@storybook/addon-docs 6.5.7-alpha.0 → 7.0.0-alpha.1
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,36 +1,4 @@
|
|
|
1
|
-
function _extends() { _extends = Object.assign
|
|
2
|
-
|
|
3
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
4
|
-
|
|
5
|
-
import "core-js/modules/es.array.includes.js";
|
|
6
|
-
import "core-js/modules/es.string.includes.js";
|
|
7
|
-
import "core-js/modules/es.object.assign.js";
|
|
8
|
-
import "core-js/modules/es.array.sort.js";
|
|
9
|
-
import "core-js/modules/es.array.find.js";
|
|
10
|
-
import "core-js/modules/es.object.to-string.js";
|
|
11
|
-
import "core-js/modules/es.object.values.js";
|
|
12
|
-
import "core-js/modules/es.symbol.js";
|
|
13
|
-
import "core-js/modules/es.symbol.description.js";
|
|
14
|
-
import "core-js/modules/es.symbol.iterator.js";
|
|
15
|
-
import "core-js/modules/es.array.iterator.js";
|
|
16
|
-
import "core-js/modules/es.string.iterator.js";
|
|
17
|
-
import "core-js/modules/web.dom-collections.iterator.js";
|
|
18
|
-
import "core-js/modules/es.array.slice.js";
|
|
19
|
-
import "core-js/modules/es.function.name.js";
|
|
20
|
-
import "core-js/modules/es.array.from.js";
|
|
21
|
-
import "core-js/modules/es.regexp.exec.js";
|
|
22
|
-
|
|
23
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
24
|
-
|
|
25
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
26
|
-
|
|
27
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
28
|
-
|
|
29
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
30
|
-
|
|
31
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
32
|
-
|
|
33
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
1
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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); }
|
|
34
2
|
|
|
35
3
|
import React, { useContext, useEffect, useState, useCallback } from 'react';
|
|
36
4
|
import mapValues from 'lodash/mapValues';
|
|
@@ -44,111 +12,93 @@ import { getComponentName } from './utils';
|
|
|
44
12
|
import { lookupStoryId } from './Story';
|
|
45
13
|
import { useStory } from './useStory';
|
|
46
14
|
|
|
47
|
-
|
|
48
|
-
|
|
15
|
+
const getContext = (storyId, context) => {
|
|
16
|
+
const story = context.storyById(storyId);
|
|
49
17
|
|
|
50
18
|
if (!story) {
|
|
51
|
-
throw new Error(
|
|
19
|
+
throw new Error(`Unknown story: ${storyId}`);
|
|
52
20
|
}
|
|
53
21
|
|
|
54
22
|
return context.getStoryContext(story);
|
|
55
23
|
};
|
|
56
24
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
args = _useState2[0],
|
|
64
|
-
setArgs = _useState2[1];
|
|
65
|
-
|
|
66
|
-
useEffect(function () {
|
|
67
|
-
var cb = function cb(changed) {
|
|
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 => {
|
|
68
31
|
if (changed.storyId === storyId) {
|
|
69
32
|
setArgs(changed.args);
|
|
70
33
|
}
|
|
71
34
|
};
|
|
72
35
|
|
|
73
36
|
channel.on(Events.STORY_ARGS_UPDATED, cb);
|
|
74
|
-
return
|
|
75
|
-
return channel.off(Events.STORY_ARGS_UPDATED, cb);
|
|
76
|
-
};
|
|
77
|
-
}, [storyId]);
|
|
78
|
-
var updateArgs = useCallback(function (updatedArgs) {
|
|
79
|
-
return channel.emit(Events.UPDATE_STORY_ARGS, {
|
|
80
|
-
storyId: storyId,
|
|
81
|
-
updatedArgs: updatedArgs
|
|
82
|
-
});
|
|
83
|
-
}, [storyId]);
|
|
84
|
-
var resetArgs = useCallback(function (argNames) {
|
|
85
|
-
return channel.emit(Events.RESET_STORY_ARGS, {
|
|
86
|
-
storyId: storyId,
|
|
87
|
-
argNames: argNames
|
|
88
|
-
});
|
|
37
|
+
return () => channel.off(Events.STORY_ARGS_UPDATED, cb);
|
|
89
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]);
|
|
90
47
|
return [args, updateArgs, resetArgs];
|
|
91
48
|
};
|
|
92
49
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
globals = _useState4[0],
|
|
100
|
-
setGlobals = _useState4[1];
|
|
101
|
-
|
|
102
|
-
useEffect(function () {
|
|
103
|
-
var cb = function cb(changed) {
|
|
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 => {
|
|
104
56
|
setGlobals(changed.globals);
|
|
105
57
|
};
|
|
106
58
|
|
|
107
59
|
channel.on(Events.GLOBALS_UPDATED, cb);
|
|
108
|
-
return
|
|
109
|
-
return channel.off(Events.GLOBALS_UPDATED, cb);
|
|
110
|
-
};
|
|
60
|
+
return () => channel.off(Events.GLOBALS_UPDATED, cb);
|
|
111
61
|
}, []);
|
|
112
62
|
return [globals];
|
|
113
63
|
};
|
|
114
64
|
|
|
115
|
-
export
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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 || {};
|
|
124
75
|
|
|
125
76
|
if (!extractArgTypes) {
|
|
126
77
|
throw new Error(ArgsTableError.ARGS_UNSUPPORTED);
|
|
127
78
|
}
|
|
128
79
|
|
|
129
|
-
|
|
80
|
+
let argTypes = extractArgTypes(component);
|
|
130
81
|
argTypes = filterArgTypes(argTypes, include, exclude);
|
|
131
82
|
return argTypes;
|
|
132
83
|
};
|
|
133
84
|
|
|
134
|
-
|
|
85
|
+
const isShortcut = value => {
|
|
135
86
|
return value && [CURRENT_SELECTION, PRIMARY_STORY].includes(value);
|
|
136
87
|
};
|
|
137
88
|
|
|
138
|
-
export
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
component = _storyById2.component;
|
|
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);
|
|
152
102
|
|
|
153
103
|
if (isShortcut(of) || isShortcut(story)) {
|
|
154
104
|
return component || null;
|
|
@@ -161,29 +111,29 @@ export var getComponent = function getComponent() {
|
|
|
161
111
|
return of;
|
|
162
112
|
};
|
|
163
113
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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;
|
|
184
134
|
|
|
185
135
|
try {
|
|
186
|
-
|
|
136
|
+
let storyId;
|
|
187
137
|
|
|
188
138
|
switch (storyName) {
|
|
189
139
|
case CURRENT_SELECTION:
|
|
@@ -194,7 +144,7 @@ export var StoryTable = function StoryTable(props) {
|
|
|
194
144
|
|
|
195
145
|
case PRIMARY_STORY:
|
|
196
146
|
{
|
|
197
|
-
|
|
147
|
+
const primaryStory = componentStories()[0];
|
|
198
148
|
storyId = primaryStory.id;
|
|
199
149
|
break;
|
|
200
150
|
}
|
|
@@ -205,38 +155,28 @@ export var StoryTable = function StoryTable(props) {
|
|
|
205
155
|
}
|
|
206
156
|
}
|
|
207
157
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
var _useArgs = useArgs(storyId, context),
|
|
211
|
-
_useArgs2 = _slicedToArray(_useArgs, 3),
|
|
212
|
-
args = _useArgs2[0],
|
|
213
|
-
updateArgs = _useArgs2[1],
|
|
214
|
-
resetArgs = _useArgs2[2];
|
|
215
|
-
|
|
216
|
-
var _useGlobals = useGlobals(storyId, context),
|
|
217
|
-
_useGlobals2 = _slicedToArray(_useGlobals, 1),
|
|
218
|
-
globals = _useGlobals2[0];
|
|
158
|
+
const story = useStory(storyId, context); // eslint-disable-next-line prefer-const
|
|
219
159
|
|
|
160
|
+
let [args, updateArgs, resetArgs] = useArgs(storyId, context);
|
|
161
|
+
const [globals] = useGlobals(storyId, context);
|
|
220
162
|
if (!story) return /*#__PURE__*/React.createElement(PureArgsTable, {
|
|
221
163
|
isLoading: true,
|
|
222
164
|
updateArgs: updateArgs,
|
|
223
165
|
resetArgs: resetArgs
|
|
224
166
|
});
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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
|
|
236
178
|
|
|
237
|
-
|
|
238
|
-
return !!(v !== null && v !== void 0 && v.control);
|
|
239
|
-
});
|
|
179
|
+
const storyHasArgsWithControls = argTypes && Object.values(argTypes).find(v => !!v?.control);
|
|
240
180
|
|
|
241
181
|
if (!storyHasArgsWithControls) {
|
|
242
182
|
updateArgs = null;
|
|
@@ -245,12 +185,14 @@ export var StoryTable = function StoryTable(props) {
|
|
|
245
185
|
}
|
|
246
186
|
|
|
247
187
|
if (component && (!storyHasArgsWithControls || showComponent)) {
|
|
248
|
-
tabs = addComponentTabs(tabs,
|
|
188
|
+
tabs = addComponentTabs(tabs, {
|
|
189
|
+
[mainLabel]: component
|
|
190
|
+
}, context, include, exclude);
|
|
249
191
|
}
|
|
250
192
|
|
|
251
193
|
if (subcomponents) {
|
|
252
194
|
if (Array.isArray(subcomponents)) {
|
|
253
|
-
throw new Error(
|
|
195
|
+
throw new Error(`Unexpected subcomponents array. Expected an object whose keys are tab labels and whose values are components.`);
|
|
254
196
|
}
|
|
255
197
|
|
|
256
198
|
tabs = addComponentTabs(tabs, subcomponents, context, include, exclude);
|
|
@@ -266,47 +208,54 @@ export var StoryTable = function StoryTable(props) {
|
|
|
266
208
|
});
|
|
267
209
|
}
|
|
268
210
|
};
|
|
269
|
-
export
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
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);
|
|
276
220
|
return /*#__PURE__*/React.createElement(TabbedArgsTable, {
|
|
277
221
|
tabs: tabs,
|
|
278
222
|
sort: sort
|
|
279
223
|
});
|
|
280
224
|
};
|
|
281
|
-
export
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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?.sort;
|
|
247
|
+
const main = getComponent(props, context);
|
|
299
248
|
|
|
300
249
|
if (storyName) {
|
|
301
250
|
return /*#__PURE__*/React.createElement(StoryTable, _extends({}, props, {
|
|
302
251
|
component: main,
|
|
303
|
-
subcomponents
|
|
304
|
-
sort
|
|
252
|
+
subcomponents,
|
|
253
|
+
sort
|
|
305
254
|
}));
|
|
306
255
|
}
|
|
307
256
|
|
|
308
257
|
if (!components && !subcomponents) {
|
|
309
|
-
|
|
258
|
+
let mainProps;
|
|
310
259
|
|
|
311
260
|
try {
|
|
312
261
|
mainProps = {
|
|
@@ -325,14 +274,16 @@ export var ArgsTable = function ArgsTable(props) {
|
|
|
325
274
|
|
|
326
275
|
if (components) {
|
|
327
276
|
return /*#__PURE__*/React.createElement(ComponentsTable, _extends({}, props, {
|
|
328
|
-
components
|
|
329
|
-
sort
|
|
277
|
+
components,
|
|
278
|
+
sort
|
|
330
279
|
}));
|
|
331
280
|
}
|
|
332
281
|
|
|
333
|
-
|
|
282
|
+
const mainLabel = getComponentName(main);
|
|
334
283
|
return /*#__PURE__*/React.createElement(ComponentsTable, _extends({}, props, {
|
|
335
|
-
components: Object.assign(
|
|
284
|
+
components: Object.assign({
|
|
285
|
+
[mainLabel]: main
|
|
286
|
+
}, subcomponents),
|
|
336
287
|
sort: sort
|
|
337
288
|
}));
|
|
338
289
|
};
|
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import "core-js/modules/es.symbol.js";
|
|
3
|
-
var _excluded = ["withSource", "mdxSource", "children"];
|
|
4
|
-
import "core-js/modules/es.object.assign.js";
|
|
5
|
-
import "core-js/modules/es.array.filter.js";
|
|
6
|
-
import "core-js/modules/es.object.to-string.js";
|
|
7
|
-
import "core-js/modules/es.function.name.js";
|
|
8
|
-
import "core-js/modules/es.array.map.js";
|
|
9
|
-
|
|
10
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
1
|
+
const _excluded = ["withSource", "mdxSource", "children"];
|
|
11
2
|
|
|
12
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; }
|
|
13
4
|
|
|
@@ -22,27 +13,31 @@ import { useStories } from './useStory';
|
|
|
22
13
|
import { CURRENT_SELECTION } from './types';
|
|
23
14
|
export { SourceState };
|
|
24
15
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
16
|
+
const getPreviewProps = (_ref, docsContext, sourceContext) => {
|
|
17
|
+
let {
|
|
18
|
+
withSource,
|
|
19
|
+
mdxSource,
|
|
20
|
+
children
|
|
21
|
+
} = _ref,
|
|
22
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
30
23
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
24
|
+
const {
|
|
25
|
+
mdxComponentAnnotations,
|
|
26
|
+
mdxStoryNameToKey
|
|
27
|
+
} = docsContext;
|
|
28
|
+
let sourceState = withSource;
|
|
29
|
+
let isLoading = false;
|
|
35
30
|
|
|
36
31
|
if (sourceState === SourceState.NONE) {
|
|
37
32
|
return {
|
|
38
|
-
isLoading
|
|
33
|
+
isLoading,
|
|
39
34
|
previewProps: props
|
|
40
35
|
};
|
|
41
36
|
}
|
|
42
37
|
|
|
43
38
|
if (mdxSource) {
|
|
44
39
|
return {
|
|
45
|
-
isLoading
|
|
40
|
+
isLoading,
|
|
46
41
|
previewProps: Object.assign({}, props, {
|
|
47
42
|
withSource: getSourceProps({
|
|
48
43
|
code: decodeURI(mdxSource)
|
|
@@ -51,26 +46,18 @@ var getPreviewProps = function getPreviewProps(_ref, docsContext, sourceContext)
|
|
|
51
46
|
};
|
|
52
47
|
}
|
|
53
48
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
var targetIds = storyChildren.map(function (s) {
|
|
59
|
-
return s.props.id || toId(mdxComponentAnnotations.id || mdxComponentAnnotations.title, storyNameFromExport(mdxStoryNameToKey[s.props.name]));
|
|
60
|
-
});
|
|
61
|
-
var sourceProps = getSourceProps({
|
|
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({
|
|
62
53
|
ids: targetIds
|
|
63
54
|
}, docsContext, sourceContext);
|
|
64
55
|
if (!sourceState) sourceState = sourceProps.state;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
var stories = useStories(storyIds, docsContext);
|
|
69
|
-
isLoading = stories.some(function (s) {
|
|
70
|
-
return !s;
|
|
71
|
-
});
|
|
56
|
+
const storyIds = targetIds.map(targetId => targetId === CURRENT_SELECTION ? docsContext.id : targetId);
|
|
57
|
+
const stories = useStories(storyIds, docsContext);
|
|
58
|
+
isLoading = stories.some(s => !s);
|
|
72
59
|
return {
|
|
73
|
-
isLoading
|
|
60
|
+
isLoading,
|
|
74
61
|
previewProps: Object.assign({}, props, {
|
|
75
62
|
// pass through columns etc.
|
|
76
63
|
withSource: sourceProps,
|
|
@@ -79,15 +66,16 @@ var getPreviewProps = function getPreviewProps(_ref, docsContext, sourceContext)
|
|
|
79
66
|
};
|
|
80
67
|
};
|
|
81
68
|
|
|
82
|
-
export
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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;
|
|
91
79
|
if (isLoading) return /*#__PURE__*/React.createElement(PreviewSkeleton, null);
|
|
92
80
|
return /*#__PURE__*/React.createElement(MDXProvider, {
|
|
93
81
|
components: resetComponents
|