@mui/internal-docs-infra 0.1.1-alpha.2 → 0.1.1-alpha.3
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loadVariant.d.ts","sourceRoot":"","sources":["../../../src/CodeHighlighter/loadVariant.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,WAAW,EAIX,WAAW,EACX,UAAU,EACV,eAAe,EACf,kBAAkB,EAClB,eAAe,EAChB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"loadVariant.d.ts","sourceRoot":"","sources":["../../../src/CodeHighlighter/loadVariant.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,WAAW,EAIX,WAAW,EACX,UAAU,EACV,eAAe,EACf,kBAAkB,EAClB,eAAe,EAChB,MAAM,SAAS,CAAC;AA6ajB;;;;;GAKG;AACH,wBAAsB,WAAW,CAC/B,GAAG,EAAE,MAAM,EACX,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,WAAW,GAAG,MAAM,GAAG,SAAS,EACzC,YAAY,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,EACnC,UAAU,CAAC,EAAE,UAAU,EACvB,eAAe,CAAC,EAAE,eAAe,EACjC,kBAAkB,CAAC,EAAE,kBAAkB,EACvC,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,YAAY,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CAiHxD"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
3
2
|
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
4
3
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
5
4
|
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
6
5
|
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
6
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
7
7
|
import { transformSource } from "./transformSource.js";
|
|
8
8
|
import { transformParsedSource } from "./transformParsedSource.js";
|
|
9
9
|
import { getFileNameFromUrl } from "../loaderUtils/index.js";
|
|
@@ -12,82 +12,90 @@ function isProduction() {
|
|
|
12
12
|
return typeof process !== 'undefined' && process.env.NODE_ENV === 'production';
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
// Helper function to
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
try {
|
|
21
|
-
// Use URL constructor to properly resolve relative paths
|
|
22
|
-
var resolved = new URL(relativePath, basePath);
|
|
23
|
-
return resolved.href;
|
|
24
|
-
} catch (error) {
|
|
25
|
-
// Fallback to manual resolution if URL constructor fails
|
|
26
|
-
var baseSegments = basePath.split('/');
|
|
27
|
-
var relativeSegments = relativePath.split('/');
|
|
28
|
-
|
|
29
|
-
// Remove the filename from base path
|
|
30
|
-
baseSegments.pop();
|
|
31
|
-
var _iterator = _createForOfIteratorHelper(relativeSegments),
|
|
32
|
-
_step;
|
|
33
|
-
try {
|
|
34
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
35
|
-
var segment = _step.value;
|
|
36
|
-
if (segment === '..') {
|
|
37
|
-
baseSegments.pop();
|
|
38
|
-
} else if (segment !== '.') {
|
|
39
|
-
baseSegments.push(segment);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
} catch (err) {
|
|
43
|
-
_iterator.e(err);
|
|
44
|
-
} finally {
|
|
45
|
-
_iterator.f();
|
|
46
|
-
}
|
|
47
|
-
return baseSegments.join('/');
|
|
15
|
+
// Helper function to convert a nested key based on the directory of the source file key
|
|
16
|
+
function convertKeyBasedOnDirectory(nestedKey, sourceFileKey) {
|
|
17
|
+
// If it's an absolute path (starts with / or contains ://), keep as-is
|
|
18
|
+
if (nestedKey.startsWith('/') || nestedKey.includes('://')) {
|
|
19
|
+
return nestedKey;
|
|
48
20
|
}
|
|
49
|
-
}
|
|
50
21
|
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
if (!
|
|
54
|
-
|
|
22
|
+
// Treat bare filenames as relative to current directory (same as ./filename)
|
|
23
|
+
var processedNestedKey = nestedKey;
|
|
24
|
+
if (!nestedKey.startsWith('.')) {
|
|
25
|
+
processedNestedKey = "./".concat(nestedKey);
|
|
55
26
|
}
|
|
56
|
-
try {
|
|
57
|
-
// Use URL constructor to resolve the relative path to absolute
|
|
58
|
-
var absoluteUrl = new URL(relativePath, fromBaseUrl);
|
|
59
27
|
|
|
60
|
-
|
|
61
|
-
|
|
28
|
+
// Manual path resolution: resolve processedNestedKey relative to the directory of sourceFileKey
|
|
29
|
+
// Both paths are relative to the entry directory (which is always './') - ignore file:// URLs completely
|
|
62
30
|
|
|
63
|
-
|
|
64
|
-
|
|
31
|
+
// Get the directory of the source file key (not URL)
|
|
32
|
+
var sourceDir = sourceFileKey.includes('/') ? sourceFileKey.substring(0, sourceFileKey.lastIndexOf('/')) : '.';
|
|
65
33
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (
|
|
69
|
-
return
|
|
34
|
+
// Parse both paths into components
|
|
35
|
+
var parsePathComponents = function parsePathComponents(path) {
|
|
36
|
+
if (path === '.' || path === '') {
|
|
37
|
+
return [];
|
|
70
38
|
}
|
|
39
|
+
return path.split('/').filter(function (part) {
|
|
40
|
+
return part !== '';
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
var sourceDirComponents = parsePathComponents(sourceDir);
|
|
44
|
+
var nestedComponents = parsePathComponents(processedNestedKey);
|
|
71
45
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
var toBaseParts = toBaseDir.pathname.split('/').filter(Boolean);
|
|
75
|
-
var absoluteParts = absoluteUrl.pathname.split('/').filter(Boolean);
|
|
46
|
+
// Start from the source directory and apply the nested path
|
|
47
|
+
var resultComponents = _toConsumableArray(sourceDirComponents);
|
|
76
48
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
49
|
+
// Apply each component of the nested path
|
|
50
|
+
var _iterator = _createForOfIteratorHelper(nestedComponents),
|
|
51
|
+
_step;
|
|
52
|
+
try {
|
|
53
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
54
|
+
var component = _step.value;
|
|
55
|
+
if (component === '..') {
|
|
56
|
+
if (resultComponents.length > 0 && resultComponents[resultComponents.length - 1] !== '..') {
|
|
57
|
+
// Normal case: pop a regular directory component
|
|
58
|
+
resultComponents.pop();
|
|
59
|
+
} else {
|
|
60
|
+
// Either resultComponents is empty OR the last component is already '..'
|
|
61
|
+
// In both cases, we need to go up one more level
|
|
62
|
+
resultComponents.push('..');
|
|
63
|
+
}
|
|
64
|
+
} else if (component === '.') {
|
|
65
|
+
// Current directory, skip
|
|
66
|
+
continue;
|
|
67
|
+
} else {
|
|
68
|
+
resultComponents.push(component);
|
|
69
|
+
}
|
|
81
70
|
}
|
|
82
71
|
|
|
83
|
-
// Build
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
72
|
+
// Build the final result
|
|
73
|
+
} catch (err) {
|
|
74
|
+
_iterator.e(err);
|
|
75
|
+
} finally {
|
|
76
|
+
_iterator.f();
|
|
77
|
+
}
|
|
78
|
+
if (resultComponents.length === 0) {
|
|
79
|
+
return '';
|
|
80
|
+
}
|
|
81
|
+
var result = resultComponents.join('/');
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Normalize a relative path key by removing unnecessary ./ prefix
|
|
87
|
+
*/
|
|
88
|
+
function normalizePathKey(key) {
|
|
89
|
+
if (key.startsWith('./')) {
|
|
90
|
+
return key.substring(2);
|
|
89
91
|
}
|
|
92
|
+
return key;
|
|
90
93
|
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Loads and processes extra files recursively with support for relative paths
|
|
97
|
+
* and circular dependency detection. Uses Promise.all for parallel loading.
|
|
98
|
+
*/
|
|
91
99
|
function loadSingleFile(_x, _x2, _x3, _x4, _x5, _x6, _x7, _x8, _x9) {
|
|
92
100
|
return _loadSingleFile.apply(this, arguments);
|
|
93
101
|
}
|
|
@@ -281,7 +289,7 @@ function _loadSingleFile() {
|
|
|
281
289
|
break;
|
|
282
290
|
}
|
|
283
291
|
_context.next = 71;
|
|
284
|
-
return transformSource(finalSource, fileName, sourceTransformers);
|
|
292
|
+
return transformSource(finalSource, normalizePathKey(fileName), sourceTransformers);
|
|
285
293
|
case 71:
|
|
286
294
|
finalTransforms = _context.sent;
|
|
287
295
|
case 72:
|
|
@@ -307,7 +315,7 @@ function _loadSingleFile() {
|
|
|
307
315
|
break;
|
|
308
316
|
}
|
|
309
317
|
_context.next = 84;
|
|
310
|
-
return transformParsedSource(sourceString, finalSource, fileName, finalTransforms, parseSource);
|
|
318
|
+
return transformParsedSource(sourceString, finalSource, normalizePathKey(fileName), finalTransforms, parseSource);
|
|
311
319
|
case 84:
|
|
312
320
|
finalTransforms = _context.sent;
|
|
313
321
|
case 85:
|
|
@@ -366,13 +374,14 @@ function _loadExtraFiles() {
|
|
|
366
374
|
_step4$value,
|
|
367
375
|
nestedExtraFiles,
|
|
368
376
|
nestedFilesUsed,
|
|
369
|
-
|
|
377
|
+
sourceFileKey,
|
|
370
378
|
_i3,
|
|
371
379
|
_Object$entries2,
|
|
372
380
|
_Object$entries2$_i,
|
|
373
381
|
nestedKey,
|
|
374
382
|
nestedValue,
|
|
375
383
|
convertedKey,
|
|
384
|
+
normalizedConvertedKey,
|
|
376
385
|
_args4 = arguments;
|
|
377
386
|
return _regeneratorRuntime().wrap(function _callee3$(_context4) {
|
|
378
387
|
while (1) switch (_context4.prev = _context4.next) {
|
|
@@ -401,8 +410,8 @@ function _loadExtraFiles() {
|
|
|
401
410
|
_context2.next = 9;
|
|
402
411
|
break;
|
|
403
412
|
}
|
|
404
|
-
// fileData is a URL/path
|
|
405
|
-
fileUrl = fileData
|
|
413
|
+
// fileData is a URL/path - use it directly, don't modify it
|
|
414
|
+
fileUrl = fileData;
|
|
406
415
|
|
|
407
416
|
// Check for circular dependencies
|
|
408
417
|
if (!loadedFiles.has(fileUrl)) {
|
|
@@ -463,12 +472,13 @@ function _loadExtraFiles() {
|
|
|
463
472
|
_iterator3 = _createForOfIteratorHelper(extraFileResults);
|
|
464
473
|
_context4.prev = 14;
|
|
465
474
|
_loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
|
|
466
|
-
var _step3$value, fileName, result, filesUsed,
|
|
475
|
+
var _step3$value, fileName, result, filesUsed, normalizedFileName, sourceFileUrl, fileData;
|
|
467
476
|
return _regeneratorRuntime().wrap(function _loop$(_context3) {
|
|
468
477
|
while (1) switch (_context3.prev = _context3.next) {
|
|
469
478
|
case 0:
|
|
470
479
|
_step3$value = _step3.value, fileName = _step3$value.fileName, result = _step3$value.result, filesUsed = _step3$value.filesUsed;
|
|
471
|
-
|
|
480
|
+
normalizedFileName = normalizePathKey(fileName);
|
|
481
|
+
processedExtraFiles[normalizedFileName] = {
|
|
472
482
|
source: result.source,
|
|
473
483
|
transforms: result.transforms
|
|
474
484
|
};
|
|
@@ -476,14 +486,14 @@ function _loadExtraFiles() {
|
|
|
476
486
|
// Add files used from this file load
|
|
477
487
|
allFilesUsed.push.apply(allFilesUsed, _toConsumableArray(filesUsed));
|
|
478
488
|
|
|
479
|
-
// Collect promises for nested extra files with their source
|
|
489
|
+
// Collect promises for nested extra files with their source key
|
|
480
490
|
if (result.extraFiles) {
|
|
481
|
-
|
|
491
|
+
sourceFileUrl = baseUrl;
|
|
482
492
|
fileData = extraFiles[fileName];
|
|
483
493
|
if (typeof fileData === 'string') {
|
|
484
|
-
|
|
494
|
+
sourceFileUrl = fileData; // Use the URL directly, don't modify it
|
|
485
495
|
}
|
|
486
|
-
nestedExtraFilesPromises.push(loadExtraFiles(variantName, result.extraFiles,
|
|
496
|
+
nestedExtraFilesPromises.push(loadExtraFiles(variantName, result.extraFiles, sourceFileUrl,
|
|
487
497
|
// Use the source file's URL as base for its extra files
|
|
488
498
|
entryUrl,
|
|
489
499
|
// Keep the entry URL for final conversion
|
|
@@ -494,11 +504,11 @@ function _loadExtraFiles() {
|
|
|
494
504
|
return {
|
|
495
505
|
files: nestedResult.extraFiles,
|
|
496
506
|
allFilesUsed: nestedResult.allFilesUsed,
|
|
497
|
-
|
|
507
|
+
sourceFileKey: normalizedFileName // Pass the normalized key
|
|
498
508
|
};
|
|
499
509
|
}));
|
|
500
510
|
}
|
|
501
|
-
case
|
|
511
|
+
case 5:
|
|
502
512
|
case "end":
|
|
503
513
|
return _context3.stop();
|
|
504
514
|
}
|
|
@@ -537,14 +547,15 @@ function _loadExtraFiles() {
|
|
|
537
547
|
_iterator4 = _createForOfIteratorHelper(nestedExtraFilesResults);
|
|
538
548
|
try {
|
|
539
549
|
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
|
540
|
-
_step4$value = _step4.value, nestedExtraFiles = _step4$value.files, nestedFilesUsed = _step4$value.allFilesUsed,
|
|
550
|
+
_step4$value = _step4.value, nestedExtraFiles = _step4$value.files, nestedFilesUsed = _step4$value.allFilesUsed, sourceFileKey = _step4$value.sourceFileKey;
|
|
541
551
|
// Add nested files used
|
|
542
552
|
allFilesUsed.push.apply(allFilesUsed, _toConsumableArray(nestedFilesUsed));
|
|
543
553
|
for (_i3 = 0, _Object$entries2 = Object.entries(nestedExtraFiles); _i3 < _Object$entries2.length; _i3++) {
|
|
544
554
|
_Object$entries2$_i = _slicedToArray(_Object$entries2[_i3], 2), nestedKey = _Object$entries2$_i[0], nestedValue = _Object$entries2$_i[1];
|
|
545
|
-
// Convert the key
|
|
546
|
-
convertedKey =
|
|
547
|
-
|
|
555
|
+
// Convert the key based on the directory structure of the source key
|
|
556
|
+
convertedKey = convertKeyBasedOnDirectory(nestedKey, sourceFileKey);
|
|
557
|
+
normalizedConvertedKey = normalizePathKey(convertedKey);
|
|
558
|
+
processedExtraFiles[normalizedConvertedKey] = nestedValue;
|
|
548
559
|
}
|
|
549
560
|
}
|
|
550
561
|
} catch (err) {
|
package/package.json
CHANGED
package/useCode/useCode.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export interface UseCodeResult {
|
|
|
22
22
|
}>;
|
|
23
23
|
selectedFile: React.ReactNode;
|
|
24
24
|
selectedFileName: string;
|
|
25
|
-
selectFileName:
|
|
25
|
+
selectFileName: (fileName: string) => void;
|
|
26
26
|
expanded: boolean;
|
|
27
27
|
expand: () => void;
|
|
28
28
|
setExpanded: React.Dispatch<React.SetStateAction<boolean>>;
|
package/useCode/useCode.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCode.d.ts","sourceRoot":"","sources":["../../../src/useCode/useCode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAM/B,OAAO,EAAa,aAAa,EAAE,MAAM,cAAc,CAAC;AAExD,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAKxD,KAAK,WAAW,GAAG;IACjB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IAC5C,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;IAC5D,KAAK,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAA;KAAE,CAAC,CAAC;IAC3D,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC;IAC9B,gBAAgB,EAAE,MAAM,CAAC;IACzB,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"useCode.d.ts","sourceRoot":"","sources":["../../../src/useCode/useCode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAM/B,OAAO,EAAa,aAAa,EAAE,MAAM,cAAc,CAAC;AAExD,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAKxD,KAAK,WAAW,GAAG;IACjB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IAC5C,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;IAC5D,KAAK,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,KAAK,CAAC,SAAS,CAAA;KAAE,CAAC,CAAC;IAC3D,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC;IAC9B,gBAAgB,EAAE,MAAM,CAAC;IACzB,cAAc,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,WAAW,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;IAC3D,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,IAAI,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,iBAAiB,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACpE,YAAY,EAAE,OAAO,CAAC;IACtB,mBAAmB,EAAE,MAAM,EAAE,CAAC;IAC9B,iBAAiB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;IAC7C,eAAe,EAAE,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;CACzD;AAMD,wBAAgB,OAAO,CAAC,YAAY,EAAE,YAAY,EAAE,IAAI,CAAC,EAAE,WAAW,GAAG,aAAa,CAyarF"}
|
package/useCode/useCode.js
CHANGED
|
@@ -161,10 +161,10 @@ export function useCode(contentProps, opts) {
|
|
|
161
161
|
// Handle different extraFile structures
|
|
162
162
|
if (typeof fileData === 'string') {
|
|
163
163
|
source = fileData;
|
|
164
|
-
transforms =
|
|
164
|
+
transforms = undefined; // Don't inherit variant transforms for simple string files
|
|
165
165
|
} else if (fileData && _typeof(fileData) === 'object' && 'source' in fileData) {
|
|
166
166
|
source = fileData.source;
|
|
167
|
-
transforms = fileData.transforms
|
|
167
|
+
transforms = fileData.transforms; // Only use explicit transforms for this file
|
|
168
168
|
} else {
|
|
169
169
|
return; // Skip invalid entries
|
|
170
170
|
}
|
|
@@ -183,13 +183,31 @@ export function useCode(contentProps, opts) {
|
|
|
183
183
|
console.error("Transform failed for ".concat(fileName, ":"), error);
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
|
-
|
|
187
|
-
files
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
component: toComponent(transformedSource)
|
|
186
|
+
|
|
187
|
+
// Only update filenameMap and add to files if this doesn't conflict with existing files
|
|
188
|
+
// If a file already exists with the target name, skip this transformation to preserve original files
|
|
189
|
+
var existingFile = files.find(function (f) {
|
|
190
|
+
return f.name === transformedName;
|
|
192
191
|
});
|
|
192
|
+
if (!existingFile) {
|
|
193
|
+
filenameMap[fileName] = transformedName;
|
|
194
|
+
files.push({
|
|
195
|
+
name: transformedName,
|
|
196
|
+
originalName: fileName,
|
|
197
|
+
source: transformedSource,
|
|
198
|
+
component: toComponent(transformedSource)
|
|
199
|
+
});
|
|
200
|
+
} else {
|
|
201
|
+
// If there's a conflict, keep the original file untransformed
|
|
202
|
+
console.warn("Transform conflict: ".concat(fileName, " would transform to ").concat(transformedName, " but that name is already taken. Keeping original file untransformed."));
|
|
203
|
+
filenameMap[fileName] = fileName;
|
|
204
|
+
files.push({
|
|
205
|
+
name: fileName,
|
|
206
|
+
originalName: fileName,
|
|
207
|
+
source: source,
|
|
208
|
+
component: toComponent(source)
|
|
209
|
+
});
|
|
210
|
+
}
|
|
193
211
|
});
|
|
194
212
|
}
|
|
195
213
|
return {
|
|
@@ -365,6 +383,37 @@ export function useCode(contentProps, opts) {
|
|
|
365
383
|
}
|
|
366
384
|
}, [availableTransforms]);
|
|
367
385
|
|
|
386
|
+
// Create a wrapper for selectFileName that handles transformed filenames
|
|
387
|
+
var selectFileName = React.useCallback(function (fileName) {
|
|
388
|
+
if (!selectedVariant) {
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// If we have transformed files, we need to reverse-lookup the original filename
|
|
393
|
+
if (transformedFiles) {
|
|
394
|
+
// Check if the fileName is a transformed name - if so, find the original
|
|
395
|
+
var fileByTransformedName = transformedFiles.files.find(function (f) {
|
|
396
|
+
return f.name === fileName;
|
|
397
|
+
});
|
|
398
|
+
if (fileByTransformedName) {
|
|
399
|
+
setSelectedFileNameInternal(fileByTransformedName.originalName);
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// Check if the fileName is already an original name
|
|
404
|
+
var fileByOriginalName = transformedFiles.files.find(function (f) {
|
|
405
|
+
return f.originalName === fileName;
|
|
406
|
+
});
|
|
407
|
+
if (fileByOriginalName) {
|
|
408
|
+
setSelectedFileNameInternal(fileName);
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// If no transformed files or fileName not found, set directly (fallback for untransformed mode)
|
|
414
|
+
setSelectedFileNameInternal(fileName);
|
|
415
|
+
}, [selectedVariant, transformedFiles]);
|
|
416
|
+
|
|
368
417
|
// Get the effective components object - context overrides contentProps
|
|
369
418
|
// Components are kept separate from variant data to maintain clean separation of concerns
|
|
370
419
|
var effectiveComponents = React.useMemo(function () {
|
|
@@ -379,7 +428,7 @@ export function useCode(contentProps, opts) {
|
|
|
379
428
|
files: files,
|
|
380
429
|
selectedFile: selectedFileComponent,
|
|
381
430
|
selectedFileName: selectedFileName,
|
|
382
|
-
selectFileName:
|
|
431
|
+
selectFileName: selectFileName,
|
|
383
432
|
expanded: expanded,
|
|
384
433
|
expand: expand,
|
|
385
434
|
setExpanded: setExpanded,
|
package/useDemo/index.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export declare function useDemo(contentProps: ContentProps, opts?: UseDemoOpts):
|
|
|
25
25
|
}>;
|
|
26
26
|
selectedFile: React.ReactNode;
|
|
27
27
|
selectedFileName: string;
|
|
28
|
-
selectFileName:
|
|
28
|
+
selectFileName: (fileName: string) => void;
|
|
29
29
|
expanded: boolean;
|
|
30
30
|
expand: () => void;
|
|
31
31
|
setExpanded: React.Dispatch<React.SetStateAction<boolean>>;
|