@stencil/storybook-plugin 0.5.4 → 0.5.5

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 CHANGED
@@ -36,6 +36,24 @@ export default config;
36
36
 
37
37
  See the [Storybook Docs](https://storybook.js.org/docs/7.0/qwik/get-started/introduction) for the best documentation on getting started with Storybook.
38
38
 
39
+ ## Autodocs
40
+
41
+ The plugin can automatically generate documentation and argTypes from your Stencil component metadata. In your `.storybook/preview.ts`, import and call `setCustomElementsManifest`:
42
+
43
+ ```tsx
44
+ import { setCustomElementsManifest } from '@stencil/storybook-plugin';
45
+ import customElements from '../dist/custom-elements.json';
46
+
47
+ setCustomElementsManifest(customElements);
48
+ ```
49
+
50
+ This will automatically populate:
51
+ - Component props documentation
52
+ - ArgTypes with proper controls
53
+ - Events documentation
54
+ - Slots documentation
55
+ - CSS custom properties
56
+
39
57
  ## Usage
40
58
 
41
59
  A basic story will look like this:
@@ -105,6 +123,75 @@ export const Primary: Story = {
105
123
  };
106
124
  ```
107
125
 
126
+ ## Source Code Display
127
+
128
+ The plugin supports displaying source code in multiple formats:
129
+
130
+ ### Language Options
131
+
132
+ Set the source language in your story parameters:
133
+
134
+ ```tsx
135
+ export default {
136
+ parameters: {
137
+ docs: {
138
+ source: {
139
+ language: 'html', // or 'jsx', 'tsx'
140
+ },
141
+ },
142
+ },
143
+ } satisfies Meta<MyComponent>;
144
+ ```
145
+
146
+ **HTML format:**
147
+ ```html
148
+ <my-component class="example" first="John"></my-component>
149
+ ```
150
+
151
+ **JSX/TSX format:**
152
+ ```jsx
153
+ <MyComponent className="example" first="John" />
154
+ ```
155
+
156
+ When using `jsx` or `tsx`:
157
+ - Custom elements (with hyphens) are converted to PascalCase: `<my-component>` → `<MyComponent>`
158
+ - Standard HTML elements remain lowercase: `<div>`, `<span>`
159
+ - HTML attributes are converted to JSX equivalents: `class` → `className`, `for` → `htmlFor`, `tabindex` → `tabIndex`
160
+ - Long attribute lists automatically wrap to multiple lines (80 character threshold)
161
+
162
+ ### Global Source Format Control
163
+
164
+ You can add a toolbar control to switch between formats globally:
165
+
166
+ ```tsx
167
+ // .storybook/preview.tsx
168
+ export const globalTypes = {
169
+ source: {
170
+ name: 'Source Format',
171
+ defaultValue: 'html',
172
+ description: 'Select the source format',
173
+ toolbar: {
174
+ items: ['html', 'jsx', 'tsx'],
175
+ icon: 'markup',
176
+ showName: true,
177
+ dynamicTitle: true,
178
+ },
179
+ },
180
+ };
181
+
182
+ export const decorators = [
183
+ (story, context) => {
184
+ const sourceLanguage = context.globals.source || 'html';
185
+ context.parameters.docs = context.parameters.docs || {};
186
+ context.parameters.docs.source = context.parameters.docs.source || {};
187
+ context.parameters.docs.source.language = sourceLanguage;
188
+ return story();
189
+ },
190
+ ];
191
+ ```
192
+
193
+ This adds a "Source Format" dropdown to the Storybook toolbar, allowing you to switch between HTML and JSX/TSX display on the fly.
194
+
108
195
  ### Troubleshooting
109
196
 
110
197
  If you encounter any issues with the story rendering, please check the following:
@@ -1,4 +1,4 @@
1
- const require_docs = require('../docs-C41e1jpq.cjs');
1
+ const require_docs = require('../docs-ONVKsKI9.cjs');
2
2
 
3
- exports.renderHTML = require_docs.renderHTML;
3
+ exports.renderVNode = require_docs.renderVNode;
4
4
  exports.sourceDecorator = require_docs.sourceDecorator;
@@ -2,14 +2,14 @@ import { StencilRenderer } from "../types-BZP9npQ9.cjs";
2
2
  import { VNode } from "@stencil/core";
3
3
  import { DecoratorFunction } from "storybook/internal/types";
4
4
 
5
- //#region src/docs/render-html.d.ts
6
- declare const renderHTML: (vnode: VNode) => string;
7
- //# sourceMappingURL=render-html.d.ts.map
5
+ //#region src/docs/render-vnode.d.ts
6
+ type RenderMode = 'html' | 'jsx';
7
+ declare const renderVNode: (vnode: VNode, mode: RenderMode) => string;
8
8
  //#endregion
9
9
  //#region src/docs/source-decorator.d.ts
10
10
  declare const sourceDecorator: DecoratorFunction<StencilRenderer<unknown>>;
11
11
  //# sourceMappingURL=source-decorator.d.ts.map
12
12
 
13
13
  //#endregion
14
- export { renderHTML, sourceDecorator };
14
+ export { renderVNode, sourceDecorator };
15
15
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/docs/render-html.ts","../../src/docs/source-decorator.ts"],"sourcesContent":[],"mappings":";;;;;cAqCa,oBAAqB;;;;cCpBrB,iBAAiB,kBAAkB"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../../src/docs/render-vnode.ts","../../src/docs/source-decorator.ts"],"sourcesContent":[],"mappings":";;;;;KAEK,UAAA;cA2HQ,qBAAsB,aAAa;;;cC5GnC,iBAAiB,kBAAkB"}
@@ -2,14 +2,14 @@ import { StencilRenderer } from "../types-DqHtEV5w.js";
2
2
  import { VNode } from "@stencil/core";
3
3
  import { DecoratorFunction } from "storybook/internal/types";
4
4
 
5
- //#region src/docs/render-html.d.ts
6
- declare const renderHTML: (vnode: VNode) => string;
7
- //# sourceMappingURL=render-html.d.ts.map
5
+ //#region src/docs/render-vnode.d.ts
6
+ type RenderMode = 'html' | 'jsx';
7
+ declare const renderVNode: (vnode: VNode, mode: RenderMode) => string;
8
8
  //#endregion
9
9
  //#region src/docs/source-decorator.d.ts
10
10
  declare const sourceDecorator: DecoratorFunction<StencilRenderer<unknown>>;
11
11
  //# sourceMappingURL=source-decorator.d.ts.map
12
12
 
13
13
  //#endregion
14
- export { renderHTML, sourceDecorator };
14
+ export { renderVNode, sourceDecorator };
15
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/docs/render-html.ts","../../src/docs/source-decorator.ts"],"sourcesContent":[],"mappings":";;;;;cAqCa,oBAAqB;;;;cCpBrB,iBAAiB,kBAAkB"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/docs/render-vnode.ts","../../src/docs/source-decorator.ts"],"sourcesContent":[],"mappings":";;;;;KAEK,UAAA;cA2HQ,qBAAsB,aAAa;;;cC5GnC,iBAAiB,kBAAkB"}
@@ -1,3 +1,3 @@
1
- import { renderHTML, sourceDecorator } from "../docs-ObZ8znBB.js";
1
+ import { renderVNode, sourceDecorator } from "../docs-DFb4MYCm.js";
2
2
 
3
- export { renderHTML, sourceDecorator };
3
+ export { renderVNode, sourceDecorator };
@@ -0,0 +1,85 @@
1
+ import { SourceType } from "storybook/internal/docs-tools";
2
+ import { emitTransformCode, useEffect } from "storybook/internal/preview-api";
3
+
4
+ //#region src/docs/render-vnode.ts
5
+ function kebabToPascal(str) {
6
+ return str.split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
7
+ }
8
+ function vnodeToString(node, options, indentLevel = 0) {
9
+ const LINE_WIDTH = 80;
10
+ const indent = " ".repeat(indentLevel);
11
+ const { mode } = options;
12
+ if (node.$text$ !== null) return indent + node.$text$;
13
+ if (node.$tag$ === null) return "";
14
+ const tag = mode === "jsx" && typeof node.$tag$ === "string" && node.$tag$.includes("-") ? kebabToPascal(node.$tag$) : String(node.$tag$);
15
+ const attrArray = node.$attrs$ ? Object.entries(node.$attrs$).filter(([_, value]) => value !== void 0).map(([key, value]) => {
16
+ let attrName = key;
17
+ if (mode === "jsx") {
18
+ const htmlToJsx = {
19
+ class: "className",
20
+ for: "htmlFor",
21
+ tabindex: "tabIndex"
22
+ };
23
+ attrName = htmlToJsx[key] || key;
24
+ }
25
+ if (typeof value === "function") return "";
26
+ if (typeof value === "boolean") return value ? attrName : "";
27
+ if (typeof value === "string") return `${attrName}="${value}"`;
28
+ if (mode === "jsx") return `${attrName}={${JSON.stringify(value)}}`;
29
+ return `${attrName}="${value}"`;
30
+ }).filter((attr) => attr.trim()) : [];
31
+ const children = node.$children$ ?? [];
32
+ if (children.length === 0) {
33
+ const attrsStr$1 = attrArray.length > 0 ? " " + attrArray.join(" ") : "";
34
+ const singleLine = mode === "jsx" ? `${indent}<${tag}${attrsStr$1} />` : `${indent}<${tag}${attrsStr$1}></${tag}>`;
35
+ if (singleLine.length <= LINE_WIDTH) return singleLine;
36
+ const attrIndent$1 = indent + " ";
37
+ const formattedAttrs$1 = attrArray.length > 0 ? "\n" + attrArray.map((attr) => `${attrIndent$1}${attr}`).join("\n") + "\n" + indent : "";
38
+ return mode === "jsx" ? `${indent}<${tag}${formattedAttrs$1}/>` : `${indent}<${tag}${formattedAttrs$1}></${tag}>`;
39
+ }
40
+ const attrsStr = attrArray.length > 0 ? " " + attrArray.join(" ") : "";
41
+ const openingTag = `${indent}<${tag}${attrsStr}>`;
42
+ if (openingTag.length <= LINE_WIDTH) {
43
+ const childrenString$1 = children.map((child) => vnodeToString(child, options, indentLevel + 1)).join("\n");
44
+ return `${openingTag}\n${childrenString$1}\n${indent}</${tag}>`;
45
+ }
46
+ const attrIndent = indent + " ";
47
+ const formattedAttrs = attrArray.length > 0 ? "\n" + attrArray.map((attr) => `${attrIndent}${attr}`).join("\n") + "\n" + indent : "";
48
+ const childrenString = children.map((child) => vnodeToString(child, options, indentLevel + 1)).join("\n");
49
+ return `${indent}<${tag}${formattedAttrs}>\n${childrenString}\n${indent}</${tag}>`;
50
+ }
51
+ const renderVNode = (vnode, mode) => {
52
+ return vnodeToString(vnode, { mode });
53
+ };
54
+
55
+ //#endregion
56
+ //#region src/docs/source-decorator.ts
57
+ const skip = (context) => {
58
+ const sourceParams = context?.parameters.docs?.source;
59
+ const isArgsStory = context?.parameters.__isArgsStory;
60
+ if (sourceParams.type === SourceType.DYNAMIC) return false;
61
+ return !isArgsStory || sourceParams?.code || sourceParams?.type === SourceType.CODE;
62
+ };
63
+ const sourceDecorator = (storyFn, context) => {
64
+ const story = storyFn();
65
+ useEffect(() => {
66
+ const renderedForSource = context?.parameters.docs?.source?.excludeDecorators ? context.originalStoryFn(context.args, context) : story;
67
+ if (skip(context)) return;
68
+ switch (context.parameters.docs.source.language) {
69
+ case "html": {
70
+ emitTransformCode(renderVNode(renderedForSource, "html"), context);
71
+ break;
72
+ }
73
+ case "jsx":
74
+ case "tsx": {
75
+ emitTransformCode(renderVNode(renderedForSource, "jsx"), context);
76
+ break;
77
+ }
78
+ }
79
+ });
80
+ return story;
81
+ };
82
+
83
+ //#endregion
84
+ export { renderVNode, sourceDecorator };
85
+ //# sourceMappingURL=docs-DFb4MYCm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docs-DFb4MYCm.js","names":["str: string","node: VNode","options: RenderOptions","htmlToJsx: Record<string, string>","attrsStr","attrIndent","formattedAttrs","childrenString","vnode: VNode","mode: RenderMode","context: Parameters<DecoratorFunction<StencilRenderer<unknown>>>[1]","sourceDecorator: DecoratorFunction<StencilRenderer<unknown>>"],"sources":["../src/docs/render-vnode.ts","../src/docs/source-decorator.ts"],"sourcesContent":["import { type VNode } from '@stencil/core';\n\ntype RenderMode = 'html' | 'jsx';\n\ninterface RenderOptions {\n mode: RenderMode;\n}\n\nfunction kebabToPascal(str: string): string {\n return str\n .split('-')\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join('');\n}\n\nfunction vnodeToString(node: VNode, options: RenderOptions, indentLevel = 0): string {\n const LINE_WIDTH = 80;\n const indent = ' '.repeat(indentLevel);\n const { mode } = options;\n\n if (node.$text$ !== null) {\n return indent + node.$text$;\n }\n\n if (node.$tag$ === null) {\n return '';\n }\n\n // Convert tag name based on mode\n // Only convert to PascalCase if it's a custom element (has a dash)\n const tag =\n mode === 'jsx' && typeof node.$tag$ === 'string' && node.$tag$.includes('-')\n ? kebabToPascal(node.$tag$)\n : String(node.$tag$);\n\n // Process attributes as array (without leading spaces)\n const attrArray = node.$attrs$\n ? Object.entries(node.$attrs$)\n .filter(([_, value]) => value !== undefined)\n .map(([key, value]) => {\n // Convert HTML attributes to JSX equivalents\n let attrName = key;\n if (mode === 'jsx') {\n // Common HTML to JSX attribute conversions\n const htmlToJsx: Record<string, string> = {\n class: 'className',\n for: 'htmlFor',\n tabindex: 'tabIndex',\n };\n attrName = htmlToJsx[key] || key;\n }\n\n if (typeof value === 'function') {\n // Hide event handlers from source code\n return '';\n }\n\n if (typeof value === 'boolean') {\n return value ? attrName : '';\n }\n\n if (typeof value === 'string') {\n return `${attrName}=\"${value}\"`;\n }\n\n // For JSX, use curly braces for non-string values\n if (mode === 'jsx') {\n return `${attrName}={${JSON.stringify(value)}}`;\n }\n\n // For HTML, convert to string\n return `${attrName}=\"${value}\"`;\n })\n .filter((attr) => attr.trim())\n : [];\n\n const children = node.$children$ ?? [];\n\n // Self-closing tags for JSX when no children\n if (children.length === 0) {\n const attrsStr = attrArray.length > 0 ? ' ' + attrArray.join(' ') : '';\n const singleLine = mode === 'jsx'\n ? `${indent}<${tag}${attrsStr} />`\n : `${indent}<${tag}${attrsStr}></${tag}>`;\n\n // If single line fits within LINE_WIDTH, use it\n if (singleLine.length <= LINE_WIDTH) {\n return singleLine;\n }\n\n // Otherwise, break attributes to multiple lines\n const attrIndent = indent + ' ';\n const formattedAttrs = attrArray.length > 0\n ? '\\n' + attrArray.map((attr) => `${attrIndent}${attr}`).join('\\n') + '\\n' + indent\n : '';\n\n return mode === 'jsx'\n ? `${indent}<${tag}${formattedAttrs}/>`\n : `${indent}<${tag}${formattedAttrs}></${tag}>`;\n }\n\n // Tags with children\n const attrsStr = attrArray.length > 0 ? ' ' + attrArray.join(' ') : '';\n const openingTag = `${indent}<${tag}${attrsStr}>`;\n\n // Check if opening tag fits on one line\n if (openingTag.length <= LINE_WIDTH) {\n const childrenString = children\n .map((child) => vnodeToString(child, options, indentLevel + 1))\n .join('\\n');\n return `${openingTag}\\n${childrenString}\\n${indent}</${tag}>`;\n }\n\n // Break opening tag to multiple lines\n const attrIndent = indent + ' ';\n const formattedAttrs = attrArray.length > 0\n ? '\\n' + attrArray.map((attr) => `${attrIndent}${attr}`).join('\\n') + '\\n' + indent\n : '';\n const childrenString = children\n .map((child) => vnodeToString(child, options, indentLevel + 1))\n .join('\\n');\n\n return `${indent}<${tag}${formattedAttrs}>\\n${childrenString}\\n${indent}</${tag}>`;\n}\n\nexport const renderVNode = (vnode: VNode, mode: RenderMode) => {\n return vnodeToString(vnode, { mode });\n};\n","import { SourceType } from 'storybook/internal/docs-tools';\nimport { emitTransformCode, useEffect } from 'storybook/internal/preview-api';\nimport type { AnnotatedStoryFn, Args, DecoratorFunction } from 'storybook/internal/types';\nimport type { StencilRenderer } from '../types';\nimport { renderVNode } from './render-vnode';\n\ntype StoryFn<TArgs = Args> = AnnotatedStoryFn<StencilRenderer<unknown>, TArgs>;\n\nconst skip = (context: Parameters<DecoratorFunction<StencilRenderer<unknown>>>[1]) => {\n const sourceParams = context?.parameters.docs?.source;\n const isArgsStory = context?.parameters.__isArgsStory;\n\n if (sourceParams.type === SourceType.DYNAMIC) return false;\n\n return !isArgsStory || sourceParams?.code || sourceParams?.type === SourceType.CODE;\n};\n\nexport const sourceDecorator: DecoratorFunction<StencilRenderer<unknown>> = (storyFn, context) => {\n const story = storyFn();\n\n useEffect(() => {\n const renderedForSource = context?.parameters.docs?.source?.excludeDecorators\n ? (context.originalStoryFn as StoryFn)(context.args, context)\n : story;\n\n if (skip(context)) return;\n\n switch (context.parameters.docs.source.language) {\n case 'html': {\n emitTransformCode(renderVNode(renderedForSource, 'html'), context);\n break;\n }\n case 'jsx':\n case 'tsx': {\n emitTransformCode(renderVNode(renderedForSource, 'jsx'), context);\n break;\n }\n }\n });\n\n return story;\n};\n"],"mappings":";;;;AAQA,SAAS,cAAcA,KAAqB;AAC1C,QAAO,IACJ,MAAM,IAAI,CACV,IAAI,CAAC,SAAS,KAAK,OAAO,EAAE,CAAC,aAAa,GAAG,KAAK,MAAM,EAAE,CAAC,CAC3D,KAAK,GAAG;AACZ;AAED,SAAS,cAAcC,MAAaC,SAAwB,cAAc,GAAW;CACnF,MAAM,aAAa;CACnB,MAAM,SAAS,KAAK,OAAO,YAAY;CACvC,MAAM,EAAE,MAAM,GAAG;AAEjB,KAAI,KAAK,WAAW,KAClB,QAAO,SAAS,KAAK;AAGvB,KAAI,KAAK,UAAU,KACjB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I,KAAK,QAAQ,CAAE;AAEnB,UAAQ,QAAQ,WAAW,KAAK,OAAO,UAAvC;GACE,KAAK,QAAQ;AACX,sBAAkB,YAAY,mBAAmB,OAAO,EAAE,QAAQ;AAClE;GACD;GACD,KAAK;GACL,KAAK,OAAO;AACV,sBAAkB,YAAY,mBAAmB,MAAM,EAAE,QAAQ;AACjE;GACD;EACF;CACF,EAAC;AAEF,QAAO;AACR"}
@@ -0,0 +1,97 @@
1
+ const require_chunk = require('./chunk-CsX-DzYB.cjs');
2
+ const storybook_internal_docs_tools = require_chunk.__toESM(require("storybook/internal/docs-tools"));
3
+ const storybook_internal_preview_api = require_chunk.__toESM(require("storybook/internal/preview-api"));
4
+
5
+ //#region src/docs/render-vnode.ts
6
+ function kebabToPascal(str) {
7
+ return str.split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
8
+ }
9
+ function vnodeToString(node, options, indentLevel = 0) {
10
+ const LINE_WIDTH = 80;
11
+ const indent = " ".repeat(indentLevel);
12
+ const { mode } = options;
13
+ if (node.$text$ !== null) return indent + node.$text$;
14
+ if (node.$tag$ === null) return "";
15
+ const tag = mode === "jsx" && typeof node.$tag$ === "string" && node.$tag$.includes("-") ? kebabToPascal(node.$tag$) : String(node.$tag$);
16
+ const attrArray = node.$attrs$ ? Object.entries(node.$attrs$).filter(([_, value]) => value !== void 0).map(([key, value]) => {
17
+ let attrName = key;
18
+ if (mode === "jsx") {
19
+ const htmlToJsx = {
20
+ class: "className",
21
+ for: "htmlFor",
22
+ tabindex: "tabIndex"
23
+ };
24
+ attrName = htmlToJsx[key] || key;
25
+ }
26
+ if (typeof value === "function") return "";
27
+ if (typeof value === "boolean") return value ? attrName : "";
28
+ if (typeof value === "string") return `${attrName}="${value}"`;
29
+ if (mode === "jsx") return `${attrName}={${JSON.stringify(value)}}`;
30
+ return `${attrName}="${value}"`;
31
+ }).filter((attr) => attr.trim()) : [];
32
+ const children = node.$children$ ?? [];
33
+ if (children.length === 0) {
34
+ const attrsStr$1 = attrArray.length > 0 ? " " + attrArray.join(" ") : "";
35
+ const singleLine = mode === "jsx" ? `${indent}<${tag}${attrsStr$1} />` : `${indent}<${tag}${attrsStr$1}></${tag}>`;
36
+ if (singleLine.length <= LINE_WIDTH) return singleLine;
37
+ const attrIndent$1 = indent + " ";
38
+ const formattedAttrs$1 = attrArray.length > 0 ? "\n" + attrArray.map((attr) => `${attrIndent$1}${attr}`).join("\n") + "\n" + indent : "";
39
+ return mode === "jsx" ? `${indent}<${tag}${formattedAttrs$1}/>` : `${indent}<${tag}${formattedAttrs$1}></${tag}>`;
40
+ }
41
+ const attrsStr = attrArray.length > 0 ? " " + attrArray.join(" ") : "";
42
+ const openingTag = `${indent}<${tag}${attrsStr}>`;
43
+ if (openingTag.length <= LINE_WIDTH) {
44
+ const childrenString$1 = children.map((child) => vnodeToString(child, options, indentLevel + 1)).join("\n");
45
+ return `${openingTag}\n${childrenString$1}\n${indent}</${tag}>`;
46
+ }
47
+ const attrIndent = indent + " ";
48
+ const formattedAttrs = attrArray.length > 0 ? "\n" + attrArray.map((attr) => `${attrIndent}${attr}`).join("\n") + "\n" + indent : "";
49
+ const childrenString = children.map((child) => vnodeToString(child, options, indentLevel + 1)).join("\n");
50
+ return `${indent}<${tag}${formattedAttrs}>\n${childrenString}\n${indent}</${tag}>`;
51
+ }
52
+ const renderVNode = (vnode, mode) => {
53
+ return vnodeToString(vnode, { mode });
54
+ };
55
+
56
+ //#endregion
57
+ //#region src/docs/source-decorator.ts
58
+ const skip = (context) => {
59
+ const sourceParams = context?.parameters.docs?.source;
60
+ const isArgsStory = context?.parameters.__isArgsStory;
61
+ if (sourceParams.type === storybook_internal_docs_tools.SourceType.DYNAMIC) return false;
62
+ return !isArgsStory || sourceParams?.code || sourceParams?.type === storybook_internal_docs_tools.SourceType.CODE;
63
+ };
64
+ const sourceDecorator = (storyFn, context) => {
65
+ const story = storyFn();
66
+ (0, storybook_internal_preview_api.useEffect)(() => {
67
+ const renderedForSource = context?.parameters.docs?.source?.excludeDecorators ? context.originalStoryFn(context.args, context) : story;
68
+ if (skip(context)) return;
69
+ switch (context.parameters.docs.source.language) {
70
+ case "html": {
71
+ (0, storybook_internal_preview_api.emitTransformCode)(renderVNode(renderedForSource, "html"), context);
72
+ break;
73
+ }
74
+ case "jsx":
75
+ case "tsx": {
76
+ (0, storybook_internal_preview_api.emitTransformCode)(renderVNode(renderedForSource, "jsx"), context);
77
+ break;
78
+ }
79
+ }
80
+ });
81
+ return story;
82
+ };
83
+
84
+ //#endregion
85
+ Object.defineProperty(exports, 'renderVNode', {
86
+ enumerable: true,
87
+ get: function () {
88
+ return renderVNode;
89
+ }
90
+ });
91
+ Object.defineProperty(exports, 'sourceDecorator', {
92
+ enumerable: true,
93
+ get: function () {
94
+ return sourceDecorator;
95
+ }
96
+ });
97
+ //# sourceMappingURL=docs-ONVKsKI9.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"docs-ONVKsKI9.cjs","names":["str: string","node: VNode","options: RenderOptions","htmlToJsx: Record<string, string>","attrsStr","attrIndent","formattedAttrs","childrenString","vnode: VNode","mode: RenderMode","context: Parameters<DecoratorFunction<StencilRenderer<unknown>>>[1]","SourceType","sourceDecorator: DecoratorFunction<StencilRenderer<unknown>>"],"sources":["../src/docs/render-vnode.ts","../src/docs/source-decorator.ts"],"sourcesContent":["import { type VNode } from '@stencil/core';\n\ntype RenderMode = 'html' | 'jsx';\n\ninterface RenderOptions {\n mode: RenderMode;\n}\n\nfunction kebabToPascal(str: string): string {\n return str\n .split('-')\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join('');\n}\n\nfunction vnodeToString(node: VNode, options: RenderOptions, indentLevel = 0): string {\n const LINE_WIDTH = 80;\n const indent = ' '.repeat(indentLevel);\n const { mode } = options;\n\n if (node.$text$ !== null) {\n return indent + node.$text$;\n }\n\n if (node.$tag$ === null) {\n return '';\n }\n\n // Convert tag name based on mode\n // Only convert to PascalCase if it's a custom element (has a dash)\n const tag =\n mode === 'jsx' && typeof node.$tag$ === 'string' && node.$tag$.includes('-')\n ? kebabToPascal(node.$tag$)\n : String(node.$tag$);\n\n // Process attributes as array (without leading spaces)\n const attrArray = node.$attrs$\n ? Object.entries(node.$attrs$)\n .filter(([_, value]) => value !== undefined)\n .map(([key, value]) => {\n // Convert HTML attributes to JSX equivalents\n let attrName = key;\n if (mode === 'jsx') {\n // Common HTML to JSX attribute conversions\n const htmlToJsx: Record<string, string> = {\n class: 'className',\n for: 'htmlFor',\n tabindex: 'tabIndex',\n };\n attrName = htmlToJsx[key] || key;\n }\n\n if (typeof value === 'function') {\n // Hide event handlers from source code\n return '';\n }\n\n if (typeof value === 'boolean') {\n return value ? attrName : '';\n }\n\n if (typeof value === 'string') {\n return `${attrName}=\"${value}\"`;\n }\n\n // For JSX, use curly braces for non-string values\n if (mode === 'jsx') {\n return `${attrName}={${JSON.stringify(value)}}`;\n }\n\n // For HTML, convert to string\n return `${attrName}=\"${value}\"`;\n })\n .filter((attr) => attr.trim())\n : [];\n\n const children = node.$children$ ?? [];\n\n // Self-closing tags for JSX when no children\n if (children.length === 0) {\n const attrsStr = attrArray.length > 0 ? ' ' + attrArray.join(' ') : '';\n const singleLine = mode === 'jsx'\n ? `${indent}<${tag}${attrsStr} />`\n : `${indent}<${tag}${attrsStr}></${tag}>`;\n\n // If single line fits within LINE_WIDTH, use it\n if (singleLine.length <= LINE_WIDTH) {\n return singleLine;\n }\n\n // Otherwise, break attributes to multiple lines\n const attrIndent = indent + ' ';\n const formattedAttrs = attrArray.length > 0\n ? '\\n' + attrArray.map((attr) => `${attrIndent}${attr}`).join('\\n') + '\\n' + indent\n : '';\n\n return mode === 'jsx'\n ? `${indent}<${tag}${formattedAttrs}/>`\n : `${indent}<${tag}${formattedAttrs}></${tag}>`;\n }\n\n // Tags with children\n const attrsStr = attrArray.length > 0 ? ' ' + attrArray.join(' ') : '';\n const openingTag = `${indent}<${tag}${attrsStr}>`;\n\n // Check if opening tag fits on one line\n if (openingTag.length <= LINE_WIDTH) {\n const childrenString = children\n .map((child) => vnodeToString(child, options, indentLevel + 1))\n .join('\\n');\n return `${openingTag}\\n${childrenString}\\n${indent}</${tag}>`;\n }\n\n // Break opening tag to multiple lines\n const attrIndent = indent + ' ';\n const formattedAttrs = attrArray.length > 0\n ? '\\n' + attrArray.map((attr) => `${attrIndent}${attr}`).join('\\n') + '\\n' + indent\n : '';\n const childrenString = children\n .map((child) => vnodeToString(child, options, indentLevel + 1))\n .join('\\n');\n\n return `${indent}<${tag}${formattedAttrs}>\\n${childrenString}\\n${indent}</${tag}>`;\n}\n\nexport const renderVNode = (vnode: VNode, mode: RenderMode) => {\n return vnodeToString(vnode, { mode });\n};\n","import { SourceType } from 'storybook/internal/docs-tools';\nimport { emitTransformCode, useEffect } from 'storybook/internal/preview-api';\nimport type { AnnotatedStoryFn, Args, DecoratorFunction } from 'storybook/internal/types';\nimport type { StencilRenderer } from '../types';\nimport { renderVNode } from './render-vnode';\n\ntype StoryFn<TArgs = Args> = AnnotatedStoryFn<StencilRenderer<unknown>, TArgs>;\n\nconst skip = (context: Parameters<DecoratorFunction<StencilRenderer<unknown>>>[1]) => {\n const sourceParams = context?.parameters.docs?.source;\n const isArgsStory = context?.parameters.__isArgsStory;\n\n if (sourceParams.type === SourceType.DYNAMIC) return false;\n\n return !isArgsStory || sourceParams?.code || sourceParams?.type === SourceType.CODE;\n};\n\nexport const sourceDecorator: DecoratorFunction<StencilRenderer<unknown>> = (storyFn, context) => {\n const story = storyFn();\n\n useEffect(() => {\n const renderedForSource = context?.parameters.docs?.source?.excludeDecorators\n ? (context.originalStoryFn as StoryFn)(context.args, context)\n : story;\n\n if (skip(context)) return;\n\n switch (context.parameters.docs.source.language) {\n case 'html': {\n emitTransformCode(renderVNode(renderedForSource, 'html'), context);\n break;\n }\n case 'jsx':\n case 'tsx': {\n emitTransformCode(renderVNode(renderedForSource, 'jsx'), context);\n break;\n }\n }\n });\n\n return story;\n};\n"],"mappings":";;;;;AAQA,S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AAwE;CACpF,MAAM,eAAe,SAAS,WAAW,MAAM;CAC/C,MAAM,cAAc,SAAS,WAAW;AAExC,KAAI,aAAa,SAASC,yCAAW,QAAS,QAAO;AAErD,SAAQ,eAAe,cAAc,QAAQ,cAAc,SAASA,yCAAW;AAChF;AAED,MAAaC,kBAA+D,CAAC,SAAS,YAAY;CAChG,MAAM,QAAQ,SAAS;AAEvB,+CAAU,MAAM;EACd,MAAM,oBAAoB,SAAS,WAAW,MAAM,QAAQ,oBACxD,AAAC,QAAQ,gBAA4B,QAAQ,MAAM,QAAQ,GAC3D;AAEJ,MAAI,KAAK,QAAQ,CAAE;AAEnB,UAAQ,QAAQ,WAAW,KAAK,OAAO,UAAvC;GACE,KAAK,QAAQ;AACX,0DAAkB,YAAY,mBAAmB,OAAO,EAAE,QAAQ;AAClE;GACD;GACD,KAAK;GACL,KAAK,OAAO;AACV,0DAAkB,YAAY,mBAAmB,MAAM,EAAE,QAAQ;AACjE;GACD;EACF;CACF,EAAC;AAEF,QAAO;AACR"}
@@ -1,5 +1,5 @@
1
1
  const require_chunk = require('./chunk-CsX-DzYB.cjs');
2
- const require_docs = require('./docs-C41e1jpq.cjs');
2
+ const require_docs = require('./docs-ONVKsKI9.cjs');
3
3
  const storybook_internal_docs_tools = require_chunk.__toESM(require("storybook/internal/docs-tools"));
4
4
 
5
5
  //#region src/entry-preview-docs.ts
@@ -8,7 +8,8 @@ const parameters = { docs: {
8
8
  story: { inline: true },
9
9
  source: {
10
10
  type: storybook_internal_docs_tools.SourceType.DYNAMIC,
11
- language: "html"
11
+ language: "html",
12
+ format: "dedent"
12
13
  }
13
14
  } };
14
15
 
@@ -1 +1 @@
1
- {"version":3,"file":"entry-preview-docs.cjs","names":["decorators: DecoratorFunction<StencilRenderer<unknown>>[]","sourceDecorator","parameters: Parameters","SourceType"],"sources":["../src/entry-preview-docs.ts"],"sourcesContent":["import { SourceType } from 'storybook/internal/docs-tools';\nimport type { DecoratorFunction, Parameters } from 'storybook/internal/types';\nimport { sourceDecorator } from './docs';\nimport type { StencilRenderer } from './types';\n\nexport const decorators: DecoratorFunction<StencilRenderer<unknown>>[] = [sourceDecorator];\n\nexport const parameters: Parameters = {\n docs: {\n story: { inline: true },\n source: {\n type: SourceType.DYNAMIC,\n language: 'html',\n },\n },\n};\n"],"mappings":";;;;;AAKA,MAAaA,aAA4D,CAACC,4BAAgB;AAE1F,MAAaC,aAAyB,EACpC,MAAM;CACJ,OAAO,EAAE,QAAQ,KAAM;CACvB,QAAQ;EACN,MAAMC,yCAAW;EACjB,UAAU;CACX;AACF,EACF"}
1
+ {"version":3,"file":"entry-preview-docs.cjs","names":["decorators: DecoratorFunction<StencilRenderer<unknown>>[]","sourceDecorator","parameters: Parameters","SourceType"],"sources":["../src/entry-preview-docs.ts"],"sourcesContent":["import { SourceType } from 'storybook/internal/docs-tools';\nimport type { DecoratorFunction, Parameters } from 'storybook/internal/types';\nimport { sourceDecorator } from './docs';\nimport type { StencilRenderer } from './types';\n\nexport const decorators: DecoratorFunction<StencilRenderer<unknown>>[] = [sourceDecorator];\n\nexport const parameters: Parameters = {\n docs: {\n story: { inline: true },\n source: {\n type: SourceType.DYNAMIC,\n language: 'html',\n format: 'dedent',\n },\n },\n};\n"],"mappings":";;;;;AAKA,MAAaA,aAA4D,CAACC,4BAAgB;AAE1F,MAAaC,aAAyB,EACpC,MAAM;CACJ,OAAO,EAAE,QAAQ,KAAM;CACvB,QAAQ;EACN,MAAMC,yCAAW;EACjB,UAAU;EACV,QAAQ;CACT;AACF,EACF"}
@@ -1,4 +1,4 @@
1
- import { sourceDecorator } from "./docs-ObZ8znBB.js";
1
+ import { sourceDecorator } from "./docs-DFb4MYCm.js";
2
2
  import { SourceType } from "storybook/internal/docs-tools";
3
3
 
4
4
  //#region src/entry-preview-docs.ts
@@ -7,7 +7,8 @@ const parameters = { docs: {
7
7
  story: { inline: true },
8
8
  source: {
9
9
  type: SourceType.DYNAMIC,
10
- language: "html"
10
+ language: "html",
11
+ format: "dedent"
11
12
  }
12
13
  } };
13
14
 
@@ -1 +1 @@
1
- {"version":3,"file":"entry-preview-docs.js","names":["decorators: DecoratorFunction<StencilRenderer<unknown>>[]","parameters: Parameters"],"sources":["../src/entry-preview-docs.ts"],"sourcesContent":["import { SourceType } from 'storybook/internal/docs-tools';\nimport type { DecoratorFunction, Parameters } from 'storybook/internal/types';\nimport { sourceDecorator } from './docs';\nimport type { StencilRenderer } from './types';\n\nexport const decorators: DecoratorFunction<StencilRenderer<unknown>>[] = [sourceDecorator];\n\nexport const parameters: Parameters = {\n docs: {\n story: { inline: true },\n source: {\n type: SourceType.DYNAMIC,\n language: 'html',\n },\n },\n};\n"],"mappings":";;;;AAKA,MAAaA,aAA4D,CAAC,eAAgB;AAE1F,MAAaC,aAAyB,EACpC,MAAM;CACJ,OAAO,EAAE,QAAQ,KAAM;CACvB,QAAQ;EACN,MAAM,WAAW;EACjB,UAAU;CACX;AACF,EACF"}
1
+ {"version":3,"file":"entry-preview-docs.js","names":["decorators: DecoratorFunction<StencilRenderer<unknown>>[]","parameters: Parameters"],"sources":["../src/entry-preview-docs.ts"],"sourcesContent":["import { SourceType } from 'storybook/internal/docs-tools';\nimport type { DecoratorFunction, Parameters } from 'storybook/internal/types';\nimport { sourceDecorator } from './docs';\nimport type { StencilRenderer } from './types';\n\nexport const decorators: DecoratorFunction<StencilRenderer<unknown>>[] = [sourceDecorator];\n\nexport const parameters: Parameters = {\n docs: {\n story: { inline: true },\n source: {\n type: SourceType.DYNAMIC,\n language: 'html',\n format: 'dedent',\n },\n },\n};\n"],"mappings":";;;;AAKA,MAAaA,aAA4D,CAAC,eAAgB;AAE1F,MAAaC,aAAyB,EACpC,MAAM;CACJ,OAAO,EAAE,QAAQ,KAAM;CACvB,QAAQ;EACN,MAAM,WAAW;EACjB,UAAU;EACV,QAAQ;CACT;AACF,EACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stencil/storybook-plugin",
3
- "version": "0.5.4",
3
+ "version": "0.5.5",
4
4
  "description": "Storybook plugin for Stencil",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/stenciljs/storybook",
@@ -1,57 +0,0 @@
1
- const require_chunk = require('./chunk-CsX-DzYB.cjs');
2
- const storybook_internal_docs_tools = require_chunk.__toESM(require("storybook/internal/docs-tools"));
3
- const storybook_internal_preview_api = require_chunk.__toESM(require("storybook/internal/preview-api"));
4
-
5
- //#region src/docs/render-html.ts
6
- function vnodeToHtml(node, indentLevel = 0) {
7
- const indent = " ".repeat(indentLevel);
8
- if (node.$text$ !== null) return indent + node.$text$;
9
- if (node.$tag$ === null) return "";
10
- const tag = node.$tag$;
11
- const attrs = node.$attrs$ ? Object.entries(node.$attrs$).filter(([_, value]) => value !== void 0).map(([key, value]) => {
12
- if (typeof value === "boolean") return value ? ` ${key}` : "";
13
- return ` ${key}="${value}"`;
14
- }).join("") : "";
15
- const children = node.$children$ ?? [];
16
- if (children.length === 0) return `${indent}<${tag}${attrs}></${tag}>`;
17
- const childrenHtml = children.map((child) => vnodeToHtml(child, indentLevel + 1)).join("\n");
18
- return `${indent}<${tag}${attrs}>\n${childrenHtml}\n${indent}</${tag}>`;
19
- }
20
- const renderHTML = (vnode) => {
21
- return vnodeToHtml(vnode);
22
- };
23
-
24
- //#endregion
25
- //#region src/docs/source-decorator.ts
26
- const skip = (context) => {
27
- const sourceParams = context?.parameters.docs?.source;
28
- const isArgsStory = context?.parameters.__isArgsStory;
29
- if (sourceParams.type === storybook_internal_docs_tools.SourceType.DYNAMIC) return false;
30
- return !isArgsStory || sourceParams?.code || sourceParams?.type === storybook_internal_docs_tools.SourceType.CODE;
31
- };
32
- const sourceDecorator = (storyFn, context) => {
33
- const story = storyFn();
34
- (0, storybook_internal_preview_api.useEffect)(() => {
35
- const renderedForSource = context?.parameters.docs?.source?.excludeDecorators ? context.originalStoryFn(context.args, context) : story;
36
- if (skip(context)) return;
37
- switch (context.parameters.docs.source.language) {
38
- case "html": (0, storybook_internal_preview_api.emitTransformCode)(renderHTML(renderedForSource), context);
39
- }
40
- });
41
- return story;
42
- };
43
-
44
- //#endregion
45
- Object.defineProperty(exports, 'renderHTML', {
46
- enumerable: true,
47
- get: function () {
48
- return renderHTML;
49
- }
50
- });
51
- Object.defineProperty(exports, 'sourceDecorator', {
52
- enumerable: true,
53
- get: function () {
54
- return sourceDecorator;
55
- }
56
- });
57
- //# sourceMappingURL=docs-C41e1jpq.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"docs-C41e1jpq.cjs","names":["node: VNode","vnode: VNode","context: Parameters<DecoratorFunction<StencilRenderer<unknown>>>[1]","SourceType","sourceDecorator: DecoratorFunction<StencilRenderer<unknown>>"],"sources":["../src/docs/render-html.ts","../src/docs/source-decorator.ts"],"sourcesContent":["import { type VNode } from '@stencil/core';\n\nfunction vnodeToHtml(node: VNode, indentLevel = 0): string {\n const indent = ' '.repeat(indentLevel);\n\n if (node.$text$ !== null) {\n return indent + node.$text$;\n }\n\n if (node.$tag$ === null) {\n return '';\n }\n\n const tag = node.$tag$;\n const attrs = node.$attrs$\n ? Object.entries(node.$attrs$)\n .filter(([_, value]) => value !== undefined)\n .map(([key, value]) => {\n if (typeof value === 'boolean') {\n return value ? ` ${key}` : '';\n }\n return ` ${key}=\"${value}\"`;\n })\n .join('')\n : '';\n\n const children = node.$children$ ?? [];\n\n if (children.length === 0) {\n return `${indent}<${tag}${attrs}></${tag}>`;\n }\n\n const childrenHtml = children.map((child) => vnodeToHtml(child, indentLevel + 1)).join('\\n');\n\n return `${indent}<${tag}${attrs}>\\n${childrenHtml}\\n${indent}</${tag}>`;\n}\n\nexport const renderHTML = (vnode: VNode) => {\n return vnodeToHtml(vnode);\n};\n","import { SourceType } from 'storybook/internal/docs-tools';\nimport { emitTransformCode, useEffect } from 'storybook/internal/preview-api';\nimport type { AnnotatedStoryFn, Args, DecoratorFunction } from 'storybook/internal/types';\nimport type { StencilRenderer } from '../types';\nimport { renderHTML } from './render-html';\n\ntype StoryFn<TArgs = Args> = AnnotatedStoryFn<StencilRenderer<unknown>, TArgs>;\n\nconst skip = (context: Parameters<DecoratorFunction<StencilRenderer<unknown>>>[1]) => {\n const sourceParams = context?.parameters.docs?.source;\n const isArgsStory = context?.parameters.__isArgsStory;\n\n if (sourceParams.type === SourceType.DYNAMIC) return false;\n\n return !isArgsStory || sourceParams?.code || sourceParams?.type === SourceType.CODE;\n};\n\nexport const sourceDecorator: DecoratorFunction<StencilRenderer<unknown>> = (storyFn, context) => {\n const story = storyFn();\n\n useEffect(() => {\n const renderedForSource = context?.parameters.docs?.source?.excludeDecorators\n ? (context.originalStoryFn as StoryFn)(context.args, context)\n : story;\n\n if (skip(context)) return;\n\n switch (context.parameters.docs.source.language) {\n case 'html': {\n emitTransformCode(renderHTML(renderedForSource), context);\n }\n }\n });\n\n return story;\n};\n"],"mappings":";;;;;AAEA,SAAS,YAAYA,MAAa,cAAc,GAAW;CACzD,MAAM,SAAS,KAAK,OAAO,YAAY;AAEvC,KAAI,KAAK,WAAW,KAClB,QAAO,SAAS,KAAK;AAGvB,KAAI,KAAK,UAAU,KACjB,QAAO;CAGT,MAAM,MAAM,KAAK;CACjB,MAAM,QAAQ,KAAK,UACf,OAAO,QAAQ,KAAK,QAAQ,CACzB,OAAO,CAAC,CAAC,GAAG,MAAM,KAAK,iBAAoB,CAC3C,IAAI,CAAC,CAAC,KAAK,MAAM,KAAK;AACrB,aAAW,UAAU,UACnB,QAAO,SAAS,GAAG,IAAI,IAAI;AAE7B,UAAQ,GAAG,IAAI,IAAI,MAAM;CAC1B,EAAC,CACD,KAAK,GAAG,GACX;CAEJ,MAAM,WAAW,KAAK,cAAc,CAAE;AAEtC,KAAI,SAAS,WAAW,EACtB,SAAQ,EAAE,OAAO,GAAG,IAAI,EAAE,MAAM,KAAK,IAAI;CAG3C,MAAM,eAAe,SAAS,IAAI,CAAC,UAAU,YAAY,OAAO,cAAc,EAAE,CAAC,CAAC,KAAK,KAAK;AAE5F,SAAQ,EAAE,OAAO,GAAG,IAAI,EAAE,MAAM,KAAK,aAAa,IAAI,OAAO,IAAI,IAAI;AACtE;AAED,MAAa,aAAa,CAACC,UAAiB;AAC1C,QAAO,YAAY,MAAM;AAC1B;;;;AC/BD,MAAM,OAAO,CAACC,YAAwE;CACpF,MAAM,eAAe,SAAS,WAAW,MAAM;CAC/C,MAAM,cAAc,SAAS,WAAW;AAExC,KAAI,aAAa,SAASC,yCAAW,QAAS,QAAO;AAErD,SAAQ,eAAe,cAAc,QAAQ,cAAc,SAASA,yCAAW;AAChF;AAED,MAAaC,kBAA+D,CAAC,SAAS,YAAY;CAChG,MAAM,QAAQ,SAAS;AAEvB,+CAAU,MAAM;EACd,MAAM,oBAAoB,SAAS,WAAW,MAAM,QAAQ,oBACxD,AAAC,QAAQ,gBAA4B,QAAQ,MAAM,QAAQ,GAC3D;AAEJ,MAAI,KAAK,QAAQ,CAAE;AAEnB,UAAQ,QAAQ,WAAW,KAAK,OAAO,UAAvC;GACE,KAAK,OACH,uDAAkB,WAAW,kBAAkB,EAAE,QAAQ;EAE5D;CACF,EAAC;AAEF,QAAO;AACR"}
@@ -1,45 +0,0 @@
1
- import { SourceType } from "storybook/internal/docs-tools";
2
- import { emitTransformCode, useEffect } from "storybook/internal/preview-api";
3
-
4
- //#region src/docs/render-html.ts
5
- function vnodeToHtml(node, indentLevel = 0) {
6
- const indent = " ".repeat(indentLevel);
7
- if (node.$text$ !== null) return indent + node.$text$;
8
- if (node.$tag$ === null) return "";
9
- const tag = node.$tag$;
10
- const attrs = node.$attrs$ ? Object.entries(node.$attrs$).filter(([_, value]) => value !== void 0).map(([key, value]) => {
11
- if (typeof value === "boolean") return value ? ` ${key}` : "";
12
- return ` ${key}="${value}"`;
13
- }).join("") : "";
14
- const children = node.$children$ ?? [];
15
- if (children.length === 0) return `${indent}<${tag}${attrs}></${tag}>`;
16
- const childrenHtml = children.map((child) => vnodeToHtml(child, indentLevel + 1)).join("\n");
17
- return `${indent}<${tag}${attrs}>\n${childrenHtml}\n${indent}</${tag}>`;
18
- }
19
- const renderHTML = (vnode) => {
20
- return vnodeToHtml(vnode);
21
- };
22
-
23
- //#endregion
24
- //#region src/docs/source-decorator.ts
25
- const skip = (context) => {
26
- const sourceParams = context?.parameters.docs?.source;
27
- const isArgsStory = context?.parameters.__isArgsStory;
28
- if (sourceParams.type === SourceType.DYNAMIC) return false;
29
- return !isArgsStory || sourceParams?.code || sourceParams?.type === SourceType.CODE;
30
- };
31
- const sourceDecorator = (storyFn, context) => {
32
- const story = storyFn();
33
- useEffect(() => {
34
- const renderedForSource = context?.parameters.docs?.source?.excludeDecorators ? context.originalStoryFn(context.args, context) : story;
35
- if (skip(context)) return;
36
- switch (context.parameters.docs.source.language) {
37
- case "html": emitTransformCode(renderHTML(renderedForSource), context);
38
- }
39
- });
40
- return story;
41
- };
42
-
43
- //#endregion
44
- export { renderHTML, sourceDecorator };
45
- //# sourceMappingURL=docs-ObZ8znBB.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"docs-ObZ8znBB.js","names":["node: VNode","vnode: VNode","context: Parameters<DecoratorFunction<StencilRenderer<unknown>>>[1]","sourceDecorator: DecoratorFunction<StencilRenderer<unknown>>"],"sources":["../src/docs/render-html.ts","../src/docs/source-decorator.ts"],"sourcesContent":["import { type VNode } from '@stencil/core';\n\nfunction vnodeToHtml(node: VNode, indentLevel = 0): string {\n const indent = ' '.repeat(indentLevel);\n\n if (node.$text$ !== null) {\n return indent + node.$text$;\n }\n\n if (node.$tag$ === null) {\n return '';\n }\n\n const tag = node.$tag$;\n const attrs = node.$attrs$\n ? Object.entries(node.$attrs$)\n .filter(([_, value]) => value !== undefined)\n .map(([key, value]) => {\n if (typeof value === 'boolean') {\n return value ? ` ${key}` : '';\n }\n return ` ${key}=\"${value}\"`;\n })\n .join('')\n : '';\n\n const children = node.$children$ ?? [];\n\n if (children.length === 0) {\n return `${indent}<${tag}${attrs}></${tag}>`;\n }\n\n const childrenHtml = children.map((child) => vnodeToHtml(child, indentLevel + 1)).join('\\n');\n\n return `${indent}<${tag}${attrs}>\\n${childrenHtml}\\n${indent}</${tag}>`;\n}\n\nexport const renderHTML = (vnode: VNode) => {\n return vnodeToHtml(vnode);\n};\n","import { SourceType } from 'storybook/internal/docs-tools';\nimport { emitTransformCode, useEffect } from 'storybook/internal/preview-api';\nimport type { AnnotatedStoryFn, Args, DecoratorFunction } from 'storybook/internal/types';\nimport type { StencilRenderer } from '../types';\nimport { renderHTML } from './render-html';\n\ntype StoryFn<TArgs = Args> = AnnotatedStoryFn<StencilRenderer<unknown>, TArgs>;\n\nconst skip = (context: Parameters<DecoratorFunction<StencilRenderer<unknown>>>[1]) => {\n const sourceParams = context?.parameters.docs?.source;\n const isArgsStory = context?.parameters.__isArgsStory;\n\n if (sourceParams.type === SourceType.DYNAMIC) return false;\n\n return !isArgsStory || sourceParams?.code || sourceParams?.type === SourceType.CODE;\n};\n\nexport const sourceDecorator: DecoratorFunction<StencilRenderer<unknown>> = (storyFn, context) => {\n const story = storyFn();\n\n useEffect(() => {\n const renderedForSource = context?.parameters.docs?.source?.excludeDecorators\n ? (context.originalStoryFn as StoryFn)(context.args, context)\n : story;\n\n if (skip(context)) return;\n\n switch (context.parameters.docs.source.language) {\n case 'html': {\n emitTransformCode(renderHTML(renderedForSource), context);\n }\n }\n });\n\n return story;\n};\n"],"mappings":";;;;AAEA,SAAS,YAAYA,MAAa,cAAc,GAAW;CACzD,MAAM,SAAS,KAAK,OAAO,YAAY;AAEvC,KAAI,KAAK,WAAW,KAClB,QAAO,SAAS,KAAK;AAGvB,KAAI,KAAK,UAAU,KACjB,QAAO;CAGT,MAAM,MAAM,KAAK;CACjB,MAAM,QAAQ,KAAK,UACf,OAAO,QAAQ,KAAK,QAAQ,CACzB,OAAO,CAAC,CAAC,GAAG,MAAM,KAAK,iBAAoB,CAC3C,IAAI,CAAC,CAAC,KAAK,MAAM,KAAK;AACrB,aAAW,UAAU,UACnB,QAAO,SAAS,GAAG,IAAI,IAAI;AAE7B,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