@storybook/web-components 10.1.0-alpha.1 → 10.1.0-alpha.11

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,9 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: !0 });
5
+ };
6
+
7
+ export {
8
+ __export
9
+ };
@@ -1,7 +1,6 @@
1
1
  import {
2
- __export,
3
- __name
4
- } from "./chunk-JFJ5UJ7Q.js";
2
+ __export
3
+ } from "./chunk-4BE7D4DS.js";
5
4
 
6
5
  // src/entry-preview.ts
7
6
  var entry_preview_exports = {};
@@ -17,41 +16,30 @@ import { render as litRender } from "lit";
17
16
  import { isTemplateResult } from "lit/directive-helpers.js";
18
17
  import { simulateDOMContentLoaded, simulatePageLoad } from "storybook/preview-api";
19
18
  import { dedent } from "ts-dedent";
20
- var { Node } = global;
21
- var render = /* @__PURE__ */ __name((args, context) => {
22
- const { id, component } = context;
23
- if (!component) {
19
+ var { Node } = global, render = (args, context) => {
20
+ let { id, component } = context;
21
+ if (!component)
24
22
  throw new Error(
25
23
  `Unable to render story ${id} as the component annotation is missing from the default export`
26
24
  );
27
- }
28
- const element = document.createElement(component);
29
- Object.entries(args).forEach(([key, val]) => {
25
+ let element = document.createElement(component);
26
+ return Object.entries(args).forEach(([key, val]) => {
30
27
  element[key] = val;
31
- });
32
- return element;
33
- }, "render");
28
+ }), element;
29
+ };
34
30
  function renderToCanvas({ storyFn, kind, name, showMain, showError, forceRemount }, canvasElement) {
35
- const element = storyFn();
36
- showMain();
37
- if (isTemplateResult(element)) {
38
- if (forceRemount || !canvasElement.querySelector('[id="root-inner"]')) {
39
- canvasElement.innerHTML = '<div id="root-inner"></div>';
40
- }
41
- const renderTo = canvasElement.querySelector('[id="root-inner"]');
42
- litRender(element, renderTo);
43
- simulatePageLoad(canvasElement);
44
- } else if (typeof element === "string") {
45
- canvasElement.innerHTML = element;
46
- simulatePageLoad(canvasElement);
47
- } else if (element instanceof Node) {
48
- if (canvasElement.firstChild === element && !forceRemount) {
31
+ let element = storyFn();
32
+ if (showMain(), isTemplateResult(element)) {
33
+ (forceRemount || !canvasElement.querySelector('[id="root-inner"]')) && (canvasElement.innerHTML = '<div id="root-inner"></div>');
34
+ let renderTo = canvasElement.querySelector('[id="root-inner"]');
35
+ litRender(element, renderTo), simulatePageLoad(canvasElement);
36
+ } else if (typeof element == "string")
37
+ canvasElement.innerHTML = element, simulatePageLoad(canvasElement);
38
+ else if (element instanceof Node) {
39
+ if (canvasElement.firstChild === element && !forceRemount)
49
40
  return;
50
- }
51
- canvasElement.innerHTML = "";
52
- canvasElement.appendChild(element);
53
- simulateDOMContentLoaded();
54
- } else {
41
+ canvasElement.innerHTML = "", canvasElement.appendChild(element), simulateDOMContentLoaded();
42
+ } else
55
43
  showError({
56
44
  title: `Expecting an HTML snippet or DOM node from the story: "${name}" of "${kind}".`,
57
45
  description: dedent`
@@ -59,9 +47,7 @@ function renderToCanvas({ storyFn, kind, name, showMain, showError, forceRemount
59
47
  Use "() => <your snippet or node>" or when defining the story.
60
48
  `
61
49
  });
62
- }
63
50
  }
64
- __name(renderToCanvas, "renderToCanvas");
65
51
 
66
52
  // src/entry-preview.ts
67
53
  var parameters = {
@@ -1,9 +1,6 @@
1
1
  import {
2
2
  entry_preview_exports
3
- } from "./chunk-NIAEHH3S.js";
4
- import {
5
- __name
6
- } from "./chunk-JFJ5UJ7Q.js";
3
+ } from "./chunk-UN5GYDGC.js";
7
4
 
8
5
  // src/index.ts
9
6
  import { global as global3 } from "@storybook/global";
@@ -16,38 +13,29 @@ globalWindow.STORYBOOK_ENV = "web-components";
16
13
  // src/framework-api.ts
17
14
  import { global as global2 } from "@storybook/global";
18
15
  function isValidComponent(tagName) {
19
- if (!tagName) {
20
- return false;
21
- }
22
- if (typeof tagName === "string") {
23
- return true;
24
- }
16
+ if (!tagName)
17
+ return !1;
18
+ if (typeof tagName == "string")
19
+ return !0;
25
20
  throw new Error('Provided component needs to be a string. e.g. component: "my-element"');
26
21
  }
27
- __name(isValidComponent, "isValidComponent");
28
22
  function isValidMetaData(customElements) {
29
- if (!customElements) {
30
- return false;
31
- }
32
- if (customElements.tags && Array.isArray(customElements.tags) || customElements.modules && Array.isArray(customElements.modules)) {
33
- return true;
34
- }
23
+ if (!customElements)
24
+ return !1;
25
+ if (customElements.tags && Array.isArray(customElements.tags) || customElements.modules && Array.isArray(customElements.modules))
26
+ return !0;
35
27
  throw new Error(`You need to setup valid meta data in your config.js via setCustomElements().
36
28
  See the readme of addon-docs for web components for more details.`);
37
29
  }
38
- __name(isValidMetaData, "isValidMetaData");
39
30
  function setCustomElements(customElements) {
40
31
  global2.__STORYBOOK_CUSTOM_ELEMENTS__ = customElements;
41
32
  }
42
- __name(setCustomElements, "setCustomElements");
43
33
  function setCustomElementsManifest(customElements) {
44
34
  global2.__STORYBOOK_CUSTOM_ELEMENTS_MANIFEST__ = customElements;
45
35
  }
46
- __name(setCustomElementsManifest, "setCustomElementsManifest");
47
36
  function getCustomElements() {
48
37
  return global2.__STORYBOOK_CUSTOM_ELEMENTS__ || global2.__STORYBOOK_CUSTOM_ELEMENTS_MANIFEST__;
49
38
  }
50
- __name(getCustomElements, "getCustomElements");
51
39
 
52
40
  // src/portable-stories.ts
53
41
  import {
@@ -55,28 +43,20 @@ import {
55
43
  setDefaultProjectAnnotations
56
44
  } from "storybook/preview-api";
57
45
  function setProjectAnnotations(projectAnnotations) {
58
- setDefaultProjectAnnotations(entry_preview_exports);
59
- return originalSetProjectAnnotations(
46
+ return setDefaultProjectAnnotations(entry_preview_exports), originalSetProjectAnnotations(
60
47
  projectAnnotations
61
48
  );
62
49
  }
63
- __name(setProjectAnnotations, "setProjectAnnotations");
64
50
 
65
51
  // src/index.ts
66
52
  var { window, EventSource } = global3;
67
- if (typeof module !== "undefined" && module?.hot?.decline) {
68
- module.hot.decline();
69
- const hmr = new EventSource("__webpack_hmr");
70
- hmr.addEventListener("message", /* @__PURE__ */ __name(function fullPageReload(event) {
71
- try {
72
- const { action } = JSON.parse(event.data);
73
- if (action === "built") {
74
- window.location.reload();
75
- }
76
- } catch (error) {
77
- }
78
- }, "fullPageReload"));
79
- }
53
+ typeof module < "u" && module?.hot?.decline && (module.hot.decline(), new EventSource("__webpack_hmr").addEventListener("message", function(event) {
54
+ try {
55
+ let { action } = JSON.parse(event.data);
56
+ action === "built" && window.location.reload();
57
+ } catch {
58
+ }
59
+ }));
80
60
 
81
61
  export {
82
62
  isValidComponent,
@@ -2,11 +2,9 @@ import {
2
2
  getCustomElements,
3
3
  isValidComponent,
4
4
  isValidMetaData
5
- } from "./_browser-chunks/chunk-CTBWQQZK.js";
6
- import "./_browser-chunks/chunk-NIAEHH3S.js";
7
- import {
8
- __name
9
- } from "./_browser-chunks/chunk-JFJ5UJ7Q.js";
5
+ } from "./_browser-chunks/chunk-XQFQKYGQ.js";
6
+ import "./_browser-chunks/chunk-UN5GYDGC.js";
7
+ import "./_browser-chunks/chunk-4BE7D4DS.js";
10
8
 
11
9
  // src/entry-preview-argtypes.ts
12
10
  import { enhanceArgTypes } from "storybook/internal/docs-tools";
@@ -30,7 +28,7 @@ function mapItem(item, category) {
30
28
  }
31
29
  return {
32
30
  name: item.name,
33
- required: false,
31
+ required: !1,
34
32
  description: item.description,
35
33
  type,
36
34
  table: {
@@ -42,25 +40,18 @@ function mapItem(item, category) {
42
40
  }
43
41
  };
44
42
  }
45
- __name(mapItem, "mapItem");
46
43
  function mapEvent(item) {
47
- let name = item.name.replace(/(-|_|:|\.|\s)+(.)?/g, (_match, _separator, chr) => {
48
- return chr ? chr.toUpperCase() : "";
49
- }).replace(/^([A-Z])/, (match) => match.toLowerCase());
50
- name = `on${name.charAt(0).toUpperCase() + name.substr(1)}`;
51
- return [{ name, action: { name: item.name }, table: { disable: true } }, mapItem(item, "events")];
44
+ let name = item.name.replace(/(-|_|:|\.|\s)+(.)?/g, (_match, _separator, chr) => chr ? chr.toUpperCase() : "").replace(/^([A-Z])/, (match) => match.toLowerCase());
45
+ return name = `on${name.charAt(0).toUpperCase() + name.substr(1)}`, [{ name, action: { name: item.name }, table: { disable: !0 } }, mapItem(item, "events")];
52
46
  }
53
- __name(mapEvent, "mapEvent");
54
47
  function mapData(data, category) {
55
48
  return data && data.filter((item) => item && item.name).reduce((acc, item) => {
56
- if (item.kind === "method") {
49
+ if (item.kind === "method")
57
50
  return acc;
58
- }
59
51
  switch (category) {
60
52
  case "events":
61
53
  mapEvent(item).forEach((argType) => {
62
- invariant(argType.name, `${argType} should have a name property.`);
63
- acc[argType.name] = argType;
54
+ invariant(argType.name, `${argType} should have a name property.`), acc[argType.name] = argType;
64
55
  });
65
56
  break;
66
57
  default:
@@ -70,44 +61,24 @@ function mapData(data, category) {
70
61
  return acc;
71
62
  }, {});
72
63
  }
73
- __name(mapData, "mapData");
74
- var getMetaDataExperimental = /* @__PURE__ */ __name((tagName, customElements) => {
75
- if (!isValidComponent(tagName) || !isValidMetaData(customElements)) {
64
+ var getMetaDataExperimental = (tagName, customElements) => {
65
+ if (!isValidComponent(tagName) || !isValidMetaData(customElements))
76
66
  return null;
77
- }
78
- const metaData = customElements.tags.find(
67
+ let metaData = customElements.tags.find(
79
68
  (tag) => tag.name.toUpperCase() === tagName.toUpperCase()
80
69
  );
81
- if (!metaData) {
82
- logger.warn(`Component not found in custom-elements.json: ${tagName}`);
83
- }
84
- return metaData;
85
- }, "getMetaDataExperimental");
86
- var getMetaDataV1 = /* @__PURE__ */ __name((tagName, customElements) => {
87
- if (!isValidComponent(tagName) || !isValidMetaData(customElements)) {
70
+ return metaData || logger.warn(`Component not found in custom-elements.json: ${tagName}`), metaData;
71
+ }, getMetaDataV1 = (tagName, customElements) => {
72
+ if (!isValidComponent(tagName) || !isValidMetaData(customElements))
88
73
  return null;
89
- }
90
74
  let metadata;
91
- customElements?.modules?.forEach((_module) => {
75
+ return customElements?.modules?.forEach((_module) => {
92
76
  _module?.declarations?.forEach((declaration) => {
93
- if (declaration.tagName === tagName) {
94
- metadata = declaration;
95
- }
77
+ declaration.tagName === tagName && (metadata = declaration);
96
78
  });
97
- });
98
- if (!metadata) {
99
- logger.warn(`Component not found in custom-elements.json: ${tagName}`);
100
- }
101
- return metadata;
102
- }, "getMetaDataV1");
103
- var getMetaData = /* @__PURE__ */ __name((tagName, manifest) => {
104
- if (manifest?.version === "experimental") {
105
- return getMetaDataExperimental(tagName, manifest);
106
- }
107
- return getMetaDataV1(tagName, manifest);
108
- }, "getMetaData");
109
- var extractArgTypesFromElements = /* @__PURE__ */ __name((tagName, customElements) => {
110
- const metaData = getMetaData(tagName, customElements);
79
+ }), metadata || logger.warn(`Component not found in custom-elements.json: ${tagName}`), metadata;
80
+ }, getMetaData = (tagName, manifest) => manifest?.version === "experimental" ? getMetaDataExperimental(tagName, manifest) : getMetaDataV1(tagName, manifest), extractArgTypesFromElements = (tagName, customElements) => {
81
+ let metaData = getMetaData(tagName, customElements);
111
82
  return metaData && {
112
83
  ...mapData(metaData.members ?? [], "properties"),
113
84
  ...mapData(metaData.properties ?? [], "properties"),
@@ -117,15 +88,13 @@ var extractArgTypesFromElements = /* @__PURE__ */ __name((tagName, customElement
117
88
  ...mapData(metaData.cssProperties ?? [], "css custom properties"),
118
89
  ...mapData(metaData.cssParts ?? [], "css shadow parts")
119
90
  };
120
- }, "extractArgTypesFromElements");
121
- var extractArgTypes = /* @__PURE__ */ __name((tagName) => {
122
- const cem = getCustomElements();
91
+ }, extractArgTypes = (tagName) => {
92
+ let cem = getCustomElements();
123
93
  return extractArgTypesFromElements(tagName, cem);
124
- }, "extractArgTypes");
125
- var extractComponentDescription = /* @__PURE__ */ __name((tagName) => {
126
- const metaData = getMetaData(tagName, getCustomElements());
94
+ }, extractComponentDescription = (tagName) => {
95
+ let metaData = getMetaData(tagName, getCustomElements());
127
96
  return metaData && metaData.description;
128
- }, "extractComponentDescription");
97
+ };
129
98
 
130
99
  // src/entry-preview-argtypes.ts
131
100
  var parameters = {
@@ -133,8 +102,7 @@ var parameters = {
133
102
  extractArgTypes,
134
103
  extractComponentDescription
135
104
  }
136
- };
137
- var argTypesEnhancers = [enhanceArgTypes];
105
+ }, argTypesEnhancers = [enhanceArgTypes];
138
106
  export {
139
107
  argTypesEnhancers,
140
108
  parameters
@@ -1,6 +1,4 @@
1
- import {
2
- __name
3
- } from "./_browser-chunks/chunk-JFJ5UJ7Q.js";
1
+ import "./_browser-chunks/chunk-4BE7D4DS.js";
4
2
 
5
3
  // src/entry-preview-docs.ts
6
4
  import { SourceType as SourceType2 } from "storybook/internal/docs-tools";
@@ -11,45 +9,28 @@ import { render } from "lit";
11
9
  import { emitTransformCode, useEffect } from "storybook/preview-api";
12
10
  var LIT_EXPRESSION_COMMENTS = /<!--\?lit\$[0-9]+\$-->|<!--\??-->/g;
13
11
  function skipSourceRender(context) {
14
- const sourceParams = context?.parameters.docs?.source;
15
- const isArgsStory = context?.parameters.__isArgsStory;
16
- if (sourceParams?.type === SourceType.DYNAMIC) {
17
- return false;
18
- }
19
- return !isArgsStory || sourceParams?.code || sourceParams?.type === SourceType.CODE;
12
+ let sourceParams = context?.parameters.docs?.source, isArgsStory = context?.parameters.__isArgsStory;
13
+ return sourceParams?.type === SourceType.DYNAMIC ? !1 : !isArgsStory || sourceParams?.code || sourceParams?.type === SourceType.CODE;
20
14
  }
21
- __name(skipSourceRender, "skipSourceRender");
22
15
  function sourceDecorator(storyFn, context) {
23
- const story = storyFn();
24
- const renderedForSource = context?.parameters.docs?.source?.excludeDecorators ? context.originalStoryFn(context.args, context) : story;
25
- let source;
26
- useEffect(() => {
27
- if (source) {
28
- emitTransformCode(source, context);
29
- }
30
- });
31
- if (!skipSourceRender(context)) {
32
- const container = window.document.createElement("div");
33
- if (renderedForSource instanceof DocumentFragment) {
34
- render(renderedForSource.cloneNode(true), container);
35
- } else {
36
- render(renderedForSource, container);
37
- }
38
- source = container.innerHTML.replace(LIT_EXPRESSION_COMMENTS, "");
16
+ let story = storyFn(), renderedForSource = context?.parameters.docs?.source?.excludeDecorators ? context.originalStoryFn(context.args, context) : story, source;
17
+ if (useEffect(() => {
18
+ source && emitTransformCode(source, context);
19
+ }), !skipSourceRender(context)) {
20
+ let container = window.document.createElement("div");
21
+ renderedForSource instanceof DocumentFragment ? render(renderedForSource.cloneNode(!0), container) : render(renderedForSource, container), source = container.innerHTML.replace(LIT_EXPRESSION_COMMENTS, "");
39
22
  }
40
23
  return story;
41
24
  }
42
- __name(sourceDecorator, "sourceDecorator");
43
25
 
44
26
  // src/entry-preview-docs.ts
45
- var decorators = [sourceDecorator];
46
- var parameters = {
27
+ var decorators = [sourceDecorator], parameters = {
47
28
  docs: {
48
29
  source: {
49
30
  type: SourceType2.DYNAMIC,
50
31
  language: "html"
51
32
  },
52
- story: { inline: true }
33
+ story: { inline: !0 }
53
34
  }
54
35
  };
55
36
  export {
@@ -2,8 +2,8 @@ import {
2
2
  parameters,
3
3
  render,
4
4
  renderToCanvas
5
- } from "./_browser-chunks/chunk-NIAEHH3S.js";
6
- import "./_browser-chunks/chunk-JFJ5UJ7Q.js";
5
+ } from "./_browser-chunks/chunk-UN5GYDGC.js";
6
+ import "./_browser-chunks/chunk-4BE7D4DS.js";
7
7
  export {
8
8
  parameters,
9
9
  render,
package/dist/index.js CHANGED
@@ -5,9 +5,9 @@ import {
5
5
  setCustomElements,
6
6
  setCustomElementsManifest,
7
7
  setProjectAnnotations
8
- } from "./_browser-chunks/chunk-CTBWQQZK.js";
9
- import "./_browser-chunks/chunk-NIAEHH3S.js";
10
- import "./_browser-chunks/chunk-JFJ5UJ7Q.js";
8
+ } from "./_browser-chunks/chunk-XQFQKYGQ.js";
9
+ import "./_browser-chunks/chunk-UN5GYDGC.js";
10
+ import "./_browser-chunks/chunk-4BE7D4DS.js";
11
11
  export {
12
12
  getCustomElements,
13
13
  isValidComponent,
package/dist/preset.js CHANGED
@@ -1,26 +1,26 @@
1
- import CJS_COMPAT_NODE_URL_m2q8l9h37u from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_m2q8l9h37u from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_m2q8l9h37u from "node:module";
1
+ import CJS_COMPAT_NODE_URL_svyss76repj from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_svyss76repj from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_svyss76repj from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_m2q8l9h37u.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_m2q8l9h37u.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_m2q8l9h37u.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_svyss76repj.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_svyss76repj.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_svyss76repj.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
11
  // ------------------------------------------------------------
12
- var __defProp = Object.defineProperty;
13
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
14
12
 
15
13
  // src/preset.ts
16
14
  import { fileURLToPath } from "node:url";
17
- var previewAnnotations = /* @__PURE__ */ __name(async (input = [], options) => {
18
- const docsEnabled = Object.keys(await options.presets.apply("docs", {}, options)).length > 0;
19
- const result = [];
20
- return result.concat(input).concat([fileURLToPath(import.meta.resolve("@storybook/web-components/entry-preview"))]).concat(
15
+ var previewAnnotations = async (input = [], options) => {
16
+ let docsEnabled = Object.keys(await options.presets.apply("docs", {}, options)).length > 0;
17
+ return [].concat(input).concat([
18
+ fileURLToPath(import.meta.resolve("@storybook/web-components/entry-preview")),
19
+ fileURLToPath(import.meta.resolve("@storybook/web-components/entry-preview-argtypes"))
20
+ ]).concat(
21
21
  docsEnabled ? [fileURLToPath(import.meta.resolve("@storybook/web-components/entry-preview-docs"))] : []
22
22
  );
23
- }, "previewAnnotations");
23
+ };
24
24
  export {
25
25
  previewAnnotations
26
26
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/web-components",
3
- "version": "10.1.0-alpha.1",
3
+ "version": "10.1.0-alpha.11",
4
4
  "description": "Storybook Web Components renderer: Develop, document, and test UI components in isolation",
5
5
  "keywords": [
6
6
  "storybook",
@@ -66,10 +66,10 @@
66
66
  },
67
67
  "peerDependencies": {
68
68
  "lit": "^2.0.0 || ^3.0.0",
69
- "storybook": "^10.1.0-alpha.1"
69
+ "storybook": "^10.1.0-alpha.11"
70
70
  },
71
71
  "publishConfig": {
72
72
  "access": "public"
73
73
  },
74
- "gitHead": "a8e7fd8a655c69780bc20b9749d2699e45beae16"
74
+ "gitHead": "a8e7fd8a655c69780bc20b9749d2699e45beae1l"
75
75
  }
@@ -1,11 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
- var __export = (target, all) => {
4
- for (var name in all)
5
- __defProp(target, name, { get: all[name], enumerable: true });
6
- };
7
-
8
- export {
9
- __name,
10
- __export
11
- };