@docusaurus/theme-common 2.0.0-beta.17 → 2.0.0-beta.18
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 +32 -4
- package/lib/components/Collapsible/index.d.ts.map +1 -1
- package/lib/components/Collapsible/index.js +12 -3
- package/lib/components/Collapsible/index.js.map +1 -1
- package/lib/components/Details/index.d.ts +6 -1
- package/lib/components/Details/index.d.ts.map +1 -1
- package/lib/components/Details/index.js +8 -4
- package/lib/components/Details/index.js.map +1 -1
- package/lib/{utils/announcementBarUtils.d.ts → contexts/announcementBar.d.ts} +7 -3
- package/lib/contexts/announcementBar.d.ts.map +1 -0
- package/lib/{utils/announcementBarUtils.js → contexts/announcementBar.js} +11 -11
- package/lib/contexts/announcementBar.js.map +1 -0
- package/lib/{utils/colorModeUtils.d.ts → contexts/colorMode.d.ts} +12 -3
- package/lib/contexts/colorMode.d.ts.map +1 -0
- package/lib/contexts/colorMode.js +114 -0
- package/lib/contexts/colorMode.js.map +1 -0
- package/lib/contexts/docSidebarItemsExpandedState.d.ts +31 -0
- package/lib/contexts/docSidebarItemsExpandedState.d.ts.map +1 -0
- package/lib/{utils → contexts}/docSidebarItemsExpandedState.js +9 -4
- package/lib/contexts/docSidebarItemsExpandedState.js.map +1 -0
- package/lib/contexts/docsPreferredVersion.d.ts +28 -0
- package/lib/contexts/docsPreferredVersion.d.ts.map +1 -0
- package/lib/contexts/docsPreferredVersion.js +125 -0
- package/lib/contexts/docsPreferredVersion.js.map +1 -0
- package/lib/contexts/docsSidebar.d.ts +20 -0
- package/lib/contexts/docsSidebar.d.ts.map +1 -0
- package/lib/contexts/docsSidebar.js +29 -0
- package/lib/contexts/docsSidebar.js.map +1 -0
- package/lib/contexts/docsVersion.d.ts +20 -0
- package/lib/contexts/docsVersion.d.ts.map +1 -0
- package/lib/contexts/docsVersion.js +26 -0
- package/lib/contexts/docsVersion.js.map +1 -0
- package/lib/contexts/navbarMobileSidebar.d.ts +31 -0
- package/lib/contexts/navbarMobileSidebar.d.ts.map +1 -0
- package/lib/contexts/navbarMobileSidebar.js +56 -0
- package/lib/contexts/navbarMobileSidebar.js.map +1 -0
- package/lib/contexts/navbarSecondaryMenu.d.ts +38 -0
- package/lib/contexts/navbarSecondaryMenu.d.ts.map +1 -0
- package/lib/contexts/navbarSecondaryMenu.js +93 -0
- package/lib/contexts/navbarSecondaryMenu.js.map +1 -0
- package/lib/{utils/tabGroupChoiceUtils.d.ts → contexts/tabGroupChoice.d.ts} +5 -3
- package/lib/contexts/tabGroupChoice.d.ts.map +1 -0
- package/lib/{utils/tabGroupChoiceUtils.js → contexts/tabGroupChoice.js} +14 -20
- package/lib/contexts/tabGroupChoice.js.map +1 -0
- package/lib/hooks/useHideableNavbar.d.ts +7 -3
- package/lib/hooks/useHideableNavbar.d.ts.map +1 -1
- package/lib/hooks/useHideableNavbar.js +8 -6
- package/lib/hooks/useHideableNavbar.js.map +1 -1
- package/lib/hooks/useKeyboardNavigation.d.ts +11 -1
- package/lib/hooks/useKeyboardNavigation.d.ts.map +1 -1
- package/lib/hooks/useKeyboardNavigation.js +11 -3
- package/lib/hooks/useKeyboardNavigation.js.map +1 -1
- package/lib/hooks/useLockBodyScroll.d.ts +5 -1
- package/lib/hooks/useLockBodyScroll.d.ts.map +1 -1
- package/lib/hooks/useLockBodyScroll.js +5 -1
- package/lib/hooks/useLockBodyScroll.js.map +1 -1
- package/lib/hooks/usePrismTheme.d.ts +5 -1
- package/lib/hooks/usePrismTheme.d.ts.map +1 -1
- package/lib/hooks/usePrismTheme.js +8 -4
- package/lib/hooks/usePrismTheme.js.map +1 -1
- package/lib/hooks/useSearchPage.d.ts +15 -4
- package/lib/hooks/useSearchPage.d.ts.map +1 -1
- package/lib/hooks/useSearchPage.js +3 -2
- package/lib/hooks/useSearchPage.js.map +1 -1
- package/lib/hooks/useTOCHighlight.d.ts +25 -0
- package/lib/hooks/useTOCHighlight.d.ts.map +1 -0
- package/lib/{utils → hooks}/useTOCHighlight.js +13 -9
- package/lib/hooks/useTOCHighlight.js.map +1 -0
- package/lib/hooks/useWindowSize.d.ts +14 -1
- package/lib/hooks/useWindowSize.d.ts.map +1 -1
- package/lib/hooks/useWindowSize.js +14 -11
- package/lib/hooks/useWindowSize.js.map +1 -1
- package/lib/index.d.ts +26 -30
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +26 -24
- package/lib/index.js.map +1 -1
- package/lib/utils/ThemeClassNames.d.ts +7 -0
- package/lib/utils/ThemeClassNames.d.ts.map +1 -1
- package/lib/utils/ThemeClassNames.js +7 -4
- package/lib/utils/ThemeClassNames.js.map +1 -1
- package/lib/utils/codeBlockUtils.d.ts +25 -2
- package/lib/utils/codeBlockUtils.d.ts.map +1 -1
- package/lib/utils/codeBlockUtils.js +36 -35
- package/lib/utils/codeBlockUtils.js.map +1 -1
- package/lib/utils/docsUtils.d.ts +25 -18
- package/lib/utils/docsUtils.d.ts.map +1 -1
- package/lib/utils/docsUtils.js +38 -56
- package/lib/utils/docsUtils.js.map +1 -1
- package/lib/utils/footerUtils.d.ts +13 -0
- package/lib/utils/footerUtils.d.ts.map +1 -0
- package/lib/utils/footerUtils.js +14 -0
- package/lib/utils/footerUtils.js.map +1 -0
- package/lib/utils/generalUtils.d.ts +4 -1
- package/lib/utils/generalUtils.d.ts.map +1 -1
- package/lib/utils/generalUtils.js +6 -3
- package/lib/utils/generalUtils.js.map +1 -1
- package/lib/utils/historyUtils.d.ts +1 -7
- package/lib/utils/historyUtils.d.ts.map +1 -1
- package/lib/utils/historyUtils.js +10 -13
- package/lib/utils/historyUtils.js.map +1 -1
- package/lib/utils/jsUtils.d.ts +1 -1
- package/lib/utils/jsUtils.js +1 -1
- package/lib/utils/metadataUtils.d.ts +38 -0
- package/lib/utils/metadataUtils.d.ts.map +1 -0
- package/lib/utils/metadataUtils.js +61 -0
- package/lib/utils/metadataUtils.js.map +1 -0
- package/lib/utils/navbarUtils.d.ts +21 -0
- package/lib/utils/navbarUtils.d.ts.map +1 -0
- package/lib/utils/navbarUtils.js +30 -0
- package/lib/utils/navbarUtils.js.map +1 -0
- package/lib/utils/reactUtils.d.ts +16 -5
- package/lib/utils/reactUtils.d.ts.map +1 -1
- package/lib/utils/reactUtils.js +28 -7
- package/lib/utils/reactUtils.js.map +1 -1
- package/lib/utils/regexpUtils.d.ts +2 -1
- package/lib/utils/regexpUtils.d.ts.map +1 -1
- package/lib/utils/regexpUtils.js +2 -1
- package/lib/utils/regexpUtils.js.map +1 -1
- package/lib/utils/routesUtils.d.ts +14 -2
- package/lib/utils/routesUtils.d.ts.map +1 -1
- package/lib/utils/routesUtils.js +20 -7
- package/lib/utils/routesUtils.js.map +1 -1
- package/lib/utils/scrollUtils.d.ts +32 -26
- package/lib/utils/scrollUtils.d.ts.map +1 -1
- package/lib/utils/scrollUtils.js +30 -17
- package/lib/utils/scrollUtils.js.map +1 -1
- package/lib/utils/searchUtils.d.ts +12 -0
- package/lib/utils/searchUtils.d.ts.map +1 -1
- package/lib/utils/searchUtils.js +34 -0
- package/lib/utils/searchUtils.js.map +1 -1
- package/lib/utils/storageUtils.d.ts +10 -7
- package/lib/utils/storageUtils.d.ts.map +1 -1
- package/lib/utils/storageUtils.js +20 -12
- package/lib/utils/storageUtils.js.map +1 -1
- package/lib/utils/tagsUtils.d.ts +5 -2
- package/lib/utils/tagsUtils.d.ts.map +1 -1
- package/lib/utils/tagsUtils.js +7 -4
- package/lib/utils/tagsUtils.js.map +1 -1
- package/lib/utils/tocUtils.d.ts +16 -0
- package/lib/utils/tocUtils.d.ts.map +1 -1
- package/lib/utils/tocUtils.js +17 -6
- package/lib/utils/tocUtils.js.map +1 -1
- package/lib/utils/useAlternatePageUtils.d.ts +20 -1
- package/lib/utils/useAlternatePageUtils.d.ts.map +1 -1
- package/lib/utils/useAlternatePageUtils.js +6 -3
- package/lib/utils/useAlternatePageUtils.js.map +1 -1
- package/lib/utils/useLocalPathname.d.ts +5 -0
- package/lib/utils/useLocalPathname.d.ts.map +1 -1
- package/lib/utils/useLocalPathname.js +6 -4
- package/lib/utils/useLocalPathname.js.map +1 -1
- package/lib/utils/useLocationChange.d.ts +7 -5
- package/lib/utils/useLocationChange.d.ts.map +1 -1
- package/lib/utils/useLocationChange.js +6 -2
- package/lib/utils/useLocationChange.js.map +1 -1
- package/lib/utils/usePluralForm.d.ts +11 -0
- package/lib/utils/usePluralForm.d.ts.map +1 -1
- package/lib/utils/usePluralForm.js +19 -24
- package/lib/utils/usePluralForm.js.map +1 -1
- package/lib/utils/useThemeConfig.d.ts +21 -11
- package/lib/utils/useThemeConfig.d.ts.map +1 -1
- package/lib/utils/useThemeConfig.js +3 -0
- package/lib/utils/useThemeConfig.js.map +1 -1
- package/package.json +8 -9
- package/src/components/Collapsible/index.tsx +40 -22
- package/src/components/Details/index.tsx +11 -6
- package/src/{utils/announcementBarUtils.tsx → contexts/announcementBar.tsx} +17 -18
- package/src/contexts/colorMode.tsx +176 -0
- package/src/contexts/docSidebarItemsExpandedState.tsx +55 -0
- package/src/contexts/docsPreferredVersion.tsx +250 -0
- package/src/contexts/docsSidebar.tsx +42 -0
- package/src/contexts/docsVersion.tsx +36 -0
- package/src/contexts/navbarMobileSidebar.tsx +99 -0
- package/src/contexts/navbarSecondaryMenu.tsx +170 -0
- package/src/{utils/tabGroupChoiceUtils.tsx → contexts/tabGroupChoice.tsx} +21 -28
- package/src/hooks/useHideableNavbar.ts +11 -11
- package/src/hooks/useKeyboardNavigation.ts +11 -3
- package/src/hooks/useLockBodyScroll.ts +5 -2
- package/src/hooks/usePrismTheme.ts +8 -4
- package/src/hooks/useSearchPage.ts +18 -5
- package/src/{utils → hooks}/useTOCHighlight.ts +21 -12
- package/src/hooks/useWindowSize.ts +14 -12
- package/src/index.ts +68 -56
- package/src/utils/ThemeClassNames.ts +10 -6
- package/src/utils/codeBlockUtils.ts +49 -47
- package/src/utils/docsUtils.tsx +48 -99
- package/src/utils/footerUtils.ts +18 -0
- package/src/utils/generalUtils.ts +6 -3
- package/src/utils/historyUtils.ts +11 -17
- package/src/utils/jsUtils.ts +1 -1
- package/src/utils/metadataUtils.tsx +115 -0
- package/src/utils/navbarUtils.tsx +40 -0
- package/src/utils/reactUtils.tsx +31 -8
- package/src/utils/regexpUtils.ts +2 -1
- package/src/utils/routesUtils.ts +27 -8
- package/src/utils/scrollUtils.tsx +44 -45
- package/src/utils/searchUtils.ts +49 -0
- package/src/utils/storageUtils.ts +21 -13
- package/src/utils/tagsUtils.ts +14 -7
- package/src/utils/tocUtils.ts +18 -7
- package/src/utils/useAlternatePageUtils.ts +17 -5
- package/src/utils/useLocalPathname.ts +6 -4
- package/src/utils/useLocationChange.ts +12 -10
- package/src/utils/usePluralForm.ts +27 -24
- package/src/utils/useThemeConfig.ts +16 -11
- package/lib/utils/announcementBarUtils.d.ts.map +0 -1
- package/lib/utils/announcementBarUtils.js.map +0 -1
- package/lib/utils/colorModeUtils.d.ts.map +0 -1
- package/lib/utils/colorModeUtils.js +0 -107
- package/lib/utils/colorModeUtils.js.map +0 -1
- package/lib/utils/docSidebarItemsExpandedState.d.ts +0 -17
- package/lib/utils/docSidebarItemsExpandedState.d.ts.map +0 -1
- package/lib/utils/docSidebarItemsExpandedState.js.map +0 -1
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.d.ts +0 -22
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.d.ts.map +0 -1
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js +0 -92
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js.map +0 -1
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.d.ts +0 -14
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.d.ts.map +0 -1
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.js +0 -19
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.js.map +0 -1
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.d.ts +0 -14
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.d.ts.map +0 -1
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.js +0 -41
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.js.map +0 -1
- package/lib/utils/mobileSecondaryMenu.d.ts +0 -21
- package/lib/utils/mobileSecondaryMenu.d.ts.map +0 -1
- package/lib/utils/mobileSecondaryMenu.js +0 -51
- package/lib/utils/mobileSecondaryMenu.js.map +0 -1
- package/lib/utils/pathUtils.d.ts +0 -8
- package/lib/utils/pathUtils.d.ts.map +0 -1
- package/lib/utils/pathUtils.js +0 -14
- package/lib/utils/pathUtils.js.map +0 -1
- package/lib/utils/tabGroupChoiceUtils.d.ts.map +0 -1
- package/lib/utils/tabGroupChoiceUtils.js.map +0 -1
- package/lib/utils/useContextualSearchFilters.d.ts +0 -12
- package/lib/utils/useContextualSearchFilters.d.ts.map +0 -1
- package/lib/utils/useContextualSearchFilters.js +0 -36
- package/lib/utils/useContextualSearchFilters.js.map +0 -1
- package/lib/utils/usePrevious.d.ts +0 -8
- package/lib/utils/usePrevious.d.ts.map +0 -1
- package/lib/utils/usePrevious.js +0 -16
- package/lib/utils/usePrevious.js.map +0 -1
- package/lib/utils/useTOCHighlight.d.ts +0 -14
- package/lib/utils/useTOCHighlight.d.ts.map +0 -1
- package/lib/utils/useTOCHighlight.js.map +0 -1
- package/src/utils/colorModeUtils.tsx +0 -158
- package/src/utils/docSidebarItemsExpandedState.tsx +0 -40
- package/src/utils/docsPreferredVersion/DocsPreferredVersionProvider.tsx +0 -166
- package/src/utils/docsPreferredVersion/DocsPreferredVersionStorage.ts +0 -33
- package/src/utils/docsPreferredVersion/useDocsPreferredVersion.ts +0 -70
- package/src/utils/mobileSecondaryMenu.tsx +0 -114
- package/src/utils/pathUtils.ts +0 -19
- package/src/utils/useContextualSearchFilters.ts +0 -53
- package/src/utils/usePrevious.ts +0 -19
|
@@ -12,7 +12,9 @@ export declare type NavbarItem = {
|
|
|
12
12
|
items?: NavbarItem[];
|
|
13
13
|
label?: string;
|
|
14
14
|
position?: 'left' | 'right';
|
|
15
|
-
} &
|
|
15
|
+
} & {
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
};
|
|
16
18
|
export declare type NavbarLogo = {
|
|
17
19
|
src: string;
|
|
18
20
|
srcDark?: string;
|
|
@@ -45,7 +47,7 @@ export declare type PrismConfig = {
|
|
|
45
47
|
theme?: PrismTheme;
|
|
46
48
|
darkTheme?: PrismTheme;
|
|
47
49
|
defaultLanguage?: string;
|
|
48
|
-
additionalLanguages
|
|
50
|
+
additionalLanguages: string[];
|
|
49
51
|
};
|
|
50
52
|
export declare type FooterLinkItem = {
|
|
51
53
|
label?: string;
|
|
@@ -53,17 +55,20 @@ export declare type FooterLinkItem = {
|
|
|
53
55
|
href?: string;
|
|
54
56
|
html?: string;
|
|
55
57
|
prependBaseUrlToHref?: string;
|
|
58
|
+
} & {
|
|
59
|
+
[key: string]: unknown;
|
|
60
|
+
};
|
|
61
|
+
export declare type FooterLogo = {
|
|
62
|
+
alt?: string;
|
|
63
|
+
src: string;
|
|
64
|
+
srcDark?: string;
|
|
65
|
+
width?: string | number;
|
|
66
|
+
height?: string | number;
|
|
67
|
+
href?: string;
|
|
56
68
|
};
|
|
57
69
|
export declare type FooterBase = {
|
|
58
70
|
style: 'light' | 'dark';
|
|
59
|
-
logo?:
|
|
60
|
-
alt?: string;
|
|
61
|
-
src?: string;
|
|
62
|
-
srcDark?: string;
|
|
63
|
-
width?: string | number;
|
|
64
|
-
height?: string | number;
|
|
65
|
-
href?: string;
|
|
66
|
-
};
|
|
71
|
+
logo?: FooterLogo;
|
|
67
72
|
copyright?: string;
|
|
68
73
|
};
|
|
69
74
|
export declare type MultiColumnFooter = FooterBase & {
|
|
@@ -92,10 +97,15 @@ export declare type ThemeConfig = {
|
|
|
92
97
|
hideableSidebar: boolean;
|
|
93
98
|
autoCollapseSidebarCategories: boolean;
|
|
94
99
|
image?: string;
|
|
95
|
-
metadata: Array<
|
|
100
|
+
metadata: Array<{
|
|
101
|
+
[key: string]: string;
|
|
102
|
+
}>;
|
|
96
103
|
sidebarCollapsible: boolean;
|
|
97
104
|
tableOfContents: TableOfContents;
|
|
98
105
|
};
|
|
99
106
|
export declare type UserThemeConfig = DeepPartial<ThemeConfig>;
|
|
107
|
+
/**
|
|
108
|
+
* A convenient/more semantic way to get theme config from context.
|
|
109
|
+
*/
|
|
100
110
|
export declare function useThemeConfig(): ThemeConfig;
|
|
101
111
|
//# sourceMappingURL=useThemeConfig.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useThemeConfig.d.ts","sourceRoot":"","sources":["../../src/utils/useThemeConfig.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,eAAe,CAAC;AAE/C,oBAAY,sBAAsB,GAAG,cAAc,GAAG,MAAM,CAAC;AAG7D,oBAAY,UAAU,GAAG;IACvB,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,KAAK,CAAC,EAAE,UAAU,EAAE,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CAC7B,GAAG,
|
|
1
|
+
{"version":3,"file":"useThemeConfig.d.ts","sourceRoot":"","sources":["../../src/utils/useThemeConfig.ts"],"names":[],"mappings":"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"}
|
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
8
|
+
/**
|
|
9
|
+
* A convenient/more semantic way to get theme config from context.
|
|
10
|
+
*/
|
|
8
11
|
export function useThemeConfig() {
|
|
9
12
|
return useDocusaurusContext().siteConfig.themeConfig;
|
|
10
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useThemeConfig.js","sourceRoot":"","sources":["../../src/utils/useThemeConfig.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"useThemeConfig.js","sourceRoot":"","sources":["../../src/utils/useThemeConfig.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;AA0HpE;;GAEG;AACH,MAAM,UAAU,cAAc;IAC5B,OAAO,oBAAoB,EAAE,CAAC,UAAU,CAAC,WAA0B,CAAC;AACtE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/theme-common",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.18",
|
|
4
4
|
"description": "Common code for Docusaurus themes.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@docusaurus/module-type-aliases": "2.0.0-beta.
|
|
22
|
-
"@docusaurus/plugin-content-blog": "2.0.0-beta.
|
|
23
|
-
"@docusaurus/plugin-content-docs": "2.0.0-beta.
|
|
24
|
-
"@docusaurus/plugin-content-pages": "2.0.0-beta.
|
|
21
|
+
"@docusaurus/module-type-aliases": "2.0.0-beta.18",
|
|
22
|
+
"@docusaurus/plugin-content-blog": "2.0.0-beta.18",
|
|
23
|
+
"@docusaurus/plugin-content-docs": "2.0.0-beta.18",
|
|
24
|
+
"@docusaurus/plugin-content-pages": "2.0.0-beta.18",
|
|
25
25
|
"clsx": "^1.1.1",
|
|
26
26
|
"parse-numeric-range": "^1.3.0",
|
|
27
27
|
"prism-react-renderer": "^1.3.1",
|
|
@@ -29,9 +29,8 @@
|
|
|
29
29
|
"utility-types": "^3.10.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@docusaurus/core": "2.0.0-beta.
|
|
33
|
-
"@docusaurus/types": "2.0.0-beta.
|
|
34
|
-
"@testing-library/react-hooks": "^7.0.2",
|
|
32
|
+
"@docusaurus/core": "2.0.0-beta.18",
|
|
33
|
+
"@docusaurus/types": "2.0.0-beta.18",
|
|
35
34
|
"fs-extra": "^10.0.1",
|
|
36
35
|
"lodash": "^4.17.21"
|
|
37
36
|
},
|
|
@@ -42,5 +41,5 @@
|
|
|
42
41
|
"engines": {
|
|
43
42
|
"node": ">=14"
|
|
44
43
|
},
|
|
45
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "1a945d06993d53376e61bed2c942799fe07dc336"
|
|
46
45
|
}
|
|
@@ -11,29 +11,28 @@ import React, {
|
|
|
11
11
|
useEffect,
|
|
12
12
|
useRef,
|
|
13
13
|
useCallback,
|
|
14
|
+
useLayoutEffect,
|
|
14
15
|
type RefObject,
|
|
15
16
|
type Dispatch,
|
|
16
17
|
type SetStateAction,
|
|
17
18
|
type ReactNode,
|
|
18
|
-
useLayoutEffect,
|
|
19
19
|
} from 'react';
|
|
20
20
|
|
|
21
21
|
const DefaultAnimationEasing = 'ease-in-out';
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
/**
|
|
24
|
+
* This hook is a very thin wrapper around a `useState`.
|
|
25
|
+
*/
|
|
26
|
+
export function useCollapsible({
|
|
27
|
+
initialState,
|
|
28
|
+
}: {
|
|
29
|
+
/** The initial state. Will be non-collapsed by default. */
|
|
24
30
|
initialState: boolean | (() => boolean);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export type UseCollapsibleReturns = {
|
|
31
|
+
}): {
|
|
28
32
|
collapsed: boolean;
|
|
29
33
|
setCollapsed: Dispatch<SetStateAction<boolean>>;
|
|
30
34
|
toggleCollapsed: () => void;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// This hook just define the state
|
|
34
|
-
export function useCollapsible({
|
|
35
|
-
initialState,
|
|
36
|
-
}: UseCollapsibleConfig): UseCollapsibleReturns {
|
|
35
|
+
} {
|
|
37
36
|
const [collapsed, setCollapsed] = useState(initialState ?? false);
|
|
38
37
|
|
|
39
38
|
const toggleCollapsed = useCallback(() => {
|
|
@@ -152,8 +151,10 @@ type CollapsibleElementType = React.ElementType<
|
|
|
152
151
|
Pick<React.HTMLAttributes<unknown>, 'className' | 'onTransitionEnd' | 'style'>
|
|
153
152
|
>;
|
|
154
153
|
|
|
155
|
-
|
|
156
|
-
|
|
154
|
+
/**
|
|
155
|
+
* Prevent hydration layout shift before animations are handled imperatively
|
|
156
|
+
* with JS
|
|
157
|
+
*/
|
|
157
158
|
function getSSRStyle(collapsed: boolean) {
|
|
158
159
|
if (ExecutionEnvironment.canUseDOM) {
|
|
159
160
|
return undefined;
|
|
@@ -162,16 +163,27 @@ function getSSRStyle(collapsed: boolean) {
|
|
|
162
163
|
}
|
|
163
164
|
|
|
164
165
|
type CollapsibleBaseProps = {
|
|
166
|
+
/** The actual DOM element to be used in the markup. */
|
|
165
167
|
as?: CollapsibleElementType;
|
|
168
|
+
/** Initial collapsed state. */
|
|
166
169
|
collapsed: boolean;
|
|
167
170
|
children: ReactNode;
|
|
171
|
+
/** Configuration of animation, like `duration` and `easing` */
|
|
168
172
|
animation?: CollapsibleAnimationConfig;
|
|
173
|
+
/**
|
|
174
|
+
* A callback fired when the collapse transition animation ends. Receives
|
|
175
|
+
* the **new** collapsed state: e.g. when
|
|
176
|
+
* expanding, `collapsed` will be `false`. You can use this for some "cleanup"
|
|
177
|
+
* like applying new styles when the container is fully expanded.
|
|
178
|
+
*/
|
|
169
179
|
onCollapseTransitionEnd?: (collapsed: boolean) => void;
|
|
180
|
+
/** Class name for the underlying DOM element. */
|
|
170
181
|
className?: string;
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
182
|
+
/**
|
|
183
|
+
* This is mostly useful for details/summary component where ssrStyle is not
|
|
184
|
+
* needed (as details are hidden natively) and can mess up with the browser's
|
|
185
|
+
* native behavior when JS fails to load or is disabled
|
|
186
|
+
*/
|
|
175
187
|
disableSSRStyle?: boolean;
|
|
176
188
|
};
|
|
177
189
|
|
|
@@ -233,14 +245,20 @@ function CollapsibleLazy({collapsed, ...props}: CollapsibleBaseProps) {
|
|
|
233
245
|
}
|
|
234
246
|
|
|
235
247
|
type CollapsibleProps = CollapsibleBaseProps & {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
248
|
+
/**
|
|
249
|
+
* Delay rendering of the content till first expansion. Marked as required to
|
|
250
|
+
* force us to think if content should be server-rendered or not. This has
|
|
251
|
+
* perf impact since it reduces html file sizes, but could undermine SEO.
|
|
252
|
+
* @see https://github.com/facebook/docusaurus/issues/4753
|
|
253
|
+
*/
|
|
241
254
|
lazy: boolean;
|
|
242
255
|
};
|
|
243
256
|
|
|
257
|
+
/**
|
|
258
|
+
* A headless component providing smooth and uniform collapsing behavior. The
|
|
259
|
+
* component will be invisible (zero height) when collapsed. Doesn't provide
|
|
260
|
+
* interactivity by itself: collapse state is toggled through props.
|
|
261
|
+
*/
|
|
244
262
|
export function Collapsible({lazy, ...props}: CollapsibleProps): JSX.Element {
|
|
245
263
|
const Comp = lazy ? CollapsibleLazy : CollapsibleBase;
|
|
246
264
|
return <Comp {...props} />;
|
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import React, {
|
|
9
|
-
type ComponentProps,
|
|
10
|
-
type ReactElement,
|
|
11
9
|
useRef,
|
|
12
10
|
useState,
|
|
11
|
+
type ComponentProps,
|
|
12
|
+
type ReactElement,
|
|
13
13
|
} from 'react';
|
|
14
14
|
import useIsBrowser from '@docusaurus/useIsBrowser';
|
|
15
15
|
import clsx from 'clsx';
|
|
@@ -31,10 +31,15 @@ function hasParent(node: HTMLElement | null, parent: HTMLElement): boolean {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
export type DetailsProps = {
|
|
34
|
+
/** Summary is provided as props, including the wrapping `<summary>` tag */
|
|
34
35
|
summary?: ReactElement;
|
|
35
36
|
} & ComponentProps<'details'>;
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
/**
|
|
39
|
+
* A mostly un-styled `<details>` element with smooth collapsing. Provides some
|
|
40
|
+
* very lightweight styles, but you should bring your UI.
|
|
41
|
+
*/
|
|
42
|
+
export function Details({
|
|
38
43
|
summary,
|
|
39
44
|
children,
|
|
40
45
|
...props
|
|
@@ -45,8 +50,8 @@ export default function Details({
|
|
|
45
50
|
const {collapsed, setCollapsed} = useCollapsible({
|
|
46
51
|
initialState: !props.open,
|
|
47
52
|
});
|
|
48
|
-
// Use a separate prop because it must be set
|
|
49
|
-
//
|
|
53
|
+
// Use a separate state for the actual details prop, because it must be set
|
|
54
|
+
// only after animation completes, otherwise close animations won't work
|
|
50
55
|
const [open, setOpen] = useState(props.open);
|
|
51
56
|
|
|
52
57
|
return (
|
|
@@ -58,7 +63,7 @@ export default function Details({
|
|
|
58
63
|
data-collapsed={collapsed}
|
|
59
64
|
className={clsx(
|
|
60
65
|
styles.details,
|
|
61
|
-
|
|
66
|
+
isBrowser && styles.isBrowser,
|
|
62
67
|
props.className,
|
|
63
68
|
)}
|
|
64
69
|
onMouseDown={(e) => {
|
|
@@ -10,14 +10,13 @@ import React, {
|
|
|
10
10
|
useEffect,
|
|
11
11
|
useCallback,
|
|
12
12
|
useMemo,
|
|
13
|
-
type ReactNode,
|
|
14
13
|
useContext,
|
|
15
|
-
|
|
14
|
+
type ReactNode,
|
|
16
15
|
} from 'react';
|
|
17
16
|
import useIsBrowser from '@docusaurus/useIsBrowser';
|
|
18
|
-
import {createStorageSlot} from '
|
|
19
|
-
import {ReactContextError} from '
|
|
20
|
-
import {useThemeConfig} from '
|
|
17
|
+
import {createStorageSlot} from '../utils/storageUtils';
|
|
18
|
+
import {ReactContextError} from '../utils/reactUtils';
|
|
19
|
+
import {useThemeConfig} from '../utils/useThemeConfig';
|
|
21
20
|
|
|
22
21
|
export const AnnouncementBarDismissStorageKey =
|
|
23
22
|
'docusaurus.announcement.dismiss';
|
|
@@ -33,12 +32,18 @@ const isDismissedInStorage = () =>
|
|
|
33
32
|
const setDismissedInStorage = (bool: boolean) =>
|
|
34
33
|
AnnouncementBarDismissStorage.set(String(bool));
|
|
35
34
|
|
|
36
|
-
type
|
|
35
|
+
type ContextValue = {
|
|
36
|
+
/** Whether the announcement bar should be displayed. */
|
|
37
37
|
readonly isActive: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Callback fired when the user closes the announcement. Will be saved.
|
|
40
|
+
*/
|
|
38
41
|
readonly close: () => void;
|
|
39
42
|
};
|
|
40
43
|
|
|
41
|
-
const
|
|
44
|
+
const Context = React.createContext<ContextValue | null>(null);
|
|
45
|
+
|
|
46
|
+
function useContextValue(): ContextValue {
|
|
42
47
|
const {announcementBar} = useThemeConfig();
|
|
43
48
|
const isBrowser = useIsBrowser();
|
|
44
49
|
|
|
@@ -94,25 +99,19 @@ const useAnnouncementBarContextValue = (): AnnouncementBarAPI => {
|
|
|
94
99
|
}),
|
|
95
100
|
[announcementBar, isClosed, handleClose],
|
|
96
101
|
);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const AnnouncementBarContext = createContext<AnnouncementBarAPI | null>(null);
|
|
102
|
+
}
|
|
100
103
|
|
|
101
104
|
export function AnnouncementBarProvider({
|
|
102
105
|
children,
|
|
103
106
|
}: {
|
|
104
107
|
children: ReactNode;
|
|
105
108
|
}): JSX.Element {
|
|
106
|
-
const value =
|
|
107
|
-
return
|
|
108
|
-
<AnnouncementBarContext.Provider value={value}>
|
|
109
|
-
{children}
|
|
110
|
-
</AnnouncementBarContext.Provider>
|
|
111
|
-
);
|
|
109
|
+
const value = useContextValue();
|
|
110
|
+
return <Context.Provider value={value}>{children}</Context.Provider>;
|
|
112
111
|
}
|
|
113
112
|
|
|
114
|
-
export function useAnnouncementBar():
|
|
115
|
-
const api = useContext(
|
|
113
|
+
export function useAnnouncementBar(): ContextValue {
|
|
114
|
+
const api = useContext(Context);
|
|
116
115
|
if (!api) {
|
|
117
116
|
throw new ReactContextError('AnnouncementBarProvider');
|
|
118
117
|
}
|
|
@@ -0,0 +1,176 @@
|
|
|
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
|
+
useContext,
|
|
13
|
+
useMemo,
|
|
14
|
+
useRef,
|
|
15
|
+
type ReactNode,
|
|
16
|
+
} from 'react';
|
|
17
|
+
import {ReactContextError} from '../utils/reactUtils';
|
|
18
|
+
|
|
19
|
+
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
|
20
|
+
import {createStorageSlot} from '../utils/storageUtils';
|
|
21
|
+
import {useThemeConfig} from '../utils/useThemeConfig';
|
|
22
|
+
|
|
23
|
+
type ContextValue = {
|
|
24
|
+
/** Current color mode. */
|
|
25
|
+
readonly colorMode: ColorMode;
|
|
26
|
+
/** Set new color mode. */
|
|
27
|
+
readonly setColorMode: (colorMode: ColorMode) => void;
|
|
28
|
+
|
|
29
|
+
// TODO legacy APIs kept for retro-compatibility: deprecate them
|
|
30
|
+
readonly isDarkTheme: boolean;
|
|
31
|
+
readonly setLightTheme: () => void;
|
|
32
|
+
readonly setDarkTheme: () => void;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const Context = React.createContext<ContextValue | undefined>(undefined);
|
|
36
|
+
|
|
37
|
+
const ColorModeStorageKey = 'theme';
|
|
38
|
+
const ColorModeStorage = createStorageSlot(ColorModeStorageKey);
|
|
39
|
+
|
|
40
|
+
const ColorModes = {
|
|
41
|
+
light: 'light',
|
|
42
|
+
dark: 'dark',
|
|
43
|
+
} as const;
|
|
44
|
+
|
|
45
|
+
export type ColorMode = typeof ColorModes[keyof typeof ColorModes];
|
|
46
|
+
|
|
47
|
+
// Ensure to always return a valid colorMode even if input is invalid
|
|
48
|
+
const coerceToColorMode = (colorMode?: string | null): ColorMode =>
|
|
49
|
+
colorMode === ColorModes.dark ? ColorModes.dark : ColorModes.light;
|
|
50
|
+
|
|
51
|
+
const getInitialColorMode = (defaultMode: ColorMode | undefined): ColorMode =>
|
|
52
|
+
ExecutionEnvironment.canUseDOM
|
|
53
|
+
? coerceToColorMode(document.documentElement.getAttribute('data-theme'))
|
|
54
|
+
: coerceToColorMode(defaultMode);
|
|
55
|
+
|
|
56
|
+
const storeColorMode = (newColorMode: ColorMode) => {
|
|
57
|
+
ColorModeStorage.set(coerceToColorMode(newColorMode));
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
function useContextValue(): ContextValue {
|
|
61
|
+
const {
|
|
62
|
+
colorMode: {defaultMode, disableSwitch, respectPrefersColorScheme},
|
|
63
|
+
} = useThemeConfig();
|
|
64
|
+
const [colorMode, setColorModeState] = useState(
|
|
65
|
+
getInitialColorMode(defaultMode),
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const setColorMode = useCallback((newColorMode: ColorMode) => {
|
|
69
|
+
setColorModeState(newColorMode);
|
|
70
|
+
storeColorMode(newColorMode);
|
|
71
|
+
}, []);
|
|
72
|
+
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
document.documentElement.setAttribute(
|
|
75
|
+
'data-theme',
|
|
76
|
+
coerceToColorMode(colorMode),
|
|
77
|
+
);
|
|
78
|
+
}, [colorMode]);
|
|
79
|
+
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (disableSwitch) {
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
const onChange = (e: StorageEvent) => {
|
|
85
|
+
if (e.key !== ColorModeStorageKey) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
const storedColorMode = ColorModeStorage.get();
|
|
90
|
+
if (storedColorMode !== null) {
|
|
91
|
+
setColorMode(coerceToColorMode(storedColorMode));
|
|
92
|
+
}
|
|
93
|
+
} catch (err) {
|
|
94
|
+
console.error(err);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
window.addEventListener('storage', onChange);
|
|
98
|
+
return () => window.removeEventListener('storage', onChange);
|
|
99
|
+
}, [disableSwitch, setColorMode]);
|
|
100
|
+
|
|
101
|
+
// PCS is coerced to light mode when printing, which causes the color mode to
|
|
102
|
+
// be reset to dark when exiting print mode, disregarding user settings. When
|
|
103
|
+
// the listener fires only because of a print/screen switch, we don't change
|
|
104
|
+
// color mode. See https://github.com/facebook/docusaurus/pull/6490
|
|
105
|
+
const previousMediaIsPrint = useRef(false);
|
|
106
|
+
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
if (disableSwitch && !respectPrefersColorScheme) {
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
const mql = window.matchMedia('(prefers-color-scheme: dark)');
|
|
112
|
+
const onChange = ({matches}: MediaQueryListEvent) => {
|
|
113
|
+
if (window.matchMedia('print').matches || previousMediaIsPrint.current) {
|
|
114
|
+
previousMediaIsPrint.current = window.matchMedia('print').matches;
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
setColorMode(matches ? ColorModes.dark : ColorModes.light);
|
|
118
|
+
};
|
|
119
|
+
mql.addListener(onChange);
|
|
120
|
+
return () => mql.removeListener(onChange);
|
|
121
|
+
}, [setColorMode, disableSwitch, respectPrefersColorScheme]);
|
|
122
|
+
|
|
123
|
+
return useMemo(
|
|
124
|
+
() => ({
|
|
125
|
+
colorMode,
|
|
126
|
+
setColorMode,
|
|
127
|
+
get isDarkTheme() {
|
|
128
|
+
if (process.env.NODE_ENV === 'development') {
|
|
129
|
+
console.error(
|
|
130
|
+
'`useColorMode().isDarkTheme` is deprecated. Please use `useColorMode().colorMode === "dark"` instead.',
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
return colorMode === ColorModes.dark;
|
|
134
|
+
},
|
|
135
|
+
setLightTheme() {
|
|
136
|
+
if (process.env.NODE_ENV === 'development') {
|
|
137
|
+
console.error(
|
|
138
|
+
'`useColorMode().setLightTheme` is deprecated. Please use `useColorMode().setColorMode("light")` instead.',
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
setColorMode(ColorModes.light);
|
|
142
|
+
storeColorMode(ColorModes.light);
|
|
143
|
+
},
|
|
144
|
+
setDarkTheme() {
|
|
145
|
+
if (process.env.NODE_ENV === 'development') {
|
|
146
|
+
console.error(
|
|
147
|
+
'`useColorMode().setDarkTheme` is deprecated. Please use `useColorMode().setColorMode("dark")` instead.',
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
setColorMode(ColorModes.dark);
|
|
151
|
+
storeColorMode(ColorModes.dark);
|
|
152
|
+
},
|
|
153
|
+
}),
|
|
154
|
+
[colorMode, setColorMode],
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function ColorModeProvider({
|
|
159
|
+
children,
|
|
160
|
+
}: {
|
|
161
|
+
children: ReactNode;
|
|
162
|
+
}): JSX.Element {
|
|
163
|
+
const value = useContextValue();
|
|
164
|
+
return <Context.Provider value={value}>{children}</Context.Provider>;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export function useColorMode(): ContextValue {
|
|
168
|
+
const context = useContext(Context);
|
|
169
|
+
if (context == null) {
|
|
170
|
+
throw new ReactContextError(
|
|
171
|
+
'ColorModeProvider',
|
|
172
|
+
'Please see https://docusaurus.io/docs/api/themes/configuration#use-color-mode.',
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
return context;
|
|
176
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
import {ReactContextError} from '../utils/reactUtils';
|
|
10
|
+
|
|
11
|
+
type ContextValue = {
|
|
12
|
+
/**
|
|
13
|
+
* The item that the user last opened, `null` when there's none open. On
|
|
14
|
+
* initial render, it will always be `null`, which doesn't necessarily mean
|
|
15
|
+
* there's no category open (can have 0, 1, or many being initially open).
|
|
16
|
+
*/
|
|
17
|
+
expandedItem: number | null;
|
|
18
|
+
/**
|
|
19
|
+
* Set the currently expanded item, when the user opens one. Set the value to
|
|
20
|
+
* `null` when the user closes an open category.
|
|
21
|
+
*/
|
|
22
|
+
setExpandedItem: (a: number | null) => void;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const EmptyContext: unique symbol = Symbol('EmptyContext');
|
|
26
|
+
const Context = React.createContext<ContextValue | typeof EmptyContext>(
|
|
27
|
+
EmptyContext,
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Should be used to wrap one sidebar category level. This provider syncs the
|
|
32
|
+
* expanded states of all sibling categories, and categories can choose to
|
|
33
|
+
* collapse itself if another one is expanded.
|
|
34
|
+
*/
|
|
35
|
+
export function DocSidebarItemsExpandedStateProvider({
|
|
36
|
+
children,
|
|
37
|
+
}: {
|
|
38
|
+
children: ReactNode;
|
|
39
|
+
}): JSX.Element {
|
|
40
|
+
const [expandedItem, setExpandedItem] = useState<number | null>(null);
|
|
41
|
+
const contextValue = useMemo(
|
|
42
|
+
() => ({expandedItem, setExpandedItem}),
|
|
43
|
+
[expandedItem],
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
return <Context.Provider value={contextValue}>{children}</Context.Provider>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function useDocSidebarItemsExpandedState(): ContextValue {
|
|
50
|
+
const value = useContext(Context);
|
|
51
|
+
if (value === EmptyContext) {
|
|
52
|
+
throw new ReactContextError('DocSidebarItemsExpandedStateProvider');
|
|
53
|
+
}
|
|
54
|
+
return value;
|
|
55
|
+
}
|