forgebook 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +136 -2
- package/dist/bin/forgebook/catalogueVite.d.ts +16 -0
- package/dist/bin/forgebook/catalogueVite.d.ts.map +1 -0
- package/dist/bin/forgebook/catalogueVite.js +15 -0
- package/dist/bin/forgebook/catalogueVite.js.map +1 -0
- package/dist/bin/forgebook/forgebook.d.mts +3 -0
- package/dist/bin/forgebook/forgebook.d.mts.map +1 -0
- package/dist/bin/forgebook/forgebook.mjs +93 -0
- package/dist/bin/forgebook/forgebook.mjs.map +1 -0
- package/dist/bin/forgebook-docs/catalogueDocs.types.d.ts +90 -0
- package/dist/bin/forgebook-docs/catalogueDocs.types.d.ts.map +1 -0
- package/dist/bin/forgebook-docs/catalogueDocs.types.js +1 -0
- package/dist/bin/forgebook-docs/catalogueDocs.types.js.map +1 -0
- package/dist/bin/forgebook-docs/catalogueMarkdown.d.ts +9 -0
- package/dist/bin/forgebook-docs/catalogueMarkdown.d.ts.map +1 -0
- package/dist/bin/forgebook-docs/catalogueMarkdown.js +132 -0
- package/dist/bin/forgebook-docs/catalogueMarkdown.js.map +1 -0
- package/dist/bin/forgebook-docs/collectDocs.d.ts +17 -0
- package/dist/bin/forgebook-docs/collectDocs.d.ts.map +1 -0
- package/dist/bin/forgebook-docs/collectDocs.js +115 -0
- package/dist/bin/forgebook-docs/collectDocs.js.map +1 -0
- package/dist/bin/forgebook-docs/forgebook-docs.d.mts +3 -0
- package/dist/bin/forgebook-docs/forgebook-docs.d.mts.map +1 -0
- package/dist/bin/forgebook-docs/forgebook-docs.mjs +115 -0
- package/dist/bin/forgebook-docs/forgebook-docs.mjs.map +1 -0
- package/dist/bin/forgebook-docs/moduleDocs.d.ts +9 -0
- package/dist/bin/forgebook-docs/moduleDocs.d.ts.map +1 -0
- package/dist/bin/forgebook-docs/moduleDocs.js +62 -0
- package/dist/bin/forgebook-docs/moduleDocs.js.map +1 -0
- package/dist/bin/forgebook-docs/sassDocs.d.ts +20 -0
- package/dist/bin/forgebook-docs/sassDocs.d.ts.map +1 -0
- package/dist/bin/forgebook-docs/sassDocs.js +77 -0
- package/dist/bin/forgebook-docs/sassDocs.js.map +1 -0
- package/dist/bin/forgebook-texts/forgebook-texts.d.mts +3 -0
- package/dist/bin/forgebook-texts/forgebook-texts.d.mts.map +1 -0
- package/dist/bin/forgebook-texts/forgebook-texts.mjs +94 -0
- package/dist/bin/forgebook-texts/forgebook-texts.mjs.map +1 -0
- package/dist/bin/forgebook-texts/storyTextsReport.d.ts +26 -0
- package/dist/bin/forgebook-texts/storyTextsReport.d.ts.map +1 -0
- package/dist/bin/forgebook-texts/storyTextsReport.js +35 -0
- package/dist/bin/forgebook-texts/storyTextsReport.js.map +1 -0
- package/dist/bin/forgebook-texts/storyTextsReport.types.d.ts +25 -0
- package/dist/bin/forgebook-texts/storyTextsReport.types.d.ts.map +1 -0
- package/dist/bin/forgebook-texts/storyTextsReport.types.js +7 -0
- package/dist/bin/forgebook-texts/storyTextsReport.types.js.map +1 -0
- package/dist/src/a11y.d.ts +28 -0
- package/dist/src/a11y.d.ts.map +1 -0
- package/dist/src/a11y.js +29 -0
- package/dist/src/a11y.js.map +1 -0
- package/dist/src/argTypes.d.ts +114 -0
- package/dist/src/argTypes.d.ts.map +1 -0
- package/dist/src/argTypes.js +254 -0
- package/dist/src/argTypes.js.map +1 -0
- package/dist/src/backdrops.d.ts +88 -0
- package/dist/src/backdrops.d.ts.map +1 -0
- package/dist/src/backdrops.js +202 -0
- package/dist/src/backdrops.js.map +1 -0
- package/dist/src/catalogue.d.ts +120 -0
- package/dist/src/catalogue.d.ts.map +1 -0
- package/dist/src/catalogue.js +80 -0
- package/dist/src/catalogue.js.map +1 -0
- package/dist/src/componentDocs.d.ts +98 -0
- package/dist/src/componentDocs.d.ts.map +1 -0
- package/dist/src/componentDocs.js +47 -0
- package/dist/src/componentDocs.js.map +1 -0
- package/dist/src/frame/checkStory.d.ts +20 -0
- package/dist/src/frame/checkStory.d.ts.map +1 -0
- package/dist/src/frame/checkStory.js +31 -0
- package/dist/src/frame/checkStory.js.map +1 -0
- package/dist/src/frame/frame.css +51 -0
- package/dist/src/frame/frameClock.d.ts +53 -0
- package/dist/src/frame/frameClock.d.ts.map +1 -0
- package/dist/src/frame/frameClock.js +80 -0
- package/dist/src/frame/frameClock.js.map +1 -0
- package/dist/src/frame/frameStatus.d.ts +8 -0
- package/dist/src/frame/frameStatus.d.ts.map +1 -0
- package/dist/src/frame/frameStatus.js +8 -0
- package/dist/src/frame/frameStatus.js.map +1 -0
- package/dist/src/frame/frameView.d.ts +33 -0
- package/dist/src/frame/frameView.d.ts.map +1 -0
- package/dist/src/frame/frameView.js +134 -0
- package/dist/src/frame/frameView.js.map +1 -0
- package/dist/src/frame/matrixLayout.d.ts +36 -0
- package/dist/src/frame/matrixLayout.d.ts.map +1 -0
- package/dist/src/frame/matrixLayout.js +87 -0
- package/dist/src/frame/matrixLayout.js.map +1 -0
- package/dist/src/frame/measureTools.d.ts +24 -0
- package/dist/src/frame/measureTools.d.ts.map +1 -0
- package/dist/src/frame/measureTools.js +141 -0
- package/dist/src/frame/measureTools.js.map +1 -0
- package/dist/src/frame/mountFrame.d.ts +47 -0
- package/dist/src/frame/mountFrame.d.ts.map +1 -0
- package/dist/src/frame/mountFrame.js +229 -0
- package/dist/src/frame/mountFrame.js.map +1 -0
- package/dist/src/frame/playStory.d.ts +40 -0
- package/dist/src/frame/playStory.d.ts.map +1 -0
- package/dist/src/frame/playStory.js +55 -0
- package/dist/src/frame/playStory.js.map +1 -0
- package/dist/src/frame/renderer.d.ts +85 -0
- package/dist/src/frame/renderer.d.ts.map +1 -0
- package/dist/src/frame/renderer.js +18 -0
- package/dist/src/frame/renderer.js.map +1 -0
- package/dist/src/frame/settle.d.ts +24 -0
- package/dist/src/frame/settle.d.ts.map +1 -0
- package/dist/src/frame/settle.js +25 -0
- package/dist/src/frame/settle.js.map +1 -0
- package/dist/src/frame/staleModule.d.ts +40 -0
- package/dist/src/frame/staleModule.d.ts.map +1 -0
- package/dist/src/frame/staleModule.js +74 -0
- package/dist/src/frame/staleModule.js.map +1 -0
- package/dist/src/frame/storyCanvas.d.ts +21 -0
- package/dist/src/frame/storyCanvas.d.ts.map +1 -0
- package/dist/src/frame/storyCanvas.js +30 -0
- package/dist/src/frame/storyCanvas.js.map +1 -0
- package/dist/src/frame/storyHooks.d.ts +31 -0
- package/dist/src/frame/storyHooks.d.ts.map +1 -0
- package/dist/src/frame/storyHooks.js +59 -0
- package/dist/src/frame/storyHooks.js.map +1 -0
- package/dist/src/frame/storyModule.d.ts +104 -0
- package/dist/src/frame/storyModule.d.ts.map +1 -0
- package/dist/src/frame/storyModule.js +205 -0
- package/dist/src/frame/storyModule.js.map +1 -0
- package/dist/src/frame/storyRun.d.ts +96 -0
- package/dist/src/frame/storyRun.d.ts.map +1 -0
- package/dist/src/frame/storyRun.js +318 -0
- package/dist/src/frame/storyRun.js.map +1 -0
- package/dist/src/languages.d.ts +15 -0
- package/dist/src/languages.d.ts.map +1 -0
- package/dist/src/languages.js +8 -0
- package/dist/src/languages.js.map +1 -0
- package/dist/src/matrix.d.ts +56 -0
- package/dist/src/matrix.d.ts.map +1 -0
- package/dist/src/matrix.js +61 -0
- package/dist/src/matrix.js.map +1 -0
- package/dist/src/messages.d.ts +203 -0
- package/dist/src/messages.d.ts.map +1 -0
- package/dist/src/messages.js +193 -0
- package/dist/src/messages.js.map +1 -0
- package/dist/src/namedValues.d.ts +38 -0
- package/dist/src/namedValues.d.ts.map +1 -0
- package/dist/src/namedValues.js +48 -0
- package/dist/src/namedValues.js.map +1 -0
- package/dist/src/pageConfig.d.ts +23 -0
- package/dist/src/pageConfig.d.ts.map +1 -0
- package/dist/src/pageConfig.js +1 -0
- package/dist/src/pageConfig.js.map +1 -0
- package/dist/src/playTrace.d.ts +41 -0
- package/dist/src/playTrace.d.ts.map +1 -0
- package/dist/src/playTrace.js +35 -0
- package/dist/src/playTrace.js.map +1 -0
- package/dist/src/shell/A11yTab.d.ts +44 -0
- package/dist/src/shell/A11yTab.d.ts.map +1 -0
- package/dist/src/shell/A11yTab.js +30 -0
- package/dist/src/shell/A11yTab.js.map +1 -0
- package/dist/src/shell/ApiReference.d.ts +18 -0
- package/dist/src/shell/ApiReference.d.ts.map +1 -0
- package/dist/src/shell/ApiReference.js +41 -0
- package/dist/src/shell/ApiReference.js.map +1 -0
- package/dist/src/shell/ClockControls.d.ts +43 -0
- package/dist/src/shell/ClockControls.d.ts.map +1 -0
- package/dist/src/shell/ClockControls.js +53 -0
- package/dist/src/shell/ClockControls.js.map +1 -0
- package/dist/src/shell/Code.d.ts +16 -0
- package/dist/src/shell/Code.d.ts.map +1 -0
- package/dist/src/shell/Code.js +9 -0
- package/dist/src/shell/Code.js.map +1 -0
- package/dist/src/shell/CodeTab.d.ts +17 -0
- package/dist/src/shell/CodeTab.d.ts.map +1 -0
- package/dist/src/shell/CodeTab.js +17 -0
- package/dist/src/shell/CodeTab.js.map +1 -0
- package/dist/src/shell/CodeText.d.ts +16 -0
- package/dist/src/shell/CodeText.d.ts.map +1 -0
- package/dist/src/shell/CodeText.js +10 -0
- package/dist/src/shell/CodeText.js.map +1 -0
- package/dist/src/shell/ComponentPage.d.ts +38 -0
- package/dist/src/shell/ComponentPage.d.ts.map +1 -0
- package/dist/src/shell/ComponentPage.js +146 -0
- package/dist/src/shell/ComponentPage.js.map +1 -0
- package/dist/src/shell/Dock.d.ts +42 -0
- package/dist/src/shell/Dock.d.ts.map +1 -0
- package/dist/src/shell/Dock.js +90 -0
- package/dist/src/shell/Dock.js.map +1 -0
- package/dist/src/shell/EventsTab.d.ts +25 -0
- package/dist/src/shell/EventsTab.d.ts.map +1 -0
- package/dist/src/shell/EventsTab.js +26 -0
- package/dist/src/shell/EventsTab.js.map +1 -0
- package/dist/src/shell/FrameView.d.ts +49 -0
- package/dist/src/shell/FrameView.d.ts.map +1 -0
- package/dist/src/shell/FrameView.js +29 -0
- package/dist/src/shell/FrameView.js.map +1 -0
- package/dist/src/shell/HomePage.d.ts +39 -0
- package/dist/src/shell/HomePage.d.ts.map +1 -0
- package/dist/src/shell/HomePage.js +85 -0
- package/dist/src/shell/HomePage.js.map +1 -0
- package/dist/src/shell/InteractionsTab.d.ts +28 -0
- package/dist/src/shell/InteractionsTab.d.ts.map +1 -0
- package/dist/src/shell/InteractionsTab.js +17 -0
- package/dist/src/shell/InteractionsTab.js.map +1 -0
- package/dist/src/shell/MatrixPicker.d.ts +24 -0
- package/dist/src/shell/MatrixPicker.d.ts.map +1 -0
- package/dist/src/shell/MatrixPicker.js +29 -0
- package/dist/src/shell/MatrixPicker.js.map +1 -0
- package/dist/src/shell/PackageHtml.d.ts +17 -0
- package/dist/src/shell/PackageHtml.d.ts.map +1 -0
- package/dist/src/shell/PackageHtml.js +13 -0
- package/dist/src/shell/PackageHtml.js.map +1 -0
- package/dist/src/shell/PartsTab.d.ts +23 -0
- package/dist/src/shell/PartsTab.d.ts.map +1 -0
- package/dist/src/shell/PartsTab.js +23 -0
- package/dist/src/shell/PartsTab.js.map +1 -0
- package/dist/src/shell/PropFields.d.ts +31 -0
- package/dist/src/shell/PropFields.d.ts.map +1 -0
- package/dist/src/shell/PropFields.js +81 -0
- package/dist/src/shell/PropFields.js.map +1 -0
- package/dist/src/shell/PropsTab.d.ts +45 -0
- package/dist/src/shell/PropsTab.d.ts.map +1 -0
- package/dist/src/shell/PropsTab.js +81 -0
- package/dist/src/shell/PropsTab.js.map +1 -0
- package/dist/src/shell/SchemeSwitches.d.ts +24 -0
- package/dist/src/shell/SchemeSwitches.d.ts.map +1 -0
- package/dist/src/shell/SchemeSwitches.js +36 -0
- package/dist/src/shell/SchemeSwitches.js.map +1 -0
- package/dist/src/shell/Segmented.d.ts +41 -0
- package/dist/src/shell/Segmented.d.ts.map +1 -0
- package/dist/src/shell/Segmented.js +19 -0
- package/dist/src/shell/Segmented.js.map +1 -0
- package/dist/src/shell/Shell.d.ts +49 -0
- package/dist/src/shell/Shell.d.ts.map +1 -0
- package/dist/src/shell/Shell.js +279 -0
- package/dist/src/shell/Shell.js.map +1 -0
- package/dist/src/shell/Sidebar.d.ts +52 -0
- package/dist/src/shell/Sidebar.d.ts.map +1 -0
- package/dist/src/shell/Sidebar.js +132 -0
- package/dist/src/shell/Sidebar.js.map +1 -0
- package/dist/src/shell/SidebarHandle.d.ts +29 -0
- package/dist/src/shell/SidebarHandle.d.ts.map +1 -0
- package/dist/src/shell/SidebarHandle.js +46 -0
- package/dist/src/shell/SidebarHandle.js.map +1 -0
- package/dist/src/shell/Stage.d.ts +68 -0
- package/dist/src/shell/Stage.d.ts.map +1 -0
- package/dist/src/shell/Stage.js +218 -0
- package/dist/src/shell/Stage.js.map +1 -0
- package/dist/src/shell/StageTools.d.ts +27 -0
- package/dist/src/shell/StageTools.d.ts.map +1 -0
- package/dist/src/shell/StageTools.js +34 -0
- package/dist/src/shell/StageTools.js.map +1 -0
- package/dist/src/shell/StageViewport.d.ts +47 -0
- package/dist/src/shell/StageViewport.d.ts.map +1 -0
- package/dist/src/shell/StageViewport.js +174 -0
- package/dist/src/shell/StageViewport.js.map +1 -0
- package/dist/src/shell/StoryCodeBlock.d.ts +35 -0
- package/dist/src/shell/StoryCodeBlock.d.ts.map +1 -0
- package/dist/src/shell/StoryCodeBlock.js +27 -0
- package/dist/src/shell/StoryCodeBlock.js.map +1 -0
- package/dist/src/shell/StoryPicker.d.ts +26 -0
- package/dist/src/shell/StoryPicker.d.ts.map +1 -0
- package/dist/src/shell/StoryPicker.js +32 -0
- package/dist/src/shell/StoryPicker.js.map +1 -0
- package/dist/src/shell/Toolbar.d.ts +40 -0
- package/dist/src/shell/Toolbar.d.ts.map +1 -0
- package/dist/src/shell/Toolbar.js +125 -0
- package/dist/src/shell/Toolbar.js.map +1 -0
- package/dist/src/shell/WidthField.d.ts +24 -0
- package/dist/src/shell/WidthField.d.ts.map +1 -0
- package/dist/src/shell/WidthField.js +40 -0
- package/dist/src/shell/WidthField.js.map +1 -0
- package/dist/src/shell/catalogueContext.d.ts +6 -0
- package/dist/src/shell/catalogueContext.d.ts.map +1 -0
- package/dist/src/shell/catalogueContext.js +14 -0
- package/dist/src/shell/catalogueContext.js.map +1 -0
- package/dist/src/shell/codeTokens.d.ts +23 -0
- package/dist/src/shell/codeTokens.d.ts.map +1 -0
- package/dist/src/shell/codeTokens.js +48 -0
- package/dist/src/shell/codeTokens.js.map +1 -0
- package/dist/src/shell/codeWriter.d.ts +6 -0
- package/dist/src/shell/codeWriter.d.ts.map +1 -0
- package/dist/src/shell/codeWriter.js +14 -0
- package/dist/src/shell/codeWriter.js.map +1 -0
- package/dist/src/shell/compareVariants.d.ts +35 -0
- package/dist/src/shell/compareVariants.d.ts.map +1 -0
- package/dist/src/shell/compareVariants.js +68 -0
- package/dist/src/shell/compareVariants.js.map +1 -0
- package/dist/src/shell/dockTabs.d.ts +63 -0
- package/dist/src/shell/dockTabs.d.ts.map +1 -0
- package/dist/src/shell/dockTabs.js +140 -0
- package/dist/src/shell/dockTabs.js.map +1 -0
- package/dist/src/shell/icons.d.ts +47 -0
- package/dist/src/shell/icons.d.ts.map +1 -0
- package/dist/src/shell/icons.js +36 -0
- package/dist/src/shell/icons.js.map +1 -0
- package/dist/src/shell/keyboard.d.ts +35 -0
- package/dist/src/shell/keyboard.d.ts.map +1 -0
- package/dist/src/shell/keyboard.js +51 -0
- package/dist/src/shell/keyboard.js.map +1 -0
- package/dist/src/shell/mountShell.d.ts +22 -0
- package/dist/src/shell/mountShell.d.ts.map +1 -0
- package/dist/src/shell/mountShell.js +39 -0
- package/dist/src/shell/mountShell.js.map +1 -0
- package/dist/src/shell/shell.css +1831 -0
- package/dist/src/shell/strings.d.ts +184 -0
- package/dist/src/shell/strings.d.ts.map +1 -0
- package/dist/src/shell/strings.js +188 -0
- package/dist/src/shell/strings.js.map +1 -0
- package/dist/src/shell/switchView.d.ts +23 -0
- package/dist/src/shell/switchView.d.ts.map +1 -0
- package/dist/src/shell/switchView.js +19 -0
- package/dist/src/shell/switchView.js.map +1 -0
- package/dist/src/shell/treeSearch.d.ts +35 -0
- package/dist/src/shell/treeSearch.d.ts.map +1 -0
- package/dist/src/shell/treeSearch.js +60 -0
- package/dist/src/shell/treeSearch.js.map +1 -0
- package/dist/src/shell/useComponentDocs.d.ts +16 -0
- package/dist/src/shell/useComponentDocs.d.ts.map +1 -0
- package/dist/src/shell/useComponentDocs.js +25 -0
- package/dist/src/shell/useComponentDocs.js.map +1 -0
- package/dist/src/shell/useCopy.d.ts +10 -0
- package/dist/src/shell/useCopy.d.ts.map +1 -0
- package/dist/src/shell/useCopy.js +23 -0
- package/dist/src/shell/useCopy.js.map +1 -0
- package/dist/src/shell/useFrameMessages.d.ts +54 -0
- package/dist/src/shell/useFrameMessages.d.ts.map +1 -0
- package/dist/src/shell/useFrameMessages.js +90 -0
- package/dist/src/shell/useFrameMessages.js.map +1 -0
- package/dist/src/shell/useFrameQueue.d.ts +29 -0
- package/dist/src/shell/useFrameQueue.d.ts.map +1 -0
- package/dist/src/shell/useFrameQueue.js +72 -0
- package/dist/src/shell/useFrameQueue.js.map +1 -0
- package/dist/src/shell/useLiveView.d.ts +29 -0
- package/dist/src/shell/useLiveView.d.ts.map +1 -0
- package/dist/src/shell/useLiveView.js +51 -0
- package/dist/src/shell/useLiveView.js.map +1 -0
- package/dist/src/shell/useLoaded.d.ts +20 -0
- package/dist/src/shell/useLoaded.d.ts.map +1 -0
- package/dist/src/shell/useLoaded.js +40 -0
- package/dist/src/shell/useLoaded.js.map +1 -0
- package/dist/src/shell/usePageDoc.d.ts +20 -0
- package/dist/src/shell/usePageDoc.d.ts.map +1 -0
- package/dist/src/shell/usePageDoc.js +21 -0
- package/dist/src/shell/usePageDoc.js.map +1 -0
- package/dist/src/shell/usePopover.d.ts +23 -0
- package/dist/src/shell/usePopover.d.ts.map +1 -0
- package/dist/src/shell/usePopover.js +39 -0
- package/dist/src/shell/usePopover.js.map +1 -0
- package/dist/src/shell/useRecentPages.d.ts +21 -0
- package/dist/src/shell/useRecentPages.d.ts.map +1 -0
- package/dist/src/shell/useRecentPages.js +62 -0
- package/dist/src/shell/useRecentPages.js.map +1 -0
- package/dist/src/shell/useScrollMemory.d.ts +40 -0
- package/dist/src/shell/useScrollMemory.d.ts.map +1 -0
- package/dist/src/shell/useScrollMemory.js +69 -0
- package/dist/src/shell/useScrollMemory.js.map +1 -0
- package/dist/src/shell/useSidebarLayout.d.ts +14 -0
- package/dist/src/shell/useSidebarLayout.d.ts.map +1 -0
- package/dist/src/shell/useSidebarLayout.js +19 -0
- package/dist/src/shell/useSidebarLayout.js.map +1 -0
- package/dist/src/shell/useStored.d.ts +11 -0
- package/dist/src/shell/useStored.d.ts.map +1 -0
- package/dist/src/shell/useStored.js +68 -0
- package/dist/src/shell/useStored.js.map +1 -0
- package/dist/src/shell/useStoryCode.d.ts +14 -0
- package/dist/src/shell/useStoryCode.d.ts.map +1 -0
- package/dist/src/shell/useStoryCode.js +29 -0
- package/dist/src/shell/useStoryCode.js.map +1 -0
- package/dist/src/shell/useStoryHeights.d.ts +9 -0
- package/dist/src/shell/useStoryHeights.d.ts.map +1 -0
- package/dist/src/shell/useStoryHeights.js +31 -0
- package/dist/src/shell/useStoryHeights.js.map +1 -0
- package/dist/src/shell/useStoryIdsElement.d.ts +7 -0
- package/dist/src/shell/useStoryIdsElement.d.ts.map +1 -0
- package/dist/src/shell/useStoryIdsElement.js +29 -0
- package/dist/src/shell/useStoryIdsElement.js.map +1 -0
- package/dist/src/shell/useStoryKeys.d.ts +11 -0
- package/dist/src/shell/useStoryKeys.d.ts.map +1 -0
- package/dist/src/shell/useStoryKeys.js +40 -0
- package/dist/src/shell/useStoryKeys.js.map +1 -0
- package/dist/src/shell/useSystemDark.d.ts +3 -0
- package/dist/src/shell/useSystemDark.d.ts.map +1 -0
- package/dist/src/shell/useSystemDark.js +19 -0
- package/dist/src/shell/useSystemDark.js.map +1 -0
- package/dist/src/sourceFiles.d.ts +18 -0
- package/dist/src/sourceFiles.d.ts.map +1 -0
- package/dist/src/sourceFiles.js +22 -0
- package/dist/src/sourceFiles.js.map +1 -0
- package/dist/src/storyBackground.d.ts +21 -0
- package/dist/src/storyBackground.d.ts.map +1 -0
- package/dist/src/storyBackground.js +27 -0
- package/dist/src/storyBackground.js.map +1 -0
- package/dist/src/storyClock.d.ts +62 -0
- package/dist/src/storyClock.d.ts.map +1 -0
- package/dist/src/storyClock.js +51 -0
- package/dist/src/storyClock.js.map +1 -0
- package/dist/src/storyGlobals.d.ts +60 -0
- package/dist/src/storyGlobals.d.ts.map +1 -0
- package/dist/src/storyGlobals.js +117 -0
- package/dist/src/storyGlobals.js.map +1 -0
- package/dist/src/storyHeights.d.ts +37 -0
- package/dist/src/storyHeights.d.ts.map +1 -0
- package/dist/src/storyHeights.js +53 -0
- package/dist/src/storyHeights.js.map +1 -0
- package/dist/src/storyIdsElement.d.ts +9 -0
- package/dist/src/storyIdsElement.d.ts.map +1 -0
- package/dist/src/storyIdsElement.js +9 -0
- package/dist/src/storyIdsElement.js.map +1 -0
- package/dist/src/storyTexts.d.ts +43 -0
- package/dist/src/storyTexts.d.ts.map +1 -0
- package/dist/src/storyTexts.js +71 -0
- package/dist/src/storyTexts.js.map +1 -0
- package/dist/src/storyTree.d.ts +215 -0
- package/dist/src/storyTree.d.ts.map +1 -0
- package/dist/src/storyTree.js +308 -0
- package/dist/src/storyTree.js.map +1 -0
- package/dist/src/switches.d.ts +156 -0
- package/dist/src/switches.d.ts.map +1 -0
- package/dist/src/switches.js +193 -0
- package/dist/src/switches.js.map +1 -0
- package/dist/src/viewState.d.ts +194 -0
- package/dist/src/viewState.d.ts.map +1 -0
- package/dist/src/viewState.js +303 -0
- package/dist/src/viewState.js.map +1 -0
- package/dist/src/vite/adapter.d.ts +70 -0
- package/dist/src/vite/adapter.d.ts.map +1 -0
- package/dist/src/vite/adapter.js +22 -0
- package/dist/src/vite/adapter.js.map +1 -0
- package/dist/src/vite/autoTitle.d.ts +28 -0
- package/dist/src/vite/autoTitle.d.ts.map +1 -0
- package/dist/src/vite/autoTitle.js +44 -0
- package/dist/src/vite/autoTitle.js.map +1 -0
- package/dist/src/vite/componentPage.d.ts +34 -0
- package/dist/src/vite/componentPage.d.ts.map +1 -0
- package/dist/src/vite/componentPage.js +94 -0
- package/dist/src/vite/componentPage.js.map +1 -0
- package/dist/src/vite/config.d.ts +72 -0
- package/dist/src/vite/config.d.ts.map +1 -0
- package/dist/src/vite/config.js +25 -0
- package/dist/src/vite/config.js.map +1 -0
- package/dist/src/vite/configFile.d.ts +76 -0
- package/dist/src/vite/configFile.d.ts.map +1 -0
- package/dist/src/vite/configFile.js +190 -0
- package/dist/src/vite/configFile.js.map +1 -0
- package/dist/src/vite/docsExtractor.d.ts +46 -0
- package/dist/src/vite/docsExtractor.d.ts.map +1 -0
- package/dist/src/vite/docsExtractor.js +88 -0
- package/dist/src/vite/docsExtractor.js.map +1 -0
- package/dist/src/vite/docsProgram.d.ts +42 -0
- package/dist/src/vite/docsProgram.d.ts.map +1 -0
- package/dist/src/vite/docsProgram.js +144 -0
- package/dist/src/vite/docsProgram.js.map +1 -0
- package/dist/src/vite/docsWorker.d.ts +2 -0
- package/dist/src/vite/docsWorker.d.ts.map +1 -0
- package/dist/src/vite/docsWorker.js +68 -0
- package/dist/src/vite/docsWorker.js.map +1 -0
- package/dist/src/vite/forcedStates.d.ts +27 -0
- package/dist/src/vite/forcedStates.d.ts.map +1 -0
- package/dist/src/vite/forcedStates.js +60 -0
- package/dist/src/vite/forcedStates.js.map +1 -0
- package/dist/src/vite/forgebookPlugin.d.ts +28 -0
- package/dist/src/vite/forgebookPlugin.d.ts.map +1 -0
- package/dist/src/vite/forgebookPlugin.js +375 -0
- package/dist/src/vite/forgebookPlugin.js.map +1 -0
- package/dist/src/vite/highlightCode.d.ts +16 -0
- package/dist/src/vite/highlightCode.d.ts.map +1 -0
- package/dist/src/vite/highlightCode.js +82 -0
- package/dist/src/vite/highlightCode.js.map +1 -0
- package/dist/src/vite/indexStoryFile.d.ts +35 -0
- package/dist/src/vite/indexStoryFile.d.ts.map +1 -0
- package/dist/src/vite/indexStoryFile.js +458 -0
- package/dist/src/vite/indexStoryFile.js.map +1 -0
- package/dist/src/vite/pages.d.ts +49 -0
- package/dist/src/vite/pages.d.ts.map +1 -0
- package/dist/src/vite/pages.js +171 -0
- package/dist/src/vite/pages.js.map +1 -0
- package/dist/src/vite/prebundled.d.ts +30 -0
- package/dist/src/vite/prebundled.d.ts.map +1 -0
- package/dist/src/vite/prebundled.js +81 -0
- package/dist/src/vite/prebundled.js.map +1 -0
- package/dist/src/vite/storyCode.d.ts +28 -0
- package/dist/src/vite/storyCode.d.ts.map +1 -0
- package/dist/src/vite/storyCode.js +80 -0
- package/dist/src/vite/storyCode.js.map +1 -0
- package/dist/src/vite/storyFilesModule.d.ts +17 -0
- package/dist/src/vite/storyFilesModule.d.ts.map +1 -0
- package/dist/src/vite/storyFilesModule.js +64 -0
- package/dist/src/vite/storyFilesModule.js.map +1 -0
- package/dist/src/vite/storyMeta.d.ts +34 -0
- package/dist/src/vite/storyMeta.d.ts.map +1 -0
- package/dist/src/vite/storyMeta.js +74 -0
- package/dist/src/vite/storyMeta.js.map +1 -0
- package/dist/src/vite/typeScriptPieces.d.ts +23 -0
- package/dist/src/vite/typeScriptPieces.d.ts.map +1 -0
- package/dist/src/vite/typeScriptPieces.js +236 -0
- package/dist/src/vite/typeScriptPieces.js.map +1 -0
- package/package.json +202 -3
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The two pages a catalogue is made of, as the plugin generates them from its configuration: their HTML, the
|
|
3
|
+
* entries that mount the shell and the frame, the configuration the pages read, and the source of the project's own
|
|
4
|
+
* stories. Pure: a resolved configuration in, text out.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* An app writes no page: the shell's entry mounts the shell with the configuration's data, its sources and the
|
|
8
|
+
* framework's code writer; the frame's mounts the framework's frame with the sources and the previews. The sources
|
|
9
|
+
* are imported by specifier (each exports `source`), the project's own stories through a generated source, the
|
|
10
|
+
* previews and the logo by path, so their code is bundled as any import is.
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
import { join } from "node:path";
|
|
15
|
+
import { PLAY_TOOLS_PACKAGES } from "./configFile.js";
|
|
16
|
+
/** The pages, by their file name. */
|
|
17
|
+
export const PAGE_FILES = ["index.html", "frame.html"];
|
|
18
|
+
/** The module the pages read the configuration's data from. */
|
|
19
|
+
export const CONFIG_MODULE = "virtual:forgebook/config";
|
|
20
|
+
/**
|
|
21
|
+
* The entries the pages load, by page: file names in the configuration's folder, never written to disk. Named as
|
|
22
|
+
* files rather than virtual modules because the build names a page's chunk and its style sheet after its entry, and a
|
|
23
|
+
* virtual module's id cannot be part of a file name.
|
|
24
|
+
*/
|
|
25
|
+
export const PAGE_ENTRIES = {
|
|
26
|
+
"index.html": ".forgebook-shell.ts",
|
|
27
|
+
"frame.html": ".forgebook-frame.ts"
|
|
28
|
+
};
|
|
29
|
+
/** The file name, in the configuration's folder, of the project's own stories' source (never written to disk). */
|
|
30
|
+
export const STORIES_SOURCE_FILE = ".forgebook-stories.ts";
|
|
31
|
+
/** The project's own stories' source id. */
|
|
32
|
+
export const OWN_SOURCE_ID = "stories";
|
|
33
|
+
/**
|
|
34
|
+
* Text set in HTML: its `<`, `>`, `&` and quotes escaped.
|
|
35
|
+
*
|
|
36
|
+
* @param text - the text.
|
|
37
|
+
*/
|
|
38
|
+
const escaped = (text) => text.replace(/[&<>"]/g, (character) => `&#${character.charCodeAt(0)};`);
|
|
39
|
+
/**
|
|
40
|
+
* A page's HTML: its title, the frame's head tags, the root the entry mounts in.
|
|
41
|
+
*
|
|
42
|
+
* @param page - the page.
|
|
43
|
+
* @param config - the configuration.
|
|
44
|
+
*/
|
|
45
|
+
export const pageHtml = (page, config) => [
|
|
46
|
+
"<!doctype html>",
|
|
47
|
+
'<html lang="en">',
|
|
48
|
+
" <head>",
|
|
49
|
+
' <meta charset="utf-8" />',
|
|
50
|
+
' <meta name="viewport" content="width=device-width, initial-scale=1" />',
|
|
51
|
+
` <title>${escaped(page === "index.html" ? config.title : "Story")}</title>`,
|
|
52
|
+
...(page === "frame.html" && config.head !== "" ? [config.head] : []),
|
|
53
|
+
" </head>",
|
|
54
|
+
" <body>",
|
|
55
|
+
' <div id="root"></div>',
|
|
56
|
+
` <script type="module" src="/${PAGE_ENTRIES[page]}"></script>`,
|
|
57
|
+
" </body>",
|
|
58
|
+
"</html>",
|
|
59
|
+
""
|
|
60
|
+
].join("\n");
|
|
61
|
+
/**
|
|
62
|
+
* The configuration's data, as the pages' module exports it.
|
|
63
|
+
*
|
|
64
|
+
* @param config - the configuration.
|
|
65
|
+
*/
|
|
66
|
+
export const configModule = (config) => {
|
|
67
|
+
const data = {
|
|
68
|
+
title: config.title,
|
|
69
|
+
heights: config.heights,
|
|
70
|
+
switches: config.switches,
|
|
71
|
+
languages: config.languages,
|
|
72
|
+
lists: config.lists
|
|
73
|
+
};
|
|
74
|
+
return `export default ${JSON.stringify(data)};`;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* The imports of the sources, and the list they make: the project's own stories first, then each package's.
|
|
78
|
+
*
|
|
79
|
+
* @param config - the configuration.
|
|
80
|
+
*/
|
|
81
|
+
const sourcesCode = (config) => {
|
|
82
|
+
const own = config.stories.length > 0 ? [`./${STORIES_SOURCE_FILE}`] : [];
|
|
83
|
+
const specifiers = [...own.map((file) => join(config.dir, file.slice(2))), ...config.sources];
|
|
84
|
+
return {
|
|
85
|
+
imports: specifiers.map((specifier, index) => `import { source as source${index} } from ${JSON.stringify(specifier)};`),
|
|
86
|
+
list: `[${specifiers.map((_specifier, index) => `source${index}`).join(", ")}]`
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* The shell's entry: the shell mounted with the configuration's data, the logo, the sources and the code writer.
|
|
91
|
+
*
|
|
92
|
+
* @param config - the configuration.
|
|
93
|
+
*/
|
|
94
|
+
export const shellEntry = (config) => {
|
|
95
|
+
const sources = sourcesCode(config);
|
|
96
|
+
return [
|
|
97
|
+
'import { mountShell } from "forgebook/shell";',
|
|
98
|
+
`import { codeOf } from ${JSON.stringify(config.framework.pages.code)};`,
|
|
99
|
+
`import config from ${JSON.stringify(CONFIG_MODULE)};`,
|
|
100
|
+
...(config.logo === undefined ? [] : [`import logo from ${JSON.stringify(`${config.logo}?url`)};`]),
|
|
101
|
+
...sources.imports,
|
|
102
|
+
'const root = document.getElementById("root");',
|
|
103
|
+
"if (root !== null)",
|
|
104
|
+
" mountShell(root, {",
|
|
105
|
+
" title: config.title,",
|
|
106
|
+
...(config.logo === undefined ? [] : [" logo,"]),
|
|
107
|
+
...(config.heights === undefined ? [] : [" heights: config.heights,"]),
|
|
108
|
+
` sources: ${sources.list},`,
|
|
109
|
+
' frameUrl: "frame.html",',
|
|
110
|
+
" languages: config.languages,",
|
|
111
|
+
...(config.switches === undefined ? [] : [" switches: config.switches,"]),
|
|
112
|
+
" lists: config.lists,",
|
|
113
|
+
" codeOf",
|
|
114
|
+
" });",
|
|
115
|
+
""
|
|
116
|
+
].join("\n");
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* The frame's loader of the play tools: Testing Library's `within` and `userEvent`, imported on the first play, so a
|
|
120
|
+
* catalogue whose stories have no play never loads them.
|
|
121
|
+
*/
|
|
122
|
+
const playToolsLoader = () => {
|
|
123
|
+
const imports = PLAY_TOOLS_PACKAGES.map((name) => `import(${JSON.stringify(name)})`).join(", ");
|
|
124
|
+
return [
|
|
125
|
+
" playTools: async () => {",
|
|
126
|
+
` const [dom, events] = await Promise.all([${imports}]);`,
|
|
127
|
+
" return { within: dom.within, userEvent: events.userEvent };",
|
|
128
|
+
" },"
|
|
129
|
+
].join("\n");
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* The frame's entry: the framework's frame mounted with the sources, the configuration's data and the previews.
|
|
133
|
+
*
|
|
134
|
+
* @param config - the configuration.
|
|
135
|
+
*/
|
|
136
|
+
export const frameEntry = (config) => {
|
|
137
|
+
const sources = sourcesCode(config);
|
|
138
|
+
return [
|
|
139
|
+
`import { mountFrame } from ${JSON.stringify(config.framework.pages.frame)};`,
|
|
140
|
+
`import config from ${JSON.stringify(CONFIG_MODULE)};`,
|
|
141
|
+
...sources.imports,
|
|
142
|
+
...config.previews.map((file, index) => `import * as preview${index} from ${JSON.stringify(file)};`),
|
|
143
|
+
'const root = document.getElementById("root");',
|
|
144
|
+
"if (root !== null)",
|
|
145
|
+
" void mountFrame(root, {",
|
|
146
|
+
` sources: ${sources.list},`,
|
|
147
|
+
" languages: config.languages,",
|
|
148
|
+
...(config.switches === undefined ? [] : [" switches: config.switches,"]),
|
|
149
|
+
" lists: config.lists,",
|
|
150
|
+
...(config.hasPlayTools ? [playToolsLoader()] : []),
|
|
151
|
+
` previews: [${config.previews.map((_file, index) => `preview${index}`).join(", ")}]`,
|
|
152
|
+
" });",
|
|
153
|
+
""
|
|
154
|
+
].join("\n");
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* The source of the project's own stories: one `?forgebook-files` import per glob, named after the catalogue.
|
|
158
|
+
*
|
|
159
|
+
* @param config - the configuration.
|
|
160
|
+
*/
|
|
161
|
+
export const storiesSourceModule = (config) => [
|
|
162
|
+
...config.stories.map((pattern, index) => `import files${index} from ${JSON.stringify(`./${pattern.replace(/^\.\//, "")}?forgebook-files`)};`),
|
|
163
|
+
"export const source = {",
|
|
164
|
+
` id: ${JSON.stringify(OWN_SOURCE_ID)},`,
|
|
165
|
+
` name: ${JSON.stringify(config.title)},`,
|
|
166
|
+
` files: [${config.stories.map((_pattern, index) => `files${index}`).join(", ")}],`,
|
|
167
|
+
" sheets: { required: [], theme: [], restyled: [] }",
|
|
168
|
+
"};",
|
|
169
|
+
""
|
|
170
|
+
].join("\n");
|
|
171
|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,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,UAAU,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;QACxF,OAAO;QACP,EAAE;KACH,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,MAAsB,EAAU,EAAE,CACpE;IACE,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CACnB,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CACjB,eAAe,KAAK,SAAS,IAAI,CAAC,SAAS,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,kBAAkB,CAAC,GAAG,CACtG;IACD,yBAAyB;IACzB,SAAS,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,GAAG;IACzC,WAAW,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG;IAC1C,aAAa,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,KAAK,EAAE,EAAE,CAAC,QAAQ,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;IACpF,qDAAqD;IACrD,IAAI;IACJ,EAAE;CACH,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type ResolvedConfig } from "./configFile.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Resolves a package as Node would from the catalogue's folder: its file's real path, or none when it is not there.
|
|
4
|
+
*
|
|
5
|
+
* @param name - the package or one of its subpaths.
|
|
6
|
+
*/
|
|
7
|
+
export type Resolve = (name: string) => string | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* The packages to pre-bundle for a catalogue.
|
|
10
|
+
*
|
|
11
|
+
* @param config - the catalogue's configuration.
|
|
12
|
+
* @param resolve - resolves a package from the catalogue's folder.
|
|
13
|
+
* @param resolveOwn - resolves a package from the core's own folder.
|
|
14
|
+
*/
|
|
15
|
+
export declare const prebundled: (config: ResolvedConfig, resolve: Resolve, resolveOwn: Resolve) => string[];
|
|
16
|
+
/**
|
|
17
|
+
* The story files Vite scans for what their components import, before the first page opens: the project's own
|
|
18
|
+
* patterns, and each source's, read from its module's `?forgebook-files` imports (relative to the module). A source
|
|
19
|
+
* the project cannot resolve, or read, adds none.
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* Without the sources' files, a package a source's stories import (`storybook/test`, a component's own dependency) is
|
|
23
|
+
* found only when a page imports it, and the page reloads once.
|
|
24
|
+
*
|
|
25
|
+
* @param config - the catalogue's configuration.
|
|
26
|
+
* @param resolve - resolves a source's module from the catalogue's folder.
|
|
27
|
+
* @param readText - reads a file's text; none when it cannot.
|
|
28
|
+
*/
|
|
29
|
+
export declare const scannedEntries: (config: ResolvedConfig, resolve: Resolve, readText: (file: string) => string | undefined) => string[];
|
|
30
|
+
//# sourceMappingURL=prebundled.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prebundled.d.ts","sourceRoot":"","sources":["../../../src/vite/prebundled.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAuB,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAmB3E;;;;GAIG;AACH,MAAM,MAAM,OAAO,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;AAK3D;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,GAAI,QAAQ,cAAc,EAAE,SAAS,OAAO,EAAE,YAAY,OAAO,KAAG,MAAM,EAiBhG,CAAC;AAKF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,cAAc,GACzB,QAAQ,cAAc,EACtB,SAAS,OAAO,EAChB,UAAU,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,KAC7C,MAAM,EAUR,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The packages Vite pre-bundles, and the story files it scans, before the catalogue's first page opens, so the pages
|
|
3
|
+
* never reload while they load.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Vite finds what to pre-bundle by scanning the app's HTML and entries on disk; a catalogue's pages and their entries
|
|
7
|
+
* are generated (`pages.ts`), so without this list Vite discovers each package as a page imports it, pre-bundles it
|
|
8
|
+
* then, and reloads the page, more than once on a first start. The list is the shell's and the frame's packages (the
|
|
9
|
+
* shell is React), the framework's, Testing Library's when the project installs it, and Forgebook's own modules when
|
|
10
|
+
* they come from an installed package (a linked one is source, which Vite does not pre-bundle). A package the project
|
|
11
|
+
* cannot resolve is left out, since Vite fails on one it cannot find. Pure: a resolver in, names out.
|
|
12
|
+
*
|
|
13
|
+
* @module
|
|
14
|
+
*/
|
|
15
|
+
import { dirname, join } from "node:path";
|
|
16
|
+
import { PLAY_TOOLS_PACKAGES } from "./configFile.js";
|
|
17
|
+
/** What the shell and the frame import in the browser from the project's packages (React is a peer of the core). */
|
|
18
|
+
const CORE_BROWSER_DEPENDENCIES = [
|
|
19
|
+
"react",
|
|
20
|
+
"react/jsx-runtime",
|
|
21
|
+
"react/jsx-dev-runtime",
|
|
22
|
+
"react-dom/client"
|
|
23
|
+
];
|
|
24
|
+
/**
|
|
25
|
+
* What the frame imports in the browser from the core's own dependencies: named through the core, as
|
|
26
|
+
* `forgebook > axe-core`, since a project need not be able to resolve them itself.
|
|
27
|
+
*/
|
|
28
|
+
const CORE_OWN_DEPENDENCIES = ["axe-core"];
|
|
29
|
+
/** Forgebook's modules the generated pages import, besides the framework's. */
|
|
30
|
+
const PAGE_MODULES = ["forgebook/shell"];
|
|
31
|
+
/** Whether a resolved file comes from an installed package rather than a linked one. */
|
|
32
|
+
const isInstalled = (file) => file.split(/[\\/]/).includes("node_modules");
|
|
33
|
+
/**
|
|
34
|
+
* The packages to pre-bundle for a catalogue.
|
|
35
|
+
*
|
|
36
|
+
* @param config - the catalogue's configuration.
|
|
37
|
+
* @param resolve - resolves a package from the catalogue's folder.
|
|
38
|
+
* @param resolveOwn - resolves a package from the core's own folder.
|
|
39
|
+
*/
|
|
40
|
+
export const prebundled = (config, resolve, resolveOwn) => {
|
|
41
|
+
const pageModules = [...PAGE_MODULES, config.framework.pages.frame, config.framework.pages.code];
|
|
42
|
+
const candidates = [
|
|
43
|
+
...CORE_BROWSER_DEPENDENCIES,
|
|
44
|
+
...(config.framework.browserDependencies ?? []),
|
|
45
|
+
...(config.hasPlayTools ? PLAY_TOOLS_PACKAGES : [])
|
|
46
|
+
];
|
|
47
|
+
const installedPages = pageModules.filter((name) => {
|
|
48
|
+
const file = resolve(name);
|
|
49
|
+
return file !== undefined && isInstalled(file);
|
|
50
|
+
});
|
|
51
|
+
const own = CORE_OWN_DEPENDENCIES.filter((name) => resolveOwn(name) !== undefined).map((name) => `forgebook > ${name}`);
|
|
52
|
+
return [
|
|
53
|
+
...new Set([...candidates.filter((name) => resolve(name) !== undefined), ...own, ...installedPages])
|
|
54
|
+
];
|
|
55
|
+
};
|
|
56
|
+
/** A `?forgebook-files` import of a source module: its pattern, before the query. */
|
|
57
|
+
const FILES_IMPORT = /["']([^"']+)\?forgebook-files["']/g;
|
|
58
|
+
/**
|
|
59
|
+
* The story files Vite scans for what their components import, before the first page opens: the project's own
|
|
60
|
+
* patterns, and each source's, read from its module's `?forgebook-files` imports (relative to the module). A source
|
|
61
|
+
* the project cannot resolve, or read, adds none.
|
|
62
|
+
*
|
|
63
|
+
* @remarks
|
|
64
|
+
* Without the sources' files, a package a source's stories import (`storybook/test`, a component's own dependency) is
|
|
65
|
+
* found only when a page imports it, and the page reloads once.
|
|
66
|
+
*
|
|
67
|
+
* @param config - the catalogue's configuration.
|
|
68
|
+
* @param resolve - resolves a source's module from the catalogue's folder.
|
|
69
|
+
* @param readText - reads a file's text; none when it cannot.
|
|
70
|
+
*/
|
|
71
|
+
export const scannedEntries = (config, resolve, readText) => {
|
|
72
|
+
const fromSources = config.sources.flatMap((specifier) => {
|
|
73
|
+
const file = resolve(specifier);
|
|
74
|
+
const text = file === undefined ? undefined : readText(file);
|
|
75
|
+
if (file === undefined || text === undefined)
|
|
76
|
+
return [];
|
|
77
|
+
return [...text.matchAll(FILES_IMPORT)].flatMap((match) => match[1] === undefined ? [] : [join(dirname(file), match[1]).split("\\").join("/")]);
|
|
78
|
+
});
|
|
79
|
+
return [...config.stories, ...fromSources];
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=prebundled.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prebundled.js","sourceRoot":"","sources":["../../../src/vite/prebundled.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,mBAAmB,EAAuB,MAAM,iBAAiB,CAAC;AAE3E,oHAAoH;AACpH,MAAM,yBAAyB,GAAG;IAChC,OAAO;IACP,mBAAmB;IACnB,uBAAuB;IACvB,kBAAkB;CACV,CAAC;AAEX;;;GAGG;AACH,MAAM,qBAAqB,GAAG,CAAC,UAAU,CAAU,CAAC;AAEpD,+EAA+E;AAC/E,MAAM,YAAY,GAAG,CAAC,iBAAiB,CAAU,CAAC;AASlD,wFAAwF;AACxF,MAAM,WAAW,GAAG,CAAC,IAAY,EAAW,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;AAE5F;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,MAAsB,EAAE,OAAgB,EAAE,UAAmB,EAAY,EAAE;IACpG,MAAM,WAAW,GAAG,CAAC,GAAG,YAAY,EAAE,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,CAA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AAS,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC7D,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,SAAS;YAAE,OAAO,EAAE,CAAC;QACxD,OAAO,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CACxD,KAAK,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CACpF,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,GAAG,MAAM,CAAC,OAAO,EAAE,GAAG,WAAW,CAAC,CAAC;AAC7C,CAAC,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The code a story shows in the catalogue's Code card: each story's `render` as written in its file, read with Vite's
|
|
3
|
+
* parser, never run.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* A story without a `render` draws the meta's component with its args: the shell writes that JSX itself from the args
|
|
7
|
+
* of the moment, so only the stories with a `render` need their text. A `render` written elsewhere (a helper the
|
|
8
|
+
* story points to) shows as the name it is given, which is what the file says.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Removes from every line past the first the indentation of the line the code starts on, so a `render` reads as if
|
|
14
|
+
* written at the left edge.
|
|
15
|
+
*
|
|
16
|
+
* @param text - the code.
|
|
17
|
+
* @param indent - the indentation of the line the code starts on, in characters.
|
|
18
|
+
*/
|
|
19
|
+
export declare const dedented: (text: string, indent: number) => string;
|
|
20
|
+
/**
|
|
21
|
+
* Each story's `render` text in a story file.
|
|
22
|
+
*
|
|
23
|
+
* @param file - the file's path, for the parser (its extension decides TypeScript and JSX) and the messages.
|
|
24
|
+
* @param text - the file's source.
|
|
25
|
+
* @returns the texts by export name, or a message saying why the file cannot be read.
|
|
26
|
+
*/
|
|
27
|
+
export declare const storyCode: (file: string, text: string) => Readonly<Record<string, string>> | string;
|
|
28
|
+
//# sourceMappingURL=storyCode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storyCode.d.ts","sourceRoot":"","sources":["../../../src/vite/storyCode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AA0BH;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,GAAI,MAAM,MAAM,EAAE,QAAQ,MAAM,KAAG,MAIvD,CAAC;AAmBF;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,GAAI,MAAM,MAAM,EAAE,MAAM,MAAM,KAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,MAczF,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The code a story shows in the catalogue's Code card: each story's `render` as written in its file, read with Vite's
|
|
3
|
+
* parser, never run.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* A story without a `render` draws the meta's component with its args: the shell writes that JSX itself from the args
|
|
7
|
+
* of the moment, so only the stories with a `render` need their text. A `render` written elsewhere (a helper the
|
|
8
|
+
* story points to) shows as the name it is given, which is what the file says.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
import { parseSync } from "vite";
|
|
13
|
+
/** An expression without the TypeScript wrappers around it (`satisfies`, `as`, parentheses). */
|
|
14
|
+
const unwrapped = (expression) => {
|
|
15
|
+
if (expression.type === "TSSatisfiesExpression" ||
|
|
16
|
+
expression.type === "TSAsExpression" ||
|
|
17
|
+
expression.type === "ParenthesizedExpression") {
|
|
18
|
+
return unwrapped(expression.expression);
|
|
19
|
+
}
|
|
20
|
+
return expression;
|
|
21
|
+
};
|
|
22
|
+
/** The `render` property of a story object, when it has one. */
|
|
23
|
+
const renderOf = (object) => object.properties.find((property) => property.type === "Property" &&
|
|
24
|
+
!property.computed &&
|
|
25
|
+
property.key.type === "Identifier" &&
|
|
26
|
+
property.key.name === "render");
|
|
27
|
+
/**
|
|
28
|
+
* Removes from every line past the first the indentation of the line the code starts on, so a `render` reads as if
|
|
29
|
+
* written at the left edge.
|
|
30
|
+
*
|
|
31
|
+
* @param text - the code.
|
|
32
|
+
* @param indent - the indentation of the line the code starts on, in characters.
|
|
33
|
+
*/
|
|
34
|
+
export const dedented = (text, indent) => {
|
|
35
|
+
const [first = "", ...rest] = text.split("\n");
|
|
36
|
+
const trimmed = rest.map((line) => line.slice(Math.min(indent, line.length - line.trimStart().length)));
|
|
37
|
+
return [first, ...trimmed].join("\n");
|
|
38
|
+
};
|
|
39
|
+
/** The indentation of the line a position is on. */
|
|
40
|
+
const indentAt = (text, position) => {
|
|
41
|
+
const lineStart = text.lastIndexOf("\n", position - 1) + 1;
|
|
42
|
+
const line = text.slice(lineStart, position);
|
|
43
|
+
return line.length - line.trimStart().length;
|
|
44
|
+
};
|
|
45
|
+
/** A story's `render` text, when the declaration is a story object with one. */
|
|
46
|
+
const renderText = (declarator, text) => {
|
|
47
|
+
if (declarator.init === null || declarator.init === undefined)
|
|
48
|
+
return undefined;
|
|
49
|
+
const init = unwrapped(declarator.init);
|
|
50
|
+
const render = init.type === "ObjectExpression" ? renderOf(init) : undefined;
|
|
51
|
+
if (render?.type !== "Property")
|
|
52
|
+
return undefined;
|
|
53
|
+
const { start, end } = render.value;
|
|
54
|
+
return dedented(text.slice(start, end), indentAt(text, start));
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Each story's `render` text in a story file.
|
|
58
|
+
*
|
|
59
|
+
* @param file - the file's path, for the parser (its extension decides TypeScript and JSX) and the messages.
|
|
60
|
+
* @param text - the file's source.
|
|
61
|
+
* @returns the texts by export name, or a message saying why the file cannot be read.
|
|
62
|
+
*/
|
|
63
|
+
export const storyCode = (file, text) => {
|
|
64
|
+
const { program, errors } = parseSync(file, text);
|
|
65
|
+
const [error] = errors;
|
|
66
|
+
if (error !== undefined)
|
|
67
|
+
return `${file} does not parse: ${error.message}`;
|
|
68
|
+
const code = {};
|
|
69
|
+
for (const statement of program.body) {
|
|
70
|
+
if (statement.type !== "ExportNamedDeclaration" || statement.declaration?.type !== "VariableDeclaration")
|
|
71
|
+
continue;
|
|
72
|
+
for (const declarator of statement.declaration.declarations) {
|
|
73
|
+
const render = renderText(declarator, text);
|
|
74
|
+
if (declarator.id.type === "Identifier" && render !== undefined)
|
|
75
|
+
code[declarator.id.name] = render;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return code;
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=storyCode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storyCode.js","sourceRoot":"","sources":["../../../src/vite/storyCode.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAe,SAAS,EAAE,MAAM,MAAM,CAAC;AAE9C,gGAAgG;AAChG,MAAM,SAAS,GAAG,CAAC,UAA6B,EAAqB,EAAE;IACrE,IACE,UAAU,CAAC,IAAI,KAAK,uBAAuB;QAC3C,UAAU,CAAC,IAAI,KAAK,gBAAgB;QACpC,UAAU,CAAC,IAAI,KAAK,yBAAyB,EAC7C,CAAC;QACD,OAAO,SAAS,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAEF,gEAAgE;AAChE,MAAM,QAAQ,GAAG,CAAC,MAA+B,EAA2B,EAAE,CAC5E,MAAM,CAAC,UAAU,CAAC,IAAI,CACpB,CAAC,QAAQ,EAAE,EAAE,CACX,QAAQ,CAAC,IAAI,KAAK,UAAU;IAC5B,CAAC,QAAQ,CAAC,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CAAC,GAAG,MAAM,CAAC;QACrG,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The story files patterns match, as paths relative to `root` starting with `./` or `../`, sorted.
|
|
3
|
+
*
|
|
4
|
+
* @param root - the folder the patterns are relative to: the declaring module's.
|
|
5
|
+
* @param patterns - the patterns (`../src/**\/*.stories.tsx`).
|
|
6
|
+
*/
|
|
7
|
+
export declare const storyFileKeys: (root: string, patterns: readonly string[]) => string[];
|
|
8
|
+
/**
|
|
9
|
+
* The code of the module for one pattern.
|
|
10
|
+
*
|
|
11
|
+
* @param root - the declaring module's folder.
|
|
12
|
+
* @param pattern - the pattern before `?forgebook-files`.
|
|
13
|
+
* @param watch - adds a file whose edit renews the module (each story file: its index is in the module).
|
|
14
|
+
* @returns the module's code, or a message saying which file cannot be indexed.
|
|
15
|
+
*/
|
|
16
|
+
export declare const storyFilesModule: (root: string, pattern: string, watch: (file: string) => void) => string;
|
|
17
|
+
//# sourceMappingURL=storyFilesModule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storyFilesModule.d.ts","sourceRoot":"","sources":["../../../src/vite/storyFilesModule.ts"],"names":[],"mappings":"AAmBA;;;;;GAKG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,EAAE,UAAU,SAAS,MAAM,EAAE,KAAG,MAAM,EAOrE,CAAC;AAMZ;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,MAAM,EAAE,SAAS,MAAM,EAAE,OAAO,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,KAAG,MA2B/F,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The module that answers a `?forgebook-files` import: every story file a pattern matches, as one module with each
|
|
3
|
+
* file's index (read from its source, never run) and the loaders of its module, its component's docs and its code.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* One module per pattern, instead of an import per file: in development the browser fetched every index module one by
|
|
7
|
+
* one, a few hundred requests per frame (D-438). The keys are the files' paths relative to the declaring module
|
|
8
|
+
* (`../src/x.stories.tsx`), the same keys `storyFileKeys` gives the tests that read the files from the disk.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
import { globSync, readFileSync } from "node:fs";
|
|
13
|
+
import { join, relative, resolve } from "node:path";
|
|
14
|
+
import { autoTitle, patternBase } from "./autoTitle.js";
|
|
15
|
+
import { indexStoryFile } from "./indexStoryFile.js";
|
|
16
|
+
/**
|
|
17
|
+
* The story files patterns match, as paths relative to `root` starting with `./` or `../`, sorted.
|
|
18
|
+
*
|
|
19
|
+
* @param root - the folder the patterns are relative to: the declaring module's.
|
|
20
|
+
* @param patterns - the patterns (`../src/**\/*.stories.tsx`).
|
|
21
|
+
*/
|
|
22
|
+
export const storyFileKeys = (root, patterns) => patterns
|
|
23
|
+
.flatMap((pattern) => globSync(pattern, { cwd: root }))
|
|
24
|
+
.map((file) => {
|
|
25
|
+
const path = relative(root, join(root, file)).split("\\").join("/");
|
|
26
|
+
return path.startsWith(".") ? path : `./${path}`;
|
|
27
|
+
})
|
|
28
|
+
.sort();
|
|
29
|
+
/** An object literal of a key per file, each value written by `value`. */
|
|
30
|
+
const objectOf = (keys, value) => `{${keys.map((key) => `${JSON.stringify(key)}: ${value(key)}`).join(",\n")}}`;
|
|
31
|
+
/**
|
|
32
|
+
* The code of the module for one pattern.
|
|
33
|
+
*
|
|
34
|
+
* @param root - the declaring module's folder.
|
|
35
|
+
* @param pattern - the pattern before `?forgebook-files`.
|
|
36
|
+
* @param watch - adds a file whose edit renews the module (each story file: its index is in the module).
|
|
37
|
+
* @returns the module's code, or a message saying which file cannot be indexed.
|
|
38
|
+
*/
|
|
39
|
+
export const storyFilesModule = (root, pattern, watch) => {
|
|
40
|
+
const keys = storyFileKeys(root, [pattern]);
|
|
41
|
+
const index = {};
|
|
42
|
+
for (const key of keys) {
|
|
43
|
+
const file = resolve(root, key);
|
|
44
|
+
watch(file);
|
|
45
|
+
const title = autoTitle(patternBase(pattern), key);
|
|
46
|
+
const entry = indexStoryFile(file, readFileSync(file, "utf8"), title === undefined ? {} : { autoTitle: title });
|
|
47
|
+
if (typeof entry === "string")
|
|
48
|
+
throw new Error(entry);
|
|
49
|
+
index[key] = entry;
|
|
50
|
+
}
|
|
51
|
+
// absolute paths: the module has no folder of its own; Vite serves them under /@fs/ in development
|
|
52
|
+
const path = (key) => JSON.stringify(resolve(root, key));
|
|
53
|
+
const query = (key, name) => JSON.stringify(`${resolve(root, key)}?${name}`);
|
|
54
|
+
return [
|
|
55
|
+
"export default {",
|
|
56
|
+
`index: ${JSON.stringify(index)},`,
|
|
57
|
+
`stories: ${objectOf(keys, (key) => `() => import(${path(key)})`)},`,
|
|
58
|
+
`docs: ${objectOf(keys, (key) => `() => import(${query(key, "forgebook-docs")}).then((module) => module.default)`)},`,
|
|
59
|
+
`code: ${objectOf(keys, (key) => `() => import(${query(key, "forgebook-code")}).then((module) => module.default)`)},`,
|
|
60
|
+
`pages: ${objectOf(keys, (key) => `() => import(${query(key, "forgebook-page")}).then((module) => module.default)`)}`,
|
|
61
|
+
"};"
|
|
62
|
+
].join("\n");
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=storyFilesModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storyFilesModule.js","sourceRoot":"","sources":["../../../src/vite/storyFilesModule.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpD,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,cAAc,EA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I,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,gBAAgB,KAAK,CAAC,GAAG,EAAE,gBAAgB,CAAC,oCAAoC,CAAC,EAAE;QACrH,IAAI;KACL,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACf,CAAC,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A story file's meta, read from its source with the TypeScript compiler's parser: the value of one of its fields, the
|
|
3
|
+
* component it names and the module it imports that component from.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* CSF is the same whatever framework a story is written for, so the plugin, `forgebook-docs` and every framework's
|
|
7
|
+
* docs extractor read the meta through this module. Pure: a parsed file in, nodes or a specifier out.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import ts from "typescript-6";
|
|
12
|
+
/**
|
|
13
|
+
* The value the meta writes for one of its fields.
|
|
14
|
+
*
|
|
15
|
+
* @param source - the story file, parsed.
|
|
16
|
+
* @param name - the field's name.
|
|
17
|
+
*/
|
|
18
|
+
export declare const metaField: (source: ts.SourceFile, name: string) => ts.Expression | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* The meta's `component` identifier in a story file, when it names one.
|
|
21
|
+
*
|
|
22
|
+
* @param source - the story file, parsed.
|
|
23
|
+
*/
|
|
24
|
+
export declare const metaComponent: (source: ts.SourceFile) => ts.Expression | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* The module a story file imports its meta's component from (`./Button`), read from the file alone: no program, so
|
|
27
|
+
* it answers at once, where the docs need the package's program.
|
|
28
|
+
*
|
|
29
|
+
* @param storyFile - the story file's path, for the parser.
|
|
30
|
+
* @param text - the story file's text.
|
|
31
|
+
* @returns the import's module specifier, or none when the meta names no imported component.
|
|
32
|
+
*/
|
|
33
|
+
export declare const componentImport: (storyFile: string, text: string) => string | undefined;
|
|
34
|
+
//# sourceMappingURL=storyMeta.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storyMeta.d.ts","sourceRoot":"","sources":["../../../src/vite/storyMeta.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,MAAM,cAAc,CAAC;AAuB9B;;;;;GAKG;AACH,eAAO,MAAM,SAAS,GAAI,QAAQ,EAAE,CAAC,UAAU,EAAE,MAAM,MAAM,KAAG,EAAE,CAAC,UAAU,GAAG,SAK/E,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAI,QAAQ,EAAE,CAAC,UAAU,KAAG,EAAE,CAAC,UAAU,GAAG,SACtC,CAAC;AAEjC;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GAAI,WAAW,MAAM,EAAE,MAAM,MAAM,KAAG,MAAM,GAAG,SAgB1E,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A story file's meta, read from its source with the TypeScript compiler's parser: the value of one of its fields, the
|
|
3
|
+
* component it names and the module it imports that component from.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* CSF is the same whatever framework a story is written for, so the plugin, `forgebook-docs` and every framework's
|
|
7
|
+
* docs extractor read the meta through this module. Pure: a parsed file in, nodes or a specifier out.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import ts from "typescript-6";
|
|
12
|
+
/**
|
|
13
|
+
* The meta's object literal in a story file: its default export, without `satisfies`, `as` and parentheses.
|
|
14
|
+
*
|
|
15
|
+
* @param source - the story file, parsed.
|
|
16
|
+
*/
|
|
17
|
+
const metaObject = (source) => {
|
|
18
|
+
for (const statement of source.statements) {
|
|
19
|
+
if (!ts.isExportAssignment(statement) || statement.isExportEquals)
|
|
20
|
+
continue;
|
|
21
|
+
let expression = statement.expression;
|
|
22
|
+
while (ts.isSatisfiesExpression(expression) ||
|
|
23
|
+
ts.isAsExpression(expression) ||
|
|
24
|
+
ts.isParenthesizedExpression(expression)) {
|
|
25
|
+
expression = expression.expression;
|
|
26
|
+
}
|
|
27
|
+
return ts.isObjectLiteralExpression(expression) ? expression : undefined;
|
|
28
|
+
}
|
|
29
|
+
return undefined;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* The value the meta writes for one of its fields.
|
|
33
|
+
*
|
|
34
|
+
* @param source - the story file, parsed.
|
|
35
|
+
* @param name - the field's name.
|
|
36
|
+
*/
|
|
37
|
+
export const metaField = (source, name) => {
|
|
38
|
+
const property = metaObject(source)?.properties.find((candidate) => ts.isPropertyAssignment(candidate) && candidate.name.getText(source) === name);
|
|
39
|
+
return property !== undefined && ts.isPropertyAssignment(property) ? property.initializer : undefined;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* The meta's `component` identifier in a story file, when it names one.
|
|
43
|
+
*
|
|
44
|
+
* @param source - the story file, parsed.
|
|
45
|
+
*/
|
|
46
|
+
export const metaComponent = (source) => metaField(source, "component");
|
|
47
|
+
/**
|
|
48
|
+
* The module a story file imports its meta's component from (`./Button`), read from the file alone: no program, so
|
|
49
|
+
* it answers at once, where the docs need the package's program.
|
|
50
|
+
*
|
|
51
|
+
* @param storyFile - the story file's path, for the parser.
|
|
52
|
+
* @param text - the story file's text.
|
|
53
|
+
* @returns the import's module specifier, or none when the meta names no imported component.
|
|
54
|
+
*/
|
|
55
|
+
export const componentImport = (storyFile, text) => {
|
|
56
|
+
const source = ts.createSourceFile(storyFile, text, ts.ScriptTarget.Latest, true);
|
|
57
|
+
const expression = metaComponent(source);
|
|
58
|
+
if (expression === undefined || !ts.isIdentifier(expression))
|
|
59
|
+
return undefined;
|
|
60
|
+
const name = expression.text;
|
|
61
|
+
for (const statement of source.statements) {
|
|
62
|
+
if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier))
|
|
63
|
+
continue;
|
|
64
|
+
const clause = statement.importClause;
|
|
65
|
+
const bindings = clause?.namedBindings;
|
|
66
|
+
const isNamed = bindings !== undefined &&
|
|
67
|
+
ts.isNamedImports(bindings) &&
|
|
68
|
+
bindings.elements.some((element) => element.name.text === name);
|
|
69
|
+
if (clause?.name?.text === name || isNamed)
|
|
70
|
+
return statement.moduleSpecifier.text;
|
|
71
|
+
}
|
|
72
|
+
return undefined;
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=storyMeta.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storyMeta.js","sourceRoot":"","sources":["../../../src/vite/storyMeta.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,MAAM,cAAc,CAAC;AAE9B;;;;GAIG;AACH,MAAM,UAAU,GAAG,CAAC,MAAqB,EAA0C,EAAE;IACnF,KAAK,MAAM,SAAS,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;QAC1C,IAAI,CAAC,EAAE,CAAC,kBAAkB,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC,cAAc;YAAE,SAAS;QAC5E,IAAI,UAAU,GAAkB,SAAS,CAAC,UAAU,CAAC;QACrD,OACE,EAAE,CAAC,qBAAqB,CAAC,UAAU,CAAC;YACpC,EAAE,CAAC,cAAc,CAAC,UAAU,CAAC;YAC7B,EAAE,CAAC,yBAAyB,CAAC,UAAU,CAAC,EACxC,CAAC;YACD,UAAU,GAAG,UAAU,CAAC,UAAU,CAAC;QACrC,CAAC;QACD,OAAO,EAAE,CAAC,yBAAyB,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3E,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,MAAqB,EAAE,IAAY,EAA6B,EAAE;IAC1F,MAAM,QAAQ,GAAG,UAAU,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC,IAAI,CAClD,CAAC,SAAS,EAAE,EAAE,CAAC,EAAE,CAAC,oBAAo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