@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,106 @@
|
|
|
1
|
+
import { useProFormContextInject } from "../ProFormContext/index.js";
|
|
2
|
+
import { useFormFieldContextInject } from "./FieldContext.js";
|
|
3
|
+
import InternalField from "./InternalField.js";
|
|
4
|
+
import { useFormListContextInject } from "./ListContext.js";
|
|
5
|
+
import { computed, createVNode, defineComponent, mergeProps } from "vue";
|
|
6
|
+
import { getNamePath } from "antdv-next/dist/form/utils/valueUtil";
|
|
7
|
+
//#region src/components/FormList/Field.tsx
|
|
8
|
+
const FormListField = /* @__PURE__ */ defineComponent((props, { slots }) => {
|
|
9
|
+
const fieldContext = useFormFieldContextInject();
|
|
10
|
+
const listContext = useFormListContextInject();
|
|
11
|
+
const { formRef } = useProFormContextInject();
|
|
12
|
+
const namePath = computed(() => props.name !== void 0 ? getNamePath(props.name) : void 0);
|
|
13
|
+
return () => {
|
|
14
|
+
const { name, ...restProps } = props;
|
|
15
|
+
const isMergedListField = restProps.isListField ?? !!listContext;
|
|
16
|
+
let key = "keep";
|
|
17
|
+
if (!isMergedListField) key = `_${(namePath.value || []).join("_")}`;
|
|
18
|
+
return createVNode(InternalField, mergeProps({ "key": key }, restProps, {
|
|
19
|
+
"isListField": isMergedListField,
|
|
20
|
+
"name": namePath.value,
|
|
21
|
+
"fieldContext": Object.keys(fieldContext).length ? fieldContext : formRef?.value
|
|
22
|
+
}), slots);
|
|
23
|
+
};
|
|
24
|
+
}, {
|
|
25
|
+
props: {
|
|
26
|
+
dependencies: {
|
|
27
|
+
type: Array,
|
|
28
|
+
required: false
|
|
29
|
+
},
|
|
30
|
+
rules: {
|
|
31
|
+
type: Array,
|
|
32
|
+
required: false
|
|
33
|
+
},
|
|
34
|
+
messageVariables: {
|
|
35
|
+
type: Object,
|
|
36
|
+
required: false
|
|
37
|
+
},
|
|
38
|
+
initialValue: { required: false },
|
|
39
|
+
valuePropName: {
|
|
40
|
+
type: String,
|
|
41
|
+
required: false
|
|
42
|
+
},
|
|
43
|
+
validateTrigger: {
|
|
44
|
+
type: [
|
|
45
|
+
String,
|
|
46
|
+
Array,
|
|
47
|
+
Boolean
|
|
48
|
+
],
|
|
49
|
+
required: false,
|
|
50
|
+
default: void 0
|
|
51
|
+
},
|
|
52
|
+
getValueProps: {
|
|
53
|
+
type: Function,
|
|
54
|
+
required: false
|
|
55
|
+
},
|
|
56
|
+
getValueFromEvent: {
|
|
57
|
+
type: Function,
|
|
58
|
+
required: false
|
|
59
|
+
},
|
|
60
|
+
trigger: {
|
|
61
|
+
type: [String, Array],
|
|
62
|
+
required: false
|
|
63
|
+
},
|
|
64
|
+
isList: {
|
|
65
|
+
type: Boolean,
|
|
66
|
+
required: false,
|
|
67
|
+
default: void 0
|
|
68
|
+
},
|
|
69
|
+
isListField: {
|
|
70
|
+
type: Boolean,
|
|
71
|
+
required: false,
|
|
72
|
+
default: void 0
|
|
73
|
+
},
|
|
74
|
+
validateDebounce: {
|
|
75
|
+
type: Number,
|
|
76
|
+
required: false
|
|
77
|
+
},
|
|
78
|
+
validateFirst: {
|
|
79
|
+
type: [Boolean, String],
|
|
80
|
+
required: false,
|
|
81
|
+
default: void 0
|
|
82
|
+
},
|
|
83
|
+
normalize: {
|
|
84
|
+
type: Function,
|
|
85
|
+
required: false
|
|
86
|
+
},
|
|
87
|
+
preserve: {
|
|
88
|
+
type: Boolean,
|
|
89
|
+
required: false,
|
|
90
|
+
default: void 0
|
|
91
|
+
},
|
|
92
|
+
onReset: {
|
|
93
|
+
type: Function,
|
|
94
|
+
required: false
|
|
95
|
+
},
|
|
96
|
+
onMetaChange: {
|
|
97
|
+
type: Function,
|
|
98
|
+
required: false
|
|
99
|
+
},
|
|
100
|
+
name: { required: false }
|
|
101
|
+
},
|
|
102
|
+
name: "FormListField",
|
|
103
|
+
inheritAttrs: false
|
|
104
|
+
});
|
|
105
|
+
//#endregion
|
|
106
|
+
export { FormListField as default };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { InternalNamePath } from "./interface.js";
|
|
2
|
+
import { ComputedRef, InjectionKey } from "vue";
|
|
3
|
+
import { FormInstance } from "antdv-next";
|
|
4
|
+
|
|
5
|
+
//#region src/components/FormList/FieldContext.d.ts
|
|
6
|
+
type FieldContextProps = FormInstance & {
|
|
7
|
+
prefixName?: ComputedRef<InternalNamePath>;
|
|
8
|
+
el?: HTMLFormElement;
|
|
9
|
+
initialValue: any[];
|
|
10
|
+
};
|
|
11
|
+
declare const formFieldContextKey: InjectionKey<FieldContextProps>;
|
|
12
|
+
declare function useFormFieldContextProvider(props: FieldContextProps): void;
|
|
13
|
+
declare function useFormFieldContextInject(): FieldContextProps;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { FieldContextProps, formFieldContextKey, useFormFieldContextInject, useFormFieldContextProvider };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { inject, provide } from "vue";
|
|
2
|
+
//#region src/components/FormList/FieldContext.ts
|
|
3
|
+
const formFieldContextKey = Symbol("formFieldContext");
|
|
4
|
+
function useFormFieldContextProvider(props) {
|
|
5
|
+
return provide(formFieldContextKey, props);
|
|
6
|
+
}
|
|
7
|
+
function useFormFieldContextInject() {
|
|
8
|
+
return inject(formFieldContextKey, {});
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { formFieldContextKey, useFormFieldContextInject, useFormFieldContextProvider };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { InternalNamePath, NamePath as NamePath$1, Store as Store$1, StoreValue as StoreValue$1 } from "./interface.js";
|
|
2
|
+
import * as _$vue from "vue";
|
|
3
|
+
import { ComputedRef, SlotsType } from "vue";
|
|
4
|
+
import { FormInstance } from "antdv-next";
|
|
5
|
+
import { Meta, Rule, TriggerType } from "antdv-next/dist/form/types";
|
|
6
|
+
|
|
7
|
+
//#region src/components/FormList/InternalField.d.ts
|
|
8
|
+
type MetaEvent = Meta & {
|
|
9
|
+
destroy?: boolean;
|
|
10
|
+
};
|
|
11
|
+
interface InternalFieldProps {
|
|
12
|
+
dependencies?: NamePath$1<string | number | boolean>[];
|
|
13
|
+
name?: NamePath$1<string | number | boolean>;
|
|
14
|
+
rules?: Rule[];
|
|
15
|
+
messageVariables?: Record<string, string>;
|
|
16
|
+
initialValue?: any;
|
|
17
|
+
valuePropName?: 'checked' | 'value' | 'fileList';
|
|
18
|
+
validateTrigger?: string | string[] | false;
|
|
19
|
+
getValueProps?: (value: StoreValue$1) => Record<string, unknown>;
|
|
20
|
+
getValueFromEvent?: (...args: any[]) => StoreValue$1;
|
|
21
|
+
trigger?: TriggerType | TriggerType[];
|
|
22
|
+
/** @private Passed by Form.List props. Do not use since it will break by path check. */
|
|
23
|
+
isList?: boolean;
|
|
24
|
+
isListField?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Trigger will after configured milliseconds.
|
|
27
|
+
*/
|
|
28
|
+
validateDebounce?: number;
|
|
29
|
+
validateFirst?: boolean | 'parallel';
|
|
30
|
+
normalize?: (value: StoreValue$1, prevValue: StoreValue$1, allValues: Store$1) => StoreValue$1;
|
|
31
|
+
fieldContext?: FormInstance & {
|
|
32
|
+
prefixName?: ComputedRef<InternalNamePath>;
|
|
33
|
+
initialValue?: any[];
|
|
34
|
+
} | null;
|
|
35
|
+
preserve?: boolean;
|
|
36
|
+
onReset?: () => void;
|
|
37
|
+
onMetaChange?: (meta: MetaEvent) => void;
|
|
38
|
+
}
|
|
39
|
+
interface ChildProps {
|
|
40
|
+
value?: any[];
|
|
41
|
+
onChange?: (...restParms: any[]) => void;
|
|
42
|
+
[key: string]: any;
|
|
43
|
+
}
|
|
44
|
+
declare const InternalField: _$vue.DefineSetupFnComponent<InternalFieldProps, {}, SlotsType<{
|
|
45
|
+
default?: (control: ChildProps, meta: Meta, form?: ((FormInstance & {
|
|
46
|
+
prefixName?: ComputedRef<InternalNamePath>;
|
|
47
|
+
initialValue?: any[];
|
|
48
|
+
}) | null)) => any;
|
|
49
|
+
}>, InternalFieldProps & {}, _$vue.PublicProps>;
|
|
50
|
+
//#endregion
|
|
51
|
+
export { ChildProps, InternalFieldProps, MetaEvent, InternalField as default };
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { useProFormContextInject } from "../ProFormContext/index.js";
|
|
2
|
+
import { defaultGetValueFromEvent } from "./utils/index.js";
|
|
3
|
+
import { defineComponent } from "vue";
|
|
4
|
+
import { getNamePath, getValue, setValue } from "antdv-next/dist/form/utils/valueUtil";
|
|
5
|
+
import { useFormContext } from "antdv-next/dist/form/context";
|
|
6
|
+
//#region src/components/FormList/InternalField.tsx
|
|
7
|
+
const triggerKey = {
|
|
8
|
+
"change": "onChange",
|
|
9
|
+
"blur": "onBlur",
|
|
10
|
+
"focus": "onFocus"
|
|
11
|
+
};
|
|
12
|
+
const InternalField = /* @__PURE__ */ defineComponent((props, { slots }) => {
|
|
13
|
+
const { formRef } = useProFormContextInject();
|
|
14
|
+
const formContext = useFormContext();
|
|
15
|
+
const getNamePath$1 = () => {
|
|
16
|
+
const { name } = props;
|
|
17
|
+
return name !== void 0 ? [...props.fieldContext?.prefixName?.value || [], ...getNamePath(name)] : [];
|
|
18
|
+
};
|
|
19
|
+
const getFieldValue = (store) => {
|
|
20
|
+
const namePath = getNamePath$1();
|
|
21
|
+
return getValue(store || formContext.value.model, namePath);
|
|
22
|
+
};
|
|
23
|
+
if (props.initialValue !== void 0) {
|
|
24
|
+
const namePath = getNamePath$1();
|
|
25
|
+
if (namePath.length) {
|
|
26
|
+
if (getValue(formContext.value.model, namePath) === void 0 && namePath.length && formRef?.value) formRef.value.setFieldsValue(setValue(formContext.value.model, namePath, props.initialValue));
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const triggerFn = (...args) => {
|
|
30
|
+
const { getValueFromEvent, normalize, valuePropName = "value" } = props;
|
|
31
|
+
const value = getFieldValue();
|
|
32
|
+
let newValue;
|
|
33
|
+
const namePath = getNamePath$1();
|
|
34
|
+
if (getValueFromEvent) newValue = getValueFromEvent(...args);
|
|
35
|
+
else newValue = defaultGetValueFromEvent(valuePropName, ...args);
|
|
36
|
+
if (normalize) newValue = normalize(newValue, value, formContext.value.model);
|
|
37
|
+
if (newValue !== value && formRef?.value) formRef.value.setFieldValue(namePath, newValue);
|
|
38
|
+
};
|
|
39
|
+
const mergedGetValueProps = props.getValueProps || ((val) => {
|
|
40
|
+
const { valuePropName = "value" } = props;
|
|
41
|
+
return {
|
|
42
|
+
[valuePropName]: val,
|
|
43
|
+
[`onUpdate:${valuePropName}`]: triggerFn
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
return () => {
|
|
47
|
+
const { trigger = "change", fieldContext } = props;
|
|
48
|
+
const value = getFieldValue();
|
|
49
|
+
const meta = {
|
|
50
|
+
touched: false,
|
|
51
|
+
validated: false,
|
|
52
|
+
validating: false,
|
|
53
|
+
name: getNamePath$1(),
|
|
54
|
+
errors: [],
|
|
55
|
+
warnings: []
|
|
56
|
+
};
|
|
57
|
+
const control = { ...props.name !== void 0 ? mergedGetValueProps(value) : {} };
|
|
58
|
+
(Array.isArray(trigger) ? trigger : [trigger]).forEach((key) => {
|
|
59
|
+
control[triggerKey[key]] = triggerFn;
|
|
60
|
+
});
|
|
61
|
+
return slots.default?.(control, meta, fieldContext);
|
|
62
|
+
};
|
|
63
|
+
}, {
|
|
64
|
+
props: {
|
|
65
|
+
dependencies: {
|
|
66
|
+
type: Array,
|
|
67
|
+
required: false
|
|
68
|
+
},
|
|
69
|
+
name: { required: false },
|
|
70
|
+
rules: {
|
|
71
|
+
type: Array,
|
|
72
|
+
required: false
|
|
73
|
+
},
|
|
74
|
+
messageVariables: {
|
|
75
|
+
type: Object,
|
|
76
|
+
required: false
|
|
77
|
+
},
|
|
78
|
+
initialValue: { required: false },
|
|
79
|
+
valuePropName: {
|
|
80
|
+
type: String,
|
|
81
|
+
required: false
|
|
82
|
+
},
|
|
83
|
+
validateTrigger: {
|
|
84
|
+
type: [
|
|
85
|
+
String,
|
|
86
|
+
Array,
|
|
87
|
+
Boolean
|
|
88
|
+
],
|
|
89
|
+
required: false,
|
|
90
|
+
default: void 0
|
|
91
|
+
},
|
|
92
|
+
getValueProps: {
|
|
93
|
+
type: Function,
|
|
94
|
+
required: false
|
|
95
|
+
},
|
|
96
|
+
getValueFromEvent: {
|
|
97
|
+
type: Function,
|
|
98
|
+
required: false
|
|
99
|
+
},
|
|
100
|
+
trigger: {
|
|
101
|
+
type: [String, Array],
|
|
102
|
+
required: false
|
|
103
|
+
},
|
|
104
|
+
isList: {
|
|
105
|
+
type: Boolean,
|
|
106
|
+
required: false,
|
|
107
|
+
default: void 0
|
|
108
|
+
},
|
|
109
|
+
isListField: {
|
|
110
|
+
type: Boolean,
|
|
111
|
+
required: false,
|
|
112
|
+
default: void 0
|
|
113
|
+
},
|
|
114
|
+
validateDebounce: {
|
|
115
|
+
type: Number,
|
|
116
|
+
required: false
|
|
117
|
+
},
|
|
118
|
+
validateFirst: {
|
|
119
|
+
type: [Boolean, String],
|
|
120
|
+
required: false,
|
|
121
|
+
default: void 0
|
|
122
|
+
},
|
|
123
|
+
normalize: {
|
|
124
|
+
type: Function,
|
|
125
|
+
required: false
|
|
126
|
+
},
|
|
127
|
+
fieldContext: {
|
|
128
|
+
type: [Object, null],
|
|
129
|
+
required: false
|
|
130
|
+
},
|
|
131
|
+
preserve: {
|
|
132
|
+
type: Boolean,
|
|
133
|
+
required: false,
|
|
134
|
+
default: void 0
|
|
135
|
+
},
|
|
136
|
+
onReset: {
|
|
137
|
+
type: Function,
|
|
138
|
+
required: false
|
|
139
|
+
},
|
|
140
|
+
onMetaChange: {
|
|
141
|
+
type: Function,
|
|
142
|
+
required: false
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
name: "InternalField",
|
|
146
|
+
inheritAttrs: false
|
|
147
|
+
});
|
|
148
|
+
//#endregion
|
|
149
|
+
export { InternalField as default };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { InternalNamePath } from "./interface.js";
|
|
2
|
+
import { InjectionKey } from "vue";
|
|
3
|
+
|
|
4
|
+
//#region src/components/FormList/ListContext.d.ts
|
|
5
|
+
interface ListContextProps {
|
|
6
|
+
getKey: (namePath: InternalNamePath) => [InternalNamePath[number], InternalNamePath];
|
|
7
|
+
}
|
|
8
|
+
declare const formListContextKey: InjectionKey<ListContextProps>;
|
|
9
|
+
declare function useFormListContextProvider(props: ListContextProps): void;
|
|
10
|
+
declare function useFormListContextInject(): ListContextProps;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { ListContextProps, formListContextKey, useFormListContextInject, useFormListContextProvider };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { inject, provide } from "vue";
|
|
2
|
+
//#region src/components/FormList/ListContext.ts
|
|
3
|
+
const formListContextKey = Symbol("formListContext");
|
|
4
|
+
function useFormListContextProvider(props) {
|
|
5
|
+
return provide(formListContextKey, props);
|
|
6
|
+
}
|
|
7
|
+
function useFormListContextInject() {
|
|
8
|
+
return inject(formListContextKey, null);
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { formListContextKey, useFormListContextInject, useFormListContextProvider };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { StoreValue as StoreValue$1 } from "./interface.js";
|
|
2
|
+
import * as _$vue from "vue";
|
|
3
|
+
import { CustomSlotsType, VueNode } from "@v-c/util/dist/type";
|
|
4
|
+
import { NamePath, ValidatorRule } from "antdv-next/dist/form/types";
|
|
5
|
+
|
|
6
|
+
//#region src/components/FormList/index.d.ts
|
|
7
|
+
interface FormListFieldData {
|
|
8
|
+
name?: number;
|
|
9
|
+
key: number;
|
|
10
|
+
isListField: boolean;
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
}
|
|
13
|
+
interface FormListOperation {
|
|
14
|
+
add: (defaultValue?: StoreValue$1, insertIndex?: number) => void;
|
|
15
|
+
remove: (index: number | number[]) => void;
|
|
16
|
+
move: (from: number, to: number) => void;
|
|
17
|
+
}
|
|
18
|
+
interface FormListProps {
|
|
19
|
+
prefixCls?: string;
|
|
20
|
+
name?: NamePath<string | number | boolean>;
|
|
21
|
+
rules?: ValidatorRule[];
|
|
22
|
+
initialValue?: any[];
|
|
23
|
+
isListField?: boolean;
|
|
24
|
+
}
|
|
25
|
+
declare const FormList: _$vue.DefineSetupFnComponent<FormListProps & {
|
|
26
|
+
validateTrigger?: string | string[] | false;
|
|
27
|
+
}, {}, CustomSlotsType<{
|
|
28
|
+
default?: (fields: FormListFieldData[], operation: FormListOperation, meta: {
|
|
29
|
+
errors: VueNode[];
|
|
30
|
+
warnings: VueNode[];
|
|
31
|
+
}) => VueNode;
|
|
32
|
+
}>, FormListProps & {
|
|
33
|
+
validateTrigger?: string | string[] | false;
|
|
34
|
+
} & {}, _$vue.PublicProps>;
|
|
35
|
+
//#endregion
|
|
36
|
+
export { FormListFieldData, FormListOperation, FormListProps, FormList as default };
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { useProFormContextInject } from "../ProFormContext/index.js";
|
|
2
|
+
import { useFormFieldContextInject, useFormFieldContextProvider } from "./FieldContext.js";
|
|
3
|
+
import { move } from "./utils/index.js";
|
|
4
|
+
import { useFormListContextInject, useFormListContextProvider } from "./ListContext.js";
|
|
5
|
+
import FormListField from "./Field.js";
|
|
6
|
+
import { computed, createVNode, defineComponent, reactive } from "vue";
|
|
7
|
+
import { getNamePath } from "antdv-next/dist/form/utils/valueUtil";
|
|
8
|
+
import warning from "antdv-next/dist/_util/warning";
|
|
9
|
+
//#region src/components/FormList/index.tsx
|
|
10
|
+
const FormList = /* @__PURE__ */ defineComponent((props, { slots }) => {
|
|
11
|
+
const { formRef } = useProFormContextInject();
|
|
12
|
+
const fieldContext = useFormFieldContextInject();
|
|
13
|
+
const wrapperListContext = useFormListContextInject();
|
|
14
|
+
const keyManager = reactive({
|
|
15
|
+
keys: [],
|
|
16
|
+
id: 0
|
|
17
|
+
});
|
|
18
|
+
const prefixName = computed(() => {
|
|
19
|
+
return [...getNamePath(fieldContext.prefixName?.value) || [], ...getNamePath(props.name)];
|
|
20
|
+
});
|
|
21
|
+
useFormFieldContextProvider({
|
|
22
|
+
...formRef?.value,
|
|
23
|
+
get nativeElement() {
|
|
24
|
+
return formRef.value?.nativeElement;
|
|
25
|
+
},
|
|
26
|
+
get el() {
|
|
27
|
+
return formRef.value?.nativeElement;
|
|
28
|
+
},
|
|
29
|
+
...fieldContext,
|
|
30
|
+
prefixName,
|
|
31
|
+
initialValue: props.initialValue || []
|
|
32
|
+
});
|
|
33
|
+
useFormListContextProvider({ getKey: (namePath) => {
|
|
34
|
+
const len = prefixName.value.length;
|
|
35
|
+
const pathName = namePath[len];
|
|
36
|
+
return [keyManager.keys[pathName], namePath.slice(len + 1)];
|
|
37
|
+
} });
|
|
38
|
+
return () => {
|
|
39
|
+
const { rules, validateTrigger, isListField, initialValue } = props;
|
|
40
|
+
return createVNode(FormListField, {
|
|
41
|
+
"name": [],
|
|
42
|
+
"rules": rules,
|
|
43
|
+
"validateTrigger": validateTrigger,
|
|
44
|
+
"initialValue": initialValue,
|
|
45
|
+
"isList": true,
|
|
46
|
+
"isListField": isListField ?? !!wrapperListContext
|
|
47
|
+
}, { default: ({ value = [], onChange }, meta) => {
|
|
48
|
+
const getNewValue = () => {
|
|
49
|
+
return formRef?.value?.getFieldValue(prefixName.value || []) || [];
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Always get latsest value in case user update fields by `form` api.
|
|
53
|
+
*/
|
|
54
|
+
const operations = {
|
|
55
|
+
add: (defaultValue, index = 0) => {
|
|
56
|
+
const newValue = getNewValue();
|
|
57
|
+
if (index >= 0 && index <= newValue.length) {
|
|
58
|
+
keyManager.keys = [
|
|
59
|
+
...keyManager.keys.slice(0, index),
|
|
60
|
+
keyManager.id,
|
|
61
|
+
...keyManager.keys.slice(index)
|
|
62
|
+
];
|
|
63
|
+
onChange?.([
|
|
64
|
+
...newValue.slice(0, index),
|
|
65
|
+
defaultValue,
|
|
66
|
+
...newValue.slice(index)
|
|
67
|
+
]);
|
|
68
|
+
} else {
|
|
69
|
+
if (process.env.NODE_ENV !== "production" && (index < 0 || index > newValue.length)) warning(false, "The second parameter of the add function should be a valid positive number.");
|
|
70
|
+
keyManager.keys = [...keyManager.keys, keyManager.id];
|
|
71
|
+
onChange?.([...newValue, defaultValue]);
|
|
72
|
+
}
|
|
73
|
+
keyManager.id += 1;
|
|
74
|
+
},
|
|
75
|
+
remove: (index) => {
|
|
76
|
+
const newValue = getNewValue();
|
|
77
|
+
const indexSet = new Set(Array.isArray(index) ? index : [index]);
|
|
78
|
+
if (indexSet.size <= 0) return;
|
|
79
|
+
keyManager.keys = keyManager.keys.filter((_, keysIndex) => !indexSet.has(keysIndex));
|
|
80
|
+
onChange?.(newValue.filter((_, valueIndex) => !indexSet.has(valueIndex)));
|
|
81
|
+
},
|
|
82
|
+
move(from, to) {
|
|
83
|
+
if (from === to) return;
|
|
84
|
+
const newValue = getNewValue();
|
|
85
|
+
if (from < 0 || from >= newValue.length || to < 0 || to >= newValue.length) return;
|
|
86
|
+
keyManager.keys = move(keyManager.keys, from, to);
|
|
87
|
+
onChange?.(move(newValue, from, to));
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
let listValue = value || [];
|
|
91
|
+
if (!Array.isArray(listValue)) {
|
|
92
|
+
listValue = [];
|
|
93
|
+
if (process.env.NODE_ENV !== "production") warning(false, `Current value of '${prefixName.value.join(" > ")}' is not an array type.`);
|
|
94
|
+
}
|
|
95
|
+
return slots.default?.(listValue.map((__, index) => {
|
|
96
|
+
let key = keyManager.keys[index];
|
|
97
|
+
if (key === void 0) {
|
|
98
|
+
keyManager.keys[index] = keyManager.id;
|
|
99
|
+
key = keyManager.keys[index];
|
|
100
|
+
keyManager.id += 1;
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
name: index,
|
|
104
|
+
key,
|
|
105
|
+
fieldKey: key,
|
|
106
|
+
isListField: true
|
|
107
|
+
};
|
|
108
|
+
}), operations, meta);
|
|
109
|
+
} });
|
|
110
|
+
};
|
|
111
|
+
}, {
|
|
112
|
+
props: {
|
|
113
|
+
prefixCls: {
|
|
114
|
+
type: String,
|
|
115
|
+
required: false
|
|
116
|
+
},
|
|
117
|
+
name: { required: false },
|
|
118
|
+
rules: {
|
|
119
|
+
type: Array,
|
|
120
|
+
required: false
|
|
121
|
+
},
|
|
122
|
+
initialValue: {
|
|
123
|
+
type: Array,
|
|
124
|
+
required: false
|
|
125
|
+
},
|
|
126
|
+
isListField: {
|
|
127
|
+
type: Boolean,
|
|
128
|
+
required: false,
|
|
129
|
+
default: void 0
|
|
130
|
+
},
|
|
131
|
+
validateTrigger: {
|
|
132
|
+
type: [
|
|
133
|
+
String,
|
|
134
|
+
Array,
|
|
135
|
+
Boolean
|
|
136
|
+
],
|
|
137
|
+
required: false,
|
|
138
|
+
default: void 0
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
name: "FormList",
|
|
142
|
+
inheritAttrs: false
|
|
143
|
+
});
|
|
144
|
+
//#endregion
|
|
145
|
+
export { FormList as default };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DeepNamePath } from "./namePathType.js";
|
|
2
|
+
|
|
3
|
+
//#region src/components/FormList/interface.d.ts
|
|
4
|
+
type StoreValue = any;
|
|
5
|
+
type Store = Record<string, StoreValue>;
|
|
6
|
+
type InternalNamePath = (string | number)[];
|
|
7
|
+
type NamePath<T = any> = DeepNamePath<T>;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { InternalNamePath, NamePath, Store, StoreValue };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/components/FormList/namePathType.d.ts
|
|
2
|
+
type BaseNamePath = string | number | boolean | (string | number | boolean)[];
|
|
3
|
+
/**
|
|
4
|
+
* Store: The store type from `FormInstance<Store>`
|
|
5
|
+
* ParentNamePath: Auto generate by nest logic. Do not fill manually.
|
|
6
|
+
*/
|
|
7
|
+
type DeepNamePath<Store = any, ParentNamePath extends any[] = []> = ParentNamePath['length'] extends 5 ? never : true extends (Store extends BaseNamePath ? true : false) ? ParentNamePath['length'] extends 0 ? Store | BaseNamePath : Store extends any[] ? [...ParentNamePath, number] : never : Store extends any[] ? [...ParentNamePath, number] | DeepNamePath<Store[number], [...ParentNamePath, number]> : keyof Store extends never ? Store : { [FieldKey in keyof Store]: Store[FieldKey] extends ((...arg: any[]) => any) ? never : (ParentNamePath['length'] extends 0 ? FieldKey : never) | [...ParentNamePath, FieldKey] | DeepNamePath<Required<Store>[FieldKey], [...ParentNamePath, FieldKey]> }[keyof Store];
|
|
8
|
+
//#endregion
|
|
9
|
+
export { DeepNamePath };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
//#region src/components/FormList/utils/index.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Moves an array item from one position in an array to another.
|
|
4
|
+
*
|
|
5
|
+
* Note: This is a pure function so a new array will be returned, instead
|
|
6
|
+
* of altering the array argument.
|
|
7
|
+
*
|
|
8
|
+
* @param array Array in which to move an item. (required)
|
|
9
|
+
* @param moveIndex The index of the item to move. (required)
|
|
10
|
+
* @param toIndex The index to move item at moveIndex to. (required)
|
|
11
|
+
*/
|
|
12
|
+
declare function move<T>(array: T[], moveIndex: number, toIndex: number): (T | undefined)[];
|
|
13
|
+
declare function defaultGetValueFromEvent(valuePropName: string, ...args: any[]): any;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { defaultGetValueFromEvent, move };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region src/components/FormList/utils/index.ts
|
|
2
|
+
/**
|
|
3
|
+
* Moves an array item from one position in an array to another.
|
|
4
|
+
*
|
|
5
|
+
* Note: This is a pure function so a new array will be returned, instead
|
|
6
|
+
* of altering the array argument.
|
|
7
|
+
*
|
|
8
|
+
* @param array Array in which to move an item. (required)
|
|
9
|
+
* @param moveIndex The index of the item to move. (required)
|
|
10
|
+
* @param toIndex The index to move item at moveIndex to. (required)
|
|
11
|
+
*/
|
|
12
|
+
function move(array, moveIndex, toIndex) {
|
|
13
|
+
const { length } = array;
|
|
14
|
+
if (moveIndex < 0 || moveIndex >= length || toIndex < 0 || toIndex >= length) return array;
|
|
15
|
+
const item = array[moveIndex];
|
|
16
|
+
const diff = moveIndex - toIndex;
|
|
17
|
+
if (diff > 0) return [
|
|
18
|
+
...array.slice(0, toIndex),
|
|
19
|
+
item,
|
|
20
|
+
...array.slice(toIndex, moveIndex),
|
|
21
|
+
...array.slice(moveIndex + 1, length)
|
|
22
|
+
];
|
|
23
|
+
if (diff < 0) return [
|
|
24
|
+
...array.slice(0, moveIndex),
|
|
25
|
+
...array.slice(moveIndex + 1, toIndex + 1),
|
|
26
|
+
item,
|
|
27
|
+
...array.slice(toIndex + 1, length)
|
|
28
|
+
];
|
|
29
|
+
return array;
|
|
30
|
+
}
|
|
31
|
+
function defaultGetValueFromEvent(valuePropName, ...args) {
|
|
32
|
+
const event = args[0];
|
|
33
|
+
if (event && event.target && typeof event.target === "object" && valuePropName in event.target) return event.target[valuePropName];
|
|
34
|
+
return event;
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
export { defaultGetValueFromEvent, move };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { FormItemProps as FormItemProps$1 } from "../FormItem/index.js";
|
|
2
|
+
import * as _$vue from "vue";
|
|
3
|
+
import { VNode } from "vue";
|
|
4
|
+
import { VueNode } from "@v-c/util";
|
|
5
|
+
import { PopoverProps } from "antdv-next";
|
|
6
|
+
|
|
7
|
+
//#region src/components/InlineErrorFormItem/InlineErrorFormItemPopover.d.ts
|
|
8
|
+
interface InlineErrorFormItemPopoverProps {
|
|
9
|
+
prefixCls?: string;
|
|
10
|
+
inputProps: FormItemProps$1 & {
|
|
11
|
+
errors?: VueNode[];
|
|
12
|
+
warnings?: VueNode[];
|
|
13
|
+
};
|
|
14
|
+
input?: VNode | null;
|
|
15
|
+
errorList?: VNode | null;
|
|
16
|
+
extra?: VNode | null;
|
|
17
|
+
popoverProps?: PopoverProps;
|
|
18
|
+
}
|
|
19
|
+
declare const InlineErrorFormItemPopover: _$vue.DefineSetupFnComponent<InlineErrorFormItemPopoverProps, {}, {}, InlineErrorFormItemPopoverProps & {}, _$vue.PublicProps>;
|
|
20
|
+
//#endregion
|
|
21
|
+
export { InlineErrorFormItemPopoverProps, InlineErrorFormItemPopover as default };
|