@docusaurus/theme-common 2.0.0-beta.14 → 2.0.0-beta.15
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 +1 -1
- package/lib/components/Collapsible/index.d.ts.map +1 -1
- package/lib/components/Collapsible/index.js +1 -1
- package/lib/components/Collapsible/index.js.map +1 -1
- package/lib/components/Details/index.d.ts +1 -1
- package/lib/components/Details/index.d.ts.map +1 -1
- package/lib/components/Details/index.js +1 -1
- package/lib/components/Details/index.js.map +1 -1
- package/lib/components/Details/styles.module.css +4 -4
- 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 +9 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +9 -0
- package/lib/index.js.map +1 -1
- package/lib/utils/ThemeClassNames.d.ts +1 -0
- package/lib/utils/ThemeClassNames.d.ts.map +1 -1
- package/lib/utils/ThemeClassNames.js +1 -0
- package/lib/utils/ThemeClassNames.js.map +1 -1
- package/lib/utils/announcementBarUtils.d.ts +1 -1
- package/lib/utils/announcementBarUtils.d.ts.map +1 -1
- package/lib/utils/announcementBarUtils.js +2 -1
- package/lib/utils/announcementBarUtils.js.map +1 -1
- package/lib/utils/codeBlockUtils.d.ts +2 -3
- package/lib/utils/codeBlockUtils.d.ts.map +1 -1
- package/lib/utils/codeBlockUtils.js +3 -1
- package/lib/utils/codeBlockUtils.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/docSidebarItemsExpandedState.d.ts +17 -0
- package/lib/utils/docSidebarItemsExpandedState.d.ts.map +1 -0
- package/lib/utils/docSidebarItemsExpandedState.js +22 -0
- package/lib/utils/docSidebarItemsExpandedState.js.map +1 -0
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.d.ts.map +1 -1
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js +2 -2
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js.map +1 -1
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.d.ts +1 -1
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.d.ts.map +1 -1
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.d.ts +1 -1
- 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.d.ts +2 -2
- package/lib/utils/docsUtils.d.ts.map +1 -1
- package/lib/utils/docsUtils.js +1 -1
- package/lib/utils/docsUtils.js.map +1 -1
- package/lib/utils/mobileSecondaryMenu.d.ts +1 -1
- package/lib/utils/mobileSecondaryMenu.d.ts.map +1 -1
- package/lib/utils/mobileSecondaryMenu.js +1 -1
- package/lib/utils/mobileSecondaryMenu.js.map +1 -1
- package/lib/utils/regexpUtils.d.ts +1 -1
- package/lib/utils/regexpUtils.js +1 -1
- package/lib/utils/scrollUtils.d.ts +1 -1
- package/lib/utils/scrollUtils.d.ts.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/tocUtils.d.ts +1 -1
- package/lib/utils/tocUtils.d.ts.map +1 -1
- 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/lib/utils/useLocationChange.d.ts +1 -1
- package/lib/utils/useLocationChange.d.ts.map +1 -1
- package/lib/utils/useTOCHighlight.d.ts.map +1 -1
- package/lib/utils/useTOCHighlight.js +1 -0
- package/lib/utils/useTOCHighlight.js.map +1 -1
- package/lib/utils/useThemeConfig.d.ts +4 -3
- package/lib/utils/useThemeConfig.d.ts.map +1 -1
- package/lib/utils/useThemeConfig.js.map +1 -1
- package/package.json +11 -11
- package/src/components/Collapsible/index.tsx +5 -5
- package/src/components/Details/index.tsx +6 -1
- package/src/components/Details/styles.module.css +4 -4
- 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 +17 -0
- package/src/utils/ThemeClassNames.ts +1 -0
- package/src/utils/announcementBarUtils.tsx +3 -2
- package/src/utils/codeBlockUtils.ts +4 -5
- package/src/utils/colorModeUtils.tsx +135 -0
- package/src/utils/docSidebarItemsExpandedState.tsx +41 -0
- package/src/utils/docsPreferredVersion/DocsPreferredVersionProvider.tsx +7 -4
- package/src/utils/docsPreferredVersion/DocsPreferredVersionStorage.ts +1 -1
- package/src/utils/docsPreferredVersion/useDocsPreferredVersion.ts +5 -1
- package/src/utils/docsUtils.tsx +3 -3
- package/src/utils/mobileSecondaryMenu.tsx +3 -3
- package/src/utils/regexpUtils.ts +1 -1
- package/src/utils/scrollUtils.tsx +1 -1
- package/src/utils/tabGroupChoiceUtils.tsx +90 -0
- package/src/utils/tocUtils.ts +1 -1
- package/src/utils/useContextualSearchFilters.ts +4 -1
- package/src/utils/useLocationChange.ts +1 -1
- package/src/utils/useTOCHighlight.ts +1 -0
- package/src/utils/useThemeConfig.ts +4 -3
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
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, {type ReactNode, useMemo, useState, useContext} from 'react';
|
|
9
|
+
|
|
10
|
+
const EmptyContext: unique symbol = Symbol('EmptyContext');
|
|
11
|
+
const Context = React.createContext<
|
|
12
|
+
DocSidebarItemsExpandedState | typeof EmptyContext
|
|
13
|
+
>(EmptyContext);
|
|
14
|
+
type DocSidebarItemsExpandedState = {
|
|
15
|
+
expandedItem: number | null;
|
|
16
|
+
setExpandedItem: (a: number | null) => void;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export function DocSidebarItemsExpandedStateProvider({
|
|
20
|
+
children,
|
|
21
|
+
}: {
|
|
22
|
+
children: ReactNode;
|
|
23
|
+
}): JSX.Element {
|
|
24
|
+
const [expandedItem, setExpandedItem] = useState<number | null>(null);
|
|
25
|
+
const contextValue = useMemo(
|
|
26
|
+
() => ({expandedItem, setExpandedItem}),
|
|
27
|
+
[expandedItem],
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
return <Context.Provider value={contextValue}>{children}</Context.Provider>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function useDocSidebarItemsExpandedState(): DocSidebarItemsExpandedState {
|
|
34
|
+
const contextValue = useContext(Context);
|
|
35
|
+
if (contextValue === EmptyContext) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
'This hook requires usage of <DocSidebarItemsExpandedStateProvider>',
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
return contextValue;
|
|
41
|
+
}
|
|
@@ -7,16 +7,19 @@
|
|
|
7
7
|
|
|
8
8
|
import React, {
|
|
9
9
|
createContext,
|
|
10
|
-
ReactNode,
|
|
10
|
+
type ReactNode,
|
|
11
11
|
useContext,
|
|
12
12
|
useEffect,
|
|
13
13
|
useMemo,
|
|
14
14
|
useState,
|
|
15
15
|
} from 'react';
|
|
16
|
-
import {useThemeConfig, DocsVersionPersistence} from '../useThemeConfig';
|
|
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
|
|
|
@@ -35,7 +38,7 @@ type DocsPreferredVersionState = Record<
|
|
|
35
38
|
DocsPreferredVersionPluginState
|
|
36
39
|
>;
|
|
37
40
|
|
|
38
|
-
// Initial state is always null as we can't read
|
|
41
|
+
// Initial state is always null as we can't read local storage from node SSR
|
|
39
42
|
function getInitialState(pluginIds: string[]): DocsPreferredVersionState {
|
|
40
43
|
const initialState: DocsPreferredVersionState = {};
|
|
41
44
|
pluginIds.forEach((pluginId) => {
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import {createStorageSlot} from '../storageUtils';
|
|
9
|
-
import {DocsVersionPersistence} from '../useThemeConfig';
|
|
9
|
+
import type {DocsVersionPersistence} from '../useThemeConfig';
|
|
10
10
|
|
|
11
11
|
const storageKey = (pluginId: string) => `docs-preferred-version-${pluginId}`;
|
|
12
12
|
|
|
@@ -7,7 +7,11 @@
|
|
|
7
7
|
|
|
8
8
|
import {useCallback} from 'react';
|
|
9
9
|
import {useDocsPreferredVersionContext} from './DocsPreferredVersionProvider';
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
useAllDocsData,
|
|
12
|
+
useDocsData,
|
|
13
|
+
type GlobalVersion,
|
|
14
|
+
} from '@docusaurus/plugin-content-docs/client';
|
|
11
15
|
|
|
12
16
|
import {DEFAULT_PLUGIN_ID} from '@docusaurus/constants';
|
|
13
17
|
|
package/src/utils/docsUtils.tsx
CHANGED
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import React, {createContext, ReactNode, useContext} from 'react';
|
|
9
|
-
import {useAllDocsData} from '@
|
|
10
|
-
import {
|
|
8
|
+
import React, {createContext, type ReactNode, useContext} from 'react';
|
|
9
|
+
import {useAllDocsData} from '@docusaurus/plugin-content-docs/client';
|
|
10
|
+
import type {
|
|
11
11
|
PropSidebar,
|
|
12
12
|
PropSidebarItem,
|
|
13
13
|
PropSidebarItemCategory,
|
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
|
|
8
8
|
import React, {
|
|
9
9
|
useState,
|
|
10
|
-
ReactNode,
|
|
10
|
+
type ReactNode,
|
|
11
11
|
useContext,
|
|
12
12
|
createContext,
|
|
13
13
|
useEffect,
|
|
14
|
-
ComponentType,
|
|
14
|
+
type ComponentType,
|
|
15
15
|
useMemo,
|
|
16
16
|
} from 'react';
|
|
17
17
|
|
|
@@ -104,7 +104,7 @@ export function MobileSecondaryMenuFiller<
|
|
|
104
104
|
const memoizedProps = useShallowMemoizedObject(props);
|
|
105
105
|
|
|
106
106
|
useEffect(() => {
|
|
107
|
-
// @ts-expect-error: context is not 100%
|
|
107
|
+
// @ts-expect-error: context is not 100% type-safe but it's ok
|
|
108
108
|
setState({component, props: memoizedProps});
|
|
109
109
|
}, [setState, component, memoizedProps]);
|
|
110
110
|
|
package/src/utils/regexpUtils.ts
CHANGED
|
@@ -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
|
+
}
|
package/src/utils/tocUtils.ts
CHANGED
|
@@ -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';
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import {useEffect} from 'react';
|
|
9
9
|
import {useLocation} from '@docusaurus/router';
|
|
10
|
-
import {Location} from '@docusaurus/history';
|
|
10
|
+
import type {Location} from '@docusaurus/history';
|
|
11
11
|
import {usePrevious} from './usePrevious';
|
|
12
12
|
import {useDynamicCallback} from './reactUtils';
|
|
13
13
|
|
|
@@ -144,6 +144,7 @@ function useTOCHighlight(config: TOCHighlightConfig | undefined): void {
|
|
|
144
144
|
}
|
|
145
145
|
link.classList.add(linkActiveClassName);
|
|
146
146
|
lastActiveLinkRef.current = link;
|
|
147
|
+
link.scrollIntoView({block: 'nearest'});
|
|
147
148
|
} else {
|
|
148
149
|
link.classList.remove(linkActiveClassName);
|
|
149
150
|
}
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
9
|
-
import {PrismTheme} from 'prism-react-renderer';
|
|
10
|
-
import {CSSProperties} from 'react';
|
|
11
|
-
import {DeepPartial} from 'utility-types';
|
|
9
|
+
import type {PrismTheme} from 'prism-react-renderer';
|
|
10
|
+
import type {CSSProperties} from 'react';
|
|
11
|
+
import type {DeepPartial} from 'utility-types';
|
|
12
12
|
|
|
13
13
|
export type DocsVersionPersistence = 'localStorage' | 'none';
|
|
14
14
|
|
|
@@ -122,6 +122,7 @@ export type ThemeConfig = {
|
|
|
122
122
|
prism: PrismConfig;
|
|
123
123
|
footer?: Footer;
|
|
124
124
|
hideableSidebar: boolean;
|
|
125
|
+
autoCollapseSidebarCategories: boolean;
|
|
125
126
|
image?: string;
|
|
126
127
|
metadata: Array<Record<string, string>>;
|
|
127
128
|
sidebarCollapsible: boolean;
|