@docusaurus/theme-common 2.2.0 → 2.3.0
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/hooks/useSearchPage.d.ts.map +1 -1
- package/lib/hooks/useSearchPage.js +4 -2
- package/lib/hooks/useSearchPage.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/internal.d.ts +3 -2
- package/lib/internal.d.ts.map +1 -1
- package/lib/internal.js +2 -2
- package/lib/internal.js.map +1 -1
- package/lib/utils/historyUtils.d.ts +12 -1
- package/lib/utils/historyUtils.d.ts.map +1 -1
- package/lib/utils/historyUtils.js +23 -0
- package/lib/utils/historyUtils.js.map +1 -1
- package/lib/utils/storageUtils.d.ts +4 -0
- package/lib/utils/storageUtils.d.ts.map +1 -1
- package/lib/utils/storageUtils.js +70 -7
- package/lib/utils/storageUtils.js.map +1 -1
- package/lib/utils/tabsUtils.d.ts +46 -0
- package/lib/utils/tabsUtils.d.ts.map +1 -0
- package/lib/utils/tabsUtils.js +151 -0
- package/lib/utils/tabsUtils.js.map +1 -0
- package/package.json +11 -10
- package/src/hooks/useSearchPage.ts +10 -5
- package/src/index.ts +5 -1
- package/src/internal.ts +7 -5
- package/src/utils/historyUtils.ts +29 -1
- package/src/utils/storageUtils.ts +108 -7
- package/src/utils/tabsUtils.tsx +266 -0
- package/lib/contexts/tabGroupChoice.d.ts +0 -21
- package/lib/contexts/tabGroupChoice.d.ts.map +0 -1
- package/lib/contexts/tabGroupChoice.js +0 -49
- package/lib/contexts/tabGroupChoice.js.map +0 -1
- package/src/contexts/tabGroupChoice.tsx +0 -85
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSearchPage.d.ts","sourceRoot":"","sources":["../../src/hooks/useSearchPage.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"useSearchPage.d.ts","sourceRoot":"","sources":["../../src/hooks/useSearchPage.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AASH,oDAAoD;AACpD,wBAAgB,aAAa,IAAI;IAC/B;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,cAAc,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,IAAI,CAAC;IACjD;;;OAGG;IACH,sBAAsB,EAAE,CAAC,iBAAiB,EAAE,MAAM,KAAK,MAAM,CAAC;CAC/D,CAoDA"}
|
|
@@ -11,7 +11,8 @@ const SEARCH_PARAM_QUERY = 'q';
|
|
|
11
11
|
/** Some utility functions around search queries. */
|
|
12
12
|
export function useSearchPage() {
|
|
13
13
|
const history = useHistory();
|
|
14
|
-
const { siteConfig: { baseUrl }, } = useDocusaurusContext();
|
|
14
|
+
const { siteConfig: { baseUrl, themeConfig }, } = useDocusaurusContext();
|
|
15
|
+
const { algolia: { searchPagePath }, } = themeConfig;
|
|
15
16
|
const [searchQuery, setSearchQueryState] = useState('');
|
|
16
17
|
// Init search query just after React hydration
|
|
17
18
|
useEffect(() => {
|
|
@@ -33,7 +34,8 @@ export function useSearchPage() {
|
|
|
33
34
|
}, [history]);
|
|
34
35
|
const generateSearchPageLink = useCallback((targetSearchQuery) =>
|
|
35
36
|
// Refer to https://github.com/facebook/docusaurus/pull/2838
|
|
36
|
-
|
|
37
|
+
// Note: if searchPagePath is falsy, useSearchPage() will not be called
|
|
38
|
+
`${baseUrl}${searchPagePath}?${SEARCH_PARAM_QUERY}=${encodeURIComponent(targetSearchQuery)}`, [baseUrl, searchPagePath]);
|
|
37
39
|
return {
|
|
38
40
|
searchQuery,
|
|
39
41
|
setSearchQuery,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSearchPage.js","sourceRoot":"","sources":["../../src/hooks/useSearchPage.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,WAAW,EAAE,SAAS,EAAE,QAAQ,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EAAE,cAAc,CAAC,CAAC;SACtD;aAAM;YACL,YAAY,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;SACzC;QAED,OAAO,CAAC,OAAO,CAAC;YACd,MAAM,EAAE,YAAY,CAAC,QAAQ,EAAE;SAChC,CAAC,CAAC;QACH,mBAAmB,CAAC,cAAc,CAAC,CAAC;IACtC,CAAC,EACD,CAAC,OAAO,CAAC,CACV,CAAC;IAEF,MAAM,sBAAsB,GAAG,WAAW,CACxC,CAAC,iBAAyB,EAAE,EAAE;IAC5B,4DAA4D;IAC5D,uEAAuE;IACvE,GAAG,OAAO,GACR,cACF,IAAI,kBAAkB,IAAI,kBAAkB,CAAC,iBAAiB,CAAC,EAAE,EACnE,CAAC,OAAO,EAAE,cAAc,CAAC,CAC1B,CAAC;IAEF,OAAO;QACL,WAAW;QACX,cAAc;QACd,sBAAsB;KACvB,CAAC;AACJ,CAAC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
export { useThemeConfig, type ThemeConfig, type UserThemeConfig, type Navbar, type NavbarItem, type NavbarLogo, type MultiColumnFooter, type SimpleFooter, type Footer, type FooterLogo, type FooterLinkItem, type ColorModeConfig, } from './utils/useThemeConfig';
|
|
8
|
-
export { createStorageSlot, listStorageKeys } from './utils/storageUtils';
|
|
8
|
+
export { createStorageSlot, useStorageSlot, listStorageKeys, } from './utils/storageUtils';
|
|
9
9
|
export { useContextualSearchFilters } from './utils/searchUtils';
|
|
10
10
|
export { useCurrentSidebarCategory, filterDocCardListItems, } from './utils/docsUtils';
|
|
11
11
|
export { usePluralForm } from './utils/usePluralForm';
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,EACL,cAAc,EACd,KAA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;AAEhD,OAAO,EAAC,aAAa,EAAC,MAAM,uBAAuB,CAAC;AAOpD,OAAO,EACL,sBAAsB,EACtB,iBAAiB,EACjB,KAAK,cAAc,GACpB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAC,wBAAwB,EAAC,MAAM,qBAAqB,CAAC;AAE7D,OAAO,EAAC,mBAAmB,EAAC,MAAM,qBAAqB,CAAC;AAExD,OAAO,EAAC,UAAU,EAAE,IAAI,EAAC,MAAM,iBAAiB,CAAC;AAEjD,OAAO,EAAC,aAAa,EAAC,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EAAC,uBAAuB,EAAC,MAAM,iCAAiC,CAAC;AAExE,OAAO,EAAC,sBAAsB,EAAC,MAAM,yBAAyB,CAAC;AAE/D,OAAO,EACL,uBAAuB,EACvB,iBAAiB,GAClB,MAAM,4BAA4B,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* APIs to document
|
|
9
9
|
*/
|
|
10
10
|
export { useThemeConfig, } from './utils/useThemeConfig';
|
|
11
|
-
export { createStorageSlot, listStorageKeys } from './utils/storageUtils';
|
|
11
|
+
export { createStorageSlot, useStorageSlot, listStorageKeys, } from './utils/storageUtils';
|
|
12
12
|
export { useContextualSearchFilters } from './utils/searchUtils';
|
|
13
13
|
export { useCurrentSidebarCategory, filterDocCardListItems, } from './utils/docsUtils';
|
|
14
14
|
export { usePluralForm } from './utils/usePluralForm';
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AAEH,OAAO,EACL,cAAc,GAYf,MAAM,wBAAwB,CAAC;AAEhC,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AAEH,OAAO,EACL,cAAc,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,7 +12,8 @@ export { DocProvider, useDoc, type DocContextValue } from './contexts/doc';
|
|
|
12
12
|
export { BlogPostProvider, useBlogPost, type BlogPostContextValue, } from './contexts/blogPost';
|
|
13
13
|
export { useDocsPreferredVersionByPluginId, DocsPreferredVersionContextProvider, } from './contexts/docsPreferredVersion';
|
|
14
14
|
export { AnnouncementBarProvider, useAnnouncementBar, } from './contexts/announcementBar';
|
|
15
|
-
export {
|
|
15
|
+
export { useTabs } from './utils/tabsUtils';
|
|
16
|
+
export type { TabValue, TabsProps, TabItemProps } from './utils/tabsUtils';
|
|
16
17
|
export { useNavbarMobileSidebar } from './contexts/navbarMobileSidebar';
|
|
17
18
|
export { useNavbarSecondaryMenu } from './contexts/navbarSecondaryMenu/display';
|
|
18
19
|
export { ColorModeProvider } from './contexts/colorMode';
|
|
@@ -23,7 +24,7 @@ export { isDocsPluginEnabled, useDocById, findSidebarCategory, findFirstCategory
|
|
|
23
24
|
export { useTitleFormatter } from './utils/generalUtils';
|
|
24
25
|
export { useLocationChange } from './utils/useLocationChange';
|
|
25
26
|
export { useLocalPathname } from './utils/useLocalPathname';
|
|
26
|
-
export { useHistoryPopHandler } from './utils/historyUtils';
|
|
27
|
+
export { useHistoryPopHandler, useHistorySelector, useQueryStringValue, } from './utils/historyUtils';
|
|
27
28
|
export { useFilteredAndTreeifiedTOC, useTreeifiedTOC, type TOCTreeNode, } from './utils/tocUtils';
|
|
28
29
|
export { ScrollControllerProvider, useScrollController, useScrollPosition, useScrollPositionBlocker, useSmoothScrollTo, } from './utils/scrollUtils';
|
|
29
30
|
export { useHomePageRoute, isSamePath } from './utils/routesUtils';
|
package/lib/internal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAaH,cAAc,SAAS,CAAC;AAExB,OAAO,EACL,oCAAoC,EACpC,+BAA+B,GAChC,MAAM,yCAAyC,C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AAC,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EACL,qBAAqB,EACrB,wBAAwB,GACzB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAC,iBAAiB,EAAC,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAC,aAAa,EAAC,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAC,eAAe,EAAC,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAC,oBAAoB,EAAC,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAC,kBAAkB,EAAC,MAAM,4BAA4B,CAAC"}
|
package/lib/internal.js
CHANGED
|
@@ -23,7 +23,7 @@ export { DocProvider, useDoc } from './contexts/doc';
|
|
|
23
23
|
export { BlogPostProvider, useBlogPost, } from './contexts/blogPost';
|
|
24
24
|
export { useDocsPreferredVersionByPluginId, DocsPreferredVersionContextProvider, } from './contexts/docsPreferredVersion';
|
|
25
25
|
export { AnnouncementBarProvider, useAnnouncementBar, } from './contexts/announcementBar';
|
|
26
|
-
export {
|
|
26
|
+
export { useTabs } from './utils/tabsUtils';
|
|
27
27
|
export { useNavbarMobileSidebar } from './contexts/navbarMobileSidebar';
|
|
28
28
|
export { useNavbarSecondaryMenu } from './contexts/navbarSecondaryMenu/display';
|
|
29
29
|
export { ColorModeProvider } from './contexts/colorMode';
|
|
@@ -34,7 +34,7 @@ export { isDocsPluginEnabled, useDocById, findSidebarCategory, findFirstCategory
|
|
|
34
34
|
export { useTitleFormatter } from './utils/generalUtils';
|
|
35
35
|
export { useLocationChange } from './utils/useLocationChange';
|
|
36
36
|
export { useLocalPathname } from './utils/useLocalPathname';
|
|
37
|
-
export { useHistoryPopHandler } from './utils/historyUtils';
|
|
37
|
+
export { useHistoryPopHandler, useHistorySelector, useQueryStringValue, } from './utils/historyUtils';
|
|
38
38
|
export { useFilteredAndTreeifiedTOC, useTreeifiedTOC, } from './utils/tocUtils';
|
|
39
39
|
export { ScrollControllerProvider, useScrollController, useScrollPosition, useScrollPositionBlocker, useSmoothScrollTo, } from './utils/scrollUtils';
|
|
40
40
|
export { useHomePageRoute, isSamePath } from './utils/routesUtils';
|
package/lib/internal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,4EAA4E;AAC5E,6EAA6E;AAC7E,2EAA2E;AAC3E,uDAAuD;AACvD,EAAE;AACF,6DAA6D;AAC7D,gFAAgF;AAChF,yEAAyE;AACzE,oDAAoD;AACpD,EAAE;AACF,gDAAgD;AAChD,cAAc,SAAS,CAAC;AAExB,OAAO,EACL,oCAAoC,EACpC,+BAA+B,GAChC,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAC,mBAAmB,EAAE,cAAc,EAAC,MAAM,wBAAwB,CAAC;AAC3E,OAAO,EAAC,mBAAmB,EAAE,cAAc,EAAC,MAAM,wBAAwB,CAAC;AAE3E,OAAO,EAAC,WAAW,EAAE,MAAM,EAAuB,MAAM,gBAAgB,CAAC;AACzE,OAAO,EACL,gBAAgB,EAChB,WAAW,GAEZ,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,iCAAiC,EACjC,mCAAmC,GACpC,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EACL,uBAAuB,EACvB,kBAAkB,GACnB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,
|
|
1
|
+
{"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,4EAA4E;AAC5E,6EAA6E;AAC7E,2EAA2E;AAC3E,uDAAuD;AACvD,EAAE;AACF,6DAA6D;AAC7D,gFAAgF;AAChF,yEAAyE;AACzE,oDAAoD;AACpD,EAAE;AACF,gDAAgD;AAChD,cAAc,SAAS,CAAC;AAExB,OAAO,EACL,oCAAoC,EACpC,+BAA+B,GAChC,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAC,mBAAmB,EAAE,c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B,EAC1B,eAAe,GAEhB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,iBAAiB,EACjB,wBAAwB,EACxB,iBAAiB,GAClB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAC,gBAAgB,EAAE,UAAU,EAAC,MAAM,qBAAqB,CAAC;AAEjE,OAAO,EAAC,2BAA2B,EAAC,MAAM,uBAAuB,CAAC;AAElE,OAAO,EAAC,gBAAgB,EAAE,cAAc,EAAC,MAAM,qBAAqB,CAAC;AAErE,OAAO,EACL,eAAe,GAEhB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAC,iBAAiB,EAAC,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EACL,qBAAqB,EACrB,wBAAwB,GACzB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAC,iBAAiB,EAAC,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAC,aAAa,EAAC,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAC,eAAe,EAAC,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAC,oBAAoB,EAAC,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAC,kBAAkB,EAAC,MAAM,4BAA4B,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 type { Location, Action } from 'history';
|
|
7
|
+
import type { History, Location, Action } from 'history';
|
|
8
8
|
declare type HistoryBlockHandler = (location: Location, action: Action) => void | false;
|
|
9
9
|
/**
|
|
10
10
|
* Permits to register a handler that will be called on history pop navigation
|
|
@@ -13,5 +13,16 @@ declare type HistoryBlockHandler = (location: Location, action: Action) => void
|
|
|
13
13
|
* "direction" (backward/forward) of the POP event.
|
|
14
14
|
*/
|
|
15
15
|
export declare function useHistoryPopHandler(handler: HistoryBlockHandler): void;
|
|
16
|
+
/**
|
|
17
|
+
* Permits to efficiently subscribe to a slice of the history
|
|
18
|
+
* See https://thisweekinreact.com/articles/useSyncExternalStore-the-underrated-react-api
|
|
19
|
+
* @param selector
|
|
20
|
+
*/
|
|
21
|
+
export declare function useHistorySelector<Value>(selector: (history: History<unknown>) => Value): Value;
|
|
22
|
+
/**
|
|
23
|
+
* Permits to efficiently subscribe to a specific querystring value
|
|
24
|
+
* @param key
|
|
25
|
+
*/
|
|
26
|
+
export declare function useQueryStringValue(key: string | null): string | null;
|
|
16
27
|
export {};
|
|
17
28
|
//# sourceMappingURL=historyUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"historyUtils.d.ts","sourceRoot":"","sources":["../../src/utils/historyUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"historyUtils.d.ts","sourceRoot":"","sources":["../../src/utils/historyUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAQH,OAAO,KAAK,EAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAC,MAAM,SAAS,CAAC;AAEvD,aAAK,mBAAmB,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,KAAK,CAAC;AAiBhF;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,mBAAmB,GAAG,IAAI,CASvE;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EACtC,QAAQ,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,KAAK,GAC7C,KAAK,CAGP;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,CAOrE"}
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { useEffect } from 'react';
|
|
8
8
|
import { useHistory } from '@docusaurus/router';
|
|
9
|
+
// @ts-expect-error: TODO temporary until React 18 upgrade
|
|
10
|
+
import { useSyncExternalStore } from 'use-sync-external-store/shim';
|
|
9
11
|
import { useEvent } from './reactUtils';
|
|
10
12
|
/**
|
|
11
13
|
* Permits to register a handler that will be called on history actions (pop,
|
|
@@ -35,4 +37,25 @@ export function useHistoryPopHandler(handler) {
|
|
|
35
37
|
return undefined;
|
|
36
38
|
});
|
|
37
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Permits to efficiently subscribe to a slice of the history
|
|
42
|
+
* See https://thisweekinreact.com/articles/useSyncExternalStore-the-underrated-react-api
|
|
43
|
+
* @param selector
|
|
44
|
+
*/
|
|
45
|
+
export function useHistorySelector(selector) {
|
|
46
|
+
const history = useHistory();
|
|
47
|
+
return useSyncExternalStore(history.listen, () => selector(history));
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Permits to efficiently subscribe to a specific querystring value
|
|
51
|
+
* @param key
|
|
52
|
+
*/
|
|
53
|
+
export function useQueryStringValue(key) {
|
|
54
|
+
return useHistorySelector((history) => {
|
|
55
|
+
if (key === null) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
return new URLSearchParams(history.location.search).get(key);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
38
61
|
//# sourceMappingURL=historyUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"historyUtils.js","sourceRoot":"","sources":["../../src/utils/historyUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,SAAS,EAAC,MAAM,OAAO,CAAC;AAChC,OAAO,EAAC,UAAU,EAAC,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAC,QAAQ,EAAC,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"historyUtils.js","sourceRoot":"","sources":["../../src/utils/historyUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,SAAS,EAAC,MAAM,OAAO,CA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AO,IAAI,eAAe,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC/D,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -10,6 +10,7 @@ export declare type StorageSlot = {
|
|
|
10
10
|
get: () => string | null;
|
|
11
11
|
set: (value: string) => void;
|
|
12
12
|
del: () => void;
|
|
13
|
+
listen: (onChange: (event: StorageEvent) => void) => () => void;
|
|
13
14
|
};
|
|
14
15
|
/**
|
|
15
16
|
* Creates an interface to work on a particular key in the storage model.
|
|
@@ -24,6 +25,9 @@ export declare type StorageSlot = {
|
|
|
24
25
|
export declare function createStorageSlot(key: string, options?: {
|
|
25
26
|
persistence?: StorageType;
|
|
26
27
|
}): StorageSlot;
|
|
28
|
+
export declare function useStorageSlot(key: string | null, options?: {
|
|
29
|
+
persistence?: StorageType;
|
|
30
|
+
}): [string | null, StorageSlot];
|
|
27
31
|
/**
|
|
28
32
|
* Returns a list of all the keys currently stored in browser storage,
|
|
29
33
|
* or an empty list if browser storage can't be accessed.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storageUtils.d.ts","sourceRoot":"","sources":["../../src/utils/storageUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"storageUtils.d.ts","sourceRoot":"","sources":["../../src/utils/storageUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,QAAA,MAAM,YAAY,qDAAsD,CAAC;AAEzE,oBAAY,WAAW,GAAG,OAAO,YAAY,CAAC,MAAM,CAAC,CAAC;AA6EtD,oBAAY,WAAW,GAAG;IACxB,GAAG,EAAE,MAAM,MAAM,GAAG,IAAI,CAAC;IACzB,GAAG,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7B,GAAG,EAAE,MAAM,IAAI,CAAC;IAChB,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,KAAK,MAAM,IAAI,CAAC;CACjE,CAAC;AAyBF;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE;IAAC,WAAW,CAAC,EAAE,WAAW,CAAA;CAAC,GACpC,WAAW,CA6Db;AAED,wBAAgB,cAAc,CAC5B,GAAG,EAAE,MAAM,GAAG,IAAI,EAClB,OAAO,CAAC,EAAE;IAAC,WAAW,CAAC,EAAE,WAAW,CAAA;CAAC,GACpC,CAAC,MAAM,GAAG,IAAI,EAAE,WAAW,CAAC,CAiC9B;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC7B,WAAW,GAAE,WAAgC,GAC5C,MAAM,EAAE,CAcV"}
|
|
@@ -4,8 +4,21 @@
|
|
|
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 { useCallback, useRef } from 'react';
|
|
8
|
+
// @ts-expect-error: TODO temp error until React 18 upgrade
|
|
9
|
+
import { useSyncExternalStore } from 'use-sync-external-store/shim';
|
|
7
10
|
const StorageTypes = ['localStorage', 'sessionStorage', 'none'];
|
|
8
11
|
const DefaultStorageType = 'localStorage';
|
|
12
|
+
// window.addEventListener('storage') only works for different windows...
|
|
13
|
+
// so for current window we have to dispatch the event manually
|
|
14
|
+
// Now we can listen for both cross-window / current-window storage changes!
|
|
15
|
+
// see https://stackoverflow.com/a/71177640/82609
|
|
16
|
+
// see https://stackoverflow.com/questions/26974084/listen-for-changes-with-localstorage-on-the-same-window
|
|
17
|
+
function dispatchChangeEvent({ key, oldValue, newValue, storage, }) {
|
|
18
|
+
const event = document.createEvent('StorageEvent');
|
|
19
|
+
event.initStorageEvent('storage', false, false, key, oldValue, newValue, window.location.href, storage);
|
|
20
|
+
window.dispatchEvent(event);
|
|
21
|
+
}
|
|
9
22
|
/**
|
|
10
23
|
* Will return `null` if browser storage is unavailable (like running Docusaurus
|
|
11
24
|
* in an iframe). This should NOT be called in SSR.
|
|
@@ -44,6 +57,7 @@ const NoopStorageSlot = {
|
|
|
44
57
|
get: () => null,
|
|
45
58
|
set: () => { },
|
|
46
59
|
del: () => { },
|
|
60
|
+
listen: () => () => { },
|
|
47
61
|
};
|
|
48
62
|
// Fail-fast, as storage APIs should not be used during the SSR process
|
|
49
63
|
function createServerStorageSlot(key) {
|
|
@@ -56,6 +70,7 @@ Please only call storage APIs in effects and event handlers.`);
|
|
|
56
70
|
get: throwError,
|
|
57
71
|
set: throwError,
|
|
58
72
|
del: throwError,
|
|
73
|
+
listen: throwError,
|
|
59
74
|
};
|
|
60
75
|
}
|
|
61
76
|
/**
|
|
@@ -72,38 +87,86 @@ export function createStorageSlot(key, options) {
|
|
|
72
87
|
if (typeof window === 'undefined') {
|
|
73
88
|
return createServerStorageSlot(key);
|
|
74
89
|
}
|
|
75
|
-
const
|
|
76
|
-
if (
|
|
90
|
+
const storage = getBrowserStorage(options?.persistence);
|
|
91
|
+
if (storage === null) {
|
|
77
92
|
return NoopStorageSlot;
|
|
78
93
|
}
|
|
79
94
|
return {
|
|
80
95
|
get: () => {
|
|
81
96
|
try {
|
|
82
|
-
return
|
|
97
|
+
return storage.getItem(key);
|
|
83
98
|
}
|
|
84
99
|
catch (err) {
|
|
85
100
|
console.error(`Docusaurus storage error, can't get key=${key}`, err);
|
|
86
101
|
return null;
|
|
87
102
|
}
|
|
88
103
|
},
|
|
89
|
-
set: (
|
|
104
|
+
set: (newValue) => {
|
|
90
105
|
try {
|
|
91
|
-
|
|
106
|
+
const oldValue = storage.getItem(key);
|
|
107
|
+
storage.setItem(key, newValue);
|
|
108
|
+
dispatchChangeEvent({
|
|
109
|
+
key,
|
|
110
|
+
oldValue,
|
|
111
|
+
newValue,
|
|
112
|
+
storage,
|
|
113
|
+
});
|
|
92
114
|
}
|
|
93
115
|
catch (err) {
|
|
94
|
-
console.error(`Docusaurus storage error, can't set ${key}=${
|
|
116
|
+
console.error(`Docusaurus storage error, can't set ${key}=${newValue}`, err);
|
|
95
117
|
}
|
|
96
118
|
},
|
|
97
119
|
del: () => {
|
|
98
120
|
try {
|
|
99
|
-
|
|
121
|
+
const oldValue = storage.getItem(key);
|
|
122
|
+
storage.removeItem(key);
|
|
123
|
+
dispatchChangeEvent({ key, oldValue, newValue: null, storage });
|
|
100
124
|
}
|
|
101
125
|
catch (err) {
|
|
102
126
|
console.error(`Docusaurus storage error, can't delete key=${key}`, err);
|
|
103
127
|
}
|
|
104
128
|
},
|
|
129
|
+
listen: (onChange) => {
|
|
130
|
+
try {
|
|
131
|
+
const listener = (event) => {
|
|
132
|
+
if (event.storageArea === storage && event.key === key) {
|
|
133
|
+
onChange(event);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
window.addEventListener('storage', listener);
|
|
137
|
+
return () => window.removeEventListener('storage', listener);
|
|
138
|
+
}
|
|
139
|
+
catch (err) {
|
|
140
|
+
console.error(`Docusaurus storage error, can't listen for changes of key=${key}`, err);
|
|
141
|
+
return () => { };
|
|
142
|
+
}
|
|
143
|
+
},
|
|
105
144
|
};
|
|
106
145
|
}
|
|
146
|
+
export function useStorageSlot(key, options) {
|
|
147
|
+
// Not ideal but good enough: assumes storage slot config is constant
|
|
148
|
+
const storageSlot = useRef(() => {
|
|
149
|
+
if (key === null) {
|
|
150
|
+
return NoopStorageSlot;
|
|
151
|
+
}
|
|
152
|
+
return createStorageSlot(key, options);
|
|
153
|
+
}).current();
|
|
154
|
+
const listen = useCallback((onChange) => {
|
|
155
|
+
// Do not try to add a listener during SSR
|
|
156
|
+
if (typeof window === 'undefined') {
|
|
157
|
+
return () => { };
|
|
158
|
+
}
|
|
159
|
+
return storageSlot.listen(onChange);
|
|
160
|
+
}, [storageSlot]);
|
|
161
|
+
const currentValue = useSyncExternalStore(listen, () => {
|
|
162
|
+
// TODO this check should be useless after React 18
|
|
163
|
+
if (typeof window === 'undefined') {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
return storageSlot.get();
|
|
167
|
+
}, () => null);
|
|
168
|
+
return [currentValue, storageSlot];
|
|
169
|
+
}
|
|
107
170
|
/**
|
|
108
171
|
* Returns a list of all the keys currently stored in browser storage,
|
|
109
172
|
* or an empty list if browser storage can't be accessed.
|
|
@@ -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;;;;;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,IAAI,CAAC;KACb;AACH,CAAC;AAED,IAAI,0CAA0C,GAAG,KAAK,CAAC;AACvD;;;;GAIG;AACH,SAAS,wCAAwC,CAAC,KAAY;IAC5D,IAAI,CAAC,0CAA0C,EAAE;QAC/C,OAAO,CAAC,IAAI,CACV;kIAC4H,EAC5H,KAAK,CACN,CAAC;QACF,0CAA0C,GAAG,IAAI,CAAC;KACnD;AACH,CAAC;
|
|
1
|
+
{"version":3,"file":"storageUtils.js","sourceRoot":"","sources":["../../src/utils/storageUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,WAAW,EAAE,MAAM,EAAC,MAAM,OAAO,CAAC;AAC1C,2DAA2D;AAC3D,OAAO,EAAC,oBAAoB,EAAC,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F;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import { type ReactNode, type ReactElement } from 'react';
|
|
8
|
+
/**
|
|
9
|
+
* TabValue is the "config" of a given Tab
|
|
10
|
+
* Provided through <Tabs> "values" prop or through the children <TabItem> props
|
|
11
|
+
*/
|
|
12
|
+
export interface TabValue {
|
|
13
|
+
readonly value: string;
|
|
14
|
+
readonly label?: string;
|
|
15
|
+
readonly attributes?: {
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
};
|
|
18
|
+
readonly default?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface TabsProps {
|
|
21
|
+
readonly lazy?: boolean;
|
|
22
|
+
readonly block?: boolean;
|
|
23
|
+
readonly children: readonly ReactElement<TabItemProps>[];
|
|
24
|
+
readonly defaultValue?: string | null;
|
|
25
|
+
readonly values?: readonly TabValue[];
|
|
26
|
+
readonly groupId?: string;
|
|
27
|
+
readonly className?: string;
|
|
28
|
+
readonly queryString?: string | boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface TabItemProps {
|
|
31
|
+
readonly children: ReactNode;
|
|
32
|
+
readonly value: string;
|
|
33
|
+
readonly default?: boolean;
|
|
34
|
+
readonly label?: string;
|
|
35
|
+
readonly hidden?: boolean;
|
|
36
|
+
readonly className?: string;
|
|
37
|
+
readonly attributes?: {
|
|
38
|
+
[key: string]: unknown;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export declare function useTabs(props: TabsProps): {
|
|
42
|
+
selectedValue: string;
|
|
43
|
+
selectValue: (value: string) => void;
|
|
44
|
+
tabValues: readonly TabValue[];
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=tabsUtils.d.ts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OAAO,CAAC;IAC1B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,CAAC,EAAE;QAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAC,CAAC;CAChD;AAuKD,wBAAgB,OAAO,CAAC,KAAK,EAAE,SAAS,GAAG;IACzC,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,SAAS,EAAE,SAAS,QAAQ,EAAE,CAAC;CAChC,CA4CA"}
|
|
@@ -0,0 +1,151 @@
|
|
|
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, { isValidElement, useCallback, useEffect, useState, useMemo, } from 'react';
|
|
8
|
+
import { useHistory } from '@docusaurus/router';
|
|
9
|
+
import { useQueryStringValue } from '@docusaurus/theme-common/internal';
|
|
10
|
+
import { duplicates, useStorageSlot } from '../index';
|
|
11
|
+
// A very rough duck type, but good enough to guard against mistakes while
|
|
12
|
+
// allowing customization
|
|
13
|
+
function isTabItem(comp) {
|
|
14
|
+
return 'value' in comp.props;
|
|
15
|
+
}
|
|
16
|
+
function ensureValidChildren(children) {
|
|
17
|
+
return React.Children.map(children, (child) => {
|
|
18
|
+
if (isValidElement(child) && isTabItem(child)) {
|
|
19
|
+
return child;
|
|
20
|
+
}
|
|
21
|
+
// child.type.name will give non-sensical values in prod because of
|
|
22
|
+
// minification, but we assume it won't throw in prod.
|
|
23
|
+
throw new Error(`Docusaurus error: Bad <Tabs> child <${
|
|
24
|
+
// @ts-expect-error: guarding against unexpected cases
|
|
25
|
+
typeof child.type === 'string' ? child.type : child.type.name}>: all children of the <Tabs> component should be <TabItem>, and every <TabItem> should have a unique "value" prop.`);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function extractChildrenTabValues(children) {
|
|
29
|
+
return ensureValidChildren(children).map(({ props: { value, label, attributes, default: isDefault } }) => ({
|
|
30
|
+
value,
|
|
31
|
+
label,
|
|
32
|
+
attributes,
|
|
33
|
+
default: isDefault,
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
function ensureNoDuplicateValue(values) {
|
|
37
|
+
const dup = duplicates(values, (a, b) => a.value === b.value);
|
|
38
|
+
if (dup.length > 0) {
|
|
39
|
+
throw new Error(`Docusaurus error: Duplicate values "${dup
|
|
40
|
+
.map((a) => a.value)
|
|
41
|
+
.join(', ')}" found in <Tabs>. Every value needs to be unique.`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function useTabValues(props) {
|
|
45
|
+
const { values: valuesProp, children } = props;
|
|
46
|
+
return useMemo(() => {
|
|
47
|
+
const values = valuesProp ?? extractChildrenTabValues(children);
|
|
48
|
+
ensureNoDuplicateValue(values);
|
|
49
|
+
return values;
|
|
50
|
+
}, [valuesProp, children]);
|
|
51
|
+
}
|
|
52
|
+
function isValidValue({ value, tabValues, }) {
|
|
53
|
+
return tabValues.some((a) => a.value === value);
|
|
54
|
+
}
|
|
55
|
+
function getInitialStateValue({ defaultValue, tabValues, }) {
|
|
56
|
+
if (tabValues.length === 0) {
|
|
57
|
+
throw new Error('Docusaurus error: the <Tabs> component requires at least one <TabItem> children component');
|
|
58
|
+
}
|
|
59
|
+
if (defaultValue) {
|
|
60
|
+
// Warn user about passing incorrect defaultValue as prop.
|
|
61
|
+
if (!isValidValue({ value: defaultValue, tabValues })) {
|
|
62
|
+
throw new Error(`Docusaurus error: The <Tabs> has a defaultValue "${defaultValue}" but none of its children has the corresponding value. Available values are: ${tabValues
|
|
63
|
+
.map((a) => a.value)
|
|
64
|
+
.join(', ')}. If you intend to show no default tab, use defaultValue={null} instead.`);
|
|
65
|
+
}
|
|
66
|
+
return defaultValue;
|
|
67
|
+
}
|
|
68
|
+
const defaultTabValue = tabValues.find((tabValue) => tabValue.default) ?? tabValues[0];
|
|
69
|
+
if (!defaultTabValue) {
|
|
70
|
+
throw new Error('Unexpected error: 0 tabValues');
|
|
71
|
+
}
|
|
72
|
+
return defaultTabValue.value;
|
|
73
|
+
}
|
|
74
|
+
function getStorageKey(groupId) {
|
|
75
|
+
if (!groupId) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
return `docusaurus.tab.${groupId}`;
|
|
79
|
+
}
|
|
80
|
+
function getQueryStringKey({ queryString = false, groupId, }) {
|
|
81
|
+
if (typeof queryString === 'string') {
|
|
82
|
+
return queryString;
|
|
83
|
+
}
|
|
84
|
+
if (queryString === false) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
if (queryString === true && !groupId) {
|
|
88
|
+
throw new Error(`Docusaurus error: The <Tabs> component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".`);
|
|
89
|
+
}
|
|
90
|
+
return groupId ?? null;
|
|
91
|
+
}
|
|
92
|
+
function useTabQueryString({ queryString = false, groupId, }) {
|
|
93
|
+
const history = useHistory();
|
|
94
|
+
const key = getQueryStringKey({ queryString, groupId });
|
|
95
|
+
const value = useQueryStringValue(key);
|
|
96
|
+
const setValue = useCallback((newValue) => {
|
|
97
|
+
if (!key) {
|
|
98
|
+
return; // no-op
|
|
99
|
+
}
|
|
100
|
+
const searchParams = new URLSearchParams(history.location.search);
|
|
101
|
+
searchParams.set(key, newValue);
|
|
102
|
+
history.replace({ ...history.location, search: searchParams.toString() });
|
|
103
|
+
}, [key, history]);
|
|
104
|
+
return [value, setValue];
|
|
105
|
+
}
|
|
106
|
+
function useTabStorage({ groupId }) {
|
|
107
|
+
const key = getStorageKey(groupId);
|
|
108
|
+
const [value, storageSlot] = useStorageSlot(key);
|
|
109
|
+
const setValue = useCallback((newValue) => {
|
|
110
|
+
if (!key) {
|
|
111
|
+
return; // no-op
|
|
112
|
+
}
|
|
113
|
+
storageSlot.set(newValue);
|
|
114
|
+
}, [key, storageSlot]);
|
|
115
|
+
return [value, setValue];
|
|
116
|
+
}
|
|
117
|
+
export function useTabs(props) {
|
|
118
|
+
const { defaultValue, queryString = false, groupId } = props;
|
|
119
|
+
const tabValues = useTabValues(props);
|
|
120
|
+
const [selectedValue, setSelectedValue] = useState(() => getInitialStateValue({ defaultValue, tabValues }));
|
|
121
|
+
const [queryStringValue, setQueryString] = useTabQueryString({
|
|
122
|
+
queryString,
|
|
123
|
+
groupId,
|
|
124
|
+
});
|
|
125
|
+
const [storageValue, setStorageValue] = useTabStorage({
|
|
126
|
+
groupId,
|
|
127
|
+
});
|
|
128
|
+
// We sync valid querystring/storage value to state on change + hydration
|
|
129
|
+
const valueToSync = (() => {
|
|
130
|
+
const value = queryStringValue ?? storageValue;
|
|
131
|
+
if (!isValidValue({ value, tabValues })) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
return value;
|
|
135
|
+
})();
|
|
136
|
+
useEffect(() => {
|
|
137
|
+
if (valueToSync) {
|
|
138
|
+
setSelectedValue(valueToSync);
|
|
139
|
+
}
|
|
140
|
+
}, [valueToSync]);
|
|
141
|
+
const selectValue = useCallback((newValue) => {
|
|
142
|
+
if (!isValidValue({ value: newValue, tabValues })) {
|
|
143
|
+
throw new Error(`Can't select invalid tab value=${newValue}`);
|
|
144
|
+
}
|
|
145
|
+
setSelectedValue(newValue);
|
|
146
|
+
setQueryString(newValue);
|
|
147
|
+
setStorageValue(newValue);
|
|
148
|
+
}, [setQueryString, setStorageValue, tabValues]);
|
|
149
|
+
return { selectedValue, selectValue, tabValues };
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=tabsUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tabsUtils.js","sourceRoot":"","sources":["../../src/utils/tabsUtils.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,EACZ,cAAc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