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