dry-ux 1.75.0 → 1.76.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.
|
@@ -60,6 +60,11 @@ export declare const toHashCode: (input: string) => number;
|
|
|
60
60
|
* @param value The value of the parameter.
|
|
61
61
|
*/
|
|
62
62
|
export declare const insertUrlParam: (key: any, value: any) => void;
|
|
63
|
+
/**
|
|
64
|
+
* Deletes a URL parameter.
|
|
65
|
+
* @param key
|
|
66
|
+
*/
|
|
67
|
+
export declare const deleteUrlParam: (key: any) => void;
|
|
63
68
|
/**
|
|
64
69
|
* Inserts multiple URL parameters.
|
|
65
70
|
* @param params An object containing key-value pairs of parameters.
|
|
@@ -129,4 +134,5 @@ export declare const useDimensions: (ref?: React.MutableRefObject<HTMLElement>)
|
|
|
129
134
|
export declare const useSearchParams: <T>() => {
|
|
130
135
|
params: T;
|
|
131
136
|
setParam: <TKey extends keyof T, TValue extends T[TKey]>(key: TKey, value: TValue) => void;
|
|
137
|
+
clearParams: <TKey extends keyof T>(...keys: TKey[]) => void;
|
|
132
138
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useSearchParams = exports.useDimensions = exports.usePubSub = exports.useIsVisible = exports.tryParseJson = exports.Deferred = exports.getUrlParams = exports.insertUrlParams = exports.insertUrlParam = exports.toHashCode = exports.StorageUtils = exports.fnWithAuthCheck = exports.formatDollar = exports.useCountdown = exports.importStyleSheet = exports.importScript = exports.preventDefault = void 0;
|
|
3
|
+
exports.useSearchParams = exports.useDimensions = exports.usePubSub = exports.useIsVisible = exports.tryParseJson = exports.Deferred = exports.getUrlParams = exports.insertUrlParams = exports.deleteUrlParam = exports.insertUrlParam = exports.toHashCode = exports.StorageUtils = exports.fnWithAuthCheck = exports.formatDollar = exports.useCountdown = exports.importStyleSheet = exports.importScript = exports.preventDefault = void 0;
|
|
4
4
|
const React = require("react");
|
|
5
5
|
/**
|
|
6
6
|
* Returns a function that will call the given handler and prevent the default event behavior.
|
|
@@ -167,6 +167,24 @@ const insertUrlParam = (key, value) => {
|
|
|
167
167
|
}
|
|
168
168
|
};
|
|
169
169
|
exports.insertUrlParam = insertUrlParam;
|
|
170
|
+
/**
|
|
171
|
+
* Deletes a URL parameter.
|
|
172
|
+
* @param key
|
|
173
|
+
*/
|
|
174
|
+
const deleteUrlParam = (key) => {
|
|
175
|
+
if (history.pushState) {
|
|
176
|
+
let searchParams = new URLSearchParams(window.location.search);
|
|
177
|
+
searchParams.delete(key);
|
|
178
|
+
let newUrl = window.location.protocol +
|
|
179
|
+
"//" +
|
|
180
|
+
window.location.host +
|
|
181
|
+
window.location.pathname +
|
|
182
|
+
"?" +
|
|
183
|
+
searchParams.toString();
|
|
184
|
+
window.history.pushState({ path: newUrl }, "", newUrl);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
exports.deleteUrlParam = deleteUrlParam;
|
|
170
188
|
/**
|
|
171
189
|
* Inserts multiple URL parameters.
|
|
172
190
|
* @param params An object containing key-value pairs of parameters.
|
|
@@ -314,9 +332,17 @@ const useSearchParams = () => {
|
|
|
314
332
|
(0, exports.insertUrlParam)(key, value);
|
|
315
333
|
setParams((0, exports.getUrlParams)());
|
|
316
334
|
}, []);
|
|
335
|
+
/**
|
|
336
|
+
* Clears one or more URL parameters and updates the state.
|
|
337
|
+
*/
|
|
338
|
+
const clearParams = React.useCallback((...keys) => {
|
|
339
|
+
keys.forEach(key => (0, exports.deleteUrlParam)(key));
|
|
340
|
+
setParams((0, exports.getUrlParams)());
|
|
341
|
+
}, []);
|
|
317
342
|
return {
|
|
318
343
|
params,
|
|
319
344
|
setParam,
|
|
345
|
+
clearParams,
|
|
320
346
|
};
|
|
321
347
|
};
|
|
322
348
|
exports.useSearchParams = useSearchParams;
|