@docusaurus/theme-common 2.0.0-beta.15d451942 → 2.0.0-beta.16

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 (211) hide show
  1. package/lib/components/Collapsible/index.d.ts +36 -0
  2. package/lib/components/Collapsible/index.d.ts.map +1 -0
  3. package/lib/components/Collapsible/index.js +144 -0
  4. package/lib/components/Collapsible/index.js.map +1 -0
  5. package/lib/components/Details/index.d.ts +12 -0
  6. package/lib/components/Details/index.d.ts.map +1 -0
  7. package/lib/components/Details/index.js +66 -0
  8. package/lib/components/Details/index.js.map +1 -0
  9. package/lib/components/Details/styles.module.css +58 -0
  10. package/lib/{utils/useChangeRoute.d.ts → hooks/styles.css} +4 -1
  11. package/lib/hooks/useHideableNavbar.d.ts +13 -0
  12. package/lib/hooks/useHideableNavbar.d.ts.map +1 -0
  13. package/lib/hooks/useHideableNavbar.js +59 -0
  14. package/lib/hooks/useHideableNavbar.js.map +1 -0
  15. package/lib/hooks/useKeyboardNavigation.d.ts +10 -0
  16. package/lib/hooks/useKeyboardNavigation.d.ts.map +1 -0
  17. package/lib/hooks/useKeyboardNavigation.js +31 -0
  18. package/lib/hooks/useKeyboardNavigation.js.map +1 -0
  19. package/{src/utils/docsUtils.ts → lib/hooks/useLockBodyScroll.d.ts} +2 -5
  20. package/lib/hooks/useLockBodyScroll.d.ts.map +1 -0
  21. package/lib/hooks/useLockBodyScroll.js +16 -0
  22. package/lib/hooks/useLockBodyScroll.js.map +1 -0
  23. package/lib/hooks/usePrismTheme.d.ts +9 -0
  24. package/lib/hooks/usePrismTheme.d.ts.map +1 -0
  25. package/lib/hooks/usePrismTheme.js +18 -0
  26. package/lib/hooks/usePrismTheme.js.map +1 -0
  27. package/lib/hooks/useSearchPage.d.ts +14 -0
  28. package/lib/hooks/useSearchPage.d.ts.map +1 -0
  29. package/lib/hooks/useSearchPage.js +43 -0
  30. package/lib/hooks/useSearchPage.js.map +1 -0
  31. package/lib/hooks/useWindowSize.d.ts +15 -0
  32. package/lib/hooks/useWindowSize.d.ts.map +1 -0
  33. package/lib/hooks/useWindowSize.js +56 -0
  34. package/lib/hooks/useWindowSize.js.map +1 -0
  35. package/lib/index.d.ts +35 -4
  36. package/lib/index.d.ts.map +1 -0
  37. package/lib/index.js +29 -3
  38. package/lib/index.js.map +1 -0
  39. package/lib/utils/ThemeClassNames.d.ts +40 -12
  40. package/lib/utils/ThemeClassNames.d.ts.map +1 -0
  41. package/lib/utils/ThemeClassNames.js +41 -3
  42. package/lib/utils/ThemeClassNames.js.map +1 -0
  43. package/lib/utils/announcementBarUtils.d.ts +18 -0
  44. package/lib/utils/announcementBarUtils.d.ts.map +1 -0
  45. package/lib/utils/announcementBarUtils.js +71 -0
  46. package/lib/utils/announcementBarUtils.js.map +1 -0
  47. package/lib/utils/codeBlockUtils.d.ts +10 -0
  48. package/lib/utils/codeBlockUtils.d.ts.map +1 -0
  49. package/lib/utils/codeBlockUtils.js +125 -2
  50. package/lib/utils/codeBlockUtils.js.map +1 -0
  51. package/lib/utils/colorModeUtils.d.ts +18 -0
  52. package/lib/utils/colorModeUtils.d.ts.map +1 -0
  53. package/lib/utils/colorModeUtils.js +106 -0
  54. package/lib/utils/colorModeUtils.js.map +1 -0
  55. package/lib/utils/docSidebarItemsExpandedState.d.ts +17 -0
  56. package/lib/utils/docSidebarItemsExpandedState.d.ts.map +1 -0
  57. package/lib/utils/docSidebarItemsExpandedState.js +22 -0
  58. package/lib/utils/docSidebarItemsExpandedState.js.map +1 -0
  59. package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.d.ts +3 -2
  60. package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.d.ts.map +1 -0
  61. package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js +8 -11
  62. package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js.map +1 -0
  63. package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.d.ts +2 -1
  64. package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.d.ts.map +1 -0
  65. package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.js +2 -3
  66. package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.js.map +1 -0
  67. package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.d.ts +12 -3
  68. package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.d.ts.map +1 -0
  69. package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.js +3 -3
  70. package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.js.map +1 -0
  71. package/lib/utils/docsUtils.d.ts +26 -0
  72. package/lib/utils/docsUtils.d.ts.map +1 -0
  73. package/lib/utils/docsUtils.js +136 -1
  74. package/lib/utils/docsUtils.js.map +1 -0
  75. package/lib/utils/generalUtils.d.ts +7 -0
  76. package/lib/utils/generalUtils.d.ts.map +1 -0
  77. package/lib/utils/generalUtils.js +3 -2
  78. package/lib/utils/generalUtils.js.map +1 -0
  79. package/lib/utils/historyUtils.d.ts +23 -0
  80. package/lib/utils/historyUtils.d.ts.map +1 -0
  81. package/lib/utils/historyUtils.js +41 -0
  82. package/lib/utils/historyUtils.js.map +1 -0
  83. package/lib/utils/jsUtils.d.ts +23 -0
  84. package/lib/utils/jsUtils.d.ts.map +1 -0
  85. package/lib/utils/jsUtils.js +29 -0
  86. package/lib/utils/jsUtils.js.map +1 -0
  87. package/lib/utils/mobileSecondaryMenu.d.ts +21 -0
  88. package/lib/utils/mobileSecondaryMenu.d.ts.map +1 -0
  89. package/lib/utils/mobileSecondaryMenu.js +50 -0
  90. package/lib/utils/mobileSecondaryMenu.js.map +1 -0
  91. package/lib/utils/pathUtils.d.ts +1 -0
  92. package/lib/utils/pathUtils.d.ts.map +1 -0
  93. package/lib/utils/pathUtils.js +6 -2
  94. package/lib/utils/pathUtils.js.map +1 -0
  95. package/lib/utils/reactUtils.d.ts +28 -0
  96. package/lib/utils/reactUtils.d.ts.map +1 -0
  97. package/lib/utils/reactUtils.js +36 -0
  98. package/lib/utils/reactUtils.js.map +1 -0
  99. package/lib/utils/regexpUtils.d.ts +11 -0
  100. package/lib/utils/regexpUtils.d.ts.map +1 -0
  101. package/lib/utils/regexpUtils.js +17 -0
  102. package/lib/utils/regexpUtils.js.map +1 -0
  103. package/lib/utils/routesUtils.d.ts +11 -0
  104. package/lib/utils/routesUtils.d.ts.map +1 -0
  105. package/lib/utils/routesUtils.js +33 -0
  106. package/lib/utils/routesUtils.js.map +1 -0
  107. package/lib/utils/scrollUtils.d.ts +53 -0
  108. package/lib/utils/scrollUtils.d.ts.map +1 -0
  109. package/lib/utils/scrollUtils.js +136 -0
  110. package/lib/utils/scrollUtils.js.map +1 -0
  111. package/lib/utils/searchUtils.d.ts +1 -0
  112. package/lib/utils/searchUtils.d.ts.map +1 -0
  113. package/lib/utils/searchUtils.js +1 -0
  114. package/lib/utils/searchUtils.js.map +1 -0
  115. package/lib/utils/storageUtils.d.ts +5 -0
  116. package/lib/utils/storageUtils.d.ts.map +1 -0
  117. package/lib/utils/storageUtils.js +41 -16
  118. package/lib/utils/storageUtils.js.map +1 -0
  119. package/lib/utils/tabGroupChoiceUtils.d.ts +19 -0
  120. package/lib/utils/tabGroupChoiceUtils.d.ts.map +1 -0
  121. package/lib/utils/tabGroupChoiceUtils.js +54 -0
  122. package/lib/utils/tabGroupChoiceUtils.js.map +1 -0
  123. package/lib/utils/tagsUtils.d.ts +19 -0
  124. package/lib/utils/tagsUtils.d.ts.map +1 -0
  125. package/lib/utils/tagsUtils.js +34 -0
  126. package/lib/utils/tagsUtils.js.map +1 -0
  127. package/lib/utils/tocUtils.d.ts +20 -0
  128. package/lib/utils/tocUtils.d.ts.map +1 -0
  129. package/lib/utils/tocUtils.js +73 -0
  130. package/lib/utils/tocUtils.js.map +1 -0
  131. package/lib/utils/useAlternatePageUtils.d.ts +1 -0
  132. package/lib/utils/useAlternatePageUtils.d.ts.map +1 -0
  133. package/lib/utils/useAlternatePageUtils.js +3 -1
  134. package/lib/utils/useAlternatePageUtils.js.map +1 -0
  135. package/lib/utils/useContextualSearchFilters.d.ts +12 -0
  136. package/lib/utils/useContextualSearchFilters.d.ts.map +1 -0
  137. package/lib/utils/useContextualSearchFilters.js +37 -0
  138. package/lib/utils/useContextualSearchFilters.js.map +1 -0
  139. package/lib/utils/useLocalPathname.d.ts +8 -0
  140. package/lib/utils/useLocalPathname.d.ts.map +1 -0
  141. package/lib/utils/useLocalPathname.js +17 -0
  142. package/lib/utils/useLocalPathname.js.map +1 -0
  143. package/lib/utils/useLocationChange.d.ts +15 -0
  144. package/lib/utils/useLocationChange.d.ts.map +1 -0
  145. package/lib/utils/useLocationChange.js +27 -0
  146. package/lib/utils/useLocationChange.js.map +1 -0
  147. package/lib/utils/usePluralForm.d.ts +1 -0
  148. package/lib/utils/usePluralForm.d.ts.map +1 -0
  149. package/lib/utils/usePluralForm.js +29 -25
  150. package/lib/utils/usePluralForm.js.map +1 -0
  151. package/lib/utils/usePrevious.d.ts +8 -0
  152. package/lib/utils/usePrevious.d.ts.map +1 -0
  153. package/lib/utils/usePrevious.js +16 -0
  154. package/lib/utils/usePrevious.js.map +1 -0
  155. package/lib/utils/useTOCHighlight.d.ts +14 -0
  156. package/lib/utils/useTOCHighlight.d.ts.map +1 -0
  157. package/lib/utils/useTOCHighlight.js +128 -0
  158. package/lib/utils/useTOCHighlight.js.map +1 -0
  159. package/lib/utils/useThemeConfig.d.ts +36 -11
  160. package/lib/utils/useThemeConfig.d.ts.map +1 -0
  161. package/lib/utils/useThemeConfig.js +1 -0
  162. package/lib/utils/useThemeConfig.js.map +1 -0
  163. package/package.json +19 -13
  164. package/src/components/Collapsible/index.tsx +247 -0
  165. package/src/components/Details/index.tsx +102 -0
  166. package/src/components/Details/styles.module.css +58 -0
  167. package/src/hooks/styles.css +10 -0
  168. package/src/hooks/useHideableNavbar.ts +77 -0
  169. package/src/hooks/useKeyboardNavigation.ts +37 -0
  170. package/src/hooks/useLockBodyScroll.ts +18 -0
  171. package/src/hooks/usePrismTheme.ts +20 -0
  172. package/src/hooks/useSearchPage.ts +66 -0
  173. package/src/hooks/useWindowSize.ts +70 -0
  174. package/src/index.ts +102 -4
  175. package/src/types.d.ts +0 -2
  176. package/src/utils/ThemeClassNames.ts +46 -4
  177. package/src/utils/announcementBarUtils.tsx +121 -0
  178. package/src/utils/codeBlockUtils.ts +153 -2
  179. package/src/utils/colorModeUtils.tsx +156 -0
  180. package/src/utils/docSidebarItemsExpandedState.tsx +41 -0
  181. package/src/utils/docsPreferredVersion/DocsPreferredVersionProvider.tsx +16 -14
  182. package/src/utils/docsPreferredVersion/DocsPreferredVersionStorage.ts +3 -4
  183. package/src/utils/docsPreferredVersion/useDocsPreferredVersion.ts +18 -14
  184. package/src/utils/docsUtils.tsx +230 -0
  185. package/src/utils/generalUtils.ts +3 -2
  186. package/src/utils/historyUtils.ts +51 -0
  187. package/src/utils/jsUtils.ts +36 -0
  188. package/src/utils/mobileSecondaryMenu.tsx +115 -0
  189. package/src/utils/pathUtils.ts +6 -4
  190. package/src/utils/reactUtils.tsx +43 -0
  191. package/src/utils/regexpUtils.ts +23 -0
  192. package/src/utils/routesUtils.ts +39 -0
  193. package/src/utils/scrollUtils.tsx +237 -0
  194. package/src/utils/storageUtils.ts +40 -15
  195. package/src/utils/tabGroupChoiceUtils.tsx +90 -0
  196. package/src/utils/tagsUtils.ts +48 -0
  197. package/src/utils/tocUtils.ts +108 -0
  198. package/src/utils/useAlternatePageUtils.ts +13 -4
  199. package/src/utils/useContextualSearchFilters.ts +53 -0
  200. package/src/utils/useLocalPathname.ts +20 -0
  201. package/src/utils/useLocationChange.ts +39 -0
  202. package/src/utils/usePluralForm.ts +35 -28
  203. package/src/utils/usePrevious.ts +19 -0
  204. package/src/utils/useTOCHighlight.ts +183 -0
  205. package/src/utils/useThemeConfig.ts +38 -11
  206. package/lib/.tsbuildinfo +0 -4159
  207. package/lib/utils/useChangeRoute.js +0 -18
  208. package/src/utils/__tests__/codeBlockUtils.test.ts +0 -54
  209. package/src/utils/__tests__/pathUtils.test.ts +0 -32
  210. package/src/utils/useChangeRoute.ts +0 -21
  211. package/tsconfig.json +0 -10
@@ -0,0 +1,102 @@
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
+ type ComponentProps,
10
+ type ReactElement,
11
+ useRef,
12
+ useState,
13
+ } from 'react';
14
+ import useIsBrowser from '@docusaurus/useIsBrowser';
15
+ import clsx from 'clsx';
16
+ import {useCollapsible, Collapsible} from '../Collapsible';
17
+ import styles from './styles.module.css';
18
+
19
+ function isInSummary(node: HTMLElement | null): boolean {
20
+ if (!node) {
21
+ return false;
22
+ }
23
+ return node.tagName === 'SUMMARY' || isInSummary(node.parentElement);
24
+ }
25
+
26
+ function hasParent(node: HTMLElement | null, parent: HTMLElement): boolean {
27
+ if (!node) {
28
+ return false;
29
+ }
30
+ return node === parent || hasParent(node.parentElement, parent);
31
+ }
32
+
33
+ export type DetailsProps = {
34
+ summary?: ReactElement;
35
+ } & ComponentProps<'details'>;
36
+
37
+ export default function Details({
38
+ summary,
39
+ children,
40
+ ...props
41
+ }: DetailsProps): JSX.Element {
42
+ const isBrowser = useIsBrowser();
43
+ const detailsRef = useRef<HTMLDetailsElement>(null);
44
+
45
+ const {collapsed, setCollapsed} = useCollapsible({
46
+ initialState: !props.open,
47
+ });
48
+ // Use a separate prop because it must be set only after animation completes
49
+ // Otherwise close anim won't work
50
+ const [open, setOpen] = useState(props.open);
51
+
52
+ return (
53
+ // eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions
54
+ <details
55
+ {...props}
56
+ ref={detailsRef}
57
+ open={open}
58
+ data-collapsed={collapsed}
59
+ className={clsx(
60
+ styles.details,
61
+ {[styles.isBrowser]: isBrowser},
62
+ props.className,
63
+ )}
64
+ onMouseDown={(e) => {
65
+ const target = e.target as HTMLElement;
66
+ // Prevent a double-click to highlight summary text
67
+ if (isInSummary(target) && e.detail > 1) {
68
+ e.preventDefault();
69
+ }
70
+ }}
71
+ onClick={(e) => {
72
+ e.stopPropagation(); // For isolation of multiple nested details/summary
73
+ const target = e.target as HTMLElement;
74
+ const shouldToggle =
75
+ isInSummary(target) && hasParent(target, detailsRef.current!);
76
+ if (!shouldToggle) {
77
+ return;
78
+ }
79
+ e.preventDefault();
80
+ if (collapsed) {
81
+ setCollapsed(false);
82
+ setOpen(true);
83
+ } else {
84
+ setCollapsed(true);
85
+ // setOpen(false); // Don't do this, it breaks close animation!
86
+ }
87
+ }}>
88
+ {summary}
89
+
90
+ <Collapsible
91
+ lazy={false} // Content might matter for SEO in this case
92
+ collapsed={collapsed}
93
+ disableSSRStyle // Allows component to work fine even with JS disabled!
94
+ onCollapseTransitionEnd={(newCollapsed) => {
95
+ setCollapsed(newCollapsed);
96
+ setOpen(!newCollapsed);
97
+ }}>
98
+ <div className={styles.collapsibleContent}>{children}</div>
99
+ </Collapsible>
100
+ </details>
101
+ );
102
+ }
@@ -0,0 +1,58 @@
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
+ /*
9
+ CSS variables, meant to be overridden by final theme
10
+ */
11
+ .details {
12
+ --docusaurus-details-summary-arrow-size: 0.38rem;
13
+ --docusaurus-details-transition: transform 200ms ease;
14
+ --docusaurus-details-decoration-color: grey;
15
+ }
16
+
17
+ .details > summary {
18
+ position: relative;
19
+ cursor: pointer;
20
+ list-style: none;
21
+ padding-left: 1rem;
22
+ }
23
+
24
+ /* TODO: deprecation, need to remove this after Safari will support `::marker` */
25
+ .details > summary::-webkit-details-marker {
26
+ display: none;
27
+ }
28
+
29
+ .details > summary::before {
30
+ position: absolute;
31
+ top: 0.45rem;
32
+ left: 0;
33
+
34
+ /* CSS-only Arrow */
35
+ content: '';
36
+ border-width: var(--docusaurus-details-summary-arrow-size);
37
+ border-style: solid;
38
+ border-color: transparent transparent transparent
39
+ var(--docusaurus-details-decoration-color);
40
+
41
+ /* Arrow rotation anim */
42
+ transform: rotate(0deg);
43
+ transition: var(--docusaurus-details-transition);
44
+ transform-origin: calc(var(--docusaurus-details-summary-arrow-size) / 2) 50%;
45
+ }
46
+
47
+ /* When JS disabled/failed to load: we use the open property for arrow animation: */
48
+ .details[open]:not(.isBrowser) > summary::before,
49
+ /* When JS works: we use the data-attribute for arrow animation */
50
+ .details[data-collapsed='false'].isBrowser > summary::before {
51
+ transform: rotate(90deg);
52
+ }
53
+
54
+ .collapsibleContent {
55
+ margin-top: 1rem;
56
+ border-top: 1px solid var(--docusaurus-details-decoration-color);
57
+ padding-top: 1rem;
58
+ }
@@ -0,0 +1,10 @@
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
+ body:not(.navigation-with-keyboard) *:not(input):focus {
9
+ outline: none;
10
+ }
@@ -0,0 +1,77 @@
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 {useState, useCallback, useRef} from 'react';
9
+ import {useLocationChange} from '../utils/useLocationChange';
10
+ import {useScrollPosition} from '../utils/scrollUtils';
11
+
12
+ type UseHideableNavbarReturns = {
13
+ readonly navbarRef: (node: HTMLElement | null) => void;
14
+ readonly isNavbarVisible: boolean;
15
+ };
16
+
17
+ export default function useHideableNavbar(
18
+ hideOnScroll: boolean,
19
+ ): UseHideableNavbarReturns {
20
+ const [isNavbarVisible, setIsNavbarVisible] = useState(hideOnScroll);
21
+ const isFocusedAnchor = useRef(false);
22
+ const navbarHeight = useRef(0);
23
+ const navbarRef = useCallback((node: HTMLElement | null) => {
24
+ if (node !== null) {
25
+ navbarHeight.current = node.getBoundingClientRect().height;
26
+ }
27
+ }, []);
28
+
29
+ useScrollPosition((currentPosition, lastPosition) => {
30
+ if (!hideOnScroll) {
31
+ return;
32
+ }
33
+
34
+ const scrollTop = currentPosition.scrollY;
35
+
36
+ // It needed for mostly to handle rubber band scrolling
37
+ if (scrollTop < navbarHeight.current) {
38
+ setIsNavbarVisible(true);
39
+ return;
40
+ }
41
+
42
+ if (isFocusedAnchor.current) {
43
+ isFocusedAnchor.current = false;
44
+ return;
45
+ }
46
+
47
+ const lastScrollTop = lastPosition?.scrollY;
48
+ const documentHeight =
49
+ document.documentElement.scrollHeight - navbarHeight.current;
50
+ const windowHeight = window.innerHeight;
51
+
52
+ if (lastScrollTop && scrollTop >= lastScrollTop) {
53
+ setIsNavbarVisible(false);
54
+ } else if (scrollTop + windowHeight < documentHeight) {
55
+ setIsNavbarVisible(true);
56
+ }
57
+ });
58
+
59
+ useLocationChange((locationChangeEvent) => {
60
+ if (!hideOnScroll) {
61
+ return;
62
+ }
63
+
64
+ if (locationChangeEvent.location.hash) {
65
+ isFocusedAnchor.current = true;
66
+ setIsNavbarVisible(false);
67
+ return;
68
+ }
69
+
70
+ setIsNavbarVisible(true);
71
+ });
72
+
73
+ return {
74
+ navbarRef,
75
+ isNavbarVisible,
76
+ };
77
+ }
@@ -0,0 +1,37 @@
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
+
10
+ import './styles.css';
11
+
12
+ export const keyboardFocusedClassName = 'navigation-with-keyboard';
13
+
14
+ // This hook detect keyboard focus indicator to not show outline for mouse users
15
+ // Inspired by https://hackernoon.com/removing-that-ugly-focus-ring-and-keeping-it-too-6c8727fefcd2
16
+ export default function useKeyboardNavigation(): void {
17
+ useEffect(() => {
18
+ function handleOutlineStyles(e: MouseEvent | KeyboardEvent) {
19
+ if (e.type === 'keydown' && (e as KeyboardEvent).key === 'Tab') {
20
+ document.body.classList.add(keyboardFocusedClassName);
21
+ }
22
+
23
+ if (e.type === 'mousedown') {
24
+ document.body.classList.remove(keyboardFocusedClassName);
25
+ }
26
+ }
27
+
28
+ document.addEventListener('keydown', handleOutlineStyles);
29
+ document.addEventListener('mousedown', handleOutlineStyles);
30
+
31
+ return () => {
32
+ document.body.classList.remove(keyboardFocusedClassName);
33
+ document.removeEventListener('keydown', handleOutlineStyles);
34
+ document.removeEventListener('mousedown', handleOutlineStyles);
35
+ };
36
+ }, []);
37
+ }
@@ -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
+ import {useEffect} from 'react';
9
+
10
+ export default function useLockBodyScroll(lock: boolean = true): void {
11
+ useEffect(() => {
12
+ document.body.style.overflow = lock ? 'hidden' : 'visible';
13
+
14
+ return () => {
15
+ document.body.style.overflow = 'visible';
16
+ };
17
+ }, [lock]);
18
+ }
@@ -0,0 +1,20 @@
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 defaultTheme from 'prism-react-renderer/themes/palenight';
9
+ import {useColorMode} from '../utils/colorModeUtils';
10
+ import {useThemeConfig} from '../utils/useThemeConfig';
11
+
12
+ export default function usePrismTheme(): typeof defaultTheme {
13
+ const {prism} = useThemeConfig();
14
+ const {isDarkTheme} = useColorMode();
15
+ const lightModeTheme = prism.theme || defaultTheme;
16
+ const darkModeTheme = prism.darkTheme || lightModeTheme;
17
+ const prismTheme = isDarkTheme ? darkModeTheme : lightModeTheme;
18
+
19
+ return prismTheme;
20
+ }
@@ -0,0 +1,66 @@
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 {useHistory} from '@docusaurus/router';
9
+ import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
10
+ import {useCallback, useEffect, useState} from 'react';
11
+
12
+ const SEARCH_PARAM_QUERY = 'q';
13
+
14
+ interface UseSearchPageReturn {
15
+ searchQuery: string;
16
+ setSearchQuery: (newSearchQuery: string) => void;
17
+ generateSearchPageLink: (targetSearchQuery: string) => string;
18
+ }
19
+
20
+ export default function useSearchPage(): UseSearchPageReturn {
21
+ const history = useHistory();
22
+ const {
23
+ siteConfig: {baseUrl},
24
+ } = useDocusaurusContext();
25
+
26
+ const [searchQuery, setSearchQueryState] = useState('');
27
+
28
+ // Init search query just after React hydration
29
+ useEffect(() => {
30
+ const searchQueryStringValue =
31
+ new URLSearchParams(window.location.search).get(SEARCH_PARAM_QUERY) ?? '';
32
+
33
+ setSearchQueryState(searchQueryStringValue);
34
+ }, []);
35
+
36
+ const setSearchQuery = useCallback(
37
+ (newSearchQuery: string) => {
38
+ const searchParams = new URLSearchParams(window.location.search);
39
+
40
+ if (newSearchQuery) {
41
+ searchParams.set(SEARCH_PARAM_QUERY, newSearchQuery);
42
+ } else {
43
+ searchParams.delete(SEARCH_PARAM_QUERY);
44
+ }
45
+
46
+ history.replace({
47
+ search: searchParams.toString(),
48
+ });
49
+ setSearchQueryState(newSearchQuery);
50
+ },
51
+ [history],
52
+ );
53
+
54
+ const generateSearchPageLink = useCallback(
55
+ (targetSearchQuery: string) =>
56
+ // Refer to https://github.com/facebook/docusaurus/pull/2838
57
+ `${baseUrl}search?q=${encodeURIComponent(targetSearchQuery)}`,
58
+ [baseUrl],
59
+ );
60
+
61
+ return {
62
+ searchQuery,
63
+ setSearchQuery,
64
+ generateSearchPageLink,
65
+ };
66
+ }
@@ -0,0 +1,70 @@
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, useState} from 'react';
9
+
10
+ import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
11
+
12
+ const windowSizes = {
13
+ desktop: 'desktop',
14
+ mobile: 'mobile',
15
+
16
+ // This "ssr" value is very important to handle hydration FOUC / layout shifts
17
+ // You have to handle server-rendering explicitly on the call-site
18
+ // On the server, you may need to render BOTH the mobile/desktop elements (and
19
+ // hide one of them with mediaquery)
20
+ // We don't return "undefined" on purpose, to make it more explicit
21
+ ssr: 'ssr',
22
+ } as const;
23
+
24
+ type WindowSize = keyof typeof windowSizes;
25
+
26
+ const DesktopThresholdWidth = 996;
27
+
28
+ function getWindowSize() {
29
+ if (!ExecutionEnvironment.canUseDOM) {
30
+ return windowSizes.ssr;
31
+ }
32
+ return window.innerWidth > DesktopThresholdWidth
33
+ ? windowSizes.desktop
34
+ : windowSizes.mobile;
35
+ }
36
+
37
+ // Simulate the SSR window size in dev, so that potential hydration FOUC/layout
38
+ // shift problems can be seen in dev too!
39
+ const DevSimulateSSR = process.env.NODE_ENV === 'development' && true;
40
+
41
+ // This hook returns an enum value on purpose!
42
+ // We don't want it to return the actual width value, for resize perf reasons
43
+ // We only want to re-render once a breakpoint is crossed
44
+ export default function useWindowSize(): WindowSize {
45
+ const [windowSize, setWindowSize] = useState<WindowSize>(() => {
46
+ if (DevSimulateSSR) {
47
+ return 'ssr';
48
+ }
49
+ return getWindowSize();
50
+ });
51
+
52
+ useEffect(() => {
53
+ function updateWindowSize() {
54
+ setWindowSize(getWindowSize());
55
+ }
56
+
57
+ const timeout = DevSimulateSSR
58
+ ? window.setTimeout(updateWindowSize, 1000)
59
+ : undefined;
60
+
61
+ window.addEventListener('resize', updateWindowSize);
62
+
63
+ return () => {
64
+ window.removeEventListener('resize', updateWindowSize);
65
+ clearTimeout(timeout);
66
+ };
67
+ }, []);
68
+
69
+ return windowSize;
70
+ }
package/src/index.ts CHANGED
@@ -6,26 +6,51 @@
6
6
  */
7
7
 
8
8
  export {useThemeConfig} from './utils/useThemeConfig';
9
+ export {
10
+ DocSidebarItemsExpandedStateProvider,
11
+ useDocSidebarItemsExpandedState,
12
+ } from './utils/docSidebarItemsExpandedState';
9
13
 
10
14
  export type {
11
15
  ThemeConfig,
16
+ UserThemeConfig,
12
17
  Navbar,
13
18
  NavbarItem,
14
19
  NavbarLogo,
20
+ MultiColumnFooter,
21
+ SimpleFooter,
15
22
  Footer,
16
- FooterLinks,
17
23
  FooterLinkItem,
24
+ ColorModeConfig,
18
25
  } from './utils/useThemeConfig';
19
26
 
20
27
  export {createStorageSlot, listStorageKeys} from './utils/storageUtils';
21
28
 
22
29
  export {useAlternatePageUtils} from './utils/useAlternatePageUtils';
23
30
 
24
- export {parseCodeBlockTitle} from './utils/codeBlockUtils';
31
+ export {useContextualSearchFilters} from './utils/useContextualSearchFilters';
32
+
33
+ export {
34
+ parseCodeBlockTitle,
35
+ parseLanguage,
36
+ parseLines,
37
+ } from './utils/codeBlockUtils';
25
38
 
26
39
  export {docVersionSearchTag, DEFAULT_SEARCH_TAG} from './utils/searchUtils';
27
40
 
28
- export {isDocsPluginEnabled} from './utils/docsUtils';
41
+ export {
42
+ isDocsPluginEnabled,
43
+ DocsVersionProvider,
44
+ useDocsVersion,
45
+ useDocById,
46
+ DocsSidebarProvider,
47
+ useDocsSidebar,
48
+ findSidebarCategory,
49
+ findFirstCategoryLink,
50
+ useCurrentSidebarCategory,
51
+ isActiveSidebarItem,
52
+ useSidebarBreadcrumbs,
53
+ } from './utils/docsUtils';
29
54
 
30
55
  export {isSamePath} from './utils/pathUtils';
31
56
 
@@ -33,13 +58,86 @@ export {useTitleFormatter} from './utils/generalUtils';
33
58
 
34
59
  export {usePluralForm} from './utils/usePluralForm';
35
60
 
36
- export {useChangeRoute} from './utils/useChangeRoute';
61
+ export {useLocationChange} from './utils/useLocationChange';
62
+
63
+ export {usePrevious} from './utils/usePrevious';
64
+
65
+ export {useCollapsible, Collapsible} from './components/Collapsible';
66
+ export type {
67
+ UseCollapsibleConfig,
68
+ UseCollapsibleReturns,
69
+ } from './components/Collapsible';
70
+
71
+ export {default as Details} from './components/Details';
72
+ export type {DetailsProps} from './components/Details';
73
+
74
+ export {
75
+ MobileSecondaryMenuProvider,
76
+ MobileSecondaryMenuFiller,
77
+ useMobileSecondaryMenuRenderer,
78
+ } from './utils/mobileSecondaryMenu';
79
+ export type {MobileSecondaryMenuComponent} from './utils/mobileSecondaryMenu';
37
80
 
38
81
  export {
39
82
  useDocsPreferredVersion,
40
83
  useDocsPreferredVersionByPluginId,
41
84
  } from './utils/docsPreferredVersion/useDocsPreferredVersion';
42
85
 
86
+ export {duplicates, uniq} from './utils/jsUtils';
87
+
43
88
  export {DocsPreferredVersionContextProvider} from './utils/docsPreferredVersion/DocsPreferredVersionProvider';
44
89
 
45
90
  export {ThemeClassNames} from './utils/ThemeClassNames';
91
+
92
+ export {
93
+ AnnouncementBarProvider,
94
+ useAnnouncementBar,
95
+ } from './utils/announcementBarUtils';
96
+
97
+ export {useLocalPathname} from './utils/useLocalPathname';
98
+
99
+ export {translateTagsPageTitle, listTagsByLetters} from './utils/tagsUtils';
100
+ export type {TagLetterEntry} from './utils/tagsUtils';
101
+
102
+ export {useHistoryPopHandler} from './utils/historyUtils';
103
+
104
+ export {default as useTOCHighlight} from './utils/useTOCHighlight';
105
+ export type {TOCHighlightConfig} from './utils/useTOCHighlight';
106
+
107
+ export {
108
+ useFilteredAndTreeifiedTOC,
109
+ useTreeifiedTOC,
110
+ type TOCTreeNode,
111
+ } from './utils/tocUtils';
112
+
113
+ export {
114
+ ScrollControllerProvider,
115
+ useScrollController,
116
+ useScrollPosition,
117
+ useScrollPositionBlocker,
118
+ } from './utils/scrollUtils';
119
+
120
+ export {
121
+ useIsomorphicLayoutEffect,
122
+ useDynamicCallback,
123
+ } from './utils/reactUtils';
124
+
125
+ export {isRegexpStringMatch} from './utils/regexpUtils';
126
+
127
+ export {useHomePageRoute} from './utils/routesUtils';
128
+
129
+ export {useColorMode, ColorModeProvider} from './utils/colorModeUtils';
130
+ export {
131
+ useTabGroupChoice,
132
+ TabGroupChoiceProvider,
133
+ } from './utils/tabGroupChoiceUtils';
134
+
135
+ export {default as useHideableNavbar} from './hooks/useHideableNavbar';
136
+ export {
137
+ default as useKeyboardNavigation,
138
+ keyboardFocusedClassName,
139
+ } from './hooks/useKeyboardNavigation';
140
+ export {default as usePrismTheme} from './hooks/usePrismTheme';
141
+ export {default as useLockBodyScroll} from './hooks/useLockBodyScroll';
142
+ export {default as useWindowSize} from './hooks/useWindowSize';
143
+ export {default as useSearchPage} from './hooks/useSearchPage';
package/src/types.d.ts CHANGED
@@ -5,8 +5,6 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- /* eslint-disable import/no-duplicates */
9
- /* eslint-disable spaced-comment */
10
8
  /// <reference types="@docusaurus/module-type-aliases" />
11
9
  /// <reference types="@docusaurus/plugin-content-blog" />
12
10
  /// <reference types="@docusaurus/plugin-content-docs" />
@@ -6,19 +6,61 @@
6
6
  */
7
7
 
8
8
  // These class names are used to style page layouts in Docusaurus
9
+ // Those are meant to be targeted by user-provided custom CSS selectors
10
+ // Please do not modify the classnames! This is a breaking change, and annoying
11
+ // for users!
9
12
  export const ThemeClassNames = {
10
13
  page: {
11
14
  blogListPage: 'blog-list-page',
12
15
  blogPostPage: 'blog-post-page',
13
16
  blogTagsListPage: 'blog-tags-list-page',
14
- blogTagsPostPage: 'blog-tags-post-page',
15
- docPage: 'doc-page',
17
+ blogTagPostListPage: 'blog-tags-post-list-page',
18
+
19
+ docsDocPage: 'docs-doc-page',
20
+ docsTagsListPage: 'docs-tags-list-page', // List of tags
21
+ docsTagDocListPage: 'docs-tags-doc-list-page', // Docs for a tag
22
+
16
23
  mdxPage: 'mdx-page',
17
24
  },
18
25
  wrapper: {
19
26
  main: 'main-wrapper',
20
27
  blogPages: 'blog-wrapper',
21
- docPages: 'docs-wrapper',
28
+ docsPages: 'docs-wrapper',
22
29
  mdxPages: 'mdx-wrapper',
23
30
  },
24
- };
31
+
32
+ // /!\ Please keep the naming convention consistent!
33
+ // Something like: "theme-{blog,doc,version,page}?-<suffix>"
34
+ common: {
35
+ editThisPage: 'theme-edit-this-page',
36
+ lastUpdated: 'theme-last-updated',
37
+ backToTopButton: 'theme-back-to-top-button',
38
+ codeBlock: 'theme-code-block',
39
+ },
40
+ layout: {
41
+ // TODO add other stable classNames here
42
+ },
43
+ docs: {
44
+ docVersionBanner: 'theme-doc-version-banner',
45
+ docVersionBadge: 'theme-doc-version-badge',
46
+ docBreadcrumbs: 'theme-doc-breadcrumbs',
47
+ docMarkdown: 'theme-doc-markdown',
48
+ docTocMobile: 'theme-doc-toc-mobile',
49
+ docTocDesktop: 'theme-doc-toc-desktop',
50
+ docFooter: 'theme-doc-footer',
51
+ docFooterTagsRow: 'theme-doc-footer-tags-row',
52
+ docFooterEditMetaRow: 'theme-doc-footer-edit-meta-row',
53
+ docSidebarContainer: 'theme-doc-sidebar-container',
54
+ docSidebarMenu: 'theme-doc-sidebar-menu',
55
+ docSidebarItemCategory: 'theme-doc-sidebar-item-category',
56
+ docSidebarItemLink: 'theme-doc-sidebar-item-link',
57
+ docSidebarItemCategoryLevel: (level: number) =>
58
+ `theme-doc-sidebar-item-category-level-${level}` as const,
59
+ docSidebarItemLinkLevel: (level: number) =>
60
+ `theme-doc-sidebar-item-link-level-${level}` as const,
61
+ // TODO add other stable classNames here
62
+ },
63
+ blog: {
64
+ // TODO add other stable classNames here
65
+ },
66
+ } as const;