@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
|
@@ -1,38 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var react = require('react');
|
|
5
|
-
var useThemeTokens = require('./use-theme-tokens.cjs');
|
|
6
|
-
|
|
7
|
-
"use strict";
|
|
8
|
-
function useGapSizeNormalizer() {
|
|
9
|
-
const {
|
|
10
|
-
paddingXS,
|
|
11
|
-
paddingSM,
|
|
12
|
-
padding,
|
|
13
|
-
paddingMD,
|
|
14
|
-
paddingLG
|
|
15
|
-
} = useThemeTokens.useThemeTokens();
|
|
16
|
-
return react.useCallback((gap) => {
|
|
17
|
-
if (gap === "tiny") {
|
|
18
|
-
return paddingXS;
|
|
19
|
-
} else if (gap === "small") {
|
|
20
|
-
return paddingSM;
|
|
21
|
-
} else if (gap === "medium") {
|
|
22
|
-
return padding;
|
|
23
|
-
} else if (gap === "large") {
|
|
24
|
-
return paddingMD;
|
|
25
|
-
} else if (gap === "huge") {
|
|
26
|
-
return paddingLG;
|
|
27
|
-
}
|
|
28
|
-
return gap;
|
|
29
|
-
}, [
|
|
30
|
-
paddingXS,
|
|
31
|
-
paddingSM,
|
|
32
|
-
padding,
|
|
33
|
-
paddingMD,
|
|
34
|
-
paddingLG
|
|
35
|
-
]);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
exports.useGapSizeNormalizer = useGapSizeNormalizer;
|
|
2
|
+
"use strict";var u=require("react"),d=require("./use-theme-tokens.cjs");function t(){const{paddingXS:i,paddingSM:r,padding:a,paddingMD:n,paddingLG:s}=d.useThemeTokens();return u.useCallback(e=>e==="tiny"?i:e==="small"?r:e==="medium"?a:e==="large"?n:e==="huge"?s:e,[i,r,a,n,s])}exports.useGapSizeNormalizer=t;
|
|
@@ -1,12 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var useGapSizeNormalizer = require('./use-gap-size-normalizer.cjs');
|
|
5
|
-
|
|
6
|
-
"use strict";
|
|
7
|
-
function useNormalizedGapSize(gap) {
|
|
8
|
-
const normalize = useGapSizeNormalizer.useGapSizeNormalizer();
|
|
9
|
-
return normalize(gap);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
exports.useNormalizedGapSize = useNormalizedGapSize;
|
|
2
|
+
"use strict";var r=require("./use-gap-size-normalizer.cjs");function i(e){return r.useGapSizeNormalizer()(e)}exports.useNormalizedGapSize=i;
|
|
@@ -1,48 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var react = require('react');
|
|
5
|
-
|
|
6
|
-
"use strict";
|
|
7
|
-
function normalizeMenuItem(item) {
|
|
8
|
-
if (item.type === "item") {
|
|
9
|
-
return {
|
|
10
|
-
type: "item",
|
|
11
|
-
key: item.key,
|
|
12
|
-
label: item.label,
|
|
13
|
-
disabled: item.disabled,
|
|
14
|
-
icon: item.icon,
|
|
15
|
-
extra: item.extra
|
|
16
|
-
};
|
|
17
|
-
} else if (item.type === "submenu") {
|
|
18
|
-
return {
|
|
19
|
-
type: "submenu",
|
|
20
|
-
key: item.key,
|
|
21
|
-
label: item.label,
|
|
22
|
-
disabled: item.disabled,
|
|
23
|
-
icon: item.icon,
|
|
24
|
-
children: item.children.map(normalizeMenuItem)
|
|
25
|
-
};
|
|
26
|
-
} else if (item.type === "group") {
|
|
27
|
-
return {
|
|
28
|
-
type: "group",
|
|
29
|
-
key: item.key,
|
|
30
|
-
label: item.label,
|
|
31
|
-
children: item.children.map(normalizeMenuItem)
|
|
32
|
-
};
|
|
33
|
-
} else {
|
|
34
|
-
return {
|
|
35
|
-
type: "divider",
|
|
36
|
-
key: item.key
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
function useNormalizedMenuItems(items) {
|
|
41
|
-
return react.useMemo(
|
|
42
|
-
() => items.map(normalizeMenuItem),
|
|
43
|
-
[items]
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
exports.normalizeMenuItem = normalizeMenuItem;
|
|
48
|
-
exports.useNormalizedMenuItems = useNormalizedMenuItems;
|
|
2
|
+
"use strict";var l=require("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.useMemo(()=>e.map(i),[e])}exports.normalizeMenuItem=i,exports.useNormalizedMenuItems=t;
|
|
@@ -1,104 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var shared = require('@vef-framework/shared');
|
|
5
|
-
var react = require('react');
|
|
6
|
-
|
|
7
|
-
"use strict";
|
|
8
|
-
function useNormalizedDataOptions(options, {
|
|
9
|
-
labelKey = "label",
|
|
10
|
-
valueKey = "value",
|
|
11
|
-
childrenKey = "children",
|
|
12
|
-
descriptionKey = "description",
|
|
13
|
-
disabledKey = "disabled",
|
|
14
|
-
defaultToFirst = false
|
|
15
|
-
}, {
|
|
16
|
-
isTree = false,
|
|
17
|
-
isGrouped = false,
|
|
18
|
-
parsePinyin = false,
|
|
19
|
-
selectedOptionValues = []
|
|
20
|
-
} = {}) {
|
|
21
|
-
return react.useMemo(() => {
|
|
22
|
-
const selectedOptionValuesSet = new Set(selectedOptionValues);
|
|
23
|
-
const isGroupedOptions = !isTree && isGrouped;
|
|
24
|
-
const normalizeOption = (option, isTopLevel = false) => {
|
|
25
|
-
const label = option[labelKey];
|
|
26
|
-
if (shared.isNullish(label)) {
|
|
27
|
-
if (labelKey === "label") {
|
|
28
|
-
throw new shared.VefError(-10001, `The label value of the option is required.`);
|
|
29
|
-
}
|
|
30
|
-
throw new shared.VefError(-10001, `The label value pointed by '${labelKey}' of the option is required.`);
|
|
31
|
-
}
|
|
32
|
-
const value = option[valueKey];
|
|
33
|
-
if (shared.isNullish(value)) {
|
|
34
|
-
if (valueKey === "value") {
|
|
35
|
-
throw new shared.VefError(-10002, `The value of the option is required.`);
|
|
36
|
-
}
|
|
37
|
-
throw new shared.VefError(-10002, `The value pointed by '${valueKey}' of the option is required.`);
|
|
38
|
-
}
|
|
39
|
-
const children = option[childrenKey];
|
|
40
|
-
const description = option[descriptionKey];
|
|
41
|
-
const disabled = option[disabledKey] ?? false;
|
|
42
|
-
const normalizedOption = {
|
|
43
|
-
...option,
|
|
44
|
-
label,
|
|
45
|
-
value,
|
|
46
|
-
children,
|
|
47
|
-
description,
|
|
48
|
-
disabled
|
|
49
|
-
};
|
|
50
|
-
if (parsePinyin) {
|
|
51
|
-
const { labelText, descriptionText } = normalizedOption;
|
|
52
|
-
if (shared.isString(label) || shared.isString(labelText)) {
|
|
53
|
-
normalizedOption.labelPinyin = shared.parsePinyinFirstLetter(
|
|
54
|
-
shared.isString(label) ? label : labelText
|
|
55
|
-
).join("");
|
|
56
|
-
}
|
|
57
|
-
if (shared.isString(description) || shared.isString(descriptionText)) {
|
|
58
|
-
normalizedOption.descriptionPinyin = shared.parsePinyinFirstLetter(
|
|
59
|
-
shared.isString(description) ? description : descriptionText
|
|
60
|
-
).join("");
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
if ((!isTopLevel || !isGroupedOptions) && selectedOptionValuesSet.has(value)) {
|
|
64
|
-
selectedOptionValuesSet.delete(value);
|
|
65
|
-
}
|
|
66
|
-
if (shared.isArray(normalizedOption.children)) {
|
|
67
|
-
normalizedOption.children = normalizedOption.children.map((option2) => normalizeOption(option2));
|
|
68
|
-
}
|
|
69
|
-
return normalizedOption;
|
|
70
|
-
};
|
|
71
|
-
const normalizedOptions = options.map((option) => normalizeOption(option, true));
|
|
72
|
-
const missingOptionValues = Array.from(selectedOptionValuesSet);
|
|
73
|
-
if (!defaultToFirst) {
|
|
74
|
-
return [normalizedOptions, missingOptionValues];
|
|
75
|
-
}
|
|
76
|
-
if (isGroupedOptions) {
|
|
77
|
-
const firstNonEmptyGroupOption = normalizedOptions.find((item) => shared.isArray(item.children) && item.children.length > 0);
|
|
78
|
-
return [
|
|
79
|
-
normalizedOptions,
|
|
80
|
-
missingOptionValues,
|
|
81
|
-
firstNonEmptyGroupOption?.children?.[0]
|
|
82
|
-
];
|
|
83
|
-
}
|
|
84
|
-
return [
|
|
85
|
-
normalizedOptions,
|
|
86
|
-
missingOptionValues,
|
|
87
|
-
normalizedOptions[0]
|
|
88
|
-
];
|
|
89
|
-
}, [
|
|
90
|
-
childrenKey,
|
|
91
|
-
defaultToFirst,
|
|
92
|
-
descriptionKey,
|
|
93
|
-
disabledKey,
|
|
94
|
-
isGrouped,
|
|
95
|
-
isTree,
|
|
96
|
-
labelKey,
|
|
97
|
-
options,
|
|
98
|
-
parsePinyin,
|
|
99
|
-
// selectedOptionValues,
|
|
100
|
-
valueKey
|
|
101
|
-
]);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
exports.useNormalizedDataOptions = useNormalizedDataOptions;
|
|
2
|
+
"use strict";var e=require("@vef-framework/shared"),E=require("react");function F(p,{labelKey:s="label",valueKey:l="value",childrenKey:f="children",descriptionKey:y="description",disabledKey:b="disabled",defaultToFirst:v=!1},{isTree:w=!1,isGrouped:g=!1,parsePinyin:S=!1,selectedOptionValues:m=[]}={}){return E.useMemo(()=>{const c=new Set(m),T=!w&&g,q=(i,a=!1)=>{const t=i[s];if(e.isNullish(t))throw s==="label"?new e.VefError(-10001,"The label value of the option is required."):new e.VefError(-10001,`The label value pointed by '${s}' of the option is required.`);const o=i[l];if(e.isNullish(o))throw l==="value"?new e.VefError(-10002,"The value of the option is required."):new e.VefError(-10002,`The value pointed by '${l}' of the option is required.`);const K=i[f],d=i[y],V=i[b]??!1,r={...i,label:t,value:o,children:K,description:d,disabled:V};if(S){const{labelText:u,descriptionText:P}=r;(e.isString(t)||e.isString(u))&&(r.labelPinyin=e.parsePinyinFirstLetter(e.isString(t)?t:u).join("")),(e.isString(d)||e.isString(P))&&(r.descriptionPinyin=e.parsePinyinFirstLetter(e.isString(d)?d:P).join(""))}return(!a||!T)&&c.has(o)&&c.delete(o),e.isArray(r.children)&&(r.children=r.children.map(u=>q(u))),r},n=p.map(i=>q(i,!0)),h=Array.from(c);if(!v)return[n,h];if(T){const i=n.find(a=>e.isArray(a.children)&&a.children.length>0);return[n,h,i?.children?.[0]]}return[n,h,n[0]]},[f,v,y,b,g,w,s,p,S,l])}exports.useNormalizedDataOptions=F;
|
|
@@ -1,20 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var shared = require('@vef-framework/shared');
|
|
5
|
-
var react = require('react');
|
|
6
|
-
|
|
7
|
-
"use strict";
|
|
8
|
-
function useOptionFilter(filterable, filterFromRemote) {
|
|
9
|
-
return react.useMemo(() => {
|
|
10
|
-
if (!filterable) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
if (filterFromRemote) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
return (filterValue, option) => (shared.isString(option.label) && option.label.includes(filterValue) || shared.isString(option.labelText) && option.labelText.includes(filterValue) || option.labelPinyin?.includes(filterValue) || option.value.includes(filterValue) || shared.isString(option.description) && option.description.includes(filterValue) || shared.isString(option.descriptionText) && option.descriptionText.includes(filterValue) || option.descriptionPinyin?.includes(filterValue)) ?? false;
|
|
17
|
-
}, [filterable, filterFromRemote]);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
exports.useOptionFilter = useOptionFilter;
|
|
2
|
+
"use strict";var t=require("@vef-framework/shared"),l=require("react");function n(r,s){return l.useMemo(()=>{if(r)return s?!1:(e,i)=>(t.isString(i.label)&&i.label.includes(e)||t.isString(i.labelText)&&i.labelText.includes(e)||i.labelPinyin?.includes(e)||i.value.includes(e)||t.isString(i.description)&&i.description.includes(e)||t.isString(i.descriptionText)&&i.descriptionText.includes(e)||i.descriptionPinyin?.includes(e))??!1},[r,s])}exports.useOptionFilter=n;
|
|
@@ -1,39 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var shared = require('@vef-framework/shared');
|
|
5
|
-
var react = require('react');
|
|
6
|
-
|
|
7
|
-
"use strict";
|
|
8
|
-
function useRemoteFilter(enabled, apiParams, keywordKey = "keyword") {
|
|
9
|
-
const [filterKeyword, setFilterKeyword] = react.useState();
|
|
10
|
-
const mergedApiParams = react.useMemo(() => {
|
|
11
|
-
if (!enabled) {
|
|
12
|
-
return apiParams;
|
|
13
|
-
}
|
|
14
|
-
const params = {
|
|
15
|
-
...apiParams
|
|
16
|
-
};
|
|
17
|
-
const keywordToUse = shared.trim(filterKeyword);
|
|
18
|
-
if (keywordToUse) {
|
|
19
|
-
params[keywordKey] = keywordToUse;
|
|
20
|
-
}
|
|
21
|
-
return params;
|
|
22
|
-
}, [
|
|
23
|
-
enabled,
|
|
24
|
-
apiParams,
|
|
25
|
-
filterKeyword,
|
|
26
|
-
keywordKey
|
|
27
|
-
]);
|
|
28
|
-
const handleInputKeyword = react.useMemo(() => {
|
|
29
|
-
if (!enabled) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
return shared.debounce({ delay: 500 }, (keyword) => {
|
|
33
|
-
setFilterKeyword(keyword);
|
|
34
|
-
});
|
|
35
|
-
}, [enabled]);
|
|
36
|
-
return [mergedApiParams, handleInputKeyword];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
exports.useRemoteFilter = useRemoteFilter;
|
|
2
|
+
"use strict";var o=require("@vef-framework/shared"),u=require("react");function d(e,t,s="keyword"){const[i,c]=u.useState(),a=u.useMemo(()=>{if(!e)return t;const r={...t},n=o.trim(i);return n&&(r[s]=n),r},[e,t,i,s]),m=u.useMemo(()=>{if(e)return o.debounce({delay:500},r=>{c(r)})},[e]);return[a,m]}exports.useRemoteFilter=d;
|
|
@@ -1,13 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var react = require('react');
|
|
5
|
-
var useShallowMemo = require('./use-shallow-memo.cjs');
|
|
6
|
-
|
|
7
|
-
"use strict";
|
|
8
|
-
function useShallowCallback(callback, dependencies) {
|
|
9
|
-
const memoizedDependencies = useShallowMemo.useShallowMemo(() => dependencies, dependencies);
|
|
10
|
-
return react.useCallback(callback, memoizedDependencies);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
exports.useShallowCallback = useShallowCallback;
|
|
2
|
+
"use strict";var r=require("react"),u=require("./use-shallow-memo.cjs");function s(l,e){const a=u.useShallowMemo(()=>e,e);return r.useCallback(l,a)}exports.useShallowCallback=s;
|
package/cjs/use-shallow-memo.cjs
CHANGED
|
@@ -1,21 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var shared = require('@vef-framework/shared');
|
|
5
|
-
var react = require('react');
|
|
6
|
-
|
|
7
|
-
"use strict";
|
|
8
|
-
function useShallowMemo(factory, dependencies) {
|
|
9
|
-
const lastDependencies = react.useRef();
|
|
10
|
-
const signal = react.useRef(0);
|
|
11
|
-
if (lastDependencies.current === void 0 || !isEqual(dependencies, lastDependencies.current)) {
|
|
12
|
-
signal.current += 1;
|
|
13
|
-
}
|
|
14
|
-
lastDependencies.current = dependencies;
|
|
15
|
-
return react.useMemo(factory, [signal.current]);
|
|
16
|
-
}
|
|
17
|
-
function isEqual(one, another) {
|
|
18
|
-
return one.length === another.length && one.every((value, index) => shared.isShallowEqual(value, another[index]));
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
exports.useShallowMemo = useShallowMemo;
|
|
2
|
+
"use strict";var s=require("@vef-framework/shared"),n=require("react");function c(u,e){const r=n.useRef(),t=n.useRef(0);return(r.current===void 0||!o(e,r.current))&&(t.current+=1),r.current=e,n.useMemo(u,[t.current])}function o(u,e){return u.length===e.length&&u.every((r,t)=>s.isShallowEqual(r,e[t]))}exports.useShallowMemo=c;
|
|
@@ -1,16 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var shared = require('@vef-framework/shared');
|
|
5
|
-
var react = require('react');
|
|
6
|
-
|
|
7
|
-
"use strict";
|
|
8
|
-
function useShallowSelector(selector) {
|
|
9
|
-
const prevSelectedState = react.useRef();
|
|
10
|
-
return (state) => {
|
|
11
|
-
const nextSelectedState = selector(state);
|
|
12
|
-
return shared.isShallowEqual(prevSelectedState.current, nextSelectedState) ? prevSelectedState.current : prevSelectedState.current = nextSelectedState;
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
exports.useShallowSelector = useShallowSelector;
|
|
2
|
+
"use strict";var c=require("@vef-framework/shared"),s=require("react");function l(t){const r=s.useRef();return u=>{const e=t(u);return c.isShallowEqual(r.current,e)?r.current:r.current=e}}exports.useShallowSelector=l;
|
package/cjs/use-singleton.cjs
CHANGED
|
@@ -1,16 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var shared = require('@vef-framework/shared');
|
|
5
|
-
var react = require('react');
|
|
6
|
-
|
|
7
|
-
"use strict";
|
|
8
|
-
function useSingleton(factory) {
|
|
9
|
-
const singleton = react.useRef();
|
|
10
|
-
if (shared.isNullish(singleton.current)) {
|
|
11
|
-
singleton.current = factory();
|
|
12
|
-
}
|
|
13
|
-
return singleton.current;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
exports.useSingleton = useSingleton;
|
|
2
|
+
"use strict";var t=require("@vef-framework/shared"),u=require("react");function n(r){const e=u.useRef();return t.isNullish(e.current)&&(e.current=r()),e.current}exports.useSingleton=n;
|
package/cjs/use-theme-tokens.cjs
CHANGED
|
@@ -1,13 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var antd = require('antd');
|
|
5
|
-
|
|
6
|
-
"use strict";
|
|
7
|
-
const { useToken } = antd.theme;
|
|
8
|
-
function useThemeTokens() {
|
|
9
|
-
const { token } = useToken();
|
|
10
|
-
return token;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
exports.useThemeTokens = useThemeTokens;
|
|
2
|
+
"use strict";var n=require("antd");const{useToken:s}=n.theme;function t(){const{token:e}=s();return e}exports.useThemeTokens=t;
|
|
@@ -1,34 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var shared = require('@vef-framework/shared');
|
|
5
|
-
var react = require('react');
|
|
6
|
-
|
|
7
|
-
"use strict";
|
|
8
|
-
function useTransientStore({ subscribe, getState }, {
|
|
9
|
-
selector = (state) => state,
|
|
10
|
-
equalityFn = shared.isShallowEqual,
|
|
11
|
-
listener
|
|
12
|
-
} = {}) {
|
|
13
|
-
const stateRef = react.useRef();
|
|
14
|
-
if (!stateRef.current) {
|
|
15
|
-
stateRef.current = selector(getState());
|
|
16
|
-
}
|
|
17
|
-
react.useEffect(
|
|
18
|
-
() => subscribe(
|
|
19
|
-
selector,
|
|
20
|
-
(state, prevState) => {
|
|
21
|
-
stateRef.current = state;
|
|
22
|
-
listener?.(state, prevState);
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
fireImmediately: false,
|
|
26
|
-
equalityFn
|
|
27
|
-
}
|
|
28
|
-
),
|
|
29
|
-
[equalityFn, listener, selector, subscribe]
|
|
30
|
-
);
|
|
31
|
-
return stateRef;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
exports.useTransientStore = useTransientStore;
|
|
2
|
+
"use strict";var l=require("@vef-framework/shared"),n=require("react");function f({subscribe:t,getState:a},{selector:r=e=>e,equalityFn:s=l.isShallowEqual,listener:u}={}){const e=n.useRef();return e.current||(e.current=r(a())),n.useEffect(()=>t(r,(i,c)=>{e.current=i,u?.(i,c)},{fireImmediately:!1,equalityFn:s}),[s,u,r,t]),e}exports.useTransientStore=f;
|
package/cjs/use-window-size.cjs
CHANGED
|
@@ -1,21 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var ahooks = require('ahooks');
|
|
5
|
-
|
|
6
|
-
"use strict";
|
|
7
|
-
function useWindowSize() {
|
|
8
|
-
const [size, setSize] = ahooks.useRafState(() => ({
|
|
9
|
-
width: window.innerWidth,
|
|
10
|
-
height: window.innerHeight
|
|
11
|
-
}));
|
|
12
|
-
ahooks.useEventListener("resize", () => {
|
|
13
|
-
setSize({
|
|
14
|
-
width: window.innerWidth,
|
|
15
|
-
height: window.innerHeight
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
return size;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
exports.useWindowSize = useWindowSize;
|
|
2
|
+
"use strict";var i=require("ahooks");function t(){const[e,n]=i.useRafState(()=>({width:window.innerWidth,height:window.innerHeight}));return i.useEventListener("resize",()=>{n({width:window.innerWidth,height:window.innerHeight})}),e}exports.useWindowSize=t;
|
package/esm/index.js
CHANGED
|
@@ -1,29 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import
|
|
3
|
-
export { useAuthorizedItems } from './use-authorized-items.js';
|
|
4
|
-
export { useColorTokens, useDefaultColorTokens, useSemanticColorTokens } from './use-color-tokens.js';
|
|
5
|
-
export { useComputedActionButtons } from './use-computed-action-buttons.js';
|
|
6
|
-
export { useComputedOptions } from './use-computed-options.js';
|
|
7
|
-
export { DisabledContextProvider, useContextDisabled } from './use-context-disabled.js';
|
|
8
|
-
export { useDataQuery } from './use-data-query.js';
|
|
9
|
-
export { useDeepCallback } from './use-deep-callback.js';
|
|
10
|
-
export { useDeepMemo } from './use-deep-memo.js';
|
|
11
|
-
export { useDeepSelector } from './use-deep-selector.js';
|
|
12
|
-
export { useFallbackOptions } from './use-fallback-options.js';
|
|
13
|
-
export { useGapSizeNormalizer } from './use-gap-size-normalizer.js';
|
|
14
|
-
export { useNormalizedGapSize } from './use-normalized-gap-size.js';
|
|
15
|
-
export { normalizeMenuItem, useNormalizedMenuItems } from './use-normalized-menu-items.js';
|
|
16
|
-
export { useNormalizedDataOptions } from './use-normalized-options.js';
|
|
17
|
-
export { useOptionFilter } from './use-option-filter.js';
|
|
18
|
-
export { useRemoteFilter } from './use-remote-filter.js';
|
|
19
|
-
export { useShallowCallback } from './use-shallow-callback.js';
|
|
20
|
-
export { useShallowMemo } from './use-shallow-memo.js';
|
|
21
|
-
export { useShallowSelector } from './use-shallow-selector.js';
|
|
22
|
-
export { useSingleton } from './use-singleton.js';
|
|
23
|
-
export { useThemeTokens } from './use-theme-tokens.js';
|
|
24
|
-
export { useTransientStore } from './use-transient-store.js';
|
|
25
|
-
export { useWindowSize } from './use-window-size.js';
|
|
26
|
-
export { useClickAway, useMeasure } from '@uidotdev/usehooks';
|
|
27
|
-
export { useDeepCompareEffect as useDeepEffect, useDeepCompareLayoutEffect as useDeepLayoutEffect, useSize as useElementSize, useEventListener, useKeyPress, useMount, useUnmount, useUpdateEffect, useUpdateLayoutEffect, useUpdate as useUpdater } from 'ahooks';
|
|
28
|
-
|
|
29
|
-
"use strict";
|
|
2
|
+
import"./lib.js";import{useAuthorizedItems as t}from"./use-authorized-items.js";import{useColorTokens as u,useDefaultColorTokens as p,useSemanticColorTokens as m}from"./use-color-tokens.js";import{useComputedActionButtons as f}from"./use-computed-action-buttons.js";import{useComputedOptions as i}from"./use-computed-options.js";import{DisabledContextProvider as x,useContextDisabled as c}from"./use-context-disabled.js";import{useDataQuery as S}from"./use-data-query.js";import{useDeepCallback as D}from"./use-deep-callback.js";import{useDeepMemo as k}from"./use-deep-memo.js";import{useDeepSelector as y}from"./use-deep-selector.js";import{useFallbackOptions as T}from"./use-fallback-options.js";import{useGapSizeNormalizer as h}from"./use-gap-size-normalizer.js";import{useNormalizedGapSize as U}from"./use-normalized-gap-size.js";import{normalizeMenuItem as N,useNormalizedMenuItems as O}from"./use-normalized-menu-items.js";import{useNormalizedDataOptions as F}from"./use-normalized-options.js";import{useOptionFilter as v}from"./use-option-filter.js";import{useRemoteFilter as P}from"./use-remote-filter.js";import{useShallowCallback as B}from"./use-shallow-callback.js";import{useShallowMemo as Q}from"./use-shallow-memo.js";import{useShallowSelector as W}from"./use-shallow-selector.js";import{useSingleton as q}from"./use-singleton.js";import{useThemeTokens as J}from"./use-theme-tokens.js";import{useTransientStore as X}from"./use-transient-store.js";import{useWindowSize as Z}from"./use-window-size.js";import{useClickAway as $,useMeasure as ee}from"@uidotdev/usehooks";import{useDeepCompareEffect as re,useDeepCompareLayoutEffect as te,useSize as se,useEventListener as ue,useKeyPress as pe,useMount as me,useUnmount as ae,useUpdateEffect as fe,useUpdateLayoutEffect as le,useUpdate as ie}from"ahooks";export{x as DisabledContextProvider,N as normalizeMenuItem,t as useAuthorizedItems,$ as useClickAway,u as useColorTokens,f as useComputedActionButtons,i as useComputedOptions,c as useContextDisabled,S as useDataQuery,D as useDeepCallback,re as useDeepEffect,te as useDeepLayoutEffect,k as useDeepMemo,y as useDeepSelector,p as useDefaultColorTokens,se as useElementSize,ue as useEventListener,T as useFallbackOptions,h as useGapSizeNormalizer,pe as useKeyPress,ee as useMeasure,me as useMount,F as useNormalizedDataOptions,U as useNormalizedGapSize,O as useNormalizedMenuItems,v as useOptionFilter,P as useRemoteFilter,m as useSemanticColorTokens,B as useShallowCallback,Q as useShallowMemo,W as useShallowSelector,q as useSingleton,J as useThemeTokens,X as useTransientStore,ae as useUnmount,fe as useUpdateEffect,le as useUpdateLayoutEffect,ie as useUpdater,Z as useWindowSize};
|
package/esm/lib.js
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
export { useDeepCompareEffect as useDeepEffect, useDeepCompareLayoutEffect as useDeepLayoutEffect, useSize as useElementSize, useEventListener, useKeyPress, useMount, useUnmount, useUpdateEffect, useUpdateLayoutEffect, useUpdate as useUpdater } from 'ahooks';
|
|
4
|
-
|
|
5
|
-
"use strict";
|
|
2
|
+
import{useClickAway as u,useMeasure as t}from"@uidotdev/usehooks";import{useDeepCompareEffect as f,useDeepCompareLayoutEffect as p,useSize as o,useEventListener as r,useKeyPress as c,useMount as E,useUnmount as m,useUpdateEffect as n,useUpdateLayoutEffect as i,useUpdate as y}from"ahooks";export{u as useClickAway,f as useDeepEffect,p as useDeepLayoutEffect,o as useElementSize,r as useEventListener,c as useKeyPress,t as useMeasure,E as useMount,m as useUnmount,n as useUpdateEffect,i as useUpdateLayoutEffect,y as useUpdater};
|
|
@@ -1,24 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import
|
|
3
|
-
import { useMemo } from 'react';
|
|
4
|
-
|
|
5
|
-
"use strict";
|
|
6
|
-
function useAuthorizedItems(items) {
|
|
7
|
-
const { checkPermission } = useAuthContext();
|
|
8
|
-
return useMemo(
|
|
9
|
-
() => items?.filter((item) => {
|
|
10
|
-
const { permissions } = item;
|
|
11
|
-
if (!permissions) {
|
|
12
|
-
return true;
|
|
13
|
-
}
|
|
14
|
-
const checkMode = item.checkMode ?? "any";
|
|
15
|
-
if (checkMode === "any") {
|
|
16
|
-
return permissions.some((permission) => checkPermission(permission));
|
|
17
|
-
}
|
|
18
|
-
return permissions.every((permission) => checkPermission(permission));
|
|
19
|
-
}),
|
|
20
|
-
[items, checkPermission]
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export { useAuthorizedItems };
|
|
2
|
+
import{useAuthContext as i}from"@vef-framework/core";import{useMemo as n}from"react";function m(o){const{checkPermission:e}=i();return n(()=>o?.filter(s=>{const{permissions:r}=s;return r?(s.checkMode??"any")==="any"?r.some(t=>e(t)):r.every(t=>e(t)):!0}),[o,e])}export{m as useAuthorizedItems};
|
package/esm/use-color-tokens.js
CHANGED
|
@@ -1,30 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import
|
|
3
|
-
import { useMemo } from 'react';
|
|
4
|
-
import { useThemeTokens } from './use-theme-tokens.js';
|
|
5
|
-
|
|
6
|
-
"use strict";
|
|
7
|
-
function useDefaultColorTokens() {
|
|
8
|
-
const tokens = useThemeTokens();
|
|
9
|
-
return useMemo(() => defaultColorTypes.reduce(
|
|
10
|
-
(map, color) => {
|
|
11
|
-
map.set(color, tokens[color]);
|
|
12
|
-
return map;
|
|
13
|
-
},
|
|
14
|
-
/* @__PURE__ */ new Map()
|
|
15
|
-
), [tokens]);
|
|
16
|
-
}
|
|
17
|
-
function useSemanticColorTokens() {
|
|
18
|
-
const tokens = useThemeTokens();
|
|
19
|
-
return useMemo(() => semanticColorTypes.reduce((map, color) => {
|
|
20
|
-
map.set(color, tokens[`color${capitalize(color)}`]);
|
|
21
|
-
return map;
|
|
22
|
-
}, /* @__PURE__ */ new Map()), [tokens]);
|
|
23
|
-
}
|
|
24
|
-
function useColorTokens() {
|
|
25
|
-
const defaultColorTokens = useDefaultColorTokens();
|
|
26
|
-
const semanticColorTokens = useSemanticColorTokens();
|
|
27
|
-
return useMemo(() => new Map([...defaultColorTokens, ...semanticColorTokens]), [defaultColorTokens, semanticColorTokens]);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export { useColorTokens, useDefaultColorTokens, useSemanticColorTokens };
|
|
2
|
+
import{defaultColorTypes as c,semanticColorTypes as i,capitalize as m}from"@vef-framework/shared";import{useMemo as n}from"react";import{useThemeTokens as r}from"./use-theme-tokens.js";function s(){const e=r();return n(()=>c.reduce((o,t)=>(o.set(t,e[t]),o),new Map),[e])}function u(){const e=r();return n(()=>i.reduce((o,t)=>(o.set(t,e[`color${m(t)}`]),o),new Map),[e])}function p(){const e=s(),o=u();return n(()=>new Map([...e,...o]),[e,o])}export{p as useColorTokens,s as useDefaultColorTokens,u as useSemanticColorTokens};
|
|
@@ -1,43 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import
|
|
3
|
-
import { useMemo } from 'react';
|
|
4
|
-
|
|
5
|
-
"use strict";
|
|
6
|
-
function useComputedActionButtons(buttons, context) {
|
|
7
|
-
return useMemo(() => buttons.filter((button) => {
|
|
8
|
-
const { show } = button;
|
|
9
|
-
if (isFunction(show)) {
|
|
10
|
-
return show(context);
|
|
11
|
-
}
|
|
12
|
-
return show ?? true;
|
|
13
|
-
}).map((button) => {
|
|
14
|
-
const {
|
|
15
|
-
disabled,
|
|
16
|
-
requireConfirmation,
|
|
17
|
-
confirmationMode,
|
|
18
|
-
confirmationTitle,
|
|
19
|
-
confirmationContent,
|
|
20
|
-
...rest
|
|
21
|
-
} = button;
|
|
22
|
-
const computedButton = {
|
|
23
|
-
...rest,
|
|
24
|
-
disabled: isFunction(disabled) ? disabled(context) : disabled ?? false,
|
|
25
|
-
requireConfirmation: isFunction(requireConfirmation) ? requireConfirmation(context) : requireConfirmation ?? false,
|
|
26
|
-
confirmationMode: isFunction(confirmationMode) ? confirmationMode(context) : confirmationMode ?? "simple",
|
|
27
|
-
confirmationTitle: isFunction(confirmationTitle) ? confirmationTitle(context) : confirmationTitle ?? defaultMessageTitle,
|
|
28
|
-
confirmationContent: isFunction(confirmationContent) ? confirmationContent(context) : confirmationContent ?? `确定要${rest.label}吗?`
|
|
29
|
-
};
|
|
30
|
-
if (computedButton.requireConfirmation && !computedButton.confirmationMode) {
|
|
31
|
-
computedButton.confirmationMode = "simple";
|
|
32
|
-
}
|
|
33
|
-
if (computedButton.requireConfirmation && !computedButton.confirmationTitle) {
|
|
34
|
-
computedButton.confirmationTitle = defaultMessageTitle;
|
|
35
|
-
}
|
|
36
|
-
if (computedButton.requireConfirmation && !computedButton.confirmationContent) {
|
|
37
|
-
computedButton.confirmationContent = `确定要${computedButton.label}吗?`;
|
|
38
|
-
}
|
|
39
|
-
return computedButton;
|
|
40
|
-
}), [buttons, context]);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export { useComputedActionButtons };
|
|
2
|
+
import{isFunction as t,defaultMessageTitle as l}from"@vef-framework/shared";import{useMemo as s}from"react";function d(c,n){return s(()=>c.filter(e=>{const{show:i}=e;return t(i)?i(n):i??!0}).map(e=>{const{disabled:i,requireConfirmation:r,confirmationMode:m,confirmationTitle:a,confirmationContent:f,...u}=e,o={...u,disabled:t(i)?i(n):i??!1,requireConfirmation:t(r)?r(n):r??!1,confirmationMode:t(m)?m(n):m??"simple",confirmationTitle:t(a)?a(n):a??l,confirmationContent:t(f)?f(n):f??`确定要${u.label}吗?`};return o.requireConfirmation&&!o.confirmationMode&&(o.confirmationMode="simple"),o.requireConfirmation&&!o.confirmationTitle&&(o.confirmationTitle=l),o.requireConfirmation&&!o.confirmationContent&&(o.confirmationContent=`确定要${o.label}吗?`),o}),[c,n])}export{d as useComputedActionButtons};
|
|
@@ -1,67 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import {
|
|
3
|
-
import { useFallbackOptions } from './use-fallback-options.js';
|
|
4
|
-
import { useNormalizedDataOptions } from './use-normalized-options.js';
|
|
5
|
-
import { useRemoteFilter } from './use-remote-filter.js';
|
|
6
|
-
|
|
7
|
-
"use strict";
|
|
8
|
-
function useComputedOptions({
|
|
9
|
-
labelKey,
|
|
10
|
-
valueKey,
|
|
11
|
-
descriptionKey,
|
|
12
|
-
childrenKey,
|
|
13
|
-
disabledKey,
|
|
14
|
-
defaultToFirst,
|
|
15
|
-
filterable = false,
|
|
16
|
-
filterFromRemote = false,
|
|
17
|
-
keywordKey = "keyword",
|
|
18
|
-
valuesKey = "ids",
|
|
19
|
-
fallbackOptionsApi,
|
|
20
|
-
fallbackOptionsApiParams,
|
|
21
|
-
resolveFallbackOptions,
|
|
22
|
-
isGrouped = false,
|
|
23
|
-
selectedOptionValues,
|
|
24
|
-
apiParams,
|
|
25
|
-
...queryConfig
|
|
26
|
-
}) {
|
|
27
|
-
const [mergedApiParams, onFilterKeywordChange] = useRemoteFilter(filterable && filterFromRemote, apiParams, keywordKey);
|
|
28
|
-
const { data: options, isLoading } = useDataQuery({
|
|
29
|
-
apiParams: mergedApiParams,
|
|
30
|
-
...queryConfig
|
|
31
|
-
});
|
|
32
|
-
const [normalizedOptions, missingOptionValues, defaultOption] = useNormalizedDataOptions(
|
|
33
|
-
options ?? [],
|
|
34
|
-
{
|
|
35
|
-
labelKey,
|
|
36
|
-
valueKey,
|
|
37
|
-
descriptionKey,
|
|
38
|
-
childrenKey,
|
|
39
|
-
disabledKey,
|
|
40
|
-
defaultToFirst
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
isGrouped,
|
|
44
|
-
parsePinyin: filterable && !filterFromRemote,
|
|
45
|
-
selectedOptionValues
|
|
46
|
-
}
|
|
47
|
-
);
|
|
48
|
-
const { data: fallbackOptions, isLoading: isFallbackOptionsLoading } = useFallbackOptions(
|
|
49
|
-
missingOptionValues,
|
|
50
|
-
{
|
|
51
|
-
fallbackOptionsApi: fallbackOptionsApi ?? queryConfig.api,
|
|
52
|
-
fallbackOptionsApiParams,
|
|
53
|
-
valuesKey,
|
|
54
|
-
resolveFallbackOptions
|
|
55
|
-
}
|
|
56
|
-
);
|
|
57
|
-
return {
|
|
58
|
-
onFilterKeywordChange,
|
|
59
|
-
isLoading,
|
|
60
|
-
normalizedOptions,
|
|
61
|
-
defaultOption,
|
|
62
|
-
fallbackOptions,
|
|
63
|
-
isFallbackOptionsLoading
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export { useComputedOptions };
|
|
2
|
+
import{useDataQuery as h}from"./use-data-query.js";import{useFallbackOptions as w}from"./use-fallback-options.js";import{useNormalizedDataOptions as T}from"./use-normalized-options.js";import{useRemoteFilter as V}from"./use-remote-filter.js";function x({labelKey:o,valueKey:l,descriptionKey:s,childrenKey:t,disabledKey:r,defaultToFirst:p,filterable:e=!1,filterFromRemote:a=!1,keywordKey:n="keyword",valuesKey:d="ids",fallbackOptionsApi:u,fallbackOptionsApiParams:c,resolveFallbackOptions:m,isGrouped:y=!1,selectedOptionValues:f,apiParams:b,...i}){const[O,K]=V(e&&a,b,n),{data:k,isLoading:F}=h({apiParams:O,...i}),[g,v,P]=T(k??[],{labelKey:o,valueKey:l,descriptionKey:s,childrenKey:t,disabledKey:r,defaultToFirst:p},{isGrouped:y,parsePinyin:e&&!a,selectedOptionValues:f}),{data:A,isLoading:L}=w(v,{fallbackOptionsApi:u??i.api,fallbackOptionsApiParams:c,valuesKey:d,resolveFallbackOptions:m});return{onFilterKeywordChange:K,isLoading:F,normalizedOptions:g,defaultOption:P,fallbackOptions:A,isFallbackOptionsLoading:L}}export{x as useComputedOptions};
|
|
@@ -1,11 +1,2 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
"use strict";
|
|
5
|
-
const DisabledContext = createContext(false);
|
|
6
|
-
function useContextDisabled() {
|
|
7
|
-
return useContext(DisabledContext);
|
|
8
|
-
}
|
|
9
|
-
const DisabledContextProvider = DisabledContext.Provider;
|
|
10
|
-
|
|
11
|
-
export { DisabledContextProvider, useContextDisabled };
|
|
2
|
+
import{createContext as e,useContext as o}from"react";const t=e(!1);function r(){return o(t)}const n=t.Provider;export{n as DisabledContextProvider,r as useContextDisabled};
|