@mui/internal-docs-infra 0.3.1-canary.3 → 0.3.1-canary.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/esm/CodeControllerContext/CodeControllerContext.js +2 -2
  2. package/esm/CodeExternalsContext/CodeExternalsContext.js +1 -1
  3. package/esm/CodeHighlighter/CodeHighlighter.js +247 -329
  4. package/esm/CodeHighlighter/CodeHighlighterClient.js +447 -653
  5. package/esm/CodeHighlighter/CodeHighlighterContext.js +2 -2
  6. package/esm/CodeHighlighter/CodeHighlighterFallbackContext.js +2 -2
  7. package/esm/CodeHighlighter/codeToFallbackProps.js +21 -37
  8. package/esm/CodeHighlighter/errors.js +248 -400
  9. package/esm/CodeHighlighter/parseControlledCode.js +12 -20
  10. package/esm/CodeProvider/CodeContext.js +3 -3
  11. package/esm/CodeProvider/CodeProvider.js +31 -40
  12. package/esm/abstractCreateDemo/abstractCreateDemo.js +13 -17
  13. package/esm/abstractCreateDemoClient/abstractCreateDemoClient.js +12 -12
  14. package/esm/cli/index.js +1 -1
  15. package/esm/cli/runValidate.js +160 -264
  16. package/esm/createDemoData/createDemoData.js +11 -12
  17. package/esm/createSitemap/createSitemap.js +2 -2
  18. package/esm/pipeline/getFileConventions/fileConventions.js +1 -1
  19. package/esm/pipeline/getFileConventions/getFileConventions.js +2 -15
  20. package/esm/pipeline/hastUtils/hastUtils.js +16 -17
  21. package/esm/pipeline/loadCodeVariant/addCodeVariantPaths.js +24 -24
  22. package/esm/pipeline/loadCodeVariant/applyCodeTransform.js +12 -22
  23. package/esm/pipeline/loadCodeVariant/calculateMainFilePath.js +30 -37
  24. package/esm/pipeline/loadCodeVariant/computeHastDeltas.js +107 -185
  25. package/esm/pipeline/loadCodeVariant/diffHast.js +18 -53
  26. package/esm/pipeline/loadCodeVariant/examineCodeVariant.js +24 -27
  27. package/esm/pipeline/loadCodeVariant/flattenCodeVariant.js +9 -10
  28. package/esm/pipeline/loadCodeVariant/hasAllCodeVariants.js +5 -5
  29. package/esm/pipeline/loadCodeVariant/loadCodeFallback.js +516 -731
  30. package/esm/pipeline/loadCodeVariant/loadCodeVariant.js +679 -1079
  31. package/esm/pipeline/loadCodeVariant/maybeCodeInitialData.js +14 -20
  32. package/esm/pipeline/loadCodeVariant/mergeCodeMetadata.js +53 -63
  33. package/esm/pipeline/loadCodeVariant/parseCode.js +40 -48
  34. package/esm/pipeline/loadCodeVariant/pathUtils.js +43 -64
  35. package/esm/pipeline/loadCodeVariant/transformSource.js +55 -125
  36. package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +160 -221
  37. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +377 -479
  38. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.js +171 -173
  39. package/esm/pipeline/loadPrecomputedCodeHighlighter/performanceLogger.js +14 -30
  40. package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +19 -21
  41. package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.js +37 -71
  42. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.js +3 -9
  43. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.js +54 -80
  44. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.js +71 -98
  45. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.js +5 -5
  46. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +161 -211
  47. package/esm/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.js +159 -207
  48. package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +42 -64
  49. package/esm/pipeline/loadServerCodeMeta/resolveModulePathWithFs.js +20 -96
  50. package/esm/pipeline/loadServerPageIndex/loadServerPageIndex.js +66 -85
  51. package/esm/pipeline/loadServerSitemap/loadServerSitemap.js +71 -118
  52. package/esm/pipeline/loadServerSource/loadServerSource.js +121 -148
  53. package/esm/pipeline/loaderUtils/externalsToPackages.js +7 -7
  54. package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +8 -12
  55. package/esm/pipeline/loaderUtils/fileUrlToPortablePath.js +5 -5
  56. package/esm/pipeline/loaderUtils/getFileNameFromUrl.js +19 -29
  57. package/esm/pipeline/loaderUtils/getLanguageFromExtension.js +3 -4
  58. package/esm/pipeline/loaderUtils/mergeExternals.js +15 -35
  59. package/esm/pipeline/loaderUtils/parseImportsAndComments.js +413 -433
  60. package/esm/pipeline/loaderUtils/processRelativeImports.js +153 -239
  61. package/esm/pipeline/loaderUtils/resolveModulePath.js +544 -1303
  62. package/esm/pipeline/loaderUtils/rewriteImports.js +73 -111
  63. package/esm/pipeline/parseSource/addLineGutters.js +33 -45
  64. package/esm/pipeline/parseSource/grammars.js +3 -3
  65. package/esm/pipeline/parseSource/parseSource.js +13 -31
  66. package/esm/pipeline/syncPageIndex/createMarkdownNodes.js +32 -55
  67. package/esm/pipeline/syncPageIndex/mergeMetadataMarkdown.js +107 -160
  68. package/esm/pipeline/syncPageIndex/metadataToMarkdown.js +846 -1033
  69. package/esm/pipeline/syncPageIndex/syncPageIndex.js +291 -438
  70. package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.js +213 -311
  71. package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.js +10 -10
  72. package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +133 -193
  73. package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.js +25 -27
  74. package/esm/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.js +572 -717
  75. package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.js +8 -8
  76. package/esm/pipeline/transformTypescriptToJavascript/removeTypes.js +84 -113
  77. package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.js +10 -26
  78. package/esm/useCode/Pre.js +58 -62
  79. package/esm/useCode/useCode.js +59 -61
  80. package/esm/useCode/useCodeUtils.js +54 -63
  81. package/esm/useCode/useCopyFunctionality.js +10 -9
  82. package/esm/useCode/useFileNavigation.js +150 -212
  83. package/esm/useCode/useSourceEditing.js +17 -14
  84. package/esm/useCode/useTransformManagement.js +23 -26
  85. package/esm/useCode/useUIState.js +12 -20
  86. package/esm/useCode/useVariantSelection.js +62 -79
  87. package/esm/useCopier/index.js +29 -56
  88. package/esm/useDemo/createCodeSandbox.js +12 -15
  89. package/esm/useDemo/createStackBlitz.js +14 -20
  90. package/esm/useDemo/exportVariant.js +200 -180
  91. package/esm/useDemo/exportVariantAsCra.js +22 -25
  92. package/esm/useDemo/useDemo.js +80 -84
  93. package/esm/useErrors/ErrorsContext.js +1 -1
  94. package/esm/useErrors/useErrors.js +3 -3
  95. package/esm/useLocalStorageState/useLocalStorageState.js +23 -39
  96. package/esm/usePreference/PreferencesProvider.js +1 -1
  97. package/esm/usePreference/usePreference.js +9 -11
  98. package/esm/useSearch/useSearch.js +290 -387
  99. package/esm/useUrlHashState/useUrlHashState.js +11 -14
  100. package/esm/withDocsInfra/withDeploymentConfig.js +26 -21
  101. package/esm/withDocsInfra/withDocsInfra.js +99 -101
  102. package/package.json +7 -4
@@ -1,6 +1,3 @@
1
- import _typeof from "@babel/runtime/helpers/esm/typeof";
2
- import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
3
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
1
  import * as React from 'react';
5
2
  import { decompressSync, strFromU8 } from 'fflate';
6
3
  import { decode } from 'uint8-to-base64';
@@ -19,11 +16,11 @@ function getLanguageFromFileName(fileName) {
19
16
  if (!fileName) {
20
17
  return undefined;
21
18
  }
22
- var lastDotIndex = fileName.lastIndexOf('.');
19
+ const lastDotIndex = fileName.lastIndexOf('.');
23
20
  if (lastDotIndex === -1) {
24
21
  return undefined;
25
22
  }
26
- var extension = fileName.substring(lastDotIndex);
23
+ const extension = fileName.substring(lastDotIndex);
27
24
  return getLanguageFromExtension(extension);
28
25
  }
29
26
 
@@ -49,8 +46,8 @@ export function isHashRelevantToDemo(urlHash, mainSlug) {
49
46
  if (!urlHash || !mainSlug) {
50
47
  return false;
51
48
  }
52
- var kebabSlug = toKebabCase(mainSlug);
53
- return urlHash.startsWith("".concat(kebabSlug, ":"));
49
+ const kebabSlug = toKebabCase(mainSlug);
50
+ return urlHash.startsWith(`${kebabSlug}:`);
54
51
  }
55
52
 
56
53
  /**
@@ -63,17 +60,17 @@ export function isHashRelevantToDemo(urlHash, mainSlug) {
63
60
  */
64
61
  function generateFileSlug(mainSlug, fileName, variantName) {
65
62
  // Extract base name from filename (strip extension)
66
- var lastDotIndex = fileName.lastIndexOf('.');
67
- var baseName = lastDotIndex !== -1 ? fileName.substring(0, lastDotIndex) : fileName;
68
- var extension = lastDotIndex !== -1 ? fileName.substring(lastDotIndex) : '';
63
+ const lastDotIndex = fileName.lastIndexOf('.');
64
+ const baseName = lastDotIndex !== -1 ? fileName.substring(0, lastDotIndex) : fileName;
65
+ const extension = lastDotIndex !== -1 ? fileName.substring(lastDotIndex) : '';
69
66
 
70
67
  // Convert to kebab-case
71
- var kebabMainSlug = toKebabCase(mainSlug);
72
- var kebabBaseName = toKebabCase(baseName);
73
- var kebabVariantName = toKebabCase(variantName);
68
+ const kebabMainSlug = toKebabCase(mainSlug);
69
+ const kebabBaseName = toKebabCase(baseName);
70
+ const kebabVariantName = toKebabCase(variantName);
74
71
 
75
72
  // Reconstruct filename with kebab-case base name but preserved extension
76
- var kebabFileName = "".concat(kebabBaseName).concat(extension);
73
+ const kebabFileName = `${kebabBaseName}${extension}`;
77
74
 
78
75
  // Handle empty main slug case
79
76
  if (!kebabMainSlug) {
@@ -83,95 +80,79 @@ function generateFileSlug(mainSlug, fileName, variantName) {
83
80
  // Format: mainSlug:fileName.ext (for Default variant) or mainSlug:variantName:fileName.ext
84
81
  // "Default" variant is treated specially and doesn't include variant name in hash
85
82
  if (variantName === 'Default') {
86
- return "".concat(kebabMainSlug, ":").concat(kebabFileName);
83
+ return `${kebabMainSlug}:${kebabFileName}`;
87
84
  }
88
- return "".concat(kebabMainSlug, ":").concat(kebabVariantName, ":").concat(kebabFileName);
85
+ return `${kebabMainSlug}:${kebabVariantName}:${kebabFileName}`;
89
86
  }
90
87
  /**
91
88
  * Hook for managing file selection and navigation within a code variant
92
89
  */
93
- export function useFileNavigation(_ref) {
94
- var selectedVariant = _ref.selectedVariant,
95
- transformedFiles = _ref.transformedFiles,
96
- _ref$mainSlug = _ref.mainSlug,
97
- mainSlug = _ref$mainSlug === void 0 ? '' : _ref$mainSlug,
98
- _ref$selectedVariantK = _ref.selectedVariantKey,
99
- selectedVariantKey = _ref$selectedVariantK === void 0 ? '' : _ref$selectedVariantK,
100
- _ref$variantKeys = _ref.variantKeys,
101
- variantKeys = _ref$variantKeys === void 0 ? [] : _ref$variantKeys,
102
- shouldHighlight = _ref.shouldHighlight,
103
- preClassName = _ref.preClassName,
104
- preRef = _ref.preRef,
105
- effectiveCode = _ref.effectiveCode,
106
- selectVariant = _ref.selectVariant,
107
- _ref$fileHashMode = _ref.fileHashMode,
108
- fileHashMode = _ref$fileHashMode === void 0 ? 'remove-hash' : _ref$fileHashMode,
109
- _ref$saveHashVariantT = _ref.saveHashVariantToLocalStorage,
110
- saveHashVariantToLocalStorage = _ref$saveHashVariantT === void 0 ? 'on-interaction' : _ref$saveHashVariantT,
111
- saveVariantToLocalStorage = _ref.saveVariantToLocalStorage,
112
- hashVariant = _ref.hashVariant;
90
+ export function useFileNavigation({
91
+ selectedVariant,
92
+ transformedFiles,
93
+ mainSlug = '',
94
+ selectedVariantKey = '',
95
+ variantKeys = [],
96
+ shouldHighlight,
97
+ preClassName,
98
+ preRef,
99
+ effectiveCode,
100
+ selectVariant,
101
+ fileHashMode = 'remove-hash',
102
+ saveHashVariantToLocalStorage = 'on-interaction',
103
+ saveVariantToLocalStorage,
104
+ hashVariant
105
+ }) {
113
106
  // Keep selectedFileName as untransformed filename for internal tracking
114
- var _React$useState = React.useState(selectedVariant == null ? void 0 : selectedVariant.fileName),
115
- _React$useState2 = _slicedToArray(_React$useState, 2),
116
- selectedFileNameInternal = _React$useState2[0],
117
- setSelectedFileNameInternal = _React$useState2[1];
107
+ const [selectedFileNameInternal, setSelectedFileNameInternal] = React.useState(selectedVariant?.fileName);
118
108
 
119
109
  // Use the simplified URL hash hook
120
- var _useUrlHashState = useUrlHashState(),
121
- _useUrlHashState2 = _slicedToArray(_useUrlHashState, 2),
122
- hash = _useUrlHashState2[0],
123
- setHash = _useUrlHashState2[1];
110
+ const [hash, setHash] = useUrlHashState();
124
111
 
125
112
  // Track if we're waiting for a variant switch to complete, and which file to select after
126
- var pendingFileSelection = React.useRef(null);
127
- var justCompletedPendingSelection = React.useRef(false);
113
+ const pendingFileSelection = React.useRef(null);
114
+ const justCompletedPendingSelection = React.useRef(false);
128
115
 
129
116
  // Track the previous variant key to detect user-initiated changes
130
- var prevVariantKeyRef = React.useRef(selectedVariantKey);
131
- var _React$useState3 = React.useState(selectedVariantKey),
132
- _React$useState4 = _slicedToArray(_React$useState3, 2),
133
- prevVariantKeyState = _React$useState4[0],
134
- setPrevVariantKeyState = _React$useState4[1];
135
- var isInitialMount = React.useRef(true);
117
+ const prevVariantKeyRef = React.useRef(selectedVariantKey);
118
+ const [prevVariantKeyState, setPrevVariantKeyState] = React.useState(selectedVariantKey);
119
+ const isInitialMount = React.useRef(true);
136
120
 
137
121
  // Detect if the current variant change was driven by a hash change
138
122
  // A variant change is hash-driven if the hash has a variant that matches where we're going
139
123
  // AND we weren't already on that variant (i.e., the hash is what triggered the change)
140
- var _React$useState5 = React.useState(hashVariant || null),
141
- _React$useState6 = _slicedToArray(_React$useState5, 2),
142
- prevHashVariant = _React$useState6[0],
143
- setPrevHashVariant = _React$useState6[1];
144
- var isHashDrivenVariantChange = hashVariant === selectedVariantKey && prevVariantKeyState !== selectedVariantKey;
124
+ const [prevHashVariant, setPrevHashVariant] = React.useState(hashVariant || null);
125
+ const isHashDrivenVariantChange = hashVariant === selectedVariantKey && prevVariantKeyState !== selectedVariantKey;
145
126
 
146
127
  // Update prevHashVariant when hashVariant changes
147
- React.useEffect(function () {
128
+ React.useEffect(() => {
148
129
  if (hashVariant !== prevHashVariant) {
149
130
  setPrevHashVariant(hashVariant || null);
150
131
  }
151
132
  }, [hashVariant, prevHashVariant]);
152
133
 
153
134
  // Update prevVariantKeyState when variant changes
154
- React.useEffect(function () {
135
+ React.useEffect(() => {
155
136
  if (selectedVariantKey !== prevVariantKeyState) {
156
137
  setPrevVariantKeyState(selectedVariantKey);
157
138
  }
158
139
  }, [selectedVariantKey, prevVariantKeyState]);
159
140
 
160
141
  // Helper function to check URL hash and switch to matching file
161
- var checkUrlHashAndSelectFile = React.useCallback(function () {
142
+ const checkUrlHashAndSelectFile = React.useCallback(() => {
162
143
  if (!hash) {
163
144
  return;
164
145
  }
165
146
 
166
147
  // Try to find matching file - check current variant first
167
- var matchingFileName;
168
- var matchingVariantKey;
148
+ let matchingFileName;
149
+ let matchingVariantKey;
169
150
 
170
151
  // Step 1: Check current variant (if we have one)
171
152
  if (selectedVariant) {
172
153
  // Check main file
173
154
  if (selectedVariant.fileName) {
174
- var mainFileSlug = generateFileSlug(mainSlug, selectedVariant.fileName, selectedVariantKey);
155
+ const mainFileSlug = generateFileSlug(mainSlug, selectedVariant.fileName, selectedVariantKey);
175
156
  if (hash === mainFileSlug) {
176
157
  matchingFileName = selectedVariant.fileName;
177
158
  matchingVariantKey = selectedVariantKey;
@@ -180,9 +161,8 @@ export function useFileNavigation(_ref) {
180
161
 
181
162
  // Check extra files
182
163
  if (!matchingFileName && selectedVariant.extraFiles) {
183
- for (var _i = 0, _Object$keys = Object.keys(selectedVariant.extraFiles); _i < _Object$keys.length; _i++) {
184
- var fileName = _Object$keys[_i];
185
- var fileSlug = generateFileSlug(mainSlug, fileName, selectedVariantKey);
164
+ for (const fileName of Object.keys(selectedVariant.extraFiles)) {
165
+ const fileSlug = generateFileSlug(mainSlug, fileName, selectedVariantKey);
186
166
  if (hash === fileSlug) {
187
167
  matchingFileName = fileName;
188
168
  matchingVariantKey = selectedVariantKey;
@@ -193,32 +173,20 @@ export function useFileNavigation(_ref) {
193
173
 
194
174
  // Check transformed files
195
175
  if (!matchingFileName && transformedFiles) {
196
- var _iterator = _createForOfIteratorHelper(transformedFiles.files),
197
- _step;
198
- try {
199
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
200
- var file = _step.value;
201
- var _fileSlug = generateFileSlug(mainSlug, file.originalName, selectedVariantKey);
202
- if (hash === _fileSlug) {
203
- matchingFileName = file.originalName;
204
- matchingVariantKey = selectedVariantKey;
205
- break;
206
- }
176
+ for (const file of transformedFiles.files) {
177
+ const fileSlug = generateFileSlug(mainSlug, file.originalName, selectedVariantKey);
178
+ if (hash === fileSlug) {
179
+ matchingFileName = file.originalName;
180
+ matchingVariantKey = selectedVariantKey;
181
+ break;
207
182
  }
208
- } catch (err) {
209
- _iterator.e(err);
210
- } finally {
211
- _iterator.f();
212
183
  }
213
184
  }
214
185
  }
215
186
 
216
187
  // Step 2: If no match and we can switch variants, search other variants
217
188
  if (!matchingFileName && effectiveCode && selectVariant) {
218
- for (var _i2 = 0, _Object$entries = Object.entries(effectiveCode); _i2 < _Object$entries.length; _i2++) {
219
- var _Object$entries$_i = _slicedToArray(_Object$entries[_i2], 2),
220
- variantKey = _Object$entries$_i[0],
221
- variant = _Object$entries$_i[1];
189
+ for (const [variantKey, variant] of Object.entries(effectiveCode)) {
222
190
  // Skip current variant (already checked) and invalid variants
223
191
  if (variantKey === selectedVariantKey || !variant || typeof variant === 'string') {
224
192
  continue;
@@ -226,8 +194,8 @@ export function useFileNavigation(_ref) {
226
194
 
227
195
  // Check main file
228
196
  if (variant.fileName) {
229
- var _mainFileSlug = generateFileSlug(mainSlug, variant.fileName, variantKey);
230
- if (hash === _mainFileSlug) {
197
+ const mainFileSlug = generateFileSlug(mainSlug, variant.fileName, variantKey);
198
+ if (hash === mainFileSlug) {
231
199
  matchingFileName = variant.fileName;
232
200
  matchingVariantKey = variantKey;
233
201
  break;
@@ -236,11 +204,10 @@ export function useFileNavigation(_ref) {
236
204
 
237
205
  // Check extra files
238
206
  if (!matchingFileName && variant.extraFiles) {
239
- for (var _i3 = 0, _Object$keys2 = Object.keys(variant.extraFiles); _i3 < _Object$keys2.length; _i3++) {
240
- var _fileName = _Object$keys2[_i3];
241
- var _fileSlug2 = generateFileSlug(mainSlug, _fileName, variantKey);
242
- if (hash === _fileSlug2) {
243
- matchingFileName = _fileName;
207
+ for (const fileName of Object.keys(variant.extraFiles)) {
208
+ const fileSlug = generateFileSlug(mainSlug, fileName, variantKey);
209
+ if (hash === fileSlug) {
210
+ matchingFileName = fileName;
244
211
  matchingVariantKey = variantKey;
245
212
  break;
246
213
  }
@@ -268,14 +235,14 @@ export function useFileNavigation(_ref) {
268
235
  }, [hash, selectedVariant, selectedVariantKey, mainSlug, transformedFiles, effectiveCode, selectVariant]);
269
236
 
270
237
  // Run hash check when URL hash changes to select the matching file
271
- React.useEffect(function () {
238
+ React.useEffect(() => {
272
239
  checkUrlHashAndSelectFile();
273
240
  }, [checkUrlHashAndSelectFile]);
274
241
 
275
242
  // When variant switches with a pending file selection, complete the file selection
276
- React.useEffect(function () {
243
+ React.useEffect(() => {
277
244
  if (pendingFileSelection.current && selectedVariant) {
278
- var fileToSelect = pendingFileSelection.current;
245
+ const fileToSelect = pendingFileSelection.current;
279
246
  pendingFileSelection.current = null;
280
247
  justCompletedPendingSelection.current = true;
281
248
  setSelectedFileNameInternal(fileToSelect);
@@ -285,7 +252,7 @@ export function useFileNavigation(_ref) {
285
252
  }, [selectedVariantKey, selectedVariant]);
286
253
 
287
254
  // Reset selectedFileName when variant changes
288
- React.useEffect(function () {
255
+ React.useEffect(() => {
289
256
  // Skip reset if we have a pending file selection from hash navigation
290
257
  // OR if we just completed a pending file selection
291
258
  if (pendingFileSelection.current || justCompletedPendingSelection.current) {
@@ -293,7 +260,7 @@ export function useFileNavigation(_ref) {
293
260
  }
294
261
  if (selectedVariant && selectedFileNameInternal !== selectedVariant.fileName) {
295
262
  // Only reset if current selectedFileName doesn't exist in the new variant
296
- var hasFile = selectedVariant.fileName === selectedFileNameInternal || selectedFileNameInternal && selectedVariant.extraFiles && selectedVariant.extraFiles[selectedFileNameInternal];
263
+ const hasFile = selectedVariant.fileName === selectedFileNameInternal || selectedFileNameInternal && selectedVariant.extraFiles && selectedVariant.extraFiles[selectedFileNameInternal];
297
264
  if (!hasFile) {
298
265
  setSelectedFileNameInternal(selectedVariant.fileName);
299
266
  }
@@ -301,7 +268,7 @@ export function useFileNavigation(_ref) {
301
268
  }, [selectedVariant, selectedFileNameInternal]);
302
269
 
303
270
  // Update hash when variant changes (user-initiated variant switch)
304
- React.useEffect(function () {
271
+ React.useEffect(() => {
305
272
  // Skip on initial mount - let hash-driven navigation handle it
306
273
  if (isInitialMount.current) {
307
274
  isInitialMount.current = false;
@@ -330,12 +297,12 @@ export function useFileNavigation(_ref) {
330
297
  // Note: localStorage is already saved by setSelectedVariantKeyAsUser
331
298
  if (fileHashMode === 'remove-filename') {
332
299
  // Keep variant in hash: mainSlug or mainSlug:variant (for non-Default variants)
333
- var kebabMainSlug = toKebabCase(mainSlug);
300
+ const kebabMainSlug = toKebabCase(mainSlug);
334
301
  if (selectedVariantKey === 'Default') {
335
302
  setHash(kebabMainSlug);
336
303
  } else {
337
- var kebabVariantName = toKebabCase(selectedVariantKey);
338
- setHash("".concat(kebabMainSlug, ":").concat(kebabVariantName));
304
+ const kebabVariantName = toKebabCase(selectedVariantKey);
305
+ setHash(`${kebabMainSlug}:${kebabVariantName}`);
339
306
  }
340
307
  } else {
341
308
  // Remove entire hash
@@ -345,71 +312,63 @@ export function useFileNavigation(_ref) {
345
312
  }, [selectedVariantKey, hash, mainSlug, fileHashMode, setHash, isHashDrivenVariantChange]);
346
313
 
347
314
  // Compute the displayed filename (transformed if applicable)
348
- var selectedFileName = React.useMemo(function () {
315
+ const selectedFileName = React.useMemo(() => {
349
316
  if (!selectedVariant) {
350
317
  return undefined;
351
318
  }
352
319
 
353
320
  // If selectedFileNameInternal is undefined, we're selecting the main file
354
- var effectiveFileName = selectedFileNameInternal || selectedVariant.fileName;
321
+ const effectiveFileName = selectedFileNameInternal || selectedVariant.fileName;
355
322
  if (!effectiveFileName) {
356
323
  return undefined;
357
324
  }
358
325
 
359
326
  // If we have transformed files, return the transformed name
360
327
  if (transformedFiles) {
361
- var file = transformedFiles.files.find(function (f) {
362
- return f.originalName === effectiveFileName;
363
- });
328
+ const file = transformedFiles.files.find(f => f.originalName === effectiveFileName);
364
329
  return file ? file.name : effectiveFileName;
365
330
  }
366
331
 
367
332
  // Otherwise, return the original filename
368
333
  return effectiveFileName;
369
334
  }, [selectedVariant, selectedFileNameInternal, transformedFiles]);
370
- var selectedFile = React.useMemo(function () {
335
+ const selectedFile = React.useMemo(() => {
371
336
  if (!selectedVariant) {
372
337
  return null;
373
338
  }
374
339
 
375
340
  // If we have transformed files, use them
376
341
  if (transformedFiles) {
377
- var effectiveFileName = selectedFileNameInternal || selectedVariant.fileName;
378
- var file = transformedFiles.files.find(function (f) {
379
- return f.originalName === effectiveFileName;
380
- });
342
+ const effectiveFileName = selectedFileNameInternal || selectedVariant.fileName;
343
+ const file = transformedFiles.files.find(f => f.originalName === effectiveFileName);
381
344
  return file ? file.source : null;
382
345
  }
383
346
 
384
347
  // Otherwise, use the original untransformed files
385
348
  if (selectedFileNameInternal === selectedVariant.fileName || !selectedFileNameInternal) {
386
- var _selectedVariant$sour;
387
- return (_selectedVariant$sour = selectedVariant.source) != null ? _selectedVariant$sour : null;
349
+ return selectedVariant.source ?? null;
388
350
  }
389
351
 
390
352
  // Look in extraFiles
391
353
  if (selectedFileNameInternal && selectedVariant.extraFiles && selectedVariant.extraFiles[selectedFileNameInternal]) {
392
- var extraFile = selectedVariant.extraFiles[selectedFileNameInternal];
354
+ const extraFile = selectedVariant.extraFiles[selectedFileNameInternal];
393
355
  if (typeof extraFile === 'string') {
394
356
  return extraFile;
395
357
  }
396
- if (extraFile && _typeof(extraFile) === 'object' && 'source' in extraFile) {
397
- var _extraFile$source;
398
- return (_extraFile$source = extraFile.source) != null ? _extraFile$source : null;
358
+ if (extraFile && typeof extraFile === 'object' && 'source' in extraFile) {
359
+ return extraFile.source ?? null;
399
360
  }
400
361
  }
401
362
  return null;
402
363
  }, [selectedVariant, selectedFileNameInternal, transformedFiles]);
403
- var selectedFileComponent = React.useMemo(function () {
364
+ const selectedFileComponent = React.useMemo(() => {
404
365
  if (!selectedVariant) {
405
366
  return null;
406
367
  }
407
368
 
408
369
  // If we have transformed files, use them
409
370
  if (transformedFiles) {
410
- var file = transformedFiles.files.find(function (f) {
411
- return f.originalName === selectedFileNameInternal;
412
- });
371
+ const file = transformedFiles.files.find(f => f.originalName === selectedFileNameInternal);
413
372
  return file ? file.component : null;
414
373
  }
415
374
 
@@ -429,11 +388,11 @@ export function useFileNavigation(_ref) {
429
388
 
430
389
  // Look in extraFiles
431
390
  if (selectedFileNameInternal && selectedVariant.extraFiles && selectedVariant.extraFiles[selectedFileNameInternal]) {
432
- var extraFile = selectedVariant.extraFiles[selectedFileNameInternal];
433
- var source;
391
+ const extraFile = selectedVariant.extraFiles[selectedFileNameInternal];
392
+ let source;
434
393
  if (typeof extraFile === 'string') {
435
394
  source = extraFile;
436
- } else if (extraFile && _typeof(extraFile) === 'object' && 'source' in extraFile) {
395
+ } else if (extraFile && typeof extraFile === 'object' && 'source' in extraFile) {
437
396
  source = extraFile.source;
438
397
  } else {
439
398
  return null;
@@ -451,7 +410,7 @@ export function useFileNavigation(_ref) {
451
410
  }
452
411
  return null;
453
412
  }, [selectedVariant, selectedFileNameInternal, transformedFiles, shouldHighlight, preClassName, preRef]);
454
- var selectedFileLines = React.useMemo(function () {
413
+ const selectedFileLines = React.useMemo(() => {
455
414
  if (selectedFile == null) {
456
415
  return 0;
457
416
  }
@@ -462,8 +421,8 @@ export function useFileNavigation(_ref) {
462
421
  }
463
422
 
464
423
  // If it's a hast object, count the children length
465
- if (selectedFile && _typeof(selectedFile) === 'object') {
466
- var hastSelectedFile;
424
+ if (selectedFile && typeof selectedFile === 'object') {
425
+ let hastSelectedFile;
467
426
  if ('hastJson' in selectedFile) {
468
427
  hastSelectedFile = JSON.parse(selectedFile.hastJson);
469
428
  } else if ('hastGzip' in selectedFile) {
@@ -472,10 +431,10 @@ export function useFileNavigation(_ref) {
472
431
  hastSelectedFile = selectedFile;
473
432
  }
474
433
  if (hastSelectedFile.data && 'totalLines' in hastSelectedFile.data) {
475
- var totalLines = hastSelectedFile.data.totalLines;
434
+ const totalLines = hastSelectedFile.data.totalLines;
476
435
  // Check if totalLines is a valid number (not null, undefined, or NaN)
477
436
  if (totalLines != null && !Number.isNaN(Number(totalLines))) {
478
- var numLines = Number(totalLines);
437
+ const numLines = Number(totalLines);
479
438
  if (numLines >= 0) {
480
439
  return numLines;
481
440
  }
@@ -491,24 +450,22 @@ export function useFileNavigation(_ref) {
491
450
  }, [selectedFile]);
492
451
 
493
452
  // Convert files for the return interface
494
- var files = React.useMemo(function () {
453
+ const files = React.useMemo(() => {
495
454
  if (!selectedVariant) {
496
455
  return [];
497
456
  }
498
457
 
499
458
  // If we have transformed files, use them
500
459
  if (transformedFiles) {
501
- return transformedFiles.files.map(function (f) {
502
- return {
503
- name: f.name,
504
- slug: generateFileSlug(mainSlug, f.originalName, selectedVariantKey),
505
- component: f.component
506
- };
507
- });
460
+ return transformedFiles.files.map(f => ({
461
+ name: f.name,
462
+ slug: generateFileSlug(mainSlug, f.originalName, selectedVariantKey),
463
+ component: f.component
464
+ }));
508
465
  }
509
466
 
510
467
  // Otherwise, create files from original untransformed data
511
- var result = [];
468
+ const result = [];
512
469
 
513
470
  // Only add main file if it has a fileName
514
471
  if (selectedVariant.fileName && selectedVariant.source) {
@@ -525,15 +482,12 @@ export function useFileNavigation(_ref) {
525
482
  });
526
483
  }
527
484
  if (selectedVariant.extraFiles) {
528
- Object.entries(selectedVariant.extraFiles).forEach(function (_ref2) {
529
- var _ref3 = _slicedToArray(_ref2, 2),
530
- fileName = _ref3[0],
531
- fileData = _ref3[1];
532
- var source;
533
- var language;
485
+ Object.entries(selectedVariant.extraFiles).forEach(([fileName, fileData]) => {
486
+ let source;
487
+ let language;
534
488
  if (typeof fileData === 'string') {
535
489
  source = fileData;
536
- } else if (fileData && _typeof(fileData) === 'object' && 'source' in fileData) {
490
+ } else if (fileData && typeof fileData === 'object' && 'source' in fileData) {
537
491
  source = fileData.source;
538
492
  language = fileData.language;
539
493
  } else {
@@ -547,7 +501,7 @@ export function useFileNavigation(_ref) {
547
501
  slug: generateFileSlug(mainSlug, fileName, selectedVariantKey),
548
502
  component: /*#__PURE__*/_jsx(Pre, {
549
503
  className: preClassName,
550
- language: language != null ? language : getLanguageFromFileName(fileName),
504
+ language: language ?? getLanguageFromFileName(fileName),
551
505
  ref: preRef,
552
506
  shouldHighlight: shouldHighlight,
553
507
  children: source
@@ -559,25 +513,21 @@ export function useFileNavigation(_ref) {
559
513
  }, [selectedVariant, transformedFiles, mainSlug, selectedVariantKey, shouldHighlight, preClassName, preRef]);
560
514
 
561
515
  // Create a wrapper for selectFileName that handles transformed filenames and URL updates
562
- var selectFileName = React.useCallback(function (fileName) {
516
+ const selectFileName = React.useCallback(fileName => {
563
517
  if (!selectedVariant) {
564
518
  return;
565
519
  }
566
- var targetFileName = fileName;
520
+ let targetFileName = fileName;
567
521
 
568
522
  // If we have transformed files, we need to reverse-lookup the original filename
569
523
  if (transformedFiles) {
570
524
  // Check if the fileName is a transformed name - if so, find the original
571
- var fileByTransformedName = transformedFiles.files.find(function (f) {
572
- return f.name === fileName;
573
- });
525
+ const fileByTransformedName = transformedFiles.files.find(f => f.name === fileName);
574
526
  if (fileByTransformedName) {
575
527
  targetFileName = fileByTransformedName.originalName;
576
528
  } else {
577
529
  // Check if the fileName is already an original name
578
- var fileByOriginalName = transformedFiles.files.find(function (f) {
579
- return f.originalName === fileName;
580
- });
530
+ const fileByOriginalName = transformedFiles.files.find(f => f.originalName === fileName);
581
531
  if (fileByOriginalName) {
582
532
  targetFileName = fileName;
583
533
  }
@@ -592,12 +542,12 @@ export function useFileNavigation(_ref) {
592
542
  }
593
543
  if (fileHashMode === 'remove-filename') {
594
544
  // Keep variant in hash: mainSlug or mainSlug:variant (for non-Default variants)
595
- var kebabMainSlug = toKebabCase(mainSlug);
545
+ const kebabMainSlug = toKebabCase(mainSlug);
596
546
  if (selectedVariantKey === 'Default') {
597
547
  setHash(kebabMainSlug);
598
548
  } else {
599
- var kebabVariantName = toKebabCase(selectedVariantKey);
600
- setHash("".concat(kebabMainSlug, ":").concat(kebabVariantName));
549
+ const kebabVariantName = toKebabCase(selectedVariantKey);
550
+ setHash(`${kebabMainSlug}:${kebabVariantName}`);
601
551
  }
602
552
  } else {
603
553
  // Remove entire hash
@@ -608,75 +558,63 @@ export function useFileNavigation(_ref) {
608
558
  }, [selectedVariant, transformedFiles, mainSlug, selectedVariantKey, fileHashMode, hash, setHash, saveHashVariantToLocalStorage, saveVariantToLocalStorage]);
609
559
 
610
560
  // Memoized array of all file slugs for all variants
611
- var allFilesSlugs = React.useMemo(function () {
612
- var result = [];
561
+ const allFilesSlugs = React.useMemo(() => {
562
+ const result = [];
613
563
  if (!effectiveCode || !variantKeys.length) {
614
564
  return result;
615
565
  }
616
566
 
617
567
  // Iterate through all variants
618
- var _iterator2 = _createForOfIteratorHelper(variantKeys),
619
- _step2;
620
- try {
621
- var _loop = function _loop() {
622
- var variantKey = _step2.value;
623
- var variant = effectiveCode[variantKey];
624
-
625
- // Skip invalid variants
626
- if (!variant || typeof variant === 'string') {
627
- return 1; // continue
628
- }
568
+ for (const variantKey of variantKeys) {
569
+ const variant = effectiveCode[variantKey];
629
570
 
630
- // Add variant-only slug (points to main file of the variant)
631
- // Skip for Default variant since it doesn't have variant name in hash
632
- if (variant.fileName && variantKey !== 'Default') {
633
- var kebabMainSlug = toKebabCase(mainSlug);
634
- var kebabVariantName = toKebabCase(variantKey);
635
- var variantOnlySlug = "".concat(kebabMainSlug, ":").concat(kebabVariantName);
636
- result.push({
637
- fileName: variant.fileName,
638
- slug: variantOnlySlug,
639
- variantName: variantKey
640
- });
641
- }
571
+ // Skip invalid variants
572
+ if (!variant || typeof variant === 'string') {
573
+ continue;
574
+ }
642
575
 
643
- // Add main file if it exists
644
- if (variant.fileName) {
576
+ // Add variant-only slug (points to main file of the variant)
577
+ // Skip for Default variant since it doesn't have variant name in hash
578
+ if (variant.fileName && variantKey !== 'Default') {
579
+ const kebabMainSlug = toKebabCase(mainSlug);
580
+ const kebabVariantName = toKebabCase(variantKey);
581
+ const variantOnlySlug = `${kebabMainSlug}:${kebabVariantName}`;
582
+ result.push({
583
+ fileName: variant.fileName,
584
+ slug: variantOnlySlug,
585
+ variantName: variantKey
586
+ });
587
+ }
588
+
589
+ // Add main file if it exists
590
+ if (variant.fileName) {
591
+ result.push({
592
+ fileName: variant.fileName,
593
+ slug: generateFileSlug(mainSlug, variant.fileName, variantKey),
594
+ variantName: variantKey
595
+ });
596
+ }
597
+
598
+ // Add extra files
599
+ if (variant.extraFiles) {
600
+ Object.keys(variant.extraFiles).forEach(fileName => {
645
601
  result.push({
646
- fileName: variant.fileName,
647
- slug: generateFileSlug(mainSlug, variant.fileName, variantKey),
602
+ fileName,
603
+ slug: generateFileSlug(mainSlug, fileName, variantKey),
648
604
  variantName: variantKey
649
605
  });
650
- }
651
-
652
- // Add extra files
653
- if (variant.extraFiles) {
654
- Object.keys(variant.extraFiles).forEach(function (fileName) {
655
- result.push({
656
- fileName: fileName,
657
- slug: generateFileSlug(mainSlug, fileName, variantKey),
658
- variantName: variantKey
659
- });
660
- });
661
- }
662
- };
663
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
664
- if (_loop()) continue;
606
+ });
665
607
  }
666
- } catch (err) {
667
- _iterator2.e(err);
668
- } finally {
669
- _iterator2.f();
670
608
  }
671
609
  return result;
672
610
  }, [effectiveCode, variantKeys, mainSlug]);
673
611
  return {
674
- selectedFileName: selectedFileName,
675
- selectedFile: selectedFile,
676
- selectedFileComponent: selectedFileComponent,
677
- selectedFileLines: selectedFileLines,
678
- files: files,
679
- allFilesSlugs: allFilesSlugs,
680
- selectFileName: selectFileName
612
+ selectedFileName,
613
+ selectedFile,
614
+ selectedFileComponent,
615
+ selectedFileLines,
616
+ files,
617
+ allFilesSlugs,
618
+ selectFileName
681
619
  };
682
620
  }