@storybook/react 10.2.0-alpha.8 → 10.2.0-beta.0
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/_browser-chunks/{chunk-BMWJYMA6.js → chunk-HWOFIGZP.js} +1 -1
- package/dist/_browser-chunks/{chunk-GLRRNWDU.js → chunk-L3JF7GGZ.js} +2 -1
- package/dist/entry-preview.js +1 -1
- package/dist/index.d.ts +128 -10
- package/dist/index.js +2 -2
- package/dist/preset.js +898 -713
- package/dist/preview.d.ts +128 -10
- package/dist/preview.js +2 -2
- package/package.json +5 -5
package/dist/preset.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_94r7q3lra3e from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_94r7q3lra3e from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_94r7q3lra3e from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_94r7q3lra3e.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_94r7q3lra3e.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_94r7q3lra3e.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
@@ -88,11 +88,11 @@ var require_filesystem = __commonJS({
|
|
|
88
88
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
89
89
|
exports.removeExtension = exports.fileExistsAsync = exports.readJsonFromDiskAsync = exports.readJsonFromDiskSync = exports.fileExistsSync = void 0;
|
|
90
90
|
var fs = __require("fs");
|
|
91
|
-
function fileExistsSync(
|
|
92
|
-
if (!fs.existsSync(
|
|
91
|
+
function fileExistsSync(path3) {
|
|
92
|
+
if (!fs.existsSync(path3))
|
|
93
93
|
return !1;
|
|
94
94
|
try {
|
|
95
|
-
var stats = fs.statSync(
|
|
95
|
+
var stats = fs.statSync(path3);
|
|
96
96
|
return stats.isFile();
|
|
97
97
|
} catch {
|
|
98
98
|
return !1;
|
|
@@ -104,8 +104,8 @@ var require_filesystem = __commonJS({
|
|
|
104
104
|
return __require(packageJsonPath);
|
|
105
105
|
}
|
|
106
106
|
exports.readJsonFromDiskSync = readJsonFromDiskSync;
|
|
107
|
-
function readJsonFromDiskAsync(
|
|
108
|
-
fs.readFile(
|
|
107
|
+
function readJsonFromDiskAsync(path3, callback) {
|
|
108
|
+
fs.readFile(path3, "utf8", function(err, result) {
|
|
109
109
|
if (err || !result)
|
|
110
110
|
return callback();
|
|
111
111
|
var json = JSON.parse(result);
|
|
@@ -113,16 +113,16 @@ var require_filesystem = __commonJS({
|
|
|
113
113
|
});
|
|
114
114
|
}
|
|
115
115
|
exports.readJsonFromDiskAsync = readJsonFromDiskAsync;
|
|
116
|
-
function fileExistsAsync(
|
|
117
|
-
fs.stat(
|
|
116
|
+
function fileExistsAsync(path22, callback2) {
|
|
117
|
+
fs.stat(path22, function(err, stats) {
|
|
118
118
|
if (err)
|
|
119
119
|
return callback2(void 0, !1);
|
|
120
120
|
callback2(void 0, stats ? stats.isFile() : !1);
|
|
121
121
|
});
|
|
122
122
|
}
|
|
123
123
|
exports.fileExistsAsync = fileExistsAsync;
|
|
124
|
-
function removeExtension(
|
|
125
|
-
return
|
|
124
|
+
function removeExtension(path3) {
|
|
125
|
+
return path3.substring(0, path3.lastIndexOf(".")) || path3;
|
|
126
126
|
}
|
|
127
127
|
exports.removeExtension = removeExtension;
|
|
128
128
|
}
|
|
@@ -134,14 +134,14 @@ var require_mapping_entry = __commonJS({
|
|
|
134
134
|
"use strict";
|
|
135
135
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
136
136
|
exports.getAbsoluteMappingEntries = void 0;
|
|
137
|
-
var
|
|
137
|
+
var path3 = __require("path");
|
|
138
138
|
function getAbsoluteMappingEntries(absoluteBaseUrl, paths, addMatchAll) {
|
|
139
139
|
for (var sortedKeys = sortByLongestPrefix(Object.keys(paths)), absolutePaths = [], _i = 0, sortedKeys_1 = sortedKeys; _i < sortedKeys_1.length; _i++) {
|
|
140
140
|
var key = sortedKeys_1[_i];
|
|
141
141
|
absolutePaths.push({
|
|
142
142
|
pattern: key,
|
|
143
143
|
paths: paths[key].map(function(pathToResolve) {
|
|
144
|
-
return
|
|
144
|
+
return path3.resolve(absoluteBaseUrl, pathToResolve);
|
|
145
145
|
})
|
|
146
146
|
});
|
|
147
147
|
}
|
|
@@ -169,7 +169,7 @@ var require_try_path = __commonJS({
|
|
|
169
169
|
"use strict";
|
|
170
170
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
171
171
|
exports.exhaustiveTypeException = exports.getStrippedPath = exports.getPathsToTry = void 0;
|
|
172
|
-
var
|
|
172
|
+
var path3 = __require("path"), path_1 = __require("path"), filesystem_1 = require_filesystem();
|
|
173
173
|
function getPathsToTry(extensions, absolutePathMappings, requestedModule) {
|
|
174
174
|
if (!(!absolutePathMappings || !requestedModule || requestedModule[0] === ".")) {
|
|
175
175
|
for (var pathsToTry = [], _i = 0, absolutePathMappings_1 = absolutePathMappings; _i < absolutePathMappings_1.length; _i++) {
|
|
@@ -181,9 +181,9 @@ var require_try_path = __commonJS({
|
|
|
181
181
|
return { type: "extension", path: physicalPath + e };
|
|
182
182
|
})), pathsToTry.push({
|
|
183
183
|
type: "package",
|
|
184
|
-
path:
|
|
184
|
+
path: path3.join(physicalPath, "/package.json")
|
|
185
185
|
});
|
|
186
|
-
var indexPath =
|
|
186
|
+
var indexPath = path3.join(physicalPath, "/index");
|
|
187
187
|
pathsToTry.push.apply(pathsToTry, extensions.map(function(e) {
|
|
188
188
|
return { type: "index", path: indexPath + e };
|
|
189
189
|
}));
|
|
@@ -225,7 +225,7 @@ var require_match_path_sync = __commonJS({
|
|
|
225
225
|
"use strict";
|
|
226
226
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
227
227
|
exports.matchFromAbsolutePaths = exports.createMatchPath = void 0;
|
|
228
|
-
var
|
|
228
|
+
var path3 = __require("path"), Filesystem = require_filesystem(), MappingEntry = require_mapping_entry(), TryPath = require_try_path();
|
|
229
229
|
function createMatchPath2(absoluteBaseUrl, paths, mainFields, addMatchAll) {
|
|
230
230
|
mainFields === void 0 && (mainFields = ["main"]), addMatchAll === void 0 && (addMatchAll = !0);
|
|
231
231
|
var absolutePaths = MappingEntry.getAbsoluteMappingEntries(absoluteBaseUrl, paths, addMatchAll);
|
|
@@ -247,7 +247,7 @@ var require_match_path_sync = __commonJS({
|
|
|
247
247
|
return obj[key];
|
|
248
248
|
}, packageJson);
|
|
249
249
|
if (candidateMapping && typeof candidateMapping == "string") {
|
|
250
|
-
var candidateFilePath =
|
|
250
|
+
var candidateFilePath = path3.join(path3.dirname(packageJsonPath), candidateMapping);
|
|
251
251
|
if (fileExists(candidateFilePath))
|
|
252
252
|
return candidateFilePath;
|
|
253
253
|
}
|
|
@@ -280,7 +280,7 @@ var require_match_path_async = __commonJS({
|
|
|
280
280
|
"use strict";
|
|
281
281
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
282
282
|
exports.matchFromAbsolutePathsAsync = exports.createMatchPathAsync = void 0;
|
|
283
|
-
var
|
|
283
|
+
var path3 = __require("path"), TryPath = require_try_path(), MappingEntry = require_mapping_entry(), Filesystem = require_filesystem();
|
|
284
284
|
function createMatchPathAsync(absoluteBaseUrl, paths, mainFields, addMatchAll) {
|
|
285
285
|
mainFields === void 0 && (mainFields = ["main"]), addMatchAll === void 0 && (addMatchAll = !0);
|
|
286
286
|
var absolutePaths = MappingEntry.getAbsoluteMappingEntries(absoluteBaseUrl, paths, addMatchAll);
|
|
@@ -307,7 +307,7 @@ var require_match_path_async = __commonJS({
|
|
|
307
307
|
}, packageJson);
|
|
308
308
|
if (typeof mainFieldMapping != "string")
|
|
309
309
|
return tryNext();
|
|
310
|
-
var mappedFilePath =
|
|
310
|
+
var mappedFilePath = path3.join(path3.dirname(packageJsonPath), mainFieldMapping);
|
|
311
311
|
fileExistsAsync(mappedFilePath, function(err, exists) {
|
|
312
312
|
return err ? doneCallback(err) : exists ? doneCallback(void 0, mappedFilePath) : tryNext();
|
|
313
313
|
});
|
|
@@ -1219,7 +1219,7 @@ var require_tsconfig_loader = __commonJS({
|
|
|
1219
1219
|
};
|
|
1220
1220
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
1221
1221
|
exports.loadTsconfig = exports.walkForTsConfig = exports.tsConfigLoader = void 0;
|
|
1222
|
-
var
|
|
1222
|
+
var path3 = __require("path"), fs = __require("fs"), JSON5 = require_lib(), StripBom = require_strip_bom();
|
|
1223
1223
|
function tsConfigLoader(_a) {
|
|
1224
1224
|
var getEnv = _a.getEnv, cwd2 = _a.cwd, _b = _a.loadSync, loadSync = _b === void 0 ? loadSyncDefault : _b, TS_NODE_PROJECT = getEnv("TS_NODE_PROJECT"), TS_NODE_BASEURL = getEnv("TS_NODE_BASEURL"), loadResult = loadSync(cwd2, TS_NODE_PROJECT, TS_NODE_BASEURL);
|
|
1225
1225
|
return loadResult;
|
|
@@ -1242,22 +1242,22 @@ var require_tsconfig_loader = __commonJS({
|
|
|
1242
1242
|
}
|
|
1243
1243
|
function resolveConfigPath(cwd2, filename) {
|
|
1244
1244
|
if (filename) {
|
|
1245
|
-
var absolutePath = fs.lstatSync(filename).isDirectory() ?
|
|
1245
|
+
var absolutePath = fs.lstatSync(filename).isDirectory() ? path3.resolve(filename, "./tsconfig.json") : path3.resolve(cwd2, filename);
|
|
1246
1246
|
return absolutePath;
|
|
1247
1247
|
}
|
|
1248
1248
|
if (fs.statSync(cwd2).isFile())
|
|
1249
|
-
return
|
|
1249
|
+
return path3.resolve(cwd2);
|
|
1250
1250
|
var configAbsolutePath = walkForTsConfig(cwd2);
|
|
1251
|
-
return configAbsolutePath ?
|
|
1251
|
+
return configAbsolutePath ? path3.resolve(configAbsolutePath) : void 0;
|
|
1252
1252
|
}
|
|
1253
1253
|
function walkForTsConfig(directory, readdirSync) {
|
|
1254
1254
|
readdirSync === void 0 && (readdirSync = fs.readdirSync);
|
|
1255
1255
|
for (var files = readdirSync(directory), filesToCheck = ["tsconfig.json", "jsconfig.json"], _i = 0, filesToCheck_1 = filesToCheck; _i < filesToCheck_1.length; _i++) {
|
|
1256
1256
|
var fileToCheck = filesToCheck_1[_i];
|
|
1257
1257
|
if (files.indexOf(fileToCheck) !== -1)
|
|
1258
|
-
return
|
|
1258
|
+
return path3.join(directory, fileToCheck);
|
|
1259
1259
|
}
|
|
1260
|
-
var parentDirectory =
|
|
1260
|
+
var parentDirectory = path3.dirname(directory);
|
|
1261
1261
|
if (directory !== parentDirectory)
|
|
1262
1262
|
return walkForTsConfig(parentDirectory, readdirSync);
|
|
1263
1263
|
}
|
|
@@ -1286,12 +1286,12 @@ var require_tsconfig_loader = __commonJS({
|
|
|
1286
1286
|
function loadTsconfigFromExtends(configFilePath, extendedConfigValue, existsSync3, readFileSync2) {
|
|
1287
1287
|
var _a;
|
|
1288
1288
|
typeof extendedConfigValue == "string" && extendedConfigValue.indexOf(".json") === -1 && (extendedConfigValue += ".json");
|
|
1289
|
-
var currentDir =
|
|
1290
|
-
extendedConfigValue.indexOf("/") !== -1 && extendedConfigValue.indexOf(".") !== -1 && !existsSync3(extendedConfigPath) && (extendedConfigPath =
|
|
1289
|
+
var currentDir = path3.dirname(configFilePath), extendedConfigPath = path3.join(currentDir, extendedConfigValue);
|
|
1290
|
+
extendedConfigValue.indexOf("/") !== -1 && extendedConfigValue.indexOf(".") !== -1 && !existsSync3(extendedConfigPath) && (extendedConfigPath = path3.join(currentDir, "node_modules", extendedConfigValue));
|
|
1291
1291
|
var config = loadTsconfig(extendedConfigPath, existsSync3, readFileSync2) || {};
|
|
1292
1292
|
if (!((_a = config.compilerOptions) === null || _a === void 0) && _a.baseUrl) {
|
|
1293
|
-
var extendsDir =
|
|
1294
|
-
config.compilerOptions.baseUrl =
|
|
1293
|
+
var extendsDir = path3.dirname(extendedConfigValue);
|
|
1294
|
+
config.compilerOptions.baseUrl = path3.join(extendsDir, config.compilerOptions.baseUrl);
|
|
1295
1295
|
}
|
|
1296
1296
|
return config;
|
|
1297
1297
|
}
|
|
@@ -1307,7 +1307,7 @@ var require_config_loader = __commonJS({
|
|
|
1307
1307
|
"use strict";
|
|
1308
1308
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
1309
1309
|
exports.configLoader = exports.loadConfig = void 0;
|
|
1310
|
-
var TsConfigLoader2 = require_tsconfig_loader(),
|
|
1310
|
+
var TsConfigLoader2 = require_tsconfig_loader(), path3 = __require("path");
|
|
1311
1311
|
function loadConfig2(cwd2) {
|
|
1312
1312
|
return cwd2 === void 0 && (cwd2 = process.cwd()), configLoader({ cwd: cwd2 });
|
|
1313
1313
|
}
|
|
@@ -1315,7 +1315,7 @@ var require_config_loader = __commonJS({
|
|
|
1315
1315
|
function configLoader(_a) {
|
|
1316
1316
|
var cwd2 = _a.cwd, explicitParams = _a.explicitParams, _b = _a.tsConfigLoader, tsConfigLoader = _b === void 0 ? TsConfigLoader2.tsConfigLoader : _b;
|
|
1317
1317
|
if (explicitParams) {
|
|
1318
|
-
var absoluteBaseUrl =
|
|
1318
|
+
var absoluteBaseUrl = path3.isAbsolute(explicitParams.baseUrl) ? explicitParams.baseUrl : path3.join(cwd2, explicitParams.baseUrl);
|
|
1319
1319
|
return {
|
|
1320
1320
|
resultType: "success",
|
|
1321
1321
|
configFileAbsolutePath: "",
|
|
@@ -1336,7 +1336,7 @@ var require_config_loader = __commonJS({
|
|
|
1336
1336
|
resultType: "success",
|
|
1337
1337
|
configFileAbsolutePath: loadResult.tsConfigPath,
|
|
1338
1338
|
baseUrl: loadResult.baseUrl,
|
|
1339
|
-
absoluteBaseUrl:
|
|
1339
|
+
absoluteBaseUrl: path3.resolve(path3.dirname(loadResult.tsConfigPath), loadResult.baseUrl || ""),
|
|
1340
1340
|
paths: loadResult.paths || {},
|
|
1341
1341
|
addMatchAll: loadResult.baseUrl !== void 0
|
|
1342
1342
|
} : {
|
|
@@ -1666,14 +1666,14 @@ var require_path_parse = __commonJS({
|
|
|
1666
1666
|
// ../../../node_modules/resolve/lib/node-modules-paths.js
|
|
1667
1667
|
var require_node_modules_paths = __commonJS({
|
|
1668
1668
|
"../../../node_modules/resolve/lib/node-modules-paths.js"(exports, module) {
|
|
1669
|
-
var
|
|
1669
|
+
var path3 = __require("path"), parse4 = path3.parse || require_path_parse(), driveLetterRegex = /^([A-Za-z]:)/, uncPathRegex = /^\\\\/, getNodeModulesDirs = function(absoluteStart, modules) {
|
|
1670
1670
|
var prefix = "/";
|
|
1671
1671
|
driveLetterRegex.test(absoluteStart) ? prefix = "" : uncPathRegex.test(absoluteStart) && (prefix = "\\\\");
|
|
1672
1672
|
for (var paths = [absoluteStart], parsed = parse4(absoluteStart); parsed.dir !== paths[paths.length - 1]; )
|
|
1673
1673
|
paths.push(parsed.dir), parsed = parse4(parsed.dir);
|
|
1674
1674
|
return paths.reduce(function(dirs, aPath) {
|
|
1675
1675
|
return dirs.concat(modules.map(function(moduleDir) {
|
|
1676
|
-
return
|
|
1676
|
+
return path3.resolve(prefix, aPath, moduleDir);
|
|
1677
1677
|
}));
|
|
1678
1678
|
}, []);
|
|
1679
1679
|
};
|
|
@@ -1697,7 +1697,7 @@ var require_node_modules_paths = __commonJS({
|
|
|
1697
1697
|
// ../../../node_modules/resolve/lib/normalize-options.js
|
|
1698
1698
|
var require_normalize_options = __commonJS({
|
|
1699
1699
|
"../../../node_modules/resolve/lib/normalize-options.js"(exports, module) {
|
|
1700
|
-
var
|
|
1700
|
+
var path3 = __require("path");
|
|
1701
1701
|
module.exports = function(_, opts) {
|
|
1702
1702
|
if (opts = opts || {}, opts.forceNodeResolution || !process.versions.pnp)
|
|
1703
1703
|
return opts;
|
|
@@ -1705,7 +1705,7 @@ var require_normalize_options = __commonJS({
|
|
|
1705
1705
|
let parts = request.match(/^((?:@[^/]+\/)?[^/]+)(\/.*)?/);
|
|
1706
1706
|
if (!parts)
|
|
1707
1707
|
throw new Error(`Assertion failed: Expected the "resolve" package to call the "paths" callback with package names only (got "${request}")`);
|
|
1708
|
-
basedir.charAt(basedir.length - 1) !== "/" && (basedir =
|
|
1708
|
+
basedir.charAt(basedir.length - 1) !== "/" && (basedir = path3.join(basedir, "/"));
|
|
1709
1709
|
let api = findPnpApi(basedir);
|
|
1710
1710
|
if (api === null)
|
|
1711
1711
|
return;
|
|
@@ -1717,7 +1717,7 @@ var require_normalize_options = __commonJS({
|
|
|
1717
1717
|
}
|
|
1718
1718
|
if (manifestPath === null)
|
|
1719
1719
|
throw new Error(`Assertion failed: The resolution thinks that "${parts[1]}" is a Node builtin`);
|
|
1720
|
-
let packagePath =
|
|
1720
|
+
let packagePath = path3.dirname(manifestPath), unqualifiedPath = typeof parts[2] < "u" ? path3.join(packagePath, parts[2]) : packagePath;
|
|
1721
1721
|
return { packagePath, unqualifiedPath };
|
|
1722
1722
|
}, runPnpResolutionOnArray = (request, paths2) => {
|
|
1723
1723
|
for (let i = 0; i < paths2.length; i++) {
|
|
@@ -1733,8 +1733,8 @@ var require_normalize_options = __commonJS({
|
|
|
1733
1733
|
let pathsToTest = [basedir].concat(originalPaths), resolution = runPnpResolutionOnArray(request, pathsToTest);
|
|
1734
1734
|
if (resolution == null)
|
|
1735
1735
|
return getNodeModulePaths().concat(originalPaths);
|
|
1736
|
-
let nodeModules =
|
|
1737
|
-
return request.match(/^@[^/]+\//) && (nodeModules =
|
|
1736
|
+
let nodeModules = path3.dirname(resolution.packagePath);
|
|
1737
|
+
return request.match(/^@[^/]+\//) && (nodeModules = path3.dirname(nodeModules)), [nodeModules];
|
|
1738
1738
|
}, isInsideIterator = !1;
|
|
1739
1739
|
return opts.__skipPackageIterator || (opts.packageIterator = function(request, basedir, getCandidates, opts2) {
|
|
1740
1740
|
isInsideIterator = !0;
|
|
@@ -2029,10 +2029,10 @@ var require_is_core_module = __commonJS({
|
|
|
2029
2029
|
// ../../../node_modules/resolve/lib/async.js
|
|
2030
2030
|
var require_async = __commonJS({
|
|
2031
2031
|
"../../../node_modules/resolve/lib/async.js"(exports, module) {
|
|
2032
|
-
var fs = __require("fs"), getHomedir = require_homedir(),
|
|
2032
|
+
var fs = __require("fs"), getHomedir = require_homedir(), path3 = __require("path"), caller = require_caller(), nodeModulesPaths = require_node_modules_paths(), normalizeOptions = require_normalize_options(), isCore = require_is_core_module(), realpathFS = process.platform !== "win32" && fs.realpath && typeof fs.realpath.native == "function" ? fs.realpath.native : fs.realpath, relativePathRegex = /^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/, windowsDriveRegex = /^\w:[/\\]*$/, nodeModulesRegex = /[/\\]node_modules[/\\]*$/, homedir = getHomedir(), defaultPaths = function() {
|
|
2033
2033
|
return [
|
|
2034
|
-
|
|
2035
|
-
|
|
2034
|
+
path3.join(homedir, ".node_modules"),
|
|
2035
|
+
path3.join(homedir, ".node_libraries")
|
|
2036
2036
|
];
|
|
2037
2037
|
}, defaultIsFile = function(file, cb) {
|
|
2038
2038
|
fs.stat(file, function(err, stat) {
|
|
@@ -2061,7 +2061,7 @@ var require_async = __commonJS({
|
|
|
2061
2061
|
});
|
|
2062
2062
|
}, getPackageCandidates = function(x, start, opts) {
|
|
2063
2063
|
for (var dirs = nodeModulesPaths(start, opts, x), i = 0; i < dirs.length; i++)
|
|
2064
|
-
dirs[i] =
|
|
2064
|
+
dirs[i] = path3.join(dirs[i], x);
|
|
2065
2065
|
return dirs;
|
|
2066
2066
|
};
|
|
2067
2067
|
module.exports = function(x, options, callback) {
|
|
@@ -2080,9 +2080,9 @@ var require_async = __commonJS({
|
|
|
2080
2080
|
cb(conflictErr);
|
|
2081
2081
|
});
|
|
2082
2082
|
}
|
|
2083
|
-
var packageIterator = opts.packageIterator, extensions = opts.extensions || [".js"], includeCoreModules = opts.includeCoreModules !== !1, basedir = opts.basedir ||
|
|
2083
|
+
var packageIterator = opts.packageIterator, extensions = opts.extensions || [".js"], includeCoreModules = opts.includeCoreModules !== !1, basedir = opts.basedir || path3.dirname(caller()), parent = opts.filename || basedir;
|
|
2084
2084
|
opts.paths = opts.paths || defaultPaths();
|
|
2085
|
-
var absoluteStart =
|
|
2085
|
+
var absoluteStart = path3.resolve(basedir);
|
|
2086
2086
|
maybeRealpath(
|
|
2087
2087
|
realpath,
|
|
2088
2088
|
absoluteStart,
|
|
@@ -2094,7 +2094,7 @@ var require_async = __commonJS({
|
|
|
2094
2094
|
var res;
|
|
2095
2095
|
function init(basedir2) {
|
|
2096
2096
|
if (relativePathRegex.test(x))
|
|
2097
|
-
res =
|
|
2097
|
+
res = path3.resolve(basedir2, x), (x === "." || x === ".." || x.slice(-1) === "/") && (res += "/"), x.slice(-1) === "/" && res === basedir2 ? loadAsDirectory(res, opts.package, onfile) : loadAsFile(res, opts.package, onfile);
|
|
2098
2098
|
else {
|
|
2099
2099
|
if (includeCoreModules && isCore(x))
|
|
2100
2100
|
return cb(null, x);
|
|
@@ -2132,14 +2132,14 @@ var require_async = __commonJS({
|
|
|
2132
2132
|
function load(exts2, x3, loadPackage) {
|
|
2133
2133
|
if (exts2.length === 0) return cb2(null, void 0, loadPackage);
|
|
2134
2134
|
var file = x3 + exts2[0], pkg = loadPackage;
|
|
2135
|
-
pkg ? onpkg(null, pkg) : loadpkg(
|
|
2135
|
+
pkg ? onpkg(null, pkg) : loadpkg(path3.dirname(file), onpkg);
|
|
2136
2136
|
function onpkg(err2, pkg_, dir) {
|
|
2137
2137
|
if (pkg = pkg_, err2) return cb2(err2);
|
|
2138
2138
|
if (dir && pkg && opts.pathFilter) {
|
|
2139
|
-
var rfile =
|
|
2139
|
+
var rfile = path3.relative(dir, file), rel = rfile.slice(0, rfile.length - exts2[0].length), r = opts.pathFilter(pkg, x3, rel);
|
|
2140
2140
|
if (r) return load(
|
|
2141
2141
|
[""].concat(extensions.slice()),
|
|
2142
|
-
|
|
2142
|
+
path3.resolve(dir, r),
|
|
2143
2143
|
pkg
|
|
2144
2144
|
);
|
|
2145
2145
|
}
|
|
@@ -2155,10 +2155,10 @@ var require_async = __commonJS({
|
|
|
2155
2155
|
function loadpkg(dir, cb2) {
|
|
2156
2156
|
if (dir === "" || dir === "/" || process.platform === "win32" && windowsDriveRegex.test(dir) || nodeModulesRegex.test(dir)) return cb2(null);
|
|
2157
2157
|
maybeRealpath(realpath, dir, opts, function(unwrapErr, pkgdir) {
|
|
2158
|
-
if (unwrapErr) return loadpkg(
|
|
2159
|
-
var pkgfile =
|
|
2158
|
+
if (unwrapErr) return loadpkg(path3.dirname(dir), cb2);
|
|
2159
|
+
var pkgfile = path3.join(pkgdir, "package.json");
|
|
2160
2160
|
isFile(pkgfile, function(err2, ex) {
|
|
2161
|
-
if (!ex) return loadpkg(
|
|
2161
|
+
if (!ex) return loadpkg(path3.dirname(dir), cb2);
|
|
2162
2162
|
readPackage(readFile, pkgfile, function(err3, pkgParam) {
|
|
2163
2163
|
err3 && cb2(err3);
|
|
2164
2164
|
var pkg = pkgParam;
|
|
@@ -2171,10 +2171,10 @@ var require_async = __commonJS({
|
|
|
2171
2171
|
var cb2 = callback2, fpkg = loadAsDirectoryPackage;
|
|
2172
2172
|
typeof fpkg == "function" && (cb2 = fpkg, fpkg = opts.package), maybeRealpath(realpath, x2, opts, function(unwrapErr, pkgdir) {
|
|
2173
2173
|
if (unwrapErr) return cb2(unwrapErr);
|
|
2174
|
-
var pkgfile =
|
|
2174
|
+
var pkgfile = path3.join(pkgdir, "package.json");
|
|
2175
2175
|
isFile(pkgfile, function(err2, ex) {
|
|
2176
2176
|
if (err2) return cb2(err2);
|
|
2177
|
-
if (!ex) return loadAsFile(
|
|
2177
|
+
if (!ex) return loadAsFile(path3.join(x2, "index"), fpkg, cb2);
|
|
2178
2178
|
readPackage(readFile, pkgfile, function(err3, pkgParam) {
|
|
2179
2179
|
if (err3) return cb2(err3);
|
|
2180
2180
|
var pkg = pkgParam;
|
|
@@ -2183,20 +2183,20 @@ var require_async = __commonJS({
|
|
|
2183
2183
|
var mainError = new TypeError("package \u201C" + pkg.name + "\u201D `main` must be a string");
|
|
2184
2184
|
return mainError.code = "INVALID_PACKAGE_MAIN", cb2(mainError);
|
|
2185
2185
|
}
|
|
2186
|
-
(pkg.main === "." || pkg.main === "./") && (pkg.main = "index"), loadAsFile(
|
|
2186
|
+
(pkg.main === "." || pkg.main === "./") && (pkg.main = "index"), loadAsFile(path3.resolve(x2, pkg.main), pkg, function(err4, m, pkg2) {
|
|
2187
2187
|
if (err4) return cb2(err4);
|
|
2188
2188
|
if (m) return cb2(null, m, pkg2);
|
|
2189
|
-
if (!pkg2) return loadAsFile(
|
|
2190
|
-
var dir =
|
|
2189
|
+
if (!pkg2) return loadAsFile(path3.join(x2, "index"), pkg2, cb2);
|
|
2190
|
+
var dir = path3.resolve(x2, pkg2.main);
|
|
2191
2191
|
loadAsDirectory(dir, pkg2, function(err5, n, pkg3) {
|
|
2192
2192
|
if (err5) return cb2(err5);
|
|
2193
2193
|
if (n) return cb2(null, n, pkg3);
|
|
2194
|
-
loadAsFile(
|
|
2194
|
+
loadAsFile(path3.join(x2, "index"), pkg3, cb2);
|
|
2195
2195
|
});
|
|
2196
2196
|
});
|
|
2197
2197
|
return;
|
|
2198
2198
|
}
|
|
2199
|
-
loadAsFile(
|
|
2199
|
+
loadAsFile(path3.join(x2, "/index"), pkg, cb2);
|
|
2200
2200
|
});
|
|
2201
2201
|
});
|
|
2202
2202
|
});
|
|
@@ -2204,7 +2204,7 @@ var require_async = __commonJS({
|
|
|
2204
2204
|
function processDirs(cb2, dirs) {
|
|
2205
2205
|
if (dirs.length === 0) return cb2(null, void 0);
|
|
2206
2206
|
var dir = dirs[0];
|
|
2207
|
-
isDirectory(
|
|
2207
|
+
isDirectory(path3.dirname(dir), isdir);
|
|
2208
2208
|
function isdir(err2, isdir2) {
|
|
2209
2209
|
if (err2) return cb2(err2);
|
|
2210
2210
|
if (!isdir2) return processDirs(cb2, dirs.slice(1));
|
|
@@ -2427,10 +2427,10 @@ var require_is_core = __commonJS({
|
|
|
2427
2427
|
// ../../../node_modules/resolve/lib/sync.js
|
|
2428
2428
|
var require_sync = __commonJS({
|
|
2429
2429
|
"../../../node_modules/resolve/lib/sync.js"(exports, module) {
|
|
2430
|
-
var isCore = require_is_core_module(), fs = __require("fs"),
|
|
2430
|
+
var isCore = require_is_core_module(), fs = __require("fs"), path3 = __require("path"), getHomedir = require_homedir(), caller = require_caller(), nodeModulesPaths = require_node_modules_paths(), normalizeOptions = require_normalize_options(), realpathFS = process.platform !== "win32" && fs.realpathSync && typeof fs.realpathSync.native == "function" ? fs.realpathSync.native : fs.realpathSync, relativePathRegex = /^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/, windowsDriveRegex = /^\w:[/\\]*$/, nodeModulesRegex = /[/\\]node_modules[/\\]*$/, homedir = getHomedir(), defaultPaths = function() {
|
|
2431
2431
|
return [
|
|
2432
|
-
|
|
2433
|
-
|
|
2432
|
+
path3.join(homedir, ".node_modules"),
|
|
2433
|
+
path3.join(homedir, ".node_libraries")
|
|
2434
2434
|
];
|
|
2435
2435
|
}, defaultIsFile = function(file) {
|
|
2436
2436
|
try {
|
|
@@ -2467,7 +2467,7 @@ var require_sync = __commonJS({
|
|
|
2467
2467
|
}
|
|
2468
2468
|
}, getPackageCandidates = function(x, start, opts) {
|
|
2469
2469
|
for (var dirs = nodeModulesPaths(start, opts, x), i = 0; i < dirs.length; i++)
|
|
2470
|
-
dirs[i] =
|
|
2470
|
+
dirs[i] = path3.join(dirs[i], x);
|
|
2471
2471
|
return dirs;
|
|
2472
2472
|
};
|
|
2473
2473
|
module.exports = function(x, options) {
|
|
@@ -2476,11 +2476,11 @@ var require_sync = __commonJS({
|
|
|
2476
2476
|
var opts = normalizeOptions(x, options), isFile = opts.isFile || defaultIsFile, readFileSync2 = opts.readFileSync || fs.readFileSync, isDirectory = opts.isDirectory || defaultIsDir, realpathSync = opts.realpathSync || defaultRealpathSync, readPackageSync = opts.readPackageSync || defaultReadPackageSync;
|
|
2477
2477
|
if (opts.readFileSync && opts.readPackageSync)
|
|
2478
2478
|
throw new TypeError("`readFileSync` and `readPackageSync` are mutually exclusive.");
|
|
2479
|
-
var packageIterator = opts.packageIterator, extensions = opts.extensions || [".js"], includeCoreModules = opts.includeCoreModules !== !1, basedir = opts.basedir ||
|
|
2479
|
+
var packageIterator = opts.packageIterator, extensions = opts.extensions || [".js"], includeCoreModules = opts.includeCoreModules !== !1, basedir = opts.basedir || path3.dirname(caller()), parent = opts.filename || basedir;
|
|
2480
2480
|
opts.paths = opts.paths || defaultPaths();
|
|
2481
|
-
var absoluteStart = maybeRealpathSync(realpathSync,
|
|
2481
|
+
var absoluteStart = maybeRealpathSync(realpathSync, path3.resolve(basedir), opts);
|
|
2482
2482
|
if (relativePathRegex.test(x)) {
|
|
2483
|
-
var res =
|
|
2483
|
+
var res = path3.resolve(absoluteStart, x);
|
|
2484
2484
|
(x === "." || x === ".." || x.slice(-1) === "/") && (res += "/");
|
|
2485
2485
|
var m = loadAsFileSync(res) || loadAsDirectorySync(res);
|
|
2486
2486
|
if (m) return maybeRealpathSync(realpathSync, m, opts);
|
|
@@ -2493,10 +2493,10 @@ var require_sync = __commonJS({
|
|
|
2493
2493
|
var err = new Error("Cannot find module '" + x + "' from '" + parent + "'");
|
|
2494
2494
|
throw err.code = "MODULE_NOT_FOUND", err;
|
|
2495
2495
|
function loadAsFileSync(x2) {
|
|
2496
|
-
var pkg = loadpkg(
|
|
2496
|
+
var pkg = loadpkg(path3.dirname(x2));
|
|
2497
2497
|
if (pkg && pkg.dir && pkg.pkg && opts.pathFilter) {
|
|
2498
|
-
var rfile =
|
|
2499
|
-
r && (x2 =
|
|
2498
|
+
var rfile = path3.relative(pkg.dir, x2), r = opts.pathFilter(pkg.pkg, x2, rfile);
|
|
2499
|
+
r && (x2 = path3.resolve(pkg.dir, r));
|
|
2500
2500
|
}
|
|
2501
2501
|
if (isFile(x2))
|
|
2502
2502
|
return x2;
|
|
@@ -2508,9 +2508,9 @@ var require_sync = __commonJS({
|
|
|
2508
2508
|
}
|
|
2509
2509
|
function loadpkg(dir) {
|
|
2510
2510
|
if (!(dir === "" || dir === "/") && !(process.platform === "win32" && windowsDriveRegex.test(dir)) && !nodeModulesRegex.test(dir)) {
|
|
2511
|
-
var pkgfile =
|
|
2511
|
+
var pkgfile = path3.join(maybeRealpathSync(realpathSync, dir, opts), "package.json");
|
|
2512
2512
|
if (!isFile(pkgfile))
|
|
2513
|
-
return loadpkg(
|
|
2513
|
+
return loadpkg(path3.dirname(dir));
|
|
2514
2514
|
var pkg = readPackageSync(readFileSync2, pkgfile);
|
|
2515
2515
|
return pkg && opts.packageFilter && (pkg = opts.packageFilter(
|
|
2516
2516
|
pkg,
|
|
@@ -2520,7 +2520,7 @@ var require_sync = __commonJS({
|
|
|
2520
2520
|
}
|
|
2521
2521
|
}
|
|
2522
2522
|
function loadAsDirectorySync(x2) {
|
|
2523
|
-
var pkgfile =
|
|
2523
|
+
var pkgfile = path3.join(maybeRealpathSync(realpathSync, x2, opts), "/package.json");
|
|
2524
2524
|
if (isFile(pkgfile)) {
|
|
2525
2525
|
try {
|
|
2526
2526
|
var pkg = readPackageSync(readFileSync2, pkgfile);
|
|
@@ -2537,22 +2537,22 @@ var require_sync = __commonJS({
|
|
|
2537
2537
|
}
|
|
2538
2538
|
(pkg.main === "." || pkg.main === "./") && (pkg.main = "index");
|
|
2539
2539
|
try {
|
|
2540
|
-
var m2 = loadAsFileSync(
|
|
2540
|
+
var m2 = loadAsFileSync(path3.resolve(x2, pkg.main));
|
|
2541
2541
|
if (m2) return m2;
|
|
2542
|
-
var n2 = loadAsDirectorySync(
|
|
2542
|
+
var n2 = loadAsDirectorySync(path3.resolve(x2, pkg.main));
|
|
2543
2543
|
if (n2) return n2;
|
|
2544
2544
|
} catch {
|
|
2545
2545
|
}
|
|
2546
2546
|
}
|
|
2547
2547
|
}
|
|
2548
|
-
return loadAsFileSync(
|
|
2548
|
+
return loadAsFileSync(path3.join(x2, "/index"));
|
|
2549
2549
|
}
|
|
2550
2550
|
function loadNodeModulesSync(x2, start) {
|
|
2551
2551
|
for (var thunk = function() {
|
|
2552
2552
|
return getPackageCandidates(x2, start, opts);
|
|
2553
2553
|
}, dirs = packageIterator ? packageIterator(x2, start, thunk, opts) : thunk(), i = 0; i < dirs.length; i++) {
|
|
2554
2554
|
var dir = dirs[i];
|
|
2555
|
-
if (isDirectory(
|
|
2555
|
+
if (isDirectory(path3.dirname(dir))) {
|
|
2556
2556
|
var m2 = loadAsFileSync(dir);
|
|
2557
2557
|
if (m2) return m2;
|
|
2558
2558
|
var n2 = loadAsDirectorySync(dir);
|
|
@@ -2576,7 +2576,9 @@ var require_resolve = __commonJS({
|
|
|
2576
2576
|
});
|
|
2577
2577
|
|
|
2578
2578
|
// src/preset.ts
|
|
2579
|
+
import path2, { join as join5 } from "node:path";
|
|
2579
2580
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
2581
|
+
import { getProjectRoot as getProjectRoot2 } from "storybook/internal/common";
|
|
2580
2582
|
|
|
2581
2583
|
// ../../core/src/shared/utils/module.ts
|
|
2582
2584
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
@@ -2710,12 +2712,12 @@ var _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
|
|
2710
2712
|
function normalizeWindowsPath(input = "") {
|
|
2711
2713
|
return input && input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
|
|
2712
2714
|
}
|
|
2713
|
-
var _UNC_REGEX = /^[/\\]{2}/, _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/, _DRIVE_LETTER_RE = /^[A-Za-z]:$/, _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/, sep = "/", delimiter = ":", normalize = function(
|
|
2714
|
-
if (
|
|
2715
|
+
var _UNC_REGEX = /^[/\\]{2}/, _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/, _DRIVE_LETTER_RE = /^[A-Za-z]:$/, _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/, sep = "/", delimiter = ":", normalize = function(path3) {
|
|
2716
|
+
if (path3.length === 0)
|
|
2715
2717
|
return ".";
|
|
2716
|
-
|
|
2717
|
-
let isUNCPath =
|
|
2718
|
-
return
|
|
2718
|
+
path3 = normalizeWindowsPath(path3);
|
|
2719
|
+
let isUNCPath = path3.match(_UNC_REGEX), isPathAbsolute = isAbsolute(path3), trailingSeparator = path3[path3.length - 1] === "/";
|
|
2720
|
+
return path3 = normalizeString(path3, !isPathAbsolute), path3.length === 0 ? isPathAbsolute ? "/" : trailingSeparator ? "./" : "." : (trailingSeparator && (path3 += "/"), _DRIVE_LETTER_RE.test(path3) && (path3 += "/"), isUNCPath ? isPathAbsolute ? `//${path3}` : `//./${path3}` : isPathAbsolute && !isAbsolute(path3) ? `/${path3}` : path3);
|
|
2719
2721
|
}, join = function(...arguments_) {
|
|
2720
2722
|
if (arguments_.length === 0)
|
|
2721
2723
|
return ".";
|
|
@@ -2731,16 +2733,16 @@ var resolve = function(...arguments_) {
|
|
|
2731
2733
|
arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
|
|
2732
2734
|
let resolvedPath = "", resolvedAbsolute = !1;
|
|
2733
2735
|
for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
|
|
2734
|
-
let
|
|
2735
|
-
!
|
|
2736
|
+
let path3 = index >= 0 ? arguments_[index] : cwd();
|
|
2737
|
+
!path3 || path3.length === 0 || (resolvedPath = `${path3}/${resolvedPath}`, resolvedAbsolute = isAbsolute(path3));
|
|
2736
2738
|
}
|
|
2737
2739
|
return resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute), resolvedAbsolute && !isAbsolute(resolvedPath) ? `/${resolvedPath}` : resolvedPath.length > 0 ? resolvedPath : ".";
|
|
2738
2740
|
};
|
|
2739
|
-
function normalizeString(
|
|
2741
|
+
function normalizeString(path3, allowAboveRoot) {
|
|
2740
2742
|
let res = "", lastSegmentLength = 0, lastSlash = -1, dots = 0, char = null;
|
|
2741
|
-
for (let index = 0; index <=
|
|
2742
|
-
if (index <
|
|
2743
|
-
char =
|
|
2743
|
+
for (let index = 0; index <= path3.length; ++index) {
|
|
2744
|
+
if (index < path3.length)
|
|
2745
|
+
char = path3[index];
|
|
2744
2746
|
else {
|
|
2745
2747
|
if (char === "/")
|
|
2746
2748
|
break;
|
|
@@ -2760,7 +2762,7 @@ function normalizeString(path2, allowAboveRoot) {
|
|
|
2760
2762
|
}
|
|
2761
2763
|
allowAboveRoot && (res += res.length > 0 ? "/.." : "..", lastSegmentLength = 2);
|
|
2762
2764
|
} else
|
|
2763
|
-
res.length > 0 ? res += `/${
|
|
2765
|
+
res.length > 0 ? res += `/${path3.slice(lastSlash + 1, index)}` : res = path3.slice(lastSlash + 1, index), lastSegmentLength = index - lastSlash - 1;
|
|
2764
2766
|
lastSlash = index, dots = 0;
|
|
2765
2767
|
} else char === "." && dots !== -1 ? ++dots : dots = -1;
|
|
2766
2768
|
}
|
|
@@ -2833,19 +2835,15 @@ var importMetaResolve = (...args) => typeof import.meta.resolve != "function" &&
|
|
|
2833
2835
|
}
|
|
2834
2836
|
};
|
|
2835
2837
|
|
|
2836
|
-
// src/componentManifest/
|
|
2837
|
-
import {
|
|
2838
|
-
import { combineTags } from "storybook/internal/csf";
|
|
2839
|
-
import { extractDescription, loadCsf } from "storybook/internal/csf-tools";
|
|
2840
|
-
import { logger as logger4 } from "storybook/internal/node-logger";
|
|
2841
|
-
|
|
2842
|
-
// src/componentManifest/generateCodeSnippet.ts
|
|
2843
|
-
import { types as t } from "storybook/internal/babel";
|
|
2838
|
+
// src/componentManifest/reactDocgen/extractDocgenInfo.ts
|
|
2839
|
+
import { logger as logger3 } from "storybook/internal/node-logger";
|
|
2844
2840
|
|
|
2845
|
-
// src/componentManifest/
|
|
2846
|
-
import {
|
|
2847
|
-
import {
|
|
2848
|
-
import {
|
|
2841
|
+
// src/componentManifest/reactDocgen.ts
|
|
2842
|
+
import { existsSync as existsSync2 } from "node:fs";
|
|
2843
|
+
import { dirname as dirname3, sep as sep2 } from "node:path";
|
|
2844
|
+
import { babelParse, types as t } from "storybook/internal/babel";
|
|
2845
|
+
import { getProjectRoot, supportedExtensions as supportedExtensions2 } from "storybook/internal/common";
|
|
2846
|
+
import { logger as logger2 } from "storybook/internal/node-logger";
|
|
2849
2847
|
|
|
2850
2848
|
// ../../../node_modules/empathic/find.mjs
|
|
2851
2849
|
import { join as join3 } from "node:path";
|
|
@@ -2862,7 +2860,7 @@ function absolute(input, root) {
|
|
|
2862
2860
|
|
|
2863
2861
|
// ../../../node_modules/empathic/walk.mjs
|
|
2864
2862
|
function up(base, options) {
|
|
2865
|
-
let { last, cwd: cwd2 } = options || {}, tmp = absolute(base, cwd2), root = absolute(
|
|
2863
|
+
let { last: last2, cwd: cwd2 } = options || {}, tmp = absolute(base, cwd2), root = absolute(last2 || "/", cwd2), prev, arr = [];
|
|
2866
2864
|
for (; prev !== root && (arr.push(tmp), tmp = dirname2(prev = tmp), tmp !== prev); )
|
|
2867
2865
|
;
|
|
2868
2866
|
return arr;
|
|
@@ -2875,413 +2873,106 @@ function up2(name, options) {
|
|
|
2875
2873
|
if (tmp = join3(dir, name), existsSync(tmp)) return tmp;
|
|
2876
2874
|
}
|
|
2877
2875
|
|
|
2878
|
-
// src/componentManifest/
|
|
2879
|
-
var
|
|
2880
|
-
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2876
|
+
// src/componentManifest/reactDocgen.ts
|
|
2877
|
+
var import_ts_dedent = __toESM(require_dist(), 1), TsconfigPaths = __toESM(require_lib2(), 1);
|
|
2878
|
+
import {
|
|
2879
|
+
builtinHandlers as docgenHandlers,
|
|
2880
|
+
builtinResolvers as docgenResolver,
|
|
2881
|
+
makeFsImporter,
|
|
2882
|
+
parse as parse3
|
|
2883
|
+
} from "react-docgen";
|
|
2884
|
+
|
|
2885
|
+
// ../../../node_modules/comment-parser/es6/primitives.js
|
|
2886
|
+
var Markers;
|
|
2887
|
+
(function(Markers2) {
|
|
2888
|
+
Markers2.start = "/**", Markers2.nostart = "/***", Markers2.delim = "*", Markers2.end = "*/";
|
|
2889
|
+
})(Markers = Markers || (Markers = {}));
|
|
2890
|
+
|
|
2891
|
+
// ../../../node_modules/comment-parser/es6/util.js
|
|
2892
|
+
function isSpace(source) {
|
|
2893
|
+
return /^\s+$/.test(source);
|
|
2886
2894
|
}
|
|
2887
|
-
|
|
2888
|
-
let
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2895
|
+
function splitCR(source) {
|
|
2896
|
+
let matches = source.match(/\r+$/);
|
|
2897
|
+
return matches == null ? ["", source] : [source.slice(-matches[0].length), source.slice(0, -matches[0].length)];
|
|
2898
|
+
}
|
|
2899
|
+
function splitSpace(source) {
|
|
2900
|
+
let matches = source.match(/^\s+/);
|
|
2901
|
+
return matches == null ? ["", source] : [source.slice(0, matches[0].length), source.slice(matches[0].length)];
|
|
2902
|
+
}
|
|
2903
|
+
function splitLines(source) {
|
|
2904
|
+
return source.split(/\n/);
|
|
2905
|
+
}
|
|
2906
|
+
function seedSpec(spec = {}) {
|
|
2907
|
+
return Object.assign({ tag: "", name: "", type: "", optional: !1, description: "", problems: [], source: [] }, spec);
|
|
2908
|
+
}
|
|
2909
|
+
function seedTokens(tokens = {}) {
|
|
2910
|
+
return Object.assign({ start: "", delimiter: "", postDelimiter: "", tag: "", postTag: "", name: "", postName: "", type: "", postType: "", description: "", end: "", lineEnd: "" }, tokens);
|
|
2911
|
+
}
|
|
2912
|
+
|
|
2913
|
+
// ../../../node_modules/comment-parser/es6/parser/block-parser.js
|
|
2914
|
+
var reTag = /^@\S+/;
|
|
2915
|
+
function getParser({ fence = "```" } = {}) {
|
|
2916
|
+
let fencer = getFencer(fence), toggleFence = (source, isFenced) => fencer(source) ? !isFenced : isFenced;
|
|
2917
|
+
return function(source) {
|
|
2918
|
+
let sections = [[]], isFenced = !1;
|
|
2919
|
+
for (let line of source)
|
|
2920
|
+
reTag.test(line.tokens.description) && !isFenced ? sections.push([line]) : sections[sections.length - 1].push(line), isFenced = toggleFence(line.tokens.description, isFenced);
|
|
2921
|
+
return sections;
|
|
2901
2922
|
};
|
|
2902
|
-
}
|
|
2903
|
-
|
|
2904
|
-
|
|
2923
|
+
}
|
|
2924
|
+
function getFencer(fence) {
|
|
2925
|
+
return typeof fence == "string" ? (source) => source.split(fence).length % 2 === 0 : fence;
|
|
2926
|
+
}
|
|
2905
2927
|
|
|
2906
|
-
//
|
|
2907
|
-
function
|
|
2908
|
-
let
|
|
2909
|
-
|
|
2910
|
-
let
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
let init = storyDeclaration.get("init");
|
|
2918
|
-
invariant(
|
|
2919
|
-
init.isExpression(),
|
|
2920
|
-
() => storyDeclaration.buildCodeFrameError("Expected story initializer to be an expression").message
|
|
2921
|
-
), storyPath = init;
|
|
2922
|
-
} else
|
|
2923
|
-
throw storyDeclaration.buildCodeFrameError(
|
|
2924
|
-
"Expected story to be a function or variable declaration"
|
|
2925
|
-
);
|
|
2926
|
-
let normalizedPath = storyPath;
|
|
2927
|
-
if (storyPath.isCallExpression()) {
|
|
2928
|
-
let callee = storyPath.get("callee");
|
|
2929
|
-
if (callee.isMemberExpression()) {
|
|
2930
|
-
let obj = callee.get("object"), prop = callee.get("property"), isBind = prop.isIdentifier() && prop.node.name === "bind" || t.isStringLiteral(prop.node) && prop.node.value === "bind";
|
|
2931
|
-
if (obj.isIdentifier() && isBind) {
|
|
2932
|
-
let resolved = resolveBindIdentifierInit(storyDeclaration, obj);
|
|
2933
|
-
resolved && (normalizedPath = resolved);
|
|
2934
|
-
}
|
|
2935
|
-
}
|
|
2936
|
-
if (storyPath === normalizedPath) {
|
|
2937
|
-
let args = storyPath.get("arguments");
|
|
2938
|
-
if (args.length !== 0) {
|
|
2939
|
-
invariant(
|
|
2940
|
-
args.length === 1,
|
|
2941
|
-
() => storyPath.buildCodeFrameError("Could not evaluate story expression").message
|
|
2942
|
-
);
|
|
2943
|
-
let storyArg = args[0];
|
|
2944
|
-
invariant(
|
|
2945
|
-
storyArg.isExpression(),
|
|
2946
|
-
() => storyPath.buildCodeFrameError("Could not evaluate story expression").message
|
|
2947
|
-
), normalizedPath = storyArg;
|
|
2948
|
-
}
|
|
2949
|
-
}
|
|
2950
|
-
}
|
|
2951
|
-
normalizedPath = normalizedPath.isTSSatisfiesExpression() || normalizedPath.isTSAsExpression() ? normalizedPath.get("expression") : normalizedPath;
|
|
2952
|
-
let storyFn;
|
|
2953
|
-
if (normalizedPath.isArrowFunctionExpression() || normalizedPath.isFunctionExpression() || normalizedPath.isFunctionDeclaration())
|
|
2954
|
-
storyFn = normalizedPath;
|
|
2955
|
-
else if (!normalizedPath.isObjectExpression() && !(normalizedPath.isCallExpression() && Array.isArray(normalizedPath.node.arguments) && normalizedPath.node.arguments.length === 0))
|
|
2956
|
-
throw normalizedPath.buildCodeFrameError(
|
|
2957
|
-
"Expected story to be csf factory, function or an object expression"
|
|
2958
|
-
);
|
|
2959
|
-
let storyProps = normalizedPath.isObjectExpression() ? normalizedPath.get("properties").filter((p) => p.isObjectProperty()) : [], metaPath = pathForNode(csf._file.path, metaObj), metaProps = metaPath?.isObjectExpression() ? metaPath.get("properties").filter((p) => p.isObjectProperty()) : [], getRenderPath = (object) => {
|
|
2960
|
-
let renderPath2 = object.find((p) => keyOf(p.node) === "render")?.get("value");
|
|
2961
|
-
if (renderPath2?.isIdentifier() && (componentName = renderPath2.node.name), renderPath2 && !(renderPath2.isArrowFunctionExpression() || renderPath2.isFunctionExpression()))
|
|
2962
|
-
throw renderPath2.buildCodeFrameError(
|
|
2963
|
-
"Expected render to be an arrow function or function expression"
|
|
2964
|
-
);
|
|
2965
|
-
return renderPath2;
|
|
2966
|
-
}, metaRenderPath = getRenderPath(metaProps), renderPath = getRenderPath(storyProps);
|
|
2967
|
-
storyFn ??= renderPath ?? metaRenderPath;
|
|
2968
|
-
let metaArgs = metaArgsRecord(metaObj ?? null), storyArgsPath = storyProps.filter((p) => keyOf(p.node) === "args").map((p) => p.get("value")).find((v) => v.isObjectExpression()), storyArgs = argsRecordFromObjectPath(storyArgsPath), storyAssignedArgsPath = storyArgsAssignmentPath(csf._file.path, storyName), storyAssignedArgs = argsRecordFromObjectPath(storyAssignedArgsPath), merged = { ...metaArgs, ...storyArgs, ...storyAssignedArgs }, entries = Object.entries(merged).filter(([k]) => k !== "children"), validEntries = entries.filter(([k, v]) => isValidJsxAttrName(k) && v != null), invalidEntries = entries.filter(([k, v]) => !isValidJsxAttrName(k) && v != null), injectedAttrs = validEntries.map(([k, v]) => toAttr(k, v)).filter((a) => a != null);
|
|
2969
|
-
if (storyFn) {
|
|
2970
|
-
let fn = storyFn.node;
|
|
2971
|
-
if (t.isArrowFunctionExpression(fn) && (t.isJSXElement(fn.body) || t.isJSXFragment(fn.body))) {
|
|
2972
|
-
let spreadRes = transformArgsSpreadsInJsx(fn.body, merged), inlineRes = inlineArgsInJsx(spreadRes.node, merged);
|
|
2973
|
-
if (spreadRes.changed || inlineRes.changed) {
|
|
2974
|
-
let newFn = t.arrowFunctionExpression([], inlineRes.node, fn.async);
|
|
2975
|
-
return t.variableDeclaration("const", [
|
|
2976
|
-
t.variableDeclarator(t.identifier(storyName), newFn)
|
|
2977
|
-
]);
|
|
2978
|
-
}
|
|
2928
|
+
// ../../../node_modules/comment-parser/es6/parser/source-parser.js
|
|
2929
|
+
function getParser2({ startLine = 0, markers = Markers } = {}) {
|
|
2930
|
+
let block = null, num = startLine;
|
|
2931
|
+
return function(source) {
|
|
2932
|
+
let rest = source, tokens = seedTokens();
|
|
2933
|
+
if ([tokens.lineEnd, rest] = splitCR(rest), [tokens.start, rest] = splitSpace(rest), block === null && rest.startsWith(markers.start) && !rest.startsWith(markers.nostart) && (block = [], tokens.delimiter = rest.slice(0, markers.start.length), rest = rest.slice(markers.start.length), [tokens.postDelimiter, rest] = splitSpace(rest)), block === null)
|
|
2934
|
+
return num++, null;
|
|
2935
|
+
let isClosed = rest.trimRight().endsWith(markers.end);
|
|
2936
|
+
if (tokens.delimiter === "" && rest.startsWith(markers.delim) && !rest.startsWith(markers.end) && (tokens.delimiter = markers.delim, rest = rest.slice(markers.delim.length), [tokens.postDelimiter, rest] = splitSpace(rest)), isClosed) {
|
|
2937
|
+
let trimmed = rest.trimRight();
|
|
2938
|
+
tokens.end = rest.slice(trimmed.length - markers.end.length), rest = trimmed.slice(0, -markers.end.length);
|
|
2979
2939
|
}
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
if (t.isReturnStatement(stmt) && stmt.argument && (t.isJSXElement(stmt.argument) || t.isJSXFragment(stmt.argument))) {
|
|
2984
|
-
let spreadRes = transformArgsSpreadsInJsx(stmt.argument, merged), inlineRes = inlineArgsInJsx(spreadRes.node, merged);
|
|
2985
|
-
if (spreadRes.changed || inlineRes.changed)
|
|
2986
|
-
return changed = !0, t.returnStatement(inlineRes.node);
|
|
2987
|
-
}
|
|
2988
|
-
return stmt;
|
|
2989
|
-
});
|
|
2990
|
-
if (changed)
|
|
2991
|
-
return t.isFunctionDeclaration(fn) ? t.functionDeclaration(fn.id, [], t.blockStatement(newBody), fn.generator, fn.async) : t.variableDeclaration("const", [
|
|
2992
|
-
t.variableDeclarator(
|
|
2993
|
-
t.identifier(storyName),
|
|
2994
|
-
t.arrowFunctionExpression([], t.blockStatement(newBody), fn.async)
|
|
2995
|
-
)
|
|
2996
|
-
]);
|
|
2940
|
+
if (tokens.description = rest, block.push({ number: num, source, tokens }), num++, isClosed) {
|
|
2941
|
+
let result = block.slice();
|
|
2942
|
+
return block = null, result;
|
|
2997
2943
|
}
|
|
2998
|
-
return t.isFunctionDeclaration(fn) ? fn : t.variableDeclaration("const", [t.variableDeclarator(t.identifier(storyName), fn)]);
|
|
2999
|
-
}
|
|
3000
|
-
invariant(componentName, "Could not generate snippet without component name.");
|
|
3001
|
-
let invalidSpread = buildInvalidSpread(invalidEntries), name = t.jsxIdentifier(componentName), openingElAttrs = invalidSpread ? [...injectedAttrs, invalidSpread] : injectedAttrs, children = toJsxChildren(merged.children), selfClosing = children.length === 0, arrow = t.arrowFunctionExpression(
|
|
3002
|
-
[],
|
|
3003
|
-
t.jsxElement(
|
|
3004
|
-
t.jsxOpeningElement(name, openingElAttrs, selfClosing),
|
|
3005
|
-
selfClosing ? null : t.jsxClosingElement(name),
|
|
3006
|
-
children,
|
|
3007
|
-
selfClosing
|
|
3008
|
-
)
|
|
3009
|
-
);
|
|
3010
|
-
return t.variableDeclaration("const", [t.variableDeclarator(t.identifier(storyName), arrow)]);
|
|
3011
|
-
}
|
|
3012
|
-
function buildInvalidSpread(entries) {
|
|
3013
|
-
if (entries.length === 0)
|
|
3014
2944
|
return null;
|
|
3015
|
-
|
|
3016
|
-
([k, v]) => t.objectProperty(t.stringLiteral(k), t.isExpression(v) ? v : t.identifier("undefined"))
|
|
3017
|
-
);
|
|
3018
|
-
return t.jsxSpreadAttribute(t.objectExpression(objectProps));
|
|
2945
|
+
};
|
|
3019
2946
|
}
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
)
|
|
3023
|
-
function
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
}
|
|
3032
|
-
}
|
|
3033
|
-
}), found;
|
|
2947
|
+
|
|
2948
|
+
// ../../../node_modules/comment-parser/es6/parser/spec-parser.js
|
|
2949
|
+
function getParser3({ tokenizers }) {
|
|
2950
|
+
return function(source) {
|
|
2951
|
+
var _a;
|
|
2952
|
+
let spec = seedSpec({ source });
|
|
2953
|
+
for (let tokenize of tokenizers)
|
|
2954
|
+
if (spec = tokenize(spec), !((_a = spec.problems[spec.problems.length - 1]) === null || _a === void 0) && _a.critical)
|
|
2955
|
+
break;
|
|
2956
|
+
return spec;
|
|
2957
|
+
};
|
|
3034
2958
|
}
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
if (t.isIdentifier(expr.property) && !expr.computed)
|
|
3048
|
-
return expr.property.name;
|
|
3049
|
-
if (t.isStringLiteral(expr.property) && expr.computed)
|
|
3050
|
-
return expr.property.value;
|
|
3051
|
-
}
|
|
3052
|
-
if (t.isOptionalMemberExpression?.(expr) && t.isIdentifier(expr.object) && expr.object.name === "args") {
|
|
3053
|
-
let prop = expr.property;
|
|
3054
|
-
if (t.isIdentifier(prop) && !expr.computed)
|
|
3055
|
-
return prop.name;
|
|
3056
|
-
if (t.isStringLiteral(prop) && expr.computed)
|
|
3057
|
-
return prop.value;
|
|
3058
|
-
}
|
|
3059
|
-
return null;
|
|
3060
|
-
}
|
|
3061
|
-
function inlineArgsInJsx(node, merged) {
|
|
3062
|
-
let changed = !1;
|
|
3063
|
-
if (t.isJSXElement(node)) {
|
|
3064
|
-
let opening = node.openingElement, newAttrs = opening.attributes.flatMap((a) => {
|
|
3065
|
-
if (!t.isJSXAttribute(a))
|
|
3066
|
-
return [a];
|
|
3067
|
-
let name = t.isJSXIdentifier(a.name) ? a.name.name : null;
|
|
3068
|
-
if (!(name && a.value && t.isJSXExpressionContainer(a.value)))
|
|
3069
|
-
return [a];
|
|
3070
|
-
let key = getArgsMemberKey(a.value.expression);
|
|
3071
|
-
if (!(key && key in merged))
|
|
3072
|
-
return [a];
|
|
3073
|
-
let repl = toAttr(name, merged[key]);
|
|
3074
|
-
return changed = !0, repl ? [repl] : [];
|
|
3075
|
-
}), newChildren = node.children.flatMap((c) => {
|
|
3076
|
-
if (t.isJSXElement(c) || t.isJSXFragment(c)) {
|
|
3077
|
-
let res = inlineArgsInJsx(c, merged);
|
|
3078
|
-
return changed ||= res.changed, [res.node];
|
|
3079
|
-
}
|
|
3080
|
-
return t.isJSXExpressionContainer(c) && getArgsMemberKey(c.expression) === "children" && merged.children ? (changed = !0, toJsxChildren(merged.children)) : [c];
|
|
3081
|
-
}), selfClosing = opening.selfClosing && newChildren.length === 0;
|
|
3082
|
-
return {
|
|
3083
|
-
node: t.jsxElement(
|
|
3084
|
-
t.jsxOpeningElement(opening.name, newAttrs, selfClosing),
|
|
3085
|
-
selfClosing ? null : node.closingElement ?? t.jsxClosingElement(opening.name),
|
|
3086
|
-
newChildren,
|
|
3087
|
-
selfClosing
|
|
3088
|
-
),
|
|
3089
|
-
changed
|
|
3090
|
-
};
|
|
3091
|
-
}
|
|
3092
|
-
let fragChildren = node.children.flatMap((c) => {
|
|
3093
|
-
if (t.isJSXElement(c) || t.isJSXFragment(c)) {
|
|
3094
|
-
let res = inlineArgsInJsx(c, merged);
|
|
3095
|
-
return changed ||= res.changed, [res.node];
|
|
3096
|
-
}
|
|
3097
|
-
return t.isJSXExpressionContainer(c) && getArgsMemberKey(c.expression) === "children" && "children" in merged ? (changed = !0, toJsxChildren(merged.children)) : [c];
|
|
3098
|
-
});
|
|
3099
|
-
return { node: t.jsxFragment(node.openingFragment, node.closingFragment, fragChildren), changed };
|
|
3100
|
-
}
|
|
3101
|
-
function transformArgsSpreadsInJsx(node, merged) {
|
|
3102
|
-
let changed = !1, makeInjectedPieces = (existing) => {
|
|
3103
|
-
let entries = Object.entries(merged).filter(([k, v]) => v != null && k !== "children"), validEntries = entries.filter(([k]) => isValidJsxAttrName(k)), invalidEntries = entries.filter(([k]) => !isValidJsxAttrName(k)), injectedAttrs = validEntries.map(([k, v]) => toAttr(k, v)).filter((a) => !!a).filter((a) => t.isJSXIdentifier(a.name) && !existing.has(a.name.name)), invalidSpread = buildInvalidSpread(invalidEntries.filter(([k]) => !existing.has(k)));
|
|
3104
|
-
return invalidSpread ? [...injectedAttrs, invalidSpread] : injectedAttrs;
|
|
3105
|
-
};
|
|
3106
|
-
if (t.isJSXElement(node)) {
|
|
3107
|
-
let opening = node.openingElement, attrs = opening.attributes, isArgsSpread = (a) => t.isJSXSpreadAttribute(a) && t.isIdentifier(a.argument) && a.argument.name === "args", sawArgsSpread = attrs.some(isArgsSpread), firstIdx = attrs.findIndex(isArgsSpread), nonArgsAttrs = attrs.filter((a) => !isArgsSpread(a)), insertionIndex = sawArgsSpread ? attrs.slice(0, firstIdx).filter((a) => !isArgsSpread(a)).length : 0, newAttrs = sawArgsSpread ? (() => {
|
|
3108
|
-
let existing = new Set(
|
|
3109
|
-
nonArgsAttrs.filter((a) => t.isJSXAttribute(a)).flatMap((a) => t.isJSXIdentifier(a.name) ? [a.name.name] : [])
|
|
3110
|
-
), pieces = makeInjectedPieces(existing);
|
|
3111
|
-
return changed = !0, [
|
|
3112
|
-
...nonArgsAttrs.slice(0, insertionIndex),
|
|
3113
|
-
...pieces,
|
|
3114
|
-
...nonArgsAttrs.slice(insertionIndex)
|
|
3115
|
-
];
|
|
3116
|
-
})() : nonArgsAttrs, newChildren = node.children.flatMap((c) => {
|
|
3117
|
-
if (t.isJSXElement(c) || t.isJSXFragment(c)) {
|
|
3118
|
-
let res = transformArgsSpreadsInJsx(c, merged);
|
|
3119
|
-
return changed ||= res.changed, [res.node];
|
|
3120
|
-
}
|
|
3121
|
-
return [c];
|
|
3122
|
-
}), children = sawArgsSpread && newChildren.length === 0 && merged.children ? (changed = !0, toJsxChildren(merged.children)) : newChildren, selfClosing = children.length === 0;
|
|
3123
|
-
return {
|
|
3124
|
-
node: t.jsxElement(
|
|
3125
|
-
t.jsxOpeningElement(opening.name, newAttrs, selfClosing),
|
|
3126
|
-
selfClosing ? null : node.closingElement ?? t.jsxClosingElement(opening.name),
|
|
3127
|
-
children,
|
|
3128
|
-
selfClosing
|
|
3129
|
-
),
|
|
3130
|
-
changed
|
|
3131
|
-
};
|
|
3132
|
-
}
|
|
3133
|
-
let fragChildren = node.children.flatMap((c) => {
|
|
3134
|
-
if (t.isJSXElement(c) || t.isJSXFragment(c)) {
|
|
3135
|
-
let res = transformArgsSpreadsInJsx(c, merged);
|
|
3136
|
-
return changed ||= res.changed, [res.node];
|
|
3137
|
-
}
|
|
3138
|
-
return [c];
|
|
3139
|
-
});
|
|
3140
|
-
return { node: t.jsxFragment(node.openingFragment, node.closingFragment, fragChildren), changed };
|
|
3141
|
-
}
|
|
3142
|
-
function resolveBindIdentifierInit(storyPath, identifier) {
|
|
3143
|
-
let programPath = storyPath.findParent((p) => p.isProgram());
|
|
3144
|
-
if (!programPath)
|
|
3145
|
-
return null;
|
|
3146
|
-
let match = programPath.get("body").flatMap((stmt) => {
|
|
3147
|
-
if (stmt.isVariableDeclaration())
|
|
3148
|
-
return stmt.get("declarations");
|
|
3149
|
-
if (stmt.isExportNamedDeclaration()) {
|
|
3150
|
-
let decl = stmt.get("declaration");
|
|
3151
|
-
if (decl && decl.isVariableDeclaration())
|
|
3152
|
-
return decl.get("declarations");
|
|
3153
|
-
}
|
|
3154
|
-
return [];
|
|
3155
|
-
}).find((d) => {
|
|
3156
|
-
let id = d.get("id");
|
|
3157
|
-
return id.isIdentifier() && id.node.name === identifier.node.name;
|
|
3158
|
-
});
|
|
3159
|
-
if (!match)
|
|
3160
|
-
return null;
|
|
3161
|
-
let init = match.get("init");
|
|
3162
|
-
return init && init.isExpression() ? init : null;
|
|
3163
|
-
}
|
|
3164
|
-
function pathForNode(program, target) {
|
|
3165
|
-
if (!target)
|
|
3166
|
-
return;
|
|
3167
|
-
let found;
|
|
3168
|
-
return program.traverse({
|
|
3169
|
-
enter(p) {
|
|
3170
|
-
p.node && p.node === target && (found = p, p.stop());
|
|
3171
|
-
}
|
|
3172
|
-
}), found;
|
|
3173
|
-
}
|
|
3174
|
-
|
|
3175
|
-
// src/componentManifest/getComponentImports.ts
|
|
3176
|
-
import { dirname as dirname4 } from "node:path";
|
|
3177
|
-
import { babelParse as babelParse2, recast, types as t3 } from "storybook/internal/babel";
|
|
3178
|
-
import { logger as logger3 } from "storybook/internal/node-logger";
|
|
3179
|
-
|
|
3180
|
-
// src/componentManifest/reactDocgen.ts
|
|
3181
|
-
import { existsSync as existsSync2 } from "node:fs";
|
|
3182
|
-
import { dirname as dirname3, sep as sep2 } from "node:path";
|
|
3183
|
-
import { babelParse, types as t2 } from "storybook/internal/babel";
|
|
3184
|
-
import { getProjectRoot, supportedExtensions as supportedExtensions2 } from "storybook/internal/common";
|
|
3185
|
-
import { logger as logger2 } from "storybook/internal/node-logger";
|
|
3186
|
-
var import_ts_dedent = __toESM(require_dist(), 1), TsconfigPaths = __toESM(require_lib2(), 1);
|
|
3187
|
-
import {
|
|
3188
|
-
builtinHandlers as docgenHandlers,
|
|
3189
|
-
builtinResolvers as docgenResolver,
|
|
3190
|
-
makeFsImporter,
|
|
3191
|
-
parse as parse3
|
|
3192
|
-
} from "react-docgen";
|
|
3193
|
-
|
|
3194
|
-
// ../../../node_modules/comment-parser/es6/primitives.js
|
|
3195
|
-
var Markers;
|
|
3196
|
-
(function(Markers2) {
|
|
3197
|
-
Markers2.start = "/**", Markers2.nostart = "/***", Markers2.delim = "*", Markers2.end = "*/";
|
|
3198
|
-
})(Markers = Markers || (Markers = {}));
|
|
3199
|
-
|
|
3200
|
-
// ../../../node_modules/comment-parser/es6/util.js
|
|
3201
|
-
function isSpace(source) {
|
|
3202
|
-
return /^\s+$/.test(source);
|
|
3203
|
-
}
|
|
3204
|
-
function splitCR(source) {
|
|
3205
|
-
let matches = source.match(/\r+$/);
|
|
3206
|
-
return matches == null ? ["", source] : [source.slice(-matches[0].length), source.slice(0, -matches[0].length)];
|
|
3207
|
-
}
|
|
3208
|
-
function splitSpace(source) {
|
|
3209
|
-
let matches = source.match(/^\s+/);
|
|
3210
|
-
return matches == null ? ["", source] : [source.slice(0, matches[0].length), source.slice(matches[0].length)];
|
|
3211
|
-
}
|
|
3212
|
-
function splitLines(source) {
|
|
3213
|
-
return source.split(/\n/);
|
|
3214
|
-
}
|
|
3215
|
-
function seedSpec(spec = {}) {
|
|
3216
|
-
return Object.assign({ tag: "", name: "", type: "", optional: !1, description: "", problems: [], source: [] }, spec);
|
|
3217
|
-
}
|
|
3218
|
-
function seedTokens(tokens = {}) {
|
|
3219
|
-
return Object.assign({ start: "", delimiter: "", postDelimiter: "", tag: "", postTag: "", name: "", postName: "", type: "", postType: "", description: "", end: "", lineEnd: "" }, tokens);
|
|
3220
|
-
}
|
|
3221
|
-
|
|
3222
|
-
// ../../../node_modules/comment-parser/es6/parser/block-parser.js
|
|
3223
|
-
var reTag = /^@\S+/;
|
|
3224
|
-
function getParser({ fence = "```" } = {}) {
|
|
3225
|
-
let fencer = getFencer(fence), toggleFence = (source, isFenced) => fencer(source) ? !isFenced : isFenced;
|
|
3226
|
-
return function(source) {
|
|
3227
|
-
let sections = [[]], isFenced = !1;
|
|
3228
|
-
for (let line of source)
|
|
3229
|
-
reTag.test(line.tokens.description) && !isFenced ? sections.push([line]) : sections[sections.length - 1].push(line), isFenced = toggleFence(line.tokens.description, isFenced);
|
|
3230
|
-
return sections;
|
|
3231
|
-
};
|
|
3232
|
-
}
|
|
3233
|
-
function getFencer(fence) {
|
|
3234
|
-
return typeof fence == "string" ? (source) => source.split(fence).length % 2 === 0 : fence;
|
|
3235
|
-
}
|
|
3236
|
-
|
|
3237
|
-
// ../../../node_modules/comment-parser/es6/parser/source-parser.js
|
|
3238
|
-
function getParser2({ startLine = 0, markers = Markers } = {}) {
|
|
3239
|
-
let block = null, num = startLine;
|
|
3240
|
-
return function(source) {
|
|
3241
|
-
let rest = source, tokens = seedTokens();
|
|
3242
|
-
if ([tokens.lineEnd, rest] = splitCR(rest), [tokens.start, rest] = splitSpace(rest), block === null && rest.startsWith(markers.start) && !rest.startsWith(markers.nostart) && (block = [], tokens.delimiter = rest.slice(0, markers.start.length), rest = rest.slice(markers.start.length), [tokens.postDelimiter, rest] = splitSpace(rest)), block === null)
|
|
3243
|
-
return num++, null;
|
|
3244
|
-
let isClosed = rest.trimRight().endsWith(markers.end);
|
|
3245
|
-
if (tokens.delimiter === "" && rest.startsWith(markers.delim) && !rest.startsWith(markers.end) && (tokens.delimiter = markers.delim, rest = rest.slice(markers.delim.length), [tokens.postDelimiter, rest] = splitSpace(rest)), isClosed) {
|
|
3246
|
-
let trimmed = rest.trimRight();
|
|
3247
|
-
tokens.end = rest.slice(trimmed.length - markers.end.length), rest = trimmed.slice(0, -markers.end.length);
|
|
3248
|
-
}
|
|
3249
|
-
if (tokens.description = rest, block.push({ number: num, source, tokens }), num++, isClosed) {
|
|
3250
|
-
let result = block.slice();
|
|
3251
|
-
return block = null, result;
|
|
3252
|
-
}
|
|
3253
|
-
return null;
|
|
3254
|
-
};
|
|
3255
|
-
}
|
|
3256
|
-
|
|
3257
|
-
// ../../../node_modules/comment-parser/es6/parser/spec-parser.js
|
|
3258
|
-
function getParser3({ tokenizers }) {
|
|
3259
|
-
return function(source) {
|
|
3260
|
-
var _a;
|
|
3261
|
-
let spec = seedSpec({ source });
|
|
3262
|
-
for (let tokenize of tokenizers)
|
|
3263
|
-
if (spec = tokenize(spec), !((_a = spec.problems[spec.problems.length - 1]) === null || _a === void 0) && _a.critical)
|
|
3264
|
-
break;
|
|
3265
|
-
return spec;
|
|
3266
|
-
};
|
|
3267
|
-
}
|
|
3268
|
-
|
|
3269
|
-
// ../../../node_modules/comment-parser/es6/parser/tokenizers/tag.js
|
|
3270
|
-
function tagTokenizer() {
|
|
3271
|
-
return (spec) => {
|
|
3272
|
-
let { tokens } = spec.source[0], match = tokens.description.match(/\s*(@(\S+))(\s*)/);
|
|
3273
|
-
return match === null ? (spec.problems.push({
|
|
3274
|
-
code: "spec:tag:prefix",
|
|
3275
|
-
message: 'tag should start with "@" symbol',
|
|
3276
|
-
line: spec.source[0].number,
|
|
3277
|
-
critical: !0
|
|
3278
|
-
}), spec) : (tokens.tag = match[1], tokens.postTag = match[3], tokens.description = tokens.description.slice(match[0].length), spec.tag = match[2], spec);
|
|
3279
|
-
};
|
|
2959
|
+
|
|
2960
|
+
// ../../../node_modules/comment-parser/es6/parser/tokenizers/tag.js
|
|
2961
|
+
function tagTokenizer() {
|
|
2962
|
+
return (spec) => {
|
|
2963
|
+
let { tokens } = spec.source[0], match = tokens.description.match(/\s*(@(\S+))(\s*)/);
|
|
2964
|
+
return match === null ? (spec.problems.push({
|
|
2965
|
+
code: "spec:tag:prefix",
|
|
2966
|
+
message: 'tag should start with "@" symbol',
|
|
2967
|
+
line: spec.source[0].number,
|
|
2968
|
+
critical: !0
|
|
2969
|
+
}), spec) : (tokens.tag = match[1], tokens.postTag = match[3], tokens.description = tokens.description.slice(match[0].length), spec.tag = match[2], spec);
|
|
2970
|
+
};
|
|
3280
2971
|
}
|
|
3281
2972
|
|
|
3282
2973
|
// ../../../node_modules/comment-parser/es6/parser/tokenizers/type.js
|
|
3283
2974
|
function typeTokenizer(spacing = "compact") {
|
|
3284
|
-
let
|
|
2975
|
+
let join6 = getJoiner(spacing);
|
|
3285
2976
|
return (spec) => {
|
|
3286
2977
|
let curlies = 0, lines = [];
|
|
3287
2978
|
for (let [i, { tokens }] of spec.source.entries()) {
|
|
@@ -3304,7 +2995,7 @@ function typeTokenizer(spacing = "compact") {
|
|
|
3304
2995
|
let parts = [], offset = lines[0][0].postDelimiter.length;
|
|
3305
2996
|
for (let [i, [tokens, type]] of lines.entries())
|
|
3306
2997
|
tokens.type = type, i > 0 && (tokens.type = tokens.postDelimiter.slice(offset) + type, tokens.postDelimiter = tokens.postDelimiter.slice(0, offset)), [tokens.postType, tokens.description] = splitSpace(tokens.description.slice(type.length)), parts.push(tokens.type);
|
|
3307
|
-
return parts[0] = parts[0].slice(1), parts[parts.length - 1] = parts[parts.length - 1].slice(0, -1), spec.type =
|
|
2998
|
+
return parts[0] = parts[0].slice(1), parts[parts.length - 1] = parts[parts.length - 1].slice(0, -1), spec.type = join6(parts), spec;
|
|
3308
2999
|
};
|
|
3309
3000
|
}
|
|
3310
3001
|
var trim = (x) => x.trim();
|
|
@@ -3366,8 +3057,8 @@ function nameTokenizer() {
|
|
|
3366
3057
|
|
|
3367
3058
|
// ../../../node_modules/comment-parser/es6/parser/tokenizers/description.js
|
|
3368
3059
|
function descriptionTokenizer(spacing = "compact", markers = Markers) {
|
|
3369
|
-
let
|
|
3370
|
-
return (spec) => (spec.description =
|
|
3060
|
+
let join6 = getJoiner2(spacing);
|
|
3061
|
+
return (spec) => (spec.description = join6(spec.source, markers), spec);
|
|
3371
3062
|
}
|
|
3372
3063
|
function getJoiner2(spacing) {
|
|
3373
3064
|
return spacing === "compact" ? compactJoiner : spacing === "preserve" ? preserveJoiner : spacing;
|
|
@@ -3446,6 +3137,37 @@ function parse2(source, options = {}) {
|
|
|
3446
3137
|
}
|
|
3447
3138
|
var stringify = getStringifier();
|
|
3448
3139
|
|
|
3140
|
+
// src/componentManifest/utils.ts
|
|
3141
|
+
import { readFileSync } from "node:fs";
|
|
3142
|
+
import { resolveImport } from "storybook/internal/common";
|
|
3143
|
+
import { logger } from "storybook/internal/node-logger";
|
|
3144
|
+
var groupBy = (items, keySelector) => items.reduce((acc = {}, item, index) => {
|
|
3145
|
+
let key = keySelector(item, index);
|
|
3146
|
+
return Array.isArray(acc[key]) || (acc[key] = []), acc[key].push(item), acc;
|
|
3147
|
+
}, {});
|
|
3148
|
+
function invariant(condition, message) {
|
|
3149
|
+
if (!condition)
|
|
3150
|
+
throw new Error((typeof message == "function" ? message() : message) ?? "Invariant failed");
|
|
3151
|
+
}
|
|
3152
|
+
var memoStore = /* @__PURE__ */ new WeakMap(), cached = (fn, opts = {}) => {
|
|
3153
|
+
let keyOf2 = opts.key ?? ((...args) => {
|
|
3154
|
+
try {
|
|
3155
|
+
return JSON.stringify(args);
|
|
3156
|
+
} catch {
|
|
3157
|
+
return String(args[0]);
|
|
3158
|
+
}
|
|
3159
|
+
});
|
|
3160
|
+
return (...args) => {
|
|
3161
|
+
let k = keyOf2(...args), name = fn.name || opts.name || "anonymous", store = memoStore.get(fn);
|
|
3162
|
+
if (store || (store = /* @__PURE__ */ new Map(), memoStore.set(fn, store)), store.has(k))
|
|
3163
|
+
return logger.verbose(`[cache] hit ${name} key=${k}`), store.get(k);
|
|
3164
|
+
let start = Date.now(), result = fn(...args), duration = Date.now() - start;
|
|
3165
|
+
return store.set(k, result), logger.verbose(`[cache] miss ${name} took ${duration}ms key=${k}`), result;
|
|
3166
|
+
};
|
|
3167
|
+
}, invalidateCache = () => {
|
|
3168
|
+
memoStore = /* @__PURE__ */ new WeakMap();
|
|
3169
|
+
}, cachedReadFileSync = cached(readFileSync, { name: "cachedReadFile" }), cachedFindUp = cached(up2, { name: "findUp" }), cachedResolveImport = cached(resolveImport, { name: "resolveImport" });
|
|
3170
|
+
|
|
3449
3171
|
// src/componentManifest/jsdocTags.ts
|
|
3450
3172
|
function extractJSDocInfo(jsdocComment) {
|
|
3451
3173
|
let jsDoc = ["/**", ...jsdocComment.split(`
|
|
@@ -3504,16 +3226,16 @@ var ReactDocgenResolveError = class extends Error {
|
|
|
3504
3226
|
// src/componentManifest/reactDocgen/exportNameHandler.ts
|
|
3505
3227
|
import { utils as utils2 } from "react-docgen";
|
|
3506
3228
|
var { isReactForwardRefCall: isReactForwardRefCall2 } = utils2;
|
|
3507
|
-
function nameFromId(
|
|
3508
|
-
if (
|
|
3509
|
-
if (
|
|
3510
|
-
return
|
|
3511
|
-
if (
|
|
3512
|
-
return
|
|
3229
|
+
function nameFromId(path3) {
|
|
3230
|
+
if (path3) {
|
|
3231
|
+
if (path3.isIdentifier())
|
|
3232
|
+
return path3.node.name;
|
|
3233
|
+
if (path3.isStringLiteral())
|
|
3234
|
+
return path3.node.value;
|
|
3513
3235
|
}
|
|
3514
3236
|
}
|
|
3515
|
-
function isInlineDefaultExport(
|
|
3516
|
-
let p =
|
|
3237
|
+
function isInlineDefaultExport(path3) {
|
|
3238
|
+
let p = path3;
|
|
3517
3239
|
for (; p && p.parentPath; ) {
|
|
3518
3240
|
if (p.parentPath.isExportDefaultDeclaration())
|
|
3519
3241
|
return !0;
|
|
@@ -3521,8 +3243,8 @@ function isInlineDefaultExport(path2) {
|
|
|
3521
3243
|
}
|
|
3522
3244
|
return !1;
|
|
3523
3245
|
}
|
|
3524
|
-
function findProgram(
|
|
3525
|
-
let found =
|
|
3246
|
+
function findProgram(path3) {
|
|
3247
|
+
let found = path3.findParent((p) => p.isProgram());
|
|
3526
3248
|
return found && found.isProgram() ? found : void 0;
|
|
3527
3249
|
}
|
|
3528
3250
|
function getLocalName(componentDefinition, fallback) {
|
|
@@ -3635,13 +3357,13 @@ var getTsConfig = cached(
|
|
|
3635
3357
|
},
|
|
3636
3358
|
{ name: "getTsConfig" }
|
|
3637
3359
|
), parseWithReactDocgen = cached(
|
|
3638
|
-
(code,
|
|
3360
|
+
(code, path3) => parse3(code, {
|
|
3639
3361
|
resolver: defaultResolver,
|
|
3640
3362
|
handlers,
|
|
3641
3363
|
importer: getReactDocgenImporter(),
|
|
3642
|
-
filename:
|
|
3364
|
+
filename: path3
|
|
3643
3365
|
}),
|
|
3644
|
-
{ key: (code,
|
|
3366
|
+
{ key: (code, path3) => path3, name: "parseWithReactDocgen" }
|
|
3645
3367
|
), getExportPaths = cached(
|
|
3646
3368
|
(code, filePath) => {
|
|
3647
3369
|
let ast;
|
|
@@ -3652,151 +3374,571 @@ var getTsConfig = cached(
|
|
|
3652
3374
|
}
|
|
3653
3375
|
let basedir = dirname3(filePath);
|
|
3654
3376
|
return ast.program.body.flatMap(
|
|
3655
|
-
(statement) =>
|
|
3377
|
+
(statement) => t.isExportAllDeclaration(statement) ? [statement.source.value] : t.isExportNamedDeclaration(statement) && statement.source && !statement.declaration ? [statement.source.value] : []
|
|
3656
3378
|
).map((id) => matchPath(id, basedir)).flatMap((id) => {
|
|
3657
3379
|
try {
|
|
3658
3380
|
return [cachedResolveImport(id, { basedir })];
|
|
3659
3381
|
} catch (e) {
|
|
3660
3382
|
return logger2.debug(e), [];
|
|
3661
3383
|
}
|
|
3662
|
-
});
|
|
3663
|
-
},
|
|
3664
|
-
{ name: "getExportPaths" }
|
|
3665
|
-
), gatherDocgensForPath = cached(
|
|
3666
|
-
(
|
|
3667
|
-
if (
|
|
3668
|
-
return {
|
|
3669
|
-
docgens: [],
|
|
3670
|
-
errors: [
|
|
3671
|
-
{
|
|
3672
|
-
path:
|
|
3673
|
-
code: "/* File in node_modules */",
|
|
3674
|
-
name: "Component file in node_modules",
|
|
3675
|
-
message: import_ts_dedent.dedent`
|
|
3676
|
-
Component files in node_modules are not supported.
|
|
3677
|
-
The distributed files in node_modules usually don't contain the necessary comments or types needed to analyze component information.
|
|
3678
|
-
Configure TypeScript path aliases to map your package name to the source file instead.
|
|
3679
|
-
|
|
3680
|
-
Example (tsconfig.json):
|
|
3681
|
-
{
|
|
3682
|
-
"compilerOptions": {
|
|
3683
|
-
"baseUrl": ".",
|
|
3684
|
-
"paths": {
|
|
3685
|
-
"@design-system/button": ["src/components/Button.tsx"],
|
|
3686
|
-
"@design-system/*": ["src/components/*"]
|
|
3687
|
-
}
|
|
3688
|
-
}
|
|
3689
|
-
}
|
|
3690
|
-
|
|
3691
|
-
Then import using:
|
|
3692
|
-
import { Button } from '@design-system/button'
|
|
3693
|
-
|
|
3694
|
-
Storybook resolves tsconfig paths automatically.
|
|
3695
|
-
`
|
|
3696
|
-
}
|
|
3697
|
-
]
|
|
3698
|
-
};
|
|
3699
|
-
let code;
|
|
3700
|
-
try {
|
|
3701
|
-
code = cachedReadFileSync(
|
|
3702
|
-
} catch {
|
|
3703
|
-
return {
|
|
3704
|
-
docgens: [],
|
|
3705
|
-
errors: [
|
|
3706
|
-
{
|
|
3707
|
-
path:
|
|
3708
|
-
code: "/* File not found or unreadable */",
|
|
3709
|
-
name: "Component file could not be read",
|
|
3710
|
-
message: `Could not read the component file located at "${
|
|
3711
|
-
Prefer relative imports if possible.`
|
|
3712
|
-
}
|
|
3713
|
-
]
|
|
3714
|
-
};
|
|
3384
|
+
});
|
|
3385
|
+
},
|
|
3386
|
+
{ name: "getExportPaths" }
|
|
3387
|
+
), gatherDocgensForPath = cached(
|
|
3388
|
+
(path3, depth) => {
|
|
3389
|
+
if (path3.includes("node_modules"))
|
|
3390
|
+
return {
|
|
3391
|
+
docgens: [],
|
|
3392
|
+
errors: [
|
|
3393
|
+
{
|
|
3394
|
+
path: path3,
|
|
3395
|
+
code: "/* File in node_modules */",
|
|
3396
|
+
name: "Component file in node_modules",
|
|
3397
|
+
message: import_ts_dedent.dedent`
|
|
3398
|
+
Component files in node_modules are not supported.
|
|
3399
|
+
The distributed files in node_modules usually don't contain the necessary comments or types needed to analyze component information.
|
|
3400
|
+
Configure TypeScript path aliases to map your package name to the source file instead.
|
|
3401
|
+
|
|
3402
|
+
Example (tsconfig.json):
|
|
3403
|
+
{
|
|
3404
|
+
"compilerOptions": {
|
|
3405
|
+
"baseUrl": ".",
|
|
3406
|
+
"paths": {
|
|
3407
|
+
"@design-system/button": ["src/components/Button.tsx"],
|
|
3408
|
+
"@design-system/*": ["src/components/*"]
|
|
3409
|
+
}
|
|
3410
|
+
}
|
|
3411
|
+
}
|
|
3412
|
+
|
|
3413
|
+
Then import using:
|
|
3414
|
+
import { Button } from '@design-system/button'
|
|
3415
|
+
|
|
3416
|
+
Storybook resolves tsconfig paths automatically.
|
|
3417
|
+
`
|
|
3418
|
+
}
|
|
3419
|
+
]
|
|
3420
|
+
};
|
|
3421
|
+
let code;
|
|
3422
|
+
try {
|
|
3423
|
+
code = cachedReadFileSync(path3, "utf-8");
|
|
3424
|
+
} catch {
|
|
3425
|
+
return {
|
|
3426
|
+
docgens: [],
|
|
3427
|
+
errors: [
|
|
3428
|
+
{
|
|
3429
|
+
path: path3,
|
|
3430
|
+
code: "/* File not found or unreadable */",
|
|
3431
|
+
name: "Component file could not be read",
|
|
3432
|
+
message: `Could not read the component file located at "${path3}".
|
|
3433
|
+
Prefer relative imports if possible.`
|
|
3434
|
+
}
|
|
3435
|
+
]
|
|
3436
|
+
};
|
|
3437
|
+
}
|
|
3438
|
+
if (depth > 5)
|
|
3439
|
+
return {
|
|
3440
|
+
docgens: [],
|
|
3441
|
+
errors: [
|
|
3442
|
+
{
|
|
3443
|
+
path: path3,
|
|
3444
|
+
code,
|
|
3445
|
+
name: "Max re-export depth exceeded",
|
|
3446
|
+
message: import_ts_dedent.dedent`
|
|
3447
|
+
Traversal stopped after 5 steps while following re-exports starting from this file.
|
|
3448
|
+
This usually indicates a deep or circular re-export chain. Try one of the following:
|
|
3449
|
+
- Import the component file directly (e.g., src/components/Button.tsx),
|
|
3450
|
+
- Reduce the number of re-export hops.
|
|
3451
|
+
`
|
|
3452
|
+
}
|
|
3453
|
+
]
|
|
3454
|
+
};
|
|
3455
|
+
let exportPaths = getExportPaths(code, path3).map((p) => gatherDocgensForPath(p, depth + 1)), docgens = exportPaths.flatMap((r) => r.docgens), errors = exportPaths.flatMap((r) => r.errors);
|
|
3456
|
+
try {
|
|
3457
|
+
return {
|
|
3458
|
+
docgens: [...parseWithReactDocgen(code, path3), ...docgens],
|
|
3459
|
+
errors
|
|
3460
|
+
};
|
|
3461
|
+
} catch (e) {
|
|
3462
|
+
let message = e instanceof Error ? e.message : String(e);
|
|
3463
|
+
return {
|
|
3464
|
+
docgens,
|
|
3465
|
+
errors: [
|
|
3466
|
+
{
|
|
3467
|
+
path: path3,
|
|
3468
|
+
code,
|
|
3469
|
+
name: "No component definition found",
|
|
3470
|
+
message: import_ts_dedent.dedent`
|
|
3471
|
+
${message}
|
|
3472
|
+
You can debug your component file in this playground: https://react-docgen.dev/playground
|
|
3473
|
+
`
|
|
3474
|
+
},
|
|
3475
|
+
...errors
|
|
3476
|
+
]
|
|
3477
|
+
};
|
|
3478
|
+
}
|
|
3479
|
+
},
|
|
3480
|
+
{ name: "gatherDocgensWithTrace", key: (filePath) => filePath }
|
|
3481
|
+
), getReactDocgen = cached(
|
|
3482
|
+
(path3, component) => {
|
|
3483
|
+
let { docgens, errors } = gatherDocgensForPath(path3, 0), docgen = getMatchingDocgen(docgens, component);
|
|
3484
|
+
return docgen ? { type: "success", data: docgen } : { type: "error", error: {
|
|
3485
|
+
name: errors.at(-1)?.name ?? "No component definition found",
|
|
3486
|
+
message: errors.map(
|
|
3487
|
+
(e) => import_ts_dedent.dedent`
|
|
3488
|
+
File: ${e.path}
|
|
3489
|
+
Error:
|
|
3490
|
+
${e.message}
|
|
3491
|
+
Code:
|
|
3492
|
+
${e.code}`
|
|
3493
|
+
).join(`
|
|
3494
|
+
|
|
3495
|
+
`)
|
|
3496
|
+
} };
|
|
3497
|
+
},
|
|
3498
|
+
{ name: "getReactDocgen", key: (path3, component) => path3 + JSON.stringify(component) }
|
|
3499
|
+
);
|
|
3500
|
+
function getReactDocgenImporter() {
|
|
3501
|
+
return makeFsImporter((filename, basedir) => {
|
|
3502
|
+
let mappedFilenameByPaths = matchPath(filename, basedir), result = cachedResolveImport(mappedFilenameByPaths, { basedir });
|
|
3503
|
+
if (result.includes(`${sep2}react-native${sep2}index.js`)) {
|
|
3504
|
+
let replaced = result.replace(
|
|
3505
|
+
`${sep2}react-native${sep2}index.js`,
|
|
3506
|
+
`${sep2}react-native-web${sep2}dist${sep2}index.js`
|
|
3507
|
+
);
|
|
3508
|
+
if (existsSync2(replaced) && supportedExtensions2.find((ext) => result.endsWith(ext)))
|
|
3509
|
+
return replaced;
|
|
3510
|
+
}
|
|
3511
|
+
if (supportedExtensions2.find((ext) => result.endsWith(ext)))
|
|
3512
|
+
return result;
|
|
3513
|
+
throw new ReactDocgenResolveError(filename);
|
|
3514
|
+
});
|
|
3515
|
+
}
|
|
3516
|
+
function getImportTag(docgen) {
|
|
3517
|
+
let jsdocComment = docgen?.description;
|
|
3518
|
+
return (jsdocComment ? extractJSDocInfo(jsdocComment).tags : void 0)?.import?.[0];
|
|
3519
|
+
}
|
|
3520
|
+
|
|
3521
|
+
// src/componentManifest/reactDocgen/extractDocgenInfo.ts
|
|
3522
|
+
function isElementsType(value) {
|
|
3523
|
+
return "elements" in value;
|
|
3524
|
+
}
|
|
3525
|
+
function isObjectSignatureType(value) {
|
|
3526
|
+
return value.name === "signature" && value.type === "object";
|
|
3527
|
+
}
|
|
3528
|
+
function isLiteralType(value) {
|
|
3529
|
+
return value.name === "literal";
|
|
3530
|
+
}
|
|
3531
|
+
function mapReactDocgenToArgType(docgenType) {
|
|
3532
|
+
let name = docgenType.name;
|
|
3533
|
+
switch (name) {
|
|
3534
|
+
case "boolean":
|
|
3535
|
+
return { name: "boolean" };
|
|
3536
|
+
case "string":
|
|
3537
|
+
return { name: "string" };
|
|
3538
|
+
case "number":
|
|
3539
|
+
return { name: "number" };
|
|
3540
|
+
case "Date":
|
|
3541
|
+
return { name: "date" };
|
|
3542
|
+
case "JSX.Element":
|
|
3543
|
+
case "ComponentType":
|
|
3544
|
+
case "ReactComponentType":
|
|
3545
|
+
case "ReactElement":
|
|
3546
|
+
case "ReactReactElement":
|
|
3547
|
+
case "ElementType":
|
|
3548
|
+
case "ReactElementType":
|
|
3549
|
+
case "ReactNode":
|
|
3550
|
+
case "ReactReactNode":
|
|
3551
|
+
return { name: "node", renderer: "react" };
|
|
3552
|
+
case "signature": {
|
|
3553
|
+
if (isObjectSignatureType(docgenType)) {
|
|
3554
|
+
let properties = {};
|
|
3555
|
+
for (let prop of docgenType.signature.properties) {
|
|
3556
|
+
let key = typeof prop.key == "string" ? prop.key : prop.key.name;
|
|
3557
|
+
properties[key] = mapReactDocgenToArgType(prop.value);
|
|
3558
|
+
}
|
|
3559
|
+
return { name: "object", value: properties };
|
|
3560
|
+
}
|
|
3561
|
+
return { name: "function" };
|
|
3562
|
+
}
|
|
3563
|
+
case "union":
|
|
3564
|
+
return { name: "union", value: (isElementsType(docgenType) ? docgenType.elements : []).map(mapReactDocgenToArgType) };
|
|
3565
|
+
case "Array": {
|
|
3566
|
+
let element = isElementsType(docgenType) ? docgenType.elements[0] : void 0;
|
|
3567
|
+
if (!element)
|
|
3568
|
+
return { name: "array", value: { name: "other", value: "any" } };
|
|
3569
|
+
let mapped = mapReactDocgenToArgType(element);
|
|
3570
|
+
return element.name && ![
|
|
3571
|
+
"string",
|
|
3572
|
+
"number",
|
|
3573
|
+
"boolean",
|
|
3574
|
+
"Date",
|
|
3575
|
+
"ReactNode",
|
|
3576
|
+
"ReactElementType",
|
|
3577
|
+
"ReactReactNode",
|
|
3578
|
+
"JSX.Element",
|
|
3579
|
+
"ComponentType",
|
|
3580
|
+
"ReactComponentType",
|
|
3581
|
+
"ReactElement",
|
|
3582
|
+
"ReactReactElement",
|
|
3583
|
+
"ElementType",
|
|
3584
|
+
"signature",
|
|
3585
|
+
"union",
|
|
3586
|
+
"Array",
|
|
3587
|
+
"tuple",
|
|
3588
|
+
"literal",
|
|
3589
|
+
"null",
|
|
3590
|
+
"void",
|
|
3591
|
+
"any",
|
|
3592
|
+
"unknown"
|
|
3593
|
+
].includes(element.name) ? { name: "array", value: { name: "other", value: element.name } } : { name: "array", value: mapped };
|
|
3594
|
+
}
|
|
3595
|
+
case "tuple":
|
|
3596
|
+
return { name: "tuple", value: (isElementsType(docgenType) ? docgenType.elements : []).map(mapReactDocgenToArgType) };
|
|
3597
|
+
case "literal":
|
|
3598
|
+
return { name: "literal", value: isLiteralType(docgenType) ? docgenType.value : void 0 };
|
|
3599
|
+
case "null":
|
|
3600
|
+
return { name: "other", value: "null" };
|
|
3601
|
+
case "void":
|
|
3602
|
+
return { name: "other", value: "void" };
|
|
3603
|
+
case "any":
|
|
3604
|
+
return { name: "other", value: "any" };
|
|
3605
|
+
case "unknown":
|
|
3606
|
+
return { name: "other", value: "unknown" };
|
|
3607
|
+
default:
|
|
3608
|
+
return { name: "other", value: name };
|
|
3609
|
+
}
|
|
3610
|
+
}
|
|
3611
|
+
function getComponentDocgen(filePath, componentName) {
|
|
3612
|
+
try {
|
|
3613
|
+
let code = cachedReadFileSync(filePath, "utf-8"), docgens = parseWithReactDocgen(code, filePath);
|
|
3614
|
+
if (docgens.length === 0)
|
|
3615
|
+
return null;
|
|
3616
|
+
if (componentName) {
|
|
3617
|
+
let matchingDocgen = docgens.find(
|
|
3618
|
+
(docgen) => docgen.actualName === componentName || docgen.displayName === componentName || docgen.exportName === componentName
|
|
3619
|
+
);
|
|
3620
|
+
return matchingDocgen ? {
|
|
3621
|
+
componentName: matchingDocgen.actualName || matchingDocgen.displayName || componentName,
|
|
3622
|
+
reactDocgen: { type: "success", data: matchingDocgen }
|
|
3623
|
+
} : null;
|
|
3624
|
+
}
|
|
3625
|
+
let firstDocgen = docgens[0];
|
|
3626
|
+
return {
|
|
3627
|
+
componentName: firstDocgen.actualName || firstDocgen.displayName || "Unknown",
|
|
3628
|
+
reactDocgen: { type: "success", data: firstDocgen }
|
|
3629
|
+
};
|
|
3630
|
+
} catch (error) {
|
|
3631
|
+
return logger3.debug(`Error parsing component file for docgen ${filePath}: ${error}`), null;
|
|
3632
|
+
}
|
|
3633
|
+
}
|
|
3634
|
+
var extractArgTypesFromDocgen = ({
|
|
3635
|
+
componentFilePath,
|
|
3636
|
+
componentExportName
|
|
3637
|
+
}) => {
|
|
3638
|
+
let docgen = getComponentDocgen(componentFilePath, componentExportName);
|
|
3639
|
+
if (!docgen || docgen.reactDocgen.type !== "success")
|
|
3640
|
+
return null;
|
|
3641
|
+
let props = docgen.reactDocgen.data.props ?? {}, mapped = { props: {} };
|
|
3642
|
+
for (let [propName, propInfo] of Object.entries(props)) {
|
|
3643
|
+
let tsType = propInfo.tsType;
|
|
3644
|
+
tsType && (mapped.props[propName] = {
|
|
3645
|
+
required: !!propInfo.required,
|
|
3646
|
+
type: mapReactDocgenToArgType(tsType)
|
|
3647
|
+
});
|
|
3648
|
+
}
|
|
3649
|
+
return mapped;
|
|
3650
|
+
};
|
|
3651
|
+
|
|
3652
|
+
// src/componentManifest/generator.ts
|
|
3653
|
+
import { recast as recast2 } from "storybook/internal/babel";
|
|
3654
|
+
import { Tag } from "storybook/internal/core-server";
|
|
3655
|
+
import { extractDescription, loadCsf } from "storybook/internal/csf-tools";
|
|
3656
|
+
import { logger as logger5 } from "storybook/internal/node-logger";
|
|
3657
|
+
|
|
3658
|
+
// ../../../node_modules/es-toolkit/dist/array/uniqBy.mjs
|
|
3659
|
+
function uniqBy(arr, mapper) {
|
|
3660
|
+
let map = /* @__PURE__ */ new Map();
|
|
3661
|
+
for (let i = 0; i < arr.length; i++) {
|
|
3662
|
+
let item = arr[i], key = mapper(item);
|
|
3663
|
+
map.has(key) || map.set(key, item);
|
|
3664
|
+
}
|
|
3665
|
+
return Array.from(map.values());
|
|
3666
|
+
}
|
|
3667
|
+
|
|
3668
|
+
// src/componentManifest/generateCodeSnippet.ts
|
|
3669
|
+
import { types as t2 } from "storybook/internal/babel";
|
|
3670
|
+
function getCodeSnippet(csf, storyName, componentName) {
|
|
3671
|
+
let storyDeclaration = csf._storyDeclarationPath[storyName], metaObj = csf._metaNode;
|
|
3672
|
+
if (!storyDeclaration) {
|
|
3673
|
+
let message = "Expected story to be a function or variable declaration";
|
|
3674
|
+
throw csf._storyPaths[storyName]?.buildCodeFrameError(message) ?? message;
|
|
3675
|
+
}
|
|
3676
|
+
let storyPath;
|
|
3677
|
+
if (storyDeclaration.isFunctionDeclaration())
|
|
3678
|
+
storyPath = storyDeclaration;
|
|
3679
|
+
else if (storyDeclaration.isVariableDeclarator()) {
|
|
3680
|
+
let init = storyDeclaration.get("init");
|
|
3681
|
+
invariant(
|
|
3682
|
+
init.isExpression(),
|
|
3683
|
+
() => storyDeclaration.buildCodeFrameError("Expected story initializer to be an expression").message
|
|
3684
|
+
), storyPath = init;
|
|
3685
|
+
} else
|
|
3686
|
+
throw storyDeclaration.buildCodeFrameError(
|
|
3687
|
+
"Expected story to be a function or variable declaration"
|
|
3688
|
+
);
|
|
3689
|
+
let normalizedPath = storyPath;
|
|
3690
|
+
if (storyPath.isCallExpression()) {
|
|
3691
|
+
let callee = storyPath.get("callee");
|
|
3692
|
+
if (callee.isMemberExpression()) {
|
|
3693
|
+
let obj = callee.get("object"), prop = callee.get("property"), isBind = prop.isIdentifier() && prop.node.name === "bind" || t2.isStringLiteral(prop.node) && prop.node.value === "bind";
|
|
3694
|
+
if (obj.isIdentifier() && isBind) {
|
|
3695
|
+
let resolved = resolveBindIdentifierInit(storyDeclaration, obj);
|
|
3696
|
+
resolved && (normalizedPath = resolved);
|
|
3697
|
+
}
|
|
3698
|
+
}
|
|
3699
|
+
if (storyPath === normalizedPath) {
|
|
3700
|
+
let args = storyPath.get("arguments");
|
|
3701
|
+
if (args.length !== 0) {
|
|
3702
|
+
invariant(
|
|
3703
|
+
args.length === 1,
|
|
3704
|
+
() => storyPath.buildCodeFrameError("Could not evaluate story expression").message
|
|
3705
|
+
);
|
|
3706
|
+
let storyArg = args[0];
|
|
3707
|
+
invariant(
|
|
3708
|
+
storyArg.isExpression(),
|
|
3709
|
+
() => storyPath.buildCodeFrameError("Could not evaluate story expression").message
|
|
3710
|
+
), normalizedPath = storyArg;
|
|
3711
|
+
}
|
|
3712
|
+
}
|
|
3713
|
+
}
|
|
3714
|
+
normalizedPath = normalizedPath.isTSSatisfiesExpression() || normalizedPath.isTSAsExpression() ? normalizedPath.get("expression") : normalizedPath;
|
|
3715
|
+
let storyFn;
|
|
3716
|
+
if (normalizedPath.isArrowFunctionExpression() || normalizedPath.isFunctionExpression() || normalizedPath.isFunctionDeclaration())
|
|
3717
|
+
storyFn = normalizedPath;
|
|
3718
|
+
else if (!normalizedPath.isObjectExpression() && !(normalizedPath.isCallExpression() && Array.isArray(normalizedPath.node.arguments) && normalizedPath.node.arguments.length === 0))
|
|
3719
|
+
throw normalizedPath.buildCodeFrameError(
|
|
3720
|
+
"Expected story to be csf factory, function or an object expression"
|
|
3721
|
+
);
|
|
3722
|
+
let storyProps = normalizedPath.isObjectExpression() ? normalizedPath.get("properties").filter((p) => p.isObjectProperty()) : [], metaPath = pathForNode(csf._file.path, metaObj), metaProps = metaPath?.isObjectExpression() ? metaPath.get("properties").filter((p) => p.isObjectProperty()) : [], getRenderPath = (object) => {
|
|
3723
|
+
let renderPath2 = object.find((p) => keyOf(p.node) === "render")?.get("value");
|
|
3724
|
+
if (renderPath2?.isIdentifier() && (componentName = renderPath2.node.name), renderPath2 && !(renderPath2.isArrowFunctionExpression() || renderPath2.isFunctionExpression()))
|
|
3725
|
+
throw renderPath2.buildCodeFrameError(
|
|
3726
|
+
"Expected render to be an arrow function or function expression"
|
|
3727
|
+
);
|
|
3728
|
+
return renderPath2;
|
|
3729
|
+
}, metaRenderPath = getRenderPath(metaProps), renderPath = getRenderPath(storyProps);
|
|
3730
|
+
storyFn ??= renderPath ?? metaRenderPath;
|
|
3731
|
+
let metaArgs = metaArgsRecord(metaObj ?? null), storyArgsPath = storyProps.filter((p) => keyOf(p.node) === "args").map((p) => p.get("value")).find((v) => v.isObjectExpression()), storyArgs = argsRecordFromObjectPath(storyArgsPath), storyAssignedArgsPath = storyArgsAssignmentPath(csf._file.path, storyName), storyAssignedArgs = argsRecordFromObjectPath(storyAssignedArgsPath), merged = { ...metaArgs, ...storyArgs, ...storyAssignedArgs }, entries = Object.entries(merged).filter(([k]) => k !== "children"), validEntries = entries.filter(([k, v]) => isValidJsxAttrName(k) && v != null), invalidEntries = entries.filter(([k, v]) => !isValidJsxAttrName(k) && v != null), injectedAttrs = validEntries.map(([k, v]) => toAttr(k, v)).filter((a) => a != null);
|
|
3732
|
+
if (storyFn) {
|
|
3733
|
+
let fn = storyFn.node;
|
|
3734
|
+
if (t2.isArrowFunctionExpression(fn) && (t2.isJSXElement(fn.body) || t2.isJSXFragment(fn.body))) {
|
|
3735
|
+
let spreadRes = transformArgsSpreadsInJsx(fn.body, merged), inlineRes = inlineArgsInJsx(spreadRes.node, merged);
|
|
3736
|
+
if (spreadRes.changed || inlineRes.changed) {
|
|
3737
|
+
let newFn = t2.arrowFunctionExpression([], inlineRes.node, fn.async);
|
|
3738
|
+
return t2.variableDeclaration("const", [
|
|
3739
|
+
t2.variableDeclarator(t2.identifier(storyName), newFn)
|
|
3740
|
+
]);
|
|
3741
|
+
}
|
|
3742
|
+
}
|
|
3743
|
+
let stmts = t2.isFunctionDeclaration(fn) || t2.isArrowFunctionExpression(fn) && t2.isBlockStatement(fn.body) || t2.isFunctionExpression(fn) && t2.isBlockStatement(fn.body) ? fn.body.body : void 0;
|
|
3744
|
+
if (stmts) {
|
|
3745
|
+
let changed = !1, newBody = stmts.map((stmt) => {
|
|
3746
|
+
if (t2.isReturnStatement(stmt) && stmt.argument && (t2.isJSXElement(stmt.argument) || t2.isJSXFragment(stmt.argument))) {
|
|
3747
|
+
let spreadRes = transformArgsSpreadsInJsx(stmt.argument, merged), inlineRes = inlineArgsInJsx(spreadRes.node, merged);
|
|
3748
|
+
if (spreadRes.changed || inlineRes.changed)
|
|
3749
|
+
return changed = !0, t2.returnStatement(inlineRes.node);
|
|
3750
|
+
}
|
|
3751
|
+
return stmt;
|
|
3752
|
+
});
|
|
3753
|
+
if (changed)
|
|
3754
|
+
return t2.isFunctionDeclaration(fn) ? t2.functionDeclaration(fn.id, [], t2.blockStatement(newBody), fn.generator, fn.async) : t2.variableDeclaration("const", [
|
|
3755
|
+
t2.variableDeclarator(
|
|
3756
|
+
t2.identifier(storyName),
|
|
3757
|
+
t2.arrowFunctionExpression([], t2.blockStatement(newBody), fn.async)
|
|
3758
|
+
)
|
|
3759
|
+
]);
|
|
3760
|
+
}
|
|
3761
|
+
return t2.isFunctionDeclaration(fn) ? fn : t2.variableDeclaration("const", [t2.variableDeclarator(t2.identifier(storyName), fn)]);
|
|
3762
|
+
}
|
|
3763
|
+
invariant(componentName, "Could not generate snippet without component name.");
|
|
3764
|
+
let invalidSpread = buildInvalidSpread(invalidEntries), name = t2.jsxIdentifier(componentName), openingElAttrs = invalidSpread ? [...injectedAttrs, invalidSpread] : injectedAttrs, children = toJsxChildren(merged.children), selfClosing = children.length === 0, arrow = t2.arrowFunctionExpression(
|
|
3765
|
+
[],
|
|
3766
|
+
t2.jsxElement(
|
|
3767
|
+
t2.jsxOpeningElement(name, openingElAttrs, selfClosing),
|
|
3768
|
+
selfClosing ? null : t2.jsxClosingElement(name),
|
|
3769
|
+
children,
|
|
3770
|
+
selfClosing
|
|
3771
|
+
)
|
|
3772
|
+
);
|
|
3773
|
+
return t2.variableDeclaration("const", [t2.variableDeclarator(t2.identifier(storyName), arrow)]);
|
|
3774
|
+
}
|
|
3775
|
+
function buildInvalidSpread(entries) {
|
|
3776
|
+
if (entries.length === 0)
|
|
3777
|
+
return null;
|
|
3778
|
+
let objectProps = entries.map(
|
|
3779
|
+
([k, v]) => t2.objectProperty(t2.stringLiteral(k), t2.isExpression(v) ? v : t2.identifier("undefined"))
|
|
3780
|
+
);
|
|
3781
|
+
return t2.jsxSpreadAttribute(t2.objectExpression(objectProps));
|
|
3782
|
+
}
|
|
3783
|
+
var keyOf = (p) => t2.isIdentifier(p.key) ? p.key.name : t2.isStringLiteral(p.key) ? p.key.value : null, isValidJsxAttrName = (n) => /^[A-Za-z_][A-Za-z0-9_:-]*$/.test(n), argsRecordFromObjectPath = (objPath) => objPath ? Object.fromEntries(
|
|
3784
|
+
objPath.get("properties").filter((p) => p.isObjectProperty()).map((p) => [keyOf(p.node), p.get("value").node]).filter((e) => !!e[0])
|
|
3785
|
+
) : {};
|
|
3786
|
+
function storyArgsAssignmentPath(program, storyName) {
|
|
3787
|
+
let found = null;
|
|
3788
|
+
return program.traverse({
|
|
3789
|
+
AssignmentExpression(p) {
|
|
3790
|
+
let left = p.get("left"), right = p.get("right");
|
|
3791
|
+
if (left.isMemberExpression()) {
|
|
3792
|
+
let obj = left.get("object"), prop = left.get("property"), isStoryIdent = obj.isIdentifier() && obj.node.name === storyName, isArgsProp = prop.isIdentifier() && prop.node.name === "args" && !left.node.computed || t2.isStringLiteral(prop.node) && left.node.computed && prop.node.value === "args";
|
|
3793
|
+
isStoryIdent && isArgsProp && right.isObjectExpression() && (found = right);
|
|
3794
|
+
}
|
|
3795
|
+
}
|
|
3796
|
+
}), found;
|
|
3797
|
+
}
|
|
3798
|
+
var argsRecordFromObjectNode = (obj) => obj ? Object.fromEntries(
|
|
3799
|
+
obj.properties.filter((p) => t2.isObjectProperty(p)).map((p) => [keyOf(p), p.value]).filter((e) => !!e[0])
|
|
3800
|
+
) : {}, metaArgsRecord = (meta) => {
|
|
3801
|
+
if (!meta)
|
|
3802
|
+
return {};
|
|
3803
|
+
let argsProp = meta.properties.find(
|
|
3804
|
+
(p) => t2.isObjectProperty(p) && keyOf(p) === "args"
|
|
3805
|
+
);
|
|
3806
|
+
return argsProp && t2.isObjectExpression(argsProp.value) ? argsRecordFromObjectNode(argsProp.value) : {};
|
|
3807
|
+
}, toAttr = (key, value) => t2.isBooleanLiteral(value) ? value.value ? t2.jsxAttribute(t2.jsxIdentifier(key), null) : t2.jsxAttribute(t2.jsxIdentifier(key), t2.jsxExpressionContainer(value)) : t2.isStringLiteral(value) ? t2.jsxAttribute(t2.jsxIdentifier(key), t2.stringLiteral(value.value)) : t2.isExpression(value) ? t2.jsxAttribute(t2.jsxIdentifier(key), t2.jsxExpressionContainer(value)) : null, toJsxChildren = (node) => node ? t2.isStringLiteral(node) ? [t2.jsxText(node.value)] : t2.isJSXElement(node) || t2.isJSXFragment(node) ? [node] : t2.isExpression(node) ? [t2.jsxExpressionContainer(node)] : [] : [];
|
|
3808
|
+
function getArgsMemberKey(expr) {
|
|
3809
|
+
if (t2.isMemberExpression(expr) && t2.isIdentifier(expr.object) && expr.object.name === "args") {
|
|
3810
|
+
if (t2.isIdentifier(expr.property) && !expr.computed)
|
|
3811
|
+
return expr.property.name;
|
|
3812
|
+
if (t2.isStringLiteral(expr.property) && expr.computed)
|
|
3813
|
+
return expr.property.value;
|
|
3814
|
+
}
|
|
3815
|
+
if (t2.isOptionalMemberExpression?.(expr) && t2.isIdentifier(expr.object) && expr.object.name === "args") {
|
|
3816
|
+
let prop = expr.property;
|
|
3817
|
+
if (t2.isIdentifier(prop) && !expr.computed)
|
|
3818
|
+
return prop.name;
|
|
3819
|
+
if (t2.isStringLiteral(prop) && expr.computed)
|
|
3820
|
+
return prop.value;
|
|
3821
|
+
}
|
|
3822
|
+
return null;
|
|
3823
|
+
}
|
|
3824
|
+
function inlineArgsInJsx(node, merged) {
|
|
3825
|
+
let changed = !1;
|
|
3826
|
+
if (t2.isJSXElement(node)) {
|
|
3827
|
+
let opening = node.openingElement, newAttrs = opening.attributes.flatMap((a) => {
|
|
3828
|
+
if (!t2.isJSXAttribute(a))
|
|
3829
|
+
return [a];
|
|
3830
|
+
let name = t2.isJSXIdentifier(a.name) ? a.name.name : null;
|
|
3831
|
+
if (!(name && a.value && t2.isJSXExpressionContainer(a.value)))
|
|
3832
|
+
return [a];
|
|
3833
|
+
let key = getArgsMemberKey(a.value.expression);
|
|
3834
|
+
if (!(key && key in merged))
|
|
3835
|
+
return [a];
|
|
3836
|
+
let repl = toAttr(name, merged[key]);
|
|
3837
|
+
return changed = !0, repl ? [repl] : [];
|
|
3838
|
+
}), newChildren = node.children.flatMap((c) => {
|
|
3839
|
+
if (t2.isJSXElement(c) || t2.isJSXFragment(c)) {
|
|
3840
|
+
let res = inlineArgsInJsx(c, merged);
|
|
3841
|
+
return changed ||= res.changed, [res.node];
|
|
3842
|
+
}
|
|
3843
|
+
return t2.isJSXExpressionContainer(c) && getArgsMemberKey(c.expression) === "children" && merged.children ? (changed = !0, toJsxChildren(merged.children)) : [c];
|
|
3844
|
+
}), selfClosing = opening.selfClosing && newChildren.length === 0;
|
|
3845
|
+
return {
|
|
3846
|
+
node: t2.jsxElement(
|
|
3847
|
+
t2.jsxOpeningElement(opening.name, newAttrs, selfClosing),
|
|
3848
|
+
selfClosing ? null : node.closingElement ?? t2.jsxClosingElement(opening.name),
|
|
3849
|
+
newChildren,
|
|
3850
|
+
selfClosing
|
|
3851
|
+
),
|
|
3852
|
+
changed
|
|
3853
|
+
};
|
|
3854
|
+
}
|
|
3855
|
+
let fragChildren = node.children.flatMap((c) => {
|
|
3856
|
+
if (t2.isJSXElement(c) || t2.isJSXFragment(c)) {
|
|
3857
|
+
let res = inlineArgsInJsx(c, merged);
|
|
3858
|
+
return changed ||= res.changed, [res.node];
|
|
3715
3859
|
}
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
|
|
3860
|
+
return t2.isJSXExpressionContainer(c) && getArgsMemberKey(c.expression) === "children" && "children" in merged ? (changed = !0, toJsxChildren(merged.children)) : [c];
|
|
3861
|
+
});
|
|
3862
|
+
return { node: t2.jsxFragment(node.openingFragment, node.closingFragment, fragChildren), changed };
|
|
3863
|
+
}
|
|
3864
|
+
function transformArgsSpreadsInJsx(node, merged) {
|
|
3865
|
+
let changed = !1, makeInjectedPieces = (existing) => {
|
|
3866
|
+
let entries = Object.entries(merged).filter(([k, v]) => v != null && k !== "children"), validEntries = entries.filter(([k]) => isValidJsxAttrName(k)), invalidEntries = entries.filter(([k]) => !isValidJsxAttrName(k)), injectedAttrs = validEntries.map(([k, v]) => toAttr(k, v)).filter((a) => !!a).filter((a) => t2.isJSXIdentifier(a.name) && !existing.has(a.name.name)), invalidSpread = buildInvalidSpread(invalidEntries.filter(([k]) => !existing.has(k)));
|
|
3867
|
+
return invalidSpread ? [...injectedAttrs, invalidSpread] : injectedAttrs;
|
|
3868
|
+
};
|
|
3869
|
+
if (t2.isJSXElement(node)) {
|
|
3870
|
+
let opening = node.openingElement, attrs = opening.attributes, isArgsSpread = (a) => t2.isJSXSpreadAttribute(a) && t2.isIdentifier(a.argument) && a.argument.name === "args", sawArgsSpread = attrs.some(isArgsSpread), firstIdx = attrs.findIndex(isArgsSpread), nonArgsAttrs = attrs.filter((a) => !isArgsSpread(a)), insertionIndex = sawArgsSpread ? attrs.slice(0, firstIdx).filter((a) => !isArgsSpread(a)).length : 0, newAttrs = sawArgsSpread ? (() => {
|
|
3871
|
+
let existing = new Set(
|
|
3872
|
+
nonArgsAttrs.filter((a) => t2.isJSXAttribute(a)).flatMap((a) => t2.isJSXIdentifier(a.name) ? [a.name.name] : [])
|
|
3873
|
+
), pieces = makeInjectedPieces(existing);
|
|
3874
|
+
return changed = !0, [
|
|
3875
|
+
...nonArgsAttrs.slice(0, insertionIndex),
|
|
3876
|
+
...pieces,
|
|
3877
|
+
...nonArgsAttrs.slice(insertionIndex)
|
|
3878
|
+
];
|
|
3879
|
+
})() : nonArgsAttrs, newChildren = node.children.flatMap((c) => {
|
|
3880
|
+
if (t2.isJSXElement(c) || t2.isJSXFragment(c)) {
|
|
3881
|
+
let res = transformArgsSpreadsInJsx(c, merged);
|
|
3882
|
+
return changed ||= res.changed, [res.node];
|
|
3883
|
+
}
|
|
3884
|
+
return [c];
|
|
3885
|
+
}), children = sawArgsSpread && newChildren.length === 0 && merged.children ? (changed = !0, toJsxChildren(merged.children)) : newChildren, selfClosing = children.length === 0;
|
|
3886
|
+
return {
|
|
3887
|
+
node: t2.jsxElement(
|
|
3888
|
+
t2.jsxOpeningElement(opening.name, newAttrs, selfClosing),
|
|
3889
|
+
selfClosing ? null : node.closingElement ?? t2.jsxClosingElement(opening.name),
|
|
3890
|
+
children,
|
|
3891
|
+
selfClosing
|
|
3892
|
+
),
|
|
3893
|
+
changed
|
|
3894
|
+
};
|
|
3895
|
+
}
|
|
3896
|
+
let fragChildren = node.children.flatMap((c) => {
|
|
3897
|
+
if (t2.isJSXElement(c) || t2.isJSXFragment(c)) {
|
|
3898
|
+
let res = transformArgsSpreadsInJsx(c, merged);
|
|
3899
|
+
return changed ||= res.changed, [res.node];
|
|
3756
3900
|
}
|
|
3757
|
-
|
|
3758
|
-
|
|
3759
|
-
),
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
`)
|
|
3774
|
-
} };
|
|
3775
|
-
},
|
|
3776
|
-
{ name: "getReactDocgen", key: (path2, component) => path2 + JSON.stringify(component) }
|
|
3777
|
-
);
|
|
3778
|
-
function getReactDocgenImporter() {
|
|
3779
|
-
return makeFsImporter((filename, basedir) => {
|
|
3780
|
-
let mappedFilenameByPaths = matchPath(filename, basedir), result = cachedResolveImport(mappedFilenameByPaths, { basedir });
|
|
3781
|
-
if (result.includes(`${sep2}react-native${sep2}index.js`)) {
|
|
3782
|
-
let replaced = result.replace(
|
|
3783
|
-
`${sep2}react-native${sep2}index.js`,
|
|
3784
|
-
`${sep2}react-native-web${sep2}dist${sep2}index.js`
|
|
3785
|
-
);
|
|
3786
|
-
if (existsSync2(replaced) && supportedExtensions2.find((ext) => result.endsWith(ext)))
|
|
3787
|
-
return replaced;
|
|
3901
|
+
return [c];
|
|
3902
|
+
});
|
|
3903
|
+
return { node: t2.jsxFragment(node.openingFragment, node.closingFragment, fragChildren), changed };
|
|
3904
|
+
}
|
|
3905
|
+
function resolveBindIdentifierInit(storyPath, identifier) {
|
|
3906
|
+
let programPath = storyPath.findParent((p) => p.isProgram());
|
|
3907
|
+
if (!programPath)
|
|
3908
|
+
return null;
|
|
3909
|
+
let match = programPath.get("body").flatMap((stmt) => {
|
|
3910
|
+
if (stmt.isVariableDeclaration())
|
|
3911
|
+
return stmt.get("declarations");
|
|
3912
|
+
if (stmt.isExportNamedDeclaration()) {
|
|
3913
|
+
let decl = stmt.get("declaration");
|
|
3914
|
+
if (decl && decl.isVariableDeclaration())
|
|
3915
|
+
return decl.get("declarations");
|
|
3788
3916
|
}
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3917
|
+
return [];
|
|
3918
|
+
}).find((d) => {
|
|
3919
|
+
let id = d.get("id");
|
|
3920
|
+
return id.isIdentifier() && id.node.name === identifier.node.name;
|
|
3792
3921
|
});
|
|
3922
|
+
if (!match)
|
|
3923
|
+
return null;
|
|
3924
|
+
let init = match.get("init");
|
|
3925
|
+
return init && init.isExpression() ? init : null;
|
|
3793
3926
|
}
|
|
3794
|
-
function
|
|
3795
|
-
|
|
3796
|
-
|
|
3927
|
+
function pathForNode(program, target) {
|
|
3928
|
+
if (!target)
|
|
3929
|
+
return;
|
|
3930
|
+
let found;
|
|
3931
|
+
return program.traverse({
|
|
3932
|
+
enter(p) {
|
|
3933
|
+
p.node && p.node === target && (found = p, p.stop());
|
|
3934
|
+
}
|
|
3935
|
+
}), found;
|
|
3797
3936
|
}
|
|
3798
3937
|
|
|
3799
3938
|
// src/componentManifest/getComponentImports.ts
|
|
3939
|
+
import { dirname as dirname4 } from "node:path";
|
|
3940
|
+
import { babelParse as babelParse2, recast, types as t3 } from "storybook/internal/babel";
|
|
3941
|
+
import { logger as logger4 } from "storybook/internal/node-logger";
|
|
3800
3942
|
var baseIdentifier = (component) => component.split(".")[0] ?? component, isTypeSpecifier = (s) => t3.isImportSpecifier(s) && s.importKind === "type", importedName = (im) => t3.isIdentifier(im) ? im.name : im.value, addUniqueBy = (arr, item, eq) => {
|
|
3801
3943
|
arr.find(eq) || arr.push(item);
|
|
3802
3944
|
}, getComponents = ({
|
|
@@ -3872,24 +4014,24 @@ var baseIdentifier = (component) => component.split(".")[0] ?? component, isType
|
|
|
3872
4014
|
importName: direct.importName
|
|
3873
4015
|
} : { componentName: c };
|
|
3874
4016
|
}).map((component) => {
|
|
3875
|
-
let
|
|
4017
|
+
let path3, isPackage = !1;
|
|
3876
4018
|
try {
|
|
3877
|
-
component.importId && storyFilePath && (
|
|
4019
|
+
component.importId && storyFilePath && (path3 = cachedResolveImport(matchPath(component.importId, dirname4(storyFilePath)), {
|
|
3878
4020
|
basedir: dirname4(storyFilePath)
|
|
3879
4021
|
}));
|
|
3880
4022
|
} catch (e) {
|
|
3881
|
-
|
|
4023
|
+
logger4.debug(e);
|
|
3882
4024
|
}
|
|
3883
4025
|
try {
|
|
3884
4026
|
component.importId && !component.importId.startsWith(".") && storyFilePath && (cachedResolveImport(component.importId, { basedir: dirname4(storyFilePath) }), isPackage = !0);
|
|
3885
4027
|
} catch {
|
|
3886
4028
|
}
|
|
3887
4029
|
let componentWithPackage = { ...component, isPackage };
|
|
3888
|
-
if (
|
|
3889
|
-
let reactDocgen = getReactDocgen(
|
|
4030
|
+
if (path3) {
|
|
4031
|
+
let reactDocgen = getReactDocgen(path3, componentWithPackage);
|
|
3890
4032
|
return {
|
|
3891
4033
|
...componentWithPackage,
|
|
3892
|
-
path:
|
|
4034
|
+
path: path3,
|
|
3893
4035
|
reactDocgen,
|
|
3894
4036
|
importOverride: reactDocgen.type === "success" ? getImportTag(reactDocgen.data) : void 0
|
|
3895
4037
|
};
|
|
@@ -4038,58 +4180,81 @@ var baseIdentifier = (component) => component.split(".")[0] ?? component, isType
|
|
|
4038
4180
|
};
|
|
4039
4181
|
|
|
4040
4182
|
// src/componentManifest/generator.ts
|
|
4041
|
-
|
|
4042
|
-
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
name: storyName,
|
|
4065
|
-
snippet: recast2.print(getCodeSnippet(csf, storyName, component?.componentName)).code,
|
|
4066
|
-
description: finalDescription?.trim(),
|
|
4067
|
-
summary: tags2.summary?.[0]
|
|
4068
|
-
};
|
|
4069
|
-
} catch (e) {
|
|
4070
|
-
return invariant(e instanceof Error), {
|
|
4071
|
-
name: storyName,
|
|
4072
|
-
error: { name: e.name, message: e.message }
|
|
4073
|
-
};
|
|
4074
|
-
}
|
|
4075
|
-
}).filter((it) => it != null), nearestPkg = cachedFindUp("package.json", {
|
|
4076
|
-
cwd: path.dirname(component?.path ?? absoluteImportPath)
|
|
4077
|
-
}), packageName;
|
|
4183
|
+
function findMatchingComponent(components, componentName, trimmedTitle) {
|
|
4184
|
+
return components.find(
|
|
4185
|
+
(it) => componentName ? [it.componentName, it.localImportName, it.importName].includes(componentName) : trimmedTitle.includes(it.componentName) || it.localImportName && trimmedTitle.includes(it.localImportName) || it.importName && trimmedTitle.includes(it.importName)
|
|
4186
|
+
);
|
|
4187
|
+
}
|
|
4188
|
+
function getPackageInfo(componentPath, fallbackPath) {
|
|
4189
|
+
let nearestPkg = cachedFindUp("package.json", {
|
|
4190
|
+
cwd: path.dirname(componentPath ?? fallbackPath)
|
|
4191
|
+
});
|
|
4192
|
+
try {
|
|
4193
|
+
return nearestPkg ? JSON.parse(cachedReadFileSync(nearestPkg, "utf-8")).name : void 0;
|
|
4194
|
+
} catch {
|
|
4195
|
+
return;
|
|
4196
|
+
}
|
|
4197
|
+
}
|
|
4198
|
+
function extractStories(csf, componentName, manifestEntries) {
|
|
4199
|
+
let manifestEntryIds = new Set(manifestEntries.map((entry) => entry.id));
|
|
4200
|
+
return Object.entries(csf._stories).filter(
|
|
4201
|
+
([, story]) => (
|
|
4202
|
+
// Only include stories that are in the list of entries already filtered for the 'manifest' tag
|
|
4203
|
+
manifestEntryIds.has(story.id)
|
|
4204
|
+
)
|
|
4205
|
+
).map(([storyName]) => {
|
|
4078
4206
|
try {
|
|
4079
|
-
|
|
4080
|
-
|
|
4207
|
+
let jsdocComment = extractDescription(csf._storyStatements[storyName]), { tags = {}, description } = jsdocComment ? extractJSDocInfo(jsdocComment) : {}, finalDescription = (tags?.describe?.[0] || tags?.desc?.[0]) ?? description;
|
|
4208
|
+
return {
|
|
4209
|
+
name: storyName,
|
|
4210
|
+
snippet: recast2.print(getCodeSnippet(csf, storyName, componentName)).code,
|
|
4211
|
+
description: finalDescription?.trim(),
|
|
4212
|
+
summary: tags.summary?.[0]
|
|
4213
|
+
};
|
|
4214
|
+
} catch (e) {
|
|
4215
|
+
return invariant(e instanceof Error), {
|
|
4216
|
+
name: storyName,
|
|
4217
|
+
error: { name: e.name, message: e.message }
|
|
4218
|
+
};
|
|
4081
4219
|
}
|
|
4082
|
-
|
|
4083
|
-
|
|
4220
|
+
});
|
|
4221
|
+
}
|
|
4222
|
+
function extractComponentDescription(csf, docgen) {
|
|
4223
|
+
let jsdocComment = extractDescription(csf._metaStatement) || docgen?.description, { tags = {}, description } = jsdocComment ? extractJSDocInfo(jsdocComment) : {};
|
|
4224
|
+
return {
|
|
4225
|
+
description: ((tags?.describe?.[0] || tags?.desc?.[0]) ?? description)?.trim(),
|
|
4226
|
+
summary: tags.summary?.[0],
|
|
4227
|
+
jsDocTags: tags
|
|
4228
|
+
};
|
|
4229
|
+
}
|
|
4230
|
+
var manifests = async (existingManifests = {}, { manifestEntries }) => {
|
|
4231
|
+
invalidateCache();
|
|
4232
|
+
let startPerformance = performance.now(), components = uniqBy(
|
|
4233
|
+
manifestEntries.filter(
|
|
4234
|
+
(entry) => entry.type === "story" && entry.subtype === "story" || // addon-docs will add docs entries to these manifest entries afterwards
|
|
4235
|
+
// Docs entries have importPath pointing to MDX file, but storiesImports[0] points to the story file
|
|
4236
|
+
entry.type === "docs" && entry.tags?.includes(Tag.ATTACHED_MDX) && entry.storiesImports.length > 0
|
|
4237
|
+
),
|
|
4238
|
+
(entry) => entry.id.split("--")[0]
|
|
4239
|
+
).map((entry) => {
|
|
4240
|
+
let storyFilePath = entry.type === "story" ? entry.importPath : (
|
|
4241
|
+
// For attached docs entries, storiesImports[0] points to the stories file being attached to
|
|
4242
|
+
entry.storiesImports[0]
|
|
4243
|
+
), absoluteImportPath = path.join(process.cwd(), storyFilePath), storyFile = cachedReadFileSync(absoluteImportPath, "utf-8"), csf = loadCsf(storyFile, { makeTitle: (title2) => title2 ?? "No title" }).parse(), componentName = csf._meta?.component, id = entry.id.split("--")[0], title = entry.title.split("/").at(-1).replace(/\s+/g, ""), allComponents = getComponents({ csf, storyFilePath: absoluteImportPath }), component = findMatchingComponent(
|
|
4244
|
+
allComponents,
|
|
4245
|
+
componentName,
|
|
4246
|
+
entry.title.replace(/\s+/g, "")
|
|
4247
|
+
), packageName = getPackageInfo(component?.path, absoluteImportPath), fallbackImport = packageName && componentName ? `import { ${componentName} } from "${packageName}";` : "", imports = getImports({ components: allComponents, packageName }).join(`
|
|
4248
|
+
`).trim() || fallbackImport, stories = extractStories(csf, component?.componentName, manifestEntries), base = {
|
|
4084
4249
|
id,
|
|
4085
4250
|
name: componentName ?? title,
|
|
4086
|
-
path:
|
|
4251
|
+
path: storyFilePath,
|
|
4087
4252
|
stories,
|
|
4088
4253
|
import: imports,
|
|
4089
4254
|
jsDocTags: {}
|
|
4090
4255
|
};
|
|
4091
4256
|
if (!component?.reactDocgen) {
|
|
4092
|
-
let
|
|
4257
|
+
let error = csf._meta?.component ? {
|
|
4093
4258
|
name: "No component import found",
|
|
4094
4259
|
message: `No component file found for the "${csf.meta.component}" component.`
|
|
4095
4260
|
} : {
|
|
@@ -4099,32 +4264,33 @@ var componentManifestGenerator = async () => (async (storyIndexGenerator) => {
|
|
|
4099
4264
|
return {
|
|
4100
4265
|
...base,
|
|
4101
4266
|
error: {
|
|
4102
|
-
name:
|
|
4103
|
-
message: (csf._metaStatementPath?.buildCodeFrameError(
|
|
4267
|
+
name: error.name,
|
|
4268
|
+
message: (csf._metaStatementPath?.buildCodeFrameError(error.message).message ?? error.message) + `
|
|
4104
4269
|
|
|
4105
4270
|
${entry.importPath}:
|
|
4106
4271
|
${storyFile}`
|
|
4107
4272
|
}
|
|
4108
4273
|
};
|
|
4109
4274
|
}
|
|
4110
|
-
let docgenResult = component.reactDocgen, docgen = docgenResult.type === "success" ? docgenResult.data : void 0,
|
|
4275
|
+
let docgenResult = component.reactDocgen, docgen = docgenResult.type === "success" ? docgenResult.data : void 0, { description, summary, jsDocTags } = extractComponentDescription(csf, docgen);
|
|
4111
4276
|
return {
|
|
4112
4277
|
...base,
|
|
4113
|
-
description
|
|
4114
|
-
summary
|
|
4278
|
+
description,
|
|
4279
|
+
summary,
|
|
4115
4280
|
import: imports,
|
|
4116
4281
|
reactDocgen: docgen,
|
|
4117
|
-
jsDocTags
|
|
4118
|
-
error
|
|
4282
|
+
jsDocTags,
|
|
4283
|
+
error: docgenResult.type === "error" ? docgenResult.error : void 0
|
|
4119
4284
|
};
|
|
4120
|
-
});
|
|
4121
|
-
return
|
|
4122
|
-
|
|
4123
|
-
components:
|
|
4124
|
-
|
|
4125
|
-
|
|
4285
|
+
}).filter((component) => component !== void 0);
|
|
4286
|
+
return logger5.verbose(`Component manifest generation took ${performance.now() - startPerformance}ms`), {
|
|
4287
|
+
...existingManifests,
|
|
4288
|
+
components: {
|
|
4289
|
+
v: 0,
|
|
4290
|
+
components: Object.fromEntries(components.map((component) => [component.id, component]))
|
|
4291
|
+
}
|
|
4126
4292
|
};
|
|
4127
|
-
}
|
|
4293
|
+
};
|
|
4128
4294
|
|
|
4129
4295
|
// src/enrichCsf.ts
|
|
4130
4296
|
import { recast as recast3, types as t4 } from "storybook/internal/babel";
|
|
@@ -4226,10 +4392,29 @@ var addons = [
|
|
|
4226
4392
|
return existing;
|
|
4227
4393
|
}
|
|
4228
4394
|
};
|
|
4395
|
+
async function internal_getArgTypesData(_input, options) {
|
|
4396
|
+
let { componentFilePath, componentExportName } = options ?? {};
|
|
4397
|
+
if (!componentFilePath)
|
|
4398
|
+
return null;
|
|
4399
|
+
let argTypesData = extractArgTypesFromDocgen({
|
|
4400
|
+
componentFilePath: path2.isAbsolute(componentFilePath) ? componentFilePath : join5(getProjectRoot2(), componentFilePath),
|
|
4401
|
+
componentExportName
|
|
4402
|
+
});
|
|
4403
|
+
if (!argTypesData?.props)
|
|
4404
|
+
return null;
|
|
4405
|
+
let argTypes = {};
|
|
4406
|
+
for (let [propName, propInfo] of Object.entries(argTypesData.props))
|
|
4407
|
+
argTypes[propName] = {
|
|
4408
|
+
name: propName,
|
|
4409
|
+
type: propInfo.required ? { ...propInfo.type, required: !0 } : propInfo.type
|
|
4410
|
+
};
|
|
4411
|
+
return argTypes;
|
|
4412
|
+
}
|
|
4229
4413
|
export {
|
|
4230
4414
|
addons,
|
|
4231
|
-
componentManifestGenerator as experimental_componentManifestGenerator,
|
|
4232
4415
|
enrichCsf as experimental_enrichCsf,
|
|
4416
|
+
manifests as experimental_manifests,
|
|
4417
|
+
internal_getArgTypesData,
|
|
4233
4418
|
previewAnnotations,
|
|
4234
4419
|
resolvedReact
|
|
4235
4420
|
};
|