@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,91 +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
|
-
|
|
10
|
-
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
|
11
|
-
import type {useThemeReturns} from '@theme/hooks/useTheme';
|
|
12
|
-
import {useThemeConfig, createStorageSlot} from '@docusaurus/theme-common';
|
|
13
|
-
|
|
14
|
-
const ThemeStorage = createStorageSlot('theme');
|
|
15
|
-
|
|
16
|
-
const themes = {
|
|
17
|
-
light: 'light',
|
|
18
|
-
dark: 'dark',
|
|
19
|
-
} as const;
|
|
20
|
-
|
|
21
|
-
type Themes = typeof themes[keyof typeof themes];
|
|
22
|
-
|
|
23
|
-
// Ensure to always return a valid theme even if input is invalid
|
|
24
|
-
const coerceToTheme = (theme?: string | null): Themes =>
|
|
25
|
-
theme === themes.dark ? themes.dark : themes.light;
|
|
26
|
-
|
|
27
|
-
const getInitialTheme = (defaultMode: Themes | undefined): Themes => {
|
|
28
|
-
if (!ExecutionEnvironment.canUseDOM) {
|
|
29
|
-
return coerceToTheme(defaultMode);
|
|
30
|
-
}
|
|
31
|
-
return coerceToTheme(document.documentElement.getAttribute('data-theme'));
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const storeTheme = (newTheme: Themes) => {
|
|
35
|
-
createStorageSlot('theme').set(coerceToTheme(newTheme));
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const useTheme = (): useThemeReturns => {
|
|
39
|
-
const {
|
|
40
|
-
colorMode: {defaultMode, disableSwitch, respectPrefersColorScheme},
|
|
41
|
-
} = useThemeConfig();
|
|
42
|
-
const [theme, setTheme] = useState(getInitialTheme(defaultMode));
|
|
43
|
-
|
|
44
|
-
const setLightTheme = useCallback(() => {
|
|
45
|
-
setTheme(themes.light);
|
|
46
|
-
storeTheme(themes.light);
|
|
47
|
-
}, []);
|
|
48
|
-
const setDarkTheme = useCallback(() => {
|
|
49
|
-
setTheme(themes.dark);
|
|
50
|
-
storeTheme(themes.dark);
|
|
51
|
-
}, []);
|
|
52
|
-
|
|
53
|
-
useEffect(() => {
|
|
54
|
-
document.documentElement.setAttribute('data-theme', coerceToTheme(theme));
|
|
55
|
-
}, [theme]);
|
|
56
|
-
|
|
57
|
-
useEffect(() => {
|
|
58
|
-
if (disableSwitch) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
try {
|
|
63
|
-
const storedTheme = ThemeStorage.get();
|
|
64
|
-
if (storedTheme !== null) {
|
|
65
|
-
setTheme(coerceToTheme(storedTheme));
|
|
66
|
-
}
|
|
67
|
-
} catch (err) {
|
|
68
|
-
console.error(err);
|
|
69
|
-
}
|
|
70
|
-
}, [disableSwitch, setTheme]);
|
|
71
|
-
|
|
72
|
-
useEffect(() => {
|
|
73
|
-
if (disableSwitch && !respectPrefersColorScheme) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
window
|
|
78
|
-
.matchMedia('(prefers-color-scheme: dark)')
|
|
79
|
-
.addListener(({matches}) => {
|
|
80
|
-
setTheme(matches ? themes.dark : themes.light);
|
|
81
|
-
});
|
|
82
|
-
}, [disableSwitch, respectPrefersColorScheme]);
|
|
83
|
-
|
|
84
|
-
return {
|
|
85
|
-
isDarkTheme: theme === themes.dark,
|
|
86
|
-
setLightTheme,
|
|
87
|
-
setDarkTheme,
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
export default useTheme;
|
|
@@ -1,23 +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 {useContext} from 'react';
|
|
9
|
-
|
|
10
|
-
import ThemeContext from '@theme/ThemeContext';
|
|
11
|
-
import type {ThemeContextProps} from '@theme/hooks/useThemeContext';
|
|
12
|
-
|
|
13
|
-
function useThemeContext(): ThemeContextProps {
|
|
14
|
-
const context = useContext<ThemeContextProps | undefined>(ThemeContext);
|
|
15
|
-
if (context == null) {
|
|
16
|
-
throw new Error(
|
|
17
|
-
'"useThemeContext" is used outside of "Layout" component. Please see https://docusaurus.io/docs/api/themes/configuration#usethemecontext.',
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
return context;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export default useThemeContext;
|
|
@@ -1,25 +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 {useContext} from 'react';
|
|
9
|
-
|
|
10
|
-
import UserPreferencesContext from '@theme/UserPreferencesContext';
|
|
11
|
-
import type {UserPreferencesContextProps} from '@theme/hooks/useUserPreferencesContext';
|
|
12
|
-
|
|
13
|
-
function useUserPreferencesContext(): UserPreferencesContextProps {
|
|
14
|
-
const context = useContext<UserPreferencesContextProps | undefined>(
|
|
15
|
-
UserPreferencesContext,
|
|
16
|
-
);
|
|
17
|
-
if (context == null) {
|
|
18
|
-
throw new Error(
|
|
19
|
-
'"useUserPreferencesContext" is used outside of "Layout" component.',
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
return context;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export default useUserPreferencesContext;
|
|
@@ -1,69 +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, useState} from 'react';
|
|
9
|
-
|
|
10
|
-
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
|
11
|
-
import type {WindowSize} from '@theme/hooks/useWindowSize';
|
|
12
|
-
|
|
13
|
-
const windowSizes = {
|
|
14
|
-
desktop: 'desktop',
|
|
15
|
-
mobile: 'mobile',
|
|
16
|
-
|
|
17
|
-
// This "ssr" value is very important to handle hydration FOUC / layout shifts
|
|
18
|
-
// You have to handle server-rendering explicitly on the call-site
|
|
19
|
-
// On the server, you may need to render BOTH the mobile/desktop elements (and hide one of them with mediaquery)
|
|
20
|
-
// We don't return "undefined" on purpose, to make it more explicit
|
|
21
|
-
ssr: 'ssr',
|
|
22
|
-
} as const;
|
|
23
|
-
|
|
24
|
-
const DesktopThresholdWidth = 996;
|
|
25
|
-
|
|
26
|
-
function getWindowSize() {
|
|
27
|
-
if (!ExecutionEnvironment.canUseDOM) {
|
|
28
|
-
return windowSizes.ssr;
|
|
29
|
-
}
|
|
30
|
-
return window.innerWidth > DesktopThresholdWidth
|
|
31
|
-
? windowSizes.desktop
|
|
32
|
-
: windowSizes.mobile;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Simulate the SSR window size in dev, so that potential hydration FOUC/layout shift problems can be seen in dev too!
|
|
36
|
-
const DevSimulateSSR = process.env.NODE_ENV === 'development' && true;
|
|
37
|
-
|
|
38
|
-
// This hook returns an enum value on purpose!
|
|
39
|
-
// We don't want it to return the actual width value, for resize perf reasons
|
|
40
|
-
// We only want to re-render once a breakpoint is crossed
|
|
41
|
-
function useWindowSize(): WindowSize {
|
|
42
|
-
const [windowSize, setWindowSize] = useState<WindowSize>(() => {
|
|
43
|
-
if (DevSimulateSSR) {
|
|
44
|
-
return 'ssr';
|
|
45
|
-
}
|
|
46
|
-
return getWindowSize();
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
useEffect(() => {
|
|
50
|
-
function updateWindowSize() {
|
|
51
|
-
setWindowSize(getWindowSize());
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const timeout = DevSimulateSSR
|
|
55
|
-
? window.setTimeout(updateWindowSize, 1000)
|
|
56
|
-
: undefined;
|
|
57
|
-
|
|
58
|
-
window.addEventListener('resize', updateWindowSize);
|
|
59
|
-
|
|
60
|
-
return () => {
|
|
61
|
-
window.removeEventListener('resize', updateWindowSize);
|
|
62
|
-
clearTimeout(timeout);
|
|
63
|
-
};
|
|
64
|
-
}, []);
|
|
65
|
-
|
|
66
|
-
return windowSize;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export default useWindowSize;
|