@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.
Files changed (250) hide show
  1. package/Details.d.ts +14 -0
  2. package/lib/components/Collapsible/index.d.ts +64 -0
  3. package/lib/components/Collapsible/index.d.ts.map +1 -0
  4. package/lib/components/Collapsible/index.js +152 -0
  5. package/lib/components/Collapsible/index.js.map +1 -0
  6. package/lib/components/Details/index.d.ts +17 -0
  7. package/lib/components/Details/index.d.ts.map +1 -0
  8. package/lib/components/Details/index.js +71 -0
  9. package/lib/components/Details/index.js.map +1 -0
  10. package/lib/components/Details/styles.module.css +62 -0
  11. package/lib/contexts/announcementBar.d.ts +22 -0
  12. package/lib/contexts/announcementBar.d.ts.map +1 -0
  13. package/lib/contexts/announcementBar.js +72 -0
  14. package/lib/contexts/announcementBar.js.map +1 -0
  15. package/lib/contexts/colorMode.d.ts +27 -0
  16. package/lib/contexts/colorMode.d.ts.map +1 -0
  17. package/lib/contexts/colorMode.js +132 -0
  18. package/lib/contexts/colorMode.js.map +1 -0
  19. package/lib/contexts/docSidebarItemsExpandedState.d.ts +31 -0
  20. package/lib/contexts/docSidebarItemsExpandedState.d.ts.map +1 -0
  21. package/lib/contexts/docSidebarItemsExpandedState.js +28 -0
  22. package/lib/contexts/docSidebarItemsExpandedState.js.map +1 -0
  23. package/lib/contexts/docsPreferredVersion.d.ts +31 -0
  24. package/lib/contexts/docsPreferredVersion.d.ts.map +1 -0
  25. package/lib/contexts/docsPreferredVersion.js +128 -0
  26. package/lib/contexts/docsPreferredVersion.js.map +1 -0
  27. package/lib/contexts/docsSidebar.d.ts +26 -0
  28. package/lib/contexts/docsSidebar.d.ts.map +1 -0
  29. package/lib/contexts/docsSidebar.js +30 -0
  30. package/lib/contexts/docsSidebar.js.map +1 -0
  31. package/lib/contexts/docsVersion.d.ts +20 -0
  32. package/lib/contexts/docsVersion.d.ts.map +1 -0
  33. package/lib/contexts/docsVersion.js +26 -0
  34. package/lib/contexts/docsVersion.js.map +1 -0
  35. package/lib/contexts/navbarMobileSidebar.d.ts +31 -0
  36. package/lib/contexts/navbarMobileSidebar.d.ts.map +1 -0
  37. package/lib/contexts/navbarMobileSidebar.js +56 -0
  38. package/lib/contexts/navbarMobileSidebar.js.map +1 -0
  39. package/lib/contexts/navbarSecondaryMenu/content.d.ts +37 -0
  40. package/lib/contexts/navbarSecondaryMenu/content.d.ts.map +1 -0
  41. package/lib/contexts/navbarSecondaryMenu/content.js +56 -0
  42. package/lib/contexts/navbarSecondaryMenu/content.js.map +1 -0
  43. package/lib/contexts/navbarSecondaryMenu/display.d.ts +24 -0
  44. package/lib/contexts/navbarSecondaryMenu/display.d.ts.map +1 -0
  45. package/lib/contexts/navbarSecondaryMenu/display.js +62 -0
  46. package/lib/contexts/navbarSecondaryMenu/display.js.map +1 -0
  47. package/lib/contexts/tabGroupChoice.d.ts +21 -0
  48. package/lib/contexts/tabGroupChoice.d.ts.map +1 -0
  49. package/lib/contexts/tabGroupChoice.js +49 -0
  50. package/lib/contexts/tabGroupChoice.js.map +1 -0
  51. package/lib/{utils/useChangeRoute.d.ts → hooks/styles.css} +4 -1
  52. package/lib/hooks/useBackToTopButton.d.ts +27 -0
  53. package/lib/hooks/useBackToTopButton.d.ts.map +1 -0
  54. package/lib/hooks/useBackToTopButton.js +50 -0
  55. package/lib/hooks/useBackToTopButton.js.map +1 -0
  56. package/lib/hooks/useCodeWordWrap.d.ts +14 -0
  57. package/lib/hooks/useCodeWordWrap.d.ts.map +1 -0
  58. package/lib/hooks/useCodeWordWrap.js +41 -0
  59. package/lib/hooks/useCodeWordWrap.js.map +1 -0
  60. package/lib/hooks/useHideableNavbar.d.ts +17 -0
  61. package/lib/hooks/useHideableNavbar.d.ts.map +1 -0
  62. package/lib/hooks/useHideableNavbar.js +60 -0
  63. package/lib/hooks/useHideableNavbar.js.map +1 -0
  64. package/lib/hooks/useKeyboardNavigation.d.ts +20 -0
  65. package/lib/hooks/useKeyboardNavigation.d.ts.map +1 -0
  66. package/lib/hooks/useKeyboardNavigation.js +39 -0
  67. package/lib/hooks/useKeyboardNavigation.js.map +1 -0
  68. package/lib/hooks/useLockBodyScroll.d.ts +12 -0
  69. package/lib/hooks/useLockBodyScroll.d.ts.map +1 -0
  70. package/lib/hooks/useLockBodyScroll.js +20 -0
  71. package/lib/hooks/useLockBodyScroll.js.map +1 -0
  72. package/lib/hooks/usePrismTheme.d.ts +13 -0
  73. package/lib/hooks/usePrismTheme.d.ts.map +1 -0
  74. package/lib/hooks/usePrismTheme.js +21 -0
  75. package/lib/hooks/usePrismTheme.js.map +1 -0
  76. package/lib/hooks/useSearchPage.d.ts +25 -0
  77. package/lib/hooks/useSearchPage.d.ts.map +1 -0
  78. package/lib/hooks/useSearchPage.js +43 -0
  79. package/lib/hooks/useSearchPage.js.map +1 -0
  80. package/lib/hooks/useSkipToContent.d.ts +25 -0
  81. package/lib/hooks/useSkipToContent.d.ts.map +1 -0
  82. package/lib/hooks/useSkipToContent.js +35 -0
  83. package/lib/hooks/useSkipToContent.js.map +1 -0
  84. package/lib/hooks/useTOCHighlight.d.ts +25 -0
  85. package/lib/hooks/useTOCHighlight.d.ts.map +1 -0
  86. package/lib/hooks/useTOCHighlight.js +130 -0
  87. package/lib/hooks/useTOCHighlight.js.map +1 -0
  88. package/lib/hooks/useWindowSize.d.ts +28 -0
  89. package/lib/hooks/useWindowSize.d.ts.map +1 -0
  90. package/lib/hooks/useWindowSize.js +59 -0
  91. package/lib/hooks/useWindowSize.js.map +1 -0
  92. package/lib/index.d.ts +39 -9
  93. package/lib/index.d.ts.map +1 -0
  94. package/lib/index.js +39 -8
  95. package/lib/index.js.map +1 -0
  96. package/lib/utils/ThemeClassNames.d.ts +47 -12
  97. package/lib/utils/ThemeClassNames.d.ts.map +1 -0
  98. package/lib/utils/ThemeClassNames.js +45 -4
  99. package/lib/utils/ThemeClassNames.js.map +1 -0
  100. package/lib/utils/codeBlockUtils.d.ts +63 -0
  101. package/lib/utils/codeBlockUtils.d.ts.map +1 -0
  102. package/lib/utils/codeBlockUtils.js +157 -3
  103. package/lib/utils/codeBlockUtils.js.map +1 -0
  104. package/lib/utils/docsUtils.d.ts +91 -0
  105. package/lib/utils/docsUtils.d.ts.map +1 -0
  106. package/lib/utils/docsUtils.js +217 -1
  107. package/lib/utils/docsUtils.js.map +1 -0
  108. package/lib/utils/footerUtils.d.ts +13 -0
  109. package/lib/utils/footerUtils.d.ts.map +1 -0
  110. package/lib/utils/footerUtils.js +14 -0
  111. package/lib/utils/footerUtils.js.map +1 -0
  112. package/lib/utils/generalUtils.d.ts +11 -1
  113. package/lib/utils/generalUtils.d.ts.map +1 -0
  114. package/lib/utils/generalUtils.js +9 -5
  115. package/lib/utils/generalUtils.js.map +1 -0
  116. package/lib/utils/historyUtils.d.ts +17 -0
  117. package/lib/utils/historyUtils.d.ts.map +1 -0
  118. package/lib/utils/historyUtils.js +38 -0
  119. package/lib/utils/historyUtils.js.map +1 -0
  120. package/lib/utils/jsUtils.d.ts +23 -0
  121. package/lib/utils/jsUtils.d.ts.map +1 -0
  122. package/lib/utils/jsUtils.js +29 -0
  123. package/lib/utils/jsUtils.js.map +1 -0
  124. package/lib/utils/metadataUtils.d.ts +38 -0
  125. package/lib/utils/metadataUtils.d.ts.map +1 -0
  126. package/lib/utils/metadataUtils.js +61 -0
  127. package/lib/utils/metadataUtils.js.map +1 -0
  128. package/lib/utils/navbarUtils.d.ts +21 -0
  129. package/lib/utils/navbarUtils.d.ts.map +1 -0
  130. package/lib/utils/navbarUtils.js +32 -0
  131. package/lib/utils/navbarUtils.js.map +1 -0
  132. package/lib/utils/reactUtils.d.ts +42 -0
  133. package/lib/utils/reactUtils.d.ts.map +1 -0
  134. package/lib/utils/reactUtils.js +64 -0
  135. package/lib/utils/reactUtils.js.map +1 -0
  136. package/lib/utils/regexpUtils.d.ts +12 -0
  137. package/lib/utils/regexpUtils.d.ts.map +1 -0
  138. package/lib/utils/regexpUtils.js +18 -0
  139. package/lib/utils/regexpUtils.js.map +1 -0
  140. package/lib/utils/routesUtils.d.ts +26 -0
  141. package/lib/utils/routesUtils.d.ts.map +1 -0
  142. package/lib/utils/routesUtils.js +54 -0
  143. package/lib/utils/routesUtils.js.map +1 -0
  144. package/lib/utils/scrollUtils.d.ts +83 -0
  145. package/lib/utils/scrollUtils.d.ts.map +1 -0
  146. package/lib/utils/scrollUtils.js +200 -0
  147. package/lib/utils/scrollUtils.js.map +1 -0
  148. package/lib/utils/searchUtils.d.ts +13 -0
  149. package/lib/utils/searchUtils.d.ts.map +1 -0
  150. package/lib/utils/searchUtils.js +37 -0
  151. package/lib/utils/searchUtils.js.map +1 -0
  152. package/lib/utils/storageUtils.d.ts +15 -7
  153. package/lib/utils/storageUtils.d.ts.map +1 -0
  154. package/lib/utils/storageUtils.js +58 -25
  155. package/lib/utils/storageUtils.js.map +1 -0
  156. package/lib/utils/tagsUtils.d.ts +18 -0
  157. package/lib/utils/tagsUtils.d.ts.map +1 -0
  158. package/lib/utils/tagsUtils.js +36 -0
  159. package/lib/utils/tagsUtils.js.map +1 -0
  160. package/lib/utils/tocUtils.d.ts +36 -0
  161. package/lib/utils/tocUtils.d.ts.map +1 -0
  162. package/lib/utils/tocUtils.js +84 -0
  163. package/lib/utils/tocUtils.js.map +1 -0
  164. package/lib/utils/useAlternatePageUtils.d.ts +21 -1
  165. package/lib/utils/useAlternatePageUtils.d.ts.map +1 -0
  166. package/lib/utils/useAlternatePageUtils.js +9 -4
  167. package/lib/utils/useAlternatePageUtils.js.map +1 -0
  168. package/lib/utils/useLocalPathname.d.ts +13 -0
  169. package/lib/utils/useLocalPathname.d.ts.map +1 -0
  170. package/lib/utils/useLocalPathname.js +19 -0
  171. package/lib/utils/useLocalPathname.js.map +1 -0
  172. package/lib/utils/useLocationChange.d.ts +17 -0
  173. package/lib/utils/useLocationChange.d.ts.map +1 -0
  174. package/lib/utils/useLocationChange.js +31 -0
  175. package/lib/utils/useLocationChange.js.map +1 -0
  176. package/lib/utils/usePluralForm.d.ts +12 -0
  177. package/lib/utils/usePluralForm.d.ts.map +1 -0
  178. package/lib/utils/usePluralForm.js +36 -37
  179. package/lib/utils/usePluralForm.js.map +1 -0
  180. package/lib/utils/useThemeConfig.d.ts +55 -23
  181. package/lib/utils/useThemeConfig.d.ts.map +1 -0
  182. package/lib/utils/useThemeConfig.js +4 -0
  183. package/lib/utils/useThemeConfig.js.map +1 -0
  184. package/package.json +26 -13
  185. package/src/components/Collapsible/index.tsx +265 -0
  186. package/src/components/Details/index.tsx +109 -0
  187. package/src/components/Details/styles.module.css +62 -0
  188. package/src/contexts/announcementBar.tsx +119 -0
  189. package/src/contexts/colorMode.tsx +199 -0
  190. package/src/contexts/docSidebarItemsExpandedState.tsx +55 -0
  191. package/src/contexts/docsPreferredVersion.tsx +253 -0
  192. package/src/contexts/docsSidebar.tsx +50 -0
  193. package/src/contexts/docsVersion.tsx +36 -0
  194. package/src/contexts/navbarMobileSidebar.tsx +99 -0
  195. package/src/contexts/navbarSecondaryMenu/content.tsx +110 -0
  196. package/src/contexts/navbarSecondaryMenu/display.tsx +102 -0
  197. package/src/contexts/tabGroupChoice.tsx +85 -0
  198. package/{lib/utils/pathUtils.d.ts → src/hooks/styles.css} +4 -1
  199. package/src/hooks/useBackToTopButton.ts +73 -0
  200. package/src/hooks/useCodeWordWrap.ts +56 -0
  201. package/src/hooks/useHideableNavbar.ts +75 -0
  202. package/src/hooks/useKeyboardNavigation.ts +45 -0
  203. package/src/hooks/useLockBodyScroll.ts +21 -0
  204. package/src/hooks/usePrismTheme.ts +24 -0
  205. package/src/hooks/useSearchPage.ts +79 -0
  206. package/src/hooks/useSkipToContent.ts +58 -0
  207. package/src/hooks/useTOCHighlight.ts +192 -0
  208. package/src/hooks/useWindowSize.ts +72 -0
  209. package/src/index.ts +136 -18
  210. package/src/types.d.ts +0 -2
  211. package/src/utils/ThemeClassNames.ts +51 -5
  212. package/src/utils/codeBlockUtils.ts +239 -2
  213. package/src/utils/docsUtils.tsx +334 -0
  214. package/src/utils/footerUtils.ts +18 -0
  215. package/src/utils/generalUtils.ts +9 -5
  216. package/src/utils/historyUtils.ts +45 -0
  217. package/src/utils/jsUtils.ts +36 -0
  218. package/src/utils/metadataUtils.tsx +115 -0
  219. package/src/utils/navbarUtils.tsx +45 -0
  220. package/src/utils/reactUtils.tsx +76 -0
  221. package/src/utils/regexpUtils.ts +24 -0
  222. package/src/utils/routesUtils.ts +75 -0
  223. package/src/utils/scrollUtils.tsx +308 -0
  224. package/src/utils/searchUtils.ts +51 -0
  225. package/src/utils/storageUtils.ts +59 -26
  226. package/src/utils/tagsUtils.ts +50 -0
  227. package/src/utils/tocUtils.ts +119 -0
  228. package/src/utils/useAlternatePageUtils.ts +28 -7
  229. package/src/utils/useLocalPathname.ts +22 -0
  230. package/src/utils/useLocationChange.ts +41 -0
  231. package/src/utils/usePluralForm.ts +49 -39
  232. package/src/utils/useThemeConfig.ts +54 -25
  233. package/lib/.tsbuildinfo +0 -4115
  234. package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.d.ts +0 -21
  235. package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js +0 -94
  236. package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.d.ts +0 -13
  237. package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.js +0 -20
  238. package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.d.ts +0 -5
  239. package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.js +0 -41
  240. package/lib/utils/pathUtils.js +0 -13
  241. package/lib/utils/useChangeRoute.js +0 -18
  242. package/src/utils/__tests__/codeBlockUtils.test.ts +0 -54
  243. package/src/utils/__tests__/pathUtils.test.ts +0 -32
  244. package/src/utils/docsPreferredVersion/DocsPreferredVersionProvider.tsx +0 -165
  245. package/src/utils/docsPreferredVersion/DocsPreferredVersionStorage.ts +0 -34
  246. package/src/utils/docsPreferredVersion/useDocsPreferredVersion.ts +0 -66
  247. package/src/utils/docsUtils.ts +0 -11
  248. package/src/utils/pathUtils.ts +0 -17
  249. package/src/utils/useChangeRoute.ts +0 -21
  250. 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
- // Permits to obtain the url of the current page in another locale
12
- // Useful to generate hreflang meta headers etc...
13
- // See https://developers.google.com/search/docs/advanced/crawling/localized-versions
14
- export function useAlternatePageUtils() {
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 another domain
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
- // Poor man's PluralSelector implementation, using an english fallback.
53
- // We want a lightweight, future-proof and good-enough solution.
54
- // We don't want a perfect and heavy solution.
55
- //
56
- // Docusaurus classic theme has only 2 deeply nested labels requiring complex plural rules
57
- // We don't want to use Intl + PluralRules polyfills + full ICU syntax (react-intl) just for that.
58
- //
59
- // Notes:
60
- // - 2021: 92+% Browsers support Intl.PluralRules, and support will increase in the future
61
- // - NodeJS >= 13 has full ICU support by default
62
- // - In case of "mismatch" between SSR and Browser ICU support, React keeps working!
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
- // @ts-expect-error checking Intl.PluralRules in case browser doesn't have it (e.g Safari 12-)
69
- if (Intl.PluralRules) {
70
- try {
71
- return createLocalePluralForms(currentLocale);
72
- } catch (e) {
73
- console.error(`Failed to use Intl.PluralRules for locale=${currentLocale}.
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
- } else {
98
- if (parts.length > localePluralForms.pluralForms.length) {
99
- console.error(
100
- `For locale=${localePluralForms.locale}, a maximum of ${localePluralForms.pluralForms.length} plural forms are expected (${localePluralForms.pluralForms}), but the message contains ${parts.length} plural forms: ${pluralMessages} `,
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
- export function usePluralForm() {
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
- return selectPluralMessage(pluralMessages, count, localePluralForm);
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 {CSSProperties} from 'react';
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?: PrismTheme;
57
+ theme: PrismTheme;
60
58
  darkTheme?: PrismTheme;
61
59
  defaultLanguage?: string;
62
- additionalLanguages?: string[];
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
- export type FooterLinks = {
73
- title?: string;
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
- hideableSidebar: boolean;
104
- image: string;
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
  }