@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.
Files changed (279) hide show
  1. package/Details.d.ts +14 -0
  2. package/lib/components/Collapsible/index.d.ts +32 -4
  3. package/lib/components/Collapsible/index.d.ts.map +1 -1
  4. package/lib/components/Collapsible/index.js +18 -10
  5. package/lib/components/Collapsible/index.js.map +1 -1
  6. package/lib/components/Details/index.d.ts +6 -1
  7. package/lib/components/Details/index.d.ts.map +1 -1
  8. package/lib/components/Details/index.js +11 -6
  9. package/lib/components/Details/index.js.map +1 -1
  10. package/lib/components/Details/styles.module.css +4 -0
  11. package/lib/{utils/announcementBarUtils.d.ts → contexts/announcementBar.d.ts} +7 -3
  12. package/lib/contexts/announcementBar.d.ts.map +1 -0
  13. package/lib/{utils/announcementBarUtils.js → contexts/announcementBar.js} +15 -14
  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/{utils → contexts}/docSidebarItemsExpandedState.js +10 -4
  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/{utils/tabGroupChoiceUtils.d.ts → contexts/tabGroupChoice.d.ts} +5 -3
  48. package/lib/contexts/tabGroupChoice.d.ts.map +1 -0
  49. package/lib/{utils/tabGroupChoiceUtils.js → contexts/tabGroupChoice.js} +15 -20
  50. package/lib/contexts/tabGroupChoice.js.map +1 -0
  51. package/lib/hooks/useBackToTopButton.d.ts +27 -0
  52. package/lib/hooks/useBackToTopButton.d.ts.map +1 -0
  53. package/lib/hooks/useBackToTopButton.js +50 -0
  54. package/lib/hooks/useBackToTopButton.js.map +1 -0
  55. package/lib/hooks/useCodeWordWrap.d.ts +14 -0
  56. package/lib/hooks/useCodeWordWrap.d.ts.map +1 -0
  57. package/lib/hooks/useCodeWordWrap.js +41 -0
  58. package/lib/hooks/useCodeWordWrap.js.map +1 -0
  59. package/lib/hooks/useHideableNavbar.d.ts +7 -3
  60. package/lib/hooks/useHideableNavbar.d.ts.map +1 -1
  61. package/lib/hooks/useHideableNavbar.js +10 -9
  62. package/lib/hooks/useHideableNavbar.js.map +1 -1
  63. package/lib/hooks/useKeyboardNavigation.d.ts +11 -1
  64. package/lib/hooks/useKeyboardNavigation.d.ts.map +1 -1
  65. package/lib/hooks/useKeyboardNavigation.js +11 -3
  66. package/lib/hooks/useKeyboardNavigation.js.map +1 -1
  67. package/lib/hooks/useLockBodyScroll.d.ts +5 -1
  68. package/lib/hooks/useLockBodyScroll.d.ts.map +1 -1
  69. package/lib/hooks/useLockBodyScroll.js +5 -1
  70. package/lib/hooks/useLockBodyScroll.js.map +1 -1
  71. package/lib/hooks/usePrismTheme.d.ts +6 -2
  72. package/lib/hooks/usePrismTheme.d.ts.map +1 -1
  73. package/lib/hooks/usePrismTheme.js +9 -6
  74. package/lib/hooks/usePrismTheme.js.map +1 -1
  75. package/lib/hooks/useSearchPage.d.ts +15 -4
  76. package/lib/hooks/useSearchPage.d.ts.map +1 -1
  77. package/lib/hooks/useSearchPage.js +4 -4
  78. package/lib/hooks/useSearchPage.js.map +1 -1
  79. package/lib/hooks/useSkipToContent.d.ts +25 -0
  80. package/lib/hooks/useSkipToContent.d.ts.map +1 -0
  81. package/lib/hooks/useSkipToContent.js +35 -0
  82. package/lib/hooks/useSkipToContent.js.map +1 -0
  83. package/lib/hooks/useTOCHighlight.d.ts +25 -0
  84. package/lib/hooks/useTOCHighlight.d.ts.map +1 -0
  85. package/lib/{utils → hooks}/useTOCHighlight.js +18 -16
  86. package/lib/hooks/useTOCHighlight.js.map +1 -0
  87. package/lib/hooks/useWindowSize.d.ts +14 -1
  88. package/lib/hooks/useWindowSize.d.ts.map +1 -1
  89. package/lib/hooks/useWindowSize.js +14 -11
  90. package/lib/hooks/useWindowSize.js.map +1 -1
  91. package/lib/index.d.ts +31 -32
  92. package/lib/index.d.ts.map +1 -1
  93. package/lib/index.js +31 -26
  94. package/lib/index.js.map +1 -1
  95. package/lib/utils/ThemeClassNames.d.ts +7 -0
  96. package/lib/utils/ThemeClassNames.d.ts.map +1 -1
  97. package/lib/utils/ThemeClassNames.js +7 -4
  98. package/lib/utils/ThemeClassNames.js.map +1 -1
  99. package/lib/utils/codeBlockUtils.d.ts +57 -4
  100. package/lib/utils/codeBlockUtils.d.ts.map +1 -1
  101. package/lib/utils/codeBlockUtils.js +111 -80
  102. package/lib/utils/codeBlockUtils.js.map +1 -1
  103. package/lib/utils/docsUtils.d.ts +83 -18
  104. package/lib/utils/docsUtils.d.ts.map +1 -1
  105. package/lib/utils/docsUtils.js +143 -62
  106. package/lib/utils/docsUtils.js.map +1 -1
  107. package/lib/utils/footerUtils.d.ts +13 -0
  108. package/lib/utils/footerUtils.d.ts.map +1 -0
  109. package/lib/utils/footerUtils.js +14 -0
  110. package/lib/utils/footerUtils.js.map +1 -0
  111. package/lib/utils/generalUtils.d.ts +4 -1
  112. package/lib/utils/generalUtils.d.ts.map +1 -1
  113. package/lib/utils/generalUtils.js +6 -3
  114. package/lib/utils/generalUtils.js.map +1 -1
  115. package/lib/utils/historyUtils.d.ts +1 -7
  116. package/lib/utils/historyUtils.d.ts.map +1 -1
  117. package/lib/utils/historyUtils.js +10 -13
  118. package/lib/utils/historyUtils.js.map +1 -1
  119. package/lib/utils/jsUtils.d.ts +1 -1
  120. package/lib/utils/jsUtils.js +1 -1
  121. package/lib/utils/metadataUtils.d.ts +38 -0
  122. package/lib/utils/metadataUtils.d.ts.map +1 -0
  123. package/lib/utils/metadataUtils.js +61 -0
  124. package/lib/utils/metadataUtils.js.map +1 -0
  125. package/lib/utils/navbarUtils.d.ts +21 -0
  126. package/lib/utils/navbarUtils.d.ts.map +1 -0
  127. package/lib/utils/navbarUtils.js +32 -0
  128. package/lib/utils/navbarUtils.js.map +1 -0
  129. package/lib/utils/reactUtils.d.ts +21 -7
  130. package/lib/utils/reactUtils.d.ts.map +1 -1
  131. package/lib/utils/reactUtils.js +34 -6
  132. package/lib/utils/reactUtils.js.map +1 -1
  133. package/lib/utils/regexpUtils.d.ts +2 -1
  134. package/lib/utils/regexpUtils.d.ts.map +1 -1
  135. package/lib/utils/regexpUtils.js +2 -1
  136. package/lib/utils/regexpUtils.js.map +1 -1
  137. package/lib/utils/routesUtils.d.ts +19 -4
  138. package/lib/utils/routesUtils.d.ts.map +1 -1
  139. package/lib/utils/routesUtils.js +40 -19
  140. package/lib/utils/routesUtils.js.map +1 -1
  141. package/lib/utils/scrollUtils.d.ts +55 -25
  142. package/lib/utils/scrollUtils.d.ts.map +1 -1
  143. package/lib/utils/scrollUtils.js +85 -21
  144. package/lib/utils/scrollUtils.js.map +1 -1
  145. package/lib/utils/searchUtils.d.ts +12 -0
  146. package/lib/utils/searchUtils.d.ts.map +1 -1
  147. package/lib/utils/searchUtils.js +36 -0
  148. package/lib/utils/searchUtils.js.map +1 -1
  149. package/lib/utils/storageUtils.d.ts +12 -9
  150. package/lib/utils/storageUtils.d.ts.map +1 -1
  151. package/lib/utils/storageUtils.js +21 -13
  152. package/lib/utils/storageUtils.js.map +1 -1
  153. package/lib/utils/tagsUtils.d.ts +7 -8
  154. package/lib/utils/tagsUtils.d.ts.map +1 -1
  155. package/lib/utils/tagsUtils.js +8 -6
  156. package/lib/utils/tagsUtils.js.map +1 -1
  157. package/lib/utils/tocUtils.d.ts +17 -1
  158. package/lib/utils/tocUtils.d.ts.map +1 -1
  159. package/lib/utils/tocUtils.js +20 -9
  160. package/lib/utils/tocUtils.js.map +1 -1
  161. package/lib/utils/useAlternatePageUtils.d.ts +20 -1
  162. package/lib/utils/useAlternatePageUtils.d.ts.map +1 -1
  163. package/lib/utils/useAlternatePageUtils.js +6 -3
  164. package/lib/utils/useAlternatePageUtils.js.map +1 -1
  165. package/lib/utils/useLocalPathname.d.ts +5 -0
  166. package/lib/utils/useLocalPathname.d.ts.map +1 -1
  167. package/lib/utils/useLocalPathname.js +6 -4
  168. package/lib/utils/useLocalPathname.js.map +1 -1
  169. package/lib/utils/useLocationChange.d.ts +7 -5
  170. package/lib/utils/useLocationChange.d.ts.map +1 -1
  171. package/lib/utils/useLocationChange.js +6 -2
  172. package/lib/utils/useLocationChange.js.map +1 -1
  173. package/lib/utils/usePluralForm.d.ts +11 -0
  174. package/lib/utils/usePluralForm.d.ts.map +1 -1
  175. package/lib/utils/usePluralForm.js +19 -24
  176. package/lib/utils/usePluralForm.js.map +1 -1
  177. package/lib/utils/useThemeConfig.d.ts +28 -22
  178. package/lib/utils/useThemeConfig.d.ts.map +1 -1
  179. package/lib/utils/useThemeConfig.js +3 -0
  180. package/lib/utils/useThemeConfig.js.map +1 -1
  181. package/package.json +18 -11
  182. package/src/components/Collapsible/index.tsx +42 -24
  183. package/src/components/Details/index.tsx +15 -8
  184. package/src/components/Details/styles.module.css +4 -0
  185. package/src/{utils/announcementBarUtils.tsx → contexts/announcementBar.tsx} +20 -22
  186. package/src/contexts/colorMode.tsx +199 -0
  187. package/src/contexts/docSidebarItemsExpandedState.tsx +55 -0
  188. package/src/contexts/docsPreferredVersion.tsx +253 -0
  189. package/src/contexts/docsSidebar.tsx +50 -0
  190. package/src/contexts/docsVersion.tsx +36 -0
  191. package/src/contexts/navbarMobileSidebar.tsx +99 -0
  192. package/src/contexts/navbarSecondaryMenu/content.tsx +110 -0
  193. package/src/contexts/navbarSecondaryMenu/display.tsx +102 -0
  194. package/src/{utils/tabGroupChoiceUtils.tsx → contexts/tabGroupChoice.tsx} +28 -33
  195. package/src/hooks/useBackToTopButton.ts +73 -0
  196. package/src/hooks/useCodeWordWrap.ts +56 -0
  197. package/src/hooks/useHideableNavbar.ts +12 -14
  198. package/src/hooks/useKeyboardNavigation.ts +11 -3
  199. package/src/hooks/useLockBodyScroll.ts +5 -2
  200. package/src/hooks/usePrismTheme.ts +10 -6
  201. package/src/hooks/useSearchPage.ts +18 -5
  202. package/src/hooks/useSkipToContent.ts +58 -0
  203. package/src/{utils → hooks}/useTOCHighlight.ts +24 -15
  204. package/src/hooks/useWindowSize.ts +14 -12
  205. package/src/index.ts +77 -57
  206. package/src/utils/ThemeClassNames.ts +10 -6
  207. package/src/utils/codeBlockUtils.ts +178 -92
  208. package/src/utils/docsUtils.tsx +205 -101
  209. package/src/utils/footerUtils.ts +18 -0
  210. package/src/utils/generalUtils.ts +6 -3
  211. package/src/utils/historyUtils.ts +11 -17
  212. package/src/utils/jsUtils.ts +1 -1
  213. package/src/utils/metadataUtils.tsx +115 -0
  214. package/src/utils/navbarUtils.tsx +45 -0
  215. package/src/utils/reactUtils.tsx +40 -7
  216. package/src/utils/regexpUtils.ts +2 -1
  217. package/src/utils/routesUtils.ts +58 -22
  218. package/src/utils/scrollUtils.tsx +120 -49
  219. package/src/utils/searchUtils.ts +51 -0
  220. package/src/utils/storageUtils.ts +23 -15
  221. package/src/utils/tagsUtils.ts +12 -10
  222. package/src/utils/tocUtils.ts +22 -11
  223. package/src/utils/useAlternatePageUtils.ts +17 -5
  224. package/src/utils/useLocalPathname.ts +6 -4
  225. package/src/utils/useLocationChange.ts +12 -10
  226. package/src/utils/usePluralForm.ts +27 -24
  227. package/src/utils/useThemeConfig.ts +23 -22
  228. package/yarn-error.log +20199 -0
  229. package/lib/utils/announcementBarUtils.d.ts.map +0 -1
  230. package/lib/utils/announcementBarUtils.js.map +0 -1
  231. package/lib/utils/colorModeUtils.d.ts +0 -18
  232. package/lib/utils/colorModeUtils.d.ts.map +0 -1
  233. package/lib/utils/colorModeUtils.js +0 -106
  234. package/lib/utils/colorModeUtils.js.map +0 -1
  235. package/lib/utils/docSidebarItemsExpandedState.d.ts +0 -17
  236. package/lib/utils/docSidebarItemsExpandedState.d.ts.map +0 -1
  237. package/lib/utils/docSidebarItemsExpandedState.js.map +0 -1
  238. package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.d.ts +0 -22
  239. package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.d.ts.map +0 -1
  240. package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js +0 -91
  241. package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js.map +0 -1
  242. package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.d.ts +0 -14
  243. package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.d.ts.map +0 -1
  244. package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.js +0 -19
  245. package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.js.map +0 -1
  246. package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.d.ts +0 -14
  247. package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.d.ts.map +0 -1
  248. package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.js +0 -41
  249. package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.js.map +0 -1
  250. package/lib/utils/mobileSecondaryMenu.d.ts +0 -21
  251. package/lib/utils/mobileSecondaryMenu.d.ts.map +0 -1
  252. package/lib/utils/mobileSecondaryMenu.js +0 -50
  253. package/lib/utils/mobileSecondaryMenu.js.map +0 -1
  254. package/lib/utils/pathUtils.d.ts +0 -8
  255. package/lib/utils/pathUtils.d.ts.map +0 -1
  256. package/lib/utils/pathUtils.js +0 -17
  257. package/lib/utils/pathUtils.js.map +0 -1
  258. package/lib/utils/tabGroupChoiceUtils.d.ts.map +0 -1
  259. package/lib/utils/tabGroupChoiceUtils.js.map +0 -1
  260. package/lib/utils/useContextualSearchFilters.d.ts +0 -12
  261. package/lib/utils/useContextualSearchFilters.d.ts.map +0 -1
  262. package/lib/utils/useContextualSearchFilters.js +0 -37
  263. package/lib/utils/useContextualSearchFilters.js.map +0 -1
  264. package/lib/utils/usePrevious.d.ts +0 -8
  265. package/lib/utils/usePrevious.d.ts.map +0 -1
  266. package/lib/utils/usePrevious.js +0 -16
  267. package/lib/utils/usePrevious.js.map +0 -1
  268. package/lib/utils/useTOCHighlight.d.ts +0 -14
  269. package/lib/utils/useTOCHighlight.d.ts.map +0 -1
  270. package/lib/utils/useTOCHighlight.js.map +0 -1
  271. package/src/utils/colorModeUtils.tsx +0 -156
  272. package/src/utils/docSidebarItemsExpandedState.tsx +0 -41
  273. package/src/utils/docsPreferredVersion/DocsPreferredVersionProvider.tsx +0 -167
  274. package/src/utils/docsPreferredVersion/DocsPreferredVersionStorage.ts +0 -33
  275. package/src/utils/docsPreferredVersion/useDocsPreferredVersion.ts +0 -70
  276. package/src/utils/mobileSecondaryMenu.tsx +0 -115
  277. package/src/utils/pathUtils.ts +0 -19
  278. package/src/utils/useContextualSearchFilters.ts +0 -53
  279. package/src/utils/usePrevious.ts +0 -19
@@ -1,16 +0,0 @@
1
- /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
- import { useRef } from 'react';
8
- import { useIsomorphicLayoutEffect } from './reactUtils';
9
- export function usePrevious(value) {
10
- const ref = useRef();
11
- useIsomorphicLayoutEffect(() => {
12
- ref.current = value;
13
- });
14
- return ref.current;
15
- }
16
- //# sourceMappingURL=usePrevious.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"usePrevious.js","sourceRoot":"","sources":["../../src/utils/usePrevious.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,MAAM,EAAC,MAAM,OAAO,CAAC;AAC7B,OAAO,EAAC,yBAAyB,EAAC,MAAM,cAAc,CAAC;AAEvD,MAAM,UAAU,WAAW,CAAI,KAAQ;IACrC,MAAM,GAAG,GAAG,MAAM,EAAK,CAAC;IAExB,yBAAyB,CAAC,GAAG,EAAE;QAC7B,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC;IACtB,CAAC,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC,OAAO,CAAC;AACrB,CAAC"}
@@ -1,14 +0,0 @@
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
- export declare type TOCHighlightConfig = {
8
- linkClassName: string;
9
- linkActiveClassName: string;
10
- minHeadingLevel: number;
11
- maxHeadingLevel: number;
12
- };
13
- export default function useTOCHighlight(config: TOCHighlightConfig | undefined): void;
14
- //# sourceMappingURL=useTOCHighlight.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useTOCHighlight.d.ts","sourceRoot":"","sources":["../../src/utils/useTOCHighlight.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAgHH,oBAAY,kBAAkB,GAAG;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,MAAM,EAAE,kBAAkB,GAAG,SAAS,GACrC,IAAI,CAwDN"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"useTOCHighlight.js","sourceRoot":"","sources":["../../src/utils/useTOCHighlight.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,SAAS,EAAE,MAAM,EAAC,MAAM,OAAO,CAAC;AACxC,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAEhD;;;GAGG;AAEH,+EAA+E;AAC/E,0DAA0D;AAC1D,SAAS,4BAA4B,CAAC,OAAoB;IACxD,MAAM,IAAI,GAAG,OAAO,CAAC,qBAAqB,EAAE,CAAC;IAC7C,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,KAAK,IAAI,CAAC,MAAM,CAAC;IAC7C,IAAI,WAAW,EAAE;QACf,OAAO,4BAA4B,CAAC,OAAO,CAAC,UAAyB,CAAC,CAAC;KACxE;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,SAAS,mBAAmB,CAAC,YAAqB;IAChD,OAAO,YAAY,CAAC,GAAG,GAAG,CAAC,IAAI,YAAY,CAAC,MAAM,GAAG,MAAM,CAAC,WAAW,GAAG,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,UAAU,CAAC,EAClB,eAAe,EACf,eAAe,GAIhB;IACC,MAAM,SAAS,GAAG,EAAE,CAAC;I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AACnC,CAAC"}
@@ -1,156 +0,0 @@
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 type {ReactNode} from 'react';
9
- import React, {
10
- useState,
11
- useCallback,
12
- useEffect,
13
- useContext,
14
- useMemo,
15
- } from 'react';
16
-
17
- import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
18
- import {createStorageSlot} from './storageUtils';
19
- import {useThemeConfig} from './useThemeConfig';
20
-
21
- type ColorModeContextValue = {
22
- readonly isDarkTheme: boolean;
23
- readonly setLightTheme: () => void;
24
- readonly setDarkTheme: () => void;
25
- };
26
-
27
- const ThemeStorageKey = 'theme';
28
- const ThemeStorage = createStorageSlot(ThemeStorageKey);
29
-
30
- const themes = {
31
- light: 'light',
32
- dark: 'dark',
33
- } as const;
34
-
35
- type Themes = typeof themes[keyof typeof themes];
36
-
37
- // Ensure to always return a valid theme even if input is invalid
38
- const coerceToTheme = (theme?: string | null): Themes =>
39
- theme === themes.dark ? themes.dark : themes.light;
40
-
41
- const getInitialTheme = (defaultMode: Themes | undefined): Themes => {
42
- if (!ExecutionEnvironment.canUseDOM) {
43
- return coerceToTheme(defaultMode);
44
- }
45
- return coerceToTheme(document.documentElement.getAttribute('data-theme'));
46
- };
47
-
48
- const storeTheme = (newTheme: Themes) => {
49
- ThemeStorage.set(coerceToTheme(newTheme));
50
- };
51
-
52
- function useColorModeContextValue(): ColorModeContextValue {
53
- const {
54
- colorMode: {defaultMode, disableSwitch, respectPrefersColorScheme},
55
- } = useThemeConfig();
56
- const [theme, setTheme] = useState(getInitialTheme(defaultMode));
57
-
58
- const setLightTheme = useCallback(() => {
59
- setTheme(themes.light);
60
- storeTheme(themes.light);
61
- }, []);
62
- const setDarkTheme = useCallback(() => {
63
- setTheme(themes.dark);
64
- storeTheme(themes.dark);
65
- }, []);
66
-
67
- useEffect(() => {
68
- document.documentElement.setAttribute('data-theme', coerceToTheme(theme));
69
- }, [theme]);
70
-
71
- useEffect(() => {
72
- if (disableSwitch) {
73
- return undefined;
74
- }
75
- const onChange = (e: StorageEvent) => {
76
- if (e.key !== ThemeStorageKey) {
77
- return;
78
- }
79
- try {
80
- const storedTheme = ThemeStorage.get();
81
- if (storedTheme !== null) {
82
- setTheme(coerceToTheme(storedTheme));
83
- }
84
- } catch (err) {
85
- console.error(err);
86
- }
87
- };
88
- window.addEventListener('storage', onChange);
89
- return () => {
90
- window.removeEventListener('storage', onChange);
91
- };
92
- }, [disableSwitch, setTheme]);
93
-
94
- // PCS is coerced to light mode when printing, which causes the color mode to
95
- // be reset to dark when exiting print mode, disregarding user settings. When
96
- // the listener fires only because of a print/screen switch, we don't change
97
- // color mode. See https://github.com/facebook/docusaurus/pull/6490
98
- const previousMediaIsPrint = React.useRef(false);
99
-
100
- useEffect(() => {
101
- if (disableSwitch && !respectPrefersColorScheme) {
102
- return undefined;
103
- }
104
- const mql = window.matchMedia('(prefers-color-scheme: dark)');
105
- const onChange = ({matches}: MediaQueryListEvent) => {
106
- if (window.matchMedia('print').matches || previousMediaIsPrint.current) {
107
- previousMediaIsPrint.current = window.matchMedia('print').matches;
108
- return;
109
- }
110
- setTheme(matches ? themes.dark : themes.light);
111
- };
112
- mql.addListener(onChange);
113
- return () => {
114
- mql.removeListener(onChange);
115
- };
116
- }, [disableSwitch, respectPrefersColorScheme]);
117
-
118
- return {
119
- isDarkTheme: theme === themes.dark,
120
- setLightTheme,
121
- setDarkTheme,
122
- };
123
- }
124
-
125
- const ColorModeContext = React.createContext<ColorModeContextValue | undefined>(
126
- undefined,
127
- );
128
-
129
- export function ColorModeProvider({
130
- children,
131
- }: {
132
- children: ReactNode;
133
- }): JSX.Element {
134
- const {isDarkTheme, setLightTheme, setDarkTheme} = useColorModeContextValue();
135
- const contextValue = useMemo(
136
- () => ({isDarkTheme, setLightTheme, setDarkTheme}),
137
- [isDarkTheme, setLightTheme, setDarkTheme],
138
- );
139
- return (
140
- <ColorModeContext.Provider value={contextValue}>
141
- {children}
142
- </ColorModeContext.Provider>
143
- );
144
- }
145
-
146
- export function useColorMode(): ColorModeContextValue {
147
- const context = useContext<ColorModeContextValue | undefined>(
148
- ColorModeContext,
149
- );
150
- if (context == null) {
151
- throw new Error(
152
- '"useColorMode()" is used outside of "Layout" component. Please see https://docusaurus.io/docs/api/themes/configuration#use-color-mode.',
153
- );
154
- }
155
- return context;
156
- }
@@ -1,41 +0,0 @@
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 React, {type ReactNode, useMemo, useState, useContext} from 'react';
9
-
10
- const EmptyContext: unique symbol = Symbol('EmptyContext');
11
- const Context = React.createContext<
12
- DocSidebarItemsExpandedState | typeof EmptyContext
13
- >(EmptyContext);
14
- type DocSidebarItemsExpandedState = {
15
- expandedItem: number | null;
16
- setExpandedItem: (a: number | null) => void;
17
- };
18
-
19
- export function DocSidebarItemsExpandedStateProvider({
20
- children,
21
- }: {
22
- children: ReactNode;
23
- }): JSX.Element {
24
- const [expandedItem, setExpandedItem] = useState<number | null>(null);
25
- const contextValue = useMemo(
26
- () => ({expandedItem, setExpandedItem}),
27
- [expandedItem],
28
- );
29
-
30
- return <Context.Provider value={contextValue}>{children}</Context.Provider>;
31
- }
32
-
33
- export function useDocSidebarItemsExpandedState(): DocSidebarItemsExpandedState {
34
- const contextValue = useContext(Context);
35
- if (contextValue === EmptyContext) {
36
- throw new Error(
37
- 'This hook requires usage of <DocSidebarItemsExpandedStateProvider>',
38
- );
39
- }
40
- return contextValue;
41
- }
@@ -1,167 +0,0 @@
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 React, {
9
- createContext,
10
- type ReactNode,
11
- useContext,
12
- useEffect,
13
- useMemo,
14
- useState,
15
- } from 'react';
16
- import {useThemeConfig, type DocsVersionPersistence} from '../useThemeConfig';
17
- import {isDocsPluginEnabled} from '../docsUtils';
18
-
19
- import {
20
- useAllDocsData,
21
- type GlobalPluginData,
22
- } from '@docusaurus/plugin-content-docs/client';
23
-
24
- import DocsPreferredVersionStorage from './DocsPreferredVersionStorage';
25
-
26
- type DocsPreferredVersionName = string | null;
27
-
28
- // State for a single docs plugin instance
29
- type DocsPreferredVersionPluginState = {
30
- preferredVersionName: DocsPreferredVersionName;
31
- };
32
-
33
- // We need to store in state/storage globally
34
- // one preferred version per docs plugin instance
35
- // pluginId => pluginState
36
- type DocsPreferredVersionState = Record<
37
- string,
38
- DocsPreferredVersionPluginState
39
- >;
40
-
41
- // Initial state is always null as we can't read local storage from node SSR
42
- function getInitialState(pluginIds: string[]): DocsPreferredVersionState {
43
- const initialState: DocsPreferredVersionState = {};
44
- pluginIds.forEach((pluginId) => {
45
- initialState[pluginId] = {
46
- preferredVersionName: null,
47
- };
48
- });
49
- return initialState;
50
- }
51
-
52
- // Read storage for all docs plugins
53
- // Assign to each doc plugin a preferred version (if found)
54
- function readStorageState({
55
- pluginIds,
56
- versionPersistence,
57
- allDocsData,
58
- }: {
59
- pluginIds: string[];
60
- versionPersistence: DocsVersionPersistence;
61
- allDocsData: Record<string, GlobalPluginData>;
62
- }): DocsPreferredVersionState {
63
- // The storage value we read might be stale,
64
- // and belong to a version that does not exist in the site anymore
65
- // In such case, we remove the storage value to avoid downstream errors
66
- function restorePluginState(
67
- pluginId: string,
68
- ): DocsPreferredVersionPluginState {
69
- const preferredVersionNameUnsafe = DocsPreferredVersionStorage.read(
70
- pluginId,
71
- versionPersistence,
72
- );
73
- const pluginData = allDocsData[pluginId];
74
- const versionExists = pluginData.versions.some(
75
- (version) => version.name === preferredVersionNameUnsafe,
76
- );
77
- if (versionExists) {
78
- return {preferredVersionName: preferredVersionNameUnsafe};
79
- }
80
- DocsPreferredVersionStorage.clear(pluginId, versionPersistence);
81
- return {preferredVersionName: null};
82
- }
83
-
84
- const initialState: DocsPreferredVersionState = {};
85
- pluginIds.forEach((pluginId) => {
86
- initialState[pluginId] = restorePluginState(pluginId);
87
- });
88
- return initialState;
89
- }
90
-
91
- function useVersionPersistence(): DocsVersionPersistence {
92
- return useThemeConfig().docs.versionPersistence;
93
- }
94
-
95
- // Value that will be accessible through context: [state,api]
96
- function useContextValue() {
97
- const allDocsData = useAllDocsData();
98
- const versionPersistence = useVersionPersistence();
99
- const pluginIds = useMemo(() => Object.keys(allDocsData), [allDocsData]);
100
-
101
- // Initial state is empty, as we can't read browser storage in node/SSR
102
- const [state, setState] = useState(() => getInitialState(pluginIds));
103
-
104
- // On mount, we set the state read from browser storage
105
- useEffect(() => {
106
- setState(readStorageState({allDocsData, versionPersistence, pluginIds}));
107
- }, [allDocsData, versionPersistence, pluginIds]);
108
-
109
- // The API that we expose to consumer hooks (memo for constant object)
110
- const api = useMemo(() => {
111
- function savePreferredVersion(pluginId: string, versionName: string) {
112
- DocsPreferredVersionStorage.save(
113
- pluginId,
114
- versionPersistence,
115
- versionName,
116
- );
117
- setState((s) => ({
118
- ...s,
119
- [pluginId]: {preferredVersionName: versionName},
120
- }));
121
- }
122
-
123
- return {
124
- savePreferredVersion,
125
- };
126
- }, [versionPersistence]);
127
-
128
- return [state, api] as const;
129
- }
130
-
131
- type DocsPreferredVersionContextValue = ReturnType<typeof useContextValue>;
132
-
133
- const Context = createContext<DocsPreferredVersionContextValue | null>(null);
134
-
135
- export function DocsPreferredVersionContextProvider({
136
- children,
137
- }: {
138
- children: JSX.Element;
139
- }): JSX.Element {
140
- if (isDocsPluginEnabled) {
141
- return (
142
- <DocsPreferredVersionContextProviderUnsafe>
143
- {children}
144
- </DocsPreferredVersionContextProviderUnsafe>
145
- );
146
- }
147
- return children;
148
- }
149
-
150
- function DocsPreferredVersionContextProviderUnsafe({
151
- children,
152
- }: {
153
- children: ReactNode;
154
- }): JSX.Element {
155
- const contextValue = useContextValue();
156
- return <Context.Provider value={contextValue}>{children}</Context.Provider>;
157
- }
158
-
159
- export function useDocsPreferredVersionContext(): DocsPreferredVersionContextValue {
160
- const value = useContext(Context);
161
- if (!value) {
162
- throw new Error(
163
- 'Can\'t find docs preferred context, maybe you forgot to use the "DocsPreferredVersionContextProvider"?',
164
- );
165
- }
166
- return value;
167
- }
@@ -1,33 +0,0 @@
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 {createStorageSlot} from '../storageUtils';
9
- import type {DocsVersionPersistence} from '../useThemeConfig';
10
-
11
- const storageKey = (pluginId: string) => `docs-preferred-version-${pluginId}`;
12
-
13
- const DocsPreferredVersionStorage = {
14
- save: (
15
- pluginId: string,
16
- persistence: DocsVersionPersistence,
17
- versionName: string,
18
- ): void => {
19
- createStorageSlot(storageKey(pluginId), {persistence}).set(versionName);
20
- },
21
-
22
- read: (
23
- pluginId: string,
24
- persistence: DocsVersionPersistence,
25
- ): string | null =>
26
- createStorageSlot(storageKey(pluginId), {persistence}).get(),
27
-
28
- clear: (pluginId: string, persistence: DocsVersionPersistence): void => {
29
- createStorageSlot(storageKey(pluginId), {persistence}).del();
30
- },
31
- };
32
-
33
- export default DocsPreferredVersionStorage;
@@ -1,70 +0,0 @@
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 {useCallback} from 'react';
9
- import {useDocsPreferredVersionContext} from './DocsPreferredVersionProvider';
10
- import {
11
- useAllDocsData,
12
- useDocsData,
13
- type GlobalVersion,
14
- } from '@docusaurus/plugin-content-docs/client';
15
-
16
- import {DEFAULT_PLUGIN_ID} from '@docusaurus/constants';
17
-
18
- // Note, the preferredVersion attribute will always be null before mount
19
- export function useDocsPreferredVersion(
20
- pluginId: string | undefined = DEFAULT_PLUGIN_ID,
21
- ): {
22
- preferredVersion: GlobalVersion | null | undefined;
23
- savePreferredVersionName: (versionName: string) => void;
24
- } {
25
- const docsData = useDocsData(pluginId);
26
- const [state, api] = useDocsPreferredVersionContext();
27
-
28
- const {preferredVersionName} = state[pluginId];
29
-
30
- const preferredVersion = preferredVersionName
31
- ? docsData.versions.find((version) => version.name === preferredVersionName)
32
- : null;
33
-
34
- const savePreferredVersionName = useCallback(
35
- (versionName: string) => {
36
- api.savePreferredVersion(pluginId, versionName);
37
- },
38
- [api, pluginId],
39
- );
40
-
41
- return {preferredVersion, savePreferredVersionName} as const;
42
- }
43
-
44
- export function useDocsPreferredVersionByPluginId(): Record<
45
- string,
46
- GlobalVersion | null | undefined
47
- > {
48
- const allDocsData = useAllDocsData();
49
- const [state] = useDocsPreferredVersionContext();
50
-
51
- function getPluginIdPreferredVersion(pluginId: string) {
52
- const docsData = allDocsData[pluginId];
53
- const {preferredVersionName} = state[pluginId];
54
-
55
- return preferredVersionName
56
- ? docsData.versions.find(
57
- (version) => version.name === preferredVersionName,
58
- )
59
- : null;
60
- }
61
-
62
- const pluginIds = Object.keys(allDocsData);
63
-
64
- const result: Record<string, GlobalVersion | null | undefined> = {};
65
- pluginIds.forEach((pluginId) => {
66
- result[pluginId] = getPluginIdPreferredVersion(pluginId);
67
- });
68
-
69
- return result;
70
- }
@@ -1,115 +0,0 @@
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 React, {
9
- useState,
10
- type ReactNode,
11
- useContext,
12
- createContext,
13
- useEffect,
14
- type ComponentType,
15
- useMemo,
16
- } from 'react';
17
-
18
- /*
19
- The idea behind all this is that a specific component must be able to fill a
20
- placeholder in the generic layout. The doc page should be able to fill the
21
- secondary menu of the main mobile navbar. This permits to reduce coupling
22
- between the main layout and the specific page.
23
-
24
- This kind of feature is often called portal/teleport/gateway... various
25
- unmaintained React libs exist. Most up-to-date one: https://github.com/gregberge/react-teleporter
26
- Not sure any of those is safe regarding concurrent mode.
27
- */
28
-
29
- type ExtraProps = {
30
- toggleSidebar: () => void;
31
- };
32
-
33
- export type MobileSecondaryMenuComponent<Props> = ComponentType<
34
- Props & ExtraProps
35
- >;
36
-
37
- type State = {
38
- component: MobileSecondaryMenuComponent<unknown>;
39
- props: unknown;
40
- } | null;
41
-
42
- function useContextValue() {
43
- return useState<State>(null);
44
- }
45
-
46
- type ContextValue = ReturnType<typeof useContextValue>;
47
-
48
- const Context = createContext<ContextValue | null>(null);
49
-
50
- export function MobileSecondaryMenuProvider({
51
- children,
52
- }: {
53
- children: ReactNode;
54
- }): JSX.Element {
55
- return (
56
- <Context.Provider value={useContextValue()}>{children}</Context.Provider>
57
- );
58
- }
59
-
60
- function useMobileSecondaryMenuContext(): ContextValue {
61
- const value = useContext(Context);
62
- if (value === null) {
63
- throw new Error(
64
- 'MobileSecondaryMenuProvider was not used correctly, context value is null',
65
- );
66
- }
67
- return value;
68
- }
69
-
70
- export function useMobileSecondaryMenuRenderer(): (
71
- extraProps: ExtraProps,
72
- ) => ReactNode | undefined {
73
- const [state] = useMobileSecondaryMenuContext();
74
- if (state) {
75
- const Comp = state.component;
76
- return function render(extraProps) {
77
- return <Comp {...state.props} {...extraProps} />;
78
- };
79
- }
80
- return () => undefined;
81
- }
82
-
83
- function useShallowMemoizedObject<O extends Record<string, unknown>>(obj: O) {
84
- return useMemo(
85
- () => obj,
86
- // Is this safe?
87
- // eslint-disable-next-line react-hooks/exhaustive-deps
88
- [...Object.keys(obj), ...Object.values(obj)],
89
- );
90
- }
91
-
92
- // Fill the secondary menu placeholder with some real content
93
- export function MobileSecondaryMenuFiller<
94
- Props extends Record<string, unknown>,
95
- >({
96
- component,
97
- props,
98
- }: {
99
- component: MobileSecondaryMenuComponent<Props & ExtraProps>;
100
- props: Props;
101
- }): JSX.Element | null {
102
- const [, setState] = useMobileSecondaryMenuContext();
103
-
104
- // To avoid useless context re-renders, props are memoized shallowly
105
- const memoizedProps = useShallowMemoizedObject(props);
106
-
107
- useEffect(() => {
108
- // @ts-expect-error: context is not 100% type-safe but it's ok
109
- setState({component, props: memoizedProps});
110
- }, [setState, component, memoizedProps]);
111
-
112
- useEffect(() => () => setState(null), [setState]);
113
-
114
- return null;
115
- }
@@ -1,19 +0,0 @@
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
- // Compare the 2 paths, case insensitive and ignoring trailing slash
9
- export const isSamePath = (
10
- path1: string | undefined,
11
- path2: string | undefined,
12
- ): boolean => {
13
- const normalize = (pathname: string | undefined) =>
14
- (!pathname || pathname?.endsWith('/')
15
- ? pathname
16
- : `${pathname}/`
17
- )?.toLowerCase();
18
- return normalize(path1) === normalize(path2);
19
- };