@volverjs/form-vue 0.0.14 → 1.0.0-beta.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/dist/index.es.js +58 -58
- package/dist/index.umd.js +1 -1
- package/dist/src/VvForm.d.ts +8 -8
- package/dist/src/VvFormTemplate.d.ts +2 -2
- package/dist/src/VvFormWrapper.d.ts +8 -8
- package/dist/src/index.d.ts +54 -54
- package/dist/src/types.d.ts +4 -5
- package/package.json +8 -8
- package/src/VvForm.ts +8 -8
- package/src/VvFormTemplate.ts +2 -2
- package/src/VvFormWrapper.ts +2 -2
- package/src/types.ts +5 -7
package/dist/index.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { defineComponent as W, computed as g, onMounted as D, onBeforeUnmount as j, inject as
|
|
1
|
+
import { defineComponent as W, computed as g, onMounted as D, onBeforeUnmount as j, inject as E, toRefs as R, watch as A, unref as _, provide as M, readonly as p, resolveComponent as w, defineAsyncComponent as F, h as x, ref as $, toRaw as S, isProxy as ee, withModifiers as re, getCurrentInstance as te } from "vue";
|
|
2
2
|
import { watchThrottled as ae } from "@vueuse/core";
|
|
3
3
|
import { ZodObject as K, ZodDefault as ue, ZodNullable as ne, ZodSchema as le, ZodArray as se, ZodEffects as ie, ZodOptional as fe } from "zod";
|
|
4
4
|
function U(e) {
|
|
@@ -123,17 +123,17 @@ const ce = (e, l, t, f) => W({
|
|
|
123
123
|
D(() => {
|
|
124
124
|
i.value === void 0 && n.defaultValue !== void 0 && (i.value = n.defaultValue);
|
|
125
125
|
}), j(() => {
|
|
126
|
-
|
|
126
|
+
O(), k();
|
|
127
127
|
});
|
|
128
|
-
const s =
|
|
128
|
+
const s = E(l, void 0);
|
|
129
129
|
s && s.fields.value.add(n.name);
|
|
130
|
-
const a =
|
|
130
|
+
const a = E(e), { props: o, name: h } = R(n), y = g(() => {
|
|
131
131
|
if (a != null && a.errors.value)
|
|
132
132
|
return G(a.errors.value, String(n.name));
|
|
133
133
|
}), c = g(() => {
|
|
134
134
|
var d;
|
|
135
|
-
return (d =
|
|
136
|
-
}), m = g(() =>
|
|
135
|
+
return (d = y.value) == null ? void 0 : d._errors;
|
|
136
|
+
}), m = g(() => y.value !== void 0), O = A(m, () => {
|
|
137
137
|
m.value ? (u("invalid", c.value), s && s.errors.value.set(
|
|
138
138
|
n.name,
|
|
139
139
|
{
|
|
@@ -142,18 +142,18 @@ const ce = (e, l, t, f) => W({
|
|
|
142
142
|
)) : (u("valid", i.value), s && s.errors.value.delete(
|
|
143
143
|
n.name
|
|
144
144
|
));
|
|
145
|
-
}), k =
|
|
145
|
+
}), k = A(
|
|
146
146
|
() => a == null ? void 0 : a.formData,
|
|
147
147
|
() => {
|
|
148
148
|
u("update:formData", a == null ? void 0 : a.formData);
|
|
149
149
|
},
|
|
150
150
|
{ deep: !0 }
|
|
151
|
-
),
|
|
151
|
+
), b = (d) => {
|
|
152
152
|
i.value = d;
|
|
153
153
|
}, V = g(() => {
|
|
154
154
|
let d = o.value;
|
|
155
155
|
return typeof d == "function" && (d = d(a == null ? void 0 : a.formData)), Object.keys(d).reduce(
|
|
156
|
-
(
|
|
156
|
+
(I, C) => (I[C] = _(d[C]), I),
|
|
157
157
|
{}
|
|
158
158
|
);
|
|
159
159
|
}), z = g(() => ({
|
|
@@ -181,11 +181,11 @@ const ce = (e, l, t, f) => W({
|
|
|
181
181
|
})(n.type),
|
|
182
182
|
invalidLabel: c.value,
|
|
183
183
|
modelValue: i.value,
|
|
184
|
-
"onUpdate:modelValue":
|
|
184
|
+
"onUpdate:modelValue": b
|
|
185
185
|
}));
|
|
186
186
|
return M(t, {
|
|
187
187
|
name: p(h),
|
|
188
|
-
errors: p(
|
|
188
|
+
errors: p(y)
|
|
189
189
|
}), { component: g(() => {
|
|
190
190
|
if (n.type === v.custom)
|
|
191
191
|
return {
|
|
@@ -193,14 +193,14 @@ const ce = (e, l, t, f) => W({
|
|
|
193
193
|
var d;
|
|
194
194
|
return ((d = r.default) == null ? void 0 : d.call(r, {
|
|
195
195
|
modelValue: i.value,
|
|
196
|
-
onUpdate:
|
|
196
|
+
onUpdate: b,
|
|
197
197
|
submit: a == null ? void 0 : a.submit,
|
|
198
198
|
validate: a == null ? void 0 : a.validate,
|
|
199
199
|
invalid: m.value,
|
|
200
200
|
invalidLabel: c.value,
|
|
201
201
|
formData: a == null ? void 0 : a.formData.value,
|
|
202
202
|
formErrors: a == null ? void 0 : a.errors.value,
|
|
203
|
-
errors:
|
|
203
|
+
errors: y.value
|
|
204
204
|
})) ?? r.defalut;
|
|
205
205
|
}
|
|
206
206
|
};
|
|
@@ -208,28 +208,28 @@ const ce = (e, l, t, f) => W({
|
|
|
208
208
|
let d;
|
|
209
209
|
switch (n.type) {
|
|
210
210
|
case v.select:
|
|
211
|
-
d =
|
|
211
|
+
d = w("VvSelect");
|
|
212
212
|
break;
|
|
213
213
|
case v.checkbox:
|
|
214
|
-
d =
|
|
214
|
+
d = w("VvCheckbox");
|
|
215
215
|
break;
|
|
216
216
|
case v.radio:
|
|
217
|
-
d =
|
|
217
|
+
d = w("VvRadio");
|
|
218
218
|
break;
|
|
219
219
|
case v.textarea:
|
|
220
|
-
d =
|
|
220
|
+
d = w("VvTextarea");
|
|
221
221
|
break;
|
|
222
222
|
case v.radioGroup:
|
|
223
|
-
d =
|
|
223
|
+
d = w("VvRadioGroup");
|
|
224
224
|
break;
|
|
225
225
|
case v.checkboxGroup:
|
|
226
|
-
d =
|
|
226
|
+
d = w("VvCheckboxGroup");
|
|
227
227
|
break;
|
|
228
228
|
case v.combobox:
|
|
229
|
-
d =
|
|
229
|
+
d = w("VvCombobox");
|
|
230
230
|
break;
|
|
231
231
|
default:
|
|
232
|
-
d =
|
|
232
|
+
d = w("VvInputText");
|
|
233
233
|
}
|
|
234
234
|
if (typeof d != "string")
|
|
235
235
|
return d;
|
|
@@ -333,7 +333,7 @@ const ce = (e, l, t, f) => W({
|
|
|
333
333
|
u.value = J(
|
|
334
334
|
e,
|
|
335
335
|
S(s.modelValue)
|
|
336
|
-
),
|
|
336
|
+
), A(
|
|
337
337
|
() => s.modelValue,
|
|
338
338
|
(c) => {
|
|
339
339
|
if (c) {
|
|
@@ -344,37 +344,37 @@ const ce = (e, l, t, f) => W({
|
|
|
344
344
|
{ deep: !0 }
|
|
345
345
|
), ae(
|
|
346
346
|
u,
|
|
347
|
-
(c) => {
|
|
347
|
+
async (c) => {
|
|
348
348
|
var m;
|
|
349
|
-
((n.value || (t == null ? void 0 : t.continuosValidation)) ?? s.continuosValidation) && o(), (!c || !s.modelValue || JSON.stringify(c) !== JSON.stringify(s.modelValue)) && (a("update:modelValue", c), (m = t == null ? void 0 : t.onUpdate) == null || m.call(t, S(c)));
|
|
349
|
+
((n.value || (t == null ? void 0 : t.continuosValidation)) ?? s.continuosValidation) && await o(), (!c || !s.modelValue || JSON.stringify(c) !== JSON.stringify(s.modelValue)) && (a("update:modelValue", c), (m = t == null ? void 0 : t.onUpdate) == null || m.call(t, S(c)));
|
|
350
350
|
},
|
|
351
351
|
{
|
|
352
352
|
deep: !0,
|
|
353
353
|
throttle: (t == null ? void 0 : t.updateThrottle) ?? s.updateThrottle
|
|
354
354
|
}
|
|
355
355
|
);
|
|
356
|
-
const o = (c = u.value) => {
|
|
357
|
-
var
|
|
358
|
-
const m = e.
|
|
359
|
-
return m.success ? (n.value = void 0, r.value = B.valid, u.value = m.data, a("update:modelValue", u.value), (k = t == null ? void 0 : t.onUpdate) == null || k.call(t, S(u.value)), a("valid", m.data), (
|
|
360
|
-
}, h = () => {
|
|
356
|
+
const o = async (c = u.value) => {
|
|
357
|
+
var O, k, b;
|
|
358
|
+
const m = await e.safeParseAsync(c);
|
|
359
|
+
return m.success ? (n.value = void 0, r.value = B.valid, u.value = m.data, a("update:modelValue", u.value), (k = t == null ? void 0 : t.onUpdate) == null || k.call(t, S(u.value)), a("valid", m.data), (b = t == null ? void 0 : t.onValid) == null || b.call(t, S(u.value)), !0) : (n.value = m.error.format(), r.value = B.invalid, a("invalid", n.value), (O = t == null ? void 0 : t.onInvalid) == null || O.call(t, S(n.value)), !1);
|
|
360
|
+
}, h = async () => {
|
|
361
361
|
var c;
|
|
362
|
-
return o() ? (a("submit", u.value), (c = t == null ? void 0 : t.onSubmit) == null || c.call(t, S(u.value)), !0) : !1;
|
|
363
|
-
},
|
|
362
|
+
return await o() ? (a("submit", u.value), (c = t == null ? void 0 : t.onSubmit) == null || c.call(t, S(u.value)), !0) : !1;
|
|
363
|
+
}, y = g(() => r.value === B.invalid);
|
|
364
364
|
return M(l, {
|
|
365
365
|
formData: u,
|
|
366
366
|
submit: h,
|
|
367
367
|
validate: o,
|
|
368
368
|
errors: p(n),
|
|
369
369
|
status: p(r),
|
|
370
|
-
invalid:
|
|
370
|
+
invalid: y
|
|
371
371
|
}), {
|
|
372
372
|
formData: u,
|
|
373
373
|
submit: h,
|
|
374
374
|
validate: o,
|
|
375
375
|
errors: p(n),
|
|
376
376
|
status: p(r),
|
|
377
|
-
invalid:
|
|
377
|
+
invalid: y
|
|
378
378
|
};
|
|
379
379
|
},
|
|
380
380
|
render() {
|
|
@@ -434,23 +434,23 @@ const ce = (e, l, t, f) => W({
|
|
|
434
434
|
emits: ["invalid", "valid"],
|
|
435
435
|
expose: ["fields", "invalid"],
|
|
436
436
|
setup(f, { emit: n }) {
|
|
437
|
-
const r =
|
|
437
|
+
const r = E(e), u = E(l, void 0), i = $(/* @__PURE__ */ new Set()), s = $(/* @__PURE__ */ new Map()), { name: a } = R(f);
|
|
438
438
|
M(l, {
|
|
439
439
|
name: p(a),
|
|
440
440
|
errors: s,
|
|
441
441
|
fields: i
|
|
442
|
-
}),
|
|
442
|
+
}), A(
|
|
443
443
|
i,
|
|
444
444
|
(h) => {
|
|
445
|
-
u != null && u.fields && h.forEach((
|
|
446
|
-
u == null || u.fields.value.add(
|
|
445
|
+
u != null && u.fields && h.forEach((y) => {
|
|
446
|
+
u == null || u.fields.value.add(y);
|
|
447
447
|
});
|
|
448
448
|
},
|
|
449
449
|
{ deep: !0 }
|
|
450
|
-
),
|
|
450
|
+
), A(
|
|
451
451
|
() => new Map(s.value),
|
|
452
|
-
(h,
|
|
453
|
-
u != null && u.errors && (Array.from(
|
|
452
|
+
(h, y) => {
|
|
453
|
+
u != null && u.errors && (Array.from(y.keys()).forEach((c) => {
|
|
454
454
|
u.errors.value.delete(c);
|
|
455
455
|
}), Array.from(h.keys()).forEach((c) => {
|
|
456
456
|
const m = h.get(c);
|
|
@@ -460,7 +460,7 @@ const ce = (e, l, t, f) => W({
|
|
|
460
460
|
{ deep: !0 }
|
|
461
461
|
);
|
|
462
462
|
const o = g(() => r != null && r.invalid.value ? s.value.size > 0 : !1);
|
|
463
|
-
return
|
|
463
|
+
return A(o, () => {
|
|
464
464
|
o.value ? n("invalid") : n("valid");
|
|
465
465
|
}), {
|
|
466
466
|
formData: r == null ? void 0 : r.formData,
|
|
@@ -495,7 +495,7 @@ const ce = (e, l, t, f) => W({
|
|
|
495
495
|
fieldsErrors: this.fieldsErrors
|
|
496
496
|
})) ?? this.$slots.defalut;
|
|
497
497
|
}
|
|
498
|
-
}),
|
|
498
|
+
}), ye = (e, l) => {
|
|
499
499
|
const t = W({
|
|
500
500
|
props: {
|
|
501
501
|
schema: {
|
|
@@ -504,31 +504,31 @@ const ce = (e, l, t, f) => W({
|
|
|
504
504
|
}
|
|
505
505
|
},
|
|
506
506
|
setup(f, { slots: n }) {
|
|
507
|
-
const r =
|
|
507
|
+
const r = E(e);
|
|
508
508
|
if (r != null && r.formData)
|
|
509
509
|
return () => {
|
|
510
510
|
var a;
|
|
511
511
|
const u = typeof f.schema == "function" ? f.schema(r) : f.schema;
|
|
512
512
|
let i;
|
|
513
513
|
const s = u.reduce((o, h) => {
|
|
514
|
-
const
|
|
514
|
+
const y = typeof h == "function" ? h(r) : h, {
|
|
515
515
|
vvIs: c,
|
|
516
516
|
vvName: m,
|
|
517
|
-
vvSlots:
|
|
517
|
+
vvSlots: O,
|
|
518
518
|
vvChildren: k,
|
|
519
|
-
vvIf:
|
|
519
|
+
vvIf: b,
|
|
520
520
|
vvElseIf: V,
|
|
521
521
|
vvType: z,
|
|
522
522
|
vvDefaultValue: q,
|
|
523
523
|
vvShowValid: d,
|
|
524
|
-
vvContent:
|
|
524
|
+
vvContent: I,
|
|
525
525
|
...C
|
|
526
|
-
} =
|
|
527
|
-
if (
|
|
528
|
-
if (typeof
|
|
526
|
+
} = y;
|
|
527
|
+
if (b !== void 0) {
|
|
528
|
+
if (typeof b == "string" ? i = !!G(
|
|
529
529
|
Object(r.formData.value),
|
|
530
|
-
|
|
531
|
-
) : typeof
|
|
530
|
+
b
|
|
531
|
+
) : typeof b == "function" ? i = _(b(r)) : i = _(b), !i)
|
|
532
532
|
return o;
|
|
533
533
|
} else if (V !== void 0 && i !== void 0) {
|
|
534
534
|
if (i || (typeof V == "string" ? i = !!G(
|
|
@@ -552,13 +552,13 @@ const ce = (e, l, t, f) => W({
|
|
|
552
552
|
showValid: d,
|
|
553
553
|
props: C
|
|
554
554
|
},
|
|
555
|
-
|
|
555
|
+
O ?? Z ?? I
|
|
556
556
|
)
|
|
557
557
|
), o) : c ? (o.push(
|
|
558
558
|
x(
|
|
559
559
|
c,
|
|
560
560
|
C,
|
|
561
|
-
|
|
561
|
+
O ?? Z ?? I
|
|
562
562
|
)
|
|
563
563
|
), o) : (k && o.push(Z), o);
|
|
564
564
|
}, []);
|
|
@@ -585,7 +585,7 @@ const ce = (e, l, t, f) => W({
|
|
|
585
585
|
f,
|
|
586
586
|
n,
|
|
587
587
|
l
|
|
588
|
-
), i =
|
|
588
|
+
), i = ye(t, u), { VvForm: s, errors: a, status: o, formData: h } = me(
|
|
589
589
|
e,
|
|
590
590
|
t,
|
|
591
591
|
l,
|
|
@@ -614,15 +614,15 @@ const ce = (e, l, t, f) => W({
|
|
|
614
614
|
}, ke = (e, l = {}) => te() ? L(
|
|
615
615
|
e,
|
|
616
616
|
{
|
|
617
|
-
...
|
|
617
|
+
...E(Y, {}),
|
|
618
618
|
...l
|
|
619
619
|
}
|
|
620
|
-
) : L(e, l),
|
|
620
|
+
) : L(e, l), we = (e, l = {}) => L(e, l);
|
|
621
621
|
export {
|
|
622
622
|
v as FormFieldType,
|
|
623
623
|
xe as createForm,
|
|
624
624
|
J as defaultObjectBySchema,
|
|
625
|
-
|
|
625
|
+
we as formFactory,
|
|
626
626
|
Y as pluginInjectionKey,
|
|
627
627
|
ke as useForm
|
|
628
628
|
};
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(b,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("vue"),require("@vueuse/core"),require("zod")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","zod"],r):(b=typeof globalThis<"u"?globalThis:b||self,r(b["@volverjs/form-vue"]={},b.Vue,b.VueUseCore,b.zod))})(this,function(b,r,q,g){"use strict";function $(e){return Array.isArray(e)}function M(e){return typeof e<"u"}function L(e){return e===null}function W(e){return typeof e=="object"}function Z(e){return typeof e=="string"}function S(e){return typeof e>"u"}const J=/^[0-9]+$/,P=["__proto__","prototype","constructor"];function I(e,i,a){const f=M(a)?a:void 0;if(!W(e)||!Z(i))return f;const s=K(i);if(s.length!==0){for(const t of s){if(t==="*")continue;const l=function(o){return o.map(u=>S(u)||L(u)?u:$(u)?l(u):u[t])};if($(e)&&!J.test(t)?e=l(e):e=e[t],S(e)||L(e))break}return S(e)?f:e}}function R(e,i,a){if(!W(e)||!Z(i))return;const f=K(i);if(f.length===0)return;const s=f.length;for(let t=0;t<s;t++){const l=f[t];if(t===s-1){e[l]=a;return}if(l==="*"&&$(e)){const o=f.slice(t+1).join(".");for(const u of e)R(u,o,a);return}S(e[l])&&(e[l]={}),e=e[l]}}function K(e){const i=e.split(/[.]|(?:\[(\d|\*)\])/).filter(a=>!!a);return i.some(a=>P.indexOf(a)!==-1)?[]:i}var d=(e=>(e.text="text",e.number="number",e.email="email",e.password="password",e.tel="tel",e.url="url",e.search="search",e.date="date",e.time="time",e.datetimeLocal="datetime-local",e.month="month",e.week="week",e.color="color",e.select="select",e.checkbox="checkbox",e.radio="radio",e.textarea="textarea",e.radioGroup="radioGroup",e.checkboxGroup="checkboxGroup",e.combobox="combobox",e.custom="custom",e))(d||{}),E=(e=>(e.invalid="invalid",e.valid="valid",e))(E||{});const T=(e,i,a,f)=>r.defineComponent({name:"FieldComponent",props:{type:{type:String,validator:s=>Object.values(d).includes(s),default:d.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}},emits:["invalid","valid","update:formData","update:modelValue"],expose:["invalid","invalidLabel","errors"],setup(s,{slots:t,emit:l}){const o=r.computed({get(){if(n!=null&&n.formData)return I(Object(n.formData.value),String(s.name))},set(m){n!=null&&n.formData&&(R(Object(n.formData.value),String(s.name),m),l("update:modelValue",{newValue:o.value,formData:n==null?void 0:n.formData}))}});r.onMounted(()=>{o.value===void 0&&s.defaultValue!==void 0&&(o.value=s.defaultValue)}),r.onBeforeUnmount(()=>{O(),x()});const u=r.inject(i,void 0);u&&u.fields.value.add(s.name);const n=r.inject(e),{props:c,name:y}=r.toRefs(s),V=r.computed(()=>{if(n!=null&&n.errors.value)return I(n.errors.value,String(s.name))}),v=r.computed(()=>{var m;return(m=V.value)==null?void 0:m._errors}),h=r.computed(()=>V.value!==void 0),O=r.watch(h,()=>{h.value?(l("invalid",v.value),u&&u.errors.value.set(s.name,{_errors:v.value})):(l("valid",o.value),u&&u.errors.value.delete(s.name))}),x=r.watch(()=>n==null?void 0:n.formData,()=>{l("update:formData",n==null?void 0:n.formData)},{deep:!0}),p=m=>{o.value=m},w=r.computed(()=>{let m=c.value;return typeof m=="function"&&(m=m(n==null?void 0:n.formData)),Object.keys(m).reduce((C,k)=>(C[k]=r.unref(m[k]),C),{})}),N=r.computed(()=>({...w.value,name:w.value.name??s.name,invalid:h.value,valid:s.showValid?!!(!h.value&&o.value):void 0,type:(m=>{if([d.text,d.number,d.email,d.password,d.tel,d.url,d.search,d.date,d.time,d.datetimeLocal,d.month,d.week,d.color].includes(m))return m})(s.type),invalidLabel:v.value,modelValue:o.value,"onUpdate:modelValue":p}));return r.provide(a,{name:r.readonly(y),errors:r.readonly(V)}),{component:r.computed(()=>{if(s.type===d.custom)return{render(){var m;return((m=t.default)==null?void 0:m.call(t,{modelValue:o.value,onUpdate:p,submit:n==null?void 0:n.submit,validate:n==null?void 0:n.validate,invalid:h.value,invalidLabel:v.value,formData:n==null?void 0:n.formData.value,formErrors:n==null?void 0:n.errors.value,errors:V.value}))??t.defalut}};if(!((f==null?void 0:f.lazyLoad)??s.lazyLoad)){let m;switch(s.type){case d.select:m=r.resolveComponent("VvSelect");break;case d.checkbox:m=r.resolveComponent("VvCheckbox");break;case d.radio:m=r.resolveComponent("VvRadio");break;case d.textarea:m=r.resolveComponent("VvTextarea");break;case d.radioGroup:m=r.resolveComponent("VvRadioGroup");break;case d.checkboxGroup:m=r.resolveComponent("VvCheckboxGroup");break;case d.combobox:m=r.resolveComponent("VvCombobox");break;default:m=r.resolveComponent("VvInputText")}if(typeof m!="string")return m;console.warn(`[form-vue warn]: ${m} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`)}return r.defineAsyncComponent(async()=>{switch(f!=null&&f.sideEffects&&await Promise.resolve(f.sideEffects(s.type)),s.type){case d.textarea:return import("@volverjs/ui-vue/vv-textarea");case d.radio:return import("@volverjs/ui-vue/vv-radio");case d.radioGroup:return import("@volverjs/ui-vue/vv-radio-group");case d.checkbox:return import("@volverjs/ui-vue/vv-checkbox");case d.checkboxGroup:return import("@volverjs/ui-vue/vv-checkbox-group");case d.select:return import("@volverjs/ui-vue/vv-select");case d.combobox:return import("@volverjs/ui-vue/vv-combobox")}return import("@volverjs/ui-vue/vv-input-text")})}),hasProps:N,invalid:h}},render(){return this.is?r.h(this.is,this.hasProps,this.$slots):this.type===d.custom?r.h(this.component,null,this.$slots):r.h(this.component,this.hasProps,this.$slots)}}),A=(e,i={})=>{const a=t=>{let l=t;for(;l instanceof g.ZodEffects;)l=l.innerType();return l instanceof g.ZodOptional&&(l=l._def.innerType),l},f=a(e);return{...(f instanceof g.ZodObject?f._def.unknownKeys==="passthrough":!1)?i:{},...Object.fromEntries(Object.entries(f.shape).map(([t,l])=>{const o=i[t];let u=a(l),n;if(u instanceof g.ZodDefault&&(n=u._def.defaultValue(),u=u._def.innerType),o===null&&u instanceof g.ZodNullable)return[t,o];if(u instanceof g.ZodSchema){const c=l.safeParse(o);if(c.success)return[t,c.data??n]}if(u instanceof g.ZodArray&&Array.isArray(o)&&o.length){const c=a(u._def.type);if(c instanceof g.ZodObject)return[t,o.map(y=>A(c,y&&typeof y=="object"?y:void 0))??n]}return u instanceof g.ZodObject?[t,A(u,o&&typeof o=="object"?o:n)]:[t,n]}))}},z=(e,i,a,f)=>{const s=r.ref(),t=r.ref(),l=r.ref(),o=r.defineComponent({name:"FormComponent",props:{modelValue:{type:Object,default:()=>({})},updateThrottle:{type:Number,default:500},continuosValidation:{type:Boolean,default:!1},template:{type:[Array,Function],default:void 0}},emits:["invalid","valid","submit","update:modelValue"],expose:["submit","validate","errors","status","valid","invalid"],setup(u,{emit:n}){l.value=A(e,r.toRaw(u.modelValue)),r.watch(()=>u.modelValue,v=>{if(v){const h=r.isProxy(v)?r.toRaw(v):v;l.value=typeof(h==null?void 0:h.clone)=="function"?h.clone():JSON.parse(JSON.stringify(h))}},{deep:!0}),q.watchThrottled(l,v=>{var h;((s.value||(a==null?void 0:a.continuosValidation))??u.continuosValidation)&&c(),(!v||!u.modelValue||JSON.stringify(v)!==JSON.stringify(u.modelValue))&&(n("update:modelValue",v),(h=a==null?void 0:a.onUpdate)==null||h.call(a,r.toRaw(v)))},{deep:!0,throttle:(a==null?void 0:a.updateThrottle)??u.updateThrottle});const c=(v=l.value)=>{var O,x,p;const h=e.safeParse(v);return h.success?(s.value=void 0,t.value=E.valid,l.value=h.data,n("update:modelValue",l.value),(x=a==null?void 0:a.onUpdate)==null||x.call(a,r.toRaw(l.value)),n("valid",h.data),(p=a==null?void 0:a.onValid)==null||p.call(a,r.toRaw(l.value)),!0):(s.value=h.error.format(),t.value=E.invalid,n("invalid",s.value),(O=a==null?void 0:a.onInvalid)==null||O.call(a,r.toRaw(s.value)),!1)},y=()=>{var v;return c()?(n("submit",l.value),(v=a==null?void 0:a.onSubmit)==null||v.call(a,r.toRaw(l.value)),!0):!1},V=r.computed(()=>t.value===E.invalid);return r.provide(i,{formData:l,submit:y,validate:c,errors:r.readonly(s),status:r.readonly(t),invalid:V}),{formData:l,submit:y,validate:c,errors:r.readonly(s),status:r.readonly(t),invalid:V}},render(){const u=()=>{var n,c;return((c=(n=this.$slots)==null?void 0:n.default)==null?void 0:c.call(n,{formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,status:this.status,invalid:this.invalid}))??this.$slots.default};return r.h("form",{onSubmit:r.withModifiers(this.submit,["prevent"])},(this.template??(a==null?void 0:a.template))&&f?[r.h(f,{schema:this.template??(a==null?void 0:a.template)},{default:u})]:{default:u})}});return{errors:s,status:t,formData:l,VvForm:o}},H=(e,i)=>r.defineComponent({name:"WrapperComponent",props:{name:{type:String,required:!0},tag:{type:String,default:void 0}},emits:["invalid","valid"],expose:["fields","invalid"],setup(f,{emit:s}){const t=r.inject(e),l=r.inject(i,void 0),o=r.ref(new Set),u=r.ref(new Map),{name:n}=r.toRefs(f);r.provide(i,{name:r.readonly(n),errors:u,fields:o}),r.watch(o,y=>{l!=null&&l.fields&&y.forEach(V=>{l==null||l.fields.value.add(V)})},{deep:!0}),r.watch(()=>new Map(u.value),(y,V)=>{l!=null&&l.errors&&(Array.from(V.keys()).forEach(v=>{l.errors.value.delete(v)}),Array.from(y.keys()).forEach(v=>{const h=y.get(v);h&&l.errors.value.set(v,h)}))},{deep:!0});const c=r.computed(()=>t!=null&&t.invalid.value?u.value.size>0:!1);return r.watch(c,()=>{c.value?s("invalid"):s("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:c,fields:o,fieldsErrors:u}},render(){var f,s;return this.tag?r.h(this.tag,null,{default:()=>{var t,l;return((l=(t=this.$slots).default)==null?void 0:l.call(t,{invalid:this.invalid,formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}):((s=(f=this.$slots).default)==null?void 0:s.call(f,{invalid:this.invalid,formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}),Q=(e,i)=>{const a=r.defineComponent({props:{schema:{type:[Array,Function],required:!0}},setup(f,{slots:s}){const t=r.inject(e);if(t!=null&&t.formData)return()=>{var n;const l=typeof f.schema=="function"?f.schema(t):f.schema;let o;const u=l.reduce((c,y)=>{const V=typeof y=="function"?y(t):y,{vvIs:v,vvName:h,vvSlots:O,vvChildren:x,vvIf:p,vvElseIf:w,vvType:N,vvDefaultValue:U,vvShowValid:m,vvContent:C,...k}=V;if(p!==void 0){if(typeof p=="string"?o=!!I(Object(t.formData.value),p):typeof p=="function"?o=r.unref(p(t)):o=r.unref(p),!o)return c}else if(w!==void 0&&o!==void 0){if(o||(typeof w=="string"?o=!!I(Object(t.formData.value),w):typeof w=="function"?o=r.unref(w(t)):o=r.unref(w),!o))return c}else o=void 0;const G=x?r.h(a,{schema:x}):void 0;return h?(c.push(r.h(i,{name:h,is:v,type:N,defaultValue:U,showValid:m,props:k},O??G??C)),c):v?(c.push(r.h(v,k,O??G??C)),c):(x&&c.push(G),c)},[]);return u.push((n=s==null?void 0:s.default)==null?void 0:n.call(s,{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})),u}}});return a},_=(e,i={})=>{const a=Symbol(),f=Symbol(),s=Symbol(),t=H(a,f),l=T(a,f,s,i),o=Q(a,l),{VvForm:u,errors:n,status:c,formData:y}=z(e,a,i,o);return{VvForm:u,VvFormWrapper:t,VvFormField:l,VvFormTemplate:o,formInjectionKey:a,formWrapperInjectionKey:f,formFieldInjectionKey:s,errors:n,status:c,formData:y}},B=Symbol(),X=e=>{let i={};return e.schema&&(i=_(e.schema,e)),{...i,install(a,{global:f=!1}={}){a.provide(B,e),f&&(a.config.globalProperties.$vvForm=e,i!=null&&i.VvForm&&a.component("VvForm",i.VvForm),i!=null&&i.VvFormWrapper&&a.component("VvFormWrapper",i.VvFormWrapper),i!=null&&i.VvFormField&&a.component("VvFormField",i.VvFormField),i!=null&&i.VvFormTemplate&&a.component("VvFormTemplate",i.VvFormTemplate))}}},Y=(e,i={})=>r.getCurrentInstance()?_(e,{...r.inject(B,{}),...i}):_(e,i),D=(e,i={})=>_(e,i);b.FormFieldType=d,b.createForm=X,b.defaultObjectBySchema=A,b.formFactory=D,b.pluginInjectionKey=B,b.useForm=Y,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(b,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("vue"),require("@vueuse/core"),require("zod")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","zod"],r):(b=typeof globalThis<"u"?globalThis:b||self,r(b["@volverjs/form-vue"]={},b.Vue,b.VueUseCore,b.zod))})(this,function(b,r,q,g){"use strict";function $(e){return Array.isArray(e)}function M(e){return typeof e<"u"}function L(e){return e===null}function W(e){return typeof e=="object"}function Z(e){return typeof e=="string"}function S(e){return typeof e>"u"}const J=/^[0-9]+$/,P=["__proto__","prototype","constructor"];function I(e,i,a){const f=M(a)?a:void 0;if(!W(e)||!Z(i))return f;const s=K(i);if(s.length!==0){for(const t of s){if(t==="*")continue;const l=function(o){return o.map(u=>S(u)||L(u)?u:$(u)?l(u):u[t])};if($(e)&&!J.test(t)?e=l(e):e=e[t],S(e)||L(e))break}return S(e)?f:e}}function R(e,i,a){if(!W(e)||!Z(i))return;const f=K(i);if(f.length===0)return;const s=f.length;for(let t=0;t<s;t++){const l=f[t];if(t===s-1){e[l]=a;return}if(l==="*"&&$(e)){const o=f.slice(t+1).join(".");for(const u of e)R(u,o,a);return}S(e[l])&&(e[l]={}),e=e[l]}}function K(e){const i=e.split(/[.]|(?:\[(\d|\*)\])/).filter(a=>!!a);return i.some(a=>P.indexOf(a)!==-1)?[]:i}var d=(e=>(e.text="text",e.number="number",e.email="email",e.password="password",e.tel="tel",e.url="url",e.search="search",e.date="date",e.time="time",e.datetimeLocal="datetime-local",e.month="month",e.week="week",e.color="color",e.select="select",e.checkbox="checkbox",e.radio="radio",e.textarea="textarea",e.radioGroup="radioGroup",e.checkboxGroup="checkboxGroup",e.combobox="combobox",e.custom="custom",e))(d||{}),A=(e=>(e.invalid="invalid",e.valid="valid",e))(A||{});const T=(e,i,a,f)=>r.defineComponent({name:"FieldComponent",props:{type:{type:String,validator:s=>Object.values(d).includes(s),default:d.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}},emits:["invalid","valid","update:formData","update:modelValue"],expose:["invalid","invalidLabel","errors"],setup(s,{slots:t,emit:l}){const o=r.computed({get(){if(n!=null&&n.formData)return I(Object(n.formData.value),String(s.name))},set(m){n!=null&&n.formData&&(R(Object(n.formData.value),String(s.name),m),l("update:modelValue",{newValue:o.value,formData:n==null?void 0:n.formData}))}});r.onMounted(()=>{o.value===void 0&&s.defaultValue!==void 0&&(o.value=s.defaultValue)}),r.onBeforeUnmount(()=>{O(),x()});const u=r.inject(i,void 0);u&&u.fields.value.add(s.name);const n=r.inject(e),{props:c,name:y}=r.toRefs(s),V=r.computed(()=>{if(n!=null&&n.errors.value)return I(n.errors.value,String(s.name))}),v=r.computed(()=>{var m;return(m=V.value)==null?void 0:m._errors}),h=r.computed(()=>V.value!==void 0),O=r.watch(h,()=>{h.value?(l("invalid",v.value),u&&u.errors.value.set(s.name,{_errors:v.value})):(l("valid",o.value),u&&u.errors.value.delete(s.name))}),x=r.watch(()=>n==null?void 0:n.formData,()=>{l("update:formData",n==null?void 0:n.formData)},{deep:!0}),p=m=>{o.value=m},w=r.computed(()=>{let m=c.value;return typeof m=="function"&&(m=m(n==null?void 0:n.formData)),Object.keys(m).reduce((C,k)=>(C[k]=r.unref(m[k]),C),{})}),N=r.computed(()=>({...w.value,name:w.value.name??s.name,invalid:h.value,valid:s.showValid?!!(!h.value&&o.value):void 0,type:(m=>{if([d.text,d.number,d.email,d.password,d.tel,d.url,d.search,d.date,d.time,d.datetimeLocal,d.month,d.week,d.color].includes(m))return m})(s.type),invalidLabel:v.value,modelValue:o.value,"onUpdate:modelValue":p}));return r.provide(a,{name:r.readonly(y),errors:r.readonly(V)}),{component:r.computed(()=>{if(s.type===d.custom)return{render(){var m;return((m=t.default)==null?void 0:m.call(t,{modelValue:o.value,onUpdate:p,submit:n==null?void 0:n.submit,validate:n==null?void 0:n.validate,invalid:h.value,invalidLabel:v.value,formData:n==null?void 0:n.formData.value,formErrors:n==null?void 0:n.errors.value,errors:V.value}))??t.defalut}};if(!((f==null?void 0:f.lazyLoad)??s.lazyLoad)){let m;switch(s.type){case d.select:m=r.resolveComponent("VvSelect");break;case d.checkbox:m=r.resolveComponent("VvCheckbox");break;case d.radio:m=r.resolveComponent("VvRadio");break;case d.textarea:m=r.resolveComponent("VvTextarea");break;case d.radioGroup:m=r.resolveComponent("VvRadioGroup");break;case d.checkboxGroup:m=r.resolveComponent("VvCheckboxGroup");break;case d.combobox:m=r.resolveComponent("VvCombobox");break;default:m=r.resolveComponent("VvInputText")}if(typeof m!="string")return m;console.warn(`[form-vue warn]: ${m} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`)}return r.defineAsyncComponent(async()=>{switch(f!=null&&f.sideEffects&&await Promise.resolve(f.sideEffects(s.type)),s.type){case d.textarea:return import("@volverjs/ui-vue/vv-textarea");case d.radio:return import("@volverjs/ui-vue/vv-radio");case d.radioGroup:return import("@volverjs/ui-vue/vv-radio-group");case d.checkbox:return import("@volverjs/ui-vue/vv-checkbox");case d.checkboxGroup:return import("@volverjs/ui-vue/vv-checkbox-group");case d.select:return import("@volverjs/ui-vue/vv-select");case d.combobox:return import("@volverjs/ui-vue/vv-combobox")}return import("@volverjs/ui-vue/vv-input-text")})}),hasProps:N,invalid:h}},render(){return this.is?r.h(this.is,this.hasProps,this.$slots):this.type===d.custom?r.h(this.component,null,this.$slots):r.h(this.component,this.hasProps,this.$slots)}}),E=(e,i={})=>{const a=t=>{let l=t;for(;l instanceof g.ZodEffects;)l=l.innerType();return l instanceof g.ZodOptional&&(l=l._def.innerType),l},f=a(e);return{...(f instanceof g.ZodObject?f._def.unknownKeys==="passthrough":!1)?i:{},...Object.fromEntries(Object.entries(f.shape).map(([t,l])=>{const o=i[t];let u=a(l),n;if(u instanceof g.ZodDefault&&(n=u._def.defaultValue(),u=u._def.innerType),o===null&&u instanceof g.ZodNullable)return[t,o];if(u instanceof g.ZodSchema){const c=l.safeParse(o);if(c.success)return[t,c.data??n]}if(u instanceof g.ZodArray&&Array.isArray(o)&&o.length){const c=a(u._def.type);if(c instanceof g.ZodObject)return[t,o.map(y=>E(c,y&&typeof y=="object"?y:void 0))??n]}return u instanceof g.ZodObject?[t,E(u,o&&typeof o=="object"?o:n)]:[t,n]}))}},z=(e,i,a,f)=>{const s=r.ref(),t=r.ref(),l=r.ref(),o=r.defineComponent({name:"FormComponent",props:{modelValue:{type:Object,default:()=>({})},updateThrottle:{type:Number,default:500},continuosValidation:{type:Boolean,default:!1},template:{type:[Array,Function],default:void 0}},emits:["invalid","valid","submit","update:modelValue"],expose:["submit","validate","errors","status","valid","invalid"],setup(u,{emit:n}){l.value=E(e,r.toRaw(u.modelValue)),r.watch(()=>u.modelValue,v=>{if(v){const h=r.isProxy(v)?r.toRaw(v):v;l.value=typeof(h==null?void 0:h.clone)=="function"?h.clone():JSON.parse(JSON.stringify(h))}},{deep:!0}),q.watchThrottled(l,async v=>{var h;((s.value||(a==null?void 0:a.continuosValidation))??u.continuosValidation)&&await c(),(!v||!u.modelValue||JSON.stringify(v)!==JSON.stringify(u.modelValue))&&(n("update:modelValue",v),(h=a==null?void 0:a.onUpdate)==null||h.call(a,r.toRaw(v)))},{deep:!0,throttle:(a==null?void 0:a.updateThrottle)??u.updateThrottle});const c=async(v=l.value)=>{var O,x,p;const h=await e.safeParseAsync(v);return h.success?(s.value=void 0,t.value=A.valid,l.value=h.data,n("update:modelValue",l.value),(x=a==null?void 0:a.onUpdate)==null||x.call(a,r.toRaw(l.value)),n("valid",h.data),(p=a==null?void 0:a.onValid)==null||p.call(a,r.toRaw(l.value)),!0):(s.value=h.error.format(),t.value=A.invalid,n("invalid",s.value),(O=a==null?void 0:a.onInvalid)==null||O.call(a,r.toRaw(s.value)),!1)},y=async()=>{var v;return await c()?(n("submit",l.value),(v=a==null?void 0:a.onSubmit)==null||v.call(a,r.toRaw(l.value)),!0):!1},V=r.computed(()=>t.value===A.invalid);return r.provide(i,{formData:l,submit:y,validate:c,errors:r.readonly(s),status:r.readonly(t),invalid:V}),{formData:l,submit:y,validate:c,errors:r.readonly(s),status:r.readonly(t),invalid:V}},render(){const u=()=>{var n,c;return((c=(n=this.$slots)==null?void 0:n.default)==null?void 0:c.call(n,{formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,status:this.status,invalid:this.invalid}))??this.$slots.default};return r.h("form",{onSubmit:r.withModifiers(this.submit,["prevent"])},(this.template??(a==null?void 0:a.template))&&f?[r.h(f,{schema:this.template??(a==null?void 0:a.template)},{default:u})]:{default:u})}});return{errors:s,status:t,formData:l,VvForm:o}},H=(e,i)=>r.defineComponent({name:"WrapperComponent",props:{name:{type:String,required:!0},tag:{type:String,default:void 0}},emits:["invalid","valid"],expose:["fields","invalid"],setup(f,{emit:s}){const t=r.inject(e),l=r.inject(i,void 0),o=r.ref(new Set),u=r.ref(new Map),{name:n}=r.toRefs(f);r.provide(i,{name:r.readonly(n),errors:u,fields:o}),r.watch(o,y=>{l!=null&&l.fields&&y.forEach(V=>{l==null||l.fields.value.add(V)})},{deep:!0}),r.watch(()=>new Map(u.value),(y,V)=>{l!=null&&l.errors&&(Array.from(V.keys()).forEach(v=>{l.errors.value.delete(v)}),Array.from(y.keys()).forEach(v=>{const h=y.get(v);h&&l.errors.value.set(v,h)}))},{deep:!0});const c=r.computed(()=>t!=null&&t.invalid.value?u.value.size>0:!1);return r.watch(c,()=>{c.value?s("invalid"):s("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:c,fields:o,fieldsErrors:u}},render(){var f,s;return this.tag?r.h(this.tag,null,{default:()=>{var t,l;return((l=(t=this.$slots).default)==null?void 0:l.call(t,{invalid:this.invalid,formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}):((s=(f=this.$slots).default)==null?void 0:s.call(f,{invalid:this.invalid,formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}),Q=(e,i)=>{const a=r.defineComponent({props:{schema:{type:[Array,Function],required:!0}},setup(f,{slots:s}){const t=r.inject(e);if(t!=null&&t.formData)return()=>{var n;const l=typeof f.schema=="function"?f.schema(t):f.schema;let o;const u=l.reduce((c,y)=>{const V=typeof y=="function"?y(t):y,{vvIs:v,vvName:h,vvSlots:O,vvChildren:x,vvIf:p,vvElseIf:w,vvType:N,vvDefaultValue:U,vvShowValid:m,vvContent:C,...k}=V;if(p!==void 0){if(typeof p=="string"?o=!!I(Object(t.formData.value),p):typeof p=="function"?o=r.unref(p(t)):o=r.unref(p),!o)return c}else if(w!==void 0&&o!==void 0){if(o||(typeof w=="string"?o=!!I(Object(t.formData.value),w):typeof w=="function"?o=r.unref(w(t)):o=r.unref(w),!o))return c}else o=void 0;const G=x?r.h(a,{schema:x}):void 0;return h?(c.push(r.h(i,{name:h,is:v,type:N,defaultValue:U,showValid:m,props:k},O??G??C)),c):v?(c.push(r.h(v,k,O??G??C)),c):(x&&c.push(G),c)},[]);return u.push((n=s==null?void 0:s.default)==null?void 0:n.call(s,{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})),u}}});return a},_=(e,i={})=>{const a=Symbol(),f=Symbol(),s=Symbol(),t=H(a,f),l=T(a,f,s,i),o=Q(a,l),{VvForm:u,errors:n,status:c,formData:y}=z(e,a,i,o);return{VvForm:u,VvFormWrapper:t,VvFormField:l,VvFormTemplate:o,formInjectionKey:a,formWrapperInjectionKey:f,formFieldInjectionKey:s,errors:n,status:c,formData:y}},B=Symbol(),X=e=>{let i={};return e.schema&&(i=_(e.schema,e)),{...i,install(a,{global:f=!1}={}){a.provide(B,e),f&&(a.config.globalProperties.$vvForm=e,i!=null&&i.VvForm&&a.component("VvForm",i.VvForm),i!=null&&i.VvFormWrapper&&a.component("VvFormWrapper",i.VvFormWrapper),i!=null&&i.VvFormField&&a.component("VvFormField",i.VvFormField),i!=null&&i.VvFormTemplate&&a.component("VvFormTemplate",i.VvFormTemplate))}}},Y=(e,i={})=>r.getCurrentInstance()?_(e,{...r.inject(B,{}),...i}):_(e,i),D=(e,i={})=>_(e,i);b.FormFieldType=d,b.createForm=X,b.defaultObjectBySchema=E,b.formFactory=D,b.pluginInjectionKey=B,b.useForm=Y,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
|
package/dist/src/VvForm.d.ts
CHANGED
|
@@ -104,8 +104,8 @@ export declare const defineForm: <Schema extends FormSchema>(schema: Schema, pro
|
|
|
104
104
|
onSubmit?: ((...args: any[]) => any) | undefined;
|
|
105
105
|
}, {
|
|
106
106
|
formData: Ref<Partial<z.TypeOf<Schema> | undefined>>;
|
|
107
|
-
submit: () => boolean
|
|
108
|
-
validate: (value?: Partial<z.TypeOf<Schema> | undefined>) => boolean
|
|
107
|
+
submit: () => Promise<boolean>;
|
|
108
|
+
validate: (value?: Partial<z.TypeOf<Schema> | undefined>) => Promise<boolean>;
|
|
109
109
|
errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema, string>> | undefined>>;
|
|
110
110
|
status: Readonly<Ref<FormStatus | undefined>>;
|
|
111
111
|
invalid: import("vue").ComputedRef<boolean>;
|
|
@@ -158,8 +158,8 @@ export declare const defineForm: <Schema extends FormSchema>(schema: Schema, pro
|
|
|
158
158
|
onSubmit?: ((...args: any[]) => any) | undefined;
|
|
159
159
|
} & import("vue").ShallowUnwrapRef<{
|
|
160
160
|
formData: Ref<Partial<z.TypeOf<Schema> | undefined>>;
|
|
161
|
-
submit: () => boolean
|
|
162
|
-
validate: (value?: Partial<z.TypeOf<Schema> | undefined>) => boolean
|
|
161
|
+
submit: () => Promise<boolean>;
|
|
162
|
+
validate: (value?: Partial<z.TypeOf<Schema> | undefined>) => Promise<boolean>;
|
|
163
163
|
errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema, string>> | undefined>>;
|
|
164
164
|
status: Readonly<Ref<FormStatus | undefined>>;
|
|
165
165
|
invalid: import("vue").ComputedRef<boolean>;
|
|
@@ -191,8 +191,8 @@ export declare const defineForm: <Schema extends FormSchema>(schema: Schema, pro
|
|
|
191
191
|
onSubmit?: ((...args: any[]) => any) | undefined;
|
|
192
192
|
}, {
|
|
193
193
|
formData: Ref<Partial<z.TypeOf<Schema> | undefined>>;
|
|
194
|
-
submit: () => boolean
|
|
195
|
-
validate: (value?: Partial<z.TypeOf<Schema> | undefined>) => boolean
|
|
194
|
+
submit: () => Promise<boolean>;
|
|
195
|
+
validate: (value?: Partial<z.TypeOf<Schema> | undefined>) => Promise<boolean>;
|
|
196
196
|
errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema, string>> | undefined>>;
|
|
197
197
|
status: Readonly<Ref<FormStatus | undefined>>;
|
|
198
198
|
invalid: import("vue").ComputedRef<boolean>;
|
|
@@ -205,8 +205,8 @@ export declare const defineForm: <Schema extends FormSchema>(schema: Schema, pro
|
|
|
205
205
|
$slots: {
|
|
206
206
|
default: (_: {
|
|
207
207
|
formData: unknown extends Partial<z.TypeOf<Schema>> | undefined ? undefined : Partial<z.TypeOf<Schema>> | undefined;
|
|
208
|
-
submit: () => boolean
|
|
209
|
-
validate: () => boolean
|
|
208
|
+
submit: () => Promise<boolean>;
|
|
209
|
+
validate: () => Promise<boolean>;
|
|
210
210
|
errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema, string>>>>;
|
|
211
211
|
status: Ref<DeepReadonly<`${FormStatus}` | undefined>>;
|
|
212
212
|
invalid: Ref<DeepReadonly<boolean>>;
|
|
@@ -121,8 +121,8 @@ export declare const defineFormTemplate: <Schema extends FormSchema>(formProvide
|
|
|
121
121
|
$slots: {
|
|
122
122
|
default: (_: {
|
|
123
123
|
formData: unknown extends Partial<TypeOf<Schema>> | undefined ? undefined : Partial<TypeOf<Schema>> | undefined;
|
|
124
|
-
submit: () => boolean
|
|
125
|
-
validate: () => boolean
|
|
124
|
+
submit: () => Promise<boolean>;
|
|
125
|
+
validate: () => Promise<boolean>;
|
|
126
126
|
errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema, string>>>>;
|
|
127
127
|
status: Ref<DeepReadonly<`${FormStatus}` | undefined>>;
|
|
128
128
|
invalid: Ref<DeepReadonly<boolean>>;
|
|
@@ -83,8 +83,8 @@ export declare const defineFormWrapper: <Schema extends FormSchema>(formProvideK
|
|
|
83
83
|
}, {
|
|
84
84
|
formData: Ref<Partial<TypeOf<Schema>> | undefined> | undefined;
|
|
85
85
|
errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema, string>> | undefined>> | undefined;
|
|
86
|
-
submit: (() => boolean) | undefined;
|
|
87
|
-
validate: (() => boolean) | undefined;
|
|
86
|
+
submit: (() => Promise<boolean>) | undefined;
|
|
87
|
+
validate: (() => Promise<boolean>) | undefined;
|
|
88
88
|
invalid: import("vue").ComputedRef<boolean>;
|
|
89
89
|
fields: Ref<Set<string>>;
|
|
90
90
|
fieldsErrors: Ref<Map<string, z.inferFormattedError<Schema, string>>>;
|
|
@@ -125,8 +125,8 @@ export declare const defineFormWrapper: <Schema extends FormSchema>(formProvideK
|
|
|
125
125
|
} & import("vue").ShallowUnwrapRef<{
|
|
126
126
|
formData: Ref<Partial<TypeOf<Schema>> | undefined> | undefined;
|
|
127
127
|
errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema, string>> | undefined>> | undefined;
|
|
128
|
-
submit: (() => boolean) | undefined;
|
|
129
|
-
validate: (() => boolean) | undefined;
|
|
128
|
+
submit: (() => Promise<boolean>) | undefined;
|
|
129
|
+
validate: (() => Promise<boolean>) | undefined;
|
|
130
130
|
invalid: import("vue").ComputedRef<boolean>;
|
|
131
131
|
fields: Ref<Set<string>>;
|
|
132
132
|
fieldsErrors: Ref<Map<string, z.inferFormattedError<Schema, string>>>;
|
|
@@ -149,8 +149,8 @@ export declare const defineFormWrapper: <Schema extends FormSchema>(formProvideK
|
|
|
149
149
|
}, {
|
|
150
150
|
formData: Ref<Partial<TypeOf<Schema>> | undefined> | undefined;
|
|
151
151
|
errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema, string>> | undefined>> | undefined;
|
|
152
|
-
submit: (() => boolean) | undefined;
|
|
153
|
-
validate: (() => boolean) | undefined;
|
|
152
|
+
submit: (() => Promise<boolean>) | undefined;
|
|
153
|
+
validate: (() => Promise<boolean>) | undefined;
|
|
154
154
|
invalid: import("vue").ComputedRef<boolean>;
|
|
155
155
|
fields: Ref<Set<string>>;
|
|
156
156
|
fieldsErrors: Ref<Map<string, z.inferFormattedError<Schema, string>>>;
|
|
@@ -161,8 +161,8 @@ export declare const defineFormWrapper: <Schema extends FormSchema>(formProvideK
|
|
|
161
161
|
default: (_: {
|
|
162
162
|
invalid: boolean;
|
|
163
163
|
formData: unknown extends Partial<TypeOf<Schema>> | undefined ? undefined : Partial<TypeOf<Schema>> | undefined;
|
|
164
|
-
submit: () => boolean
|
|
165
|
-
validate: () => boolean
|
|
164
|
+
submit: () => Promise<boolean>;
|
|
165
|
+
validate: () => Promise<boolean>;
|
|
166
166
|
errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema, string>>>>;
|
|
167
167
|
fieldsErrors: Map<string, Record<string, {
|
|
168
168
|
_errors: string[];
|
package/dist/src/index.d.ts
CHANGED
|
@@ -103,8 +103,8 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
103
103
|
onSubmit?: ((...args: any[]) => any) | undefined;
|
|
104
104
|
}, {
|
|
105
105
|
formData: import("vue").Ref<Partial<import("zod").TypeOf<Schema> | undefined>>;
|
|
106
|
-
submit: () => boolean
|
|
107
|
-
validate: (value?: Partial<import("zod").TypeOf<Schema> | undefined>) => boolean
|
|
106
|
+
submit: () => Promise<boolean>;
|
|
107
|
+
validate: (value?: Partial<import("zod").TypeOf<Schema> | undefined>) => Promise<boolean>;
|
|
108
108
|
errors: Readonly<import("vue").Ref<import("vue").DeepReadonly<import("zod").inferFormattedError<Schema, string>> | undefined>>;
|
|
109
109
|
status: Readonly<import("vue").Ref<import("./enums").FormStatus | undefined>>;
|
|
110
110
|
invalid: import("vue").ComputedRef<boolean>;
|
|
@@ -157,8 +157,8 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
157
157
|
onSubmit?: ((...args: any[]) => any) | undefined;
|
|
158
158
|
} & import("vue").ShallowUnwrapRef<{
|
|
159
159
|
formData: import("vue").Ref<Partial<import("zod").TypeOf<Schema> | undefined>>;
|
|
160
|
-
submit: () => boolean
|
|
161
|
-
validate: (value?: Partial<import("zod").TypeOf<Schema> | undefined>) => boolean
|
|
160
|
+
submit: () => Promise<boolean>;
|
|
161
|
+
validate: (value?: Partial<import("zod").TypeOf<Schema> | undefined>) => Promise<boolean>;
|
|
162
162
|
errors: Readonly<import("vue").Ref<import("vue").DeepReadonly<import("zod").inferFormattedError<Schema, string>> | undefined>>;
|
|
163
163
|
status: Readonly<import("vue").Ref<import("./enums").FormStatus | undefined>>;
|
|
164
164
|
invalid: import("vue").ComputedRef<boolean>;
|
|
@@ -190,8 +190,8 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
190
190
|
onSubmit?: ((...args: any[]) => any) | undefined;
|
|
191
191
|
}, {
|
|
192
192
|
formData: import("vue").Ref<Partial<import("zod").TypeOf<Schema> | undefined>>;
|
|
193
|
-
submit: () => boolean
|
|
194
|
-
validate: (value?: Partial<import("zod").TypeOf<Schema> | undefined>) => boolean
|
|
193
|
+
submit: () => Promise<boolean>;
|
|
194
|
+
validate: (value?: Partial<import("zod").TypeOf<Schema> | undefined>) => Promise<boolean>;
|
|
195
195
|
errors: Readonly<import("vue").Ref<import("vue").DeepReadonly<import("zod").inferFormattedError<Schema, string>> | undefined>>;
|
|
196
196
|
status: Readonly<import("vue").Ref<import("./enums").FormStatus | undefined>>;
|
|
197
197
|
invalid: import("vue").ComputedRef<boolean>;
|
|
@@ -204,8 +204,8 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
204
204
|
$slots: {
|
|
205
205
|
default: (_: {
|
|
206
206
|
formData: unknown extends Partial<import("zod").TypeOf<Schema>> | undefined ? undefined : Partial<import("zod").TypeOf<Schema>> | undefined;
|
|
207
|
-
submit: () => boolean
|
|
208
|
-
validate: () => boolean
|
|
207
|
+
submit: () => Promise<boolean>;
|
|
208
|
+
validate: () => Promise<boolean>;
|
|
209
209
|
errors: Readonly<import("vue").Ref<import("vue").DeepReadonly<import("zod").inferFormattedError<Schema, string>>>>;
|
|
210
210
|
status: import("vue").Ref<import("vue").DeepReadonly<"invalid" | "valid" | undefined>>;
|
|
211
211
|
invalid: import("vue").Ref<import("vue").DeepReadonly<boolean>>;
|
|
@@ -294,8 +294,8 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
294
294
|
}, {
|
|
295
295
|
formData: import("vue").Ref<Partial<import("zod").TypeOf<Schema>> | undefined> | undefined;
|
|
296
296
|
errors: Readonly<import("vue").Ref<import("vue").DeepReadonly<import("zod").inferFormattedError<Schema, string>> | undefined>> | undefined;
|
|
297
|
-
submit: (() => boolean) | undefined;
|
|
298
|
-
validate: (() => boolean) | undefined;
|
|
297
|
+
submit: (() => Promise<boolean>) | undefined;
|
|
298
|
+
validate: (() => Promise<boolean>) | undefined;
|
|
299
299
|
invalid: import("vue").ComputedRef<boolean>;
|
|
300
300
|
fields: import("vue").Ref<Set<string>>;
|
|
301
301
|
fieldsErrors: import("vue").Ref<Map<string, import("zod").inferFormattedError<Schema, string>>>;
|
|
@@ -336,8 +336,8 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
336
336
|
} & import("vue").ShallowUnwrapRef<{
|
|
337
337
|
formData: import("vue").Ref<Partial<import("zod").TypeOf<Schema>> | undefined> | undefined;
|
|
338
338
|
errors: Readonly<import("vue").Ref<import("vue").DeepReadonly<import("zod").inferFormattedError<Schema, string>> | undefined>> | undefined;
|
|
339
|
-
submit: (() => boolean) | undefined;
|
|
340
|
-
validate: (() => boolean) | undefined;
|
|
339
|
+
submit: (() => Promise<boolean>) | undefined;
|
|
340
|
+
validate: (() => Promise<boolean>) | undefined;
|
|
341
341
|
invalid: import("vue").ComputedRef<boolean>;
|
|
342
342
|
fields: import("vue").Ref<Set<string>>;
|
|
343
343
|
fieldsErrors: import("vue").Ref<Map<string, import("zod").inferFormattedError<Schema, string>>>;
|
|
@@ -360,8 +360,8 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
360
360
|
}, {
|
|
361
361
|
formData: import("vue").Ref<Partial<import("zod").TypeOf<Schema>> | undefined> | undefined;
|
|
362
362
|
errors: Readonly<import("vue").Ref<import("vue").DeepReadonly<import("zod").inferFormattedError<Schema, string>> | undefined>> | undefined;
|
|
363
|
-
submit: (() => boolean) | undefined;
|
|
364
|
-
validate: (() => boolean) | undefined;
|
|
363
|
+
submit: (() => Promise<boolean>) | undefined;
|
|
364
|
+
validate: (() => Promise<boolean>) | undefined;
|
|
365
365
|
invalid: import("vue").ComputedRef<boolean>;
|
|
366
366
|
fields: import("vue").Ref<Set<string>>;
|
|
367
367
|
fieldsErrors: import("vue").Ref<Map<string, import("zod").inferFormattedError<Schema, string>>>;
|
|
@@ -372,8 +372,8 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
372
372
|
default: (_: {
|
|
373
373
|
invalid: boolean;
|
|
374
374
|
formData: unknown extends Partial<import("zod").TypeOf<Schema>> | undefined ? undefined : Partial<import("zod").TypeOf<Schema>> | undefined;
|
|
375
|
-
submit: () => boolean
|
|
376
|
-
validate: () => boolean
|
|
375
|
+
submit: () => Promise<boolean>;
|
|
376
|
+
validate: () => Promise<boolean>;
|
|
377
377
|
errors: Readonly<import("vue").Ref<import("vue").DeepReadonly<import("zod").inferFormattedError<Schema, string>>>>;
|
|
378
378
|
fieldsErrors: Map<string, Record<string, {
|
|
379
379
|
_errors: string[];
|
|
@@ -602,8 +602,8 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
602
602
|
$slots: {
|
|
603
603
|
default: (_: {
|
|
604
604
|
formData: unknown extends Partial<import("zod").TypeOf<Schema>> | undefined ? undefined : Partial<import("zod").TypeOf<Schema>> | undefined;
|
|
605
|
-
submit: () => boolean
|
|
606
|
-
validate: () => boolean
|
|
605
|
+
submit: () => Promise<boolean>;
|
|
606
|
+
validate: () => Promise<boolean>;
|
|
607
607
|
errors: Readonly<import("vue").Ref<import("vue").DeepReadonly<import("zod").inferFormattedError<Schema, string>>>>;
|
|
608
608
|
status: import("vue").Ref<import("vue").DeepReadonly<"invalid" | "valid" | undefined>>;
|
|
609
609
|
invalid: import("vue").Ref<import("vue").DeepReadonly<boolean>>;
|
|
@@ -714,10 +714,10 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
714
714
|
formData: import("vue").Ref<Partial<{
|
|
715
715
|
[x: string]: any;
|
|
716
716
|
} | undefined>>;
|
|
717
|
-
submit: () => boolean
|
|
717
|
+
submit: () => Promise<boolean>;
|
|
718
718
|
validate: (value?: Partial<{
|
|
719
719
|
[x: string]: any;
|
|
720
|
-
} | undefined>) => boolean
|
|
720
|
+
} | undefined>) => Promise<boolean>;
|
|
721
721
|
errors: Readonly<import("vue").Ref<{
|
|
722
722
|
readonly [x: string]: {
|
|
723
723
|
readonly _errors: readonly string[];
|
|
@@ -777,10 +777,10 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
777
777
|
formData: import("vue").Ref<Partial<{
|
|
778
778
|
[x: string]: any;
|
|
779
779
|
} | undefined>>;
|
|
780
|
-
submit: () => boolean
|
|
780
|
+
submit: () => Promise<boolean>;
|
|
781
781
|
validate: (value?: Partial<{
|
|
782
782
|
[x: string]: any;
|
|
783
|
-
} | undefined>) => boolean
|
|
783
|
+
} | undefined>) => Promise<boolean>;
|
|
784
784
|
errors: Readonly<import("vue").Ref<{
|
|
785
785
|
readonly [x: string]: {
|
|
786
786
|
readonly _errors: readonly string[];
|
|
@@ -819,10 +819,10 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
819
819
|
formData: import("vue").Ref<Partial<{
|
|
820
820
|
[x: string]: any;
|
|
821
821
|
} | undefined>>;
|
|
822
|
-
submit: () => boolean
|
|
822
|
+
submit: () => Promise<boolean>;
|
|
823
823
|
validate: (value?: Partial<{
|
|
824
824
|
[x: string]: any;
|
|
825
|
-
} | undefined>) => boolean
|
|
825
|
+
} | undefined>) => Promise<boolean>;
|
|
826
826
|
errors: Readonly<import("vue").Ref<{
|
|
827
827
|
readonly [x: string]: {
|
|
828
828
|
readonly _errors: readonly string[];
|
|
@@ -842,8 +842,8 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
842
842
|
formData: Partial<{
|
|
843
843
|
[x: string]: any;
|
|
844
844
|
}> | undefined;
|
|
845
|
-
submit: () => boolean
|
|
846
|
-
validate: () => boolean
|
|
845
|
+
submit: () => Promise<boolean>;
|
|
846
|
+
validate: () => Promise<boolean>;
|
|
847
847
|
errors: Readonly<import("vue").Ref<{
|
|
848
848
|
readonly [x: string]: {
|
|
849
849
|
readonly _errors: readonly string[];
|
|
@@ -944,8 +944,8 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
944
944
|
} | undefined;
|
|
945
945
|
readonly _errors: readonly string[];
|
|
946
946
|
} | undefined>> | undefined;
|
|
947
|
-
submit: (() => boolean) | undefined;
|
|
948
|
-
validate: (() => boolean) | undefined;
|
|
947
|
+
submit: (() => Promise<boolean>) | undefined;
|
|
948
|
+
validate: (() => Promise<boolean>) | undefined;
|
|
949
949
|
invalid: import("vue").ComputedRef<boolean>;
|
|
950
950
|
fields: import("vue").Ref<Set<string>>;
|
|
951
951
|
fieldsErrors: import("vue").Ref<Map<string, import("zod").inferFormattedError<AnyZodObject, string>>>;
|
|
@@ -993,8 +993,8 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
993
993
|
} | undefined;
|
|
994
994
|
readonly _errors: readonly string[];
|
|
995
995
|
} | undefined>> | undefined;
|
|
996
|
-
submit: (() => boolean) | undefined;
|
|
997
|
-
validate: (() => boolean) | undefined;
|
|
996
|
+
submit: (() => Promise<boolean>) | undefined;
|
|
997
|
+
validate: (() => Promise<boolean>) | undefined;
|
|
998
998
|
invalid: import("vue").ComputedRef<boolean>;
|
|
999
999
|
fields: import("vue").Ref<Set<string>>;
|
|
1000
1000
|
fieldsErrors: import("vue").Ref<Map<string, import("zod").inferFormattedError<AnyZodObject, string>>>;
|
|
@@ -1024,8 +1024,8 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
1024
1024
|
} | undefined;
|
|
1025
1025
|
readonly _errors: readonly string[];
|
|
1026
1026
|
} | undefined>> | undefined;
|
|
1027
|
-
submit: (() => boolean) | undefined;
|
|
1028
|
-
validate: (() => boolean) | undefined;
|
|
1027
|
+
submit: (() => Promise<boolean>) | undefined;
|
|
1028
|
+
validate: (() => Promise<boolean>) | undefined;
|
|
1029
1029
|
invalid: import("vue").ComputedRef<boolean>;
|
|
1030
1030
|
fields: import("vue").Ref<Set<string>>;
|
|
1031
1031
|
fieldsErrors: import("vue").Ref<Map<string, import("zod").inferFormattedError<AnyZodObject, string>>>;
|
|
@@ -1038,8 +1038,8 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
1038
1038
|
formData: Partial<{
|
|
1039
1039
|
[x: string]: any;
|
|
1040
1040
|
}> | undefined;
|
|
1041
|
-
submit: () => boolean
|
|
1042
|
-
validate: () => boolean
|
|
1041
|
+
submit: () => Promise<boolean>;
|
|
1042
|
+
validate: () => Promise<boolean>;
|
|
1043
1043
|
errors: Readonly<import("vue").Ref<{
|
|
1044
1044
|
readonly [x: string]: {
|
|
1045
1045
|
readonly _errors: readonly string[];
|
|
@@ -1275,8 +1275,8 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
1275
1275
|
formData: Partial<{
|
|
1276
1276
|
[x: string]: any;
|
|
1277
1277
|
}> | undefined;
|
|
1278
|
-
submit: () => boolean
|
|
1279
|
-
validate: () => boolean
|
|
1278
|
+
submit: () => Promise<boolean>;
|
|
1279
|
+
validate: () => Promise<boolean>;
|
|
1280
1280
|
errors: Readonly<import("vue").Ref<{
|
|
1281
1281
|
readonly [x: string]: {
|
|
1282
1282
|
readonly _errors: readonly string[];
|
|
@@ -1403,8 +1403,8 @@ export declare const formFactory: <Schema extends FormSchema>(schema: Schema, op
|
|
|
1403
1403
|
onSubmit?: ((...args: any[]) => any) | undefined;
|
|
1404
1404
|
}, {
|
|
1405
1405
|
formData: import("vue").Ref<Partial<import("zod").TypeOf<Schema> | undefined>>;
|
|
1406
|
-
submit: () => boolean
|
|
1407
|
-
validate: (value?: Partial<import("zod").TypeOf<Schema> | undefined>) => boolean
|
|
1406
|
+
submit: () => Promise<boolean>;
|
|
1407
|
+
validate: (value?: Partial<import("zod").TypeOf<Schema> | undefined>) => Promise<boolean>;
|
|
1408
1408
|
errors: Readonly<import("vue").Ref<import("vue").DeepReadonly<import("zod").inferFormattedError<Schema, string>> | undefined>>;
|
|
1409
1409
|
status: Readonly<import("vue").Ref<import("./enums").FormStatus | undefined>>;
|
|
1410
1410
|
invalid: import("vue").ComputedRef<boolean>;
|
|
@@ -1457,8 +1457,8 @@ export declare const formFactory: <Schema extends FormSchema>(schema: Schema, op
|
|
|
1457
1457
|
onSubmit?: ((...args: any[]) => any) | undefined;
|
|
1458
1458
|
} & import("vue").ShallowUnwrapRef<{
|
|
1459
1459
|
formData: import("vue").Ref<Partial<import("zod").TypeOf<Schema> | undefined>>;
|
|
1460
|
-
submit: () => boolean
|
|
1461
|
-
validate: (value?: Partial<import("zod").TypeOf<Schema> | undefined>) => boolean
|
|
1460
|
+
submit: () => Promise<boolean>;
|
|
1461
|
+
validate: (value?: Partial<import("zod").TypeOf<Schema> | undefined>) => Promise<boolean>;
|
|
1462
1462
|
errors: Readonly<import("vue").Ref<import("vue").DeepReadonly<import("zod").inferFormattedError<Schema, string>> | undefined>>;
|
|
1463
1463
|
status: Readonly<import("vue").Ref<import("./enums").FormStatus | undefined>>;
|
|
1464
1464
|
invalid: import("vue").ComputedRef<boolean>;
|
|
@@ -1490,8 +1490,8 @@ export declare const formFactory: <Schema extends FormSchema>(schema: Schema, op
|
|
|
1490
1490
|
onSubmit?: ((...args: any[]) => any) | undefined;
|
|
1491
1491
|
}, {
|
|
1492
1492
|
formData: import("vue").Ref<Partial<import("zod").TypeOf<Schema> | undefined>>;
|
|
1493
|
-
submit: () => boolean
|
|
1494
|
-
validate: (value?: Partial<import("zod").TypeOf<Schema> | undefined>) => boolean
|
|
1493
|
+
submit: () => Promise<boolean>;
|
|
1494
|
+
validate: (value?: Partial<import("zod").TypeOf<Schema> | undefined>) => Promise<boolean>;
|
|
1495
1495
|
errors: Readonly<import("vue").Ref<import("vue").DeepReadonly<import("zod").inferFormattedError<Schema, string>> | undefined>>;
|
|
1496
1496
|
status: Readonly<import("vue").Ref<import("./enums").FormStatus | undefined>>;
|
|
1497
1497
|
invalid: import("vue").ComputedRef<boolean>;
|
|
@@ -1504,8 +1504,8 @@ export declare const formFactory: <Schema extends FormSchema>(schema: Schema, op
|
|
|
1504
1504
|
$slots: {
|
|
1505
1505
|
default: (_: {
|
|
1506
1506
|
formData: unknown extends Partial<import("zod").TypeOf<Schema>> | undefined ? undefined : Partial<import("zod").TypeOf<Schema>> | undefined;
|
|
1507
|
-
submit: () => boolean
|
|
1508
|
-
validate: () => boolean
|
|
1507
|
+
submit: () => Promise<boolean>;
|
|
1508
|
+
validate: () => Promise<boolean>;
|
|
1509
1509
|
errors: Readonly<import("vue").Ref<import("vue").DeepReadonly<import("zod").inferFormattedError<Schema, string>>>>;
|
|
1510
1510
|
status: import("vue").Ref<import("vue").DeepReadonly<"invalid" | "valid" | undefined>>;
|
|
1511
1511
|
invalid: import("vue").Ref<import("vue").DeepReadonly<boolean>>;
|
|
@@ -1594,8 +1594,8 @@ export declare const formFactory: <Schema extends FormSchema>(schema: Schema, op
|
|
|
1594
1594
|
}, {
|
|
1595
1595
|
formData: import("vue").Ref<Partial<import("zod").TypeOf<Schema>> | undefined> | undefined;
|
|
1596
1596
|
errors: Readonly<import("vue").Ref<import("vue").DeepReadonly<import("zod").inferFormattedError<Schema, string>> | undefined>> | undefined;
|
|
1597
|
-
submit: (() => boolean) | undefined;
|
|
1598
|
-
validate: (() => boolean) | undefined;
|
|
1597
|
+
submit: (() => Promise<boolean>) | undefined;
|
|
1598
|
+
validate: (() => Promise<boolean>) | undefined;
|
|
1599
1599
|
invalid: import("vue").ComputedRef<boolean>;
|
|
1600
1600
|
fields: import("vue").Ref<Set<string>>;
|
|
1601
1601
|
fieldsErrors: import("vue").Ref<Map<string, import("zod").inferFormattedError<Schema, string>>>;
|
|
@@ -1636,8 +1636,8 @@ export declare const formFactory: <Schema extends FormSchema>(schema: Schema, op
|
|
|
1636
1636
|
} & import("vue").ShallowUnwrapRef<{
|
|
1637
1637
|
formData: import("vue").Ref<Partial<import("zod").TypeOf<Schema>> | undefined> | undefined;
|
|
1638
1638
|
errors: Readonly<import("vue").Ref<import("vue").DeepReadonly<import("zod").inferFormattedError<Schema, string>> | undefined>> | undefined;
|
|
1639
|
-
submit: (() => boolean) | undefined;
|
|
1640
|
-
validate: (() => boolean) | undefined;
|
|
1639
|
+
submit: (() => Promise<boolean>) | undefined;
|
|
1640
|
+
validate: (() => Promise<boolean>) | undefined;
|
|
1641
1641
|
invalid: import("vue").ComputedRef<boolean>;
|
|
1642
1642
|
fields: import("vue").Ref<Set<string>>;
|
|
1643
1643
|
fieldsErrors: import("vue").Ref<Map<string, import("zod").inferFormattedError<Schema, string>>>;
|
|
@@ -1660,8 +1660,8 @@ export declare const formFactory: <Schema extends FormSchema>(schema: Schema, op
|
|
|
1660
1660
|
}, {
|
|
1661
1661
|
formData: import("vue").Ref<Partial<import("zod").TypeOf<Schema>> | undefined> | undefined;
|
|
1662
1662
|
errors: Readonly<import("vue").Ref<import("vue").DeepReadonly<import("zod").inferFormattedError<Schema, string>> | undefined>> | undefined;
|
|
1663
|
-
submit: (() => boolean) | undefined;
|
|
1664
|
-
validate: (() => boolean) | undefined;
|
|
1663
|
+
submit: (() => Promise<boolean>) | undefined;
|
|
1664
|
+
validate: (() => Promise<boolean>) | undefined;
|
|
1665
1665
|
invalid: import("vue").ComputedRef<boolean>;
|
|
1666
1666
|
fields: import("vue").Ref<Set<string>>;
|
|
1667
1667
|
fieldsErrors: import("vue").Ref<Map<string, import("zod").inferFormattedError<Schema, string>>>;
|
|
@@ -1672,8 +1672,8 @@ export declare const formFactory: <Schema extends FormSchema>(schema: Schema, op
|
|
|
1672
1672
|
default: (_: {
|
|
1673
1673
|
invalid: boolean;
|
|
1674
1674
|
formData: unknown extends Partial<import("zod").TypeOf<Schema>> | undefined ? undefined : Partial<import("zod").TypeOf<Schema>> | undefined;
|
|
1675
|
-
submit: () => boolean
|
|
1676
|
-
validate: () => boolean
|
|
1675
|
+
submit: () => Promise<boolean>;
|
|
1676
|
+
validate: () => Promise<boolean>;
|
|
1677
1677
|
errors: Readonly<import("vue").Ref<import("vue").DeepReadonly<import("zod").inferFormattedError<Schema, string>>>>;
|
|
1678
1678
|
fieldsErrors: Map<string, Record<string, {
|
|
1679
1679
|
_errors: string[];
|
|
@@ -1902,8 +1902,8 @@ export declare const formFactory: <Schema extends FormSchema>(schema: Schema, op
|
|
|
1902
1902
|
$slots: {
|
|
1903
1903
|
default: (_: {
|
|
1904
1904
|
formData: unknown extends Partial<import("zod").TypeOf<Schema>> | undefined ? undefined : Partial<import("zod").TypeOf<Schema>> | undefined;
|
|
1905
|
-
submit: () => boolean
|
|
1906
|
-
validate: () => boolean
|
|
1905
|
+
submit: () => Promise<boolean>;
|
|
1906
|
+
validate: () => Promise<boolean>;
|
|
1907
1907
|
errors: Readonly<import("vue").Ref<import("vue").DeepReadonly<import("zod").inferFormattedError<Schema, string>>>>;
|
|
1908
1908
|
status: import("vue").Ref<import("vue").DeepReadonly<"invalid" | "valid" | undefined>>;
|
|
1909
1909
|
invalid: import("vue").Ref<import("vue").DeepReadonly<boolean>>;
|
package/dist/src/types.d.ts
CHANGED
|
@@ -23,8 +23,8 @@ export type FormPluginOptions = FormPluginOptionsSchema & FormComposableOptions<
|
|
|
23
23
|
export type InjectedFormData<Schema extends FormSchema> = {
|
|
24
24
|
formData: Ref<Partial<z.infer<Schema>> | undefined>;
|
|
25
25
|
errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema>> | undefined>>;
|
|
26
|
-
submit: () => boolean
|
|
27
|
-
validate: () => boolean
|
|
26
|
+
submit: () => Promise<boolean>;
|
|
27
|
+
validate: () => Promise<boolean>;
|
|
28
28
|
status: Readonly<Ref<FormStatus | undefined>>;
|
|
29
29
|
invalid: Readonly<Ref<boolean>>;
|
|
30
30
|
};
|
|
@@ -38,16 +38,15 @@ export type InjectedFormFieldData<Schema extends FormSchema> = {
|
|
|
38
38
|
errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema>>>>;
|
|
39
39
|
};
|
|
40
40
|
export type Primitive = null | undefined | string | number | boolean | symbol | bigint;
|
|
41
|
-
type ArrayKey = number;
|
|
42
41
|
type IsTuple<T extends readonly any[]> = number extends T['length'] ? false : true;
|
|
43
42
|
type TupleKeys<T extends readonly any[]> = Exclude<keyof T, keyof any[]>;
|
|
44
43
|
export type PathConcat<TKey extends string | number, TValue> = TValue extends Primitive ? `${TKey}` : `${TKey}` | `${TKey}.${Path<TValue>}`;
|
|
45
44
|
export type Path<T> = T extends readonly (infer V)[] ? IsTuple<T> extends true ? {
|
|
46
45
|
[K in TupleKeys<T>]-?: PathConcat<K & string, T[K]>;
|
|
47
|
-
}[TupleKeys<T>] : PathConcat<
|
|
46
|
+
}[TupleKeys<T>] : PathConcat<number, V> : {
|
|
48
47
|
[K in keyof T]-?: PathConcat<K & string, T[K]>;
|
|
49
48
|
}[keyof T];
|
|
50
|
-
export type PathValue<T, TPath extends Path<T> | Path<T>[]> = T extends any ? TPath extends `${infer K}.${infer R}` ? K extends keyof T ? R extends Path<T[K]> ? undefined extends T[K] ? PathValue<T[K], R> | undefined : PathValue<T[K], R> : never : K extends `${
|
|
49
|
+
export type PathValue<T, TPath extends Path<T> | Path<T>[]> = T extends any ? TPath extends `${infer K}.${infer R}` ? K extends keyof T ? R extends Path<T[K]> ? undefined extends T[K] ? PathValue<T[K], R> | undefined : PathValue<T[K], R> : never : K extends `${number}` ? T extends readonly (infer V)[] ? PathValue<V, R & Path<V>> : never : never : TPath extends keyof T ? T[TPath] : TPath extends `${number}` ? T extends readonly (infer V)[] ? V : never : never : never;
|
|
51
50
|
export type AnyBoolean<Schema extends FormSchema> = boolean | Ref<boolean> | ((data?: InjectedFormData<Schema>) => boolean | Ref<boolean>);
|
|
52
51
|
export type SimpleFormTemplateItem<Schema extends FormSchema> = Record<string, any> & {
|
|
53
52
|
vvIs?: string | Component;
|
package/package.json
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"bugs": {
|
|
20
20
|
"url": "https://github.com/volverjs/form-vue/issues"
|
|
21
21
|
},
|
|
22
|
-
"version": "0.0.
|
|
22
|
+
"version": "1.0.0-beta.1",
|
|
23
23
|
"engines": {
|
|
24
24
|
"node": ">= 16.x"
|
|
25
25
|
},
|
|
@@ -35,16 +35,16 @@
|
|
|
35
35
|
"*.d.ts"
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@volverjs/ui-vue": "
|
|
38
|
+
"@volverjs/ui-vue": "next",
|
|
39
39
|
"@vueuse/core": "^10.4.1",
|
|
40
40
|
"ts-dot-prop": "^2.1.3",
|
|
41
41
|
"vue": "^3.3.4",
|
|
42
42
|
"zod": "^3.22.2"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@playwright/experimental-ct-vue": "1.38.
|
|
45
|
+
"@playwright/experimental-ct-vue": "1.38.1",
|
|
46
46
|
"@testing-library/vue": "^7.0.0",
|
|
47
|
-
"@typescript-eslint/eslint-plugin": "^6.7.
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^6.7.3",
|
|
48
48
|
"@vitejs/plugin-vue": "^4.3.4",
|
|
49
49
|
"@volverjs/style": "^0.1.11",
|
|
50
50
|
"@vue/compiler-sfc": "^3.3.4",
|
|
@@ -52,18 +52,18 @@
|
|
|
52
52
|
"@vue/runtime-core": "^3.3.4",
|
|
53
53
|
"@vue/test-utils": "^2.4.1",
|
|
54
54
|
"copy": "^0.3.2",
|
|
55
|
-
"eslint": "^8.
|
|
55
|
+
"eslint": "^8.50.0",
|
|
56
56
|
"eslint-config-prettier": "^9.0.0",
|
|
57
57
|
"eslint-plugin-prettier": "^5.0.0",
|
|
58
58
|
"eslint-plugin-vue": "^9.17.0",
|
|
59
|
-
"happy-dom": "^
|
|
59
|
+
"happy-dom": "^12.2.0",
|
|
60
60
|
"prettier": "^3.0.3",
|
|
61
61
|
"typescript": "^5.2.2",
|
|
62
62
|
"vite": "^4.4.9",
|
|
63
|
-
"vite-plugin-dts": "^3.
|
|
63
|
+
"vite-plugin-dts": "^3.6.0",
|
|
64
64
|
"vite-plugin-eslint": "^1.8.1",
|
|
65
65
|
"vite-plugin-externalize-deps": "^0.7.0",
|
|
66
|
-
"vitest": "^0.34.
|
|
66
|
+
"vitest": "^0.34.5"
|
|
67
67
|
},
|
|
68
68
|
"typesVersions": {
|
|
69
69
|
"*": {
|
package/src/VvForm.ts
CHANGED
|
@@ -83,12 +83,12 @@ export const defineForm = <Schema extends FormSchema>(
|
|
|
83
83
|
// emit update:modelValue on formData change
|
|
84
84
|
watchThrottled(
|
|
85
85
|
formData,
|
|
86
|
-
(newValue) => {
|
|
86
|
+
async (newValue) => {
|
|
87
87
|
if (
|
|
88
88
|
(errors.value || options?.continuosValidation) ??
|
|
89
89
|
props.continuosValidation
|
|
90
90
|
) {
|
|
91
|
-
validate()
|
|
91
|
+
await validate()
|
|
92
92
|
}
|
|
93
93
|
if (
|
|
94
94
|
!newValue ||
|
|
@@ -107,8 +107,8 @@ export const defineForm = <Schema extends FormSchema>(
|
|
|
107
107
|
)
|
|
108
108
|
|
|
109
109
|
// validate formData with safeParse
|
|
110
|
-
const validate = (value = formData.value) => {
|
|
111
|
-
const parseResult = schema.
|
|
110
|
+
const validate = async (value = formData.value) => {
|
|
111
|
+
const parseResult = await schema.safeParseAsync(value)
|
|
112
112
|
if (!parseResult.success) {
|
|
113
113
|
errors.value =
|
|
114
114
|
parseResult.error.format() as ZodFormattedError<
|
|
@@ -130,8 +130,8 @@ export const defineForm = <Schema extends FormSchema>(
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
// emit submit event if form is valid
|
|
133
|
-
const submit = () => {
|
|
134
|
-
if (!validate()) {
|
|
133
|
+
const submit = async () => {
|
|
134
|
+
if (!(await validate())) {
|
|
135
135
|
return false
|
|
136
136
|
}
|
|
137
137
|
emit('submit', formData.value as z.infer<Schema>)
|
|
@@ -209,8 +209,8 @@ export const defineForm = <Schema extends FormSchema>(
|
|
|
209
209
|
| undefined
|
|
210
210
|
? undefined
|
|
211
211
|
: Partial<TypeOf<Schema>> | undefined
|
|
212
|
-
submit: () => boolean
|
|
213
|
-
validate: () => boolean
|
|
212
|
+
submit: () => Promise<boolean>
|
|
213
|
+
validate: () => Promise<boolean>
|
|
214
214
|
errors: Readonly<
|
|
215
215
|
Ref<DeepReadonly<z.inferFormattedError<Schema>>>
|
|
216
216
|
>
|
package/src/VvFormTemplate.ts
CHANGED
|
@@ -162,8 +162,8 @@ export const defineFormTemplate = <Schema extends FormSchema>(
|
|
|
162
162
|
| undefined
|
|
163
163
|
? undefined
|
|
164
164
|
: Partial<TypeOf<Schema>> | undefined
|
|
165
|
-
submit: () => boolean
|
|
166
|
-
validate: () => boolean
|
|
165
|
+
submit: () => Promise<boolean>
|
|
166
|
+
validate: () => Promise<boolean>
|
|
167
167
|
errors: Readonly<
|
|
168
168
|
Ref<DeepReadonly<z.inferFormattedError<Schema>>>
|
|
169
169
|
>
|
package/src/VvFormWrapper.ts
CHANGED
|
@@ -149,8 +149,8 @@ export const defineFormWrapper = <Schema extends FormSchema>(
|
|
|
149
149
|
| undefined
|
|
150
150
|
? undefined
|
|
151
151
|
: Partial<TypeOf<Schema>> | undefined
|
|
152
|
-
submit: () => boolean
|
|
153
|
-
validate: () => boolean
|
|
152
|
+
submit: () => Promise<boolean>
|
|
153
|
+
validate: () => Promise<boolean>
|
|
154
154
|
errors: Readonly<
|
|
155
155
|
Ref<DeepReadonly<z.inferFormattedError<Schema>>>
|
|
156
156
|
>
|
package/src/types.ts
CHANGED
|
@@ -45,8 +45,8 @@ export type InjectedFormData<Schema extends FormSchema> = {
|
|
|
45
45
|
errors: Readonly<
|
|
46
46
|
Ref<DeepReadonly<z.inferFormattedError<Schema>> | undefined>
|
|
47
47
|
>
|
|
48
|
-
submit: () => boolean
|
|
49
|
-
validate: () => boolean
|
|
48
|
+
submit: () => Promise<boolean>
|
|
49
|
+
validate: () => Promise<boolean>
|
|
50
50
|
status: Readonly<Ref<FormStatus | undefined>>
|
|
51
51
|
invalid: Readonly<Ref<boolean>>
|
|
52
52
|
}
|
|
@@ -71,8 +71,6 @@ export type Primitive =
|
|
|
71
71
|
| symbol
|
|
72
72
|
| bigint
|
|
73
73
|
|
|
74
|
-
type ArrayKey = number
|
|
75
|
-
|
|
76
74
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
77
75
|
type IsTuple<T extends readonly any[]> = number extends T['length']
|
|
78
76
|
? false
|
|
@@ -91,7 +89,7 @@ export type Path<T> = T extends readonly (infer V)[]
|
|
|
91
89
|
? {
|
|
92
90
|
[K in TupleKeys<T>]-?: PathConcat<K & string, T[K]>
|
|
93
91
|
}[TupleKeys<T>]
|
|
94
|
-
: PathConcat<
|
|
92
|
+
: PathConcat<number, V>
|
|
95
93
|
: {
|
|
96
94
|
[K in keyof T]-?: PathConcat<K & string, T[K]>
|
|
97
95
|
}[keyof T]
|
|
@@ -105,14 +103,14 @@ export type PathValue<T, TPath extends Path<T> | Path<T>[]> = T extends any
|
|
|
105
103
|
? PathValue<T[K], R> | undefined
|
|
106
104
|
: PathValue<T[K], R>
|
|
107
105
|
: never
|
|
108
|
-
: K extends `${
|
|
106
|
+
: K extends `${number}`
|
|
109
107
|
? T extends readonly (infer V)[]
|
|
110
108
|
? PathValue<V, R & Path<V>>
|
|
111
109
|
: never
|
|
112
110
|
: never
|
|
113
111
|
: TPath extends keyof T
|
|
114
112
|
? T[TPath]
|
|
115
|
-
: TPath extends `${
|
|
113
|
+
: TPath extends `${number}`
|
|
116
114
|
? T extends readonly (infer V)[]
|
|
117
115
|
? V
|
|
118
116
|
: never
|