@etsoo/react 1.5.85 → 1.5.86
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.js +1 -0
- package/lib/uses/useSearchParamsEx.d.ts +6 -0
- package/lib/uses/useSearchParamsEx.js +16 -0
- package/package.json +7 -7
- package/src/index.ts +1 -0
- package/src/uses/useSearchParamsEx.ts +22 -0
package/lib/index.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export * from './uses/useCombinedRefs';
|
|
|
21
21
|
export * from './uses/useDelayedExecutor';
|
|
22
22
|
export * from './uses/useDimensions';
|
|
23
23
|
export * from './uses/useParamsEx';
|
|
24
|
+
export * from './uses/useSearchParamsEx';
|
|
24
25
|
export * from './uses/useTimeout';
|
|
25
26
|
export * from './uses/useWindowScroll';
|
|
26
27
|
export * from './uses/useWindowSize';
|
package/lib/index.js
CHANGED
|
@@ -26,6 +26,7 @@ export * from './uses/useCombinedRefs';
|
|
|
26
26
|
export * from './uses/useDelayedExecutor';
|
|
27
27
|
export * from './uses/useDimensions';
|
|
28
28
|
export * from './uses/useParamsEx';
|
|
29
|
+
export * from './uses/useSearchParamsEx';
|
|
29
30
|
export * from './uses/useTimeout';
|
|
30
31
|
export * from './uses/useWindowScroll';
|
|
31
32
|
export * from './uses/useWindowSize';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DomUtils } from '@etsoo/shared';
|
|
2
|
+
import { useSearchParams } from 'react-router-dom';
|
|
3
|
+
/**
|
|
4
|
+
* Extended useSearchParams of react-router-dom
|
|
5
|
+
* Provide exact type data
|
|
6
|
+
*/
|
|
7
|
+
export function useSearchParamsEx(template) {
|
|
8
|
+
// Get parameters
|
|
9
|
+
const [sp] = useSearchParams();
|
|
10
|
+
const paras = Object.fromEntries(Object.keys(template).map((key) => {
|
|
11
|
+
const type = template[key];
|
|
12
|
+
return [key, type.endsWith('[]') ? sp.getAll(key) : sp.get(key)];
|
|
13
|
+
}));
|
|
14
|
+
// Return
|
|
15
|
+
return DomUtils.dataAs(paras, template, false);
|
|
16
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/react",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.86",
|
|
4
4
|
"description": "TypeScript ReactJs UI Independent Framework",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -48,12 +48,12 @@
|
|
|
48
48
|
"@dnd-kit/core": "^6.0.5",
|
|
49
49
|
"@dnd-kit/sortable": "^7.0.1",
|
|
50
50
|
"@emotion/css": "^11.10.0",
|
|
51
|
-
"@emotion/react": "^11.10.
|
|
52
|
-
"@emotion/styled": "^11.10.
|
|
51
|
+
"@emotion/react": "^11.10.4",
|
|
52
|
+
"@emotion/styled": "^11.10.4",
|
|
53
53
|
"@etsoo/appscript": "^1.2.88",
|
|
54
54
|
"@etsoo/notificationbase": "^1.1.7",
|
|
55
55
|
"@etsoo/shared": "^1.1.51",
|
|
56
|
-
"@types/react": "^18.0.
|
|
56
|
+
"@types/react": "^18.0.18",
|
|
57
57
|
"@types/react-dom": "^18.0.6",
|
|
58
58
|
"@types/react-window": "^1.8.5",
|
|
59
59
|
"react": "^18.2.0",
|
|
@@ -69,9 +69,9 @@
|
|
|
69
69
|
"@babel/runtime-corejs3": "^7.18.9",
|
|
70
70
|
"@testing-library/jest-dom": "^5.16.5",
|
|
71
71
|
"@testing-library/react": "^13.3.0",
|
|
72
|
-
"@types/jest": "^
|
|
73
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
74
|
-
"@typescript-eslint/parser": "^5.
|
|
72
|
+
"@types/jest": "^29.0.0",
|
|
73
|
+
"@typescript-eslint/eslint-plugin": "^5.36.1",
|
|
74
|
+
"@typescript-eslint/parser": "^5.36.1",
|
|
75
75
|
"eslint": "^8.23.0",
|
|
76
76
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
77
77
|
"eslint-plugin-import": "^2.26.0",
|
package/src/index.ts
CHANGED
|
@@ -30,6 +30,7 @@ export * from './uses/useCombinedRefs';
|
|
|
30
30
|
export * from './uses/useDelayedExecutor';
|
|
31
31
|
export * from './uses/useDimensions';
|
|
32
32
|
export * from './uses/useParamsEx';
|
|
33
|
+
export * from './uses/useSearchParamsEx';
|
|
33
34
|
export * from './uses/useTimeout';
|
|
34
35
|
export * from './uses/useWindowScroll';
|
|
35
36
|
export * from './uses/useWindowSize';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { DataTypes, DomUtils } from '@etsoo/shared';
|
|
2
|
+
import { useSearchParams } from 'react-router-dom';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Extended useSearchParams of react-router-dom
|
|
6
|
+
* Provide exact type data
|
|
7
|
+
*/
|
|
8
|
+
export function useSearchParamsEx<T extends DataTypes.BasicTemplate>(
|
|
9
|
+
template: T
|
|
10
|
+
) {
|
|
11
|
+
// Get parameters
|
|
12
|
+
const [sp] = useSearchParams();
|
|
13
|
+
const paras = Object.fromEntries(
|
|
14
|
+
Object.keys(template).map((key) => {
|
|
15
|
+
const type = template[key];
|
|
16
|
+
return [key, type.endsWith('[]') ? sp.getAll(key) : sp.get(key)];
|
|
17
|
+
})
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
// Return
|
|
21
|
+
return DomUtils.dataAs(paras, template, false);
|
|
22
|
+
}
|