@docusaurus/theme-common 2.0.0-beta.16 → 2.0.0-beta.19
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/Details.d.ts +14 -0
- 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 +18 -10
- 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 +11 -6
- package/lib/components/Details/index.js.map +1 -1
- package/lib/components/Details/styles.module.css +4 -0
- 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} +15 -14
- package/lib/contexts/announcementBar.js.map +1 -0
- package/lib/contexts/colorMode.d.ts +27 -0
- package/lib/contexts/colorMode.d.ts.map +1 -0
- package/lib/contexts/colorMode.js +132 -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 +10 -4
- package/lib/contexts/docSidebarItemsExpandedState.js.map +1 -0
- package/lib/contexts/docsPreferredVersion.d.ts +31 -0
- package/lib/contexts/docsPreferredVersion.d.ts.map +1 -0
- package/lib/contexts/docsPreferredVersion.js +128 -0
- package/lib/contexts/docsPreferredVersion.js.map +1 -0
- package/lib/contexts/docsSidebar.d.ts +26 -0
- package/lib/contexts/docsSidebar.d.ts.map +1 -0
- package/lib/contexts/docsSidebar.js +30 -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/content.d.ts +37 -0
- package/lib/contexts/navbarSecondaryMenu/content.d.ts.map +1 -0
- package/lib/contexts/navbarSecondaryMenu/content.js +56 -0
- package/lib/contexts/navbarSecondaryMenu/content.js.map +1 -0
- package/lib/contexts/navbarSecondaryMenu/display.d.ts +24 -0
- package/lib/contexts/navbarSecondaryMenu/display.d.ts.map +1 -0
- package/lib/contexts/navbarSecondaryMenu/display.js +62 -0
- package/lib/contexts/navbarSecondaryMenu/display.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} +15 -20
- package/lib/contexts/tabGroupChoice.js.map +1 -0
- package/lib/hooks/useBackToTopButton.d.ts +27 -0
- package/lib/hooks/useBackToTopButton.d.ts.map +1 -0
- package/lib/hooks/useBackToTopButton.js +50 -0
- package/lib/hooks/useBackToTopButton.js.map +1 -0
- package/lib/hooks/useCodeWordWrap.d.ts +14 -0
- package/lib/hooks/useCodeWordWrap.d.ts.map +1 -0
- package/lib/hooks/useCodeWordWrap.js +41 -0
- package/lib/hooks/useCodeWordWrap.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 +10 -9
- 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 +6 -2
- package/lib/hooks/usePrismTheme.d.ts.map +1 -1
- package/lib/hooks/usePrismTheme.js +9 -6
- 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 +4 -4
- package/lib/hooks/useSearchPage.js.map +1 -1
- package/lib/hooks/useSkipToContent.d.ts +25 -0
- package/lib/hooks/useSkipToContent.d.ts.map +1 -0
- package/lib/hooks/useSkipToContent.js +35 -0
- package/lib/hooks/useSkipToContent.js.map +1 -0
- package/lib/hooks/useTOCHighlight.d.ts +25 -0
- package/lib/hooks/useTOCHighlight.d.ts.map +1 -0
- package/lib/{utils → hooks}/useTOCHighlight.js +18 -16
- 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 +31 -32
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +31 -26
- 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 +57 -4
- package/lib/utils/codeBlockUtils.d.ts.map +1 -1
- package/lib/utils/codeBlockUtils.js +111 -80
- package/lib/utils/codeBlockUtils.js.map +1 -1
- package/lib/utils/docsUtils.d.ts +83 -18
- package/lib/utils/docsUtils.d.ts.map +1 -1
- package/lib/utils/docsUtils.js +143 -62
- 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 +32 -0
- package/lib/utils/navbarUtils.js.map +1 -0
- package/lib/utils/reactUtils.d.ts +21 -7
- package/lib/utils/reactUtils.d.ts.map +1 -1
- package/lib/utils/reactUtils.js +34 -6
- 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 +19 -4
- package/lib/utils/routesUtils.d.ts.map +1 -1
- package/lib/utils/routesUtils.js +40 -19
- package/lib/utils/routesUtils.js.map +1 -1
- package/lib/utils/scrollUtils.d.ts +55 -25
- package/lib/utils/scrollUtils.d.ts.map +1 -1
- package/lib/utils/scrollUtils.js +85 -21
- 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 +36 -0
- package/lib/utils/searchUtils.js.map +1 -1
- package/lib/utils/storageUtils.d.ts +12 -9
- package/lib/utils/storageUtils.d.ts.map +1 -1
- package/lib/utils/storageUtils.js +21 -13
- package/lib/utils/storageUtils.js.map +1 -1
- package/lib/utils/tagsUtils.d.ts +7 -8
- package/lib/utils/tagsUtils.d.ts.map +1 -1
- package/lib/utils/tagsUtils.js +8 -6
- package/lib/utils/tagsUtils.js.map +1 -1
- package/lib/utils/tocUtils.d.ts +17 -1
- package/lib/utils/tocUtils.d.ts.map +1 -1
- package/lib/utils/tocUtils.js +20 -9
- 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 +28 -22
- 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 +18 -11
- package/src/components/Collapsible/index.tsx +42 -24
- package/src/components/Details/index.tsx +15 -8
- package/src/components/Details/styles.module.css +4 -0
- package/src/{utils/announcementBarUtils.tsx → contexts/announcementBar.tsx} +20 -22
- package/src/contexts/colorMode.tsx +199 -0
- package/src/contexts/docSidebarItemsExpandedState.tsx +55 -0
- package/src/contexts/docsPreferredVersion.tsx +253 -0
- package/src/contexts/docsSidebar.tsx +50 -0
- package/src/contexts/docsVersion.tsx +36 -0
- package/src/contexts/navbarMobileSidebar.tsx +99 -0
- package/src/contexts/navbarSecondaryMenu/content.tsx +110 -0
- package/src/contexts/navbarSecondaryMenu/display.tsx +102 -0
- package/src/{utils/tabGroupChoiceUtils.tsx → contexts/tabGroupChoice.tsx} +28 -33
- package/src/hooks/useBackToTopButton.ts +73 -0
- package/src/hooks/useCodeWordWrap.ts +56 -0
- package/src/hooks/useHideableNavbar.ts +12 -14
- package/src/hooks/useKeyboardNavigation.ts +11 -3
- package/src/hooks/useLockBodyScroll.ts +5 -2
- package/src/hooks/usePrismTheme.ts +10 -6
- package/src/hooks/useSearchPage.ts +18 -5
- package/src/hooks/useSkipToContent.ts +58 -0
- package/src/{utils → hooks}/useTOCHighlight.ts +24 -15
- package/src/hooks/useWindowSize.ts +14 -12
- package/src/index.ts +77 -57
- package/src/utils/ThemeClassNames.ts +10 -6
- package/src/utils/codeBlockUtils.ts +178 -92
- package/src/utils/docsUtils.tsx +205 -101
- 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 +45 -0
- package/src/utils/reactUtils.tsx +40 -7
- package/src/utils/regexpUtils.ts +2 -1
- package/src/utils/routesUtils.ts +58 -22
- package/src/utils/scrollUtils.tsx +120 -49
- package/src/utils/searchUtils.ts +51 -0
- package/src/utils/storageUtils.ts +23 -15
- package/src/utils/tagsUtils.ts +12 -10
- package/src/utils/tocUtils.ts +22 -11
- 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 +23 -22
- package/yarn-error.log +20199 -0
- package/lib/utils/announcementBarUtils.d.ts.map +0 -1
- package/lib/utils/announcementBarUtils.js.map +0 -1
- package/lib/utils/colorModeUtils.d.ts +0 -18
- package/lib/utils/colorModeUtils.d.ts.map +0 -1
- package/lib/utils/colorModeUtils.js +0 -106
- 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 -91
- 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 -50
- 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 -17
- 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 -37
- 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 -156
- package/src/utils/docSidebarItemsExpandedState.tsx +0 -41
- package/src/utils/docsPreferredVersion/DocsPreferredVersionProvider.tsx +0 -167
- package/src/utils/docsPreferredVersion/DocsPreferredVersionStorage.ts +0 -33
- package/src/utils/docsPreferredVersion/useDocsPreferredVersion.ts +0 -70
- package/src/utils/mobileSecondaryMenu.tsx +0 -115
- package/src/utils/pathUtils.ts +0 -19
- package/src/utils/useContextualSearchFilters.ts +0 -53
- package/src/utils/usePrevious.ts +0 -19
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
/// <reference types="react" />
|
|
8
|
+
/// <reference types="@docusaurus/plugin-content-docs" />
|
|
9
|
+
import { type GlobalVersion } from '@docusaurus/plugin-content-docs/client';
|
|
10
|
+
/**
|
|
11
|
+
* This is a maybe-layer. If the docs plugin is not enabled, this provider is a
|
|
12
|
+
* simple pass-through.
|
|
13
|
+
*/
|
|
14
|
+
export declare function DocsPreferredVersionContextProvider({ children, }: {
|
|
15
|
+
children: JSX.Element;
|
|
16
|
+
}): JSX.Element;
|
|
17
|
+
/**
|
|
18
|
+
* Returns a read-write interface to a plugin's preferred version. The
|
|
19
|
+
* "preferred version" is defined as the last version that the user visited.
|
|
20
|
+
* For example, if a user is using v3, even when v4 is later published, the user
|
|
21
|
+
* would still be browsing v3 docs when she opens the website next time. Note,
|
|
22
|
+
* the `preferredVersion` attribute will always be `null` before mount.
|
|
23
|
+
*/
|
|
24
|
+
export declare function useDocsPreferredVersion(pluginId?: string | undefined): {
|
|
25
|
+
preferredVersion: GlobalVersion | null;
|
|
26
|
+
savePreferredVersionName: (versionName: string) => void;
|
|
27
|
+
};
|
|
28
|
+
export declare function useDocsPreferredVersionByPluginId(): {
|
|
29
|
+
[pluginId: string]: GlobalVersion | null;
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=docsPreferredVersion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docsPreferredVersion.d.ts","sourceRoot":"","sources":["../../src/contexts/docsPreferredVersion.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;;;AAkBH,OAAO,EAIL,KAAK,aAAa,EACnB,MAAM,wCAAwC,CAAC;AAgJhD;;;GAGG;AACH,wBAAgB,mCAAmC,CAAC,EAClD,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC;CACvB,GAAG,GAAG,CAAC,OAAO,CASd;AAUD;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,GAAE,MAAM,GAAG,SAA6B,GAC/C;IACD,gBAAgB,EAAE,aAAa,GAAG,IAAI,CAAC;IACvC,wBAAwB,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;CACzD,CAmBA;AAED,wBAAgB,iCAAiC,IAAI;IACnD,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI,CAAC;CAC1C,CAkBA"}
|
|
@@ -0,0 +1,128 @@
|
|
|
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 React, { useContext, useEffect, useMemo, useState, useCallback, } from 'react';
|
|
8
|
+
import { useThemeConfig, } from '../utils/useThemeConfig';
|
|
9
|
+
import { isDocsPluginEnabled } from '../utils/docsUtils';
|
|
10
|
+
import { ReactContextError } from '../utils/reactUtils';
|
|
11
|
+
import { createStorageSlot } from '../utils/storageUtils';
|
|
12
|
+
import { useAllDocsData, useDocsData, } from '@docusaurus/plugin-content-docs/client';
|
|
13
|
+
import { DEFAULT_PLUGIN_ID } from '@docusaurus/constants';
|
|
14
|
+
const storageKey = (pluginId) => `docs-preferred-version-${pluginId}`;
|
|
15
|
+
const DocsPreferredVersionStorage = {
|
|
16
|
+
save: (pluginId, persistence, versionName) => {
|
|
17
|
+
createStorageSlot(storageKey(pluginId), { persistence }).set(versionName);
|
|
18
|
+
},
|
|
19
|
+
read: (pluginId, persistence) => createStorageSlot(storageKey(pluginId), { persistence }).get(),
|
|
20
|
+
clear: (pluginId, persistence) => {
|
|
21
|
+
createStorageSlot(storageKey(pluginId), { persistence }).del();
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Initial state is always null as we can't read local storage from node SSR
|
|
26
|
+
*/
|
|
27
|
+
const getInitialState = (pluginIds) => Object.fromEntries(pluginIds.map((id) => [id, { preferredVersionName: null }]));
|
|
28
|
+
/**
|
|
29
|
+
* Read storage for all docs plugins, assigning each doc plugin a preferred
|
|
30
|
+
* version (if found)
|
|
31
|
+
*/
|
|
32
|
+
function readStorageState({ pluginIds, versionPersistence, allDocsData, }) {
|
|
33
|
+
/**
|
|
34
|
+
* The storage value we read might be stale, and belong to a version that does
|
|
35
|
+
* not exist in the site anymore. In such case, we remove the storage value to
|
|
36
|
+
* avoid downstream errors.
|
|
37
|
+
*/
|
|
38
|
+
function restorePluginState(pluginId) {
|
|
39
|
+
const preferredVersionNameUnsafe = DocsPreferredVersionStorage.read(pluginId, versionPersistence);
|
|
40
|
+
const pluginData = allDocsData[pluginId];
|
|
41
|
+
const versionExists = pluginData.versions.some((version) => version.name === preferredVersionNameUnsafe);
|
|
42
|
+
if (versionExists) {
|
|
43
|
+
return { preferredVersionName: preferredVersionNameUnsafe };
|
|
44
|
+
}
|
|
45
|
+
DocsPreferredVersionStorage.clear(pluginId, versionPersistence);
|
|
46
|
+
return { preferredVersionName: null };
|
|
47
|
+
}
|
|
48
|
+
return Object.fromEntries(pluginIds.map((id) => [id, restorePluginState(id)]));
|
|
49
|
+
}
|
|
50
|
+
function useVersionPersistence() {
|
|
51
|
+
return useThemeConfig().docs.versionPersistence;
|
|
52
|
+
}
|
|
53
|
+
const Context = React.createContext(null);
|
|
54
|
+
function useContextValue() {
|
|
55
|
+
const allDocsData = useAllDocsData();
|
|
56
|
+
const versionPersistence = useVersionPersistence();
|
|
57
|
+
const pluginIds = useMemo(() => Object.keys(allDocsData), [allDocsData]);
|
|
58
|
+
// Initial state is empty, as we can't read browser storage in node/SSR
|
|
59
|
+
const [state, setState] = useState(() => getInitialState(pluginIds));
|
|
60
|
+
// On mount, we set the state read from browser storage
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
setState(readStorageState({ allDocsData, versionPersistence, pluginIds }));
|
|
63
|
+
}, [allDocsData, versionPersistence, pluginIds]);
|
|
64
|
+
// The API that we expose to consumer hooks (memo for constant object)
|
|
65
|
+
const api = useMemo(() => {
|
|
66
|
+
function savePreferredVersion(pluginId, versionName) {
|
|
67
|
+
DocsPreferredVersionStorage.save(pluginId, versionPersistence, versionName);
|
|
68
|
+
setState((s) => ({
|
|
69
|
+
...s,
|
|
70
|
+
[pluginId]: { preferredVersionName: versionName },
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
return {
|
|
74
|
+
savePreferredVersion,
|
|
75
|
+
};
|
|
76
|
+
}, [versionPersistence]);
|
|
77
|
+
return [state, api];
|
|
78
|
+
}
|
|
79
|
+
function DocsPreferredVersionContextProviderUnsafe({ children, }) {
|
|
80
|
+
const value = useContextValue();
|
|
81
|
+
return React.createElement(Context.Provider, { value: value }, children);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* This is a maybe-layer. If the docs plugin is not enabled, this provider is a
|
|
85
|
+
* simple pass-through.
|
|
86
|
+
*/
|
|
87
|
+
export function DocsPreferredVersionContextProvider({ children, }) {
|
|
88
|
+
if (isDocsPluginEnabled) {
|
|
89
|
+
return (React.createElement(DocsPreferredVersionContextProviderUnsafe, null, children));
|
|
90
|
+
}
|
|
91
|
+
return children;
|
|
92
|
+
}
|
|
93
|
+
function useDocsPreferredVersionContext() {
|
|
94
|
+
const value = useContext(Context);
|
|
95
|
+
if (!value) {
|
|
96
|
+
throw new ReactContextError('DocsPreferredVersionContextProvider');
|
|
97
|
+
}
|
|
98
|
+
return value;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Returns a read-write interface to a plugin's preferred version. The
|
|
102
|
+
* "preferred version" is defined as the last version that the user visited.
|
|
103
|
+
* For example, if a user is using v3, even when v4 is later published, the user
|
|
104
|
+
* would still be browsing v3 docs when she opens the website next time. Note,
|
|
105
|
+
* the `preferredVersion` attribute will always be `null` before mount.
|
|
106
|
+
*/
|
|
107
|
+
export function useDocsPreferredVersion(pluginId = DEFAULT_PLUGIN_ID) {
|
|
108
|
+
const docsData = useDocsData(pluginId);
|
|
109
|
+
const [state, api] = useDocsPreferredVersionContext();
|
|
110
|
+
const { preferredVersionName } = state[pluginId];
|
|
111
|
+
const preferredVersion = docsData.versions.find((version) => version.name === preferredVersionName) ?? null;
|
|
112
|
+
const savePreferredVersionName = useCallback((versionName) => {
|
|
113
|
+
api.savePreferredVersion(pluginId, versionName);
|
|
114
|
+
}, [api, pluginId]);
|
|
115
|
+
return { preferredVersion, savePreferredVersionName };
|
|
116
|
+
}
|
|
117
|
+
export function useDocsPreferredVersionByPluginId() {
|
|
118
|
+
const allDocsData = useAllDocsData();
|
|
119
|
+
const [state] = useDocsPreferredVersionContext();
|
|
120
|
+
function getPluginIdPreferredVersion(pluginId) {
|
|
121
|
+
const docsData = allDocsData[pluginId];
|
|
122
|
+
const { preferredVersionName } = state[pluginId];
|
|
123
|
+
return (docsData.versions.find((version) => version.name === preferredVersionName) ?? null);
|
|
124
|
+
}
|
|
125
|
+
const pluginIds = Object.keys(allDocsData);
|
|
126
|
+
return Object.fromEntries(pluginIds.map((id) => [id, getPluginIdPreferredVersion(id)]));
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=docsPreferredVersion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docsPreferredVersion.js","sourceRoot":"","sources":["../../src/contexts/docsPreferredVersion.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,EACZ,UAAU,EACV,SAAS,EACT,OAAO,EACP,QAAQ,EACR,WAAW,GAEZ,MAAM,OAAO,CAAC;AACf,OAAO,EACL,cAAc,GAEf,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAC,mBAAmB,EAAC,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAC,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAC,iBAAiB,EAAC,MAAM,uBAAuB,CAAC;AAExD,OAAO,EACL,cAAc,EACd,WAAW,GAGZ,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EAAC,iBAAiB,EAAC,MAAM,uBAAuB,CAAC;AAExD,MAAM,UAAU,GAAG,CAAC,QAAgB,EAAE,EAAE,CAAC,0BAA0B,QAAQ,EAAE,CAAC;AAE9E,MAAM,2BAA2B,GAAG;IAClC,IAAI,EAAE,CACJ,QAAgB,EAChB,WAAmC,EACnC,WAAmB,EACb,EAAE;QACR,iBAAiB,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,EAAC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C,WAAmB,EAAE,EAAE;QACtB,GAAG,CAAC,oBAAoB,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;IAClD,CAAC,EACD,CAAC,GAAG,EAAE,QAAQ,CAAC,CAChB,CAAC;IAEF,OAAO,EAAC,gBAAgB,EAAE,wBAAwB,EAAC,CAAC;AACtD,CAAC;AAED,MAAM,UAAU,iCAAiC;IAG/C,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IACrC,MAAM,CAAC,KAAK,CAAC,GAAG,8BAA8B,EAAE,CAAC;IAEjD,SAAS,2BAA2B,CAAC,QAAgB;QACnD,MAAM,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAE,CAAC;QACxC,MAAM,EAAC,oBAAoB,EAAC,GAAG,KAAK,CAAC,QAAQ,CAAE,CAAC;QAEhD,OAAO,CACL,QAAQ,CAAC,QAAQ,CAAC,IAAI,CACpB,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,KAAK,oBAAoB,CACnD,IAAI,IAAI,CACV,CAAC;IACJ,CAAC;IACD,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC3C,OAAO,MAAM,CAAC,WAAW,CACvB,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,2BAA2B,CAAC,EAAE,CAAC,CAAC,CAAC,CAC7D,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
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 { type ReactNode } from 'react';
|
|
8
|
+
import type { PropSidebar } from '@docusaurus/plugin-content-docs';
|
|
9
|
+
declare type ContextValue = {
|
|
10
|
+
name: string;
|
|
11
|
+
items: PropSidebar;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Provide the current sidebar to your children.
|
|
15
|
+
*/
|
|
16
|
+
export declare function DocsSidebarProvider({ children, name, items, }: {
|
|
17
|
+
children: ReactNode;
|
|
18
|
+
name: string | undefined;
|
|
19
|
+
items: PropSidebar | undefined;
|
|
20
|
+
}): JSX.Element;
|
|
21
|
+
/**
|
|
22
|
+
* Gets the sidebar that's currently displayed, or `null` if there isn't one
|
|
23
|
+
*/
|
|
24
|
+
export declare function useDocsSidebar(): ContextValue | null;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=docsSidebar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docsSidebar.d.ts","sourceRoot":"","sources":["../../src/contexts/docsSidebar.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAc,EAAsB,KAAK,SAAS,EAAC,MAAM,OAAO,CAAC;AACjE,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,iCAAiC,CAAC;AAOjE,aAAK,YAAY,GAAG;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,WAAW,CAAA;CAAC,CAAC;AAMvD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,QAAQ,EACR,IAAI,EACJ,KAAK,GACN,EAAE;IACD,QAAQ,EAAE,SAAS,CAAC;IACpB,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,KAAK,EAAE,WAAW,GAAG,SAAS,CAAC;CAChC,GAAG,GAAG,CAAC,OAAO,CAMd;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,YAAY,GAAG,IAAI,CAMpD"}
|
|
@@ -0,0 +1,30 @@
|
|
|
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 React, { useMemo, useContext } from 'react';
|
|
8
|
+
import { ReactContextError } from '../utils/reactUtils';
|
|
9
|
+
// Using a Symbol because null is a valid context value (a doc with no sidebar)
|
|
10
|
+
// Inspired by https://github.com/jamiebuilds/unstated-next/blob/master/src/unstated-next.tsx
|
|
11
|
+
const EmptyContext = Symbol('EmptyContext');
|
|
12
|
+
const Context = React.createContext(EmptyContext);
|
|
13
|
+
/**
|
|
14
|
+
* Provide the current sidebar to your children.
|
|
15
|
+
*/
|
|
16
|
+
export function DocsSidebarProvider({ children, name, items, }) {
|
|
17
|
+
const stableValue = useMemo(() => (name && items ? { name, items } : null), [name, items]);
|
|
18
|
+
return React.createElement(Context.Provider, { value: stableValue }, children);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Gets the sidebar that's currently displayed, or `null` if there isn't one
|
|
22
|
+
*/
|
|
23
|
+
export function useDocsSidebar() {
|
|
24
|
+
const value = useContext(Context);
|
|
25
|
+
if (value === EmptyContext) {
|
|
26
|
+
throw new ReactContextError('DocsSidebarProvider');
|
|
27
|
+
}
|
|
28
|
+
return value;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=docsSidebar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docsSidebar.js","sourceRoot":"","sources":["../../src/contexts/docsSidebar.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,EAAC,OAAO,EAAE,UAAU,EAAiB,MAAM,OAAO,CAAC;AAEjE,OAAO,EAAC,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AAEtD,+EAA+E;AAC/E,6FAA6F;AAC7F,MAAM,YAAY,GAAkB,MAAM,CAAC,cAAc,CAAC,CAAC;AAI3D,MAAM,OAAO,GAAG,KAAK,CAAC,aAAa,CACjC,YAAY,CACb,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAClC,QAAQ,EACR,IAAI,EACJ,KAAK,GAKN;IACC,MAAM,WAAW,GAAwB,OAAO,CAC9C,GAAG,EAAE,CAAC,CAAC,IAAI,IAAI,KAAK,CAAC,CAAC,CAAC,EAAC,IAAI,EAAE,KAAK,EAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAC5C,CAAC,IAAI,EAAE,KAAK,CAAC,CACd,CAAC;IACF,OAAO,oBAAC,OAAO,CAAC,QAAQ,IAAC,KAAK,EAAE,WAAW,IAAG,QAAQ,CAAoB,CAAC;AAC7E,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IAClC,IAAI,KAAK,KAAK,YAAY,EAAE;QAC1B,MAAM,IAAI,iBAAiB,CAAC,qBAAqB,CAAC,CAAC;KACpD;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
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 { type ReactNode } from 'react';
|
|
8
|
+
import type { PropVersionMetadata } from '@docusaurus/plugin-content-docs';
|
|
9
|
+
/**
|
|
10
|
+
* Provide the current version's metadata to your children.
|
|
11
|
+
*/
|
|
12
|
+
export declare function DocsVersionProvider({ children, version, }: {
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
version: PropVersionMetadata | null;
|
|
15
|
+
}): JSX.Element;
|
|
16
|
+
/**
|
|
17
|
+
* Gets the version metadata of the current doc page.
|
|
18
|
+
*/
|
|
19
|
+
export declare function useDocsVersion(): PropVersionMetadata;
|
|
20
|
+
//# sourceMappingURL=docsVersion.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docsVersion.d.ts","sourceRoot":"","sources":["../../src/contexts/docsVersion.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAc,EAAC,KAAK,SAAS,EAAa,MAAM,OAAO,CAAC;AACxD,OAAO,KAAK,EAAC,mBAAmB,EAAC,MAAM,iCAAiC,CAAC;AAKzE;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,QAAQ,EACR,OAAO,GACR,EAAE;IACD,QAAQ,EAAE,SAAS,CAAC;IACpB,OAAO,EAAE,mBAAmB,GAAG,IAAI,CAAC;CACrC,GAAG,GAAG,CAAC,OAAO,CAEd;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,mBAAmB,CAMpD"}
|
|
@@ -0,0 +1,26 @@
|
|
|
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 React, { useContext } from 'react';
|
|
8
|
+
import { ReactContextError } from '../utils/reactUtils';
|
|
9
|
+
const Context = React.createContext(null);
|
|
10
|
+
/**
|
|
11
|
+
* Provide the current version's metadata to your children.
|
|
12
|
+
*/
|
|
13
|
+
export function DocsVersionProvider({ children, version, }) {
|
|
14
|
+
return React.createElement(Context.Provider, { value: version }, children);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Gets the version metadata of the current doc page.
|
|
18
|
+
*/
|
|
19
|
+
export function useDocsVersion() {
|
|
20
|
+
const version = useContext(Context);
|
|
21
|
+
if (version === null) {
|
|
22
|
+
throw new ReactContextError('DocsVersionProvider');
|
|
23
|
+
}
|
|
24
|
+
return version;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=docsVersion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docsVersion.js","sourceRoot":"","sources":["../../src/contexts/docsVersion.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,EAAiB,UAAU,EAAC,MAAM,OAAO,CAAC;AAExD,OAAO,EAAC,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AAEtD,MAAM,OAAO,GAAG,KAAK,CAAC,aAAa,CAA6B,IAAI,CAAC,CAAC;AAEtE;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAClC,QAAQ,EACR,OAAO,GAIR;IACC,OAAO,oBAAC,OAAO,CAAC,QAAQ,IAAC,KAAK,EAAE,OAAO,IAAG,QAAQ,CAAoB,CAAC;AACzE,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc;IAC5B,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IACpC,IAAI,OAAO,KAAK,IAAI,EAAE;QACpB,MAAM,IAAI,iBAAiB,CAAC,qBAAqB,CAAC,CAAC;KACpD;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
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 { type ReactNode } from 'react';
|
|
8
|
+
declare type ContextValue = {
|
|
9
|
+
/**
|
|
10
|
+
* Mobile sidebar should be disabled in case it's empty, i.e. no secondary
|
|
11
|
+
* menu + no navbar items). If disabled, the toggle button should not be
|
|
12
|
+
* displayed at all.
|
|
13
|
+
*/
|
|
14
|
+
disabled: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Signals whether the actual sidebar should be displayed (contrary to
|
|
17
|
+
* `disabled` which is about the toggle button). Sidebar should not visible
|
|
18
|
+
* until user interaction to avoid SSR rendering.
|
|
19
|
+
*/
|
|
20
|
+
shouldRender: boolean;
|
|
21
|
+
/** The displayed state. Can be toggled with the `toggle` callback. */
|
|
22
|
+
shown: boolean;
|
|
23
|
+
/** Toggle the `shown` attribute. */
|
|
24
|
+
toggle: () => void;
|
|
25
|
+
};
|
|
26
|
+
export declare function NavbarMobileSidebarProvider({ children, }: {
|
|
27
|
+
children: ReactNode;
|
|
28
|
+
}): JSX.Element;
|
|
29
|
+
export declare function useNavbarMobileSidebar(): ContextValue;
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=navbarMobileSidebar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navbarMobileSidebar.d.ts","sourceRoot":"","sources":["../../src/contexts/navbarMobileSidebar.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAc,EAKZ,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAOf,aAAK,YAAY,GAAG;IAClB;;;;OAIG;IACH,QAAQ,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,YAAY,EAAE,OAAO,CAAC;IACtB,sEAAsE;IACtE,KAAK,EAAE,OAAO,CAAC;IACf,oCAAoC;IACpC,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB,CAAC;AA8CF,wBAAgB,2BAA2B,CAAC,EAC1C,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,SAAS,CAAC;CACrB,GAAG,GAAG,CAAC,OAAO,CAGd;AAED,wBAAgB,sBAAsB,IAAI,YAAY,CAMrD"}
|
|
@@ -0,0 +1,56 @@
|
|
|
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 React, { useCallback, useEffect, useState, useMemo, } from 'react';
|
|
8
|
+
import { useNavbarSecondaryMenuContent } from './navbarSecondaryMenu/content';
|
|
9
|
+
import { useWindowSize } from '../hooks/useWindowSize';
|
|
10
|
+
import { useHistoryPopHandler } from '../utils/historyUtils';
|
|
11
|
+
import { useThemeConfig } from '../utils/useThemeConfig';
|
|
12
|
+
import { ReactContextError } from '../utils/reactUtils';
|
|
13
|
+
const Context = React.createContext(undefined);
|
|
14
|
+
function useIsNavbarMobileSidebarDisabled() {
|
|
15
|
+
const secondaryMenuContent = useNavbarSecondaryMenuContent();
|
|
16
|
+
const { items } = useThemeConfig().navbar;
|
|
17
|
+
return items.length === 0 && !secondaryMenuContent.component;
|
|
18
|
+
}
|
|
19
|
+
function useContextValue() {
|
|
20
|
+
const disabled = useIsNavbarMobileSidebarDisabled();
|
|
21
|
+
const windowSize = useWindowSize();
|
|
22
|
+
const shouldRender = !disabled && windowSize === 'mobile';
|
|
23
|
+
const [shown, setShown] = useState(false);
|
|
24
|
+
// Close mobile sidebar on navigation pop
|
|
25
|
+
// Most likely firing when using the Android back button (but not only)
|
|
26
|
+
useHistoryPopHandler(() => {
|
|
27
|
+
if (shown) {
|
|
28
|
+
setShown(false);
|
|
29
|
+
// Prevent pop navigation; seems desirable enough
|
|
30
|
+
// See https://github.com/facebook/docusaurus/pull/5462#issuecomment-911699846
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
return undefined;
|
|
34
|
+
});
|
|
35
|
+
const toggle = useCallback(() => {
|
|
36
|
+
setShown((s) => !s);
|
|
37
|
+
}, []);
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (windowSize === 'desktop') {
|
|
40
|
+
setShown(false);
|
|
41
|
+
}
|
|
42
|
+
}, [windowSize]);
|
|
43
|
+
return useMemo(() => ({ disabled, shouldRender, toggle, shown }), [disabled, shouldRender, toggle, shown]);
|
|
44
|
+
}
|
|
45
|
+
export function NavbarMobileSidebarProvider({ children, }) {
|
|
46
|
+
const value = useContextValue();
|
|
47
|
+
return React.createElement(Context.Provider, { value: value }, children);
|
|
48
|
+
}
|
|
49
|
+
export function useNavbarMobileSidebar() {
|
|
50
|
+
const context = React.useContext(Context);
|
|
51
|
+
if (context === undefined) {
|
|
52
|
+
throw new ReactContextError('NavbarMobileSidebarProvider');
|
|
53
|
+
}
|
|
54
|
+
return context;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=navbarMobileSidebar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navbarMobileSidebar.js","sourceRoot":"","sources":["../../src/contexts/navbarMobileSidebar.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,EACZ,WAAW,EACX,SAAS,EACT,QAAQ,EACR,OAAO,GAER,MAAM,OAAO,CAAC;AACf,OAAO,EAAC,6BAA6B,EAAC,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAC,aAAa,EAAC,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAC,oBAAoB,EAAC,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAC,cAAc,EAAC,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAC,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AAqBtD,MAAM,OAAO,GAAG,KAAK,CAAC,aAAa,CAA2B,SAAS,CAAC,CAAC;AAEzE,SAAS,gCAAgC;IACvC,MAAM,oBAAoB,GAAG,6BAA6B,EAAE,CAAC;IAC7D,MAAM,EAAC,KAAK,EAAC,GAAG,cAAc,EAAE,CAAC,MAAM,CAAC;IACxC,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,oBAAoB,CAAC,SAAS,CAAC;AAC/D,CAAC;AAED,SAAS,eAAe;IACtB,MAAM,QAAQ,GAAG,gCAAgC,EAAE,CAAC;IACpD,MAAM,UAAU,GAAG,aAAa,EAAE,CAAC;IAEnC,MAAM,YAAY,GAAG,CAAC,QAAQ,IAAI,UAAU,KAAK,QAAQ,CAAC;IAE1D,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAE1C,yCAAyC;IACzC,uEAAuE;IACvE,oBAAoB,CAAC,GAAG,EAAE;QACxB,IAAI,KAAK,EAAE;YACT,QAAQ,CAAC,KAAK,CAAC,CAAC;YAChB,iDAAiD;YACjD,8EAA8E;YAC9E,OAAO,KAAK,CAAC;SACd;QACD,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,EAAE;QAC9B,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IACtB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,UAAU,KAAK,SAAS,EAAE;YAC5B,QAAQ,CAAC,KAAK,CAAC,CAAC;SACjB;IACH,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;IAEjB,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,CAAC,EAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,EAAC,CAAC,EAC/C,CAAC,QAAQ,EAAE,YAAY,EAAE,MAAM,EAAE,KAAK,CAAC,CACxC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,2BAA2B,CAAC,EAC1C,QAAQ,GAGT;IACC,MAAM,KAAK,GAAG,eAAe,EAAE,CAAC;IAChC,OAAO,oBAAC,OAAO,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,IAAG,QAAQ,CAAoB,CAAC;AACvE,CAAC;AAED,MAAM,UAAU,sBAAsB;IACpC,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IAC1C,IAAI,OAAO,KAAK,SAAS,EAAE;QACzB,MAAM,IAAI,iBAAiB,CAAC,6BAA6B,CAAC,CAAC;KAC5D;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
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 { type ReactNode, type ComponentType } from 'react';
|
|
8
|
+
export declare type NavbarSecondaryMenuComponent<Props> = ComponentType<Props>;
|
|
9
|
+
/** @internal */
|
|
10
|
+
export declare type Content = {
|
|
11
|
+
component: NavbarSecondaryMenuComponent<object>;
|
|
12
|
+
props: object;
|
|
13
|
+
} | {
|
|
14
|
+
component: null;
|
|
15
|
+
props: null;
|
|
16
|
+
};
|
|
17
|
+
/** @internal */
|
|
18
|
+
export declare function NavbarSecondaryMenuContentProvider({ children, }: {
|
|
19
|
+
children: ReactNode;
|
|
20
|
+
}): JSX.Element;
|
|
21
|
+
/** @internal */
|
|
22
|
+
export declare function useNavbarSecondaryMenuContent(): Content;
|
|
23
|
+
/**
|
|
24
|
+
* This component renders nothing by itself, but it fills the placeholder in the
|
|
25
|
+
* generic secondary menu layout. This reduces coupling between the main layout
|
|
26
|
+
* and the specific page.
|
|
27
|
+
*
|
|
28
|
+
* This kind of feature is often called portal/teleport/gateway/outlet...
|
|
29
|
+
* Various unmaintained React libs exist. Most up-to-date one:
|
|
30
|
+
* https://github.com/gregberge/react-teleporter
|
|
31
|
+
* Not sure any of those is safe regarding concurrent mode.
|
|
32
|
+
*/
|
|
33
|
+
export declare function NavbarSecondaryMenuFiller<P extends object>({ component, props, }: {
|
|
34
|
+
component: NavbarSecondaryMenuComponent<P>;
|
|
35
|
+
props: P;
|
|
36
|
+
}): JSX.Element | null;
|
|
37
|
+
//# sourceMappingURL=content.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content.d.ts","sourceRoot":"","sources":["../../../src/contexts/navbarSecondaryMenu/content.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAc,EAKZ,KAAK,SAAS,EACd,KAAK,aAAa,EACnB,MAAM,OAAO,CAAC;AAUf,oBAAY,4BAA4B,CAAC,KAAK,IAAI,aAAa,CAAC,KAAK,CAAC,CAAC;AAEvE,gBAAgB;AAChB,oBAAY,OAAO,GACf;IACE,SAAS,EAAE,4BAA4B,CAAC,MAAM,CAAC,CAAC;IAChD,KAAK,EAAE,MAAM,CAAC;CACf,GACD;IAAC,SAAS,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,IAAI,CAAA;CAAC,CAAC;AASnC,gBAAgB;AAChB,wBAAgB,kCAAkC,CAAC,EACjD,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,SAAS,CAAC;CACrB,GAAG,GAAG,CAAC,OAAO,CAMd;AAED,gBAAgB;AAChB,wBAAgB,6BAA6B,IAAI,OAAO,CAMvD;AAWD;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CAAC,CAAC,SAAS,MAAM,EAAE,EAC1D,SAAS,EACT,KAAK,GACN,EAAE;IACD,SAAS,EAAE,4BAA4B,CAAC,CAAC,CAAC,CAAC;IAC3C,KAAK,EAAE,CAAC,CAAC;CACV,GAAG,GAAG,CAAC,OAAO,GAAG,IAAI,CAqBrB"}
|
|
@@ -0,0 +1,56 @@
|
|
|
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 React, { useState, useContext, useEffect, useMemo, } from 'react';
|
|
8
|
+
import { ReactContextError } from '../../utils/reactUtils';
|
|
9
|
+
const Context = React.createContext(null);
|
|
10
|
+
/** @internal */
|
|
11
|
+
export function NavbarSecondaryMenuContentProvider({ children, }) {
|
|
12
|
+
const value = useState({ component: null, props: null });
|
|
13
|
+
return (
|
|
14
|
+
// @ts-expect-error: this context is hard to type
|
|
15
|
+
React.createElement(Context.Provider, { value: value }, children));
|
|
16
|
+
}
|
|
17
|
+
/** @internal */
|
|
18
|
+
export function useNavbarSecondaryMenuContent() {
|
|
19
|
+
const value = useContext(Context);
|
|
20
|
+
if (!value) {
|
|
21
|
+
throw new ReactContextError('NavbarSecondaryMenuContentProvider');
|
|
22
|
+
}
|
|
23
|
+
return value[0];
|
|
24
|
+
}
|
|
25
|
+
function useShallowMemoizedObject(obj) {
|
|
26
|
+
return useMemo(() => obj,
|
|
27
|
+
// Is this safe?
|
|
28
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
29
|
+
[...Object.keys(obj), ...Object.values(obj)]);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* This component renders nothing by itself, but it fills the placeholder in the
|
|
33
|
+
* generic secondary menu layout. This reduces coupling between the main layout
|
|
34
|
+
* and the specific page.
|
|
35
|
+
*
|
|
36
|
+
* This kind of feature is often called portal/teleport/gateway/outlet...
|
|
37
|
+
* Various unmaintained React libs exist. Most up-to-date one:
|
|
38
|
+
* https://github.com/gregberge/react-teleporter
|
|
39
|
+
* Not sure any of those is safe regarding concurrent mode.
|
|
40
|
+
*/
|
|
41
|
+
export function NavbarSecondaryMenuFiller({ component, props, }) {
|
|
42
|
+
const context = useContext(Context);
|
|
43
|
+
if (!context) {
|
|
44
|
+
throw new ReactContextError('NavbarSecondaryMenuContentProvider');
|
|
45
|
+
}
|
|
46
|
+
const [, setContent] = context;
|
|
47
|
+
// To avoid useless context re-renders, props are memoized shallowly
|
|
48
|
+
const memoizedProps = useShallowMemoizedObject(props);
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
// @ts-expect-error: this context is hard to type
|
|
51
|
+
setContent({ component, props: memoizedProps });
|
|
52
|
+
}, [setContent, component, memoizedProps]);
|
|
53
|
+
useEffect(() => () => setContent({ component: null, props: null }), [setContent]);
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=content.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content.js","sourceRoot":"","sources":["../../../src/contexts/navbarSecondaryMenu/content.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,EACZ,QAAQ,EACR,UAAU,EACV,SAAS,EACT,OAAO,GAGR,MAAM,OAAO,CAAC;AACf,OAAO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C;IAEtD,SAAS,CAAC,GAAG,EAAE;QACb,iDAAiD;QACjD,UAAU,CAAC,EAAC,SAAS,EAAE,KAAK,EAAE,aAAa,EAAC,CAAC,CAAC;IAChD,CAAC,EAAE,CAAC,UAAU,EAAE,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC;IAE3C,SAAS,CACP,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,EAAC,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAC,CAAC,EACtD,CAAC,UAAU,CAAC,CACb,CAAC;IAEF,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
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 { type ReactNode } from 'react';
|
|
8
|
+
/** @internal */
|
|
9
|
+
export declare function NavbarSecondaryMenuDisplayProvider({ children, }: {
|
|
10
|
+
children: ReactNode;
|
|
11
|
+
}): JSX.Element;
|
|
12
|
+
/** Wires the logic for rendering the mobile navbar secondary menu. */
|
|
13
|
+
export declare function useNavbarSecondaryMenu(): {
|
|
14
|
+
/** Whether secondary menu is displayed. */
|
|
15
|
+
shown: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Hide the secondary menu; fired either when hiding the entire sidebar, or
|
|
18
|
+
* when going back to the primary menu.
|
|
19
|
+
*/
|
|
20
|
+
hide: () => void;
|
|
21
|
+
/** The content returned from the current secondary menu filler. */
|
|
22
|
+
content: JSX.Element | undefined;
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=display.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"display.d.ts","sourceRoot":"","sources":["../../../src/contexts/navbarSecondaryMenu/display.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAc,EAMZ,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AA6Cf,gBAAgB;AAChB,wBAAgB,kCAAkC,CAAC,EACjD,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,SAAS,CAAC;CACrB,GAAG,GAAG,CAAC,OAAO,CAGd;AAUD,sEAAsE;AACtE,wBAAgB,sBAAsB,IAAI;IACxC,2CAA2C;IAC3C,KAAK,EAAE,OAAO,CAAC;IACf;;;OAGG;IACH,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,mEAAmE;IACnE,OAAO,EAAE,GAAG,CAAC,OAAO,GAAG,SAAS,CAAC;CAClC,CAaA"}
|
|
@@ -0,0 +1,62 @@
|
|
|
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 React, { useState, useContext, useEffect, useMemo, useCallback, } from 'react';
|
|
8
|
+
import { ReactContextError, usePrevious } from '../../utils/reactUtils';
|
|
9
|
+
import { useNavbarMobileSidebar } from '../navbarMobileSidebar';
|
|
10
|
+
import { useNavbarSecondaryMenuContent } from './content';
|
|
11
|
+
const Context = React.createContext(null);
|
|
12
|
+
function useContextValue() {
|
|
13
|
+
const mobileSidebar = useNavbarMobileSidebar();
|
|
14
|
+
const content = useNavbarSecondaryMenuContent();
|
|
15
|
+
const [shown, setShown] = useState(false);
|
|
16
|
+
const hasContent = content.component !== null;
|
|
17
|
+
const previousHasContent = usePrevious(hasContent);
|
|
18
|
+
// When content is become available for the first time (set in useEffect)
|
|
19
|
+
// we set this content to be shown!
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
const contentBecameAvailable = hasContent && !previousHasContent;
|
|
22
|
+
if (contentBecameAvailable) {
|
|
23
|
+
setShown(true);
|
|
24
|
+
}
|
|
25
|
+
}, [hasContent, previousHasContent]);
|
|
26
|
+
// On sidebar close, secondary menu is set to be shown on next re-opening
|
|
27
|
+
// (if any secondary menu content available)
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (!hasContent) {
|
|
30
|
+
setShown(false);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (!mobileSidebar.shown) {
|
|
34
|
+
setShown(true);
|
|
35
|
+
}
|
|
36
|
+
}, [mobileSidebar.shown, hasContent]);
|
|
37
|
+
return useMemo(() => [shown, setShown], [shown]);
|
|
38
|
+
}
|
|
39
|
+
/** @internal */
|
|
40
|
+
export function NavbarSecondaryMenuDisplayProvider({ children, }) {
|
|
41
|
+
const value = useContextValue();
|
|
42
|
+
return React.createElement(Context.Provider, { value: value }, children);
|
|
43
|
+
}
|
|
44
|
+
function renderElement(content) {
|
|
45
|
+
if (content.component) {
|
|
46
|
+
const Comp = content.component;
|
|
47
|
+
return React.createElement(Comp, { ...content.props });
|
|
48
|
+
}
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
/** Wires the logic for rendering the mobile navbar secondary menu. */
|
|
52
|
+
export function useNavbarSecondaryMenu() {
|
|
53
|
+
const value = useContext(Context);
|
|
54
|
+
if (!value) {
|
|
55
|
+
throw new ReactContextError('NavbarSecondaryMenuDisplayProvider');
|
|
56
|
+
}
|
|
57
|
+
const [shown, setShown] = value;
|
|
58
|
+
const hide = useCallback(() => setShown(false), [setShown]);
|
|
59
|
+
const content = useNavbarSecondaryMenuContent();
|
|
60
|
+
return useMemo(() => ({ shown, hide, content: renderElement(content) }), [hide, content, shown]);
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=display.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"display.js","sourceRoot":"","sources":["../../../src/contexts/navbarSecondaryMenu/display.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,EACZ,QAAQ,EACR,UAAU,EACV,SAAS,EACT,OAAO,EACP,WAAW,GAEZ,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AC;AAED,gBAAgB;AAChB,MAAM,UAAU,kCAAkC,CAAC,EACjD,QAAQ,GAGT;IACC,MAAM,KAAK,GAAG,eAAe,EAAE,CAAC;IAChC,OAAO,oBAAC,OAAO,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,IAAG,QAAQ,CAAoB,CAAC;AACvE,CAAC;AAED,SAAS,aAAa,CAAC,OAAgB;IACrC,IAAI,OAAO,CAAC,SAAS,EAAE;QACrB,MAAM,IAAI,GAAG,OAAO,CAAC,SAAS,CAAC;QAC/B,OAAO,oBAAC,IAAI,OAAK,OAAO,CAAC,KAAK,GAAI,CAAC;KACpC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,sBAAsB;IAWpC,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IAClC,IAAI,CAAC,KAAK,EAAE;QACV,MAAM,IAAI,iBAAiB,CAAC,oCAAoC,CAAC,CAAC;KACnE;IACD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,KAAK,CAAC;IAChC,MAAM,IAAI,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC5D,MAAM,OAAO,GAAG,6BAA6B,EAAE,CAAC;IAEhD,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,CAAC,EAAC,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,aAAa,CAAC,OAAO,CAAC,EAAC,CAAC,EACtD,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,CACvB,CAAC;AACJ,CAAC"}
|
|
@@ -5,15 +5,17 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import { type ReactNode } from 'react';
|
|
8
|
-
declare type
|
|
8
|
+
declare type ContextValue = {
|
|
9
|
+
/** A map from `groupId` to the `value` of the saved choice. */
|
|
9
10
|
readonly tabGroupChoices: {
|
|
10
11
|
readonly [groupId: string]: string;
|
|
11
12
|
};
|
|
13
|
+
/** Set the new choice value of a group. */
|
|
12
14
|
readonly setTabGroupChoices: (groupId: string, newChoice: string) => void;
|
|
13
15
|
};
|
|
14
16
|
export declare function TabGroupChoiceProvider({ children, }: {
|
|
15
17
|
children: ReactNode;
|
|
16
18
|
}): JSX.Element;
|
|
17
|
-
export declare function useTabGroupChoice():
|
|
19
|
+
export declare function useTabGroupChoice(): ContextValue;
|
|
18
20
|
export {};
|
|
19
|
-
//# sourceMappingURL=
|
|
21
|
+
//# sourceMappingURL=tabGroupChoice.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tabGroupChoice.d.ts","sourceRoot":"","sources":["../../src/contexts/tabGroupChoice.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAc,EAMZ,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAMf,aAAK,YAAY,GAAG;IAClB,+DAA+D;IAC/D,QAAQ,CAAC,eAAe,EAAE;QAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAAA;KAAC,CAAC;IAC/D,2CAA2C;IAC3C,QAAQ,CAAC,kBAAkB,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;CAC3E,CAAC;AA4CF,wBAAgB,sBAAsB,CAAC,EACrC,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,SAAS,CAAC;CACrB,GAAG,GAAG,CAAC,OAAO,CAGd;AAED,wBAAgB,iBAAiB,IAAI,YAAY,CAMhD"}
|