@docusaurus/theme-classic 3.7.0 → 3.8.0-canary-6324

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 (136) hide show
  1. package/lib/getSwizzleConfig.js +1 -1
  2. package/lib/index.js +9 -0
  3. package/lib/inlineScripts.js +6 -27
  4. package/lib/inlineSvgSprites.d.ts +7 -0
  5. package/lib/inlineSvgSprites.js +14 -0
  6. package/lib/options.js +5 -0
  7. package/lib/theme/AnnouncementBar/index.js +6 -2
  8. package/lib/theme/CodeBlock/{WordWrapButton → Buttons/Button}/index.d.ts +2 -2
  9. package/lib/theme/CodeBlock/Buttons/Button/index.js +13 -0
  10. package/lib/theme/CodeBlock/Buttons/CopyButton/index.d.ts +9 -0
  11. package/lib/theme/CodeBlock/{CopyButton → Buttons/CopyButton}/index.js +36 -25
  12. package/lib/theme/CodeBlock/Buttons/WordWrapButton/index.d.ts +9 -0
  13. package/lib/theme/CodeBlock/{WordWrapButton → Buttons/WordWrapButton}/index.js +12 -7
  14. package/lib/theme/CodeBlock/{CopyButton → Buttons}/index.d.ts +2 -2
  15. package/lib/theme/CodeBlock/Buttons/index.js +27 -0
  16. package/lib/theme/CodeBlock/Buttons/styles.module.css +37 -0
  17. package/lib/theme/CodeBlock/Content/Element.js +4 -2
  18. package/lib/theme/CodeBlock/Content/String.d.ts +1 -1
  19. package/lib/theme/CodeBlock/Content/String.js +22 -92
  20. package/lib/theme/CodeBlock/Content/index.d.ts +9 -0
  21. package/lib/theme/CodeBlock/Content/index.js +74 -0
  22. package/lib/theme/CodeBlock/Content/styles.module.css +0 -52
  23. package/lib/theme/CodeBlock/Layout/index.d.ts +9 -0
  24. package/lib/theme/CodeBlock/Layout/index.js +30 -0
  25. package/lib/theme/CodeBlock/Layout/styles.module.css +27 -0
  26. package/lib/theme/CodeBlock/Line/Token/index.d.ts +9 -0
  27. package/lib/theme/CodeBlock/Line/Token/index.js +11 -0
  28. package/lib/theme/CodeBlock/Line/index.d.ts +1 -1
  29. package/lib/theme/CodeBlock/Line/index.js +21 -7
  30. package/lib/theme/CodeBlock/Title/index.d.ts +9 -0
  31. package/lib/theme/CodeBlock/Title/index.js +10 -0
  32. package/lib/theme/ColorModeToggle/index.d.ts +1 -1
  33. package/lib/theme/ColorModeToggle/index.js +85 -27
  34. package/lib/theme/ColorModeToggle/styles.module.css +7 -2
  35. package/lib/theme/DocBreadcrumbs/StructuredData/index.d.ts +9 -0
  36. package/lib/theme/DocBreadcrumbs/StructuredData/index.js +21 -0
  37. package/lib/theme/DocBreadcrumbs/index.js +36 -54
  38. package/lib/theme/DocCard/index.js +6 -4
  39. package/lib/theme/DocCardList/index.js +12 -6
  40. package/lib/theme/DocCardList/styles.module.css +14 -0
  41. package/lib/theme/DocCategoryGeneratedIndexPage/index.js +1 -1
  42. package/lib/theme/DocCategoryGeneratedIndexPage/styles.module.css +0 -8
  43. package/lib/theme/DocItem/Paginator/index.js +7 -1
  44. package/lib/theme/DocPaginator/index.js +3 -2
  45. package/lib/theme/DocSidebarItem/Category/index.js +8 -1
  46. package/lib/theme/Footer/Layout/index.js +2 -1
  47. package/lib/theme/Footer/Links/MultiColumn/index.js +7 -1
  48. package/lib/theme/Icon/ExternalLink/index.js +4 -5
  49. package/lib/theme/Icon/SystemColorMode/index.d.ts +9 -0
  50. package/lib/theme/Icon/SystemColorMode/index.js +16 -0
  51. package/lib/theme/Layout/index.js +1 -0
  52. package/lib/theme/Navbar/ColorModeToggle/index.js +5 -4
  53. package/lib/theme/Navbar/Content/index.js +20 -3
  54. package/lib/theme/Navbar/Content/styles.module.css +8 -0
  55. package/lib/theme/Navbar/Layout/index.js +2 -1
  56. package/lib/theme/Navbar/MobileSidebar/Layout/index.js +35 -4
  57. package/lib/theme/NavbarItem/DefaultNavbarItem/Desktop/index.d.ts +9 -0
  58. package/lib/theme/NavbarItem/DefaultNavbarItem/Desktop/index.js +29 -0
  59. package/lib/theme/NavbarItem/DefaultNavbarItem/Mobile/index.d.ts +9 -0
  60. package/lib/theme/NavbarItem/DefaultNavbarItem/Mobile/index.js +20 -0
  61. package/lib/theme/NavbarItem/DefaultNavbarItem/index.js +25 -0
  62. package/lib/theme/NavbarItem/DocsVersionDropdownNavbarItem.d.ts +1 -1
  63. package/lib/theme/NavbarItem/DocsVersionDropdownNavbarItem.js +50 -7
  64. package/lib/theme/NavbarItem/DropdownNavbarItem/Desktop/index.d.ts +9 -0
  65. package/lib/theme/NavbarItem/DropdownNavbarItem/Desktop/index.js +74 -0
  66. package/lib/theme/NavbarItem/DropdownNavbarItem/Mobile/index.d.ts +10 -0
  67. package/lib/theme/NavbarItem/DropdownNavbarItem/Mobile/index.js +142 -0
  68. package/lib/theme/NavbarItem/DropdownNavbarItem/index.js +3 -142
  69. package/lib/theme/Tag/index.js +1 -0
  70. package/lib/theme/ThemeProvider/TitleFormatter/index.d.ts +9 -0
  71. package/lib/theme/ThemeProvider/TitleFormatter/index.js +19 -0
  72. package/lib/theme/ThemeProvider/index.d.ts +9 -0
  73. package/lib/theme/ThemeProvider/index.js +11 -0
  74. package/package.json +15 -15
  75. package/src/getSwizzleConfig.ts +1 -1
  76. package/src/index.ts +9 -0
  77. package/src/inlineScripts.ts +6 -27
  78. package/src/inlineSvgSprites.ts +12 -0
  79. package/src/options.ts +15 -0
  80. package/src/theme/AnnouncementBar/index.tsx +6 -2
  81. package/src/theme/CodeBlock/Buttons/Button/index.tsx +19 -0
  82. package/src/theme/CodeBlock/{CopyButton → Buttons/CopyButton}/index.tsx +42 -26
  83. package/src/theme/CodeBlock/{WordWrapButton → Buttons/WordWrapButton}/index.tsx +15 -12
  84. package/src/theme/CodeBlock/Buttons/index.tsx +32 -0
  85. package/src/theme/CodeBlock/Buttons/styles.module.css +37 -0
  86. package/src/theme/CodeBlock/Content/Element.tsx +4 -2
  87. package/src/theme/CodeBlock/Content/String.tsx +24 -101
  88. package/src/theme/CodeBlock/Content/index.tsx +84 -0
  89. package/src/theme/CodeBlock/Content/styles.module.css +0 -52
  90. package/src/theme/CodeBlock/Layout/index.tsx +34 -0
  91. package/src/theme/CodeBlock/Layout/styles.module.css +27 -0
  92. package/src/theme/CodeBlock/Line/Token/index.tsx +18 -0
  93. package/src/theme/CodeBlock/Line/index.tsx +26 -7
  94. package/src/theme/CodeBlock/Title/index.tsx +15 -0
  95. package/src/theme/ColorModeToggle/index.tsx +102 -32
  96. package/src/theme/ColorModeToggle/styles.module.css +7 -2
  97. package/src/theme/DocBreadcrumbs/StructuredData/index.tsx +24 -0
  98. package/src/theme/DocBreadcrumbs/index.tsx +35 -57
  99. package/src/theme/DocCard/index.tsx +8 -2
  100. package/src/theme/DocCardList/index.tsx +18 -7
  101. package/src/theme/DocCardList/styles.module.css +14 -0
  102. package/src/theme/DocCategoryGeneratedIndexPage/index.tsx +1 -1
  103. package/src/theme/DocCategoryGeneratedIndexPage/styles.module.css +0 -8
  104. package/src/theme/DocItem/Paginator/index.tsx +7 -1
  105. package/src/theme/DocPaginator/index.tsx +3 -2
  106. package/src/theme/DocSidebarItem/Category/index.tsx +8 -1
  107. package/src/theme/Footer/Layout/index.tsx +2 -1
  108. package/src/theme/Footer/Links/MultiColumn/index.tsx +7 -1
  109. package/src/theme/Icon/ExternalLink/index.tsx +5 -5
  110. package/src/theme/Icon/SystemColorMode/index.tsx +20 -0
  111. package/src/theme/Layout/index.tsx +1 -0
  112. package/src/theme/Navbar/ColorModeToggle/index.tsx +5 -4
  113. package/src/theme/Navbar/Content/index.tsx +20 -3
  114. package/src/theme/Navbar/Content/styles.module.css +8 -0
  115. package/src/theme/Navbar/Layout/index.tsx +2 -1
  116. package/src/theme/Navbar/MobileSidebar/Layout/index.tsx +43 -4
  117. package/src/theme/NavbarItem/DefaultNavbarItem/Desktop/index.tsx +34 -0
  118. package/src/theme/NavbarItem/DefaultNavbarItem/Mobile/index.tsx +23 -0
  119. package/src/theme/NavbarItem/DefaultNavbarItem/index.tsx +28 -0
  120. package/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx +87 -9
  121. package/src/theme/NavbarItem/DropdownNavbarItem/Desktop/index.tsx +86 -0
  122. package/src/theme/NavbarItem/DropdownNavbarItem/Mobile/index.tsx +166 -0
  123. package/src/theme/NavbarItem/DropdownNavbarItem/index.tsx +4 -168
  124. package/src/theme/Tag/index.tsx +1 -0
  125. package/src/theme/ThemeProvider/TitleFormatter/index.tsx +27 -0
  126. package/src/theme/ThemeProvider/index.tsx +14 -0
  127. package/src/theme-classic.d.ts +175 -20
  128. package/lib/theme/NavbarItem/DefaultNavbarItem.js +0 -52
  129. package/src/theme/NavbarItem/DefaultNavbarItem.tsx +0 -66
  130. /package/lib/theme/CodeBlock/{CopyButton → Buttons/CopyButton}/styles.module.css +0 -0
  131. /package/lib/theme/CodeBlock/{WordWrapButton → Buttons/WordWrapButton}/styles.module.css +0 -0
  132. /package/lib/theme/NavbarItem/{DefaultNavbarItem.d.ts → DefaultNavbarItem/index.d.ts} +0 -0
  133. /package/lib/theme/NavbarItem/DropdownNavbarItem/{styles.module.css → Mobile/styles.module.css} +0 -0
  134. /package/src/theme/CodeBlock/{CopyButton → Buttons/CopyButton}/styles.module.css +0 -0
  135. /package/src/theme/CodeBlock/{WordWrapButton → Buttons/WordWrapButton}/styles.module.css +0 -0
  136. /package/src/theme/NavbarItem/DropdownNavbarItem/{styles.module.css → Mobile/styles.module.css} +0 -0
@@ -0,0 +1,142 @@
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, {useEffect} from 'react';
8
+ import clsx from 'clsx';
9
+ import {
10
+ isRegexpStringMatch,
11
+ useCollapsible,
12
+ Collapsible,
13
+ } from '@docusaurus/theme-common';
14
+ import {isSamePath, useLocalPathname} from '@docusaurus/theme-common/internal';
15
+ import {translate} from '@docusaurus/Translate';
16
+ import NavbarNavLink from '@theme/NavbarItem/NavbarNavLink';
17
+ import NavbarItem from '@theme/NavbarItem';
18
+ import styles from './styles.module.css';
19
+ function isItemActive(item, localPathname) {
20
+ if (isSamePath(item.to, localPathname)) {
21
+ return true;
22
+ }
23
+ if (isRegexpStringMatch(item.activeBaseRegex, localPathname)) {
24
+ return true;
25
+ }
26
+ if (item.activeBasePath && localPathname.startsWith(item.activeBasePath)) {
27
+ return true;
28
+ }
29
+ return false;
30
+ }
31
+ function containsActiveItems(items, localPathname) {
32
+ return items.some((item) => isItemActive(item, localPathname));
33
+ }
34
+ function CollapseButton({collapsed, onClick}) {
35
+ return (
36
+ <button
37
+ aria-label={
38
+ collapsed
39
+ ? translate({
40
+ id: 'theme.navbar.mobileDropdown.collapseButton.expandAriaLabel',
41
+ message: 'Expand the dropdown',
42
+ description:
43
+ 'The ARIA label of the button to expand the mobile dropdown navbar item',
44
+ })
45
+ : translate({
46
+ id: 'theme.navbar.mobileDropdown.collapseButton.collapseAriaLabel',
47
+ message: 'Collapse the dropdown',
48
+ description:
49
+ 'The ARIA label of the button to collapse the mobile dropdown navbar item',
50
+ })
51
+ }
52
+ aria-expanded={!collapsed}
53
+ type="button"
54
+ className="clean-btn menu__caret"
55
+ onClick={onClick}
56
+ />
57
+ );
58
+ }
59
+ function useItemCollapsible({active}) {
60
+ const {collapsed, toggleCollapsed, setCollapsed} = useCollapsible({
61
+ initialState: () => !active,
62
+ });
63
+ // Expand if any item active after a navigation
64
+ useEffect(() => {
65
+ if (active) {
66
+ setCollapsed(false);
67
+ }
68
+ }, [active, setCollapsed]);
69
+ return {
70
+ collapsed,
71
+ toggleCollapsed,
72
+ };
73
+ }
74
+ export default function DropdownNavbarItemMobile({
75
+ items,
76
+ className,
77
+ position, // Need to destructure position from props so that it doesn't get passed on.
78
+ onClick,
79
+ ...props
80
+ }) {
81
+ const localPathname = useLocalPathname();
82
+ const isActive = isSamePath(props.to, localPathname);
83
+ const containsActive = containsActiveItems(items, localPathname);
84
+ const {collapsed, toggleCollapsed} = useItemCollapsible({
85
+ active: isActive || containsActive,
86
+ });
87
+ // # hash permits to make the <a> tag focusable in case no link target
88
+ // See https://github.com/facebook/docusaurus/pull/6003
89
+ // There's probably a better solution though...
90
+ const href = props.to ? undefined : '#';
91
+ return (
92
+ <li
93
+ className={clsx('menu__list-item', {
94
+ 'menu__list-item--collapsed': collapsed,
95
+ })}>
96
+ <div
97
+ className={clsx('menu__list-item-collapsible', {
98
+ 'menu__list-item-collapsible--active': isActive,
99
+ })}>
100
+ <NavbarNavLink
101
+ role="button"
102
+ className={clsx(
103
+ styles.dropdownNavbarItemMobile,
104
+ 'menu__link menu__link--sublist',
105
+ className,
106
+ )}
107
+ href={href}
108
+ {...props}
109
+ onClick={(e) => {
110
+ // Prevent navigation when link is "#"
111
+ if (href === '#') {
112
+ e.preventDefault();
113
+ }
114
+ // Otherwise we let navigation eventually happen, and/or collapse
115
+ toggleCollapsed();
116
+ }}>
117
+ {props.children ?? props.label}
118
+ </NavbarNavLink>
119
+ <CollapseButton
120
+ collapsed={collapsed}
121
+ onClick={(e) => {
122
+ e.preventDefault();
123
+ toggleCollapsed();
124
+ }}
125
+ />
126
+ </div>
127
+
128
+ <Collapsible lazy as="ul" className="menu__list" collapsed={collapsed}>
129
+ {items.map((childItemProps, i) => (
130
+ <NavbarItem
131
+ mobile
132
+ isDropdownItem
133
+ onClick={onClick}
134
+ activeClassName="menu__link--active"
135
+ {...childItemProps}
136
+ key={i}
137
+ />
138
+ ))}
139
+ </Collapsible>
140
+ </li>
141
+ );
142
+ }
@@ -4,148 +4,9 @@
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, {useState, useRef, useEffect} from 'react';
8
- import clsx from 'clsx';
9
- import {
10
- isRegexpStringMatch,
11
- useCollapsible,
12
- Collapsible,
13
- } from '@docusaurus/theme-common';
14
- import {isSamePath, useLocalPathname} from '@docusaurus/theme-common/internal';
15
- import NavbarNavLink from '@theme/NavbarItem/NavbarNavLink';
16
- import NavbarItem from '@theme/NavbarItem';
17
- import styles from './styles.module.css';
18
- function isItemActive(item, localPathname) {
19
- if (isSamePath(item.to, localPathname)) {
20
- return true;
21
- }
22
- if (isRegexpStringMatch(item.activeBaseRegex, localPathname)) {
23
- return true;
24
- }
25
- if (item.activeBasePath && localPathname.startsWith(item.activeBasePath)) {
26
- return true;
27
- }
28
- return false;
29
- }
30
- function containsActiveItems(items, localPathname) {
31
- return items.some((item) => isItemActive(item, localPathname));
32
- }
33
- function DropdownNavbarItemDesktop({
34
- items,
35
- position,
36
- className,
37
- onClick,
38
- ...props
39
- }) {
40
- const dropdownRef = useRef(null);
41
- const [showDropdown, setShowDropdown] = useState(false);
42
- useEffect(() => {
43
- const handleClickOutside = (event) => {
44
- if (!dropdownRef.current || dropdownRef.current.contains(event.target)) {
45
- return;
46
- }
47
- setShowDropdown(false);
48
- };
49
- document.addEventListener('mousedown', handleClickOutside);
50
- document.addEventListener('touchstart', handleClickOutside);
51
- document.addEventListener('focusin', handleClickOutside);
52
- return () => {
53
- document.removeEventListener('mousedown', handleClickOutside);
54
- document.removeEventListener('touchstart', handleClickOutside);
55
- document.removeEventListener('focusin', handleClickOutside);
56
- };
57
- }, [dropdownRef]);
58
- return (
59
- <div
60
- ref={dropdownRef}
61
- className={clsx('navbar__item', 'dropdown', 'dropdown--hoverable', {
62
- 'dropdown--right': position === 'right',
63
- 'dropdown--show': showDropdown,
64
- })}>
65
- <NavbarNavLink
66
- aria-haspopup="true"
67
- aria-expanded={showDropdown}
68
- role="button"
69
- // # hash permits to make the <a> tag focusable in case no link target
70
- // See https://github.com/facebook/docusaurus/pull/6003
71
- // There's probably a better solution though...
72
- href={props.to ? undefined : '#'}
73
- className={clsx('navbar__link', className)}
74
- {...props}
75
- onClick={props.to ? undefined : (e) => e.preventDefault()}
76
- onKeyDown={(e) => {
77
- if (e.key === 'Enter') {
78
- e.preventDefault();
79
- setShowDropdown(!showDropdown);
80
- }
81
- }}>
82
- {props.children ?? props.label}
83
- </NavbarNavLink>
84
- <ul className="dropdown__menu">
85
- {items.map((childItemProps, i) => (
86
- <NavbarItem
87
- isDropdownItem
88
- activeClassName="dropdown__link--active"
89
- {...childItemProps}
90
- key={i}
91
- />
92
- ))}
93
- </ul>
94
- </div>
95
- );
96
- }
97
- function DropdownNavbarItemMobile({
98
- items,
99
- className,
100
- position, // Need to destructure position from props so that it doesn't get passed on.
101
- onClick,
102
- ...props
103
- }) {
104
- const localPathname = useLocalPathname();
105
- const containsActive = containsActiveItems(items, localPathname);
106
- const {collapsed, toggleCollapsed, setCollapsed} = useCollapsible({
107
- initialState: () => !containsActive,
108
- });
109
- // Expand/collapse if any item active after a navigation
110
- useEffect(() => {
111
- if (containsActive) {
112
- setCollapsed(!containsActive);
113
- }
114
- }, [localPathname, containsActive, setCollapsed]);
115
- return (
116
- <li
117
- className={clsx('menu__list-item', {
118
- 'menu__list-item--collapsed': collapsed,
119
- })}>
120
- <NavbarNavLink
121
- role="button"
122
- className={clsx(
123
- styles.dropdownNavbarItemMobile,
124
- 'menu__link menu__link--sublist menu__link--sublist-caret',
125
- className,
126
- )}
127
- {...props}
128
- onClick={(e) => {
129
- e.preventDefault();
130
- toggleCollapsed();
131
- }}>
132
- {props.children ?? props.label}
133
- </NavbarNavLink>
134
- <Collapsible lazy as="ul" className="menu__list" collapsed={collapsed}>
135
- {items.map((childItemProps, i) => (
136
- <NavbarItem
137
- mobile
138
- isDropdownItem
139
- onClick={onClick}
140
- activeClassName="menu__link--active"
141
- {...childItemProps}
142
- key={i}
143
- />
144
- ))}
145
- </Collapsible>
146
- </li>
147
- );
148
- }
7
+ import React from 'react';
8
+ import DropdownNavbarItemMobile from '@theme/NavbarItem/DropdownNavbarItem/Mobile';
9
+ import DropdownNavbarItemDesktop from '@theme/NavbarItem/DropdownNavbarItem/Desktop';
149
10
  export default function DropdownNavbarItem({mobile = false, ...props}) {
150
11
  const Comp = mobile ? DropdownNavbarItemMobile : DropdownNavbarItemDesktop;
151
12
  return <Comp {...props} />;
@@ -11,6 +11,7 @@ import styles from './styles.module.css';
11
11
  export default function Tag({permalink, label, count, description}) {
12
12
  return (
13
13
  <Link
14
+ rel="tag"
14
15
  href={permalink}
15
16
  title={description}
16
17
  className={clsx(
@@ -0,0 +1,9 @@
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 { type ReactNode } from 'react';
8
+ import type { Props } from '@theme/ThemeProvider/TitleFormatter';
9
+ export default function ThemeProviderTitleFormatter({ children, }: Props): ReactNode;
@@ -0,0 +1,19 @@
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 {TitleFormatterProvider} from '@docusaurus/theme-common/internal';
9
+ const formatter = (params) => {
10
+ // Add your own title formatting logic here!
11
+ return params.defaultFormatter(params);
12
+ };
13
+ export default function ThemeProviderTitleFormatter({children}) {
14
+ return (
15
+ <TitleFormatterProvider formatter={formatter}>
16
+ {children}
17
+ </TitleFormatterProvider>
18
+ );
19
+ }
@@ -0,0 +1,9 @@
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 { type ReactNode } from 'react';
8
+ import type { Props } from '@theme/ThemeProvider';
9
+ export default function ThemeProvider({ children }: Props): ReactNode;
@@ -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 TitleFormatterProvider from '@theme/ThemeProvider/TitleFormatter';
9
+ export default function ThemeProvider({children}) {
10
+ return <TitleFormatterProvider>{children}</TitleFormatterProvider>;
11
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/theme-classic",
3
- "version": "3.7.0",
3
+ "version": "3.8.0-canary-6324",
4
4
  "description": "Classic theme for Docusaurus",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/theme-classic.d.ts",
@@ -20,19 +20,19 @@
20
20
  "copy:watch": "node ../../admin/scripts/copyUntypedFiles.js --watch"
21
21
  },
22
22
  "dependencies": {
23
- "@docusaurus/core": "3.7.0",
24
- "@docusaurus/logger": "3.7.0",
25
- "@docusaurus/mdx-loader": "3.7.0",
26
- "@docusaurus/module-type-aliases": "3.7.0",
27
- "@docusaurus/plugin-content-blog": "3.7.0",
28
- "@docusaurus/plugin-content-docs": "3.7.0",
29
- "@docusaurus/plugin-content-pages": "3.7.0",
30
- "@docusaurus/theme-common": "3.7.0",
31
- "@docusaurus/theme-translations": "3.7.0",
32
- "@docusaurus/types": "3.7.0",
33
- "@docusaurus/utils": "3.7.0",
34
- "@docusaurus/utils-common": "3.7.0",
35
- "@docusaurus/utils-validation": "3.7.0",
23
+ "@docusaurus/core": "3.8.0-canary-6324",
24
+ "@docusaurus/logger": "3.8.0-canary-6324",
25
+ "@docusaurus/mdx-loader": "3.8.0-canary-6324",
26
+ "@docusaurus/module-type-aliases": "3.8.0-canary-6324",
27
+ "@docusaurus/plugin-content-blog": "3.8.0-canary-6324",
28
+ "@docusaurus/plugin-content-docs": "3.8.0-canary-6324",
29
+ "@docusaurus/plugin-content-pages": "3.8.0-canary-6324",
30
+ "@docusaurus/theme-common": "3.8.0-canary-6324",
31
+ "@docusaurus/theme-translations": "3.8.0-canary-6324",
32
+ "@docusaurus/types": "3.8.0-canary-6324",
33
+ "@docusaurus/utils": "3.8.0-canary-6324",
34
+ "@docusaurus/utils-common": "3.8.0-canary-6324",
35
+ "@docusaurus/utils-validation": "3.8.0-canary-6324",
36
36
  "@mdx-js/react": "^3.0.0",
37
37
  "clsx": "^2.0.0",
38
38
  "copy-text-to-clipboard": "^3.2.0",
@@ -62,5 +62,5 @@
62
62
  "engines": {
63
63
  "node": ">=18.0"
64
64
  },
65
- "gitHead": "dd59750c16fe6908a26f18806a54d4c3dbe6db43"
65
+ "gitHead": "1fdcae691b9f171b90695b15e8e643eb031cb96a"
66
66
  }
@@ -159,7 +159,7 @@ export default function getSwizzleConfig(): SwizzleConfig {
159
159
  'CodeBlock/Content': {
160
160
  actions: {
161
161
  eject: 'unsafe',
162
- wrap: 'forbidden',
162
+ wrap: 'unsafe',
163
163
  },
164
164
  description:
165
165
  'The folder containing components responsible for rendering different types of CodeBlock content.',
package/src/index.ts CHANGED
@@ -14,6 +14,7 @@ import {
14
14
  getAnnouncementBarInlineScript,
15
15
  DataAttributeQueryStringInlineJavaScript,
16
16
  } from './inlineScripts';
17
+ import {SvgSpriteDefs} from './inlineSvgSprites';
17
18
  import type {LoadContext, Plugin} from '@docusaurus/types';
18
19
  import type {ThemeConfig} from '@docusaurus/theme-common';
19
20
  import type {Plugin as PostCssPlugin} from 'postcss';
@@ -121,6 +122,14 @@ export default function themeClassic(
121
122
  injectHtmlTags() {
122
123
  return {
123
124
  preBodyTags: [
125
+ {
126
+ tagName: 'svg',
127
+ attributes: {
128
+ xmlns: 'http://www.w3.org/2000/svg',
129
+ style: 'display: none;',
130
+ },
131
+ innerHTML: SvgSpriteDefs,
132
+ },
124
133
  {
125
134
  tagName: 'script',
126
135
  innerHTML: `
@@ -30,43 +30,22 @@ export function getThemeInlineScript({
30
30
  return `(function() {
31
31
  var defaultMode = '${defaultMode}';
32
32
  var respectPrefersColorScheme = ${respectPrefersColorScheme};
33
-
34
- function setDataThemeAttribute(theme) {
35
- document.documentElement.setAttribute('data-theme', theme);
33
+ function getSystemColorMode() {
34
+ return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
36
35
  }
37
-
38
36
  function getQueryStringTheme() {
39
37
  try {
40
38
  return new URLSearchParams(window.location.search).get('${ThemeQueryStringKey}')
41
- } catch (e) {
42
- }
39
+ } catch (e) {}
43
40
  }
44
-
45
41
  function getStoredTheme() {
46
42
  try {
47
43
  return window['${siteStorage.type}'].getItem('${themeStorageKey}');
48
- } catch (err) {
49
- }
44
+ } catch (err) {}
50
45
  }
51
-
52
46
  var initialTheme = getQueryStringTheme() || getStoredTheme();
53
- if (initialTheme !== null) {
54
- setDataThemeAttribute(initialTheme);
55
- } else {
56
- if (
57
- respectPrefersColorScheme &&
58
- window.matchMedia('(prefers-color-scheme: dark)').matches
59
- ) {
60
- setDataThemeAttribute('dark');
61
- } else if (
62
- respectPrefersColorScheme &&
63
- window.matchMedia('(prefers-color-scheme: light)').matches
64
- ) {
65
- setDataThemeAttribute('light');
66
- } else {
67
- setDataThemeAttribute(defaultMode === 'dark' ? 'dark' : 'light');
68
- }
69
- }
47
+ document.documentElement.setAttribute('data-theme', initialTheme || (respectPrefersColorScheme ? getSystemColorMode() : defaultMode));
48
+ document.documentElement.setAttribute('data-theme-choice', initialTheme || (respectPrefersColorScheme ? 'system' : defaultMode));
70
49
  })();`;
71
50
  }
72
51
 
@@ -0,0 +1,12 @@
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
+ // For icons that are heavily repeated in the static html output
9
+ // See also https://github.com/facebook/docusaurus/issues/5865
10
+ export const SvgSpriteDefs = `<defs>
11
+ <symbol id="theme-svg-external-link" viewBox="0 0 24 24"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z" /></symbol>
12
+ </defs>`;
package/src/options.ts CHANGED
@@ -7,6 +7,10 @@
7
7
 
8
8
  import {themes} from 'prism-react-renderer';
9
9
  import {Joi, URISchema} from '@docusaurus/utils-validation';
10
+ import type {
11
+ PropVersionItem,
12
+ PropVersionItems,
13
+ } from '@theme/NavbarItem/DocsVersionDropdownNavbarItem';
10
14
  import type {Options, PluginOptions} from '@docusaurus/theme-classic';
11
15
  import type {ThemeConfig} from '@docusaurus/theme-common';
12
16
  import type {
@@ -210,6 +214,17 @@ const DocsVersionDropdownNavbarItemSchema = NavbarItemBaseSchema.append({
210
214
  dropdownActiveClassDisabled: Joi.boolean(),
211
215
  dropdownItemsBefore: Joi.array().items(DropdownSubitemSchema).default([]),
212
216
  dropdownItemsAfter: Joi.array().items(DropdownSubitemSchema).default([]),
217
+ versions: Joi.alternatives().try(
218
+ Joi.array().items(Joi.string().min(1)).min(1),
219
+ Joi.object<PropVersionItems>()
220
+ .pattern(
221
+ Joi.string().min(1),
222
+ Joi.object<PropVersionItem>({
223
+ label: Joi.string().min(1),
224
+ }),
225
+ )
226
+ .min(1),
227
+ ),
213
228
  });
214
229
 
215
230
  const LocaleDropdownNavbarItemSchema = NavbarItemBaseSchema.append({
@@ -6,7 +6,8 @@
6
6
  */
7
7
 
8
8
  import React, {type ReactNode} from 'react';
9
- import {useThemeConfig} from '@docusaurus/theme-common';
9
+ import clsx from 'clsx';
10
+ import {ThemeClassNames, useThemeConfig} from '@docusaurus/theme-common';
10
11
  import {useAnnouncementBar} from '@docusaurus/theme-common/internal';
11
12
  import AnnouncementBarCloseButton from '@theme/AnnouncementBar/CloseButton';
12
13
  import AnnouncementBarContent from '@theme/AnnouncementBar/Content';
@@ -22,7 +23,10 @@ export default function AnnouncementBar(): ReactNode {
22
23
  const {backgroundColor, textColor, isCloseable} = announcementBar!;
23
24
  return (
24
25
  <div
25
- className={styles.announcementBar}
26
+ className={clsx(
27
+ ThemeClassNames.announcementBar.container,
28
+ styles.announcementBar,
29
+ )}
26
30
  style={{backgroundColor, color: textColor}}
27
31
  role="banner">
28
32
  {isCloseable && <div className={styles.announcementBarPlaceholder} />}
@@ -0,0 +1,19 @@
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 type {Props} from '@theme/CodeBlock/Buttons/Button';
11
+
12
+ export default function CodeBlockButton({
13
+ className,
14
+ ...props
15
+ }: Props): ReactNode {
16
+ return (
17
+ <button type="button" {...props} className={clsx('clean-btn', className)} />
18
+ );
19
+ }
@@ -15,16 +15,44 @@ import React, {
15
15
  import clsx from 'clsx';
16
16
  import copy from 'copy-text-to-clipboard';
17
17
  import {translate} from '@docusaurus/Translate';
18
- import type {Props} from '@theme/CodeBlock/CopyButton';
18
+ import {useCodeBlockContext} from '@docusaurus/theme-common/internal';
19
+ import Button from '@theme/CodeBlock/Buttons/Button';
20
+ import type {Props} from '@theme/CodeBlock/Buttons/CopyButton';
19
21
  import IconCopy from '@theme/Icon/Copy';
20
22
  import IconSuccess from '@theme/Icon/Success';
21
23
 
22
24
  import styles from './styles.module.css';
23
25
 
24
- export default function CopyButton({code, className}: Props): ReactNode {
26
+ function title() {
27
+ return translate({
28
+ id: 'theme.CodeBlock.copy',
29
+ message: 'Copy',
30
+ description: 'The copy button label on code blocks',
31
+ });
32
+ }
33
+
34
+ function ariaLabel(isCopied: boolean) {
35
+ return isCopied
36
+ ? translate({
37
+ id: 'theme.CodeBlock.copied',
38
+ message: 'Copied',
39
+ description: 'The copied button label on code blocks',
40
+ })
41
+ : translate({
42
+ id: 'theme.CodeBlock.copyButtonAriaLabel',
43
+ message: 'Copy code to clipboard',
44
+ description: 'The ARIA label for copy code blocks button',
45
+ });
46
+ }
47
+
48
+ function useCopyButton() {
49
+ const {
50
+ metadata: {code},
51
+ } = useCodeBlockContext();
25
52
  const [isCopied, setIsCopied] = useState(false);
26
53
  const copyTimeout = useRef<number | undefined>(undefined);
27
- const handleCopyCode = useCallback(() => {
54
+
55
+ const copyCode = useCallback(() => {
28
56
  copy(code);
29
57
  setIsCopied(true);
30
58
  copyTimeout.current = window.setTimeout(() => {
@@ -34,38 +62,26 @@ export default function CopyButton({code, className}: Props): ReactNode {
34
62
 
35
63
  useEffect(() => () => window.clearTimeout(copyTimeout.current), []);
36
64
 
65
+ return {copyCode, isCopied};
66
+ }
67
+
68
+ export default function CopyButton({className}: Props): ReactNode {
69
+ const {copyCode, isCopied} = useCopyButton();
70
+
37
71
  return (
38
- <button
39
- type="button"
40
- aria-label={
41
- isCopied
42
- ? translate({
43
- id: 'theme.CodeBlock.copied',
44
- message: 'Copied',
45
- description: 'The copied button label on code blocks',
46
- })
47
- : translate({
48
- id: 'theme.CodeBlock.copyButtonAriaLabel',
49
- message: 'Copy code to clipboard',
50
- description: 'The ARIA label for copy code blocks button',
51
- })
52
- }
53
- title={translate({
54
- id: 'theme.CodeBlock.copy',
55
- message: 'Copy',
56
- description: 'The copy button label on code blocks',
57
- })}
72
+ <Button
73
+ aria-label={ariaLabel(isCopied)}
74
+ title={title()}
58
75
  className={clsx(
59
- 'clean-btn',
60
76
  className,
61
77
  styles.copyButton,
62
78
  isCopied && styles.copyButtonCopied,
63
79
  )}
64
- onClick={handleCopyCode}>
80
+ onClick={copyCode}>
65
81
  <span className={styles.copyButtonIcons} aria-hidden="true">
66
82
  <IconCopy className={styles.copyButtonIcon} />
67
83
  <IconSuccess className={styles.copyButtonSuccessIcon} />
68
84
  </span>
69
- </button>
85
+ </Button>
70
86
  );
71
87
  }