@mui/internal-docs-infra 0.2.0-alpha.1 → 0.2.0
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/CodeHighlighter/CodeHighlighter.js +54 -39
- package/esm/CodeHighlighter/CodeHighlighterClient.js +77 -33
- package/esm/CodeHighlighter/errors.js +1 -1
- package/esm/CodeHighlighter/loadFallbackCode.js +6 -2
- package/esm/CodeHighlighter/loadVariant.js +64 -22
- package/esm/CodeHighlighter/maybeInitialData.d.ts +2 -2
- package/esm/CodeHighlighter/maybeInitialData.js +2 -2
- package/esm/CodeHighlighter/transformSource.js +57 -17
- package/esm/CodeHighlighter/types.d.ts +20 -3
- package/esm/abstractCreateDemo/abstractCreateDemo.d.ts +4 -2
- package/esm/abstractCreateDemo/abstractCreateDemo.js +2 -1
- package/esm/pipeline/hastUtils/hastUtils.d.ts +6 -0
- package/esm/pipeline/hastUtils/hastUtils.js +20 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.ts +3 -1
- package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +2 -1
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.d.ts +6 -4
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +443 -258
- package/esm/pipeline/loadServerSource/loadServerSource.js +59 -19
- package/esm/pipeline/loaderUtils/index.d.ts +1 -1
- package/esm/pipeline/loaderUtils/index.js +1 -1
- package/esm/pipeline/loaderUtils/parseImportsAndComments.d.ts +91 -0
- package/esm/pipeline/loaderUtils/parseImportsAndComments.js +1329 -0
- package/esm/pipeline/loaderUtils/processRelativeImports.d.ts +8 -3
- package/esm/pipeline/loaderUtils/processRelativeImports.js +237 -118
- package/esm/pipeline/loaderUtils/resolveModulePath.d.ts +7 -3
- package/esm/pipeline/loaderUtils/resolveModulePath.js +3 -3
- package/esm/pipeline/loaderUtils/resolveModulePathWithFs.d.ts +4 -0
- package/esm/pipeline/loaderUtils/rewriteImports.d.ts +12 -5
- package/esm/pipeline/loaderUtils/rewriteImports.js +56 -26
- package/esm/pipeline/transformHtmlCodePrecomputed/index.d.ts +2 -0
- package/esm/pipeline/transformHtmlCodePrecomputed/index.js +4 -0
- package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.d.ts +13 -0
- package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.js +415 -0
- package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +304 -47
- package/esm/useCode/Pre.js +5 -0
- package/esm/useCode/useFileNavigation.js +4 -0
- package/esm/withDocsInfra/withDocsInfra.d.ts +12 -1
- package/esm/withDocsInfra/withDocsInfra.js +34 -6
- package/package.json +6 -4
- package/esm/pipeline/loaderUtils/parseImports.d.ts +0 -19
- package/esm/pipeline/loaderUtils/parseImports.js +0 -306
- package/esm/pipeline/transformHtmlCode/index.d.ts +0 -2
- package/esm/pipeline/transformHtmlCode/index.js +0 -4
- package/esm/pipeline/transformHtmlCode/transformHtmlCode.d.ts +0 -13
- package/esm/pipeline/transformHtmlCode/transformHtmlCode.js +0 -300
|
@@ -68,7 +68,7 @@ import { hasAllVariants } from "./hasAllVariants.js";
|
|
|
68
68
|
* initialKey,
|
|
69
69
|
* code || props.precompute,
|
|
70
70
|
* undefined,
|
|
71
|
-
*
|
|
71
|
+
* highlightAfter === 'init',
|
|
72
72
|
* props.fallbackUsesExtraFiles,
|
|
73
73
|
* props.fallbackUsesAllVariants,
|
|
74
74
|
* );
|
|
@@ -85,7 +85,7 @@ import { hasAllVariants } from "./hasAllVariants.js";
|
|
|
85
85
|
* variantName,
|
|
86
86
|
* code,
|
|
87
87
|
* fileName,
|
|
88
|
-
*
|
|
88
|
+
* highlightAfter === 'init',
|
|
89
89
|
* fallbackUsesExtraFiles,
|
|
90
90
|
* fallbackUsesAllVariants,
|
|
91
91
|
* ), [dependencies]);
|
|
@@ -3,10 +3,24 @@ import _regenerator from "@babel/runtime/helpers/esm/regenerator";
|
|
|
3
3
|
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
4
4
|
import { create } from 'jsondiffpatch';
|
|
5
5
|
import { toText } from 'hast-util-to-text';
|
|
6
|
+
import { decompress, strFromU8 } from 'fflate';
|
|
7
|
+
import { decode } from 'uint8-to-base64';
|
|
6
8
|
var differ = create({
|
|
7
9
|
omitRemovedValues: true,
|
|
8
10
|
cloneDiffValues: true
|
|
9
11
|
});
|
|
12
|
+
function decompressAsync(input) {
|
|
13
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
14
|
+
return new Promise(function (resolve, reject) {
|
|
15
|
+
decompress(input, options, function (err, output) {
|
|
16
|
+
if (err) {
|
|
17
|
+
reject(err);
|
|
18
|
+
} else {
|
|
19
|
+
resolve(output);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
}
|
|
10
24
|
export function transformSource(_x, _x2, _x3) {
|
|
11
25
|
return _transformSource.apply(this, arguments);
|
|
12
26
|
}
|
|
@@ -19,7 +33,7 @@ function _transformSource() {
|
|
|
19
33
|
_context2.n = 1;
|
|
20
34
|
return Promise.all(sourceTransformers.map(/*#__PURE__*/function () {
|
|
21
35
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
|
|
22
|
-
var extensions, transformer, sourceString, transformed, splitSource, _t;
|
|
36
|
+
var extensions, transformer, sourceString, decompressed, transformed, splitSource, _t, _t2;
|
|
23
37
|
return _regenerator().w(function (_context) {
|
|
24
38
|
while (1) switch (_context.p = _context.n) {
|
|
25
39
|
case 0:
|
|
@@ -33,19 +47,45 @@ function _transformSource() {
|
|
|
33
47
|
return _context.a(2, undefined);
|
|
34
48
|
case 1:
|
|
35
49
|
_context.p = 1;
|
|
36
|
-
if (typeof source === 'string') {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
sourceString = toText(JSON.parse(source.hastJson));
|
|
40
|
-
} else {
|
|
41
|
-
sourceString = toText(source);
|
|
50
|
+
if (!(typeof source === 'string')) {
|
|
51
|
+
_context.n = 2;
|
|
52
|
+
break;
|
|
42
53
|
}
|
|
43
|
-
|
|
44
|
-
|
|
54
|
+
sourceString = source;
|
|
55
|
+
_context.n = 6;
|
|
56
|
+
break;
|
|
45
57
|
case 2:
|
|
58
|
+
if (!('hastJson' in source)) {
|
|
59
|
+
_context.n = 3;
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
sourceString = toText(JSON.parse(source.hastJson));
|
|
63
|
+
_context.n = 6;
|
|
64
|
+
break;
|
|
65
|
+
case 3:
|
|
66
|
+
if (!('hastGzip' in source)) {
|
|
67
|
+
_context.n = 5;
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
_t = strFromU8;
|
|
71
|
+
_context.n = 4;
|
|
72
|
+
return decompressAsync(decode(source.hastGzip), {
|
|
73
|
+
consume: true
|
|
74
|
+
});
|
|
75
|
+
case 4:
|
|
76
|
+
decompressed = _t(_context.v);
|
|
77
|
+
sourceString = toText(JSON.parse(decompressed));
|
|
78
|
+
_context.n = 6;
|
|
79
|
+
break;
|
|
80
|
+
case 5:
|
|
81
|
+
sourceString = toText(source);
|
|
82
|
+
case 6:
|
|
83
|
+
_context.n = 7;
|
|
84
|
+
return transformer(sourceString, fileName);
|
|
85
|
+
case 7:
|
|
46
86
|
transformed = _context.v;
|
|
47
87
|
if (!transformed) {
|
|
48
|
-
_context.n =
|
|
88
|
+
_context.n = 8;
|
|
49
89
|
break;
|
|
50
90
|
}
|
|
51
91
|
splitSource = sourceString.split('\n');
|
|
@@ -57,16 +97,16 @@ function _transformSource() {
|
|
|
57
97
|
};
|
|
58
98
|
return acc;
|
|
59
99
|
}, {}));
|
|
60
|
-
case
|
|
100
|
+
case 8:
|
|
61
101
|
return _context.a(2, undefined);
|
|
62
|
-
case
|
|
63
|
-
_context.p =
|
|
64
|
-
|
|
65
|
-
throw new Error("Failed to transform source code (file: ".concat(fileName, "): ").concat(
|
|
66
|
-
case
|
|
102
|
+
case 9:
|
|
103
|
+
_context.p = 9;
|
|
104
|
+
_t2 = _context.v;
|
|
105
|
+
throw new Error("Failed to transform source code (file: ".concat(fileName, "): ").concat(_t2 instanceof Error && _t2.message));
|
|
106
|
+
case 10:
|
|
67
107
|
return _context.a(2);
|
|
68
108
|
}
|
|
69
|
-
}, _callee, null, [[1,
|
|
109
|
+
}, _callee, null, [[1, 9]]);
|
|
70
110
|
}));
|
|
71
111
|
return function (_x4) {
|
|
72
112
|
return _ref2.apply(this, arguments);
|
|
@@ -26,6 +26,8 @@ export interface HastRoot extends Root {
|
|
|
26
26
|
}
|
|
27
27
|
export type VariantSource = string | HastRoot | {
|
|
28
28
|
hastJson: string;
|
|
29
|
+
} | {
|
|
30
|
+
hastGzip: string;
|
|
29
31
|
};
|
|
30
32
|
/**
|
|
31
33
|
* Additional files associated with a code variant.
|
|
@@ -141,6 +143,10 @@ export interface LoadFileOptions {
|
|
|
141
143
|
loadedFiles?: Set<string>;
|
|
142
144
|
/** Side effects code to inject into extraFiles */
|
|
143
145
|
globalsCode?: Array<VariantCode | string>;
|
|
146
|
+
/** Output format for the loaded file
|
|
147
|
+
* @default 'hast'
|
|
148
|
+
*/
|
|
149
|
+
output?: 'hast' | 'hastJson' | 'hastGzip';
|
|
144
150
|
}
|
|
145
151
|
/**
|
|
146
152
|
* Options for the loadVariant function, extending LoadFileOptions with required function dependencies
|
|
@@ -207,11 +213,21 @@ export interface CodeLoadingProps {
|
|
|
207
213
|
children?: string;
|
|
208
214
|
/**
|
|
209
215
|
* When to perform syntax highlighting and code processing
|
|
210
|
-
* @default '
|
|
216
|
+
* @default 'idle'
|
|
217
|
+
*/
|
|
218
|
+
highlightAfter?: 'init' | 'stream' | 'hydration' | 'idle';
|
|
219
|
+
/**
|
|
220
|
+
* When to enhance the code display with interactivity
|
|
221
|
+
* @default 'idle'
|
|
211
222
|
*/
|
|
212
|
-
|
|
223
|
+
enhanceAfter?: 'init' | 'stream' | 'hydration' | 'idle';
|
|
213
224
|
/** Force client-side rendering even when server rendering is available */
|
|
214
225
|
forceClient?: boolean;
|
|
226
|
+
/** Defer parsing and populating the AST into memory until the code is enhanced
|
|
227
|
+
* Applies only in production when RSC loading
|
|
228
|
+
* @default 'gzip'
|
|
229
|
+
*/
|
|
230
|
+
deferParsing?: 'none' | 'json' | 'gzip';
|
|
215
231
|
}
|
|
216
232
|
/**
|
|
217
233
|
* Function props for loading and transforming code
|
|
@@ -262,7 +278,8 @@ export interface CodeHighlighterClientProps extends CodeIdentityProps, CodeConte
|
|
|
262
278
|
* When to perform syntax highlighting for performance optimization
|
|
263
279
|
* @default 'hydration'
|
|
264
280
|
*/
|
|
265
|
-
|
|
281
|
+
highlightAfter?: 'init' | 'hydration' | 'idle';
|
|
282
|
+
enhanceAfter?: 'init' | 'hydration' | 'idle';
|
|
266
283
|
}
|
|
267
284
|
/**
|
|
268
285
|
* Main props for the CodeHighlighter component.
|
|
@@ -7,7 +7,8 @@ type CreateDemoMeta = {
|
|
|
7
7
|
displayName?: string;
|
|
8
8
|
variantType?: string;
|
|
9
9
|
skipPrecompute?: boolean;
|
|
10
|
-
|
|
10
|
+
highlightAfter?: CodeHighlighterProps<{}>['highlightAfter'];
|
|
11
|
+
enhanceAfter?: CodeHighlighterProps<{}>['enhanceAfter'];
|
|
11
12
|
precompute?: Code;
|
|
12
13
|
ClientProvider?: React.ComponentType<{
|
|
13
14
|
children: React.ReactNode;
|
|
@@ -23,7 +24,8 @@ type AbstractCreateDemoOptions<T extends {}> = {
|
|
|
23
24
|
controlled?: boolean;
|
|
24
25
|
demoGlobalData?: DemoGlobalData[];
|
|
25
26
|
variantTypes?: Record<string, string>;
|
|
26
|
-
|
|
27
|
+
highlightAfter?: CodeHighlighterProps<{}>['highlightAfter'];
|
|
28
|
+
enhanceAfter?: CodeHighlighterProps<{}>['enhanceAfter'];
|
|
27
29
|
fallbackUsesExtraFiles?: boolean;
|
|
28
30
|
fallbackUsesAllVariants?: boolean;
|
|
29
31
|
loadCodeMeta?: LoadCodeMeta;
|
|
@@ -35,7 +35,8 @@ export function abstractCreateDemo(options, url, variants, meta) {
|
|
|
35
35
|
loadVariantMeta: options.loadVariantMeta,
|
|
36
36
|
loadSource: options.loadSource,
|
|
37
37
|
sourceParser: options.sourceParser,
|
|
38
|
-
|
|
38
|
+
highlightAfter: (meta == null ? void 0 : meta.highlightAfter) || options.highlightAfter,
|
|
39
|
+
enhanceAfter: (meta == null ? void 0 : meta.enhanceAfter) || options.enhanceAfter,
|
|
39
40
|
controlled: options.controlled,
|
|
40
41
|
fallbackUsesExtraFiles: options.fallbackUsesExtraFiles,
|
|
41
42
|
fallbackUsesAllVariants: options.fallbackUsesAllVariants
|
|
@@ -2,10 +2,16 @@ import type { Nodes as HastNodes } from 'hast';
|
|
|
2
2
|
export declare function hastToJsx(hast: HastNodes): React.ReactNode;
|
|
3
3
|
export declare function hastOrJsonToJsx(hastOrJson: HastNodes | {
|
|
4
4
|
hastJson: string;
|
|
5
|
+
} | {
|
|
6
|
+
hastGzip: string;
|
|
5
7
|
}): React.ReactNode;
|
|
6
8
|
export declare function stringOrHastToString(source: string | HastNodes | {
|
|
7
9
|
hastJson: string;
|
|
10
|
+
} | {
|
|
11
|
+
hastGzip: string;
|
|
8
12
|
}): string;
|
|
9
13
|
export declare function stringOrHastToJsx(source: string | HastNodes | {
|
|
10
14
|
hastJson: string;
|
|
15
|
+
} | {
|
|
16
|
+
hastGzip: string;
|
|
11
17
|
}, highlighted?: boolean): React.ReactNode;
|
|
@@ -2,6 +2,8 @@ import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
|
2
2
|
import { Fragment, jsx, jsxs } from 'react/jsx-runtime';
|
|
3
3
|
import { toText } from 'hast-util-to-text';
|
|
4
4
|
import { toJsxRuntime } from 'hast-util-to-jsx-runtime';
|
|
5
|
+
import { decompressSync, strFromU8 } from 'fflate';
|
|
6
|
+
import { decode } from 'uint8-to-base64';
|
|
5
7
|
export function hastToJsx(hast) {
|
|
6
8
|
return toJsxRuntime(hast, {
|
|
7
9
|
Fragment: Fragment,
|
|
@@ -17,6 +19,12 @@ export function hastOrJsonToJsx(hastOrJson) {
|
|
|
17
19
|
} catch (error) {
|
|
18
20
|
throw new Error("Failed to parse hastJson: ".concat(JSON.stringify(error)));
|
|
19
21
|
}
|
|
22
|
+
} else if ('hastGzip' in hastOrJson) {
|
|
23
|
+
try {
|
|
24
|
+
hast = JSON.parse(strFromU8(decompressSync(decode(hastOrJson.hastGzip))));
|
|
25
|
+
} catch (error) {
|
|
26
|
+
throw new Error("Failed to parse hastGzip: ".concat(JSON.stringify(error)));
|
|
27
|
+
}
|
|
20
28
|
} else {
|
|
21
29
|
hast = hastOrJson;
|
|
22
30
|
}
|
|
@@ -37,6 +45,12 @@ export function stringOrHastToString(source) {
|
|
|
37
45
|
} catch (error) {
|
|
38
46
|
throw new Error("Failed to parse hastJson: ".concat(JSON.stringify(error)));
|
|
39
47
|
}
|
|
48
|
+
} else if ('hastGzip' in source) {
|
|
49
|
+
try {
|
|
50
|
+
hast = JSON.parse(strFromU8(decompressSync(decode(source.hastGzip))));
|
|
51
|
+
} catch (error) {
|
|
52
|
+
throw new Error("Failed to parse hastGzip: ".concat(JSON.stringify(error)));
|
|
53
|
+
}
|
|
40
54
|
} else {
|
|
41
55
|
hast = source;
|
|
42
56
|
}
|
|
@@ -55,6 +69,12 @@ export function stringOrHastToJsx(source, highlighted) {
|
|
|
55
69
|
} catch (error) {
|
|
56
70
|
throw new Error("Failed to parse hastJson: ".concat(JSON.stringify(error)));
|
|
57
71
|
}
|
|
72
|
+
} else if ('hastGzip' in source) {
|
|
73
|
+
try {
|
|
74
|
+
hast = JSON.parse(strFromU8(decompressSync(decode(source.hastGzip))));
|
|
75
|
+
} catch (error) {
|
|
76
|
+
throw new Error("Failed to parse hastGzip: ".concat(JSON.stringify(error)));
|
|
77
|
+
}
|
|
58
78
|
} else {
|
|
59
79
|
hast = source;
|
|
60
80
|
}
|
|
@@ -109,7 +109,8 @@ function _loadPrecomputedCodeHighlighter() {
|
|
|
109
109
|
loadVariantMeta: undefined,
|
|
110
110
|
sourceTransformers: sourceTransformers,
|
|
111
111
|
// For TypeScript to JavaScript conversion
|
|
112
|
-
maxDepth: 5
|
|
112
|
+
maxDepth: 5,
|
|
113
|
+
output: _this.getOptions().output || 'hastGzip'
|
|
113
114
|
});
|
|
114
115
|
case 3:
|
|
115
116
|
_yield$loadVariant = _context.v;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type ImportsAndComments } from "../loaderUtils/index.js";
|
|
2
2
|
import { type SplitArguments } from "./parseFunctionArguments.js";
|
|
3
3
|
import type { Externals } from "../../CodeHighlighter/types.js";
|
|
4
4
|
/**
|
|
@@ -29,16 +29,18 @@ export interface ParsedCreateFactory {
|
|
|
29
29
|
structuredUrl: string;
|
|
30
30
|
structuredVariants: string | SplitArguments | Record<string, string> | undefined;
|
|
31
31
|
structuredOptions?: Record<string, any>;
|
|
32
|
+
hasGenerics: boolean;
|
|
33
|
+
structuredGenerics?: Record<string, any>;
|
|
32
34
|
remaining?: string;
|
|
33
|
-
|
|
35
|
+
importsAndComments?: ImportsAndComments;
|
|
34
36
|
}
|
|
35
37
|
/**
|
|
36
38
|
* Parses a file to extract a single create* factory call and its variants and options
|
|
37
39
|
* Returns the parsed result with remaining content included
|
|
38
40
|
* Returns null if no create* call is found
|
|
39
41
|
*/
|
|
40
|
-
export declare function parseCreateFactoryCall(code: string, filePath: string, parseOptions?: ParseOptions,
|
|
41
|
-
|
|
42
|
+
export declare function parseCreateFactoryCall(code: string, filePath: string, parseOptions?: ParseOptions, importsAndComments?: ImportsAndComments): Promise<(ParsedCreateFactory & {
|
|
43
|
+
importsAndComments?: ImportsAndComments;
|
|
42
44
|
}) | null>;
|
|
43
45
|
/**
|
|
44
46
|
* Parses all create* factory calls in a file sequentially
|