@storybook/react 7.0.0-alpha.1 → 7.0.0-alpha.4
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/config.js +4 -12
- package/dist/cjs/docs/config.js +3 -7
- package/dist/cjs/docs/extractArgTypes.js +20 -27
- package/dist/cjs/docs/extractProps.js +9 -29
- package/dist/cjs/docs/jsxDecorator.js +50 -117
- package/dist/cjs/docs/lib/captions.js +6 -6
- package/dist/cjs/docs/lib/componentTypes.js +2 -12
- package/dist/cjs/docs/lib/defaultValues/createDefaultValue.js +16 -11
- package/dist/cjs/docs/lib/defaultValues/createFromRawDefaultProp.js +40 -59
- package/dist/cjs/docs/lib/defaultValues/generateArray.js +8 -6
- package/dist/cjs/docs/lib/defaultValues/generateObject.js +8 -6
- package/dist/cjs/docs/lib/defaultValues/index.js +2 -8
- package/dist/cjs/docs/lib/defaultValues/prettyIdentifier.js +8 -4
- package/dist/cjs/docs/lib/generateCode.js +10 -25
- package/dist/cjs/docs/lib/index.js +4 -10
- package/dist/cjs/docs/lib/inspection/acornParser.js +34 -58
- package/dist/cjs/docs/lib/inspection/index.js +2 -8
- package/dist/cjs/docs/lib/inspection/inspectValue.js +1 -3
- package/dist/cjs/docs/lib/inspection/types.js +1 -1
- package/dist/cjs/docs/lib/isHtmlTag.js +0 -4
- package/dist/cjs/docs/propTypes/createType.js +108 -119
- package/dist/cjs/docs/propTypes/generateFuncSignature.js +13 -23
- package/dist/cjs/docs/propTypes/handleProp.js +13 -15
- package/dist/cjs/docs/propTypes/rawDefaultPropResolvers.js +10 -14
- package/dist/cjs/docs/propTypes/sortProps.js +4 -20
- package/dist/cjs/docs/react-argtypes.stories.js +30 -92
- package/dist/cjs/docs/typeScript/handleProp.js +11 -11
- package/dist/cjs/index.js +10 -16
- package/dist/cjs/preview/config.js +2 -2
- package/dist/cjs/preview/globals.js +3 -1
- package/dist/cjs/preview/index.js +12 -20
- package/dist/cjs/preview/render.js +113 -258
- package/dist/cjs/preview/types-6-3.js +1 -7
- package/dist/cjs/testing/index.js +4 -3
- package/dist/esm/docs/config.js +0 -2
- package/dist/esm/docs/jsxDecorator.js +1 -1
- package/dist/esm/docs/lib/defaultValues/createFromRawDefaultProp.js +2 -1
- package/dist/esm/docs/lib/defaultValues/prettyIdentifier.js +2 -0
- package/dist/esm/docs/propTypes/createType.js +7 -5
- package/dist/esm/docs/propTypes/sortProps.js +1 -1
- package/dist/esm/testing/index.js +1 -0
- package/dist/types/config.d.ts +0 -1
- package/dist/types/docs/config.d.ts +1 -4
- package/dist/types/docs/extractProps.d.ts +6 -2
- package/dist/types/docs/jsxDecorator.d.ts +1 -1
- package/dist/types/docs/lib/defaultValues/createDefaultValue.d.ts +1 -1
- package/dist/types/docs/lib/defaultValues/createFromRawDefaultProp.d.ts +2 -2
- package/dist/types/docs/propTypes/createType.d.ts +1 -1
- package/dist/types/preview/render.d.ts +1 -1
- package/package.json +7 -8
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
require("core-js/modules/es.object.to-string.js");
|
|
4
|
-
|
|
5
|
-
require("core-js/modules/web.dom-collections.for-each.js");
|
|
6
|
-
|
|
7
|
-
require("core-js/modules/es.object.keys.js");
|
|
8
|
-
|
|
9
3
|
Object.defineProperty(exports, "__esModule", {
|
|
10
4
|
value: true
|
|
11
5
|
});
|
|
@@ -17,7 +11,7 @@ Object.keys(_types).forEach(function (key) {
|
|
|
17
11
|
if (key in exports && exports[key] === _types[key]) return;
|
|
18
12
|
Object.defineProperty(exports, key, {
|
|
19
13
|
enumerable: true,
|
|
20
|
-
get: function
|
|
14
|
+
get: function () {
|
|
21
15
|
return _types[key];
|
|
22
16
|
}
|
|
23
17
|
});
|
|
@@ -30,7 +24,7 @@ Object.keys(_inspectValue).forEach(function (key) {
|
|
|
30
24
|
if (key in exports && exports[key] === _inspectValue[key]) return;
|
|
31
25
|
Object.defineProperty(exports, key, {
|
|
32
26
|
enumerable: true,
|
|
33
|
-
get: function
|
|
27
|
+
get: function () {
|
|
34
28
|
return _inspectValue[key];
|
|
35
29
|
}
|
|
36
30
|
});
|
|
@@ -5,15 +5,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.inspectValue = inspectValue;
|
|
7
7
|
|
|
8
|
-
require("core-js/modules/es.object.assign.js");
|
|
9
|
-
|
|
10
8
|
var _acornParser = require("./acornParser");
|
|
11
9
|
|
|
12
10
|
var _types = require("./types");
|
|
13
11
|
|
|
14
12
|
function inspectValue(value) {
|
|
15
13
|
try {
|
|
16
|
-
|
|
14
|
+
const parsingResult = (0, _acornParser.parse)(value);
|
|
17
15
|
return Object.assign({}, parsingResult);
|
|
18
16
|
} catch (e) {// do nothing.
|
|
19
17
|
}
|
|
@@ -5,10 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.isHtmlTag = isHtmlTag;
|
|
7
7
|
|
|
8
|
-
require("core-js/modules/es.array.includes.js");
|
|
9
|
-
|
|
10
|
-
require("core-js/modules/es.string.includes.js");
|
|
11
|
-
|
|
12
8
|
var _htmlTags = _interopRequireDefault(require("html-tags"));
|
|
13
9
|
|
|
14
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -5,24 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.createType = createType;
|
|
7
7
|
|
|
8
|
-
require("core-js/modules/es.function.name.js");
|
|
9
|
-
|
|
10
|
-
require("core-js/modules/es.regexp.exec.js");
|
|
11
|
-
|
|
12
|
-
require("core-js/modules/es.string.replace.js");
|
|
13
|
-
|
|
14
|
-
require("core-js/modules/es.string.split.js");
|
|
15
|
-
|
|
16
|
-
require("core-js/modules/es.array.join.js");
|
|
17
|
-
|
|
18
|
-
require("core-js/modules/es.array.map.js");
|
|
19
|
-
|
|
20
|
-
require("core-js/modules/es.object.keys.js");
|
|
21
|
-
|
|
22
|
-
require("core-js/modules/es.array.concat.js");
|
|
23
|
-
|
|
24
|
-
require("core-js/modules/es.object.to-string.js");
|
|
25
|
-
|
|
26
8
|
var _docsTools = require("@storybook/docs-tools");
|
|
27
9
|
|
|
28
10
|
var _generateFuncSignature = require("./generateFuncSignature");
|
|
@@ -31,7 +13,7 @@ var _lib = require("../lib");
|
|
|
31
13
|
|
|
32
14
|
var _inspection = require("../lib/inspection");
|
|
33
15
|
|
|
34
|
-
|
|
16
|
+
const MAX_FUNC_LENGTH = 150;
|
|
35
17
|
var PropTypesType;
|
|
36
18
|
|
|
37
19
|
(function (PropTypesType) {
|
|
@@ -50,18 +32,19 @@ var PropTypesType;
|
|
|
50
32
|
PropTypesType["NODE"] = "node";
|
|
51
33
|
})(PropTypesType || (PropTypesType = {}));
|
|
52
34
|
|
|
53
|
-
function createTypeDef(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
35
|
+
function createTypeDef({
|
|
36
|
+
name,
|
|
37
|
+
short,
|
|
38
|
+
compact,
|
|
39
|
+
full,
|
|
40
|
+
inferredType
|
|
41
|
+
}) {
|
|
59
42
|
return {
|
|
60
|
-
name
|
|
61
|
-
short
|
|
62
|
-
compact
|
|
43
|
+
name,
|
|
44
|
+
short,
|
|
45
|
+
compact,
|
|
63
46
|
full: full != null ? full : short,
|
|
64
|
-
inferredType
|
|
47
|
+
inferredType
|
|
65
48
|
};
|
|
66
49
|
}
|
|
67
50
|
|
|
@@ -73,13 +56,11 @@ function splitIntoLines(value) {
|
|
|
73
56
|
return value.split(/\r?\n/);
|
|
74
57
|
}
|
|
75
58
|
|
|
76
|
-
function prettyObject(ast) {
|
|
77
|
-
var compact = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
59
|
+
function prettyObject(ast, compact = false) {
|
|
78
60
|
return cleanPropTypes((0, _lib.generateObjectCode)(ast, compact));
|
|
79
61
|
}
|
|
80
62
|
|
|
81
|
-
function prettyArray(ast) {
|
|
82
|
-
var compact = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
63
|
+
function prettyArray(ast, compact = false) {
|
|
83
64
|
return cleanPropTypes((0, _lib.generateCode)(ast, compact));
|
|
84
65
|
}
|
|
85
66
|
|
|
@@ -106,14 +87,16 @@ function getCaptionForInspectionType(type) {
|
|
|
106
87
|
}
|
|
107
88
|
|
|
108
89
|
function generateTypeFromString(value, originalTypeName) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
90
|
+
const {
|
|
91
|
+
inferredType,
|
|
92
|
+
ast
|
|
93
|
+
} = (0, _inspection.inspectValue)(value);
|
|
94
|
+
const {
|
|
95
|
+
type
|
|
96
|
+
} = inferredType;
|
|
97
|
+
let short;
|
|
98
|
+
let compact;
|
|
99
|
+
let full;
|
|
117
100
|
|
|
118
101
|
switch (type) {
|
|
119
102
|
case _inspection.InspectionType.IDENTIFIER:
|
|
@@ -124,8 +107,9 @@ function generateTypeFromString(value, originalTypeName) {
|
|
|
124
107
|
|
|
125
108
|
case _inspection.InspectionType.OBJECT:
|
|
126
109
|
{
|
|
127
|
-
|
|
128
|
-
|
|
110
|
+
const {
|
|
111
|
+
depth
|
|
112
|
+
} = inferredType;
|
|
129
113
|
short = _lib.OBJECT_CAPTION;
|
|
130
114
|
compact = depth === 1 ? prettyObject(ast, true) : null;
|
|
131
115
|
full = prettyObject(ast);
|
|
@@ -134,8 +118,9 @@ function generateTypeFromString(value, originalTypeName) {
|
|
|
134
118
|
|
|
135
119
|
case _inspection.InspectionType.ELEMENT:
|
|
136
120
|
{
|
|
137
|
-
|
|
138
|
-
|
|
121
|
+
const {
|
|
122
|
+
identifier
|
|
123
|
+
} = inferredType;
|
|
139
124
|
short = identifier != null && !(0, _lib.isHtmlTag)(identifier) ? identifier : _lib.ELEMENT_CAPTION;
|
|
140
125
|
compact = splitIntoLines(value).length === 1 ? value : null;
|
|
141
126
|
full = value;
|
|
@@ -144,10 +129,11 @@ function generateTypeFromString(value, originalTypeName) {
|
|
|
144
129
|
|
|
145
130
|
case _inspection.InspectionType.ARRAY:
|
|
146
131
|
{
|
|
147
|
-
|
|
148
|
-
|
|
132
|
+
const {
|
|
133
|
+
depth
|
|
134
|
+
} = inferredType;
|
|
149
135
|
short = _lib.ARRAY_CAPTION;
|
|
150
|
-
compact =
|
|
136
|
+
compact = depth <= 2 ? prettyArray(ast, true) : null;
|
|
151
137
|
full = prettyArray(ast);
|
|
152
138
|
break;
|
|
153
139
|
}
|
|
@@ -161,16 +147,16 @@ function generateTypeFromString(value, originalTypeName) {
|
|
|
161
147
|
|
|
162
148
|
return createTypeDef({
|
|
163
149
|
name: originalTypeName,
|
|
164
|
-
short
|
|
165
|
-
compact
|
|
166
|
-
full
|
|
150
|
+
short,
|
|
151
|
+
compact,
|
|
152
|
+
full,
|
|
167
153
|
inferredType: type
|
|
168
154
|
});
|
|
169
155
|
}
|
|
170
156
|
|
|
171
|
-
function generateCustom(
|
|
172
|
-
|
|
173
|
-
|
|
157
|
+
function generateCustom({
|
|
158
|
+
raw
|
|
159
|
+
}) {
|
|
174
160
|
if (raw != null) {
|
|
175
161
|
return generateTypeFromString(raw, PropTypesType.CUSTOM);
|
|
176
162
|
}
|
|
@@ -183,14 +169,18 @@ function generateCustom(_ref5) {
|
|
|
183
169
|
}
|
|
184
170
|
|
|
185
171
|
function generateFunc(extractedProp) {
|
|
186
|
-
|
|
172
|
+
const {
|
|
173
|
+
jsDocTags
|
|
174
|
+
} = extractedProp;
|
|
187
175
|
|
|
188
176
|
if (jsDocTags != null) {
|
|
189
177
|
if (jsDocTags.params != null || jsDocTags.returns != null) {
|
|
190
178
|
return createTypeDef({
|
|
191
179
|
name: PropTypesType.FUNC,
|
|
180
|
+
// @ts-ignore
|
|
192
181
|
short: (0, _generateFuncSignature.generateShortFuncSignature)(jsDocTags.params, jsDocTags.returns),
|
|
193
182
|
compact: null,
|
|
183
|
+
// @ts-ignore
|
|
194
184
|
full: (0, _generateFuncSignature.generateFuncSignature)(jsDocTags.params, jsDocTags.returns)
|
|
195
185
|
});
|
|
196
186
|
}
|
|
@@ -204,16 +194,14 @@ function generateFunc(extractedProp) {
|
|
|
204
194
|
}
|
|
205
195
|
|
|
206
196
|
function generateShape(type, extractedProp) {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
var _ref6 = inferredType,
|
|
216
|
-
depth = _ref6.depth;
|
|
197
|
+
const fields = Object.keys(type.value).map(key => `${key}: ${generateType(type.value[key], extractedProp).full}`).join(', ');
|
|
198
|
+
const {
|
|
199
|
+
inferredType,
|
|
200
|
+
ast
|
|
201
|
+
} = (0, _inspection.inspectValue)(`{ ${fields} }`);
|
|
202
|
+
const {
|
|
203
|
+
depth
|
|
204
|
+
} = inferredType;
|
|
217
205
|
return createTypeDef({
|
|
218
206
|
name: PropTypesType.SHAPE,
|
|
219
207
|
short: _lib.OBJECT_CAPTION,
|
|
@@ -223,31 +211,31 @@ function generateShape(type, extractedProp) {
|
|
|
223
211
|
}
|
|
224
212
|
|
|
225
213
|
function objectOf(of) {
|
|
226
|
-
return
|
|
214
|
+
return `objectOf(${of})`;
|
|
227
215
|
}
|
|
228
216
|
|
|
229
217
|
function generateObjectOf(type, extractedProp) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
218
|
+
const {
|
|
219
|
+
short,
|
|
220
|
+
compact,
|
|
221
|
+
full
|
|
222
|
+
} = generateType(type.value, extractedProp);
|
|
235
223
|
return createTypeDef({
|
|
236
224
|
name: PropTypesType.OBJECTOF,
|
|
237
225
|
short: objectOf(short),
|
|
238
226
|
compact: compact != null ? objectOf(compact) : null,
|
|
239
|
-
full: objectOf(full)
|
|
227
|
+
full: full ? objectOf(full) : full
|
|
240
228
|
});
|
|
241
229
|
}
|
|
242
230
|
|
|
243
231
|
function generateUnion(type, extractedProp) {
|
|
244
232
|
if (Array.isArray(type.value)) {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
233
|
+
const values = type.value.reduce((acc, v) => {
|
|
234
|
+
const {
|
|
235
|
+
short,
|
|
236
|
+
compact,
|
|
237
|
+
full
|
|
238
|
+
} = generateType(v, extractedProp);
|
|
251
239
|
acc.short.push(short);
|
|
252
240
|
acc.compact.push(compact);
|
|
253
241
|
acc.full.push(full);
|
|
@@ -260,9 +248,7 @@ function generateUnion(type, extractedProp) {
|
|
|
260
248
|
return createTypeDef({
|
|
261
249
|
name: PropTypesType.UNION,
|
|
262
250
|
short: values.short.join(' | '),
|
|
263
|
-
compact: values.compact.every(
|
|
264
|
-
return x != null;
|
|
265
|
-
}) ? values.compact.join(' | ') : null,
|
|
251
|
+
compact: values.compact.every(x => x != null) ? values.compact.join(' | ') : null,
|
|
266
252
|
full: values.full.join(' | ')
|
|
267
253
|
});
|
|
268
254
|
}
|
|
@@ -274,9 +260,10 @@ function generateUnion(type, extractedProp) {
|
|
|
274
260
|
});
|
|
275
261
|
}
|
|
276
262
|
|
|
277
|
-
function generateEnumValue(
|
|
278
|
-
|
|
279
|
-
|
|
263
|
+
function generateEnumValue({
|
|
264
|
+
value,
|
|
265
|
+
computed
|
|
266
|
+
}) {
|
|
280
267
|
return computed ? generateTypeFromString(value, 'enumvalue') : createTypeDef({
|
|
281
268
|
name: 'enumvalue',
|
|
282
269
|
short: value,
|
|
@@ -286,12 +273,12 @@ function generateEnumValue(_ref7) {
|
|
|
286
273
|
|
|
287
274
|
function generateEnum(type) {
|
|
288
275
|
if (Array.isArray(type.value)) {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
276
|
+
const values = type.value.reduce((acc, v) => {
|
|
277
|
+
const {
|
|
278
|
+
short,
|
|
279
|
+
compact,
|
|
280
|
+
full
|
|
281
|
+
} = generateEnumValue(v);
|
|
295
282
|
acc.short.push(short);
|
|
296
283
|
acc.compact.push(compact);
|
|
297
284
|
acc.full.push(full);
|
|
@@ -304,9 +291,7 @@ function generateEnum(type) {
|
|
|
304
291
|
return createTypeDef({
|
|
305
292
|
name: PropTypesType.ENUM,
|
|
306
293
|
short: values.short.join(' | '),
|
|
307
|
-
compact: values.compact.every(
|
|
308
|
-
return x != null;
|
|
309
|
-
}) ? values.compact.join(' | ') : null,
|
|
294
|
+
compact: values.compact.every(x => x != null) ? values.compact.join(' | ') : null,
|
|
310
295
|
full: values.full.join(' | ')
|
|
311
296
|
});
|
|
312
297
|
}
|
|
@@ -319,11 +304,11 @@ function generateEnum(type) {
|
|
|
319
304
|
}
|
|
320
305
|
|
|
321
306
|
function braceAfter(of) {
|
|
322
|
-
return
|
|
307
|
+
return `${of}[]`;
|
|
323
308
|
}
|
|
324
309
|
|
|
325
310
|
function braceAround(of) {
|
|
326
|
-
return
|
|
311
|
+
return `[${of}]`;
|
|
327
312
|
}
|
|
328
313
|
|
|
329
314
|
function createArrayOfObjectTypeDef(short, compact, full) {
|
|
@@ -331,17 +316,18 @@ function createArrayOfObjectTypeDef(short, compact, full) {
|
|
|
331
316
|
name: PropTypesType.ARRAYOF,
|
|
332
317
|
short: braceAfter(short),
|
|
333
318
|
compact: compact != null ? braceAround(compact) : null,
|
|
334
|
-
full: braceAround(full)
|
|
319
|
+
full: full ? braceAround(full) : full
|
|
335
320
|
});
|
|
336
321
|
}
|
|
337
322
|
|
|
338
323
|
function generateArray(type, extractedProp) {
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
324
|
+
const {
|
|
325
|
+
name,
|
|
326
|
+
short,
|
|
327
|
+
compact,
|
|
328
|
+
full,
|
|
329
|
+
inferredType
|
|
330
|
+
} = generateType(type.value, extractedProp);
|
|
345
331
|
|
|
346
332
|
if (name === PropTypesType.CUSTOM) {
|
|
347
333
|
if (inferredType === _inspection.InspectionType.OBJECT) {
|
|
@@ -409,7 +395,9 @@ function generateType(type, extractedProp) {
|
|
|
409
395
|
}
|
|
410
396
|
|
|
411
397
|
function createType(extractedProp) {
|
|
412
|
-
|
|
398
|
+
const {
|
|
399
|
+
type
|
|
400
|
+
} = extractedProp.docgenInfo; // A type could be null if a defaultProp has been provided without a type definition.
|
|
413
401
|
|
|
414
402
|
if (type == null) {
|
|
415
403
|
return null;
|
|
@@ -425,10 +413,11 @@ function createType(extractedProp) {
|
|
|
425
413
|
case PropTypesType.ENUM:
|
|
426
414
|
case PropTypesType.ARRAYOF:
|
|
427
415
|
{
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
416
|
+
const {
|
|
417
|
+
short,
|
|
418
|
+
compact,
|
|
419
|
+
full
|
|
420
|
+
} = generateType(type, extractedProp);
|
|
432
421
|
|
|
433
422
|
if (compact != null) {
|
|
434
423
|
if (!(0, _docsTools.isTooLongForTypeSummary)(compact)) {
|
|
@@ -436,22 +425,22 @@ function createType(extractedProp) {
|
|
|
436
425
|
}
|
|
437
426
|
}
|
|
438
427
|
|
|
439
|
-
return (0, _docsTools.createSummaryValue)(short, full);
|
|
428
|
+
return full ? (0, _docsTools.createSummaryValue)(short, full) : (0, _docsTools.createSummaryValue)(short);
|
|
440
429
|
}
|
|
441
430
|
|
|
442
431
|
case PropTypesType.FUNC:
|
|
443
432
|
{
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
if (
|
|
452
|
-
summary =
|
|
453
|
-
} else {
|
|
454
|
-
detail = (0, _generateFuncSignature.toMultilineSignature)(
|
|
433
|
+
const {
|
|
434
|
+
short,
|
|
435
|
+
full
|
|
436
|
+
} = generateType(type, extractedProp);
|
|
437
|
+
let summary = short;
|
|
438
|
+
let detail;
|
|
439
|
+
|
|
440
|
+
if (full && full.length < MAX_FUNC_LENGTH) {
|
|
441
|
+
summary = full;
|
|
442
|
+
} else if (full) {
|
|
443
|
+
detail = (0, _generateFuncSignature.toMultilineSignature)(full);
|
|
455
444
|
}
|
|
456
445
|
|
|
457
446
|
return (0, _docsTools.createSummaryValue)(summary, detail);
|
|
@@ -7,58 +7,48 @@ exports.generateFuncSignature = generateFuncSignature;
|
|
|
7
7
|
exports.generateShortFuncSignature = generateShortFuncSignature;
|
|
8
8
|
exports.toMultilineSignature = toMultilineSignature;
|
|
9
9
|
|
|
10
|
-
require("core-js/modules/es.array.map.js");
|
|
11
|
-
|
|
12
|
-
require("core-js/modules/es.array.concat.js");
|
|
13
|
-
|
|
14
|
-
require("core-js/modules/es.array.join.js");
|
|
15
|
-
|
|
16
|
-
require("core-js/modules/es.regexp.exec.js");
|
|
17
|
-
|
|
18
|
-
require("core-js/modules/es.string.replace.js");
|
|
19
|
-
|
|
20
10
|
function generateFuncSignature(params, returns) {
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
const hasParams = params != null;
|
|
12
|
+
const hasReturns = returns != null;
|
|
23
13
|
|
|
24
14
|
if (!hasParams && !hasReturns) {
|
|
25
15
|
return '';
|
|
26
16
|
}
|
|
27
17
|
|
|
28
|
-
|
|
18
|
+
const funcParts = [];
|
|
29
19
|
|
|
30
20
|
if (hasParams) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
21
|
+
const funcParams = params.map(x => {
|
|
22
|
+
const prettyName = x.getPrettyName();
|
|
23
|
+
const typeName = x.getTypeName();
|
|
34
24
|
|
|
35
25
|
if (typeName != null) {
|
|
36
|
-
return
|
|
26
|
+
return `${prettyName}: ${typeName}`;
|
|
37
27
|
}
|
|
38
28
|
|
|
39
29
|
return prettyName;
|
|
40
30
|
});
|
|
41
|
-
funcParts.push(
|
|
31
|
+
funcParts.push(`(${funcParams.join(', ')})`);
|
|
42
32
|
} else {
|
|
43
33
|
funcParts.push('()');
|
|
44
34
|
}
|
|
45
35
|
|
|
46
36
|
if (hasReturns) {
|
|
47
|
-
funcParts.push(
|
|
37
|
+
funcParts.push(`=> ${returns.getTypeName()}`);
|
|
48
38
|
}
|
|
49
39
|
|
|
50
40
|
return funcParts.join(' ');
|
|
51
41
|
}
|
|
52
42
|
|
|
53
43
|
function generateShortFuncSignature(params, returns) {
|
|
54
|
-
|
|
55
|
-
|
|
44
|
+
const hasParams = params != null;
|
|
45
|
+
const hasReturns = returns != null;
|
|
56
46
|
|
|
57
47
|
if (!hasParams && !hasReturns) {
|
|
58
48
|
return '';
|
|
59
49
|
}
|
|
60
50
|
|
|
61
|
-
|
|
51
|
+
const funcParts = [];
|
|
62
52
|
|
|
63
53
|
if (hasParams) {
|
|
64
54
|
funcParts.push('( ... )');
|
|
@@ -67,7 +57,7 @@ function generateShortFuncSignature(params, returns) {
|
|
|
67
57
|
}
|
|
68
58
|
|
|
69
59
|
if (hasReturns) {
|
|
70
|
-
funcParts.push(
|
|
60
|
+
funcParts.push(`=> ${returns.getTypeName()}`);
|
|
71
61
|
}
|
|
72
62
|
|
|
73
63
|
return funcParts.join(' ');
|
|
@@ -6,10 +6,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.enhancePropTypesProp = enhancePropTypesProp;
|
|
7
7
|
exports.enhancePropTypesProps = enhancePropTypesProps;
|
|
8
8
|
|
|
9
|
-
require("core-js/modules/es.array.map.js");
|
|
10
|
-
|
|
11
|
-
require("core-js/modules/es.function.name.js");
|
|
12
|
-
|
|
13
9
|
var _createType = require("./createType");
|
|
14
10
|
|
|
15
11
|
var _defaultValues = require("../lib/defaultValues");
|
|
@@ -19,26 +15,30 @@ var _sortProps = require("./sortProps");
|
|
|
19
15
|
var _rawDefaultPropResolvers = require("./rawDefaultPropResolvers");
|
|
20
16
|
|
|
21
17
|
function enhancePropTypesProp(extractedProp, rawDefaultProp) {
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
const {
|
|
19
|
+
propDef
|
|
20
|
+
} = extractedProp;
|
|
21
|
+
const newtype = (0, _createType.createType)(extractedProp);
|
|
24
22
|
|
|
25
23
|
if (newtype != null) {
|
|
26
24
|
propDef.type = newtype;
|
|
27
25
|
}
|
|
28
26
|
|
|
29
|
-
|
|
27
|
+
const {
|
|
28
|
+
defaultValue
|
|
29
|
+
} = extractedProp.docgenInfo;
|
|
30
30
|
|
|
31
31
|
if (defaultValue != null && defaultValue.value != null) {
|
|
32
|
-
|
|
32
|
+
const newDefaultValue = (0, _defaultValues.createDefaultValue)(defaultValue.value);
|
|
33
33
|
|
|
34
34
|
if (newDefaultValue != null) {
|
|
35
35
|
propDef.defaultValue = newDefaultValue;
|
|
36
36
|
}
|
|
37
37
|
} else if (rawDefaultProp != null) {
|
|
38
|
-
|
|
38
|
+
const newDefaultValue = (0, _defaultValues.createDefaultValueFromRawDefaultProp)(rawDefaultProp, propDef, _rawDefaultPropResolvers.rawDefaultPropTypeResolvers);
|
|
39
39
|
|
|
40
|
-
if (
|
|
41
|
-
propDef.defaultValue =
|
|
40
|
+
if (newDefaultValue != null) {
|
|
41
|
+
propDef.defaultValue = newDefaultValue;
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
|
|
@@ -46,9 +46,7 @@ function enhancePropTypesProp(extractedProp, rawDefaultProp) {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
function enhancePropTypesProps(extractedProps, component) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return enhancePropTypesProp(x, rawDefaultProps[x.propDef.name]);
|
|
52
|
-
});
|
|
49
|
+
const rawDefaultProps = component.defaultProps != null ? component.defaultProps : {};
|
|
50
|
+
const enhancedProps = extractedProps.map(x => enhancePropTypesProp(x, rawDefaultProps[x.propDef.name]));
|
|
53
51
|
return (0, _sortProps.keepOriginalDefinitionOrder)(enhancedProps, component);
|
|
54
52
|
}
|
|
@@ -5,12 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.rawDefaultPropTypeResolvers = void 0;
|
|
7
7
|
|
|
8
|
-
require("core-js/modules/es.function.name.js");
|
|
9
|
-
|
|
10
|
-
require("core-js/modules/es.object.to-string.js");
|
|
11
|
-
|
|
12
|
-
require("core-js/modules/es.regexp.to-string.js");
|
|
13
|
-
|
|
14
8
|
var _docsTools = require("@storybook/docs-tools");
|
|
15
9
|
|
|
16
10
|
var _defaultValues = require("../lib/defaultValues");
|
|
@@ -21,11 +15,12 @@ var _prettyIdentifier = require("../lib/defaultValues/prettyIdentifier");
|
|
|
21
15
|
|
|
22
16
|
var _inspection = require("../lib/inspection");
|
|
23
17
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
18
|
+
const funcResolver = (rawDefaultProp, {
|
|
19
|
+
name,
|
|
20
|
+
type
|
|
21
|
+
}) => {
|
|
22
|
+
const isElement = type.summary === 'element' || type.summary === 'elementType';
|
|
23
|
+
const funcName = (0, _defaultValues.extractFunctionName)(rawDefaultProp, name);
|
|
29
24
|
|
|
30
25
|
if (funcName != null) {
|
|
31
26
|
// Try to display the name of the component. The body of the component is omitted since the code has been transpiled.
|
|
@@ -33,15 +28,16 @@ var funcResolver = function funcResolver(rawDefaultProp, _ref) {
|
|
|
33
28
|
return (0, _docsTools.createSummaryValue)((0, _prettyIdentifier.getPrettyElementIdentifier)(funcName));
|
|
34
29
|
}
|
|
35
30
|
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
const {
|
|
32
|
+
hasParams
|
|
33
|
+
} = (0, _inspection.inspectValue)(rawDefaultProp.toString()).inferredType;
|
|
38
34
|
return (0, _docsTools.createSummaryValue)((0, _prettyIdentifier.getPrettyFuncIdentifier)(funcName, hasParams));
|
|
39
35
|
}
|
|
40
36
|
|
|
41
37
|
return (0, _docsTools.createSummaryValue)(isElement ? _lib.ELEMENT_CAPTION : _lib.FUNCTION_CAPTION);
|
|
42
38
|
};
|
|
43
39
|
|
|
44
|
-
|
|
40
|
+
const rawDefaultPropTypeResolvers = (0, _defaultValues.createTypeResolvers)({
|
|
45
41
|
function: funcResolver
|
|
46
42
|
});
|
|
47
43
|
exports.rawDefaultPropTypeResolvers = rawDefaultPropTypeResolvers;
|