@docusaurus/theme-common 2.0.0-beta.17 → 2.0.0-beta.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/Collapsible/index.d.ts +32 -4
- package/lib/components/Collapsible/index.d.ts.map +1 -1
- package/lib/components/Collapsible/index.js +12 -3
- package/lib/components/Collapsible/index.js.map +1 -1
- package/lib/components/Details/index.d.ts +6 -1
- package/lib/components/Details/index.d.ts.map +1 -1
- package/lib/components/Details/index.js +8 -4
- package/lib/components/Details/index.js.map +1 -1
- package/lib/{utils/announcementBarUtils.d.ts → contexts/announcementBar.d.ts} +7 -3
- package/lib/contexts/announcementBar.d.ts.map +1 -0
- package/lib/{utils/announcementBarUtils.js → contexts/announcementBar.js} +11 -11
- package/lib/contexts/announcementBar.js.map +1 -0
- package/lib/{utils/colorModeUtils.d.ts → contexts/colorMode.d.ts} +12 -3
- package/lib/contexts/colorMode.d.ts.map +1 -0
- package/lib/contexts/colorMode.js +114 -0
- package/lib/contexts/colorMode.js.map +1 -0
- package/lib/contexts/docSidebarItemsExpandedState.d.ts +31 -0
- package/lib/contexts/docSidebarItemsExpandedState.d.ts.map +1 -0
- package/lib/{utils → contexts}/docSidebarItemsExpandedState.js +9 -4
- package/lib/contexts/docSidebarItemsExpandedState.js.map +1 -0
- package/lib/contexts/docsPreferredVersion.d.ts +28 -0
- package/lib/contexts/docsPreferredVersion.d.ts.map +1 -0
- package/lib/contexts/docsPreferredVersion.js +125 -0
- package/lib/contexts/docsPreferredVersion.js.map +1 -0
- package/lib/contexts/docsSidebar.d.ts +20 -0
- package/lib/contexts/docsSidebar.d.ts.map +1 -0
- package/lib/contexts/docsSidebar.js +29 -0
- package/lib/contexts/docsSidebar.js.map +1 -0
- package/lib/contexts/docsVersion.d.ts +20 -0
- package/lib/contexts/docsVersion.d.ts.map +1 -0
- package/lib/contexts/docsVersion.js +26 -0
- package/lib/contexts/docsVersion.js.map +1 -0
- package/lib/contexts/navbarMobileSidebar.d.ts +31 -0
- package/lib/contexts/navbarMobileSidebar.d.ts.map +1 -0
- package/lib/contexts/navbarMobileSidebar.js +56 -0
- package/lib/contexts/navbarMobileSidebar.js.map +1 -0
- package/lib/contexts/navbarSecondaryMenu.d.ts +38 -0
- package/lib/contexts/navbarSecondaryMenu.d.ts.map +1 -0
- package/lib/contexts/navbarSecondaryMenu.js +93 -0
- package/lib/contexts/navbarSecondaryMenu.js.map +1 -0
- package/lib/{utils/tabGroupChoiceUtils.d.ts → contexts/tabGroupChoice.d.ts} +5 -3
- package/lib/contexts/tabGroupChoice.d.ts.map +1 -0
- package/lib/{utils/tabGroupChoiceUtils.js → contexts/tabGroupChoice.js} +14 -20
- package/lib/contexts/tabGroupChoice.js.map +1 -0
- package/lib/hooks/useHideableNavbar.d.ts +7 -3
- package/lib/hooks/useHideableNavbar.d.ts.map +1 -1
- package/lib/hooks/useHideableNavbar.js +8 -6
- package/lib/hooks/useHideableNavbar.js.map +1 -1
- package/lib/hooks/useKeyboardNavigation.d.ts +11 -1
- package/lib/hooks/useKeyboardNavigation.d.ts.map +1 -1
- package/lib/hooks/useKeyboardNavigation.js +11 -3
- package/lib/hooks/useKeyboardNavigation.js.map +1 -1
- package/lib/hooks/useLockBodyScroll.d.ts +5 -1
- package/lib/hooks/useLockBodyScroll.d.ts.map +1 -1
- package/lib/hooks/useLockBodyScroll.js +5 -1
- package/lib/hooks/useLockBodyScroll.js.map +1 -1
- package/lib/hooks/usePrismTheme.d.ts +5 -1
- package/lib/hooks/usePrismTheme.d.ts.map +1 -1
- package/lib/hooks/usePrismTheme.js +8 -4
- package/lib/hooks/usePrismTheme.js.map +1 -1
- package/lib/hooks/useSearchPage.d.ts +15 -4
- package/lib/hooks/useSearchPage.d.ts.map +1 -1
- package/lib/hooks/useSearchPage.js +3 -2
- package/lib/hooks/useSearchPage.js.map +1 -1
- package/lib/hooks/useTOCHighlight.d.ts +25 -0
- package/lib/hooks/useTOCHighlight.d.ts.map +1 -0
- package/lib/{utils → hooks}/useTOCHighlight.js +13 -9
- package/lib/hooks/useTOCHighlight.js.map +1 -0
- package/lib/hooks/useWindowSize.d.ts +14 -1
- package/lib/hooks/useWindowSize.d.ts.map +1 -1
- package/lib/hooks/useWindowSize.js +14 -11
- package/lib/hooks/useWindowSize.js.map +1 -1
- package/lib/index.d.ts +26 -30
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +26 -24
- package/lib/index.js.map +1 -1
- package/lib/utils/ThemeClassNames.d.ts +7 -0
- package/lib/utils/ThemeClassNames.d.ts.map +1 -1
- package/lib/utils/ThemeClassNames.js +7 -4
- package/lib/utils/ThemeClassNames.js.map +1 -1
- package/lib/utils/codeBlockUtils.d.ts +25 -2
- package/lib/utils/codeBlockUtils.d.ts.map +1 -1
- package/lib/utils/codeBlockUtils.js +36 -35
- package/lib/utils/codeBlockUtils.js.map +1 -1
- package/lib/utils/docsUtils.d.ts +25 -18
- package/lib/utils/docsUtils.d.ts.map +1 -1
- package/lib/utils/docsUtils.js +38 -56
- package/lib/utils/docsUtils.js.map +1 -1
- package/lib/utils/footerUtils.d.ts +13 -0
- package/lib/utils/footerUtils.d.ts.map +1 -0
- package/lib/utils/footerUtils.js +14 -0
- package/lib/utils/footerUtils.js.map +1 -0
- package/lib/utils/generalUtils.d.ts +4 -1
- package/lib/utils/generalUtils.d.ts.map +1 -1
- package/lib/utils/generalUtils.js +6 -3
- package/lib/utils/generalUtils.js.map +1 -1
- package/lib/utils/historyUtils.d.ts +1 -7
- package/lib/utils/historyUtils.d.ts.map +1 -1
- package/lib/utils/historyUtils.js +10 -13
- package/lib/utils/historyUtils.js.map +1 -1
- package/lib/utils/jsUtils.d.ts +1 -1
- package/lib/utils/jsUtils.js +1 -1
- package/lib/utils/metadataUtils.d.ts +38 -0
- package/lib/utils/metadataUtils.d.ts.map +1 -0
- package/lib/utils/metadataUtils.js +61 -0
- package/lib/utils/metadataUtils.js.map +1 -0
- package/lib/utils/navbarUtils.d.ts +21 -0
- package/lib/utils/navbarUtils.d.ts.map +1 -0
- package/lib/utils/navbarUtils.js +30 -0
- package/lib/utils/navbarUtils.js.map +1 -0
- package/lib/utils/reactUtils.d.ts +16 -5
- package/lib/utils/reactUtils.d.ts.map +1 -1
- package/lib/utils/reactUtils.js +28 -7
- package/lib/utils/reactUtils.js.map +1 -1
- package/lib/utils/regexpUtils.d.ts +2 -1
- package/lib/utils/regexpUtils.d.ts.map +1 -1
- package/lib/utils/regexpUtils.js +2 -1
- package/lib/utils/regexpUtils.js.map +1 -1
- package/lib/utils/routesUtils.d.ts +14 -2
- package/lib/utils/routesUtils.d.ts.map +1 -1
- package/lib/utils/routesUtils.js +20 -7
- package/lib/utils/routesUtils.js.map +1 -1
- package/lib/utils/scrollUtils.d.ts +32 -26
- package/lib/utils/scrollUtils.d.ts.map +1 -1
- package/lib/utils/scrollUtils.js +30 -17
- package/lib/utils/scrollUtils.js.map +1 -1
- package/lib/utils/searchUtils.d.ts +12 -0
- package/lib/utils/searchUtils.d.ts.map +1 -1
- package/lib/utils/searchUtils.js +34 -0
- package/lib/utils/searchUtils.js.map +1 -1
- package/lib/utils/storageUtils.d.ts +10 -7
- package/lib/utils/storageUtils.d.ts.map +1 -1
- package/lib/utils/storageUtils.js +20 -12
- package/lib/utils/storageUtils.js.map +1 -1
- package/lib/utils/tagsUtils.d.ts +5 -2
- package/lib/utils/tagsUtils.d.ts.map +1 -1
- package/lib/utils/tagsUtils.js +7 -4
- package/lib/utils/tagsUtils.js.map +1 -1
- package/lib/utils/tocUtils.d.ts +16 -0
- package/lib/utils/tocUtils.d.ts.map +1 -1
- package/lib/utils/tocUtils.js +17 -6
- package/lib/utils/tocUtils.js.map +1 -1
- package/lib/utils/useAlternatePageUtils.d.ts +20 -1
- package/lib/utils/useAlternatePageUtils.d.ts.map +1 -1
- package/lib/utils/useAlternatePageUtils.js +6 -3
- package/lib/utils/useAlternatePageUtils.js.map +1 -1
- package/lib/utils/useLocalPathname.d.ts +5 -0
- package/lib/utils/useLocalPathname.d.ts.map +1 -1
- package/lib/utils/useLocalPathname.js +6 -4
- package/lib/utils/useLocalPathname.js.map +1 -1
- package/lib/utils/useLocationChange.d.ts +7 -5
- package/lib/utils/useLocationChange.d.ts.map +1 -1
- package/lib/utils/useLocationChange.js +6 -2
- package/lib/utils/useLocationChange.js.map +1 -1
- package/lib/utils/usePluralForm.d.ts +11 -0
- package/lib/utils/usePluralForm.d.ts.map +1 -1
- package/lib/utils/usePluralForm.js +19 -24
- package/lib/utils/usePluralForm.js.map +1 -1
- package/lib/utils/useThemeConfig.d.ts +21 -11
- package/lib/utils/useThemeConfig.d.ts.map +1 -1
- package/lib/utils/useThemeConfig.js +3 -0
- package/lib/utils/useThemeConfig.js.map +1 -1
- package/package.json +8 -9
- package/src/components/Collapsible/index.tsx +40 -22
- package/src/components/Details/index.tsx +11 -6
- package/src/{utils/announcementBarUtils.tsx → contexts/announcementBar.tsx} +17 -18
- package/src/contexts/colorMode.tsx +176 -0
- package/src/contexts/docSidebarItemsExpandedState.tsx +55 -0
- package/src/contexts/docsPreferredVersion.tsx +250 -0
- package/src/contexts/docsSidebar.tsx +42 -0
- package/src/contexts/docsVersion.tsx +36 -0
- package/src/contexts/navbarMobileSidebar.tsx +99 -0
- package/src/contexts/navbarSecondaryMenu.tsx +170 -0
- package/src/{utils/tabGroupChoiceUtils.tsx → contexts/tabGroupChoice.tsx} +21 -28
- package/src/hooks/useHideableNavbar.ts +11 -11
- package/src/hooks/useKeyboardNavigation.ts +11 -3
- package/src/hooks/useLockBodyScroll.ts +5 -2
- package/src/hooks/usePrismTheme.ts +8 -4
- package/src/hooks/useSearchPage.ts +18 -5
- package/src/{utils → hooks}/useTOCHighlight.ts +21 -12
- package/src/hooks/useWindowSize.ts +14 -12
- package/src/index.ts +68 -56
- package/src/utils/ThemeClassNames.ts +10 -6
- package/src/utils/codeBlockUtils.ts +49 -47
- package/src/utils/docsUtils.tsx +48 -99
- package/src/utils/footerUtils.ts +18 -0
- package/src/utils/generalUtils.ts +6 -3
- package/src/utils/historyUtils.ts +11 -17
- package/src/utils/jsUtils.ts +1 -1
- package/src/utils/metadataUtils.tsx +115 -0
- package/src/utils/navbarUtils.tsx +40 -0
- package/src/utils/reactUtils.tsx +31 -8
- package/src/utils/regexpUtils.ts +2 -1
- package/src/utils/routesUtils.ts +27 -8
- package/src/utils/scrollUtils.tsx +44 -45
- package/src/utils/searchUtils.ts +49 -0
- package/src/utils/storageUtils.ts +21 -13
- package/src/utils/tagsUtils.ts +14 -7
- package/src/utils/tocUtils.ts +18 -7
- package/src/utils/useAlternatePageUtils.ts +17 -5
- package/src/utils/useLocalPathname.ts +6 -4
- package/src/utils/useLocationChange.ts +12 -10
- package/src/utils/usePluralForm.ts +27 -24
- package/src/utils/useThemeConfig.ts +16 -11
- package/lib/utils/announcementBarUtils.d.ts.map +0 -1
- package/lib/utils/announcementBarUtils.js.map +0 -1
- package/lib/utils/colorModeUtils.d.ts.map +0 -1
- package/lib/utils/colorModeUtils.js +0 -107
- package/lib/utils/colorModeUtils.js.map +0 -1
- package/lib/utils/docSidebarItemsExpandedState.d.ts +0 -17
- package/lib/utils/docSidebarItemsExpandedState.d.ts.map +0 -1
- package/lib/utils/docSidebarItemsExpandedState.js.map +0 -1
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.d.ts +0 -22
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.d.ts.map +0 -1
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js +0 -92
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js.map +0 -1
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.d.ts +0 -14
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.d.ts.map +0 -1
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.js +0 -19
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.js.map +0 -1
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.d.ts +0 -14
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.d.ts.map +0 -1
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.js +0 -41
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.js.map +0 -1
- package/lib/utils/mobileSecondaryMenu.d.ts +0 -21
- package/lib/utils/mobileSecondaryMenu.d.ts.map +0 -1
- package/lib/utils/mobileSecondaryMenu.js +0 -51
- package/lib/utils/mobileSecondaryMenu.js.map +0 -1
- package/lib/utils/pathUtils.d.ts +0 -8
- package/lib/utils/pathUtils.d.ts.map +0 -1
- package/lib/utils/pathUtils.js +0 -14
- package/lib/utils/pathUtils.js.map +0 -1
- package/lib/utils/tabGroupChoiceUtils.d.ts.map +0 -1
- package/lib/utils/tabGroupChoiceUtils.js.map +0 -1
- package/lib/utils/useContextualSearchFilters.d.ts +0 -12
- package/lib/utils/useContextualSearchFilters.d.ts.map +0 -1
- package/lib/utils/useContextualSearchFilters.js +0 -36
- package/lib/utils/useContextualSearchFilters.js.map +0 -1
- package/lib/utils/usePrevious.d.ts +0 -8
- package/lib/utils/usePrevious.d.ts.map +0 -1
- package/lib/utils/usePrevious.js +0 -16
- package/lib/utils/usePrevious.js.map +0 -1
- package/lib/utils/useTOCHighlight.d.ts +0 -14
- package/lib/utils/useTOCHighlight.d.ts.map +0 -1
- package/lib/utils/useTOCHighlight.js.map +0 -1
- package/src/utils/colorModeUtils.tsx +0 -158
- package/src/utils/docSidebarItemsExpandedState.tsx +0 -40
- package/src/utils/docsPreferredVersion/DocsPreferredVersionProvider.tsx +0 -166
- package/src/utils/docsPreferredVersion/DocsPreferredVersionStorage.ts +0 -33
- package/src/utils/docsPreferredVersion/useDocsPreferredVersion.ts +0 -70
- package/src/utils/mobileSecondaryMenu.tsx +0 -114
- package/src/utils/pathUtils.ts +0 -19
- package/src/utils/useContextualSearchFilters.ts +0 -53
- package/src/utils/usePrevious.ts +0 -19
|
@@ -5,5 +5,17 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
export declare const DEFAULT_SEARCH_TAG = "default";
|
|
8
|
+
/** The search tag to append as each doc's metadata. */
|
|
8
9
|
export declare function docVersionSearchTag(pluginId: string, versionName: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Gets the relevant context information for contextual search.
|
|
12
|
+
*
|
|
13
|
+
* The value is generic and not coupled to Algolia/DocSearch, since we may want
|
|
14
|
+
* to support multiple search engines, or allowing users to use their own search
|
|
15
|
+
* engine solution.
|
|
16
|
+
*/
|
|
17
|
+
export declare function useContextualSearchFilters(): {
|
|
18
|
+
locale: string;
|
|
19
|
+
tags: string[];
|
|
20
|
+
};
|
|
9
21
|
//# sourceMappingURL=searchUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"searchUtils.d.ts","sourceRoot":"","sources":["../../src/utils/searchUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"searchUtils.d.ts","sourceRoot":"","sources":["../../src/utils/searchUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,eAAO,MAAM,kBAAkB,YAAY,CAAC;AAE5C,uDAAuD;AACvD,wBAAgB,mBAAmB,CACjC,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,GAClB,MAAM,CAER;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,IAAI;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAC,CAgC7E"}
|
package/lib/utils/searchUtils.js
CHANGED
|
@@ -4,8 +4,42 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
+
import { useAllDocsData, useActivePluginAndVersion, } from '@docusaurus/plugin-content-docs/client';
|
|
8
|
+
import { useDocsPreferredVersionByPluginId } from '../contexts/docsPreferredVersion';
|
|
9
|
+
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
7
10
|
export const DEFAULT_SEARCH_TAG = 'default';
|
|
11
|
+
/** The search tag to append as each doc's metadata. */
|
|
8
12
|
export function docVersionSearchTag(pluginId, versionName) {
|
|
9
13
|
return `docs-${pluginId}-${versionName}`;
|
|
10
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Gets the relevant context information for contextual search.
|
|
17
|
+
*
|
|
18
|
+
* The value is generic and not coupled to Algolia/DocSearch, since we may want
|
|
19
|
+
* to support multiple search engines, or allowing users to use their own search
|
|
20
|
+
* engine solution.
|
|
21
|
+
*/
|
|
22
|
+
export function useContextualSearchFilters() {
|
|
23
|
+
const { i18n } = useDocusaurusContext();
|
|
24
|
+
const allDocsData = useAllDocsData();
|
|
25
|
+
const activePluginAndVersion = useActivePluginAndVersion();
|
|
26
|
+
const docsPreferredVersionByPluginId = useDocsPreferredVersionByPluginId();
|
|
27
|
+
function getDocPluginTags(pluginId) {
|
|
28
|
+
const activeVersion = activePluginAndVersion?.activePlugin?.pluginId === pluginId
|
|
29
|
+
? activePluginAndVersion.activeVersion
|
|
30
|
+
: undefined;
|
|
31
|
+
const preferredVersion = docsPreferredVersionByPluginId[pluginId];
|
|
32
|
+
const latestVersion = allDocsData[pluginId].versions.find((v) => v.isLast);
|
|
33
|
+
const version = activeVersion ?? preferredVersion ?? latestVersion;
|
|
34
|
+
return docVersionSearchTag(pluginId, version.name);
|
|
35
|
+
}
|
|
36
|
+
const tags = [
|
|
37
|
+
DEFAULT_SEARCH_TAG,
|
|
38
|
+
...Object.keys(allDocsData).map(getDocPluginTags),
|
|
39
|
+
];
|
|
40
|
+
return {
|
|
41
|
+
locale: i18n.currentLocale,
|
|
42
|
+
tags,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
11
45
|
//# sourceMappingURL=searchUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"searchUtils.js","sourceRoot":"","sources":["../../src/utils/searchUtils.ts"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C,CAAC,MAAM,CACf,CAAC;QAEH,MAAM,OAAO,GAAG,aAAa,IAAI,gBAAgB,IAAI,aAAa,CAAC;QAEnE,OAAO,mBAAmB,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACrD,CAAC;IAED,MAAM,IAAI,GAAG;QACX,kBAAkB;QAClB,GAAG,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,gBAAgB,CAAC;KAClD,CAAC;IAEF,OAAO;QACL,MAAM,EAAE,IAAI,CAAC,aAAa;QAC1B,IAAI;KACL,CAAC;AACJ,CAAC"}
|
|
@@ -12,17 +12,20 @@ export interface StorageSlot {
|
|
|
12
12
|
del: () => void;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
|
-
* Creates an
|
|
16
|
-
*
|
|
15
|
+
* Creates an interface to work on a particular key in the storage model.
|
|
16
|
+
* Note that this function only initializes the interface, but doesn't allocate
|
|
17
|
+
* anything by itself (i.e. no side-effects).
|
|
18
|
+
*
|
|
19
|
+
* The API is fail-safe, since usage of browser storage should be considered
|
|
17
20
|
* unreliable. Local storage might simply be unavailable (iframe + browser
|
|
18
21
|
* security) or operations might fail individually. Please assume that using
|
|
19
|
-
* this API can be a
|
|
22
|
+
* this API can be a no-op. See also https://github.com/facebook/docusaurus/issues/6036
|
|
20
23
|
*/
|
|
21
|
-
export declare
|
|
22
|
-
persistence?:
|
|
23
|
-
}
|
|
24
|
+
export declare function createStorageSlot(key: string, options?: {
|
|
25
|
+
persistence?: StorageType;
|
|
26
|
+
}): StorageSlot;
|
|
24
27
|
/**
|
|
25
|
-
* Returns a list of all the keys currently stored in browser storage
|
|
28
|
+
* Returns a list of all the keys currently stored in browser storage,
|
|
26
29
|
* or an empty list if browser storage can't be accessed.
|
|
27
30
|
*/
|
|
28
31
|
export declare function listStorageKeys(storageType?: StorageType): string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storageUtils.d.ts","sourceRoot":"","sources":["../../src/utils/storageUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,QAAA,MAAM,YAAY,qDAAsD,CAAC;AAEzE,oBAAY,WAAW,GAAG,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"storageUtils.d.ts","sourceRoot":"","sources":["../../src/utils/storageUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,QAAA,MAAM,YAAY,qDAAsD,CAAC;AAEzE,oBAAY,WAAW,GAAG,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC;AA+CtD,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IACzB,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7B,GAAG,EAAE,MAAM,IAAI,CAAC;CACjB;AAuBD;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE;IAAC,WAAW,CAAC,EAAE,WAAW,CAAA;CAAC,GACpC,WAAW,CAmCb;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,WAAW,GAAE,WAAgC,GAC5C,MAAM,EAAE,CAcV"}
|
|
@@ -6,8 +6,12 @@
|
|
|
6
6
|
*/
|
|
7
7
|
const StorageTypes = ['localStorage', 'sessionStorage', 'none'];
|
|
8
8
|
const DefaultStorageType = 'localStorage';
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Will return `null` if browser storage is unavailable (like running Docusaurus
|
|
11
|
+
* in an iframe). This should NOT be called in SSR.
|
|
12
|
+
*
|
|
13
|
+
* @see https://github.com/facebook/docusaurus/pull/4501
|
|
14
|
+
*/
|
|
11
15
|
function getBrowserStorage(storageType = DefaultStorageType) {
|
|
12
16
|
if (typeof window === 'undefined') {
|
|
13
17
|
throw new Error('Browser storage is not available on Node.js/Docusaurus SSR process.');
|
|
@@ -23,11 +27,12 @@ function getBrowserStorage(storageType = DefaultStorageType) {
|
|
|
23
27
|
return null;
|
|
24
28
|
}
|
|
25
29
|
}
|
|
30
|
+
let hasLoggedBrowserStorageNotAvailableWarning = false;
|
|
26
31
|
/**
|
|
27
|
-
* Poor man's memoization to avoid logging multiple times the same warning
|
|
28
|
-
* Sometimes, localStorage
|
|
32
|
+
* Poor man's memoization to avoid logging multiple times the same warning.
|
|
33
|
+
* Sometimes, `localStorage`/`sessionStorage` is unavailable due to browser
|
|
34
|
+
* policies.
|
|
29
35
|
*/
|
|
30
|
-
let hasLoggedBrowserStorageNotAvailableWarning = false;
|
|
31
36
|
function logOnceBrowserStorageNotAvailableWarning(error) {
|
|
32
37
|
if (!hasLoggedBrowserStorageNotAvailableWarning) {
|
|
33
38
|
console.warn(`Docusaurus browser storage is not available.
|
|
@@ -40,7 +45,7 @@ const NoopStorageSlot = {
|
|
|
40
45
|
set: () => { },
|
|
41
46
|
del: () => { },
|
|
42
47
|
};
|
|
43
|
-
//
|
|
48
|
+
// Fail-fast, as storage APIs should not be used during the SSR process
|
|
44
49
|
function createServerStorageSlot(key) {
|
|
45
50
|
function throwError() {
|
|
46
51
|
throw new Error(`Illegal storage API usage for storage key "${key}".
|
|
@@ -54,13 +59,16 @@ Please only call storage APIs in effects and event handlers.`);
|
|
|
54
59
|
};
|
|
55
60
|
}
|
|
56
61
|
/**
|
|
57
|
-
* Creates an
|
|
58
|
-
*
|
|
62
|
+
* Creates an interface to work on a particular key in the storage model.
|
|
63
|
+
* Note that this function only initializes the interface, but doesn't allocate
|
|
64
|
+
* anything by itself (i.e. no side-effects).
|
|
65
|
+
*
|
|
66
|
+
* The API is fail-safe, since usage of browser storage should be considered
|
|
59
67
|
* unreliable. Local storage might simply be unavailable (iframe + browser
|
|
60
68
|
* security) or operations might fail individually. Please assume that using
|
|
61
|
-
* this API can be a
|
|
69
|
+
* this API can be a no-op. See also https://github.com/facebook/docusaurus/issues/6036
|
|
62
70
|
*/
|
|
63
|
-
export
|
|
71
|
+
export function createStorageSlot(key, options) {
|
|
64
72
|
if (typeof window === 'undefined') {
|
|
65
73
|
return createServerStorageSlot(key);
|
|
66
74
|
}
|
|
@@ -95,9 +103,9 @@ export const createStorageSlot = (key, options) => {
|
|
|
95
103
|
}
|
|
96
104
|
},
|
|
97
105
|
};
|
|
98
|
-
}
|
|
106
|
+
}
|
|
99
107
|
/**
|
|
100
|
-
* Returns a list of all the keys currently stored in browser storage
|
|
108
|
+
* Returns a list of all the keys currently stored in browser storage,
|
|
101
109
|
* or an empty list if browser storage can't be accessed.
|
|
102
110
|
*/
|
|
103
111
|
export function listStorageKeys(storageType = DefaultStorageType) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storageUtils.js","sourceRoot":"","sources":["../../src/utils/storageUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,YAAY,GAAG,CAAC,cAAc,EAAE,gBAAgB,EAAE,MAAM,CAAU,CAAC;AAIzE,MAAM,kBAAkB,GAAgB,cAAc,CAAC;AAEvD
|
|
1
|
+
{"version":3,"file":"storageUtils.js","sourceRoot":"","sources":["../../src/utils/storageUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,YAAY,GAAG,CAAC,cAAc,EAAE,gBAAgB,EAAE,MAAM,CAAU,CAAC;AAIzE,MAAM,kBAAkB,GAAgB,cAAc,CAAC;AAEvD;;;;;GAKG;AACH,SAAS,iBAAiB,CACxB,cAA2B,kBAAkB;IAE7C,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE;QACjC,MAAM,IAAI,KAAK,CACb,qEAAqE,CACtE,CAAC;KACH;IACD,IAAI,WAAW,KAAK,MAAM,EAAE;QAC1B,OAAO,IAAI,CAAC;KACb;IACD,IAAI;QACF,OAAO,MAAM,CAAC,WAAW,CAAC,CAAC;KAC5B;IAAC,OAAO,GAAG,EAAE;QACZ,wCAAwC,CAAC,GAAY,CAAC,CAAC;QACvD,OAAO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AC,KAAK,EAAE,EAAE;YACb,IAAI;gBACF,cAAc,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;aACpC;YAAC,OAAO,GAAG,EAAE;gBACZ,OAAO,CAAC,KAAK,CACX,uCAAuC,GAAG,IAAI,KAAK,EAAE,EACrD,GAAG,CACJ,CAAC;aACH;QACH,CAAC;QACD,GAAG,EAAE,GAAG,EAAE;YACR,IAAI;gBACF,cAAc,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;aAChC;YAAC,OAAO,GAAG,EAAE;gBACZ,OAAO,CAAC,KAAK,CAAC,8CAA8C,GAAG,EAAE,EAAE,GAAG,CAAC,CAAC;aACzE;QACH,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC7B,cAA2B,kBAAkB;IAE7C,MAAM,cAAc,GAAG,iBAAiB,CAAC,WAAW,CAAC,CAAC;IACtD,IAAI,CAAC,cAAc,EAAE;QACnB,OAAO,EAAE,CAAC;KACX;IAED,MAAM,IAAI,GAAa,EAAE,CAAC;IAC1B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,cAAc,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE;QACjD,MAAM,GAAG,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAClC,IAAI,GAAG,KAAK,IAAI,EAAE;YAChB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;SAChB;KACF;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/lib/utils/tagsUtils.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
export declare const translateTagsPageTitle: () => string;
|
|
8
|
-
declare type TagsListItem = Readonly<{
|
|
8
|
+
export declare type TagsListItem = Readonly<{
|
|
9
9
|
name: string;
|
|
10
10
|
permalink: string;
|
|
11
11
|
count: number;
|
|
@@ -14,6 +14,9 @@ export declare type TagLetterEntry = Readonly<{
|
|
|
14
14
|
letter: string;
|
|
15
15
|
tags: TagsListItem[];
|
|
16
16
|
}>;
|
|
17
|
+
/**
|
|
18
|
+
* Takes a list of tags (as provided by the content plugins), and groups them by
|
|
19
|
+
* their initials.
|
|
20
|
+
*/
|
|
17
21
|
export declare function listTagsByLetters(tags: readonly TagsListItem[]): TagLetterEntry[];
|
|
18
|
-
export {};
|
|
19
22
|
//# sourceMappingURL=tagsUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tagsUtils.d.ts","sourceRoot":"","sources":["../../src/utils/tagsUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,eAAO,MAAM,sBAAsB,QAAO,MAKtC,CAAC;AAEL,
|
|
1
|
+
{"version":3,"file":"tagsUtils.d.ts","sourceRoot":"","sources":["../../src/utils/tagsUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,eAAO,MAAM,sBAAsB,QAAO,MAKtC,CAAC;AAEL,oBAAY,YAAY,GAAG,QAAQ,CAAC;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC,CAAC;AAEH,oBAAY,cAAc,GAAG,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,YAAY,EAAE,CAAA;CAAC,CAAC,CAAC;AAM9E;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,SAAS,YAAY,EAAE,GAC5B,cAAc,EAAE,CAoBlB"}
|
package/lib/utils/tagsUtils.js
CHANGED
|
@@ -13,13 +13,16 @@ export const translateTagsPageTitle = () => translate({
|
|
|
13
13
|
function getTagLetter(tag) {
|
|
14
14
|
return tag[0].toUpperCase();
|
|
15
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Takes a list of tags (as provided by the content plugins), and groups them by
|
|
18
|
+
* their initials.
|
|
19
|
+
*/
|
|
16
20
|
export function listTagsByLetters(tags) {
|
|
17
|
-
// Group by letters
|
|
18
21
|
const groups = {};
|
|
19
22
|
Object.values(tags).forEach((tag) => {
|
|
20
|
-
const
|
|
21
|
-
groups[
|
|
22
|
-
groups[
|
|
23
|
+
const initial = getTagLetter(tag.name);
|
|
24
|
+
groups[initial] ?? (groups[initial] = []);
|
|
25
|
+
groups[initial].push(tag);
|
|
23
26
|
});
|
|
24
27
|
return (Object.entries(groups)
|
|
25
28
|
// Sort letters
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tagsUtils.js","sourceRoot":"","sources":["../../src/utils/tagsUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,SAAS,EAAC,MAAM,uBAAuB,CAAC;AAEhD,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAW,EAAE,CACjD,SAAS,CAAC;IACR,EAAE,EAAE,0BAA0B;IAC9B,OAAO,EAAE,MAAM;IACf,WAAW,EAAE,gCAAgC;CAC9C,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"tagsUtils.js","sourceRoot":"","sources":["../../src/utils/tagsUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,SAAS,EAAC,MAAM,uBAAuB,CAAC;AAEhD,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAW,EAAE,CACjD,SAAS,CAAC;IACR,EAAE,EAAE,0BAA0B;IAC9B,OAAO,EAAE,MAAM;IACf,WAAW,EAAE,gCAAgC;CAC9C,CAAC,CAAC;AAUL,SAAS,YAAY,CAAC,GAAW;IAC/B,OAAO,GAAG,CAAC,CAAC,CAAE,CAAC,WAAW,EAAE,CAAC;AAC/B,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAC/B,IAA6B;IAE7B,MAAM,MAAM,GAAwC,EAAE,CAAC;IACvD,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QAClC,MAAM,OAAO,GAAG,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACvC,MAAM,CAAC,OAAO,MAAd,MAAM,CAAC,OAAO,IAAM,EAAE,EAAC;QACvB,MAAM,CAAC,OAAO,CAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC,CAAC,CAAC;IAEH,OAAO,CACL,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;QACpB,eAAe;SACd,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;SAC9D,GAAG,CAAC,CAAC,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,EAAE;QAC5B,4BAA4B;QAC5B,MAAM,UAAU,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAChD,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CACnC,CAAC;QACF,OAAO,EAAC,MAAM,EAAE,IAAI,EAAE,UAAU,EAAC,CAAC;IACpC,CAAC,CAAC,CACL,CAAC;AACJ,CAAC"}
|
package/lib/utils/tocUtils.d.ts
CHANGED
|
@@ -11,7 +11,23 @@ export declare type TOCTreeNode = {
|
|
|
11
11
|
readonly level: number;
|
|
12
12
|
readonly children: readonly TOCTreeNode[];
|
|
13
13
|
};
|
|
14
|
+
/**
|
|
15
|
+
* Takes a flat TOC list (from the MDX loader) and treeifies it into what the
|
|
16
|
+
* TOC components expect. Memoized for performance.
|
|
17
|
+
*/
|
|
14
18
|
export declare function useTreeifiedTOC(toc: TOCItem[]): readonly TOCTreeNode[];
|
|
19
|
+
/**
|
|
20
|
+
* Takes a flat TOC list (from the MDX loader) and treeifies it into what the
|
|
21
|
+
* TOC components expect, applying the `minHeadingLevel` and `maxHeadingLevel`.
|
|
22
|
+
* Memoized for performance.
|
|
23
|
+
*
|
|
24
|
+
* **Important**: this is not the same as `useTreeifiedTOC(toc.filter(...))`,
|
|
25
|
+
* because we have to filter the TOC after it has been treeified. This is mostly
|
|
26
|
+
* to ensure that weird TOC structures preserve their semantics. For example, an
|
|
27
|
+
* h3-h2-h4 sequence should not be treeified as an "h3 > h4" hierarchy with
|
|
28
|
+
* min=3, max=4, but should rather be "[h3, h4]" (since the h2 heading has split
|
|
29
|
+
* the two headings and they are not parents)
|
|
30
|
+
*/
|
|
15
31
|
export declare function useFilteredAndTreeifiedTOC({ toc, minHeadingLevel, maxHeadingLevel, }: {
|
|
16
32
|
toc: readonly TOCItem[];
|
|
17
33
|
minHeadingLevel: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tocUtils.d.ts","sourceRoot":"","sources":["../../src/utils/tocUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,mBAAmB,CAAC;AAE/C,oBAAY,WAAW,GAAG;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,SAAS,WAAW,EAAE,CAAC;CAC3C,CAAC;AAuCF,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,SAAS,WAAW,EAAE,CAEtE;AAiCD,wBAAgB,0BAA0B,CAAC,EACzC,GAAG,EACH,eAAe,EACf,eAAe,GAChB,EAAE;IACD,GAAG,EAAE,SAAS,OAAO,EAAE,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;CACzB,GAAG,SAAS,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"tocUtils.d.ts","sourceRoot":"","sources":["../../src/utils/tocUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,mBAAmB,CAAC;AAE/C,oBAAY,WAAW,GAAG;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,SAAS,WAAW,EAAE,CAAC;CAC3C,CAAC;AAuCF;;;GAGG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,SAAS,WAAW,EAAE,CAEtE;AAiCD;;;;;;;;;;;GAWG;AACH,wBAAgB,0BAA0B,CAAC,EACzC,GAAG,EACH,eAAe,EACf,eAAe,GAChB,EAAE;IACD,GAAG,EAAE,SAAS,OAAO,EAAE,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;CACzB,GAAG,SAAS,WAAW,EAAE,CAKzB"}
|
package/lib/utils/tocUtils.js
CHANGED
|
@@ -38,6 +38,10 @@ function treeifyTOC(flatTOC) {
|
|
|
38
38
|
});
|
|
39
39
|
return rootNodes;
|
|
40
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* Takes a flat TOC list (from the MDX loader) and treeifies it into what the
|
|
43
|
+
* TOC components expect. Memoized for performance.
|
|
44
|
+
*/
|
|
41
45
|
export function useTreeifiedTOC(toc) {
|
|
42
46
|
return useMemo(() => treeifyTOC(toc), [toc]);
|
|
43
47
|
}
|
|
@@ -62,12 +66,19 @@ function filterTOC({ toc, minHeadingLevel, maxHeadingLevel, }) {
|
|
|
62
66
|
return filteredChildren;
|
|
63
67
|
});
|
|
64
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Takes a flat TOC list (from the MDX loader) and treeifies it into what the
|
|
71
|
+
* TOC components expect, applying the `minHeadingLevel` and `maxHeadingLevel`.
|
|
72
|
+
* Memoized for performance.
|
|
73
|
+
*
|
|
74
|
+
* **Important**: this is not the same as `useTreeifiedTOC(toc.filter(...))`,
|
|
75
|
+
* because we have to filter the TOC after it has been treeified. This is mostly
|
|
76
|
+
* to ensure that weird TOC structures preserve their semantics. For example, an
|
|
77
|
+
* h3-h2-h4 sequence should not be treeified as an "h3 > h4" hierarchy with
|
|
78
|
+
* min=3, max=4, but should rather be "[h3, h4]" (since the h2 heading has split
|
|
79
|
+
* the two headings and they are not parents)
|
|
80
|
+
*/
|
|
65
81
|
export function useFilteredAndTreeifiedTOC({ toc, minHeadingLevel, maxHeadingLevel, }) {
|
|
66
|
-
return useMemo(() =>
|
|
67
|
-
// Note: we have to filter the TOC after it has been treeified. This is
|
|
68
|
-
// mostly to ensure that weird TOC structures preserve their semantics.
|
|
69
|
-
// For example, an h3-h2-h4 sequence should not be treeified as an h3 > h4
|
|
70
|
-
// hierarchy with min=3, max=4, but should rather be [h3, h4]
|
|
71
|
-
filterTOC({ toc: treeifyTOC(toc), minHeadingLevel, maxHeadingLevel }), [toc, minHeadingLevel, maxHeadingLevel]);
|
|
82
|
+
return useMemo(() => filterTOC({ toc: treeifyTOC(toc), minHeadingLevel, maxHeadingLevel }), [toc, minHeadingLevel, maxHeadingLevel]);
|
|
72
83
|
}
|
|
73
84
|
//# sourceMappingURL=tocUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tocUtils.js","sourceRoot":"","sources":["../../src/utils/tocUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAU9B,SAAS,UAAU,CAAC,OAA2B;IAC7C,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QACzC,GAAG,OAAO;QACV,WAAW,EAAE,CAAC,CAAC;QACf,QAAQ,EAAE,EAAmB;KAC9B,CAAC,CAAC,CAAC;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xE,CAAC;IAED,OAAO,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAC1B,MAAM,gBAAgB,GAAG,SAAS,CAAC;YACjC,GAAG,EAAE,IAAI,CAAC,QAAQ;YAClB,eAAe;YACf,eAAe;SAChB,CAAC,CAAC;QACH,IAAI,OAAO,CAAC,IAAI,CAAC,EAAE;YACjB,OAAO;gBACL;oBACE,GAAG,IAAI;oBACP,QAAQ,EAAE,gBAAgB;iBAC3B;aACF,CAAC;SACH;QACD,OAAO,gBAAgB,CAAC;IAC1B,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,0BAA0B,CAAC,EACzC,GAAG,EACH,eAAe,EACf,eAAe,GAKhB;IACC,OAAO,OAAO,CACZ,GAAG,EAAE,CAAC,SAAS,CAAC,EAAC,GAAG,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,eAAe,EAAE,eAAe,EAAC,CAAC,EACzE,CAAC,GAAG,EAAE,eAAe,EAAE,eAAe,CAAC,CACxC,CAAC;AACJ,CAAC"}
|
|
@@ -4,8 +4,27 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
+
/**
|
|
8
|
+
* Permits to obtain the url of the current page in another locale, useful to
|
|
9
|
+
* generate hreflang meta headers etc...
|
|
10
|
+
*
|
|
11
|
+
* @see https://developers.google.com/search/docs/advanced/crawling/localized-versions
|
|
12
|
+
*/
|
|
7
13
|
export declare function useAlternatePageUtils(): {
|
|
8
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Everything (pathname, base URL, etc.) is read from the context. Just tell
|
|
16
|
+
* it which locale to link to and it will give you the alternate link for the
|
|
17
|
+
* current page.
|
|
18
|
+
*/
|
|
19
|
+
createUrl: ({
|
|
20
|
+
/** The locale name to link to. */
|
|
21
|
+
locale,
|
|
22
|
+
/**
|
|
23
|
+
* For hreflang SEO headers, we need it to be fully qualified (full
|
|
24
|
+
* protocol/domain/path...); but for locale dropdowns, using a pathname is
|
|
25
|
+
* good enough.
|
|
26
|
+
*/
|
|
27
|
+
fullyQualified, }: {
|
|
9
28
|
locale: string;
|
|
10
29
|
fullyQualified: boolean;
|
|
11
30
|
}) => string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAlternatePageUtils.d.ts","sourceRoot":"","sources":["../../src/utils/useAlternatePageUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"useAlternatePageUtils.d.ts","sourceRoot":"","sources":["../../src/utils/useAlternatePageUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH;;;;;GAKG;AACH,wBAAgB,qBAAqB,IAAI;IACvC;;;;OAIG;IACH,SAAS,EAAE,CAAC;IACV,kCAAkC;IAClC,MAAM;IACN;;;;OAIG;IACH,cAAc,GACf,EAAE;QACD,MAAM,EAAE,MAAM,CAAC;QACf,cAAc,EAAE,OAAO,CAAC;KACzB,KAAK,MAAM,CAAC;CACd,CAmCA"}
|
|
@@ -6,9 +6,12 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
8
8
|
import { useLocation } from '@docusaurus/router';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Permits to obtain the url of the current page in another locale, useful to
|
|
11
|
+
* generate hreflang meta headers etc...
|
|
12
|
+
*
|
|
13
|
+
* @see https://developers.google.com/search/docs/advanced/crawling/localized-versions
|
|
14
|
+
*/
|
|
12
15
|
export function useAlternatePageUtils() {
|
|
13
16
|
const { siteConfig: { baseUrl, url }, i18n: { defaultLocale, currentLocale }, } = useDocusaurusContext();
|
|
14
17
|
const { pathname } = useLocation();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAlternatePageUtils.js","sourceRoot":"","sources":["../../src/utils/useAlternatePageUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAC,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAE/C
|
|
1
|
+
{"version":3,"file":"useAlternatePageUtils.js","sourceRoot":"","sources":["../../src/utils/useAlternatePageUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAC,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAE/C;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB;IAoBnC,MAAM,EACJ,UAAU,EAAE,EAAC,OAAO,EAAE,GAAG,EAAC,EAC1B,IAAI,EAAE,EAAC,aAAa,EAAE,aAAa,EAAC,GACrC,GAAG,oBAAoB,EAAE,CAAC;IAC3B,MAAM,EAAC,QAAQ,EAAC,GAAG,WAAW,EAAE,CAAC;IAEjC,MAAM,kBAAkB,GACtB,aAAa,KAAK,aAAa;QAC7B,CAAC,CAAC,OAAO;QACT,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,aAAa,GAAG,EAAE,GAAG,CAAC,CAAC;IAEjD,MAAM,cAAc,GAAG,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAErD,SAAS,mBAAmB,CAAC,MAAc;QACzC,OAAO,MAAM,KAAK,aAAa;YAC7B,CAAC,CAAC,GAAG,kBAAkB,EAAE;YACzB,CAAC,CAAC,GAAG,kBAAkB,GAAG,MAAM,GAAG,CAAC;IACxC,CAAC;IAED,wEAAwE;IACxE,iBAAiB;IACjB,SAAS,SAAS,CAAC,EACjB,MAAM,EACN,cAAc,GAIf;QACC,OAAO,GAAG,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,GAAG,mBAAmB,CACvD,MAAM,CACP,GAAG,cAAc,EAAE,CAAC;IACvB,CAAC;IAED,OAAO,EAAC,SAAS,EAAC,CAAC;AACrB,CAAC"}
|
|
@@ -4,5 +4,10 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
+
/**
|
|
8
|
+
* Get the pathname of current route, without the optional site baseUrl.
|
|
9
|
+
* - `/docs/myDoc` => `/docs/myDoc`
|
|
10
|
+
* - `/baseUrl/docs/myDoc` => `/docs/myDoc`
|
|
11
|
+
*/
|
|
7
12
|
export declare function useLocalPathname(): string;
|
|
8
13
|
//# sourceMappingURL=useLocalPathname.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocalPathname.d.ts","sourceRoot":"","sources":["../../src/utils/useLocalPathname.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"useLocalPathname.d.ts","sourceRoot":"","sources":["../../src/utils/useLocalPathname.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAMzC"}
|
|
@@ -4,11 +4,13 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
8
7
|
import { useLocation } from '@docusaurus/router';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
9
|
+
/**
|
|
10
|
+
* Get the pathname of current route, without the optional site baseUrl.
|
|
11
|
+
* - `/docs/myDoc` => `/docs/myDoc`
|
|
12
|
+
* - `/baseUrl/docs/myDoc` => `/docs/myDoc`
|
|
13
|
+
*/
|
|
12
14
|
export function useLocalPathname() {
|
|
13
15
|
const { siteConfig: { baseUrl }, } = useDocusaurusContext();
|
|
14
16
|
const { pathname } = useLocation();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocalPathname.js","sourceRoot":"","sources":["../../src/utils/useLocalPathname.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"useLocalPathname.js","sourceRoot":"","sources":["../../src/utils/useLocalPathname.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAC/C,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;AAEpE;;;;GAIG;AACH,MAAM,UAAU,gBAAgB;IAC9B,MAAM,EACJ,UAAU,EAAE,EAAC,OAAO,EAAC,GACtB,GAAG,oBAAoB,EAAE,CAAC;IAC3B,MAAM,EAAC,QAAQ,EAAC,GAAG,WAAW,EAAE,CAAC;IACjC,OAAO,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -5,11 +5,13 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type { Location } from 'history';
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Fires an effect when the location changes (which includes hash, query, etc.).
|
|
10
|
+
* Importantly, doesn't fire when there's no previous location: see
|
|
11
|
+
* https://github.com/facebook/docusaurus/pull/6696
|
|
12
|
+
*/
|
|
13
|
+
export declare function useLocationChange(onLocationChange: (locationChangeEvent: {
|
|
9
14
|
location: Location;
|
|
10
15
|
previousLocation: Location | undefined;
|
|
11
|
-
};
|
|
12
|
-
declare type OnLocationChange = (locationChangeEvent: LocationChangeEvent) => void;
|
|
13
|
-
export declare function useLocationChange(onLocationChange: OnLocationChange): void;
|
|
14
|
-
export {};
|
|
16
|
+
}) => void): void;
|
|
15
17
|
//# sourceMappingURL=useLocationChange.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocationChange.d.ts","sourceRoot":"","sources":["../../src/utils/useLocationChange.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"useLocationChange.d.ts","sourceRoot":"","sources":["../../src/utils/useLocationChange.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,SAAS,CAAC;AAGtC;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,gBAAgB,EAAE,CAAC,mBAAmB,EAAE;IACtC,QAAQ,EAAE,QAAQ,CAAC;IACnB,gBAAgB,EAAE,QAAQ,GAAG,SAAS,CAAC;CACxC,KAAK,IAAI,GACT,IAAI,CAkBN"}
|
|
@@ -6,8 +6,12 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { useEffect } from 'react';
|
|
8
8
|
import { useLocation } from '@docusaurus/router';
|
|
9
|
-
import { usePrevious } from './
|
|
10
|
-
|
|
9
|
+
import { useDynamicCallback, usePrevious } from './reactUtils';
|
|
10
|
+
/**
|
|
11
|
+
* Fires an effect when the location changes (which includes hash, query, etc.).
|
|
12
|
+
* Importantly, doesn't fire when there's no previous location: see
|
|
13
|
+
* https://github.com/facebook/docusaurus/pull/6696
|
|
14
|
+
*/
|
|
11
15
|
export function useLocationChange(onLocationChange) {
|
|
12
16
|
const location = useLocation();
|
|
13
17
|
const previousLocation = usePrevious(location);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocationChange.js","sourceRoot":"","sources":["../../src/utils/useLocationChange.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AAChC,OAAO,EAAC,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"useLocationChange.js","sourceRoot":"","sources":["../../src/utils/useLocationChange.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AAChC,OAAO,EAAC,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAC,kBAAkB,EAAE,WAAW,EAAC,MAAM,cAAc,CAAC;AAE7D;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAC/B,gBAGU;IAEV,MAAM,QAAQ,GAAG,WAAW,EAAE,CAAC;IAC/B,MAAM,gBAAgB,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC;IAE/C,MAAM,uBAAuB,GAAG,kBAAkB,CAAC,gBAAgB,CAAC,CAAC;IAErE,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,CAAC,gBAAgB,EAAE;YACrB,OAAO;SACR;QAED,IAAI,QAAQ,KAAK,gBAAgB,EAAE;YACjC,uBAAuB,CAAC;gBACtB,QAAQ;gBACR,gBAAgB;aACjB,CAAC,CAAC;SACJ;IACH,CAAC,EAAE,CAAC,uBAAuB,EAAE,QAAQ,EAAE,gBAAgB,CAAC,CAAC,CAAC;AAC5D,CAAC"}
|
|
@@ -4,7 +4,18 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
+
/**
|
|
8
|
+
* Reads the current locale and returns an interface very similar to
|
|
9
|
+
* `Intl.PluralRules`.
|
|
10
|
+
*/
|
|
7
11
|
export declare function usePluralForm(): {
|
|
12
|
+
/**
|
|
13
|
+
* Give it a `count` and it will select the relevant message from
|
|
14
|
+
* `pluralMessages`. `pluralMessages` should be separated by `|`, and in the
|
|
15
|
+
* order of "zero", "one", "two", "few", "many", "other". The actual selection
|
|
16
|
+
* is done by `Intl.PluralRules`, which tells us all plurals the locale has
|
|
17
|
+
* and which plural we should use for `count`.
|
|
18
|
+
*/
|
|
8
19
|
selectMessage: (count: number, pluralMessages: string) => string;
|
|
9
20
|
};
|
|
10
21
|
//# sourceMappingURL=usePluralForm.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePluralForm.d.ts","sourceRoot":"","sources":["../../src/utils/usePluralForm.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"usePluralForm.d.ts","sourceRoot":"","sources":["../../src/utils/usePluralForm.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAsGH;;;GAGG;AACH,wBAAgB,aAAa,IAAI;IAC/B;;;;;;OAMG;IACH,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,KAAK,MAAM,CAAC;CAClE,CAMA"}
|
|
@@ -35,17 +35,17 @@ function createLocalePluralForms(locale) {
|
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
|
-
* Poor man's PluralSelector implementation, using an
|
|
39
|
-
* a lightweight, future-proof and good-enough solution. We don't want a
|
|
40
|
-
* and heavy solution.
|
|
38
|
+
* Poor man's `PluralSelector` implementation, using an English fallback. We
|
|
39
|
+
* want a lightweight, future-proof and good-enough solution. We don't want a
|
|
40
|
+
* perfect and heavy solution.
|
|
41
41
|
*
|
|
42
42
|
* Docusaurus classic theme has only 2 deeply nested labels requiring complex
|
|
43
|
-
* plural rules. We don't want to use Intl + PluralRules polyfills + full
|
|
44
|
-
* syntax (react-intl) just for that.
|
|
43
|
+
* plural rules. We don't want to use `Intl` + `PluralRules` polyfills + full
|
|
44
|
+
* ICU syntax (react-intl) just for that.
|
|
45
45
|
*
|
|
46
46
|
* Notes:
|
|
47
|
-
* - 2021: 92+% Browsers support Intl.PluralRules
|
|
48
|
-
* the future
|
|
47
|
+
* - 2021: 92+% Browsers support `Intl.PluralRules`, and support will increase
|
|
48
|
+
* in the future
|
|
49
49
|
* - NodeJS >= 13 has full ICU support by default
|
|
50
50
|
* - In case of "mismatch" between SSR and Browser ICU support, React keeps
|
|
51
51
|
* working!
|
|
@@ -53,23 +53,14 @@ function createLocalePluralForms(locale) {
|
|
|
53
53
|
function useLocalePluralForms() {
|
|
54
54
|
const { i18n: { currentLocale }, } = useDocusaurusContext();
|
|
55
55
|
return useMemo(() => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (Intl.PluralRules) {
|
|
59
|
-
try {
|
|
60
|
-
return createLocalePluralForms(currentLocale);
|
|
61
|
-
}
|
|
62
|
-
catch {
|
|
63
|
-
console.error(`Failed to use Intl.PluralRules for locale "${currentLocale}".
|
|
64
|
-
Docusaurus will fallback to a default/fallback (English) Intl.PluralRules implementation.
|
|
65
|
-
`);
|
|
66
|
-
return EnglishPluralForms;
|
|
67
|
-
}
|
|
56
|
+
try {
|
|
57
|
+
return createLocalePluralForms(currentLocale);
|
|
68
58
|
}
|
|
69
|
-
|
|
70
|
-
console.error(`Intl.PluralRules
|
|
71
|
-
Docusaurus will fallback to
|
|
72
|
-
|
|
59
|
+
catch (err) {
|
|
60
|
+
console.error(`Failed to use Intl.PluralRules for locale "${currentLocale}".
|
|
61
|
+
Docusaurus will fallback to the default (English) implementation.
|
|
62
|
+
Error: ${err.message}
|
|
63
|
+
`);
|
|
73
64
|
return EnglishPluralForms;
|
|
74
65
|
}
|
|
75
66
|
}, [currentLocale]);
|
|
@@ -81,7 +72,7 @@ function selectPluralMessage(pluralMessages, count, localePluralForms) {
|
|
|
81
72
|
return parts[0];
|
|
82
73
|
}
|
|
83
74
|
if (parts.length > localePluralForms.pluralForms.length) {
|
|
84
|
-
console.error(`For locale=${localePluralForms.locale}, a maximum of ${localePluralForms.pluralForms.length} plural forms are expected (${localePluralForms.pluralForms}), but the message contains ${parts.length}
|
|
75
|
+
console.error(`For locale=${localePluralForms.locale}, a maximum of ${localePluralForms.pluralForms.length} plural forms are expected (${localePluralForms.pluralForms}), but the message contains ${parts.length}: ${pluralMessages}`);
|
|
85
76
|
}
|
|
86
77
|
const pluralForm = localePluralForms.select(count);
|
|
87
78
|
const pluralFormIndex = localePluralForms.pluralForms.indexOf(pluralForm);
|
|
@@ -89,6 +80,10 @@ function selectPluralMessage(pluralMessages, count, localePluralForms) {
|
|
|
89
80
|
// instead of returning undefined
|
|
90
81
|
return parts[Math.min(pluralFormIndex, parts.length - 1)];
|
|
91
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Reads the current locale and returns an interface very similar to
|
|
85
|
+
* `Intl.PluralRules`.
|
|
86
|
+
*/
|
|
92
87
|
export function usePluralForm() {
|
|
93
88
|
const localePluralForm = useLocalePluralForms();
|
|
94
89
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePluralForm.js","sourceRoot":"","sources":["../../src/utils/usePluralForm.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,OAAO,EAAC,MAAM,OAAO,CAAC;AAC9B,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;AAEpE,6DAA6D;AAC7D,mEAAmE;AACnE,qEAAqE;AACrE,MAAM,kBAAkB,GAA0B;IAChD,MAAM;IACN,KAAK;IACL,KAAK;IACL,KAAK;IACL,MAAM;IACN,OAAO;CACR,CAAC;AACF,SAAS,eAAe,CACtB,WAAkC;IAElC,OAAO,kBAAkB,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;AACrE,CAAC;AAQD,4CAA4C;AAC5C,MAAM,kBAAkB,GAAsB;IAC5C,MAAM,EAAE,IAAI;IACZ,WAAW,EAAE,eAAe,CAAC,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC9C,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC;CACnD,CAAC;AAEF,SAAS,uBAAuB,CAAC,MAAc;IAC7C,MAAM,WAAW,GAAG,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IACjD,OAAO;QACL,MAAM;QACN,WAAW,EA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