@volverjs/form-vue 1.0.0-beta.17 → 1.0.0-beta.18
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 +115 -115
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
- package/src/VvForm.ts +1 -4
package/dist/index.es.js
CHANGED
|
@@ -24,15 +24,15 @@ function z(e, l, r) {
|
|
|
24
24
|
const f = be(r) ? r : void 0;
|
|
25
25
|
if (!ee(e) || !re(l))
|
|
26
26
|
return f;
|
|
27
|
-
const
|
|
28
|
-
if (
|
|
29
|
-
for (const
|
|
30
|
-
if (
|
|
27
|
+
const a = ae(l);
|
|
28
|
+
if (a.length !== 0) {
|
|
29
|
+
for (const n of a) {
|
|
30
|
+
if (n === "*")
|
|
31
31
|
continue;
|
|
32
32
|
const i = function(u) {
|
|
33
|
-
return u.map((t) => Z(t) || D(t) ? t : q(t) ? i(t) : t[
|
|
33
|
+
return u.map((t) => Z(t) || D(t) ? t : q(t) ? i(t) : t[n]);
|
|
34
34
|
};
|
|
35
|
-
if (q(e) && !Ve.test(
|
|
35
|
+
if (q(e) && !Ve.test(n) ? e = i(e) : e = e[n], Z(e) || D(e))
|
|
36
36
|
break;
|
|
37
37
|
}
|
|
38
38
|
return Z(e) ? f : e;
|
|
@@ -44,15 +44,15 @@ function te(e, l, r) {
|
|
|
44
44
|
const f = ae(l);
|
|
45
45
|
if (f.length === 0)
|
|
46
46
|
return;
|
|
47
|
-
const
|
|
48
|
-
for (let
|
|
49
|
-
const i = f[
|
|
50
|
-
if (
|
|
47
|
+
const a = f.length;
|
|
48
|
+
for (let n = 0; n < a; n++) {
|
|
49
|
+
const i = f[n];
|
|
50
|
+
if (n === a - 1) {
|
|
51
51
|
e[i] = r;
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
54
|
if (i === "*" && q(e)) {
|
|
55
|
-
const u = f.slice(
|
|
55
|
+
const u = f.slice(n + 1).join(".");
|
|
56
56
|
for (const t of e)
|
|
57
57
|
te(t, u, r);
|
|
58
58
|
return;
|
|
@@ -64,14 +64,14 @@ function ae(e) {
|
|
|
64
64
|
const l = e.split(/[.]|(?:\[(\d|\*)\])/).filter((r) => !!r);
|
|
65
65
|
return l.some((r) => ge.indexOf(r) !== -1) ? [] : l;
|
|
66
66
|
}
|
|
67
|
-
var d = /* @__PURE__ */ ((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 || {}),
|
|
67
|
+
var d = /* @__PURE__ */ ((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 || {}), k = /* @__PURE__ */ ((e) => (e.invalid = "invalid", e.valid = "valid", e.submitting = "submitting", e.reset = "reset", e.updated = "updated", e.unknown = "unknown", e))(k || {});
|
|
68
68
|
function xe(e, l, r, f) {
|
|
69
69
|
return M({
|
|
70
70
|
name: "VvFormField",
|
|
71
71
|
props: {
|
|
72
72
|
type: {
|
|
73
73
|
type: String,
|
|
74
|
-
validator: (
|
|
74
|
+
validator: (a) => Object.values(d).includes(a),
|
|
75
75
|
default: d.custom
|
|
76
76
|
},
|
|
77
77
|
is: {
|
|
@@ -119,21 +119,21 @@ function xe(e, l, r, f) {
|
|
|
119
119
|
"type"
|
|
120
120
|
],
|
|
121
121
|
slots: Object,
|
|
122
|
-
setup(
|
|
122
|
+
setup(a, { slots: n, emit: i }) {
|
|
123
123
|
const u = C(l, void 0);
|
|
124
|
-
u && u.fields.value.add(
|
|
125
|
-
const t = C(e), { props: g, name: o } = j(
|
|
124
|
+
u && u.fields.value.add(a.name);
|
|
125
|
+
const t = C(e), { props: g, name: o } = j(a), v = W({
|
|
126
126
|
get() {
|
|
127
127
|
if (t != null && t.formData)
|
|
128
128
|
return z(
|
|
129
129
|
new Object(t.formData.value),
|
|
130
|
-
String(
|
|
130
|
+
String(a.name)
|
|
131
131
|
);
|
|
132
132
|
},
|
|
133
133
|
set(s) {
|
|
134
134
|
t != null && t.formData && (te(
|
|
135
135
|
new Object(t.formData.value),
|
|
136
|
-
String(
|
|
136
|
+
String(a.name),
|
|
137
137
|
s
|
|
138
138
|
), i("update:modelValue", {
|
|
139
139
|
newValue: v.value,
|
|
@@ -142,22 +142,22 @@ function xe(e, l, r, f) {
|
|
|
142
142
|
}
|
|
143
143
|
});
|
|
144
144
|
F(() => {
|
|
145
|
-
v.value === void 0 &&
|
|
145
|
+
v.value === void 0 && a.defaultValue !== void 0 && (v.value = a.defaultValue);
|
|
146
146
|
});
|
|
147
147
|
const m = W(() => {
|
|
148
148
|
if (t != null && t.errors.value)
|
|
149
|
-
return z(t.errors.value, String(
|
|
149
|
+
return z(t.errors.value, String(a.name));
|
|
150
150
|
}), c = W(() => {
|
|
151
151
|
var s;
|
|
152
152
|
return (s = m.value) == null ? void 0 : s._errors;
|
|
153
153
|
}), h = W(() => m.value !== void 0), S = _(h, () => {
|
|
154
154
|
h.value ? (i("invalid", c.value), u && u.errors.value.set(
|
|
155
|
-
|
|
155
|
+
a.name,
|
|
156
156
|
{
|
|
157
157
|
_errors: c.value
|
|
158
158
|
}
|
|
159
159
|
)) : (i("valid", v.value), u && u.errors.value.delete(
|
|
160
|
-
|
|
160
|
+
a.name
|
|
161
161
|
));
|
|
162
162
|
}), I = _(
|
|
163
163
|
() => t == null ? void 0 : t.formData,
|
|
@@ -171,17 +171,17 @@ function xe(e, l, r, f) {
|
|
|
171
171
|
});
|
|
172
172
|
const O = (s) => {
|
|
173
173
|
v.value = s;
|
|
174
|
-
},
|
|
174
|
+
}, w = W(() => {
|
|
175
175
|
let s = g.value;
|
|
176
176
|
return typeof s == "function" && (s = s(t == null ? void 0 : t.formData)), Object.keys(s).reduce(
|
|
177
|
-
(E,
|
|
177
|
+
(E, p) => (E[p] = G(s[p]), E),
|
|
178
178
|
{}
|
|
179
179
|
);
|
|
180
|
-
}), b = W(() => t != null && t.readonly.value ? !0 :
|
|
181
|
-
...
|
|
182
|
-
name:
|
|
180
|
+
}), b = W(() => t != null && t.readonly.value ? !0 : w.value.readonly ?? a.readonly), V = W(() => ({
|
|
181
|
+
...w.value,
|
|
182
|
+
name: w.value.name ?? a.name,
|
|
183
183
|
invalid: h.value,
|
|
184
|
-
valid:
|
|
184
|
+
valid: a.showValid ? !!(!h.value && v.value) : void 0,
|
|
185
185
|
type: ((s) => {
|
|
186
186
|
if ([
|
|
187
187
|
d.color,
|
|
@@ -199,7 +199,7 @@ function xe(e, l, r, f) {
|
|
|
199
199
|
d.week
|
|
200
200
|
].includes(s))
|
|
201
201
|
return s;
|
|
202
|
-
})(
|
|
202
|
+
})(a.type),
|
|
203
203
|
invalidLabel: c.value,
|
|
204
204
|
modelValue: v.value,
|
|
205
205
|
readonly: b.value,
|
|
@@ -209,11 +209,11 @@ function xe(e, l, r, f) {
|
|
|
209
209
|
name: U(o),
|
|
210
210
|
errors: U(m)
|
|
211
211
|
}), { component: W(() => {
|
|
212
|
-
if (
|
|
212
|
+
if (a.type === d.custom)
|
|
213
213
|
return {
|
|
214
214
|
render() {
|
|
215
215
|
var s;
|
|
216
|
-
return ((s =
|
|
216
|
+
return ((s = n.default) == null ? void 0 : s.call(n, {
|
|
217
217
|
errors: m.value,
|
|
218
218
|
formData: t == null ? void 0 : t.formData.value,
|
|
219
219
|
formErrors: t == null ? void 0 : t.errors.value,
|
|
@@ -224,12 +224,12 @@ function xe(e, l, r, f) {
|
|
|
224
224
|
readonly: b.value,
|
|
225
225
|
submit: t == null ? void 0 : t.submit,
|
|
226
226
|
validate: t == null ? void 0 : t.validate
|
|
227
|
-
})) ??
|
|
227
|
+
})) ?? n.default;
|
|
228
228
|
}
|
|
229
229
|
};
|
|
230
|
-
if (!((f == null ? void 0 : f.lazyLoad) ??
|
|
230
|
+
if (!((f == null ? void 0 : f.lazyLoad) ?? a.lazyLoad)) {
|
|
231
231
|
let s;
|
|
232
|
-
switch (
|
|
232
|
+
switch (a.type) {
|
|
233
233
|
case d.select:
|
|
234
234
|
s = B("VvSelect");
|
|
235
235
|
break;
|
|
@@ -261,7 +261,7 @@ function xe(e, l, r, f) {
|
|
|
261
261
|
);
|
|
262
262
|
}
|
|
263
263
|
return le(async () => {
|
|
264
|
-
switch (f != null && f.sideEffects && await Promise.resolve(f.sideEffects(
|
|
264
|
+
switch (f != null && f.sideEffects && await Promise.resolve(f.sideEffects(a.type)), a.type) {
|
|
265
265
|
case d.textarea:
|
|
266
266
|
return import("@volverjs/ui-vue/vv-textarea");
|
|
267
267
|
case d.radio:
|
|
@@ -297,11 +297,11 @@ function L(e, l = {}) {
|
|
|
297
297
|
for (; u instanceof X; )
|
|
298
298
|
u = u.innerType();
|
|
299
299
|
return u instanceof Y;
|
|
300
|
-
},
|
|
300
|
+
}, a = r(e);
|
|
301
301
|
return {
|
|
302
|
-
...(
|
|
302
|
+
...(a instanceof K ? a._def.unknownKeys === "passthrough" : !1) ? l : {},
|
|
303
303
|
...Object.fromEntries(
|
|
304
|
-
Object.entries(
|
|
304
|
+
Object.entries(a.shape).map(
|
|
305
305
|
([i, u]) => {
|
|
306
306
|
const t = l[i], g = f(u);
|
|
307
307
|
let o = r(u), v;
|
|
@@ -344,34 +344,34 @@ function L(e, l = {}) {
|
|
|
344
344
|
)
|
|
345
345
|
};
|
|
346
346
|
}
|
|
347
|
-
function
|
|
348
|
-
const
|
|
347
|
+
function Oe(e, l, r, f) {
|
|
348
|
+
const a = R(), n = R(), i = W(() => n.value === k.invalid), u = R(), t = R(!1);
|
|
349
349
|
let g;
|
|
350
350
|
const o = async (b = u.value, V) => {
|
|
351
351
|
if (g = V, t.value)
|
|
352
352
|
return !0;
|
|
353
353
|
const y = await e.safeParseAsync(b);
|
|
354
354
|
if (!y.success) {
|
|
355
|
-
if (!V)
|
|
356
|
-
return
|
|
355
|
+
if (n.value = k.invalid, !V)
|
|
356
|
+
return a.value = y.error.format(), !1;
|
|
357
357
|
const s = y.error.issues.filter((E) => V.has(E.path.join(".")));
|
|
358
|
-
return s.length ? (
|
|
358
|
+
return s.length ? (a.value = new he(s).format(), !1) : (a.value = void 0, !0);
|
|
359
359
|
}
|
|
360
|
-
return
|
|
360
|
+
return a.value = void 0, n.value = k.valid, u.value = y.data, !0;
|
|
361
361
|
}, v = () => {
|
|
362
|
-
|
|
362
|
+
a.value = void 0, n.value = void 0, g = void 0;
|
|
363
363
|
}, m = () => {
|
|
364
|
-
u.value = L(e), v(),
|
|
365
|
-
}, c = async () => t.value || !await o() ? !1 : (
|
|
364
|
+
u.value = L(e), v(), n.value = k.reset;
|
|
365
|
+
}, c = async () => t.value || !await o() ? !1 : (n.value = k.submitting, !0), { ignoreUpdates: h, stop: S } = fe(
|
|
366
366
|
u,
|
|
367
367
|
() => {
|
|
368
|
-
|
|
368
|
+
n.value = k.updated;
|
|
369
369
|
},
|
|
370
370
|
{
|
|
371
371
|
deep: !0,
|
|
372
372
|
eventFilter: oe((r == null ? void 0 : r.updateThrottle) ?? 500)
|
|
373
373
|
}
|
|
374
|
-
), I = U(
|
|
374
|
+
), I = U(a), O = U(n), w = M({
|
|
375
375
|
name: "VvForm",
|
|
376
376
|
props: {
|
|
377
377
|
continuousValidation: {
|
|
@@ -432,37 +432,37 @@ function we(e, l, r, f) {
|
|
|
432
432
|
}
|
|
433
433
|
},
|
|
434
434
|
{ deep: !0 }
|
|
435
|
-
), _(
|
|
436
|
-
var s, E,
|
|
437
|
-
if (y ===
|
|
438
|
-
const x = N(
|
|
435
|
+
), _(n, async (y) => {
|
|
436
|
+
var s, E, p, $, T, H;
|
|
437
|
+
if (y === k.invalid) {
|
|
438
|
+
const x = N(a.value);
|
|
439
439
|
V("invalid", x), (s = r == null ? void 0 : r.onInvalid) == null || s.call(
|
|
440
440
|
r,
|
|
441
441
|
x
|
|
442
442
|
);
|
|
443
443
|
return;
|
|
444
444
|
}
|
|
445
|
-
if (y ===
|
|
445
|
+
if (y === k.valid) {
|
|
446
446
|
const x = N(u.value);
|
|
447
|
-
V("valid", x), (E = r == null ? void 0 : r.onValid) == null || E.call(r, x), V("update:modelValue", x), (
|
|
447
|
+
V("valid", x), (E = r == null ? void 0 : r.onValid) == null || E.call(r, x), V("update:modelValue", x), (p = r == null ? void 0 : r.onUpdate) == null || p.call(r, x);
|
|
448
448
|
return;
|
|
449
449
|
}
|
|
450
|
-
if (y ===
|
|
450
|
+
if (y === k.submitting) {
|
|
451
451
|
const x = N(u.value);
|
|
452
452
|
V("submit", x), ($ = r == null ? void 0 : r.onSubmit) == null || $.call(r, x);
|
|
453
453
|
return;
|
|
454
454
|
}
|
|
455
|
-
if (y ===
|
|
455
|
+
if (y === k.reset) {
|
|
456
456
|
const x = N(u.value);
|
|
457
457
|
V("reset", x), (T = r == null ? void 0 : r.onReset) == null || T.call(r, x);
|
|
458
458
|
return;
|
|
459
459
|
}
|
|
460
|
-
if (y ===
|
|
461
|
-
if ((
|
|
460
|
+
if (y === k.updated) {
|
|
461
|
+
if ((a.value || r != null && r.continuousValidation || b.continuousValidation) && await o(void 0, g), !u.value || !b.modelValue || JSON.stringify(u.value) !== JSON.stringify(b.modelValue)) {
|
|
462
462
|
const x = N(u.value);
|
|
463
463
|
V("update:modelValue", x), (H = r == null ? void 0 : r.onUpdate) == null || H.call(r, x);
|
|
464
464
|
}
|
|
465
|
-
|
|
465
|
+
n.value === k.updated && (n.value = k.unknown);
|
|
466
466
|
}
|
|
467
467
|
}), F(() => {
|
|
468
468
|
t.value = b.readonly;
|
|
@@ -540,20 +540,20 @@ function we(e, l, r, f) {
|
|
|
540
540
|
});
|
|
541
541
|
return {
|
|
542
542
|
clear: v,
|
|
543
|
-
errors:
|
|
543
|
+
errors: a,
|
|
544
544
|
formData: u,
|
|
545
545
|
ignoreUpdates: h,
|
|
546
546
|
invalid: i,
|
|
547
547
|
readonly: t,
|
|
548
548
|
reset: m,
|
|
549
|
-
status:
|
|
549
|
+
status: n,
|
|
550
550
|
stopUpdatesWatch: S,
|
|
551
551
|
submit: c,
|
|
552
552
|
validate: o,
|
|
553
|
-
VvForm:
|
|
553
|
+
VvForm: w
|
|
554
554
|
};
|
|
555
555
|
}
|
|
556
|
-
function
|
|
556
|
+
function we(e, l) {
|
|
557
557
|
return M({
|
|
558
558
|
name: "VvFormWrapper",
|
|
559
559
|
props: {
|
|
@@ -582,7 +582,7 @@ function Oe(e, l) {
|
|
|
582
582
|
],
|
|
583
583
|
slots: Object,
|
|
584
584
|
setup(r, { emit: f }) {
|
|
585
|
-
const
|
|
585
|
+
const a = C(e), n = C(l, void 0), i = R(/* @__PURE__ */ new Set()), u = R(/* @__PURE__ */ new Map()), { name: t } = j(r);
|
|
586
586
|
P(l, {
|
|
587
587
|
name: U(t),
|
|
588
588
|
errors: u,
|
|
@@ -590,45 +590,45 @@ function Oe(e, l) {
|
|
|
590
590
|
}), _(
|
|
591
591
|
i,
|
|
592
592
|
(v) => {
|
|
593
|
-
|
|
594
|
-
|
|
593
|
+
n != null && n.fields && v.forEach((m) => {
|
|
594
|
+
n == null || n.fields.value.add(m);
|
|
595
595
|
});
|
|
596
596
|
},
|
|
597
597
|
{ deep: !0 }
|
|
598
598
|
), _(
|
|
599
599
|
() => new Map(u.value),
|
|
600
600
|
(v, m) => {
|
|
601
|
-
|
|
602
|
-
|
|
601
|
+
n != null && n.errors && (Array.from(m.keys()).forEach((c) => {
|
|
602
|
+
n.errors.value.delete(c);
|
|
603
603
|
}), Array.from(v.keys()).forEach((c) => {
|
|
604
604
|
const h = v.get(c);
|
|
605
|
-
h &&
|
|
605
|
+
h && n.errors.value.set(c, h);
|
|
606
606
|
}));
|
|
607
607
|
},
|
|
608
608
|
{ deep: !0 }
|
|
609
609
|
);
|
|
610
|
-
const g = W(() =>
|
|
610
|
+
const g = W(() => a != null && a.invalid.value ? u.value.size > 0 : !1);
|
|
611
611
|
_(g, () => {
|
|
612
612
|
g.value ? f("invalid") : f("valid");
|
|
613
613
|
});
|
|
614
|
-
const o = () => (
|
|
614
|
+
const o = () => (a == null ? void 0 : a.validate(void 0, i.value)) ?? Promise.resolve(!0);
|
|
615
615
|
return {
|
|
616
|
-
clear:
|
|
617
|
-
errors:
|
|
616
|
+
clear: a == null ? void 0 : a.clear,
|
|
617
|
+
errors: a == null ? void 0 : a.errors,
|
|
618
618
|
fields: i,
|
|
619
619
|
fieldsErrors: u,
|
|
620
|
-
formData:
|
|
620
|
+
formData: a == null ? void 0 : a.formData,
|
|
621
621
|
invalid: g,
|
|
622
|
-
reset:
|
|
623
|
-
submit:
|
|
624
|
-
validate:
|
|
622
|
+
reset: a == null ? void 0 : a.reset,
|
|
623
|
+
submit: a == null ? void 0 : a.submit,
|
|
624
|
+
validate: a == null ? void 0 : a.validate,
|
|
625
625
|
validateWrapper: o
|
|
626
626
|
};
|
|
627
627
|
},
|
|
628
628
|
render() {
|
|
629
629
|
const r = () => {
|
|
630
|
-
var f,
|
|
631
|
-
return (
|
|
630
|
+
var f, a;
|
|
631
|
+
return (a = (f = this.$slots).default) == null ? void 0 : a.call(f, {
|
|
632
632
|
clear: this.clear,
|
|
633
633
|
errors: this.errors,
|
|
634
634
|
fieldsErrors: this.fieldsErrors,
|
|
@@ -660,24 +660,24 @@ function pe(e, l) {
|
|
|
660
660
|
}
|
|
661
661
|
},
|
|
662
662
|
slots: Object,
|
|
663
|
-
setup(f, { slots:
|
|
664
|
-
const
|
|
665
|
-
if (
|
|
663
|
+
setup(f, { slots: a }) {
|
|
664
|
+
const n = C(e);
|
|
665
|
+
if (n != null && n.formData)
|
|
666
666
|
return () => {
|
|
667
667
|
var g;
|
|
668
668
|
const i = typeof f.schema == "function" ? f.schema(
|
|
669
|
-
|
|
669
|
+
n,
|
|
670
670
|
f.scope
|
|
671
671
|
) : f.schema;
|
|
672
672
|
let u;
|
|
673
673
|
const t = i.reduce((o, v) => {
|
|
674
|
-
const m = typeof v == "function" ? v(
|
|
674
|
+
const m = typeof v == "function" ? v(n, f.scope) : v, {
|
|
675
675
|
vvIs: c,
|
|
676
676
|
vvName: h,
|
|
677
677
|
vvSlots: S,
|
|
678
678
|
vvChildren: I,
|
|
679
679
|
vvIf: O,
|
|
680
|
-
vvElseIf:
|
|
680
|
+
vvElseIf: w,
|
|
681
681
|
vvType: b,
|
|
682
682
|
vvDefaultValue: V,
|
|
683
683
|
vvShowValid: y,
|
|
@@ -686,22 +686,22 @@ function pe(e, l) {
|
|
|
686
686
|
} = m;
|
|
687
687
|
if (O !== void 0) {
|
|
688
688
|
if (typeof O == "string" ? u = !!z(
|
|
689
|
-
new Object(
|
|
689
|
+
new Object(n.formData.value),
|
|
690
690
|
O
|
|
691
|
-
) : typeof O == "function" ? u = G(O(
|
|
691
|
+
) : typeof O == "function" ? u = G(O(n)) : u = G(O), !u)
|
|
692
692
|
return o;
|
|
693
|
-
} else if (
|
|
694
|
-
if (u || (typeof
|
|
695
|
-
new Object(
|
|
696
|
-
|
|
697
|
-
) : typeof
|
|
693
|
+
} else if (w !== void 0 && u !== void 0) {
|
|
694
|
+
if (u || (typeof w == "string" ? u = !!z(
|
|
695
|
+
new Object(n.formData.value),
|
|
696
|
+
w
|
|
697
|
+
) : typeof w == "function" ? u = G(w(n)) : u = G(w), !u))
|
|
698
698
|
return o;
|
|
699
699
|
} else
|
|
700
700
|
u = void 0;
|
|
701
|
-
let
|
|
702
|
-
return I && (typeof c == "string" ?
|
|
701
|
+
let p;
|
|
702
|
+
return I && (typeof c == "string" ? p = A(r, {
|
|
703
703
|
schema: I
|
|
704
|
-
}) :
|
|
704
|
+
}) : p = {
|
|
705
705
|
default: ($) => A(r, {
|
|
706
706
|
schema: I,
|
|
707
707
|
scope: $
|
|
@@ -717,26 +717,26 @@ function pe(e, l) {
|
|
|
717
717
|
showValid: y,
|
|
718
718
|
props: E
|
|
719
719
|
},
|
|
720
|
-
S ??
|
|
720
|
+
S ?? p ?? s
|
|
721
721
|
)
|
|
722
722
|
), o) : c ? (o.push(
|
|
723
723
|
A(
|
|
724
724
|
c,
|
|
725
725
|
E,
|
|
726
|
-
S ??
|
|
726
|
+
S ?? p ?? s
|
|
727
727
|
)
|
|
728
|
-
), o) : (
|
|
728
|
+
), o) : (p && ("default" in p ? o.push(p.default(f.scope)) : o.push(p)), o);
|
|
729
729
|
}, []);
|
|
730
730
|
return t.push(
|
|
731
|
-
(g =
|
|
732
|
-
errors:
|
|
733
|
-
formData:
|
|
734
|
-
invalid:
|
|
735
|
-
status:
|
|
736
|
-
submit:
|
|
737
|
-
validate:
|
|
738
|
-
clear:
|
|
739
|
-
reset:
|
|
731
|
+
(g = a == null ? void 0 : a.default) == null ? void 0 : g.call(a, {
|
|
732
|
+
errors: n == null ? void 0 : n.errors.value,
|
|
733
|
+
formData: n == null ? void 0 : n.formData.value,
|
|
734
|
+
invalid: n == null ? void 0 : n.invalid.value,
|
|
735
|
+
status: n == null ? void 0 : n.status.value,
|
|
736
|
+
submit: n == null ? void 0 : n.submit,
|
|
737
|
+
validate: n == null ? void 0 : n.validate,
|
|
738
|
+
clear: n == null ? void 0 : n.clear,
|
|
739
|
+
reset: n == null ? void 0 : n.reset
|
|
740
740
|
})
|
|
741
741
|
), t;
|
|
742
742
|
};
|
|
@@ -745,13 +745,13 @@ function pe(e, l) {
|
|
|
745
745
|
return r;
|
|
746
746
|
}
|
|
747
747
|
function J(e, l = {}) {
|
|
748
|
-
const r = Symbol("formInjectionKey"), f = Symbol("formWrapperInjectionKey"),
|
|
748
|
+
const r = Symbol("formInjectionKey"), f = Symbol("formWrapperInjectionKey"), a = Symbol("formFieldInjectionKey"), n = we(
|
|
749
749
|
r,
|
|
750
750
|
f
|
|
751
751
|
), i = xe(
|
|
752
752
|
r,
|
|
753
753
|
f,
|
|
754
|
-
|
|
754
|
+
a,
|
|
755
755
|
l
|
|
756
756
|
), u = pe(r, i), {
|
|
757
757
|
clear: t,
|
|
@@ -764,14 +764,14 @@ function J(e, l = {}) {
|
|
|
764
764
|
status: S,
|
|
765
765
|
stopUpdatesWatch: I,
|
|
766
766
|
submit: O,
|
|
767
|
-
validate:
|
|
767
|
+
validate: w,
|
|
768
768
|
VvForm: b
|
|
769
|
-
} =
|
|
769
|
+
} = Oe(e, r, l, u);
|
|
770
770
|
return {
|
|
771
771
|
clear: t,
|
|
772
772
|
errors: g,
|
|
773
773
|
formData: o,
|
|
774
|
-
formFieldInjectionKey:
|
|
774
|
+
formFieldInjectionKey: a,
|
|
775
775
|
formInjectionKey: r,
|
|
776
776
|
formWrapperInjectionKey: f,
|
|
777
777
|
ignoreUpdates: v,
|
|
@@ -781,11 +781,11 @@ function J(e, l = {}) {
|
|
|
781
781
|
status: S,
|
|
782
782
|
stopUpdatesWatch: I,
|
|
783
783
|
submit: O,
|
|
784
|
-
validate:
|
|
784
|
+
validate: w,
|
|
785
785
|
VvForm: b,
|
|
786
786
|
VvFormField: i,
|
|
787
787
|
VvFormTemplate: u,
|
|
788
|
-
VvFormWrapper:
|
|
788
|
+
VvFormWrapper: n
|
|
789
789
|
};
|
|
790
790
|
}
|
|
791
791
|
const ne = Symbol("pluginInjectionKey");
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(k,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):(k=typeof globalThis<"u"?globalThis:k||self,r(k["@volverjs/form-vue"]={},k.Vue,k.VueUseCore,k.zod))})(this,function(k,r,K,S){"use strict";function U(e){return Array.isArray(e)}function H(e){return typeof e<"u"}function L(e){return e===null}function $(e){return typeof e=="object"}function M(e){return typeof e=="string"}function Z(e){return typeof e>"u"}const Q=/^[0-9]+$/,X=["__proto__","prototype","constructor"];function B(e,i,t){const o=H(t)?t:void 0;if(!$(e)||!M(i))return o;const l=J(i);if(l.length!==0){for(const n of l){if(n==="*")continue;const f=function(u){return u.map(a=>Z(a)||L(a)?a:U(a)?f(a):a[n])};if(U(e)&&!Q.test(n)?e=f(e):e=e[n],Z(e)||L(e))break}return Z(e)?o:e}}function q(e,i,t){if(!$(e)||!M(i))return;const o=J(i);if(o.length===0)return;const l=o.length;for(let n=0;n<l;n++){const f=o[n];if(n===l-1){e[f]=t;return}if(f==="*"&&U(e)){const u=o.slice(n+1).join(".");for(const a of e)q(a,u,t);return}Z(e[f])&&(e[f]={}),e=e[f]}}function J(e){const i=e.split(/[.]|(?:\[(\d|\*)\])/).filter(t=>!!t);return i.some(t=>X.indexOf(t)!==-1)?[]:i}var c=(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))(c||{}),p=(e=>(e.invalid="invalid",e.valid="valid",e.submitting="submitting",e.reset="reset",e.updated="updated",e.unknown="unknown",e))(p||{});function Y(e,i,t,o){return r.defineComponent({name:"VvFormField",props:{type:{type:String,validator:l=>Object.values(c).includes(l),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","update:formData","update:modelValue","valid"],expose:["component","errors","hasProps","invalid","invalidLabel","is","type"],slots:Object,setup(l,{slots:n,emit:f}){const u=r.inject(i,void 0);u&&u.fields.value.add(l.name);const a=r.inject(e),{props:w,name:d}=r.toRefs(l),v=r.computed({get(){if(a!=null&&a.formData)return B(new Object(a.formData.value),String(l.name))},set(s){a!=null&&a.formData&&(q(new Object(a.formData.value),String(l.name),s),f("update:modelValue",{newValue:v.value,formData:a==null?void 0:a.formData}))}});r.onMounted(()=>{v.value===void 0&&l.defaultValue!==void 0&&(v.value=l.defaultValue)});const h=r.computed(()=>{if(a!=null&&a.errors.value)return B(a.errors.value,String(l.name))}),m=r.computed(()=>{var s;return(s=h.value)==null?void 0:s._errors}),b=r.computed(()=>h.value!==void 0),R=r.watch(b,()=>{b.value?(f("invalid",m.value),u&&u.errors.value.set(l.name,{_errors:m.value})):(f("valid",v.value),u&&u.errors.value.delete(l.name))}),E=r.watch(()=>a==null?void 0:a.formData,()=>{f("update:formData",a==null?void 0:a.formData)},{deep:!0});r.onBeforeUnmount(()=>{R(),E()});const x=s=>{v.value=s},C=r.computed(()=>{let s=w.value;return typeof s=="function"&&(s=s(a==null?void 0:a.formData)),Object.keys(s).reduce((W,I)=>(W[I]=r.unref(s[I]),W),{})}),V=r.computed(()=>a!=null&&a.readonly.value?!0:C.value.readonly??l.readonly),g=r.computed(()=>({...C.value,name:C.value.name??l.name,invalid:b.value,valid:l.showValid?!!(!b.value&&v.value):void 0,type:(s=>{if([c.color,c.date,c.datetimeLocal,c.email,c.month,c.number,c.password,c.search,c.tel,c.text,c.time,c.url,c.week].includes(s))return s})(l.type),invalidLabel:m.value,modelValue:v.value,readonly:V.value,"onUpdate:modelValue":x}));return r.provide(t,{name:r.readonly(d),errors:r.readonly(h)}),{component:r.computed(()=>{if(l.type===c.custom)return{render(){var s;return((s=n.default)==null?void 0:s.call(n,{errors:h.value,formData:a==null?void 0:a.formData.value,formErrors:a==null?void 0:a.errors.value,invalid:b.value,invalidLabel:m.value,modelValue:v.value,onUpdate:x,readonly:V.value,submit:a==null?void 0:a.submit,validate:a==null?void 0:a.validate}))??n.default}};if(!((o==null?void 0:o.lazyLoad)??l.lazyLoad)){let s;switch(l.type){case c.select:s=r.resolveComponent("VvSelect");break;case c.checkbox:s=r.resolveComponent("VvCheckbox");break;case c.radio:s=r.resolveComponent("VvRadio");break;case c.textarea:s=r.resolveComponent("VvTextarea");break;case c.radioGroup:s=r.resolveComponent("VvRadioGroup");break;case c.checkboxGroup:s=r.resolveComponent("VvCheckboxGroup");break;case c.combobox:s=r.resolveComponent("VvCombobox");break;default:s=r.resolveComponent("VvInputText")}if(typeof s!="string")return s;console.warn(`[form-vue warn]: ${s} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`)}return r.defineAsyncComponent(async()=>{switch(o!=null&&o.sideEffects&&await Promise.resolve(o.sideEffects(l.type)),l.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:g,invalid:b}},render(){return this.is?r.h(this.is,this.hasProps,this.$slots):this.type===c.custom?r.h(this.component,null,this.$slots):r.h(this.component,this.hasProps,this.$slots)}})}function A(e,i={}){const t=f=>{let u=f;for(;u instanceof S.ZodEffects;)u=u.innerType();return u instanceof S.ZodOptional&&(u=u._def.innerType),u},o=f=>{let u=f;for(;u instanceof S.ZodEffects;)u=u.innerType();return u instanceof S.ZodOptional},l=t(e);return{...(l instanceof S.ZodObject?l._def.unknownKeys==="passthrough":!1)?i:{},...Object.fromEntries(Object.entries(l.shape).map(([f,u])=>{const a=i[f],w=o(u);let d=t(u),v;if(d instanceof S.ZodDefault&&(v=d._def.defaultValue(),d=d._def.innerType),a===null&&d instanceof S.ZodNullable)return[f,a];if(a==null&&w)return[f,v];if(d instanceof S.ZodSchema){const h=u.safeParse(a);if(h.success)return[f,h.data??v]}if(d instanceof S.ZodArray&&Array.isArray(a)&&a.length){const h=t(d._def.type);if(h instanceof S.ZodObject)return[f,a.map(m=>A(h,m&&typeof m=="object"?m:void 0))]}if(d instanceof S.ZodRecord&&a){const h=t(d._def.valueType);if(h instanceof S.ZodObject)return[f,Object.keys(a).reduce((m,b)=>(m[b]=A(h,a[b]),m),{})]}return d instanceof S.ZodObject?[f,A(d,a&&typeof a=="object"?a:v)]:[f,v]}))}}function z(e,i,t,o){const l=r.ref(),n=r.ref(),f=r.computed(()=>n.value===p.invalid),u=r.ref(),a=r.ref(!1);let w;const d=async(V=u.value,g)=>{if(w=g,a.value)return!0;const y=await e.safeParseAsync(V);if(!y.success){if(!g)return l.value=y.error.format(),n.value=p.invalid,!1;const s=y.error.issues.filter(W=>g.has(W.path.join(".")));return s.length?(l.value=new S.ZodError(s).format(),n.value=p.invalid,!1):(l.value=void 0,n.value=p.unknown,u.value=y.data,!0)}return l.value=void 0,n.value=p.valid,u.value=y.data,!0},v=()=>{l.value=void 0,n.value=void 0,w=void 0},h=()=>{u.value=A(e),v(),n.value=p.reset},m=async()=>a.value||!await d()?!1:(n.value=p.submitting,!0),{ignoreUpdates:b,stop:R}=K.watchIgnorable(u,()=>{n.value=p.updated},{deep:!0,eventFilter:K.throttleFilter((t==null?void 0:t.updateThrottle)??500)}),E=r.readonly(l),x=r.readonly(n),C=r.defineComponent({name:"VvForm",props:{continuousValidation:{type:Boolean,default:!1},modelValue:{type:Object,default:()=>({})},readonly:{type:Boolean,default:(t==null?void 0:t.readonly)??!1},tag:{type:String,default:"form"},template:{type:[Array,Function],default:void 0}},emits:["invalid","submit","update:modelValue","update:readonly","valid","reset"],expose:["errors","invalid","readonly","status","submit","tag","template","valid","validate","clear","reset"],slots:Object,setup(V,{emit:g}){return u.value=A(e,r.toRaw(V.modelValue)),r.watch(()=>V.modelValue,y=>{if(y){const s=r.isProxy(y)?r.toRaw(y):y;if(JSON.stringify(s)===JSON.stringify(r.toRaw(u.value)))return;u.value=typeof(s==null?void 0:s.clone)=="function"?s.clone():JSON.parse(JSON.stringify(s))}},{deep:!0}),r.watch(n,async y=>{var s,W,I,N,T,P;if(y===p.invalid){const O=r.toRaw(l.value);g("invalid",O),(s=t==null?void 0:t.onInvalid)==null||s.call(t,O);return}if(y===p.valid){const O=r.toRaw(u.value);g("valid",O),(W=t==null?void 0:t.onValid)==null||W.call(t,O),g("update:modelValue",O),(I=t==null?void 0:t.onUpdate)==null||I.call(t,O);return}if(y===p.submitting){const O=r.toRaw(u.value);g("submit",O),(N=t==null?void 0:t.onSubmit)==null||N.call(t,O);return}if(y===p.reset){const O=r.toRaw(u.value);g("reset",O),(T=t==null?void 0:t.onReset)==null||T.call(t,O);return}if(y===p.updated){if((l.value||t!=null&&t.continuousValidation||V.continuousValidation)&&await d(void 0,w),!u.value||!V.modelValue||JSON.stringify(u.value)!==JSON.stringify(V.modelValue)){const O=r.toRaw(u.value);g("update:modelValue",O),(P=t==null?void 0:t.onUpdate)==null||P.call(t,O)}n.value===p.updated&&(n.value=p.unknown)}}),r.onMounted(()=>{a.value=V.readonly}),r.watch(()=>V.readonly,y=>{a.value=y}),r.watch(a,y=>{y!==V.readonly&&g("update:readonly",a.value)}),r.provide(i,{clear:v,errors:E,formData:u,ignoreUpdates:b,invalid:f,readonly:a,reset:h,status:x,stopUpdatesWatch:R,submit:m,validate:d}),{clear:v,errors:E,formData:u,ignoreUpdates:b,invalid:f,isReadonly:a,reset:h,status:x,stopUpdatesWatch:R,submit:m,validate:d}},render(){const V=()=>{var g,y;return((y=(g=this.$slots)==null?void 0:g.default)==null?void 0:y.call(g,{clear:v,errors:E,formData:u,ignoreUpdates:b,invalid:f,readonly:a,reset:h,status:x,stopUpdatesWatch:R,submit:m,validate:d}))??this.$slots.default};return r.h(this.tag,{onSubmit:r.withModifiers(this.submit,["prevent"]),onReset:r.withModifiers(this.reset,["prevent"])},(this.template??(t==null?void 0:t.template))&&o?[r.h(o,{schema:this.template??(t==null?void 0:t.template)},{default:V})]:{default:V})}});return{clear:v,errors:l,formData:u,ignoreUpdates:b,invalid:f,readonly:a,reset:h,status:n,stopUpdatesWatch:R,submit:m,validate:d,VvForm:C}}function j(e,i){return r.defineComponent({name:"VvFormWrapper",props:{name:{type:String,required:!0},tag:{type:String,default:void 0}},emits:["invalid","valid"],expose:["clear","errors","fields","fieldsErrors","formData","invalid","reset","submit","tag","validate","validateWrapper"],slots:Object,setup(t,{emit:o}){const l=r.inject(e),n=r.inject(i,void 0),f=r.ref(new Set),u=r.ref(new Map),{name:a}=r.toRefs(t);r.provide(i,{name:r.readonly(a),errors:u,fields:f}),r.watch(f,v=>{n!=null&&n.fields&&v.forEach(h=>{n==null||n.fields.value.add(h)})},{deep:!0}),r.watch(()=>new Map(u.value),(v,h)=>{n!=null&&n.errors&&(Array.from(h.keys()).forEach(m=>{n.errors.value.delete(m)}),Array.from(v.keys()).forEach(m=>{const b=v.get(m);b&&n.errors.value.set(m,b)}))},{deep:!0});const w=r.computed(()=>l!=null&&l.invalid.value?u.value.size>0:!1);r.watch(w,()=>{w.value?o("invalid"):o("valid")});const d=()=>(l==null?void 0:l.validate(void 0,f.value))??Promise.resolve(!0);return{clear:l==null?void 0:l.clear,errors:l==null?void 0:l.errors,fields:f,fieldsErrors:u,formData:l==null?void 0:l.formData,invalid:w,reset:l==null?void 0:l.reset,submit:l==null?void 0:l.submit,validate:l==null?void 0:l.validate,validateWrapper:d}},render(){const t=()=>{var o,l;return(l=(o=this.$slots).default)==null?void 0:l.call(o,{clear:this.clear,errors:this.errors,fieldsErrors:this.fieldsErrors,formData:this.formData,invalid:this.invalid,reset:this.reset,submit:this.submit,validate:this.validate,validateWrapper:this.validateWrapper})};return this.tag?r.h(this.tag,null,{default:t}):t()}})}function D(e,i){const t=r.defineComponent({name:"VvFormTemplate",props:{schema:{type:[Array,Function],required:!0},scope:{type:Object,default:()=>({})}},slots:Object,setup(o,{slots:l}){const n=r.inject(e);if(n!=null&&n.formData)return()=>{var w;const f=typeof o.schema=="function"?o.schema(n,o.scope):o.schema;let u;const a=f.reduce((d,v)=>{const h=typeof v=="function"?v(n,o.scope):v,{vvIs:m,vvName:b,vvSlots:R,vvChildren:E,vvIf:x,vvElseIf:C,vvType:V,vvDefaultValue:g,vvShowValid:y,vvContent:s,...W}=h;if(x!==void 0){if(typeof x=="string"?u=!!B(new Object(n.formData.value),x):typeof x=="function"?u=r.unref(x(n)):u=r.unref(x),!u)return d}else if(C!==void 0&&u!==void 0){if(u||(typeof C=="string"?u=!!B(new Object(n.formData.value),C):typeof C=="function"?u=r.unref(C(n)):u=r.unref(C),!u))return d}else u=void 0;let I;return E&&(typeof m=="string"?I=r.h(t,{schema:E}):I={default:N=>r.h(t,{schema:E,scope:N})}),b?(d.push(r.h(i,{name:b,is:m,type:V,defaultValue:g,showValid:y,props:W},R??I??s)),d):m?(d.push(r.h(m,W,R??I??s)),d):(I&&("default"in I?d.push(I.default(o.scope)):d.push(I)),d)},[]);return a.push((w=l==null?void 0:l.default)==null?void 0:w.call(l,{errors:n==null?void 0:n.errors.value,formData:n==null?void 0:n.formData.value,invalid:n==null?void 0:n.invalid.value,status:n==null?void 0:n.status.value,submit:n==null?void 0:n.submit,validate:n==null?void 0:n.validate,clear:n==null?void 0:n.clear,reset:n==null?void 0:n.reset})),a}}});return t}function _(e,i={}){const t=Symbol("formInjectionKey"),o=Symbol("formWrapperInjectionKey"),l=Symbol("formFieldInjectionKey"),n=j(t,o),f=Y(t,o,l,i),u=D(t,f),{clear:a,errors:w,formData:d,ignoreUpdates:v,invalid:h,readonly:m,reset:b,status:R,stopUpdatesWatch:E,submit:x,validate:C,VvForm:V}=z(e,t,i,u);return{clear:a,errors:w,formData:d,formFieldInjectionKey:l,formInjectionKey:t,formWrapperInjectionKey:o,ignoreUpdates:v,invalid:h,readonly:m,reset:b,status:R,stopUpdatesWatch:E,submit:x,validate:C,VvForm:V,VvFormField:f,VvFormTemplate:u,VvFormWrapper:n}}const G=Symbol("pluginInjectionKey");function F(e){let i={};return e.schema&&(i=_(e.schema,e)),{...i,install(t,{global:o=!1}={}){t.provide(G,e),o&&(t.config.globalProperties.$vvForm=e,i!=null&&i.VvForm&&t.component("VvForm",i.VvForm),i!=null&&i.VvFormWrapper&&t.component("VvFormWrapper",i.VvFormWrapper),i!=null&&i.VvFormField&&t.component("VvFormField",i.VvFormField),i!=null&&i.VvFormTemplate&&t.component("VvFormTemplate",i.VvFormTemplate))}}}function ee(e,i={}){return r.getCurrentInstance()?_(e,{...r.inject(G,{}),...i}):_(e,i)}function re(e,i={}){return _(e,i)}k.FormFieldType=c,k.createForm=F,k.defaultObjectBySchema=A,k.formFactory=re,k.pluginInjectionKey=G,k.useForm=ee,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(x,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):(x=typeof globalThis<"u"?globalThis:x||self,r(x["@volverjs/form-vue"]={},x.Vue,x.VueUseCore,x.zod))})(this,function(x,r,K,k){"use strict";function U(e){return Array.isArray(e)}function H(e){return typeof e<"u"}function L(e){return e===null}function $(e){return typeof e=="object"}function M(e){return typeof e=="string"}function Z(e){return typeof e>"u"}const Q=/^[0-9]+$/,X=["__proto__","prototype","constructor"];function B(e,s,t){const o=H(t)?t:void 0;if(!$(e)||!M(s))return o;const n=J(s);if(n.length!==0){for(const l of n){if(l==="*")continue;const f=function(u){return u.map(a=>Z(a)||L(a)?a:U(a)?f(a):a[l])};if(U(e)&&!Q.test(l)?e=f(e):e=e[l],Z(e)||L(e))break}return Z(e)?o:e}}function q(e,s,t){if(!$(e)||!M(s))return;const o=J(s);if(o.length===0)return;const n=o.length;for(let l=0;l<n;l++){const f=o[l];if(l===n-1){e[f]=t;return}if(f==="*"&&U(e)){const u=o.slice(l+1).join(".");for(const a of e)q(a,u,t);return}Z(e[f])&&(e[f]={}),e=e[f]}}function J(e){const s=e.split(/[.]|(?:\[(\d|\*)\])/).filter(t=>!!t);return s.some(t=>X.indexOf(t)!==-1)?[]:s}var c=(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))(c||{}),S=(e=>(e.invalid="invalid",e.valid="valid",e.submitting="submitting",e.reset="reset",e.updated="updated",e.unknown="unknown",e))(S||{});function Y(e,s,t,o){return r.defineComponent({name:"VvFormField",props:{type:{type:String,validator:n=>Object.values(c).includes(n),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","update:formData","update:modelValue","valid"],expose:["component","errors","hasProps","invalid","invalidLabel","is","type"],slots:Object,setup(n,{slots:l,emit:f}){const u=r.inject(s,void 0);u&&u.fields.value.add(n.name);const a=r.inject(e),{props:p,name:d}=r.toRefs(n),v=r.computed({get(){if(a!=null&&a.formData)return B(new Object(a.formData.value),String(n.name))},set(i){a!=null&&a.formData&&(q(new Object(a.formData.value),String(n.name),i),f("update:modelValue",{newValue:v.value,formData:a==null?void 0:a.formData}))}});r.onMounted(()=>{v.value===void 0&&n.defaultValue!==void 0&&(v.value=n.defaultValue)});const h=r.computed(()=>{if(a!=null&&a.errors.value)return B(a.errors.value,String(n.name))}),m=r.computed(()=>{var i;return(i=h.value)==null?void 0:i._errors}),b=r.computed(()=>h.value!==void 0),R=r.watch(b,()=>{b.value?(f("invalid",m.value),u&&u.errors.value.set(n.name,{_errors:m.value})):(f("valid",v.value),u&&u.errors.value.delete(n.name))}),E=r.watch(()=>a==null?void 0:a.formData,()=>{f("update:formData",a==null?void 0:a.formData)},{deep:!0});r.onBeforeUnmount(()=>{R(),E()});const O=i=>{v.value=i},C=r.computed(()=>{let i=p.value;return typeof i=="function"&&(i=i(a==null?void 0:a.formData)),Object.keys(i).reduce((W,I)=>(W[I]=r.unref(i[I]),W),{})}),V=r.computed(()=>a!=null&&a.readonly.value?!0:C.value.readonly??n.readonly),g=r.computed(()=>({...C.value,name:C.value.name??n.name,invalid:b.value,valid:n.showValid?!!(!b.value&&v.value):void 0,type:(i=>{if([c.color,c.date,c.datetimeLocal,c.email,c.month,c.number,c.password,c.search,c.tel,c.text,c.time,c.url,c.week].includes(i))return i})(n.type),invalidLabel:m.value,modelValue:v.value,readonly:V.value,"onUpdate:modelValue":O}));return r.provide(t,{name:r.readonly(d),errors:r.readonly(h)}),{component:r.computed(()=>{if(n.type===c.custom)return{render(){var i;return((i=l.default)==null?void 0:i.call(l,{errors:h.value,formData:a==null?void 0:a.formData.value,formErrors:a==null?void 0:a.errors.value,invalid:b.value,invalidLabel:m.value,modelValue:v.value,onUpdate:O,readonly:V.value,submit:a==null?void 0:a.submit,validate:a==null?void 0:a.validate}))??l.default}};if(!((o==null?void 0:o.lazyLoad)??n.lazyLoad)){let i;switch(n.type){case c.select:i=r.resolveComponent("VvSelect");break;case c.checkbox:i=r.resolveComponent("VvCheckbox");break;case c.radio:i=r.resolveComponent("VvRadio");break;case c.textarea:i=r.resolveComponent("VvTextarea");break;case c.radioGroup:i=r.resolveComponent("VvRadioGroup");break;case c.checkboxGroup:i=r.resolveComponent("VvCheckboxGroup");break;case c.combobox:i=r.resolveComponent("VvCombobox");break;default:i=r.resolveComponent("VvInputText")}if(typeof i!="string")return i;console.warn(`[form-vue warn]: ${i} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`)}return r.defineAsyncComponent(async()=>{switch(o!=null&&o.sideEffects&&await Promise.resolve(o.sideEffects(n.type)),n.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:g,invalid:b}},render(){return this.is?r.h(this.is,this.hasProps,this.$slots):this.type===c.custom?r.h(this.component,null,this.$slots):r.h(this.component,this.hasProps,this.$slots)}})}function A(e,s={}){const t=f=>{let u=f;for(;u instanceof k.ZodEffects;)u=u.innerType();return u instanceof k.ZodOptional&&(u=u._def.innerType),u},o=f=>{let u=f;for(;u instanceof k.ZodEffects;)u=u.innerType();return u instanceof k.ZodOptional},n=t(e);return{...(n instanceof k.ZodObject?n._def.unknownKeys==="passthrough":!1)?s:{},...Object.fromEntries(Object.entries(n.shape).map(([f,u])=>{const a=s[f],p=o(u);let d=t(u),v;if(d instanceof k.ZodDefault&&(v=d._def.defaultValue(),d=d._def.innerType),a===null&&d instanceof k.ZodNullable)return[f,a];if(a==null&&p)return[f,v];if(d instanceof k.ZodSchema){const h=u.safeParse(a);if(h.success)return[f,h.data??v]}if(d instanceof k.ZodArray&&Array.isArray(a)&&a.length){const h=t(d._def.type);if(h instanceof k.ZodObject)return[f,a.map(m=>A(h,m&&typeof m=="object"?m:void 0))]}if(d instanceof k.ZodRecord&&a){const h=t(d._def.valueType);if(h instanceof k.ZodObject)return[f,Object.keys(a).reduce((m,b)=>(m[b]=A(h,a[b]),m),{})]}return d instanceof k.ZodObject?[f,A(d,a&&typeof a=="object"?a:v)]:[f,v]}))}}function z(e,s,t,o){const n=r.ref(),l=r.ref(),f=r.computed(()=>l.value===S.invalid),u=r.ref(),a=r.ref(!1);let p;const d=async(V=u.value,g)=>{if(p=g,a.value)return!0;const y=await e.safeParseAsync(V);if(!y.success){if(l.value=S.invalid,!g)return n.value=y.error.format(),!1;const i=y.error.issues.filter(W=>g.has(W.path.join(".")));return i.length?(n.value=new k.ZodError(i).format(),!1):(n.value=void 0,!0)}return n.value=void 0,l.value=S.valid,u.value=y.data,!0},v=()=>{n.value=void 0,l.value=void 0,p=void 0},h=()=>{u.value=A(e),v(),l.value=S.reset},m=async()=>a.value||!await d()?!1:(l.value=S.submitting,!0),{ignoreUpdates:b,stop:R}=K.watchIgnorable(u,()=>{l.value=S.updated},{deep:!0,eventFilter:K.throttleFilter((t==null?void 0:t.updateThrottle)??500)}),E=r.readonly(n),O=r.readonly(l),C=r.defineComponent({name:"VvForm",props:{continuousValidation:{type:Boolean,default:!1},modelValue:{type:Object,default:()=>({})},readonly:{type:Boolean,default:(t==null?void 0:t.readonly)??!1},tag:{type:String,default:"form"},template:{type:[Array,Function],default:void 0}},emits:["invalid","submit","update:modelValue","update:readonly","valid","reset"],expose:["errors","invalid","readonly","status","submit","tag","template","valid","validate","clear","reset"],slots:Object,setup(V,{emit:g}){return u.value=A(e,r.toRaw(V.modelValue)),r.watch(()=>V.modelValue,y=>{if(y){const i=r.isProxy(y)?r.toRaw(y):y;if(JSON.stringify(i)===JSON.stringify(r.toRaw(u.value)))return;u.value=typeof(i==null?void 0:i.clone)=="function"?i.clone():JSON.parse(JSON.stringify(i))}},{deep:!0}),r.watch(l,async y=>{var i,W,I,N,T,P;if(y===S.invalid){const w=r.toRaw(n.value);g("invalid",w),(i=t==null?void 0:t.onInvalid)==null||i.call(t,w);return}if(y===S.valid){const w=r.toRaw(u.value);g("valid",w),(W=t==null?void 0:t.onValid)==null||W.call(t,w),g("update:modelValue",w),(I=t==null?void 0:t.onUpdate)==null||I.call(t,w);return}if(y===S.submitting){const w=r.toRaw(u.value);g("submit",w),(N=t==null?void 0:t.onSubmit)==null||N.call(t,w);return}if(y===S.reset){const w=r.toRaw(u.value);g("reset",w),(T=t==null?void 0:t.onReset)==null||T.call(t,w);return}if(y===S.updated){if((n.value||t!=null&&t.continuousValidation||V.continuousValidation)&&await d(void 0,p),!u.value||!V.modelValue||JSON.stringify(u.value)!==JSON.stringify(V.modelValue)){const w=r.toRaw(u.value);g("update:modelValue",w),(P=t==null?void 0:t.onUpdate)==null||P.call(t,w)}l.value===S.updated&&(l.value=S.unknown)}}),r.onMounted(()=>{a.value=V.readonly}),r.watch(()=>V.readonly,y=>{a.value=y}),r.watch(a,y=>{y!==V.readonly&&g("update:readonly",a.value)}),r.provide(s,{clear:v,errors:E,formData:u,ignoreUpdates:b,invalid:f,readonly:a,reset:h,status:O,stopUpdatesWatch:R,submit:m,validate:d}),{clear:v,errors:E,formData:u,ignoreUpdates:b,invalid:f,isReadonly:a,reset:h,status:O,stopUpdatesWatch:R,submit:m,validate:d}},render(){const V=()=>{var g,y;return((y=(g=this.$slots)==null?void 0:g.default)==null?void 0:y.call(g,{clear:v,errors:E,formData:u,ignoreUpdates:b,invalid:f,readonly:a,reset:h,status:O,stopUpdatesWatch:R,submit:m,validate:d}))??this.$slots.default};return r.h(this.tag,{onSubmit:r.withModifiers(this.submit,["prevent"]),onReset:r.withModifiers(this.reset,["prevent"])},(this.template??(t==null?void 0:t.template))&&o?[r.h(o,{schema:this.template??(t==null?void 0:t.template)},{default:V})]:{default:V})}});return{clear:v,errors:n,formData:u,ignoreUpdates:b,invalid:f,readonly:a,reset:h,status:l,stopUpdatesWatch:R,submit:m,validate:d,VvForm:C}}function j(e,s){return r.defineComponent({name:"VvFormWrapper",props:{name:{type:String,required:!0},tag:{type:String,default:void 0}},emits:["invalid","valid"],expose:["clear","errors","fields","fieldsErrors","formData","invalid","reset","submit","tag","validate","validateWrapper"],slots:Object,setup(t,{emit:o}){const n=r.inject(e),l=r.inject(s,void 0),f=r.ref(new Set),u=r.ref(new Map),{name:a}=r.toRefs(t);r.provide(s,{name:r.readonly(a),errors:u,fields:f}),r.watch(f,v=>{l!=null&&l.fields&&v.forEach(h=>{l==null||l.fields.value.add(h)})},{deep:!0}),r.watch(()=>new Map(u.value),(v,h)=>{l!=null&&l.errors&&(Array.from(h.keys()).forEach(m=>{l.errors.value.delete(m)}),Array.from(v.keys()).forEach(m=>{const b=v.get(m);b&&l.errors.value.set(m,b)}))},{deep:!0});const p=r.computed(()=>n!=null&&n.invalid.value?u.value.size>0:!1);r.watch(p,()=>{p.value?o("invalid"):o("valid")});const d=()=>(n==null?void 0:n.validate(void 0,f.value))??Promise.resolve(!0);return{clear:n==null?void 0:n.clear,errors:n==null?void 0:n.errors,fields:f,fieldsErrors:u,formData:n==null?void 0:n.formData,invalid:p,reset:n==null?void 0:n.reset,submit:n==null?void 0:n.submit,validate:n==null?void 0:n.validate,validateWrapper:d}},render(){const t=()=>{var o,n;return(n=(o=this.$slots).default)==null?void 0:n.call(o,{clear:this.clear,errors:this.errors,fieldsErrors:this.fieldsErrors,formData:this.formData,invalid:this.invalid,reset:this.reset,submit:this.submit,validate:this.validate,validateWrapper:this.validateWrapper})};return this.tag?r.h(this.tag,null,{default:t}):t()}})}function D(e,s){const t=r.defineComponent({name:"VvFormTemplate",props:{schema:{type:[Array,Function],required:!0},scope:{type:Object,default:()=>({})}},slots:Object,setup(o,{slots:n}){const l=r.inject(e);if(l!=null&&l.formData)return()=>{var p;const f=typeof o.schema=="function"?o.schema(l,o.scope):o.schema;let u;const a=f.reduce((d,v)=>{const h=typeof v=="function"?v(l,o.scope):v,{vvIs:m,vvName:b,vvSlots:R,vvChildren:E,vvIf:O,vvElseIf:C,vvType:V,vvDefaultValue:g,vvShowValid:y,vvContent:i,...W}=h;if(O!==void 0){if(typeof O=="string"?u=!!B(new Object(l.formData.value),O):typeof O=="function"?u=r.unref(O(l)):u=r.unref(O),!u)return d}else if(C!==void 0&&u!==void 0){if(u||(typeof C=="string"?u=!!B(new Object(l.formData.value),C):typeof C=="function"?u=r.unref(C(l)):u=r.unref(C),!u))return d}else u=void 0;let I;return E&&(typeof m=="string"?I=r.h(t,{schema:E}):I={default:N=>r.h(t,{schema:E,scope:N})}),b?(d.push(r.h(s,{name:b,is:m,type:V,defaultValue:g,showValid:y,props:W},R??I??i)),d):m?(d.push(r.h(m,W,R??I??i)),d):(I&&("default"in I?d.push(I.default(o.scope)):d.push(I)),d)},[]);return a.push((p=n==null?void 0:n.default)==null?void 0:p.call(n,{errors:l==null?void 0:l.errors.value,formData:l==null?void 0:l.formData.value,invalid:l==null?void 0:l.invalid.value,status:l==null?void 0:l.status.value,submit:l==null?void 0:l.submit,validate:l==null?void 0:l.validate,clear:l==null?void 0:l.clear,reset:l==null?void 0:l.reset})),a}}});return t}function _(e,s={}){const t=Symbol("formInjectionKey"),o=Symbol("formWrapperInjectionKey"),n=Symbol("formFieldInjectionKey"),l=j(t,o),f=Y(t,o,n,s),u=D(t,f),{clear:a,errors:p,formData:d,ignoreUpdates:v,invalid:h,readonly:m,reset:b,status:R,stopUpdatesWatch:E,submit:O,validate:C,VvForm:V}=z(e,t,s,u);return{clear:a,errors:p,formData:d,formFieldInjectionKey:n,formInjectionKey:t,formWrapperInjectionKey:o,ignoreUpdates:v,invalid:h,readonly:m,reset:b,status:R,stopUpdatesWatch:E,submit:O,validate:C,VvForm:V,VvFormField:f,VvFormTemplate:u,VvFormWrapper:l}}const G=Symbol("pluginInjectionKey");function F(e){let s={};return e.schema&&(s=_(e.schema,e)),{...s,install(t,{global:o=!1}={}){t.provide(G,e),o&&(t.config.globalProperties.$vvForm=e,s!=null&&s.VvForm&&t.component("VvForm",s.VvForm),s!=null&&s.VvFormWrapper&&t.component("VvFormWrapper",s.VvFormWrapper),s!=null&&s.VvFormField&&t.component("VvFormField",s.VvFormField),s!=null&&s.VvFormTemplate&&t.component("VvFormTemplate",s.VvFormTemplate))}}}function ee(e,s={}){return r.getCurrentInstance()?_(e,{...r.inject(G,{}),...s}):_(e,s)}function re(e,s={}){return _(e,s)}x.FormFieldType=c,x.createForm=F,x.defaultObjectBySchema=A,x.formFactory=re,x.pluginInjectionKey=G,x.useForm=ee,Object.defineProperty(x,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
package/src/VvForm.ts
CHANGED
|
@@ -44,21 +44,18 @@ export function defineForm<Schema extends FormSchema>(schema: Schema, provideKey
|
|
|
44
44
|
}
|
|
45
45
|
const parseResult = await schema.safeParseAsync(value)
|
|
46
46
|
if (!parseResult.success) {
|
|
47
|
+
status.value = FormStatus.invalid
|
|
47
48
|
if (!fields) {
|
|
48
49
|
errors.value
|
|
49
50
|
= parseResult.error.format() as z.inferFormattedError<Schema>
|
|
50
|
-
status.value = FormStatus.invalid
|
|
51
51
|
return false
|
|
52
52
|
}
|
|
53
53
|
const fieldsIssues = parseResult.error.issues.filter(item => fields.has(item.path.join('.')))
|
|
54
54
|
if (!fieldsIssues.length) {
|
|
55
55
|
errors.value = undefined
|
|
56
|
-
status.value = FormStatus.unknown
|
|
57
|
-
formData.value = parseResult.data
|
|
58
56
|
return true
|
|
59
57
|
}
|
|
60
58
|
errors.value = new ZodError(fieldsIssues).format() as z.inferFormattedError<Schema>
|
|
61
|
-
status.value = FormStatus.invalid
|
|
62
59
|
return false
|
|
63
60
|
}
|
|
64
61
|
errors.value = undefined
|