forgebook 0.3.2 → 0.4.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/README.md +917 -74
- package/dist/bin/forgebook/agentClient.d.ts +2 -1
- package/dist/bin/forgebook/agentClient.js +13 -6
- package/dist/bin/forgebook/agentGuide.d.ts +59 -0
- package/dist/bin/forgebook/agentGuide.js +203 -0
- package/dist/bin/forgebook/agentLoopCommands.mjs +22 -42
- package/dist/bin/forgebook/agentSetup/agentFiles.d.ts +55 -0
- package/dist/bin/forgebook/agentSetup/agentFiles.js +319 -0
- package/dist/bin/forgebook/agentSetup/assistantHooks.d.ts +71 -0
- package/dist/bin/forgebook/agentSetup/assistantHooks.js +125 -0
- package/dist/bin/forgebook/agentSetup/ciWorkflow.d.ts +23 -0
- package/dist/bin/forgebook/agentSetup/ciWorkflow.js +55 -0
- package/dist/bin/forgebook/agentSetup/drawCandidates.d.ts +25 -0
- package/dist/bin/forgebook/agentSetup/drawCandidates.js +116 -0
- package/dist/bin/forgebook/agentSetup/drawDiagnosis.d.ts +28 -0
- package/dist/bin/forgebook/agentSetup/drawDiagnosis.js +134 -0
- package/dist/bin/forgebook/agentSetup/drawRun.d.ts +91 -0
- package/dist/bin/forgebook/agentSetup/drawRun.js +353 -0
- package/dist/bin/forgebook/agentSetup/hookNames.d.ts +7 -0
- package/dist/bin/forgebook/agentSetup/hookNames.js +7 -0
- package/dist/bin/forgebook/agentSetup/initAgentSteps.d.ts +48 -0
- package/dist/bin/forgebook/agentSetup/initAgentSteps.js +104 -0
- package/dist/bin/forgebook/agentSetup/liftedProviders.d.ts +17 -0
- package/dist/bin/forgebook/agentSetup/liftedProviders.js +186 -0
- package/dist/bin/forgebook/agentSetup/projectRunner.d.ts +46 -0
- package/dist/bin/forgebook/agentSetup/projectRunner.js +85 -0
- package/dist/bin/forgebook/agentSetup/stopHook.d.ts +65 -0
- package/dist/bin/forgebook/agentSetup/stopHook.js +202 -0
- package/dist/bin/forgebook/agentSetup/uniformPicture.d.ts +7 -0
- package/dist/bin/forgebook/agentSetup/uniformPicture.js +98 -0
- package/dist/bin/forgebook/agentSetupCommands.d.mts +14 -0
- package/dist/bin/forgebook/agentSetupCommands.mjs +98 -0
- package/dist/bin/forgebook/agentText.d.ts +23 -3
- package/dist/bin/forgebook/agentText.js +175 -28
- package/dist/bin/forgebook/agents.md +20 -191
- package/dist/bin/forgebook/agentsText.js +2 -1
- package/dist/bin/forgebook/appBuild/appBuild.d.ts +59 -0
- package/dist/bin/forgebook/appBuild/appBuild.js +213 -0
- package/dist/bin/forgebook/appBuild/appViteConfig.d.ts +96 -0
- package/dist/bin/forgebook/appBuild/appViteConfig.js +320 -0
- package/dist/bin/forgebook/appBuild/tsconfigPaths.d.ts +14 -0
- package/dist/bin/forgebook/appBuild/tsconfigPaths.js +80 -0
- package/dist/bin/forgebook/auditCommand.d.mts +8 -0
- package/dist/bin/forgebook/auditCommand.mjs +75 -0
- package/dist/bin/forgebook/auditRun.d.ts +95 -0
- package/dist/bin/forgebook/auditRun.js +270 -0
- package/dist/bin/forgebook/browserRun.d.ts +21 -0
- package/dist/bin/forgebook/browserRun.js +57 -0
- package/dist/bin/forgebook/buildFailure.d.ts +7 -0
- package/dist/bin/forgebook/buildFailure.js +47 -0
- package/dist/bin/forgebook/buildWatch.d.ts +52 -0
- package/dist/bin/forgebook/buildWatch.js +137 -0
- package/dist/bin/forgebook/builtCatalogue.js +9 -5
- package/dist/bin/forgebook/catalogueCommands.d.ts +9 -0
- package/dist/bin/forgebook/catalogueCommands.js +23 -0
- package/dist/bin/forgebook/catalogueVite.d.ts +5 -1
- package/dist/bin/forgebook/catalogueVite.js +14 -6
- package/dist/bin/forgebook/commandCacheClaim.d.ts +18 -0
- package/dist/bin/forgebook/commandCacheClaim.js +170 -0
- package/dist/bin/forgebook/commandServer.d.ts +8 -0
- package/dist/bin/forgebook/commandServer.js +61 -13
- package/dist/bin/forgebook/forgebookCommands.mjs +105 -28
- package/dist/bin/forgebook/graphCommand.d.mts +8 -0
- package/dist/bin/forgebook/graphCommand.mjs +84 -0
- package/dist/bin/forgebook/guide/commands.md +57 -0
- package/dist/bin/forgebook/guide/devices.md +17 -0
- package/dist/bin/forgebook/guide/docs-pages.md +13 -0
- package/dist/bin/forgebook/guide/frameworks/angular.md +22 -0
- package/dist/bin/forgebook/guide/frameworks/html.md +22 -0
- package/dist/bin/forgebook/guide/frameworks/nextjs.md +23 -0
- package/dist/bin/forgebook/guide/frameworks/nuxt.md +22 -0
- package/dist/bin/forgebook/guide/frameworks/preact.md +16 -0
- package/dist/bin/forgebook/guide/frameworks/react-native-web.md +21 -0
- package/dist/bin/forgebook/guide/frameworks/react.md +16 -0
- package/dist/bin/forgebook/guide/frameworks/solid.md +18 -0
- package/dist/bin/forgebook/guide/frameworks/svelte.md +18 -0
- package/dist/bin/forgebook/guide/frameworks/sveltekit.md +23 -0
- package/dist/bin/forgebook/guide/frameworks/vue.md +18 -0
- package/dist/bin/forgebook/guide/frameworks/web-components.md +21 -0
- package/dist/bin/forgebook/guide/links.md +29 -0
- package/dist/bin/forgebook/guide/setup.md +23 -0
- package/dist/bin/forgebook/guide/stories.md +90 -0
- package/dist/bin/forgebook/guide/switches.md +43 -0
- package/dist/bin/forgebook/guideCommand.d.mts +13 -0
- package/dist/bin/forgebook/guideCommand.mjs +37 -0
- package/dist/bin/forgebook/importers/storybook.d.ts +21 -0
- package/dist/bin/forgebook/importers/storybook.js +11 -5
- package/dist/bin/forgebook/importers/storybookFrameworks.js +1 -1
- package/dist/bin/forgebook/initCommands.d.mts +11 -0
- package/dist/bin/forgebook/initCommands.mjs +51 -78
- package/dist/bin/forgebook/initConfig.d.ts +5 -3
- package/dist/bin/forgebook/initConfig.js +6 -3
- package/dist/bin/forgebook/initInstall.d.ts +15 -0
- package/dist/bin/forgebook/initInstall.js +77 -0
- package/dist/bin/forgebook/initPrint.d.ts +9 -0
- package/dist/bin/forgebook/initPrint.js +60 -0
- package/dist/bin/forgebook/initRefusals.d.ts +45 -0
- package/dist/bin/forgebook/initRefusals.js +91 -0
- package/dist/bin/forgebook/initRun.d.ts +28 -0
- package/dist/bin/forgebook/initRun.js +311 -0
- package/dist/bin/forgebook/mcpCommand.mjs +38 -4
- package/dist/bin/forgebook/mcpGraph.d.ts +13 -0
- package/dist/bin/forgebook/mcpGraph.js +24 -0
- package/dist/bin/forgebook/mcpTokens.d.ts +14 -0
- package/dist/bin/forgebook/mcpTokens.js +58 -0
- package/dist/bin/forgebook/mcpToolParts.d.ts +7 -0
- package/dist/bin/forgebook/mcpToolParts.js +10 -0
- package/dist/bin/forgebook/mcpTools.d.ts +13 -6
- package/dist/bin/forgebook/mcpTools.js +57 -90
- package/dist/bin/forgebook/mcpVerify.d.ts +16 -0
- package/dist/bin/forgebook/mcpVerify.js +36 -0
- package/dist/bin/forgebook/migrate/codemods.d.ts +11 -0
- package/dist/bin/forgebook/migrate/codemods.js +61 -0
- package/dist/bin/forgebook/migrate/migrate.types.d.ts +117 -0
- package/dist/bin/forgebook/migrate/migrate.types.js +5 -0
- package/dist/bin/forgebook/migrate/migrateCommand.d.mts +8 -0
- package/dist/bin/forgebook/migrate/migrateCommand.mjs +76 -0
- package/dist/bin/forgebook/migrate/migrateRun.d.ts +61 -0
- package/dist/bin/forgebook/migrate/migrateRun.js +210 -0
- package/dist/bin/forgebook/migrate/migrateText.d.ts +12 -0
- package/dist/bin/forgebook/migrate/migrateText.js +30 -0
- package/dist/bin/forgebook/migrate/migrateWrite.d.ts +27 -0
- package/dist/bin/forgebook/migrate/migrateWrite.js +66 -0
- package/dist/bin/forgebook/migrate/objectEdits.d.ts +70 -0
- package/dist/bin/forgebook/migrate/objectEdits.js +241 -0
- package/dist/bin/forgebook/migrate/playOnInBuilds.d.ts +3 -0
- package/dist/bin/forgebook/migrate/playOnInBuilds.js +86 -0
- package/dist/bin/forgebook/migrate/propGroupStrings.d.ts +5 -0
- package/dist/bin/forgebook/migrate/propGroupStrings.js +81 -0
- package/dist/bin/forgebook/newProject/newProject.d.ts +39 -0
- package/dist/bin/forgebook/newProject/newProject.js +180 -0
- package/dist/bin/forgebook/newProject/newProject.types.d.ts +97 -0
- package/dist/bin/forgebook/newProject/newProject.types.js +6 -0
- package/dist/bin/forgebook/newProject/packageManagers.d.ts +51 -0
- package/dist/bin/forgebook/newProject/packageManagers.js +121 -0
- package/dist/bin/forgebook/newProject/projectEntries.d.ts +62 -0
- package/dist/bin/forgebook/newProject/projectEntries.js +191 -0
- package/dist/bin/forgebook/newProject/projectFrameworks.d.ts +57 -0
- package/dist/bin/forgebook/newProject/projectFrameworks.js +148 -0
- package/dist/bin/forgebook/newProject/projectLook.d.ts +23 -0
- package/dist/bin/forgebook/newProject/projectLook.js +293 -0
- package/dist/bin/forgebook/newProject/projectPackages.d.ts +66 -0
- package/dist/bin/forgebook/newProject/projectPackages.js +178 -0
- package/dist/bin/forgebook/newRepair.d.ts +45 -0
- package/dist/bin/forgebook/newRepair.js +157 -0
- package/dist/bin/forgebook/newRepairRun.d.ts +69 -0
- package/dist/bin/forgebook/newRepairRun.js +148 -0
- package/dist/bin/forgebook/newStories.d.ts +23 -1
- package/dist/bin/forgebook/newStories.js +101 -11
- package/dist/bin/forgebook/newStoriesFile.d.ts +20 -1
- package/dist/bin/forgebook/newStoriesFile.js +43 -4
- package/dist/bin/forgebook/prebundleRun.d.ts +3 -1
- package/dist/bin/forgebook/prebundleRun.js +28 -8
- package/dist/bin/forgebook/proofCommand.d.mts +15 -0
- package/dist/bin/forgebook/proofCommand.mjs +212 -0
- package/dist/bin/forgebook/proofRun.d.ts +63 -0
- package/dist/bin/forgebook/proofRun.js +412 -0
- package/dist/bin/forgebook/proofText.d.ts +36 -0
- package/dist/bin/forgebook/proofText.js +131 -0
- package/dist/bin/forgebook/proofWorkflow.d.ts +29 -0
- package/dist/bin/forgebook/proofWorkflow.js +205 -0
- package/dist/bin/forgebook/setArgsTool.d.ts +8 -0
- package/dist/bin/forgebook/setArgsTool.js +70 -0
- package/dist/bin/forgebook/storyCheckCommands.mjs +42 -3
- package/dist/bin/forgebook/storyCheckRun.d.ts +50 -0
- package/dist/bin/forgebook/storyCheckRun.js +83 -9
- package/dist/bin/forgebook/storyFileIds.d.ts +15 -0
- package/dist/bin/forgebook/storyFileIds.js +14 -0
- package/dist/bin/forgebook/stressCases.d.ts +31 -0
- package/dist/bin/forgebook/stressCases.js +79 -0
- package/dist/bin/forgebook/stressRun.d.ts +12 -0
- package/dist/bin/forgebook/stressRun.js +61 -0
- package/dist/bin/forgebook/stressText.d.ts +27 -0
- package/dist/bin/forgebook/stressText.js +46 -0
- package/dist/bin/forgebook/verifyBase.d.ts +45 -0
- package/dist/bin/forgebook/verifyBase.js +196 -0
- package/dist/bin/forgebook/verifyCommand.d.mts +13 -0
- package/dist/bin/forgebook/verifyCommand.mjs +125 -0
- package/dist/bin/forgebook/verifyRun.d.ts +63 -0
- package/dist/bin/forgebook/verifyRun.js +108 -0
- package/dist/bin/forgebook/verifyVerdict.d.ts +40 -0
- package/dist/bin/forgebook/verifyVerdict.js +297 -0
- package/dist/bin/forgebook/workflowActions.d.ts +23 -0
- package/dist/bin/forgebook/workflowActions.js +23 -0
- package/dist/bin/forgebook-docs/catalogueMarkdown.js +12 -1
- package/dist/src/addressArgs.d.ts +54 -6
- package/dist/src/addressArgs.js +72 -16
- package/dist/src/addressArgsParam.d.ts +54 -0
- package/dist/src/addressArgsParam.js +51 -0
- package/dist/src/addressTexts.d.ts +14 -0
- package/dist/src/addressTexts.js +28 -21
- package/dist/src/agentIndexFile.d.ts +11 -0
- package/dist/src/agentIndexFile.js +11 -0
- package/dist/src/argConditions.d.ts +52 -0
- package/dist/src/argConditions.js +80 -0
- package/dist/src/argControl.d.ts +100 -0
- package/dist/src/argControl.js +0 -0
- package/dist/src/argExpression.d.ts +21 -0
- package/dist/src/argExpression.js +30 -0
- package/dist/src/argTypes.d.ts +40 -51
- package/dist/src/argTypes.js +66 -184
- package/dist/src/argsProps.d.ts +3 -3
- package/dist/src/argsProps.js +11 -5
- package/dist/src/bundlerErrors.d.ts +29 -0
- package/dist/src/bundlerErrors.js +49 -0
- package/dist/src/catalogue.d.ts +31 -0
- package/dist/src/catalogue.js +13 -2
- package/dist/src/catalogueRefs.d.ts +75 -0
- package/dist/src/catalogueRefs.js +122 -0
- package/dist/src/componentDocs.d.ts +71 -0
- package/dist/src/componentDocs.js +15 -2
- package/dist/src/frame/callValues.d.ts +19 -0
- package/dist/src/frame/callValues.js +58 -0
- package/dist/src/frame/canvasScheme.d.ts +33 -0
- package/dist/src/frame/canvasScheme.js +67 -0
- package/dist/src/frame/frame.css +36 -3
- package/dist/src/frame/frameStatus.d.ts +16 -1
- package/dist/src/frame/frameStatus.js +16 -1
- package/dist/src/frame/frameView.js +4 -3
- package/dist/src/frame/mountFrame.d.ts +7 -1
- package/dist/src/frame/mountFrame.js +153 -46
- package/dist/src/frame/panelValues.d.ts +35 -0
- package/dist/src/frame/panelValues.js +127 -0
- package/dist/src/frame/playActions.d.ts +39 -0
- package/dist/src/frame/playActions.js +98 -0
- package/dist/src/frame/playStepper.d.ts +28 -0
- package/dist/src/frame/playStepper.js +38 -0
- package/dist/src/frame/playStory.d.ts +9 -1
- package/dist/src/frame/playStory.js +49 -3
- package/dist/src/frame/renderer.d.ts +34 -1
- package/dist/src/frame/renderer.js +24 -0
- package/dist/src/frame/shellChannel.d.ts +1 -1
- package/dist/src/frame/shellChannel.js +1 -1
- package/dist/src/frame/shellCheck.d.ts +17 -0
- package/dist/src/frame/shellCheck.js +25 -0
- package/dist/src/frame/shellMessageCheck.d.ts +7 -0
- package/dist/src/frame/shellMessageCheck.js +53 -0
- package/dist/src/frame/storyContent.d.ts +50 -0
- package/dist/src/frame/storyContent.js +73 -0
- package/dist/src/frame/storyModule.d.ts +9 -0
- package/dist/src/frame/storyModule.js +20 -2
- package/dist/src/frame/storyRun.d.ts +15 -7
- package/dist/src/frame/storyRun.js +64 -15
- package/dist/src/frame/valueSheets.d.ts +35 -0
- package/dist/src/frame/valueSheets.js +99 -0
- package/dist/src/hotModules.d.ts +20 -0
- package/dist/src/hotModules.js +23 -0
- package/dist/src/jsxCode.d.ts +1 -14
- package/dist/src/jsxCode.js +46 -10
- package/dist/src/liveErrors.d.ts +30 -4
- package/dist/src/liveErrors.js +18 -3
- package/dist/src/messages.d.ts +77 -27
- package/dist/src/messages.js +58 -100
- package/dist/src/namedValues.d.ts +2 -26
- package/dist/src/namedValues.js +0 -47
- package/dist/src/pageConfig.d.ts +2 -0
- package/dist/src/playTrace.d.ts +19 -2
- package/dist/src/playTrace.js +10 -5
- package/dist/src/plugin.d.ts +10 -3
- package/dist/src/previewRelay.js +9 -1
- package/dist/src/printable.d.ts +12 -0
- package/dist/src/printable.js +22 -0
- package/dist/src/propsSignature.d.ts +37 -0
- package/dist/src/propsSignature.js +40 -0
- package/dist/src/search.d.ts +41 -5
- package/dist/src/search.js +93 -23
- package/dist/src/searchMatch.d.ts +4 -1
- package/dist/src/searchMatch.js +26 -5
- package/dist/src/searchTypos.d.ts +88 -0
- package/dist/src/searchTypos.js +178 -0
- package/dist/src/shapeValues.d.ts +86 -0
- package/dist/src/shapeValues.js +295 -0
- package/dist/src/shell/ApiReference.js +6 -3
- package/dist/src/shell/ApiTableBox.d.ts +15 -0
- package/dist/src/shell/ApiTableBox.js +11 -0
- package/dist/src/shell/AppearanceMenu.d.ts +4 -1
- package/dist/src/shell/AppearanceMenu.js +9 -6
- package/dist/src/shell/CodeTab.d.ts +3 -2
- package/dist/src/shell/CodeTab.js +3 -2
- package/dist/src/shell/CodeText.d.ts +1 -1
- package/dist/src/shell/CodeText.js +2 -3
- package/dist/src/shell/CompareGrid.js +1 -1
- package/dist/src/shell/ComponentPage.d.ts +1 -1
- package/dist/src/shell/ComponentPage.js +5 -1
- package/dist/src/shell/CustomControl.d.ts +34 -0
- package/dist/src/shell/CustomControl.js +132 -0
- package/dist/src/shell/DocContainers.js +1 -1
- package/dist/src/shell/DocPage.js +2 -2
- package/dist/src/shell/DroppedArgsList.d.ts +2 -2
- package/dist/src/shell/DroppedArgsList.js +1 -1
- package/dist/src/shell/EmbedPage.js +58 -14
- package/dist/src/shell/Example.d.ts +5 -1
- package/dist/src/shell/Example.js +16 -8
- package/dist/src/shell/FrameView.d.ts +6 -3
- package/dist/src/shell/FrameView.js +2 -2
- package/dist/src/shell/HomePage.d.ts +3 -1
- package/dist/src/shell/HomePage.js +16 -6
- package/dist/src/shell/InfoTip.js +2 -2
- package/dist/src/shell/InteractionsTab.d.ts +11 -4
- package/dist/src/shell/InteractionsTab.js +18 -2
- package/dist/src/shell/LazyPage.js +1 -1
- package/dist/src/shell/PackageHtml.js +3 -1
- package/dist/src/shell/PinnedControl.js +14 -62
- package/dist/src/shell/PinnedControlMenu.d.ts +44 -0
- package/dist/src/shell/PinnedControlMenu.js +72 -0
- package/dist/src/shell/PluginBlockHost.js +2 -1
- package/dist/src/shell/PluginTabHost.js +19 -2
- package/dist/src/shell/PropFields.d.ts +3 -1
- package/dist/src/shell/PropFields.js +9 -6
- package/dist/src/shell/PropRows.d.ts +23 -2
- package/dist/src/shell/PropRows.js +58 -19
- package/dist/src/shell/PropsTab.d.ts +12 -5
- package/dist/src/shell/PropsTab.js +9 -21
- package/dist/src/shell/RefStoryPage.d.ts +33 -0
- package/dist/src/shell/RefStoryPage.js +123 -0
- package/dist/src/shell/SearchPanel.js +51 -24
- package/dist/src/shell/Shell.d.ts +18 -0
- package/dist/src/shell/Shell.js +137 -22
- package/dist/src/shell/ShortcutHelp.d.ts +22 -0
- package/dist/src/shell/ShortcutHelp.js +66 -0
- package/dist/src/shell/Sidebar.d.ts +17 -4
- package/dist/src/shell/Sidebar.js +92 -41
- package/dist/src/shell/SidebarDocs.js +2 -2
- package/dist/src/shell/SidebarEntries.js +5 -3
- package/dist/src/shell/SidebarHandle.d.ts +3 -5
- package/dist/src/shell/SidebarHandle.js +4 -4
- package/dist/src/shell/SidebarRefs.d.ts +39 -0
- package/dist/src/shell/SidebarRefs.js +99 -0
- package/dist/src/shell/SidebarSearch.js +37 -9
- package/dist/src/shell/SignatureReference.js +3 -1
- package/dist/src/shell/Stage.d.ts +10 -2
- package/dist/src/shell/Stage.js +35 -60
- package/dist/src/shell/StatusBadges.d.ts +54 -0
- package/dist/src/shell/StatusBadges.js +77 -0
- package/dist/src/shell/StoryCodeBlock.d.ts +8 -19
- package/dist/src/shell/StoryCodeBlock.js +7 -6
- package/dist/src/shell/SwitchGallery.d.ts +36 -0
- package/dist/src/shell/SwitchGallery.js +17 -0
- package/dist/src/shell/SwitchGalleryPanel.d.ts +37 -0
- package/dist/src/shell/SwitchGalleryPanel.js +99 -0
- package/dist/src/shell/TagFilter.d.ts +24 -0
- package/dist/src/shell/TagFilter.js +45 -0
- package/dist/src/shell/TagViews.d.ts +39 -0
- package/dist/src/shell/TagViews.js +20 -0
- package/dist/src/shell/Toolbar.d.ts +4 -1
- package/dist/src/shell/Toolbar.js +17 -7
- package/dist/src/shell/ToolbarControl.d.ts +3 -0
- package/dist/src/shell/ToolbarControl.js +23 -6
- package/dist/src/shell/ViewMenuPanel.js +6 -1
- package/dist/src/shell/argChecks.d.ts +22 -0
- package/dist/src/shell/argChecks.js +20 -0
- package/dist/src/shell/asideStory.d.ts +17 -4
- package/dist/src/shell/asideStory.js +21 -4
- package/dist/src/shell/audienceSections.css +9 -9
- package/dist/src/shell/catalogueContext.d.ts +1 -1
- package/dist/src/shell/catalogueContext.js +6 -1
- package/dist/src/shell/codeSpans.d.ts +27 -0
- package/dist/src/shell/codeSpans.js +76 -0
- package/dist/src/shell/compareVariants.d.ts +4 -2
- package/dist/src/shell/compareVariants.js +16 -8
- package/dist/src/shell/composition.d.ts +23 -0
- package/dist/src/shell/composition.js +26 -0
- package/dist/src/shell/controlCycle.d.ts +1 -1
- package/dist/src/shell/controlCycle.js +3 -2
- package/dist/src/shell/customControls.d.ts +55 -0
- package/dist/src/shell/customControls.js +70 -0
- package/dist/src/shell/docPage.css +22 -22
- package/dist/src/shell/dockTabs.d.ts +19 -3
- package/dist/src/shell/dockTabs.js +28 -20
- package/dist/src/shell/embed.css +7 -7
- package/dist/src/shell/framesOrigin.d.ts +7 -0
- package/dist/src/shell/framesOrigin.js +1 -1
- package/dist/src/shell/galleryPlace.d.ts +20 -0
- package/dist/src/shell/galleryPlace.js +26 -0
- package/dist/src/shell/icons.d.ts +1 -0
- package/dist/src/shell/icons.js +1 -0
- package/dist/src/shell/keyboard.d.ts +14 -12
- package/dist/src/shell/keyboard.js +21 -6
- package/dist/src/shell/laterStrings.d.ts +29 -0
- package/dist/src/shell/laterStrings.js +42 -3
- package/dist/src/shell/mountShell.js +3 -0
- package/dist/src/shell/pageStrings.d.ts +4 -0
- package/dist/src/shell/pageStrings.js +4 -0
- package/dist/src/shell/pageTagView.d.ts +18 -0
- package/dist/src/shell/pageTagView.js +10 -0
- package/dist/src/shell/playMemory.d.ts +14 -0
- package/dist/src/shell/playMemory.js +8 -0
- package/dist/src/shell/propNotes.d.ts +23 -0
- package/dist/src/shell/propNotes.js +37 -0
- package/dist/src/shell/refIndexLoad.d.ts +17 -0
- package/dist/src/shell/refIndexLoad.js +38 -0
- package/dist/src/shell/refParts.d.ts +34 -0
- package/dist/src/shell/refParts.js +9 -0
- package/dist/src/shell/refStory.css +21 -0
- package/dist/src/shell/refStrings.d.ts +13 -0
- package/dist/src/shell/refStrings.js +21 -0
- package/dist/src/shell/search.css +11 -11
- package/dist/src/shell/shell.css +348 -168
- package/dist/src/shell/shellScheme.js +2 -2
- package/dist/src/shell/shortcutHelp.css +64 -0
- package/dist/src/shell/stageArgs.d.ts +53 -0
- package/dist/src/shell/stageArgs.js +64 -0
- package/dist/src/shell/statusBadges.css +51 -0
- package/dist/src/shell/strings.d.ts +7 -16
- package/dist/src/shell/strings.js +12 -17
- package/dist/src/shell/switchGallery.css +104 -0
- package/dist/src/shell/tagFilter.css +46 -0
- package/dist/src/shell/tagView.d.ts +20 -0
- package/dist/src/shell/tagView.js +10 -0
- package/dist/src/shell/useAddressArgs.d.ts +27 -2
- package/dist/src/shell/useAddressArgs.js +71 -14
- package/dist/src/shell/useControlKeys.js +2 -2
- package/dist/src/shell/useEditedProblems.d.ts +6 -0
- package/dist/src/shell/useEditedProblems.js +40 -0
- package/dist/src/shell/useFrameMessages.js +3 -0
- package/dist/src/shell/useListedTree.d.ts +13 -0
- package/dist/src/shell/useListedTree.js +32 -0
- package/dist/src/shell/usePageFrames.js +2 -2
- package/dist/src/shell/usePopover.d.ts +5 -0
- package/dist/src/shell/usePopover.js +7 -1
- package/dist/src/shell/useRefIndex.d.ts +22 -0
- package/dist/src/shell/useRefIndex.js +36 -0
- package/dist/src/shell/useScrollStops.d.ts +20 -0
- package/dist/src/shell/useScrollStops.js +41 -0
- package/dist/src/shell/useShortcutHelp.d.ts +18 -0
- package/dist/src/shell/useShortcutHelp.js +32 -0
- package/dist/src/shell/useSidebarOverlay.d.ts +2 -1
- package/dist/src/shell/useSidebarOverlay.js +12 -4
- package/dist/src/shell/useStoryCode.d.ts +2 -1
- package/dist/src/shell/useStoryCode.js +12 -7
- package/dist/src/shell/useToolbarLayout.d.ts +5 -1
- package/dist/src/shell/useToolbarLayout.js +2 -2
- package/dist/src/shell/useWorstCase.d.ts +8 -2
- package/dist/src/shell/useWorstCase.js +2 -2
- package/dist/src/shell/valueEditors/FileEditor.d.ts +28 -0
- package/dist/src/shell/valueEditors/FileEditor.js +66 -0
- package/dist/src/shell/valueEditors/JsonEditor.d.ts +14 -0
- package/dist/src/shell/valueEditors/JsonEditor.js +53 -0
- package/dist/src/shell/valueEditors/ListEditor.d.ts +24 -0
- package/dist/src/shell/valueEditors/ListEditor.js +82 -0
- package/dist/src/shell/valueEditors/ObjectEditor.d.ts +32 -0
- package/dist/src/shell/valueEditors/ObjectEditor.js +70 -0
- package/dist/src/shell/valueEditors/PropEditor.d.ts +37 -0
- package/dist/src/shell/valueEditors/PropEditor.js +53 -0
- package/dist/src/shell/valueEditors/RecordEditor.d.ts +20 -0
- package/dist/src/shell/valueEditors/RecordEditor.js +84 -0
- package/dist/src/shell/valueEditors/SearchSelect.d.ts +42 -0
- package/dist/src/shell/valueEditors/SearchSelect.js +80 -0
- package/dist/src/shell/valueEditors/TokenEditor.d.ts +49 -0
- package/dist/src/shell/valueEditors/TokenEditor.js +74 -0
- package/dist/src/shell/valueEditors/UnionEditor.d.ts +20 -0
- package/dist/src/shell/valueEditors/UnionEditor.js +64 -0
- package/dist/src/shell/valueEditors/ValueField.d.ts +15 -0
- package/dist/src/shell/valueEditors/ValueField.js +147 -0
- package/dist/src/shell/valueEditors/editorStrings.d.ts +56 -0
- package/dist/src/shell/valueEditors/editorStrings.js +66 -0
- package/dist/src/shell/valueEditors/fieldTypes.d.ts +31 -0
- package/dist/src/shell/valueEditors/fieldTypes.js +0 -0
- package/dist/src/shell/valueEditors/valueEditors.css +153 -0
- package/dist/src/shell/worstArgs.d.ts +8 -5
- package/dist/src/shell/worstArgs.js +14 -7
- package/dist/src/shellTheme.d.ts +1 -1
- package/dist/src/shellTheme.js +15 -1
- package/dist/src/shellTheme.types.d.ts +4 -0
- package/dist/src/shellWord.d.ts +12 -0
- package/dist/src/shellWord.js +15 -0
- package/dist/src/sourceFiles.js +2 -1
- package/dist/src/storyArgTypes.d.ts +57 -0
- package/dist/src/storyArgTypes.js +195 -0
- package/dist/src/storyBackground.js +14 -3
- package/dist/src/storyCheck.d.ts +85 -3
- package/dist/src/storyCheck.js +23 -1
- package/dist/src/storyCodeText.d.ts +46 -0
- package/dist/src/storyCodeText.js +27 -0
- package/dist/src/storyControls.d.ts +100 -0
- package/dist/src/storyControls.js +100 -0
- package/dist/src/storyStatuses.d.ts +55 -0
- package/dist/src/storyStatuses.js +104 -0
- package/dist/src/storyTagNames.d.ts +25 -0
- package/dist/src/storyTagNames.js +25 -0
- package/dist/src/storyTags.d.ts +29 -0
- package/dist/src/storyTags.js +85 -0
- package/dist/src/storyTree.d.ts +13 -0
- package/dist/src/storyTree.js +24 -4
- package/dist/src/storybookArgs.d.ts +24 -0
- package/dist/src/storybookArgs.js +185 -0
- package/dist/src/switches.d.ts +66 -3
- package/dist/src/switches.js +42 -1
- package/dist/src/valueSchema.d.ts +28 -0
- package/dist/src/valueSchema.js +196 -0
- package/dist/src/valueShape.d.ts +94 -0
- package/dist/src/valueShape.js +25 -0
- package/dist/src/viewState.d.ts +8 -3
- package/dist/src/viewState.js +27 -10
- package/dist/src/vite/adapter.d.ts +40 -2
- package/dist/src/vite/adapter.js +1 -0
- package/dist/src/vite/agent.types.d.ts +347 -7
- package/dist/src/vite/agentApi.d.ts +23 -0
- package/dist/src/vite/agentApi.js +90 -17
- package/dist/src/vite/agentIndex.d.ts +0 -2
- package/dist/src/vite/agentIndex.js +5 -6
- package/dist/src/vite/agentRoutes.d.ts +20 -1
- package/dist/src/vite/agentRoutes.js +106 -65
- package/dist/src/vite/agentStatuses.d.ts +42 -0
- package/dist/src/vite/agentStatuses.js +67 -0
- package/dist/src/vite/agentStoryCode.d.ts +48 -0
- package/dist/src/vite/agentStoryCode.js +38 -0
- package/dist/src/vite/agentVisibility.d.ts +47 -0
- package/dist/src/vite/agentVisibility.js +174 -0
- package/dist/src/vite/appAudit.d.ts +134 -0
- package/dist/src/vite/appAudit.js +333 -0
- package/dist/src/vite/appBuildOption.d.ts +53 -0
- package/dist/src/vite/appBuildOption.js +55 -0
- package/dist/src/vite/appTokenFiles.d.ts +92 -0
- package/dist/src/vite/appTokenFiles.js +433 -0
- package/dist/src/vite/appTokens.d.ts +23 -0
- package/dist/src/vite/appTokens.js +275 -0
- package/dist/src/vite/builtTexts.d.ts +10 -0
- package/dist/src/vite/builtTexts.js +59 -22
- package/dist/src/vite/catalogueConfig.d.ts +3 -1
- package/dist/src/vite/catalogueConfig.js +15 -3
- package/dist/src/vite/changeCoverage.d.ts +74 -0
- package/dist/src/vite/changeCoverage.js +120 -0
- package/dist/src/vite/changedRoute.d.ts +30 -0
- package/dist/src/vite/changedRoute.js +197 -0
- package/dist/src/vite/checkCode.d.ts +105 -3
- package/dist/src/vite/checkCode.js +323 -36
- package/dist/src/vite/checkoutWatch.d.ts +97 -0
- package/dist/src/vite/checkoutWatch.js +287 -0
- package/dist/src/vite/closeWatch.d.ts +8 -0
- package/dist/src/vite/closeWatch.js +1 -1
- package/dist/src/vite/componentCache.d.ts +8 -0
- package/dist/src/vite/componentCache.js +66 -0
- package/dist/src/vite/componentGraph.d.ts +71 -0
- package/dist/src/vite/componentGraph.js +133 -0
- package/dist/src/vite/componentRules.d.ts +33 -0
- package/dist/src/vite/componentRules.js +105 -0
- package/dist/src/vite/componentScan.d.ts +69 -0
- package/dist/src/vite/componentScan.js +418 -0
- package/dist/src/vite/compositionCheck.d.ts +15 -0
- package/dist/src/vite/compositionCheck.js +243 -0
- package/dist/src/vite/config.d.ts +32 -1
- package/dist/src/vite/configFile.d.ts +14 -2
- package/dist/src/vite/configFile.js +124 -40
- package/dist/src/vite/configKeys.d.ts +15 -0
- package/dist/src/vite/configKeys.js +171 -0
- package/dist/src/vite/configLoadError.d.ts +23 -0
- package/dist/src/vite/configLoadError.js +71 -0
- package/dist/src/vite/cssDeclarations.d.ts +71 -0
- package/dist/src/vite/cssDeclarations.js +290 -0
- package/dist/src/vite/cssImports.d.ts +14 -0
- package/dist/src/vite/cssImports.js +48 -0
- package/dist/src/vite/cssReferences.d.ts +54 -0
- package/dist/src/vite/cssReferences.js +157 -0
- package/dist/src/vite/cssTokenValues.d.ts +50 -0
- package/dist/src/vite/cssTokenValues.js +233 -0
- package/dist/src/vite/designTokens.d.ts +24 -0
- package/dist/src/vite/designTokens.js +5 -1
- package/dist/src/vite/docsExtractor.d.ts +9 -3
- package/dist/src/vite/docsExtractor.js +11 -3
- package/dist/src/vite/docsProgram.d.ts +17 -4
- package/dist/src/vite/docsProgram.js +52 -11
- package/dist/src/vite/docsWorker.js +7 -2
- package/dist/src/vite/emptyStoryGlobs.d.ts +41 -0
- package/dist/src/vite/emptyStoryGlobs.js +52 -0
- package/dist/src/vite/fileImports.d.ts +17 -0
- package/dist/src/vite/fileImports.js +57 -0
- package/dist/src/vite/findComponent.d.ts +10 -2
- package/dist/src/vite/findComponent.js +27 -22
- package/dist/src/vite/findRoute.js +3 -2
- package/dist/src/vite/forcedStates.d.ts +9 -2
- package/dist/src/vite/forcedStates.js +12 -3
- package/dist/src/vite/forgebookPlugin.d.ts +2 -0
- package/dist/src/vite/forgebookPlugin.js +52 -72
- package/dist/src/vite/frameErrors.d.ts +19 -0
- package/dist/src/vite/frameErrors.js +70 -0
- package/dist/src/vite/framesServer.d.ts +12 -0
- package/dist/src/vite/framesServer.js +21 -4
- package/dist/src/vite/functionComponentDocs.js +81 -12
- package/dist/src/vite/generatedModules.js +4 -2
- package/dist/src/vite/gitChange.d.ts +38 -5
- package/dist/src/vite/gitChange.js +71 -11
- package/dist/src/vite/hiddenStoryFiles.d.ts +23 -0
- package/dist/src/vite/hiddenStoryFiles.js +107 -0
- package/dist/src/vite/hotSnippets.d.ts +38 -14
- package/dist/src/vite/hotSnippets.js +137 -39
- package/dist/src/vite/importedNames.d.ts +37 -0
- package/dist/src/vite/importedNames.js +138 -0
- package/dist/src/vite/indexFields.d.ts +6 -0
- package/dist/src/vite/indexFields.js +21 -0
- package/dist/src/vite/indexStoryFile.d.ts +8 -1
- package/dist/src/vite/indexStoryFile.js +22 -157
- package/dist/src/vite/jsxCallSites.d.ts +33 -0
- package/dist/src/vite/jsxCallSites.js +200 -0
- package/dist/src/vite/jsxInScripts.d.ts +67 -0
- package/dist/src/vite/jsxInScripts.js +138 -0
- package/dist/src/vite/jsxTree.d.ts +20 -0
- package/dist/src/vite/jsxTree.js +163 -0
- package/dist/src/vite/lineAndColumn.d.ts +13 -0
- package/dist/src/vite/lineAndColumn.js +18 -0
- package/dist/src/vite/lookAlikes.d.ts +65 -0
- package/dist/src/vite/lookAlikes.js +228 -0
- package/dist/src/vite/nearestToken.d.ts +17 -0
- package/dist/src/vite/nearestToken.js +9 -2
- package/dist/src/vite/packageEntries.d.ts +42 -0
- package/dist/src/vite/packageEntries.js +127 -0
- package/dist/src/vite/pages.d.ts +9 -1
- package/dist/src/vite/pages.js +108 -4
- package/dist/src/vite/pluginConfig.js +4 -0
- package/dist/src/vite/pluginIds.d.ts +2 -0
- package/dist/src/vite/pluginIds.js +5 -1
- package/dist/src/vite/pluginModules.d.ts +81 -11
- package/dist/src/vite/pluginModules.js +109 -21
- package/dist/src/vite/prebundled.d.ts +57 -15
- package/dist/src/vite/prebundled.js +80 -0
- package/dist/src/vite/previewTags.d.ts +25 -0
- package/dist/src/vite/previewTags.js +56 -0
- package/dist/src/vite/projectFiles.d.ts +54 -0
- package/dist/src/vite/projectFiles.js +116 -0
- package/dist/src/vite/projectPostcss.d.ts +70 -0
- package/dist/src/vite/projectPostcss.js +250 -0
- package/dist/src/vite/propDocs.d.ts +12 -0
- package/dist/src/vite/propDocs.js +130 -58
- package/dist/src/vite/propKind.d.ts +40 -0
- package/dist/src/vite/propKind.js +71 -0
- package/dist/src/vite/propTypeNotes.d.ts +22 -0
- package/dist/src/vite/propTypeNotes.js +51 -0
- package/dist/src/vite/publishedExports.d.ts +27 -0
- package/dist/src/vite/publishedExports.js +298 -0
- package/dist/src/vite/realFolder.d.ts +6 -0
- package/dist/src/vite/realFolder.js +25 -0
- package/dist/src/vite/refsConfig.d.ts +39 -0
- package/dist/src/vite/refsConfig.js +54 -0
- package/dist/src/vite/reuseCheck.d.ts +45 -0
- package/dist/src/vite/reuseCheck.js +260 -0
- package/dist/src/vite/runningVersions.d.ts +33 -0
- package/dist/src/vite/runningVersions.js +25 -0
- package/dist/src/vite/scriptProblems.d.ts +60 -0
- package/dist/src/vite/scriptProblems.js +155 -0
- package/dist/src/vite/searchModule.js +3 -2
- package/dist/src/vite/searchRoute.js +4 -2
- package/dist/src/vite/shapeDocs.d.ts +36 -0
- package/dist/src/vite/shapeDocs.js +177 -0
- package/dist/src/vite/singleFileComponent.d.ts +17 -0
- package/dist/src/vite/singleFileComponent.js +83 -0
- package/dist/src/vite/sourceText.d.ts +34 -0
- package/dist/src/vite/sourceText.js +72 -0
- package/dist/src/vite/sourceTokens.d.ts +7 -0
- package/dist/src/vite/sourceTokens.js +7 -2
- package/dist/src/vite/stackLines.d.ts +49 -0
- package/dist/src/vite/stackLines.js +96 -0
- package/dist/src/vite/storyCode.d.ts +22 -7
- package/dist/src/vite/storyCode.js +263 -37
- package/dist/src/vite/storyCoverage.d.ts +48 -0
- package/dist/src/vite/storyCoverage.js +179 -0
- package/dist/src/vite/storyFilesModule.d.ts +48 -3
- package/dist/src/vite/storyFilesModule.js +105 -15
- package/dist/src/vite/storyPatterns.d.ts +31 -0
- package/dist/src/vite/storyPatterns.js +140 -5
- package/dist/src/vite/storyReach.d.ts +10 -2
- package/dist/src/vite/storyReach.js +15 -11
- package/dist/src/vite/storyTopLevel.d.ts +51 -0
- package/dist/src/vite/storyTopLevel.js +146 -0
- package/dist/src/vite/storylessRoutes.d.ts +4 -3
- package/dist/src/vite/storylessRoutes.js +210 -19
- package/dist/src/vite/switchValuesCheck.d.ts +19 -0
- package/dist/src/vite/switchValuesCheck.js +164 -0
- package/dist/src/vite/switchesDocument.d.ts +15 -0
- package/dist/src/vite/switchesDocument.js +47 -0
- package/dist/src/vite/tailwindConfigTokens.d.ts +41 -0
- package/dist/src/vite/tailwindConfigTokens.js +306 -0
- package/dist/src/vite/textImports.d.ts +15 -0
- package/dist/src/vite/textImports.js +58 -0
- package/dist/src/vite/textModules.d.ts +6 -5
- package/dist/src/vite/textModules.js +13 -8
- package/dist/src/vite/tokenAnswers.d.ts +6 -2
- package/dist/src/vite/tokenAnswers.js +11 -7
- package/dist/src/vite/typeParameters.d.ts +83 -0
- package/dist/src/vite/typeParameters.js +270 -0
- package/dist/src/vite/unionProps.d.ts +37 -0
- package/dist/src/vite/unionProps.js +121 -0
- package/dist/src/vite/unresolvedTokens.d.ts +20 -0
- package/dist/src/vite/unresolvedTokens.js +193 -0
- package/dist/src/vite/usageGraph.js +10 -52
- package/dist/src/vite/usageGuidance.d.ts +9 -2
- package/dist/src/vite/usageGuidance.js +36 -8
- package/dist/src/vite/usageImports.d.ts +35 -0
- package/dist/src/vite/usageImports.js +280 -0
- package/dist/src/vite/visibilityRoute.d.ts +16 -0
- package/dist/src/vite/visibilityRoute.js +320 -0
- package/dist/src/worstCase.d.ts +2 -0
- package/dist/src/worstCase.js +2 -0
- package/package.json +28 -8
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where an application draws a JSX component, read from its program with the TypeScript checker (no code runs): each
|
|
3
|
+
* element whose tag is the component, with the props it gives a literal value. `forgebook new` takes its values from
|
|
4
|
+
* them, so a first story shows the component as the application uses it rather than with a prop's name for its text.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* Shared by the frameworks whose components are functions of their props (React, Preact, Solid). The program is the
|
|
8
|
+
* component's configuration's, read whole. Story files, tests and declaration files are left out: they are not the
|
|
9
|
+
* application. A value is kept only when it is a literal (a string, a number, `true`, `false`, `null`, a list or an
|
|
10
|
+
* object of them); one that depends on the caller's state would not mean anything in a story. A child that is plain text
|
|
11
|
+
* is `children`.
|
|
12
|
+
*
|
|
13
|
+
* @module
|
|
14
|
+
*/
|
|
15
|
+
import ts from "typescript-6";
|
|
16
|
+
import { programFor } from "./docsProgram.js";
|
|
17
|
+
import { VITE_PATHS } from "./vitePaths.js";
|
|
18
|
+
/** A file that is not the application: a story, a test, a declaration. */
|
|
19
|
+
const NOT_APPLICATION = /\.(?:stories|story|test|spec)\.[cm]?[jt]sx?$|\.d\.[cm]?ts$|[\\/]node_modules[\\/]/;
|
|
20
|
+
/** How deep a list or an object is followed: past it, a value is not kept. */
|
|
21
|
+
const MAX_DEPTH = 4;
|
|
22
|
+
/**
|
|
23
|
+
* An expression as code a story can hold, when it is a literal: shared with the frameworks that read their templates'
|
|
24
|
+
* bindings as expressions (Vue's `:size="3"`).
|
|
25
|
+
*
|
|
26
|
+
* @param node - the expression.
|
|
27
|
+
* @param depth - how deep in a list or an object it is.
|
|
28
|
+
* @returns the code; none when it is not a literal.
|
|
29
|
+
*/
|
|
30
|
+
export const literalExpressionCode = (node, depth = 0) => {
|
|
31
|
+
if (depth > MAX_DEPTH)
|
|
32
|
+
return undefined;
|
|
33
|
+
if (ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isSatisfiesExpression(node))
|
|
34
|
+
return literalExpressionCode(node.expression, depth);
|
|
35
|
+
if (ts.isArrayLiteralExpression(node))
|
|
36
|
+
return listCode(node, depth);
|
|
37
|
+
if (ts.isObjectLiteralExpression(node))
|
|
38
|
+
return objectCode(node, depth);
|
|
39
|
+
return scalarCode(node);
|
|
40
|
+
};
|
|
41
|
+
/** A string, a number (a negative one too), `true`, `false` or `null` as code; none for anything else. */
|
|
42
|
+
const scalarCode = (node) => {
|
|
43
|
+
if (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node))
|
|
44
|
+
return JSON.stringify(node.text);
|
|
45
|
+
if (ts.isNumericLiteral(node))
|
|
46
|
+
return node.text;
|
|
47
|
+
const isNegative = ts.isPrefixUnaryExpression(node) &&
|
|
48
|
+
node.operator === ts.SyntaxKind.MinusToken &&
|
|
49
|
+
ts.isNumericLiteral(node.operand);
|
|
50
|
+
if (isNegative)
|
|
51
|
+
return `-${node.operand.text}`;
|
|
52
|
+
return KEYWORD_CODE.get(node.kind);
|
|
53
|
+
};
|
|
54
|
+
/** The keywords that are literals, as code. */
|
|
55
|
+
const KEYWORD_CODE = new Map([
|
|
56
|
+
[ts.SyntaxKind.TrueKeyword, "true"],
|
|
57
|
+
[ts.SyntaxKind.FalseKeyword, "false"],
|
|
58
|
+
[ts.SyntaxKind.NullKeyword, "null"]
|
|
59
|
+
]);
|
|
60
|
+
/** A list of literals as code. */
|
|
61
|
+
const listCode = (node, depth) => {
|
|
62
|
+
const items = node.elements.map((item) => ts.isSpreadElement(item) ? undefined : literalExpressionCode(item, depth + 1));
|
|
63
|
+
return items.some((item) => item === undefined) ? undefined : `[${items.join(", ")}]`;
|
|
64
|
+
};
|
|
65
|
+
/** A property's name as code: a name as it is, a string quoted; none for a computed one. */
|
|
66
|
+
const keyCode = (name) => {
|
|
67
|
+
if (ts.isIdentifier(name))
|
|
68
|
+
return name.text;
|
|
69
|
+
if (ts.isStringLiteral(name))
|
|
70
|
+
return JSON.stringify(name.text);
|
|
71
|
+
return undefined;
|
|
72
|
+
};
|
|
73
|
+
/** An object of literals as code. */
|
|
74
|
+
const objectCode = (node, depth) => {
|
|
75
|
+
const pairs = [];
|
|
76
|
+
for (const property of node.properties) {
|
|
77
|
+
if (!ts.isPropertyAssignment(property))
|
|
78
|
+
return undefined;
|
|
79
|
+
const key = keyCode(property.name);
|
|
80
|
+
const value = literalExpressionCode(property.initializer, depth + 1);
|
|
81
|
+
if (key === undefined || value === undefined)
|
|
82
|
+
return undefined;
|
|
83
|
+
pairs.push(`${key}: ${value}`);
|
|
84
|
+
}
|
|
85
|
+
return `{ ${pairs.join(", ")} }`;
|
|
86
|
+
};
|
|
87
|
+
/** The character references JSX text and attributes most often hold, as the characters they stand for. */
|
|
88
|
+
const ENTITIES = {
|
|
89
|
+
amp: "&",
|
|
90
|
+
lt: "<",
|
|
91
|
+
gt: ">",
|
|
92
|
+
quot: '"',
|
|
93
|
+
apos: "'",
|
|
94
|
+
nbsp: "\u00a0"
|
|
95
|
+
};
|
|
96
|
+
/** JSX text with its common character references read (`a & b` is `a & b`), as React reads them. */
|
|
97
|
+
const decoded = (text) => text.replace(/&(amp|lt|gt|quot|apos|nbsp);/g, (_, name) => ENTITIES[name] ?? "");
|
|
98
|
+
/** An attribute's value as code: a bare attribute is `true`, a string as written, an expression when a literal. */
|
|
99
|
+
const initializerCode = (initializer) => {
|
|
100
|
+
if (initializer === undefined)
|
|
101
|
+
return "true";
|
|
102
|
+
if (ts.isStringLiteral(initializer))
|
|
103
|
+
return JSON.stringify(decoded(initializer.text));
|
|
104
|
+
if (ts.isJsxExpression(initializer) && initializer.expression !== undefined)
|
|
105
|
+
return literalExpressionCode(initializer.expression);
|
|
106
|
+
return undefined;
|
|
107
|
+
};
|
|
108
|
+
/** The props an element gives a literal value, and its text child as `children`. */
|
|
109
|
+
const argsOf = (element) => {
|
|
110
|
+
const opening = ts.isJsxElement(element) ? element.openingElement : element;
|
|
111
|
+
const args = {};
|
|
112
|
+
for (const attribute of opening.attributes.properties) {
|
|
113
|
+
if (!ts.isJsxAttribute(attribute) || !ts.isIdentifier(attribute.name))
|
|
114
|
+
continue;
|
|
115
|
+
const name = attribute.name.text;
|
|
116
|
+
if (name === "key" || name === "ref")
|
|
117
|
+
continue;
|
|
118
|
+
const { initializer } = attribute;
|
|
119
|
+
const code = initializerCode(initializer);
|
|
120
|
+
if (code !== undefined)
|
|
121
|
+
args[name] = code;
|
|
122
|
+
}
|
|
123
|
+
const texts = ts.isJsxElement(element) ? element.children.filter(ts.isJsxText) : [];
|
|
124
|
+
if (ts.isJsxElement(element) && texts.length > 0 && texts.length === element.children.length) {
|
|
125
|
+
const text = texts
|
|
126
|
+
.map((child) => decoded(child.text))
|
|
127
|
+
.join("")
|
|
128
|
+
.replace(/\s+/g, " ")
|
|
129
|
+
.trim();
|
|
130
|
+
if (text !== "")
|
|
131
|
+
args["children"] = JSON.stringify(text);
|
|
132
|
+
}
|
|
133
|
+
return args;
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* The symbol a name stands for, through its imports and re-exports.
|
|
137
|
+
*
|
|
138
|
+
* @param symbol - the symbol at the name.
|
|
139
|
+
* @param checker - the checker.
|
|
140
|
+
*/
|
|
141
|
+
const declared = (symbol, checker) => symbol !== undefined && (symbol.flags & ts.SymbolFlags.Alias) !== 0
|
|
142
|
+
? checker.getAliasedSymbol(symbol)
|
|
143
|
+
: symbol;
|
|
144
|
+
/** The component's export, by its name or by its declaration's (`const TagImpl = …; export { TagImpl as Tag }`). */
|
|
145
|
+
const exportedSymbol = (source, name, checker) => {
|
|
146
|
+
const moduleSymbol = checker.getSymbolAtLocation(source);
|
|
147
|
+
const exports = moduleSymbol === undefined ? [] : checker.getExportsOfModule(moduleSymbol);
|
|
148
|
+
const exported = exports.find((each) => each.getName() === name) ??
|
|
149
|
+
exports.find((each) => declared(each, checker)?.getName() === name);
|
|
150
|
+
const target = declared(exported, checker);
|
|
151
|
+
return exported === undefined || target === undefined ? undefined : { exported, target };
|
|
152
|
+
};
|
|
153
|
+
/** The names a file that draws the component must hold: its export's, its declaration's, its file's. */
|
|
154
|
+
const searchedNames = (file, exported, target) => {
|
|
155
|
+
const stem = (VITE_PATHS.normalize(file).split("/").pop() ?? "").replace(/\.[^.]+$/, "");
|
|
156
|
+
return [exported.getName(), target.getName(), stem].filter((each) => each !== "default" && each !== "index");
|
|
157
|
+
};
|
|
158
|
+
/** The elements of a file whose tag is the component, with their literal props. */
|
|
159
|
+
const sitesIn = (file, target, checker) => {
|
|
160
|
+
const sites = [];
|
|
161
|
+
const visit = (node) => {
|
|
162
|
+
if (ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node)) {
|
|
163
|
+
const tag = ts.isJsxElement(node) ? node.openingElement.tagName : node.tagName;
|
|
164
|
+
if (declared(checker.getSymbolAtLocation(tag), checker) === target)
|
|
165
|
+
sites.push({ file: file.fileName, args: argsOf(node) });
|
|
166
|
+
}
|
|
167
|
+
ts.forEachChild(node, visit);
|
|
168
|
+
};
|
|
169
|
+
visit(file);
|
|
170
|
+
return sites;
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* Where the application draws a component a file exports.
|
|
174
|
+
*
|
|
175
|
+
* @param file - the component's file, absolute.
|
|
176
|
+
* @param name - the export's name (`default` for a default export).
|
|
177
|
+
* @returns the call sites; a message when the file or the export cannot be read.
|
|
178
|
+
*/
|
|
179
|
+
export const jsxCallSites = (file, name) => {
|
|
180
|
+
const program = programFor(file, { reach: "whole" });
|
|
181
|
+
if (typeof program === "string")
|
|
182
|
+
return program;
|
|
183
|
+
const { checker } = program;
|
|
184
|
+
const source = program.program.getSourceFile(file);
|
|
185
|
+
if (source === undefined)
|
|
186
|
+
return `${file} is not in its program`;
|
|
187
|
+
const found = exportedSymbol(source, name, checker);
|
|
188
|
+
if (found === undefined)
|
|
189
|
+
return `${file} exports no ${name}`;
|
|
190
|
+
// a file that names neither the component nor its file cannot draw it: the checker is not asked about its tags
|
|
191
|
+
const names = searchedNames(file, found.exported, found.target);
|
|
192
|
+
const component = VITE_PATHS.normalize(file);
|
|
193
|
+
return program.program
|
|
194
|
+
.getSourceFiles()
|
|
195
|
+
.filter((each) => !NOT_APPLICATION.test(each.fileName) &&
|
|
196
|
+
!program.program.isSourceFileFromExternalLibrary(each) &&
|
|
197
|
+
VITE_PATHS.normalize(each.fileName) !== component &&
|
|
198
|
+
(names.length === 0 || names.some((searched) => each.text.includes(searched))))
|
|
199
|
+
.flatMap((each) => sitesIn(each, found.target, checker));
|
|
200
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { type ResolvedConfig, type Rollup } from "vite";
|
|
2
|
+
import type { FrameworkAdapter } from "./adapter.ts";
|
|
3
|
+
import { type VitePaths } from "./vitePaths.ts";
|
|
4
|
+
/** A `.js` file compiled: its JavaScript and the source map back to its JSX. */
|
|
5
|
+
export type CompiledScript = {
|
|
6
|
+
/** The JavaScript. */
|
|
7
|
+
readonly code: string;
|
|
8
|
+
/** Its source map, back to the file's own text. */
|
|
9
|
+
readonly map: Rollup.SourceMapInput;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* The folder of the package a file belongs to: the nearest folder with a `package.json`; none outside any.
|
|
13
|
+
*
|
|
14
|
+
* @param file - the file, absolute in Vite's form.
|
|
15
|
+
*/
|
|
16
|
+
export type PackageOf = (file: string) => string | undefined;
|
|
17
|
+
/** Finds a file's package on disk, each folder looked at once. */
|
|
18
|
+
export declare const packageFinder: () => PackageOf;
|
|
19
|
+
/**
|
|
20
|
+
* The file of one of the catalogue's own `.js` files asked for as a module, from its id; none for any other id: an
|
|
21
|
+
* installed package's, another package's, one outside the catalogue's folder, a virtual module's, or one whose query
|
|
22
|
+
* asks for something else than the module (`?raw`).
|
|
23
|
+
*
|
|
24
|
+
* @param id - the module's id, with any query Vite gave it.
|
|
25
|
+
* @param root - the catalogue's folder, in Vite's form.
|
|
26
|
+
* @param packageOf - finds a file's package.
|
|
27
|
+
* @param paths - the path functions, the running system's by default.
|
|
28
|
+
*/
|
|
29
|
+
export declare const ownScriptOf: (id: string, root: string, packageOf: PackageOf, paths?: Pick<VitePaths, "normalize">) => string | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Whether a file's text may hold JSX: it has a closing tag.
|
|
32
|
+
*
|
|
33
|
+
* @param code - the text.
|
|
34
|
+
*/
|
|
35
|
+
export declare const mayHoldJsx: (code: string) => boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Compiles a `.js` file's JSX, with the code the project's `jsxInject` puts first (a classic runtime's `React` import),
|
|
38
|
+
* as Vite does for its `.jsx` files; leaves a file with no closing tag, and any file of a project that turns `oxc` off,
|
|
39
|
+
* to Vite.
|
|
40
|
+
*
|
|
41
|
+
* @param config - Vite's resolved configuration, for the project's JSX options.
|
|
42
|
+
* @param code - the file's text.
|
|
43
|
+
* @param file - the file, absolute.
|
|
44
|
+
* @returns the compiled module, or none when it is not compiled.
|
|
45
|
+
*/
|
|
46
|
+
export declare const jsxInScript: (config: ResolvedConfig, code: string, file: string) => Promise<CompiledScript | null>;
|
|
47
|
+
/** The plugin's hooks for JSX in the project's `.js` files. */
|
|
48
|
+
export type JsxInScripts = {
|
|
49
|
+
/** Keeps Vite's resolved configuration, for the project's JSX options and folder. */
|
|
50
|
+
readonly remember: (config: ResolvedConfig) => void;
|
|
51
|
+
/**
|
|
52
|
+
* Loads one of the catalogue's own `.js` files that holds JSX, compiled; none for any other module, and for all
|
|
53
|
+
* before `remember`, which Vite then loads itself.
|
|
54
|
+
*/
|
|
55
|
+
readonly load: (id: string) => Promise<CompiledScript | null>;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* The plugin's hooks for JSX in the project's `.js` files.
|
|
59
|
+
*
|
|
60
|
+
* @remarks
|
|
61
|
+
* The file is compiled as it is loaded, not in a `transform` hook, so the plugin's other transforms (a story file's
|
|
62
|
+
* hot code, `hotSnippets.ts`) read JavaScript and stay the plugin's one `transform`.
|
|
63
|
+
*
|
|
64
|
+
* @param frameworkOf - the catalogue's framework, whose adapter asks for it (`compilesJsxInScripts`); read on each module
|
|
65
|
+
* since the catalogue's configuration is read once Vite starts.
|
|
66
|
+
*/
|
|
67
|
+
export declare const jsxInScripts: (frameworkOf: () => Pick<FrameworkAdapter, "compilesJsxInScripts"> | undefined) => JsxInScripts;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSX in a project's `.js` files, compiled as Vite compiles it in `.jsx` ones, so a library that writes its components
|
|
3
|
+
* and stories in JavaScript with JSX (as Storybook's webpack builder lets it) draws with no configuration.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* Vite compiles JSX only in `.jsx` and `.tsx` files, and its `oxc` option takes one language for every file it
|
|
7
|
+
* includes, so a configuration cannot add `.js` without breaking TypeScript. Forgebook's plugin compiles such a file
|
|
8
|
+
* itself as it loads it, with the project's own JSX options (`oxc.jsx`: the runtime and the import
|
|
9
|
+
* source, `jsxInject`), before Vite's plugins read it. Only the catalogue's own files that hold a closing tag (`</`
|
|
10
|
+
* or `/>`) are compiled: every JSX element has one, and a plain `.js` file costs one search of its text. Its own: in
|
|
11
|
+
* its folder and in its package, so an installed package, or another package of a workspace (whose built files keep
|
|
12
|
+
* their own source maps), is never touched. A module asked for with a query that wants something else of the file
|
|
13
|
+
* (`?raw`, `?url`, `?worker`) is left to Vite. JSX is a superset of what a `.js` module may hold, so a file the search
|
|
14
|
+
* takes wrongly compiles to the same program. A
|
|
15
|
+
* project that turns `oxc` off compiles its scripts its own way, and none is compiled here; neither is any for a
|
|
16
|
+
* framework whose adapter does not ask for it (`compilesJsxInScripts`). Vite's dependency scan
|
|
17
|
+
* reads `.js` files as JSX too (`prebundled.ts`).
|
|
18
|
+
*
|
|
19
|
+
* @module
|
|
20
|
+
*/
|
|
21
|
+
import { existsSync } from "node:fs";
|
|
22
|
+
import { readFile } from "node:fs/promises";
|
|
23
|
+
import { transformWithOxc } from "vite";
|
|
24
|
+
import { VITE_PATHS } from "./vitePaths.js";
|
|
25
|
+
/** A script whose extension says nothing about JSX, as a browser loads it. */
|
|
26
|
+
const PLAIN_SCRIPT = /\.m?js$/;
|
|
27
|
+
/** A file of an installed package. */
|
|
28
|
+
const INSTALLED = /[\\/]node_modules[\\/]/;
|
|
29
|
+
/** What every JSX element holds: a closing tag, or the end of one that closes itself. */
|
|
30
|
+
const TAG_END = /<\/|\/>/;
|
|
31
|
+
/** The queries that still ask for the module itself: Vite's version stamp, its edit stamp, an import's mark. */
|
|
32
|
+
const MODULE_QUERIES = new Set(["v", "t", "import"]);
|
|
33
|
+
/** Finds a file's package on disk, each folder looked at once. */
|
|
34
|
+
export const packageFinder = () => {
|
|
35
|
+
const known = new Map();
|
|
36
|
+
const packageOf = (folder) => {
|
|
37
|
+
if (known.has(folder))
|
|
38
|
+
return known.get(folder);
|
|
39
|
+
const parent = VITE_PATHS.dirname(folder);
|
|
40
|
+
let found;
|
|
41
|
+
if (existsSync(`${folder}/package.json`))
|
|
42
|
+
found = folder;
|
|
43
|
+
// the system's root has no parent
|
|
44
|
+
else if (parent !== folder)
|
|
45
|
+
found = packageOf(parent);
|
|
46
|
+
known.set(folder, found);
|
|
47
|
+
return found;
|
|
48
|
+
};
|
|
49
|
+
return (file) => packageOf(VITE_PATHS.dirname(file));
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* The file of one of the catalogue's own `.js` files asked for as a module, from its id; none for any other id: an
|
|
53
|
+
* installed package's, another package's, one outside the catalogue's folder, a virtual module's, or one whose query
|
|
54
|
+
* asks for something else than the module (`?raw`).
|
|
55
|
+
*
|
|
56
|
+
* @param id - the module's id, with any query Vite gave it.
|
|
57
|
+
* @param root - the catalogue's folder, in Vite's form.
|
|
58
|
+
* @param packageOf - finds a file's package.
|
|
59
|
+
* @param paths - the path functions, the running system's by default.
|
|
60
|
+
*/
|
|
61
|
+
export const ownScriptOf = (id, root, packageOf, paths = VITE_PATHS) => {
|
|
62
|
+
if (id.startsWith("\0"))
|
|
63
|
+
return undefined;
|
|
64
|
+
const [path = id, query = ""] = id.split("?");
|
|
65
|
+
if ([...new URLSearchParams(query).keys()].some((key) => !MODULE_QUERIES.has(key)))
|
|
66
|
+
return undefined;
|
|
67
|
+
const file = paths.normalize(path);
|
|
68
|
+
if (!PLAIN_SCRIPT.test(file) || INSTALLED.test(file) || !file.startsWith(`${root}/`))
|
|
69
|
+
return undefined;
|
|
70
|
+
return packageOf(file) === packageOf(`${root}/package.json`) ? file : undefined;
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Whether a file's text may hold JSX: it has a closing tag.
|
|
74
|
+
*
|
|
75
|
+
* @param code - the text.
|
|
76
|
+
*/
|
|
77
|
+
export const mayHoldJsx = (code) => TAG_END.test(code);
|
|
78
|
+
/**
|
|
79
|
+
* The compiler's options for a `.js` file read as JSX: the project's own, without what only chooses Vite's files, and
|
|
80
|
+
* without React's Fast Refresh, which Vite's own plugin adds to the compiled module as it does to any `.js` file the
|
|
81
|
+
* project's refresh options include. Added here too, every component would be registered twice.
|
|
82
|
+
*
|
|
83
|
+
* @param oxc - the project's resolved `oxc` options.
|
|
84
|
+
*/
|
|
85
|
+
const jsxOptions = (oxc) => {
|
|
86
|
+
const { include, exclude, jsxInject, jsxRefreshInclude, jsxRefreshExclude, ...rest } = oxc;
|
|
87
|
+
const jsx = typeof rest.jsx === "object" ? { ...rest.jsx, refresh: false } : rest.jsx;
|
|
88
|
+
return { ...rest, ...(jsx === undefined ? {} : { jsx }), lang: "jsx", sourcemap: true };
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Compiles a `.js` file's JSX, with the code the project's `jsxInject` puts first (a classic runtime's `React` import),
|
|
92
|
+
* as Vite does for its `.jsx` files; leaves a file with no closing tag, and any file of a project that turns `oxc` off,
|
|
93
|
+
* to Vite.
|
|
94
|
+
*
|
|
95
|
+
* @param config - Vite's resolved configuration, for the project's JSX options.
|
|
96
|
+
* @param code - the file's text.
|
|
97
|
+
* @param file - the file, absolute.
|
|
98
|
+
* @returns the compiled module, or none when it is not compiled.
|
|
99
|
+
*/
|
|
100
|
+
export const jsxInScript = async (config, code, file) => {
|
|
101
|
+
if (config.oxc === false || !mayHoldJsx(code))
|
|
102
|
+
return null;
|
|
103
|
+
const result = await transformWithOxc(code, file, jsxOptions(config.oxc), undefined, config);
|
|
104
|
+
const inject = config.oxc.jsxInject;
|
|
105
|
+
// on the compiled code's first line, so the source map's lines stay where they were
|
|
106
|
+
return { code: inject === undefined ? result.code : `${inject};${result.code}`, map: result.map ?? null };
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* The plugin's hooks for JSX in the project's `.js` files.
|
|
110
|
+
*
|
|
111
|
+
* @remarks
|
|
112
|
+
* The file is compiled as it is loaded, not in a `transform` hook, so the plugin's other transforms (a story file's
|
|
113
|
+
* hot code, `hotSnippets.ts`) read JavaScript and stay the plugin's one `transform`.
|
|
114
|
+
*
|
|
115
|
+
* @param frameworkOf - the catalogue's framework, whose adapter asks for it (`compilesJsxInScripts`); read on each module
|
|
116
|
+
* since the catalogue's configuration is read once Vite starts.
|
|
117
|
+
*/
|
|
118
|
+
export const jsxInScripts = (frameworkOf) => {
|
|
119
|
+
let viteConfig;
|
|
120
|
+
const packageOf = packageFinder();
|
|
121
|
+
return {
|
|
122
|
+
remember: (config) => {
|
|
123
|
+
viteConfig = config;
|
|
124
|
+
},
|
|
125
|
+
load: async (id) => {
|
|
126
|
+
if (viteConfig === undefined || viteConfig.oxc === false)
|
|
127
|
+
return null;
|
|
128
|
+
if (frameworkOf()?.compilesJsxInScripts !== true)
|
|
129
|
+
return null;
|
|
130
|
+
const file = ownScriptOf(id, VITE_PATHS.normalize(viteConfig.root), packageOf);
|
|
131
|
+
if (file === undefined)
|
|
132
|
+
return null;
|
|
133
|
+
// a file that cannot be read is Vite's to report
|
|
134
|
+
const code = await readFile(file, "utf8").catch(() => undefined);
|
|
135
|
+
return code === undefined ? null : jsxInScript(viteConfig, code, file);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** A JSX element, as this walks it. */
|
|
2
|
+
export type Element = {
|
|
3
|
+
/** Its name. */
|
|
4
|
+
readonly name: string;
|
|
5
|
+
/** Its line. */
|
|
6
|
+
readonly line: number;
|
|
7
|
+
/** The elements directly inside it, through fragments. */
|
|
8
|
+
readonly children: readonly Element[];
|
|
9
|
+
/** Whether nothing of it shows, or what it is cannot be told: no system's component stands in for that. */
|
|
10
|
+
readonly isOutOfSight: boolean;
|
|
11
|
+
/** Whether it is one branch of a condition, so what stands in the other is no sibling of it. */
|
|
12
|
+
readonly isAlternative: boolean;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* The roots of a file: each outermost piece of markup, whose elements stand together with nothing known above them.
|
|
16
|
+
*
|
|
17
|
+
* @param node - the file's tree.
|
|
18
|
+
* @param starts - where its lines start.
|
|
19
|
+
*/
|
|
20
|
+
export declare const rootsOf: (node: unknown, starts: readonly number[]) => (readonly Element[])[];
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The JSX of a script as what stands where: which elements are directly inside which, and what is written in a place that
|
|
3
|
+
* says nothing of where it will be drawn (a prop, a value kept for later).
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { lineAt } from "./sourceText.js";
|
|
8
|
+
/** Elements that stand for what is inside them and say nothing of what a component stands in. */
|
|
9
|
+
const TRANSPARENT = /^(?:React\.)?(?:Fragment|Suspense|StrictMode|Profiler)$|(?:Provider|Consumer|Boundary)$/;
|
|
10
|
+
/** Whether a value is a node of the tree. */
|
|
11
|
+
const isNode = (value) => typeof value === "object" && value !== null && "type" in value && typeof value.type === "string";
|
|
12
|
+
/** A JSX name as text. */
|
|
13
|
+
const nameOf = (node) => {
|
|
14
|
+
if (!isNode(node))
|
|
15
|
+
return undefined;
|
|
16
|
+
if (node.type === "JSXIdentifier" && typeof node["name"] === "string")
|
|
17
|
+
return node["name"];
|
|
18
|
+
if (node.type !== "JSXMemberExpression")
|
|
19
|
+
return undefined;
|
|
20
|
+
const [object, property] = [nameOf(node["object"]), nameOf(node["property"])];
|
|
21
|
+
return object === undefined || property === undefined ? undefined : `${object}.${property}`;
|
|
22
|
+
};
|
|
23
|
+
/** A plain attribute's text; none when it is absent, empty when written by code. */
|
|
24
|
+
const attributeText = (attributes, name) => {
|
|
25
|
+
for (const each of attributes) {
|
|
26
|
+
if (!isNode(each) || !isNode(each["name"]) || each["name"]["name"] !== name)
|
|
27
|
+
continue;
|
|
28
|
+
const value = each["value"];
|
|
29
|
+
return isNode(value) && typeof value["value"] === "string" ? value["value"] : "";
|
|
30
|
+
}
|
|
31
|
+
return undefined;
|
|
32
|
+
};
|
|
33
|
+
/** Whether an element's attributes say nothing of it shows, or hand what it is to code (`{...getInputProps()}`). */
|
|
34
|
+
const isOutOfSight = (attributes) => {
|
|
35
|
+
const list = Array.isArray(attributes) ? attributes : [];
|
|
36
|
+
if (list.some((each) => isNode(each) && each.type === "JSXSpreadAttribute"))
|
|
37
|
+
return true;
|
|
38
|
+
const type = attributeText(list, "type");
|
|
39
|
+
if (type === "hidden" || type === "file" || attributeText(list, "hidden") !== undefined)
|
|
40
|
+
return true;
|
|
41
|
+
return /(?:^|\s)(?:sr-only|hidden)(?:\s|$)/.test(attributeText(list, "className") ?? "");
|
|
42
|
+
};
|
|
43
|
+
/** Two readings or more as one. */
|
|
44
|
+
const joined = (readings) => ({
|
|
45
|
+
direct: readings.flatMap((each) => each.direct),
|
|
46
|
+
detached: readings.flatMap((each) => each.detached)
|
|
47
|
+
});
|
|
48
|
+
/** Every outermost element under a node, standing nowhere known. */
|
|
49
|
+
const anyElements = (node, starts) => {
|
|
50
|
+
if (Array.isArray(node))
|
|
51
|
+
return node.flatMap((each) => anyElements(each, starts));
|
|
52
|
+
if (typeof node !== "object" || node === null)
|
|
53
|
+
return [];
|
|
54
|
+
if (isNode(node) && (node.type === "JSXElement" || node.type === "JSXFragment")) {
|
|
55
|
+
const { direct, detached } = readValue(node, starts);
|
|
56
|
+
return [...direct, ...detached];
|
|
57
|
+
}
|
|
58
|
+
return Object.values(node).flatMap((value) => typeof value === "object" ? anyElements(value, starts) : []);
|
|
59
|
+
};
|
|
60
|
+
/** What stands under a part of the tree. */
|
|
61
|
+
const childrenOfNode = (node) => {
|
|
62
|
+
if (Array.isArray(node))
|
|
63
|
+
return node;
|
|
64
|
+
return typeof node === "object" && node !== null
|
|
65
|
+
? Object.values(node).filter((value) => typeof value === "object")
|
|
66
|
+
: [];
|
|
67
|
+
};
|
|
68
|
+
/** What a function gives back, as elements: its expression, or its own returns. */
|
|
69
|
+
const readReturns = (body, starts) => {
|
|
70
|
+
if (!isNode(body) || body.type !== "BlockStatement")
|
|
71
|
+
return readValue(body, starts);
|
|
72
|
+
const returned = [];
|
|
73
|
+
const others = [];
|
|
74
|
+
const visit = (node) => {
|
|
75
|
+
if (isNode(node) && node.type === "ReturnStatement")
|
|
76
|
+
returned.push(node["argument"]);
|
|
77
|
+
else if (isNode(node) && (node.type === "JSXElement" || node.type === "JSXFragment"))
|
|
78
|
+
others.push(node);
|
|
79
|
+
else
|
|
80
|
+
childrenOfNode(node).forEach(visit);
|
|
81
|
+
};
|
|
82
|
+
visit(body["body"]);
|
|
83
|
+
const given = joined(returned.map((each) => readValue(each, starts)));
|
|
84
|
+
return { direct: given.direct, detached: [...given.detached, ...anyElements(others, starts)] };
|
|
85
|
+
};
|
|
86
|
+
/** A call's elements: `items.map((item) => <Option />)` stands where it is written; another's argument may go anywhere. */
|
|
87
|
+
const readCall = (node, starts) => {
|
|
88
|
+
const callee = node["callee"];
|
|
89
|
+
const method = isNode(callee) && isNode(callee["property"]) ? callee["property"]["name"] : undefined;
|
|
90
|
+
const parts = Array.isArray(node["arguments"]) ? node["arguments"] : [];
|
|
91
|
+
return method === "map" || method === "flatMap"
|
|
92
|
+
? readValue(parts, starts)
|
|
93
|
+
: { direct: [], detached: anyElements(parts, starts) };
|
|
94
|
+
};
|
|
95
|
+
/** An element and what it holds. What its props hold (`icon={<X />}`, `render={() => …}`) may be drawn anywhere. */
|
|
96
|
+
const readElement = (node, starts) => {
|
|
97
|
+
const opening = node["openingElement"];
|
|
98
|
+
const name = isNode(opening) ? nameOf(opening["name"]) : undefined;
|
|
99
|
+
const inner = readValue(node["children"], starts);
|
|
100
|
+
const held = isNode(opening) ? anyElements(opening["attributes"], starts) : [];
|
|
101
|
+
if (name === undefined || !isNode(opening) || TRANSPARENT.test(name)) {
|
|
102
|
+
return { direct: inner.direct, detached: [...inner.detached, ...held] };
|
|
103
|
+
}
|
|
104
|
+
const element = {
|
|
105
|
+
name,
|
|
106
|
+
line: lineAt(starts, Number(opening["start"])),
|
|
107
|
+
children: inner.direct,
|
|
108
|
+
isOutOfSight: isOutOfSight(opening["attributes"]),
|
|
109
|
+
isAlternative: false
|
|
110
|
+
};
|
|
111
|
+
return { direct: [element], detached: [...inner.detached, ...held] };
|
|
112
|
+
};
|
|
113
|
+
/** The elements an expression comes to, through what JSX writes around them. */
|
|
114
|
+
const readValue = (node, starts) => {
|
|
115
|
+
if (Array.isArray(node))
|
|
116
|
+
return joined(node.map((each) => readValue(each, starts)));
|
|
117
|
+
if (!isNode(node))
|
|
118
|
+
return { direct: [], detached: [] };
|
|
119
|
+
switch (node.type) {
|
|
120
|
+
case "JSXElement":
|
|
121
|
+
return readElement(node, starts);
|
|
122
|
+
case "JSXFragment":
|
|
123
|
+
return readValue(node["children"], starts);
|
|
124
|
+
case "JSXExpressionContainer":
|
|
125
|
+
case "ParenthesizedExpression":
|
|
126
|
+
case "TSAsExpression":
|
|
127
|
+
case "TSNonNullExpression":
|
|
128
|
+
return readValue(node["expression"], starts);
|
|
129
|
+
case "ConditionalExpression": {
|
|
130
|
+
const branches = joined([readValue(node["consequent"], starts), readValue(node["alternate"], starts)]);
|
|
131
|
+
return {
|
|
132
|
+
direct: branches.direct.map((each) => ({ ...each, isAlternative: true })),
|
|
133
|
+
detached: branches.detached
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
case "LogicalExpression":
|
|
137
|
+
return readValue(node["right"], starts);
|
|
138
|
+
case "ArrowFunctionExpression":
|
|
139
|
+
case "FunctionExpression":
|
|
140
|
+
return readReturns(node["body"], starts);
|
|
141
|
+
case "CallExpression":
|
|
142
|
+
return readCall(node, starts);
|
|
143
|
+
default:
|
|
144
|
+
return { direct: [], detached: anyElements(node, starts) };
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* The roots of a file: each outermost piece of markup, whose elements stand together with nothing known above them.
|
|
149
|
+
*
|
|
150
|
+
* @param node - the file's tree.
|
|
151
|
+
* @param starts - where its lines start.
|
|
152
|
+
*/
|
|
153
|
+
export const rootsOf = (node, starts) => {
|
|
154
|
+
if (Array.isArray(node))
|
|
155
|
+
return node.flatMap((each) => rootsOf(each, starts));
|
|
156
|
+
if (typeof node !== "object" || node === null)
|
|
157
|
+
return [];
|
|
158
|
+
if (isNode(node) && (node.type === "JSXElement" || node.type === "JSXFragment")) {
|
|
159
|
+
const { direct, detached } = readValue(node, starts);
|
|
160
|
+
return [direct, ...detached.map((each) => [each])];
|
|
161
|
+
}
|
|
162
|
+
return Object.values(node).flatMap((value) => (typeof value === "object" ? rootsOf(value, starts) : []));
|
|
163
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where an offset of a parser's error falls in a file, as an editor counts, for the messages that name a place.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Where an offset falls in a text, as an editor counts: both from 1.
|
|
8
|
+
*
|
|
9
|
+
* @param text - the text.
|
|
10
|
+
* @param offset - the offset, in UTF-16 code units, as the parser gives it.
|
|
11
|
+
* @returns `line:column`.
|
|
12
|
+
*/
|
|
13
|
+
export declare const lineAndColumn: (text: string, offset: number) => string;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where an offset of a parser's error falls in a file, as an editor counts, for the messages that name a place.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/** What ends a line, for an editor as for JavaScript. */
|
|
7
|
+
const LINE_END = /\r\n|[\n\r\u2028\u2029]/g;
|
|
8
|
+
/**
|
|
9
|
+
* Where an offset falls in a text, as an editor counts: both from 1.
|
|
10
|
+
*
|
|
11
|
+
* @param text - the text.
|
|
12
|
+
* @param offset - the offset, in UTF-16 code units, as the parser gives it.
|
|
13
|
+
* @returns `line:column`.
|
|
14
|
+
*/
|
|
15
|
+
export const lineAndColumn = (text, offset) => {
|
|
16
|
+
const lines = text.slice(0, offset).split(LINE_END);
|
|
17
|
+
return `${lines.length}:${(lines.at(-1)?.length ?? 0) + 1}`;
|
|
18
|
+
};
|