@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.
- package/Details.d.ts +14 -0
- package/lib/components/Collapsible/index.d.ts +32 -4
- package/lib/components/Collapsible/index.d.ts.map +1 -1
- package/lib/components/Collapsible/index.js +18 -10
- package/lib/components/Collapsible/index.js.map +1 -1
- package/lib/components/Details/index.d.ts +6 -1
- package/lib/components/Details/index.d.ts.map +1 -1
- package/lib/components/Details/index.js +11 -6
- package/lib/components/Details/index.js.map +1 -1
- package/lib/components/Details/styles.module.css +4 -0
- package/lib/{utils/announcementBarUtils.d.ts → contexts/announcementBar.d.ts} +7 -3
- package/lib/contexts/announcementBar.d.ts.map +1 -0
- package/lib/{utils/announcementBarUtils.js → contexts/announcementBar.js} +15 -14
- package/lib/contexts/announcementBar.js.map +1 -0
- package/lib/contexts/colorMode.d.ts +27 -0
- package/lib/contexts/colorMode.d.ts.map +1 -0
- package/lib/contexts/colorMode.js +132 -0
- package/lib/contexts/colorMode.js.map +1 -0
- package/lib/contexts/docSidebarItemsExpandedState.d.ts +31 -0
- package/lib/contexts/docSidebarItemsExpandedState.d.ts.map +1 -0
- package/lib/{utils → contexts}/docSidebarItemsExpandedState.js +10 -4
- package/lib/contexts/docSidebarItemsExpandedState.js.map +1 -0
- package/lib/contexts/docsPreferredVersion.d.ts +31 -0
- package/lib/contexts/docsPreferredVersion.d.ts.map +1 -0
- package/lib/contexts/docsPreferredVersion.js +128 -0
- package/lib/contexts/docsPreferredVersion.js.map +1 -0
- package/lib/contexts/docsSidebar.d.ts +26 -0
- package/lib/contexts/docsSidebar.d.ts.map +1 -0
- package/lib/contexts/docsSidebar.js +30 -0
- package/lib/contexts/docsSidebar.js.map +1 -0
- package/lib/contexts/docsVersion.d.ts +20 -0
- package/lib/contexts/docsVersion.d.ts.map +1 -0
- package/lib/contexts/docsVersion.js +26 -0
- package/lib/contexts/docsVersion.js.map +1 -0
- package/lib/contexts/navbarMobileSidebar.d.ts +31 -0
- package/lib/contexts/navbarMobileSidebar.d.ts.map +1 -0
- package/lib/contexts/navbarMobileSidebar.js +56 -0
- package/lib/contexts/navbarMobileSidebar.js.map +1 -0
- package/lib/contexts/navbarSecondaryMenu/content.d.ts +37 -0
- package/lib/contexts/navbarSecondaryMenu/content.d.ts.map +1 -0
- package/lib/contexts/navbarSecondaryMenu/content.js +56 -0
- package/lib/contexts/navbarSecondaryMenu/content.js.map +1 -0
- package/lib/contexts/navbarSecondaryMenu/display.d.ts +24 -0
- package/lib/contexts/navbarSecondaryMenu/display.d.ts.map +1 -0
- package/lib/contexts/navbarSecondaryMenu/display.js +62 -0
- package/lib/contexts/navbarSecondaryMenu/display.js.map +1 -0
- package/lib/{utils/tabGroupChoiceUtils.d.ts → contexts/tabGroupChoice.d.ts} +5 -3
- package/lib/contexts/tabGroupChoice.d.ts.map +1 -0
- package/lib/{utils/tabGroupChoiceUtils.js → contexts/tabGroupChoice.js} +15 -20
- package/lib/contexts/tabGroupChoice.js.map +1 -0
- package/lib/hooks/useBackToTopButton.d.ts +27 -0
- package/lib/hooks/useBackToTopButton.d.ts.map +1 -0
- package/lib/hooks/useBackToTopButton.js +50 -0
- package/lib/hooks/useBackToTopButton.js.map +1 -0
- package/lib/hooks/useCodeWordWrap.d.ts +14 -0
- package/lib/hooks/useCodeWordWrap.d.ts.map +1 -0
- package/lib/hooks/useCodeWordWrap.js +41 -0
- package/lib/hooks/useCodeWordWrap.js.map +1 -0
- package/lib/hooks/useHideableNavbar.d.ts +7 -3
- package/lib/hooks/useHideableNavbar.d.ts.map +1 -1
- package/lib/hooks/useHideableNavbar.js +10 -9
- package/lib/hooks/useHideableNavbar.js.map +1 -1
- package/lib/hooks/useKeyboardNavigation.d.ts +11 -1
- package/lib/hooks/useKeyboardNavigation.d.ts.map +1 -1
- package/lib/hooks/useKeyboardNavigation.js +11 -3
- package/lib/hooks/useKeyboardNavigation.js.map +1 -1
- package/lib/hooks/useLockBodyScroll.d.ts +5 -1
- package/lib/hooks/useLockBodyScroll.d.ts.map +1 -1
- package/lib/hooks/useLockBodyScroll.js +5 -1
- package/lib/hooks/useLockBodyScroll.js.map +1 -1
- package/lib/hooks/usePrismTheme.d.ts +6 -2
- package/lib/hooks/usePrismTheme.d.ts.map +1 -1
- package/lib/hooks/usePrismTheme.js +9 -6
- package/lib/hooks/usePrismTheme.js.map +1 -1
- package/lib/hooks/useSearchPage.d.ts +15 -4
- package/lib/hooks/useSearchPage.d.ts.map +1 -1
- package/lib/hooks/useSearchPage.js +4 -4
- package/lib/hooks/useSearchPage.js.map +1 -1
- package/lib/hooks/useSkipToContent.d.ts +25 -0
- package/lib/hooks/useSkipToContent.d.ts.map +1 -0
- package/lib/hooks/useSkipToContent.js +35 -0
- package/lib/hooks/useSkipToContent.js.map +1 -0
- package/lib/hooks/useTOCHighlight.d.ts +25 -0
- package/lib/hooks/useTOCHighlight.d.ts.map +1 -0
- package/lib/{utils → hooks}/useTOCHighlight.js +18 -16
- package/lib/hooks/useTOCHighlight.js.map +1 -0
- package/lib/hooks/useWindowSize.d.ts +14 -1
- package/lib/hooks/useWindowSize.d.ts.map +1 -1
- package/lib/hooks/useWindowSize.js +14 -11
- package/lib/hooks/useWindowSize.js.map +1 -1
- package/lib/index.d.ts +31 -32
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +31 -26
- package/lib/index.js.map +1 -1
- package/lib/utils/ThemeClassNames.d.ts +7 -0
- package/lib/utils/ThemeClassNames.d.ts.map +1 -1
- package/lib/utils/ThemeClassNames.js +7 -4
- package/lib/utils/ThemeClassNames.js.map +1 -1
- package/lib/utils/codeBlockUtils.d.ts +57 -4
- package/lib/utils/codeBlockUtils.d.ts.map +1 -1
- package/lib/utils/codeBlockUtils.js +111 -80
- package/lib/utils/codeBlockUtils.js.map +1 -1
- package/lib/utils/docsUtils.d.ts +83 -18
- package/lib/utils/docsUtils.d.ts.map +1 -1
- package/lib/utils/docsUtils.js +143 -62
- package/lib/utils/docsUtils.js.map +1 -1
- package/lib/utils/footerUtils.d.ts +13 -0
- package/lib/utils/footerUtils.d.ts.map +1 -0
- package/lib/utils/footerUtils.js +14 -0
- package/lib/utils/footerUtils.js.map +1 -0
- package/lib/utils/generalUtils.d.ts +4 -1
- package/lib/utils/generalUtils.d.ts.map +1 -1
- package/lib/utils/generalUtils.js +6 -3
- package/lib/utils/generalUtils.js.map +1 -1
- package/lib/utils/historyUtils.d.ts +1 -7
- package/lib/utils/historyUtils.d.ts.map +1 -1
- package/lib/utils/historyUtils.js +10 -13
- package/lib/utils/historyUtils.js.map +1 -1
- package/lib/utils/jsUtils.d.ts +1 -1
- package/lib/utils/jsUtils.js +1 -1
- package/lib/utils/metadataUtils.d.ts +38 -0
- package/lib/utils/metadataUtils.d.ts.map +1 -0
- package/lib/utils/metadataUtils.js +61 -0
- package/lib/utils/metadataUtils.js.map +1 -0
- package/lib/utils/navbarUtils.d.ts +21 -0
- package/lib/utils/navbarUtils.d.ts.map +1 -0
- package/lib/utils/navbarUtils.js +32 -0
- package/lib/utils/navbarUtils.js.map +1 -0
- package/lib/utils/reactUtils.d.ts +21 -7
- package/lib/utils/reactUtils.d.ts.map +1 -1
- package/lib/utils/reactUtils.js +34 -6
- package/lib/utils/reactUtils.js.map +1 -1
- package/lib/utils/regexpUtils.d.ts +2 -1
- package/lib/utils/regexpUtils.d.ts.map +1 -1
- package/lib/utils/regexpUtils.js +2 -1
- package/lib/utils/regexpUtils.js.map +1 -1
- package/lib/utils/routesUtils.d.ts +19 -4
- package/lib/utils/routesUtils.d.ts.map +1 -1
- package/lib/utils/routesUtils.js +40 -19
- package/lib/utils/routesUtils.js.map +1 -1
- package/lib/utils/scrollUtils.d.ts +55 -25
- package/lib/utils/scrollUtils.d.ts.map +1 -1
- package/lib/utils/scrollUtils.js +85 -21
- package/lib/utils/scrollUtils.js.map +1 -1
- package/lib/utils/searchUtils.d.ts +12 -0
- package/lib/utils/searchUtils.d.ts.map +1 -1
- package/lib/utils/searchUtils.js +36 -0
- package/lib/utils/searchUtils.js.map +1 -1
- package/lib/utils/storageUtils.d.ts +12 -9
- package/lib/utils/storageUtils.d.ts.map +1 -1
- package/lib/utils/storageUtils.js +21 -13
- package/lib/utils/storageUtils.js.map +1 -1
- package/lib/utils/tagsUtils.d.ts +7 -8
- package/lib/utils/tagsUtils.d.ts.map +1 -1
- package/lib/utils/tagsUtils.js +8 -6
- package/lib/utils/tagsUtils.js.map +1 -1
- package/lib/utils/tocUtils.d.ts +17 -1
- package/lib/utils/tocUtils.d.ts.map +1 -1
- package/lib/utils/tocUtils.js +20 -9
- package/lib/utils/tocUtils.js.map +1 -1
- package/lib/utils/useAlternatePageUtils.d.ts +20 -1
- package/lib/utils/useAlternatePageUtils.d.ts.map +1 -1
- package/lib/utils/useAlternatePageUtils.js +6 -3
- package/lib/utils/useAlternatePageUtils.js.map +1 -1
- package/lib/utils/useLocalPathname.d.ts +5 -0
- package/lib/utils/useLocalPathname.d.ts.map +1 -1
- package/lib/utils/useLocalPathname.js +6 -4
- package/lib/utils/useLocalPathname.js.map +1 -1
- package/lib/utils/useLocationChange.d.ts +7 -5
- package/lib/utils/useLocationChange.d.ts.map +1 -1
- package/lib/utils/useLocationChange.js +6 -2
- package/lib/utils/useLocationChange.js.map +1 -1
- package/lib/utils/usePluralForm.d.ts +11 -0
- package/lib/utils/usePluralForm.d.ts.map +1 -1
- package/lib/utils/usePluralForm.js +19 -24
- package/lib/utils/usePluralForm.js.map +1 -1
- package/lib/utils/useThemeConfig.d.ts +28 -22
- package/lib/utils/useThemeConfig.d.ts.map +1 -1
- package/lib/utils/useThemeConfig.js +3 -0
- package/lib/utils/useThemeConfig.js.map +1 -1
- package/package.json +18 -11
- package/src/components/Collapsible/index.tsx +42 -24
- package/src/components/Details/index.tsx +15 -8
- package/src/components/Details/styles.module.css +4 -0
- package/src/{utils/announcementBarUtils.tsx → contexts/announcementBar.tsx} +20 -22
- package/src/contexts/colorMode.tsx +199 -0
- package/src/contexts/docSidebarItemsExpandedState.tsx +55 -0
- package/src/contexts/docsPreferredVersion.tsx +253 -0
- package/src/contexts/docsSidebar.tsx +50 -0
- package/src/contexts/docsVersion.tsx +36 -0
- package/src/contexts/navbarMobileSidebar.tsx +99 -0
- package/src/contexts/navbarSecondaryMenu/content.tsx +110 -0
- package/src/contexts/navbarSecondaryMenu/display.tsx +102 -0
- package/src/{utils/tabGroupChoiceUtils.tsx → contexts/tabGroupChoice.tsx} +28 -33
- package/src/hooks/useBackToTopButton.ts +73 -0
- package/src/hooks/useCodeWordWrap.ts +56 -0
- package/src/hooks/useHideableNavbar.ts +12 -14
- package/src/hooks/useKeyboardNavigation.ts +11 -3
- package/src/hooks/useLockBodyScroll.ts +5 -2
- package/src/hooks/usePrismTheme.ts +10 -6
- package/src/hooks/useSearchPage.ts +18 -5
- package/src/hooks/useSkipToContent.ts +58 -0
- package/src/{utils → hooks}/useTOCHighlight.ts +24 -15
- package/src/hooks/useWindowSize.ts +14 -12
- package/src/index.ts +77 -57
- package/src/utils/ThemeClassNames.ts +10 -6
- package/src/utils/codeBlockUtils.ts +178 -92
- package/src/utils/docsUtils.tsx +205 -101
- package/src/utils/footerUtils.ts +18 -0
- package/src/utils/generalUtils.ts +6 -3
- package/src/utils/historyUtils.ts +11 -17
- package/src/utils/jsUtils.ts +1 -1
- package/src/utils/metadataUtils.tsx +115 -0
- package/src/utils/navbarUtils.tsx +45 -0
- package/src/utils/reactUtils.tsx +40 -7
- package/src/utils/regexpUtils.ts +2 -1
- package/src/utils/routesUtils.ts +58 -22
- package/src/utils/scrollUtils.tsx +120 -49
- package/src/utils/searchUtils.ts +51 -0
- package/src/utils/storageUtils.ts +23 -15
- package/src/utils/tagsUtils.ts +12 -10
- package/src/utils/tocUtils.ts +22 -11
- package/src/utils/useAlternatePageUtils.ts +17 -5
- package/src/utils/useLocalPathname.ts +6 -4
- package/src/utils/useLocationChange.ts +12 -10
- package/src/utils/usePluralForm.ts +27 -24
- package/src/utils/useThemeConfig.ts +23 -22
- package/yarn-error.log +20199 -0
- package/lib/utils/announcementBarUtils.d.ts.map +0 -1
- package/lib/utils/announcementBarUtils.js.map +0 -1
- package/lib/utils/colorModeUtils.d.ts +0 -18
- package/lib/utils/colorModeUtils.d.ts.map +0 -1
- package/lib/utils/colorModeUtils.js +0 -106
- package/lib/utils/colorModeUtils.js.map +0 -1
- package/lib/utils/docSidebarItemsExpandedState.d.ts +0 -17
- package/lib/utils/docSidebarItemsExpandedState.d.ts.map +0 -1
- package/lib/utils/docSidebarItemsExpandedState.js.map +0 -1
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.d.ts +0 -22
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.d.ts.map +0 -1
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js +0 -91
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js.map +0 -1
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.d.ts +0 -14
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.d.ts.map +0 -1
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.js +0 -19
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.js.map +0 -1
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.d.ts +0 -14
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.d.ts.map +0 -1
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.js +0 -41
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.js.map +0 -1
- package/lib/utils/mobileSecondaryMenu.d.ts +0 -21
- package/lib/utils/mobileSecondaryMenu.d.ts.map +0 -1
- package/lib/utils/mobileSecondaryMenu.js +0 -50
- package/lib/utils/mobileSecondaryMenu.js.map +0 -1
- package/lib/utils/pathUtils.d.ts +0 -8
- package/lib/utils/pathUtils.d.ts.map +0 -1
- package/lib/utils/pathUtils.js +0 -17
- package/lib/utils/pathUtils.js.map +0 -1
- package/lib/utils/tabGroupChoiceUtils.d.ts.map +0 -1
- package/lib/utils/tabGroupChoiceUtils.js.map +0 -1
- package/lib/utils/useContextualSearchFilters.d.ts +0 -12
- package/lib/utils/useContextualSearchFilters.d.ts.map +0 -1
- package/lib/utils/useContextualSearchFilters.js +0 -37
- package/lib/utils/useContextualSearchFilters.js.map +0 -1
- package/lib/utils/usePrevious.d.ts +0 -8
- package/lib/utils/usePrevious.d.ts.map +0 -1
- package/lib/utils/usePrevious.js +0 -16
- package/lib/utils/usePrevious.js.map +0 -1
- package/lib/utils/useTOCHighlight.d.ts +0 -14
- package/lib/utils/useTOCHighlight.d.ts.map +0 -1
- package/lib/utils/useTOCHighlight.js.map +0 -1
- package/src/utils/colorModeUtils.tsx +0 -156
- package/src/utils/docSidebarItemsExpandedState.tsx +0 -41
- package/src/utils/docsPreferredVersion/DocsPreferredVersionProvider.tsx +0 -167
- package/src/utils/docsPreferredVersion/DocsPreferredVersionStorage.ts +0 -33
- package/src/utils/docsPreferredVersion/useDocsPreferredVersion.ts +0 -70
- package/src/utils/mobileSecondaryMenu.tsx +0 -115
- package/src/utils/pathUtils.ts +0 -19
- package/src/utils/useContextualSearchFilters.ts +0 -53
- package/src/utils/usePrevious.ts +0 -19
|
@@ -0,0 +1,32 @@
|
|
|
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 from 'react';
|
|
8
|
+
import { NavbarMobileSidebarProvider } from '../contexts/navbarMobileSidebar';
|
|
9
|
+
import { NavbarSecondaryMenuContentProvider } from '../contexts/navbarSecondaryMenu/content';
|
|
10
|
+
import { NavbarSecondaryMenuDisplayProvider } from '../contexts/navbarSecondaryMenu/display';
|
|
11
|
+
const DefaultNavItemPosition = 'right';
|
|
12
|
+
/**
|
|
13
|
+
* Split links by left/right. If position is unspecified, fallback to right.
|
|
14
|
+
*/
|
|
15
|
+
export function splitNavbarItems(items) {
|
|
16
|
+
function isLeft(item) {
|
|
17
|
+
return (item.position ?? DefaultNavItemPosition) === 'left';
|
|
18
|
+
}
|
|
19
|
+
const leftItems = items.filter(isLeft);
|
|
20
|
+
const rightItems = items.filter((item) => !isLeft(item));
|
|
21
|
+
return [leftItems, rightItems];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Composes multiple navbar state providers that are mutually dependent and
|
|
25
|
+
* hence can't be re-ordered.
|
|
26
|
+
*/
|
|
27
|
+
export function NavbarProvider({ children }) {
|
|
28
|
+
return (React.createElement(NavbarSecondaryMenuContentProvider, null,
|
|
29
|
+
React.createElement(NavbarMobileSidebarProvider, null,
|
|
30
|
+
React.createElement(NavbarSecondaryMenuDisplayProvider, null, children))));
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=navbarUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navbarUtils.js","sourceRoot":"","sources":["../../src/utils/navbarUtils.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAuB,MAAM,OAAO,CAAC;AAC5C,OAAO,EAAC,2BAA2B,EAAC,MAAM,iCAAiC,CAAC;AAC5E,OAAO,EAAC,kCAAkC,EAAC,MAAM,yCAAyC,CAAC;AAC3F,OAAO,EAAC,kCAAkC,EAAC,MAAM,yCAAyC,CAAC;AAE3F,MAAM,sBAAsB,GAAG,OAAO,CAAC;AAEvC;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAC9B,KAAU;IAEV,SAAS,MAAM,CAAC,IAAO;QACrB,OAAO,CAAC,IAAI,CAAC,QAAQ,IAAI,sBAAsB,CAAC,KAAK,MAAM,CAAC;IAC9D,CAAC;IAED,MAAM,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IACvC,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;IAEzD,OAAO,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;AACjC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAAC,EAAC,QAAQ,EAAwB;IAC9D,OAAO,CACL,oBAAC,kCAAkC;QACjC,oBAAC,2BAA2B;YAC1B,oBAAC,kCAAkC,QAChC,QAAQ,CAC0B,CACT,CACK,CACtC,CAAC;AACJ,CAAC"}
|
|
@@ -4,25 +4,39 @@
|
|
|
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 {
|
|
7
|
+
import { useLayoutEffect } from 'react';
|
|
8
8
|
/**
|
|
9
|
-
* This hook is like useLayoutEffect
|
|
10
|
-
* It seems hacky but it's used in many React libs (Redux, Formik...)
|
|
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
11
|
* Also mentioned here: https://github.com/facebook/react/issues/16956
|
|
12
|
+
*
|
|
12
13
|
* It is useful when you need to update a ref as soon as possible after a React
|
|
13
|
-
* render (before `useEffect`)
|
|
14
|
+
* render (before `useEffect`).
|
|
14
15
|
*/
|
|
15
|
-
export declare const useIsomorphicLayoutEffect: typeof
|
|
16
|
+
export declare const useIsomorphicLayoutEffect: typeof useLayoutEffect;
|
|
16
17
|
/**
|
|
17
18
|
* Permits to transform an unstable callback (like an arrow function provided as
|
|
18
|
-
* props) to a "stable" callback that is safe to use in a useEffect dependency
|
|
19
|
+
* props) to a "stable" callback that is safe to use in a `useEffect` dependency
|
|
19
20
|
* array. Useful to avoid React stale closure problems + avoid useless effect
|
|
20
|
-
* re-executions
|
|
21
|
+
* re-executions.
|
|
21
22
|
*
|
|
22
23
|
* Workaround until the React team recommends a good solution, see
|
|
23
24
|
* https://github.com/facebook/react/issues/16956
|
|
25
|
+
*
|
|
24
26
|
* This generally works but has some potential drawbacks, such as
|
|
25
27
|
* https://github.com/facebook/react/issues/16956#issuecomment-536636418
|
|
26
28
|
*/
|
|
27
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
|
+
}
|
|
28
42
|
//# sourceMappingURL=reactUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reactUtils.d.ts","sourceRoot":"","sources":["../../src/utils/reactUtils.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,
|
|
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"}
|
package/lib/utils/reactUtils.js
CHANGED
|
@@ -5,22 +5,27 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import { useCallback, useEffect, useLayoutEffect, useRef } from 'react';
|
|
8
|
+
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
|
8
9
|
/**
|
|
9
|
-
* This hook is like useLayoutEffect
|
|
10
|
-
* It seems hacky but it's used in many React libs (Redux, Formik...)
|
|
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...).
|
|
11
12
|
* Also mentioned here: https://github.com/facebook/react/issues/16956
|
|
13
|
+
*
|
|
12
14
|
* It is useful when you need to update a ref as soon as possible after a React
|
|
13
|
-
* render (before `useEffect`)
|
|
15
|
+
* render (before `useEffect`).
|
|
14
16
|
*/
|
|
15
|
-
export const useIsomorphicLayoutEffect =
|
|
17
|
+
export const useIsomorphicLayoutEffect = ExecutionEnvironment.canUseDOM
|
|
18
|
+
? useLayoutEffect
|
|
19
|
+
: useEffect;
|
|
16
20
|
/**
|
|
17
21
|
* Permits to transform an unstable callback (like an arrow function provided as
|
|
18
|
-
* props) to a "stable" callback that is safe to use in a useEffect dependency
|
|
22
|
+
* props) to a "stable" callback that is safe to use in a `useEffect` dependency
|
|
19
23
|
* array. Useful to avoid React stale closure problems + avoid useless effect
|
|
20
|
-
* re-executions
|
|
24
|
+
* re-executions.
|
|
21
25
|
*
|
|
22
26
|
* Workaround until the React team recommends a good solution, see
|
|
23
27
|
* https://github.com/facebook/react/issues/16956
|
|
28
|
+
*
|
|
24
29
|
* This generally works but has some potential drawbacks, such as
|
|
25
30
|
* https://github.com/facebook/react/issues/16956#issuecomment-536636418
|
|
26
31
|
*/
|
|
@@ -33,4 +38,27 @@ export function useDynamicCallback(callback) {
|
|
|
33
38
|
// but good enough for our use
|
|
34
39
|
return useCallback((...args) => ref.current(...args), []);
|
|
35
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
|
+
}
|
|
36
64
|
//# sourceMappingURL=reactUtils.js.map
|
|
@@ -1 +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;
|
|
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,IACL,2BAA2B,YAAY,MAAM,cAAc,IAAI,EAAE,EAAE,CAAC;IACtE,CAAC;CACF"}
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Matches a string regex (as provided from the config) against a target in a
|
|
9
|
+
* null-safe fashion, case insensitive and global.
|
|
9
10
|
*/
|
|
10
11
|
export declare function isRegexpStringMatch(regexAsString?: string, valueToTest?: string): boolean;
|
|
11
12
|
//# sourceMappingURL=regexpUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"regexpUtils.d.ts","sourceRoot":"","sources":["../../src/utils/regexpUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH
|
|
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"}
|
package/lib/utils/regexpUtils.js
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Matches a string regex (as provided from the config) against a target in a
|
|
9
|
+
* null-safe fashion, case insensitive and global.
|
|
9
10
|
*/
|
|
10
11
|
export function isRegexpStringMatch(regexAsString, valueToTest) {
|
|
11
12
|
if (typeof regexAsString === 'undefined' ||
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"regexpUtils.js","sourceRoot":"","sources":["../../src/utils/regexpUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH
|
|
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"}
|
|
@@ -4,8 +4,23 @@
|
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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;
|
|
11
26
|
//# sourceMappingURL=routesUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routesUtils.d.ts","sourceRoot":"","sources":["../../src/utils/routesUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG
|
|
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"}
|
package/lib/utils/routesUtils.js
CHANGED
|
@@ -4,30 +4,51 @@
|
|
|
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 GeneratedRoutes from '@generated/routes';
|
|
8
7
|
import { useMemo } from 'react';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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);
|
|
14
18
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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;
|
|
20
30
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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);
|
|
24
43
|
}
|
|
25
|
-
|
|
26
|
-
.filter(isHomeParentRoute)
|
|
27
|
-
.flatMap((route) => { var _a; return (_a = route.routes) !== null && _a !== void 0 ? _a : []; });
|
|
28
|
-
return findHomePageRoute(indexSubRoutes);
|
|
44
|
+
return doFindHomePageRoute(initialRoutes);
|
|
29
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Fetches the route that points to "/". Use this instead of the naive "/",
|
|
48
|
+
* because the homepage may not exist.
|
|
49
|
+
*/
|
|
30
50
|
export function useHomePageRoute() {
|
|
31
|
-
|
|
51
|
+
const { baseUrl } = useDocusaurusContext().siteConfig;
|
|
52
|
+
return useMemo(() => findHomePageRoute({ routes: generatedRoutes, baseUrl }), [baseUrl]);
|
|
32
53
|
}
|
|
33
54
|
//# sourceMappingURL=routesUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routesUtils.js","sourceRoot":"","sources":["../../src/utils/routesUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"routesUtils.js","sourceRoot":"","sources":["../../src/utils/routesUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,OAAO,EAAC,MAAM,O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AC;IAED,OAAO,mBAAmB,CAAC,aAAa,CAAC,CAAC;AAC5C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB;IAC9B,MAAM,EAAC,OAAO,EAAC,GAAG,oBAAoB,EAAE,CAAC,UAAU,CAAC;IACpD,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,iBAAiB,CAAC,EAAC,MAAM,EAAE,eAAe,EAAE,OAAO,EAAC,CAAC,EAC3D,CAAC,OAAO,CAAC,CACV,CAAC;AACJ,CAAC"}
|
|
@@ -5,49 +5,79 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import React, { type ReactNode } from 'react';
|
|
8
|
-
/**
|
|
9
|
-
* We need a way to update the scroll position while ignoring scroll events
|
|
10
|
-
* without affecting Navbar/BackToTop visibility
|
|
11
|
-
*
|
|
12
|
-
* This API permits to temporarily disable/ignore scroll events
|
|
13
|
-
* Motivated by https://github.com/facebook/docusaurus/pull/5618
|
|
14
|
-
*/
|
|
15
8
|
declare type ScrollController = {
|
|
16
|
-
/**
|
|
17
|
-
* A boolean ref tracking whether scroll events are enabled
|
|
18
|
-
*/
|
|
9
|
+
/** A boolean ref tracking whether scroll events are enabled. */
|
|
19
10
|
scrollEventsEnabledRef: React.MutableRefObject<boolean>;
|
|
20
|
-
/**
|
|
21
|
-
* Enables scroll events in `useScrollPosition`
|
|
22
|
-
*/
|
|
11
|
+
/** Enable scroll events in `useScrollPosition`. */
|
|
23
12
|
enableScrollEvents: () => void;
|
|
24
|
-
/**
|
|
25
|
-
* Disables scroll events in `useScrollPosition`
|
|
26
|
-
*/
|
|
13
|
+
/** Disable scroll events in `useScrollPosition`. */
|
|
27
14
|
disableScrollEvents: () => void;
|
|
28
15
|
};
|
|
29
16
|
export declare function ScrollControllerProvider({ children, }: {
|
|
30
17
|
children: ReactNode;
|
|
31
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
|
+
*/
|
|
32
26
|
export declare function useScrollController(): ScrollController;
|
|
33
27
|
declare type ScrollPosition = {
|
|
34
28
|
scrollX: number;
|
|
35
29
|
scrollY: number;
|
|
36
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
|
+
*/
|
|
37
39
|
export declare function useScrollPosition(effect: (position: ScrollPosition, lastPosition: ScrollPosition | null) => void, deps?: unknown[]): void;
|
|
38
|
-
|
|
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
|
+
*/
|
|
39
56
|
blockElementScrollPositionUntilNextRender: (el: HTMLElement) => void;
|
|
40
57
|
};
|
|
58
|
+
declare type CancelScrollTop = () => void;
|
|
41
59
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
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.
|
|
45
64
|
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* Yet to avoid a bad UX, the clicked tab must remain under the user mouse!
|
|
49
|
-
* See GIF here: https://github.com/facebook/docusaurus/pull/5618
|
|
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.
|
|
50
67
|
*/
|
|
51
|
-
export declare function
|
|
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
|
+
};
|
|
52
82
|
export {};
|
|
53
83
|
//# sourceMappingURL=scrollUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scrollUtils.d.ts","sourceRoot":"","sources":["../../src/utils/scrollUtils.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,
|
|
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,CA8BN;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"}
|
package/lib/utils/scrollUtils.js
CHANGED
|
@@ -4,9 +4,10 @@
|
|
|
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 React, {
|
|
8
|
-
import { useDynamicCallback } from './reactUtils';
|
|
7
|
+
import React, { useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, } from 'react';
|
|
8
|
+
import { useDynamicCallback, ReactContextError } from './reactUtils';
|
|
9
9
|
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
|
10
|
+
import useIsBrowser from '@docusaurus/useIsBrowser';
|
|
10
11
|
function useScrollControllerContextValue() {
|
|
11
12
|
const scrollEventsEnabledRef = useRef(true);
|
|
12
13
|
return useMemo(() => ({
|
|
@@ -19,14 +20,22 @@ function useScrollControllerContextValue() {
|
|
|
19
20
|
},
|
|
20
21
|
}), []);
|
|
21
22
|
}
|
|
22
|
-
const ScrollMonitorContext = createContext(undefined);
|
|
23
|
+
const ScrollMonitorContext = React.createContext(undefined);
|
|
23
24
|
export function ScrollControllerProvider({ children, }) {
|
|
24
|
-
|
|
25
|
+
const value = useScrollControllerContextValue();
|
|
26
|
+
return (React.createElement(ScrollMonitorContext.Provider, { value: value }, children));
|
|
25
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* We need a way to update the scroll position while ignoring scroll events
|
|
30
|
+
* so as not to toggle Navbar/BackToTop visibility.
|
|
31
|
+
*
|
|
32
|
+
* This API permits to temporarily disable/ignore scroll events. Motivated by
|
|
33
|
+
* https://github.com/facebook/docusaurus/pull/5618
|
|
34
|
+
*/
|
|
26
35
|
export function useScrollController() {
|
|
27
36
|
const context = useContext(ScrollMonitorContext);
|
|
28
37
|
if (context == null) {
|
|
29
|
-
throw new
|
|
38
|
+
throw new ReactContextError('ScrollControllerProvider');
|
|
30
39
|
}
|
|
31
40
|
return context;
|
|
32
41
|
}
|
|
@@ -36,6 +45,14 @@ const getScrollPosition = () => ExecutionEnvironment.canUseDOM
|
|
|
36
45
|
scrollY: window.pageYOffset,
|
|
37
46
|
}
|
|
38
47
|
: null;
|
|
48
|
+
/**
|
|
49
|
+
* This hook fires an effect when the scroll position changes. The effect will
|
|
50
|
+
* be provided with the before/after scroll positions. Note that the effect may
|
|
51
|
+
* not be always run: if scrolling is disabled through `useScrollController`, it
|
|
52
|
+
* will be a no-op.
|
|
53
|
+
*
|
|
54
|
+
* @see {@link useScrollController}
|
|
55
|
+
*/
|
|
39
56
|
export function useScrollPosition(effect, deps = []) {
|
|
40
57
|
const { scrollEventsEnabledRef } = useScrollController();
|
|
41
58
|
const lastPositionRef = useRef(getScrollPosition());
|
|
@@ -57,12 +74,8 @@ export function useScrollPosition(effect, deps = []) {
|
|
|
57
74
|
handleScroll();
|
|
58
75
|
window.addEventListener('scroll', handleScroll, opts);
|
|
59
76
|
return () => window.removeEventListener('scroll', handleScroll, opts);
|
|
60
|
-
}, [
|
|
61
|
-
dynamicEffect,
|
|
62
|
-
scrollEventsEnabledRef,
|
|
63
77
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
64
|
-
|
|
65
|
-
]);
|
|
78
|
+
}, [dynamicEffect, scrollEventsEnabledRef, ...deps]);
|
|
66
79
|
}
|
|
67
80
|
function useScrollPositionSaver() {
|
|
68
81
|
const lastElementRef = useRef({
|
|
@@ -91,14 +104,15 @@ function useScrollPositionSaver() {
|
|
|
91
104
|
return useMemo(() => ({ save, restore }), [restore, save]);
|
|
92
105
|
}
|
|
93
106
|
/**
|
|
94
|
-
* This hook permits to "block" the scroll position of a
|
|
107
|
+
* This hook permits to "block" the scroll position of a DOM element.
|
|
95
108
|
* The idea is that we should be able to update DOM content above this element
|
|
96
|
-
* but the screen position of this element should not change
|
|
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.
|
|
97
114
|
*
|
|
98
|
-
*
|
|
99
|
-
* clicking on a tab may affect tabs of the same group upper in the tree
|
|
100
|
-
* Yet to avoid a bad UX, the clicked tab must remain under the user mouse!
|
|
101
|
-
* See GIF here: https://github.com/facebook/docusaurus/pull/5618
|
|
115
|
+
* @see https://github.com/facebook/docusaurus/pull/5618
|
|
102
116
|
*/
|
|
103
117
|
export function useScrollPositionBlocker() {
|
|
104
118
|
const scrollController = useScrollController();
|
|
@@ -110,9 +124,9 @@ export function useScrollPositionBlocker() {
|
|
|
110
124
|
nextLayoutEffectCallbackRef.current = () => {
|
|
111
125
|
const { restored } = scrollPositionSaver.restore();
|
|
112
126
|
nextLayoutEffectCallbackRef.current = undefined;
|
|
113
|
-
// Restoring the former scroll position will trigger a scroll event
|
|
114
|
-
//
|
|
115
|
-
//
|
|
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.
|
|
116
130
|
if (restored) {
|
|
117
131
|
const handleScrollRestoreEvent = () => {
|
|
118
132
|
scrollController.enableScrollEvents();
|
|
@@ -126,11 +140,61 @@ export function useScrollPositionBlocker() {
|
|
|
126
140
|
};
|
|
127
141
|
}, [scrollController, scrollPositionSaver]);
|
|
128
142
|
useLayoutEffect(() => {
|
|
129
|
-
|
|
130
|
-
(_a = nextLayoutEffectCallbackRef.current) === null || _a === void 0 ? void 0 : _a.call(nextLayoutEffectCallbackRef);
|
|
143
|
+
nextLayoutEffectCallbackRef.current?.();
|
|
131
144
|
});
|
|
132
145
|
return {
|
|
133
146
|
blockElementScrollPositionUntilNextRender,
|
|
134
147
|
};
|
|
135
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
|
+
}
|
|
136
200
|
//# sourceMappingURL=scrollUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scrollUtils.js","sourceRoot":"","sources":["../../src/utils/scrollUtils.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,EACZ,
|
|
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,EAAC,kBAAkB,EAAE,iBAAiB,EAAC,MAAM,cAAc,CAAC;AACnE,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;AACpE,OAAO,YAAY,MAAM,0BAA0B,CAAC;AAWpD,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,oBAAC,oBAAoB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,IACxC,QAAQ,CACqB,CACjC,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,mBAAmB;IACjC,MAAM,OAAO,GAAG,UAAU,CAAC,oBAAoB,CAAC,CAAC;IACjD,IAAI,OAAO,IAAI,IAAI,EAAE;QACnB,M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,OAAO,EAAE,EAAE;KAC1C,CAAC;AACJ,CAAC"}
|
|
@@ -5,5 +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
|
+
};
|
|
9
21
|
//# sourceMappingURL=searchUtils.d.ts.map
|