@docusaurus/theme-common 2.0.0-beta.15d451942 → 2.0.0-beta.18
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/lib/components/Collapsible/index.d.ts +64 -0
- package/lib/components/Collapsible/index.d.ts.map +1 -0
- package/lib/components/Collapsible/index.js +152 -0
- package/lib/components/Collapsible/index.js.map +1 -0
- package/lib/components/Details/index.d.ts +17 -0
- package/lib/components/Details/index.d.ts.map +1 -0
- package/lib/components/Details/index.js +70 -0
- package/lib/components/Details/index.js.map +1 -0
- package/lib/components/Details/styles.module.css +58 -0
- package/lib/contexts/announcementBar.d.ts +22 -0
- package/lib/contexts/announcementBar.d.ts.map +1 -0
- package/lib/contexts/announcementBar.js +72 -0
- 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 +114 -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/contexts/docSidebarItemsExpandedState.js +28 -0
- package/lib/contexts/docSidebarItemsExpandedState.js.map +1 -0
- package/lib/contexts/docsPreferredVersion.d.ts +28 -0
- package/lib/contexts/docsPreferredVersion.d.ts.map +1 -0
- package/lib/contexts/docsPreferredVersion.js +125 -0
- package/lib/contexts/docsPreferredVersion.js.map +1 -0
- package/lib/contexts/docsSidebar.d.ts +20 -0
- package/lib/contexts/docsSidebar.d.ts.map +1 -0
- package/lib/contexts/docsSidebar.js +29 -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.d.ts +38 -0
- package/lib/contexts/navbarSecondaryMenu.d.ts.map +1 -0
- package/lib/contexts/navbarSecondaryMenu.js +93 -0
- package/lib/contexts/navbarSecondaryMenu.js.map +1 -0
- package/lib/contexts/tabGroupChoice.d.ts +21 -0
- package/lib/contexts/tabGroupChoice.d.ts.map +1 -0
- package/lib/contexts/tabGroupChoice.js +49 -0
- package/lib/contexts/tabGroupChoice.js.map +1 -0
- package/lib/{utils/useChangeRoute.d.ts → hooks/styles.css} +4 -1
- package/lib/hooks/useHideableNavbar.d.ts +17 -0
- package/lib/hooks/useHideableNavbar.d.ts.map +1 -0
- package/lib/hooks/useHideableNavbar.js +61 -0
- package/lib/hooks/useHideableNavbar.js.map +1 -0
- package/lib/hooks/useKeyboardNavigation.d.ts +20 -0
- package/lib/hooks/useKeyboardNavigation.d.ts.map +1 -0
- package/lib/hooks/useKeyboardNavigation.js +39 -0
- package/lib/hooks/useKeyboardNavigation.js.map +1 -0
- package/lib/hooks/useLockBodyScroll.d.ts +12 -0
- package/lib/hooks/useLockBodyScroll.d.ts.map +1 -0
- package/lib/hooks/useLockBodyScroll.js +20 -0
- package/lib/hooks/useLockBodyScroll.js.map +1 -0
- package/lib/hooks/usePrismTheme.d.ts +13 -0
- package/lib/hooks/usePrismTheme.d.ts.map +1 -0
- package/lib/hooks/usePrismTheme.js +22 -0
- package/lib/hooks/usePrismTheme.js.map +1 -0
- package/lib/hooks/useSearchPage.d.ts +25 -0
- package/lib/hooks/useSearchPage.d.ts.map +1 -0
- package/lib/hooks/useSearchPage.js +43 -0
- package/lib/hooks/useSearchPage.js.map +1 -0
- package/lib/hooks/useTOCHighlight.d.ts +25 -0
- package/lib/hooks/useTOCHighlight.d.ts.map +1 -0
- package/lib/hooks/useTOCHighlight.js +130 -0
- package/lib/hooks/useTOCHighlight.js.map +1 -0
- package/lib/hooks/useWindowSize.d.ts +28 -0
- package/lib/hooks/useWindowSize.d.ts.map +1 -0
- package/lib/hooks/useWindowSize.js +59 -0
- package/lib/hooks/useWindowSize.js.map +1 -0
- package/lib/index.d.ts +36 -9
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +36 -8
- package/lib/index.js.map +1 -0
- package/lib/utils/ThemeClassNames.d.ts +47 -12
- package/lib/utils/ThemeClassNames.d.ts.map +1 -0
- package/lib/utils/ThemeClassNames.js +45 -4
- package/lib/utils/ThemeClassNames.js.map +1 -0
- package/lib/utils/codeBlockUtils.d.ts +33 -0
- package/lib/utils/codeBlockUtils.d.ts.map +1 -0
- package/lib/utils/codeBlockUtils.js +126 -3
- package/lib/utils/codeBlockUtils.js.map +1 -0
- package/lib/utils/docsUtils.d.ts +33 -0
- package/lib/utils/docsUtils.d.ts.map +1 -0
- package/lib/utils/docsUtils.js +118 -1
- package/lib/utils/docsUtils.js.map +1 -0
- 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 +11 -1
- package/lib/utils/generalUtils.d.ts.map +1 -0
- package/lib/utils/generalUtils.js +9 -5
- package/lib/utils/generalUtils.js.map +1 -0
- package/lib/utils/historyUtils.d.ts +17 -0
- package/lib/utils/historyUtils.d.ts.map +1 -0
- package/lib/utils/historyUtils.js +38 -0
- package/lib/utils/historyUtils.js.map +1 -0
- package/lib/utils/jsUtils.d.ts +23 -0
- package/lib/utils/jsUtils.d.ts.map +1 -0
- package/lib/utils/jsUtils.js +29 -0
- package/lib/utils/jsUtils.js.map +1 -0
- 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 +30 -0
- package/lib/utils/navbarUtils.js.map +1 -0
- package/lib/utils/reactUtils.d.ts +42 -0
- package/lib/utils/reactUtils.d.ts.map +1 -0
- package/lib/utils/reactUtils.js +64 -0
- package/lib/utils/reactUtils.js.map +1 -0
- package/lib/utils/regexpUtils.d.ts +12 -0
- package/lib/utils/regexpUtils.d.ts.map +1 -0
- package/lib/utils/regexpUtils.js +18 -0
- package/lib/utils/regexpUtils.js.map +1 -0
- package/lib/utils/routesUtils.d.ts +26 -0
- package/lib/utils/routesUtils.d.ts.map +1 -0
- package/lib/utils/routesUtils.js +54 -0
- package/lib/utils/routesUtils.js.map +1 -0
- package/lib/utils/scrollUtils.d.ts +59 -0
- package/lib/utils/scrollUtils.d.ts.map +1 -0
- package/lib/utils/scrollUtils.js +148 -0
- package/lib/utils/scrollUtils.js.map +1 -0
- package/lib/utils/searchUtils.d.ts +13 -0
- package/lib/utils/searchUtils.d.ts.map +1 -0
- package/lib/utils/searchUtils.js +35 -0
- package/lib/utils/searchUtils.js.map +1 -0
- package/lib/utils/storageUtils.d.ts +13 -5
- package/lib/utils/storageUtils.d.ts.map +1 -0
- package/lib/utils/storageUtils.js +58 -25
- package/lib/utils/storageUtils.js.map +1 -0
- package/lib/utils/tagsUtils.d.ts +22 -0
- package/lib/utils/tagsUtils.d.ts.map +1 -0
- package/lib/utils/tagsUtils.js +36 -0
- package/lib/utils/tagsUtils.js.map +1 -0
- package/lib/utils/tocUtils.d.ts +36 -0
- package/lib/utils/tocUtils.d.ts.map +1 -0
- package/lib/utils/tocUtils.js +84 -0
- package/lib/utils/tocUtils.js.map +1 -0
- package/lib/utils/useAlternatePageUtils.d.ts +21 -1
- package/lib/utils/useAlternatePageUtils.d.ts.map +1 -0
- package/lib/utils/useAlternatePageUtils.js +9 -4
- package/lib/utils/useAlternatePageUtils.js.map +1 -0
- package/lib/utils/useLocalPathname.d.ts +13 -0
- package/lib/utils/useLocalPathname.d.ts.map +1 -0
- package/lib/utils/useLocalPathname.js +19 -0
- package/lib/utils/useLocalPathname.js.map +1 -0
- package/lib/utils/useLocationChange.d.ts +17 -0
- package/lib/utils/useLocationChange.d.ts.map +1 -0
- package/lib/utils/useLocationChange.js +31 -0
- package/lib/utils/useLocationChange.js.map +1 -0
- package/lib/utils/usePluralForm.d.ts +12 -0
- package/lib/utils/usePluralForm.d.ts.map +1 -0
- package/lib/utils/usePluralForm.js +36 -37
- package/lib/utils/usePluralForm.js.map +1 -0
- package/lib/utils/useThemeConfig.d.ts +50 -22
- package/lib/utils/useThemeConfig.d.ts.map +1 -0
- package/lib/utils/useThemeConfig.js +4 -0
- package/lib/utils/useThemeConfig.js.map +1 -0
- package/package.json +18 -13
- package/src/components/Collapsible/index.tsx +265 -0
- package/src/components/Details/index.tsx +107 -0
- package/src/components/Details/styles.module.css +58 -0
- package/src/contexts/announcementBar.tsx +119 -0
- package/src/contexts/colorMode.tsx +176 -0
- package/src/contexts/docSidebarItemsExpandedState.tsx +55 -0
- package/src/contexts/docsPreferredVersion.tsx +250 -0
- package/src/contexts/docsSidebar.tsx +42 -0
- package/src/contexts/docsVersion.tsx +36 -0
- package/src/contexts/navbarMobileSidebar.tsx +99 -0
- package/src/contexts/navbarSecondaryMenu.tsx +170 -0
- package/src/contexts/tabGroupChoice.tsx +82 -0
- package/{lib/utils/pathUtils.d.ts → src/hooks/styles.css} +4 -1
- package/src/hooks/useHideableNavbar.ts +77 -0
- package/src/hooks/useKeyboardNavigation.ts +45 -0
- package/src/hooks/useLockBodyScroll.ts +21 -0
- package/src/hooks/usePrismTheme.ts +24 -0
- package/src/hooks/useSearchPage.ts +79 -0
- package/src/hooks/useTOCHighlight.ts +192 -0
- package/src/hooks/useWindowSize.ts +72 -0
- package/src/index.ts +129 -18
- package/src/types.d.ts +0 -2
- package/src/utils/ThemeClassNames.ts +51 -5
- package/src/utils/codeBlockUtils.ts +155 -2
- package/src/utils/docsUtils.tsx +180 -0
- package/src/utils/footerUtils.ts +18 -0
- package/src/utils/generalUtils.ts +9 -5
- package/src/utils/historyUtils.ts +45 -0
- package/src/utils/jsUtils.ts +36 -0
- package/src/utils/metadataUtils.tsx +115 -0
- package/src/utils/navbarUtils.tsx +40 -0
- package/src/utils/reactUtils.tsx +76 -0
- package/src/utils/regexpUtils.ts +24 -0
- package/src/utils/routesUtils.ts +75 -0
- package/src/utils/scrollUtils.tsx +234 -0
- package/src/utils/searchUtils.ts +49 -0
- package/src/utils/storageUtils.ts +57 -24
- package/src/utils/tagsUtils.ts +55 -0
- package/src/utils/tocUtils.ts +119 -0
- package/src/utils/useAlternatePageUtils.ts +28 -7
- package/src/utils/useLocalPathname.ts +22 -0
- package/src/utils/useLocationChange.ts +41 -0
- package/src/utils/usePluralForm.ts +49 -39
- package/src/utils/useThemeConfig.ts +49 -24
- package/lib/.tsbuildinfo +0 -4159
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.d.ts +0 -21
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js +0 -94
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.d.ts +0 -13
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.js +0 -20
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.d.ts +0 -5
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.js +0 -41
- package/lib/utils/pathUtils.js +0 -13
- package/lib/utils/useChangeRoute.js +0 -18
- package/src/utils/__tests__/codeBlockUtils.test.ts +0 -54
- package/src/utils/__tests__/pathUtils.test.ts +0 -32
- package/src/utils/docsPreferredVersion/DocsPreferredVersionProvider.tsx +0 -165
- package/src/utils/docsPreferredVersion/DocsPreferredVersionStorage.ts +0 -34
- package/src/utils/docsPreferredVersion/useDocsPreferredVersion.ts +0 -66
- package/src/utils/docsUtils.ts +0 -11
- package/src/utils/pathUtils.ts +0 -17
- package/src/utils/useChangeRoute.ts +0 -21
- package/tsconfig.json +0 -10
|
@@ -0,0 +1,49 @@
|
|
|
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, { useState, useCallback, useEffect, useMemo, useContext, } from 'react';
|
|
8
|
+
import { createStorageSlot, listStorageKeys } from '../utils/storageUtils';
|
|
9
|
+
import { ReactContextError } from '../utils/reactUtils';
|
|
10
|
+
const TAB_CHOICE_PREFIX = 'docusaurus.tab.';
|
|
11
|
+
const Context = React.createContext(undefined);
|
|
12
|
+
function useContextValue() {
|
|
13
|
+
const [tabGroupChoices, setChoices] = useState({});
|
|
14
|
+
const setChoiceSyncWithLocalStorage = useCallback((groupId, newChoice) => {
|
|
15
|
+
createStorageSlot(`${TAB_CHOICE_PREFIX}${groupId}`).set(newChoice);
|
|
16
|
+
}, []);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
try {
|
|
19
|
+
const localStorageChoices = {};
|
|
20
|
+
listStorageKeys().forEach((storageKey) => {
|
|
21
|
+
if (storageKey.startsWith(TAB_CHOICE_PREFIX)) {
|
|
22
|
+
const groupId = storageKey.substring(TAB_CHOICE_PREFIX.length);
|
|
23
|
+
localStorageChoices[groupId] = createStorageSlot(storageKey).get();
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
setChoices(localStorageChoices);
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
console.error(err);
|
|
30
|
+
}
|
|
31
|
+
}, []);
|
|
32
|
+
const setTabGroupChoices = useCallback((groupId, newChoice) => {
|
|
33
|
+
setChoices((oldChoices) => ({ ...oldChoices, [groupId]: newChoice }));
|
|
34
|
+
setChoiceSyncWithLocalStorage(groupId, newChoice);
|
|
35
|
+
}, [setChoiceSyncWithLocalStorage]);
|
|
36
|
+
return useMemo(() => ({ tabGroupChoices, setTabGroupChoices }), [tabGroupChoices, setTabGroupChoices]);
|
|
37
|
+
}
|
|
38
|
+
export function TabGroupChoiceProvider({ children, }) {
|
|
39
|
+
const value = useContextValue();
|
|
40
|
+
return React.createElement(Context.Provider, { value: value }, children);
|
|
41
|
+
}
|
|
42
|
+
export function useTabGroupChoice() {
|
|
43
|
+
const context = useContext(Context);
|
|
44
|
+
if (context == null) {
|
|
45
|
+
throw new ReactContextError('TabGroupChoiceProvider');
|
|
46
|
+
}
|
|
47
|
+
return context;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=tabGroupChoice.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tabGroupChoice.js","sourceRoot":"","sources":["../../src/contexts/tabGroupChoice.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,EACZ,QAAQ,EACR,WAAW,EACX,SAAS,EACT,OAAO,EACP,UAAU,GAEX,MAAM,OAAO,CAAC;AACf,OAAO,EAAC,iBAAiB,EAAE,eAAe,EAAC,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAC,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AAEtD,MAAM,iBAAiB,GAAG,iBAAiB,CAAC;AAS5C,MAAM,OAAO,GAAG,KAAK,CAAC,aAAa,CAA2B,SAAS,CAAC,CAAC;AAEzE,SAAS,eAAe;IACtB,MAAM,CAAC,eAAe,EAAE,UAAU,CAAC,GAAG,QAAQ,CAE3C,EAAE,CAAC,CAAC;IACP,MAAM,6BAA6B,GAAG,WAAW,CAAC,CAAC,OAAO,EAAE,SAAS,EAAE,EAAE;QACvE,iBAAiB,CAAC,GAAG,iBAAiB,GAAG,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACrE,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,SAAS,CAAC,GAAG,EAAE;QACb,IAAI;YACF,MAAM,mBAAmB,GAAgC,EAAE,CAAC;YAC5D,eAAe,EAAE,CAAC,OAAO,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I,iBAAiB,CAAC,wBAAwB,CAAC,CAAC;KACvD;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -4,4 +4,7 @@
|
|
|
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
|
-
|
|
7
|
+
|
|
8
|
+
body:not(.navigation-with-keyboard) *:not(input):focus {
|
|
9
|
+
outline: none;
|
|
10
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
* Wires the imperative logic of a hideable navbar.
|
|
9
|
+
* @param hideOnScroll If `false`, this hook is basically a no-op.
|
|
10
|
+
*/
|
|
11
|
+
export declare function useHideableNavbar(hideOnScroll: boolean): {
|
|
12
|
+
/** A ref to the navbar component. Plug this into the actual element. */
|
|
13
|
+
readonly navbarRef: (node: HTMLElement | null) => void;
|
|
14
|
+
/** If `false`, the navbar component should not be rendered. */
|
|
15
|
+
readonly isNavbarVisible: boolean;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=useHideableNavbar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useHideableNavbar.d.ts","sourceRoot":"","sources":["../../src/hooks/useHideableNavbar.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,OAAO,GAAG;IACxD,wEAAwE;IACxE,QAAQ,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,KAAK,IAAI,CAAC;IACvD,+DAA+D;IAC/D,QAAQ,CAAC,eAAe,EAAE,OAAO,CAAC;CACnC,CAwDA"}
|
|
@@ -0,0 +1,61 @@
|
|
|
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 { useState, useCallback, useRef } from 'react';
|
|
8
|
+
import { useLocationChange } from '../utils/useLocationChange';
|
|
9
|
+
import { useScrollPosition } from '../utils/scrollUtils';
|
|
10
|
+
/**
|
|
11
|
+
* Wires the imperative logic of a hideable navbar.
|
|
12
|
+
* @param hideOnScroll If `false`, this hook is basically a no-op.
|
|
13
|
+
*/
|
|
14
|
+
export function useHideableNavbar(hideOnScroll) {
|
|
15
|
+
const [isNavbarVisible, setIsNavbarVisible] = useState(hideOnScroll);
|
|
16
|
+
const isFocusedAnchor = useRef(false);
|
|
17
|
+
const navbarHeight = useRef(0);
|
|
18
|
+
const navbarRef = useCallback((node) => {
|
|
19
|
+
if (node !== null) {
|
|
20
|
+
navbarHeight.current = node.getBoundingClientRect().height;
|
|
21
|
+
}
|
|
22
|
+
}, []);
|
|
23
|
+
useScrollPosition((currentPosition, lastPosition) => {
|
|
24
|
+
if (!hideOnScroll) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const scrollTop = currentPosition.scrollY;
|
|
28
|
+
// Needed mostly for handling rubber band scrolling.
|
|
29
|
+
// See https://github.com/facebook/docusaurus/pull/5721
|
|
30
|
+
if (scrollTop < navbarHeight.current) {
|
|
31
|
+
setIsNavbarVisible(true);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (isFocusedAnchor.current) {
|
|
35
|
+
isFocusedAnchor.current = false;
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const lastScrollTop = lastPosition?.scrollY;
|
|
39
|
+
const documentHeight = document.documentElement.scrollHeight - navbarHeight.current;
|
|
40
|
+
const windowHeight = window.innerHeight;
|
|
41
|
+
if (lastScrollTop && scrollTop >= lastScrollTop) {
|
|
42
|
+
setIsNavbarVisible(false);
|
|
43
|
+
}
|
|
44
|
+
else if (scrollTop + windowHeight < documentHeight) {
|
|
45
|
+
setIsNavbarVisible(true);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
useLocationChange((locationChangeEvent) => {
|
|
49
|
+
if (!hideOnScroll) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (locationChangeEvent.location.hash) {
|
|
53
|
+
isFocusedAnchor.current = true;
|
|
54
|
+
setIsNavbarVisible(false);
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
setIsNavbarVisible(true);
|
|
58
|
+
});
|
|
59
|
+
return { navbarRef, isNavbarVisible };
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=useHideableNavbar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useHideableNavbar.js","sourceRoot":"","sources":["../../src/hooks/useHideableNavbar.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAC,MAAM,OAAO,CAAC;AACpD,OAAO,EAAC,iBAAiB,EAAC,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAC,iBAAiB,EAAC,MAAM,sBAAsB,CAAC;AAEvD;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,YAAqB;IAMrD,MAAM,CAAC,eAAe,EAAE,kBAAkB,CAAC,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC;IACrE,MAAM,eAAe,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACtC,MAAM,YAAY,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IAC/B,MAAM,SAAS,GAAG,WAAW,CAAC,CAAC,IAAwB,EAAE,EAAE;QACzD,IAAI,IAAI,KAAK,IAAI,EAAE;YACjB,YAAY,CAAC,OAAO,GAAG,IAAI,CAAC,qBAAqB,EAAE,CAAC,MAAM,CAAC;SA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|
+
* 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 './styles.css';
|
|
8
|
+
export declare const keyboardFocusedClassName = "navigation-with-keyboard";
|
|
9
|
+
/**
|
|
10
|
+
* Side-effect that adds the `keyboardFocusedClassName` to the body element when
|
|
11
|
+
* the keyboard has been pressed, or removes it when the mouse is clicked.
|
|
12
|
+
*
|
|
13
|
+
* The presence of this class name signals that the user may be using keyboard
|
|
14
|
+
* for navigation, and the theme **must** add focus outline when this class name
|
|
15
|
+
* is present. (And optionally not if it's absent, for design purposes)
|
|
16
|
+
*
|
|
17
|
+
* Inspired by https://hackernoon.com/removing-that-ugly-focus-ring-and-keeping-it-too-6c8727fefcd2
|
|
18
|
+
*/
|
|
19
|
+
export declare function useKeyboardNavigation(): void;
|
|
20
|
+
//# sourceMappingURL=useKeyboardNavigation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useKeyboardNavigation.d.ts","sourceRoot":"","sources":["../../src/hooks/useKeyboardNavigation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,cAAc,CAAC;AAEtB,eAAO,MAAM,wBAAwB,6BAA6B,CAAC;AAEnE;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAqB5C"}
|
|
@@ -0,0 +1,39 @@
|
|
|
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 { useEffect } from 'react';
|
|
8
|
+
import './styles.css';
|
|
9
|
+
export const keyboardFocusedClassName = 'navigation-with-keyboard';
|
|
10
|
+
/**
|
|
11
|
+
* Side-effect that adds the `keyboardFocusedClassName` to the body element when
|
|
12
|
+
* the keyboard has been pressed, or removes it when the mouse is clicked.
|
|
13
|
+
*
|
|
14
|
+
* The presence of this class name signals that the user may be using keyboard
|
|
15
|
+
* for navigation, and the theme **must** add focus outline when this class name
|
|
16
|
+
* is present. (And optionally not if it's absent, for design purposes)
|
|
17
|
+
*
|
|
18
|
+
* Inspired by https://hackernoon.com/removing-that-ugly-focus-ring-and-keeping-it-too-6c8727fefcd2
|
|
19
|
+
*/
|
|
20
|
+
export function useKeyboardNavigation() {
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
function handleOutlineStyles(e) {
|
|
23
|
+
if (e.type === 'keydown' && e.key === 'Tab') {
|
|
24
|
+
document.body.classList.add(keyboardFocusedClassName);
|
|
25
|
+
}
|
|
26
|
+
if (e.type === 'mousedown') {
|
|
27
|
+
document.body.classList.remove(keyboardFocusedClassName);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
document.addEventListener('keydown', handleOutlineStyles);
|
|
31
|
+
document.addEventListener('mousedown', handleOutlineStyles);
|
|
32
|
+
return () => {
|
|
33
|
+
document.body.classList.remove(keyboardFocusedClassName);
|
|
34
|
+
document.removeEventListener('keydown', handleOutlineStyles);
|
|
35
|
+
document.removeEventListener('mousedown', handleOutlineStyles);
|
|
36
|
+
};
|
|
37
|
+
}, []);
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=useKeyboardNavigation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useKeyboardNavigation.js","sourceRoot":"","sources":["../../src/hooks/useKeyboardNavigation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AAEhC,OAAO,cAAc,CAAC;AAEtB,MAAM,CAAC,MAAM,wBAAwB,GAAG,0BAA0B,CAAC;AAEnE;;;;;;;;;GASG;AACH,MAAM,UAAU,qBAAqB;IACnC,SAAS,CAAC,GAAG,EAAE;QACb,SAAS,mBAAmB,CAAC,CAA6B;YACxD,IAAI,CAAC,CAAC,IAAI,KAAK,SAAS,IAAK,CAAmB,CAAC,GAAG,KAAK,KAAK,EAAE;gBAC9D,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;aACvD;YAED,IAAI,CAAC,CAAC,IAAI,KAAK,WAAW,EAAE;gBAC1B,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,wBAAwB,CAAC,CAAC;aAC1D;QACH,CAAC;QAED,QAAQ,CAAC,gBAAgB,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC;QAC1D,QAAQ,CAAC,gBAAgB,CAAC,WAAW,EAAE,mBAAmB,CAAC,CAAC;QAE5D,OAAO,GAAG,EAAE;YACV,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,wBAAwB,CAAC,CAAC;YACzD,QAAQ,CAAC,mBAAmB,CAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC;YAC7D,QAAQ,CAAC,mBAAmB,CAAC,WAAW,EAAE,mBAAmB,CAAC,CAAC;QACjE,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Side-effect that locks the document body's scroll throughout the lifetime of
|
|
9
|
+
* the containing component. e.g. when the mobile sidebar is expanded.
|
|
10
|
+
*/
|
|
11
|
+
export declare function useLockBodyScroll(lock?: boolean): void;
|
|
12
|
+
//# sourceMappingURL=useLockBodyScroll.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLockBodyScroll.d.ts","sourceRoot":"","sources":["../../src/hooks/useLockBodyScroll.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,GAAE,OAAc,GAAG,IAAI,CAO5D"}
|
|
@@ -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
|
+
import { useEffect } from 'react';
|
|
8
|
+
/**
|
|
9
|
+
* Side-effect that locks the document body's scroll throughout the lifetime of
|
|
10
|
+
* the containing component. e.g. when the mobile sidebar is expanded.
|
|
11
|
+
*/
|
|
12
|
+
export function useLockBodyScroll(lock = true) {
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
document.body.style.overflow = lock ? 'hidden' : 'visible';
|
|
15
|
+
return () => {
|
|
16
|
+
document.body.style.overflow = 'visible';
|
|
17
|
+
};
|
|
18
|
+
}, [lock]);
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=useLockBodyScroll.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLockBodyScroll.js","sourceRoot":"","sources":["../../src/hooks/useLockBodyScroll.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AAEhC;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAAgB,IAAI;IACpD,SAAS,CAAC,GAAG,EAAE;QACb,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;QAC3D,OAAO,GAAG,EAAE;YACV,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,GAAG,SAAS,CAAC;QAC3C,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
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 defaultTheme from 'prism-react-renderer/themes/palenight';
|
|
8
|
+
/**
|
|
9
|
+
* Returns a color-mode-dependent Prism theme: whatever the user specified in
|
|
10
|
+
* the config. Falls back to `palenight`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function usePrismTheme(): typeof defaultTheme;
|
|
13
|
+
//# sourceMappingURL=usePrismTheme.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePrismTheme.d.ts","sourceRoot":"","sources":["../../src/hooks/usePrismTheme.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,YAAY,MAAM,uCAAuC,CAAC;AAIjE;;;GAGG;AACH,wBAAgB,aAAa,IAAI,OAAO,YAAY,CAQnD"}
|
|
@@ -0,0 +1,22 @@
|
|
|
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 defaultTheme from 'prism-react-renderer/themes/palenight';
|
|
8
|
+
import { useColorMode } from '../contexts/colorMode';
|
|
9
|
+
import { useThemeConfig } from '../utils/useThemeConfig';
|
|
10
|
+
/**
|
|
11
|
+
* Returns a color-mode-dependent Prism theme: whatever the user specified in
|
|
12
|
+
* the config. Falls back to `palenight`.
|
|
13
|
+
*/
|
|
14
|
+
export function usePrismTheme() {
|
|
15
|
+
const { prism } = useThemeConfig();
|
|
16
|
+
const { colorMode } = useColorMode();
|
|
17
|
+
const lightModeTheme = prism.theme || defaultTheme;
|
|
18
|
+
const darkModeTheme = prism.darkTheme || lightModeTheme;
|
|
19
|
+
const prismTheme = colorMode === 'dark' ? darkModeTheme : lightModeTheme;
|
|
20
|
+
return prismTheme;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=usePrismTheme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePrismTheme.js","sourceRoot":"","sources":["../../src/hooks/usePrismTheme.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,YAAY,MAAM,uCAAuC,CAAC;AACjE,OAAO,EAAC,YAAY,EAAC,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAC,cAAc,EAAC,MAAM,yBAAyB,CAAC;AAEvD;;;GAGG;AACH,MAAM,UAAU,aAAa;IAC3B,MAAM,EAAC,KAAK,EAAC,GAAG,cAAc,EAAE,CAAC;IACjC,MAAM,EAAC,SAAS,EAAC,GAAG,YAAY,EAAE,CAAC;IACnC,MAAM,cAAc,GAAG,KAAK,CAAC,KAAK,IAAI,YAAY,CAAC;IACnD,MAAM,aAAa,GAAG,KAAK,CAAC,SAAS,IAAI,cAAc,CAAC;IACxD,MAAM,UAAU,GAAG,SAAS,KAAK,MAAM,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,cAAc,CAAC;IAEzE,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
/** Some utility functions around search queries. */
|
|
8
|
+
export declare function useSearchPage(): {
|
|
9
|
+
/**
|
|
10
|
+
* Works hand-in-hand with `setSearchQuery`; whatever the user has inputted
|
|
11
|
+
* into the search box.
|
|
12
|
+
*/
|
|
13
|
+
searchQuery: string;
|
|
14
|
+
/**
|
|
15
|
+
* Set a new search query. In addition to updating `searchQuery`, this handle
|
|
16
|
+
* also mutates the location and appends the query.
|
|
17
|
+
*/
|
|
18
|
+
setSearchQuery: (newSearchQuery: string) => void;
|
|
19
|
+
/**
|
|
20
|
+
* Given a query, this handle generates the corresponding search page link,
|
|
21
|
+
* with base URL prepended.
|
|
22
|
+
*/
|
|
23
|
+
generateSearchPageLink: (targetSearchQuery: string) => string;
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=useSearchPage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSearchPage.d.ts","sourceRoot":"","sources":["../../src/hooks/useSearchPage.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,oDAAoD;AACpD,wBAAgB,aAAa,IAAI;IAC/B;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,cAAc,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,IAAI,CAAC;IACjD;;;OAGG;IACH,sBAAsB,EAAE,CAAC,iBAAiB,EAAE,MAAM,KAAK,MAAM,CAAC;CAC/D,CAgDA"}
|
|
@@ -0,0 +1,43 @@
|
|
|
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 { useHistory } from '@docusaurus/router';
|
|
8
|
+
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
9
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
10
|
+
const SEARCH_PARAM_QUERY = 'q';
|
|
11
|
+
/** Some utility functions around search queries. */
|
|
12
|
+
export function useSearchPage() {
|
|
13
|
+
const history = useHistory();
|
|
14
|
+
const { siteConfig: { baseUrl }, } = useDocusaurusContext();
|
|
15
|
+
const [searchQuery, setSearchQueryState] = useState('');
|
|
16
|
+
// Init search query just after React hydration
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
const searchQueryStringValue = new URLSearchParams(window.location.search).get(SEARCH_PARAM_QUERY) ?? '';
|
|
19
|
+
setSearchQueryState(searchQueryStringValue);
|
|
20
|
+
}, []);
|
|
21
|
+
const setSearchQuery = useCallback((newSearchQuery) => {
|
|
22
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
23
|
+
if (newSearchQuery) {
|
|
24
|
+
searchParams.set(SEARCH_PARAM_QUERY, newSearchQuery);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
searchParams.delete(SEARCH_PARAM_QUERY);
|
|
28
|
+
}
|
|
29
|
+
history.replace({
|
|
30
|
+
search: searchParams.toString(),
|
|
31
|
+
});
|
|
32
|
+
setSearchQueryState(newSearchQuery);
|
|
33
|
+
}, [history]);
|
|
34
|
+
const generateSearchPageLink = useCallback((targetSearchQuery) =>
|
|
35
|
+
// Refer to https://github.com/facebook/docusaurus/pull/2838
|
|
36
|
+
`${baseUrl}search?${SEARCH_PARAM_QUERY}=${encodeURIComponent(targetSearchQuery)}`, [baseUrl]);
|
|
37
|
+
return {
|
|
38
|
+
searchQuery,
|
|
39
|
+
setSearchQuery,
|
|
40
|
+
generateSearchPageLink,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=useSearchPage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSearchPage.js","sourceRoot":"","sources":["../../src/hooks/useSearchPage.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,UAAU,EAAC,MAAM,oBAAoB,CAAC;AAC9C,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAC,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AAEvD,MAAM,kBAAkB,GAAG,GAAG,CAAC;AAE/B,oDAAoD;AACpD,MAAM,UAAU,aAAa;IAiB3B,MAAM,OA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|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
export declare type TOCHighlightConfig = {
|
|
8
|
+
/** A class name that all TOC links share. */
|
|
9
|
+
linkClassName: string;
|
|
10
|
+
/** The class name applied to the active (highlighted) link. */
|
|
11
|
+
linkActiveClassName: string;
|
|
12
|
+
/**
|
|
13
|
+
* The minimum heading level that the TOC includes. Only headings that are in
|
|
14
|
+
* this range will be eligible as "active heading".
|
|
15
|
+
*/
|
|
16
|
+
minHeadingLevel: number;
|
|
17
|
+
/** @see {@link TOCHighlightConfig.minHeadingLevel} */
|
|
18
|
+
maxHeadingLevel: number;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Side-effect that applies the active class name to the TOC heading that the
|
|
22
|
+
* user is currently viewing. Disabled when `config` is undefined.
|
|
23
|
+
*/
|
|
24
|
+
export declare function useTOCHighlight(config: TOCHighlightConfig | undefined): void;
|
|
25
|
+
//# sourceMappingURL=useTOCHighlight.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTOCHighlight.d.ts","sourceRoot":"","sources":["../../src/hooks/useTOCHighlight.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAgHH,oBAAY,kBAAkB,GAAG;IAC/B,6CAA6C;IAC7C,aAAa,EAAE,MAAM,CAAC;IACtB,+DAA+D;IAC/D,mBAAmB,EAAE,MAAM,CAAC;IAC5B;;;OAGG;IACH,eAAe,EAAE,MAAM,CAAC;IACxB,sDAAsD;IACtD,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,kBAAkB,GAAG,SAAS,GAAG,IAAI,CAwD5E"}
|
|
@@ -0,0 +1,130 @@
|
|
|
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 { useEffect, useRef } from 'react';
|
|
8
|
+
import { useThemeConfig } from '../utils/useThemeConfig';
|
|
9
|
+
// TODO make the hardcoded theme-classic classnames configurable (or add them
|
|
10
|
+
// to ThemeClassNames?)
|
|
11
|
+
/**
|
|
12
|
+
* If the anchor has no height and is just a "marker" in the DOM; we'll use the
|
|
13
|
+
* parent (normally the link text) rect boundaries instead
|
|
14
|
+
*/
|
|
15
|
+
function getVisibleBoundingClientRect(element) {
|
|
16
|
+
const rect = element.getBoundingClientRect();
|
|
17
|
+
const hasNoHeight = rect.top === rect.bottom;
|
|
18
|
+
if (hasNoHeight) {
|
|
19
|
+
return getVisibleBoundingClientRect(element.parentNode);
|
|
20
|
+
}
|
|
21
|
+
return rect;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Considering we divide viewport into 2 zones of each 50vh, this returns true
|
|
25
|
+
* if an element is in the first zone (i.e., appear in viewport, near the top)
|
|
26
|
+
*/
|
|
27
|
+
function isInViewportTopHalf(boundingRect) {
|
|
28
|
+
return boundingRect.top > 0 && boundingRect.bottom < window.innerHeight / 2;
|
|
29
|
+
}
|
|
30
|
+
function getAnchors({ minHeadingLevel, maxHeadingLevel, }) {
|
|
31
|
+
const selectors = [];
|
|
32
|
+
for (let i = minHeadingLevel; i <= maxHeadingLevel; i += 1) {
|
|
33
|
+
selectors.push(`h${i}.anchor`);
|
|
34
|
+
}
|
|
35
|
+
return Array.from(document.querySelectorAll(selectors.join()));
|
|
36
|
+
}
|
|
37
|
+
function getActiveAnchor(anchors, { anchorTopOffset, }) {
|
|
38
|
+
// Naming is hard: The "nextVisibleAnchor" is the first anchor that appear
|
|
39
|
+
// under the viewport top boundary. It does not mean this anchor is visible
|
|
40
|
+
// yet, but if user continues scrolling down, it will be the first to become
|
|
41
|
+
// visible
|
|
42
|
+
const nextVisibleAnchor = anchors.find((anchor) => {
|
|
43
|
+
const boundingRect = getVisibleBoundingClientRect(anchor);
|
|
44
|
+
return boundingRect.top >= anchorTopOffset;
|
|
45
|
+
});
|
|
46
|
+
if (nextVisibleAnchor) {
|
|
47
|
+
const boundingRect = getVisibleBoundingClientRect(nextVisibleAnchor);
|
|
48
|
+
// If anchor is in the top half of the viewport: it is the one we consider
|
|
49
|
+
// "active" (unless it's too close to the top and and soon to be scrolled
|
|
50
|
+
// outside viewport)
|
|
51
|
+
if (isInViewportTopHalf(boundingRect)) {
|
|
52
|
+
return nextVisibleAnchor;
|
|
53
|
+
}
|
|
54
|
+
// If anchor is in the bottom half of the viewport, or under the viewport,
|
|
55
|
+
// we consider the active anchor is the previous one. This is because the
|
|
56
|
+
// main text appearing in the user screen mostly belong to the previous
|
|
57
|
+
// anchor. Returns null for the first anchor, see
|
|
58
|
+
// https://github.com/facebook/docusaurus/issues/5318
|
|
59
|
+
return anchors[anchors.indexOf(nextVisibleAnchor) - 1] ?? null;
|
|
60
|
+
}
|
|
61
|
+
// no anchor under viewport top? (ie we are at the bottom of the page)
|
|
62
|
+
// => highlight the last anchor found
|
|
63
|
+
return anchors[anchors.length - 1] ?? null;
|
|
64
|
+
}
|
|
65
|
+
function getLinkAnchorValue(link) {
|
|
66
|
+
return decodeURIComponent(link.href.substring(link.href.indexOf('#') + 1));
|
|
67
|
+
}
|
|
68
|
+
function getLinks(linkClassName) {
|
|
69
|
+
return Array.from(document.getElementsByClassName(linkClassName));
|
|
70
|
+
}
|
|
71
|
+
function getNavbarHeight() {
|
|
72
|
+
// Not ideal to obtain actual height this way
|
|
73
|
+
// Using TS ! (not ?) because otherwise a bad selector would be un-noticed
|
|
74
|
+
return document.querySelector('.navbar').clientHeight;
|
|
75
|
+
}
|
|
76
|
+
function useAnchorTopOffsetRef() {
|
|
77
|
+
const anchorTopOffsetRef = useRef(0);
|
|
78
|
+
const { navbar: { hideOnScroll }, } = useThemeConfig();
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
anchorTopOffsetRef.current = hideOnScroll ? 0 : getNavbarHeight();
|
|
81
|
+
}, [hideOnScroll]);
|
|
82
|
+
return anchorTopOffsetRef;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Side-effect that applies the active class name to the TOC heading that the
|
|
86
|
+
* user is currently viewing. Disabled when `config` is undefined.
|
|
87
|
+
*/
|
|
88
|
+
export function useTOCHighlight(config) {
|
|
89
|
+
const lastActiveLinkRef = useRef(undefined);
|
|
90
|
+
const anchorTopOffsetRef = useAnchorTopOffsetRef();
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
if (!config) {
|
|
93
|
+
// no-op, highlighting is disabled
|
|
94
|
+
return () => { };
|
|
95
|
+
}
|
|
96
|
+
const { linkClassName, linkActiveClassName, minHeadingLevel, maxHeadingLevel, } = config;
|
|
97
|
+
function updateLinkActiveClass(link, active) {
|
|
98
|
+
if (active) {
|
|
99
|
+
if (lastActiveLinkRef.current && lastActiveLinkRef.current !== link) {
|
|
100
|
+
lastActiveLinkRef.current?.classList.remove(linkActiveClassName);
|
|
101
|
+
}
|
|
102
|
+
link.classList.add(linkActiveClassName);
|
|
103
|
+
lastActiveLinkRef.current = link;
|
|
104
|
+
// link.scrollIntoView({block: 'nearest'});
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
link.classList.remove(linkActiveClassName);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function updateActiveLink() {
|
|
111
|
+
const links = getLinks(linkClassName);
|
|
112
|
+
const anchors = getAnchors({ minHeadingLevel, maxHeadingLevel });
|
|
113
|
+
const activeAnchor = getActiveAnchor(anchors, {
|
|
114
|
+
anchorTopOffset: anchorTopOffsetRef.current,
|
|
115
|
+
});
|
|
116
|
+
const activeLink = links.find((link) => activeAnchor && activeAnchor.id === getLinkAnchorValue(link));
|
|
117
|
+
links.forEach((link) => {
|
|
118
|
+
updateLinkActiveClass(link, link === activeLink);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
document.addEventListener('scroll', updateActiveLink);
|
|
122
|
+
document.addEventListener('resize', updateActiveLink);
|
|
123
|
+
updateActiveLink();
|
|
124
|
+
return () => {
|
|
125
|
+
document.removeEventListener('scroll', updateActiveLink);
|
|
126
|
+
document.removeEventListener('resize', updateActiveLink);
|
|
127
|
+
};
|
|
128
|
+
}, [config, anchorTopOffsetRef]);
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=useTOCHighlight.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTOCHighlight.js","sourceRoot":"","sources":["../../src/hooks/useTOCHighlight.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,SAAS,EAAE,MAAM,EAAC,MAAM,OAAO,CAAC;AACxC,OAAO,EAAC,cAAc,EAAC,MAAM,yBAAyB,CAAC;AAEvD,6EAA6E;AAC7E,uBAAuB;AAEvB;;;GAGG;AACH,SAAS,4BAA4B,CAAC,OAAoB;IACxD,MAAM,IAAI,GAAG,OAAO,CAAC,qBAAqB,EAAE,CAAC;IAC7C,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,KAAK,IAAI,CAAC,MAAM,CAAC;IAC7C,IAAI,WAAW,EAAE;QACf,OAAO,4BAA4B,CAAC,OAAO,CAAC,UAAyB,CAAC,CAAC;KACxE;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;GAGG;AACH,SAAS,mBAAmB,CAAC,YAAqB;IAChD,OAAO,YAAY,CAAC,GAAG,GAAG,CAAC,IAAI,YAAY,CAAC,MAAM,GAAG,MAAM,CAAC,WAAW,GAAG,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,UAAU,CAAC,EAClB,eAAe,EACf,eAAe,GAIhB;IACC,MAAM,SAAS,GAAG,EAAE,CAAC;IACrB,KAAK,IAAI,CAAC,GAAG,eAAe,EAAE,CAAC,IAAI,eAAe,EAAE,CAA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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
|
+
declare const windowSizes: {
|
|
8
|
+
readonly desktop: "desktop";
|
|
9
|
+
readonly mobile: "mobile";
|
|
10
|
+
readonly ssr: "ssr";
|
|
11
|
+
};
|
|
12
|
+
declare type WindowSize = keyof typeof windowSizes;
|
|
13
|
+
/**
|
|
14
|
+
* Gets the current window size as an enum value. We don't want it to return the
|
|
15
|
+
* actual width value, so that it only re-renders once a breakpoint is crossed.
|
|
16
|
+
*
|
|
17
|
+
* It may return `"ssr"`, which is very important to handle hydration FOUC or
|
|
18
|
+
* layout shifts. You have to handle it explicitly upfront. On the server, you
|
|
19
|
+
* may need to render BOTH the mobile/desktop elements (and hide one of them
|
|
20
|
+
* with mediaquery). We don't return `undefined` on purpose, to make it more
|
|
21
|
+
* explicit.
|
|
22
|
+
*
|
|
23
|
+
* In development mode, this hook will still return `"ssr"` for one second, to
|
|
24
|
+
* catch potential layout shifts, similar to strict mode calling effects twice.
|
|
25
|
+
*/
|
|
26
|
+
export declare function useWindowSize(): WindowSize;
|
|
27
|
+
export {};
|
|
28
|
+
//# sourceMappingURL=useWindowSize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useWindowSize.d.ts","sourceRoot":"","sources":["../../src/hooks/useWindowSize.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,QAAA,MAAM,WAAW;;;;CAIP,CAAC;AAEX,aAAK,UAAU,GAAG,MAAM,OAAO,WAAW,CAAC;AAe3C;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,IAAI,UAAU,CA0B1C"}
|