@vef-framework/hooks 1.0.128 → 1.0.129
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/cjs/index.cjs +1 -106
- package/cjs/lib.cjs +1 -55
- package/cjs/use-authorized-items.cjs +1 -25
- package/cjs/use-color-tokens.cjs +1 -33
- package/cjs/use-computed-action-buttons.cjs +1 -44
- package/cjs/use-computed-options.cjs +1 -68
- package/cjs/use-context-disabled.cjs +1 -13
- package/cjs/use-data-query.cjs +1 -109
- package/cjs/use-deep-callback.cjs +1 -12
- package/cjs/use-deep-memo.cjs +1 -20
- package/cjs/use-deep-selector.cjs +1 -15
- package/cjs/use-fallback-options.cjs +1 -104
- package/cjs/use-gap-size-normalizer.cjs +1 -37
- package/cjs/use-normalized-gap-size.cjs +1 -11
- package/cjs/use-normalized-menu-items.cjs +1 -47
- package/cjs/use-normalized-options.cjs +1 -103
- package/cjs/use-option-filter.cjs +1 -19
- package/cjs/use-remote-filter.cjs +1 -38
- package/cjs/use-shallow-callback.cjs +1 -12
- package/cjs/use-shallow-memo.cjs +1 -20
- package/cjs/use-shallow-selector.cjs +1 -15
- package/cjs/use-singleton.cjs +1 -15
- package/cjs/use-theme-tokens.cjs +1 -12
- package/cjs/use-transient-store.cjs +1 -33
- package/cjs/use-window-size.cjs +1 -20
- package/esm/index.js +1 -28
- package/esm/lib.js +1 -4
- package/esm/use-authorized-items.js +1 -23
- package/esm/use-color-tokens.js +1 -29
- package/esm/use-computed-action-buttons.js +1 -42
- package/esm/use-computed-options.js +1 -66
- package/esm/use-context-disabled.js +1 -10
- package/esm/use-data-query.js +1 -107
- package/esm/use-deep-callback.js +1 -10
- package/esm/use-deep-memo.js +1 -18
- package/esm/use-deep-selector.js +1 -13
- package/esm/use-fallback-options.js +1 -102
- package/esm/use-gap-size-normalizer.js +1 -35
- package/esm/use-normalized-gap-size.js +1 -9
- package/esm/use-normalized-menu-items.js +1 -44
- package/esm/use-normalized-options.js +1 -101
- package/esm/use-option-filter.js +1 -17
- package/esm/use-remote-filter.js +1 -36
- package/esm/use-shallow-callback.js +1 -10
- package/esm/use-shallow-memo.js +1 -18
- package/esm/use-shallow-selector.js +1 -13
- package/esm/use-singleton.js +1 -13
- package/esm/use-theme-tokens.js +1 -10
- package/esm/use-transient-store.js +1 -31
- package/esm/use-window-size.js +1 -18
- package/package.json +3 -3
package/esm/use-data-query.js
CHANGED
|
@@ -1,108 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import
|
|
3
|
-
import { isNullish, isFunction } from '@vef-framework/shared';
|
|
4
|
-
import { useUnmount } from 'ahooks';
|
|
5
|
-
import { useMemo } from 'react';
|
|
6
|
-
|
|
7
|
-
"use strict";
|
|
8
|
-
function useApi({
|
|
9
|
-
data,
|
|
10
|
-
dataDictionaryKey,
|
|
11
|
-
api,
|
|
12
|
-
apiParams,
|
|
13
|
-
apiEnabled,
|
|
14
|
-
staleTime,
|
|
15
|
-
keepPreviousData,
|
|
16
|
-
placeholderData
|
|
17
|
-
}, stubQueryApi, dataDictionaryApi) {
|
|
18
|
-
return useMemo(() => {
|
|
19
|
-
if (!isNullish(data)) {
|
|
20
|
-
return [
|
|
21
|
-
stubQueryApi,
|
|
22
|
-
data,
|
|
23
|
-
{
|
|
24
|
-
keepPreviousData: true,
|
|
25
|
-
initialData: data
|
|
26
|
-
}
|
|
27
|
-
];
|
|
28
|
-
}
|
|
29
|
-
if (!isNullish(dataDictionaryKey)) {
|
|
30
|
-
return [
|
|
31
|
-
dataDictionaryApi,
|
|
32
|
-
{
|
|
33
|
-
...apiParams,
|
|
34
|
-
key: dataDictionaryKey
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
enabled: apiEnabled ?? true,
|
|
38
|
-
staleTime,
|
|
39
|
-
keepPreviousData,
|
|
40
|
-
placeholderData
|
|
41
|
-
}
|
|
42
|
-
];
|
|
43
|
-
}
|
|
44
|
-
if (!isNullish(api)) {
|
|
45
|
-
return [
|
|
46
|
-
api,
|
|
47
|
-
apiParams,
|
|
48
|
-
{
|
|
49
|
-
enabled: apiEnabled ?? true,
|
|
50
|
-
staleTime,
|
|
51
|
-
keepPreviousData,
|
|
52
|
-
placeholderData
|
|
53
|
-
}
|
|
54
|
-
];
|
|
55
|
-
}
|
|
56
|
-
return [
|
|
57
|
-
stubQueryApi,
|
|
58
|
-
[],
|
|
59
|
-
{
|
|
60
|
-
keepPreviousData: true,
|
|
61
|
-
initialData: []
|
|
62
|
-
}
|
|
63
|
-
];
|
|
64
|
-
}, [
|
|
65
|
-
data,
|
|
66
|
-
dataDictionaryKey,
|
|
67
|
-
api,
|
|
68
|
-
stubQueryApi,
|
|
69
|
-
dataDictionaryApi,
|
|
70
|
-
apiParams,
|
|
71
|
-
apiEnabled,
|
|
72
|
-
staleTime,
|
|
73
|
-
keepPreviousData,
|
|
74
|
-
placeholderData
|
|
75
|
-
]);
|
|
76
|
-
}
|
|
77
|
-
function useDataQuery({ onFetched, ...config }) {
|
|
78
|
-
const {
|
|
79
|
-
useApiQuery,
|
|
80
|
-
stubQueryApi,
|
|
81
|
-
dataDictionaryApi: dataDictionaryQueryApi
|
|
82
|
-
} = useApiContext();
|
|
83
|
-
const [api, args, options] = useApi(config, stubQueryApi, dataDictionaryQueryApi);
|
|
84
|
-
const result = useApiQuery(api, args, options);
|
|
85
|
-
useUnmount(() => {
|
|
86
|
-
if (Object.is(api, stubQueryApi)) {
|
|
87
|
-
stubQueryApi.removeQueries(args);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
const {
|
|
91
|
-
isSuccess,
|
|
92
|
-
data: rawData,
|
|
93
|
-
...rest
|
|
94
|
-
} = result;
|
|
95
|
-
const data = useMemo(() => {
|
|
96
|
-
if (isSuccess && isFunction(onFetched)) {
|
|
97
|
-
return onFetched(rawData);
|
|
98
|
-
}
|
|
99
|
-
return rawData;
|
|
100
|
-
}, [isSuccess, rawData, onFetched]);
|
|
101
|
-
return {
|
|
102
|
-
...rest,
|
|
103
|
-
isSuccess,
|
|
104
|
-
data
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export { useDataQuery };
|
|
2
|
+
import{useApiContext as k}from"@vef-framework/core";import{isNullish as l,isFunction as v}from"@vef-framework/shared";import{useUnmount as y}from"ahooks";import{useMemo as m}from"react";function P({data:e,dataDictionaryKey:s,api:o,apiParams:a,apiEnabled:u,staleTime:t,keepPreviousData:i,placeholderData:p},n,r){return m(()=>l(e)?l(s)?l(o)?[n,[],{keepPreviousData:!0,initialData:[]}]:[o,a,{enabled:u??!0,staleTime:t,keepPreviousData:i,placeholderData:p}]:[r,{...a,key:s},{enabled:u??!0,staleTime:t,keepPreviousData:i,placeholderData:p}]:[n,e,{keepPreviousData:!0,initialData:e}],[e,s,o,n,r,a,u,t,i,p])}function b({onFetched:e,...s}){const{useApiQuery:o,stubQueryApi:a,dataDictionaryApi:u}=k(),[t,i,p]=P(s,a,u),n=o(t,i,p);y(()=>{Object.is(t,a)&&a.removeQueries(i)});const{isSuccess:r,data:c,...D}=n,d=m(()=>r&&v(e)?e(c):c,[r,c,e]);return{...D,isSuccess:r,data:d}}export{b as useDataQuery};
|
package/esm/use-deep-callback.js
CHANGED
|
@@ -1,11 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import {
|
|
3
|
-
import { useDeepMemo } from './use-deep-memo.js';
|
|
4
|
-
|
|
5
|
-
"use strict";
|
|
6
|
-
function useDeepCallback(callback, dependencies) {
|
|
7
|
-
const memoizedDependencies = useDeepMemo(() => dependencies, dependencies);
|
|
8
|
-
return useCallback(callback, memoizedDependencies);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export { useDeepCallback };
|
|
2
|
+
import{useCallback as r}from"react";import{useDeepMemo as s}from"./use-deep-memo.js";function u(t,e){const o=s(()=>e,e);return r(t,o)}export{u as useDeepCallback};
|
package/esm/use-deep-memo.js
CHANGED
|
@@ -1,19 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import
|
|
3
|
-
import { useRef, useMemo } from 'react';
|
|
4
|
-
|
|
5
|
-
"use strict";
|
|
6
|
-
function useDeepMemo(factory, dependencies) {
|
|
7
|
-
const lastDependencies = useRef();
|
|
8
|
-
const signal = useRef(0);
|
|
9
|
-
if (lastDependencies.current === void 0 || !isEqual(dependencies, lastDependencies.current)) {
|
|
10
|
-
signal.current += 1;
|
|
11
|
-
}
|
|
12
|
-
lastDependencies.current = dependencies;
|
|
13
|
-
return useMemo(factory, [signal.current]);
|
|
14
|
-
}
|
|
15
|
-
function isEqual(one, another) {
|
|
16
|
-
return one.length === another.length && one.every((value, index) => isDeepEqual(value, another[index]));
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export { useDeepMemo };
|
|
2
|
+
import{isDeepEqual as o}from"@vef-framework/shared";import{useRef as n,useMemo as c}from"react";function s(t,r){const e=n(),u=n(0);return(e.current===void 0||!i(r,e.current))&&(u.current+=1),e.current=r,c(t,[u.current])}function i(t,r){return t.length===r.length&&t.every((e,u)=>o(e,r[u]))}export{s as useDeepMemo};
|
package/esm/use-deep-selector.js
CHANGED
|
@@ -1,14 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import
|
|
3
|
-
import { useRef } from 'react';
|
|
4
|
-
|
|
5
|
-
"use strict";
|
|
6
|
-
function useDeepSelector(selector) {
|
|
7
|
-
const prevSelectedState = useRef();
|
|
8
|
-
return (state) => {
|
|
9
|
-
const nextSelectedState = selector(state);
|
|
10
|
-
return isDeepEqual(prevSelectedState.current, nextSelectedState) ? prevSelectedState.current : prevSelectedState.current = nextSelectedState;
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export { useDeepSelector };
|
|
2
|
+
import{isDeepEqual as n}from"@vef-framework/shared";import{useRef as o}from"react";function c(t){const r=o();return u=>{const e=t(u);return n(r.current,e)?r.current:r.current=e}}export{c as useDeepSelector};
|
|
@@ -1,103 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import
|
|
3
|
-
import { isFunction } from '@vef-framework/shared';
|
|
4
|
-
import { useUnmount } from 'ahooks';
|
|
5
|
-
import { useId } from 'react';
|
|
6
|
-
import { useShallowMemo } from './use-shallow-memo.js';
|
|
7
|
-
|
|
8
|
-
"use strict";
|
|
9
|
-
function useApi(missingOptionValues, {
|
|
10
|
-
fallbackOptionsApi,
|
|
11
|
-
fallbackOptionsApiParams,
|
|
12
|
-
valuesKey,
|
|
13
|
-
resolveFallbackOptions
|
|
14
|
-
}, stubQueryApi, asyncFnQueryApi) {
|
|
15
|
-
const uniqueId = useId();
|
|
16
|
-
return useShallowMemo(() => {
|
|
17
|
-
if (missingOptionValues.length > 0) {
|
|
18
|
-
if (isFunction(resolveFallbackOptions)) {
|
|
19
|
-
const params = {
|
|
20
|
-
key: uniqueId,
|
|
21
|
-
args: [missingOptionValues],
|
|
22
|
-
fn: resolveFallbackOptions
|
|
23
|
-
};
|
|
24
|
-
return [
|
|
25
|
-
asyncFnQueryApi,
|
|
26
|
-
params,
|
|
27
|
-
{
|
|
28
|
-
keepPreviousData: true
|
|
29
|
-
}
|
|
30
|
-
];
|
|
31
|
-
}
|
|
32
|
-
if (fallbackOptionsApi) {
|
|
33
|
-
const params = {
|
|
34
|
-
...fallbackOptionsApiParams,
|
|
35
|
-
[valuesKey ?? "ids"]: missingOptionValues
|
|
36
|
-
};
|
|
37
|
-
return [
|
|
38
|
-
fallbackOptionsApi,
|
|
39
|
-
params,
|
|
40
|
-
{
|
|
41
|
-
keepPreviousData: true
|
|
42
|
-
}
|
|
43
|
-
];
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return [
|
|
47
|
-
stubQueryApi,
|
|
48
|
-
[],
|
|
49
|
-
{
|
|
50
|
-
keepPreviousData: true,
|
|
51
|
-
initialData: []
|
|
52
|
-
}
|
|
53
|
-
];
|
|
54
|
-
}, [
|
|
55
|
-
resolveFallbackOptions,
|
|
56
|
-
fallbackOptionsApi,
|
|
57
|
-
stubQueryApi,
|
|
58
|
-
uniqueId,
|
|
59
|
-
missingOptionValues,
|
|
60
|
-
asyncFnQueryApi,
|
|
61
|
-
fallbackOptionsApiParams,
|
|
62
|
-
valuesKey
|
|
63
|
-
]);
|
|
64
|
-
}
|
|
65
|
-
function useFallbackOptions(missingOptionValues, {
|
|
66
|
-
fallbackOptionsApi,
|
|
67
|
-
fallbackOptionsApiParams,
|
|
68
|
-
valuesKey,
|
|
69
|
-
resolveFallbackOptions
|
|
70
|
-
}) {
|
|
71
|
-
const {
|
|
72
|
-
useApiQuery,
|
|
73
|
-
stubQueryApi,
|
|
74
|
-
asyncFnQueryApi
|
|
75
|
-
} = useApiContext();
|
|
76
|
-
const [
|
|
77
|
-
api,
|
|
78
|
-
params,
|
|
79
|
-
options
|
|
80
|
-
] = useApi(
|
|
81
|
-
missingOptionValues,
|
|
82
|
-
{
|
|
83
|
-
fallbackOptionsApi,
|
|
84
|
-
fallbackOptionsApiParams,
|
|
85
|
-
valuesKey,
|
|
86
|
-
resolveFallbackOptions
|
|
87
|
-
},
|
|
88
|
-
stubQueryApi,
|
|
89
|
-
asyncFnQueryApi
|
|
90
|
-
);
|
|
91
|
-
const result = useApiQuery(api, params, options);
|
|
92
|
-
useUnmount(() => {
|
|
93
|
-
if (Object.is(api, stubQueryApi)) {
|
|
94
|
-
stubQueryApi.removeQueries(params);
|
|
95
|
-
}
|
|
96
|
-
if (Object.is(api, asyncFnQueryApi)) {
|
|
97
|
-
asyncFnQueryApi.removeQueries(params);
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
return result;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export { useFallbackOptions };
|
|
2
|
+
import{useApiContext as m}from"@vef-framework/core";import{isFunction as f}from"@vef-framework/shared";import{useUnmount as b}from"ahooks";import{useId as k}from"react";import{useShallowMemo as O}from"./use-shallow-memo.js";function v(e,{fallbackOptionsApi:r,fallbackOptionsApiParams:o,valuesKey:l,resolveFallbackOptions:s},n,a){const i=k();return O(()=>{if(e.length>0){if(f(s))return[a,{key:i,args:[e],fn:s},{keepPreviousData:!0}];if(r){const t={...o,[l??"ids"]:e};return[r,t,{keepPreviousData:!0}]}}return[n,[],{keepPreviousData:!0,initialData:[]}]},[s,r,n,i,e,a,o,l])}function A(e,{fallbackOptionsApi:r,fallbackOptionsApiParams:o,valuesKey:l,resolveFallbackOptions:s}){const{useApiQuery:n,stubQueryApi:a,asyncFnQueryApi:i}=m(),[t,p,u]=v(e,{fallbackOptionsApi:r,fallbackOptionsApiParams:o,valuesKey:l,resolveFallbackOptions:s},a,i),c=n(t,p,u);return b(()=>{Object.is(t,a)&&a.removeQueries(p),Object.is(t,i)&&i.removeQueries(p)}),c}export{A as useFallbackOptions};
|
|
@@ -1,36 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import {
|
|
3
|
-
import { useThemeTokens } from './use-theme-tokens.js';
|
|
4
|
-
|
|
5
|
-
"use strict";
|
|
6
|
-
function useGapSizeNormalizer() {
|
|
7
|
-
const {
|
|
8
|
-
paddingXS,
|
|
9
|
-
paddingSM,
|
|
10
|
-
padding,
|
|
11
|
-
paddingMD,
|
|
12
|
-
paddingLG
|
|
13
|
-
} = useThemeTokens();
|
|
14
|
-
return useCallback((gap) => {
|
|
15
|
-
if (gap === "tiny") {
|
|
16
|
-
return paddingXS;
|
|
17
|
-
} else if (gap === "small") {
|
|
18
|
-
return paddingSM;
|
|
19
|
-
} else if (gap === "medium") {
|
|
20
|
-
return padding;
|
|
21
|
-
} else if (gap === "large") {
|
|
22
|
-
return paddingMD;
|
|
23
|
-
} else if (gap === "huge") {
|
|
24
|
-
return paddingLG;
|
|
25
|
-
}
|
|
26
|
-
return gap;
|
|
27
|
-
}, [
|
|
28
|
-
paddingXS,
|
|
29
|
-
paddingSM,
|
|
30
|
-
padding,
|
|
31
|
-
paddingMD,
|
|
32
|
-
paddingLG
|
|
33
|
-
]);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export { useGapSizeNormalizer };
|
|
2
|
+
import{useCallback as t}from"react";import{useThemeTokens as e}from"./use-theme-tokens.js";function m(){const{paddingXS:n,paddingSM:r,padding:a,paddingMD:d,paddingLG:o}=e();return t(i=>i==="tiny"?n:i==="small"?r:i==="medium"?a:i==="large"?d:i==="huge"?o:i,[n,r,a,d,o])}export{m as useGapSizeNormalizer};
|
|
@@ -1,10 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
"use strict";
|
|
5
|
-
function useNormalizedGapSize(gap) {
|
|
6
|
-
const normalize = useGapSizeNormalizer();
|
|
7
|
-
return normalize(gap);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export { useNormalizedGapSize };
|
|
2
|
+
import{useGapSizeNormalizer as r}from"./use-gap-size-normalizer.js";function i(e){return r()(e)}export{i as useNormalizedGapSize};
|
|
@@ -1,45 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
"use strict";
|
|
5
|
-
function normalizeMenuItem(item) {
|
|
6
|
-
if (item.type === "item") {
|
|
7
|
-
return {
|
|
8
|
-
type: "item",
|
|
9
|
-
key: item.key,
|
|
10
|
-
label: item.label,
|
|
11
|
-
disabled: item.disabled,
|
|
12
|
-
icon: item.icon,
|
|
13
|
-
extra: item.extra
|
|
14
|
-
};
|
|
15
|
-
} else if (item.type === "submenu") {
|
|
16
|
-
return {
|
|
17
|
-
type: "submenu",
|
|
18
|
-
key: item.key,
|
|
19
|
-
label: item.label,
|
|
20
|
-
disabled: item.disabled,
|
|
21
|
-
icon: item.icon,
|
|
22
|
-
children: item.children.map(normalizeMenuItem)
|
|
23
|
-
};
|
|
24
|
-
} else if (item.type === "group") {
|
|
25
|
-
return {
|
|
26
|
-
type: "group",
|
|
27
|
-
key: item.key,
|
|
28
|
-
label: item.label,
|
|
29
|
-
children: item.children.map(normalizeMenuItem)
|
|
30
|
-
};
|
|
31
|
-
} else {
|
|
32
|
-
return {
|
|
33
|
-
type: "divider",
|
|
34
|
-
key: item.key
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
function useNormalizedMenuItems(items) {
|
|
39
|
-
return useMemo(
|
|
40
|
-
() => items.map(normalizeMenuItem),
|
|
41
|
-
[items]
|
|
42
|
-
);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export { normalizeMenuItem, useNormalizedMenuItems };
|
|
2
|
+
import{useMemo as l}from"react";function i(e){return e.type==="item"?{type:"item",key:e.key,label:e.label,disabled:e.disabled,icon:e.icon,extra:e.extra}:e.type==="submenu"?{type:"submenu",key:e.key,label:e.label,disabled:e.disabled,icon:e.icon,children:e.children.map(i)}:e.type==="group"?{type:"group",key:e.key,label:e.label,children:e.children.map(i)}:{type:"divider",key:e.key}}function t(e){return l(()=>e.map(i),[e])}export{i as normalizeMenuItem,t as useNormalizedMenuItems};
|
|
@@ -1,102 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import
|
|
3
|
-
import { useMemo } from 'react';
|
|
4
|
-
|
|
5
|
-
"use strict";
|
|
6
|
-
function useNormalizedDataOptions(options, {
|
|
7
|
-
labelKey = "label",
|
|
8
|
-
valueKey = "value",
|
|
9
|
-
childrenKey = "children",
|
|
10
|
-
descriptionKey = "description",
|
|
11
|
-
disabledKey = "disabled",
|
|
12
|
-
defaultToFirst = false
|
|
13
|
-
}, {
|
|
14
|
-
isTree = false,
|
|
15
|
-
isGrouped = false,
|
|
16
|
-
parsePinyin = false,
|
|
17
|
-
selectedOptionValues = []
|
|
18
|
-
} = {}) {
|
|
19
|
-
return useMemo(() => {
|
|
20
|
-
const selectedOptionValuesSet = new Set(selectedOptionValues);
|
|
21
|
-
const isGroupedOptions = !isTree && isGrouped;
|
|
22
|
-
const normalizeOption = (option, isTopLevel = false) => {
|
|
23
|
-
const label = option[labelKey];
|
|
24
|
-
if (isNullish(label)) {
|
|
25
|
-
if (labelKey === "label") {
|
|
26
|
-
throw new VefError(-10001, `The label value of the option is required.`);
|
|
27
|
-
}
|
|
28
|
-
throw new VefError(-10001, `The label value pointed by '${labelKey}' of the option is required.`);
|
|
29
|
-
}
|
|
30
|
-
const value = option[valueKey];
|
|
31
|
-
if (isNullish(value)) {
|
|
32
|
-
if (valueKey === "value") {
|
|
33
|
-
throw new VefError(-10002, `The value of the option is required.`);
|
|
34
|
-
}
|
|
35
|
-
throw new VefError(-10002, `The value pointed by '${valueKey}' of the option is required.`);
|
|
36
|
-
}
|
|
37
|
-
const children = option[childrenKey];
|
|
38
|
-
const description = option[descriptionKey];
|
|
39
|
-
const disabled = option[disabledKey] ?? false;
|
|
40
|
-
const normalizedOption = {
|
|
41
|
-
...option,
|
|
42
|
-
label,
|
|
43
|
-
value,
|
|
44
|
-
children,
|
|
45
|
-
description,
|
|
46
|
-
disabled
|
|
47
|
-
};
|
|
48
|
-
if (parsePinyin) {
|
|
49
|
-
const { labelText, descriptionText } = normalizedOption;
|
|
50
|
-
if (isString(label) || isString(labelText)) {
|
|
51
|
-
normalizedOption.labelPinyin = parsePinyinFirstLetter(
|
|
52
|
-
isString(label) ? label : labelText
|
|
53
|
-
).join("");
|
|
54
|
-
}
|
|
55
|
-
if (isString(description) || isString(descriptionText)) {
|
|
56
|
-
normalizedOption.descriptionPinyin = parsePinyinFirstLetter(
|
|
57
|
-
isString(description) ? description : descriptionText
|
|
58
|
-
).join("");
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
if ((!isTopLevel || !isGroupedOptions) && selectedOptionValuesSet.has(value)) {
|
|
62
|
-
selectedOptionValuesSet.delete(value);
|
|
63
|
-
}
|
|
64
|
-
if (isArray(normalizedOption.children)) {
|
|
65
|
-
normalizedOption.children = normalizedOption.children.map((option2) => normalizeOption(option2));
|
|
66
|
-
}
|
|
67
|
-
return normalizedOption;
|
|
68
|
-
};
|
|
69
|
-
const normalizedOptions = options.map((option) => normalizeOption(option, true));
|
|
70
|
-
const missingOptionValues = Array.from(selectedOptionValuesSet);
|
|
71
|
-
if (!defaultToFirst) {
|
|
72
|
-
return [normalizedOptions, missingOptionValues];
|
|
73
|
-
}
|
|
74
|
-
if (isGroupedOptions) {
|
|
75
|
-
const firstNonEmptyGroupOption = normalizedOptions.find((item) => isArray(item.children) && item.children.length > 0);
|
|
76
|
-
return [
|
|
77
|
-
normalizedOptions,
|
|
78
|
-
missingOptionValues,
|
|
79
|
-
firstNonEmptyGroupOption?.children?.[0]
|
|
80
|
-
];
|
|
81
|
-
}
|
|
82
|
-
return [
|
|
83
|
-
normalizedOptions,
|
|
84
|
-
missingOptionValues,
|
|
85
|
-
normalizedOptions[0]
|
|
86
|
-
];
|
|
87
|
-
}, [
|
|
88
|
-
childrenKey,
|
|
89
|
-
defaultToFirst,
|
|
90
|
-
descriptionKey,
|
|
91
|
-
disabledKey,
|
|
92
|
-
isGrouped,
|
|
93
|
-
isTree,
|
|
94
|
-
labelKey,
|
|
95
|
-
options,
|
|
96
|
-
parsePinyin,
|
|
97
|
-
// selectedOptionValues,
|
|
98
|
-
valueKey
|
|
99
|
-
]);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export { useNormalizedDataOptions };
|
|
2
|
+
import{isNullish as F,VefError as c,isString as n,parsePinyinFirstLetter as O,isArray as g}from"@vef-framework/shared";import{useMemo as V}from"react";function $(f,{labelKey:l="label",valueKey:o="value",childrenKey:y="children",descriptionKey:b="description",disabledKey:m="disabled",defaultToFirst:v=!1},{isTree:w=!1,isGrouped:T=!1,parsePinyin:K=!1,selectedOptionValues:j=[]}={}){return V(()=>{const p=new Set(j),P=!w&&T,q=(e,s=!1)=>{const t=e[l];if(F(t))throw l==="label"?new c(-10001,"The label value of the option is required."):new c(-10001,`The label value pointed by '${l}' of the option is required.`);const d=e[o];if(F(d))throw o==="value"?new c(-10002,"The value of the option is required."):new c(-10002,`The value pointed by '${o}' of the option is required.`);const A=e[y],a=e[b],S=e[m]??!1,i={...e,label:t,value:d,children:A,description:a,disabled:S};if(K){const{labelText:u,descriptionText:x}=i;(n(t)||n(u))&&(i.labelPinyin=O(n(t)?t:u).join("")),(n(a)||n(x))&&(i.descriptionPinyin=O(n(a)?a:x).join(""))}return(!s||!P)&&p.has(d)&&p.delete(d),g(i.children)&&(i.children=i.children.map(u=>q(u))),i},r=f.map(e=>q(e,!0)),h=Array.from(p);if(!v)return[r,h];if(P){const e=r.find(s=>g(s.children)&&s.children.length>0);return[r,h,e?.children?.[0]]}return[r,h,r[0]]},[y,v,b,m,T,w,l,f,K,o])}export{$ as useNormalizedDataOptions};
|
package/esm/use-option-filter.js
CHANGED
|
@@ -1,18 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import
|
|
3
|
-
import { useMemo } from 'react';
|
|
4
|
-
|
|
5
|
-
"use strict";
|
|
6
|
-
function useOptionFilter(filterable, filterFromRemote) {
|
|
7
|
-
return useMemo(() => {
|
|
8
|
-
if (!filterable) {
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
if (filterFromRemote) {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
return (filterValue, option) => (isString(option.label) && option.label.includes(filterValue) || isString(option.labelText) && option.labelText.includes(filterValue) || option.labelPinyin?.includes(filterValue) || option.value.includes(filterValue) || isString(option.description) && option.description.includes(filterValue) || isString(option.descriptionText) && option.descriptionText.includes(filterValue) || option.descriptionPinyin?.includes(filterValue)) ?? false;
|
|
15
|
-
}, [filterable, filterFromRemote]);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export { useOptionFilter };
|
|
2
|
+
import{isString as t}from"@vef-framework/shared";import{useMemo as r}from"react";function s(l,n){return r(()=>{if(l)return n?!1:(e,i)=>(t(i.label)&&i.label.includes(e)||t(i.labelText)&&i.labelText.includes(e)||i.labelPinyin?.includes(e)||i.value.includes(e)||t(i.description)&&i.description.includes(e)||t(i.descriptionText)&&i.descriptionText.includes(e)||i.descriptionPinyin?.includes(e))??!1},[l,n])}export{s as useOptionFilter};
|
package/esm/use-remote-filter.js
CHANGED
|
@@ -1,37 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import
|
|
3
|
-
import { useState, useMemo } from 'react';
|
|
4
|
-
|
|
5
|
-
"use strict";
|
|
6
|
-
function useRemoteFilter(enabled, apiParams, keywordKey = "keyword") {
|
|
7
|
-
const [filterKeyword, setFilterKeyword] = useState();
|
|
8
|
-
const mergedApiParams = useMemo(() => {
|
|
9
|
-
if (!enabled) {
|
|
10
|
-
return apiParams;
|
|
11
|
-
}
|
|
12
|
-
const params = {
|
|
13
|
-
...apiParams
|
|
14
|
-
};
|
|
15
|
-
const keywordToUse = trim(filterKeyword);
|
|
16
|
-
if (keywordToUse) {
|
|
17
|
-
params[keywordKey] = keywordToUse;
|
|
18
|
-
}
|
|
19
|
-
return params;
|
|
20
|
-
}, [
|
|
21
|
-
enabled,
|
|
22
|
-
apiParams,
|
|
23
|
-
filterKeyword,
|
|
24
|
-
keywordKey
|
|
25
|
-
]);
|
|
26
|
-
const handleInputKeyword = useMemo(() => {
|
|
27
|
-
if (!enabled) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
return debounce({ delay: 500 }, (keyword) => {
|
|
31
|
-
setFilterKeyword(keyword);
|
|
32
|
-
});
|
|
33
|
-
}, [enabled]);
|
|
34
|
-
return [mergedApiParams, handleInputKeyword];
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export { useRemoteFilter };
|
|
2
|
+
import{trim as f,debounce as d}from"@vef-framework/shared";import{useState as p,useMemo as i}from"react";function y(r,t,o="keyword"){const[u,m]=p(),s=i(()=>{if(!r)return t;const e={...t},n=f(u);return n&&(e[o]=n),e},[r,t,u,o]),c=i(()=>{if(r)return d({delay:500},e=>{m(e)})},[r]);return[s,c]}export{y as useRemoteFilter};
|
|
@@ -1,11 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import {
|
|
3
|
-
import { useShallowMemo } from './use-shallow-memo.js';
|
|
4
|
-
|
|
5
|
-
"use strict";
|
|
6
|
-
function useShallowCallback(callback, dependencies) {
|
|
7
|
-
const memoizedDependencies = useShallowMemo(() => dependencies, dependencies);
|
|
8
|
-
return useCallback(callback, memoizedDependencies);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export { useShallowCallback };
|
|
2
|
+
import{useCallback as r}from"react";import{useShallowMemo as a}from"./use-shallow-memo.js";function e(t,o){const l=a(()=>o,o);return r(t,l)}export{e as useShallowCallback};
|
package/esm/use-shallow-memo.js
CHANGED
|
@@ -1,19 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import
|
|
3
|
-
import { useRef, useMemo } from 'react';
|
|
4
|
-
|
|
5
|
-
"use strict";
|
|
6
|
-
function useShallowMemo(factory, dependencies) {
|
|
7
|
-
const lastDependencies = useRef();
|
|
8
|
-
const signal = useRef(0);
|
|
9
|
-
if (lastDependencies.current === void 0 || !isEqual(dependencies, lastDependencies.current)) {
|
|
10
|
-
signal.current += 1;
|
|
11
|
-
}
|
|
12
|
-
lastDependencies.current = dependencies;
|
|
13
|
-
return useMemo(factory, [signal.current]);
|
|
14
|
-
}
|
|
15
|
-
function isEqual(one, another) {
|
|
16
|
-
return one.length === another.length && one.every((value, index) => isShallowEqual(value, another[index]));
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export { useShallowMemo };
|
|
2
|
+
import{isShallowEqual as o}from"@vef-framework/shared";import{useRef as n,useMemo as c}from"react";function s(e,r){const t=n(),u=n(0);return(t.current===void 0||!i(r,t.current))&&(u.current+=1),t.current=r,c(e,[u.current])}function i(e,r){return e.length===r.length&&e.every((t,u)=>o(t,r[u]))}export{s as useShallowMemo};
|
|
@@ -1,14 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import
|
|
3
|
-
import { useRef } from 'react';
|
|
4
|
-
|
|
5
|
-
"use strict";
|
|
6
|
-
function useShallowSelector(selector) {
|
|
7
|
-
const prevSelectedState = useRef();
|
|
8
|
-
return (state) => {
|
|
9
|
-
const nextSelectedState = selector(state);
|
|
10
|
-
return isShallowEqual(prevSelectedState.current, nextSelectedState) ? prevSelectedState.current : prevSelectedState.current = nextSelectedState;
|
|
11
|
-
};
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export { useShallowSelector };
|
|
2
|
+
import{isShallowEqual as u}from"@vef-framework/shared";import{useRef as n}from"react";function c(e){const r=n();return o=>{const t=e(o);return u(r.current,t)?r.current:r.current=t}}export{c as useShallowSelector};
|
package/esm/use-singleton.js
CHANGED
|
@@ -1,14 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import
|
|
3
|
-
import { useRef } from 'react';
|
|
4
|
-
|
|
5
|
-
"use strict";
|
|
6
|
-
function useSingleton(factory) {
|
|
7
|
-
const singleton = useRef();
|
|
8
|
-
if (isNullish(singleton.current)) {
|
|
9
|
-
singleton.current = factory();
|
|
10
|
-
}
|
|
11
|
-
return singleton.current;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export { useSingleton };
|
|
2
|
+
import{isNullish as e}from"@vef-framework/shared";import{useRef as n}from"react";function u(t){const r=n();return e(r.current)&&(r.current=t()),r.current}export{u as useSingleton};
|
package/esm/use-theme-tokens.js
CHANGED
|
@@ -1,11 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
"use strict";
|
|
5
|
-
const { useToken } = theme;
|
|
6
|
-
function useThemeTokens() {
|
|
7
|
-
const { token } = useToken();
|
|
8
|
-
return token;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export { useThemeTokens };
|
|
2
|
+
import{theme as t}from"antd";const{useToken:n}=t;function o(){const{token:e}=n();return e}export{o as useThemeTokens};
|
|
@@ -1,32 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import
|
|
3
|
-
import { useRef, useEffect } from 'react';
|
|
4
|
-
|
|
5
|
-
"use strict";
|
|
6
|
-
function useTransientStore({ subscribe, getState }, {
|
|
7
|
-
selector = (state) => state,
|
|
8
|
-
equalityFn = isShallowEqual,
|
|
9
|
-
listener
|
|
10
|
-
} = {}) {
|
|
11
|
-
const stateRef = useRef();
|
|
12
|
-
if (!stateRef.current) {
|
|
13
|
-
stateRef.current = selector(getState());
|
|
14
|
-
}
|
|
15
|
-
useEffect(
|
|
16
|
-
() => subscribe(
|
|
17
|
-
selector,
|
|
18
|
-
(state, prevState) => {
|
|
19
|
-
stateRef.current = state;
|
|
20
|
-
listener?.(state, prevState);
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
fireImmediately: false,
|
|
24
|
-
equalityFn
|
|
25
|
-
}
|
|
26
|
-
),
|
|
27
|
-
[equalityFn, listener, selector, subscribe]
|
|
28
|
-
);
|
|
29
|
-
return stateRef;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export { useTransientStore };
|
|
2
|
+
import{isShallowEqual as o}from"@vef-framework/shared";import{useRef as l,useEffect as f}from"react";function a({subscribe:r,getState:n},{selector:t=e=>e,equalityFn:u=o,listener:i}={}){const e=l();return e.current||(e.current=t(n())),f(()=>r(t,(s,c)=>{e.current=s,i?.(s,c)},{fireImmediately:!1,equalityFn:u}),[u,i,t,r]),e}export{a as useTransientStore};
|
package/esm/use-window-size.js
CHANGED
|
@@ -1,19 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
"use strict";
|
|
5
|
-
function useWindowSize() {
|
|
6
|
-
const [size, setSize] = useRafState(() => ({
|
|
7
|
-
width: window.innerWidth,
|
|
8
|
-
height: window.innerHeight
|
|
9
|
-
}));
|
|
10
|
-
useEventListener("resize", () => {
|
|
11
|
-
setSize({
|
|
12
|
-
width: window.innerWidth,
|
|
13
|
-
height: window.innerHeight
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
return size;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export { useWindowSize };
|
|
2
|
+
import{useRafState as n,useEventListener as t}from"ahooks";function r(){const[i,e]=n(()=>({width:window.innerWidth,height:window.innerHeight}));return t("resize",()=>{e({width:window.innerWidth,height:window.innerHeight})}),i}export{r as useWindowSize};
|