@vef-framework/hooks 1.0.100 → 1.0.101
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/es/index.js +27 -2
- package/es/lib.js +3 -2
- package/es/use-authorized-items.js +23 -2
- package/es/use-color-tokens.js +29 -2
- package/es/use-computed-action-buttons.js +42 -2
- package/es/use-computed-options.js +66 -2
- package/es/use-context-disabled.js +10 -2
- package/es/use-data-query.js +107 -2
- package/es/use-deep-callback.js +10 -2
- package/es/use-deep-memo.js +18 -2
- package/es/use-deep-selector.js +13 -2
- package/es/use-fallback-options.js +102 -2
- package/es/use-gap-size-normalizer.js +35 -2
- package/es/use-normalized-gap-size.js +9 -2
- package/es/use-normalized-menu-items.js +44 -2
- package/es/use-normalized-options.js +101 -2
- package/es/use-option-filter.js +17 -2
- package/es/use-remote-filter.js +36 -2
- package/es/use-shallow-callback.js +10 -2
- package/es/use-shallow-memo.js +18 -2
- package/es/use-shallow-selector.js +13 -2
- package/es/use-singleton.js +13 -2
- package/es/use-theme-tokens.js +10 -2
- package/es/use-transient-store.js +31 -2
- package/es/use-window-size.js +18 -2
- package/lib/index.cjs +109 -2
- package/lib/lib.cjs +58 -2
- package/lib/use-authorized-items.cjs +27 -2
- package/lib/use-color-tokens.cjs +35 -2
- package/lib/use-computed-action-buttons.cjs +46 -2
- package/lib/use-computed-options.cjs +70 -2
- package/lib/use-context-disabled.cjs +15 -2
- package/lib/use-data-query.cjs +111 -2
- package/lib/use-deep-callback.cjs +14 -2
- package/lib/use-deep-memo.cjs +22 -2
- package/lib/use-deep-selector.cjs +17 -2
- package/lib/use-fallback-options.cjs +106 -2
- package/lib/use-gap-size-normalizer.cjs +39 -2
- package/lib/use-normalized-gap-size.cjs +13 -2
- package/lib/use-normalized-menu-items.cjs +49 -2
- package/lib/use-normalized-options.cjs +105 -2
- package/lib/use-option-filter.cjs +21 -2
- package/lib/use-remote-filter.cjs +40 -2
- package/lib/use-shallow-callback.cjs +14 -2
- package/lib/use-shallow-memo.cjs +22 -2
- package/lib/use-shallow-selector.cjs +17 -2
- package/lib/use-singleton.cjs +17 -2
- package/lib/use-theme-tokens.cjs +14 -2
- package/lib/use-transient-store.cjs +35 -2
- package/lib/use-window-size.cjs +22 -2
- package/package.json +3 -3
|
@@ -1,3 +1,71 @@
|
|
|
1
|
-
/*! VefFramework version: 1.0.
|
|
2
|
-
|
|
1
|
+
/*! VefFramework version: 1.0.101, build time: 2025-03-07T14:07:14.523Z, made by Venus. */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const useDataQuery = require('./use-data-query.cjs');
|
|
7
|
+
const useFallbackOptions = require('./use-fallback-options.cjs');
|
|
8
|
+
const useNormalizedOptions = require('./use-normalized-options.cjs');
|
|
9
|
+
const useRemoteFilter = require('./use-remote-filter.cjs');
|
|
10
|
+
|
|
11
|
+
function useComputedOptions({
|
|
12
|
+
labelKey,
|
|
13
|
+
valueKey,
|
|
14
|
+
descriptionKey,
|
|
15
|
+
childrenKey,
|
|
16
|
+
disabledKey,
|
|
17
|
+
defaultToFirst,
|
|
18
|
+
filterable = false,
|
|
19
|
+
filterFromRemote = false,
|
|
20
|
+
keywordKey = "keyword",
|
|
21
|
+
valuesKey = "ids",
|
|
22
|
+
fallbackOptionsApi,
|
|
23
|
+
fallbackOptionsApiParams,
|
|
24
|
+
resolveFallbackOptions,
|
|
25
|
+
isGrouped = false,
|
|
26
|
+
selectedOptionValues,
|
|
27
|
+
apiParams,
|
|
28
|
+
...queryConfig
|
|
29
|
+
}) {
|
|
30
|
+
const [mergedApiParams, onFilterKeywordChange] = useRemoteFilter.useRemoteFilter(filterable && filterFromRemote, apiParams, keywordKey);
|
|
31
|
+
const { data: options, isLoading } = useDataQuery.useDataQuery({
|
|
32
|
+
apiParams: mergedApiParams,
|
|
33
|
+
...queryConfig
|
|
34
|
+
});
|
|
35
|
+
const [normalizedOptions, missingOptionValues, defaultOption] = useNormalizedOptions.useNormalizedDataOptions(
|
|
36
|
+
options ?? [],
|
|
37
|
+
{
|
|
38
|
+
labelKey,
|
|
39
|
+
valueKey,
|
|
40
|
+
descriptionKey,
|
|
41
|
+
childrenKey,
|
|
42
|
+
disabledKey,
|
|
43
|
+
defaultToFirst
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
isGrouped,
|
|
47
|
+
parsePinyin: filterable && !filterFromRemote,
|
|
48
|
+
selectedOptionValues
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
const { data: fallbackOptions, isLoading: isFallbackOptionsLoading } = useFallbackOptions.useFallbackOptions(
|
|
52
|
+
missingOptionValues,
|
|
53
|
+
{
|
|
54
|
+
fallbackOptionsApi: fallbackOptionsApi ?? queryConfig.api,
|
|
55
|
+
fallbackOptionsApiParams,
|
|
56
|
+
valuesKey,
|
|
57
|
+
resolveFallbackOptions
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
return {
|
|
61
|
+
onFilterKeywordChange,
|
|
62
|
+
isLoading,
|
|
63
|
+
normalizedOptions,
|
|
64
|
+
defaultOption,
|
|
65
|
+
fallbackOptions,
|
|
66
|
+
isFallbackOptionsLoading
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
exports.useComputedOptions = useComputedOptions;
|
|
3
71
|
/*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
|
|
@@ -1,3 +1,16 @@
|
|
|
1
|
-
/*! VefFramework version: 1.0.
|
|
2
|
-
|
|
1
|
+
/*! VefFramework version: 1.0.101, build time: 2025-03-07T14:07:14.523Z, made by Venus. */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const react = require('react');
|
|
7
|
+
|
|
8
|
+
const DisabledContext = react.createContext(false);
|
|
9
|
+
function useContextDisabled() {
|
|
10
|
+
return react.useContext(DisabledContext);
|
|
11
|
+
}
|
|
12
|
+
const DisabledContextProvider = DisabledContext.Provider;
|
|
13
|
+
|
|
14
|
+
exports.DisabledContextProvider = DisabledContextProvider;
|
|
15
|
+
exports.useContextDisabled = useContextDisabled;
|
|
3
16
|
/*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
|
package/lib/use-data-query.cjs
CHANGED
|
@@ -1,3 +1,112 @@
|
|
|
1
|
-
/*! VefFramework version: 1.0.
|
|
2
|
-
|
|
1
|
+
/*! VefFramework version: 1.0.101, build time: 2025-03-07T14:07:14.523Z, made by Venus. */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const core = require('@vef-framework/core');
|
|
7
|
+
const shared = require('@vef-framework/shared');
|
|
8
|
+
const ahooks = require('ahooks');
|
|
9
|
+
const react = require('react');
|
|
10
|
+
|
|
11
|
+
function useApi({
|
|
12
|
+
data,
|
|
13
|
+
dataDictionaryKey,
|
|
14
|
+
api,
|
|
15
|
+
apiParams,
|
|
16
|
+
apiEnabled,
|
|
17
|
+
staleTime,
|
|
18
|
+
keepPreviousData,
|
|
19
|
+
placeholderData
|
|
20
|
+
}, stubQueryApi, dataDictionaryApi) {
|
|
21
|
+
return react.useMemo(() => {
|
|
22
|
+
if (!shared.isNullish(data)) {
|
|
23
|
+
return [
|
|
24
|
+
stubQueryApi,
|
|
25
|
+
data,
|
|
26
|
+
{
|
|
27
|
+
keepPreviousData: true,
|
|
28
|
+
initialData: data
|
|
29
|
+
}
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
if (!shared.isNullish(dataDictionaryKey)) {
|
|
33
|
+
return [
|
|
34
|
+
dataDictionaryApi,
|
|
35
|
+
{
|
|
36
|
+
...apiParams,
|
|
37
|
+
key: dataDictionaryKey
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
enabled: apiEnabled ?? true,
|
|
41
|
+
staleTime,
|
|
42
|
+
keepPreviousData,
|
|
43
|
+
placeholderData
|
|
44
|
+
}
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
if (!shared.isNullish(api)) {
|
|
48
|
+
return [
|
|
49
|
+
api,
|
|
50
|
+
apiParams,
|
|
51
|
+
{
|
|
52
|
+
enabled: apiEnabled ?? true,
|
|
53
|
+
staleTime,
|
|
54
|
+
keepPreviousData,
|
|
55
|
+
placeholderData
|
|
56
|
+
}
|
|
57
|
+
];
|
|
58
|
+
}
|
|
59
|
+
return [
|
|
60
|
+
stubQueryApi,
|
|
61
|
+
[],
|
|
62
|
+
{
|
|
63
|
+
keepPreviousData: true,
|
|
64
|
+
initialData: []
|
|
65
|
+
}
|
|
66
|
+
];
|
|
67
|
+
}, [
|
|
68
|
+
data,
|
|
69
|
+
dataDictionaryKey,
|
|
70
|
+
api,
|
|
71
|
+
stubQueryApi,
|
|
72
|
+
dataDictionaryApi,
|
|
73
|
+
apiParams,
|
|
74
|
+
apiEnabled,
|
|
75
|
+
staleTime,
|
|
76
|
+
keepPreviousData,
|
|
77
|
+
placeholderData
|
|
78
|
+
]);
|
|
79
|
+
}
|
|
80
|
+
function useDataQuery({ onFetched, ...config }) {
|
|
81
|
+
const {
|
|
82
|
+
useApiQuery,
|
|
83
|
+
stubQueryApi,
|
|
84
|
+
dataDictionaryApi: dataDictionaryQueryApi
|
|
85
|
+
} = core.useApiContext();
|
|
86
|
+
const [api, args, options] = useApi(config, stubQueryApi, dataDictionaryQueryApi);
|
|
87
|
+
const result = useApiQuery(api, args, options);
|
|
88
|
+
ahooks.useUnmount(() => {
|
|
89
|
+
if (Object.is(api, stubQueryApi)) {
|
|
90
|
+
stubQueryApi.removeQueries(args);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
const {
|
|
94
|
+
isSuccess,
|
|
95
|
+
data: rawData,
|
|
96
|
+
...rest
|
|
97
|
+
} = result;
|
|
98
|
+
const data = react.useMemo(() => {
|
|
99
|
+
if (isSuccess && shared.isFunction(onFetched)) {
|
|
100
|
+
return onFetched(rawData);
|
|
101
|
+
}
|
|
102
|
+
return rawData;
|
|
103
|
+
}, [isSuccess, rawData, onFetched]);
|
|
104
|
+
return {
|
|
105
|
+
...rest,
|
|
106
|
+
isSuccess,
|
|
107
|
+
data
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
exports.useDataQuery = useDataQuery;
|
|
3
112
|
/*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
|
|
@@ -1,3 +1,15 @@
|
|
|
1
|
-
/*! VefFramework version: 1.0.
|
|
2
|
-
|
|
1
|
+
/*! VefFramework version: 1.0.101, build time: 2025-03-07T14:07:14.523Z, made by Venus. */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const react = require('react');
|
|
7
|
+
const useDeepMemo = require('./use-deep-memo.cjs');
|
|
8
|
+
|
|
9
|
+
function useDeepCallback(callback, dependencies) {
|
|
10
|
+
const memoizedDependencies = useDeepMemo.useDeepMemo(() => dependencies, dependencies);
|
|
11
|
+
return react.useCallback(callback, memoizedDependencies);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
exports.useDeepCallback = useDeepCallback;
|
|
3
15
|
/*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
|
package/lib/use-deep-memo.cjs
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
-
/*! VefFramework version: 1.0.
|
|
2
|
-
|
|
1
|
+
/*! VefFramework version: 1.0.101, build time: 2025-03-07T14:07:14.523Z, made by Venus. */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const shared = require('@vef-framework/shared');
|
|
7
|
+
const react = require('react');
|
|
8
|
+
|
|
9
|
+
function useDeepMemo(factory, dependencies) {
|
|
10
|
+
const lastDependencies = react.useRef();
|
|
11
|
+
const signal = react.useRef(0);
|
|
12
|
+
if (lastDependencies.current === void 0 || !isEqual(dependencies, lastDependencies.current)) {
|
|
13
|
+
signal.current += 1;
|
|
14
|
+
}
|
|
15
|
+
lastDependencies.current = dependencies;
|
|
16
|
+
return react.useMemo(factory, [signal.current]);
|
|
17
|
+
}
|
|
18
|
+
function isEqual(one, another) {
|
|
19
|
+
return one.length === another.length && one.every((value, index) => shared.isDeepEqual(value, another[index]));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
exports.useDeepMemo = useDeepMemo;
|
|
3
23
|
/*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
|
|
@@ -1,3 +1,18 @@
|
|
|
1
|
-
/*! VefFramework version: 1.0.
|
|
2
|
-
|
|
1
|
+
/*! VefFramework version: 1.0.101, build time: 2025-03-07T14:07:14.523Z, made by Venus. */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const shared = require('@vef-framework/shared');
|
|
7
|
+
const react = require('react');
|
|
8
|
+
|
|
9
|
+
function useDeepSelector(selector) {
|
|
10
|
+
const prevSelectedState = react.useRef();
|
|
11
|
+
return (state) => {
|
|
12
|
+
const nextSelectedState = selector(state);
|
|
13
|
+
return shared.isDeepEqual(prevSelectedState.current, nextSelectedState) ? prevSelectedState.current : prevSelectedState.current = nextSelectedState;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
exports.useDeepSelector = useDeepSelector;
|
|
3
18
|
/*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
|
|
@@ -1,3 +1,107 @@
|
|
|
1
|
-
/*! VefFramework version: 1.0.
|
|
2
|
-
|
|
1
|
+
/*! VefFramework version: 1.0.101, build time: 2025-03-07T14:07:14.523Z, made by Venus. */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const core = require('@vef-framework/core');
|
|
7
|
+
const shared = require('@vef-framework/shared');
|
|
8
|
+
const ahooks = require('ahooks');
|
|
9
|
+
const react = require('react');
|
|
10
|
+
const useShallowMemo = require('./use-shallow-memo.cjs');
|
|
11
|
+
|
|
12
|
+
function useApi(missingOptionValues, {
|
|
13
|
+
fallbackOptionsApi,
|
|
14
|
+
fallbackOptionsApiParams,
|
|
15
|
+
valuesKey,
|
|
16
|
+
resolveFallbackOptions
|
|
17
|
+
}, stubQueryApi, asyncFnQueryApi) {
|
|
18
|
+
const uniqueId = react.useId();
|
|
19
|
+
return useShallowMemo.useShallowMemo(() => {
|
|
20
|
+
if (missingOptionValues.length > 0) {
|
|
21
|
+
if (shared.isFunction(resolveFallbackOptions)) {
|
|
22
|
+
const params = {
|
|
23
|
+
key: uniqueId,
|
|
24
|
+
args: [missingOptionValues],
|
|
25
|
+
fn: resolveFallbackOptions
|
|
26
|
+
};
|
|
27
|
+
return [
|
|
28
|
+
asyncFnQueryApi,
|
|
29
|
+
params,
|
|
30
|
+
{
|
|
31
|
+
keepPreviousData: true
|
|
32
|
+
}
|
|
33
|
+
];
|
|
34
|
+
}
|
|
35
|
+
if (fallbackOptionsApi) {
|
|
36
|
+
const params = {
|
|
37
|
+
...fallbackOptionsApiParams,
|
|
38
|
+
[valuesKey ?? "ids"]: missingOptionValues
|
|
39
|
+
};
|
|
40
|
+
return [
|
|
41
|
+
fallbackOptionsApi,
|
|
42
|
+
params,
|
|
43
|
+
{
|
|
44
|
+
keepPreviousData: true
|
|
45
|
+
}
|
|
46
|
+
];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return [
|
|
50
|
+
stubQueryApi,
|
|
51
|
+
[],
|
|
52
|
+
{
|
|
53
|
+
keepPreviousData: true,
|
|
54
|
+
initialData: []
|
|
55
|
+
}
|
|
56
|
+
];
|
|
57
|
+
}, [
|
|
58
|
+
resolveFallbackOptions,
|
|
59
|
+
fallbackOptionsApi,
|
|
60
|
+
stubQueryApi,
|
|
61
|
+
uniqueId,
|
|
62
|
+
missingOptionValues,
|
|
63
|
+
asyncFnQueryApi,
|
|
64
|
+
fallbackOptionsApiParams,
|
|
65
|
+
valuesKey
|
|
66
|
+
]);
|
|
67
|
+
}
|
|
68
|
+
function useFallbackOptions(missingOptionValues, {
|
|
69
|
+
fallbackOptionsApi,
|
|
70
|
+
fallbackOptionsApiParams,
|
|
71
|
+
valuesKey,
|
|
72
|
+
resolveFallbackOptions
|
|
73
|
+
}) {
|
|
74
|
+
const {
|
|
75
|
+
useApiQuery,
|
|
76
|
+
stubQueryApi,
|
|
77
|
+
asyncFnQueryApi
|
|
78
|
+
} = core.useApiContext();
|
|
79
|
+
const [
|
|
80
|
+
api,
|
|
81
|
+
params,
|
|
82
|
+
options
|
|
83
|
+
] = useApi(
|
|
84
|
+
missingOptionValues,
|
|
85
|
+
{
|
|
86
|
+
fallbackOptionsApi,
|
|
87
|
+
fallbackOptionsApiParams,
|
|
88
|
+
valuesKey,
|
|
89
|
+
resolveFallbackOptions
|
|
90
|
+
},
|
|
91
|
+
stubQueryApi,
|
|
92
|
+
asyncFnQueryApi
|
|
93
|
+
);
|
|
94
|
+
const result = useApiQuery(api, params, options);
|
|
95
|
+
ahooks.useUnmount(() => {
|
|
96
|
+
if (Object.is(api, stubQueryApi)) {
|
|
97
|
+
stubQueryApi.removeQueries(params);
|
|
98
|
+
}
|
|
99
|
+
if (Object.is(api, asyncFnQueryApi)) {
|
|
100
|
+
asyncFnQueryApi.removeQueries(params);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
exports.useFallbackOptions = useFallbackOptions;
|
|
3
107
|
/*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
|
|
@@ -1,3 +1,40 @@
|
|
|
1
|
-
/*! VefFramework version: 1.0.
|
|
2
|
-
|
|
1
|
+
/*! VefFramework version: 1.0.101, build time: 2025-03-07T14:07:14.523Z, made by Venus. */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const react = require('react');
|
|
7
|
+
const useThemeTokens = require('./use-theme-tokens.cjs');
|
|
8
|
+
|
|
9
|
+
function useGapSizeNormalizer() {
|
|
10
|
+
const {
|
|
11
|
+
paddingXS,
|
|
12
|
+
paddingSM,
|
|
13
|
+
padding,
|
|
14
|
+
paddingMD,
|
|
15
|
+
paddingLG
|
|
16
|
+
} = useThemeTokens.useThemeTokens();
|
|
17
|
+
return react.useCallback((gap) => {
|
|
18
|
+
if (gap === "tiny") {
|
|
19
|
+
return paddingXS;
|
|
20
|
+
} else if (gap === "small") {
|
|
21
|
+
return paddingSM;
|
|
22
|
+
} else if (gap === "medium") {
|
|
23
|
+
return padding;
|
|
24
|
+
} else if (gap === "large") {
|
|
25
|
+
return paddingMD;
|
|
26
|
+
} else if (gap === "huge") {
|
|
27
|
+
return paddingLG;
|
|
28
|
+
}
|
|
29
|
+
return gap;
|
|
30
|
+
}, [
|
|
31
|
+
paddingXS,
|
|
32
|
+
paddingSM,
|
|
33
|
+
padding,
|
|
34
|
+
paddingMD,
|
|
35
|
+
paddingLG
|
|
36
|
+
]);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
exports.useGapSizeNormalizer = useGapSizeNormalizer;
|
|
3
40
|
/*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
-
/*! VefFramework version: 1.0.
|
|
2
|
-
|
|
1
|
+
/*! VefFramework version: 1.0.101, build time: 2025-03-07T14:07:14.523Z, made by Venus. */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const useGapSizeNormalizer = require('./use-gap-size-normalizer.cjs');
|
|
7
|
+
|
|
8
|
+
function useNormalizedGapSize(gap) {
|
|
9
|
+
const normalize = useGapSizeNormalizer.useGapSizeNormalizer();
|
|
10
|
+
return normalize(gap);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
exports.useNormalizedGapSize = useNormalizedGapSize;
|
|
3
14
|
/*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
|
|
@@ -1,3 +1,50 @@
|
|
|
1
|
-
/*! VefFramework version: 1.0.
|
|
2
|
-
|
|
1
|
+
/*! VefFramework version: 1.0.101, build time: 2025-03-07T14:07:14.523Z, made by Venus. */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const react = require('react');
|
|
7
|
+
|
|
8
|
+
function normalizeMenuItem(item) {
|
|
9
|
+
if (item.type === "item") {
|
|
10
|
+
return {
|
|
11
|
+
type: "item",
|
|
12
|
+
key: item.key,
|
|
13
|
+
label: item.label,
|
|
14
|
+
disabled: item.disabled,
|
|
15
|
+
icon: item.icon,
|
|
16
|
+
extra: item.extra
|
|
17
|
+
};
|
|
18
|
+
} else if (item.type === "submenu") {
|
|
19
|
+
return {
|
|
20
|
+
type: "submenu",
|
|
21
|
+
key: item.key,
|
|
22
|
+
label: item.label,
|
|
23
|
+
disabled: item.disabled,
|
|
24
|
+
icon: item.icon,
|
|
25
|
+
children: item.children.map(normalizeMenuItem)
|
|
26
|
+
};
|
|
27
|
+
} else if (item.type === "group") {
|
|
28
|
+
return {
|
|
29
|
+
type: "group",
|
|
30
|
+
key: item.key,
|
|
31
|
+
label: item.label,
|
|
32
|
+
children: item.children.map(normalizeMenuItem)
|
|
33
|
+
};
|
|
34
|
+
} else {
|
|
35
|
+
return {
|
|
36
|
+
type: "divider",
|
|
37
|
+
key: item.key
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function useNormalizedMenuItems(items) {
|
|
42
|
+
return react.useMemo(
|
|
43
|
+
() => items.map(normalizeMenuItem),
|
|
44
|
+
[items]
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
exports.normalizeMenuItem = normalizeMenuItem;
|
|
49
|
+
exports.useNormalizedMenuItems = useNormalizedMenuItems;
|
|
3
50
|
/*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
|
|
@@ -1,3 +1,106 @@
|
|
|
1
|
-
/*! VefFramework version: 1.0.
|
|
2
|
-
|
|
1
|
+
/*! VefFramework version: 1.0.101, build time: 2025-03-07T14:07:14.523Z, made by Venus. */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const shared = require('@vef-framework/shared');
|
|
7
|
+
const react = require('react');
|
|
8
|
+
|
|
9
|
+
function useNormalizedDataOptions(options, {
|
|
10
|
+
labelKey = "label",
|
|
11
|
+
valueKey = "value",
|
|
12
|
+
childrenKey = "children",
|
|
13
|
+
descriptionKey = "description",
|
|
14
|
+
disabledKey = "disabled",
|
|
15
|
+
defaultToFirst = false
|
|
16
|
+
}, {
|
|
17
|
+
isTree = false,
|
|
18
|
+
isGrouped = false,
|
|
19
|
+
parsePinyin = false,
|
|
20
|
+
selectedOptionValues = []
|
|
21
|
+
} = {}) {
|
|
22
|
+
return react.useMemo(() => {
|
|
23
|
+
const selectedOptionValuesSet = new Set(selectedOptionValues);
|
|
24
|
+
const isGroupedOptions = !isTree && isGrouped;
|
|
25
|
+
const normalizeOption = (option, isTopLevel = false) => {
|
|
26
|
+
const label = option[labelKey];
|
|
27
|
+
if (shared.isNullish(label)) {
|
|
28
|
+
if (labelKey === "label") {
|
|
29
|
+
throw new shared.VefError(-10001, `The label value of the option is required.`);
|
|
30
|
+
}
|
|
31
|
+
throw new shared.VefError(-10001, `The label value pointed by '${labelKey}' of the option is required.`);
|
|
32
|
+
}
|
|
33
|
+
const value = option[valueKey];
|
|
34
|
+
if (shared.isNullish(value)) {
|
|
35
|
+
if (valueKey === "value") {
|
|
36
|
+
throw new shared.VefError(-10002, `The value of the option is required.`);
|
|
37
|
+
}
|
|
38
|
+
throw new shared.VefError(-10002, `The value pointed by '${valueKey}' of the option is required.`);
|
|
39
|
+
}
|
|
40
|
+
const children = option[childrenKey];
|
|
41
|
+
const description = option[descriptionKey];
|
|
42
|
+
const disabled = option[disabledKey] ?? false;
|
|
43
|
+
const normalizedOption = {
|
|
44
|
+
...option,
|
|
45
|
+
label,
|
|
46
|
+
value,
|
|
47
|
+
children,
|
|
48
|
+
description,
|
|
49
|
+
disabled
|
|
50
|
+
};
|
|
51
|
+
if (parsePinyin) {
|
|
52
|
+
const { labelText, descriptionText } = normalizedOption;
|
|
53
|
+
if (shared.isString(label) || shared.isString(labelText)) {
|
|
54
|
+
normalizedOption.labelPinyin = shared.parsePinyinFirstLetter(
|
|
55
|
+
shared.isString(label) ? label : labelText
|
|
56
|
+
).join("");
|
|
57
|
+
}
|
|
58
|
+
if (shared.isString(description) || shared.isString(descriptionText)) {
|
|
59
|
+
normalizedOption.descriptionPinyin = shared.parsePinyinFirstLetter(
|
|
60
|
+
shared.isString(description) ? description : descriptionText
|
|
61
|
+
).join("");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if ((!isTopLevel || !isGroupedOptions) && selectedOptionValuesSet.has(value)) {
|
|
65
|
+
selectedOptionValuesSet.delete(value);
|
|
66
|
+
}
|
|
67
|
+
if (shared.isArray(normalizedOption.children)) {
|
|
68
|
+
normalizedOption.children = normalizedOption.children.map((option2) => normalizeOption(option2));
|
|
69
|
+
}
|
|
70
|
+
return normalizedOption;
|
|
71
|
+
};
|
|
72
|
+
const normalizedOptions = options.map((option) => normalizeOption(option, true));
|
|
73
|
+
const missingOptionValues = Array.from(selectedOptionValuesSet);
|
|
74
|
+
if (!defaultToFirst) {
|
|
75
|
+
return [normalizedOptions, missingOptionValues];
|
|
76
|
+
}
|
|
77
|
+
if (isGroupedOptions) {
|
|
78
|
+
const firstNonEmptyGroupOption = normalizedOptions.find((item) => shared.isArray(item.children) && item.children.length > 0);
|
|
79
|
+
return [
|
|
80
|
+
normalizedOptions,
|
|
81
|
+
missingOptionValues,
|
|
82
|
+
firstNonEmptyGroupOption?.children?.[0]
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
return [
|
|
86
|
+
normalizedOptions,
|
|
87
|
+
missingOptionValues,
|
|
88
|
+
normalizedOptions[0]
|
|
89
|
+
];
|
|
90
|
+
}, [
|
|
91
|
+
childrenKey,
|
|
92
|
+
defaultToFirst,
|
|
93
|
+
descriptionKey,
|
|
94
|
+
disabledKey,
|
|
95
|
+
isGrouped,
|
|
96
|
+
isTree,
|
|
97
|
+
labelKey,
|
|
98
|
+
options,
|
|
99
|
+
parsePinyin,
|
|
100
|
+
// selectedOptionValues,
|
|
101
|
+
valueKey
|
|
102
|
+
]);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
exports.useNormalizedDataOptions = useNormalizedDataOptions;
|
|
3
106
|
/*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
|
|
@@ -1,3 +1,22 @@
|
|
|
1
|
-
/*! VefFramework version: 1.0.
|
|
2
|
-
|
|
1
|
+
/*! VefFramework version: 1.0.101, build time: 2025-03-07T14:07:14.523Z, made by Venus. */
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const shared = require('@vef-framework/shared');
|
|
7
|
+
const react = require('react');
|
|
8
|
+
|
|
9
|
+
function useOptionFilter(filterable, filterFromRemote) {
|
|
10
|
+
return react.useMemo(() => {
|
|
11
|
+
if (!filterable) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (filterFromRemote) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
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;
|
|
18
|
+
}, [filterable, filterFromRemote]);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
exports.useOptionFilter = useOptionFilter;
|
|
3
22
|
/*! VefFramework is a blazingly high-level, modern, flexible, easy-to-use UI framework made by Venus. Follow me on Github: https://github.com/ilxqx! @ilxqx */
|