@azerion/bunosaurus-theme-common 0.0.0-stage → 4.0.0
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/README.md +2 -2
- package/lib/components/Collapsible/index.d.ts +59 -0
- package/lib/components/Collapsible/index.d.ts.map +1 -0
- package/lib/components/Collapsible/index.js +145 -0
- package/lib/components/Collapsible/index.js.map +1 -0
- package/lib/components/Details/index.d.ts +20 -0
- package/lib/components/Details/index.d.ts.map +1 -0
- package/lib/components/Details/index.js +86 -0
- package/lib/components/Details/index.js.map +1 -0
- package/lib/components/Details/styles.module.css +66 -0
- package/lib/components/ThemedComponent/index.d.ts +31 -0
- package/lib/components/ThemedComponent/index.d.ts.map +1 -0
- package/lib/components/ThemedComponent/index.js +47 -0
- package/lib/components/ThemedComponent/index.js.map +1 -0
- package/lib/components/ThemedComponent/styles.module.css +26 -0
- package/lib/contexts/announcementBar.d.ts +21 -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 +23 -0
- package/lib/contexts/colorMode.d.ts.map +1 -0
- package/lib/contexts/colorMode.js +163 -0
- package/lib/contexts/colorMode.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 +65 -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 +50 -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/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 +15 -0
- package/lib/hooks/useCodeWordWrap.d.ts.map +1 -0
- package/lib/hooks/useCodeWordWrap.js +67 -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 +65 -0
- package/lib/hooks/useHideableNavbar.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/useMutationObserver.d.ts +4 -0
- package/lib/hooks/useMutationObserver.d.ts.map +1 -0
- package/lib/hooks/useMutationObserver.js +29 -0
- package/lib/hooks/useMutationObserver.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/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 +27 -0
- package/lib/hooks/useWindowSize.d.ts.map +1 -0
- package/lib/hooks/useWindowSize.js +49 -0
- package/lib/hooks/useWindowSize.js.map +1 -0
- package/lib/index.d.ts +30 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +37 -0
- package/lib/index.js.map +1 -0
- package/lib/internal.d.ts +35 -0
- package/lib/internal.d.ts.map +1 -0
- package/lib/internal.js +45 -0
- package/lib/internal.js.map +1 -0
- package/lib/translations/blogTranslations.d.ts +20 -0
- package/lib/translations/blogTranslations.d.ts.map +1 -0
- package/lib/translations/blogTranslations.js +52 -0
- package/lib/translations/blogTranslations.js.map +1 -0
- package/lib/translations/contentVisibilityTranslations.d.ts +12 -0
- package/lib/translations/contentVisibilityTranslations.d.ts.map +1 -0
- package/lib/translations/contentVisibilityTranslations.js +30 -0
- package/lib/translations/contentVisibilityTranslations.js.map +1 -0
- package/lib/translations/docsTranslations.d.ts +8 -0
- package/lib/translations/docsTranslations.d.ts.map +1 -0
- package/lib/translations/docsTranslations.js +17 -0
- package/lib/translations/docsTranslations.js.map +1 -0
- package/lib/utils/IntlUtils.d.ts +2 -0
- package/lib/utils/IntlUtils.d.ts.map +1 -0
- package/lib/utils/IntlUtils.js +20 -0
- package/lib/utils/IntlUtils.js.map +1 -0
- package/lib/utils/ThemeClassNames.d.ts +99 -0
- package/lib/utils/ThemeClassNames.d.ts.map +1 -0
- package/lib/utils/ThemeClassNames.js +107 -0
- package/lib/utils/ThemeClassNames.js.map +1 -0
- package/lib/utils/accessibilityUtils.d.ts +8 -0
- package/lib/utils/accessibilityUtils.d.ts.map +1 -0
- package/lib/utils/accessibilityUtils.js +10 -0
- package/lib/utils/accessibilityUtils.js.map +1 -0
- package/lib/utils/admonitionUtils.d.ts +12 -0
- package/lib/utils/admonitionUtils.d.ts.map +1 -0
- package/lib/utils/admonitionUtils.js +32 -0
- package/lib/utils/admonitionUtils.js.map +1 -0
- package/lib/utils/anchorUtils.d.ts +16 -0
- package/lib/utils/anchorUtils.d.ts.map +1 -0
- package/lib/utils/anchorUtils.js +26 -0
- package/lib/utils/anchorUtils.js.map +1 -0
- package/lib/utils/anchorUtils.module.css +14 -0
- package/lib/utils/codeBlockUtils.d.ts +101 -0
- package/lib/utils/codeBlockUtils.d.ts.map +1 -0
- package/lib/utils/codeBlockUtils.js +310 -0
- package/lib/utils/codeBlockUtils.js.map +1 -0
- package/lib/utils/emojiUtils.d.ts +20 -0
- package/lib/utils/emojiUtils.d.ts.map +1 -0
- package/lib/utils/emojiUtils.js +32 -0
- package/lib/utils/emojiUtils.js.map +1 -0
- package/lib/utils/errorBoundaryUtils.d.ts +31 -0
- package/lib/utils/errorBoundaryUtils.d.ts.map +1 -0
- package/lib/utils/errorBoundaryUtils.js +48 -0
- package/lib/utils/errorBoundaryUtils.js.map +1 -0
- package/lib/utils/errorBoundaryUtils.module.css +16 -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/historyUtils.d.ts +39 -0
- package/lib/utils/historyUtils.d.ts.map +1 -0
- package/lib/utils/historyUtils.js +148 -0
- package/lib/utils/historyUtils.js.map +1 -0
- package/lib/utils/jsUtils.d.ts +24 -0
- package/lib/utils/jsUtils.d.ts.map +1 -0
- package/lib/utils/jsUtils.js +43 -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 +87 -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 +35 -0
- package/lib/utils/navbarUtils.js.map +1 -0
- package/lib/utils/reactUtils.d.ts +60 -0
- package/lib/utils/reactUtils.d.ts.map +1 -0
- package/lib/utils/reactUtils.js +91 -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 +201 -0
- package/lib/utils/scrollUtils.js.map +1 -0
- package/lib/utils/searchUtils.d.ts +8 -0
- package/lib/utils/searchUtils.d.ts.map +1 -0
- package/lib/utils/searchUtils.js +8 -0
- package/lib/utils/searchUtils.js.map +1 -0
- package/lib/utils/skipToContentUtils.d.ts +20 -0
- package/lib/utils/skipToContentUtils.d.ts.map +1 -0
- package/lib/utils/skipToContentUtils.js +75 -0
- package/lib/utils/skipToContentUtils.js.map +1 -0
- package/lib/utils/storageUtils.d.ts +36 -0
- package/lib/utils/storageUtils.d.ts.map +1 -0
- package/lib/utils/storageUtils.js +193 -0
- package/lib/utils/storageUtils.js.map +1 -0
- package/lib/utils/tabsUtils.d.ts +55 -0
- package/lib/utils/tabsUtils.d.ts.map +1 -0
- package/lib/utils/tabsUtils.js +179 -0
- package/lib/utils/tabsUtils.js.map +1 -0
- package/lib/utils/tagsUtils.d.ts +20 -0
- package/lib/utils/tagsUtils.d.ts.map +1 -0
- package/lib/utils/tagsUtils.js +41 -0
- package/lib/utils/tagsUtils.js.map +1 -0
- package/lib/utils/titleFormatterUtils.d.ts +59 -0
- package/lib/utils/titleFormatterUtils.d.ts.map +1 -0
- package/lib/utils/titleFormatterUtils.js +49 -0
- package/lib/utils/titleFormatterUtils.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 +32 -0
- package/lib/utils/useAlternatePageUtils.d.ts.map +1 -0
- package/lib/utils/useAlternatePageUtils.js +42 -0
- 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 +21 -0
- package/lib/utils/usePluralForm.d.ts.map +1 -0
- package/lib/utils/usePluralForm.js +93 -0
- package/lib/utils/usePluralForm.js.map +1 -0
- package/lib/utils/useThemeConfig.d.ts +120 -0
- package/lib/utils/useThemeConfig.d.ts.map +1 -0
- package/lib/utils/useThemeConfig.js +14 -0
- package/lib/utils/useThemeConfig.js.map +1 -0
- package/package.json +58 -4
- package/src/components/Collapsible/index.tsx +250 -0
- package/src/components/Details/index.tsx +130 -0
- package/src/components/Details/styles.module.css +66 -0
- package/src/components/ThemedComponent/index.tsx +75 -0
- package/src/components/ThemedComponent/styles.module.css +26 -0
- package/src/contexts/announcementBar.tsx +117 -0
- package/src/contexts/colorMode.tsx +257 -0
- package/src/contexts/navbarMobileSidebar.tsx +119 -0
- package/src/contexts/navbarSecondaryMenu/content.tsx +100 -0
- package/src/contexts/navbarSecondaryMenu/display.tsx +102 -0
- package/src/hooks/useBackToTopButton.ts +73 -0
- package/src/hooks/useCodeWordWrap.ts +107 -0
- package/src/hooks/useHideableNavbar.ts +81 -0
- package/src/hooks/useLockBodyScroll.ts +21 -0
- package/src/hooks/useMutationObserver.ts +38 -0
- package/src/hooks/usePrismTheme.ts +24 -0
- package/src/hooks/useTOCHighlight.ts +189 -0
- package/src/hooks/useWindowSize.ts +67 -0
- package/src/index.ts +112 -0
- package/src/internal.ts +107 -0
- package/src/translations/blogTranslations.tsx +89 -0
- package/src/translations/contentVisibilityTranslations.tsx +51 -0
- package/src/translations/docsTranslations.tsx +28 -0
- package/src/types.d.ts +8 -0
- package/src/utils/IntlUtils.ts +27 -0
- package/src/utils/ThemeClassNames.ts +119 -0
- package/src/utils/accessibilityUtils.ts +10 -0
- package/src/utils/admonitionUtils.tsx +44 -0
- package/src/utils/anchorUtils.module.css +14 -0
- package/src/utils/anchorUtils.ts +31 -0
- package/src/utils/codeBlockUtils.tsx +494 -0
- package/src/utils/emojiUtils.ts +40 -0
- package/src/utils/errorBoundaryUtils.module.css +16 -0
- package/src/utils/errorBoundaryUtils.tsx +71 -0
- package/src/utils/footerUtils.ts +18 -0
- package/src/utils/historyUtils.ts +199 -0
- package/src/utils/jsUtils.ts +54 -0
- package/src/utils/metadataUtils.tsx +145 -0
- package/src/utils/navbarUtils.tsx +45 -0
- package/src/utils/reactUtils.tsx +120 -0
- package/src/utils/regexpUtils.ts +24 -0
- package/src/utils/routesUtils.ts +75 -0
- package/src/utils/scrollUtils.tsx +303 -0
- package/src/utils/searchUtils.ts +8 -0
- package/src/utils/skipToContentUtils.tsx +108 -0
- package/src/utils/storageUtils.ts +260 -0
- package/src/utils/tabsUtils.tsx +307 -0
- package/src/utils/tagsUtils.tsx +61 -0
- package/src/utils/titleFormatterUtils.tsx +120 -0
- package/src/utils/tocUtils.ts +119 -0
- package/src/utils/useAlternatePageUtils.ts +80 -0
- package/src/utils/useLocalPathname.ts +22 -0
- package/src/utils/useLocationChange.ts +41 -0
- package/src/utils/usePluralForm.ts +131 -0
- package/src/utils/useThemeConfig.ts +147 -0
|
@@ -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 {useEvent, usePrevious} from './reactUtils';
|
|
11
|
+
import type {Location} from 'history';
|
|
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 = useEvent(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
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
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 {useMemo} from 'react';
|
|
9
|
+
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
10
|
+
|
|
11
|
+
// We want to ensurer a stable plural form order in all cases
|
|
12
|
+
// It is more convenient and natural to handle "small values" first
|
|
13
|
+
// See https://x.com/sebastienlorber/status/1366820663261077510
|
|
14
|
+
const OrderedPluralForms: Intl.LDMLPluralRule[] = [
|
|
15
|
+
'zero',
|
|
16
|
+
'one',
|
|
17
|
+
'two',
|
|
18
|
+
'few',
|
|
19
|
+
'many',
|
|
20
|
+
'other',
|
|
21
|
+
];
|
|
22
|
+
function sortPluralForms(
|
|
23
|
+
pluralForms: Intl.LDMLPluralRule[],
|
|
24
|
+
): Intl.LDMLPluralRule[] {
|
|
25
|
+
return OrderedPluralForms.filter((pf) => pluralForms.includes(pf));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type LocalePluralForms = {
|
|
29
|
+
locale: string;
|
|
30
|
+
pluralForms: Intl.LDMLPluralRule[];
|
|
31
|
+
select: (count: number) => Intl.LDMLPluralRule;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// Hardcoded english/fallback implementation
|
|
35
|
+
const EnglishPluralForms: LocalePluralForms = {
|
|
36
|
+
locale: 'en',
|
|
37
|
+
pluralForms: sortPluralForms(['one', 'other']),
|
|
38
|
+
select: (count) => (count === 1 ? 'one' : 'other'),
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
function createLocalePluralForms(locale: string): LocalePluralForms {
|
|
42
|
+
const pluralRules = new Intl.PluralRules(locale);
|
|
43
|
+
return {
|
|
44
|
+
locale,
|
|
45
|
+
pluralForms: sortPluralForms(
|
|
46
|
+
pluralRules.resolvedOptions().pluralCategories,
|
|
47
|
+
),
|
|
48
|
+
select: (count) => pluralRules.select(count),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
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
|
+
*/
|
|
68
|
+
function useLocalePluralForms(): LocalePluralForms {
|
|
69
|
+
const {
|
|
70
|
+
i18n: {currentLocale},
|
|
71
|
+
} = useDocusaurusContext();
|
|
72
|
+
return useMemo(() => {
|
|
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}
|
|
79
|
+
`);
|
|
80
|
+
return EnglishPluralForms;
|
|
81
|
+
}
|
|
82
|
+
}, [currentLocale]);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function selectPluralMessage(
|
|
86
|
+
pluralMessages: string,
|
|
87
|
+
count: number,
|
|
88
|
+
localePluralForms: LocalePluralForms,
|
|
89
|
+
): string {
|
|
90
|
+
const separator = '|';
|
|
91
|
+
const parts = pluralMessages.split(separator);
|
|
92
|
+
|
|
93
|
+
if (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 ${
|
|
99
|
+
localePluralForms.pluralForms.length
|
|
100
|
+
} plural forms are expected (${localePluralForms.pluralForms.join(
|
|
101
|
+
',',
|
|
102
|
+
)}), but the message contains ${parts.length}: ${pluralMessages}`,
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
const pluralForm = localePluralForms.select(count);
|
|
106
|
+
const pluralFormIndex = localePluralForms.pluralForms.indexOf(pluralForm);
|
|
107
|
+
// In case of not enough plural form messages, we take the last one (other)
|
|
108
|
+
// instead of returning undefined
|
|
109
|
+
return parts[Math.min(pluralFormIndex, parts.length - 1)]!;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Reads the current locale and returns an interface very similar to
|
|
114
|
+
* `Intl.PluralRules`.
|
|
115
|
+
*/
|
|
116
|
+
export function usePluralForm(): {
|
|
117
|
+
/**
|
|
118
|
+
* Give it a `count` and it will select the relevant message from
|
|
119
|
+
* `pluralMessages`. `pluralMessages` should be separated by `|`, and in the
|
|
120
|
+
* order of "zero", "one", "two", "few", "many", "other". The actual selection
|
|
121
|
+
* is done by `Intl.PluralRules`, which tells us all plurals the locale has
|
|
122
|
+
* and which plural we should use for `count`.
|
|
123
|
+
*/
|
|
124
|
+
selectMessage: (count: number, pluralMessages: string) => string;
|
|
125
|
+
} {
|
|
126
|
+
const localePluralForm = useLocalePluralForms();
|
|
127
|
+
return {
|
|
128
|
+
selectMessage: (count: number, pluralMessages: string): string =>
|
|
129
|
+
selectPluralMessage(pluralMessages, count, localePluralForm),
|
|
130
|
+
};
|
|
131
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
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 useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
9
|
+
import type {PrismTheme} from 'prism-react-renderer';
|
|
10
|
+
import type {DeepPartial} from 'utility-types';
|
|
11
|
+
import type {MagicCommentConfig} from './codeBlockUtils';
|
|
12
|
+
import type {ColorMode} from '../contexts/colorMode';
|
|
13
|
+
|
|
14
|
+
type DocsVersionPersistence = 'localStorage' | 'none';
|
|
15
|
+
|
|
16
|
+
// TODO improve types, use unions
|
|
17
|
+
export type NavbarItem = {
|
|
18
|
+
type?: string;
|
|
19
|
+
items?: NavbarItem[];
|
|
20
|
+
label?: string;
|
|
21
|
+
position?: 'left' | 'right';
|
|
22
|
+
} & {[key: string]: unknown};
|
|
23
|
+
|
|
24
|
+
type BaseLogo = {
|
|
25
|
+
alt?: string;
|
|
26
|
+
src: string;
|
|
27
|
+
srcDark?: string;
|
|
28
|
+
href?: string;
|
|
29
|
+
width?: string | number;
|
|
30
|
+
height?: string | number;
|
|
31
|
+
target?: string;
|
|
32
|
+
style?: object;
|
|
33
|
+
className?: string;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type NavbarLogo = BaseLogo;
|
|
37
|
+
|
|
38
|
+
// TODO improve
|
|
39
|
+
export type Navbar = {
|
|
40
|
+
style?: 'dark' | 'primary';
|
|
41
|
+
hideOnScroll: boolean;
|
|
42
|
+
title?: string;
|
|
43
|
+
items: NavbarItem[];
|
|
44
|
+
logo?: NavbarLogo;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type ColorModeConfig = {
|
|
48
|
+
defaultMode: ColorMode;
|
|
49
|
+
disableSwitch: boolean;
|
|
50
|
+
respectPrefersColorScheme: boolean;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
type AnnouncementBarConfig = {
|
|
54
|
+
id: string;
|
|
55
|
+
content: string;
|
|
56
|
+
backgroundColor: string;
|
|
57
|
+
textColor: string;
|
|
58
|
+
isCloseable: boolean;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
type PrismConfig = {
|
|
62
|
+
theme: PrismTheme;
|
|
63
|
+
darkTheme?: PrismTheme;
|
|
64
|
+
defaultLanguage?: string;
|
|
65
|
+
additionalLanguages: string[];
|
|
66
|
+
magicComments: MagicCommentConfig[];
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export type FooterLinkItem = {
|
|
70
|
+
label?: string;
|
|
71
|
+
className?: string;
|
|
72
|
+
to?: string;
|
|
73
|
+
href?: string;
|
|
74
|
+
html?: string;
|
|
75
|
+
prependBaseUrlToHref?: string;
|
|
76
|
+
} & {[key: string]: unknown};
|
|
77
|
+
|
|
78
|
+
export type FooterColumnItem = {
|
|
79
|
+
title: string | null;
|
|
80
|
+
className?: string;
|
|
81
|
+
items: FooterLinkItem[];
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export type FooterLogo = BaseLogo;
|
|
85
|
+
|
|
86
|
+
type FooterBase = {
|
|
87
|
+
style: 'light' | 'dark';
|
|
88
|
+
logo?: FooterLogo;
|
|
89
|
+
copyright?: string;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export type MultiColumnFooter = FooterBase & {
|
|
93
|
+
links: FooterColumnItem[];
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export type SimpleFooter = FooterBase & {
|
|
97
|
+
links: FooterLinkItem[];
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export type Footer = MultiColumnFooter | SimpleFooter;
|
|
101
|
+
|
|
102
|
+
type TableOfContents = {
|
|
103
|
+
minHeadingLevel: number;
|
|
104
|
+
maxHeadingLevel: number;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// TODO Docusaurus v4: use interface + declaration merging to enhance
|
|
108
|
+
// Theme config after validation/normalization
|
|
109
|
+
export type ThemeConfig = {
|
|
110
|
+
docs: {
|
|
111
|
+
versionPersistence: DocsVersionPersistence;
|
|
112
|
+
sidebar: {
|
|
113
|
+
hideable: boolean;
|
|
114
|
+
autoCollapseCategories: boolean;
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
blog: {
|
|
119
|
+
sidebar: {
|
|
120
|
+
groupByYear: boolean;
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// TODO we should complete this theme config type over time
|
|
125
|
+
// and share it across all themes
|
|
126
|
+
// and use it in the Joi validation schema?
|
|
127
|
+
|
|
128
|
+
// TODO temporary types
|
|
129
|
+
navbar: Navbar;
|
|
130
|
+
colorMode: ColorModeConfig;
|
|
131
|
+
announcementBar?: AnnouncementBarConfig;
|
|
132
|
+
prism: PrismConfig;
|
|
133
|
+
footer?: Footer;
|
|
134
|
+
image?: string;
|
|
135
|
+
metadata: {[key: string]: string}[];
|
|
136
|
+
tableOfContents: TableOfContents;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
// User-provided theme config, unnormalized
|
|
140
|
+
export type UserThemeConfig = DeepPartial<ThemeConfig>;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* A convenient/more semantic way to get theme config from context.
|
|
144
|
+
*/
|
|
145
|
+
export function useThemeConfig(): ThemeConfig {
|
|
146
|
+
return useDocusaurusContext().siteConfig.themeConfig as ThemeConfig;
|
|
147
|
+
}
|