@docusaurus/theme-common 0.0.0-5892 → 0.0.0-5898
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/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/utils/historyUtils.d.ts +7 -4
- package/lib/utils/historyUtils.d.ts.map +1 -1
- package/lib/utils/historyUtils.js +47 -13
- package/lib/utils/historyUtils.js.map +1 -1
- package/package.json +11 -11
- package/src/index.ts +7 -0
- package/src/utils/historyUtils.ts +65 -20
package/lib/index.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ export { duplicates, uniq } from './utils/jsUtils';
|
|
|
27
27
|
export { usePrismTheme } from './hooks/usePrismTheme';
|
|
28
28
|
export { useDocsPreferredVersion } from './contexts/docsPreferredVersion';
|
|
29
29
|
export { processAdmonitionProps } from './utils/admonitionUtils';
|
|
30
|
+
export { useHistorySelector, useQueryString, useQueryStringList, useClearQueryString, } from './utils/historyUtils';
|
|
30
31
|
export { SkipToContentFallbackId, SkipToContentLink, } from './utils/skipToContentUtils';
|
|
31
32
|
export { UnlistedBannerTitle, UnlistedBannerMessage, UnlistedMetadata, } from './utils/unlistedUtils';
|
|
32
33
|
export { ErrorBoundaryTryAgainButton, ErrorBoundaryError, ErrorBoundaryErrorMessageFallback, ErrorCauseBoundary, } from './utils/errorBoundaryUtils';
|
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,KAAK,WAAW,EAChB,KAAK,eAAe,EACpB,KAAK,MAAM,EACX,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,KAAK,MAAM,EACX,KAAK,UAAU,EACf,KAAK,cAAc,EAC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GACnB,MAAM,4BAA4B,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -34,6 +34,7 @@ export { duplicates, uniq } from './utils/jsUtils';
|
|
|
34
34
|
export { usePrismTheme } from './hooks/usePrismTheme';
|
|
35
35
|
export { useDocsPreferredVersion } from './contexts/docsPreferredVersion';
|
|
36
36
|
export { processAdmonitionProps } from './utils/admonitionUtils';
|
|
37
|
+
export { useHistorySelector, useQueryString, useQueryStringList, useClearQueryString, } from './utils/historyUtils';
|
|
37
38
|
export { SkipToContentFallbackId, SkipToContentLink, } from './utils/skipToContentUtils';
|
|
38
39
|
export { UnlistedBannerTitle, UnlistedBannerMessage, UnlistedMetadata, } from './utils/unlistedUtils';
|
|
39
40
|
export { ErrorBoundaryTryAgainButton, ErrorBoundaryError, ErrorBoundaryErrorMessageFallback, ErrorCauseBoundary, } from './utils/errorBoundaryUtils';
|
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,EAAC,OAAO,IAAI,eAAe,EAAC,MAAM,8BAA8B,CAAC;AAExE,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,eAAe,GAChB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAC,0BAA0B,EAAC,MAAM,qBAAqB,CAAC;AAE/D,OAAO,EACL,yBAAyB,EACzB,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,6BAA6B,EAC7B,yBAAyB,GAC1B,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAC,aAAa,EAAC,MAAM,uBAAuB,CAAC;AAEpD,OAAO,EAAC,cAAc,EAAE,WAAW,EAAC,MAAM,0BAA0B,CAAC;AAErE,OAAO,EAAC,eAAe,EAAC,MAAM,yBAAyB,CAAC;AAExD,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CAAC;AAEpD,OAAO,EAAC,uBAAuB,EAAC,MAAM,iCAAiC,CAAC;AAExE,OAAO,EAAC,sBAAsB,EAAC,MAAM,yBAAyB,CAAC;AAE/D,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,uBAAuB,EACvB,iBAAiB,GAClB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EACL,2BAA2B,EAC3B,kBAAkB,EAClB,iCAAiC,EACjC,kBAAkB,GACnB,MAAM,4BAA4B,CAAC"}
|
|
@@ -24,11 +24,14 @@ export declare function useHistorySelector<Value>(selector: (history: History<un
|
|
|
24
24
|
* @param key
|
|
25
25
|
*/
|
|
26
26
|
export declare function useQueryStringValue(key: string | null): string | null;
|
|
27
|
-
export declare function
|
|
28
|
-
push: boolean;
|
|
29
|
-
}) => void;
|
|
30
|
-
export declare function useQueryString(key: string): [string, (newValue: string, options?: {
|
|
27
|
+
export declare function useQueryString(key: string): [string, (newValue: string | null, options?: {
|
|
31
28
|
push: boolean;
|
|
32
29
|
}) => void];
|
|
30
|
+
type ListUpdate = string[] | ((oldValues: string[]) => string[]);
|
|
31
|
+
type ListUpdateFunction = (update: ListUpdate, options?: {
|
|
32
|
+
push: boolean;
|
|
33
|
+
}) => void;
|
|
34
|
+
export declare function useQueryStringList(key: string): [string[], ListUpdateFunction];
|
|
35
|
+
export declare function useClearQueryString(): () => void;
|
|
33
36
|
export {};
|
|
34
37
|
//# sourceMappingURL=historyUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"historyUtils.d.ts","sourceRoot":"","sources":["../../src/utils/historyUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,OAAO,KAAK,EAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,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AAO,CAAA;CAAC,KAAK,IAAI,CAAC,CAIxE;AAaD,KAAK,UAAU,GAAG,MAAM,EAAE,GAAG,CAAC,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,MAAM,EAAE,CAAC,CAAC;AACjE,KAAK,kBAAkB,GAAG,CACxB,MAAM,EAAE,UAAU,EAClB,OAAO,CAAC,EAAE;IAAC,IAAI,EAAE,OAAO,CAAA;CAAC,KACtB,IAAI,CAAC;AAuBV,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,MAAM,GACV,CAAC,MAAM,EAAE,EAAE,kBAAkB,CAAC,CAIhC;AAED,wBAAgB,mBAAmB,IAAI,MAAM,IAAI,CAOhD"}
|
|
@@ -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 { useCallback, useEffect, useSyncExternalStore } from 'react';
|
|
7
|
+
import { useCallback, useEffect, useMemo, useSyncExternalStore } from 'react';
|
|
8
8
|
import { useHistory } from '@docusaurus/router';
|
|
9
9
|
import { useEvent } from './reactUtils';
|
|
10
10
|
/**
|
|
@@ -56,9 +56,9 @@ export function useQueryStringValue(key) {
|
|
|
56
56
|
return new URLSearchParams(history.location.search).get(key);
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
|
-
|
|
59
|
+
function useQueryStringUpdater(key) {
|
|
60
60
|
const history = useHistory();
|
|
61
|
-
return useCallback((
|
|
61
|
+
return useCallback((newValue, options) => {
|
|
62
62
|
const searchParams = new URLSearchParams(history.location.search);
|
|
63
63
|
if (newValue) {
|
|
64
64
|
searchParams.set(key, newValue);
|
|
@@ -66,20 +66,54 @@ export function useQueryStringKeySetter() {
|
|
|
66
66
|
else {
|
|
67
67
|
searchParams.delete(key);
|
|
68
68
|
}
|
|
69
|
-
const
|
|
70
|
-
|
|
69
|
+
const updateHistory = options?.push ? history.push : history.replace;
|
|
70
|
+
updateHistory({
|
|
71
71
|
search: searchParams.toString(),
|
|
72
72
|
});
|
|
73
|
-
}, [history]);
|
|
73
|
+
}, [key, history]);
|
|
74
74
|
}
|
|
75
75
|
export function useQueryString(key) {
|
|
76
76
|
const value = useQueryStringValue(key) ?? '';
|
|
77
|
-
const
|
|
78
|
-
return [
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
77
|
+
const update = useQueryStringUpdater(key);
|
|
78
|
+
return [value, update];
|
|
79
|
+
}
|
|
80
|
+
function useQueryStringListValues(key) {
|
|
81
|
+
// Unfortunately we can't just use searchParams.getAll(key) in the selector
|
|
82
|
+
// It would create a new array every time and lead to an infinite loop...
|
|
83
|
+
// The selector has to return a primitive/string value to avoid that...
|
|
84
|
+
const arrayJsonString = useHistorySelector((history) => {
|
|
85
|
+
const values = new URLSearchParams(history.location.search).getAll(key);
|
|
86
|
+
return JSON.stringify(values);
|
|
87
|
+
});
|
|
88
|
+
return useMemo(() => JSON.parse(arrayJsonString), [arrayJsonString]);
|
|
89
|
+
}
|
|
90
|
+
function useQueryStringListUpdater(key) {
|
|
91
|
+
const history = useHistory();
|
|
92
|
+
const setValues = useCallback((update, options) => {
|
|
93
|
+
const searchParams = new URLSearchParams(history.location.search);
|
|
94
|
+
const newValues = Array.isArray(update)
|
|
95
|
+
? update
|
|
96
|
+
: update(searchParams.getAll(key));
|
|
97
|
+
searchParams.delete(key);
|
|
98
|
+
newValues.forEach((v) => searchParams.append(key, v));
|
|
99
|
+
const updateHistory = options?.push ? history.push : history.replace;
|
|
100
|
+
updateHistory({
|
|
101
|
+
search: searchParams.toString(),
|
|
102
|
+
});
|
|
103
|
+
}, [history, key]);
|
|
104
|
+
return setValues;
|
|
105
|
+
}
|
|
106
|
+
export function useQueryStringList(key) {
|
|
107
|
+
const values = useQueryStringListValues(key);
|
|
108
|
+
const setValues = useQueryStringListUpdater(key);
|
|
109
|
+
return [values, setValues];
|
|
110
|
+
}
|
|
111
|
+
export function useClearQueryString() {
|
|
112
|
+
const history = useHistory();
|
|
113
|
+
return useCallback(() => {
|
|
114
|
+
history.replace({
|
|
115
|
+
search: undefined,
|
|
116
|
+
});
|
|
117
|
+
}, [history]);
|
|
84
118
|
}
|
|
85
119
|
//# 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,WAAW,EAAE,SAAS,EAAE,oBAAoB,EAAC,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"historyUtils.js","sourceRoot":"","sources":["../../src/utils/historyUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,oBAAoB,EAAC,MAAM,OAAO,CAAC;AAC5E,OAAO,EAAC,UAAU,EAAC,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAC,QAAQ,EAAC,MAAM,cAAc,CAAC;AAMtC;;;;GAIG;AACH,SAAS,uBAAuB,CAAC,OAA4B;IAC3D,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,aAAa,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;IACxC,SAAS;IACP,kFAAkF;IAClF,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,EAC1E,CAAC,OAAO,EAAE,aAAa,CAAC,CACzB,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAA4B;IAC/D,uBAAuB,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE;QAC3C,IAAI,MAAM,KAAK,KAAK,EAAE;YACpB,kDAAkD;YAClD,OAAO,OAAO,CAAC,QAAQ,EAAE,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C,CAAC,CAAC,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;QAEtD,MAAM,aAAa,GAAG,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;QACrE,aAAa,CAAC;YACZ,MAAM,EAAE,YAAY,CAAC,QAAQ,EAAE;SAChC,CAAC,CAAC;IACL,CAAC,EACD,CAAC,OAAO,EAAE,GAAG,CAAC,CACf,CAAC;IACF,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,GAAW;IAEX,MAAM,MAAM,GAAG,wBAAwB,CAAC,GAAG,CAAC,CAAC;IAC7C,MAAM,SAAS,GAAG,yBAAyB,CAAC,GAAG,CAAC,CAAC;IACjD,OAAO,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;AAC7B,CAAC;AAED,MAAM,UAAU,mBAAmB;IACjC,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,OAAO,WAAW,CAAC,GAAG,EAAE;QACtB,OAAO,CAAC,OAAO,CAAC;YACd,MAAM,EAAE,SAAS;SAClB,CAAC,CAAC;IACL,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/theme-common",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-5898",
|
|
4
4
|
"description": "Common code for Docusaurus themes.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -30,13 +30,13 @@
|
|
|
30
30
|
},
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@docusaurus/mdx-loader": "0.0.0-
|
|
34
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
35
|
-
"@docusaurus/plugin-content-blog": "0.0.0-
|
|
36
|
-
"@docusaurus/plugin-content-docs": "0.0.0-
|
|
37
|
-
"@docusaurus/plugin-content-pages": "0.0.0-
|
|
38
|
-
"@docusaurus/utils": "0.0.0-
|
|
39
|
-
"@docusaurus/utils-common": "0.0.0-
|
|
33
|
+
"@docusaurus/mdx-loader": "0.0.0-5898",
|
|
34
|
+
"@docusaurus/module-type-aliases": "0.0.0-5898",
|
|
35
|
+
"@docusaurus/plugin-content-blog": "0.0.0-5898",
|
|
36
|
+
"@docusaurus/plugin-content-docs": "0.0.0-5898",
|
|
37
|
+
"@docusaurus/plugin-content-pages": "0.0.0-5898",
|
|
38
|
+
"@docusaurus/utils": "0.0.0-5898",
|
|
39
|
+
"@docusaurus/utils-common": "0.0.0-5898",
|
|
40
40
|
"@types/history": "^4.7.11",
|
|
41
41
|
"@types/react": "*",
|
|
42
42
|
"@types/react-router-config": "*",
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"utility-types": "^3.10.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@docusaurus/core": "0.0.0-
|
|
51
|
-
"@docusaurus/types": "0.0.0-
|
|
50
|
+
"@docusaurus/core": "0.0.0-5898",
|
|
51
|
+
"@docusaurus/types": "0.0.0-5898",
|
|
52
52
|
"fs-extra": "^11.1.1",
|
|
53
53
|
"lodash": "^4.17.21",
|
|
54
54
|
"schema-dts": "^1.1.2"
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"engines": {
|
|
61
61
|
"node": ">=18.0"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "9ae3e7f8841dc5ae7c07b084c48c1e80d4d355fe"
|
|
64
64
|
}
|
package/src/index.ts
CHANGED
|
@@ -98,6 +98,13 @@ export {useDocsPreferredVersion} from './contexts/docsPreferredVersion';
|
|
|
98
98
|
|
|
99
99
|
export {processAdmonitionProps} from './utils/admonitionUtils';
|
|
100
100
|
|
|
101
|
+
export {
|
|
102
|
+
useHistorySelector,
|
|
103
|
+
useQueryString,
|
|
104
|
+
useQueryStringList,
|
|
105
|
+
useClearQueryString,
|
|
106
|
+
} from './utils/historyUtils';
|
|
107
|
+
|
|
101
108
|
export {
|
|
102
109
|
SkipToContentFallbackId,
|
|
103
110
|
SkipToContentLink,
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {useCallback, useEffect, useSyncExternalStore} from 'react';
|
|
8
|
+
import {useCallback, useEffect, useMemo, useSyncExternalStore} from 'react';
|
|
9
9
|
import {useHistory} from '@docusaurus/router';
|
|
10
10
|
import {useEvent} from './reactUtils';
|
|
11
11
|
|
|
@@ -74,41 +74,86 @@ export function useQueryStringValue(key: string | null): string | null {
|
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
function useQueryStringUpdater(
|
|
78
78
|
key: string,
|
|
79
|
-
|
|
80
|
-
options?: {push: boolean},
|
|
81
|
-
) => void {
|
|
79
|
+
): (newValue: string | null, options?: {push: boolean}) => void {
|
|
82
80
|
const history = useHistory();
|
|
83
81
|
return useCallback(
|
|
84
|
-
(
|
|
82
|
+
(newValue, options) => {
|
|
85
83
|
const searchParams = new URLSearchParams(history.location.search);
|
|
86
84
|
if (newValue) {
|
|
87
85
|
searchParams.set(key, newValue);
|
|
88
86
|
} else {
|
|
89
87
|
searchParams.delete(key);
|
|
90
88
|
}
|
|
91
|
-
const
|
|
92
|
-
|
|
89
|
+
const updateHistory = options?.push ? history.push : history.replace;
|
|
90
|
+
updateHistory({
|
|
93
91
|
search: searchParams.toString(),
|
|
94
92
|
});
|
|
95
93
|
},
|
|
96
|
-
[history],
|
|
94
|
+
[key, history],
|
|
97
95
|
);
|
|
98
96
|
}
|
|
99
97
|
|
|
100
98
|
export function useQueryString(
|
|
101
99
|
key: string,
|
|
102
|
-
): [string, (newValue: string, options?: {push: boolean}) => void] {
|
|
100
|
+
): [string, (newValue: string | null, options?: {push: boolean}) => void] {
|
|
103
101
|
const value = useQueryStringValue(key) ?? '';
|
|
104
|
-
const
|
|
105
|
-
return [
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
102
|
+
const update = useQueryStringUpdater(key);
|
|
103
|
+
return [value, update];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function useQueryStringListValues(key: string): string[] {
|
|
107
|
+
// Unfortunately we can't just use searchParams.getAll(key) in the selector
|
|
108
|
+
// It would create a new array every time and lead to an infinite loop...
|
|
109
|
+
// The selector has to return a primitive/string value to avoid that...
|
|
110
|
+
const arrayJsonString = useHistorySelector((history) => {
|
|
111
|
+
const values = new URLSearchParams(history.location.search).getAll(key);
|
|
112
|
+
return JSON.stringify(values);
|
|
113
|
+
});
|
|
114
|
+
return useMemo(() => JSON.parse(arrayJsonString), [arrayJsonString]);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
type ListUpdate = string[] | ((oldValues: string[]) => string[]);
|
|
118
|
+
type ListUpdateFunction = (
|
|
119
|
+
update: ListUpdate,
|
|
120
|
+
options?: {push: boolean},
|
|
121
|
+
) => void;
|
|
122
|
+
|
|
123
|
+
function useQueryStringListUpdater(key: string): ListUpdateFunction {
|
|
124
|
+
const history = useHistory();
|
|
125
|
+
const setValues: ListUpdateFunction = useCallback(
|
|
126
|
+
(update, options) => {
|
|
127
|
+
const searchParams = new URLSearchParams(history.location.search);
|
|
128
|
+
const newValues = Array.isArray(update)
|
|
129
|
+
? update
|
|
130
|
+
: update(searchParams.getAll(key));
|
|
131
|
+
searchParams.delete(key);
|
|
132
|
+
newValues.forEach((v) => searchParams.append(key, v));
|
|
133
|
+
|
|
134
|
+
const updateHistory = options?.push ? history.push : history.replace;
|
|
135
|
+
updateHistory({
|
|
136
|
+
search: searchParams.toString(),
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
[history, key],
|
|
140
|
+
);
|
|
141
|
+
return setValues;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function useQueryStringList(
|
|
145
|
+
key: string,
|
|
146
|
+
): [string[], ListUpdateFunction] {
|
|
147
|
+
const values = useQueryStringListValues(key);
|
|
148
|
+
const setValues = useQueryStringListUpdater(key);
|
|
149
|
+
return [values, setValues];
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export function useClearQueryString(): () => void {
|
|
153
|
+
const history = useHistory();
|
|
154
|
+
return useCallback(() => {
|
|
155
|
+
history.replace({
|
|
156
|
+
search: undefined,
|
|
157
|
+
});
|
|
158
|
+
}, [history]);
|
|
114
159
|
}
|