@storybook/web-components 11.0.0-alpha.1 → 11.0.0-alpha.2

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.
@@ -0,0 +1,18 @@
1
+ import CJS_COMPAT_NODE_URL_rucz8cqr0ps from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_rucz8cqr0ps from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_rucz8cqr0ps from "node:module";
4
+
5
+ var __filename = CJS_COMPAT_NODE_URL_rucz8cqr0ps.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_rucz8cqr0ps.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_rucz8cqr0ps.createRequire(import.meta.url);
8
+
9
+ // ------------------------------------------------------------
10
+ // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
+ // ------------------------------------------------------------
12
+ import {
13
+ createDocgenProvider
14
+ } from "../_node-chunks/chunk-FABV47GL.js";
15
+ import "../_node-chunks/chunk-36BPTBR5.js";
16
+ export {
17
+ createDocgenProvider
18
+ };
@@ -0,0 +1,49 @@
1
+ import { DocgenError, DocgenMiddleware, DocgenPayload, DocgenProviderInput } from "storybook/internal/types";
2
+ import { CustomElementDeclaration, CustomElementMixinDeclaration } from "custom-elements-manifest";
3
+
4
+ //#region code/renderers/web-components/.dts-emit/code/renderers/web-components/src/docgen/component-docgen/manifest/types.d.ts
5
+ type ManifestDeclaration = CustomElementDeclaration | CustomElementMixinDeclaration;
6
+ //#endregion
7
+ //#region code/renderers/web-components/.dts-emit/code/renderers/web-components/src/docgen/component-docgen/manifest/cem-manager.d.ts
8
+ interface CemTag {
9
+ declaration: ManifestDeclaration;
10
+ /** Path relative to `process.cwd()`, as shown in messages and payloads. */
11
+ manifestPath: string;
12
+ warning?: string;
13
+ }
14
+ interface CemSnapshot {
15
+ /** First manifest in configuration order wins a tag. */
16
+ tags: ReadonlyMap<string, CemTag>;
17
+ /** Manifests that contribute nothing: missing or invalid with no last valid version. */
18
+ errors: DocgenError[];
19
+ paths: string[];
20
+ }
21
+ //#endregion
22
+ //#region code/renderers/web-components/.dts-emit/code/renderers/web-components/src/docgen/component-docgen/build-docgen.d.ts
23
+ interface WebComponentsDocgenOptions {
24
+ manifestPaths: string[];
25
+ typeProperty: string;
26
+ }
27
+ type WebComponentsDocgenPayload = DocgenPayload & {
28
+ /** Set while the manifest is served from its last valid version after a failed reload. */warning?: string;
29
+ customElementsManifest?: {
30
+ manifestPath: string;
31
+ declaration: ManifestDeclaration;
32
+ };
33
+ };
34
+ interface BuildDocgenContext {
35
+ cem: CemSnapshot;
36
+ typeProperty: string;
37
+ }
38
+ declare function buildDocgenPayload(input: DocgenProviderInput, context: BuildDocgenContext): WebComponentsDocgenPayload | undefined;
39
+ //#endregion
40
+ //#region code/renderers/web-components/.dts-emit/code/renderers/web-components/src/docgen/docgen-worker.d.ts
41
+ declare const createDocgenProvider: ({
42
+ manifestPaths,
43
+ typeProperty
44
+ }: WebComponentsDocgenOptions) => DocgenMiddleware;
45
+ //#endregion
46
+ //#region code/renderers/web-components/.dts-emit/code/renderers/web-components/src/docgen/component-docgen/arg-types/alt-type.d.ts
47
+ declare const DEFAULT_TYPE_PROPERTY = "parsedType";
48
+ //#endregion
49
+ export { DEFAULT_TYPE_PROPERTY, type WebComponentsDocgenOptions, type WebComponentsDocgenPayload, buildDocgenPayload, createDocgenProvider };
@@ -0,0 +1,23 @@
1
+ import CJS_COMPAT_NODE_URL_rucz8cqr0ps from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_rucz8cqr0ps from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_rucz8cqr0ps from "node:module";
4
+
5
+ var __filename = CJS_COMPAT_NODE_URL_rucz8cqr0ps.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_rucz8cqr0ps.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_rucz8cqr0ps.createRequire(import.meta.url);
8
+
9
+ // ------------------------------------------------------------
10
+ // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
+ // ------------------------------------------------------------
12
+ import {
13
+ buildDocgenPayload,
14
+ createDocgenProvider
15
+ } from "../_node-chunks/chunk-FABV47GL.js";
16
+ import {
17
+ DEFAULT_TYPE_PROPERTY
18
+ } from "../_node-chunks/chunk-36BPTBR5.js";
19
+ export {
20
+ DEFAULT_TYPE_PROPERTY,
21
+ buildDocgenPayload,
22
+ createDocgenProvider
23
+ };
@@ -2,8 +2,8 @@ import {
2
2
  getCustomElements,
3
3
  isValidComponent,
4
4
  isValidMetaData
5
- } from "./_browser-chunks/chunk-FQI5YULV.js";
6
- import "./_browser-chunks/chunk-UN5GYDGC.js";
5
+ } from "./_browser-chunks/chunk-ZTODZABH.js";
6
+ import "./_browser-chunks/chunk-Z3YF52EY.js";
7
7
  import "./_browser-chunks/chunk-6ZSMINL7.js";
8
8
  import "./_browser-chunks/chunk-4BE7D4DS.js";
9
9
 
@@ -12,29 +12,70 @@ import { enhanceArgTypes } from "storybook/internal/docs-tools";
12
12
 
13
13
  // src/docs/custom-elements.ts
14
14
  import { logger } from "storybook/internal/client-logger";
15
- import invariant from "tiny-invariant";
15
+
16
+ // ../../../node_modules/es-toolkit/dist/string/capitalize.mjs
17
+ function capitalize(str) {
18
+ return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
19
+ }
20
+
21
+ // ../../../node_modules/es-toolkit/dist/string/words.mjs
22
+ var CASE_SPLIT_PATTERN = new RegExp("\\p{Lu}?\\p{Ll}+|[0-9]+|\\p{Lu}+(?!\\p{Ll})|\\p{Emoji_Presentation}|\\p{Extended_Pictographic}|\\p{L}+", "gu");
23
+ function words(str) {
24
+ return Array.from(str.match(CASE_SPLIT_PATTERN) ?? []);
25
+ }
26
+
27
+ // ../../../node_modules/es-toolkit/dist/string/pascalCase.mjs
28
+ function pascalCase(str) {
29
+ return words(str).map((word) => capitalize(word)).join("");
30
+ }
31
+
32
+ // src/docgen/component-docgen/arg-types/event-action-name.ts
33
+ function eventActionName(name) {
34
+ return `on${pascalCase(name)}`;
35
+ }
36
+
37
+ // src/docs/map-arg-types.ts
38
+ var ITEM_GROUPS = [
39
+ ["members", "properties"],
40
+ ["properties", "properties"],
41
+ ["attributes", "attributes"],
42
+ ["events", "events"],
43
+ ["slots", "slots"],
44
+ ["cssProperties", "css custom properties"],
45
+ ["cssParts", "css shadow parts"]
46
+ ];
47
+ function mapArgTypes(groups) {
48
+ return ITEM_GROUPS.reduce(
49
+ (argTypes, [groupName, category]) => ({
50
+ ...argTypes,
51
+ ...mapData(groups[groupName] ?? [], category)
52
+ }),
53
+ {}
54
+ );
55
+ }
16
56
  function mapItem(item, category) {
17
- let type;
57
+ let text = typeText(item), typeName;
18
58
  switch (category) {
19
59
  case "attributes":
20
60
  case "properties":
21
- type = { name: item.type?.text || item.type };
61
+ typeName = text;
22
62
  break;
23
63
  case "slots":
24
- type = { name: "string" };
64
+ typeName = "string";
25
65
  break;
26
66
  default:
27
- type = { name: "void" };
67
+ typeName = "void";
28
68
  break;
29
69
  }
30
70
  return {
31
71
  name: item.name,
32
72
  required: !1,
33
73
  description: item.description,
34
- type,
74
+ // The legacy runtime keeps manifest type text as the sbType name; server docgen maps real SBTypes.
75
+ type: { name: typeName },
35
76
  table: {
36
77
  category,
37
- type: { summary: item.type?.text || item.type },
78
+ type: { summary: text },
38
79
  defaultValue: {
39
80
  summary: item.default !== void 0 ? item.default : item.defaultValue
40
81
  }
@@ -42,14 +83,18 @@ function mapItem(item, category) {
42
83
  };
43
84
  }
44
85
  function mapEvent(item) {
45
- let name = item.name.replace(/(-|_|:|\.|\s)+(.)?/g, (_match, _separator, chr) => chr ? chr.toUpperCase() : "").replace(/^([A-Z])/, (match) => match.toLowerCase());
46
- return name = `on${name.charAt(0).toUpperCase() + name.substr(1)}`, [{ name, action: { name: item.name }, table: { disable: !0 } }, mapItem(item, "events")];
86
+ return [{ name: eventActionName(item.name), action: { name: item.name }, table: { disable: !0 } }, mapItem(item, "events")];
47
87
  }
48
- function mapData(data, category) {
49
- return data && data.filter((item) => item && item.name).reduce((acc, item) => (item.kind === "method" || (category === "events" ? mapEvent(item).forEach((argType) => {
50
- invariant(argType.name, `${argType} should have a name property.`), acc[argType.name] = argType;
88
+ function mapData(items, category) {
89
+ return items.filter((item) => item?.name).reduce((acc, item) => (item.kind === "method" || (category === "events" ? mapEvent(item).forEach((argType) => {
90
+ acc[argType.name] = argType;
51
91
  }) : acc[item.name] = mapItem(item, category)), acc), {});
52
92
  }
93
+ function typeText(item) {
94
+ return typeof item.type == "string" ? item.type : item.type?.text;
95
+ }
96
+
97
+ // src/docs/custom-elements.ts
53
98
  var getMetaDataExperimental = (tagName, customElements) => {
54
99
  if (!isValidComponent(tagName) || !isValidMetaData(customElements))
55
100
  return null;
@@ -68,15 +113,7 @@ var getMetaDataExperimental = (tagName, customElements) => {
68
113
  }), metadata || logger.warn(`Component not found in custom-elements.json: ${tagName}`), metadata;
69
114
  }, getMetaData = (tagName, manifest) => manifest?.version === "experimental" ? getMetaDataExperimental(tagName, manifest) : getMetaDataV1(tagName, manifest), extractArgTypesFromElements = (tagName, customElements) => {
70
115
  let metaData = getMetaData(tagName, customElements);
71
- return metaData && {
72
- ...mapData(metaData.members ?? [], "properties"),
73
- ...mapData(metaData.properties ?? [], "properties"),
74
- ...mapData(metaData.attributes ?? [], "attributes"),
75
- ...mapData(metaData.events ?? [], "events"),
76
- ...mapData(metaData.slots ?? [], "slots"),
77
- ...mapData(metaData.cssProperties ?? [], "css custom properties"),
78
- ...mapData(metaData.cssParts ?? [], "css shadow parts")
79
- };
116
+ return metaData && mapArgTypes(metaData);
80
117
  }, extractArgTypes = (tagName) => {
81
118
  let cem = getCustomElements();
82
119
  return extractArgTypesFromElements(tagName, cem);
@@ -2,7 +2,7 @@ import {
2
2
  parameters,
3
3
  render,
4
4
  renderToCanvas
5
- } from "./_browser-chunks/chunk-UN5GYDGC.js";
5
+ } from "./_browser-chunks/chunk-Z3YF52EY.js";
6
6
  import "./_browser-chunks/chunk-4BE7D4DS.js";
7
7
  export {
8
8
  parameters,