@mui/internal-docs-infra 0.2.3-canary.8 → 0.3.1-canary.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.
Files changed (144) hide show
  1. package/README.md +3 -2
  2. package/esm/CodeHighlighter/CodeHighlighter.js +16 -16
  3. package/esm/CodeHighlighter/CodeHighlighterClient.js +33 -33
  4. package/esm/CodeHighlighter/errors.js +3 -3
  5. package/esm/CodeHighlighter/types.d.ts +1 -1
  6. package/esm/CodeProvider/CodeContext.d.ts +4 -4
  7. package/esm/CodeProvider/CodeProvider.js +7 -7
  8. package/esm/cli/index.d.ts +1 -0
  9. package/esm/cli/index.js +6 -0
  10. package/esm/cli/runValidate.d.ts +8 -0
  11. package/esm/cli/runValidate.js +297 -0
  12. package/esm/createSitemap/createSitemap.d.ts +23 -0
  13. package/esm/createSitemap/createSitemap.js +45 -0
  14. package/esm/createSitemap/index.d.ts +1 -0
  15. package/esm/createSitemap/index.js +1 -0
  16. package/esm/createSitemap/types.d.ts +68 -0
  17. package/esm/createSitemap/types.js +1 -0
  18. package/esm/pipeline/getFileConventions/fileConventions.d.ts +4 -0
  19. package/esm/pipeline/getFileConventions/fileConventions.js +4 -0
  20. package/esm/pipeline/getFileConventions/getFileConventions.d.ts +4 -0
  21. package/esm/pipeline/getFileConventions/getFileConventions.js +17 -0
  22. package/esm/pipeline/getFileConventions/index.d.ts +1 -0
  23. package/esm/pipeline/getFileConventions/index.js +1 -0
  24. package/esm/{CodeHighlighter/addPathsToVariant.d.ts → pipeline/loadCodeVariant/addCodeVariantPaths.d.ts} +1 -1
  25. package/esm/{CodeHighlighter/applyTransform.d.ts → pipeline/loadCodeVariant/applyCodeTransform.d.ts} +3 -3
  26. package/esm/{CodeHighlighter/applyTransform.js → pipeline/loadCodeVariant/applyCodeTransform.js} +4 -4
  27. package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/calculateMainFilePath.js +1 -1
  28. package/esm/{CodeHighlighter/transformCode.d.ts → pipeline/loadCodeVariant/computeHastDeltas.d.ts} +9 -5
  29. package/esm/{CodeHighlighter/transformCode.js → pipeline/loadCodeVariant/computeHastDeltas.js} +20 -16
  30. package/esm/pipeline/loadCodeVariant/diffHast.d.ts +3 -0
  31. package/esm/{CodeHighlighter/transformParsedSource.js → pipeline/loadCodeVariant/diffHast.js} +5 -5
  32. package/esm/{CodeHighlighter/examineVariant.d.ts → pipeline/loadCodeVariant/examineCodeVariant.d.ts} +2 -2
  33. package/esm/{CodeHighlighter/examineVariant.js → pipeline/loadCodeVariant/examineCodeVariant.js} +1 -1
  34. package/esm/{useDemo/flattenVariant.d.ts → pipeline/loadCodeVariant/flattenCodeVariant.d.ts} +2 -2
  35. package/esm/{useDemo/flattenVariant.js → pipeline/loadCodeVariant/flattenCodeVariant.js} +3 -3
  36. package/esm/{CodeHighlighter/hasAllVariants.d.ts → pipeline/loadCodeVariant/hasAllCodeVariants.d.ts} +1 -1
  37. package/esm/pipeline/loadCodeVariant/index.d.ts +10 -0
  38. package/esm/pipeline/loadCodeVariant/index.js +17 -0
  39. package/esm/{CodeHighlighter/loadFallbackCode.d.ts → pipeline/loadCodeVariant/loadCodeFallback.d.ts} +2 -2
  40. package/esm/{CodeHighlighter/loadFallbackCode.js → pipeline/loadCodeVariant/loadCodeFallback.js} +180 -106
  41. package/esm/{CodeHighlighter/loadVariant.d.ts → pipeline/loadCodeVariant/loadCodeVariant.d.ts} +2 -2
  42. package/esm/{CodeHighlighter/loadVariant.js → pipeline/loadCodeVariant/loadCodeVariant.js} +122 -49
  43. package/esm/{CodeHighlighter/maybeInitialData.d.ts → pipeline/loadCodeVariant/maybeCodeInitialData.d.ts} +6 -6
  44. package/esm/{CodeHighlighter/maybeInitialData.js → pipeline/loadCodeVariant/maybeCodeInitialData.js} +6 -6
  45. package/esm/{CodeHighlighter/mergeMetadata.d.ts → pipeline/loadCodeVariant/mergeCodeMetadata.d.ts} +3 -3
  46. package/esm/{CodeHighlighter/mergeMetadata.js → pipeline/loadCodeVariant/mergeCodeMetadata.js} +3 -3
  47. package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/parseCode.d.ts +1 -1
  48. package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/transformSource.d.ts +1 -1
  49. package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.ts +5 -0
  50. package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +86 -13
  51. package/esm/pipeline/loadPrecomputedCodeHighlighter/performanceLogger.d.ts +30 -0
  52. package/esm/pipeline/loadPrecomputedCodeHighlighter/performanceLogger.js +77 -0
  53. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +7 -7
  54. package/esm/pipeline/loadPrecomputedSitemap/index.d.ts +2 -0
  55. package/esm/pipeline/loadPrecomputedSitemap/index.js +4 -0
  56. package/esm/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.d.ts +10 -0
  57. package/esm/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.js +213 -0
  58. package/esm/pipeline/loadServerCodeMeta/index.d.ts +2 -1
  59. package/esm/pipeline/loadServerCodeMeta/index.js +2 -1
  60. package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.d.ts +1 -1
  61. package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +2 -2
  62. package/esm/pipeline/{loaderUtils → loadServerCodeMeta}/resolveModulePathWithFs.d.ts +1 -1
  63. package/esm/pipeline/{loaderUtils → loadServerCodeMeta}/resolveModulePathWithFs.js +1 -1
  64. package/esm/pipeline/loadServerPageIndex/index.d.ts +2 -0
  65. package/esm/pipeline/loadServerPageIndex/index.js +1 -0
  66. package/esm/pipeline/loadServerPageIndex/loadServerPageIndex.d.ts +51 -0
  67. package/esm/pipeline/loadServerPageIndex/loadServerPageIndex.js +174 -0
  68. package/esm/pipeline/loadServerSitemap/index.d.ts +2 -0
  69. package/esm/pipeline/loadServerSitemap/index.js +1 -0
  70. package/esm/pipeline/loadServerSitemap/loadServerSitemap.d.ts +39 -0
  71. package/esm/pipeline/loadServerSitemap/loadServerSitemap.js +168 -0
  72. package/esm/pipeline/loadServerSource/loadServerSource.js +1 -1
  73. package/esm/pipeline/loaderUtils/externalsToPackages.js +1 -1
  74. package/esm/pipeline/loaderUtils/processRelativeImports.js +16 -3
  75. package/esm/pipeline/loaderUtils/rewriteImports.d.ts +36 -0
  76. package/esm/pipeline/loaderUtils/rewriteImports.js +139 -8
  77. package/esm/pipeline/syncPageIndex/createMarkdownNodes.d.ts +76 -0
  78. package/esm/pipeline/syncPageIndex/createMarkdownNodes.js +305 -0
  79. package/esm/pipeline/syncPageIndex/index.d.ts +1 -0
  80. package/esm/pipeline/syncPageIndex/index.js +1 -0
  81. package/esm/pipeline/syncPageIndex/mergeMetadataMarkdown.d.ts +58 -0
  82. package/esm/pipeline/syncPageIndex/mergeMetadataMarkdown.js +214 -0
  83. package/esm/pipeline/syncPageIndex/metadataToMarkdown.d.ts +67 -0
  84. package/esm/pipeline/syncPageIndex/metadataToMarkdown.js +1486 -0
  85. package/esm/pipeline/syncPageIndex/syncPageIndex.d.ts +108 -0
  86. package/esm/pipeline/syncPageIndex/syncPageIndex.js +540 -0
  87. package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.d.ts +2 -2
  88. package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.js +5 -5
  89. package/esm/pipeline/transformMarkdownBlockquoteCallouts/index.d.ts +2 -0
  90. package/esm/pipeline/transformMarkdownBlockquoteCallouts/index.js +4 -0
  91. package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.d.ts +16 -0
  92. package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.js +58 -0
  93. package/esm/pipeline/transformMarkdownDemoLinks/index.d.ts +2 -0
  94. package/esm/pipeline/transformMarkdownDemoLinks/index.js +4 -0
  95. package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.d.ts +26 -0
  96. package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.js +107 -0
  97. package/esm/pipeline/transformMarkdownMetadata/index.d.ts +2 -0
  98. package/esm/pipeline/transformMarkdownMetadata/index.js +4 -0
  99. package/esm/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.d.ts +3 -0
  100. package/esm/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.js +1010 -0
  101. package/esm/pipeline/transformMarkdownMetadata/types.d.ts +110 -0
  102. package/esm/pipeline/transformMarkdownMetadata/types.js +1 -0
  103. package/esm/pipeline/transformMarkdownRelativePaths/index.d.ts +2 -0
  104. package/esm/pipeline/transformMarkdownRelativePaths/index.js +4 -0
  105. package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.d.ts +15 -0
  106. package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.js +40 -0
  107. package/esm/useCode/Pre.js +15 -2
  108. package/esm/useCode/useCode.d.ts +15 -2
  109. package/esm/useCode/useCode.js +15 -6
  110. package/esm/useCode/useCodeUtils.js +3 -3
  111. package/esm/useCode/useFileNavigation.d.ts +9 -3
  112. package/esm/useCode/useFileNavigation.js +124 -81
  113. package/esm/useCode/useUIState.d.ts +4 -1
  114. package/esm/useCode/useUIState.js +17 -2
  115. package/esm/useCode/useVariantSelection.d.ts +8 -3
  116. package/esm/useCode/useVariantSelection.js +144 -52
  117. package/esm/useCopier/index.js +5 -4
  118. package/esm/useDemo/createCodeSandbox.d.ts +1 -1
  119. package/esm/useDemo/createStackBlitz.d.ts +1 -1
  120. package/esm/useDemo/exportVariant.js +13 -11
  121. package/esm/useDemo/index.d.ts +1 -1
  122. package/esm/useDemo/index.js +1 -1
  123. package/esm/useDemo/useDemo.d.ts +5 -5
  124. package/esm/useDemo/useDemo.js +6 -6
  125. package/esm/useErrors/useErrors.d.ts +1 -1
  126. package/esm/useErrors/useErrors.js +6 -2
  127. package/esm/useSearch/index.d.ts +1 -0
  128. package/esm/useSearch/index.js +1 -0
  129. package/esm/useSearch/types.d.ts +165 -0
  130. package/esm/useSearch/types.js +1 -0
  131. package/esm/useSearch/useSearch.d.ts +56 -0
  132. package/esm/useSearch/useSearch.js +647 -0
  133. package/esm/withDocsInfra/withDeploymentConfig.js +4 -2
  134. package/esm/withDocsInfra/withDocsInfra.d.ts +39 -0
  135. package/esm/withDocsInfra/withDocsInfra.js +79 -7
  136. package/package.json +106 -6
  137. package/esm/CodeHighlighter/transformParsedSource.d.ts +0 -3
  138. /package/esm/{CodeHighlighter/addPathsToVariant.js → pipeline/loadCodeVariant/addCodeVariantPaths.js} +0 -0
  139. /package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/calculateMainFilePath.d.ts +0 -0
  140. /package/esm/{CodeHighlighter/hasAllVariants.js → pipeline/loadCodeVariant/hasAllCodeVariants.js} +0 -0
  141. /package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/parseCode.js +0 -0
  142. /package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/pathUtils.d.ts +0 -0
  143. /package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/pathUtils.js +0 -0
  144. /package/esm/{CodeHighlighter → pipeline/loadCodeVariant}/transformSource.js +0 -0
@@ -0,0 +1,110 @@
1
+ import type { PhrasingContent } from 'mdast';
2
+ /**
3
+ * Plugin options for transformMarkdownMetadata
4
+ */
5
+ export interface TransformMarkdownMetadataOptions {
6
+ /**
7
+ * A suffix to append to the title when saving it to the `export const metadata` object.
8
+ * This suffix is not included in the metadata used for index extraction or returned metadata.
9
+ *
10
+ * Useful for adding site-wide title suffixes like " | My Site" to page metadata.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * transformMarkdownMetadata({ titleSuffix: ' | Base UI' })
15
+ * // Title "Button" becomes "Button | Base UI" in the export
16
+ * ```
17
+ */
18
+ titleSuffix?: string;
19
+ /**
20
+ * Controls automatic extraction of page metadata to parent directory index files.
21
+ *
22
+ * When enabled, the plugin extracts metadata (title, description, headings) from MDX files
23
+ * and maintains an index in the parent directory's page.mdx file.
24
+ *
25
+ * Index files themselves (e.g., pattern/page.mdx) are automatically excluded from extraction.
26
+ *
27
+ * Can be:
28
+ * - `false` - Disabled
29
+ * - `true` - Enabled with default filter: `{ include: ['app/'], exclude: [] }`
30
+ * - `{ include: string[], exclude: string[] }` - Enabled with custom path filters
31
+ *
32
+ * Path matching uses prefix matching - a file matches if it starts with any include path
33
+ * and doesn't start with any exclude path. Files that are index files themselves
34
+ * (matching pattern/page.mdx) are automatically skipped.
35
+ */
36
+ extractToIndex?: boolean | {
37
+ /** Path prefixes that files must match to have metadata extracted */
38
+ include: string[];
39
+ /** Path prefixes to exclude from metadata extraction */
40
+ exclude: string[];
41
+ /** Base directory to strip from file paths before matching (e.g., '/path/to/project/docs') */
42
+ baseDir?: string;
43
+ /** Only update existing indexes, don't create new ones */
44
+ onlyUpdateIndexes?: boolean;
45
+ /**
46
+ * Directory to write marker files when indexes are updated.
47
+ * Path is relative to baseDir.
48
+ * Set to false to disable marker file creation.
49
+ * @default false
50
+ */
51
+ markerDir?: string | false;
52
+ /**
53
+ * Throw an error if the index is out of date or missing.
54
+ * Useful for CI environments to ensure indexes are committed.
55
+ * @default false
56
+ */
57
+ errorIfOutOfDate?: boolean;
58
+ /**
59
+ * Use the first visible paragraph as the description in the extracted index,
60
+ * even if a meta tag description is present.
61
+ * This does not affect the `export const metadata` which will still use the meta tag.
62
+ * @default false
63
+ */
64
+ useVisibleDescription?: boolean;
65
+ /**
66
+ * Name of a React component to wrap around the autogenerated index content.
67
+ * If provided, the generated markdown will wrap the page list and detail sections
68
+ * in this component (e.g., `<PagesIndex>...</PagesIndex>`).
69
+ *
70
+ * When processing autogenerated index files, the plugin will also automatically
71
+ * inject `SitemapSectionData` as a `data` prop to this wrapper component,
72
+ * enabling dynamic rendering, search, or navigation features.
73
+ *
74
+ * @example 'PagesIndex'
75
+ */
76
+ indexWrapperComponent?: string;
77
+ };
78
+ }
79
+ /**
80
+ * Represents a hierarchical structure of headings.
81
+ * Each heading is keyed by its slug, with title and nested children.
82
+ */
83
+ export type HeadingHierarchy = {
84
+ [slug: string]: {
85
+ title: string;
86
+ titleMarkdown: PhrasingContent[];
87
+ children: HeadingHierarchy;
88
+ };
89
+ };
90
+ /**
91
+ * Extracted metadata from markdown/MDX files
92
+ */
93
+ export interface ExtractedMetadata {
94
+ title?: string;
95
+ description?: string;
96
+ descriptionMarkdown?: PhrasingContent[];
97
+ keywords?: string[];
98
+ sections?: HeadingHierarchy;
99
+ embeddings?: number[];
100
+ openGraph?: {
101
+ title?: string;
102
+ description?: string;
103
+ images?: Array<{
104
+ url: string;
105
+ width: number;
106
+ height: number;
107
+ alt: string;
108
+ }>;
109
+ };
110
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ import { transformMarkdownRelativePaths } from "./transformMarkdownRelativePaths.js";
2
+ export default transformMarkdownRelativePaths;
@@ -0,0 +1,4 @@
1
+ // This is the export format expected by a remark plugin.
2
+
3
+ import { transformMarkdownRelativePaths } from "./transformMarkdownRelativePaths.js";
4
+ export default transformMarkdownRelativePaths;
@@ -0,0 +1,15 @@
1
+ import type { Plugin } from 'unified';
2
+ /**
3
+ * Remark plugin that strips page file extensions from URLs.
4
+ * Removes /page.tsx, /page.jsx, /page.js, /page.mdx, /page.md from both absolute and relative URLs.
5
+ * For relative URLs (both ./ and ../), converts them to absolute paths based on the current file's location.
6
+ * Also removes Next.js route group segments (parenthesis) from URLs.
7
+ *
8
+ * Examples:
9
+ * - /components/page.tsx -> /components
10
+ * - ./code-highlighter/page.mdx -> /components/code-highlighter (when processed from /components/page.mdx)
11
+ * - ../code-highlighter/page.tsx -> /code-highlighter (when processed from /components/button/page.mdx)
12
+ * - /(public)/components/page.tsx -> /components
13
+ * This allows URLs to resolve when reading in VSCode and Github
14
+ */
15
+ export declare const transformMarkdownRelativePaths: Plugin;
@@ -0,0 +1,40 @@
1
+ // webpack does not like node: imports
2
+ // eslint-disable-next-line n/prefer-node-protocol
3
+ import path from 'path';
4
+ import { visit } from 'unist-util-visit';
5
+ /**
6
+ * Remark plugin that strips page file extensions from URLs.
7
+ * Removes /page.tsx, /page.jsx, /page.js, /page.mdx, /page.md from both absolute and relative URLs.
8
+ * For relative URLs (both ./ and ../), converts them to absolute paths based on the current file's location.
9
+ * Also removes Next.js route group segments (parenthesis) from URLs.
10
+ *
11
+ * Examples:
12
+ * - /components/page.tsx -> /components
13
+ * - ./code-highlighter/page.mdx -> /components/code-highlighter (when processed from /components/page.mdx)
14
+ * - ../code-highlighter/page.tsx -> /code-highlighter (when processed from /components/button/page.mdx)
15
+ * - /(public)/components/page.tsx -> /components
16
+ * This allows URLs to resolve when reading in VSCode and Github
17
+ */
18
+ export var transformMarkdownRelativePaths = function transformMarkdownRelativePaths() {
19
+ return function (tree, file) {
20
+ visit(tree, 'link', function (node) {
21
+ if (node.url) {
22
+ node.url = node.url.replace(/\/page\.(tsx|jsx|js|mdx|md)$/g, '');
23
+ node.url = node.url.replace(/\/page\.(tsx|jsx|js|mdx|md)(\?[^#]*)?(#.*)?$/g, '$2$3');
24
+ if ((node.url.startsWith('./') || node.url.startsWith('../')) && file.path) {
25
+ var currentDir = path.dirname(file.path);
26
+ var appIndex = currentDir.indexOf('/app/');
27
+ var baseDir = appIndex !== -1 ? currentDir.substring(appIndex + 4) : '/';
28
+
29
+ // Resolve the relative path from the current directory
30
+ var resolvedPath = path.resolve('/', baseDir, node.url);
31
+ node.url = resolvedPath;
32
+ }
33
+
34
+ // Remove Next.js route group segments (parenthesis)
35
+ node.url = node.url.replace(/\/\([^)]+\)/g, '');
36
+ node.url = node.url.replace(/\/$/, '');
37
+ }
38
+ });
39
+ };
40
+ };
@@ -105,10 +105,16 @@ export function Pre(_ref) {
105
105
  }, {
106
106
  rootMargin: hydrateMargin
107
107
  });
108
- root.childNodes.forEach(function (node) {
108
+
109
+ // <pre><code><span class="frame" data-frame="0">...</span><span class="frame" data-frame="1">...</span>...</code></pre>
110
+ root.childNodes[0].childNodes.forEach(function (node) {
109
111
  if (node.nodeType === Node.ELEMENT_NODE) {
110
112
  var _observer$current;
111
113
  var element = node;
114
+ if (!element.hasAttribute('data-frame')) {
115
+ console.warn('Expected frame element in useCode <Pre>', element);
116
+ return;
117
+ }
112
118
  (_observer$current = observer.current) == null || _observer$current.observe(element);
113
119
  }
114
120
  });
@@ -128,6 +134,11 @@ export function Pre(_ref) {
128
134
  var frames = React.useMemo(function () {
129
135
  return hast == null ? void 0 : hast.children.map(function (child, index) {
130
136
  if (child.type !== 'element') {
137
+ if (child.type === 'text') {
138
+ return /*#__PURE__*/_jsx(React.Fragment, {
139
+ children: child.value
140
+ }, index);
141
+ }
131
142
  return null;
132
143
  }
133
144
  if (child.properties.className === 'frame') {
@@ -150,6 +161,8 @@ export function Pre(_ref) {
150
161
  return /*#__PURE__*/_jsx("pre", {
151
162
  ref: bindIntersectionObserver,
152
163
  className: className,
153
- children: typeof children === 'string' ? children : frames
164
+ children: /*#__PURE__*/_jsx("code", {
165
+ children: typeof children === 'string' ? children : frames
166
+ })
154
167
  });
155
168
  }
@@ -9,6 +9,19 @@ export type UseCodeOpts = {
9
9
  githubUrlPrefix?: string;
10
10
  initialVariant?: string;
11
11
  initialTransform?: string;
12
+ /**
13
+ * Controls hash removal behavior when user interacts with file tabs:
14
+ * - 'remove-hash': Remove entire hash (default)
15
+ * - 'remove-filename': Remove only filename, keep variant in hash
16
+ */
17
+ fileHashMode?: 'remove-hash' | 'remove-filename';
18
+ /**
19
+ * Controls when to save hash variant to localStorage:
20
+ * - 'on-load': Save immediately when page loads with hash
21
+ * - 'on-interaction': Save only when user clicks a tab (default)
22
+ * - 'never': Never save hash variant to localStorage
23
+ */
24
+ saveHashVariantToLocalStorage?: 'on-load' | 'on-interaction' | 'never';
12
25
  };
13
26
  type UserProps<T extends {} = {}> = T & {
14
27
  name?: string;
@@ -17,7 +30,7 @@ type UserProps<T extends {} = {}> = T & {
17
30
  export interface UseCodeResult<T extends {} = {}> {
18
31
  variants: string[];
19
32
  selectedVariant: string;
20
- selectVariant: React.Dispatch<React.SetStateAction<string>>;
33
+ selectVariant: (variant: string | null) => void;
21
34
  files: Array<{
22
35
  name: string;
23
36
  slug?: string;
@@ -34,7 +47,7 @@ export interface UseCodeResult<T extends {} = {}> {
34
47
  }>;
35
48
  expanded: boolean;
36
49
  expand: () => void;
37
- setExpanded: React.Dispatch<React.SetStateAction<boolean>>;
50
+ setExpanded: (expanded: boolean) => void;
38
51
  copy: (event: React.MouseEvent<HTMLButtonElement>) => Promise<void>;
39
52
  availableTransforms: string[];
40
53
  selectedTransform: string | null | undefined;
@@ -18,7 +18,11 @@ export function useCode(contentProps, opts) {
18
18
  initialVariant = _ref.initialVariant,
19
19
  initialTransform = _ref.initialTransform,
20
20
  preClassName = _ref.preClassName,
21
- preRef = _ref.preRef;
21
+ preRef = _ref.preRef,
22
+ _ref$fileHashMode = _ref.fileHashMode,
23
+ fileHashMode = _ref$fileHashMode === void 0 ? 'remove-hash' : _ref$fileHashMode,
24
+ _ref$saveHashVariantT = _ref.saveHashVariantToLocalStorage,
25
+ saveHashVariantToLocalStorage = _ref$saveHashVariantT === void 0 ? 'on-interaction' : _ref$saveHashVariantT;
22
26
 
23
27
  // Safely try to get context values - will be undefined if not in context
24
28
  var context = useCodeHighlighterContextOptional();
@@ -58,9 +62,10 @@ export function useCode(contentProps, opts) {
58
62
  });
59
63
  }, [contentProps, context == null ? void 0 : context.url]);
60
64
 
61
- // Sub-hook: UI State Management
65
+ // Sub-hook: UI State Management (needs slug to check for relevant hash)
62
66
  var uiState = useUIState({
63
- defaultOpen: defaultOpen
67
+ defaultOpen: defaultOpen,
68
+ mainSlug: userProps.slug
64
69
  });
65
70
 
66
71
  // Sub-hook: Variant Selection
@@ -68,7 +73,8 @@ export function useCode(contentProps, opts) {
68
73
  effectiveCode: effectiveCode,
69
74
  initialVariant: initialVariant,
70
75
  variantType: contentProps.variantType,
71
- mainSlug: userProps.slug
76
+ mainSlug: userProps.slug,
77
+ saveHashVariantToLocalStorage: saveHashVariantToLocalStorage
72
78
  });
73
79
 
74
80
  // Sub-hook: Transform Management
@@ -89,11 +95,14 @@ export function useCode(contentProps, opts) {
89
95
  selectedVariantKey: variantSelection.selectedVariantKey,
90
96
  selectVariant: variantSelection.selectVariantProgrammatic,
91
97
  variantKeys: variantSelection.variantKeys,
92
- initialVariant: initialVariant,
93
98
  shouldHighlight: shouldHighlight,
94
99
  preClassName: preClassName,
95
100
  preRef: preRef,
96
- effectiveCode: effectiveCode
101
+ effectiveCode: effectiveCode,
102
+ fileHashMode: fileHashMode,
103
+ saveHashVariantToLocalStorage: saveHashVariantToLocalStorage,
104
+ saveVariantToLocalStorage: variantSelection.saveVariantToLocalStorage,
105
+ hashVariant: variantSelection.hashVariant
97
106
  });
98
107
 
99
108
  // Sub-hook: Copy Functionality
@@ -1,7 +1,7 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
2
  import _typeof from "@babel/runtime/helpers/esm/typeof";
3
3
  import { stringOrHastToJsx } from "../pipeline/hastUtils/index.js";
4
- import { applyTransform } from "../CodeHighlighter/applyTransform.js";
4
+ import { applyCodeTransform } from "../pipeline/loadCodeVariant/applyCodeTransform.js";
5
5
  /**
6
6
  * Pure function to get available transforms from effective code data.
7
7
  * Only includes transforms that have actual deltas (file changes), not just filename changes.
@@ -94,7 +94,7 @@ export function applyTransformToSource(source, fileName, transforms, selectedTra
94
94
  }
95
95
 
96
96
  // Apply transform
97
- var result = applyTransform(source, transforms, selectedTransform);
97
+ var result = applyCodeTransform(source, transforms, selectedTransform);
98
98
  var transformedName = transformData.fileName || fileName;
99
99
  return {
100
100
  transformedSource: result,
@@ -209,7 +209,7 @@ export function createTransformedFiles(selectedVariant, selectedTransform, shoul
209
209
  // Only apply transform if there's a meaningful delta
210
210
  var hasTransformDelta = transformData.delta && Object.keys(transformData.delta).length > 0;
211
211
  if (hasTransformDelta) {
212
- transformedSource = applyTransform(source, transforms, selectedTransform);
212
+ transformedSource = applyCodeTransform(source, transforms, selectedTransform);
213
213
  transformedName = transformData.fileName || extraFileName;
214
214
  }
215
215
  }
@@ -22,11 +22,14 @@ interface UseFileNavigationProps {
22
22
  selectedVariantKey?: string;
23
23
  variantKeys?: string[];
24
24
  shouldHighlight: boolean;
25
- initialVariant?: string;
26
25
  preClassName?: string;
27
26
  preRef?: React.Ref<HTMLPreElement>;
28
27
  effectiveCode?: Code;
29
28
  selectVariant?: React.Dispatch<React.SetStateAction<string>>;
29
+ fileHashMode?: 'remove-hash' | 'remove-filename';
30
+ saveHashVariantToLocalStorage?: 'on-load' | 'on-interaction' | 'never';
31
+ saveVariantToLocalStorage?: (variant: string) => void;
32
+ hashVariant?: string | null;
30
33
  }
31
34
  export interface UseFileNavigationResult {
32
35
  selectedFileName: string | undefined;
@@ -54,11 +57,14 @@ export declare function useFileNavigation({
54
57
  mainSlug,
55
58
  selectedVariantKey,
56
59
  variantKeys,
57
- initialVariant,
58
60
  shouldHighlight,
59
61
  preClassName,
60
62
  preRef,
61
63
  effectiveCode,
62
- selectVariant
64
+ selectVariant,
65
+ fileHashMode,
66
+ saveHashVariantToLocalStorage,
67
+ saveVariantToLocalStorage,
68
+ hashVariant
63
69
  }: UseFileNavigationProps): UseFileNavigationResult;
64
70
  export {};