@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,741 @@
|
|
|
1
|
+
import type { Template, TemplateNode } from '@js-template-engine/types';
|
|
2
|
+
import type { PreviewCanvasConfiguration, PreviewMountNode, PreviewOption, PreviewViewCanvasConfiguration } from '../options.js';
|
|
3
|
+
export type JsonValue = string | number | boolean | null | undefined | JsonValue[] | {
|
|
4
|
+
[key: string]: JsonValue;
|
|
5
|
+
};
|
|
6
|
+
/** A scripted target the preview can render a component into. A component declares the
|
|
7
|
+
* subset it supports (`targets`); most support all three, but one bound to a
|
|
8
|
+
* single-framework library (a React-only toast package, say) supports fewer - the
|
|
9
|
+
* generator emits only those registries and the host shows only those panes. */
|
|
10
|
+
export type Target = 'react' | 'vue' | 'svelte';
|
|
11
|
+
/** The default: a component renders in every target unless it narrows the set. */
|
|
12
|
+
export declare const ALL_TARGETS: Target[];
|
|
13
|
+
/** A control derived from one component prop. */
|
|
14
|
+
export interface PropTypeSpecification {
|
|
15
|
+
name: string;
|
|
16
|
+
control: 'text' | 'boolean' | 'number' | 'select' | 'color-select';
|
|
17
|
+
/** For `select`: its values, each a string or a boolean, and `undefined`
|
|
18
|
+
* for the unset choice. `color-select` draws its options from the shared
|
|
19
|
+
* token list. */
|
|
20
|
+
options?: (string | boolean | undefined)[];
|
|
21
|
+
/** For `number`. */
|
|
22
|
+
number?: {
|
|
23
|
+
min?: number;
|
|
24
|
+
max?: number;
|
|
25
|
+
step?: number;
|
|
26
|
+
};
|
|
27
|
+
/** false → omit from the controls table (driver-internal / complex props). */
|
|
28
|
+
include: boolean;
|
|
29
|
+
/** The prop's description from its template, in markdown, shown on its control. */
|
|
30
|
+
description?: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* What a component declares about one prop, as its template (or, for a
|
|
34
|
+
* component written by hand, its props type) writes it.
|
|
35
|
+
*/
|
|
36
|
+
export interface PropDeclaration {
|
|
37
|
+
/** The prop's type as written, such as `"'solid' | 'ghost'"` or `'boolean'`. */
|
|
38
|
+
declaredType: string;
|
|
39
|
+
/** Whether the component requires the prop. */
|
|
40
|
+
required: boolean;
|
|
41
|
+
/** The component's own default for the prop, absent when it declares none.
|
|
42
|
+
* A story's `defaultProps` start from it, then add the kit's hints and the
|
|
43
|
+
* story file's `defaultProps`, so the two can differ. */
|
|
44
|
+
declaredDefault?: JsonValue;
|
|
45
|
+
/** A default the component applies without declaring it, as the code a
|
|
46
|
+
* consumer reads (`"'start'"`), for showing beside the control. Absent
|
|
47
|
+
* when the component documents none. */
|
|
48
|
+
documentedDefault?: string;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* One prop of a component: the control the preview derives for it and what
|
|
52
|
+
* the component declares about it.
|
|
53
|
+
*
|
|
54
|
+
* - `name`, `control`, `options` (a select's values), `number` (a number
|
|
55
|
+
* input's range), `include` (`false` for a prop shown no control) and
|
|
56
|
+
* `description` (markdown) describe the control.
|
|
57
|
+
* - `declaredType` is the prop's type as the component writes it, `required`
|
|
58
|
+
* whether the component requires it, `declaredDefault` the component's
|
|
59
|
+
* own default, absent when it declares none, and `documentedDefault` a
|
|
60
|
+
* default it applies without declaring, as the code a consumer reads.
|
|
61
|
+
*
|
|
62
|
+
* `declaredDefault` is the component's default as a consumer gets it. The
|
|
63
|
+
* story's starting value is in its `defaultProps`, which adds the kit's hints
|
|
64
|
+
* and the story file's `defaultProps` over it.
|
|
65
|
+
*/
|
|
66
|
+
export type PreviewPropType = PropTypeSpecification & PropDeclaration;
|
|
67
|
+
/**
|
|
68
|
+
* A two-way prop a component declares (a prop whose `bindable` is an
|
|
69
|
+
* object): the component keeps its own value while the prop is not given,
|
|
70
|
+
* and calls `changeProp` with each new value. A story that gives `prop` is
|
|
71
|
+
* controlled: when a pane reports `changeProp`, the controller takes the
|
|
72
|
+
* value as the story's new `prop`.
|
|
73
|
+
*/
|
|
74
|
+
export interface PreviewBinding {
|
|
75
|
+
/** The two-way prop. */
|
|
76
|
+
prop: string;
|
|
77
|
+
/** The prop the component's own value starts from, if any. */
|
|
78
|
+
defaultProp?: string;
|
|
79
|
+
/** The event prop called with each new value, if any. A story that gives
|
|
80
|
+
* `prop` takes the value it reports as its new `prop`. */
|
|
81
|
+
changeProp?: string;
|
|
82
|
+
/** Whether a Vue consumer binds the prop with a bare `v-model` (the
|
|
83
|
+
* template's `extensions.vue.model`), beside `v-model:<prop>`. */
|
|
84
|
+
vueModel?: boolean;
|
|
85
|
+
/** Whether the component takes type parameters (its template's
|
|
86
|
+
* `typeParameters`), so a consumer's state for the prop infers its type
|
|
87
|
+
* from the value rather than naming it. */
|
|
88
|
+
generic?: boolean;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* How to fill a slot when rendering a demo. A recursive node tree - a slot fill
|
|
92
|
+
* *is*, in effect, an anonymous template subtree whose leaves are real
|
|
93
|
+
* components. Single-source; the emitters translate it to each target's markup.
|
|
94
|
+
* Field names are a deliberate subset of `@js-template-engine/types`
|
|
95
|
+
* `TemplateNode` (`slots`, `children`, `tag`).
|
|
96
|
+
*
|
|
97
|
+
* - `element` carries a component's `props`, its default-slot `children`, **and**
|
|
98
|
+
* its **named** `slots` (e.g. an `IconLabel` with its `icon` slot filled).
|
|
99
|
+
* - `html` is a plain DOM tag (`<section>`/`<div>` wrappers) - props + children,
|
|
100
|
+
* no named slots.
|
|
101
|
+
*/
|
|
102
|
+
export type SlotFill = {
|
|
103
|
+
kind: 'text';
|
|
104
|
+
value: string;
|
|
105
|
+
} | {
|
|
106
|
+
kind: 'element';
|
|
107
|
+
component: string;
|
|
108
|
+
props?: Record<string, JsonValue>;
|
|
109
|
+
slots?: Record<string, SlotFill>;
|
|
110
|
+
children?: SlotFill;
|
|
111
|
+
} | {
|
|
112
|
+
kind: 'html';
|
|
113
|
+
tag: string;
|
|
114
|
+
props?: Record<string, JsonValue>;
|
|
115
|
+
children?: SlotFill;
|
|
116
|
+
} | {
|
|
117
|
+
kind: 'fragment';
|
|
118
|
+
children: SlotFill[];
|
|
119
|
+
} | {
|
|
120
|
+
kind: 'raw';
|
|
121
|
+
react: string;
|
|
122
|
+
vue: string;
|
|
123
|
+
svelte: string;
|
|
124
|
+
/** What it renders to, for the story's html source: markup, or template
|
|
125
|
+
* nodes, which render as the kit's templates do - a kit component
|
|
126
|
+
* among them included. Without it, the story has no html source. */
|
|
127
|
+
html?: string | TemplateNode[];
|
|
128
|
+
/** Kit components the raw strings reference, so the generated registry imports
|
|
129
|
+
* them (a raw string is opaque - unlike `element`, its imports can't be walked).
|
|
130
|
+
* e.g. a `renderCell` raw that returns `<TextInput/>` declares `['TextInput']`. */
|
|
131
|
+
imports?: string[];
|
|
132
|
+
} | {
|
|
133
|
+
/**
|
|
134
|
+
* A **scoped** slot fill - content the *parent* parameterizes with runtime
|
|
135
|
+
* values (a row, an index, a setter), the cross-framework generalization of a
|
|
136
|
+
* React render-prop. Only valid at a top-level named-slot position (it needs the
|
|
137
|
+
* host component to supply the scope), never nested inside another fill.
|
|
138
|
+
*
|
|
139
|
+
* Its target name differs per framework because the same scoped slot is a render-prop
|
|
140
|
+
* in React but a scoped slot / snippet in Vue/Svelte (e.g. a table's
|
|
141
|
+
* `renderCell` prop is a `#cell` slot in Vue and a `cell` snippet in Svelte). The
|
|
142
|
+
* emitters translate one fill into: React `name={({ parameters }) => (body)}` (prop),
|
|
143
|
+
* Vue `<template #name="{ parameters }">body</template>`, Svelte
|
|
144
|
+
* `{#snippet name({ parameters })} body{/snippet}` - one `parameters` list, spelled the
|
|
145
|
+
* same way in every target unless `reactScope` says the React side is
|
|
146
|
+
* positional.
|
|
147
|
+
*/
|
|
148
|
+
kind: 'scoped';
|
|
149
|
+
/** The slot's identifier per target: the React render-prop name, the Vue scoped-slot
|
|
150
|
+
* name, the Svelte snippet name (they differ - see above). */
|
|
151
|
+
slot: {
|
|
152
|
+
react: string;
|
|
153
|
+
vue: string;
|
|
154
|
+
svelte: string;
|
|
155
|
+
};
|
|
156
|
+
/** The scope parameter names the host passes, destructured in each target
|
|
157
|
+
* (e.g. `['column', 'row', 'index', 'setField']`). */
|
|
158
|
+
parameters: string[];
|
|
159
|
+
/**
|
|
160
|
+
* How the React side receives the scope. Vue and Svelte always destructure
|
|
161
|
+
* `parameters` off one scope object; React can do either, and the two shapes are
|
|
162
|
+
* indistinguishable in the generated source - both compile, and the wrong one
|
|
163
|
+
* binds the whole scope to the first name.
|
|
164
|
+
*
|
|
165
|
+
* - `'object'` (the default) - React destructures one scope object,
|
|
166
|
+
* `name={({ a, b }) => body}`. This is what a generated component's scoped
|
|
167
|
+
* slot supplies: its render prop is always called with a single object, so
|
|
168
|
+
* one `parameters` list stays correct across all three emitters.
|
|
169
|
+
* - `'positional'` - React takes the names as separate parameters,
|
|
170
|
+
* `name={(a, b) => body}`. For a hand-written component whose React prop really
|
|
171
|
+
* is positional (a table's `renderCell(column, row, index, setField)`),
|
|
172
|
+
* where its Vue and Svelte counterparts are still one destructured object.
|
|
173
|
+
*/
|
|
174
|
+
reactScope?: 'object' | 'positional';
|
|
175
|
+
/** Per-target body referencing `parameters`. React is a JSX expression, or
|
|
176
|
+
* JSX content (sibling roots, text), which it returns in a fragment; Vue
|
|
177
|
+
* and Svelte are markup fragments. An empty string omits that target's
|
|
178
|
+
* slot. */
|
|
179
|
+
react: string;
|
|
180
|
+
vue: string;
|
|
181
|
+
svelte: string;
|
|
182
|
+
/** What the body renders to at rest, for the story's html source:
|
|
183
|
+
* markup, or template nodes, which also read the values the slot
|
|
184
|
+
* exposes under `parameters` (one the slot cannot give reads every
|
|
185
|
+
* property as `undefined`). Without it, the story has no html source. */
|
|
186
|
+
html?: string | TemplateNode[];
|
|
187
|
+
/** Components the bodies reference, imported into the generated registry (opaque
|
|
188
|
+
* strings can't be walked - as `raw`). */
|
|
189
|
+
imports?: string[];
|
|
190
|
+
} | {
|
|
191
|
+
/**
|
|
192
|
+
* A call to a **part**: content the story declares once, by name, outside
|
|
193
|
+
* its markup, and calls here with `props`. Its body may call the part
|
|
194
|
+
* again, so content shaped like its data - a tree, lists nested in each
|
|
195
|
+
* other's items - renders to any depth, ending where the data does.
|
|
196
|
+
*
|
|
197
|
+
* Each target declares the part as it would by hand: React a function
|
|
198
|
+
* component, Vue a component (a single-file component of its own in the
|
|
199
|
+
* story's source), Svelte a snippet at the top of the markup. A call is
|
|
200
|
+
* `<Name ... />` in React and Vue and `{@render Name({ ... })}` in Svelte,
|
|
201
|
+
* spelled the same way inside a body, where the props are expressions.
|
|
202
|
+
* The declaration rides on every call; two calls of one name must carry
|
|
203
|
+
* the same one.
|
|
204
|
+
*/
|
|
205
|
+
kind: 'part';
|
|
206
|
+
/** The part's name: a component's name in React and Vue, the snippet's in Svelte. */
|
|
207
|
+
name: string;
|
|
208
|
+
/** The props the part takes, read by name in its bodies. */
|
|
209
|
+
parameters: string[];
|
|
210
|
+
/** A TypeScript type per parameter, for the story's printed source: React's
|
|
211
|
+
* props and Svelte's snippet take them, a parameter without one is `any`,
|
|
212
|
+
* and Vue's `defineProps` is typed once any is given. A type a kit names
|
|
213
|
+
* (`Folder[]`) is the reader's to declare or import. */
|
|
214
|
+
parameterTypes?: Record<string, string>;
|
|
215
|
+
/** The props this call passes. */
|
|
216
|
+
props?: Record<string, JsonValue>;
|
|
217
|
+
/** The body per target, reading `parameters`. React is a JSX expression,
|
|
218
|
+
* or JSX content (sibling roots, text), which it returns in a fragment;
|
|
219
|
+
* Vue and Svelte are markup fragments. */
|
|
220
|
+
react: string;
|
|
221
|
+
vue: string;
|
|
222
|
+
svelte: string;
|
|
223
|
+
/** What the body renders to, for the story's html source: template
|
|
224
|
+
* nodes reading `parameters`, a call to the part among them rendering
|
|
225
|
+
* it again. Without it, the story has no html source. */
|
|
226
|
+
html?: TemplateNode[];
|
|
227
|
+
/** Kit components the bodies reference, imported where the part is declared. */
|
|
228
|
+
imports?: string[];
|
|
229
|
+
};
|
|
230
|
+
/** A call to a part (see the `part` slot fill). */
|
|
231
|
+
export type PartFill = Extract<SlotFill, {
|
|
232
|
+
kind: 'part';
|
|
233
|
+
}>;
|
|
234
|
+
export interface SlotPlan {
|
|
235
|
+
default?: SlotFill;
|
|
236
|
+
named?: Record<string, SlotFill>;
|
|
237
|
+
}
|
|
238
|
+
/** Content a story renders beside its component: any slot fill but a
|
|
239
|
+
* `scoped` one, which needs a slot to give it values. */
|
|
240
|
+
export type AroundFill = Exclude<SlotFill, {
|
|
241
|
+
kind: 'scoped';
|
|
242
|
+
}>;
|
|
243
|
+
/** What a story renders beside its component, as its siblings: `before` it
|
|
244
|
+
* and `after` it, such as a hint element whose id the component's
|
|
245
|
+
* `aria-describedby` names. */
|
|
246
|
+
export interface StoryAround {
|
|
247
|
+
before?: AroundFill;
|
|
248
|
+
after?: AroundFill;
|
|
249
|
+
}
|
|
250
|
+
export interface Scenario {
|
|
251
|
+
id: string;
|
|
252
|
+
/** Display label in the scenario picker. Defaults to `id` when omitted. */
|
|
253
|
+
label?: string;
|
|
254
|
+
/** What the scenario shows and why it is worth a look, for a shell to show
|
|
255
|
+
* beside it. Markdown allowed. */
|
|
256
|
+
description?: string;
|
|
257
|
+
props?: Record<string, JsonValue>;
|
|
258
|
+
/** Slot content of the scenario's own, in the shape of the story's
|
|
259
|
+
* `slots`: a slot it fills takes the scenario's fill in place of the
|
|
260
|
+
* story's, and every other slot keeps the story's. For a scenario whose
|
|
261
|
+
* point is what the component holds, such as a message's text per
|
|
262
|
+
* severity. */
|
|
263
|
+
slots?: SlotPlan;
|
|
264
|
+
/** Values for the kit's preview options, keyed by option id, that picking
|
|
265
|
+
* the scenario sets: the setting it shows the component in, such as
|
|
266
|
+
* `{ mode: 'dark', surface: '3' }`. A global option keeps its value after
|
|
267
|
+
* another scenario is picked, as if it were set by hand; a story option
|
|
268
|
+
* keeps it until another story is selected. */
|
|
269
|
+
options?: Record<string, string | boolean>;
|
|
270
|
+
/** Mark the baseline configuration: shown as "<label> (default)" and selected
|
|
271
|
+
* initially, instead of the anonymous "(default)". At most one per component. */
|
|
272
|
+
default?: boolean;
|
|
273
|
+
/** Generated from one enum value or boolean (see Story.generate), not curated.
|
|
274
|
+
* Set by the generator; listed after the curated scenarios. */
|
|
275
|
+
generated?: boolean;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* A component's story file (`<Name>.story.ts` in its source's stories
|
|
279
|
+
* directory, default-exported): what its story shows - props, controls, slot
|
|
280
|
+
* content, scenarios, options - and whether it has one. Absent, the story is
|
|
281
|
+
* the component's defaults. The single home for per-component curation, never
|
|
282
|
+
* per target.
|
|
283
|
+
*/
|
|
284
|
+
export interface Story {
|
|
285
|
+
omit?: boolean;
|
|
286
|
+
/**
|
|
287
|
+
* Whether the component has a story of its own. Default `true`. A
|
|
288
|
+
* component set `false` (a compound's subcomponent such as `TabList`,
|
|
289
|
+
* `Tab` or `TabPanel`, meaningful only nested inside its parent, or a
|
|
290
|
+
* shared building block) is left out of the story navigation but stays in
|
|
291
|
+
* the manifest for the editor's component picker, so its node, props and
|
|
292
|
+
* slots can be authored in a parent's content tree. Unlike `omit`, which
|
|
293
|
+
* drops it from the manifest entirely. A component its compound's root
|
|
294
|
+
* lists in `parts` (in the root's template, or in the kit configuration's
|
|
295
|
+
* `parts` for a root with no template) is `standalone: false` without the
|
|
296
|
+
* flag; `check` warns of the flag on a component no root lists, unless the
|
|
297
|
+
* component is no one compound's part: two or more templates render it, a
|
|
298
|
+
* story of its source labeled with its name stands in for it, or it lists
|
|
299
|
+
* parts of its own. A manual spec's `standalone` is not checked; its story
|
|
300
|
+
* file's is.
|
|
301
|
+
*/
|
|
302
|
+
standalone?: boolean;
|
|
303
|
+
/**
|
|
304
|
+
* An *unlisted* story: generated, rendered in every target and reachable
|
|
305
|
+
* at its address (`?component=<id>`) and through the testing helpers, as
|
|
306
|
+
* any story is, but left out of what a reader browses - the navigation,
|
|
307
|
+
* the editor's component picker, the component count, and the catalog a
|
|
308
|
+
* custom view reads. For a story that exists for a kit's own tests, such as
|
|
309
|
+
* a fixture a browser test drives. The catalog keeps it, flagged
|
|
310
|
+
* `unlisted`. A component that is `omit` or `standalone: false` has no
|
|
311
|
+
* story to leave unlisted, so `check` reports `unlisted` beside either as
|
|
312
|
+
* an error.
|
|
313
|
+
*/
|
|
314
|
+
unlisted?: boolean;
|
|
315
|
+
category?: string;
|
|
316
|
+
/** The name shown in the navigation, when it should differ from the component's
|
|
317
|
+
* (import) name - e.g. a playground fixture of another package whose export must stay unique
|
|
318
|
+
* in the shared registry (`ToastExample`) but reads better as `Toast`. Display only;
|
|
319
|
+
* the import identifier and editor root stay the component's real `name`.
|
|
320
|
+
* A story labeled with the name of a component in its source that is
|
|
321
|
+
* `standalone: false` is that component's story. */
|
|
322
|
+
label?: string;
|
|
323
|
+
defaultProps?: Record<string, JsonValue>;
|
|
324
|
+
/** Control tweaks per prop (a number range, a select's options). `false` excludes
|
|
325
|
+
* the prop: no control, no generated scenario, no coverage warning. */
|
|
326
|
+
controls?: Record<string, Partial<PropTypeSpecification> | false>;
|
|
327
|
+
/** Props always passed with this value and never shown as controls. A scenario
|
|
328
|
+
* may not set one. */
|
|
329
|
+
fixed?: Record<string, JsonValue>;
|
|
330
|
+
/** Scenario generation: by default one scenario per enum value other than the
|
|
331
|
+
* default and one per boolean flipped from its default, for every select and
|
|
332
|
+
* boolean control. `false` turns it off; a list of prop names narrows it to
|
|
333
|
+
* those props; `{ exclude }` generates every prop but those. A curated
|
|
334
|
+
* scenario setting exactly one such value stands in for its generated one, and
|
|
335
|
+
* a curated scenario taking a generated id (`<prop>-<value>`, or the prop for
|
|
336
|
+
* a boolean) replaces it, so it should set that value. */
|
|
337
|
+
generate?: false | string[] | {
|
|
338
|
+
exclude: string[];
|
|
339
|
+
};
|
|
340
|
+
slots?: SlotPlan;
|
|
341
|
+
/** Content rendered beside the component, as its siblings, in every pane
|
|
342
|
+
* and the story's code: `before` it and `after` it. Shared by the
|
|
343
|
+
* scenarios, as `slots` is. */
|
|
344
|
+
around?: StoryAround;
|
|
345
|
+
scenarios?: Scenario[];
|
|
346
|
+
/** Per-story defaults for story-scoped preview options (the kit's
|
|
347
|
+
* `options`, such as a box or padding around the component), keyed by option id. A value seeds that option's starting value
|
|
348
|
+
* for this component; `false` marks the option *unavailable* here (no control
|
|
349
|
+
* shown, and held at its option default) - e.g. a full-page template is edge-to-edge
|
|
350
|
+
* so `{ box: false, padded: false }`. Options omitted here use their config default. */
|
|
351
|
+
options?: Record<string, JsonValue | false>;
|
|
352
|
+
}
|
|
353
|
+
/** What content a component accepts - its default slot and any named slots.
|
|
354
|
+
* Surfaced to the host so the editor can offer the right add-targets. */
|
|
355
|
+
export interface ContentSlots {
|
|
356
|
+
/** Whether the component exposes an unnamed (default) slot. */
|
|
357
|
+
default: boolean;
|
|
358
|
+
/** Named slot names the component exposes (e.g. `icon`, `navigation`). */
|
|
359
|
+
named: string[];
|
|
360
|
+
/** The slots among them whose content must take their scope, the default
|
|
361
|
+
* slot as `default`: they hold content like any other, but take only a
|
|
362
|
+
* scoped fill, so the editor offers no plain content for them. */
|
|
363
|
+
scopeRequired?: string[];
|
|
364
|
+
}
|
|
365
|
+
/** The framework-agnostic intermediate an emitter consumes. */
|
|
366
|
+
export interface ResolvedStory {
|
|
367
|
+
name: string;
|
|
368
|
+
title: string;
|
|
369
|
+
/** What the component is: its template's `description`, or its manual
|
|
370
|
+
* spec's. Markdown allowed. */
|
|
371
|
+
description?: string;
|
|
372
|
+
omit: boolean;
|
|
373
|
+
/** Whether the component has a story of its own. One that is not stays in
|
|
374
|
+
* the manifest for the editor, hidden from the story navigation and the
|
|
375
|
+
* per-target registries (see Story.standalone). */
|
|
376
|
+
standalone: boolean;
|
|
377
|
+
/** A story left out of the navigation, the editor's picker and the counts,
|
|
378
|
+
* still generated and reachable at its address (see Story.unlisted).
|
|
379
|
+
* Never set on one that is `omit` or not `standalone`. */
|
|
380
|
+
unlisted: boolean;
|
|
381
|
+
propTypes: PreviewPropType[];
|
|
382
|
+
/** The props that are events: functions returning nothing, which the
|
|
383
|
+
* component calls as things happen. */
|
|
384
|
+
events?: string[];
|
|
385
|
+
/** The component's two-way props. */
|
|
386
|
+
bindings?: PreviewBinding[];
|
|
387
|
+
defaultProps: Record<string, JsonValue>;
|
|
388
|
+
/** The values in `defaultProps` that neither the component declares nor its
|
|
389
|
+
* story file sets: the preview's own starting values, from the kit's control
|
|
390
|
+
* hints. A consumer's source leaves them out. */
|
|
391
|
+
previewDefaults?: Record<string, JsonValue>;
|
|
392
|
+
slots?: SlotPlan;
|
|
393
|
+
/** The content rendered beside the component (see Story.around). */
|
|
394
|
+
around?: StoryAround;
|
|
395
|
+
scenarios: Scenario[];
|
|
396
|
+
/** Extra component names referenced by slot fills and the content beside
|
|
397
|
+
* the component, to import in the story. */
|
|
398
|
+
slotComponents: string[];
|
|
399
|
+
/** The slots the component accepts (for the editor's add-content targets). */
|
|
400
|
+
contentSlots: ContentSlots;
|
|
401
|
+
/** Per-story preview-option defaults / availability (see Story.options). */
|
|
402
|
+
options?: Record<string, JsonValue | false>;
|
|
403
|
+
/** The id of the preview source this story belongs to - groups it under its
|
|
404
|
+
* navigation section. Assigned by the generator; defaults to 'core'. */
|
|
405
|
+
source?: string;
|
|
406
|
+
/** The targets this story renders into (default all three). A React-only
|
|
407
|
+
* fixture narrows this to `['react']`, so the generator emits only the
|
|
408
|
+
* React registry and the host shows only the React pane. */
|
|
409
|
+
targets: Target[];
|
|
410
|
+
/** Set on the story of one scenario with slot content of its own, which
|
|
411
|
+
* the generator renders beside the component's story: the id the panes
|
|
412
|
+
* mount it by and the name its render unit takes, in place of the ones
|
|
413
|
+
* derived from the title and the component's name. */
|
|
414
|
+
scenarioStory?: {
|
|
415
|
+
id: string;
|
|
416
|
+
renderName: string;
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
/** One enumerated component: a globbed template, or a resolved manual spec. */
|
|
420
|
+
export interface EnumeratedComponent {
|
|
421
|
+
name: string;
|
|
422
|
+
file: string;
|
|
423
|
+
/** The template a globbed component was read from; a manual spec has none. */
|
|
424
|
+
template?: Template;
|
|
425
|
+
/** What the component is: the template's `description`, or, for a manual
|
|
426
|
+
* spec, written beside it. Markdown allowed. */
|
|
427
|
+
description?: string;
|
|
428
|
+
props: Record<string, {
|
|
429
|
+
type: string;
|
|
430
|
+
/** `type` with the named types it uses expanded through the template's
|
|
431
|
+
* imports, when that differs: what the prop's control is read from,
|
|
432
|
+
* while `type` stays as written. */
|
|
433
|
+
resolvedType?: string;
|
|
434
|
+
default?: JsonValue;
|
|
435
|
+
documentedDefault?: string;
|
|
436
|
+
required?: boolean;
|
|
437
|
+
description?: string;
|
|
438
|
+
}>;
|
|
439
|
+
hasDefaultSlot: boolean;
|
|
440
|
+
/** Whether the default slot exposes values to its content (a scoped slot):
|
|
441
|
+
* the preview then seeds no placeholder text into it, so its fallback
|
|
442
|
+
* renders. */
|
|
443
|
+
defaultSlotScoped?: boolean;
|
|
444
|
+
/** Named slots the component declares (`{ type: 'slot', name }`). */
|
|
445
|
+
slotNames: string[];
|
|
446
|
+
/** The slots whose content must take their scope (a template slot's
|
|
447
|
+
* `scopeRequired`), by name, the default slot as `default`: a story fills
|
|
448
|
+
* them only with a `scoped` fill, React's render function, and the editor
|
|
449
|
+
* offers them no plain content. */
|
|
450
|
+
scopeRequiredSlots?: string[];
|
|
451
|
+
/** Whether the component's root forwards native attributes (a template's
|
|
452
|
+
* `passthrough` element): the check then accepts HTML attribute names too. */
|
|
453
|
+
passthrough?: boolean;
|
|
454
|
+
/** Where the component gathers a consumer's leftover attributes (a
|
|
455
|
+
* template's `rest`), and the tag they are typed as: the check then
|
|
456
|
+
* accepts HTML attribute names too, as for `passthrough`. */
|
|
457
|
+
rest?: {
|
|
458
|
+
tag: string;
|
|
459
|
+
};
|
|
460
|
+
/** Whether the component has a story of its own (a manual spec's). Default
|
|
461
|
+
* `true`; `false` makes it editor-only. See Story.standalone. */
|
|
462
|
+
standalone?: boolean;
|
|
463
|
+
/** A story reachable at its address but left out of the navigation, the
|
|
464
|
+
* editor's picker and the counts (a manual spec's). See Story.unlisted. */
|
|
465
|
+
unlisted?: boolean;
|
|
466
|
+
/** The targets this component renders into (default all three - `ALL_TARGETS`).
|
|
467
|
+
* A manual spec bound to a React-only library sets `['react']`. */
|
|
468
|
+
targets?: Target[];
|
|
469
|
+
/** Override the module each target imports this component from, when it is NOT the
|
|
470
|
+
* source's module for the target - e.g. a preview-internal playground fixture that
|
|
471
|
+
* lives beside another package's code rather than in its published barrel. Keyed by
|
|
472
|
+
* target; a target absent from the map falls back to the source default. */
|
|
473
|
+
importModule?: Partial<Record<Target, string>>;
|
|
474
|
+
/** The identifier the module actually **exports**, when it differs from `name` (the
|
|
475
|
+
* unique preview identity used for addressing + as the local binding). Another
|
|
476
|
+
* package's components export clean, unprefixed names that collide with the kit's - a toast package exporting
|
|
477
|
+
* `Toast`, a forms package its own `TextInput` - so the preview names the
|
|
478
|
+
* component uniquely (`NoticeToast`) and the generator imports `{ Toast as NoticeToast }`.
|
|
479
|
+
* Defaults to `name` (no alias). */
|
|
480
|
+
exportName?: string;
|
|
481
|
+
/** Members read from a manual spec's `propsFrom` interface whose type is not a
|
|
482
|
+
* control (a function, an object, a type from another file): the check lists
|
|
483
|
+
* them, so the hiding is visible. */
|
|
484
|
+
hiddenProps?: string[];
|
|
485
|
+
/** Every member name read from `propsFrom` - in React a named or scoped slot is
|
|
486
|
+
* a prop, so the check accepts these as named-slot keys. */
|
|
487
|
+
memberNames?: string[];
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* A manual (non-template) component spec, as a source's `manualModule` returns it:
|
|
491
|
+
* an EnumeratedComponent whose props are either written by hand (a preview-only
|
|
492
|
+
* fixture) or read from code. `propsFrom` names the React driver's props
|
|
493
|
+
* interface as `'<file relative to the kit root>#<InterfaceName>'`; its own
|
|
494
|
+
* members (not what it extends) become the props, and a `children` member marks
|
|
495
|
+
* the default slot. Give `props` or `propsFrom`, not both.
|
|
496
|
+
*/
|
|
497
|
+
export interface ManualComponentSpecification extends Omit<EnumeratedComponent, 'props' | 'hasDefaultSlot' | 'slotNames'> {
|
|
498
|
+
props?: EnumeratedComponent['props'];
|
|
499
|
+
propsFrom?: string;
|
|
500
|
+
/** Defaults to whether `propsFrom` declares a non-function `children`, else false. */
|
|
501
|
+
hasDefaultSlot?: boolean;
|
|
502
|
+
/** Whether the default slot exposes values to its content (a scoped slot).
|
|
503
|
+
* Defaults to whether `propsFrom` takes it from a template component
|
|
504
|
+
* whose default slot does, else false. */
|
|
505
|
+
defaultSlotScoped?: boolean;
|
|
506
|
+
/** Defaults to none. */
|
|
507
|
+
slotNames?: string[];
|
|
508
|
+
}
|
|
509
|
+
/** Imports a kit-authored TypeScript module by absolute path (jiti under the
|
|
510
|
+
* built CLI - kit files are TS source the CLI must compile on the fly). */
|
|
511
|
+
export type ModuleImporter = (absolutePath: string) => Promise<unknown>;
|
|
512
|
+
/**
|
|
513
|
+
* What a hand-written component renders as in a story's html source:
|
|
514
|
+
* `'content'`, a template's name, or `{ template, slots }`, where `slots`
|
|
515
|
+
* names the template slot each of the component's slots fills when they
|
|
516
|
+
* differ (`{ default: 'inner' }`; `default` is the default slot).
|
|
517
|
+
*/
|
|
518
|
+
export type HandWrittenMapping = string | {
|
|
519
|
+
template: string;
|
|
520
|
+
slots?: Record<string, string>;
|
|
521
|
+
};
|
|
522
|
+
/** One preview source: a package whose components + story files the generator
|
|
523
|
+
* renders under its own navigation section. Fundamentally a source is *where its
|
|
524
|
+
* components import from* (`moduleBase` → `${moduleBase}/${target}`, or the
|
|
525
|
+
* base with `{target}` replaced when it names one) plus a
|
|
526
|
+
* navigation identity. The kit's own components are a source like any other -
|
|
527
|
+
* the first source (lowest `order`) is the default module for slot children
|
|
528
|
+
* that belong to no registered source. */
|
|
529
|
+
export interface PreviewSourceConfiguration {
|
|
530
|
+
/** Stable id - groups this source's stories in the manifest + navigation. */
|
|
531
|
+
id: string;
|
|
532
|
+
/** Navigation heading. */
|
|
533
|
+
label: string;
|
|
534
|
+
/** Navigation order - the kit's own source first, other packages after. */
|
|
535
|
+
order: number;
|
|
536
|
+
/** Where the emitters import this source's components from: `${moduleBase}/${target}`,
|
|
537
|
+
* or, when it contains `{target}`, the base with the target in its place
|
|
538
|
+
* (`'@acme/{target}'` imports `'@acme/react'`). */
|
|
539
|
+
moduleBase: string;
|
|
540
|
+
/** The directory of component templates to read, relative to the kit
|
|
541
|
+
* root (omit for a source of manual specs alone). */
|
|
542
|
+
templatesDirectory?: string;
|
|
543
|
+
/** Module (relative to the kit root) whose default/named export supplies the
|
|
544
|
+
* source's manual (non-template) component specs: `() => EnumeratedComponent[]`. */
|
|
545
|
+
manualModule?: string;
|
|
546
|
+
/** This source's stories directory, relative to the kit root. */
|
|
547
|
+
storiesDirectory?: string;
|
|
548
|
+
}
|
|
549
|
+
/** A shipped theme: the compiled stylesheet (and optional asset dir - e.g.
|
|
550
|
+
* self-hosted fonts referenced by relative `url()`) are file paths relative to
|
|
551
|
+
* the kit root; the generator copies them into the served tree, so the map is
|
|
552
|
+
* pure config (no bundler import constraints). */
|
|
553
|
+
export interface PreviewThemeConfiguration {
|
|
554
|
+
id: string;
|
|
555
|
+
label: string;
|
|
556
|
+
/** The compiled stylesheet path (relative to the kit root). */
|
|
557
|
+
css: string;
|
|
558
|
+
/** Optional asset directory copied beside the stylesheet (fonts). */
|
|
559
|
+
assets?: string;
|
|
560
|
+
}
|
|
561
|
+
/** The kit's control hints - the token-config hook feeding prop controls,
|
|
562
|
+
* the preview block's `controlHints`, read in Node only, so its hook may be
|
|
563
|
+
* a function in `scaffold-ui-kit.ts`. Everything is optional (a kit without
|
|
564
|
+
* color tokens gets no color-select controls, and its color props are treated
|
|
565
|
+
* by their declared types). */
|
|
566
|
+
export interface PreviewControlHints {
|
|
567
|
+
/** The kit's color tokens. When it holds any, a string-typed prop whose
|
|
568
|
+
* name ends in `color`, in any case (`color`, `borderColor`), gets a
|
|
569
|
+
* select of these tokens (the
|
|
570
|
+
* color-select control) in place of the control its type gives. `null`
|
|
571
|
+
* (or `undefined`) is the select's unset choice. */
|
|
572
|
+
colorTokens?: (string | null | undefined)[];
|
|
573
|
+
/** Component-scoped size default in rem (e.g. Badge → 0.75), or undefined. */
|
|
574
|
+
componentSizeRem?: (componentName: string) => number | undefined;
|
|
575
|
+
}
|
|
576
|
+
/** The host's own copy, so it can follow the kit's casing: the preview
|
|
577
|
+
* block's `labels`, read in Node only, so `generatedScenario` may be a
|
|
578
|
+
* function in `scaffold-ui-kit.ts`. Each label falls back to its default. */
|
|
579
|
+
export interface PreviewLabels {
|
|
580
|
+
/** The category a component without a story file `category` sits in. Default `Components`. */
|
|
581
|
+
category?: string;
|
|
582
|
+
/** The synthetic scenario that renders a component with no content. Default `Empty`. */
|
|
583
|
+
emptyScenario?: string;
|
|
584
|
+
/** The label of a generated scenario, from the prop and the value it sets.
|
|
585
|
+
* Default `prop: value`, or the bare prop for a boolean turned on. */
|
|
586
|
+
generatedScenario?: (prop: string, value: string | boolean) => string;
|
|
587
|
+
}
|
|
588
|
+
/** Where the preview remembers what a person chose. `'url'` keeps the
|
|
589
|
+
* selection, the scenario and the option values in the page's query
|
|
590
|
+
* parameters, so a link opens the preview as it was; `'url-and-local-storage'`
|
|
591
|
+
* also remembers the global option values in the browser, per kit name,
|
|
592
|
+
* across sessions - a value in the URL winning over a remembered one. */
|
|
593
|
+
export type PreviewPersistence = 'url' | 'url-and-local-storage';
|
|
594
|
+
/** A width the preview offers to lay a story's panes out at, so a component
|
|
595
|
+
* that responds to its width can be seen on a small screen or a large one. */
|
|
596
|
+
export interface PreviewPaneWidth {
|
|
597
|
+
/** What a reader picks it by, such as `small`. */
|
|
598
|
+
label: string;
|
|
599
|
+
/** The width in CSS pixels: a whole number greater than zero. */
|
|
600
|
+
width: number;
|
|
601
|
+
}
|
|
602
|
+
/** The entry the preview opens on when its address names none: a custom
|
|
603
|
+
* view by its id, or a component's story by its id, on one of its
|
|
604
|
+
* scenarios or its baseline. The ids are the ones the preview's address
|
|
605
|
+
* carries (`view=`, `component=`, `scenario=`). */
|
|
606
|
+
export type PreviewLandingConfiguration = {
|
|
607
|
+
view: string;
|
|
608
|
+
} | {
|
|
609
|
+
component: string;
|
|
610
|
+
scenario?: string;
|
|
611
|
+
};
|
|
612
|
+
/**
|
|
613
|
+
* The keys of the preview block the preview's pages read: data, which the
|
|
614
|
+
* preview checks can be sent as JSON and serves to the browser.
|
|
615
|
+
*/
|
|
616
|
+
export interface PreviewBrowserConfiguration {
|
|
617
|
+
/** The kit's options, such as a color mode, and how each reaches a story. */
|
|
618
|
+
options: PreviewOption[];
|
|
619
|
+
/** The name prefix, page background and extra CSS each frame paints with. */
|
|
620
|
+
canvas: PreviewCanvasConfiguration;
|
|
621
|
+
/** The kit's theme stylesheets; the first is the default. */
|
|
622
|
+
themes: PreviewThemeConfiguration[];
|
|
623
|
+
/** The wrapper tree rendered around each story's mount; omitted, the mount
|
|
624
|
+
* is a direct child of `<body>`. */
|
|
625
|
+
mount?: PreviewMountNode;
|
|
626
|
+
/** The canvas of a custom view's frame. */
|
|
627
|
+
viewCanvas?: PreviewViewCanvasConfiguration;
|
|
628
|
+
}
|
|
629
|
+
/** The keys of the preview block its pages read, which must be JSON. */
|
|
630
|
+
export declare const PREVIEW_BROWSER_KEYS: readonly ["options", "canvas", "themes", "mount", "viewCanvas"];
|
|
631
|
+
/** The kit's shell with its page named: the long form of `preview.shell`. */
|
|
632
|
+
export interface PreviewShellSetting {
|
|
633
|
+
/** The shell module: a package specifier, or a module path relative to
|
|
634
|
+
* the kit root, whose default export is a shell. */
|
|
635
|
+
module: string;
|
|
636
|
+
/** The shell's page module, which supplies the host page's static start:
|
|
637
|
+
* a package specifier, or a module path relative to the kit root, whose
|
|
638
|
+
* default export is a shell page. Left out, a shell named as a package
|
|
639
|
+
* specifier uses the module at that specifier followed by `/page`, when
|
|
640
|
+
* the package has one. */
|
|
641
|
+
page?: string;
|
|
642
|
+
}
|
|
643
|
+
/** The `preview` block of the kit configuration (`scaffold-ui-kit.ts` or
|
|
644
|
+
* `scaffold-ui-kit.json`): plain data, plus module paths for the parts that
|
|
645
|
+
* are code. The keys the preview's pages read are served to the browser as
|
|
646
|
+
* JSON; `controlHints` and `labels` stay in Node, so in `scaffold-ui-kit.ts`
|
|
647
|
+
* their hooks may be functions. The build never reads this block; the
|
|
648
|
+
* preview owns and validates it. */
|
|
649
|
+
export interface PreviewConfiguration {
|
|
650
|
+
sources: PreviewSourceConfiguration[];
|
|
651
|
+
/** The kit's options (see {@link PreviewBrowserConfiguration}). */
|
|
652
|
+
options?: PreviewOption[];
|
|
653
|
+
/** How each frame paints: a name prefix for the names the preview sets,
|
|
654
|
+
* and optionally a page background and extra CSS. Omitted, the name
|
|
655
|
+
* prefix is the kit's name, its characters other than letters, digits,
|
|
656
|
+
* `-` and `_` made `-`, and the frames paint nothing of their own. */
|
|
657
|
+
canvas?: PreviewCanvasConfiguration;
|
|
658
|
+
/** The kit's compiled theme stylesheets; the first is the default. */
|
|
659
|
+
themes?: PreviewThemeConfiguration[];
|
|
660
|
+
/** The wrapper tree rendered around each story's mount. */
|
|
661
|
+
mount?: PreviewMountNode;
|
|
662
|
+
/** The canvas of a custom view's frame; without it a view gets
|
|
663
|
+
* `canvas.pageBackground` and nothing else. */
|
|
664
|
+
viewCanvas?: PreviewViewCanvasConfiguration;
|
|
665
|
+
/** The widths a shell offers to lay a story's panes out at, in place of
|
|
666
|
+
* the preview's own (`small` 375, `medium` 768 and `large` 1280), so a
|
|
667
|
+
* kit can derive them from its own breakpoints. An empty list offers
|
|
668
|
+
* none. */
|
|
669
|
+
paneWidths?: PreviewPaneWidth[];
|
|
670
|
+
/** The hints feeding prop controls, read in Node only. */
|
|
671
|
+
controlHints?: PreviewControlHints;
|
|
672
|
+
/** The host's own copy, read in Node only. */
|
|
673
|
+
labels?: PreviewLabels;
|
|
674
|
+
/** The shell that renders the preview's interface around the iframes: a
|
|
675
|
+
* package specifier, or a module path relative to the kit root, whose
|
|
676
|
+
* default export is a shell; or the shell's module with its page module
|
|
677
|
+
* named beside it. Required; `@scaffold-ui-kit/preview/shells/charcell`
|
|
678
|
+
* is the one shipped with the preview. */
|
|
679
|
+
shell: string | PreviewShellSetting;
|
|
680
|
+
/** Kit-authored module exporting the custom-view registry. */
|
|
681
|
+
viewsModule?: string;
|
|
682
|
+
/** Preview-only import aliases (playground fixtures outside published barrels). */
|
|
683
|
+
aliases?: Record<string, string>;
|
|
684
|
+
/** Per-target setup modules (side effects only): ambient providers a story
|
|
685
|
+
* assumes mounted (a toast container), another package's stylesheets. Each is
|
|
686
|
+
* imported once by that target's preview iframe. */
|
|
687
|
+
setupModules?: Partial<Record<Target, string>>;
|
|
688
|
+
/** Stylesheets (relative to the kit root) the html pane loads beside the
|
|
689
|
+
* theme's: what a framework's setup module brings in as CSS, such as a
|
|
690
|
+
* preflight or another package's sheet, since the html pane runs no script. */
|
|
691
|
+
htmlStylesheets?: string[];
|
|
692
|
+
/** The kit's own code block for the code view: a module (relative to the
|
|
693
|
+
* kit root) whose default export is a `CodeBlockMount`, and the framework
|
|
694
|
+
* it mounts with, whose setup module loads first (`dom`, the default,
|
|
695
|
+
* loads none). The preview mounts it in an iframe per code pane, in place
|
|
696
|
+
* of the shell's own. */
|
|
697
|
+
codeBlock?: {
|
|
698
|
+
module: string;
|
|
699
|
+
framework?: 'react' | 'vue' | 'svelte' | 'dom';
|
|
700
|
+
};
|
|
701
|
+
/** Extra SCSS load paths (relative to the kit root) for per-component SCSS. */
|
|
702
|
+
scssLoadPaths?: string[];
|
|
703
|
+
/** Package names Vite must not esbuild-prebundle (raw `.svelte` shippers etc.). */
|
|
704
|
+
optimizeDepsExclude?: string[];
|
|
705
|
+
/** Packages the preview loads one copy of, resolved from the kit root
|
|
706
|
+
* wherever they are imported, beside the framework runtimes it always
|
|
707
|
+
* loads once: a package the shell and the kit's components both import,
|
|
708
|
+
* whose instances must be shared (a library with a plugin registry or
|
|
709
|
+
* module-level state). Each must resolve from the kit root. */
|
|
710
|
+
dedupe?: string[];
|
|
711
|
+
/** A regular expression (as a string) matched against each component's name:
|
|
712
|
+
* a match gets no story, the way a story file's `omit` does - for a kit whose
|
|
713
|
+
* naming marks a compound's parts, such as `"(Driver|Visual)$"`. Unset, no
|
|
714
|
+
* component is left out by name. */
|
|
715
|
+
omitPattern?: string;
|
|
716
|
+
/** What each component written by hand renders as in a story's html
|
|
717
|
+
* source: `'content'` for one that renders only the content passed into it
|
|
718
|
+
* (a driver adding behavior to markup it is given), or the template it
|
|
719
|
+
* renders, which then takes its props and content. Either way one comment
|
|
720
|
+
* around it says its behavior is not included. A component with no
|
|
721
|
+
* template that is not listed leaves the story with no html source. */
|
|
722
|
+
handWrittenComponents?: Record<string, HandWrittenMapping>;
|
|
723
|
+
/** Dev-server port (default 6100; `dev --port` overrides it). If it is taken, the server takes the next free one. */
|
|
724
|
+
port?: number;
|
|
725
|
+
/** The addresses the dev server listens on: an address such as
|
|
726
|
+
* `'0.0.0.0'`, or `true` for every address, so another device on the
|
|
727
|
+
* network can open the preview. Default: this machine only;
|
|
728
|
+
* `dev --host` overrides it. */
|
|
729
|
+
host?: string | boolean;
|
|
730
|
+
/** Where the preview remembers what a person chose. Default `'url'`. */
|
|
731
|
+
persistence?: PreviewPersistence;
|
|
732
|
+
/** The entry the preview opens on when its address names no view or
|
|
733
|
+
* story, such as a foundations view: `{ view }` or
|
|
734
|
+
* `{ component, scenario? }`. Unset, it opens on the first listed story. */
|
|
735
|
+
landing?: PreviewLandingConfiguration;
|
|
736
|
+
}
|
|
737
|
+
declare module 'scaffold-ui-kit' {
|
|
738
|
+
/** The preview's settings in the kit configuration, typed by this package. */
|
|
739
|
+
interface KitPreviewConfiguration extends PreviewConfiguration {
|
|
740
|
+
}
|
|
741
|
+
}
|