@storybook/web-components 11.0.0-alpha.7 → 11.0.0-alpha.8

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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  entry_preview_exports
3
- } from "./chunk-CAPEJO4V.js";
3
+ } from "./chunk-XOX44XZE.js";
4
4
  import {
5
5
  entry_preview_docs_exports
6
6
  } from "./chunk-EGBR6PF2.js";
@@ -27,6 +27,7 @@ function parseArgKey(key) {
27
27
  return { category, name: key.slice(0, -suffix.length) };
28
28
  }
29
29
  var ARG_KEY_SUFFIXES = {
30
+ attributes: "-attr",
30
31
  events: "-event",
31
32
  methods: "-method",
32
33
  slots: "-slot",
@@ -36,6 +37,9 @@ var ARG_KEY_SUFFIXES = {
36
37
 
37
38
  // src/bind-args.ts
38
39
  var BINDERS = {
40
+ attributes: (element, name, value) => {
41
+ bindPrimitiveAttribute(element, name, value);
42
+ },
39
43
  events: (element, name, value) => {
40
44
  typeof value == "function" && element.addEventListener(name, value);
41
45
  },
@@ -48,6 +52,8 @@ var BINDERS = {
48
52
  function bindArgs(element, args) {
49
53
  let observedAttributes = observedAttributesOf(element), styleRules = [];
50
54
  for (let [key, value] of Object.entries(args)) {
55
+ if (value == null)
56
+ continue;
51
57
  let parsedKey = parseArgKey(key);
52
58
  if (parsedKey?.category === "cssProperties") {
53
59
  bindCssCustomProperty(element, key, value);
@@ -57,16 +63,14 @@ function bindArgs(element, args) {
57
63
  assignProperty(element, key, value);
58
64
  continue;
59
65
  }
60
- if (observedAttributes.has(key) && isPrimitive(value)) {
61
- bindAttribute(element, key, value);
62
- continue;
63
- }
64
- if (parsedKey) {
65
- let rule = BINDERS[parsedKey.category](element, parsedKey.name, value);
66
- rule && styleRules.push(rule);
67
- continue;
66
+ if (!(observedAttributes.has(key) && bindPrimitiveAttribute(element, key, value))) {
67
+ if (parsedKey) {
68
+ let rule = BINDERS[parsedKey.category](element, parsedKey.name, value);
69
+ rule && styleRules.push(rule);
70
+ continue;
71
+ }
72
+ assignProperty(element, key, value);
68
73
  }
69
- assignProperty(element, key, value);
70
74
  }
71
75
  return styleRules;
72
76
  }
@@ -83,6 +87,9 @@ function isUnset(value) {
83
87
  function assignProperty(element, key, value) {
84
88
  element[key] = value;
85
89
  }
90
+ function bindPrimitiveAttribute(element, name, value) {
91
+ return isPrimitive(value) ? (bindAttribute(element, name, value), !0) : !1;
92
+ }
86
93
  function bindAttribute(element, name, value) {
87
94
  isUnset(value) || value === !1 || element.setAttribute(name, value === !0 ? "" : String(value));
88
95
  }
@@ -1,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_seyt09815b from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_seyt09815b from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_seyt09815b from "node:module";
1
+ import CJS_COMPAT_NODE_URL_f6rwsm0jxpo from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_f6rwsm0jxpo from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_f6rwsm0jxpo from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_seyt09815b.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_seyt09815b.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_seyt09815b.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_f6rwsm0jxpo.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_f6rwsm0jxpo.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_f6rwsm0jxpo.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
@@ -12,7 +12,7 @@ var require = CJS_COMPAT_NODE_MODULE_seyt09815b.createRequire(import.meta.url);
12
12
  import {
13
13
  parseStoryFile,
14
14
  resolveStoryComponent
15
- } from "./chunk-MMJPCIXK.js";
15
+ } from "./chunk-A2ZEEPU6.js";
16
16
 
17
17
  // src/docgen/docgen-worker.ts
18
18
  import { createLazyDocgenMiddleware } from "storybook/internal/common";
@@ -20,7 +20,10 @@ import { logger as logger5 } from "storybook/internal/node-logger";
20
20
 
21
21
  // src/docgen/component-docgen/build-docgen.ts
22
22
  import { getComponentIdFromEntry, getStoryImportPathFromEntry } from "storybook/internal/common";
23
- import { extractComponentDescription, extractDescription } from "storybook/internal/csf-tools";
23
+ import {
24
+ extractComponentDescription,
25
+ extractDescription
26
+ } from "storybook/internal/csf-tools";
24
27
 
25
28
  // node_modules/pathe/dist/shared/pathe.ff20891b.mjs
26
29
  var _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
@@ -109,6 +112,7 @@ function toArgKey(category, name) {
109
112
  return category === "cssProperties" ? name : `${name}${ARG_KEY_SUFFIXES[category]}`;
110
113
  }
111
114
  var ARG_KEY_SUFFIXES = {
115
+ attributes: "-attr",
112
116
  events: "-event",
113
117
  methods: "-method",
114
118
  slots: "-slot",
@@ -189,10 +193,16 @@ function classifyDeclaration(declaration) {
189
193
  };
190
194
  }
191
195
  function isBackedByAttribute(field, attributes) {
196
+ return attributes.some((attribute) => isAttributeField(attribute, field));
197
+ }
198
+ function foldsIntoAttributeRow(field, attributes) {
192
199
  return attributes.some(
193
- (attribute) => attribute.field === field || attribute.attribute.name === field.name
200
+ (attribute) => attribute.attribute.name === field.name && isAttributeField(attribute, field)
194
201
  );
195
202
  }
203
+ function isAttributeField({ attribute, field: backingField2 }, field) {
204
+ return backingField2 === field || attribute.fieldName === void 0 && attribute.name === field.name;
205
+ }
196
206
  function backingField(attribute, fields) {
197
207
  return attribute.fieldName === void 0 ? void 0 : fields.find((field) => field.name === attribute.fieldName);
198
208
  }
@@ -360,9 +370,9 @@ var ARRAY_RE = /^(?:Array<(.+)>|(.+)\[\])$/, DROPPED_MEMBERS = /* @__PURE__ */ n
360
370
  "never",
361
371
  "string & {}",
362
372
  "(string & {})"
363
- ]), FUNCTION_RE = /^(new\s+)?(<.*>\s*)?\(.*\)\s*=>/, UNKNOWN_ARRAY_ELEMENT_TYPE = { name: "other", value: "" }, MAX_ARRAY_DEPTH = 8;
373
+ ]), FUNCTION_RE = /^(new\s+)?(<.*>\s*)?\(.*\)\s*=>/, QUOTED_OR_WHITESPACE_RE = /(['"])(?:\\.|(?!\1)[^\\])*\1|\s+/g, UNKNOWN_ARRAY_ELEMENT_TYPE = { name: "other", value: "" }, MAX_ARRAY_DEPTH = 8;
364
374
  function parseTypeText(text, depth = 0) {
365
- let trimmed = text?.trim() ?? "", members = normalizeMembers(trimmed);
375
+ let members = normalizeMembers(collapseWhitespace(text ?? ""));
366
376
  if (members.length === 0)
367
377
  return;
368
378
  let literalValues = members.map(parseLiteral).filter((literal) => literal !== void 0);
@@ -407,6 +417,9 @@ function parseTypeText(text, depth = 0) {
407
417
  function normalizeMembers(text) {
408
418
  return text ? flattenMembers(text).filter((member) => member && !DROPPED_MEMBERS.has(member)) : [];
409
419
  }
420
+ function collapseWhitespace(text) {
421
+ return text.replace(QUOTED_OR_WHITESPACE_RE, (match) => /^\s/.test(match) ? " " : match).trim();
422
+ }
410
423
  function flattenMembers(text) {
411
424
  return splitTopLevel(text).flatMap((part) => {
412
425
  let member = stripWrappingParens(part);
@@ -501,9 +514,7 @@ function mapArgTypes(declaration) {
501
514
  };
502
515
  }
503
516
  function mapAttributesAndProperties(api) {
504
- let argTypes = {}, properties = api.fields.filter(
505
- (field) => !api.attributes.some(({ attribute }) => attribute.name === field.name)
506
- );
517
+ let argTypes = {}, properties = api.fields.filter((field) => !foldsIntoAttributeRow(field, api.attributes));
507
518
  for (let field of properties) {
508
519
  let attribute = api.attributes.find(({ field: backingField2 }) => backingField2 === field);
509
520
  argTypes[field.name] = toArgType({
@@ -512,12 +523,14 @@ function mapAttributesAndProperties(api) {
512
523
  sources: attribute ? [field, attribute.attribute] : [field]
513
524
  });
514
525
  }
515
- for (let { attribute, field } of api.attributes)
516
- argTypes[attribute.name] = toArgType({
526
+ for (let { attribute, field } of api.attributes) {
527
+ let key = Object.hasOwn(argTypes, attribute.name) ? toArgKey("attributes", attribute.name) : attribute.name;
528
+ argTypes[key] = toArgType({
517
529
  key: attribute.name,
518
530
  category: "attributes",
519
531
  sources: field ? [field, attribute] : [attribute]
520
532
  });
533
+ }
521
534
  return argTypes;
522
535
  }
523
536
  function toArgType({ key, category, sources }) {
@@ -629,7 +642,10 @@ async function buildDocgenPayload(input, context) {
629
642
  if (resolved.reason === "no-meta-component")
630
643
  return;
631
644
  let componentName = input.entry.title.slice(input.entry.title.lastIndexOf("/") + 1);
632
- return fail(componentName, {
645
+ return resolved.reason === "unresolvable-meta-spread" ? fail(componentName, {
646
+ name: "unresolvable-meta-spread",
647
+ message: `\`meta.component\` could not be read because \`${resolved.spread}\` is not a local object literal. Set \`component: '<tag-name>'\` on the default export.`
648
+ }) : fail(componentName, {
633
649
  name: "component-not-a-tag",
634
650
  message: `\`meta.component\` must be the element's tag name as a string, got \`${resolved.expression}\``
635
651
  });
@@ -638,7 +654,7 @@ async function buildDocgenPayload(input, context) {
638
654
  if (!("declaration" in found))
639
655
  return fail(tag, found);
640
656
  let { description, summary, jsDocTags } = extractComponentDescription(
641
- extractDescription(csf._metaStatement) || void 0,
657
+ extractDescription(csf._metaStatement, csf.editor) || void 0,
642
658
  found.declaration.description,
643
659
  declarationTags(found.declaration)
644
660
  );
@@ -0,0 +1,76 @@
1
+ import CJS_COMPAT_NODE_URL_f6rwsm0jxpo from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_f6rwsm0jxpo from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_f6rwsm0jxpo from "node:module";
4
+
5
+ var __filename = CJS_COMPAT_NODE_URL_f6rwsm0jxpo.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_f6rwsm0jxpo.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_f6rwsm0jxpo.createRequire(import.meta.url);
8
+
9
+ // ------------------------------------------------------------
10
+ // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
+ // ------------------------------------------------------------
12
+
13
+ // src/docgen/component-docgen/resolve-component/resolve-component.ts
14
+ import {
15
+ isStringLiteral,
16
+ loadCsf,
17
+ oneLineTextOf,
18
+ resolveBindingMembers,
19
+ resolveObjectMembers,
20
+ unwrapExpression
21
+ } from "storybook/internal/csf-tools";
22
+ import { readFileSync } from "node:fs";
23
+ function parseStoryFile(storyFilePath, title) {
24
+ try {
25
+ let source = readFileSync(storyFilePath, "utf8");
26
+ return loadCsf(source, { makeTitle: () => title, fileName: storyFilePath }).parse();
27
+ } catch {
28
+ return;
29
+ }
30
+ }
31
+ function tagFromNode(csf, node) {
32
+ let unwrapped = unwrapExpression(node);
33
+ if (isStringLiteral(unwrapped) && unwrapped.value !== "")
34
+ return { tag: unwrapped.value };
35
+ if (unwrapped.type === "TemplateLiteral" && unwrapped.expressions.length === 0) {
36
+ let tag = unwrapped.quasis[0]?.value.cooked;
37
+ if (tag)
38
+ return { tag };
39
+ }
40
+ return { reason: "component-not-a-tag", expression: csf.editor.source(node) };
41
+ }
42
+ function resolveStoryComponent(csf) {
43
+ if (!csf._metaNode)
44
+ return { reason: "no-meta-component" };
45
+ let ctx = { editor: csf.editor, filePath: csf._options.fileName ?? "" }, members = resolveObjectMembers(csf._metaNode, ctx);
46
+ return componentIn(csf, members, csf._metaNode, ctx, /* @__PURE__ */ new Set()) ?? { reason: "no-meta-component" };
47
+ }
48
+ function componentIn(csf, members, object, ctx, visited) {
49
+ let component = members.properties.component;
50
+ if (component && !members.shadowed.includes("component"))
51
+ return tagFromNode(csf, component);
52
+ let unreadable = object.properties.filter((property) => property.type === "SpreadElement").filter((spread) => members.unresolved.includes(oneLineTextOf(spread))).reverse();
53
+ for (let spread of unreadable) {
54
+ let found = spreadComponent(csf, spread, ctx, visited);
55
+ if (found || component)
56
+ return found ?? { reason: "unresolvable-meta-spread", spread: oneLineTextOf(spread) };
57
+ }
58
+ return component && tagFromNode(csf, component);
59
+ }
60
+ function spreadComponent(csf, spread, ctx, visited) {
61
+ let local = localObject(unwrapExpression(spread.argument), ctx);
62
+ return !local || visited.has(local.object) ? { reason: "unresolvable-meta-spread", spread: oneLineTextOf(spread) } : componentIn(csf, local.members, local.object, ctx, new Set(visited).add(local.object));
63
+ }
64
+ function localObject(argument, ctx) {
65
+ if (argument.type === "ObjectExpression")
66
+ return { object: argument, members: resolveObjectMembers(argument, ctx) };
67
+ if (argument.type !== "Identifier")
68
+ return;
69
+ let declarator = ctx.editor.scopes.program.bindings.get(argument.name)?.node, init = declarator?.type === "VariableDeclarator" && declarator.init ? unwrapExpression(declarator.init) : void 0, members = resolveBindingMembers(ctx, argument.name);
70
+ return init?.type === "ObjectExpression" && members ? { object: init, members } : void 0;
71
+ }
72
+
73
+ export {
74
+ parseStoryFile,
75
+ resolveStoryComponent
76
+ };
@@ -1,18 +1,18 @@
1
- import CJS_COMPAT_NODE_URL_seyt09815b from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_seyt09815b from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_seyt09815b from "node:module";
1
+ import CJS_COMPAT_NODE_URL_f6rwsm0jxpo from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_f6rwsm0jxpo from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_f6rwsm0jxpo from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_seyt09815b.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_seyt09815b.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_seyt09815b.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_f6rwsm0jxpo.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_f6rwsm0jxpo.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_f6rwsm0jxpo.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
11
  // ------------------------------------------------------------
12
12
  import {
13
13
  createDocgenProvider
14
- } from "../_node-chunks/chunk-P75AOQLO.js";
15
- import "../_node-chunks/chunk-MMJPCIXK.js";
14
+ } from "../_node-chunks/chunk-7DGX2RHV.js";
15
+ import "../_node-chunks/chunk-A2ZEEPU6.js";
16
16
  export {
17
17
  createDocgenProvider
18
18
  };
@@ -1,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_seyt09815b from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_seyt09815b from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_seyt09815b from "node:module";
1
+ import CJS_COMPAT_NODE_URL_f6rwsm0jxpo from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_f6rwsm0jxpo from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_f6rwsm0jxpo from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_seyt09815b.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_seyt09815b.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_seyt09815b.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_f6rwsm0jxpo.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_f6rwsm0jxpo.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_f6rwsm0jxpo.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
@@ -12,8 +12,8 @@ var require = CJS_COMPAT_NODE_MODULE_seyt09815b.createRequire(import.meta.url);
12
12
  import {
13
13
  buildDocgenPayload,
14
14
  createDocgenProvider
15
- } from "../_node-chunks/chunk-P75AOQLO.js";
16
- import "../_node-chunks/chunk-MMJPCIXK.js";
15
+ } from "../_node-chunks/chunk-7DGX2RHV.js";
16
+ import "../_node-chunks/chunk-A2ZEEPU6.js";
17
17
  export {
18
18
  buildDocgenPayload,
19
19
  createDocgenProvider
@@ -2,8 +2,8 @@ import {
2
2
  getCustomElements,
3
3
  isValidComponent,
4
4
  isValidMetaData
5
- } from "./_browser-chunks/chunk-IPGO7UEM.js";
6
- import "./_browser-chunks/chunk-CAPEJO4V.js";
5
+ } from "./_browser-chunks/chunk-4CVRUPXU.js";
6
+ import "./_browser-chunks/chunk-XOX44XZE.js";
7
7
  import "./_browser-chunks/chunk-EGBR6PF2.js";
8
8
  import "./_browser-chunks/chunk-4BE7D4DS.js";
9
9
 
@@ -2,7 +2,7 @@ import {
2
2
  parameters,
3
3
  render,
4
4
  renderToCanvas
5
- } from "./_browser-chunks/chunk-CAPEJO4V.js";
5
+ } from "./_browser-chunks/chunk-XOX44XZE.js";
6
6
  import "./_browser-chunks/chunk-4BE7D4DS.js";
7
7
  export {
8
8
  parameters,
package/dist/index.js CHANGED
@@ -6,8 +6,8 @@ import {
6
6
  setCustomElements,
7
7
  setCustomElementsManifest,
8
8
  setProjectAnnotations
9
- } from "./_browser-chunks/chunk-IPGO7UEM.js";
10
- import "./_browser-chunks/chunk-CAPEJO4V.js";
9
+ } from "./_browser-chunks/chunk-4CVRUPXU.js";
10
+ import "./_browser-chunks/chunk-XOX44XZE.js";
11
11
  import "./_browser-chunks/chunk-EGBR6PF2.js";
12
12
  import "./_browser-chunks/chunk-4BE7D4DS.js";
13
13
  export {