@storybook/react 11.0.0-rc.2 → 11.0.0-rc.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_browser-chunks/{chunk-KI7YBTX7.js → chunk-VG7VCVF3.js} +2 -2
- package/dist/_node-chunks/{chunk-VEMSK7QJ.js → chunk-6DVQPLAK.js} +1 -1
- package/dist/_node-chunks/{chunk-CJ2XYAXX.js → chunk-M3SEC5XW.js} +321 -27
- package/dist/_node-chunks/chunk-PQZIOGBY.js +1 -1
- package/dist/_node-chunks/{chunk-XPEWS4XG.js → chunk-PVKC5GIW.js} +19 -4
- package/dist/_node-chunks/{chunk-N7TOZR54.js → chunk-RIMY5QBX.js} +10 -6
- package/dist/_node-chunks/{chunk-E7AXB5JU.js → chunk-ZGMTV3ZQ.js} +275 -455
- package/dist/_node-chunks/{extractArgTypesFromComponentFile-JKOCA6RX.js → extractArgTypesFromComponentFile-2KTCTT6A.js} +4 -4
- package/dist/_node-chunks/{extractReactDocgenInfo-L44YP4OM.js → extractReactDocgenInfo-Z5DJORGO.js} +2 -2
- package/dist/_node-chunks/{reactDocgen-WMOVFLAX.js → reactDocgen-CS462JSF.js} +2 -2
- package/dist/docgen/docgen-worker.js +5 -3
- package/dist/docs/register-print-hole.js +1 -1
- package/dist/entry-preview-docs.js +1 -1
- package/dist/index.js +1 -1
- package/dist/preset.js +9 -9
- package/dist/preview.js +1 -1
- package/package.json +3 -3
|
@@ -11,8 +11,10 @@ import {
|
|
|
11
11
|
getImportTag,
|
|
12
12
|
groupByToMap,
|
|
13
13
|
invariant,
|
|
14
|
-
matchPath
|
|
15
|
-
|
|
14
|
+
matchPath,
|
|
15
|
+
posix,
|
|
16
|
+
relative
|
|
17
|
+
} from "./chunk-M3SEC5XW.js";
|
|
16
18
|
import {
|
|
17
19
|
__commonJS,
|
|
18
20
|
__toESM
|
|
@@ -1563,7 +1565,7 @@ var require_proxyLanguageService = __commonJS({
|
|
|
1563
1565
|
};
|
|
1564
1566
|
}
|
|
1565
1567
|
function getEncodedSemanticClassifications(language, getEncodedSemanticClassifications2) {
|
|
1566
|
-
return (filePath, span,
|
|
1568
|
+
return (filePath, span, format) => {
|
|
1567
1569
|
let fileName = filePath.replace(windowsPathReg, "/"), [serviceScript, targetScript, sourceScript] = (0, utils_1.getServiceScript)(language, fileName);
|
|
1568
1570
|
if (targetScript?.associatedOnly)
|
|
1569
1571
|
return {
|
|
@@ -1577,7 +1579,7 @@ var require_proxyLanguageService = __commonJS({
|
|
|
1577
1579
|
spans: [],
|
|
1578
1580
|
endOfLineState: 0
|
|
1579
1581
|
};
|
|
1580
|
-
let mappingOffset = (0, transform_1.getMappingOffset)(language, serviceScript), start = mapped.start + mappingOffset, end = mapped.end + mappingOffset, result = getEncodedSemanticClassifications2(targetScript.id, { start, length: end - start },
|
|
1582
|
+
let mappingOffset = (0, transform_1.getMappingOffset)(language, serviceScript), start = mapped.start + mappingOffset, end = mapped.end + mappingOffset, result = getEncodedSemanticClassifications2(targetScript.id, { start, length: end - start }, format), spans = [];
|
|
1581
1583
|
for (let i = 0; i < result.spans.length; i += 3)
|
|
1582
1584
|
for (let [_, sourceStart, sourceEnd] of (0, transform_1.toSourceRanges)(sourceScript, language, serviceScript, result.spans[i], result.spans[i] + result.spans[i + 1], !1, language_core_1.isSemanticTokensEnabled)) {
|
|
1583
1585
|
spans.push(sourceStart, sourceEnd - sourceStart, result.spans[i + 2]);
|
|
@@ -1585,7 +1587,7 @@ var require_proxyLanguageService = __commonJS({
|
|
|
1585
1587
|
}
|
|
1586
1588
|
return result.spans = spans, result;
|
|
1587
1589
|
} else
|
|
1588
|
-
return getEncodedSemanticClassifications2(fileName, span,
|
|
1590
|
+
return getEncodedSemanticClassifications2(fileName, span, format);
|
|
1589
1591
|
};
|
|
1590
1592
|
}
|
|
1591
1593
|
function getSyntacticDiagnostics(language, languageService, getSyntacticDiagnostics2) {
|
|
@@ -1833,23 +1835,23 @@ var require_path_browserify = __commonJS({
|
|
|
1833
1835
|
}
|
|
1834
1836
|
return res;
|
|
1835
1837
|
}
|
|
1836
|
-
function _format(
|
|
1838
|
+
function _format(sep, pathObject) {
|
|
1837
1839
|
var dir = pathObject.dir || pathObject.root, base = pathObject.base || (pathObject.name || "") + (pathObject.ext || "");
|
|
1838
|
-
return dir ? dir === pathObject.root ? dir + base : dir +
|
|
1840
|
+
return dir ? dir === pathObject.root ? dir + base : dir + sep + base : base;
|
|
1839
1841
|
}
|
|
1840
1842
|
var posix2 = {
|
|
1841
1843
|
// path.resolve([from ...], to)
|
|
1842
1844
|
resolve: function() {
|
|
1843
|
-
for (var resolvedPath = "", resolvedAbsolute = !1,
|
|
1845
|
+
for (var resolvedPath = "", resolvedAbsolute = !1, cwd, i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) {
|
|
1844
1846
|
var path2;
|
|
1845
|
-
i >= 0 ? path2 = arguments[i] : (
|
|
1847
|
+
i >= 0 ? path2 = arguments[i] : (cwd === void 0 && (cwd = process.cwd()), path2 = cwd), assertPath(path2), path2.length !== 0 && (resolvedPath = path2 + "/" + resolvedPath, resolvedAbsolute = path2.charCodeAt(0) === 47);
|
|
1846
1848
|
}
|
|
1847
1849
|
return resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute), resolvedAbsolute ? resolvedPath.length > 0 ? "/" + resolvedPath : "/" : resolvedPath.length > 0 ? resolvedPath : ".";
|
|
1848
1850
|
},
|
|
1849
1851
|
normalize: function(path2) {
|
|
1850
1852
|
if (assertPath(path2), path2.length === 0) return ".";
|
|
1851
|
-
var
|
|
1852
|
-
return path2 = normalizeStringPosix(path2, !
|
|
1853
|
+
var isAbsolute2 = path2.charCodeAt(0) === 47, trailingSeparator = path2.charCodeAt(path2.length - 1) === 47;
|
|
1854
|
+
return path2 = normalizeStringPosix(path2, !isAbsolute2), path2.length === 0 && !isAbsolute2 && (path2 = "."), path2.length > 0 && trailingSeparator && (path2 += "/"), isAbsolute2 ? "/" + path2 : path2;
|
|
1853
1855
|
},
|
|
1854
1856
|
isAbsolute: function(path2) {
|
|
1855
1857
|
return assertPath(path2), path2.length > 0 && path2.charCodeAt(0) === 47;
|
|
@@ -1959,8 +1961,8 @@ var require_path_browserify = __commonJS({
|
|
|
1959
1961
|
assertPath(path2);
|
|
1960
1962
|
var ret = { root: "", dir: "", base: "", ext: "", name: "" };
|
|
1961
1963
|
if (path2.length === 0) return ret;
|
|
1962
|
-
var code = path2.charCodeAt(0),
|
|
1963
|
-
|
|
1964
|
+
var code = path2.charCodeAt(0), isAbsolute2 = code === 47, start;
|
|
1965
|
+
isAbsolute2 ? (ret.root = "/", start = 1) : start = 0;
|
|
1964
1966
|
for (var startDot = -1, startPart = 0, end = -1, matchedSlash = !0, i = path2.length - 1, preDotState = 0; i >= start; --i) {
|
|
1965
1967
|
if (code = path2.charCodeAt(i), code === 47) {
|
|
1966
1968
|
if (!matchedSlash) {
|
|
@@ -1973,7 +1975,7 @@ var require_path_browserify = __commonJS({
|
|
|
1973
1975
|
}
|
|
1974
1976
|
return startDot === -1 || end === -1 || // We saw a non-dot character immediately before the dot
|
|
1975
1977
|
preDotState === 0 || // The (right-most) trimmed path component is exactly '..'
|
|
1976
|
-
preDotState === 1 && startDot === end - 1 && startDot === startPart + 1 ? end !== -1 && (startPart === 0 &&
|
|
1978
|
+
preDotState === 1 && startDot === end - 1 && startDot === startPart + 1 ? end !== -1 && (startPart === 0 && isAbsolute2 ? ret.base = ret.name = path2.slice(1, end) : ret.base = ret.name = path2.slice(startPart, end)) : (startPart === 0 && isAbsolute2 ? (ret.name = path2.slice(1, startDot), ret.base = path2.slice(1, end)) : (ret.name = path2.slice(startPart, startDot), ret.base = path2.slice(startPart, end)), ret.ext = path2.slice(startDot, end)), startPart > 0 ? ret.dir = path2.slice(0, startPart - 1) : isAbsolute2 && (ret.dir = "/"), ret;
|
|
1977
1979
|
},
|
|
1978
1980
|
sep: "/",
|
|
1979
1981
|
delimiter: ":",
|
|
@@ -4201,7 +4203,6 @@ import * as path from "path";
|
|
|
4201
4203
|
import { logger as logger2 } from "storybook/internal/node-logger";
|
|
4202
4204
|
|
|
4203
4205
|
// src/componentManifest/componentMeta/componentMetaExtractor.ts
|
|
4204
|
-
import { extractComponentJsDocInfo } from "storybook/internal/component-meta";
|
|
4205
4206
|
var LARGE_SOURCE_THRESHOLD = 30, MAX_UNWRAP_DEPTH = 5, MAX_SERIALIZATION_DEPTH = 5, ARRAY_SYMBOL_NAMES = /* @__PURE__ */ new Set(["Array", "ReadonlyArray"]);
|
|
4206
4207
|
function isLiteralType(type) {
|
|
4207
4208
|
return type.isStringLiteral() || type.isNumberLiteral();
|
|
@@ -4841,19 +4842,13 @@ function serializeComponentDoc(typescript, checker, {
|
|
|
4841
4842
|
);
|
|
4842
4843
|
unionForceOptional?.has(prop.getName()) && (item.required = !1), props[prop.getName()] = item;
|
|
4843
4844
|
}
|
|
4844
|
-
let displayName = (isMemberSelection ? displayNameOverride : void 0) ?? computeDisplayName({
|
|
4845
|
-
exportSymbol,
|
|
4846
|
-
resolvedSymbol: resolved
|
|
4847
|
-
}) ?? displayNameOverride, resolvedJsDocInfo = extractComponentJsDocInfo(typescript, checker, resolved), description = resolvedJsDocInfo.description, selectedJsDocTags = resolvedJsDocInfo.jsDocTags, exportResolved = exportSymbol && exportSymbol !== resolved ? resolveAliasedSymbol(typescript, checker, exportSymbol) : void 0, exportJsDocTags = exportResolved ? extractComponentJsDocInfo(typescript, checker, exportResolved).jsDocTags : void 0, jsDocTags = selectedJsDocTags?.import || !exportJsDocTags?.import ? selectedJsDocTags : {
|
|
4848
|
-
...selectedJsDocTags ?? {},
|
|
4849
|
-
import: exportJsDocTags.import
|
|
4850
|
-
};
|
|
4851
4845
|
return {
|
|
4852
|
-
displayName
|
|
4846
|
+
displayName: (isMemberSelection ? displayNameOverride : void 0) ?? computeDisplayName({
|
|
4847
|
+
exportSymbol,
|
|
4848
|
+
resolvedSymbol: resolved
|
|
4849
|
+
}) ?? displayNameOverride,
|
|
4853
4850
|
exportName,
|
|
4854
4851
|
filePath,
|
|
4855
|
-
description,
|
|
4856
|
-
jsDocTags,
|
|
4857
4852
|
props
|
|
4858
4853
|
};
|
|
4859
4854
|
}
|
|
@@ -5000,7 +4995,7 @@ function extractEntries({ typescript, checker, program, resolveModule }, entries
|
|
|
5000
4995
|
resolvedComponent,
|
|
5001
4996
|
defaultsSourcePath: serializationContext.defaultsSourcePath
|
|
5002
4997
|
});
|
|
5003
|
-
doc && (entryComponent.reactComponentMeta = doc
|
|
4998
|
+
doc && (entryComponent.reactComponentMeta = doc);
|
|
5004
4999
|
} catch (error) {
|
|
5005
5000
|
logger2.debug(`[reactComponentMeta] Extraction failed for ${entry.storyPath}: ${error}`);
|
|
5006
5001
|
continue;
|
|
@@ -5284,296 +5279,6 @@ var ComponentMetaManager = class extends BaseComponentMetaManager {
|
|
|
5284
5279
|
}
|
|
5285
5280
|
}, isExtractable = (storyRef) => !!storyRef.component?.path && !!storyRef.component.importName;
|
|
5286
5281
|
|
|
5287
|
-
// ../../../node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
|
|
5288
|
-
var _lazyMatch = () => {
|
|
5289
|
-
var __lib__ = (() => {
|
|
5290
|
-
var m = Object.defineProperty, V = Object.getOwnPropertyDescriptor, G = Object.getOwnPropertyNames, T = Object.prototype.hasOwnProperty, q = (r, e) => {
|
|
5291
|
-
for (var n in e) m(r, n, { get: e[n], enumerable: !0 });
|
|
5292
|
-
}, H = (r, e, n, a) => {
|
|
5293
|
-
if (e && typeof e == "object" || typeof e == "function") for (let t of G(e)) !T.call(r, t) && t !== n && m(r, t, { get: () => e[t], enumerable: !(a = V(e, t)) || a.enumerable });
|
|
5294
|
-
return r;
|
|
5295
|
-
}, J = (r) => H(m({}, "__esModule", { value: !0 }), r), w = {};
|
|
5296
|
-
q(w, { default: () => re });
|
|
5297
|
-
var A = (r) => Array.isArray(r), d = (r) => typeof r == "function", Q = (r) => r.length === 0, W = (r) => typeof r == "number", K = (r) => typeof r == "object" && r !== null, X = (r) => r instanceof RegExp, b = (r) => typeof r == "string", h = (r) => r === void 0, Y = (r) => {
|
|
5298
|
-
let e = /* @__PURE__ */ new Map();
|
|
5299
|
-
return (n) => {
|
|
5300
|
-
let a = e.get(n);
|
|
5301
|
-
if (a) return a;
|
|
5302
|
-
let t = r(n);
|
|
5303
|
-
return e.set(n, t), t;
|
|
5304
|
-
};
|
|
5305
|
-
}, rr = (r, e, n = {}) => {
|
|
5306
|
-
let a = { cache: {}, input: r, index: 0, indexMax: 0, options: n, output: [] };
|
|
5307
|
-
if (v(e)(a) && a.index === r.length) return a.output;
|
|
5308
|
-
throw new Error(`Failed to parse at index ${a.indexMax}`);
|
|
5309
|
-
}, i = (r, e) => A(r) ? er(r, e) : b(r) ? ar(r, e) : nr(r, e), er = (r, e) => {
|
|
5310
|
-
let n = {};
|
|
5311
|
-
for (let a of r) {
|
|
5312
|
-
if (a.length !== 1) throw new Error(`Invalid character: "${a}"`);
|
|
5313
|
-
let t = a.charCodeAt(0);
|
|
5314
|
-
n[t] = !0;
|
|
5315
|
-
}
|
|
5316
|
-
return (a) => {
|
|
5317
|
-
let t = a.index, o = a.input;
|
|
5318
|
-
for (; a.index < o.length && o.charCodeAt(a.index) in n; ) a.index += 1;
|
|
5319
|
-
let u = a.index;
|
|
5320
|
-
if (u > t) {
|
|
5321
|
-
if (!h(e) && !a.options.silent) {
|
|
5322
|
-
let s = a.input.slice(t, u), c = d(e) ? e(s, o, String(t)) : e;
|
|
5323
|
-
h(c) || a.output.push(c);
|
|
5324
|
-
}
|
|
5325
|
-
a.indexMax = Math.max(a.indexMax, a.index);
|
|
5326
|
-
}
|
|
5327
|
-
return !0;
|
|
5328
|
-
};
|
|
5329
|
-
}, nr = (r, e) => {
|
|
5330
|
-
let n = r.source, a = r.flags.replace(/y|$/, "y"), t = new RegExp(n, a);
|
|
5331
|
-
return g((o) => {
|
|
5332
|
-
t.lastIndex = o.index;
|
|
5333
|
-
let u = t.exec(o.input);
|
|
5334
|
-
if (u) {
|
|
5335
|
-
if (!h(e) && !o.options.silent) {
|
|
5336
|
-
let s = d(e) ? e(...u, o.input, String(o.index)) : e;
|
|
5337
|
-
h(s) || o.output.push(s);
|
|
5338
|
-
}
|
|
5339
|
-
return o.index += u[0].length, o.indexMax = Math.max(o.indexMax, o.index), !0;
|
|
5340
|
-
} else return !1;
|
|
5341
|
-
});
|
|
5342
|
-
}, ar = (r, e) => (n) => {
|
|
5343
|
-
if (n.input.startsWith(r, n.index)) {
|
|
5344
|
-
if (!h(e) && !n.options.silent) {
|
|
5345
|
-
let t = d(e) ? e(r, n.input, String(n.index)) : e;
|
|
5346
|
-
h(t) || n.output.push(t);
|
|
5347
|
-
}
|
|
5348
|
-
return n.index += r.length, n.indexMax = Math.max(n.indexMax, n.index), !0;
|
|
5349
|
-
} else return !1;
|
|
5350
|
-
}, C = (r, e, n, a) => {
|
|
5351
|
-
let t = v(r);
|
|
5352
|
-
return g(_(M((o) => {
|
|
5353
|
-
let u = 0;
|
|
5354
|
-
for (; u < n; ) {
|
|
5355
|
-
let s = o.index;
|
|
5356
|
-
if (!t(o) || (u += 1, o.index === s)) break;
|
|
5357
|
-
}
|
|
5358
|
-
return u >= e;
|
|
5359
|
-
})));
|
|
5360
|
-
}, tr = (r, e) => C(r, 0, 1), f = (r, e) => C(r, 0, 1 / 0), x = (r, e) => {
|
|
5361
|
-
let n = r.map(v);
|
|
5362
|
-
return g(_(M((a) => {
|
|
5363
|
-
for (let t = 0, o = n.length; t < o; t++) if (!n[t](a)) return !1;
|
|
5364
|
-
return !0;
|
|
5365
|
-
})));
|
|
5366
|
-
}, l = (r, e) => {
|
|
5367
|
-
let n = r.map(v);
|
|
5368
|
-
return g(_((a) => {
|
|
5369
|
-
for (let t = 0, o = n.length; t < o; t++) if (n[t](a)) return !0;
|
|
5370
|
-
return !1;
|
|
5371
|
-
}));
|
|
5372
|
-
}, M = (r, e = !1) => {
|
|
5373
|
-
let n = v(r);
|
|
5374
|
-
return (a) => {
|
|
5375
|
-
let t = a.index, o = a.output.length, u = n(a);
|
|
5376
|
-
return (!u || e) && (a.index = t, a.output.length !== o && (a.output.length = o)), u;
|
|
5377
|
-
};
|
|
5378
|
-
}, _ = (r, e) => v(r), g = /* @__PURE__ */ (() => {
|
|
5379
|
-
let r = 0;
|
|
5380
|
-
return (e) => {
|
|
5381
|
-
let n = v(e), a = r += 1;
|
|
5382
|
-
return (t) => {
|
|
5383
|
-
var o;
|
|
5384
|
-
if (t.options.memoization === !1) return n(t);
|
|
5385
|
-
let u = t.index, s = (o = t.cache)[a] || (o[a] = /* @__PURE__ */ new Map()), c = s.get(u);
|
|
5386
|
-
if (c === !1) return !1;
|
|
5387
|
-
if (W(c)) return t.index = c, !0;
|
|
5388
|
-
if (c) return t.index = c.index, c.output?.length && t.output.push(...c.output), !0;
|
|
5389
|
-
{
|
|
5390
|
-
let Z = t.output.length;
|
|
5391
|
-
if (n(t)) {
|
|
5392
|
-
let D = t.index, U = t.output.length;
|
|
5393
|
-
if (U > Z) {
|
|
5394
|
-
let ee = t.output.slice(Z, U);
|
|
5395
|
-
s.set(u, { index: D, output: ee });
|
|
5396
|
-
} else s.set(u, D);
|
|
5397
|
-
return !0;
|
|
5398
|
-
} else return s.set(u, !1), !1;
|
|
5399
|
-
}
|
|
5400
|
-
};
|
|
5401
|
-
};
|
|
5402
|
-
})(), E = (r) => {
|
|
5403
|
-
let e;
|
|
5404
|
-
return (n) => (e || (e = v(r())), e(n));
|
|
5405
|
-
}, v = Y((r) => {
|
|
5406
|
-
if (d(r)) return Q(r) ? E(r) : r;
|
|
5407
|
-
if (b(r) || X(r)) return i(r);
|
|
5408
|
-
if (A(r)) return x(r);
|
|
5409
|
-
if (K(r)) return l(Object.values(r));
|
|
5410
|
-
throw new Error("Invalid rule");
|
|
5411
|
-
}), P = "abcdefghijklmnopqrstuvwxyz", ir = (r) => {
|
|
5412
|
-
let e = "";
|
|
5413
|
-
for (; r > 0; ) {
|
|
5414
|
-
let n = (r - 1) % 26;
|
|
5415
|
-
e = P[n] + e, r = Math.floor((r - 1) / 26);
|
|
5416
|
-
}
|
|
5417
|
-
return e;
|
|
5418
|
-
}, O = (r) => {
|
|
5419
|
-
let e = 0;
|
|
5420
|
-
for (let n = 0, a = r.length; n < a; n++) e = e * 26 + P.indexOf(r[n]) + 1;
|
|
5421
|
-
return e;
|
|
5422
|
-
}, S = (r, e) => {
|
|
5423
|
-
if (e < r) return S(e, r);
|
|
5424
|
-
let n = [];
|
|
5425
|
-
for (; r <= e; ) n.push(r++);
|
|
5426
|
-
return n;
|
|
5427
|
-
}, or = (r, e, n) => S(r, e).map((a) => String(a).padStart(n, "0")), R = (r, e) => S(O(r), O(e)).map(ir), p = (r) => r, z = (r) => ur((e) => rr(e, r, { memoization: !1 }).join("")), ur = (r) => {
|
|
5428
|
-
let e = {};
|
|
5429
|
-
return (n) => e[n] ?? (e[n] = r(n));
|
|
5430
|
-
}, sr = i(/^\*\*\/\*$/, ".*"), cr = i(/^\*\*\/(\*)?([ a-zA-Z0-9._-]+)$/, (r, e, n) => `.*${e ? "" : "(?:^|/)"}${n.replaceAll(".", "\\.")}`), lr = i(/^\*\*\/(\*)?([ a-zA-Z0-9._-]*)\{([ a-zA-Z0-9._-]+(?:,[ a-zA-Z0-9._-]+)*)\}$/, (r, e, n, a) => `.*${e ? "" : "(?:^|/)"}${n.replaceAll(".", "\\.")}(?:${a.replaceAll(",", "|").replaceAll(".", "\\.")})`), y = i(/\\./, p), pr = i(/[$.*+?^(){}[\]\|]/, (r) => `\\${r}`), vr = i(/./, p), hr = i(/^(?:!!)*!(.*)$/, (r, e) => `(?!^${L(e)}$).*?`), dr = i(/^(!!)+/, ""), fr = l([hr, dr]), xr = i(/\/(\*\*\/)+/, "(?:/.+/|/)"), gr = i(/^(\*\*\/)+/, "(?:^|.*/)"), mr = i(/\/(\*\*)$/, "(?:/.*|$)"), _r = i(/\*\*/, ".*"), j = l([xr, gr, mr, _r]), Sr = i(/\*\/(?!\*\*\/)/, "[^/]*/"), yr = i(/\*/, "[^/]*"), N = l([Sr, yr]), k = i("?", "[^/]"), $r = i("[", p), wr = i("]", p), Ar = i(/[!^]/, "^/"), br = i(/[a-z]-[a-z]|[0-9]-[0-9]/i, p), Cr = i(/[$.*+?^(){}[\|]/, (r) => `\\${r}`), Mr = i(/[^\]]/, p), Er = l([y, Cr, br, Mr]), B = x([$r, tr(Ar), f(Er), wr]), Pr = i("{", "(?:"), Or = i("}", ")"), Rr = i(/(\d+)\.\.(\d+)/, (r, e, n) => or(+e, +n, Math.min(e.length, n.length)).join("|")), zr = i(/([a-z]+)\.\.([a-z]+)/, (r, e, n) => R(e, n).join("|")), jr = i(/([A-Z]+)\.\.([A-Z]+)/, (r, e, n) => R(e.toLowerCase(), n.toLowerCase()).join("|").toUpperCase()), Nr = l([Rr, zr, jr]), I = x([Pr, Nr, Or]), kr = i("{", "(?:"), Br = i("}", ")"), Ir = i(",", "|"), Fr = i(/[$.*+?^(){[\]\|]/, (r) => `\\${r}`), Lr = i(/[^}]/, p), Zr = E(() => F), Dr = l([j, N, k, B, I, Zr, y, Fr, Ir, Lr]), F = x([kr, f(Dr), Br]), Ur = f(l([sr, cr, lr, fr, j, N, k, B, I, F, y, pr, vr])), Vr = Ur, Gr = z(Vr), L = Gr, Tr = i(/\\./, p), qr = i(/./, p), Hr = i(/\*\*\*+/, "*"), Jr = i(/([^/{[(!])\*\*/, (r, e) => `${e}*`), Qr = i(/(^|.)\*\*(?=[^*/)\]}])/, (r, e) => `${e}*`), Wr = f(l([Tr, Hr, Jr, Qr, qr])), Kr = Wr, Xr = z(Kr), Yr = Xr, $ = (r, e) => {
|
|
5431
|
-
let n = Array.isArray(r) ? r : [r];
|
|
5432
|
-
if (!n.length) return !1;
|
|
5433
|
-
let a = n.map($.compile), t = n.every((s) => /(\/(?:\*\*)?|\[\/\])$/.test(s)), o = e.replace(/[\\\/]+/g, "/").replace(/\/$/, t ? "/" : "");
|
|
5434
|
-
return a.some((s) => s.test(o));
|
|
5435
|
-
};
|
|
5436
|
-
$.compile = (r) => new RegExp(`^${L(Yr(r))}$`, "s");
|
|
5437
|
-
var re = $;
|
|
5438
|
-
return J(w);
|
|
5439
|
-
})();
|
|
5440
|
-
return __lib__.default || __lib__;
|
|
5441
|
-
}, _match, zeptomatch = (path2, pattern) => (_match || (_match = _lazyMatch(), _lazyMatch = null), _match(path2, pattern)), _DRIVE_LETTER_START_RE2 = /^[A-Za-z]:\//;
|
|
5442
|
-
function normalizeWindowsPath2(input = "") {
|
|
5443
|
-
return input && input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE2, (r) => r.toUpperCase());
|
|
5444
|
-
}
|
|
5445
|
-
var _UNC_REGEX2 = /^[/\\]{2}/, _IS_ABSOLUTE_RE2 = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/, _DRIVE_LETTER_RE2 = /^[A-Za-z]:$/, _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/, _EXTNAME_RE = /.(\.[^./]+|\.)$/, _PATH_ROOT_RE = /^[/\\]|^[a-zA-Z]:[/\\]/, sep = "/", normalize2 = function(path2) {
|
|
5446
|
-
if (path2.length === 0)
|
|
5447
|
-
return ".";
|
|
5448
|
-
path2 = normalizeWindowsPath2(path2);
|
|
5449
|
-
let isUNCPath = path2.match(_UNC_REGEX2), isPathAbsolute = isAbsolute2(path2), trailingSeparator = path2[path2.length - 1] === "/";
|
|
5450
|
-
return path2 = normalizeString2(path2, !isPathAbsolute), path2.length === 0 ? isPathAbsolute ? "/" : trailingSeparator ? "./" : "." : (trailingSeparator && (path2 += "/"), _DRIVE_LETTER_RE2.test(path2) && (path2 += "/"), isUNCPath ? isPathAbsolute ? `//${path2}` : `//./${path2}` : isPathAbsolute && !isAbsolute2(path2) ? `/${path2}` : path2);
|
|
5451
|
-
}, join2 = function(...segments) {
|
|
5452
|
-
let path2 = "";
|
|
5453
|
-
for (let seg of segments)
|
|
5454
|
-
if (seg)
|
|
5455
|
-
if (path2.length > 0) {
|
|
5456
|
-
let pathTrailing = path2[path2.length - 1] === "/", segLeading = seg[0] === "/";
|
|
5457
|
-
pathTrailing && segLeading ? path2 += seg.slice(1) : path2 += pathTrailing || segLeading ? seg : `/${seg}`;
|
|
5458
|
-
} else
|
|
5459
|
-
path2 += seg;
|
|
5460
|
-
return normalize2(path2);
|
|
5461
|
-
};
|
|
5462
|
-
function cwd() {
|
|
5463
|
-
return typeof process < "u" && typeof process.cwd == "function" ? process.cwd().replace(/\\/g, "/") : "/";
|
|
5464
|
-
}
|
|
5465
|
-
var resolve = function(...arguments_) {
|
|
5466
|
-
arguments_ = arguments_.map((argument) => normalizeWindowsPath2(argument));
|
|
5467
|
-
let resolvedPath = "", resolvedAbsolute = !1;
|
|
5468
|
-
for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
|
|
5469
|
-
let path2 = index >= 0 ? arguments_[index] : cwd();
|
|
5470
|
-
!path2 || path2.length === 0 || (resolvedPath = `${path2}/${resolvedPath}`, resolvedAbsolute = isAbsolute2(path2));
|
|
5471
|
-
}
|
|
5472
|
-
return resolvedPath = normalizeString2(resolvedPath, !resolvedAbsolute), resolvedAbsolute && !isAbsolute2(resolvedPath) ? `/${resolvedPath}` : resolvedPath.length > 0 ? resolvedPath : ".";
|
|
5473
|
-
};
|
|
5474
|
-
function normalizeString2(path2, allowAboveRoot) {
|
|
5475
|
-
let res = "", lastSegmentLength = 0, lastSlash = -1, dots = 0, char = null;
|
|
5476
|
-
for (let index = 0; index <= path2.length; ++index) {
|
|
5477
|
-
if (index < path2.length)
|
|
5478
|
-
char = path2[index];
|
|
5479
|
-
else {
|
|
5480
|
-
if (char === "/")
|
|
5481
|
-
break;
|
|
5482
|
-
char = "/";
|
|
5483
|
-
}
|
|
5484
|
-
if (char === "/") {
|
|
5485
|
-
if (!(lastSlash === index - 1 || dots === 1)) if (dots === 2) {
|
|
5486
|
-
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
5487
|
-
if (res.length > 2) {
|
|
5488
|
-
let lastSlashIndex = res.lastIndexOf("/");
|
|
5489
|
-
lastSlashIndex === -1 ? (res = "", lastSegmentLength = 0) : (res = res.slice(0, lastSlashIndex), lastSegmentLength = res.length - 1 - res.lastIndexOf("/")), lastSlash = index, dots = 0;
|
|
5490
|
-
continue;
|
|
5491
|
-
} else if (res.length > 0) {
|
|
5492
|
-
res = "", lastSegmentLength = 0, lastSlash = index, dots = 0;
|
|
5493
|
-
continue;
|
|
5494
|
-
}
|
|
5495
|
-
}
|
|
5496
|
-
allowAboveRoot && (res += res.length > 0 ? "/.." : "..", lastSegmentLength = 2);
|
|
5497
|
-
} else
|
|
5498
|
-
res.length > 0 ? res += `/${path2.slice(lastSlash + 1, index)}` : res = path2.slice(lastSlash + 1, index), lastSegmentLength = index - lastSlash - 1;
|
|
5499
|
-
lastSlash = index, dots = 0;
|
|
5500
|
-
} else char === "." && dots !== -1 ? ++dots : dots = -1;
|
|
5501
|
-
}
|
|
5502
|
-
return res;
|
|
5503
|
-
}
|
|
5504
|
-
var isAbsolute2 = function(p) {
|
|
5505
|
-
return _IS_ABSOLUTE_RE2.test(p);
|
|
5506
|
-
}, toNamespacedPath = function(p) {
|
|
5507
|
-
return normalizeWindowsPath2(p);
|
|
5508
|
-
}, extname = function(p) {
|
|
5509
|
-
if (p === "..") return "";
|
|
5510
|
-
let match = _EXTNAME_RE.exec(normalizeWindowsPath2(p));
|
|
5511
|
-
return match && match[1] || "";
|
|
5512
|
-
}, relative = function(from, to) {
|
|
5513
|
-
let _from = resolve(from).replace(_ROOT_FOLDER_RE, "$1").split("/"), _to = resolve(to).replace(_ROOT_FOLDER_RE, "$1").split("/");
|
|
5514
|
-
if (_to[0][1] === ":" && _from[0][1] === ":" && _from[0] !== _to[0])
|
|
5515
|
-
return _to.join("/");
|
|
5516
|
-
let _fromCopy = [..._from];
|
|
5517
|
-
for (let segment of _fromCopy) {
|
|
5518
|
-
if (_to[0] !== segment)
|
|
5519
|
-
break;
|
|
5520
|
-
_from.shift(), _to.shift();
|
|
5521
|
-
}
|
|
5522
|
-
return [..._from.map(() => ".."), ..._to].join("/");
|
|
5523
|
-
}, dirname3 = function(p) {
|
|
5524
|
-
let segments = normalizeWindowsPath2(p).replace(/\/$/, "").split("/").slice(0, -1);
|
|
5525
|
-
return segments.length === 1 && _DRIVE_LETTER_RE2.test(segments[0]) && (segments[0] += "/"), segments.join("/") || (isAbsolute2(p) ? "/" : ".");
|
|
5526
|
-
}, format = function(p) {
|
|
5527
|
-
let ext = p.ext ? p.ext.startsWith(".") ? p.ext : `.${p.ext}` : "", segments = [p.root, p.dir, p.base ?? (p.name ?? "") + ext].filter(
|
|
5528
|
-
Boolean
|
|
5529
|
-
);
|
|
5530
|
-
return normalizeWindowsPath2(
|
|
5531
|
-
p.root ? resolve(...segments) : segments.join("/")
|
|
5532
|
-
);
|
|
5533
|
-
}, basename = function(p, extension) {
|
|
5534
|
-
let segments = normalizeWindowsPath2(p).split("/"), lastSegment = "";
|
|
5535
|
-
for (let i = segments.length - 1; i >= 0; i--) {
|
|
5536
|
-
let val = segments[i];
|
|
5537
|
-
if (val) {
|
|
5538
|
-
lastSegment = val;
|
|
5539
|
-
break;
|
|
5540
|
-
}
|
|
5541
|
-
}
|
|
5542
|
-
return extension && lastSegment.endsWith(extension) ? lastSegment.slice(0, -extension.length) : lastSegment;
|
|
5543
|
-
}, parse = function(p) {
|
|
5544
|
-
let root = _PATH_ROOT_RE.exec(p)?.[0]?.replace(/\\/g, "/") || "", base = basename(p), extension = extname(base);
|
|
5545
|
-
return {
|
|
5546
|
-
root,
|
|
5547
|
-
dir: dirname3(p),
|
|
5548
|
-
base,
|
|
5549
|
-
ext: extension,
|
|
5550
|
-
name: base.slice(0, base.length - extension.length)
|
|
5551
|
-
};
|
|
5552
|
-
}, matchesGlob = (path2, pattern) => zeptomatch(pattern, normalize2(path2)), _path = {
|
|
5553
|
-
__proto__: null,
|
|
5554
|
-
basename,
|
|
5555
|
-
dirname: dirname3,
|
|
5556
|
-
extname,
|
|
5557
|
-
format,
|
|
5558
|
-
isAbsolute: isAbsolute2,
|
|
5559
|
-
join: join2,
|
|
5560
|
-
matchesGlob,
|
|
5561
|
-
normalize: normalize2,
|
|
5562
|
-
normalizeString: normalizeString2,
|
|
5563
|
-
parse,
|
|
5564
|
-
relative,
|
|
5565
|
-
resolve,
|
|
5566
|
-
sep,
|
|
5567
|
-
toNamespacedPath
|
|
5568
|
-
};
|
|
5569
|
-
|
|
5570
|
-
// ../../../node_modules/pathe/dist/index.mjs
|
|
5571
|
-
var delimiter = globalThis.process?.platform === "win32" ? ";" : ":", _platforms = { posix: void 0, win32: void 0 }, mix = (del = delimiter) => new Proxy(_path, {
|
|
5572
|
-
get(_, prop) {
|
|
5573
|
-
return prop === "delimiter" ? del : prop === "posix" ? posix : prop === "win32" ? win32 : _platforms[prop] || _path[prop];
|
|
5574
|
-
}
|
|
5575
|
-
}), posix = /* @__PURE__ */ mix(":"), win32 = /* @__PURE__ */ mix(";");
|
|
5576
|
-
|
|
5577
5282
|
// src/componentManifest/generateCodeSnippet.ts
|
|
5578
5283
|
import {
|
|
5579
5284
|
textOf,
|
|
@@ -5592,13 +5297,17 @@ import {
|
|
|
5592
5297
|
walk
|
|
5593
5298
|
} from "storybook/internal/csf-tools";
|
|
5594
5299
|
import {
|
|
5300
|
+
SNIPPET_INDENT,
|
|
5595
5301
|
createHoleMarks,
|
|
5302
|
+
fitsOnLine,
|
|
5303
|
+
layOutWrittenTag,
|
|
5304
|
+
printOpeningTag,
|
|
5596
5305
|
stripHoles,
|
|
5597
5306
|
withHoleSpace
|
|
5598
5307
|
} from "storybook/internal/docs-tools";
|
|
5599
5308
|
|
|
5600
5309
|
// src/snippet-values.ts
|
|
5601
|
-
var unmarked = (_, text) => text, isAttributeName = (name) => /^[A-Za-z_][A-Za-z0-9_:-]*$/.test(name), isAttributeText = (text) => !/["&\r\n]/.test(text), isChildText = (text) => !/[{}<>&\r\n]
|
|
5310
|
+
var unmarked = (_, text) => text, isAttributeName = (name) => /^[A-Za-z_][A-Za-z0-9_:-]*$/.test(name), isAttributeText = (text) => !/["&\r\n]/.test(text), isChildText = (text) => !/[{}<>&\r\n]|^\s|\s$/.test(text), valueCode = (value) => value.kind === "boolean" ? String(value.value) : value.code, printAttribute = (name, value) => value.kind === "boolean" ? value.value ? name : `${name}={false}` : value.kind === "string" && isAttributeText(value.value) ? `${name}="${value.value}"` : `${name}={${value.code}}`, printAttributes = (args, mark = unmarked) => {
|
|
5602
5311
|
let unnamed = args.filter(([name]) => !isAttributeName(name)), attributes = args.filter(([name]) => isAttributeName(name)).map(([name, value]) => mark({ kind: "attr", arg: name }, printAttribute(name, value)));
|
|
5603
5312
|
if (unnamed.length !== 0) {
|
|
5604
5313
|
let members = unnamed.map(
|
|
@@ -5614,7 +5323,7 @@ function renderFunctionOf(resolution) {
|
|
|
5614
5323
|
return resolution.kind === "resolved" ? resolution.node : resolution.kind === "unresolved" ? resolution.shadowedRender : void 0;
|
|
5615
5324
|
}
|
|
5616
5325
|
function getCodeSnippet(csf, storyName, componentName, resolver = createStoryArgsResolver(csf)) {
|
|
5617
|
-
let { args, imports, unresolved } = resolver.resolve(storyName), importedBind = importedBoundStory(csf, storyName, args), sources = [csf.editor.code, ...Object.values(args).map(detachedTextOf)], marks = createHoleMarks(sources, (mark) => `/*${mark}*/`), marked = importedBind ? importedBind.print(marks.mark) : buildSnippet(csf, storyName, componentName, args, resolver, marks.mark), holes = marks.toTemplate(marked);
|
|
5326
|
+
let { args, imports, unresolved } = resolver.resolve(storyName), importedBind = importedBoundStory(csf, storyName, args), sources = [csf.editor.code, ...Object.values(args).map(detachedTextOf)], marks = createHoleMarks(sources, (mark) => `/*${mark}*/`), marked = importedBind ? importedBind.print(marks.mark) : buildSnippet(csf, storyName, componentName, args, resolver, marks.mark, marks.unmark), holes = marks.toTemplate(marked);
|
|
5618
5327
|
invariant(holes, "A place an arg prints was printed inside another.");
|
|
5619
5328
|
let template = withHoleSpace(
|
|
5620
5329
|
holes,
|
|
@@ -5655,7 +5364,7 @@ function importedBoundStory(csf, storyName, args) {
|
|
|
5655
5364
|
}
|
|
5656
5365
|
};
|
|
5657
5366
|
}
|
|
5658
|
-
function buildSnippet(csf, storyName, componentName, merged, resolver, mark) {
|
|
5367
|
+
function buildSnippet(csf, storyName, componentName, merged, resolver, mark, measure) {
|
|
5659
5368
|
let editor = csf.editor, storyDeclaration = csf._storyExports[storyName];
|
|
5660
5369
|
if (!storyDeclaration) {
|
|
5661
5370
|
let message = "Expected story to be a function or variable declaration", statement = csf.program.body.find(
|
|
@@ -5666,31 +5375,55 @@ function buildSnippet(csf, storyName, componentName, merged, resolver, mark) {
|
|
|
5666
5375
|
throw statement ? storyShapeError(message, statement, editor) : message;
|
|
5667
5376
|
}
|
|
5668
5377
|
let normalizedStory = normalizeStoryDeclaration(storyDeclaration, editor), storyFn = normalizedStory.type === "fn" ? normalizedStory.node : void 0, storyConfig = normalizedStory.type === "config" ? normalizedStory.node : void 0, metaRender = resolveRenderFunction(metaObject(csf), editor, resolver.ctx), storyRender = resolveRenderFunction(storyConfig, editor, resolver.ctx);
|
|
5669
|
-
|
|
5670
|
-
|
|
5671
|
-
|
|
5672
|
-
|
|
5673
|
-
|
|
5674
|
-
|
|
5675
|
-
|
|
5676
|
-
|
|
5677
|
-
|
|
5678
|
-
|
|
5679
|
-
|
|
5680
|
-
|
|
5378
|
+
return storyFn || (storyFn = renderFunctionOf(storyRender) ?? (storyRender.kind === "missing" ? renderFunctionOf(metaRender) : void 0)), storyFn ? functionSnippet(
|
|
5379
|
+
editor.code,
|
|
5380
|
+
storyName,
|
|
5381
|
+
storyFn,
|
|
5382
|
+
isMethod(editor.parentOf(storyFn)),
|
|
5383
|
+
merged,
|
|
5384
|
+
mark,
|
|
5385
|
+
measure
|
|
5386
|
+
) : (invariant(componentName, "Could not generate snippet without component name."), synthesizedSnippet(storyName, componentName, merged, mark, measure));
|
|
5387
|
+
}
|
|
5388
|
+
function synthesizedSnippet(storyName, componentName, merged, mark, measure) {
|
|
5389
|
+
let declaration = `const ${storyName} = () => `, contentIndent = `${SNIPPET_INDENT}${SNIPPET_INDENT}`, print = valuePrinter(contentIndent), tag = {
|
|
5390
|
+
open: `<${componentName}`,
|
|
5391
|
+
attributes: [
|
|
5392
|
+
...injectedAttributes(merged, /* @__PURE__ */ new Set(), print, mark),
|
|
5393
|
+
(separator) => addedAttributes(
|
|
5394
|
+
injectedNames(merged, /* @__PURE__ */ new Set()),
|
|
5395
|
+
!!merged.children,
|
|
5396
|
+
mark,
|
|
5397
|
+
separator
|
|
5398
|
+
)
|
|
5399
|
+
],
|
|
5400
|
+
close: merged.children ? ">" : "/>"
|
|
5401
|
+
}, closing = `</${componentName}>`, content = merged.children ? childrenHole(merged.children, print, mark) : "", inline = `${printOpeningTag(tag, { broken: !1 }).text}${merged.children ? `${content}${closing}` : ""}`;
|
|
5402
|
+
if (fitsOnLine(measure(`${declaration}${inline};`)))
|
|
5403
|
+
return `${declaration}${inline};`;
|
|
5404
|
+
let opening = printOpeningTag(tag, { indent: SNIPPET_INDENT, measure }).text, line = `
|
|
5405
|
+
${contentIndent}`, children = merged.children ? `${childrenHole(merged.children, print, mark, { written: line, space: line })}
|
|
5406
|
+
${SNIPPET_INDENT}${closing}` : "";
|
|
5407
|
+
return `${declaration}(
|
|
5408
|
+
${SNIPPET_INDENT}${opening}${children}
|
|
5409
|
+
);`;
|
|
5681
5410
|
}
|
|
5682
5411
|
var isMethod = (parent) => parent?.type === "Property" && (parent.method || parent.kind !== "init");
|
|
5683
|
-
function functionSnippet(code, storyName, fn, method, merged, mark) {
|
|
5684
|
-
let asyncPrefix = fn.async ? "async " : "", params = fn.params.length ? code.slice(fn.params[0].start, fn.params[fn.params.length - 1].end) : "", edits = []
|
|
5412
|
+
function functionSnippet(code, storyName, fn, method, merged, mark, measure) {
|
|
5413
|
+
let asyncPrefix = fn.async ? "async " : "", params = fn.params.length ? code.slice(fn.params[0].start, fn.params[fn.params.length - 1].end) : "", edits = [], bodyStart = fn.body?.start ?? fn.start, layout = {
|
|
5414
|
+
measure,
|
|
5415
|
+
base: lineIndent(code, bodyStart),
|
|
5416
|
+
first: { start: bodyStart, prefix: `const ${storyName} = () => ` }
|
|
5417
|
+
};
|
|
5685
5418
|
if (fn.type === "ArrowFunctionExpression" && isJsx(fn.body)) {
|
|
5686
|
-
if (rewriteJsx(code, fn.body, merged, edits, mark)) {
|
|
5419
|
+
if (rewriteJsx(code, fn.body, merged, edits, mark, layout)) {
|
|
5687
5420
|
let body = printRange(code, fn.body, edits), kept = readsArgs(`${asyncPrefix}() => (${body});`) ? params : "";
|
|
5688
5421
|
return `const ${storyName} = ${asyncPrefix}(${kept}) => ${body};`;
|
|
5689
5422
|
}
|
|
5690
5423
|
} else if (fn.body?.type === "BlockStatement") {
|
|
5691
5424
|
let changed = !1;
|
|
5692
5425
|
for (let statement of fn.body.body)
|
|
5693
|
-
statement.type === "ReturnStatement" && isJsx(statement.argument) && (changed = rewriteJsx(code, statement.argument, merged, edits, mark) || changed);
|
|
5426
|
+
statement.type === "ReturnStatement" && isJsx(statement.argument) && (changed = rewriteJsx(code, statement.argument, merged, edits, mark, layout) || changed);
|
|
5694
5427
|
if (changed) {
|
|
5695
5428
|
let body = printRange(code, fn.body, edits), head = `${asyncPrefix}function${fn.generator ? "*" : ""}`, kept = readsArgs(`${head} f() ${body}`) ? params : "";
|
|
5696
5429
|
return fn.type === "FunctionDeclaration" ? `${asyncPrefix}function${fn.generator ? "*" : ""} ${storyName}(${kept}) ${body}` : `const ${storyName} = ${asyncPrefix}(${kept}) => ${body};`;
|
|
@@ -5714,30 +5447,79 @@ function readsArgs(source) {
|
|
|
5714
5447
|
var valuePrinter = (indent) => (node) => reindent(detachedTextOf(node), "", indent), toJsxValue = (node, print) => node.type === "Literal" && typeof node.value == "boolean" ? { kind: "boolean", value: node.value } : isStringLiteral(node) ? { kind: "string", value: node.value, code: print(node) } : { kind: isJsx(node) ? "jsx" : "code", code: print(node) }, toAttr = (key, value, print) => printAttribute(key, toJsxValue(value, print)), injectedArgs = (merged, existing) => Object.entries(merged).filter(([k, v]) => v != null && k !== "children" && !existing.has(k)), injectedNames = (merged, existing) => injectedArgs(merged, existing).map(([k]) => k), injectedAttributes = (merged, existing, print, mark) => printAttributes(
|
|
5715
5448
|
injectedArgs(merged, existing).map(([k, v]) => [k, toJsxValue(v, print)]),
|
|
5716
5449
|
mark
|
|
5717
|
-
), addedAttributes = (printed, hasContent, mark) => mark(
|
|
5718
|
-
{
|
|
5719
|
-
|
|
5720
|
-
|
|
5450
|
+
), addedAttributes = (printed, hasContent, mark, separator) => mark(
|
|
5451
|
+
{
|
|
5452
|
+
kind: "attrs",
|
|
5453
|
+
spread: !0,
|
|
5454
|
+
except: hasContent ? [...printed, "children"] : printed,
|
|
5455
|
+
separator
|
|
5456
|
+
},
|
|
5457
|
+
"",
|
|
5458
|
+
separator
|
|
5459
|
+
), childrenHole = (node, print, mark, { written, space } = { written: "", space: "" }) => mark({ kind: "text", arg: "children" }, `${written}${toJsxChildren(node, print)}`, space), toJsxChildren = (node, print) => node ? printChildren(toJsxValue(node, print)) : "";
|
|
5460
|
+
function layOutOpening(code, opening, spread, own, { measure, base, first }) {
|
|
5461
|
+
let close = opening.selfClosing ? "/>" : ">", closeStart = opening.end - close.length, nameEnd = (opening.typeArguments ?? opening.name).end, indent = lineIndent(code, opening.start), attributes = opening.attributes.flatMap((attribute, index) => {
|
|
5462
|
+
if (index === spread.index)
|
|
5463
|
+
return [
|
|
5464
|
+
...spread.attributes(`${indent}${SNIPPET_INDENT}`),
|
|
5465
|
+
(separator) => spread.added(
|
|
5466
|
+
separator.startsWith(`
|
|
5467
|
+
`) ? `
|
|
5468
|
+
${indent.slice(base.length)}${SNIPPET_INDENT}` : separator
|
|
5469
|
+
)
|
|
5470
|
+
];
|
|
5471
|
+
let removed = own.some(
|
|
5472
|
+
(edit) => edit.text === "" && edit.start < attribute.start && edit.end >= attribute.end
|
|
5473
|
+
), text2 = own.filter((edit) => edit.start >= attribute.start && edit.end <= attribute.end).sort((a, b) => b.start - a.start).reduce(
|
|
5474
|
+
(printed, edit) => printed.slice(0, edit.start - attribute.start) + edit.text + printed.slice(edit.end - attribute.start),
|
|
5475
|
+
code.slice(attribute.start, attribute.end)
|
|
5476
|
+
);
|
|
5477
|
+
return removed || text2 === "" ? [] : [text2];
|
|
5478
|
+
}), onFirstLine = code.lastIndexOf(`
|
|
5479
|
+
`, opening.start - 1) + 1 <= first.start, text = layOutWrittenTag(
|
|
5480
|
+
code,
|
|
5481
|
+
{ start: opening.start, nameEnd, closeStart, close },
|
|
5482
|
+
attributes,
|
|
5483
|
+
{
|
|
5484
|
+
measure,
|
|
5485
|
+
before: (written) => onFirstLine ? `${first.prefix}${code.slice(first.start, opening.start)}` : written.slice(base.length)
|
|
5486
|
+
}
|
|
5487
|
+
);
|
|
5488
|
+
return text === void 0 ? { edits: own } : {
|
|
5489
|
+
edits: [
|
|
5490
|
+
...own.filter((edit) => edit.start < nameEnd || edit.end > closeStart),
|
|
5491
|
+
{ start: nameEnd, end: closeStart, text }
|
|
5492
|
+
],
|
|
5493
|
+
broken: { indent, closeStart }
|
|
5494
|
+
};
|
|
5495
|
+
}
|
|
5721
5496
|
function getArgsMemberKey(expr) {
|
|
5722
5497
|
let member = expr.type === "ChainExpression" ? expr.expression : expr;
|
|
5723
5498
|
return member.type !== "MemberExpression" || member.object.type !== "Identifier" || member.object.name !== "args" ? null : member.property.type === "Identifier" && !member.computed ? member.property.name : isStringLiteral(member.property) && member.computed ? member.property.value : null;
|
|
5724
5499
|
}
|
|
5725
|
-
function rewriteJsx(code, node, merged, edits, mark) {
|
|
5500
|
+
function rewriteJsx(code, node, merged, edits, mark, layout) {
|
|
5726
5501
|
let changed = !1, printAt = (offset) => valuePrinter(lineIndent(code, offset));
|
|
5727
5502
|
if (node.type === "JSXElement") {
|
|
5728
|
-
let opening = node.openingElement, attrs = opening.attributes, isArgsSpread = (a) => a.type === "JSXSpreadAttribute" && a.argument.type === "Identifier" && a.argument.name === "args", firstSpread = attrs.findIndex(isArgsSpread), tagEnd = (opening.typeArguments ?? opening.name).end;
|
|
5503
|
+
let opening = node.openingElement, attrs = opening.attributes, isArgsSpread = (a) => a.type === "JSXSpreadAttribute" && a.argument.type === "Identifier" && a.argument.name === "args", firstSpread = attrs.findIndex(isArgsSpread), tagEnd = (opening.typeArguments ?? opening.name).end, elementEdits = edits.length, spread;
|
|
5729
5504
|
if (firstSpread !== -1) {
|
|
5730
5505
|
changed = !0;
|
|
5731
5506
|
let existing = new Set(
|
|
5732
5507
|
attrs.flatMap(
|
|
5733
5508
|
(a) => a.type === "JSXAttribute" && a.name.type === "JSXIdentifier" ? [a.name.name] : []
|
|
5734
5509
|
)
|
|
5735
|
-
),
|
|
5736
|
-
|
|
5737
|
-
|
|
5738
|
-
mark
|
|
5739
|
-
|
|
5740
|
-
|
|
5510
|
+
), injected = injectedNames(merged, existing);
|
|
5511
|
+
spread = {
|
|
5512
|
+
index: firstSpread,
|
|
5513
|
+
attributes: (indent) => injectedAttributes(merged, existing, valuePrinter(indent), mark),
|
|
5514
|
+
added: (separator) => addedAttributes(
|
|
5515
|
+
[...existing, ...injected],
|
|
5516
|
+
!!merged.children || node.children.length > 0,
|
|
5517
|
+
mark,
|
|
5518
|
+
separator
|
|
5519
|
+
)
|
|
5520
|
+
};
|
|
5521
|
+
let pieces = spread.attributes(lineIndent(code, attrs[firstSpread].start)).join(" ") + spread.added(" ");
|
|
5522
|
+
attrs.forEach((a, index) => {
|
|
5741
5523
|
if (isArgsSpread(a))
|
|
5742
5524
|
if (index === firstSpread && injected.length > 0)
|
|
5743
5525
|
edits.push({ start: a.start, end: a.end, text: pieces });
|
|
@@ -5745,17 +5527,10 @@ function rewriteJsx(code, node, merged, edits, mark) {
|
|
|
5745
5527
|
let start = index > 0 ? attrs[index - 1].end : tagEnd;
|
|
5746
5528
|
edits.push({ start, end: a.end, text: index === firstSpread ? pieces : "" });
|
|
5747
5529
|
}
|
|
5748
|
-
})
|
|
5749
|
-
let name = code.slice(opening.name.start, opening.name.end), children = childrenHole(merged.children, printAt(opening.start), mark);
|
|
5750
|
-
if (opening.selfClosing) {
|
|
5751
|
-
let start = attrs.length > 0 ? attrs[attrs.length - 1].end : tagEnd;
|
|
5752
|
-
edits.push({ start, end: opening.end, text: `>${children}</${name}>` });
|
|
5753
|
-
} else
|
|
5754
|
-
edits.push({ start: opening.end, end: opening.end, text: children });
|
|
5755
|
-
}
|
|
5530
|
+
});
|
|
5756
5531
|
}
|
|
5757
5532
|
let lastSpread = attrs.findLastIndex(isArgsSpread);
|
|
5758
|
-
attrs.forEach((a, index) => {
|
|
5533
|
+
if (attrs.forEach((a, index) => {
|
|
5759
5534
|
if (a.type !== "JSXAttribute" || a.name.type !== "JSXIdentifier")
|
|
5760
5535
|
return;
|
|
5761
5536
|
let name = a.name.name, key = a.value?.type === "JSXExpressionContainer" ? getArgsMemberKey(a.value.expression) : null, arg = index < lastSpread ? name : key;
|
|
@@ -5767,11 +5542,31 @@ function rewriteJsx(code, node, merged, edits, mark) {
|
|
|
5767
5542
|
end: a.end,
|
|
5768
5543
|
text: mark({ kind: "attr", arg, ...arg !== name && { name } }, text)
|
|
5769
5544
|
}), changed ||= set;
|
|
5770
|
-
})
|
|
5545
|
+
}), spread) {
|
|
5546
|
+
let { edits: laidOut, broken } = layOutOpening(
|
|
5547
|
+
code,
|
|
5548
|
+
opening,
|
|
5549
|
+
spread,
|
|
5550
|
+
edits.splice(elementEdits),
|
|
5551
|
+
layout
|
|
5552
|
+
);
|
|
5553
|
+
if (edits.push(...laidOut), node.children.length === 0 && merged.children) {
|
|
5554
|
+
let name = code.slice(opening.name.start, opening.name.end), inner = broken && `${broken.indent}${SNIPPET_INDENT}`, children = inner ? `${childrenHole(merged.children, valuePrinter(inner), mark, {
|
|
5555
|
+
written: `
|
|
5556
|
+
${inner}`,
|
|
5557
|
+
space: `
|
|
5558
|
+
${inner.slice(layout.base.length)}`
|
|
5559
|
+
})}
|
|
5560
|
+
${broken.indent}` : childrenHole(merged.children, printAt(opening.start), mark), start = broken ? broken.closeStart : attrs.length > 0 ? attrs[attrs.length - 1].end : tagEnd;
|
|
5561
|
+
edits.push(
|
|
5562
|
+
opening.selfClosing ? { start, end: opening.end, text: `>${children}</${name}>` } : { start: opening.end, end: opening.end, text: children }
|
|
5563
|
+
);
|
|
5564
|
+
}
|
|
5565
|
+
}
|
|
5771
5566
|
}
|
|
5772
5567
|
for (let child of node.children)
|
|
5773
5568
|
if (isJsx(child))
|
|
5774
|
-
changed = rewriteJsx(code, child, merged, edits, mark) || changed;
|
|
5569
|
+
changed = rewriteJsx(code, child, merged, edits, mark, layout) || changed;
|
|
5775
5570
|
else if (child.type === "JSXExpressionContainer") {
|
|
5776
5571
|
let key = getArgsMemberKey(child.expression);
|
|
5777
5572
|
if (key === null)
|
|
@@ -5787,11 +5582,7 @@ function rewriteJsx(code, node, merged, edits, mark) {
|
|
|
5787
5582
|
}
|
|
5788
5583
|
|
|
5789
5584
|
// src/componentManifest/reactDocgenTypescript.ts
|
|
5790
|
-
import { dirname as
|
|
5791
|
-
import {
|
|
5792
|
-
extractComponentJsDocInfo as extractComponentJsDocInfo2,
|
|
5793
|
-
resolveExportedSymbol
|
|
5794
|
-
} from "storybook/internal/component-meta";
|
|
5585
|
+
import { dirname as dirname3, join as join2, resolve } from "node:path";
|
|
5795
5586
|
import { logger as logger4 } from "storybook/internal/node-logger";
|
|
5796
5587
|
var typeScriptPromise, reactDocgenTypescriptPromise, loadTypeScript = () => typeScriptPromise ??= import("typescript").then((ts) => ts.default ?? ts), loadReactDocgenTypescript = () => reactDocgenTypescriptPromise ??= import("react-docgen-typescript"), LARGE_NON_USER_SOURCE_THRESHOLD = 30, getPropSource = (prop) => prop.parent?.fileName ?? prop.declarations?.[0]?.fileName, getLargeNonUserPropSources = (props) => {
|
|
5797
5588
|
let countBySource = /* @__PURE__ */ new Map();
|
|
@@ -5901,17 +5692,18 @@ function getReactDocgenTypescriptError(path2, {
|
|
|
5901
5692
|
localImportName,
|
|
5902
5693
|
componentName
|
|
5903
5694
|
}, docs) {
|
|
5695
|
+
let file = `File: ${relative(process.cwd(), path2)}`;
|
|
5904
5696
|
return docs.length === 0 ? {
|
|
5905
5697
|
name: "react-docgen-typescript found no component docs",
|
|
5906
5698
|
message: [
|
|
5907
|
-
|
|
5699
|
+
file,
|
|
5908
5700
|
"react-docgen-typescript did not return any component docs for this file."
|
|
5909
5701
|
].join(`
|
|
5910
5702
|
`)
|
|
5911
5703
|
} : {
|
|
5912
5704
|
name: "react-docgen-typescript could not match component docs",
|
|
5913
5705
|
message: [
|
|
5914
|
-
|
|
5706
|
+
file,
|
|
5915
5707
|
"react-docgen-typescript returned component docs for this file, but none matched the story's component import.",
|
|
5916
5708
|
`Looked for: componentName=${componentName}, localImportName=${localImportName ?? "<none>"}, importName=${importName ?? "<none>"}.`
|
|
5917
5709
|
].join(`
|
|
@@ -5922,11 +5714,10 @@ var parseWithReactDocgenTypescript = asyncCache(
|
|
|
5922
5714
|
async (filePath, userOptions) => {
|
|
5923
5715
|
let { program, fileParser, typescript } = await getParser(filePath, userOptions), checker = program.getTypeChecker(), sourceFile = program.getSourceFile(filePath), docs = fileParser.parseWithProgramProvider(filePath, () => program), exportNameMap = sourceFile ? getExportNameMap(typescript, checker, sourceFile) : /* @__PURE__ */ new Map();
|
|
5924
5716
|
return docs.map((doc) => {
|
|
5925
|
-
let largeNonUserSources = getLargeNonUserPropSources(doc.props), exportName = exportNameMap.get(doc.displayName) ?? doc.displayName
|
|
5717
|
+
let largeNonUserSources = getLargeNonUserPropSources(doc.props), exportName = exportNameMap.get(doc.displayName) ?? doc.displayName;
|
|
5926
5718
|
return {
|
|
5927
5719
|
...doc,
|
|
5928
5720
|
exportName,
|
|
5929
|
-
componentJsDocTags,
|
|
5930
5721
|
// Filter out bulk props from non-user sources (React built-ins, DOM, CSS-in-JS system props)
|
|
5931
5722
|
props: Object.fromEntries(
|
|
5932
5723
|
Object.entries(doc.props).filter(([, prop]) => {
|
|
@@ -5939,15 +5730,15 @@ var parseWithReactDocgenTypescript = asyncCache(
|
|
|
5939
5730
|
},
|
|
5940
5731
|
{ name: "parseWithReactDocgenTypescript" }
|
|
5941
5732
|
), findOwningTsconfigPath = cached(
|
|
5942
|
-
(typescript,
|
|
5943
|
-
let configPath = findTsconfigPath(
|
|
5733
|
+
(typescript, cwd, filePath) => {
|
|
5734
|
+
let configPath = findTsconfigPath(cwd);
|
|
5944
5735
|
if (configPath)
|
|
5945
5736
|
return findTsconfigPathIncludingFile(typescript, configPath, filePath, /* @__PURE__ */ new Set()) ?? configPath;
|
|
5946
5737
|
},
|
|
5947
5738
|
{
|
|
5948
|
-
key: (typescript,
|
|
5739
|
+
key: (typescript, cwd, filePath) => `${normalizeFileName(typescript, resolve(cwd))}::${normalizeFileName(
|
|
5949
5740
|
typescript,
|
|
5950
|
-
|
|
5741
|
+
resolve(filePath)
|
|
5951
5742
|
)}`,
|
|
5952
5743
|
name: "findOwningTsconfigPath"
|
|
5953
5744
|
}
|
|
@@ -5972,8 +5763,8 @@ function findTsconfigPathIncludingFile(typescript, configPath, filePath, seenCon
|
|
|
5972
5763
|
}
|
|
5973
5764
|
}
|
|
5974
5765
|
function getReferencedTsconfigPaths(typescript, configPath, config) {
|
|
5975
|
-
return (Array.isArray(config?.references) ? config.references : []).map((reference) => reference.path).filter((referencePath) => typeof referencePath == "string").map((referencePath) =>
|
|
5976
|
-
(referencePath) => referencePath.endsWith(".json") ? referencePath :
|
|
5766
|
+
return (Array.isArray(config?.references) ? config.references : []).map((reference) => reference.path).filter((referencePath) => typeof referencePath == "string").map((referencePath) => resolve(dirname3(configPath), referencePath)).map(
|
|
5767
|
+
(referencePath) => referencePath.endsWith(".json") ? referencePath : join2(referencePath, "tsconfig.json")
|
|
5977
5768
|
).filter((referencePath) => typescript.sys.fileExists(referencePath));
|
|
5978
5769
|
}
|
|
5979
5770
|
function parseTsconfig(typescript, configPath) {
|
|
@@ -5985,7 +5776,7 @@ function readTsconfig(typescript, configPath) {
|
|
|
5985
5776
|
return cachedTsconfig;
|
|
5986
5777
|
let { config } = typescript.readConfigFile(configPath, typescript.sys.readFile), state = {
|
|
5987
5778
|
config,
|
|
5988
|
-
parsed: typescript.parseJsonConfigFileContent(config, typescript.sys,
|
|
5779
|
+
parsed: typescript.parseJsonConfigFileContent(config, typescript.sys, dirname3(configPath))
|
|
5989
5780
|
};
|
|
5990
5781
|
return tsconfigCache.set(cacheKey, state), state;
|
|
5991
5782
|
}
|
|
@@ -5993,16 +5784,15 @@ function isSameFileName(typescript, left, right) {
|
|
|
5993
5784
|
return normalizeFileName(typescript, left) === normalizeFileName(typescript, right);
|
|
5994
5785
|
}
|
|
5995
5786
|
function normalizeFileName(typescript, fileName) {
|
|
5996
|
-
let normalized =
|
|
5787
|
+
let normalized = resolve(fileName).replace(/\\/g, "/");
|
|
5997
5788
|
return typescript.sys.useCaseSensitiveFileNames ? normalized : normalized.toLowerCase();
|
|
5998
5789
|
}
|
|
5999
5790
|
|
|
6000
5791
|
// src/componentManifest/resolveComponents.ts
|
|
6001
5792
|
import {
|
|
6002
|
-
createMetaComponentResolver,
|
|
6003
|
-
createModuleResolver,
|
|
6004
5793
|
extractDeclaredSubcomponents,
|
|
6005
|
-
|
|
5794
|
+
readDeclarationDocs as readDeclarationDocs2,
|
|
5795
|
+
resolveFileOrUndefined
|
|
6006
5796
|
} from "storybook/internal/common";
|
|
6007
5797
|
import { storyNameFromExport } from "storybook/internal/csf/csf-utils";
|
|
6008
5798
|
import {
|
|
@@ -6014,14 +5804,22 @@ import {
|
|
|
6014
5804
|
} from "storybook/internal/csf-tools";
|
|
6015
5805
|
|
|
6016
5806
|
// src/componentManifest/getComponentImports.ts
|
|
6017
|
-
import { dirname as
|
|
5807
|
+
import { dirname as dirname4 } from "node:path";
|
|
6018
5808
|
import {
|
|
6019
5809
|
buildImportStatements,
|
|
6020
5810
|
collectImportBindings as collectImportBindings2,
|
|
6021
5811
|
resolveComponentImport,
|
|
6022
5812
|
walk as walk2
|
|
6023
5813
|
} from "storybook/internal/csf-tools";
|
|
6024
|
-
import {
|
|
5814
|
+
import {
|
|
5815
|
+
createDocsModuleResolver,
|
|
5816
|
+
createMetaComponentResolver,
|
|
5817
|
+
createModuleResolver,
|
|
5818
|
+
followExport,
|
|
5819
|
+
isModuleNotFoundError as isModuleNotFoundError3,
|
|
5820
|
+
readDeclarationDocs,
|
|
5821
|
+
supportedExtensions
|
|
5822
|
+
} from "storybook/internal/common";
|
|
6025
5823
|
import { logger as logger6 } from "storybook/internal/node-logger";
|
|
6026
5824
|
|
|
6027
5825
|
// src/componentManifest/loadReactDocgen.ts
|
|
@@ -6029,7 +5827,7 @@ import { getTypeScriptForDocgenError, isModuleNotFoundError as isModuleNotFoundE
|
|
|
6029
5827
|
import { logger as logger5 } from "storybook/internal/node-logger";
|
|
6030
5828
|
var reactDocgenPromise;
|
|
6031
5829
|
function loadReactDocgen() {
|
|
6032
|
-
return reactDocgenPromise ??= import("./reactDocgen-
|
|
5830
|
+
return reactDocgenPromise ??= import("./reactDocgen-CS462JSF.js").catch((error) => {
|
|
6033
5831
|
if (isModuleNotFoundError2(error)) {
|
|
6034
5832
|
logger5.debug(`Skipping react-docgen, which is not installed: ${error}`);
|
|
6035
5833
|
return;
|
|
@@ -6057,7 +5855,34 @@ var isReactDocgenTypescriptResolvable = () => {
|
|
|
6057
5855
|
} catch {
|
|
6058
5856
|
return !1;
|
|
6059
5857
|
}
|
|
6060
|
-
}, baseIdentifier = (component) => component.split(".")[0] ?? component,
|
|
5858
|
+
}, baseIdentifier = (component) => component.split(".")[0] ?? component, followWith = (resolver) => {
|
|
5859
|
+
let reader = { resolver };
|
|
5860
|
+
return { reader, resolveMetaComponent: createMetaComponentResolver({ reader }) };
|
|
5861
|
+
}, followers = {
|
|
5862
|
+
// react-docgen and react-docgen-typescript document the source. Extensions are tried in the order
|
|
5863
|
+
// React's own lookup does, `.js` first as Vite does, so when `ui.js` sits next to `ui.tsx` both
|
|
5864
|
+
// pick the same file.
|
|
5865
|
+
source: followWith(
|
|
5866
|
+
createModuleResolver({
|
|
5867
|
+
extensions: [...supportedExtensions],
|
|
5868
|
+
extensionAlias: {
|
|
5869
|
+
".js": [".js", ".ts", ".tsx"],
|
|
5870
|
+
".jsx": [".jsx", ".tsx"],
|
|
5871
|
+
".mjs": [".mjs", ".mts"],
|
|
5872
|
+
".cjs": [".cjs", ".cts"]
|
|
5873
|
+
},
|
|
5874
|
+
mainFields: ["module", "main"],
|
|
5875
|
+
tsconfig: "auto"
|
|
5876
|
+
})
|
|
5877
|
+
),
|
|
5878
|
+
// react-component-meta documents what TypeScript does: the declaration file of a package.
|
|
5879
|
+
types: followWith(createDocsModuleResolver())
|
|
5880
|
+
};
|
|
5881
|
+
function readExportDocs(reader, filePath, exportName) {
|
|
5882
|
+
let origin = followExport(reader, filePath, exportName);
|
|
5883
|
+
return origin?.kind === "declaration" ? readDeclarationDocs({ path: origin.filePath, exportName: origin.exportName }) : void 0;
|
|
5884
|
+
}
|
|
5885
|
+
var getComponents = async ({
|
|
6061
5886
|
csf,
|
|
6062
5887
|
storyFilePath,
|
|
6063
5888
|
typescriptOptions = {},
|
|
@@ -6099,14 +5924,14 @@ var isReactDocgenTypescriptResolvable = () => {
|
|
|
6099
5924
|
jsxDepth: componentDepth.get(c)
|
|
6100
5925
|
}, path2, isPackage = !1;
|
|
6101
5926
|
try {
|
|
6102
|
-
component.importId && storyFilePath && (path2 = cachedResolveImport(matchPath(component.importId,
|
|
6103
|
-
basedir:
|
|
5927
|
+
component.importId && storyFilePath && (path2 = cachedResolveImport(matchPath(component.importId, dirname4(storyFilePath)), {
|
|
5928
|
+
basedir: dirname4(storyFilePath)
|
|
6104
5929
|
}));
|
|
6105
5930
|
} catch (e) {
|
|
6106
5931
|
logger6.debug(e);
|
|
6107
5932
|
}
|
|
6108
5933
|
try {
|
|
6109
|
-
component.importId && !component.importId.startsWith(".") && storyFilePath && (cachedResolveImport(component.importId, { basedir:
|
|
5934
|
+
component.importId && !component.importId.startsWith(".") && storyFilePath && (cachedResolveImport(component.importId, { basedir: dirname4(storyFilePath) }), isPackage = !0);
|
|
6110
5935
|
} catch {
|
|
6111
5936
|
}
|
|
6112
5937
|
let componentWithPackage = { ...component, isPackage }, target = docgenTargets?.get(c);
|
|
@@ -6123,13 +5948,17 @@ var isReactDocgenTypescriptResolvable = () => {
|
|
|
6123
5948
|
} : componentWithPackage, docgenPath = target?.path ?? path2;
|
|
6124
5949
|
if (path2 ??= docgenPath, path2 && docgenPath) {
|
|
6125
5950
|
if (docgenEngine === "react-docgen-typescript") {
|
|
6126
|
-
let reactDocgenTypescript, reactDocgenTypescriptError;
|
|
5951
|
+
let reactDocgenTypescript, reactDocgenTypescriptError, jsDoc;
|
|
6127
5952
|
try {
|
|
6128
5953
|
let docs = await parseWithReactDocgenTypescript(
|
|
6129
5954
|
docgenPath,
|
|
6130
5955
|
reactDocgenTypescriptOptions
|
|
6131
5956
|
);
|
|
6132
|
-
reactDocgenTypescript = matchComponentDoc(docs, docgenRef),
|
|
5957
|
+
reactDocgenTypescript = matchComponentDoc(docs, docgenRef), jsDoc = reactDocgenTypescript && readExportDocs(
|
|
5958
|
+
followers.source.reader,
|
|
5959
|
+
docgenPath,
|
|
5960
|
+
reactDocgenTypescript.exportName
|
|
5961
|
+
), reactDocgenTypescript || (reactDocgenTypescriptError = getReactDocgenTypescriptError(
|
|
6133
5962
|
docgenPath,
|
|
6134
5963
|
docgenRef,
|
|
6135
5964
|
docs
|
|
@@ -6138,22 +5967,17 @@ var isReactDocgenTypescriptResolvable = () => {
|
|
|
6138
5967
|
let message = e instanceof Error ? e.message : String(e);
|
|
6139
5968
|
logger6.debug(`react-docgen-typescript failed for ${docgenPath}: ${message}`), reactDocgenTypescriptError = isModuleNotFoundError3(e) && !isReactDocgenTypescriptResolvable() ? getDocgenPackageMissingError("react-docgen-typescript") : {
|
|
6140
5969
|
name: "react-docgen-typescript parse error",
|
|
6141
|
-
message: `File: ${docgenPath}
|
|
5970
|
+
message: `File: ${relative(process.cwd(), docgenPath)}
|
|
6142
5971
|
${message}`
|
|
6143
5972
|
};
|
|
6144
5973
|
}
|
|
6145
|
-
let reactDocgenTypescriptDoc, componentJsDocTags = reactDocgenTypescript?.componentJsDocTags;
|
|
6146
|
-
if (reactDocgenTypescript) {
|
|
6147
|
-
let { componentJsDocTags: _tags, ...doc } = reactDocgenTypescript;
|
|
6148
|
-
reactDocgenTypescriptDoc = doc, componentJsDocTags = _tags;
|
|
6149
|
-
}
|
|
6150
5974
|
return {
|
|
6151
5975
|
...componentWithPackage,
|
|
6152
5976
|
path: path2,
|
|
6153
|
-
...
|
|
5977
|
+
...reactDocgenTypescript ? { reactDocgenTypescript } : {},
|
|
6154
5978
|
...reactDocgenTypescriptError ? { reactDocgenTypescriptError } : {},
|
|
6155
|
-
...
|
|
6156
|
-
importOverride:
|
|
5979
|
+
...jsDoc ? { jsDoc } : {},
|
|
5980
|
+
importOverride: jsDoc?.tags.import?.[0]?.trim()
|
|
6157
5981
|
};
|
|
6158
5982
|
}
|
|
6159
5983
|
if (docgenEngine === "react-docgen") {
|
|
@@ -6183,21 +6007,6 @@ function findExactComponentMatch(components, componentName) {
|
|
|
6183
6007
|
}
|
|
6184
6008
|
|
|
6185
6009
|
// src/componentManifest/resolveComponents.ts
|
|
6186
|
-
var resolveMetaComponent = createMetaComponentResolver({
|
|
6187
|
-
reader: {
|
|
6188
|
-
resolver: createModuleResolver({
|
|
6189
|
-
extensions: [...supportedExtensions],
|
|
6190
|
-
extensionAlias: {
|
|
6191
|
-
".js": [".js", ".ts", ".tsx"],
|
|
6192
|
-
".jsx": [".jsx", ".tsx"],
|
|
6193
|
-
".mjs": [".mjs", ".mts"],
|
|
6194
|
-
".cjs": [".cjs", ".cts"]
|
|
6195
|
-
},
|
|
6196
|
-
mainFields: ["module", "main"],
|
|
6197
|
-
tsconfig: "auto"
|
|
6198
|
-
})
|
|
6199
|
-
}
|
|
6200
|
-
});
|
|
6201
6010
|
function findMatchingComponent(components, componentName, title) {
|
|
6202
6011
|
let exactMatch = findExactComponentMatch(components, componentName);
|
|
6203
6012
|
if (exactMatch)
|
|
@@ -6216,14 +6025,14 @@ function findMatchingComponent(components, componentName, title) {
|
|
|
6216
6025
|
return best;
|
|
6217
6026
|
}
|
|
6218
6027
|
async function resolveStoryFileComponents(options) {
|
|
6219
|
-
let { storyPath, title, typescriptOptions, docgenEngine } = options, storyFile = cachedReadTextFileSync(storyPath), csf = loadCsf(storyFile, { makeTitle: () => title, fileName: storyPath }).parse(), componentName = csf._meta?.component, declaredSubcomponents = extractDeclaredSubcomponents(csf), docgenTargets = /* @__PURE__ */ new Map(), storyImports = collectImportBindings3(csf.editor.program), resolveName = (name, node) => {
|
|
6028
|
+
let { storyPath, title, typescriptOptions, docgenEngine } = options, { reader, resolveMetaComponent } = docgenEngine === "react-component-meta" ? followers.types : followers.source, { resolver } = reader, storyFile = cachedReadTextFileSync(storyPath), csf = loadCsf(storyFile, { makeTitle: () => title, fileName: storyPath }).parse(), componentName = csf._meta?.component, declaredSubcomponents = extractDeclaredSubcomponents(csf), declarations = /* @__PURE__ */ new Map(), docgenTargets = /* @__PURE__ */ new Map(), storyImports = collectImportBindings3(csf.editor.program), resolveName = (name, node) => {
|
|
6220
6029
|
let resolved = resolveMetaComponent(csf, storyPath, node);
|
|
6221
6030
|
if ("reason" in resolved)
|
|
6222
6031
|
return resolved.reason === "missing-export" && docgenTargets.set(name, {
|
|
6223
6032
|
missing: `"${resolved.importId}" has no export "${resolved.exportName}", which ${resolved.expression} reads.`
|
|
6224
6033
|
}), name;
|
|
6225
6034
|
let { localName, importId, importer, path: path2, exportName } = resolved.component, ownName = importer === storyPath && storyImports.get(localName)?.importId === importId && !storyImports.has(name.split(".")[0]) ? localName : name;
|
|
6226
|
-
return importId && path2 && docgenTargets.set(ownName, { path: path2, exportName }), ownName;
|
|
6035
|
+
return declarations.set(ownName, resolved.component), importId && path2 && docgenTargets.set(ownName, { path: path2, exportName }), ownName;
|
|
6227
6036
|
}, metaComponentName = componentName && resolveName(componentName), declared = declaredSubcomponents.map((subcomponent) => ({
|
|
6228
6037
|
name: subcomponent.name,
|
|
6229
6038
|
componentName: resolveName(subcomponent.componentName, subcomponent.node)
|
|
@@ -6241,6 +6050,20 @@ async function resolveStoryFileComponents(options) {
|
|
|
6241
6050
|
name: subcomponent.name,
|
|
6242
6051
|
component: findExactComponentMatch(allComponents, subcomponent.componentName)
|
|
6243
6052
|
}));
|
|
6053
|
+
if (docgenEngine === "react-component-meta") {
|
|
6054
|
+
let readImportDocs = (ref) => {
|
|
6055
|
+
let filePath = ref.importId && resolveFileOrUndefined(resolver, storyPath, ref.importId);
|
|
6056
|
+
return filePath && ref.importName ? readExportDocs(reader, filePath, ref.importName) : void 0;
|
|
6057
|
+
};
|
|
6058
|
+
for (let ref of /* @__PURE__ */ new Set([component, ...subcomponents.map((sub) => sub.component)])) {
|
|
6059
|
+
if (!ref)
|
|
6060
|
+
continue;
|
|
6061
|
+
let isMemberOfImport = !!ref.member && !ref.namespace, declaration = declarations.get(ref.componentName);
|
|
6062
|
+
declaration?.path ? ref.jsDoc = readDeclarationDocs2(declaration) : !declaration && !isMemberOfImport && (ref.jsDoc = readImportDocs(ref));
|
|
6063
|
+
let importTag = ref.jsDoc?.tags.import ?? (ref.member ? readImportDocs(ref)?.tags.import : void 0);
|
|
6064
|
+
ref.importOverride = importTag?.[0]?.trim();
|
|
6065
|
+
}
|
|
6066
|
+
}
|
|
6244
6067
|
return { storyPath, storyFile, csf, componentName, allComponents, component, subcomponents };
|
|
6245
6068
|
}
|
|
6246
6069
|
function extractStorySnippets(csf, componentName, filterStoryIds, references, withTemplate = !1) {
|
|
@@ -6276,7 +6099,7 @@ function extractStorySnippets(csf, componentName, filterStoryIds, references, wi
|
|
|
6276
6099
|
}
|
|
6277
6100
|
|
|
6278
6101
|
// src/componentManifest/buildReactComponentDocgen.ts
|
|
6279
|
-
import { getComponentIdFromEntry } from "storybook/internal/common";
|
|
6102
|
+
import { componentPathFromStory, getComponentIdFromEntry } from "storybook/internal/common";
|
|
6280
6103
|
import {
|
|
6281
6104
|
buildImportStatements as buildImportStatements2,
|
|
6282
6105
|
createStoryReferenceResolver,
|
|
@@ -6316,8 +6139,9 @@ function getFallbackImport(packageName, componentName) {
|
|
|
6316
6139
|
}).join(`
|
|
6317
6140
|
`) : "";
|
|
6318
6141
|
}
|
|
6142
|
+
var relativize = (fileName) => posix.relative(process.cwd(), fileName);
|
|
6319
6143
|
function relativizeComponentMetaPaths(doc) {
|
|
6320
|
-
let
|
|
6144
|
+
let relativizeProp = (prop) => ({
|
|
6321
6145
|
...prop,
|
|
6322
6146
|
parent: prop.parent ? { ...prop.parent, fileName: relativize(prop.parent.fileName) } : prop.parent,
|
|
6323
6147
|
declarations: prop.declarations?.map((declaration) => ({
|
|
@@ -6327,21 +6151,24 @@ function relativizeComponentMetaPaths(doc) {
|
|
|
6327
6151
|
});
|
|
6328
6152
|
return {
|
|
6329
6153
|
...doc,
|
|
6154
|
+
filePath: relativize(doc.filePath),
|
|
6330
6155
|
props: Object.fromEntries(
|
|
6331
6156
|
Object.entries(doc.props).map(([name, prop]) => [name, relativizeProp(prop)])
|
|
6332
6157
|
)
|
|
6333
6158
|
};
|
|
6334
6159
|
}
|
|
6160
|
+
var getJsDoc = (component) => component?.jsDoc ?? (component?.reactDocgen?.type === "success" ? { description: component.reactDocgen.data.description, tags: void 0 } : void 0);
|
|
6335
6161
|
function getComponentDocgenData(component, docgenEngine) {
|
|
6336
|
-
let reactDocgen, reactDocgenTypescript, reactComponentMeta,
|
|
6162
|
+
let reactDocgen, reactDocgenTypescript, reactComponentMeta, docgenError;
|
|
6337
6163
|
if (docgenEngine === "react-docgen") {
|
|
6338
6164
|
let result = component?.reactDocgen;
|
|
6339
|
-
reactDocgen = result?.type === "success" ? result.data :
|
|
6340
|
-
} else docgenEngine === "react-docgen-typescript" ? (reactDocgenTypescript = component?.reactDocgenTypescript
|
|
6165
|
+
reactDocgen = result?.type === "success" ? { ...result.data, definedInFile: relativize(result.data.definedInFile) } : void 0, docgenError = result?.type === "error" ? result.error : void 0;
|
|
6166
|
+
} else docgenEngine === "react-docgen-typescript" ? (reactDocgenTypescript = component?.reactDocgenTypescript && {
|
|
6167
|
+
...component.reactDocgenTypescript,
|
|
6168
|
+
filePath: relativize(component.reactDocgenTypescript.filePath)
|
|
6169
|
+
}, docgenError = component?.reactDocgenTypescriptError) : reactComponentMeta = component?.reactComponentMeta ? relativizeComponentMetaPaths(component.reactComponentMeta) : void 0;
|
|
6341
6170
|
return {
|
|
6342
|
-
docgenDescription,
|
|
6343
6171
|
docgenError,
|
|
6344
|
-
docgenJsDocTags,
|
|
6345
6172
|
reactComponentMeta,
|
|
6346
6173
|
reactDocgen,
|
|
6347
6174
|
reactDocgenTypescript
|
|
@@ -6352,24 +6179,18 @@ function createSubcomponentDocgen({
|
|
|
6352
6179
|
declaredName,
|
|
6353
6180
|
docgenEngine,
|
|
6354
6181
|
packageName,
|
|
6182
|
+
storyPath,
|
|
6355
6183
|
storyFilePath
|
|
6356
6184
|
}) {
|
|
6357
6185
|
let imports = buildImportStatements2({ refs: component ? [component] : [], packageName }).join(`
|
|
6358
|
-
`).trim() || getFallbackImport(packageName, component?.componentName), {
|
|
6359
|
-
reactDocgen,
|
|
6360
|
-
reactDocgenTypescript,
|
|
6361
|
-
reactComponentMeta,
|
|
6362
|
-
docgenDescription,
|
|
6363
|
-
docgenJsDocTags,
|
|
6364
|
-
docgenError
|
|
6365
|
-
} = getComponentDocgenData(component, docgenEngine), { description, summary, jsDocTags } = extractComponentDescription(
|
|
6186
|
+
`).trim() || getFallbackImport(packageName, component?.componentName), { reactDocgen, reactDocgenTypescript, reactComponentMeta, docgenError } = getComponentDocgenData(component, docgenEngine), jsDoc = getJsDoc(component), { description, summary, jsDocTags } = extractComponentDescription(
|
|
6366
6187
|
void 0,
|
|
6367
|
-
|
|
6368
|
-
|
|
6188
|
+
jsDoc?.description,
|
|
6189
|
+
jsDoc?.tags
|
|
6369
6190
|
);
|
|
6370
6191
|
return {
|
|
6371
6192
|
name: declaredName,
|
|
6372
|
-
path: component?.path
|
|
6193
|
+
path: component?.path ? componentPathFromStory(storyFilePath, storyPath, component.path) : storyFilePath,
|
|
6373
6194
|
description,
|
|
6374
6195
|
summary,
|
|
6375
6196
|
import: imports || void 0,
|
|
@@ -6383,6 +6204,22 @@ function createSubcomponentDocgen({
|
|
|
6383
6204
|
})
|
|
6384
6205
|
};
|
|
6385
6206
|
}
|
|
6207
|
+
function describeComponent({
|
|
6208
|
+
entry,
|
|
6209
|
+
csf,
|
|
6210
|
+
componentName,
|
|
6211
|
+
component
|
|
6212
|
+
}) {
|
|
6213
|
+
let jsDoc = getJsDoc(component);
|
|
6214
|
+
return {
|
|
6215
|
+
name: componentName ?? entry.title.split("/").at(-1).replace(/\s+/g, ""),
|
|
6216
|
+
...extractComponentDescription(
|
|
6217
|
+
extractDescription(csf._metaStatement, csf.editor) || void 0,
|
|
6218
|
+
jsDoc?.description,
|
|
6219
|
+
jsDoc?.tags
|
|
6220
|
+
)
|
|
6221
|
+
};
|
|
6222
|
+
}
|
|
6386
6223
|
function buildStoryDocsFromResolved({
|
|
6387
6224
|
entry,
|
|
6388
6225
|
storyPath,
|
|
@@ -6424,19 +6261,11 @@ function buildComponentDocgenFromResolved({
|
|
|
6424
6261
|
subcomponents,
|
|
6425
6262
|
docgenEngine
|
|
6426
6263
|
}) {
|
|
6427
|
-
let
|
|
6428
|
-
id,
|
|
6429
|
-
name: componentName ?? title,
|
|
6264
|
+
let packageName = getImportablePackageName(component?.path, storyPath), base = {
|
|
6265
|
+
id: getComponentIdFromEntry(entry),
|
|
6430
6266
|
path: storyFilePath,
|
|
6431
|
-
|
|
6432
|
-
}, {
|
|
6433
|
-
reactDocgen,
|
|
6434
|
-
reactDocgenTypescript,
|
|
6435
|
-
reactComponentMeta,
|
|
6436
|
-
docgenDescription,
|
|
6437
|
-
docgenJsDocTags,
|
|
6438
|
-
docgenError
|
|
6439
|
-
} = getComponentDocgenData(component, docgenEngine);
|
|
6267
|
+
...describeComponent({ entry, csf, componentName, component })
|
|
6268
|
+
}, { reactDocgen, reactDocgenTypescript, reactComponentMeta, docgenError } = getComponentDocgenData(component, docgenEngine);
|
|
6440
6269
|
if (!reactDocgen && !reactDocgenTypescript && !reactComponentMeta) {
|
|
6441
6270
|
let error = csf._meta?.component ? {
|
|
6442
6271
|
name: "No component import found",
|
|
@@ -6447,7 +6276,6 @@ function buildComponentDocgenFromResolved({
|
|
|
6447
6276
|
};
|
|
6448
6277
|
return {
|
|
6449
6278
|
...base,
|
|
6450
|
-
jsDocTags: base.jsDocTags ?? {},
|
|
6451
6279
|
error: docgenError ?? {
|
|
6452
6280
|
name: error.name,
|
|
6453
6281
|
message: (csf._metaStatement ? storyShapeError2(error.message, csf._metaStatement, csf.editor).message : error.message) + `
|
|
@@ -6457,11 +6285,7 @@ ${storyFile}`
|
|
|
6457
6285
|
}
|
|
6458
6286
|
};
|
|
6459
6287
|
}
|
|
6460
|
-
let
|
|
6461
|
-
metaJsDoc,
|
|
6462
|
-
docgenDescription,
|
|
6463
|
-
docgenJsDocTags
|
|
6464
|
-
), subcomponentEntries = Object.fromEntries(
|
|
6288
|
+
let subcomponentEntries = Object.fromEntries(
|
|
6465
6289
|
subcomponents.map((subcomponent) => [
|
|
6466
6290
|
subcomponent.name,
|
|
6467
6291
|
createSubcomponentDocgen({
|
|
@@ -6469,18 +6293,16 @@ ${storyFile}`
|
|
|
6469
6293
|
declaredName: subcomponent.name,
|
|
6470
6294
|
docgenEngine,
|
|
6471
6295
|
packageName,
|
|
6296
|
+
storyPath,
|
|
6472
6297
|
storyFilePath
|
|
6473
6298
|
})
|
|
6474
6299
|
])
|
|
6475
6300
|
);
|
|
6476
6301
|
return {
|
|
6477
6302
|
...base,
|
|
6478
|
-
description,
|
|
6479
|
-
summary,
|
|
6480
6303
|
reactDocgen,
|
|
6481
6304
|
reactDocgenTypescript,
|
|
6482
6305
|
reactComponentMeta,
|
|
6483
|
-
jsDocTags,
|
|
6484
6306
|
...Object.keys(subcomponentEntries).length > 0 ? { subcomponents: subcomponentEntries } : {},
|
|
6485
6307
|
error: docgenError
|
|
6486
6308
|
};
|
|
@@ -6527,12 +6349,10 @@ function buildReactComponentDocgenFromResolved({
|
|
|
6527
6349
|
}
|
|
6528
6350
|
|
|
6529
6351
|
export {
|
|
6530
|
-
join2 as join,
|
|
6531
|
-
isAbsolute2 as isAbsolute,
|
|
6532
|
-
posix,
|
|
6533
6352
|
getCodeSnippet,
|
|
6534
6353
|
invalidateParser,
|
|
6535
6354
|
resolveStoryFileComponents,
|
|
6355
|
+
describeComponent,
|
|
6536
6356
|
buildStoryDocsFromResolved,
|
|
6537
6357
|
buildComponentDocgenFromResolved,
|
|
6538
6358
|
buildReactComponentDocgenFromResolved,
|