@storybook/web-components 8.3.0-alpha.6 → 8.3.0-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,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,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_client_logger=require("storybook/internal/client-logger"),import_tiny_invariant=__toESM(require("tiny-invariant"));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_docs_tools=require("storybook/internal/docs-tools"),import_preview_api=require("storybook/internal/preview-api"),import_lit=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_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,4 +1,5 @@
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
4
  import { logger } from 'storybook/internal/client-logger';
4
5
  import invariant from 'tiny-invariant';
@@ -1,12 +1 @@
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 {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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/web-components",
3
- "version": "8.3.0-alpha.6",
3
+ "version": "8.3.0-alpha.8",
4
4
  "description": "Storybook web-components renderer",
5
5
  "keywords": [
6
6
  "lit",
@@ -50,11 +50,11 @@
50
50
  "prep": "jiti ../../../scripts/prepare/bundle.ts"
51
51
  },
52
52
  "dependencies": {
53
- "@storybook/components": "^8.3.0-alpha.6",
53
+ "@storybook/components": "^8.3.0-alpha.8",
54
54
  "@storybook/global": "^5.0.0",
55
- "@storybook/manager-api": "^8.3.0-alpha.6",
56
- "@storybook/preview-api": "^8.3.0-alpha.6",
57
- "@storybook/theming": "^8.3.0-alpha.6",
55
+ "@storybook/manager-api": "^8.3.0-alpha.8",
56
+ "@storybook/preview-api": "^8.3.0-alpha.8",
57
+ "@storybook/theming": "^8.3.0-alpha.8",
58
58
  "tiny-invariant": "^1.3.1",
59
59
  "ts-dedent": "^2.0.0"
60
60
  },
@@ -68,7 +68,7 @@
68
68
  },
69
69
  "peerDependencies": {
70
70
  "lit": "^2.0.0 || ^3.0.0",
71
- "storybook": "^8.3.0-alpha.6"
71
+ "storybook": "^8.3.0-alpha.8"
72
72
  },
73
73
  "engines": {
74
74
  "node": ">=18.0.0"
@@ -3,9 +3,7 @@ import { styleMap } from 'lit/directives/style-map.js';
3
3
 
4
4
  import './button.css';
5
5
 
6
- /**
7
- * Primary UI component for user interaction
8
- */
6
+ /** Primary UI component for user interaction */
9
7
  export const Button = ({ primary, backgroundColor = null, size, label, onClick }) => {
10
8
  const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
11
9
 
@@ -4,30 +4,18 @@ import { styleMap } from 'lit/directives/style-map.js';
4
4
  import './button.css';
5
5
 
6
6
  export interface ButtonProps {
7
- /**
8
- * Is this the principal call to action on the page?
9
- */
7
+ /** Is this the principal call to action on the page? */
10
8
  primary?: boolean;
11
- /**
12
- * What background color to use
13
- */
9
+ /** What background color to use */
14
10
  backgroundColor?: string;
15
- /**
16
- * How large should the button be?
17
- */
11
+ /** How large should the button be? */
18
12
  size?: 'small' | 'medium' | 'large';
19
- /**
20
- * Button contents
21
- */
13
+ /** Button contents */
22
14
  label: string;
23
- /**
24
- * Optional click handler
25
- */
15
+ /** Optional click handler */
26
16
  onClick?: () => void;
27
17
  }
28
- /**
29
- * Primary UI component for user interaction
30
- */
18
+ /** Primary UI component for user interaction */
31
19
  export const Button = ({ primary, backgroundColor, size, label, onClick }: ButtonProps) => {
32
20
  const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
33
21
 
@@ -4,30 +4,18 @@ import { styleMap } from 'lit/directives/style-map.js';
4
4
  import './button.css';
5
5
 
6
6
  export interface ButtonProps {
7
- /**
8
- * Is this the principal call to action on the page?
9
- */
7
+ /** Is this the principal call to action on the page? */
10
8
  primary?: boolean;
11
- /**
12
- * What background color to use
13
- */
9
+ /** What background color to use */
14
10
  backgroundColor?: string;
15
- /**
16
- * How large should the button be?
17
- */
11
+ /** How large should the button be? */
18
12
  size?: 'small' | 'medium' | 'large';
19
- /**
20
- * Button contents
21
- */
13
+ /** Button contents */
22
14
  label: string;
23
- /**
24
- * Optional click handler
25
- */
15
+ /** Optional click handler */
26
16
  onClick?: () => void;
27
17
  }
28
- /**
29
- * Primary UI component for user interaction
30
- */
18
+ /** Primary UI component for user interaction */
31
19
  export const Button = ({ primary, backgroundColor, size, label, onClick }: ButtonProps) => {
32
20
  const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
33
21
 
@@ -5,14 +5,12 @@ import { LitElement, html } from 'lit';
5
5
  const { CustomEvent, customElements } = globalThis;
6
6
 
7
7
  /**
8
+ * @property {boolean} primary - Set button in primary mode
8
9
  * @attr {string} label - Label of the button
9
10
  * @attr {string} size - Size of the button, can be "small", "medium" or "large"; default is "medium".
10
11
  * @attr {string} backgroundColor - Color of the button's background
11
12
  *
12
- * @cssprop [--sb-primary-color=#1ea7fd] - Controls the color of bar
13
- *
14
- * @prop {boolean} primary - Set button in primary mode
15
- *
13
+ * @cssprop [--sb-primary-color=#1ea7fd] - Controls the color of bar. Default is `#1ea7fd`
16
14
  * @event {CustomEvent} sb-button:click - Custom event send when the button is clicked
17
15
  *
18
16
  * @summary This is a simple Storybook Button
@@ -4,10 +4,7 @@ import { LitElement } from 'lit';
4
4
 
5
5
  const { customElements } = globalThis;
6
6
 
7
- /**
8
- *
9
- * @tag sb-html
10
- */
7
+ /** @tag sb-html */
11
8
  export class SbHtml extends LitElement {
12
9
  static get properties() {
13
10
  return {
@@ -5,10 +5,7 @@ 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
@@ -9,8 +9,8 @@ const { CustomEvent } = global;
9
9
  /**
10
10
  * This is a container looking like a card with a back and front side you can switch
11
11
  *
12
- * @slot - This is an unnamed slot (the default slot)
13
12
  * @fires side-changed - Fires whenever it switches between front/back
13
+ * @slot - This is an unnamed slot (the default slot)
14
14
  * @cssprop --demo-wc-card-header-font-size - Header font size
15
15
  * @cssprop --demo-wc-card-front-color - Font color for front
16
16
  * @cssprop --demo-wc-card-back-color - Font color for back
@@ -37,19 +37,13 @@ export class DemoWcCard extends LitElement {
37
37
  constructor() {
38
38
  super();
39
39
 
40
- /**
41
- * Indicates that the back of the card is shown
42
- */
40
+ /** Indicates that the back of the card is shown */
43
41
  this.backSide = false;
44
42
 
45
- /**
46
- * Header message
47
- */
43
+ /** Header message */
48
44
  this.header = 'Your Message';
49
45
 
50
- /**
51
- * Data rows
52
- */
46
+ /** Data rows */
53
47
  this.rows = [];
54
48
  }
55
49
 
@@ -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';