@docusaurus/theme-classic 3.7.0 → 3.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/getSwizzleConfig.js +1 -1
- package/lib/index.js +9 -0
- package/lib/inlineScripts.js +6 -27
- package/lib/inlineSvgSprites.d.ts +7 -0
- package/lib/inlineSvgSprites.js +14 -0
- package/lib/options.js +5 -0
- package/lib/theme/AnnouncementBar/index.js +6 -2
- package/lib/theme/CodeBlock/{WordWrapButton → Buttons/Button}/index.d.ts +2 -2
- package/lib/theme/CodeBlock/Buttons/Button/index.js +13 -0
- package/lib/theme/CodeBlock/Buttons/CopyButton/index.d.ts +9 -0
- package/lib/theme/CodeBlock/{CopyButton → Buttons/CopyButton}/index.js +36 -25
- package/lib/theme/CodeBlock/Buttons/WordWrapButton/index.d.ts +9 -0
- package/lib/theme/CodeBlock/{WordWrapButton → Buttons/WordWrapButton}/index.js +12 -7
- package/lib/theme/CodeBlock/{CopyButton → Buttons}/index.d.ts +2 -2
- package/lib/theme/CodeBlock/Buttons/index.js +27 -0
- package/lib/theme/CodeBlock/Buttons/styles.module.css +37 -0
- package/lib/theme/CodeBlock/Content/Element.js +4 -2
- package/lib/theme/CodeBlock/Content/String.d.ts +1 -1
- package/lib/theme/CodeBlock/Content/String.js +22 -92
- package/lib/theme/CodeBlock/Content/index.d.ts +9 -0
- package/lib/theme/CodeBlock/Content/index.js +74 -0
- package/lib/theme/CodeBlock/Content/styles.module.css +0 -52
- package/lib/theme/CodeBlock/Layout/index.d.ts +9 -0
- package/lib/theme/CodeBlock/Layout/index.js +30 -0
- package/lib/theme/CodeBlock/Layout/styles.module.css +27 -0
- package/lib/theme/CodeBlock/Line/Token/index.d.ts +9 -0
- package/lib/theme/CodeBlock/Line/Token/index.js +11 -0
- package/lib/theme/CodeBlock/Line/index.d.ts +1 -1
- package/lib/theme/CodeBlock/Line/index.js +21 -7
- package/lib/theme/CodeBlock/Title/index.d.ts +9 -0
- package/lib/theme/CodeBlock/Title/index.js +10 -0
- package/lib/theme/ColorModeToggle/index.d.ts +1 -1
- package/lib/theme/ColorModeToggle/index.js +85 -27
- package/lib/theme/ColorModeToggle/styles.module.css +7 -2
- package/lib/theme/DocBreadcrumbs/StructuredData/index.d.ts +9 -0
- package/lib/theme/DocBreadcrumbs/StructuredData/index.js +21 -0
- package/lib/theme/DocBreadcrumbs/index.js +36 -54
- package/lib/theme/DocCard/index.js +6 -4
- package/lib/theme/DocCardList/index.js +12 -6
- package/lib/theme/DocCardList/styles.module.css +14 -0
- package/lib/theme/DocCategoryGeneratedIndexPage/index.js +1 -1
- package/lib/theme/DocCategoryGeneratedIndexPage/styles.module.css +0 -8
- package/lib/theme/DocItem/Paginator/index.js +7 -1
- package/lib/theme/DocPaginator/index.js +3 -2
- package/lib/theme/DocSidebarItem/Category/index.js +8 -1
- package/lib/theme/Footer/Layout/index.js +2 -1
- package/lib/theme/Footer/Links/MultiColumn/index.js +7 -1
- package/lib/theme/Icon/ExternalLink/index.js +4 -5
- package/lib/theme/Icon/SystemColorMode/index.d.ts +9 -0
- package/lib/theme/Icon/SystemColorMode/index.js +16 -0
- package/lib/theme/Layout/index.js +1 -0
- package/lib/theme/Navbar/ColorModeToggle/index.js +5 -4
- package/lib/theme/Navbar/Content/index.js +20 -3
- package/lib/theme/Navbar/Content/styles.module.css +8 -0
- package/lib/theme/Navbar/Layout/index.js +2 -1
- package/lib/theme/Navbar/MobileSidebar/Layout/index.js +35 -4
- package/lib/theme/NavbarItem/DefaultNavbarItem/Desktop/index.d.ts +9 -0
- package/lib/theme/NavbarItem/DefaultNavbarItem/Desktop/index.js +29 -0
- package/lib/theme/NavbarItem/DefaultNavbarItem/Mobile/index.d.ts +9 -0
- package/lib/theme/NavbarItem/DefaultNavbarItem/Mobile/index.js +20 -0
- package/lib/theme/NavbarItem/DefaultNavbarItem/index.js +25 -0
- package/lib/theme/NavbarItem/DocsVersionDropdownNavbarItem.d.ts +1 -1
- package/lib/theme/NavbarItem/DocsVersionDropdownNavbarItem.js +50 -7
- package/lib/theme/NavbarItem/DropdownNavbarItem/Desktop/index.d.ts +9 -0
- package/lib/theme/NavbarItem/DropdownNavbarItem/Desktop/index.js +74 -0
- package/lib/theme/NavbarItem/DropdownNavbarItem/Mobile/index.d.ts +10 -0
- package/lib/theme/NavbarItem/DropdownNavbarItem/Mobile/index.js +142 -0
- package/lib/theme/NavbarItem/DropdownNavbarItem/index.js +3 -142
- package/lib/theme/Tag/index.js +1 -0
- package/lib/theme/ThemeProvider/TitleFormatter/index.d.ts +9 -0
- package/lib/theme/ThemeProvider/TitleFormatter/index.js +19 -0
- package/lib/theme/ThemeProvider/index.d.ts +9 -0
- package/lib/theme/ThemeProvider/index.js +11 -0
- package/package.json +15 -15
- package/src/getSwizzleConfig.ts +1 -1
- package/src/index.ts +9 -0
- package/src/inlineScripts.ts +6 -27
- package/src/inlineSvgSprites.ts +12 -0
- package/src/options.ts +15 -0
- package/src/theme/AnnouncementBar/index.tsx +6 -2
- package/src/theme/CodeBlock/Buttons/Button/index.tsx +19 -0
- package/src/theme/CodeBlock/{CopyButton → Buttons/CopyButton}/index.tsx +42 -26
- package/src/theme/CodeBlock/{WordWrapButton → Buttons/WordWrapButton}/index.tsx +15 -12
- package/src/theme/CodeBlock/Buttons/index.tsx +32 -0
- package/src/theme/CodeBlock/Buttons/styles.module.css +37 -0
- package/src/theme/CodeBlock/Content/Element.tsx +4 -2
- package/src/theme/CodeBlock/Content/String.tsx +24 -101
- package/src/theme/CodeBlock/Content/index.tsx +84 -0
- package/src/theme/CodeBlock/Content/styles.module.css +0 -52
- package/src/theme/CodeBlock/Layout/index.tsx +34 -0
- package/src/theme/CodeBlock/Layout/styles.module.css +27 -0
- package/src/theme/CodeBlock/Line/Token/index.tsx +18 -0
- package/src/theme/CodeBlock/Line/index.tsx +26 -7
- package/src/theme/CodeBlock/Title/index.tsx +15 -0
- package/src/theme/ColorModeToggle/index.tsx +102 -32
- package/src/theme/ColorModeToggle/styles.module.css +7 -2
- package/src/theme/DocBreadcrumbs/StructuredData/index.tsx +24 -0
- package/src/theme/DocBreadcrumbs/index.tsx +35 -57
- package/src/theme/DocCard/index.tsx +8 -2
- package/src/theme/DocCardList/index.tsx +18 -7
- package/src/theme/DocCardList/styles.module.css +14 -0
- package/src/theme/DocCategoryGeneratedIndexPage/index.tsx +1 -1
- package/src/theme/DocCategoryGeneratedIndexPage/styles.module.css +0 -8
- package/src/theme/DocItem/Paginator/index.tsx +7 -1
- package/src/theme/DocPaginator/index.tsx +3 -2
- package/src/theme/DocSidebarItem/Category/index.tsx +8 -1
- package/src/theme/Footer/Layout/index.tsx +2 -1
- package/src/theme/Footer/Links/MultiColumn/index.tsx +7 -1
- package/src/theme/Icon/ExternalLink/index.tsx +5 -5
- package/src/theme/Icon/SystemColorMode/index.tsx +20 -0
- package/src/theme/Layout/index.tsx +1 -0
- package/src/theme/Navbar/ColorModeToggle/index.tsx +5 -4
- package/src/theme/Navbar/Content/index.tsx +20 -3
- package/src/theme/Navbar/Content/styles.module.css +8 -0
- package/src/theme/Navbar/Layout/index.tsx +2 -1
- package/src/theme/Navbar/MobileSidebar/Layout/index.tsx +43 -4
- package/src/theme/NavbarItem/DefaultNavbarItem/Desktop/index.tsx +34 -0
- package/src/theme/NavbarItem/DefaultNavbarItem/Mobile/index.tsx +23 -0
- package/src/theme/NavbarItem/DefaultNavbarItem/index.tsx +28 -0
- package/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx +87 -9
- package/src/theme/NavbarItem/DropdownNavbarItem/Desktop/index.tsx +86 -0
- package/src/theme/NavbarItem/DropdownNavbarItem/Mobile/index.tsx +166 -0
- package/src/theme/NavbarItem/DropdownNavbarItem/index.tsx +4 -168
- package/src/theme/Tag/index.tsx +1 -0
- package/src/theme/ThemeProvider/TitleFormatter/index.tsx +27 -0
- package/src/theme/ThemeProvider/index.tsx +14 -0
- package/src/theme-classic.d.ts +175 -20
- package/lib/theme/NavbarItem/DefaultNavbarItem.js +0 -52
- package/src/theme/NavbarItem/DefaultNavbarItem.tsx +0 -66
- /package/lib/theme/CodeBlock/{CopyButton → Buttons/CopyButton}/styles.module.css +0 -0
- /package/lib/theme/CodeBlock/{WordWrapButton → Buttons/WordWrapButton}/styles.module.css +0 -0
- /package/lib/theme/NavbarItem/{DefaultNavbarItem.d.ts → DefaultNavbarItem/index.d.ts} +0 -0
- /package/lib/theme/NavbarItem/DropdownNavbarItem/{styles.module.css → Mobile/styles.module.css} +0 -0
- /package/src/theme/CodeBlock/{CopyButton → Buttons/CopyButton}/styles.module.css +0 -0
- /package/src/theme/CodeBlock/{WordWrapButton → Buttons/WordWrapButton}/styles.module.css +0 -0
- /package/src/theme/NavbarItem/DropdownNavbarItem/{styles.module.css → Mobile/styles.module.css} +0 -0
|
@@ -8,16 +8,21 @@
|
|
|
8
8
|
import React, {type ReactNode} from 'react';
|
|
9
9
|
import clsx from 'clsx';
|
|
10
10
|
import {translate} from '@docusaurus/Translate';
|
|
11
|
-
import
|
|
11
|
+
import {useCodeBlockContext} from '@docusaurus/theme-common/internal';
|
|
12
|
+
import Button from '@theme/CodeBlock/Buttons/Button';
|
|
13
|
+
import type {Props} from '@theme/CodeBlock/Buttons/WordWrapButton';
|
|
12
14
|
import IconWordWrap from '@theme/Icon/WordWrap';
|
|
13
15
|
|
|
14
16
|
import styles from './styles.module.css';
|
|
15
17
|
|
|
16
|
-
export default function WordWrapButton({
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
isEnabled
|
|
20
|
-
|
|
18
|
+
export default function WordWrapButton({className}: Props): ReactNode {
|
|
19
|
+
const {wordWrap} = useCodeBlockContext();
|
|
20
|
+
|
|
21
|
+
const canShowButton = wordWrap.isEnabled || wordWrap.isCodeScrollable;
|
|
22
|
+
if (!canShowButton) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
|
|
21
26
|
const title = translate({
|
|
22
27
|
id: 'theme.CodeBlock.wordWrapToggle',
|
|
23
28
|
message: 'Toggle word wrap',
|
|
@@ -26,17 +31,15 @@ export default function WordWrapButton({
|
|
|
26
31
|
});
|
|
27
32
|
|
|
28
33
|
return (
|
|
29
|
-
<
|
|
30
|
-
|
|
31
|
-
onClick={onClick}
|
|
34
|
+
<Button
|
|
35
|
+
onClick={() => wordWrap.toggle()}
|
|
32
36
|
className={clsx(
|
|
33
|
-
'clean-btn',
|
|
34
37
|
className,
|
|
35
|
-
isEnabled && styles.wordWrapButtonEnabled,
|
|
38
|
+
wordWrap.isEnabled && styles.wordWrapButtonEnabled,
|
|
36
39
|
)}
|
|
37
40
|
aria-label={title}
|
|
38
41
|
title={title}>
|
|
39
42
|
<IconWordWrap className={styles.wordWrapButtonIcon} aria-hidden="true" />
|
|
40
|
-
</
|
|
43
|
+
</Button>
|
|
41
44
|
);
|
|
42
45
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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 ReactNode} from 'react';
|
|
9
|
+
import clsx from 'clsx';
|
|
10
|
+
import BrowserOnly from '@docusaurus/BrowserOnly';
|
|
11
|
+
|
|
12
|
+
import CopyButton from '@theme/CodeBlock/Buttons/CopyButton';
|
|
13
|
+
import WordWrapButton from '@theme/CodeBlock/Buttons/WordWrapButton';
|
|
14
|
+
import type {Props} from '@theme/CodeBlock/Buttons';
|
|
15
|
+
|
|
16
|
+
import styles from './styles.module.css';
|
|
17
|
+
|
|
18
|
+
// Code block buttons are not server-rendered on purpose
|
|
19
|
+
// Adding them to the initial HTML is useless and expensive (due to JSX SVG)
|
|
20
|
+
// They are hidden by default and require React to become interactive
|
|
21
|
+
export default function CodeBlockButtons({className}: Props): ReactNode {
|
|
22
|
+
return (
|
|
23
|
+
<BrowserOnly>
|
|
24
|
+
{() => (
|
|
25
|
+
<div className={clsx(className, styles.buttonGroup)}>
|
|
26
|
+
<WordWrapButton />
|
|
27
|
+
<CopyButton />
|
|
28
|
+
</div>
|
|
29
|
+
)}
|
|
30
|
+
</BrowserOnly>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
@@ -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
|
+
.buttonGroup {
|
|
9
|
+
display: flex;
|
|
10
|
+
column-gap: 0.2rem;
|
|
11
|
+
position: absolute;
|
|
12
|
+
/* rtl:ignore */
|
|
13
|
+
right: calc(var(--ifm-pre-padding) / 2);
|
|
14
|
+
top: calc(var(--ifm-pre-padding) / 2);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.buttonGroup button {
|
|
18
|
+
display: flex;
|
|
19
|
+
align-items: center;
|
|
20
|
+
background: var(--prism-background-color);
|
|
21
|
+
color: var(--prism-color);
|
|
22
|
+
border: 1px solid var(--ifm-color-emphasis-300);
|
|
23
|
+
border-radius: var(--ifm-global-radius);
|
|
24
|
+
padding: 0.4rem;
|
|
25
|
+
line-height: 0;
|
|
26
|
+
transition: opacity var(--ifm-transition-fast) ease-in-out;
|
|
27
|
+
opacity: 0;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.buttonGroup button:focus-visible,
|
|
31
|
+
.buttonGroup button:hover {
|
|
32
|
+
opacity: 1 !important;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
:global(.theme-code-block:hover) .buttonGroup button {
|
|
36
|
+
opacity: 0.4;
|
|
37
|
+
}
|
|
@@ -12,8 +12,10 @@ import type {Props} from '@theme/CodeBlock/Content/Element';
|
|
|
12
12
|
|
|
13
13
|
import styles from './styles.module.css';
|
|
14
14
|
|
|
15
|
-
//
|
|
16
|
-
//
|
|
15
|
+
// TODO Docusaurus v4: move this component at the root?
|
|
16
|
+
// This component only handles a rare edge-case: <pre><MyComp/></pre> in MDX
|
|
17
|
+
// <pre> tags in markdown map to CodeBlocks. They may contain JSX children.
|
|
18
|
+
// When children is not a simple string, we just return a styled block without
|
|
17
19
|
// actually highlighting.
|
|
18
20
|
export default function CodeBlockJSX({children, className}: Props): ReactNode {
|
|
19
21
|
return (
|
|
@@ -6,114 +6,37 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import React, {type ReactNode} from 'react';
|
|
9
|
-
import
|
|
10
|
-
import {useThemeConfig, usePrismTheme} from '@docusaurus/theme-common';
|
|
9
|
+
import {useThemeConfig} from '@docusaurus/theme-common';
|
|
11
10
|
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
containsLineNumbers,
|
|
11
|
+
CodeBlockContextProvider,
|
|
12
|
+
type CodeBlockMetadata,
|
|
13
|
+
createCodeBlockMetadata,
|
|
16
14
|
useCodeWordWrap,
|
|
17
15
|
} from '@docusaurus/theme-common/internal';
|
|
18
|
-
import {Highlight, type Language} from 'prism-react-renderer';
|
|
19
|
-
import Line from '@theme/CodeBlock/Line';
|
|
20
|
-
import CopyButton from '@theme/CodeBlock/CopyButton';
|
|
21
|
-
import WordWrapButton from '@theme/CodeBlock/WordWrapButton';
|
|
22
|
-
import Container from '@theme/CodeBlock/Container';
|
|
23
16
|
import type {Props} from '@theme/CodeBlock/Content/String';
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
17
|
+
import CodeBlockLayout from '@theme/CodeBlock/Layout';
|
|
18
|
+
|
|
19
|
+
function useCodeBlockMetadata(props: Props): CodeBlockMetadata {
|
|
20
|
+
const {prism} = useThemeConfig();
|
|
21
|
+
return createCodeBlockMetadata({
|
|
22
|
+
code: props.children,
|
|
23
|
+
className: props.className,
|
|
24
|
+
metastring: props.metastring,
|
|
25
|
+
magicComments: prism.magicComments,
|
|
26
|
+
defaultLanguage: prism.defaultLanguage,
|
|
27
|
+
language: props.language,
|
|
28
|
+
title: props.title,
|
|
29
|
+
showLineNumbers: props.showLineNumbers,
|
|
30
|
+
});
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
metastring,
|
|
38
|
-
title: titleProp,
|
|
39
|
-
showLineNumbers: showLineNumbersProp,
|
|
40
|
-
language: languageProp,
|
|
41
|
-
}: Props): ReactNode {
|
|
42
|
-
const {
|
|
43
|
-
prism: {defaultLanguage, magicComments},
|
|
44
|
-
} = useThemeConfig();
|
|
45
|
-
const language = normalizeLanguage(
|
|
46
|
-
languageProp ?? parseLanguage(blockClassName) ?? defaultLanguage,
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
const prismTheme = usePrismTheme();
|
|
33
|
+
// TODO Docusaurus v4: move this component at the root?
|
|
34
|
+
export default function CodeBlockString(props: Props): ReactNode {
|
|
35
|
+
const metadata = useCodeBlockMetadata(props);
|
|
50
36
|
const wordWrap = useCodeWordWrap();
|
|
51
|
-
|
|
52
|
-
// We still parse the metastring in case we want to support more syntax in the
|
|
53
|
-
// future. Note that MDX doesn't strip quotes when parsing metastring:
|
|
54
|
-
// "title=\"xyz\"" => title: "\"xyz\""
|
|
55
|
-
const title = parseCodeBlockTitle(metastring) || titleProp;
|
|
56
|
-
|
|
57
|
-
const {lineClassNames, code} = parseLines(children, {
|
|
58
|
-
metastring,
|
|
59
|
-
language,
|
|
60
|
-
magicComments,
|
|
61
|
-
});
|
|
62
|
-
const showLineNumbers =
|
|
63
|
-
showLineNumbersProp ?? containsLineNumbers(metastring);
|
|
64
|
-
|
|
65
37
|
return (
|
|
66
|
-
<
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
blockClassName,
|
|
70
|
-
language &&
|
|
71
|
-
!blockClassName.includes(`language-${language}`) &&
|
|
72
|
-
`language-${language}`,
|
|
73
|
-
)}>
|
|
74
|
-
{title && <div className={styles.codeBlockTitle}>{title}</div>}
|
|
75
|
-
<div className={styles.codeBlockContent}>
|
|
76
|
-
<Highlight
|
|
77
|
-
theme={prismTheme}
|
|
78
|
-
code={code}
|
|
79
|
-
language={(language ?? 'text') as Language}>
|
|
80
|
-
{({className, style, tokens, getLineProps, getTokenProps}) => (
|
|
81
|
-
<pre
|
|
82
|
-
/* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex */
|
|
83
|
-
tabIndex={0}
|
|
84
|
-
ref={wordWrap.codeBlockRef}
|
|
85
|
-
className={clsx(className, styles.codeBlock, 'thin-scrollbar')}
|
|
86
|
-
style={style}>
|
|
87
|
-
<code
|
|
88
|
-
className={clsx(
|
|
89
|
-
styles.codeBlockLines,
|
|
90
|
-
showLineNumbers && styles.codeBlockLinesWithNumbering,
|
|
91
|
-
)}>
|
|
92
|
-
{tokens.map((line, i) => (
|
|
93
|
-
<Line
|
|
94
|
-
key={i}
|
|
95
|
-
line={line}
|
|
96
|
-
getLineProps={getLineProps}
|
|
97
|
-
getTokenProps={getTokenProps}
|
|
98
|
-
classNames={lineClassNames[i]}
|
|
99
|
-
showLineNumbers={showLineNumbers}
|
|
100
|
-
/>
|
|
101
|
-
))}
|
|
102
|
-
</code>
|
|
103
|
-
</pre>
|
|
104
|
-
)}
|
|
105
|
-
</Highlight>
|
|
106
|
-
<div className={styles.buttonGroup}>
|
|
107
|
-
{(wordWrap.isEnabled || wordWrap.isCodeScrollable) && (
|
|
108
|
-
<WordWrapButton
|
|
109
|
-
className={styles.codeButton}
|
|
110
|
-
onClick={() => wordWrap.toggle()}
|
|
111
|
-
isEnabled={wordWrap.isEnabled}
|
|
112
|
-
/>
|
|
113
|
-
)}
|
|
114
|
-
<CopyButton className={styles.codeButton} code={code} />
|
|
115
|
-
</div>
|
|
116
|
-
</div>
|
|
117
|
-
</Container>
|
|
38
|
+
<CodeBlockContextProvider metadata={metadata} wordWrap={wordWrap}>
|
|
39
|
+
<CodeBlockLayout />
|
|
40
|
+
</CodeBlockContextProvider>
|
|
118
41
|
);
|
|
119
42
|
}
|
|
@@ -0,0 +1,84 @@
|
|
|
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 ReactNode} from 'react';
|
|
9
|
+
import clsx from 'clsx';
|
|
10
|
+
import {useCodeBlockContext} from '@docusaurus/theme-common/internal';
|
|
11
|
+
import {usePrismTheme} from '@docusaurus/theme-common';
|
|
12
|
+
import {Highlight} from 'prism-react-renderer';
|
|
13
|
+
import type {Props} from '@theme/CodeBlock/Content';
|
|
14
|
+
import Line from '@theme/CodeBlock/Line';
|
|
15
|
+
|
|
16
|
+
import styles from './styles.module.css';
|
|
17
|
+
|
|
18
|
+
// TODO Docusaurus v4: remove useless forwardRef
|
|
19
|
+
const Pre = React.forwardRef<HTMLPreElement, ComponentProps<'pre'>>(
|
|
20
|
+
(props, ref) => {
|
|
21
|
+
return (
|
|
22
|
+
<pre
|
|
23
|
+
ref={ref}
|
|
24
|
+
/* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex */
|
|
25
|
+
tabIndex={0}
|
|
26
|
+
{...props}
|
|
27
|
+
className={clsx(props.className, styles.codeBlock, 'thin-scrollbar')}
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
},
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
function Code(props: ComponentProps<'code'>) {
|
|
34
|
+
const {metadata} = useCodeBlockContext();
|
|
35
|
+
return (
|
|
36
|
+
<code
|
|
37
|
+
{...props}
|
|
38
|
+
className={clsx(
|
|
39
|
+
props.className,
|
|
40
|
+
styles.codeBlockLines,
|
|
41
|
+
metadata.lineNumbersStart !== undefined &&
|
|
42
|
+
styles.codeBlockLinesWithNumbering,
|
|
43
|
+
)}
|
|
44
|
+
style={{
|
|
45
|
+
...props.style,
|
|
46
|
+
counterReset:
|
|
47
|
+
metadata.lineNumbersStart === undefined
|
|
48
|
+
? undefined
|
|
49
|
+
: `line-count ${metadata.lineNumbersStart - 1}`,
|
|
50
|
+
}}
|
|
51
|
+
/>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export default function CodeBlockContent({
|
|
56
|
+
className: classNameProp,
|
|
57
|
+
}: Props): ReactNode {
|
|
58
|
+
const {metadata, wordWrap} = useCodeBlockContext();
|
|
59
|
+
const prismTheme = usePrismTheme();
|
|
60
|
+
const {code, language, lineNumbersStart, lineClassNames} = metadata;
|
|
61
|
+
return (
|
|
62
|
+
<Highlight theme={prismTheme} code={code} language={language}>
|
|
63
|
+
{({className, style, tokens: lines, getLineProps, getTokenProps}) => (
|
|
64
|
+
<Pre
|
|
65
|
+
ref={wordWrap.codeBlockRef}
|
|
66
|
+
className={clsx(classNameProp, className)}
|
|
67
|
+
style={style}>
|
|
68
|
+
<Code>
|
|
69
|
+
{lines.map((line, i) => (
|
|
70
|
+
<Line
|
|
71
|
+
key={i}
|
|
72
|
+
line={line}
|
|
73
|
+
getLineProps={getLineProps}
|
|
74
|
+
getTokenProps={getTokenProps}
|
|
75
|
+
classNames={lineClassNames[i]}
|
|
76
|
+
showLineNumbers={lineNumbersStart !== undefined}
|
|
77
|
+
/>
|
|
78
|
+
))}
|
|
79
|
+
</Code>
|
|
80
|
+
</Pre>
|
|
81
|
+
)}
|
|
82
|
+
</Highlight>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
@@ -5,33 +5,12 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
.codeBlockContent {
|
|
9
|
-
position: relative;
|
|
10
|
-
/* rtl:ignore */
|
|
11
|
-
direction: ltr;
|
|
12
|
-
border-radius: inherit;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
.codeBlockTitle {
|
|
16
|
-
border-bottom: 1px solid var(--ifm-color-emphasis-300);
|
|
17
|
-
font-size: var(--ifm-code-font-size);
|
|
18
|
-
font-weight: 500;
|
|
19
|
-
padding: 0.75rem var(--ifm-pre-padding);
|
|
20
|
-
border-top-left-radius: inherit;
|
|
21
|
-
border-top-right-radius: inherit;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
8
|
.codeBlock {
|
|
25
9
|
--ifm-pre-background: var(--prism-background-color);
|
|
26
10
|
margin: 0;
|
|
27
11
|
padding: 0;
|
|
28
12
|
}
|
|
29
13
|
|
|
30
|
-
.codeBlockTitle + .codeBlockContent .codeBlock {
|
|
31
|
-
border-top-left-radius: 0;
|
|
32
|
-
border-top-right-radius: 0;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
14
|
.codeBlockStandalone {
|
|
36
15
|
padding: 0;
|
|
37
16
|
}
|
|
@@ -54,34 +33,3 @@
|
|
|
54
33
|
white-space: pre-wrap;
|
|
55
34
|
}
|
|
56
35
|
}
|
|
57
|
-
|
|
58
|
-
.buttonGroup {
|
|
59
|
-
display: flex;
|
|
60
|
-
column-gap: 0.2rem;
|
|
61
|
-
position: absolute;
|
|
62
|
-
/* rtl:ignore */
|
|
63
|
-
right: calc(var(--ifm-pre-padding) / 2);
|
|
64
|
-
top: calc(var(--ifm-pre-padding) / 2);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
.buttonGroup button {
|
|
68
|
-
display: flex;
|
|
69
|
-
align-items: center;
|
|
70
|
-
background: var(--prism-background-color);
|
|
71
|
-
color: var(--prism-color);
|
|
72
|
-
border: 1px solid var(--ifm-color-emphasis-300);
|
|
73
|
-
border-radius: var(--ifm-global-radius);
|
|
74
|
-
padding: 0.4rem;
|
|
75
|
-
line-height: 0;
|
|
76
|
-
transition: opacity var(--ifm-transition-fast) ease-in-out;
|
|
77
|
-
opacity: 0;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
.buttonGroup button:focus-visible,
|
|
81
|
-
.buttonGroup button:hover {
|
|
82
|
-
opacity: 1 !important;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
:global(.theme-code-block:hover) .buttonGroup button {
|
|
86
|
-
opacity: 0.4;
|
|
87
|
-
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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 ReactNode} from 'react';
|
|
9
|
+
import clsx from 'clsx';
|
|
10
|
+
import {useCodeBlockContext} from '@docusaurus/theme-common/internal';
|
|
11
|
+
import Container from '@theme/CodeBlock/Container';
|
|
12
|
+
import Title from '@theme/CodeBlock/Title';
|
|
13
|
+
import Content from '@theme/CodeBlock/Content';
|
|
14
|
+
import type {Props} from '@theme/CodeBlock/Layout';
|
|
15
|
+
import Buttons from '@theme/CodeBlock/Buttons';
|
|
16
|
+
|
|
17
|
+
import styles from './styles.module.css';
|
|
18
|
+
|
|
19
|
+
export default function CodeBlockLayout({className}: Props): ReactNode {
|
|
20
|
+
const {metadata} = useCodeBlockContext();
|
|
21
|
+
return (
|
|
22
|
+
<Container as="div" className={clsx(className, metadata.className)}>
|
|
23
|
+
{metadata.title && (
|
|
24
|
+
<div className={styles.codeBlockTitle}>
|
|
25
|
+
<Title>{metadata.title}</Title>
|
|
26
|
+
</div>
|
|
27
|
+
)}
|
|
28
|
+
<div className={styles.codeBlockContent}>
|
|
29
|
+
<Content />
|
|
30
|
+
<Buttons />
|
|
31
|
+
</div>
|
|
32
|
+
</Container>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
.codeBlockContent {
|
|
9
|
+
position: relative;
|
|
10
|
+
/* rtl:ignore */
|
|
11
|
+
direction: ltr;
|
|
12
|
+
border-radius: inherit;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.codeBlockTitle {
|
|
16
|
+
border-bottom: 1px solid var(--ifm-color-emphasis-300);
|
|
17
|
+
font-size: var(--ifm-code-font-size);
|
|
18
|
+
font-weight: 500;
|
|
19
|
+
padding: 0.75rem var(--ifm-pre-padding);
|
|
20
|
+
border-top-left-radius: inherit;
|
|
21
|
+
border-top-right-radius: inherit;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.codeBlockTitle + .codeBlockContent .codeBlock {
|
|
25
|
+
border-top-left-radius: 0;
|
|
26
|
+
border-top-right-radius: 0;
|
|
27
|
+
}
|
|
@@ -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
|
+
|
|
8
|
+
import React, {type ReactNode} from 'react';
|
|
9
|
+
import type {Props} from '@theme/CodeBlock/Line/Token';
|
|
10
|
+
|
|
11
|
+
// Pass-through components that users can swizzle and customize
|
|
12
|
+
export default function CodeBlockLineToken({
|
|
13
|
+
line,
|
|
14
|
+
token,
|
|
15
|
+
...props
|
|
16
|
+
}: Props): ReactNode {
|
|
17
|
+
return <span {...props} />;
|
|
18
|
+
}
|
|
@@ -7,29 +7,48 @@
|
|
|
7
7
|
|
|
8
8
|
import React, {type ReactNode} from 'react';
|
|
9
9
|
import clsx from 'clsx';
|
|
10
|
+
import LineToken from '@theme/CodeBlock/Line/Token';
|
|
10
11
|
import type {Props} from '@theme/CodeBlock/Line';
|
|
11
12
|
|
|
12
13
|
import styles from './styles.module.css';
|
|
13
14
|
|
|
15
|
+
type Token = Props['line'][number];
|
|
16
|
+
|
|
17
|
+
// Replaces '\n' by ''
|
|
18
|
+
// Historical code, not sure why we even need this :/
|
|
19
|
+
function fixLineBreak(line: Token[]) {
|
|
20
|
+
const singleLineBreakToken =
|
|
21
|
+
line.length === 1 && line[0]!.content === '\n' ? line[0] : undefined;
|
|
22
|
+
|
|
23
|
+
if (singleLineBreakToken) {
|
|
24
|
+
return [{...singleLineBreakToken, content: ''}];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return line;
|
|
28
|
+
}
|
|
29
|
+
|
|
14
30
|
export default function CodeBlockLine({
|
|
15
|
-
line,
|
|
31
|
+
line: lineProp,
|
|
16
32
|
classNames,
|
|
17
33
|
showLineNumbers,
|
|
18
34
|
getLineProps,
|
|
19
35
|
getTokenProps,
|
|
20
36
|
}: Props): ReactNode {
|
|
21
|
-
|
|
22
|
-
line[0]!.content = '';
|
|
23
|
-
}
|
|
37
|
+
const line = fixLineBreak(lineProp);
|
|
24
38
|
|
|
25
39
|
const lineProps = getLineProps({
|
|
26
40
|
line,
|
|
27
41
|
className: clsx(classNames, showLineNumbers && styles.codeLine),
|
|
28
42
|
});
|
|
29
43
|
|
|
30
|
-
const lineTokens = line.map((token, key) =>
|
|
31
|
-
|
|
32
|
-
|
|
44
|
+
const lineTokens = line.map((token, key) => {
|
|
45
|
+
const tokenProps = getTokenProps({token});
|
|
46
|
+
return (
|
|
47
|
+
<LineToken key={key} {...tokenProps} line={line} token={token}>
|
|
48
|
+
{tokenProps.children}
|
|
49
|
+
</LineToken>
|
|
50
|
+
);
|
|
51
|
+
});
|
|
33
52
|
|
|
34
53
|
return (
|
|
35
54
|
<span {...lineProps}>
|
|
@@ -0,0 +1,15 @@
|
|
|
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 {ReactNode} from 'react';
|
|
9
|
+
|
|
10
|
+
import type {Props} from '@theme/CodeBlock/Title';
|
|
11
|
+
|
|
12
|
+
// Just a pass-through component that users can swizzle and customize
|
|
13
|
+
export default function CodeBlockTitle({children}: Props): ReactNode {
|
|
14
|
+
return children;
|
|
15
|
+
}
|