@volverjs/form-vue 1.0.0-beta.2 → 1.0.0-beta.3
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 +163 -162
- package/dist/index.umd.js +1 -1
- package/dist/src/VvForm.d.ts +1 -0
- package/dist/src/index.d.ts +3 -0
- package/package.json +1 -1
- package/src/VvForm.ts +2 -2
- package/src/index.ts +2 -0
package/dist/index.es.js
CHANGED
|
@@ -20,52 +20,52 @@ function G(e) {
|
|
|
20
20
|
return typeof e > "u";
|
|
21
21
|
}
|
|
22
22
|
const ve = /^[0-9]+$/, ce = ["__proto__", "prototype", "constructor"];
|
|
23
|
-
function L(e,
|
|
23
|
+
function L(e, s, t) {
|
|
24
24
|
const o = de(t) ? t : void 0;
|
|
25
|
-
if (!H(e) || !Q(
|
|
25
|
+
if (!H(e) || !Q(s))
|
|
26
26
|
return o;
|
|
27
|
-
const u = Y(
|
|
27
|
+
const u = Y(s);
|
|
28
28
|
if (u.length !== 0) {
|
|
29
29
|
for (const r of u) {
|
|
30
30
|
if (r === "*")
|
|
31
31
|
continue;
|
|
32
|
-
const
|
|
33
|
-
return
|
|
32
|
+
const l = function(a) {
|
|
33
|
+
return a.map((f) => G(f) || q(f) ? f : R(f) ? l(f) : f[r]);
|
|
34
34
|
};
|
|
35
|
-
if (R(e) && !ve.test(r) ? e =
|
|
35
|
+
if (R(e) && !ve.test(r) ? e = l(e) : e = e[r], G(e) || q(e))
|
|
36
36
|
break;
|
|
37
37
|
}
|
|
38
38
|
return G(e) ? o : e;
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
function X(e,
|
|
42
|
-
if (!H(e) || !Q(
|
|
41
|
+
function X(e, s, t) {
|
|
42
|
+
if (!H(e) || !Q(s))
|
|
43
43
|
return;
|
|
44
|
-
const o = Y(
|
|
44
|
+
const o = Y(s);
|
|
45
45
|
if (o.length === 0)
|
|
46
46
|
return;
|
|
47
47
|
const u = o.length;
|
|
48
48
|
for (let r = 0; r < u; r++) {
|
|
49
|
-
const
|
|
49
|
+
const l = o[r];
|
|
50
50
|
if (r === u - 1) {
|
|
51
|
-
e[
|
|
51
|
+
e[l] = t;
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
|
-
if (
|
|
55
|
-
const
|
|
54
|
+
if (l === "*" && R(e)) {
|
|
55
|
+
const a = o.slice(r + 1).join(".");
|
|
56
56
|
for (const f of e)
|
|
57
|
-
X(f,
|
|
57
|
+
X(f, a, t);
|
|
58
58
|
return;
|
|
59
59
|
}
|
|
60
|
-
G(e[
|
|
60
|
+
G(e[l]) && (e[l] = {}), e = e[l];
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
function Y(e) {
|
|
64
|
-
const
|
|
65
|
-
return
|
|
64
|
+
const s = e.split(/[.]|(?:\[(\d|\*)\])/).filter((t) => !!t);
|
|
65
|
+
return s.some((t) => ce.indexOf(t) !== -1) ? [] : s;
|
|
66
66
|
}
|
|
67
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 || {}), x = /* @__PURE__ */ ((e) => (e.invalid = "invalid", e.valid = "valid", e.submitting = "submitting", e.updated = "updated", e.unknown = "unknown", e))(x || {});
|
|
68
|
-
const me = (e,
|
|
68
|
+
const me = (e, s, t, o) => z({
|
|
69
69
|
name: "VvFormField",
|
|
70
70
|
props: {
|
|
71
71
|
type: {
|
|
@@ -100,8 +100,8 @@ const me = (e, l, t, o) => z({
|
|
|
100
100
|
},
|
|
101
101
|
emits: ["invalid", "valid", "update:formData", "update:modelValue"],
|
|
102
102
|
expose: ["invalid", "invalidLabel", "errors"],
|
|
103
|
-
setup(u, { slots: r, emit:
|
|
104
|
-
const
|
|
103
|
+
setup(u, { slots: r, emit: l }) {
|
|
104
|
+
const a = k({
|
|
105
105
|
get() {
|
|
106
106
|
if (n != null && n.formData)
|
|
107
107
|
return L(
|
|
@@ -114,42 +114,42 @@ const me = (e, l, t, o) => z({
|
|
|
114
114
|
Object(n.formData.value),
|
|
115
115
|
String(u.name),
|
|
116
116
|
i
|
|
117
|
-
),
|
|
118
|
-
newValue:
|
|
117
|
+
), l("update:modelValue", {
|
|
118
|
+
newValue: a.value,
|
|
119
119
|
formData: n == null ? void 0 : n.formData
|
|
120
120
|
}));
|
|
121
121
|
}
|
|
122
122
|
});
|
|
123
123
|
D(() => {
|
|
124
|
-
|
|
124
|
+
a.value === void 0 && u.defaultValue !== void 0 && (a.value = u.defaultValue);
|
|
125
125
|
}), j(() => {
|
|
126
|
-
|
|
126
|
+
b(), y();
|
|
127
127
|
});
|
|
128
|
-
const f = U(
|
|
128
|
+
const f = U(s, void 0);
|
|
129
129
|
f && f.fields.value.add(u.name);
|
|
130
|
-
const n = U(e), { props: c, name:
|
|
130
|
+
const n = U(e), { props: c, name: h } = P(u), V = k(() => {
|
|
131
131
|
if (n != null && n.errors.value)
|
|
132
132
|
return L(n.errors.value, String(u.name));
|
|
133
|
-
}),
|
|
133
|
+
}), m = k(() => {
|
|
134
134
|
var i;
|
|
135
|
-
return (i =
|
|
136
|
-
}),
|
|
137
|
-
|
|
135
|
+
return (i = V.value) == null ? void 0 : i._errors;
|
|
136
|
+
}), v = k(() => V.value !== void 0), b = I(v, () => {
|
|
137
|
+
v.value ? (l("invalid", m.value), f && f.errors.value.set(
|
|
138
138
|
u.name,
|
|
139
139
|
{
|
|
140
|
-
_errors:
|
|
140
|
+
_errors: m.value
|
|
141
141
|
}
|
|
142
|
-
)) : (
|
|
142
|
+
)) : (l("valid", a.value), f && f.errors.value.delete(
|
|
143
143
|
u.name
|
|
144
144
|
));
|
|
145
|
-
}),
|
|
145
|
+
}), y = I(
|
|
146
146
|
() => n == null ? void 0 : n.formData,
|
|
147
147
|
() => {
|
|
148
|
-
|
|
148
|
+
l("update:formData", n == null ? void 0 : n.formData);
|
|
149
149
|
},
|
|
150
150
|
{ deep: !0 }
|
|
151
151
|
), g = (i) => {
|
|
152
|
-
|
|
152
|
+
a.value = i;
|
|
153
153
|
}, p = k(() => {
|
|
154
154
|
let i = c.value;
|
|
155
155
|
return typeof i == "function" && (i = i(n == null ? void 0 : n.formData)), Object.keys(i).reduce(
|
|
@@ -159,8 +159,8 @@ const me = (e, l, t, o) => z({
|
|
|
159
159
|
}), A = k(() => ({
|
|
160
160
|
...p.value,
|
|
161
161
|
name: p.value.name ?? u.name,
|
|
162
|
-
invalid:
|
|
163
|
-
valid: u.showValid ? !!(!
|
|
162
|
+
invalid: v.value,
|
|
163
|
+
valid: u.showValid ? !!(!v.value && a.value) : void 0,
|
|
164
164
|
type: ((i) => {
|
|
165
165
|
if ([
|
|
166
166
|
d.text,
|
|
@@ -179,28 +179,28 @@ const me = (e, l, t, o) => z({
|
|
|
179
179
|
].includes(i))
|
|
180
180
|
return i;
|
|
181
181
|
})(u.type),
|
|
182
|
-
invalidLabel:
|
|
183
|
-
modelValue:
|
|
182
|
+
invalidLabel: m.value,
|
|
183
|
+
modelValue: a.value,
|
|
184
184
|
"onUpdate:modelValue": g
|
|
185
185
|
}));
|
|
186
186
|
return M(t, {
|
|
187
|
-
name: S(
|
|
188
|
-
errors: S(
|
|
187
|
+
name: S(h),
|
|
188
|
+
errors: S(V)
|
|
189
189
|
}), { component: k(() => {
|
|
190
190
|
if (u.type === d.custom)
|
|
191
191
|
return {
|
|
192
192
|
render() {
|
|
193
193
|
var i;
|
|
194
194
|
return ((i = r.default) == null ? void 0 : i.call(r, {
|
|
195
|
-
modelValue:
|
|
195
|
+
modelValue: a.value,
|
|
196
196
|
onUpdate: g,
|
|
197
197
|
submit: n == null ? void 0 : n.submit,
|
|
198
198
|
validate: n == null ? void 0 : n.validate,
|
|
199
|
-
invalid:
|
|
200
|
-
invalidLabel:
|
|
199
|
+
invalid: v.value,
|
|
200
|
+
invalidLabel: m.value,
|
|
201
201
|
formData: n == null ? void 0 : n.formData.value,
|
|
202
202
|
formErrors: n == null ? void 0 : n.errors.value,
|
|
203
|
-
errors:
|
|
203
|
+
errors: V.value
|
|
204
204
|
})) ?? r.defalut;
|
|
205
205
|
}
|
|
206
206
|
};
|
|
@@ -256,41 +256,41 @@ const me = (e, l, t, o) => z({
|
|
|
256
256
|
}
|
|
257
257
|
return import("@volverjs/ui-vue/vv-input-text");
|
|
258
258
|
});
|
|
259
|
-
}), hasProps: A, invalid:
|
|
259
|
+
}), hasProps: A, invalid: v };
|
|
260
260
|
},
|
|
261
261
|
render() {
|
|
262
262
|
return this.is ? w(this.is, this.hasProps, this.$slots) : this.type === d.custom ? w(this.component, null, this.$slots) : w(this.component, this.hasProps, this.$slots);
|
|
263
263
|
}
|
|
264
|
-
}), J = (e,
|
|
264
|
+
}), J = (e, s = {}) => {
|
|
265
265
|
const t = (r) => {
|
|
266
|
-
let
|
|
267
|
-
for (;
|
|
268
|
-
|
|
269
|
-
return
|
|
266
|
+
let l = r;
|
|
267
|
+
for (; l instanceof fe; )
|
|
268
|
+
l = l.innerType();
|
|
269
|
+
return l instanceof oe && (l = l._def.innerType), l;
|
|
270
270
|
}, o = t(e);
|
|
271
271
|
return {
|
|
272
|
-
...(o instanceof K ? o._def.unknownKeys === "passthrough" : !1) ?
|
|
272
|
+
...(o instanceof K ? o._def.unknownKeys === "passthrough" : !1) ? s : {},
|
|
273
273
|
...Object.fromEntries(
|
|
274
274
|
Object.entries(o.shape).map(
|
|
275
|
-
([r,
|
|
276
|
-
const
|
|
277
|
-
let f = t(
|
|
278
|
-
if (f instanceof ue && (n = f._def.defaultValue(), f = f._def.innerType),
|
|
279
|
-
return [r,
|
|
275
|
+
([r, l]) => {
|
|
276
|
+
const a = s[r];
|
|
277
|
+
let f = t(l), n;
|
|
278
|
+
if (f instanceof ue && (n = f._def.defaultValue(), f = f._def.innerType), a === null && f instanceof le)
|
|
279
|
+
return [r, a];
|
|
280
280
|
if (f instanceof se) {
|
|
281
|
-
const c =
|
|
281
|
+
const c = l.safeParse(a);
|
|
282
282
|
if (c.success)
|
|
283
283
|
return [r, c.data ?? n];
|
|
284
284
|
}
|
|
285
|
-
if (f instanceof ie && Array.isArray(
|
|
285
|
+
if (f instanceof ie && Array.isArray(a) && a.length) {
|
|
286
286
|
const c = t(f._def.type);
|
|
287
287
|
if (c instanceof K)
|
|
288
288
|
return [
|
|
289
289
|
r,
|
|
290
|
-
|
|
291
|
-
(
|
|
290
|
+
a.map(
|
|
291
|
+
(h) => J(
|
|
292
292
|
c,
|
|
293
|
-
|
|
293
|
+
h && typeof h == "object" ? h : void 0
|
|
294
294
|
)
|
|
295
295
|
) ?? n
|
|
296
296
|
];
|
|
@@ -299,18 +299,18 @@ const me = (e, l, t, o) => z({
|
|
|
299
299
|
r,
|
|
300
300
|
J(
|
|
301
301
|
f,
|
|
302
|
-
|
|
302
|
+
a && typeof a == "object" ? a : n
|
|
303
303
|
)
|
|
304
304
|
] : [r, n];
|
|
305
305
|
}
|
|
306
306
|
)
|
|
307
307
|
)
|
|
308
308
|
};
|
|
309
|
-
}, he = (e,
|
|
310
|
-
const u = C(), r = C(), a = C(),
|
|
309
|
+
}, he = (e, s, t, o) => {
|
|
310
|
+
const u = C(), r = C(), l = k(() => r.value === x.invalid), a = C(), f = async (m = a.value) => {
|
|
311
311
|
const v = await e.safeParseAsync(m);
|
|
312
312
|
return v.success ? (u.value = void 0, r.value = x.valid, a.value = v.data, !0) : (u.value = v.error.format(), r.value = x.invalid, !1);
|
|
313
|
-
},
|
|
313
|
+
}, n = async () => await f() ? (r.value = x.submitting, !0) : !1, { ignoreUpdates: c, stop: h } = ae(
|
|
314
314
|
a,
|
|
315
315
|
() => {
|
|
316
316
|
r.value = x.updated;
|
|
@@ -319,7 +319,7 @@ const me = (e, l, t, o) => z({
|
|
|
319
319
|
deep: !0,
|
|
320
320
|
eventFilter: ne((t == null ? void 0 : t.updateThrottle) ?? 500)
|
|
321
321
|
}
|
|
322
|
-
),
|
|
322
|
+
), V = z({
|
|
323
323
|
name: "VvForm",
|
|
324
324
|
props: {
|
|
325
325
|
continuosValidation: {
|
|
@@ -342,38 +342,38 @@ const me = (e, l, t, o) => z({
|
|
|
342
342
|
emits: ["invalid", "valid", "submit", "update:modelValue"],
|
|
343
343
|
expose: ["submit", "validate", "errors", "status", "valid", "invalid"],
|
|
344
344
|
setup(m, { emit: v }) {
|
|
345
|
-
a.value = J(
|
|
345
|
+
return a.value = J(
|
|
346
346
|
e,
|
|
347
347
|
E(m.modelValue)
|
|
348
348
|
), I(
|
|
349
349
|
() => m.modelValue,
|
|
350
|
-
(
|
|
351
|
-
if (
|
|
352
|
-
const
|
|
353
|
-
a.value = typeof (
|
|
350
|
+
(b) => {
|
|
351
|
+
if (b) {
|
|
352
|
+
const y = ee(b) ? E(b) : b;
|
|
353
|
+
a.value = typeof (y == null ? void 0 : y.clone) == "function" ? y.clone() : JSON.parse(JSON.stringify(y));
|
|
354
354
|
}
|
|
355
355
|
},
|
|
356
356
|
{ deep: !0 }
|
|
357
|
-
), I(r, async (
|
|
358
|
-
var
|
|
359
|
-
if (
|
|
357
|
+
), I(r, async (b) => {
|
|
358
|
+
var y, g, p, A, W;
|
|
359
|
+
if (b === x.invalid) {
|
|
360
360
|
const i = E(
|
|
361
361
|
u.value
|
|
362
362
|
);
|
|
363
|
-
v("invalid", i), (
|
|
363
|
+
v("invalid", i), (y = t == null ? void 0 : t.onInvalid) == null || y.call(t, i);
|
|
364
364
|
return;
|
|
365
365
|
}
|
|
366
|
-
if (
|
|
366
|
+
if (b === x.valid) {
|
|
367
367
|
const i = E(a.value);
|
|
368
368
|
v("valid", i), (g = t == null ? void 0 : t.onValid) == null || g.call(t, i), v("update:modelValue", i), (p = t == null ? void 0 : t.onUpdate) == null || p.call(t, i);
|
|
369
369
|
return;
|
|
370
370
|
}
|
|
371
|
-
if (
|
|
371
|
+
if (b === x.submitting) {
|
|
372
372
|
const i = E(a.value);
|
|
373
373
|
v("submit", i), (A = t == null ? void 0 : t.onSubmit) == null || A.call(t, i);
|
|
374
374
|
}
|
|
375
|
-
if (
|
|
376
|
-
if ((u.value || t != null && t.continuosValidation || m.continuosValidation) && await
|
|
375
|
+
if (b === x.updated) {
|
|
376
|
+
if ((u.value || t != null && t.continuosValidation || m.continuosValidation) && await f(), !a.value || !m.modelValue || JSON.stringify(a.value) !== JSON.stringify(m.modelValue)) {
|
|
377
377
|
const i = E(
|
|
378
378
|
a.value
|
|
379
379
|
);
|
|
@@ -381,32 +381,30 @@ const me = (e, l, t, o) => z({
|
|
|
381
381
|
}
|
|
382
382
|
r.value === x.updated && (r.value = x.unknown);
|
|
383
383
|
}
|
|
384
|
-
})
|
|
385
|
-
const h = k(() => r.value === x.invalid);
|
|
386
|
-
return M(l, {
|
|
384
|
+
}), M(s, {
|
|
387
385
|
formData: a,
|
|
388
|
-
submit:
|
|
389
|
-
validate:
|
|
390
|
-
ignoreUpdates:
|
|
391
|
-
stopUpdatesWatch:
|
|
386
|
+
submit: n,
|
|
387
|
+
validate: f,
|
|
388
|
+
ignoreUpdates: c,
|
|
389
|
+
stopUpdatesWatch: h,
|
|
392
390
|
errors: S(u),
|
|
393
391
|
status: S(r),
|
|
394
|
-
invalid:
|
|
392
|
+
invalid: l
|
|
395
393
|
}), {
|
|
396
394
|
formData: a,
|
|
397
|
-
submit:
|
|
398
|
-
validate:
|
|
399
|
-
ignoreUpdates:
|
|
400
|
-
stopUpdatesWatch:
|
|
395
|
+
submit: n,
|
|
396
|
+
validate: f,
|
|
397
|
+
ignoreUpdates: c,
|
|
398
|
+
stopUpdatesWatch: h,
|
|
401
399
|
errors: S(u),
|
|
402
400
|
status: S(r),
|
|
403
|
-
invalid:
|
|
401
|
+
invalid: l
|
|
404
402
|
};
|
|
405
403
|
},
|
|
406
404
|
render() {
|
|
407
405
|
const m = () => {
|
|
408
|
-
var v,
|
|
409
|
-
return ((
|
|
406
|
+
var v, b;
|
|
407
|
+
return ((b = (v = this.$slots) == null ? void 0 : v.default) == null ? void 0 : b.call(v, {
|
|
410
408
|
formData: this.formData,
|
|
411
409
|
submit: this.submit,
|
|
412
410
|
validate: this.validate,
|
|
@@ -441,17 +439,18 @@ const me = (e, l, t, o) => z({
|
|
|
441
439
|
return {
|
|
442
440
|
errors: u,
|
|
443
441
|
status: r,
|
|
442
|
+
invalid: l,
|
|
444
443
|
formData: a,
|
|
445
|
-
validate:
|
|
446
|
-
submit:
|
|
447
|
-
ignoreUpdates:
|
|
448
|
-
stopUpdatesWatch:
|
|
444
|
+
validate: f,
|
|
445
|
+
submit: n,
|
|
446
|
+
ignoreUpdates: c,
|
|
447
|
+
stopUpdatesWatch: h,
|
|
449
448
|
/**
|
|
450
449
|
* An hack to add types to the default slot
|
|
451
450
|
*/
|
|
452
|
-
VvForm:
|
|
451
|
+
VvForm: V
|
|
453
452
|
};
|
|
454
|
-
}, be = (e,
|
|
453
|
+
}, be = (e, s) => z({
|
|
455
454
|
name: "VvFormWrapper",
|
|
456
455
|
props: {
|
|
457
456
|
name: {
|
|
@@ -466,27 +465,27 @@ const me = (e, l, t, o) => z({
|
|
|
466
465
|
emits: ["invalid", "valid"],
|
|
467
466
|
expose: ["fields", "invalid"],
|
|
468
467
|
setup(o, { emit: u }) {
|
|
469
|
-
const r = U(e),
|
|
470
|
-
M(
|
|
468
|
+
const r = U(e), l = U(s, void 0), a = C(/* @__PURE__ */ new Set()), f = C(/* @__PURE__ */ new Map()), { name: n } = P(o);
|
|
469
|
+
M(s, {
|
|
471
470
|
name: S(n),
|
|
472
471
|
errors: f,
|
|
473
|
-
fields:
|
|
472
|
+
fields: a
|
|
474
473
|
}), I(
|
|
475
|
-
|
|
476
|
-
(
|
|
477
|
-
|
|
478
|
-
|
|
474
|
+
a,
|
|
475
|
+
(h) => {
|
|
476
|
+
l != null && l.fields && h.forEach((V) => {
|
|
477
|
+
l == null || l.fields.value.add(V);
|
|
479
478
|
});
|
|
480
479
|
},
|
|
481
480
|
{ deep: !0 }
|
|
482
481
|
), I(
|
|
483
482
|
() => new Map(f.value),
|
|
484
|
-
(
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
}), Array.from(
|
|
488
|
-
const
|
|
489
|
-
|
|
483
|
+
(h, V) => {
|
|
484
|
+
l != null && l.errors && (Array.from(V.keys()).forEach((m) => {
|
|
485
|
+
l.errors.value.delete(m);
|
|
486
|
+
}), Array.from(h.keys()).forEach((m) => {
|
|
487
|
+
const v = h.get(m);
|
|
488
|
+
v && l.errors.value.set(m, v);
|
|
490
489
|
}));
|
|
491
490
|
},
|
|
492
491
|
{ deep: !0 }
|
|
@@ -500,7 +499,7 @@ const me = (e, l, t, o) => z({
|
|
|
500
499
|
submit: r == null ? void 0 : r.submit,
|
|
501
500
|
validate: r == null ? void 0 : r.validate,
|
|
502
501
|
invalid: c,
|
|
503
|
-
fields:
|
|
502
|
+
fields: a,
|
|
504
503
|
fieldsErrors: f
|
|
505
504
|
};
|
|
506
505
|
},
|
|
@@ -508,8 +507,8 @@ const me = (e, l, t, o) => z({
|
|
|
508
507
|
var o, u;
|
|
509
508
|
return this.tag ? w(this.tag, null, {
|
|
510
509
|
default: () => {
|
|
511
|
-
var r,
|
|
512
|
-
return ((
|
|
510
|
+
var r, l;
|
|
511
|
+
return ((l = (r = this.$slots).default) == null ? void 0 : l.call(r, {
|
|
513
512
|
invalid: this.invalid,
|
|
514
513
|
formData: this.formData,
|
|
515
514
|
submit: this.submit,
|
|
@@ -527,7 +526,7 @@ const me = (e, l, t, o) => z({
|
|
|
527
526
|
fieldsErrors: this.fieldsErrors
|
|
528
527
|
})) ?? this.$slots.defalut;
|
|
529
528
|
}
|
|
530
|
-
}), ye = (e,
|
|
529
|
+
}), ye = (e, s) => {
|
|
531
530
|
const t = z({
|
|
532
531
|
name: "VvFormTemplate",
|
|
533
532
|
props: {
|
|
@@ -541,14 +540,14 @@ const me = (e, l, t, o) => z({
|
|
|
541
540
|
if (r != null && r.formData)
|
|
542
541
|
return () => {
|
|
543
542
|
var n;
|
|
544
|
-
const
|
|
545
|
-
let
|
|
546
|
-
const f =
|
|
547
|
-
const
|
|
548
|
-
vvIs:
|
|
549
|
-
vvName:
|
|
550
|
-
vvSlots:
|
|
551
|
-
vvChildren:
|
|
543
|
+
const l = typeof o.schema == "function" ? o.schema(r) : o.schema;
|
|
544
|
+
let a;
|
|
545
|
+
const f = l.reduce((c, h) => {
|
|
546
|
+
const V = typeof h == "function" ? h(r) : h, {
|
|
547
|
+
vvIs: m,
|
|
548
|
+
vvName: v,
|
|
549
|
+
vvSlots: b,
|
|
550
|
+
vvChildren: y,
|
|
552
551
|
vvIf: g,
|
|
553
552
|
vvElseIf: p,
|
|
554
553
|
vvType: A,
|
|
@@ -556,44 +555,44 @@ const me = (e, l, t, o) => z({
|
|
|
556
555
|
vvShowValid: i,
|
|
557
556
|
vvContent: _,
|
|
558
557
|
...$
|
|
559
|
-
} =
|
|
558
|
+
} = V;
|
|
560
559
|
if (g !== void 0) {
|
|
561
|
-
if (typeof g == "string" ?
|
|
560
|
+
if (typeof g == "string" ? a = !!L(
|
|
562
561
|
Object(r.formData.value),
|
|
563
562
|
g
|
|
564
|
-
) : typeof g == "function" ?
|
|
563
|
+
) : typeof g == "function" ? a = B(g(r)) : a = B(g), !a)
|
|
565
564
|
return c;
|
|
566
|
-
} else if (p !== void 0 &&
|
|
567
|
-
if (
|
|
565
|
+
} else if (p !== void 0 && a !== void 0) {
|
|
566
|
+
if (a || (typeof p == "string" ? a = !!L(
|
|
568
567
|
Object(r.formData.value),
|
|
569
568
|
p
|
|
570
|
-
) : typeof p == "function" ?
|
|
569
|
+
) : typeof p == "function" ? a = B(p(r)) : a = B(p), !a))
|
|
571
570
|
return c;
|
|
572
571
|
} else
|
|
573
|
-
|
|
574
|
-
const Z =
|
|
575
|
-
schema:
|
|
572
|
+
a = void 0;
|
|
573
|
+
const Z = y ? w(t, {
|
|
574
|
+
schema: y
|
|
576
575
|
}) : void 0;
|
|
577
|
-
return
|
|
576
|
+
return v ? (c.push(
|
|
578
577
|
w(
|
|
579
|
-
|
|
578
|
+
s,
|
|
580
579
|
{
|
|
581
|
-
name:
|
|
582
|
-
is:
|
|
580
|
+
name: v,
|
|
581
|
+
is: m,
|
|
583
582
|
type: A,
|
|
584
583
|
defaultValue: W,
|
|
585
584
|
showValid: i,
|
|
586
585
|
props: $
|
|
587
586
|
},
|
|
588
|
-
|
|
587
|
+
b ?? Z ?? _
|
|
589
588
|
)
|
|
590
|
-
), c) :
|
|
589
|
+
), c) : m ? (c.push(
|
|
591
590
|
w(
|
|
592
|
-
|
|
591
|
+
m,
|
|
593
592
|
$,
|
|
594
|
-
|
|
593
|
+
b ?? Z ?? _
|
|
595
594
|
)
|
|
596
|
-
), c) : (
|
|
595
|
+
), c) : (y && c.push(Z), c);
|
|
597
596
|
}, []);
|
|
598
597
|
return f.push(
|
|
599
598
|
(n = u == null ? void 0 : u.default) == null ? void 0 : n.call(u, {
|
|
@@ -609,56 +608,58 @@ const me = (e, l, t, o) => z({
|
|
|
609
608
|
}
|
|
610
609
|
});
|
|
611
610
|
return t;
|
|
612
|
-
}, N = (e,
|
|
611
|
+
}, N = (e, s = {}) => {
|
|
613
612
|
const t = Symbol(), o = Symbol(), u = Symbol(), r = be(
|
|
614
613
|
t,
|
|
615
614
|
o
|
|
616
|
-
),
|
|
615
|
+
), l = me(
|
|
617
616
|
t,
|
|
618
617
|
o,
|
|
619
618
|
u,
|
|
620
|
-
|
|
621
|
-
),
|
|
619
|
+
s
|
|
620
|
+
), a = ye(t, l), {
|
|
622
621
|
VvForm: f,
|
|
623
622
|
errors: n,
|
|
624
623
|
status: c,
|
|
625
|
-
|
|
624
|
+
invalid: h,
|
|
625
|
+
formData: V,
|
|
626
626
|
validate: m,
|
|
627
627
|
submit: v,
|
|
628
|
-
ignoreUpdates:
|
|
628
|
+
ignoreUpdates: b,
|
|
629
629
|
stopUpdatesWatch: y
|
|
630
|
-
} = he(e, t,
|
|
630
|
+
} = he(e, t, s, a);
|
|
631
631
|
return {
|
|
632
632
|
VvForm: f,
|
|
633
633
|
VvFormWrapper: r,
|
|
634
|
-
VvFormField:
|
|
635
|
-
VvFormTemplate:
|
|
634
|
+
VvFormField: l,
|
|
635
|
+
VvFormTemplate: a,
|
|
636
636
|
formInjectionKey: t,
|
|
637
637
|
formWrapperInjectionKey: o,
|
|
638
638
|
formFieldInjectionKey: u,
|
|
639
639
|
errors: n,
|
|
640
640
|
status: c,
|
|
641
|
-
|
|
641
|
+
invalid: h,
|
|
642
|
+
formData: V,
|
|
642
643
|
validate: m,
|
|
643
644
|
submit: v,
|
|
644
|
-
ignoreUpdates:
|
|
645
|
+
ignoreUpdates: b,
|
|
645
646
|
stopUpdatesWatch: y
|
|
646
647
|
};
|
|
647
648
|
}, T = Symbol(), xe = (e) => {
|
|
648
|
-
let
|
|
649
|
-
return e.schema && (
|
|
650
|
-
...
|
|
649
|
+
let s = {};
|
|
650
|
+
return e.schema && (s = N(e.schema, e)), {
|
|
651
|
+
...s,
|
|
651
652
|
install(t, { global: o = !1 } = {}) {
|
|
652
|
-
t.provide(T, e), o && (t.config.globalProperties.$vvForm = e,
|
|
653
|
+
t.provide(T, 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));
|
|
653
654
|
}
|
|
654
655
|
};
|
|
655
|
-
}, ke = (e,
|
|
656
|
+
}, ke = (e, s = {}) => te() ? N(
|
|
656
657
|
e,
|
|
657
658
|
{
|
|
658
659
|
...U(T, {}),
|
|
659
|
-
...
|
|
660
|
+
...s
|
|
660
661
|
}
|
|
661
|
-
) : N(e,
|
|
662
|
+
) : N(e, s), we = (e, s = {}) => N(e, s);
|
|
662
663
|
export {
|
|
663
664
|
d as FormFieldType,
|
|
664
665
|
xe as createForm,
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(p,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):(p=typeof globalThis<"u"?globalThis:p||self,r(p["@volverjs/form-vue"]={},p.Vue,p.VueUseCore,p.zod))})(this,function(p,r,G,O){"use strict";function $(e){return Array.isArray(e)}function M(e){return typeof e<"u"}function L(e){return e===null}function N(e){return typeof e=="object"}function Z(e){return typeof e=="string"}function A(e){return typeof e>"u"}const J=/^[0-9]+$/,P=["__proto__","prototype","constructor"];function E(e,i,a){const d=M(a)?a:void 0;if(!N(e)||!Z(i))return d;const s=q(i);if(s.length!==0){for(const t of s){if(t==="*")continue;const n=function(u){return u.map(f=>A(f)||L(f)?f:$(f)?n(f):f[t])};if($(e)&&!J.test(t)?e=n(e):e=e[t],A(e)||L(e))break}return A(e)?d:e}}function K(e,i,a){if(!N(e)||!Z(i))return;const d=q(i);if(d.length===0)return;const s=d.length;for(let t=0;t<s;t++){const n=d[t];if(t===s-1){e[n]=a;return}if(n==="*"&&$(e)){const u=d.slice(t+1).join(".");for(const f of e)K(f,u,a);return}A(e[n])&&(e[n]={}),e=e[n]}}function q(e){const i=e.split(/[.]|(?:\[(\d|\*)\])/).filter(a=>!!a);return i.some(a=>P.indexOf(a)!==-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||{}),w=(e=>(e.invalid="invalid",e.valid="valid",e.submitting="submitting",e.updated="updated",e.unknown="unknown",e))(w||{});const z=(e,i,a,d)=>r.defineComponent({name:"VvFormField",props:{type:{type:String,validator:s=>Object.values(c).includes(s),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}},emits:["invalid","valid","update:formData","update:modelValue"],expose:["invalid","invalidLabel","errors"],setup(s,{slots:t,emit:n}){const u=r.computed({get(){if(l!=null&&l.formData)return E(Object(l.formData.value),String(s.name))},set(o){l!=null&&l.formData&&(K(Object(l.formData.value),String(s.name),o),n("update:modelValue",{newValue:u.value,formData:l==null?void 0:l.formData}))}});r.onMounted(()=>{u.value===void 0&&s.defaultValue!==void 0&&(u.value=s.defaultValue)}),r.onBeforeUnmount(()=>{V(),g()});const f=r.inject(i,void 0);f&&f.fields.value.add(s.name);const l=r.inject(e),{props:v,name:b}=r.toRefs(s),h=r.computed(()=>{if(l!=null&&l.errors.value)return E(l.errors.value,String(s.name))}),m=r.computed(()=>{var o;return(o=h.value)==null?void 0:o._errors}),y=r.computed(()=>h.value!==void 0),V=r.watch(y,()=>{y.value?(n("invalid",m.value),f&&f.errors.value.set(s.name,{_errors:m.value})):(n("valid",u.value),f&&f.errors.value.delete(s.name))}),g=r.watch(()=>l==null?void 0:l.formData,()=>{n("update:formData",l==null?void 0:l.formData)},{deep:!0}),x=o=>{u.value=o},k=r.computed(()=>{let o=v.value;return typeof o=="function"&&(o=o(l==null?void 0:l.formData)),Object.keys(o).reduce((I,U)=>(I[U]=r.unref(o[U]),I),{})}),C=r.computed(()=>({...k.value,name:k.value.name??s.name,invalid:y.value,valid:s.showValid?!!(!y.value&&u.value):void 0,type:(o=>{if([c.text,c.number,c.email,c.password,c.tel,c.url,c.search,c.date,c.time,c.datetimeLocal,c.month,c.week,c.color].includes(o))return o})(s.type),invalidLabel:m.value,modelValue:u.value,"onUpdate:modelValue":x}));return r.provide(a,{name:r.readonly(b),errors:r.readonly(h)}),{component:r.computed(()=>{if(s.type===c.custom)return{render(){var o;return((o=t.default)==null?void 0:o.call(t,{modelValue:u.value,onUpdate:x,submit:l==null?void 0:l.submit,validate:l==null?void 0:l.validate,invalid:y.value,invalidLabel:m.value,formData:l==null?void 0:l.formData.value,formErrors:l==null?void 0:l.errors.value,errors:h.value}))??t.defalut}};if(!((d==null?void 0:d.lazyLoad)??s.lazyLoad)){let o;switch(s.type){case c.select:o=r.resolveComponent("VvSelect");break;case c.checkbox:o=r.resolveComponent("VvCheckbox");break;case c.radio:o=r.resolveComponent("VvRadio");break;case c.textarea:o=r.resolveComponent("VvTextarea");break;case c.radioGroup:o=r.resolveComponent("VvRadioGroup");break;case c.checkboxGroup:o=r.resolveComponent("VvCheckboxGroup");break;case c.combobox:o=r.resolveComponent("VvCombobox");break;default:o=r.resolveComponent("VvInputText")}if(typeof o!="string")return o;console.warn(`[form-vue warn]: ${o} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`)}return r.defineAsyncComponent(async()=>{switch(d!=null&&d.sideEffects&&await Promise.resolve(d.sideEffects(s.type)),s.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:C,invalid:y}},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)}}),W=(e,i={})=>{const a=t=>{let n=t;for(;n instanceof O.ZodEffects;)n=n.innerType();return n instanceof O.ZodOptional&&(n=n._def.innerType),n},d=a(e);return{...(d instanceof O.ZodObject?d._def.unknownKeys==="passthrough":!1)?i:{},...Object.fromEntries(Object.entries(d.shape).map(([t,n])=>{const u=i[t];let f=a(n),l;if(f instanceof O.ZodDefault&&(l=f._def.defaultValue(),f=f._def.innerType),u===null&&f instanceof O.ZodNullable)return[t,u];if(f instanceof O.ZodSchema){const v=n.safeParse(u);if(v.success)return[t,v.data??l]}if(f instanceof O.ZodArray&&Array.isArray(u)&&u.length){const v=a(f._def.type);if(v instanceof O.ZodObject)return[t,u.map(b=>W(v,b&&typeof b=="object"?b:void 0))??l]}return f instanceof O.ZodObject?[t,W(f,u&&typeof u=="object"?u:l)]:[t,l]}))}},T=(e,i,a,d)=>{const s=r.ref(),t=r.ref(),n=r.ref(),u=async(h=n.value)=>{const m=await e.safeParseAsync(h);return m.success?(s.value=void 0,t.value=w.valid,n.value=m.data,!0):(s.value=m.error.format(),t.value=w.invalid,!1)},f=async()=>await u()?(t.value=w.submitting,!0):!1,{ignoreUpdates:l,stop:v}=G.watchIgnorable(n,()=>{t.value=w.updated},{deep:!0,eventFilter:G.throttleFilter((a==null?void 0:a.updateThrottle)??500)}),b=r.defineComponent({name:"VvForm",props:{continuosValidation:{type:Boolean,default:!1},modelValue:{type:Object,default:()=>({})},tag:{type:String,default:"form"},template:{type:[Array,Function],default:void 0}},emits:["invalid","valid","submit","update:modelValue"],expose:["submit","validate","errors","status","valid","invalid"],setup(h,{emit:m}){n.value=W(e,r.toRaw(h.modelValue)),r.watch(()=>h.modelValue,V=>{if(V){const g=r.isProxy(V)?r.toRaw(V):V;n.value=typeof(g==null?void 0:g.clone)=="function"?g.clone():JSON.parse(JSON.stringify(g))}},{deep:!0}),r.watch(t,async V=>{var g,x,k,C,S;if(V===w.invalid){const o=r.toRaw(s.value);m("invalid",o),(g=a==null?void 0:a.onInvalid)==null||g.call(a,o);return}if(V===w.valid){const o=r.toRaw(n.value);m("valid",o),(x=a==null?void 0:a.onValid)==null||x.call(a,o),m("update:modelValue",o),(k=a==null?void 0:a.onUpdate)==null||k.call(a,o);return}if(V===w.submitting){const o=r.toRaw(n.value);m("submit",o),(C=a==null?void 0:a.onSubmit)==null||C.call(a,o)}if(V===w.updated){if((s.value||a!=null&&a.continuosValidation||h.continuosValidation)&&await u(),!n.value||!h.modelValue||JSON.stringify(n.value)!==JSON.stringify(h.modelValue)){const o=r.toRaw(n.value);m("update:modelValue",o),(S=a==null?void 0:a.onUpdate)==null||S.call(a,o)}t.value===w.updated&&(t.value=w.unknown)}});const y=r.computed(()=>t.value===w.invalid);return r.provide(i,{formData:n,submit:f,validate:u,ignoreUpdates:l,stopUpdatesWatch:v,errors:r.readonly(s),status:r.readonly(t),invalid:y}),{formData:n,submit:f,validate:u,ignoreUpdates:l,stopUpdatesWatch:v,errors:r.readonly(s),status:r.readonly(t),invalid:y}},render(){const h=()=>{var m,y;return((y=(m=this.$slots)==null?void 0:m.default)==null?void 0:y.call(m,{formData:this.formData,submit:this.submit,validate:this.validate,ignoreUpdates:this.ignoreUpdates,stopUpdatesWatch:this.stopUpdatesWatch,errors:this.errors,status:this.status,invalid:this.invalid}))??this.$slots.default};return r.h(this.tag,{onSubmit:r.withModifiers(this.submit,["prevent"])},(this.template??(a==null?void 0:a.template))&&d?[r.h(d,{schema:this.template??(a==null?void 0:a.template)},{default:h})]:{default:h})}});return{errors:s,status:t,formData:n,validate:u,submit:f,ignoreUpdates:l,stopUpdatesWatch:v,VvForm:b}},H=(e,i)=>r.defineComponent({name:"VvFormWrapper",props:{name:{type:String,required:!0},tag:{type:String,default:void 0}},emits:["invalid","valid"],expose:["fields","invalid"],setup(d,{emit:s}){const t=r.inject(e),n=r.inject(i,void 0),u=r.ref(new Set),f=r.ref(new Map),{name:l}=r.toRefs(d);r.provide(i,{name:r.readonly(l),errors:f,fields:u}),r.watch(u,b=>{n!=null&&n.fields&&b.forEach(h=>{n==null||n.fields.value.add(h)})},{deep:!0}),r.watch(()=>new Map(f.value),(b,h)=>{n!=null&&n.errors&&(Array.from(h.keys()).forEach(m=>{n.errors.value.delete(m)}),Array.from(b.keys()).forEach(m=>{const y=b.get(m);y&&n.errors.value.set(m,y)}))},{deep:!0});const v=r.computed(()=>t!=null&&t.invalid.value?f.value.size>0:!1);return r.watch(v,()=>{v.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:v,fields:u,fieldsErrors:f}},render(){var d,s;return this.tag?r.h(this.tag,null,{default:()=>{var t,n;return((n=(t=this.$slots).default)==null?void 0:n.call(t,{invalid:this.invalid,formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}):((s=(d=this.$slots).default)==null?void 0:s.call(d,{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({name:"VvFormTemplate",props:{schema:{type:[Array,Function],required:!0}},setup(d,{slots:s}){const t=r.inject(e);if(t!=null&&t.formData)return()=>{var l;const n=typeof d.schema=="function"?d.schema(t):d.schema;let u;const f=n.reduce((v,b)=>{const h=typeof b=="function"?b(t):b,{vvIs:m,vvName:y,vvSlots:V,vvChildren:g,vvIf:x,vvElseIf:k,vvType:C,vvDefaultValue:S,vvShowValid:o,vvContent:I,...U}=h;if(x!==void 0){if(typeof x=="string"?u=!!E(Object(t.formData.value),x):typeof x=="function"?u=r.unref(x(t)):u=r.unref(x),!u)return v}else if(k!==void 0&&u!==void 0){if(u||(typeof k=="string"?u=!!E(Object(t.formData.value),k):typeof k=="function"?u=r.unref(k(t)):u=r.unref(k),!u))return v}else u=void 0;const R=g?r.h(a,{schema:g}):void 0;return y?(v.push(r.h(i,{name:y,is:m,type:C,defaultValue:S,showValid:o,props:U},V??R??I)),v):m?(v.push(r.h(m,U,V??R??I)),v):(g&&v.push(R),v)},[]);return f.push((l=s==null?void 0:s.default)==null?void 0:l.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})),f}}});return a},_=(e,i={})=>{const a=Symbol(),d=Symbol(),s=Symbol(),t=H(a,d),n=z(a,d,s,i),u=Q(a,n),{VvForm:f,errors:l,status:v,formData:b,validate:h,submit:m,ignoreUpdates:y,stopUpdatesWatch:V}=T(e,a,i,u);return{VvForm:f,VvFormWrapper:t,VvFormField:n,VvFormTemplate:u,formInjectionKey:a,formWrapperInjectionKey:d,formFieldInjectionKey:s,errors:l,status:v,formData:b,validate:h,submit:m,ignoreUpdates:y,stopUpdatesWatch:V}},B=Symbol(),X=e=>{let i={};return e.schema&&(i=_(e.schema,e)),{...i,install(a,{global:d=!1}={}){a.provide(B,e),d&&(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);p.FormFieldType=c,p.createForm=X,p.defaultObjectBySchema=W,p.formFactory=D,p.pluginInjectionKey=B,p.useForm=Y,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(p,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):(p=typeof globalThis<"u"?globalThis:p||self,r(p["@volverjs/form-vue"]={},p.Vue,p.VueUseCore,p.zod))})(this,function(p,r,G,O){"use strict";function $(e){return Array.isArray(e)}function M(e){return typeof e<"u"}function L(e){return e===null}function N(e){return typeof e=="object"}function Z(e){return typeof e=="string"}function A(e){return typeof e>"u"}const J=/^[0-9]+$/,P=["__proto__","prototype","constructor"];function E(e,u,a){const d=M(a)?a:void 0;if(!N(e)||!Z(u))return d;const i=q(u);if(i.length!==0){for(const t of i){if(t==="*")continue;const s=function(n){return n.map(f=>A(f)||L(f)?f:$(f)?s(f):f[t])};if($(e)&&!J.test(t)?e=s(e):e=e[t],A(e)||L(e))break}return A(e)?d:e}}function K(e,u,a){if(!N(e)||!Z(u))return;const d=q(u);if(d.length===0)return;const i=d.length;for(let t=0;t<i;t++){const s=d[t];if(t===i-1){e[s]=a;return}if(s==="*"&&$(e)){const n=d.slice(t+1).join(".");for(const f of e)K(f,n,a);return}A(e[s])&&(e[s]={}),e=e[s]}}function q(e){const u=e.split(/[.]|(?:\[(\d|\*)\])/).filter(a=>!!a);return u.some(a=>P.indexOf(a)!==-1)?[]:u}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||{}),w=(e=>(e.invalid="invalid",e.valid="valid",e.submitting="submitting",e.updated="updated",e.unknown="unknown",e))(w||{});const z=(e,u,a,d)=>r.defineComponent({name:"VvFormField",props:{type:{type:String,validator:i=>Object.values(c).includes(i),default:c.custom},is:{type:[Object,String],default:void 0},name:{type:[String,Number,Boolean,Symbol],required:!0},props:{type:[Object,Function],default:()=>({})},showValid:{type:Boolean,default:!1},defaultValue:{type:[String,Number,Boolean,Array,Object],default:void 0},lazyLoad:{type:Boolean,default:!1}},emits:["invalid","valid","update:formData","update:modelValue"],expose:["invalid","invalidLabel","errors"],setup(i,{slots:t,emit:s}){const n=r.computed({get(){if(l!=null&&l.formData)return E(Object(l.formData.value),String(i.name))},set(o){l!=null&&l.formData&&(K(Object(l.formData.value),String(i.name),o),s("update:modelValue",{newValue:n.value,formData:l==null?void 0:l.formData}))}});r.onMounted(()=>{n.value===void 0&&i.defaultValue!==void 0&&(n.value=i.defaultValue)}),r.onBeforeUnmount(()=>{b(),V()});const f=r.inject(u,void 0);f&&f.fields.value.add(i.name);const l=r.inject(e),{props:v,name:y}=r.toRefs(i),g=r.computed(()=>{if(l!=null&&l.errors.value)return E(l.errors.value,String(i.name))}),h=r.computed(()=>{var o;return(o=g.value)==null?void 0:o._errors}),m=r.computed(()=>g.value!==void 0),b=r.watch(m,()=>{m.value?(s("invalid",h.value),f&&f.errors.value.set(i.name,{_errors:h.value})):(s("valid",n.value),f&&f.errors.value.delete(i.name))}),V=r.watch(()=>l==null?void 0:l.formData,()=>{s("update:formData",l==null?void 0:l.formData)},{deep:!0}),x=o=>{n.value=o},k=r.computed(()=>{let o=v.value;return typeof o=="function"&&(o=o(l==null?void 0:l.formData)),Object.keys(o).reduce((I,U)=>(I[U]=r.unref(o[U]),I),{})}),C=r.computed(()=>({...k.value,name:k.value.name??i.name,invalid:m.value,valid:i.showValid?!!(!m.value&&n.value):void 0,type:(o=>{if([c.text,c.number,c.email,c.password,c.tel,c.url,c.search,c.date,c.time,c.datetimeLocal,c.month,c.week,c.color].includes(o))return o})(i.type),invalidLabel:h.value,modelValue:n.value,"onUpdate:modelValue":x}));return r.provide(a,{name:r.readonly(y),errors:r.readonly(g)}),{component:r.computed(()=>{if(i.type===c.custom)return{render(){var o;return((o=t.default)==null?void 0:o.call(t,{modelValue:n.value,onUpdate:x,submit:l==null?void 0:l.submit,validate:l==null?void 0:l.validate,invalid:m.value,invalidLabel:h.value,formData:l==null?void 0:l.formData.value,formErrors:l==null?void 0:l.errors.value,errors:g.value}))??t.defalut}};if(!((d==null?void 0:d.lazyLoad)??i.lazyLoad)){let o;switch(i.type){case c.select:o=r.resolveComponent("VvSelect");break;case c.checkbox:o=r.resolveComponent("VvCheckbox");break;case c.radio:o=r.resolveComponent("VvRadio");break;case c.textarea:o=r.resolveComponent("VvTextarea");break;case c.radioGroup:o=r.resolveComponent("VvRadioGroup");break;case c.checkboxGroup:o=r.resolveComponent("VvCheckboxGroup");break;case c.combobox:o=r.resolveComponent("VvCombobox");break;default:o=r.resolveComponent("VvInputText")}if(typeof o!="string")return o;console.warn(`[form-vue warn]: ${o} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`)}return r.defineAsyncComponent(async()=>{switch(d!=null&&d.sideEffects&&await Promise.resolve(d.sideEffects(i.type)),i.type){case c.textarea:return import("@volverjs/ui-vue/vv-textarea");case c.radio:return import("@volverjs/ui-vue/vv-radio");case c.radioGroup:return import("@volverjs/ui-vue/vv-radio-group");case c.checkbox:return import("@volverjs/ui-vue/vv-checkbox");case c.checkboxGroup:return import("@volverjs/ui-vue/vv-checkbox-group");case c.select:return import("@volverjs/ui-vue/vv-select");case c.combobox:return import("@volverjs/ui-vue/vv-combobox")}return import("@volverjs/ui-vue/vv-input-text")})}),hasProps:C,invalid:m}},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)}}),W=(e,u={})=>{const a=t=>{let s=t;for(;s instanceof O.ZodEffects;)s=s.innerType();return s instanceof O.ZodOptional&&(s=s._def.innerType),s},d=a(e);return{...(d instanceof O.ZodObject?d._def.unknownKeys==="passthrough":!1)?u:{},...Object.fromEntries(Object.entries(d.shape).map(([t,s])=>{const n=u[t];let f=a(s),l;if(f instanceof O.ZodDefault&&(l=f._def.defaultValue(),f=f._def.innerType),n===null&&f instanceof O.ZodNullable)return[t,n];if(f instanceof O.ZodSchema){const v=s.safeParse(n);if(v.success)return[t,v.data??l]}if(f instanceof O.ZodArray&&Array.isArray(n)&&n.length){const v=a(f._def.type);if(v instanceof O.ZodObject)return[t,n.map(y=>W(v,y&&typeof y=="object"?y:void 0))??l]}return f instanceof O.ZodObject?[t,W(f,n&&typeof n=="object"?n:l)]:[t,l]}))}},T=(e,u,a,d)=>{const i=r.ref(),t=r.ref(),s=r.computed(()=>t.value===w.invalid),n=r.ref(),f=async(h=n.value)=>{const m=await e.safeParseAsync(h);return m.success?(i.value=void 0,t.value=w.valid,n.value=m.data,!0):(i.value=m.error.format(),t.value=w.invalid,!1)},l=async()=>await f()?(t.value=w.submitting,!0):!1,{ignoreUpdates:v,stop:y}=G.watchIgnorable(n,()=>{t.value=w.updated},{deep:!0,eventFilter:G.throttleFilter((a==null?void 0:a.updateThrottle)??500)}),g=r.defineComponent({name:"VvForm",props:{continuosValidation:{type:Boolean,default:!1},modelValue:{type:Object,default:()=>({})},tag:{type:String,default:"form"},template:{type:[Array,Function],default:void 0}},emits:["invalid","valid","submit","update:modelValue"],expose:["submit","validate","errors","status","valid","invalid"],setup(h,{emit:m}){return n.value=W(e,r.toRaw(h.modelValue)),r.watch(()=>h.modelValue,b=>{if(b){const V=r.isProxy(b)?r.toRaw(b):b;n.value=typeof(V==null?void 0:V.clone)=="function"?V.clone():JSON.parse(JSON.stringify(V))}},{deep:!0}),r.watch(t,async b=>{var V,x,k,C,S;if(b===w.invalid){const o=r.toRaw(i.value);m("invalid",o),(V=a==null?void 0:a.onInvalid)==null||V.call(a,o);return}if(b===w.valid){const o=r.toRaw(n.value);m("valid",o),(x=a==null?void 0:a.onValid)==null||x.call(a,o),m("update:modelValue",o),(k=a==null?void 0:a.onUpdate)==null||k.call(a,o);return}if(b===w.submitting){const o=r.toRaw(n.value);m("submit",o),(C=a==null?void 0:a.onSubmit)==null||C.call(a,o)}if(b===w.updated){if((i.value||a!=null&&a.continuosValidation||h.continuosValidation)&&await f(),!n.value||!h.modelValue||JSON.stringify(n.value)!==JSON.stringify(h.modelValue)){const o=r.toRaw(n.value);m("update:modelValue",o),(S=a==null?void 0:a.onUpdate)==null||S.call(a,o)}t.value===w.updated&&(t.value=w.unknown)}}),r.provide(u,{formData:n,submit:l,validate:f,ignoreUpdates:v,stopUpdatesWatch:y,errors:r.readonly(i),status:r.readonly(t),invalid:s}),{formData:n,submit:l,validate:f,ignoreUpdates:v,stopUpdatesWatch:y,errors:r.readonly(i),status:r.readonly(t),invalid:s}},render(){const h=()=>{var m,b;return((b=(m=this.$slots)==null?void 0:m.default)==null?void 0:b.call(m,{formData:this.formData,submit:this.submit,validate:this.validate,ignoreUpdates:this.ignoreUpdates,stopUpdatesWatch:this.stopUpdatesWatch,errors:this.errors,status:this.status,invalid:this.invalid}))??this.$slots.default};return r.h(this.tag,{onSubmit:r.withModifiers(this.submit,["prevent"])},(this.template??(a==null?void 0:a.template))&&d?[r.h(d,{schema:this.template??(a==null?void 0:a.template)},{default:h})]:{default:h})}});return{errors:i,status:t,invalid:s,formData:n,validate:f,submit:l,ignoreUpdates:v,stopUpdatesWatch:y,VvForm:g}},H=(e,u)=>r.defineComponent({name:"VvFormWrapper",props:{name:{type:String,required:!0},tag:{type:String,default:void 0}},emits:["invalid","valid"],expose:["fields","invalid"],setup(d,{emit:i}){const t=r.inject(e),s=r.inject(u,void 0),n=r.ref(new Set),f=r.ref(new Map),{name:l}=r.toRefs(d);r.provide(u,{name:r.readonly(l),errors:f,fields:n}),r.watch(n,y=>{s!=null&&s.fields&&y.forEach(g=>{s==null||s.fields.value.add(g)})},{deep:!0}),r.watch(()=>new Map(f.value),(y,g)=>{s!=null&&s.errors&&(Array.from(g.keys()).forEach(h=>{s.errors.value.delete(h)}),Array.from(y.keys()).forEach(h=>{const m=y.get(h);m&&s.errors.value.set(h,m)}))},{deep:!0});const v=r.computed(()=>t!=null&&t.invalid.value?f.value.size>0:!1);return r.watch(v,()=>{v.value?i("invalid"):i("valid")}),{formData:t==null?void 0:t.formData,errors:t==null?void 0:t.errors,submit:t==null?void 0:t.submit,validate:t==null?void 0:t.validate,invalid:v,fields:n,fieldsErrors:f}},render(){var d,i;return this.tag?r.h(this.tag,null,{default:()=>{var t,s;return((s=(t=this.$slots).default)==null?void 0:s.call(t,{invalid:this.invalid,formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}):((i=(d=this.$slots).default)==null?void 0:i.call(d,{invalid:this.invalid,formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}),Q=(e,u)=>{const a=r.defineComponent({name:"VvFormTemplate",props:{schema:{type:[Array,Function],required:!0}},setup(d,{slots:i}){const t=r.inject(e);if(t!=null&&t.formData)return()=>{var l;const s=typeof d.schema=="function"?d.schema(t):d.schema;let n;const f=s.reduce((v,y)=>{const g=typeof y=="function"?y(t):y,{vvIs:h,vvName:m,vvSlots:b,vvChildren:V,vvIf:x,vvElseIf:k,vvType:C,vvDefaultValue:S,vvShowValid:o,vvContent:I,...U}=g;if(x!==void 0){if(typeof x=="string"?n=!!E(Object(t.formData.value),x):typeof x=="function"?n=r.unref(x(t)):n=r.unref(x),!n)return v}else if(k!==void 0&&n!==void 0){if(n||(typeof k=="string"?n=!!E(Object(t.formData.value),k):typeof k=="function"?n=r.unref(k(t)):n=r.unref(k),!n))return v}else n=void 0;const R=V?r.h(a,{schema:V}):void 0;return m?(v.push(r.h(u,{name:m,is:h,type:C,defaultValue:S,showValid:o,props:U},b??R??I)),v):h?(v.push(r.h(h,U,b??R??I)),v):(V&&v.push(R),v)},[]);return f.push((l=i==null?void 0:i.default)==null?void 0:l.call(i,{formData:t==null?void 0:t.formData.value,submit:t==null?void 0:t.submit,validate:t==null?void 0:t.validate,errors:t==null?void 0:t.errors.value,status:t==null?void 0:t.status.value,invalid:t==null?void 0:t.invalid.value})),f}}});return a},_=(e,u={})=>{const a=Symbol(),d=Symbol(),i=Symbol(),t=H(a,d),s=z(a,d,i,u),n=Q(a,s),{VvForm:f,errors:l,status:v,invalid:y,formData:g,validate:h,submit:m,ignoreUpdates:b,stopUpdatesWatch:V}=T(e,a,u,n);return{VvForm:f,VvFormWrapper:t,VvFormField:s,VvFormTemplate:n,formInjectionKey:a,formWrapperInjectionKey:d,formFieldInjectionKey:i,errors:l,status:v,invalid:y,formData:g,validate:h,submit:m,ignoreUpdates:b,stopUpdatesWatch:V}},B=Symbol(),X=e=>{let u={};return e.schema&&(u=_(e.schema,e)),{...u,install(a,{global:d=!1}={}){a.provide(B,e),d&&(a.config.globalProperties.$vvForm=e,u!=null&&u.VvForm&&a.component("VvForm",u.VvForm),u!=null&&u.VvFormWrapper&&a.component("VvFormWrapper",u.VvFormWrapper),u!=null&&u.VvFormField&&a.component("VvFormField",u.VvFormField),u!=null&&u.VvFormTemplate&&a.component("VvFormTemplate",u.VvFormTemplate))}}},Y=(e,u={})=>r.getCurrentInstance()?_(e,{...r.inject(B,{}),...u}):_(e,u),D=(e,u={})=>_(e,u);p.FormFieldType=c,p.createForm=X,p.defaultObjectBySchema=W,p.formFactory=D,p.pluginInjectionKey=B,p.useForm=Y,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
|
package/dist/src/VvForm.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { FormStatus } from './enums';
|
|
|
6
6
|
export declare const defineForm: <Schema extends FormSchema>(schema: Schema, provideKey: InjectionKey<InjectedFormData<Schema>>, options?: FormComponentOptions<Schema> | undefined, VvFormTemplate?: Component) => {
|
|
7
7
|
errors: Ref<z.inferFormattedError<Schema, string> | undefined>;
|
|
8
8
|
status: Ref<FormStatus | undefined>;
|
|
9
|
+
invalid: import("vue").ComputedRef<boolean>;
|
|
9
10
|
formData: Ref<Partial<z.TypeOf<Schema> | undefined>>;
|
|
10
11
|
validate: (value?: Partial<z.TypeOf<Schema> | undefined>) => Promise<boolean>;
|
|
11
12
|
submit: () => Promise<boolean>;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -623,6 +623,7 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
623
623
|
formFieldInjectionKey: InjectionKey<InjectedFormFieldData<Schema>>;
|
|
624
624
|
errors: import("vue").Ref<import("zod").inferFormattedError<Schema, string> | undefined>;
|
|
625
625
|
status: import("vue").Ref<import("./enums").FormStatus | undefined>;
|
|
626
|
+
invalid: import("vue").ComputedRef<boolean>;
|
|
626
627
|
formData: import("vue").Ref<Partial<import("zod").TypeOf<Schema> | undefined>>;
|
|
627
628
|
validate: (value?: Partial<import("zod").TypeOf<Schema> | undefined>) => Promise<boolean>;
|
|
628
629
|
submit: () => Promise<boolean>;
|
|
@@ -1313,6 +1314,7 @@ export declare const useForm: <Schema extends FormSchema>(schema: Schema, option
|
|
|
1313
1314
|
formFieldInjectionKey: InjectionKey<InjectedFormFieldData<AnyZodObject>>;
|
|
1314
1315
|
errors: import("vue").Ref<import("zod").inferFormattedError<AnyZodObject, string> | undefined>;
|
|
1315
1316
|
status: import("vue").Ref<import("./enums").FormStatus | undefined>;
|
|
1317
|
+
invalid: import("vue").ComputedRef<boolean>;
|
|
1316
1318
|
formData: import("vue").Ref<Partial<{
|
|
1317
1319
|
[x: string]: any;
|
|
1318
1320
|
} | undefined>>;
|
|
@@ -1949,6 +1951,7 @@ export declare const formFactory: <Schema extends FormSchema>(schema: Schema, op
|
|
|
1949
1951
|
formFieldInjectionKey: InjectionKey<InjectedFormFieldData<Schema>>;
|
|
1950
1952
|
errors: import("vue").Ref<import("zod").inferFormattedError<Schema, string> | undefined>;
|
|
1951
1953
|
status: import("vue").Ref<import("./enums").FormStatus | undefined>;
|
|
1954
|
+
invalid: import("vue").ComputedRef<boolean>;
|
|
1952
1955
|
formData: import("vue").Ref<Partial<import("zod").TypeOf<Schema> | undefined>>;
|
|
1953
1956
|
validate: (value?: Partial<import("zod").TypeOf<Schema> | undefined>) => Promise<boolean>;
|
|
1954
1957
|
submit: () => Promise<boolean>;
|
package/package.json
CHANGED
package/src/VvForm.ts
CHANGED
|
@@ -39,6 +39,7 @@ export const defineForm = <Schema extends FormSchema>(
|
|
|
39
39
|
) => {
|
|
40
40
|
const errors = ref<z.inferFormattedError<Schema> | undefined>()
|
|
41
41
|
const status = ref<FormStatus | undefined>()
|
|
42
|
+
const invalid = computed(() => status.value === FormStatus.invalid)
|
|
42
43
|
const formData = ref<Partial<z.infer<Schema> | undefined>>()
|
|
43
44
|
|
|
44
45
|
const validate = async (value = formData.value) => {
|
|
@@ -167,8 +168,6 @@ export const defineForm = <Schema extends FormSchema>(
|
|
|
167
168
|
}
|
|
168
169
|
})
|
|
169
170
|
|
|
170
|
-
const invalid = computed(() => status.value === FormStatus.invalid)
|
|
171
|
-
|
|
172
171
|
provide(provideKey, {
|
|
173
172
|
formData,
|
|
174
173
|
submit,
|
|
@@ -229,6 +228,7 @@ export const defineForm = <Schema extends FormSchema>(
|
|
|
229
228
|
return {
|
|
230
229
|
errors,
|
|
231
230
|
status,
|
|
231
|
+
invalid,
|
|
232
232
|
formData,
|
|
233
233
|
validate,
|
|
234
234
|
submit,
|
package/src/index.ts
CHANGED
|
@@ -52,6 +52,7 @@ const _formFactory = <Schema extends FormSchema>(
|
|
|
52
52
|
VvForm,
|
|
53
53
|
errors,
|
|
54
54
|
status,
|
|
55
|
+
invalid,
|
|
55
56
|
formData,
|
|
56
57
|
validate,
|
|
57
58
|
submit,
|
|
@@ -69,6 +70,7 @@ const _formFactory = <Schema extends FormSchema>(
|
|
|
69
70
|
formFieldInjectionKey,
|
|
70
71
|
errors,
|
|
71
72
|
status,
|
|
73
|
+
invalid,
|
|
72
74
|
formData,
|
|
73
75
|
validate,
|
|
74
76
|
submit,
|