@docusaurus/theme-common 2.0.0-beta.15a2b59f9 → 2.0.0-beta.17
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 +36 -0
- package/lib/components/Collapsible/index.d.ts.map +1 -0
- package/lib/components/Collapsible/index.js +143 -0
- package/lib/components/Collapsible/index.js.map +1 -0
- package/lib/components/Details/index.d.ts +12 -0
- package/lib/components/Details/index.d.ts.map +1 -0
- package/lib/components/Details/index.js +66 -0
- package/lib/components/Details/index.js.map +1 -0
- package/lib/components/Details/styles.module.css +58 -0
- package/{src/utils/docsUtils.ts → lib/hooks/styles.css} +3 -4
- package/lib/hooks/useHideableNavbar.d.ts +13 -0
- package/lib/hooks/useHideableNavbar.d.ts.map +1 -0
- package/lib/hooks/useHideableNavbar.js +59 -0
- package/lib/hooks/useHideableNavbar.js.map +1 -0
- package/lib/hooks/useKeyboardNavigation.d.ts +10 -0
- package/lib/hooks/useKeyboardNavigation.d.ts.map +1 -0
- package/lib/hooks/useKeyboardNavigation.js +31 -0
- package/lib/hooks/useKeyboardNavigation.js.map +1 -0
- package/lib/hooks/useLockBodyScroll.d.ts +8 -0
- package/lib/hooks/useLockBodyScroll.d.ts.map +1 -0
- package/lib/hooks/useLockBodyScroll.js +16 -0
- package/lib/hooks/useLockBodyScroll.js.map +1 -0
- package/lib/hooks/usePrismTheme.d.ts +9 -0
- package/lib/hooks/usePrismTheme.d.ts.map +1 -0
- package/lib/hooks/usePrismTheme.js +18 -0
- package/lib/hooks/usePrismTheme.js.map +1 -0
- package/lib/hooks/useSearchPage.d.ts +14 -0
- package/lib/hooks/useSearchPage.d.ts.map +1 -0
- package/lib/hooks/useSearchPage.js +42 -0
- package/lib/hooks/useSearchPage.js.map +1 -0
- package/lib/hooks/useWindowSize.d.ts +15 -0
- package/lib/hooks/useWindowSize.d.ts.map +1 -0
- package/lib/hooks/useWindowSize.js +56 -0
- package/lib/hooks/useWindowSize.js.map +1 -0
- package/lib/index.d.ts +32 -3
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +26 -2
- package/lib/index.js.map +1 -0
- package/lib/utils/ThemeClassNames.d.ts +40 -12
- package/lib/utils/ThemeClassNames.d.ts.map +1 -0
- package/lib/utils/ThemeClassNames.js +41 -3
- package/lib/utils/ThemeClassNames.js.map +1 -0
- package/lib/utils/announcementBarUtils.d.ts +6 -5
- package/lib/utils/announcementBarUtils.d.ts.map +1 -0
- package/lib/utils/announcementBarUtils.js +20 -21
- package/lib/utils/announcementBarUtils.js.map +1 -0
- package/lib/utils/codeBlockUtils.d.ts +10 -0
- package/lib/utils/codeBlockUtils.d.ts.map +1 -0
- package/lib/utils/codeBlockUtils.js +125 -3
- package/lib/utils/codeBlockUtils.js.map +1 -0
- package/lib/utils/colorModeUtils.d.ts +18 -0
- package/lib/utils/colorModeUtils.d.ts.map +1 -0
- package/lib/utils/colorModeUtils.js +107 -0
- package/lib/utils/colorModeUtils.js.map +1 -0
- package/lib/utils/docSidebarItemsExpandedState.d.ts +17 -0
- package/lib/utils/docSidebarItemsExpandedState.d.ts.map +1 -0
- package/lib/utils/docSidebarItemsExpandedState.js +23 -0
- package/lib/utils/docSidebarItemsExpandedState.js.map +1 -0
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.d.ts +3 -2
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.d.ts.map +1 -0
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js +9 -11
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionProvider.js.map +1 -0
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.d.ts +2 -1
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.d.ts.map +1 -0
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.js +2 -3
- package/lib/utils/docsPreferredVersion/DocsPreferredVersionStorage.js.map +1 -0
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.d.ts +12 -3
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.d.ts.map +1 -0
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.js +3 -3
- package/lib/utils/docsPreferredVersion/useDocsPreferredVersion.js.map +1 -0
- package/lib/utils/docsUtils.d.ts +26 -0
- package/lib/utils/docsUtils.d.ts.map +1 -0
- package/lib/utils/docsUtils.js +136 -1
- package/lib/utils/docsUtils.js.map +1 -0
- package/lib/utils/generalUtils.d.ts +7 -0
- package/lib/utils/generalUtils.d.ts.map +1 -0
- package/lib/utils/generalUtils.js +3 -2
- package/lib/utils/generalUtils.js.map +1 -0
- package/lib/utils/historyUtils.d.ts +23 -0
- package/lib/utils/historyUtils.d.ts.map +1 -0
- package/lib/utils/historyUtils.js +41 -0
- package/lib/utils/historyUtils.js.map +1 -0
- package/lib/utils/jsUtils.d.ts +23 -0
- package/lib/utils/jsUtils.d.ts.map +1 -0
- package/lib/utils/jsUtils.js +29 -0
- package/lib/utils/jsUtils.js.map +1 -0
- package/lib/utils/mobileSecondaryMenu.d.ts +21 -0
- package/lib/utils/mobileSecondaryMenu.d.ts.map +1 -0
- package/lib/utils/mobileSecondaryMenu.js +51 -0
- package/lib/utils/mobileSecondaryMenu.js.map +1 -0
- package/lib/utils/pathUtils.d.ts +1 -0
- package/lib/utils/pathUtils.d.ts.map +1 -0
- package/lib/utils/pathUtils.js +5 -4
- package/lib/utils/pathUtils.js.map +1 -0
- package/lib/utils/reactUtils.d.ts +31 -0
- package/lib/utils/reactUtils.d.ts.map +1 -0
- package/lib/utils/reactUtils.js +43 -0
- package/lib/utils/reactUtils.js.map +1 -0
- package/lib/utils/regexpUtils.d.ts +11 -0
- package/lib/utils/regexpUtils.d.ts.map +1 -0
- package/lib/utils/regexpUtils.js +17 -0
- package/lib/utils/regexpUtils.js.map +1 -0
- package/lib/utils/routesUtils.d.ts +14 -0
- package/lib/utils/routesUtils.d.ts.map +1 -0
- package/lib/utils/routesUtils.js +41 -0
- package/lib/utils/routesUtils.js.map +1 -0
- package/lib/utils/scrollUtils.d.ts +53 -0
- package/lib/utils/scrollUtils.d.ts.map +1 -0
- package/lib/utils/scrollUtils.js +135 -0
- package/lib/utils/scrollUtils.js.map +1 -0
- package/lib/utils/searchUtils.d.ts +1 -0
- package/lib/utils/searchUtils.d.ts.map +1 -0
- package/lib/utils/searchUtils.js +1 -0
- package/lib/utils/searchUtils.js.map +1 -0
- package/lib/utils/storageUtils.d.ts +5 -0
- package/lib/utils/storageUtils.d.ts.map +1 -0
- package/lib/utils/storageUtils.js +39 -14
- package/lib/utils/storageUtils.js.map +1 -0
- package/lib/utils/tabGroupChoiceUtils.d.ts +19 -0
- package/lib/utils/tabGroupChoiceUtils.d.ts.map +1 -0
- package/lib/utils/tabGroupChoiceUtils.js +55 -0
- package/lib/utils/tabGroupChoiceUtils.js.map +1 -0
- package/lib/utils/tagsUtils.d.ts +19 -0
- package/lib/utils/tagsUtils.d.ts.map +1 -0
- package/lib/utils/tagsUtils.js +33 -0
- package/lib/utils/tagsUtils.js.map +1 -0
- package/lib/utils/tocUtils.d.ts +20 -0
- package/lib/utils/tocUtils.d.ts.map +1 -0
- package/lib/utils/tocUtils.js +73 -0
- package/lib/utils/tocUtils.js.map +1 -0
- package/lib/utils/useAlternatePageUtils.d.ts +1 -0
- package/lib/utils/useAlternatePageUtils.d.ts.map +1 -0
- package/lib/utils/useAlternatePageUtils.js +3 -1
- package/lib/utils/useAlternatePageUtils.js.map +1 -0
- package/lib/utils/useContextualSearchFilters.d.ts +12 -0
- package/lib/utils/useContextualSearchFilters.d.ts.map +1 -0
- package/lib/utils/useContextualSearchFilters.js +36 -0
- package/lib/utils/useContextualSearchFilters.js.map +1 -0
- package/lib/utils/useLocalPathname.d.ts +8 -0
- package/lib/utils/useLocalPathname.d.ts.map +1 -0
- package/lib/utils/useLocalPathname.js +17 -0
- package/lib/utils/useLocalPathname.js.map +1 -0
- package/lib/utils/useLocationChange.d.ts +2 -1
- package/lib/utils/useLocationChange.d.ts.map +1 -0
- package/lib/utils/useLocationChange.js +12 -10
- package/lib/utils/useLocationChange.js.map +1 -0
- package/lib/utils/usePluralForm.d.ts +1 -0
- package/lib/utils/usePluralForm.d.ts.map +1 -0
- package/lib/utils/usePluralForm.js +28 -24
- package/lib/utils/usePluralForm.js.map +1 -0
- package/lib/utils/usePrevious.d.ts +1 -0
- package/lib/utils/usePrevious.d.ts.map +1 -0
- package/lib/utils/usePrevious.js +4 -2
- package/lib/utils/usePrevious.js.map +1 -0
- package/lib/utils/useTOCHighlight.d.ts +14 -0
- package/lib/utils/useTOCHighlight.d.ts.map +1 -0
- package/lib/utils/useTOCHighlight.js +126 -0
- package/lib/utils/useTOCHighlight.js.map +1 -0
- package/lib/utils/useThemeConfig.d.ts +35 -17
- package/lib/utils/useThemeConfig.d.ts.map +1 -0
- package/lib/utils/useThemeConfig.js +1 -0
- package/lib/utils/useThemeConfig.js.map +1 -0
- package/package.json +19 -13
- package/src/components/Collapsible/index.tsx +247 -0
- package/src/components/Details/index.tsx +102 -0
- package/src/components/Details/styles.module.css +58 -0
- package/src/hooks/styles.css +10 -0
- package/src/hooks/useHideableNavbar.ts +77 -0
- package/src/hooks/useKeyboardNavigation.ts +37 -0
- package/src/hooks/useLockBodyScroll.ts +18 -0
- package/src/hooks/usePrismTheme.ts +20 -0
- package/src/hooks/useSearchPage.ts +66 -0
- package/src/hooks/useWindowSize.ts +70 -0
- package/src/index.ts +95 -3
- package/src/types.d.ts +0 -2
- package/src/utils/ThemeClassNames.ts +46 -4
- package/src/utils/announcementBarUtils.tsx +27 -22
- package/src/utils/codeBlockUtils.ts +153 -2
- package/src/utils/colorModeUtils.tsx +158 -0
- package/src/utils/docSidebarItemsExpandedState.tsx +40 -0
- package/src/utils/docsPreferredVersion/DocsPreferredVersionProvider.tsx +17 -16
- package/src/utils/docsPreferredVersion/DocsPreferredVersionStorage.ts +3 -4
- package/src/utils/docsPreferredVersion/useDocsPreferredVersion.ts +18 -14
- package/src/utils/docsUtils.tsx +231 -0
- package/src/utils/generalUtils.ts +3 -2
- package/src/utils/historyUtils.ts +51 -0
- package/src/utils/jsUtils.ts +36 -0
- package/src/utils/mobileSecondaryMenu.tsx +114 -0
- package/src/utils/pathUtils.ts +6 -4
- package/src/utils/reactUtils.tsx +53 -0
- package/src/utils/regexpUtils.ts +23 -0
- package/src/utils/routesUtils.ts +56 -0
- package/src/utils/scrollUtils.tsx +235 -0
- package/src/utils/storageUtils.ts +37 -12
- package/src/utils/tabGroupChoiceUtils.tsx +89 -0
- package/src/utils/tagsUtils.ts +48 -0
- package/src/utils/tocUtils.ts +108 -0
- package/src/utils/useAlternatePageUtils.ts +4 -3
- package/src/utils/useContextualSearchFilters.ts +53 -0
- package/src/utils/useLocalPathname.ts +20 -0
- package/src/utils/useLocationChange.ts +13 -11
- package/src/utils/usePluralForm.ts +31 -26
- package/src/utils/usePrevious.ts +3 -2
- package/src/utils/useTOCHighlight.ts +183 -0
- package/src/utils/useThemeConfig.ts +37 -17
- package/lib/.tsbuildinfo +0 -1
- package/src/utils/__tests__/codeBlockUtils.test.ts +0 -54
- package/src/utils/__tests__/pathUtils.test.ts +0 -32
- package/tsconfig.json +0 -10
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
const StorageTypes = ['localStorage', 'sessionStorage', 'none'];
|
|
8
8
|
const DefaultStorageType = 'localStorage';
|
|
9
|
-
// Will return null browser storage is unavailable (like running Docusaurus in
|
|
10
|
-
// See https://github.com/facebook/docusaurus/pull/4501
|
|
9
|
+
// Will return null browser storage is unavailable (like running Docusaurus in
|
|
10
|
+
// iframe) See https://github.com/facebook/docusaurus/pull/4501
|
|
11
11
|
function getBrowserStorage(storageType = DefaultStorageType) {
|
|
12
12
|
if (typeof window === 'undefined') {
|
|
13
13
|
throw new Error('Browser storage is not available on Node.js/Docusaurus SSR process.');
|
|
@@ -15,14 +15,12 @@ function getBrowserStorage(storageType = DefaultStorageType) {
|
|
|
15
15
|
if (storageType === 'none') {
|
|
16
16
|
return null;
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
18
|
+
try {
|
|
19
|
+
return window[storageType];
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
logOnceBrowserStorageNotAvailableWarning(err);
|
|
23
|
+
return null;
|
|
26
24
|
}
|
|
27
25
|
}
|
|
28
26
|
/**
|
|
@@ -57,19 +55,45 @@ Please only call storage APIs in effects and event handlers.`);
|
|
|
57
55
|
}
|
|
58
56
|
/**
|
|
59
57
|
* Creates an object for accessing a particular key in localStorage.
|
|
58
|
+
* The API is fail-safe, and usage of browser storage should be considered
|
|
59
|
+
* unreliable. Local storage might simply be unavailable (iframe + browser
|
|
60
|
+
* security) or operations might fail individually. Please assume that using
|
|
61
|
+
* this API can be a NO-OP. See also https://github.com/facebook/docusaurus/issues/6036
|
|
60
62
|
*/
|
|
61
63
|
export const createStorageSlot = (key, options) => {
|
|
62
64
|
if (typeof window === 'undefined') {
|
|
63
65
|
return createServerStorageSlot(key);
|
|
64
66
|
}
|
|
65
|
-
const browserStorage = getBrowserStorage(options
|
|
67
|
+
const browserStorage = getBrowserStorage(options?.persistence);
|
|
66
68
|
if (browserStorage === null) {
|
|
67
69
|
return NoopStorageSlot;
|
|
68
70
|
}
|
|
69
71
|
return {
|
|
70
|
-
get: () =>
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
get: () => {
|
|
73
|
+
try {
|
|
74
|
+
return browserStorage.getItem(key);
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
console.error(`Docusaurus storage error, can't get key=${key}`, err);
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
set: (value) => {
|
|
82
|
+
try {
|
|
83
|
+
browserStorage.setItem(key, value);
|
|
84
|
+
}
|
|
85
|
+
catch (err) {
|
|
86
|
+
console.error(`Docusaurus storage error, can't set ${key}=${value}`, err);
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
del: () => {
|
|
90
|
+
try {
|
|
91
|
+
browserStorage.removeItem(key);
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
console.error(`Docusaurus storage error, can't delete key=${key}`, err);
|
|
95
|
+
}
|
|
96
|
+
},
|
|
73
97
|
};
|
|
74
98
|
};
|
|
75
99
|
/**
|
|
@@ -90,3 +114,4 @@ export function listStorageKeys(storageType = DefaultStorageType) {
|
|
|
90
114
|
}
|
|
91
115
|
return keys;
|
|
92
116
|
}
|
|
117
|
+
//# sourceMappingURL=storageUtils.js.map
|
|
@@ -0,0 +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,8EAA8E;AAC9E,+DAA+D;AAC/D,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,IAAI,CAAC;KACb;AACH,CAAC;AAED;;;GAGG;AACH,IAAI,0CAA0C,GAAG,KAAK,CAAC;AACvD,SAAS,wCAAwC,CAAC,KAAY;IAC5D,IAAI,CAAC,0CAA0C,EAAE;QAC/C,OAAO,CAAC,IAAI,CACV;kIAC4H,EAC5H,KAAK,CACN,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E,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,CAAC;AAEF;;;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"}
|
|
@@ -0,0 +1,19 @@
|
|
|
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 TabGroupChoiceContextValue = {
|
|
9
|
+
readonly tabGroupChoices: {
|
|
10
|
+
readonly [groupId: string]: string;
|
|
11
|
+
};
|
|
12
|
+
readonly setTabGroupChoices: (groupId: string, newChoice: string) => void;
|
|
13
|
+
};
|
|
14
|
+
export declare function TabGroupChoiceProvider({ children, }: {
|
|
15
|
+
children: ReactNode;
|
|
16
|
+
}): JSX.Element;
|
|
17
|
+
export declare function useTabGroupChoice(): TabGroupChoiceContextValue;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=tabGroupChoiceUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tabGroupChoiceUtils.d.ts","sourceRoot":"","sources":["../../src/utils/tabGroupChoiceUtils.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAc,EAOZ,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAMf,aAAK,0BAA0B,GAAG;IAChC,QAAQ,CAAC,eAAe,EAAE;QAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAAA;KAAC,CAAC;IAC/D,QAAQ,CAAC,kBAAkB,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;CAC3E,CAAC;AAsCF,wBAAgB,sBAAsB,CAAC,EACrC,QAAQ,GACT,EAAE;IACD,QAAQ,EAAE,SAAS,CAAC;CACrB,GAAG,GAAG,CAAC,OAAO,CAcd;AAED,wBAAgB,iBAAiB,IAAI,0BAA0B,CAM9D"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import React, { useState, useCallback, useEffect, createContext, useMemo, useContext, } from 'react';
|
|
8
|
+
import { createStorageSlot, listStorageKeys } from './storageUtils';
|
|
9
|
+
import { ReactContextError } from './reactUtils';
|
|
10
|
+
const TAB_CHOICE_PREFIX = 'docusaurus.tab.';
|
|
11
|
+
const TabGroupChoiceContext = createContext(undefined);
|
|
12
|
+
function useTabGroupChoiceContextValue() {
|
|
13
|
+
const [tabGroupChoices, setChoices] = useState({});
|
|
14
|
+
const setChoiceSyncWithLocalStorage = useCallback((groupId, newChoice) => {
|
|
15
|
+
createStorageSlot(`${TAB_CHOICE_PREFIX}${groupId}`).set(newChoice);
|
|
16
|
+
}, []);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
try {
|
|
19
|
+
const localStorageChoices = {};
|
|
20
|
+
listStorageKeys().forEach((storageKey) => {
|
|
21
|
+
if (storageKey.startsWith(TAB_CHOICE_PREFIX)) {
|
|
22
|
+
const groupId = storageKey.substring(TAB_CHOICE_PREFIX.length);
|
|
23
|
+
localStorageChoices[groupId] = createStorageSlot(storageKey).get();
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
setChoices(localStorageChoices);
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
console.error(err);
|
|
30
|
+
}
|
|
31
|
+
}, []);
|
|
32
|
+
return {
|
|
33
|
+
tabGroupChoices,
|
|
34
|
+
setTabGroupChoices: (groupId, newChoice) => {
|
|
35
|
+
setChoices((oldChoices) => ({ ...oldChoices, [groupId]: newChoice }));
|
|
36
|
+
setChoiceSyncWithLocalStorage(groupId, newChoice);
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export function TabGroupChoiceProvider({ children, }) {
|
|
41
|
+
const { tabGroupChoices, setTabGroupChoices } = useTabGroupChoiceContextValue();
|
|
42
|
+
const contextValue = useMemo(() => ({
|
|
43
|
+
tabGroupChoices,
|
|
44
|
+
setTabGroupChoices,
|
|
45
|
+
}), [tabGroupChoices, setTabGroupChoices]);
|
|
46
|
+
return (React.createElement(TabGroupChoiceContext.Provider, { value: contextValue }, children));
|
|
47
|
+
}
|
|
48
|
+
export function useTabGroupChoice() {
|
|
49
|
+
const context = useContext(TabGroupChoiceContext);
|
|
50
|
+
if (context == null) {
|
|
51
|
+
throw new ReactContextError('TabGroupChoiceProvider');
|
|
52
|
+
}
|
|
53
|
+
return context;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL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,CAAC;SACjC;QAAC,OAAO,GAAG,EAAE;YACZ,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;SACpB;IACH,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO;QACL,eAAe;QACf,kBAAkB,EAAE,CAAC,OAAe,EAAE,SAAiB,EAAE,EAAE;YACzD,UAAU,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,EAAC,GAAG,UAAU,EAAE,CAAC,OAAO,CAAC,EAAE,SAAS,EAAC,CAAC,CAAC,CAAC;YACpE,6BAA6B,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QACpD,CAAC;KACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,EACrC,QAAQ,GAGT;IACC,MAAM,EAAC,eAAe,EAAE,kBAAkB,EAAC,GAAG,6BAA6B,EAAE,CAAC;IAC9E,MAAM,YAAY,GAAG,OAAO,CAC1B,GAAG,EAAE,CAAC,CAAC;QACL,eAAe;QACf,kBAAkB;KACnB,CAAC,EACF,CAAC,eAAe,EAAE,kBAAkB,CAAC,CACtC,CAAC;IACF,OAAO,CACL,oBAAC,qBAAqB,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,IAChD,QAAQ,CACsB,CAClC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB;IAC/B,MAAM,OAAO,GAAG,UAAU,CAAC,qBAAqB,CAAC,CAAC;IAClD,IAAI,OAAO,IAAI,IAAI,EAAE;QACnB,MAAM,IAAI,iBAAiB,CAAC,wBAAwB,CAAC,CAAC;KACvD;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
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 const translateTagsPageTitle: () => string;
|
|
8
|
+
declare type TagsListItem = Readonly<{
|
|
9
|
+
name: string;
|
|
10
|
+
permalink: string;
|
|
11
|
+
count: number;
|
|
12
|
+
}>;
|
|
13
|
+
export declare type TagLetterEntry = Readonly<{
|
|
14
|
+
letter: string;
|
|
15
|
+
tags: TagsListItem[];
|
|
16
|
+
}>;
|
|
17
|
+
export declare function listTagsByLetters(tags: readonly TagsListItem[]): TagLetterEntry[];
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=tagsUtils.d.ts.map
|
|
@@ -0,0 +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,aAAK,YAAY,GAAG,QAAQ,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAC,CAAC,CAAC;AAE/E,oBAAY,cAAc,GAAG,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,YAAY,EAAE,CAAA;CAAC,CAAC,CAAC;AAM9E,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,SAAS,YAAY,EAAE,GAC5B,cAAc,EAAE,CAqBlB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
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 { translate } from '@docusaurus/Translate';
|
|
8
|
+
export const translateTagsPageTitle = () => translate({
|
|
9
|
+
id: 'theme.tags.tagsPageTitle',
|
|
10
|
+
message: 'Tags',
|
|
11
|
+
description: 'The title of the tag list page',
|
|
12
|
+
});
|
|
13
|
+
function getTagLetter(tag) {
|
|
14
|
+
return tag[0].toUpperCase();
|
|
15
|
+
}
|
|
16
|
+
export function listTagsByLetters(tags) {
|
|
17
|
+
// Group by letters
|
|
18
|
+
const groups = {};
|
|
19
|
+
Object.values(tags).forEach((tag) => {
|
|
20
|
+
const letter = getTagLetter(tag.name);
|
|
21
|
+
groups[letter] = groups[letter] ?? [];
|
|
22
|
+
groups[letter].push(tag);
|
|
23
|
+
});
|
|
24
|
+
return (Object.entries(groups)
|
|
25
|
+
// Sort letters
|
|
26
|
+
.sort(([letter1], [letter2]) => letter1.localeCompare(letter2))
|
|
27
|
+
.map(([letter, letterTags]) => {
|
|
28
|
+
// Sort tags inside a letter
|
|
29
|
+
const sortedTags = letterTags.sort((tag1, tag2) => tag1.name.localeCompare(tag2.name));
|
|
30
|
+
return { letter, tags: sortedTags };
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=tagsUtils.js.map
|
|
@@ -0,0 +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;AAML,SAAS,YAAY,CAAC,GAAW;IAC/B,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,IAA6B;IAE7B,mBAAmB;IACnB,MAAM,MAAM,GAAmC,EAAE,CAAC;IAClD,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;QAClC,MAAM,MAAM,GAAG,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACtC,MAAM,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QACtC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC3B,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"}
|
|
@@ -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 { TOCItem } from '@docusaurus/types';
|
|
8
|
+
export declare type TOCTreeNode = {
|
|
9
|
+
readonly value: string;
|
|
10
|
+
readonly id: string;
|
|
11
|
+
readonly level: number;
|
|
12
|
+
readonly children: readonly TOCTreeNode[];
|
|
13
|
+
};
|
|
14
|
+
export declare function useTreeifiedTOC(toc: TOCItem[]): readonly TOCTreeNode[];
|
|
15
|
+
export declare function useFilteredAndTreeifiedTOC({ toc, minHeadingLevel, maxHeadingLevel, }: {
|
|
16
|
+
toc: readonly TOCItem[];
|
|
17
|
+
minHeadingLevel: number;
|
|
18
|
+
maxHeadingLevel: number;
|
|
19
|
+
}): readonly TOCTreeNode[];
|
|
20
|
+
//# sourceMappingURL=tocUtils.d.ts.map
|
|
@@ -0,0 +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,CAUzB"}
|
|
@@ -0,0 +1,73 @@
|
|
|
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 { useMemo } from 'react';
|
|
8
|
+
function treeifyTOC(flatTOC) {
|
|
9
|
+
const headings = flatTOC.map((heading) => ({
|
|
10
|
+
...heading,
|
|
11
|
+
parentIndex: -1,
|
|
12
|
+
children: [],
|
|
13
|
+
}));
|
|
14
|
+
// Keep track of which previous index would be the current heading's direct
|
|
15
|
+
// parent. Each entry <i> is the last index of the `headings` array at heading
|
|
16
|
+
// level <i>. We will modify these indices as we iterate through all headings.
|
|
17
|
+
// e.g. if an ### H3 was last seen at index 2, then prevIndexForLevel[3] === 2
|
|
18
|
+
// indices 0 and 1 will remain unused.
|
|
19
|
+
const prevIndexForLevel = Array(7).fill(-1);
|
|
20
|
+
headings.forEach((curr, currIndex) => {
|
|
21
|
+
// take the last seen index for each ancestor level. the highest
|
|
22
|
+
// index will be the direct ancestor of the current heading.
|
|
23
|
+
const ancestorLevelIndexes = prevIndexForLevel.slice(2, curr.level);
|
|
24
|
+
curr.parentIndex = Math.max(...ancestorLevelIndexes);
|
|
25
|
+
// mark that curr.level was last seen at the current index
|
|
26
|
+
prevIndexForLevel[curr.level] = currIndex;
|
|
27
|
+
});
|
|
28
|
+
const rootNodes = [];
|
|
29
|
+
// For a given parentIndex, add each Node into that parent's `children` array
|
|
30
|
+
headings.forEach((heading) => {
|
|
31
|
+
const { parentIndex, ...rest } = heading;
|
|
32
|
+
if (parentIndex >= 0) {
|
|
33
|
+
headings[parentIndex].children.push(rest);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
rootNodes.push(rest);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
return rootNodes;
|
|
40
|
+
}
|
|
41
|
+
export function useTreeifiedTOC(toc) {
|
|
42
|
+
return useMemo(() => treeifyTOC(toc), [toc]);
|
|
43
|
+
}
|
|
44
|
+
function filterTOC({ toc, minHeadingLevel, maxHeadingLevel, }) {
|
|
45
|
+
function isValid(item) {
|
|
46
|
+
return item.level >= minHeadingLevel && item.level <= maxHeadingLevel;
|
|
47
|
+
}
|
|
48
|
+
return toc.flatMap((item) => {
|
|
49
|
+
const filteredChildren = filterTOC({
|
|
50
|
+
toc: item.children,
|
|
51
|
+
minHeadingLevel,
|
|
52
|
+
maxHeadingLevel,
|
|
53
|
+
});
|
|
54
|
+
if (isValid(item)) {
|
|
55
|
+
return [
|
|
56
|
+
{
|
|
57
|
+
...item,
|
|
58
|
+
children: filteredChildren,
|
|
59
|
+
},
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
return filteredChildren;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
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]);
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=tocUtils.js.map
|
|
@@ -0,0 +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;IAEJ,2EAA2E;IAC3E,8EAA8E;IAC9E,8EAA8E;IAC9E,8EAA8E;IAC9E,sCAAsC;IACtC,MAAM,iBAAiB,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAE5C,QAAQ,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,SAAS,EAAE,EAAE;QACnC,g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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,MAAM,UAAU,0BAA0B,CAAC,EACzC,GAAG,EACH,eAAe,EACf,eAAe,GAKhB;IACC,OAAO,OAAO,CACZ,GAAG,EAAE;IACH,uEAAuE;IACvE,uEAAuE;IACvE,0EAA0E;IAC1E,6DAA6D;IAC7D,SAAS,CAAC,EAAC,GAAG,EAAE,UAAU,CAAC,GAAG,CAAC,EAAE,eAAe,EAAE,eAAe,EAAC,CAAC,EACrE,CAAC,GAAG,EAAE,eAAe,EAAE,eAAe,CAAC,CACxC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAlternatePageUtils.d.ts","sourceRoot":"","sources":["../../src/utils/useAlternatePageUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,wBAAgB,qBAAqB,IAAI;IACvC,SAAS,EAAE,CAAC,EACV,MAAM,EACN,cAAc,GACf,EAAE;QACD,MAAM,EAAE,MAAM,CAAC;QACf,cAAc,EAAE,OAAO,CAAC;KACzB,KAAK,MAAM,CAAC;CACd,CAqCA"}
|
|
@@ -21,9 +21,11 @@ export function useAlternatePageUtils() {
|
|
|
21
21
|
? `${baseUrlUnlocalized}`
|
|
22
22
|
: `${baseUrlUnlocalized}${locale}/`;
|
|
23
23
|
}
|
|
24
|
-
// TODO support correct alternate url when localized site is deployed on
|
|
24
|
+
// TODO support correct alternate url when localized site is deployed on
|
|
25
|
+
// another domain
|
|
25
26
|
function createUrl({ locale, fullyQualified, }) {
|
|
26
27
|
return `${fullyQualified ? url : ''}${getLocalizedBaseUrl(locale)}${pathnameSuffix}`;
|
|
27
28
|
}
|
|
28
29
|
return { createUrl };
|
|
29
30
|
}
|
|
31
|
+
//# sourceMappingURL=useAlternatePageUtils.js.map
|
|
@@ -0,0 +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,kEAAkE;AAClE,kDAAkD;AAClD,qFAAqF;AACrF,MAAM,UAAU,qBAAqB;IASnC,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,GAMf;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"}
|
|
@@ -0,0 +1,12 @@
|
|
|
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 useContextualSearchFiltersReturns = {
|
|
8
|
+
locale: string;
|
|
9
|
+
tags: string[];
|
|
10
|
+
};
|
|
11
|
+
export declare function useContextualSearchFilters(): useContextualSearchFiltersReturns;
|
|
12
|
+
//# sourceMappingURL=useContextualSearchFilters.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useContextualSearchFilters.d.ts","sourceRoot":"","sources":["../../src/utils/useContextualSearchFilters.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAUH,oBAAY,iCAAiC,GAAG;IAC9C,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB,CAAC;AAIF,wBAAgB,0BAA0B,IAAI,iCAAiC,CA8B9E"}
|
|
@@ -0,0 +1,36 @@
|
|
|
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 { useAllDocsData, useActivePluginAndVersion, } from '@docusaurus/plugin-content-docs/client';
|
|
8
|
+
import { useDocsPreferredVersionByPluginId } from './docsPreferredVersion/useDocsPreferredVersion';
|
|
9
|
+
import { docVersionSearchTag, DEFAULT_SEARCH_TAG } from './searchUtils';
|
|
10
|
+
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
11
|
+
// We may want to support multiple search engines, don't couple that to
|
|
12
|
+
// Algolia/DocSearch. Maybe users want to use their own search engine solution
|
|
13
|
+
export function useContextualSearchFilters() {
|
|
14
|
+
const { i18n } = useDocusaurusContext();
|
|
15
|
+
const allDocsData = useAllDocsData();
|
|
16
|
+
const activePluginAndVersion = useActivePluginAndVersion();
|
|
17
|
+
const docsPreferredVersionByPluginId = useDocsPreferredVersionByPluginId();
|
|
18
|
+
function getDocPluginTags(pluginId) {
|
|
19
|
+
const activeVersion = activePluginAndVersion?.activePlugin?.pluginId === pluginId
|
|
20
|
+
? activePluginAndVersion.activeVersion
|
|
21
|
+
: undefined;
|
|
22
|
+
const preferredVersion = docsPreferredVersionByPluginId[pluginId];
|
|
23
|
+
const latestVersion = allDocsData[pluginId].versions.find((v) => v.isLast);
|
|
24
|
+
const version = activeVersion ?? preferredVersion ?? latestVersion;
|
|
25
|
+
return docVersionSearchTag(pluginId, version.name);
|
|
26
|
+
}
|
|
27
|
+
const tags = [
|
|
28
|
+
DEFAULT_SEARCH_TAG,
|
|
29
|
+
...Object.keys(allDocsData).map(getDocPluginTags),
|
|
30
|
+
];
|
|
31
|
+
return {
|
|
32
|
+
locale: i18n.currentLocale,
|
|
33
|
+
tags,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=useContextualSearchFilters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useContextualSearchFilters.js","sourceRoot":"","sources":["../../src/utils/useContextualSearchFilters.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,cAAc,EACd,yBAAyB,GAC1B,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAC,iCAAiC,EAAC,MAAM,gDAAgD,CAAC;AACjG,OAAO,EAAC,mBAAmB,EAAE,kBAAkB,EAAC,MAAM,eAAe,CAAC;AACtE,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;AAOpE,uEAAuE;AACvE,8EAA8E;AAC9E,MAAM,UAAU,0BAA0B;IACxC,MAAM,EAAC,IAAI,EAAC,GAAG,oBAAoB,EAAE,CAAC;IACtC,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;IACrC,MAAM,sBAAsB,GAAG,yBAAyB,EAAE,CAAC;IAC3D,MAAM,8BAA8B,GAAG,iCAAiC,EAAE,CAAC;IAE3E,SAAS,gBAAgB,CAAC,QAAgB;QACxC,MAAM,aAAa,GACjB,sBAAsB,EAAE,YAAY,EAAE,QAAQ,KAAK,QAAQ;YACzD,CAAC,CAAC,sBAAsB,CAAC,aAAa;YACtC,CAAC,CAAC,SAAS,CAAC;QAEhB,MAAM,gBAAgB,GAAG,8BAA8B,CAAC,QAAQ,CAAC,CAAC;QAElE,MAAM,aAAa,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAE,CAAC;QAE5E,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"}
|
|
@@ -0,0 +1,8 @@
|
|
|
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 function useLocalPathname(): string;
|
|
8
|
+
//# sourceMappingURL=useLocalPathname.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLocalPathname.d.ts","sourceRoot":"","sources":["../../src/utils/useLocalPathname.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,wBAAgB,gBAAgB,IAAI,MAAM,CAMzC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
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 useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
8
|
+
import { useLocation } from '@docusaurus/router';
|
|
9
|
+
// Get the pathname of current route, without the optional site baseUrl
|
|
10
|
+
// - /docs/myDoc => /docs/myDoc
|
|
11
|
+
// - /baseUrl/docs/myDoc => /docs/myDoc
|
|
12
|
+
export function useLocalPathname() {
|
|
13
|
+
const { siteConfig: { baseUrl }, } = useDocusaurusContext();
|
|
14
|
+
const { pathname } = useLocation();
|
|
15
|
+
return pathname.replace(baseUrl, '/');
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=useLocalPathname.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLocalPathname.js","sourceRoot":"","sources":["../../src/utils/useLocalPathname.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,oBAAoB,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAC,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAE/C,uEAAuE;AACvE,+BAA+B;AAC/B,uCAAuC;AACvC,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"}
|
|
@@ -4,7 +4,7 @@
|
|
|
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 { Location } from '
|
|
7
|
+
import type { Location } from 'history';
|
|
8
8
|
declare type LocationChangeEvent = {
|
|
9
9
|
location: Location;
|
|
10
10
|
previousLocation: Location | undefined;
|
|
@@ -12,3 +12,4 @@ declare type LocationChangeEvent = {
|
|
|
12
12
|
declare type OnLocationChange = (locationChangeEvent: LocationChangeEvent) => void;
|
|
13
13
|
export declare function useLocationChange(onLocationChange: OnLocationChange): void;
|
|
14
14
|
export {};
|
|
15
|
+
//# sourceMappingURL=useLocationChange.d.ts.map
|
|
@@ -0,0 +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;AAItC,aAAK,mBAAmB,GAAG;IACzB,QAAQ,EAAE,QAAQ,CAAC;IACnB,gBAAgB,EAAE,QAAQ,GAAG,SAAS,CAAC;CACxC,CAAC;AAEF,aAAK,gBAAgB,GAAG,CAAC,mBAAmB,EAAE,mBAAmB,KAAK,IAAI,CAAC;AAE3E,wBAAgB,iBAAiB,CAAC,gBAAgB,EAAE,gBAAgB,GAAG,IAAI,CAkB1E"}
|
|
@@ -4,22 +4,24 @@
|
|
|
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 { useEffect
|
|
7
|
+
import { useEffect } from 'react';
|
|
8
8
|
import { useLocation } from '@docusaurus/router';
|
|
9
9
|
import { usePrevious } from './usePrevious';
|
|
10
|
+
import { useDynamicCallback } from './reactUtils';
|
|
10
11
|
export function useLocationChange(onLocationChange) {
|
|
11
12
|
const location = useLocation();
|
|
12
13
|
const previousLocation = usePrevious(location);
|
|
13
|
-
const
|
|
14
|
+
const onLocationChangeDynamic = useDynamicCallback(onLocationChange);
|
|
14
15
|
useEffect(() => {
|
|
15
|
-
|
|
16
|
-
if (isFirst.current) {
|
|
17
|
-
isFirst.current = false;
|
|
16
|
+
if (!previousLocation) {
|
|
18
17
|
return;
|
|
19
18
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
if (location !== previousLocation) {
|
|
20
|
+
onLocationChangeDynamic({
|
|
21
|
+
location,
|
|
22
|
+
previousLocation,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}, [onLocationChangeDynamic, location, previousLocation]);
|
|
25
26
|
}
|
|
27
|
+
//# sourceMappingURL=useLocationChange.js.map
|
|
@@ -0,0 +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,WAAW,EAAC,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAC,kBAAkB,EAAC,MAAM,cAAc,CAAC;AAShD,MAAM,UAAU,iBAAiB,CAAC,gBAAkC;IAClE,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usePluralForm.d.ts","sourceRoot":"","sources":["../../src/utils/usePluralForm.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA8GH,wBAAgB,aAAa,IAAI;IAC/B,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,KAAK,MAAM,CAAC;CAClE,CAMA"}
|
|
@@ -34,26 +34,32 @@ function createLocalePluralForms(locale) {
|
|
|
34
34
|
select: (count) => pluralRules.select(count),
|
|
35
35
|
};
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Poor man's PluralSelector implementation, using an english fallback. We want
|
|
39
|
+
* a lightweight, future-proof and good-enough solution. We don't want a perfect
|
|
40
|
+
* and heavy solution.
|
|
41
|
+
*
|
|
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 ICU
|
|
44
|
+
* syntax (react-intl) just for that.
|
|
45
|
+
*
|
|
46
|
+
* Notes:
|
|
47
|
+
* - 2021: 92+% Browsers support Intl.PluralRules, and support will increase in
|
|
48
|
+
* the future
|
|
49
|
+
* - NodeJS >= 13 has full ICU support by default
|
|
50
|
+
* - In case of "mismatch" between SSR and Browser ICU support, React keeps
|
|
51
|
+
* working!
|
|
52
|
+
*/
|
|
48
53
|
function useLocalePluralForms() {
|
|
49
54
|
const { i18n: { currentLocale }, } = useDocusaurusContext();
|
|
50
55
|
return useMemo(() => {
|
|
51
|
-
// @ts-expect-error checking Intl.PluralRules in case browser doesn't
|
|
56
|
+
// @ts-expect-error checking Intl.PluralRules in case browser doesn't
|
|
57
|
+
// have it (e.g Safari 12-)
|
|
52
58
|
if (Intl.PluralRules) {
|
|
53
59
|
try {
|
|
54
60
|
return createLocalePluralForms(currentLocale);
|
|
55
61
|
}
|
|
56
|
-
catch
|
|
62
|
+
catch {
|
|
57
63
|
console.error(`Failed to use Intl.PluralRules for locale "${currentLocale}".
|
|
58
64
|
Docusaurus will fallback to a default/fallback (English) Intl.PluralRules implementation.
|
|
59
65
|
`);
|
|
@@ -74,21 +80,19 @@ function selectPluralMessage(pluralMessages, count, localePluralForms) {
|
|
|
74
80
|
if (parts.length === 1) {
|
|
75
81
|
return parts[0];
|
|
76
82
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
console.error(`For locale=${localePluralForms.locale}, a maximum of ${localePluralForms.pluralForms.length} plural forms are expected (${localePluralForms.pluralForms}), but the message contains ${parts.length} plural forms: ${pluralMessages} `);
|
|
80
|
-
}
|
|
81
|
-
const pluralForm = localePluralForms.select(count);
|
|
82
|
-
const pluralFormIndex = localePluralForms.pluralForms.indexOf(pluralForm);
|
|
83
|
-
// In case of not enough plural form messages, we take the last one (other) instead of returning undefined
|
|
84
|
-
return parts[Math.min(pluralFormIndex, parts.length - 1)];
|
|
83
|
+
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} plural forms: ${pluralMessages} `);
|
|
85
85
|
}
|
|
86
|
+
const pluralForm = localePluralForms.select(count);
|
|
87
|
+
const pluralFormIndex = localePluralForms.pluralForms.indexOf(pluralForm);
|
|
88
|
+
// In case of not enough plural form messages, we take the last one (other)
|
|
89
|
+
// instead of returning undefined
|
|
90
|
+
return parts[Math.min(pluralFormIndex, parts.length - 1)];
|
|
86
91
|
}
|
|
87
92
|
export function usePluralForm() {
|
|
88
93
|
const localePluralForm = useLocalePluralForms();
|
|
89
94
|
return {
|
|
90
|
-
selectMessage: (count, pluralMessages) =>
|
|
91
|
-
return selectPluralMessage(pluralMessages, count, localePluralForm);
|
|
92
|
-
},
|
|
95
|
+
selectMessage: (count, pluralMessages) => selectPluralMessage(pluralMessages, count, localePluralForm),
|
|
93
96
|
};
|
|
94
97
|
}
|
|
98
|
+
//# sourceMappingURL=usePluralForm.js.map
|
|
@@ -0,0 +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,EAAE,eAAe,CAC1B,WAAW,CAAC,eAAe,EAAE,CAAC,gBAAgB,CAC/C;QACD,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC;KAC7C,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,SAAS,oBAAoB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