-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
Copy pathindex.js
89 lines (76 loc) · 2.17 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { start } from '@storybook/core/client';
import Vue from 'vue';
import './globals';
import render, { VALUES } from './render';
import { extractProps } from './util';
export const WRAPS = 'STORYBOOK_WRAPS';
function prepare(rawStory, innerStory) {
let story = rawStory;
// eslint-disable-next-line no-underscore-dangle
if (!story._isVue) {
if (typeof story === 'string') {
story = { template: story };
}
if (innerStory) {
story.components = { ...(story.components || {}), story: innerStory };
}
story = Vue.extend(story);
} else if (story.options[WRAPS]) {
return story;
}
return Vue.extend({
[WRAPS]: story,
[VALUES]: { ...(innerStory ? innerStory.options[VALUES] : {}), ...extractProps(story) },
functional: true,
render(h, { data, parent, children }) {
return h(
story,
{
...data,
props: { ...(data.props || {}), ...parent.$root[VALUES] },
},
children
);
},
});
}
function decorateStory(getStory, decorators) {
return decorators.reduce(
(decorated, decorator) => (context = {}) => {
let story;
const decoratedStory = decorator((p = {}) => {
story = decorated(
Object.assign(
context,
p,
{ parameters: Object.assign(context.parameters || {}, p.parameters) },
{ options: Object.assign(context.options || {}, p.options) }
)
);
return story;
}, context);
if (!story) {
story = decorated(context);
}
if (decoratedStory === story) {
return story;
}
return prepare(decoratedStory, story);
},
context => prepare(getStory(context))
);
}
const { load: coreLoad, clientApi, configApi, forceReRender } = start(render, { decorateStory });
export const {
setAddon,
addDecorator,
addParameters,
clearDecorators,
getStorybook,
raw,
} = clientApi;
const framework = 'vue';
export const storiesOf = (...args) => clientApi.storiesOf(...args).addParameters({ framework });
export const load = (...args) => coreLoad(...args, framework);
export const { configure } = configApi;
export { forceReRender };