@docusaurus/theme-classic 0.0.0-4764 → 0.0.0-4768

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.
@@ -137,6 +137,62 @@ function getSwizzleConfig() {
137
137
  },
138
138
  description: 'The MDX components to use for rendering MDX files. Meant to be ejected.'
139
139
  },
140
+ 'MDXComponents/A': {
141
+ actions: {
142
+ eject: 'safe',
143
+ wrap: 'safe'
144
+ },
145
+ description: 'The component used to render <a> tags and Markdown links in MDX'
146
+ },
147
+ 'MDXComponents/Code': {
148
+ actions: {
149
+ eject: 'safe',
150
+ wrap: 'safe'
151
+ },
152
+ description: 'The component used to render <code> tags and Markdown code blocks in MDX'
153
+ },
154
+ 'MDXComponents/Details': {
155
+ actions: {
156
+ eject: 'safe',
157
+ wrap: 'safe'
158
+ },
159
+ description: 'The component used to render <details> tags in MDX'
160
+ },
161
+ 'MDXComponents/Head': {
162
+ actions: {
163
+ eject: 'forbidden',
164
+ wrap: 'forbidden'
165
+ },
166
+ description: 'Technical component used to assign metadata (generally for SEO purpose) to the current MDX document'
167
+ },
168
+ 'MDXComponents/Heading': {
169
+ actions: {
170
+ eject: 'safe',
171
+ wrap: 'safe'
172
+ },
173
+ description: 'The component used to render heading tags (<h1>, <h2>...) and Markdown headings in MDX'
174
+ },
175
+ 'MDXComponents/Img': {
176
+ actions: {
177
+ eject: 'safe',
178
+ wrap: 'safe'
179
+ },
180
+ description: 'The component used to render <img> tags and Markdown images in MDX'
181
+ },
182
+ 'MDXComponents/Pre': {
183
+ actions: {
184
+ eject: 'safe',
185
+ wrap: 'safe'
186
+ },
187
+ description: 'The component used to render <pre> tags in MDX'
188
+ },
189
+ 'MDXComponents/Ul': {
190
+ actions: {
191
+ eject: 'safe',
192
+ wrap: 'safe'
193
+ },
194
+ description: 'The component used to render <ul> tags and Markdown unordered lists in MDX'
195
+ },
140
196
  MDXContent: {
141
197
  actions: {
142
198
  eject: 'safe',
@@ -417,24 +417,97 @@ declare module '@theme/SkipToContent' {
417
417
  export default function SkipToContent(): JSX.Element;
418
418
  }
419
419
 
420
- declare module '@theme/MDXComponents' {
420
+ declare module '@theme/MDXComponents/A' {
421
+ import type {ComponentProps} from 'react';
422
+
423
+ export interface Props extends ComponentProps<'a'> {}
424
+
425
+ export default function MDXA(props: Props): JSX.Element;
426
+ }
427
+
428
+ declare module '@theme/MDXComponents/Code' {
429
+ import type {ComponentProps} from 'react';
430
+
431
+ export interface Props extends ComponentProps<'code'> {}
432
+
433
+ export default function MDXCode(props: Props): JSX.Element;
434
+ }
435
+
436
+ declare module '@theme/MDXComponents/Details' {
421
437
  import type {ComponentProps} from 'react';
422
- import type CodeBlock from '@theme/CodeBlock';
423
- import type Head from '@docusaurus/Head';
438
+
439
+ export interface Props extends ComponentProps<'details'> {}
440
+
441
+ export default function MDXDetails(props: Props): JSX.Element;
442
+ }
443
+
444
+ declare module '@theme/MDXComponents/Ul' {
445
+ import type {ComponentProps} from 'react';
446
+
447
+ export interface Props extends ComponentProps<'ul'> {}
448
+
449
+ export default function MDXUl(props: Props): JSX.Element;
450
+ }
451
+
452
+ declare module '@theme/MDXComponents/Img' {
453
+ import type {ComponentProps} from 'react';
454
+
455
+ export interface Props extends ComponentProps<'img'> {}
456
+
457
+ export default function MDXImg(props: Props): JSX.Element;
458
+ }
459
+
460
+ declare module '@theme/MDXComponents/Head' {
461
+ import type {ComponentProps} from 'react';
462
+
463
+ export interface Props extends ComponentProps<'head'> {}
464
+
465
+ export default function MDXHead(props: Props): JSX.Element;
466
+ }
467
+
468
+ declare module '@theme/MDXComponents/Heading' {
469
+ import type {ComponentProps} from 'react';
470
+ import type Heading from '@theme/Heading';
471
+
472
+ export interface Props extends ComponentProps<typeof Heading> {}
473
+
474
+ export default function MDXHeading(props: Props): JSX.Element;
475
+ }
476
+
477
+ declare module '@theme/MDXComponents/Pre' {
478
+ import type {ComponentProps} from 'react';
479
+
480
+ export interface Props extends ComponentProps<'pre'> {}
481
+
482
+ export default function MDXPre(props: Props): JSX.Element;
483
+ }
484
+
485
+ declare module '@theme/MDXComponents' {
486
+ import type {ComponentType, ComponentProps} from 'react';
487
+
488
+ import type MDXHead from '@theme/MDXComponents/Head';
489
+ import type MDXCode from '@theme/MDXComponents/Code';
490
+ import type MDXA from '@theme/MDXComponents/A';
491
+ import type MDXPre from '@theme/MDXComponents/Pre';
492
+ import type MDXDetails from '@theme/MDXComponents/Details';
493
+ import type MDXUl from '@theme/MDXComponents/Ul';
494
+ import type MDXImg from '@theme/MDXComponents/Img';
424
495
 
425
496
  export type MDXComponentsObject = {
426
- readonly head: typeof Head;
427
- readonly code: typeof CodeBlock;
428
- readonly a: (props: ComponentProps<'a'>) => JSX.Element;
429
- readonly pre: typeof CodeBlock;
430
- readonly details: (props: ComponentProps<'details'>) => JSX.Element;
497
+ readonly head: typeof MDXHead;
498
+ readonly code: typeof MDXCode;
499
+ readonly a: typeof MDXA;
500
+ readonly pre: typeof MDXPre;
501
+ readonly details: typeof MDXDetails;
502
+ readonly ul: typeof MDXUl;
503
+ readonly img: typeof MDXImg;
431
504
  readonly h1: (props: ComponentProps<'h1'>) => JSX.Element;
432
505
  readonly h2: (props: ComponentProps<'h2'>) => JSX.Element;
433
506
  readonly h3: (props: ComponentProps<'h3'>) => JSX.Element;
434
507
  readonly h4: (props: ComponentProps<'h4'>) => JSX.Element;
435
508
  readonly h5: (props: ComponentProps<'h5'>) => JSX.Element;
436
509
  readonly h6: (props: ComponentProps<'h6'>) => JSX.Element;
437
- };
510
+ } & Record<string, ComponentType<unknown>>;
438
511
 
439
512
  const MDXComponents: MDXComponentsObject;
440
513
  export default MDXComponents;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import React from 'react';
8
+ import Link from '@docusaurus/Link';
9
+ export default function MDXA(props) {
10
+ return <Link {...props} />;
11
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import React, {isValidElement} from 'react';
8
+ import CodeBlock from '@theme/CodeBlock';
9
+ export default function MDXCode(props) {
10
+ const inlineElements = [
11
+ 'a',
12
+ 'b',
13
+ 'big',
14
+ 'i',
15
+ 'span',
16
+ 'em',
17
+ 'strong',
18
+ 'sup',
19
+ 'sub',
20
+ 'small',
21
+ ];
22
+ const shouldBeInline = React.Children.toArray(props.children).every(
23
+ (el) =>
24
+ (typeof el === 'string' && !el.includes('\n')) ||
25
+ (isValidElement(el) && inlineElements.includes(el.props.mdxType)),
26
+ );
27
+ return shouldBeInline ? <code {...props} /> : <CodeBlock {...props} />;
28
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import React from 'react';
8
+ import Details from '@theme/Details';
9
+ export default function MDXDetails(props) {
10
+ const items = React.Children.toArray(props.children); // Split summary item from the rest to pass it as a separate prop to the
11
+ // Details theme component
12
+
13
+ const summary = items.find((item) => item?.props?.mdxType === 'summary');
14
+ const children = <>{items.filter((item) => item !== summary)}</>;
15
+ return (
16
+ <Details {...props} summary={summary}>
17
+ {children}
18
+ </Details>
19
+ );
20
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import React from 'react';
8
+ import Head from '@docusaurus/Head';
9
+
10
+ // MDX elements are wrapped through the MDX pragma. In some cases (notably usage
11
+ // with Head/Helmet) we need to unwrap those elements.
12
+ function unwrapMDXElement(element) {
13
+ if (element?.props?.mdxType && element?.props?.originalType) {
14
+ const {mdxType, originalType, ...newProps} = element.props;
15
+ return React.createElement(element.props.originalType, newProps);
16
+ }
17
+
18
+ return element;
19
+ }
20
+
21
+ export default function MDXHead(props) {
22
+ const unwrappedChildren = React.Children.map(props.children, (child) =>
23
+ unwrapMDXElement(child),
24
+ );
25
+ return <Head {...props}>{unwrappedChildren}</Head>;
26
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import React from 'react';
8
+ import Heading from '@theme/Heading';
9
+ export default function MDXHeading(props) {
10
+ return <Heading {...props} />;
11
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import React from 'react';
8
+ import styles from './Img.module.css';
9
+ import clsx from 'clsx';
10
+
11
+ function transformImgClassName(className) {
12
+ return clsx(className, styles.img);
13
+ }
14
+
15
+ export default function MDXImg(props) {
16
+ // eslint-disable-next-line jsx-a11y/alt-text
17
+ return <img {...props} className={transformImgClassName(props.className)} />;
18
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ .img {
9
+ height: auto;
10
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import React, {isValidElement} from 'react';
8
+ import CodeBlock from '@theme/CodeBlock';
9
+ export default function MDXPre(props) {
10
+ return (
11
+ <CodeBlock // If this pre is created by a ``` fenced codeblock, unwrap the children
12
+ {...(isValidElement(props.children) &&
13
+ props.children.props.originalType === 'code'
14
+ ? props.children?.props
15
+ : {...props})}
16
+ />
17
+ );
18
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import React from 'react';
8
+ import clsx from 'clsx';
9
+ import styles from './Ul.module.css';
10
+ const containsClassListLocalClass = styles['contains-task-list'];
11
+
12
+ function transformUlClassName(className) {
13
+ return clsx(
14
+ className, // This class is set globally by GitHub/MDX
15
+ // We keep the global class, but apply scoped CSS
16
+ // See https://github.com/syntax-tree/mdast-util-to-hast/issues/28
17
+ className?.includes('contains-task-list') && containsClassListLocalClass,
18
+ );
19
+ }
20
+
21
+ export default function MDXUl(props) {
22
+ return <ul {...props} className={transformUlClassName(props.className)} />;
23
+ }
@@ -5,11 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- ul.contains-task-list {
8
+ .contains-task-list {
9
9
  padding-left: 0;
10
10
  list-style: none;
11
11
  }
12
-
13
- img {
14
- height: auto;
15
- }
@@ -4,77 +4,28 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import React, {isValidElement} from 'react';
8
- import Head from '@docusaurus/Head';
9
- import Link from '@docusaurus/Link';
10
- import CodeBlock from '@theme/CodeBlock';
11
- import Heading from '@theme/Heading';
12
- import Details from '@theme/Details';
13
- import './styles.css'; // MDX elements are wrapped through the MDX pragma. In some cases (notably usage
14
- // with Head/Helmet) we need to unwrap those elements.
15
-
16
- function unwrapMDXElement(element) {
17
- if (element?.props?.mdxType && element?.props?.originalType) {
18
- const {mdxType, originalType, ...newProps} = element.props;
19
- return React.createElement(element.props.originalType, newProps);
20
- }
21
-
22
- return element;
23
- }
24
-
7
+ import React from 'react';
8
+ import MDXHead from '@theme/MDXComponents/Head';
9
+ import MDXCode from '@theme/MDXComponents/Code';
10
+ import MDXA from '@theme/MDXComponents/A';
11
+ import MDXPre from '@theme/MDXComponents/Pre';
12
+ import MDXDetails from '@theme/MDXComponents/Details';
13
+ import MDXHeading from '@theme/MDXComponents/Heading';
14
+ import MDXUl from '@theme/MDXComponents/Ul';
15
+ import MDXImg from '@theme/MDXComponents/Img';
25
16
  const MDXComponents = {
26
- head: (props) => {
27
- const unwrappedChildren = React.Children.map(props.children, (child) =>
28
- unwrapMDXElement(child),
29
- );
30
- return <Head {...props}>{unwrappedChildren}</Head>;
31
- },
32
- code: (props) => {
33
- const inlineElements = [
34
- 'a',
35
- 'b',
36
- 'big',
37
- 'i',
38
- 'span',
39
- 'em',
40
- 'strong',
41
- 'sup',
42
- 'sub',
43
- 'small',
44
- ];
45
- const shouldBeInline = React.Children.toArray(props.children).every(
46
- (el) =>
47
- (typeof el === 'string' && !el.includes('\n')) ||
48
- (isValidElement(el) && inlineElements.includes(el.props.mdxType)),
49
- );
50
- return shouldBeInline ? <code {...props} /> : <CodeBlock {...props} />;
51
- },
52
- a: (props) => <Link {...props} />,
53
- pre: (props) => (
54
- <CodeBlock // If this pre is created by a ``` fenced codeblock, unwrap the children
55
- {...(isValidElement(props.children) &&
56
- props.children.props.originalType === 'code'
57
- ? props.children?.props
58
- : {...props})}
59
- />
60
- ),
61
- details: (props) => {
62
- const items = React.Children.toArray(props.children); // Split summary item from the rest to pass it as a separate prop to the
63
- // Details theme component
64
-
65
- const summary = items.find((item) => item?.props?.mdxType === 'summary');
66
- const children = <>{items.filter((item) => item !== summary)}</>;
67
- return (
68
- <Details {...props} summary={summary}>
69
- {children}
70
- </Details>
71
- );
72
- },
73
- h1: (props) => <Heading as="h1" {...props} />,
74
- h2: (props) => <Heading as="h2" {...props} />,
75
- h3: (props) => <Heading as="h3" {...props} />,
76
- h4: (props) => <Heading as="h4" {...props} />,
77
- h5: (props) => <Heading as="h5" {...props} />,
78
- h6: (props) => <Heading as="h6" {...props} />,
17
+ head: MDXHead,
18
+ code: MDXCode,
19
+ a: MDXA,
20
+ pre: MDXPre,
21
+ details: MDXDetails,
22
+ ul: MDXUl,
23
+ img: MDXImg,
24
+ h1: (props) => <MDXHeading as="h1" {...props} />,
25
+ h2: (props) => <MDXHeading as="h2" {...props} />,
26
+ h3: (props) => <MDXHeading as="h3" {...props} />,
27
+ h4: (props) => <MDXHeading as="h4" {...props} />,
28
+ h5: (props) => <MDXHeading as="h5" {...props} />,
29
+ h6: (props) => <MDXHeading as="h6" {...props} />,
79
30
  };
80
31
  export default MDXComponents;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/theme-classic",
3
- "version": "0.0.0-4764",
3
+ "version": "0.0.0-4768",
4
4
  "description": "Classic theme for Docusaurus",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/theme-classic.d.ts",
@@ -21,15 +21,15 @@
21
21
  "format:lib-next": "prettier --config ../../.prettierrc --write \"lib-next/**/*.{js,ts,jsx,tsc}\""
22
22
  },
23
23
  "dependencies": {
24
- "@docusaurus/core": "0.0.0-4764",
25
- "@docusaurus/plugin-content-blog": "0.0.0-4764",
26
- "@docusaurus/plugin-content-docs": "0.0.0-4764",
27
- "@docusaurus/plugin-content-pages": "0.0.0-4764",
28
- "@docusaurus/theme-common": "0.0.0-4764",
29
- "@docusaurus/theme-translations": "0.0.0-4764",
30
- "@docusaurus/utils": "0.0.0-4764",
31
- "@docusaurus/utils-common": "0.0.0-4764",
32
- "@docusaurus/utils-validation": "0.0.0-4764",
24
+ "@docusaurus/core": "0.0.0-4768",
25
+ "@docusaurus/plugin-content-blog": "0.0.0-4768",
26
+ "@docusaurus/plugin-content-docs": "0.0.0-4768",
27
+ "@docusaurus/plugin-content-pages": "0.0.0-4768",
28
+ "@docusaurus/theme-common": "0.0.0-4768",
29
+ "@docusaurus/theme-translations": "0.0.0-4768",
30
+ "@docusaurus/utils": "0.0.0-4768",
31
+ "@docusaurus/utils-common": "0.0.0-4768",
32
+ "@docusaurus/utils-validation": "0.0.0-4768",
33
33
  "@mdx-js/react": "^1.6.22",
34
34
  "clsx": "^1.1.1",
35
35
  "copy-text-to-clipboard": "^3.0.1",
@@ -42,8 +42,8 @@
42
42
  "rtlcss": "^3.5.0"
43
43
  },
44
44
  "devDependencies": {
45
- "@docusaurus/module-type-aliases": "0.0.0-4764",
46
- "@docusaurus/types": "0.0.0-4764",
45
+ "@docusaurus/module-type-aliases": "0.0.0-4768",
46
+ "@docusaurus/types": "0.0.0-4768",
47
47
  "@types/mdx-js__react": "^1.5.5",
48
48
  "@types/prismjs": "^1.26.0",
49
49
  "@types/rtlcss": "^3.1.2",
@@ -59,5 +59,5 @@
59
59
  "engines": {
60
60
  "node": ">=14"
61
61
  },
62
- "gitHead": "b45d59dcc7270365eb6648e8061ef3698b18ad28"
62
+ "gitHead": "4a89ff667d4a8896c47c4f946796cf3f58d219dc"
63
63
  }
@@ -136,6 +136,68 @@ export default function getSwizzleConfig(): SwizzleConfig {
136
136
  description:
137
137
  'The MDX components to use for rendering MDX files. Meant to be ejected.',
138
138
  },
139
+ 'MDXComponents/A': {
140
+ actions: {
141
+ eject: 'safe',
142
+ wrap: 'safe',
143
+ },
144
+ description:
145
+ 'The component used to render <a> tags and Markdown links in MDX',
146
+ },
147
+ 'MDXComponents/Code': {
148
+ actions: {
149
+ eject: 'safe',
150
+ wrap: 'safe',
151
+ },
152
+ description:
153
+ 'The component used to render <code> tags and Markdown code blocks in MDX',
154
+ },
155
+ 'MDXComponents/Details': {
156
+ actions: {
157
+ eject: 'safe',
158
+ wrap: 'safe',
159
+ },
160
+ description: 'The component used to render <details> tags in MDX',
161
+ },
162
+ 'MDXComponents/Head': {
163
+ actions: {
164
+ eject: 'forbidden',
165
+ wrap: 'forbidden',
166
+ },
167
+ description:
168
+ 'Technical component used to assign metadata (generally for SEO purpose) to the current MDX document',
169
+ },
170
+ 'MDXComponents/Heading': {
171
+ actions: {
172
+ eject: 'safe',
173
+ wrap: 'safe',
174
+ },
175
+ description:
176
+ 'The component used to render heading tags (<h1>, <h2>...) and Markdown headings in MDX',
177
+ },
178
+ 'MDXComponents/Img': {
179
+ actions: {
180
+ eject: 'safe',
181
+ wrap: 'safe',
182
+ },
183
+ description:
184
+ 'The component used to render <img> tags and Markdown images in MDX',
185
+ },
186
+ 'MDXComponents/Pre': {
187
+ actions: {
188
+ eject: 'safe',
189
+ wrap: 'safe',
190
+ },
191
+ description: 'The component used to render <pre> tags in MDX',
192
+ },
193
+ 'MDXComponents/Ul': {
194
+ actions: {
195
+ eject: 'safe',
196
+ wrap: 'safe',
197
+ },
198
+ description:
199
+ 'The component used to render <ul> tags and Markdown unordered lists in MDX',
200
+ },
139
201
  MDXContent: {
140
202
  actions: {
141
203
  eject: 'safe',
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import React from 'react';
9
+ import Link from '@docusaurus/Link';
10
+ import type {Props} from '@theme/MDXComponents/A';
11
+
12
+ export default function MDXA(props: Props): JSX.Element {
13
+ return <Link {...props} />;
14
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import type {ComponentProps} from 'react';
9
+ import React, {isValidElement} from 'react';
10
+ import CodeBlock from '@theme/CodeBlock';
11
+ import type {Props} from '@theme/MDXComponents/Code';
12
+
13
+ export default function MDXCode(props: Props): JSX.Element {
14
+ const inlineElements = [
15
+ 'a',
16
+ 'b',
17
+ 'big',
18
+ 'i',
19
+ 'span',
20
+ 'em',
21
+ 'strong',
22
+ 'sup',
23
+ 'sub',
24
+ 'small',
25
+ ];
26
+ const shouldBeInline = React.Children.toArray(props.children).every(
27
+ (el) =>
28
+ (typeof el === 'string' && !el.includes('\n')) ||
29
+ (isValidElement(el) && inlineElements.includes(el.props.mdxType)),
30
+ );
31
+
32
+ return shouldBeInline ? (
33
+ <code {...props} />
34
+ ) : (
35
+ <CodeBlock {...(props as ComponentProps<typeof CodeBlock>)} />
36
+ );
37
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import React, {type ComponentProps, type ReactElement} from 'react';
9
+ import Details from '@theme/Details';
10
+ import type {Props} from '@theme/MDXComponents/Details';
11
+
12
+ export default function MDXDetails(props: Props): JSX.Element {
13
+ const items = React.Children.toArray(props.children) as ReactElement[];
14
+ // Split summary item from the rest to pass it as a separate prop to the
15
+ // Details theme component
16
+ const summary: ReactElement<ComponentProps<'summary'>> = items.find(
17
+ (item) => item?.props?.mdxType === 'summary',
18
+ )!;
19
+ const children = <>{items.filter((item) => item !== summary)}</>;
20
+
21
+ return (
22
+ <Details {...props} summary={summary}>
23
+ {children}
24
+ </Details>
25
+ );
26
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import React, {type ReactElement, type ComponentProps} from 'react';
9
+ import Head from '@docusaurus/Head';
10
+ import type {Props} from '@theme/MDXComponents/Head';
11
+
12
+ // MDX elements are wrapped through the MDX pragma. In some cases (notably usage
13
+ // with Head/Helmet) we need to unwrap those elements.
14
+ function unwrapMDXElement(element: ReactElement) {
15
+ if (element?.props?.mdxType && element?.props?.originalType) {
16
+ const {mdxType, originalType, ...newProps} = element.props;
17
+ return React.createElement(element.props.originalType, newProps);
18
+ }
19
+ return element;
20
+ }
21
+
22
+ export default function MDXHead(props: Props): JSX.Element {
23
+ const unwrappedChildren = React.Children.map(props.children, (child) =>
24
+ unwrapMDXElement(child as ReactElement),
25
+ );
26
+ return (
27
+ <Head {...(props as ComponentProps<typeof Head>)}>{unwrappedChildren}</Head>
28
+ );
29
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import React from 'react';
9
+ import Heading from '@theme/Heading';
10
+ import type {Props} from '@theme/MDXComponents/Heading';
11
+
12
+ export default function MDXHeading(props: Props): JSX.Element {
13
+ return <Heading {...props} />;
14
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ .img {
9
+ height: auto;
10
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import React from 'react';
9
+ import type {Props} from '@theme/MDXComponents/Img';
10
+ import styles from './Img.module.css';
11
+ import clsx from 'clsx';
12
+
13
+ function transformImgClassName(className?: string): string {
14
+ return clsx(className, styles.img);
15
+ }
16
+
17
+ export default function MDXImg(props: Props): JSX.Element {
18
+ // eslint-disable-next-line jsx-a11y/alt-text
19
+ return <img {...props} className={transformImgClassName(props.className)} />;
20
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import React, {isValidElement} from 'react';
9
+ import CodeBlock from '@theme/CodeBlock';
10
+
11
+ export default function MDXPre(props: any) {
12
+ return (
13
+ <CodeBlock
14
+ // If this pre is created by a ``` fenced codeblock, unwrap the children
15
+ {...(isValidElement(props.children) &&
16
+ props.children.props.originalType === 'code'
17
+ ? props.children?.props
18
+ : {...props})}
19
+ />
20
+ );
21
+ }
@@ -5,11 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- ul.contains-task-list {
8
+ .contains-task-list {
9
9
  padding-left: 0;
10
10
  list-style: none;
11
11
  }
12
-
13
- img {
14
- height: auto;
15
- }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import React from 'react';
9
+ import clsx from 'clsx';
10
+ import type {Props} from '@theme/MDXComponents/Ul';
11
+
12
+ import styles from './Ul.module.css';
13
+
14
+ const containsClassListLocalClass = styles['contains-task-list'];
15
+
16
+ function transformUlClassName(className?: string): string {
17
+ return clsx(
18
+ className,
19
+ // This class is set globally by GitHub/MDX
20
+ // We keep the global class, but apply scoped CSS
21
+ // See https://github.com/syntax-tree/mdast-util-to-hast/issues/28
22
+ className?.includes('contains-task-list') && containsClassListLocalClass,
23
+ );
24
+ }
25
+
26
+ export default function MDXUl(props: Props): JSX.Element {
27
+ return <ul {...props} className={transformUlClassName(props.className)} />;
28
+ }
@@ -5,89 +5,32 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import React, {
9
- isValidElement,
10
- type ComponentProps,
11
- type ReactElement,
12
- } from 'react';
13
- import Head from '@docusaurus/Head';
14
- import Link from '@docusaurus/Link';
15
- import CodeBlock from '@theme/CodeBlock';
16
- import Heading from '@theme/Heading';
17
- import Details from '@theme/Details';
18
- import type {MDXComponentsObject} from '@theme/MDXComponents';
19
-
20
- import './styles.css';
8
+ import React from 'react';
9
+ import MDXHead from '@theme/MDXComponents/Head';
10
+ import MDXCode from '@theme/MDXComponents/Code';
11
+ import MDXA from '@theme/MDXComponents/A';
12
+ import MDXPre from '@theme/MDXComponents/Pre';
13
+ import MDXDetails from '@theme/MDXComponents/Details';
14
+ import MDXHeading from '@theme/MDXComponents/Heading';
15
+ import MDXUl from '@theme/MDXComponents/Ul';
16
+ import MDXImg from '@theme/MDXComponents/Img';
21
17
 
22
- // MDX elements are wrapped through the MDX pragma. In some cases (notably usage
23
- // with Head/Helmet) we need to unwrap those elements.
24
- function unwrapMDXElement(element: ReactElement) {
25
- if (element?.props?.mdxType && element?.props?.originalType) {
26
- const {mdxType, originalType, ...newProps} = element.props;
27
- return React.createElement(element.props.originalType, newProps);
28
- }
29
- return element;
30
- }
18
+ import type {MDXComponentsObject} from '@theme/MDXComponents';
31
19
 
32
20
  const MDXComponents: MDXComponentsObject = {
33
- head: (props) => {
34
- const unwrappedChildren = React.Children.map(props.children, (child) =>
35
- unwrapMDXElement(child as ReactElement),
36
- );
37
- return <Head {...props}>{unwrappedChildren}</Head>;
38
- },
39
- code: (props) => {
40
- const inlineElements = [
41
- 'a',
42
- 'b',
43
- 'big',
44
- 'i',
45
- 'span',
46
- 'em',
47
- 'strong',
48
- 'sup',
49
- 'sub',
50
- 'small',
51
- ];
52
- const shouldBeInline = React.Children.toArray(props.children).every(
53
- (el) =>
54
- (typeof el === 'string' && !el.includes('\n')) ||
55
- (isValidElement(el) && inlineElements.includes(el.props.mdxType)),
56
- );
57
-
58
- return shouldBeInline ? <code {...props} /> : <CodeBlock {...props} />;
59
- },
60
- a: (props) => <Link {...props} />,
61
- pre: (props) => (
62
- <CodeBlock
63
- // If this pre is created by a ``` fenced codeblock, unwrap the children
64
- {...(isValidElement(props.children) &&
65
- props.children.props.originalType === 'code'
66
- ? props.children?.props
67
- : {...props})}
68
- />
69
- ),
70
- details: (props): JSX.Element => {
71
- const items = React.Children.toArray(props.children) as ReactElement[];
72
- // Split summary item from the rest to pass it as a separate prop to the
73
- // Details theme component
74
- const summary: ReactElement<ComponentProps<'summary'>> = items.find(
75
- (item) => item?.props?.mdxType === 'summary',
76
- )!;
77
- const children = <>{items.filter((item) => item !== summary)}</>;
78
-
79
- return (
80
- <Details {...props} summary={summary}>
81
- {children}
82
- </Details>
83
- );
84
- },
85
- h1: (props) => <Heading as="h1" {...props} />,
86
- h2: (props) => <Heading as="h2" {...props} />,
87
- h3: (props) => <Heading as="h3" {...props} />,
88
- h4: (props) => <Heading as="h4" {...props} />,
89
- h5: (props) => <Heading as="h5" {...props} />,
90
- h6: (props) => <Heading as="h6" {...props} />,
21
+ head: MDXHead,
22
+ code: MDXCode,
23
+ a: MDXA,
24
+ pre: MDXPre,
25
+ details: MDXDetails,
26
+ ul: MDXUl,
27
+ img: MDXImg,
28
+ h1: (props) => <MDXHeading as="h1" {...props} />,
29
+ h2: (props) => <MDXHeading as="h2" {...props} />,
30
+ h3: (props) => <MDXHeading as="h3" {...props} />,
31
+ h4: (props) => <MDXHeading as="h4" {...props} />,
32
+ h5: (props) => <MDXHeading as="h5" {...props} />,
33
+ h6: (props) => <MDXHeading as="h6" {...props} />,
91
34
  };
92
35
 
93
36
  export default MDXComponents;
@@ -417,24 +417,97 @@ declare module '@theme/SkipToContent' {
417
417
  export default function SkipToContent(): JSX.Element;
418
418
  }
419
419
 
420
- declare module '@theme/MDXComponents' {
420
+ declare module '@theme/MDXComponents/A' {
421
+ import type {ComponentProps} from 'react';
422
+
423
+ export interface Props extends ComponentProps<'a'> {}
424
+
425
+ export default function MDXA(props: Props): JSX.Element;
426
+ }
427
+
428
+ declare module '@theme/MDXComponents/Code' {
429
+ import type {ComponentProps} from 'react';
430
+
431
+ export interface Props extends ComponentProps<'code'> {}
432
+
433
+ export default function MDXCode(props: Props): JSX.Element;
434
+ }
435
+
436
+ declare module '@theme/MDXComponents/Details' {
421
437
  import type {ComponentProps} from 'react';
422
- import type CodeBlock from '@theme/CodeBlock';
423
- import type Head from '@docusaurus/Head';
438
+
439
+ export interface Props extends ComponentProps<'details'> {}
440
+
441
+ export default function MDXDetails(props: Props): JSX.Element;
442
+ }
443
+
444
+ declare module '@theme/MDXComponents/Ul' {
445
+ import type {ComponentProps} from 'react';
446
+
447
+ export interface Props extends ComponentProps<'ul'> {}
448
+
449
+ export default function MDXUl(props: Props): JSX.Element;
450
+ }
451
+
452
+ declare module '@theme/MDXComponents/Img' {
453
+ import type {ComponentProps} from 'react';
454
+
455
+ export interface Props extends ComponentProps<'img'> {}
456
+
457
+ export default function MDXImg(props: Props): JSX.Element;
458
+ }
459
+
460
+ declare module '@theme/MDXComponents/Head' {
461
+ import type {ComponentProps} from 'react';
462
+
463
+ export interface Props extends ComponentProps<'head'> {}
464
+
465
+ export default function MDXHead(props: Props): JSX.Element;
466
+ }
467
+
468
+ declare module '@theme/MDXComponents/Heading' {
469
+ import type {ComponentProps} from 'react';
470
+ import type Heading from '@theme/Heading';
471
+
472
+ export interface Props extends ComponentProps<typeof Heading> {}
473
+
474
+ export default function MDXHeading(props: Props): JSX.Element;
475
+ }
476
+
477
+ declare module '@theme/MDXComponents/Pre' {
478
+ import type {ComponentProps} from 'react';
479
+
480
+ export interface Props extends ComponentProps<'pre'> {}
481
+
482
+ export default function MDXPre(props: Props): JSX.Element;
483
+ }
484
+
485
+ declare module '@theme/MDXComponents' {
486
+ import type {ComponentType, ComponentProps} from 'react';
487
+
488
+ import type MDXHead from '@theme/MDXComponents/Head';
489
+ import type MDXCode from '@theme/MDXComponents/Code';
490
+ import type MDXA from '@theme/MDXComponents/A';
491
+ import type MDXPre from '@theme/MDXComponents/Pre';
492
+ import type MDXDetails from '@theme/MDXComponents/Details';
493
+ import type MDXUl from '@theme/MDXComponents/Ul';
494
+ import type MDXImg from '@theme/MDXComponents/Img';
424
495
 
425
496
  export type MDXComponentsObject = {
426
- readonly head: typeof Head;
427
- readonly code: typeof CodeBlock;
428
- readonly a: (props: ComponentProps<'a'>) => JSX.Element;
429
- readonly pre: typeof CodeBlock;
430
- readonly details: (props: ComponentProps<'details'>) => JSX.Element;
497
+ readonly head: typeof MDXHead;
498
+ readonly code: typeof MDXCode;
499
+ readonly a: typeof MDXA;
500
+ readonly pre: typeof MDXPre;
501
+ readonly details: typeof MDXDetails;
502
+ readonly ul: typeof MDXUl;
503
+ readonly img: typeof MDXImg;
431
504
  readonly h1: (props: ComponentProps<'h1'>) => JSX.Element;
432
505
  readonly h2: (props: ComponentProps<'h2'>) => JSX.Element;
433
506
  readonly h3: (props: ComponentProps<'h3'>) => JSX.Element;
434
507
  readonly h4: (props: ComponentProps<'h4'>) => JSX.Element;
435
508
  readonly h5: (props: ComponentProps<'h5'>) => JSX.Element;
436
509
  readonly h6: (props: ComponentProps<'h6'>) => JSX.Element;
437
- };
510
+ } & Record<string, ComponentType<unknown>>;
438
511
 
439
512
  const MDXComponents: MDXComponentsObject;
440
513
  export default MDXComponents;