@storybook/addon-docs 6.5.7 → 7.0.0-alpha.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/blocks.d.ts +1 -1
- package/dist/cjs/blocks/ArgsTable.js +1 -1
- package/dist/cjs/blocks/Primary.js +1 -1
- package/dist/cjs/blocks/Stories.js +1 -1
- package/dist/cjs/blocks/mdx.js +1 -1
- package/dist/cjs/blocks/useStory.js +18 -4
- package/dist/cjs/preset.js +137 -33
- package/dist/cjs/preview.js +22 -6
- package/dist/esm/blocks/Anchor.js +7 -10
- package/dist/esm/blocks/ArgsTable.js +133 -182
- package/dist/esm/blocks/Canvas.js +34 -46
- package/dist/esm/blocks/Description.js +39 -45
- package/dist/esm/blocks/DocsContainer.js +36 -44
- package/dist/esm/blocks/DocsContext.js +1 -1
- package/dist/esm/blocks/DocsPage.js +3 -5
- package/dist/esm/blocks/DocsStory.js +18 -27
- package/dist/esm/blocks/Heading.js +5 -7
- package/dist/esm/blocks/Meta.js +9 -13
- package/dist/esm/blocks/Preview.js +5 -10
- package/dist/esm/blocks/Primary.js +10 -16
- package/dist/esm/blocks/Props.js +5 -10
- package/dist/esm/blocks/Source.js +64 -70
- package/dist/esm/blocks/SourceContainer.js +17 -50
- package/dist/esm/blocks/Stories.js +15 -27
- package/dist/esm/blocks/Story.js +58 -99
- package/dist/esm/blocks/Subheading.js +5 -7
- package/dist/esm/blocks/Subtitle.js +12 -12
- package/dist/esm/blocks/Title.js +10 -11
- package/dist/esm/blocks/Wrapper.js +7 -8
- package/dist/esm/blocks/enhanceSource.js +32 -56
- package/dist/esm/blocks/mdx.js +85 -89
- package/dist/esm/blocks/types.js +2 -2
- package/dist/esm/blocks/useStory.js +16 -73
- package/dist/esm/blocks/utils.js +4 -18
- package/dist/esm/manager.js +9 -14
- package/dist/esm/preset.js +114 -179
- package/dist/esm/preview.js +3 -61
- package/dist/esm/shared.js +5 -5
- package/dist/{ts3.9 → types}/blocks/Anchor.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/ArgsTable.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/Canvas.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/Description.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/DocsContainer.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/DocsContext.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/DocsPage.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/DocsStory.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/Heading.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/Meta.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/Preview.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/Primary.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/Props.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/Source.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/SourceContainer.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/Stories.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/Story.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/Subheading.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/Subtitle.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/Title.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/Wrapper.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/enhanceSource.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/index.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/mdx.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/types.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/useStory.d.ts +0 -0
- package/dist/{ts3.9 → types}/blocks/utils.d.ts +0 -0
- package/dist/{ts3.9 → types}/index.d.ts +0 -0
- package/dist/{ts3.9 → types}/manager.d.ts +0 -0
- package/dist/{ts3.9 → types}/preset.d.ts +2 -1
- package/dist/{ts3.9 → types}/preview.d.ts +0 -0
- package/dist/{ts3.9 → types}/shared.d.ts +0 -0
- package/package.json +16 -24
- package/dist/modern/blocks/Anchor.js +0 -8
- package/dist/modern/blocks/ArgsTable.js +0 -292
- package/dist/modern/blocks/Canvas.js +0 -83
- package/dist/modern/blocks/Description.js +0 -107
- package/dist/modern/blocks/DocsContainer.js +0 -98
- package/dist/modern/blocks/DocsContext.js +0 -16
- package/dist/modern/blocks/DocsPage.js +0 -11
- package/dist/modern/blocks/DocsStory.js +0 -48
- package/dist/modern/blocks/Heading.js +0 -17
- package/dist/modern/blocks/Meta.js +0 -31
- package/dist/modern/blocks/Preview.js +0 -9
- package/dist/modern/blocks/Primary.js +0 -23
- package/dist/modern/blocks/Props.js +0 -14
- package/dist/modern/blocks/Source.js +0 -154
- package/dist/modern/blocks/SourceContainer.js +0 -44
- package/dist/modern/blocks/Stories.js +0 -34
- package/dist/modern/blocks/Story.js +0 -168
- package/dist/modern/blocks/Subheading.js +0 -17
- package/dist/modern/blocks/Subtitle.js +0 -23
- package/dist/modern/blocks/Title.js +0 -24
- package/dist/modern/blocks/Wrapper.js +0 -8
- package/dist/modern/blocks/enhanceSource.js +0 -89
- package/dist/modern/blocks/index.js +0 -24
- package/dist/modern/blocks/mdx.js +0 -204
- package/dist/modern/blocks/types.js +0 -2
- package/dist/modern/blocks/useStory.js +0 -28
- package/dist/modern/blocks/utils.js +0 -29
- package/dist/modern/index.js +0 -1
- package/dist/modern/manager.js +0 -16
- package/dist/modern/preset.js +0 -130
- package/dist/modern/preview.js +0 -6
- package/dist/modern/shared.js +0 -11
- package/dist/ts3.4/blocks/Anchor.d.ts +0 -6
- package/dist/ts3.4/blocks/ArgsTable.d.ts +0 -33
- package/dist/ts3.4/blocks/Canvas.d.ts +0 -9
- package/dist/ts3.4/blocks/Description.d.ts +0 -20
- package/dist/ts3.4/blocks/DocsContainer.d.ts +0 -7
- package/dist/ts3.4/blocks/DocsContext.d.ts +0 -5
- package/dist/ts3.4/blocks/DocsPage.d.ts +0 -2
- package/dist/ts3.4/blocks/DocsStory.d.ts +0 -3
- package/dist/ts3.4/blocks/Heading.d.ts +0 -6
- package/dist/ts3.4/blocks/Meta.d.ts +0 -9
- package/dist/ts3.4/blocks/Preview.d.ts +0 -3
- package/dist/ts3.4/blocks/Primary.d.ts +0 -6
- package/dist/ts3.4/blocks/Props.d.ts +0 -3
- package/dist/ts3.4/blocks/Source.d.ts +0 -38
- package/dist/ts3.4/blocks/SourceContainer.d.ts +0 -14
- package/dist/ts3.4/blocks/Stories.d.ts +0 -7
- package/dist/ts3.4/blocks/Story.d.ts +0 -28
- package/dist/ts3.4/blocks/Subheading.d.ts +0 -3
- package/dist/ts3.4/blocks/Subtitle.d.ts +0 -6
- package/dist/ts3.4/blocks/Title.d.ts +0 -8
- package/dist/ts3.4/blocks/Wrapper.d.ts +0 -2
- package/dist/ts3.4/blocks/enhanceSource.d.ts +0 -3
- package/dist/ts3.4/blocks/index.d.ts +0 -24
- package/dist/ts3.4/blocks/mdx.d.ts +0 -20
- package/dist/ts3.4/blocks/types.d.ts +0 -13
- package/dist/ts3.4/blocks/useStory.d.ts +0 -5
- package/dist/ts3.4/blocks/utils.d.ts +0 -3
- package/dist/ts3.4/index.d.ts +0 -1
- package/dist/ts3.4/manager.d.ts +0 -1
- package/dist/ts3.4/preset.d.ts +0 -11
- package/dist/ts3.4/preview.d.ts +0 -6
- package/dist/ts3.4/shared.d.ts +0 -24
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
-
|
|
3
|
-
import React, { useContext, useEffect, useState, useCallback } from 'react';
|
|
4
|
-
import mapValues from 'lodash/mapValues';
|
|
5
|
-
import { ArgsTable as PureArgsTable, ArgsTableError, TabbedArgsTable } from '@storybook/components';
|
|
6
|
-
import { addons } from '@storybook/addons';
|
|
7
|
-
import { filterArgTypes } from '@storybook/store';
|
|
8
|
-
import Events from '@storybook/core-events';
|
|
9
|
-
import { DocsContext } from './DocsContext';
|
|
10
|
-
import { CURRENT_SELECTION, PRIMARY_STORY } from './types';
|
|
11
|
-
import { getComponentName } from './utils';
|
|
12
|
-
import { lookupStoryId } from './Story';
|
|
13
|
-
import { useStory } from './useStory';
|
|
14
|
-
|
|
15
|
-
const getContext = (storyId, context) => {
|
|
16
|
-
const story = context.storyById(storyId);
|
|
17
|
-
|
|
18
|
-
if (!story) {
|
|
19
|
-
throw new Error(`Unknown story: ${storyId}`);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return context.getStoryContext(story);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const useArgs = (storyId, context) => {
|
|
26
|
-
const channel = addons.getChannel();
|
|
27
|
-
const storyContext = getContext(storyId, context);
|
|
28
|
-
const [args, setArgs] = useState(storyContext.args);
|
|
29
|
-
useEffect(() => {
|
|
30
|
-
const cb = changed => {
|
|
31
|
-
if (changed.storyId === storyId) {
|
|
32
|
-
setArgs(changed.args);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
channel.on(Events.STORY_ARGS_UPDATED, cb);
|
|
37
|
-
return () => channel.off(Events.STORY_ARGS_UPDATED, cb);
|
|
38
|
-
}, [storyId]);
|
|
39
|
-
const updateArgs = useCallback(updatedArgs => channel.emit(Events.UPDATE_STORY_ARGS, {
|
|
40
|
-
storyId,
|
|
41
|
-
updatedArgs
|
|
42
|
-
}), [storyId]);
|
|
43
|
-
const resetArgs = useCallback(argNames => channel.emit(Events.RESET_STORY_ARGS, {
|
|
44
|
-
storyId,
|
|
45
|
-
argNames
|
|
46
|
-
}), [storyId]);
|
|
47
|
-
return [args, updateArgs, resetArgs];
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const useGlobals = (storyId, context) => {
|
|
51
|
-
const channel = addons.getChannel();
|
|
52
|
-
const storyContext = getContext(storyId, context);
|
|
53
|
-
const [globals, setGlobals] = useState(storyContext.globals);
|
|
54
|
-
useEffect(() => {
|
|
55
|
-
const cb = changed => {
|
|
56
|
-
setGlobals(changed.globals);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
channel.on(Events.GLOBALS_UPDATED, cb);
|
|
60
|
-
return () => channel.off(Events.GLOBALS_UPDATED, cb);
|
|
61
|
-
}, []);
|
|
62
|
-
return [globals];
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export const extractComponentArgTypes = (component, {
|
|
66
|
-
id,
|
|
67
|
-
storyById
|
|
68
|
-
}, include, exclude) => {
|
|
69
|
-
const {
|
|
70
|
-
parameters
|
|
71
|
-
} = storyById(id);
|
|
72
|
-
const {
|
|
73
|
-
extractArgTypes
|
|
74
|
-
} = parameters.docs || {};
|
|
75
|
-
|
|
76
|
-
if (!extractArgTypes) {
|
|
77
|
-
throw new Error(ArgsTableError.ARGS_UNSUPPORTED);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
let argTypes = extractArgTypes(component);
|
|
81
|
-
argTypes = filterArgTypes(argTypes, include, exclude);
|
|
82
|
-
return argTypes;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const isShortcut = value => {
|
|
86
|
-
return value && [CURRENT_SELECTION, PRIMARY_STORY].includes(value);
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
export const getComponent = (props = {}, {
|
|
90
|
-
id,
|
|
91
|
-
storyById
|
|
92
|
-
}) => {
|
|
93
|
-
const {
|
|
94
|
-
of
|
|
95
|
-
} = props;
|
|
96
|
-
const {
|
|
97
|
-
story
|
|
98
|
-
} = props;
|
|
99
|
-
const {
|
|
100
|
-
component
|
|
101
|
-
} = storyById(id);
|
|
102
|
-
|
|
103
|
-
if (isShortcut(of) || isShortcut(story)) {
|
|
104
|
-
return component || null;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (!of) {
|
|
108
|
-
throw new Error(ArgsTableError.NO_COMPONENT);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return of;
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
const addComponentTabs = (tabs, components, context, include, exclude, sort) => Object.assign({}, tabs, mapValues(components, comp => ({
|
|
115
|
-
rows: extractComponentArgTypes(comp, context, include, exclude),
|
|
116
|
-
sort
|
|
117
|
-
})));
|
|
118
|
-
|
|
119
|
-
export const StoryTable = props => {
|
|
120
|
-
const context = useContext(DocsContext);
|
|
121
|
-
const {
|
|
122
|
-
id: currentId,
|
|
123
|
-
componentStories
|
|
124
|
-
} = context;
|
|
125
|
-
const {
|
|
126
|
-
story: storyName,
|
|
127
|
-
component,
|
|
128
|
-
subcomponents,
|
|
129
|
-
showComponent,
|
|
130
|
-
include,
|
|
131
|
-
exclude,
|
|
132
|
-
sort
|
|
133
|
-
} = props;
|
|
134
|
-
|
|
135
|
-
try {
|
|
136
|
-
let storyId;
|
|
137
|
-
|
|
138
|
-
switch (storyName) {
|
|
139
|
-
case CURRENT_SELECTION:
|
|
140
|
-
{
|
|
141
|
-
storyId = currentId;
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
case PRIMARY_STORY:
|
|
146
|
-
{
|
|
147
|
-
const primaryStory = componentStories()[0];
|
|
148
|
-
storyId = primaryStory.id;
|
|
149
|
-
break;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
default:
|
|
153
|
-
{
|
|
154
|
-
storyId = lookupStoryId(storyName, context);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const story = useStory(storyId, context); // eslint-disable-next-line prefer-const
|
|
159
|
-
|
|
160
|
-
let [args, updateArgs, resetArgs] = useArgs(storyId, context);
|
|
161
|
-
const [globals] = useGlobals(storyId, context);
|
|
162
|
-
if (!story) return /*#__PURE__*/React.createElement(PureArgsTable, {
|
|
163
|
-
isLoading: true,
|
|
164
|
-
updateArgs: updateArgs,
|
|
165
|
-
resetArgs: resetArgs
|
|
166
|
-
});
|
|
167
|
-
const argTypes = filterArgTypes(story.argTypes, include, exclude);
|
|
168
|
-
const mainLabel = getComponentName(component) || 'Story';
|
|
169
|
-
let tabs = {
|
|
170
|
-
[mainLabel]: {
|
|
171
|
-
rows: argTypes,
|
|
172
|
-
args,
|
|
173
|
-
globals,
|
|
174
|
-
updateArgs,
|
|
175
|
-
resetArgs
|
|
176
|
-
}
|
|
177
|
-
}; // Use the dynamically generated component tabs if there are no controls
|
|
178
|
-
|
|
179
|
-
const storyHasArgsWithControls = argTypes && Object.values(argTypes).find(v => !!(v !== null && v !== void 0 && v.control));
|
|
180
|
-
|
|
181
|
-
if (!storyHasArgsWithControls) {
|
|
182
|
-
updateArgs = null;
|
|
183
|
-
resetArgs = null;
|
|
184
|
-
tabs = {};
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (component && (!storyHasArgsWithControls || showComponent)) {
|
|
188
|
-
tabs = addComponentTabs(tabs, {
|
|
189
|
-
[mainLabel]: component
|
|
190
|
-
}, context, include, exclude);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (subcomponents) {
|
|
194
|
-
if (Array.isArray(subcomponents)) {
|
|
195
|
-
throw new Error(`Unexpected subcomponents array. Expected an object whose keys are tab labels and whose values are components.`);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
tabs = addComponentTabs(tabs, subcomponents, context, include, exclude);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
return /*#__PURE__*/React.createElement(TabbedArgsTable, {
|
|
202
|
-
tabs: tabs,
|
|
203
|
-
sort: sort
|
|
204
|
-
});
|
|
205
|
-
} catch (err) {
|
|
206
|
-
return /*#__PURE__*/React.createElement(PureArgsTable, {
|
|
207
|
-
error: err.message
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
export const ComponentsTable = props => {
|
|
212
|
-
const context = useContext(DocsContext);
|
|
213
|
-
const {
|
|
214
|
-
components,
|
|
215
|
-
include,
|
|
216
|
-
exclude,
|
|
217
|
-
sort
|
|
218
|
-
} = props;
|
|
219
|
-
const tabs = addComponentTabs({}, components, context, include, exclude);
|
|
220
|
-
return /*#__PURE__*/React.createElement(TabbedArgsTable, {
|
|
221
|
-
tabs: tabs,
|
|
222
|
-
sort: sort
|
|
223
|
-
});
|
|
224
|
-
};
|
|
225
|
-
export const ArgsTable = props => {
|
|
226
|
-
const context = useContext(DocsContext);
|
|
227
|
-
const {
|
|
228
|
-
id,
|
|
229
|
-
storyById
|
|
230
|
-
} = context;
|
|
231
|
-
const {
|
|
232
|
-
parameters: {
|
|
233
|
-
controls
|
|
234
|
-
},
|
|
235
|
-
subcomponents
|
|
236
|
-
} = storyById(id);
|
|
237
|
-
const {
|
|
238
|
-
include,
|
|
239
|
-
exclude,
|
|
240
|
-
components,
|
|
241
|
-
sort: sortProp
|
|
242
|
-
} = props;
|
|
243
|
-
const {
|
|
244
|
-
story: storyName
|
|
245
|
-
} = props;
|
|
246
|
-
const sort = sortProp || (controls === null || controls === void 0 ? void 0 : controls.sort);
|
|
247
|
-
const main = getComponent(props, context);
|
|
248
|
-
|
|
249
|
-
if (storyName) {
|
|
250
|
-
return /*#__PURE__*/React.createElement(StoryTable, _extends({}, props, {
|
|
251
|
-
component: main,
|
|
252
|
-
subcomponents,
|
|
253
|
-
sort
|
|
254
|
-
}));
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
if (!components && !subcomponents) {
|
|
258
|
-
let mainProps;
|
|
259
|
-
|
|
260
|
-
try {
|
|
261
|
-
mainProps = {
|
|
262
|
-
rows: extractComponentArgTypes(main, context, include, exclude)
|
|
263
|
-
};
|
|
264
|
-
} catch (err) {
|
|
265
|
-
mainProps = {
|
|
266
|
-
error: err.message
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
return /*#__PURE__*/React.createElement(PureArgsTable, _extends({}, mainProps, {
|
|
271
|
-
sort: sort
|
|
272
|
-
}));
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
if (components) {
|
|
276
|
-
return /*#__PURE__*/React.createElement(ComponentsTable, _extends({}, props, {
|
|
277
|
-
components,
|
|
278
|
-
sort
|
|
279
|
-
}));
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
const mainLabel = getComponentName(main);
|
|
283
|
-
return /*#__PURE__*/React.createElement(ComponentsTable, _extends({}, props, {
|
|
284
|
-
components: Object.assign({
|
|
285
|
-
[mainLabel]: main
|
|
286
|
-
}, subcomponents),
|
|
287
|
-
sort: sort
|
|
288
|
-
}));
|
|
289
|
-
};
|
|
290
|
-
ArgsTable.defaultProps = {
|
|
291
|
-
of: CURRENT_SELECTION
|
|
292
|
-
};
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
const _excluded = ["withSource", "mdxSource", "children"];
|
|
2
|
-
|
|
3
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
4
|
-
|
|
5
|
-
import React, { useContext } from 'react';
|
|
6
|
-
import { MDXProvider } from '@mdx-js/react';
|
|
7
|
-
import { toId, storyNameFromExport } from '@storybook/csf';
|
|
8
|
-
import { resetComponents, Preview as PurePreview, PreviewSkeleton } from '@storybook/components';
|
|
9
|
-
import { DocsContext } from './DocsContext';
|
|
10
|
-
import { SourceContext } from './SourceContainer';
|
|
11
|
-
import { getSourceProps, SourceState } from './Source';
|
|
12
|
-
import { useStories } from './useStory';
|
|
13
|
-
import { CURRENT_SELECTION } from './types';
|
|
14
|
-
export { SourceState };
|
|
15
|
-
|
|
16
|
-
const getPreviewProps = (_ref, docsContext, sourceContext) => {
|
|
17
|
-
let {
|
|
18
|
-
withSource,
|
|
19
|
-
mdxSource,
|
|
20
|
-
children
|
|
21
|
-
} = _ref,
|
|
22
|
-
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
23
|
-
|
|
24
|
-
const {
|
|
25
|
-
mdxComponentAnnotations,
|
|
26
|
-
mdxStoryNameToKey
|
|
27
|
-
} = docsContext;
|
|
28
|
-
let sourceState = withSource;
|
|
29
|
-
let isLoading = false;
|
|
30
|
-
|
|
31
|
-
if (sourceState === SourceState.NONE) {
|
|
32
|
-
return {
|
|
33
|
-
isLoading,
|
|
34
|
-
previewProps: props
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (mdxSource) {
|
|
39
|
-
return {
|
|
40
|
-
isLoading,
|
|
41
|
-
previewProps: Object.assign({}, props, {
|
|
42
|
-
withSource: getSourceProps({
|
|
43
|
-
code: decodeURI(mdxSource)
|
|
44
|
-
}, docsContext, sourceContext)
|
|
45
|
-
})
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const childArray = Array.isArray(children) ? children : [children];
|
|
50
|
-
const storyChildren = childArray.filter(c => c.props && (c.props.id || c.props.name));
|
|
51
|
-
const targetIds = storyChildren.map(s => s.props.id || toId(mdxComponentAnnotations.id || mdxComponentAnnotations.title, storyNameFromExport(mdxStoryNameToKey[s.props.name])));
|
|
52
|
-
const sourceProps = getSourceProps({
|
|
53
|
-
ids: targetIds
|
|
54
|
-
}, docsContext, sourceContext);
|
|
55
|
-
if (!sourceState) sourceState = sourceProps.state;
|
|
56
|
-
const storyIds = targetIds.map(targetId => targetId === CURRENT_SELECTION ? docsContext.id : targetId);
|
|
57
|
-
const stories = useStories(storyIds, docsContext);
|
|
58
|
-
isLoading = stories.some(s => !s);
|
|
59
|
-
return {
|
|
60
|
-
isLoading,
|
|
61
|
-
previewProps: Object.assign({}, props, {
|
|
62
|
-
// pass through columns etc.
|
|
63
|
-
withSource: sourceProps,
|
|
64
|
-
isExpanded: sourceState === SourceState.OPEN
|
|
65
|
-
})
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export const Canvas = props => {
|
|
70
|
-
const docsContext = useContext(DocsContext);
|
|
71
|
-
const sourceContext = useContext(SourceContext);
|
|
72
|
-
const {
|
|
73
|
-
isLoading,
|
|
74
|
-
previewProps
|
|
75
|
-
} = getPreviewProps(props, docsContext, sourceContext);
|
|
76
|
-
const {
|
|
77
|
-
children
|
|
78
|
-
} = props;
|
|
79
|
-
if (isLoading) return /*#__PURE__*/React.createElement(PreviewSkeleton, null);
|
|
80
|
-
return /*#__PURE__*/React.createElement(MDXProvider, {
|
|
81
|
-
components: resetComponents
|
|
82
|
-
}, /*#__PURE__*/React.createElement(PurePreview, previewProps, children));
|
|
83
|
-
};
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import React, { useContext } from 'react';
|
|
2
|
-
import { Description } from '@storybook/components';
|
|
3
|
-
import { str } from '@storybook/docs-tools';
|
|
4
|
-
import { DocsContext } from './DocsContext';
|
|
5
|
-
import { CURRENT_SELECTION } from './types';
|
|
6
|
-
export let DescriptionType;
|
|
7
|
-
|
|
8
|
-
(function (DescriptionType) {
|
|
9
|
-
DescriptionType["INFO"] = "info";
|
|
10
|
-
DescriptionType["NOTES"] = "notes";
|
|
11
|
-
DescriptionType["DOCGEN"] = "docgen";
|
|
12
|
-
DescriptionType["LEGACY_5_2"] = "legacy-5.2";
|
|
13
|
-
DescriptionType["AUTO"] = "auto";
|
|
14
|
-
})(DescriptionType || (DescriptionType = {}));
|
|
15
|
-
|
|
16
|
-
const getNotes = notes => notes && (typeof notes === 'string' ? notes : str(notes.markdown) || str(notes.text));
|
|
17
|
-
|
|
18
|
-
const getInfo = info => info && (typeof info === 'string' ? info : str(info.text));
|
|
19
|
-
|
|
20
|
-
const noDescription = component => null;
|
|
21
|
-
|
|
22
|
-
export const getDescriptionProps = ({
|
|
23
|
-
of,
|
|
24
|
-
type,
|
|
25
|
-
markdown,
|
|
26
|
-
children
|
|
27
|
-
}, {
|
|
28
|
-
id,
|
|
29
|
-
storyById
|
|
30
|
-
}) => {
|
|
31
|
-
const {
|
|
32
|
-
component,
|
|
33
|
-
parameters
|
|
34
|
-
} = storyById(id);
|
|
35
|
-
|
|
36
|
-
if (children || markdown) {
|
|
37
|
-
return {
|
|
38
|
-
markdown: children || markdown
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const {
|
|
43
|
-
notes,
|
|
44
|
-
info,
|
|
45
|
-
docs
|
|
46
|
-
} = parameters;
|
|
47
|
-
const {
|
|
48
|
-
extractComponentDescription = noDescription,
|
|
49
|
-
description
|
|
50
|
-
} = docs || {};
|
|
51
|
-
const target = of === CURRENT_SELECTION ? component : of; // override component description
|
|
52
|
-
|
|
53
|
-
const componentDescriptionParameter = description === null || description === void 0 ? void 0 : description.component;
|
|
54
|
-
|
|
55
|
-
if (componentDescriptionParameter) {
|
|
56
|
-
return {
|
|
57
|
-
markdown: componentDescriptionParameter
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
switch (type) {
|
|
62
|
-
case DescriptionType.INFO:
|
|
63
|
-
return {
|
|
64
|
-
markdown: getInfo(info)
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
case DescriptionType.NOTES:
|
|
68
|
-
return {
|
|
69
|
-
markdown: getNotes(notes)
|
|
70
|
-
};
|
|
71
|
-
// FIXME: remove in 6.0
|
|
72
|
-
|
|
73
|
-
case DescriptionType.LEGACY_5_2:
|
|
74
|
-
return {
|
|
75
|
-
markdown: `
|
|
76
|
-
${getNotes(notes) || getInfo(info) || ''}
|
|
77
|
-
|
|
78
|
-
${extractComponentDescription(target) || ''}
|
|
79
|
-
`.trim()
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
case DescriptionType.DOCGEN:
|
|
83
|
-
case DescriptionType.AUTO:
|
|
84
|
-
default:
|
|
85
|
-
return {
|
|
86
|
-
markdown: extractComponentDescription(target, Object.assign({
|
|
87
|
-
component
|
|
88
|
-
}, parameters))
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
const DescriptionContainer = props => {
|
|
94
|
-
const context = useContext(DocsContext);
|
|
95
|
-
const {
|
|
96
|
-
markdown
|
|
97
|
-
} = getDescriptionProps(props, context);
|
|
98
|
-
return markdown ? /*#__PURE__*/React.createElement(Description, {
|
|
99
|
-
markdown: markdown
|
|
100
|
-
}) : null;
|
|
101
|
-
}; // since we are in the docs blocks, assume default description if for primary component story
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
DescriptionContainer.defaultProps = {
|
|
105
|
-
of: '.'
|
|
106
|
-
};
|
|
107
|
-
export { DescriptionContainer as Description };
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import React, { useEffect } from 'react';
|
|
2
|
-
import global from 'global';
|
|
3
|
-
import deprecate from 'util-deprecate';
|
|
4
|
-
import dedent from 'ts-dedent';
|
|
5
|
-
import { MDXProvider } from '@mdx-js/react';
|
|
6
|
-
import { ThemeProvider, ensure as ensureTheme } from '@storybook/theming';
|
|
7
|
-
import { DocsWrapper, DocsContent, components as htmlComponents } from '@storybook/components';
|
|
8
|
-
import { DocsContext } from './DocsContext';
|
|
9
|
-
import { anchorBlockIdFromId } from './Anchor';
|
|
10
|
-
import { storyBlockIdFromId } from './Story';
|
|
11
|
-
import { SourceContainer } from './SourceContainer';
|
|
12
|
-
import { CodeOrSourceMdx, AnchorMdx, HeadersMdx } from './mdx';
|
|
13
|
-
import { scrollToElement } from './utils';
|
|
14
|
-
const {
|
|
15
|
-
document,
|
|
16
|
-
window: globalWindow
|
|
17
|
-
} = global;
|
|
18
|
-
const defaultComponents = Object.assign({}, htmlComponents, {
|
|
19
|
-
code: CodeOrSourceMdx,
|
|
20
|
-
a: AnchorMdx
|
|
21
|
-
}, HeadersMdx);
|
|
22
|
-
const warnOptionsTheme = deprecate(() => {}, dedent`
|
|
23
|
-
Deprecated parameter: options.theme => docs.theme
|
|
24
|
-
|
|
25
|
-
https://github.com/storybookjs/storybook/blob/next/addons/docs/docs/theming.md#storybook-theming
|
|
26
|
-
`);
|
|
27
|
-
export const DocsContainer = ({
|
|
28
|
-
context,
|
|
29
|
-
children
|
|
30
|
-
}) => {
|
|
31
|
-
const {
|
|
32
|
-
id: storyId,
|
|
33
|
-
storyById
|
|
34
|
-
} = context;
|
|
35
|
-
const {
|
|
36
|
-
parameters: {
|
|
37
|
-
options = {},
|
|
38
|
-
docs = {}
|
|
39
|
-
}
|
|
40
|
-
} = storyById(storyId);
|
|
41
|
-
let themeVars = docs.theme;
|
|
42
|
-
|
|
43
|
-
if (!themeVars && options.theme) {
|
|
44
|
-
warnOptionsTheme();
|
|
45
|
-
themeVars = options.theme;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const theme = ensureTheme(themeVars);
|
|
49
|
-
const allComponents = Object.assign({}, defaultComponents, docs.components);
|
|
50
|
-
useEffect(() => {
|
|
51
|
-
let url;
|
|
52
|
-
|
|
53
|
-
try {
|
|
54
|
-
url = new URL(globalWindow.parent.location);
|
|
55
|
-
} catch (err) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (url.hash) {
|
|
60
|
-
const element = document.getElementById(url.hash.substring(1));
|
|
61
|
-
|
|
62
|
-
if (element) {
|
|
63
|
-
// Introducing a delay to ensure scrolling works when it's a full refresh.
|
|
64
|
-
setTimeout(() => {
|
|
65
|
-
scrollToElement(element);
|
|
66
|
-
}, 200);
|
|
67
|
-
}
|
|
68
|
-
} else {
|
|
69
|
-
const element = document.getElementById(anchorBlockIdFromId(storyId)) || document.getElementById(storyBlockIdFromId(storyId));
|
|
70
|
-
|
|
71
|
-
if (element) {
|
|
72
|
-
const allStories = element.parentElement.querySelectorAll('[id|="anchor-"]');
|
|
73
|
-
let scrollTarget = element;
|
|
74
|
-
|
|
75
|
-
if (allStories && allStories[0] === element) {
|
|
76
|
-
// Include content above first story
|
|
77
|
-
scrollTarget = document.getElementById('docs-root');
|
|
78
|
-
} // Introducing a delay to ensure scrolling works when it's a full refresh.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
setTimeout(() => {
|
|
82
|
-
scrollToElement(scrollTarget, 'start');
|
|
83
|
-
}, 200);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}, [storyId]);
|
|
87
|
-
return /*#__PURE__*/React.createElement(DocsContext.Provider, {
|
|
88
|
-
value: context
|
|
89
|
-
}, /*#__PURE__*/React.createElement(SourceContainer, null, /*#__PURE__*/React.createElement(ThemeProvider, {
|
|
90
|
-
theme: theme
|
|
91
|
-
}, /*#__PURE__*/React.createElement(MDXProvider, {
|
|
92
|
-
components: allComponents
|
|
93
|
-
}, /*#__PURE__*/React.createElement(DocsWrapper, {
|
|
94
|
-
className: "sbdocs sbdocs-wrapper"
|
|
95
|
-
}, /*#__PURE__*/React.createElement(DocsContent, {
|
|
96
|
-
className: "sbdocs sbdocs-content"
|
|
97
|
-
}, children))))));
|
|
98
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { createContext } from 'react';
|
|
2
|
-
import { window as globalWindow } from 'global';
|
|
3
|
-
|
|
4
|
-
// We add DocsContext to window. The reason is that in case DocsContext.ts is
|
|
5
|
-
// imported multiple times (maybe once directly, and another time from a minified bundle)
|
|
6
|
-
// we will have multiple DocsContext definitions - leading to lost context in
|
|
7
|
-
// the React component tree.
|
|
8
|
-
// This was specifically a problem with the Vite builder.
|
|
9
|
-
|
|
10
|
-
/* eslint-disable no-underscore-dangle */
|
|
11
|
-
if (globalWindow && globalWindow.__DOCS_CONTEXT__ === undefined) {
|
|
12
|
-
globalWindow.__DOCS_CONTEXT__ = /*#__PURE__*/createContext({});
|
|
13
|
-
globalWindow.__DOCS_CONTEXT__.displayName = 'DocsContext';
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const DocsContext = globalWindow ? globalWindow.__DOCS_CONTEXT__ : /*#__PURE__*/createContext({});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Title } from './Title';
|
|
3
|
-
import { Subtitle } from './Subtitle';
|
|
4
|
-
import { Description } from './Description';
|
|
5
|
-
import { Primary } from './Primary';
|
|
6
|
-
import { PRIMARY_STORY } from './types';
|
|
7
|
-
import { ArgsTable } from './ArgsTable';
|
|
8
|
-
import { Stories } from './Stories';
|
|
9
|
-
export const DocsPage = () => /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Title, null), /*#__PURE__*/React.createElement(Subtitle, null), /*#__PURE__*/React.createElement(Description, null), /*#__PURE__*/React.createElement(Primary, null), /*#__PURE__*/React.createElement(ArgsTable, {
|
|
10
|
-
story: PRIMARY_STORY
|
|
11
|
-
}), /*#__PURE__*/React.createElement(Stories, null));
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import deprecate from 'util-deprecate';
|
|
3
|
-
import dedent from 'ts-dedent';
|
|
4
|
-
import { Subheading } from './Subheading';
|
|
5
|
-
import { Anchor } from './Anchor';
|
|
6
|
-
import { Description } from './Description';
|
|
7
|
-
import { Story } from './Story';
|
|
8
|
-
import { Canvas } from './Canvas';
|
|
9
|
-
const warnStoryDescription = deprecate(() => {}, dedent`
|
|
10
|
-
Deprecated parameter: docs.storyDescription => docs.description.story
|
|
11
|
-
|
|
12
|
-
https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#docs-description-parameter
|
|
13
|
-
`);
|
|
14
|
-
export const DocsStory = ({
|
|
15
|
-
id,
|
|
16
|
-
name,
|
|
17
|
-
expanded = true,
|
|
18
|
-
withToolbar = false,
|
|
19
|
-
parameters = {}
|
|
20
|
-
}) => {
|
|
21
|
-
let description;
|
|
22
|
-
const {
|
|
23
|
-
docs
|
|
24
|
-
} = parameters;
|
|
25
|
-
|
|
26
|
-
if (expanded && docs) {
|
|
27
|
-
var _docs$description;
|
|
28
|
-
|
|
29
|
-
description = (_docs$description = docs.description) === null || _docs$description === void 0 ? void 0 : _docs$description.story;
|
|
30
|
-
|
|
31
|
-
if (!description) {
|
|
32
|
-
description = docs.storyDescription;
|
|
33
|
-
if (description) warnStoryDescription();
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const subheading = expanded && name;
|
|
38
|
-
return /*#__PURE__*/React.createElement(Anchor, {
|
|
39
|
-
storyId: id
|
|
40
|
-
}, subheading && /*#__PURE__*/React.createElement(Subheading, null, subheading), description && /*#__PURE__*/React.createElement(Description, {
|
|
41
|
-
markdown: description
|
|
42
|
-
}), /*#__PURE__*/React.createElement(Canvas, {
|
|
43
|
-
withToolbar: withToolbar
|
|
44
|
-
}, /*#__PURE__*/React.createElement(Story, {
|
|
45
|
-
id: id,
|
|
46
|
-
parameters: parameters
|
|
47
|
-
})));
|
|
48
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { H2 } from '@storybook/components';
|
|
3
|
-
import { HeaderMdx } from './mdx';
|
|
4
|
-
export const Heading = ({
|
|
5
|
-
children,
|
|
6
|
-
disableAnchor
|
|
7
|
-
}) => {
|
|
8
|
-
if (disableAnchor || typeof children !== 'string') {
|
|
9
|
-
return /*#__PURE__*/React.createElement(H2, null, children);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const tagID = children.toLowerCase().replace(/[^a-z0-9]/gi, '-');
|
|
13
|
-
return /*#__PURE__*/React.createElement(HeaderMdx, {
|
|
14
|
-
as: "h2",
|
|
15
|
-
id: tagID
|
|
16
|
-
}, children);
|
|
17
|
-
};
|