From afaec920fd1db84fcc84f8dda2494703d68de9b0 Mon Sep 17 00:00:00 2001 From: Javi Aguilar <122741+itsjavi@users.noreply.github.com> Date: Fri, 25 Aug 2023 02:16:00 +0200 Subject: [PATCH] refactor(ui): implement an event-driven bidirectional communication system between for the iframe --- package.json | 4 +- packages/storylite/package.json | 6 +- packages/storylite/src/app/index.test.tsx | 3 - .../storylite/src/components/StoryFrame.tsx | 15 -- .../src/components/canvas/CanvasIframe.tsx | 90 ++++++++++++ .../components/canvas/CanvasIframeBody.tsx | 57 ++++++++ .../canvas/useCanvasIframe.test.tsx | 131 +++++++++++++++++ .../src/components/canvas/useCanvasIframe.ts | 94 +++++++++++++ packages/storylite/src/pages/index.tsx | 6 +- .../storylite/src/pages/sandbox/dashboard.tsx | 5 +- .../sandbox/stories/$story/$export_name.tsx | 10 +- .../pages/sandbox/stories/$story/index.tsx | 6 +- .../src/pages/stories/$story/$export_name.tsx | 5 +- packages/storylite/src/types/config.ts | 1 + packages/vite-plugin/package.json | 4 +- packages/vite-plugin/src/index.ts | 2 +- pnpm-lock.yaml | 132 +++++++++--------- 17 files changed, 464 insertions(+), 107 deletions(-) delete mode 100644 packages/storylite/src/app/index.test.tsx delete mode 100644 packages/storylite/src/components/StoryFrame.tsx create mode 100644 packages/storylite/src/components/canvas/CanvasIframe.tsx create mode 100644 packages/storylite/src/components/canvas/CanvasIframeBody.tsx create mode 100644 packages/storylite/src/components/canvas/useCanvasIframe.test.tsx create mode 100644 packages/storylite/src/components/canvas/useCanvasIframe.ts diff --git a/package.json b/package.json index 0fd5aaa..d1fb067 100644 --- a/package.json +++ b/package.json @@ -50,13 +50,13 @@ "devDependencies": { "@commitlint/cli": "^17.7.1", "@commitlint/config-conventional": "^17.7.0", - "@r1stack/coding-style": "^0.4.1", + "@r1stack/coding-style": "^0.4.3", "@swc/core": "^1.3.78", "@swc/jest": "^0.2.29", "@testing-library/jest-dom": "^6.1.2", "@testing-library/react": "^14.0.0", "@types/jest": "^29.5.4", - "@types/node": "^20.5.4", + "@types/node": "^20.5.6", "changelogen": "^0.5.5", "eslint": "^8.47.0", "husky": "^8.0.3", diff --git a/packages/storylite/package.json b/packages/storylite/package.json index 2615e90..f0416f7 100644 --- a/packages/storylite/package.json +++ b/packages/storylite/package.json @@ -29,12 +29,12 @@ "type-check": "tsc --noEmit" }, "dependencies": { - "@r1stack/core": "^0.4.1", + "@r1stack/core": "^0.4.3", "lucide-react": "^0.268.0" }, "devDependencies": { - "@r1stack/coding-style": "^0.4.1", - "@types/node": "^20.5.4", + "@r1stack/coding-style": "^0.4.3", + "@types/node": "^20.5.6", "@types/react": "^18.2.21", "@types/react-dom": "^18.2.7", "publint": "^0.2.2", diff --git a/packages/storylite/src/app/index.test.tsx b/packages/storylite/src/app/index.test.tsx deleted file mode 100644 index b20bb8f..0000000 --- a/packages/storylite/src/app/index.test.tsx +++ /dev/null @@ -1,3 +0,0 @@ -it('passes', () => { - expect(true).toBe(true) -}) diff --git a/packages/storylite/src/components/StoryFrame.tsx b/packages/storylite/src/components/StoryFrame.tsx deleted file mode 100644 index e459722..0000000 --- a/packages/storylite/src/components/StoryFrame.tsx +++ /dev/null @@ -1,15 +0,0 @@ -import { ElementIds } from '@/types' - -type StoryFrameProps = { - story?: string - exportName?: string -} - -export default function StoryFrame({ story, exportName }: StoryFrameProps) { - const iframeSrc = - story === undefined ? '/#/sandbox/dashboard' : `/#/sandbox/stories/${story}/${exportName || ''}` - - return ( -