@volverjs/form-vue 1.0.0-beta.10 → 1.0.0-beta.11
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/README.md +4 -4
- package/dist/VvForm.d.ts +7 -7
- package/dist/index.d.ts +21 -21
- package/dist/index.es.js +2 -2
- package/dist/index.umd.js +1 -1
- package/dist/types.d.ts +1 -1
- package/package.json +1 -1
- package/src/VvForm.ts +3 -3
- package/src/types.ts +1 -1
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ const form = createForm({
|
|
|
56
56
|
schema
|
|
57
57
|
// lazyLoad: boolean - default false
|
|
58
58
|
// updateThrottle: number - default 500
|
|
59
|
-
//
|
|
59
|
+
// continuousValidation: boolean - default false
|
|
60
60
|
// sideEffects?: (data: any) => void
|
|
61
61
|
})
|
|
62
62
|
|
|
@@ -118,7 +118,7 @@ Use the `v-model` directive (or only `:model-value` to set the initial value of
|
|
|
118
118
|
The form data two way binding is **throttled** by default (500ms) to avoid performance issues. The throttle can be changed with the `updateThrottle` option or prop.
|
|
119
119
|
|
|
120
120
|
By default form validation **stops** when a **valid state** is reached.
|
|
121
|
-
To activate **
|
|
121
|
+
To activate **continuous validation** use the `continuousValidation` option or prop.
|
|
122
122
|
|
|
123
123
|
```vue
|
|
124
124
|
<script lang="ts" setup>
|
|
@@ -131,7 +131,7 @@ To activate **continuos validation** use the `continuosValidation` option or pro
|
|
|
131
131
|
</script>
|
|
132
132
|
|
|
133
133
|
<template>
|
|
134
|
-
<VvForm v-model="formData" :update-throttle="1000"
|
|
134
|
+
<VvForm v-model="formData" :update-throttle="1000" continuous-validation>
|
|
135
135
|
<!-- ... -->
|
|
136
136
|
</VvForm>
|
|
137
137
|
</template>
|
|
@@ -155,7 +155,7 @@ The **default settings** are **inherited** from the plugin (if it's installed).
|
|
|
155
155
|
const { VvForm, VvFormWrapper, VvFormField } = useForm(schema, {
|
|
156
156
|
// lazyLoad: boolean - default false
|
|
157
157
|
// updateThrottle: number - default 500
|
|
158
|
-
//
|
|
158
|
+
// continuousValidation: boolean - default false
|
|
159
159
|
// sideEffects?: (formData: any) => void
|
|
160
160
|
})
|
|
161
161
|
</script>
|
package/dist/VvForm.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export declare const defineForm: <Schema extends FormSchema>(schema: Schema, pro
|
|
|
19
19
|
*/
|
|
20
20
|
VvForm: {
|
|
21
21
|
new (...args: any[]): import('vue').CreateComponentPublicInstance<Readonly<import("vue").ExtractPropTypes<{
|
|
22
|
-
|
|
22
|
+
continuousValidation: {
|
|
23
23
|
type: BooleanConstructor;
|
|
24
24
|
default: boolean;
|
|
25
25
|
};
|
|
@@ -56,7 +56,7 @@ export declare const defineForm: <Schema extends FormSchema>(schema: Schema, pro
|
|
|
56
56
|
invalid: import("vue").ComputedRef<boolean>;
|
|
57
57
|
isReadonly: Ref<boolean>;
|
|
58
58
|
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("invalid" | "valid" | "update:modelValue" | "submit" | "update:readonly")[], import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & Readonly<import("vue").ExtractPropTypes<{
|
|
59
|
-
|
|
59
|
+
continuousValidation: {
|
|
60
60
|
type: BooleanConstructor;
|
|
61
61
|
default: boolean;
|
|
62
62
|
};
|
|
@@ -86,7 +86,7 @@ export declare const defineForm: <Schema extends FormSchema>(schema: Schema, pro
|
|
|
86
86
|
readonly: boolean;
|
|
87
87
|
template: FormTemplate<Schema>;
|
|
88
88
|
modelValue: Record<string, any>;
|
|
89
|
-
|
|
89
|
+
continuousValidation: boolean;
|
|
90
90
|
tag: string;
|
|
91
91
|
}, true, {}, {}, {
|
|
92
92
|
P: {};
|
|
@@ -96,7 +96,7 @@ export declare const defineForm: <Schema extends FormSchema>(schema: Schema, pro
|
|
|
96
96
|
M: {};
|
|
97
97
|
Defaults: {};
|
|
98
98
|
}, Readonly<import("vue").ExtractPropTypes<{
|
|
99
|
-
|
|
99
|
+
continuousValidation: {
|
|
100
100
|
type: BooleanConstructor;
|
|
101
101
|
default: boolean;
|
|
102
102
|
};
|
|
@@ -136,14 +136,14 @@ export declare const defineForm: <Schema extends FormSchema>(schema: Schema, pro
|
|
|
136
136
|
readonly: boolean;
|
|
137
137
|
template: FormTemplate<Schema>;
|
|
138
138
|
modelValue: Record<string, any>;
|
|
139
|
-
|
|
139
|
+
continuousValidation: boolean;
|
|
140
140
|
tag: string;
|
|
141
141
|
}>;
|
|
142
142
|
__isFragment?: undefined;
|
|
143
143
|
__isTeleport?: undefined;
|
|
144
144
|
__isSuspense?: undefined;
|
|
145
145
|
} & import('vue').ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<{
|
|
146
|
-
|
|
146
|
+
continuousValidation: {
|
|
147
147
|
type: BooleanConstructor;
|
|
148
148
|
default: boolean;
|
|
149
149
|
};
|
|
@@ -183,7 +183,7 @@ export declare const defineForm: <Schema extends FormSchema>(schema: Schema, pro
|
|
|
183
183
|
readonly: boolean;
|
|
184
184
|
template: FormTemplate<Schema>;
|
|
185
185
|
modelValue: Record<string, any>;
|
|
186
|
-
|
|
186
|
+
continuousValidation: boolean;
|
|
187
187
|
tag: string;
|
|
188
188
|
}, {}, string, {}> & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps & (new () => {
|
|
189
189
|
$slots: {
|
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare const createForm: (options: FormPluginOptions) => Plugin & Partia
|
|
|
11
11
|
export declare const useForm: <Schema extends FormSchema>(schema: Schema, options?: FormComposableOptions<Schema>) => {
|
|
12
12
|
VvForm: {
|
|
13
13
|
new (...args: any[]): import('vue').CreateComponentPublicInstance<Readonly<import("vue").ExtractPropTypes<{
|
|
14
|
-
|
|
14
|
+
continuousValidation: {
|
|
15
15
|
type: BooleanConstructor;
|
|
16
16
|
default: boolean;
|
|
17
17
|
};
|
|
@@ -48,7 +48,7 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
48
48
|
invalid: import("vue").ComputedRef<boolean>;
|
|
49
49
|
isReadonly: import("vue").Ref<boolean>;
|
|
50
50
|
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("invalid" | "valid" | "update:modelValue" | "submit" | "update:readonly")[], import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & Readonly<import("vue").ExtractPropTypes<{
|
|
51
|
-
|
|
51
|
+
continuousValidation: {
|
|
52
52
|
type: BooleanConstructor;
|
|
53
53
|
default: boolean;
|
|
54
54
|
};
|
|
@@ -78,7 +78,7 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
78
78
|
readonly: boolean;
|
|
79
79
|
template: FormTemplate<Schema>;
|
|
80
80
|
modelValue: Record<string, any>;
|
|
81
|
-
|
|
81
|
+
continuousValidation: boolean;
|
|
82
82
|
tag: string;
|
|
83
83
|
}, true, {}, {}, {
|
|
84
84
|
P: {};
|
|
@@ -88,7 +88,7 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
88
88
|
M: {};
|
|
89
89
|
Defaults: {};
|
|
90
90
|
}, Readonly<import("vue").ExtractPropTypes<{
|
|
91
|
-
|
|
91
|
+
continuousValidation: {
|
|
92
92
|
type: BooleanConstructor;
|
|
93
93
|
default: boolean;
|
|
94
94
|
};
|
|
@@ -128,14 +128,14 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
128
128
|
readonly: boolean;
|
|
129
129
|
template: FormTemplate<Schema>;
|
|
130
130
|
modelValue: Record<string, any>;
|
|
131
|
-
|
|
131
|
+
continuousValidation: boolean;
|
|
132
132
|
tag: string;
|
|
133
133
|
}>;
|
|
134
134
|
__isFragment?: undefined;
|
|
135
135
|
__isTeleport?: undefined;
|
|
136
136
|
__isSuspense?: undefined;
|
|
137
137
|
} & import('vue').ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<{
|
|
138
|
-
|
|
138
|
+
continuousValidation: {
|
|
139
139
|
type: BooleanConstructor;
|
|
140
140
|
default: boolean;
|
|
141
141
|
};
|
|
@@ -175,7 +175,7 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
175
175
|
readonly: boolean;
|
|
176
176
|
template: FormTemplate<Schema>;
|
|
177
177
|
modelValue: Record<string, any>;
|
|
178
|
-
|
|
178
|
+
continuousValidation: boolean;
|
|
179
179
|
tag: string;
|
|
180
180
|
}, {}, string, {}> & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps & (new () => {
|
|
181
181
|
$slots: {
|
|
@@ -501,7 +501,7 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
501
501
|
} | {
|
|
502
502
|
VvForm: {
|
|
503
503
|
new (...args: any[]): import('vue').CreateComponentPublicInstance<Readonly<import("vue").ExtractPropTypes<{
|
|
504
|
-
|
|
504
|
+
continuousValidation: {
|
|
505
505
|
type: BooleanConstructor;
|
|
506
506
|
default: boolean;
|
|
507
507
|
};
|
|
@@ -547,7 +547,7 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
547
547
|
invalid: import("vue").ComputedRef<boolean>;
|
|
548
548
|
isReadonly: import("vue").Ref<boolean>;
|
|
549
549
|
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("invalid" | "valid" | "update:modelValue" | "submit" | "update:readonly")[], import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & Readonly<import("vue").ExtractPropTypes<{
|
|
550
|
-
|
|
550
|
+
continuousValidation: {
|
|
551
551
|
type: BooleanConstructor;
|
|
552
552
|
default: boolean;
|
|
553
553
|
};
|
|
@@ -577,7 +577,7 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
577
577
|
readonly: boolean;
|
|
578
578
|
template: FormTemplate<AnyZodObject>;
|
|
579
579
|
modelValue: Record<string, any>;
|
|
580
|
-
|
|
580
|
+
continuousValidation: boolean;
|
|
581
581
|
tag: string;
|
|
582
582
|
}, true, {}, {}, {
|
|
583
583
|
P: {};
|
|
@@ -587,7 +587,7 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
587
587
|
M: {};
|
|
588
588
|
Defaults: {};
|
|
589
589
|
}, Readonly<import("vue").ExtractPropTypes<{
|
|
590
|
-
|
|
590
|
+
continuousValidation: {
|
|
591
591
|
type: BooleanConstructor;
|
|
592
592
|
default: boolean;
|
|
593
593
|
};
|
|
@@ -636,14 +636,14 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
636
636
|
readonly: boolean;
|
|
637
637
|
template: FormTemplate<AnyZodObject>;
|
|
638
638
|
modelValue: Record<string, any>;
|
|
639
|
-
|
|
639
|
+
continuousValidation: boolean;
|
|
640
640
|
tag: string;
|
|
641
641
|
}>;
|
|
642
642
|
__isFragment?: undefined;
|
|
643
643
|
__isTeleport?: undefined;
|
|
644
644
|
__isSuspense?: undefined;
|
|
645
645
|
} & import('vue').ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<{
|
|
646
|
-
|
|
646
|
+
continuousValidation: {
|
|
647
647
|
type: BooleanConstructor;
|
|
648
648
|
default: boolean;
|
|
649
649
|
};
|
|
@@ -692,7 +692,7 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
692
692
|
readonly: boolean;
|
|
693
693
|
template: FormTemplate<AnyZodObject>;
|
|
694
694
|
modelValue: Record<string, any>;
|
|
695
|
-
|
|
695
|
+
continuousValidation: boolean;
|
|
696
696
|
tag: string;
|
|
697
697
|
}, {}, string, {}> & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps & (new () => {
|
|
698
698
|
$slots: {
|
|
@@ -1075,7 +1075,7 @@ export type { InjectedFormData, InjectedFormWrapperData, InjectedFormFieldData,
|
|
|
1075
1075
|
export declare const formFactory: <Schema extends FormSchema>(schema: Schema, options?: FormComposableOptions<Schema>) => {
|
|
1076
1076
|
VvForm: {
|
|
1077
1077
|
new (...args: any[]): import('vue').CreateComponentPublicInstance<Readonly<import("vue").ExtractPropTypes<{
|
|
1078
|
-
|
|
1078
|
+
continuousValidation: {
|
|
1079
1079
|
type: BooleanConstructor;
|
|
1080
1080
|
default: boolean;
|
|
1081
1081
|
};
|
|
@@ -1112,7 +1112,7 @@ export declare const formFactory: <Schema extends FormSchema>(schema: Schema, op
|
|
|
1112
1112
|
invalid: import("vue").ComputedRef<boolean>;
|
|
1113
1113
|
isReadonly: import("vue").Ref<boolean>;
|
|
1114
1114
|
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("invalid" | "valid" | "update:modelValue" | "submit" | "update:readonly")[], import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & Readonly<import("vue").ExtractPropTypes<{
|
|
1115
|
-
|
|
1115
|
+
continuousValidation: {
|
|
1116
1116
|
type: BooleanConstructor;
|
|
1117
1117
|
default: boolean;
|
|
1118
1118
|
};
|
|
@@ -1142,7 +1142,7 @@ export declare const formFactory: <Schema extends FormSchema>(schema: Schema, op
|
|
|
1142
1142
|
readonly: boolean;
|
|
1143
1143
|
template: FormTemplate<Schema>;
|
|
1144
1144
|
modelValue: Record<string, any>;
|
|
1145
|
-
|
|
1145
|
+
continuousValidation: boolean;
|
|
1146
1146
|
tag: string;
|
|
1147
1147
|
}, true, {}, {}, {
|
|
1148
1148
|
P: {};
|
|
@@ -1152,7 +1152,7 @@ export declare const formFactory: <Schema extends FormSchema>(schema: Schema, op
|
|
|
1152
1152
|
M: {};
|
|
1153
1153
|
Defaults: {};
|
|
1154
1154
|
}, Readonly<import("vue").ExtractPropTypes<{
|
|
1155
|
-
|
|
1155
|
+
continuousValidation: {
|
|
1156
1156
|
type: BooleanConstructor;
|
|
1157
1157
|
default: boolean;
|
|
1158
1158
|
};
|
|
@@ -1192,14 +1192,14 @@ export declare const formFactory: <Schema extends FormSchema>(schema: Schema, op
|
|
|
1192
1192
|
readonly: boolean;
|
|
1193
1193
|
template: FormTemplate<Schema>;
|
|
1194
1194
|
modelValue: Record<string, any>;
|
|
1195
|
-
|
|
1195
|
+
continuousValidation: boolean;
|
|
1196
1196
|
tag: string;
|
|
1197
1197
|
}>;
|
|
1198
1198
|
__isFragment?: undefined;
|
|
1199
1199
|
__isTeleport?: undefined;
|
|
1200
1200
|
__isSuspense?: undefined;
|
|
1201
1201
|
} & import('vue').ComponentOptionsBase<Readonly<import("vue").ExtractPropTypes<{
|
|
1202
|
-
|
|
1202
|
+
continuousValidation: {
|
|
1203
1203
|
type: BooleanConstructor;
|
|
1204
1204
|
default: boolean;
|
|
1205
1205
|
};
|
|
@@ -1239,7 +1239,7 @@ export declare const formFactory: <Schema extends FormSchema>(schema: Schema, op
|
|
|
1239
1239
|
readonly: boolean;
|
|
1240
1240
|
template: FormTemplate<Schema>;
|
|
1241
1241
|
modelValue: Record<string, any>;
|
|
1242
|
-
|
|
1242
|
+
continuousValidation: boolean;
|
|
1243
1243
|
tag: string;
|
|
1244
1244
|
}, {}, string, {}> & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps & (new () => {
|
|
1245
1245
|
$slots: {
|
package/dist/index.es.js
CHANGED
|
@@ -330,7 +330,7 @@ const he = (e, s, t, o) => z({
|
|
|
330
330
|
), V = z({
|
|
331
331
|
name: "VvForm",
|
|
332
332
|
props: {
|
|
333
|
-
|
|
333
|
+
continuousValidation: {
|
|
334
334
|
type: Boolean,
|
|
335
335
|
default: !1
|
|
336
336
|
},
|
|
@@ -399,7 +399,7 @@ const he = (e, s, t, o) => z({
|
|
|
399
399
|
h("submit", i), (W = t == null ? void 0 : t.onSubmit) == null || W.call(t, i);
|
|
400
400
|
}
|
|
401
401
|
if (m === k.updated) {
|
|
402
|
-
if ((u.value || t != null && t.
|
|
402
|
+
if ((u.value || t != null && t.continuousValidation || c.continuousValidation) && await a(), !n.value || !c.modelValue || JSON.stringify(n.value) !== JSON.stringify(c.modelValue)) {
|
|
403
403
|
const i = E(n.value);
|
|
404
404
|
h("update:modelValue", i), (N = t == null ? void 0 : t.onUpdate) == null || N.call(t, i);
|
|
405
405
|
}
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(w,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("@vueuse/core"),require("zod")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","zod"],e):(w=typeof globalThis<"u"?globalThis:w||self,e(w["@volverjs/form-vue"]={},w.Vue,w.VueUseCore,w.zod))})(this,function(w,e,$,k){"use strict";function N(r){return Array.isArray(r)}function J(r){return typeof r<"u"}function G(r){return r===null}function L(r){return typeof r=="object"}function Z(r){return typeof r=="string"}function A(r){return typeof r>"u"}const M=/^[0-9]+$/,z=["__proto__","prototype","constructor"];function E(r,u,a){const d=J(a)?a:void 0;if(!L(r)||!Z(u))return d;const i=q(u);if(i.length!==0){for(const t of i){if(t==="*")continue;const s=function(l){return l.map(f=>A(f)||G(f)?f:N(f)?s(f):f[t])};if(N(r)&&!M.test(t)?r=s(r):r=r[t],A(r)||G(r))break}return A(r)?d:r}}function K(r,u,a){if(!L(r)||!Z(u))return;const d=q(u);if(d.length===0)return;const i=d.length;for(let t=0;t<i;t++){const s=d[t];if(t===i-1){r[s]=a;return}if(s==="*"&&N(r)){const l=d.slice(t+1).join(".");for(const f of r)K(f,l,a);return}A(r[s])&&(r[s]={}),r=r[s]}}function q(r){const u=r.split(/[.]|(?:\[(\d|\*)\])/).filter(a=>!!a);return u.some(a=>z.indexOf(a)!==-1)?[]:u}var c=(r=>(r.text="text",r.number="number",r.email="email",r.password="password",r.tel="tel",r.url="url",r.search="search",r.date="date",r.time="time",r.datetimeLocal="datetime-local",r.month="month",r.week="week",r.color="color",r.select="select",r.checkbox="checkbox",r.radio="radio",r.textarea="textarea",r.radioGroup="radioGroup",r.checkboxGroup="checkboxGroup",r.combobox="combobox",r.custom="custom",r))(c||{}),O=(r=>(r.invalid="invalid",r.valid="valid",r.submitting="submitting",r.updated="updated",r.unknown="unknown",r))(O||{});const T=(r,u,a,d)=>e.defineComponent({name:"VvFormField",props:{type:{type:String,validator:i=>Object.values(c).includes(i),default:c.custom},is:{type:[Object,String],default:void 0},name:{type:[String,Number,Boolean,Symbol],required:!0},props:{type:[Object,Function],default:()=>({})},showValid:{type:Boolean,default:!1},defaultValue:{type:[String,Number,Boolean,Array,Object],default:void 0},lazyLoad:{type:Boolean,default:!1},readonly:{type:Boolean,default:void 0}},emits:["invalid","valid","update:formData","update:modelValue"],expose:["invalid","invalidLabel","errors"],setup(i,{slots:t,emit:s}){const l=e.computed({get(){if(n!=null&&n.formData)return E(Object(n.formData.value),String(i.name))},set(o){n!=null&&n.formData&&(K(Object(n.formData.value),String(i.name),o),s("update:modelValue",{newValue:l.value,formData:n==null?void 0:n.formData}))}});e.onMounted(()=>{l.value===void 0&&i.defaultValue!==void 0&&(l.value=i.defaultValue)}),e.onBeforeUnmount(()=>{y(),h()});const f=e.inject(u,void 0);f&&f.fields.value.add(i.name);const n=e.inject(r),{props:v,name:V}=e.toRefs(i),p=e.computed(()=>{if(n!=null&&n.errors.value)return E(n.errors.value,String(i.name))}),g=e.computed(()=>{var o;return(o=p.value)==null?void 0:o._errors}),m=e.computed(()=>p.value!==void 0),y=e.watch(m,()=>{m.value?(s("invalid",g.value),f&&f.errors.value.set(i.name,{_errors:g.value})):(s("valid",l.value),f&&f.errors.value.delete(i.name))}),h=e.watch(()=>n==null?void 0:n.formData,()=>{s("update:formData",n==null?void 0:n.formData)},{deep:!0}),b=o=>{l.value=o},x=e.computed(()=>{let o=v.value;return typeof o=="function"&&(o=o(n==null?void 0:n.formData)),Object.keys(o).reduce((U,C)=>(U[C]=e.unref(o[C]),U),{})}),S=e.computed(()=>n!=null&&n.readonly.value?!0:x.value.readonly??i.readonly),I=e.computed(()=>({...x.value,name:x.value.name??i.name,invalid:m.value,valid:i.showValid?!!(!m.value&&l.value):void 0,type:(o=>{if([c.text,c.number,c.email,c.password,c.tel,c.url,c.search,c.date,c.time,c.datetimeLocal,c.month,c.week,c.color].includes(o))return o})(i.type),invalidLabel:g.value,modelValue:l.value,readonly:S.value,"onUpdate:modelValue":b}));return e.provide(a,{name:e.readonly(V),errors:e.readonly(p)}),{component:e.computed(()=>{if(i.type===c.custom)return{render(){var o;return((o=t.default)==null?void 0:o.call(t,{modelValue:l.value,onUpdate:b,submit:n==null?void 0:n.submit,validate:n==null?void 0:n.validate,invalid:m.value,invalidLabel:g.value,formData:n==null?void 0:n.formData.value,formErrors:n==null?void 0:n.errors.value,errors:p.value,readonly:S.value}))??t.defalut}};if(!((d==null?void 0:d.lazyLoad)??i.lazyLoad)){let o;switch(i.type){case c.select:o=e.resolveComponent("VvSelect");break;case c.checkbox:o=e.resolveComponent("VvCheckbox");break;case c.radio:o=e.resolveComponent("VvRadio");break;case c.textarea:o=e.resolveComponent("VvTextarea");break;case c.radioGroup:o=e.resolveComponent("VvRadioGroup");break;case c.checkboxGroup:o=e.resolveComponent("VvCheckboxGroup");break;case c.combobox:o=e.resolveComponent("VvCombobox");break;default:o=e.resolveComponent("VvInputText")}if(typeof o!="string")return o;console.warn(`[form-vue warn]: ${o} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`)}return e.defineAsyncComponent(async()=>{switch(d!=null&&d.sideEffects&&await Promise.resolve(d.sideEffects(i.type)),i.type){case c.textarea:return import("@volverjs/ui-vue/vv-textarea");case c.radio:return import("@volverjs/ui-vue/vv-radio");case c.radioGroup:return import("@volverjs/ui-vue/vv-radio-group");case c.checkbox:return import("@volverjs/ui-vue/vv-checkbox");case c.checkboxGroup:return import("@volverjs/ui-vue/vv-checkbox-group");case c.select:return import("@volverjs/ui-vue/vv-select");case c.combobox:return import("@volverjs/ui-vue/vv-combobox")}return import("@volverjs/ui-vue/vv-input-text")})}),hasProps:I,invalid:m}},render(){return this.is?e.h(this.is,this.hasProps,this.$slots):this.type===c.custom?e.h(this.component,null,this.$slots):e.h(this.component,this.hasProps,this.$slots)}}),W=(r,u={})=>{const a=t=>{let s=t;for(;s instanceof k.ZodEffects;)s=s.innerType();return s instanceof k.ZodOptional&&(s=s._def.innerType),s},d=a(r);return{...(d instanceof k.ZodObject?d._def.unknownKeys==="passthrough":!1)?u:{},...Object.fromEntries(Object.entries(d.shape).map(([t,s])=>{const l=u[t];let f=a(s),n;if(f instanceof k.ZodDefault&&(n=f._def.defaultValue(),f=f._def.innerType),l===null&&f instanceof k.ZodNullable)return[t,l];if(f instanceof k.ZodSchema){const v=s.safeParse(l);if(v.success)return[t,v.data??n]}if(f instanceof k.ZodArray&&Array.isArray(l)&&l.length){const v=a(f._def.type);if(v instanceof k.ZodObject)return[t,l.map(V=>W(v,V&&typeof V=="object"?V:void 0))??n]}return f instanceof k.ZodObject?[t,W(f,l&&typeof l=="object"?l:n)]:[t,n]}))}},P=(r,u,a,d)=>{const i=e.ref(),t=e.ref(),s=e.computed(()=>t.value===O.invalid),l=e.ref(),f=e.ref(!1),n=async(m=l.value)=>{if(f.value)return!0;const y=await r.safeParseAsync(m);return y.success?(i.value=void 0,t.value=O.valid,l.value=y.data,!0):(i.value=y.error.format(),t.value=O.invalid,!1)},v=async()=>f.value||!await n()?!1:(t.value=O.submitting,!0),{ignoreUpdates:V,stop:p}=$.watchIgnorable(l,()=>{t.value=O.updated},{deep:!0,eventFilter:$.throttleFilter((a==null?void 0:a.updateThrottle)??500)}),g=e.defineComponent({name:"VvForm",props:{continuosValidation:{type:Boolean,default:!1},modelValue:{type:Object,default:()=>({})},readonly:{type:Boolean,default:(a==null?void 0:a.readonly)??!1},tag:{type:String,default:"form"},template:{type:[Array,Function],default:void 0}},emits:["invalid","valid","submit","update:modelValue","update:readonly"],expose:["submit","validate","errors","status","valid","invalid","readonly"],setup(m,{emit:y}){return l.value=W(r,e.toRaw(m.modelValue)),e.watch(()=>m.modelValue,h=>{if(h){const b=e.isProxy(h)?e.toRaw(h):h;if(JSON.stringify(b)===JSON.stringify(e.toRaw(l.value)))return;l.value=typeof(b==null?void 0:b.clone)=="function"?b.clone():JSON.parse(JSON.stringify(b))}},{deep:!0}),e.watch(t,async h=>{var b,x,S,I,R;if(h===O.invalid){const o=e.toRaw(i.value);y("invalid",o),(b=a==null?void 0:a.onInvalid)==null||b.call(a,o);return}if(h===O.valid){const o=e.toRaw(l.value);y("valid",o),(x=a==null?void 0:a.onValid)==null||x.call(a,o),y("update:modelValue",o),(S=a==null?void 0:a.onUpdate)==null||S.call(a,o);return}if(h===O.submitting){const o=e.toRaw(l.value);y("submit",o),(I=a==null?void 0:a.onSubmit)==null||I.call(a,o)}if(h===O.updated){if((i.value||a!=null&&a.continuosValidation||m.continuosValidation)&&await n(),!l.value||!m.modelValue||JSON.stringify(l.value)!==JSON.stringify(m.modelValue)){const o=e.toRaw(l.value);y("update:modelValue",o),(R=a==null?void 0:a.onUpdate)==null||R.call(a,o)}t.value===O.updated&&(t.value=O.unknown)}}),e.onMounted(()=>{f.value=m.readonly}),e.watch(()=>m.readonly,h=>{f.value=h}),e.watch(f,h=>{h!==m.readonly&&y("update:readonly",f.value)}),e.provide(u,{formData:l,submit:v,validate:n,ignoreUpdates:V,stopUpdatesWatch:p,errors:e.readonly(i),status:e.readonly(t),invalid:s,readonly:f}),{formData:l,submit:v,validate:n,ignoreUpdates:V,stopUpdatesWatch:p,errors:e.readonly(i),status:e.readonly(t),invalid:s,isReadonly:f}},render(){const m=()=>{var y,h;return((h=(y=this.$slots)==null?void 0:y.default)==null?void 0:h.call(y,{formData:this.formData,submit:this.submit,validate:this.validate,ignoreUpdates:this.ignoreUpdates,stopUpdatesWatch:this.stopUpdatesWatch,errors:this.errors,status:this.status,invalid:this.invalid,readonly:this.isReadonly}))??this.$slots.default};return e.h(this.tag,{onSubmit:e.withModifiers(this.submit,["prevent"])},(this.template??(a==null?void 0:a.template))&&d?[e.h(d,{schema:this.template??(a==null?void 0:a.template)},{default:m})]:{default:m})}});return{errors:i,status:t,invalid:s,readonly:f,formData:l,validate:n,submit:v,ignoreUpdates:V,stopUpdatesWatch:p,VvForm:g}},H=(r,u)=>e.defineComponent({name:"VvFormWrapper",props:{name:{type:String,required:!0},tag:{type:String,default:void 0}},emits:["invalid","valid"],expose:["fields","invalid"],setup(d,{emit:i}){const t=e.inject(r),s=e.inject(u,void 0),l=e.ref(new Set),f=e.ref(new Map),{name:n}=e.toRefs(d);e.provide(u,{name:e.readonly(n),errors:f,fields:l}),e.watch(l,V=>{s!=null&&s.fields&&V.forEach(p=>{s==null||s.fields.value.add(p)})},{deep:!0}),e.watch(()=>new Map(f.value),(V,p)=>{s!=null&&s.errors&&(Array.from(p.keys()).forEach(g=>{s.errors.value.delete(g)}),Array.from(V.keys()).forEach(g=>{const m=V.get(g);m&&s.errors.value.set(g,m)}))},{deep:!0});const v=e.computed(()=>t!=null&&t.invalid.value?f.value.size>0:!1);return e.watch(v,()=>{v.value?i("invalid"):i("valid")}),{formData:t==null?void 0:t.formData,errors:t==null?void 0:t.errors,submit:t==null?void 0:t.submit,validate:t==null?void 0:t.validate,invalid:v,fields:l,fieldsErrors:f}},render(){var d,i;return this.tag?e.h(this.tag,null,{default:()=>{var t,s;return((s=(t=this.$slots).default)==null?void 0:s.call(t,{invalid:this.invalid,formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}):((i=(d=this.$slots).default)==null?void 0:i.call(d,{invalid:this.invalid,formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}),Q=(r,u)=>{const a=e.defineComponent({name:"VvFormTemplate",props:{schema:{type:[Array,Function],required:!0},scope:{type:Object,default:()=>({})}},setup(d,{slots:i}){const t=e.inject(r);if(t!=null&&t.formData)return()=>{var n;const s=typeof d.schema=="function"?d.schema(t,d.scope):d.schema;let l;const f=s.reduce((v,V)=>{const p=typeof V=="function"?V(t,d.scope):V,{vvIs:g,vvName:m,vvSlots:y,vvChildren:h,vvIf:b,vvElseIf:x,vvType:S,vvDefaultValue:I,vvShowValid:R,vvContent:o,...U}=p;if(b!==void 0){if(typeof b=="string"?l=!!E(Object(t.formData.value),b):typeof b=="function"?l=e.unref(b(t)):l=e.unref(b),!l)return v}else if(x!==void 0&&l!==void 0){if(l||(typeof x=="string"?l=!!E(Object(t.formData.value),x):typeof x=="function"?l=e.unref(x(t)):l=e.unref(x),!l))return v}else l=void 0;const C=h?{default:j=>e.h(a,{schema:h,scope:j})}:void 0;return m?(v.push(e.h(u,{name:m,is:g,type:S,defaultValue:I,showValid:R,props:U},y??C??o)),v):g?(v.push(e.h(g,U,y??C??o)),v):(C&&v.push(C.default(d.scope)),v)},[]);return f.push((n=i==null?void 0:i.default)==null?void 0:n.call(i,{formData:t==null?void 0:t.formData.value,submit:t==null?void 0:t.submit,validate:t==null?void 0:t.validate,errors:t==null?void 0:t.errors.value,status:t==null?void 0:t.status.value,invalid:t==null?void 0:t.invalid.value})),f}}});return a},B=(r,u={})=>{const a=Symbol(),d=Symbol(),i=Symbol(),t=H(a,d),s=T(a,d,i,u),l=Q(a,s),{VvForm:f,errors:n,status:v,invalid:V,readonly:p,formData:g,validate:m,submit:y,ignoreUpdates:h,stopUpdatesWatch:b}=P(r,a,u,l);return{VvForm:f,VvFormWrapper:t,VvFormField:s,VvFormTemplate:l,formInjectionKey:a,formWrapperInjectionKey:d,formFieldInjectionKey:i,errors:n,status:v,invalid:V,readonly:p,formData:g,validate:m,submit:y,ignoreUpdates:h,stopUpdatesWatch:b}},_=Symbol(),X=r=>{let u={};return r.schema&&(u=B(r.schema,r)),{...u,install(a,{global:d=!1}={}){a.provide(_,r),d&&(a.config.globalProperties.$vvForm=r,u!=null&&u.VvForm&&a.component("VvForm",u.VvForm),u!=null&&u.VvFormWrapper&&a.component("VvFormWrapper",u.VvFormWrapper),u!=null&&u.VvFormField&&a.component("VvFormField",u.VvFormField),u!=null&&u.VvFormTemplate&&a.component("VvFormTemplate",u.VvFormTemplate))}}},Y=(r,u={})=>e.getCurrentInstance()?B(r,{...e.inject(_,{}),...u}):B(r,u),D=(r,u={})=>B(r,u);w.FormFieldType=c,w.createForm=X,w.defaultObjectBySchema=W,w.formFactory=D,w.pluginInjectionKey=_,w.useForm=Y,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(w,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("@vueuse/core"),require("zod")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","zod"],e):(w=typeof globalThis<"u"?globalThis:w||self,e(w["@volverjs/form-vue"]={},w.Vue,w.VueUseCore,w.zod))})(this,function(w,e,$,k){"use strict";function N(r){return Array.isArray(r)}function J(r){return typeof r<"u"}function G(r){return r===null}function L(r){return typeof r=="object"}function Z(r){return typeof r=="string"}function A(r){return typeof r>"u"}const M=/^[0-9]+$/,z=["__proto__","prototype","constructor"];function E(r,s,a){const d=J(a)?a:void 0;if(!L(r)||!Z(s))return d;const i=q(s);if(i.length!==0){for(const t of i){if(t==="*")continue;const u=function(l){return l.map(f=>A(f)||G(f)?f:N(f)?u(f):f[t])};if(N(r)&&!M.test(t)?r=u(r):r=r[t],A(r)||G(r))break}return A(r)?d:r}}function K(r,s,a){if(!L(r)||!Z(s))return;const d=q(s);if(d.length===0)return;const i=d.length;for(let t=0;t<i;t++){const u=d[t];if(t===i-1){r[u]=a;return}if(u==="*"&&N(r)){const l=d.slice(t+1).join(".");for(const f of r)K(f,l,a);return}A(r[u])&&(r[u]={}),r=r[u]}}function q(r){const s=r.split(/[.]|(?:\[(\d|\*)\])/).filter(a=>!!a);return s.some(a=>z.indexOf(a)!==-1)?[]:s}var c=(r=>(r.text="text",r.number="number",r.email="email",r.password="password",r.tel="tel",r.url="url",r.search="search",r.date="date",r.time="time",r.datetimeLocal="datetime-local",r.month="month",r.week="week",r.color="color",r.select="select",r.checkbox="checkbox",r.radio="radio",r.textarea="textarea",r.radioGroup="radioGroup",r.checkboxGroup="checkboxGroup",r.combobox="combobox",r.custom="custom",r))(c||{}),O=(r=>(r.invalid="invalid",r.valid="valid",r.submitting="submitting",r.updated="updated",r.unknown="unknown",r))(O||{});const T=(r,s,a,d)=>e.defineComponent({name:"VvFormField",props:{type:{type:String,validator:i=>Object.values(c).includes(i),default:c.custom},is:{type:[Object,String],default:void 0},name:{type:[String,Number,Boolean,Symbol],required:!0},props:{type:[Object,Function],default:()=>({})},showValid:{type:Boolean,default:!1},defaultValue:{type:[String,Number,Boolean,Array,Object],default:void 0},lazyLoad:{type:Boolean,default:!1},readonly:{type:Boolean,default:void 0}},emits:["invalid","valid","update:formData","update:modelValue"],expose:["invalid","invalidLabel","errors"],setup(i,{slots:t,emit:u}){const l=e.computed({get(){if(n!=null&&n.formData)return E(Object(n.formData.value),String(i.name))},set(o){n!=null&&n.formData&&(K(Object(n.formData.value),String(i.name),o),u("update:modelValue",{newValue:l.value,formData:n==null?void 0:n.formData}))}});e.onMounted(()=>{l.value===void 0&&i.defaultValue!==void 0&&(l.value=i.defaultValue)}),e.onBeforeUnmount(()=>{y(),h()});const f=e.inject(s,void 0);f&&f.fields.value.add(i.name);const n=e.inject(r),{props:v,name:V}=e.toRefs(i),p=e.computed(()=>{if(n!=null&&n.errors.value)return E(n.errors.value,String(i.name))}),g=e.computed(()=>{var o;return(o=p.value)==null?void 0:o._errors}),m=e.computed(()=>p.value!==void 0),y=e.watch(m,()=>{m.value?(u("invalid",g.value),f&&f.errors.value.set(i.name,{_errors:g.value})):(u("valid",l.value),f&&f.errors.value.delete(i.name))}),h=e.watch(()=>n==null?void 0:n.formData,()=>{u("update:formData",n==null?void 0:n.formData)},{deep:!0}),b=o=>{l.value=o},x=e.computed(()=>{let o=v.value;return typeof o=="function"&&(o=o(n==null?void 0:n.formData)),Object.keys(o).reduce((U,C)=>(U[C]=e.unref(o[C]),U),{})}),S=e.computed(()=>n!=null&&n.readonly.value?!0:x.value.readonly??i.readonly),I=e.computed(()=>({...x.value,name:x.value.name??i.name,invalid:m.value,valid:i.showValid?!!(!m.value&&l.value):void 0,type:(o=>{if([c.text,c.number,c.email,c.password,c.tel,c.url,c.search,c.date,c.time,c.datetimeLocal,c.month,c.week,c.color].includes(o))return o})(i.type),invalidLabel:g.value,modelValue:l.value,readonly:S.value,"onUpdate:modelValue":b}));return e.provide(a,{name:e.readonly(V),errors:e.readonly(p)}),{component:e.computed(()=>{if(i.type===c.custom)return{render(){var o;return((o=t.default)==null?void 0:o.call(t,{modelValue:l.value,onUpdate:b,submit:n==null?void 0:n.submit,validate:n==null?void 0:n.validate,invalid:m.value,invalidLabel:g.value,formData:n==null?void 0:n.formData.value,formErrors:n==null?void 0:n.errors.value,errors:p.value,readonly:S.value}))??t.defalut}};if(!((d==null?void 0:d.lazyLoad)??i.lazyLoad)){let o;switch(i.type){case c.select:o=e.resolveComponent("VvSelect");break;case c.checkbox:o=e.resolveComponent("VvCheckbox");break;case c.radio:o=e.resolveComponent("VvRadio");break;case c.textarea:o=e.resolveComponent("VvTextarea");break;case c.radioGroup:o=e.resolveComponent("VvRadioGroup");break;case c.checkboxGroup:o=e.resolveComponent("VvCheckboxGroup");break;case c.combobox:o=e.resolveComponent("VvCombobox");break;default:o=e.resolveComponent("VvInputText")}if(typeof o!="string")return o;console.warn(`[form-vue warn]: ${o} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`)}return e.defineAsyncComponent(async()=>{switch(d!=null&&d.sideEffects&&await Promise.resolve(d.sideEffects(i.type)),i.type){case c.textarea:return import("@volverjs/ui-vue/vv-textarea");case c.radio:return import("@volverjs/ui-vue/vv-radio");case c.radioGroup:return import("@volverjs/ui-vue/vv-radio-group");case c.checkbox:return import("@volverjs/ui-vue/vv-checkbox");case c.checkboxGroup:return import("@volverjs/ui-vue/vv-checkbox-group");case c.select:return import("@volverjs/ui-vue/vv-select");case c.combobox:return import("@volverjs/ui-vue/vv-combobox")}return import("@volverjs/ui-vue/vv-input-text")})}),hasProps:I,invalid:m}},render(){return this.is?e.h(this.is,this.hasProps,this.$slots):this.type===c.custom?e.h(this.component,null,this.$slots):e.h(this.component,this.hasProps,this.$slots)}}),W=(r,s={})=>{const a=t=>{let u=t;for(;u instanceof k.ZodEffects;)u=u.innerType();return u instanceof k.ZodOptional&&(u=u._def.innerType),u},d=a(r);return{...(d instanceof k.ZodObject?d._def.unknownKeys==="passthrough":!1)?s:{},...Object.fromEntries(Object.entries(d.shape).map(([t,u])=>{const l=s[t];let f=a(u),n;if(f instanceof k.ZodDefault&&(n=f._def.defaultValue(),f=f._def.innerType),l===null&&f instanceof k.ZodNullable)return[t,l];if(f instanceof k.ZodSchema){const v=u.safeParse(l);if(v.success)return[t,v.data??n]}if(f instanceof k.ZodArray&&Array.isArray(l)&&l.length){const v=a(f._def.type);if(v instanceof k.ZodObject)return[t,l.map(V=>W(v,V&&typeof V=="object"?V:void 0))??n]}return f instanceof k.ZodObject?[t,W(f,l&&typeof l=="object"?l:n)]:[t,n]}))}},P=(r,s,a,d)=>{const i=e.ref(),t=e.ref(),u=e.computed(()=>t.value===O.invalid),l=e.ref(),f=e.ref(!1),n=async(m=l.value)=>{if(f.value)return!0;const y=await r.safeParseAsync(m);return y.success?(i.value=void 0,t.value=O.valid,l.value=y.data,!0):(i.value=y.error.format(),t.value=O.invalid,!1)},v=async()=>f.value||!await n()?!1:(t.value=O.submitting,!0),{ignoreUpdates:V,stop:p}=$.watchIgnorable(l,()=>{t.value=O.updated},{deep:!0,eventFilter:$.throttleFilter((a==null?void 0:a.updateThrottle)??500)}),g=e.defineComponent({name:"VvForm",props:{continuousValidation:{type:Boolean,default:!1},modelValue:{type:Object,default:()=>({})},readonly:{type:Boolean,default:(a==null?void 0:a.readonly)??!1},tag:{type:String,default:"form"},template:{type:[Array,Function],default:void 0}},emits:["invalid","valid","submit","update:modelValue","update:readonly"],expose:["submit","validate","errors","status","valid","invalid","readonly"],setup(m,{emit:y}){return l.value=W(r,e.toRaw(m.modelValue)),e.watch(()=>m.modelValue,h=>{if(h){const b=e.isProxy(h)?e.toRaw(h):h;if(JSON.stringify(b)===JSON.stringify(e.toRaw(l.value)))return;l.value=typeof(b==null?void 0:b.clone)=="function"?b.clone():JSON.parse(JSON.stringify(b))}},{deep:!0}),e.watch(t,async h=>{var b,x,S,I,R;if(h===O.invalid){const o=e.toRaw(i.value);y("invalid",o),(b=a==null?void 0:a.onInvalid)==null||b.call(a,o);return}if(h===O.valid){const o=e.toRaw(l.value);y("valid",o),(x=a==null?void 0:a.onValid)==null||x.call(a,o),y("update:modelValue",o),(S=a==null?void 0:a.onUpdate)==null||S.call(a,o);return}if(h===O.submitting){const o=e.toRaw(l.value);y("submit",o),(I=a==null?void 0:a.onSubmit)==null||I.call(a,o)}if(h===O.updated){if((i.value||a!=null&&a.continuousValidation||m.continuousValidation)&&await n(),!l.value||!m.modelValue||JSON.stringify(l.value)!==JSON.stringify(m.modelValue)){const o=e.toRaw(l.value);y("update:modelValue",o),(R=a==null?void 0:a.onUpdate)==null||R.call(a,o)}t.value===O.updated&&(t.value=O.unknown)}}),e.onMounted(()=>{f.value=m.readonly}),e.watch(()=>m.readonly,h=>{f.value=h}),e.watch(f,h=>{h!==m.readonly&&y("update:readonly",f.value)}),e.provide(s,{formData:l,submit:v,validate:n,ignoreUpdates:V,stopUpdatesWatch:p,errors:e.readonly(i),status:e.readonly(t),invalid:u,readonly:f}),{formData:l,submit:v,validate:n,ignoreUpdates:V,stopUpdatesWatch:p,errors:e.readonly(i),status:e.readonly(t),invalid:u,isReadonly:f}},render(){const m=()=>{var y,h;return((h=(y=this.$slots)==null?void 0:y.default)==null?void 0:h.call(y,{formData:this.formData,submit:this.submit,validate:this.validate,ignoreUpdates:this.ignoreUpdates,stopUpdatesWatch:this.stopUpdatesWatch,errors:this.errors,status:this.status,invalid:this.invalid,readonly:this.isReadonly}))??this.$slots.default};return e.h(this.tag,{onSubmit:e.withModifiers(this.submit,["prevent"])},(this.template??(a==null?void 0:a.template))&&d?[e.h(d,{schema:this.template??(a==null?void 0:a.template)},{default:m})]:{default:m})}});return{errors:i,status:t,invalid:u,readonly:f,formData:l,validate:n,submit:v,ignoreUpdates:V,stopUpdatesWatch:p,VvForm:g}},H=(r,s)=>e.defineComponent({name:"VvFormWrapper",props:{name:{type:String,required:!0},tag:{type:String,default:void 0}},emits:["invalid","valid"],expose:["fields","invalid"],setup(d,{emit:i}){const t=e.inject(r),u=e.inject(s,void 0),l=e.ref(new Set),f=e.ref(new Map),{name:n}=e.toRefs(d);e.provide(s,{name:e.readonly(n),errors:f,fields:l}),e.watch(l,V=>{u!=null&&u.fields&&V.forEach(p=>{u==null||u.fields.value.add(p)})},{deep:!0}),e.watch(()=>new Map(f.value),(V,p)=>{u!=null&&u.errors&&(Array.from(p.keys()).forEach(g=>{u.errors.value.delete(g)}),Array.from(V.keys()).forEach(g=>{const m=V.get(g);m&&u.errors.value.set(g,m)}))},{deep:!0});const v=e.computed(()=>t!=null&&t.invalid.value?f.value.size>0:!1);return e.watch(v,()=>{v.value?i("invalid"):i("valid")}),{formData:t==null?void 0:t.formData,errors:t==null?void 0:t.errors,submit:t==null?void 0:t.submit,validate:t==null?void 0:t.validate,invalid:v,fields:l,fieldsErrors:f}},render(){var d,i;return this.tag?e.h(this.tag,null,{default:()=>{var t,u;return((u=(t=this.$slots).default)==null?void 0:u.call(t,{invalid:this.invalid,formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}):((i=(d=this.$slots).default)==null?void 0:i.call(d,{invalid:this.invalid,formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}),Q=(r,s)=>{const a=e.defineComponent({name:"VvFormTemplate",props:{schema:{type:[Array,Function],required:!0},scope:{type:Object,default:()=>({})}},setup(d,{slots:i}){const t=e.inject(r);if(t!=null&&t.formData)return()=>{var n;const u=typeof d.schema=="function"?d.schema(t,d.scope):d.schema;let l;const f=u.reduce((v,V)=>{const p=typeof V=="function"?V(t,d.scope):V,{vvIs:g,vvName:m,vvSlots:y,vvChildren:h,vvIf:b,vvElseIf:x,vvType:S,vvDefaultValue:I,vvShowValid:R,vvContent:o,...U}=p;if(b!==void 0){if(typeof b=="string"?l=!!E(Object(t.formData.value),b):typeof b=="function"?l=e.unref(b(t)):l=e.unref(b),!l)return v}else if(x!==void 0&&l!==void 0){if(l||(typeof x=="string"?l=!!E(Object(t.formData.value),x):typeof x=="function"?l=e.unref(x(t)):l=e.unref(x),!l))return v}else l=void 0;const C=h?{default:j=>e.h(a,{schema:h,scope:j})}:void 0;return m?(v.push(e.h(s,{name:m,is:g,type:S,defaultValue:I,showValid:R,props:U},y??C??o)),v):g?(v.push(e.h(g,U,y??C??o)),v):(C&&v.push(C.default(d.scope)),v)},[]);return f.push((n=i==null?void 0:i.default)==null?void 0:n.call(i,{formData:t==null?void 0:t.formData.value,submit:t==null?void 0:t.submit,validate:t==null?void 0:t.validate,errors:t==null?void 0:t.errors.value,status:t==null?void 0:t.status.value,invalid:t==null?void 0:t.invalid.value})),f}}});return a},B=(r,s={})=>{const a=Symbol(),d=Symbol(),i=Symbol(),t=H(a,d),u=T(a,d,i,s),l=Q(a,u),{VvForm:f,errors:n,status:v,invalid:V,readonly:p,formData:g,validate:m,submit:y,ignoreUpdates:h,stopUpdatesWatch:b}=P(r,a,s,l);return{VvForm:f,VvFormWrapper:t,VvFormField:u,VvFormTemplate:l,formInjectionKey:a,formWrapperInjectionKey:d,formFieldInjectionKey:i,errors:n,status:v,invalid:V,readonly:p,formData:g,validate:m,submit:y,ignoreUpdates:h,stopUpdatesWatch:b}},_=Symbol(),X=r=>{let s={};return r.schema&&(s=B(r.schema,r)),{...s,install(a,{global:d=!1}={}){a.provide(_,r),d&&(a.config.globalProperties.$vvForm=r,s!=null&&s.VvForm&&a.component("VvForm",s.VvForm),s!=null&&s.VvFormWrapper&&a.component("VvFormWrapper",s.VvFormWrapper),s!=null&&s.VvFormField&&a.component("VvFormField",s.VvFormField),s!=null&&s.VvFormTemplate&&a.component("VvFormTemplate",s.VvFormTemplate))}}},Y=(r,s={})=>e.getCurrentInstance()?B(r,{...e.inject(_,{}),...s}):B(r,s),D=(r,s={})=>B(r,s);w.FormFieldType=c,w.createForm=X,w.defaultObjectBySchema=W,w.formFactory=D,w.pluginInjectionKey=_,w.useForm=Y,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
|
package/dist/types.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export type FormFieldComponentOptions = {
|
|
|
10
10
|
};
|
|
11
11
|
export type FormComponentOptions<Schema> = {
|
|
12
12
|
updateThrottle?: number;
|
|
13
|
-
|
|
13
|
+
continuousValidation?: boolean;
|
|
14
14
|
readonly?: boolean;
|
|
15
15
|
template?: Schema extends FormSchema ? FormTemplate<Schema> : never;
|
|
16
16
|
onUpdate?: Schema extends FormSchema ? (data?: Partial<z.infer<Schema>>) => void : never;
|
package/package.json
CHANGED
package/src/VvForm.ts
CHANGED
|
@@ -86,7 +86,7 @@ export const defineForm = <Schema extends FormSchema>(
|
|
|
86
86
|
const component = defineComponent({
|
|
87
87
|
name: 'VvForm',
|
|
88
88
|
props: {
|
|
89
|
-
|
|
89
|
+
continuousValidation: {
|
|
90
90
|
type: Boolean,
|
|
91
91
|
default: false,
|
|
92
92
|
},
|
|
@@ -176,8 +176,8 @@ export const defineForm = <Schema extends FormSchema>(
|
|
|
176
176
|
if (newValue === FormStatus.updated) {
|
|
177
177
|
if (
|
|
178
178
|
errors.value ||
|
|
179
|
-
options?.
|
|
180
|
-
props.
|
|
179
|
+
options?.continuousValidation ||
|
|
180
|
+
props.continuousValidation
|
|
181
181
|
) {
|
|
182
182
|
await validate()
|
|
183
183
|
}
|
package/src/types.ts
CHANGED
|
@@ -15,7 +15,7 @@ export type FormFieldComponentOptions = {
|
|
|
15
15
|
|
|
16
16
|
export type FormComponentOptions<Schema> = {
|
|
17
17
|
updateThrottle?: number
|
|
18
|
-
|
|
18
|
+
continuousValidation?: boolean
|
|
19
19
|
readonly?: boolean
|
|
20
20
|
template?: Schema extends FormSchema ? FormTemplate<Schema> : never
|
|
21
21
|
onUpdate?: Schema extends FormSchema
|