@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,367 @@
|
|
|
1
|
+
// The catalog a preview controller is created with: everything static about
|
|
2
|
+
// the kit being previewed, in the shape a shell reads (a navigation tree, short
|
|
3
|
+
// titles, the Empty scenario in place). The preview's bootstrap builds it from
|
|
4
|
+
// the generated manifest with `catalogFromManifest`; another producer can build
|
|
5
|
+
// one by hand. Browser-safe: no node imports, type-only imports.
|
|
6
|
+
import { EMPTY_SCENARIO_ID } from '../lib/naming.js';
|
|
7
|
+
import { PREVIEW_SCRIPTED_TARGETS, PREVIEW_TARGETS, } from '../protocol.js';
|
|
8
|
+
import { DEFAULT_SLOT, HTML_TAGS, isContainer, } from './editor-tree.js';
|
|
9
|
+
/** The widths a shell offers to lay the story panes out at when the kit
|
|
10
|
+
* names none: a small screen's, a medium one's and a large one's. */
|
|
11
|
+
export const DEFAULT_PANE_WIDTHS = [
|
|
12
|
+
{ label: 'small', width: 375 },
|
|
13
|
+
{ label: 'medium', width: 768 },
|
|
14
|
+
{ label: 'large', width: 1280 },
|
|
15
|
+
];
|
|
16
|
+
const DEFAULT_SOURCES = [
|
|
17
|
+
{ id: 'core', label: 'Components', order: 0 },
|
|
18
|
+
];
|
|
19
|
+
/**
|
|
20
|
+
* Build a catalog from the generated manifest and the kit's registered views.
|
|
21
|
+
*
|
|
22
|
+
* Components that accept slot content get the Empty scenario ahead of their
|
|
23
|
+
* own, labeled as the manifest says. Each component's `shortTitle` drops its
|
|
24
|
+
* source's label prefix. The navigation lists each source's views and its
|
|
25
|
+
* component tree interleaved by `order`; a source whose views set no
|
|
26
|
+
* component tree lists its components under `Components`, first among the
|
|
27
|
+
* entries of order 0. Components that are not standalone and unlisted stories stay in
|
|
28
|
+
* `components` but out of the navigation. The kit's targets are the manifest's,
|
|
29
|
+
* the three targets when it names none, with `html` only where it names
|
|
30
|
+
* it, and each component's targets are narrowed to the targets among them.
|
|
31
|
+
* The pane widths are the manifest's, narrowest first, or
|
|
32
|
+
* `DEFAULT_PANE_WIDTHS` when it names none, the Svelte mode the
|
|
33
|
+
* manifest's, `legacy` when it names none, and the landing entry the
|
|
34
|
+
* manifest's.
|
|
35
|
+
*
|
|
36
|
+
* @param manifest - The generated manifest.
|
|
37
|
+
* @param views - The kit's registered views (rendered views and component-tree markers).
|
|
38
|
+
* @returns The catalog.
|
|
39
|
+
*/
|
|
40
|
+
export function catalogFromManifest(manifest, views = []) {
|
|
41
|
+
const sources = (manifest.sources?.length ? manifest.sources : DEFAULT_SOURCES)
|
|
42
|
+
.slice()
|
|
43
|
+
.sort((a, b) => a.order - b.order);
|
|
44
|
+
const rootSourceId = sources[0].id;
|
|
45
|
+
const targets = PREVIEW_TARGETS.filter((target) => manifest.targets?.includes(target) ?? target !== 'html');
|
|
46
|
+
const emptyScenario = {
|
|
47
|
+
id: EMPTY_SCENARIO_ID,
|
|
48
|
+
label: manifest.labels?.emptyScenario ?? 'Empty',
|
|
49
|
+
props: {},
|
|
50
|
+
empty: true,
|
|
51
|
+
};
|
|
52
|
+
const components = manifest.components.map((component) => {
|
|
53
|
+
const source = component.source ?? rootSourceId;
|
|
54
|
+
const hasContent = component.slots.default || component.slots.named.length > 0;
|
|
55
|
+
return {
|
|
56
|
+
id: component.id,
|
|
57
|
+
name: component.name,
|
|
58
|
+
...(component.description !== undefined
|
|
59
|
+
? { description: component.description }
|
|
60
|
+
: {}),
|
|
61
|
+
title: component.title,
|
|
62
|
+
shortTitle: stripSourcePrefix(component.title, sources.find((candidate) => candidate.id === source)),
|
|
63
|
+
source,
|
|
64
|
+
standalone: component.standalone !== false,
|
|
65
|
+
unlisted: component.unlisted === true,
|
|
66
|
+
propTypes: component.propTypes,
|
|
67
|
+
events: component.events ?? [],
|
|
68
|
+
bindings: component.bindings ?? [],
|
|
69
|
+
defaultProps: component.defaultProps,
|
|
70
|
+
previewDefaults: component.previewDefaults ?? {},
|
|
71
|
+
scenarios: hasContent
|
|
72
|
+
? [emptyScenario, ...component.scenarios]
|
|
73
|
+
: [...component.scenarios],
|
|
74
|
+
slots: component.slots,
|
|
75
|
+
...(component.content ? { content: component.content } : {}),
|
|
76
|
+
...(component.around ? { around: component.around } : {}),
|
|
77
|
+
...(component.options
|
|
78
|
+
? {
|
|
79
|
+
options: component.options,
|
|
80
|
+
}
|
|
81
|
+
: {}),
|
|
82
|
+
targets: (component.targets ?? PREVIEW_SCRIPTED_TARGETS).filter((target) => targets.includes(target)),
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
const catalogViews = views
|
|
86
|
+
.filter((view) => !view.componentTree)
|
|
87
|
+
.map((view) => ({
|
|
88
|
+
id: view.id,
|
|
89
|
+
label: view.label,
|
|
90
|
+
source: view.source ?? rootSourceId,
|
|
91
|
+
order: view.order ?? 0,
|
|
92
|
+
framework: view.framework ?? 'dom',
|
|
93
|
+
}))
|
|
94
|
+
.sort((a, b) => a.order - b.order);
|
|
95
|
+
return {
|
|
96
|
+
kitName: manifest.kitName ?? 'kit',
|
|
97
|
+
...(manifest.kitVersion ? { kitVersion: manifest.kitVersion } : {}),
|
|
98
|
+
targets,
|
|
99
|
+
sources,
|
|
100
|
+
components,
|
|
101
|
+
views: catalogViews,
|
|
102
|
+
...(manifest.codeBlock ? { codeBlock: manifest.codeBlock } : {}),
|
|
103
|
+
navigation: buildNavigation(sources, components, views),
|
|
104
|
+
htmlTags: [...HTML_TAGS],
|
|
105
|
+
colorTokens: (manifest.colorOptions ?? []).map((token) => token ?? null),
|
|
106
|
+
paneWidths: (manifest.paneWidths ?? DEFAULT_PANE_WIDTHS)
|
|
107
|
+
.map((paneWidth) => ({ ...paneWidth }))
|
|
108
|
+
.sort((a, b) => a.width - b.width),
|
|
109
|
+
...(manifest.landing
|
|
110
|
+
? {
|
|
111
|
+
landing: 'view' in manifest.landing
|
|
112
|
+
? { kind: 'view', id: manifest.landing.view }
|
|
113
|
+
: {
|
|
114
|
+
kind: 'component',
|
|
115
|
+
id: manifest.landing.component,
|
|
116
|
+
...(manifest.landing.scenario !== undefined
|
|
117
|
+
? { scenario: manifest.landing.scenario }
|
|
118
|
+
: {}),
|
|
119
|
+
},
|
|
120
|
+
}
|
|
121
|
+
: {}),
|
|
122
|
+
imports: manifest.imports ?? {},
|
|
123
|
+
svelteMode: manifest.svelteMode ?? 'legacy',
|
|
124
|
+
reactAttributeNames: manifest.reactAttributeNames ?? {},
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
function stripSourcePrefix(title, source) {
|
|
128
|
+
const prefix = source ? `${source.label}/` : '';
|
|
129
|
+
return prefix && title.startsWith(prefix)
|
|
130
|
+
? title.slice(prefix.length)
|
|
131
|
+
: title;
|
|
132
|
+
}
|
|
133
|
+
/** A source's stories as a category tree: titles (minus the source's label)
|
|
134
|
+
* split on `/` into folders and leaves, folders first, each level alphabetical. */
|
|
135
|
+
function buildTitleTree(components, rootLabel) {
|
|
136
|
+
const root = { label: rootLabel, children: [] };
|
|
137
|
+
const prefix = `${rootLabel}/`;
|
|
138
|
+
for (const component of components) {
|
|
139
|
+
const rest = component.title.startsWith(prefix)
|
|
140
|
+
? component.title.slice(prefix.length)
|
|
141
|
+
: component.title;
|
|
142
|
+
const segments = rest.split('/');
|
|
143
|
+
let node = root;
|
|
144
|
+
segments.forEach((segment, index) => {
|
|
145
|
+
let child = node.children.find((candidate) => candidate.label === segment);
|
|
146
|
+
if (!child) {
|
|
147
|
+
child = { label: segment, children: [] };
|
|
148
|
+
node.children.push(child);
|
|
149
|
+
}
|
|
150
|
+
if (index === segments.length - 1)
|
|
151
|
+
child.component = component;
|
|
152
|
+
node = child;
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
const sort = (treeNode) => {
|
|
156
|
+
treeNode.children.sort((a, b) => {
|
|
157
|
+
const aFolder = a.children.length > 0;
|
|
158
|
+
const bFolder = b.children.length > 0;
|
|
159
|
+
if (aFolder !== bFolder)
|
|
160
|
+
return aFolder ? -1 : 1;
|
|
161
|
+
return a.label.localeCompare(b.label);
|
|
162
|
+
});
|
|
163
|
+
treeNode.children.forEach(sort);
|
|
164
|
+
};
|
|
165
|
+
sort(root);
|
|
166
|
+
return root;
|
|
167
|
+
}
|
|
168
|
+
function titleTreeToNavigation(node, parentKey) {
|
|
169
|
+
const key = `${parentKey}/${node.label}`;
|
|
170
|
+
if (node.children.length > 0) {
|
|
171
|
+
return {
|
|
172
|
+
kind: 'group',
|
|
173
|
+
key,
|
|
174
|
+
label: node.label,
|
|
175
|
+
children: node.children.map((child) => titleTreeToNavigation(child, key)),
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
const component = node.component;
|
|
179
|
+
return {
|
|
180
|
+
kind: 'component',
|
|
181
|
+
id: component.id,
|
|
182
|
+
label: node.label,
|
|
183
|
+
title: component.title,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/** A source's component tree as one group, or `null` when it has no stories. */
|
|
187
|
+
function componentsEntry(source, components, entryLabel) {
|
|
188
|
+
const stories = components.filter((component) => component.standalone &&
|
|
189
|
+
!component.unlisted &&
|
|
190
|
+
component.source === source.id);
|
|
191
|
+
if (stories.length === 0)
|
|
192
|
+
return null;
|
|
193
|
+
const root = buildTitleTree(stories, source.label);
|
|
194
|
+
const key = `components:${source.id}`;
|
|
195
|
+
return {
|
|
196
|
+
kind: 'group',
|
|
197
|
+
key,
|
|
198
|
+
label: entryLabel,
|
|
199
|
+
children: root.children.map((child) => titleTreeToNavigation(child, key)),
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
/** The label of a source's component tree where no view sets one. */
|
|
203
|
+
const COMPONENT_TREE_LABEL = 'Components';
|
|
204
|
+
/** A source's entries: its views and its component tree, by `order`. A source
|
|
205
|
+
* with stories whose views set no component tree gets one, labeled
|
|
206
|
+
* `Components`, first among the entries of its order. */
|
|
207
|
+
function sourceEntries(source, rootSourceId, components, views) {
|
|
208
|
+
const scoped = views.filter((view) => (view.source ?? rootSourceId) === source.id);
|
|
209
|
+
const entries = scoped.map((view) => ({
|
|
210
|
+
order: view.order ?? 0,
|
|
211
|
+
entry: view.componentTree
|
|
212
|
+
? componentsEntry(source, components, view.label)
|
|
213
|
+
: {
|
|
214
|
+
kind: 'view',
|
|
215
|
+
id: view.id,
|
|
216
|
+
label: view.label,
|
|
217
|
+
},
|
|
218
|
+
}));
|
|
219
|
+
if (!scoped.some((view) => view.componentTree))
|
|
220
|
+
entries.unshift({
|
|
221
|
+
order: 0,
|
|
222
|
+
entry: componentsEntry(source, components, COMPONENT_TREE_LABEL),
|
|
223
|
+
});
|
|
224
|
+
// A stable sort: the default tree stays ahead of the views of its order.
|
|
225
|
+
return entries
|
|
226
|
+
.sort((a, b) => a.order - b.order)
|
|
227
|
+
.map(({ entry }) => entry)
|
|
228
|
+
.filter((entry) => entry !== null);
|
|
229
|
+
}
|
|
230
|
+
function buildNavigation(sources, components, views) {
|
|
231
|
+
const rootSourceId = sources[0].id;
|
|
232
|
+
const nodes = [];
|
|
233
|
+
for (const source of sources) {
|
|
234
|
+
const entries = sourceEntries(source, rootSourceId, components, views);
|
|
235
|
+
if (source.id === rootSourceId)
|
|
236
|
+
nodes.push(...entries);
|
|
237
|
+
else if (entries.length > 0)
|
|
238
|
+
nodes.push({
|
|
239
|
+
kind: 'group',
|
|
240
|
+
key: `source:${source.id}`,
|
|
241
|
+
label: source.label,
|
|
242
|
+
children: entries,
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
return nodes;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* The scenario picker's choices for a component: its baseline first, labeled
|
|
249
|
+
* as the default, then the rest. The Empty scenario renders through a
|
|
250
|
+
* regeneration, so it is left out where the preview cannot regenerate, as in
|
|
251
|
+
* a static build. Empty when the component offers no choice beyond its
|
|
252
|
+
* default, so a shell can leave the picker out.
|
|
253
|
+
*
|
|
254
|
+
* @param component - The component.
|
|
255
|
+
* @param capabilities - What the preview can do: the controller's
|
|
256
|
+
* `capabilities`.
|
|
257
|
+
* @returns The choices, or an empty list.
|
|
258
|
+
* @example
|
|
259
|
+
* ```ts
|
|
260
|
+
* const choices = scenarioChoices(component, controller.capabilities);
|
|
261
|
+
* ```
|
|
262
|
+
*/
|
|
263
|
+
export function scenarioChoices(component, capabilities) {
|
|
264
|
+
if (!component)
|
|
265
|
+
return [];
|
|
266
|
+
const baseline = component.scenarios.find((scenario) => scenario.default);
|
|
267
|
+
const others = component.scenarios.filter((scenario) => !scenario.default && (capabilities.regeneration || !scenario.empty));
|
|
268
|
+
if (others.length === 0)
|
|
269
|
+
return [];
|
|
270
|
+
return [
|
|
271
|
+
baseline
|
|
272
|
+
? { value: baseline.id, label: `${baseline.label} (default)` }
|
|
273
|
+
: { value: '', label: '(default)' },
|
|
274
|
+
...others.map((scenario) => ({
|
|
275
|
+
value: scenario.id,
|
|
276
|
+
label: scenario.label,
|
|
277
|
+
})),
|
|
278
|
+
];
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* The key a detached story pane's readiness is reported under in the
|
|
282
|
+
* state's `storyFrames`: the target, the component, then the scenario and
|
|
283
|
+
* the props as given. Two panes of the same story, scenario and props share
|
|
284
|
+
* a key, and it reads `ready` once either has loaded.
|
|
285
|
+
*
|
|
286
|
+
* @param target - The target the pane renders in.
|
|
287
|
+
* @param story - The story, as passed to `frames.mountStory`.
|
|
288
|
+
* @returns The key, such as `react:components-button:ghost`.
|
|
289
|
+
* @example
|
|
290
|
+
* ```ts
|
|
291
|
+
* const ready = state.storyFrames[storyFrameKey('vue', { component: id, scenario: 'ghost' })] === 'ready';
|
|
292
|
+
* ```
|
|
293
|
+
*/
|
|
294
|
+
export function storyFrameKey(target, story) {
|
|
295
|
+
return [
|
|
296
|
+
target,
|
|
297
|
+
story.component,
|
|
298
|
+
...(story.scenario !== undefined ? [story.scenario] : []),
|
|
299
|
+
...(story.props !== undefined ? [JSON.stringify(story.props)] : []),
|
|
300
|
+
].join(':');
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* The scenario a component starts on: its default-flagged one, else `''`,
|
|
304
|
+
* the anonymous default.
|
|
305
|
+
*
|
|
306
|
+
* @param component - The component.
|
|
307
|
+
* @returns The scenario id.
|
|
308
|
+
*/
|
|
309
|
+
export function defaultScenarioId(component) {
|
|
310
|
+
return component?.scenarios.find((scenario) => scenario.default)?.id ?? '';
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* The slots a node of the editor's tree holds content in: a component's
|
|
314
|
+
* default slot (when it has one) and then its named slots, as the catalog
|
|
315
|
+
* records them; an HTML tag's default slot; nothing for text or an opaque
|
|
316
|
+
* fill. The tree itself counts as its root component's node.
|
|
317
|
+
*
|
|
318
|
+
* @param catalog - The catalog the node's component is looked up in.
|
|
319
|
+
* @param node - A node of the tree, or the tree itself for its root.
|
|
320
|
+
* @returns The slot names, the default slot first.
|
|
321
|
+
* @example
|
|
322
|
+
* ```ts
|
|
323
|
+
* const tree = controller.getState().editor.tree!;
|
|
324
|
+
* for (const slot of nodeSlots(controller.catalog, tree)) render(slot, tree.slots[slot] ?? []);
|
|
325
|
+
* ```
|
|
326
|
+
*/
|
|
327
|
+
export function nodeSlots(catalog, node) {
|
|
328
|
+
let name;
|
|
329
|
+
if ('root' in node)
|
|
330
|
+
name = node.root;
|
|
331
|
+
else if (!isContainer(node))
|
|
332
|
+
return [];
|
|
333
|
+
else if (node.kind === 'html')
|
|
334
|
+
return [DEFAULT_SLOT];
|
|
335
|
+
else
|
|
336
|
+
name = node.component;
|
|
337
|
+
const slots = catalog.components.find((component) => component.name === name)?.slots;
|
|
338
|
+
if (!slots)
|
|
339
|
+
return [];
|
|
340
|
+
return [...(slots.default ? [DEFAULT_SLOT] : []), ...slots.named];
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* The slots the editor can add plain content to in a node of its tree: the
|
|
344
|
+
* node's slots ({@link nodeSlots}) without those whose content must take
|
|
345
|
+
* their scope, which take only a scoped fill the editor cannot author. Such a
|
|
346
|
+
* slot still holds and shows the fill a story gives it.
|
|
347
|
+
*
|
|
348
|
+
* @param catalog - The catalog the node's component is looked up in.
|
|
349
|
+
* @param node - A node of the tree, or the tree itself for its root.
|
|
350
|
+
* @returns The slot names, the default slot first.
|
|
351
|
+
* @example
|
|
352
|
+
* ```ts
|
|
353
|
+
* const targets = nodeAddSlots(controller.catalog, controller.getState().editor.tree!);
|
|
354
|
+
* ```
|
|
355
|
+
*/
|
|
356
|
+
export function nodeAddSlots(catalog, node) {
|
|
357
|
+
const name = 'root' in node
|
|
358
|
+
? node.root
|
|
359
|
+
: isContainer(node) && node.kind !== 'html'
|
|
360
|
+
? node.component
|
|
361
|
+
: undefined;
|
|
362
|
+
const scopeRequired = name === undefined
|
|
363
|
+
? []
|
|
364
|
+
: (catalog.components.find((component) => component.name === name)?.slots
|
|
365
|
+
.scopeRequired ?? []);
|
|
366
|
+
return nodeSlots(catalog, node).filter((slot) => !scopeRequired.includes(slot));
|
|
367
|
+
}
|