@storybook/vue3 7.2.0-canary-22285-1690367272-d07bfc52.0 → 7.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-CKUIH7TX.mjs → chunk-SRVBJOBI.mjs} +1 -1
- package/dist/config.d.ts +2 -2
- package/dist/config.js +3 -3
- package/dist/config.mjs +4 -4
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/index.mjs +2 -2
- package/dist/{render-210e2c92.d.ts → render-32b7dd3f.d.ts} +3 -3
- package/package.json +9 -16
- package/template/cli/ts-3-8/Button.vue +1 -1
- package/template/cli/ts-4-9/Button.vue +1 -1
- package/template/stories_vue3-vite-default-ts/GlobalSetup.stories.ts +1 -2
- package/template/stories_vue3-vite-default-ts/ReactiveArgs.stories.ts +3 -6
- package/template/stories_vue3-vite-default-ts/ReactiveDecorators.stories.ts +3 -5
- package/template/stories_vue3-vite-default-ts/ReactiveSlots.stories.ts +5 -8
- package/template/stories_vue3-vite-default-ts/ScopedSlots.stories.ts +7 -3
- package/template/stories_vue3-vite-default-ts/component-meta/OptionApi.stories.ts +0 -19
- package/template/stories_vue3-vite-default-ts/component-meta/ReferenceTypeEvents.stories.ts +0 -11
- package/template/stories_vue3-vite-default-ts/component-meta/ReferenceTypeExposed.stories.ts +0 -11
- package/template/stories_vue3-vite-default-ts/component-meta/ReferenceTypeProps.stories.ts +0 -31
- package/template/stories_vue3-vite-default-ts/component-meta/TemplateSlots.stories.ts +0 -18
- package/template/stories_vue3-vite-default-ts/component-meta/TsComponent.stories.ts +0 -12
- package/template/stories_vue3-vite-default-ts/component-meta/TsNameExport.stories.ts +0 -12
- package/template/stories_vue3-vite-default-ts/component-meta/class-slots/component.vue +0 -10
- package/template/stories_vue3-vite-default-ts/component-meta/empty-component/component.vue +0 -7
- package/template/stories_vue3-vite-default-ts/component-meta/options-api/component.ts +0 -65
- package/template/stories_vue3-vite-default-ts/component-meta/reference-type-events/component.vue +0 -30
- package/template/stories_vue3-vite-default-ts/component-meta/reference-type-exposed/component.vue +0 -22
- package/template/stories_vue3-vite-default-ts/component-meta/reference-type-props/component-js-setup.vue +0 -58
- package/template/stories_vue3-vite-default-ts/component-meta/reference-type-props/component-js.vue +0 -42
- package/template/stories_vue3-vite-default-ts/component-meta/reference-type-props/component.vue +0 -109
- package/template/stories_vue3-vite-default-ts/component-meta/reference-type-props/my-props.ts +0 -113
- package/template/stories_vue3-vite-default-ts/component-meta/template-slots/component-no-script.vue +0 -6
- package/template/stories_vue3-vite-default-ts/component-meta/template-slots/component.vue +0 -12
- package/template/stories_vue3-vite-default-ts/component-meta/ts-component/PropDefinitions.ts +0 -10
- package/template/stories_vue3-vite-default-ts/component-meta/ts-component/component.ts +0 -17
- package/template/stories_vue3-vite-default-ts/component-meta/ts-named-export/component.ts +0 -52
@@ -1,6 +1,6 @@
|
|
1
1
|
import { h, createApp, reactive, isVNode, isReactive } from 'vue';
|
2
2
|
import { sanitizeStoryContextUpdate } from '@storybook/preview-api';
|
3
3
|
|
4
|
-
function normalizeFunctionalComponent(options){return typeof options=="function"?{render:options,name:options.name}:options}function prepare(rawStory,innerStory){let story=rawStory;return story===null?null:typeof story=="function"?story:innerStory?{...normalizeFunctionalComponent(story),components:{...story.components||{},story:innerStory}}:{render(){return h(story)}}}function decorateStory(storyFn,decorators){return decorators.reduce((decorated,decorator)=>context=>{let story,decoratedStory=decorator(update=>{let sanitizedUpdate=sanitizeStoryContextUpdate(update);return update&&(sanitizedUpdate.args=Object.assign(context.args,sanitizedUpdate.args)),story=decorated({...context,...sanitizedUpdate}),story},context);return story||(story=decorated(context)),decoratedStory===story?story:prepare(decoratedStory,()=>h(story))},context=>prepare(storyFn(context)))}var render=(props,context)=>{let{id,component:Component}=context;if(!Component)throw new Error(`Unable to render story ${id} as the component annotation is missing from the default export`);return ()=>h(Component,props,generateSlots(context))},setupFunctions=new Set,setup=fn=>{setupFunctions.add(fn);},runSetupFunctions=(app,storyContext)=>{setupFunctions.forEach(fn=>fn(app,storyContext));},map=new Map;function renderToCanvas({storyFn,forceRemount,showMain,showException,storyContext,id},canvasElement){let existingApp=map.get(canvasElement);if(existingApp&&!forceRemount){let element=storyFn(),args=getArgs(element,storyContext);return updateArgs(existingApp.reactiveArgs,args),()=>{teardown(existingApp.vueApp,canvasElement);}}existingApp&&forceRemount&&teardown(existingApp.vueApp,canvasElement);let vueApp=createApp({setup(){storyContext.args=reactive(storyContext.args);let rootElement=storyFn(),args=getArgs(rootElement,storyContext),appState={vueApp,reactiveArgs:reactive(args)};return map.set(canvasElement,appState),()=>h(rootElement)}});return vueApp.config.errorHandler=e=>showException(e),runSetupFunctions(vueApp,storyContext),vueApp.mount(canvasElement),showMain(),()=>{teardown(vueApp,canvasElement);}}function generateSlots(context){let{argTypes}=context,slots=Object.entries(argTypes).filter(([key,value])=>argTypes[key]?.table?.category==="slots").map(([key,value])=>{let slotValue=context.args[key];return [key,typeof slotValue=="function"?slotValue:()=>slotValue]});return reactive(Object.fromEntries(slots))}function getArgs(element,storyContext){return
|
4
|
+
function normalizeFunctionalComponent(options){return typeof options=="function"?{render:options,name:options.name}:options}function prepare(rawStory,innerStory){let story=rawStory;return story===null?null:typeof story=="function"?story:innerStory?{...normalizeFunctionalComponent(story),components:{...story.components||{},story:innerStory}}:{render(){return h(story)}}}function decorateStory(storyFn,decorators){return decorators.reduce((decorated,decorator)=>context=>{let story,decoratedStory=decorator(update=>{let sanitizedUpdate=sanitizeStoryContextUpdate(update);return update&&(sanitizedUpdate.args=Object.assign(context.args,sanitizedUpdate.args)),story=decorated({...context,...sanitizedUpdate}),story},context);return story||(story=decorated(context)),decoratedStory===story?story:prepare(decoratedStory,()=>h(story))},context=>prepare(storyFn(context)))}var render=(props,context)=>{let{id,component:Component}=context;if(!Component)throw new Error(`Unable to render story ${id} as the component annotation is missing from the default export`);return ()=>h(Component,props,generateSlots(context))},setupFunctions=new Set,setup=fn=>{setupFunctions.add(fn);},runSetupFunctions=(app,storyContext)=>{setupFunctions.forEach(fn=>fn(app,storyContext));},map=new Map;function renderToCanvas({storyFn,forceRemount,showMain,showException,storyContext,id},canvasElement){let existingApp=map.get(canvasElement);if(existingApp&&!forceRemount){let element=storyFn(),args=getArgs(element,storyContext);return updateArgs(existingApp.reactiveArgs,args),()=>{teardown(existingApp.vueApp,canvasElement);}}existingApp&&forceRemount&&teardown(existingApp.vueApp,canvasElement);let vueApp=createApp({setup(){storyContext.args=reactive(storyContext.args);let rootElement=storyFn(),args=getArgs(rootElement,storyContext),appState={vueApp,reactiveArgs:reactive(args)};return map.set(canvasElement,appState),()=>h(rootElement)}});return vueApp.config.errorHandler=e=>showException(e),runSetupFunctions(vueApp,storyContext),vueApp.mount(canvasElement),showMain(),()=>{teardown(vueApp,canvasElement);}}function generateSlots(context){let{argTypes}=context,slots=Object.entries(argTypes).filter(([key,value])=>argTypes[key]?.table?.category==="slots").map(([key,value])=>{let slotValue=context.args[key];return [key,typeof slotValue=="function"?slotValue:()=>slotValue]});return reactive(Object.fromEntries(slots))}function getArgs(element,storyContext){return element.props&&isVNode(element)?element.props:storyContext.args}function updateArgs(reactiveArgs,nextArgs){if(Object.keys(nextArgs).length===0)return;let currentArgs=isReactive(reactiveArgs)?reactiveArgs:reactive(reactiveArgs);Object.keys(currentArgs).forEach(key=>{key in nextArgs||delete currentArgs[key];}),Object.assign(currentArgs,nextArgs);}function teardown(storybookApp,canvasElement){storybookApp?.unmount(),map.has(canvasElement)&&map.delete(canvasElement);}
|
5
5
|
|
6
6
|
export { decorateStory, render, renderToCanvas, setup };
|
package/dist/config.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Addon_DecoratorFunction, ArgTypesEnhancer, LegacyStoryFn, DecoratorFunction } from '@storybook/types';
|
2
|
-
import { V as VueRenderer } from './render-
|
3
|
-
export { r as render, a as renderToCanvas } from './render-
|
2
|
+
import { V as VueRenderer } from './render-32b7dd3f.js';
|
3
|
+
export { r as render, a as renderToCanvas } from './render-32b7dd3f.js';
|
4
4
|
import 'vue';
|
5
5
|
|
6
6
|
declare const decorators: Addon_DecoratorFunction<unknown>[];
|
package/dist/config.js
CHANGED
@@ -1,5 +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 config_exports={};__export(config_exports,{applyDecorators:()=>decorateStory,argTypesEnhancers:()=>argTypesEnhancers,decorators:()=>decorators,parameters:()=>parameters2,render:()=>render,renderToCanvas:()=>renderToCanvas});module.exports=__toCommonJS(config_exports);var import_docs_tools3=require("@storybook/docs-tools");var import_docs_tools=require("@storybook/docs-tools"),
|
2
|
-
`)}</script>`}function getTemplateComponents(renderFn,context){try{let originalStoryFn=renderFn,storyFn=originalStoryFn?originalStoryFn(context==null?void 0:context.args,context):context==null?void 0:context.component,story=typeof storyFn=="function"?storyFn():storyFn,{template}=story;return template?getComponents(template):[(0,import_vue.h)(story,context==null?void 0:context.args)]}catch{return[]}}function getComponents(template){let ast=(0,import_compiler_core.baseParse)(template),components=ast==null?void 0:ast.children;return components||[]}function generateTemplateSource(componentOrNodes,{args,argTypes},byRef=!1){let isElementNode=node=>node&&node.type===1,isInterpolationNode=node=>node&&node.type===5,isTextNode=node=>node&&node.type===2,generateComponentSource=componentOrNode=>{var _a,_b;if(isElementNode(componentOrNode)){let{tag:name,props:attributes,children}=componentOrNode,childSources=typeof children=="string"?children:children.map(child=>generateComponentSource(child)).join(""),props=generateAttributesSource(attributes,args,argTypes,byRef);return childSources===""?`<${name} ${props} />`:`<${name} ${props}>${childSources}</${name}>`}if(isTextNode(componentOrNode)){let{content:content2}=componentOrNode;return content2}if(isInterpolationNode(componentOrNode)){let{content}=componentOrNode,expValue=evalExp(content.loc.source,args);return expValue===content.loc.source?`{{${expValue}}}`:eval(expValue)}if((0,import_vue.isVNode)(componentOrNode)){let vnode=componentOrNode,{props,type,children}=vnode,slotsProps=typeof children=="string"?void 0:children,componentSlots=(_a=type==null?void 0:type.__docgenInfo)==null?void 0:_a.slots,attrsProps=slotsProps?Object.fromEntries(Object.entries(props??{}).filter(([key,value])=>!slotsProps[key]&&!["class","style"].includes(key)).map(([key,value])=>[key,value])):props,attributes=mapAttributesAndDirectives(attrsProps??{}),slotArgs=Object.fromEntries(Object.entries(props??{}).filter(([key,value])=>slotsProps==null?void 0:slotsProps[key])),childSources=children?typeof children=="string"?children:mapSlots(slotArgs,generateComponentSource,componentSlots??[]).map(child=>child.content).join(""):"",name=typeof type=="string"?type:type.name||type.__name||((_b=type.__docgenInfo)==null?void 0:_b.displayName),propsSource=generateAttributesSource(attributes,args,argTypes,byRef);return childSources.trim()===""?`<${name} ${propsSource}/>`:`<${name} ${propsSource}>${childSources}</${name}>`}return null},componentsOrNodes=Array.isArray(componentOrNodes)?componentOrNodes:[componentOrNodes],source=componentsOrNodes.map(componentOrNode2=>generateComponentSource(componentOrNode2)).join(" ");return source||null}var sourceDecorator=(storyFn,context)=>{let skip=skipSourceRender(context),story=storyFn();return(0,import_vue.watch)(()=>context.args,()=>{skip||generateSource(context)},{immediate:!0,deep:!0}),story};function generateSource(context){var _a,_b,_c;let channel=import_preview_api.addons.getChannel(),{args:args2={},argTypes:argTypes2={},id}=context||{},storyComponents=getTemplateComponents(context==null?void 0:context.originalStoryFn,context),withScript=((_c=(_b=(_a=context==null?void 0:context.parameters)==null?void 0:_a.docs)==null?void 0:_b.source)==null?void 0:_c.withScriptSetup)||!1,generatedScript=withScript?generateScriptSetup(args2,argTypes2,storyComponents):"",generatedTemplate=generateTemplateSource(storyComponents,context,withScript);if(generatedTemplate){let source2=`${generatedScript}
|
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 config_exports={};__export(config_exports,{applyDecorators:()=>decorateStory,argTypesEnhancers:()=>argTypesEnhancers,decorators:()=>decorators,parameters:()=>parameters2,render:()=>render,renderToCanvas:()=>renderToCanvas});module.exports=__toCommonJS(config_exports);var import_docs_tools3=require("@storybook/docs-tools");var import_docs_tools=require("@storybook/docs-tools"),SECTIONS=["props","events","slots","methods"],extractArgTypes=component=>{if(!(0,import_docs_tools.hasDocgen)(component))return null;let results={};return SECTIONS.forEach(section=>{(0,import_docs_tools.extractComponentProps)(component,section).forEach(({propDef,docgenInfo,jsDocTags})=>{let{name,type,description,defaultValue:defaultSummary,required}=propDef,sbType=section==="props"?(0,import_docs_tools.convert)(docgenInfo):{name:"void"};results[name]={name,description,type:{required,...sbType},table:{type,jsDocTags,defaultValue:defaultSummary,category:section}}})}),results};var import_preview_api=require("@storybook/preview-api"),import_docs_tools2=require("@storybook/docs-tools"),import_compiler_core=require("@vue/compiler-core"),import_vue=require("vue"),import_lodash=require("lodash");var omitEvent=args2=>args2?Object.fromEntries(Object.entries(args2).filter(([key,value])=>!key.startsWith("on"))):{},displayObject=obj=>obj&&typeof obj=="object"?`{${Object.keys(obj).map(key=>`${key}:${displayObject(obj[key])}`).join(",")}}`:typeof obj=="string"?`'${obj}'`:obj==null?void 0:obj.toString(),htmlEventAttributeToVueEventAttribute=key=>/^on[A-Za-z]/.test(key)?key.replace(/^on/,"v-on:").toLowerCase():key,directiveSource=(key,value)=>key.includes("on")?`${htmlEventAttributeToVueEventAttribute(key)}='()=>({})'`:`${key}="${value}"`,attributeSource=(key,value,dynamic)=>["boolean","number","object"].includes(typeof value)||dynamic&&["style","class"].includes(key)?`:${key}="${displayObject(value)}"`:directiveSource(key,value),evalExp=(argExpValue,args2)=>{let evalVal=argExpValue;return evalVal&&/v-bind="(\w+)"/.test(evalVal)?evalVal.replace(/"(\w+)"/g,`"${displayObject(args2)}"`):(Object.keys(args2).forEach(akey=>{let regexMatch=new RegExp(`(\\w+)\\.${akey}`,"g"),regexTarget=new RegExp(`(\\w+)\\.${akey}`,"g");regexMatch.test(evalVal)&&(evalVal=evalVal.replace(regexTarget,displayObject(args2[akey])))}),evalVal)},replaceValueWithRef=(source2,args2,ref)=>{let value=ref?args2[ref]:"args",bindValue=()=>{let argsRef=Object.fromEntries(Object.entries(args2).map(([key])=>[key,key]));return displayObject(argsRef).replace(/'/g,"")},regexMatch=new RegExp(`="${value}"`,"g");return source2.replace(regexMatch,`="${ref??bindValue()}"`)};function generateExpression(slot){let body=slot.toString().split("=>")[1].trim().replace("return","").trim();return body.startsWith("{")&&body.endsWith("}")&&(body=body.substring(1,body.length-1).trim()),`{{${body}}}`}var skipSourceRender=context=>{var _a;let sourceParams=(_a=context==null?void 0:context.parameters.docs)==null?void 0:_a.source,isArgsStory=context==null?void 0:context.parameters.__isArgsStory,isDocsViewMode=(context==null?void 0:context.viewMode)==="docs";return(sourceParams==null?void 0:sourceParams.type)===import_docs_tools2.SourceType.DYNAMIC?!1:!isDocsViewMode||!isArgsStory||(sourceParams==null?void 0:sourceParams.code)||(sourceParams==null?void 0:sourceParams.type)===import_docs_tools2.SourceType.CODE};function generateAttributesSource(tempArgs,args2,argTypes2,byRef2){return Object.keys(tempArgs).map(key=>{var _a;let source2=tempArgs[key].loc.source.replace(/\$props/g,"args"),argKey=(_a=tempArgs[key].arg)==null?void 0:_a.loc.source;return byRef2&&argKey?replaceValueWithRef(source2,args2,argKey):evalExp(source2,omitEvent(args2))}).join(" ")}function mapAttributesAndDirectives(props){let tranformKey=key=>key.startsWith("on")?key:(0,import_lodash.kebabCase)(key);return Object.keys(props).map(key=>({name:"bind",type:["v-","@","v-on"].includes(key)?7:6,arg:{content:tranformKey(key),loc:{source:tranformKey(key)}},loc:{source:attributeSource(tranformKey(key),props[key])},exp:{isStatic:!1,loc:{source:props[key]}},modifiers:[""]}))}function mapSlots(slotsArgs,generateComponentSource2,slots){return Object.keys(slotsArgs).map(key=>{var _a,_b;let slot=slotsArgs[key],slotContent="",scropedArgs=(_b=(_a=slots.find(s=>s.name===key&&s.scoped))==null?void 0:_a.bindings)==null?void 0:_b.map(b=>b.name).join(",");typeof slot=="function"&&(slotContent=generateExpression(slot)),(0,import_vue.isVNode)(slot)&&(slotContent=generateComponentSource2(slot)),typeof slot=="object"&&!(0,import_vue.isVNode)(slot)&&(slotContent=JSON.stringify(slot));let bindingsString=scropedArgs?`="{${scropedArgs}}"`:"";return slotContent=slot?`<template #${key}${bindingsString}>${slotContent}</template>`:"",{type:2,content:slotContent,loc:{source:slotContent,start:{offset:0,line:1,column:0},end:{offset:0,line:1,column:0}}}})}function generateScriptSetup(args2,argTypes2,components){let scriptLines=Object.keys(args2).map(key=>`const ${key} = ${typeof args2[key]=="function"?"()=>{}":`ref(${JSON.stringify(args2[key])});`}`);return scriptLines.unshift('import { ref } from "vue";'),`<script lang='ts' setup>${scriptLines.join(`
|
2
|
+
`)}</script>`}function getTemplateComponents(renderFn,context){try{let originalStoryFn=renderFn,storyFn=originalStoryFn?originalStoryFn(context==null?void 0:context.args,context):context==null?void 0:context.component,story=typeof storyFn=="function"?storyFn():storyFn,{template}=story;return template?getComponents(template):[(0,import_vue.h)(story,context==null?void 0:context.args)]}catch(e){return console.log("error",e),[]}}function getComponents(template){let ast=(0,import_compiler_core.baseParse)(template),components=ast==null?void 0:ast.children;return components||[]}function generateTemplateSource(componentOrNodes,{args,argTypes},byRef=!1){let isElementNode=node=>node&&node.type===1,isInterpolationNode=node=>node&&node.type===5,isTextNode=node=>node&&node.type===2,generateComponentSource=componentOrNode=>{var _a,_b;if(isElementNode(componentOrNode)){let{tag:name,props:attributes,children}=componentOrNode,childSources=typeof children=="string"?children:children.map(child=>generateComponentSource(child)).join(""),props=generateAttributesSource(attributes,args,argTypes,byRef);return childSources===""?`<${name} ${props} />`:`<${name} ${props}>${childSources}</${name}>`}if(isTextNode(componentOrNode)){let{content:content2}=componentOrNode;return content2}if(isInterpolationNode(componentOrNode)){let{content}=componentOrNode,expValue=evalExp(content.loc.source,args);return expValue===content.loc.source?`{{${expValue}}}`:eval(expValue)}if((0,import_vue.isVNode)(componentOrNode)){let vnode=componentOrNode,{props,type,children}=vnode,slotsProps=typeof children=="string"?void 0:children,componentSlots=(_a=type==null?void 0:type.__docgenInfo)==null?void 0:_a.slots,attrsProps=slotsProps?Object.fromEntries(Object.entries(props??{}).filter(([key,value])=>!slotsProps[key]&&!["class","style"].includes(key)).map(([key,value])=>[key,value])):props,attributes=mapAttributesAndDirectives(attrsProps??{}),slotArgs=Object.fromEntries(Object.entries(props??{}).filter(([key,value])=>slotsProps==null?void 0:slotsProps[key])),childSources=children?typeof children=="string"?children:mapSlots(slotArgs,generateComponentSource,componentSlots??[]).map(child=>child.content).join(""):"";console.log(" vnode ",vnode," childSources ",childSources," attributes ",attributes);let name=typeof type=="string"?type:type.name||type.__name||((_b=type.__docgenInfo)==null?void 0:_b.displayName),propsSource=generateAttributesSource(attributes,args,argTypes,byRef);return childSources.trim()===""?`<${name} ${propsSource}/>`:`<${name} ${propsSource}>${childSources}</${name}>`}return null},componentsOrNodes=Array.isArray(componentOrNodes)?componentOrNodes:[componentOrNodes],source=componentsOrNodes.map(componentOrNode2=>generateComponentSource(componentOrNode2)).join(" ");return source||null}var sourceDecorator=(storyFn,context)=>{let skip=skipSourceRender(context),story=storyFn();return(0,import_vue.watch)(()=>context.args,()=>{skip||generateSource(context)},{immediate:!0,deep:!0}),story};function generateSource(context){var _a,_b,_c;let channel=import_preview_api.addons.getChannel(),{args:args2={},argTypes:argTypes2={},id}=context||{},storyComponents=getTemplateComponents(context==null?void 0:context.originalStoryFn,context),withScript=((_c=(_b=(_a=context==null?void 0:context.parameters)==null?void 0:_a.docs)==null?void 0:_b.source)==null?void 0:_c.withScriptSetup)||!1,generatedScript=withScript?generateScriptSetup(args2,argTypes2,storyComponents):"",generatedTemplate=generateTemplateSource(storyComponents,context,withScript);if(generatedTemplate){let source2=`${generatedScript}
|
3
3
|
<template>
|
4
4
|
${generatedTemplate}
|
5
|
-
</template>`;return channel.emit(import_docs_tools2.SNIPPET_RENDERED,{id,args:args2,source:source2,format:"vue"}),source2}return null}var parameters={docs:{story:{inline:!0},extractArgTypes,extractComponentDescription:import_docs_tools3.extractComponentDescription}},decorators=[sourceDecorator],argTypesEnhancers=[import_docs_tools3.enhanceArgTypes];var import_vue2=require("vue"),render=(props,context)=>{let{id,component:Component}=context;if(!Component)throw new Error(`Unable to render story ${id} as the component annotation is missing from the default export`);return()=>(0,import_vue2.h)(Component,props,generateSlots(context))},setupFunctions=new Set;var runSetupFunctions=(app,storyContext)=>{setupFunctions.forEach(fn=>fn(app,storyContext))},map=new Map;function renderToCanvas({storyFn,forceRemount,showMain,showException,storyContext,id},canvasElement){let existingApp=map.get(canvasElement);if(existingApp&&!forceRemount){let element=storyFn(),args2=getArgs(element,storyContext);return updateArgs(existingApp.reactiveArgs,args2),()=>{teardown(existingApp.vueApp,canvasElement)}}existingApp&&forceRemount&&teardown(existingApp.vueApp,canvasElement);let vueApp=(0,import_vue2.createApp)({setup(){storyContext.args=(0,import_vue2.reactive)(storyContext.args);let rootElement=storyFn(),args2=getArgs(rootElement,storyContext),appState={vueApp,reactiveArgs:(0,import_vue2.reactive)(args2)};return map.set(canvasElement,appState),()=>(0,import_vue2.h)(rootElement)}});return vueApp.config.errorHandler=e=>showException(e),runSetupFunctions(vueApp,storyContext),vueApp.mount(canvasElement),showMain(),()=>{teardown(vueApp,canvasElement)}}function generateSlots(context){let{argTypes:argTypes2}=context,slots=Object.entries(argTypes2).filter(([key,value])=>{var _a,_b;return((_b=(_a=argTypes2[key])==null?void 0:_a.table)==null?void 0:_b.category)==="slots"}).map(([key,value])=>{let slotValue=context.args[key];return[key,typeof slotValue=="function"?slotValue:()=>slotValue]});return(0,import_vue2.reactive)(Object.fromEntries(slots))}function getArgs(element,storyContext){return
|
5
|
+
</template>`;return channel.emit(import_docs_tools2.SNIPPET_RENDERED,{id,args:args2,source:source2,format:"vue"}),source2}return null}var parameters={docs:{story:{inline:!0},extractArgTypes,extractComponentDescription:import_docs_tools3.extractComponentDescription}},decorators=[sourceDecorator],argTypesEnhancers=[import_docs_tools3.enhanceArgTypes];var import_vue2=require("vue"),render=(props,context)=>{let{id,component:Component}=context;if(!Component)throw new Error(`Unable to render story ${id} as the component annotation is missing from the default export`);return()=>(0,import_vue2.h)(Component,props,generateSlots(context))},setupFunctions=new Set;var runSetupFunctions=(app,storyContext)=>{setupFunctions.forEach(fn=>fn(app,storyContext))},map=new Map;function renderToCanvas({storyFn,forceRemount,showMain,showException,storyContext,id},canvasElement){let existingApp=map.get(canvasElement);if(existingApp&&!forceRemount){let element=storyFn(),args2=getArgs(element,storyContext);return updateArgs(existingApp.reactiveArgs,args2),()=>{teardown(existingApp.vueApp,canvasElement)}}existingApp&&forceRemount&&teardown(existingApp.vueApp,canvasElement);let vueApp=(0,import_vue2.createApp)({setup(){storyContext.args=(0,import_vue2.reactive)(storyContext.args);let rootElement=storyFn(),args2=getArgs(rootElement,storyContext),appState={vueApp,reactiveArgs:(0,import_vue2.reactive)(args2)};return map.set(canvasElement,appState),()=>(0,import_vue2.h)(rootElement)}});return vueApp.config.errorHandler=e=>showException(e),runSetupFunctions(vueApp,storyContext),vueApp.mount(canvasElement),showMain(),()=>{teardown(vueApp,canvasElement)}}function generateSlots(context){let{argTypes:argTypes2}=context,slots=Object.entries(argTypes2).filter(([key,value])=>{var _a,_b;return((_b=(_a=argTypes2[key])==null?void 0:_a.table)==null?void 0:_b.category)==="slots"}).map(([key,value])=>{let slotValue=context.args[key];return[key,typeof slotValue=="function"?slotValue:()=>slotValue]});return(0,import_vue2.reactive)(Object.fromEntries(slots))}function getArgs(element,storyContext){return element.props&&(0,import_vue2.isVNode)(element)?element.props:storyContext.args}function updateArgs(reactiveArgs,nextArgs){if(Object.keys(nextArgs).length===0)return;let currentArgs=(0,import_vue2.isReactive)(reactiveArgs)?reactiveArgs:(0,import_vue2.reactive)(reactiveArgs);Object.keys(currentArgs).forEach(key=>{key in nextArgs||delete currentArgs[key]}),Object.assign(currentArgs,nextArgs)}function teardown(storybookApp,canvasElement){storybookApp==null||storybookApp.unmount(),map.has(canvasElement)&&map.delete(canvasElement)}var import_vue3=require("vue"),import_preview_api2=require("@storybook/preview-api");function normalizeFunctionalComponent(options){return typeof options=="function"?{render:options,name:options.name}:options}function prepare(rawStory,innerStory){let story=rawStory;return story===null?null:typeof story=="function"?story:innerStory?{...normalizeFunctionalComponent(story),components:{...story.components||{},story:innerStory}}:{render(){return(0,import_vue3.h)(story)}}}function decorateStory(storyFn,decorators2){return decorators2.reduce((decorated,decorator)=>context=>{let story,decoratedStory=decorator(update=>{let sanitizedUpdate=(0,import_preview_api2.sanitizeStoryContextUpdate)(update);return update&&(sanitizedUpdate.args=Object.assign(context.args,sanitizedUpdate.args)),story=decorated({...context,...sanitizedUpdate}),story},context);return story||(story=decorated(context)),decoratedStory===story?story:prepare(decoratedStory,()=>(0,import_vue3.h)(story))},context=>prepare(storyFn(context)))}var parameters2={renderer:"vue3",...parameters};0&&(module.exports={applyDecorators,argTypesEnhancers,decorators,parameters,render,renderToCanvas});
|
package/dist/config.mjs
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
export { decorateStory as applyDecorators, render, renderToCanvas } from './chunk-
|
2
|
-
import { enhanceArgTypes, SNIPPET_RENDERED, extractComponentDescription, hasDocgen, extractComponentProps, SourceType } from '@storybook/docs-tools';
|
1
|
+
export { decorateStory as applyDecorators, render, renderToCanvas } from './chunk-SRVBJOBI.mjs';
|
2
|
+
import { enhanceArgTypes, SNIPPET_RENDERED, extractComponentDescription, hasDocgen, extractComponentProps, convert, SourceType } from '@storybook/docs-tools';
|
3
3
|
import { addons } from '@storybook/preview-api';
|
4
4
|
import { baseParse } from '@vue/compiler-core';
|
5
5
|
import { watch, h, isVNode } from 'vue';
|
6
6
|
import { kebabCase } from 'lodash';
|
7
7
|
|
8
|
-
var
|
9
|
-
`)}<\/script>`}function getTemplateComponents(renderFn,context){try{let originalStoryFn=renderFn,storyFn=originalStoryFn?originalStoryFn(context?.args,context):context?.component,story=typeof storyFn=="function"?storyFn():storyFn,{template}=story;return template?getComponents(template):[h(story,context?.args)]}catch{return []}}function getComponents(template){let components=baseParse(template)?.children;return components||[]}function generateTemplateSource(componentOrNodes,{args,argTypes},byRef=!1){let isElementNode=node=>node&&node.type===1,isInterpolationNode=node=>node&&node.type===5,isTextNode=node=>node&&node.type===2,generateComponentSource=componentOrNode=>{if(isElementNode(componentOrNode)){let{tag:name,props:attributes,children}=componentOrNode,childSources=typeof children=="string"?children:children.map(child=>generateComponentSource(child)).join(""),props=generateAttributesSource(attributes,args,argTypes,byRef);return childSources===""?`<${name} ${props} />`:`<${name} ${props}>${childSources}</${name}>`}if(isTextNode(componentOrNode)){let{content:content2}=componentOrNode;return content2}if(isInterpolationNode(componentOrNode)){let{content}=componentOrNode,expValue=evalExp(content.loc.source,args);return expValue===content.loc.source?`{{${expValue}}}`:eval(expValue)}if(isVNode(componentOrNode)){let vnode=componentOrNode,{props,type,children}=vnode,slotsProps=typeof children=="string"?void 0:children,componentSlots=type?.__docgenInfo?.slots,attrsProps=slotsProps?Object.fromEntries(Object.entries(props??{}).filter(([key,value])=>!slotsProps[key]&&!["class","style"].includes(key)).map(([key,value])=>[key,value])):props,attributes=mapAttributesAndDirectives(attrsProps??{}),slotArgs=Object.fromEntries(Object.entries(props??{}).filter(([key,value])=>slotsProps?.[key])),childSources=children?typeof children=="string"?children:mapSlots(slotArgs,generateComponentSource,componentSlots??[]).map(child=>child.content).join(""):"",name=typeof type=="string"?type:type.name||type.__name||type.__docgenInfo?.displayName,propsSource=generateAttributesSource(attributes,args,argTypes,byRef);return childSources.trim()===""?`<${name} ${propsSource}/>`:`<${name} ${propsSource}>${childSources}</${name}>`}return null},componentsOrNodes=Array.isArray(componentOrNodes)?componentOrNodes:[componentOrNodes],source=componentsOrNodes.map(componentOrNode2=>generateComponentSource(componentOrNode2)).join(" ");return source||null}var sourceDecorator=(storyFn,context)=>{let skip=skipSourceRender(context),story=storyFn();return watch(()=>context.args,()=>{skip||generateSource(context);},{immediate:!0,deep:!0}),story};function generateSource(context){let channel=addons.getChannel(),{args:args2={},argTypes:argTypes2={},id}=context||{},storyComponents=getTemplateComponents(context?.originalStoryFn,context),withScript=context?.parameters?.docs?.source?.withScriptSetup||!1,generatedScript=withScript?generateScriptSetup(args2):"",generatedTemplate=generateTemplateSource(storyComponents,context,withScript);if(generatedTemplate){let source2=`${generatedScript}
|
8
|
+
var SECTIONS=["props","events","slots","methods"],extractArgTypes=component=>{if(!hasDocgen(component))return null;let results={};return SECTIONS.forEach(section=>{extractComponentProps(component,section).forEach(({propDef,docgenInfo,jsDocTags})=>{let{name,type,description,defaultValue:defaultSummary,required}=propDef,sbType=section==="props"?convert(docgenInfo):{name:"void"};results[name]={name,description,type:{required,...sbType},table:{type,jsDocTags,defaultValue:defaultSummary,category:section}};});}),results};var omitEvent=args2=>args2?Object.fromEntries(Object.entries(args2).filter(([key,value])=>!key.startsWith("on"))):{},displayObject=obj=>obj&&typeof obj=="object"?`{${Object.keys(obj).map(key=>`${key}:${displayObject(obj[key])}`).join(",")}}`:typeof obj=="string"?`'${obj}'`:obj?.toString(),htmlEventAttributeToVueEventAttribute=key=>/^on[A-Za-z]/.test(key)?key.replace(/^on/,"v-on:").toLowerCase():key,directiveSource=(key,value)=>key.includes("on")?`${htmlEventAttributeToVueEventAttribute(key)}='()=>({})'`:`${key}="${value}"`,attributeSource=(key,value,dynamic)=>["boolean","number","object"].includes(typeof value)||dynamic&&["style","class"].includes(key)?`:${key}="${displayObject(value)}"`:directiveSource(key,value),evalExp=(argExpValue,args2)=>{let evalVal=argExpValue;return evalVal&&/v-bind="(\w+)"/.test(evalVal)?evalVal.replace(/"(\w+)"/g,`"${displayObject(args2)}"`):(Object.keys(args2).forEach(akey=>{let regexMatch=new RegExp(`(\\w+)\\.${akey}`,"g"),regexTarget=new RegExp(`(\\w+)\\.${akey}`,"g");regexMatch.test(evalVal)&&(evalVal=evalVal.replace(regexTarget,displayObject(args2[akey])));}),evalVal)},replaceValueWithRef=(source2,args2,ref)=>{let value=ref?args2[ref]:"args",bindValue=()=>{let argsRef=Object.fromEntries(Object.entries(args2).map(([key])=>[key,key]));return displayObject(argsRef).replace(/'/g,"")},regexMatch=new RegExp(`="${value}"`,"g");return source2.replace(regexMatch,`="${ref??bindValue()}"`)};function generateExpression(slot){let body=slot.toString().split("=>")[1].trim().replace("return","").trim();return body.startsWith("{")&&body.endsWith("}")&&(body=body.substring(1,body.length-1).trim()),`{{${body}}}`}var skipSourceRender=context=>{let sourceParams=context?.parameters.docs?.source,isArgsStory=context?.parameters.__isArgsStory,isDocsViewMode=context?.viewMode==="docs";return sourceParams?.type===SourceType.DYNAMIC?!1:!isDocsViewMode||!isArgsStory||sourceParams?.code||sourceParams?.type===SourceType.CODE};function generateAttributesSource(tempArgs,args2,argTypes2,byRef2){return Object.keys(tempArgs).map(key=>{let source2=tempArgs[key].loc.source.replace(/\$props/g,"args"),argKey=tempArgs[key].arg?.loc.source;return byRef2&&argKey?replaceValueWithRef(source2,args2,argKey):evalExp(source2,omitEvent(args2))}).join(" ")}function mapAttributesAndDirectives(props){let tranformKey=key=>key.startsWith("on")?key:kebabCase(key);return Object.keys(props).map(key=>({name:"bind",type:["v-","@","v-on"].includes(key)?7:6,arg:{content:tranformKey(key),loc:{source:tranformKey(key)}},loc:{source:attributeSource(tranformKey(key),props[key])},exp:{isStatic:!1,loc:{source:props[key]}},modifiers:[""]}))}function mapSlots(slotsArgs,generateComponentSource2,slots){return Object.keys(slotsArgs).map(key=>{let slot=slotsArgs[key],slotContent="",scropedArgs=slots.find(s=>s.name===key&&s.scoped)?.bindings?.map(b=>b.name).join(",");typeof slot=="function"&&(slotContent=generateExpression(slot)),isVNode(slot)&&(slotContent=generateComponentSource2(slot)),typeof slot=="object"&&!isVNode(slot)&&(slotContent=JSON.stringify(slot));let bindingsString=scropedArgs?`="{${scropedArgs}}"`:"";return slotContent=slot?`<template #${key}${bindingsString}>${slotContent}</template>`:"",{type:2,content:slotContent,loc:{source:slotContent,start:{offset:0,line:1,column:0},end:{offset:0,line:1,column:0}}}})}function generateScriptSetup(args2,argTypes2,components){let scriptLines=Object.keys(args2).map(key=>`const ${key} = ${typeof args2[key]=="function"?"()=>{}":`ref(${JSON.stringify(args2[key])});`}`);return scriptLines.unshift('import { ref } from "vue";'),`<script lang='ts' setup>${scriptLines.join(`
|
9
|
+
`)}<\/script>`}function getTemplateComponents(renderFn,context){try{let originalStoryFn=renderFn,storyFn=originalStoryFn?originalStoryFn(context?.args,context):context?.component,story=typeof storyFn=="function"?storyFn():storyFn,{template}=story;return template?getComponents(template):[h(story,context?.args)]}catch(e){return console.log("error",e),[]}}function getComponents(template){let components=baseParse(template)?.children;return components||[]}function generateTemplateSource(componentOrNodes,{args,argTypes},byRef=!1){let isElementNode=node=>node&&node.type===1,isInterpolationNode=node=>node&&node.type===5,isTextNode=node=>node&&node.type===2,generateComponentSource=componentOrNode=>{if(isElementNode(componentOrNode)){let{tag:name,props:attributes,children}=componentOrNode,childSources=typeof children=="string"?children:children.map(child=>generateComponentSource(child)).join(""),props=generateAttributesSource(attributes,args,argTypes,byRef);return childSources===""?`<${name} ${props} />`:`<${name} ${props}>${childSources}</${name}>`}if(isTextNode(componentOrNode)){let{content:content2}=componentOrNode;return content2}if(isInterpolationNode(componentOrNode)){let{content}=componentOrNode,expValue=evalExp(content.loc.source,args);return expValue===content.loc.source?`{{${expValue}}}`:eval(expValue)}if(isVNode(componentOrNode)){let vnode=componentOrNode,{props,type,children}=vnode,slotsProps=typeof children=="string"?void 0:children,componentSlots=type?.__docgenInfo?.slots,attrsProps=slotsProps?Object.fromEntries(Object.entries(props??{}).filter(([key,value])=>!slotsProps[key]&&!["class","style"].includes(key)).map(([key,value])=>[key,value])):props,attributes=mapAttributesAndDirectives(attrsProps??{}),slotArgs=Object.fromEntries(Object.entries(props??{}).filter(([key,value])=>slotsProps?.[key])),childSources=children?typeof children=="string"?children:mapSlots(slotArgs,generateComponentSource,componentSlots??[]).map(child=>child.content).join(""):"";console.log(" vnode ",vnode," childSources ",childSources," attributes ",attributes);let name=typeof type=="string"?type:type.name||type.__name||type.__docgenInfo?.displayName,propsSource=generateAttributesSource(attributes,args,argTypes,byRef);return childSources.trim()===""?`<${name} ${propsSource}/>`:`<${name} ${propsSource}>${childSources}</${name}>`}return null},componentsOrNodes=Array.isArray(componentOrNodes)?componentOrNodes:[componentOrNodes],source=componentsOrNodes.map(componentOrNode2=>generateComponentSource(componentOrNode2)).join(" ");return source||null}var sourceDecorator=(storyFn,context)=>{let skip=skipSourceRender(context),story=storyFn();return watch(()=>context.args,()=>{skip||generateSource(context);},{immediate:!0,deep:!0}),story};function generateSource(context){let channel=addons.getChannel(),{args:args2={},argTypes:argTypes2={},id}=context||{},storyComponents=getTemplateComponents(context?.originalStoryFn,context),withScript=context?.parameters?.docs?.source?.withScriptSetup||!1,generatedScript=withScript?generateScriptSetup(args2):"",generatedTemplate=generateTemplateSource(storyComponents,context,withScript);if(generatedTemplate){let source2=`${generatedScript}
|
10
10
|
<template>
|
11
11
|
${generatedTemplate}
|
12
12
|
</template>`;return channel.emit(SNIPPET_RENDERED,{id,args:args2,source:source2,format:"vue"}),source2}return null}var parameters={docs:{story:{inline:!0},extractArgTypes,extractComponentDescription}},decorators=[sourceDecorator],argTypesEnhancers=[enhanceArgTypes];var parameters2={renderer:"vue3",...parameters};
|
package/dist/index.d.ts
CHANGED
@@ -2,8 +2,8 @@ import * as _storybook_types from '@storybook/types';
|
|
2
2
|
import { Addon_ClientStoryApi, Addon_Loadable, Args, ComponentAnnotations, AnnotatedStoryFn, ArgsStoryFn, ArgsFromMeta, StoryAnnotations, StrictArgs, DecoratorFunction, LoaderFunction, StoryContext as StoryContext$1, ProjectAnnotations } from '@storybook/types';
|
3
3
|
export { ArgTypes, Args, Parameters, StrictArgs } from '@storybook/types';
|
4
4
|
import { App, FunctionalComponent, VNodeChild } from 'vue';
|
5
|
-
import { V as VueRenderer } from './render-
|
6
|
-
export { s as setup } from './render-
|
5
|
+
import { V as VueRenderer } from './render-32b7dd3f.js';
|
6
|
+
export { s as setup } from './render-32b7dd3f.js';
|
7
7
|
import { Simplify, SetOptional, Constructor, RemoveIndexSignature } from 'type-fest';
|
8
8
|
import { ComponentProps, ComponentSlots } from 'vue-component-type-helpers';
|
9
9
|
|
package/dist/index.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 src_exports={};__export(src_exports,{configure:()=>configure,forceReRender:()=>forceReRender,raw:()=>raw,setup:()=>setup,storiesOf:()=>storiesOf});module.exports=__toCommonJS(src_exports);var import_global=require("@storybook/global"),{window:globalWindow}=import_global.global;globalWindow.STORYBOOK_ENV="vue3";var import_preview_api2=require("@storybook/preview-api");var import_vue=require("vue"),import_preview_api=require("@storybook/preview-api");function normalizeFunctionalComponent(options){return typeof options=="function"?{render:options,name:options.name}:options}function prepare(rawStory,innerStory){let story=rawStory;return story===null?null:typeof story=="function"?story:innerStory?{...normalizeFunctionalComponent(story),components:{...story.components||{},story:innerStory}}:{render(){return(0,import_vue.h)(story)}}}function decorateStory(storyFn,decorators){return decorators.reduce((decorated,decorator)=>context=>{let story,decoratedStory=decorator(update=>{let sanitizedUpdate=(0,import_preview_api.sanitizeStoryContextUpdate)(update);return update&&(sanitizedUpdate.args=Object.assign(context.args,sanitizedUpdate.args)),story=decorated({...context,...sanitizedUpdate}),story},context);return story||(story=decorated(context)),decoratedStory===story?story:prepare(decoratedStory,()=>(0,import_vue.h)(story))},context=>prepare(storyFn(context)))}var import_vue2=require("vue"),render=(props,context)=>{let{id,component:Component}=context;if(!Component)throw new Error(`Unable to render story ${id} as the component annotation is missing from the default export`);return()=>(0,import_vue2.h)(Component,props,generateSlots(context))},setupFunctions=new Set,setup=fn=>{setupFunctions.add(fn)},runSetupFunctions=(app,storyContext)=>{setupFunctions.forEach(fn=>fn(app,storyContext))},map=new Map;function renderToCanvas({storyFn,forceRemount,showMain,showException,storyContext,id},canvasElement){let existingApp=map.get(canvasElement);if(existingApp&&!forceRemount){let element=storyFn(),args=getArgs(element,storyContext);return updateArgs(existingApp.reactiveArgs,args),()=>{teardown(existingApp.vueApp,canvasElement)}}existingApp&&forceRemount&&teardown(existingApp.vueApp,canvasElement);let vueApp=(0,import_vue2.createApp)({setup(){storyContext.args=(0,import_vue2.reactive)(storyContext.args);let rootElement=storyFn(),args=getArgs(rootElement,storyContext),appState={vueApp,reactiveArgs:(0,import_vue2.reactive)(args)};return map.set(canvasElement,appState),()=>(0,import_vue2.h)(rootElement)}});return vueApp.config.errorHandler=e=>showException(e),runSetupFunctions(vueApp,storyContext),vueApp.mount(canvasElement),showMain(),()=>{teardown(vueApp,canvasElement)}}function generateSlots(context){let{argTypes}=context,slots=Object.entries(argTypes).filter(([key,value])=>{var _a2,_b;return((_b=(_a2=argTypes[key])==null?void 0:_a2.table)==null?void 0:_b.category)==="slots"}).map(([key,value])=>{let slotValue=context.args[key];return[key,typeof slotValue=="function"?slotValue:()=>slotValue]});return(0,import_vue2.reactive)(Object.fromEntries(slots))}function getArgs(element,storyContext){return
|
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,{configure:()=>configure,forceReRender:()=>forceReRender,raw:()=>raw,setup:()=>setup,storiesOf:()=>storiesOf});module.exports=__toCommonJS(src_exports);var import_global=require("@storybook/global"),{window:globalWindow}=import_global.global;globalWindow.STORYBOOK_ENV="vue3";var import_preview_api2=require("@storybook/preview-api");var import_vue=require("vue"),import_preview_api=require("@storybook/preview-api");function normalizeFunctionalComponent(options){return typeof options=="function"?{render:options,name:options.name}:options}function prepare(rawStory,innerStory){let story=rawStory;return story===null?null:typeof story=="function"?story:innerStory?{...normalizeFunctionalComponent(story),components:{...story.components||{},story:innerStory}}:{render(){return(0,import_vue.h)(story)}}}function decorateStory(storyFn,decorators){return decorators.reduce((decorated,decorator)=>context=>{let story,decoratedStory=decorator(update=>{let sanitizedUpdate=(0,import_preview_api.sanitizeStoryContextUpdate)(update);return update&&(sanitizedUpdate.args=Object.assign(context.args,sanitizedUpdate.args)),story=decorated({...context,...sanitizedUpdate}),story},context);return story||(story=decorated(context)),decoratedStory===story?story:prepare(decoratedStory,()=>(0,import_vue.h)(story))},context=>prepare(storyFn(context)))}var import_vue2=require("vue"),render=(props,context)=>{let{id,component:Component}=context;if(!Component)throw new Error(`Unable to render story ${id} as the component annotation is missing from the default export`);return()=>(0,import_vue2.h)(Component,props,generateSlots(context))},setupFunctions=new Set,setup=fn=>{setupFunctions.add(fn)},runSetupFunctions=(app,storyContext)=>{setupFunctions.forEach(fn=>fn(app,storyContext))},map=new Map;function renderToCanvas({storyFn,forceRemount,showMain,showException,storyContext,id},canvasElement){let existingApp=map.get(canvasElement);if(existingApp&&!forceRemount){let element=storyFn(),args=getArgs(element,storyContext);return updateArgs(existingApp.reactiveArgs,args),()=>{teardown(existingApp.vueApp,canvasElement)}}existingApp&&forceRemount&&teardown(existingApp.vueApp,canvasElement);let vueApp=(0,import_vue2.createApp)({setup(){storyContext.args=(0,import_vue2.reactive)(storyContext.args);let rootElement=storyFn(),args=getArgs(rootElement,storyContext),appState={vueApp,reactiveArgs:(0,import_vue2.reactive)(args)};return map.set(canvasElement,appState),()=>(0,import_vue2.h)(rootElement)}});return vueApp.config.errorHandler=e=>showException(e),runSetupFunctions(vueApp,storyContext),vueApp.mount(canvasElement),showMain(),()=>{teardown(vueApp,canvasElement)}}function generateSlots(context){let{argTypes}=context,slots=Object.entries(argTypes).filter(([key,value])=>{var _a2,_b;return((_b=(_a2=argTypes[key])==null?void 0:_a2.table)==null?void 0:_b.category)==="slots"}).map(([key,value])=>{let slotValue=context.args[key];return[key,typeof slotValue=="function"?slotValue:()=>slotValue]});return(0,import_vue2.reactive)(Object.fromEntries(slots))}function getArgs(element,storyContext){return element.props&&(0,import_vue2.isVNode)(element)?element.props:storyContext.args}function updateArgs(reactiveArgs,nextArgs){if(Object.keys(nextArgs).length===0)return;let currentArgs=(0,import_vue2.isReactive)(reactiveArgs)?reactiveArgs:(0,import_vue2.reactive)(reactiveArgs);Object.keys(currentArgs).forEach(key=>{key in nextArgs||delete currentArgs[key]}),Object.assign(currentArgs,nextArgs)}function teardown(storybookApp,canvasElement){storybookApp==null||storybookApp.unmount(),map.has(canvasElement)&&map.delete(canvasElement)}var RENDERER="vue3",api=(0,import_preview_api2.start)(renderToCanvas,{decorateStory,render}),storiesOf=(kind,m)=>api.clientApi.storiesOf(kind,m).addParameters({renderer:RENDERER}),configure=(...args)=>api.configure(RENDERER,...args),{forceReRender}=api,{raw}=api.clientApi;var _a;typeof module<"u"&&((_a=module==null?void 0:module.hot)==null||_a.decline());0&&(module.exports={configure,forceReRender,raw,setup,storiesOf});
|
package/dist/index.mjs
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { renderToCanvas, decorateStory, render } from './chunk-
|
2
|
-
export { setup } from './chunk-
|
1
|
+
import { renderToCanvas, decorateStory, render } from './chunk-SRVBJOBI.mjs';
|
2
|
+
export { setup } from './chunk-SRVBJOBI.mjs';
|
3
3
|
import { global } from '@storybook/global';
|
4
4
|
import { start } from '@storybook/preview-api';
|
5
5
|
|
@@ -1,9 +1,9 @@
|
|
1
|
-
import {
|
1
|
+
import { ConcreteComponent, App } from 'vue';
|
2
2
|
import { WebRenderer, ArgsStoryFn as ArgsStoryFn$1, RenderContext } from '@storybook/types';
|
3
3
|
|
4
|
-
type StoryFnVueReturnType =
|
4
|
+
type StoryFnVueReturnType = ConcreteComponent<any>;
|
5
5
|
interface VueRenderer extends WebRenderer {
|
6
|
-
component:
|
6
|
+
component: Omit<ConcreteComponent<this['T']>, 'props'>;
|
7
7
|
storyResult: StoryFnVueReturnType;
|
8
8
|
}
|
9
9
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@storybook/vue3",
|
3
|
-
"version": "7.2.0
|
3
|
+
"version": "7.2.0",
|
4
4
|
"description": "Storybook Vue 3 renderer",
|
5
5
|
"keywords": [
|
6
6
|
"storybook"
|
@@ -48,35 +48,28 @@
|
|
48
48
|
"prep": "../../../scripts/prepare/bundle.ts"
|
49
49
|
},
|
50
50
|
"dependencies": {
|
51
|
-
"@storybook/core-client": "7.2.0
|
52
|
-
"@storybook/docs-tools": "7.2.0
|
51
|
+
"@storybook/core-client": "7.2.0",
|
52
|
+
"@storybook/docs-tools": "7.2.0",
|
53
53
|
"@storybook/global": "^5.0.0",
|
54
|
-
"@storybook/preview-api": "7.2.0
|
55
|
-
"@storybook/types": "7.2.0
|
54
|
+
"@storybook/preview-api": "7.2.0",
|
55
|
+
"@storybook/types": "7.2.0",
|
56
56
|
"lodash": "^4.17.21",
|
57
57
|
"ts-dedent": "^2.0.0",
|
58
58
|
"type-fest": "~2.19",
|
59
|
-
"vue": "3.3.4",
|
60
59
|
"vue-component-type-helpers": "latest"
|
61
60
|
},
|
62
61
|
"devDependencies": {
|
63
62
|
"@digitak/esrun": "^3.2.2",
|
64
63
|
"@types/prettier": "2.7.2",
|
64
|
+
"@vue/compiler-core": "^3.3.4",
|
65
65
|
"@vue/vue3-jest": "29",
|
66
66
|
"typescript": "~4.9.3",
|
67
|
+
"vue": "^3.2.47",
|
67
68
|
"vue-tsc": "latest"
|
68
69
|
},
|
69
70
|
"peerDependencies": {
|
70
|
-
"@vue/compiler-core": "^3.
|
71
|
-
"vue": "^3.
|
72
|
-
},
|
73
|
-
"peerDependenciesMeta": {
|
74
|
-
"@vue/compiler-core": {
|
75
|
-
"optional": true
|
76
|
-
},
|
77
|
-
"vue": {
|
78
|
-
"optional": true
|
79
|
-
}
|
71
|
+
"@vue/compiler-core": "^3.0.0",
|
72
|
+
"vue": "^3.0.0"
|
80
73
|
},
|
81
74
|
"engines": {
|
82
75
|
"node": ">=16.0.0"
|
@@ -5,7 +5,6 @@ import { expect } from '@storybook/jest';
|
|
5
5
|
import type { Meta, StoryObj } from '@storybook/vue3';
|
6
6
|
import { within } from '@storybook/testing-library';
|
7
7
|
import { inject } from 'vue';
|
8
|
-
import type { PlayFunctionContext } from '@storybook/csf';
|
9
8
|
import GlobalSetup from './GlobalSetup.vue';
|
10
9
|
|
11
10
|
const meta: Meta = {
|
@@ -32,7 +31,7 @@ export const Primary: Story = {
|
|
32
31
|
primary: true,
|
33
32
|
label: 'someColor injected from .storybook/preview.ts',
|
34
33
|
},
|
35
|
-
play: async ({ canvasElement, id }
|
34
|
+
play: async ({ canvasElement, id }) => {
|
36
35
|
const canvas = within(canvasElement);
|
37
36
|
|
38
37
|
const button = await canvas.getByRole('button');
|
@@ -1,14 +1,11 @@
|
|
1
1
|
import { expect } from '@storybook/jest';
|
2
|
-
import { global } from '@storybook/global';
|
2
|
+
import { global as globalThis } from '@storybook/global';
|
3
3
|
import type { Meta, StoryObj, StoryFn } from '@storybook/vue3';
|
4
4
|
import { within, userEvent } from '@storybook/testing-library';
|
5
5
|
import { UPDATE_STORY_ARGS, STORY_ARGS_UPDATED, RESET_STORY_ARGS } from '@storybook/core-events';
|
6
6
|
|
7
|
-
import type { PlayFunctionContext } from '@storybook/csf';
|
8
7
|
import ReactiveArgs from './ReactiveArgs.vue';
|
9
8
|
|
10
|
-
const globalThis = global as any;
|
11
|
-
|
12
9
|
const meta = {
|
13
10
|
component: ReactiveArgs,
|
14
11
|
argTypes: {
|
@@ -26,7 +23,7 @@ export const ReactiveTest: Story = {
|
|
26
23
|
label: 'Button',
|
27
24
|
},
|
28
25
|
// test that args are updated correctly in rective mode
|
29
|
-
play: async ({ canvasElement, id }
|
26
|
+
play: async ({ canvasElement, id }) => {
|
30
27
|
const channel = globalThis.__STORYBOOK_ADDONS_CHANNEL__;
|
31
28
|
const canvas = within(canvasElement);
|
32
29
|
|
@@ -114,7 +111,7 @@ ReactiveCSF2Wrapper.decorators = [
|
|
114
111
|
}),
|
115
112
|
];
|
116
113
|
|
117
|
-
ReactiveCSF2Wrapper.play = async ({ canvasElement, id }
|
114
|
+
ReactiveCSF2Wrapper.play = async ({ canvasElement, id }) => {
|
118
115
|
const channel = globalThis.__STORYBOOK_ADDONS_CHANNEL__;
|
119
116
|
const canvas = within(canvasElement);
|
120
117
|
|
@@ -3,8 +3,6 @@ import { userEvent, within } from '@storybook/testing-library';
|
|
3
3
|
import type { Meta, StoryObj } from '@storybook/vue3';
|
4
4
|
import { h } from 'vue';
|
5
5
|
import { RESET_STORY_ARGS, STORY_ARGS_UPDATED, UPDATE_STORY_ARGS } from '@storybook/core-events';
|
6
|
-
import type { PlayFunctionContext } from '@storybook/csf';
|
7
|
-
|
8
6
|
import Reactivity from './Reactivity.vue';
|
9
7
|
|
10
8
|
const meta = {
|
@@ -20,7 +18,7 @@ const meta = {
|
|
20
18
|
header: 'If you see this, the header slot was not reactive.', // this can be useless if you have custom render function that overrides the slot
|
21
19
|
footer: 'If you see this, the footer slot was not reactive.',
|
22
20
|
},
|
23
|
-
play: async ({ canvasElement, id, args }
|
21
|
+
play: async ({ canvasElement, id, args }) => {
|
24
22
|
const channel = (globalThis as any).__STORYBOOK_ADDONS_CHANNEL__;
|
25
23
|
|
26
24
|
const canvas = within(canvasElement);
|
@@ -51,7 +49,7 @@ export const NoDecorators: Story = {};
|
|
51
49
|
|
52
50
|
export const DecoratorFunctionalComponent: Story = {
|
53
51
|
decorators: [
|
54
|
-
(storyFn
|
52
|
+
(storyFn, context) => {
|
55
53
|
const story = storyFn();
|
56
54
|
return () => h('div', [h('h2', ['Decorator not using args']), [h(story)]]);
|
57
55
|
},
|
@@ -70,7 +68,7 @@ export const DecoratorFunctionalComponentArgsFromContext: Story = {
|
|
70
68
|
|
71
69
|
export const DecoratorComponentOptions: Story = {
|
72
70
|
decorators: [
|
73
|
-
(storyFn
|
71
|
+
(storyFn, context) => {
|
74
72
|
return {
|
75
73
|
template: '<div><h2>Decorator not using args</h2><story/></div>',
|
76
74
|
};
|
@@ -1,14 +1,11 @@
|
|
1
1
|
import { expect } from '@storybook/jest';
|
2
|
-
import { global } from '@storybook/global';
|
2
|
+
import { global as globalThis } from '@storybook/global';
|
3
3
|
import { within } from '@storybook/testing-library';
|
4
4
|
import { STORY_ARGS_UPDATED, RESET_STORY_ARGS, UPDATE_STORY_ARGS } from '@storybook/core-events';
|
5
5
|
import { h } from 'vue';
|
6
6
|
import type { Meta, StoryObj } from '@storybook/vue3';
|
7
|
-
import type { PlayFunctionContext } from '@storybook/csf';
|
8
7
|
import BaseLayout from './BaseLayout.vue';
|
9
8
|
|
10
|
-
const globalThis = global as any;
|
11
|
-
|
12
9
|
const meta = {
|
13
10
|
component: BaseLayout,
|
14
11
|
args: {
|
@@ -29,7 +26,7 @@ export const SimpleSlotTest: Story = {
|
|
29
26
|
default: () => 'Default Text Slot',
|
30
27
|
footer: h('p', 'Footer VNode Slot'),
|
31
28
|
},
|
32
|
-
play: async ({ canvasElement, id }
|
29
|
+
play: async ({ canvasElement, id }) => {
|
33
30
|
const channel = globalThis.__STORYBOOK_ADDONS_CHANNEL__;
|
34
31
|
const canvas = within(canvasElement);
|
35
32
|
|
@@ -67,7 +64,7 @@ export const NamedSlotTest: Story = {
|
|
67
64
|
footer: h('p', 'Footer VNode Slot'),
|
68
65
|
},
|
69
66
|
// test that args are updated correctly in rective mode
|
70
|
-
play: async ({ canvasElement, id }
|
67
|
+
play: async ({ canvasElement, id }) => {
|
71
68
|
const channel = globalThis.__STORYBOOK_ADDONS_CHANNEL__;
|
72
69
|
const canvas = within(canvasElement);
|
73
70
|
|
@@ -107,7 +104,7 @@ export const SlotWithRenderFn: Story = {
|
|
107
104
|
default: () => 'Default Text Slot',
|
108
105
|
footer: h('p', 'Footer VNode Slot'),
|
109
106
|
},
|
110
|
-
render: (args
|
107
|
+
render: (args) => ({
|
111
108
|
components: { BaseLayout },
|
112
109
|
setup() {
|
113
110
|
return { args };
|
@@ -117,7 +114,7 @@ export const SlotWithRenderFn: Story = {
|
|
117
114
|
<template #header="{ title }"><h1>{{args.header({title})}}</h1></template>
|
118
115
|
</BaseLayout>`,
|
119
116
|
}),
|
120
|
-
play: async ({ canvasElement, id }
|
117
|
+
play: async ({ canvasElement, id }) => {
|
121
118
|
const channel = globalThis.__STORYBOOK_ADDONS_CHANNEL__;
|
122
119
|
const canvas = within(canvasElement);
|
123
120
|
|
@@ -1,12 +1,16 @@
|
|
1
1
|
import { expect } from '@storybook/jest';
|
2
|
+
import { global as globalThis } from '@storybook/global';
|
3
|
+
import type { Channel } from '@storybook/channels';
|
2
4
|
import { within } from '@storybook/testing-library';
|
3
5
|
import { UPDATE_STORY_ARGS, STORY_ARGS_UPDATED, RESET_STORY_ARGS } from '@storybook/core-events';
|
4
6
|
|
5
7
|
import type { Meta, StoryObj } from '@storybook/vue3';
|
6
|
-
import type { PlayFunctionContext } from '@storybook/csf';
|
7
8
|
import MySlotComponent from './MySlotComponent.vue';
|
8
9
|
|
9
|
-
|
10
|
+
declare global {
|
11
|
+
// eslint-disable-next-line no-var,vars-on-top,@typescript-eslint/naming-convention
|
12
|
+
var __STORYBOOK_ADDONS_CHANNEL__: Channel;
|
13
|
+
}
|
10
14
|
|
11
15
|
const meta = {
|
12
16
|
component: MySlotComponent,
|
@@ -23,7 +27,7 @@ type Story = StoryObj<typeof meta>;
|
|
23
27
|
|
24
28
|
export const Basic: Story = {
|
25
29
|
// test that args are updated correctly in reactive mode
|
26
|
-
play: async ({ canvasElement, id }
|
30
|
+
play: async ({ canvasElement, id }) => {
|
27
31
|
const channel = globalThis.__STORYBOOK_ADDONS_CHANNEL__;
|
28
32
|
const canvas = within(canvasElement);
|
29
33
|
|
@@ -1,19 +0,0 @@
|
|
1
|
-
import type { StoryObj, Meta } from '@storybook/vue3';
|
2
|
-
|
3
|
-
import Component from './options-api/component';
|
4
|
-
|
5
|
-
const meta = {
|
6
|
-
component: Component,
|
7
|
-
tags: ['autodocs'],
|
8
|
-
} satisfies Meta<typeof Component>;
|
9
|
-
type Story = StoryObj<typeof meta>;
|
10
|
-
export default meta;
|
11
|
-
|
12
|
-
export const Default: Story = {
|
13
|
-
args: {
|
14
|
-
numberDefault: 12,
|
15
|
-
objectDefault: { bar: 'foo' },
|
16
|
-
arrayDefault: [1, 2, 3],
|
17
|
-
complexDefault: [1, 2, 3, 4, 5],
|
18
|
-
},
|
19
|
-
};
|
@@ -1,11 +0,0 @@
|
|
1
|
-
import type { StoryObj, Meta } from '@storybook/vue3';
|
2
|
-
import Component from './reference-type-events/component.vue';
|
3
|
-
|
4
|
-
const meta = {
|
5
|
-
component: Component,
|
6
|
-
tags: ['autodocs'],
|
7
|
-
} satisfies Meta<typeof Component>;
|
8
|
-
type Story = StoryObj<typeof meta>;
|
9
|
-
export default meta;
|
10
|
-
|
11
|
-
export const ReferenceTypeEvents: Story = {};
|
package/template/stories_vue3-vite-default-ts/component-meta/ReferenceTypeExposed.stories.ts
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
import type { StoryObj, Meta } from '@storybook/vue3';
|
2
|
-
import Component from './reference-type-exposed/component.vue';
|
3
|
-
|
4
|
-
const meta = {
|
5
|
-
component: Component,
|
6
|
-
tags: ['autodocs'],
|
7
|
-
} satisfies Meta<typeof Component>;
|
8
|
-
type Story = StoryObj<typeof meta>;
|
9
|
-
export default meta;
|
10
|
-
|
11
|
-
export const ReferenceTypeExposed: Story = {};
|
@@ -1,31 +0,0 @@
|
|
1
|
-
import type { StoryObj, Meta } from '@storybook/vue3';
|
2
|
-
import Component from './reference-type-props/component.vue';
|
3
|
-
|
4
|
-
const meta = {
|
5
|
-
component: Component,
|
6
|
-
tags: ['autodocs'],
|
7
|
-
} satisfies Meta<typeof Component>;
|
8
|
-
type Story = StoryObj<typeof meta>;
|
9
|
-
export default meta;
|
10
|
-
enum MyEnum {
|
11
|
-
Small,
|
12
|
-
Medium,
|
13
|
-
Large,
|
14
|
-
}
|
15
|
-
|
16
|
-
export const ReferenceTypeProps: Story = {
|
17
|
-
args: {
|
18
|
-
foo: 'Foo',
|
19
|
-
baz: true,
|
20
|
-
stringArray: ['Foo', 'Bar', 'Baz'],
|
21
|
-
bar: 1,
|
22
|
-
unionOptional: 'Foo',
|
23
|
-
union: 'Foo',
|
24
|
-
inlined: { foo: 'Foo' },
|
25
|
-
nested: { nestedProp: 'Nested Prop' },
|
26
|
-
nestedIntersection: { nestedProp: 'Nested Prop', additionalProp: 'Additional Prop' },
|
27
|
-
array: [{ nestedProp: 'Nested Prop' }],
|
28
|
-
literalFromContext: 'Uncategorized',
|
29
|
-
enumValue: MyEnum.Small,
|
30
|
-
},
|
31
|
-
};
|
@@ -1,18 +0,0 @@
|
|
1
|
-
import type { StoryObj, Meta } from '@storybook/vue3';
|
2
|
-
|
3
|
-
import Component from './template-slots/component.vue';
|
4
|
-
|
5
|
-
const meta = {
|
6
|
-
component: Component,
|
7
|
-
tags: ['autodocs'],
|
8
|
-
} satisfies Meta<typeof Component>;
|
9
|
-
type Story = StoryObj<typeof meta>;
|
10
|
-
export default meta;
|
11
|
-
|
12
|
-
export const Default: Story = {
|
13
|
-
args: {
|
14
|
-
default: ({ num }) => `Default slot { num=${num} }`,
|
15
|
-
named: ({ str }) => `Named slot { str=${str} }`,
|
16
|
-
vbind: ({ num, str }) => `Named v-bind slot { num=${num}, str=${str} }`,
|
17
|
-
},
|
18
|
-
};
|
@@ -1,12 +0,0 @@
|
|
1
|
-
import type { StoryObj, Meta } from '@storybook/vue3';
|
2
|
-
|
3
|
-
import Component from './ts-component/component';
|
4
|
-
|
5
|
-
const meta = {
|
6
|
-
component: Component,
|
7
|
-
tags: ['autodocs'],
|
8
|
-
} satisfies Meta<typeof Component>;
|
9
|
-
type Story = StoryObj<typeof meta>;
|
10
|
-
export default meta;
|
11
|
-
|
12
|
-
export const Default: Story = { args: { foo: 'bar', bar: 20 } };
|
@@ -1,12 +0,0 @@
|
|
1
|
-
import type { StoryObj, Meta } from '@storybook/vue3';
|
2
|
-
|
3
|
-
import { ComponentA } from './ts-named-export/component';
|
4
|
-
|
5
|
-
const meta = {
|
6
|
-
component: ComponentA,
|
7
|
-
tags: ['autodocs'],
|
8
|
-
} satisfies Meta<typeof ComponentA>;
|
9
|
-
type Story = StoryObj<typeof meta>;
|
10
|
-
export default meta;
|
11
|
-
|
12
|
-
export const Default: Story = { args: { size: 'large', backgroundColor: 'blue' } };
|
@@ -1,65 +0,0 @@
|
|
1
|
-
import { defineComponent, h } from 'vue';
|
2
|
-
|
3
|
-
interface SubmitPayload {
|
4
|
-
/**
|
5
|
-
* email of user
|
6
|
-
*/
|
7
|
-
email: string;
|
8
|
-
/**
|
9
|
-
* password of same user
|
10
|
-
*/
|
11
|
-
password: string;
|
12
|
-
}
|
13
|
-
|
14
|
-
export default defineComponent({
|
15
|
-
emits: {
|
16
|
-
// Validate submit event
|
17
|
-
submit: ({ email, password }: SubmitPayload) => {
|
18
|
-
if (email && password) {
|
19
|
-
return true;
|
20
|
-
}
|
21
|
-
|
22
|
-
return false;
|
23
|
-
},
|
24
|
-
},
|
25
|
-
props: {
|
26
|
-
/**
|
27
|
-
* Number prop with default
|
28
|
-
*/
|
29
|
-
numberDefault: {
|
30
|
-
type: Number,
|
31
|
-
default: 42,
|
32
|
-
},
|
33
|
-
/**
|
34
|
-
* Object prop with default
|
35
|
-
*/
|
36
|
-
objectDefault: {
|
37
|
-
type: Object,
|
38
|
-
default: () => ({
|
39
|
-
foo: 'bar',
|
40
|
-
}),
|
41
|
-
},
|
42
|
-
/**
|
43
|
-
* Array prop with default
|
44
|
-
*/
|
45
|
-
arrayDefault: {
|
46
|
-
type: Array,
|
47
|
-
default: () => [1, 2, 3],
|
48
|
-
},
|
49
|
-
/**
|
50
|
-
* Default function more complex
|
51
|
-
*/
|
52
|
-
complexDefault: {
|
53
|
-
type: Array,
|
54
|
-
default: (props: any) => {
|
55
|
-
if (props.arrayDefault.length > props.numberDefault) {
|
56
|
-
return [];
|
57
|
-
}
|
58
|
-
return undefined;
|
59
|
-
},
|
60
|
-
},
|
61
|
-
},
|
62
|
-
render() {
|
63
|
-
return h('pre', JSON.stringify(this.$props, null, 2));
|
64
|
-
},
|
65
|
-
});
|
package/template/stories_vue3-vite-default-ts/component-meta/reference-type-events/component.vue
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
<script setup lang="ts">
|
2
|
-
|
3
|
-
/**
|
4
|
-
* Emitted when the foo property is changed.
|
5
|
-
*/
|
6
|
-
type MyEventsFoo = /** Emitted when the foo property is changed. */ 'foo';
|
7
|
-
interface MyEvents {
|
8
|
-
(event: MyEventsFoo, data?: { foo: string }): void;
|
9
|
-
(event: 'bar', value: { year: number; title?: any }): void;
|
10
|
-
(e: 'baz'): void;
|
11
|
-
}
|
12
|
-
|
13
|
-
const emit = defineEmits<MyEvents>();
|
14
|
-
</script>
|
15
|
-
<template>
|
16
|
-
<div>
|
17
|
-
foo:
|
18
|
-
<button @click="emit('bar', { year: 2023, title: 'Storybook' })">
|
19
|
-
event: 'bar', value: {year: 2023, title:'Storybook' }
|
20
|
-
</button>
|
21
|
-
</div>
|
22
|
-
<div>bar:
|
23
|
-
<button @click="emit('baz')">event: 'baz'</button>
|
24
|
-
</div>
|
25
|
-
<div>foo:
|
26
|
-
<button @click="emit('foo', { foo: 'foo' })">
|
27
|
-
event: 'foo', data: {foo: 'foo'}
|
28
|
-
</button>
|
29
|
-
</div>
|
30
|
-
</template>
|
package/template/stories_vue3-vite-default-ts/component-meta/reference-type-exposed/component.vue
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
<template>
|
2
|
-
<Pre>{{ JSON.stringify({ label, count }, null, 2) }} </Pre>
|
3
|
-
</template>
|
4
|
-
<script setup lang="ts">
|
5
|
-
|
6
|
-
import { ref } from 'vue';
|
7
|
-
|
8
|
-
const label = ref('Button')
|
9
|
-
const count = ref(100)
|
10
|
-
|
11
|
-
defineExpose({
|
12
|
-
/**
|
13
|
-
* a label string
|
14
|
-
*/
|
15
|
-
label,
|
16
|
-
/**
|
17
|
-
* a count number
|
18
|
-
*/
|
19
|
-
count
|
20
|
-
});
|
21
|
-
|
22
|
-
</script>
|
@@ -1,58 +0,0 @@
|
|
1
|
-
<script lang="ts" setup>
|
2
|
-
import { StringEmpty, StringRequired, StringUndefined } from './my-props';
|
3
|
-
|
4
|
-
defineProps({
|
5
|
-
/**
|
6
|
-
* The foo property is required.
|
7
|
-
* @since v1.0.0
|
8
|
-
* @deprecated v1.1.0
|
9
|
-
* @description This is a description of the foo property.
|
10
|
-
*/
|
11
|
-
foo: {
|
12
|
-
type: String,
|
13
|
-
required: true
|
14
|
-
},
|
15
|
-
/**
|
16
|
-
* The bar property has default value
|
17
|
-
*/
|
18
|
-
bar: {
|
19
|
-
type: String,
|
20
|
-
default: 'BAR'
|
21
|
-
},
|
22
|
-
/**
|
23
|
-
* The baz property is optional.
|
24
|
-
*/
|
25
|
-
baz: {
|
26
|
-
type: String
|
27
|
-
},
|
28
|
-
/**
|
29
|
-
* The xfoo property is required.
|
30
|
-
*/
|
31
|
-
xfoo: StringRequired,
|
32
|
-
/**
|
33
|
-
* The xbar property is empty.
|
34
|
-
*/
|
35
|
-
xbar: StringEmpty,
|
36
|
-
/**
|
37
|
-
* The xbaz property is undefined.
|
38
|
-
*/
|
39
|
-
xbaz: StringUndefined,
|
40
|
-
/**
|
41
|
-
* The hello property.
|
42
|
-
*
|
43
|
-
* @since v1.0.0
|
44
|
-
*/
|
45
|
-
hello: {
|
46
|
-
type: String,
|
47
|
-
default: 'Hello'
|
48
|
-
},
|
49
|
-
numberOrStringProp: {
|
50
|
-
type: [Number, String],
|
51
|
-
default: 42
|
52
|
-
},
|
53
|
-
arrayProps: {
|
54
|
-
type: Array,
|
55
|
-
default: () => [42, 43, 44]
|
56
|
-
}
|
57
|
-
})
|
58
|
-
</script>
|
package/template/stories_vue3-vite-default-ts/component-meta/reference-type-props/component-js.vue
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
<script lang="ts">
|
2
|
-
import { defineComponent } from 'vue'
|
3
|
-
import { StringEmpty, StringRequired, StringUndefined } from './my-props';
|
4
|
-
|
5
|
-
export default defineComponent({
|
6
|
-
props: {
|
7
|
-
/**
|
8
|
-
* foo description, required prop
|
9
|
-
* @required
|
10
|
-
*/
|
11
|
-
foo: {
|
12
|
-
type: String,
|
13
|
-
required: true
|
14
|
-
},
|
15
|
-
/**
|
16
|
-
* bar description, default value BAR
|
17
|
-
*/
|
18
|
-
bar: {
|
19
|
-
type: String,
|
20
|
-
default: 'BAR',
|
21
|
-
},
|
22
|
-
/**
|
23
|
-
* baz description, optional prop
|
24
|
-
*/
|
25
|
-
baz: {
|
26
|
-
type: String
|
27
|
-
},
|
28
|
-
/**
|
29
|
-
* xfoo description, required string prop
|
30
|
-
*/
|
31
|
-
xfoo: StringRequired,
|
32
|
-
/**
|
33
|
-
* xbar description, empty string prop
|
34
|
-
*/
|
35
|
-
xbar: StringEmpty,
|
36
|
-
xbaz: StringUndefined,
|
37
|
-
}
|
38
|
-
})
|
39
|
-
</script>
|
40
|
-
<template>
|
41
|
-
<pre> {{ $props }}</pre>
|
42
|
-
</template>
|
package/template/stories_vue3-vite-default-ts/component-meta/reference-type-props/component.vue
DELETED
@@ -1,109 +0,0 @@
|
|
1
|
-
<script setup lang="ts">
|
2
|
-
export interface MyNestedProps {
|
3
|
-
/**
|
4
|
-
* nested prop documentation
|
5
|
-
*/
|
6
|
-
nestedProp: string;
|
7
|
-
}
|
8
|
-
|
9
|
-
interface MyIgnoredNestedProps {
|
10
|
-
nestedProp: string;
|
11
|
-
}
|
12
|
-
|
13
|
-
interface MyNestedRecursiveProps {
|
14
|
-
recursive: MyNestedRecursiveProps
|
15
|
-
}
|
16
|
-
|
17
|
-
enum MyEnum {
|
18
|
-
Small,
|
19
|
-
Medium,
|
20
|
-
Large,
|
21
|
-
}
|
22
|
-
|
23
|
-
const categories = [
|
24
|
-
'Uncategorized',
|
25
|
-
'Content',
|
26
|
-
'Interaction',
|
27
|
-
'Display',
|
28
|
-
'Forms',
|
29
|
-
'Addons',
|
30
|
-
] as const;
|
31
|
-
|
32
|
-
type MyCategories = typeof categories[number];
|
33
|
-
|
34
|
-
interface MyProps {
|
35
|
-
/**
|
36
|
-
* string foo
|
37
|
-
*
|
38
|
-
* @default "rounded"
|
39
|
-
* @since v1.0.0
|
40
|
-
* @see https://vuejs.org/
|
41
|
-
* @deprecated v1.1.0
|
42
|
-
*/
|
43
|
-
foo: string,
|
44
|
-
/**
|
45
|
-
* description bar is optional number
|
46
|
-
*/
|
47
|
-
bar?: number,
|
48
|
-
/**
|
49
|
-
* description baz is required boolean
|
50
|
-
*/
|
51
|
-
baz: boolean,
|
52
|
-
/**
|
53
|
-
* description stringArray is string array
|
54
|
-
*/
|
55
|
-
stringArray?: string[],
|
56
|
-
/**
|
57
|
-
* description union is required union type
|
58
|
-
*/
|
59
|
-
union: string | number,
|
60
|
-
/**
|
61
|
-
* description unionOptional is optional union type
|
62
|
-
*/
|
63
|
-
unionOptional?: string | number | boolean,
|
64
|
-
/**
|
65
|
-
* description nested is required nested object
|
66
|
-
*/
|
67
|
-
nested: MyNestedProps,
|
68
|
-
/**
|
69
|
-
* description required nested object with intersection
|
70
|
-
*/
|
71
|
-
nestedIntersection: MyNestedProps & {
|
72
|
-
/**
|
73
|
-
* description required additional property
|
74
|
-
*/
|
75
|
-
additionalProp: string;
|
76
|
-
},
|
77
|
-
/**
|
78
|
-
* description optional nested object
|
79
|
-
*/
|
80
|
-
nestedOptional?: MyNestedProps | MyIgnoredNestedProps,
|
81
|
-
/**
|
82
|
-
* description required array object
|
83
|
-
*/
|
84
|
-
array: MyNestedProps[],
|
85
|
-
/**
|
86
|
-
* description optional array object
|
87
|
-
*/
|
88
|
-
arrayOptional?: MyNestedProps[],
|
89
|
-
/**
|
90
|
-
* description enum value
|
91
|
-
*/
|
92
|
-
enumValue: MyEnum,
|
93
|
-
/**
|
94
|
-
* description literal type alias that require context
|
95
|
-
*/
|
96
|
-
literalFromContext: MyCategories,
|
97
|
-
inlined: { foo: string; },
|
98
|
-
recursive?: MyNestedRecursiveProps
|
99
|
-
}
|
100
|
-
|
101
|
-
|
102
|
-
withDefaults(defineProps<MyProps>(), {
|
103
|
-
bar: 1,
|
104
|
-
stringArray: () => ['foo', 'bar'],
|
105
|
-
});
|
106
|
-
</script>
|
107
|
-
<template>
|
108
|
-
<pre>{{ JSON.stringify($props, null, 2) }}</pre>
|
109
|
-
</template>
|
package/template/stories_vue3-vite-default-ts/component-meta/reference-type-props/my-props.ts
DELETED
@@ -1,113 +0,0 @@
|
|
1
|
-
export interface MyNestedProps {
|
2
|
-
/**
|
3
|
-
* nested prop documentation
|
4
|
-
*/
|
5
|
-
nestedProp: string;
|
6
|
-
}
|
7
|
-
|
8
|
-
export interface MyIgnoredNestedProps {
|
9
|
-
nestedProp: string;
|
10
|
-
}
|
11
|
-
|
12
|
-
export interface MyNestedRecursiveProps {
|
13
|
-
recursive: MyNestedRecursiveProps;
|
14
|
-
}
|
15
|
-
|
16
|
-
enum MyEnum {
|
17
|
-
Small,
|
18
|
-
Medium,
|
19
|
-
Large,
|
20
|
-
}
|
21
|
-
|
22
|
-
const categories = [
|
23
|
-
'Uncategorized',
|
24
|
-
'Content',
|
25
|
-
'Interaction',
|
26
|
-
'Display',
|
27
|
-
'Forms',
|
28
|
-
'Addons',
|
29
|
-
] as const;
|
30
|
-
|
31
|
-
type MyCategories = typeof categories[number];
|
32
|
-
|
33
|
-
export interface MyProps {
|
34
|
-
/**
|
35
|
-
* string foo
|
36
|
-
*
|
37
|
-
* @default "rounded"
|
38
|
-
* @since v1.0.0
|
39
|
-
* @see https://vuejs.org/
|
40
|
-
* @example
|
41
|
-
* ```vue
|
42
|
-
* <template>
|
43
|
-
* <component foo="straight" />
|
44
|
-
* </template>
|
45
|
-
* ```
|
46
|
-
*/
|
47
|
-
foo: string;
|
48
|
-
/**
|
49
|
-
* optional number bar
|
50
|
-
*/
|
51
|
-
bar?: number;
|
52
|
-
/**
|
53
|
-
* string array baz
|
54
|
-
*/
|
55
|
-
baz?: string[];
|
56
|
-
/**
|
57
|
-
* required union type
|
58
|
-
*/
|
59
|
-
union: string | number;
|
60
|
-
/**
|
61
|
-
* optional union type
|
62
|
-
*/
|
63
|
-
unionOptional?: string | number;
|
64
|
-
/**
|
65
|
-
* required nested object
|
66
|
-
*/
|
67
|
-
nested: MyNestedProps;
|
68
|
-
/**
|
69
|
-
* required nested object with intersection
|
70
|
-
*/
|
71
|
-
nestedIntersection: MyNestedProps & {
|
72
|
-
/**
|
73
|
-
* required additional property
|
74
|
-
*/
|
75
|
-
additionalProp: string;
|
76
|
-
};
|
77
|
-
/**
|
78
|
-
* optional nested object
|
79
|
-
*/
|
80
|
-
nestedOptional?: MyNestedProps | MyIgnoredNestedProps;
|
81
|
-
/**
|
82
|
-
* required array object
|
83
|
-
*/
|
84
|
-
array: MyNestedProps[];
|
85
|
-
/**
|
86
|
-
* optional array object
|
87
|
-
*/
|
88
|
-
arrayOptional?: MyNestedProps[];
|
89
|
-
/**
|
90
|
-
* enum value
|
91
|
-
*/
|
92
|
-
enumValue: MyEnum;
|
93
|
-
/**
|
94
|
-
* literal type alias that require context
|
95
|
-
*/
|
96
|
-
literalFromContext: MyCategories;
|
97
|
-
inlined: { foo: string };
|
98
|
-
recursive: MyNestedRecursiveProps;
|
99
|
-
}
|
100
|
-
|
101
|
-
export const StringRequired = {
|
102
|
-
type: String,
|
103
|
-
required: true,
|
104
|
-
} as const;
|
105
|
-
|
106
|
-
export const StringEmpty = {
|
107
|
-
type: String,
|
108
|
-
value: '',
|
109
|
-
} as const;
|
110
|
-
|
111
|
-
export const StringUndefined = {
|
112
|
-
type: String,
|
113
|
-
} as const;
|
@@ -1,17 +0,0 @@
|
|
1
|
-
import { h, defineComponent } from 'vue';
|
2
|
-
// import type { MyProps } from './PropDefinitions'; this works on vue@3.3.0
|
3
|
-
|
4
|
-
interface MyProps {
|
5
|
-
/**
|
6
|
-
* string foo
|
7
|
-
*/
|
8
|
-
foo: string;
|
9
|
-
/**
|
10
|
-
* optional number bar
|
11
|
-
*/
|
12
|
-
bar?: number;
|
13
|
-
}
|
14
|
-
|
15
|
-
export default defineComponent((props: MyProps) => () => h('Pre', `${JSON.stringify(props)}`), {
|
16
|
-
props: ['foo', 'bar'],
|
17
|
-
});
|
@@ -1,52 +0,0 @@
|
|
1
|
-
import type { PropType } from 'vue';
|
2
|
-
import { defineComponent, h } from 'vue';
|
3
|
-
|
4
|
-
export const ComponentA = defineComponent({
|
5
|
-
name: 'MyCompo1',
|
6
|
-
props: {
|
7
|
-
/**
|
8
|
-
* This is a description of the prop
|
9
|
-
* @values 'small', 'medium', 'large'
|
10
|
-
* @defaultValue 'medium'
|
11
|
-
* @control select
|
12
|
-
* @group Size
|
13
|
-
* */
|
14
|
-
size: {
|
15
|
-
type: String as PropType<'small' | 'medium' | 'large'>,
|
16
|
-
default: 'medium',
|
17
|
-
},
|
18
|
-
/**
|
19
|
-
* This is a description of the prop
|
20
|
-
* @defaultValue false
|
21
|
-
* @control color
|
22
|
-
* @group Style
|
23
|
-
* */
|
24
|
-
backgroundColor: {
|
25
|
-
type: String,
|
26
|
-
default: 'red',
|
27
|
-
},
|
28
|
-
},
|
29
|
-
setup(props: any) {
|
30
|
-
return () => h('pre', JSON.stringify(props, null, 2));
|
31
|
-
},
|
32
|
-
});
|
33
|
-
|
34
|
-
export const ComponentB = defineComponent({
|
35
|
-
name: 'MyCompo2',
|
36
|
-
props: {
|
37
|
-
/**
|
38
|
-
* This is a description of the prop
|
39
|
-
* @values true, false
|
40
|
-
* @defaultValue false
|
41
|
-
* @control boolean
|
42
|
-
* @group Size
|
43
|
-
* */
|
44
|
-
primary: {
|
45
|
-
type: Boolean,
|
46
|
-
default: false,
|
47
|
-
},
|
48
|
-
},
|
49
|
-
setup(props: any) {
|
50
|
-
return () => h('pre', JSON.stringify(props, null, 2));
|
51
|
-
},
|
52
|
-
});
|