@storybook/vue3 7.1.0-alpha.3 → 7.1.0-alpha.31
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-HSFPF76R.mjs +6 -0
- package/dist/config.d.ts +6 -17
- package/dist/config.js +25 -44
- package/dist/config.mjs +32 -43
- package/dist/index.d.ts +10 -11
- package/dist/index.js +1 -1
- package/dist/index.mjs +8 -1
- package/dist/render-32b7dd3f.d.ts +148 -0
- package/package.json +16 -15
- package/src/typings.d.ts +1 -0
- package/template/cli/js/Header.vue +1 -1
- package/template/cli/js/Page.vue +1 -1
- package/template/cli/ts-3-8/Header.vue +1 -1
- package/template/cli/ts-3-8/Page.vue +8 -5
- package/template/cli/ts-4-9/Header.vue +1 -1
- package/template/cli/ts-4-9/Page.vue +8 -5
- package/template/stories/preview.js +29 -4
- package/template/stories_vue3-vite-default-ts/BaseLayout.vue +18 -0
- package/template/stories_vue3-vite-default-ts/CustomRenderFunctionalComponent.stories.ts +32 -0
- package/template/stories_vue3-vite-default-ts/CustomRenderOptionsArgsFromData.stories.ts +45 -0
- package/template/stories_vue3-vite-default-ts/GlobalSetup.stories.ts +52 -0
- package/template/stories_vue3-vite-default-ts/GlobalSetup.vue +6 -0
- package/template/{stories/GlobalUsage.stories.js → stories_vue3-vite-default-ts/GlobalUsage.stories.ts} +1 -1
- package/template/stories_vue3-vite-default-ts/GlobalUsage.vue +3 -0
- package/template/stories_vue3-vite-default-ts/MySlotComponent.vue +12 -0
- package/template/{stories → stories_vue3-vite-default-ts}/OverrideArgs.stories.js +3 -1
- package/template/{stories → stories_vue3-vite-default-ts}/OverrideArgs.vue +3 -3
- package/template/stories_vue3-vite-default-ts/ReactiveArgs.stories.ts +137 -0
- package/template/stories_vue3-vite-default-ts/ReactiveDecorators.stories.ts +88 -0
- package/template/stories_vue3-vite-default-ts/ReactiveSlots.stories.ts +127 -0
- package/template/stories_vue3-vite-default-ts/Reactivity.vue +44 -0
- package/template/stories_vue3-vite-default-ts/ScopedSlots.stories.ts +81 -0
- package/template/stories_vue3-vite-default-ts/SourceDecorator.stories.ts +46 -0
- package/template/stories_vue3-vite-default-ts/decorators.stories.ts +84 -0
- package/template/stories_vue3-vite-default-ts/preview.ts +12 -0
- package/dist/chunk-2GDW2BFM.mjs +0 -1
- package/dist/render-c842c5d5.d.ts +0 -14
- package/template/stories/GlobalUsage.vue +0 -3
- package/template/stories/ReactiveArgs.stories.js +0 -44
- package/template/stories/decorators.stories.js +0 -66
- /package/template/{stories → stories_vue3-vite-default-ts}/ReactiveArgs.vue +0 -0
package/dist/index.d.ts
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
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
|
-
import { App,
|
5
|
-
import { V as VueRenderer } from './render-
|
6
|
-
export { s as setup } from './render-
|
7
|
-
import { Simplify, SetOptional, RemoveIndexSignature } from 'type-fest';
|
4
|
+
import { App, FunctionalComponent, VNodeChild } from 'vue';
|
5
|
+
import { V as VueRenderer } from './render-32b7dd3f.js';
|
6
|
+
export { s as setup } from './render-32b7dd3f.js';
|
7
|
+
import { Simplify, SetOptional, Constructor, RemoveIndexSignature } from 'type-fest';
|
8
|
+
import { ComponentProps, ComponentSlots } from 'vue-component-type-helpers';
|
8
9
|
|
9
10
|
interface ClientApi extends Addon_ClientStoryApi<VueRenderer['storyResult']> {
|
10
11
|
configure(loader: Addon_Loadable, module: NodeModule): void;
|
@@ -39,15 +40,13 @@ type StoryObj<TMetaOrCmpOrArgs = Args> = TMetaOrCmpOrArgs extends {
|
|
39
40
|
render?: ArgsStoryFn<VueRenderer, any>;
|
40
41
|
component?: infer Component;
|
41
42
|
args?: infer DefaultArgs;
|
42
|
-
} ? Simplify<
|
43
|
-
type ExtractSlots<C> = C
|
44
|
-
$slots: infer T;
|
45
|
-
} ? AllowNonFunctionSlots<Partial<RemoveIndexSignature<T>>> : unknown;
|
43
|
+
} ? Simplify<ComponentPropsAndSlots<Component> & ArgsFromMeta<VueRenderer, TMetaOrCmpOrArgs>> extends infer TArgs ? StoryAnnotations<VueRenderer, TArgs, SetOptional<TArgs, Extract<keyof TArgs, keyof DefaultArgs>>> : never : StoryAnnotations<VueRenderer, ComponentPropsOrProps<TMetaOrCmpOrArgs>>;
|
44
|
+
type ExtractSlots<C> = AllowNonFunctionSlots<Partial<RemoveIndexSignature<ComponentSlots<C>>>>;
|
46
45
|
type AllowNonFunctionSlots<Slots> = {
|
47
46
|
[K in keyof Slots]: Slots[K] | VNodeChild;
|
48
47
|
};
|
49
|
-
type
|
50
|
-
type ComponentPropsOrProps<TCmpOrArgs> = TCmpOrArgs extends
|
48
|
+
type ComponentPropsAndSlots<C> = ComponentProps<C> & ExtractSlots<C>;
|
49
|
+
type ComponentPropsOrProps<TCmpOrArgs> = TCmpOrArgs extends Constructor<any> ? ComponentPropsAndSlots<TCmpOrArgs> : TCmpOrArgs extends FunctionalComponent<any> ? ComponentPropsAndSlots<TCmpOrArgs> : TCmpOrArgs;
|
51
50
|
/**
|
52
51
|
* @deprecated Use `StoryFn` instead.
|
53
52
|
* Use `StoryObj` if you want to migrate to CSF3, which uses objects instead of functions to represent stories.
|
@@ -63,4 +62,4 @@ type Loader<TArgs = StrictArgs> = LoaderFunction<VueRenderer, TArgs>;
|
|
63
62
|
type StoryContext<TArgs = StrictArgs> = StoryContext$1<VueRenderer, TArgs>;
|
64
63
|
type Preview = ProjectAnnotations<VueRenderer>;
|
65
64
|
|
66
|
-
export {
|
65
|
+
export { ComponentPropsAndSlots, Decorator, Loader, Meta, Preview, Story, StoryContext, StoryFn, StoryObj, VueRenderer, configure, forceReRender, raw, storiesOf };
|
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
|
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 +1,8 @@
|
|
1
|
-
import{decorateStory,render
|
1
|
+
import { renderToCanvas, decorateStory, render } from './chunk-HSFPF76R.mjs';
|
2
|
+
export { setup } from './chunk-HSFPF76R.mjs';
|
3
|
+
import { global } from '@storybook/global';
|
4
|
+
import { start } from '@storybook/preview-api';
|
5
|
+
|
6
|
+
var{window:globalWindow}=global;globalWindow.STORYBOOK_ENV="vue3";var RENDERER="vue3",api=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;typeof module<"u"&&module?.hot?.decline();
|
7
|
+
|
8
|
+
export { configure, forceReRender, raw, storiesOf };
|
@@ -0,0 +1,148 @@
|
|
1
|
+
import { ConcreteComponent, App } from 'vue';
|
2
|
+
import { WebRenderer, ArgsStoryFn as ArgsStoryFn$1, RenderContext } from '@storybook/types';
|
3
|
+
|
4
|
+
type StoryFnVueReturnType = ConcreteComponent<any>;
|
5
|
+
interface VueRenderer extends WebRenderer {
|
6
|
+
component: Omit<ConcreteComponent<this['T']>, 'props'>;
|
7
|
+
storyResult: StoryFnVueReturnType;
|
8
|
+
}
|
9
|
+
|
10
|
+
interface SBBaseType {
|
11
|
+
required?: boolean;
|
12
|
+
raw?: string;
|
13
|
+
}
|
14
|
+
type SBScalarType = SBBaseType & {
|
15
|
+
name: 'boolean' | 'string' | 'number' | 'function' | 'symbol';
|
16
|
+
};
|
17
|
+
type SBArrayType = SBBaseType & {
|
18
|
+
name: 'array';
|
19
|
+
value: SBType;
|
20
|
+
};
|
21
|
+
type SBObjectType = SBBaseType & {
|
22
|
+
name: 'object';
|
23
|
+
value: Record<string, SBType>;
|
24
|
+
};
|
25
|
+
type SBEnumType = SBBaseType & {
|
26
|
+
name: 'enum';
|
27
|
+
value: (string | number)[];
|
28
|
+
};
|
29
|
+
type SBIntersectionType = SBBaseType & {
|
30
|
+
name: 'intersection';
|
31
|
+
value: SBType[];
|
32
|
+
};
|
33
|
+
type SBUnionType = SBBaseType & {
|
34
|
+
name: 'union';
|
35
|
+
value: SBType[];
|
36
|
+
};
|
37
|
+
type SBOtherType = SBBaseType & {
|
38
|
+
name: 'other';
|
39
|
+
value: string;
|
40
|
+
};
|
41
|
+
type SBType = SBScalarType | SBEnumType | SBArrayType | SBObjectType | SBIntersectionType | SBUnionType | SBOtherType;
|
42
|
+
|
43
|
+
type StoryId = string;
|
44
|
+
type ComponentId = string;
|
45
|
+
type ComponentTitle = string;
|
46
|
+
type StoryName = string;
|
47
|
+
type Tag = string;
|
48
|
+
interface StoryIdentifier {
|
49
|
+
componentId: ComponentId;
|
50
|
+
title: ComponentTitle;
|
51
|
+
/** @deprecated */
|
52
|
+
kind: ComponentTitle;
|
53
|
+
id: StoryId;
|
54
|
+
name: StoryName;
|
55
|
+
/** @deprecated */
|
56
|
+
story: StoryName;
|
57
|
+
tags: Tag[];
|
58
|
+
}
|
59
|
+
interface Parameters {
|
60
|
+
[name: string]: any;
|
61
|
+
}
|
62
|
+
type ConditionalTest = {
|
63
|
+
truthy?: boolean;
|
64
|
+
} | {
|
65
|
+
exists: boolean;
|
66
|
+
} | {
|
67
|
+
eq: any;
|
68
|
+
} | {
|
69
|
+
neq: any;
|
70
|
+
};
|
71
|
+
type ConditionalValue = {
|
72
|
+
arg: string;
|
73
|
+
} | {
|
74
|
+
global: string;
|
75
|
+
};
|
76
|
+
type Conditional = ConditionalValue & ConditionalTest;
|
77
|
+
interface InputType {
|
78
|
+
name?: string;
|
79
|
+
description?: string;
|
80
|
+
defaultValue?: any;
|
81
|
+
type?: SBType | SBScalarType['name'];
|
82
|
+
if?: Conditional;
|
83
|
+
[key: string]: any;
|
84
|
+
}
|
85
|
+
interface StrictInputType extends InputType {
|
86
|
+
name: string;
|
87
|
+
type?: SBType;
|
88
|
+
}
|
89
|
+
interface Args {
|
90
|
+
[name: string]: any;
|
91
|
+
}
|
92
|
+
type StrictArgTypes<TArgs = Args> = {
|
93
|
+
[name in keyof TArgs]: StrictInputType;
|
94
|
+
};
|
95
|
+
type Globals = {
|
96
|
+
[name: string]: any;
|
97
|
+
};
|
98
|
+
type Renderer = {
|
99
|
+
/** What is the type of the `component` annotation in this renderer? */
|
100
|
+
component: unknown;
|
101
|
+
/** What does the story function return in this renderer? */
|
102
|
+
storyResult: unknown;
|
103
|
+
/** What type of element does this renderer render to? */
|
104
|
+
canvasElement: unknown;
|
105
|
+
T?: unknown;
|
106
|
+
};
|
107
|
+
type StoryContextForEnhancers<TRenderer extends Renderer = Renderer, TArgs = Args> = StoryIdentifier & {
|
108
|
+
component?: (TRenderer & {
|
109
|
+
T: any;
|
110
|
+
})['component'];
|
111
|
+
subcomponents?: Record<string, (TRenderer & {
|
112
|
+
T: any;
|
113
|
+
})['component']>;
|
114
|
+
parameters: Parameters;
|
115
|
+
initialArgs: TArgs;
|
116
|
+
argTypes: StrictArgTypes<TArgs>;
|
117
|
+
};
|
118
|
+
type StoryContextUpdate<TArgs = Args> = {
|
119
|
+
args?: TArgs;
|
120
|
+
globals?: Globals;
|
121
|
+
[key: string]: any;
|
122
|
+
};
|
123
|
+
type ViewMode = 'story' | 'docs';
|
124
|
+
type StoryContextForLoaders<TRenderer extends Renderer = Renderer, TArgs = Args> = StoryContextForEnhancers<TRenderer, TArgs> & Required<StoryContextUpdate<TArgs>> & {
|
125
|
+
hooks: unknown;
|
126
|
+
viewMode: ViewMode;
|
127
|
+
originalStoryFn: StoryFn<TRenderer>;
|
128
|
+
};
|
129
|
+
type StoryContext<TRenderer extends Renderer = Renderer, TArgs = Args> = StoryContextForLoaders<TRenderer, TArgs> & {
|
130
|
+
loaded: Record<string, any>;
|
131
|
+
abortSignal: AbortSignal;
|
132
|
+
canvasElement: TRenderer['canvasElement'];
|
133
|
+
};
|
134
|
+
type LegacyStoryFn<TRenderer extends Renderer = Renderer, TArgs = Args> = (context: StoryContext<TRenderer, TArgs>) => TRenderer['storyResult'];
|
135
|
+
type ArgsStoryFn<TRenderer extends Renderer = Renderer, TArgs = Args> = (args: TArgs, context: StoryContext<TRenderer, TArgs>) => (TRenderer & {
|
136
|
+
T: TArgs;
|
137
|
+
})['storyResult'];
|
138
|
+
type StoryFn<TRenderer extends Renderer = Renderer, TArgs = Args> = LegacyStoryFn<TRenderer, TArgs> | ArgsStoryFn<TRenderer, TArgs>;
|
139
|
+
|
140
|
+
declare const render: ArgsStoryFn$1<VueRenderer>;
|
141
|
+
/** add a setup function to set that will be call when story is created a d
|
142
|
+
*
|
143
|
+
* @param fn
|
144
|
+
*/
|
145
|
+
declare const setup: (fn: (app: App, storyContext?: StoryContext<VueRenderer>) => void) => void;
|
146
|
+
declare function renderToCanvas({ storyFn, forceRemount, showMain, showException, storyContext, id }: RenderContext<VueRenderer>, canvasElement: VueRenderer['canvasElement']): () => void;
|
147
|
+
|
148
|
+
export { VueRenderer as V, renderToCanvas as a, render as r, setup as s };
|
package/package.json
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
{
|
2
2
|
"name": "@storybook/vue3",
|
3
|
-
"version": "7.1.0-alpha.
|
3
|
+
"version": "7.1.0-alpha.31",
|
4
4
|
"description": "Storybook Vue 3 renderer",
|
5
5
|
"keywords": [
|
6
6
|
"storybook"
|
7
7
|
],
|
8
|
-
"homepage": "https://github.com/storybookjs/storybook/tree/
|
8
|
+
"homepage": "https://github.com/storybookjs/storybook/tree/next/code/renderers/vue3",
|
9
9
|
"bugs": {
|
10
10
|
"url": "https://github.com/storybookjs/storybook/issues"
|
11
11
|
},
|
12
12
|
"repository": {
|
13
13
|
"type": "git",
|
14
14
|
"url": "https://github.com/storybookjs/storybook.git",
|
15
|
-
"directory": "renderers/vue3"
|
15
|
+
"directory": "code/renderers/vue3"
|
16
16
|
},
|
17
17
|
"funding": {
|
18
18
|
"type": "opencollective",
|
@@ -21,15 +21,15 @@
|
|
21
21
|
"license": "MIT",
|
22
22
|
"exports": {
|
23
23
|
".": {
|
24
|
+
"types": "./dist/index.d.ts",
|
24
25
|
"node": "./dist/index.js",
|
25
26
|
"require": "./dist/index.js",
|
26
|
-
"import": "./dist/index.mjs"
|
27
|
-
"types": "./dist/index.d.ts"
|
27
|
+
"import": "./dist/index.mjs"
|
28
28
|
},
|
29
29
|
"./preview": {
|
30
|
+
"types": "./dist/config.d.ts",
|
30
31
|
"require": "./dist/config.js",
|
31
|
-
"import": "./dist/config.mjs"
|
32
|
-
"types": "./dist/config.d.ts"
|
32
|
+
"import": "./dist/config.mjs"
|
33
33
|
},
|
34
34
|
"./package.json": "./package.json"
|
35
35
|
},
|
@@ -48,13 +48,14 @@
|
|
48
48
|
"prep": "../../../scripts/prepare/bundle.ts"
|
49
49
|
},
|
50
50
|
"dependencies": {
|
51
|
-
"@storybook/core-client": "7.1.0-alpha.
|
52
|
-
"@storybook/docs-tools": "7.1.0-alpha.
|
51
|
+
"@storybook/core-client": "7.1.0-alpha.31",
|
52
|
+
"@storybook/docs-tools": "7.1.0-alpha.31",
|
53
53
|
"@storybook/global": "^5.0.0",
|
54
|
-
"@storybook/preview-api": "7.1.0-alpha.
|
55
|
-
"@storybook/types": "7.1.0-alpha.
|
54
|
+
"@storybook/preview-api": "7.1.0-alpha.31",
|
55
|
+
"@storybook/types": "7.1.0-alpha.31",
|
56
56
|
"ts-dedent": "^2.0.0",
|
57
|
-
"type-fest": "
|
57
|
+
"type-fest": "^3.11.0",
|
58
|
+
"vue-component-type-helpers": "latest"
|
58
59
|
},
|
59
60
|
"devDependencies": {
|
60
61
|
"@digitak/esrun": "^3.2.2",
|
@@ -62,7 +63,7 @@
|
|
62
63
|
"@vue/vue3-jest": "29",
|
63
64
|
"typescript": "~4.9.3",
|
64
65
|
"vue": "^3.2.47",
|
65
|
-
"vue-tsc": "
|
66
|
+
"vue-tsc": "latest"
|
66
67
|
},
|
67
68
|
"peerDependencies": {
|
68
69
|
"vue": "^3.0.0"
|
@@ -80,5 +81,5 @@
|
|
80
81
|
],
|
81
82
|
"platform": "browser"
|
82
83
|
},
|
83
|
-
"gitHead": "
|
84
|
-
}
|
84
|
+
"gitHead": "e6a7fd8a655c69780bc20b9749c2699e44beae16"
|
85
|
+
}
|
package/src/typings.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
declare var STORYBOOK_ENV: 'vue3';
|
package/template/cli/js/Page.vue
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
<article>
|
3
3
|
<my-header :user="user" @login="onLogin" @logout="onLogout" @create-account="onCreateAccount" />
|
4
4
|
|
5
|
-
<section>
|
5
|
+
<section class="storybook-page">
|
6
6
|
<h2>Pages in Storybook</h2>
|
7
7
|
<p>
|
8
8
|
We recommend building UIs with a
|
@@ -28,7 +28,9 @@
|
|
28
28
|
</ul>
|
29
29
|
<p>
|
30
30
|
Get a guided tutorial on component-driven development at
|
31
|
-
<a href="https://storybook.js.org/tutorials/" target="_blank" rel="noopener noreferrer"
|
31
|
+
<a href="https://storybook.js.org/tutorials/" target="_blank" rel="noopener noreferrer"
|
32
|
+
>Storybook tutorials</a
|
33
|
+
>
|
32
34
|
. Read more in the
|
33
35
|
<a href="https://storybook.js.org/docs" target="_blank" rel="noopener noreferrer">docs</a>
|
34
36
|
.
|
@@ -40,7 +42,9 @@
|
|
40
42
|
<g fill="none" fill-rule="evenodd">
|
41
43
|
<path
|
42
44
|
d="M1.5 5.2h4.8c.3 0 .5.2.5.4v5.1c-.1.2-.3.3-.4.3H1.4a.5.5 0 01-.5-.4V5.7c0-.3.2-.5.5-.5zm0-2.1h6.9c.3 0 .5.2.5.4v7a.5.5 0 01-1 0V4H1.5a.5.5 0 010-1zm0-2.1h9c.3 0 .5.2.5.4v9.1a.5.5 0 01-1 0V2H1.5a.5.5 0 010-1zm4.3 5.2H2V10h3.8V6.2z"
|
43
|
-
id="a"
|
45
|
+
id="a"
|
46
|
+
fill="#999"
|
47
|
+
/>
|
44
48
|
</g>
|
45
49
|
</svg>
|
46
50
|
Viewports addon in the toolbar
|
@@ -55,7 +59,7 @@ import MyHeader from './Header.vue';
|
|
55
59
|
|
56
60
|
import { ref } from 'vue';
|
57
61
|
|
58
|
-
const user = ref<{ name: string } | null>(null)
|
62
|
+
const user = ref<{ name: string } | null>(null);
|
59
63
|
|
60
64
|
const onLogin = () => {
|
61
65
|
user.value = { name: 'Jane Doe' };
|
@@ -66,5 +70,4 @@ const onLogout = () => {
|
|
66
70
|
const onCreateAccount = () => {
|
67
71
|
user.value = { name: 'Jane Doe' };
|
68
72
|
};
|
69
|
-
|
70
73
|
</script>
|
@@ -2,7 +2,7 @@
|
|
2
2
|
<article>
|
3
3
|
<my-header :user="user" @login="onLogin" @logout="onLogout" @create-account="onCreateAccount" />
|
4
4
|
|
5
|
-
<section>
|
5
|
+
<section class="storybook-page">
|
6
6
|
<h2>Pages in Storybook</h2>
|
7
7
|
<p>
|
8
8
|
We recommend building UIs with a
|
@@ -28,7 +28,9 @@
|
|
28
28
|
</ul>
|
29
29
|
<p>
|
30
30
|
Get a guided tutorial on component-driven development at
|
31
|
-
<a href="https://storybook.js.org/tutorials/" target="_blank" rel="noopener noreferrer"
|
31
|
+
<a href="https://storybook.js.org/tutorials/" target="_blank" rel="noopener noreferrer"
|
32
|
+
>Storybook tutorials</a
|
33
|
+
>
|
32
34
|
. Read more in the
|
33
35
|
<a href="https://storybook.js.org/docs" target="_blank" rel="noopener noreferrer">docs</a>
|
34
36
|
.
|
@@ -40,7 +42,9 @@
|
|
40
42
|
<g fill="none" fill-rule="evenodd">
|
41
43
|
<path
|
42
44
|
d="M1.5 5.2h4.8c.3 0 .5.2.5.4v5.1c-.1.2-.3.3-.4.3H1.4a.5.5 0 01-.5-.4V5.7c0-.3.2-.5.5-.5zm0-2.1h6.9c.3 0 .5.2.5.4v7a.5.5 0 01-1 0V4H1.5a.5.5 0 010-1zm0-2.1h9c.3 0 .5.2.5.4v9.1a.5.5 0 01-1 0V2H1.5a.5.5 0 010-1zm4.3 5.2H2V10h3.8V6.2z"
|
43
|
-
id="a"
|
45
|
+
id="a"
|
46
|
+
fill="#999"
|
47
|
+
/>
|
44
48
|
</g>
|
45
49
|
</svg>
|
46
50
|
Viewports addon in the toolbar
|
@@ -55,7 +59,7 @@ import MyHeader from './Header.vue';
|
|
55
59
|
|
56
60
|
import { ref } from 'vue';
|
57
61
|
|
58
|
-
const user = ref<{ name: string } | null>(null)
|
62
|
+
const user = ref<{ name: string } | null>(null);
|
59
63
|
|
60
64
|
const onLogin = () => {
|
61
65
|
user.value = { name: 'Jane Doe' };
|
@@ -66,5 +70,4 @@ const onLogout = () => {
|
|
66
70
|
const onCreateAccount = () => {
|
67
71
|
user.value = { name: 'Jane Doe' };
|
68
72
|
};
|
69
|
-
|
70
73
|
</script>
|
@@ -2,12 +2,37 @@ import { global as globalThis } from '@storybook/global';
|
|
2
2
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
3
3
|
import { setup } from '@storybook/vue3';
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
//
|
8
|
-
//
|
5
|
+
const somePlugin = {
|
6
|
+
install: (app, options) => {
|
7
|
+
// inject a globally available $greetingText() method
|
8
|
+
// eslint-disable-next-line no-param-reassign
|
9
|
+
app.config.globalProperties.$greetingMessage = (key) => {
|
10
|
+
// retrieve a nested property in `options`
|
11
|
+
// using `key`
|
12
|
+
return options.greetings[key];
|
13
|
+
};
|
14
|
+
},
|
15
|
+
};
|
16
|
+
const someColor = 'someColor';
|
9
17
|
|
18
|
+
// add components to global scope
|
10
19
|
setup((app) => {
|
11
20
|
// This adds a component that can be used globally in stories
|
12
21
|
app.component('GlobalButton', globalThis.Components.Button);
|
13
22
|
});
|
23
|
+
|
24
|
+
// this adds a plugin to vue app that can be used globally in stories
|
25
|
+
setup((app, context) => {
|
26
|
+
app.use(somePlugin, {
|
27
|
+
greetings: {
|
28
|
+
hello: `Hello Story! from some plugin your name is ${context?.name}!`,
|
29
|
+
welcome: `Welcome Story! from some plugin your name is ${context?.name}!`,
|
30
|
+
hi: `Hi Story! from some plugin your name is ${context?.name}!`,
|
31
|
+
},
|
32
|
+
});
|
33
|
+
});
|
34
|
+
|
35
|
+
// additonal setup to provide some propriety to the app
|
36
|
+
setup((app, context) => {
|
37
|
+
app.provide(someColor, 'green');
|
38
|
+
});
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<script setup lang="ts">
|
2
|
+
defineProps({
|
3
|
+
label: String,
|
4
|
+
});
|
5
|
+
</script>
|
6
|
+
<template>
|
7
|
+
<div>
|
8
|
+
<header data-testid="header-slot">
|
9
|
+
<slot name="header" title="Header title from the slot"></slot>
|
10
|
+
</header>
|
11
|
+
<main data-testid="default-slot">
|
12
|
+
<slot></slot>
|
13
|
+
</main>
|
14
|
+
<footer data-testid="footer-slot">
|
15
|
+
<slot name="footer"></slot>
|
16
|
+
</footer>
|
17
|
+
</div>
|
18
|
+
</template>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import type { Meta } from '@storybook/vue3';
|
2
|
+
import { h } from 'vue';
|
3
|
+
import Reactivity from './Reactivity.vue';
|
4
|
+
import * as ReactiveDecorators from './ReactiveDecorators.stories';
|
5
|
+
|
6
|
+
const meta = {
|
7
|
+
...ReactiveDecorators.default,
|
8
|
+
component: Reactivity,
|
9
|
+
// storybook render function is not a functional component. it returns a functional component or a component options
|
10
|
+
render: (args) => {
|
11
|
+
// create the slot contents as a functional components
|
12
|
+
const header = ({ title }: { title: string }) => h('h3', `${args.header} - Title: ${title}`);
|
13
|
+
const defaultSlot = () => h('p', `${args.default}`);
|
14
|
+
const footer = () => h('p', `${args.footer}`);
|
15
|
+
// vue render function is a functional components
|
16
|
+
return () =>
|
17
|
+
h('div', [
|
18
|
+
`Custom render uses a functional component, and passes slots to the component:`,
|
19
|
+
h(Reactivity, args, { header, default: defaultSlot, footer }),
|
20
|
+
]);
|
21
|
+
},
|
22
|
+
} satisfies Meta<typeof Reactivity>;
|
23
|
+
|
24
|
+
export default meta;
|
25
|
+
|
26
|
+
export {
|
27
|
+
NoDecorators,
|
28
|
+
DecoratorFunctionalComponent,
|
29
|
+
DecoratorFunctionalComponentArgsFromContext,
|
30
|
+
DecoratorComponentOptions,
|
31
|
+
DecoratorComponentOptionsArgsFromData,
|
32
|
+
} from './ReactiveDecorators.stories';
|
@@ -0,0 +1,45 @@
|
|
1
|
+
import type { Meta } from '@storybook/vue3';
|
2
|
+
import { defineComponent, shallowReactive } from 'vue';
|
3
|
+
import Reactivity from './Reactivity.vue';
|
4
|
+
import * as ReactiveDecorators from './ReactiveDecorators.stories';
|
5
|
+
|
6
|
+
// when you use custom render, you can use any vue api to create your story and garanti reactivity, otherwise i can ease kill the reactivity.
|
7
|
+
const state = shallowReactive<{ header: any; default: any; footer: any }>({
|
8
|
+
header: '',
|
9
|
+
default: '',
|
10
|
+
footer: '',
|
11
|
+
}); // or reactive
|
12
|
+
|
13
|
+
const meta = {
|
14
|
+
...ReactiveDecorators.default,
|
15
|
+
component: Reactivity,
|
16
|
+
render: (args, { argTypes }) => {
|
17
|
+
state.header = args.header;
|
18
|
+
state.default = args.default;
|
19
|
+
state.footer = args.footer;
|
20
|
+
// return a component options
|
21
|
+
return defineComponent({
|
22
|
+
data: () => ({ args, header: state.header, default: state.default, footer: state.footer }),
|
23
|
+
components: {
|
24
|
+
Reactivity,
|
25
|
+
},
|
26
|
+
template: `<div>Custom render uses options api and binds args to data:
|
27
|
+
<Reactivity v-bind="args">
|
28
|
+
<template #header="{title}"><h3>{{ args.header }} - Title: {{ title }}</h3></template>
|
29
|
+
<template #default>{{ args.default }}</template>
|
30
|
+
<template #footer>{{ args.footer }} </template>
|
31
|
+
</Reactivity>
|
32
|
+
</div>`,
|
33
|
+
});
|
34
|
+
},
|
35
|
+
} satisfies Meta<typeof Reactivity>;
|
36
|
+
|
37
|
+
export default meta;
|
38
|
+
|
39
|
+
export {
|
40
|
+
NoDecorators,
|
41
|
+
DecoratorFunctionalComponent,
|
42
|
+
DecoratorFunctionalComponentArgsFromContext,
|
43
|
+
DecoratorComponentOptions,
|
44
|
+
DecoratorComponentOptionsArgsFromData,
|
45
|
+
} from './ReactiveDecorators.stories';
|
@@ -0,0 +1,52 @@
|
|
1
|
+
import { expect } from '@storybook/jest';
|
2
|
+
import type { Meta, StoryObj } from '@storybook/vue3';
|
3
|
+
import { within } from '@storybook/testing-library';
|
4
|
+
import { inject } from 'vue';
|
5
|
+
import GlobalSetup from './GlobalSetup.vue';
|
6
|
+
|
7
|
+
const meta: Meta = {
|
8
|
+
component: GlobalSetup,
|
9
|
+
argTypes: {},
|
10
|
+
render: (args: any) => ({
|
11
|
+
// Components used in your story `template` are defined in the `components` object
|
12
|
+
components: { GlobalUsage: GlobalSetup },
|
13
|
+
// The story's `args` need to be mapped into the template through the `setup()` method
|
14
|
+
setup() {
|
15
|
+
const color = inject('someColor', 'red'); // <-- this is the global setup from .storybook/preview.ts
|
16
|
+
return { args: { ...args, backgroundColor: color } };
|
17
|
+
},
|
18
|
+
// And then the `args` are bound to your component with `v-bind="args"`
|
19
|
+
template: '<global-usage v-bind="args" />',
|
20
|
+
}),
|
21
|
+
} satisfies Meta<typeof GlobalSetup>;
|
22
|
+
export default meta;
|
23
|
+
|
24
|
+
type Story = StoryObj<typeof meta>;
|
25
|
+
|
26
|
+
export const Primary: Story = {
|
27
|
+
args: {
|
28
|
+
primary: true,
|
29
|
+
label: 'someColor injected from .storybook/preview.ts',
|
30
|
+
},
|
31
|
+
play: async ({ canvasElement, id }) => {
|
32
|
+
const canvas = within(canvasElement);
|
33
|
+
|
34
|
+
const button = await canvas.getByRole('button');
|
35
|
+
await expect(button).toHaveStyle('background-color: rgb(0, 128, 0)'); // <-- this provide themeColor = green from .storybook/preview.ts
|
36
|
+
|
37
|
+
const h2 = await canvas.getByRole('heading', { level: 2 });
|
38
|
+
await expect(h2).toHaveTextContent('Hi Story! from some plugin your name is Primary!');
|
39
|
+
|
40
|
+
const h3 = await canvas.getByRole('heading', { level: 3 });
|
41
|
+
await expect(h3).toHaveTextContent('Hello Story! from some plugin your name is Primary!');
|
42
|
+
|
43
|
+
const h4 = await canvas.getByRole('heading', { level: 4 });
|
44
|
+
await expect(h4).toHaveTextContent('Welcome Story! from some plugin your name is Primary!');
|
45
|
+
},
|
46
|
+
};
|
47
|
+
|
48
|
+
export const Secondary: Story = {
|
49
|
+
args: {
|
50
|
+
label: 'someColor injected from .storybook/preview.ts',
|
51
|
+
},
|
52
|
+
};
|
@@ -3,7 +3,7 @@ import GlobalUsage from './GlobalUsage.vue';
|
|
3
3
|
export default {
|
4
4
|
component: GlobalUsage,
|
5
5
|
argTypes: {},
|
6
|
-
render: (args) => ({
|
6
|
+
render: (args: any) => ({
|
7
7
|
// Components used in your story `template` are defined in the `components` object
|
8
8
|
components: { GlobalUsage },
|
9
9
|
// The story's `args` need to be mapped into the template through the `setup()` method
|