@storybook/vue3 7.1.0-alpha.6 → 7.1.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,84 @@
1
+ import type { DecoratorFunction } from '@storybook/csf';
2
+ import { global as globalThis } from '@storybook/global';
3
+ import type { Meta, StoryObj, VueRenderer } from '@storybook/vue3';
4
+ import { h } from 'vue';
5
+
6
+ const { Button, Pre } = (globalThis as any).Components;
7
+
8
+ const meta = {
9
+ component: Button,
10
+ } satisfies Meta<typeof Button>;
11
+
12
+ export default meta;
13
+
14
+ type Story = StoryObj<typeof meta>;
15
+
16
+ const ComponentTemplateWrapper = () => ({
17
+ components: {
18
+ Pre,
19
+ },
20
+ template: `
21
+ <Pre text="decorator" />
22
+ <story v-bind="$attrs"/>
23
+ `,
24
+ });
25
+
26
+ const SimpleTemplateWrapper = () => ({
27
+ template: `
28
+ <div style="border: 5px solid red;">
29
+ <story/>
30
+ </div>
31
+ `,
32
+ });
33
+
34
+ const VueWrapperWrapper: DecoratorFunction<VueRenderer> = (storyFn, context) => {
35
+ // Call the `storyFn` to receive a component that Vue can render
36
+ const story = storyFn();
37
+ // Vue 3 "Functional" component as decorator
38
+ return () => {
39
+ return h('div', { style: 'border: 5px solid blue' }, h(story, context.args));
40
+ };
41
+ };
42
+
43
+ const DynamicWrapperWrapper: DecoratorFunction<VueRenderer> = (storyFn, { args }) => ({
44
+ template: `<div :style="{ borderWidth: level, borderColor: 'green', borderStyle: 'solid' }"><story /></div>`,
45
+ computed: { level: () => `${args.level}px` },
46
+ });
47
+
48
+ export const ComponentTemplate: Story = {
49
+ args: { label: 'With component' },
50
+ decorators: [ComponentTemplateWrapper],
51
+ };
52
+
53
+ export const SimpleTemplate: Story = {
54
+ args: { label: 'With border' },
55
+ decorators: [SimpleTemplateWrapper],
56
+ };
57
+
58
+ export const VueWrapper: Story = {
59
+ args: { label: 'With Vue wrapper' },
60
+ decorators: [VueWrapperWrapper],
61
+ };
62
+
63
+ export const DynamicWrapper: Story = {
64
+ args: { label: 'With dynamic wrapper', primary: true },
65
+ argTypes: {
66
+ // Number type is detected, but we still want to constrain the range from 1-6
67
+ level: { control: { type: 'range', min: 1, max: 6 } },
68
+ },
69
+ decorators: [DynamicWrapperWrapper],
70
+ };
71
+
72
+ export const MultipleWrappers = {
73
+ args: { label: 'With multiple wrappers' },
74
+ argTypes: {
75
+ // Number type is detected, but we still want to constrain the range from 1-6
76
+ level: { control: { type: 'range', min: 1, max: 6 } },
77
+ },
78
+ decorators: [
79
+ ComponentTemplateWrapper,
80
+ SimpleTemplateWrapper,
81
+ VueWrapperWrapper,
82
+ DynamicWrapperWrapper,
83
+ ],
84
+ };
@@ -1 +0,0 @@
1
- var __create=Object.create;var __defProp=Object.defineProperty;var __getOwnPropDesc=Object.getOwnPropertyDescriptor;var __getOwnPropNames=Object.getOwnPropertyNames;var __getProtoOf=Object.getPrototypeOf,__hasOwnProp=Object.prototype.hasOwnProperty;var __commonJS=(cb,mod)=>function(){return mod||(0,cb[__getOwnPropNames(cb)[0]])((mod={exports:{}}).exports,mod),mod.exports};var __copyProps=(to,from,except,desc)=>{if(from&&typeof from=="object"||typeof from=="function")for(let key of __getOwnPropNames(from))!__hasOwnProp.call(to,key)&&key!==except&&__defProp(to,key,{get:()=>from[key],enumerable:!(desc=__getOwnPropDesc(from,key))||desc.enumerable});return to};var __toESM=(mod,isNodeMode,target)=>(target=mod!=null?__create(__getProtoOf(mod)):{},__copyProps(isNodeMode||!mod||!mod.__esModule?__defProp(target,"default",{value:mod,enumerable:!0}):target,mod));import{h}from"vue";import{sanitizeStoryContextUpdate}from"@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: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=>(story=decorated({...context,...sanitizeStoryContextUpdate(update)}),story),context);return story||(story=decorated(context)),decoratedStory===story?story:prepare(decoratedStory,h(story,context.args))},context=>prepare(storyFn(context)))}import{createApp,h as h2,reactive}from"vue";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 h2(Component,props,getSlots(props,context))},setupFunction=_app=>{},setup=fn=>{setupFunction=fn},map=new Map,elementMap=new Map;function renderToCanvas({storyFn,forceRemount,showMain,showException,storyContext},canvasElement){storyContext.args=reactive(storyContext.args);let element=storyFn();elementMap.set(canvasElement,element);let props=element.render?.().props,reactiveArgs=props?reactive(props):storyContext.args,existingApp=map.get(canvasElement);if(existingApp&&!forceRemount)return updateArgs(existingApp.reactiveArgs,reactiveArgs),()=>{teardown(existingApp.vueApp,canvasElement)};existingApp&&forceRemount&&teardown(existingApp.vueApp,canvasElement);let storybookApp=createApp({render(){let renderedElement=elementMap.get(canvasElement),current=renderedElement&&renderedElement.template?renderedElement:element;return map.set(canvasElement,{vueApp:storybookApp,reactiveArgs}),h2(current,reactiveArgs)}});return storybookApp.config.errorHandler=e=>showException(e),setupFunction(storybookApp),storybookApp.mount(canvasElement),showMain(),()=>{teardown(storybookApp,canvasElement)}}function getSlots(props,context){let{argTypes}=context,slots=Object.entries(props).filter(([key,value])=>argTypes[key]?.table?.category==="slots").map(([key,value])=>[key,typeof value=="function"?value:()=>value]);return Object.fromEntries(slots)}function updateArgs(reactiveArgs,nextArgs){nextArgs&&(Object.keys(reactiveArgs).forEach(key=>{delete reactiveArgs[key]}),Object.assign(reactiveArgs,nextArgs))}function teardown(storybookApp,canvasElement){storybookApp?.unmount(),map.has(canvasElement)&&map.delete(canvasElement)}export{__commonJS,__toESM,decorateStory,render,setup,renderToCanvas};
@@ -1,44 +0,0 @@
1
- import { expect } from '@storybook/jest';
2
- import { global as globalThis } from '@storybook/global';
3
- import { within, userEvent } from '@storybook/testing-library';
4
- import { UPDATE_STORY_ARGS, STORY_ARGS_UPDATED, RESET_STORY_ARGS } from '@storybook/core-events';
5
- import ReactiveArgs from './ReactiveArgs.vue';
6
-
7
- export default {
8
- component: ReactiveArgs,
9
- argTypes: {
10
- // To show that other props are passed through
11
- backgroundColor: { control: 'color' },
12
- },
13
- };
14
-
15
- export const ReactiveTest = {
16
- args: {
17
- label: 'Button',
18
- },
19
- // test that args are updated correctly in rective mode
20
- play: async ({ canvasElement, id }) => {
21
- const channel = globalThis.__STORYBOOK_ADDONS_CHANNEL__;
22
- const canvas = within(canvasElement);
23
-
24
- await channel.emit(RESET_STORY_ARGS, { storyId: id });
25
- await new Promise((resolve) => {
26
- channel.once(STORY_ARGS_UPDATED, resolve);
27
- });
28
- const reactiveButton = await canvas.getByRole('button');
29
- await expect(reactiveButton).toHaveTextContent('Button 0');
30
-
31
- await userEvent.click(reactiveButton); // click to update the label to increment the count + 1
32
- await channel.emit(UPDATE_STORY_ARGS, {
33
- storyId: id,
34
- updatedArgs: { label: 'updated' },
35
- });
36
- await new Promise((resolve) => {
37
- channel.once(STORY_ARGS_UPDATED, resolve);
38
- });
39
- await expect(canvas.getByRole('button')).toHaveTextContent('updated 1');
40
-
41
- await userEvent.click(reactiveButton); // click to update the label to increment the count + 1
42
- await expect(reactiveButton).toHaveTextContent('updated 2');
43
- },
44
- };
@@ -1,66 +0,0 @@
1
- import { global as globalThis } from '@storybook/global';
2
- import { h } from 'vue';
3
-
4
- const { Button, Pre } = globalThis.Components;
5
-
6
- export default {
7
- component: Button,
8
- };
9
-
10
- export const ComponentTemplate = {
11
- args: { label: 'With component' },
12
- decorators: [
13
- () => ({
14
- components: {
15
- Pre,
16
- },
17
- template: `
18
- <Pre text="decorator" />
19
- <story/>
20
- `,
21
- }),
22
- ],
23
- };
24
-
25
- export const SimpleTemplate = {
26
- args: { label: 'With border' },
27
- decorators: [
28
- () => ({
29
- template: `
30
- <div style="border: 5px solid red;">
31
- <story/>
32
- </div>
33
- `,
34
- }),
35
- ],
36
- };
37
-
38
- export const VueWrapper = {
39
- args: { label: 'With Vue wrapper' },
40
- decorators: [
41
- (storyFn) => {
42
- // Call the `storyFn` to receive a component that Vue can render
43
- const story = storyFn();
44
- // Vue 3 "Functional" component as decorator
45
- return () => {
46
- return h('div', { style: 'border: 2px solid blue' }, h(story));
47
- };
48
- },
49
- ],
50
- };
51
-
52
- export const DynamicWrapper = {
53
- args: { label: 'With dynamic wrapper', primary: true },
54
- argTypes: {
55
- // Number type is detected, but we still want to constrain the range from 1-6
56
- level: { control: { type: 'range', min: 1, max: 6 } },
57
- },
58
- decorators: [
59
- (storyFn, { args }) => ({
60
- template: `<div :style="{ borderWidth: level, borderColor: 'red', borderStyle: 'solid' }"><story /></div>`,
61
- data() {
62
- return { level: `${args.level}px` };
63
- },
64
- }),
65
- ],
66
- };