@storybook/web-components 8.3.0-alpha.0 → 8.3.0-alpha.10

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.
Files changed (34) hide show
  1. package/dist/{chunk-GKNNPQCW.mjs → chunk-L4EGOTBX.mjs} +4 -2
  2. package/dist/chunk-X7CW7BOR.mjs +12 -0
  3. package/dist/entry-preview-docs.d.ts +2 -171
  4. package/dist/entry-preview-docs.js +2 -2
  5. package/dist/entry-preview-docs.mjs +4 -3
  6. package/dist/entry-preview.js +1 -1
  7. package/dist/entry-preview.mjs +1 -12
  8. package/dist/index.d.ts +24 -5
  9. package/dist/index.js +5 -2
  10. package/dist/index.mjs +2 -1
  11. package/dist/preset.js +1 -1
  12. package/package.json +11 -7
  13. package/template/cli/js/Button.js +2 -3
  14. package/template/cli/js/Button.stories.js +1 -0
  15. package/template/cli/js/Header.stories.js +1 -0
  16. package/template/cli/js/Page.js +1 -0
  17. package/template/cli/js/Page.stories.js +1 -1
  18. package/template/cli/ts-3-8/Button.stories.ts +3 -1
  19. package/template/cli/ts-3-8/Button.ts +7 -18
  20. package/template/cli/ts-3-8/Header.stories.ts +3 -1
  21. package/template/cli/ts-3-8/Page.stories.ts +1 -1
  22. package/template/cli/ts-3-8/Page.ts +1 -0
  23. package/template/cli/ts-4-9/Button.stories.ts +3 -1
  24. package/template/cli/ts-4-9/Button.ts +7 -18
  25. package/template/cli/ts-4-9/Header.stories.ts +3 -1
  26. package/template/cli/ts-4-9/Page.stories.ts +1 -1
  27. package/template/cli/ts-4-9/Page.ts +1 -0
  28. package/template/components/Button.js +4 -5
  29. package/template/components/Form.js +2 -1
  30. package/template/components/Html.js +2 -4
  31. package/template/components/Pre.js +2 -5
  32. package/template/stories/demo-wc-card/DemoWcCard.js +5 -10
  33. package/template/stories/demo-wc-card.stories.js +1 -0
  34. package/template/stories/preview.js +0 -1
@@ -1,6 +1,8 @@
1
+ import { entry_preview_exports } from './chunk-X7CW7BOR.mjs';
1
2
  import { global } from '@storybook/global';
3
+ import { setDefaultProjectAnnotations, setProjectAnnotations as setProjectAnnotations$1 } from 'storybook/internal/preview-api';
2
4
 
3
5
  var{window:globalWindow}=global;globalWindow.STORYBOOK_ENV="web-components";function isValidComponent(tagName){if(!tagName)return !1;if(typeof tagName=="string")return !0;throw new Error('Provided component needs to be a string. e.g. component: "my-element"')}function isValidMetaData(customElements){if(!customElements)return !1;if(customElements.tags&&Array.isArray(customElements.tags)||customElements.modules&&Array.isArray(customElements.modules))return !0;throw new Error(`You need to setup valid meta data in your config.js via setCustomElements().
4
- See the readme of addon-docs for web components for more details.`)}function setCustomElements(customElements){global.__STORYBOOK_CUSTOM_ELEMENTS__=customElements;}function setCustomElementsManifest(customElements){global.__STORYBOOK_CUSTOM_ELEMENTS_MANIFEST__=customElements;}function getCustomElements(){return global.__STORYBOOK_CUSTOM_ELEMENTS__||global.__STORYBOOK_CUSTOM_ELEMENTS_MANIFEST__}var{window,EventSource}=global;typeof module<"u"&&module?.hot?.decline&&(module.hot.decline(),new EventSource("__webpack_hmr").addEventListener("message",function(event){try{let{action}=JSON.parse(event.data);action==="built"&&window.location.reload();}catch{}}));
6
+ See the readme of addon-docs for web components for more details.`)}function setCustomElements(customElements){global.__STORYBOOK_CUSTOM_ELEMENTS__=customElements;}function setCustomElementsManifest(customElements){global.__STORYBOOK_CUSTOM_ELEMENTS_MANIFEST__=customElements;}function getCustomElements(){return global.__STORYBOOK_CUSTOM_ELEMENTS__||global.__STORYBOOK_CUSTOM_ELEMENTS_MANIFEST__}function setProjectAnnotations(projectAnnotations){return setDefaultProjectAnnotations(entry_preview_exports),setProjectAnnotations$1(projectAnnotations)}var{window,EventSource}=global;typeof module<"u"&&module?.hot?.decline&&(module.hot.decline(),new EventSource("__webpack_hmr").addEventListener("message",function(event){try{let{action}=JSON.parse(event.data);action==="built"&&window.location.reload();}catch{}}));
5
7
 
6
- export { getCustomElements, isValidComponent, isValidMetaData, setCustomElements, setCustomElementsManifest };
8
+ export { getCustomElements, isValidComponent, isValidMetaData, setCustomElements, setCustomElementsManifest, setProjectAnnotations };
@@ -0,0 +1,12 @@
1
+ import { simulatePageLoad, simulateDOMContentLoaded } from 'storybook/internal/preview-api';
2
+ import { global } from '@storybook/global';
3
+ import { render as render$1 } from 'lit';
4
+ import { isTemplateResult } from 'lit/directive-helpers.js';
5
+ import { dedent } from 'ts-dedent';
6
+
7
+ var __defProp=Object.defineProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0});};var entry_preview_exports={};__export(entry_preview_exports,{parameters:()=>parameters,render:()=>render,renderToCanvas:()=>renderToCanvas});var {Node}=global,render=(args,context)=>{let{id,component}=context;if(!component)throw new Error(`Unable to render story ${id} as the component annotation is missing from the default export`);let element=document.createElement(component);return Object.entries(args).forEach(([key,val])=>{element[key]=val;}),element};function renderToCanvas({storyFn,kind,name,showMain,showError,forceRemount},canvasElement){let element=storyFn();if(showMain(),isTemplateResult(element)){(forceRemount||!canvasElement.querySelector('[id="root-inner"]'))&&(canvasElement.innerHTML='<div id="root-inner"></div>');let renderTo=canvasElement.querySelector('[id="root-inner"]');render$1(element,renderTo),simulatePageLoad(canvasElement);}else if(typeof element=="string")canvasElement.innerHTML=element,simulatePageLoad(canvasElement);else if(element instanceof Node){if(canvasElement.firstChild===element&&!forceRemount)return;canvasElement.innerHTML="",canvasElement.appendChild(element),simulateDOMContentLoaded();}else showError({title:`Expecting an HTML snippet or DOM node from the story: "${name}" of "${kind}".`,description:dedent`
8
+ Did you forget to return the HTML snippet from the story?
9
+ Use "() => <your snippet or node>" or when defining the story.
10
+ `});}var parameters={renderer:"web-components"};
11
+
12
+ export { entry_preview_exports, parameters, render, renderToCanvas };
@@ -1,177 +1,8 @@
1
- import { DecoratorFunction, ArgTypesEnhancer } from 'storybook/internal/types';
2
1
  import { SourceType } from 'storybook/internal/docs-tools';
2
+ import { DecoratorFunction, InputType, ArgTypesEnhancer } from 'storybook/internal/types';
3
3
  import { W as WebComponentsRenderer } from './types-9976a2c9.js';
4
4
  import 'lit';
5
5
 
6
- declare global {
7
- interface SymbolConstructor {
8
- readonly observable: symbol;
9
- }
10
- }
11
-
12
- interface SBBaseType {
13
- required?: boolean;
14
- raw?: string;
15
- }
16
- type SBScalarType = SBBaseType & {
17
- name: 'boolean' | 'string' | 'number' | 'function' | 'symbol';
18
- };
19
- type SBArrayType = SBBaseType & {
20
- name: 'array';
21
- value: SBType;
22
- };
23
- type SBObjectType = SBBaseType & {
24
- name: 'object';
25
- value: Record<string, SBType>;
26
- };
27
- type SBEnumType = SBBaseType & {
28
- name: 'enum';
29
- value: (string | number)[];
30
- };
31
- type SBIntersectionType = SBBaseType & {
32
- name: 'intersection';
33
- value: SBType[];
34
- };
35
- type SBUnionType = SBBaseType & {
36
- name: 'union';
37
- value: SBType[];
38
- };
39
- type SBOtherType = SBBaseType & {
40
- name: 'other';
41
- value: string;
42
- };
43
- type SBType = SBScalarType | SBEnumType | SBArrayType | SBObjectType | SBIntersectionType | SBUnionType | SBOtherType;
44
- type ControlType = 'object' | 'boolean' | 'check' | 'inline-check' | 'radio' | 'inline-radio' | 'select' | 'multi-select' | 'number' | 'range' | 'file' | 'color' | 'date' | 'text';
45
- type ConditionalTest = {
46
- truthy?: boolean;
47
- } | {
48
- exists: boolean;
49
- } | {
50
- eq: any;
51
- } | {
52
- neq: any;
53
- };
54
- type ConditionalValue = {
55
- arg: string;
56
- } | {
57
- global: string;
58
- };
59
- type Conditional = ConditionalValue & ConditionalTest;
60
- interface ControlBase {
61
- [key: string]: any;
62
- /**
63
- * @see https://storybook.js.org/docs/api/arg-types#controltype
64
- */
65
- type?: ControlType;
66
- disable?: boolean;
67
- }
68
- type Control = ControlType | false | (ControlBase & (ControlBase | {
69
- type: 'color';
70
- /**
71
- * @see https://storybook.js.org/docs/api/arg-types#controlpresetcolors
72
- */
73
- presetColors?: string[];
74
- } | {
75
- type: 'file';
76
- /**
77
- * @see https://storybook.js.org/docs/api/arg-types#controlaccept
78
- */
79
- accept?: string;
80
- } | {
81
- type: 'inline-check' | 'radio' | 'inline-radio' | 'select' | 'multi-select';
82
- /**
83
- * @see https://storybook.js.org/docs/api/arg-types#controllabels
84
- */
85
- labels?: {
86
- [options: string]: string;
87
- };
88
- } | {
89
- type: 'number' | 'range';
90
- /**
91
- * @see https://storybook.js.org/docs/api/arg-types#controlmax
92
- */
93
- max?: number;
94
- /**
95
- * @see https://storybook.js.org/docs/api/arg-types#controlmin
96
- */
97
- min?: number;
98
- /**
99
- * @see https://storybook.js.org/docs/api/arg-types#controlstep
100
- */
101
- step?: number;
102
- }));
103
- interface InputType {
104
- /**
105
- * @see https://storybook.js.org/docs/api/arg-types#control
106
- */
107
- control?: Control;
108
- /**
109
- * @see https://storybook.js.org/docs/api/arg-types#description
110
- */
111
- description?: string;
112
- /**
113
- * @see https://storybook.js.org/docs/api/arg-types#if
114
- */
115
- if?: Conditional;
116
- /**
117
- * @see https://storybook.js.org/docs/api/arg-types#mapping
118
- */
119
- mapping?: {
120
- [key: string]: any;
121
- };
122
- /**
123
- * @see https://storybook.js.org/docs/api/arg-types#name
124
- */
125
- name?: string;
126
- /**
127
- * @see https://storybook.js.org/docs/api/arg-types#options
128
- */
129
- options?: readonly any[];
130
- /**
131
- * @see https://storybook.js.org/docs/api/arg-types#table
132
- */
133
- table?: {
134
- [key: string]: unknown;
135
- /**
136
- * @see https://storybook.js.org/docs/api/arg-types#tablecategory
137
- */
138
- category?: string;
139
- /**
140
- * @see https://storybook.js.org/docs/api/arg-types#tabledefaultvalue
141
- */
142
- defaultValue?: {
143
- summary?: string;
144
- detail?: string;
145
- };
146
- /**
147
- * @see https://storybook.js.org/docs/api/arg-types#tabledisable
148
- */
149
- disable?: boolean;
150
- /**
151
- * @see https://storybook.js.org/docs/api/arg-types#tablesubcategory
152
- */
153
- subcategory?: string;
154
- /**
155
- * @see https://storybook.js.org/docs/api/arg-types#tabletype
156
- */
157
- type?: {
158
- summary?: string;
159
- detail?: string;
160
- };
161
- };
162
- /**
163
- * @see https://storybook.js.org/docs/api/arg-types#type
164
- */
165
- type?: SBType | SBScalarType['name'];
166
- /**
167
- * @see https://storybook.js.org/docs/api/arg-types#defaultvalue
168
- *
169
- * @deprecated Use `table.defaultValue.summary` instead.
170
- */
171
- defaultValue?: any;
172
- [key: string]: any;
173
- }
174
-
175
6
  declare const decorators: DecoratorFunction<WebComponentsRenderer>[];
176
7
  declare const parameters: {
177
8
  docs: {
@@ -180,7 +11,7 @@ declare const parameters: {
180
11
  } | null | undefined;
181
12
  extractComponentDescription: (tagName: string) => string | null | undefined;
182
13
  story: {
183
- inline: boolean;
14
+ inline: true;
184
15
  };
185
16
  source: {
186
17
  type: SourceType;
@@ -1,2 +1,2 @@
1
- "use strict";var __create=Object.create;var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toESM=(mod,isNodeMode,target)=>(target=mod!=null?__create(__getProtoOf(mod)):{},__copyProps(isNodeMode||!mod||!mod.__esModule?__defProp(target,"default",{value:mod,enumerable:!0}):target,mod)),__toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var entry_preview_docs_exports={};__export(entry_preview_docs_exports,{argTypesEnhancers:()=>argTypesEnhancers,decorators:()=>decorators,parameters:()=>parameters});module.exports=__toCommonJS(entry_preview_docs_exports);var import_docs_tools2=require("storybook/internal/docs-tools");var import_tiny_invariant=__toESM(require("tiny-invariant")),import_client_logger=require("storybook/internal/client-logger");var import_global3=require("@storybook/global");var import_global=require("@storybook/global"),{window:globalWindow}=import_global.global;globalWindow.STORYBOOK_ENV="web-components";var import_global2=require("@storybook/global");function isValidComponent(tagName){if(!tagName)return!1;if(typeof tagName=="string")return!0;throw new Error('Provided component needs to be a string. e.g. component: "my-element"')}function isValidMetaData(customElements){if(!customElements)return!1;if(customElements.tags&&Array.isArray(customElements.tags)||customElements.modules&&Array.isArray(customElements.modules))return!0;throw new Error(`You need to setup valid meta data in your config.js via setCustomElements().
2
- See the readme of addon-docs for web components for more details.`)}function getCustomElements(){return import_global2.global.__STORYBOOK_CUSTOM_ELEMENTS__||import_global2.global.__STORYBOOK_CUSTOM_ELEMENTS_MANIFEST__}var{window:window2,EventSource}=import_global3.global;typeof module<"u"&&module?.hot?.decline&&(module.hot.decline(),new EventSource("__webpack_hmr").addEventListener("message",function(event){try{let{action}=JSON.parse(event.data);action==="built"&&window2.location.reload()}catch{}}));function mapItem(item,category){let type;switch(category){case"attributes":case"properties":type={name:item.type?.text||item.type};break;case"slots":type={name:"string"};break;default:type={name:"void"};break}return{name:item.name,required:!1,description:item.description,type,table:{category,type:{summary:item.type?.text||item.type},defaultValue:{summary:item.default!==void 0?item.default:item.defaultValue}}}}function mapEvent(item){let name=item.name.replace(/(-|_|:|\.|\s)+(.)?/g,(_match,_separator,chr)=>chr?chr.toUpperCase():"").replace(/^([A-Z])/,match=>match.toLowerCase());return name=`on${name.charAt(0).toUpperCase()+name.substr(1)}`,[{name,action:{name:item.name},table:{disable:!0}},mapItem(item,"events")]}function mapData(data,category){return data&&data.filter(item=>item&&item.name).reduce((acc,item)=>{if(item.kind==="method")return acc;switch(category){case"events":mapEvent(item).forEach(argType=>{(0,import_tiny_invariant.default)(argType.name,`${argType} should have a name property.`),acc[argType.name]=argType});break;default:acc[item.name]=mapItem(item,category);break}return acc},{})}var getMetaDataExperimental=(tagName,customElements)=>{if(!isValidComponent(tagName)||!isValidMetaData(customElements))return null;let metaData=customElements.tags.find(tag=>tag.name.toUpperCase()===tagName.toUpperCase());return metaData||import_client_logger.logger.warn(`Component not found in custom-elements.json: ${tagName}`),metaData},getMetaDataV1=(tagName,customElements)=>{if(!isValidComponent(tagName)||!isValidMetaData(customElements))return null;let metadata;return customElements?.modules?.forEach(_module=>{_module?.declarations?.forEach(declaration=>{declaration.tagName===tagName&&(metadata=declaration)})}),metadata||import_client_logger.logger.warn(`Component not found in custom-elements.json: ${tagName}`),metadata},getMetaData=(tagName,manifest)=>manifest?.version==="experimental"?getMetaDataExperimental(tagName,manifest):getMetaDataV1(tagName,manifest),extractArgTypesFromElements=(tagName,customElements)=>{let metaData=getMetaData(tagName,customElements);return metaData&&{...mapData(metaData.members??[],"properties"),...mapData(metaData.properties??[],"properties"),...mapData(metaData.attributes??[],"attributes"),...mapData(metaData.events??[],"events"),...mapData(metaData.slots??[],"slots"),...mapData(metaData.cssProperties??[],"css custom properties"),...mapData(metaData.cssParts??[],"css shadow parts")}},extractArgTypes=tagName=>{let cem=getCustomElements();return extractArgTypesFromElements(tagName,cem)},extractComponentDescription=tagName=>{let metaData=getMetaData(tagName,getCustomElements());return metaData&&metaData.description};var import_lit=require("lit"),import_preview_api=require("storybook/internal/preview-api"),import_docs_tools=require("storybook/internal/docs-tools"),LIT_EXPRESSION_COMMENTS=/<!--\?lit\$[0-9]+\$-->|<!--\??-->/g;function skipSourceRender(context){let sourceParams=context?.parameters.docs?.source,isArgsStory=context?.parameters.__isArgsStory;return sourceParams?.type===import_docs_tools.SourceType.DYNAMIC?!1:!isArgsStory||sourceParams?.code||sourceParams?.type===import_docs_tools.SourceType.CODE}function sourceDecorator(storyFn,context){let story=storyFn(),renderedForSource=context?.parameters.docs?.source?.excludeDecorators?context.originalStoryFn(context.args,context):story,source;if((0,import_preview_api.useEffect)(()=>{let{id,unmappedArgs}=context;source&&import_preview_api.addons.getChannel().emit(import_docs_tools.SNIPPET_RENDERED,{id,source,args:unmappedArgs})}),!skipSourceRender(context)){let container=window.document.createElement("div");renderedForSource instanceof DocumentFragment?(0,import_lit.render)(renderedForSource.cloneNode(!0),container):(0,import_lit.render)(renderedForSource,container),source=container.innerHTML.replace(LIT_EXPRESSION_COMMENTS,"")}return story}var decorators=[sourceDecorator],parameters={docs:{extractArgTypes,extractComponentDescription,story:{inline:!0},source:{type:import_docs_tools2.SourceType.DYNAMIC,language:"html"}}},argTypesEnhancers=[import_docs_tools2.enhanceArgTypes];0&&(module.exports={argTypesEnhancers,decorators,parameters});
1
+ "use strict";var __create=Object.create;var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toESM=(mod,isNodeMode,target)=>(target=mod!=null?__create(__getProtoOf(mod)):{},__copyProps(isNodeMode||!mod||!mod.__esModule?__defProp(target,"default",{value:mod,enumerable:!0}):target,mod)),__toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var entry_preview_docs_exports={};__export(entry_preview_docs_exports,{argTypesEnhancers:()=>argTypesEnhancers,decorators:()=>decorators,parameters:()=>parameters});module.exports=__toCommonJS(entry_preview_docs_exports);var import_docs_tools2=require("storybook/internal/docs-tools");var import_client_logger=require("storybook/internal/client-logger"),import_tiny_invariant=__toESM(require("tiny-invariant"));var import_global4=require("@storybook/global");var import_global=require("@storybook/global"),{window:globalWindow}=import_global.global;globalWindow.STORYBOOK_ENV="web-components";var import_global2=require("@storybook/global");function isValidComponent(tagName){if(!tagName)return!1;if(typeof tagName=="string")return!0;throw new Error('Provided component needs to be a string. e.g. component: "my-element"')}function isValidMetaData(customElements){if(!customElements)return!1;if(customElements.tags&&Array.isArray(customElements.tags)||customElements.modules&&Array.isArray(customElements.modules))return!0;throw new Error(`You need to setup valid meta data in your config.js via setCustomElements().
2
+ See the readme of addon-docs for web components for more details.`)}function getCustomElements(){return import_global2.global.__STORYBOOK_CUSTOM_ELEMENTS__||import_global2.global.__STORYBOOK_CUSTOM_ELEMENTS_MANIFEST__}var import_preview_api2=require("storybook/internal/preview-api");var import_preview_api=require("storybook/internal/preview-api"),import_global3=require("@storybook/global"),import_lit=require("lit"),import_directive_helpers=require("lit/directive-helpers.js"),import_ts_dedent=require("ts-dedent"),{Node}=import_global3.global;var{window:window2,EventSource}=import_global4.global;typeof module<"u"&&module?.hot?.decline&&(module.hot.decline(),new EventSource("__webpack_hmr").addEventListener("message",function(event){try{let{action}=JSON.parse(event.data);action==="built"&&window2.location.reload()}catch{}}));function mapItem(item,category){let type;switch(category){case"attributes":case"properties":type={name:item.type?.text||item.type};break;case"slots":type={name:"string"};break;default:type={name:"void"};break}return{name:item.name,required:!1,description:item.description,type,table:{category,type:{summary:item.type?.text||item.type},defaultValue:{summary:item.default!==void 0?item.default:item.defaultValue}}}}function mapEvent(item){let name=item.name.replace(/(-|_|:|\.|\s)+(.)?/g,(_match,_separator,chr)=>chr?chr.toUpperCase():"").replace(/^([A-Z])/,match=>match.toLowerCase());return name=`on${name.charAt(0).toUpperCase()+name.substr(1)}`,[{name,action:{name:item.name},table:{disable:!0}},mapItem(item,"events")]}function mapData(data,category){return data&&data.filter(item=>item&&item.name).reduce((acc,item)=>{if(item.kind==="method")return acc;switch(category){case"events":mapEvent(item).forEach(argType=>{(0,import_tiny_invariant.default)(argType.name,`${argType} should have a name property.`),acc[argType.name]=argType});break;default:acc[item.name]=mapItem(item,category);break}return acc},{})}var getMetaDataExperimental=(tagName,customElements)=>{if(!isValidComponent(tagName)||!isValidMetaData(customElements))return null;let metaData=customElements.tags.find(tag=>tag.name.toUpperCase()===tagName.toUpperCase());return metaData||import_client_logger.logger.warn(`Component not found in custom-elements.json: ${tagName}`),metaData},getMetaDataV1=(tagName,customElements)=>{if(!isValidComponent(tagName)||!isValidMetaData(customElements))return null;let metadata;return customElements?.modules?.forEach(_module=>{_module?.declarations?.forEach(declaration=>{declaration.tagName===tagName&&(metadata=declaration)})}),metadata||import_client_logger.logger.warn(`Component not found in custom-elements.json: ${tagName}`),metadata},getMetaData=(tagName,manifest)=>manifest?.version==="experimental"?getMetaDataExperimental(tagName,manifest):getMetaDataV1(tagName,manifest),extractArgTypesFromElements=(tagName,customElements)=>{let metaData=getMetaData(tagName,customElements);return metaData&&{...mapData(metaData.members??[],"properties"),...mapData(metaData.properties??[],"properties"),...mapData(metaData.attributes??[],"attributes"),...mapData(metaData.events??[],"events"),...mapData(metaData.slots??[],"slots"),...mapData(metaData.cssProperties??[],"css custom properties"),...mapData(metaData.cssParts??[],"css shadow parts")}},extractArgTypes=tagName=>{let cem=getCustomElements();return extractArgTypesFromElements(tagName,cem)},extractComponentDescription=tagName=>{let metaData=getMetaData(tagName,getCustomElements());return metaData&&metaData.description};var import_docs_tools=require("storybook/internal/docs-tools"),import_preview_api3=require("storybook/internal/preview-api"),import_lit2=require("lit"),LIT_EXPRESSION_COMMENTS=/<!--\?lit\$[0-9]+\$-->|<!--\??-->/g;function skipSourceRender(context){let sourceParams=context?.parameters.docs?.source,isArgsStory=context?.parameters.__isArgsStory;return sourceParams?.type===import_docs_tools.SourceType.DYNAMIC?!1:!isArgsStory||sourceParams?.code||sourceParams?.type===import_docs_tools.SourceType.CODE}function sourceDecorator(storyFn,context){let story=storyFn(),renderedForSource=context?.parameters.docs?.source?.excludeDecorators?context.originalStoryFn(context.args,context):story,source;if((0,import_preview_api3.useEffect)(()=>{let{id,unmappedArgs}=context;source&&import_preview_api3.addons.getChannel().emit(import_docs_tools.SNIPPET_RENDERED,{id,source,args:unmappedArgs})}),!skipSourceRender(context)){let container=window.document.createElement("div");renderedForSource instanceof DocumentFragment?(0,import_lit2.render)(renderedForSource.cloneNode(!0),container):(0,import_lit2.render)(renderedForSource,container),source=container.innerHTML.replace(LIT_EXPRESSION_COMMENTS,"")}return story}var decorators=[sourceDecorator],parameters={docs:{extractArgTypes,extractComponentDescription,story:{inline:!0},source:{type:import_docs_tools2.SourceType.DYNAMIC,language:"html"}}},argTypesEnhancers=[import_docs_tools2.enhanceArgTypes];0&&(module.exports={argTypesEnhancers,decorators,parameters});
@@ -1,9 +1,10 @@
1
- import { getCustomElements, isValidComponent, isValidMetaData } from './chunk-GKNNPQCW.mjs';
1
+ import { getCustomElements, isValidComponent, isValidMetaData } from './chunk-L4EGOTBX.mjs';
2
+ import './chunk-X7CW7BOR.mjs';
2
3
  import { SourceType, enhanceArgTypes, SNIPPET_RENDERED } from 'storybook/internal/docs-tools';
3
- import invariant from 'tiny-invariant';
4
4
  import { logger } from 'storybook/internal/client-logger';
5
- import { render } from 'lit';
5
+ import invariant from 'tiny-invariant';
6
6
  import { useEffect, addons } from 'storybook/internal/preview-api';
7
+ import { render } from 'lit';
7
8
 
8
9
  function mapItem(item,category){let type;switch(category){case"attributes":case"properties":type={name:item.type?.text||item.type};break;case"slots":type={name:"string"};break;default:type={name:"void"};break}return {name:item.name,required:!1,description:item.description,type,table:{category,type:{summary:item.type?.text||item.type},defaultValue:{summary:item.default!==void 0?item.default:item.defaultValue}}}}function mapEvent(item){let name=item.name.replace(/(-|_|:|\.|\s)+(.)?/g,(_match,_separator,chr)=>chr?chr.toUpperCase():"").replace(/^([A-Z])/,match=>match.toLowerCase());return name=`on${name.charAt(0).toUpperCase()+name.substr(1)}`,[{name,action:{name:item.name},table:{disable:!0}},mapItem(item,"events")]}function mapData(data,category){return data&&data.filter(item=>item&&item.name).reduce((acc,item)=>{if(item.kind==="method")return acc;switch(category){case"events":mapEvent(item).forEach(argType=>{invariant(argType.name,`${argType} should have a name property.`),acc[argType.name]=argType;});break;default:acc[item.name]=mapItem(item,category);break}return acc},{})}var getMetaDataExperimental=(tagName,customElements)=>{if(!isValidComponent(tagName)||!isValidMetaData(customElements))return null;let metaData=customElements.tags.find(tag=>tag.name.toUpperCase()===tagName.toUpperCase());return metaData||logger.warn(`Component not found in custom-elements.json: ${tagName}`),metaData},getMetaDataV1=(tagName,customElements)=>{if(!isValidComponent(tagName)||!isValidMetaData(customElements))return null;let metadata;return customElements?.modules?.forEach(_module=>{_module?.declarations?.forEach(declaration=>{declaration.tagName===tagName&&(metadata=declaration);});}),metadata||logger.warn(`Component not found in custom-elements.json: ${tagName}`),metadata},getMetaData=(tagName,manifest)=>manifest?.version==="experimental"?getMetaDataExperimental(tagName,manifest):getMetaDataV1(tagName,manifest),extractArgTypesFromElements=(tagName,customElements)=>{let metaData=getMetaData(tagName,customElements);return metaData&&{...mapData(metaData.members??[],"properties"),...mapData(metaData.properties??[],"properties"),...mapData(metaData.attributes??[],"attributes"),...mapData(metaData.events??[],"events"),...mapData(metaData.slots??[],"slots"),...mapData(metaData.cssProperties??[],"css custom properties"),...mapData(metaData.cssParts??[],"css shadow parts")}},extractArgTypes=tagName=>{let cem=getCustomElements();return extractArgTypesFromElements(tagName,cem)},extractComponentDescription=tagName=>{let metaData=getMetaData(tagName,getCustomElements());return metaData&&metaData.description};var LIT_EXPRESSION_COMMENTS=/<!--\?lit\$[0-9]+\$-->|<!--\??-->/g;function skipSourceRender(context){let sourceParams=context?.parameters.docs?.source,isArgsStory=context?.parameters.__isArgsStory;return sourceParams?.type===SourceType.DYNAMIC?!1:!isArgsStory||sourceParams?.code||sourceParams?.type===SourceType.CODE}function sourceDecorator(storyFn,context){let story=storyFn(),renderedForSource=context?.parameters.docs?.source?.excludeDecorators?context.originalStoryFn(context.args,context):story,source;if(useEffect(()=>{let{id,unmappedArgs}=context;source&&addons.getChannel().emit(SNIPPET_RENDERED,{id,source,args:unmappedArgs});}),!skipSourceRender(context)){let container=window.document.createElement("div");renderedForSource instanceof DocumentFragment?render(renderedForSource.cloneNode(!0),container):render(renderedForSource,container),source=container.innerHTML.replace(LIT_EXPRESSION_COMMENTS,"");}return story}var decorators=[sourceDecorator],parameters={docs:{extractArgTypes,extractComponentDescription,story:{inline:!0},source:{type:SourceType.DYNAMIC,language:"html"}}},argTypesEnhancers=[enhanceArgTypes];
9
10
 
@@ -1,4 +1,4 @@
1
- "use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var entry_preview_exports={};__export(entry_preview_exports,{parameters:()=>parameters,render:()=>render,renderToCanvas:()=>renderToCanvas});module.exports=__toCommonJS(entry_preview_exports);var import_global=require("@storybook/global"),import_ts_dedent=require("ts-dedent"),import_lit=require("lit"),import_directive_helpers=require("lit/directive-helpers.js"),import_preview_api=require("storybook/internal/preview-api"),{Node}=import_global.global,render=(args,context)=>{let{id,component}=context;if(!component)throw new Error(`Unable to render story ${id} as the component annotation is missing from the default export`);let element=document.createElement(component);return Object.entries(args).forEach(([key,val])=>{element[key]=val}),element};function renderToCanvas({storyFn,kind,name,showMain,showError,forceRemount},canvasElement){let element=storyFn();if(showMain(),(0,import_directive_helpers.isTemplateResult)(element)){(forceRemount||!canvasElement.querySelector('[id="root-inner"]'))&&(canvasElement.innerHTML='<div id="root-inner"></div>');let renderTo=canvasElement.querySelector('[id="root-inner"]');(0,import_lit.render)(element,renderTo),(0,import_preview_api.simulatePageLoad)(canvasElement)}else if(typeof element=="string")canvasElement.innerHTML=element,(0,import_preview_api.simulatePageLoad)(canvasElement);else if(element instanceof Node){if(canvasElement.firstChild===element&&!forceRemount)return;canvasElement.innerHTML="",canvasElement.appendChild(element),(0,import_preview_api.simulateDOMContentLoaded)()}else showError({title:`Expecting an HTML snippet or DOM node from the story: "${name}" of "${kind}".`,description:import_ts_dedent.dedent`
1
+ "use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var entry_preview_exports={};__export(entry_preview_exports,{parameters:()=>parameters,render:()=>render,renderToCanvas:()=>renderToCanvas});module.exports=__toCommonJS(entry_preview_exports);var import_preview_api=require("storybook/internal/preview-api"),import_global=require("@storybook/global"),import_lit=require("lit"),import_directive_helpers=require("lit/directive-helpers.js"),import_ts_dedent=require("ts-dedent"),{Node}=import_global.global,render=(args,context)=>{let{id,component}=context;if(!component)throw new Error(`Unable to render story ${id} as the component annotation is missing from the default export`);let element=document.createElement(component);return Object.entries(args).forEach(([key,val])=>{element[key]=val}),element};function renderToCanvas({storyFn,kind,name,showMain,showError,forceRemount},canvasElement){let element=storyFn();if(showMain(),(0,import_directive_helpers.isTemplateResult)(element)){(forceRemount||!canvasElement.querySelector('[id="root-inner"]'))&&(canvasElement.innerHTML='<div id="root-inner"></div>');let renderTo=canvasElement.querySelector('[id="root-inner"]');(0,import_lit.render)(element,renderTo),(0,import_preview_api.simulatePageLoad)(canvasElement)}else if(typeof element=="string")canvasElement.innerHTML=element,(0,import_preview_api.simulatePageLoad)(canvasElement);else if(element instanceof Node){if(canvasElement.firstChild===element&&!forceRemount)return;canvasElement.innerHTML="",canvasElement.appendChild(element),(0,import_preview_api.simulateDOMContentLoaded)()}else showError({title:`Expecting an HTML snippet or DOM node from the story: "${name}" of "${kind}".`,description:import_ts_dedent.dedent`
2
2
  Did you forget to return the HTML snippet from the story?
3
3
  Use "() => <your snippet or node>" or when defining the story.
4
4
  `})}var parameters={renderer:"web-components"};0&&(module.exports={parameters,render,renderToCanvas});
@@ -1,12 +1 @@
1
- import { global } from '@storybook/global';
2
- import { dedent } from 'ts-dedent';
3
- import { render as render$1 } from 'lit';
4
- import { isTemplateResult } from 'lit/directive-helpers.js';
5
- import { simulatePageLoad, simulateDOMContentLoaded } from 'storybook/internal/preview-api';
6
-
7
- var {Node}=global,render=(args,context)=>{let{id,component}=context;if(!component)throw new Error(`Unable to render story ${id} as the component annotation is missing from the default export`);let element=document.createElement(component);return Object.entries(args).forEach(([key,val])=>{element[key]=val;}),element};function renderToCanvas({storyFn,kind,name,showMain,showError,forceRemount},canvasElement){let element=storyFn();if(showMain(),isTemplateResult(element)){(forceRemount||!canvasElement.querySelector('[id="root-inner"]'))&&(canvasElement.innerHTML='<div id="root-inner"></div>');let renderTo=canvasElement.querySelector('[id="root-inner"]');render$1(element,renderTo),simulatePageLoad(canvasElement);}else if(typeof element=="string")canvasElement.innerHTML=element,simulatePageLoad(canvasElement);else if(element instanceof Node){if(canvasElement.firstChild===element&&!forceRemount)return;canvasElement.innerHTML="",canvasElement.appendChild(element),simulateDOMContentLoaded();}else showError({title:`Expecting an HTML snippet or DOM node from the story: "${name}" of "${kind}".`,description:dedent`
8
- Did you forget to return the HTML snippet from the story?
9
- Use "() => <your snippet or node>" or when defining the story.
10
- `});}var parameters={renderer:"web-components"};
11
-
12
- export { parameters, render, renderToCanvas };
1
+ export { parameters, render, renderToCanvas } from './chunk-X7CW7BOR.mjs';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Args, ComponentAnnotations, AnnotatedStoryFn, StoryAnnotations, StrictArgs, DecoratorFunction, LoaderFunction, StoryContext as StoryContext$1, ProjectAnnotations } from 'storybook/internal/types';
1
+ import { Args, ComponentAnnotations, AnnotatedStoryFn, StoryAnnotations, StrictArgs, DecoratorFunction, LoaderFunction, StoryContext as StoryContext$1, ProjectAnnotations, NamedOrDefaultProjectAnnotations, NormalizedProjectAnnotations } from 'storybook/internal/types';
2
2
  export { ArgTypes, Args, Parameters, StrictArgs } from 'storybook/internal/types';
3
3
  import { W as WebComponentsRenderer } from './types-9976a2c9.js';
4
4
  import 'lit';
@@ -28,11 +28,30 @@ type Preview = ProjectAnnotations<WebComponentsRenderer>;
28
28
 
29
29
  declare function isValidComponent(tagName: string): boolean;
30
30
  declare function isValidMetaData(customElements: any): boolean;
31
- /**
32
- * @param customElements any for now as spec is not super stable yet
33
- */
31
+ /** @param customElements `any` for now as spec is not super stable yet */
34
32
  declare function setCustomElements(customElements: any): void;
35
33
  declare function setCustomElementsManifest(customElements: any): void;
36
34
  declare function getCustomElements(): any;
37
35
 
38
- export { Decorator, Loader, Meta, Preview, StoryContext, StoryFn, StoryObj, WebComponentsRenderer, getCustomElements, isValidComponent, isValidMetaData, setCustomElements, setCustomElementsManifest };
36
+ /**
37
+ * Function that sets the globalConfig of your storybook. The global config is the preview module of
38
+ * your .storybook folder.
39
+ *
40
+ * It should be run a single time, so that your global config (e.g. decorators) is applied to your
41
+ * stories when using `composeStories` or `composeStory`.
42
+ *
43
+ * Example:
44
+ *
45
+ * ```jsx
46
+ * // setup-file.js
47
+ * import { setProjectAnnotations } from '@storybook/web-components';
48
+ * import projectAnnotations from './.storybook/preview';
49
+ *
50
+ * setProjectAnnotations(projectAnnotations);
51
+ * ```
52
+ *
53
+ * @param projectAnnotations - E.g. (import projectAnnotations from '../.storybook/preview')
54
+ */
55
+ declare function setProjectAnnotations(projectAnnotations: NamedOrDefaultProjectAnnotations<any> | NamedOrDefaultProjectAnnotations<any>[]): NormalizedProjectAnnotations<WebComponentsRenderer>;
56
+
57
+ export { Decorator, Loader, Meta, Preview, StoryContext, StoryFn, StoryObj, WebComponentsRenderer, getCustomElements, isValidComponent, isValidMetaData, setCustomElements, setCustomElementsManifest, setProjectAnnotations };
package/dist/index.js CHANGED
@@ -1,2 +1,5 @@
1
- "use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var src_exports={};__export(src_exports,{getCustomElements:()=>getCustomElements,isValidComponent:()=>isValidComponent,isValidMetaData:()=>isValidMetaData,setCustomElements:()=>setCustomElements,setCustomElementsManifest:()=>setCustomElementsManifest});module.exports=__toCommonJS(src_exports);var import_global3=require("@storybook/global");var import_global=require("@storybook/global"),{window:globalWindow}=import_global.global;globalWindow.STORYBOOK_ENV="web-components";var import_global2=require("@storybook/global");function isValidComponent(tagName){if(!tagName)return!1;if(typeof tagName=="string")return!0;throw new Error('Provided component needs to be a string. e.g. component: "my-element"')}function isValidMetaData(customElements){if(!customElements)return!1;if(customElements.tags&&Array.isArray(customElements.tags)||customElements.modules&&Array.isArray(customElements.modules))return!0;throw new Error(`You need to setup valid meta data in your config.js via setCustomElements().
2
- See the readme of addon-docs for web components for more details.`)}function setCustomElements(customElements){import_global2.global.__STORYBOOK_CUSTOM_ELEMENTS__=customElements}function setCustomElementsManifest(customElements){import_global2.global.__STORYBOOK_CUSTOM_ELEMENTS_MANIFEST__=customElements}function getCustomElements(){return import_global2.global.__STORYBOOK_CUSTOM_ELEMENTS__||import_global2.global.__STORYBOOK_CUSTOM_ELEMENTS_MANIFEST__}var{window,EventSource}=import_global3.global;typeof module<"u"&&module?.hot?.decline&&(module.hot.decline(),new EventSource("__webpack_hmr").addEventListener("message",function(event){try{let{action}=JSON.parse(event.data);action==="built"&&window.location.reload()}catch{}}));0&&(module.exports={getCustomElements,isValidComponent,isValidMetaData,setCustomElements,setCustomElementsManifest});
1
+ "use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var src_exports={};__export(src_exports,{getCustomElements:()=>getCustomElements,isValidComponent:()=>isValidComponent,isValidMetaData:()=>isValidMetaData,setCustomElements:()=>setCustomElements,setCustomElementsManifest:()=>setCustomElementsManifest,setProjectAnnotations:()=>setProjectAnnotations});module.exports=__toCommonJS(src_exports);var import_global4=require("@storybook/global");var import_global=require("@storybook/global"),{window:globalWindow}=import_global.global;globalWindow.STORYBOOK_ENV="web-components";var import_global2=require("@storybook/global");function isValidComponent(tagName){if(!tagName)return!1;if(typeof tagName=="string")return!0;throw new Error('Provided component needs to be a string. e.g. component: "my-element"')}function isValidMetaData(customElements){if(!customElements)return!1;if(customElements.tags&&Array.isArray(customElements.tags)||customElements.modules&&Array.isArray(customElements.modules))return!0;throw new Error(`You need to setup valid meta data in your config.js via setCustomElements().
2
+ See the readme of addon-docs for web components for more details.`)}function setCustomElements(customElements){import_global2.global.__STORYBOOK_CUSTOM_ELEMENTS__=customElements}function setCustomElementsManifest(customElements){import_global2.global.__STORYBOOK_CUSTOM_ELEMENTS_MANIFEST__=customElements}function getCustomElements(){return import_global2.global.__STORYBOOK_CUSTOM_ELEMENTS__||import_global2.global.__STORYBOOK_CUSTOM_ELEMENTS_MANIFEST__}var import_preview_api2=require("storybook/internal/preview-api");var entry_preview_exports={};__export(entry_preview_exports,{parameters:()=>parameters,render:()=>render,renderToCanvas:()=>renderToCanvas});var import_preview_api=require("storybook/internal/preview-api"),import_global3=require("@storybook/global"),import_lit=require("lit"),import_directive_helpers=require("lit/directive-helpers.js"),import_ts_dedent=require("ts-dedent"),{Node}=import_global3.global,render=(args,context)=>{let{id,component}=context;if(!component)throw new Error(`Unable to render story ${id} as the component annotation is missing from the default export`);let element=document.createElement(component);return Object.entries(args).forEach(([key,val])=>{element[key]=val}),element};function renderToCanvas({storyFn,kind,name,showMain,showError,forceRemount},canvasElement){let element=storyFn();if(showMain(),(0,import_directive_helpers.isTemplateResult)(element)){(forceRemount||!canvasElement.querySelector('[id="root-inner"]'))&&(canvasElement.innerHTML='<div id="root-inner"></div>');let renderTo=canvasElement.querySelector('[id="root-inner"]');(0,import_lit.render)(element,renderTo),(0,import_preview_api.simulatePageLoad)(canvasElement)}else if(typeof element=="string")canvasElement.innerHTML=element,(0,import_preview_api.simulatePageLoad)(canvasElement);else if(element instanceof Node){if(canvasElement.firstChild===element&&!forceRemount)return;canvasElement.innerHTML="",canvasElement.appendChild(element),(0,import_preview_api.simulateDOMContentLoaded)()}else showError({title:`Expecting an HTML snippet or DOM node from the story: "${name}" of "${kind}".`,description:import_ts_dedent.dedent`
3
+ Did you forget to return the HTML snippet from the story?
4
+ Use "() => <your snippet or node>" or when defining the story.
5
+ `})}var parameters={renderer:"web-components"};function setProjectAnnotations(projectAnnotations){return(0,import_preview_api2.setDefaultProjectAnnotations)(entry_preview_exports),(0,import_preview_api2.setProjectAnnotations)(projectAnnotations)}var{window,EventSource}=import_global4.global;typeof module<"u"&&module?.hot?.decline&&(module.hot.decline(),new EventSource("__webpack_hmr").addEventListener("message",function(event){try{let{action}=JSON.parse(event.data);action==="built"&&window.location.reload()}catch{}}));0&&(module.exports={getCustomElements,isValidComponent,isValidMetaData,setCustomElements,setCustomElementsManifest,setProjectAnnotations});
package/dist/index.mjs CHANGED
@@ -1 +1,2 @@
1
- export { getCustomElements, isValidComponent, isValidMetaData, setCustomElements, setCustomElementsManifest } from './chunk-GKNNPQCW.mjs';
1
+ export { getCustomElements, isValidComponent, isValidMetaData, setCustomElements, setCustomElementsManifest, setProjectAnnotations } from './chunk-L4EGOTBX.mjs';
2
+ import './chunk-X7CW7BOR.mjs';
package/dist/preset.js CHANGED
@@ -1 +1 @@
1
- "use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var preset_exports={};__export(preset_exports,{previewAnnotations:()=>previewAnnotations});module.exports=__toCommonJS(preset_exports);var import_path=require("path"),previewAnnotations=async(input=[],options)=>{let docsEnabled=Object.keys(await options.presets.apply("docs",{},options)).length>0;return[].concat(input).concat([(0,import_path.join)(__dirname,"entry-preview.mjs")]).concat(docsEnabled?[(0,import_path.join)(__dirname,"entry-preview-docs.mjs")]:[])};0&&(module.exports={previewAnnotations});
1
+ "use strict";var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __hasOwnProp=Object.prototype.hasOwnProperty;var __export=(target,all)=>{for(var name in all)__defProp(target,name,{get:all[name],enumerable:!0})},__copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toCommonJS=mod=>__copyProps(__defProp({},"__esModule",{value:!0}),mod);var preset_exports={};__export(preset_exports,{previewAnnotations:()=>previewAnnotations});module.exports=__toCommonJS(preset_exports);var import_node_path=require("path"),previewAnnotations=async(input=[],options)=>{let docsEnabled=Object.keys(await options.presets.apply("docs",{},options)).length>0;return[].concat(input).concat([(0,import_node_path.join)(__dirname,"entry-preview.mjs")]).concat(docsEnabled?[(0,import_node_path.join)(__dirname,"entry-preview-docs.mjs")]:[])};0&&(module.exports={previewAnnotations});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/web-components",
3
- "version": "8.3.0-alpha.0",
3
+ "version": "8.3.0-alpha.10",
4
4
  "description": "Storybook web-components renderer",
5
5
  "keywords": [
6
6
  "lit",
@@ -25,9 +25,9 @@
25
25
  "exports": {
26
26
  ".": {
27
27
  "types": "./dist/index.d.ts",
28
- "node": "./dist/index.js",
29
28
  "import": "./dist/index.mjs",
30
- "require": "./dist/index.js"
29
+ "require": "./dist/index.js",
30
+ "node": "./dist/index.js"
31
31
  },
32
32
  "./preset": "./preset.js",
33
33
  "./dist/entry-preview.mjs": "./dist/entry-preview.mjs",
@@ -46,17 +46,21 @@
46
46
  "!src/**/*"
47
47
  ],
48
48
  "scripts": {
49
- "check": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/check.ts",
50
- "prep": "node --loader ../../../scripts/node_modules/esbuild-register/loader.js -r ../../../scripts/node_modules/esbuild-register/register.js ../../../scripts/prepare/bundle.ts"
49
+ "check": "jiti ../../../scripts/prepare/check.ts",
50
+ "prep": "jiti ../../../scripts/prepare/bundle.ts"
51
51
  },
52
52
  "dependencies": {
53
+ "@storybook/components": "^8.3.0-alpha.10",
53
54
  "@storybook/global": "^5.0.0",
55
+ "@storybook/manager-api": "^8.3.0-alpha.10",
56
+ "@storybook/preview-api": "^8.3.0-alpha.10",
57
+ "@storybook/theming": "^8.3.0-alpha.10",
54
58
  "tiny-invariant": "^1.3.1",
55
59
  "ts-dedent": "^2.0.0"
56
60
  },
57
61
  "devDependencies": {
58
62
  "@types/cross-spawn": "^6.0.2",
59
- "@types/node": "^18.0.0",
63
+ "@types/node": "^22.0.0",
60
64
  "cross-spawn": "^7.0.3",
61
65
  "lit": "2.3.1",
62
66
  "typescript": "^5.3.2",
@@ -64,7 +68,7 @@
64
68
  },
65
69
  "peerDependencies": {
66
70
  "lit": "^2.0.0 || ^3.0.0",
67
- "storybook": "^8.3.0-alpha.0"
71
+ "storybook": "^8.3.0-alpha.10"
68
72
  },
69
73
  "engines": {
70
74
  "node": ">=18.0.0"
@@ -1,10 +1,9 @@
1
1
  import { html } from 'lit';
2
2
  import { styleMap } from 'lit/directives/style-map.js';
3
+
3
4
  import './button.css';
4
5
 
5
- /**
6
- * Primary UI component for user interaction
7
- */
6
+ /** Primary UI component for user interaction */
8
7
  export const Button = ({ primary, backgroundColor = null, size, label, onClick }) => {
9
8
  const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
10
9
 
@@ -1,4 +1,5 @@
1
1
  import { fn } from '@storybook/test';
2
+
2
3
  import { Button } from './Button';
3
4
 
4
5
  // More on how to set up stories at: https://storybook.js.org/docs/writing-stories
@@ -1,4 +1,5 @@
1
1
  import { fn } from '@storybook/test';
2
+
2
3
  import { Header } from './Header';
3
4
 
4
5
  export default {
@@ -1,4 +1,5 @@
1
1
  import { html } from 'lit';
2
+
2
3
  import { Header } from './Header';
3
4
  import './page.css';
4
5
 
@@ -1,5 +1,5 @@
1
- import { Page } from './Page';
2
1
  import * as HeaderStories from './Header.stories';
2
+ import { Page } from './Page';
3
3
 
4
4
  export default {
5
5
  title: 'Example/Page',
@@ -1,5 +1,7 @@
1
- import type { Meta, StoryObj } from '@storybook/web-components';
2
1
  import { fn } from '@storybook/test';
2
+
3
+ import type { Meta, StoryObj } from '@storybook/web-components';
4
+
3
5
  import type { ButtonProps } from './Button';
4
6
  import { Button } from './Button';
5
7
 
@@ -1,32 +1,21 @@
1
1
  import { html } from 'lit';
2
2
  import { styleMap } from 'lit/directives/style-map.js';
3
+
3
4
  import './button.css';
4
5
 
5
6
  export interface ButtonProps {
6
- /**
7
- * Is this the principal call to action on the page?
8
- */
7
+ /** Is this the principal call to action on the page? */
9
8
  primary?: boolean;
10
- /**
11
- * What background color to use
12
- */
9
+ /** What background color to use */
13
10
  backgroundColor?: string;
14
- /**
15
- * How large should the button be?
16
- */
11
+ /** How large should the button be? */
17
12
  size?: 'small' | 'medium' | 'large';
18
- /**
19
- * Button contents
20
- */
13
+ /** Button contents */
21
14
  label: string;
22
- /**
23
- * Optional click handler
24
- */
15
+ /** Optional click handler */
25
16
  onClick?: () => void;
26
17
  }
27
- /**
28
- * Primary UI component for user interaction
29
- */
18
+ /** Primary UI component for user interaction */
30
19
  export const Button = ({ primary, backgroundColor, size, label, onClick }: ButtonProps) => {
31
20
  const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
32
21
 
@@ -1,5 +1,7 @@
1
- import type { Meta, StoryObj } from '@storybook/web-components';
2
1
  import { fn } from '@storybook/test';
2
+
3
+ import type { Meta, StoryObj } from '@storybook/web-components';
4
+
3
5
  import type { HeaderProps } from './Header';
4
6
  import { Header } from './Header';
5
7
 
@@ -1,8 +1,8 @@
1
1
  import type { Meta, StoryObj } from '@storybook/web-components';
2
2
 
3
+ import * as HeaderStories from './Header.stories';
3
4
  import type { PageProps } from './Page';
4
5
  import { Page } from './Page';
5
- import * as HeaderStories from './Header.stories';
6
6
 
7
7
  const meta: Meta<PageProps> = {
8
8
  title: 'Example/Page',
@@ -1,4 +1,5 @@
1
1
  import { html } from 'lit';
2
+
2
3
  import { Header } from './Header';
3
4
  import './page.css';
4
5
 
@@ -1,5 +1,7 @@
1
- import type { Meta, StoryObj } from '@storybook/web-components';
2
1
  import { fn } from '@storybook/test';
2
+
3
+ import type { Meta, StoryObj } from '@storybook/web-components';
4
+
3
5
  import type { ButtonProps } from './Button';
4
6
  import { Button } from './Button';
5
7
 
@@ -1,32 +1,21 @@
1
1
  import { html } from 'lit';
2
2
  import { styleMap } from 'lit/directives/style-map.js';
3
+
3
4
  import './button.css';
4
5
 
5
6
  export interface ButtonProps {
6
- /**
7
- * Is this the principal call to action on the page?
8
- */
7
+ /** Is this the principal call to action on the page? */
9
8
  primary?: boolean;
10
- /**
11
- * What background color to use
12
- */
9
+ /** What background color to use */
13
10
  backgroundColor?: string;
14
- /**
15
- * How large should the button be?
16
- */
11
+ /** How large should the button be? */
17
12
  size?: 'small' | 'medium' | 'large';
18
- /**
19
- * Button contents
20
- */
13
+ /** Button contents */
21
14
  label: string;
22
- /**
23
- * Optional click handler
24
- */
15
+ /** Optional click handler */
25
16
  onClick?: () => void;
26
17
  }
27
- /**
28
- * Primary UI component for user interaction
29
- */
18
+ /** Primary UI component for user interaction */
30
19
  export const Button = ({ primary, backgroundColor, size, label, onClick }: ButtonProps) => {
31
20
  const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
32
21
 
@@ -1,5 +1,7 @@
1
- import type { Meta, StoryObj } from '@storybook/web-components';
2
1
  import { fn } from '@storybook/test';
2
+
3
+ import type { Meta, StoryObj } from '@storybook/web-components';
4
+
3
5
  import type { HeaderProps } from './Header';
4
6
  import { Header } from './Header';
5
7
 
@@ -1,8 +1,8 @@
1
1
  import type { Meta, StoryObj } from '@storybook/web-components';
2
2
 
3
+ import * as HeaderStories from './Header.stories';
3
4
  import type { PageProps } from './Page';
4
5
  import { Page } from './Page';
5
- import * as HeaderStories from './Header.stories';
6
6
 
7
7
  const meta = {
8
8
  title: 'Example/Page',
@@ -1,4 +1,5 @@
1
1
  import { html } from 'lit';
2
+
2
3
  import { Header } from './Header';
3
4
  import './page.css';
4
5
 
@@ -1,17 +1,16 @@
1
1
  import { global as globalThis } from '@storybook/global';
2
- import { html, LitElement } from 'lit';
2
+
3
+ import { LitElement, html } from 'lit';
3
4
 
4
5
  const { CustomEvent, customElements } = globalThis;
5
6
 
6
7
  /**
8
+ * @property {boolean} primary - Set button in primary mode
7
9
  * @attr {string} label - Label of the button
8
10
  * @attr {string} size - Size of the button, can be "small", "medium" or "large"; default is "medium".
9
11
  * @attr {string} backgroundColor - Color of the button's background
10
12
  *
11
- * @cssprop [--sb-primary-color=#1ea7fd] - Controls the color of bar
12
- *
13
- * @prop {boolean} primary - Set button in primary mode
14
- *
13
+ * @cssprop [--sb-primary-color=#1ea7fd] - Controls the color of bar. Default is `#1ea7fd`
15
14
  * @event {CustomEvent} sb-button:click - Custom event send when the button is clicked
16
15
  *
17
16
  * @summary This is a simple Storybook Button
@@ -1,5 +1,6 @@
1
1
  import { global as globalThis } from '@storybook/global';
2
- import { html, LitElement } from 'lit';
2
+
3
+ import { LitElement, html } from 'lit';
3
4
 
4
5
  const { CustomEvent, customElements } = globalThis;
5
6
 
@@ -1,12 +1,10 @@
1
1
  import { global as globalThis } from '@storybook/global';
2
+
2
3
  import { LitElement } from 'lit';
3
4
 
4
5
  const { customElements } = globalThis;
5
6
 
6
- /**
7
- *
8
- * @tag sb-html
9
- */
7
+ /** @tag sb-html */
10
8
  export class SbHtml extends LitElement {
11
9
  static get properties() {
12
10
  return {
@@ -1,14 +1,11 @@
1
1
  import { global as globalThis } from '@storybook/global';
2
- import { html, LitElement } from 'lit';
3
2
 
3
+ import { LitElement, html } from 'lit';
4
4
  import { styleMap } from 'lit/directives/style-map.js';
5
5
 
6
6
  const { customElements } = globalThis;
7
7
 
8
- /**
9
- *
10
- * @tag sb-pre
11
- */
8
+ /** @tag sb-pre */
12
9
  export class SbPre extends LitElement {
13
10
  // Currently TS decorators are not reflected so we have to use static `properties` function
14
11
  // https://github.com/Polymer/lit-html/issues/1476
@@ -1,4 +1,5 @@
1
1
  import { global } from '@storybook/global';
2
+
2
3
  import { LitElement, html } from 'lit';
3
4
 
4
5
  import { demoWcCardStyle } from './demoWcCardStyle.css.js';
@@ -8,8 +9,8 @@ const { CustomEvent } = global;
8
9
  /**
9
10
  * This is a container looking like a card with a back and front side you can switch
10
11
  *
11
- * @slot - This is an unnamed slot (the default slot)
12
12
  * @fires side-changed - Fires whenever it switches between front/back
13
+ * @slot - This is an unnamed slot (the default slot)
13
14
  * @cssprop --demo-wc-card-header-font-size - Header font size
14
15
  * @cssprop --demo-wc-card-front-color - Font color for front
15
16
  * @cssprop --demo-wc-card-back-color - Font color for back
@@ -36,19 +37,13 @@ export class DemoWcCard extends LitElement {
36
37
  constructor() {
37
38
  super();
38
39
 
39
- /**
40
- * Indicates that the back of the card is shown
41
- */
40
+ /** Indicates that the back of the card is shown */
42
41
  this.backSide = false;
43
42
 
44
- /**
45
- * Header message
46
- */
43
+ /** Header message */
47
44
  this.header = 'Your Message';
48
45
 
49
- /**
50
- * Data rows
51
- */
46
+ /** Data rows */
52
47
  this.rows = [];
53
48
  }
54
49
 
@@ -1,4 +1,5 @@
1
1
  import { html } from 'lit';
2
+
2
3
  import './demo-wc-card';
3
4
 
4
5
  export default {
@@ -1,4 +1,3 @@
1
- // eslint-disable-next-line import/no-extraneous-dependencies
2
1
  import { setCustomElementsManifest } from '@storybook/web-components';
3
2
 
4
3
  import customElementsManifest from './custom-elements.json';