forgebook 0.3.3 → 0.4.1
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 +994 -72
- 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 +182 -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 +62 -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 +95 -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 +204 -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 +323 -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 +29 -5
- package/dist/src/addressArgs.js +58 -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 +148 -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 +69 -185
- 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 +83 -0
- package/dist/src/componentDocs.js +20 -3
- package/dist/src/controlCode.d.ts +27 -0
- package/dist/src/controlCode.js +41 -0
- 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/controlValues.d.ts +39 -0
- package/dist/src/frame/controlValues.js +143 -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 +10 -1
- package/dist/src/frame/mountFrame.js +160 -55
- package/dist/src/frame/panelControls.d.ts +67 -0
- package/dist/src/frame/panelControls.js +110 -0
- 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/AuthoredHome.js +3 -1
- package/dist/src/shell/CodeTab.d.ts +12 -6
- package/dist/src/shell/CodeTab.js +47 -3
- 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 +6 -6
- package/dist/src/shell/ComponentPage.js +8 -2
- package/dist/src/shell/CustomControl.d.ts +34 -0
- package/dist/src/shell/CustomControl.js +125 -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 +30 -12
- 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 +18 -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/PageWidth.d.ts +29 -0
- package/dist/src/shell/PageWidth.js +18 -0
- 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/PropFields.d.ts +3 -1
- package/dist/src/shell/PropFields.js +9 -6
- package/dist/src/shell/PropRows.d.ts +22 -11
- package/dist/src/shell/PropRows.js +62 -24
- package/dist/src/shell/PropsTab.d.ts +12 -5
- package/dist/src/shell/PropsTab.js +9 -22
- 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 +141 -23
- 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 +29 -49
- 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/StoryPicker.d.ts +4 -2
- package/dist/src/shell/StoryPicker.js +3 -3
- package/dist/src/shell/Switch.d.ts +29 -0
- package/dist/src/shell/Switch.js +11 -0
- 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.js +7 -2
- 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 +62 -0
- package/dist/src/shell/customControls.js +81 -0
- package/dist/src/shell/docPage.css +22 -22
- package/dist/src/shell/dockTabs.d.ts +19 -3
- package/dist/src/shell/dockTabs.js +29 -20
- package/dist/src/shell/embed.css +7 -7
- package/dist/src/shell/frameOrder.d.ts +35 -0
- package/dist/src/shell/frameOrder.js +45 -0
- 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 +30 -0
- package/dist/src/shell/laterStrings.js +43 -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 +376 -169
- 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 +9 -0
- package/dist/src/shell/useAddressArgs.js +56 -11
- 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/useFrameQueue.d.ts +8 -3
- package/dist/src/shell/useFrameQueue.js +42 -12
- 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/useScrollSettled.d.ts +18 -0
- package/dist/src/shell/useScrollSettled.js +56 -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 +148 -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 +99 -3
- package/dist/src/storyCheck.js +39 -1
- package/dist/src/storyCodeText.d.ts +52 -0
- package/dist/src/storyCodeText.js +30 -0
- package/dist/src/storyControls.d.ts +103 -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 +354 -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 +135 -66
- package/dist/src/vite/agentStatuses.d.ts +42 -0
- package/dist/src/vite/agentStatuses.js +67 -0
- package/dist/src/vite/agentStoryCode.d.ts +51 -0
- package/dist/src/vite/agentStoryCode.js +44 -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/argControlsConfig.d.ts +30 -0
- package/dist/src/vite/argControlsConfig.js +176 -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 +21 -4
- 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 +67 -1
- package/dist/src/vite/configFile.d.ts +15 -2
- package/dist/src/vite/configFile.js +109 -40
- package/dist/src/vite/configKeys.d.ts +15 -0
- package/dist/src/vite/configKeys.js +172 -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 +55 -73
- 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 +119 -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 +187 -60
- 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/typedControls.d.ts +31 -0
- package/dist/src/vite/typedControls.js +66 -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,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How the catalogue's searches read a word nothing holds as typed: as the nearest word of the catalogue's names, a
|
|
3
|
+
* letter or two away.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* `forgebook find`, `forgebook search`, the dev server's API and MCP read typos alike from here. The shell's search
|
|
7
|
+
* reads words as typed: what reading typos costs is more than its first search's budget leaves. Pure.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import { type SearchAnswer, type Searchable, type SearchLimits } from "./search.ts";
|
|
12
|
+
import { type SearchPlace } from "./searchMatch.ts";
|
|
13
|
+
/** A word of a query read as another, because nothing holds it as typed and the other is a letter or two away. */
|
|
14
|
+
export type SearchCorrection = {
|
|
15
|
+
/** The word as typed, lower case and without accents. */
|
|
16
|
+
readonly typed: string;
|
|
17
|
+
/** The word of the catalogue it was read as. */
|
|
18
|
+
readonly read: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* How many letters a typed word may be away from the word meant: none under four letters, one up to seven, two from
|
|
22
|
+
* eight.
|
|
23
|
+
*
|
|
24
|
+
* @param word - a word, as `wordsOf` gives it.
|
|
25
|
+
*/
|
|
26
|
+
export declare const typosAllowed: (word: string) => number;
|
|
27
|
+
/**
|
|
28
|
+
* How many letters two words are apart, a letter added, removed, changed, or two side by side swapped counting one
|
|
29
|
+
* each (the restricted Damerau-Levenshtein distance); none past a limit.
|
|
30
|
+
*
|
|
31
|
+
* @remarks
|
|
32
|
+
* Stops at the first row past the limit, so a word far from the one asked costs a few steps, not its whole table.
|
|
33
|
+
*
|
|
34
|
+
* @param first - a word.
|
|
35
|
+
* @param second - another.
|
|
36
|
+
* @param limit - the most that counts.
|
|
37
|
+
* @returns the distance, or `undefined` past the limit.
|
|
38
|
+
*/
|
|
39
|
+
export declare const distanceWithin: (first: string, second: string, limit: number) => number | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* The words of a query that nothing holds, each read as the nearest word of the catalogue's names, when one is near
|
|
42
|
+
* enough (`typosAllowed`).
|
|
43
|
+
*
|
|
44
|
+
* @remarks
|
|
45
|
+
* Only a word that matches nothing anywhere is read as another, so a typo never changes what a word found already
|
|
46
|
+
* finds, and every result of an exact query stays. The nearest wins; between words as near, the one the catalogue
|
|
47
|
+
* uses most, then the first in alphabetical order, so the same query reads the same way twice. The synonyms' words
|
|
48
|
+
* count as the catalogue's where it holds a word of their group: `dialgo` reads `dialog`, which then finds a `Modal`.
|
|
49
|
+
*
|
|
50
|
+
* @param missing - the query's words that nothing holds.
|
|
51
|
+
* @param everything - the words of each thing that can be found, by where they are.
|
|
52
|
+
*/
|
|
53
|
+
export declare const correctionsOf: (missing: readonly string[], everything: readonly Partial<Record<SearchPlace, readonly string[]>>[]) => readonly SearchCorrection[];
|
|
54
|
+
/**
|
|
55
|
+
* A query's words with its corrections applied, each word once.
|
|
56
|
+
*
|
|
57
|
+
* @param words - the query's words.
|
|
58
|
+
* @param corrections - what some of them are read as (`correctionsOf`).
|
|
59
|
+
*/
|
|
60
|
+
export declare const correctedWords: (words: readonly string[], corrections: readonly SearchCorrection[]) => string[];
|
|
61
|
+
/** A query's words as a search reads them. */
|
|
62
|
+
export type CorrectedQuery = {
|
|
63
|
+
/** The words nothing held as typed, and what each was read as; empty when the query is read as typed. */
|
|
64
|
+
readonly corrections: readonly SearchCorrection[];
|
|
65
|
+
/** The query's words, the corrections applied, each word once. */
|
|
66
|
+
readonly words: readonly string[];
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* A query's words with those nothing holds read as near names (`correctionsOf`).
|
|
70
|
+
*
|
|
71
|
+
* @param words - the query's words.
|
|
72
|
+
* @param held - those something holds as typed.
|
|
73
|
+
* @param everything - the words of each thing that can be found, by where they are.
|
|
74
|
+
*/
|
|
75
|
+
export declare const correctedQuery: (words: readonly string[], held: ReadonlySet<string>, everything: readonly Partial<Record<SearchPlace, readonly string[]>>[]) => CorrectedQuery;
|
|
76
|
+
/** What a query finds, with the words read as others. */
|
|
77
|
+
export type CorrectedAnswer = SearchAnswer & {
|
|
78
|
+
/** The words nothing held as typed, and what each was read as; empty when the query was read as typed. */
|
|
79
|
+
readonly corrections: readonly SearchCorrection[];
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* What a query finds (`searchCatalogue`), a word nothing holds as typed read as the nearest name (`correctedQuery`).
|
|
83
|
+
*
|
|
84
|
+
* @param all - everything that can be found (`searchables`).
|
|
85
|
+
* @param query - what was typed.
|
|
86
|
+
* @param limits - how much of the answer to give.
|
|
87
|
+
*/
|
|
88
|
+
export declare const correctedSearch: (all: readonly Searchable[], query: string, limits: SearchLimits) => CorrectedAnswer;
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How the catalogue's searches read a word nothing holds as typed: as the nearest word of the catalogue's names, a
|
|
3
|
+
* letter or two away.
|
|
4
|
+
*
|
|
5
|
+
* @remarks
|
|
6
|
+
* `forgebook find`, `forgebook search`, the dev server's API and MCP read typos alike from here. The shell's search
|
|
7
|
+
* reads words as typed: what reading typos costs is more than its first search's budget leaves. Pure.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import { answerOf, queryOf, scoredAll } from "./search.js";
|
|
12
|
+
import { SYNONYMS } from "./searchMatch.js";
|
|
13
|
+
/** The places whose words a typo is read against: names, not prose, where a near word is seldom the one meant. */
|
|
14
|
+
const CORRECTION_PLACES = ["name", "keyword", "prop", "heading", "title", "story"];
|
|
15
|
+
/** The shortest word read as another: in a shorter one, a letter changed makes most often a different word. */
|
|
16
|
+
const MIN_CORRECTED = 4;
|
|
17
|
+
/** From this length a word may be two letters away from the one meant. */
|
|
18
|
+
const TWO_TYPOS_FROM = 8;
|
|
19
|
+
/**
|
|
20
|
+
* How many letters a typed word may be away from the word meant: none under four letters, one up to seven, two from
|
|
21
|
+
* eight.
|
|
22
|
+
*
|
|
23
|
+
* @param word - a word, as `wordsOf` gives it.
|
|
24
|
+
*/
|
|
25
|
+
export const typosAllowed = (word) => {
|
|
26
|
+
if (word.length < MIN_CORRECTED)
|
|
27
|
+
return 0;
|
|
28
|
+
return word.length < TWO_TYPOS_FROM ? 1 : 2;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* How many letters two words are apart, a letter added, removed, changed, or two side by side swapped counting one
|
|
32
|
+
* each (the restricted Damerau-Levenshtein distance); none past a limit.
|
|
33
|
+
*
|
|
34
|
+
* @remarks
|
|
35
|
+
* Stops at the first row past the limit, so a word far from the one asked costs a few steps, not its whole table.
|
|
36
|
+
*
|
|
37
|
+
* @param first - a word.
|
|
38
|
+
* @param second - another.
|
|
39
|
+
* @param limit - the most that counts.
|
|
40
|
+
* @returns the distance, or `undefined` past the limit.
|
|
41
|
+
*/
|
|
42
|
+
export const distanceWithin = (first, second, limit) => {
|
|
43
|
+
if (Math.abs(first.length - second.length) > limit)
|
|
44
|
+
return undefined;
|
|
45
|
+
let before = [];
|
|
46
|
+
let previous = Array.from({ length: second.length + 1 }, (_, index) => index);
|
|
47
|
+
for (let row = 1; row <= first.length; row += 1) {
|
|
48
|
+
const current = distanceRow(first, second, row, { previous, before });
|
|
49
|
+
if (Math.min(...current) > limit)
|
|
50
|
+
return undefined;
|
|
51
|
+
before = previous;
|
|
52
|
+
previous = current;
|
|
53
|
+
}
|
|
54
|
+
const distance = previous[second.length] ?? 0;
|
|
55
|
+
return distance <= limit ? distance : undefined;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* One row of the distance's table: how far the first `row` letters of a word are from each start of another.
|
|
59
|
+
*
|
|
60
|
+
* @param first - the word the rows follow.
|
|
61
|
+
* @param second - the word the columns follow.
|
|
62
|
+
* @param row - how many letters of the first word.
|
|
63
|
+
* @param rows - the row before and the one before it, for a swap.
|
|
64
|
+
*/
|
|
65
|
+
const distanceRow = (first, second, row, rows) => {
|
|
66
|
+
const { previous, before } = rows;
|
|
67
|
+
const current = [row];
|
|
68
|
+
for (let column = 1; column <= second.length; column += 1) {
|
|
69
|
+
const cost = first[row - 1] === second[column - 1] ? 0 : 1;
|
|
70
|
+
const steps = [
|
|
71
|
+
(previous[column] ?? 0) + 1,
|
|
72
|
+
(current[column - 1] ?? 0) + 1,
|
|
73
|
+
(previous[column - 1] ?? 0) + cost
|
|
74
|
+
];
|
|
75
|
+
const isSwap = row > 1 && column > 1 && first[row - 1] === second[column - 2] && first[row - 2] === second[column - 1];
|
|
76
|
+
if (isSwap)
|
|
77
|
+
steps.push((before[column - 2] ?? 0) + 1);
|
|
78
|
+
current.push(Math.min(...steps));
|
|
79
|
+
}
|
|
80
|
+
return current;
|
|
81
|
+
};
|
|
82
|
+
/**
|
|
83
|
+
* The words a typo can be read as, each with how often the catalogue's names use it.
|
|
84
|
+
*
|
|
85
|
+
* @param everything - the words of each thing that can be found, by where they are.
|
|
86
|
+
*/
|
|
87
|
+
const candidateWords = (everything) => {
|
|
88
|
+
const counts = new Map();
|
|
89
|
+
for (const parts of everything) {
|
|
90
|
+
for (const word of CORRECTION_PLACES.flatMap((place) => parts[place] ?? [])) {
|
|
91
|
+
counts.set(word, (counts.get(word) ?? 0) + 1);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// a synonym is a candidate only when the catalogue holds a word of its group: read otherwise, it would find nothing
|
|
95
|
+
for (const group of SYNONYMS.filter((each) => each.some((word) => counts.has(word)))) {
|
|
96
|
+
for (const word of group)
|
|
97
|
+
if (!counts.has(word))
|
|
98
|
+
counts.set(word, 0);
|
|
99
|
+
}
|
|
100
|
+
return counts;
|
|
101
|
+
};
|
|
102
|
+
/** Whether a candidate is a better reading than the best so far: nearer, then used more, then first in order. */
|
|
103
|
+
const isBetter = (candidate, best) => best === undefined ||
|
|
104
|
+
candidate.distance < best.distance ||
|
|
105
|
+
(candidate.distance === best.distance &&
|
|
106
|
+
(candidate.count > best.count || (candidate.count === best.count && candidate.word < best.word)));
|
|
107
|
+
/** The candidate a typed word is read as; none when none is near enough. */
|
|
108
|
+
const nearestWord = (typed, counts) => {
|
|
109
|
+
let best;
|
|
110
|
+
for (const [word, count] of counts) {
|
|
111
|
+
const distance = distanceWithin(typed, word, typosAllowed(typed));
|
|
112
|
+
if (distance === undefined || distance === 0)
|
|
113
|
+
continue;
|
|
114
|
+
const candidate = { word, distance, count };
|
|
115
|
+
if (isBetter(candidate, best))
|
|
116
|
+
best = candidate;
|
|
117
|
+
}
|
|
118
|
+
return best?.word;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* The words of a query that nothing holds, each read as the nearest word of the catalogue's names, when one is near
|
|
122
|
+
* enough (`typosAllowed`).
|
|
123
|
+
*
|
|
124
|
+
* @remarks
|
|
125
|
+
* Only a word that matches nothing anywhere is read as another, so a typo never changes what a word found already
|
|
126
|
+
* finds, and every result of an exact query stays. The nearest wins; between words as near, the one the catalogue
|
|
127
|
+
* uses most, then the first in alphabetical order, so the same query reads the same way twice. The synonyms' words
|
|
128
|
+
* count as the catalogue's where it holds a word of their group: `dialgo` reads `dialog`, which then finds a `Modal`.
|
|
129
|
+
*
|
|
130
|
+
* @param missing - the query's words that nothing holds.
|
|
131
|
+
* @param everything - the words of each thing that can be found, by where they are.
|
|
132
|
+
*/
|
|
133
|
+
export const correctionsOf = (missing, everything) => {
|
|
134
|
+
const asked = missing.filter((word) => typosAllowed(word) > 0);
|
|
135
|
+
if (asked.length === 0)
|
|
136
|
+
return [];
|
|
137
|
+
const counts = candidateWords(everything);
|
|
138
|
+
return asked.flatMap((typed) => {
|
|
139
|
+
const read = nearestWord(typed, counts);
|
|
140
|
+
return read === undefined ? [] : [{ typed, read }];
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* A query's words with its corrections applied, each word once.
|
|
145
|
+
*
|
|
146
|
+
* @param words - the query's words.
|
|
147
|
+
* @param corrections - what some of them are read as (`correctionsOf`).
|
|
148
|
+
*/
|
|
149
|
+
export const correctedWords = (words, corrections) => [
|
|
150
|
+
...new Set(words.map((word) => corrections.find((each) => each.typed === word)?.read ?? word))
|
|
151
|
+
];
|
|
152
|
+
/**
|
|
153
|
+
* A query's words with those nothing holds read as near names (`correctionsOf`).
|
|
154
|
+
*
|
|
155
|
+
* @param words - the query's words.
|
|
156
|
+
* @param held - those something holds as typed.
|
|
157
|
+
* @param everything - the words of each thing that can be found, by where they are.
|
|
158
|
+
*/
|
|
159
|
+
export const correctedQuery = (words, held, everything) => {
|
|
160
|
+
const corrections = correctionsOf(words.filter((word) => !held.has(word)), everything);
|
|
161
|
+
return { corrections, words: correctedWords(words, corrections) };
|
|
162
|
+
};
|
|
163
|
+
/**
|
|
164
|
+
* What a query finds (`searchCatalogue`), a word nothing holds as typed read as the nearest name (`correctedQuery`).
|
|
165
|
+
*
|
|
166
|
+
* @param all - everything that can be found (`searchables`).
|
|
167
|
+
* @param query - what was typed.
|
|
168
|
+
* @param limits - how much of the answer to give.
|
|
169
|
+
*/
|
|
170
|
+
export const correctedSearch = (all, query, limits) => {
|
|
171
|
+
const typed = queryOf(query);
|
|
172
|
+
const strict = scoredAll(all, typed);
|
|
173
|
+
const { corrections, words } = correctedQuery(typed.words, new Set(strict.flatMap((each) => each.matched)), all.map((each) => each.parts));
|
|
174
|
+
if (corrections.length === 0)
|
|
175
|
+
return { ...answerOf(strict, typed, limits), corrections };
|
|
176
|
+
const read = { ...typed, words };
|
|
177
|
+
return { ...answerOf(scoredAll(all, read), read, limits), corrections };
|
|
178
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What reads a value against its shape (`valueShape.ts`): whether it fits, what the panel starts from, what a story's own
|
|
3
|
+
* arg looks like, and the worst case of each kind. Loaded with the first prop that has a shape, so a catalogue of plain
|
|
4
|
+
* props never pays for it; the commands import it directly.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* A link's author chooses the values, and a component may spread an object onto an element. What a type declares is
|
|
8
|
+
* checked by name; what no type describes (`json`, `record`) is checked for what an element would run: an attribute that
|
|
9
|
+
* runs a script or writes markup, Vue's marks for a property or a modifier (`.innerHTML`, `^onclick`), an address that
|
|
10
|
+
* runs when opened, and a named value, which only a type offers. Pure.
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
import { type ArgValue } from "./messages.ts";
|
|
15
|
+
import { type NamedValues } from "./namedValues.ts";
|
|
16
|
+
import type { ValueShape } from "./valueShape.ts";
|
|
17
|
+
/**
|
|
18
|
+
* The names a free-form part of a value may not hold (`json`, `record`): an attribute that runs a script or writes
|
|
19
|
+
* markup when a component spreads the object onto an element. A link's author chooses these names, and no type says
|
|
20
|
+
* which are meant; an `on` word that is no event stays allowed.
|
|
21
|
+
*
|
|
22
|
+
* @param name - the name.
|
|
23
|
+
*/
|
|
24
|
+
export declare const isUnsafeFreeName: (name: string) => boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Whether a free-form value holds anything it may not hold, at any depth.
|
|
27
|
+
*
|
|
28
|
+
* @param value - the value.
|
|
29
|
+
* @param allowsNamed - whether a named value may be in it: a schema's author has said what it takes, and the name is looked
|
|
30
|
+
* up among the source's own values; `false` by default, where nothing has said.
|
|
31
|
+
*/
|
|
32
|
+
export declare const holdsUnsafePart: (value: ArgValue, allowsNamed?: boolean) => boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Whether a value fits a shape: what the panel could have set. Names an object's type does not declare are refused, as
|
|
35
|
+
* a prop the story does not declare is: a link must not reach an element's attributes through them.
|
|
36
|
+
*
|
|
37
|
+
* @param shape - the shape.
|
|
38
|
+
* @param value - the value.
|
|
39
|
+
* @param namedValues - the source's named values.
|
|
40
|
+
*/
|
|
41
|
+
export declare const isValueOfShape: (shape: ValueShape, value: ArgValue, namedValues: NamedValues) => boolean;
|
|
42
|
+
/**
|
|
43
|
+
* The value a shape starts from when the panel first gives it one: what a required part must hold, so a value the
|
|
44
|
+
* panel sends always fits its type.
|
|
45
|
+
*
|
|
46
|
+
* @param shape - the shape.
|
|
47
|
+
* @param namedValues - the source's named values.
|
|
48
|
+
* @returns the value; none when the source names none for a part that needs one.
|
|
49
|
+
*/
|
|
50
|
+
export declare const startValueOf: (shape: ValueShape, namedValues: NamedValues) => ArgValue | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* The shape a story's own arg shows, for an arg no type describes: fields from its names, a list's items from its
|
|
53
|
+
* items when they all look alike, JSON for the rest.
|
|
54
|
+
*
|
|
55
|
+
* @param value - the arg's value.
|
|
56
|
+
*/
|
|
57
|
+
export declare const shapeOfValue: (value: ArgValue) => ValueShape;
|
|
58
|
+
/**
|
|
59
|
+
* A shape with what a story's own arg looks like read from it.
|
|
60
|
+
*
|
|
61
|
+
* @param shape - the shape.
|
|
62
|
+
*/
|
|
63
|
+
export declare const resolvedShape: (shape: ValueShape) => ValueShape;
|
|
64
|
+
/** The longest text a `file` control keeps: a link holds the file, and a server refuses a longer address. */
|
|
65
|
+
export declare const MOST_FILE_TEXT = 8000;
|
|
66
|
+
/**
|
|
67
|
+
* Whether a text is what a `file` control sets: a small file as a `data:` address, of a type it keeps.
|
|
68
|
+
*
|
|
69
|
+
* @param value - the text.
|
|
70
|
+
*/
|
|
71
|
+
export declare const isFileText: (value: ArgValue) => boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Whether a value is what a `file` control sets.
|
|
74
|
+
*
|
|
75
|
+
* @param value - the value.
|
|
76
|
+
*/
|
|
77
|
+
export declare const isFileList: (value: ArgValue) => boolean;
|
|
78
|
+
/**
|
|
79
|
+
* A shape's worst value: an object's fields at their worst, a list of many items, a mixed union's first member that has a
|
|
80
|
+
* worst case.
|
|
81
|
+
*
|
|
82
|
+
* @param shape - the shape.
|
|
83
|
+
* @param namedValues - the source's named values, for a required part only they can fill.
|
|
84
|
+
* @returns the value; none when a long text or a huge number has no place in it, or when the address could not hold it.
|
|
85
|
+
*/
|
|
86
|
+
export declare const worstOfShape: (shape: ValueShape, namedValues: NamedValues) => ArgValue | undefined;
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What reads a value against its shape (`valueShape.ts`): whether it fits, what the panel starts from, what a story's own
|
|
3
|
+
* arg looks like, and the worst case of each kind. Loaded with the first prop that has a shape, so a catalogue of plain
|
|
4
|
+
* props never pays for it; the commands import it directly.
|
|
5
|
+
*
|
|
6
|
+
* @remarks
|
|
7
|
+
* A link's author chooses the values, and a component may spread an object onto an element. What a type declares is
|
|
8
|
+
* checked by name; what no type describes (`json`, `record`) is checked for what an element would run: an attribute that
|
|
9
|
+
* runs a script or writes markup, Vue's marks for a property or a modifier (`.innerHTML`, `^onclick`), an address that
|
|
10
|
+
* runs when opened, and a named value, which only a type offers. Pure.
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
import { isArgList, isArgObject, isArgValue, isDateArg, isNamedArg } from "./messages.js";
|
|
15
|
+
import { namedValueOf } from "./namedValues.js";
|
|
16
|
+
import { WORST_ARG_TEXT, WORST_NUMBER } from "./worstCase.js";
|
|
17
|
+
/**
|
|
18
|
+
* The names a free-form part of a value may not hold (`json`, `record`): an attribute that runs a script or writes
|
|
19
|
+
* markup when a component spreads the object onto an element. A link's author chooses these names, and no type says
|
|
20
|
+
* which are meant; an `on` word that is no event stays allowed.
|
|
21
|
+
*
|
|
22
|
+
* @param name - the name.
|
|
23
|
+
*/
|
|
24
|
+
export const isUnsafeFreeName = (name) => /^(dangerouslySetInnerHTML|innerHTML|outerHTML|srcdoc)$/i.test(name) ||
|
|
25
|
+
/^[.^:@#]/.test(name) ||
|
|
26
|
+
name.includes(":") ||
|
|
27
|
+
(/^on/i.test(name) && !/^(once|one|only|online|onboarding|ongoing|onward)$/.test(name));
|
|
28
|
+
/** Whether a text in a free-form value is an address a browser would run. */
|
|
29
|
+
const isRunnableText = (text) =>
|
|
30
|
+
// browsers skip control characters and white space inside a scheme, so a link's `java\tscript:` is the same address
|
|
31
|
+
/^(javascript|vbscript|data:text\/html)/i.test([...text].filter((each) => each > " ").join(""));
|
|
32
|
+
/**
|
|
33
|
+
* Whether a free-form value holds anything it may not hold, at any depth.
|
|
34
|
+
*
|
|
35
|
+
* @param value - the value.
|
|
36
|
+
* @param allowsNamed - whether a named value may be in it: a schema's author has said what it takes, and the name is looked
|
|
37
|
+
* up among the source's own values; `false` by default, where nothing has said.
|
|
38
|
+
*/
|
|
39
|
+
export const holdsUnsafePart = (value, allowsNamed = false) => {
|
|
40
|
+
if (typeof value === "string")
|
|
41
|
+
return isRunnableText(value);
|
|
42
|
+
if (isNamedArg(value))
|
|
43
|
+
return !allowsNamed;
|
|
44
|
+
if (isArgList(value))
|
|
45
|
+
return value.some((each) => holdsUnsafePart(each, allowsNamed));
|
|
46
|
+
if (!isArgObject(value))
|
|
47
|
+
return false;
|
|
48
|
+
return Object.entries(value).some(([name, each]) => isUnsafeFreeName(name) || holdsUnsafePart(each, allowsNamed));
|
|
49
|
+
};
|
|
50
|
+
/** Whether a value fits a tuple's items. */
|
|
51
|
+
const fitsTuple = (items, value, namedValues) => isArgList(value) &&
|
|
52
|
+
value.length === items.length &&
|
|
53
|
+
items.every((item, index) => {
|
|
54
|
+
const each = value[index];
|
|
55
|
+
return each !== undefined && isValueOfShape(item, each, namedValues);
|
|
56
|
+
});
|
|
57
|
+
/** Whether a value fits an object's fields, and names no other. */
|
|
58
|
+
const fitsObject = (fields, value, namedValues) => {
|
|
59
|
+
if (!isArgObject(value) || isNamedArg(value))
|
|
60
|
+
return false;
|
|
61
|
+
const isKnown = Object.keys(value).every((name) => fields.some((field) => field.name === name));
|
|
62
|
+
return (isKnown &&
|
|
63
|
+
fields.every((field) => {
|
|
64
|
+
const each = Object.hasOwn(value, field.name) ? value[field.name] : undefined;
|
|
65
|
+
if (each === undefined)
|
|
66
|
+
return !field.isRequired;
|
|
67
|
+
return (each === null && field.isNullable === true) || isValueOfShape(field.shape, each, namedValues);
|
|
68
|
+
}));
|
|
69
|
+
};
|
|
70
|
+
/** Whether a value fits a part only the source's named values fill, or a text where it takes one. */
|
|
71
|
+
const fitsNamed = (shape, value, namedValues) => {
|
|
72
|
+
if (typeof value === "string")
|
|
73
|
+
return shape.canTakeText === true;
|
|
74
|
+
return (isNamedArg(value) &&
|
|
75
|
+
value.of === shape.type &&
|
|
76
|
+
namedValueOf(namedValues, value.of, value.named) !== undefined);
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Whether a value fits a shape: what the panel could have set. Names an object's type does not declare are refused, as
|
|
80
|
+
* a prop the story does not declare is: a link must not reach an element's attributes through them.
|
|
81
|
+
*
|
|
82
|
+
* @param shape - the shape.
|
|
83
|
+
* @param value - the value.
|
|
84
|
+
* @param namedValues - the source's named values.
|
|
85
|
+
*/
|
|
86
|
+
export const isValueOfShape = (shape, value, namedValues) => {
|
|
87
|
+
switch (shape.kind) {
|
|
88
|
+
case "text":
|
|
89
|
+
return typeof value === "string";
|
|
90
|
+
case "date":
|
|
91
|
+
return isDateArg(value);
|
|
92
|
+
case "number":
|
|
93
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
94
|
+
case "boolean":
|
|
95
|
+
return typeof value === "boolean" && (shape.only === undefined || shape.only === value);
|
|
96
|
+
case "choice":
|
|
97
|
+
return (typeof value === "string" || typeof value === "number") && shape.values.includes(value);
|
|
98
|
+
case "list":
|
|
99
|
+
return isArgList(value) && value.every((item) => isValueOfShape(shape.of, item, namedValues));
|
|
100
|
+
case "tuple":
|
|
101
|
+
return fitsTuple(shape.items, value, namedValues);
|
|
102
|
+
case "object":
|
|
103
|
+
return fitsObject(shape.fields, value, namedValues);
|
|
104
|
+
case "record":
|
|
105
|
+
return (isArgObject(value) &&
|
|
106
|
+
!isNamedArg(value) &&
|
|
107
|
+
Object.entries(value).every(([name, each]) => !isUnsafeFreeName(name) && isValueOfShape(shape.of, each, namedValues)));
|
|
108
|
+
case "union":
|
|
109
|
+
return shape.of.some((member) => isValueOfShape(member, value, namedValues));
|
|
110
|
+
case "named":
|
|
111
|
+
return fitsNamed(shape, value, namedValues);
|
|
112
|
+
case "json":
|
|
113
|
+
return isArgValue(value) && !holdsUnsafePart(value);
|
|
114
|
+
case "like":
|
|
115
|
+
return isValueOfShape(shapeOfValue(shape.value), value, namedValues);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* The value a shape starts from when the panel first gives it one: what a required part must hold, so a value the
|
|
120
|
+
* panel sends always fits its type.
|
|
121
|
+
*
|
|
122
|
+
* @param shape - the shape.
|
|
123
|
+
* @param namedValues - the source's named values.
|
|
124
|
+
* @returns the value; none when the source names none for a part that needs one.
|
|
125
|
+
*/
|
|
126
|
+
export const startValueOf = (shape, namedValues) => {
|
|
127
|
+
switch (shape.kind) {
|
|
128
|
+
case "text":
|
|
129
|
+
return "";
|
|
130
|
+
case "date":
|
|
131
|
+
return { forgebookDate: new Date().toISOString() };
|
|
132
|
+
case "number":
|
|
133
|
+
return 0;
|
|
134
|
+
case "boolean":
|
|
135
|
+
return shape.only ?? false;
|
|
136
|
+
case "choice":
|
|
137
|
+
return shape.values[0];
|
|
138
|
+
case "list":
|
|
139
|
+
return [];
|
|
140
|
+
case "record":
|
|
141
|
+
return {};
|
|
142
|
+
case "json":
|
|
143
|
+
return null;
|
|
144
|
+
case "like":
|
|
145
|
+
return startValueOf(shapeOfValue(shape.value), namedValues);
|
|
146
|
+
case "tuple": {
|
|
147
|
+
const items = shape.items.map((item) => startValueOf(item, namedValues));
|
|
148
|
+
return items.every((item) => item !== undefined)
|
|
149
|
+
? items.filter((item) => item !== undefined)
|
|
150
|
+
: undefined;
|
|
151
|
+
}
|
|
152
|
+
case "object": {
|
|
153
|
+
const fields = shape.fields
|
|
154
|
+
.filter((field) => field.isRequired)
|
|
155
|
+
.map((field) => [field.name, startValueOf(field.shape, namedValues)]);
|
|
156
|
+
return fields.every(([, each]) => each !== undefined)
|
|
157
|
+
? Object.fromEntries(fields.flatMap(([name, each]) => (each === undefined ? [] : [[name, each]])))
|
|
158
|
+
: undefined;
|
|
159
|
+
}
|
|
160
|
+
case "union":
|
|
161
|
+
return shape.of.map((member) => startValueOf(member, namedValues)).find((start) => start !== undefined);
|
|
162
|
+
case "named": {
|
|
163
|
+
if (Object.hasOwn(namedValues, shape.type)) {
|
|
164
|
+
const [first] = Object.keys(namedValues[shape.type] ?? {});
|
|
165
|
+
if (first !== undefined)
|
|
166
|
+
return { of: shape.type, named: first };
|
|
167
|
+
}
|
|
168
|
+
return shape.canTakeText === true ? "" : undefined;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* The shape a story's own arg shows, for an arg no type describes: fields from its names, a list's items from its
|
|
174
|
+
* items when they all look alike, JSON for the rest.
|
|
175
|
+
*
|
|
176
|
+
* @param value - the arg's value.
|
|
177
|
+
*/
|
|
178
|
+
export const shapeOfValue = (value) => {
|
|
179
|
+
if (typeof value === "string")
|
|
180
|
+
return { kind: "text" };
|
|
181
|
+
if (typeof value === "number")
|
|
182
|
+
return { kind: "number" };
|
|
183
|
+
if (typeof value === "boolean")
|
|
184
|
+
return { kind: "boolean" };
|
|
185
|
+
if (isNamedArg(value))
|
|
186
|
+
return { kind: "named", type: value.of };
|
|
187
|
+
if (isDateArg(value))
|
|
188
|
+
return { kind: "date" };
|
|
189
|
+
if (isArgList(value)) {
|
|
190
|
+
const shapes = [...new Set(value.map((item) => JSON.stringify(shapeOfValue(item))))];
|
|
191
|
+
const [first] = value;
|
|
192
|
+
return {
|
|
193
|
+
kind: "list",
|
|
194
|
+
of: shapes.length === 1 && first !== undefined ? shapeOfValue(first) : { kind: "json" }
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
if (isArgObject(value)) {
|
|
198
|
+
return {
|
|
199
|
+
kind: "object",
|
|
200
|
+
fields: Object.entries(value).map(([name, each]) => ({
|
|
201
|
+
name,
|
|
202
|
+
shape: shapeOfValue(each),
|
|
203
|
+
isRequired: false
|
|
204
|
+
}))
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
return { kind: "json" };
|
|
208
|
+
};
|
|
209
|
+
/**
|
|
210
|
+
* A shape with what a story's own arg looks like read from it.
|
|
211
|
+
*
|
|
212
|
+
* @param shape - the shape.
|
|
213
|
+
*/
|
|
214
|
+
export const resolvedShape = (shape) => shape.kind === "like" ? shapeOfValue(shape.value) : shape;
|
|
215
|
+
/** The longest text a `file` control keeps: a link holds the file, and a server refuses a longer address. */
|
|
216
|
+
export const MOST_FILE_TEXT = 8000;
|
|
217
|
+
/** What a `file` control keeps: pictures, sound and film, a plain text and a PDF, none of which a browser runs as a page. */
|
|
218
|
+
const FILE_TYPES = /^data:((image\/(png|jpeg|gif|webp|avif|bmp|x-icon))|(audio\/[\w.+-]+)|(video\/[\w.+-]+)|text\/plain|application\/pdf)(;[\w=.+-]+)*,/i;
|
|
219
|
+
/**
|
|
220
|
+
* Whether a text is what a `file` control sets: a small file as a `data:` address, of a type it keeps.
|
|
221
|
+
*
|
|
222
|
+
* @param value - the text.
|
|
223
|
+
*/
|
|
224
|
+
export const isFileText = (value) => typeof value === "string" && value.length <= MOST_FILE_TEXT && FILE_TYPES.test(value);
|
|
225
|
+
/**
|
|
226
|
+
* Whether a value is what a `file` control sets.
|
|
227
|
+
*
|
|
228
|
+
* @param value - the value.
|
|
229
|
+
*/
|
|
230
|
+
export const isFileList = (value) => isArgList(value) && value.every(isFileText);
|
|
231
|
+
/** How many items a list at the top takes in the worst case: more than a row or a page of a list lays out comfortably. */
|
|
232
|
+
const WORST_ITEMS = 12;
|
|
233
|
+
/** How many items a list inside another part takes: several levels of many would write an address no server takes. */
|
|
234
|
+
const WORST_NESTED_ITEMS = 2;
|
|
235
|
+
/** The longest worst value kept, as JSON: an address holds it, and a server refuses a longer one. */
|
|
236
|
+
const MOST_WORST_TEXT = 3000;
|
|
237
|
+
/** A tuple's worst value: each item's, or what it must hold; none when no item has a worst case. */
|
|
238
|
+
const worstTuple = (shapes, namedValues, depth) => {
|
|
239
|
+
const items = shapes.map((item) => worstAt(item, namedValues, depth + 1) ?? startValueOf(item, namedValues));
|
|
240
|
+
const fitted = items.filter((item) => item !== undefined);
|
|
241
|
+
const hasWorst = shapes.some((item) => worstAt(item, namedValues, depth + 1) !== undefined);
|
|
242
|
+
return hasWorst && fitted.length === items.length ? fitted : undefined;
|
|
243
|
+
};
|
|
244
|
+
/** An object's worst value: each field's, or what a required one must hold; none when no field has a worst case. */
|
|
245
|
+
const worstObject = (shapes, namedValues, depth) => {
|
|
246
|
+
const fields = shapes.flatMap((field) => {
|
|
247
|
+
const worst = worstAt(field.shape, namedValues, depth + 1);
|
|
248
|
+
if (worst !== undefined)
|
|
249
|
+
return [[field.name, worst, true]];
|
|
250
|
+
const start = field.isRequired ? startValueOf(field.shape, namedValues) : undefined;
|
|
251
|
+
return start === undefined ? [] : [[field.name, start, false]];
|
|
252
|
+
});
|
|
253
|
+
const isWhole = shapes.every((field) => !field.isRequired || fields.some(([name]) => name === field.name));
|
|
254
|
+
return isWhole && fields.some(([, , isWorst]) => isWorst)
|
|
255
|
+
? Object.fromEntries(fields.map(([name, value]) => [name, value]))
|
|
256
|
+
: undefined;
|
|
257
|
+
};
|
|
258
|
+
/** A shape's worst value, however long. */
|
|
259
|
+
const worstAt = (shape, namedValues, depth) => {
|
|
260
|
+
switch (shape.kind) {
|
|
261
|
+
case "text":
|
|
262
|
+
return WORST_ARG_TEXT;
|
|
263
|
+
case "number":
|
|
264
|
+
return WORST_NUMBER;
|
|
265
|
+
case "like":
|
|
266
|
+
return worstAt(shapeOfValue(shape.value), namedValues, depth);
|
|
267
|
+
case "list": {
|
|
268
|
+
const item = worstAt(shape.of, namedValues, depth + 1);
|
|
269
|
+
const length = depth === 0 ? WORST_ITEMS : WORST_NESTED_ITEMS;
|
|
270
|
+
return item === undefined ? undefined : Array.from({ length }, () => item);
|
|
271
|
+
}
|
|
272
|
+
case "tuple":
|
|
273
|
+
return worstTuple(shape.items, namedValues, depth);
|
|
274
|
+
case "object":
|
|
275
|
+
return worstObject(shape.fields, namedValues, depth);
|
|
276
|
+
case "union":
|
|
277
|
+
return shape.of
|
|
278
|
+
.map((member) => worstAt(member, namedValues, depth + 1))
|
|
279
|
+
.find((each) => each !== undefined);
|
|
280
|
+
default:
|
|
281
|
+
return undefined;
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
/**
|
|
285
|
+
* A shape's worst value: an object's fields at their worst, a list of many items, a mixed union's first member that has a
|
|
286
|
+
* worst case.
|
|
287
|
+
*
|
|
288
|
+
* @param shape - the shape.
|
|
289
|
+
* @param namedValues - the source's named values, for a required part only they can fill.
|
|
290
|
+
* @returns the value; none when a long text or a huge number has no place in it, or when the address could not hold it.
|
|
291
|
+
*/
|
|
292
|
+
export const worstOfShape = (shape, namedValues) => {
|
|
293
|
+
const worst = worstAt(shape, namedValues, 0);
|
|
294
|
+
return worst !== undefined && JSON.stringify(worst).length <= MOST_WORST_TEXT ? worst : undefined;
|
|
295
|
+
};
|