@stencil/storybook-plugin 0.5.9 → 0.7.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/dist/{entry-preview-C0ipNwpw.cjs → entry-preview-BmNVHtoL.cjs} +5 -3
- package/dist/entry-preview-BmNVHtoL.cjs.map +1 -0
- package/dist/{entry-preview-C1JSJAGq.js → entry-preview-Oaye2Q3u.js} +8 -3
- package/dist/entry-preview-Oaye2Q3u.js.map +1 -0
- package/dist/entry-preview-argtypes.cjs +2 -2
- package/dist/entry-preview-argtypes.js +2 -2
- package/dist/entry-preview.cjs +1 -1
- package/dist/entry-preview.d.cts.map +1 -1
- package/dist/entry-preview.d.ts.map +1 -1
- package/dist/entry-preview.js +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.js +2 -2
- package/dist/preset.cjs +104 -4
- package/dist/preset.cjs.map +1 -1
- package/dist/preset.d.cts.map +1 -1
- package/dist/preset.d.ts.map +1 -1
- package/dist/preset.js +104 -4
- package/dist/preset.js.map +1 -1
- package/dist/{src-D0dJRYm2.cjs → src-C4ce9Ps1.cjs} +2 -2
- package/dist/{src-D0dJRYm2.cjs.map → src-C4ce9Ps1.cjs.map} +1 -1
- package/dist/{src-BBcTbcCa.js → src-DWOWXEPY.js} +2 -2
- package/dist/{src-BBcTbcCa.js.map → src-DWOWXEPY.js.map} +1 -1
- package/package.json +6 -7
- package/preset.js +1 -1
- package/dist/entry-preview-C0ipNwpw.cjs.map +0 -1
- package/dist/entry-preview-C1JSJAGq.js.map +0 -1
|
@@ -8,8 +8,10 @@ const render = (args, context) => {
|
|
|
8
8
|
const { component, parameters: parameters$1 } = context;
|
|
9
9
|
if (Array.isArray(component)) throw new Error("If your story does not contain a render function, you must provide a component property!");
|
|
10
10
|
if (typeof component === "string" && !customElements.get(component)) throw new Error(`Stencil component not found. If you are not lazy loading your components with \`defineCustomElements()\` in preview.ts, pass a constructor value for component in your story \`component: MyComponent\``);
|
|
11
|
-
else if (typeof component !== "string" && !customElements.getName(component))
|
|
12
|
-
|
|
11
|
+
else if (typeof component !== "string" && !customElements.getName(component)) {
|
|
12
|
+
if (!component.is || !customElements.get(component.is)) throw new Error(`Stencil component not found. If you are lazy loading your components with \`defineCustomElements()\` in preview.ts, pass a string value for component in your story \`component: 'my-component'\``);
|
|
13
|
+
}
|
|
14
|
+
const cmpName = typeof component === "string" ? component : customElements.getName(component) ?? component.is;
|
|
13
15
|
const children = Object.entries(parameters$1.slots || []).map(([key, value]) => {
|
|
14
16
|
const slot = key === "default" ? void 0 : key;
|
|
15
17
|
const child = typeof value === "string" ? (0, __stencil_core.h)(void 0, { slot }, value) : {
|
|
@@ -82,4 +84,4 @@ Object.defineProperty(exports, 'renderToCanvas', {
|
|
|
82
84
|
return renderToCanvas;
|
|
83
85
|
}
|
|
84
86
|
});
|
|
85
|
-
//# sourceMappingURL=entry-preview-
|
|
87
|
+
//# sourceMappingURL=entry-preview-BmNVHtoL.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-preview-BmNVHtoL.cjs","names":["render: ArgsStoryFn<StencilRenderer<unknown>>","children: any[]","parameters","canvasElement: StencilRenderer<unknown>['canvasElement']","parameters: Parameters","argTypesEnhancers: ArgTypesEnhancer[]","enhanceArgTypes"],"sources":["../src/render.ts","../src/entry-preview.ts"],"sourcesContent":["import { h, render as renderStencil, VNode } from '@stencil/core';\nimport { ArgsStoryFn, RenderContext } from 'storybook/internal/types';\nimport { simulatePageLoad } from 'storybook/preview-api';\n\nimport type { StencilRenderer } from './types';\n\nexport const render: ArgsStoryFn<StencilRenderer<unknown>> = (args, context) => {\n const { component, parameters } = context;\n\n if (Array.isArray(component)) {\n throw new Error('If your story does not contain a render function, you must provide a component property!');\n }\n if (typeof component === 'string' && !customElements.get(component)) {\n throw new Error(\n `Stencil component not found. If you are not lazy loading your components with \\`defineCustomElements()\\` in preview.ts, pass a constructor value for component in your story \\`component: MyComponent\\``,\n );\n } else if (typeof component !== 'string' && !customElements.getName(component)) {\n // After HMR the module re-evaluates and produces a new class reference, so\n // getName returns null even though the tag is still registered under component.is.\n if (!(component as any).is || !customElements.get((component as any).is)) {\n throw new Error(\n `Stencil component not found. If you are lazy loading your components with \\`defineCustomElements()\\` in preview.ts, pass a string value for component in your story \\`component: 'my-component'\\``,\n );\n }\n }\n const cmpName =\n typeof component === 'string' ? component : (customElements.getName(component) ?? (component as any).is);\n\n const children: any[] = Object.entries<VNode>(parameters.slots || []).map(([key, value]) => {\n // if the parameter key is 'default' don't give it a slot name so it renders just as a child\n const slot = key === 'default' ? undefined : key;\n // if the value it s a string, create a vnode with the string as the children\n const child =\n typeof value === 'string'\n ? h(undefined, { slot }, value)\n : {\n ...value,\n $attrs$: {\n ...value.$attrs$,\n slot,\n },\n };\n // if the value is a fragment and it is a named slot, create a span element with the slot name\n child.$tag$ = child.$tag$ || (slot ? 'span' : null);\n return child.$tag$ ? child : child.$children$;\n });\n\n const Component = `${cmpName}`;\n return h(Component, { ...args }, children);\n};\n\nexport function renderToCanvas(\n { storyFn, showMain, storyContext }: RenderContext<StencilRenderer<unknown>>,\n canvasElement: StencilRenderer<unknown>['canvasElement'],\n) {\n const vdom = storyFn();\n showMain();\n\n /**\n * If the component is not automatically registered after import, register it here\n */\n if (storyContext.component && storyContext.component.is && !customElements.get(storyContext.component.is)) {\n customElements.define(storyContext.component.is, storyContext.component);\n }\n\n if (canvasElement.firstChild) {\n canvasElement.removeChild(canvasElement.firstChild);\n }\n\n const element = document.createElement('div');\n canvasElement.appendChild(element);\n renderStencil(vdom, element);\n simulatePageLoad(element);\n}\n","import { enhanceArgTypes } from 'storybook/internal/docs-tools';\nimport type { ArgTypesEnhancer, Parameters } from 'storybook/internal/types';\n\nexport const parameters: Parameters = { renderer: 'stencil' };\n\nexport { render, renderToCanvas } from './render';\n\nexport const argTypesEnhancers: ArgTypesEnhancer[] = [enhanceArgTypes];\n\n// Reload the iframe when a Stencil component .tsx is rebuilt — see preset.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,QAAQ;AAClC,4BAAc,MAAM,QAAQ;AAC5B,6CAAiB,QAAQ;AAC1B;;;;;;;;;;;ACtED,MAAaC,aAAyB,EAAE,UAAU,UAAW;AAI7D,MAAaC,oBAAwC,CAACC,6CAAgB"}
|
|
@@ -17,8 +17,10 @@ const render$1 = (args, context) => {
|
|
|
17
17
|
const { component, parameters: parameters$1 } = context;
|
|
18
18
|
if (Array.isArray(component)) throw new Error("If your story does not contain a render function, you must provide a component property!");
|
|
19
19
|
if (typeof component === "string" && !customElements.get(component)) throw new Error(`Stencil component not found. If you are not lazy loading your components with \`defineCustomElements()\` in preview.ts, pass a constructor value for component in your story \`component: MyComponent\``);
|
|
20
|
-
else if (typeof component !== "string" && !customElements.getName(component))
|
|
21
|
-
|
|
20
|
+
else if (typeof component !== "string" && !customElements.getName(component)) {
|
|
21
|
+
if (!component.is || !customElements.get(component.is)) throw new Error(`Stencil component not found. If you are lazy loading your components with \`defineCustomElements()\` in preview.ts, pass a string value for component in your story \`component: 'my-component'\``);
|
|
22
|
+
}
|
|
23
|
+
const cmpName = typeof component === "string" ? component : customElements.getName(component) ?? component.is;
|
|
22
24
|
const children = Object.entries(parameters$1.slots || []).map(([key, value]) => {
|
|
23
25
|
const slot = key === "default" ? void 0 : key;
|
|
24
26
|
const child = typeof value === "string" ? h(void 0, { slot }, value) : {
|
|
@@ -59,7 +61,10 @@ __export(entry_preview_exports, {
|
|
|
59
61
|
});
|
|
60
62
|
const parameters = { renderer: "stencil" };
|
|
61
63
|
const argTypesEnhancers = [enhanceArgTypes];
|
|
64
|
+
if (import.meta.hot) import.meta.hot.on("stencil:reload", () => {
|
|
65
|
+
location.reload();
|
|
66
|
+
});
|
|
62
67
|
|
|
63
68
|
//#endregion
|
|
64
69
|
export { argTypesEnhancers, entry_preview_exports, parameters, render$1 as render, renderToCanvas };
|
|
65
|
-
//# sourceMappingURL=entry-preview-
|
|
70
|
+
//# sourceMappingURL=entry-preview-Oaye2Q3u.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-preview-Oaye2Q3u.js","names":["render: ArgsStoryFn<StencilRenderer<unknown>>","children: any[]","parameters","canvasElement: StencilRenderer<unknown>['canvasElement']","parameters: Parameters","argTypesEnhancers: ArgTypesEnhancer[]"],"sources":["../src/render.ts","../src/entry-preview.ts"],"sourcesContent":["import { h, render as renderStencil, VNode } from '@stencil/core';\nimport { ArgsStoryFn, RenderContext } from 'storybook/internal/types';\nimport { simulatePageLoad } from 'storybook/preview-api';\n\nimport type { StencilRenderer } from './types';\n\nexport const render: ArgsStoryFn<StencilRenderer<unknown>> = (args, context) => {\n const { component, parameters } = context;\n\n if (Array.isArray(component)) {\n throw new Error('If your story does not contain a render function, you must provide a component property!');\n }\n if (typeof component === 'string' && !customElements.get(component)) {\n throw new Error(\n `Stencil component not found. If you are not lazy loading your components with \\`defineCustomElements()\\` in preview.ts, pass a constructor value for component in your story \\`component: MyComponent\\``,\n );\n } else if (typeof component !== 'string' && !customElements.getName(component)) {\n // After HMR the module re-evaluates and produces a new class reference, so\n // getName returns null even though the tag is still registered under component.is.\n if (!(component as any).is || !customElements.get((component as any).is)) {\n throw new Error(\n `Stencil component not found. If you are lazy loading your components with \\`defineCustomElements()\\` in preview.ts, pass a string value for component in your story \\`component: 'my-component'\\``,\n );\n }\n }\n const cmpName =\n typeof component === 'string' ? component : (customElements.getName(component) ?? (component as any).is);\n\n const children: any[] = Object.entries<VNode>(parameters.slots || []).map(([key, value]) => {\n // if the parameter key is 'default' don't give it a slot name so it renders just as a child\n const slot = key === 'default' ? undefined : key;\n // if the value it s a string, create a vnode with the string as the children\n const child =\n typeof value === 'string'\n ? h(undefined, { slot }, value)\n : {\n ...value,\n $attrs$: {\n ...value.$attrs$,\n slot,\n },\n };\n // if the value is a fragment and it is a named slot, create a span element with the slot name\n child.$tag$ = child.$tag$ || (slot ? 'span' : null);\n return child.$tag$ ? child : child.$children$;\n });\n\n const Component = `${cmpName}`;\n return h(Component, { ...args }, children);\n};\n\nexport function renderToCanvas(\n { storyFn, showMain, storyContext }: RenderContext<StencilRenderer<unknown>>,\n canvasElement: StencilRenderer<unknown>['canvasElement'],\n) {\n const vdom = storyFn();\n showMain();\n\n /**\n * If the component is not automatically registered after import, register it here\n */\n if (storyContext.component && storyContext.component.is && !customElements.get(storyContext.component.is)) {\n customElements.define(storyContext.component.is, storyContext.component);\n }\n\n if (canvasElement.firstChild) {\n canvasElement.removeChild(canvasElement.firstChild);\n }\n\n const element = document.createElement('div');\n canvasElement.appendChild(element);\n renderStencil(vdom, element);\n simulatePageLoad(element);\n}\n","import { enhanceArgTypes } from 'storybook/internal/docs-tools';\nimport type { ArgTypesEnhancer, Parameters } from 'storybook/internal/types';\n\nexport const parameters: Parameters = { renderer: 'stencil' };\n\nexport { render, renderToCanvas } from './render';\n\nexport const argTypesEnhancers: ArgTypesEnhancer[] = [enhanceArgTypes];\n\n// Reload the iframe when a Stencil component .tsx is rebuilt — see preset.ts.\nif (import.meta.hot) {\n import.meta.hot.on('stencil:reload', () => {\n location.reload();\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;AAMA,MAAaA,WAAgD,CAAC,MAAM,YAAY;CAC9E,MAAM,EAAE,WAAW,0BAAY,GAAG;AAElC,KAAI,MAAM,QAAQ,UAAU,CAC1B,OAAM,IAAI,MAAM;AAElB,YAAW,cAAc,aAAa,eAAe,IAAI,UAAU,CACjE,OAAM,IAAI,OACP;iBAEa,cAAc,aAAa,eAAe,QAAQ,UAAU,EAG5E;OAAM,UAAkB,OAAO,eAAe,IAAK,UAAkB,GAAG,CACtE,OAAM,IAAI,OACP;CAEJ;CAEH,MAAM,iBACG,cAAc,WAAW,YAAa,eAAe,QAAQ,UAAU,IAAK,UAAkB;CAEvG,MAAMC,WAAkB,OAAO,QAAeC,aAAW,SAAS,CAAE,EAAC,CAAC,IAAI,CAAC,CAAC,KAAK,MAAM,KAAK;EAE1F,MAAM,OAAO,QAAQ,qBAAwB;EAE7C,MAAM,eACG,UAAU,WACb,UAAa,EAAE,KAAM,GAAE,MAAM,GAC7B;GACE,GAAG;GACH,SAAS;IACP,GAAG,MAAM;IACT;GACD;EACF;AAEP,QAAM,QAAQ,MAAM,UAAU,OAAO,SAAS;AAC9C,SAAO,MAAM,QAAQ,QAAQ,MAAM;CACpC,EAAC;CAEF,MAAM,aAAa,EAAE,QAAQ;AAC7B,QAAO,EAAE,WAAW,EAAE,GAAG,KAAM,GAAE,SAAS;AAC3C;AAED,SAAgB,eACd,EAAE,SAAS,UAAU,cAAuD,EAC5EC,eACA;CACA,MAAM,OAAO,SAAS;AACtB,WAAU;;;;AAKV,KAAI,aAAa,aAAa,aAAa,UAAU,OAAO,eAAe,IAAI,aAAa,UAAU,GAAG,CACvG,gBAAe,OAAO,aAAa,UAAU,IAAI,aAAa,UAAU;AAG1E,KAAI,cAAc,WAChB,eAAc,YAAY,cAAc,WAAW;CAGrD,MAAM,UAAU,SAAS,cAAc,MAAM;AAC7C,eAAc,YAAY,QAAQ;AAClC,QAAc,MAAM,QAAQ;AAC5B,kBAAiB,QAAQ;AAC1B;;;;;;;;;;;ACtED,MAAaC,aAAyB,EAAE,UAAU,UAAW;AAI7D,MAAaC,oBAAwC,CAAC,eAAgB;AAGtE,IAAI,OAAO,KAAK,IACd,QAAO,KAAK,IAAI,GAAG,kBAAkB,MAAM;AACzC,UAAS,QAAQ;AAClB,EAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-CsX-DzYB.cjs');
|
|
2
|
-
const require_src = require('./src-
|
|
3
|
-
require('./entry-preview-
|
|
2
|
+
const require_src = require('./src-C4ce9Ps1.cjs');
|
|
3
|
+
require('./entry-preview-BmNVHtoL.cjs');
|
|
4
4
|
const storybook_internal_docs_tools = require_chunk.__toESM(require("storybook/internal/docs-tools"));
|
|
5
5
|
const storybook_internal_client_logger = require_chunk.__toESM(require("storybook/internal/client-logger"));
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "./entry-preview-
|
|
1
|
+
import "./entry-preview-Oaye2Q3u.js";
|
|
2
2
|
import "./rollup-parseAst-t-4tfMPG.d.ts";
|
|
3
|
-
import { getCustomElements, isValidComponent, isValidMetaData } from "./src-
|
|
3
|
+
import { getCustomElements, isValidComponent, isValidMetaData } from "./src-DWOWXEPY.js";
|
|
4
4
|
import { enhanceArgTypes } from "storybook/internal/docs-tools";
|
|
5
5
|
import { logger } from "storybook/internal/client-logger";
|
|
6
6
|
|
package/dist/entry-preview.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_entry_preview = require('./entry-preview-
|
|
1
|
+
const require_entry_preview = require('./entry-preview-BmNVHtoL.cjs');
|
|
2
2
|
|
|
3
3
|
exports.argTypesEnhancers = require_entry_preview.argTypesEnhancers;
|
|
4
4
|
exports.parameters = require_entry_preview.parameters;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry-preview.d.cts","names":[],"sources":["../src/render.ts","../src/entry-preview.ts"],"sourcesContent":[],"mappings":";;;;cAMa,QAAQ,YAAY;
|
|
1
|
+
{"version":3,"file":"entry-preview.d.cts","names":[],"sources":["../src/render.ts","../src/entry-preview.ts"],"sourcesContent":[],"mappings":";;;;cAMa,QAAQ,YAAY;iBA6CjB,cAAA;;;;GACuB,cAAc,0CACpC;AA/CjB;;;cCHa,YAAY;cAIZ,mBAAmB;ADDhC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry-preview.d.ts","names":[],"sources":["../src/render.ts","../src/entry-preview.ts"],"sourcesContent":[],"mappings":";;;;cAMa,QAAQ,YAAY;
|
|
1
|
+
{"version":3,"file":"entry-preview.d.ts","names":[],"sources":["../src/render.ts","../src/entry-preview.ts"],"sourcesContent":[],"mappings":";;;;cAMa,QAAQ,YAAY;iBA6CjB,cAAA;;;;GACuB,cAAc,0CACpC;AA/CjB;;;cCHa,YAAY;cAIZ,mBAAmB;ADDhC"}
|
package/dist/entry-preview.js
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const require_src = require('./src-
|
|
2
|
-
require('./entry-preview-
|
|
1
|
+
const require_src = require('./src-C4ce9Ps1.cjs');
|
|
2
|
+
require('./entry-preview-BmNVHtoL.cjs');
|
|
3
3
|
|
|
4
4
|
exports.getCustomElements = require_src.getCustomElements;
|
|
5
5
|
exports.isValidComponent = require_src.isValidComponent;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "./entry-preview-
|
|
1
|
+
import "./entry-preview-Oaye2Q3u.js";
|
|
2
2
|
import "./rollup-parseAst-t-4tfMPG.d.ts";
|
|
3
|
-
import { getCustomElements, isValidComponent, isValidMetaData, setCustomElements, setCustomElementsManifest, setProjectAnnotations } from "./src-
|
|
3
|
+
import { getCustomElements, isValidComponent, isValidMetaData, setCustomElements, setCustomElementsManifest, setProjectAnnotations } from "./src-DWOWXEPY.js";
|
|
4
4
|
|
|
5
5
|
export { getCustomElements, isValidComponent, isValidMetaData, setCustomElements, setCustomElementsManifest, setProjectAnnotations };
|
package/dist/preset.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-CsX-DzYB.cjs');
|
|
2
|
+
const fs = require_chunk.__toESM(require("fs"));
|
|
2
3
|
const module$1 = require_chunk.__toESM(require("module"));
|
|
3
4
|
const path = require_chunk.__toESM(require("path"));
|
|
4
|
-
const
|
|
5
|
+
const __stencil_community_unplugin_stencil = require_chunk.__toESM(require("@stencil-community/unplugin-stencil"));
|
|
6
|
+
const __stencil_community_unplugin_stencil_vite = require_chunk.__toESM(require("@stencil-community/unplugin-stencil/vite"));
|
|
5
7
|
const url = require_chunk.__toESM(require("url"));
|
|
6
8
|
const vite = require_chunk.__toESM(require("vite"));
|
|
7
9
|
|
|
@@ -10,18 +12,116 @@ const require$1 = (0, module$1.createRequire)(require("url").pathToFileURL(__fil
|
|
|
10
12
|
const getAbsolutePath = (input) => (0, path.dirname)(require$1.resolve((0, path.join)(input, "package.json")));
|
|
11
13
|
const __dirname$1 = (0, path.dirname)((0, url.fileURLToPath)(require("url").pathToFileURL(__filename).href));
|
|
12
14
|
const renderer = (0, path.join)(__dirname$1, "entry-preview.js");
|
|
15
|
+
const UNPLUGIN_STENCIL_NAME = "@stencil-community/unplugin-stencil";
|
|
13
16
|
const core = {
|
|
14
|
-
builder: getAbsolutePath("@storybook/builder-vite"),
|
|
17
|
+
builder: (0, path.join)(getAbsolutePath("@storybook/builder-vite"), "dist", "index.js"),
|
|
15
18
|
renderer
|
|
16
19
|
};
|
|
17
20
|
const viteFinal = async (defaultConfig, { configType }) => {
|
|
18
21
|
const config = (0, vite.mergeConfig)(defaultConfig, {
|
|
19
22
|
build: { target: "es2020" },
|
|
20
|
-
plugins: [(0,
|
|
23
|
+
plugins: [(0, __stencil_community_unplugin_stencil_vite.default)({ rootPath: defaultConfig.root })]
|
|
24
|
+
});
|
|
25
|
+
if (configType === "DEVELOPMENT") return (0, vite.mergeConfig)(config, {
|
|
26
|
+
build: { rollupOptions: { external: ["@stencil/core"] } },
|
|
27
|
+
server: { watch: { ignored: [(0, path.join)(__dirname$1, "**")] } },
|
|
28
|
+
plugins: [stencilPreviewReloadPlugin()]
|
|
21
29
|
});
|
|
22
|
-
if (configType === "DEVELOPMENT") return (0, vite.mergeConfig)(config, { build: { rollupOptions: { external: ["@stencil/core"] } } });
|
|
23
30
|
return config;
|
|
24
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* Forces a full preview reload when a Stencil component changes.
|
|
34
|
+
*
|
|
35
|
+
* `customElements.define()` is permanent, so HMR can't swap the new class in —
|
|
36
|
+
* the iframe must reload. We use a custom HMR event (instead of Vite's
|
|
37
|
+
* `full-reload`) because Storybook's story-index watcher races us with its own
|
|
38
|
+
* `vite-app.js` HMR update and cancels plain reloads.
|
|
39
|
+
*
|
|
40
|
+
* - Eager: the .tsx is in Vite's graph; our `transform` hook fires after
|
|
41
|
+
* unplugin-stencil and emits the reload.
|
|
42
|
+
* - Lazy: the .tsx isn't imported, so we run unplugin-stencil ourselves, then
|
|
43
|
+
* reload once `@stencil-community/unplugin-stencil` reports the build
|
|
44
|
+
* finished (its `stencilBuildEvents` emitter, instead of polling dist/esm).
|
|
45
|
+
* - Styles: `@stencil-community/unplugin-stencil` exposes a `style → component`
|
|
46
|
+
* map built from each component's `@Component` decorator (AST-parsed, covers
|
|
47
|
+
* `styleUrl`, `styleUrls` array, and `styleUrls` mode object). When a tracked
|
|
48
|
+
* style file changes we touch every dependent `.tsx` so the eager/lazy paths
|
|
49
|
+
* above pick up the rebuild.
|
|
50
|
+
* - Global style: the same package resolves `stencil.config#globalStyle`; when
|
|
51
|
+
* it changes we touch every known component `.tsx`.
|
|
52
|
+
*/
|
|
53
|
+
function stencilPreviewReloadPlugin() {
|
|
54
|
+
let devServer;
|
|
55
|
+
let lazyBuildPending = false;
|
|
56
|
+
const sendReload = (server) => {
|
|
57
|
+
server.ws.send({
|
|
58
|
+
type: "custom",
|
|
59
|
+
event: "stencil:reload"
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
const distEsmFragment = `${path.sep}dist${path.sep}esm${path.sep}`;
|
|
63
|
+
const isComponentSource = (id) => id.endsWith(".tsx") && !id.endsWith(".stories.tsx") && !id.includes(`${path.sep}node_modules${path.sep}`) && !id.includes(`${path.sep}.storybook${path.sep}`);
|
|
64
|
+
const invalidateDistEsm = (server) => {
|
|
65
|
+
for (const cached of server.moduleGraph.idToModuleMap.values()) if (cached.id && cached.id.includes(distEsmFragment) && cached.id.endsWith(".js")) server.moduleGraph.invalidateModule(cached);
|
|
66
|
+
};
|
|
67
|
+
const touch = (file) => {
|
|
68
|
+
try {
|
|
69
|
+
const now = /* @__PURE__ */ new Date();
|
|
70
|
+
(0, fs.utimesSync)(file, now, now);
|
|
71
|
+
} catch {}
|
|
72
|
+
};
|
|
73
|
+
return {
|
|
74
|
+
name: "stencil-preview-reload",
|
|
75
|
+
configureServer(server) {
|
|
76
|
+
devServer = server;
|
|
77
|
+
__stencil_community_unplugin_stencil.stencilBuildEvents.on("buildFinished", () => {
|
|
78
|
+
if (!lazyBuildPending || !devServer) return;
|
|
79
|
+
lazyBuildPending = false;
|
|
80
|
+
invalidateDistEsm(devServer);
|
|
81
|
+
sendReload(devServer);
|
|
82
|
+
});
|
|
83
|
+
server.watcher.on("change", async (file) => {
|
|
84
|
+
const { byStyle, byComponent, globalStyle } = (0, __stencil_community_unplugin_stencil.getComponentStyleDependencies)();
|
|
85
|
+
const resolved = (0, path.resolve)(file);
|
|
86
|
+
if (globalStyle && resolved === globalStyle) {
|
|
87
|
+
for (const componentId of byComponent.keys()) touch(componentId);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const dependents = byStyle.get(resolved);
|
|
91
|
+
if (dependents && dependents.size > 0) {
|
|
92
|
+
for (const componentId of dependents) touch(componentId);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (!file.endsWith(".tsx") || file.endsWith(".stories.tsx")) return;
|
|
96
|
+
const mod = server.moduleGraph.getModuleById(file);
|
|
97
|
+
if (mod && mod.importers.size > 0) return;
|
|
98
|
+
const stencilPlugin = server.config.plugins.find((p) => p.name === UNPLUGIN_STENCIL_NAME);
|
|
99
|
+
if (!stencilPlugin || typeof stencilPlugin.transform !== "function") return;
|
|
100
|
+
lazyBuildPending = true;
|
|
101
|
+
try {
|
|
102
|
+
const code = (0, fs.readFileSync)(file, "utf-8");
|
|
103
|
+
await stencilPlugin.transform.call({ resolve: () => null }, code, file);
|
|
104
|
+
} catch {
|
|
105
|
+
lazyBuildPending = false;
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
handleHotUpdate(ctx) {
|
|
110
|
+
const { file, modules } = ctx;
|
|
111
|
+
if (!file.endsWith(".tsx") || file.endsWith(".stories.tsx")) return;
|
|
112
|
+
const mod = modules[0];
|
|
113
|
+
if (mod && mod.importers?.size > 0) return;
|
|
114
|
+
return [];
|
|
115
|
+
},
|
|
116
|
+
async transform(_code, id) {
|
|
117
|
+
if (!devServer) return;
|
|
118
|
+
const cleanId = id.split("?")[0];
|
|
119
|
+
if (!isComponentSource(cleanId)) return;
|
|
120
|
+
if (lazyBuildPending) return;
|
|
121
|
+
sendReload(devServer);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
|
25
125
|
const previewAnnotations = async (input = [], options) => {
|
|
26
126
|
const docsEnabled = Object.keys(await options.presets.apply("docs", {}, options)).length > 0;
|
|
27
127
|
const result = [];
|
package/dist/preset.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preset.cjs","names":["require","input: I","__dirname","core: StorybookConfig['core']","viteFinal: StorybookConfig['viteFinal']","previewAnnotations: StorybookConfig['previewAnnotations']","result: string[]"],"sources":["../src/preset.ts"],"sourcesContent":["/**\n * we can't prefix the Node.js imports with `node:` because it will break\n * within Storybook due to its Vite setup.\n */\nimport { createRequire } from 'module';\nimport { dirname, join } from 'path';\nimport stencil from 'unplugin-stencil/vite';\nimport { fileURLToPath } from 'url';\nimport { mergeConfig } from 'vite';\nimport { StorybookConfig } from './types';\n\nconst require = createRequire(import.meta.url);\nconst getAbsolutePath = <I extends string>(input: I): I => dirname(require.resolve(join(input, 'package.json'))) as any;\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nconst renderer = join(__dirname, 'entry-preview.js');\n\nexport const core: StorybookConfig['core'] = {\n builder: getAbsolutePath('@storybook/builder-vite'),\n renderer,\n};\n\nexport const viteFinal: StorybookConfig['viteFinal'] = async (defaultConfig, { configType }) => {\n const config = mergeConfig(defaultConfig, {\n build: {\n target: 'es2020',\n },\n plugins: [\n stencil({\n rootPath: defaultConfig.root,\n }),\n ],\n });\n if (configType === 'DEVELOPMENT') {\n return mergeConfig(config, {\n build: {\n rollupOptions: {\n external: ['@stencil/core'],\n },\n },\n });\n }\n\n return config;\n};\n\nexport const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input = [], options) => {\n const docsEnabled = Object.keys(await options.presets.apply('docs', {}, options)).length > 0;\n const result: string[] = [];\n\n return result\n .concat(input)\n .concat([renderer, join(__dirname, 'entry-preview-argtypes.js')])\n .concat(docsEnabled ? [join(__dirname, 'entry-preview-docs.js')] : []);\n};\n"],"mappings":";;;;;;;;AAWA,MAAMA,YAAU,0EAA8B;AAC9C,MAAM,kBAAkB,CAAmBC,UAAgB,kBAAQ,UAAQ,QAAQ,eAAK,OAAO,eAAe,CAAC,CAAC;AAEhH,MAAMC,cAAY,kBAAQ,qEAA8B,CAAC;AAEzD,MAAM,WAAW,eAAKA,aAAW,mBAAmB;AAEpD,MAAaC,OAAgC;CAC3C,SAAS,gBAAgB,0BAA0B;CACnD;AACD;AAED,MAAaC,YAA0C,OAAO,eAAe,EAAE,YAAY,KAAK;CAC9F,MAAM,SAAS,sBAAY,eAAe;EACxC,OAAO,EACL,QAAQ,SACT;EACD,SAAS,CACP,mCAAQ,EACN,UAAU,cAAc,KACzB,EAAC,AACH;CACF,EAAC;AACF,KAAI,eAAe,cACjB,QAAO,sBAAY,QAAQ,EACzB,OAAO,EACL,eAAe,EACb,UAAU,CAAC,eAAgB,EAC5B,EACF,EACF,EAAC;AAGJ,QAAO;AACR;AAED,MAAaC,qBAA4D,OAAO,QAAQ,CAAE,GAAE,YAAY;CACtG,MAAM,cAAc,OAAO,KAAK,MAAM,QAAQ,QAAQ,MAAM,QAAQ,CAAE,GAAE,QAAQ,CAAC,CAAC,SAAS;CAC3F,MAAMC,SAAmB,CAAE;AAE3B,QAAO,OACJ,OAAO,MAAM,CACb,OAAO,CAAC,UAAU,eAAKJ,aAAW,4BAA4B,AAAC,EAAC,CAChE,OAAO,cAAc,CAAC,eAAKA,aAAW,wBAAwB,AAAC,IAAG,CAAE,EAAC;AACzE"}
|
|
1
|
+
{"version":3,"file":"preset.cjs","names":["require","input: I","__dirname","core: StorybookConfig['core']","viteFinal: StorybookConfig['viteFinal']","devServer: ViteDevServer | undefined","server: ViteDevServer","sep","id: string","file: string","ctx: HmrContext","previewAnnotations: StorybookConfig['previewAnnotations']","result: string[]"],"sources":["../src/preset.ts"],"sourcesContent":["/**\n * we can't prefix the Node.js imports with `node:` because it will break\n * within Storybook due to its Vite setup.\n */\nimport { readFileSync, utimesSync } from 'fs';\nimport { createRequire } from 'module';\nimport { dirname, join, resolve, sep } from 'path';\nimport { getComponentStyleDependencies, stencilBuildEvents } from '@stencil-community/unplugin-stencil';\nimport stencil from '@stencil-community/unplugin-stencil/vite';\nimport { fileURLToPath } from 'url';\nimport type { HmrContext, Plugin, ViteDevServer } from 'vite';\nimport { mergeConfig } from 'vite';\nimport { StorybookConfig } from './types';\n\nconst require = createRequire(import.meta.url);\nconst getAbsolutePath = <I extends string>(input: I): I => dirname(require.resolve(join(input, 'package.json'))) as any;\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nconst renderer = join(__dirname, 'entry-preview.js');\n\nconst UNPLUGIN_STENCIL_NAME = '@stencil-community/unplugin-stencil';\n\nexport const core: StorybookConfig['core'] = {\n builder: join(getAbsolutePath('@storybook/builder-vite'), 'dist', 'index.js'),\n renderer,\n};\n\nexport const viteFinal: StorybookConfig['viteFinal'] = async (defaultConfig, { configType }) => {\n const config = mergeConfig(defaultConfig, {\n build: {\n target: 'es2020',\n },\n plugins: [\n stencil({\n rootPath: defaultConfig.root,\n }),\n ],\n });\n if (configType === 'DEVELOPMENT') {\n return mergeConfig(config, {\n build: {\n rollupOptions: {\n external: ['@stencil/core'],\n },\n },\n // Don't let Vite watch this plugin's own `dist/`. `tsdown --watch`\n // rewrites those files during plugin development; if Vite picks the\n // change up it re-optimizes deps, bumping the React chunk hash and\n // leaving previously-imported chunks pointing at a torn-down React\n // (`useEffect` becomes null in <DocsContainer>).\n server: {\n watch: {\n ignored: [join(__dirname, '**')],\n },\n },\n plugins: [stencilPreviewReloadPlugin()],\n });\n }\n\n return config;\n};\n\n/**\n * Forces a full preview reload when a Stencil component changes.\n *\n * `customElements.define()` is permanent, so HMR can't swap the new class in —\n * the iframe must reload. We use a custom HMR event (instead of Vite's\n * `full-reload`) because Storybook's story-index watcher races us with its own\n * `vite-app.js` HMR update and cancels plain reloads.\n *\n * - Eager: the .tsx is in Vite's graph; our `transform` hook fires after\n * unplugin-stencil and emits the reload.\n * - Lazy: the .tsx isn't imported, so we run unplugin-stencil ourselves, then\n * reload once `@stencil-community/unplugin-stencil` reports the build\n * finished (its `stencilBuildEvents` emitter, instead of polling dist/esm).\n * - Styles: `@stencil-community/unplugin-stencil` exposes a `style → component`\n * map built from each component's `@Component` decorator (AST-parsed, covers\n * `styleUrl`, `styleUrls` array, and `styleUrls` mode object). When a tracked\n * style file changes we touch every dependent `.tsx` so the eager/lazy paths\n * above pick up the rebuild.\n * - Global style: the same package resolves `stencil.config#globalStyle`; when\n * it changes we touch every known component `.tsx`.\n */\nfunction stencilPreviewReloadPlugin(): Plugin {\n let devServer: ViteDevServer | undefined;\n let lazyBuildPending = false;\n\n const sendReload = (server: ViteDevServer) => {\n server.ws.send({ type: 'custom', event: 'stencil:reload' });\n };\n\n // Match dist/esm module ids on both POSIX and Windows.\n const distEsmFragment = `${sep}dist${sep}esm${sep}`;\n\n const isComponentSource = (id: string): boolean =>\n id.endsWith('.tsx') &&\n !id.endsWith('.stories.tsx') &&\n !id.includes(`${sep}node_modules${sep}`) &&\n !id.includes(`${sep}.storybook${sep}`);\n\n // dist/esm lives outside Vite's watched root, so its module cache never\n // invalidates on its own. Drop it before reloading.\n const invalidateDistEsm = (server: ViteDevServer): void => {\n for (const cached of server.moduleGraph.idToModuleMap.values()) {\n if (cached.id && cached.id.includes(distEsmFragment) && cached.id.endsWith('.js')) {\n server.moduleGraph.invalidateModule(cached);\n }\n }\n };\n\n // Touch a file's mtime so unplugin-stencil recompiles it. The resulting\n // `change` event re-enters the watcher handler and rides the eager/lazy path.\n const touch = (file: string): void => {\n try {\n const now = new Date();\n utimesSync(file, now, now);\n } catch {\n // ignore: best-effort touch\n }\n };\n\n return {\n name: 'stencil-preview-reload',\n\n configureServer(server) {\n devServer = server;\n\n // When unplugin-stencil finishes a (project-wide) Stencil build, the\n // fresh dist/esm chunks are on disk but Vite still has the old versions\n // cached. If we kicked a lazy rebuild, invalidate + reload now.\n stencilBuildEvents.on('buildFinished', () => {\n if (!lazyBuildPending || !devServer) return;\n lazyBuildPending = false;\n invalidateDistEsm(devServer);\n sendReload(devServer);\n });\n\n server.watcher.on('change', async (file: string) => {\n // unplugin-stencil seeds this map at buildStart, so it's populated from\n // the first watcher event for eager, lazy, and globalStyle alike.\n const { byStyle, byComponent, globalStyle } = getComponentStyleDependencies();\n const resolved = resolve(file);\n\n // Global style: baked into every component, so touch every component\n // we know about and let the eager/lazy paths reload.\n if (globalStyle && resolved === globalStyle) {\n for (const componentId of byComponent.keys()) touch(componentId);\n return;\n }\n\n // Component-style change: re-route to every dependent .tsx. Each touch\n // produces a fresh `change` event that flows through the logic below.\n const dependents = byStyle.get(resolved);\n if (dependents && dependents.size > 0) {\n for (const componentId of dependents) touch(componentId);\n return;\n }\n\n if (!file.endsWith('.tsx') || file.endsWith('.stories.tsx')) return;\n\n const mod = server.moduleGraph.getModuleById(file);\n // Eager components are handled by the `transform` hook below.\n if (mod && mod.importers.size > 0) return;\n\n // Lazy: trigger Stencil's build manually. unplugin-stencil's transform\n // resolves before the build flushes to disk, so we set a flag and wait\n // for `stencilBuildEvents.buildFinished` (above) to do the reload.\n const stencilPlugin = server.config.plugins.find((p) => p.name === UNPLUGIN_STENCIL_NAME);\n if (!stencilPlugin || typeof stencilPlugin.transform !== 'function') return;\n\n lazyBuildPending = true;\n try {\n const code = readFileSync(file, 'utf-8');\n await (stencilPlugin.transform as any).call({ resolve: (): null => null }, code, file);\n } catch {\n lazyBuildPending = false;\n }\n });\n },\n\n // Always reload (never HMR) for component .tsx files. Eager modules still\n // need to flow through Vite so unplugin-stencil rebuilds dist.\n handleHotUpdate(ctx: HmrContext) {\n const { file, modules } = ctx;\n if (!file.endsWith('.tsx') || file.endsWith('.stories.tsx')) return;\n const mod = modules[0];\n if (mod && mod.importers?.size > 0) return;\n return [];\n },\n\n async transform(_code, id) {\n if (!devServer) return;\n const cleanId = id.split('?')[0];\n if (!isComponentSource(cleanId)) return;\n if (lazyBuildPending) return;\n sendReload(devServer);\n },\n };\n}\n\nexport const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input = [], options) => {\n const docsEnabled = Object.keys(await options.presets.apply('docs', {}, options)).length > 0;\n const result: string[] = [];\n\n return result\n .concat(input)\n .concat([renderer, join(__dirname, 'entry-preview-argtypes.js')])\n .concat(docsEnabled ? [join(__dirname, 'entry-preview-docs.js')] : []);\n};\n"],"mappings":";;;;;;;;;;AAcA,MAAMA,YAAU,0EAA8B;AAC9C,MAAM,kBAAkB,CAAmBC,UAAgB,kBAAQ,UAAQ,QAAQ,eAAK,OAAO,eAAe,CAAC,CAAC;AAEhH,MAAMC,cAAY,kBAAQ,qEAA8B,CAAC;AAEzD,MAAM,WAAW,eAAKA,aAAW,mBAAmB;AAEpD,MAAM,wBAAwB;AAE9B,MAAaC,OAAgC;CAC3C,SAAS,eAAK,gBAAgB,0BAA0B,EAAE,QAAQ,WAAW;CAC7E;AACD;AAED,MAAaC,YAA0C,OAAO,eAAe,EAAE,YAAY,KAAK;CAC9F,MAAM,SAAS,sBAAY,eAAe;EACxC,OAAO,EACL,QAAQ,SACT;EACD,SAAS,CACP,uDAAQ,EACN,UAAU,cAAc,KACzB,EAAC,AACH;CACF,EAAC;AACF,KAAI,eAAe,cACjB,QAAO,sBAAY,QAAQ;EACzB,OAAO,EACL,eAAe,EACb,UAAU,CAAC,eAAgB,EAC5B,EACF;EAMD,QAAQ,EACN,OAAO,EACL,SAAS,CAAC,eAAKF,aAAW,KAAK,AAAC,EACjC,EACF;EACD,SAAS,CAAC,4BAA4B,AAAC;CACxC,EAAC;AAGJ,QAAO;AACR;;;;;;;;;;;;;;;;;;;;;;AA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cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preset.d.cts","names":[],"sources":["../src/preset.ts"],"sourcesContent":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"preset.d.cts","names":[],"sources":["../src/preset.ts"],"sourcesContent":[],"mappings":";;;cAuBa,MAAM;cAKN,WAAW;AALX,cAkLA,kBAlLqB,EAkLD,eAlLC,CAAA,oBAAA,CAAA;AAKlC"}
|
package/dist/preset.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preset.d.ts","names":[],"sources":["../src/preset.ts"],"sourcesContent":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"preset.d.ts","names":[],"sources":["../src/preset.ts"],"sourcesContent":[],"mappings":";;;cAuBa,MAAM;cAKN,WAAW;AALX,cAkLA,kBAlLqB,EAkLD,eAlLC,CAAA,oBAAA,CAAA;AAKlC"}
|
package/dist/preset.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { readFileSync, utimesSync } from "fs";
|
|
1
2
|
import { createRequire } from "module";
|
|
2
|
-
import { dirname, join } from "path";
|
|
3
|
-
import
|
|
3
|
+
import { dirname, join, resolve, sep } from "path";
|
|
4
|
+
import { getComponentStyleDependencies, stencilBuildEvents } from "@stencil-community/unplugin-stencil";
|
|
5
|
+
import stencil from "@stencil-community/unplugin-stencil/vite";
|
|
4
6
|
import { fileURLToPath } from "url";
|
|
5
7
|
import { mergeConfig } from "vite";
|
|
6
8
|
|
|
@@ -9,8 +11,9 @@ const require = createRequire(import.meta.url);
|
|
|
9
11
|
const getAbsolutePath = (input) => dirname(require.resolve(join(input, "package.json")));
|
|
10
12
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
11
13
|
const renderer = join(__dirname, "entry-preview.js");
|
|
14
|
+
const UNPLUGIN_STENCIL_NAME = "@stencil-community/unplugin-stencil";
|
|
12
15
|
const core = {
|
|
13
|
-
builder: getAbsolutePath("@storybook/builder-vite"),
|
|
16
|
+
builder: join(getAbsolutePath("@storybook/builder-vite"), "dist", "index.js"),
|
|
14
17
|
renderer
|
|
15
18
|
};
|
|
16
19
|
const viteFinal = async (defaultConfig, { configType }) => {
|
|
@@ -18,9 +21,106 @@ const viteFinal = async (defaultConfig, { configType }) => {
|
|
|
18
21
|
build: { target: "es2020" },
|
|
19
22
|
plugins: [stencil({ rootPath: defaultConfig.root })]
|
|
20
23
|
});
|
|
21
|
-
if (configType === "DEVELOPMENT") return mergeConfig(config, {
|
|
24
|
+
if (configType === "DEVELOPMENT") return mergeConfig(config, {
|
|
25
|
+
build: { rollupOptions: { external: ["@stencil/core"] } },
|
|
26
|
+
server: { watch: { ignored: [join(__dirname, "**")] } },
|
|
27
|
+
plugins: [stencilPreviewReloadPlugin()]
|
|
28
|
+
});
|
|
22
29
|
return config;
|
|
23
30
|
};
|
|
31
|
+
/**
|
|
32
|
+
* Forces a full preview reload when a Stencil component changes.
|
|
33
|
+
*
|
|
34
|
+
* `customElements.define()` is permanent, so HMR can't swap the new class in —
|
|
35
|
+
* the iframe must reload. We use a custom HMR event (instead of Vite's
|
|
36
|
+
* `full-reload`) because Storybook's story-index watcher races us with its own
|
|
37
|
+
* `vite-app.js` HMR update and cancels plain reloads.
|
|
38
|
+
*
|
|
39
|
+
* - Eager: the .tsx is in Vite's graph; our `transform` hook fires after
|
|
40
|
+
* unplugin-stencil and emits the reload.
|
|
41
|
+
* - Lazy: the .tsx isn't imported, so we run unplugin-stencil ourselves, then
|
|
42
|
+
* reload once `@stencil-community/unplugin-stencil` reports the build
|
|
43
|
+
* finished (its `stencilBuildEvents` emitter, instead of polling dist/esm).
|
|
44
|
+
* - Styles: `@stencil-community/unplugin-stencil` exposes a `style → component`
|
|
45
|
+
* map built from each component's `@Component` decorator (AST-parsed, covers
|
|
46
|
+
* `styleUrl`, `styleUrls` array, and `styleUrls` mode object). When a tracked
|
|
47
|
+
* style file changes we touch every dependent `.tsx` so the eager/lazy paths
|
|
48
|
+
* above pick up the rebuild.
|
|
49
|
+
* - Global style: the same package resolves `stencil.config#globalStyle`; when
|
|
50
|
+
* it changes we touch every known component `.tsx`.
|
|
51
|
+
*/
|
|
52
|
+
function stencilPreviewReloadPlugin() {
|
|
53
|
+
let devServer;
|
|
54
|
+
let lazyBuildPending = false;
|
|
55
|
+
const sendReload = (server) => {
|
|
56
|
+
server.ws.send({
|
|
57
|
+
type: "custom",
|
|
58
|
+
event: "stencil:reload"
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
const distEsmFragment = `${sep}dist${sep}esm${sep}`;
|
|
62
|
+
const isComponentSource = (id) => id.endsWith(".tsx") && !id.endsWith(".stories.tsx") && !id.includes(`${sep}node_modules${sep}`) && !id.includes(`${sep}.storybook${sep}`);
|
|
63
|
+
const invalidateDistEsm = (server) => {
|
|
64
|
+
for (const cached of server.moduleGraph.idToModuleMap.values()) if (cached.id && cached.id.includes(distEsmFragment) && cached.id.endsWith(".js")) server.moduleGraph.invalidateModule(cached);
|
|
65
|
+
};
|
|
66
|
+
const touch = (file) => {
|
|
67
|
+
try {
|
|
68
|
+
const now = /* @__PURE__ */ new Date();
|
|
69
|
+
utimesSync(file, now, now);
|
|
70
|
+
} catch {}
|
|
71
|
+
};
|
|
72
|
+
return {
|
|
73
|
+
name: "stencil-preview-reload",
|
|
74
|
+
configureServer(server) {
|
|
75
|
+
devServer = server;
|
|
76
|
+
stencilBuildEvents.on("buildFinished", () => {
|
|
77
|
+
if (!lazyBuildPending || !devServer) return;
|
|
78
|
+
lazyBuildPending = false;
|
|
79
|
+
invalidateDistEsm(devServer);
|
|
80
|
+
sendReload(devServer);
|
|
81
|
+
});
|
|
82
|
+
server.watcher.on("change", async (file) => {
|
|
83
|
+
const { byStyle, byComponent, globalStyle } = getComponentStyleDependencies();
|
|
84
|
+
const resolved = resolve(file);
|
|
85
|
+
if (globalStyle && resolved === globalStyle) {
|
|
86
|
+
for (const componentId of byComponent.keys()) touch(componentId);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const dependents = byStyle.get(resolved);
|
|
90
|
+
if (dependents && dependents.size > 0) {
|
|
91
|
+
for (const componentId of dependents) touch(componentId);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (!file.endsWith(".tsx") || file.endsWith(".stories.tsx")) return;
|
|
95
|
+
const mod = server.moduleGraph.getModuleById(file);
|
|
96
|
+
if (mod && mod.importers.size > 0) return;
|
|
97
|
+
const stencilPlugin = server.config.plugins.find((p) => p.name === UNPLUGIN_STENCIL_NAME);
|
|
98
|
+
if (!stencilPlugin || typeof stencilPlugin.transform !== "function") return;
|
|
99
|
+
lazyBuildPending = true;
|
|
100
|
+
try {
|
|
101
|
+
const code = readFileSync(file, "utf-8");
|
|
102
|
+
await stencilPlugin.transform.call({ resolve: () => null }, code, file);
|
|
103
|
+
} catch {
|
|
104
|
+
lazyBuildPending = false;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
},
|
|
108
|
+
handleHotUpdate(ctx) {
|
|
109
|
+
const { file, modules } = ctx;
|
|
110
|
+
if (!file.endsWith(".tsx") || file.endsWith(".stories.tsx")) return;
|
|
111
|
+
const mod = modules[0];
|
|
112
|
+
if (mod && mod.importers?.size > 0) return;
|
|
113
|
+
return [];
|
|
114
|
+
},
|
|
115
|
+
async transform(_code, id) {
|
|
116
|
+
if (!devServer) return;
|
|
117
|
+
const cleanId = id.split("?")[0];
|
|
118
|
+
if (!isComponentSource(cleanId)) return;
|
|
119
|
+
if (lazyBuildPending) return;
|
|
120
|
+
sendReload(devServer);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
24
124
|
const previewAnnotations = async (input = [], options) => {
|
|
25
125
|
const docsEnabled = Object.keys(await options.presets.apply("docs", {}, options)).length > 0;
|
|
26
126
|
const result = [];
|
package/dist/preset.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preset.js","names":["input: I","core: StorybookConfig['core']","viteFinal: StorybookConfig['viteFinal']","previewAnnotations: StorybookConfig['previewAnnotations']","result: string[]"],"sources":["../src/preset.ts"],"sourcesContent":["/**\n * we can't prefix the Node.js imports with `node:` because it will break\n * within Storybook due to its Vite setup.\n */\nimport { createRequire } from 'module';\nimport { dirname, join } from 'path';\nimport stencil from 'unplugin-stencil/vite';\nimport { fileURLToPath } from 'url';\nimport { mergeConfig } from 'vite';\nimport { StorybookConfig } from './types';\n\nconst require = createRequire(import.meta.url);\nconst getAbsolutePath = <I extends string>(input: I): I => dirname(require.resolve(join(input, 'package.json'))) as any;\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nconst renderer = join(__dirname, 'entry-preview.js');\n\nexport const core: StorybookConfig['core'] = {\n builder: getAbsolutePath('@storybook/builder-vite'),\n renderer,\n};\n\nexport const viteFinal: StorybookConfig['viteFinal'] = async (defaultConfig, { configType }) => {\n const config = mergeConfig(defaultConfig, {\n build: {\n target: 'es2020',\n },\n plugins: [\n stencil({\n rootPath: defaultConfig.root,\n }),\n ],\n });\n if (configType === 'DEVELOPMENT') {\n return mergeConfig(config, {\n build: {\n rollupOptions: {\n external: ['@stencil/core'],\n },\n },\n });\n }\n\n return config;\n};\n\nexport const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input = [], options) => {\n const docsEnabled = Object.keys(await options.presets.apply('docs', {}, options)).length > 0;\n const result: string[] = [];\n\n return result\n .concat(input)\n .concat([renderer, join(__dirname, 'entry-preview-argtypes.js')])\n .concat(docsEnabled ? [join(__dirname, 'entry-preview-docs.js')] : []);\n};\n"],"mappings":";;;;;;;AAWA,MAAM,UAAU,cAAc,OAAO,KAAK,IAAI;AAC9C,MAAM,kBAAkB,CAAmBA,UAAgB,QAAQ,QAAQ,QAAQ,KAAK,OAAO,eAAe,CAAC,CAAC;AAEhH,MAAM,YAAY,QAAQ,cAAc,OAAO,KAAK,IAAI,CAAC;AAEzD,MAAM,WAAW,KAAK,WAAW,mBAAmB;AAEpD,MAAaC,OAAgC;CAC3C,SAAS,gBAAgB,0BAA0B;CACnD;AACD;AAED,MAAaC,YAA0C,OAAO,eAAe,EAAE,YAAY,KAAK;CAC9F,MAAM,SAAS,YAAY,eAAe;EACxC,OAAO,EACL,QAAQ,SACT;EACD,SAAS,CACP,QAAQ,EACN,UAAU,cAAc,KACzB,EAAC,AACH;CACF,EAAC;AACF,KAAI,eAAe,cACjB,QAAO,YAAY,QAAQ,EACzB,OAAO,EACL,eAAe,EACb,UAAU,CAAC,eAAgB,EAC5B,EACF,EACF,EAAC;AAGJ,QAAO;AACR;AAED,MAAaC,qBAA4D,OAAO,QAAQ,CAAE,GAAE,YAAY;CACtG,MAAM,cAAc,OAAO,KAAK,MAAM,QAAQ,QAAQ,MAAM,QAAQ,CAAE,GAAE,QAAQ,CAAC,CAAC,SAAS;CAC3F,MAAMC,SAAmB,CAAE;AAE3B,QAAO,OACJ,OAAO,MAAM,CACb,OAAO,CAAC,UAAU,KAAK,WAAW,4BAA4B,AAAC,EAAC,CAChE,OAAO,cAAc,CAAC,KAAK,WAAW,wBAAwB,AAAC,IAAG,CAAE,EAAC;AACzE"}
|
|
1
|
+
{"version":3,"file":"preset.js","names":["input: I","core: StorybookConfig['core']","viteFinal: StorybookConfig['viteFinal']","devServer: ViteDevServer | undefined","server: ViteDevServer","id: string","file: string","ctx: HmrContext","previewAnnotations: StorybookConfig['previewAnnotations']","result: string[]"],"sources":["../src/preset.ts"],"sourcesContent":["/**\n * we can't prefix the Node.js imports with `node:` because it will break\n * within Storybook due to its Vite setup.\n */\nimport { readFileSync, utimesSync } from 'fs';\nimport { createRequire } from 'module';\nimport { dirname, join, resolve, sep } from 'path';\nimport { getComponentStyleDependencies, stencilBuildEvents } from '@stencil-community/unplugin-stencil';\nimport stencil from '@stencil-community/unplugin-stencil/vite';\nimport { fileURLToPath } from 'url';\nimport type { HmrContext, Plugin, ViteDevServer } from 'vite';\nimport { mergeConfig } from 'vite';\nimport { StorybookConfig } from './types';\n\nconst require = createRequire(import.meta.url);\nconst getAbsolutePath = <I extends string>(input: I): I => dirname(require.resolve(join(input, 'package.json'))) as any;\n\nconst __dirname = dirname(fileURLToPath(import.meta.url));\n\nconst renderer = join(__dirname, 'entry-preview.js');\n\nconst UNPLUGIN_STENCIL_NAME = '@stencil-community/unplugin-stencil';\n\nexport const core: StorybookConfig['core'] = {\n builder: join(getAbsolutePath('@storybook/builder-vite'), 'dist', 'index.js'),\n renderer,\n};\n\nexport const viteFinal: StorybookConfig['viteFinal'] = async (defaultConfig, { configType }) => {\n const config = mergeConfig(defaultConfig, {\n build: {\n target: 'es2020',\n },\n plugins: [\n stencil({\n rootPath: defaultConfig.root,\n }),\n ],\n });\n if (configType === 'DEVELOPMENT') {\n return mergeConfig(config, {\n build: {\n rollupOptions: {\n external: ['@stencil/core'],\n },\n },\n // Don't let Vite watch this plugin's own `dist/`. `tsdown --watch`\n // rewrites those files during plugin development; if Vite picks the\n // change up it re-optimizes deps, bumping the React chunk hash and\n // leaving previously-imported chunks pointing at a torn-down React\n // (`useEffect` becomes null in <DocsContainer>).\n server: {\n watch: {\n ignored: [join(__dirname, '**')],\n },\n },\n plugins: [stencilPreviewReloadPlugin()],\n });\n }\n\n return config;\n};\n\n/**\n * Forces a full preview reload when a Stencil component changes.\n *\n * `customElements.define()` is permanent, so HMR can't swap the new class in —\n * the iframe must reload. We use a custom HMR event (instead of Vite's\n * `full-reload`) because Storybook's story-index watcher races us with its own\n * `vite-app.js` HMR update and cancels plain reloads.\n *\n * - Eager: the .tsx is in Vite's graph; our `transform` hook fires after\n * unplugin-stencil and emits the reload.\n * - Lazy: the .tsx isn't imported, so we run unplugin-stencil ourselves, then\n * reload once `@stencil-community/unplugin-stencil` reports the build\n * finished (its `stencilBuildEvents` emitter, instead of polling dist/esm).\n * - Styles: `@stencil-community/unplugin-stencil` exposes a `style → component`\n * map built from each component's `@Component` decorator (AST-parsed, covers\n * `styleUrl`, `styleUrls` array, and `styleUrls` mode object). When a tracked\n * style file changes we touch every dependent `.tsx` so the eager/lazy paths\n * above pick up the rebuild.\n * - Global style: the same package resolves `stencil.config#globalStyle`; when\n * it changes we touch every known component `.tsx`.\n */\nfunction stencilPreviewReloadPlugin(): Plugin {\n let devServer: ViteDevServer | undefined;\n let lazyBuildPending = false;\n\n const sendReload = (server: ViteDevServer) => {\n server.ws.send({ type: 'custom', event: 'stencil:reload' });\n };\n\n // Match dist/esm module ids on both POSIX and Windows.\n const distEsmFragment = `${sep}dist${sep}esm${sep}`;\n\n const isComponentSource = (id: string): boolean =>\n id.endsWith('.tsx') &&\n !id.endsWith('.stories.tsx') &&\n !id.includes(`${sep}node_modules${sep}`) &&\n !id.includes(`${sep}.storybook${sep}`);\n\n // dist/esm lives outside Vite's watched root, so its module cache never\n // invalidates on its own. Drop it before reloading.\n const invalidateDistEsm = (server: ViteDevServer): void => {\n for (const cached of server.moduleGraph.idToModuleMap.values()) {\n if (cached.id && cached.id.includes(distEsmFragment) && cached.id.endsWith('.js')) {\n server.moduleGraph.invalidateModule(cached);\n }\n }\n };\n\n // Touch a file's mtime so unplugin-stencil recompiles it. The resulting\n // `change` event re-enters the watcher handler and rides the eager/lazy path.\n const touch = (file: string): void => {\n try {\n const now = new Date();\n utimesSync(file, now, now);\n } catch {\n // ignore: best-effort touch\n }\n };\n\n return {\n name: 'stencil-preview-reload',\n\n configureServer(server) {\n devServer = server;\n\n // When unplugin-stencil finishes a (project-wide) Stencil build, the\n // fresh dist/esm chunks are on disk but Vite still has the old versions\n // cached. If we kicked a lazy rebuild, invalidate + reload now.\n stencilBuildEvents.on('buildFinished', () => {\n if (!lazyBuildPending || !devServer) return;\n lazyBuildPending = false;\n invalidateDistEsm(devServer);\n sendReload(devServer);\n });\n\n server.watcher.on('change', async (file: string) => {\n // unplugin-stencil seeds this map at buildStart, so it's populated from\n // the first watcher event for eager, lazy, and globalStyle alike.\n const { byStyle, byComponent, globalStyle } = getComponentStyleDependencies();\n const resolved = resolve(file);\n\n // Global style: baked into every component, so touch every component\n // we know about and let the eager/lazy paths reload.\n if (globalStyle && resolved === globalStyle) {\n for (const componentId of byComponent.keys()) touch(componentId);\n return;\n }\n\n // Component-style change: re-route to every dependent .tsx. Each touch\n // produces a fresh `change` event that flows through the logic below.\n const dependents = byStyle.get(resolved);\n if (dependents && dependents.size > 0) {\n for (const componentId of dependents) touch(componentId);\n return;\n }\n\n if (!file.endsWith('.tsx') || file.endsWith('.stories.tsx')) return;\n\n const mod = server.moduleGraph.getModuleById(file);\n // Eager components are handled by the `transform` hook below.\n if (mod && mod.importers.size > 0) return;\n\n // Lazy: trigger Stencil's build manually. unplugin-stencil's transform\n // resolves before the build flushes to disk, so we set a flag and wait\n // for `stencilBuildEvents.buildFinished` (above) to do the reload.\n const stencilPlugin = server.config.plugins.find((p) => p.name === UNPLUGIN_STENCIL_NAME);\n if (!stencilPlugin || typeof stencilPlugin.transform !== 'function') return;\n\n lazyBuildPending = true;\n try {\n const code = readFileSync(file, 'utf-8');\n await (stencilPlugin.transform as any).call({ resolve: (): null => null }, code, file);\n } catch {\n lazyBuildPending = false;\n }\n });\n },\n\n // Always reload (never HMR) for component .tsx files. Eager modules still\n // need to flow through Vite so unplugin-stencil rebuilds dist.\n handleHotUpdate(ctx: HmrContext) {\n const { file, modules } = ctx;\n if (!file.endsWith('.tsx') || file.endsWith('.stories.tsx')) return;\n const mod = modules[0];\n if (mod && mod.importers?.size > 0) return;\n return [];\n },\n\n async transform(_code, id) {\n if (!devServer) return;\n const cleanId = id.split('?')[0];\n if (!isComponentSource(cleanId)) return;\n if (lazyBuildPending) return;\n sendReload(devServer);\n },\n };\n}\n\nexport const previewAnnotations: StorybookConfig['previewAnnotations'] = async (input = [], options) => {\n const docsEnabled = Object.keys(await options.presets.apply('docs', {}, options)).length > 0;\n const result: string[] = [];\n\n return result\n .concat(input)\n .concat([renderer, join(__dirname, 'entry-preview-argtypes.js')])\n .concat(docsEnabled ? [join(__dirname, 'entry-preview-docs.js')] : []);\n};\n"],"mappings":";;;;;;;;;AAcA,MAAM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AC;EACH;EAID,gBAAgBC,KAAiB;GAC/B,MAAM,EAAE,MAAM,SAAS,GAAG;AAC1B,QAAK,KAAK,SAAS,OAAO,IAAI,KAAK,SAAS,eAAe,CAAE;GAC7D,MAAM,MAAM,QAAQ;AACpB,OAAI,OAAO,IAAI,WAAW,OAAO,EAAG;AACpC,UAAO,CAAE;EACV;EAED,MAAM,UAAU,OAAO,IAAI;AACzB,QAAK,UAAW;GAChB,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC;AAC9B,QAAK,kBAAkB,QAAQ,CAAE;AACjC,OAAI,iBAAkB;AACtB,cAAW,UAAU;EACtB;CACF;AACF;AAED,MAAaC,qBAA4D,OAAO,QAAQ,CAAE,GAAE,YAAY;CACtG,MAAM,cAAc,OAAO,KAAK,MAAM,QAAQ,QAAQ,MAAM,QAAQ,CAAE,GAAE,QAAQ,CAAC,CAAC,SAAS;CAC3F,MAAMC,SAAmB,CAAE;AAE3B,QAAO,OACJ,OAAO,MAAM,CACb,OAAO,CAAC,UAAU,KAAK,WAAW,4BAA4B,AAAC,EAAC,CAChE,OAAO,cAAc,CAAC,KAAK,WAAW,wBAAwB,AAAC,IAAG,CAAE,EAAC;AACzE"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-CsX-DzYB.cjs');
|
|
2
|
-
const require_entry_preview = require('./entry-preview-
|
|
2
|
+
const require_entry_preview = require('./entry-preview-BmNVHtoL.cjs');
|
|
3
3
|
const __storybook_global = require_chunk.__toESM(require("@storybook/global"));
|
|
4
4
|
const storybook_preview_api = require_chunk.__toESM(require("storybook/preview-api"));
|
|
5
5
|
|
|
@@ -88,4 +88,4 @@ Object.defineProperty(exports, 'setProjectAnnotations', {
|
|
|
88
88
|
return setProjectAnnotations;
|
|
89
89
|
}
|
|
90
90
|
});
|
|
91
|
-
//# sourceMappingURL=src-
|
|
91
|
+
//# sourceMappingURL=src-C4ce9Ps1.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"src-
|
|
1
|
+
{"version":3,"file":"src-C4ce9Ps1.cjs","names":["tagName: string","customElements: JsonDocs","customElements: any","global","projectAnnotations: NamedOrDefaultProjectAnnotations<any> | NamedOrDefaultProjectAnnotations<any>[]","stencilAnnotations"],"sources":["../src/framework-api.ts","../src/portable-stories.tsx"],"sourcesContent":["import { global } from '@storybook/global';\nimport type { JsonDocs } from '@stencil/core/internal';\n\nexport function isValidComponent(tagName: string) {\n if (!tagName) {\n return false;\n }\n if (typeof tagName === 'string') {\n return true;\n }\n throw new Error('Provided component needs to be a string. e.g. component: \"my-element\"');\n}\n\nexport function isValidMetaData(customElements: JsonDocs) {\n if (!customElements) {\n return false;\n }\n\n if (customElements.components && Array.isArray(customElements.components)) {\n return true;\n }\n \n throw new Error(`You need to setup valid meta data in your stencil.config.js via docs-json output target.`);\n}\n\n/** @param customElements `any` for now as spec is not super stable yet */\nexport function setCustomElements(customElements: any) {\n global.__STORYBOOK_CUSTOM_ELEMENTS__ = customElements;\n}\n\nexport function setCustomElementsManifest(customElements: any) {\n global.__STORYBOOK_CUSTOM_ELEMENTS_MANIFEST__ = customElements;\n}\n\nexport function getCustomElements() {\n return global.__STORYBOOK_CUSTOM_ELEMENTS__ || global.__STORYBOOK_CUSTOM_ELEMENTS_MANIFEST__;\n}\n","import type { NamedOrDefaultProjectAnnotations, NormalizedProjectAnnotations } from 'storybook/internal/types';\n\nimport {\n setProjectAnnotations as originalSetProjectAnnotations,\n setDefaultProjectAnnotations,\n} from 'storybook/preview-api';\n\nimport * as stencilAnnotations from './entry-preview';\nimport type { StencilRenderer } from './types';\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/web-components';\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: NamedOrDefaultProjectAnnotations<any> | NamedOrDefaultProjectAnnotations<any>[],\n): NormalizedProjectAnnotations<StencilRenderer<unknown>> {\n setDefaultProjectAnnotations(stencilAnnotations);\n return originalSetProjectAnnotations(projectAnnotations) as NormalizedProjectAnnotations<StencilRenderer<unknown>>;\n}\n"],"mappings":";;;;;;AAGA,SAAgB,iBAAiBA,SAAiB;AAChD,MAAK,QACH,QAAO;AAET,YAAW,YAAY,SACrB,QAAO;AAET,OAAM,IAAI,MAAM;AACjB;AAED,SAAgB,gBAAgBC,gBAA0B;AACxD,MAAK,eACH,QAAO;AAGT,KAAI,eAAe,cAAc,MAAM,QAAQ,eAAe,WAAW,CACvE,QAAO;AAGT,OAAM,IAAI,OAAO;AAClB;;AAGD,SAAgB,kBAAkBC,gBAAqB;AACrD,2BAAO,gCAAgC;AACxC;AAED,SAAgB,0BAA0BA,gBAAqB;AAC7D,2BAAO,yCAAyC;AACjD;AAED,SAAgB,oBAAoB;AAClC,QAAOC,0BAAO,iCAAiCA,0BAAO;AACvD;;;;;;;;;;;;;;;;;;;;;;;ACPD,SAAgB,sBACdC,oBACwD;AACxD,yDAA6BC,4CAAmB;AAChD,QAAO,iDAA8B,mBAAmB;AACzD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { entry_preview_exports } from "./entry-preview-
|
|
1
|
+
import { entry_preview_exports } from "./entry-preview-Oaye2Q3u.js";
|
|
2
2
|
import { global } from "@storybook/global";
|
|
3
3
|
import { setDefaultProjectAnnotations, setProjectAnnotations } from "storybook/preview-api";
|
|
4
4
|
|
|
@@ -52,4 +52,4 @@ function setProjectAnnotations$1(projectAnnotations) {
|
|
|
52
52
|
|
|
53
53
|
//#endregion
|
|
54
54
|
export { getCustomElements, isValidComponent, isValidMetaData, setCustomElements, setCustomElementsManifest, setProjectAnnotations$1 as setProjectAnnotations };
|
|
55
|
-
//# sourceMappingURL=src-
|
|
55
|
+
//# sourceMappingURL=src-DWOWXEPY.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"src-
|
|
1
|
+
{"version":3,"file":"src-DWOWXEPY.js","names":["tagName: string","customElements: JsonDocs","customElements: any","setProjectAnnotations","projectAnnotations: NamedOrDefaultProjectAnnotations<any> | NamedOrDefaultProjectAnnotations<any>[]","stencilAnnotations"],"sources":["../src/framework-api.ts","../src/portable-stories.tsx"],"sourcesContent":["import { global } from '@storybook/global';\nimport type { JsonDocs } from '@stencil/core/internal';\n\nexport function isValidComponent(tagName: string) {\n if (!tagName) {\n return false;\n }\n if (typeof tagName === 'string') {\n return true;\n }\n throw new Error('Provided component needs to be a string. e.g. component: \"my-element\"');\n}\n\nexport function isValidMetaData(customElements: JsonDocs) {\n if (!customElements) {\n return false;\n }\n\n if (customElements.components && Array.isArray(customElements.components)) {\n return true;\n }\n \n throw new Error(`You need to setup valid meta data in your stencil.config.js via docs-json output target.`);\n}\n\n/** @param customElements `any` for now as spec is not super stable yet */\nexport function setCustomElements(customElements: any) {\n global.__STORYBOOK_CUSTOM_ELEMENTS__ = customElements;\n}\n\nexport function setCustomElementsManifest(customElements: any) {\n global.__STORYBOOK_CUSTOM_ELEMENTS_MANIFEST__ = customElements;\n}\n\nexport function getCustomElements() {\n return global.__STORYBOOK_CUSTOM_ELEMENTS__ || global.__STORYBOOK_CUSTOM_ELEMENTS_MANIFEST__;\n}\n","import type { NamedOrDefaultProjectAnnotations, NormalizedProjectAnnotations } from 'storybook/internal/types';\n\nimport {\n setProjectAnnotations as originalSetProjectAnnotations,\n setDefaultProjectAnnotations,\n} from 'storybook/preview-api';\n\nimport * as stencilAnnotations from './entry-preview';\nimport type { StencilRenderer } from './types';\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/web-components';\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: NamedOrDefaultProjectAnnotations<any> | NamedOrDefaultProjectAnnotations<any>[],\n): NormalizedProjectAnnotations<StencilRenderer<unknown>> {\n setDefaultProjectAnnotations(stencilAnnotations);\n return originalSetProjectAnnotations(projectAnnotations) as NormalizedProjectAnnotations<StencilRenderer<unknown>>;\n}\n"],"mappings":";;;;;AAGA,SAAgB,iBAAiBA,SAAiB;AAChD,MAAK,QACH,QAAO;AAET,YAAW,YAAY,SACrB,QAAO;AAET,OAAM,IAAI,MAAM;AACjB;AAED,SAAgB,gBAAgBC,gBAA0B;AACxD,MAAK,eACH,QAAO;AAGT,KAAI,eAAe,cAAc,MAAM,QAAQ,eAAe,WAAW,CACvE,QAAO;AAGT,OAAM,IAAI,OAAO;AAClB;;AAGD,SAAgB,kBAAkBC,gBAAqB;AACrD,QAAO,gCAAgC;AACxC;AAED,SAAgB,0BAA0BA,gBAAqB;AAC7D,QAAO,yCAAyC;AACjD;AAED,SAAgB,oBAAoB;AAClC,QAAO,OAAO,iCAAiC,OAAO;AACvD;;;;;;;;;;;;;;;;;;;;;;;ACPD,SAAgBC,wBACdC,oBACwD;AACxD,8BAA6BC,sBAAmB;AAChD,QAAO,sBAA8B,mBAAmB;AACzD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stencil/storybook-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Storybook plugin for Stencil",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/stenciljs/storybook",
|
|
@@ -64,17 +64,16 @@
|
|
|
64
64
|
"build": "tsdown"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
|
-
"@
|
|
68
|
-
"@storybook/builder-vite": "^
|
|
67
|
+
"@stencil-community/unplugin-stencil": "^0.5.2",
|
|
68
|
+
"@storybook/builder-vite": "^10.0.0",
|
|
69
69
|
"@storybook/global": "^5.0.0",
|
|
70
|
-
"@storybook/html": "^
|
|
70
|
+
"@storybook/html": "^10.0.0",
|
|
71
71
|
"preact-render-to-string": "^6.5.13",
|
|
72
|
-
"react-docgen-typescript": "^2.4.0"
|
|
73
|
-
"unplugin-stencil": "^0.4.1"
|
|
72
|
+
"react-docgen-typescript": "^2.4.0"
|
|
74
73
|
},
|
|
75
74
|
"peerDependencies": {
|
|
76
75
|
"@stencil/core": "^4.30.0",
|
|
77
|
-
"storybook": "^
|
|
76
|
+
"storybook": "^10.0.0"
|
|
78
77
|
},
|
|
79
78
|
"devDependencies": {
|
|
80
79
|
"@stencil/core": "^4.33.1",
|
package/preset.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file seems to only be necessary for Windows
|
|
2
|
-
export
|
|
2
|
+
export { core, viteFinal, previewAnnotations } from './dist/preset.cjs';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entry-preview-C0ipNwpw.cjs","names":["render: ArgsStoryFn<StencilRenderer<unknown>>","children: any[]","parameters","canvasElement: StencilRenderer<unknown>['canvasElement']","parameters: Parameters","argTypesEnhancers: ArgTypesEnhancer[]","enhanceArgTypes"],"sources":["../src/render.ts","../src/entry-preview.ts"],"sourcesContent":["import { h, render as renderStencil, VNode } from '@stencil/core';\nimport { ArgsStoryFn, RenderContext } from 'storybook/internal/types';\nimport { simulatePageLoad } from 'storybook/preview-api';\n\nimport type { StencilRenderer } from './types';\n\nexport const render: ArgsStoryFn<StencilRenderer<unknown>> = (args, context) => {\n const { component, parameters } = context;\n\n if (Array.isArray(component)) {\n throw new Error('If your story does not contain a render function, you must provide a component property!');\n }\n if (typeof component === 'string' && !customElements.get(component)) {\n throw new Error(\n `Stencil component not found. If you are not lazy loading your components with \\`defineCustomElements()\\` in preview.ts, pass a constructor value for component in your story \\`component: MyComponent\\``,\n );\n } else if (typeof component !== 'string' && !customElements.getName(component)) {\n throw new Error(\n `Stencil component not found. If you are lazy loading your components with \\`defineCustomElements()\\` in preview.ts, pass a string value for component in your story \\`component: 'my-component'\\``,\n );\n }\n const cmpName = typeof component === 'string' ? component : customElements.getName(component);\n\n const children: any[] = Object.entries<VNode>(parameters.slots || []).map(([key, value]) => {\n // if the parameter key is 'default' don't give it a slot name so it renders just as a child\n const slot = key === 'default' ? undefined : key;\n // if the value it s a string, create a vnode with the string as the children\n const child =\n typeof value === 'string'\n ? h(undefined, { slot }, value)\n : {\n ...value,\n $attrs$: {\n ...value.$attrs$,\n slot,\n },\n };\n // if the value is a fragment and it is a named slot, create a span element with the slot name\n child.$tag$ = child.$tag$ || (slot ? 'span' : null);\n return child.$tag$ ? child : child.$children$;\n });\n\n const Component = `${cmpName}`;\n return h(Component, { ...args }, children);\n};\n\nexport function renderToCanvas(\n { storyFn, showMain, storyContext }: RenderContext<StencilRenderer<unknown>>,\n canvasElement: StencilRenderer<unknown>['canvasElement'],\n) {\n const vdom = storyFn();\n showMain();\n\n /**\n * If the component is not automatically registered after import, register it here\n */\n if (storyContext.component && storyContext.component.is && !customElements.get(storyContext.component.is)) {\n customElements.define(storyContext.component.is, storyContext.component);\n }\n\n if (canvasElement.firstChild) {\n canvasElement.removeChild(canvasElement.firstChild);\n }\n\n const element = document.createElement('div');\n canvasElement.appendChild(element);\n renderStencil(vdom, element);\n simulatePageLoad(element);\n}\n","import { enhanceArgTypes } from 'storybook/internal/docs-tools';\nimport type { ArgTypesEnhancer, Parameters } from 'storybook/internal/types';\n\nexport const parameters: Parameters = { renderer: 'stencil' };\n\nexport { render, renderToCanvas } from './render';\n\nexport const argTypesEnhancers: ArgTypesEnhancer[] = [enhanceArgTypes];\n"],"mappings":";;;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,6CAAgB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entry-preview-C1JSJAGq.js","names":["render: ArgsStoryFn<StencilRenderer<unknown>>","children: any[]","parameters","canvasElement: StencilRenderer<unknown>['canvasElement']","parameters: Parameters","argTypesEnhancers: ArgTypesEnhancer[]"],"sources":["../src/render.ts","../src/entry-preview.ts"],"sourcesContent":["import { h, render as renderStencil, VNode } from '@stencil/core';\nimport { ArgsStoryFn, RenderContext } from 'storybook/internal/types';\nimport { simulatePageLoad } from 'storybook/preview-api';\n\nimport type { StencilRenderer } from './types';\n\nexport const render: ArgsStoryFn<StencilRenderer<unknown>> = (args, context) => {\n const { component, parameters } = context;\n\n if (Array.isArray(component)) {\n throw new Error('If your story does not contain a render function, you must provide a component property!');\n }\n if (typeof component === 'string' && !customElements.get(component)) {\n throw new Error(\n `Stencil component not found. If you are not lazy loading your components with \\`defineCustomElements()\\` in preview.ts, pass a constructor value for component in your story \\`component: MyComponent\\``,\n );\n } else if (typeof component !== 'string' && !customElements.getName(component)) {\n throw new Error(\n `Stencil component not found. If you are lazy loading your components with \\`defineCustomElements()\\` in preview.ts, pass a string value for component in your story \\`component: 'my-component'\\``,\n );\n }\n const cmpName = typeof component === 'string' ? component : customElements.getName(component);\n\n const children: any[] = Object.entries<VNode>(parameters.slots || []).map(([key, value]) => {\n // if the parameter key is 'default' don't give it a slot name so it renders just as a child\n const slot = key === 'default' ? undefined : key;\n // if the value it s a string, create a vnode with the string as the children\n const child =\n typeof value === 'string'\n ? h(undefined, { slot }, value)\n : {\n ...value,\n $attrs$: {\n ...value.$attrs$,\n slot,\n },\n };\n // if the value is a fragment and it is a named slot, create a span element with the slot name\n child.$tag$ = child.$tag$ || (slot ? 'span' : null);\n return child.$tag$ ? child : child.$children$;\n });\n\n const Component = `${cmpName}`;\n return h(Component, { ...args }, children);\n};\n\nexport function renderToCanvas(\n { storyFn, showMain, storyContext }: RenderContext<StencilRenderer<unknown>>,\n canvasElement: StencilRenderer<unknown>['canvasElement'],\n) {\n const vdom = storyFn();\n showMain();\n\n /**\n * If the component is not automatically registered after import, register it here\n */\n if (storyContext.component && storyContext.component.is && !customElements.get(storyContext.component.is)) {\n customElements.define(storyContext.component.is, storyContext.component);\n }\n\n if (canvasElement.firstChild) {\n canvasElement.removeChild(canvasElement.firstChild);\n }\n\n const element = document.createElement('div');\n canvasElement.appendChild(element);\n renderStencil(vdom, element);\n simulatePageLoad(element);\n}\n","import { enhanceArgTypes } from 'storybook/internal/docs-tools';\nimport type { ArgTypesEnhancer, Parameters } from 'storybook/internal/types';\n\nexport const parameters: Parameters = { renderer: 'stencil' };\n\nexport { render, renderToCanvas } from './render';\n\nexport const argTypesEnhancers: ArgTypesEnhancer[] = [enhanceArgTypes];\n"],"mappings":";;;;;;;;;;;;;;;AAMA,MAAaA,WAAgD,CAAC,MAAM,YAAY;CAC9E,MAAM,EAAE,WAAW,0BAAY,GAAG;AAElC,KAAI,MAAM,QAAQ,UAAU,CAC1B,OAAM,IAAI,MAAM;AAElB,YAAW,cAAc,aAAa,eAAe,IAAI,UAAU,CACjE,OAAM,IAAI,OACP;iBAEa,cAAc,aAAa,eAAe,QAAQ,UAAU,CAC5E,OAAM,IAAI,OACP;CAGL,MAAM,iBAAiB,cAAc,WAAW,YAAY,eAAe,QAAQ,UAAU;CAE7F,MAAMC,WAAkB,OAAO,QAAeC,aAAW,SAAS,CAAE,EAAC,CAAC,IAAI,CAAC,CAAC,KAAK,MAAM,KAAK;EAE1F,MAAM,OAAO,QAAQ,qBAAwB;EAE7C,MAAM,eACG,UAAU,WACb,UAAa,EAAE,KAAM,GAAE,MAAM,GAC7B;GACE,GAAG;GACH,SAAS;IACP,GAAG,MAAM;IACT;GACD;EACF;AAEP,QAAM,QAAQ,MAAM,UAAU,OAAO,SAAS;AAC9C,SAAO,MAAM,QAAQ,QAAQ,MAAM;CACpC,EAAC;CAEF,MAAM,aAAa,EAAE,QAAQ;AAC7B,QAAO,EAAE,WAAW,EAAE,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