@docusaurus/theme-classic 0.0.0-4777 → 0.0.0-4782

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.
@@ -0,0 +1,53 @@
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 {isActiveSidebarItem, ThemeClassNames} from '@docusaurus/theme-common';
10
+ import Link from '@docusaurus/Link';
11
+ import isInternalUrl from '@docusaurus/isInternalUrl';
12
+ import IconExternalLink from '@theme/IconExternalLink';
13
+ import styles from './Link.module.css';
14
+ export default function DocSidebarItemLink({
15
+ item,
16
+ onItemClick,
17
+ activePath,
18
+ level,
19
+ index,
20
+ ...props
21
+ }) {
22
+ const {href, label, className} = item;
23
+ const isActive = isActiveSidebarItem(item, activePath);
24
+ const isInternalLink = isInternalUrl(href);
25
+ return (
26
+ <li
27
+ className={clsx(
28
+ ThemeClassNames.docs.docSidebarItemLink,
29
+ ThemeClassNames.docs.docSidebarItemLinkLevel(level),
30
+ 'menu__list-item',
31
+ className,
32
+ )}
33
+ key={label}>
34
+ <Link
35
+ className={clsx(
36
+ 'menu__link',
37
+ !isInternalLink && styles.menuExternalLink,
38
+ {
39
+ 'menu__link--active': isActive,
40
+ },
41
+ )}
42
+ aria-current={isActive ? 'page' : undefined}
43
+ to={href}
44
+ {...(isInternalLink && {
45
+ onClick: onItemClick ? () => onItemClick(item) : undefined,
46
+ })}
47
+ {...props}>
48
+ {label}
49
+ {!isInternalLink && <IconExternalLink />}
50
+ </Link>
51
+ </li>
52
+ );
53
+ }
@@ -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
+ .menuExternalLink {
9
+ align-items: center;
10
+ }
@@ -4,26 +4,10 @@
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, {useEffect, useMemo} from 'react';
8
- import clsx from 'clsx';
9
- import {
10
- isActiveSidebarItem,
11
- usePrevious,
12
- Collapsible,
13
- useCollapsible,
14
- findFirstCategoryLink,
15
- ThemeClassNames,
16
- useThemeConfig,
17
- useDocSidebarItemsExpandedState,
18
- isSamePath,
19
- } from '@docusaurus/theme-common';
20
- import Link from '@docusaurus/Link';
21
- import isInternalUrl from '@docusaurus/isInternalUrl';
22
- import {translate} from '@docusaurus/Translate';
23
- import IconExternalLink from '@theme/IconExternalLink';
24
- import DocSidebarItems from '@theme/DocSidebarItems';
25
- import styles from './styles.module.css';
26
- import useIsBrowser from '@docusaurus/useIsBrowser';
7
+ import React from 'react';
8
+ import DocSidebarItemCategory from '@theme/DocSidebarItem/Category';
9
+ import DocSidebarItemLink from '@theme/DocSidebarItem/Link';
10
+ import DocSidebarItemHtml from '@theme/DocSidebarItem/Html';
27
11
  export default function DocSidebarItem({item, ...props}) {
28
12
  switch (item.type) {
29
13
  case 'category':
@@ -36,230 +20,4 @@ export default function DocSidebarItem({item, ...props}) {
36
20
  default:
37
21
  return <DocSidebarItemLink item={item} {...props} />;
38
22
  }
39
- } // If we navigate to a category and it becomes active, it should automatically
40
- // expand itself
41
-
42
- function useAutoExpandActiveCategory({isActive, collapsed, setCollapsed}) {
43
- const wasActive = usePrevious(isActive);
44
- useEffect(() => {
45
- const justBecameActive = isActive && !wasActive;
46
-
47
- if (justBecameActive && collapsed) {
48
- setCollapsed(false);
49
- }
50
- }, [isActive, wasActive, collapsed, setCollapsed]);
51
- }
52
- /**
53
- * When a collapsible category has no link, we still link it to its first child
54
- * during SSR as a temporary fallback. This allows to be able to navigate inside
55
- * the category even when JS fails to load, is delayed or simply disabled
56
- * React hydration becomes an optional progressive enhancement
57
- * see https://github.com/facebookincubator/infima/issues/36#issuecomment-772543188
58
- * see https://github.com/facebook/docusaurus/issues/3030
59
- */
60
-
61
- function useCategoryHrefWithSSRFallback(item) {
62
- const isBrowser = useIsBrowser();
63
- return useMemo(() => {
64
- if (item.href) {
65
- return item.href;
66
- } // In these cases, it's not necessary to render a fallback
67
- // We skip the "findFirstCategoryLink" computation
68
-
69
- if (isBrowser || !item.collapsible) {
70
- return undefined;
71
- }
72
-
73
- return findFirstCategoryLink(item);
74
- }, [item, isBrowser]);
75
- }
76
-
77
- function DocSidebarItemCategory({
78
- item,
79
- onItemClick,
80
- activePath,
81
- level,
82
- index,
83
- ...props
84
- }) {
85
- const {items, label, collapsible, className, href} = item;
86
- const hrefWithSSRFallback = useCategoryHrefWithSSRFallback(item);
87
- const isActive = isActiveSidebarItem(item, activePath);
88
- const isCurrentPage = isSamePath(href, activePath);
89
- const {collapsed, setCollapsed} = useCollapsible({
90
- // active categories are always initialized as expanded
91
- // the default (item.collapsed) is only used for non-active categories
92
- initialState: () => {
93
- if (!collapsible) {
94
- return false;
95
- }
96
-
97
- return isActive ? false : item.collapsed;
98
- },
99
- });
100
- useAutoExpandActiveCategory({
101
- isActive,
102
- collapsed,
103
- setCollapsed,
104
- });
105
- const {expandedItem, setExpandedItem} = useDocSidebarItemsExpandedState();
106
-
107
- function updateCollapsed(toCollapsed = !collapsed) {
108
- setExpandedItem(toCollapsed ? null : index);
109
- setCollapsed(toCollapsed);
110
- }
111
-
112
- const {autoCollapseSidebarCategories} = useThemeConfig();
113
- useEffect(() => {
114
- if (
115
- collapsible &&
116
- expandedItem &&
117
- expandedItem !== index &&
118
- autoCollapseSidebarCategories
119
- ) {
120
- setCollapsed(true);
121
- }
122
- }, [
123
- collapsible,
124
- expandedItem,
125
- index,
126
- setCollapsed,
127
- autoCollapseSidebarCategories,
128
- ]);
129
- return (
130
- <li
131
- className={clsx(
132
- ThemeClassNames.docs.docSidebarItemCategory,
133
- ThemeClassNames.docs.docSidebarItemCategoryLevel(level),
134
- 'menu__list-item',
135
- {
136
- 'menu__list-item--collapsed': collapsed,
137
- },
138
- className,
139
- )}>
140
- <div
141
- className={clsx('menu__list-item-collapsible', {
142
- 'menu__list-item-collapsible--active': isCurrentPage,
143
- })}>
144
- <Link
145
- className={clsx('menu__link', {
146
- 'menu__link--sublist': collapsible,
147
- 'menu__link--sublist-caret': !href,
148
- 'menu__link--active': isActive,
149
- })}
150
- onClick={
151
- collapsible
152
- ? (e) => {
153
- onItemClick?.(item);
154
-
155
- if (href) {
156
- updateCollapsed(false);
157
- } else {
158
- e.preventDefault();
159
- updateCollapsed();
160
- }
161
- }
162
- : () => {
163
- onItemClick?.(item);
164
- }
165
- }
166
- aria-current={isCurrentPage ? 'page' : undefined}
167
- aria-expanded={collapsible ? !collapsed : undefined}
168
- href={collapsible ? hrefWithSSRFallback ?? '#' : hrefWithSSRFallback}
169
- {...props}>
170
- {label}
171
- </Link>
172
- {href && collapsible && (
173
- <button
174
- aria-label={translate(
175
- {
176
- id: 'theme.DocSidebarItem.toggleCollapsedCategoryAriaLabel',
177
- message: "Toggle the collapsible sidebar category '{label}'",
178
- description:
179
- 'The ARIA label to toggle the collapsible sidebar category',
180
- },
181
- {
182
- label,
183
- },
184
- )}
185
- type="button"
186
- className="clean-btn menu__caret"
187
- onClick={(e) => {
188
- e.preventDefault();
189
- updateCollapsed();
190
- }}
191
- />
192
- )}
193
- </div>
194
-
195
- <Collapsible lazy as="ul" className="menu__list" collapsed={collapsed}>
196
- <DocSidebarItems
197
- items={items}
198
- tabIndex={collapsed ? -1 : 0}
199
- onItemClick={onItemClick}
200
- activePath={activePath}
201
- level={level + 1}
202
- />
203
- </Collapsible>
204
- </li>
205
- );
206
- }
207
-
208
- function DocSidebarItemHtml({item, level, index}) {
209
- const {value, defaultStyle, className} = item;
210
- return (
211
- <li
212
- className={clsx(
213
- ThemeClassNames.docs.docSidebarItemLink,
214
- ThemeClassNames.docs.docSidebarItemLinkLevel(level),
215
- defaultStyle && `${styles.menuHtmlItem} menu__list-item`,
216
- className,
217
- )}
218
- key={index} // eslint-disable-next-line react/no-danger
219
- dangerouslySetInnerHTML={{
220
- __html: value,
221
- }}
222
- />
223
- );
224
- }
225
-
226
- function DocSidebarItemLink({
227
- item,
228
- onItemClick,
229
- activePath,
230
- level,
231
- index,
232
- ...props
233
- }) {
234
- const {href, label, className} = item;
235
- const isActive = isActiveSidebarItem(item, activePath);
236
- const isInternalLink = isInternalUrl(href);
237
- return (
238
- <li
239
- className={clsx(
240
- ThemeClassNames.docs.docSidebarItemLink,
241
- ThemeClassNames.docs.docSidebarItemLinkLevel(level),
242
- 'menu__list-item',
243
- className,
244
- )}
245
- key={label}>
246
- <Link
247
- className={clsx(
248
- 'menu__link',
249
- !isInternalLink && styles.menuExternalLink,
250
- {
251
- 'menu__link--active': isActive,
252
- },
253
- )}
254
- aria-current={isActive ? 'page' : undefined}
255
- to={href}
256
- {...(isInternalLink && {
257
- onClick: onItemClick ? () => onItemClick(item) : undefined,
258
- })}
259
- {...props}>
260
- {label}
261
- {!isInternalLink && <IconExternalLink />}
262
- </Link>
263
- </li>
264
- );
265
23
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/theme-classic",
3
- "version": "0.0.0-4777",
3
+ "version": "0.0.0-4782",
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-4777",
25
- "@docusaurus/plugin-content-blog": "0.0.0-4777",
26
- "@docusaurus/plugin-content-docs": "0.0.0-4777",
27
- "@docusaurus/plugin-content-pages": "0.0.0-4777",
28
- "@docusaurus/theme-common": "0.0.0-4777",
29
- "@docusaurus/theme-translations": "0.0.0-4777",
30
- "@docusaurus/utils": "0.0.0-4777",
31
- "@docusaurus/utils-common": "0.0.0-4777",
32
- "@docusaurus/utils-validation": "0.0.0-4777",
24
+ "@docusaurus/core": "0.0.0-4782",
25
+ "@docusaurus/plugin-content-blog": "0.0.0-4782",
26
+ "@docusaurus/plugin-content-docs": "0.0.0-4782",
27
+ "@docusaurus/plugin-content-pages": "0.0.0-4782",
28
+ "@docusaurus/theme-common": "0.0.0-4782",
29
+ "@docusaurus/theme-translations": "0.0.0-4782",
30
+ "@docusaurus/utils": "0.0.0-4782",
31
+ "@docusaurus/utils-common": "0.0.0-4782",
32
+ "@docusaurus/utils-validation": "0.0.0-4782",
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-4777",
46
- "@docusaurus/types": "0.0.0-4777",
45
+ "@docusaurus/module-type-aliases": "0.0.0-4782",
46
+ "@docusaurus/types": "0.0.0-4782",
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": "245a2a7fe952df111da8cccf7f3b8b8ec389d39e"
62
+ "gitHead": "97a8115b2a8f3bba73380e6316107b76cca69c54"
63
63
  }
@@ -0,0 +1,100 @@
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, useState, useCallback} from 'react';
9
+ import DocSidebar from '@theme/DocSidebar';
10
+ import IconArrow from '@theme/IconArrow';
11
+ import {translate} from '@docusaurus/Translate';
12
+ import {useLocation} from '@docusaurus/router';
13
+ import type {Props} from '@theme/DocPage/Layout/Aside';
14
+
15
+ import clsx from 'clsx';
16
+ import styles from './styles.module.css';
17
+
18
+ import {ThemeClassNames, useDocsSidebar} from '@docusaurus/theme-common';
19
+
20
+ function SidebarExpandButton({toggleSidebar}: {toggleSidebar: () => void}) {
21
+ return (
22
+ <div
23
+ className={styles.collapsedDocSidebar}
24
+ title={translate({
25
+ id: 'theme.docs.sidebar.expandButtonTitle',
26
+ message: 'Expand sidebar',
27
+ description:
28
+ 'The ARIA label and title attribute for expand button of doc sidebar',
29
+ })}
30
+ aria-label={translate({
31
+ id: 'theme.docs.sidebar.expandButtonAriaLabel',
32
+ message: 'Expand sidebar',
33
+ description:
34
+ 'The ARIA label and title attribute for expand button of doc sidebar',
35
+ })}
36
+ tabIndex={0}
37
+ role="button"
38
+ onKeyDown={toggleSidebar}
39
+ onClick={toggleSidebar}>
40
+ <IconArrow className={styles.expandSidebarButtonIcon} />
41
+ </div>
42
+ );
43
+ }
44
+
45
+ // Reset sidebar state when sidebar changes
46
+ // Use React key to unmount/remount the children
47
+ // See https://github.com/facebook/docusaurus/issues/3414
48
+ function ResetOnSidebarChange({children}: {children: ReactNode}) {
49
+ const sidebar = useDocsSidebar();
50
+ return (
51
+ <React.Fragment key={sidebar?.name ?? 'noSidebar'}>
52
+ {children}
53
+ </React.Fragment>
54
+ );
55
+ }
56
+
57
+ export default function DocPageLayoutAside({
58
+ sidebar,
59
+ hiddenSidebarContainer,
60
+ setHiddenSidebarContainer,
61
+ }: Props): JSX.Element {
62
+ const {pathname} = useLocation();
63
+
64
+ const [hiddenSidebar, setHiddenSidebar] = useState(false);
65
+ const toggleSidebar = useCallback(() => {
66
+ if (hiddenSidebar) {
67
+ setHiddenSidebar(false);
68
+ }
69
+ setHiddenSidebarContainer((value) => !value);
70
+ }, [setHiddenSidebarContainer, hiddenSidebar]);
71
+
72
+ return (
73
+ <aside
74
+ className={clsx(
75
+ ThemeClassNames.docs.docSidebarContainer,
76
+ styles.docSidebarContainer,
77
+ hiddenSidebarContainer && styles.docSidebarContainerHidden,
78
+ )}
79
+ onTransitionEnd={(e) => {
80
+ if (!e.currentTarget.classList.contains(styles.docSidebarContainer!)) {
81
+ return;
82
+ }
83
+
84
+ if (hiddenSidebarContainer) {
85
+ setHiddenSidebar(true);
86
+ }
87
+ }}>
88
+ <ResetOnSidebarChange>
89
+ <DocSidebar
90
+ sidebar={sidebar}
91
+ path={pathname}
92
+ onCollapse={toggleSidebar}
93
+ isHidden={hiddenSidebar}
94
+ />
95
+ </ResetOnSidebarChange>
96
+
97
+ {hiddenSidebar && <SidebarExpandButton toggleSidebar={toggleSidebar} />}
98
+ </aside>
99
+ );
100
+ }
@@ -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 React from 'react';
9
+
10
+ import {useDocsSidebar} from '@docusaurus/theme-common';
11
+
12
+ import clsx from 'clsx';
13
+ import styles from './styles.module.css';
14
+ import type {Props} from '@theme/DocPage/Layout/Main';
15
+
16
+ export default function DocPageLayoutMain({
17
+ hiddenSidebarContainer,
18
+ children,
19
+ }: Props): JSX.Element {
20
+ const sidebar = useDocsSidebar();
21
+ return (
22
+ <main
23
+ className={clsx(
24
+ styles.docMainContainer,
25
+ (hiddenSidebarContainer || !sidebar) && styles.docMainContainerEnhanced,
26
+ )}>
27
+ <div
28
+ className={clsx(
29
+ 'container padding-top--md padding-bottom--lg',
30
+ styles.docItemWrapper,
31
+ hiddenSidebarContainer && styles.docItemWrapperEnhanced,
32
+ )}>
33
+ {children}
34
+ </div>
35
+ </main>
36
+ );
37
+ }
@@ -0,0 +1,39 @@
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, {useState} from 'react';
9
+ import Layout from '@theme/Layout';
10
+ import BackToTopButton from '@theme/BackToTopButton';
11
+ import type {Props} from '@theme/DocPage/Layout';
12
+ import DocPageLayoutAside from '@theme/DocPage/Layout/Aside';
13
+ import DocPageLayoutMain from '@theme/DocPage/Layout/Main';
14
+
15
+ import styles from './styles.module.css';
16
+
17
+ import {useDocsSidebar} from '@docusaurus/theme-common';
18
+
19
+ export default function DocPageLayout({children}: Props): JSX.Element {
20
+ const sidebar = useDocsSidebar();
21
+ const [hiddenSidebarContainer, setHiddenSidebarContainer] = useState(false);
22
+ return (
23
+ <Layout>
24
+ <BackToTopButton />
25
+ <div className={styles.docPage}>
26
+ {sidebar && (
27
+ <DocPageLayoutAside
28
+ sidebar={sidebar.items}
29
+ hiddenSidebarContainer={hiddenSidebarContainer}
30
+ setHiddenSidebarContainer={setHiddenSidebarContainer}
31
+ />
32
+ )}
33
+ <DocPageLayoutMain hiddenSidebarContainer={hiddenSidebarContainer}>
34
+ {children}
35
+ </DocPageLayoutMain>
36
+ </div>
37
+ </Layout>
38
+ );
39
+ }