@storybook/web-components 11.0.0-alpha.6 → 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.
package/dist/preset.js CHANGED
@@ -1,24 +1,24 @@
1
- import CJS_COMPAT_NODE_URL_3ov4ld79bt3 from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_3ov4ld79bt3 from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_3ov4ld79bt3 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_3ov4ld79bt3.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_3ov4ld79bt3.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_3ov4ld79bt3.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
- DEFAULT_TYPE_PROPERTY,
14
13
  parseStoryFile,
15
14
  resolveStoryComponent
16
- } from "./_node-chunks/chunk-GDY64HEP.js";
15
+ } from "./_node-chunks/chunk-A2ZEEPU6.js";
17
16
 
18
17
  // src/preset.ts
19
18
  import { fileURLToPath as fileURLToPath3 } from "node:url";
20
19
 
21
20
  // src/docgen/preset.ts
21
+ import { loadPreviewOrConfigFile } from "storybook/internal/common";
22
22
  import { fileURLToPath } from "node:url";
23
23
 
24
24
  // src/docgen/component-docgen/config/resolve-manifest-paths.ts
@@ -46,7 +46,7 @@ var experimental_docgenProvider = async (existing = [], options) => {
46
46
  moduleSpecifier: fileURLToPath(import.meta.resolve(DOCGEN_WORKER_SPECIFIER)),
47
47
  options: {
48
48
  manifestPaths: resolveManifestPaths(options.configDir, frameworkOptions),
49
- typeProperty: frameworkOptions.docgen?.typeProperty ?? DEFAULT_TYPE_PROPERTY
49
+ previewFilePath: loadPreviewOrConfigFile({ configDir: options.configDir })
50
50
  }
51
51
  };
52
52
  return [...existing, descriptor];
@@ -68,7 +68,6 @@ import { createWorkerGatedStoryDocsProvider, getService } from "storybook/intern
68
68
  import { logger } from "storybook/internal/node-logger";
69
69
 
70
70
  // src/docgen/story-docs/build-story-docs.ts
71
- import { types as t7 } from "storybook/internal/babel";
72
71
  import { getComponentIdFromEntry, getStoryImportPathFromEntry } from "storybook/internal/common";
73
72
  import { storyNameFromExport } from "storybook/internal/csf";
74
73
  import {
@@ -77,38 +76,41 @@ import {
77
76
  createStoryReferenceResolver,
78
77
  extractStoryJSDocInfo,
79
78
  noSnippetWarning,
80
- sourceOf as sourceOf6,
81
- unwrapExpression as unwrapExpression5,
79
+ resolveEffectiveRender,
80
+ oneLineTextOf as oneLineTextOf5,
81
+ unwrapExpression as unwrapExpression4,
82
82
  unresolvedWarning
83
83
  } from "storybook/internal/csf-tools";
84
84
  import { resolve as resolve2 } from "node:path";
85
85
 
86
86
  // src/docgen/story-docs/arg-values.ts
87
- import { types as t } from "storybook/internal/babel";
88
- import { keyOf, sourceOf, templateParts, unwrapExpression } from "storybook/internal/csf-tools";
89
- var FAILED = /* @__PURE__ */ Symbol("failed");
87
+ import {
88
+ staticKey,
89
+ oneLineTextOf,
90
+ templateParts,
91
+ unwrapExpression
92
+ } from "storybook/internal/csf-tools";
93
+ var FAILED = /* @__PURE__ */ Symbol("failed"), isFunctionNode = (node) => node.type === "ArrowFunctionExpression" || node.type === "FunctionExpression" || node.type === "FunctionDeclaration", primitiveLiteralValue = (node) => node.type !== "Literal" ? FAILED : ["string", "number", "boolean"].includes(typeof node.value) ? node.value : node.value === null && !("regex" in node) && !("bigint" in node) ? null : FAILED;
90
94
  function evaluateArgValue(node) {
91
95
  let value = evaluate(node);
92
96
  if (value === FAILED) {
93
97
  let unwrapped = unwrapExpression(node);
94
- return t.isFunction(unwrapped) ? { kind: "function" } : { kind: "unresolved", source: sourceOf(node) };
98
+ return isFunctionNode(unwrapped) ? { kind: "function" } : { kind: "unresolved", source: oneLineTextOf(node) };
95
99
  }
96
100
  return value === void 0 ? { kind: "unset" } : { kind: "value", value };
97
101
  }
98
102
  var evaluate = (node) => {
99
- let unwrapped = unwrapExpression(node);
100
- if (t.isStringLiteral(unwrapped) || t.isNumericLiteral(unwrapped) || t.isBooleanLiteral(unwrapped))
101
- return unwrapped.value;
102
- if (t.isNullLiteral(unwrapped)) return null;
103
- if (t.isIdentifier(unwrapped, { name: "undefined" }) || t.isUnaryExpression(unwrapped) && unwrapped.operator === "void") return;
104
- if (t.isUnaryExpression(unwrapped) && (unwrapped.operator === "-" || unwrapped.operator === "+") && t.isNumericLiteral(unwrapped.argument))
103
+ let unwrapped = unwrapExpression(node), literal = primitiveLiteralValue(unwrapped);
104
+ if (literal !== FAILED) return literal;
105
+ if (unwrapped.type === "Identifier" && unwrapped.name === "undefined" || unwrapped.type === "UnaryExpression" && unwrapped.operator === "void") return;
106
+ if (unwrapped.type === "UnaryExpression" && (unwrapped.operator === "-" || unwrapped.operator === "+") && unwrapped.argument.type === "Literal" && typeof unwrapped.argument.value == "number")
105
107
  return unwrapped.operator === "-" ? -unwrapped.argument.value : unwrapped.argument.value;
106
108
  let parts = templateParts(unwrapped);
107
- return parts && parts.expressions.length === 0 ? parts.quasis[0] ?? FAILED : t.isFunction(unwrapped) ? FAILED : t.isArrayExpression(unwrapped) ? evaluateArray(unwrapped) : t.isObjectExpression(unwrapped) ? evaluateObject(unwrapped) : FAILED;
109
+ return parts && parts.expressions.length === 0 ? parts.quasis[0] ?? FAILED : isFunctionNode(unwrapped) ? FAILED : unwrapped.type === "ArrayExpression" ? evaluateArray(unwrapped) : unwrapped.type === "ObjectExpression" ? evaluateObject(unwrapped) : FAILED;
108
110
  }, evaluateArray = (node) => {
109
111
  let values = [];
110
112
  for (let element of node.elements) {
111
- if (element === null || t.isSpreadElement(element))
113
+ if (element === null || element.type === "SpreadElement")
112
114
  return FAILED;
113
115
  let value = evaluate(element);
114
116
  if (value === FAILED)
@@ -119,10 +121,10 @@ var evaluate = (node) => {
119
121
  }, evaluateObject = (node) => {
120
122
  let values = {};
121
123
  for (let property of node.properties) {
122
- if (!t.isObjectProperty(property) || property.computed || t.isSpreadElement(property))
124
+ if (property.type !== "Property" || property.method || property.kind !== "init" || property.computed)
123
125
  return FAILED;
124
- let key = keyOf(property), value = evaluate(property.value);
125
- if (key === null || value === FAILED)
126
+ let key = staticKey(property), value = evaluate(property.value);
127
+ if (key === void 0 || value === FAILED)
126
128
  return FAILED;
127
129
  values[key] = value;
128
130
  }
@@ -162,15 +164,15 @@ function classifyArg(key, isFunction, argTypes, declaration) {
162
164
  case "attributes":
163
165
  return attributeBinding(
164
166
  name,
165
- attributeViaField(key, name, declaration),
166
- attributeDefault(key, name, declaration)
167
+ attributeViaField(name, declaration),
168
+ attributeDefault(name, declaration)
167
169
  );
168
170
  case "properties": {
169
171
  let attribute = pairedAttribute(name, declaration);
170
172
  return attribute ? attributeBinding(
171
173
  attribute,
172
174
  !0,
173
- fieldDefault(name, declaration) ?? attributeDefault(name, attribute, declaration)
175
+ fieldDefault(name, declaration) ?? attributeDefault(attribute, declaration)
174
176
  ) : { kind: "property", name };
175
177
  }
176
178
  case "events":
@@ -201,8 +203,8 @@ var fieldDefault = (fieldName, declaration) => fieldDeclaration(fieldName, decla
201
203
  ...defaultValue === void 0 ? {} : { defaultValue }
202
204
  }), fieldDeclaration = (fieldName, declaration) => declaration.members?.find(
203
205
  (member) => member.kind === "field" && member.name === fieldName
204
- ), attributeDeclaration = (attributeName, declaration) => declaration.attributes?.find((attribute) => attribute.name === attributeName), attributeViaField = (key, attributeName, declaration) => pairedAttribute(key, declaration) === attributeName, attributeDefault = (key, attributeName, declaration) => {
205
- let attribute = attributeDeclaration(attributeName, declaration), fieldName = attribute?.fieldName === key || pairedAttribute(key, declaration) === attributeName ? key : void 0;
206
+ ), attributeDeclaration = (attributeName, declaration) => declaration.attributes?.find((attribute) => attribute.name === attributeName), attributeViaField = (attributeName, declaration) => pairedAttribute(attributeName, declaration) === attributeName, attributeDefault = (attributeName, declaration) => {
207
+ let attribute = attributeDeclaration(attributeName, declaration), fieldName = attribute?.fieldName ?? (attributeViaField(attributeName, declaration) ? attributeName : void 0);
206
208
  return (fieldName ? fieldDefault(fieldName, declaration) : void 0) ?? attribute?.default;
207
209
  }, eventForArg = (key, declaration) => {
208
210
  let matches = declaration.events?.filter(
@@ -609,82 +611,82 @@ var printCssProperties = (properties) => {
609
611
  ];
610
612
  }, hasSlotAttribute = (node) => node.attributes.some((attribute) => attribute.name === "slot"), escapeScriptString = (value) => value.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/</g, "\\x3C"), sanitizeScriptHandler = (value) => value.replace(/<!--/g, "<\\!--").replace(/<script/gi, "<\\script").replace(/<\/script/gi, "<\\/script");
611
613
 
612
- // src/docgen/story-docs/template-print.ts
613
- import { sourceOf as sourceOf4 } from "storybook/internal/csf-tools";
614
-
615
614
  // src/docgen/story-docs/template-holes.ts
616
- import { types as t3 } from "storybook/internal/babel";
617
- import { sourceOf as sourceOf3, unwrapExpression as unwrapExpression3 } from "storybook/internal/csf-tools";
615
+ import {
616
+ oneLineTextOf as oneLineTextOf3,
617
+ reindent,
618
+ textOf,
619
+ unwrapExpression as unwrapExpression3,
620
+ walk
621
+ } from "storybook/internal/csf-tools";
618
622
 
619
623
  // src/docgen/story-docs/template-scope.ts
620
- import { types as t2 } from "storybook/internal/babel";
621
624
  import {
622
625
  collectImportBindings,
623
- keyOf as keyOf2,
624
- returnedExpressionPath,
625
- sourceOf as sourceOf2,
626
+ isStringLiteral,
627
+ staticKey as staticKey2,
628
+ returnedExpression,
629
+ oneLineTextOf as oneLineTextOf2,
626
630
  unwrapExpression as unwrapExpression2
627
631
  } from "storybook/internal/csf-tools";
628
632
  var TEMPLATE_TAG_SOURCES = ["lit", "lit-html", "lit-element"];
629
633
  function resolveHtmlTemplate(renderFunction, csf) {
630
- let bindings = collectImportBindings(csf._file.path), returned = returnedTemplateExpression(renderFunction, bindings);
634
+ let bindings = collectImportBindings(csf.program), returned = returnedTemplateExpression(renderFunction, bindings);
631
635
  return returned ? templateFromExpression(unwrapExpression2(returned.node), bindings, returned.scope) : void 0;
632
636
  }
633
637
  function templateFromExpression(expression, bindings, scope) {
634
- if (t2.isStringLiteral(expression))
638
+ if (isStringLiteral(expression))
635
639
  return {
636
640
  bindings,
637
641
  expressions: [],
638
642
  lit: !1,
639
643
  quasis: [expression.value],
640
644
  scope,
641
- source: sourceOf2(expression)
645
+ source: oneLineTextOf2(expression)
642
646
  };
643
- if (t2.isTemplateLiteral(expression))
644
- return templateFromLiteral(expression, bindings, !1, scope, sourceOf2(expression));
645
- if (!(!t2.isTaggedTemplateExpression(expression) || !t2.isIdentifier(expression.tag)))
646
- return isImported(expression.tag.name, "html", TEMPLATE_TAG_SOURCES, bindings) || isImported(expression.tag.name, "default", TEMPLATE_TAG_SOURCES, bindings) ? templateFromLiteral(expression.quasi, bindings, !0, scope, sourceOf2(expression)) : void 0;
647
+ if (expression.type === "TemplateLiteral")
648
+ return templateFromLiteral(expression, bindings, !1, scope, oneLineTextOf2(expression));
649
+ if (!(expression.type !== "TaggedTemplateExpression" || expression.tag.type !== "Identifier"))
650
+ return isImported(expression.tag.name, "html", TEMPLATE_TAG_SOURCES, bindings) || isImported(expression.tag.name, "default", TEMPLATE_TAG_SOURCES, bindings) ? templateFromLiteral(expression.quasi, bindings, !0, scope, oneLineTextOf2(expression)) : void 0;
647
651
  }
648
652
  function aliasValueForIdentifier(expression, scope) {
649
653
  return scope.aliases.get(expression.name);
650
654
  }
651
655
  function argReferenceForExpression(expression, scope) {
652
656
  let unwrapped = unwrapExpression2(expression);
653
- if (t2.isIdentifier(unwrapped)) {
657
+ if (unwrapped.type === "Identifier") {
654
658
  let alias = aliasValueForIdentifier(unwrapped, scope);
655
659
  return alias?.kind === "arg" ? { name: alias.name, path: alias.path } : parameterArgReference(unwrapped, scope);
656
660
  }
657
- if (!t2.isMemberExpression(unwrapped))
661
+ if (unwrapped.type !== "MemberExpression")
658
662
  return;
659
663
  let property = memberPropertyName(unwrapped);
660
664
  if (property === void 0)
661
665
  return;
662
- if (scope.args && t2.isIdentifier(unwrapped.object, { name: scope.args }))
666
+ if (scope.args && unwrapped.object.type === "Identifier" && unwrapped.object.name === scope.args)
663
667
  return { name: property, path: [] };
664
- if (!t2.isExpression(unwrapped.object))
665
- return;
666
668
  let object = argReferenceForExpression(unwrapped.object, scope);
667
669
  return object ? { name: object.name, path: [...object.path, property] } : void 0;
668
670
  }
669
671
  var returnedTemplateExpression = (renderFunction, bindings) => {
670
- let baseScope = scopeForRenderFunction(renderFunction), strict = returnedExpressionPath(renderFunction);
672
+ let baseScope = scopeForRenderFunction(renderFunction), strict = returnedExpression(renderFunction);
671
673
  if (strict)
672
- return { node: strict.node, scope: baseScope };
673
- if (!t2.isBlockStatement(renderFunction.node.body))
674
+ return { node: strict, scope: baseScope };
675
+ if (renderFunction.body?.type !== "BlockStatement")
674
676
  return;
675
- let statements = renderFunction.node.body.body, returned = statements.at(-1);
676
- if (!t2.isReturnStatement(returned) || !t2.isExpression(returned.argument))
677
+ let statements = renderFunction.body.body, returned = statements.at(-1);
678
+ if (returned?.type !== "ReturnStatement" || !returned.argument)
677
679
  return;
678
680
  let scope = copyScope(baseScope);
679
681
  for (let statement of statements.slice(0, -1))
680
- if (!t2.isVariableDeclaration(statement) || statement.kind !== "const" && statement.kind !== "let" || !addVariableAliases(statement, scope, bindings))
682
+ if (statement.type !== "VariableDeclaration" || statement.kind !== "const" && statement.kind !== "let" || !addVariableAliases(statement, scope, bindings))
681
683
  return;
682
684
  return { node: returned.argument, scope };
683
685
  }, scopeForRenderFunction = (renderFunction) => {
684
- let [first] = renderFunction.node.params, scope = { aliases: /* @__PURE__ */ new Map(), destructured: /* @__PURE__ */ new Map() };
685
- if (t2.isIdentifier(first))
686
+ let [first] = renderFunction.params, scope = { aliases: /* @__PURE__ */ new Map(), destructured: /* @__PURE__ */ new Map() };
687
+ if (first?.type === "Identifier")
686
688
  return scope.args = first.name, scope;
687
- if (!t2.isObjectPattern(first))
689
+ if (first?.type !== "ObjectPattern")
688
690
  return scope;
689
691
  let destructured = destructuredAliases(first, { name: "", path: [] });
690
692
  if (!destructured)
@@ -694,16 +696,16 @@ var returnedTemplateExpression = (renderFunction, bindings) => {
694
696
  return scope;
695
697
  }, addVariableAliases = (declaration, scope, bindings) => {
696
698
  for (let declarator of declaration.declarations) {
697
- if (!t2.isExpression(declarator.init))
699
+ if (!declarator.init)
698
700
  return !1;
699
- if (t2.isIdentifier(declarator.id)) {
701
+ if (declarator.id.type === "Identifier") {
700
702
  let alias = aliasForExpression(declarator.init, scope, bindings);
701
703
  if (!alias)
702
704
  return !1;
703
705
  scope.aliases.set(declarator.id.name, alias);
704
706
  continue;
705
707
  }
706
- if (t2.isObjectPattern(declarator.id)) {
708
+ if (declarator.id.type === "ObjectPattern") {
707
709
  let source = destructureSourceForExpression(declarator.init, scope);
708
710
  if (!source)
709
711
  return !1;
@@ -718,28 +720,28 @@ var returnedTemplateExpression = (renderFunction, bindings) => {
718
720
  return !0;
719
721
  }, destructureSourceForExpression = (expression, scope) => {
720
722
  let unwrapped = unwrapExpression2(expression);
721
- return scope.args && t2.isIdentifier(unwrapped, { name: scope.args }) ? { name: "", path: [] } : argReferenceForExpression(expression, scope);
723
+ return scope.args && unwrapped.type === "Identifier" && unwrapped.name === scope.args ? { name: "", path: [] } : argReferenceForExpression(expression, scope);
722
724
  }, aliasForExpression = (expression, scope, bindings) => {
723
- let unwrapped = unwrapExpression2(expression), arg = t2.isExpression(unwrapped) ? argReferenceForExpression(unwrapped, scope) : void 0;
725
+ let unwrapped = unwrapExpression2(expression), arg = argReferenceForExpression(unwrapped, scope);
724
726
  if (arg)
725
- return { kind: "arg", source: sourceOf2(expression), ...arg };
727
+ return { kind: "arg", source: oneLineTextOf2(expression), ...arg };
726
728
  if (isStaticLiteral(unwrapped))
727
729
  return { kind: "value", value: literalValue(unwrapped) };
728
730
  let template = templateFromExpression(unwrapped, bindings, copyScope(scope));
729
731
  if (template)
730
- return { kind: "template", source: sourceOf2(expression), template };
732
+ return { kind: "template", source: oneLineTextOf2(expression), template };
731
733
  }, destructuredAliases = (pattern, source) => {
732
734
  let aliases = /* @__PURE__ */ new Map();
733
735
  for (let property of pattern.properties) {
734
- if (!t2.isObjectProperty(property) || property.computed)
736
+ if (property.type !== "Property" || property.computed)
735
737
  return;
736
- let key = keyOf2(property);
738
+ let key = staticKey2(property);
737
739
  if (!key)
738
740
  return;
739
741
  let root = source.name === "" ? { name: key, path: [] } : { name: source.name, path: [...source.path, key] };
740
- if (t2.isIdentifier(property.value))
742
+ if (property.value.type === "Identifier")
741
743
  aliases.set(property.value.name, { kind: "arg", ...root });
742
- else if (t2.isObjectPattern(property.value)) {
744
+ else if (property.value.type === "ObjectPattern") {
743
745
  let nested = destructuredAliases(property.value, root);
744
746
  if (!nested)
745
747
  return;
@@ -751,11 +753,9 @@ var returnedTemplateExpression = (renderFunction, bindings) => {
751
753
  }, parameterArgReference = (expression, scope) => {
752
754
  let arg = scope.destructured.get(expression.name);
753
755
  return arg ? { name: arg, path: [] } : void 0;
754
- }, memberPropertyName = (expression) => !expression.computed && t2.isIdentifier(expression.property) ? expression.property.name : expression.computed && t2.isStringLiteral(expression.property) ? expression.property.value : void 0, templateFromLiteral = (literal, bindings, lit, scope, source) => ({
756
+ }, memberPropertyName = (expression) => !expression.computed && expression.property.type === "Identifier" ? expression.property.name : expression.computed && isStringLiteral(expression.property) ? expression.property.value : void 0, templateFromLiteral = (literal, bindings, lit, scope, source) => ({
755
757
  bindings,
756
- expressions: literal.expressions.filter(
757
- (expression) => t2.isExpression(expression)
758
- ),
758
+ expressions: literal.expressions,
759
759
  lit,
760
760
  quasis: literal.quasis.map((quasi) => quasi.value.raw),
761
761
  scope,
@@ -767,36 +767,47 @@ var returnedTemplateExpression = (renderFunction, bindings) => {
767
767
  }), isImported = (local, importName, sources, bindings) => {
768
768
  let binding = bindings.get(local);
769
769
  return !!binding && sources.includes(binding.importId) && binding.importName === importName;
770
- }, isStaticLiteral = (expression) => t2.isStringLiteral(expression) || t2.isNumericLiteral(expression) || t2.isBooleanLiteral(expression) || t2.isTemplateLiteral(expression) && expression.expressions.length === 0, literalValue = (expression) => {
771
- if (t2.isStringLiteral(expression) || t2.isNumericLiteral(expression) || t2.isBooleanLiteral(expression))
772
- return expression.value;
773
- if (t2.isTemplateLiteral(expression))
770
+ }, isStaticLiteral = (expression) => {
771
+ let value = primitiveLiteralValue(expression);
772
+ return value !== FAILED && value !== null || expression.type === "TemplateLiteral" && expression.expressions.length === 0;
773
+ }, literalValue = (expression) => {
774
+ if (expression.type === "TemplateLiteral")
774
775
  return expression.quasis[0]?.value.cooked ?? expression.quasis[0]?.value.raw ?? "";
776
+ let value = primitiveLiteralValue(expression);
777
+ return value === FAILED ? void 0 : value;
775
778
  };
776
779
 
777
780
  // src/docgen/story-docs/template-holes.ts
778
- var TEMPLATE_TAG_SOURCES2 = ["lit", "lit-html", "lit-element"], IF_DEFINED_SOURCES = ["lit/directives/if-defined.js", "lit-html/directives/if-defined.js"], resolveHoleValue = (expression, context) => {
779
- let expressionNode = unwrapExpression3(expression), alias = t3.isIdentifier(expressionNode) ? aliasValueForIdentifier(expressionNode, context.scope) : void 0;
781
+ var handlerText = (node) => {
782
+ let code = textOf(node), closingIndent = /^[ \t]*/.exec(code.slice(code.lastIndexOf(`
783
+ `) + 1))[0];
784
+ return reindent(code, closingIndent, " ");
785
+ }, TEMPLATE_TAG_SOURCES2 = ["lit", "lit-html", "lit-element"], IF_DEFINED_SOURCES = ["lit/directives/if-defined.js", "lit-html/directives/if-defined.js"], resolveHoleValue = (expression, context) => {
786
+ let expressionNode = unwrapExpression3(expression), alias = expressionNode.type === "Identifier" ? aliasValueForIdentifier(expressionNode, context.scope) : void 0;
780
787
  if (alias)
781
- return resolveAlias(alias, context, sourceOf3(expression));
788
+ return resolveAlias(alias, context, oneLineTextOf3(expression));
782
789
  let arg = argReferenceForExpression(expression, context.scope);
783
790
  if (arg)
784
- return resolveArgReference(arg, context.storyArgs[arg.name], sourceOf3(expression));
791
+ return resolveArgReference(arg, context.storyArgs[arg.name], oneLineTextOf3(expression));
785
792
  let unwrapped = expressionNode;
786
793
  if (isNothingExpression(unwrapped, context.bindings))
787
794
  return { kind: "nothing" };
788
795
  if (isStaticLiteral2(unwrapped))
789
796
  return { kind: "value", value: literalValue2(unwrapped) };
790
- if (t3.isFunction(unwrapped))
791
- return { handler: sourceOf3(expression), kind: "function" };
797
+ if (isFunctionNode(unwrapped))
798
+ return {
799
+ handler: handlerText(expression),
800
+ kind: "function",
801
+ source: oneLineTextOf3(expression)
802
+ };
792
803
  let nested = templateFromExpression(unwrapped, context.bindings, context.scope);
793
804
  if (nested)
794
- return { kind: "template", source: sourceOf3(expression), template: nested };
805
+ return { kind: "template", source: oneLineTextOf3(expression), template: nested };
795
806
  if (isIfDefinedCall(unwrapped, context.bindings)) {
796
807
  let value = resolveHoleValue(unwrapped.arguments[0], context);
797
808
  return value.kind === "value" && value.value !== null && value.value !== void 0 ? value : { kind: "nothing", ...value.arg ? { arg: value.arg } : {} };
798
809
  }
799
- if (t3.isConditionalExpression(unwrapped)) {
810
+ if (unwrapped.type === "ConditionalExpression") {
800
811
  let test = resolveConditionalTest(unwrapped.test, context);
801
812
  if (test.kind === "unresolved")
802
813
  return test;
@@ -806,24 +817,14 @@ var TEMPLATE_TAG_SOURCES2 = ["lit", "lit-html", "lit-element"], IF_DEFINED_SOURC
806
817
  );
807
818
  return test.arg && !branch.arg ? { ...branch, arg: test.arg } : branch;
808
819
  }
809
- return { kind: "unresolved", source: sourceOf3(expression) };
820
+ return { kind: "unresolved", source: oneLineTextOf3(expression) };
810
821
  }, collectReferencedArgs = (expression, scope) => {
811
- let referenced = /* @__PURE__ */ new Set(), visit = (node) => {
812
- if (t3.isExpression(node)) {
813
- let args = referencedArgsForExpression(node, scope);
814
- for (let arg of args)
815
- referenced.add(arg);
816
- }
817
- for (let key of t3.VISITOR_KEYS[node.type] ?? []) {
818
- if (skipsReferenceChild(node, key))
819
- continue;
820
- let child = node[key];
821
- Array.isArray(child) ? child.forEach((entry) => {
822
- t3.isNode(entry) && visit(entry);
823
- }) : t3.isNode(child) && visit(child);
824
- }
825
- };
826
- return visit(expression), referenced;
822
+ let referenced = /* @__PURE__ */ new Set();
823
+ return walk(expression, (node, parent) => {
824
+ if (isStaticName(node, parent))
825
+ return !1;
826
+ referencedArgsForExpression(node, scope).forEach((arg) => referenced.add(arg));
827
+ }), referenced;
827
828
  }, isTruthyAttributeValue = (value) => value.kind === "value" ? !!value.value : value.kind === "template" || value.kind === "function", attributeValue = (value, context, referenced) => {
828
829
  if (value.kind === "empty" || value.kind === "function" || value.kind === "nothing")
829
830
  return { kind: "value", value: void 0 };
@@ -839,7 +840,7 @@ var TEMPLATE_TAG_SOURCES2 = ["lit", "lit-html", "lit-element"], IF_DEFINED_SOURC
839
840
  let value = evaluateArgValue(node);
840
841
  switch (value.kind) {
841
842
  case "function":
842
- return { handler: sourceOf3(node), kind: "function", arg };
843
+ return { handler: handlerText(node), kind: "function", arg, source: oneLineTextOf3(node) };
843
844
  case "unset":
844
845
  return { kind: "value", arg, value: void 0 };
845
846
  case "unresolved":
@@ -875,7 +876,7 @@ var TEMPLATE_TAG_SOURCES2 = ["lit", "lit-html", "lit-element"], IF_DEFINED_SOURC
875
876
  }
876
877
  return current2 === void 0 ? missingPathSource ? { arg: reference.name, kind: "unresolved", source: missingPathSource } : { arg: reference.name, kind: "empty" } : { arg: reference.name, kind: "value", value: current2 };
877
878
  }, referencedArgsForExpression = (expression, scope) => {
878
- let alias = t3.isIdentifier(expression) ? aliasValueForIdentifier(expression, scope) : void 0;
879
+ let alias = expression.type === "Identifier" ? aliasValueForIdentifier(expression, scope) : void 0;
879
880
  if (alias)
880
881
  return referencedArgsForAlias(alias);
881
882
  let arg = argReferenceForExpression(expression, scope);
@@ -897,24 +898,22 @@ var TEMPLATE_TAG_SOURCES2 = ["lit", "lit-html", "lit-element"], IF_DEFINED_SOURC
897
898
  default:
898
899
  return alias;
899
900
  }
900
- }, skipsReferenceChild = (node, key) => t3.isMemberExpression(node) && key === "property" && !node.computed || (t3.isObjectProperty(node) || t3.isObjectMethod(node)) && key === "key" && !node.computed, isNothingExpression = (expression, bindings) => t3.isIdentifier(expression) && isImported2(expression.name, "nothing", TEMPLATE_TAG_SOURCES2, bindings), isStaticLiteral2 = (expression) => t3.isNullLiteral(expression) || t3.isStringLiteral(expression) || t3.isNumericLiteral(expression) || t3.isBooleanLiteral(expression) || t3.isIdentifier(expression, { name: "undefined" }) || t3.isUnaryExpression(expression) && expression.operator === "void" || t3.isTemplateLiteral(expression) && expression.expressions.length === 0, literalValue2 = (expression) => {
901
- if (t3.isNullLiteral(expression))
902
- return null;
903
- if (t3.isStringLiteral(expression) || t3.isNumericLiteral(expression) || t3.isBooleanLiteral(expression))
904
- return expression.value;
905
- if (!t3.isIdentifier(expression, { name: "undefined" }) && !(t3.isUnaryExpression(expression) && expression.operator === "void") && t3.isTemplateLiteral(expression))
901
+ }, isStaticName = (node, parent) => parent?.type === "MemberExpression" && parent.property === node && !parent.computed || parent?.type === "Property" && parent.key === node && parent.value !== node && !parent.computed, isNothingExpression = (expression, bindings) => expression.type === "Identifier" && isImported2(expression.name, "nothing", TEMPLATE_TAG_SOURCES2, bindings), isStaticLiteral2 = (expression) => primitiveLiteralValue(expression) !== FAILED || expression.type === "Identifier" && expression.name === "undefined" || expression.type === "UnaryExpression" && expression.operator === "void" || expression.type === "TemplateLiteral" && expression.expressions.length === 0, literalValue2 = (expression) => {
902
+ if (expression.type === "TemplateLiteral")
906
903
  return expression.quasis[0]?.value.cooked ?? expression.quasis[0]?.value.raw ?? "";
907
- }, isIfDefinedCall = (expression, bindings) => t3.isCallExpression(expression) && expression.arguments.length === 1 && t3.isExpression(expression.arguments[0]) && t3.isIdentifier(expression.callee) && isImported2(expression.callee.name, "ifDefined", IF_DEFINED_SOURCES, bindings), resolveConditionalTest = (expression, context) => {
904
+ let value = primitiveLiteralValue(expression);
905
+ return value === FAILED ? void 0 : value;
906
+ }, isIfDefinedCall = (expression, bindings) => expression.type === "CallExpression" && expression.arguments.length === 1 && expression.arguments[0].type !== "SpreadElement" && expression.callee.type === "Identifier" && isImported2(expression.callee.name, "ifDefined", IF_DEFINED_SOURCES, bindings), resolveConditionalTest = (expression, context) => {
908
907
  let arg = argReferenceForExpression(expression, context.scope);
909
908
  if (arg) {
910
- let value = resolveArgReference(arg, context.storyArgs[arg.name], sourceOf3(expression));
909
+ let value = resolveArgReference(arg, context.storyArgs[arg.name], oneLineTextOf3(expression));
911
910
  return value.kind === "value" || value.kind === "empty" ? { arg: arg.name, kind: "value", truthy: value.kind === "value" && !!value.value } : {
912
911
  kind: "unresolved",
913
- source: value.kind === "unresolved" ? value.source : sourceOf3(expression)
912
+ source: value.kind === "unresolved" ? value.source : oneLineTextOf3(expression)
914
913
  };
915
914
  }
916
915
  let unwrapped = unwrapExpression3(expression);
917
- return isNothingExpression(unwrapped, context.bindings) ? { kind: "value", truthy: !1 } : isStaticLiteral2(unwrapped) ? { kind: "value", truthy: !!literalValue2(unwrapped) } : { kind: "unresolved", source: sourceOf3(expression) };
916
+ return isNothingExpression(unwrapped, context.bindings) ? { kind: "value", truthy: !1 } : isStaticLiteral2(unwrapped) ? { kind: "value", truthy: !!literalValue2(unwrapped) } : { kind: "unresolved", source: oneLineTextOf3(expression) };
918
917
  }, templateAttributeText = (template, context, referenced) => {
919
918
  let scopedContext = { ...context, bindings: template.bindings, scope: template.scope }, text = "";
920
919
  for (let index = 0; index < template.expressions.length; index += 1) {
@@ -935,6 +934,7 @@ var TEMPLATE_TAG_SOURCES2 = ["lit", "lit-html", "lit-element"], IF_DEFINED_SOURC
935
934
  };
936
935
 
937
936
  // src/docgen/story-docs/template-print.ts
937
+ import { oneLineTextOf as oneLineTextOf4 } from "storybook/internal/csf-tools";
938
938
  function printHtmlTemplate(template, storyArgs, declaration) {
939
939
  return printTemplate(template, {
940
940
  bindings: template.bindings,
@@ -1055,7 +1055,7 @@ ${script}` : snippet,
1055
1055
  continue;
1056
1056
  let value = resolveMarkerValue(expression, state);
1057
1057
  if (value.kind === "function") {
1058
- state.unresolved.add(sourceOf4(expression));
1058
+ state.unresolved.add(oneLineTextOf4(expression));
1059
1059
  return;
1060
1060
  }
1061
1061
  if (value.kind === "nothing")
@@ -1121,15 +1121,15 @@ ${script}` : snippet,
1121
1121
  let next = text;
1122
1122
  for (let marker of markersIn(text, state)) {
1123
1123
  let expression = state.markers.get(marker);
1124
- expression && state.unresolved.add(sourceOf4(expression)), next = next.replace(marker, "");
1124
+ expression && state.unresolved.add(oneLineTextOf4(expression)), next = next.replace(marker, "");
1125
1125
  }
1126
1126
  return next;
1127
1127
  }, unresolvedMarkers = (text, state) => {
1128
1128
  for (let marker of markersIn(text, state)) {
1129
1129
  let expression = state.markers.get(marker);
1130
- expression && state.unresolved.add(sourceOf4(expression));
1130
+ expression && state.unresolved.add(oneLineTextOf4(expression));
1131
1131
  }
1132
- }, containsMarker = (text, state) => markersIn(text, state).length > 0, markersIn = (text, state) => [...state.markers.keys()].filter((marker) => text.includes(marker)), markerSources = (markers, state) => markers.map((marker) => state.markers.get(marker)).filter((expression) => expression !== void 0).map(sourceOf4).join(", "), attributeFromPrinted = (attribute) => {
1132
+ }, containsMarker = (text, state) => markersIn(text, state).length > 0, markersIn = (text, state) => [...state.markers.keys()].filter((marker) => text.includes(marker)), markerSources = (markers, state) => markers.map((marker) => state.markers.get(marker)).filter((expression) => expression !== void 0).map(oneLineTextOf4).join(", "), attributeFromPrinted = (attribute) => {
1133
1133
  if (!attribute)
1134
1134
  return;
1135
1135
  let [node] = parseHtml(`<x ${attribute}></x>`);
@@ -1143,434 +1143,6 @@ ${script}` : snippet,
1143
1143
  attributes[index] = next;
1144
1144
  };
1145
1145
 
1146
- // ../../core/src/csf-tools/story-shape/utils.ts
1147
- import { types as t4 } from "storybook/internal/babel";
1148
- var unwrapExpression4 = (node) => t4.isTSAsExpression(node) || t4.isTSSatisfiesExpression(node) || t4.isTSNonNullExpression(node) || t4.isTSTypeAssertion(node) || t4.isParenthesizedExpression(node) ? unwrapExpression4(node.expression) : node, isCanonicalCsf2BindCall = (node) => t4.isCallExpression(node) && t4.isMemberExpression(node.callee) && !node.callee.computed && t4.isIdentifier(node.callee.object) && t4.isIdentifier(node.callee.property, { name: "bind" }) && (node.arguments.length === 0 || node.arguments.length === 1 && t4.isObjectExpression(node.arguments[0]) && node.arguments[0].properties.length === 0), withoutTypeCalls = (object) => t4.isCallExpression(object) && object.arguments.length === 0 && t4.isMemberExpression(object.callee) && !object.callee.computed && t4.isIdentifier(object.callee.property, { name: "type" }) ? withoutTypeCalls(object.callee.object) : object, isCsfFactoryCall = (node) => t4.isCallExpression(node) && t4.isMemberExpression(node.callee) && !node.callee.computed && t4.isIdentifier(withoutTypeCalls(node.callee.object)) && t4.isIdentifier(node.callee.property) && (node.callee.property.name === "story" || node.callee.property.name === "extend"), csfFactoryReceiver = (node) => withoutTypeCalls(node.callee.object);
1149
- var keyOf3 = (p) => t4.isStringLiteral(p.key) ? p.key.value : !p.computed && t4.isIdentifier(p.key) ? p.key.name : null;
1150
- function resolveIdentifierInit(storyPath, identifier) {
1151
- let programPath = storyPath.findParent((p) => p.isProgram());
1152
- if (!programPath)
1153
- return null;
1154
- for (let stmt of programPath.get("body")) {
1155
- if (stmt.isFunctionDeclaration() && stmt.node.id?.name === identifier.node.name)
1156
- return stmt;
1157
- if (stmt.isExportNamedDeclaration()) {
1158
- let decl = stmt.get("declaration");
1159
- if (decl.isFunctionDeclaration() && decl.node.id?.name === identifier.node.name)
1160
- return decl;
1161
- }
1162
- }
1163
- let match = programPath.get("body").flatMap((stmt) => {
1164
- if (stmt.isVariableDeclaration())
1165
- return stmt.get("declarations");
1166
- if (stmt.isExportNamedDeclaration()) {
1167
- let decl = stmt.get("declaration");
1168
- if (decl && decl.isVariableDeclaration())
1169
- return decl.get("declarations");
1170
- }
1171
- return [];
1172
- }).find((d) => {
1173
- let id = d.get("id");
1174
- return id.isIdentifier() && id.node.name === identifier.node.name;
1175
- });
1176
- if (!match)
1177
- return null;
1178
- let init = match.get("init");
1179
- return init && init.isExpression() ? init : null;
1180
- }
1181
- function pathForNode(program, target) {
1182
- if (!target)
1183
- return;
1184
- let found;
1185
- return program.traverse({
1186
- enter(p) {
1187
- p.node && p.node === target && (found = p, p.stop());
1188
- }
1189
- }), found;
1190
- }
1191
- function metaObjectPath(csf) {
1192
- let metaPath = pathForNode(csf._file.path, csf._metaNode);
1193
- return metaPath?.isObjectExpression() ? metaPath : void 0;
1194
- }
1195
-
1196
- // ../../core/src/csf-tools/story-shape/normalize-story.ts
1197
- function normalizeStoryDeclaration(storyDeclaration) {
1198
- let storyPath = declarationExpression(storyDeclaration), normalizedPath = bindInitializer(storyDeclaration, storyPath) ?? factoryArgumentExpression(storyPath), unwrappedPath = unwrapTypeExpression(normalizedPath);
1199
- return classifyStoryPath(unwrappedPath);
1200
- }
1201
- function declarationExpression(storyDeclaration) {
1202
- if (storyDeclaration.isFunctionDeclaration())
1203
- return storyDeclaration;
1204
- if (storyDeclaration.isVariableDeclarator()) {
1205
- let init = storyDeclaration.get("init");
1206
- if (!init.isExpression())
1207
- throw storyDeclaration.buildCodeFrameError("Expected story initializer to be an expression");
1208
- return init;
1209
- }
1210
- throw storyDeclaration.buildCodeFrameError(
1211
- "Expected story to be a function or variable declaration"
1212
- );
1213
- }
1214
- function bindInitializer(storyDeclaration, storyPath) {
1215
- if (!storyPath.isCallExpression() || !isCanonicalCsf2BindCall(storyPath.node))
1216
- return null;
1217
- let callee = storyPath.get("callee");
1218
- if (!callee.isMemberExpression())
1219
- return null;
1220
- let obj = callee.get("object");
1221
- return obj.isIdentifier() ? resolveIdentifierInit(storyDeclaration, obj) : null;
1222
- }
1223
- function factoryArgumentExpression(storyPath) {
1224
- if (!storyPath.isCallExpression() || !isCsfFactoryCall(storyPath.node))
1225
- return storyPath;
1226
- let args = storyPath.get("arguments");
1227
- if (args.length === 0)
1228
- return storyPath;
1229
- if (args.length !== 1 || !args[0].isExpression())
1230
- throw storyPath.buildCodeFrameError("Could not evaluate story expression");
1231
- return args[0];
1232
- }
1233
- function unwrapTypeExpression(storyPath) {
1234
- return storyPath.isTSSatisfiesExpression() || storyPath.isTSAsExpression() ? storyPath.get("expression") : storyPath;
1235
- }
1236
- function classifyStoryPath(storyPath) {
1237
- if (storyPath.isObjectExpression())
1238
- return { type: "config", path: storyPath };
1239
- if (storyPath.isArrowFunctionExpression() || storyPath.isFunctionExpression() || storyPath.isFunctionDeclaration())
1240
- return { type: "fn", path: storyPath };
1241
- if (storyPath.isCallExpression() && isCsfFactoryCall(storyPath.node) && storyPath.node.arguments.length === 0)
1242
- return { type: "emptyConfig", path: storyPath };
1243
- throw storyPath.buildCodeFrameError(
1244
- "Expected story to be csf factory, function or an object expression"
1245
- );
1246
- }
1247
-
1248
- // ../../core/src/csf-tools/story-shape/resolve-members.ts
1249
- import { generate, types as t6 } from "storybook/internal/babel";
1250
-
1251
- // ../../core/src/csf-tools/story-shape/imports.ts
1252
- import { types as t5 } from "storybook/internal/babel";
1253
- var isTypeSpecifier = (s) => t5.isImportSpecifier(s) && s.importKind === "type", importedName = (im) => t5.isIdentifier(im) ? im.name : im.value;
1254
-
1255
- // ../../core/src/csf-tools/story-shape/resolve-members.ts
1256
- var sourceOf5 = (node) => generate(node, { concise: !0, comments: !1 }).code, complete = (properties = {}) => ({
1257
- properties,
1258
- shadowed: [],
1259
- unresolved: []
1260
- }), resolveObjectMembers = (object, ctx) => membersOf(object, ctx, /* @__PURE__ */ new Set());
1261
- var membersOf = (object, ctx, visited) => {
1262
- let properties = {}, unresolved = [], shadowed = /* @__PURE__ */ new Set(), shadowKnownMembers = (source) => {
1263
- unresolved.push(source);
1264
- for (let key of Object.keys(properties))
1265
- shadowed.add(key);
1266
- };
1267
- for (let property of object.properties) {
1268
- if (t6.isSpreadElement(property)) {
1269
- let spread = spreadMembers(ctx, property, visited);
1270
- if (spread === void 0 || spread.unresolved.length > 0) {
1271
- shadowKnownMembers(sourceOf5(property));
1272
- continue;
1273
- }
1274
- for (let [key2, value] of Object.entries(spread.properties))
1275
- properties[key2] = value, shadowed.delete(key2);
1276
- continue;
1277
- }
1278
- let key = keyOf3(property);
1279
- if (key === null) {
1280
- shadowKnownMembers(sourceOf5(property));
1281
- continue;
1282
- }
1283
- if (t6.isObjectMethod(property) && (property.kind !== "method" || property.generator)) {
1284
- delete properties[key], shadowed.delete(key), unresolved.push(sourceOf5(property));
1285
- continue;
1286
- }
1287
- properties[key] = t6.isObjectMethod(property) ? property : property.value, shadowed.delete(key);
1288
- }
1289
- return { properties, shadowed: [...shadowed], unresolved };
1290
- }, spreadMembers = (ctx, spread, visited) => {
1291
- let argument = unwrapExpression4(spread.argument);
1292
- return t6.isObjectExpression(argument) ? membersOf(argument, ctx, visited) : resolveReference(ctx, argument, spread.start ?? void 0, visited);
1293
- }, memberChain = (node) => {
1294
- let path = [], current2 = unwrapExpression4(node);
1295
- for (; t6.isMemberExpression(current2); ) {
1296
- let key = t6.isIdentifier(current2.property) && !current2.computed ? current2.property.name : t6.isStringLiteral(current2.property) ? current2.property.value : void 0;
1297
- if (key === void 0)
1298
- return;
1299
- path.unshift(key), current2 = unwrapExpression4(current2.object);
1300
- }
1301
- return t6.isIdentifier(current2) ? { root: current2.name, path } : void 0;
1302
- }, resolveReference = (ctx, expression, position, visited) => {
1303
- let chain = memberChain(expression);
1304
- if (!chain)
1305
- return;
1306
- let key = `ref:${ctx.filePath}#${chain.root}.${chain.path.join(".")}`;
1307
- if (!visited.has(key)) {
1308
- visited.add(key);
1309
- try {
1310
- return unguardedResolveReference(ctx, chain, position, visited);
1311
- } finally {
1312
- visited.delete(key);
1313
- }
1314
- }
1315
- }, unguardedResolveReference = (ctx, chain, position, visited) => {
1316
- let located = locate(ctx, chain, position, visited);
1317
- if (!located)
1318
- return;
1319
- let members = located.members, scope = located.ctx;
1320
- for (let [index, key] of located.path.entries()) {
1321
- if (members.unresolved.length > 0)
1322
- return;
1323
- let value = members.properties[key];
1324
- if (value === void 0)
1325
- return index === located.path.length - 1 ? complete() : void 0;
1326
- let unwrapped = unwrapExpression4(value);
1327
- if (!t6.isObjectExpression(unwrapped))
1328
- return;
1329
- members = membersOf(unwrapped, scope, visited);
1330
- }
1331
- return located.external ? externalized(members, scope) : members;
1332
- }, locate = (ctx, chain, position, visited) => {
1333
- let binding = bindingMembers(ctx, chain.root, position, visited);
1334
- if (!binding)
1335
- return;
1336
- if (binding.kind === "namespace") {
1337
- let [exportName, ...path] = chain.path;
1338
- if (exportName === void 0)
1339
- return;
1340
- let exported = bindingMembers(binding.ctx, exportName, void 0, visited);
1341
- if (exported === void 0 || exported.kind === "namespace")
1342
- return;
1343
- let located2 = withAccessor(exported, path);
1344
- return located2 === void 0 ? void 0 : { ...located2, external: !0 };
1345
- }
1346
- let located = withAccessor(binding, chain.path);
1347
- return located === void 0 ? void 0 : { ...located, external: binding.external };
1348
- }, withAccessor = (binding, path) => binding.accessor === void 0 ? { members: binding.members, ctx: binding.ctx, path } : path[0] === binding.accessor ? { members: binding.members, ctx: binding.ctx, path: path.slice(1) } : void 0, externalized = (members, ctx) => {
1349
- if (!ctx.externalize)
1350
- return members;
1351
- let properties = {};
1352
- for (let [key, node] of Object.entries(members.properties)) {
1353
- let value = ctx.externalize(node);
1354
- if (value === void 0)
1355
- return;
1356
- properties[key] = value;
1357
- }
1358
- return {
1359
- properties,
1360
- shadowed: members.shadowed,
1361
- unresolved: members.unresolved
1362
- };
1363
- }, bindingMembers = (ctx, name, position, visited) => {
1364
- let key = `${ctx.filePath}#${name}`;
1365
- if (!visited.has(key)) {
1366
- visited.add(key);
1367
- try {
1368
- return unguardedBindingMembers(ctx, name, position, visited);
1369
- } finally {
1370
- visited.delete(key);
1371
- }
1372
- }
1373
- }, unguardedBindingMembers = (ctx, name, position, visited) => {
1374
- let binding = ctx.program.scope.getBinding(name);
1375
- if (!binding)
1376
- return;
1377
- if (binding.kind === "module")
1378
- return importedBinding(ctx, binding.path, visited);
1379
- if (!binding.constant)
1380
- return;
1381
- let declared = declaredBindingMembers(ctx, binding.path.node, position, visited);
1382
- if (declared === void 0)
1383
- return;
1384
- let assigned = assignedMembers(ctx, name, position);
1385
- return {
1386
- kind: "members",
1387
- ctx,
1388
- external: !1,
1389
- ...declared.accessor ? { accessor: declared.accessor } : {},
1390
- members: {
1391
- properties: { ...declared.members.properties, ...assigned.properties },
1392
- shadowed: declared.members.shadowed.filter((key) => !(key in assigned.properties)),
1393
- unresolved: [...declared.members.unresolved, ...assigned.unresolved]
1394
- }
1395
- };
1396
- }, declaredBindingMembers = (ctx, node, position, visited) => {
1397
- if (t6.isFunctionDeclaration(node))
1398
- return { members: complete() };
1399
- if (t6.isVariableDeclarator(node) && !(position !== void 0 && (node.start ?? Number.POSITIVE_INFINITY) > position))
1400
- return node.init ? declaredMembers(ctx, node.init, position, visited) : { members: complete() };
1401
- }, declaredMembers = (ctx, init, position, visited) => {
1402
- let unwrapped = unwrapExpression4(init);
1403
- if (t6.isObjectExpression(unwrapped))
1404
- return { members: membersOf(unwrapped, ctx, visited) };
1405
- let factory = factoryCall(unwrapped);
1406
- if (factory === void 0 && (t6.isFunction(unwrapped) || isCanonicalCsf2BindCall(unwrapped)))
1407
- return { members: complete() };
1408
- if (factory === void 0)
1409
- return {
1410
- members: { properties: {}, shadowed: [], unresolved: [sourceOf5(unwrapped)] }
1411
- };
1412
- let config = factory.config ? membersOf(factory.config, ctx, visited) : complete();
1413
- if (factory.method === "story")
1414
- return { members: config, accessor: "input" };
1415
- let parent = bindingMembers(ctx, factory.parent, position, visited);
1416
- return parent === void 0 || parent.kind === "namespace" || parent.accessor !== "input" || parent.external ? void 0 : {
1417
- members: {
1418
- properties: mergedAnnotations(parent.members, config).properties,
1419
- shadowed: [
1420
- ...parent.members.shadowed.filter((key) => !(key in config.properties)),
1421
- ...config.shadowed
1422
- ],
1423
- unresolved: [...parent.members.unresolved, ...config.unresolved]
1424
- },
1425
- accessor: "input"
1426
- };
1427
- }, MERGED_ANNOTATIONS = ["args", "argTypes", "parameters", "globals"], mergedAnnotations = (parent, child) => {
1428
- let properties = { ...parent.properties, ...child.properties };
1429
- for (let key of MERGED_ANNOTATIONS) {
1430
- let from = parent.properties[key], over = child.properties[key];
1431
- from === void 0 || over === void 0 || !t6.isExpression(from) || !t6.isExpression(over) || (properties[key] = t6.objectExpression([t6.spreadElement(from), t6.spreadElement(over)]));
1432
- }
1433
- return { properties };
1434
- }, factoryCall = (node) => {
1435
- if (!isCsfFactoryCall(node))
1436
- return;
1437
- let method = node.callee.property.name;
1438
- if (method !== "story" && method !== "extend")
1439
- return;
1440
- let [argument] = node.arguments, config = argument && unwrapExpression4(argument);
1441
- if (!(argument !== void 0 && (config === void 0 || !t6.isObjectExpression(config))))
1442
- return {
1443
- method,
1444
- parent: csfFactoryReceiver(node).name,
1445
- ...config && t6.isObjectExpression(config) ? { config } : {}
1446
- };
1447
- }, assignedMembers = (ctx, name, position) => {
1448
- let properties = {}, unresolved = [];
1449
- for (let statement of ctx.program.node.body) {
1450
- if (!t6.isExpressionStatement(statement) || !t6.isAssignmentExpression(statement.expression))
1451
- continue;
1452
- let assignment = statement.expression, target = assignment.left, depth = 0, outermost;
1453
- for (; t6.isMemberExpression(target); )
1454
- depth += 1, outermost = t6.isIdentifier(target.property) && !target.computed ? target.property.name : t6.isStringLiteral(target.property) ? target.property.value : void 0, target = target.object;
1455
- if (!(depth === 0 || !t6.isIdentifier(target) || target.name !== name) && !(position !== void 0 && (assignment.start ?? 0) > position)) {
1456
- if (depth > 1 || outermost === void 0 || assignment.operator !== "=") {
1457
- unresolved.push(sourceOf5(assignment));
1458
- continue;
1459
- }
1460
- properties[outermost] = assignment.right;
1461
- }
1462
- }
1463
- return { properties, unresolved };
1464
- }, importedBinding = (ctx, specifierPath, visited) => {
1465
- let specifier = specifierPath.node, declaration = specifierPath.parent;
1466
- if (!t6.isImportDeclaration(declaration) || declaration.importKind === "type" || !(t6.isImportSpecifier(specifier) || t6.isImportDefaultSpecifier(specifier) || t6.isImportNamespaceSpecifier(specifier)) || isTypeSpecifier(specifier))
1467
- return;
1468
- let target = resolveTargetModule(ctx, declaration.source.value);
1469
- if (!target)
1470
- return;
1471
- if (t6.isImportNamespaceSpecifier(specifier))
1472
- return { kind: "namespace", ctx: target };
1473
- let exportName = t6.isImportDefaultSpecifier(specifier) ? "default" : importedName(specifier.imported);
1474
- return exportedBinding(target, exportName, visited);
1475
- }, resolveTargetModule = (ctx, specifier) => {
1476
- let target = ctx.resolveModule?.(ctx.filePath, specifier);
1477
- return target ? { ...ctx, ...target } : void 0;
1478
- }, exportedBinding = (ctx, exportName, visited) => {
1479
- let asExternal = (bound) => bound === void 0 || bound.kind === "namespace" ? bound : { ...bound, external: !0 };
1480
- for (let statement of ctx.program.node.body) {
1481
- if (t6.isExportDefaultDeclaration(statement) && exportName === "default") {
1482
- let declaration = unwrapExpression4(statement.declaration);
1483
- return t6.isIdentifier(declaration) ? asExternal(bindingMembers(ctx, declaration.name, void 0, visited)) : t6.isObjectExpression(declaration) ? {
1484
- kind: "members",
1485
- ctx,
1486
- external: !0,
1487
- members: membersOf(declaration, ctx, visited)
1488
- } : void 0;
1489
- }
1490
- if (!t6.isExportNamedDeclaration(statement) || statement.exportKind === "type")
1491
- continue;
1492
- let specifier = statement.specifiers.find(
1493
- (candidate) => t6.isExportSpecifier(candidate) && candidate.exportKind !== "type" && importedName(candidate.exported) === exportName
1494
- );
1495
- if (!specifier)
1496
- continue;
1497
- if (!statement.source)
1498
- return asExternal(bindingMembers(ctx, specifier.local.name, void 0, visited));
1499
- let target = resolveTargetModule(ctx, statement.source.value);
1500
- return target ? exportedBinding(target, specifier.local.name, visited) : void 0;
1501
- }
1502
- return exportName === "default" ? void 0 : asExternal(bindingMembers(ctx, exportName, void 0, visited));
1503
- };
1504
-
1505
- // ../../core/src/csf-tools/story-shape/render.ts
1506
- var isRenderFunction = (path) => path.isArrowFunctionExpression() || path.isFunctionExpression() || path.isFunctionDeclaration();
1507
- function resolveEffectiveRender(csf, exportName, references) {
1508
- let declaration = csf._storyDeclarationPath[exportName], normalized = normalizeStoryDeclarationForRender(declaration);
1509
- if (normalized.type === "fn")
1510
- return { kind: "resolved", path: normalized.path };
1511
- let storyRender = readRender(
1512
- normalized.type === "config" ? normalized.path : void 0,
1513
- declaration,
1514
- references
1515
- );
1516
- if (storyRender.kind === "invalid")
1517
- return { kind: "unresolved" };
1518
- if (storyRender.kind !== "missing")
1519
- return storyRender;
1520
- let metaRender = readRender(metaObjectPath(csf), declaration, references);
1521
- return metaRender.kind === "invalid" ? { kind: "unresolved" } : metaRender;
1522
- }
1523
- var normalizeStoryDeclarationForRender = normalizeStoryDeclaration, readRender = (config, storyDeclaration, references) => {
1524
- let properties = config?.get("properties") ?? [], renderIndex = -1;
1525
- for (let index = properties.length - 1; index >= 0; index -= 1) {
1526
- let property = properties[index];
1527
- if ((property.isObjectProperty() || property.isObjectMethod()) && keyOf3(property.node) === "render") {
1528
- renderIndex = index;
1529
- break;
1530
- }
1531
- }
1532
- let throughSpreads = () => config && references ? renderFromMembers(
1533
- resolveObjectMembers(config.node, references),
1534
- references,
1535
- storyDeclaration
1536
- ) : { kind: "unresolved" };
1537
- if (renderIndex === -1)
1538
- return properties.some((property) => property.isSpreadElement()) ? throughSpreads() : { kind: "missing" };
1539
- let resolved = readRenderProperty(properties[renderIndex], storyDeclaration);
1540
- if (properties.some((property, index) => index > renderIndex && property.isSpreadElement())) {
1541
- let read = throughSpreads();
1542
- return read.kind !== "unresolved" ? read : resolved.kind === "resolved" ? { kind: "unresolved", shadowedRender: resolved.path } : { kind: "unresolved" };
1543
- }
1544
- return resolved;
1545
- };
1546
- function renderFromMembers(members, references, storyDeclaration) {
1547
- if (members.unresolved.length > 0)
1548
- return { kind: "unresolved" };
1549
- let node = members.properties.render;
1550
- if (node === void 0)
1551
- return { kind: "missing" };
1552
- let path = pathForNode(references.program, node);
1553
- if (!path)
1554
- return { kind: "unresolved" };
1555
- if (path.isObjectMethod())
1556
- return path.node.kind === "method" && !path.node.generator ? { kind: "resolved", path } : { kind: "unresolved" };
1557
- if (path.isIdentifier()) {
1558
- let resolved = resolveIdentifierInit(storyDeclaration, path);
1559
- return resolved && isRenderFunction(resolved) ? { kind: "resolved", path: resolved } : { kind: "unresolved" };
1560
- }
1561
- return isRenderFunction(path) ? { kind: "resolved", path } : { kind: "unresolved" };
1562
- }
1563
- function readRenderProperty(renderProperty, storyDeclaration) {
1564
- if (renderProperty.isObjectMethod())
1565
- return renderProperty.node.kind === "method" && !renderProperty.node.generator ? { kind: "resolved", path: renderProperty } : { kind: "unresolved" };
1566
- let renderPath = renderProperty.get("value");
1567
- if (renderPath.isIdentifier()) {
1568
- let resolved = resolveIdentifierInit(storyDeclaration, renderPath);
1569
- return resolved && isRenderFunction(resolved) ? { kind: "resolved", path: resolved } : { kind: "unresolved" };
1570
- }
1571
- return isRenderFunction(renderPath) ? { kind: "resolved", path: renderPath } : { kind: "invalid", path: renderPath };
1572
- }
1573
-
1574
1146
  // src/docgen/story-docs/build-story-docs.ts
1575
1147
  var NO_COMPONENT_WARNING = "No static snippet: `meta.component` is not set.", openStoryReferences = createStoryReferenceResolver();
1576
1148
  async function buildStoryDocsPayload(input, context) {
@@ -1625,7 +1197,10 @@ var buildPayload = (input, storyImportPath, csf, snippetFor, name) => {
1625
1197
  filePath: storyFilePath,
1626
1198
  resolveModule: openStoryReferences().resolveModule
1627
1199
  }), baseStoryDoc = (csf, exportName, story, result) => {
1628
- let { description, summary } = extractStoryJSDocInfo(csf._storyStatements[exportName]);
1200
+ let { description, summary } = extractStoryJSDocInfo(
1201
+ csf._storyStatements[exportName],
1202
+ csf.editor
1203
+ );
1629
1204
  return {
1630
1205
  id: story.id,
1631
1206
  name: story.name ?? storyNameFromExport(exportName),
@@ -1664,7 +1239,7 @@ var buildPayload = (input, storyImportPath, csf, snippetFor, name) => {
1664
1239
  }, renderedArgsSnippet = (exportName, resolved, deps) => {
1665
1240
  let warnings = [], render = resolveEffectiveRender(deps.csf, exportName, deps.resolveStoryArgs.ctx);
1666
1241
  if (render.kind === "resolved") {
1667
- let template = resolveHtmlTemplate(render.path, deps.csf);
1242
+ let template = resolveHtmlTemplate(render.node, deps.csf);
1668
1243
  if (template) {
1669
1244
  let printed = printHtmlTemplate(template, resolved.args, deps.declaration), unresolved = [...resolved.unresolved, ...printed.unresolved];
1670
1245
  warnings.push(unresolvedWarning(unresolved)), warnings.push(incompleteList(printed.properties, "properties without an attribute")), warnings.push(
@@ -1676,7 +1251,7 @@ var buildPayload = (input, storyImportPath, csf, snippetFor, name) => {
1676
1251
  ...joinWarnings(hasSnippet ? warnings : [...warnings, noSnippetWarning(unresolved)])
1677
1252
  };
1678
1253
  }
1679
- warnings.push(unresolvedWarning([sourceOf6(render.path.node)]));
1254
+ warnings.push(unresolvedWarning([oneLineTextOf5(render.node)]));
1680
1255
  } else render.kind === "unresolved" && warnings.push(unresolvedWarning(unresolvedRenderSource(render, resolved)));
1681
1256
  let args = argsSnippet(
1682
1257
  resolved.args,
@@ -1693,8 +1268,8 @@ var buildPayload = (input, storyImportPath, csf, snippetFor, name) => {
1693
1268
  let bound = new Set(referenced), unbound = Object.entries(args).filter(([name, node]) => !bound.has(name) && evaluateArgValue(node).kind !== "unset").map(([name]) => name);
1694
1269
  return incompleteList(unbound, "args not bound by the render template");
1695
1270
  }, unresolvedRenderSource = (render, resolved) => {
1696
- let node = resolved.storyMembers.properties.render ?? resolved.metaMembers.properties.render ?? render.shadowedRender?.node;
1697
- return node ? [sourceOf6(node)] : [];
1271
+ let node = resolved.storyMembers.properties.render ?? resolved.metaMembers.properties.render ?? render.shadowedRender;
1272
+ return node ? [oneLineTextOf5(node)] : [];
1698
1273
  }, argsSnippet = (args, declaration, argTypes, tag, unresolvedArgs) => {
1699
1274
  let snippet = {
1700
1275
  tag,
@@ -1788,10 +1363,7 @@ var buildPayload = (input, storyImportPath, csf, snippetFor, name) => {
1788
1363
  return;
1789
1364
  }
1790
1365
  items[index] = next;
1791
- }, falseDefaultAttributes = (snippet) => snippet.attributes.filter(({ value, defaultValue }) => value === !1 && defaultValue === "true").map(({ source, name }) => source ?? name), hasSnippetContent = (snippet) => snippet.attributes.length > 0 || snippet.cssProperties.length > 0 || snippet.listeners.length > 0 || snippet.slots.length > 0 || snippet.styleRules.length > 0, listenerHandler2 = (node) => {
1792
- let unwrapped = t7.isExpression(node) ? unwrapExpression5(node) : node;
1793
- return t7.isFunction(unwrapped) ? sourceOf6(node) : "() => {}";
1794
- }, incompleteList = (names, suffix) => names.length === 0 ? void 0 : `Incomplete snippet: ${suffix}: ${names.map((name) => `\`${name}\``).join(", ")}.`, joinWarnings = (parts) => {
1366
+ }, falseDefaultAttributes = (snippet) => snippet.attributes.filter(({ value, defaultValue }) => value === !1 && defaultValue === "true").map(({ source, name }) => source ?? name), hasSnippetContent = (snippet) => snippet.attributes.length > 0 || snippet.cssProperties.length > 0 || snippet.listeners.length > 0 || snippet.slots.length > 0 || snippet.styleRules.length > 0, listenerHandler2 = (node) => isFunctionNode(unwrapExpression4(node)) ? handlerText(node) : "() => {}", incompleteList = (names, suffix) => names.length === 0 ? void 0 : `Incomplete snippet: ${suffix}: ${names.map((name) => `\`${name}\``).join(", ")}.`, joinWarnings = (parts) => {
1795
1367
  let warning = [...new Set(parts.filter((part) => part !== void 0))].join(`
1796
1368
  `);
1797
1369
  return warning === "" ? {} : { warning };