@storybook/addon-docs 6.4.0-beta.3 → 6.4.0-beta.33
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/cjs/blocks/ArgsTable.js +3 -4
- package/dist/cjs/blocks/Canvas.js +2 -1
- package/dist/cjs/blocks/DocsStory.js +2 -1
- package/dist/cjs/blocks/Source.js +1 -1
- package/dist/cjs/blocks/Story.js +65 -30
- package/dist/cjs/blocks/enhanceSource.js +2 -2
- package/dist/cjs/blocks/useStory.js +8 -3
- package/dist/cjs/frameworks/angular/compodoc.js +3 -1
- package/dist/cjs/frameworks/angular/prepareForInline.js +52 -53
- package/dist/cjs/frameworks/angular/sourceDecorator.js +99 -23
- package/dist/cjs/frameworks/common/config.js +87 -3
- package/dist/cjs/frameworks/html/sourceDecorator.js +9 -2
- package/dist/cjs/frameworks/react/react-argtypes.stories.js +2 -2
- package/dist/cjs/frameworks/vue/extractArgTypes.js +106 -15
- package/dist/cjs/frameworks/vue/sourceDecorator.js +80 -33
- package/dist/cjs/frameworks/web-components/custom-elements.js +63 -25
- package/dist/esm/blocks/ArgsTable.js +3 -4
- package/dist/esm/blocks/Canvas.js +3 -2
- package/dist/esm/blocks/DocsStory.js +2 -1
- package/dist/esm/blocks/Source.js +1 -1
- package/dist/esm/blocks/Story.js +63 -27
- package/dist/esm/blocks/enhanceSource.js +7 -1
- package/dist/esm/blocks/useStory.js +8 -3
- package/dist/esm/frameworks/angular/compodoc.js +3 -1
- package/dist/esm/frameworks/angular/prepareForInline.js +46 -50
- package/dist/esm/frameworks/angular/sourceDecorator.js +72 -20
- package/dist/esm/frameworks/common/config.js +60 -3
- package/dist/esm/frameworks/html/sourceDecorator.js +9 -2
- package/dist/esm/frameworks/react/react-argtypes.stories.js +1 -1
- package/dist/esm/frameworks/vue/extractArgTypes.js +97 -14
- package/dist/esm/frameworks/vue/sourceDecorator.js +60 -23
- package/dist/esm/frameworks/web-components/custom-elements.js +60 -24
- package/dist/modern/blocks/ArgsTable.js +3 -5
- package/dist/modern/blocks/Canvas.js +3 -2
- package/dist/modern/blocks/DocsStory.js +2 -1
- package/dist/modern/blocks/Source.js +1 -1
- package/dist/modern/blocks/Story.js +37 -29
- package/dist/modern/blocks/enhanceSource.js +7 -1
- package/dist/modern/blocks/useStory.js +14 -3
- package/dist/modern/frameworks/angular/compodoc.js +3 -1
- package/dist/modern/frameworks/angular/prepareForInline.js +20 -15
- package/dist/modern/frameworks/angular/sourceDecorator.js +33 -20
- package/dist/modern/frameworks/common/config.js +2 -3
- package/dist/modern/frameworks/html/sourceDecorator.js +9 -2
- package/dist/modern/frameworks/react/react-argtypes.stories.js +1 -1
- package/dist/modern/frameworks/vue/extractArgTypes.js +64 -4
- package/dist/modern/frameworks/vue/sourceDecorator.js +14 -9
- package/dist/modern/frameworks/web-components/custom-elements.js +55 -23
- package/dist/ts3.4/blocks/Story.d.ts +1 -1
- package/dist/ts3.4/frameworks/angular/config.d.ts +1 -1
- package/dist/ts3.4/frameworks/angular/prepareForInline.d.ts +1 -1
- package/dist/ts3.4/frameworks/angular/sourceDecorator.d.ts +1 -1
- package/dist/ts3.4/frameworks/common/config.d.ts +2 -2
- package/dist/ts3.4/frameworks/web-components/custom-elements.d.ts +4 -3
- package/dist/ts3.9/blocks/Story.d.ts +1 -1
- package/dist/ts3.9/frameworks/angular/config.d.ts +1 -1
- package/dist/ts3.9/frameworks/angular/prepareForInline.d.ts +1 -1
- package/dist/ts3.9/frameworks/angular/sourceDecorator.d.ts +1 -1
- package/dist/ts3.9/frameworks/common/config.d.ts +2 -2
- package/dist/ts3.9/frameworks/web-components/custom-elements.d.ts +4 -3
- package/package.json +29 -30
|
@@ -1,11 +1,81 @@
|
|
|
1
|
-
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
|
|
3
|
+
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."); }
|
|
4
|
+
|
|
5
|
+
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); }
|
|
6
|
+
|
|
7
|
+
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; }
|
|
8
|
+
|
|
9
|
+
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_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; }
|
|
10
|
+
|
|
11
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
|
+
|
|
13
|
+
import "core-js/modules/es.object.to-string.js";
|
|
14
|
+
import "core-js/modules/es.array.iterator.js";
|
|
15
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
2
16
|
import "core-js/modules/es.function.name.js";
|
|
17
|
+
import "core-js/modules/es.array.join.js";
|
|
18
|
+
import "core-js/modules/es.array.concat.js";
|
|
19
|
+
import "core-js/modules/es.object.assign.js";
|
|
20
|
+
import "core-js/modules/web.dom-collections.for-each.js";
|
|
3
21
|
import "core-js/modules/es.symbol.js";
|
|
4
22
|
import "core-js/modules/es.symbol.description.js";
|
|
5
|
-
import "core-js/modules/es.
|
|
23
|
+
import "core-js/modules/es.symbol.iterator.js";
|
|
24
|
+
import "core-js/modules/es.string.iterator.js";
|
|
25
|
+
import "core-js/modules/es.array.slice.js";
|
|
26
|
+
import "core-js/modules/es.array.from.js";
|
|
6
27
|
import { hasDocgen, extractComponentProps } from '../../lib/docgen';
|
|
7
28
|
import { convert } from '../../lib/convert';
|
|
8
29
|
var SECTIONS = ['props', 'events', 'slots'];
|
|
30
|
+
/**
|
|
31
|
+
* Check if "@values" tag is defined within docgenInfo.
|
|
32
|
+
* If true, then propDef is mutated.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
function isEnum(propDef, docgenInfo) {
|
|
36
|
+
// cast as any, since "values" doesn't exist in DocgenInfo type
|
|
37
|
+
var _ref = docgenInfo,
|
|
38
|
+
type = _ref.type,
|
|
39
|
+
values = _ref.values;
|
|
40
|
+
var matched = Array.isArray(values) && values.length && type.name !== 'enum';
|
|
41
|
+
if (!matched) return false;
|
|
42
|
+
var enumString = values.join(', ');
|
|
43
|
+
var summary = propDef.type.summary;
|
|
44
|
+
summary = summary ? "".concat(summary, ": ").concat(enumString) : enumString;
|
|
45
|
+
Object.assign(propDef.type, Object.assign({}, propDef.type, {
|
|
46
|
+
name: 'enum',
|
|
47
|
+
value: values,
|
|
48
|
+
summary: summary
|
|
49
|
+
}));
|
|
50
|
+
return propDef;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @returns {Array} result
|
|
54
|
+
* @returns {PropDef} result.def - propDef
|
|
55
|
+
* @returns {boolean} result.isChanged - flag whether propDef is mutated or not.
|
|
56
|
+
* this is needed to prevent sbType from performing convert(docgenInfo).
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
function verifyPropDef(propDef, docgenInfo) {
|
|
61
|
+
var def = propDef;
|
|
62
|
+
var isChanged = false; // another callback can be added here.
|
|
63
|
+
// callback is mutually exclusive from each other.
|
|
64
|
+
|
|
65
|
+
var callbacks = [isEnum];
|
|
66
|
+
|
|
67
|
+
for (var i = 0, len = callbacks.length; i < len; i += 1) {
|
|
68
|
+
var matched = callbacks[i](propDef, docgenInfo);
|
|
69
|
+
|
|
70
|
+
if (matched) {
|
|
71
|
+
def = matched;
|
|
72
|
+
isChanged = true;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return [def, isChanged];
|
|
77
|
+
}
|
|
78
|
+
|
|
9
79
|
export var extractArgTypes = function extractArgTypes(component) {
|
|
10
80
|
if (!hasDocgen(component)) {
|
|
11
81
|
return null;
|
|
@@ -14,18 +84,31 @@ export var extractArgTypes = function extractArgTypes(component) {
|
|
|
14
84
|
var results = {};
|
|
15
85
|
SECTIONS.forEach(function (section) {
|
|
16
86
|
var props = extractComponentProps(component, section);
|
|
17
|
-
props.forEach(function (
|
|
18
|
-
var propDef =
|
|
19
|
-
docgenInfo =
|
|
20
|
-
jsDocTags =
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
87
|
+
props.forEach(function (_ref2) {
|
|
88
|
+
var propDef = _ref2.propDef,
|
|
89
|
+
docgenInfo = _ref2.docgenInfo,
|
|
90
|
+
jsDocTags = _ref2.jsDocTags;
|
|
91
|
+
|
|
92
|
+
var _verifyPropDef = verifyPropDef(propDef, docgenInfo),
|
|
93
|
+
_verifyPropDef2 = _slicedToArray(_verifyPropDef, 2),
|
|
94
|
+
result = _verifyPropDef2[0],
|
|
95
|
+
isPropDefChanged = _verifyPropDef2[1];
|
|
96
|
+
|
|
97
|
+
var name = result.name,
|
|
98
|
+
type = result.type,
|
|
99
|
+
description = result.description,
|
|
100
|
+
defaultSummary = result.defaultValue,
|
|
101
|
+
required = result.required;
|
|
102
|
+
var sbType;
|
|
103
|
+
|
|
104
|
+
if (isPropDefChanged) {
|
|
105
|
+
sbType = type;
|
|
106
|
+
} else {
|
|
107
|
+
sbType = section === 'props' ? convert(docgenInfo) : {
|
|
108
|
+
name: 'void'
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
29
112
|
results[name] = {
|
|
30
113
|
name: name,
|
|
31
114
|
description: description,
|
|
@@ -20,6 +20,9 @@ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToAr
|
|
|
20
20
|
|
|
21
21
|
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; }
|
|
22
22
|
|
|
23
|
+
import "regenerator-runtime/runtime.js";
|
|
24
|
+
import "core-js/modules/es.promise.js";
|
|
25
|
+
import "core-js/modules/es.object.to-string.js";
|
|
23
26
|
import "core-js/modules/es.array.join.js";
|
|
24
27
|
import "core-js/modules/es.array.filter.js";
|
|
25
28
|
import "core-js/modules/es.array.map.js";
|
|
@@ -33,7 +36,6 @@ import "core-js/modules/es.array.includes.js";
|
|
|
33
36
|
import "core-js/modules/es.string.includes.js";
|
|
34
37
|
import "core-js/modules/es.symbol.js";
|
|
35
38
|
import "core-js/modules/es.symbol.description.js";
|
|
36
|
-
import "core-js/modules/es.object.to-string.js";
|
|
37
39
|
import "core-js/modules/es.symbol.iterator.js";
|
|
38
40
|
import "core-js/modules/es.string.iterator.js";
|
|
39
41
|
import "core-js/modules/es.array.iterator.js";
|
|
@@ -42,11 +44,13 @@ import "core-js/modules/es.array.from.js";
|
|
|
42
44
|
import "core-js/modules/es.array.slice.js";
|
|
43
45
|
import "core-js/modules/es.function.name.js";
|
|
44
46
|
|
|
47
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
48
|
+
|
|
49
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
50
|
+
|
|
45
51
|
/* eslint no-underscore-dangle: ["error", { "allow": ["_vnode"] }] */
|
|
46
52
|
import { addons } from '@storybook/addons';
|
|
47
53
|
import { logger } from '@storybook/client-logger';
|
|
48
|
-
import prettier from 'prettier/standalone';
|
|
49
|
-
import prettierHtml from 'prettier/parser-html';
|
|
50
54
|
import { SourceType, SNIPPET_RENDERED } from '../../shared';
|
|
51
55
|
export var skipSourceRender = function skipSourceRender(context) {
|
|
52
56
|
var _context$parameters$d;
|
|
@@ -87,13 +91,46 @@ export var sourceDecorator = function sourceDecorator(storyFn, context) {
|
|
|
87
91
|
try {
|
|
88
92
|
var storyNode = lookupStoryInstance(this, storyComponent);
|
|
89
93
|
var code = vnodeToString(storyNode._vnode);
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
|
|
95
|
+
var emitFormattedTemplate = /*#__PURE__*/function () {
|
|
96
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
97
|
+
var prettier, prettierHtml;
|
|
98
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
99
|
+
while (1) {
|
|
100
|
+
switch (_context.prev = _context.next) {
|
|
101
|
+
case 0:
|
|
102
|
+
_context.next = 2;
|
|
103
|
+
return import('prettier/standalone');
|
|
104
|
+
|
|
105
|
+
case 2:
|
|
106
|
+
prettier = _context.sent;
|
|
107
|
+
_context.next = 5;
|
|
108
|
+
return import('prettier/parser-html');
|
|
109
|
+
|
|
110
|
+
case 5:
|
|
111
|
+
prettierHtml = _context.sent;
|
|
112
|
+
channel.emit(SNIPPET_RENDERED, (context || {}).id, prettier.format("<template>".concat(code, "</template>"), {
|
|
113
|
+
parser: 'vue',
|
|
114
|
+
plugins: [prettierHtml],
|
|
115
|
+
// Because the parsed vnode missing spaces right before/after the surround tag,
|
|
116
|
+
// we always get weird wrapped code without this option.
|
|
117
|
+
htmlWhitespaceSensitivity: 'ignore'
|
|
118
|
+
}));
|
|
119
|
+
|
|
120
|
+
case 7:
|
|
121
|
+
case "end":
|
|
122
|
+
return _context.stop();
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}, _callee);
|
|
126
|
+
}));
|
|
127
|
+
|
|
128
|
+
return function emitFormattedTemplate() {
|
|
129
|
+
return _ref.apply(this, arguments);
|
|
130
|
+
};
|
|
131
|
+
}();
|
|
132
|
+
|
|
133
|
+
emitFormattedTemplate();
|
|
97
134
|
} catch (e) {
|
|
98
135
|
logger.warn("Failed to generate dynamic story source: ".concat(e));
|
|
99
136
|
}
|
|
@@ -104,17 +141,17 @@ export var sourceDecorator = function sourceDecorator(storyFn, context) {
|
|
|
104
141
|
export function vnodeToString(vnode) {
|
|
105
142
|
var _vnode$data, _vnode$componentOptio, _vnode$data2;
|
|
106
143
|
|
|
107
|
-
var attrString = [].concat(_toConsumableArray((_vnode$data = vnode.data) !== null && _vnode$data !== void 0 && _vnode$data.slot ? [['slot', vnode.data.slot]] : []), [['class', stringifyClassAttribute(vnode)]], _toConsumableArray((_vnode$componentOptio = vnode.componentOptions) !== null && _vnode$componentOptio !== void 0 && _vnode$componentOptio.propsData ? Object.entries(vnode.componentOptions.propsData) : []), _toConsumableArray((_vnode$data2 = vnode.data) !== null && _vnode$data2 !== void 0 && _vnode$data2.attrs ? Object.entries(vnode.data.attrs) : [])).filter(function (
|
|
108
|
-
var
|
|
109
|
-
name =
|
|
144
|
+
var attrString = [].concat(_toConsumableArray((_vnode$data = vnode.data) !== null && _vnode$data !== void 0 && _vnode$data.slot ? [['slot', vnode.data.slot]] : []), [['class', stringifyClassAttribute(vnode)]], _toConsumableArray((_vnode$componentOptio = vnode.componentOptions) !== null && _vnode$componentOptio !== void 0 && _vnode$componentOptio.propsData ? Object.entries(vnode.componentOptions.propsData) : []), _toConsumableArray((_vnode$data2 = vnode.data) !== null && _vnode$data2 !== void 0 && _vnode$data2.attrs ? Object.entries(vnode.data.attrs) : [])).filter(function (_ref2, index, list) {
|
|
145
|
+
var _ref3 = _slicedToArray(_ref2, 1),
|
|
146
|
+
name = _ref3[0];
|
|
110
147
|
|
|
111
148
|
return list.findIndex(function (item) {
|
|
112
149
|
return item[0] === name;
|
|
113
150
|
}) === index;
|
|
114
|
-
}).map(function (
|
|
115
|
-
var
|
|
116
|
-
name =
|
|
117
|
-
value =
|
|
151
|
+
}).map(function (_ref4) {
|
|
152
|
+
var _ref5 = _slicedToArray(_ref4, 2),
|
|
153
|
+
name = _ref5[0],
|
|
154
|
+
value = _ref5[1];
|
|
118
155
|
|
|
119
156
|
return stringifyAttr(name, value);
|
|
120
157
|
}).filter(Boolean).join(' ');
|
|
@@ -181,14 +218,14 @@ function normalizeClassBinding(binding) {
|
|
|
181
218
|
}
|
|
182
219
|
|
|
183
220
|
if (_typeof(binding) === 'object') {
|
|
184
|
-
return Object.entries(binding).filter(function (
|
|
185
|
-
var
|
|
186
|
-
active =
|
|
221
|
+
return Object.entries(binding).filter(function (_ref6) {
|
|
222
|
+
var _ref7 = _slicedToArray(_ref6, 2),
|
|
223
|
+
active = _ref7[1];
|
|
187
224
|
|
|
188
225
|
return !!active;
|
|
189
|
-
}).map(function (
|
|
190
|
-
var
|
|
191
|
-
className =
|
|
226
|
+
}).map(function (_ref8) {
|
|
227
|
+
var _ref9 = _slicedToArray(_ref8, 1),
|
|
228
|
+
className = _ref9[0];
|
|
192
229
|
|
|
193
230
|
return className;
|
|
194
231
|
});
|
|
@@ -1,44 +1,80 @@
|
|
|
1
1
|
import "core-js/modules/es.array.filter.js";
|
|
2
2
|
import "core-js/modules/es.function.name.js";
|
|
3
|
+
import "core-js/modules/web.dom-collections.for-each.js";
|
|
3
4
|
import "core-js/modules/es.symbol.js";
|
|
4
5
|
import "core-js/modules/es.symbol.description.js";
|
|
6
|
+
import "core-js/modules/es.string.replace.js";
|
|
7
|
+
import "core-js/modules/es.regexp.exec.js";
|
|
5
8
|
import "core-js/modules/es.array.find.js";
|
|
6
|
-
import "core-js/modules/web.dom-collections.for-each.js";
|
|
7
9
|
import "core-js/modules/es.object.assign.js";
|
|
8
10
|
import { getCustomElements, isValidComponent, isValidMetaData } from '@storybook/web-components';
|
|
9
11
|
import { logger } from '@storybook/client-logger';
|
|
10
12
|
|
|
11
13
|
function mapData(data, category) {
|
|
12
14
|
return data && data.filter(function (item) {
|
|
13
|
-
return
|
|
15
|
+
return item && item.name;
|
|
14
16
|
}).reduce(function (acc, item) {
|
|
15
|
-
var _item$type, _item$type2;
|
|
16
|
-
|
|
17
17
|
if (item.kind === 'method') return acc;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
summary: ((_item$type2 = item.type) === null || _item$type2 === void 0 ? void 0 : _item$type2.text) || item.type
|
|
32
|
-
},
|
|
33
|
-
defaultValue: {
|
|
34
|
-
summary: item.default !== undefined ? item.default : item.defaultValue
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
};
|
|
18
|
+
|
|
19
|
+
switch (category) {
|
|
20
|
+
case 'events':
|
|
21
|
+
mapEvent(item).forEach(function (argType) {
|
|
22
|
+
acc[argType.name] = argType;
|
|
23
|
+
});
|
|
24
|
+
break;
|
|
25
|
+
|
|
26
|
+
default:
|
|
27
|
+
acc[item.name] = mapItem(item, category);
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
|
|
38
31
|
return acc;
|
|
39
32
|
}, {});
|
|
40
33
|
}
|
|
41
34
|
|
|
35
|
+
function mapItem(item, category) {
|
|
36
|
+
var _item$type, _item$type2;
|
|
37
|
+
|
|
38
|
+
var type = category === 'properties' ? {
|
|
39
|
+
name: ((_item$type = item.type) === null || _item$type === void 0 ? void 0 : _item$type.text) || item.type
|
|
40
|
+
} : {
|
|
41
|
+
name: 'void'
|
|
42
|
+
};
|
|
43
|
+
return {
|
|
44
|
+
name: item.name,
|
|
45
|
+
required: false,
|
|
46
|
+
description: item.description,
|
|
47
|
+
type: type,
|
|
48
|
+
table: {
|
|
49
|
+
category: category,
|
|
50
|
+
type: {
|
|
51
|
+
summary: ((_item$type2 = item.type) === null || _item$type2 === void 0 ? void 0 : _item$type2.text) || item.type
|
|
52
|
+
},
|
|
53
|
+
defaultValue: {
|
|
54
|
+
summary: item.default !== undefined ? item.default : item.defaultValue
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function mapEvent(item) {
|
|
61
|
+
var name = item.name.replace(/(-|_|:|\.|\s)+(.)?/g, function (_match, _separator, chr) {
|
|
62
|
+
return chr ? chr.toUpperCase() : '';
|
|
63
|
+
}).replace(/^([A-Z])/, function (match) {
|
|
64
|
+
return match.toLowerCase();
|
|
65
|
+
});
|
|
66
|
+
name = "on".concat(name.charAt(0).toUpperCase() + name.substr(1));
|
|
67
|
+
return [{
|
|
68
|
+
name: name,
|
|
69
|
+
action: {
|
|
70
|
+
name: item.name
|
|
71
|
+
},
|
|
72
|
+
table: {
|
|
73
|
+
disable: true
|
|
74
|
+
}
|
|
75
|
+
}, mapItem(item, 'events')];
|
|
76
|
+
}
|
|
77
|
+
|
|
42
78
|
var getMetaDataExperimental = function getMetaDataExperimental(tagName, customElements) {
|
|
43
79
|
if (!isValidComponent(tagName) || !isValidMetaData(customElements)) {
|
|
44
80
|
return null;
|
|
@@ -139,11 +139,9 @@ export const StoryTable = props => {
|
|
|
139
139
|
const story = useStory(storyId, context); // eslint-disable-next-line prefer-const
|
|
140
140
|
|
|
141
141
|
let [args, updateArgs, resetArgs] = useArgs(storyId, context);
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
|
|
142
|
+
if (!story) return /*#__PURE__*/React.createElement(PureArgsTable, {
|
|
143
|
+
isLoading: true
|
|
144
|
+
});
|
|
147
145
|
const argTypes = filterArgTypes(story.argTypes, include, exclude);
|
|
148
146
|
const mainLabel = getComponentName(component) || 'Story';
|
|
149
147
|
let tabs = {
|
|
@@ -3,7 +3,7 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
|
|
|
3
3
|
import React, { useContext } from 'react';
|
|
4
4
|
import { MDXProvider } from '@mdx-js/react';
|
|
5
5
|
import { toId, storyNameFromExport } from '@storybook/csf';
|
|
6
|
-
import { resetComponents, Preview as PurePreview } from '@storybook/components';
|
|
6
|
+
import { resetComponents, Preview as PurePreview, PreviewSkeleton } from '@storybook/components';
|
|
7
7
|
import { DocsContext } from './DocsContext';
|
|
8
8
|
import { SourceContext } from './SourceContainer';
|
|
9
9
|
import { getSourceProps, SourceState } from './Source';
|
|
@@ -72,7 +72,8 @@ export const Canvas = props => {
|
|
|
72
72
|
const {
|
|
73
73
|
children
|
|
74
74
|
} = props;
|
|
75
|
-
|
|
75
|
+
if (isLoading) return /*#__PURE__*/React.createElement(PreviewSkeleton, null);
|
|
76
|
+
return /*#__PURE__*/React.createElement(MDXProvider, {
|
|
76
77
|
components: resetComponents
|
|
77
78
|
}, /*#__PURE__*/React.createElement(PurePreview, previewProps, children));
|
|
78
79
|
};
|
|
@@ -50,7 +50,7 @@ const getSnippet = (snippet, story) => {
|
|
|
50
50
|
|
|
51
51
|
const userCode = (_parameters$docs2 = parameters.docs) === null || _parameters$docs2 === void 0 ? void 0 : (_parameters$docs2$sou = _parameters$docs2.source) === null || _parameters$docs2$sou === void 0 ? void 0 : _parameters$docs2$sou.code;
|
|
52
52
|
|
|
53
|
-
if (userCode) {
|
|
53
|
+
if (userCode !== undefined) {
|
|
54
54
|
return userCode;
|
|
55
55
|
} // if user has explicitly set this as dynamic, use snippet
|
|
56
56
|
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import React, { useContext, useRef, useEffect,
|
|
1
|
+
import React, { useContext, useRef, useEffect, useState } from 'react';
|
|
2
2
|
import { MDXProvider } from '@mdx-js/react';
|
|
3
|
-
import { resetComponents, Story as PureStory } from '@storybook/components';
|
|
4
|
-
import { toId, storyNameFromExport } from '@storybook/csf';
|
|
5
3
|
import global from 'global';
|
|
4
|
+
import { resetComponents, Story as PureStory, StorySkeleton } from '@storybook/components';
|
|
5
|
+
import { toId, storyNameFromExport } from '@storybook/csf';
|
|
6
|
+
import { addons } from '@storybook/addons';
|
|
7
|
+
import Events from '@storybook/core-events';
|
|
6
8
|
import { CURRENT_SELECTION } from './types';
|
|
7
9
|
import { DocsContext } from './DocsContext';
|
|
8
10
|
import { useStory } from './useStory';
|
|
@@ -24,7 +26,7 @@ export const getStoryId = (props, context) => {
|
|
|
24
26
|
export const getStoryProps = ({
|
|
25
27
|
height,
|
|
26
28
|
inline
|
|
27
|
-
}, story, context) => {
|
|
29
|
+
}, story, context, onStoryFnCalled) => {
|
|
28
30
|
const {
|
|
29
31
|
name: storyName,
|
|
30
32
|
parameters
|
|
@@ -49,9 +51,19 @@ export const getStoryProps = ({
|
|
|
49
51
|
throw new Error(`Story '${storyName}' is set to render inline, but no 'prepareForInline' function is implemented in your docs configuration!`);
|
|
50
52
|
}
|
|
51
53
|
|
|
52
|
-
const boundStoryFn = () =>
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
const boundStoryFn = () => {
|
|
55
|
+
const storyResult = story.unboundStoryFn(Object.assign({}, context.getStoryContext(story), {
|
|
56
|
+
loaded: {},
|
|
57
|
+
abortSignal: undefined,
|
|
58
|
+
canvasElement: undefined
|
|
59
|
+
})); // We need to wait until the bound story function has actually been called before we
|
|
60
|
+
// consider the story rendered. Certain frameworks (i.e. angular) don't actually render
|
|
61
|
+
// the component in the very first react render cycle, and so we can't just wait until the
|
|
62
|
+
// `PureStory` component has been rendered to consider the underlying story "rendered".
|
|
63
|
+
|
|
64
|
+
onStoryFnCalled();
|
|
65
|
+
return storyResult;
|
|
66
|
+
};
|
|
55
67
|
|
|
56
68
|
return Object.assign({
|
|
57
69
|
inline: storyIsInline,
|
|
@@ -60,7 +72,7 @@ export const getStoryProps = ({
|
|
|
60
72
|
title: storyName
|
|
61
73
|
}, storyIsInline && {
|
|
62
74
|
parameters,
|
|
63
|
-
storyFn: () => prepareForInline(boundStoryFn, story)
|
|
75
|
+
storyFn: () => prepareForInline(boundStoryFn, context.getStoryContext(story))
|
|
64
76
|
});
|
|
65
77
|
};
|
|
66
78
|
|
|
@@ -68,23 +80,15 @@ const Story = props => {
|
|
|
68
80
|
var _global$FEATURES;
|
|
69
81
|
|
|
70
82
|
const context = useContext(DocsContext);
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const {
|
|
77
|
-
id: storyId,
|
|
78
|
-
registerRenderingStory
|
|
79
|
-
} = context;
|
|
80
|
-
const storyRendered = useMemo(registerRenderingStory, [storyId]);
|
|
81
|
-
useEffect(() => {
|
|
82
|
-
if (story) storyRendered();
|
|
83
|
-
}, [story]);
|
|
83
|
+
const channel = addons.getChannel();
|
|
84
|
+
const storyRef = useRef();
|
|
85
|
+
const storyId = getStoryId(props, context);
|
|
86
|
+
const story = useStory(storyId, context);
|
|
87
|
+
const [showLoader, setShowLoader] = useState(true);
|
|
84
88
|
useEffect(() => {
|
|
85
89
|
let cleanup;
|
|
86
90
|
|
|
87
|
-
if (story &&
|
|
91
|
+
if (story && storyRef.current) {
|
|
88
92
|
const {
|
|
89
93
|
componentId,
|
|
90
94
|
id,
|
|
@@ -106,18 +110,22 @@ const Story = props => {
|
|
|
106
110
|
cleanup = context.renderStoryToElement({
|
|
107
111
|
story,
|
|
108
112
|
renderContext,
|
|
109
|
-
element:
|
|
113
|
+
element: storyRef.current
|
|
110
114
|
});
|
|
115
|
+
setShowLoader(false);
|
|
111
116
|
}
|
|
112
117
|
|
|
113
118
|
return () => cleanup && cleanup();
|
|
114
119
|
}, [story]);
|
|
115
120
|
|
|
116
121
|
if (!story) {
|
|
117
|
-
return /*#__PURE__*/React.createElement(
|
|
118
|
-
}
|
|
122
|
+
return /*#__PURE__*/React.createElement(StorySkeleton, null);
|
|
123
|
+
} // If we are rendering a old-style inline Story via `PureStory` below, we want to emit
|
|
124
|
+
// the `STORY_RENDERED` event when it renders. The modern mode below calls out to
|
|
125
|
+
// `Preview.renderStoryToDom()` which itself emits the event.
|
|
126
|
+
|
|
119
127
|
|
|
120
|
-
const storyProps = getStoryProps(props, story, context);
|
|
128
|
+
const storyProps = getStoryProps(props, story, context, () => channel.emit(Events.STORY_RENDERED, storyId));
|
|
121
129
|
|
|
122
130
|
if (!storyProps) {
|
|
123
131
|
return null;
|
|
@@ -125,7 +133,7 @@ const Story = props => {
|
|
|
125
133
|
|
|
126
134
|
if (global !== null && global !== void 0 && (_global$FEATURES = global.FEATURES) !== null && _global$FEATURES !== void 0 && _global$FEATURES.modernInlineRender) {
|
|
127
135
|
// We do this so React doesn't complain when we replace the span in a secondary render
|
|
128
|
-
const htmlContents = `<span
|
|
136
|
+
const htmlContents = `<span></span>`; // FIXME: height/style/etc. lifted from PureStory
|
|
129
137
|
|
|
130
138
|
const {
|
|
131
139
|
height
|
|
@@ -134,8 +142,8 @@ const Story = props => {
|
|
|
134
142
|
id: storyBlockIdFromId(story.id)
|
|
135
143
|
}, /*#__PURE__*/React.createElement(MDXProvider, {
|
|
136
144
|
components: resetComponents
|
|
137
|
-
}, height ? /*#__PURE__*/React.createElement("style", null, `#story--${story.id} { min-height: ${height}; transform: translateZ(0); overflow: auto }`) : null, /*#__PURE__*/React.createElement("div", {
|
|
138
|
-
ref:
|
|
145
|
+
}, height ? /*#__PURE__*/React.createElement("style", null, `#story--${story.id} { min-height: ${height}; transform: translateZ(0); overflow: auto }`) : null, showLoader && /*#__PURE__*/React.createElement(StorySkeleton, null), /*#__PURE__*/React.createElement("div", {
|
|
146
|
+
ref: storyRef,
|
|
139
147
|
"data-name": story.name,
|
|
140
148
|
dangerouslySetInnerHTML: {
|
|
141
149
|
__html: htmlContents
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import { combineParameters } from '@storybook/
|
|
1
|
+
import { combineParameters } from '@storybook/store'; // ============================================================
|
|
2
|
+
// START @storybook/source-loader/extract-source
|
|
3
|
+
//
|
|
4
|
+
// This code duplicated because tree-shaking isn't working.
|
|
5
|
+
// It's not DRY, but source-loader is on the chopping block for
|
|
6
|
+
// the next version of addon-docs, so it's not the worst sin.
|
|
7
|
+
// ============================================================
|
|
2
8
|
|
|
3
9
|
/**
|
|
4
10
|
* given a location, extract the text from the full source
|
|
@@ -1,17 +1,28 @@
|
|
|
1
|
+
import "core-js/modules/es.array.reduce.js";
|
|
1
2
|
import { useState, useEffect } from 'react';
|
|
2
3
|
export function useStory(storyId, context) {
|
|
3
4
|
const stories = useStories([storyId], context);
|
|
4
5
|
return stories && stories[0];
|
|
5
6
|
}
|
|
6
7
|
export function useStories(storyIds, context) {
|
|
7
|
-
const
|
|
8
|
+
const initialStoriesById = context.componentStories().reduce((acc, story) => {
|
|
9
|
+
acc[story.id] = story;
|
|
10
|
+
return acc;
|
|
11
|
+
}, {});
|
|
12
|
+
const [storiesById, setStories] = useState(initialStoriesById);
|
|
8
13
|
useEffect(() => {
|
|
9
14
|
Promise.all(storyIds.map(async storyId => {
|
|
15
|
+
// loadStory will be called every single time useStory is called
|
|
16
|
+
// because useEffect does not use storyIds as an input. This is because
|
|
17
|
+
// HMR can change the story even when the storyId hasn't changed. However, it
|
|
18
|
+
// will be a no-op once the story has loaded. Furthermore, the `story` will
|
|
19
|
+
// have an exact equality when the story hasn't changed, so it won't trigger
|
|
20
|
+
// any unnecessary re-renders
|
|
10
21
|
const story = await context.loadStory(storyId);
|
|
11
|
-
setStories(current => Object.assign({}, current, {
|
|
22
|
+
setStories(current => current[storyId] === story ? current : Object.assign({}, current, {
|
|
12
23
|
[storyId]: story
|
|
13
24
|
}));
|
|
14
25
|
}));
|
|
15
|
-
}
|
|
26
|
+
});
|
|
16
27
|
return storyIds.map(storyId => storiesById[storyId]);
|
|
17
28
|
}
|
|
@@ -225,8 +225,10 @@ const extractDefaultValue = property => {
|
|
|
225
225
|
};
|
|
226
226
|
|
|
227
227
|
const resolveTypealias = compodocType => {
|
|
228
|
+
var _compodocJson$miscell, _compodocJson$miscell2;
|
|
229
|
+
|
|
228
230
|
const compodocJson = getCompodocJson();
|
|
229
|
-
const typeAlias = compodocJson === null || compodocJson === void 0 ? void 0 : compodocJson.miscellaneous.typealiases.find(x => x.name === compodocType);
|
|
231
|
+
const typeAlias = compodocJson === null || compodocJson === void 0 ? void 0 : (_compodocJson$miscell = compodocJson.miscellaneous) === null || _compodocJson$miscell === void 0 ? void 0 : (_compodocJson$miscell2 = _compodocJson$miscell.typealiases) === null || _compodocJson$miscell2 === void 0 ? void 0 : _compodocJson$miscell2.find(x => x.name === compodocType);
|
|
230
232
|
return typeAlias ? resolveTypealias(typeAlias.rawtype) : compodocType;
|
|
231
233
|
};
|
|
232
234
|
|
|
@@ -9,23 +9,28 @@ const limit = pLimit(1);
|
|
|
9
9
|
|
|
10
10
|
export const prepareForInline = (storyFn, {
|
|
11
11
|
id,
|
|
12
|
-
parameters
|
|
12
|
+
parameters,
|
|
13
|
+
component
|
|
13
14
|
}) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
const el = React.useRef();
|
|
16
|
+
React.useEffect(() => {
|
|
17
|
+
(async () => {
|
|
18
|
+
limit(async () => {
|
|
19
|
+
const renderer = await rendererFactory.getRendererInstance(`${id}-${nanoid(10)}`.toLowerCase(), el.current);
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
21
|
+
if (renderer) {
|
|
22
|
+
await renderer.render({
|
|
23
|
+
forced: false,
|
|
24
|
+
component,
|
|
25
|
+
parameters,
|
|
26
|
+
storyFnAngular: storyFn(),
|
|
27
|
+
targetDOMNode: el.current
|
|
28
|
+
});
|
|
29
|
+
}
|
|
28
30
|
});
|
|
29
|
-
}
|
|
31
|
+
})();
|
|
32
|
+
});
|
|
33
|
+
return /*#__PURE__*/React.createElement('div', {
|
|
34
|
+
ref: el
|
|
30
35
|
});
|
|
31
36
|
};
|