@antdv-vue/pro-utils 0.0.0-stage → 2.1.1
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/CHANGELOG.md +123 -0
- package/README.md +80 -2
- package/dist/autoFocusToFirstChild/index.d.ts +9 -0
- package/dist/autoFocusToFirstChild/index.js +36 -0
- package/dist/childrenToArray/index.d.ts +7 -0
- package/dist/childrenToArray/index.js +8 -0
- package/dist/components/CopyToClipboard/copy/index.d.ts +10 -0
- package/dist/components/CopyToClipboard/copy/index.js +84 -0
- package/dist/components/CopyToClipboard/copy/toggle-selection.d.ts +4 -0
- package/dist/components/CopyToClipboard/copy/toggle-selection.js +27 -0
- package/dist/components/CopyToClipboard/index.d.ts +14 -0
- package/dist/components/CopyToClipboard/index.js +13 -0
- package/dist/components/Draggable/Draggable.d.ts +62 -0
- package/dist/components/Draggable/Draggable.js +162 -0
- package/dist/components/Draggable/DraggableCore.d.ts +40 -0
- package/dist/components/Draggable/DraggableCore.js +149 -0
- package/dist/components/Draggable/index.d.ts +4 -0
- package/dist/components/Draggable/index.js +3 -0
- package/dist/components/Draggable/types.d.ts +30 -0
- package/dist/components/Draggable/types.js +1 -0
- package/dist/components/Draggable/utils/domFns.d.ts +36 -0
- package/dist/components/Draggable/utils/domFns.js +165 -0
- package/dist/components/Draggable/utils/getPrefix.d.ts +6 -0
- package/dist/components/Draggable/utils/getPrefix.js +31 -0
- package/dist/components/Draggable/utils/positionFns.d.ts +13 -0
- package/dist/components/Draggable/utils/positionFns.js +96 -0
- package/dist/components/Draggable/utils/shims.d.ts +7 -0
- package/dist/components/Draggable/utils/shims.js +19 -0
- package/dist/components/DropdownFooter/index.d.ts +20 -0
- package/dist/components/DropdownFooter/index.js +80 -0
- package/dist/components/DropdownFooter/style/index.d.ts +8 -0
- package/dist/components/DropdownFooter/style/index.js +18 -0
- package/dist/components/ErrorBoundary/index.d.ts +25 -0
- package/dist/components/ErrorBoundary/index.js +65 -0
- package/dist/components/FieldLabel/index.d.ts +31 -0
- package/dist/components/FieldLabel/index.js +212 -0
- package/dist/components/FieldLabel/style/index.d.ts +8 -0
- package/dist/components/FieldLabel/style/index.js +146 -0
- package/dist/components/FilterDropdown/index.d.ts +38 -0
- package/dist/components/FilterDropdown/index.js +91 -0
- package/dist/components/FilterDropdown/style/index.d.ts +8 -0
- package/dist/components/FilterDropdown/style/index.js +21 -0
- package/dist/components/FormItem/FormItemInput.d.ts +34 -0
- package/dist/components/FormItem/FormItemInput.js +163 -0
- package/dist/components/FormItem/ItemHolder.d.ts +58 -0
- package/dist/components/FormItem/ItemHolder.js +289 -0
- package/dist/components/FormItem/index.d.ts +64 -0
- package/dist/components/FormItem/index.js +591 -0
- package/dist/components/FormList/Field.d.ts +29 -0
- package/dist/components/FormList/Field.js +106 -0
- package/dist/components/FormList/FieldContext.d.ts +15 -0
- package/dist/components/FormList/FieldContext.js +11 -0
- package/dist/components/FormList/InternalField.d.ts +51 -0
- package/dist/components/FormList/InternalField.js +149 -0
- package/dist/components/FormList/ListContext.d.ts +12 -0
- package/dist/components/FormList/ListContext.js +11 -0
- package/dist/components/FormList/index.d.ts +36 -0
- package/dist/components/FormList/index.js +145 -0
- package/dist/components/FormList/interface.d.ts +9 -0
- package/dist/components/FormList/interface.js +1 -0
- package/dist/components/FormList/namePathType.d.ts +9 -0
- package/dist/components/FormList/namePathType.js +1 -0
- package/dist/components/FormList/utils/index.d.ts +15 -0
- package/dist/components/FormList/utils/index.js +37 -0
- package/dist/components/InlineErrorFormItem/InlineErrorFormItemPopover.d.ts +21 -0
- package/dist/components/InlineErrorFormItem/InlineErrorFormItemPopover.js +95 -0
- package/dist/components/InlineErrorFormItem/index.d.ts +14 -0
- package/dist/components/InlineErrorFormItem/index.js +44 -0
- package/dist/components/InlineErrorFormItem/style/index.d.ts +8 -0
- package/dist/components/InlineErrorFormItem/style/index.js +46 -0
- package/dist/components/LabelIconTip/index.d.ts +16 -0
- package/dist/components/LabelIconTip/index.js +79 -0
- package/dist/components/LabelIconTip/style/index.d.ts +8 -0
- package/dist/components/LabelIconTip/style/index.js +38 -0
- package/dist/components/ProFormContext/index.d.ts +51 -0
- package/dist/components/ProFormContext/index.js +11 -0
- package/dist/conversionMomentValue/index.d.ts +48 -0
- package/dist/conversionMomentValue/index.js +103 -0
- package/dist/dateArrayFormatter/index.d.ts +14 -0
- package/dist/dateArrayFormatter/index.js +38 -0
- package/dist/deepMerge/index.d.ts +4 -0
- package/dist/deepMerge/index.js +17 -0
- package/dist/genCopyable/index.d.ts +27 -0
- package/dist/genCopyable/index.js +82 -0
- package/dist/getFieldPropsOrFormItemProps/index.d.ts +18 -0
- package/dist/getFieldPropsOrFormItemProps/index.js +15 -0
- package/dist/getSlot/index.d.ts +8 -0
- package/dist/getSlot/index.js +11 -0
- package/dist/hooks/index.d.ts +9 -0
- package/dist/hooks/index.js +9 -0
- package/dist/hooks/useDebounceFn/index.d.ts +12 -0
- package/dist/hooks/useDebounceFn/index.js +34 -0
- package/dist/hooks/useDebounceValue/index.d.ts +12 -0
- package/dist/hooks/useDebounceValue/index.js +21 -0
- package/dist/hooks/useDocumentTitle/index.d.ts +10 -0
- package/dist/hooks/useDocumentTitle/index.js +12 -0
- package/dist/hooks/useEffect/index.d.ts +6 -0
- package/dist/hooks/useEffect/index.js +17 -0
- package/dist/hooks/useFetchData/index.d.ts +12 -0
- package/dist/hooks/useFetchData/index.js +35 -0
- package/dist/hooks/useLayoutEffect/index.d.ts +6 -0
- package/dist/hooks/useLayoutEffect/index.js +21 -0
- package/dist/hooks/useMemo/index.d.ts +6 -0
- package/dist/hooks/useMemo/index.js +13 -0
- package/dist/hooks/useState/index.d.ts +6 -0
- package/dist/hooks/useState/index.js +11 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.js +58 -0
- package/dist/isBrowser/index.d.ts +4 -0
- package/dist/isBrowser/index.js +8 -0
- package/dist/isDropdownValueType/index.d.ts +4 -0
- package/dist/isDropdownValueType/index.js +8 -0
- package/dist/isImg/index.d.ts +5 -0
- package/dist/isImg/index.js +7 -0
- package/dist/isNil/index.d.ts +4 -0
- package/dist/isNil/index.js +6 -0
- package/dist/isUrl/index.d.ts +9 -0
- package/dist/isUrl/index.js +17 -0
- package/dist/merge/index.d.ts +9 -0
- package/dist/merge/index.js +20 -0
- package/dist/nanoid/index.d.ts +9 -0
- package/dist/nanoid/index.js +25 -0
- package/dist/normalizeProps/index.d.ts +6 -0
- package/dist/normalizeProps/index.js +6 -0
- package/dist/omitBoolean/index.d.ts +9 -0
- package/dist/omitBoolean/index.js +11 -0
- package/dist/omitUndefined/index.d.ts +5 -0
- package/dist/omitUndefined/index.js +11 -0
- package/dist/omitUndefinedAndEmptyArr/index.d.ts +4 -0
- package/dist/omitUndefinedAndEmptyArr/index.js +12 -0
- package/dist/parseValueToDay/index.d.ts +7 -0
- package/dist/parseValueToDay/index.js +21 -0
- package/dist/pickProFormItemProps/index.d.ts +34 -0
- package/dist/pickProFormItemProps/index.js +42 -0
- package/dist/pickProProps/index.d.ts +4 -0
- package/dist/pickProProps/index.js +14 -0
- package/dist/pro-utils.esm.js +3672 -0
- package/dist/proFieldParsingText/index.d.ts +25 -0
- package/dist/proFieldParsingText/index.js +100 -0
- package/dist/runFunction/index.d.ts +5 -0
- package/dist/runFunction/index.js +8 -0
- package/dist/stringify/index.d.ts +7 -0
- package/dist/stringify/index.js +10 -0
- package/dist/transformBooleanProps/index.d.ts +4 -0
- package/dist/transformBooleanProps/index.js +9 -0
- package/dist/transformKeySubmitValue/index.d.ts +24 -0
- package/dist/transformKeySubmitValue/index.js +200 -0
- package/dist/transformVueNodeType/index.d.ts +14 -0
- package/dist/transformVueNodeType/index.js +14 -0
- package/dist/typing.d.ts +562 -0
- package/dist/typing.js +1 -0
- package/dist/useEditableArray/components/CancelEditableAction.d.ts +47 -0
- package/dist/useEditableArray/components/CancelEditableAction.js +90 -0
- package/dist/useEditableArray/components/DeleteEditableAction.d.ts +33 -0
- package/dist/useEditableArray/components/DeleteEditableAction.js +63 -0
- package/dist/useEditableArray/components/SaveEditableAction.d.ts +33 -0
- package/dist/useEditableArray/components/SaveEditableAction.js +79 -0
- package/dist/useEditableArray/index.d.ts +66 -0
- package/dist/useEditableArray/index.js +584 -0
- package/dist/useEditableArray/typing.d.ts +130 -0
- package/dist/useEditableArray/typing.js +1 -0
- package/dist/useEditableMap/index.d.ts +32 -0
- package/dist/useEditableMap/index.js +147 -0
- package/dist/useMediaQuery/index.d.ts +44 -0
- package/dist/useMediaQuery/index.js +99 -0
- package/dist/useMediaQuery/query.d.ts +6 -0
- package/dist/useMediaQuery/query.js +17 -0
- package/dist/useMountMergeState/index.d.ts +11 -0
- package/dist/useMountMergeState/index.js +26 -0
- package/dist/usePrevious/index.d.ts +6 -0
- package/dist/usePrevious/index.js +11 -0
- package/dist/useRefFunction/index.d.ts +4 -0
- package/dist/useRefFunction/index.js +11 -0
- package/package.json +69 -3
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ProFieldValueEnumType, ProSchemaValueEnumMap, VueNode } from "../typing.js";
|
|
2
|
+
import { FunctionalComponent, VNode } from "vue";
|
|
3
|
+
import { BadgeProps, SelectValue } from "antdv-next";
|
|
4
|
+
|
|
5
|
+
//#region src/proFieldParsingText/index.d.ts
|
|
6
|
+
declare const ProFieldBadgeColor: FunctionalComponent<BadgeProps, {}, {
|
|
7
|
+
default?: () => VNode;
|
|
8
|
+
}>;
|
|
9
|
+
declare function objectToMap(value?: ProFieldValueEnumType): ProSchemaValueEnumMap;
|
|
10
|
+
/**
|
|
11
|
+
* 转化 text 和 valueEnum 通过 type 来添加 Status
|
|
12
|
+
*
|
|
13
|
+
* @param text
|
|
14
|
+
* @param valueEnumParams
|
|
15
|
+
* @param key
|
|
16
|
+
*/
|
|
17
|
+
declare function proFieldParsingText(text: SelectValue | {
|
|
18
|
+
title?: string;
|
|
19
|
+
value: any;
|
|
20
|
+
} | ({
|
|
21
|
+
title?: string;
|
|
22
|
+
value: any;
|
|
23
|
+
})[], valueEnumParams: ProFieldValueEnumType, key?: number | string): VueNode;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { ProFieldBadgeColor, objectToMap, proFieldParsingText };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { Fragment, createVNode, isVNode, mergeProps } from "vue";
|
|
2
|
+
import { Badge, Space } from "antdv-next";
|
|
3
|
+
//#region src/proFieldParsingText/index.tsx
|
|
4
|
+
/**
|
|
5
|
+
* 获取类型的 type
|
|
6
|
+
*
|
|
7
|
+
* @param obj
|
|
8
|
+
*/
|
|
9
|
+
function _isSlot(s) {
|
|
10
|
+
return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
|
|
11
|
+
}
|
|
12
|
+
function getType(obj) {
|
|
13
|
+
const type = Object.prototype.toString.call(obj)?.match(/^\[object (.*)\]$/)[1]?.toLowerCase();
|
|
14
|
+
if (type === "string" && typeof obj === "object") return "object";
|
|
15
|
+
if (obj === null) return "null";
|
|
16
|
+
if (obj === void 0) return "undefined";
|
|
17
|
+
return type;
|
|
18
|
+
}
|
|
19
|
+
const ProFieldBadgeColor = ({ color, ...rest }, { slots }) => createVNode(Badge, mergeProps(rest, {
|
|
20
|
+
"color": color,
|
|
21
|
+
"text": slots.default?.()
|
|
22
|
+
}), null);
|
|
23
|
+
function objectToMap(value) {
|
|
24
|
+
if (getType(value) === "map") return value;
|
|
25
|
+
return new Map(Object.entries(value || {}));
|
|
26
|
+
}
|
|
27
|
+
const TableStatus = {
|
|
28
|
+
Success: (props, { slots }) => createVNode(Badge, mergeProps(props, {
|
|
29
|
+
"status": "success",
|
|
30
|
+
"text": slots.default?.()
|
|
31
|
+
}), null),
|
|
32
|
+
Error: (props, { slots }) => createVNode(Badge, mergeProps(props, {
|
|
33
|
+
"status": "error",
|
|
34
|
+
"text": slots.default?.()
|
|
35
|
+
}), null),
|
|
36
|
+
Default: (props, { slots }) => createVNode(Badge, mergeProps(props, {
|
|
37
|
+
"status": "default",
|
|
38
|
+
"text": slots.default?.()
|
|
39
|
+
}), null),
|
|
40
|
+
Processing: (props, { slots }) => createVNode(Badge, mergeProps(props, {
|
|
41
|
+
"status": "processing",
|
|
42
|
+
"text": slots.default?.()
|
|
43
|
+
}), null),
|
|
44
|
+
Warning: (props, { slots }) => createVNode(Badge, mergeProps(props, {
|
|
45
|
+
"status": "warning",
|
|
46
|
+
"text": slots.default?.()
|
|
47
|
+
}), null),
|
|
48
|
+
success: (props, { slots }) => createVNode(Badge, mergeProps(props, {
|
|
49
|
+
"status": "success",
|
|
50
|
+
"text": slots.default?.()
|
|
51
|
+
}), null),
|
|
52
|
+
error: (props, { slots }) => createVNode(Badge, mergeProps(props, {
|
|
53
|
+
"status": "error",
|
|
54
|
+
"text": slots.default?.()
|
|
55
|
+
}), null),
|
|
56
|
+
default: (props, { slots }) => createVNode(Badge, mergeProps(props, {
|
|
57
|
+
"status": "default",
|
|
58
|
+
"text": slots.default?.()
|
|
59
|
+
}), null),
|
|
60
|
+
processing: (props, { slots }) => createVNode(Badge, mergeProps(props, {
|
|
61
|
+
"status": "processing",
|
|
62
|
+
"text": slots.default?.()
|
|
63
|
+
}), null),
|
|
64
|
+
warning: (props, { slots }) => createVNode(Badge, mergeProps(props, {
|
|
65
|
+
"status": "warning",
|
|
66
|
+
"text": slots.default?.()
|
|
67
|
+
}), null)
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* 转化 text 和 valueEnum 通过 type 来添加 Status
|
|
71
|
+
*
|
|
72
|
+
* @param text
|
|
73
|
+
* @param valueEnumParams
|
|
74
|
+
* @param key
|
|
75
|
+
*/
|
|
76
|
+
function proFieldParsingText(text, valueEnumParams, key) {
|
|
77
|
+
if (Array.isArray(text)) {
|
|
78
|
+
let _slot;
|
|
79
|
+
return createVNode(Space, {
|
|
80
|
+
"key": key,
|
|
81
|
+
"separator": ",",
|
|
82
|
+
"size": 2,
|
|
83
|
+
"wrap": true
|
|
84
|
+
}, _isSlot(_slot = text.map((value, index) => proFieldParsingText(value, valueEnumParams, index))) ? _slot : { default: () => [_slot] });
|
|
85
|
+
}
|
|
86
|
+
const valueEnum = objectToMap(valueEnumParams);
|
|
87
|
+
if (!valueEnum.has(text) && !valueEnum.has(`${text}`)) return text?.label || text?.title || text;
|
|
88
|
+
const domText = valueEnum.get(text) || valueEnum.get(`${text}`);
|
|
89
|
+
if (!domText) return createVNode(Fragment, { "key": key }, [text?.label || text?.title || text]);
|
|
90
|
+
const { status, color } = domText;
|
|
91
|
+
const Status = TableStatus[status || "Init"];
|
|
92
|
+
if (Status) return createVNode(Status, { "key": key }, { default: () => [domText.text] });
|
|
93
|
+
if (color) return createVNode(ProFieldBadgeColor, {
|
|
94
|
+
"key": key,
|
|
95
|
+
"color": color
|
|
96
|
+
}, { default: () => [domText.text] });
|
|
97
|
+
return createVNode(Fragment, { "key": key }, [domText.text || domText]);
|
|
98
|
+
}
|
|
99
|
+
//#endregion
|
|
100
|
+
export { ProFieldBadgeColor, objectToMap, proFieldParsingText };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as _$safe_stable_stringify0 from "safe-stable-stringify";
|
|
2
|
+
import { configure } from "safe-stable-stringify";
|
|
3
|
+
|
|
4
|
+
//#region src/stringify/index.d.ts
|
|
5
|
+
declare const stringify: typeof _$safe_stable_stringify0.default;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { configure, stringify };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { configure } from "safe-stable-stringify";
|
|
2
|
+
//#region src/stringify/index.ts
|
|
3
|
+
const stringify = configure({
|
|
4
|
+
bigint: true,
|
|
5
|
+
circularValue: "Magic circle!",
|
|
6
|
+
deterministic: false,
|
|
7
|
+
maximumDepth: 4
|
|
8
|
+
});
|
|
9
|
+
//#endregion
|
|
10
|
+
export { configure, stringify };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/transformBooleanProps/index.ts
|
|
2
|
+
function transformBooleanProps(booleanPropsKey, props) {
|
|
3
|
+
return booleanPropsKey.reduce((acc, key) => {
|
|
4
|
+
acc[key] = typeof props[key] === "string" ? true : props[key];
|
|
5
|
+
return acc;
|
|
6
|
+
}, {});
|
|
7
|
+
}
|
|
8
|
+
//#endregion
|
|
9
|
+
export { transformBooleanProps };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { SearchTransformKeyFn } from "../typing.js";
|
|
2
|
+
|
|
3
|
+
//#region src/transformKeySubmitValue/index.d.ts
|
|
4
|
+
type DataFormatMapType = Record<string, SearchTransformKeyFn | undefined>;
|
|
5
|
+
/**
|
|
6
|
+
* 暂时还不支持 Set和 Map 结构 判断是不是一个能遍历的对象
|
|
7
|
+
*
|
|
8
|
+
* @param itemValue
|
|
9
|
+
* @returns Boolean
|
|
10
|
+
*/
|
|
11
|
+
declare function isPlainObj(itemValue: any): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* 转换提交值中的键名
|
|
14
|
+
* 支持两种格式的转换配置:
|
|
15
|
+
* 1. 点号路径格式:'users.0.name' => 转换嵌套路径的值
|
|
16
|
+
* 2. 传统嵌套对象格式:{ users: { 0: { name: transformFn } } }
|
|
17
|
+
*
|
|
18
|
+
* @param values - 要转换的值对象
|
|
19
|
+
* @param dataFormatMapRaw - 转换配置映射
|
|
20
|
+
* @returns 转换后的值对象
|
|
21
|
+
*/
|
|
22
|
+
declare function transformKeySubmitValue<T extends Record<string, any> = any>(values: T, dataFormatMapRaw: Record<string, SearchTransformKeyFn | undefined | DataFormatMapType>): T;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { DataFormatMapType, isPlainObj, transformKeySubmitValue };
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { isNil } from "../isNil/index.js";
|
|
2
|
+
import { isVNode } from "vue";
|
|
3
|
+
import { get } from "@v-c/util";
|
|
4
|
+
import { cloneDeep } from "es-toolkit";
|
|
5
|
+
//#region src/transformKeySubmitValue/index.ts
|
|
6
|
+
/**
|
|
7
|
+
* 暂时还不支持 Set和 Map 结构 判断是不是一个能遍历的对象
|
|
8
|
+
*
|
|
9
|
+
* @param itemValue
|
|
10
|
+
* @returns Boolean
|
|
11
|
+
*/
|
|
12
|
+
function isPlainObj(itemValue) {
|
|
13
|
+
if (typeof itemValue !== "object") return false;
|
|
14
|
+
/** Null 也要处理,不然omit空会失效 */
|
|
15
|
+
if (itemValue === null) return true;
|
|
16
|
+
if (isVNode(itemValue)) return false;
|
|
17
|
+
if (itemValue.constructor === RegExp) return false;
|
|
18
|
+
if (itemValue instanceof Map) return false;
|
|
19
|
+
if (itemValue instanceof Set) return false;
|
|
20
|
+
if (itemValue instanceof HTMLElement) return false;
|
|
21
|
+
if (itemValue instanceof Blob) return false;
|
|
22
|
+
if (itemValue instanceof File) return false;
|
|
23
|
+
return !Array.isArray(itemValue);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 将点号路径字符串转换为路径数组
|
|
27
|
+
* 例如: 'users.0.name' => ['users', 0, 'name']
|
|
28
|
+
*
|
|
29
|
+
* @param dotPath - 点号分隔的路径字符串
|
|
30
|
+
* @returns 路径数组,数字会被转换为数字类型
|
|
31
|
+
*/
|
|
32
|
+
function parseDotPath(dotPath) {
|
|
33
|
+
return dotPath.split(".").map((segment) => {
|
|
34
|
+
return /^\d+$/.test(segment) ? Number.parseInt(segment, 10) : segment;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* 过滤掉空值的转换配置
|
|
39
|
+
*
|
|
40
|
+
* @param dataFormatMapRaw - 原始转换配置
|
|
41
|
+
* @returns 过滤后的转换配置
|
|
42
|
+
*/
|
|
43
|
+
function filterNilTransforms(dataFormatMapRaw) {
|
|
44
|
+
const filtered = {};
|
|
45
|
+
for (const key in dataFormatMapRaw) {
|
|
46
|
+
const value = dataFormatMapRaw[key];
|
|
47
|
+
if (!isNil(value)) filtered[key] = value;
|
|
48
|
+
}
|
|
49
|
+
return filtered;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* 将转换配置分为点号路径格式和传统嵌套对象格式
|
|
53
|
+
*
|
|
54
|
+
* @param dataFormatMapRaw - 原始转换配置
|
|
55
|
+
* @returns 包含两种格式转换配置的对象
|
|
56
|
+
*/
|
|
57
|
+
function separateTransformFormats(dataFormatMapRaw) {
|
|
58
|
+
const dotPathTransforms = {};
|
|
59
|
+
const objectTransforms = {};
|
|
60
|
+
for (const key in dataFormatMapRaw) {
|
|
61
|
+
const value = dataFormatMapRaw[key];
|
|
62
|
+
if (isNil(value)) continue;
|
|
63
|
+
if (key.includes(".")) dotPathTransforms[key] = value;
|
|
64
|
+
else objectTransforms[key] = value;
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
dotPathTransforms,
|
|
68
|
+
objectTransforms
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* 处理点号路径格式的转换
|
|
73
|
+
* 例如: 'users.0.name' => 转换 users[0].name 的值
|
|
74
|
+
*
|
|
75
|
+
* @param result - 要转换的数据对象
|
|
76
|
+
* @param dotPathTransforms - 点号路径转换配置
|
|
77
|
+
*/
|
|
78
|
+
function processDotPathTransforms(result, dotPathTransforms) {
|
|
79
|
+
for (const dotPath in dotPathTransforms) {
|
|
80
|
+
const transform = dotPathTransforms[dotPath];
|
|
81
|
+
if (typeof transform !== "function") continue;
|
|
82
|
+
const pathArray = parseDotPath(dotPath);
|
|
83
|
+
const currentValue = get(result, pathArray);
|
|
84
|
+
if (currentValue === void 0) continue;
|
|
85
|
+
const transformed = transform(currentValue, pathArray.map(String), result);
|
|
86
|
+
if (typeof transformed === "object" && transformed !== null && !Array.isArray(transformed)) {
|
|
87
|
+
const parentPath = pathArray.slice(0, -1);
|
|
88
|
+
const parentObj = parentPath.length > 0 ? get(result, parentPath) : result;
|
|
89
|
+
if (parentObj && typeof parentObj === "object") {
|
|
90
|
+
const keyToDelete = pathArray[pathArray.length - 1];
|
|
91
|
+
delete parentObj[keyToDelete];
|
|
92
|
+
Object.assign(parentObj, transformed);
|
|
93
|
+
}
|
|
94
|
+
} else {
|
|
95
|
+
let current = result;
|
|
96
|
+
for (let i = 0; i < pathArray.length - 1; i++) {
|
|
97
|
+
const key = pathArray[i];
|
|
98
|
+
if (current[key] === void 0) {
|
|
99
|
+
const nextKey = pathArray[i + 1];
|
|
100
|
+
current[key] = typeof nextKey === "number" ? [] : {};
|
|
101
|
+
}
|
|
102
|
+
current = current[key];
|
|
103
|
+
}
|
|
104
|
+
current[pathArray[pathArray.length - 1]] = transformed;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* 在嵌套转换配置中查找转换函数
|
|
110
|
+
*
|
|
111
|
+
* @param currentTransforms - 当前转换配置
|
|
112
|
+
* @param parentsKey - 父级路径
|
|
113
|
+
* @param entityKey - 当前实体键
|
|
114
|
+
* @returns 找到的转换函数或 undefined
|
|
115
|
+
*/
|
|
116
|
+
function findNestedTransformFunction(currentTransforms, parentsKey, entityKey) {
|
|
117
|
+
let nestedTransforms = currentTransforms;
|
|
118
|
+
for (const parentKey of parentsKey) {
|
|
119
|
+
const parentKeyStr = String(parentKey);
|
|
120
|
+
if (nestedTransforms && typeof nestedTransforms[parentKeyStr] === "object") nestedTransforms = nestedTransforms[parentKeyStr];
|
|
121
|
+
else {
|
|
122
|
+
nestedTransforms = null;
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (nestedTransforms && typeof nestedTransforms[entityKey] === "function") return nestedTransforms[entityKey];
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* 检查路径是否包含数组索引
|
|
130
|
+
*
|
|
131
|
+
* @param parentsKey - 父级路径数组
|
|
132
|
+
* @returns 如果包含数组索引返回 true
|
|
133
|
+
*/
|
|
134
|
+
function isInArrayPath(parentsKey) {
|
|
135
|
+
return parentsKey.some((key) => !Number.isNaN(Number(key)));
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* 递归处理嵌套对象转换(传统格式)
|
|
139
|
+
*
|
|
140
|
+
* @param tempValues - 要处理的值
|
|
141
|
+
* @param parentsKey - 父级路径
|
|
142
|
+
* @param currentTransforms - 当前转换配置
|
|
143
|
+
* @param rootMergeObjects - 存储需要在根级别合并的对象
|
|
144
|
+
* @param visited - 存储已经访问过的对象,防止循环引用
|
|
145
|
+
* @returns 处理后的结果
|
|
146
|
+
*/
|
|
147
|
+
function processNestedObjectTransforms(tempValues, parentsKey, currentTransforms, rootMergeObjects, visited) {
|
|
148
|
+
if (tempValues != null && typeof tempValues === "object") {
|
|
149
|
+
if (visited.has(tempValues)) return tempValues;
|
|
150
|
+
visited.add(tempValues);
|
|
151
|
+
}
|
|
152
|
+
const isArrayValues = Array.isArray(tempValues);
|
|
153
|
+
const tempResult = isArrayValues ? [] : {};
|
|
154
|
+
if (tempValues == null || tempValues === void 0) return tempResult;
|
|
155
|
+
const keysToProcess = isArrayValues ? tempValues.map((_, index) => index.toString()) : Object.keys(tempValues);
|
|
156
|
+
for (const entityKey of keysToProcess) {
|
|
157
|
+
const key = parentsKey ? [...parentsKey, entityKey] : [entityKey];
|
|
158
|
+
const itemValue = tempValues[entityKey];
|
|
159
|
+
let transformFunction = currentTransforms[entityKey];
|
|
160
|
+
if (!transformFunction && parentsKey) transformFunction = findNestedTransformFunction(currentTransforms, parentsKey, entityKey);
|
|
161
|
+
if (transformFunction && typeof transformFunction === "function") {
|
|
162
|
+
const transformed = transformFunction(itemValue, entityKey, tempValues);
|
|
163
|
+
if (typeof transformed === "object" && transformed !== null && !Array.isArray(transformed)) if (parentsKey ? isInArrayPath(parentsKey) : false) Object.assign(tempResult, transformed);
|
|
164
|
+
else rootMergeObjects.push(transformed);
|
|
165
|
+
else tempResult[entityKey] = transformed;
|
|
166
|
+
} else if (isPlainObj(itemValue) && !isNil(itemValue)) {
|
|
167
|
+
const nestedTransforms = currentTransforms[entityKey];
|
|
168
|
+
if (nestedTransforms && typeof nestedTransforms === "object") {
|
|
169
|
+
const nested = processNestedObjectTransforms(itemValue, key, nestedTransforms, rootMergeObjects, visited);
|
|
170
|
+
if (Object.keys(nested).length > 0) tempResult[entityKey] = nested;
|
|
171
|
+
} else tempResult[entityKey] = processNestedObjectTransforms(itemValue, key, currentTransforms, rootMergeObjects, visited);
|
|
172
|
+
} else if (!isNil(itemValue)) tempResult[entityKey] = itemValue;
|
|
173
|
+
}
|
|
174
|
+
return tempResult;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* 转换提交值中的键名
|
|
178
|
+
* 支持两种格式的转换配置:
|
|
179
|
+
* 1. 点号路径格式:'users.0.name' => 转换嵌套路径的值
|
|
180
|
+
* 2. 传统嵌套对象格式:{ users: { 0: { name: transformFn } } }
|
|
181
|
+
*
|
|
182
|
+
* @param values - 要转换的值对象
|
|
183
|
+
* @param dataFormatMapRaw - 转换配置映射
|
|
184
|
+
* @returns 转换后的值对象
|
|
185
|
+
*/
|
|
186
|
+
function transformKeySubmitValue(values, dataFormatMapRaw) {
|
|
187
|
+
const dataFormatMap = filterNilTransforms(dataFormatMapRaw);
|
|
188
|
+
if (Object.keys(dataFormatMap).length < 1) return values;
|
|
189
|
+
if (typeof window === "undefined") return values;
|
|
190
|
+
if (typeof values !== "object" || isNil(values) || values instanceof Blob) return values;
|
|
191
|
+
let result = cloneDeep(values);
|
|
192
|
+
const { dotPathTransforms, objectTransforms } = separateTransformFormats(dataFormatMapRaw);
|
|
193
|
+
processDotPathTransforms(result, dotPathTransforms);
|
|
194
|
+
const rootMergeObjects = [];
|
|
195
|
+
if (Object.keys(objectTransforms).length > 0) result = processNestedObjectTransforms(result, void 0, objectTransforms, rootMergeObjects, /* @__PURE__ */ new Set());
|
|
196
|
+
for (const obj of rootMergeObjects) Object.assign(result, obj);
|
|
197
|
+
return result;
|
|
198
|
+
}
|
|
199
|
+
//#endregion
|
|
200
|
+
export { isPlainObj, transformKeySubmitValue };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as _$vue from "vue";
|
|
2
|
+
import { VNode } from "vue";
|
|
3
|
+
import { VueNode } from "@v-c/util";
|
|
4
|
+
|
|
5
|
+
//#region src/transformVueNodeType/index.d.ts
|
|
6
|
+
declare function transformVueNodeType(vueNode: VueNode | (() => VueNode[])): string | number | true | VNode<_$vue.RendererNode, _$vue.RendererElement, {
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
}> | (string | number | boolean | VNode<_$vue.RendererNode, _$vue.RendererElement, {
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
}> | (string | number | boolean | VNode<_$vue.RendererNode, _$vue.RendererElement, {
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
}> | undefined)[] | undefined)[] | undefined;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { transformVueNodeType };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { h } from "vue";
|
|
2
|
+
//#region src/transformVueNodeType/index.ts
|
|
3
|
+
function transformVueNodeType(vueNode) {
|
|
4
|
+
if (vueNode) {
|
|
5
|
+
if (typeof vueNode === "function") return h(vueNode);
|
|
6
|
+
if (typeof vueNode === "string" || typeof vueNode === "boolean" || typeof vueNode === "number") return vueNode;
|
|
7
|
+
if (Array.isArray(vueNode)) return vueNode.filter((node) => node).map((node) => {
|
|
8
|
+
return transformVueNodeType(node);
|
|
9
|
+
}).filter(Boolean);
|
|
10
|
+
return h(vueNode);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { transformVueNodeType };
|