@docusaurus/theme-common 2.0.0-beta.1decd6f80 → 2.0.0-beta.20
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 +64 -0
- package/lib/components/Collapsible/index.d.ts.map +1 -0
- package/lib/components/Collapsible/index.js +152 -0
- package/lib/components/Collapsible/index.js.map +1 -0
- package/lib/components/Details/index.d.ts +17 -0
- package/lib/components/Details/index.d.ts.map +1 -0
- package/lib/components/Details/index.js +71 -0
- package/lib/components/Details/index.js.map +1 -0
- package/lib/components/Details/styles.module.css +62 -0
- package/lib/contexts/announcementBar.d.ts +22 -0
- package/lib/contexts/announcementBar.d.ts.map +1 -0
- package/lib/contexts/announcementBar.js +72 -0
- 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/contexts/docSidebarItemsExpandedState.js +28 -0
- 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/contexts/tabGroupChoice.d.ts +21 -0
- package/lib/contexts/tabGroupChoice.d.ts.map +1 -0
- package/lib/contexts/tabGroupChoice.js +49 -0
- package/lib/contexts/tabGroupChoice.js.map +1 -0
- package/lib/{utils/useChangeRoute.d.ts → hooks/styles.css} +4 -1
- 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 +17 -0
- package/lib/hooks/useHideableNavbar.d.ts.map +1 -0
- package/lib/hooks/useHideableNavbar.js +60 -0
- package/lib/hooks/useHideableNavbar.js.map +1 -0
- package/lib/hooks/useKeyboardNavigation.d.ts +20 -0
- package/lib/hooks/useKeyboardNavigation.d.ts.map +1 -0
- package/lib/hooks/useKeyboardNavigation.js +39 -0
- package/lib/hooks/useKeyboardNavigation.js.map +1 -0
- package/lib/hooks/useLockBodyScroll.d.ts +12 -0
- package/lib/hooks/useLockBodyScroll.d.ts.map +1 -0
- package/lib/hooks/useLockBodyScroll.js +20 -0
- package/lib/hooks/useLockBodyScroll.js.map +1 -0
- package/lib/hooks/usePrismTheme.d.ts +13 -0
- package/lib/hooks/usePrismTheme.d.ts.map +1 -0
- package/lib/hooks/usePrismTheme.js +21 -0
- package/lib/hooks/usePrismTheme.js.map +1 -0
- package/lib/hooks/useSearchPage.d.ts +25 -0
- package/lib/hooks/useSearchPage.d.ts.map +1 -0
- package/lib/hooks/useSearchPage.js +43 -0
- package/lib/hooks/useSearchPage.js.map +1 -0
- 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/hooks/useTOCHighlight.js +130 -0
- package/lib/hooks/useTOCHighlight.js.map +1 -0
- package/lib/hooks/useWindowSize.d.ts +28 -0
- package/lib/hooks/useWindowSize.d.ts.map +1 -0
- package/lib/hooks/useWindowSize.js +59 -0
- package/lib/hooks/useWindowSize.js.map +1 -0
- package/lib/index.d.ts +39 -9
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +39 -8
- package/lib/index.js.map +1 -0
- package/lib/utils/ThemeClassNames.d.ts +47 -12
- package/lib/utils/ThemeClassNames.d.ts.map +1 -0
- package/lib/utils/ThemeClassNames.js +45 -4
- package/lib/utils/ThemeClassNames.js.map +1 -0
- package/lib/utils/codeBlockUtils.d.ts +63 -0
- package/lib/utils/codeBlockUtils.d.ts.map +1 -0
- package/lib/utils/codeBlockUtils.js +157 -3
- package/lib/utils/codeBlockUtils.js.map +1 -0
- package/lib/utils/docsUtils.d.ts +91 -0
- package/lib/utils/docsUtils.d.ts.map +1 -0
- package/lib/utils/docsUtils.js +217 -1
- package/lib/utils/docsUtils.js.map +1 -0
- 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 +11 -1
- package/lib/utils/generalUtils.d.ts.map +1 -0
- package/lib/utils/generalUtils.js +9 -5
- package/lib/utils/generalUtils.js.map +1 -0
- package/lib/utils/historyUtils.d.ts +17 -0
- package/lib/utils/historyUtils.d.ts.map +1 -0
- package/lib/utils/historyUtils.js +38 -0
- package/lib/utils/historyUtils.js.map +1 -0
- package/lib/utils/jsUtils.d.ts +23 -0
- package/lib/utils/jsUtils.d.ts.map +1 -0
- package/lib/utils/jsUtils.js +29 -0
- package/lib/utils/jsUtils.js.map +1 -0
- 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 +42 -0
- package/lib/utils/reactUtils.d.ts.map +1 -0
- package/lib/utils/reactUtils.js +64 -0
- package/lib/utils/reactUtils.js.map +1 -0
- package/lib/utils/regexpUtils.d.ts +12 -0
- package/lib/utils/regexpUtils.d.ts.map +1 -0
- package/lib/utils/regexpUtils.js +18 -0
- package/lib/utils/regexpUtils.js.map +1 -0
- package/lib/utils/routesUtils.d.ts +26 -0
- package/lib/utils/routesUtils.d.ts.map +1 -0
- package/lib/utils/routesUtils.js +54 -0
- package/lib/utils/routesUtils.js.map +1 -0
- package/lib/utils/scrollUtils.d.ts +83 -0
- package/lib/utils/scrollUtils.d.ts.map +1 -0
- package/lib/utils/scrollUtils.js +200 -0
- package/lib/utils/scrollUtils.js.map +1 -0
- package/lib/utils/searchUtils.d.ts +13 -0
- package/lib/utils/searchUtils.d.ts.map +1 -0
- package/lib/utils/searchUtils.js +37 -0
- package/lib/utils/searchUtils.js.map +1 -0
- package/lib/utils/storageUtils.d.ts +15 -7
- package/lib/utils/storageUtils.d.ts.map +1 -0
- package/lib/utils/storageUtils.js +58 -25
- package/lib/utils/storageUtils.js.map +1 -0
- package/lib/utils/tagsUtils.d.ts +18 -0
- package/lib/utils/tagsUtils.d.ts.map +1 -0
- package/lib/utils/tagsUtils.js +36 -0
- package/lib/utils/tagsUtils.js.map +1 -0
- package/lib/utils/tocUtils.d.ts +36 -0
- package/lib/utils/tocUtils.d.ts.map +1 -0
- package/lib/utils/tocUtils.js +84 -0
- package/lib/utils/tocUtils.js.map +1 -0
- package/lib/utils/useAlternatePageUtils.d.ts +21 -1
- package/lib/utils/useAlternatePageUtils.d.ts.map +1 -0
- package/lib/utils/useAlternatePageUtils.js +9 -4
- package/lib/utils/useAlternatePageUtils.js.map +1 -0
- package/lib/utils/useLocalPathname.d.ts +13 -0
- package/lib/utils/useLocalPathname.d.ts.map +1 -0
- package/lib/utils/useLocalPathname.js +19 -0
- package/lib/utils/useLocalPathname.js.map +1 -0
- package/lib/utils/useLocationChange.d.ts +17 -0
- package/lib/utils/useLocationChange.d.ts.map +1 -0
- package/lib/utils/useLocationChange.js +31 -0
- package/lib/utils/useLocationChange.js.map +1 -0
- package/lib/utils/usePluralForm.d.ts +12 -0
- package/lib/utils/usePluralForm.d.ts.map +1 -0
- package/lib/utils/usePluralForm.js +36 -37
- package/lib/utils/usePluralForm.js.map +1 -0
- package/lib/utils/useThemeConfig.d.ts +55 -23
- package/lib/utils/useThemeConfig.d.ts.map +1 -0
- package/lib/utils/useThemeConfig.js +4 -0
- package/lib/utils/useThemeConfig.js.map +1 -0
- package/package.json +26 -13
- package/src/components/Collapsible/index.tsx +265 -0
- package/src/components/Details/index.tsx +109 -0
- package/src/components/Details/styles.module.css +62 -0
- package/src/contexts/announcementBar.tsx +119 -0
- 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/contexts/tabGroupChoice.tsx +85 -0
- package/{lib/utils/pathUtils.d.ts → src/hooks/styles.css} +4 -1
- package/src/hooks/useBackToTopButton.ts +73 -0
- package/src/hooks/useCodeWordWrap.ts +56 -0
- package/src/hooks/useHideableNavbar.ts +75 -0
- package/src/hooks/useKeyboardNavigation.ts +45 -0
- package/src/hooks/useLockBodyScroll.ts +21 -0
- package/src/hooks/usePrismTheme.ts +24 -0
- package/src/hooks/useSearchPage.ts +79 -0
- package/src/hooks/useSkipToContent.ts +58 -0
- package/src/hooks/useTOCHighlight.ts +192 -0
- package/src/hooks/useWindowSize.ts +72 -0
- package/src/index.ts +136 -18
- package/src/types.d.ts +0 -2
- package/src/utils/ThemeClassNames.ts +51 -5
- package/src/utils/codeBlockUtils.ts +239 -2
- package/src/utils/docsUtils.tsx +334 -0
- package/src/utils/footerUtils.ts +18 -0
- package/src/utils/generalUtils.ts +9 -5
- package/src/utils/historyUtils.ts +45 -0
- package/src/utils/jsUtils.ts +36 -0
- package/src/utils/metadataUtils.tsx +115 -0
- package/src/utils/navbarUtils.tsx +45 -0
- package/src/utils/reactUtils.tsx +76 -0
- package/src/utils/regexpUtils.ts +24 -0
- package/src/utils/routesUtils.ts +75 -0
- package/src/utils/scrollUtils.tsx +308 -0
- package/src/utils/searchUtils.ts +51 -0
- package/src/utils/storageUtils.ts +59 -26
- package/src/utils/tagsUtils.ts +50 -0
- package/src/utils/tocUtils.ts +119 -0
- package/src/utils/useAlternatePageUtils.ts +28 -7
- package/src/utils/useLocalPathname.ts +22 -0
- package/src/utils/useLocationChange.ts +41 -0
- package/src/utils/usePluralForm.ts +49 -39
- package/src/utils/useThemeConfig.ts +54 -25
- package/lib/.tsbuildinfo +0 -4115
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.d.ts +0 -21
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js +0 -94
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.d.ts +0 -13
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.js +0 -20
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.d.ts +0 -5
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.js +0 -41
- package/lib/utils/pathUtils.js +0 -13
- package/lib/utils/useChangeRoute.js +0 -18
- package/src/utils/__tests__/codeBlockUtils.test.ts +0 -54
- package/src/utils/__tests__/pathUtils.test.ts +0 -32
- package/src/utils/docsPreferredVersion/DocsPreferredVersionProvider.tsx +0 -165
- package/src/utils/docsPreferredVersion/DocsPreferredVersionStorage.ts +0 -34
- package/src/utils/docsPreferredVersion/useDocsPreferredVersion.ts +0 -66
- package/src/utils/docsUtils.ts +0 -11
- package/src/utils/pathUtils.ts +0 -17
- package/src/utils/useChangeRoute.ts +0 -21
- package/tsconfig.json +0 -10
|
@@ -8,10 +8,32 @@
|
|
|
8
8
|
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
9
9
|
import {useLocation} from '@docusaurus/router';
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
+
*/
|
|
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
|
+
*/
|
|
23
|
+
createUrl: ({
|
|
24
|
+
/** The locale name to link to. */
|
|
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
|
+
*/
|
|
31
|
+
fullyQualified,
|
|
32
|
+
}: {
|
|
33
|
+
locale: string;
|
|
34
|
+
fullyQualified: boolean;
|
|
35
|
+
}) => string;
|
|
36
|
+
} {
|
|
15
37
|
const {
|
|
16
38
|
siteConfig: {baseUrl, url},
|
|
17
39
|
i18n: {defaultLocale, currentLocale},
|
|
@@ -31,14 +53,13 @@ export function useAlternatePageUtils() {
|
|
|
31
53
|
: `${baseUrlUnlocalized}${locale}/`;
|
|
32
54
|
}
|
|
33
55
|
|
|
34
|
-
// TODO support correct alternate url when localized site is deployed on
|
|
56
|
+
// TODO support correct alternate url when localized site is deployed on
|
|
57
|
+
// another domain
|
|
35
58
|
function createUrl({
|
|
36
59
|
locale,
|
|
37
60
|
fullyQualified,
|
|
38
61
|
}: {
|
|
39
62
|
locale: string;
|
|
40
|
-
// For hreflang SEO headers, we need it to be fully qualified (full protocol/domain/path...)
|
|
41
|
-
// For locale dropdown, using a path is good enough
|
|
42
63
|
fullyQualified: boolean;
|
|
43
64
|
}) {
|
|
44
65
|
return `${fullyQualified ? url : ''}${getLocalizedBaseUrl(
|
|
@@ -0,0 +1,22 @@
|
|
|
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 {useLocation} from '@docusaurus/router';
|
|
9
|
+
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
10
|
+
|
|
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
|
+
*/
|
|
16
|
+
export function useLocalPathname(): string {
|
|
17
|
+
const {
|
|
18
|
+
siteConfig: {baseUrl},
|
|
19
|
+
} = useDocusaurusContext();
|
|
20
|
+
const {pathname} = useLocation();
|
|
21
|
+
return pathname.replace(baseUrl, '/');
|
|
22
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
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 {useEffect} from 'react';
|
|
9
|
+
import {useLocation} from '@docusaurus/router';
|
|
10
|
+
import type {Location} from 'history';
|
|
11
|
+
import {useDynamicCallback, usePrevious} from './reactUtils';
|
|
12
|
+
|
|
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 {
|
|
24
|
+
const location = useLocation();
|
|
25
|
+
const previousLocation = usePrevious(location);
|
|
26
|
+
|
|
27
|
+
const onLocationChangeDynamic = useDynamicCallback(onLocationChange);
|
|
28
|
+
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (!previousLocation) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (location !== previousLocation) {
|
|
35
|
+
onLocationChangeDynamic({
|
|
36
|
+
location,
|
|
37
|
+
previousLocation,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}, [onLocationChangeDynamic, location, previousLocation]);
|
|
41
|
+
}
|
|
@@ -49,36 +49,34 @@ function createLocalePluralForms(locale: string): LocalePluralForms {
|
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
52
|
+
/**
|
|
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
|
+
*
|
|
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
|
+
* ICU syntax (react-intl) just for that.
|
|
60
|
+
*
|
|
61
|
+
* Notes:
|
|
62
|
+
* - 2021: 92+% Browsers support `Intl.PluralRules`, and support will increase
|
|
63
|
+
* in the future
|
|
64
|
+
* - NodeJS >= 13 has full ICU support by default
|
|
65
|
+
* - In case of "mismatch" between SSR and Browser ICU support, React keeps
|
|
66
|
+
* working!
|
|
67
|
+
*/
|
|
63
68
|
function useLocalePluralForms(): LocalePluralForms {
|
|
64
69
|
const {
|
|
65
70
|
i18n: {currentLocale},
|
|
66
71
|
} = useDocusaurusContext();
|
|
67
72
|
return useMemo(() => {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
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}
|
|
75
79
|
`);
|
|
76
|
-
return EnglishPluralForms;
|
|
77
|
-
}
|
|
78
|
-
} else {
|
|
79
|
-
console.error(`Intl.PluralRules not available!
|
|
80
|
-
Docusaurus will fallback to a default/fallback (English) Intl.PluralRules implementation.
|
|
81
|
-
`);
|
|
82
80
|
return EnglishPluralForms;
|
|
83
81
|
}
|
|
84
82
|
}, [currentLocale]);
|
|
@@ -93,25 +91,37 @@ function selectPluralMessage(
|
|
|
93
91
|
const parts = pluralMessages.split(separator);
|
|
94
92
|
|
|
95
93
|
if (parts.length === 1) {
|
|
96
|
-
return parts[0]
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
const pluralForm = localePluralForms.select(count);
|
|
104
|
-
const pluralFormIndex = localePluralForms.pluralForms.indexOf(pluralForm);
|
|
105
|
-
// In case of not enough plural form messages, we take the last one (other) instead of returning undefined
|
|
106
|
-
return parts[Math.min(pluralFormIndex, parts.length - 1)];
|
|
94
|
+
return parts[0]!;
|
|
95
|
+
}
|
|
96
|
+
if (parts.length > localePluralForms.pluralForms.length) {
|
|
97
|
+
console.error(
|
|
98
|
+
`For locale=${localePluralForms.locale}, a maximum of ${localePluralForms.pluralForms.length} plural forms are expected (${localePluralForms.pluralForms}), but the message contains ${parts.length}: ${pluralMessages}`,
|
|
99
|
+
);
|
|
107
100
|
}
|
|
101
|
+
const pluralForm = localePluralForms.select(count);
|
|
102
|
+
const pluralFormIndex = localePluralForms.pluralForms.indexOf(pluralForm);
|
|
103
|
+
// In case of not enough plural form messages, we take the last one (other)
|
|
104
|
+
// instead of returning undefined
|
|
105
|
+
return parts[Math.min(pluralFormIndex, parts.length - 1)]!;
|
|
108
106
|
}
|
|
109
107
|
|
|
110
|
-
|
|
108
|
+
/**
|
|
109
|
+
* Reads the current locale and returns an interface very similar to
|
|
110
|
+
* `Intl.PluralRules`.
|
|
111
|
+
*/
|
|
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
|
+
*/
|
|
120
|
+
selectMessage: (count: number, pluralMessages: string) => string;
|
|
121
|
+
} {
|
|
111
122
|
const localePluralForm = useLocalePluralForms();
|
|
112
123
|
return {
|
|
113
|
-
selectMessage: (count: number, pluralMessages: string): string =>
|
|
114
|
-
|
|
115
|
-
},
|
|
124
|
+
selectMessage: (count: number, pluralMessages: string): string =>
|
|
125
|
+
selectPluralMessage(pluralMessages, count, localePluralForm),
|
|
116
126
|
};
|
|
117
127
|
}
|
|
@@ -4,9 +4,11 @@
|
|
|
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
|
+
|
|
7
8
|
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
8
|
-
import {PrismTheme} from 'prism-react-renderer';
|
|
9
|
-
import {
|
|
9
|
+
import type {PrismTheme} from 'prism-react-renderer';
|
|
10
|
+
import type {DeepPartial} from 'utility-types';
|
|
11
|
+
import type {MagicCommentConfig} from './codeBlockUtils';
|
|
10
12
|
|
|
11
13
|
export type DocsVersionPersistence = 'localStorage' | 'none';
|
|
12
14
|
|
|
@@ -16,11 +18,13 @@ export type NavbarItem = {
|
|
|
16
18
|
items?: NavbarItem[];
|
|
17
19
|
label?: string;
|
|
18
20
|
position?: 'left' | 'right';
|
|
19
|
-
};
|
|
21
|
+
} & {[key: string]: unknown};
|
|
20
22
|
|
|
21
23
|
export type NavbarLogo = {
|
|
22
24
|
src: string;
|
|
23
25
|
srcDark?: string;
|
|
26
|
+
width?: string | number;
|
|
27
|
+
height?: string | number;
|
|
24
28
|
href?: string;
|
|
25
29
|
target?: string;
|
|
26
30
|
alt?: string;
|
|
@@ -39,12 +43,6 @@ export type ColorModeConfig = {
|
|
|
39
43
|
defaultMode: 'light' | 'dark';
|
|
40
44
|
disableSwitch: boolean;
|
|
41
45
|
respectPrefersColorScheme: boolean;
|
|
42
|
-
switchConfig: {
|
|
43
|
-
darkIcon: string;
|
|
44
|
-
darkIconStyle: CSSProperties;
|
|
45
|
-
lightIcon: string;
|
|
46
|
-
lightIconStyle: CSSProperties;
|
|
47
|
-
};
|
|
48
46
|
};
|
|
49
47
|
|
|
50
48
|
export type AnnouncementBarConfig = {
|
|
@@ -56,10 +54,11 @@ export type AnnouncementBarConfig = {
|
|
|
56
54
|
};
|
|
57
55
|
|
|
58
56
|
export type PrismConfig = {
|
|
59
|
-
theme
|
|
57
|
+
theme: PrismTheme;
|
|
60
58
|
darkTheme?: PrismTheme;
|
|
61
59
|
defaultLanguage?: string;
|
|
62
|
-
additionalLanguages
|
|
60
|
+
additionalLanguages: string[];
|
|
61
|
+
magicComments: MagicCommentConfig[];
|
|
63
62
|
};
|
|
64
63
|
|
|
65
64
|
export type FooterLinkItem = {
|
|
@@ -68,26 +67,49 @@ export type FooterLinkItem = {
|
|
|
68
67
|
href?: string;
|
|
69
68
|
html?: string;
|
|
70
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;
|
|
71
79
|
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
items: FooterLinkItem[];
|
|
75
|
-
};
|
|
76
|
-
export type Footer = {
|
|
80
|
+
|
|
81
|
+
export type FooterBase = {
|
|
77
82
|
style: 'light' | 'dark';
|
|
78
|
-
logo?:
|
|
79
|
-
alt?: string;
|
|
80
|
-
src?: string;
|
|
81
|
-
srcDark?: string;
|
|
82
|
-
href?: string;
|
|
83
|
-
};
|
|
83
|
+
logo?: FooterLogo;
|
|
84
84
|
copyright?: string;
|
|
85
|
-
links: FooterLinks[];
|
|
86
85
|
};
|
|
87
86
|
|
|
87
|
+
export type MultiColumnFooter = FooterBase & {
|
|
88
|
+
links: Array<{
|
|
89
|
+
title: string | null;
|
|
90
|
+
items: FooterLinkItem[];
|
|
91
|
+
}>;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export type SimpleFooter = FooterBase & {
|
|
95
|
+
links: FooterLinkItem[];
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export type Footer = MultiColumnFooter | SimpleFooter;
|
|
99
|
+
|
|
100
|
+
export type TableOfContents = {
|
|
101
|
+
minHeadingLevel: number;
|
|
102
|
+
maxHeadingLevel: number;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// Theme config after validation/normalization
|
|
88
106
|
export type ThemeConfig = {
|
|
89
107
|
docs: {
|
|
90
108
|
versionPersistence: DocsVersionPersistence;
|
|
109
|
+
sidebar: {
|
|
110
|
+
hideable: boolean;
|
|
111
|
+
autoCollapseCategories: boolean;
|
|
112
|
+
};
|
|
91
113
|
};
|
|
92
114
|
|
|
93
115
|
// TODO we should complete this theme config type over time
|
|
@@ -100,10 +122,17 @@ export type ThemeConfig = {
|
|
|
100
122
|
announcementBar?: AnnouncementBarConfig;
|
|
101
123
|
prism: PrismConfig;
|
|
102
124
|
footer?: Footer;
|
|
103
|
-
|
|
104
|
-
|
|
125
|
+
image?: string;
|
|
126
|
+
metadata: Array<{[key: string]: string}>;
|
|
127
|
+
tableOfContents: TableOfContents;
|
|
105
128
|
};
|
|
106
129
|
|
|
130
|
+
// User-provided theme config, unnormalized
|
|
131
|
+
export type UserThemeConfig = DeepPartial<ThemeConfig>;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* A convenient/more semantic way to get theme config from context.
|
|
135
|
+
*/
|
|
107
136
|
export function useThemeConfig(): ThemeConfig {
|
|
108
137
|
return useDocusaurusContext().siteConfig.themeConfig as ThemeConfig;
|
|
109
138
|
}
|