@mui/internal-docs-infra 0.3.1-canary.3 → 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 +247 -329
- 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/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 +516 -731
- package/esm/pipeline/loadCodeVariant/loadCodeVariant.js +679 -1079
- 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.js +3 -4
- 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.js +3 -3
- package/esm/pipeline/parseSource/parseSource.js +13 -31
- 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 +213 -311
- package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.js +10 -10
- package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +133 -193
- 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.js +58 -62
- 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 +150 -212
- 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,4 +1,3 @@
|
|
|
1
|
-
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
2
1
|
import { hasAllVariants } from "./hasAllCodeVariants.js";
|
|
3
2
|
/**
|
|
4
3
|
* Type guard function that determines if we have sufficient data to render a code highlighter
|
|
@@ -98,10 +97,7 @@ import { hasAllVariants } from "./hasAllCodeVariants.js";
|
|
|
98
97
|
* }, [initialData, reason, ...]);
|
|
99
98
|
* ```
|
|
100
99
|
*/
|
|
101
|
-
export function maybeCodeInitialData(variants, variant, code, fileName) {
|
|
102
|
-
var needsHighlight = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
103
|
-
var needsAllFiles = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
|
|
104
|
-
var needsAllVariants = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
|
|
100
|
+
export function maybeCodeInitialData(variants, variant, code, fileName, needsHighlight = false, needsAllFiles = false, needsAllVariants = false) {
|
|
105
101
|
if (!code) {
|
|
106
102
|
return {
|
|
107
103
|
initialData: false,
|
|
@@ -114,7 +110,7 @@ export function maybeCodeInitialData(variants, variant, code, fileName) {
|
|
|
114
110
|
reason: 'Not all variants are available'
|
|
115
111
|
};
|
|
116
112
|
}
|
|
117
|
-
|
|
113
|
+
const variantCode = code[variant];
|
|
118
114
|
if (!variantCode || typeof variantCode === 'string') {
|
|
119
115
|
return {
|
|
120
116
|
initialData: false,
|
|
@@ -134,10 +130,9 @@ export function maybeCodeInitialData(variants, variant, code, fileName) {
|
|
|
134
130
|
reason: 'Variant source not found'
|
|
135
131
|
};
|
|
136
132
|
}
|
|
137
|
-
if (variantCode.extraFiles && !Object.keys(variantCode.extraFiles).every(
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
return _typeof(fileData) === 'object' && (fileData == null ? void 0 : fileData.source) !== undefined;
|
|
133
|
+
if (variantCode.extraFiles && !Object.keys(variantCode.extraFiles).every(file => {
|
|
134
|
+
const fileData = variantCode.extraFiles?.[file];
|
|
135
|
+
return typeof fileData === 'object' && fileData?.source !== undefined;
|
|
141
136
|
})) {
|
|
142
137
|
return {
|
|
143
138
|
initialData: false,
|
|
@@ -147,22 +142,21 @@ export function maybeCodeInitialData(variants, variant, code, fileName) {
|
|
|
147
142
|
}
|
|
148
143
|
|
|
149
144
|
// TODO, filename might need to be determined from filesOrder if provided?
|
|
150
|
-
|
|
151
|
-
|
|
145
|
+
const initialFilename = fileName || variantCode.fileName;
|
|
146
|
+
let fileSource;
|
|
152
147
|
if (fileName && fileName !== variantCode.fileName) {
|
|
153
|
-
|
|
154
|
-
var fileData = variantCode == null || (_variantCode$extraFil2 = variantCode.extraFiles) == null ? void 0 : _variantCode$extraFil2[fileName];
|
|
148
|
+
const fileData = variantCode?.extraFiles?.[fileName];
|
|
155
149
|
if (!fileData) {
|
|
156
150
|
return {
|
|
157
151
|
initialData: false,
|
|
158
|
-
reason:
|
|
152
|
+
reason: `File not found in code`
|
|
159
153
|
};
|
|
160
154
|
}
|
|
161
155
|
if (typeof fileData === 'string') {
|
|
162
156
|
// It's a URL, not actual source content
|
|
163
157
|
return {
|
|
164
158
|
initialData: false,
|
|
165
|
-
reason:
|
|
159
|
+
reason: `File is not loaded yet`
|
|
166
160
|
};
|
|
167
161
|
}
|
|
168
162
|
fileSource = fileData.source;
|
|
@@ -172,7 +166,7 @@ export function maybeCodeInitialData(variants, variant, code, fileName) {
|
|
|
172
166
|
if (!fileSource) {
|
|
173
167
|
return {
|
|
174
168
|
initialData: false,
|
|
175
|
-
reason:
|
|
169
|
+
reason: `File source not found`
|
|
176
170
|
};
|
|
177
171
|
}
|
|
178
172
|
if (needsHighlight && typeof fileSource === 'string') {
|
|
@@ -183,10 +177,10 @@ export function maybeCodeInitialData(variants, variant, code, fileName) {
|
|
|
183
177
|
}
|
|
184
178
|
return {
|
|
185
179
|
initialData: {
|
|
186
|
-
code
|
|
187
|
-
initialFilename
|
|
180
|
+
code,
|
|
181
|
+
initialFilename,
|
|
188
182
|
initialSource: fileSource,
|
|
189
|
-
initialExtraFiles: variantCode
|
|
183
|
+
initialExtraFiles: variantCode?.extraFiles
|
|
190
184
|
}
|
|
191
185
|
};
|
|
192
186
|
}
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
-
var _excluded = ["metadata"];
|
|
5
1
|
/**
|
|
6
2
|
* Metadata merging utility for positioning metadata files relative to source files
|
|
7
3
|
*/
|
|
@@ -27,86 +23,83 @@ import { calculateMaxSourceBackNavigation, removeBackNavigationPrefix, buildPath
|
|
|
27
23
|
* @returns An object with the cleaned variant and extracted metadata
|
|
28
24
|
*/
|
|
29
25
|
export function extractCodeMetadata(variant) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
const {
|
|
27
|
+
metadataPrefix
|
|
28
|
+
} = variant;
|
|
29
|
+
const extractedMetadata = {};
|
|
30
|
+
const nonMetadataFiles = {};
|
|
33
31
|
if (!variant.extraFiles) {
|
|
34
32
|
return {
|
|
35
|
-
variant:
|
|
33
|
+
variant: {
|
|
34
|
+
...variant,
|
|
36
35
|
extraFiles: {}
|
|
37
|
-
}
|
|
36
|
+
},
|
|
38
37
|
metadata: {}
|
|
39
38
|
};
|
|
40
39
|
}
|
|
41
40
|
|
|
42
41
|
// Calculate how much back navigation to remove using pathUtils
|
|
43
|
-
|
|
42
|
+
let backLevelsToRemove = calculateMaxSourceBackNavigation(variant.extraFiles || {});
|
|
44
43
|
if (metadataPrefix) {
|
|
45
44
|
// Add metadataPrefix levels if present
|
|
46
45
|
backLevelsToRemove += splitPath(metadataPrefix).length;
|
|
47
46
|
}
|
|
48
47
|
|
|
49
48
|
// Process all extraFiles
|
|
50
|
-
for (
|
|
51
|
-
|
|
52
|
-
relativePath = _Object$entries$_i[0],
|
|
53
|
-
fileContent = _Object$entries$_i[1];
|
|
54
|
-
var file = typeof fileContent === 'string' ? {
|
|
49
|
+
for (const [relativePath, fileContent] of Object.entries(variant.extraFiles)) {
|
|
50
|
+
const file = typeof fileContent === 'string' ? {
|
|
55
51
|
source: fileContent
|
|
56
52
|
} : fileContent;
|
|
57
53
|
if (file.metadata) {
|
|
58
|
-
|
|
54
|
+
const scopedPath = removeBackNavigationPrefix(relativePath, backLevelsToRemove);
|
|
59
55
|
|
|
60
56
|
// Remove metadata flag when extracting
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
const {
|
|
58
|
+
metadata: metadataFlag,
|
|
59
|
+
...cleanFile
|
|
60
|
+
} = file;
|
|
63
61
|
extractedMetadata[scopedPath] = cleanFile;
|
|
64
62
|
} else {
|
|
65
63
|
nonMetadataFiles[relativePath] = file;
|
|
66
64
|
}
|
|
67
65
|
}
|
|
68
66
|
return {
|
|
69
|
-
variant:
|
|
67
|
+
variant: {
|
|
68
|
+
...variant,
|
|
70
69
|
extraFiles: nonMetadataFiles
|
|
71
|
-
}
|
|
70
|
+
},
|
|
72
71
|
metadata: extractedMetadata
|
|
73
72
|
};
|
|
74
73
|
}
|
|
75
|
-
export function mergeCodeMetadata(variant) {
|
|
76
|
-
var _options$metadataPref;
|
|
77
|
-
var metadataFiles = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
78
|
-
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
74
|
+
export function mergeCodeMetadata(variant, metadataFiles = {}, options = {}) {
|
|
79
75
|
// Determine which metadataPrefix to use
|
|
80
|
-
|
|
76
|
+
const targetMetadataPrefix = options.metadataPrefix ?? variant.metadataPrefix;
|
|
81
77
|
|
|
82
78
|
// Check if we need to re-extract metadata due to metadataPrefix change
|
|
83
|
-
|
|
79
|
+
const needsReextraction = options.metadataPrefix !== undefined && options.metadataPrefix !== variant.metadataPrefix;
|
|
84
80
|
|
|
85
81
|
// If metadataPrefix is changing, extract existing metadata and reposition everything
|
|
86
|
-
|
|
87
|
-
|
|
82
|
+
let workingVariant = variant;
|
|
83
|
+
let existingMetadata = {};
|
|
88
84
|
if (needsReextraction && variant.extraFiles) {
|
|
89
85
|
// Extract existing metadata using the old metadataPrefix
|
|
90
|
-
|
|
86
|
+
const extracted = extractCodeMetadata(variant);
|
|
91
87
|
workingVariant = extracted.variant;
|
|
92
88
|
existingMetadata = extracted.metadata;
|
|
93
89
|
}
|
|
94
90
|
|
|
95
91
|
// Calculate the positioning level for metadata files
|
|
96
|
-
|
|
92
|
+
const metadataBackNavigation = calculateMetadataBackNavigation(workingVariant.extraFiles, targetMetadataPrefix);
|
|
97
93
|
|
|
98
94
|
// Collect all metadata files that need positioning
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
95
|
+
const allMetadataFiles = {};
|
|
96
|
+
const nonMetadataFiles = {};
|
|
97
|
+
const positionedMetadataFiles = {};
|
|
102
98
|
|
|
103
99
|
// Process existing extraFiles from working variant
|
|
104
100
|
if (workingVariant.extraFiles) {
|
|
105
|
-
for (
|
|
106
|
-
|
|
107
|
-
relativePath = _Object$entries2$_i[0],
|
|
108
|
-
fileContent = _Object$entries2$_i[1];
|
|
109
|
-
var file = typeof fileContent === 'string' ? {
|
|
101
|
+
for (const [relativePath, fileContent] of Object.entries(workingVariant.extraFiles)) {
|
|
102
|
+
const file = typeof fileContent === 'string' ? {
|
|
110
103
|
source: fileContent
|
|
111
104
|
} : fileContent;
|
|
112
105
|
if (file.metadata) {
|
|
@@ -124,42 +117,39 @@ export function mergeCodeMetadata(variant) {
|
|
|
124
117
|
}
|
|
125
118
|
|
|
126
119
|
// Add extracted metadata (if any) for repositioning
|
|
127
|
-
for (
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
source: _file
|
|
133
|
-
} : _file), {}, {
|
|
120
|
+
for (const [filePath, file] of Object.entries(existingMetadata)) {
|
|
121
|
+
allMetadataFiles[filePath] = {
|
|
122
|
+
...(typeof file === 'string' ? {
|
|
123
|
+
source: file
|
|
124
|
+
} : file),
|
|
134
125
|
metadata: true
|
|
135
|
-
}
|
|
126
|
+
};
|
|
136
127
|
}
|
|
137
128
|
|
|
138
129
|
// Add additional metadata files for positioning
|
|
139
|
-
for (
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
source: _file2
|
|
145
|
-
} : _file2), {}, {
|
|
130
|
+
for (const [filePath, file] of Object.entries(metadataFiles)) {
|
|
131
|
+
allMetadataFiles[filePath] = {
|
|
132
|
+
...(typeof file === 'string' ? {
|
|
133
|
+
source: file
|
|
134
|
+
} : file),
|
|
146
135
|
metadata: true
|
|
147
|
-
}
|
|
136
|
+
};
|
|
148
137
|
}
|
|
149
138
|
|
|
150
139
|
// Position new metadata files at the calculated level using buildPath
|
|
151
|
-
for (
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
_file3 = _Object$entries5$_i[1];
|
|
155
|
-
var metadataPath = buildPath(metadataBackNavigation, originalPath);
|
|
156
|
-
positionedMetadataFiles[metadataPath] = _file3;
|
|
140
|
+
for (const [originalPath, file] of Object.entries(allMetadataFiles)) {
|
|
141
|
+
const metadataPath = buildPath(metadataBackNavigation, originalPath);
|
|
142
|
+
positionedMetadataFiles[metadataPath] = file;
|
|
157
143
|
}
|
|
158
144
|
|
|
159
145
|
// Combine all files
|
|
160
|
-
|
|
161
|
-
|
|
146
|
+
const finalExtraFiles = {
|
|
147
|
+
...nonMetadataFiles,
|
|
148
|
+
...positionedMetadataFiles
|
|
149
|
+
};
|
|
150
|
+
return {
|
|
151
|
+
...workingVariant,
|
|
162
152
|
extraFiles: finalExtraFiles,
|
|
163
153
|
metadataPrefix: targetMetadataPrefix
|
|
164
|
-
}
|
|
154
|
+
};
|
|
165
155
|
}
|
|
@@ -1,41 +1,33 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
3
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
4
1
|
/**
|
|
5
2
|
* Pure function to parse code variants and their extraFiles.
|
|
6
3
|
* Converts string sources to HAST nodes and handles hastJson parsing.
|
|
7
4
|
*/
|
|
8
5
|
export function parseCode(code, parseSource) {
|
|
9
|
-
|
|
10
|
-
for (
|
|
11
|
-
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
12
|
-
variant = _Object$entries$_i[0],
|
|
13
|
-
variantCode = _Object$entries$_i[1];
|
|
6
|
+
const parsed = {};
|
|
7
|
+
for (const [variant, variantCode] of Object.entries(code)) {
|
|
14
8
|
if (typeof variantCode === 'string') {
|
|
15
9
|
// Already parsed/highlighted
|
|
16
10
|
parsed[variant] = variantCode;
|
|
17
|
-
} else if (variantCode &&
|
|
11
|
+
} else if (variantCode && typeof variantCode === 'object') {
|
|
18
12
|
// Parse if source is available and not already parsed, and we have a filename to determine the file type
|
|
19
13
|
if (variantCode.source && typeof variantCode.source === 'string' && variantCode.fileName) {
|
|
20
14
|
try {
|
|
21
|
-
|
|
15
|
+
const hastRoot = parseSource(variantCode.source, variantCode.fileName);
|
|
22
16
|
|
|
23
17
|
// Also parse extraFiles if they contain sources that need parsing
|
|
24
|
-
|
|
25
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
26
|
-
fileName = _ref2[0],
|
|
27
|
-
fileContent = _ref2[1];
|
|
18
|
+
const parsedExtraFiles = variantCode.extraFiles ? Object.fromEntries(Object.entries(variantCode.extraFiles).map(([fileName, fileContent]) => {
|
|
28
19
|
if (typeof fileContent === 'string') {
|
|
29
20
|
return [fileName, fileContent]; // Keep string as-is
|
|
30
21
|
}
|
|
31
|
-
if (fileContent &&
|
|
22
|
+
if (fileContent && typeof fileContent === 'object' && fileContent.source) {
|
|
32
23
|
if (typeof fileContent.source === 'string') {
|
|
33
24
|
// Parse string source in extraFile
|
|
34
25
|
try {
|
|
35
|
-
|
|
36
|
-
return [fileName,
|
|
26
|
+
const parsedHastRoot = parseSource(fileContent.source, fileName);
|
|
27
|
+
return [fileName, {
|
|
28
|
+
...fileContent,
|
|
37
29
|
source: parsedHastRoot
|
|
38
|
-
}
|
|
30
|
+
}];
|
|
39
31
|
} catch (error) {
|
|
40
32
|
return [fileName, fileContent]; // Keep original if parsing fails
|
|
41
33
|
}
|
|
@@ -43,10 +35,11 @@ export function parseCode(code, parseSource) {
|
|
|
43
35
|
}
|
|
44
36
|
return [fileName, fileContent]; // Keep as-is for other cases
|
|
45
37
|
})) : undefined;
|
|
46
|
-
parsed[variant] =
|
|
38
|
+
parsed[variant] = {
|
|
39
|
+
...variantCode,
|
|
47
40
|
source: hastRoot,
|
|
48
41
|
extraFiles: parsedExtraFiles
|
|
49
|
-
}
|
|
42
|
+
};
|
|
50
43
|
} catch (error) {
|
|
51
44
|
// Keep original if parsing fails
|
|
52
45
|
parsed[variant] = variantCode;
|
|
@@ -54,7 +47,8 @@ export function parseCode(code, parseSource) {
|
|
|
54
47
|
} else if (variantCode.source && typeof variantCode.source === 'string' && !variantCode.fileName) {
|
|
55
48
|
// Return a basic HAST root node with the source text for unsupported file types
|
|
56
49
|
// This indicates that the source has at least passed through the parsing pipeline
|
|
57
|
-
parsed[variant] =
|
|
50
|
+
parsed[variant] = {
|
|
51
|
+
...variantCode,
|
|
58
52
|
source: {
|
|
59
53
|
type: 'root',
|
|
60
54
|
children: [{
|
|
@@ -62,28 +56,26 @@ export function parseCode(code, parseSource) {
|
|
|
62
56
|
value: variantCode.source
|
|
63
57
|
}]
|
|
64
58
|
}
|
|
65
|
-
}
|
|
66
|
-
} else if (variantCode.source &&
|
|
59
|
+
};
|
|
60
|
+
} else if (variantCode.source && typeof variantCode.source === 'object' && 'hastJson' in variantCode.source) {
|
|
67
61
|
try {
|
|
68
62
|
// Parse hastJson to HAST nodes
|
|
69
|
-
|
|
63
|
+
const hastRoot = JSON.parse(variantCode.source.hastJson);
|
|
70
64
|
|
|
71
65
|
// Also parse extraFiles if they contain sources that need parsing
|
|
72
|
-
|
|
73
|
-
var _ref4 = _slicedToArray(_ref3, 2),
|
|
74
|
-
fileName = _ref4[0],
|
|
75
|
-
fileContent = _ref4[1];
|
|
66
|
+
const parsedExtraFiles = variantCode.extraFiles ? Object.fromEntries(Object.entries(variantCode.extraFiles).map(([fileName, fileContent]) => {
|
|
76
67
|
if (typeof fileContent === 'string') {
|
|
77
68
|
return [fileName, fileContent]; // Keep string as-is
|
|
78
69
|
}
|
|
79
|
-
if (fileContent &&
|
|
70
|
+
if (fileContent && typeof fileContent === 'object' && fileContent.source) {
|
|
80
71
|
if (typeof fileContent.source === 'string') {
|
|
81
72
|
// Parse string source in extraFile
|
|
82
73
|
try {
|
|
83
|
-
|
|
84
|
-
return [fileName,
|
|
74
|
+
const parsedHastRoot = parseSource(fileContent.source, fileName);
|
|
75
|
+
return [fileName, {
|
|
76
|
+
...fileContent,
|
|
85
77
|
source: parsedHastRoot
|
|
86
|
-
}
|
|
78
|
+
}];
|
|
87
79
|
} catch (error) {
|
|
88
80
|
return [fileName, fileContent]; // Keep original if parsing fails
|
|
89
81
|
}
|
|
@@ -91,32 +83,31 @@ export function parseCode(code, parseSource) {
|
|
|
91
83
|
}
|
|
92
84
|
return [fileName, fileContent]; // Keep as-is for other cases
|
|
93
85
|
})) : undefined;
|
|
94
|
-
parsed[variant] =
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
86
|
+
parsed[variant] = {
|
|
87
|
+
...variantCode,
|
|
88
|
+
source: hastRoot,
|
|
89
|
+
extraFiles: parsedExtraFiles
|
|
90
|
+
};
|
|
98
91
|
} catch (error) {
|
|
99
92
|
// Keep original if parsing fails
|
|
100
|
-
console.error(
|
|
93
|
+
console.error(`Failed to parse hastJson for variant ${variant}:`, error);
|
|
101
94
|
parsed[variant] = variantCode;
|
|
102
95
|
}
|
|
103
96
|
} else {
|
|
104
97
|
// Already parsed or no source to parse - but still check extraFiles
|
|
105
|
-
|
|
106
|
-
var _ref6 = _slicedToArray(_ref5, 2),
|
|
107
|
-
fileName = _ref6[0],
|
|
108
|
-
fileContent = _ref6[1];
|
|
98
|
+
const parsedExtraFiles = variantCode.extraFiles ? Object.fromEntries(Object.entries(variantCode.extraFiles).map(([fileName, fileContent]) => {
|
|
109
99
|
if (typeof fileContent === 'string') {
|
|
110
100
|
return [fileName, fileContent]; // Keep string as-is
|
|
111
101
|
}
|
|
112
|
-
if (fileContent &&
|
|
102
|
+
if (fileContent && typeof fileContent === 'object' && fileContent.source) {
|
|
113
103
|
if (typeof fileContent.source === 'string') {
|
|
114
104
|
// Parse string source in extraFile
|
|
115
105
|
try {
|
|
116
|
-
|
|
117
|
-
return [fileName,
|
|
106
|
+
const parsedHastRoot = parseSource(fileContent.source, fileName);
|
|
107
|
+
return [fileName, {
|
|
108
|
+
...fileContent,
|
|
118
109
|
source: parsedHastRoot
|
|
119
|
-
}
|
|
110
|
+
}];
|
|
120
111
|
} catch (error) {
|
|
121
112
|
return [fileName, fileContent]; // Keep original if parsing fails
|
|
122
113
|
}
|
|
@@ -124,9 +115,10 @@ export function parseCode(code, parseSource) {
|
|
|
124
115
|
}
|
|
125
116
|
return [fileName, fileContent]; // Keep as-is for other cases
|
|
126
117
|
})) : undefined;
|
|
127
|
-
parsed[variant] =
|
|
128
|
-
|
|
129
|
-
|
|
118
|
+
parsed[variant] = {
|
|
119
|
+
...variantCode,
|
|
120
|
+
extraFiles: parsedExtraFiles
|
|
121
|
+
};
|
|
130
122
|
}
|
|
131
123
|
}
|
|
132
124
|
}
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
-
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
3
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
4
|
-
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
5
1
|
/**
|
|
6
2
|
* Shared path utilities for CodeHighlighter components
|
|
7
3
|
*
|
|
@@ -22,38 +18,29 @@ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIt
|
|
|
22
18
|
*/
|
|
23
19
|
export function resolveRelativePath(relativePath) {
|
|
24
20
|
// Split the path into segments
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (
|
|
34
|
-
//
|
|
35
|
-
|
|
36
|
-
} else if (segment === '..') {
|
|
37
|
-
if (resolved.length > 0) {
|
|
38
|
-
// Remove the last segment (go back one directory)
|
|
39
|
-
resolved.pop();
|
|
40
|
-
} else {
|
|
41
|
-
// Count back steps that go beyond the current directory
|
|
42
|
-
backSteps += 1;
|
|
43
|
-
}
|
|
21
|
+
const segments = relativePath.split('/');
|
|
22
|
+
const resolved = [];
|
|
23
|
+
let backSteps = 0;
|
|
24
|
+
for (const segment of segments) {
|
|
25
|
+
if (segment === '' || segment === '.') {
|
|
26
|
+
// Skip empty and current directory segments
|
|
27
|
+
continue;
|
|
28
|
+
} else if (segment === '..') {
|
|
29
|
+
if (resolved.length > 0) {
|
|
30
|
+
// Remove the last segment (go back one directory)
|
|
31
|
+
resolved.pop();
|
|
44
32
|
} else {
|
|
45
|
-
//
|
|
46
|
-
|
|
33
|
+
// Count back steps that go beyond the current directory
|
|
34
|
+
backSteps += 1;
|
|
47
35
|
}
|
|
36
|
+
} else {
|
|
37
|
+
// Regular directory or file segment
|
|
38
|
+
resolved.push(segment);
|
|
48
39
|
}
|
|
49
|
-
} catch (err) {
|
|
50
|
-
_iterator.e(err);
|
|
51
|
-
} finally {
|
|
52
|
-
_iterator.f();
|
|
53
40
|
}
|
|
54
41
|
return {
|
|
55
42
|
resolvedPath: resolved.join('/'),
|
|
56
|
-
backSteps
|
|
43
|
+
backSteps
|
|
57
44
|
};
|
|
58
45
|
}
|
|
59
46
|
|
|
@@ -82,8 +69,8 @@ export function removeTrailingSlash(path) {
|
|
|
82
69
|
* Remove a specific number of back navigation prefixes from a path
|
|
83
70
|
*/
|
|
84
71
|
export function removeBackNavigationPrefix(path, count) {
|
|
85
|
-
|
|
86
|
-
for (
|
|
72
|
+
let result = path;
|
|
73
|
+
for (let i = 0; i < count; i += 1) {
|
|
87
74
|
if (result.startsWith('../')) {
|
|
88
75
|
result = result.slice(3);
|
|
89
76
|
} else {
|
|
@@ -118,24 +105,22 @@ export function removeBackNavigationPrefix(path, count) {
|
|
|
118
105
|
* ```
|
|
119
106
|
*/
|
|
120
107
|
export function calculateMaxBackNavigation(files) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
for (
|
|
124
|
-
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
125
|
-
relativePath = _Object$entries$_i[0],
|
|
126
|
-
fileContent = _Object$entries$_i[1];
|
|
108
|
+
let maxBackNavigation = 0;
|
|
109
|
+
let maxSourceBackNavigation = 0;
|
|
110
|
+
for (const [relativePath, fileContent] of Object.entries(files)) {
|
|
127
111
|
// Check if this is a metadata file
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
backSteps
|
|
112
|
+
const isMetadata = typeof fileContent === 'object' && fileContent.metadata;
|
|
113
|
+
const {
|
|
114
|
+
backSteps
|
|
115
|
+
} = resolveRelativePath(relativePath);
|
|
131
116
|
if (!isMetadata) {
|
|
132
117
|
maxSourceBackNavigation = Math.max(maxSourceBackNavigation, backSteps);
|
|
133
118
|
}
|
|
134
119
|
maxBackNavigation = Math.max(maxBackNavigation, backSteps);
|
|
135
120
|
}
|
|
136
121
|
return {
|
|
137
|
-
maxBackNavigation
|
|
138
|
-
maxSourceBackNavigation
|
|
122
|
+
maxBackNavigation,
|
|
123
|
+
maxSourceBackNavigation
|
|
139
124
|
};
|
|
140
125
|
}
|
|
141
126
|
|
|
@@ -163,13 +148,10 @@ export function calculateMaxBackNavigation(files) {
|
|
|
163
148
|
* ```
|
|
164
149
|
*/
|
|
165
150
|
export function calculateMaxSourceBackNavigation(files) {
|
|
166
|
-
|
|
167
|
-
for (
|
|
168
|
-
var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
|
|
169
|
-
relativePath = _Object$entries2$_i[0],
|
|
170
|
-
fileContent = _Object$entries2$_i[1];
|
|
151
|
+
let maxSourceBackNavigation = 0;
|
|
152
|
+
for (const [relativePath, fileContent] of Object.entries(files)) {
|
|
171
153
|
// Check if this is a metadata file
|
|
172
|
-
|
|
154
|
+
const isMetadata = typeof fileContent === 'object' && fileContent.metadata;
|
|
173
155
|
|
|
174
156
|
// Skip metadata files - only consider non-metadata files for maxSourceBackNavigation
|
|
175
157
|
if (isMetadata) {
|
|
@@ -177,8 +159,9 @@ export function calculateMaxSourceBackNavigation(files) {
|
|
|
177
159
|
}
|
|
178
160
|
|
|
179
161
|
// Use path resolution to get the net back steps (most accurate)
|
|
180
|
-
|
|
181
|
-
backSteps
|
|
162
|
+
const {
|
|
163
|
+
backSteps
|
|
164
|
+
} = resolveRelativePath(relativePath);
|
|
182
165
|
maxSourceBackNavigation = Math.max(maxSourceBackNavigation, backSteps);
|
|
183
166
|
}
|
|
184
167
|
return maxSourceBackNavigation;
|
|
@@ -187,18 +170,14 @@ export function calculateMaxSourceBackNavigation(files) {
|
|
|
187
170
|
/**
|
|
188
171
|
* Build a path from multiple components, filtering out empty parts
|
|
189
172
|
*/
|
|
190
|
-
export function buildPath() {
|
|
191
|
-
|
|
192
|
-
for (
|
|
193
|
-
segments[_key] = arguments[_key];
|
|
194
|
-
}
|
|
195
|
-
for (var _i3 = 0, _segments = segments; _i3 < _segments.length; _i3++) {
|
|
196
|
-
var segment = _segments[_i3];
|
|
173
|
+
export function buildPath(...segments) {
|
|
174
|
+
const parts = [];
|
|
175
|
+
for (const segment of segments) {
|
|
197
176
|
if (segment === undefined) {
|
|
198
177
|
continue;
|
|
199
178
|
}
|
|
200
179
|
if (Array.isArray(segment)) {
|
|
201
|
-
parts.push
|
|
180
|
+
parts.push(...segment);
|
|
202
181
|
} else {
|
|
203
182
|
parts.push(segment);
|
|
204
183
|
}
|
|
@@ -215,9 +194,9 @@ export function buildPath() {
|
|
|
215
194
|
export function createSyntheticDirectories(count) {
|
|
216
195
|
return Array.from({
|
|
217
196
|
length: count
|
|
218
|
-
},
|
|
219
|
-
|
|
220
|
-
|
|
197
|
+
}, (_, i) => {
|
|
198
|
+
let result = '';
|
|
199
|
+
let num = i + 1; // 1-based for Excel-style naming
|
|
221
200
|
|
|
222
201
|
while (num > 0) {
|
|
223
202
|
num -= 1; // Adjust for 0-based indexing
|
|
@@ -245,13 +224,13 @@ export function createSyntheticDirectories(count) {
|
|
|
245
224
|
*/
|
|
246
225
|
export function calculateMetadataBackNavigation(files, metadataPrefix) {
|
|
247
226
|
// Get the maxSourceBackNavigation from the file structure
|
|
248
|
-
|
|
227
|
+
let backLevels = 0;
|
|
249
228
|
if (files) {
|
|
250
229
|
backLevels = calculateMaxSourceBackNavigation(files);
|
|
251
230
|
}
|
|
252
231
|
if (metadataPrefix) {
|
|
253
232
|
// When a prefix is provided, add additional back navigation based on prefix depth
|
|
254
|
-
|
|
233
|
+
const prefixSegments = metadataPrefix.split('/').filter(Boolean);
|
|
255
234
|
backLevels += prefixSegments.length;
|
|
256
235
|
}
|
|
257
236
|
return '../'.repeat(backLevels);
|