@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.
Files changed (102) hide show
  1. package/esm/CodeControllerContext/CodeControllerContext.js +2 -2
  2. package/esm/CodeExternalsContext/CodeExternalsContext.js +1 -1
  3. package/esm/CodeHighlighter/CodeHighlighter.js +247 -329
  4. package/esm/CodeHighlighter/CodeHighlighterClient.js +447 -653
  5. package/esm/CodeHighlighter/CodeHighlighterContext.js +2 -2
  6. package/esm/CodeHighlighter/CodeHighlighterFallbackContext.js +2 -2
  7. package/esm/CodeHighlighter/codeToFallbackProps.js +21 -37
  8. package/esm/CodeHighlighter/errors.js +248 -400
  9. package/esm/CodeHighlighter/parseControlledCode.js +12 -20
  10. package/esm/CodeProvider/CodeContext.js +3 -3
  11. package/esm/CodeProvider/CodeProvider.js +31 -40
  12. package/esm/abstractCreateDemo/abstractCreateDemo.js +13 -17
  13. package/esm/abstractCreateDemoClient/abstractCreateDemoClient.js +12 -12
  14. package/esm/cli/index.js +1 -1
  15. package/esm/cli/runValidate.js +160 -264
  16. package/esm/createDemoData/createDemoData.js +11 -12
  17. package/esm/createSitemap/createSitemap.js +2 -2
  18. package/esm/pipeline/getFileConventions/fileConventions.js +1 -1
  19. package/esm/pipeline/getFileConventions/getFileConventions.js +2 -15
  20. package/esm/pipeline/hastUtils/hastUtils.js +16 -17
  21. package/esm/pipeline/loadCodeVariant/addCodeVariantPaths.js +24 -24
  22. package/esm/pipeline/loadCodeVariant/applyCodeTransform.js +12 -22
  23. package/esm/pipeline/loadCodeVariant/calculateMainFilePath.js +30 -37
  24. package/esm/pipeline/loadCodeVariant/computeHastDeltas.js +107 -185
  25. package/esm/pipeline/loadCodeVariant/diffHast.js +18 -53
  26. package/esm/pipeline/loadCodeVariant/examineCodeVariant.js +24 -27
  27. package/esm/pipeline/loadCodeVariant/flattenCodeVariant.js +9 -10
  28. package/esm/pipeline/loadCodeVariant/hasAllCodeVariants.js +5 -5
  29. package/esm/pipeline/loadCodeVariant/loadCodeFallback.js +516 -731
  30. package/esm/pipeline/loadCodeVariant/loadCodeVariant.js +679 -1079
  31. package/esm/pipeline/loadCodeVariant/maybeCodeInitialData.js +14 -20
  32. package/esm/pipeline/loadCodeVariant/mergeCodeMetadata.js +53 -63
  33. package/esm/pipeline/loadCodeVariant/parseCode.js +40 -48
  34. package/esm/pipeline/loadCodeVariant/pathUtils.js +43 -64
  35. package/esm/pipeline/loadCodeVariant/transformSource.js +55 -125
  36. package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +160 -221
  37. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +377 -479
  38. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.js +171 -173
  39. package/esm/pipeline/loadPrecomputedCodeHighlighter/performanceLogger.js +14 -30
  40. package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +19 -21
  41. package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.js +37 -71
  42. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.js +3 -9
  43. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.js +54 -80
  44. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.js +71 -98
  45. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.js +5 -5
  46. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +161 -211
  47. package/esm/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.js +159 -207
  48. package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +42 -64
  49. package/esm/pipeline/loadServerCodeMeta/resolveModulePathWithFs.js +20 -96
  50. package/esm/pipeline/loadServerPageIndex/loadServerPageIndex.js +66 -85
  51. package/esm/pipeline/loadServerSitemap/loadServerSitemap.js +71 -118
  52. package/esm/pipeline/loadServerSource/loadServerSource.js +121 -148
  53. package/esm/pipeline/loaderUtils/externalsToPackages.js +7 -7
  54. package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +8 -12
  55. package/esm/pipeline/loaderUtils/fileUrlToPortablePath.js +5 -5
  56. package/esm/pipeline/loaderUtils/getFileNameFromUrl.js +19 -29
  57. package/esm/pipeline/loaderUtils/getLanguageFromExtension.js +3 -4
  58. package/esm/pipeline/loaderUtils/mergeExternals.js +15 -35
  59. package/esm/pipeline/loaderUtils/parseImportsAndComments.js +413 -433
  60. package/esm/pipeline/loaderUtils/processRelativeImports.js +153 -239
  61. package/esm/pipeline/loaderUtils/resolveModulePath.js +544 -1303
  62. package/esm/pipeline/loaderUtils/rewriteImports.js +73 -111
  63. package/esm/pipeline/parseSource/addLineGutters.js +33 -45
  64. package/esm/pipeline/parseSource/grammars.js +3 -3
  65. package/esm/pipeline/parseSource/parseSource.js +13 -31
  66. package/esm/pipeline/syncPageIndex/createMarkdownNodes.js +32 -55
  67. package/esm/pipeline/syncPageIndex/mergeMetadataMarkdown.js +107 -160
  68. package/esm/pipeline/syncPageIndex/metadataToMarkdown.js +846 -1033
  69. package/esm/pipeline/syncPageIndex/syncPageIndex.js +291 -438
  70. package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.js +213 -311
  71. package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.js +10 -10
  72. package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +133 -193
  73. package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.js +25 -27
  74. package/esm/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.js +572 -717
  75. package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.js +8 -8
  76. package/esm/pipeline/transformTypescriptToJavascript/removeTypes.js +84 -113
  77. package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.js +10 -26
  78. package/esm/useCode/Pre.js +58 -62
  79. package/esm/useCode/useCode.js +59 -61
  80. package/esm/useCode/useCodeUtils.js +54 -63
  81. package/esm/useCode/useCopyFunctionality.js +10 -9
  82. package/esm/useCode/useFileNavigation.js +150 -212
  83. package/esm/useCode/useSourceEditing.js +17 -14
  84. package/esm/useCode/useTransformManagement.js +23 -26
  85. package/esm/useCode/useUIState.js +12 -20
  86. package/esm/useCode/useVariantSelection.js +62 -79
  87. package/esm/useCopier/index.js +29 -56
  88. package/esm/useDemo/createCodeSandbox.js +12 -15
  89. package/esm/useDemo/createStackBlitz.js +14 -20
  90. package/esm/useDemo/exportVariant.js +200 -180
  91. package/esm/useDemo/exportVariantAsCra.js +22 -25
  92. package/esm/useDemo/useDemo.js +80 -84
  93. package/esm/useErrors/ErrorsContext.js +1 -1
  94. package/esm/useErrors/useErrors.js +3 -3
  95. package/esm/useLocalStorageState/useLocalStorageState.js +23 -39
  96. package/esm/usePreference/PreferencesProvider.js +1 -1
  97. package/esm/usePreference/usePreference.js +9 -11
  98. package/esm/useSearch/useSearch.js +290 -387
  99. package/esm/useUrlHashState/useUrlHashState.js +11 -14
  100. package/esm/withDocsInfra/withDeploymentConfig.js +26 -21
  101. package/esm/withDocsInfra/withDocsInfra.js +99 -101
  102. package/package.json +7 -4
@@ -1,60 +1,25 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
- import _regenerator from "@babel/runtime/helpers/esm/regenerator";
3
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
- import _extends from "@babel/runtime/helpers/esm/extends";
5
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
6
- import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
7
1
  import { create, patch } from 'jsondiffpatch';
8
- var differ = create({
2
+ const differ = create({
9
3
  omitRemovedValues: true,
10
4
  cloneDiffValues: true
11
5
  });
12
- export function diffHast(_x, _x2, _x3, _x4, _x5) {
13
- return _diffHast.apply(this, arguments);
14
- }
15
- function _diffHast() {
16
- _diffHast = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(source, parsedSource, filename, transforms, parseSource) {
17
- var transformed;
18
- return _regenerator().w(function (_context2) {
19
- while (1) switch (_context2.n) {
20
- case 0:
21
- _context2.n = 1;
22
- return Promise.all(Object.entries(transforms).map(/*#__PURE__*/function () {
23
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
24
- var _ref3, key, transform, patched, transformedSource, parsedTransform, delta;
25
- return _regenerator().w(function (_context) {
26
- while (1) switch (_context.n) {
27
- case 0:
28
- _ref3 = _slicedToArray(_ref, 2), key = _ref3[0], transform = _ref3[1];
29
- patched = patch(source.split('\n'), transform.delta);
30
- if (Array.isArray(patched)) {
31
- _context.n = 1;
32
- break;
33
- }
34
- throw new Error("Patch for ".concat(key, " did not return an array"));
35
- case 1:
36
- transformedSource = patched.join('\n');
37
- _context.n = 2;
38
- return parseSource(transformedSource, transform.fileName || filename);
39
- case 2:
40
- parsedTransform = _context.v;
41
- // TODO: further optimize this delta, it looks a little noisy
42
- delta = differ.diff(parsedSource, parsedTransform);
43
- return _context.a(2, _defineProperty({}, key, _extends(_extends({}, transform), {}, {
44
- delta: delta
45
- })));
46
- }
47
- }, _callee);
48
- }));
49
- return function (_x6) {
50
- return _ref2.apply(this, arguments);
51
- };
52
- }()));
53
- case 1:
54
- transformed = _context2.v;
55
- return _context2.a(2, Object.assign.apply(Object, [{}].concat(_toConsumableArray(transformed))));
6
+ export async function diffHast(source, parsedSource, filename, transforms, parseSource) {
7
+ const transformed = await Promise.all(Object.entries(transforms).map(async ([key, transform]) => {
8
+ const patched = patch(source.split('\n'), transform.delta);
9
+ if (!Array.isArray(patched)) {
10
+ throw new Error(`Patch for ${key} did not return an array`);
11
+ }
12
+ const transformedSource = patched.join('\n');
13
+ const parsedTransform = await parseSource(transformedSource, transform.fileName || filename);
14
+
15
+ // TODO: further optimize this delta, it looks a little noisy
16
+ const delta = differ.diff(parsedSource, parsedTransform);
17
+ return {
18
+ [key]: {
19
+ ...transform,
20
+ delta
56
21
  }
57
- }, _callee2);
22
+ };
58
23
  }));
59
- return _diffHast.apply(this, arguments);
24
+ return Object.assign({}, ...transformed);
60
25
  }
@@ -1,4 +1,3 @@
1
- import _typeof from "@babel/runtime/helpers/esm/typeof";
2
1
  /**
3
2
  * Variant examination utility for analyzing variant structure and paths
4
3
  */
@@ -8,38 +7,36 @@ import { getUrlParts, calculateMaxSourceBackNavigation } from "./pathUtils.js";
8
7
  * Create path context for processing files with extended information
9
8
  */
10
9
  export function examineCodeVariant(variant) {
11
- var hasMetadata = variant.extraFiles ? Object.values(variant.extraFiles).some(function (file) {
12
- return _typeof(file) === 'object' && file.metadata;
13
- }) : false;
10
+ const hasMetadata = variant.extraFiles ? Object.values(variant.extraFiles).some(file => typeof file === 'object' && file.metadata) : false;
14
11
 
15
12
  // Calculate maxSourceBackNavigation based only on extraFiles structure
16
- var maxSourceBackNavigation = variant.extraFiles ? calculateMaxSourceBackNavigation(variant.extraFiles) : 0;
13
+ const maxSourceBackNavigation = variant.extraFiles ? calculateMaxSourceBackNavigation(variant.extraFiles) : 0;
17
14
 
18
15
  // Parse URL to determine path structure
19
- var urlDirectory = [];
20
- var rootLevel = '';
21
- var pathInwardFromRoot = '';
16
+ let urlDirectory = [];
17
+ let rootLevel = '';
18
+ let pathInwardFromRoot = '';
22
19
  if (variant.url && variant.url.includes('://')) {
23
20
  try {
24
- var pathComponents = getUrlParts(variant.url);
21
+ const pathComponents = getUrlParts(variant.url);
25
22
  if (pathComponents.length > 0) {
26
23
  // Check if the last component looks like a filename (has an extension)
27
- var lastComponent = pathComponents[pathComponents.length - 1];
28
- var hasFileExtension = lastComponent.includes('.') && /\.[a-zA-Z0-9]+$/.test(lastComponent);
24
+ const lastComponent = pathComponents[pathComponents.length - 1];
25
+ const hasFileExtension = lastComponent.includes('.') && /\.[a-zA-Z0-9]+$/.test(lastComponent);
29
26
 
30
27
  // If it has a file extension, exclude it from directory components
31
- var directoryComponents = hasFileExtension ? pathComponents.slice(0, -1) : pathComponents;
28
+ const directoryComponents = hasFileExtension ? pathComponents.slice(0, -1) : pathComponents;
32
29
  urlDirectory = directoryComponents;
33
30
  rootLevel = directoryComponents[0] || '';
34
31
 
35
32
  // Only calculate pathInwardFromRoot if there's actual back navigation
36
33
  if (maxSourceBackNavigation > 0 && directoryComponents.length >= maxSourceBackNavigation) {
37
34
  // Take the last maxSourceBackNavigation components as the pathInwardFromRoot
38
- var relevantComponents = directoryComponents.slice(-maxSourceBackNavigation);
35
+ const relevantComponents = directoryComponents.slice(-maxSourceBackNavigation);
39
36
  pathInwardFromRoot = relevantComponents.join('/');
40
37
  }
41
38
  }
42
- } catch (_unused) {
39
+ } catch {
43
40
  // If URL parsing fails, keep defaults
44
41
  urlDirectory = [];
45
42
  rootLevel = '';
@@ -48,26 +45,26 @@ export function examineCodeVariant(variant) {
48
45
  }
49
46
 
50
47
  // We keep the URL info for compatibility, but don't use it for calculations
51
- var hasUrl = Boolean(variant.url);
52
- var actualUrl = variant.url;
48
+ const hasUrl = Boolean(variant.url);
49
+ const actualUrl = variant.url;
53
50
  if (hasUrl && actualUrl) {
54
51
  return {
55
52
  hasUrl: true,
56
- hasMetadata: hasMetadata,
57
- maxSourceBackNavigation: maxSourceBackNavigation,
58
- urlDirectory: urlDirectory,
59
- rootLevel: rootLevel,
60
- pathInwardFromRoot: pathInwardFromRoot,
61
- actualUrl: actualUrl
53
+ hasMetadata,
54
+ maxSourceBackNavigation,
55
+ urlDirectory,
56
+ rootLevel,
57
+ pathInwardFromRoot,
58
+ actualUrl
62
59
  };
63
60
  }
64
61
  return {
65
62
  hasUrl: false,
66
- hasMetadata: hasMetadata,
67
- maxSourceBackNavigation: maxSourceBackNavigation,
68
- urlDirectory: urlDirectory,
69
- rootLevel: rootLevel,
70
- pathInwardFromRoot: pathInwardFromRoot,
63
+ hasMetadata,
64
+ maxSourceBackNavigation,
65
+ urlDirectory,
66
+ rootLevel,
67
+ pathInwardFromRoot,
71
68
  actualUrl: undefined
72
69
  };
73
70
  }
@@ -1,4 +1,3 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
1
  /**
3
2
  * Flatten variant utility to convert a VariantCode into a flat files list
4
3
  * Handles relative path resolution and metadata file scoping
@@ -13,10 +12,10 @@ import { addPathsToVariant } from "./addCodeVariantPaths.js";
13
12
  * Uses addPathsToVariant for path resolution logic
14
13
  */
15
14
  export function flattenCodeVariant(variant) {
16
- var result = {};
15
+ const result = {};
17
16
 
18
17
  // Use addPathsToVariant to get the structured paths
19
- var variantWithPaths = addPathsToVariant(variant);
18
+ const variantWithPaths = addPathsToVariant(variant);
20
19
 
21
20
  // Add main file if it exists
22
21
  if (variantWithPaths.path && variantWithPaths.source !== undefined) {
@@ -27,8 +26,7 @@ export function flattenCodeVariant(variant) {
27
26
 
28
27
  // Add extra files if they exist
29
28
  if (variantWithPaths.extraFiles) {
30
- for (var _i = 0, _Object$values = Object.values(variantWithPaths.extraFiles); _i < _Object$values.length; _i++) {
31
- var fileWithPath = _Object$values[_i];
29
+ for (const fileWithPath of Object.values(variantWithPaths.extraFiles)) {
32
30
  // Skip files that are just URLs or missing a path
33
31
  if (typeof fileWithPath === 'string' || !fileWithPath.path) {
34
32
  continue;
@@ -38,11 +36,12 @@ export function flattenCodeVariant(variant) {
38
36
  if (!fileWithPath.source && fileWithPath.source !== '') {
39
37
  continue;
40
38
  }
41
- result[fileWithPath.path] = _extends({
42
- source: stringOrHastToString(fileWithPath.source || '')
43
- }, fileWithPath.metadata && {
44
- metadata: fileWithPath.metadata
45
- });
39
+ result[fileWithPath.path] = {
40
+ source: stringOrHastToString(fileWithPath.source || ''),
41
+ ...(fileWithPath.metadata && {
42
+ metadata: fileWithPath.metadata
43
+ })
44
+ };
46
45
  }
47
46
  }
48
47
  return result;
@@ -43,17 +43,17 @@ function isSourceLoaded(code, needsHighlight) {
43
43
  * ```
44
44
  */
45
45
  export function hasAllVariants(variants, code, needsHighlight) {
46
- return variants.every(function (variant) {
47
- var codeVariant = code == null ? void 0 : code[variant];
46
+ return variants.every(variant => {
47
+ const codeVariant = code?.[variant];
48
48
  if (!codeVariant || typeof codeVariant === 'string' || !isSourceLoaded(codeVariant, needsHighlight)) {
49
49
  return false;
50
50
  }
51
- var extraFiles = codeVariant.extraFiles;
51
+ const extraFiles = codeVariant.extraFiles;
52
52
  if (!extraFiles) {
53
53
  return true;
54
54
  }
55
- return Object.keys(extraFiles).every(function (file) {
56
- var extraFile = extraFiles[file];
55
+ return Object.keys(extraFiles).every(file => {
56
+ const extraFile = extraFiles[file];
57
57
  if (!extraFile || typeof extraFile === 'string' || !isSourceLoaded(extraFile, needsHighlight)) {
58
58
  return false;
59
59
  }