dry-ux 1.74.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.
@@ -59,7 +59,12 @@ export declare const toHashCode: (input: string) => number;
59
59
  * @param key The key of the parameter.
60
60
  * @param value The value of the parameter.
61
61
  */
62
- export declare const insertUrlParam: (key: string, value: any) => void;
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.
@@ -113,7 +118,21 @@ export declare const usePubSub: <T>() => {
113
118
  usePub: () => <TName extends keyof T, TPayload extends T[TName]>(event: TName, data?: TPayload) => void;
114
119
  useSub: <TName extends keyof T, TPayload_1 extends T[TName]>(event: TName, callback: (data: TPayload_1) => void) => () => void;
115
120
  };
121
+ /**
122
+ * Hook to get dimensions of an element or the viewport.
123
+ * @param ref
124
+ */
116
125
  export declare const useDimensions: (ref?: React.MutableRefObject<HTMLElement>) => {
117
126
  width: number;
118
127
  height: number;
119
128
  };
129
+ /**
130
+ * Hook to get and set URL search parameters.
131
+ * @template T The type of the URL parameters.
132
+ * @returns An object containing the current URL parameters and a function to set a parameter.
133
+ */
134
+ export declare const useSearchParams: <T>() => {
135
+ params: T;
136
+ setParam: <TKey extends keyof T, TValue extends T[TKey]>(key: TKey, value: TValue) => void;
137
+ clearParams: <TKey extends keyof T>(...keys: TKey[]) => void;
138
+ };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- 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.
@@ -282,6 +300,10 @@ const usePubSub = () => {
282
300
  return { usePub, useSub };
283
301
  };
284
302
  exports.usePubSub = usePubSub;
303
+ /**
304
+ * Hook to get dimensions of an element or the viewport.
305
+ * @param ref
306
+ */
285
307
  const useDimensions = (ref) => {
286
308
  const [size, setSize] = React.useState({ width: 0, height: 0 });
287
309
  const element = (ref === null || ref === void 0 ? void 0 : ref.current) || document.documentElement;
@@ -296,3 +318,31 @@ const useDimensions = (ref) => {
296
318
  return size;
297
319
  };
298
320
  exports.useDimensions = useDimensions;
321
+ /**
322
+ * Hook to get and set URL search parameters.
323
+ * @template T The type of the URL parameters.
324
+ * @returns An object containing the current URL parameters and a function to set a parameter.
325
+ */
326
+ const useSearchParams = () => {
327
+ const [params, setParams] = React.useState((0, exports.getUrlParams)());
328
+ /**
329
+ * Sets a URL parameter and updates the state.
330
+ */
331
+ const setParam = React.useCallback((key, value) => {
332
+ (0, exports.insertUrlParam)(key, value);
333
+ setParams((0, exports.getUrlParams)());
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
+ }, []);
342
+ return {
343
+ params,
344
+ setParam,
345
+ clearParams,
346
+ };
347
+ };
348
+ exports.useSearchParams = useSearchParams;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dry-ux",
3
- "version": "1.74.0",
3
+ "version": "1.76.0",
4
4
  "description": "",
5
5
  "main": "dist/index",
6
6
  "scripts": {