@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.
- package/cjs/index.cjs +107 -0
- package/cjs/lib.cjs +56 -0
- package/cjs/use-authorized-items.cjs +26 -0
- package/cjs/use-color-tokens.cjs +34 -0
- package/cjs/use-computed-action-buttons.cjs +45 -0
- package/cjs/use-computed-options.cjs +69 -0
- package/cjs/use-context-disabled.cjs +14 -0
- package/cjs/use-data-query.cjs +110 -0
- package/cjs/use-deep-callback.cjs +13 -0
- package/cjs/use-deep-memo.cjs +21 -0
- package/cjs/use-deep-selector.cjs +16 -0
- package/cjs/use-fallback-options.cjs +105 -0
- package/cjs/use-gap-size-normalizer.cjs +38 -0
- package/cjs/use-normalized-gap-size.cjs +12 -0
- package/cjs/use-normalized-menu-items.cjs +48 -0
- package/cjs/use-normalized-options.cjs +104 -0
- package/cjs/use-option-filter.cjs +20 -0
- package/cjs/use-remote-filter.cjs +39 -0
- package/cjs/use-shallow-callback.cjs +13 -0
- package/cjs/use-shallow-memo.cjs +21 -0
- package/cjs/use-shallow-selector.cjs +16 -0
- package/cjs/use-singleton.cjs +16 -0
- package/cjs/use-theme-tokens.cjs +13 -0
- package/cjs/use-transient-store.cjs +34 -0
- package/cjs/use-window-size.cjs +21 -0
- package/esm/index.js +29 -0
- package/esm/lib.js +5 -0
- package/esm/use-authorized-items.js +24 -0
- package/esm/use-color-tokens.js +30 -0
- package/esm/use-computed-action-buttons.js +43 -0
- package/esm/use-computed-options.js +67 -0
- package/esm/use-context-disabled.js +11 -0
- package/esm/use-data-query.js +108 -0
- package/esm/use-deep-callback.js +11 -0
- package/esm/use-deep-memo.js +19 -0
- package/esm/use-deep-selector.js +14 -0
- package/esm/use-fallback-options.js +103 -0
- package/esm/use-gap-size-normalizer.js +36 -0
- package/esm/use-normalized-gap-size.js +10 -0
- package/esm/use-normalized-menu-items.js +45 -0
- package/esm/use-normalized-options.js +102 -0
- package/esm/use-option-filter.js +18 -0
- package/esm/use-remote-filter.js +37 -0
- package/esm/use-shallow-callback.js +11 -0
- package/esm/use-shallow-memo.js +19 -0
- package/esm/use-shallow-selector.js +14 -0
- package/esm/use-singleton.js +14 -0
- package/esm/use-theme-tokens.js +11 -0
- package/esm/use-transient-store.js +32 -0
- package/esm/use-window-size.js +19 -0
- package/package.json +9 -8
- package/es/index.js +0 -1
- package/es/lib.js +0 -1
- package/es/use-authorized-items.js +0 -1
- package/es/use-color-tokens.js +0 -1
- package/es/use-computed-action-buttons.js +0 -1
- package/es/use-computed-options.js +0 -1
- package/es/use-context-disabled.js +0 -1
- package/es/use-data-query.js +0 -1
- package/es/use-deep-callback.js +0 -1
- package/es/use-deep-memo.js +0 -1
- package/es/use-deep-selector.js +0 -1
- package/es/use-fallback-options.js +0 -1
- package/es/use-gap-size-normalizer.js +0 -1
- package/es/use-normalized-gap-size.js +0 -1
- package/es/use-normalized-menu-items.js +0 -1
- package/es/use-normalized-options.js +0 -1
- package/es/use-option-filter.js +0 -1
- package/es/use-remote-filter.js +0 -1
- package/es/use-shallow-callback.js +0 -1
- package/es/use-shallow-memo.js +0 -1
- package/es/use-shallow-selector.js +0 -1
- package/es/use-singleton.js +0 -1
- package/es/use-theme-tokens.js +0 -1
- package/es/use-transient-store.js +0 -1
- package/es/use-window-size.js +0 -1
- package/lib/index.cjs +0 -1
- package/lib/lib.cjs +0 -1
- package/lib/use-authorized-items.cjs +0 -1
- package/lib/use-color-tokens.cjs +0 -1
- package/lib/use-computed-action-buttons.cjs +0 -1
- package/lib/use-computed-options.cjs +0 -1
- package/lib/use-context-disabled.cjs +0 -1
- package/lib/use-data-query.cjs +0 -1
- package/lib/use-deep-callback.cjs +0 -1
- package/lib/use-deep-memo.cjs +0 -1
- package/lib/use-deep-selector.cjs +0 -1
- package/lib/use-fallback-options.cjs +0 -1
- package/lib/use-gap-size-normalizer.cjs +0 -1
- package/lib/use-normalized-gap-size.cjs +0 -1
- package/lib/use-normalized-menu-items.cjs +0 -1
- package/lib/use-normalized-options.cjs +0 -1
- package/lib/use-option-filter.cjs +0 -1
- package/lib/use-remote-filter.cjs +0 -1
- package/lib/use-shallow-callback.cjs +0 -1
- package/lib/use-shallow-memo.cjs +0 -1
- package/lib/use-shallow-selector.cjs +0 -1
- package/lib/use-singleton.cjs +0 -1
- package/lib/use-theme-tokens.cjs +0 -1
- package/lib/use-transient-store.cjs +0 -1
- package/lib/use-window-size.cjs +0 -1
package/cjs/index.cjs
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
require('./lib.cjs');
|
|
5
|
+
var useAuthorizedItems = require('./use-authorized-items.cjs');
|
|
6
|
+
var useColorTokens = require('./use-color-tokens.cjs');
|
|
7
|
+
var useComputedActionButtons = require('./use-computed-action-buttons.cjs');
|
|
8
|
+
var useComputedOptions = require('./use-computed-options.cjs');
|
|
9
|
+
var useContextDisabled = require('./use-context-disabled.cjs');
|
|
10
|
+
var useDataQuery = require('./use-data-query.cjs');
|
|
11
|
+
var useDeepCallback = require('./use-deep-callback.cjs');
|
|
12
|
+
var useDeepMemo = require('./use-deep-memo.cjs');
|
|
13
|
+
var useDeepSelector = require('./use-deep-selector.cjs');
|
|
14
|
+
var useFallbackOptions = require('./use-fallback-options.cjs');
|
|
15
|
+
var useGapSizeNormalizer = require('./use-gap-size-normalizer.cjs');
|
|
16
|
+
var useNormalizedGapSize = require('./use-normalized-gap-size.cjs');
|
|
17
|
+
var useNormalizedMenuItems = require('./use-normalized-menu-items.cjs');
|
|
18
|
+
var useNormalizedOptions = require('./use-normalized-options.cjs');
|
|
19
|
+
var useOptionFilter = require('./use-option-filter.cjs');
|
|
20
|
+
var useRemoteFilter = require('./use-remote-filter.cjs');
|
|
21
|
+
var useShallowCallback = require('./use-shallow-callback.cjs');
|
|
22
|
+
var useShallowMemo = require('./use-shallow-memo.cjs');
|
|
23
|
+
var useShallowSelector = require('./use-shallow-selector.cjs');
|
|
24
|
+
var useSingleton = require('./use-singleton.cjs');
|
|
25
|
+
var useThemeTokens = require('./use-theme-tokens.cjs');
|
|
26
|
+
var useTransientStore = require('./use-transient-store.cjs');
|
|
27
|
+
var useWindowSize = require('./use-window-size.cjs');
|
|
28
|
+
var usehooks = require('@uidotdev/usehooks');
|
|
29
|
+
var ahooks = require('ahooks');
|
|
30
|
+
|
|
31
|
+
"use strict";
|
|
32
|
+
|
|
33
|
+
exports.useAuthorizedItems = useAuthorizedItems.useAuthorizedItems;
|
|
34
|
+
exports.useColorTokens = useColorTokens.useColorTokens;
|
|
35
|
+
exports.useDefaultColorTokens = useColorTokens.useDefaultColorTokens;
|
|
36
|
+
exports.useSemanticColorTokens = useColorTokens.useSemanticColorTokens;
|
|
37
|
+
exports.useComputedActionButtons = useComputedActionButtons.useComputedActionButtons;
|
|
38
|
+
exports.useComputedOptions = useComputedOptions.useComputedOptions;
|
|
39
|
+
exports.DisabledContextProvider = useContextDisabled.DisabledContextProvider;
|
|
40
|
+
exports.useContextDisabled = useContextDisabled.useContextDisabled;
|
|
41
|
+
exports.useDataQuery = useDataQuery.useDataQuery;
|
|
42
|
+
exports.useDeepCallback = useDeepCallback.useDeepCallback;
|
|
43
|
+
exports.useDeepMemo = useDeepMemo.useDeepMemo;
|
|
44
|
+
exports.useDeepSelector = useDeepSelector.useDeepSelector;
|
|
45
|
+
exports.useFallbackOptions = useFallbackOptions.useFallbackOptions;
|
|
46
|
+
exports.useGapSizeNormalizer = useGapSizeNormalizer.useGapSizeNormalizer;
|
|
47
|
+
exports.useNormalizedGapSize = useNormalizedGapSize.useNormalizedGapSize;
|
|
48
|
+
exports.normalizeMenuItem = useNormalizedMenuItems.normalizeMenuItem;
|
|
49
|
+
exports.useNormalizedMenuItems = useNormalizedMenuItems.useNormalizedMenuItems;
|
|
50
|
+
exports.useNormalizedDataOptions = useNormalizedOptions.useNormalizedDataOptions;
|
|
51
|
+
exports.useOptionFilter = useOptionFilter.useOptionFilter;
|
|
52
|
+
exports.useRemoteFilter = useRemoteFilter.useRemoteFilter;
|
|
53
|
+
exports.useShallowCallback = useShallowCallback.useShallowCallback;
|
|
54
|
+
exports.useShallowMemo = useShallowMemo.useShallowMemo;
|
|
55
|
+
exports.useShallowSelector = useShallowSelector.useShallowSelector;
|
|
56
|
+
exports.useSingleton = useSingleton.useSingleton;
|
|
57
|
+
exports.useThemeTokens = useThemeTokens.useThemeTokens;
|
|
58
|
+
exports.useTransientStore = useTransientStore.useTransientStore;
|
|
59
|
+
exports.useWindowSize = useWindowSize.useWindowSize;
|
|
60
|
+
Object.defineProperty(exports, "useClickAway", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () { return usehooks.useClickAway; }
|
|
63
|
+
});
|
|
64
|
+
Object.defineProperty(exports, "useMeasure", {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
get: function () { return usehooks.useMeasure; }
|
|
67
|
+
});
|
|
68
|
+
Object.defineProperty(exports, "useDeepEffect", {
|
|
69
|
+
enumerable: true,
|
|
70
|
+
get: function () { return ahooks.useDeepCompareEffect; }
|
|
71
|
+
});
|
|
72
|
+
Object.defineProperty(exports, "useDeepLayoutEffect", {
|
|
73
|
+
enumerable: true,
|
|
74
|
+
get: function () { return ahooks.useDeepCompareLayoutEffect; }
|
|
75
|
+
});
|
|
76
|
+
Object.defineProperty(exports, "useElementSize", {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
get: function () { return ahooks.useSize; }
|
|
79
|
+
});
|
|
80
|
+
Object.defineProperty(exports, "useEventListener", {
|
|
81
|
+
enumerable: true,
|
|
82
|
+
get: function () { return ahooks.useEventListener; }
|
|
83
|
+
});
|
|
84
|
+
Object.defineProperty(exports, "useKeyPress", {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
get: function () { return ahooks.useKeyPress; }
|
|
87
|
+
});
|
|
88
|
+
Object.defineProperty(exports, "useMount", {
|
|
89
|
+
enumerable: true,
|
|
90
|
+
get: function () { return ahooks.useMount; }
|
|
91
|
+
});
|
|
92
|
+
Object.defineProperty(exports, "useUnmount", {
|
|
93
|
+
enumerable: true,
|
|
94
|
+
get: function () { return ahooks.useUnmount; }
|
|
95
|
+
});
|
|
96
|
+
Object.defineProperty(exports, "useUpdateEffect", {
|
|
97
|
+
enumerable: true,
|
|
98
|
+
get: function () { return ahooks.useUpdateEffect; }
|
|
99
|
+
});
|
|
100
|
+
Object.defineProperty(exports, "useUpdateLayoutEffect", {
|
|
101
|
+
enumerable: true,
|
|
102
|
+
get: function () { return ahooks.useUpdateLayoutEffect; }
|
|
103
|
+
});
|
|
104
|
+
Object.defineProperty(exports, "useUpdater", {
|
|
105
|
+
enumerable: true,
|
|
106
|
+
get: function () { return ahooks.useUpdate; }
|
|
107
|
+
});
|
package/cjs/lib.cjs
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var usehooks = require('@uidotdev/usehooks');
|
|
5
|
+
var ahooks = require('ahooks');
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
|
|
9
|
+
Object.defineProperty(exports, "useClickAway", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () { return usehooks.useClickAway; }
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(exports, "useMeasure", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () { return usehooks.useMeasure; }
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "useDeepEffect", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () { return ahooks.useDeepCompareEffect; }
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(exports, "useDeepLayoutEffect", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () { return ahooks.useDeepCompareLayoutEffect; }
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(exports, "useElementSize", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () { return ahooks.useSize; }
|
|
28
|
+
});
|
|
29
|
+
Object.defineProperty(exports, "useEventListener", {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
get: function () { return ahooks.useEventListener; }
|
|
32
|
+
});
|
|
33
|
+
Object.defineProperty(exports, "useKeyPress", {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
get: function () { return ahooks.useKeyPress; }
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(exports, "useMount", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: function () { return ahooks.useMount; }
|
|
40
|
+
});
|
|
41
|
+
Object.defineProperty(exports, "useUnmount", {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
get: function () { return ahooks.useUnmount; }
|
|
44
|
+
});
|
|
45
|
+
Object.defineProperty(exports, "useUpdateEffect", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
get: function () { return ahooks.useUpdateEffect; }
|
|
48
|
+
});
|
|
49
|
+
Object.defineProperty(exports, "useUpdateLayoutEffect", {
|
|
50
|
+
enumerable: true,
|
|
51
|
+
get: function () { return ahooks.useUpdateLayoutEffect; }
|
|
52
|
+
});
|
|
53
|
+
Object.defineProperty(exports, "useUpdater", {
|
|
54
|
+
enumerable: true,
|
|
55
|
+
get: function () { return ahooks.useUpdate; }
|
|
56
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var core = require('@vef-framework/core');
|
|
5
|
+
var react = require('react');
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
function useAuthorizedItems(items) {
|
|
9
|
+
const { checkPermission } = core.useAuthContext();
|
|
10
|
+
return react.useMemo(
|
|
11
|
+
() => items?.filter((item) => {
|
|
12
|
+
const { permissions } = item;
|
|
13
|
+
if (!permissions) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
const checkMode = item.checkMode ?? "any";
|
|
17
|
+
if (checkMode === "any") {
|
|
18
|
+
return permissions.some((permission) => checkPermission(permission));
|
|
19
|
+
}
|
|
20
|
+
return permissions.every((permission) => checkPermission(permission));
|
|
21
|
+
}),
|
|
22
|
+
[items, checkPermission]
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
exports.useAuthorizedItems = useAuthorizedItems;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var shared = require('@vef-framework/shared');
|
|
5
|
+
var react = require('react');
|
|
6
|
+
var useThemeTokens = require('./use-theme-tokens.cjs');
|
|
7
|
+
|
|
8
|
+
"use strict";
|
|
9
|
+
function useDefaultColorTokens() {
|
|
10
|
+
const tokens = useThemeTokens.useThemeTokens();
|
|
11
|
+
return react.useMemo(() => shared.defaultColorTypes.reduce(
|
|
12
|
+
(map, color) => {
|
|
13
|
+
map.set(color, tokens[color]);
|
|
14
|
+
return map;
|
|
15
|
+
},
|
|
16
|
+
/* @__PURE__ */ new Map()
|
|
17
|
+
), [tokens]);
|
|
18
|
+
}
|
|
19
|
+
function useSemanticColorTokens() {
|
|
20
|
+
const tokens = useThemeTokens.useThemeTokens();
|
|
21
|
+
return react.useMemo(() => shared.semanticColorTypes.reduce((map, color) => {
|
|
22
|
+
map.set(color, tokens[`color${shared.capitalize(color)}`]);
|
|
23
|
+
return map;
|
|
24
|
+
}, /* @__PURE__ */ new Map()), [tokens]);
|
|
25
|
+
}
|
|
26
|
+
function useColorTokens() {
|
|
27
|
+
const defaultColorTokens = useDefaultColorTokens();
|
|
28
|
+
const semanticColorTokens = useSemanticColorTokens();
|
|
29
|
+
return react.useMemo(() => new Map([...defaultColorTokens, ...semanticColorTokens]), [defaultColorTokens, semanticColorTokens]);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
exports.useColorTokens = useColorTokens;
|
|
33
|
+
exports.useDefaultColorTokens = useDefaultColorTokens;
|
|
34
|
+
exports.useSemanticColorTokens = useSemanticColorTokens;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var shared = require('@vef-framework/shared');
|
|
5
|
+
var react = require('react');
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
function useComputedActionButtons(buttons, context) {
|
|
9
|
+
return react.useMemo(() => buttons.filter((button) => {
|
|
10
|
+
const { show } = button;
|
|
11
|
+
if (shared.isFunction(show)) {
|
|
12
|
+
return show(context);
|
|
13
|
+
}
|
|
14
|
+
return show ?? true;
|
|
15
|
+
}).map((button) => {
|
|
16
|
+
const {
|
|
17
|
+
disabled,
|
|
18
|
+
requireConfirmation,
|
|
19
|
+
confirmationMode,
|
|
20
|
+
confirmationTitle,
|
|
21
|
+
confirmationContent,
|
|
22
|
+
...rest
|
|
23
|
+
} = button;
|
|
24
|
+
const computedButton = {
|
|
25
|
+
...rest,
|
|
26
|
+
disabled: shared.isFunction(disabled) ? disabled(context) : disabled ?? false,
|
|
27
|
+
requireConfirmation: shared.isFunction(requireConfirmation) ? requireConfirmation(context) : requireConfirmation ?? false,
|
|
28
|
+
confirmationMode: shared.isFunction(confirmationMode) ? confirmationMode(context) : confirmationMode ?? "simple",
|
|
29
|
+
confirmationTitle: shared.isFunction(confirmationTitle) ? confirmationTitle(context) : confirmationTitle ?? shared.defaultMessageTitle,
|
|
30
|
+
confirmationContent: shared.isFunction(confirmationContent) ? confirmationContent(context) : confirmationContent ?? `确定要${rest.label}吗?`
|
|
31
|
+
};
|
|
32
|
+
if (computedButton.requireConfirmation && !computedButton.confirmationMode) {
|
|
33
|
+
computedButton.confirmationMode = "simple";
|
|
34
|
+
}
|
|
35
|
+
if (computedButton.requireConfirmation && !computedButton.confirmationTitle) {
|
|
36
|
+
computedButton.confirmationTitle = shared.defaultMessageTitle;
|
|
37
|
+
}
|
|
38
|
+
if (computedButton.requireConfirmation && !computedButton.confirmationContent) {
|
|
39
|
+
computedButton.confirmationContent = `确定要${computedButton.label}吗?`;
|
|
40
|
+
}
|
|
41
|
+
return computedButton;
|
|
42
|
+
}), [buttons, context]);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
exports.useComputedActionButtons = useComputedActionButtons;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var useDataQuery = require('./use-data-query.cjs');
|
|
5
|
+
var useFallbackOptions = require('./use-fallback-options.cjs');
|
|
6
|
+
var useNormalizedOptions = require('./use-normalized-options.cjs');
|
|
7
|
+
var useRemoteFilter = require('./use-remote-filter.cjs');
|
|
8
|
+
|
|
9
|
+
"use strict";
|
|
10
|
+
function useComputedOptions({
|
|
11
|
+
labelKey,
|
|
12
|
+
valueKey,
|
|
13
|
+
descriptionKey,
|
|
14
|
+
childrenKey,
|
|
15
|
+
disabledKey,
|
|
16
|
+
defaultToFirst,
|
|
17
|
+
filterable = false,
|
|
18
|
+
filterFromRemote = false,
|
|
19
|
+
keywordKey = "keyword",
|
|
20
|
+
valuesKey = "ids",
|
|
21
|
+
fallbackOptionsApi,
|
|
22
|
+
fallbackOptionsApiParams,
|
|
23
|
+
resolveFallbackOptions,
|
|
24
|
+
isGrouped = false,
|
|
25
|
+
selectedOptionValues,
|
|
26
|
+
apiParams,
|
|
27
|
+
...queryConfig
|
|
28
|
+
}) {
|
|
29
|
+
const [mergedApiParams, onFilterKeywordChange] = useRemoteFilter.useRemoteFilter(filterable && filterFromRemote, apiParams, keywordKey);
|
|
30
|
+
const { data: options, isLoading } = useDataQuery.useDataQuery({
|
|
31
|
+
apiParams: mergedApiParams,
|
|
32
|
+
...queryConfig
|
|
33
|
+
});
|
|
34
|
+
const [normalizedOptions, missingOptionValues, defaultOption] = useNormalizedOptions.useNormalizedDataOptions(
|
|
35
|
+
options ?? [],
|
|
36
|
+
{
|
|
37
|
+
labelKey,
|
|
38
|
+
valueKey,
|
|
39
|
+
descriptionKey,
|
|
40
|
+
childrenKey,
|
|
41
|
+
disabledKey,
|
|
42
|
+
defaultToFirst
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
isGrouped,
|
|
46
|
+
parsePinyin: filterable && !filterFromRemote,
|
|
47
|
+
selectedOptionValues
|
|
48
|
+
}
|
|
49
|
+
);
|
|
50
|
+
const { data: fallbackOptions, isLoading: isFallbackOptionsLoading } = useFallbackOptions.useFallbackOptions(
|
|
51
|
+
missingOptionValues,
|
|
52
|
+
{
|
|
53
|
+
fallbackOptionsApi: fallbackOptionsApi ?? queryConfig.api,
|
|
54
|
+
fallbackOptionsApiParams,
|
|
55
|
+
valuesKey,
|
|
56
|
+
resolveFallbackOptions
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
return {
|
|
60
|
+
onFilterKeywordChange,
|
|
61
|
+
isLoading,
|
|
62
|
+
normalizedOptions,
|
|
63
|
+
defaultOption,
|
|
64
|
+
fallbackOptions,
|
|
65
|
+
isFallbackOptionsLoading
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
exports.useComputedOptions = useComputedOptions;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var react = require('react');
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
const DisabledContext = react.createContext(false);
|
|
8
|
+
function useContextDisabled() {
|
|
9
|
+
return react.useContext(DisabledContext);
|
|
10
|
+
}
|
|
11
|
+
const DisabledContextProvider = DisabledContext.Provider;
|
|
12
|
+
|
|
13
|
+
exports.DisabledContextProvider = DisabledContextProvider;
|
|
14
|
+
exports.useContextDisabled = useContextDisabled;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var core = require('@vef-framework/core');
|
|
5
|
+
var shared = require('@vef-framework/shared');
|
|
6
|
+
var ahooks = require('ahooks');
|
|
7
|
+
var react = require('react');
|
|
8
|
+
|
|
9
|
+
"use strict";
|
|
10
|
+
function useApi({
|
|
11
|
+
data,
|
|
12
|
+
dataDictionaryKey,
|
|
13
|
+
api,
|
|
14
|
+
apiParams,
|
|
15
|
+
apiEnabled,
|
|
16
|
+
staleTime,
|
|
17
|
+
keepPreviousData,
|
|
18
|
+
placeholderData
|
|
19
|
+
}, stubQueryApi, dataDictionaryApi) {
|
|
20
|
+
return react.useMemo(() => {
|
|
21
|
+
if (!shared.isNullish(data)) {
|
|
22
|
+
return [
|
|
23
|
+
stubQueryApi,
|
|
24
|
+
data,
|
|
25
|
+
{
|
|
26
|
+
keepPreviousData: true,
|
|
27
|
+
initialData: data
|
|
28
|
+
}
|
|
29
|
+
];
|
|
30
|
+
}
|
|
31
|
+
if (!shared.isNullish(dataDictionaryKey)) {
|
|
32
|
+
return [
|
|
33
|
+
dataDictionaryApi,
|
|
34
|
+
{
|
|
35
|
+
...apiParams,
|
|
36
|
+
key: dataDictionaryKey
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
enabled: apiEnabled ?? true,
|
|
40
|
+
staleTime,
|
|
41
|
+
keepPreviousData,
|
|
42
|
+
placeholderData
|
|
43
|
+
}
|
|
44
|
+
];
|
|
45
|
+
}
|
|
46
|
+
if (!shared.isNullish(api)) {
|
|
47
|
+
return [
|
|
48
|
+
api,
|
|
49
|
+
apiParams,
|
|
50
|
+
{
|
|
51
|
+
enabled: apiEnabled ?? true,
|
|
52
|
+
staleTime,
|
|
53
|
+
keepPreviousData,
|
|
54
|
+
placeholderData
|
|
55
|
+
}
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
return [
|
|
59
|
+
stubQueryApi,
|
|
60
|
+
[],
|
|
61
|
+
{
|
|
62
|
+
keepPreviousData: true,
|
|
63
|
+
initialData: []
|
|
64
|
+
}
|
|
65
|
+
];
|
|
66
|
+
}, [
|
|
67
|
+
data,
|
|
68
|
+
dataDictionaryKey,
|
|
69
|
+
api,
|
|
70
|
+
stubQueryApi,
|
|
71
|
+
dataDictionaryApi,
|
|
72
|
+
apiParams,
|
|
73
|
+
apiEnabled,
|
|
74
|
+
staleTime,
|
|
75
|
+
keepPreviousData,
|
|
76
|
+
placeholderData
|
|
77
|
+
]);
|
|
78
|
+
}
|
|
79
|
+
function useDataQuery({ onFetched, ...config }) {
|
|
80
|
+
const {
|
|
81
|
+
useApiQuery,
|
|
82
|
+
stubQueryApi,
|
|
83
|
+
dataDictionaryApi: dataDictionaryQueryApi
|
|
84
|
+
} = core.useApiContext();
|
|
85
|
+
const [api, args, options] = useApi(config, stubQueryApi, dataDictionaryQueryApi);
|
|
86
|
+
const result = useApiQuery(api, args, options);
|
|
87
|
+
ahooks.useUnmount(() => {
|
|
88
|
+
if (Object.is(api, stubQueryApi)) {
|
|
89
|
+
stubQueryApi.removeQueries(args);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
const {
|
|
93
|
+
isSuccess,
|
|
94
|
+
data: rawData,
|
|
95
|
+
...rest
|
|
96
|
+
} = result;
|
|
97
|
+
const data = react.useMemo(() => {
|
|
98
|
+
if (isSuccess && shared.isFunction(onFetched)) {
|
|
99
|
+
return onFetched(rawData);
|
|
100
|
+
}
|
|
101
|
+
return rawData;
|
|
102
|
+
}, [isSuccess, rawData, onFetched]);
|
|
103
|
+
return {
|
|
104
|
+
...rest,
|
|
105
|
+
isSuccess,
|
|
106
|
+
data
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
exports.useDataQuery = useDataQuery;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var useDeepMemo = require('./use-deep-memo.cjs');
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
function useDeepCallback(callback, dependencies) {
|
|
9
|
+
const memoizedDependencies = useDeepMemo.useDeepMemo(() => dependencies, dependencies);
|
|
10
|
+
return react.useCallback(callback, memoizedDependencies);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
exports.useDeepCallback = useDeepCallback;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var shared = require('@vef-framework/shared');
|
|
5
|
+
var react = require('react');
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
function useDeepMemo(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.isDeepEqual(value, another[index]));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
exports.useDeepMemo = useDeepMemo;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var shared = require('@vef-framework/shared');
|
|
5
|
+
var react = require('react');
|
|
6
|
+
|
|
7
|
+
"use strict";
|
|
8
|
+
function useDeepSelector(selector) {
|
|
9
|
+
const prevSelectedState = react.useRef();
|
|
10
|
+
return (state) => {
|
|
11
|
+
const nextSelectedState = selector(state);
|
|
12
|
+
return shared.isDeepEqual(prevSelectedState.current, nextSelectedState) ? prevSelectedState.current : prevSelectedState.current = nextSelectedState;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
exports.useDeepSelector = useDeepSelector;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var core = require('@vef-framework/core');
|
|
5
|
+
var shared = require('@vef-framework/shared');
|
|
6
|
+
var ahooks = require('ahooks');
|
|
7
|
+
var react = require('react');
|
|
8
|
+
var useShallowMemo = require('./use-shallow-memo.cjs');
|
|
9
|
+
|
|
10
|
+
"use strict";
|
|
11
|
+
function useApi(missingOptionValues, {
|
|
12
|
+
fallbackOptionsApi,
|
|
13
|
+
fallbackOptionsApiParams,
|
|
14
|
+
valuesKey,
|
|
15
|
+
resolveFallbackOptions
|
|
16
|
+
}, stubQueryApi, asyncFnQueryApi) {
|
|
17
|
+
const uniqueId = react.useId();
|
|
18
|
+
return useShallowMemo.useShallowMemo(() => {
|
|
19
|
+
if (missingOptionValues.length > 0) {
|
|
20
|
+
if (shared.isFunction(resolveFallbackOptions)) {
|
|
21
|
+
const params = {
|
|
22
|
+
key: uniqueId,
|
|
23
|
+
args: [missingOptionValues],
|
|
24
|
+
fn: resolveFallbackOptions
|
|
25
|
+
};
|
|
26
|
+
return [
|
|
27
|
+
asyncFnQueryApi,
|
|
28
|
+
params,
|
|
29
|
+
{
|
|
30
|
+
keepPreviousData: true
|
|
31
|
+
}
|
|
32
|
+
];
|
|
33
|
+
}
|
|
34
|
+
if (fallbackOptionsApi) {
|
|
35
|
+
const params = {
|
|
36
|
+
...fallbackOptionsApiParams,
|
|
37
|
+
[valuesKey ?? "ids"]: missingOptionValues
|
|
38
|
+
};
|
|
39
|
+
return [
|
|
40
|
+
fallbackOptionsApi,
|
|
41
|
+
params,
|
|
42
|
+
{
|
|
43
|
+
keepPreviousData: true
|
|
44
|
+
}
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return [
|
|
49
|
+
stubQueryApi,
|
|
50
|
+
[],
|
|
51
|
+
{
|
|
52
|
+
keepPreviousData: true,
|
|
53
|
+
initialData: []
|
|
54
|
+
}
|
|
55
|
+
];
|
|
56
|
+
}, [
|
|
57
|
+
resolveFallbackOptions,
|
|
58
|
+
fallbackOptionsApi,
|
|
59
|
+
stubQueryApi,
|
|
60
|
+
uniqueId,
|
|
61
|
+
missingOptionValues,
|
|
62
|
+
asyncFnQueryApi,
|
|
63
|
+
fallbackOptionsApiParams,
|
|
64
|
+
valuesKey
|
|
65
|
+
]);
|
|
66
|
+
}
|
|
67
|
+
function useFallbackOptions(missingOptionValues, {
|
|
68
|
+
fallbackOptionsApi,
|
|
69
|
+
fallbackOptionsApiParams,
|
|
70
|
+
valuesKey,
|
|
71
|
+
resolveFallbackOptions
|
|
72
|
+
}) {
|
|
73
|
+
const {
|
|
74
|
+
useApiQuery,
|
|
75
|
+
stubQueryApi,
|
|
76
|
+
asyncFnQueryApi
|
|
77
|
+
} = core.useApiContext();
|
|
78
|
+
const [
|
|
79
|
+
api,
|
|
80
|
+
params,
|
|
81
|
+
options
|
|
82
|
+
] = useApi(
|
|
83
|
+
missingOptionValues,
|
|
84
|
+
{
|
|
85
|
+
fallbackOptionsApi,
|
|
86
|
+
fallbackOptionsApiParams,
|
|
87
|
+
valuesKey,
|
|
88
|
+
resolveFallbackOptions
|
|
89
|
+
},
|
|
90
|
+
stubQueryApi,
|
|
91
|
+
asyncFnQueryApi
|
|
92
|
+
);
|
|
93
|
+
const result = useApiQuery(api, params, options);
|
|
94
|
+
ahooks.useUnmount(() => {
|
|
95
|
+
if (Object.is(api, stubQueryApi)) {
|
|
96
|
+
stubQueryApi.removeQueries(params);
|
|
97
|
+
}
|
|
98
|
+
if (Object.is(api, asyncFnQueryApi)) {
|
|
99
|
+
asyncFnQueryApi.removeQueries(params);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
exports.useFallbackOptions = useFallbackOptions;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use strict';
|
|
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;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use strict';
|
|
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;
|