@docusaurus/theme-common 2.0.0-beta.16 → 2.0.0-beta.19
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/Details.d.ts +14 -0
- package/lib/components/Collapsible/index.d.ts +32 -4
- package/lib/components/Collapsible/index.d.ts.map +1 -1
- package/lib/components/Collapsible/index.js +18 -10
- package/lib/components/Collapsible/index.js.map +1 -1
- package/lib/components/Details/index.d.ts +6 -1
- package/lib/components/Details/index.d.ts.map +1 -1
- package/lib/components/Details/index.js +11 -6
- package/lib/components/Details/index.js.map +1 -1
- package/lib/components/Details/styles.module.css +4 -0
- package/lib/{utils/announcementBarUtils.d.ts → contexts/announcementBar.d.ts} +7 -3
- package/lib/contexts/announcementBar.d.ts.map +1 -0
- package/lib/{utils/announcementBarUtils.js → contexts/announcementBar.js} +15 -14
- package/lib/contexts/announcementBar.js.map +1 -0
- package/lib/contexts/colorMode.d.ts +27 -0
- package/lib/contexts/colorMode.d.ts.map +1 -0
- package/lib/contexts/colorMode.js +132 -0
- package/lib/contexts/colorMode.js.map +1 -0
- package/lib/contexts/docSidebarItemsExpandedState.d.ts +31 -0
- package/lib/contexts/docSidebarItemsExpandedState.d.ts.map +1 -0
- package/lib/{utils → contexts}/docSidebarItemsExpandedState.js +10 -4
- package/lib/contexts/docSidebarItemsExpandedState.js.map +1 -0
- package/lib/contexts/docsPreferredVersion.d.ts +31 -0
- package/lib/contexts/docsPreferredVersion.d.ts.map +1 -0
- package/lib/contexts/docsPreferredVersion.js +128 -0
- package/lib/contexts/docsPreferredVersion.js.map +1 -0
- package/lib/contexts/docsSidebar.d.ts +26 -0
- package/lib/contexts/docsSidebar.d.ts.map +1 -0
- package/lib/contexts/docsSidebar.js +30 -0
- package/lib/contexts/docsSidebar.js.map +1 -0
- package/lib/contexts/docsVersion.d.ts +20 -0
- package/lib/contexts/docsVersion.d.ts.map +1 -0
- package/lib/contexts/docsVersion.js +26 -0
- package/lib/contexts/docsVersion.js.map +1 -0
- package/lib/contexts/navbarMobileSidebar.d.ts +31 -0
- package/lib/contexts/navbarMobileSidebar.d.ts.map +1 -0
- package/lib/contexts/navbarMobileSidebar.js +56 -0
- package/lib/contexts/navbarMobileSidebar.js.map +1 -0
- package/lib/contexts/navbarSecondaryMenu/content.d.ts +37 -0
- package/lib/contexts/navbarSecondaryMenu/content.d.ts.map +1 -0
- package/lib/contexts/navbarSecondaryMenu/content.js +56 -0
- package/lib/contexts/navbarSecondaryMenu/content.js.map +1 -0
- package/lib/contexts/navbarSecondaryMenu/display.d.ts +24 -0
- package/lib/contexts/navbarSecondaryMenu/display.d.ts.map +1 -0
- package/lib/contexts/navbarSecondaryMenu/display.js +62 -0
- package/lib/contexts/navbarSecondaryMenu/display.js.map +1 -0
- package/lib/{utils/tabGroupChoiceUtils.d.ts → contexts/tabGroupChoice.d.ts} +5 -3
- package/lib/contexts/tabGroupChoice.d.ts.map +1 -0
- package/lib/{utils/tabGroupChoiceUtils.js → contexts/tabGroupChoice.js} +15 -20
- package/lib/contexts/tabGroupChoice.js.map +1 -0
- package/lib/hooks/useBackToTopButton.d.ts +27 -0
- package/lib/hooks/useBackToTopButton.d.ts.map +1 -0
- package/lib/hooks/useBackToTopButton.js +50 -0
- package/lib/hooks/useBackToTopButton.js.map +1 -0
- package/lib/hooks/useCodeWordWrap.d.ts +14 -0
- package/lib/hooks/useCodeWordWrap.d.ts.map +1 -0
- package/lib/hooks/useCodeWordWrap.js +41 -0
- package/lib/hooks/useCodeWordWrap.js.map +1 -0
- package/lib/hooks/useHideableNavbar.d.ts +7 -3
- package/lib/hooks/useHideableNavbar.d.ts.map +1 -1
- package/lib/hooks/useHideableNavbar.js +10 -9
- package/lib/hooks/useHideableNavbar.js.map +1 -1
- package/lib/hooks/useKeyboardNavigation.d.ts +11 -1
- package/lib/hooks/useKeyboardNavigation.d.ts.map +1 -1
- package/lib/hooks/useKeyboardNavigation.js +11 -3
- package/lib/hooks/useKeyboardNavigation.js.map +1 -1
- package/lib/hooks/useLockBodyScroll.d.ts +5 -1
- package/lib/hooks/useLockBodyScroll.d.ts.map +1 -1
- package/lib/hooks/useLockBodyScroll.js +5 -1
- package/lib/hooks/useLockBodyScroll.js.map +1 -1
- package/lib/hooks/usePrismTheme.d.ts +6 -2
- package/lib/hooks/usePrismTheme.d.ts.map +1 -1
- package/lib/hooks/usePrismTheme.js +9 -6
- package/lib/hooks/usePrismTheme.js.map +1 -1
- package/lib/hooks/useSearchPage.d.ts +15 -4
- package/lib/hooks/useSearchPage.d.ts.map +1 -1
- package/lib/hooks/useSearchPage.js +4 -4
- package/lib/hooks/useSearchPage.js.map +1 -1
- package/lib/hooks/useSkipToContent.d.ts +25 -0
- package/lib/hooks/useSkipToContent.d.ts.map +1 -0
- package/lib/hooks/useSkipToContent.js +35 -0
- package/lib/hooks/useSkipToContent.js.map +1 -0
- package/lib/hooks/useTOCHighlight.d.ts +25 -0
- package/lib/hooks/useTOCHighlight.d.ts.map +1 -0
- package/lib/{utils → hooks}/useTOCHighlight.js +18 -16
- package/lib/hooks/useTOCHighlight.js.map +1 -0
- package/lib/hooks/useWindowSize.d.ts +14 -1
- package/lib/hooks/useWindowSize.d.ts.map +1 -1
- package/lib/hooks/useWindowSize.js +14 -11
- package/lib/hooks/useWindowSize.js.map +1 -1
- package/lib/index.d.ts +31 -32
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +31 -26
- package/lib/index.js.map +1 -1
- package/lib/utils/ThemeClassNames.d.ts +7 -0
- package/lib/utils/ThemeClassNames.d.ts.map +1 -1
- package/lib/utils/ThemeClassNames.js +7 -4
- package/lib/utils/ThemeClassNames.js.map +1 -1
- package/lib/utils/codeBlockUtils.d.ts +57 -4
- package/lib/utils/codeBlockUtils.d.ts.map +1 -1
- package/lib/utils/codeBlockUtils.js +111 -80
- package/lib/utils/codeBlockUtils.js.map +1 -1
- package/lib/utils/docsUtils.d.ts +83 -18
- package/lib/utils/docsUtils.d.ts.map +1 -1
- package/lib/utils/docsUtils.js +143 -62
- package/lib/utils/docsUtils.js.map +1 -1
- package/lib/utils/footerUtils.d.ts +13 -0
- package/lib/utils/footerUtils.d.ts.map +1 -0
- package/lib/utils/footerUtils.js +14 -0
- package/lib/utils/footerUtils.js.map +1 -0
- package/lib/utils/generalUtils.d.ts +4 -1
- package/lib/utils/generalUtils.d.ts.map +1 -1
- package/lib/utils/generalUtils.js +6 -3
- package/lib/utils/generalUtils.js.map +1 -1
- package/lib/utils/historyUtils.d.ts +1 -7
- package/lib/utils/historyUtils.d.ts.map +1 -1
- package/lib/utils/historyUtils.js +10 -13
- package/lib/utils/historyUtils.js.map +1 -1
- package/lib/utils/jsUtils.d.ts +1 -1
- package/lib/utils/jsUtils.js +1 -1
- package/lib/utils/metadataUtils.d.ts +38 -0
- package/lib/utils/metadataUtils.d.ts.map +1 -0
- package/lib/utils/metadataUtils.js +61 -0
- package/lib/utils/metadataUtils.js.map +1 -0
- package/lib/utils/navbarUtils.d.ts +21 -0
- package/lib/utils/navbarUtils.d.ts.map +1 -0
- package/lib/utils/navbarUtils.js +32 -0
- package/lib/utils/navbarUtils.js.map +1 -0
- package/lib/utils/reactUtils.d.ts +21 -7
- package/lib/utils/reactUtils.d.ts.map +1 -1
- package/lib/utils/reactUtils.js +34 -6
- package/lib/utils/reactUtils.js.map +1 -1
- package/lib/utils/regexpUtils.d.ts +2 -1
- package/lib/utils/regexpUtils.d.ts.map +1 -1
- package/lib/utils/regexpUtils.js +2 -1
- package/lib/utils/regexpUtils.js.map +1 -1
- package/lib/utils/routesUtils.d.ts +19 -4
- package/lib/utils/routesUtils.d.ts.map +1 -1
- package/lib/utils/routesUtils.js +40 -19
- package/lib/utils/routesUtils.js.map +1 -1
- package/lib/utils/scrollUtils.d.ts +55 -25
- package/lib/utils/scrollUtils.d.ts.map +1 -1
- package/lib/utils/scrollUtils.js +85 -21
- package/lib/utils/scrollUtils.js.map +1 -1
- package/lib/utils/searchUtils.d.ts +12 -0
- package/lib/utils/searchUtils.d.ts.map +1 -1
- package/lib/utils/searchUtils.js +36 -0
- package/lib/utils/searchUtils.js.map +1 -1
- package/lib/utils/storageUtils.d.ts +12 -9
- package/lib/utils/storageUtils.d.ts.map +1 -1
- package/lib/utils/storageUtils.js +21 -13
- package/lib/utils/storageUtils.js.map +1 -1
- package/lib/utils/tagsUtils.d.ts +7 -8
- package/lib/utils/tagsUtils.d.ts.map +1 -1
- package/lib/utils/tagsUtils.js +8 -6
- package/lib/utils/tagsUtils.js.map +1 -1
- package/lib/utils/tocUtils.d.ts +17 -1
- package/lib/utils/tocUtils.d.ts.map +1 -1
- package/lib/utils/tocUtils.js +20 -9
- package/lib/utils/tocUtils.js.map +1 -1
- package/lib/utils/useAlternatePageUtils.d.ts +20 -1
- package/lib/utils/useAlternatePageUtils.d.ts.map +1 -1
- package/lib/utils/useAlternatePageUtils.js +6 -3
- package/lib/utils/useAlternatePageUtils.js.map +1 -1
- package/lib/utils/useLocalPathname.d.ts +5 -0
- package/lib/utils/useLocalPathname.d.ts.map +1 -1
- package/lib/utils/useLocalPathname.js +6 -4
- package/lib/utils/useLocalPathname.js.map +1 -1
- package/lib/utils/useLocationChange.d.ts +7 -5
- package/lib/utils/useLocationChange.d.ts.map +1 -1
- package/lib/utils/useLocationChange.js +6 -2
- package/lib/utils/useLocationChange.js.map +1 -1
- package/lib/utils/usePluralForm.d.ts +11 -0
- package/lib/utils/usePluralForm.d.ts.map +1 -1
- package/lib/utils/usePluralForm.js +19 -24
- package/lib/utils/usePluralForm.js.map +1 -1
- package/lib/utils/useThemeConfig.d.ts +28 -22
- package/lib/utils/useThemeConfig.d.ts.map +1 -1
- package/lib/utils/useThemeConfig.js +3 -0
- package/lib/utils/useThemeConfig.js.map +1 -1
- package/package.json +18 -11
- package/src/components/Collapsible/index.tsx +42 -24
- package/src/components/Details/index.tsx +15 -8
- package/src/components/Details/styles.module.css +4 -0
- package/src/{utils/announcementBarUtils.tsx → contexts/announcementBar.tsx} +20 -22
- package/src/contexts/colorMode.tsx +199 -0
- package/src/contexts/docSidebarItemsExpandedState.tsx +55 -0
- package/src/contexts/docsPreferredVersion.tsx +253 -0
- package/src/contexts/docsSidebar.tsx +50 -0
- package/src/contexts/docsVersion.tsx +36 -0
- package/src/contexts/navbarMobileSidebar.tsx +99 -0
- package/src/contexts/navbarSecondaryMenu/content.tsx +110 -0
- package/src/contexts/navbarSecondaryMenu/display.tsx +102 -0
- package/src/{utils/tabGroupChoiceUtils.tsx → contexts/tabGroupChoice.tsx} +28 -33
- package/src/hooks/useBackToTopButton.ts +73 -0
- package/src/hooks/useCodeWordWrap.ts +56 -0
- package/src/hooks/useHideableNavbar.ts +12 -14
- package/src/hooks/useKeyboardNavigation.ts +11 -3
- package/src/hooks/useLockBodyScroll.ts +5 -2
- package/src/hooks/usePrismTheme.ts +10 -6
- package/src/hooks/useSearchPage.ts +18 -5
- package/src/hooks/useSkipToContent.ts +58 -0
- package/src/{utils → hooks}/useTOCHighlight.ts +24 -15
- package/src/hooks/useWindowSize.ts +14 -12
- package/src/index.ts +77 -57
- package/src/utils/ThemeClassNames.ts +10 -6
- package/src/utils/codeBlockUtils.ts +178 -92
- package/src/utils/docsUtils.tsx +205 -101
- package/src/utils/footerUtils.ts +18 -0
- package/src/utils/generalUtils.ts +6 -3
- package/src/utils/historyUtils.ts +11 -17
- package/src/utils/jsUtils.ts +1 -1
- package/src/utils/metadataUtils.tsx +115 -0
- package/src/utils/navbarUtils.tsx +45 -0
- package/src/utils/reactUtils.tsx +40 -7
- package/src/utils/regexpUtils.ts +2 -1
- package/src/utils/routesUtils.ts +58 -22
- package/src/utils/scrollUtils.tsx +120 -49
- package/src/utils/searchUtils.ts +51 -0
- package/src/utils/storageUtils.ts +23 -15
- package/src/utils/tagsUtils.ts +12 -10
- package/src/utils/tocUtils.ts +22 -11
- package/src/utils/useAlternatePageUtils.ts +17 -5
- package/src/utils/useLocalPathname.ts +6 -4
- package/src/utils/useLocationChange.ts +12 -10
- package/src/utils/usePluralForm.ts +27 -24
- package/src/utils/useThemeConfig.ts +23 -22
- package/yarn-error.log +20199 -0
- package/lib/utils/announcementBarUtils.d.ts.map +0 -1
- package/lib/utils/announcementBarUtils.js.map +0 -1
- package/lib/utils/colorModeUtils.d.ts +0 -18
- package/lib/utils/colorModeUtils.d.ts.map +0 -1
- package/lib/utils/colorModeUtils.js +0 -106
- package/lib/utils/colorModeUtils.js.map +0 -1
- package/lib/utils/docSidebarItemsExpandedState.d.ts +0 -17
- package/lib/utils/docSidebarItemsExpandedState.d.ts.map +0 -1
- package/lib/utils/docSidebarItemsExpandedState.js.map +0 -1
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.d.ts +0 -22
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.d.ts.map +0 -1
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js +0 -91
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js.map +0 -1
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.d.ts +0 -14
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.d.ts.map +0 -1
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.js +0 -19
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.js.map +0 -1
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.d.ts +0 -14
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.d.ts.map +0 -1
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.js +0 -41
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.js.map +0 -1
- package/lib/utils/mobileSecondaryMenu.d.ts +0 -21
- package/lib/utils/mobileSecondaryMenu.d.ts.map +0 -1
- package/lib/utils/mobileSecondaryMenu.js +0 -50
- package/lib/utils/mobileSecondaryMenu.js.map +0 -1
- package/lib/utils/pathUtils.d.ts +0 -8
- package/lib/utils/pathUtils.d.ts.map +0 -1
- package/lib/utils/pathUtils.js +0 -17
- package/lib/utils/pathUtils.js.map +0 -1
- package/lib/utils/tabGroupChoiceUtils.d.ts.map +0 -1
- package/lib/utils/tabGroupChoiceUtils.js.map +0 -1
- package/lib/utils/useContextualSearchFilters.d.ts +0 -12
- package/lib/utils/useContextualSearchFilters.d.ts.map +0 -1
- package/lib/utils/useContextualSearchFilters.js +0 -37
- package/lib/utils/useContextualSearchFilters.js.map +0 -1
- package/lib/utils/usePrevious.d.ts +0 -8
- package/lib/utils/usePrevious.d.ts.map +0 -1
- package/lib/utils/usePrevious.js +0 -16
- package/lib/utils/usePrevious.js.map +0 -1
- package/lib/utils/useTOCHighlight.d.ts +0 -14
- package/lib/utils/useTOCHighlight.d.ts.map +0 -1
- package/lib/utils/useTOCHighlight.js.map +0 -1
- package/src/utils/colorModeUtils.tsx +0 -156
- package/src/utils/docSidebarItemsExpandedState.tsx +0 -41
- package/src/utils/docsPreferredVersion/DocsPreferredVersionProvider.tsx +0 -167
- package/src/utils/docsPreferredVersion/DocsPreferredVersionStorage.ts +0 -33
- package/src/utils/docsPreferredVersion/useDocsPreferredVersion.ts +0 -70
- package/src/utils/mobileSecondaryMenu.tsx +0 -115
- package/src/utils/pathUtils.ts +0 -19
- package/src/utils/useContextualSearchFilters.ts +0 -53
- package/src/utils/usePrevious.ts +0 -19
package/src/utils/tocUtils.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import {useMemo} from 'react';
|
|
9
|
-
import type {TOCItem} from '@docusaurus/
|
|
9
|
+
import type {TOCItem} from '@docusaurus/mdx-loader';
|
|
10
10
|
|
|
11
11
|
export type TOCTreeNode = {
|
|
12
12
|
readonly value: string;
|
|
@@ -30,11 +30,11 @@ function treeifyTOC(flatTOC: readonly TOCItem[]): TOCTreeNode[] {
|
|
|
30
30
|
const prevIndexForLevel = Array(7).fill(-1);
|
|
31
31
|
|
|
32
32
|
headings.forEach((curr, currIndex) => {
|
|
33
|
-
//
|
|
34
|
-
//
|
|
33
|
+
// Take the last seen index for each ancestor level. the highest index will
|
|
34
|
+
// be the direct ancestor of the current heading.
|
|
35
35
|
const ancestorLevelIndexes = prevIndexForLevel.slice(2, curr.level);
|
|
36
36
|
curr.parentIndex = Math.max(...ancestorLevelIndexes);
|
|
37
|
-
//
|
|
37
|
+
// Mark that curr.level was last seen at the current index.
|
|
38
38
|
prevIndexForLevel[curr.level] = currIndex;
|
|
39
39
|
});
|
|
40
40
|
|
|
@@ -44,7 +44,7 @@ function treeifyTOC(flatTOC: readonly TOCItem[]): TOCTreeNode[] {
|
|
|
44
44
|
headings.forEach((heading) => {
|
|
45
45
|
const {parentIndex, ...rest} = heading;
|
|
46
46
|
if (parentIndex >= 0) {
|
|
47
|
-
headings[parentIndex]
|
|
47
|
+
headings[parentIndex]!.children.push(rest);
|
|
48
48
|
} else {
|
|
49
49
|
rootNodes.push(rest);
|
|
50
50
|
}
|
|
@@ -52,6 +52,10 @@ function treeifyTOC(flatTOC: readonly TOCItem[]): TOCTreeNode[] {
|
|
|
52
52
|
return rootNodes;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
/**
|
|
56
|
+
* Takes a flat TOC list (from the MDX loader) and treeifies it into what the
|
|
57
|
+
* TOC components expect. Memoized for performance.
|
|
58
|
+
*/
|
|
55
59
|
export function useTreeifiedTOC(toc: TOCItem[]): readonly TOCTreeNode[] {
|
|
56
60
|
return useMemo(() => treeifyTOC(toc), [toc]);
|
|
57
61
|
}
|
|
@@ -87,6 +91,18 @@ function filterTOC({
|
|
|
87
91
|
});
|
|
88
92
|
}
|
|
89
93
|
|
|
94
|
+
/**
|
|
95
|
+
* Takes a flat TOC list (from the MDX loader) and treeifies it into what the
|
|
96
|
+
* TOC components expect, applying the `minHeadingLevel` and `maxHeadingLevel`.
|
|
97
|
+
* Memoized for performance.
|
|
98
|
+
*
|
|
99
|
+
* **Important**: this is not the same as `useTreeifiedTOC(toc.filter(...))`,
|
|
100
|
+
* because we have to filter the TOC after it has been treeified. This is mostly
|
|
101
|
+
* to ensure that weird TOC structures preserve their semantics. For example, an
|
|
102
|
+
* h3-h2-h4 sequence should not be treeified as an "h3 > h4" hierarchy with
|
|
103
|
+
* min=3, max=4, but should rather be "[h3, h4]" (since the h2 heading has split
|
|
104
|
+
* the two headings and they are not parent-children)
|
|
105
|
+
*/
|
|
90
106
|
export function useFilteredAndTreeifiedTOC({
|
|
91
107
|
toc,
|
|
92
108
|
minHeadingLevel,
|
|
@@ -97,12 +113,7 @@ export function useFilteredAndTreeifiedTOC({
|
|
|
97
113
|
maxHeadingLevel: number;
|
|
98
114
|
}): readonly TOCTreeNode[] {
|
|
99
115
|
return useMemo(
|
|
100
|
-
() =>
|
|
101
|
-
// Note: we have to filter the TOC after it has been treeified. This is
|
|
102
|
-
// mostly to ensure that weird TOC structures preserve their semantics.
|
|
103
|
-
// For example, an h3-h2-h4 sequence should not be treeified as an h3 > h4
|
|
104
|
-
// hierarchy with min=3, max=4, but should rather be [h3, h4]
|
|
105
|
-
filterTOC({toc: treeifyTOC(toc), minHeadingLevel, maxHeadingLevel}),
|
|
116
|
+
() => filterTOC({toc: treeifyTOC(toc), minHeadingLevel, maxHeadingLevel}),
|
|
106
117
|
[toc, minHeadingLevel, maxHeadingLevel],
|
|
107
118
|
);
|
|
108
119
|
}
|
|
@@ -8,12 +8,26 @@
|
|
|
8
8
|
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
9
9
|
import {useLocation} from '@docusaurus/router';
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Permits to obtain the url of the current page in another locale, useful to
|
|
13
|
+
* generate hreflang meta headers etc...
|
|
14
|
+
*
|
|
15
|
+
* @see https://developers.google.com/search/docs/advanced/crawling/localized-versions
|
|
16
|
+
*/
|
|
14
17
|
export function useAlternatePageUtils(): {
|
|
18
|
+
/**
|
|
19
|
+
* Everything (pathname, base URL, etc.) is read from the context. Just tell
|
|
20
|
+
* it which locale to link to and it will give you the alternate link for the
|
|
21
|
+
* current page.
|
|
22
|
+
*/
|
|
15
23
|
createUrl: ({
|
|
24
|
+
/** The locale name to link to. */
|
|
16
25
|
locale,
|
|
26
|
+
/**
|
|
27
|
+
* For hreflang SEO headers, we need it to be fully qualified (full
|
|
28
|
+
* protocol/domain/path...); but for locale dropdowns, using a pathname is
|
|
29
|
+
* good enough.
|
|
30
|
+
*/
|
|
17
31
|
fullyQualified,
|
|
18
32
|
}: {
|
|
19
33
|
locale: string;
|
|
@@ -46,8 +60,6 @@ export function useAlternatePageUtils(): {
|
|
|
46
60
|
fullyQualified,
|
|
47
61
|
}: {
|
|
48
62
|
locale: string;
|
|
49
|
-
// For hreflang SEO headers, we need it to be fully qualified (full
|
|
50
|
-
// protocol/domain/path...) or locale dropdown, using a path is good enough
|
|
51
63
|
fullyQualified: boolean;
|
|
52
64
|
}) {
|
|
53
65
|
return `${fullyQualified ? url : ''}${getLocalizedBaseUrl(
|
|
@@ -5,12 +5,14 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
9
8
|
import {useLocation} from '@docusaurus/router';
|
|
9
|
+
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Get the pathname of current route, without the optional site baseUrl.
|
|
13
|
+
* - `/docs/myDoc` => `/docs/myDoc`
|
|
14
|
+
* - `/baseUrl/docs/myDoc` => `/docs/myDoc`
|
|
15
|
+
*/
|
|
14
16
|
export function useLocalPathname(): string {
|
|
15
17
|
const {
|
|
16
18
|
siteConfig: {baseUrl},
|
|
@@ -8,17 +8,19 @@
|
|
|
8
8
|
import {useEffect} from 'react';
|
|
9
9
|
import {useLocation} from '@docusaurus/router';
|
|
10
10
|
import type {Location} from 'history';
|
|
11
|
-
import {usePrevious} from './
|
|
12
|
-
import {useDynamicCallback} from './reactUtils';
|
|
11
|
+
import {useDynamicCallback, usePrevious} from './reactUtils';
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Fires an effect when the location changes (which includes hash, query, etc.).
|
|
15
|
+
* Importantly, doesn't fire when there's no previous location: see
|
|
16
|
+
* https://github.com/facebook/docusaurus/pull/6696
|
|
17
|
+
*/
|
|
18
|
+
export function useLocationChange(
|
|
19
|
+
onLocationChange: (locationChangeEvent: {
|
|
20
|
+
location: Location;
|
|
21
|
+
previousLocation: Location | undefined;
|
|
22
|
+
}) => void,
|
|
23
|
+
): void {
|
|
22
24
|
const location = useLocation();
|
|
23
25
|
const previousLocation = usePrevious(location);
|
|
24
26
|
|
|
@@ -50,17 +50,17 @@ function createLocalePluralForms(locale: string): LocalePluralForms {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
|
-
* Poor man's PluralSelector implementation, using an
|
|
54
|
-
* a lightweight, future-proof and good-enough solution. We don't want a
|
|
55
|
-
* and heavy solution.
|
|
53
|
+
* Poor man's `PluralSelector` implementation, using an English fallback. We
|
|
54
|
+
* want a lightweight, future-proof and good-enough solution. We don't want a
|
|
55
|
+
* perfect and heavy solution.
|
|
56
56
|
*
|
|
57
57
|
* Docusaurus classic theme has only 2 deeply nested labels requiring complex
|
|
58
|
-
* plural rules. We don't want to use Intl + PluralRules polyfills + full
|
|
59
|
-
* syntax (react-intl) just for that.
|
|
58
|
+
* plural rules. We don't want to use `Intl` + `PluralRules` polyfills + full
|
|
59
|
+
* ICU syntax (react-intl) just for that.
|
|
60
60
|
*
|
|
61
61
|
* Notes:
|
|
62
|
-
* - 2021: 92+% Browsers support Intl.PluralRules
|
|
63
|
-
* the future
|
|
62
|
+
* - 2021: 92+% Browsers support `Intl.PluralRules`, and support will increase
|
|
63
|
+
* in the future
|
|
64
64
|
* - NodeJS >= 13 has full ICU support by default
|
|
65
65
|
* - In case of "mismatch" between SSR and Browser ICU support, React keeps
|
|
66
66
|
* working!
|
|
@@ -70,21 +70,13 @@ function useLocalePluralForms(): LocalePluralForms {
|
|
|
70
70
|
i18n: {currentLocale},
|
|
71
71
|
} = useDocusaurusContext();
|
|
72
72
|
return useMemo(() => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
console.error(`Failed to use Intl.PluralRules for locale "${currentLocale}".
|
|
80
|
-
Docusaurus will fallback to a default/fallback (English) Intl.PluralRules implementation.
|
|
73
|
+
try {
|
|
74
|
+
return createLocalePluralForms(currentLocale);
|
|
75
|
+
} catch (err) {
|
|
76
|
+
console.error(`Failed to use Intl.PluralRules for locale "${currentLocale}".
|
|
77
|
+
Docusaurus will fallback to the default (English) implementation.
|
|
78
|
+
Error: ${(err as Error).message}
|
|
81
79
|
`);
|
|
82
|
-
return EnglishPluralForms;
|
|
83
|
-
}
|
|
84
|
-
} else {
|
|
85
|
-
console.error(`Intl.PluralRules not available!
|
|
86
|
-
Docusaurus will fallback to a default/fallback (English) Intl.PluralRules implementation.
|
|
87
|
-
`);
|
|
88
80
|
return EnglishPluralForms;
|
|
89
81
|
}
|
|
90
82
|
}, [currentLocale]);
|
|
@@ -99,21 +91,32 @@ function selectPluralMessage(
|
|
|
99
91
|
const parts = pluralMessages.split(separator);
|
|
100
92
|
|
|
101
93
|
if (parts.length === 1) {
|
|
102
|
-
return parts[0]
|
|
94
|
+
return parts[0]!;
|
|
103
95
|
}
|
|
104
96
|
if (parts.length > localePluralForms.pluralForms.length) {
|
|
105
97
|
console.error(
|
|
106
|
-
`For locale=${localePluralForms.locale}, a maximum of ${localePluralForms.pluralForms.length} plural forms are expected (${localePluralForms.pluralForms}), but the message contains ${parts.length}
|
|
98
|
+
`For locale=${localePluralForms.locale}, a maximum of ${localePluralForms.pluralForms.length} plural forms are expected (${localePluralForms.pluralForms}), but the message contains ${parts.length}: ${pluralMessages}`,
|
|
107
99
|
);
|
|
108
100
|
}
|
|
109
101
|
const pluralForm = localePluralForms.select(count);
|
|
110
102
|
const pluralFormIndex = localePluralForms.pluralForms.indexOf(pluralForm);
|
|
111
103
|
// In case of not enough plural form messages, we take the last one (other)
|
|
112
104
|
// instead of returning undefined
|
|
113
|
-
return parts[Math.min(pluralFormIndex, parts.length - 1)]
|
|
105
|
+
return parts[Math.min(pluralFormIndex, parts.length - 1)]!;
|
|
114
106
|
}
|
|
115
107
|
|
|
108
|
+
/**
|
|
109
|
+
* Reads the current locale and returns an interface very similar to
|
|
110
|
+
* `Intl.PluralRules`.
|
|
111
|
+
*/
|
|
116
112
|
export function usePluralForm(): {
|
|
113
|
+
/**
|
|
114
|
+
* Give it a `count` and it will select the relevant message from
|
|
115
|
+
* `pluralMessages`. `pluralMessages` should be separated by `|`, and in the
|
|
116
|
+
* order of "zero", "one", "two", "few", "many", "other". The actual selection
|
|
117
|
+
* is done by `Intl.PluralRules`, which tells us all plurals the locale has
|
|
118
|
+
* and which plural we should use for `count`.
|
|
119
|
+
*/
|
|
117
120
|
selectMessage: (count: number, pluralMessages: string) => string;
|
|
118
121
|
} {
|
|
119
122
|
const localePluralForm = useLocalePluralForms();
|
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
|
|
8
8
|
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
9
9
|
import type {PrismTheme} from 'prism-react-renderer';
|
|
10
|
-
import type {CSSProperties} from 'react';
|
|
11
10
|
import type {DeepPartial} from 'utility-types';
|
|
11
|
+
import type {MagicCommentConfig} from './codeBlockUtils';
|
|
12
12
|
|
|
13
13
|
export type DocsVersionPersistence = 'localStorage' | 'none';
|
|
14
14
|
|
|
@@ -18,7 +18,7 @@ export type NavbarItem = {
|
|
|
18
18
|
items?: NavbarItem[];
|
|
19
19
|
label?: string;
|
|
20
20
|
position?: 'left' | 'right';
|
|
21
|
-
} &
|
|
21
|
+
} & {[key: string]: unknown};
|
|
22
22
|
|
|
23
23
|
export type NavbarLogo = {
|
|
24
24
|
src: string;
|
|
@@ -43,12 +43,6 @@ export type ColorModeConfig = {
|
|
|
43
43
|
defaultMode: 'light' | 'dark';
|
|
44
44
|
disableSwitch: boolean;
|
|
45
45
|
respectPrefersColorScheme: boolean;
|
|
46
|
-
switchConfig: {
|
|
47
|
-
darkIcon: string;
|
|
48
|
-
darkIconStyle: CSSProperties;
|
|
49
|
-
lightIcon: string;
|
|
50
|
-
lightIconStyle: CSSProperties;
|
|
51
|
-
};
|
|
52
46
|
};
|
|
53
47
|
|
|
54
48
|
export type AnnouncementBarConfig = {
|
|
@@ -60,10 +54,11 @@ export type AnnouncementBarConfig = {
|
|
|
60
54
|
};
|
|
61
55
|
|
|
62
56
|
export type PrismConfig = {
|
|
63
|
-
theme
|
|
57
|
+
theme: PrismTheme;
|
|
64
58
|
darkTheme?: PrismTheme;
|
|
65
59
|
defaultLanguage?: string;
|
|
66
|
-
additionalLanguages
|
|
60
|
+
additionalLanguages: string[];
|
|
61
|
+
magicComments: MagicCommentConfig[];
|
|
67
62
|
};
|
|
68
63
|
|
|
69
64
|
export type FooterLinkItem = {
|
|
@@ -72,18 +67,20 @@ export type FooterLinkItem = {
|
|
|
72
67
|
href?: string;
|
|
73
68
|
html?: string;
|
|
74
69
|
prependBaseUrlToHref?: string;
|
|
70
|
+
} & {[key: string]: unknown};
|
|
71
|
+
|
|
72
|
+
export type FooterLogo = {
|
|
73
|
+
alt?: string;
|
|
74
|
+
src: string;
|
|
75
|
+
srcDark?: string;
|
|
76
|
+
width?: string | number;
|
|
77
|
+
height?: string | number;
|
|
78
|
+
href?: string;
|
|
75
79
|
};
|
|
76
80
|
|
|
77
81
|
export type FooterBase = {
|
|
78
82
|
style: 'light' | 'dark';
|
|
79
|
-
logo?:
|
|
80
|
-
alt?: string;
|
|
81
|
-
src?: string;
|
|
82
|
-
srcDark?: string;
|
|
83
|
-
width?: string | number;
|
|
84
|
-
height?: string | number;
|
|
85
|
-
href?: string;
|
|
86
|
-
};
|
|
83
|
+
logo?: FooterLogo;
|
|
87
84
|
copyright?: string;
|
|
88
85
|
};
|
|
89
86
|
|
|
@@ -109,6 +106,10 @@ export type TableOfContents = {
|
|
|
109
106
|
export type ThemeConfig = {
|
|
110
107
|
docs: {
|
|
111
108
|
versionPersistence: DocsVersionPersistence;
|
|
109
|
+
sidebar: {
|
|
110
|
+
hideable: boolean;
|
|
111
|
+
autoCollapseCategories: boolean;
|
|
112
|
+
};
|
|
112
113
|
};
|
|
113
114
|
|
|
114
115
|
// TODO we should complete this theme config type over time
|
|
@@ -121,17 +122,17 @@ export type ThemeConfig = {
|
|
|
121
122
|
announcementBar?: AnnouncementBarConfig;
|
|
122
123
|
prism: PrismConfig;
|
|
123
124
|
footer?: Footer;
|
|
124
|
-
hideableSidebar: boolean;
|
|
125
|
-
autoCollapseSidebarCategories: boolean;
|
|
126
125
|
image?: string;
|
|
127
|
-
metadata: Array<
|
|
128
|
-
sidebarCollapsible: boolean;
|
|
126
|
+
metadata: Array<{[key: string]: string}>;
|
|
129
127
|
tableOfContents: TableOfContents;
|
|
130
128
|
};
|
|
131
129
|
|
|
132
130
|
// User-provided theme config, unnormalized
|
|
133
131
|
export type UserThemeConfig = DeepPartial<ThemeConfig>;
|
|
134
132
|
|
|
133
|
+
/**
|
|
134
|
+
* A convenient/more semantic way to get theme config from context.
|
|
135
|
+
*/
|
|
135
136
|
export function useThemeConfig(): ThemeConfig {
|
|
136
137
|
return useDocusaurusContext().siteConfig.themeConfig as ThemeConfig;
|
|
137
138
|
}
|