@storybook/react 7.0.0-alpha.2 → 7.0.0-alpha.23
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/chunk-X53CQCCB.mjs +1 -0
- package/dist/config.d.ts +24 -0
- package/dist/config.js +7 -0
- package/dist/config.mjs +7 -0
- package/dist/index.d.ts +173 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/dist/types-9f8d440a.d.ts +17 -0
- package/package.json +39 -14
- package/preview.js +1 -1
- package/LICENSE +0 -21
- package/dist/cjs/config.js +0 -43
- package/dist/cjs/docs/config.js +0 -25
- package/dist/cjs/docs/extractArgTypes.js +0 -47
- package/dist/cjs/docs/extractProps.js +0 -57
- package/dist/cjs/docs/jsxDecorator.js +0 -210
- package/dist/cjs/docs/lib/captions.js +0 -18
- package/dist/cjs/docs/lib/componentTypes.js +0 -14
- package/dist/cjs/docs/lib/defaultValues/createDefaultValue.js +0 -86
- package/dist/cjs/docs/lib/defaultValues/createFromRawDefaultProp.js +0 -205
- package/dist/cjs/docs/lib/defaultValues/generateArray.js +0 -31
- package/dist/cjs/docs/lib/defaultValues/generateObject.js +0 -31
- package/dist/cjs/docs/lib/defaultValues/index.js +0 -31
- package/dist/cjs/docs/lib/defaultValues/prettyIdentifier.js +0 -36
- package/dist/cjs/docs/lib/generateCode.js +0 -74
- package/dist/cjs/docs/lib/index.js +0 -57
- package/dist/cjs/docs/lib/inspection/acornParser.js +0 -230
- package/dist/cjs/docs/lib/inspection/index.js +0 -31
- package/dist/cjs/docs/lib/inspection/inspectValue.js +0 -24
- package/dist/cjs/docs/lib/inspection/types.js +0 -19
- package/dist/cjs/docs/lib/isHtmlTag.js +0 -14
- package/dist/cjs/docs/propTypes/createType.js +0 -456
- package/dist/cjs/docs/propTypes/generateFuncSignature.js +0 -68
- package/dist/cjs/docs/propTypes/handleProp.js +0 -52
- package/dist/cjs/docs/propTypes/rawDefaultPropResolvers.js +0 -43
- package/dist/cjs/docs/propTypes/sortProps.js +0 -21
- package/dist/cjs/docs/react-argtypes.stories.js +0 -67
- package/dist/cjs/docs/typeScript/handleProp.js +0 -38
- package/dist/cjs/index.js +0 -98
- package/dist/cjs/preview/config.js +0 -19
- package/dist/cjs/preview/globals.js +0 -13
- package/dist/cjs/preview/index.js +0 -44
- package/dist/cjs/preview/render.js +0 -165
- package/dist/cjs/preview/types-6-0.js +0 -5
- package/dist/cjs/preview/types-6-3.js +0 -18
- package/dist/cjs/preview/types-7-0.js +0 -5
- package/dist/cjs/preview/types.js +0 -5
- package/dist/cjs/testing/index.js +0 -112
- package/dist/esm/config.js +0 -6
- package/dist/esm/docs/config.js +0 -12
- package/dist/esm/docs/extractArgTypes.js +0 -37
- package/dist/esm/docs/extractProps.js +0 -42
- package/dist/esm/docs/jsxDecorator.js +0 -170
- package/dist/esm/docs/lib/captions.js +0 -6
- package/dist/esm/docs/lib/componentTypes.js +0 -2
- package/dist/esm/docs/lib/defaultValues/createDefaultValue.js +0 -72
- package/dist/esm/docs/lib/defaultValues/createFromRawDefaultProp.js +0 -182
- package/dist/esm/docs/lib/defaultValues/generateArray.js +0 -21
- package/dist/esm/docs/lib/defaultValues/generateObject.js +0 -21
- package/dist/esm/docs/lib/defaultValues/index.js +0 -2
- package/dist/esm/docs/lib/defaultValues/prettyIdentifier.js +0 -24
- package/dist/esm/docs/lib/generateCode.js +0 -59
- package/dist/esm/docs/lib/index.js +0 -4
- package/dist/esm/docs/lib/inspection/acornParser.js +0 -211
- package/dist/esm/docs/lib/inspection/index.js +0 -2
- package/dist/esm/docs/lib/inspection/inspectValue.js +0 -15
- package/dist/esm/docs/lib/inspection/types.js +0 -12
- package/dist/esm/docs/lib/isHtmlTag.js +0 -4
- package/dist/esm/docs/propTypes/createType.js +0 -445
- package/dist/esm/docs/propTypes/generateFuncSignature.js +0 -57
- package/dist/esm/docs/propTypes/handleProp.js +0 -39
- package/dist/esm/docs/propTypes/rawDefaultPropResolvers.js +0 -31
- package/dist/esm/docs/propTypes/sortProps.js +0 -14
- package/dist/esm/docs/react-argtypes.stories.js +0 -54
- package/dist/esm/docs/typeScript/handleProp.js +0 -28
- package/dist/esm/index.js +0 -5
- package/dist/esm/preview/config.js +0 -1
- package/dist/esm/preview/globals.js +0 -8
- package/dist/esm/preview/index.js +0 -21
- package/dist/esm/preview/render.js +0 -141
- package/dist/esm/preview/types-6-0.js +0 -1
- package/dist/esm/preview/types-6-3.js +0 -10
- package/dist/esm/preview/types-7-0.js +0 -1
- package/dist/esm/preview/types.js +0 -1
- package/dist/esm/testing/index.js +0 -96
- package/dist/types/config.d.ts +0 -10
- package/dist/types/docs/config.d.ts +0 -10
- package/dist/types/docs/extractArgTypes.d.ts +0 -2
- package/dist/types/docs/extractProps.d.ts +0 -5
- package/dist/types/docs/jsxDecorator.d.ts +0 -23
- package/dist/types/docs/lib/captions.d.ts +0 -6
- package/dist/types/docs/lib/componentTypes.d.ts +0 -2
- package/dist/types/docs/lib/defaultValues/createDefaultValue.d.ts +0 -2
- package/dist/types/docs/lib/defaultValues/createFromRawDefaultProp.d.ts +0 -11
- package/dist/types/docs/lib/defaultValues/generateArray.d.ts +0 -3
- package/dist/types/docs/lib/defaultValues/generateObject.d.ts +0 -3
- package/dist/types/docs/lib/defaultValues/index.d.ts +0 -2
- package/dist/types/docs/lib/defaultValues/prettyIdentifier.d.ts +0 -4
- package/dist/types/docs/lib/generateCode.d.ts +0 -3
- package/dist/types/docs/lib/index.d.ts +0 -4
- package/dist/types/docs/lib/inspection/acornParser.d.ts +0 -7
- package/dist/types/docs/lib/inspection/index.d.ts +0 -2
- package/dist/types/docs/lib/inspection/inspectValue.d.ts +0 -2
- package/dist/types/docs/lib/inspection/types.d.ts +0 -50
- package/dist/types/docs/lib/isHtmlTag.d.ts +0 -1
- package/dist/types/docs/propTypes/createType.d.ts +0 -2
- package/dist/types/docs/propTypes/generateFuncSignature.d.ts +0 -4
- package/dist/types/docs/propTypes/handleProp.d.ts +0 -5
- package/dist/types/docs/propTypes/rawDefaultPropResolvers.d.ts +0 -1
- package/dist/types/docs/propTypes/sortProps.d.ts +0 -4
- package/dist/types/docs/react-argtypes.stories.d.ts +0 -1
- package/dist/types/docs/typeScript/handleProp.d.ts +0 -3
- package/dist/types/index.d.ts +0 -4
- package/dist/types/preview/config.d.ts +0 -1
- package/dist/types/preview/globals.d.ts +0 -1
- package/dist/types/preview/index.d.ts +0 -25
- package/dist/types/preview/render.d.ts +0 -5
- package/dist/types/preview/types-6-0.d.ts +0 -35
- package/dist/types/preview/types-6-3.d.ts +0 -40
- package/dist/types/preview/types-7-0.d.ts +0 -21
- package/dist/types/preview/types.d.ts +0 -16
- package/dist/types/testing/index.d.ts +0 -84
|
@@ -1,456 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createType = createType;
|
|
7
|
-
|
|
8
|
-
var _docsTools = require("@storybook/docs-tools");
|
|
9
|
-
|
|
10
|
-
var _generateFuncSignature = require("./generateFuncSignature");
|
|
11
|
-
|
|
12
|
-
var _lib = require("../lib");
|
|
13
|
-
|
|
14
|
-
var _inspection = require("../lib/inspection");
|
|
15
|
-
|
|
16
|
-
const MAX_FUNC_LENGTH = 150;
|
|
17
|
-
var PropTypesType;
|
|
18
|
-
|
|
19
|
-
(function (PropTypesType) {
|
|
20
|
-
PropTypesType["CUSTOM"] = "custom";
|
|
21
|
-
PropTypesType["ANY"] = "any";
|
|
22
|
-
PropTypesType["FUNC"] = "func";
|
|
23
|
-
PropTypesType["SHAPE"] = "shape";
|
|
24
|
-
PropTypesType["OBJECT"] = "object";
|
|
25
|
-
PropTypesType["INSTANCEOF"] = "instanceOf";
|
|
26
|
-
PropTypesType["OBJECTOF"] = "objectOf";
|
|
27
|
-
PropTypesType["UNION"] = "union";
|
|
28
|
-
PropTypesType["ENUM"] = "enum";
|
|
29
|
-
PropTypesType["ARRAYOF"] = "arrayOf";
|
|
30
|
-
PropTypesType["ELEMENT"] = "element";
|
|
31
|
-
PropTypesType["ELEMENTTYPE"] = "elementType";
|
|
32
|
-
PropTypesType["NODE"] = "node";
|
|
33
|
-
})(PropTypesType || (PropTypesType = {}));
|
|
34
|
-
|
|
35
|
-
function createTypeDef({
|
|
36
|
-
name,
|
|
37
|
-
short,
|
|
38
|
-
compact,
|
|
39
|
-
full,
|
|
40
|
-
inferredType
|
|
41
|
-
}) {
|
|
42
|
-
return {
|
|
43
|
-
name,
|
|
44
|
-
short,
|
|
45
|
-
compact,
|
|
46
|
-
full: full != null ? full : short,
|
|
47
|
-
inferredType
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function cleanPropTypes(value) {
|
|
52
|
-
return value.replace(/PropTypes./g, '').replace(/.isRequired/g, '');
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function splitIntoLines(value) {
|
|
56
|
-
return value.split(/\r?\n/);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function prettyObject(ast, compact = false) {
|
|
60
|
-
return cleanPropTypes((0, _lib.generateObjectCode)(ast, compact));
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function prettyArray(ast, compact = false) {
|
|
64
|
-
return cleanPropTypes((0, _lib.generateCode)(ast, compact));
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function getCaptionForInspectionType(type) {
|
|
68
|
-
switch (type) {
|
|
69
|
-
case _inspection.InspectionType.OBJECT:
|
|
70
|
-
return _lib.OBJECT_CAPTION;
|
|
71
|
-
|
|
72
|
-
case _inspection.InspectionType.ARRAY:
|
|
73
|
-
return _lib.ARRAY_CAPTION;
|
|
74
|
-
|
|
75
|
-
case _inspection.InspectionType.CLASS:
|
|
76
|
-
return _lib.CLASS_CAPTION;
|
|
77
|
-
|
|
78
|
-
case _inspection.InspectionType.FUNCTION:
|
|
79
|
-
return _lib.FUNCTION_CAPTION;
|
|
80
|
-
|
|
81
|
-
case _inspection.InspectionType.ELEMENT:
|
|
82
|
-
return _lib.ELEMENT_CAPTION;
|
|
83
|
-
|
|
84
|
-
default:
|
|
85
|
-
return _lib.CUSTOM_CAPTION;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function generateTypeFromString(value, originalTypeName) {
|
|
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;
|
|
100
|
-
|
|
101
|
-
switch (type) {
|
|
102
|
-
case _inspection.InspectionType.IDENTIFIER:
|
|
103
|
-
case _inspection.InspectionType.LITERAL:
|
|
104
|
-
short = value;
|
|
105
|
-
compact = value;
|
|
106
|
-
break;
|
|
107
|
-
|
|
108
|
-
case _inspection.InspectionType.OBJECT:
|
|
109
|
-
{
|
|
110
|
-
const {
|
|
111
|
-
depth
|
|
112
|
-
} = inferredType;
|
|
113
|
-
short = _lib.OBJECT_CAPTION;
|
|
114
|
-
compact = depth === 1 ? prettyObject(ast, true) : null;
|
|
115
|
-
full = prettyObject(ast);
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
case _inspection.InspectionType.ELEMENT:
|
|
120
|
-
{
|
|
121
|
-
const {
|
|
122
|
-
identifier
|
|
123
|
-
} = inferredType;
|
|
124
|
-
short = identifier != null && !(0, _lib.isHtmlTag)(identifier) ? identifier : _lib.ELEMENT_CAPTION;
|
|
125
|
-
compact = splitIntoLines(value).length === 1 ? value : null;
|
|
126
|
-
full = value;
|
|
127
|
-
break;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
case _inspection.InspectionType.ARRAY:
|
|
131
|
-
{
|
|
132
|
-
const {
|
|
133
|
-
depth
|
|
134
|
-
} = inferredType;
|
|
135
|
-
short = _lib.ARRAY_CAPTION;
|
|
136
|
-
compact = depth <= 2 ? prettyArray(ast, true) : null;
|
|
137
|
-
full = prettyArray(ast);
|
|
138
|
-
break;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
default:
|
|
142
|
-
short = getCaptionForInspectionType(type);
|
|
143
|
-
compact = splitIntoLines(value).length === 1 ? value : null;
|
|
144
|
-
full = value;
|
|
145
|
-
break;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return createTypeDef({
|
|
149
|
-
name: originalTypeName,
|
|
150
|
-
short,
|
|
151
|
-
compact,
|
|
152
|
-
full,
|
|
153
|
-
inferredType: type
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function generateCustom({
|
|
158
|
-
raw
|
|
159
|
-
}) {
|
|
160
|
-
if (raw != null) {
|
|
161
|
-
return generateTypeFromString(raw, PropTypesType.CUSTOM);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
return createTypeDef({
|
|
165
|
-
name: PropTypesType.CUSTOM,
|
|
166
|
-
short: _lib.CUSTOM_CAPTION,
|
|
167
|
-
compact: _lib.CUSTOM_CAPTION
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function generateFunc(extractedProp) {
|
|
172
|
-
const {
|
|
173
|
-
jsDocTags
|
|
174
|
-
} = extractedProp;
|
|
175
|
-
|
|
176
|
-
if (jsDocTags != null) {
|
|
177
|
-
if (jsDocTags.params != null || jsDocTags.returns != null) {
|
|
178
|
-
return createTypeDef({
|
|
179
|
-
name: PropTypesType.FUNC,
|
|
180
|
-
short: (0, _generateFuncSignature.generateShortFuncSignature)(jsDocTags.params, jsDocTags.returns),
|
|
181
|
-
compact: null,
|
|
182
|
-
full: (0, _generateFuncSignature.generateFuncSignature)(jsDocTags.params, jsDocTags.returns)
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return createTypeDef({
|
|
188
|
-
name: PropTypesType.FUNC,
|
|
189
|
-
short: _lib.FUNCTION_CAPTION,
|
|
190
|
-
compact: _lib.FUNCTION_CAPTION
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
function generateShape(type, extractedProp) {
|
|
195
|
-
const fields = Object.keys(type.value).map(key => `${key}: ${generateType(type.value[key], extractedProp).full}`).join(', ');
|
|
196
|
-
const {
|
|
197
|
-
inferredType,
|
|
198
|
-
ast
|
|
199
|
-
} = (0, _inspection.inspectValue)(`{ ${fields} }`);
|
|
200
|
-
const {
|
|
201
|
-
depth
|
|
202
|
-
} = inferredType;
|
|
203
|
-
return createTypeDef({
|
|
204
|
-
name: PropTypesType.SHAPE,
|
|
205
|
-
short: _lib.OBJECT_CAPTION,
|
|
206
|
-
compact: depth === 1 && ast ? prettyObject(ast, true) : null,
|
|
207
|
-
full: ast ? prettyObject(ast) : null
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
function objectOf(of) {
|
|
212
|
-
return `objectOf(${of})`;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
function generateObjectOf(type, extractedProp) {
|
|
216
|
-
const {
|
|
217
|
-
short,
|
|
218
|
-
compact,
|
|
219
|
-
full
|
|
220
|
-
} = generateType(type.value, extractedProp);
|
|
221
|
-
return createTypeDef({
|
|
222
|
-
name: PropTypesType.OBJECTOF,
|
|
223
|
-
short: objectOf(short),
|
|
224
|
-
compact: compact != null ? objectOf(compact) : null,
|
|
225
|
-
full: objectOf(full)
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
function generateUnion(type, extractedProp) {
|
|
230
|
-
if (Array.isArray(type.value)) {
|
|
231
|
-
const values = type.value.reduce((acc, v) => {
|
|
232
|
-
const {
|
|
233
|
-
short,
|
|
234
|
-
compact,
|
|
235
|
-
full
|
|
236
|
-
} = generateType(v, extractedProp);
|
|
237
|
-
acc.short.push(short);
|
|
238
|
-
acc.compact.push(compact);
|
|
239
|
-
acc.full.push(full);
|
|
240
|
-
return acc;
|
|
241
|
-
}, {
|
|
242
|
-
short: [],
|
|
243
|
-
compact: [],
|
|
244
|
-
full: []
|
|
245
|
-
});
|
|
246
|
-
return createTypeDef({
|
|
247
|
-
name: PropTypesType.UNION,
|
|
248
|
-
short: values.short.join(' | '),
|
|
249
|
-
compact: values.compact.every(x => x != null) ? values.compact.join(' | ') : null,
|
|
250
|
-
full: values.full.join(' | ')
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
return createTypeDef({
|
|
255
|
-
name: PropTypesType.UNION,
|
|
256
|
-
short: type.value,
|
|
257
|
-
compact: null
|
|
258
|
-
});
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
function generateEnumValue({
|
|
262
|
-
value,
|
|
263
|
-
computed
|
|
264
|
-
}) {
|
|
265
|
-
return computed ? generateTypeFromString(value, 'enumvalue') : createTypeDef({
|
|
266
|
-
name: 'enumvalue',
|
|
267
|
-
short: value,
|
|
268
|
-
compact: value
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
function generateEnum(type) {
|
|
273
|
-
if (Array.isArray(type.value)) {
|
|
274
|
-
const values = type.value.reduce((acc, v) => {
|
|
275
|
-
const {
|
|
276
|
-
short,
|
|
277
|
-
compact,
|
|
278
|
-
full
|
|
279
|
-
} = generateEnumValue(v);
|
|
280
|
-
acc.short.push(short);
|
|
281
|
-
acc.compact.push(compact);
|
|
282
|
-
acc.full.push(full);
|
|
283
|
-
return acc;
|
|
284
|
-
}, {
|
|
285
|
-
short: [],
|
|
286
|
-
compact: [],
|
|
287
|
-
full: []
|
|
288
|
-
});
|
|
289
|
-
return createTypeDef({
|
|
290
|
-
name: PropTypesType.ENUM,
|
|
291
|
-
short: values.short.join(' | '),
|
|
292
|
-
compact: values.compact.every(x => x != null) ? values.compact.join(' | ') : null,
|
|
293
|
-
full: values.full.join(' | ')
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
return createTypeDef({
|
|
298
|
-
name: PropTypesType.ENUM,
|
|
299
|
-
short: type.value,
|
|
300
|
-
compact: type.value
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
function braceAfter(of) {
|
|
305
|
-
return `${of}[]`;
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
function braceAround(of) {
|
|
309
|
-
return `[${of}]`;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
function createArrayOfObjectTypeDef(short, compact, full) {
|
|
313
|
-
return createTypeDef({
|
|
314
|
-
name: PropTypesType.ARRAYOF,
|
|
315
|
-
short: braceAfter(short),
|
|
316
|
-
compact: compact != null ? braceAround(compact) : null,
|
|
317
|
-
full: braceAround(full)
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
function generateArray(type, extractedProp) {
|
|
322
|
-
const {
|
|
323
|
-
name,
|
|
324
|
-
short,
|
|
325
|
-
compact,
|
|
326
|
-
full,
|
|
327
|
-
inferredType
|
|
328
|
-
} = generateType(type.value, extractedProp);
|
|
329
|
-
|
|
330
|
-
if (name === PropTypesType.CUSTOM) {
|
|
331
|
-
if (inferredType === _inspection.InspectionType.OBJECT) {
|
|
332
|
-
return createArrayOfObjectTypeDef(short, compact, full);
|
|
333
|
-
}
|
|
334
|
-
} else if (name === PropTypesType.SHAPE) {
|
|
335
|
-
return createArrayOfObjectTypeDef(short, compact, full);
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
return createTypeDef({
|
|
339
|
-
name: PropTypesType.ARRAYOF,
|
|
340
|
-
short: braceAfter(short),
|
|
341
|
-
compact: braceAfter(short)
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
function generateType(type, extractedProp) {
|
|
346
|
-
try {
|
|
347
|
-
switch (type.name) {
|
|
348
|
-
case PropTypesType.CUSTOM:
|
|
349
|
-
return generateCustom(type);
|
|
350
|
-
|
|
351
|
-
case PropTypesType.FUNC:
|
|
352
|
-
return generateFunc(extractedProp);
|
|
353
|
-
|
|
354
|
-
case PropTypesType.SHAPE:
|
|
355
|
-
return generateShape(type, extractedProp);
|
|
356
|
-
|
|
357
|
-
case PropTypesType.INSTANCEOF:
|
|
358
|
-
return createTypeDef({
|
|
359
|
-
name: PropTypesType.INSTANCEOF,
|
|
360
|
-
short: type.value,
|
|
361
|
-
compact: type.value
|
|
362
|
-
});
|
|
363
|
-
|
|
364
|
-
case PropTypesType.OBJECTOF:
|
|
365
|
-
return generateObjectOf(type, extractedProp);
|
|
366
|
-
|
|
367
|
-
case PropTypesType.UNION:
|
|
368
|
-
return generateUnion(type, extractedProp);
|
|
369
|
-
|
|
370
|
-
case PropTypesType.ENUM:
|
|
371
|
-
return generateEnum(type);
|
|
372
|
-
|
|
373
|
-
case PropTypesType.ARRAYOF:
|
|
374
|
-
return generateArray(type, extractedProp);
|
|
375
|
-
|
|
376
|
-
default:
|
|
377
|
-
return createTypeDef({
|
|
378
|
-
name: type.name,
|
|
379
|
-
short: type.name,
|
|
380
|
-
compact: type.name
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
} catch (e) {
|
|
384
|
-
// eslint-disable-next-line no-console
|
|
385
|
-
console.error(e);
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
return createTypeDef({
|
|
389
|
-
name: 'unknown',
|
|
390
|
-
short: 'unknown',
|
|
391
|
-
compact: 'unknown'
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
function createType(extractedProp) {
|
|
396
|
-
const {
|
|
397
|
-
type
|
|
398
|
-
} = extractedProp.docgenInfo; // A type could be null if a defaultProp has been provided without a type definition.
|
|
399
|
-
|
|
400
|
-
if (type == null) {
|
|
401
|
-
return null;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
try {
|
|
405
|
-
switch (type.name) {
|
|
406
|
-
case PropTypesType.CUSTOM:
|
|
407
|
-
case PropTypesType.SHAPE:
|
|
408
|
-
case PropTypesType.INSTANCEOF:
|
|
409
|
-
case PropTypesType.OBJECTOF:
|
|
410
|
-
case PropTypesType.UNION:
|
|
411
|
-
case PropTypesType.ENUM:
|
|
412
|
-
case PropTypesType.ARRAYOF:
|
|
413
|
-
{
|
|
414
|
-
const {
|
|
415
|
-
short,
|
|
416
|
-
compact,
|
|
417
|
-
full
|
|
418
|
-
} = generateType(type, extractedProp);
|
|
419
|
-
|
|
420
|
-
if (compact != null) {
|
|
421
|
-
if (!(0, _docsTools.isTooLongForTypeSummary)(compact)) {
|
|
422
|
-
return (0, _docsTools.createSummaryValue)(compact);
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
return (0, _docsTools.createSummaryValue)(short, full);
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
case PropTypesType.FUNC:
|
|
430
|
-
{
|
|
431
|
-
const {
|
|
432
|
-
short,
|
|
433
|
-
full
|
|
434
|
-
} = generateType(type, extractedProp);
|
|
435
|
-
let summary = short;
|
|
436
|
-
let detail;
|
|
437
|
-
|
|
438
|
-
if (full.length < MAX_FUNC_LENGTH) {
|
|
439
|
-
summary = full;
|
|
440
|
-
} else {
|
|
441
|
-
detail = (0, _generateFuncSignature.toMultilineSignature)(full);
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
return (0, _docsTools.createSummaryValue)(summary, detail);
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
default:
|
|
448
|
-
return null;
|
|
449
|
-
}
|
|
450
|
-
} catch (e) {
|
|
451
|
-
// eslint-disable-next-line no-console
|
|
452
|
-
console.error(e);
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
return null;
|
|
456
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.generateFuncSignature = generateFuncSignature;
|
|
7
|
-
exports.generateShortFuncSignature = generateShortFuncSignature;
|
|
8
|
-
exports.toMultilineSignature = toMultilineSignature;
|
|
9
|
-
|
|
10
|
-
function generateFuncSignature(params, returns) {
|
|
11
|
-
const hasParams = params != null;
|
|
12
|
-
const hasReturns = returns != null;
|
|
13
|
-
|
|
14
|
-
if (!hasParams && !hasReturns) {
|
|
15
|
-
return '';
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const funcParts = [];
|
|
19
|
-
|
|
20
|
-
if (hasParams) {
|
|
21
|
-
const funcParams = params.map(x => {
|
|
22
|
-
const prettyName = x.getPrettyName();
|
|
23
|
-
const typeName = x.getTypeName();
|
|
24
|
-
|
|
25
|
-
if (typeName != null) {
|
|
26
|
-
return `${prettyName}: ${typeName}`;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return prettyName;
|
|
30
|
-
});
|
|
31
|
-
funcParts.push(`(${funcParams.join(', ')})`);
|
|
32
|
-
} else {
|
|
33
|
-
funcParts.push('()');
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (hasReturns) {
|
|
37
|
-
funcParts.push(`=> ${returns.getTypeName()}`);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return funcParts.join(' ');
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function generateShortFuncSignature(params, returns) {
|
|
44
|
-
const hasParams = params != null;
|
|
45
|
-
const hasReturns = returns != null;
|
|
46
|
-
|
|
47
|
-
if (!hasParams && !hasReturns) {
|
|
48
|
-
return '';
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const funcParts = [];
|
|
52
|
-
|
|
53
|
-
if (hasParams) {
|
|
54
|
-
funcParts.push('( ... )');
|
|
55
|
-
} else {
|
|
56
|
-
funcParts.push('()');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (hasReturns) {
|
|
60
|
-
funcParts.push(`=> ${returns.getTypeName()}`);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return funcParts.join(' ');
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function toMultilineSignature(signature) {
|
|
67
|
-
return signature.replace(/,/g, ',\r\n');
|
|
68
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.enhancePropTypesProp = enhancePropTypesProp;
|
|
7
|
-
exports.enhancePropTypesProps = enhancePropTypesProps;
|
|
8
|
-
|
|
9
|
-
var _createType = require("./createType");
|
|
10
|
-
|
|
11
|
-
var _defaultValues = require("../lib/defaultValues");
|
|
12
|
-
|
|
13
|
-
var _sortProps = require("./sortProps");
|
|
14
|
-
|
|
15
|
-
var _rawDefaultPropResolvers = require("./rawDefaultPropResolvers");
|
|
16
|
-
|
|
17
|
-
function enhancePropTypesProp(extractedProp, rawDefaultProp) {
|
|
18
|
-
const {
|
|
19
|
-
propDef
|
|
20
|
-
} = extractedProp;
|
|
21
|
-
const newtype = (0, _createType.createType)(extractedProp);
|
|
22
|
-
|
|
23
|
-
if (newtype != null) {
|
|
24
|
-
propDef.type = newtype;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const {
|
|
28
|
-
defaultValue
|
|
29
|
-
} = extractedProp.docgenInfo;
|
|
30
|
-
|
|
31
|
-
if (defaultValue != null && defaultValue.value != null) {
|
|
32
|
-
const newDefaultValue = (0, _defaultValues.createDefaultValue)(defaultValue.value);
|
|
33
|
-
|
|
34
|
-
if (newDefaultValue != null) {
|
|
35
|
-
propDef.defaultValue = newDefaultValue;
|
|
36
|
-
}
|
|
37
|
-
} else if (rawDefaultProp != null) {
|
|
38
|
-
const newDefaultValue = (0, _defaultValues.createDefaultValueFromRawDefaultProp)(rawDefaultProp, propDef, _rawDefaultPropResolvers.rawDefaultPropTypeResolvers);
|
|
39
|
-
|
|
40
|
-
if (newDefaultValue != null) {
|
|
41
|
-
propDef.defaultValue = newDefaultValue;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return propDef;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function enhancePropTypesProps(extractedProps, component) {
|
|
49
|
-
const rawDefaultProps = component.defaultProps != null ? component.defaultProps : {};
|
|
50
|
-
const enhancedProps = extractedProps.map(x => enhancePropTypesProp(x, rawDefaultProps[x.propDef.name]));
|
|
51
|
-
return (0, _sortProps.keepOriginalDefinitionOrder)(enhancedProps, component);
|
|
52
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.rawDefaultPropTypeResolvers = void 0;
|
|
7
|
-
|
|
8
|
-
var _docsTools = require("@storybook/docs-tools");
|
|
9
|
-
|
|
10
|
-
var _defaultValues = require("../lib/defaultValues");
|
|
11
|
-
|
|
12
|
-
var _lib = require("../lib");
|
|
13
|
-
|
|
14
|
-
var _prettyIdentifier = require("../lib/defaultValues/prettyIdentifier");
|
|
15
|
-
|
|
16
|
-
var _inspection = require("../lib/inspection");
|
|
17
|
-
|
|
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);
|
|
24
|
-
|
|
25
|
-
if (funcName != null) {
|
|
26
|
-
// Try to display the name of the component. The body of the component is omitted since the code has been transpiled.
|
|
27
|
-
if (isElement) {
|
|
28
|
-
return (0, _docsTools.createSummaryValue)((0, _prettyIdentifier.getPrettyElementIdentifier)(funcName));
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const {
|
|
32
|
-
hasParams
|
|
33
|
-
} = (0, _inspection.inspectValue)(rawDefaultProp.toString()).inferredType;
|
|
34
|
-
return (0, _docsTools.createSummaryValue)((0, _prettyIdentifier.getPrettyFuncIdentifier)(funcName, hasParams));
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return (0, _docsTools.createSummaryValue)(isElement ? _lib.ELEMENT_CAPTION : _lib.FUNCTION_CAPTION);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const rawDefaultPropTypeResolvers = (0, _defaultValues.createTypeResolvers)({
|
|
41
|
-
function: funcResolver
|
|
42
|
-
});
|
|
43
|
-
exports.rawDefaultPropTypeResolvers = rawDefaultPropTypeResolvers;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.keepOriginalDefinitionOrder = keepOriginalDefinitionOrder;
|
|
7
|
-
|
|
8
|
-
// react-docgen doesn't returned the props in the order they were defined in the "propTypes" object of the component.
|
|
9
|
-
// This function re-order them by their original definition order.
|
|
10
|
-
function keepOriginalDefinitionOrder(extractedProps, component) {
|
|
11
|
-
// eslint-disable-next-line react/forbid-foreign-prop-types
|
|
12
|
-
const {
|
|
13
|
-
propTypes
|
|
14
|
-
} = component;
|
|
15
|
-
|
|
16
|
-
if (propTypes != null) {
|
|
17
|
-
return Object.keys(propTypes).map(x => extractedProps.find(y => y.name === x)).filter(x => x);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return extractedProps;
|
|
21
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
4
|
-
|
|
5
|
-
var _mapValues = _interopRequireDefault(require("lodash/mapValues"));
|
|
6
|
-
|
|
7
|
-
var _components = require("@storybook/components");
|
|
8
|
-
|
|
9
|
-
var _store = require("@storybook/store");
|
|
10
|
-
|
|
11
|
-
var _ = require("..");
|
|
12
|
-
|
|
13
|
-
var _extractArgTypes = require("./extractArgTypes");
|
|
14
|
-
|
|
15
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
-
|
|
17
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
18
|
-
|
|
19
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
20
|
-
|
|
21
|
-
const argsTableProps = component => {
|
|
22
|
-
const argTypes = (0, _extractArgTypes.extractArgTypes)(component);
|
|
23
|
-
const parameters = {
|
|
24
|
-
__isArgsStory: true
|
|
25
|
-
};
|
|
26
|
-
const rows = (0, _store.inferControls)({
|
|
27
|
-
argTypes,
|
|
28
|
-
parameters
|
|
29
|
-
});
|
|
30
|
-
return {
|
|
31
|
-
rows
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const ArgsStory = ({
|
|
36
|
-
component
|
|
37
|
-
}) => {
|
|
38
|
-
const {
|
|
39
|
-
rows
|
|
40
|
-
} = argsTableProps(component);
|
|
41
|
-
const initialArgs = (0, _mapValues.default)(rows, argType => argType.defaultValue);
|
|
42
|
-
const [args, setArgs] = (0, _react.useState)(initialArgs);
|
|
43
|
-
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("p", null, /*#__PURE__*/_react.default.createElement("b", null, "NOTE:"), " these stories are to help visualise the snapshot tests in", ' ', /*#__PURE__*/_react.default.createElement("code", null, "./react-properties.test.js"), "."), /*#__PURE__*/_react.default.createElement(_components.ArgsTable, {
|
|
44
|
-
rows: rows,
|
|
45
|
-
args: args,
|
|
46
|
-
updateArgs: val => setArgs(Object.assign({}, args, val))
|
|
47
|
-
}), /*#__PURE__*/_react.default.createElement("table", null, /*#__PURE__*/_react.default.createElement("thead", null, /*#__PURE__*/_react.default.createElement("tr", null, /*#__PURE__*/_react.default.createElement("th", null, "arg name"), /*#__PURE__*/_react.default.createElement("th", null, "argType"))), /*#__PURE__*/_react.default.createElement("tbody", null, Object.entries(args).map(([key, val]) => /*#__PURE__*/_react.default.createElement("tr", {
|
|
48
|
-
key: key
|
|
49
|
-
}, /*#__PURE__*/_react.default.createElement("td", null, /*#__PURE__*/_react.default.createElement("code", null, key)), /*#__PURE__*/_react.default.createElement("td", null, /*#__PURE__*/_react.default.createElement("pre", null, JSON.stringify(rows[key]))))))));
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const issuesFixtures = ['js-class-component', 'js-function-component', 'js-function-component-inline-defaults', 'js-function-component-inline-defaults-no-propTypes', 'ts-function-component', 'ts-function-component-inline-defaults', '9399-js-proptypes-shape', '8663-js-styled-components', '9626-js-default-values', '9668-js-proptypes-no-jsdoc', '8143-ts-react-fc-generics', '8143-ts-imported-types', '8279-js-styled-docgen', '8140-js-prop-types-oneof', '9023-js-hoc', '8740-ts-multi-props', '9556-ts-react-default-exports', '9592-ts-styled-props', '9591-ts-import-types', '9721-ts-deprecated-jsdoc', '9827-ts-default-values', '9586-js-react-memo', '9575-ts-camel-case', '9493-ts-display-name', '8894-9511-ts-forward-ref', '9465-ts-type-props', '8428-js-static-prop-types', '9764-ts-extend-props', '9922-ts-component-props'];
|
|
53
|
-
const issuesStories = (0, _.storiesOf)('ArgTypes/Issues', module);
|
|
54
|
-
issuesFixtures.forEach(fixture => {
|
|
55
|
-
// eslint-disable-next-line import/no-dynamic-require, global-require
|
|
56
|
-
const {
|
|
57
|
-
component
|
|
58
|
-
} = require(`./__testfixtures__/${fixture}/input`);
|
|
59
|
-
|
|
60
|
-
issuesStories.add(fixture, () => /*#__PURE__*/_react.default.createElement(ArgsStory, {
|
|
61
|
-
component: component
|
|
62
|
-
}), {
|
|
63
|
-
chromatic: {
|
|
64
|
-
disable: true
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
});
|