@storybook/react 10.2.0-beta.3 → 10.2.0-beta.5

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.
@@ -0,0 +1,755 @@
1
+ import CJS_COMPAT_NODE_URL_fpjk9qjlmms from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_fpjk9qjlmms from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_fpjk9qjlmms from "node:module";
4
+
5
+ var __filename = CJS_COMPAT_NODE_URL_fpjk9qjlmms.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_fpjk9qjlmms.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_fpjk9qjlmms.createRequire(import.meta.url);
8
+
9
+ // ------------------------------------------------------------
10
+ // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
+ // ------------------------------------------------------------
12
+ import {
13
+ __commonJS,
14
+ __require
15
+ } from "./chunk-IGARYXOH.js";
16
+
17
+ // ../../../node_modules/react-docgen-typescript/lib/buildFilter.js
18
+ var require_buildFilter = __commonJS({
19
+ "../../../node_modules/react-docgen-typescript/lib/buildFilter.js"(exports) {
20
+ "use strict";
21
+ Object.defineProperty(exports, "__esModule", { value: !0 });
22
+ exports.buildFilter = void 0;
23
+ function buildFilter(opts) {
24
+ return function(prop, component) {
25
+ var propFilter = opts.propFilter;
26
+ if (prop.name === "children" && prop.description.length === 0 && opts.skipChildrenPropWithoutDoc !== !1)
27
+ return !1;
28
+ if (typeof propFilter == "function") {
29
+ var keep = propFilter(prop, component);
30
+ if (!keep)
31
+ return !1;
32
+ } else if (typeof propFilter == "object") {
33
+ var _a = propFilter, skipPropsWithName = _a.skipPropsWithName, skipPropsWithoutDoc = _a.skipPropsWithoutDoc;
34
+ if (typeof skipPropsWithName == "string" && skipPropsWithName === prop.name)
35
+ return !1;
36
+ if (Array.isArray(skipPropsWithName) && skipPropsWithName.indexOf(prop.name) > -1 || skipPropsWithoutDoc && prop.description.length === 0)
37
+ return !1;
38
+ }
39
+ return !0;
40
+ };
41
+ }
42
+ exports.buildFilter = buildFilter;
43
+ }
44
+ });
45
+
46
+ // ../../../node_modules/react-docgen-typescript/lib/trimFileName.js
47
+ var require_trimFileName = __commonJS({
48
+ "../../../node_modules/react-docgen-typescript/lib/trimFileName.js"(exports) {
49
+ "use strict";
50
+ Object.defineProperty(exports, "__esModule", { value: !0 });
51
+ exports.trimFileName = void 0;
52
+ var path = __require("path"), slashRegex = /[\\/]/g, fileNameCache = /* @__PURE__ */ new Map();
53
+ function trimFileName(fileName, cwd, platform) {
54
+ var _a;
55
+ if (cwd === void 0 && (cwd = process.cwd()), fileNameCache.has(fileName))
56
+ return fileNameCache.get(fileName);
57
+ var pathLib = platform ? path[platform] : path, originalSep = ((_a = fileName.match(slashRegex)) === null || _a === void 0 ? void 0 : _a[0]) || pathLib.sep, normalizedFileName = pathLib.normalize(fileName), root = pathLib.parse(cwd).root, parent = cwd;
58
+ do {
59
+ if (normalizedFileName.startsWith(parent)) {
60
+ var finalPathName = pathLib.relative(pathLib.dirname(parent), normalizedFileName).replace(slashRegex, originalSep);
61
+ return fileNameCache.set(fileName, finalPathName), finalPathName;
62
+ }
63
+ parent = pathLib.dirname(parent);
64
+ } while (parent !== root);
65
+ return fileNameCache.set(fileName, fileName), fileName;
66
+ }
67
+ exports.trimFileName = trimFileName;
68
+ }
69
+ });
70
+
71
+ // ../../../node_modules/react-docgen-typescript/lib/parser.js
72
+ var require_parser = __commonJS({
73
+ "../../../node_modules/react-docgen-typescript/lib/parser.js"(exports) {
74
+ "use strict";
75
+ var __assign = exports && exports.__assign || function() {
76
+ return __assign = Object.assign || function(t) {
77
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
78
+ s = arguments[i];
79
+ for (var p in s) Object.prototype.hasOwnProperty.call(s, p) && (t[p] = s[p]);
80
+ }
81
+ return t;
82
+ }, __assign.apply(this, arguments);
83
+ }, __spreadArray = exports && exports.__spreadArray || function(to, from) {
84
+ for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
85
+ to[j] = from[i];
86
+ return to;
87
+ };
88
+ Object.defineProperty(exports, "__esModule", { value: !0 });
89
+ exports.getDefaultExportForFile = exports.Parser = exports.withCompilerOptions = exports.withCustomConfig = exports.withDefaultConfig = exports.parse = exports.defaultOptions = exports.defaultParserOpts = void 0;
90
+ var fs = __require("fs"), path = __require("path"), ts = __require("typescript"), buildFilter_1 = require_buildFilter(), trimFileName_1 = require_trimFileName();
91
+ exports.defaultParserOpts = {};
92
+ exports.defaultOptions = {
93
+ jsx: ts.JsxEmit.React,
94
+ module: ts.ModuleKind.CommonJS,
95
+ target: ts.ScriptTarget.Latest,
96
+ esModuleInterop: !0
97
+ };
98
+ function parse(filePathOrPaths, parserOpts) {
99
+ return parserOpts === void 0 && (parserOpts = exports.defaultParserOpts), withCompilerOptions(exports.defaultOptions, parserOpts).parse(filePathOrPaths);
100
+ }
101
+ exports.parse = parse;
102
+ function withDefaultConfig(parserOpts) {
103
+ return parserOpts === void 0 && (parserOpts = exports.defaultParserOpts), withCompilerOptions(exports.defaultOptions, parserOpts);
104
+ }
105
+ exports.withDefaultConfig = withDefaultConfig;
106
+ function withCustomConfig(tsconfigPath, parserOpts) {
107
+ var basePath = path.dirname(tsconfigPath), _a = ts.readConfigFile(tsconfigPath, function(filename) {
108
+ return fs.readFileSync(filename, "utf8");
109
+ }), config = _a.config, error = _a.error;
110
+ if (error !== void 0) {
111
+ var errorText = "Cannot load custom tsconfig.json from provided path: " + tsconfigPath + ", with error code: " + error.code + ", message: " + error.messageText;
112
+ throw new Error(errorText);
113
+ }
114
+ var _b = ts.parseJsonConfigFileContent(config, ts.sys, basePath, {}, tsconfigPath), options = _b.options, errors = _b.errors;
115
+ if (errors && errors.length)
116
+ throw errors[0] instanceof Error ? errors[0] : errors[0].messageText ? new Error("TS" + errors[0].code + ": " + errors[0].messageText) : new Error(JSON.stringify(errors[0]));
117
+ return withCompilerOptions(options, parserOpts);
118
+ }
119
+ exports.withCustomConfig = withCustomConfig;
120
+ function withCompilerOptions(compilerOptions, parserOpts) {
121
+ return parserOpts === void 0 && (parserOpts = exports.defaultParserOpts), {
122
+ parse: function(filePathOrPaths) {
123
+ return parseWithProgramProvider(filePathOrPaths, compilerOptions, parserOpts);
124
+ },
125
+ parseWithProgramProvider: function(filePathOrPaths, programProvider) {
126
+ return parseWithProgramProvider(filePathOrPaths, compilerOptions, parserOpts, programProvider);
127
+ }
128
+ };
129
+ }
130
+ exports.withCompilerOptions = withCompilerOptions;
131
+ var isOptional = function(prop) {
132
+ return (prop.getFlags() & ts.SymbolFlags.Optional) !== 0;
133
+ }, defaultJSDoc = {
134
+ description: "",
135
+ fullComment: "",
136
+ tags: {}
137
+ }, Parser = (
138
+ /** @class */
139
+ (function() {
140
+ function Parser2(program, opts) {
141
+ this.propertiesOfPropsCache = /* @__PURE__ */ new Map(), this.componentsInfoCache = /* @__PURE__ */ new Map();
142
+ var savePropValueAsString = opts.savePropValueAsString, shouldExtractLiteralValuesFromEnum = opts.shouldExtractLiteralValuesFromEnum, shouldRemoveUndefinedFromOptional = opts.shouldRemoveUndefinedFromOptional, shouldExtractValuesFromUnion = opts.shouldExtractValuesFromUnion, shouldSortUnions = opts.shouldSortUnions, shouldIncludePropTagMap = opts.shouldIncludePropTagMap, shouldIncludeExpression = opts.shouldIncludeExpression;
143
+ this.checker = program.getTypeChecker(), this.propFilter = buildFilter_1.buildFilter(opts), this.shouldExtractLiteralValuesFromEnum = !!shouldExtractLiteralValuesFromEnum, this.shouldRemoveUndefinedFromOptional = !!shouldRemoveUndefinedFromOptional, this.shouldExtractValuesFromUnion = !!shouldExtractValuesFromUnion, this.shouldSortUnions = !!shouldSortUnions, this.savePropValueAsString = !!savePropValueAsString, this.shouldIncludePropTagMap = !!shouldIncludePropTagMap, this.shouldIncludeExpression = !!shouldIncludeExpression;
144
+ }
145
+ return Parser2.prototype.getTypeSymbol = function(exp) {
146
+ var declaration = exp.valueDeclaration || exp.declarations[0], type = this.checker.getTypeOfSymbolAtLocation(exp, declaration), typeSymbol = type.symbol || type.aliasSymbol;
147
+ return typeSymbol;
148
+ }, Parser2.prototype.isPlainObjectType = function(exp) {
149
+ var targetSymbol = exp;
150
+ exp.flags & ts.SymbolFlags.Alias && (targetSymbol = this.checker.getAliasedSymbol(exp));
151
+ var declaration = targetSymbol.valueDeclaration;
152
+ if (!declaration || ts.isClassDeclaration(declaration))
153
+ return !1;
154
+ var type = this.checker.getTypeOfSymbolAtLocation(targetSymbol, declaration);
155
+ if (!(type.flags & ts.TypeFlags.Object))
156
+ return !1;
157
+ var objectType = type, isPlain = !!(objectType.objectFlags & (ts.ObjectFlags.Anonymous | ts.ObjectFlags.ObjectLiteral));
158
+ return isPlain;
159
+ }, Parser2.prototype.getComponentExports = function(exp) {
160
+ var targetSymbol = exp;
161
+ if (targetSymbol.exports)
162
+ return { symbol: targetSymbol, exports: targetSymbol.exports };
163
+ if (exp.flags & ts.SymbolFlags.Alias && (targetSymbol = this.checker.getAliasedSymbol(exp)), targetSymbol.exports)
164
+ return { symbol: targetSymbol, exports: targetSymbol.exports };
165
+ }, Parser2.prototype.getComponentFromExpression = function(exp) {
166
+ var declaration = exp.valueDeclaration || exp.declarations[0];
167
+ if (declaration && ts.isPropertyAssignment(declaration) && ts.isIdentifier(declaration.initializer)) {
168
+ var newSymbol = this.checker.getSymbolAtLocation(declaration.initializer);
169
+ newSymbol && (exp = newSymbol, declaration = exp.valueDeclaration || exp.declarations[0]);
170
+ }
171
+ var type = this.checker.getTypeOfSymbolAtLocation(exp, declaration), typeSymbol = type.symbol || type.aliasSymbol;
172
+ if (!typeSymbol)
173
+ return exp;
174
+ var symbolName = typeSymbol.getName();
175
+ if ((symbolName === "MemoExoticComponent" || symbolName === "ForwardRefExoticComponent") && exp.valueDeclaration && ts.isExportAssignment(exp.valueDeclaration) && ts.isCallExpression(exp.valueDeclaration.expression)) {
176
+ var component = this.checker.getSymbolAtLocation(exp.valueDeclaration.expression.arguments[0]);
177
+ component && (exp = component);
178
+ }
179
+ return exp;
180
+ }, Parser2.prototype.getComponentInfo = function(exp, source, componentNameResolver, customComponentTypes) {
181
+ if (componentNameResolver === void 0 && (componentNameResolver = function() {
182
+ }), customComponentTypes === void 0 && (customComponentTypes = []), exp.declarations && exp.declarations.length === 0)
183
+ return null;
184
+ var rootExp = this.getComponentFromExpression(exp), declaration = rootExp.valueDeclaration || rootExp.declarations[0], type = this.checker.getTypeOfSymbolAtLocation(rootExp, declaration), commentSource = rootExp, typeSymbol = type.symbol || type.aliasSymbol, originalName = rootExp.getName(), filePath = source.fileName, cacheKey = filePath + "_" + originalName;
185
+ if (this.componentsInfoCache.has(cacheKey))
186
+ return this.componentsInfoCache.get(cacheKey);
187
+ if (rootExp.valueDeclaration)
188
+ type.symbol && (ts.isPropertyAccessExpression(declaration) || ts.isPropertyDeclaration(declaration)) && (commentSource = type.symbol);
189
+ else if (!typeSymbol && (rootExp.flags & ts.SymbolFlags.Alias) !== 0)
190
+ commentSource = this.checker.getAliasedSymbol(commentSource);
191
+ else if (typeSymbol) {
192
+ rootExp = typeSymbol;
193
+ var expName = rootExp.getName(), defaultComponentTypes = [
194
+ "__function",
195
+ "StatelessComponent",
196
+ "Stateless",
197
+ "StyledComponentClass",
198
+ "StyledComponent",
199
+ "IStyledComponent",
200
+ "FunctionComponent",
201
+ "ForwardRefExoticComponent",
202
+ "MemoExoticComponent"
203
+ ], supportedComponentTypes = __spreadArray(__spreadArray([], defaultComponentTypes), customComponentTypes);
204
+ supportedComponentTypes.indexOf(expName) !== -1 ? commentSource = this.checker.getAliasedSymbol(commentSource) : commentSource = rootExp;
205
+ } else
206
+ return this.componentsInfoCache.set(cacheKey, null), null;
207
+ if (typeSymbol && (typeSymbol.getEscapedName() === "Requireable" || typeSymbol.getEscapedName() === "Validator"))
208
+ return this.componentsInfoCache.set(cacheKey, null), null;
209
+ var propsType = this.extractPropsFromTypeIfStatelessComponent(type) || this.extractPropsFromTypeIfStatefulComponent(type), nameSource = originalName === "default" ? rootExp : commentSource, resolvedComponentName = componentNameResolver(nameSource, source), _a = this.findDocComment(commentSource), description = _a.description, tags = _a.tags, displayName = resolvedComponentName || tags.visibleName || computeComponentName(nameSource, source, customComponentTypes), methods = this.getMethodsInfo(type), result = null;
210
+ if (propsType) {
211
+ if (!commentSource.valueDeclaration)
212
+ return this.componentsInfoCache.set(cacheKey, null), null;
213
+ for (var defaultProps = this.extractDefaultPropsFromComponent(commentSource, commentSource.valueDeclaration.getSourceFile()), props = this.getPropsInfo(propsType, defaultProps), _i = 0, _b = Object.keys(props); _i < _b.length; _i++) {
214
+ var propName = _b[_i], prop = props[propName], component = { name: displayName };
215
+ this.propFilter(prop, component) || delete props[propName];
216
+ }
217
+ result = {
218
+ tags,
219
+ filePath,
220
+ description,
221
+ displayName,
222
+ methods,
223
+ props
224
+ };
225
+ } else description && displayName && (result = {
226
+ tags,
227
+ filePath,
228
+ description,
229
+ displayName,
230
+ methods,
231
+ props: {}
232
+ });
233
+ return result !== null && this.shouldIncludeExpression && (result.expression = rootExp, result.rootExpression = exp), this.componentsInfoCache.set(cacheKey, result), result;
234
+ }, Parser2.prototype.extractPropsFromTypeIfStatelessComponent = function(type) {
235
+ var callSignatures = type.getCallSignatures();
236
+ if (callSignatures.length)
237
+ for (var _i = 0, callSignatures_1 = callSignatures; _i < callSignatures_1.length; _i++) {
238
+ var sig = callSignatures_1[_i], params = sig.getParameters();
239
+ if (params.length !== 0) {
240
+ var propsParam = params[0];
241
+ if (propsParam.name === "props" || params.length === 1)
242
+ return propsParam;
243
+ }
244
+ }
245
+ return null;
246
+ }, Parser2.prototype.extractPropsFromTypeIfStatefulComponent = function(type) {
247
+ var constructSignatures = type.getConstructSignatures();
248
+ if (constructSignatures.length)
249
+ for (var _i = 0, constructSignatures_1 = constructSignatures; _i < constructSignatures_1.length; _i++) {
250
+ var sig = constructSignatures_1[_i], instanceType = sig.getReturnType(), props = instanceType.getProperty("props");
251
+ if (props)
252
+ return props;
253
+ }
254
+ return null;
255
+ }, Parser2.prototype.extractMembersFromType = function(type) {
256
+ var _this = this, methodSymbols = [];
257
+ return type.getProperties().forEach(function(property) {
258
+ _this.getCallSignature(property) && methodSymbols.push(property);
259
+ }), type.symbol && type.symbol.members && type.symbol.members.forEach(function(member) {
260
+ methodSymbols.push(member);
261
+ }), methodSymbols;
262
+ }, Parser2.prototype.getMethodsInfo = function(type) {
263
+ var _this = this, members = this.extractMembersFromType(type), methods = [];
264
+ return members.forEach(function(member) {
265
+ if (_this.isTaggedPublic(member)) {
266
+ var name = member.getName(), docblock = _this.getFullJsDocComment(member).fullComment, callSignature = _this.getCallSignature(member), params = _this.getParameterInfo(callSignature), description = ts.displayPartsToString(member.getDocumentationComment(_this.checker)), returnType = _this.checker.typeToString(callSignature.getReturnType()), returnDescription = ts.displayPartsToString(_this.getReturnDescription(member)), modifiers = _this.getModifiers(member);
267
+ methods.push({
268
+ description,
269
+ docblock,
270
+ modifiers,
271
+ name,
272
+ params,
273
+ returns: returnDescription ? {
274
+ description: returnDescription,
275
+ type: returnType
276
+ } : null
277
+ });
278
+ }
279
+ }), methods;
280
+ }, Parser2.prototype.getModifiers = function(member) {
281
+ var modifiers = [];
282
+ if (!member.valueDeclaration)
283
+ return modifiers;
284
+ var flags = ts.getCombinedModifierFlags(member.valueDeclaration), isStatic = (flags & ts.ModifierFlags.Static) !== 0;
285
+ return isStatic && modifiers.push("static"), modifiers;
286
+ }, Parser2.prototype.getParameterInfo = function(callSignature) {
287
+ var _this = this;
288
+ return callSignature.parameters.map(function(param) {
289
+ var paramType = _this.checker.getTypeOfSymbolAtLocation(param, param.valueDeclaration), paramDeclaration = _this.checker.symbolToParameterDeclaration(param, void 0, void 0), isOptionalParam = !!(paramDeclaration && paramDeclaration.questionToken);
290
+ return {
291
+ description: ts.displayPartsToString(param.getDocumentationComment(_this.checker)) || null,
292
+ name: param.getName() + (isOptionalParam ? "?" : ""),
293
+ type: { name: _this.checker.typeToString(paramType) }
294
+ };
295
+ });
296
+ }, Parser2.prototype.getCallSignature = function(symbol) {
297
+ var symbolType = this.checker.getTypeOfSymbolAtLocation(symbol, symbol.valueDeclaration);
298
+ return symbolType.getCallSignatures()[0];
299
+ }, Parser2.prototype.isTaggedPublic = function(symbol) {
300
+ var jsDocTags = symbol.getJsDocTags();
301
+ return !!jsDocTags.find(function(tag) {
302
+ return tag.name === "public";
303
+ });
304
+ }, Parser2.prototype.getReturnDescription = function(symbol) {
305
+ var tags = symbol.getJsDocTags(), returnTag = tags.find(function(tag) {
306
+ return tag.name === "returns";
307
+ });
308
+ if (!(!returnTag || !Array.isArray(returnTag.text)))
309
+ return returnTag.text;
310
+ }, Parser2.prototype.getValuesFromUnionType = function(type) {
311
+ return type.isStringLiteral() ? '"' + type.value + '"' : type.isNumberLiteral() ? "" + type.value : this.checker.typeToString(type);
312
+ }, Parser2.prototype.getInfoFromUnionType = function(type) {
313
+ var commentInfo = {};
314
+ return type.getSymbol() && (commentInfo = __assign({}, this.getFullJsDocComment(type.getSymbol()))), __assign({ value: this.getValuesFromUnionType(type) }, commentInfo);
315
+ }, Parser2.prototype.getDocgenType = function(propType, isRequired) {
316
+ var _this = this;
317
+ propType.getConstraint() && (propType = propType.getConstraint());
318
+ var propTypeString = this.checker.typeToString(propType);
319
+ if (this.shouldRemoveUndefinedFromOptional && !isRequired && (propTypeString = propTypeString.replace(" | undefined", "")), propType.isUnion() && (this.shouldExtractValuesFromUnion || this.shouldExtractLiteralValuesFromEnum && propType.types.every(function(type) {
320
+ return type.getFlags() & (ts.TypeFlags.StringLiteral | ts.TypeFlags.NumberLiteral | ts.TypeFlags.EnumLiteral | ts.TypeFlags.Undefined);
321
+ }))) {
322
+ var value = propType.types.map(function(type) {
323
+ return _this.getInfoFromUnionType(type);
324
+ });
325
+ return this.shouldRemoveUndefinedFromOptional && !isRequired && (value = value.filter(function(option) {
326
+ return option.value != "undefined";
327
+ })), this.shouldSortUnions && value.sort(function(a, b) {
328
+ return a.value.toString().localeCompare(b.value.toString());
329
+ }), {
330
+ name: "enum",
331
+ raw: propTypeString,
332
+ value
333
+ };
334
+ }
335
+ return this.shouldRemoveUndefinedFromOptional && !isRequired && (propTypeString = propTypeString.replace(" | undefined", "")), { name: propTypeString };
336
+ }, Parser2.prototype.getPropsInfo = function(propsObj, defaultProps) {
337
+ var _this = this;
338
+ if (defaultProps === void 0 && (defaultProps = {}), !propsObj.valueDeclaration)
339
+ return {};
340
+ var propsType = this.checker.getTypeOfSymbolAtLocation(propsObj, propsObj.valueDeclaration), baseProps = propsType.getApparentProperties(), propertiesOfProps = baseProps;
341
+ if (propsType.isUnionOrIntersection() && (propertiesOfProps = __spreadArray(__spreadArray([], propertiesOfProps = this.checker.getAllPossiblePropertiesOfTypes(propsType.types)), baseProps), !propertiesOfProps.length)) {
342
+ var subTypes = this.checker.getAllPossiblePropertiesOfTypes(propsType.types.reduce(
343
+ // @ts-ignore
344
+ function(all, t) {
345
+ return __spreadArray(__spreadArray([], all), t.types || []);
346
+ },
347
+ []
348
+ ));
349
+ propertiesOfProps = __spreadArray(__spreadArray([], subTypes), baseProps);
350
+ }
351
+ var result = {};
352
+ return propertiesOfProps.forEach(function(prop) {
353
+ var propName = prop.getName(), parent = getParentType(prop), cacheKey = parent?.fileName + "_" + propName;
354
+ if (_this.propertiesOfPropsCache.has(cacheKey))
355
+ result[propName] = _this.propertiesOfPropsCache.get(cacheKey);
356
+ else {
357
+ var propType = _this.checker.getTypeOfSymbolAtLocation(prop, propsObj.valueDeclaration), jsDocComment = _this.findDocComment(prop), hasCodeBasedDefault = defaultProps[propName] !== void 0, defaultValue = null;
358
+ hasCodeBasedDefault ? defaultValue = { value: defaultProps[propName] } : jsDocComment.tags.default && (defaultValue = { value: jsDocComment.tags.default });
359
+ var parents = getDeclarations(prop), declarations = prop.declarations || [], baseProp = baseProps.find(function(p) {
360
+ return p.getName() === propName;
361
+ }), required = !isOptional(prop) && !hasCodeBasedDefault && // If in a intersection or union check original declaration for "?"
362
+ // @ts-ignore
363
+ declarations.every(function(d) {
364
+ return !d.questionToken;
365
+ }) && (!baseProp || !isOptional(baseProp)), type = jsDocComment.tags.type ? {
366
+ name: jsDocComment.tags.type
367
+ } : _this.getDocgenType(propType, required), propTags = _this.shouldIncludePropTagMap ? { tags: jsDocComment.tags } : {}, description = _this.shouldIncludePropTagMap ? jsDocComment.description.replace(/\r\n/g, `
368
+ `) : jsDocComment.fullComment.replace(/\r\n/g, `
369
+ `), propItem = __assign({
370
+ defaultValue,
371
+ description,
372
+ name: propName,
373
+ parent,
374
+ declarations: parents,
375
+ required,
376
+ type
377
+ }, propTags);
378
+ parent?.fileName.includes("node_modules") && _this.propertiesOfPropsCache.set(parent.fileName + "_" + propName, propItem), result[propName] = propItem;
379
+ }
380
+ }), result;
381
+ }, Parser2.prototype.findDocComment = function(symbol) {
382
+ var _this = this, comment = this.getFullJsDocComment(symbol);
383
+ if (comment.fullComment || comment.tags.default)
384
+ return comment;
385
+ var rootSymbols = this.checker.getRootSymbols(symbol), commentsOnRootSymbols = rootSymbols.filter(function(x) {
386
+ return x !== symbol;
387
+ }).map(function(x) {
388
+ return _this.getFullJsDocComment(x);
389
+ }).filter(function(x) {
390
+ return !!x.fullComment || !!comment.tags.default;
391
+ });
392
+ return commentsOnRootSymbols.length ? commentsOnRootSymbols[0] : defaultJSDoc;
393
+ }, Parser2.prototype.getFullJsDocComment = function(symbol) {
394
+ if (symbol.getDocumentationComment === void 0)
395
+ return defaultJSDoc;
396
+ var mainComment = ts.displayPartsToString(symbol.getDocumentationComment(this.checker));
397
+ mainComment && (mainComment = mainComment.replace(/\r\n/g, `
398
+ `));
399
+ var tags = symbol.getJsDocTags() || [], tagComments = [], tagMap = {};
400
+ return tags.forEach(function(tag) {
401
+ var trimmedText = ts.displayPartsToString(tag.text).trim(), currentValue = tagMap[tag.name];
402
+ tagMap[tag.name] = currentValue ? currentValue + `
403
+ ` + trimmedText : trimmedText, ["default", "type"].indexOf(tag.name) < 0 && tagComments.push(formatTag(tag));
404
+ }), {
405
+ description: mainComment,
406
+ fullComment: (mainComment + `
407
+ ` + tagComments.join(`
408
+ `)).trim(),
409
+ tags: tagMap
410
+ };
411
+ }, Parser2.prototype.getFunctionStatement = function(statement) {
412
+ if (ts.isFunctionDeclaration(statement))
413
+ return statement;
414
+ if (ts.isVariableStatement(statement)) {
415
+ var initializer = statement.declarationList && statement.declarationList.declarations[0].initializer;
416
+ if (initializer && ts.isCallExpression(initializer)) {
417
+ var symbol = this.checker.getSymbolAtLocation(initializer.expression);
418
+ if (!symbol || symbol.getName() !== "forwardRef")
419
+ return;
420
+ initializer = initializer.arguments[0];
421
+ }
422
+ if (initializer && (ts.isArrowFunction(initializer) || ts.isFunctionExpression(initializer)))
423
+ return initializer;
424
+ }
425
+ }, Parser2.prototype.extractDefaultPropsFromComponent = function(symbol, source) {
426
+ var _this = this, possibleStatements = __spreadArray(__spreadArray([], source.statements.filter(function(stmt) {
427
+ return !!stmt.name;
428
+ }).filter(function(stmt) {
429
+ return _this.checker.getSymbolAtLocation(stmt.name) === symbol;
430
+ })), source.statements.filter(function(stmt) {
431
+ return ts.isExpressionStatement(stmt) || ts.isVariableStatement(stmt);
432
+ }));
433
+ return possibleStatements.reduce(function(res, statement) {
434
+ if (statementIsClassDeclaration(statement) && statement.members.length) {
435
+ var possibleDefaultProps = statement.members.filter(function(member) {
436
+ return member.name && getPropertyName(member.name) === "defaultProps";
437
+ });
438
+ if (!possibleDefaultProps.length)
439
+ return res;
440
+ var defaultProps = possibleDefaultProps[0], initializer = defaultProps.initializer;
441
+ if (!initializer)
442
+ return res;
443
+ for (var properties = initializer.properties; ts.isIdentifier(initializer); ) {
444
+ var defaultPropsReference = _this.checker.getSymbolAtLocation(initializer);
445
+ if (defaultPropsReference) {
446
+ var declarations = defaultPropsReference.getDeclarations();
447
+ if (declarations) {
448
+ if (ts.isImportSpecifier(declarations[0])) {
449
+ var symbol2 = _this.checker.getSymbolAtLocation(declarations[0].name);
450
+ if (!symbol2)
451
+ continue;
452
+ var aliasedSymbol = _this.checker.getAliasedSymbol(symbol2);
453
+ if (aliasedSymbol && aliasedSymbol.declarations && aliasedSymbol.declarations.length)
454
+ initializer = aliasedSymbol.declarations[0].initializer;
455
+ else
456
+ continue;
457
+ } else
458
+ initializer = declarations[0].initializer;
459
+ properties = initializer.properties;
460
+ }
461
+ }
462
+ }
463
+ var propMap = {};
464
+ return properties && (propMap = _this.getPropMap(properties)), __assign(__assign({}, res), propMap);
465
+ } else if (statementIsStatelessWithDefaultProps(statement)) {
466
+ var propMap_1 = {};
467
+ return statement.getChildren().forEach(function(child) {
468
+ var right = child.right;
469
+ if (right && ts.isIdentifier(right)) {
470
+ var value = source.locals.get(right.escapedText);
471
+ value && value.valueDeclaration && ts.isVariableDeclaration(value.valueDeclaration) && value.valueDeclaration.initializer && (right = value.valueDeclaration.initializer);
472
+ }
473
+ if (right) {
474
+ var properties2 = right.properties;
475
+ properties2 && (propMap_1 = _this.getPropMap(properties2));
476
+ }
477
+ }), __assign(__assign({}, res), propMap_1);
478
+ }
479
+ var functionStatement = _this.getFunctionStatement(statement);
480
+ if (functionStatement && functionStatement.parameters && functionStatement.parameters.length) {
481
+ var name = functionStatement.parameters[0].name;
482
+ if (ts.isObjectBindingPattern(name))
483
+ return __assign(__assign({}, res), _this.getPropMap(name.elements));
484
+ }
485
+ return res;
486
+ }, {});
487
+ }, Parser2.prototype.getLiteralValueFromImportSpecifier = function(property) {
488
+ if (ts.isImportSpecifier(property)) {
489
+ var symbol = this.checker.getSymbolAtLocation(property.name);
490
+ if (!symbol)
491
+ return null;
492
+ var aliasedSymbol = this.checker.getAliasedSymbol(symbol);
493
+ return aliasedSymbol && aliasedSymbol.declarations && aliasedSymbol.declarations.length ? this.getLiteralValueFromPropertyAssignment(aliasedSymbol.declarations[0]) : null;
494
+ }
495
+ return null;
496
+ }, Parser2.prototype.getLiteralValueFromPropertyAssignment = function(property) {
497
+ var initializer = property.initializer;
498
+ if (!initializer && ts.isShorthandPropertyAssignment(property)) {
499
+ var symbol = this.checker.getShorthandAssignmentValueSymbol(property), decl = symbol && symbol.valueDeclaration;
500
+ decl && decl.initializer && (initializer = decl.initializer);
501
+ }
502
+ if (initializer)
503
+ switch (initializer.kind) {
504
+ case ts.SyntaxKind.FalseKeyword:
505
+ return this.savePropValueAsString ? "false" : !1;
506
+ case ts.SyntaxKind.TrueKeyword:
507
+ return this.savePropValueAsString ? "true" : !0;
508
+ case ts.SyntaxKind.StringLiteral:
509
+ return initializer.text.trim();
510
+ case ts.SyntaxKind.PrefixUnaryExpression:
511
+ return this.savePropValueAsString ? initializer.getFullText().trim() : Number(initializer.getFullText());
512
+ case ts.SyntaxKind.NumericLiteral:
513
+ return this.savePropValueAsString ? "" + initializer.text : Number(initializer.text);
514
+ case ts.SyntaxKind.NullKeyword:
515
+ return this.savePropValueAsString ? "null" : null;
516
+ case ts.SyntaxKind.Identifier:
517
+ if (initializer.text === "undefined")
518
+ return "undefined";
519
+ var symbol = this.checker.getSymbolAtLocation(initializer);
520
+ return symbol && symbol.declarations && symbol.declarations.length ? ts.isImportSpecifier(symbol.declarations[0]) ? this.getLiteralValueFromImportSpecifier(symbol.declarations[0]) : this.getLiteralValueFromPropertyAssignment(symbol.declarations[0]) : null;
521
+ case ts.SyntaxKind.PropertyAccessExpression: {
522
+ var symbol_1 = this.checker.getSymbolAtLocation(initializer);
523
+ if (symbol_1 && symbol_1.declarations && symbol_1.declarations.length) {
524
+ var declaration = symbol_1.declarations[0];
525
+ if (ts.isBindingElement(declaration) || ts.isPropertyAssignment(declaration))
526
+ return this.getLiteralValueFromPropertyAssignment(declaration);
527
+ }
528
+ }
529
+ case ts.SyntaxKind.ObjectLiteralExpression:
530
+ default:
531
+ try {
532
+ return initializer.getText();
533
+ } catch {
534
+ return null;
535
+ }
536
+ }
537
+ }, Parser2.prototype.getPropMap = function(properties) {
538
+ var _this = this;
539
+ return properties.reduce(function(acc, property) {
540
+ var propertyName = getPropertyName(ts.isBindingElement(property) && property.propertyName || property.name);
541
+ if (ts.isSpreadAssignment(property) || !propertyName)
542
+ return acc;
543
+ var literalValue = _this.getLiteralValueFromPropertyAssignment(property);
544
+ return (typeof literalValue == "string" || typeof literalValue == "number" || typeof literalValue == "boolean" || literalValue === null) && (acc[propertyName] = literalValue), acc;
545
+ }, {});
546
+ }, Parser2;
547
+ })()
548
+ );
549
+ exports.Parser = Parser;
550
+ function statementIsClassDeclaration(statement) {
551
+ return !!statement.members;
552
+ }
553
+ function statementIsStatelessWithDefaultProps(statement) {
554
+ for (var children = statement.getChildren(), _i = 0, children_1 = children; _i < children_1.length; _i++) {
555
+ var child = children_1[_i], left = child.left;
556
+ if (left) {
557
+ var name = left.name;
558
+ if (name && name.escapedText === "defaultProps")
559
+ return !0;
560
+ }
561
+ }
562
+ return !1;
563
+ }
564
+ function getPropertyName(name) {
565
+ switch (name.kind) {
566
+ case ts.SyntaxKind.NumericLiteral:
567
+ case ts.SyntaxKind.StringLiteral:
568
+ case ts.SyntaxKind.Identifier:
569
+ return name.text;
570
+ case ts.SyntaxKind.ComputedPropertyName:
571
+ return name.getText();
572
+ default:
573
+ return null;
574
+ }
575
+ }
576
+ function formatTag(tag) {
577
+ var result = "@" + tag.name;
578
+ return tag.text && (result += " " + ts.displayPartsToString(tag.text)), result;
579
+ }
580
+ function getTextValueOfClassMember(classDeclaration, memberName) {
581
+ var classDeclarationMembers = classDeclaration.members || [], textValue = (classDeclarationMembers && classDeclarationMembers.filter(function(member) {
582
+ return ts.isPropertyDeclaration(member);
583
+ }).filter(function(member) {
584
+ var name = ts.getNameOfDeclaration(member);
585
+ return name && name.text === memberName;
586
+ }).map(function(member) {
587
+ var property = member;
588
+ return property.initializer && property.initializer.text;
589
+ }))[0];
590
+ return textValue || "";
591
+ }
592
+ function getTextValueOfFunctionProperty(exp, source, propertyName) {
593
+ var identifierStatements = source.statements.filter(function(statement) {
594
+ return ts.isExpressionStatement(statement);
595
+ }).filter(function(statement) {
596
+ var _a, _b, _c, _d, expr = statement.expression, locals = Array.from(source.locals), hasOneLocalExport = locals.filter(function(local) {
597
+ return !!local[1].exports;
598
+ }).length === 1;
599
+ if (hasOneLocalExport)
600
+ return expr.left && expr.left.name && expr.left.name.escapedText === propertyName;
601
+ var flowNodeNameEscapedText = (_d = (_c = (_b = (_a = statement) === null || _a === void 0 ? void 0 : _a.flowNode) === null || _b === void 0 ? void 0 : _b.node) === null || _c === void 0 ? void 0 : _c.name) === null || _d === void 0 ? void 0 : _d.escapedText;
602
+ return expr.left && expr.left.name && expr.left.name.escapedText === propertyName && flowNodeNameEscapedText === exp.escapedName;
603
+ }).filter(function(statement) {
604
+ return ts.isStringLiteral(statement.expression.right);
605
+ }).map(function(statement) {
606
+ var expressionStatement = statement.expression, name = expressionStatement.left.expression.escapedText, value = expressionStatement.right.text;
607
+ return [name, value];
608
+ });
609
+ if (identifierStatements.length > 0) {
610
+ var locatedStatement = identifierStatements.find(function(statement) {
611
+ return statement[0] === exp.escapedName;
612
+ });
613
+ return locatedStatement ? locatedStatement[1] : identifierStatements[0][1] || "";
614
+ }
615
+ return "";
616
+ }
617
+ function computeComponentName(exp, source, customComponentTypes) {
618
+ customComponentTypes === void 0 && (customComponentTypes = []);
619
+ var exportName = exp.getName(), statelessDisplayName = getTextValueOfFunctionProperty(exp, source, "displayName"), statefulDisplayName = exp.valueDeclaration && ts.isClassDeclaration(exp.valueDeclaration) && getTextValueOfClassMember(exp.valueDeclaration, "displayName");
620
+ if (statelessDisplayName || statefulDisplayName)
621
+ return statelessDisplayName || statefulDisplayName || "";
622
+ var defaultComponentTypes = [
623
+ "default",
624
+ "__function",
625
+ "Stateless",
626
+ "StyledComponentClass",
627
+ "StyledComponent",
628
+ "IStyledComponent",
629
+ "FunctionComponent",
630
+ "StatelessComponent",
631
+ "ForwardRefExoticComponent",
632
+ "MemoExoticComponent"
633
+ ], supportedComponentTypes = __spreadArray(__spreadArray([], defaultComponentTypes), customComponentTypes);
634
+ return supportedComponentTypes.indexOf(exportName) !== -1 ? getDefaultExportForFile(source) : exportName;
635
+ }
636
+ function getDefaultExportForFile(source) {
637
+ var name = path.basename(source.fileName).split(".")[0], filename = name === "index" ? path.basename(path.dirname(source.fileName)) : name, identifier = filename.replace(/^[^A-Z]*/gi, "").replace(/[^A-Z0-9]*/gi, "");
638
+ return identifier.length ? identifier : "DefaultName";
639
+ }
640
+ exports.getDefaultExportForFile = getDefaultExportForFile;
641
+ function isTypeLiteral(node) {
642
+ return node.kind === ts.SyntaxKind.TypeLiteral;
643
+ }
644
+ function getDeclarations(prop) {
645
+ var declarations = prop.getDeclarations();
646
+ if (!(declarations === void 0 || declarations.length === 0)) {
647
+ for (var parents = [], _i = 0, declarations_1 = declarations; _i < declarations_1.length; _i++) {
648
+ var declaration = declarations_1[_i], parent = declaration.parent;
649
+ if (!(!isTypeLiteral(parent) && !isInterfaceOrTypeAliasDeclaration(parent))) {
650
+ var parentName = "name" in parent ? parent.name.text : "TypeLiteral", fileName = parent.getSourceFile().fileName;
651
+ parents.push({
652
+ fileName: trimFileName_1.trimFileName(fileName),
653
+ name: parentName
654
+ });
655
+ }
656
+ }
657
+ return parents;
658
+ }
659
+ }
660
+ function getParentType(prop) {
661
+ var declarations = prop.getDeclarations();
662
+ if (!(declarations == null || declarations.length === 0)) {
663
+ var parent = declarations[0].parent;
664
+ if (isInterfaceOrTypeAliasDeclaration(parent)) {
665
+ var parentName = parent.name.text, fileName = parent.getSourceFile().fileName;
666
+ return {
667
+ fileName: trimFileName_1.trimFileName(fileName),
668
+ name: parentName
669
+ };
670
+ }
671
+ }
672
+ }
673
+ function isInterfaceOrTypeAliasDeclaration(node) {
674
+ return node.kind === ts.SyntaxKind.InterfaceDeclaration || node.kind === ts.SyntaxKind.TypeAliasDeclaration;
675
+ }
676
+ function parseWithProgramProvider(filePathOrPaths, compilerOptions, parserOpts, programProvider) {
677
+ var filePaths = Array.isArray(filePathOrPaths) ? filePathOrPaths : [filePathOrPaths], program = programProvider ? programProvider() : ts.createProgram(filePaths, compilerOptions), parser = new Parser(program, parserOpts), checker = program.getTypeChecker();
678
+ return filePaths.map(function(filePath) {
679
+ return program.getSourceFile(filePath);
680
+ }).filter(function(sourceFile) {
681
+ return typeof sourceFile < "u";
682
+ }).reduce(function(docs, sourceFile) {
683
+ var moduleSymbol = checker.getSymbolAtLocation(sourceFile);
684
+ if (!moduleSymbol)
685
+ return docs;
686
+ var exports2 = checker.getExportsOfModule(moduleSymbol), componentDocs = [], exportsAndMembers = [];
687
+ exports2.forEach(function(exp) {
688
+ if (exportsAndMembers.push(exp), !!parser.isPlainObjectType(exp)) {
689
+ var typeSymbol = parser.getTypeSymbol(exp);
690
+ typeSymbol?.members && typeSymbol.members.forEach(function(member) {
691
+ exportsAndMembers.push(member);
692
+ });
693
+ }
694
+ }), exportsAndMembers.forEach(function(exp) {
695
+ var doc = parser.getComponentInfo(exp, sourceFile, parserOpts.componentNameResolver, parserOpts.customComponentTypes);
696
+ doc && componentDocs.push(doc);
697
+ var componentExports = parser.getComponentExports(exp);
698
+ componentExports && componentExports.exports.forEach(function(symbol) {
699
+ if (!(symbol.flags & ts.SymbolFlags.Prototype)) {
700
+ if (symbol.flags & ts.SymbolFlags.Method) {
701
+ var signature = parser.getCallSignature(symbol), returnType = checker.typeToString(signature.getReturnType());
702
+ if (returnType !== "Element")
703
+ return;
704
+ }
705
+ var doc2 = parser.getComponentInfo(symbol, sourceFile, parserOpts.componentNameResolver, parserOpts.customComponentTypes);
706
+ if (doc2) {
707
+ var prefix = componentExports.symbol.escapedName === "default" ? "" : componentExports.symbol.escapedName + ".";
708
+ componentDocs.push(__assign(__assign({}, doc2), { displayName: "" + prefix + symbol.escapedName }));
709
+ }
710
+ }
711
+ });
712
+ });
713
+ var componentDocsNoDuplicates = componentDocs.reduce(function(prevVal, comp) {
714
+ var duplicate = prevVal.find(function(compDoc) {
715
+ return compDoc.displayName === comp.displayName;
716
+ });
717
+ return duplicate ? prevVal : __spreadArray(__spreadArray([], prevVal), [comp]);
718
+ }, []), filteredComponentDocs = componentDocsNoDuplicates.filter(function(comp, index, comps) {
719
+ return comps.slice(index + 1).every(function(innerComp) {
720
+ return innerComp.displayName !== comp.displayName;
721
+ });
722
+ });
723
+ return __spreadArray(__spreadArray([], docs), filteredComponentDocs);
724
+ }, []);
725
+ }
726
+ }
727
+ });
728
+
729
+ // ../../../node_modules/react-docgen-typescript/lib/index.js
730
+ var require_lib = __commonJS({
731
+ "../../../node_modules/react-docgen-typescript/lib/index.js"(exports) {
732
+ Object.defineProperty(exports, "__esModule", { value: !0 });
733
+ exports.Parser = exports.withCustomConfig = exports.withDefaultConfig = exports.withCompilerOptions = exports.getDefaultExportForFile = exports.parse = void 0;
734
+ var parser_1 = require_parser();
735
+ Object.defineProperty(exports, "getDefaultExportForFile", { enumerable: !0, get: function() {
736
+ return parser_1.getDefaultExportForFile;
737
+ } });
738
+ Object.defineProperty(exports, "parse", { enumerable: !0, get: function() {
739
+ return parser_1.parse;
740
+ } });
741
+ Object.defineProperty(exports, "Parser", { enumerable: !0, get: function() {
742
+ return parser_1.Parser;
743
+ } });
744
+ Object.defineProperty(exports, "withCompilerOptions", { enumerable: !0, get: function() {
745
+ return parser_1.withCompilerOptions;
746
+ } });
747
+ Object.defineProperty(exports, "withCustomConfig", { enumerable: !0, get: function() {
748
+ return parser_1.withCustomConfig;
749
+ } });
750
+ Object.defineProperty(exports, "withDefaultConfig", { enumerable: !0, get: function() {
751
+ return parser_1.withDefaultConfig;
752
+ } });
753
+ }
754
+ });
755
+ export default require_lib();