@carefrees/form-utils-vue 0.0.8 → 0.0.10
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/esm/form/form.vue2.mjs +4 -0
- package/esm/form/index.mjs +1 -1
- package/esm/formItem/form.Item.base.vue.mjs +1 -1
- package/esm/formItem/form.hide.item.vue.mjs +1 -1
- package/esm/formItem/formItem.vue.mjs +1 -1
- package/esm/hooks/attr/attr.FormItem.d.ts +5 -784
- package/esm/hooks/attr/attr.FormItem.mjs +7 -7
- package/esm/hooks/register/register.FormHideItem.mjs +5 -5
- package/esm/hooks/register/register.FormItem.d.ts +3 -782
- package/esm/hooks/register/register.FormItem.mjs +10 -10
- package/esm/hooks/register/register.FormList.d.ts +1 -781
- package/esm/hooks/register/register.FormList.mjs +5 -5
- package/esm/hooks/useAttrs.mjs +7 -9
- package/esm/interface/index.d.ts +2 -2
- package/lib/form/form.vue2.js +4 -0
- package/lib/form/index.js +2 -2
- package/lib/formItem/form.Item.base.vue.js +1 -1
- package/lib/formItem/form.hide.item.vue.js +1 -1
- package/lib/formItem/formItem.vue.js +1 -1
- package/lib/hooks/attr/attr.FormItem.d.ts +5 -784
- package/lib/hooks/attr/attr.FormItem.js +7 -7
- package/lib/hooks/register/register.FormHideItem.js +4 -4
- package/lib/hooks/register/register.FormItem.d.ts +3 -782
- package/lib/hooks/register/register.FormItem.js +10 -10
- package/lib/hooks/register/register.FormList.d.ts +1 -781
- package/lib/hooks/register/register.FormList.js +5 -5
- package/lib/hooks/useAttrs.js +6 -8
- package/lib/interface/index.d.ts +2 -2
- package/package.json +3 -3
- package/src/form/{index.vue → form.vue} +1 -1
- package/src/form/index.ts +1 -1
- package/src/hooks/attr/attr.FormItem.tsx +13 -9
- package/src/hooks/register/register.FormHideItem.ts +5 -5
- package/src/hooks/register/register.FormItem.ts +12 -12
- package/src/hooks/register/register.FormList.ts +5 -5
- package/src/hooks/useAttrs.ts +6 -8
- package/src/interface/index.ts +2 -2
- package/src/layout/layout.formItem.vue +1 -1
- package/esm/form/index.vue2.mjs +0 -4
- package/lib/form/index.vue2.js +0 -4
- /package/esm/form/{index.vue.d.ts → form.vue.d.ts} +0 -0
- /package/esm/form/{index.vue.mjs → form.vue.mjs} +0 -0
- /package/lib/form/{index.vue.d.ts → form.vue.d.ts} +0 -0
- /package/lib/form/{index.vue.js → form.vue.js} +0 -0
|
@@ -8,23 +8,23 @@ const useRegisterFormList = (options) => {
|
|
|
8
8
|
const { ruleInstance, formItemInstance, form, newName, parentItem } = register_FormItem.useRegisterFormItem(options);
|
|
9
9
|
const formListInstance = useFormList.useFormList();
|
|
10
10
|
vue.watch(
|
|
11
|
-
[newName
|
|
11
|
+
() => [vue.toValue(newName)],
|
|
12
12
|
() => {
|
|
13
|
-
formListInstance.ctor(newName
|
|
13
|
+
formListInstance.ctor(vue.toValue(newName));
|
|
14
14
|
},
|
|
15
15
|
{ immediate: true }
|
|
16
16
|
);
|
|
17
17
|
vue.watch(
|
|
18
|
-
[form, formItemInstance, ruleInstance
|
|
18
|
+
() => [form, formItemInstance, vue.toValue(ruleInstance)],
|
|
19
19
|
() => {
|
|
20
20
|
formListInstance.instance = form;
|
|
21
21
|
formListInstance.formItemInstance = formItemInstance;
|
|
22
|
-
formListInstance.rule = ruleInstance
|
|
22
|
+
formListInstance.rule = vue.toValue(ruleInstance);
|
|
23
23
|
},
|
|
24
24
|
{ immediate: true }
|
|
25
25
|
);
|
|
26
26
|
vue.watch(
|
|
27
|
-
[options.sort, parentItem
|
|
27
|
+
() => [options.sort, vue.toValue(parentItem)],
|
|
28
28
|
() => {
|
|
29
29
|
formListInstance.sort = vue.toValue(parentItem.value.sort);
|
|
30
30
|
formListInstance.parentDataField = vue.toValue(parentItem.value.name);
|
package/lib/hooks/useAttrs.js
CHANGED
|
@@ -30,14 +30,12 @@ function useAttrsProvide(options) {
|
|
|
30
30
|
function useAttrsInject() {
|
|
31
31
|
const attrs = vue.inject(
|
|
32
32
|
attrsProvideSymbol,
|
|
33
|
-
vue.computed(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
})
|
|
40
|
-
)
|
|
33
|
+
vue.computed(() => ({
|
|
34
|
+
colCount: vue.ref(4),
|
|
35
|
+
errorLayout: vue.ref("left-bottom"),
|
|
36
|
+
labelMode: vue.ref("top"),
|
|
37
|
+
showColon: vue.ref(true)
|
|
38
|
+
}))
|
|
41
39
|
);
|
|
42
40
|
return attrs;
|
|
43
41
|
}
|
package/lib/interface/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ComputedRef, Ref,
|
|
1
|
+
import { ComputedRef, Ref, Component, StyleValue, UnwrapNestedRefs } from 'vue';
|
|
2
2
|
import { FormItemAttrOptions } from '../hooks/attr/attr.FormItem';
|
|
3
3
|
import { LayoutFormItemProps } from './layout.formItem';
|
|
4
4
|
import { FormLayoutProps } from './layout';
|
|
@@ -11,7 +11,7 @@ export interface FormItemProps extends FormItemAttrOptions, LayoutFormItemProps
|
|
|
11
11
|
/**不进行样式渲染*/
|
|
12
12
|
noStyle?: boolean;
|
|
13
13
|
/**输入框组件*/
|
|
14
|
-
input?:
|
|
14
|
+
input?: Component | string;
|
|
15
15
|
}
|
|
16
16
|
export interface FormProps<T = any> extends FormLayoutProps {
|
|
17
17
|
form?: FormInstanceBase;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@carefrees/form-utils-vue",
|
|
3
3
|
"author": "SunLxy <1011771396@qq.com>",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.10",
|
|
5
5
|
"description": "",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"module": "esm/index.mjs",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"vue": "^3.5.13"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
+
"@carefrees/form-utils": "^0.0.10",
|
|
29
30
|
"async-validator": "~4.2.5",
|
|
30
|
-
"@carefrees/form-utils": "^0.0.8",
|
|
31
31
|
"classnames": "2.5.1"
|
|
32
32
|
}
|
|
33
|
-
}
|
|
33
|
+
}
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
import { computed, defineProps, withDefaults, reactive, defineEmits } from "vue"
|
|
12
12
|
import type { FormProps } from "../interface/index"
|
|
13
13
|
import { useRegisterForm } from "../hooks/register/register.form"
|
|
14
|
-
import { useForm, useFormProvide } from "
|
|
14
|
+
import { useForm, useFormProvide } from "../hooks/useForm"
|
|
15
15
|
import FormLayout from "../layout/layout.vue"
|
|
16
16
|
import clx from 'classnames';
|
|
17
17
|
|
package/src/form/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FormInstanceBase, FormItemInstanceBase, get } from '@carefrees/form-utils';
|
|
2
2
|
import { useHtmlFor } from './../useHtmlFor';
|
|
3
3
|
import { useRegisterFormItem, RegisterFormItemOptions } from './../register/register.FormItem';
|
|
4
|
-
import { computed, ref, toValue, watch } from 'vue';
|
|
4
|
+
import { computed, Ref, ref, toValue, watch } from 'vue';
|
|
5
5
|
import type { RuleInstanceBase2 } from '../../instance/ruleIntsnace';
|
|
6
6
|
|
|
7
7
|
export interface FormItemAttrOptions extends RegisterFormItemOptions {
|
|
@@ -16,7 +16,11 @@ export interface FormItemAttrOptions extends RegisterFormItemOptions {
|
|
|
16
16
|
/**是否保护值(不进行表单项组件卸载重置初始值)*/
|
|
17
17
|
preserve?: boolean;
|
|
18
18
|
/**重写规则*/
|
|
19
|
-
useRules?: (
|
|
19
|
+
useRules?: (
|
|
20
|
+
ruleInstance: Ref<RuleInstanceBase2>,
|
|
21
|
+
form: FormInstanceBase,
|
|
22
|
+
formItemInstance: FormItemInstanceBase,
|
|
23
|
+
) => void;
|
|
20
24
|
/**输入框属性重写*/
|
|
21
25
|
useAttrs?: (attrs: any, form: FormInstanceBase, formItemInstance: FormItemInstanceBase) => any;
|
|
22
26
|
/**输入框属性*/
|
|
@@ -67,7 +71,7 @@ export const useFormItemAttr = (options: FormItemAttrOptions) => {
|
|
|
67
71
|
watch(
|
|
68
72
|
() => [get(form.formData, toValue(newName)), toValue(newName)],
|
|
69
73
|
() => {
|
|
70
|
-
oldValue.value = form.getFieldValue(newName
|
|
74
|
+
oldValue.value = form.getFieldValue(toValue(newName));
|
|
71
75
|
},
|
|
72
76
|
{ immediate: true },
|
|
73
77
|
);
|
|
@@ -84,7 +88,7 @@ export const useFormItemAttr = (options: FormItemAttrOptions) => {
|
|
|
84
88
|
value = formatValue(value, form, formItemInstance, event);
|
|
85
89
|
}
|
|
86
90
|
if (oldValue.value !== value) {
|
|
87
|
-
form.updatedFieldValue(newName
|
|
91
|
+
form.updatedFieldValue(toValue(newName), value, 'validate');
|
|
88
92
|
formItemInstance.onAfterUpdate?.(value, form, formItemInstance, event);
|
|
89
93
|
if (Array.isArray(formItemInstance.noticeWatchField) && formItemInstance.noticeWatchField.length) {
|
|
90
94
|
form.noticeWatch(formItemInstance.noticeWatchField);
|
|
@@ -132,25 +136,25 @@ export const useFormItemAttr = (options: FormItemAttrOptions) => {
|
|
|
132
136
|
watch(
|
|
133
137
|
() => [toValue(newAttrs), toValue(deepRefData), toValue(oldValue)],
|
|
134
138
|
() => {
|
|
135
|
-
attrsLastData.value = useAttrs?.(newAttrs
|
|
139
|
+
attrsLastData.value = useAttrs?.(toValue(newAttrs), form, formItemInstance) || toValue(newAttrs);
|
|
136
140
|
},
|
|
137
141
|
{ immediate: true },
|
|
138
142
|
);
|
|
139
143
|
|
|
140
144
|
/**规则处理**/
|
|
141
|
-
const validateResult = ref(ruleInstance.
|
|
145
|
+
const validateResult = ref(toValue(ruleInstance).getValidateResult());
|
|
142
146
|
|
|
143
147
|
watch(
|
|
144
148
|
() => [toValue(deepRefData), toValue(oldValue)],
|
|
145
149
|
() => {
|
|
146
|
-
useRules?.(ruleInstance
|
|
150
|
+
useRules?.(ruleInstance as any, form, formItemInstance);
|
|
147
151
|
},
|
|
148
152
|
);
|
|
149
153
|
|
|
150
154
|
watch(
|
|
151
|
-
() => [ruleInstance.
|
|
155
|
+
() => [toValue(ruleInstance).messages, toValue(ruleInstance).rules, toValue(oldValue)],
|
|
152
156
|
() => {
|
|
153
|
-
validateResult.value = ruleInstance.
|
|
157
|
+
validateResult.value = toValue(ruleInstance).getValidateResult();
|
|
154
158
|
},
|
|
155
159
|
);
|
|
156
160
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ref, watch } from 'vue';
|
|
1
|
+
import { ref, toValue, watch } from 'vue';
|
|
2
2
|
import { RegisterFormItemOptions } from './register.FormItem';
|
|
3
3
|
import { FormHideItemInstanceBase } from '@carefrees/form-utils';
|
|
4
4
|
import { useFormItemParentNameInject } from '../useFormItemParentName';
|
|
@@ -15,7 +15,7 @@ export const useRegisterFormHideItem = (options: RegisterFormHideItemOptions) =>
|
|
|
15
15
|
const hideItemInstance = ref<FormHideItemInstanceBase>(new FormHideItemInstanceBase().ctor(newName.value));
|
|
16
16
|
const isHide = ref(form.getFieldHideValue(newName.value));
|
|
17
17
|
watch(
|
|
18
|
-
[isHide
|
|
18
|
+
() => [toValue(isHide)],
|
|
19
19
|
() => {
|
|
20
20
|
hideItemInstance.value.preHideValue = isHide.value;
|
|
21
21
|
},
|
|
@@ -29,16 +29,16 @@ export const useRegisterFormHideItem = (options: RegisterFormHideItemOptions) =>
|
|
|
29
29
|
hideItemInstance.value.updatedItem = setValue;
|
|
30
30
|
|
|
31
31
|
watch(
|
|
32
|
-
[form, newSort
|
|
32
|
+
() => [form, toValue(newSort)],
|
|
33
33
|
() => {
|
|
34
34
|
hideItemInstance.value.instance = form;
|
|
35
|
-
hideItemInstance.value.sort = newSort
|
|
35
|
+
hideItemInstance.value.sort = toValue(newSort);
|
|
36
36
|
},
|
|
37
37
|
{ immediate: true },
|
|
38
38
|
);
|
|
39
39
|
|
|
40
40
|
useEffect(() => {
|
|
41
|
-
return form.registerFormHideItem(hideItemInstance
|
|
41
|
+
return form.registerFormHideItem(toValue(hideItemInstance) as FormHideItemInstanceBase);
|
|
42
42
|
});
|
|
43
43
|
|
|
44
44
|
return { form, isHide };
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @description 注册组件
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { ref, toValue, watch } from 'vue';
|
|
5
|
+
import { Ref, ref, toValue, watch } from 'vue';
|
|
6
6
|
import type { RuleItem } from 'async-validator';
|
|
7
7
|
import { useFormInject } from '../useForm';
|
|
8
8
|
import { useFormItem } from '../useFormItem';
|
|
@@ -29,11 +29,11 @@ export const useRegisterFormItem = (options: RegisterFormItemOptions) => {
|
|
|
29
29
|
const { newName, newSort, parentItem } = useFormItemParentNameInject({ name, sort, isJoinParentField });
|
|
30
30
|
// 注册规则
|
|
31
31
|
// 注册单个实例
|
|
32
|
-
const ruleInstance = ref(new RuleInstanceBase2());
|
|
32
|
+
const ruleInstance: Ref<RuleInstanceBase2> = ref<any>(new RuleInstanceBase2());
|
|
33
33
|
const formItemInstance = useFormItem();
|
|
34
34
|
|
|
35
35
|
watch(
|
|
36
|
-
[form],
|
|
36
|
+
() => [form],
|
|
37
37
|
() => {
|
|
38
38
|
ruleInstance.value.instance = form;
|
|
39
39
|
formItemInstance.instance = form;
|
|
@@ -42,33 +42,33 @@ export const useRegisterFormItem = (options: RegisterFormItemOptions) => {
|
|
|
42
42
|
);
|
|
43
43
|
|
|
44
44
|
watch(
|
|
45
|
-
[newName
|
|
45
|
+
() => [toValue(newName)],
|
|
46
46
|
() => {
|
|
47
|
-
ruleInstance.value.ctor(newName
|
|
48
|
-
formItemInstance.ctor(newName
|
|
47
|
+
ruleInstance.value.ctor(toValue(newName), rules || []);
|
|
48
|
+
formItemInstance.ctor(toValue(newName), toValue(ruleInstance) as any);
|
|
49
49
|
},
|
|
50
50
|
{ immediate: true },
|
|
51
51
|
);
|
|
52
52
|
|
|
53
53
|
watch(
|
|
54
|
-
[newSort
|
|
54
|
+
() => [toValue(newSort)],
|
|
55
55
|
() => {
|
|
56
|
-
ruleInstance.value.sort = newSort
|
|
57
|
-
formItemInstance.sort = newSort
|
|
56
|
+
ruleInstance.value.sort = toValue(newSort);
|
|
57
|
+
formItemInstance.sort = toValue(newSort);
|
|
58
58
|
},
|
|
59
59
|
{ immediate: true },
|
|
60
60
|
);
|
|
61
61
|
|
|
62
62
|
watch(
|
|
63
|
-
[parentItem
|
|
63
|
+
() => [toValue(parentItem)],
|
|
64
64
|
() => {
|
|
65
|
-
formItemInstance.parentDataField = toValue(parentItem.
|
|
65
|
+
formItemInstance.parentDataField = toValue(toValue(parentItem).name);
|
|
66
66
|
},
|
|
67
67
|
{ immediate: true },
|
|
68
68
|
);
|
|
69
69
|
|
|
70
70
|
const updated = () => {
|
|
71
|
-
deepRefData.value = {
|
|
71
|
+
deepRefData.value = { __temp: new Date().valueOf() };
|
|
72
72
|
};
|
|
73
73
|
|
|
74
74
|
formItemInstance.updated = updated;
|
|
@@ -11,25 +11,25 @@ export const useRegisterFormList = (options: RegisterFormListOptions) => {
|
|
|
11
11
|
const formListInstance = useFormList();
|
|
12
12
|
|
|
13
13
|
watch(
|
|
14
|
-
[newName
|
|
14
|
+
() => [toValue(newName)],
|
|
15
15
|
() => {
|
|
16
|
-
formListInstance.ctor(newName
|
|
16
|
+
formListInstance.ctor(toValue(newName));
|
|
17
17
|
},
|
|
18
18
|
{ immediate: true },
|
|
19
19
|
);
|
|
20
20
|
|
|
21
21
|
watch(
|
|
22
|
-
[form, formItemInstance, ruleInstance
|
|
22
|
+
() => [form, formItemInstance, toValue(ruleInstance)],
|
|
23
23
|
() => {
|
|
24
24
|
formListInstance.instance = form;
|
|
25
25
|
formListInstance.formItemInstance = formItemInstance;
|
|
26
|
-
formListInstance.rule = ruleInstance
|
|
26
|
+
formListInstance.rule = toValue(ruleInstance) as any;
|
|
27
27
|
},
|
|
28
28
|
{ immediate: true },
|
|
29
29
|
);
|
|
30
30
|
|
|
31
31
|
watch(
|
|
32
|
-
[options.sort, parentItem
|
|
32
|
+
() => [options.sort, toValue(parentItem)],
|
|
33
33
|
() => {
|
|
34
34
|
formListInstance.sort = toValue(parentItem.value.sort);
|
|
35
35
|
formListInstance.parentDataField = toValue(parentItem.value.name);
|
package/src/hooks/useAttrs.ts
CHANGED
|
@@ -53,14 +53,12 @@ export function useAttrsProvide(options: AttrsOptions) {
|
|
|
53
53
|
export function useAttrsInject() {
|
|
54
54
|
const attrs = inject<ComputedRef<AttrsOptions>>(
|
|
55
55
|
attrsProvideSymbol,
|
|
56
|
-
computed(() =>
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}),
|
|
63
|
-
),
|
|
56
|
+
computed(() => ({
|
|
57
|
+
colCount: ref(4),
|
|
58
|
+
errorLayout: ref('left-bottom'),
|
|
59
|
+
labelMode: ref('top'),
|
|
60
|
+
showColon: ref(true),
|
|
61
|
+
})),
|
|
64
62
|
);
|
|
65
63
|
return attrs;
|
|
66
64
|
}
|
package/src/interface/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ComputedRef, Ref,
|
|
1
|
+
import { ComputedRef, Ref, VNode, Component, StyleValue, UnwrapNestedRefs } from 'vue';
|
|
2
2
|
import { FormItemAttrOptions } from '../hooks/attr/attr.FormItem';
|
|
3
3
|
import { LayoutFormItemProps } from './layout.formItem';
|
|
4
4
|
import { FormLayoutProps } from './layout';
|
|
@@ -14,7 +14,7 @@ export interface FormItemProps extends FormItemAttrOptions, LayoutFormItemProps
|
|
|
14
14
|
/**不进行样式渲染*/
|
|
15
15
|
noStyle?: boolean;
|
|
16
16
|
/**输入框组件*/
|
|
17
|
-
input?:
|
|
17
|
+
input?: Component | string;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
export interface FormProps<T = any> extends FormLayoutProps {
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
|
|
48
48
|
<script lang="ts" setup>
|
|
49
49
|
import clx from 'classnames';
|
|
50
|
-
import { defineProps, withDefaults, toValue, computed, StyleValue
|
|
50
|
+
import { defineProps, withDefaults, toValue, computed, StyleValue } from "vue"
|
|
51
51
|
import type { LayoutFormItemProps } from "../interface/layout.formItem"
|
|
52
52
|
import { useAttrsInject } from "../hooks/useAttrs"
|
|
53
53
|
const preCls = 'carefrees-form-item';
|
package/esm/form/index.vue2.mjs
DELETED
package/lib/form/index.vue2.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
-
const index_vue_vue_type_script_setup_true_lang = require("./index.vue.js");
|
|
4
|
-
exports.default = index_vue_vue_type_script_setup_true_lang.default;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|