@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
@@ -6,15 +6,15 @@
6
6
  */
7
7
 
8
8
  import {useEffect, useRef} from 'react';
9
- import {useThemeConfig} from './useThemeConfig';
9
+ import {useThemeConfig} from '../utils/useThemeConfig';
10
10
 
11
- /*
12
- TODO make the hardcoded theme-classic classnames configurable
13
- (or add them to ThemeClassNames?)
14
- */
11
+ // TODO make the hardcoded theme-classic classnames configurable (or add them
12
+ // to ThemeClassNames?)
15
13
 
16
- // If the anchor has no height and is just a "marker" in the dom; we'll use the
17
- // parent (normally the link text) rect boundaries instead
14
+ /**
15
+ * If the anchor has no height and is just a "marker" in the DOM; we'll use the
16
+ * parent (normally the link text) rect boundaries instead
17
+ */
18
18
  function getVisibleBoundingClientRect(element: HTMLElement): DOMRect {
19
19
  const rect = element.getBoundingClientRect();
20
20
  const hasNoHeight = rect.top === rect.bottom;
@@ -26,7 +26,7 @@ function getVisibleBoundingClientRect(element: HTMLElement): DOMRect {
26
26
 
27
27
  /**
28
28
  * Considering we divide viewport into 2 zones of each 50vh, this returns true
29
- * if an element is in the first zone (ie, appear in viewport, near the top)
29
+ * if an element is in the first zone (i.e., appear in viewport, near the top)
30
30
  */
31
31
  function isInViewportTopHalf(boundingRect: DOMRect) {
32
32
  return boundingRect.top > 0 && boundingRect.bottom < window.innerHeight / 2;
@@ -81,9 +81,9 @@ function getActiveAnchor(
81
81
  // https://github.com/facebook/docusaurus/issues/5318
82
82
  return anchors[anchors.indexOf(nextVisibleAnchor) - 1] ?? null;
83
83
  }
84
- // no anchor under viewport top? (ie we are at the bottom of the page)
85
- // => highlight the last anchor found
86
- return anchors[anchors.length - 1];
84
+ // No anchor under viewport top (i.e. we are at the bottom of the page),
85
+ // highlight the last anchor found
86
+ return anchors[anchors.length - 1] ?? null;
87
87
  }
88
88
 
89
89
  function getLinkAnchorValue(link: HTMLAnchorElement): string {
@@ -116,22 +116,31 @@ function useAnchorTopOffsetRef() {
116
116
  }
117
117
 
118
118
  export type TOCHighlightConfig = {
119
+ /** A class name that all TOC links share. */
119
120
  linkClassName: string;
121
+ /** The class name applied to the active (highlighted) link. */
120
122
  linkActiveClassName: string;
123
+ /**
124
+ * The minimum heading level that the TOC includes. Only headings that are in
125
+ * this range will be eligible as "active heading".
126
+ */
121
127
  minHeadingLevel: number;
128
+ /** @see {@link TOCHighlightConfig.minHeadingLevel} */
122
129
  maxHeadingLevel: number;
123
130
  };
124
131
 
125
- export default function useTOCHighlight(
126
- config: TOCHighlightConfig | undefined,
127
- ): void {
132
+ /**
133
+ * Side-effect that applies the active class name to the TOC heading that the
134
+ * user is currently viewing. Disabled when `config` is undefined.
135
+ */
136
+ export function useTOCHighlight(config: TOCHighlightConfig | undefined): void {
128
137
  const lastActiveLinkRef = useRef<HTMLAnchorElement | undefined>(undefined);
129
138
 
130
139
  const anchorTopOffsetRef = useAnchorTopOffsetRef();
131
140
 
132
141
  useEffect(() => {
133
142
  if (!config) {
134
- // no-op, highlighting is disabled
143
+ // No-op, highlighting is disabled
135
144
  return () => {};
136
145
  }
137
146
 
@@ -12,12 +12,6 @@ import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
12
12
  const windowSizes = {
13
13
  desktop: 'desktop',
14
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
15
  ssr: 'ssr',
22
16
  } as const;
23
17
 
@@ -34,14 +28,22 @@ function getWindowSize() {
34
28
  : windowSizes.mobile;
35
29
  }
36
30
 
37
- // Simulate the SSR window size in dev, so that potential hydration FOUC/layout
38
- // shift problems can be seen in dev too!
39
31
  const DevSimulateSSR = process.env.NODE_ENV === 'development' && true;
40
32
 
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 {
33
+ /**
34
+ * Gets the current window size as an enum value. We don't want it to return the
35
+ * actual width value, so that it only re-renders once a breakpoint is crossed.
36
+ *
37
+ * It may return `"ssr"`, which is very important to handle hydration FOUC or
38
+ * layout shifts. You have to handle it explicitly upfront. On the server, you
39
+ * may need to render BOTH the mobile/desktop elements (and hide one of them
40
+ * with mediaquery). We don't return `undefined` on purpose, to make it more
41
+ * explicit.
42
+ *
43
+ * In development mode, this hook will still return `"ssr"` for one second, to
44
+ * catch potential layout shifts, similar to strict mode calling effects twice.
45
+ */
46
+ export function useWindowSize(): WindowSize {
45
47
  const [windowSize, setWindowSize] = useState<WindowSize>(() => {
46
48
  if (DevSimulateSSR) {
47
49
  return 'ssr';
package/src/index.ts CHANGED
@@ -5,104 +5,96 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- export {useThemeConfig} from './utils/useThemeConfig';
8
+ export {
9
+ useThemeConfig,
10
+ type ThemeConfig,
11
+ type UserThemeConfig,
12
+ type Navbar,
13
+ type NavbarItem,
14
+ type NavbarLogo,
15
+ type MultiColumnFooter,
16
+ type SimpleFooter,
17
+ type Footer,
18
+ type FooterLogo,
19
+ type FooterLinkItem,
20
+ type ColorModeConfig,
21
+ } from './utils/useThemeConfig';
9
22
  export {
10
23
  DocSidebarItemsExpandedStateProvider,
11
24
  useDocSidebarItemsExpandedState,
12
- } from './utils/docSidebarItemsExpandedState';
13
-
14
- export type {
15
- ThemeConfig,
16
- UserThemeConfig,
17
- Navbar,
18
- NavbarItem,
19
- NavbarLogo,
20
- MultiColumnFooter,
21
- SimpleFooter,
22
- Footer,
23
- FooterLinkItem,
24
- ColorModeConfig,
25
- } from './utils/useThemeConfig';
25
+ } from './contexts/docSidebarItemsExpandedState';
26
+ export {DocsVersionProvider, useDocsVersion} from './contexts/docsVersion';
27
+ export {DocsSidebarProvider, useDocsSidebar} from './contexts/docsSidebar';
26
28
 
27
29
  export {createStorageSlot, listStorageKeys} from './utils/storageUtils';
28
30
 
29
31
  export {useAlternatePageUtils} from './utils/useAlternatePageUtils';
30
32
 
31
- export {useContextualSearchFilters} from './utils/useContextualSearchFilters';
32
-
33
33
  export {
34
34
  parseCodeBlockTitle,
35
35
  parseLanguage,
36
36
  parseLines,
37
+ containsLineNumbers,
38
+ getPrismCssVariables,
37
39
  } from './utils/codeBlockUtils';
38
40
 
39
- export {docVersionSearchTag, DEFAULT_SEARCH_TAG} from './utils/searchUtils';
41
+ export {
42
+ docVersionSearchTag,
43
+ DEFAULT_SEARCH_TAG,
44
+ useContextualSearchFilters,
45
+ } from './utils/searchUtils';
40
46
 
41
47
  export {
42
48
  isDocsPluginEnabled,
43
- DocsVersionProvider,
44
- useDocsVersion,
45
49
  useDocById,
46
- DocsSidebarProvider,
47
- useDocsSidebar,
48
50
  findSidebarCategory,
49
51
  findFirstCategoryLink,
50
52
  useCurrentSidebarCategory,
51
53
  isActiveSidebarItem,
52
54
  useSidebarBreadcrumbs,
55
+ useDocsVersionCandidates,
56
+ useLayoutDoc,
57
+ useLayoutDocsSidebar,
58
+ useDocRouteMetadata,
53
59
  } from './utils/docsUtils';
54
60
 
55
- export {isSamePath} from './utils/pathUtils';
56
-
57
61
  export {useTitleFormatter} from './utils/generalUtils';
58
62
 
59
63
  export {usePluralForm} from './utils/usePluralForm';
60
64
 
61
65
  export {useLocationChange} from './utils/useLocationChange';
62
66
 
63
- export {usePrevious} from './utils/usePrevious';
64
-
65
67
  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';
80
68
 
81
69
  export {
82
70
  useDocsPreferredVersion,
83
71
  useDocsPreferredVersionByPluginId,
84
- } from './utils/docsPreferredVersion/useDocsPreferredVersion';
72
+ DocsPreferredVersionContextProvider,
73
+ } from './contexts/docsPreferredVersion';
85
74
 
86
75
  export {duplicates, uniq} from './utils/jsUtils';
87
76
 
88
- export {DocsPreferredVersionContextProvider} from './utils/docsPreferredVersion/DocsPreferredVersionProvider';
89
-
90
77
  export {ThemeClassNames} from './utils/ThemeClassNames';
91
78
 
92
79
  export {
93
80
  AnnouncementBarProvider,
94
81
  useAnnouncementBar,
95
- } from './utils/announcementBarUtils';
82
+ } from './contexts/announcementBar';
96
83
 
97
84
  export {useLocalPathname} from './utils/useLocalPathname';
98
85
 
99
- export {translateTagsPageTitle, listTagsByLetters} from './utils/tagsUtils';
100
- export type {TagLetterEntry} from './utils/tagsUtils';
86
+ export {
87
+ translateTagsPageTitle,
88
+ listTagsByLetters,
89
+ type TagLetterEntry,
90
+ } from './utils/tagsUtils';
101
91
 
102
92
  export {useHistoryPopHandler} from './utils/historyUtils';
103
93
 
104
- export {default as useTOCHighlight} from './utils/useTOCHighlight';
105
- export type {TOCHighlightConfig} from './utils/useTOCHighlight';
94
+ export {
95
+ useTOCHighlight,
96
+ type TOCHighlightConfig,
97
+ } from './hooks/useTOCHighlight';
106
98
 
107
99
  export {
108
100
  useFilteredAndTreeifiedTOC,
@@ -110,34 +102,62 @@ export {
110
102
  type TOCTreeNode,
111
103
  } from './utils/tocUtils';
112
104
 
105
+ export {isMultiColumnFooterLinks} from './utils/footerUtils';
106
+
113
107
  export {
114
108
  ScrollControllerProvider,
115
109
  useScrollController,
116
110
  useScrollPosition,
117
111
  useScrollPositionBlocker,
112
+ useSmoothScrollTo,
118
113
  } from './utils/scrollUtils';
119
114
 
120
115
  export {
121
116
  useIsomorphicLayoutEffect,
122
117
  useDynamicCallback,
118
+ usePrevious,
119
+ ReactContextError,
123
120
  } from './utils/reactUtils';
124
121
 
125
122
  export {isRegexpStringMatch} from './utils/regexpUtils';
126
123
 
127
- export {useHomePageRoute} from './utils/routesUtils';
124
+ export {useHomePageRoute, isSamePath} from './utils/routesUtils';
125
+
126
+ export {
127
+ PageMetadata,
128
+ HtmlClassNameProvider,
129
+ PluginHtmlClassNameProvider,
130
+ } from './utils/metadataUtils';
131
+
132
+ export {
133
+ useColorMode,
134
+ ColorModeProvider,
135
+ type ColorMode,
136
+ } from './contexts/colorMode';
137
+
138
+ export {splitNavbarItems, NavbarProvider} from './utils/navbarUtils';
128
139
 
129
- export {useColorMode, ColorModeProvider} from './utils/colorModeUtils';
130
140
  export {
131
141
  useTabGroupChoice,
132
142
  TabGroupChoiceProvider,
133
- } from './utils/tabGroupChoiceUtils';
143
+ } from './contexts/tabGroupChoice';
144
+
145
+ export {useNavbarMobileSidebar} from './contexts/navbarMobileSidebar';
146
+ export {
147
+ NavbarSecondaryMenuFiller,
148
+ type NavbarSecondaryMenuComponent,
149
+ } from './contexts/navbarSecondaryMenu/content';
150
+ export {useNavbarSecondaryMenu} from './contexts/navbarSecondaryMenu/display';
134
151
 
135
- export {default as useHideableNavbar} from './hooks/useHideableNavbar';
152
+ export {useBackToTopButton} from './hooks/useBackToTopButton';
153
+ export {useHideableNavbar} from './hooks/useHideableNavbar';
136
154
  export {
137
- default as useKeyboardNavigation,
155
+ useKeyboardNavigation,
138
156
  keyboardFocusedClassName,
139
157
  } 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';
158
+ export {usePrismTheme} from './hooks/usePrismTheme';
159
+ export {useLockBodyScroll} from './hooks/useLockBodyScroll';
160
+ export {useWindowSize} from './hooks/useWindowSize';
161
+ export {useSearchPage} from './hooks/useSearchPage';
162
+ export {useCodeWordWrap} from './hooks/useCodeWordWrap';
163
+ export {useSkipToContent} from './hooks/useSkipToContent';
@@ -5,10 +5,13 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
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
8
  // Please do not modify the classnames! This is a breaking change, and annoying
11
9
  // for users!
10
+
11
+ /**
12
+ * These class names are used to style page layouts in Docusaurus, meant to be
13
+ * targeted by user-provided custom CSS selectors.
14
+ */
12
15
  export const ThemeClassNames = {
13
16
  page: {
14
17
  blogListPage: 'blog-list-page',
@@ -17,8 +20,8 @@ export const ThemeClassNames = {
17
20
  blogTagPostListPage: 'blog-tags-post-list-page',
18
21
 
19
22
  docsDocPage: 'docs-doc-page',
20
- docsTagsListPage: 'docs-tags-list-page', // List of tags
21
- docsTagDocListPage: 'docs-tags-doc-list-page', // Docs for a tag
23
+ docsTagsListPage: 'docs-tags-list-page',
24
+ docsTagDocListPage: 'docs-tags-doc-list-page',
22
25
 
23
26
  mdxPage: 'mdx-page',
24
27
  },
@@ -29,8 +32,9 @@ export const ThemeClassNames = {
29
32
  mdxPages: 'mdx-wrapper',
30
33
  },
31
34
 
32
- // /!\ Please keep the naming convention consistent!
33
- // Something like: "theme-{blog,doc,version,page}?-<suffix>"
35
+ /**
36
+ * Follows the naming convention "theme-{blog,doc,version,page}?-<suffix>"
37
+ */
34
38
  common: {
35
39
  editThisPage: 'theme-edit-this-page',
36
40
  lastUpdated: 'theme-last-updated',