@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
package/lib/utils/usePrevious.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
import { useRef } from 'react';
|
|
8
|
-
import { useIsomorphicLayoutEffect } from './reactUtils';
|
|
9
|
-
export function usePrevious(value) {
|
|
10
|
-
const ref = useRef();
|
|
11
|
-
useIsomorphicLayoutEffect(() => {
|
|
12
|
-
ref.current = value;
|
|
13
|
-
});
|
|
14
|
-
return ref.current;
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=usePrevious.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"usePrevious.js","sourceRoot":"","sources":["../../src/utils/usePrevious.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,MAAM,EAAC,MAAM,OAAO,CAAC;AAC7B,OAAO,EAAC,yBAAyB,EAAC,MAAM,cAAc,CAAC;AAEvD,MAAM,UAAU,WAAW,CAAI,KAAQ;IACrC,MAAM,GAAG,GAAG,MAAM,EAAK,CAAC;IAExB,yBAAyB,CAAC,GAAG,EAAE;QAC7B,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC;IACtB,CAAC,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC,OAAO,CAAC;AACrB,CAAC"}
|
|
@@ -1,14 +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
|
-
export declare type TOCHighlightConfig = {
|
|
8
|
-
linkClassName: string;
|
|
9
|
-
linkActiveClassName: string;
|
|
10
|
-
minHeadingLevel: number;
|
|
11
|
-
maxHeadingLevel: number;
|
|
12
|
-
};
|
|
13
|
-
export default function useTOCHighlight(config: TOCHighlightConfig | undefined): void;
|
|
14
|
-
//# sourceMappingURL=useTOCHighlight.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useTOCHighlight.d.ts","sourceRoot":"","sources":["../../src/utils/useTOCHighlight.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAgHH,oBAAY,kBAAkB,GAAG;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,eAAe,CACr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AM,OAAO,GAAG,UAAU,CAAC,EAAC,eAAe,EAAE,eAAe,EAAC,CAAC,CAAC;YAC/D,MAAM,YAAY,GAAG,eAAe,CAAC,OAAO,EAAE;gBAC5C,eAAe,EAAE,kBAAkB,CAAC,OAAO;aAC5C,CAAC,CAAC;YACH,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,CAC3B,CAAC,IAAI,EAAE,EAAE,CAAC,YAAY,IAAI,YAAY,CAAC,EAAE,KAAK,kBAAkB,CAAC,IAAI,CAAC,CACvE,CAAC;YAEF,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;gBACrB,qBAAqB,CAAC,IAAI,EAAE,IAAI,KAAK,UAAU,CAAC,CAAC;YACnD,CAAC,CAAC,CAAC;QACL,CAAC;QAED,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;QACtD,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;QAEtD,gBAAgB,EAAE,CAAC;QAEnB,OAAO,GAAG,EAAE;YACV,QAAQ,CAAC,mBAAmB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;YACzD,QAAQ,CAAC,mBAAmB,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAC;QAC3D,CAAC,CAAC;IACJ,CAAC,EAAE,CAAC,MAAM,EAAE,kBAAkB,CAAC,CAAC,CAAC;AACnC,CAAC"}
|
|
@@ -1,156 +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 type {ReactNode} from 'react';
|
|
9
|
-
import React, {
|
|
10
|
-
useState,
|
|
11
|
-
useCallback,
|
|
12
|
-
useEffect,
|
|
13
|
-
useContext,
|
|
14
|
-
useMemo,
|
|
15
|
-
} from 'react';
|
|
16
|
-
|
|
17
|
-
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
|
18
|
-
import {createStorageSlot} from './storageUtils';
|
|
19
|
-
import {useThemeConfig} from './useThemeConfig';
|
|
20
|
-
|
|
21
|
-
type ColorModeContextValue = {
|
|
22
|
-
readonly isDarkTheme: boolean;
|
|
23
|
-
readonly setLightTheme: () => void;
|
|
24
|
-
readonly setDarkTheme: () => void;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const ThemeStorageKey = 'theme';
|
|
28
|
-
const ThemeStorage = createStorageSlot(ThemeStorageKey);
|
|
29
|
-
|
|
30
|
-
const themes = {
|
|
31
|
-
light: 'light',
|
|
32
|
-
dark: 'dark',
|
|
33
|
-
} as const;
|
|
34
|
-
|
|
35
|
-
type Themes = typeof themes[keyof typeof themes];
|
|
36
|
-
|
|
37
|
-
// Ensure to always return a valid theme even if input is invalid
|
|
38
|
-
const coerceToTheme = (theme?: string | null): Themes =>
|
|
39
|
-
theme === themes.dark ? themes.dark : themes.light;
|
|
40
|
-
|
|
41
|
-
const getInitialTheme = (defaultMode: Themes | undefined): Themes => {
|
|
42
|
-
if (!ExecutionEnvironment.canUseDOM) {
|
|
43
|
-
return coerceToTheme(defaultMode);
|
|
44
|
-
}
|
|
45
|
-
return coerceToTheme(document.documentElement.getAttribute('data-theme'));
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const storeTheme = (newTheme: Themes) => {
|
|
49
|
-
ThemeStorage.set(coerceToTheme(newTheme));
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
function useColorModeContextValue(): ColorModeContextValue {
|
|
53
|
-
const {
|
|
54
|
-
colorMode: {defaultMode, disableSwitch, respectPrefersColorScheme},
|
|
55
|
-
} = useThemeConfig();
|
|
56
|
-
const [theme, setTheme] = useState(getInitialTheme(defaultMode));
|
|
57
|
-
|
|
58
|
-
const setLightTheme = useCallback(() => {
|
|
59
|
-
setTheme(themes.light);
|
|
60
|
-
storeTheme(themes.light);
|
|
61
|
-
}, []);
|
|
62
|
-
const setDarkTheme = useCallback(() => {
|
|
63
|
-
setTheme(themes.dark);
|
|
64
|
-
storeTheme(themes.dark);
|
|
65
|
-
}, []);
|
|
66
|
-
|
|
67
|
-
useEffect(() => {
|
|
68
|
-
document.documentElement.setAttribute('data-theme', coerceToTheme(theme));
|
|
69
|
-
}, [theme]);
|
|
70
|
-
|
|
71
|
-
useEffect(() => {
|
|
72
|
-
if (disableSwitch) {
|
|
73
|
-
return undefined;
|
|
74
|
-
}
|
|
75
|
-
const onChange = (e: StorageEvent) => {
|
|
76
|
-
if (e.key !== ThemeStorageKey) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
try {
|
|
80
|
-
const storedTheme = ThemeStorage.get();
|
|
81
|
-
if (storedTheme !== null) {
|
|
82
|
-
setTheme(coerceToTheme(storedTheme));
|
|
83
|
-
}
|
|
84
|
-
} catch (err) {
|
|
85
|
-
console.error(err);
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
window.addEventListener('storage', onChange);
|
|
89
|
-
return () => {
|
|
90
|
-
window.removeEventListener('storage', onChange);
|
|
91
|
-
};
|
|
92
|
-
}, [disableSwitch, setTheme]);
|
|
93
|
-
|
|
94
|
-
// PCS is coerced to light mode when printing, which causes the color mode to
|
|
95
|
-
// be reset to dark when exiting print mode, disregarding user settings. When
|
|
96
|
-
// the listener fires only because of a print/screen switch, we don't change
|
|
97
|
-
// color mode. See https://github.com/facebook/docusaurus/pull/6490
|
|
98
|
-
const previousMediaIsPrint = React.useRef(false);
|
|
99
|
-
|
|
100
|
-
useEffect(() => {
|
|
101
|
-
if (disableSwitch && !respectPrefersColorScheme) {
|
|
102
|
-
return undefined;
|
|
103
|
-
}
|
|
104
|
-
const mql = window.matchMedia('(prefers-color-scheme: dark)');
|
|
105
|
-
const onChange = ({matches}: MediaQueryListEvent) => {
|
|
106
|
-
if (window.matchMedia('print').matches || previousMediaIsPrint.current) {
|
|
107
|
-
previousMediaIsPrint.current = window.matchMedia('print').matches;
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
setTheme(matches ? themes.dark : themes.light);
|
|
111
|
-
};
|
|
112
|
-
mql.addListener(onChange);
|
|
113
|
-
return () => {
|
|
114
|
-
mql.removeListener(onChange);
|
|
115
|
-
};
|
|
116
|
-
}, [disableSwitch, respectPrefersColorScheme]);
|
|
117
|
-
|
|
118
|
-
return {
|
|
119
|
-
isDarkTheme: theme === themes.dark,
|
|
120
|
-
setLightTheme,
|
|
121
|
-
setDarkTheme,
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const ColorModeContext = React.createContext<ColorModeContextValue | undefined>(
|
|
126
|
-
undefined,
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
export function ColorModeProvider({
|
|
130
|
-
children,
|
|
131
|
-
}: {
|
|
132
|
-
children: ReactNode;
|
|
133
|
-
}): JSX.Element {
|
|
134
|
-
const {isDarkTheme, setLightTheme, setDarkTheme} = useColorModeContextValue();
|
|
135
|
-
const contextValue = useMemo(
|
|
136
|
-
() => ({isDarkTheme, setLightTheme, setDarkTheme}),
|
|
137
|
-
[isDarkTheme, setLightTheme, setDarkTheme],
|
|
138
|
-
);
|
|
139
|
-
return (
|
|
140
|
-
<ColorModeContext.Provider value={contextValue}>
|
|
141
|
-
{children}
|
|
142
|
-
</ColorModeContext.Provider>
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export function useColorMode(): ColorModeContextValue {
|
|
147
|
-
const context = useContext<ColorModeContextValue | undefined>(
|
|
148
|
-
ColorModeContext,
|
|
149
|
-
);
|
|
150
|
-
if (context == null) {
|
|
151
|
-
throw new Error(
|
|
152
|
-
'"useColorMode()" is used outside of "Layout" component. Please see https://docusaurus.io/docs/api/themes/configuration#use-color-mode.',
|
|
153
|
-
);
|
|
154
|
-
}
|
|
155
|
-
return context;
|
|
156
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import React, {type ReactNode, useMemo, useState, useContext} from 'react';
|
|
9
|
-
|
|
10
|
-
const EmptyContext: unique symbol = Symbol('EmptyContext');
|
|
11
|
-
const Context = React.createContext<
|
|
12
|
-
DocSidebarItemsExpandedState | typeof EmptyContext
|
|
13
|
-
>(EmptyContext);
|
|
14
|
-
type DocSidebarItemsExpandedState = {
|
|
15
|
-
expandedItem: number | null;
|
|
16
|
-
setExpandedItem: (a: number | null) => void;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export function DocSidebarItemsExpandedStateProvider({
|
|
20
|
-
children,
|
|
21
|
-
}: {
|
|
22
|
-
children: ReactNode;
|
|
23
|
-
}): JSX.Element {
|
|
24
|
-
const [expandedItem, setExpandedItem] = useState<number | null>(null);
|
|
25
|
-
const contextValue = useMemo(
|
|
26
|
-
() => ({expandedItem, setExpandedItem}),
|
|
27
|
-
[expandedItem],
|
|
28
|
-
);
|
|
29
|
-
|
|
30
|
-
return <Context.Provider value={contextValue}>{children}</Context.Provider>;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function useDocSidebarItemsExpandedState(): DocSidebarItemsExpandedState {
|
|
34
|
-
const contextValue = useContext(Context);
|
|
35
|
-
if (contextValue === EmptyContext) {
|
|
36
|
-
throw new Error(
|
|
37
|
-
'This hook requires usage of <DocSidebarItemsExpandedStateProvider>',
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
return contextValue;
|
|
41
|
-
}
|
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import React, {
|
|
9
|
-
createContext,
|
|
10
|
-
type ReactNode,
|
|
11
|
-
useContext,
|
|
12
|
-
useEffect,
|
|
13
|
-
useMemo,
|
|
14
|
-
useState,
|
|
15
|
-
} from 'react';
|
|
16
|
-
import {useThemeConfig, type DocsVersionPersistence} from '../useThemeConfig';
|
|
17
|
-
import {isDocsPluginEnabled} from '../docsUtils';
|
|
18
|
-
|
|
19
|
-
import {
|
|
20
|
-
useAllDocsData,
|
|
21
|
-
type GlobalPluginData,
|
|
22
|
-
} from '@docusaurus/plugin-content-docs/client';
|
|
23
|
-
|
|
24
|
-
import DocsPreferredVersionStorage from './DocsPreferredVersionStorage';
|
|
25
|
-
|
|
26
|
-
type DocsPreferredVersionName = string | null;
|
|
27
|
-
|
|
28
|
-
// State for a single docs plugin instance
|
|
29
|
-
type DocsPreferredVersionPluginState = {
|
|
30
|
-
preferredVersionName: DocsPreferredVersionName;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
// We need to store in state/storage globally
|
|
34
|
-
// one preferred version per docs plugin instance
|
|
35
|
-
// pluginId => pluginState
|
|
36
|
-
type DocsPreferredVersionState = Record<
|
|
37
|
-
string,
|
|
38
|
-
DocsPreferredVersionPluginState
|
|
39
|
-
>;
|
|
40
|
-
|
|
41
|
-
// Initial state is always null as we can't read local storage from node SSR
|
|
42
|
-
function getInitialState(pluginIds: string[]): DocsPreferredVersionState {
|
|
43
|
-
const initialState: DocsPreferredVersionState = {};
|
|
44
|
-
pluginIds.forEach((pluginId) => {
|
|
45
|
-
initialState[pluginId] = {
|
|
46
|
-
preferredVersionName: null,
|
|
47
|
-
};
|
|
48
|
-
});
|
|
49
|
-
return initialState;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Read storage for all docs plugins
|
|
53
|
-
// Assign to each doc plugin a preferred version (if found)
|
|
54
|
-
function readStorageState({
|
|
55
|
-
pluginIds,
|
|
56
|
-
versionPersistence,
|
|
57
|
-
allDocsData,
|
|
58
|
-
}: {
|
|
59
|
-
pluginIds: string[];
|
|
60
|
-
versionPersistence: DocsVersionPersistence;
|
|
61
|
-
allDocsData: Record<string, GlobalPluginData>;
|
|
62
|
-
}): DocsPreferredVersionState {
|
|
63
|
-
// The storage value we read might be stale,
|
|
64
|
-
// and belong to a version that does not exist in the site anymore
|
|
65
|
-
// In such case, we remove the storage value to avoid downstream errors
|
|
66
|
-
function restorePluginState(
|
|
67
|
-
pluginId: string,
|
|
68
|
-
): DocsPreferredVersionPluginState {
|
|
69
|
-
const preferredVersionNameUnsafe = DocsPreferredVersionStorage.read(
|
|
70
|
-
pluginId,
|
|
71
|
-
versionPersistence,
|
|
72
|
-
);
|
|
73
|
-
const pluginData = allDocsData[pluginId];
|
|
74
|
-
const versionExists = pluginData.versions.some(
|
|
75
|
-
(version) => version.name === preferredVersionNameUnsafe,
|
|
76
|
-
);
|
|
77
|
-
if (versionExists) {
|
|
78
|
-
return {preferredVersionName: preferredVersionNameUnsafe};
|
|
79
|
-
}
|
|
80
|
-
DocsPreferredVersionStorage.clear(pluginId, versionPersistence);
|
|
81
|
-
return {preferredVersionName: null};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const initialState: DocsPreferredVersionState = {};
|
|
85
|
-
pluginIds.forEach((pluginId) => {
|
|
86
|
-
initialState[pluginId] = restorePluginState(pluginId);
|
|
87
|
-
});
|
|
88
|
-
return initialState;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function useVersionPersistence(): DocsVersionPersistence {
|
|
92
|
-
return useThemeConfig().docs.versionPersistence;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// Value that will be accessible through context: [state,api]
|
|
96
|
-
function useContextValue() {
|
|
97
|
-
const allDocsData = useAllDocsData();
|
|
98
|
-
const versionPersistence = useVersionPersistence();
|
|
99
|
-
const pluginIds = useMemo(() => Object.keys(allDocsData), [allDocsData]);
|
|
100
|
-
|
|
101
|
-
// Initial state is empty, as we can't read browser storage in node/SSR
|
|
102
|
-
const [state, setState] = useState(() => getInitialState(pluginIds));
|
|
103
|
-
|
|
104
|
-
// On mount, we set the state read from browser storage
|
|
105
|
-
useEffect(() => {
|
|
106
|
-
setState(readStorageState({allDocsData, versionPersistence, pluginIds}));
|
|
107
|
-
}, [allDocsData, versionPersistence, pluginIds]);
|
|
108
|
-
|
|
109
|
-
// The API that we expose to consumer hooks (memo for constant object)
|
|
110
|
-
const api = useMemo(() => {
|
|
111
|
-
function savePreferredVersion(pluginId: string, versionName: string) {
|
|
112
|
-
DocsPreferredVersionStorage.save(
|
|
113
|
-
pluginId,
|
|
114
|
-
versionPersistence,
|
|
115
|
-
versionName,
|
|
116
|
-
);
|
|
117
|
-
setState((s) => ({
|
|
118
|
-
...s,
|
|
119
|
-
[pluginId]: {preferredVersionName: versionName},
|
|
120
|
-
}));
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return {
|
|
124
|
-
savePreferredVersion,
|
|
125
|
-
};
|
|
126
|
-
}, [versionPersistence]);
|
|
127
|
-
|
|
128
|
-
return [state, api] as const;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
type DocsPreferredVersionContextValue = ReturnType<typeof useContextValue>;
|
|
132
|
-
|
|
133
|
-
const Context = createContext<DocsPreferredVersionContextValue | null>(null);
|
|
134
|
-
|
|
135
|
-
export function DocsPreferredVersionContextProvider({
|
|
136
|
-
children,
|
|
137
|
-
}: {
|
|
138
|
-
children: JSX.Element;
|
|
139
|
-
}): JSX.Element {
|
|
140
|
-
if (isDocsPluginEnabled) {
|
|
141
|
-
return (
|
|
142
|
-
<DocsPreferredVersionContextProviderUnsafe>
|
|
143
|
-
{children}
|
|
144
|
-
</DocsPreferredVersionContextProviderUnsafe>
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
return children;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function DocsPreferredVersionContextProviderUnsafe({
|
|
151
|
-
children,
|
|
152
|
-
}: {
|
|
153
|
-
children: ReactNode;
|
|
154
|
-
}): JSX.Element {
|
|
155
|
-
const contextValue = useContextValue();
|
|
156
|
-
return <Context.Provider value={contextValue}>{children}</Context.Provider>;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
export function useDocsPreferredVersionContext(): DocsPreferredVersionContextValue {
|
|
160
|
-
const value = useContext(Context);
|
|
161
|
-
if (!value) {
|
|
162
|
-
throw new Error(
|
|
163
|
-
'Can\'t find docs preferred context, maybe you forgot to use the "DocsPreferredVersionContextProvider"?',
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
return value;
|
|
167
|
-
}
|
|
@@ -1,33 +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 {createStorageSlot} from '../storageUtils';
|
|
9
|
-
import type {DocsVersionPersistence} from '../useThemeConfig';
|
|
10
|
-
|
|
11
|
-
const storageKey = (pluginId: string) => `docs-preferred-version-${pluginId}`;
|
|
12
|
-
|
|
13
|
-
const DocsPreferredVersionStorage = {
|
|
14
|
-
save: (
|
|
15
|
-
pluginId: string,
|
|
16
|
-
persistence: DocsVersionPersistence,
|
|
17
|
-
versionName: string,
|
|
18
|
-
): void => {
|
|
19
|
-
createStorageSlot(storageKey(pluginId), {persistence}).set(versionName);
|
|
20
|
-
},
|
|
21
|
-
|
|
22
|
-
read: (
|
|
23
|
-
pluginId: string,
|
|
24
|
-
persistence: DocsVersionPersistence,
|
|
25
|
-
): string | null =>
|
|
26
|
-
createStorageSlot(storageKey(pluginId), {persistence}).get(),
|
|
27
|
-
|
|
28
|
-
clear: (pluginId: string, persistence: DocsVersionPersistence): void => {
|
|
29
|
-
createStorageSlot(storageKey(pluginId), {persistence}).del();
|
|
30
|
-
},
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export default DocsPreferredVersionStorage;
|
|
@@ -1,70 +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 {useCallback} from 'react';
|
|
9
|
-
import {useDocsPreferredVersionContext} from './DocsPreferredVersionProvider';
|
|
10
|
-
import {
|
|
11
|
-
useAllDocsData,
|
|
12
|
-
useDocsData,
|
|
13
|
-
type GlobalVersion,
|
|
14
|
-
} from '@docusaurus/plugin-content-docs/client';
|
|
15
|
-
|
|
16
|
-
import {DEFAULT_PLUGIN_ID} from '@docusaurus/constants';
|
|
17
|
-
|
|
18
|
-
// Note, the preferredVersion attribute will always be null before mount
|
|
19
|
-
export function useDocsPreferredVersion(
|
|
20
|
-
pluginId: string | undefined = DEFAULT_PLUGIN_ID,
|
|
21
|
-
): {
|
|
22
|
-
preferredVersion: GlobalVersion | null | undefined;
|
|
23
|
-
savePreferredVersionName: (versionName: string) => void;
|
|
24
|
-
} {
|
|
25
|
-
const docsData = useDocsData(pluginId);
|
|
26
|
-
const [state, api] = useDocsPreferredVersionContext();
|
|
27
|
-
|
|
28
|
-
const {preferredVersionName} = state[pluginId];
|
|
29
|
-
|
|
30
|
-
const preferredVersion = preferredVersionName
|
|
31
|
-
? docsData.versions.find((version) => version.name === preferredVersionName)
|
|
32
|
-
: null;
|
|
33
|
-
|
|
34
|
-
const savePreferredVersionName = useCallback(
|
|
35
|
-
(versionName: string) => {
|
|
36
|
-
api.savePreferredVersion(pluginId, versionName);
|
|
37
|
-
},
|
|
38
|
-
[api, pluginId],
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
return {preferredVersion, savePreferredVersionName} as const;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function useDocsPreferredVersionByPluginId(): Record<
|
|
45
|
-
string,
|
|
46
|
-
GlobalVersion | null | undefined
|
|
47
|
-
> {
|
|
48
|
-
const allDocsData = useAllDocsData();
|
|
49
|
-
const [state] = useDocsPreferredVersionContext();
|
|
50
|
-
|
|
51
|
-
function getPluginIdPreferredVersion(pluginId: string) {
|
|
52
|
-
const docsData = allDocsData[pluginId];
|
|
53
|
-
const {preferredVersionName} = state[pluginId];
|
|
54
|
-
|
|
55
|
-
return preferredVersionName
|
|
56
|
-
? docsData.versions.find(
|
|
57
|
-
(version) => version.name === preferredVersionName,
|
|
58
|
-
)
|
|
59
|
-
: null;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const pluginIds = Object.keys(allDocsData);
|
|
63
|
-
|
|
64
|
-
const result: Record<string, GlobalVersion | null | undefined> = {};
|
|
65
|
-
pluginIds.forEach((pluginId) => {
|
|
66
|
-
result[pluginId] = getPluginIdPreferredVersion(pluginId);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
return result;
|
|
70
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import React, {
|
|
9
|
-
useState,
|
|
10
|
-
type ReactNode,
|
|
11
|
-
useContext,
|
|
12
|
-
createContext,
|
|
13
|
-
useEffect,
|
|
14
|
-
type ComponentType,
|
|
15
|
-
useMemo,
|
|
16
|
-
} from 'react';
|
|
17
|
-
|
|
18
|
-
/*
|
|
19
|
-
The idea behind all this is that a specific component must be able to fill a
|
|
20
|
-
placeholder in the generic layout. The doc page should be able to fill the
|
|
21
|
-
secondary menu of the main mobile navbar. This permits to reduce coupling
|
|
22
|
-
between the main layout and the specific page.
|
|
23
|
-
|
|
24
|
-
This kind of feature is often called portal/teleport/gateway... various
|
|
25
|
-
unmaintained React libs exist. Most up-to-date one: https://github.com/gregberge/react-teleporter
|
|
26
|
-
Not sure any of those is safe regarding concurrent mode.
|
|
27
|
-
*/
|
|
28
|
-
|
|
29
|
-
type ExtraProps = {
|
|
30
|
-
toggleSidebar: () => void;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export type MobileSecondaryMenuComponent<Props> = ComponentType<
|
|
34
|
-
Props & ExtraProps
|
|
35
|
-
>;
|
|
36
|
-
|
|
37
|
-
type State = {
|
|
38
|
-
component: MobileSecondaryMenuComponent<unknown>;
|
|
39
|
-
props: unknown;
|
|
40
|
-
} | null;
|
|
41
|
-
|
|
42
|
-
function useContextValue() {
|
|
43
|
-
return useState<State>(null);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
type ContextValue = ReturnType<typeof useContextValue>;
|
|
47
|
-
|
|
48
|
-
const Context = createContext<ContextValue | null>(null);
|
|
49
|
-
|
|
50
|
-
export function MobileSecondaryMenuProvider({
|
|
51
|
-
children,
|
|
52
|
-
}: {
|
|
53
|
-
children: ReactNode;
|
|
54
|
-
}): JSX.Element {
|
|
55
|
-
return (
|
|
56
|
-
<Context.Provider value={useContextValue()}>{children}</Context.Provider>
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function useMobileSecondaryMenuContext(): ContextValue {
|
|
61
|
-
const value = useContext(Context);
|
|
62
|
-
if (value === null) {
|
|
63
|
-
throw new Error(
|
|
64
|
-
'MobileSecondaryMenuProvider was not used correctly, context value is null',
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
return value;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export function useMobileSecondaryMenuRenderer(): (
|
|
71
|
-
extraProps: ExtraProps,
|
|
72
|
-
) => ReactNode | undefined {
|
|
73
|
-
const [state] = useMobileSecondaryMenuContext();
|
|
74
|
-
if (state) {
|
|
75
|
-
const Comp = state.component;
|
|
76
|
-
return function render(extraProps) {
|
|
77
|
-
return <Comp {...state.props} {...extraProps} />;
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
return () => undefined;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function useShallowMemoizedObject<O extends Record<string, unknown>>(obj: O) {
|
|
84
|
-
return useMemo(
|
|
85
|
-
() => obj,
|
|
86
|
-
// Is this safe?
|
|
87
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
88
|
-
[...Object.keys(obj), ...Object.values(obj)],
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// Fill the secondary menu placeholder with some real content
|
|
93
|
-
export function MobileSecondaryMenuFiller<
|
|
94
|
-
Props extends Record<string, unknown>,
|
|
95
|
-
>({
|
|
96
|
-
component,
|
|
97
|
-
props,
|
|
98
|
-
}: {
|
|
99
|
-
component: MobileSecondaryMenuComponent<Props & ExtraProps>;
|
|
100
|
-
props: Props;
|
|
101
|
-
}): JSX.Element | null {
|
|
102
|
-
const [, setState] = useMobileSecondaryMenuContext();
|
|
103
|
-
|
|
104
|
-
// To avoid useless context re-renders, props are memoized shallowly
|
|
105
|
-
const memoizedProps = useShallowMemoizedObject(props);
|
|
106
|
-
|
|
107
|
-
useEffect(() => {
|
|
108
|
-
// @ts-expect-error: context is not 100% type-safe but it's ok
|
|
109
|
-
setState({component, props: memoizedProps});
|
|
110
|
-
}, [setState, component, memoizedProps]);
|
|
111
|
-
|
|
112
|
-
useEffect(() => () => setState(null), [setState]);
|
|
113
|
-
|
|
114
|
-
return null;
|
|
115
|
-
}
|
package/src/utils/pathUtils.ts
DELETED
|
@@ -1,19 +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
|
-
// Compare the 2 paths, case insensitive and ignoring trailing slash
|
|
9
|
-
export const isSamePath = (
|
|
10
|
-
path1: string | undefined,
|
|
11
|
-
path2: string | undefined,
|
|
12
|
-
): boolean => {
|
|
13
|
-
const normalize = (pathname: string | undefined) =>
|
|
14
|
-
(!pathname || pathname?.endsWith('/')
|
|
15
|
-
? pathname
|
|
16
|
-
: `${pathname}/`
|
|
17
|
-
)?.toLowerCase();
|
|
18
|
-
return normalize(path1) === normalize(path2);
|
|
19
|
-
};
|