@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,9 +1,3 @@
|
|
|
1
|
-
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
2
|
-
import _regenerator from "@babel/runtime/helpers/esm/regenerator";
|
|
3
|
-
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
4
|
-
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
5
|
-
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
6
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
7
1
|
import * as React from 'react';
|
|
8
2
|
import { loadCodeVariant } from "../pipeline/loadCodeVariant/loadCodeVariant.js";
|
|
9
3
|
import { loadCodeFallback } from "../pipeline/loadCodeVariant/loadCodeFallback.js";
|
|
@@ -14,19 +8,20 @@ import { getFileNameFromUrl, getLanguageFromExtension } from "../pipeline/loader
|
|
|
14
8
|
import { codeToFallbackProps } from "./codeToFallbackProps.js";
|
|
15
9
|
import * as Errors from "./errors.js";
|
|
16
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
|
-
|
|
11
|
+
const DEBUG = false; // Set to true for debugging purposes
|
|
18
12
|
|
|
19
13
|
function createClientProps(props) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
const highlightAfter = props.highlightAfter === 'stream' ? 'init' : props.highlightAfter;
|
|
15
|
+
const enhanceAfter = props.enhanceAfter === 'stream' ? 'init' : props.enhanceAfter;
|
|
16
|
+
const contentProps = {
|
|
23
17
|
code: props.code || props.precompute,
|
|
24
18
|
components: props.components,
|
|
25
19
|
name: props.name,
|
|
26
20
|
slug: props.slug,
|
|
27
21
|
url: props.url,
|
|
28
|
-
variantType: props.variantType
|
|
29
|
-
|
|
22
|
+
variantType: props.variantType,
|
|
23
|
+
...props.contentProps
|
|
24
|
+
};
|
|
30
25
|
return {
|
|
31
26
|
url: props.url,
|
|
32
27
|
code: props.code,
|
|
@@ -49,386 +44,306 @@ function createClientProps(props) {
|
|
|
49
44
|
// otherwise we will get an error because functions can't be serialized
|
|
50
45
|
// On the client, in order to send data to these components, we have to set context
|
|
51
46
|
fallback: props.fallback,
|
|
52
|
-
children: /*#__PURE__*/_jsx(props.Content,
|
|
47
|
+
children: /*#__PURE__*/_jsx(props.Content, {
|
|
48
|
+
...contentProps
|
|
49
|
+
})
|
|
53
50
|
};
|
|
54
51
|
}
|
|
55
|
-
function CodeSourceLoader(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
case 2:
|
|
82
|
-
_context2.p = 2;
|
|
83
|
-
_context2.n = 3;
|
|
84
|
-
return props.loadCodeMeta(props.url);
|
|
85
|
-
case 3:
|
|
86
|
-
loadedCode = _context2.v;
|
|
87
|
-
_context2.n = 5;
|
|
88
|
-
break;
|
|
89
|
-
case 4:
|
|
90
|
-
_context2.p = 4;
|
|
91
|
-
_t2 = _context2.v;
|
|
92
|
-
throw new Errors.ErrorCodeHighlighterServerLoadCodeFailure(props.url, _t2);
|
|
93
|
-
case 5:
|
|
94
|
-
// TODO: if props.variant is provided, we should only load that variant
|
|
95
|
-
// Process globalsCode: use already processed version if available, otherwise convert string URLs to Code objects
|
|
96
|
-
processedGlobalsCode = props.processedGlobalsCode;
|
|
97
|
-
if (!(!processedGlobalsCode && props.globalsCode && props.globalsCode.length > 0)) {
|
|
98
|
-
_context2.n = 8;
|
|
99
|
-
break;
|
|
100
|
-
}
|
|
101
|
-
hasStringUrls = props.globalsCode.some(function (item) {
|
|
102
|
-
return typeof item === 'string';
|
|
103
|
-
});
|
|
104
|
-
if (!(hasStringUrls && !props.loadCodeMeta)) {
|
|
105
|
-
_context2.n = 6;
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
throw new Errors.ErrorCodeHighlighterServerMissingLoadCodeMetaForGlobals();
|
|
109
|
-
case 6:
|
|
110
|
-
// Load all string URLs in parallel, keep Code objects as-is
|
|
111
|
-
globalsPromises = props.globalsCode.map(/*#__PURE__*/function () {
|
|
112
|
-
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(globalItem) {
|
|
113
|
-
var _t;
|
|
114
|
-
return _regenerator().w(function (_context) {
|
|
115
|
-
while (1) switch (_context.p = _context.n) {
|
|
116
|
-
case 0:
|
|
117
|
-
if (!(typeof globalItem === 'string')) {
|
|
118
|
-
_context.n = 4;
|
|
119
|
-
break;
|
|
120
|
-
}
|
|
121
|
-
_context.p = 1;
|
|
122
|
-
_context.n = 2;
|
|
123
|
-
return props.loadCodeMeta(globalItem);
|
|
124
|
-
case 2:
|
|
125
|
-
return _context.a(2, _context.v);
|
|
126
|
-
case 3:
|
|
127
|
-
_context.p = 3;
|
|
128
|
-
_t = _context.v;
|
|
129
|
-
throw new Errors.ErrorCodeHighlighterServerLoadGlobalsFailure(globalItem, _t);
|
|
130
|
-
case 4:
|
|
131
|
-
return _context.a(2, globalItem);
|
|
132
|
-
case 5:
|
|
133
|
-
return _context.a(2);
|
|
134
|
-
}
|
|
135
|
-
}, _callee, null, [[1, 3]]);
|
|
136
|
-
}));
|
|
137
|
-
return function (_x4) {
|
|
138
|
-
return _ref.apply(this, arguments);
|
|
139
|
-
};
|
|
140
|
-
}());
|
|
141
|
-
_context2.n = 7;
|
|
142
|
-
return Promise.all(globalsPromises);
|
|
143
|
-
case 7:
|
|
144
|
-
processedGlobalsCode = _context2.v;
|
|
145
|
-
case 8:
|
|
146
|
-
variantNames = Object.keys(props.components || loadedCode || {});
|
|
147
|
-
_context2.n = 9;
|
|
148
|
-
return Promise.all(variantNames.map(function (variantName) {
|
|
149
|
-
var variantCode = loadedCode[variantName];
|
|
150
|
-
var variantUrl = _typeof(variantCode) === 'object' && variantCode != null && variantCode.url ? variantCode.url : props.url;
|
|
52
|
+
async function CodeSourceLoader(props) {
|
|
53
|
+
// Start with the loaded code from precompute, or load it if needed
|
|
54
|
+
let loadedCode = props.code || props.precompute;
|
|
55
|
+
if (!loadedCode) {
|
|
56
|
+
if (!props.loadCodeMeta) {
|
|
57
|
+
throw new Errors.ErrorCodeHighlighterServerMissingLoadCodeMeta();
|
|
58
|
+
}
|
|
59
|
+
if (!props.url) {
|
|
60
|
+
throw new Errors.ErrorCodeHighlighterServerMissingUrlForLoadCodeMeta();
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
loadedCode = await props.loadCodeMeta(props.url);
|
|
64
|
+
} catch (error) {
|
|
65
|
+
throw new Errors.ErrorCodeHighlighterServerLoadCodeFailure(props.url, error);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// TODO: if props.variant is provided, we should only load that variant
|
|
70
|
+
|
|
71
|
+
// Process globalsCode: use already processed version if available, otherwise convert string URLs to Code objects
|
|
72
|
+
let processedGlobalsCode = props.processedGlobalsCode;
|
|
73
|
+
if (!processedGlobalsCode && props.globalsCode && props.globalsCode.length > 0) {
|
|
74
|
+
const hasStringUrls = props.globalsCode.some(item => typeof item === 'string');
|
|
75
|
+
if (hasStringUrls && !props.loadCodeMeta) {
|
|
76
|
+
throw new Errors.ErrorCodeHighlighterServerMissingLoadCodeMetaForGlobals();
|
|
77
|
+
}
|
|
151
78
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
resolvedGlobalsCode.push(targetVariant);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
} catch (err) {
|
|
168
|
-
_iterator.e(err);
|
|
169
|
-
} finally {
|
|
170
|
-
_iterator.f();
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
var output = 'hastGzip';
|
|
174
|
-
if (props.deferParsing === 'json') {
|
|
175
|
-
output = 'hastJson';
|
|
176
|
-
} else if (props.deferParsing === 'none') {
|
|
177
|
-
output = 'hast';
|
|
178
|
-
}
|
|
179
|
-
return loadCodeVariant(variantUrl, variantName, variantCode, {
|
|
180
|
-
sourceParser: props.sourceParser,
|
|
181
|
-
loadSource: props.loadSource,
|
|
182
|
-
loadVariantMeta: props.loadVariantMeta,
|
|
183
|
-
sourceTransformers: props.sourceTransformers,
|
|
184
|
-
globalsCode: resolvedGlobalsCode,
|
|
185
|
-
output: output
|
|
186
|
-
}).then(function (variant) {
|
|
187
|
-
return {
|
|
188
|
-
name: variantName,
|
|
189
|
-
variant: variant
|
|
190
|
-
};
|
|
191
|
-
})["catch"](function (error) {
|
|
192
|
-
return {
|
|
193
|
-
error: error
|
|
194
|
-
};
|
|
195
|
-
});
|
|
196
|
-
}));
|
|
197
|
-
case 9:
|
|
198
|
-
variantCodes = _context2.v;
|
|
199
|
-
processedCode = {};
|
|
200
|
-
errors = [];
|
|
201
|
-
_iterator2 = _createForOfIteratorHelper(variantCodes);
|
|
202
|
-
try {
|
|
203
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
204
|
-
item = _step2.value;
|
|
205
|
-
if ('error' in item) {
|
|
206
|
-
console.error(new Errors.ErrorCodeHighlighterServerLoadVariantFailure(props.url, item.error));
|
|
207
|
-
errors.push(item.error);
|
|
208
|
-
} else {
|
|
209
|
-
processedCode[item.name] = item.variant.code;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
} catch (err) {
|
|
213
|
-
_iterator2.e(err);
|
|
214
|
-
} finally {
|
|
215
|
-
_iterator2.f();
|
|
216
|
-
}
|
|
217
|
-
if (!(errors.length > 0)) {
|
|
218
|
-
_context2.n = 10;
|
|
219
|
-
break;
|
|
220
|
-
}
|
|
221
|
-
throw new Errors.ErrorCodeHighlighterServerLoadVariantsFailure(props.url, errors);
|
|
222
|
-
case 10:
|
|
223
|
-
clientProps = createClientProps(_extends(_extends({}, props), {}, {
|
|
224
|
-
code: processedCode,
|
|
225
|
-
processedGlobalsCode: processedGlobalsCode
|
|
226
|
-
}));
|
|
227
|
-
return _context2.a(2, /*#__PURE__*/_jsx(CodeHighlighterClient, _extends({}, clientProps)));
|
|
79
|
+
// Load all string URLs in parallel, keep Code objects as-is
|
|
80
|
+
const globalsPromises = props.globalsCode.map(async globalItem => {
|
|
81
|
+
if (typeof globalItem === 'string') {
|
|
82
|
+
// String URL - load Code object via loadCodeMeta
|
|
83
|
+
try {
|
|
84
|
+
return await props.loadCodeMeta(globalItem);
|
|
85
|
+
} catch (error) {
|
|
86
|
+
throw new Errors.ErrorCodeHighlighterServerLoadGlobalsFailure(globalItem, error);
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
// Code object - return as-is
|
|
90
|
+
return globalItem;
|
|
228
91
|
}
|
|
229
|
-
}
|
|
92
|
+
});
|
|
93
|
+
processedGlobalsCode = await Promise.all(globalsPromises);
|
|
94
|
+
}
|
|
95
|
+
const variantNames = Object.keys(props.components || loadedCode || {});
|
|
96
|
+
const variantCodes = await Promise.all(variantNames.map(variantName => {
|
|
97
|
+
const variantCode = loadedCode[variantName];
|
|
98
|
+
const variantUrl = typeof variantCode === 'object' && variantCode?.url ? variantCode.url : props.url;
|
|
99
|
+
|
|
100
|
+
// Convert processedGlobalsCode to VariantCode | string for this specific variant
|
|
101
|
+
let resolvedGlobalsCode;
|
|
102
|
+
if (processedGlobalsCode && processedGlobalsCode.length > 0) {
|
|
103
|
+
resolvedGlobalsCode = [];
|
|
104
|
+
for (const codeObj of processedGlobalsCode) {
|
|
105
|
+
// Only include if this variant exists in the globalsCode
|
|
106
|
+
const targetVariant = codeObj[variantName];
|
|
107
|
+
if (targetVariant) {
|
|
108
|
+
resolvedGlobalsCode.push(targetVariant);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
let output = 'hastGzip';
|
|
113
|
+
if (props.deferParsing === 'json') {
|
|
114
|
+
output = 'hastJson';
|
|
115
|
+
} else if (props.deferParsing === 'none') {
|
|
116
|
+
output = 'hast';
|
|
117
|
+
}
|
|
118
|
+
return loadCodeVariant(variantUrl, variantName, variantCode, {
|
|
119
|
+
sourceParser: props.sourceParser,
|
|
120
|
+
loadSource: props.loadSource,
|
|
121
|
+
loadVariantMeta: props.loadVariantMeta,
|
|
122
|
+
sourceTransformers: props.sourceTransformers,
|
|
123
|
+
globalsCode: resolvedGlobalsCode,
|
|
124
|
+
output
|
|
125
|
+
}).then(variant => ({
|
|
126
|
+
name: variantName,
|
|
127
|
+
variant
|
|
128
|
+
})).catch(error => ({
|
|
129
|
+
error
|
|
130
|
+
}));
|
|
230
131
|
}));
|
|
231
|
-
|
|
132
|
+
const processedCode = {};
|
|
133
|
+
const errors = [];
|
|
134
|
+
for (const item of variantCodes) {
|
|
135
|
+
if ('error' in item) {
|
|
136
|
+
console.error(new Errors.ErrorCodeHighlighterServerLoadVariantFailure(props.url, item.error));
|
|
137
|
+
errors.push(item.error);
|
|
138
|
+
} else {
|
|
139
|
+
processedCode[item.name] = item.variant.code;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (errors.length > 0) {
|
|
143
|
+
throw new Errors.ErrorCodeHighlighterServerLoadVariantsFailure(props.url, errors);
|
|
144
|
+
}
|
|
145
|
+
const clientProps = createClientProps({
|
|
146
|
+
...props,
|
|
147
|
+
code: processedCode,
|
|
148
|
+
processedGlobalsCode
|
|
149
|
+
});
|
|
150
|
+
return /*#__PURE__*/_jsx(CodeHighlighterClient, {
|
|
151
|
+
...clientProps
|
|
152
|
+
});
|
|
232
153
|
}
|
|
233
154
|
function renderCodeHighlighter(props) {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
155
|
+
const code = props.code || props.precompute;
|
|
156
|
+
const variants = props.variants || Object.keys(props.components || code || {});
|
|
157
|
+
const allCodeVariantsLoaded = code && hasAllVariants(variants, code, true);
|
|
237
158
|
|
|
238
159
|
// Check if any loader functions are available before trying async loading
|
|
239
|
-
|
|
160
|
+
const hasAnyLoaderFunction = !!(props.loadCodeMeta || props.loadVariantMeta || props.loadSource || props.sourceParser || props.sourceTransformers);
|
|
240
161
|
if (!allCodeVariantsLoaded && hasAnyLoaderFunction && !props.forceClient) {
|
|
241
|
-
return /*#__PURE__*/_jsx(CodeSourceLoader,
|
|
162
|
+
return /*#__PURE__*/_jsx(CodeSourceLoader, {
|
|
163
|
+
...props
|
|
164
|
+
});
|
|
242
165
|
}
|
|
243
|
-
|
|
244
|
-
return /*#__PURE__*/_jsx(CodeHighlighterClient,
|
|
166
|
+
const clientProps = createClientProps(props);
|
|
167
|
+
return /*#__PURE__*/_jsx(CodeHighlighterClient, {
|
|
168
|
+
...clientProps
|
|
169
|
+
});
|
|
245
170
|
}
|
|
246
171
|
|
|
247
172
|
/**
|
|
248
173
|
* Ensures that the suspense boundary is always rendered, even if none of the children have async operations.
|
|
249
174
|
*/
|
|
250
|
-
function CodeHighlighterSuspense(
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
return _regenerator().w(function (_context3) {
|
|
256
|
-
while (1) switch (_context3.n) {
|
|
257
|
-
case 0:
|
|
258
|
-
_context3.n = 1;
|
|
259
|
-
return new Promise(function (resolve) {
|
|
260
|
-
setTimeout(resolve, 0);
|
|
261
|
-
});
|
|
262
|
-
case 1:
|
|
263
|
-
return _context3.a(2, props.children);
|
|
264
|
-
}
|
|
265
|
-
}, _callee3);
|
|
266
|
-
}));
|
|
267
|
-
return _CodeHighlighterSuspense.apply(this, arguments);
|
|
175
|
+
async function CodeHighlighterSuspense(props) {
|
|
176
|
+
await new Promise(resolve => {
|
|
177
|
+
setTimeout(resolve, 0);
|
|
178
|
+
});
|
|
179
|
+
return props.children;
|
|
268
180
|
}
|
|
269
181
|
function renderWithInitialSource(props) {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
slug
|
|
274
|
-
name
|
|
275
|
-
initialVariant
|
|
276
|
-
code
|
|
277
|
-
initialFilename
|
|
278
|
-
fallbackUsesExtraFiles
|
|
279
|
-
fallbackUsesAllVariants
|
|
280
|
-
|
|
182
|
+
const ContentLoading = props.ContentLoading;
|
|
183
|
+
const {
|
|
184
|
+
url,
|
|
185
|
+
slug,
|
|
186
|
+
name,
|
|
187
|
+
initialVariant,
|
|
188
|
+
code,
|
|
189
|
+
initialFilename,
|
|
190
|
+
fallbackUsesExtraFiles,
|
|
191
|
+
fallbackUsesAllVariants
|
|
192
|
+
} = props;
|
|
193
|
+
const fallbackProps = codeToFallbackProps(initialVariant, code, initialFilename, fallbackUsesExtraFiles, fallbackUsesAllVariants);
|
|
281
194
|
|
|
282
195
|
// Get the component for the selected variant
|
|
283
|
-
|
|
196
|
+
const component = props.components?.[initialVariant];
|
|
284
197
|
|
|
285
198
|
// Only include components (plural) if we're also including extraVariants
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
name
|
|
289
|
-
slug
|
|
290
|
-
url
|
|
291
|
-
initialFilename
|
|
292
|
-
component
|
|
293
|
-
components
|
|
294
|
-
|
|
295
|
-
|
|
199
|
+
const components = fallbackProps.extraVariants ? props.components : undefined;
|
|
200
|
+
const contentProps = {
|
|
201
|
+
name,
|
|
202
|
+
slug,
|
|
203
|
+
url,
|
|
204
|
+
initialFilename,
|
|
205
|
+
component,
|
|
206
|
+
components,
|
|
207
|
+
...fallbackProps,
|
|
208
|
+
...props.contentProps
|
|
209
|
+
};
|
|
210
|
+
const fallback = /*#__PURE__*/_jsx(ContentLoading, {
|
|
211
|
+
...contentProps
|
|
212
|
+
});
|
|
296
213
|
if (props.highlightAfter === 'stream' && !props.forceClient) {
|
|
297
214
|
return /*#__PURE__*/_jsx(React.Suspense, {
|
|
298
215
|
fallback: fallback,
|
|
299
216
|
children: /*#__PURE__*/_jsx(CodeHighlighterSuspense, {
|
|
300
|
-
children: renderCodeHighlighter(
|
|
301
|
-
|
|
217
|
+
children: renderCodeHighlighter({
|
|
218
|
+
...props,
|
|
219
|
+
fallback,
|
|
302
220
|
skipFallback: props.enhanceAfter === 'stream'
|
|
303
|
-
})
|
|
221
|
+
})
|
|
304
222
|
})
|
|
305
223
|
});
|
|
306
224
|
}
|
|
307
|
-
return renderCodeHighlighter(
|
|
308
|
-
|
|
309
|
-
|
|
225
|
+
return renderCodeHighlighter({
|
|
226
|
+
...props,
|
|
227
|
+
fallback
|
|
228
|
+
});
|
|
310
229
|
}
|
|
311
|
-
function CodeInitialSourceLoader(
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
}));
|
|
365
|
-
return _CodeInitialSourceLoader.apply(this, arguments);
|
|
230
|
+
async function CodeInitialSourceLoader(props) {
|
|
231
|
+
const {
|
|
232
|
+
url,
|
|
233
|
+
initialVariant,
|
|
234
|
+
highlightAfter,
|
|
235
|
+
fallbackUsesExtraFiles,
|
|
236
|
+
fallbackUsesAllVariants,
|
|
237
|
+
sourceParser,
|
|
238
|
+
loadSource,
|
|
239
|
+
loadVariantMeta,
|
|
240
|
+
loadCodeMeta,
|
|
241
|
+
fileName,
|
|
242
|
+
variants,
|
|
243
|
+
globalsCode,
|
|
244
|
+
ContentLoading
|
|
245
|
+
} = props;
|
|
246
|
+
if (!url) {
|
|
247
|
+
throw new Errors.ErrorCodeHighlighterServerMissingUrl();
|
|
248
|
+
}
|
|
249
|
+
let output = 'hastGzip';
|
|
250
|
+
if (props.deferParsing === 'json') {
|
|
251
|
+
output = 'hastJson';
|
|
252
|
+
} else if (props.deferParsing === 'none') {
|
|
253
|
+
output = 'hast';
|
|
254
|
+
}
|
|
255
|
+
const {
|
|
256
|
+
code,
|
|
257
|
+
initialFilename,
|
|
258
|
+
initialSource,
|
|
259
|
+
initialExtraFiles,
|
|
260
|
+
processedGlobalsCode
|
|
261
|
+
} = await loadCodeFallback(url, initialVariant, props.code, {
|
|
262
|
+
shouldHighlight: highlightAfter === 'init',
|
|
263
|
+
fallbackUsesExtraFiles,
|
|
264
|
+
fallbackUsesAllVariants,
|
|
265
|
+
sourceParser,
|
|
266
|
+
loadSource,
|
|
267
|
+
loadVariantMeta,
|
|
268
|
+
loadCodeMeta,
|
|
269
|
+
initialFilename: fileName,
|
|
270
|
+
variants,
|
|
271
|
+
globalsCode,
|
|
272
|
+
output
|
|
273
|
+
});
|
|
274
|
+
return renderWithInitialSource({
|
|
275
|
+
...props,
|
|
276
|
+
ContentLoading,
|
|
277
|
+
code,
|
|
278
|
+
initialFilename,
|
|
279
|
+
initialSource,
|
|
280
|
+
initialExtraFiles,
|
|
281
|
+
processedGlobalsCode
|
|
282
|
+
});
|
|
366
283
|
}
|
|
367
284
|
export function CodeHighlighter(props) {
|
|
368
|
-
var _code, _props$precompute, _props$components2;
|
|
369
285
|
// Validate mutually exclusive props
|
|
370
286
|
if (props.children && (props.code || props.precompute)) {
|
|
371
287
|
throw new Errors.ErrorCodeHighlighterServerInvalidProps();
|
|
372
288
|
}
|
|
373
289
|
|
|
374
290
|
// Handle children as string -> Default variant
|
|
375
|
-
|
|
291
|
+
let code = props.code;
|
|
376
292
|
if (props.children && typeof props.children === 'string') {
|
|
377
|
-
|
|
293
|
+
const fileName = props.fileName || (props.url ? getFileNameFromUrl(props.url).fileName : undefined);
|
|
378
294
|
// Derive language: use explicit prop, or derive from fileName extension
|
|
379
|
-
|
|
295
|
+
let language = props.language;
|
|
380
296
|
if (!language && fileName) {
|
|
381
|
-
|
|
297
|
+
const extension = fileName.slice(fileName.lastIndexOf('.'));
|
|
382
298
|
language = getLanguageFromExtension(extension);
|
|
383
299
|
}
|
|
384
300
|
code = {
|
|
385
301
|
Default: {
|
|
386
|
-
fileName
|
|
387
|
-
language
|
|
302
|
+
fileName,
|
|
303
|
+
language,
|
|
388
304
|
source: props.children,
|
|
389
305
|
url: props.url
|
|
390
306
|
}
|
|
391
307
|
};
|
|
392
308
|
}
|
|
393
|
-
|
|
309
|
+
const variants = props.variants || Object.keys(props.components || code || props.precompute || {});
|
|
394
310
|
if (variants.length === 0) {
|
|
395
311
|
throw new Errors.ErrorCodeHighlighterServerMissingData();
|
|
396
312
|
}
|
|
397
313
|
|
|
398
314
|
// Validate fileName is provided when extraFiles are present
|
|
399
315
|
if (code) {
|
|
400
|
-
for (
|
|
401
|
-
|
|
402
|
-
variantName = _Object$entries$_i[0],
|
|
403
|
-
variantCode = _Object$entries$_i[1];
|
|
404
|
-
if (_typeof(variantCode) === 'object' && variantCode != null && variantCode.extraFiles && Object.keys(variantCode.extraFiles).length > 0 && !variantCode.fileName && !variantCode.url) {
|
|
316
|
+
for (const [variantName, variantCode] of Object.entries(code)) {
|
|
317
|
+
if (typeof variantCode === 'object' && variantCode?.extraFiles && Object.keys(variantCode.extraFiles).length > 0 && !variantCode.fileName && !variantCode.url) {
|
|
405
318
|
throw new Errors.ErrorCodeHighlighterServerMissingFileName(variantName);
|
|
406
319
|
}
|
|
407
320
|
}
|
|
408
321
|
}
|
|
409
|
-
|
|
322
|
+
const ContentLoading = props.ContentLoading;
|
|
410
323
|
if (!ContentLoading) {
|
|
411
324
|
if (props.highlightAfter === 'stream') {
|
|
412
325
|
// if the user explicitly sets highlightAfter to 'stream', we need a ContentLoading component
|
|
413
326
|
throw new Errors.ErrorCodeHighlighterServerMissingContentLoading();
|
|
414
327
|
}
|
|
415
|
-
return renderCodeHighlighter(
|
|
416
|
-
|
|
417
|
-
|
|
328
|
+
return renderCodeHighlighter({
|
|
329
|
+
...props,
|
|
330
|
+
code
|
|
331
|
+
});
|
|
418
332
|
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
if (!initial && !
|
|
333
|
+
const initialKey = props.initialVariant || props.variant || props.defaultVariant || variants[0];
|
|
334
|
+
const initial = code?.[initialKey] || props.precompute?.[initialKey];
|
|
335
|
+
if (!initial && !props.components?.[initialKey]) {
|
|
422
336
|
throw new Errors.ErrorCodeHighlighterServerMissingVariant(initialKey);
|
|
423
337
|
}
|
|
424
338
|
|
|
425
339
|
// TODO: use initial.filesOrder to determing which source to use
|
|
426
340
|
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
341
|
+
const {
|
|
342
|
+
initialData,
|
|
343
|
+
reason
|
|
344
|
+
} = maybeCodeInitialData(variants, initialKey, code || props.precompute, undefined,
|
|
345
|
+
// TODO: use initial.filesOrder if provided?
|
|
346
|
+
props.highlightAfter === 'init', props.fallbackUsesExtraFiles, props.fallbackUsesAllVariants);
|
|
432
347
|
if (!initialData) {
|
|
433
348
|
if (DEBUG) {
|
|
434
349
|
// eslint-disable-next-line no-console
|
|
@@ -436,28 +351,31 @@ export function CodeHighlighter(props) {
|
|
|
436
351
|
}
|
|
437
352
|
|
|
438
353
|
// Check if any loader functions are available
|
|
439
|
-
|
|
354
|
+
const hasAnyLoaderFunction = !!(props.loadCodeMeta || props.loadVariantMeta || props.loadSource || props.sourceParser || props.sourceTransformers);
|
|
440
355
|
|
|
441
356
|
// If no loader functions are available, skip async loading and go directly to client
|
|
442
357
|
if (!hasAnyLoaderFunction || props.forceClient) {
|
|
443
358
|
if (props.highlightAfter === 'init') {
|
|
444
359
|
throw new Errors.ErrorCodeHighlighterServerInvalidClientMode();
|
|
445
360
|
}
|
|
446
|
-
return renderCodeHighlighter(
|
|
447
|
-
|
|
448
|
-
|
|
361
|
+
return renderCodeHighlighter({
|
|
362
|
+
...props,
|
|
363
|
+
code
|
|
364
|
+
});
|
|
449
365
|
}
|
|
450
|
-
return /*#__PURE__*/_jsx(CodeInitialSourceLoader,
|
|
366
|
+
return /*#__PURE__*/_jsx(CodeInitialSourceLoader, {
|
|
367
|
+
...props,
|
|
451
368
|
ContentLoading: ContentLoading,
|
|
452
369
|
initialVariant: initialKey
|
|
453
|
-
})
|
|
370
|
+
});
|
|
454
371
|
}
|
|
455
|
-
return renderWithInitialSource(
|
|
372
|
+
return renderWithInitialSource({
|
|
373
|
+
...props,
|
|
456
374
|
code: initialData.code,
|
|
457
|
-
ContentLoading
|
|
375
|
+
ContentLoading,
|
|
458
376
|
initialVariant: initialKey,
|
|
459
377
|
initialFilename: initialData.initialFilename,
|
|
460
378
|
initialSource: initialData.initialSource,
|
|
461
379
|
initialExtraFiles: initialData.initialExtraFiles
|
|
462
|
-
})
|
|
380
|
+
});
|
|
463
381
|
}
|