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

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.
@@ -137,7 +137,7 @@ var { Node: Node2 } = global, render = (args, context) => {
137
137
  }
138
138
  return fragment.append(element), fragment;
139
139
  };
140
- function renderToCanvas({ storyFn, kind, name, showMain, showError, forceRemount }, canvasElement) {
140
+ function renderToCanvas({ storyFn, title, name, showMain, showError, forceRemount }, canvasElement) {
141
141
  let element = storyFn();
142
142
  if (showMain(), isTemplateResult(element)) {
143
143
  (forceRemount || !canvasElement.querySelector('[id="root-inner"]')) && (canvasElement.innerHTML = '<div id="root-inner"></div>');
@@ -151,7 +151,7 @@ function renderToCanvas({ storyFn, kind, name, showMain, showError, forceRemount
151
151
  canvasElement.innerHTML = "", canvasElement.appendChild(element), simulateDOMContentLoaded();
152
152
  } else
153
153
  showError({
154
- title: `Expecting an HTML snippet or DOM node from the story: "${name}" of "${kind}".`,
154
+ title: `Expecting an HTML snippet or DOM node from the story: "${name}" of "${title}".`,
155
155
  description: dedent`
156
156
  Did you forget to return the HTML snippet from the story?
157
157
  Use "() => <your snippet or node>" or when defining the story.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  entry_preview_exports
3
- } from "./chunk-BNL7LBNI.js";
3
+ } from "./chunk-CAPEJO4V.js";
4
4
  import {
5
5
  entry_preview_docs_exports
6
6
  } from "./chunk-EGBR6PF2.js";
@@ -15,6 +15,8 @@ globalWindow.STORYBOOK_ENV = "web-components";
15
15
 
16
16
  // src/framework-api.ts
17
17
  import { global as global2 } from "@storybook/global";
18
+ import { deprecate } from "storybook/internal/client-logger";
19
+ var RUNTIME_MANIFEST_DEPRECATION = "The runtime Custom Elements Manifest is deprecated and will be removed in Storybook 12. Set framework.options.customElementsManifest in .storybook/main and enable features.docgenServer instead.";
18
20
  function isValidComponent(tagName) {
19
21
  if (!tagName)
20
22
  return !1;
@@ -27,17 +29,18 @@ function isValidMetaData(customElements) {
27
29
  return !1;
28
30
  if (customElements.tags && Array.isArray(customElements.tags) || customElements.modules && Array.isArray(customElements.modules))
29
31
  return !0;
30
- throw new Error(`You need to setup valid meta data in your config.js via setCustomElements().
31
- See the readme of addon-docs for web components for more details.`);
32
+ throw new Error(
33
+ "You need to set up valid Custom Elements metadata with a manifest generated by @custom-elements-manifest/analyzer. Configure it with framework.options.customElementsManifest in .storybook/main."
34
+ );
32
35
  }
33
36
  function setCustomElements(customElements) {
34
- global2.__STORYBOOK_CUSTOM_ELEMENTS__ = customElements;
37
+ deprecate(`setCustomElements() is deprecated: ${RUNTIME_MANIFEST_DEPRECATION}`), global2.__STORYBOOK_CUSTOM_ELEMENTS__ = customElements;
35
38
  }
36
39
  function setCustomElementsManifest(customElements) {
37
- global2.__STORYBOOK_CUSTOM_ELEMENTS_MANIFEST__ = customElements;
40
+ deprecate(`setCustomElementsManifest() is deprecated: ${RUNTIME_MANIFEST_DEPRECATION}`), global2.__STORYBOOK_CUSTOM_ELEMENTS_MANIFEST__ = customElements;
38
41
  }
39
42
  function getCustomElements() {
40
- return global2.__STORYBOOK_CUSTOM_ELEMENTS__ || global2.__STORYBOOK_CUSTOM_ELEMENTS_MANIFEST__;
43
+ return global2.__STORYBOOK_CUSTOM_ELEMENTS_MANIFEST__ || global2.__STORYBOOK_CUSTOM_ELEMENTS__;
41
44
  }
42
45
 
43
46
  // src/portable-stories.ts
@@ -0,0 +1,45 @@
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";
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);
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 { loadCsf, unwrapExpression } from "storybook/internal/csf-tools";
15
+ import { recast, types as t } from "storybook/internal/babel";
16
+ import { readFileSync } from "node:fs";
17
+ function parseStoryFile(storyFilePath, title) {
18
+ try {
19
+ let source = readFileSync(storyFilePath, "utf8");
20
+ return loadCsf(source, { makeTitle: () => title }).parse();
21
+ } catch {
22
+ return;
23
+ }
24
+ }
25
+ var expressionFor = (node) => recast.print(node).code;
26
+ function tagFromNode(node) {
27
+ let expression = expressionFor(node), unwrapped = unwrapExpression(node);
28
+ if (t.isStringLiteral(unwrapped) && unwrapped.value !== "")
29
+ return { tag: unwrapped.value };
30
+ if (t.isTemplateLiteral(unwrapped) && unwrapped.expressions.length === 0) {
31
+ let tag = unwrapped.quasis[0]?.value.cooked;
32
+ if (tag)
33
+ return { tag };
34
+ }
35
+ return { reason: "component-not-a-tag", expression };
36
+ }
37
+ function resolveStoryComponent(csf) {
38
+ let component = csf._metaAnnotations.component;
39
+ return component ? tagFromNode(component) : { reason: "no-meta-component" };
40
+ }
41
+
42
+ export {
43
+ parseStoryFile,
44
+ resolveStoryComponent
45
+ };