@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,210 @@
|
|
|
1
|
+
// Emit the React render-registry: a map of component id → a render function
|
|
2
|
+
// `(props) => <Component {...props}>...slots...</Component>`. React maps the default
|
|
3
|
+
// slot to JSX children and named slots to props (e.g. a popover's `trigger`).
|
|
4
|
+
// A story spells a component's attributes as HTML does in every target; the
|
|
5
|
+
// fills here are spelled as React takes them (lib/react-spelling.ts), and the
|
|
6
|
+
// registry exports what the React pane spells a story's live props with.
|
|
7
|
+
import { effectiveDefaultSlot, namedSlots, serialize, } from './common.js';
|
|
8
|
+
import { storyRegistryId } from '../lib/scenario-story.js';
|
|
9
|
+
import { REACT_ATTRIBUTE_NAMES } from '@js-template-engine/extension-react';
|
|
10
|
+
import { reactFill, styleProperties } from '../lib/react-spelling.js';
|
|
11
|
+
import { singleJsxRoot } from '../lib/jsx-roots.js';
|
|
12
|
+
import { collectParts } from '../lib/slot-fill.js';
|
|
13
|
+
import { isVoidElement } from '../lib/void-elements.js';
|
|
14
|
+
// A story file `style` string ('padding: 0 1ch;') → the React style object literal
|
|
15
|
+
// source. Story files author plain CSS text (the natural cross-target form - Vue and
|
|
16
|
+
// Svelte take it verbatim); only React needs the object mapping.
|
|
17
|
+
function styleObjectSource(css) {
|
|
18
|
+
const entries = Object.entries(styleProperties(css)).map(([name, value]) => `${name.startsWith('--') ? JSON.stringify(name) : name}: ${JSON.stringify(value)}`);
|
|
19
|
+
return `{ ${entries.join(', ')} }`;
|
|
20
|
+
}
|
|
21
|
+
// A JSX attribute list from `props` (named slots become slot-as-prop attributes,
|
|
22
|
+
// like reactEntry's top-level `namedProps`). For HTML tags, `class` maps to the
|
|
23
|
+
// JSX `className` spelling and a `style` string becomes the object mapping React
|
|
24
|
+
// requires.
|
|
25
|
+
function jsxAttributes(props, slots, html) {
|
|
26
|
+
const parts = [];
|
|
27
|
+
for (const [propName, value] of Object.entries(props ?? {})) {
|
|
28
|
+
const key = html && propName === 'class' ? 'className' : propName;
|
|
29
|
+
if (html && propName === 'style' && typeof value === 'string') {
|
|
30
|
+
parts.push(`style={${styleObjectSource(value)}}`);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
parts.push(typeof value === 'boolean' && value ? key : `${key}={${serialize(value)}}`);
|
|
34
|
+
}
|
|
35
|
+
for (const [slot, fill] of Object.entries(slots ?? {}))
|
|
36
|
+
parts.push(`${slot}={${slotExpression(fill)}}`);
|
|
37
|
+
return parts.length ? ' ' + parts.join(' ') : '';
|
|
38
|
+
}
|
|
39
|
+
function elementJsx(fill) {
|
|
40
|
+
const inner = fill.children ? slotJsx(fill.children) : '';
|
|
41
|
+
return `<${fill.component}${jsxAttributes(fill.props, fill.slots, false)}>${inner}</${fill.component}>`;
|
|
42
|
+
}
|
|
43
|
+
function htmlJsx(fill) {
|
|
44
|
+
// A void element (img, input, br) takes no children and no closing tag.
|
|
45
|
+
if (isVoidElement(fill.tag))
|
|
46
|
+
return `<${fill.tag}${jsxAttributes(fill.props, undefined, true)} />`;
|
|
47
|
+
const inner = fill.children ? slotJsx(fill.children) : '';
|
|
48
|
+
return `<${fill.tag}${jsxAttributes(fill.props, undefined, true)}>${inner}</${fill.tag}>`;
|
|
49
|
+
}
|
|
50
|
+
// A call to a part: the function component the story's entry declares.
|
|
51
|
+
function partJsx(fill) {
|
|
52
|
+
return `<${fill.name}${jsxAttributes(fill.props, undefined, false)} />`;
|
|
53
|
+
}
|
|
54
|
+
function slotJsx(fill) {
|
|
55
|
+
if (fill.kind === 'text')
|
|
56
|
+
return `{${JSON.stringify(fill.value)}}`;
|
|
57
|
+
if (fill.kind === 'raw')
|
|
58
|
+
return fill.react;
|
|
59
|
+
if (fill.kind === 'part')
|
|
60
|
+
return partJsx(fill);
|
|
61
|
+
// A scoped fill is only valid at a top-level named slot (reactEntry); ignored nested.
|
|
62
|
+
if (fill.kind === 'scoped')
|
|
63
|
+
return '';
|
|
64
|
+
if (fill.kind === 'fragment')
|
|
65
|
+
return fill.children.map(slotJsx).join('');
|
|
66
|
+
if (fill.kind === 'html')
|
|
67
|
+
return htmlJsx(fill);
|
|
68
|
+
return elementJsx(fill);
|
|
69
|
+
}
|
|
70
|
+
// A scoped fill's React arrow head. Vue and Svelte always destructure `parameters` off
|
|
71
|
+
// one scope object; React takes either shape, so the fill says which. The default
|
|
72
|
+
// is the single scope object a generated component's scoped slot supplies - a
|
|
73
|
+
// render prop there is always called with one object, so the same `parameters` list is
|
|
74
|
+
// correct in all three emitters. `positional` keeps the separate-parameters form
|
|
75
|
+
// for a hand-written driver prop whose React side really is positional.
|
|
76
|
+
function reactArrowHead(fill) {
|
|
77
|
+
return fill.reactScope === 'positional'
|
|
78
|
+
? `(${fill.parameters.join(', ')})`
|
|
79
|
+
: `({ ${fill.parameters.join(', ')} })`;
|
|
80
|
+
}
|
|
81
|
+
// A slot fill in *prop* position (a named slot mapped to a React prop, e.g.
|
|
82
|
+
// `description={...}`). Unlike slotJsx (children position), the value must be a bare
|
|
83
|
+
// JSX *expression* - so text is a plain string literal (not `{"..."}`, which would
|
|
84
|
+
// double-brace) and a multi-child fragment is wrapped in `<>...</>` so it stays a
|
|
85
|
+
// single expression.
|
|
86
|
+
function slotExpression(fill) {
|
|
87
|
+
if (fill.kind === 'text')
|
|
88
|
+
return JSON.stringify(fill.value);
|
|
89
|
+
// A raw body of sibling roots, or of text, is one expression in a fragment.
|
|
90
|
+
if (fill.kind === 'raw')
|
|
91
|
+
return singleJsxRoot(fill.react);
|
|
92
|
+
if (fill.kind === 'part')
|
|
93
|
+
return partJsx(fill);
|
|
94
|
+
// A scoped fill becomes a render-prop arrow (handled in reactEntry, not here).
|
|
95
|
+
if (fill.kind === 'scoped')
|
|
96
|
+
return `${reactArrowHead(fill)} => (${singleJsxRoot(fill.react)})`;
|
|
97
|
+
if (fill.kind === 'fragment')
|
|
98
|
+
return `<>${fill.children.map(slotJsx).join('')}</>`;
|
|
99
|
+
if (fill.kind === 'html')
|
|
100
|
+
return htmlJsx(fill);
|
|
101
|
+
return elementJsx(fill);
|
|
102
|
+
}
|
|
103
|
+
function defaultJsx(def) {
|
|
104
|
+
if (!def)
|
|
105
|
+
return '';
|
|
106
|
+
if (def.kind === 'propText')
|
|
107
|
+
return `{props.${def.prop}}`;
|
|
108
|
+
// Scoped content for the default slot is the function child.
|
|
109
|
+
if (def.kind === 'scoped')
|
|
110
|
+
return def.react ? `{${slotExpression(def)}}` : '';
|
|
111
|
+
return slotJsx(def);
|
|
112
|
+
}
|
|
113
|
+
function reactEntry(model, declares) {
|
|
114
|
+
const given = effectiveDefaultSlot(model);
|
|
115
|
+
const def = given?.kind === 'propText'
|
|
116
|
+
? given
|
|
117
|
+
: reactFill(given, declares, REACT_ATTRIBUTE_NAMES);
|
|
118
|
+
const named = Object.fromEntries(Object.entries(namedSlots(model)).map(([slot, fill]) => [
|
|
119
|
+
slot,
|
|
120
|
+
reactFill(fill, declares, REACT_ATTRIBUTE_NAMES),
|
|
121
|
+
]));
|
|
122
|
+
const namedProps = Object.entries(named)
|
|
123
|
+
.map(([slot, fill]) => {
|
|
124
|
+
// A scoped fill maps to a render-prop named per target (`fill.slot.react`), not
|
|
125
|
+
// the map key; an empty target body omits the prop.
|
|
126
|
+
if (fill.kind === 'scoped')
|
|
127
|
+
return fill.react
|
|
128
|
+
? ` ${fill.slot.react}={${slotExpression(fill)}}`
|
|
129
|
+
: '';
|
|
130
|
+
return ` ${slot}={${slotExpression(fill)}}`;
|
|
131
|
+
})
|
|
132
|
+
.join('');
|
|
133
|
+
const children = defaultJsx(def);
|
|
134
|
+
// The content beside the component: its siblings, in a fragment with it.
|
|
135
|
+
const before = reactFill(model.around?.before, declares, REACT_ATTRIBUTE_NAMES);
|
|
136
|
+
const after = reactFill(model.around?.after, declares, REACT_ATTRIBUTE_NAMES);
|
|
137
|
+
const beside = before !== undefined || after !== undefined;
|
|
138
|
+
const open = `${beside ? `<>${before ? slotJsx(before) : ''}` : ''}<${model.name} {...props}${namedProps}>`;
|
|
139
|
+
const close = `</${model.name}>${beside ? `${after ? slotJsx(after) : ''}</>` : ''}`;
|
|
140
|
+
const body = children ? `\n ${children}\n ` : '';
|
|
141
|
+
const key = JSON.stringify(storyRegistryId(model));
|
|
142
|
+
const parts = collectParts([
|
|
143
|
+
before,
|
|
144
|
+
model.slots?.default,
|
|
145
|
+
...Object.values(named),
|
|
146
|
+
after,
|
|
147
|
+
]);
|
|
148
|
+
if (parts.size === 0)
|
|
149
|
+
return ` ${key}: (props) => (\n ${open}${body}${close}\n ),`;
|
|
150
|
+
// The story's parts are function components declared in its entry, so two
|
|
151
|
+
// stories can each declare a part of one name.
|
|
152
|
+
const declarations = [...parts.values()]
|
|
153
|
+
.map((part) => ` function ${part.name}({ ${part.parameters.join(', ')} }: Record<string, any>) {\n` +
|
|
154
|
+
` return ${part.react ? `(${singleJsxRoot(part.react)})` : 'null'};\n` +
|
|
155
|
+
` }\n`)
|
|
156
|
+
.join('');
|
|
157
|
+
return (` ${key}: (() => {\n${declarations}` +
|
|
158
|
+
` return (props: Record<string, any>) => (\n ${open}${children ? `\n ${children}\n ` : ''}${close}\n );\n` +
|
|
159
|
+
` })(),`);
|
|
160
|
+
}
|
|
161
|
+
// Group a component into its source's module bucket (insertion-ordered, so the core
|
|
162
|
+
// source's import line comes first and other sources' lines append after it).
|
|
163
|
+
function addImport(byModule, mod, name) {
|
|
164
|
+
let set = byModule.get(mod);
|
|
165
|
+
if (!set)
|
|
166
|
+
byModule.set(mod, (set = new Set()));
|
|
167
|
+
set.add(name);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* The React render-registry module: each story's id → its render function.
|
|
171
|
+
*
|
|
172
|
+
* @param models - The stories React renders.
|
|
173
|
+
* @param moduleFor - The module a component is imported from, per target.
|
|
174
|
+
* @param exportFor - The name a component is exported under.
|
|
175
|
+
* @param declaredAttributes - The names a component declares that React
|
|
176
|
+
* would otherwise respell (`class`, `style`, an attribute React renames),
|
|
177
|
+
* which it takes as they are; every other attribute a story gives a
|
|
178
|
+
* component is spelled as React takes it.
|
|
179
|
+
* @returns The registry module's source: the `registry`, and the
|
|
180
|
+
* `reactAttributeNames` and `declaredAttributes` (of each story's root, by
|
|
181
|
+
* id) the React pane spells a story's live props with.
|
|
182
|
+
*/
|
|
183
|
+
export function emitReactRegistry(models, moduleFor, exportFor = (name) => name, declaredAttributes = () => []) {
|
|
184
|
+
const declares = (component, name) => declaredAttributes(component).includes(name);
|
|
185
|
+
const rootDeclarations = Object.fromEntries(models
|
|
186
|
+
.map((model) => [storyRegistryId(model), declaredAttributes(model.name)])
|
|
187
|
+
.filter(([, names]) => names.length > 0));
|
|
188
|
+
const byModule = new Map();
|
|
189
|
+
for (const model of models) {
|
|
190
|
+
addImport(byModule, moduleFor(model.name, 'react'), model.name);
|
|
191
|
+
for (const slotComponent of model.slotComponents)
|
|
192
|
+
addImport(byModule, moduleFor(slotComponent, 'react'), slotComponent);
|
|
193
|
+
}
|
|
194
|
+
// A component whose module export differs from its preview name is aliased on import
|
|
195
|
+
// (`Toast as NoticeToast`) so another package's clean export can't clash with a core name.
|
|
196
|
+
const importSpecifier = (name) => exportFor(name) === name ? name : `${exportFor(name)} as ${name}`;
|
|
197
|
+
const importLines = [...byModule.entries()]
|
|
198
|
+
.map(([mod, names]) => `import { ${[...names].map(importSpecifier).join(', ')} } from '${mod}';`)
|
|
199
|
+
.join('\n');
|
|
200
|
+
return (`// Generated by scaffold-ui-kit-preview - do not edit.\n` +
|
|
201
|
+
`${importLines}\n\n` +
|
|
202
|
+
`type RenderFn = (props: Record<string, any>) => any;\n\n` +
|
|
203
|
+
`export const registry: Record<string, RenderFn> = {\n` +
|
|
204
|
+
models.map((model) => reactEntry(model, declares)).join('\n') +
|
|
205
|
+
`\n};\n\n` +
|
|
206
|
+
`// How React spells the attributes it renames, by their HTML names.\n` +
|
|
207
|
+
`export const reactAttributeNames: Record<string, string> = ${JSON.stringify(REACT_ATTRIBUTE_NAMES)};\n\n` +
|
|
208
|
+
`// The names each story's root declares that React would otherwise respell.\n` +
|
|
209
|
+
`export const declaredAttributes: Record<string, string[]> = ${JSON.stringify(rootDeclarations)};\n`);
|
|
210
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { JsonValue, SlotPlan, StoryAround, Target } from '../lib/types.js';
|
|
2
|
+
/** The module-resolution data the generator serializes beside the registries
|
|
3
|
+
* (`<generatedRoot>/modules.json`), so this dev-middleware module needs no kit
|
|
4
|
+
* imports: the default module for unregistered slot children, each manual
|
|
5
|
+
* component's source module, per-target overrides, and export aliases. */
|
|
6
|
+
export interface ScratchModules {
|
|
7
|
+
defaultModule: string;
|
|
8
|
+
moduleByName: Record<string, string>;
|
|
9
|
+
importOverrideByName: Record<string, Partial<Record<Target, string>>>;
|
|
10
|
+
exportByName: Record<string, string>;
|
|
11
|
+
/** The scripted targets the kit builds; a scratch registry for any other stays
|
|
12
|
+
* empty. All three when absent. */
|
|
13
|
+
targets?: Target[];
|
|
14
|
+
/** The names each component declares that React would otherwise respell
|
|
15
|
+
* (`class`, `style`, an attribute React renames), which it takes as they
|
|
16
|
+
* are. A component missing here declares none. */
|
|
17
|
+
declaredAttributes?: Record<string, string[]>;
|
|
18
|
+
}
|
|
19
|
+
/** Reserved story id the editor renders under, in every target registry. */
|
|
20
|
+
export declare const SCRATCH_ID = "scratch";
|
|
21
|
+
/** The host posts this shape on every structural edit. */
|
|
22
|
+
export interface ScratchPayload {
|
|
23
|
+
/** The root component name (e.g. `Button`), imported per the modules.json mapping. */
|
|
24
|
+
rootComponent: string;
|
|
25
|
+
/** The root component's own scalar props (also delivered live via the props channel). */
|
|
26
|
+
props: Record<string, JsonValue>;
|
|
27
|
+
/** The editable tree: the root's default-slot fill (and any named slots). */
|
|
28
|
+
slots?: SlotPlan;
|
|
29
|
+
/** The content beside the root, carried unchanged from the story. */
|
|
30
|
+
around?: StoryAround;
|
|
31
|
+
}
|
|
32
|
+
/** Placeholder registries so the previews' static scratch imports resolve before
|
|
33
|
+
* the first edit. Written at `preview:generate` time. */
|
|
34
|
+
export declare function writeScratchStubs(generatedRoot: string): void;
|
|
35
|
+
/** Regenerate the scratch registries from an editor payload (one synthetic story
|
|
36
|
+
* through the real emitters). Returns the absolute paths written, so the caller
|
|
37
|
+
* can invalidate them in Vite's module graph before the previews reload (a plain
|
|
38
|
+
* reload can otherwise serve Vite's stale transform if the file-change event
|
|
39
|
+
* hasn't been processed yet). */
|
|
40
|
+
export declare function writeScratch(payload: ScratchPayload, generatedRoot: string): string[];
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// The scenario editor's regeneration target. The host's editable node tree is, in effect,
|
|
2
|
+
// a one-entry story: a root component with `props` and a slot plan. We build a
|
|
3
|
+
// synthetic `ResolvedStory` from the editor payload and run it through the *existing*
|
|
4
|
+
// emitters verbatim - no new per-framework codegen - writing a `scratch/` sibling
|
|
5
|
+
// of the generated registries. The preview's normal .preview-generated → Vite-HMR path
|
|
6
|
+
// then reloads the previews.
|
|
7
|
+
//
|
|
8
|
+
// Loaded by the Vite dev middleware via `ssrLoadModule` (so it runs in Node with
|
|
9
|
+
// fs + the TS emitters compiled on the fly). `writeScratchStubs` is also called at
|
|
10
|
+
// `preview:generate` time so the previews' static scratch imports always resolve.
|
|
11
|
+
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
12
|
+
import { resolve } from 'node:path';
|
|
13
|
+
import { emitReactRegistry } from './react.js';
|
|
14
|
+
import { emitVueRegistry } from './vue.js';
|
|
15
|
+
import { emitSvelteRegistry, emitSvelteWrapper } from './svelte.js';
|
|
16
|
+
import { collectSlotComponents } from '../lib/slot-fill.js';
|
|
17
|
+
import { moduleOfSource } from '../lib/module-of-source.js';
|
|
18
|
+
import { ALL_TARGETS } from '../lib/types.js';
|
|
19
|
+
// A component's per-target import module for the scratch registry, mirroring
|
|
20
|
+
// generate.ts: a per-component `importModule` override (a playground fixture
|
|
21
|
+
// outside its source's barrel) wins; otherwise the component's source module,
|
|
22
|
+
// defaulting to the kit's own source. Read from the generator's modules.json.
|
|
23
|
+
function loadResolvers(generatedRoot) {
|
|
24
|
+
const data = JSON.parse(readFileSync(resolve(generatedRoot, 'modules.json'), 'utf8'));
|
|
25
|
+
return {
|
|
26
|
+
targets: data.targets ?? ALL_TARGETS,
|
|
27
|
+
moduleFor: (name, target) => data.importOverrideByName[name]?.[target] ??
|
|
28
|
+
moduleOfSource(data.moduleByName[name] ?? data.defaultModule, target),
|
|
29
|
+
exportFor: (name) => data.exportByName[name] ?? name,
|
|
30
|
+
declaredAttributes: (name) => data.declaredAttributes?.[name] ?? [],
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/** Reserved story id the editor renders under, in every target registry. */
|
|
34
|
+
export const SCRATCH_ID = 'scratch';
|
|
35
|
+
function buildScratchModel(payload) {
|
|
36
|
+
const slotComponents = new Set();
|
|
37
|
+
collectSlotComponents(payload.slots?.default, slotComponents);
|
|
38
|
+
for (const fill of Object.values(payload.slots?.named ?? {})) {
|
|
39
|
+
collectSlotComponents(fill, slotComponents);
|
|
40
|
+
}
|
|
41
|
+
collectSlotComponents(payload.around?.before, slotComponents);
|
|
42
|
+
collectSlotComponents(payload.around?.after, slotComponents);
|
|
43
|
+
slotComponents.delete(payload.rootComponent);
|
|
44
|
+
return {
|
|
45
|
+
name: payload.rootComponent,
|
|
46
|
+
title: SCRATCH_ID,
|
|
47
|
+
omit: false,
|
|
48
|
+
standalone: true,
|
|
49
|
+
unlisted: false,
|
|
50
|
+
propTypes: [],
|
|
51
|
+
defaultProps: payload.props ?? {},
|
|
52
|
+
slots: payload.slots,
|
|
53
|
+
...(payload.around ? { around: payload.around } : {}),
|
|
54
|
+
scenarios: [],
|
|
55
|
+
slotComponents: [...slotComponents],
|
|
56
|
+
// The scratch story is rendered, never introspected for add-targets.
|
|
57
|
+
contentSlots: { default: false, named: [] },
|
|
58
|
+
// Unused by the scratch emitters (they emit the single model unconditionally), but
|
|
59
|
+
// the model shape requires it; the editor composes across all targets.
|
|
60
|
+
targets: ALL_TARGETS,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const EMPTY_REGISTRY = 'export const registry: Record<string, any> = {};\n';
|
|
64
|
+
// The React page reads the names each story's root declares beside its
|
|
65
|
+
// registry, so React's placeholder exports them too, none.
|
|
66
|
+
const EMPTY_REACT_REGISTRY = EMPTY_REGISTRY +
|
|
67
|
+
'export const declaredAttributes: Record<string, string[]> = {};\n';
|
|
68
|
+
function scratchDirectory(generatedRoot) {
|
|
69
|
+
const directory = resolve(generatedRoot, 'scratch');
|
|
70
|
+
mkdirSync(directory, { recursive: true });
|
|
71
|
+
return directory;
|
|
72
|
+
}
|
|
73
|
+
/** Placeholder registries so the previews' static scratch imports resolve before
|
|
74
|
+
* the first edit. Written at `preview:generate` time. */
|
|
75
|
+
export function writeScratchStubs(generatedRoot) {
|
|
76
|
+
const directory = scratchDirectory(generatedRoot);
|
|
77
|
+
writeFileSync(resolve(directory, 'react.tsx'), EMPTY_REACT_REGISTRY);
|
|
78
|
+
writeFileSync(resolve(directory, 'vue.ts'), EMPTY_REGISTRY);
|
|
79
|
+
writeFileSync(resolve(directory, 'registry.ts'), EMPTY_REGISTRY);
|
|
80
|
+
}
|
|
81
|
+
/** Regenerate the scratch registries from an editor payload (one synthetic story
|
|
82
|
+
* through the real emitters). Returns the absolute paths written, so the caller
|
|
83
|
+
* can invalidate them in Vite's module graph before the previews reload (a plain
|
|
84
|
+
* reload can otherwise serve Vite's stale transform if the file-change event
|
|
85
|
+
* hasn't been processed yet). */
|
|
86
|
+
export function writeScratch(payload, generatedRoot) {
|
|
87
|
+
const model = buildScratchModel(payload);
|
|
88
|
+
const directory = scratchDirectory(generatedRoot);
|
|
89
|
+
const { moduleFor, exportFor, targets, declaredAttributes } = loadResolvers(generatedRoot);
|
|
90
|
+
// A target the kit does not build keeps its empty registry: its
|
|
91
|
+
// components have no module to import.
|
|
92
|
+
const files = [
|
|
93
|
+
[
|
|
94
|
+
resolve(directory, 'react.tsx'),
|
|
95
|
+
targets.includes('react')
|
|
96
|
+
? emitReactRegistry([model], moduleFor, exportFor, declaredAttributes)
|
|
97
|
+
: EMPTY_REACT_REGISTRY,
|
|
98
|
+
],
|
|
99
|
+
[
|
|
100
|
+
resolve(directory, 'vue.ts'),
|
|
101
|
+
targets.includes('vue')
|
|
102
|
+
? emitVueRegistry([model], moduleFor, exportFor)
|
|
103
|
+
: EMPTY_REGISTRY,
|
|
104
|
+
],
|
|
105
|
+
];
|
|
106
|
+
if (targets.includes('svelte')) {
|
|
107
|
+
const wrapper = emitSvelteWrapper(model, moduleFor, exportFor);
|
|
108
|
+
files.push([resolve(directory, 'registry.ts'), emitSvelteRegistry([model])], [resolve(directory, wrapper.fileName), wrapper.source]);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
files.push([resolve(directory, 'registry.ts'), EMPTY_REGISTRY]);
|
|
112
|
+
}
|
|
113
|
+
for (const [path, source] of files)
|
|
114
|
+
writeFileSync(path, source);
|
|
115
|
+
return files.map(([path]) => path);
|
|
116
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { JsonValue, SlotFill, StoryAround, Target } from '../lib/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* A two-way prop the story gives, which the printed source binds to state of
|
|
4
|
+
* its own so the component's changes come back: React holds it in `useState`
|
|
5
|
+
* and passes the setter as `changeProp`, Vue binds it with `v-model` (bare
|
|
6
|
+
* with `vueModel`) or `v-model:<prop>`, and Svelte with `bind:<prop>`.
|
|
7
|
+
*/
|
|
8
|
+
export interface SourceBinding {
|
|
9
|
+
/** The two-way prop. */
|
|
10
|
+
prop: string;
|
|
11
|
+
/** The event prop called with each new value. Without one, React prints
|
|
12
|
+
* the prop's value alone, as it has no way to hear a change. */
|
|
13
|
+
changeProp?: string;
|
|
14
|
+
/** The prop the component's own value starts from when the two-way prop
|
|
15
|
+
* is not given, which the source leaves out while it gives the prop. */
|
|
16
|
+
defaultProp?: string;
|
|
17
|
+
/** Whether a Vue consumer binds the prop with a bare `v-model`. */
|
|
18
|
+
vueModel?: boolean;
|
|
19
|
+
/** The prop's type as the component declares it, which types the state
|
|
20
|
+
* where the value alone would read narrower. */
|
|
21
|
+
declaredType?: string;
|
|
22
|
+
/** Whether the component takes type parameters, so its prop's type is
|
|
23
|
+
* the consumer's to infer rather than to name. */
|
|
24
|
+
generic?: boolean;
|
|
25
|
+
}
|
|
26
|
+
/** A story resolved for printing: its root component, props and slot content. */
|
|
27
|
+
export interface SourceStory {
|
|
28
|
+
/** The root component's local name (its export name). */
|
|
29
|
+
component: string;
|
|
30
|
+
/** The props to print, already merged and filtered. */
|
|
31
|
+
props: Record<string, JsonValue>;
|
|
32
|
+
/** Default-slot content. */
|
|
33
|
+
children?: SlotFill;
|
|
34
|
+
/** Named-slot content, keyed by slot name. */
|
|
35
|
+
named: Record<string, SlotFill>;
|
|
36
|
+
/** The content beside the component, printed as its siblings: React holds
|
|
37
|
+
* them in a fragment, Vue's template and Svelte's markup list them. */
|
|
38
|
+
around?: StoryAround;
|
|
39
|
+
/** Import lines' modules per local component name, and the names the
|
|
40
|
+
* component declares that React would otherwise respell
|
|
41
|
+
* (`declaredAttributes`: `class`, `style`, an attribute React renames),
|
|
42
|
+
* which React takes as they are. */
|
|
43
|
+
imports: Map<string, {
|
|
44
|
+
module: string;
|
|
45
|
+
exported: string;
|
|
46
|
+
declaredAttributes?: string[];
|
|
47
|
+
}>;
|
|
48
|
+
/** The root component's two-way props, those given in `props` bound to
|
|
49
|
+
* state of the source's own. */
|
|
50
|
+
bindings?: SourceBinding[];
|
|
51
|
+
/** The mode the kit builds its Svelte target in, which the state a bound
|
|
52
|
+
* prop is held in follows: `$state` in runes mode, a plain `let` in
|
|
53
|
+
* legacy mode (the default). */
|
|
54
|
+
svelteMode?: 'legacy' | 'runes';
|
|
55
|
+
/** How React spells the HTML attributes it renames (`tabindex` as
|
|
56
|
+
* `tabIndex`), by their HTML names. A story spells a component's
|
|
57
|
+
* attributes as HTML does; React's source takes `class` as `className`,
|
|
58
|
+
* a `style` string as a style object and these by their React names,
|
|
59
|
+
* unless the component declares a prop by that name. Without it, only
|
|
60
|
+
* `class` and `style` are respelled. */
|
|
61
|
+
reactAttributeNames?: Readonly<Record<string, string>>;
|
|
62
|
+
/** The type names the kit's package entries export, each with the module
|
|
63
|
+
* it is imported from for this target: a bound prop's state is typed by
|
|
64
|
+
* its declared type where it names these and the language's own types
|
|
65
|
+
* alone, importing them. */
|
|
66
|
+
exportedTypes?: ReadonlyMap<string, string>;
|
|
67
|
+
}
|
|
68
|
+
/** The story as a React component module, the attributes it gives a
|
|
69
|
+
* component spelled as React takes them (see `reactAttributeNames`). */
|
|
70
|
+
export declare function reactSource(given: SourceStory): string;
|
|
71
|
+
/** The story as a Vue single-file component. */
|
|
72
|
+
export declare function vueSource(given: SourceStory): string;
|
|
73
|
+
/** The story as a Svelte component. */
|
|
74
|
+
export declare function svelteSource(given: SourceStory): string;
|
|
75
|
+
/**
|
|
76
|
+
* A story's props in the order the component declares them, so the source
|
|
77
|
+
* prints them alike however they were gathered (the template's defaults, the
|
|
78
|
+
* story file's, a scenario's); a prop the component does not declare follows,
|
|
79
|
+
* in the order given.
|
|
80
|
+
*
|
|
81
|
+
* @param props - The props to print.
|
|
82
|
+
* @param declared - The component's prop names, in declaration order.
|
|
83
|
+
* @returns The same props, reordered.
|
|
84
|
+
*/
|
|
85
|
+
export declare function inDeclarationOrder(props: Record<string, JsonValue>, declared: readonly string[]): Record<string, JsonValue>;
|
|
86
|
+
/** The printer per target. */
|
|
87
|
+
export declare const SOURCE_PRINTERS: Record<Target, (story: SourceStory) => string>;
|