@docusaurus/theme-classic 2.0.0-beta.14 → 2.0.0-beta.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/README.md +1 -1
  2. package/lib/index.js +7 -16
  3. package/lib/theme-classic.d.ts +89 -182
  4. package/lib/validateThemeConfig.js +13 -1
  5. package/lib-next/theme/BackToTopButton/styles.module.css +1 -1
  6. package/lib-next/theme/BlogListPaginator/index.js +12 -12
  7. package/lib-next/theme/BlogPostAuthor/index.js +1 -1
  8. package/lib-next/theme/BlogPostAuthors/index.js +12 -2
  9. package/lib-next/theme/BlogPostAuthors/styles.module.css +10 -0
  10. package/lib-next/theme/BlogPostItem/index.js +12 -15
  11. package/lib-next/theme/BlogPostPage/index.js +10 -7
  12. package/lib-next/theme/BlogPostPaginator/index.js +11 -15
  13. package/lib-next/theme/BlogSidebar/styles.module.css +2 -0
  14. package/lib-next/theme/CodeBlock/index.js +44 -9
  15. package/lib-next/theme/CodeBlock/styles.module.css +12 -7
  16. package/lib-next/theme/DocCard/styles.module.css +3 -3
  17. package/lib-next/theme/DocCategoryGeneratedIndexPage/index.js +6 -3
  18. package/lib-next/theme/DocItem/index.js +9 -6
  19. package/lib-next/theme/DocItem/styles.module.css +2 -2
  20. package/lib-next/theme/DocPage/index.js +7 -3
  21. package/lib-next/theme/DocPage/styles.module.css +1 -0
  22. package/lib-next/theme/DocPaginator/index.js +26 -4
  23. package/lib-next/theme/DocSidebar/index.js +2 -2
  24. package/lib-next/theme/DocSidebar/styles.module.css +1 -0
  25. package/lib-next/theme/DocSidebarItem/index.js +43 -21
  26. package/lib-next/theme/DocSidebarItem/styles.module.css +1 -0
  27. package/lib-next/theme/DocSidebarItems/index.js +28 -0
  28. package/{src/theme/hooks/styles.css → lib-next/theme/DocSidebarItems/styles.module.css} +12 -2
  29. package/lib-next/theme/DocVersionBanner/index.js +4 -1
  30. package/lib-next/theme/Footer/styles.module.css +2 -1
  31. package/lib-next/theme/Heading/index.js +39 -42
  32. package/lib-next/theme/Heading/styles.css +1 -1
  33. package/lib-next/theme/Layout/index.js +1 -2
  34. package/lib-next/theme/LayoutHead/index.js +5 -9
  35. package/lib-next/theme/LayoutProviders/index.js +6 -6
  36. package/lib-next/theme/MDXComponents/index.js +18 -31
  37. package/lib-next/theme/MDXComponents/styles.css +4 -0
  38. package/lib-next/theme/MDXPage/index.js +3 -10
  39. package/lib-next/theme/Navbar/index.js +6 -6
  40. package/lib-next/theme/NavbarItem/DefaultNavbarItem.js +4 -66
  41. package/lib-next/theme/NavbarItem/DocNavbarItem.js +5 -2
  42. package/lib-next/theme/NavbarItem/DocSidebarNavbarItem.js +73 -0
  43. package/lib-next/theme/NavbarItem/DocsVersionDropdownNavbarItem.js +5 -3
  44. package/lib-next/theme/NavbarItem/DocsVersionNavbarItem.js +4 -1
  45. package/lib-next/theme/NavbarItem/DropdownNavbarItem.js +5 -5
  46. package/lib-next/theme/NavbarItem/NavbarNavLink.js +70 -0
  47. package/lib-next/theme/NavbarItem/index.js +1 -2
  48. package/lib-next/theme/{hooks/styles.css → NavbarItem/utils.js} +3 -4
  49. package/lib-next/theme/PaginatorNavLink/index.js +20 -0
  50. package/lib-next/theme/SkipToContent/index.js +1 -1
  51. package/lib-next/theme/SkipToContent/styles.module.css +7 -0
  52. package/lib-next/theme/TOCCollapsible/styles.module.css +2 -2
  53. package/lib-next/theme/Tabs/__tests__/index.test.js +8 -6
  54. package/lib-next/theme/Tabs/index.js +6 -3
  55. package/lib-next/theme/Tag/styles.module.css +4 -4
  56. package/lib-next/theme/ThemedImage/index.js +2 -2
  57. package/lib-next/theme/Toggle/styles.module.css +16 -15
  58. package/lib-next/theme/prism-include-languages.js +10 -3
  59. package/package.json +16 -17
  60. package/src/index.ts +10 -21
  61. package/src/theme/Admonition/index.tsx +1 -1
  62. package/src/theme/BackToTopButton/styles.module.css +1 -1
  63. package/src/theme/BlogListPaginator/index.tsx +12 -12
  64. package/src/theme/BlogPostAuthor/index.tsx +1 -1
  65. package/src/theme/BlogPostAuthors/index.tsx +12 -2
  66. package/src/theme/BlogPostAuthors/styles.module.css +10 -0
  67. package/src/theme/BlogPostItem/index.tsx +13 -15
  68. package/src/theme/BlogPostPage/index.tsx +10 -7
  69. package/src/theme/BlogPostPaginator/index.tsx +11 -15
  70. package/src/theme/BlogSidebar/styles.module.css +2 -0
  71. package/src/theme/CodeBlock/index.tsx +45 -10
  72. package/src/theme/CodeBlock/styles.module.css +12 -7
  73. package/src/theme/DocCard/index.tsx +2 -2
  74. package/src/theme/DocCard/styles.module.css +3 -3
  75. package/src/theme/DocCardList/index.tsx +1 -1
  76. package/src/theme/DocCategoryGeneratedIndexPage/index.tsx +7 -3
  77. package/src/theme/DocItem/index.tsx +9 -6
  78. package/src/theme/DocItem/styles.module.css +2 -2
  79. package/src/theme/DocItemFooter/index.tsx +1 -1
  80. package/src/theme/DocPage/index.tsx +8 -4
  81. package/src/theme/DocPage/styles.module.css +1 -0
  82. package/src/theme/DocPaginator/index.tsx +26 -4
  83. package/src/theme/DocSidebar/index.tsx +3 -3
  84. package/src/theme/DocSidebar/styles.module.css +1 -0
  85. package/src/theme/DocSidebarItem/index.tsx +34 -23
  86. package/src/theme/DocSidebarItem/styles.module.css +1 -0
  87. package/src/theme/DocSidebarItems/index.tsx +32 -0
  88. package/src/theme/{UserPreferencesContext.ts → DocSidebarItems/styles.module.css} +11 -3
  89. package/src/theme/DocVersionBanner/index.tsx +3 -3
  90. package/src/theme/Footer/index.tsx +4 -4
  91. package/src/theme/Footer/styles.module.css +2 -1
  92. package/src/theme/Heading/index.tsx +39 -46
  93. package/src/theme/Heading/styles.css +1 -1
  94. package/src/theme/Layout/index.tsx +1 -2
  95. package/src/theme/LayoutHead/index.tsx +4 -8
  96. package/src/theme/LayoutProviders/index.tsx +6 -6
  97. package/src/theme/MDXComponents/index.tsx +26 -37
  98. package/src/theme/MDXComponents/styles.css +4 -0
  99. package/src/theme/MDXPage/index.tsx +3 -11
  100. package/src/theme/Navbar/index.tsx +7 -7
  101. package/src/theme/NavbarItem/DefaultNavbarItem.tsx +6 -62
  102. package/src/theme/NavbarItem/DocNavbarItem.tsx +8 -5
  103. package/src/theme/NavbarItem/DocSidebarNavbarItem.tsx +84 -0
  104. package/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx +9 -6
  105. package/src/theme/NavbarItem/DocsVersionNavbarItem.tsx +2 -2
  106. package/src/theme/NavbarItem/DropdownNavbarItem.tsx +5 -5
  107. package/src/theme/NavbarItem/NavbarNavLink.tsx +68 -0
  108. package/src/theme/NavbarItem/index.tsx +3 -5
  109. package/{lib-next/theme/UserPreferencesContext.js → src/theme/NavbarItem/utils.ts} +4 -3
  110. package/src/theme/PaginatorNavLink/index.tsx +22 -0
  111. package/src/theme/SkipToContent/index.tsx +1 -1
  112. package/src/theme/SkipToContent/styles.module.css +7 -0
  113. package/src/theme/TOCCollapsible/styles.module.css +2 -2
  114. package/src/theme/TOCItems/index.tsx +2 -2
  115. package/src/theme/Tabs/index.tsx +7 -4
  116. package/src/theme/Tag/styles.module.css +4 -4
  117. package/src/theme/TagsListByLetter/index.tsx +1 -1
  118. package/src/theme/ThemedImage/index.tsx +2 -2
  119. package/src/theme/Toggle/index.tsx +1 -1
  120. package/src/theme/Toggle/styles.module.css +16 -15
  121. package/src/theme/prism-include-languages.ts +10 -3
  122. package/src/theme-classic.d.ts +89 -182
  123. package/src/translations.ts +2 -2
  124. package/src/validateThemeConfig.ts +16 -0
  125. package/lib-next/theme/DocPaginatorNavLink/index.js +0 -36
  126. package/lib-next/theme/ThemeContext.js +0 -9
  127. package/lib-next/theme/ThemeProvider/index.js +0 -28
  128. package/lib-next/theme/UserPreferencesProvider/index.js +0 -27
  129. package/lib-next/theme/hooks/useDocs.js +0 -10
  130. package/lib-next/theme/hooks/useHideableNavbar.js +0 -66
  131. package/lib-next/theme/hooks/useKeyboardNavigation.js +0 -35
  132. package/lib-next/theme/hooks/useLockBodyScroll.js +0 -18
  133. package/lib-next/theme/hooks/usePrismTheme.js +0 -20
  134. package/lib-next/theme/hooks/useTabGroupChoice.js +0 -39
  135. package/lib-next/theme/hooks/useTheme.js +0 -81
  136. package/lib-next/theme/hooks/useThemeContext.js +0 -22
  137. package/lib-next/theme/hooks/useUserPreferencesContext.js +0 -22
  138. package/lib-next/theme/hooks/useWindowSize.js +0 -59
  139. package/src/theme/DocPaginatorNavLink/index.tsx +0 -38
  140. package/src/theme/ThemeContext.ts +0 -15
  141. package/src/theme/ThemeProvider/index.tsx +0 -28
  142. package/src/theme/UserPreferencesProvider/index.tsx +0 -30
  143. package/src/theme/hooks/useDocs.ts +0 -11
  144. package/src/theme/hooks/useHideableNavbar.ts +0 -72
  145. package/src/theme/hooks/useKeyboardNavigation.ts +0 -39
  146. package/src/theme/hooks/useLockBodyScroll.ts +0 -20
  147. package/src/theme/hooks/usePrismTheme.ts +0 -22
  148. package/src/theme/hooks/useTabGroupChoice.ts +0 -46
  149. package/src/theme/hooks/useTheme.ts +0 -91
  150. package/src/theme/hooks/useThemeContext.ts +0 -23
  151. package/src/theme/hooks/useUserPreferencesContext.ts +0 -25
  152. package/src/theme/hooks/useWindowSize.ts +0 -69
@@ -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, {memo} from 'react';
8
+ import DocSidebarItem from '@theme/DocSidebarItem';
9
+ import {DocSidebarItemsExpandedStateProvider} from '@docusaurus/theme-common';
10
+
11
+ // TODO this item should probably not receive the "activePath" props
12
+ // TODO this triggers whole sidebar re-renders on navigation
13
+ function DocSidebarItems({items, ...props}) {
14
+ return (
15
+ <DocSidebarItemsExpandedStateProvider>
16
+ {items.map((item, index) => (
17
+ <DocSidebarItem
18
+ key={index} // sidebar is static, the index does not change
19
+ item={item}
20
+ index={index}
21
+ {...props}
22
+ />
23
+ ))}
24
+ </DocSidebarItemsExpandedStateProvider>
25
+ );
26
+ } // Optimize sidebar at each "level"
27
+
28
+ export default memo(DocSidebarItems);
@@ -5,6 +5,16 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- body:not(.navigation-with-keyboard) *:not(input):focus {
9
- outline: none;
8
+ @media (min-width: 997px) {
9
+ .menuLinkText {
10
+ cursor: initial;
11
+ }
12
+
13
+ .menuLinkText:hover {
14
+ background: none;
15
+ }
16
+
17
+ .menuLinkText.hasHref {
18
+ cursor: pointer;
19
+ }
10
20
  }
@@ -8,7 +8,10 @@ import React from 'react';
8
8
  import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
9
9
  import Link from '@docusaurus/Link';
10
10
  import Translate from '@docusaurus/Translate';
11
- import {useActivePlugin, useDocVersionSuggestions} from '@theme/hooks/useDocs';
11
+ import {
12
+ useActivePlugin,
13
+ useDocVersionSuggestions,
14
+ } from '@docusaurus/plugin-content-docs/client';
12
15
  import {
13
16
  ThemeClassNames,
14
17
  useDocsPreferredVersion,
@@ -7,7 +7,8 @@
7
7
 
8
8
  .footerLogoLink {
9
9
  opacity: 0.5;
10
- transition: opacity var(--ifm-transition-fast) var(--ifm-transition-timing-default);
10
+ transition: opacity var(--ifm-transition-fast)
11
+ var(--ifm-transition-timing-default);
11
12
  }
12
13
 
13
14
  .footerLogoLink:hover {
@@ -10,53 +10,50 @@ import {translate} from '@docusaurus/Translate';
10
10
  import {useThemeConfig} from '@docusaurus/theme-common';
11
11
  import './styles.css';
12
12
  import styles from './styles.module.css';
13
- // eslint-disable-next-line react/function-component-definition
14
- export const MainHeading = ({...props}) => (
15
- <header>
16
- <h1
17
- {...props}
18
- id={undefined} // h1 headings do not need an id because they don't appear in the TOC
19
- >
20
- {props.children}
21
- </h1>
22
- </header>
23
- );
24
13
 
25
- const createAnchorHeading =
26
- (Tag) =>
27
- ({id, ...props}) => {
28
- const {
29
- navbar: {hideOnScroll},
30
- } = useThemeConfig();
14
+ function AnchorHeading({as: As, id, ...props}) {
15
+ const {
16
+ navbar: {hideOnScroll},
17
+ } = useThemeConfig();
18
+
19
+ if (!id) {
20
+ return <As {...props} />;
21
+ }
31
22
 
32
- if (!id) {
33
- return <Tag {...props} />;
34
- }
23
+ return (
24
+ <As
25
+ {...props}
26
+ className={clsx('anchor', {
27
+ [styles.anchorWithHideOnScrollNavbar]: hideOnScroll,
28
+ [styles.anchorWithStickyNavbar]: !hideOnScroll,
29
+ })}
30
+ id={id}>
31
+ {props.children}
32
+ <a
33
+ className="hash-link"
34
+ href={`#${id}`}
35
+ title={translate({
36
+ id: 'theme.common.headingLinkTitle',
37
+ message: 'Direct link to heading',
38
+ description: 'Title for link to heading',
39
+ })}>
40
+ &#8203;
41
+ </a>
42
+ </As>
43
+ );
44
+ }
35
45
 
46
+ export default function Heading({as, ...props}) {
47
+ if (as === 'h1') {
36
48
  return (
37
- <Tag
49
+ <h1
38
50
  {...props}
39
- className={clsx('anchor', {
40
- [styles.anchorWithHideOnScrollNavbar]: hideOnScroll,
41
- [styles.anchorWithStickyNavbar]: !hideOnScroll,
42
- })}
43
- id={id}>
51
+ id={undefined} // h1 headings do not need an id because they don't appear in the TOC
52
+ >
44
53
  {props.children}
45
- <a
46
- className="hash-link"
47
- href={`#${id}`}
48
- title={translate({
49
- id: 'theme.common.headingLinkTitle',
50
- message: 'Direct link to heading',
51
- description: 'Title for link to heading',
52
- })}>
53
- &#8203;
54
- </a>
55
- </Tag>
54
+ </h1>
56
55
  );
57
- };
58
-
59
- const Heading = (headingType) =>
60
- headingType === 'h1' ? MainHeading : createAnchorHeading(headingType);
56
+ }
61
57
 
62
- export default Heading;
58
+ return <AnchorHeading as={as} {...props} />;
59
+ }
@@ -12,7 +12,7 @@
12
12
  user-select: none;
13
13
  }
14
14
 
15
- .hash-link:before {
15
+ .hash-link::before {
16
16
  content: '#';
17
17
  }
18
18
 
@@ -13,8 +13,7 @@ import Navbar from '@theme/Navbar';
13
13
  import Footer from '@theme/Footer';
14
14
  import LayoutProviders from '@theme/LayoutProviders';
15
15
  import LayoutHead from '@theme/LayoutHead';
16
- import useKeyboardNavigation from '@theme/hooks/useKeyboardNavigation';
17
- import {ThemeClassNames} from '@docusaurus/theme-common';
16
+ import {ThemeClassNames, useKeyboardNavigation} from '@docusaurus/theme-common';
18
17
  import ErrorPageContent from '@theme/ErrorPageContent';
19
18
  import './styles.css';
20
19
 
@@ -22,14 +22,14 @@ import {useLocation} from '@docusaurus/router'; // Useful for SEO
22
22
 
23
23
  function AlternateLangHeaders() {
24
24
  const {
25
- i18n: {defaultLocale, locales},
25
+ i18n: {defaultLocale, localeConfigs},
26
26
  } = useDocusaurusContext();
27
27
  const alternatePageUtils = useAlternatePageUtils(); // Note: it is fine to use both "x-default" and "en" to target the same url
28
28
  // See https://www.searchviu.com/en/multiple-hreflang-tags-one-url/
29
29
 
30
30
  return (
31
31
  <Head>
32
- {locales.map((locale) => (
32
+ {Object.entries(localeConfigs).map(([locale, {htmlLang}]) => (
33
33
  <link
34
34
  key={locale}
35
35
  rel="alternate"
@@ -37,7 +37,7 @@ function AlternateLangHeaders() {
37
37
  locale,
38
38
  fullyQualified: true,
39
39
  })}
40
- hrefLang={locale}
40
+ hrefLang={htmlLang}
41
41
  />
42
42
  ))}
43
43
  <link
@@ -84,12 +84,8 @@ export default function LayoutHead(props) {
84
84
  const {metadata, image: defaultImage} = useThemeConfig();
85
85
  const {title, description, image, keywords, searchMetadata} = props;
86
86
  const faviconUrl = useBaseUrl(favicon);
87
- const pageTitle = useTitleFormatter(title); // See https://github.com/facebook/docusaurus/issues/3317#issuecomment-754661855
88
- // const htmlLang = currentLocale.split('-')[0];
89
-
90
- const htmlLang = currentLocale; // should we allow the user to override htmlLang with localeConfig?
91
-
92
- const htmlDir = localeConfigs[currentLocale].direction;
87
+ const pageTitle = useTitleFormatter(title);
88
+ const {htmlLang, direction: htmlDir} = localeConfigs[currentLocale];
93
89
  return (
94
90
  <>
95
91
  <Head>
@@ -5,9 +5,9 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  import React from 'react';
8
- import ThemeProvider from '@theme/ThemeProvider';
9
- import UserPreferencesProvider from '@theme/UserPreferencesProvider';
10
8
  import {
9
+ ColorModeProvider,
10
+ TabGroupChoiceProvider,
11
11
  AnnouncementBarProvider,
12
12
  DocsPreferredVersionContextProvider,
13
13
  MobileSecondaryMenuProvider,
@@ -15,9 +15,9 @@ import {
15
15
  } from '@docusaurus/theme-common';
16
16
  export default function LayoutProviders({children}) {
17
17
  return (
18
- <ThemeProvider>
18
+ <ColorModeProvider>
19
19
  <AnnouncementBarProvider>
20
- <UserPreferencesProvider>
20
+ <TabGroupChoiceProvider>
21
21
  <ScrollControllerProvider>
22
22
  <DocsPreferredVersionContextProvider>
23
23
  <MobileSecondaryMenuProvider>
@@ -25,8 +25,8 @@ export default function LayoutProviders({children}) {
25
25
  </MobileSecondaryMenuProvider>
26
26
  </DocsPreferredVersionContextProvider>
27
27
  </ScrollControllerProvider>
28
- </UserPreferencesProvider>
28
+ </TabGroupChoiceProvider>
29
29
  </AnnouncementBarProvider>
30
- </ThemeProvider>
30
+ </ColorModeProvider>
31
31
  );
32
32
  }
@@ -30,35 +30,22 @@ const MDXComponents = {
30
30
  return <Head {...props}>{unwrappedChildren}</Head>;
31
31
  },
32
32
  code: (props) => {
33
- const {children} = props; // For retrocompatibility purposes (pretty rare use case)
34
- // See https://github.com/facebook/docusaurus/pull/1584
35
-
36
- if (isValidElement(children)) {
37
- return children;
38
- }
39
-
40
- return !children.includes('\n') ? (
41
- <code {...props} />
42
- ) : (
43
- <CodeBlock {...props} />
33
+ const shouldBeInline = React.Children.toArray(props.children).every(
34
+ (el) => typeof el === 'string' && !el.includes('\n'),
44
35
  );
36
+ return shouldBeInline ? <code {...props} /> : <CodeBlock {...props} />;
45
37
  },
46
38
  a: (props) => <Link {...props} />,
47
- pre: (props) => {
48
- const {children} = props; // See comment for `code` above
49
-
50
- if (isValidElement(children) && isValidElement(children?.props?.children)) {
51
- return children.props.children;
52
- }
53
-
54
- return (
55
- <CodeBlock
56
- {...(isValidElement(children) ? children?.props : {...props})}
57
- />
58
- );
59
- },
39
+ pre: (props) => (
40
+ <CodeBlock // If this pre is created by a ``` fenced codeblock, unwrap the children
41
+ {...(isValidElement(props.children) &&
42
+ props.children.props.originalType === 'code'
43
+ ? props.children?.props
44
+ : {...props})}
45
+ />
46
+ ),
60
47
  details: (props) => {
61
- const items = React.Children.toArray(props.children); // Split summary item from the rest to pass it as a separate prop to the Detais theme component
48
+ const items = React.Children.toArray(props.children); // Split summary item from the rest to pass it as a separate prop to the Details theme component
62
49
 
63
50
  const summary = items.find((item) => item?.props?.mdxType === 'summary');
64
51
  const children = <>{items.filter((item) => item !== summary)}</>;
@@ -68,11 +55,11 @@ const MDXComponents = {
68
55
  </Details>
69
56
  );
70
57
  },
71
- h1: Heading('h1'),
72
- h2: Heading('h2'),
73
- h3: Heading('h3'),
74
- h4: Heading('h4'),
75
- h5: Heading('h5'),
76
- h6: Heading('h6'),
58
+ h1: (props) => <Heading as="h1" {...props} />,
59
+ h2: (props) => <Heading as="h2" {...props} />,
60
+ h3: (props) => <Heading as="h3" {...props} />,
61
+ h4: (props) => <Heading as="h4" {...props} />,
62
+ h5: (props) => <Heading as="h5" {...props} />,
63
+ h6: (props) => <Heading as="h6" {...props} />,
77
64
  };
78
65
  export default MDXComponents;
@@ -9,3 +9,7 @@ ul.contains-task-list {
9
9
  padding-left: 0;
10
10
  list-style: none;
11
11
  }
12
+
13
+ img {
14
+ height: auto;
15
+ }
@@ -16,17 +16,10 @@ import styles from './styles.module.css';
16
16
  function MDXPage(props) {
17
17
  const {content: MDXPageContent} = props;
18
18
  const {
19
- // TODO this frontmatter is not validated/normalized, it's the raw user-provided one. We should expose normalized one too!
20
- frontMatter,
21
- metadata,
19
+ metadata: {title, description, permalink, frontMatter},
22
20
  } = MDXPageContent;
23
- const {
24
- title,
25
- description,
26
- wrapperClassName,
27
- hide_table_of_contents: hideTableOfContents,
28
- } = frontMatter;
29
- const {permalink} = metadata;
21
+ const {wrapperClassName, hide_table_of_contents: hideTableOfContents} =
22
+ frontMatter;
30
23
  return (
31
24
  <Layout
32
25
  title={title}
@@ -9,17 +9,17 @@ import clsx from 'clsx';
9
9
  import Translate from '@docusaurus/Translate';
10
10
  import SearchBar from '@theme/SearchBar';
11
11
  import Toggle from '@theme/Toggle';
12
- import useThemeContext from '@theme/hooks/useThemeContext';
13
12
  import {
14
13
  useThemeConfig,
15
14
  useMobileSecondaryMenuRenderer,
16
15
  usePrevious,
17
16
  useHistoryPopHandler,
17
+ useHideableNavbar,
18
+ useLockBodyScroll,
19
+ useWindowSize,
20
+ useColorMode,
18
21
  } from '@docusaurus/theme-common';
19
- import useHideableNavbar from '@theme/hooks/useHideableNavbar';
20
- import useLockBodyScroll from '@theme/hooks/useLockBodyScroll';
21
- import useWindowSize from '@theme/hooks/useWindowSize';
22
- import {useActivePlugin} from '@theme/hooks/useDocs';
22
+ import {useActivePlugin} from '@docusaurus/plugin-content-docs/client';
23
23
  import NavbarItem from '@theme/NavbarItem';
24
24
  import Logo from '@theme/Logo';
25
25
  import IconMenu from '@theme/IconMenu';
@@ -84,7 +84,7 @@ function useColorModeToggle() {
84
84
  const {
85
85
  colorMode: {disableSwitch},
86
86
  } = useThemeConfig();
87
- const {isDarkTheme, setLightTheme, setDarkTheme} = useThemeContext();
87
+ const {isDarkTheme, setLightTheme, setDarkTheme} = useColorMode();
88
88
  const toggle = useCallback(
89
89
  (e) => (e.target.checked ? setDarkTheme() : setLightTheme()),
90
90
  [setLightTheme, setDarkTheme],
@@ -6,70 +6,8 @@
6
6
  */
7
7
  import React from 'react';
8
8
  import clsx from 'clsx';
9
- import Link from '@docusaurus/Link';
10
- import useBaseUrl from '@docusaurus/useBaseUrl';
11
- import IconExternalLink from '@theme/IconExternalLink';
12
- import isInternalUrl from '@docusaurus/isInternalUrl';
13
- import {isRegexpStringMatch} from '@docusaurus/theme-common';
14
- import {getInfimaActiveClassName} from './index';
15
- const dropdownLinkActiveClass = 'dropdown__link--active';
16
- export function NavLink({
17
- activeBasePath,
18
- activeBaseRegex,
19
- to,
20
- href,
21
- label,
22
- activeClassName = '',
23
- prependBaseUrlToHref,
24
- ...props
25
- }) {
26
- // TODO all this seems hacky
27
- // {to: 'version'} should probably be forbidden, in favor of {to: '/version'}
28
- const toUrl = useBaseUrl(to);
29
- const activeBaseUrl = useBaseUrl(activeBasePath);
30
- const normalizedHref = useBaseUrl(href, {
31
- forcePrependBaseUrl: true,
32
- });
33
- const isExternalLink = label && href && !isInternalUrl(href);
34
- const isDropdownLink = activeClassName === dropdownLinkActiveClass;
35
- return (
36
- <Link
37
- {...(href
38
- ? {
39
- href: prependBaseUrlToHref ? normalizedHref : href,
40
- }
41
- : {
42
- isNavLink: true,
43
- activeClassName: !props.className?.includes(activeClassName)
44
- ? activeClassName
45
- : '',
46
- to: toUrl,
47
- ...(activeBasePath || activeBaseRegex
48
- ? {
49
- isActive: (_match, location) =>
50
- activeBaseRegex
51
- ? isRegexpStringMatch(activeBaseRegex, location.pathname)
52
- : location.pathname.startsWith(activeBaseUrl),
53
- }
54
- : null),
55
- })}
56
- {...props}>
57
- {isExternalLink ? (
58
- <span>
59
- {label}
60
- <IconExternalLink
61
- {...(isDropdownLink && {
62
- width: 12,
63
- height: 12,
64
- })}
65
- />
66
- </span>
67
- ) : (
68
- label
69
- )}
70
- </Link>
71
- );
72
- }
9
+ import NavbarNavLink from '@theme/NavbarItem/NavbarNavLink';
10
+ import {getInfimaActiveClassName} from '@theme/NavbarItem/utils';
73
11
 
74
12
  function DefaultNavbarItemDesktop({
75
13
  className,
@@ -77,7 +15,7 @@ function DefaultNavbarItemDesktop({
77
15
  ...props
78
16
  }) {
79
17
  const element = (
80
- <NavLink
18
+ <NavbarNavLink
81
19
  className={clsx(
82
20
  isDropdownItem ? 'dropdown__link' : 'navbar__item navbar__link',
83
21
  className,
@@ -100,7 +38,7 @@ function DefaultNavbarItemMobile({
100
38
  }) {
101
39
  return (
102
40
  <li className="menu__list-item">
103
- <NavLink className={clsx('menu__link', className)} {...props} />
41
+ <NavbarNavLink className={clsx('menu__link', className)} {...props} />
104
42
  </li>
105
43
  );
106
44
  }
@@ -6,9 +6,12 @@
6
6
  */
7
7
  import React from 'react';
8
8
  import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
9
- import {useLatestVersion, useActiveDocContext} from '@theme/hooks/useDocs';
9
+ import {
10
+ useLatestVersion,
11
+ useActiveDocContext,
12
+ } from '@docusaurus/plugin-content-docs/client';
10
13
  import clsx from 'clsx';
11
- import {getInfimaActiveClassName} from './index';
14
+ import {getInfimaActiveClassName} from '@theme/NavbarItem/utils';
12
15
  import {useDocsPreferredVersion, uniq} from '@docusaurus/theme-common';
13
16
 
14
17
  function getDocInVersions(versions, docId) {
@@ -0,0 +1,73 @@
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 DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
9
+ import {
10
+ useLatestVersion,
11
+ useActiveDocContext,
12
+ } from '@docusaurus/plugin-content-docs/client';
13
+ import clsx from 'clsx';
14
+ import {getInfimaActiveClassName} from '@theme/NavbarItem/utils';
15
+ import {useDocsPreferredVersion, uniq} from '@docusaurus/theme-common';
16
+
17
+ function getSidebarLink(versions, sidebarId) {
18
+ const allSidebars = versions
19
+ .flatMap((version) => {
20
+ if (version.sidebars) {
21
+ return Object.entries(version.sidebars);
22
+ }
23
+
24
+ return undefined;
25
+ })
26
+ .filter((sidebarItem) => !!sidebarItem);
27
+ const sidebarEntry = allSidebars.find((sidebar) => sidebar[0] === sidebarId);
28
+
29
+ if (!sidebarEntry) {
30
+ throw new Error(`DocSidebarNavbarItem: couldn't find any sidebar with id "${sidebarId}" in version${
31
+ versions.length ? 's' : ''
32
+ } ${versions.map((version) => version.name).join(', ')}".
33
+ Available sidebar ids are:
34
+ - ${Object.keys(allSidebars).join('\n- ')}`);
35
+ }
36
+
37
+ if (!sidebarEntry[1].link) {
38
+ throw new Error(
39
+ `DocSidebarNavbarItem: couldn't find any document for sidebar with id "${sidebarId}"`,
40
+ );
41
+ }
42
+
43
+ return sidebarEntry[1].link;
44
+ }
45
+
46
+ export default function DocSidebarNavbarItem({
47
+ sidebarId,
48
+ label,
49
+ docsPluginId,
50
+ ...props
51
+ }) {
52
+ const {activeVersion, activeDoc} = useActiveDocContext(docsPluginId);
53
+ const {preferredVersion} = useDocsPreferredVersion(docsPluginId);
54
+ const latestVersion = useLatestVersion(docsPluginId); // Versions used to look for the doc to link to, ordered + no duplicate
55
+
56
+ const versions = uniq(
57
+ [activeVersion, preferredVersion, latestVersion].filter(Boolean),
58
+ );
59
+ const sidebarLink = getSidebarLink(versions, sidebarId);
60
+ const activeDocInfimaClassName = getInfimaActiveClassName(props.mobile);
61
+ return (
62
+ <DefaultNavbarItem
63
+ exact
64
+ {...props}
65
+ className={clsx(props.className, {
66
+ [activeDocInfimaClassName]: activeDoc?.sidebar === sidebarId,
67
+ })}
68
+ activeClassName={activeDocInfimaClassName}
69
+ label={label ?? sidebarLink.label}
70
+ to={sidebarLink.path}
71
+ />
72
+ );
73
+ }
@@ -11,7 +11,7 @@ import {
11
11
  useVersions,
12
12
  useLatestVersion,
13
13
  useActiveDocContext,
14
- } from '@theme/hooks/useDocs';
14
+ } from '@docusaurus/plugin-content-docs/client';
15
15
  import {useDocsPreferredVersion} from '@docusaurus/theme-common';
16
16
  import {translate} from '@docusaurus/Translate';
17
17
 
@@ -57,7 +57,7 @@ export default function DocsVersionDropdownNavbarItem({
57
57
  activeDocContext.activeVersion ?? preferredVersion ?? latestVersion; // Mobile dropdown is handled a bit differently
58
58
 
59
59
  const dropdownLabel =
60
- mobile && items
60
+ mobile && items.length > 1
61
61
  ? translate({
62
62
  id: 'theme.navbar.mobileVersionsDropdown.label',
63
63
  message: 'Versions',
@@ -66,7 +66,9 @@ export default function DocsVersionDropdownNavbarItem({
66
66
  })
67
67
  : dropdownVersion.label;
68
68
  const dropdownTo =
69
- mobile && items ? undefined : getVersionMainDoc(dropdownVersion).path; // We don't want to render a version dropdown with 0 or 1 item
69
+ mobile && items.length > 1
70
+ ? undefined
71
+ : getVersionMainDoc(dropdownVersion).path; // We don't want to render a version dropdown with 0 or 1 item
70
72
  // If we build the site with a single docs version (onlyIncludeVersions: ['1.0.0'])
71
73
  // We'd rather render a button instead of a dropdown
72
74
 
@@ -6,7 +6,10 @@
6
6
  */
7
7
  import React from 'react';
8
8
  import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
9
- import {useActiveVersion, useLatestVersion} from '@theme/hooks/useDocs';
9
+ import {
10
+ useActiveVersion,
11
+ useLatestVersion,
12
+ } from '@docusaurus/plugin-content-docs/client';
10
13
  import {useDocsPreferredVersion} from '@docusaurus/theme-common';
11
14
 
12
15
  const getVersionMainDoc = (version) =>
@@ -13,7 +13,7 @@ import {
13
13
  isRegexpStringMatch,
14
14
  useLocalPathname,
15
15
  } from '@docusaurus/theme-common';
16
- import {NavLink} from '@theme/NavbarItem/DefaultNavbarItem';
16
+ import NavbarNavLink from '@theme/NavbarItem/NavbarNavLink';
17
17
  import NavbarItem from '@theme/NavbarItem';
18
18
  const dropdownLinkActiveClass = 'dropdown__link--active';
19
19
 
@@ -63,7 +63,7 @@ function DropdownNavbarItemDesktop({items, position, className, ...props}) {
63
63
  'dropdown--right': position === 'right',
64
64
  'dropdown--show': showDropdown,
65
65
  })}>
66
- <NavLink
66
+ <NavbarNavLink
67
67
  href={props.to ? undefined : '#'}
68
68
  className={clsx('navbar__link', className)}
69
69
  {...props}
@@ -75,7 +75,7 @@ function DropdownNavbarItemDesktop({items, position, className, ...props}) {
75
75
  }
76
76
  }}>
77
77
  {props.children ?? props.label}
78
- </NavLink>
78
+ </NavbarNavLink>
79
79
  <ul className="dropdown__menu">
80
80
  {items.map((childItemProps, i) => (
81
81
  <NavbarItem
@@ -124,7 +124,7 @@ function DropdownNavbarItemMobile({
124
124
  className={clsx('menu__list-item', {
125
125
  'menu__list-item--collapsed': collapsed,
126
126
  })}>
127
- <NavLink
127
+ <NavbarNavLink
128
128
  role="button"
129
129
  className={clsx('menu__link menu__link--sublist', className)}
130
130
  {...props}
@@ -133,7 +133,7 @@ function DropdownNavbarItemMobile({
133
133
  toggleCollapsed();
134
134
  }}>
135
135
  {props.children ?? props.label}
136
- </NavLink>
136
+ </NavbarNavLink>
137
137
  <Collapsible lazy as="ul" className="menu__list" collapsed={collapsed}>
138
138
  {items.map((childItemProps, i) => (
139
139
  <NavbarItem