@storybook/preview 7.0.0-alpha.53

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/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # Preview (Web)
2
+
3
+ This is the main API for the (web) version of the Storybook Preview.
4
+
5
+ The preview's job is:
6
+
7
+ 1. Read and update the URL (via the URL Store)
8
+
9
+ 2. Listen to instructions on the channel and emit events as things occur.
10
+
11
+ 3. Render the current selection to the web view in either story or docs mode.
12
+
13
+ ## V7 Store vs Legacy (V6)
14
+
15
+ The story store is designed to load stories 'on demand', and will operate in this fashion if the `storyStoreV7` feature is enabled.
16
+
17
+ However, for back-compat reasons, in v6 mode, we need to load all stories, synchronously on bootup, emitting the `SET_STORIES` event.
18
+
19
+ In V7 mode we do not emit that event, instead preferring the `STORY_PREPARED` event, with the data for the single story being rendered.
20
+
21
+ ## Initialization
22
+
23
+ The preview is `initialized` in two ways.
24
+
25
+ ### V7 Mode:
26
+
27
+ - `importFn` - is an async `import()` function
28
+
29
+ - `getProjectAnnotations` - is a simple function that evaluations `preview.js` and addon config files and combines them. If it errors, the Preview will show the error.
30
+
31
+ - No `getStoryIndex` function is passed, instead the preview creates a `StoryIndexClient` that pulls `stories.json` from node and watches the event stream for invalidation events.
32
+
33
+ ### V6 Mode
34
+
35
+ - `importFn` - is a simulated `import()` function, that is synchronous, see `client-api` for details.
36
+ - `getProjectAnnotations` - also evaluates `preview.js` et al, but watches for calls to `setStories`, and passes them to the `ClientApi`
37
+ - `getStoryIndex` is a local function (that must be called _after_ `getProjectAnnotations`) that gets the list of stories added.
38
+
39
+ See `client-api` for more details on this process.
40
+
41
+ ## Story Rendering and interruptions
42
+
43
+ The Preview is split into three parts responsible for state management:
44
+
45
+ - `PreviewWeb` - which story is rendered, receives events and (maybe) changes/re-renders stories
46
+ - `StoryRender` - (imports +) prepares the story, renders it through the various phases
47
+ - `DocsRender` - if a story renders in docs mode, it is "transformed" into a `DocsRender` once we know.
48
+
49
+ A rendering story goes through these phases:
50
+
51
+ - `preparing` - (maybe async) import the story file and prepare the story function.
52
+ - `loading` - async loaders are running
53
+ - `rendering` - the `renderToDOM` function for the framework is running
54
+ - `playing` - the `play` function is running
55
+ - `completed` - the story is done.
56
+
57
+ It also has two error states:
58
+
59
+ - `aborted` - the story was stopped midway (see below)
60
+ - `errored` - there was an error thrown somewhere along the way.
61
+
62
+ ### Re-rendering and aborting
63
+
64
+ A story may re-render due to various events, which can have implications if the story is not in the `completed` phase:
65
+
66
+ - `UPDATE_STORY_ARGS` / `UPDATE_GLOBALS` -- change of inputs
67
+ - `FORCE_RE_RENDER` - re-render unchanged
68
+
69
+ If these events happen during a render:
70
+
71
+ - if the story is `preparing` or `loading`, leave thing unchanged and let the new `args`/`globals` be picked up by the render phase
72
+ - otherwise, use the result of the previous `loaders` run, and simply re-render over the top
73
+
74
+ - `FORCE_REMOUNT` - remount (or equivalent) the component and re-render.
75
+
76
+ If this happens during a render, treat `loading` similarly, but:
77
+
78
+ - if the story is `rendering`, start a new render and abort the previous render immediately afterwards
79
+ - if the story is `playing`, attempt to abort the previous play function, and start a new render.
80
+
81
+ ### Changing story
82
+
83
+ Also the `SET_CURRENT_STORY` event may change the current story. We need to check:
84
+
85
+ - If the `storyId` changed
86
+ - If the `viewMode` changed
87
+ - If the story implementation changed (i.e if HMR occurred).
88
+
89
+ If the _previous_ story is still `preparing`, we cannot know if the implementation changed, so we
90
+ abort the preparing immediately, and let the new story take over.
91
+
92
+ Otherwise, if all of the above are the same, we do nothing.
93
+
94
+ If they are different, and the old story is not `completed`, we try to abort it immediately. If that fails (e.g. the `play` function doesn't respond to the `abort` event), then we reload the window.
@@ -0,0 +1 @@
1
+ var r=Object.create;var e=Object.defineProperty;var n=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty;var b=(_=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(_,{get:(o,O)=>(typeof require!="undefined"?require:o)[O]}):_)(function(_){if(typeof require!="undefined")return require.apply(this,arguments);throw new Error('Dynamic require of "'+_+'" is not supported')});var i=(_,o)=>()=>(o||_((o={exports:{}}).exports,o),o.exports),k=(_,o)=>{for(var O in o)e(_,O,{get:o[O],enumerable:!0})},T=(_,o,O,t)=>{if(o&&typeof o=="object"||typeof o=="function")for(let E of R(o))!L.call(_,E)&&E!==O&&e(_,E,{get:()=>o[E],enumerable:!(t=n(o,E))||t.enumerable});return _};var s=(_,o,O)=>(O=_!=null?r(S(_)):{},T(o||!_||!_.__esModule?e(O,"default",{value:_,enumerable:!0}):O,_));var l=(_=>(_["@storybook/addons"]="__STORYBOOK_MODULE_ADDONS__",_["@storybook/channel-postmessage"]="__STORYBOOK_MODULE_CHANNEL_POSTMESSAGE__",_["@storybook/channel-websocket"]="__STORYBOOK_MODULE_CHANNEL_WEBSOCKET__",_["@storybook/channels"]="__STORYBOOK_MODULE_CHANNELS__",_["@storybook/client-api"]="__STORYBOOK_MODULE_CLIENT_API__",_["@storybook/client-logger"]="__STORYBOOK_MODULE_CLIENT_LOGGER__",_["@storybook/core-client"]="__STORYBOOK_MODULE_CORE_CLIENT__",_["@storybook/core-events"]="__STORYBOOK_MODULE_CORE_EVENTS__",_["@storybook/preview-web"]="__STORYBOOK_MODULE_PREVIEW_WEB__",_["@storybook/store"]="__STORYBOOK_MODULE_STORE__",_))(l||{});export{b as a,i as b,k as c,s as d,l as e};
@@ -0,0 +1,36 @@
1
+ declare type ModuleType = "esm" | "cjs";
2
+
3
+ /**
4
+ * Information that discribes a module to be imported.
5
+ */
6
+ declare type ModuleInfo = {
7
+ /**
8
+ * Global variable name with which the import statements of the module
9
+ * should be replaced.
10
+ */
11
+ varName: string;
12
+
13
+ /**
14
+ * Type (either `"esm"` or `"cjs"`) that determines the internal behavior of
15
+ * this plugin. Defaults to `"esm"`.
16
+ */
17
+ type?: ModuleType;
18
+
19
+ /**
20
+ * Names of variables that are exported from the module and may be imported
21
+ * from another module.
22
+ * No effect if `type` is `"cjs"`.
23
+ */
24
+ namedExports?: readonly string[];
25
+
26
+ /**
27
+ * Set to `false` to prevent emitting code for default import/export
28
+ * (which you won't need to unless you are finicky).
29
+ * Defaults to `true`. No effect if `type` is `"cjs"`.
30
+ */
31
+ defaultExport?: boolean;
32
+ };
33
+
34
+ declare const definitions: Required<Record<"@storybook/addons" | "@storybook/channel-postmessage" | "@storybook/channel-websocket" | "@storybook/channels" | "@storybook/client-api" | "@storybook/client-logger" | "@storybook/core-client" | "@storybook/core-events" | "@storybook/preview-web" | "@storybook/store", Required<ModuleInfo>>>;
35
+
36
+ export { definitions };
@@ -0,0 +1 @@
1
+ "use strict";var n=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var i=Object.prototype.hasOwnProperty;var l=(e,o)=>{for(var r in o)n(e,r,{get:o[r],enumerable:!0})},O=(e,o,r,a)=>{if(o&&typeof o=="object"||typeof o=="function")for(let t of S(o))!i.call(e,t)&&t!==r&&n(e,t,{get:()=>o[t],enumerable:!(a=E(o,t))||a.enumerable});return e};var T=e=>O(n({},"__esModule",{value:!0}),e);var u={};l(u,{definitions:()=>p});module.exports=T(u);var _={"@storybook/addons":["AddonStore","HooksContext","addons","applyHooks","isSupportedType","makeDecorator","mockChannel","types","useArgs","useCallback","useChannel","useEffect","useGlobals","useMemo","useParameter","useReducer","useRef","useState","useStoryContext"],"@storybook/channel-postmessage":["KEY","PostmsgTransport","createChannel"],"@storybook/channel-websocket":["WebsocketTransport","createChannel"],"@storybook/channels":["Channel"],"@storybook/client-api":["ClientApi","addArgTypes","addArgTypesEnhancer","addArgs","addArgsEnhancer","addDecorator","addLoader","addParameters","addStepRunner","getQueryParam","getQueryParams","setGlobalRender","DEEPLY_EQUAL","HooksContext","NO_TARGET_NAME","StoryStore","applyHooks","combineArgs","combineParameters","composeConfigs","composeStepRunners","composeStories","composeStory","decorateStory","deepDiff","defaultDecorateStory","filterArgTypes","getArrayField","getField","getObjectField","getSingletonField","getValuesFromArgTypes","groupArgsByTarget","inferControls","mapArgsToTypes","noTargetArgs","normalizeComponentAnnotations","normalizeInputType","normalizeInputTypes","normalizeProjectAnnotations","normalizeStory","prepareStory","processCSFFile","sanitizeStoryContextUpdate","setProjectAnnotations","sortStoriesV6","sortStoriesV7","useAddonState","useArgs","useCallback","useChannel","useEffect","useGlobals","useMemo","useParameter","useReducer","useRef","useSharedState","useState","useStoryContext","userOrAutoTitle","userOrAutoTitleFromSpecifier","validateOptions"],"@storybook/client-logger":["deprecate","logger","once","pretty"],"@storybook/core-client":["ClientApi","StoryStore","start"],"@storybook/core-events":["CHANNEL_CREATED","CONFIG_ERROR","CURRENT_STORY_WAS_SET","DOCS_RENDERED","FORCE_REMOUNT","FORCE_RE_RENDER","GLOBALS_UPDATED","IGNORED_EXCEPTION","NAVIGATE_URL","PLAY_FUNCTION_THREW_EXCEPTION","PRELOAD_ENTRIES","PREVIEW_BUILDER_PROGRESS","PREVIEW_KEYDOWN","REGISTER_SUBSCRIPTION","RESET_STORY_ARGS","SELECT_STORY","SET_CONFIG","SET_CURRENT_STORY","SET_GLOBALS","SET_INDEX","SET_STORIES","SHARED_STATE_CHANGED","SHARED_STATE_SET","STORIES_COLLAPSE_ALL","STORIES_EXPAND_ALL","STORY_ARGS_UPDATED","STORY_CHANGED","STORY_ERRORED","STORY_INDEX_INVALIDATED","STORY_MISSING","STORY_PREPARED","STORY_RENDERED","STORY_RENDER_PHASE_CHANGED","STORY_SPECIFIED","STORY_THREW_EXCEPTION","STORY_UNCHANGED","UPDATE_GLOBALS","UPDATE_QUERY_PARAMS","UPDATE_STORY_ARGS"],"@storybook/preview-web":["DocsContext","Preview","PreviewWeb","PreviewWithSelection","composeConfigs","simulateDOMContentLoaded","simulatePageLoad"],"@storybook/store":["DEEPLY_EQUAL","HooksContext","NO_TARGET_NAME","StoryStore","applyHooks","combineArgs","combineParameters","composeConfigs","composeStepRunners","composeStories","composeStory","decorateStory","deepDiff","defaultDecorateStory","filterArgTypes","getArrayField","getField","getObjectField","getSingletonField","getValuesFromArgTypes","groupArgsByTarget","inferControls","mapArgsToTypes","noTargetArgs","normalizeComponentAnnotations","normalizeInputType","normalizeInputTypes","normalizeProjectAnnotations","normalizeStory","prepareStory","processCSFFile","sanitizeStoryContextUpdate","setProjectAnnotations","sortStoriesV6","sortStoriesV7","useAddonState","useArgs","useCallback","useChannel","useEffect","useGlobals","useMemo","useParameter","useReducer","useRef","useSharedState","useState","useStoryContext","userOrAutoTitle","userOrAutoTitleFromSpecifier","validateOptions"]};var s=(e=>(e["@storybook/addons"]="__STORYBOOK_MODULE_ADDONS__",e["@storybook/channel-postmessage"]="__STORYBOOK_MODULE_CHANNEL_POSTMESSAGE__",e["@storybook/channel-websocket"]="__STORYBOOK_MODULE_CHANNEL_WEBSOCKET__",e["@storybook/channels"]="__STORYBOOK_MODULE_CHANNELS__",e["@storybook/client-api"]="__STORYBOOK_MODULE_CLIENT_API__",e["@storybook/client-logger"]="__STORYBOOK_MODULE_CLIENT_LOGGER__",e["@storybook/core-client"]="__STORYBOOK_MODULE_CORE_CLIENT__",e["@storybook/core-events"]="__STORYBOOK_MODULE_CORE_EVENTS__",e["@storybook/preview-web"]="__STORYBOOK_MODULE_PREVIEW_WEB__",e["@storybook/store"]="__STORYBOOK_MODULE_STORE__",e))(s||{});var R=e=>({type:"esm",varName:s[e],namedExports:_[e],defaultExport:!0}),p=Object.keys(s).reduce((e,o)=>(e[o]=R(o),e),{});0&&(module.exports={definitions});
@@ -0,0 +1 @@
1
+ import{e as o}from"./chunk-IM5IP5SQ.mjs";var r={"@storybook/addons":["AddonStore","HooksContext","addons","applyHooks","isSupportedType","makeDecorator","mockChannel","types","useArgs","useCallback","useChannel","useEffect","useGlobals","useMemo","useParameter","useReducer","useRef","useState","useStoryContext"],"@storybook/channel-postmessage":["KEY","PostmsgTransport","createChannel"],"@storybook/channel-websocket":["WebsocketTransport","createChannel"],"@storybook/channels":["Channel"],"@storybook/client-api":["ClientApi","addArgTypes","addArgTypesEnhancer","addArgs","addArgsEnhancer","addDecorator","addLoader","addParameters","addStepRunner","getQueryParam","getQueryParams","setGlobalRender","DEEPLY_EQUAL","HooksContext","NO_TARGET_NAME","StoryStore","applyHooks","combineArgs","combineParameters","composeConfigs","composeStepRunners","composeStories","composeStory","decorateStory","deepDiff","defaultDecorateStory","filterArgTypes","getArrayField","getField","getObjectField","getSingletonField","getValuesFromArgTypes","groupArgsByTarget","inferControls","mapArgsToTypes","noTargetArgs","normalizeComponentAnnotations","normalizeInputType","normalizeInputTypes","normalizeProjectAnnotations","normalizeStory","prepareStory","processCSFFile","sanitizeStoryContextUpdate","setProjectAnnotations","sortStoriesV6","sortStoriesV7","useAddonState","useArgs","useCallback","useChannel","useEffect","useGlobals","useMemo","useParameter","useReducer","useRef","useSharedState","useState","useStoryContext","userOrAutoTitle","userOrAutoTitleFromSpecifier","validateOptions"],"@storybook/client-logger":["deprecate","logger","once","pretty"],"@storybook/core-client":["ClientApi","StoryStore","start"],"@storybook/core-events":["CHANNEL_CREATED","CONFIG_ERROR","CURRENT_STORY_WAS_SET","DOCS_RENDERED","FORCE_REMOUNT","FORCE_RE_RENDER","GLOBALS_UPDATED","IGNORED_EXCEPTION","NAVIGATE_URL","PLAY_FUNCTION_THREW_EXCEPTION","PRELOAD_ENTRIES","PREVIEW_BUILDER_PROGRESS","PREVIEW_KEYDOWN","REGISTER_SUBSCRIPTION","RESET_STORY_ARGS","SELECT_STORY","SET_CONFIG","SET_CURRENT_STORY","SET_GLOBALS","SET_INDEX","SET_STORIES","SHARED_STATE_CHANGED","SHARED_STATE_SET","STORIES_COLLAPSE_ALL","STORIES_EXPAND_ALL","STORY_ARGS_UPDATED","STORY_CHANGED","STORY_ERRORED","STORY_INDEX_INVALIDATED","STORY_MISSING","STORY_PREPARED","STORY_RENDERED","STORY_RENDER_PHASE_CHANGED","STORY_SPECIFIED","STORY_THREW_EXCEPTION","STORY_UNCHANGED","UPDATE_GLOBALS","UPDATE_QUERY_PARAMS","UPDATE_STORY_ARGS"],"@storybook/preview-web":["DocsContext","Preview","PreviewWeb","PreviewWithSelection","composeConfigs","simulateDOMContentLoaded","simulatePageLoad"],"@storybook/store":["DEEPLY_EQUAL","HooksContext","NO_TARGET_NAME","StoryStore","applyHooks","combineArgs","combineParameters","composeConfigs","composeStepRunners","composeStories","composeStory","decorateStory","deepDiff","defaultDecorateStory","filterArgTypes","getArrayField","getField","getObjectField","getSingletonField","getValuesFromArgTypes","groupArgsByTarget","inferControls","mapArgsToTypes","noTargetArgs","normalizeComponentAnnotations","normalizeInputType","normalizeInputTypes","normalizeProjectAnnotations","normalizeStory","prepareStory","processCSFFile","sanitizeStoryContextUpdate","setProjectAnnotations","sortStoriesV6","sortStoriesV7","useAddonState","useArgs","useCallback","useChannel","useEffect","useGlobals","useMemo","useParameter","useReducer","useRef","useSharedState","useState","useStoryContext","userOrAutoTitle","userOrAutoTitleFromSpecifier","validateOptions"]};var s=e=>({type:"esm",varName:o[e],namedExports:r[e],defaultExport:!0}),E=Object.keys(o).reduce((e,t)=>(e[t]=s(t),e),{});export{E as definitions};
@@ -0,0 +1 @@
1
+