@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
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import React, {
|
|
9
|
+
useState,
|
|
10
|
+
useCallback,
|
|
11
|
+
useEffect,
|
|
12
|
+
createContext,
|
|
13
|
+
useMemo,
|
|
14
|
+
useContext,
|
|
15
|
+
type ReactNode,
|
|
16
|
+
} from 'react';
|
|
17
|
+
import {createStorageSlot, listStorageKeys} from './storageUtils';
|
|
18
|
+
|
|
19
|
+
const TAB_CHOICE_PREFIX = 'docusaurus.tab.';
|
|
20
|
+
|
|
21
|
+
type TabGroupChoiceContextValue = {
|
|
22
|
+
readonly tabGroupChoices: {readonly [groupId: string]: string};
|
|
23
|
+
readonly setTabGroupChoices: (groupId: string, newChoice: string) => void;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const TabGroupChoiceContext = createContext<
|
|
27
|
+
TabGroupChoiceContextValue | undefined
|
|
28
|
+
>(undefined);
|
|
29
|
+
|
|
30
|
+
function useTabGroupChoiceContextValue(): TabGroupChoiceContextValue {
|
|
31
|
+
const [tabGroupChoices, setChoices] = useState<{
|
|
32
|
+
readonly [groupId: string]: string;
|
|
33
|
+
}>({});
|
|
34
|
+
const setChoiceSyncWithLocalStorage = useCallback((groupId, newChoice) => {
|
|
35
|
+
createStorageSlot(`${TAB_CHOICE_PREFIX}${groupId}`).set(newChoice);
|
|
36
|
+
}, []);
|
|
37
|
+
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
try {
|
|
40
|
+
const localStorageChoices: Record<string, string> = {};
|
|
41
|
+
listStorageKeys().forEach((storageKey) => {
|
|
42
|
+
if (storageKey.startsWith(TAB_CHOICE_PREFIX)) {
|
|
43
|
+
const groupId = storageKey.substring(TAB_CHOICE_PREFIX.length);
|
|
44
|
+
localStorageChoices[groupId] = createStorageSlot(storageKey).get()!;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
setChoices(localStorageChoices);
|
|
48
|
+
} catch (err) {
|
|
49
|
+
console.error(err);
|
|
50
|
+
}
|
|
51
|
+
}, []);
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
tabGroupChoices,
|
|
55
|
+
setTabGroupChoices: (groupId: string, newChoice: string) => {
|
|
56
|
+
setChoices((oldChoices) => ({...oldChoices, [groupId]: newChoice}));
|
|
57
|
+
setChoiceSyncWithLocalStorage(groupId, newChoice);
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function TabGroupChoiceProvider({
|
|
63
|
+
children,
|
|
64
|
+
}: {
|
|
65
|
+
children: ReactNode;
|
|
66
|
+
}): JSX.Element {
|
|
67
|
+
const {tabGroupChoices, setTabGroupChoices} = useTabGroupChoiceContextValue();
|
|
68
|
+
const contextValue = useMemo(
|
|
69
|
+
() => ({
|
|
70
|
+
tabGroupChoices,
|
|
71
|
+
setTabGroupChoices,
|
|
72
|
+
}),
|
|
73
|
+
[tabGroupChoices, setTabGroupChoices],
|
|
74
|
+
);
|
|
75
|
+
return (
|
|
76
|
+
<TabGroupChoiceContext.Provider value={contextValue}>
|
|
77
|
+
{children}
|
|
78
|
+
</TabGroupChoiceContext.Provider>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function useTabGroupChoice(): TabGroupChoiceContextValue {
|
|
83
|
+
const context = useContext(TabGroupChoiceContext);
|
|
84
|
+
if (context == null) {
|
|
85
|
+
throw new Error(
|
|
86
|
+
'"useUserPreferencesContext" is used outside of "Layout" component.',
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
return context;
|
|
90
|
+
}
|
|
@@ -5,7 +5,10 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
useAllDocsData,
|
|
10
|
+
useActivePluginAndVersion,
|
|
11
|
+
} from '@docusaurus/plugin-content-docs/client';
|
|
9
12
|
import {useDocsPreferredVersionByPluginId} from './docsPreferredVersion/useDocsPreferredVersion';
|
|
10
13
|
import {docVersionSearchTag, DEFAULT_SEARCH_TAG} from './searchUtils';
|
|
11
14
|
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|