@docusaurus/theme-common 2.0.0-beta.1ec2c95e3 → 2.0.0-beta.21

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 (251) 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 +150 -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 +76 -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/{utils/announcementBarUtils.js → contexts/announcementBar.js} +30 -31
  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 +130 -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/usePrevious.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 +38 -10
  93. package/lib/index.d.ts.map +1 -0
  94. package/lib/index.js +38 -9
  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 +159 -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 +70 -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 +36 -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 +55 -22
  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 +9 -6
  173. package/lib/utils/useLocationChange.d.ts.map +1 -0
  174. package/lib/utils/useLocationChange.js +17 -11
  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 +56 -25
  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 +28 -13
  185. package/src/components/Collapsible/index.tsx +263 -0
  186. package/src/components/Details/index.tsx +109 -0
  187. package/src/components/Details/styles.module.css +62 -0
  188. package/src/{utils/announcementBarUtils.tsx → contexts/announcementBar.tsx} +43 -39
  189. package/src/contexts/colorMode.tsx +198 -0
  190. package/src/contexts/docSidebarItemsExpandedState.tsx +55 -0
  191. package/src/contexts/docsPreferredVersion.tsx +251 -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 +189 -0
  208. package/src/hooks/useWindowSize.ts +72 -0
  209. package/src/index.ts +130 -19
  210. package/src/types.d.ts +0 -2
  211. package/src/utils/ThemeClassNames.ts +51 -5
  212. package/src/utils/codeBlockUtils.ts +241 -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 +304 -0
  224. package/src/utils/searchUtils.ts +51 -0
  225. package/src/utils/storageUtils.ts +56 -23
  226. package/src/utils/tagsUtils.ts +50 -0
  227. package/src/utils/tocUtils.ts +119 -0
  228. package/src/utils/useAlternatePageUtils.ts +19 -6
  229. package/src/utils/useLocalPathname.ts +22 -0
  230. package/src/utils/useLocationChange.ts +24 -20
  231. package/src/utils/usePluralForm.ts +50 -38
  232. package/src/utils/useThemeConfig.ts +55 -27
  233. package/lib/.tsbuildinfo +0 -1
  234. package/lib/utils/announcementBarUtils.d.ts +0 -17
  235. package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.d.ts +0 -21
  236. package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js +0 -94
  237. package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.d.ts +0 -13
  238. package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.js +0 -20
  239. package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.d.ts +0 -5
  240. package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.js +0 -41
  241. package/lib/utils/pathUtils.js +0 -13
  242. package/lib/utils/usePrevious.js +0 -14
  243. package/src/utils/__tests__/codeBlockUtils.test.ts +0 -54
  244. package/src/utils/__tests__/pathUtils.test.ts +0 -32
  245. package/src/utils/docsPreferredVersion/DocsPreferredVersionProvider.tsx +0 -165
  246. package/src/utils/docsPreferredVersion/DocsPreferredVersionStorage.ts +0 -34
  247. package/src/utils/docsPreferredVersion/useDocsPreferredVersion.ts +0 -66
  248. package/src/utils/docsUtils.ts +0 -11
  249. package/src/utils/pathUtils.ts +0 -17
  250. package/src/utils/usePrevious.ts +0 -18
  251. package/tsconfig.json +0 -10
@@ -0,0 +1,42 @@
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 { useLayoutEffect } from 'react';
8
+ /**
9
+ * This hook is like `useLayoutEffect`, but without the SSR warning.
10
+ * It seems hacky but it's used in many React libs (Redux, Formik...).
11
+ * Also mentioned here: https://github.com/facebook/react/issues/16956
12
+ *
13
+ * It is useful when you need to update a ref as soon as possible after a React
14
+ * render (before `useEffect`).
15
+ */
16
+ export declare const useIsomorphicLayoutEffect: typeof useLayoutEffect;
17
+ /**
18
+ * Permits to transform an unstable callback (like an arrow function provided as
19
+ * props) to a "stable" callback that is safe to use in a `useEffect` dependency
20
+ * array. Useful to avoid React stale closure problems + avoid useless effect
21
+ * re-executions.
22
+ *
23
+ * Workaround until the React team recommends a good solution, see
24
+ * https://github.com/facebook/react/issues/16956
25
+ *
26
+ * This generally works but has some potential drawbacks, such as
27
+ * https://github.com/facebook/react/issues/16956#issuecomment-536636418
28
+ */
29
+ export declare function useDynamicCallback<T extends (...args: never[]) => unknown>(callback: T): T;
30
+ /**
31
+ * Gets `value` from the last render.
32
+ */
33
+ export declare function usePrevious<T>(value: T): T | undefined;
34
+ /**
35
+ * This error is thrown when a context is consumed outside its provider. Allows
36
+ * reusing a generic error message format and reduces bundle size. The hook's
37
+ * name will be extracted from its stack, so only the provider's name is needed.
38
+ */
39
+ export declare class ReactContextError extends Error {
40
+ constructor(providerName: string, additionalInfo?: string);
41
+ }
42
+ //# sourceMappingURL=reactUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reactUtils.d.ts","sourceRoot":"","sources":["../../src/utils/reactUtils.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAyB,eAAe,EAAS,MAAM,OAAO,CAAC;AAGtE;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,wBAEzB,CAAC;AAEd;;;;;;;;;;;GAWG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,OAAO,EACxE,QAAQ,EAAE,CAAC,GACV,CAAC,CAUH;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS,CAQtD;AAED;;;;GAIG;AACH,qBAAa,iBAAkB,SAAQ,KAAK;gBAC9B,YAAY,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,MAAM;CAQ1D"}
@@ -0,0 +1,64 @@
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 { useCallback, useEffect, useLayoutEffect, useRef } from 'react';
8
+ import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
9
+ /**
10
+ * This hook is like `useLayoutEffect`, but without the SSR warning.
11
+ * It seems hacky but it's used in many React libs (Redux, Formik...).
12
+ * Also mentioned here: https://github.com/facebook/react/issues/16956
13
+ *
14
+ * It is useful when you need to update a ref as soon as possible after a React
15
+ * render (before `useEffect`).
16
+ */
17
+ export const useIsomorphicLayoutEffect = ExecutionEnvironment.canUseDOM
18
+ ? useLayoutEffect
19
+ : useEffect;
20
+ /**
21
+ * Permits to transform an unstable callback (like an arrow function provided as
22
+ * props) to a "stable" callback that is safe to use in a `useEffect` dependency
23
+ * array. Useful to avoid React stale closure problems + avoid useless effect
24
+ * re-executions.
25
+ *
26
+ * Workaround until the React team recommends a good solution, see
27
+ * https://github.com/facebook/react/issues/16956
28
+ *
29
+ * This generally works but has some potential drawbacks, such as
30
+ * https://github.com/facebook/react/issues/16956#issuecomment-536636418
31
+ */
32
+ export function useDynamicCallback(callback) {
33
+ const ref = useRef(callback);
34
+ useIsomorphicLayoutEffect(() => {
35
+ ref.current = callback;
36
+ }, [callback]);
37
+ // @ts-expect-error: TS is right that this callback may be a supertype of T,
38
+ // but good enough for our use
39
+ return useCallback((...args) => ref.current(...args), []);
40
+ }
41
+ /**
42
+ * Gets `value` from the last render.
43
+ */
44
+ export function usePrevious(value) {
45
+ const ref = useRef();
46
+ useIsomorphicLayoutEffect(() => {
47
+ ref.current = value;
48
+ });
49
+ return ref.current;
50
+ }
51
+ /**
52
+ * This error is thrown when a context is consumed outside its provider. Allows
53
+ * reusing a generic error message format and reduces bundle size. The hook's
54
+ * name will be extracted from its stack, so only the provider's name is needed.
55
+ */
56
+ export class ReactContextError extends Error {
57
+ constructor(providerName, additionalInfo) {
58
+ super();
59
+ this.name = 'ReactContextError';
60
+ this.message = `Hook ${this.stack?.split('\n')[1]?.match(/at (?:\w+\.)?(?<name>\w+)/)?.groups
61
+ .name ?? ''} is called outside the <${providerName}>. ${additionalInfo ?? ''}`;
62
+ }
63
+ }
64
+ //# sourceMappingURL=reactUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reactUtils.js","sourceRoot":"","sources":["../../src/utils/reactUtils.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,WAAW,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,EAAC,MAAM,OAAO,CAAC;AACtE,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;AAEpE;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,oBAAoB,CAAC,SAAS;IACrE,CAAC,CAAC,eAAe;IACjB,CAAC,CAAC,SAAS,CAAC;AAEd;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,kBAAkB,CAChC,QAAW;IAEX,MAAM,GAAG,GAAG,MAAM,CAAI,QAAQ,CAAC,CAAC;IAEhC,yBAAyB,CAAC,GAAG,EAAE;QAC7B,GAAG,CAAC,OAAO,GAAG,QAAQ,CAAC;IACzB,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEf,4EAA4E;IAC5E,8BAA8B;IAC9B,OAAO,WAAW,CAAI,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,CAAC;AAC/D,CAAC;AAED;;GAEG;AACH,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;AAED;;;;GAIG;AACH,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C,YAAY,YAAoB,EAAE,cAAuB;QACvD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;QAChC,IAAI,CAAC,OAAO,GAAG,QACb,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,2BAA2B,CAAC,EAAE,MAAO;aACpE,IAAI,IAAI,EACb,2BAA2B,YAAY,MAAM,cAAc,IAAI,EAAE,EAAE,CAAC;IACtE,CAAC;CACF"}
@@ -0,0 +1,12 @@
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
+ * Matches a string regex (as provided from the config) against a target in a
9
+ * null-safe fashion, case insensitive and global.
10
+ */
11
+ export declare function isRegexpStringMatch(regexAsString?: string, valueToTest?: string): boolean;
12
+ //# sourceMappingURL=regexpUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"regexpUtils.d.ts","sourceRoot":"","sources":["../../src/utils/regexpUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,aAAa,CAAC,EAAE,MAAM,EACtB,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAST"}
@@ -0,0 +1,18 @@
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
+ * Matches a string regex (as provided from the config) against a target in a
9
+ * null-safe fashion, case insensitive and global.
10
+ */
11
+ export function isRegexpStringMatch(regexAsString, valueToTest) {
12
+ if (typeof regexAsString === 'undefined' ||
13
+ typeof valueToTest === 'undefined') {
14
+ return false;
15
+ }
16
+ return new RegExp(regexAsString, 'gi').test(valueToTest);
17
+ }
18
+ //# sourceMappingURL=regexpUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"regexpUtils.js","sourceRoot":"","sources":["../../src/utils/regexpUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CACjC,aAAsB,EACtB,WAAoB;IAEpB,IACE,OAAO,aAAa,KAAK,WAAW;QACpC,OAAO,WAAW,KAAK,WAAW,EAClC;QACA,OAAO,KAAK,CAAC;KACd;IAED,OAAO,IAAI,MAAM,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AAC3D,CAAC"}
@@ -0,0 +1,26 @@
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 type { RouteConfig } from 'react-router-config';
8
+ /**
9
+ * Compare the 2 paths, case insensitive and ignoring trailing slash
10
+ */
11
+ export declare function isSamePath(path1: string | undefined, path2: string | undefined): boolean;
12
+ /**
13
+ * Note that sites don't always have a homepage in practice, so we can't assume
14
+ * that linking to '/' is always safe.
15
+ * @see https://github.com/facebook/docusaurus/pull/6517#issuecomment-1048709116
16
+ */
17
+ export declare function findHomePageRoute({ baseUrl, routes: initialRoutes, }: {
18
+ routes: RouteConfig[];
19
+ baseUrl: string;
20
+ }): RouteConfig | undefined;
21
+ /**
22
+ * Fetches the route that points to "/". Use this instead of the naive "/",
23
+ * because the homepage may not exist.
24
+ */
25
+ export declare function useHomePageRoute(): RouteConfig | undefined;
26
+ //# sourceMappingURL=routesUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routesUtils.d.ts","sourceRoot":"","sources":["../../src/utils/routesUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,qBAAqB,CAAC;AAErD;;GAEG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,KAAK,EAAE,MAAM,GAAG,SAAS,GACxB,OAAO,CAOT;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,EAChC,OAAO,EACP,MAAM,EAAE,aAAa,GACtB,EAAE;IACD,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;CACjB,GAAG,WAAW,GAAG,SAAS,CAwB1B;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,WAAW,GAAG,SAAS,CAM1D"}
@@ -0,0 +1,54 @@
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 { useMemo } from 'react';
8
+ import generatedRoutes from '@generated/routes';
9
+ import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
10
+ /**
11
+ * Compare the 2 paths, case insensitive and ignoring trailing slash
12
+ */
13
+ export function isSamePath(path1, path2) {
14
+ const normalize = (pathname) => (!pathname || pathname.endsWith('/')
15
+ ? pathname
16
+ : `${pathname}/`)?.toLowerCase();
17
+ return normalize(path1) === normalize(path2);
18
+ }
19
+ /**
20
+ * Note that sites don't always have a homepage in practice, so we can't assume
21
+ * that linking to '/' is always safe.
22
+ * @see https://github.com/facebook/docusaurus/pull/6517#issuecomment-1048709116
23
+ */
24
+ export function findHomePageRoute({ baseUrl, routes: initialRoutes, }) {
25
+ function isHomePageRoute(route) {
26
+ return route.path === baseUrl && route.exact === true;
27
+ }
28
+ function isHomeParentRoute(route) {
29
+ return route.path === baseUrl && !route.exact;
30
+ }
31
+ function doFindHomePageRoute(routes) {
32
+ if (routes.length === 0) {
33
+ return undefined;
34
+ }
35
+ const homePage = routes.find(isHomePageRoute);
36
+ if (homePage) {
37
+ return homePage;
38
+ }
39
+ const indexSubRoutes = routes
40
+ .filter(isHomeParentRoute)
41
+ .flatMap((route) => route.routes ?? []);
42
+ return doFindHomePageRoute(indexSubRoutes);
43
+ }
44
+ return doFindHomePageRoute(initialRoutes);
45
+ }
46
+ /**
47
+ * Fetches the route that points to "/". Use this instead of the naive "/",
48
+ * because the homepage may not exist.
49
+ */
50
+ export function useHomePageRoute() {
51
+ const { baseUrl } = useDocusaurusContext().siteConfig;
52
+ return useMemo(() => findHomePageRoute({ routes: generatedRoutes, baseUrl }), [baseUrl]);
53
+ }
54
+ //# sourceMappingURL=routesUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routesUtils.js","sourceRoot":"","sources":["../../src/utils/routesUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAC9B,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAChD,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;AAGpE;;GAEG;AACH,MAAM,UAAU,UAAU,CACxB,KAAyB,EACzB,KAAyB;IAEzB,MAAM,SAAS,GAAG,CAA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O,CACZ,GAAG,EAAE,CAAC,iBAAiB,CAAC,EAAC,MAAM,EAAE,eAAe,EAAE,OAAO,EAAC,CAAC,EAC3D,CAAC,OAAO,CAAC,CACV,CAAC;AACJ,CAAC"}
@@ -0,0 +1,83 @@
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 React, { type ReactNode } from 'react';
8
+ declare type ScrollController = {
9
+ /** A boolean ref tracking whether scroll events are enabled. */
10
+ scrollEventsEnabledRef: React.MutableRefObject<boolean>;
11
+ /** Enable scroll events in `useScrollPosition`. */
12
+ enableScrollEvents: () => void;
13
+ /** Disable scroll events in `useScrollPosition`. */
14
+ disableScrollEvents: () => void;
15
+ };
16
+ export declare function ScrollControllerProvider({ children, }: {
17
+ children: ReactNode;
18
+ }): JSX.Element;
19
+ /**
20
+ * We need a way to update the scroll position while ignoring scroll events
21
+ * so as not to toggle Navbar/BackToTop visibility.
22
+ *
23
+ * This API permits to temporarily disable/ignore scroll events. Motivated by
24
+ * https://github.com/facebook/docusaurus/pull/5618
25
+ */
26
+ export declare function useScrollController(): ScrollController;
27
+ declare type ScrollPosition = {
28
+ scrollX: number;
29
+ scrollY: number;
30
+ };
31
+ /**
32
+ * This hook fires an effect when the scroll position changes. The effect will
33
+ * be provided with the before/after scroll positions. Note that the effect may
34
+ * not be always run: if scrolling is disabled through `useScrollController`, it
35
+ * will be a no-op.
36
+ *
37
+ * @see {@link useScrollController}
38
+ */
39
+ export declare function useScrollPosition(effect: (position: ScrollPosition, lastPosition: ScrollPosition | null) => void, deps?: unknown[]): void;
40
+ /**
41
+ * This hook permits to "block" the scroll position of a DOM element.
42
+ * The idea is that we should be able to update DOM content above this element
43
+ * but the screen position of this element should not change.
44
+ *
45
+ * Feature motivated by the Tabs groups: clicking on a tab may affect tabs of
46
+ * the same group upper in the tree, yet to avoid a bad UX, the clicked tab must
47
+ * remain under the user mouse.
48
+ *
49
+ * @see https://github.com/facebook/docusaurus/pull/5618
50
+ */
51
+ export declare function useScrollPositionBlocker(): {
52
+ /**
53
+ * Takes an element, and keeps its screen position no matter what's getting
54
+ * rendered above it, until the next render.
55
+ */
56
+ blockElementScrollPositionUntilNextRender: (el: HTMLElement) => void;
57
+ };
58
+ declare type CancelScrollTop = () => void;
59
+ /**
60
+ * A "smart polyfill" of `window.scrollTo({ top, behavior: "smooth" })`.
61
+ * This currently always uses a polyfilled implementation unless
62
+ * `scroll-behavior: smooth` has been set in CSS, because native support
63
+ * detection for scroll behavior seems unreliable.
64
+ *
65
+ * This hook does not do anything by itself: it returns a start and a stop
66
+ * handle. You can execute either handle at any time.
67
+ */
68
+ export declare function useSmoothScrollTo(): {
69
+ /**
70
+ * Start the scroll.
71
+ *
72
+ * @param top The final scroll top position.
73
+ */
74
+ startScroll: (top: number) => void;
75
+ /**
76
+ * A cancel function, because the non-native smooth scroll-top
77
+ * implementation must be interrupted if user scrolls down. If there's no
78
+ * existing animation or the scroll is using native behavior, this is a no-op.
79
+ */
80
+ cancelScroll: CancelScrollTop;
81
+ };
82
+ export {};
83
+ //# sourceMappingURL=scrollUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scrollUtils.d.ts","sourceRoot":"","sources":["../../src/utils/scrollUtils.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,EAOZ,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAKf,aAAK,gBAAgB,GAAG;IACtB,gEAAgE;IAChE,sBAAsB,EAAE,KAAK,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACxD,mDAAmD;IACnD,kBAAkB,EAAE,MAAM,IAAI,CAAC;IAC/B,oDAAoD;IACpD,mBAAmB,EAAE,MAAM,IAAI,CAAC;CACjC,CAAC;AAuBF,wBAAgB,wBAAwB,CAAC,EACvC,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,SAAS,CAAC;CACrB,GAAG,GAAG,CAAC,OAAO,CAOd;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,IAAI,gBAAgB,CAMtD;AAED,aAAK,cAAc,GAAG;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAC,CAAC;AAUzD;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,CACN,QAAQ,EAAE,cAAc,EACxB,YAAY,EAAE,cAAc,GAAG,IAAI,KAChC,IAAI,EACT,IAAI,GAAE,OAAO,EAAO,GACnB,IAAI,CA0BN;AA6CD;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,IAAI;IAC1C;;;OAGG;IACH,yCAAyC,EAAE,CAAC,EAAE,EAAE,WAAW,KAAK,IAAI,CAAC;CACtE,CAwCA;AAED,aAAK,eAAe,GAAG,MAAM,IAAI,CAAC;AA6BlC;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,IAAI;IACnC;;;;OAIG;IACH,WAAW,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC;;;;OAIG;IACH,YAAY,EAAE,eAAe,CAAC;CAC/B,CAoBA"}
@@ -0,0 +1,200 @@
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 React, { useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, } from 'react';
8
+ import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
9
+ import useIsBrowser from '@docusaurus/useIsBrowser';
10
+ import { useDynamicCallback, ReactContextError } from './reactUtils';
11
+ function useScrollControllerContextValue() {
12
+ const scrollEventsEnabledRef = useRef(true);
13
+ return useMemo(() => ({
14
+ scrollEventsEnabledRef,
15
+ enableScrollEvents: () => {
16
+ scrollEventsEnabledRef.current = true;
17
+ },
18
+ disableScrollEvents: () => {
19
+ scrollEventsEnabledRef.current = false;
20
+ },
21
+ }), []);
22
+ }
23
+ const ScrollMonitorContext = React.createContext(undefined);
24
+ export function ScrollControllerProvider({ children, }) {
25
+ const value = useScrollControllerContextValue();
26
+ return (<ScrollMonitorContext.Provider value={value}>
27
+ {children}
28
+ </ScrollMonitorContext.Provider>);
29
+ }
30
+ /**
31
+ * We need a way to update the scroll position while ignoring scroll events
32
+ * so as not to toggle Navbar/BackToTop visibility.
33
+ *
34
+ * This API permits to temporarily disable/ignore scroll events. Motivated by
35
+ * https://github.com/facebook/docusaurus/pull/5618
36
+ */
37
+ export function useScrollController() {
38
+ const context = useContext(ScrollMonitorContext);
39
+ if (context == null) {
40
+ throw new ReactContextError('ScrollControllerProvider');
41
+ }
42
+ return context;
43
+ }
44
+ const getScrollPosition = () => ExecutionEnvironment.canUseDOM
45
+ ? {
46
+ scrollX: window.pageXOffset,
47
+ scrollY: window.pageYOffset,
48
+ }
49
+ : null;
50
+ /**
51
+ * This hook fires an effect when the scroll position changes. The effect will
52
+ * be provided with the before/after scroll positions. Note that the effect may
53
+ * not be always run: if scrolling is disabled through `useScrollController`, it
54
+ * will be a no-op.
55
+ *
56
+ * @see {@link useScrollController}
57
+ */
58
+ export function useScrollPosition(effect, deps = []) {
59
+ const { scrollEventsEnabledRef } = useScrollController();
60
+ const lastPositionRef = useRef(getScrollPosition());
61
+ const dynamicEffect = useDynamicCallback(effect);
62
+ useEffect(() => {
63
+ const handleScroll = () => {
64
+ if (!scrollEventsEnabledRef.current) {
65
+ return;
66
+ }
67
+ const currentPosition = getScrollPosition();
68
+ dynamicEffect(currentPosition, lastPositionRef.current);
69
+ lastPositionRef.current = currentPosition;
70
+ };
71
+ const opts = {
72
+ passive: true,
73
+ };
74
+ handleScroll();
75
+ window.addEventListener('scroll', handleScroll, opts);
76
+ return () => window.removeEventListener('scroll', handleScroll, opts);
77
+ // eslint-disable-next-line react-hooks/exhaustive-deps
78
+ }, [dynamicEffect, scrollEventsEnabledRef, ...deps]);
79
+ }
80
+ function useScrollPositionSaver() {
81
+ const lastElementRef = useRef({
82
+ elem: null,
83
+ top: 0,
84
+ });
85
+ const save = useCallback((elem) => {
86
+ lastElementRef.current = {
87
+ elem,
88
+ top: elem.getBoundingClientRect().top,
89
+ };
90
+ }, []);
91
+ const restore = useCallback(() => {
92
+ const { current: { elem, top }, } = lastElementRef;
93
+ if (!elem) {
94
+ return { restored: false };
95
+ }
96
+ const newTop = elem.getBoundingClientRect().top;
97
+ const heightDiff = newTop - top;
98
+ if (heightDiff) {
99
+ window.scrollBy({ left: 0, top: heightDiff });
100
+ }
101
+ lastElementRef.current = { elem: null, top: 0 };
102
+ return { restored: heightDiff !== 0 };
103
+ }, []);
104
+ return useMemo(() => ({ save, restore }), [restore, save]);
105
+ }
106
+ /**
107
+ * This hook permits to "block" the scroll position of a DOM element.
108
+ * The idea is that we should be able to update DOM content above this element
109
+ * but the screen position of this element should not change.
110
+ *
111
+ * Feature motivated by the Tabs groups: clicking on a tab may affect tabs of
112
+ * the same group upper in the tree, yet to avoid a bad UX, the clicked tab must
113
+ * remain under the user mouse.
114
+ *
115
+ * @see https://github.com/facebook/docusaurus/pull/5618
116
+ */
117
+ export function useScrollPositionBlocker() {
118
+ const scrollController = useScrollController();
119
+ const scrollPositionSaver = useScrollPositionSaver();
120
+ const nextLayoutEffectCallbackRef = useRef(undefined);
121
+ const blockElementScrollPositionUntilNextRender = useCallback((el) => {
122
+ scrollPositionSaver.save(el);
123
+ scrollController.disableScrollEvents();
124
+ nextLayoutEffectCallbackRef.current = () => {
125
+ const { restored } = scrollPositionSaver.restore();
126
+ nextLayoutEffectCallbackRef.current = undefined;
127
+ // Restoring the former scroll position will trigger a scroll event. We
128
+ // need to wait for next scroll event to happen before enabling the
129
+ // scrollController events again.
130
+ if (restored) {
131
+ const handleScrollRestoreEvent = () => {
132
+ scrollController.enableScrollEvents();
133
+ window.removeEventListener('scroll', handleScrollRestoreEvent);
134
+ };
135
+ window.addEventListener('scroll', handleScrollRestoreEvent);
136
+ }
137
+ else {
138
+ scrollController.enableScrollEvents();
139
+ }
140
+ };
141
+ }, [scrollController, scrollPositionSaver]);
142
+ useLayoutEffect(() => {
143
+ nextLayoutEffectCallbackRef.current?.();
144
+ });
145
+ return {
146
+ blockElementScrollPositionUntilNextRender,
147
+ };
148
+ }
149
+ function smoothScrollNative(top) {
150
+ window.scrollTo({ top, behavior: 'smooth' });
151
+ return () => {
152
+ // Nothing to cancel, it's natively cancelled if user tries to scroll down
153
+ };
154
+ }
155
+ function smoothScrollPolyfill(top) {
156
+ let raf = null;
157
+ const isUpScroll = document.documentElement.scrollTop > top;
158
+ function rafRecursion() {
159
+ const currentScroll = document.documentElement.scrollTop;
160
+ if ((isUpScroll && currentScroll > top) ||
161
+ (!isUpScroll && currentScroll < top)) {
162
+ raf = requestAnimationFrame(rafRecursion);
163
+ window.scrollTo(0, Math.floor((currentScroll - top) * 0.85) + top);
164
+ }
165
+ }
166
+ rafRecursion();
167
+ // Break the recursion. Prevents the user from "fighting" against that
168
+ // recursion producing a weird UX
169
+ return () => raf && cancelAnimationFrame(raf);
170
+ }
171
+ /**
172
+ * A "smart polyfill" of `window.scrollTo({ top, behavior: "smooth" })`.
173
+ * This currently always uses a polyfilled implementation unless
174
+ * `scroll-behavior: smooth` has been set in CSS, because native support
175
+ * detection for scroll behavior seems unreliable.
176
+ *
177
+ * This hook does not do anything by itself: it returns a start and a stop
178
+ * handle. You can execute either handle at any time.
179
+ */
180
+ export function useSmoothScrollTo() {
181
+ const cancelRef = useRef(null);
182
+ const isBrowser = useIsBrowser();
183
+ // Not all have support for smooth scrolling (particularly Safari mobile iOS)
184
+ // TODO proper detection is currently unreliable!
185
+ // see https://github.com/wessberg/scroll-behavior-polyfill/issues/16
186
+ // For now, we only use native scroll behavior if smooth is already set,
187
+ // because otherwise the polyfill produces a weird UX when both CSS and JS try
188
+ // to scroll a page, and they cancel each other.
189
+ const supportsNativeSmoothScrolling = isBrowser &&
190
+ getComputedStyle(document.documentElement).scrollBehavior === 'smooth';
191
+ return {
192
+ startScroll: (top) => {
193
+ cancelRef.current = supportsNativeSmoothScrolling
194
+ ? smoothScrollNative(top)
195
+ : smoothScrollPolyfill(top);
196
+ },
197
+ cancelScroll: () => cancelRef.current?.(),
198
+ };
199
+ }
200
+ //# sourceMappingURL=scrollUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scrollUtils.js","sourceRoot":"","sources":["../../src/utils/scrollUtils.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,EACZ,WAAW,EACX,UAAU,EACV,SAAS,EACT,eAAe,EACf,OAAO,EACP,MAAM,GAEP,MAAM,OAAO,CAAC;AACf,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;AACpE,OAAO,YAAY,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAC,kBAAkB,EAAE,iBAAiB,EAAC,MAAM,cAAc,CAAC;AAWnE,SAAS,+BAA+B;IACtC,MAAM,sBAAsB,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAE5C,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,CAAC;QACL,sBAAsB;QACtB,kBAAkB,EAAE,GAAG,EAAE;YACvB,sBAAsB,CAAC,OAAO,GAAG,IAAI,CAAC;QACxC,CAAC;QACD,mBAAmB,EAAE,GAAG,EAAE;YACxB,sBAAsB,CAAC,OAAO,GAAG,KAAK,CAAC;QACzC,CAAC;KACF,CAAC,EACF,EAAE,CACH,CAAC;AACJ,CAAC;AAED,MAAM,oBAAoB,GAAG,KAAK,CAAC,aAAa,CAC9C,SAAS,CACV,CAAC;AAEF,MAAM,UAAU,wBAAwB,CAAC,EACvC,QAAQ,GAGT;IACC,MAAM,KAAK,GAAG,+BAA+B,EAAE,CAAC;IAChD,OAAO,CACL,CAAC,oBAAoB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAC1C;MAAA,CAAC,QAAQ,CACX;IAAA,EAAE,oBAAoB,CAA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/C,CAAC,CAAC,kBAAkB,CAAC,GAAG,CAAC;gBACzB,CAAC,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAC;QAChC,CAAC;QACD,YAAY,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE;KAC1C,CAAC;AACJ,CAAC"}
@@ -5,4 +5,17 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  export declare const DEFAULT_SEARCH_TAG = "default";
8
+ /** The search tag to append as each doc's metadata. */
8
9
  export declare function docVersionSearchTag(pluginId: string, versionName: string): string;
10
+ /**
11
+ * Gets the relevant context information for contextual search.
12
+ *
13
+ * The value is generic and not coupled to Algolia/DocSearch, since we may want
14
+ * to support multiple search engines, or allowing users to use their own search
15
+ * engine solution.
16
+ */
17
+ export declare function useContextualSearchFilters(): {
18
+ locale: string;
19
+ tags: string[];
20
+ };
21
+ //# sourceMappingURL=searchUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"searchUtils.d.ts","sourceRoot":"","sources":["../../src/utils/searchUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,eAAO,MAAM,kBAAkB,YAAY,CAAC;AAE5C,uDAAuD;AACvD,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,GAClB,MAAM,CAER;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,IAAI;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAC,CAkC7E"}
@@ -4,7 +4,44 @@
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
+ import { useAllDocsData, useActivePluginAndVersion, } from '@docusaurus/plugin-content-docs/client';
8
+ import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
9
+ import { useDocsPreferredVersionByPluginId } from '../contexts/docsPreferredVersion';
7
10
  export const DEFAULT_SEARCH_TAG = 'default';
11
+ /** The search tag to append as each doc's metadata. */
8
12
  export function docVersionSearchTag(pluginId, versionName) {
9
13
  return `docs-${pluginId}-${versionName}`;
10
14
  }
15
+ /**
16
+ * Gets the relevant context information for contextual search.
17
+ *
18
+ * The value is generic and not coupled to Algolia/DocSearch, since we may want
19
+ * to support multiple search engines, or allowing users to use their own search
20
+ * engine solution.
21
+ */
22
+ export function useContextualSearchFilters() {
23
+ const { i18n } = useDocusaurusContext();
24
+ const allDocsData = useAllDocsData();
25
+ const activePluginAndVersion = useActivePluginAndVersion();
26
+ const docsPreferredVersionByPluginId = useDocsPreferredVersionByPluginId();
27
+ // This can't use more specialized hooks because we are mapping over all
28
+ // plugin instances.
29
+ function getDocPluginTags(pluginId) {
30
+ const activeVersion = activePluginAndVersion?.activePlugin.pluginId === pluginId
31
+ ? activePluginAndVersion.activeVersion
32
+ : undefined;
33
+ const preferredVersion = docsPreferredVersionByPluginId[pluginId];
34
+ const latestVersion = allDocsData[pluginId].versions.find((v) => v.isLast);
35
+ const version = activeVersion ?? preferredVersion ?? latestVersion;
36
+ return docVersionSearchTag(pluginId, version.name);
37
+ }
38
+ const tags = [
39
+ DEFAULT_SEARCH_TAG,
40
+ ...Object.keys(allDocsData).map(getDocPluginTags),
41
+ ];
42
+ return {
43
+ locale: i18n.currentLocale,
44
+ tags,
45
+ };
46
+ }
47
+ //# sourceMappingURL=searchUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"searchUtils.js","sourceRoot":"","sources":["../../src/utils/searchUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,cAAc,EACd,yBAAyB,GAC1B,MAAM,wCAAwC,CAAC;AAChD,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAC,iCAAiC,EAAC,MAAM,kCAAkC,CAAC;AAEnF,MAAM,CAAC,MAAM,kBAAkB,GAAG,SAAS,CAAC;AAE5C,uDAAuD;AACvD,MAAM,UAAU,mBAAmB,CACjC,QAAgB,EAChB,WAAmB;IAEnB,OAAO,QAAQ,QAAQ,IAAI,WAAW,EAAE,CAAC;AAC3C,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,0BAA0B;IACxC,MAAM,EAAC,IAAI,EAAC,GAAG,oBAAoB,EAAE,CAAC;IACtC,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IACrC,MAAM,sBAAsB,GAAG,yBAAyB,EAAE,CAAC;IAC3D,MAAM,8BAA8B,GAAG,iCAAiC,EAAE,CAAC;IAE3E,wEAAwE;IACxE,oBAAoB;IACpB,SAAS,gBAAgB,CAAC,QAAgB;QACxC,MAAM,aAAa,GACjB,sBAAsB,EAAE,YAAY,CAAC,QAAQ,KAAK,QAAQ;YACxD,CAAC,CAAC,sBAAsB,CAAC,aAAa;YACtC,CAAC,CAAC,SAAS,CAAC;QAEhB,MAAM,gBAAgB,GAAG,8BAA8B,CAAC,QAAQ,CAAC,CAAC;QAElE,MAAM,aAAa,GAAG,WAAW,CAAC,QAAQ,CAAE,CAAC,QAAQ,CAAC,IAAI,CACxD,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CACf,CAAC;QAEH,MAAM,OAAO,GAAG,aAAa,IAAI,gBAAgB,IAAI,aAAa,CAAC;QAEnE,OAAO,mBAAmB,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACrD,CAAC;IAED,MAAM,IAAI,GAAG;QACX,kBAAkB;QAClB,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,gBAAgB,CAAC;KAClD,CAAC;IAEF,OAAO;QACL,MAAM,EAAE,IAAI,CAAC,aAAa;QAC1B,IAAI;KACL,CAAC;AACJ,CAAC"}
@@ -6,20 +6,28 @@
6
6
  */
7
7
  declare const StorageTypes: readonly ["localStorage", "sessionStorage", "none"];
8
8
  export declare type StorageType = typeof StorageTypes[number];
9
- export interface StorageSlot {
9
+ export declare type StorageSlot = {
10
10
  get: () => string | null;
11
11
  set: (value: string) => void;
12
12
  del: () => void;
13
- }
13
+ };
14
14
  /**
15
- * Creates an object for accessing a particular key in localStorage.
15
+ * Creates an interface to work on a particular key in the storage model.
16
+ * Note that this function only initializes the interface, but doesn't allocate
17
+ * anything by itself (i.e. no side-effects).
18
+ *
19
+ * The API is fail-safe, since usage of browser storage should be considered
20
+ * unreliable. Local storage might simply be unavailable (iframe + browser
21
+ * security) or operations might fail individually. Please assume that using
22
+ * this API can be a no-op. See also https://github.com/facebook/docusaurus/issues/6036
16
23
  */
17
- export declare const createStorageSlot: (key: string, options?: {
18
- persistence?: "localStorage" | "none" | "sessionStorage" | undefined;
19
- } | undefined) => StorageSlot;
24
+ export declare function createStorageSlot(key: string, options?: {
25
+ persistence?: StorageType;
26
+ }): StorageSlot;
20
27
  /**
21
- * Returns a list of all the keys currently stored in browser storage
28
+ * Returns a list of all the keys currently stored in browser storage,
22
29
  * or an empty list if browser storage can't be accessed.
23
30
  */
24
31
  export declare function listStorageKeys(storageType?: StorageType): string[];
25
32
  export {};
33
+ //# sourceMappingURL=storageUtils.d.ts.map