@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.
- 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,11 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
-
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
5
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
6
|
-
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
7
|
-
import _regenerator from "@babel/runtime/helpers/esm/regenerator";
|
|
8
|
-
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
9
3
|
import * as React from 'react';
|
|
10
4
|
import { useCodeContext } from "../CodeProvider/CodeContext.js";
|
|
11
5
|
import { CodeHighlighterContext } from "./CodeHighlighterContext.js";
|
|
@@ -17,33 +11,34 @@ import { codeToFallbackProps } from "./codeToFallbackProps.js";
|
|
|
17
11
|
import { mergeCodeMetadata } from "../pipeline/loadCodeVariant/mergeCodeMetadata.js";
|
|
18
12
|
import * as Errors from "./errors.js";
|
|
19
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
function useInitialData(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
initialData
|
|
45
|
-
reason
|
|
46
|
-
|
|
14
|
+
const DEBUG = false; // Set to true for debugging purposes
|
|
15
|
+
|
|
16
|
+
function useInitialData({
|
|
17
|
+
variants,
|
|
18
|
+
variantName,
|
|
19
|
+
code,
|
|
20
|
+
setCode,
|
|
21
|
+
fileName,
|
|
22
|
+
url,
|
|
23
|
+
highlightAfter,
|
|
24
|
+
fallbackUsesExtraFiles,
|
|
25
|
+
fallbackUsesAllVariants,
|
|
26
|
+
isControlled,
|
|
27
|
+
globalsCode,
|
|
28
|
+
setProcessedGlobalsCode
|
|
29
|
+
}) {
|
|
30
|
+
const {
|
|
31
|
+
sourceParser,
|
|
32
|
+
loadCodeMeta,
|
|
33
|
+
loadVariantMeta,
|
|
34
|
+
loadSource,
|
|
35
|
+
loadCodeFallback
|
|
36
|
+
} = useCodeContext();
|
|
37
|
+
const {
|
|
38
|
+
initialData,
|
|
39
|
+
reason
|
|
40
|
+
} = React.useMemo(() => maybeCodeInitialData(variants, variantName, code, fileName, highlightAfter === 'init', fallbackUsesExtraFiles, fallbackUsesAllVariants), [variants, variantName, code, fileName, highlightAfter, fallbackUsesExtraFiles, fallbackUsesAllVariants]);
|
|
41
|
+
const needsFallback = !initialData && !isControlled;
|
|
47
42
|
if (needsFallback) {
|
|
48
43
|
if (!url) {
|
|
49
44
|
// URL is required for loading fallback data
|
|
@@ -56,76 +51,65 @@ function useInitialData(_ref) {
|
|
|
56
51
|
|
|
57
52
|
// TODO: fallbackInitialRenderOnly option? this would mean we can't fetch fallback data on the client side
|
|
58
53
|
// Load initial data if not provided
|
|
59
|
-
React.useEffect(
|
|
54
|
+
React.useEffect(() => {
|
|
60
55
|
if (!needsFallback || !url || !loadCodeFallback) {
|
|
61
56
|
return;
|
|
62
57
|
}
|
|
63
58
|
|
|
64
59
|
// TODO: abort controller
|
|
65
60
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
case 1:
|
|
93
|
-
loaded = _context.v;
|
|
94
|
-
if ('error' in loaded) {
|
|
95
|
-
console.error(new Errors.ErrorCodeHighlighterClientLoadFallbackFailure(loaded.error));
|
|
96
|
-
} else {
|
|
97
|
-
setCode(loaded.code);
|
|
98
|
-
// Store processed globalsCode from loadCodeFallback result
|
|
99
|
-
if (loaded.processedGlobalsCode) {
|
|
100
|
-
setProcessedGlobalsCode(loaded.processedGlobalsCode);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
case 2:
|
|
104
|
-
return _context.a(2);
|
|
61
|
+
(async () => {
|
|
62
|
+
if (DEBUG) {
|
|
63
|
+
// eslint-disable-next-line no-console
|
|
64
|
+
console.log('Loading initial data for CodeHighlighterClient: ', reason);
|
|
65
|
+
}
|
|
66
|
+
const loaded = await loadCodeFallback(url, variantName, code, {
|
|
67
|
+
shouldHighlight: highlightAfter === 'init',
|
|
68
|
+
fallbackUsesExtraFiles,
|
|
69
|
+
fallbackUsesAllVariants,
|
|
70
|
+
sourceParser,
|
|
71
|
+
loadSource,
|
|
72
|
+
loadVariantMeta,
|
|
73
|
+
loadCodeMeta,
|
|
74
|
+
initialFilename: fileName,
|
|
75
|
+
variants,
|
|
76
|
+
globalsCode // Let loadCodeFallback handle processing
|
|
77
|
+
}).catch(error => ({
|
|
78
|
+
error
|
|
79
|
+
}));
|
|
80
|
+
if ('error' in loaded) {
|
|
81
|
+
console.error(new Errors.ErrorCodeHighlighterClientLoadFallbackFailure(loaded.error));
|
|
82
|
+
} else {
|
|
83
|
+
setCode(loaded.code);
|
|
84
|
+
// Store processed globalsCode from loadCodeFallback result
|
|
85
|
+
if (loaded.processedGlobalsCode) {
|
|
86
|
+
setProcessedGlobalsCode(loaded.processedGlobalsCode);
|
|
105
87
|
}
|
|
106
|
-
}
|
|
107
|
-
})
|
|
88
|
+
}
|
|
89
|
+
})();
|
|
108
90
|
}, [initialData, reason, needsFallback, variantName, code, setCode, highlightAfter, url, sourceParser, loadSource, loadVariantMeta, loadCodeMeta, fallbackUsesExtraFiles, fallbackUsesAllVariants, fileName, variants, globalsCode, setProcessedGlobalsCode, loadCodeFallback]);
|
|
109
91
|
}
|
|
110
|
-
function useAllVariants(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
92
|
+
function useAllVariants({
|
|
93
|
+
readyForContent,
|
|
94
|
+
variants,
|
|
95
|
+
isControlled,
|
|
96
|
+
url,
|
|
97
|
+
code,
|
|
98
|
+
setCode,
|
|
99
|
+
processedGlobalsCode,
|
|
100
|
+
globalsCode,
|
|
101
|
+
setProcessedGlobalsCode
|
|
102
|
+
}) {
|
|
103
|
+
const {
|
|
104
|
+
loadCodeMeta,
|
|
105
|
+
loadVariantMeta,
|
|
106
|
+
loadSource,
|
|
107
|
+
loadCodeVariant
|
|
108
|
+
} = useCodeContext();
|
|
109
|
+
const needsData = !readyForContent && !isControlled;
|
|
126
110
|
|
|
127
111
|
// validation
|
|
128
|
-
React.useMemo(
|
|
112
|
+
React.useMemo(() => {
|
|
129
113
|
if (needsData) {
|
|
130
114
|
if (!url) {
|
|
131
115
|
throw new Errors.ErrorCodeHighlighterClientMissingUrlForVariants();
|
|
@@ -136,23 +120,19 @@ function useAllVariants(_ref3) {
|
|
|
136
120
|
if (!code && !loadCodeMeta) {
|
|
137
121
|
throw new Errors.ErrorCodeHighlighterClientMissingLoadCodeMetaForNoCode(url);
|
|
138
122
|
}
|
|
139
|
-
if (globalsCode && globalsCode.length > 0 && globalsCode.some(
|
|
140
|
-
return typeof item === 'string';
|
|
141
|
-
}) && !loadCodeMeta) {
|
|
123
|
+
if (globalsCode && globalsCode.length > 0 && globalsCode.some(item => typeof item === 'string') && !loadCodeMeta) {
|
|
142
124
|
throw new Errors.ErrorCodeHighlighterClientMissingLoadCodeMetaForGlobals();
|
|
143
125
|
}
|
|
144
126
|
if (!code && !loadSource) {
|
|
145
127
|
throw new Errors.ErrorCodeHighlighterClientMissingLoadSourceForNoCode();
|
|
146
128
|
}
|
|
147
|
-
if (code && Object.keys(code).some(
|
|
148
|
-
|
|
129
|
+
if (code && Object.keys(code).some(variantName => {
|
|
130
|
+
const variant = code[variantName];
|
|
149
131
|
if (!variant || typeof variant === 'string' || !variant.source) {
|
|
150
132
|
return true;
|
|
151
133
|
}
|
|
152
|
-
|
|
153
|
-
if (extraFiles && Object.keys(extraFiles).some(
|
|
154
|
-
return !extraFiles[fileName] || typeof extraFiles[fileName] === 'string' || !extraFiles[fileName].source;
|
|
155
|
-
})) {
|
|
134
|
+
const extraFiles = variant.extraFiles;
|
|
135
|
+
if (extraFiles && Object.keys(extraFiles).some(fileName => !extraFiles[fileName] || typeof extraFiles[fileName] === 'string' || !extraFiles[fileName].source)) {
|
|
156
136
|
return true;
|
|
157
137
|
}
|
|
158
138
|
return false;
|
|
@@ -161,200 +141,134 @@ function useAllVariants(_ref3) {
|
|
|
161
141
|
}
|
|
162
142
|
}
|
|
163
143
|
}, [code, globalsCode, loadCodeMeta, loadCodeVariant, loadSource, needsData, url]);
|
|
164
|
-
React.useEffect(
|
|
144
|
+
React.useEffect(() => {
|
|
165
145
|
if (!needsData || !url || !loadCodeVariant) {
|
|
166
146
|
return;
|
|
167
147
|
}
|
|
168
148
|
|
|
169
149
|
// TODO: abort controller
|
|
170
150
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
_context3.p = 0;
|
|
177
|
-
loadedCode = code;
|
|
178
|
-
if (loadedCode) {
|
|
179
|
-
_context3.n = 3;
|
|
180
|
-
break;
|
|
181
|
-
}
|
|
182
|
-
if (loadCodeMeta) {
|
|
183
|
-
_context3.n = 1;
|
|
184
|
-
break;
|
|
185
|
-
}
|
|
151
|
+
(async () => {
|
|
152
|
+
try {
|
|
153
|
+
let loadedCode = code;
|
|
154
|
+
if (!loadedCode) {
|
|
155
|
+
if (!loadCodeMeta) {
|
|
186
156
|
throw new Errors.ErrorCodeHighlighterClientMissingLoadCodeMeta();
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
case 4:
|
|
204
|
-
if (!(globalsCode && globalsCode.length > 0)) {
|
|
205
|
-
_context3.n = 6;
|
|
206
|
-
break;
|
|
207
|
-
}
|
|
208
|
-
_context3.n = 5;
|
|
209
|
-
return Promise.all(globalsCode.map(/*#__PURE__*/function () {
|
|
210
|
-
var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(item) {
|
|
211
|
-
return _regenerator().w(function (_context2) {
|
|
212
|
-
while (1) switch (_context2.n) {
|
|
213
|
-
case 0:
|
|
214
|
-
if (!(typeof item === 'string')) {
|
|
215
|
-
_context2.n = 2;
|
|
216
|
-
break;
|
|
217
|
-
}
|
|
218
|
-
if (loadCodeMeta) {
|
|
219
|
-
_context2.n = 1;
|
|
220
|
-
break;
|
|
221
|
-
}
|
|
222
|
-
throw new Errors.ErrorCodeHighlighterClientMissingLoadCodeMeta();
|
|
223
|
-
case 1:
|
|
224
|
-
return _context2.a(2, loadCodeMeta(item));
|
|
225
|
-
case 2:
|
|
226
|
-
return _context2.a(2, item);
|
|
227
|
-
}
|
|
228
|
-
}, _callee2);
|
|
229
|
-
}));
|
|
230
|
-
return function (_x) {
|
|
231
|
-
return _ref5.apply(this, arguments);
|
|
232
|
-
};
|
|
233
|
-
}()));
|
|
234
|
-
case 5:
|
|
235
|
-
globalsCodeObjects = _context3.v;
|
|
236
|
-
// Store processed globalsCode in state for future use
|
|
237
|
-
setProcessedGlobalsCode(globalsCodeObjects);
|
|
238
|
-
case 6:
|
|
239
|
-
_context3.n = 7;
|
|
240
|
-
return Promise.all(variants.map(function (name) {
|
|
241
|
-
// Resolve globalsCode for this specific variant
|
|
242
|
-
var globalsForVariant = globalsCodeObjects.map(function (codeObj) {
|
|
243
|
-
// Only include if this variant exists in the globalsCode
|
|
244
|
-
return codeObj[name];
|
|
245
|
-
}).filter(function (item) {
|
|
246
|
-
return Boolean(item);
|
|
247
|
-
});
|
|
248
|
-
return loadCodeVariant(url, name, loadedCode[name], {
|
|
249
|
-
disableParsing: true,
|
|
250
|
-
disableTransforms: true,
|
|
251
|
-
loadSource: loadSource,
|
|
252
|
-
loadVariantMeta: loadVariantMeta,
|
|
253
|
-
globalsCode: globalsForVariant
|
|
254
|
-
}).then(function (variant) {
|
|
255
|
-
return {
|
|
256
|
-
name: name,
|
|
257
|
-
variant: variant
|
|
258
|
-
};
|
|
259
|
-
})["catch"](function (error) {
|
|
260
|
-
return {
|
|
261
|
-
error: error
|
|
262
|
-
};
|
|
263
|
-
});
|
|
264
|
-
}));
|
|
265
|
-
case 7:
|
|
266
|
-
result = _context3.v;
|
|
267
|
-
resultCode = {};
|
|
268
|
-
errors = [];
|
|
269
|
-
_iterator = _createForOfIteratorHelper(result);
|
|
270
|
-
try {
|
|
271
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
272
|
-
item = _step.value;
|
|
273
|
-
if ('error' in item) {
|
|
274
|
-
errors.push(item.error);
|
|
275
|
-
} else {
|
|
276
|
-
resultCode[item.name] = item.variant.code;
|
|
277
|
-
}
|
|
157
|
+
}
|
|
158
|
+
loadedCode = await loadCodeMeta(url);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Use the already-processed globalsCode from state, or process it if not available
|
|
162
|
+
let globalsCodeObjects = [];
|
|
163
|
+
if (processedGlobalsCode) {
|
|
164
|
+
// Use the already-processed globalsCode from state
|
|
165
|
+
globalsCodeObjects = processedGlobalsCode;
|
|
166
|
+
} else if (globalsCode && globalsCode.length > 0) {
|
|
167
|
+
// Process globalsCode: load any string URLs into Code objects
|
|
168
|
+
globalsCodeObjects = await Promise.all(globalsCode.map(async item => {
|
|
169
|
+
if (typeof item === 'string') {
|
|
170
|
+
// Load Code object from URL string
|
|
171
|
+
if (!loadCodeMeta) {
|
|
172
|
+
throw new Errors.ErrorCodeHighlighterClientMissingLoadCodeMeta();
|
|
278
173
|
}
|
|
279
|
-
|
|
280
|
-
_iterator.e(err);
|
|
281
|
-
} finally {
|
|
282
|
-
_iterator.f();
|
|
283
|
-
}
|
|
284
|
-
if (errors.length > 0) {
|
|
285
|
-
console.error(new Errors.ErrorCodeHighlighterClientLoadVariantsFailure(url, errors));
|
|
286
|
-
} else {
|
|
287
|
-
setCode(resultCode);
|
|
174
|
+
return loadCodeMeta(item);
|
|
288
175
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
console.error(new Errors.ErrorCodeHighlighterClientLoadAllVariantsFailure(url, _t));
|
|
295
|
-
case 9:
|
|
296
|
-
return _context3.a(2);
|
|
176
|
+
// Already a Code object
|
|
177
|
+
return item;
|
|
178
|
+
}));
|
|
179
|
+
// Store processed globalsCode in state for future use
|
|
180
|
+
setProcessedGlobalsCode(globalsCodeObjects);
|
|
297
181
|
}
|
|
298
|
-
|
|
299
|
-
|
|
182
|
+
|
|
183
|
+
// Load variant data without parsing or transforming
|
|
184
|
+
const result = await Promise.all(variants.map(name => {
|
|
185
|
+
// Resolve globalsCode for this specific variant
|
|
186
|
+
const globalsForVariant = globalsCodeObjects.map(codeObj => {
|
|
187
|
+
// Only include if this variant exists in the globalsCode
|
|
188
|
+
return codeObj[name];
|
|
189
|
+
}).filter(item => Boolean(item));
|
|
190
|
+
return loadCodeVariant(url, name, loadedCode[name], {
|
|
191
|
+
disableParsing: true,
|
|
192
|
+
disableTransforms: true,
|
|
193
|
+
loadSource,
|
|
194
|
+
loadVariantMeta,
|
|
195
|
+
globalsCode: globalsForVariant
|
|
196
|
+
}).then(variant => ({
|
|
197
|
+
name,
|
|
198
|
+
variant
|
|
199
|
+
})).catch(error => ({
|
|
200
|
+
error
|
|
201
|
+
}));
|
|
202
|
+
}));
|
|
203
|
+
const resultCode = {};
|
|
204
|
+
const errors = [];
|
|
205
|
+
for (const item of result) {
|
|
206
|
+
if ('error' in item) {
|
|
207
|
+
errors.push(item.error);
|
|
208
|
+
} else {
|
|
209
|
+
resultCode[item.name] = item.variant.code;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (errors.length > 0) {
|
|
213
|
+
console.error(new Errors.ErrorCodeHighlighterClientLoadVariantsFailure(url, errors));
|
|
214
|
+
} else {
|
|
215
|
+
setCode(resultCode);
|
|
216
|
+
}
|
|
217
|
+
} catch (error) {
|
|
218
|
+
console.error(new Errors.ErrorCodeHighlighterClientLoadAllVariantsFailure(url, error));
|
|
219
|
+
}
|
|
220
|
+
})();
|
|
300
221
|
}, [needsData, variants, url, code, setCode, loadSource, loadVariantMeta, loadCodeMeta, processedGlobalsCode, globalsCode, setProcessedGlobalsCode, loadCodeVariant]);
|
|
301
222
|
return {
|
|
302
|
-
readyForContent
|
|
223
|
+
readyForContent
|
|
303
224
|
};
|
|
304
225
|
}
|
|
305
226
|
function yieldToMain() {
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
return globalThis.scheduler["yield"]();
|
|
227
|
+
if (globalThis.scheduler?.yield) {
|
|
228
|
+
return globalThis.scheduler.yield();
|
|
309
229
|
}
|
|
310
230
|
|
|
311
231
|
// Fall back to yielding with setTimeout.
|
|
312
|
-
return new Promise(
|
|
232
|
+
return new Promise(resolve => {
|
|
313
233
|
setTimeout(resolve, 0);
|
|
314
234
|
});
|
|
315
235
|
}
|
|
316
|
-
function useCodeParsing(
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
React.useEffect(function () {
|
|
236
|
+
function useCodeParsing({
|
|
237
|
+
code,
|
|
238
|
+
readyForContent,
|
|
239
|
+
highlightAfter,
|
|
240
|
+
isHydrated,
|
|
241
|
+
forceClient,
|
|
242
|
+
url
|
|
243
|
+
}) {
|
|
244
|
+
const {
|
|
245
|
+
parseSource,
|
|
246
|
+
parseCode
|
|
247
|
+
} = useCodeContext();
|
|
248
|
+
const [isHighlightAllowed, setIsHighlightAllowed] = React.useState(highlightAfter === 'init' || highlightAfter === 'hydration' && isHydrated);
|
|
249
|
+
React.useEffect(() => {
|
|
331
250
|
if (highlightAfter === 'idle') {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
var idleRequest = requestIdleCallback(function () {
|
|
251
|
+
const requestIdleCallback = window.requestIdleCallback ?? setTimeout;
|
|
252
|
+
const cancelIdleCallback = window.cancelIdleCallback ?? clearTimeout;
|
|
253
|
+
const idleRequest = requestIdleCallback(() => {
|
|
336
254
|
setIsHighlightAllowed(true);
|
|
337
255
|
});
|
|
338
|
-
return
|
|
339
|
-
return cancelIdleCallback(idleRequest);
|
|
340
|
-
};
|
|
256
|
+
return () => cancelIdleCallback(idleRequest);
|
|
341
257
|
}
|
|
342
258
|
return undefined;
|
|
343
259
|
}, [highlightAfter]);
|
|
344
260
|
|
|
345
261
|
// Update highlight allowed state when hydration completes
|
|
346
|
-
React.useEffect(
|
|
262
|
+
React.useEffect(() => {
|
|
347
263
|
if (highlightAfter === 'hydration' && isHydrated) {
|
|
348
264
|
// we should ensure that each code highlighter is enhanced as a separate task
|
|
349
265
|
// this should run from top to bottom
|
|
350
|
-
yieldToMain().then(
|
|
351
|
-
return setIsHighlightAllowed(true);
|
|
352
|
-
});
|
|
266
|
+
yieldToMain().then(() => setIsHighlightAllowed(true));
|
|
353
267
|
}
|
|
354
268
|
}, [highlightAfter, isHydrated]);
|
|
355
269
|
|
|
356
270
|
// Determine if we should highlight based on the highlightAfter setting
|
|
357
|
-
|
|
271
|
+
const shouldHighlight = React.useMemo(() => {
|
|
358
272
|
if (!readyForContent) {
|
|
359
273
|
return false;
|
|
360
274
|
}
|
|
@@ -362,7 +276,7 @@ function useCodeParsing(_ref6) {
|
|
|
362
276
|
}, [readyForContent, isHighlightAllowed]);
|
|
363
277
|
|
|
364
278
|
// Parse the internal code state when ready and timing conditions are met
|
|
365
|
-
|
|
279
|
+
const parsedCode = React.useMemo(() => {
|
|
366
280
|
if (!code || !shouldHighlight || hasAllVariants(Object.keys(code), code, true)) {
|
|
367
281
|
return undefined;
|
|
368
282
|
}
|
|
@@ -384,26 +298,25 @@ function useCodeParsing(_ref6) {
|
|
|
384
298
|
}
|
|
385
299
|
return parseCode(code, parseSource);
|
|
386
300
|
}, [code, shouldHighlight, parseSource, parseCode, forceClient, url]);
|
|
387
|
-
|
|
301
|
+
const deferHighlight = !shouldHighlight;
|
|
388
302
|
return {
|
|
389
|
-
parsedCode
|
|
390
|
-
deferHighlight
|
|
303
|
+
parsedCode,
|
|
304
|
+
deferHighlight
|
|
391
305
|
};
|
|
392
306
|
}
|
|
393
|
-
function useCodeTransforms(
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
setTransformedCode = _React$useState4[1];
|
|
307
|
+
function useCodeTransforms({
|
|
308
|
+
parsedCode,
|
|
309
|
+
variantName
|
|
310
|
+
}) {
|
|
311
|
+
const {
|
|
312
|
+
sourceParser,
|
|
313
|
+
getAvailableTransforms,
|
|
314
|
+
computeHastDeltas
|
|
315
|
+
} = useCodeContext();
|
|
316
|
+
const [transformedCode, setTransformedCode] = React.useState(undefined);
|
|
404
317
|
|
|
405
318
|
// Get available transforms from the current variant (separate memo for efficiency)
|
|
406
|
-
|
|
319
|
+
const availableTransforms = React.useMemo(() => {
|
|
407
320
|
if (!getAvailableTransforms) {
|
|
408
321
|
return [];
|
|
409
322
|
}
|
|
@@ -411,56 +324,41 @@ function useCodeTransforms(_ref7) {
|
|
|
411
324
|
}, [parsedCode, variantName, getAvailableTransforms]);
|
|
412
325
|
|
|
413
326
|
// Effect to compute transformations for all variants
|
|
414
|
-
React.useEffect(
|
|
327
|
+
React.useEffect(() => {
|
|
415
328
|
if (!parsedCode || !sourceParser || !computeHastDeltas) {
|
|
416
329
|
setTransformedCode(parsedCode);
|
|
417
330
|
return;
|
|
418
331
|
}
|
|
419
332
|
|
|
420
333
|
// Process transformations for all variants
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
_context4.n = 2;
|
|
432
|
-
return computeHastDeltas(parsedCode, parseSource);
|
|
433
|
-
case 2:
|
|
434
|
-
enhanced = _context4.v;
|
|
435
|
-
setTransformedCode(enhanced);
|
|
436
|
-
_context4.n = 4;
|
|
437
|
-
break;
|
|
438
|
-
case 3:
|
|
439
|
-
_context4.p = 3;
|
|
440
|
-
_t2 = _context4.v;
|
|
441
|
-
console.error(new Errors.ErrorCodeHighlighterClientTransformProcessingFailure(_t2));
|
|
442
|
-
setTransformedCode(parsedCode);
|
|
443
|
-
case 4:
|
|
444
|
-
return _context4.a(2);
|
|
445
|
-
}
|
|
446
|
-
}, _callee4, null, [[0, 3]]);
|
|
447
|
-
}))();
|
|
334
|
+
(async () => {
|
|
335
|
+
try {
|
|
336
|
+
const parseSource = await sourceParser;
|
|
337
|
+
const enhanced = await computeHastDeltas(parsedCode, parseSource);
|
|
338
|
+
setTransformedCode(enhanced);
|
|
339
|
+
} catch (error) {
|
|
340
|
+
console.error(new Errors.ErrorCodeHighlighterClientTransformProcessingFailure(error));
|
|
341
|
+
setTransformedCode(parsedCode);
|
|
342
|
+
}
|
|
343
|
+
})();
|
|
448
344
|
}, [parsedCode, sourceParser, computeHastDeltas]);
|
|
449
345
|
return {
|
|
450
|
-
transformedCode
|
|
451
|
-
availableTransforms
|
|
346
|
+
transformedCode,
|
|
347
|
+
availableTransforms
|
|
452
348
|
};
|
|
453
349
|
}
|
|
454
|
-
function useControlledCodeParsing(
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
350
|
+
function useControlledCodeParsing({
|
|
351
|
+
code,
|
|
352
|
+
forceClient,
|
|
353
|
+
url
|
|
354
|
+
}) {
|
|
355
|
+
const {
|
|
356
|
+
parseSource,
|
|
357
|
+
parseControlledCode
|
|
358
|
+
} = useCodeContext();
|
|
461
359
|
|
|
462
360
|
// Parse the controlled code separately (no need to check readyForContent)
|
|
463
|
-
|
|
361
|
+
const parsedControlledCode = React.useMemo(() => {
|
|
464
362
|
if (!code) {
|
|
465
363
|
return undefined;
|
|
466
364
|
}
|
|
@@ -485,38 +383,36 @@ function useControlledCodeParsing(_ref9) {
|
|
|
485
383
|
return parseControlledCode(code, parseSource);
|
|
486
384
|
}, [code, parseSource, parseControlledCode, forceClient, url]);
|
|
487
385
|
return {
|
|
488
|
-
parsedControlledCode
|
|
386
|
+
parsedControlledCode
|
|
489
387
|
};
|
|
490
388
|
}
|
|
491
|
-
function useGlobalsCodeMerging(
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
389
|
+
function useGlobalsCodeMerging({
|
|
390
|
+
url,
|
|
391
|
+
code,
|
|
392
|
+
globalsCode,
|
|
393
|
+
processedGlobalsCode,
|
|
394
|
+
setProcessedGlobalsCode,
|
|
395
|
+
readyForContent,
|
|
396
|
+
variants
|
|
397
|
+
}) {
|
|
398
|
+
const {
|
|
399
|
+
loadCodeMeta,
|
|
400
|
+
loadSource,
|
|
401
|
+
loadVariantMeta,
|
|
402
|
+
loadCodeVariant
|
|
403
|
+
} = useCodeContext();
|
|
504
404
|
|
|
505
405
|
// Set processedGlobalsCode if we have ready Code objects but haven't stored them yet
|
|
506
|
-
React.useEffect(
|
|
406
|
+
React.useEffect(() => {
|
|
507
407
|
if (!globalsCode || processedGlobalsCode) {
|
|
508
408
|
return; // No globals or already processed
|
|
509
409
|
}
|
|
510
410
|
|
|
511
411
|
// Check if all items are already Code objects (precomputed)
|
|
512
|
-
if (globalsCode.every(
|
|
513
|
-
|
|
514
|
-
})) {
|
|
515
|
-
var codeObjects = globalsCode;
|
|
412
|
+
if (globalsCode.every(item => typeof item === 'object')) {
|
|
413
|
+
const codeObjects = globalsCode;
|
|
516
414
|
// Check if all Code objects have all their own variants
|
|
517
|
-
|
|
518
|
-
return hasAllVariants(Object.keys(codeObj), codeObj);
|
|
519
|
-
});
|
|
415
|
+
const allReady = codeObjects.every(codeObj => hasAllVariants(Object.keys(codeObj), codeObj));
|
|
520
416
|
if (allReady) {
|
|
521
417
|
setProcessedGlobalsCode(codeObjects);
|
|
522
418
|
return;
|
|
@@ -529,149 +425,79 @@ function useGlobalsCodeMerging(_ref0) {
|
|
|
529
425
|
}
|
|
530
426
|
|
|
531
427
|
// Need to load string URLs or load missing variants
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
return Promise.all(variants.map(/*#__PURE__*/function () {
|
|
596
|
-
var _ref13 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(variantName) {
|
|
597
|
-
var result, _t5;
|
|
598
|
-
return _regenerator().w(function (_context6) {
|
|
599
|
-
while (1) switch (_context6.p = _context6.n) {
|
|
600
|
-
case 0:
|
|
601
|
-
if (!(codeObj[variantName] && _typeof(codeObj[variantName]) === 'object')) {
|
|
602
|
-
_context6.n = 1;
|
|
603
|
-
break;
|
|
604
|
-
}
|
|
605
|
-
return _context6.a(2);
|
|
606
|
-
case 1:
|
|
607
|
-
_context6.p = 1;
|
|
608
|
-
_context6.n = 2;
|
|
609
|
-
return loadCodeVariant(originalUrl || '',
|
|
610
|
-
// Use the original URL if available
|
|
611
|
-
variantName, codeObj[variantName],
|
|
612
|
-
// May be undefined or string
|
|
613
|
-
{
|
|
614
|
-
disableParsing: true,
|
|
615
|
-
disableTransforms: true,
|
|
616
|
-
loadSource: loadSource,
|
|
617
|
-
loadVariantMeta: loadVariantMeta
|
|
618
|
-
});
|
|
619
|
-
case 2:
|
|
620
|
-
result = _context6.v;
|
|
621
|
-
loadedVariants[variantName] = result.code;
|
|
622
|
-
_context6.n = 4;
|
|
623
|
-
break;
|
|
624
|
-
case 3:
|
|
625
|
-
_context6.p = 3;
|
|
626
|
-
_t5 = _context6.v;
|
|
627
|
-
console.error(new Errors.ErrorCodeHighlighterClientLoadVariantFailureForGlobals(variantName, originalUrl, _t5));
|
|
628
|
-
// Keep the original variant data (may be undefined)
|
|
629
|
-
case 4:
|
|
630
|
-
return _context6.a(2);
|
|
631
|
-
}
|
|
632
|
-
}, _callee6, null, [[1, 3]]);
|
|
633
|
-
}));
|
|
634
|
-
return function (_x4) {
|
|
635
|
-
return _ref13.apply(this, arguments);
|
|
636
|
-
};
|
|
637
|
-
}()));
|
|
638
|
-
case 2:
|
|
639
|
-
return _context7.a(2, loadedVariants);
|
|
640
|
-
}
|
|
641
|
-
}, _callee7);
|
|
642
|
-
}));
|
|
643
|
-
return function (_x3) {
|
|
644
|
-
return _ref12.apply(this, arguments);
|
|
645
|
-
};
|
|
646
|
-
}()));
|
|
647
|
-
case 2:
|
|
648
|
-
fullyLoadedCodeObjects = _context8.v;
|
|
649
|
-
setProcessedGlobalsCode(fullyLoadedCodeObjects);
|
|
650
|
-
_context8.n = 4;
|
|
651
|
-
break;
|
|
652
|
-
case 3:
|
|
653
|
-
_context8.p = 3;
|
|
654
|
-
_t6 = _context8.v;
|
|
655
|
-
console.error(new Errors.ErrorCodeHighlighterClientLoadGlobalsCodeFailure(url || 'No URL', _t6));
|
|
656
|
-
case 4:
|
|
657
|
-
return _context8.a(2);
|
|
658
|
-
}
|
|
659
|
-
}, _callee8, null, [[0, 3]]);
|
|
660
|
-
}))();
|
|
428
|
+
(async () => {
|
|
429
|
+
try {
|
|
430
|
+
// First, load any string URLs into Code objects
|
|
431
|
+
const basicCodeObjects = await Promise.all(globalsCode.map(async item => {
|
|
432
|
+
if (typeof item === 'string') {
|
|
433
|
+
if (!loadCodeMeta) {
|
|
434
|
+
throw new Errors.ErrorCodeHighlighterClientMissingLoadCodeMetaForStringUrls();
|
|
435
|
+
}
|
|
436
|
+
return {
|
|
437
|
+
codeObj: await loadCodeMeta(item),
|
|
438
|
+
originalUrl: item
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
return {
|
|
442
|
+
codeObj: item,
|
|
443
|
+
originalUrl: undefined
|
|
444
|
+
};
|
|
445
|
+
}));
|
|
446
|
+
|
|
447
|
+
// Now check if we need to load variants for any of the Code objects
|
|
448
|
+
const fullyLoadedCodeObjects = await Promise.all(basicCodeObjects.map(async ({
|
|
449
|
+
codeObj,
|
|
450
|
+
originalUrl
|
|
451
|
+
}) => {
|
|
452
|
+
// Check if this Code object has all required variants
|
|
453
|
+
if (hasAllVariants(variants, codeObj)) {
|
|
454
|
+
return codeObj; // Already has all variants
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// Need to load missing variants
|
|
458
|
+
const loadedVariants = {
|
|
459
|
+
...codeObj
|
|
460
|
+
};
|
|
461
|
+
await Promise.all(variants.map(async variantName => {
|
|
462
|
+
if (codeObj[variantName] && typeof codeObj[variantName] === 'object') {
|
|
463
|
+
return; // Variant already loaded
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// Need to load this variant
|
|
467
|
+
try {
|
|
468
|
+
const result = await loadCodeVariant(originalUrl || '',
|
|
469
|
+
// Use the original URL if available
|
|
470
|
+
variantName, codeObj[variantName],
|
|
471
|
+
// May be undefined or string
|
|
472
|
+
{
|
|
473
|
+
disableParsing: true,
|
|
474
|
+
disableTransforms: true,
|
|
475
|
+
loadSource,
|
|
476
|
+
loadVariantMeta
|
|
477
|
+
});
|
|
478
|
+
loadedVariants[variantName] = result.code;
|
|
479
|
+
} catch (error) {
|
|
480
|
+
console.error(new Errors.ErrorCodeHighlighterClientLoadVariantFailureForGlobals(variantName, originalUrl, error));
|
|
481
|
+
// Keep the original variant data (may be undefined)
|
|
482
|
+
}
|
|
483
|
+
}));
|
|
484
|
+
return loadedVariants;
|
|
485
|
+
}));
|
|
486
|
+
setProcessedGlobalsCode(fullyLoadedCodeObjects);
|
|
487
|
+
} catch (error) {
|
|
488
|
+
console.error(new Errors.ErrorCodeHighlighterClientLoadGlobalsCodeFailure(url || 'No URL', error));
|
|
489
|
+
}
|
|
490
|
+
})();
|
|
661
491
|
}, [url, globalsCode, processedGlobalsCode, setProcessedGlobalsCode, loadCodeMeta, loadSource, loadVariantMeta, variants, loadCodeVariant]);
|
|
662
492
|
|
|
663
493
|
// Determine globalsCodeObjects to use (prefer processed, fallback to direct if ready)
|
|
664
|
-
|
|
494
|
+
const globalsCodeObjects = React.useMemo(() => {
|
|
665
495
|
if (processedGlobalsCode) {
|
|
666
496
|
return processedGlobalsCode;
|
|
667
497
|
}
|
|
668
|
-
if (globalsCode && globalsCode.every(
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
var codeObjects = globalsCode;
|
|
672
|
-
var allGlobalsReady = codeObjects.every(function (codeObj) {
|
|
673
|
-
return hasAllVariants(Object.keys(codeObj), codeObj);
|
|
674
|
-
});
|
|
498
|
+
if (globalsCode && globalsCode.every(item => typeof item === 'object')) {
|
|
499
|
+
const codeObjects = globalsCode;
|
|
500
|
+
const allGlobalsReady = codeObjects.every(codeObj => hasAllVariants(Object.keys(codeObj), codeObj));
|
|
675
501
|
if (allGlobalsReady) {
|
|
676
502
|
return codeObjects;
|
|
677
503
|
}
|
|
@@ -680,7 +506,7 @@ function useGlobalsCodeMerging(_ref0) {
|
|
|
680
506
|
}, [processedGlobalsCode, globalsCode]);
|
|
681
507
|
|
|
682
508
|
// Merge globalsCode with code when ready
|
|
683
|
-
return React.useMemo(
|
|
509
|
+
return React.useMemo(() => {
|
|
684
510
|
// If no globalsCode or code not ready, return as-is
|
|
685
511
|
if (!globalsCode || !code || !readyForContent) {
|
|
686
512
|
return code;
|
|
@@ -692,37 +518,34 @@ function useGlobalsCodeMerging(_ref0) {
|
|
|
692
518
|
}
|
|
693
519
|
|
|
694
520
|
// For precomputed code, do simple synchronous merging of extraFiles
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
521
|
+
const mergedCode = {
|
|
522
|
+
...code
|
|
523
|
+
};
|
|
524
|
+
let hasChanges = false;
|
|
525
|
+
variants.forEach(variant => {
|
|
526
|
+
const variantData = code[variant];
|
|
699
527
|
if (!variantData || typeof variantData === 'string') {
|
|
700
528
|
return;
|
|
701
529
|
}
|
|
702
530
|
|
|
703
531
|
// Get globalsCode for this variant (only exact matches, no fallback)
|
|
704
|
-
|
|
705
|
-
return codeObj[variant];
|
|
706
|
-
}).filter(function (item) {
|
|
707
|
-
return Boolean(item) && _typeof(item) === 'object';
|
|
708
|
-
});
|
|
532
|
+
const globalsForVariant = globalsCodeObjects.map(codeObj => codeObj[variant]).filter(item => Boolean(item) && typeof item === 'object');
|
|
709
533
|
if (globalsForVariant.length > 0) {
|
|
710
534
|
// Use mergeCodeMetadata for sophisticated globals merging with proper positioning
|
|
711
|
-
|
|
712
|
-
globalsForVariant.forEach(
|
|
535
|
+
let currentVariant = variantData;
|
|
536
|
+
globalsForVariant.forEach(globalVariant => {
|
|
713
537
|
if (globalVariant.extraFiles) {
|
|
714
538
|
// Convert globals extraFiles to metadata format for mergeCodeMetadata
|
|
715
|
-
|
|
716
|
-
for (
|
|
717
|
-
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
718
|
-
key = _Object$entries$_i[0],
|
|
719
|
-
value = _Object$entries$_i[1];
|
|
539
|
+
const globalsMetadata = {};
|
|
540
|
+
for (const [key, value] of Object.entries(globalVariant.extraFiles)) {
|
|
720
541
|
if (typeof value === 'string') {
|
|
721
542
|
globalsMetadata[key] = {
|
|
722
543
|
source: value
|
|
723
544
|
};
|
|
724
545
|
} else {
|
|
725
|
-
globalsMetadata[key] =
|
|
546
|
+
globalsMetadata[key] = {
|
|
547
|
+
...value
|
|
548
|
+
};
|
|
726
549
|
}
|
|
727
550
|
}
|
|
728
551
|
|
|
@@ -743,53 +566,51 @@ function useGlobalsCodeMerging(_ref0) {
|
|
|
743
566
|
return hasChanges ? mergedCode : code;
|
|
744
567
|
}, [code, globalsCode, globalsCodeObjects, readyForContent, variants]);
|
|
745
568
|
}
|
|
746
|
-
function usePropsCodeGlobalsMerging(
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
569
|
+
function usePropsCodeGlobalsMerging({
|
|
570
|
+
code,
|
|
571
|
+
globalsCode,
|
|
572
|
+
processedGlobalsCode,
|
|
573
|
+
variants
|
|
574
|
+
}) {
|
|
751
575
|
// For props.code, always do synchronous merging if possible
|
|
752
576
|
// We don't want to cache this in state since props.code can change frequently
|
|
753
|
-
return React.useMemo(
|
|
577
|
+
return React.useMemo(() => {
|
|
754
578
|
if (!code || !globalsCode || !processedGlobalsCode) {
|
|
755
579
|
return code; // No merge needed or not ready
|
|
756
580
|
}
|
|
757
581
|
|
|
758
582
|
// Use processedGlobalsCode for synchronous merging
|
|
759
|
-
|
|
583
|
+
const globalsCodeObjects = processedGlobalsCode;
|
|
760
584
|
|
|
761
585
|
// For props.code (controlled), do simple synchronous merging
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
586
|
+
const mergedCode = {
|
|
587
|
+
...code
|
|
588
|
+
};
|
|
589
|
+
let hasChanges = false;
|
|
590
|
+
variants.forEach(variant => {
|
|
591
|
+
const variantData = code[variant];
|
|
766
592
|
if (!variantData || typeof variantData === 'string') {
|
|
767
593
|
return;
|
|
768
594
|
}
|
|
769
595
|
|
|
770
596
|
// Get globalsCode for this variant (only exact matches, no fallback)
|
|
771
|
-
|
|
772
|
-
return codeObj[variant];
|
|
773
|
-
}).filter(function (item) {
|
|
774
|
-
return Boolean(item) && _typeof(item) === 'object';
|
|
775
|
-
});
|
|
597
|
+
const globalsForVariant = globalsCodeObjects.map(codeObj => codeObj[variant]).filter(item => Boolean(item) && typeof item === 'object');
|
|
776
598
|
if (globalsForVariant.length > 0) {
|
|
777
599
|
// Use mergeCodeMetadata for sophisticated globals merging with proper positioning
|
|
778
|
-
|
|
779
|
-
globalsForVariant.forEach(
|
|
600
|
+
let currentVariant = variantData;
|
|
601
|
+
globalsForVariant.forEach(globalVariant => {
|
|
780
602
|
if (globalVariant.extraFiles) {
|
|
781
603
|
// Convert globals extraFiles to metadata format for mergeCodeMetadata
|
|
782
|
-
|
|
783
|
-
for (
|
|
784
|
-
var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
|
|
785
|
-
key = _Object$entries2$_i[0],
|
|
786
|
-
value = _Object$entries2$_i[1];
|
|
604
|
+
const globalsMetadata = {};
|
|
605
|
+
for (const [key, value] of Object.entries(globalVariant.extraFiles)) {
|
|
787
606
|
if (typeof value === 'string') {
|
|
788
607
|
globalsMetadata[key] = {
|
|
789
608
|
source: value
|
|
790
609
|
};
|
|
791
610
|
} else {
|
|
792
|
-
globalsMetadata[key] =
|
|
611
|
+
globalsMetadata[key] = {
|
|
612
|
+
...value
|
|
613
|
+
};
|
|
793
614
|
}
|
|
794
615
|
}
|
|
795
616
|
|
|
@@ -811,17 +632,13 @@ function usePropsCodeGlobalsMerging(_ref14) {
|
|
|
811
632
|
}, [code, globalsCode, processedGlobalsCode, variants]);
|
|
812
633
|
}
|
|
813
634
|
export function CodeHighlighterClient(props) {
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
var _React$useState5 = React.useState(_typeof(props.precompute) === 'object' ? props.precompute : undefined),
|
|
818
|
-
_React$useState6 = _slicedToArray(_React$useState5, 2),
|
|
819
|
-
code = _React$useState6[0],
|
|
820
|
-
setCode = _React$useState6[1];
|
|
635
|
+
const controlled = useControlledCode();
|
|
636
|
+
const isControlled = Boolean(props.code || controlled?.code);
|
|
637
|
+
const [code, setCode] = React.useState(typeof props.precompute === 'object' ? props.precompute : undefined);
|
|
821
638
|
|
|
822
639
|
// Sync code state with precompute prop changes (for hot-reload)
|
|
823
|
-
React.useEffect(
|
|
824
|
-
if (
|
|
640
|
+
React.useEffect(() => {
|
|
641
|
+
if (typeof props.precompute === 'object') {
|
|
825
642
|
setCode(props.precompute);
|
|
826
643
|
} else if (props.precompute === undefined) {
|
|
827
644
|
// Only reset to undefined if precompute is explicitly undefined
|
|
@@ -830,94 +647,72 @@ export function CodeHighlighterClient(props) {
|
|
|
830
647
|
}, [props.precompute]);
|
|
831
648
|
|
|
832
649
|
// State to store processed globalsCode to avoid duplicate loading
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
setProcessedGlobalsCode = _React$useState8[1];
|
|
837
|
-
var activeCode = (controlled == null ? void 0 : controlled.code) || props.code || code;
|
|
838
|
-
var variants = React.useMemo(function () {
|
|
839
|
-
return props.variants || Object.keys(props.components || activeCode || {});
|
|
840
|
-
}, [props.variants, props.components, activeCode]);
|
|
650
|
+
const [processedGlobalsCode, setProcessedGlobalsCode] = React.useState(undefined);
|
|
651
|
+
const activeCode = controlled?.code || props.code || code;
|
|
652
|
+
const variants = React.useMemo(() => props.variants || Object.keys(props.components || activeCode || {}), [props.variants, props.components, activeCode]);
|
|
841
653
|
|
|
842
654
|
// TODO: if using props.variant, then the variant is controlled and we can't use our own state
|
|
843
655
|
// does props.variant make any sense instead of controlledSelection?.variant?
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
if (_typeof(activeCode == null ? void 0 : activeCode[variantName]) === 'object') {
|
|
853
|
-
var variant = activeCode[variantName];
|
|
854
|
-
initialFilename = variant != null && variant.filesOrder ? variant.filesOrder[0] : variant == null ? void 0 : variant.fileName;
|
|
656
|
+
const [selection, setSelection] = React.useState({
|
|
657
|
+
variant: props.initialVariant || props.defaultVariant || variants[0]
|
|
658
|
+
});
|
|
659
|
+
const variantName = controlled?.selection?.variant || props.variant || selection.variant;
|
|
660
|
+
let initialFilename;
|
|
661
|
+
if (typeof activeCode?.[variantName] === 'object') {
|
|
662
|
+
const variant = activeCode[variantName];
|
|
663
|
+
initialFilename = variant?.filesOrder ? variant.filesOrder[0] : variant?.fileName;
|
|
855
664
|
}
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
665
|
+
const fileName = controlled?.selection?.fileName || props.fileName || initialFilename;
|
|
666
|
+
const {
|
|
667
|
+
url,
|
|
668
|
+
highlightAfter,
|
|
669
|
+
enhanceAfter,
|
|
670
|
+
fallbackUsesExtraFiles,
|
|
671
|
+
fallbackUsesAllVariants
|
|
672
|
+
} = props;
|
|
862
673
|
useInitialData({
|
|
863
|
-
variants
|
|
864
|
-
variantName
|
|
865
|
-
code
|
|
866
|
-
setCode
|
|
867
|
-
fileName
|
|
868
|
-
url
|
|
869
|
-
highlightAfter
|
|
870
|
-
fallbackUsesExtraFiles
|
|
871
|
-
fallbackUsesAllVariants
|
|
872
|
-
isControlled
|
|
674
|
+
variants,
|
|
675
|
+
variantName,
|
|
676
|
+
code,
|
|
677
|
+
setCode,
|
|
678
|
+
fileName,
|
|
679
|
+
url,
|
|
680
|
+
highlightAfter,
|
|
681
|
+
fallbackUsesExtraFiles,
|
|
682
|
+
fallbackUsesAllVariants,
|
|
683
|
+
isControlled,
|
|
873
684
|
globalsCode: props.globalsCode,
|
|
874
|
-
setProcessedGlobalsCode
|
|
685
|
+
setProcessedGlobalsCode
|
|
875
686
|
});
|
|
876
687
|
|
|
877
688
|
// Use useSyncExternalStore to detect hydration
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
return false;
|
|
886
|
-
}, []);
|
|
887
|
-
var useIsHydrated = function useIsHydrated() {
|
|
888
|
-
return React.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
889
|
-
};
|
|
890
|
-
var isHydrated = useIsHydrated();
|
|
891
|
-
var _React$useState1 = React.useState(enhanceAfter === 'init' || enhanceAfter === 'hydration' && isHydrated),
|
|
892
|
-
_React$useState10 = _slicedToArray(_React$useState1, 2),
|
|
893
|
-
isEnhanceAllowed = _React$useState10[0],
|
|
894
|
-
setIsEnhanceAllowed = _React$useState10[1];
|
|
895
|
-
React.useEffect(function () {
|
|
689
|
+
const subscribe = React.useCallback(() => () => {}, []);
|
|
690
|
+
const getSnapshot = React.useCallback(() => true, []);
|
|
691
|
+
const getServerSnapshot = React.useCallback(() => false, []);
|
|
692
|
+
const useIsHydrated = () => React.useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
|
|
693
|
+
const isHydrated = useIsHydrated();
|
|
694
|
+
const [isEnhanceAllowed, setIsEnhanceAllowed] = React.useState(enhanceAfter === 'init' || enhanceAfter === 'hydration' && isHydrated);
|
|
695
|
+
React.useEffect(() => {
|
|
896
696
|
if (enhanceAfter === 'idle') {
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
var idleRequest = requestIdleCallback(function () {
|
|
697
|
+
const requestIdleCallback = window.requestIdleCallback ?? setTimeout;
|
|
698
|
+
const cancelIdleCallback = window.cancelIdleCallback ?? clearTimeout;
|
|
699
|
+
const idleRequest = requestIdleCallback(() => {
|
|
901
700
|
setIsEnhanceAllowed(true);
|
|
902
701
|
});
|
|
903
|
-
return
|
|
904
|
-
return cancelIdleCallback(idleRequest);
|
|
905
|
-
};
|
|
702
|
+
return () => cancelIdleCallback(idleRequest);
|
|
906
703
|
}
|
|
907
704
|
return undefined;
|
|
908
705
|
}, [enhanceAfter]);
|
|
909
706
|
|
|
910
707
|
// Update enhance allowed state when hydration completes
|
|
911
|
-
React.useEffect(
|
|
708
|
+
React.useEffect(() => {
|
|
912
709
|
if (enhanceAfter === 'hydration' && isHydrated) {
|
|
913
710
|
// we should ensure that each code highlighter is enhanced as a separate task
|
|
914
711
|
// this should run from top to bottom
|
|
915
|
-
yieldToMain().then(
|
|
916
|
-
return setIsEnhanceAllowed(true);
|
|
917
|
-
});
|
|
712
|
+
yieldToMain().then(() => setIsEnhanceAllowed(true));
|
|
918
713
|
}
|
|
919
714
|
}, [enhanceAfter, isHydrated]);
|
|
920
|
-
|
|
715
|
+
const readyForContent = React.useMemo(() => {
|
|
921
716
|
if (!code) {
|
|
922
717
|
return false;
|
|
923
718
|
}
|
|
@@ -925,102 +720,101 @@ export function CodeHighlighterClient(props) {
|
|
|
925
720
|
}, [code, variants]);
|
|
926
721
|
|
|
927
722
|
// Separate check for activeCode to determine when to show fallback
|
|
928
|
-
|
|
723
|
+
const activeCodeReady = React.useMemo(() => {
|
|
929
724
|
if (!activeCode || !isEnhanceAllowed) {
|
|
930
725
|
return false;
|
|
931
726
|
}
|
|
932
727
|
|
|
933
728
|
// Controlled code is always ready since it comes from editing already-ready code
|
|
934
|
-
if (controlled
|
|
729
|
+
if (controlled?.code) {
|
|
935
730
|
return true;
|
|
936
731
|
}
|
|
937
732
|
|
|
938
733
|
// For regular code, use the existing hasAllVariants function
|
|
939
|
-
|
|
734
|
+
const regularCode = props.code || code;
|
|
940
735
|
return regularCode ? hasAllVariants(variants, regularCode) : false;
|
|
941
|
-
}, [activeCode, isEnhanceAllowed, controlled
|
|
736
|
+
}, [activeCode, isEnhanceAllowed, controlled?.code, variants, props.code, code]);
|
|
942
737
|
useAllVariants({
|
|
943
|
-
readyForContent
|
|
944
|
-
variants
|
|
945
|
-
isControlled
|
|
946
|
-
url
|
|
947
|
-
code
|
|
948
|
-
setCode
|
|
949
|
-
processedGlobalsCode
|
|
738
|
+
readyForContent,
|
|
739
|
+
variants,
|
|
740
|
+
isControlled,
|
|
741
|
+
url,
|
|
742
|
+
code,
|
|
743
|
+
setCode,
|
|
744
|
+
processedGlobalsCode,
|
|
950
745
|
globalsCode: props.globalsCode,
|
|
951
|
-
setProcessedGlobalsCode
|
|
746
|
+
setProcessedGlobalsCode
|
|
952
747
|
});
|
|
953
748
|
|
|
954
749
|
// Merge globalsCode with internal state code (fetched data) - this should be stable once ready
|
|
955
|
-
|
|
956
|
-
url
|
|
957
|
-
code
|
|
750
|
+
const stateCodeWithGlobals = useGlobalsCodeMerging({
|
|
751
|
+
url,
|
|
752
|
+
code,
|
|
958
753
|
// Only use internal state, not props.code
|
|
959
754
|
globalsCode: props.globalsCode,
|
|
960
|
-
processedGlobalsCode
|
|
961
|
-
setProcessedGlobalsCode
|
|
962
|
-
readyForContent
|
|
963
|
-
variants
|
|
755
|
+
processedGlobalsCode,
|
|
756
|
+
setProcessedGlobalsCode,
|
|
757
|
+
readyForContent,
|
|
758
|
+
variants
|
|
964
759
|
});
|
|
965
760
|
|
|
966
761
|
// For props.code (controlled), always re-merge when it changes (don't cache in state)
|
|
967
|
-
|
|
762
|
+
const propsCodeWithGlobals = usePropsCodeGlobalsMerging({
|
|
968
763
|
code: props.code,
|
|
969
764
|
globalsCode: props.globalsCode,
|
|
970
|
-
processedGlobalsCode
|
|
971
|
-
variants
|
|
765
|
+
processedGlobalsCode,
|
|
766
|
+
variants
|
|
972
767
|
});
|
|
973
768
|
|
|
974
769
|
// Use props.code result if available, otherwise use state code result
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
770
|
+
const codeWithGlobals = propsCodeWithGlobals || stateCodeWithGlobals;
|
|
771
|
+
const {
|
|
772
|
+
parsedCode,
|
|
773
|
+
deferHighlight
|
|
774
|
+
} = useCodeParsing({
|
|
775
|
+
code: codeWithGlobals,
|
|
776
|
+
readyForContent: readyForContent || Boolean(props.code),
|
|
777
|
+
highlightAfter,
|
|
778
|
+
isHydrated,
|
|
779
|
+
forceClient: props.forceClient,
|
|
780
|
+
url: props.url
|
|
781
|
+
});
|
|
782
|
+
const {
|
|
783
|
+
transformedCode,
|
|
784
|
+
availableTransforms
|
|
785
|
+
} = useCodeTransforms({
|
|
786
|
+
parsedCode,
|
|
787
|
+
variantName
|
|
788
|
+
});
|
|
789
|
+
const {
|
|
790
|
+
parsedControlledCode
|
|
791
|
+
} = useControlledCodeParsing({
|
|
792
|
+
code: controlled?.code,
|
|
793
|
+
forceClient: props.forceClient,
|
|
794
|
+
url: props.url
|
|
795
|
+
});
|
|
998
796
|
|
|
999
797
|
// Determine the final overlaid code (controlled takes precedence)
|
|
1000
|
-
|
|
798
|
+
const overlaidCode = parsedControlledCode || transformedCode || codeWithGlobals;
|
|
1001
799
|
|
|
1002
800
|
// For fallback context, use the processed code or fall back to non-controlled code
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
url: props.url,
|
|
1017
|
-
deferHighlight: deferHighlight
|
|
1018
|
-
};
|
|
1019
|
-
}, [overlaidCode, controlled == null ? void 0 : controlled.setCode, selection, controlled == null ? void 0 : controlled.selection, controlled == null ? void 0 : controlled.setSelection, controlled == null ? void 0 : controlled.components, props.components, isControlled, availableTransforms, props.url, deferHighlight]);
|
|
801
|
+
const codeForFallback = overlaidCode || (controlled?.code ? undefined : props.code || code);
|
|
802
|
+
const fallbackContext = React.useMemo(() => codeToFallbackProps(variantName, codeForFallback, fileName, props.fallbackUsesExtraFiles, props.fallbackUsesAllVariants), [variantName, codeForFallback, fileName, props.fallbackUsesExtraFiles, props.fallbackUsesAllVariants]);
|
|
803
|
+
const context = React.useMemo(() => ({
|
|
804
|
+
code: overlaidCode,
|
|
805
|
+
// Use processed/transformed code
|
|
806
|
+
setCode: controlled?.setCode,
|
|
807
|
+
selection: controlled?.selection || selection,
|
|
808
|
+
setSelection: controlled?.setSelection || setSelection,
|
|
809
|
+
components: controlled?.components || props.components,
|
|
810
|
+
availableTransforms: isControlled ? [] : availableTransforms,
|
|
811
|
+
url: props.url,
|
|
812
|
+
deferHighlight
|
|
813
|
+
}), [overlaidCode, controlled?.setCode, selection, controlled?.selection, controlled?.setSelection, controlled?.components, props.components, isControlled, availableTransforms, props.url, deferHighlight]);
|
|
1020
814
|
if (!props.variants && !props.components && !activeCode) {
|
|
1021
815
|
throw new Errors.ErrorCodeHighlighterClientMissingData();
|
|
1022
816
|
}
|
|
1023
|
-
|
|
817
|
+
const fallback = props.fallback;
|
|
1024
818
|
if (fallback && !props.skipFallback && !activeCodeReady) {
|
|
1025
819
|
return /*#__PURE__*/_jsx(CodeHighlighterFallbackContext.Provider, {
|
|
1026
820
|
value: fallbackContext,
|