@scaffold-ui-kit/preview 0.0.0-stage → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +1868 -2
- package/application/host/bootstrap.ts +43 -0
- package/application/host/main.ts +31 -0
- package/application/host/shell-host.ts +47 -0
- package/application/index.html +12 -0
- package/application/lib/base-url.ts +15 -0
- package/application/lib/no-code-block.ts +7 -0
- package/application/lib/no-setup.ts +3 -0
- package/application/lib/no-views.ts +6 -0
- package/application/preview/code/code.html +12 -0
- package/application/preview/code/main.ts +89 -0
- package/application/preview/globals.ts +254 -0
- package/application/preview/html/main.ts +93 -0
- package/application/preview/html/preview.html +12 -0
- package/application/preview/react/main.tsx +146 -0
- package/application/preview/react/preview.html +12 -0
- package/application/preview/svelte/Preview.svelte +104 -0
- package/application/preview/svelte/main.ts +13 -0
- package/application/preview/svelte/preview.html +12 -0
- package/application/preview/svelte/story-props.ts +172 -0
- package/application/preview/view/main.ts +124 -0
- package/application/preview/view/view.html +12 -0
- package/application/preview/vue/main.ts +145 -0
- package/application/preview/vue/preview.html +12 -0
- package/application/shells/charcell/components/Application/index.css +37 -0
- package/application/shells/charcell/components/Application/index.tsx +65 -0
- package/application/shells/charcell/components/Bar/index.css +68 -0
- package/application/shells/charcell/components/Bar/index.tsx +60 -0
- package/application/shells/charcell/components/CodePane/index.css +60 -0
- package/application/shells/charcell/components/CodePane/index.tsx +113 -0
- package/application/shells/charcell/components/ComponentStage/index.css +26 -0
- package/application/shells/charcell/components/ComponentStage/index.tsx +110 -0
- package/application/shells/charcell/components/Control/index.css +20 -0
- package/application/shells/charcell/components/Control/index.tsx +118 -0
- package/application/shells/charcell/components/CopyLink/index.tsx +35 -0
- package/application/shells/charcell/components/Description/index.css +6 -0
- package/application/shells/charcell/components/Description/index.tsx +24 -0
- package/application/shells/charcell/components/EditorAddDialog/index.css +9 -0
- package/application/shells/charcell/components/EditorAddDialog/index.tsx +158 -0
- package/application/shells/charcell/components/EditorPanel/index.css +48 -0
- package/application/shells/charcell/components/EditorPanel/index.tsx +496 -0
- package/application/shells/charcell/components/EventsRow/index.css +42 -0
- package/application/shells/charcell/components/EventsRow/index.tsx +68 -0
- package/application/shells/charcell/components/HeadingRow/index.css +11 -0
- package/application/shells/charcell/components/HeadingRow/index.tsx +16 -0
- package/application/shells/charcell/components/Hint/index.css +16 -0
- package/application/shells/charcell/components/Hint/index.tsx +81 -0
- package/application/shells/charcell/components/HtmlWarnings/index.tsx +45 -0
- package/application/shells/charcell/components/KeyHints/index.css +27 -0
- package/application/shells/charcell/components/KeyHints/index.tsx +106 -0
- package/application/shells/charcell/components/KitCodeBlock/index.css +55 -0
- package/application/shells/charcell/components/KitCodeBlock/index.tsx +18 -0
- package/application/shells/charcell/components/Markdown/index.tsx +16 -0
- package/application/shells/charcell/components/Navigation/index.css +13 -0
- package/application/shells/charcell/components/Navigation/index.tsx +98 -0
- package/application/shells/charcell/components/NavigationSplit/index.css +16 -0
- package/application/shells/charcell/components/NavigationSplit/index.tsx +82 -0
- package/application/shells/charcell/components/OptionControls/index.tsx +93 -0
- package/application/shells/charcell/components/PaneStatus/index.css +7 -0
- package/application/shells/charcell/components/PaneStatus/index.tsx +47 -0
- package/application/shells/charcell/components/PaneWidth/index.tsx +45 -0
- package/application/shells/charcell/components/PreviewGrid/index.css +39 -0
- package/application/shells/charcell/components/PreviewGrid/index.tsx +344 -0
- package/application/shells/charcell/components/PreviewPane/index.css +127 -0
- package/application/shells/charcell/components/PreviewPane/index.tsx +182 -0
- package/application/shells/charcell/components/PromptBar/index.tsx +133 -0
- package/application/shells/charcell/components/ScenarioRow/index.css +36 -0
- package/application/shells/charcell/components/ScenarioRow/index.tsx +71 -0
- package/application/shells/charcell/components/Select/index.tsx +48 -0
- package/application/shells/charcell/components/SlotOutlet/index.css +7 -0
- package/application/shells/charcell/components/SlotOutlet/index.tsx +25 -0
- package/application/shells/charcell/components/StageBar/index.css +7 -0
- package/application/shells/charcell/components/StageBar/index.tsx +109 -0
- package/application/shells/charcell/components/StageSplit/index.css +11 -0
- package/application/shells/charcell/components/StageSplit/index.tsx +99 -0
- package/application/shells/charcell/components/StatusBar/index.tsx +30 -0
- package/application/shells/charcell/components/ViewControls/index.css +15 -0
- package/application/shells/charcell/components/ViewControls/index.tsx +58 -0
- package/application/shells/charcell/components/ViewHeading/index.css +13 -0
- package/application/shells/charcell/components/ViewHeading/index.tsx +8 -0
- package/application/shells/charcell/components/ViewStage/index.css +9 -0
- package/application/shells/charcell/components/ViewStage/index.tsx +25 -0
- package/application/shells/charcell/components/WrapToggle/index.tsx +27 -0
- package/application/shells/charcell/configuration.ts +45 -0
- package/application/shells/charcell/controller-context.ts +27 -0
- package/application/shells/charcell/fit-labels.ts +42 -0
- package/application/shells/charcell/html-warnings.ts +18 -0
- package/application/shells/charcell/index.tsx +82 -0
- package/application/shells/charcell/page-loading.html +57 -0
- package/application/shells/charcell/placement.ts +24 -0
- package/application/shells/charcell/shell-options.ts +23 -0
- package/application/shells/charcell/shell.css +37 -0
- package/application/shells/charcell/shell.tsx +25 -0
- package/application/shells/charcell/split-reset.ts +47 -0
- package/application/shells/charcell/stacked-rows.ts +117 -0
- package/application/shells/charcell/stage-toggles.ts +93 -0
- package/application/types/manifest.d.ts +6 -0
- package/application/types/preview-configuration.d.ts +10 -0
- package/application/types/preview-shell.d.ts +7 -0
- package/application/types/react-registry.d.ts +15 -0
- package/application/types/vue-registry.d.ts +6 -0
- package/dist/build.d.ts +24 -0
- package/dist/build.js +34 -0
- package/dist/check.d.ts +48 -0
- package/dist/check.js +781 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +88 -0
- package/dist/context.d.ts +179 -0
- package/dist/context.js +783 -0
- package/dist/controller/catalog.d.ts +339 -0
- package/dist/controller/catalog.js +367 -0
- package/dist/controller/create-preview-controller.d.ts +532 -0
- package/dist/controller/create-preview-controller.js +1707 -0
- package/dist/controller/editor-tree.d.ts +161 -0
- package/dist/controller/editor-tree.js +373 -0
- package/dist/controller/html-source.d.ts +62 -0
- package/dist/controller/html-source.js +61 -0
- package/dist/controller/index.d.ts +9 -0
- package/dist/controller/index.js +12 -0
- package/dist/controller/persistence.d.ts +191 -0
- package/dist/controller/persistence.js +315 -0
- package/dist/controller/regeneration.d.ts +30 -0
- package/dist/controller/regeneration.js +27 -0
- package/dist/controller/source.d.ts +80 -0
- package/dist/controller/source.js +236 -0
- package/dist/controller/store.d.ts +27 -0
- package/dist/controller/store.js +40 -0
- package/dist/declarations/application/shells/charcell/components/Application/index.d.ts +2 -0
- package/dist/declarations/application/shells/charcell/components/Bar/index.d.ts +11 -0
- package/dist/declarations/application/shells/charcell/components/CodePane/index.d.ts +5 -0
- package/dist/declarations/application/shells/charcell/components/ComponentStage/index.d.ts +2 -0
- package/dist/declarations/application/shells/charcell/components/Control/index.d.ts +9 -0
- package/dist/declarations/application/shells/charcell/components/CopyLink/index.d.ts +1 -0
- package/dist/declarations/application/shells/charcell/components/Description/index.d.ts +5 -0
- package/dist/declarations/application/shells/charcell/components/EditorAddDialog/index.d.ts +6 -0
- package/dist/declarations/application/shells/charcell/components/EditorPanel/index.d.ts +2 -0
- package/dist/declarations/application/shells/charcell/components/EventsRow/index.d.ts +4 -0
- package/dist/declarations/application/shells/charcell/components/HeadingRow/index.d.ts +6 -0
- package/dist/declarations/application/shells/charcell/components/Hint/index.d.ts +11 -0
- package/dist/declarations/application/shells/charcell/components/HtmlWarnings/index.d.ts +5 -0
- package/dist/declarations/application/shells/charcell/components/KeyHints/index.d.ts +2 -0
- package/dist/declarations/application/shells/charcell/components/KitCodeBlock/index.d.ts +5 -0
- package/dist/declarations/application/shells/charcell/components/Markdown/index.d.ts +3 -0
- package/dist/declarations/application/shells/charcell/components/Navigation/index.d.ts +8 -0
- package/dist/declarations/application/shells/charcell/components/NavigationSplit/index.d.ts +7 -0
- package/dist/declarations/application/shells/charcell/components/OptionControls/index.d.ts +7 -0
- package/dist/declarations/application/shells/charcell/components/PaneStatus/index.d.ts +2 -0
- package/dist/declarations/application/shells/charcell/components/PaneWidth/index.d.ts +4 -0
- package/dist/declarations/application/shells/charcell/components/PreviewGrid/index.d.ts +7 -0
- package/dist/declarations/application/shells/charcell/components/PreviewPane/index.d.ts +9 -0
- package/dist/declarations/application/shells/charcell/components/PromptBar/index.d.ts +1 -0
- package/dist/declarations/application/shells/charcell/components/ScenarioRow/index.d.ts +2 -0
- package/dist/declarations/application/shells/charcell/components/Select/index.d.ts +16 -0
- package/dist/declarations/application/shells/charcell/components/SlotOutlet/index.d.ts +5 -0
- package/dist/declarations/application/shells/charcell/components/StageBar/index.d.ts +2 -0
- package/dist/declarations/application/shells/charcell/components/StageSplit/index.d.ts +17 -0
- package/dist/declarations/application/shells/charcell/components/StatusBar/index.d.ts +1 -0
- package/dist/declarations/application/shells/charcell/components/ViewControls/index.d.ts +9 -0
- package/dist/declarations/application/shells/charcell/components/ViewHeading/index.d.ts +4 -0
- package/dist/declarations/application/shells/charcell/components/ViewStage/index.d.ts +4 -0
- package/dist/declarations/application/shells/charcell/components/WrapToggle/index.d.ts +1 -0
- package/dist/declarations/application/shells/charcell/configuration.d.ts +31 -0
- package/dist/declarations/application/shells/charcell/controller-context.d.ts +9 -0
- package/dist/declarations/application/shells/charcell/fit-labels.d.ts +18 -0
- package/dist/declarations/application/shells/charcell/html-warnings.d.ts +5 -0
- package/dist/declarations/application/shells/charcell/index.d.ts +39 -0
- package/dist/declarations/application/shells/charcell/placement.d.ts +7 -0
- package/dist/declarations/application/shells/charcell/shell-options.d.ts +15 -0
- package/dist/declarations/application/shells/charcell/shell.d.ts +9 -0
- package/dist/declarations/application/shells/charcell/split-reset.d.ts +30 -0
- package/dist/declarations/application/shells/charcell/stacked-rows.d.ts +58 -0
- package/dist/declarations/application/shells/charcell/stage-toggles.d.ts +28 -0
- package/dist/declarations/src/controller/catalog.d.ts +339 -0
- package/dist/declarations/src/controller/create-preview-controller.d.ts +532 -0
- package/dist/declarations/src/controller/editor-tree.d.ts +161 -0
- package/dist/declarations/src/controller/html-source.d.ts +62 -0
- package/dist/declarations/src/controller/index.d.ts +9 -0
- package/dist/declarations/src/controller/persistence.d.ts +191 -0
- package/dist/declarations/src/controller/regeneration.d.ts +30 -0
- package/dist/declarations/src/controller/source.d.ts +80 -0
- package/dist/declarations/src/controller/store.d.ts +27 -0
- package/dist/declarations/src/emit/common.d.ts +103 -0
- package/dist/declarations/src/emit/manifest.d.ts +138 -0
- package/dist/declarations/src/emit/source.d.ts +87 -0
- package/dist/declarations/src/lib/jsx-roots.d.ts +22 -0
- package/dist/declarations/src/lib/module-of-source.d.ts +18 -0
- package/dist/declarations/src/lib/naming.d.ts +29 -0
- package/dist/declarations/src/lib/react-spelling.d.ts +68 -0
- package/dist/declarations/src/lib/scenario-story.d.ts +41 -0
- package/dist/declarations/src/lib/slot-fill.d.ts +15 -0
- package/dist/declarations/src/lib/types.d.ts +741 -0
- package/dist/declarations/src/options.d.ts +224 -0
- package/dist/declarations/src/protocol.d.ts +541 -0
- package/dist/declarations/src/react-view.d.ts +22 -0
- package/dist/declarations/src/react.d.ts +17 -0
- package/dist/declarations/src/shell.d.ts +99 -0
- package/dist/declarations/src/views.d.ts +152 -0
- package/dist/development-server.d.ts +121 -0
- package/dist/development-server.js +331 -0
- package/dist/emit/common.d.ts +103 -0
- package/dist/emit/common.js +170 -0
- package/dist/emit/html-source.d.ts +46 -0
- package/dist/emit/html-source.js +322 -0
- package/dist/emit/manifest.d.ts +138 -0
- package/dist/emit/manifest.js +74 -0
- package/dist/emit/react.d.ts +16 -0
- package/dist/emit/react.js +210 -0
- package/dist/emit/scratch.d.ts +40 -0
- package/dist/emit/scratch.js +116 -0
- package/dist/emit/source.d.ts +87 -0
- package/dist/emit/source.js +789 -0
- package/dist/emit/svelte.d.ts +9 -0
- package/dist/emit/svelte.js +177 -0
- package/dist/emit/vue.d.ts +2 -0
- package/dist/emit/vue.js +152 -0
- package/dist/enumerate.d.ts +2 -0
- package/dist/enumerate.js +162 -0
- package/dist/generate.d.ts +43 -0
- package/dist/generate.js +302 -0
- package/dist/html-stylesheet.d.ts +43 -0
- package/dist/html-stylesheet.js +145 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +21 -0
- package/dist/landing.d.ts +16 -0
- package/dist/landing.js +45 -0
- package/dist/lib/exported-types.d.ts +42 -0
- package/dist/lib/exported-types.js +86 -0
- package/dist/lib/html-attributes.d.ts +2 -0
- package/dist/lib/html-attributes.js +111 -0
- package/dist/lib/html-warnings.d.ts +19 -0
- package/dist/lib/html-warnings.js +79 -0
- package/dist/lib/jsx-roots.d.ts +22 -0
- package/dist/lib/jsx-roots.js +243 -0
- package/dist/lib/module-of-source.d.ts +18 -0
- package/dist/lib/module-of-source.js +24 -0
- package/dist/lib/naming.d.ts +29 -0
- package/dist/lib/naming.js +56 -0
- package/dist/lib/parse-type.d.ts +32 -0
- package/dist/lib/parse-type.js +103 -0
- package/dist/lib/react-spelling.d.ts +68 -0
- package/dist/lib/react-spelling.js +197 -0
- package/dist/lib/scenario-story.d.ts +41 -0
- package/dist/lib/scenario-story.js +84 -0
- package/dist/lib/slot-fill.d.ts +15 -0
- package/dist/lib/slot-fill.js +92 -0
- package/dist/lib/template-files.d.ts +14 -0
- package/dist/lib/template-files.js +25 -0
- package/dist/lib/types.d.ts +741 -0
- package/dist/lib/types.js +13 -0
- package/dist/lib/void-elements.d.ts +7 -0
- package/dist/lib/void-elements.js +13 -0
- package/dist/load.d.ts +37 -0
- package/dist/load.js +82 -0
- package/dist/model.d.ts +44 -0
- package/dist/model.js +464 -0
- package/dist/options.d.ts +224 -0
- package/dist/options.js +223 -0
- package/dist/prop-types.d.ts +26 -0
- package/dist/prop-types.js +102 -0
- package/dist/props-from.d.ts +84 -0
- package/dist/props-from.js +510 -0
- package/dist/protocol.d.ts +541 -0
- package/dist/protocol.js +819 -0
- package/dist/react-view.d.ts +22 -0
- package/dist/react-view.js +36 -0
- package/dist/react.d.ts +17 -0
- package/dist/react.js +23 -0
- package/dist/sass-importers.d.ts +26 -0
- package/dist/sass-importers.js +32 -0
- package/dist/shell-acceptance.d.ts +21 -0
- package/dist/shell-acceptance.js +37 -0
- package/dist/shell-page.d.ts +36 -0
- package/dist/shell-page.js +90 -0
- package/dist/shell-peers.d.ts +38 -0
- package/dist/shell-peers.js +61 -0
- package/dist/shell.d.ts +99 -0
- package/dist/shell.js +52 -0
- package/dist/shells/charcell/page.d.ts +8 -0
- package/dist/shells/charcell/page.js +69 -0
- package/dist/story-source.d.ts +113 -0
- package/dist/story-source.js +271 -0
- package/dist/story.d.ts +5 -0
- package/dist/story.js +28 -0
- package/dist/testing.d.ts +218 -0
- package/dist/testing.js +284 -0
- package/dist/views.d.ts +152 -0
- package/dist/views.js +7 -0
- package/dist/vite-configuration.d.ts +114 -0
- package/dist/vite-configuration.js +578 -0
- package/package.json +123 -3
- package/src/build.ts +51 -0
- package/src/check.ts +1062 -0
- package/src/cli.ts +123 -0
- package/src/context.ts +1168 -0
- package/src/controller/catalog.ts +719 -0
- package/src/controller/create-preview-controller.ts +2683 -0
- package/src/controller/editor-tree.ts +530 -0
- package/src/controller/html-source.ts +114 -0
- package/src/controller/index.ts +105 -0
- package/src/controller/persistence.ts +403 -0
- package/src/controller/regeneration.ts +55 -0
- package/src/controller/source.ts +333 -0
- package/src/controller/store.ts +55 -0
- package/src/development-server.ts +442 -0
- package/src/emit/common.ts +201 -0
- package/src/emit/html-source.ts +402 -0
- package/src/emit/manifest.ts +241 -0
- package/src/emit/react.ts +263 -0
- package/src/emit/scratch.ts +175 -0
- package/src/emit/source.ts +1094 -0
- package/src/emit/svelte.ts +230 -0
- package/src/emit/vue.ts +194 -0
- package/src/enumerate.ts +220 -0
- package/src/generate.ts +443 -0
- package/src/html-stylesheet.ts +173 -0
- package/src/index.ts +60 -0
- package/src/landing.ts +58 -0
- package/src/lib/exported-types.ts +114 -0
- package/src/lib/html-attributes.ts +113 -0
- package/src/lib/html-warnings.ts +81 -0
- package/src/lib/jsx-roots.ts +238 -0
- package/src/lib/module-of-source.ts +26 -0
- package/src/lib/naming.ts +65 -0
- package/src/lib/parse-type.ts +143 -0
- package/src/lib/react-spelling.ts +235 -0
- package/src/lib/scenario-story.ts +97 -0
- package/src/lib/slot-fill.ts +102 -0
- package/src/lib/template-files.ts +31 -0
- package/src/lib/types.ts +778 -0
- package/src/lib/void-elements.ts +15 -0
- package/src/load.ts +144 -0
- package/src/model.ts +568 -0
- package/src/options.ts +435 -0
- package/src/prop-types.ts +133 -0
- package/src/props-from.ts +678 -0
- package/src/protocol.ts +1135 -0
- package/src/react-view.ts +45 -0
- package/src/react.ts +34 -0
- package/src/sass-importers.ts +45 -0
- package/src/shell-acceptance.ts +45 -0
- package/src/shell-page.ts +133 -0
- package/src/shell-peers.ts +70 -0
- package/src/shell.ts +194 -0
- package/src/shells/charcell/page.ts +82 -0
- package/src/story-source.ts +391 -0
- package/src/story.ts +42 -0
- package/src/testing.ts +497 -0
- package/src/views.ts +183 -0
- package/src/vite-configuration.ts +675 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { PreviewCatalog, PreviewController } from './controller/index.js';
|
|
2
|
+
import type { PreviewShellOption } from './options.js';
|
|
3
|
+
export { childPath, DEFAULT_PANE_WIDTHS, DEFAULT_SLOT, defaultScenarioId, isContainer, MAXIMUM_PANE_WIDTH, PREVIEW_FRAME_SHOWN_ATTRIBUTE, nodeAt, nodeAddSlots, nodeSlots, previewStore, printStorySource, scenarioChoices, storyFrameKey, type AroundFill, type ContainerNode, type DropTarget, type EditorNode, type EditorState, type NodePath, type OpaqueFill, type PreviewBinding, type PreviewCatalog, type PreviewCatalogView, type PreviewComponent, type PreviewController, type PreviewEditorState, type PreviewEvent, type PreviewFrameReadiness, type PreviewFrameTarget, type PreviewTargetCode, type PreviewHtmlSource, type PreviewImport, type PreviewInsertTarget, type PreviewLanding, type PreviewNavigationNode, type PreviewNodeRequest, type PreviewOptionDescriptor, type PreviewPaneWidth, type PreviewPropType, type PreviewRegenerationStatus, type PreviewScenario, type PreviewSource, type PreviewSelection, type PreviewSortableDrop, type PreviewCode, type PreviewState, type PreviewStore, type PreviewStoryReference, type ScenarioChoice, type SortableListAddress, type Step, type StoryAround, } from './controller/index.js';
|
|
4
|
+
export { CONTEXT_OPTION_GROUP, KIT_OPTION_GROUP, optionGroup, optionKind, shellOptionId, type OptionChoice, type OptionKind, type OptionValue, type PreviewShellOption, } from './options.js';
|
|
5
|
+
export { PREVIEW_SCRIPTED_TARGETS, PREVIEW_TARGETS, type PreviewContentSize, type PreviewScriptedTarget, type PreviewTarget, } from './protocol.js';
|
|
6
|
+
export type { ViewFramework } from './views.js';
|
|
7
|
+
/** The version of the shell contract this preview serves. */
|
|
8
|
+
export declare const PREVIEW_SHELL_API_VERSION = 1;
|
|
9
|
+
/**
|
|
10
|
+
* What a shell module default-exports: the contract version it was written
|
|
11
|
+
* against, its own options, and how it mounts.
|
|
12
|
+
*/
|
|
13
|
+
export interface PreviewShell {
|
|
14
|
+
/** The shell contract version the shell was written against. The preview
|
|
15
|
+
* refuses a shell whose version it does not serve. */
|
|
16
|
+
apiVersion: number;
|
|
17
|
+
/** The shell's own options, such as its color mode or density. The preview
|
|
18
|
+
* keeps their values beside the kit's, under `shell.<id>`. A function is
|
|
19
|
+
* called once with the kit's catalog before the preview starts, for options
|
|
20
|
+
* that depend on the kit, such as a choice among its targets. */
|
|
21
|
+
options?: PreviewShellOption[] | ((catalog: PreviewCatalog) => PreviewShellOption[]);
|
|
22
|
+
/**
|
|
23
|
+
* Render the shell into `root`, reading and driving `controller`.
|
|
24
|
+
*
|
|
25
|
+
* @param root - The host page's root element, empty.
|
|
26
|
+
* @param controller - The preview's behavior.
|
|
27
|
+
* @returns A function that unmounts the shell, or nothing when there is
|
|
28
|
+
* nothing to undo. The preview calls it before mounting a changed shell
|
|
29
|
+
* over the same controller during development.
|
|
30
|
+
*/
|
|
31
|
+
mount(root: HTMLElement, controller: PreviewController): (() => void) | void;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Declare a shell. The function only types its argument and returns it, so a
|
|
35
|
+
* shell module reads as one declaration.
|
|
36
|
+
*
|
|
37
|
+
* @param shell - The shell.
|
|
38
|
+
* @returns The shell, unchanged.
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* export default defineShell({
|
|
42
|
+
* apiVersion: 1,
|
|
43
|
+
* options: [{ id: 'density', label: 'density', default: false }],
|
|
44
|
+
* mount(root, controller) {
|
|
45
|
+
* const stop = controller.subscribe((state) => render(root, state));
|
|
46
|
+
* render(root, controller.getState());
|
|
47
|
+
* return stop;
|
|
48
|
+
* },
|
|
49
|
+
* });
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function defineShell(shell: PreviewShell): PreviewShell;
|
|
53
|
+
/** What a shell page's `head` and `root` functions are given. */
|
|
54
|
+
export interface ShellPageContext {
|
|
55
|
+
/**
|
|
56
|
+
* The address of a file the page's markup references, such as a font to
|
|
57
|
+
* preload: the development server serves the file from where it is, and the
|
|
58
|
+
* static build copies it into its output.
|
|
59
|
+
*
|
|
60
|
+
* @param file - The file's absolute path.
|
|
61
|
+
* @returns The address to write into the markup, in an `href`, a `src` or
|
|
62
|
+
* a CSS `url()`.
|
|
63
|
+
*/
|
|
64
|
+
asset(file: string): string;
|
|
65
|
+
}
|
|
66
|
+
/** A part of the host page a shell supplies: markup, or a function that
|
|
67
|
+
* gives it. */
|
|
68
|
+
export type ShellPageMarkup = string | ((context: ShellPageContext) => string | Promise<string>);
|
|
69
|
+
/**
|
|
70
|
+
* What a shell's page module default-exports: the static start of the host
|
|
71
|
+
* page, which shows before the shell's script has loaded. The module is
|
|
72
|
+
* evaluated in Node as the preview starts or builds, so it reads files and
|
|
73
|
+
* resolves packages freely and holds nothing that needs a browser.
|
|
74
|
+
*/
|
|
75
|
+
export interface ShellPage {
|
|
76
|
+
/** Markup for the end of the page's `<head>`: styles, a font face, links
|
|
77
|
+
* that preload what the shell will need. It stays for the life of the
|
|
78
|
+
* page. */
|
|
79
|
+
head?: ShellPageMarkup;
|
|
80
|
+
/** Markup for the page's root element, shown until the shell mounts: a
|
|
81
|
+
* loading note, with the styles only it needs. The preview empties the
|
|
82
|
+
* root before it mounts the shell. */
|
|
83
|
+
root?: ShellPageMarkup;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Declare a shell's page. The function only types its argument and returns
|
|
87
|
+
* it, so a page module reads as one declaration.
|
|
88
|
+
*
|
|
89
|
+
* @param page - The page.
|
|
90
|
+
* @returns The page, unchanged.
|
|
91
|
+
* @example
|
|
92
|
+
* ```ts
|
|
93
|
+
* export default defineShellPage({
|
|
94
|
+
* head: '<style>html { background: #101010; }</style>',
|
|
95
|
+
* root: '<p role="status">loading</p>',
|
|
96
|
+
* });
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export declare function defineShellPage(page: ShellPage): ShellPage;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import type { OptionValue } from './options.js';
|
|
2
|
+
export { reactView, type ReactViewRender } from './react-view.js';
|
|
3
|
+
/** One entry of the component index a view receives: a browseable story the
|
|
4
|
+
* view can cross-reference or select. */
|
|
5
|
+
export interface ViewContextComponent {
|
|
6
|
+
/** The component's selection id - pass to `selectComponent` to open its story. */
|
|
7
|
+
id: string;
|
|
8
|
+
/** The full title (source label prefix included). */
|
|
9
|
+
title: string;
|
|
10
|
+
/** The preview source (navigation section) the component belongs to. */
|
|
11
|
+
source: string;
|
|
12
|
+
}
|
|
13
|
+
/** A source as a view sees it - the kit's own source plus any other package whose components it shows. */
|
|
14
|
+
export interface ViewContextSource {
|
|
15
|
+
id: string;
|
|
16
|
+
label: string;
|
|
17
|
+
order: number;
|
|
18
|
+
}
|
|
19
|
+
/** What the preview passes a view. `options` is live (a new context arrives
|
|
20
|
+
* on every change, see `ViewContextUpdates`); the catalog fields are a
|
|
21
|
+
* read-only snapshot of the kit's catalog, so a view can cross-link into a
|
|
22
|
+
* component story. A view reads
|
|
23
|
+
* what it needs (a foundations view reads `options.theme` to pick its palette;
|
|
24
|
+
* a gallery resolves a component from `components` and deep-links via
|
|
25
|
+
* `selectComponent`). */
|
|
26
|
+
export interface ViewContext {
|
|
27
|
+
options: Record<string, OptionValue>;
|
|
28
|
+
/** The kit being previewed. Empty until the host handshake delivers the catalog. */
|
|
29
|
+
kitName: string;
|
|
30
|
+
/** The sources, ordered. Empty until the handshake delivers the catalog. */
|
|
31
|
+
sources: ViewContextSource[];
|
|
32
|
+
/** The browseable component stories (components that are not standalone and unlisted
|
|
33
|
+
* stories excluded; an unlisted story's id still selects it). Empty until
|
|
34
|
+
* the handshake delivers the catalog. */
|
|
35
|
+
components: ViewContextComponent[];
|
|
36
|
+
/**
|
|
37
|
+
* Ask the preview to select a component story, as choosing it in the
|
|
38
|
+
* preview's navigation does. With `props`, the story opens with those root props merged
|
|
39
|
+
* over the component's defaults (a gallery opens the clicked entry's variant);
|
|
40
|
+
* without, it opens on its baseline scenario. Unknown ids are ignored.
|
|
41
|
+
*/
|
|
42
|
+
selectComponent: (id: string, props?: Record<string, unknown>) => void;
|
|
43
|
+
}
|
|
44
|
+
/** Fields common to every navigation entry a kit registers. */
|
|
45
|
+
interface PreviewEntryBase {
|
|
46
|
+
/** Reserved selection id - also the view iframe's `?view=` parameter. */
|
|
47
|
+
id: string;
|
|
48
|
+
/** The entry's name in the navigation. */
|
|
49
|
+
label: string;
|
|
50
|
+
/** The source whose entries list this one (a source id from
|
|
51
|
+
* `preview.sources`); defaults to the kit's own (first) source. */
|
|
52
|
+
source?: string;
|
|
53
|
+
/** Position among the source's entries - lower first. Views and the
|
|
54
|
+
* auto-generated component tree interleave by this. */
|
|
55
|
+
order?: number;
|
|
56
|
+
}
|
|
57
|
+
/** The framework a view mounts with. The view iframe loads the kit's setup
|
|
58
|
+
* module for that framework (`preview.setupModules`) before it
|
|
59
|
+
* mounts the view; `'dom'` loads none. */
|
|
60
|
+
export type ViewFramework = 'react' | 'vue' | 'svelte' | 'dom';
|
|
61
|
+
/** How a mounted view hears of a changed context: the options as the
|
|
62
|
+
* preview applies them, and the catalog once the handshake delivers it. */
|
|
63
|
+
export interface ViewContextUpdates {
|
|
64
|
+
/**
|
|
65
|
+
* Call `listener` with each new context.
|
|
66
|
+
*
|
|
67
|
+
* @returns A function that stops the calls.
|
|
68
|
+
*/
|
|
69
|
+
subscribe(listener: (context: ViewContext) => void): () => void;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Mount a view into `element` with the context as it stands. The view stays
|
|
73
|
+
* mounted for the life of the view iframe and follows later changes through
|
|
74
|
+
* `updates`; a view that ignores them shows the context it mounted with.
|
|
75
|
+
*
|
|
76
|
+
* @param element - The element the view renders into.
|
|
77
|
+
* @param context - The context as it stands when the view mounts.
|
|
78
|
+
* @param updates - Delivers each new context.
|
|
79
|
+
* @returns A function that unmounts the view, or nothing.
|
|
80
|
+
*/
|
|
81
|
+
export type ViewMount = (element: HTMLElement, context: ViewContext, updates: ViewContextUpdates) => (() => void) | void;
|
|
82
|
+
/** A consumer-authored panel: the preview lists it beside the component stories
|
|
83
|
+
* and mounts it in the generic view iframe (`?view=<id>`) under the live
|
|
84
|
+
* options. */
|
|
85
|
+
export interface RenderedView extends PreviewEntryBase {
|
|
86
|
+
/** Discriminant - omit (or `false`) for a rendered view. */
|
|
87
|
+
componentTree?: false;
|
|
88
|
+
/** The framework `mount` renders with. Default `'dom'`. */
|
|
89
|
+
framework?: ViewFramework;
|
|
90
|
+
/** Mount the view inside the view iframe. */
|
|
91
|
+
mount: ViewMount;
|
|
92
|
+
}
|
|
93
|
+
/** The "magic" entry standing in for the source's auto-generated component tree (its
|
|
94
|
+
* stories) at a chosen position. It mounts no iframe, so it carries no `mount`. */
|
|
95
|
+
export interface ComponentTreeEntry extends PreviewEntryBase {
|
|
96
|
+
componentTree: true;
|
|
97
|
+
mount?: never;
|
|
98
|
+
}
|
|
99
|
+
/** A navigation entry a kit's `viewsModule` registers: either a rendered view or the
|
|
100
|
+
* component-tree marker. The two interleave by `order`. */
|
|
101
|
+
export type PreviewView = RenderedView | ComponentTreeEntry;
|
|
102
|
+
/** What the kit's `viewsModule` must export. */
|
|
103
|
+
export interface PreviewViewsModule {
|
|
104
|
+
views: PreviewView[];
|
|
105
|
+
viewById: (id: string) => PreviewView | undefined;
|
|
106
|
+
}
|
|
107
|
+
/** The language of a code block's source, as a highlighter names it: a
|
|
108
|
+
* scripted target's file (`tsx`, `vue`, `svelte`) or the html target's
|
|
109
|
+
* markup. */
|
|
110
|
+
export type CodeBlockLanguage = 'tsx' | 'vue' | 'svelte' | 'html';
|
|
111
|
+
/** What a code block shows: one target's source of the story, or, while it
|
|
112
|
+
* has none, nothing (it is being printed) or why there is none. */
|
|
113
|
+
export interface CodeBlockContent {
|
|
114
|
+
/** The target the source is for: a scripted target, or `html`. */
|
|
115
|
+
target: 'react' | 'vue' | 'svelte' | 'html';
|
|
116
|
+
language: CodeBlockLanguage;
|
|
117
|
+
/** The source, as a consumer writes it. */
|
|
118
|
+
source?: string;
|
|
119
|
+
/** Why the target has no source, when it has none to be had. */
|
|
120
|
+
reason?: string;
|
|
121
|
+
/** Whether the shell wraps its code panes' long lines: the block wraps
|
|
122
|
+
* them when true and scrolls sideways when false. A shell with no such
|
|
123
|
+
* choice sends false. */
|
|
124
|
+
wrap: boolean;
|
|
125
|
+
}
|
|
126
|
+
/** How a mounted code block hears of a new source: each time the story, its
|
|
127
|
+
* props or its content change, or the shell's wrapping does. */
|
|
128
|
+
export interface CodeBlockUpdates {
|
|
129
|
+
/**
|
|
130
|
+
* Call `listener` with each new content.
|
|
131
|
+
*
|
|
132
|
+
* @returns A function that stops the calls.
|
|
133
|
+
*/
|
|
134
|
+
subscribe(listener: (content: CodeBlockContent) => void): () => void;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Mount a kit's code block into `element`, showing `content`, the default
|
|
138
|
+
* export of the module the kit names as its `codeBlock`. The block stays
|
|
139
|
+
* mounted for the life of its iframe, one per code pane, and follows later
|
|
140
|
+
* sources through `updates`. It wraps long lines while `content.wrap` is
|
|
141
|
+
* true and scrolls sideways while it is false, as the shell's own panes do.
|
|
142
|
+
* The iframe's page is the block's alone: its root carries
|
|
143
|
+
* `data-preview-frame="code"`, so the kit's stylesheet may style the frame's
|
|
144
|
+
* `html` and `body` by it, say in the block's background so an overscroll
|
|
145
|
+
* shows no other color.
|
|
146
|
+
*
|
|
147
|
+
* @param element - The element the block renders into.
|
|
148
|
+
* @param content - The source as it stands when the block mounts.
|
|
149
|
+
* @param updates - Delivers each new source.
|
|
150
|
+
* @returns A function that unmounts the block, or nothing.
|
|
151
|
+
*/
|
|
152
|
+
export type CodeBlockMount = (element: HTMLElement, content: CodeBlockContent, updates: CodeBlockUpdates) => (() => void) | void;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { ConfigurationLookupOptions } from 'scaffold-ui-kit';
|
|
2
|
+
import { type Plugin, type ViteDevServer } from 'vite';
|
|
3
|
+
import { type PreviewContext } from './context.js';
|
|
4
|
+
import { type DevelopmentServerOverrides } from './vite-configuration.js';
|
|
5
|
+
/** How long a burst of saves settles before the preview regenerates. */
|
|
6
|
+
export declare const REGENERATION_DELAY_MILLISECONDS = 100;
|
|
7
|
+
/**
|
|
8
|
+
* The kit's own modules generation has loaded: the templates and story files,
|
|
9
|
+
* and every module of the kit they import.
|
|
10
|
+
*
|
|
11
|
+
* @param context - The kit's preview context.
|
|
12
|
+
* @returns Their absolute paths.
|
|
13
|
+
*/
|
|
14
|
+
export declare function loadedKitModules(context: PreviewContext): string[];
|
|
15
|
+
/**
|
|
16
|
+
* Forgets the kit's loaded modules, so the next generation imports each one
|
|
17
|
+
* afresh from disk. Installed packages stay loaded.
|
|
18
|
+
*
|
|
19
|
+
* @param context - The kit's preview context.
|
|
20
|
+
* @returns The absolute paths forgotten.
|
|
21
|
+
*/
|
|
22
|
+
export declare function forgetKitModules(context: PreviewContext): string[];
|
|
23
|
+
/** What the last successful generation read from a kit, beyond the paths
|
|
24
|
+
* its preview context names. */
|
|
25
|
+
export interface GenerationInputs {
|
|
26
|
+
/** The kit modules it loaded (`loadedKitModules`). */
|
|
27
|
+
loadedModules?: readonly string[];
|
|
28
|
+
/** The theme stylesheets and assets it copied (`generatePreview`'s
|
|
29
|
+
* `themeSources`). */
|
|
30
|
+
themeSources?: readonly string[];
|
|
31
|
+
}
|
|
32
|
+
/** What the development server watches in a kit. */
|
|
33
|
+
export interface KitWatchPaths {
|
|
34
|
+
/** The files and directories whose changes regenerate the preview. */
|
|
35
|
+
regeneration: string[];
|
|
36
|
+
/** The kit configuration file, whose changes restart the server. */
|
|
37
|
+
kitConfiguration: string;
|
|
38
|
+
/** The kit's modules a `.ts` configuration imports. A change to one
|
|
39
|
+
* restarts the server too. */
|
|
40
|
+
configurationModules: string[];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The paths the development server watches in a kit: each source's templates
|
|
44
|
+
* and stories directories (so an added or deleted component is noticed),
|
|
45
|
+
* its manual components module, the shared
|
|
46
|
+
* modules templates import, every other kit module generation loaded, and
|
|
47
|
+
* the themes' stylesheets and assets. The custom views module, the shell and
|
|
48
|
+
* the setup modules are left to Vite, which serves them and reloads them
|
|
49
|
+
* itself; generation reads none of them.
|
|
50
|
+
*
|
|
51
|
+
* @param context - The kit's preview context.
|
|
52
|
+
* @param inputs - What the last successful generation read.
|
|
53
|
+
* @returns The paths, absolute.
|
|
54
|
+
*/
|
|
55
|
+
export declare function kitWatchPaths(context: PreviewContext, inputs?: GenerationInputs): KitWatchPaths;
|
|
56
|
+
/** What a change to a file means for the development server. */
|
|
57
|
+
export type KitChange = 'regenerate' | 'restart';
|
|
58
|
+
/**
|
|
59
|
+
* What a change to `path` asks of the development server: a restart for the
|
|
60
|
+
* kit configuration file and the kit modules it loads; a regeneration for a template (a TypeScript module
|
|
61
|
+
* directly in a templates directory), a story file, a theme's stylesheet or a
|
|
62
|
+
* file in its assets, or a module named in `kitWatchPaths`; nothing for any
|
|
63
|
+
* other file.
|
|
64
|
+
*
|
|
65
|
+
* @param path - The absolute path that changed, was added or was deleted.
|
|
66
|
+
* @param context - The kit's preview context.
|
|
67
|
+
* @param inputs - What the last successful generation read.
|
|
68
|
+
* @returns The change, or `undefined` when the file is none of the kit's inputs.
|
|
69
|
+
*/
|
|
70
|
+
export declare function classifyKitChange(path: string, context: PreviewContext, inputs?: GenerationInputs): KitChange | undefined;
|
|
71
|
+
/** What the kit-watching plugin is told to do beyond regenerating. */
|
|
72
|
+
export interface KitWatchOptions {
|
|
73
|
+
/** Called when the kit configuration file changes; settles once the
|
|
74
|
+
* server is replaced, or kept because the new configuration did not load. */
|
|
75
|
+
onKitConfigurationChange: () => Promise<void>;
|
|
76
|
+
/** What the generation before the server started read; later ones
|
|
77
|
+
* replace it. */
|
|
78
|
+
inputs?: GenerationInputs;
|
|
79
|
+
/** How long a burst of saves settles first. */
|
|
80
|
+
delayMilliseconds?: number;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* A Vite plugin that watches a kit's preview inputs while the development
|
|
84
|
+
* server runs and regenerates the preview when one changes. Saves arriving
|
|
85
|
+
* within the delay of each other regenerate once. A regeneration imports the
|
|
86
|
+
* kit's modules afresh, keeps Vite's cache and the scenario editor's story,
|
|
87
|
+
* and writes only the files whose content changed; Vite then reloads the
|
|
88
|
+
* pages importing them. A kit with an html pane also reloads its pages when
|
|
89
|
+
* a regeneration writes nothing, since the pane prints the templates' markup
|
|
90
|
+
* itself and a change to it writes no generated file. A kit module that fails to load is
|
|
91
|
+
* logged and the last good output stays until a later save loads.
|
|
92
|
+
*
|
|
93
|
+
* @param context - The kit's preview context.
|
|
94
|
+
* @param options - What a change to the kit configuration file does, and the delay.
|
|
95
|
+
* @returns The plugin.
|
|
96
|
+
*/
|
|
97
|
+
export declare function kitWatchPlugin(context: PreviewContext, options: KitWatchOptions): Plugin;
|
|
98
|
+
/** A running development server. */
|
|
99
|
+
export interface DevelopmentServer {
|
|
100
|
+
/** The Vite server currently serving; replaced when the kit configuration changes. */
|
|
101
|
+
readonly server: ViteDevServer;
|
|
102
|
+
/** Stops serving. */
|
|
103
|
+
close(): Promise<void>;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Generates a kit's preview and serves it, regenerating as the kit's
|
|
107
|
+
* preview inputs change and starting a new server, from the new
|
|
108
|
+
* configuration, when the kit configuration changes. A configuration that
|
|
109
|
+
* fails to load is logged and the running server kept.
|
|
110
|
+
*
|
|
111
|
+
* @param kitRoot - The kit root (where its package.json lives).
|
|
112
|
+
* @param overrides - The port and host, over the kit's configured ones.
|
|
113
|
+
* @param options - The kit configuration file, when it is not the one the
|
|
114
|
+
* kit root gives.
|
|
115
|
+
* @returns The running server.
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* const development = await startDevelopmentServer(kitRoot, { port: 6100 });
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export declare function startDevelopmentServer(kitRoot: string, overrides?: DevelopmentServerOverrides, options?: ConfigurationLookupOptions): Promise<DevelopmentServer>;
|