@stencil/storybook-plugin 0.5.4 → 0.5.6
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 +87 -0
- package/dist/docs/index.cjs +2 -2
- package/dist/docs/index.d.cts +4 -4
- package/dist/docs/index.d.cts.map +1 -1
- package/dist/docs/index.d.ts +4 -4
- package/dist/docs/index.d.ts.map +1 -1
- package/dist/docs/index.js +2 -2
- package/dist/docs-DFb4MYCm.js +85 -0
- package/dist/docs-DFb4MYCm.js.map +1 -0
- package/dist/docs-ONVKsKI9.cjs +97 -0
- package/dist/docs-ONVKsKI9.cjs.map +1 -0
- package/dist/entry-preview-argtypes.cjs +36 -4
- package/dist/entry-preview-argtypes.cjs.map +1 -1
- package/dist/entry-preview-argtypes.js +36 -4
- package/dist/entry-preview-argtypes.js.map +1 -1
- package/dist/entry-preview-docs.cjs +3 -2
- package/dist/entry-preview-docs.cjs.map +1 -1
- package/dist/entry-preview-docs.js +3 -2
- package/dist/entry-preview-docs.js.map +1 -1
- package/package.json +1 -1
- package/dist/docs-C41e1jpq.cjs +0 -57
- package/dist/docs-C41e1jpq.cjs.map +0 -1
- package/dist/docs-ObZ8znBB.js +0 -45
- package/dist/docs-ObZ8znBB.js.map +0 -1
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:
|
package/dist/docs/index.cjs
CHANGED
package/dist/docs/index.d.cts
CHANGED
|
@@ -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-
|
|
6
|
-
|
|
7
|
-
|
|
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 {
|
|
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-
|
|
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"}
|
package/dist/docs/index.d.ts
CHANGED
|
@@ -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-
|
|
6
|
-
|
|
7
|
-
|
|
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 {
|
|
14
|
+
export { renderVNode, sourceDecorator };
|
|
15
15
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/docs/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/docs/render-
|
|
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"}
|
package/dist/docs/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { renderVNode, sourceDecorator } from "../docs-DFb4MYCm.js";
|
|
2
2
|
|
|
3
|
-
export {
|
|
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,QAAO;CAKT,MAAM,MACJ,SAAS,gBAAgB,KAAK,UAAU,YAAY,KAAK,MAAM,SAAS,IAAI,GACxE,cAAc,KAAK,MAAM,GACzB,OAAO,KAAK,MAAM;CAGxB,MAAM,YAAY,KAAK,UACnB,OAAO,QAAQ,KAAK,QAAQ,CACzB,OAAO,CAAC,CAAC,GAAG,MAAM,KAAK,iBAAoB,CAC3C,IAAI,CAAC,CAAC,KAAK,MAAM,KAAK;EAErB,IAAI,WAAW;AACf,MAAI,SAAS,OAAO;GAElB,MAAMC,YAAoC;IACxC,OAAO;IACP,KAAK;IACL,UAAU;GACX;AACD,cAAW,UAAU,QAAQ;EAC9B;AAED,aAAW,UAAU,WAEnB,QAAO;AAGT,aAAW,UAAU,UACnB,QAAO,QAAQ,WAAW;AAG5B,aAAW,UAAU,SACnB,SAAQ,EAAE,SAAS,IAAI,MAAM;AAI/B,MAAI,SAAS,MACX,SAAQ,EAAE,SAAS,IA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,CAAC,UAAU,cAAc,OAAO,SAAS,cAAc,EAAE,CAAC,CAC9D,KAAK,KAAK;AAEb,SAAQ,EAAE,OAAO,GAAG,IAAI,EAAE,eAAe,KAAK,eAAe,IAAI,OAAO,IAAI,IAAI;AACjF;AAED,MAAa,cAAc,CAACC,OAAcC,SAAqB;AAC7D,QAAO,cAAc,OAAO,EAAE,KAAM,EAAC;AACtC;;;;ACvHD,MAAM,OAAO,CAACC,YAAwE;CACpF,MAAM,eAAe,SAAS,WAAW,MAAM;CAC/C,MAAM,cAAc,SAAS,WAAW;AAExC,KAAI,aAAa,SAAS,WAAW,QAAS,QAAO;AAErD,SAAQ,eAAe,cAAc,QAAQ,cAAc,SAAS,WAAW;AAChF;AAED,MAAaC,kBAA+D,CAAC,SAAS,YAAY;CAChG,MAAM,QAAQ,SAAS;AAEvB,WAAU,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,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,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,QAAO;CAKT,MAAM,MACJ,SAAS,gBAAgB,KAAK,UAAU,YAAY,KAAK,MAAM,SAAS,IAAI,GACxE,cAAc,KAAK,MAAM,GACzB,OAAO,KAAK,MAAM;CAGxB,MAAM,YAAY,KAAK,UACnB,OAAO,QAAQ,KAAK,QAAQ,CACzB,OAAO,CAAC,CAAC,GAAG,MAAM,KAAK,iBAAoB,CAC3C,IAAI,CAAC,CAAC,KAAK,MAAM,KAAK;EAErB,IAAI,WAAW;AACf,MAAI,SAAS,OAAO;GAElB,MAAMC,YAAoC;IACxC,OAAO;IACP,KAAK;IACL,UAAU;GACX;AACD,cAAW,UAAU,QAAQ;EAC9B;AAED,aAAW,UAAU,WAEnB,QAAO;AAGT,aAAW,UAAU,UACnB,QAAO,QAAQ,WAAW;AAG5B,aAAW,UAAU,SACnB,SAAQ,EAAE,SAAS,IAAI,MAAM;AAI/B,MAAI,SAAS,MACX,SAAQ,EAAE,SAAS,IAAI,KAAK,UAAU,MAAM,CAAC;AAI/C,UAAQ,EAAE,SAAS,IAAI,MAAM;CAC9B,EAAC,CACD,OAAO,CAAC,SAAS,KAAK,MAAM,CAAC,GAChC,CAAE;CAEN,MAAM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AAI,IAAI;AACjF;AAED,MAAa,cAAc,CAACC,OAAcC,SAAqB;AAC7D,QAAO,cAAc,OAAO,EAAE,KAAM,EAAC;AACtC;;;;ACvHD,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,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"}
|
|
@@ -54,10 +54,42 @@ const inferControlType = (prop) => {
|
|
|
54
54
|
|
|
55
55
|
//#endregion
|
|
56
56
|
//#region src/docs/custom-elements.ts
|
|
57
|
+
/**
|
|
58
|
+
* Formats docsTags (@deprecated, @see, @since) and appends them to the description
|
|
59
|
+
*/
|
|
60
|
+
const formatDocsTags = (docs, docsTags) => {
|
|
61
|
+
if (!docsTags || docsTags.length === 0) return docs;
|
|
62
|
+
const tagSections = [];
|
|
63
|
+
const deprecationSections = [];
|
|
64
|
+
const deprecatedTags = docsTags.filter((tag) => tag.name === "deprecated");
|
|
65
|
+
if (deprecatedTags.length > 0) deprecatedTags.forEach((tag) => {
|
|
66
|
+
if (tag.text) deprecationSections.push(`**⚠️ DEPRECATED:** ${tag.text}`);
|
|
67
|
+
else deprecationSections.push(`**⚠️ DEPRECATED**`);
|
|
68
|
+
});
|
|
69
|
+
const seeTags = docsTags.filter((tag) => tag.name === "see");
|
|
70
|
+
if (seeTags.length > 0) {
|
|
71
|
+
const seeLinks = seeTags.map((tag) => {
|
|
72
|
+
const url = tag.text?.trim();
|
|
73
|
+
return url ? `[${url}](${url})` : "";
|
|
74
|
+
}).filter(Boolean).join(", ");
|
|
75
|
+
if (seeLinks) tagSections.push(`**See:** ${seeLinks}`);
|
|
76
|
+
}
|
|
77
|
+
const sinceTags = docsTags.filter((tag) => tag.name === "since");
|
|
78
|
+
if (sinceTags.length > 0) {
|
|
79
|
+
const sinceText = sinceTags.map((tag) => tag.text).filter(Boolean).join(", ");
|
|
80
|
+
if (sinceText) tagSections.push(`**Since:** ${sinceText}`);
|
|
81
|
+
}
|
|
82
|
+
const allSections = [
|
|
83
|
+
...deprecationSections,
|
|
84
|
+
docs,
|
|
85
|
+
...tagSections
|
|
86
|
+
].filter(Boolean);
|
|
87
|
+
return allSections.join("\n\n");
|
|
88
|
+
};
|
|
57
89
|
const mapData = (data, category) => data.reduce((acc, item) => {
|
|
58
90
|
acc[item.name] = {
|
|
59
91
|
name: item.name,
|
|
60
|
-
description: item.docs,
|
|
92
|
+
description: formatDocsTags(item.docs, item.docsTags),
|
|
61
93
|
control: false,
|
|
62
94
|
table: { category }
|
|
63
95
|
};
|
|
@@ -66,7 +98,7 @@ const mapData = (data, category) => data.reduce((acc, item) => {
|
|
|
66
98
|
const mapMethods = (methods) => methods.reduce((acc, method) => {
|
|
67
99
|
acc[method.name] = {
|
|
68
100
|
name: method.name,
|
|
69
|
-
description: method.docs,
|
|
101
|
+
description: formatDocsTags(method.docs, method.docsTags),
|
|
70
102
|
control: null,
|
|
71
103
|
type: { name: "function" },
|
|
72
104
|
table: {
|
|
@@ -83,7 +115,7 @@ const mapEvent = (events) => events.reduce((acc, event) => {
|
|
|
83
115
|
name = `on${name.charAt(0).toUpperCase() + name.slice(1)}`;
|
|
84
116
|
acc[name] = {
|
|
85
117
|
name,
|
|
86
|
-
description: event.docs,
|
|
118
|
+
description: formatDocsTags(event.docs, event.docsTags),
|
|
87
119
|
control: null,
|
|
88
120
|
table: {
|
|
89
121
|
category: "events",
|
|
@@ -96,7 +128,7 @@ const mapEvent = (events) => events.reduce((acc, event) => {
|
|
|
96
128
|
const mapProps = (props) => props.reduce((acc, prop) => {
|
|
97
129
|
acc[prop.name] = {
|
|
98
130
|
name: prop.attr || prop.name,
|
|
99
|
-
description: prop.docs,
|
|
131
|
+
description: formatDocsTags(prop.docs, prop.docsTags),
|
|
100
132
|
control: inferControlType(prop),
|
|
101
133
|
table: {
|
|
102
134
|
category: "properties",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry-preview-argtypes.cjs","names":["prop: JsonDocsProp","scalarTypes: SBScalarType['name'][]","data: T[]","category: string","methods: JsonDocsMethod[]","events: JsonDocsEvent[]","chr: string","props: JsonDocsProp[]","tagName: string","manifest: JsonDocs","customElements: JsonDocs","component: any","argTypesEnhancers: ArgTypesEnhancer<StencilRenderer<unknown>>[]","enhanceArgTypes"],"sources":["../src/docs/infer-type.ts","../src/docs/custom-elements.ts","../src/entry-preview-argtypes.ts"],"sourcesContent":["import type { JsonDocsProp } from '@stencil/core/internal';\nimport type { InputType, SBScalarType, SBType } from 'storybook/internal/types';\n\nexport const inferSBType = (prop: JsonDocsProp): SBType => {\n const scalarTypes: SBScalarType['name'][] = ['string', 'number', 'boolean', 'symbol'];\n if (prop.type.toLowerCase() in scalarTypes) {\n return { name: prop.type.toLowerCase(), raw: prop.type, required: prop.required } as SBScalarType;\n }\n\n if (/^\\(.*\\)\\s*=>\\s*.*$/.test(prop.type)) {\n return { name: 'function', raw: prop.type, required: prop.required };\n }\n\n return { name: 'other', value: prop.type, raw: prop.type, required: prop.required };\n};\n\nexport const mapPropOptions = (prop: JsonDocsProp) =>\n prop.values.filter((value) => ['string', 'number'].includes(value.type)).map(({ value }) => value);\n\nexport const inferControlType = (prop: JsonDocsProp): InputType['control'] => {\n switch (prop.type) {\n case 'string':\n case 'string | undefined':\n return { type: 'text' };\n case 'number':\n case 'number | undefined':\n return { type: 'number' };\n case 'boolean':\n case 'boolean | undefined':\n return { type: 'boolean' };\n case 'Date':\n case 'Date | string':\n return { type: 'date' };\n case 'function':\n case 'function | undefined':\n case 'void':\n case 'void | undefined':\n return null;\n default:\n const values = mapPropOptions(prop);\n\n if (values.length === 0) {\n return { type: 'object' };\n }\n if (values.length < 5) {\n return { type: 'radio' };\n }\n return { type: 'select' };\n }\n};\n","import type {\n JsonDocs,\n JsonDocsEvent,\n JsonDocsMethod,\n JsonDocsPart,\n JsonDocsProp,\n JsonDocsSlot,\n JsonDocsStyle,\n} from '@stencil/core/internal';\nimport { logger } from 'storybook/internal/client-logger';\nimport type { ArgTypes } from 'storybook/internal/types';\n\nimport { getCustomElements, isValidComponent, isValidMetaData } from '..';\nimport { inferControlType, inferSBType, mapPropOptions } from './infer-type';\n\nconst mapData = <T extends JsonDocsPart>(data: T[], category: string): ArgTypes =>\n data.reduce<ArgTypes>((acc, item) => {\n acc[item.name] = {\n name: item.name,\n description: item.docs,\n control: false,\n table: {\n category,\n },\n };\n return acc;\n }, {});\n\nconst mapMethods = (methods: JsonDocsMethod[]): ArgTypes =>\n methods.reduce<ArgTypes>((acc, method) => {\n acc[method.name] = {\n name: method.name,\n description: method.docs,\n control: null,\n type: { name: 'function' },\n table: {\n category: 'methods',\n type: { summary: method.signature },\n },\n };\n return acc;\n }, {});\n\nconst mapEvent = (events: JsonDocsEvent[]): ArgTypes =>\n events.reduce<ArgTypes>((acc, event) => {\n let name = event.event\n .replace(/(-|_|:|\\.|\\s)+(.)?/g, (_match, _separator, chr: string) => {\n return chr ? chr.toUpperCase() : '';\n })\n .replace(/^([A-Z])/, (match) => match.toLowerCase());\n\n name = `on${name.charAt(0).toUpperCase() + name.slice(1)}`;\n\n acc[name] = {\n name,\n description: event.docs,\n control: null,\n table: {\n category: 'events',\n type: { summary: event.detail },\n },\n type: { name: 'function' },\n };\n\n return acc;\n }, {});\n\nconst mapProps = (props: JsonDocsProp[]): ArgTypes =>\n props.reduce<ArgTypes>((acc, prop) => {\n acc[prop.name] = {\n name: prop.attr || prop.name,\n description: prop.docs,\n control: inferControlType(prop),\n table: {\n category: 'properties',\n type: { summary: prop.complexType?.original },\n defaultValue: { summary: prop.default },\n },\n options: mapPropOptions(prop),\n type: inferSBType(prop),\n };\n\n return acc;\n }, {});\n\nconst getMetaData = (tagName: string, manifest: JsonDocs) => {\n if (!isValidComponent(tagName) || !isValidMetaData(manifest)) {\n return null;\n }\n const metaData = manifest.components.find((component) => component.tag.toUpperCase() === tagName.toUpperCase());\n if (!metaData) {\n logger.warn(`Component not found in custom-elements.json: ${tagName}`);\n }\n return metaData;\n};\n\nexport const extractArgTypesFromElements = (tagName: string, customElements: JsonDocs) => {\n const metaData = getMetaData(tagName, customElements);\n return (\n metaData && {\n ...mapProps(metaData.props),\n ...mapEvent(metaData.events),\n ...mapMethods(metaData.methods),\n ...mapData<JsonDocsSlot>(metaData.slots, 'slots'),\n ...mapData<JsonDocsPart>(metaData.parts, 'parts'),\n ...mapData<JsonDocsStyle>(metaData.styles, 'styles'),\n }\n );\n};\n\nexport const extractArgTypes = (component: any) => {\n const cem = getCustomElements();\n // Handle both string references (lazy loading) and class references (auto-define)\n const tagName = typeof component === 'string' ? component : component?.is;\n return extractArgTypesFromElements(tagName, cem);\n};\n\nexport const extractComponentDescription = (component: any) => {\n // Handle both string references (lazy loading) and class references (auto-define)\n const tagName = typeof component === 'string' ? component : component?.is;\n const metaData = getMetaData(tagName, getCustomElements());\n return metaData && metaData.docs;\n};\n","import { enhanceArgTypes } from 'storybook/internal/docs-tools';\nimport type { ArgTypesEnhancer } from 'storybook/internal/types';\n\nimport { extractArgTypes, extractComponentDescription } from './docs/custom-elements';\nimport type { StencilRenderer } from './types';\n\nexport const parameters = {\n docs: {\n extractArgTypes,\n extractComponentDescription,\n },\n};\n\nexport const argTypesEnhancers: ArgTypesEnhancer<StencilRenderer<unknown>>[] = [enhanceArgTypes];"],"mappings":";;;;;;;AAGA,MAAa,cAAc,CAACA,SAA+B;CACzD,MAAMC,cAAsC;EAAC;EAAU;EAAU;EAAW;CAAS;AACrF,KAAI,KAAK,KAAK,aAAa,IAAI,YAC7B,QAAO;EAAE,MAAM,KAAK,KAAK,aAAa;EAAE,KAAK,KAAK;EAAM,UAAU,KAAK;CAAU;AAGnF,KAAI,qBAAqB,KAAK,KAAK,KAAK,CACtC,QAAO;EAAE,MAAM;EAAY,KAAK,KAAK;EAAM,UAAU,KAAK;CAAU;AAGtE,QAAO;EAAE,MAAM;EAAS,OAAO,KAAK;EAAM,KAAK,KAAK;EAAM,UAAU,KAAK;CAAU;AACpF;AAED,MAAa,iBAAiB,CAACD,SAC7B,KAAK,OAAO,OAAO,CAAC,UAAU,CAAC,UAAU,QAAS,EAAC,SAAS,MAAM,KAAK,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,KAAK,MAAM;AAEpG,MAAa,mBAAmB,CAACA,SAA6C;AAC5E,SAAQ,KAAK,MAAb;EACE,KAAK;EACL,KAAK,qBACH,QAAO,EAAE,MAAM,OAAQ;EACzB,KAAK;EACL,KAAK,qBACH,QAAO,EAAE,MAAM,SAAU;EAC3B,KAAK;EACL,KAAK,sBACH,QAAO,EAAE,MAAM,UAAW;EAC5B,KAAK;EACL,KAAK,gBACH,QAAO,EAAE,MAAM,OAAQ;EACzB,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,mBACH,QAAO;EACT;GACE,MAAM,SAAS,eAAe,KAAK;AAEnC,OAAI,OAAO,WAAW,EACpB,QAAO,EAAE,MAAM,SAAU;AAE3B,OAAI,OAAO,SAAS,EAClB,QAAO,EAAE,MAAM,QAAS;AAE1B,UAAO,EAAE,MAAM,SAAU;CAC5B;AACF;;;;AClCD,MAAM,UAAU,CAAyBE,MAAWC,aAClD,KAAK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AK;CACxB;AAED,QAAO;AACR,GAAE,CAAE,EAAC;AAER,MAAM,cAAc,CAACC,SAAiBC,aAAuB;AAC3D,MAAK,6BAAiB,QAAQ,KAAK,4BAAgB,SAAS,CAC1D,QAAO;CAET,MAAM,WAAW,SAAS,WAAW,KAAK,CAAC,cAAc,UAAU,IAAI,aAAa,KAAK,QAAQ,aAAa,CAAC;AAC/G,MAAK,SACH,yCAAO,MAAM,+CAA+C,QAAQ,EAAE;AAExE,QAAO;AACR;AAED,MAAa,8BAA8B,CAACD,SAAiBE,mBAA6B;CACxF,MAAM,WAAW,YAAY,SAAS,eAAe;AACrD,QACE,YAAY;EACV,GAAG,SAAS,SAAS,MAAM;EAC3B,GAAG,SAAS,SAAS,OAAO;EAC5B,GAAG,WAAW,SAAS,QAAQ;EAC/B,GAAG,QAAsB,SAAS,OAAO,QAAQ;EACjD,GAAG,QAAsB,SAAS,OAAO,QAAQ;EACjD,GAAG,QAAuB,SAAS,QAAQ,SAAS;CACrD;AAEJ;AAED,MAAa,kBAAkB,CAACC,cAAmB;CACjD,MAAM,MAAM,+BAAmB;CAE/B,MAAM,iBAAiB,cAAc,WAAW,YAAY,WAAW;AACvE,QAAO,4BAA4B,SAAS,IAAI;AACjD;AAED,MAAa,8BAA8B,CAACA,cAAmB;CAE7D,MAAM,iBAAiB,cAAc,WAAW,YAAY,WAAW;CACvE,MAAM,WAAW,YAAY,SAAS,+BAAmB,CAAC;AAC1D,QAAO,YAAY,SAAS;AAC7B;;;;ACpHD,MAAa,aAAa,EACxB,MAAM;CACJ;CACA;AACD,EACF;AAED,MAAaC,oBAAkE,CAACC,6CAAgB"}
|
|
1
|
+
{"version":3,"file":"entry-preview-argtypes.cjs","names":["prop: JsonDocsProp","scalarTypes: SBScalarType['name'][]","docs: string","docsTags?: DocsTag[]","tagSections: string[]","deprecationSections: string[]","data: T[]","category: string","methods: JsonDocsMethod[]","events: JsonDocsEvent[]","chr: string","props: JsonDocsProp[]","tagName: string","manifest: JsonDocs","customElements: JsonDocs","component: any","argTypesEnhancers: ArgTypesEnhancer<StencilRenderer<unknown>>[]","enhanceArgTypes"],"sources":["../src/docs/infer-type.ts","../src/docs/custom-elements.ts","../src/entry-preview-argtypes.ts"],"sourcesContent":["import type { JsonDocsProp } from '@stencil/core/internal';\nimport type { InputType, SBScalarType, SBType } from 'storybook/internal/types';\n\nexport const inferSBType = (prop: JsonDocsProp): SBType => {\n const scalarTypes: SBScalarType['name'][] = ['string', 'number', 'boolean', 'symbol'];\n if (prop.type.toLowerCase() in scalarTypes) {\n return { name: prop.type.toLowerCase(), raw: prop.type, required: prop.required } as SBScalarType;\n }\n\n if (/^\\(.*\\)\\s*=>\\s*.*$/.test(prop.type)) {\n return { name: 'function', raw: prop.type, required: prop.required };\n }\n\n return { name: 'other', value: prop.type, raw: prop.type, required: prop.required };\n};\n\nexport const mapPropOptions = (prop: JsonDocsProp) =>\n prop.values.filter((value) => ['string', 'number'].includes(value.type)).map(({ value }) => value);\n\nexport const inferControlType = (prop: JsonDocsProp): InputType['control'] => {\n switch (prop.type) {\n case 'string':\n case 'string | undefined':\n return { type: 'text' };\n case 'number':\n case 'number | undefined':\n return { type: 'number' };\n case 'boolean':\n case 'boolean | undefined':\n return { type: 'boolean' };\n case 'Date':\n case 'Date | string':\n return { type: 'date' };\n case 'function':\n case 'function | undefined':\n case 'void':\n case 'void | undefined':\n return null;\n default:\n const values = mapPropOptions(prop);\n\n if (values.length === 0) {\n return { type: 'object' };\n }\n if (values.length < 5) {\n return { type: 'radio' };\n }\n return { type: 'select' };\n }\n};\n","import type {\n JsonDocs,\n JsonDocsEvent,\n JsonDocsMethod,\n JsonDocsPart,\n JsonDocsProp,\n JsonDocsSlot,\n JsonDocsStyle,\n} from '@stencil/core/internal';\nimport { logger } from 'storybook/internal/client-logger';\nimport type { ArgTypes } from 'storybook/internal/types';\n\nimport { getCustomElements, isValidComponent, isValidMetaData } from '..';\nimport { inferControlType, inferSBType, mapPropOptions } from './infer-type';\n\ninterface DocsTag {\n name: string;\n text?: string;\n}\n\n/**\n * Formats docsTags (@deprecated, @see, @since) and appends them to the description\n */\nconst formatDocsTags = (docs: string, docsTags?: DocsTag[]): string => {\n if (!docsTags || docsTags.length === 0) {\n return docs;\n }\n\n const tagSections: string[] = [];\n const deprecationSections: string[] = [];\n\n // Handle @deprecated tags - show at the top with emphasis\n const deprecatedTags = docsTags.filter((tag) => tag.name === 'deprecated');\n if (deprecatedTags.length > 0) {\n deprecatedTags.forEach((tag) => {\n if (tag.text) {\n deprecationSections.push(`**⚠️ DEPRECATED:** ${tag.text}`);\n } else {\n deprecationSections.push(`**⚠️ DEPRECATED**`);\n }\n });\n }\n\n // Handle @see tags - create links\n const seeTags = docsTags.filter((tag) => tag.name === 'see');\n if (seeTags.length > 0) {\n const seeLinks = seeTags\n .map((tag) => {\n const url = tag.text?.trim();\n return url ? `[${url}](${url})` : '';\n })\n .filter(Boolean)\n .join(', ');\n if (seeLinks) {\n tagSections.push(`**See:** ${seeLinks}`);\n }\n }\n\n // Handle @since tags\n const sinceTags = docsTags.filter((tag) => tag.name === 'since');\n if (sinceTags.length > 0) {\n const sinceText = sinceTags\n .map((tag) => tag.text)\n .filter(Boolean)\n .join(', ');\n if (sinceText) {\n tagSections.push(`**Since:** ${sinceText}`);\n }\n }\n\n // Combine all sections - deprecation first, then docs, then other tags\n const allSections = [...deprecationSections, docs, ...tagSections].filter(Boolean);\n\n return allSections.join('\\n\\n');\n};\n\nconst mapData = <T extends JsonDocsPart>(data: T[], category: string): ArgTypes =>\n data.reduce<ArgTypes>((acc, item) => {\n acc[item.name] = {\n name: item.name,\n description: formatDocsTags(item.docs, (item as any).docsTags as DocsTag[]),\n control: false,\n table: {\n category,\n },\n };\n return acc;\n }, {});\n\nconst mapMethods = (methods: JsonDocsMethod[]): ArgTypes =>\n methods.reduce<ArgTypes>((acc, method) => {\n acc[method.name] = {\n name: method.name,\n description: formatDocsTags(method.docs, method.docsTags as DocsTag[]),\n control: null,\n type: { name: 'function' },\n table: {\n category: 'methods',\n type: { summary: method.signature },\n },\n };\n return acc;\n }, {});\n\nconst mapEvent = (events: JsonDocsEvent[]): ArgTypes =>\n events.reduce<ArgTypes>((acc, event) => {\n let name = event.event\n .replace(/(-|_|:|\\.|\\s)+(.)?/g, (_match, _separator, chr: string) => {\n return chr ? chr.toUpperCase() : '';\n })\n .replace(/^([A-Z])/, (match) => match.toLowerCase());\n\n name = `on${name.charAt(0).toUpperCase() + name.slice(1)}`;\n\n acc[name] = {\n name,\n description: formatDocsTags(event.docs, event.docsTags as DocsTag[]),\n control: null,\n table: {\n category: 'events',\n type: { summary: event.detail },\n },\n type: { name: 'function' },\n };\n\n return acc;\n }, {});\n\nconst mapProps = (props: JsonDocsProp[]): ArgTypes =>\n props.reduce<ArgTypes>((acc, prop) => {\n acc[prop.name] = {\n name: prop.attr || prop.name,\n description: formatDocsTags(prop.docs, prop.docsTags as DocsTag[]),\n control: inferControlType(prop),\n table: {\n category: 'properties',\n type: { summary: prop.complexType?.original },\n defaultValue: { summary: prop.default },\n },\n options: mapPropOptions(prop),\n type: inferSBType(prop),\n };\n\n return acc;\n }, {});\n\nconst getMetaData = (tagName: string, manifest: JsonDocs) => {\n if (!isValidComponent(tagName) || !isValidMetaData(manifest)) {\n return null;\n }\n const metaData = manifest.components.find((component) => component.tag.toUpperCase() === tagName.toUpperCase());\n if (!metaData) {\n logger.warn(`Component not found in custom-elements.json: ${tagName}`);\n }\n return metaData;\n};\n\nexport const extractArgTypesFromElements = (tagName: string, customElements: JsonDocs) => {\n const metaData = getMetaData(tagName, customElements);\n return (\n metaData && {\n ...mapProps(metaData.props),\n ...mapEvent(metaData.events),\n ...mapMethods(metaData.methods),\n ...mapData<JsonDocsSlot>(metaData.slots, 'slots'),\n ...mapData<JsonDocsPart>(metaData.parts, 'parts'),\n ...mapData<JsonDocsStyle>(metaData.styles, 'styles'),\n }\n );\n};\n\nexport const extractArgTypes = (component: any) => {\n const cem = getCustomElements();\n // Handle both string references (lazy loading) and class references (auto-define)\n const tagName = typeof component === 'string' ? component : component?.is;\n return extractArgTypesFromElements(tagName, cem);\n};\n\nexport const extractComponentDescription = (component: any) => {\n // Handle both string references (lazy loading) and class references (auto-define)\n const tagName = typeof component === 'string' ? component : component?.is;\n const metaData = getMetaData(tagName, getCustomElements());\n return metaData && metaData.docs;\n};\n","import { enhanceArgTypes } from 'storybook/internal/docs-tools';\nimport type { ArgTypesEnhancer } from 'storybook/internal/types';\n\nimport { extractArgTypes, extractComponentDescription } from './docs/custom-elements';\nimport type { StencilRenderer } from './types';\n\nexport const parameters = {\n docs: {\n extractArgTypes,\n extractComponentDescription,\n },\n};\n\nexport const argTypesEnhancers: ArgTypesEnhancer<StencilRenderer<unknown>>[] = [enhanceArgTypes];"],"mappings":";;;;;;;AAGA,MAAa,cAAc,CAACA,SAA+B;CACzD,MAAMC,cAAsC;EAAC;EAAU;EAAU;EAAW;CAAS;AACrF,KAAI,KAAK,KAAK,aAAa,IAAI,YAC7B,QAAO;EAAE,MAAM,KAAK,KAAK,aAAa;EAAE,KAAK,KAAK;EAAM,UAAU,KAAK;CAAU;AAGnF,KAAI,qBAAqB,KAAK,KAAK,KAAK,CACtC,QAAO;EAAE,MAAM;EAAY,KAAK,KAAK;EAAM,UAAU,KAAK;CAAU;AAGtE,QAAO;EAAE,MAAM;EAAS,OAAO,KAAK;EAAM,KAAK,KAAK;EAAM,UAAU,KAAK;CAAU;AACpF;AAED,MAAa,iBAAiB,CAACD,SAC7B,KAAK,OAAO,OAAO,CAAC,UAAU,CAAC,UAAU,QAAS,EAAC,SAAS,MAAM,KAAK,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,KAAK,MAAM;AAEpG,MAAa,mBAAmB,CAACA,SAA6C;AAC5E,SAAQ,KAAK,MAAb;EACE,KAAK;EACL,KAAK,qBACH,QAAO,EAAE,MAAM,OAAQ;EACzB,KAAK;EACL,KAAK,qBACH,QAAO,EAAE,MAAM,SAAU;EAC3B,KAAK;EACL,KAAK,sBACH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xB,MAAM;CACJ;CACA;AACD,EACF;AAED,MAAaC,oBAAkE,CAACC,6CAAgB"}
|
|
@@ -54,10 +54,42 @@ const inferControlType = (prop) => {
|
|
|
54
54
|
|
|
55
55
|
//#endregion
|
|
56
56
|
//#region src/docs/custom-elements.ts
|
|
57
|
+
/**
|
|
58
|
+
* Formats docsTags (@deprecated, @see, @since) and appends them to the description
|
|
59
|
+
*/
|
|
60
|
+
const formatDocsTags = (docs, docsTags) => {
|
|
61
|
+
if (!docsTags || docsTags.length === 0) return docs;
|
|
62
|
+
const tagSections = [];
|
|
63
|
+
const deprecationSections = [];
|
|
64
|
+
const deprecatedTags = docsTags.filter((tag) => tag.name === "deprecated");
|
|
65
|
+
if (deprecatedTags.length > 0) deprecatedTags.forEach((tag) => {
|
|
66
|
+
if (tag.text) deprecationSections.push(`**⚠️ DEPRECATED:** ${tag.text}`);
|
|
67
|
+
else deprecationSections.push(`**⚠️ DEPRECATED**`);
|
|
68
|
+
});
|
|
69
|
+
const seeTags = docsTags.filter((tag) => tag.name === "see");
|
|
70
|
+
if (seeTags.length > 0) {
|
|
71
|
+
const seeLinks = seeTags.map((tag) => {
|
|
72
|
+
const url = tag.text?.trim();
|
|
73
|
+
return url ? `[${url}](${url})` : "";
|
|
74
|
+
}).filter(Boolean).join(", ");
|
|
75
|
+
if (seeLinks) tagSections.push(`**See:** ${seeLinks}`);
|
|
76
|
+
}
|
|
77
|
+
const sinceTags = docsTags.filter((tag) => tag.name === "since");
|
|
78
|
+
if (sinceTags.length > 0) {
|
|
79
|
+
const sinceText = sinceTags.map((tag) => tag.text).filter(Boolean).join(", ");
|
|
80
|
+
if (sinceText) tagSections.push(`**Since:** ${sinceText}`);
|
|
81
|
+
}
|
|
82
|
+
const allSections = [
|
|
83
|
+
...deprecationSections,
|
|
84
|
+
docs,
|
|
85
|
+
...tagSections
|
|
86
|
+
].filter(Boolean);
|
|
87
|
+
return allSections.join("\n\n");
|
|
88
|
+
};
|
|
57
89
|
const mapData = (data, category) => data.reduce((acc, item) => {
|
|
58
90
|
acc[item.name] = {
|
|
59
91
|
name: item.name,
|
|
60
|
-
description: item.docs,
|
|
92
|
+
description: formatDocsTags(item.docs, item.docsTags),
|
|
61
93
|
control: false,
|
|
62
94
|
table: { category }
|
|
63
95
|
};
|
|
@@ -66,7 +98,7 @@ const mapData = (data, category) => data.reduce((acc, item) => {
|
|
|
66
98
|
const mapMethods = (methods) => methods.reduce((acc, method) => {
|
|
67
99
|
acc[method.name] = {
|
|
68
100
|
name: method.name,
|
|
69
|
-
description: method.docs,
|
|
101
|
+
description: formatDocsTags(method.docs, method.docsTags),
|
|
70
102
|
control: null,
|
|
71
103
|
type: { name: "function" },
|
|
72
104
|
table: {
|
|
@@ -83,7 +115,7 @@ const mapEvent = (events) => events.reduce((acc, event) => {
|
|
|
83
115
|
name = `on${name.charAt(0).toUpperCase() + name.slice(1)}`;
|
|
84
116
|
acc[name] = {
|
|
85
117
|
name,
|
|
86
|
-
description: event.docs,
|
|
118
|
+
description: formatDocsTags(event.docs, event.docsTags),
|
|
87
119
|
control: null,
|
|
88
120
|
table: {
|
|
89
121
|
category: "events",
|
|
@@ -96,7 +128,7 @@ const mapEvent = (events) => events.reduce((acc, event) => {
|
|
|
96
128
|
const mapProps = (props) => props.reduce((acc, prop) => {
|
|
97
129
|
acc[prop.name] = {
|
|
98
130
|
name: prop.attr || prop.name,
|
|
99
|
-
description: prop.docs,
|
|
131
|
+
description: formatDocsTags(prop.docs, prop.docsTags),
|
|
100
132
|
control: inferControlType(prop),
|
|
101
133
|
table: {
|
|
102
134
|
category: "properties",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entry-preview-argtypes.js","names":["prop: JsonDocsProp","scalarTypes: SBScalarType['name'][]","data: T[]","category: string","methods: JsonDocsMethod[]","events: JsonDocsEvent[]","chr: string","props: JsonDocsProp[]","tagName: string","manifest: JsonDocs","customElements: JsonDocs","component: any","argTypesEnhancers: ArgTypesEnhancer<StencilRenderer<unknown>>[]"],"sources":["../src/docs/infer-type.ts","../src/docs/custom-elements.ts","../src/entry-preview-argtypes.ts"],"sourcesContent":["import type { JsonDocsProp } from '@stencil/core/internal';\nimport type { InputType, SBScalarType, SBType } from 'storybook/internal/types';\n\nexport const inferSBType = (prop: JsonDocsProp): SBType => {\n const scalarTypes: SBScalarType['name'][] = ['string', 'number', 'boolean', 'symbol'];\n if (prop.type.toLowerCase() in scalarTypes) {\n return { name: prop.type.toLowerCase(), raw: prop.type, required: prop.required } as SBScalarType;\n }\n\n if (/^\\(.*\\)\\s*=>\\s*.*$/.test(prop.type)) {\n return { name: 'function', raw: prop.type, required: prop.required };\n }\n\n return { name: 'other', value: prop.type, raw: prop.type, required: prop.required };\n};\n\nexport const mapPropOptions = (prop: JsonDocsProp) =>\n prop.values.filter((value) => ['string', 'number'].includes(value.type)).map(({ value }) => value);\n\nexport const inferControlType = (prop: JsonDocsProp): InputType['control'] => {\n switch (prop.type) {\n case 'string':\n case 'string | undefined':\n return { type: 'text' };\n case 'number':\n case 'number | undefined':\n return { type: 'number' };\n case 'boolean':\n case 'boolean | undefined':\n return { type: 'boolean' };\n case 'Date':\n case 'Date | string':\n return { type: 'date' };\n case 'function':\n case 'function | undefined':\n case 'void':\n case 'void | undefined':\n return null;\n default:\n const values = mapPropOptions(prop);\n\n if (values.length === 0) {\n return { type: 'object' };\n }\n if (values.length < 5) {\n return { type: 'radio' };\n }\n return { type: 'select' };\n }\n};\n","import type {\n JsonDocs,\n JsonDocsEvent,\n JsonDocsMethod,\n JsonDocsPart,\n JsonDocsProp,\n JsonDocsSlot,\n JsonDocsStyle,\n} from '@stencil/core/internal';\nimport { logger } from 'storybook/internal/client-logger';\nimport type { ArgTypes } from 'storybook/internal/types';\n\nimport { getCustomElements, isValidComponent, isValidMetaData } from '..';\nimport { inferControlType, inferSBType, mapPropOptions } from './infer-type';\n\nconst mapData = <T extends JsonDocsPart>(data: T[], category: string): ArgTypes =>\n data.reduce<ArgTypes>((acc, item) => {\n acc[item.name] = {\n name: item.name,\n description: item.docs,\n control: false,\n table: {\n category,\n },\n };\n return acc;\n }, {});\n\nconst mapMethods = (methods: JsonDocsMethod[]): ArgTypes =>\n methods.reduce<ArgTypes>((acc, method) => {\n acc[method.name] = {\n name: method.name,\n description: method.docs,\n control: null,\n type: { name: 'function' },\n table: {\n category: 'methods',\n type: { summary: method.signature },\n },\n };\n return acc;\n }, {});\n\nconst mapEvent = (events: JsonDocsEvent[]): ArgTypes =>\n events.reduce<ArgTypes>((acc, event) => {\n let name = event.event\n .replace(/(-|_|:|\\.|\\s)+(.)?/g, (_match, _separator, chr: string) => {\n return chr ? chr.toUpperCase() : '';\n })\n .replace(/^([A-Z])/, (match) => match.toLowerCase());\n\n name = `on${name.charAt(0).toUpperCase() + name.slice(1)}`;\n\n acc[name] = {\n name,\n description: event.docs,\n control: null,\n table: {\n category: 'events',\n type: { summary: event.detail },\n },\n type: { name: 'function' },\n };\n\n return acc;\n }, {});\n\nconst mapProps = (props: JsonDocsProp[]): ArgTypes =>\n props.reduce<ArgTypes>((acc, prop) => {\n acc[prop.name] = {\n name: prop.attr || prop.name,\n description: prop.docs,\n control: inferControlType(prop),\n table: {\n category: 'properties',\n type: { summary: prop.complexType?.original },\n defaultValue: { summary: prop.default },\n },\n options: mapPropOptions(prop),\n type: inferSBType(prop),\n };\n\n return acc;\n }, {});\n\nconst getMetaData = (tagName: string, manifest: JsonDocs) => {\n if (!isValidComponent(tagName) || !isValidMetaData(manifest)) {\n return null;\n }\n const metaData = manifest.components.find((component) => component.tag.toUpperCase() === tagName.toUpperCase());\n if (!metaData) {\n logger.warn(`Component not found in custom-elements.json: ${tagName}`);\n }\n return metaData;\n};\n\nexport const extractArgTypesFromElements = (tagName: string, customElements: JsonDocs) => {\n const metaData = getMetaData(tagName, customElements);\n return (\n metaData && {\n ...mapProps(metaData.props),\n ...mapEvent(metaData.events),\n ...mapMethods(metaData.methods),\n ...mapData<JsonDocsSlot>(metaData.slots, 'slots'),\n ...mapData<JsonDocsPart>(metaData.parts, 'parts'),\n ...mapData<JsonDocsStyle>(metaData.styles, 'styles'),\n }\n );\n};\n\nexport const extractArgTypes = (component: any) => {\n const cem = getCustomElements();\n // Handle both string references (lazy loading) and class references (auto-define)\n const tagName = typeof component === 'string' ? component : component?.is;\n return extractArgTypesFromElements(tagName, cem);\n};\n\nexport const extractComponentDescription = (component: any) => {\n // Handle both string references (lazy loading) and class references (auto-define)\n const tagName = typeof component === 'string' ? component : component?.is;\n const metaData = getMetaData(tagName, getCustomElements());\n return metaData && metaData.docs;\n};\n","import { enhanceArgTypes } from 'storybook/internal/docs-tools';\nimport type { ArgTypesEnhancer } from 'storybook/internal/types';\n\nimport { extractArgTypes, extractComponentDescription } from './docs/custom-elements';\nimport type { StencilRenderer } from './types';\n\nexport const parameters = {\n docs: {\n extractArgTypes,\n extractComponentDescription,\n },\n};\n\nexport const argTypesEnhancers: ArgTypesEnhancer<StencilRenderer<unknown>>[] = [enhanceArgTypes];"],"mappings":";;;;;;;AAGA,MAAa,cAAc,CAACA,SAA+B;CACzD,MAAMC,cAAsC;EAAC;EAAU;EAAU;EAAW;CAAS;AACrF,KAAI,KAAK,KAAK,aAAa,IAAI,YAC7B,QAAO;EAAE,MAAM,KAAK,KAAK,aAAa;EAAE,KAAK,KAAK;EAAM,UAAU,KAAK;CAAU;AAGnF,KAAI,qBAAqB,KAAK,KAAK,KAAK,CACtC,QAAO;EAAE,MAAM;EAAY,KAAK,KAAK;EAAM,UAAU,KAAK;CAAU;AAGtE,QAAO;EAAE,MAAM;EAAS,OAAO,KAAK;EAAM,KAAK,KAAK;EAAM,UAAU,KAAK;CAAU;AACpF;AAED,MAAa,iBAAiB,CAACD,SAC7B,KAAK,OAAO,OAAO,CAAC,UAAU,CAAC,UAAU,QAAS,EAAC,SAAS,MAAM,KAAK,CAAC,CAAC,IAAI,CAAC,EAAE,OAAO,KAAK,MAAM;AAEpG,MAAa,mBAAmB,CAACA,SAA6C;AAC5E,SAAQ,KAA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AY,WAAW;AACvE,QAAO,4BAA4B,SAAS,IAAI;AACjD;AAED,MAAa,8BAA8B,CAACA,cAAmB;CAE7D,MAAM,iBAAiB,cAAc,WAAW,YAAY,WAAW;CACvE,MAAM,WAAW,YAAY,SAAS,mBAAmB,CAAC;AAC1D,QAAO,YAAY,SAAS;AAC7B;;;;ACpHD,MAAa,aAAa,EACxB,MAAM;CACJ;CACA;AACD,EACF;AAED,MAAaC,oBAAkE,CAAC,eAAgB"}
|
|
1
|
+
{"version":3,"file":"entry-preview-argtypes.js","names":["prop: JsonDocsProp","scalarTypes: SBScalarType['name'][]","docs: string","docsTags?: DocsTag[]","tagSections: string[]","deprecationSections: string[]","data: T[]","category: string","methods: JsonDocsMethod[]","events: JsonDocsEvent[]","chr: string","props: JsonDocsProp[]","tagName: string","manifest: JsonDocs","customElements: JsonDocs","component: any","argTypesEnhancers: ArgTypesEnhancer<StencilRenderer<unknown>>[]"],"sources":["../src/docs/infer-type.ts","../src/docs/custom-elements.ts","../src/entry-preview-argtypes.ts"],"sourcesContent":["import type { JsonDocsProp } from '@stencil/core/internal';\nimport type { InputType, SBScalarType, SBType } from 'storybook/internal/types';\n\nexport const inferSBType = (prop: JsonDocsProp): SBType => {\n const scalarTypes: SBScalarType['name'][] = ['string', 'number', 'boolean', 'symbol'];\n if (prop.type.toLowerCase() in scalarTypes) {\n return { name: prop.type.toLowerCase(), raw: prop.type, required: prop.required } as SBScalarType;\n }\n\n if (/^\\(.*\\)\\s*=>\\s*.*$/.test(prop.type)) {\n return { name: 'function', raw: prop.type, required: prop.required };\n }\n\n return { name: 'other', value: prop.type, raw: prop.type, required: prop.required };\n};\n\nexport const mapPropOptions = (prop: JsonDocsProp) =>\n prop.values.filter((value) => ['string', 'number'].includes(value.type)).map(({ value }) => value);\n\nexport const inferControlType = (prop: JsonDocsProp): InputType['control'] => {\n switch (prop.type) {\n case 'string':\n case 'string | undefined':\n return { type: 'text' };\n case 'number':\n case 'number | undefined':\n return { type: 'number' };\n case 'boolean':\n case 'boolean | undefined':\n return { type: 'boolean' };\n case 'Date':\n case 'Date | string':\n return { type: 'date' };\n case 'function':\n case 'function | undefined':\n case 'void':\n case 'void | undefined':\n return null;\n default:\n const values = mapPropOptions(prop);\n\n if (values.length === 0) {\n return { type: 'object' };\n }\n if (values.length < 5) {\n return { type: 'radio' };\n }\n return { type: 'select' };\n }\n};\n","import type {\n JsonDocs,\n JsonDocsEvent,\n JsonDocsMethod,\n JsonDocsPart,\n JsonDocsProp,\n JsonDocsSlot,\n JsonDocsStyle,\n} from '@stencil/core/internal';\nimport { logger } from 'storybook/internal/client-logger';\nimport type { ArgTypes } from 'storybook/internal/types';\n\nimport { getCustomElements, isValidComponent, isValidMetaData } from '..';\nimport { inferControlType, inferSBType, mapPropOptions } from './infer-type';\n\ninterface DocsTag {\n name: string;\n text?: string;\n}\n\n/**\n * Formats docsTags (@deprecated, @see, @since) and appends them to the description\n */\nconst formatDocsTags = (docs: string, docsTags?: DocsTag[]): string => {\n if (!docsTags || docsTags.length === 0) {\n return docs;\n }\n\n const tagSections: string[] = [];\n const deprecationSections: string[] = [];\n\n // Handle @deprecated tags - show at the top with emphasis\n const deprecatedTags = docsTags.filter((tag) => tag.name === 'deprecated');\n if (deprecatedTags.length > 0) {\n deprecatedTags.forEach((tag) => {\n if (tag.text) {\n deprecationSections.push(`**⚠️ DEPRECATED:** ${tag.text}`);\n } else {\n deprecationSections.push(`**⚠️ DEPRECATED**`);\n }\n });\n }\n\n // Handle @see tags - create links\n const seeTags = docsTags.filter((tag) => tag.name === 'see');\n if (seeTags.length > 0) {\n const seeLinks = seeTags\n .map((tag) => {\n const url = tag.text?.trim();\n return url ? `[${url}](${url})` : '';\n })\n .filter(Boolean)\n .join(', ');\n if (seeLinks) {\n tagSections.push(`**See:** ${seeLinks}`);\n }\n }\n\n // Handle @since tags\n const sinceTags = docsTags.filter((tag) => tag.name === 'since');\n if (sinceTags.length > 0) {\n const sinceText = sinceTags\n .map((tag) => tag.text)\n .filter(Boolean)\n .join(', ');\n if (sinceText) {\n tagSections.push(`**Since:** ${sinceText}`);\n }\n }\n\n // Combine all sections - deprecation first, then docs, then other tags\n const allSections = [...deprecationSections, docs, ...tagSections].filter(Boolean);\n\n return allSections.join('\\n\\n');\n};\n\nconst mapData = <T extends JsonDocsPart>(data: T[], category: string): ArgTypes =>\n data.reduce<ArgTypes>((acc, item) => {\n acc[item.name] = {\n name: item.name,\n description: formatDocsTags(item.docs, (item as any).docsTags as DocsTag[]),\n control: false,\n table: {\n category,\n },\n };\n return acc;\n }, {});\n\nconst mapMethods = (methods: JsonDocsMethod[]): ArgTypes =>\n methods.reduce<ArgTypes>((acc, method) => {\n acc[method.name] = {\n name: method.name,\n description: formatDocsTags(method.docs, method.docsTags as DocsTag[]),\n control: null,\n type: { name: 'function' },\n table: {\n category: 'methods',\n type: { summary: method.signature },\n },\n };\n return acc;\n }, {});\n\nconst mapEvent = (events: JsonDocsEvent[]): ArgTypes =>\n events.reduce<ArgTypes>((acc, event) => {\n let name = event.event\n .replace(/(-|_|:|\\.|\\s)+(.)?/g, (_match, _separator, chr: string) => {\n return chr ? chr.toUpperCase() : '';\n })\n .replace(/^([A-Z])/, (match) => match.toLowerCase());\n\n name = `on${name.charAt(0).toUpperCase() + name.slice(1)}`;\n\n acc[name] = {\n name,\n description: formatDocsTags(event.docs, event.docsTags as DocsTag[]),\n control: null,\n table: {\n category: 'events',\n type: { summary: event.detail },\n },\n type: { name: 'function' },\n };\n\n return acc;\n }, {});\n\nconst mapProps = (props: JsonDocsProp[]): ArgTypes =>\n props.reduce<ArgTypes>((acc, prop) => {\n acc[prop.name] = {\n name: prop.attr || prop.name,\n description: formatDocsTags(prop.docs, prop.docsTags as DocsTag[]),\n control: inferControlType(prop),\n table: {\n category: 'properties',\n type: { summary: prop.complexType?.original },\n defaultValue: { summary: prop.default },\n },\n options: mapPropOptions(prop),\n type: inferSBType(prop),\n };\n\n return acc;\n }, {});\n\nconst getMetaData = (tagName: string, manifest: JsonDocs) => {\n if (!isValidComponent(tagName) || !isValidMetaData(manifest)) {\n return null;\n }\n const metaData = manifest.components.find((component) => component.tag.toUpperCase() === tagName.toUpperCase());\n if (!metaData) {\n logger.warn(`Component not found in custom-elements.json: ${tagName}`);\n }\n return metaData;\n};\n\nexport const extractArgTypesFromElements = (tagName: string, customElements: JsonDocs) => {\n const metaData = getMetaData(tagName, customElements);\n return (\n metaData && {\n ...mapProps(metaData.props),\n ...mapEvent(metaData.events),\n ...mapMethods(metaData.methods),\n ...mapData<JsonDocsSlot>(metaData.slots, 'slots'),\n ...mapData<JsonDocsPart>(metaData.parts, 'parts'),\n ...mapData<JsonDocsStyle>(metaData.styles, 'styles'),\n }\n );\n};\n\nexport const extractArgTypes = (component: any) => {\n const cem = getCustomElements();\n // Handle both string references (lazy loading) and class references (auto-define)\n const tagName = typeof component === 'string' ? component : component?.is;\n return extractArgTypesFromElements(tagName, cem);\n};\n\nexport const extractComponentDescription = (component: any) => {\n // Handle both string references (lazy loading) and class references (auto-define)\n const tagName = typeof component === 'string' ? component : component?.is;\n const metaData = getMetaData(tagName, getCustomElements());\n return metaData && metaData.docs;\n};\n","import { enhanceArgTypes } from 'storybook/internal/docs-tools';\nimport type { ArgTypesEnhancer } from 'storybook/internal/types';\n\nimport { extractArgTypes, extractComponentDescription } from './docs/custom-elements';\nimport type { StencilRenderer } from './types';\n\nexport const parameters = {\n docs: {\n extractArgTypes,\n extractComponentDescription,\n },\n};\n\nexport const argTypesEnhancers: ArgTypesEnhancer<StencilRenderer<unknown>>[] = [enhanceArgTypes];"],"mappings":";;;;;;;AAGA,MAAa,cAAc,CAACA,SAA+B;CACzD,MAAMC,cAAsC;EAAC;EAAU;EAAU;EAAW;CAAS;AACrF,KAAI,KAAK,KAAK,aAAa,IAAI,YAC7B,QAAO;EAAE,MAAM,KAAK,KAAK,aAAa;EAAE,KAAK,KAAK;EAAM,UAAU,KAAK;CAAU;AAGnF,KAAI,qBAAqB,KAAK,KAAK,KAAK,CACtC,Q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SAAS,OAAO;EAC5B,GAAG,WAAW,SAAS,QAAQ;EAC/B,GAAG,QAAsB,SAAS,OAAO,QAAQ;EACjD,GAAG,QAAsB,SAAS,OAAO,QAAQ;EACjD,GAAG,QAAuB,SAAS,QAAQ,SAAS;CACrD;AAEJ;AAED,MAAa,kBAAkB,CAACC,cAAmB;CACjD,MAAM,MAAM,mBAAmB;CAE/B,MAAM,iBAAiB,cAAc,WAAW,YAAY,WAAW;AACvE,QAAO,4BAA4B,SAAS,IAAI;AACjD;AAED,MAAa,8BAA8B,CAACA,cAAmB;CAE7D,MAAM,iBAAiB,cAAc,WAAW,YAAY,WAAW;CACvE,MAAM,WAAW,YAAY,SAAS,mBAAmB,CAAC;AAC1D,QAAO,YAAY,SAAS;AAC7B;;;;ACjLD,MAAa,aAAa,EACxB,MAAM;CACJ;CACA;AACD,EACF;AAED,MAAaC,oBAAkE,CAAC,eAAgB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-CsX-DzYB.cjs');
|
|
2
|
-
const require_docs = require('./docs-
|
|
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;
|
|
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-
|
|
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;
|
|
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
package/dist/docs-C41e1jpq.cjs
DELETED
|
@@ -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,KAA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 @@
|
|
|
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,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,GAA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