@vef-framework/hooks 1.0.122 → 1.0.123

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.
Files changed (101) hide show
  1. package/cjs/index.cjs +107 -0
  2. package/cjs/lib.cjs +56 -0
  3. package/cjs/use-authorized-items.cjs +26 -0
  4. package/cjs/use-color-tokens.cjs +34 -0
  5. package/cjs/use-computed-action-buttons.cjs +45 -0
  6. package/cjs/use-computed-options.cjs +69 -0
  7. package/cjs/use-context-disabled.cjs +14 -0
  8. package/cjs/use-data-query.cjs +110 -0
  9. package/cjs/use-deep-callback.cjs +13 -0
  10. package/cjs/use-deep-memo.cjs +21 -0
  11. package/cjs/use-deep-selector.cjs +16 -0
  12. package/cjs/use-fallback-options.cjs +105 -0
  13. package/cjs/use-gap-size-normalizer.cjs +38 -0
  14. package/cjs/use-normalized-gap-size.cjs +12 -0
  15. package/cjs/use-normalized-menu-items.cjs +48 -0
  16. package/cjs/use-normalized-options.cjs +104 -0
  17. package/cjs/use-option-filter.cjs +20 -0
  18. package/cjs/use-remote-filter.cjs +39 -0
  19. package/cjs/use-shallow-callback.cjs +13 -0
  20. package/cjs/use-shallow-memo.cjs +21 -0
  21. package/cjs/use-shallow-selector.cjs +16 -0
  22. package/cjs/use-singleton.cjs +16 -0
  23. package/cjs/use-theme-tokens.cjs +13 -0
  24. package/cjs/use-transient-store.cjs +34 -0
  25. package/cjs/use-window-size.cjs +21 -0
  26. package/esm/index.js +29 -0
  27. package/esm/lib.js +5 -0
  28. package/esm/use-authorized-items.js +24 -0
  29. package/esm/use-color-tokens.js +30 -0
  30. package/esm/use-computed-action-buttons.js +43 -0
  31. package/esm/use-computed-options.js +67 -0
  32. package/esm/use-context-disabled.js +11 -0
  33. package/esm/use-data-query.js +108 -0
  34. package/esm/use-deep-callback.js +11 -0
  35. package/esm/use-deep-memo.js +19 -0
  36. package/esm/use-deep-selector.js +14 -0
  37. package/esm/use-fallback-options.js +103 -0
  38. package/esm/use-gap-size-normalizer.js +36 -0
  39. package/esm/use-normalized-gap-size.js +10 -0
  40. package/esm/use-normalized-menu-items.js +45 -0
  41. package/esm/use-normalized-options.js +102 -0
  42. package/esm/use-option-filter.js +18 -0
  43. package/esm/use-remote-filter.js +37 -0
  44. package/esm/use-shallow-callback.js +11 -0
  45. package/esm/use-shallow-memo.js +19 -0
  46. package/esm/use-shallow-selector.js +14 -0
  47. package/esm/use-singleton.js +14 -0
  48. package/esm/use-theme-tokens.js +11 -0
  49. package/esm/use-transient-store.js +32 -0
  50. package/esm/use-window-size.js +19 -0
  51. package/package.json +9 -8
  52. package/es/index.js +0 -1
  53. package/es/lib.js +0 -1
  54. package/es/use-authorized-items.js +0 -1
  55. package/es/use-color-tokens.js +0 -1
  56. package/es/use-computed-action-buttons.js +0 -1
  57. package/es/use-computed-options.js +0 -1
  58. package/es/use-context-disabled.js +0 -1
  59. package/es/use-data-query.js +0 -1
  60. package/es/use-deep-callback.js +0 -1
  61. package/es/use-deep-memo.js +0 -1
  62. package/es/use-deep-selector.js +0 -1
  63. package/es/use-fallback-options.js +0 -1
  64. package/es/use-gap-size-normalizer.js +0 -1
  65. package/es/use-normalized-gap-size.js +0 -1
  66. package/es/use-normalized-menu-items.js +0 -1
  67. package/es/use-normalized-options.js +0 -1
  68. package/es/use-option-filter.js +0 -1
  69. package/es/use-remote-filter.js +0 -1
  70. package/es/use-shallow-callback.js +0 -1
  71. package/es/use-shallow-memo.js +0 -1
  72. package/es/use-shallow-selector.js +0 -1
  73. package/es/use-singleton.js +0 -1
  74. package/es/use-theme-tokens.js +0 -1
  75. package/es/use-transient-store.js +0 -1
  76. package/es/use-window-size.js +0 -1
  77. package/lib/index.cjs +0 -1
  78. package/lib/lib.cjs +0 -1
  79. package/lib/use-authorized-items.cjs +0 -1
  80. package/lib/use-color-tokens.cjs +0 -1
  81. package/lib/use-computed-action-buttons.cjs +0 -1
  82. package/lib/use-computed-options.cjs +0 -1
  83. package/lib/use-context-disabled.cjs +0 -1
  84. package/lib/use-data-query.cjs +0 -1
  85. package/lib/use-deep-callback.cjs +0 -1
  86. package/lib/use-deep-memo.cjs +0 -1
  87. package/lib/use-deep-selector.cjs +0 -1
  88. package/lib/use-fallback-options.cjs +0 -1
  89. package/lib/use-gap-size-normalizer.cjs +0 -1
  90. package/lib/use-normalized-gap-size.cjs +0 -1
  91. package/lib/use-normalized-menu-items.cjs +0 -1
  92. package/lib/use-normalized-options.cjs +0 -1
  93. package/lib/use-option-filter.cjs +0 -1
  94. package/lib/use-remote-filter.cjs +0 -1
  95. package/lib/use-shallow-callback.cjs +0 -1
  96. package/lib/use-shallow-memo.cjs +0 -1
  97. package/lib/use-shallow-selector.cjs +0 -1
  98. package/lib/use-singleton.cjs +0 -1
  99. package/lib/use-theme-tokens.cjs +0 -1
  100. package/lib/use-transient-store.cjs +0 -1
  101. package/lib/use-window-size.cjs +0 -1
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ import { useCallback } from 'react';
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 };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ import { isDeepEqual } from '@vef-framework/shared';
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 };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ import { isDeepEqual } from '@vef-framework/shared';
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 };
@@ -0,0 +1,103 @@
1
+ "use strict";
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
+ "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 };
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ import { useCallback } from 'react';
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 };
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ import { useGapSizeNormalizer } from './use-gap-size-normalizer.js';
3
+
4
+ "use strict";
5
+ function useNormalizedGapSize(gap) {
6
+ const normalize = useGapSizeNormalizer();
7
+ return normalize(gap);
8
+ }
9
+
10
+ export { useNormalizedGapSize };
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ import { useMemo } from 'react';
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 };
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ import { isNullish, VefError, isString, parsePinyinFirstLetter, isArray } from '@vef-framework/shared';
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 };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ import { isString } from '@vef-framework/shared';
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 };
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ import { trim, debounce } from '@vef-framework/shared';
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 };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ import { useCallback } from 'react';
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 };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ import { isShallowEqual } from '@vef-framework/shared';
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 };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ import { isShallowEqual } from '@vef-framework/shared';
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 };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ import { isNullish } from '@vef-framework/shared';
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 };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ import { theme } from 'antd';
3
+
4
+ "use strict";
5
+ const { useToken } = theme;
6
+ function useThemeTokens() {
7
+ const { token } = useToken();
8
+ return token;
9
+ }
10
+
11
+ export { useThemeTokens };
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ import { isShallowEqual } from '@vef-framework/shared';
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 };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ import { useRafState, useEventListener } from 'ahooks';
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 };
package/package.json CHANGED
@@ -1,9 +1,8 @@
1
1
  {
2
2
  "name": "@vef-framework/hooks",
3
3
  "type": "module",
4
- "version": "1.0.122",
4
+ "version": "1.0.123",
5
5
  "private": false,
6
- "packageManager": "pnpm@9.15.0",
7
6
  "description": "The hooks of the VEF framework",
8
7
  "author": "Venus",
9
8
  "keywords": [
@@ -15,11 +14,11 @@
15
14
  "exports": {
16
15
  ".": {
17
16
  "types": "./types/index.d.ts",
18
- "import": "./es/index.js",
19
- "require": "./lib/index.cjs"
17
+ "import": "./esm/index.js",
18
+ "require": "./cjs/index.cjs"
20
19
  }
21
20
  },
22
- "main": "es/index.js",
21
+ "main": "cjs/index.cjs",
23
22
  "types": "types/index.d.ts",
24
23
  "files": [
25
24
  "*"
@@ -31,17 +30,19 @@
31
30
  "@emotion/cache": "11.14.0",
32
31
  "@emotion/react": "11.14.0",
33
32
  "@emotion/styled": "11.14.0",
34
- "antd": "5.24.3",
33
+ "antd": "5.24.4",
35
34
  "tslib": "2.8.1",
36
35
  "use-sync-external-store": "^1.4.0",
37
36
  "@uidotdev/usehooks": "^2.4.1",
38
- "@vef-framework/core": "1.0.122",
39
- "@vef-framework/shared": "1.0.122",
37
+ "@vef-framework/core": "1.0.123",
38
+ "@vef-framework/shared": "1.0.123",
40
39
  "ahooks": "3.8.4"
41
40
  },
42
41
  "publishConfig": {
43
42
  "access": "public"
44
43
  },
44
+ "module": "esm/index.js",
45
+ "packageManager": "pnpm@10.6.3",
45
46
  "peerDependencies": {
46
47
  "react": "18.3.1",
47
48
  "react-dom": "18.3.1"
package/es/index.js DELETED
@@ -1 +0,0 @@
1
- /*! VefFramework version: 1.0.122, build time: 2025-03-11T09:32:18.065Z, made by Venus. */import"./lib.js";import{useAuthorizedItems}from"./use-authorized-items.js";import{useColorTokens,useDefaultColorTokens,useSemanticColorTokens}from"./use-color-tokens.js";import{useComputedActionButtons}from"./use-computed-action-buttons.js";import{useComputedOptions}from"./use-computed-options.js";import{DisabledContextProvider,useContextDisabled}from"./use-context-disabled.js";import{useDataQuery}from"./use-data-query.js";import{useDeepCallback}from"./use-deep-callback.js";import{useDeepMemo}from"./use-deep-memo.js";import{useDeepSelector}from"./use-deep-selector.js";import{useFallbackOptions}from"./use-fallback-options.js";import{useGapSizeNormalizer}from"./use-gap-size-normalizer.js";import{useNormalizedGapSize}from"./use-normalized-gap-size.js";import{normalizeMenuItem,useNormalizedMenuItems}from"./use-normalized-menu-items.js";import{useNormalizedDataOptions}from"./use-normalized-options.js";import{useOptionFilter}from"./use-option-filter.js";import{useRemoteFilter}from"./use-remote-filter.js";import{useShallowCallback}from"./use-shallow-callback.js";import{useShallowMemo}from"./use-shallow-memo.js";import{useShallowSelector}from"./use-shallow-selector.js";import{useSingleton}from"./use-singleton.js";import{useThemeTokens}from"./use-theme-tokens.js";import{useTransientStore}from"./use-transient-store.js";import{useWindowSize}from"./use-window-size.js";import{useClickAway,useMeasure}from"@uidotdev/usehooks";import{useDeepCompareEffect,useDeepCompareLayoutEffect,useSize,useEventListener,useKeyPress,useMount,useUnmount,useUpdateEffect,useUpdateLayoutEffect,useUpdate}from"ahooks";/*! 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 */export{DisabledContextProvider,normalizeMenuItem,useAuthorizedItems,useClickAway,useColorTokens,useComputedActionButtons,useComputedOptions,useContextDisabled,useDataQuery,useDeepCallback,useDeepCompareEffect as useDeepEffect,useDeepCompareLayoutEffect as useDeepLayoutEffect,useDeepMemo,useDeepSelector,useDefaultColorTokens,useSize as useElementSize,useEventListener,useFallbackOptions,useGapSizeNormalizer,useKeyPress,useMeasure,useMount,useNormalizedDataOptions,useNormalizedGapSize,useNormalizedMenuItems,useOptionFilter,useRemoteFilter,useSemanticColorTokens,useShallowCallback,useShallowMemo,useShallowSelector,useSingleton,useThemeTokens,useTransientStore,useUnmount,useUpdateEffect,useUpdateLayoutEffect,useUpdate as useUpdater,useWindowSize};
package/es/lib.js DELETED
@@ -1 +0,0 @@
1
- /*! VefFramework version: 1.0.122, build time: 2025-03-11T09:32:18.065Z, made by Venus. */import{useClickAway,useMeasure}from"@uidotdev/usehooks";import{useDeepCompareEffect,useDeepCompareLayoutEffect,useSize,useEventListener,useKeyPress,useMount,useUnmount,useUpdateEffect,useUpdateLayoutEffect,useUpdate}from"ahooks";/*! 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 */export{useClickAway,useDeepCompareEffect as useDeepEffect,useDeepCompareLayoutEffect as useDeepLayoutEffect,useSize as useElementSize,useEventListener,useKeyPress,useMeasure,useMount,useUnmount,useUpdateEffect,useUpdateLayoutEffect,useUpdate as useUpdater};
@@ -1 +0,0 @@
1
- /*! VefFramework version: 1.0.122, build time: 2025-03-11T09:32:18.065Z, made by Venus. */import{useAuthContext}from"@vef-framework/core";import{useMemo}from"react";function useAuthorizedItems(items){const{checkPermission}=useAuthContext();return useMemo(()=>items?.filter(item=>{const{permissions}=item;return permissions?(item.checkMode??"any")==="any"?permissions.some(permission=>checkPermission(permission)):permissions.every(permission=>checkPermission(permission)):!0}),[items,checkPermission])}/*! 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 */export{useAuthorizedItems};
@@ -1 +0,0 @@
1
- /*! VefFramework version: 1.0.122, build time: 2025-03-11T09:32:18.065Z, made by Venus. */import{defaultColorTypes,semanticColorTypes,capitalize}from"@vef-framework/shared";import{useMemo}from"react";import{useThemeTokens}from"./use-theme-tokens.js";function useDefaultColorTokens(){const tokens=useThemeTokens();return useMemo(()=>defaultColorTypes.reduce((map,color)=>(map.set(color,tokens[color]),map),new Map),[tokens])}function useSemanticColorTokens(){const tokens=useThemeTokens();return useMemo(()=>semanticColorTypes.reduce((map,color)=>(map.set(color,tokens[`color${capitalize(color)}`]),map),new Map),[tokens])}function useColorTokens(){const defaultColorTokens=useDefaultColorTokens(),semanticColorTokens=useSemanticColorTokens();return useMemo(()=>new Map([...defaultColorTokens,...semanticColorTokens]),[defaultColorTokens,semanticColorTokens])}/*! 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 */export{useColorTokens,useDefaultColorTokens,useSemanticColorTokens};
@@ -1 +0,0 @@
1
- /*! VefFramework version: 1.0.122, build time: 2025-03-11T09:32:18.065Z, made by Venus. */import{isFunction,defaultMessageTitle}from"@vef-framework/shared";import{useMemo}from"react";function useComputedActionButtons(buttons,context){return useMemo(()=>buttons.filter(button=>{const{show}=button;return isFunction(show)?show(context):show??!0}).map(button=>{const{disabled,requireConfirmation,confirmationMode,confirmationTitle,confirmationContent,...rest}=button,computedButton={...rest,disabled:isFunction(disabled)?disabled(context):disabled??!1,requireConfirmation:isFunction(requireConfirmation)?requireConfirmation(context):requireConfirmation??!1,confirmationMode:isFunction(confirmationMode)?confirmationMode(context):confirmationMode??"simple",confirmationTitle:isFunction(confirmationTitle)?confirmationTitle(context):confirmationTitle??defaultMessageTitle,confirmationContent:isFunction(confirmationContent)?confirmationContent(context):confirmationContent??`确定要${rest.label}吗?`};return computedButton.requireConfirmation&&!computedButton.confirmationMode&&(computedButton.confirmationMode="simple"),computedButton.requireConfirmation&&!computedButton.confirmationTitle&&(computedButton.confirmationTitle=defaultMessageTitle),computedButton.requireConfirmation&&!computedButton.confirmationContent&&(computedButton.confirmationContent=`确定要${computedButton.label}吗?`),computedButton}),[buttons,context])}/*! 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 */export{useComputedActionButtons};
@@ -1 +0,0 @@
1
- /*! VefFramework version: 1.0.122, build time: 2025-03-11T09:32:18.065Z, made by Venus. */import{useDataQuery}from"./use-data-query.js";import{useFallbackOptions}from"./use-fallback-options.js";import{useNormalizedDataOptions}from"./use-normalized-options.js";import{useRemoteFilter}from"./use-remote-filter.js";function useComputedOptions({labelKey,valueKey,descriptionKey,childrenKey,disabledKey,defaultToFirst,filterable=!1,filterFromRemote=!1,keywordKey="keyword",valuesKey="ids",fallbackOptionsApi,fallbackOptionsApiParams,resolveFallbackOptions,isGrouped=!1,selectedOptionValues,apiParams,...queryConfig}){const[mergedApiParams,onFilterKeywordChange]=useRemoteFilter(filterable&&filterFromRemote,apiParams,keywordKey),{data:options,isLoading}=useDataQuery({apiParams:mergedApiParams,...queryConfig}),[normalizedOptions,missingOptionValues,defaultOption]=useNormalizedDataOptions(options??[],{labelKey,valueKey,descriptionKey,childrenKey,disabledKey,defaultToFirst},{isGrouped,parsePinyin:filterable&&!filterFromRemote,selectedOptionValues}),{data:fallbackOptions,isLoading:isFallbackOptionsLoading}=useFallbackOptions(missingOptionValues,{fallbackOptionsApi:fallbackOptionsApi??queryConfig.api,fallbackOptionsApiParams,valuesKey,resolveFallbackOptions});return{onFilterKeywordChange,isLoading,normalizedOptions,defaultOption,fallbackOptions,isFallbackOptionsLoading}}/*! 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 */export{useComputedOptions};
@@ -1 +0,0 @@
1
- /*! VefFramework version: 1.0.122, build time: 2025-03-11T09:32:18.065Z, made by Venus. */import{createContext,useContext}from"react";const DisabledContext=createContext(!1);function useContextDisabled(){return useContext(DisabledContext)}const DisabledContextProvider=DisabledContext.Provider;/*! 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 */export{DisabledContextProvider,useContextDisabled};
@@ -1 +0,0 @@
1
- /*! VefFramework version: 1.0.122, build time: 2025-03-11T09:32:18.065Z, made by Venus. */import{useApiContext}from"@vef-framework/core";import{isNullish,isFunction}from"@vef-framework/shared";import{useUnmount}from"ahooks";import{useMemo}from"react";function useApi({data,dataDictionaryKey,api,apiParams,apiEnabled,staleTime,keepPreviousData,placeholderData},stubQueryApi,dataDictionaryApi){return useMemo(()=>isNullish(data)?isNullish(dataDictionaryKey)?isNullish(api)?[stubQueryApi,[],{keepPreviousData:!0,initialData:[]}]:[api,apiParams,{enabled:apiEnabled??!0,staleTime,keepPreviousData,placeholderData}]:[dataDictionaryApi,{...apiParams,key:dataDictionaryKey},{enabled:apiEnabled??!0,staleTime,keepPreviousData,placeholderData}]:[stubQueryApi,data,{keepPreviousData:!0,initialData:data}],[data,dataDictionaryKey,api,stubQueryApi,dataDictionaryApi,apiParams,apiEnabled,staleTime,keepPreviousData,placeholderData])}function useDataQuery({onFetched,...config}){const{useApiQuery,stubQueryApi,dataDictionaryApi:dataDictionaryQueryApi}=useApiContext(),[api,args,options]=useApi(config,stubQueryApi,dataDictionaryQueryApi),result=useApiQuery(api,args,options);useUnmount(()=>{Object.is(api,stubQueryApi)&&stubQueryApi.removeQueries(args)});const{isSuccess,data:rawData,...rest}=result,data=useMemo(()=>isSuccess&&isFunction(onFetched)?onFetched(rawData):rawData,[isSuccess,rawData,onFetched]);return{...rest,isSuccess,data}}/*! 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 */export{useDataQuery};
@@ -1 +0,0 @@
1
- /*! VefFramework version: 1.0.122, build time: 2025-03-11T09:32:18.065Z, made by Venus. */import{useCallback}from"react";import{useDeepMemo}from"./use-deep-memo.js";function useDeepCallback(callback,dependencies){const memoizedDependencies=useDeepMemo(()=>dependencies,dependencies);return useCallback(callback,memoizedDependencies)}/*! 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 */export{useDeepCallback};
@@ -1 +0,0 @@
1
- /*! VefFramework version: 1.0.122, build time: 2025-03-11T09:32:18.065Z, made by Venus. */import{isDeepEqual}from"@vef-framework/shared";import{useRef,useMemo}from"react";function useDeepMemo(factory,dependencies){const lastDependencies=useRef(),signal=useRef(0);return(lastDependencies.current===void 0||!isEqual(dependencies,lastDependencies.current))&&(signal.current+=1),lastDependencies.current=dependencies,useMemo(factory,[signal.current])}function isEqual(one,another){return one.length===another.length&&one.every((value,index)=>isDeepEqual(value,another[index]))}/*! 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 */export{useDeepMemo};
@@ -1 +0,0 @@
1
- /*! VefFramework version: 1.0.122, build time: 2025-03-11T09:32:18.065Z, made by Venus. */import{isDeepEqual}from"@vef-framework/shared";import{useRef}from"react";function useDeepSelector(selector){const prevSelectedState=useRef();return state=>{const nextSelectedState=selector(state);return isDeepEqual(prevSelectedState.current,nextSelectedState)?prevSelectedState.current:prevSelectedState.current=nextSelectedState}}/*! 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 */export{useDeepSelector};
@@ -1 +0,0 @@
1
- /*! VefFramework version: 1.0.122, build time: 2025-03-11T09:32:18.065Z, made by Venus. */import{useApiContext}from"@vef-framework/core";import{isFunction}from"@vef-framework/shared";import{useUnmount}from"ahooks";import{useId}from"react";import{useShallowMemo}from"./use-shallow-memo.js";function useApi(missingOptionValues,{fallbackOptionsApi,fallbackOptionsApiParams,valuesKey,resolveFallbackOptions},stubQueryApi,asyncFnQueryApi){const uniqueId=useId();return useShallowMemo(()=>{if(missingOptionValues.length>0){if(isFunction(resolveFallbackOptions))return[asyncFnQueryApi,{key:uniqueId,args:[missingOptionValues],fn:resolveFallbackOptions},{keepPreviousData:!0}];if(fallbackOptionsApi){const params={...fallbackOptionsApiParams,[valuesKey??"ids"]:missingOptionValues};return[fallbackOptionsApi,params,{keepPreviousData:!0}]}}return[stubQueryApi,[],{keepPreviousData:!0,initialData:[]}]},[resolveFallbackOptions,fallbackOptionsApi,stubQueryApi,uniqueId,missingOptionValues,asyncFnQueryApi,fallbackOptionsApiParams,valuesKey])}function useFallbackOptions(missingOptionValues,{fallbackOptionsApi,fallbackOptionsApiParams,valuesKey,resolveFallbackOptions}){const{useApiQuery,stubQueryApi,asyncFnQueryApi}=useApiContext(),[api,params,options]=useApi(missingOptionValues,{fallbackOptionsApi,fallbackOptionsApiParams,valuesKey,resolveFallbackOptions},stubQueryApi,asyncFnQueryApi),result=useApiQuery(api,params,options);return useUnmount(()=>{Object.is(api,stubQueryApi)&&stubQueryApi.removeQueries(params),Object.is(api,asyncFnQueryApi)&&asyncFnQueryApi.removeQueries(params)}),result}/*! 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 */export{useFallbackOptions};
@@ -1 +0,0 @@
1
- /*! VefFramework version: 1.0.122, build time: 2025-03-11T09:32:18.065Z, made by Venus. */import{useCallback}from"react";import{useThemeTokens}from"./use-theme-tokens.js";function useGapSizeNormalizer(){const{paddingXS,paddingSM,padding,paddingMD,paddingLG}=useThemeTokens();return useCallback(gap=>gap==="tiny"?paddingXS:gap==="small"?paddingSM:gap==="medium"?padding:gap==="large"?paddingMD:gap==="huge"?paddingLG:gap,[paddingXS,paddingSM,padding,paddingMD,paddingLG])}/*! 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 */export{useGapSizeNormalizer};
@@ -1 +0,0 @@
1
- /*! VefFramework version: 1.0.122, build time: 2025-03-11T09:32:18.065Z, made by Venus. */import{useGapSizeNormalizer}from"./use-gap-size-normalizer.js";function useNormalizedGapSize(gap){return useGapSizeNormalizer()(gap)}/*! 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 */export{useNormalizedGapSize};
@@ -1 +0,0 @@
1
- /*! VefFramework version: 1.0.122, build time: 2025-03-11T09:32:18.065Z, made by Venus. */import{useMemo}from"react";function normalizeMenuItem(item){return item.type==="item"?{type:"item",key:item.key,label:item.label,disabled:item.disabled,icon:item.icon,extra:item.extra}:item.type==="submenu"?{type:"submenu",key:item.key,label:item.label,disabled:item.disabled,icon:item.icon,children:item.children.map(normalizeMenuItem)}:item.type==="group"?{type:"group",key:item.key,label:item.label,children:item.children.map(normalizeMenuItem)}:{type:"divider",key:item.key}}function useNormalizedMenuItems(items){return useMemo(()=>items.map(normalizeMenuItem),[items])}/*! 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 */export{normalizeMenuItem,useNormalizedMenuItems};