@mui/internal-docs-infra 0.2.3-canary.14 → 0.2.3-canary.15

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 (26) hide show
  1. package/README.md +3 -2
  2. package/esm/pipeline/getFileConventions/fileConventions.d.ts +4 -0
  3. package/esm/pipeline/getFileConventions/fileConventions.js +4 -0
  4. package/esm/pipeline/getFileConventions/getFileConventions.d.ts +4 -0
  5. package/esm/pipeline/getFileConventions/getFileConventions.js +17 -0
  6. package/esm/pipeline/getFileConventions/index.d.ts +1 -0
  7. package/esm/pipeline/getFileConventions/index.js +1 -0
  8. package/esm/pipeline/loadCodeVariant/calculateMainFilePath.js +1 -1
  9. package/esm/pipeline/transformMarkdownBlockquoteCallouts/index.d.ts +2 -0
  10. package/esm/pipeline/transformMarkdownBlockquoteCallouts/index.js +4 -0
  11. package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.d.ts +16 -0
  12. package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.js +58 -0
  13. package/esm/pipeline/transformMarkdownDemoLinks/index.d.ts +2 -0
  14. package/esm/pipeline/transformMarkdownDemoLinks/index.js +4 -0
  15. package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.d.ts +26 -0
  16. package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.js +107 -0
  17. package/esm/pipeline/transformMarkdownRelativePaths/index.d.ts +2 -0
  18. package/esm/pipeline/transformMarkdownRelativePaths/index.js +4 -0
  19. package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.d.ts +13 -0
  20. package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.js +35 -0
  21. package/esm/useCode/Pre.js +8 -1
  22. package/esm/useCopier/index.js +5 -4
  23. package/esm/useErrors/useErrors.d.ts +1 -1
  24. package/esm/useErrors/useErrors.js +6 -2
  25. package/esm/withDocsInfra/withDocsInfra.js +1 -1
  26. package/package.json +26 -2
package/README.md CHANGED
@@ -4,6 +4,7 @@ This package hosts the tools that help create the documentation.
4
4
 
5
5
  ## Documentation
6
6
 
7
- This is stored in the `docs` directory.
7
+ This is stored in the `docs` top-level directory.
8
8
 
9
- [Read More](../../docs/app/docs-infra/page.mdx)
9
+ [Read in Markdown](../../docs/app/docs-infra/page.mdx)
10
+ [Read in Browser](https://infra.mui.com/docs-infra)
@@ -0,0 +1,4 @@
1
+ export declare const fileConventions: {
2
+ rule: string;
3
+ loader: string;
4
+ }[];
@@ -0,0 +1,4 @@
1
+ export var fileConventions = [{
2
+ rule: './app/**/demos/*/index.ts',
3
+ loader: 'loadPrecomputedCodeHighlighter'
4
+ }];
@@ -0,0 +1,4 @@
1
+ export declare function getFileConventions(): Promise<{
2
+ rule: string;
3
+ loader: string;
4
+ }[]>;
@@ -0,0 +1,17 @@
1
+ import _regenerator from "@babel/runtime/helpers/esm/regenerator";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
+ import { fileConventions } from "./fileConventions.js";
4
+ export function getFileConventions() {
5
+ return _getFileConventions.apply(this, arguments);
6
+ }
7
+ function _getFileConventions() {
8
+ _getFileConventions = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
9
+ return _regenerator().w(function (_context) {
10
+ while (1) switch (_context.n) {
11
+ case 0:
12
+ return _context.a(2, fileConventions);
13
+ }
14
+ }, _callee);
15
+ }));
16
+ return _getFileConventions.apply(this, arguments);
17
+ }
@@ -0,0 +1 @@
1
+ export * from "./getFileConventions.js";
@@ -0,0 +1 @@
1
+ export * from "./getFileConventions.js";
@@ -1,5 +1,5 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
- import { createSyntheticDirectories, buildPath } from './pathUtils.js';
2
+ import { createSyntheticDirectories, buildPath } from "./pathUtils.js";
3
3
  export function calculateMainFilePath(url, maxBackNav, maxSourceBackNav, metadataPrefix, fileName) {
4
4
  // Handle optional parameters with defaults
5
5
  var actualMaxSourceBackNav = maxSourceBackNav != null ? maxSourceBackNav : maxBackNav;
@@ -0,0 +1,2 @@
1
+ import { transformMarkdownBlockquoteCallouts } from "./transformMarkdownBlockquoteCallouts.js";
2
+ export default transformMarkdownBlockquoteCallouts;
@@ -0,0 +1,4 @@
1
+ // This is the export format expected by a remark plugin.
2
+
3
+ import { transformMarkdownBlockquoteCallouts } from "./transformMarkdownBlockquoteCallouts.js";
4
+ export default transformMarkdownBlockquoteCallouts;
@@ -0,0 +1,16 @@
1
+ import type { Plugin } from 'unified';
2
+ /**
3
+ * Remark plugin that extracts GitHub-style callouts from blockquotes and injects them into data attributes.
4
+ *
5
+ * Transforms blockquotes like:
6
+ * > [!NOTE]
7
+ * > This is a note.
8
+ *
9
+ * Into blockquotes with a custom data attribute that will be preserved when converted to HTML:
10
+ * <blockquote data-callout-type="note">
11
+ * <p>This is a note.</p>
12
+ * </blockquote>
13
+ *
14
+ * Supported callout types: NOTE, TIP, IMPORTANT, WARNING, CAUTION
15
+ */
16
+ export declare const transformMarkdownBlockquoteCallouts: Plugin;
@@ -0,0 +1,58 @@
1
+ import { visit } from 'unist-util-visit';
2
+ /**
3
+ * Remark plugin that extracts GitHub-style callouts from blockquotes and injects them into data attributes.
4
+ *
5
+ * Transforms blockquotes like:
6
+ * > [!NOTE]
7
+ * > This is a note.
8
+ *
9
+ * Into blockquotes with a custom data attribute that will be preserved when converted to HTML:
10
+ * <blockquote data-callout-type="note">
11
+ * <p>This is a note.</p>
12
+ * </blockquote>
13
+ *
14
+ * Supported callout types: NOTE, TIP, IMPORTANT, WARNING, CAUTION
15
+ */
16
+ export var transformMarkdownBlockquoteCallouts = function transformMarkdownBlockquoteCallouts() {
17
+ return function (tree) {
18
+ visit(tree, 'blockquote', function (node) {
19
+ // Find the first paragraph in the blockquote
20
+ var firstChild = node.children[0];
21
+ if (!firstChild || firstChild.type !== 'paragraph') {
22
+ return;
23
+ }
24
+
25
+ // Find the first text node in the paragraph
26
+ var firstTextNode = firstChild.children[0];
27
+ if (!firstTextNode || firstTextNode.type !== 'text') {
28
+ return;
29
+ }
30
+ var textNode = firstTextNode;
31
+ var calloutPattern = /^\[!(NOTE|TIP|IMPORTANT|WARNING|CAUTION)\]\s*/;
32
+ var match = textNode.value.match(calloutPattern);
33
+ if (match) {
34
+ var calloutType = match[1].toLowerCase();
35
+
36
+ // Remove the callout marker from the text
37
+ var newText = textNode.value.replace(calloutPattern, '');
38
+ if (newText.trim() === '') {
39
+ // Remove the text node if it becomes empty
40
+ firstChild.children.shift();
41
+ } else {
42
+ // Update the text content
43
+ textNode.value = newText;
44
+ }
45
+
46
+ // Add the data attribute to the blockquote
47
+ // This creates a custom property that will be preserved when converting to HTML
48
+ if (!node.data) {
49
+ node.data = {};
50
+ }
51
+ if (!node.data.hProperties) {
52
+ node.data.hProperties = {};
53
+ }
54
+ node.data.hProperties['data-callout-type'] = calloutType;
55
+ }
56
+ });
57
+ };
58
+ };
@@ -0,0 +1,2 @@
1
+ import { transformMarkdownDemoLinks } from "./transformMarkdownDemoLinks.js";
2
+ export default transformMarkdownDemoLinks;
@@ -0,0 +1,4 @@
1
+ // This is the export format expected by a remark plugin.
2
+
3
+ import { transformMarkdownDemoLinks } from "./transformMarkdownDemoLinks.js";
4
+ export default transformMarkdownDemoLinks;
@@ -0,0 +1,26 @@
1
+ import type { Plugin } from 'unified';
2
+ /**
3
+ * Remark plugin that cleans up demo patterns in markdown.
4
+ *
5
+ * Looks for patterns where a Demo component is followed by a "[See Demo]" link
6
+ * and optionally a horizontal rule (---). When found, removes the link and
7
+ * any following horizontal rule.
8
+ *
9
+ * This is useful for markdown that will be converted to HTML where the link
10
+ * and separator are distracting on the page.
11
+ *
12
+ * Pattern it matches:
13
+ * ```
14
+ * <DemoSomething />
15
+ *
16
+ * [See Demo](./demos/base/)
17
+ *
18
+ * --- (optional)
19
+ * ```
20
+ *
21
+ * Gets transformed to:
22
+ * ```
23
+ * <DemoSomething />
24
+ * ```
25
+ */
26
+ export declare const transformMarkdownDemoLinks: Plugin;
@@ -0,0 +1,107 @@
1
+ // MDX JSX types
2
+
3
+ /**
4
+ * Remark plugin that cleans up demo patterns in markdown.
5
+ *
6
+ * Looks for patterns where a Demo component is followed by a "[See Demo]" link
7
+ * and optionally a horizontal rule (---). When found, removes the link and
8
+ * any following horizontal rule.
9
+ *
10
+ * This is useful for markdown that will be converted to HTML where the link
11
+ * and separator are distracting on the page.
12
+ *
13
+ * Pattern it matches:
14
+ * ```
15
+ * <DemoSomething />
16
+ *
17
+ * [See Demo](./demos/base/)
18
+ *
19
+ * --- (optional)
20
+ * ```
21
+ *
22
+ * Gets transformed to:
23
+ * ```
24
+ * <DemoSomething />
25
+ * ```
26
+ */
27
+ export var transformMarkdownDemoLinks = function transformMarkdownDemoLinks() {
28
+ return function (tree) {
29
+ var parent = tree;
30
+ var children = parent.children;
31
+ for (var i = 0; i < children.length - 1; i += 1) {
32
+ var current = children[i];
33
+ var next = children[i + 1];
34
+ var separator = children[i + 2]; // May not exist
35
+
36
+ var hasDemo = false;
37
+
38
+ // Check if current node is an HTML element containing a Demo component without .Title
39
+ if ((current == null ? void 0 : current.type) === 'html') {
40
+ var htmlNode = current;
41
+ hasDemo = htmlNode.value.includes('<Demo') && !htmlNode.value.includes('.Title');
42
+ } else if ((current == null ? void 0 : current.type) === 'mdxJsxFlowElement') {
43
+ // Check if current node is an MDX JSX element (for imported Demo components)
44
+ var mdxNode = current;
45
+ if (mdxNode.name && mdxNode.name.includes('Demo') && !mdxNode.name.includes('.Title')) {
46
+ hasDemo = true;
47
+ }
48
+ } else if ((current == null ? void 0 : current.type) === 'paragraph') {
49
+ // Check if paragraph contains only a single HTML node with a Demo component
50
+ var paragraphNode = current;
51
+ if (paragraphNode.children.length === 1 && paragraphNode.children[0].type === 'html') {
52
+ var _htmlNode = paragraphNode.children[0];
53
+ hasDemo = _htmlNode.value.includes('<Demo') && !_htmlNode.value.includes('.Title');
54
+ } else if (paragraphNode.children.length >= 2 && paragraphNode.children[0].type === 'html' && paragraphNode.children[paragraphNode.children.length - 1].type === 'html') {
55
+ // Check if this looks like a Demo component with opening and closing tags
56
+ var openingTag = paragraphNode.children[0];
57
+ var closingTag = paragraphNode.children[paragraphNode.children.length - 1];
58
+ if (openingTag.value.includes('<Demo') && !openingTag.value.includes('.Title') && closingTag.value.includes('</Demo')) {
59
+ hasDemo = true;
60
+ }
61
+ } else {
62
+ // Check if paragraph contains any HTML nodes with Demo components (mixed content)
63
+ hasDemo = paragraphNode.children.some(function (child) {
64
+ return child.type === 'html' && child.value.includes('<Demo') && !child.value.includes('.Title');
65
+ });
66
+ }
67
+ }
68
+ if (!hasDemo) {
69
+ continue;
70
+ }
71
+ var removedSomething = false;
72
+
73
+ // Check if next node is a paragraph containing a "See Demo" link
74
+ if ((next == null ? void 0 : next.type) === 'paragraph') {
75
+ var hasSeeDemo = next.children.some(function (child) {
76
+ return child.type === 'link' && child.children.some(function (linkChild) {
77
+ return linkChild.type === 'text' && linkChild.value === 'See Demo';
78
+ });
79
+ });
80
+
81
+ // Check if there's also a thematic break (---) after the paragraph
82
+ var hasThematicBreak = (separator == null ? void 0 : separator.type) === 'thematicBreak';
83
+ if (hasSeeDemo) {
84
+ // Remove the "See Demo" paragraph and any following thematic break
85
+ if (hasThematicBreak) {
86
+ // Remove both the "See Demo" paragraph and the thematic break
87
+ children.splice(i + 1, 2);
88
+ removedSomething = true;
89
+ } else {
90
+ // Remove only the "See Demo" paragraph
91
+ children.splice(i + 1, 1);
92
+ removedSomething = true;
93
+ }
94
+ } else if (hasThematicBreak) {
95
+ // No "See Demo" link, but there's a thematic break after the paragraph - remove just the HR
96
+ children.splice(i + 2, 1);
97
+ removedSomething = true;
98
+ }
99
+ }
100
+
101
+ // If we removed something, adjust the loop index to prevent skipping
102
+ if (removedSomething) {
103
+ i -= 1;
104
+ }
105
+ }
106
+ };
107
+ };
@@ -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,13 @@
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
+ *
7
+ * Examples:
8
+ * - /components/page.tsx -> /components
9
+ * - ./code-highlighter/page.mdx -> /components/code-highlighter (when processed from /components/page.mdx)
10
+ * - ../code-highlighter/page.tsx -> /code-highlighter (when processed from /components/button/page.mdx)
11
+ * This allows URLs to resolve when reading in VSCode and Github
12
+ */
13
+ export declare const transformMarkdownRelativePaths: Plugin;
@@ -0,0 +1,35 @@
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
+ *
10
+ * Examples:
11
+ * - /components/page.tsx -> /components
12
+ * - ./code-highlighter/page.mdx -> /components/code-highlighter (when processed from /components/page.mdx)
13
+ * - ../code-highlighter/page.tsx -> /code-highlighter (when processed from /components/button/page.mdx)
14
+ * This allows URLs to resolve when reading in VSCode and Github
15
+ */
16
+ export var transformMarkdownRelativePaths = function transformMarkdownRelativePaths() {
17
+ return function (tree, file) {
18
+ visit(tree, 'link', function (node) {
19
+ if (node.url) {
20
+ node.url = node.url.replace(/\/page\.(tsx|jsx|js|mdx|md)$/g, '');
21
+ node.url = node.url.replace(/\/page\.(tsx|jsx|js|mdx|md)(\?[^#]*)?(#.*)?$/g, '$2$3');
22
+ if ((node.url.startsWith('./') || node.url.startsWith('../')) && file.path) {
23
+ var currentDir = path.dirname(file.path);
24
+ var appIndex = currentDir.indexOf('/app/');
25
+ var baseDir = appIndex !== -1 ? currentDir.substring(appIndex + 4) : '/';
26
+
27
+ // Resolve the relative path from the current directory
28
+ var resolvedPath = path.resolve('/', baseDir, node.url);
29
+ node.url = resolvedPath;
30
+ }
31
+ node.url = node.url.replace(/\/$/, '');
32
+ }
33
+ });
34
+ };
35
+ };
@@ -128,6 +128,11 @@ export function Pre(_ref) {
128
128
  var frames = React.useMemo(function () {
129
129
  return hast == null ? void 0 : hast.children.map(function (child, index) {
130
130
  if (child.type !== 'element') {
131
+ if (child.type === 'text') {
132
+ return /*#__PURE__*/_jsx(React.Fragment, {
133
+ children: child.value
134
+ }, index);
135
+ }
131
136
  return null;
132
137
  }
133
138
  if (child.properties.className === 'frame') {
@@ -150,6 +155,8 @@ export function Pre(_ref) {
150
155
  return /*#__PURE__*/_jsx("pre", {
151
156
  ref: bindIntersectionObserver,
152
157
  className: className,
153
- children: typeof children === 'string' ? children : frames
158
+ children: /*#__PURE__*/_jsx("code", {
159
+ children: typeof children === 'string' ? children : frames
160
+ })
154
161
  });
155
162
  }
@@ -32,7 +32,12 @@ export function useCopier(contents, opts) {
32
32
  _context.n = 2;
33
33
  return copyToClipboard(content);
34
34
  case 2:
35
+ setRecentlySuccessful(true);
35
36
  onCopied == null || onCopied();
37
+ copyTimeoutRef.current = setTimeout(function () {
38
+ clearTimeout(copyTimeoutRef.current);
39
+ setRecentlySuccessful(false);
40
+ }, timeout);
36
41
  _context.n = 4;
37
42
  break;
38
43
  case 3:
@@ -41,10 +46,6 @@ export function useCopier(contents, opts) {
41
46
  onError == null || onError(_t);
42
47
  case 4:
43
48
  onClick == null || onClick(event);
44
- copyTimeoutRef.current = setTimeout(function () {
45
- clearTimeout(copyTimeoutRef.current);
46
- setRecentlySuccessful(false);
47
- }, timeout);
48
49
  case 5:
49
50
  return _context.a(2);
50
51
  }
@@ -1,5 +1,5 @@
1
1
  type Errors = {
2
2
  errors?: Error[];
3
3
  };
4
- export declare function useErrors(): Errors;
4
+ export declare function useErrors(props?: Errors): Errors;
5
5
  export {};
@@ -1,7 +1,11 @@
1
1
  import { useErrorsContext } from "./ErrorsContext.js";
2
- export function useErrors() {
2
+ export function useErrors(props) {
3
3
  var context = useErrorsContext();
4
+
5
+ // Context errors take precedence over prop errors
6
+ // This ensures client-side errors override server-side errors
7
+ var errors = (context == null ? void 0 : context.errors) || (props == null ? void 0 : props.errors);
4
8
  return {
5
- errors: context == null ? void 0 : context.errors
9
+ errors: errors
6
10
  };
7
11
  }
@@ -9,7 +9,7 @@ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
9
9
  export function getDocsInfraMdxOptions() {
10
10
  var _customOptions$remark, _customOptions$additi, _customOptions$rehype, _customOptions$additi2;
11
11
  var customOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
12
- var defaultRemarkPlugins = [['remark-gfm'], ['@mui/internal-docs-infra/pipeline/transformMarkdownCode']];
12
+ var defaultRemarkPlugins = [['remark-gfm'], ['@mui/internal-docs-infra/pipeline/transformMarkdownRelativePaths'], ['@mui/internal-docs-infra/pipeline/transformMarkdownBlockquoteCallouts'], ['@mui/internal-docs-infra/pipeline/transformMarkdownCode'], ['@mui/internal-docs-infra/pipeline/transformMarkdownDemoLinks']];
13
13
  var defaultRehypePlugins = [['@mui/internal-docs-infra/pipeline/transformHtmlCodePrecomputed']];
14
14
 
15
15
  // Build final plugin arrays
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/internal-docs-infra",
3
- "version": "0.2.3-canary.14",
3
+ "version": "0.2.3-canary.15",
4
4
  "author": "MUI Team",
5
5
  "description": "MUI Infra - internal documentation creation tools.",
6
6
  "keywords": [
@@ -167,6 +167,30 @@
167
167
  "default": "./esm/withDocsInfra/index.js"
168
168
  }
169
169
  },
170
+ "./pipeline/getFileConventions": {
171
+ "default": {
172
+ "types": "./esm/pipeline/getFileConventions/index.d.ts",
173
+ "default": "./esm/pipeline/getFileConventions/index.js"
174
+ }
175
+ },
176
+ "./pipeline/transformMarkdownBlockquoteCallouts": {
177
+ "default": {
178
+ "types": "./esm/pipeline/transformMarkdownBlockquoteCallouts/index.d.ts",
179
+ "default": "./esm/pipeline/transformMarkdownBlockquoteCallouts/index.js"
180
+ }
181
+ },
182
+ "./pipeline/transformMarkdownDemoLinks": {
183
+ "default": {
184
+ "types": "./esm/pipeline/transformMarkdownDemoLinks/index.d.ts",
185
+ "default": "./esm/pipeline/transformMarkdownDemoLinks/index.js"
186
+ }
187
+ },
188
+ "./pipeline/transformMarkdownRelativePaths": {
189
+ "default": {
190
+ "types": "./esm/pipeline/transformMarkdownRelativePaths/index.d.ts",
191
+ "default": "./esm/pipeline/transformMarkdownRelativePaths/index.js"
192
+ }
193
+ },
170
194
  "./pipeline/hastUtils": {
171
195
  "default": {
172
196
  "types": "./esm/pipeline/hastUtils/index.d.ts",
@@ -235,5 +259,5 @@
235
259
  },
236
260
  "./esm": null
237
261
  },
238
- "gitSha": "8e64ec558ea98ce0a577b4b11cd8ffd78de4f0a3"
262
+ "gitSha": "34cb67a083eb058dd61fc7961dffbd32ef28e11a"
239
263
  }