@vef-framework/hooks 1.0.97 → 1.0.99
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
package/es/index.js
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
-
/*! VefFramework version: 1.0.
|
|
2
|
-
import
|
|
1
|
+
/*! VefFramework version: 1.0.99, build time: 2025-03-07T13:41:55.433Z, made by Venus. */
|
|
2
|
+
import './lib.js';
|
|
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';
|
|
3
28
|
/*! 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/es/lib.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
/*! VefFramework version: 1.0.
|
|
2
|
-
export{useClickAway,useMeasure}from
|
|
1
|
+
/*! VefFramework version: 1.0.99, build time: 2025-03-07T13:41:55.433Z, made by Venus. */
|
|
2
|
+
export { useClickAway, useMeasure } from '@uidotdev/usehooks';
|
|
3
|
+
export { useDeepCompareEffect as useDeepEffect, useDeepCompareLayoutEffect as useDeepLayoutEffect, useSize as useElementSize, useEventListener, useKeyPress, useMount, useUnmount, useUpdateEffect, useUpdateLayoutEffect, useUpdate as useUpdater } from 'ahooks';
|
|
3
4
|
/*! 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,24 @@
|
|
|
1
|
-
/*! VefFramework version: 1.0.
|
|
2
|
-
import{useAuthContext
|
|
1
|
+
/*! VefFramework version: 1.0.99, build time: 2025-03-07T13:41:55.433Z, made by Venus. */
|
|
2
|
+
import { useAuthContext } from '@vef-framework/core';
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
|
|
5
|
+
function useAuthorizedItems(items) {
|
|
6
|
+
const { checkPermission } = useAuthContext();
|
|
7
|
+
return useMemo(
|
|
8
|
+
() => items?.filter((item) => {
|
|
9
|
+
const { permissions } = item;
|
|
10
|
+
if (!permissions) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
const checkMode = item.checkMode ?? "any";
|
|
14
|
+
if (checkMode === "any") {
|
|
15
|
+
return permissions.some((permission) => checkPermission(permission));
|
|
16
|
+
}
|
|
17
|
+
return permissions.every((permission) => checkPermission(permission));
|
|
18
|
+
}),
|
|
19
|
+
[items, checkPermission]
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { useAuthorizedItems };
|
|
3
24
|
/*! 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/es/use-color-tokens.js
CHANGED
|
@@ -1,3 +1,30 @@
|
|
|
1
|
-
/*! VefFramework version: 1.0.
|
|
2
|
-
import{defaultColorTypes
|
|
1
|
+
/*! VefFramework version: 1.0.99, build time: 2025-03-07T13:41:55.433Z, made by Venus. */
|
|
2
|
+
import { defaultColorTypes, semanticColorTypes, capitalize } from '@vef-framework/shared';
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
import { useThemeTokens } from './use-theme-tokens.js';
|
|
5
|
+
|
|
6
|
+
function useDefaultColorTokens() {
|
|
7
|
+
const tokens = useThemeTokens();
|
|
8
|
+
return useMemo(() => defaultColorTypes.reduce(
|
|
9
|
+
(map, color) => {
|
|
10
|
+
map.set(color, tokens[color]);
|
|
11
|
+
return map;
|
|
12
|
+
},
|
|
13
|
+
/* @__PURE__ */ new Map()
|
|
14
|
+
), [tokens]);
|
|
15
|
+
}
|
|
16
|
+
function useSemanticColorTokens() {
|
|
17
|
+
const tokens = useThemeTokens();
|
|
18
|
+
return useMemo(() => semanticColorTypes.reduce((map, color) => {
|
|
19
|
+
map.set(color, tokens[`color${capitalize(color)}`]);
|
|
20
|
+
return map;
|
|
21
|
+
}, /* @__PURE__ */ new Map()), [tokens]);
|
|
22
|
+
}
|
|
23
|
+
function useColorTokens() {
|
|
24
|
+
const defaultColorTokens = useDefaultColorTokens();
|
|
25
|
+
const semanticColorTokens = useSemanticColorTokens();
|
|
26
|
+
return useMemo(() => new Map([...defaultColorTokens, ...semanticColorTokens]), [defaultColorTokens, semanticColorTokens]);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { useColorTokens, useDefaultColorTokens, useSemanticColorTokens };
|
|
3
30
|
/*! 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,43 @@
|
|
|
1
|
-
/*! VefFramework version: 1.0.
|
|
2
|
-
import{isFunction
|
|
1
|
+
/*! VefFramework version: 1.0.99, build time: 2025-03-07T13:41:55.433Z, made by Venus. */
|
|
2
|
+
import { isFunction, defaultMessageTitle } from '@vef-framework/shared';
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
|
|
5
|
+
function useComputedActionButtons(buttons, context) {
|
|
6
|
+
return useMemo(() => buttons.filter((button) => {
|
|
7
|
+
const { show } = button;
|
|
8
|
+
if (isFunction(show)) {
|
|
9
|
+
return show(context);
|
|
10
|
+
}
|
|
11
|
+
return show ?? true;
|
|
12
|
+
}).map((button) => {
|
|
13
|
+
const {
|
|
14
|
+
disabled,
|
|
15
|
+
requireConfirmation,
|
|
16
|
+
confirmationMode,
|
|
17
|
+
confirmationTitle,
|
|
18
|
+
confirmationContent,
|
|
19
|
+
...rest
|
|
20
|
+
} = button;
|
|
21
|
+
const computedButton = {
|
|
22
|
+
...rest,
|
|
23
|
+
disabled: isFunction(disabled) ? disabled(context) : disabled ?? false,
|
|
24
|
+
requireConfirmation: isFunction(requireConfirmation) ? requireConfirmation(context) : requireConfirmation ?? false,
|
|
25
|
+
confirmationMode: isFunction(confirmationMode) ? confirmationMode(context) : confirmationMode ?? "simple",
|
|
26
|
+
confirmationTitle: isFunction(confirmationTitle) ? confirmationTitle(context) : confirmationTitle ?? defaultMessageTitle,
|
|
27
|
+
confirmationContent: isFunction(confirmationContent) ? confirmationContent(context) : confirmationContent ?? `\u786E\u5B9A\u8981${rest.label}\u5417\uFF1F`
|
|
28
|
+
};
|
|
29
|
+
if (computedButton.requireConfirmation && !computedButton.confirmationMode) {
|
|
30
|
+
computedButton.confirmationMode = "simple";
|
|
31
|
+
}
|
|
32
|
+
if (computedButton.requireConfirmation && !computedButton.confirmationTitle) {
|
|
33
|
+
computedButton.confirmationTitle = defaultMessageTitle;
|
|
34
|
+
}
|
|
35
|
+
if (computedButton.requireConfirmation && !computedButton.confirmationContent) {
|
|
36
|
+
computedButton.confirmationContent = `\u786E\u5B9A\u8981${computedButton.label}\u5417\uFF1F`;
|
|
37
|
+
}
|
|
38
|
+
return computedButton;
|
|
39
|
+
}), [buttons, context]);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { useComputedActionButtons };
|
|
3
43
|
/*! 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,67 @@
|
|
|
1
|
-
/*! VefFramework version: 1.0.
|
|
2
|
-
import
|
|
1
|
+
/*! VefFramework version: 1.0.99, build time: 2025-03-07T13:41:55.433Z, made by Venus. */
|
|
2
|
+
import { useDataQuery } from './use-data-query.js';
|
|
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
|
+
function useComputedOptions({
|
|
8
|
+
labelKey,
|
|
9
|
+
valueKey,
|
|
10
|
+
descriptionKey,
|
|
11
|
+
childrenKey,
|
|
12
|
+
disabledKey,
|
|
13
|
+
defaultToFirst,
|
|
14
|
+
filterable = false,
|
|
15
|
+
filterFromRemote = false,
|
|
16
|
+
keywordKey = "keyword",
|
|
17
|
+
valuesKey = "ids",
|
|
18
|
+
fallbackOptionsApi,
|
|
19
|
+
fallbackOptionsApiParams,
|
|
20
|
+
resolveFallbackOptions,
|
|
21
|
+
isGrouped = false,
|
|
22
|
+
selectedOptionValues,
|
|
23
|
+
apiParams,
|
|
24
|
+
...queryConfig
|
|
25
|
+
}) {
|
|
26
|
+
const [mergedApiParams, onFilterKeywordChange] = useRemoteFilter(filterable && filterFromRemote, apiParams, keywordKey);
|
|
27
|
+
const { data: options, isLoading } = useDataQuery({
|
|
28
|
+
apiParams: mergedApiParams,
|
|
29
|
+
...queryConfig
|
|
30
|
+
});
|
|
31
|
+
const [normalizedOptions, missingOptionValues, defaultOption] = useNormalizedDataOptions(
|
|
32
|
+
options ?? [],
|
|
33
|
+
{
|
|
34
|
+
labelKey,
|
|
35
|
+
valueKey,
|
|
36
|
+
descriptionKey,
|
|
37
|
+
childrenKey,
|
|
38
|
+
disabledKey,
|
|
39
|
+
defaultToFirst
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
isGrouped,
|
|
43
|
+
parsePinyin: filterable && !filterFromRemote,
|
|
44
|
+
selectedOptionValues
|
|
45
|
+
}
|
|
46
|
+
);
|
|
47
|
+
const { data: fallbackOptions, isLoading: isFallbackOptionsLoading } = useFallbackOptions(
|
|
48
|
+
missingOptionValues,
|
|
49
|
+
{
|
|
50
|
+
fallbackOptionsApi: fallbackOptionsApi ?? queryConfig.api,
|
|
51
|
+
fallbackOptionsApiParams,
|
|
52
|
+
valuesKey,
|
|
53
|
+
resolveFallbackOptions
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
return {
|
|
57
|
+
onFilterKeywordChange,
|
|
58
|
+
isLoading,
|
|
59
|
+
normalizedOptions,
|
|
60
|
+
defaultOption,
|
|
61
|
+
fallbackOptions,
|
|
62
|
+
isFallbackOptionsLoading
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export { useComputedOptions };
|
|
3
67
|
/*! 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,11 @@
|
|
|
1
|
-
/*! VefFramework version: 1.0.
|
|
2
|
-
import{createContext
|
|
1
|
+
/*! VefFramework version: 1.0.99, build time: 2025-03-07T13:41:55.433Z, made by Venus. */
|
|
2
|
+
import { createContext, useContext } from 'react';
|
|
3
|
+
|
|
4
|
+
const DisabledContext = createContext(false);
|
|
5
|
+
function useContextDisabled() {
|
|
6
|
+
return useContext(DisabledContext);
|
|
7
|
+
}
|
|
8
|
+
const DisabledContextProvider = DisabledContext.Provider;
|
|
9
|
+
|
|
10
|
+
export { DisabledContextProvider, useContextDisabled };
|
|
3
11
|
/*! 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/es/use-data-query.js
CHANGED
|
@@ -1,3 +1,108 @@
|
|
|
1
|
-
/*! VefFramework version: 1.0.
|
|
2
|
-
import{useApiContext
|
|
1
|
+
/*! VefFramework version: 1.0.99, build time: 2025-03-07T13:41:55.433Z, made by Venus. */
|
|
2
|
+
import { useApiContext } from '@vef-framework/core';
|
|
3
|
+
import { isNullish, isFunction } from '@vef-framework/shared';
|
|
4
|
+
import { useUnmount } from 'ahooks';
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
|
+
|
|
7
|
+
function useApi({
|
|
8
|
+
data,
|
|
9
|
+
dataDictionaryKey,
|
|
10
|
+
api,
|
|
11
|
+
apiParams,
|
|
12
|
+
apiEnabled,
|
|
13
|
+
staleTime,
|
|
14
|
+
keepPreviousData,
|
|
15
|
+
placeholderData
|
|
16
|
+
}, stubQueryApi, dataDictionaryApi) {
|
|
17
|
+
return useMemo(() => {
|
|
18
|
+
if (!isNullish(data)) {
|
|
19
|
+
return [
|
|
20
|
+
stubQueryApi,
|
|
21
|
+
data,
|
|
22
|
+
{
|
|
23
|
+
keepPreviousData: true,
|
|
24
|
+
initialData: data
|
|
25
|
+
}
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
if (!isNullish(dataDictionaryKey)) {
|
|
29
|
+
return [
|
|
30
|
+
dataDictionaryApi,
|
|
31
|
+
{
|
|
32
|
+
...apiParams,
|
|
33
|
+
key: dataDictionaryKey
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
enabled: apiEnabled ?? true,
|
|
37
|
+
staleTime,
|
|
38
|
+
keepPreviousData,
|
|
39
|
+
placeholderData
|
|
40
|
+
}
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
if (!isNullish(api)) {
|
|
44
|
+
return [
|
|
45
|
+
api,
|
|
46
|
+
apiParams,
|
|
47
|
+
{
|
|
48
|
+
enabled: apiEnabled ?? true,
|
|
49
|
+
staleTime,
|
|
50
|
+
keepPreviousData,
|
|
51
|
+
placeholderData
|
|
52
|
+
}
|
|
53
|
+
];
|
|
54
|
+
}
|
|
55
|
+
return [
|
|
56
|
+
stubQueryApi,
|
|
57
|
+
[],
|
|
58
|
+
{
|
|
59
|
+
keepPreviousData: true,
|
|
60
|
+
initialData: []
|
|
61
|
+
}
|
|
62
|
+
];
|
|
63
|
+
}, [
|
|
64
|
+
data,
|
|
65
|
+
dataDictionaryKey,
|
|
66
|
+
api,
|
|
67
|
+
stubQueryApi,
|
|
68
|
+
dataDictionaryApi,
|
|
69
|
+
apiParams,
|
|
70
|
+
apiEnabled,
|
|
71
|
+
staleTime,
|
|
72
|
+
keepPreviousData,
|
|
73
|
+
placeholderData
|
|
74
|
+
]);
|
|
75
|
+
}
|
|
76
|
+
function useDataQuery({ onFetched, ...config }) {
|
|
77
|
+
const {
|
|
78
|
+
useApiQuery,
|
|
79
|
+
stubQueryApi,
|
|
80
|
+
dataDictionaryApi: dataDictionaryQueryApi
|
|
81
|
+
} = useApiContext();
|
|
82
|
+
const [api, args, options] = useApi(config, stubQueryApi, dataDictionaryQueryApi);
|
|
83
|
+
const result = useApiQuery(api, args, options);
|
|
84
|
+
useUnmount(() => {
|
|
85
|
+
if (Object.is(api, stubQueryApi)) {
|
|
86
|
+
stubQueryApi.removeQueries(args);
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
const {
|
|
90
|
+
isSuccess,
|
|
91
|
+
data: rawData,
|
|
92
|
+
...rest
|
|
93
|
+
} = result;
|
|
94
|
+
const data = useMemo(() => {
|
|
95
|
+
if (isSuccess && isFunction(onFetched)) {
|
|
96
|
+
return onFetched(rawData);
|
|
97
|
+
}
|
|
98
|
+
return rawData;
|
|
99
|
+
}, [isSuccess, rawData, onFetched]);
|
|
100
|
+
return {
|
|
101
|
+
...rest,
|
|
102
|
+
isSuccess,
|
|
103
|
+
data
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export { useDataQuery };
|
|
3
108
|
/*! 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/es/use-deep-callback.js
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
/*! VefFramework version: 1.0.
|
|
2
|
-
import{useCallback
|
|
1
|
+
/*! VefFramework version: 1.0.99, build time: 2025-03-07T13:41:55.433Z, made by Venus. */
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
|
+
import { useDeepMemo } from './use-deep-memo.js';
|
|
4
|
+
|
|
5
|
+
function useDeepCallback(callback, dependencies) {
|
|
6
|
+
const memoizedDependencies = useDeepMemo(() => dependencies, dependencies);
|
|
7
|
+
return useCallback(callback, memoizedDependencies);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { useDeepCallback };
|
|
3
11
|
/*! 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/es/use-deep-memo.js
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
-
/*! VefFramework version: 1.0.
|
|
2
|
-
import{isDeepEqual
|
|
1
|
+
/*! VefFramework version: 1.0.99, build time: 2025-03-07T13:41:55.433Z, made by Venus. */
|
|
2
|
+
import { isDeepEqual } from '@vef-framework/shared';
|
|
3
|
+
import { useRef, useMemo } from 'react';
|
|
4
|
+
|
|
5
|
+
function useDeepMemo(factory, dependencies) {
|
|
6
|
+
const lastDependencies = useRef();
|
|
7
|
+
const signal = useRef(0);
|
|
8
|
+
if (lastDependencies.current === void 0 || !isEqual(dependencies, lastDependencies.current)) {
|
|
9
|
+
signal.current += 1;
|
|
10
|
+
}
|
|
11
|
+
lastDependencies.current = dependencies;
|
|
12
|
+
return useMemo(factory, [signal.current]);
|
|
13
|
+
}
|
|
14
|
+
function isEqual(one, another) {
|
|
15
|
+
return one.length === another.length && one.every((value, index) => isDeepEqual(value, another[index]));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { useDeepMemo };
|
|
3
19
|
/*! 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/es/use-deep-selector.js
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
-
/*! VefFramework version: 1.0.
|
|
2
|
-
import{isDeepEqual
|
|
1
|
+
/*! VefFramework version: 1.0.99, build time: 2025-03-07T13:41:55.433Z, made by Venus. */
|
|
2
|
+
import { isDeepEqual } from '@vef-framework/shared';
|
|
3
|
+
import { useRef } from 'react';
|
|
4
|
+
|
|
5
|
+
function useDeepSelector(selector) {
|
|
6
|
+
const prevSelectedState = useRef();
|
|
7
|
+
return (state) => {
|
|
8
|
+
const nextSelectedState = selector(state);
|
|
9
|
+
return isDeepEqual(prevSelectedState.current, nextSelectedState) ? prevSelectedState.current : prevSelectedState.current = nextSelectedState;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { useDeepSelector };
|
|
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,103 @@
|
|
|
1
|
-
/*! VefFramework version: 1.0.
|
|
2
|
-
import{useApiContext
|
|
1
|
+
/*! VefFramework version: 1.0.99, build time: 2025-03-07T13:41:55.433Z, made by Venus. */
|
|
2
|
+
import { useApiContext } from '@vef-framework/core';
|
|
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
|
+
function useApi(missingOptionValues, {
|
|
9
|
+
fallbackOptionsApi,
|
|
10
|
+
fallbackOptionsApiParams,
|
|
11
|
+
valuesKey,
|
|
12
|
+
resolveFallbackOptions
|
|
13
|
+
}, stubQueryApi, asyncFnQueryApi) {
|
|
14
|
+
const uniqueId = useId();
|
|
15
|
+
return useShallowMemo(() => {
|
|
16
|
+
if (missingOptionValues.length > 0) {
|
|
17
|
+
if (isFunction(resolveFallbackOptions)) {
|
|
18
|
+
const params = {
|
|
19
|
+
key: uniqueId,
|
|
20
|
+
args: [missingOptionValues],
|
|
21
|
+
fn: resolveFallbackOptions
|
|
22
|
+
};
|
|
23
|
+
return [
|
|
24
|
+
asyncFnQueryApi,
|
|
25
|
+
params,
|
|
26
|
+
{
|
|
27
|
+
keepPreviousData: true
|
|
28
|
+
}
|
|
29
|
+
];
|
|
30
|
+
}
|
|
31
|
+
if (fallbackOptionsApi) {
|
|
32
|
+
const params = {
|
|
33
|
+
...fallbackOptionsApiParams,
|
|
34
|
+
[valuesKey ?? "ids"]: missingOptionValues
|
|
35
|
+
};
|
|
36
|
+
return [
|
|
37
|
+
fallbackOptionsApi,
|
|
38
|
+
params,
|
|
39
|
+
{
|
|
40
|
+
keepPreviousData: true
|
|
41
|
+
}
|
|
42
|
+
];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return [
|
|
46
|
+
stubQueryApi,
|
|
47
|
+
[],
|
|
48
|
+
{
|
|
49
|
+
keepPreviousData: true,
|
|
50
|
+
initialData: []
|
|
51
|
+
}
|
|
52
|
+
];
|
|
53
|
+
}, [
|
|
54
|
+
resolveFallbackOptions,
|
|
55
|
+
fallbackOptionsApi,
|
|
56
|
+
stubQueryApi,
|
|
57
|
+
uniqueId,
|
|
58
|
+
missingOptionValues,
|
|
59
|
+
asyncFnQueryApi,
|
|
60
|
+
fallbackOptionsApiParams,
|
|
61
|
+
valuesKey
|
|
62
|
+
]);
|
|
63
|
+
}
|
|
64
|
+
function useFallbackOptions(missingOptionValues, {
|
|
65
|
+
fallbackOptionsApi,
|
|
66
|
+
fallbackOptionsApiParams,
|
|
67
|
+
valuesKey,
|
|
68
|
+
resolveFallbackOptions
|
|
69
|
+
}) {
|
|
70
|
+
const {
|
|
71
|
+
useApiQuery,
|
|
72
|
+
stubQueryApi,
|
|
73
|
+
asyncFnQueryApi
|
|
74
|
+
} = useApiContext();
|
|
75
|
+
const [
|
|
76
|
+
api,
|
|
77
|
+
params,
|
|
78
|
+
options
|
|
79
|
+
] = useApi(
|
|
80
|
+
missingOptionValues,
|
|
81
|
+
{
|
|
82
|
+
fallbackOptionsApi,
|
|
83
|
+
fallbackOptionsApiParams,
|
|
84
|
+
valuesKey,
|
|
85
|
+
resolveFallbackOptions
|
|
86
|
+
},
|
|
87
|
+
stubQueryApi,
|
|
88
|
+
asyncFnQueryApi
|
|
89
|
+
);
|
|
90
|
+
const result = useApiQuery(api, params, options);
|
|
91
|
+
useUnmount(() => {
|
|
92
|
+
if (Object.is(api, stubQueryApi)) {
|
|
93
|
+
stubQueryApi.removeQueries(params);
|
|
94
|
+
}
|
|
95
|
+
if (Object.is(api, asyncFnQueryApi)) {
|
|
96
|
+
asyncFnQueryApi.removeQueries(params);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export { useFallbackOptions };
|
|
3
103
|
/*! 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,36 @@
|
|
|
1
|
-
/*! VefFramework version: 1.0.
|
|
2
|
-
import{useCallback
|
|
1
|
+
/*! VefFramework version: 1.0.99, build time: 2025-03-07T13:41:55.433Z, made by Venus. */
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
|
+
import { useThemeTokens } from './use-theme-tokens.js';
|
|
4
|
+
|
|
5
|
+
function useGapSizeNormalizer() {
|
|
6
|
+
const {
|
|
7
|
+
paddingXS,
|
|
8
|
+
paddingSM,
|
|
9
|
+
padding,
|
|
10
|
+
paddingMD,
|
|
11
|
+
paddingLG
|
|
12
|
+
} = useThemeTokens();
|
|
13
|
+
return useCallback((gap) => {
|
|
14
|
+
if (gap === "tiny") {
|
|
15
|
+
return paddingXS;
|
|
16
|
+
} else if (gap === "small") {
|
|
17
|
+
return paddingSM;
|
|
18
|
+
} else if (gap === "medium") {
|
|
19
|
+
return padding;
|
|
20
|
+
} else if (gap === "large") {
|
|
21
|
+
return paddingMD;
|
|
22
|
+
} else if (gap === "huge") {
|
|
23
|
+
return paddingLG;
|
|
24
|
+
}
|
|
25
|
+
return gap;
|
|
26
|
+
}, [
|
|
27
|
+
paddingXS,
|
|
28
|
+
paddingSM,
|
|
29
|
+
padding,
|
|
30
|
+
paddingMD,
|
|
31
|
+
paddingLG
|
|
32
|
+
]);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { useGapSizeNormalizer };
|
|
3
36
|
/*! 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,10 @@
|
|
|
1
|
-
/*! VefFramework version: 1.0.
|
|
2
|
-
import{useGapSizeNormalizer
|
|
1
|
+
/*! VefFramework version: 1.0.99, build time: 2025-03-07T13:41:55.433Z, made by Venus. */
|
|
2
|
+
import { useGapSizeNormalizer } from './use-gap-size-normalizer.js';
|
|
3
|
+
|
|
4
|
+
function useNormalizedGapSize(gap) {
|
|
5
|
+
const normalize = useGapSizeNormalizer();
|
|
6
|
+
return normalize(gap);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { useNormalizedGapSize };
|
|
3
10
|
/*! 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,45 @@
|
|
|
1
|
-
/*! VefFramework version: 1.0.
|
|
2
|
-
import{useMemo
|
|
1
|
+
/*! VefFramework version: 1.0.99, build time: 2025-03-07T13:41:55.433Z, made by Venus. */
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
|
|
4
|
+
function normalizeMenuItem(item) {
|
|
5
|
+
if (item.type === "item") {
|
|
6
|
+
return {
|
|
7
|
+
type: "item",
|
|
8
|
+
key: item.key,
|
|
9
|
+
label: item.label,
|
|
10
|
+
disabled: item.disabled,
|
|
11
|
+
icon: item.icon,
|
|
12
|
+
extra: item.extra
|
|
13
|
+
};
|
|
14
|
+
} else if (item.type === "submenu") {
|
|
15
|
+
return {
|
|
16
|
+
type: "submenu",
|
|
17
|
+
key: item.key,
|
|
18
|
+
label: item.label,
|
|
19
|
+
disabled: item.disabled,
|
|
20
|
+
icon: item.icon,
|
|
21
|
+
children: item.children.map(normalizeMenuItem)
|
|
22
|
+
};
|
|
23
|
+
} else if (item.type === "group") {
|
|
24
|
+
return {
|
|
25
|
+
type: "group",
|
|
26
|
+
key: item.key,
|
|
27
|
+
label: item.label,
|
|
28
|
+
children: item.children.map(normalizeMenuItem)
|
|
29
|
+
};
|
|
30
|
+
} else {
|
|
31
|
+
return {
|
|
32
|
+
type: "divider",
|
|
33
|
+
key: item.key
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function useNormalizedMenuItems(items) {
|
|
38
|
+
return useMemo(
|
|
39
|
+
() => items.map(normalizeMenuItem),
|
|
40
|
+
[items]
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { normalizeMenuItem, useNormalizedMenuItems };
|
|
3
45
|
/*! 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 */
|