@docusaurus/theme-classic 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/README.md +1 -1
- package/lib/index.js +7 -16
- package/lib/theme-classic.d.ts +89 -182
- package/lib/validateThemeConfig.js +13 -1
- package/lib-next/theme/BackToTopButton/styles.module.css +1 -1
- package/lib-next/theme/BlogListPaginator/index.js +12 -12
- package/lib-next/theme/BlogPostAuthor/index.js +1 -1
- package/lib-next/theme/BlogPostAuthors/index.js +12 -2
- package/lib-next/theme/BlogPostAuthors/styles.module.css +10 -0
- package/lib-next/theme/BlogPostItem/index.js +12 -15
- package/lib-next/theme/BlogPostPage/index.js +10 -7
- package/lib-next/theme/BlogPostPaginator/index.js +11 -15
- package/lib-next/theme/BlogSidebar/styles.module.css +2 -0
- package/lib-next/theme/CodeBlock/index.js +44 -9
- package/lib-next/theme/CodeBlock/styles.module.css +12 -7
- package/lib-next/theme/DocCard/styles.module.css +3 -3
- package/lib-next/theme/DocCategoryGeneratedIndexPage/index.js +6 -3
- package/lib-next/theme/DocItem/index.js +9 -6
- package/lib-next/theme/DocItem/styles.module.css +2 -2
- package/lib-next/theme/DocPage/index.js +7 -3
- package/lib-next/theme/DocPage/styles.module.css +1 -0
- package/lib-next/theme/DocPaginator/index.js +26 -4
- package/lib-next/theme/DocSidebar/index.js +2 -2
- package/lib-next/theme/DocSidebar/styles.module.css +1 -0
- package/lib-next/theme/DocSidebarItem/index.js +43 -21
- package/lib-next/theme/DocSidebarItem/styles.module.css +1 -0
- package/lib-next/theme/DocSidebarItems/index.js +28 -0
- package/{src/theme/hooks/styles.css → lib-next/theme/DocSidebarItems/styles.module.css} +12 -2
- package/lib-next/theme/DocVersionBanner/index.js +4 -1
- package/lib-next/theme/Footer/styles.module.css +2 -1
- package/lib-next/theme/Heading/index.js +39 -42
- package/lib-next/theme/Heading/styles.css +1 -1
- package/lib-next/theme/Layout/index.js +1 -2
- package/lib-next/theme/LayoutHead/index.js +5 -9
- package/lib-next/theme/LayoutProviders/index.js +6 -6
- package/lib-next/theme/MDXComponents/index.js +18 -31
- package/lib-next/theme/MDXComponents/styles.css +4 -0
- package/lib-next/theme/MDXPage/index.js +3 -10
- package/lib-next/theme/Navbar/index.js +6 -6
- package/lib-next/theme/NavbarItem/DefaultNavbarItem.js +4 -66
- package/lib-next/theme/NavbarItem/DocNavbarItem.js +5 -2
- package/lib-next/theme/NavbarItem/DocSidebarNavbarItem.js +73 -0
- package/lib-next/theme/NavbarItem/DocsVersionDropdownNavbarItem.js +5 -3
- package/lib-next/theme/NavbarItem/DocsVersionNavbarItem.js +4 -1
- package/lib-next/theme/NavbarItem/DropdownNavbarItem.js +5 -5
- package/lib-next/theme/NavbarItem/NavbarNavLink.js +70 -0
- package/lib-next/theme/NavbarItem/index.js +1 -2
- package/lib-next/theme/{hooks/styles.css → NavbarItem/utils.js} +3 -4
- package/lib-next/theme/PaginatorNavLink/index.js +20 -0
- package/lib-next/theme/SkipToContent/index.js +1 -1
- package/lib-next/theme/SkipToContent/styles.module.css +7 -0
- package/lib-next/theme/TOCCollapsible/styles.module.css +2 -2
- package/lib-next/theme/Tabs/__tests__/index.test.js +8 -6
- package/lib-next/theme/Tabs/index.js +6 -3
- package/lib-next/theme/Tag/styles.module.css +4 -4
- package/lib-next/theme/ThemedImage/index.js +2 -2
- package/lib-next/theme/Toggle/styles.module.css +16 -15
- package/lib-next/theme/prism-include-languages.js +10 -3
- package/package.json +16 -17
- package/src/index.ts +10 -21
- package/src/theme/Admonition/index.tsx +1 -1
- package/src/theme/BackToTopButton/styles.module.css +1 -1
- package/src/theme/BlogListPaginator/index.tsx +12 -12
- package/src/theme/BlogPostAuthor/index.tsx +1 -1
- package/src/theme/BlogPostAuthors/index.tsx +12 -2
- package/src/theme/BlogPostAuthors/styles.module.css +10 -0
- package/src/theme/BlogPostItem/index.tsx +13 -15
- package/src/theme/BlogPostPage/index.tsx +10 -7
- package/src/theme/BlogPostPaginator/index.tsx +11 -15
- package/src/theme/BlogSidebar/styles.module.css +2 -0
- package/src/theme/CodeBlock/index.tsx +45 -10
- package/src/theme/CodeBlock/styles.module.css +12 -7
- package/src/theme/DocCard/index.tsx +2 -2
- package/src/theme/DocCard/styles.module.css +3 -3
- package/src/theme/DocCardList/index.tsx +1 -1
- package/src/theme/DocCategoryGeneratedIndexPage/index.tsx +7 -3
- package/src/theme/DocItem/index.tsx +9 -6
- package/src/theme/DocItem/styles.module.css +2 -2
- package/src/theme/DocItemFooter/index.tsx +1 -1
- package/src/theme/DocPage/index.tsx +8 -4
- package/src/theme/DocPage/styles.module.css +1 -0
- package/src/theme/DocPaginator/index.tsx +26 -4
- package/src/theme/DocSidebar/index.tsx +3 -3
- package/src/theme/DocSidebar/styles.module.css +1 -0
- package/src/theme/DocSidebarItem/index.tsx +34 -23
- package/src/theme/DocSidebarItem/styles.module.css +1 -0
- package/src/theme/DocSidebarItems/index.tsx +32 -0
- package/src/theme/{UserPreferencesContext.ts → DocSidebarItems/styles.module.css} +11 -3
- package/src/theme/DocVersionBanner/index.tsx +3 -3
- package/src/theme/Footer/index.tsx +4 -4
- package/src/theme/Footer/styles.module.css +2 -1
- package/src/theme/Heading/index.tsx +39 -46
- package/src/theme/Heading/styles.css +1 -1
- package/src/theme/Layout/index.tsx +1 -2
- package/src/theme/LayoutHead/index.tsx +4 -8
- package/src/theme/LayoutProviders/index.tsx +6 -6
- package/src/theme/MDXComponents/index.tsx +26 -37
- package/src/theme/MDXComponents/styles.css +4 -0
- package/src/theme/MDXPage/index.tsx +3 -11
- package/src/theme/Navbar/index.tsx +7 -7
- package/src/theme/NavbarItem/DefaultNavbarItem.tsx +6 -62
- package/src/theme/NavbarItem/DocNavbarItem.tsx +8 -5
- package/src/theme/NavbarItem/DocSidebarNavbarItem.tsx +84 -0
- package/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx +9 -6
- package/src/theme/NavbarItem/DocsVersionNavbarItem.tsx +2 -2
- package/src/theme/NavbarItem/DropdownNavbarItem.tsx +5 -5
- package/src/theme/NavbarItem/NavbarNavLink.tsx +68 -0
- package/src/theme/NavbarItem/index.tsx +3 -5
- package/{lib-next/theme/UserPreferencesContext.js → src/theme/NavbarItem/utils.ts} +4 -3
- package/src/theme/PaginatorNavLink/index.tsx +22 -0
- package/src/theme/SkipToContent/index.tsx +1 -1
- package/src/theme/SkipToContent/styles.module.css +7 -0
- package/src/theme/TOCCollapsible/styles.module.css +2 -2
- package/src/theme/TOCItems/index.tsx +2 -2
- package/src/theme/Tabs/index.tsx +7 -4
- package/src/theme/Tag/styles.module.css +4 -4
- package/src/theme/TagsListByLetter/index.tsx +1 -1
- package/src/theme/ThemedImage/index.tsx +2 -2
- package/src/theme/Toggle/index.tsx +1 -1
- package/src/theme/Toggle/styles.module.css +16 -15
- package/src/theme/prism-include-languages.ts +10 -3
- package/src/theme-classic.d.ts +89 -182
- package/src/translations.ts +2 -2
- package/src/validateThemeConfig.ts +16 -0
- package/lib-next/theme/DocPaginatorNavLink/index.js +0 -36
- package/lib-next/theme/ThemeContext.js +0 -9
- package/lib-next/theme/ThemeProvider/index.js +0 -28
- package/lib-next/theme/UserPreferencesProvider/index.js +0 -27
- package/lib-next/theme/hooks/useDocs.js +0 -10
- package/lib-next/theme/hooks/useHideableNavbar.js +0 -66
- package/lib-next/theme/hooks/useKeyboardNavigation.js +0 -35
- package/lib-next/theme/hooks/useLockBodyScroll.js +0 -18
- package/lib-next/theme/hooks/usePrismTheme.js +0 -20
- package/lib-next/theme/hooks/useTabGroupChoice.js +0 -39
- package/lib-next/theme/hooks/useTheme.js +0 -81
- package/lib-next/theme/hooks/useThemeContext.js +0 -22
- package/lib-next/theme/hooks/useUserPreferencesContext.js +0 -22
- package/lib-next/theme/hooks/useWindowSize.js +0 -59
- package/src/theme/DocPaginatorNavLink/index.tsx +0 -38
- package/src/theme/ThemeContext.ts +0 -15
- package/src/theme/ThemeProvider/index.tsx +0 -28
- package/src/theme/UserPreferencesProvider/index.tsx +0 -30
- package/src/theme/hooks/useDocs.ts +0 -11
- package/src/theme/hooks/useHideableNavbar.ts +0 -72
- package/src/theme/hooks/useKeyboardNavigation.ts +0 -39
- package/src/theme/hooks/useLockBodyScroll.ts +0 -20
- package/src/theme/hooks/usePrismTheme.ts +0 -22
- package/src/theme/hooks/useTabGroupChoice.ts +0 -46
- package/src/theme/hooks/useTheme.ts +0 -91
- package/src/theme/hooks/useThemeContext.ts +0 -23
- package/src/theme/hooks/useUserPreferencesContext.ts +0 -25
- package/src/theme/hooks/useWindowSize.ts +0 -69
|
@@ -1,35 +0,0 @@
|
|
|
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'; // This hook detect keyboard focus indicator to not show outline for mouse users
|
|
9
|
-
// Inspired by https://hackernoon.com/removing-that-ugly-focus-ring-and-keeping-it-too-6c8727fefcd2
|
|
10
|
-
|
|
11
|
-
function useKeyboardNavigation() {
|
|
12
|
-
useEffect(() => {
|
|
13
|
-
const keyboardFocusedClassName = 'navigation-with-keyboard';
|
|
14
|
-
|
|
15
|
-
function handleOutlineStyles(e) {
|
|
16
|
-
if (e.type === 'keydown' && e.key === 'Tab') {
|
|
17
|
-
document.body.classList.add(keyboardFocusedClassName);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (e.type === 'mousedown') {
|
|
21
|
-
document.body.classList.remove(keyboardFocusedClassName);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
document.addEventListener('keydown', handleOutlineStyles);
|
|
26
|
-
document.addEventListener('mousedown', handleOutlineStyles);
|
|
27
|
-
return () => {
|
|
28
|
-
document.body.classList.remove(keyboardFocusedClassName);
|
|
29
|
-
document.removeEventListener('keydown', handleOutlineStyles);
|
|
30
|
-
document.removeEventListener('mousedown', handleOutlineStyles);
|
|
31
|
-
};
|
|
32
|
-
}, []);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export default useKeyboardNavigation;
|
|
@@ -1,18 +0,0 @@
|
|
|
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
|
-
function useLockBodyScroll(lock = true) {
|
|
10
|
-
useEffect(() => {
|
|
11
|
-
document.body.style.overflow = lock ? 'hidden' : 'visible';
|
|
12
|
-
return () => {
|
|
13
|
-
document.body.style.overflow = 'visible';
|
|
14
|
-
};
|
|
15
|
-
}, [lock]);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export default useLockBodyScroll;
|
|
@@ -1,20 +0,0 @@
|
|
|
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 useThemeContext from '@theme/hooks/useThemeContext';
|
|
9
|
-
import {useThemeConfig} from '@docusaurus/theme-common';
|
|
10
|
-
|
|
11
|
-
const usePrismTheme = () => {
|
|
12
|
-
const {prism} = useThemeConfig();
|
|
13
|
-
const {isDarkTheme} = useThemeContext();
|
|
14
|
-
const lightModeTheme = prism.theme || defaultTheme;
|
|
15
|
-
const darkModeTheme = prism.darkTheme || lightModeTheme;
|
|
16
|
-
const prismTheme = isDarkTheme ? darkModeTheme : lightModeTheme;
|
|
17
|
-
return prismTheme;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export default usePrismTheme;
|
|
@@ -1,39 +0,0 @@
|
|
|
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, useEffect} from 'react';
|
|
8
|
-
import {createStorageSlot, listStorageKeys} from '@docusaurus/theme-common';
|
|
9
|
-
const TAB_CHOICE_PREFIX = 'docusaurus.tab.';
|
|
10
|
-
|
|
11
|
-
const useTabGroupChoice = () => {
|
|
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
|
-
} catch (err) {
|
|
27
|
-
console.error(err);
|
|
28
|
-
}
|
|
29
|
-
}, []);
|
|
30
|
-
return {
|
|
31
|
-
tabGroupChoices,
|
|
32
|
-
setTabGroupChoices: (groupId, newChoice) => {
|
|
33
|
-
setChoices((oldChoices) => ({...oldChoices, [groupId]: newChoice}));
|
|
34
|
-
setChoiceSyncWithLocalStorage(groupId, newChoice);
|
|
35
|
-
},
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export default useTabGroupChoice;
|
|
@@ -1,81 +0,0 @@
|
|
|
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, useEffect} from 'react';
|
|
8
|
-
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
|
9
|
-
import {useThemeConfig, createStorageSlot} from '@docusaurus/theme-common';
|
|
10
|
-
const ThemeStorage = createStorageSlot('theme');
|
|
11
|
-
const themes = {
|
|
12
|
-
light: 'light',
|
|
13
|
-
dark: 'dark',
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
// Ensure to always return a valid theme even if input is invalid
|
|
17
|
-
const coerceToTheme = (theme) =>
|
|
18
|
-
theme === themes.dark ? themes.dark : themes.light;
|
|
19
|
-
|
|
20
|
-
const getInitialTheme = (defaultMode) => {
|
|
21
|
-
if (!ExecutionEnvironment.canUseDOM) {
|
|
22
|
-
return coerceToTheme(defaultMode);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return coerceToTheme(document.documentElement.getAttribute('data-theme'));
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const storeTheme = (newTheme) => {
|
|
29
|
-
createStorageSlot('theme').set(coerceToTheme(newTheme));
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const useTheme = () => {
|
|
33
|
-
const {
|
|
34
|
-
colorMode: {defaultMode, disableSwitch, respectPrefersColorScheme},
|
|
35
|
-
} = useThemeConfig();
|
|
36
|
-
const [theme, setTheme] = useState(getInitialTheme(defaultMode));
|
|
37
|
-
const setLightTheme = useCallback(() => {
|
|
38
|
-
setTheme(themes.light);
|
|
39
|
-
storeTheme(themes.light);
|
|
40
|
-
}, []);
|
|
41
|
-
const setDarkTheme = useCallback(() => {
|
|
42
|
-
setTheme(themes.dark);
|
|
43
|
-
storeTheme(themes.dark);
|
|
44
|
-
}, []);
|
|
45
|
-
useEffect(() => {
|
|
46
|
-
document.documentElement.setAttribute('data-theme', coerceToTheme(theme));
|
|
47
|
-
}, [theme]);
|
|
48
|
-
useEffect(() => {
|
|
49
|
-
if (disableSwitch) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
try {
|
|
54
|
-
const storedTheme = ThemeStorage.get();
|
|
55
|
-
|
|
56
|
-
if (storedTheme !== null) {
|
|
57
|
-
setTheme(coerceToTheme(storedTheme));
|
|
58
|
-
}
|
|
59
|
-
} catch (err) {
|
|
60
|
-
console.error(err);
|
|
61
|
-
}
|
|
62
|
-
}, [disableSwitch, setTheme]);
|
|
63
|
-
useEffect(() => {
|
|
64
|
-
if (disableSwitch && !respectPrefersColorScheme) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
window
|
|
69
|
-
.matchMedia('(prefers-color-scheme: dark)')
|
|
70
|
-
.addListener(({matches}) => {
|
|
71
|
-
setTheme(matches ? themes.dark : themes.light);
|
|
72
|
-
});
|
|
73
|
-
}, [disableSwitch, respectPrefersColorScheme]);
|
|
74
|
-
return {
|
|
75
|
-
isDarkTheme: theme === themes.dark,
|
|
76
|
-
setLightTheme,
|
|
77
|
-
setDarkTheme,
|
|
78
|
-
};
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
export default useTheme;
|
|
@@ -1,22 +0,0 @@
|
|
|
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 {useContext} from 'react';
|
|
8
|
-
import ThemeContext from '@theme/ThemeContext';
|
|
9
|
-
|
|
10
|
-
function useThemeContext() {
|
|
11
|
-
const context = useContext(ThemeContext);
|
|
12
|
-
|
|
13
|
-
if (context == null) {
|
|
14
|
-
throw new Error(
|
|
15
|
-
'"useThemeContext" is used outside of "Layout" component. Please see https://docusaurus.io/docs/api/themes/configuration#usethemecontext.',
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return context;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export default useThemeContext;
|
|
@@ -1,22 +0,0 @@
|
|
|
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 {useContext} from 'react';
|
|
8
|
-
import UserPreferencesContext from '@theme/UserPreferencesContext';
|
|
9
|
-
|
|
10
|
-
function useUserPreferencesContext() {
|
|
11
|
-
const context = useContext(UserPreferencesContext);
|
|
12
|
-
|
|
13
|
-
if (context == null) {
|
|
14
|
-
throw new Error(
|
|
15
|
-
'"useUserPreferencesContext" is used outside of "Layout" component.',
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return context;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export default useUserPreferencesContext;
|
|
@@ -1,59 +0,0 @@
|
|
|
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, useState} from 'react';
|
|
8
|
-
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
|
9
|
-
const windowSizes = {
|
|
10
|
-
desktop: 'desktop',
|
|
11
|
-
mobile: 'mobile',
|
|
12
|
-
// This "ssr" value is very important to handle hydration FOUC / layout shifts
|
|
13
|
-
// You have to handle server-rendering explicitly on the call-site
|
|
14
|
-
// On the server, you may need to render BOTH the mobile/desktop elements (and hide one of them with mediaquery)
|
|
15
|
-
// We don't return "undefined" on purpose, to make it more explicit
|
|
16
|
-
ssr: 'ssr',
|
|
17
|
-
};
|
|
18
|
-
const DesktopThresholdWidth = 996;
|
|
19
|
-
|
|
20
|
-
function getWindowSize() {
|
|
21
|
-
if (!ExecutionEnvironment.canUseDOM) {
|
|
22
|
-
return windowSizes.ssr;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return window.innerWidth > DesktopThresholdWidth
|
|
26
|
-
? windowSizes.desktop
|
|
27
|
-
: windowSizes.mobile;
|
|
28
|
-
} // Simulate the SSR window size in dev, so that potential hydration FOUC/layout shift problems can be seen in dev too!
|
|
29
|
-
|
|
30
|
-
const DevSimulateSSR = process.env.NODE_ENV === 'development' && true; // This hook returns an enum value on purpose!
|
|
31
|
-
// We don't want it to return the actual width value, for resize perf reasons
|
|
32
|
-
// We only want to re-render once a breakpoint is crossed
|
|
33
|
-
|
|
34
|
-
function useWindowSize() {
|
|
35
|
-
const [windowSize, setWindowSize] = useState(() => {
|
|
36
|
-
if (DevSimulateSSR) {
|
|
37
|
-
return 'ssr';
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return getWindowSize();
|
|
41
|
-
});
|
|
42
|
-
useEffect(() => {
|
|
43
|
-
function updateWindowSize() {
|
|
44
|
-
setWindowSize(getWindowSize());
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const timeout = DevSimulateSSR
|
|
48
|
-
? window.setTimeout(updateWindowSize, 1000)
|
|
49
|
-
: undefined;
|
|
50
|
-
window.addEventListener('resize', updateWindowSize);
|
|
51
|
-
return () => {
|
|
52
|
-
window.removeEventListener('resize', updateWindowSize);
|
|
53
|
-
clearTimeout(timeout);
|
|
54
|
-
};
|
|
55
|
-
}, []);
|
|
56
|
-
return windowSize;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export default useWindowSize;
|
|
@@ -1,38 +0,0 @@
|
|
|
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 from 'react';
|
|
9
|
-
import clsx from 'clsx';
|
|
10
|
-
import Link from '@docusaurus/Link';
|
|
11
|
-
import Translate from '@docusaurus/Translate';
|
|
12
|
-
import type {Props} from '@theme/DocPaginatorNavLink';
|
|
13
|
-
|
|
14
|
-
function DocPaginatorNavLink(props: Props): JSX.Element {
|
|
15
|
-
const {navLink, next} = props;
|
|
16
|
-
return (
|
|
17
|
-
<Link className={clsx('pagination-nav__link')} to={navLink.permalink}>
|
|
18
|
-
<div className="pagination-nav__sublabel">
|
|
19
|
-
{next ? (
|
|
20
|
-
<Translate
|
|
21
|
-
id="theme.docs.paginator.next"
|
|
22
|
-
description="The label used to navigate to the next doc">
|
|
23
|
-
Next
|
|
24
|
-
</Translate>
|
|
25
|
-
) : (
|
|
26
|
-
<Translate
|
|
27
|
-
id="theme.docs.paginator.previous"
|
|
28
|
-
description="The label used to navigate to the previous doc">
|
|
29
|
-
Previous
|
|
30
|
-
</Translate>
|
|
31
|
-
)}
|
|
32
|
-
</div>
|
|
33
|
-
<div className="pagination-nav__label">{navLink.title}</div>
|
|
34
|
-
</Link>
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export default DocPaginatorNavLink;
|
|
@@ -1,15 +0,0 @@
|
|
|
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 from 'react';
|
|
9
|
-
import type {ThemeContextProps} from '@theme/hooks/useThemeContext';
|
|
10
|
-
|
|
11
|
-
const ThemeContext = React.createContext<ThemeContextProps | undefined>(
|
|
12
|
-
undefined,
|
|
13
|
-
);
|
|
14
|
-
|
|
15
|
-
export default ThemeContext;
|
|
@@ -1,28 +0,0 @@
|
|
|
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, {useMemo} from 'react';
|
|
9
|
-
|
|
10
|
-
import useTheme from '@theme/hooks/useTheme';
|
|
11
|
-
import ThemeContext from '@theme/ThemeContext';
|
|
12
|
-
import type {Props} from '@theme/ThemeProvider';
|
|
13
|
-
|
|
14
|
-
function ThemeProvider(props: Props): JSX.Element {
|
|
15
|
-
const {isDarkTheme, setLightTheme, setDarkTheme} = useTheme();
|
|
16
|
-
const contextValue = useMemo(
|
|
17
|
-
() => ({isDarkTheme, setLightTheme, setDarkTheme}),
|
|
18
|
-
[isDarkTheme, setLightTheme, setDarkTheme],
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
return (
|
|
22
|
-
<ThemeContext.Provider value={contextValue}>
|
|
23
|
-
{props.children}
|
|
24
|
-
</ThemeContext.Provider>
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export default ThemeProvider;
|
|
@@ -1,30 +0,0 @@
|
|
|
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, {useMemo} from 'react';
|
|
9
|
-
|
|
10
|
-
import useTabGroupChoice from '@theme/hooks/useTabGroupChoice';
|
|
11
|
-
import UserPreferencesContext from '@theme/UserPreferencesContext';
|
|
12
|
-
import type {Props} from '@theme/UserPreferencesProvider';
|
|
13
|
-
|
|
14
|
-
function UserPreferencesProvider(props: Props): JSX.Element {
|
|
15
|
-
const {tabGroupChoices, setTabGroupChoices} = useTabGroupChoice();
|
|
16
|
-
const contextValue = useMemo(
|
|
17
|
-
() => ({
|
|
18
|
-
tabGroupChoices,
|
|
19
|
-
setTabGroupChoices,
|
|
20
|
-
}),
|
|
21
|
-
[tabGroupChoices, setTabGroupChoices],
|
|
22
|
-
);
|
|
23
|
-
return (
|
|
24
|
-
<UserPreferencesContext.Provider value={contextValue}>
|
|
25
|
-
{props.children}
|
|
26
|
-
</UserPreferencesContext.Provider>
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export default UserPreferencesProvider;
|
|
@@ -1,11 +0,0 @@
|
|
|
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
|
-
// Re-expose useDocs
|
|
9
|
-
// Ensure it's always statically available even if user is not using the docs plugin
|
|
10
|
-
// Problem reported for the blog-only mode: https://github.com/facebook/docusaurus/issues/3360
|
|
11
|
-
export * from '@docusaurus/plugin-content-docs/lib/theme/hooks/useDocs';
|
|
@@ -1,72 +0,0 @@
|
|
|
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, useScrollPosition} from '@docusaurus/theme-common';
|
|
10
|
-
import type {useHideableNavbarReturns} from '@theme/hooks/useHideableNavbar';
|
|
11
|
-
|
|
12
|
-
const useHideableNavbar = (hideOnScroll: boolean): useHideableNavbarReturns => {
|
|
13
|
-
const [isNavbarVisible, setIsNavbarVisible] = useState(hideOnScroll);
|
|
14
|
-
const isFocusedAnchor = useRef(false);
|
|
15
|
-
const navbarHeight = useRef(0);
|
|
16
|
-
const navbarRef = useCallback((node: HTMLElement | null) => {
|
|
17
|
-
if (node !== null) {
|
|
18
|
-
navbarHeight.current = node.getBoundingClientRect().height;
|
|
19
|
-
}
|
|
20
|
-
}, []);
|
|
21
|
-
|
|
22
|
-
useScrollPosition((currentPosition, lastPosition) => {
|
|
23
|
-
if (!hideOnScroll) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const scrollTop = currentPosition.scrollY;
|
|
28
|
-
|
|
29
|
-
// It needed for mostly to handle rubber band scrolling
|
|
30
|
-
if (scrollTop < navbarHeight.current) {
|
|
31
|
-
setIsNavbarVisible(true);
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (isFocusedAnchor.current) {
|
|
36
|
-
isFocusedAnchor.current = false;
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const lastScrollTop = lastPosition?.scrollY;
|
|
41
|
-
const documentHeight =
|
|
42
|
-
document.documentElement.scrollHeight - navbarHeight.current;
|
|
43
|
-
const windowHeight = window.innerHeight;
|
|
44
|
-
|
|
45
|
-
if (lastScrollTop && scrollTop >= lastScrollTop) {
|
|
46
|
-
setIsNavbarVisible(false);
|
|
47
|
-
} else if (scrollTop + windowHeight < documentHeight) {
|
|
48
|
-
setIsNavbarVisible(true);
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
useLocationChange((locationChangeEvent) => {
|
|
53
|
-
if (!hideOnScroll) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (locationChangeEvent.location.hash) {
|
|
58
|
-
isFocusedAnchor.current = true;
|
|
59
|
-
setIsNavbarVisible(false);
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
setIsNavbarVisible(true);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
navbarRef,
|
|
68
|
-
isNavbarVisible,
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
export default useHideableNavbar;
|
|
@@ -1,39 +0,0 @@
|
|
|
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
|
-
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
|
-
}
|
|
38
|
-
|
|
39
|
-
export default useKeyboardNavigation;
|
|
@@ -1,20 +0,0 @@
|
|
|
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
|
-
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
|
-
}
|
|
19
|
-
|
|
20
|
-
export default useLockBodyScroll;
|
|
@@ -1,22 +0,0 @@
|
|
|
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 useThemeContext from '@theme/hooks/useThemeContext';
|
|
10
|
-
import {useThemeConfig} from '@docusaurus/theme-common';
|
|
11
|
-
|
|
12
|
-
const usePrismTheme = (): typeof defaultTheme => {
|
|
13
|
-
const {prism} = useThemeConfig();
|
|
14
|
-
const {isDarkTheme} = useThemeContext();
|
|
15
|
-
const lightModeTheme = prism.theme || defaultTheme;
|
|
16
|
-
const darkModeTheme = prism.darkTheme || lightModeTheme;
|
|
17
|
-
const prismTheme = isDarkTheme ? darkModeTheme : lightModeTheme;
|
|
18
|
-
|
|
19
|
-
return prismTheme;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export default usePrismTheme;
|
|
@@ -1,46 +0,0 @@
|
|
|
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, useEffect} from 'react';
|
|
9
|
-
import type {useTabGroupChoiceReturns} from '@theme/hooks/useTabGroupChoice';
|
|
10
|
-
import {createStorageSlot, listStorageKeys} from '@docusaurus/theme-common';
|
|
11
|
-
|
|
12
|
-
const TAB_CHOICE_PREFIX = 'docusaurus.tab.';
|
|
13
|
-
|
|
14
|
-
const useTabGroupChoice = (): useTabGroupChoiceReturns => {
|
|
15
|
-
const [tabGroupChoices, setChoices] = useState<{
|
|
16
|
-
readonly [groupId: string]: string;
|
|
17
|
-
}>({});
|
|
18
|
-
const setChoiceSyncWithLocalStorage = useCallback((groupId, newChoice) => {
|
|
19
|
-
createStorageSlot(`${TAB_CHOICE_PREFIX}${groupId}`).set(newChoice);
|
|
20
|
-
}, []);
|
|
21
|
-
|
|
22
|
-
useEffect(() => {
|
|
23
|
-
try {
|
|
24
|
-
const localStorageChoices: Record<string, string> = {};
|
|
25
|
-
listStorageKeys().forEach((storageKey) => {
|
|
26
|
-
if (storageKey.startsWith(TAB_CHOICE_PREFIX)) {
|
|
27
|
-
const groupId = storageKey.substring(TAB_CHOICE_PREFIX.length);
|
|
28
|
-
localStorageChoices[groupId] = createStorageSlot(storageKey).get()!;
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
setChoices(localStorageChoices);
|
|
32
|
-
} catch (err) {
|
|
33
|
-
console.error(err);
|
|
34
|
-
}
|
|
35
|
-
}, []);
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
tabGroupChoices,
|
|
39
|
-
setTabGroupChoices: (groupId: string, newChoice: string) => {
|
|
40
|
-
setChoices((oldChoices) => ({...oldChoices, [groupId]: newChoice}));
|
|
41
|
-
setChoiceSyncWithLocalStorage(groupId, newChoice);
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export default useTabGroupChoice;
|