@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,541 @@
|
|
|
1
|
+
import type { OptionValue, PreviewOption } from './options.js';
|
|
2
|
+
import type { CodeBlockContent, ViewContextComponent, ViewContextSource, ViewFramework } from './views.js';
|
|
3
|
+
/**
|
|
4
|
+
* What a story pane renders in: a scripted target, which a component preview
|
|
5
|
+
* iframe runs the story's script in, or `html`, the markup the story renders
|
|
6
|
+
* to with no JavaScript of its own.
|
|
7
|
+
*/
|
|
8
|
+
export declare const PREVIEW_TARGETS: readonly ["react", "vue", "svelte", "html"];
|
|
9
|
+
/** What a story pane renders in: one of {@link PREVIEW_TARGETS}. */
|
|
10
|
+
export type PreviewTarget = (typeof PREVIEW_TARGETS)[number];
|
|
11
|
+
/** A target a component preview iframe runs a story's script in: every
|
|
12
|
+
* target but `html`. */
|
|
13
|
+
export type PreviewScriptedTarget = Exclude<PreviewTarget, 'html'>;
|
|
14
|
+
/** The scripted targets, in the preview's order: {@link PREVIEW_TARGETS}
|
|
15
|
+
* without `html`. */
|
|
16
|
+
export declare const PREVIEW_SCRIPTED_TARGETS: readonly ["react", "vue", "svelte"];
|
|
17
|
+
/** The `type` of each message, keyed by a short name. */
|
|
18
|
+
export declare const PREVIEW_MESSAGE: {
|
|
19
|
+
/** Iframe → host: the iframe listens for messages now (sent on each load). */
|
|
20
|
+
readonly ready: "preview:ready";
|
|
21
|
+
/** Host → iframe: mount a story by id with its root props. */
|
|
22
|
+
readonly setStory: "preview:set-story";
|
|
23
|
+
/** Host → iframe: replace the mounted story's props in place. */
|
|
24
|
+
readonly props: "preview:props";
|
|
25
|
+
/** Host → iframe: the merged option values to apply to the document. */
|
|
26
|
+
readonly globals: "preview:globals";
|
|
27
|
+
/** Host → view iframe: the catalog a custom view builds its context from. */
|
|
28
|
+
readonly catalog: "preview:catalog";
|
|
29
|
+
/** View iframe → host: open a component story, as a navigation click does. */
|
|
30
|
+
readonly select: "preview:select";
|
|
31
|
+
/** Iframe → host: the size of what the iframe shows, sent once it renders
|
|
32
|
+
* and again on each change. */
|
|
33
|
+
readonly contentSize: "preview:content-size";
|
|
34
|
+
/** Host → html iframe: the markup to show, or why there is none. */
|
|
35
|
+
readonly markup: "preview:markup";
|
|
36
|
+
/** Iframe → host: the story threw as it rendered, or, with no message,
|
|
37
|
+
* the story it mounts since renders. */
|
|
38
|
+
readonly renderError: "preview:render-error";
|
|
39
|
+
/** Host → code iframe: the source the kit's code block shows. */
|
|
40
|
+
readonly code: "preview:code";
|
|
41
|
+
/** Iframe → host: the story called one of its events. */
|
|
42
|
+
readonly event: "preview:event";
|
|
43
|
+
/** Iframe → host: its first content has mounted and painted, so the host
|
|
44
|
+
* can show the iframe. Sent once per document. */
|
|
45
|
+
readonly shown: "preview:shown";
|
|
46
|
+
};
|
|
47
|
+
/** The `type` of a preview message. */
|
|
48
|
+
export type PreviewMessageType = (typeof PREVIEW_MESSAGE)[keyof typeof PREVIEW_MESSAGE];
|
|
49
|
+
/** Sent by an iframe once its message listener is attached. */
|
|
50
|
+
export interface PreviewReadyMessage {
|
|
51
|
+
type: typeof PREVIEW_MESSAGE.ready;
|
|
52
|
+
}
|
|
53
|
+
/** Sent by an iframe once its first content has mounted and painted. */
|
|
54
|
+
export interface PreviewShownMessage {
|
|
55
|
+
type: typeof PREVIEW_MESSAGE.shown;
|
|
56
|
+
}
|
|
57
|
+
/** Mounts the story `id` afresh with `props` as its root props. */
|
|
58
|
+
export interface PreviewSetStoryMessage {
|
|
59
|
+
type: typeof PREVIEW_MESSAGE.setStory;
|
|
60
|
+
id: string;
|
|
61
|
+
props: Record<string, unknown>;
|
|
62
|
+
/** The story's events: the function props a pane records the calls of,
|
|
63
|
+
* reporting each as a `preview:event`. */
|
|
64
|
+
events?: string[];
|
|
65
|
+
/** The story's two-way props and the event each reports its new value
|
|
66
|
+
* through. A pane may take a value a story's given prop reports as that
|
|
67
|
+
* prop at once, as the host does after it (see {@link withWriteBacks}). */
|
|
68
|
+
bindings?: PreviewWriteBack[];
|
|
69
|
+
/** Which of the host's story mounts this is: a pane tags each event it
|
|
70
|
+
* records with it, so the host can tell an event of a story it has since
|
|
71
|
+
* replaced (see {@link withEventRecorders}). */
|
|
72
|
+
mount?: number;
|
|
73
|
+
}
|
|
74
|
+
/** A two-way prop and the event prop it reports each new value through. */
|
|
75
|
+
export interface PreviewWriteBack {
|
|
76
|
+
/** The two-way prop. */
|
|
77
|
+
prop: string;
|
|
78
|
+
/** The event prop called with each new value. */
|
|
79
|
+
changeProp: string;
|
|
80
|
+
}
|
|
81
|
+
/** Replaces the mounted story's root props, keeping its component instance. */
|
|
82
|
+
export interface PreviewPropsMessage {
|
|
83
|
+
type: typeof PREVIEW_MESSAGE.props;
|
|
84
|
+
props: Record<string, unknown>;
|
|
85
|
+
/** The newest of the receiving pane's own write-backs the host had taken
|
|
86
|
+
* when it sent the props (the `write` of the pane's events, see
|
|
87
|
+
* {@link PendingWriteBacks}): a pane keeps a later write of its own over
|
|
88
|
+
* the value these props hold. Absent, the pane takes the props as they
|
|
89
|
+
* are. */
|
|
90
|
+
answers?: number;
|
|
91
|
+
}
|
|
92
|
+
/** The option values (global and story-scoped, merged) the iframe applies. */
|
|
93
|
+
export interface PreviewGlobalsMessage {
|
|
94
|
+
type: typeof PREVIEW_MESSAGE.globals;
|
|
95
|
+
options: Record<string, OptionValue>;
|
|
96
|
+
}
|
|
97
|
+
/** The catalog a custom view reads: the kit's name, its sources and its stories. */
|
|
98
|
+
export interface PreviewCatalogPayload {
|
|
99
|
+
kitName: string;
|
|
100
|
+
sources: ViewContextSource[];
|
|
101
|
+
components: ViewContextComponent[];
|
|
102
|
+
}
|
|
103
|
+
/** Delivers the {@link PreviewCatalogPayload} to the view iframe. */
|
|
104
|
+
export interface PreviewCatalogMessage extends PreviewCatalogPayload {
|
|
105
|
+
type: typeof PREVIEW_MESSAGE.catalog;
|
|
106
|
+
}
|
|
107
|
+
/** Asks the host to open a component story, optionally with root props. */
|
|
108
|
+
export interface PreviewSelectMessage {
|
|
109
|
+
type: typeof PREVIEW_MESSAGE.select;
|
|
110
|
+
id: string;
|
|
111
|
+
props?: Record<string, unknown>;
|
|
112
|
+
}
|
|
113
|
+
/** The size of what a preview iframe shows, in whole CSS pixels. */
|
|
114
|
+
export interface PreviewContentSize {
|
|
115
|
+
width: number;
|
|
116
|
+
height: number;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Reports the size of what an iframe shows: its story or view, with the
|
|
120
|
+
* padding, borders and margins of the elements around it, rounded up to
|
|
121
|
+
* whole CSS pixels, so an iframe of that size shows it all.
|
|
122
|
+
*/
|
|
123
|
+
export interface PreviewContentSizeMessage extends PreviewContentSize {
|
|
124
|
+
type: typeof PREVIEW_MESSAGE.contentSize;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* The html iframe's story: its `markup`, or the `reason` it has none. With
|
|
128
|
+
* neither, the markup is being printed, and the iframe keeps what it shows.
|
|
129
|
+
*/
|
|
130
|
+
export interface PreviewMarkupMessage {
|
|
131
|
+
type: typeof PREVIEW_MESSAGE.markup;
|
|
132
|
+
markup?: string;
|
|
133
|
+
/** The styles of the components the markup renders, shown with it. */
|
|
134
|
+
stylesheet?: string;
|
|
135
|
+
reason?: string;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Reports what an iframe's story threw as it rendered (`message`), shown in
|
|
139
|
+
* the story's place; with no `message`, the story mounted since renders.
|
|
140
|
+
*/
|
|
141
|
+
export interface PreviewRenderErrorMessage {
|
|
142
|
+
type: typeof PREVIEW_MESSAGE.renderError;
|
|
143
|
+
message?: string;
|
|
144
|
+
}
|
|
145
|
+
/** The source a code iframe's block shows: a target's, in its language, or
|
|
146
|
+
* why it has none; with neither, it is being printed. */
|
|
147
|
+
export interface PreviewCodeMessage extends CodeBlockContent {
|
|
148
|
+
type: typeof PREVIEW_MESSAGE.code;
|
|
149
|
+
}
|
|
150
|
+
/** Reports a story's call of one of its events: its `name`, a readable
|
|
151
|
+
* summary of what it was called with, and its first argument as `value`
|
|
152
|
+
* when that is plain data (what JSON holds), such as the new value a
|
|
153
|
+
* two-way prop's change callback reports. */
|
|
154
|
+
export interface PreviewEventMessage {
|
|
155
|
+
type: typeof PREVIEW_MESSAGE.event;
|
|
156
|
+
name: string;
|
|
157
|
+
payload: string;
|
|
158
|
+
value?: unknown;
|
|
159
|
+
/** The `mount` of the set-story message the pane was showing. */
|
|
160
|
+
mount?: number;
|
|
161
|
+
/** The number of the newest value the pane wrote back itself since its
|
|
162
|
+
* last report, when it wrote one (see {@link PendingWriteBacks}): the
|
|
163
|
+
* host answers it on the pane's next props message. */
|
|
164
|
+
write?: number;
|
|
165
|
+
}
|
|
166
|
+
/** Any message the host and the iframes exchange. */
|
|
167
|
+
export type PreviewMessage = PreviewReadyMessage | PreviewSetStoryMessage | PreviewPropsMessage | PreviewGlobalsMessage | PreviewCatalogMessage | PreviewSelectMessage | PreviewContentSizeMessage | PreviewMarkupMessage | PreviewRenderErrorMessage | PreviewCodeMessage | PreviewEventMessage | PreviewShownMessage;
|
|
168
|
+
/** The message whose `type` is `Type`. */
|
|
169
|
+
export type PreviewMessageOf<Type extends PreviewMessageType> = Extract<PreviewMessage, {
|
|
170
|
+
type: Type;
|
|
171
|
+
}>;
|
|
172
|
+
/**
|
|
173
|
+
* Read posted data as a preview message: the data itself when it is an object
|
|
174
|
+
* whose `type` is one of the preview's, otherwise `undefined`. Only the `type`
|
|
175
|
+
* is checked; a receiver validates the payload it relies on.
|
|
176
|
+
*
|
|
177
|
+
* @param data - A `MessageEvent`'s `data`.
|
|
178
|
+
* @returns The data as a {@link PreviewMessage}, or `undefined`.
|
|
179
|
+
*/
|
|
180
|
+
export declare function readPreviewMessage(data: unknown): PreviewMessage | undefined;
|
|
181
|
+
/**
|
|
182
|
+
* Whether posted data is a preview message of one type.
|
|
183
|
+
*
|
|
184
|
+
* @param data - A `MessageEvent`'s `data`.
|
|
185
|
+
* @param type - The message type to match.
|
|
186
|
+
* @returns `true` when `data` is an object whose `type` is `type`.
|
|
187
|
+
*/
|
|
188
|
+
export declare function isPreviewMessage<Type extends PreviewMessageType>(data: unknown, type: Type): data is PreviewMessageOf<Type>;
|
|
189
|
+
/** @returns A {@link PreviewReadyMessage}. */
|
|
190
|
+
export declare function readyMessage(): PreviewReadyMessage;
|
|
191
|
+
/**
|
|
192
|
+
* @param id - The story's id.
|
|
193
|
+
* @param props - Its root props.
|
|
194
|
+
* @param events - The function props a pane records the calls of.
|
|
195
|
+
* @param bindings - The two-way props and the events they report through.
|
|
196
|
+
* @param mount - Which of the host's story mounts this is.
|
|
197
|
+
* @returns A {@link PreviewSetStoryMessage}.
|
|
198
|
+
*/
|
|
199
|
+
export declare function setStoryMessage(id: string, props: Record<string, unknown>, events?: string[], bindings?: readonly PreviewWriteBack[], mount?: number): PreviewSetStoryMessage;
|
|
200
|
+
/**
|
|
201
|
+
* The story's props with each two-way prop's change event writing the value
|
|
202
|
+
* it reports back as that prop at once, through `write`, while the story
|
|
203
|
+
* gives the prop: what the host does with the value after it hears of the
|
|
204
|
+
* call, done inside the pane, so a framework that restores a controlled
|
|
205
|
+
* input to its prop's value as the event ends (React) finds the new value
|
|
206
|
+
* there and keeps the caret where it was. The host's own write-back follows
|
|
207
|
+
* with the same value. Only plain data is written, as the host takes only
|
|
208
|
+
* plain data; a prop the story leaves out stays the component's own.
|
|
209
|
+
*
|
|
210
|
+
* @param props - The story's root props, its events' recorders in place.
|
|
211
|
+
* @param bindings - The two-way props and the events they report through.
|
|
212
|
+
* @param write - Takes a two-way prop's new value.
|
|
213
|
+
* @returns The props, each given two-way prop's change event writing back.
|
|
214
|
+
* @example
|
|
215
|
+
* ```ts
|
|
216
|
+
* withWriteBacks(props, [{ prop: 'value', changeProp: 'onValueChange' }], (prop, value) =>
|
|
217
|
+
* setProps((current) => ({ ...current, [prop]: value }))
|
|
218
|
+
* );
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
export declare function withWriteBacks(props: Record<string, unknown>, bindings: readonly PreviewWriteBack[] | undefined, write: (prop: string, value: unknown) => void): Record<string, unknown>;
|
|
222
|
+
/**
|
|
223
|
+
* The values a pane has written back itself (see {@link withWriteBacks}) and
|
|
224
|
+
* the host has not yet answered, per two-way prop, oldest first. Each write
|
|
225
|
+
* gets a number, counting up for the life of the pane, which the next event
|
|
226
|
+
* the pane reports carries (`write`); each props message from the host
|
|
227
|
+
* names the newest write it had taken when it sent them (`answers`). Props
|
|
228
|
+
* the host sent before it took a write hold an older value for that prop,
|
|
229
|
+
* whether they answer the write's own echo or a change of another control,
|
|
230
|
+
* so `reconcile` keeps the pane's newest value over them.
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```ts
|
|
234
|
+
* const pending = new PendingWriteBacks();
|
|
235
|
+
* pending.wrote('value', 'ab'); // 1
|
|
236
|
+
* pending.wrote('value', 'abc'); // 2
|
|
237
|
+
* pending.reconcile({ value: 'ab' }, 1); // { value: 'abc' }, still waiting for 2
|
|
238
|
+
* pending.reconcile({ value: 'abc' }, 2); // { value: 'abc' }, nothing waiting
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
export declare class PendingWriteBacks {
|
|
242
|
+
private readonly pending;
|
|
243
|
+
private count;
|
|
244
|
+
private unreported;
|
|
245
|
+
/**
|
|
246
|
+
* Note a value the pane has written back for a prop.
|
|
247
|
+
*
|
|
248
|
+
* @param prop - The two-way prop.
|
|
249
|
+
* @param value - The value, plain data.
|
|
250
|
+
* @returns The write's number.
|
|
251
|
+
*/
|
|
252
|
+
wrote(prop: string, value: unknown): number;
|
|
253
|
+
/**
|
|
254
|
+
* The number of the newest write since the last call, for the event the
|
|
255
|
+
* pane reports next to carry; `undefined` when there has been none.
|
|
256
|
+
*
|
|
257
|
+
* @returns The write's number, or `undefined`.
|
|
258
|
+
*/
|
|
259
|
+
takeUnreported(): number | undefined;
|
|
260
|
+
/**
|
|
261
|
+
* The host's props as the pane takes them. The writes up to `answers` are
|
|
262
|
+
* done with: the host had them when it sent the props. A two-way prop the
|
|
263
|
+
* host gives with a later write still waiting keeps the newest value the
|
|
264
|
+
* pane wrote. Without `answers` the props are taken as they are, and
|
|
265
|
+
* every write is done with.
|
|
266
|
+
*
|
|
267
|
+
* @param props - The props the host sends.
|
|
268
|
+
* @param answers - The newest of the pane's writes the host had taken.
|
|
269
|
+
* @returns The props to take.
|
|
270
|
+
*/
|
|
271
|
+
reconcile(props: Record<string, unknown>, answers?: number): Record<string, unknown>;
|
|
272
|
+
/** Forget every write, as a new story starts. The count goes on. */
|
|
273
|
+
clear(): void;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* The story's props with a recorder for each of its events: a function that
|
|
277
|
+
* reports its call to the host as a `preview:event`, the event's name and a
|
|
278
|
+
* readable summary of what it was called with. A function the props hold
|
|
279
|
+
* already for an event is called too.
|
|
280
|
+
*
|
|
281
|
+
* @param props - The story's root props.
|
|
282
|
+
* @param events - The function props to record the calls of.
|
|
283
|
+
* @param target - The pane's window.
|
|
284
|
+
* @param mount - The `mount` of the set-story message the pane shows, which
|
|
285
|
+
* each report carries.
|
|
286
|
+
* @param writes - The pane's own write-backs: a report carries the number of
|
|
287
|
+
* the newest write since the last one (`write`), for the host to answer.
|
|
288
|
+
* @returns The props, an event's recorder in its place.
|
|
289
|
+
*/
|
|
290
|
+
export declare function withEventRecorders(props: Record<string, unknown>, events?: readonly string[], target?: Window, mount?: number, writes?: PendingWriteBacks): Record<string, unknown>;
|
|
291
|
+
/**
|
|
292
|
+
* Whether a value is plain data, which survives `postMessage` and JSON as it
|
|
293
|
+
* is: `null`, a boolean, a finite number, a string, or an array or plain
|
|
294
|
+
* object of these.
|
|
295
|
+
*
|
|
296
|
+
* @param value - The value.
|
|
297
|
+
* @param depth - How deep the value sits in the one being read.
|
|
298
|
+
* @returns `true` when the value is plain data.
|
|
299
|
+
*/
|
|
300
|
+
export declare function isPlainData(value: unknown, depth?: number): boolean;
|
|
301
|
+
/** A readable, one-line summary of what an event was called with. */
|
|
302
|
+
export declare function summarizeArguments(parameters: unknown[]): string;
|
|
303
|
+
/**
|
|
304
|
+
* @param props - The mounted story's new root props.
|
|
305
|
+
* @param answers - The newest of the receiving pane's write-backs the host
|
|
306
|
+
* has taken.
|
|
307
|
+
* @returns A {@link PreviewPropsMessage}.
|
|
308
|
+
*/
|
|
309
|
+
export declare function propsMessage(props: Record<string, unknown>, answers?: number): PreviewPropsMessage;
|
|
310
|
+
/**
|
|
311
|
+
* @param options - The option values, keyed by option id.
|
|
312
|
+
* @returns A {@link PreviewGlobalsMessage}.
|
|
313
|
+
*/
|
|
314
|
+
export declare function globalsMessage(options: Record<string, OptionValue>): PreviewGlobalsMessage;
|
|
315
|
+
/**
|
|
316
|
+
* @param catalog - The kit's name, sources and browseable stories.
|
|
317
|
+
* @returns A {@link PreviewCatalogMessage}.
|
|
318
|
+
*/
|
|
319
|
+
export declare function catalogMessage(catalog: PreviewCatalogPayload): PreviewCatalogMessage;
|
|
320
|
+
/**
|
|
321
|
+
* @param id - The component story to open.
|
|
322
|
+
* @param props - Root props to open it with, over the component's defaults.
|
|
323
|
+
* @returns A {@link PreviewSelectMessage}.
|
|
324
|
+
*/
|
|
325
|
+
export declare function selectMessage(id: string, props?: Record<string, unknown>): PreviewSelectMessage;
|
|
326
|
+
/**
|
|
327
|
+
* @param content - The target's source, its language, or why it has none.
|
|
328
|
+
* @returns A {@link PreviewCodeMessage}.
|
|
329
|
+
*/
|
|
330
|
+
export declare function codeMessage(content: CodeBlockContent): PreviewCodeMessage;
|
|
331
|
+
/**
|
|
332
|
+
* Tell the host what the iframe's story threw as it rendered, or, with no
|
|
333
|
+
* message, that the story mounted since renders.
|
|
334
|
+
*
|
|
335
|
+
* @param message - The error's message; omitted when a new story mounts.
|
|
336
|
+
* @param target - The iframe's window.
|
|
337
|
+
*/
|
|
338
|
+
export declare function reportRenderError(message?: string, target?: Window): void;
|
|
339
|
+
/**
|
|
340
|
+
* @param size - The content's width and height in CSS pixels.
|
|
341
|
+
* @returns A {@link PreviewContentSizeMessage}.
|
|
342
|
+
*/
|
|
343
|
+
export declare function contentSizeMessage(size: PreviewContentSize): PreviewContentSizeMessage;
|
|
344
|
+
/**
|
|
345
|
+
* @param story - The markup to show, the reason there is none, or neither
|
|
346
|
+
* while it is being printed.
|
|
347
|
+
* @returns A {@link PreviewMarkupMessage}.
|
|
348
|
+
*/
|
|
349
|
+
export declare function markupMessage(story: {
|
|
350
|
+
markup: string;
|
|
351
|
+
stylesheet?: string;
|
|
352
|
+
} | {
|
|
353
|
+
reason: string;
|
|
354
|
+
} | Record<string, never>): PreviewMarkupMessage;
|
|
355
|
+
/**
|
|
356
|
+
* Read posted data as a content size: its width and height when both are
|
|
357
|
+
* finite numbers of zero or more, otherwise `undefined`.
|
|
358
|
+
*
|
|
359
|
+
* @param message - A {@link PreviewContentSizeMessage} as it was received.
|
|
360
|
+
* @returns The size, or `undefined` for a malformed message.
|
|
361
|
+
*/
|
|
362
|
+
export declare function readContentSize(message: PreviewContentSizeMessage): PreviewContentSize | undefined;
|
|
363
|
+
/** The window property an iframe sets to `true` once it can receive messages,
|
|
364
|
+
* for a test that loads the iframe's page on its own (where the ready message
|
|
365
|
+
* has no parent to reach). */
|
|
366
|
+
export declare const PREVIEW_READY_FLAG = "__previewReady";
|
|
367
|
+
/** The window property a story iframe sets to the ids of the stories it can
|
|
368
|
+
* mount, for a test helper to reject an id that would mount nothing. */
|
|
369
|
+
export declare const PREVIEW_STORIES_FLAG = "__previewStories";
|
|
370
|
+
/** The window property a preview iframe sets to the kit's options, each with
|
|
371
|
+
* the values a choice option offers, for a test helper to reject an id or a
|
|
372
|
+
* value the iframe would ignore. */
|
|
373
|
+
export declare const PREVIEW_OPTIONS_FLAG = "__previewOptions";
|
|
374
|
+
/** The window property a story iframe sets to the message of what its story
|
|
375
|
+
* threw as it rendered, or to `null` while the story mounted since renders,
|
|
376
|
+
* for a test that loads the iframe's page on its own (where the report has no
|
|
377
|
+
* parent to reach). The message is a string, and may be empty. */
|
|
378
|
+
export declare const PREVIEW_RENDER_ERROR_FLAG = "__previewRenderError";
|
|
379
|
+
/** The window property a story iframe sets to the id of the story it last
|
|
380
|
+
* finished mounting, or to the empty string once a story has unmounted with
|
|
381
|
+
* none set after it. Set after the story's first render and its effects, so
|
|
382
|
+
* a test that loads the iframe's page on its own can tell a story that
|
|
383
|
+
* rendered nothing from one still mounting. */
|
|
384
|
+
export declare const PREVIEW_MOUNTED_STORY_FLAG = "__previewMountedStory";
|
|
385
|
+
/** The id of the element each preview iframe mounts its story or view in. */
|
|
386
|
+
export declare const PREVIEW_MOUNT_ELEMENT_ID = "app";
|
|
387
|
+
/**
|
|
388
|
+
* Announce that an iframe shows its first content: post a
|
|
389
|
+
* {@link PreviewShownMessage} to the parent window once the content mounted
|
|
390
|
+
* now has painted, two animation frames on. Call it after the iframe mounts
|
|
391
|
+
* the first content the host sends; a later call in the same document sends
|
|
392
|
+
* nothing.
|
|
393
|
+
*
|
|
394
|
+
* @param target - The iframe's window.
|
|
395
|
+
*/
|
|
396
|
+
export declare function announcePreviewShown(target?: Window): void;
|
|
397
|
+
/**
|
|
398
|
+
* Record under {@link PREVIEW_MOUNTED_STORY_FLAG} that the iframe has finished
|
|
399
|
+
* mounting a story. Call it once the framework has committed the mount,
|
|
400
|
+
* whatever the story rendered.
|
|
401
|
+
*
|
|
402
|
+
* @param id - The story's id, or the empty string after an unmount.
|
|
403
|
+
* @param target - The iframe's window.
|
|
404
|
+
*/
|
|
405
|
+
export declare function announceStoryMounted(id: string, target?: Window): void;
|
|
406
|
+
/**
|
|
407
|
+
* List the stories an iframe can mount under {@link PREVIEW_STORIES_FLAG}.
|
|
408
|
+
* Call it before {@link announcePreviewReady}, so a test that waits for the
|
|
409
|
+
* iframe finds the list.
|
|
410
|
+
*
|
|
411
|
+
* @param ids - The ids of the stories.
|
|
412
|
+
* @param target - The iframe's window.
|
|
413
|
+
*/
|
|
414
|
+
export declare function announcePreviewStories(ids: readonly string[], target?: Window): void;
|
|
415
|
+
/** An option as a preview iframe lists it: its id and, for a choice, the
|
|
416
|
+
* values it offers; a boolean option has no `values`. */
|
|
417
|
+
export interface PreviewListedOption {
|
|
418
|
+
/** The option's id. */
|
|
419
|
+
id: string;
|
|
420
|
+
/** The values of a choice option. */
|
|
421
|
+
values?: string[];
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* List the kit's options under {@link PREVIEW_OPTIONS_FLAG}.
|
|
425
|
+
*
|
|
426
|
+
* @param options - The options.
|
|
427
|
+
* @param target - The iframe's window.
|
|
428
|
+
*/
|
|
429
|
+
export declare function announcePreviewOptions(options: readonly Pick<PreviewOption, 'id' | 'values'>[], target?: Window): void;
|
|
430
|
+
/**
|
|
431
|
+
* Announce that an iframe listens for messages: set {@link PREVIEW_READY_FLAG}
|
|
432
|
+
* and post a {@link PreviewReadyMessage} to the parent window. Call it right
|
|
433
|
+
* after attaching the message listener.
|
|
434
|
+
*
|
|
435
|
+
* @param target - The iframe's window.
|
|
436
|
+
*/
|
|
437
|
+
export declare function announcePreviewReady(target?: Window): void;
|
|
438
|
+
/**
|
|
439
|
+
* Measure what an iframe shows: the mount element's own box, with the
|
|
440
|
+
* padding, borders and margins of the mount and every element around it up
|
|
441
|
+
* to the body, rounded up to whole CSS pixels. Nothing in it depends on the
|
|
442
|
+
* height of the iframe, so a host that sizes the iframe to it does not make
|
|
443
|
+
* it grow: a wrapper's `min-height: 100vh` adds nothing but its padding.
|
|
444
|
+
* Where the mount's own height may follow the layout around it (a minimum
|
|
445
|
+
* height of its own, or a flex or grid item), its children's extent stands
|
|
446
|
+
* in for it.
|
|
447
|
+
*
|
|
448
|
+
* @param mount - The element the story or view is mounted in.
|
|
449
|
+
* @returns The content's width and height.
|
|
450
|
+
*/
|
|
451
|
+
export declare function measureContentSize(mount: HTMLElement): PreviewContentSize;
|
|
452
|
+
/**
|
|
453
|
+
* Report the size of what an iframe shows to the parent window as a
|
|
454
|
+
* {@link PreviewContentSizeMessage}: once now, and again whenever it
|
|
455
|
+
* changes, at most once per animation frame and only when the size differs
|
|
456
|
+
* from the last one reported. It watches the mount, its children and the
|
|
457
|
+
* elements around it for a change of size, the mount's content for a change
|
|
458
|
+
* of nodes or text, the elements around it for a change of class or style,
|
|
459
|
+
* and the window for a resize. Call it once the message listener is
|
|
460
|
+
* attached; a second call for the same mount returns the first one's stop.
|
|
461
|
+
*
|
|
462
|
+
* @param mount - The element the story or view is mounted in.
|
|
463
|
+
* @param target - The iframe's window.
|
|
464
|
+
* @returns A function that stops the reports.
|
|
465
|
+
*/
|
|
466
|
+
export declare function reportContentSize(mount: HTMLElement, target?: Window): () => void;
|
|
467
|
+
/** The query parameter that names the view the view iframe renders. */
|
|
468
|
+
export declare const VIEW_PARAMETER = "view";
|
|
469
|
+
/** The query parameter that names the framework of the view the view iframe
|
|
470
|
+
* renders, so the iframe loads that framework's setup module before the view. */
|
|
471
|
+
export declare const VIEW_FRAMEWORK_PARAMETER = "framework";
|
|
472
|
+
/** The query parameter that names the target whose source a code iframe
|
|
473
|
+
* shows. */
|
|
474
|
+
export declare const CODE_TARGET_PARAMETER = "target";
|
|
475
|
+
/** The query parameter a component iframe's URL carries so that changing it
|
|
476
|
+
* reloads the iframe. */
|
|
477
|
+
export declare const RELOAD_PARAMETER = "r";
|
|
478
|
+
/**
|
|
479
|
+
* The URL of a story pane's iframe: a target's, or the html one's.
|
|
480
|
+
*
|
|
481
|
+
* @param target - What the iframe renders in.
|
|
482
|
+
* @param reload - A counter whose change reloads the iframe; omitted, the URL
|
|
483
|
+
* carries no reload parameter.
|
|
484
|
+
* @param baseUrl - The URL the preview is served under, ending in `/`; the
|
|
485
|
+
* root of the origin, `/`, by default.
|
|
486
|
+
* @returns The page's URL, such as `/preview/vue/preview.html?r=0`.
|
|
487
|
+
*/
|
|
488
|
+
export declare function componentFrameUrl(target: PreviewTarget, reload?: number, baseUrl?: string): string;
|
|
489
|
+
/** The query parameters a target's pane, opened on its own, reads its
|
|
490
|
+
* story from: the story's id, its root props and the option values, the
|
|
491
|
+
* latter two as JSON. */
|
|
492
|
+
export declare const STANDALONE_PARAMETERS: {
|
|
493
|
+
readonly story: "story";
|
|
494
|
+
readonly props: "props";
|
|
495
|
+
readonly options: "options";
|
|
496
|
+
};
|
|
497
|
+
/**
|
|
498
|
+
* The URL of a target's pane opened on its own, outside the preview: it
|
|
499
|
+
* shows `story` with its props under its option values, as the preview's pane
|
|
500
|
+
* does, with no host to follow.
|
|
501
|
+
*
|
|
502
|
+
* @param target - The target to render the story in.
|
|
503
|
+
* @param story - The story's id, root props and option values.
|
|
504
|
+
* @param baseUrl - The URL the preview is served under, ending in `/`.
|
|
505
|
+
* @returns The pane's URL.
|
|
506
|
+
*/
|
|
507
|
+
export declare function standaloneFrameUrl(target: PreviewScriptedTarget, story: {
|
|
508
|
+
id: string;
|
|
509
|
+
props: Record<string, unknown>;
|
|
510
|
+
options: Record<string, OptionValue>;
|
|
511
|
+
}, baseUrl?: string): string;
|
|
512
|
+
/**
|
|
513
|
+
* The messages a pane opened on its own gives itself, from its address: the
|
|
514
|
+
* story to mount and the option values. None when the address names no story.
|
|
515
|
+
*
|
|
516
|
+
* @param search - The pane's `location.search`.
|
|
517
|
+
* @returns A set-story and a globals message, or none.
|
|
518
|
+
*/
|
|
519
|
+
export declare function standaloneMessages(search: string): PreviewMessage[];
|
|
520
|
+
/**
|
|
521
|
+
* The URL of a code iframe: the kit's code block, showing one target's
|
|
522
|
+
* source.
|
|
523
|
+
*
|
|
524
|
+
* @param target - The target whose source the block shows.
|
|
525
|
+
* @param framework - The block's framework; a framework other than `'dom'`
|
|
526
|
+
* is named in the URL, so the iframe loads its setup module first.
|
|
527
|
+
* @param baseUrl - The URL the preview is served under, ending in `/`.
|
|
528
|
+
* @returns The page's URL, such as `/preview/code/code.html?target=vue`.
|
|
529
|
+
*/
|
|
530
|
+
export declare function codeFrameUrl(target: PreviewTarget, framework?: ViewFramework, baseUrl?: string): string;
|
|
531
|
+
/**
|
|
532
|
+
* The URL of the view iframe rendering one custom view.
|
|
533
|
+
*
|
|
534
|
+
* @param viewId - The view's id.
|
|
535
|
+
* @param framework - The view's framework; a framework other than `'dom'` is
|
|
536
|
+
* named in the URL, so the iframe loads its setup module ahead of the views.
|
|
537
|
+
* @param baseUrl - The URL the preview is served under, ending in `/`; the
|
|
538
|
+
* root of the origin, `/`, by default.
|
|
539
|
+
* @returns The page's URL, such as `/preview/view/view.html?view=tokens`.
|
|
540
|
+
*/
|
|
541
|
+
export declare function viewFrameUrl(viewId: string, framework?: ViewFramework, baseUrl?: string): string;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { RenderedView, ViewContext } from './views.js';
|
|
3
|
+
/** A React view's render function: the view's element tree for a context. */
|
|
4
|
+
export type ReactViewRender = (context: ViewContext) => ReactNode;
|
|
5
|
+
/**
|
|
6
|
+
* Make a view's `framework` and `mount` from a React render function. The
|
|
7
|
+
* view iframe then loads the kit's React setup module before mounting it.
|
|
8
|
+
*
|
|
9
|
+
* @param render - Renders the view for a context; called again with each new one.
|
|
10
|
+
* @returns The view's `framework` (`'react'`) and `mount`, to spread into its entry.
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* export const views: PreviewView[] = [
|
|
14
|
+
* {
|
|
15
|
+
* id: 'foundations',
|
|
16
|
+
* label: 'Foundations',
|
|
17
|
+
* ...reactView((context) => <Foundations theme={String(context.options.theme)} />),
|
|
18
|
+
* },
|
|
19
|
+
* ];
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare function reactView(render: ReactViewRender): Required<Pick<RenderedView, 'framework' | 'mount'>>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { PreviewController, PreviewState } from './controller/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Read a slice of the controller's state. The component re-renders when the
|
|
4
|
+
* slice changes by identity, so `selector` returns a field of the state (or
|
|
5
|
+
* a primitive derived from it) rather than a fresh object or array; derive
|
|
6
|
+
* those from the slice afterwards.
|
|
7
|
+
*
|
|
8
|
+
* @param controller - The controller to read.
|
|
9
|
+
* @param selector - Picks the slice; the whole state when omitted.
|
|
10
|
+
* @returns The slice.
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* const scenario = usePreview(controller, (state) => state.scenario);
|
|
14
|
+
* const panes = usePreview(controller, (state) => state.targets.panes);
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function usePreview<Selected = PreviewState>(controller: PreviewController, selector?: (state: PreviewState) => Selected): Selected;
|