@docusaurus/theme-common 0.0.0-4369 → 0.0.0-4378
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/hooks/styles.css +10 -0
- package/lib/hooks/useHideableNavbar.d.ts +13 -0
- package/lib/hooks/useHideableNavbar.d.ts.map +1 -0
- package/lib/hooks/useHideableNavbar.js +59 -0
- package/lib/hooks/useHideableNavbar.js.map +1 -0
- package/lib/hooks/useKeyboardNavigation.d.ts +9 -0
- package/lib/hooks/useKeyboardNavigation.d.ts.map +1 -0
- package/lib/hooks/useKeyboardNavigation.js +31 -0
- package/lib/hooks/useKeyboardNavigation.js.map +1 -0
- package/lib/hooks/useLockBodyScroll.d.ts +8 -0
- package/lib/hooks/useLockBodyScroll.d.ts.map +1 -0
- package/lib/hooks/useLockBodyScroll.js +16 -0
- package/lib/hooks/useLockBodyScroll.js.map +1 -0
- package/lib/hooks/usePrismTheme.d.ts +9 -0
- package/lib/hooks/usePrismTheme.d.ts.map +1 -0
- package/lib/hooks/usePrismTheme.js +18 -0
- package/lib/hooks/usePrismTheme.js.map +1 -0
- package/lib/hooks/useSearchPage.d.ts +14 -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/useWindowSize.d.ts +15 -0
- package/lib/hooks/useWindowSize.d.ts.map +1 -0
- package/lib/hooks/useWindowSize.js +54 -0
- package/lib/hooks/useWindowSize.js.map +1 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +8 -0
- package/lib/index.js.map +1 -1
- package/lib/utils/colorModeUtils.d.ts +18 -0
- package/lib/utils/colorModeUtils.d.ts.map +1 -0
- package/lib/utils/colorModeUtils.js +84 -0
- package/lib/utils/colorModeUtils.js.map +1 -0
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.d.ts.map +1 -1
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js +1 -1
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js.map +1 -1
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.d.ts +1 -2
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.d.ts.map +1 -1
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.js +1 -1
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.js.map +1 -1
- package/lib/utils/docsUtils.js +1 -1
- package/lib/utils/docsUtils.js.map +1 -1
- package/lib/utils/tabGroupChoiceUtils.d.ts +19 -0
- package/lib/utils/tabGroupChoiceUtils.d.ts.map +1 -0
- package/lib/utils/tabGroupChoiceUtils.js +54 -0
- package/lib/utils/tabGroupChoiceUtils.js.map +1 -0
- package/lib/utils/useContextualSearchFilters.d.ts.map +1 -1
- package/lib/utils/useContextualSearchFilters.js +1 -1
- package/lib/utils/useContextualSearchFilters.js.map +1 -1
- package/package.json +8 -8
- package/src/hooks/styles.css +10 -0
- package/src/hooks/useHideableNavbar.ts +77 -0
- package/src/hooks/useKeyboardNavigation.ts +37 -0
- package/src/hooks/useLockBodyScroll.ts +18 -0
- package/src/hooks/usePrismTheme.ts +20 -0
- package/src/hooks/useSearchPage.ts +66 -0
- package/src/hooks/useWindowSize.ts +68 -0
- package/src/index.ts +13 -0
- package/src/utils/colorModeUtils.tsx +135 -0
- package/src/utils/docsPreferredVersion/DocsPreferredVersionProvider.tsx +4 -1
- package/src/utils/docsPreferredVersion/useDocsPreferredVersion.ts +1 -1
- package/src/utils/docsUtils.tsx +1 -1
- package/src/utils/tabGroupChoiceUtils.tsx +90 -0
- package/src/utils/useContextualSearchFilters.ts +4 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"docsUtils.js","sourceRoot":"","sources":["../../src/utils/docsUtils.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,EAAC,aAAa,EAAkB,UAAU,E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CAAC,IAAI,KAAK,MAAM,EAAE;QACxB,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;KAC5B;IAED,IAAI,IAAI,CAAC,IAAI,KAAK,UAAU,EAAE;QAC5B,OAAO,CACL,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,yBAAyB,CAAC,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC,CACzE,CAAC;KACH;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import { type ReactNode } from 'react';
|
|
8
|
+
declare type TabGroupChoiceContextValue = {
|
|
9
|
+
readonly tabGroupChoices: {
|
|
10
|
+
readonly [groupId: string]: string;
|
|
11
|
+
};
|
|
12
|
+
readonly setTabGroupChoices: (groupId: string, newChoice: string) => void;
|
|
13
|
+
};
|
|
14
|
+
export declare function TabGroupChoiceProvider({ children, }: {
|
|
15
|
+
children: ReactNode;
|
|
16
|
+
}): JSX.Element;
|
|
17
|
+
export declare function useTabGroupChoice(): TabGroupChoiceContextValue;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=tabGroupChoiceUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tabGroupChoiceUtils.d.ts","sourceRoot":"","sources":["../../src/utils/tabGroupChoiceUtils.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAc,EAOZ,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAKf,aAAK,0BAA0B,GAAG;IAChC,QAAQ,CAAC,eAAe,EAAE;QAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAAA;KAAC,CAAC;IAC/D,QAAQ,CAAC,kBAAkB,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;CAC3E,CAAC;AAsCF,wBAAgB,sBAAsB,CAAC,EACrC,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,SAAS,CAAC;CACrB,GAAG,GAAG,CAAC,OAAO,CAcd;AAED,wBAAgB,iBAAiB,IAAI,0BAA0B,CAQ9D"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import React, { useState, useCallback, useEffect, createContext, useMemo, useContext, } from 'react';
|
|
8
|
+
import { createStorageSlot, listStorageKeys } from './storageUtils';
|
|
9
|
+
const TAB_CHOICE_PREFIX = 'docusaurus.tab.';
|
|
10
|
+
const TabGroupChoiceContext = createContext(undefined);
|
|
11
|
+
function useTabGroupChoiceContextValue() {
|
|
12
|
+
const [tabGroupChoices, setChoices] = useState({});
|
|
13
|
+
const setChoiceSyncWithLocalStorage = useCallback((groupId, newChoice) => {
|
|
14
|
+
createStorageSlot(`${TAB_CHOICE_PREFIX}${groupId}`).set(newChoice);
|
|
15
|
+
}, []);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
try {
|
|
18
|
+
const localStorageChoices = {};
|
|
19
|
+
listStorageKeys().forEach((storageKey) => {
|
|
20
|
+
if (storageKey.startsWith(TAB_CHOICE_PREFIX)) {
|
|
21
|
+
const groupId = storageKey.substring(TAB_CHOICE_PREFIX.length);
|
|
22
|
+
localStorageChoices[groupId] = createStorageSlot(storageKey).get();
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
setChoices(localStorageChoices);
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
console.error(err);
|
|
29
|
+
}
|
|
30
|
+
}, []);
|
|
31
|
+
return {
|
|
32
|
+
tabGroupChoices,
|
|
33
|
+
setTabGroupChoices: (groupId, newChoice) => {
|
|
34
|
+
setChoices((oldChoices) => ({ ...oldChoices, [groupId]: newChoice }));
|
|
35
|
+
setChoiceSyncWithLocalStorage(groupId, newChoice);
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export function TabGroupChoiceProvider({ children, }) {
|
|
40
|
+
const { tabGroupChoices, setTabGroupChoices } = useTabGroupChoiceContextValue();
|
|
41
|
+
const contextValue = useMemo(() => ({
|
|
42
|
+
tabGroupChoices,
|
|
43
|
+
setTabGroupChoices,
|
|
44
|
+
}), [tabGroupChoices, setTabGroupChoices]);
|
|
45
|
+
return (React.createElement(TabGroupChoiceContext.Provider, { value: contextValue }, children));
|
|
46
|
+
}
|
|
47
|
+
export function useTabGroupChoice() {
|
|
48
|
+
const context = useContext(TabGroupChoiceContext);
|
|
49
|
+
if (context == null) {
|
|
50
|
+
throw new Error('"useUserPreferencesContext" is used outside of "Layout" component.');
|
|
51
|
+
}
|
|
52
|
+
return context;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=tabGroupChoiceUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tabGroupChoiceUtils.js","sourceRoot":"","sources":["../../src/utils/tabGroupChoiceUtils.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,EACZ,QAAQ,EACR,WAAW,EACX,SAAS,EACT,aAAa,EACb,OAAO,EACP,UAAU,GAEX,MAAM,OAAO,CAAC;AACf,OAAO,EAAC,iBAAiB,EAAE,eAAe,EAAC,MAAM,gBAAgB,CAAC;AAElE,MAAM,iBAAiB,GAAG,iBAAiB,CAAC;AAO5C,MAAM,qBAAqB,GAAG,aAAa,CAEzC,SAAS,CAAC,CAAC;AAEb,SAAS,6BAA6B;IACpC,MAAM,CAAC,eAAe,EAAE,UAAU,CAAC,GAAG,Q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AAG,OAAO,CAC1B,GAAG,EAAE,CAAC,CAAC;QACL,eAAe;QACf,kBAAkB;KACnB,CAAC,EACF,CAAC,eAAe,EAAE,kBAAkB,CAAC,CACtC,CAAC;IACF,OAAO,CACL,oBAAC,qBAAqB,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,IAChD,QAAQ,CACsB,CAClC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB;IAC/B,MAAM,OAAO,GAAG,UAAU,CAAC,qBAAqB,CAAC,CAAC;IAClD,IAAI,OAAO,IAAI,IAAI,EAAE;QACnB,MAAM,IAAI,KAAK,CACb,oEAAoE,CACrE,CAAC;KACH;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useContextualSearchFilters.d.ts","sourceRoot":"","sources":["../../src/utils/useContextualSearchFilters.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"useContextualSearchFilters.d.ts","sourceRoot":"","sources":["../../src/utils/useContextualSearchFilters.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAUH,oBAAY,iCAAiC,GAAG;IAC9C,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB,CAAC;AAIF,wBAAgB,0BAA0B,IAAI,iCAAiC,CA8B9E"}
|
|
@@ -4,7 +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
|
-
import { useAllDocsData, useActivePluginAndVersion } from '@
|
|
7
|
+
import { useAllDocsData, useActivePluginAndVersion, } from '@docusaurus/plugin-content-docs/client';
|
|
8
8
|
import { useDocsPreferredVersionByPluginId } from './docsPreferredVersion/useDocsPreferredVersion';
|
|
9
9
|
import { docVersionSearchTag, DEFAULT_SEARCH_TAG } from './searchUtils';
|
|
10
10
|
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useContextualSearchFilters.js","sourceRoot":"","sources":["../../src/utils/useContextualSearchFilters.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"useContextualSearchFilters.js","sourceRoot":"","sources":["../../src/utils/useContextualSearchFilters.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,cAAc,EACd,yBAAyB,GAC1B,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAC,iCAAiC,EAAC,MAAM,gDAAgD,CAAC;AACjG,OAAO,EAAC,mBAAmB,EAAE,kBAAkB,EAAC,MAAM,eAAe,CAAC;AACtE,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;AAOpE,yFAAyF;AACzF,8DAA8D;AAC9D,MAAM,UAAU,0BAA0B;IACxC,MAAM,EAAC,IAAI,EAAC,GAAG,oBAAoB,EAAE,CAAC;IACtC,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IACrC,MAAM,sBAAsB,GAAG,yBAAyB,EAAE,CAAC;IAC3D,MAAM,8BAA8B,GAAG,iCAAiC,EAAE,CAAC;IAE3E,SAAS,gBAAgB,CAAC,QAAgB;;QACxC,MAAM,aAAa,GACjB,CAAA,MAAA,sBAAsB,aAAtB,sBAAsB,uBAAtB,sBAAsB,CAAE,YAAY,0CAAE,QAAQ,MAAK,QAAQ;YACzD,CAAC,CAAC,sBAAsB,CAAC,aAAa;YACtC,CAAC,CAAC,SAAS,CAAC;QAEhB,MAAM,gBAAgB,GAAG,8BAA8B,CAAC,QAAQ,CAAC,CAAC;QAElE,MAAM,aAAa,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAE,CAAC;QAE5E,MAAM,OAAO,GAAG,MAAA,aAAa,aAAb,aAAa,cAAb,aAAa,GAAI,gBAAgB,mCAAI,aAAa,CAAC;QAEnE,OAAO,mBAAmB,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACrD,CAAC;IAED,MAAM,IAAI,GAAG;QACX,kBAAkB;QAClB,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,gBAAgB,CAAC;KAClD,CAAC;IAEF,OAAO;QACL,MAAM,EAAE,IAAI,CAAC,aAAa;QAC1B,IAAI;KACL,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/theme-common",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-4378",
|
|
4
4
|
"description": "Common code for Docusaurus themes.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@docusaurus/plugin-content-blog": "0.0.0-
|
|
22
|
-
"@docusaurus/plugin-content-docs": "0.0.0-
|
|
23
|
-
"@docusaurus/plugin-content-pages": "0.0.0-
|
|
21
|
+
"@docusaurus/plugin-content-blog": "0.0.0-4378",
|
|
22
|
+
"@docusaurus/plugin-content-docs": "0.0.0-4378",
|
|
23
|
+
"@docusaurus/plugin-content-pages": "0.0.0-4378",
|
|
24
24
|
"clsx": "^1.1.1",
|
|
25
25
|
"fs-extra": "^10.0.0",
|
|
26
26
|
"parse-numeric-range": "^1.3.0",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"utility-types": "^3.10.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@docusaurus/core": "0.0.0-
|
|
32
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
33
|
-
"@docusaurus/types": "0.0.0-
|
|
31
|
+
"@docusaurus/core": "0.0.0-4378",
|
|
32
|
+
"@docusaurus/module-type-aliases": "0.0.0-4378",
|
|
33
|
+
"@docusaurus/types": "0.0.0-4378",
|
|
34
34
|
"@testing-library/react-hooks": "^7.0.2",
|
|
35
35
|
"lodash": "^4.17.20"
|
|
36
36
|
},
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"engines": {
|
|
43
43
|
"node": ">=14"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "bd7999376fa63feafe5b169296beb91dac362954"
|
|
46
46
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
body:not(.navigation-with-keyboard) *:not(input):focus {
|
|
9
|
+
outline: none;
|
|
10
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {useState, useCallback, useRef} from 'react';
|
|
9
|
+
import {useLocationChange} from '../utils/useLocationChange';
|
|
10
|
+
import {useScrollPosition} from '../utils/scrollUtils';
|
|
11
|
+
|
|
12
|
+
type UseHideableNavbarReturns = {
|
|
13
|
+
readonly navbarRef: (node: HTMLElement | null) => void;
|
|
14
|
+
readonly isNavbarVisible: boolean;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default function useHideableNavbar(
|
|
18
|
+
hideOnScroll: boolean,
|
|
19
|
+
): UseHideableNavbarReturns {
|
|
20
|
+
const [isNavbarVisible, setIsNavbarVisible] = useState(hideOnScroll);
|
|
21
|
+
const isFocusedAnchor = useRef(false);
|
|
22
|
+
const navbarHeight = useRef(0);
|
|
23
|
+
const navbarRef = useCallback((node: HTMLElement | null) => {
|
|
24
|
+
if (node !== null) {
|
|
25
|
+
navbarHeight.current = node.getBoundingClientRect().height;
|
|
26
|
+
}
|
|
27
|
+
}, []);
|
|
28
|
+
|
|
29
|
+
useScrollPosition((currentPosition, lastPosition) => {
|
|
30
|
+
if (!hideOnScroll) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const scrollTop = currentPosition.scrollY;
|
|
35
|
+
|
|
36
|
+
// It needed for mostly to handle rubber band scrolling
|
|
37
|
+
if (scrollTop < navbarHeight.current) {
|
|
38
|
+
setIsNavbarVisible(true);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (isFocusedAnchor.current) {
|
|
43
|
+
isFocusedAnchor.current = false;
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const lastScrollTop = lastPosition?.scrollY;
|
|
48
|
+
const documentHeight =
|
|
49
|
+
document.documentElement.scrollHeight - navbarHeight.current;
|
|
50
|
+
const windowHeight = window.innerHeight;
|
|
51
|
+
|
|
52
|
+
if (lastScrollTop && scrollTop >= lastScrollTop) {
|
|
53
|
+
setIsNavbarVisible(false);
|
|
54
|
+
} else if (scrollTop + windowHeight < documentHeight) {
|
|
55
|
+
setIsNavbarVisible(true);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
useLocationChange((locationChangeEvent) => {
|
|
60
|
+
if (!hideOnScroll) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (locationChangeEvent.location.hash) {
|
|
65
|
+
isFocusedAnchor.current = true;
|
|
66
|
+
setIsNavbarVisible(false);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
setIsNavbarVisible(true);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
navbarRef,
|
|
75
|
+
isNavbarVisible,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {useEffect} from 'react';
|
|
9
|
+
|
|
10
|
+
import './styles.css';
|
|
11
|
+
|
|
12
|
+
// This hook detect keyboard focus indicator to not show outline for mouse users
|
|
13
|
+
// Inspired by https://hackernoon.com/removing-that-ugly-focus-ring-and-keeping-it-too-6c8727fefcd2
|
|
14
|
+
export default function useKeyboardNavigation(): void {
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
const keyboardFocusedClassName = 'navigation-with-keyboard';
|
|
17
|
+
|
|
18
|
+
function handleOutlineStyles(e: MouseEvent | KeyboardEvent) {
|
|
19
|
+
if (e.type === 'keydown' && (e as KeyboardEvent).key === 'Tab') {
|
|
20
|
+
document.body.classList.add(keyboardFocusedClassName);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (e.type === 'mousedown') {
|
|
24
|
+
document.body.classList.remove(keyboardFocusedClassName);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
document.addEventListener('keydown', handleOutlineStyles);
|
|
29
|
+
document.addEventListener('mousedown', handleOutlineStyles);
|
|
30
|
+
|
|
31
|
+
return () => {
|
|
32
|
+
document.body.classList.remove(keyboardFocusedClassName);
|
|
33
|
+
document.removeEventListener('keydown', handleOutlineStyles);
|
|
34
|
+
document.removeEventListener('mousedown', handleOutlineStyles);
|
|
35
|
+
};
|
|
36
|
+
}, []);
|
|
37
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {useEffect} from 'react';
|
|
9
|
+
|
|
10
|
+
export default function useLockBodyScroll(lock: boolean = true): void {
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
document.body.style.overflow = lock ? 'hidden' : 'visible';
|
|
13
|
+
|
|
14
|
+
return () => {
|
|
15
|
+
document.body.style.overflow = 'visible';
|
|
16
|
+
};
|
|
17
|
+
}, [lock]);
|
|
18
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import defaultTheme from 'prism-react-renderer/themes/palenight';
|
|
9
|
+
import {useColorMode} from '../utils/colorModeUtils';
|
|
10
|
+
import {useThemeConfig} from '../utils/useThemeConfig';
|
|
11
|
+
|
|
12
|
+
export default function usePrismTheme(): typeof defaultTheme {
|
|
13
|
+
const {prism} = useThemeConfig();
|
|
14
|
+
const {isDarkTheme} = useColorMode();
|
|
15
|
+
const lightModeTheme = prism.theme || defaultTheme;
|
|
16
|
+
const darkModeTheme = prism.darkTheme || lightModeTheme;
|
|
17
|
+
const prismTheme = isDarkTheme ? darkModeTheme : lightModeTheme;
|
|
18
|
+
|
|
19
|
+
return prismTheme;
|
|
20
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {useHistory} from '@docusaurus/router';
|
|
9
|
+
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
10
|
+
import {useCallback, useEffect, useState} from 'react';
|
|
11
|
+
|
|
12
|
+
const SEARCH_PARAM_QUERY = 'q';
|
|
13
|
+
|
|
14
|
+
interface UseSearchPageReturn {
|
|
15
|
+
searchQuery: string;
|
|
16
|
+
setSearchQuery: (newSearchQuery: string) => void;
|
|
17
|
+
generateSearchPageLink: (targetSearchQuery: string) => string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default function useSearchPage(): UseSearchPageReturn {
|
|
21
|
+
const history = useHistory();
|
|
22
|
+
const {
|
|
23
|
+
siteConfig: {baseUrl},
|
|
24
|
+
} = useDocusaurusContext();
|
|
25
|
+
|
|
26
|
+
const [searchQuery, setSearchQueryState] = useState('');
|
|
27
|
+
|
|
28
|
+
// Init search query just after React hydration
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
const searchQueryStringValue =
|
|
31
|
+
new URLSearchParams(window.location.search).get(SEARCH_PARAM_QUERY) ?? '';
|
|
32
|
+
|
|
33
|
+
setSearchQueryState(searchQueryStringValue);
|
|
34
|
+
}, []);
|
|
35
|
+
|
|
36
|
+
const setSearchQuery = useCallback(
|
|
37
|
+
(newSearchQuery: string) => {
|
|
38
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
39
|
+
|
|
40
|
+
if (newSearchQuery) {
|
|
41
|
+
searchParams.set(SEARCH_PARAM_QUERY, newSearchQuery);
|
|
42
|
+
} else {
|
|
43
|
+
searchParams.delete(SEARCH_PARAM_QUERY);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
history.replace({
|
|
47
|
+
search: searchParams.toString(),
|
|
48
|
+
});
|
|
49
|
+
setSearchQueryState(newSearchQuery);
|
|
50
|
+
},
|
|
51
|
+
[history],
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const generateSearchPageLink = useCallback(
|
|
55
|
+
(targetSearchQuery: string) =>
|
|
56
|
+
// Refer to https://github.com/facebook/docusaurus/pull/2838
|
|
57
|
+
`${baseUrl}search?q=${encodeURIComponent(targetSearchQuery)}`,
|
|
58
|
+
[baseUrl],
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
searchQuery,
|
|
63
|
+
setSearchQuery,
|
|
64
|
+
generateSearchPageLink,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import {useEffect, useState} from 'react';
|
|
9
|
+
|
|
10
|
+
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
|
11
|
+
|
|
12
|
+
const windowSizes = {
|
|
13
|
+
desktop: 'desktop',
|
|
14
|
+
mobile: 'mobile',
|
|
15
|
+
|
|
16
|
+
// This "ssr" value is very important to handle hydration FOUC / layout shifts
|
|
17
|
+
// You have to handle server-rendering explicitly on the call-site
|
|
18
|
+
// On the server, you may need to render BOTH the mobile/desktop elements (and hide one of them with mediaquery)
|
|
19
|
+
// We don't return "undefined" on purpose, to make it more explicit
|
|
20
|
+
ssr: 'ssr',
|
|
21
|
+
} as const;
|
|
22
|
+
|
|
23
|
+
type WindowSize = keyof typeof windowSizes;
|
|
24
|
+
|
|
25
|
+
const DesktopThresholdWidth = 996;
|
|
26
|
+
|
|
27
|
+
function getWindowSize() {
|
|
28
|
+
if (!ExecutionEnvironment.canUseDOM) {
|
|
29
|
+
return windowSizes.ssr;
|
|
30
|
+
}
|
|
31
|
+
return window.innerWidth > DesktopThresholdWidth
|
|
32
|
+
? windowSizes.desktop
|
|
33
|
+
: windowSizes.mobile;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Simulate the SSR window size in dev, so that potential hydration FOUC/layout shift problems can be seen in dev too!
|
|
37
|
+
const DevSimulateSSR = process.env.NODE_ENV === 'development' && true;
|
|
38
|
+
|
|
39
|
+
// This hook returns an enum value on purpose!
|
|
40
|
+
// We don't want it to return the actual width value, for resize perf reasons
|
|
41
|
+
// We only want to re-render once a breakpoint is crossed
|
|
42
|
+
export default function useWindowSize(): WindowSize {
|
|
43
|
+
const [windowSize, setWindowSize] = useState<WindowSize>(() => {
|
|
44
|
+
if (DevSimulateSSR) {
|
|
45
|
+
return 'ssr';
|
|
46
|
+
}
|
|
47
|
+
return getWindowSize();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
function updateWindowSize() {
|
|
52
|
+
setWindowSize(getWindowSize());
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const timeout = DevSimulateSSR
|
|
56
|
+
? window.setTimeout(updateWindowSize, 1000)
|
|
57
|
+
: undefined;
|
|
58
|
+
|
|
59
|
+
window.addEventListener('resize', updateWindowSize);
|
|
60
|
+
|
|
61
|
+
return () => {
|
|
62
|
+
window.removeEventListener('resize', updateWindowSize);
|
|
63
|
+
clearTimeout(timeout);
|
|
64
|
+
};
|
|
65
|
+
}, []);
|
|
66
|
+
|
|
67
|
+
return windowSize;
|
|
68
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -114,3 +114,16 @@ export {
|
|
|
114
114
|
} from './utils/reactUtils';
|
|
115
115
|
|
|
116
116
|
export {isRegexpStringMatch} from './utils/regexpUtils';
|
|
117
|
+
|
|
118
|
+
export {useColorMode, ColorModeProvider} from './utils/colorModeUtils';
|
|
119
|
+
export {
|
|
120
|
+
useTabGroupChoice,
|
|
121
|
+
TabGroupChoiceProvider,
|
|
122
|
+
} from './utils/tabGroupChoiceUtils';
|
|
123
|
+
|
|
124
|
+
export {default as useHideableNavbar} from './hooks/useHideableNavbar';
|
|
125
|
+
export {default as useKeyboardNavigation} from './hooks/useKeyboardNavigation';
|
|
126
|
+
export {default as usePrismTheme} from './hooks/usePrismTheme';
|
|
127
|
+
export {default as useLockBodyScroll} from './hooks/useLockBodyScroll';
|
|
128
|
+
export {default as useWindowSize} from './hooks/useWindowSize';
|
|
129
|
+
export {default as useSearchPage} from './hooks/useSearchPage';
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type {ReactNode} from 'react';
|
|
9
|
+
import React, {
|
|
10
|
+
useState,
|
|
11
|
+
useCallback,
|
|
12
|
+
useEffect,
|
|
13
|
+
useContext,
|
|
14
|
+
useMemo,
|
|
15
|
+
} from 'react';
|
|
16
|
+
|
|
17
|
+
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
|
18
|
+
import {createStorageSlot} from './storageUtils';
|
|
19
|
+
import {useThemeConfig} from './useThemeConfig';
|
|
20
|
+
|
|
21
|
+
type ColorModeContextValue = {
|
|
22
|
+
readonly isDarkTheme: boolean;
|
|
23
|
+
readonly setLightTheme: () => void;
|
|
24
|
+
readonly setDarkTheme: () => void;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const ThemeStorage = createStorageSlot('theme');
|
|
28
|
+
|
|
29
|
+
const themes = {
|
|
30
|
+
light: 'light',
|
|
31
|
+
dark: 'dark',
|
|
32
|
+
} as const;
|
|
33
|
+
|
|
34
|
+
type Themes = typeof themes[keyof typeof themes];
|
|
35
|
+
|
|
36
|
+
// Ensure to always return a valid theme even if input is invalid
|
|
37
|
+
const coerceToTheme = (theme?: string | null): Themes =>
|
|
38
|
+
theme === themes.dark ? themes.dark : themes.light;
|
|
39
|
+
|
|
40
|
+
const getInitialTheme = (defaultMode: Themes | undefined): Themes => {
|
|
41
|
+
if (!ExecutionEnvironment.canUseDOM) {
|
|
42
|
+
return coerceToTheme(defaultMode);
|
|
43
|
+
}
|
|
44
|
+
return coerceToTheme(document.documentElement.getAttribute('data-theme'));
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const storeTheme = (newTheme: Themes) => {
|
|
48
|
+
createStorageSlot('theme').set(coerceToTheme(newTheme));
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
function useColorModeContextValue(): ColorModeContextValue {
|
|
52
|
+
const {
|
|
53
|
+
colorMode: {defaultMode, disableSwitch, respectPrefersColorScheme},
|
|
54
|
+
} = useThemeConfig();
|
|
55
|
+
const [theme, setTheme] = useState(getInitialTheme(defaultMode));
|
|
56
|
+
|
|
57
|
+
const setLightTheme = useCallback(() => {
|
|
58
|
+
setTheme(themes.light);
|
|
59
|
+
storeTheme(themes.light);
|
|
60
|
+
}, []);
|
|
61
|
+
const setDarkTheme = useCallback(() => {
|
|
62
|
+
setTheme(themes.dark);
|
|
63
|
+
storeTheme(themes.dark);
|
|
64
|
+
}, []);
|
|
65
|
+
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
document.documentElement.setAttribute('data-theme', coerceToTheme(theme));
|
|
68
|
+
}, [theme]);
|
|
69
|
+
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
if (disableSwitch) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
try {
|
|
76
|
+
const storedTheme = ThemeStorage.get();
|
|
77
|
+
if (storedTheme !== null) {
|
|
78
|
+
setTheme(coerceToTheme(storedTheme));
|
|
79
|
+
}
|
|
80
|
+
} catch (err) {
|
|
81
|
+
console.error(err);
|
|
82
|
+
}
|
|
83
|
+
}, [disableSwitch, setTheme]);
|
|
84
|
+
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
if (disableSwitch && !respectPrefersColorScheme) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
window
|
|
91
|
+
.matchMedia('(prefers-color-scheme: dark)')
|
|
92
|
+
.addListener(({matches}) => {
|
|
93
|
+
setTheme(matches ? themes.dark : themes.light);
|
|
94
|
+
});
|
|
95
|
+
}, [disableSwitch, respectPrefersColorScheme]);
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
isDarkTheme: theme === themes.dark,
|
|
99
|
+
setLightTheme,
|
|
100
|
+
setDarkTheme,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const ColorModeContext = React.createContext<ColorModeContextValue | undefined>(
|
|
105
|
+
undefined,
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
export function ColorModeProvider({
|
|
109
|
+
children,
|
|
110
|
+
}: {
|
|
111
|
+
children: ReactNode;
|
|
112
|
+
}): JSX.Element {
|
|
113
|
+
const {isDarkTheme, setLightTheme, setDarkTheme} = useColorModeContextValue();
|
|
114
|
+
const contextValue = useMemo(
|
|
115
|
+
() => ({isDarkTheme, setLightTheme, setDarkTheme}),
|
|
116
|
+
[isDarkTheme, setLightTheme, setDarkTheme],
|
|
117
|
+
);
|
|
118
|
+
return (
|
|
119
|
+
<ColorModeContext.Provider value={contextValue}>
|
|
120
|
+
{children}
|
|
121
|
+
</ColorModeContext.Provider>
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function useColorMode(): ColorModeContextValue {
|
|
126
|
+
const context = useContext<ColorModeContextValue | undefined>(
|
|
127
|
+
ColorModeContext,
|
|
128
|
+
);
|
|
129
|
+
if (context == null) {
|
|
130
|
+
throw new Error(
|
|
131
|
+
'"useColorMode()" is used outside of "Layout" component. Please see https://docusaurus.io/docs/api/themes/configuration#use-color-mode.',
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
return context;
|
|
135
|
+
}
|
|
@@ -16,7 +16,10 @@ import React, {
|
|
|
16
16
|
import {useThemeConfig, type DocsVersionPersistence} from '../useThemeConfig';
|
|
17
17
|
import {isDocsPluginEnabled} from '../docsUtils';
|
|
18
18
|
|
|
19
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
useAllDocsData,
|
|
21
|
+
type GlobalPluginData,
|
|
22
|
+
} from '@docusaurus/plugin-content-docs/client';
|
|
20
23
|
|
|
21
24
|
import DocsPreferredVersionStorage from './DocsPreferredVersionStorage';
|
|
22
25
|
|
package/src/utils/docsUtils.tsx
CHANGED