storybook-solidjs-vite 9.0.1-dev.1 → 9.0.1
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/dist/index.js +20 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -3
- package/dist/preset.js +92433 -5
- package/dist/preset.js.map +1 -1
- package/dist/preset.mjs +3 -3
- package/dist/preset.mjs.map +1 -1
- package/dist/renderer/entry-preview-argtypes.mjs +1 -1
- package/dist/renderer/entry-preview-docs.mjs +1 -1
- package/dist/renderer/entry-preview.mjs +2 -2
- package/dist/renderer/index.js +20 -2
- package/dist/renderer/index.js.map +1 -1
- package/dist/renderer/index.mjs +3 -3
- package/dist/renderer/preset.mjs +1 -1
- package/package.json +12 -9
- package/dist/chunk-LBLGWNID.mjs +0 -16
- package/dist/chunk-LBLGWNID.mjs.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var global = require('@storybook/global');
|
|
4
3
|
var previewApi = require('storybook/preview-api');
|
|
5
4
|
var docsTools = require('storybook/internal/docs-tools');
|
|
6
5
|
var web = require('solid-js/web');
|
|
@@ -12,7 +11,26 @@ var __export = (target, all) => {
|
|
|
12
11
|
for (var name in all)
|
|
13
12
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
13
|
};
|
|
15
|
-
|
|
14
|
+
|
|
15
|
+
// node_modules/@storybook/global/dist/index.mjs
|
|
16
|
+
var scope = (() => {
|
|
17
|
+
let win;
|
|
18
|
+
if (typeof window !== "undefined") {
|
|
19
|
+
win = window;
|
|
20
|
+
} else if (typeof globalThis !== "undefined") {
|
|
21
|
+
win = globalThis;
|
|
22
|
+
} else if (typeof global !== "undefined") {
|
|
23
|
+
win = global;
|
|
24
|
+
} else if (typeof self !== "undefined") {
|
|
25
|
+
win = self;
|
|
26
|
+
} else {
|
|
27
|
+
win = {};
|
|
28
|
+
}
|
|
29
|
+
return win;
|
|
30
|
+
})();
|
|
31
|
+
|
|
32
|
+
// src/renderer/globals.ts
|
|
33
|
+
var { window: globalWindow } = scope;
|
|
16
34
|
globalWindow.STORYBOOK_ENV = "solid";
|
|
17
35
|
|
|
18
36
|
// src/renderer/entry-preview.ts
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/renderer/globals.ts","../src/renderer/entry-preview.ts","../src/renderer/renderToCanvas.tsx","../src/renderer/render.tsx","../src/renderer/portable-stories.ts"],"names":["global","store","setStore","createStore","solidReactivityDecorator","Story","context","storyId","canvasElement","id","args","_$createComponent","_$mergeProps","cleanStoryStore","storeId","rendered","disposeFn","disposeStory","storyIsRendered","Boolean","renderSolidApp","renderContext","storyContext","storyFn","showMain","showException","App","onMount","ErrorBoundary","fallback","err","children","solidRender","renderToCanvas","forceRemount","render","_","component","Component","Error","enhanceArgTypes","setDefaultProjectAnnotations","originalSetProjectAnnotations"],"mappings":";;;;;;;;;;;;;;AAEA,IAAM,EAAE,MAAA,EAAQ,YAAA,EAAa,GAAIA,aAAA;AAEjC,YAAA,CAAa,aAAA,GAAgB,OAAA;;;ACJ7B,IAAA,qBAAA,GAAA,EAAA;AAAA,QAAA,CAAA,qBAAA,EAAA;AAAA,EAAA,iBAAA,EAAA,MAAA,iBAAA;AAAA,EAAA,UAAA,EAAA,MAAA,UAAA;AAAA,EAAA,UAAA,EAAA,MAAA,UAAA;AAAA,EAAA,MAAA,EAAA,MAAA,MAAA;AAAA,EAAA,cAAA,EAAA,MAAA;AAAA,CAAA,CAAA;ACcA,IAAM,CAACC,KAAAA,EAAOC,QAAQ,CAAA,GAAIC,mBAAAA,CAAY,EAAoB,CAAA;AAKnD,IAAMC,wBAAAA,GAAsCA,CAACC,KAAAA,EAAOC,OAAAA,KAAY;AACnE,EAAA,MAAMC,OAAAA,GAAUD,QAAQE,aAAAA,CAAcC,EAAAA;AAEtCH,EAAAA,OAAAA,CAAQI,IA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,EAAQ;AACvC,IAAM,UAAA,GAA0B,CAAC,wBAAwB,CAAA;AACzD,IAAM,iBAAA,GAAwC,CAAC8B,yBAAe,CAAA;;;AGqB9D,SAAS,sBACZ,kBAAA,EAG2C;AAC3C,EAAAC,uCAAA,CAA6B,qBAAoC,CAAA;AAEjE,EAAA,OAAOC,gCAAA;AAAA,IACH;AAAA,GACJ;AACJ","file":"index.js","sourcesContent":["import { global } from '@storybook/global';\n\nconst { window: globalWindow } = global as any;\n\nglobalWindow.STORYBOOK_ENV = 'solid';\n","/* Configuration for default renderer. */\nimport { enhanceArgTypes } from 'storybook/internal/docs-tools';\n\nimport { solidReactivityDecorator } from './renderToCanvas';\n\nimport type { Decorator } from './public-types';\nimport type { ArgTypesEnhancer } from 'storybook/internal/types';\n\nexport { render } from './render';\nexport { renderToCanvas } from './renderToCanvas';\n\nexport const parameters = { renderer: 'solid' };\nexport const decorators: Decorator[] = [solidReactivityDecorator];\nexport const argTypesEnhancers: ArgTypesEnhancer[] = [enhanceArgTypes];\n","import { ErrorBoundary, onMount } from 'solid-js';\nimport { createStore } from 'solid-js/store';\nimport { render as solidRender } from 'solid-js/web';\n\nimport type { Decorator } from './public-types';\n\nimport type { ComponentsData, SolidRenderer, StoryContext } from './types';\nimport type { Component } from 'solid-js';\nimport type { RenderContext } from 'storybook/internal/types';\n\n/**\n * SolidJS store for handling fine grained updates\n * of the components data as f.e. story args.\n */\nconst [store, setStore] = createStore({} as ComponentsData);\n\n/**\n * A decorator that ensures changing args updates the story.\n */\nexport const solidReactivityDecorator: Decorator = (Story, context) => {\n const storyId = context.canvasElement.id;\n\n context.args = store[storyId]?.args || {};\n\n return <Story { ...context.args } />;\n};\n\n/**\n * Resets an specific story store.\n */\nconst cleanStoryStore = (storeId: string) => {\n setStore({ [storeId]: { args: {}, rendered: false, disposeFn: () => {} } });\n};\n\n/**\n * Disposes an specific story.\n */\nconst disposeStory = (storeId: string) => {\n store[storeId]?.disposeFn?.();\n};\n\n\n/**\n * Checks if the story store exists\n */\nconst storyIsRendered = (storyId: string) => Boolean(store[storyId]?.rendered);\n\n/**\n * Renders solid App into DOM.\n */\nconst renderSolidApp = (\n storyId: string,\n renderContext: RenderContext<SolidRenderer>,\n canvasElement: SolidRenderer['canvasElement']\n) => {\n const { storyContext, storyFn, showMain, showException } = renderContext;\n\n const App: Component = () => {\n const Story = storyFn as Component<StoryContext<SolidRenderer>>;\n\n onMount(() => {\n showMain();\n });\n\n return (\n <ErrorBoundary\n fallback={ (err: any) => {\n showException(err);\n\n return err;\n } }\n >\n <Story { ...storyContext } />\n </ErrorBoundary>\n );\n };\n\n const disposeFn = solidRender(() => <App />, canvasElement);\n\n setStore(storyId, 'disposeFn', () => disposeFn);\n setStore(storyId, 'rendered', true);\n};\n\n/**\n * Main renderer function for initializing the SolidJS app with the story content.\n *\n * How this works is a bit different from the React renderer.\n * In React, components run again on rerender so the React renderer just recalls the component,\n * but Solid has fine-grained reactivity so components run once,\n * and when dependencies are updated, effects/tracking scopes run again.\n *\n * So, we can store args in a store and just update the store when this function is called.\n */\nexport async function renderToCanvas(\n renderContext: RenderContext<SolidRenderer>,\n canvasElement: SolidRenderer['canvasElement']\n) {\n const { storyContext, forceRemount } = renderContext;\n const storyId = storyContext.canvasElement.id;\n\n // Story is remounted given the conditions\n if (forceRemount) {\n disposeStory(storyId);\n cleanStoryStore(storyId);\n }\n\n // Story store data is updated\n setStore(storyId, 'args', storyContext.args);\n\n // Story is rendered and store data is created\n if (!storyIsRendered(storyId)) {\n renderSolidApp(storyId, renderContext, canvasElement);\n }\n}\n","import type { SolidRenderer } from './types';\nimport type { ArgsStoryFn } from 'storybook/internal/types';\n\n/**\n * Default render function for a story definition (inside a csf file) without\n * a render function. e.g:\n * ```typescript\n * export const StoryExample = {\n * args: {\n * disabled: true,\n * children: \"Hello World\",\n * },\n * };\n * ```\n */\nexport const render: ArgsStoryFn<SolidRenderer> = (_, context) => {\n const { id, component: Component } = context;\n\n if (!Component) {\n throw new Error(\n `Unable to render story ${ id } as the component annotation is missing from the default export`\n );\n }\n\n // context.args is a SolidJS proxy thanks to the solidReactivityDecorator.\n return <Component { ...context.args } />;\n};\n","import {\n setDefaultProjectAnnotations,\n setProjectAnnotations as originalSetProjectAnnotations,\n} from 'storybook/preview-api';\n\nimport * as INTERNAL_DEFAULT_PROJECT_ANNOTATIONS from './entry-preview';\n\nimport type { SolidRenderer } from './types';\n\nimport type {\n NamedOrDefaultProjectAnnotations,\n NormalizedProjectAnnotations,\n} from 'storybook/internal/types';\n\n\n/**\n * Function that sets the globalConfig of your storybook. The global config is the preview module of\n * your .storybook folder.\n *\n * It should be run a single time, so that your global config (e.g. decorators) is applied to your\n * stories when using `composeStories` or `composeStory`.\n *\n * Example:\n *\n * ```jsx\n * // setup-file.js\n * import { setProjectAnnotations } from 'storybook-solidjs';\n * import projectAnnotations from './.storybook/preview';\n *\n * setProjectAnnotations(projectAnnotations);\n * ```\n *\n * @param projectAnnotations - E.g. (import projectAnnotations from '../.storybook/preview')\n */\nexport function setProjectAnnotations(\n projectAnnotations:\n | NamedOrDefaultProjectAnnotations<any>\n | NamedOrDefaultProjectAnnotations<any>[]\n): NormalizedProjectAnnotations<SolidRenderer> {\n setDefaultProjectAnnotations(INTERNAL_DEFAULT_PROJECT_ANNOTATIONS);\n\n return originalSetProjectAnnotations(\n projectAnnotations\n ) as NormalizedProjectAnnotations<SolidRenderer>;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../node_modules/@storybook/global/dist/index.mjs","../src/renderer/globals.ts","../src/renderer/entry-preview.ts","../src/renderer/renderToCanvas.tsx","../src/renderer/render.tsx","../src/renderer/portable-stories.ts"],"names":["store","setStore","createStore","solidReactivityDecorator","Story","context","storyId","canvasElement","id","args","_$createComponent","_$mergeProps","cleanStoryStore","storeId","rendered","disposeFn","disposeStory","storyIsRendered","Boolean","renderSolidApp","renderContext","storyContext","storyFn","showMain","showException","App","onMount","ErrorBoundary","fallback","err","children","solidRender","renderToCanvas","forceRemount","render","_","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Ae,CAAA;;;AGqB9D,SAAS,sBACZ,kBAAA,EAG2C;AAC3C,EAAAC,uCAAA,CAA6B,qBAAoC,CAAA;AAEjE,EAAA,OAAOC,gCAAA;AAAA,IACH;AAAA,GACJ;AACJ","file":"index.js","sourcesContent":["// src/index.ts\nvar scope = (() => {\n let win;\n if (typeof window !== \"undefined\") {\n win = window;\n } else if (typeof globalThis !== \"undefined\") {\n win = globalThis;\n } else if (typeof global !== \"undefined\") {\n win = global;\n } else if (typeof self !== \"undefined\") {\n win = self;\n } else {\n win = {};\n }\n return win;\n})();\nexport {\n scope as global\n};\n","import { global } from '@storybook/global';\n\nconst { window: globalWindow } = global as any;\n\nglobalWindow.STORYBOOK_ENV = 'solid';\n","/* Configuration for default renderer. */\nimport { enhanceArgTypes } from 'storybook/internal/docs-tools';\n\nimport { solidReactivityDecorator } from './renderToCanvas';\n\nimport type { Decorator } from './public-types';\nimport type { ArgTypesEnhancer } from 'storybook/internal/types';\n\nexport { render } from './render';\nexport { renderToCanvas } from './renderToCanvas';\n\nexport const parameters = { renderer: 'solid' };\nexport const decorators: Decorator[] = [solidReactivityDecorator];\nexport const argTypesEnhancers: ArgTypesEnhancer[] = [enhanceArgTypes];\n","import { ErrorBoundary, onMount } from 'solid-js';\nimport { createStore } from 'solid-js/store';\nimport { render as solidRender } from 'solid-js/web';\n\nimport type { Decorator } from './public-types';\n\nimport type { ComponentsData, SolidRenderer, StoryContext } from './types';\nimport type { Component } from 'solid-js';\nimport type { RenderContext } from 'storybook/internal/types';\n\n/**\n * SolidJS store for handling fine grained updates\n * of the components data as f.e. story args.\n */\nconst [store, setStore] = createStore({} as ComponentsData);\n\n/**\n * A decorator that ensures changing args updates the story.\n */\nexport const solidReactivityDecorator: Decorator = (Story, context) => {\n const storyId = context.canvasElement.id;\n\n context.args = store[storyId]?.args || {};\n\n return <Story { ...context.args } />;\n};\n\n/**\n * Resets an specific story store.\n */\nconst cleanStoryStore = (storeId: string) => {\n setStore({ [storeId]: { args: {}, rendered: false, disposeFn: () => {} } });\n};\n\n/**\n * Disposes an specific story.\n */\nconst disposeStory = (storeId: string) => {\n store[storeId]?.disposeFn?.();\n};\n\n\n/**\n * Checks if the story store exists\n */\nconst storyIsRendered = (storyId: string) => Boolean(store[storyId]?.rendered);\n\n/**\n * Renders solid App into DOM.\n */\nconst renderSolidApp = (\n storyId: string,\n renderContext: RenderContext<SolidRenderer>,\n canvasElement: SolidRenderer['canvasElement']\n) => {\n const { storyContext, storyFn, showMain, showException } = renderContext;\n\n const App: Component = () => {\n const Story = storyFn as Component<StoryContext<SolidRenderer>>;\n\n onMount(() => {\n showMain();\n });\n\n return (\n <ErrorBoundary\n fallback={ (err: any) => {\n showException(err);\n\n return err;\n } }\n >\n <Story { ...storyContext } />\n </ErrorBoundary>\n );\n };\n\n const disposeFn = solidRender(() => <App />, canvasElement);\n\n setStore(storyId, 'disposeFn', () => disposeFn);\n setStore(storyId, 'rendered', true);\n};\n\n/**\n * Main renderer function for initializing the SolidJS app with the story content.\n *\n * How this works is a bit different from the React renderer.\n * In React, components run again on rerender so the React renderer just recalls the component,\n * but Solid has fine-grained reactivity so components run once,\n * and when dependencies are updated, effects/tracking scopes run again.\n *\n * So, we can store args in a store and just update the store when this function is called.\n */\nexport async function renderToCanvas(\n renderContext: RenderContext<SolidRenderer>,\n canvasElement: SolidRenderer['canvasElement']\n) {\n const { storyContext, forceRemount } = renderContext;\n const storyId = storyContext.canvasElement.id;\n\n // Story is remounted given the conditions\n if (forceRemount) {\n disposeStory(storyId);\n cleanStoryStore(storyId);\n }\n\n // Story store data is updated\n setStore(storyId, 'args', storyContext.args);\n\n // Story is rendered and store data is created\n if (!storyIsRendered(storyId)) {\n renderSolidApp(storyId, renderContext, canvasElement);\n }\n}\n","import type { SolidRenderer } from './types';\nimport type { ArgsStoryFn } from 'storybook/internal/types';\n\n/**\n * Default render function for a story definition (inside a csf file) without\n * a render function. e.g:\n * ```typescript\n * export const StoryExample = {\n * args: {\n * disabled: true,\n * children: \"Hello World\",\n * },\n * };\n * ```\n */\nexport const render: ArgsStoryFn<SolidRenderer> = (_, context) => {\n const { id, component: Component } = context;\n\n if (!Component) {\n throw new Error(\n `Unable to render story ${ id } as the component annotation is missing from the default export`\n );\n }\n\n // context.args is a SolidJS proxy thanks to the solidReactivityDecorator.\n return <Component { ...context.args } />;\n};\n","import {\n setDefaultProjectAnnotations,\n setProjectAnnotations as originalSetProjectAnnotations,\n} from 'storybook/preview-api';\n\nimport * as INTERNAL_DEFAULT_PROJECT_ANNOTATIONS from './entry-preview';\n\nimport type { SolidRenderer } from './types';\n\nimport type {\n NamedOrDefaultProjectAnnotations,\n NormalizedProjectAnnotations,\n} from 'storybook/internal/types';\n\n\n/**\n * Function that sets the globalConfig of your storybook. The global config is the preview module of\n * your .storybook folder.\n *\n * It should be run a single time, so that your global config (e.g. decorators) is applied to your\n * stories when using `composeStories` or `composeStory`.\n *\n * Example:\n *\n * ```jsx\n * // setup-file.js\n * import { setProjectAnnotations } from 'storybook-solidjs';\n * import projectAnnotations from './.storybook/preview';\n *\n * setProjectAnnotations(projectAnnotations);\n * ```\n *\n * @param projectAnnotations - E.g. (import projectAnnotations from '../.storybook/preview')\n */\nexport function setProjectAnnotations(\n projectAnnotations:\n | NamedOrDefaultProjectAnnotations<any>\n | NamedOrDefaultProjectAnnotations<any>[]\n): NormalizedProjectAnnotations<SolidRenderer> {\n setDefaultProjectAnnotations(INTERNAL_DEFAULT_PROJECT_ANNOTATIONS);\n\n return originalSetProjectAnnotations(\n projectAnnotations\n ) as NormalizedProjectAnnotations<SolidRenderer>;\n}\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { setProjectAnnotations } from './chunk-
|
|
2
|
-
import './chunk-
|
|
3
|
-
import './chunk-
|
|
1
|
+
export { setProjectAnnotations } from './chunk-DW4YVOOF.mjs';
|
|
2
|
+
import './chunk-X7YLPC2R.mjs';
|
|
3
|
+
import './chunk-J7LXIPZS.mjs';
|
|
4
4
|
//# sourceMappingURL=index.mjs.map
|
|
5
5
|
//# sourceMappingURL=index.mjs.map
|