@volverjs/form-vue 1.0.0-beta.7 → 1.0.0-beta.8

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 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, i, t) {
23
+ function L(e, s, t) {
24
24
  const o = de(t) ? t : void 0;
25
- if (!Q(e) || !X(i))
25
+ if (!Q(e) || !X(s))
26
26
  return o;
27
- const u = T(i);
27
+ const u = T(s);
28
28
  if (u.length !== 0) {
29
29
  for (const r of u) {
30
30
  if (r === "*")
31
31
  continue;
32
- const s = function(n) {
33
- return n.map((f) => G(f) || q(f) ? f : J(f) ? s(f) : f[r]);
32
+ const l = function(n) {
33
+ return n.map((i) => G(i) || q(i) ? i : J(i) ? l(i) : i[r]);
34
34
  };
35
- if (J(e) && !ve.test(r) ? e = s(e) : e = e[r], G(e) || q(e))
35
+ if (J(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 Y(e, i, t) {
42
- if (!Q(e) || !X(i))
41
+ function Y(e, s, t) {
42
+ if (!Q(e) || !X(s))
43
43
  return;
44
- const o = T(i);
44
+ const o = T(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 s = o[r];
49
+ const l = o[r];
50
50
  if (r === u - 1) {
51
- e[s] = t;
51
+ e[l] = t;
52
52
  return;
53
53
  }
54
- if (s === "*" && J(e)) {
54
+ if (l === "*" && J(e)) {
55
55
  const n = o.slice(r + 1).join(".");
56
- for (const f of e)
57
- Y(f, n, t);
56
+ for (const i of e)
57
+ Y(i, n, t);
58
58
  return;
59
59
  }
60
- G(e[s]) && (e[s] = {}), e = e[s];
60
+ G(e[l]) && (e[l] = {}), e = e[l];
61
61
  }
62
62
  }
63
63
  function T(e) {
64
- const i = e.split(/[.]|(?:\[(\d|\*)\])/).filter((t) => !!t);
65
- return i.some((t) => ce.indexOf(t) !== -1) ? [] : i;
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 || {}), k = /* @__PURE__ */ ((e) => (e.invalid = "invalid", e.valid = "valid", e.submitting = "submitting", e.updated = "updated", e.unknown = "unknown", e))(k || {});
68
- const me = (e, i, t, o) => z({
68
+ const me = (e, s, t, o) => z({
69
69
  name: "VvFormField",
70
70
  props: {
71
71
  type: {
@@ -104,7 +104,7 @@ const me = (e, i, t, o) => z({
104
104
  },
105
105
  emits: ["invalid", "valid", "update:formData", "update:modelValue"],
106
106
  expose: ["invalid", "invalidLabel", "errors"],
107
- setup(u, { slots: r, emit: s }) {
107
+ setup(u, { slots: r, emit: l }) {
108
108
  const n = w({
109
109
  get() {
110
110
  if (a != null && a.formData)
@@ -113,12 +113,12 @@ const me = (e, i, t, o) => z({
113
113
  String(u.name)
114
114
  );
115
115
  },
116
- set(l) {
116
+ set(f) {
117
117
  a != null && a.formData && (Y(
118
118
  Object(a.formData.value),
119
119
  String(u.name),
120
- l
121
- ), s("update:modelValue", {
120
+ f
121
+ ), l("update:modelValue", {
122
122
  newValue: n.value,
123
123
  formData: a == null ? void 0 : a.formData
124
124
  }));
@@ -129,46 +129,43 @@ const me = (e, i, t, o) => z({
129
129
  }), j(() => {
130
130
  h(), m();
131
131
  });
132
- const f = B(i, void 0);
133
- f && f.fields.value.add(u.name);
132
+ const i = B(s, void 0);
133
+ i && i.fields.value.add(u.name);
134
134
  const a = B(e), { props: c, name: b } = H(u), g = w(() => {
135
135
  if (a != null && a.errors.value)
136
136
  return L(a.errors.value, String(u.name));
137
137
  }), V = w(() => {
138
- var l;
139
- return (l = g.value) == null ? void 0 : l._errors;
138
+ var f;
139
+ return (f = g.value) == null ? void 0 : f._errors;
140
140
  }), v = w(() => g.value !== void 0), h = O(v, () => {
141
- v.value ? (s("invalid", V.value), f && f.errors.value.set(
141
+ v.value ? (l("invalid", V.value), i && i.errors.value.set(
142
142
  u.name,
143
143
  {
144
144
  _errors: V.value
145
145
  }
146
- )) : (s("valid", n.value), f && f.errors.value.delete(
146
+ )) : (l("valid", n.value), i && i.errors.value.delete(
147
147
  u.name
148
148
  ));
149
149
  }), m = O(
150
150
  () => a == null ? void 0 : a.formData,
151
151
  () => {
152
- s("update:formData", a == null ? void 0 : a.formData);
152
+ l("update:formData", a == null ? void 0 : a.formData);
153
153
  },
154
154
  { deep: !0 }
155
- ), y = (l) => {
156
- n.value = l;
155
+ ), y = (f) => {
156
+ n.value = f;
157
157
  }, x = w(() => {
158
- let l = c.value;
159
- return typeof l == "function" && (l = l(a == null ? void 0 : a.formData)), Object.keys(l).reduce(
160
- (_, W) => (_[W] = C(l[W]), _),
158
+ let f = c.value;
159
+ return typeof f == "function" && (f = f(a == null ? void 0 : a.formData)), Object.keys(f).reduce(
160
+ (_, W) => (_[W] = C(f[W]), _),
161
161
  {}
162
162
  );
163
- }), I = w(() => {
164
- const l = x.value.readonly ?? u.readonly;
165
- return l === void 0 ? a == null ? void 0 : a.readonly.value : l;
166
- }), U = w(() => ({
163
+ }), I = w(() => a != null && a.readonly.value ? !0 : x.value.readonly ?? u.readonly), U = w(() => ({
167
164
  ...x.value,
168
165
  name: x.value.name ?? u.name,
169
166
  invalid: v.value,
170
167
  valid: u.showValid ? !!(!v.value && n.value) : void 0,
171
- type: ((l) => {
168
+ type: ((f) => {
172
169
  if ([
173
170
  d.text,
174
171
  d.number,
@@ -183,8 +180,8 @@ const me = (e, i, t, o) => z({
183
180
  d.month,
184
181
  d.week,
185
182
  d.color
186
- ].includes(l))
187
- return l;
183
+ ].includes(f))
184
+ return f;
188
185
  })(u.type),
189
186
  invalidLabel: V.value,
190
187
  modelValue: n.value,
@@ -198,8 +195,8 @@ const me = (e, i, t, o) => z({
198
195
  if (u.type === d.custom)
199
196
  return {
200
197
  render() {
201
- var l;
202
- return ((l = r.default) == null ? void 0 : l.call(r, {
198
+ var f;
199
+ return ((f = r.default) == null ? void 0 : f.call(r, {
203
200
  modelValue: n.value,
204
201
  onUpdate: y,
205
202
  submit: a == null ? void 0 : a.submit,
@@ -214,36 +211,36 @@ const me = (e, i, t, o) => z({
214
211
  }
215
212
  };
216
213
  if (!((o == null ? void 0 : o.lazyLoad) ?? u.lazyLoad)) {
217
- let l;
214
+ let f;
218
215
  switch (u.type) {
219
216
  case d.select:
220
- l = S("VvSelect");
217
+ f = S("VvSelect");
221
218
  break;
222
219
  case d.checkbox:
223
- l = S("VvCheckbox");
220
+ f = S("VvCheckbox");
224
221
  break;
225
222
  case d.radio:
226
- l = S("VvRadio");
223
+ f = S("VvRadio");
227
224
  break;
228
225
  case d.textarea:
229
- l = S("VvTextarea");
226
+ f = S("VvTextarea");
230
227
  break;
231
228
  case d.radioGroup:
232
- l = S("VvRadioGroup");
229
+ f = S("VvRadioGroup");
233
230
  break;
234
231
  case d.checkboxGroup:
235
- l = S("VvCheckboxGroup");
232
+ f = S("VvCheckboxGroup");
236
233
  break;
237
234
  case d.combobox:
238
- l = S("VvCombobox");
235
+ f = S("VvCombobox");
239
236
  break;
240
237
  default:
241
- l = S("VvInputText");
238
+ f = S("VvInputText");
242
239
  }
243
- if (typeof l != "string")
244
- return l;
240
+ if (typeof f != "string")
241
+ return f;
245
242
  console.warn(
246
- `[form-vue warn]: ${l} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`
243
+ `[form-vue warn]: ${f} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`
247
244
  );
248
245
  }
249
246
  return F(async () => {
@@ -270,29 +267,29 @@ const me = (e, i, t, o) => z({
270
267
  render() {
271
268
  return this.is ? p(this.is, this.hasProps, this.$slots) : this.type === d.custom ? p(this.component, null, this.$slots) : p(this.component, this.hasProps, this.$slots);
272
269
  }
273
- }), K = (e, i = {}) => {
270
+ }), K = (e, s = {}) => {
274
271
  const t = (r) => {
275
- let s = r;
276
- for (; s instanceof fe; )
277
- s = s.innerType();
278
- return s instanceof oe && (s = s._def.innerType), s;
272
+ let l = r;
273
+ for (; l instanceof fe; )
274
+ l = l.innerType();
275
+ return l instanceof oe && (l = l._def.innerType), l;
279
276
  }, o = t(e);
280
277
  return {
281
- ...(o instanceof Z ? o._def.unknownKeys === "passthrough" : !1) ? i : {},
278
+ ...(o instanceof Z ? o._def.unknownKeys === "passthrough" : !1) ? s : {},
282
279
  ...Object.fromEntries(
283
280
  Object.entries(o.shape).map(
284
- ([r, s]) => {
285
- const n = i[r];
286
- let f = t(s), a;
287
- if (f instanceof ue && (a = f._def.defaultValue(), f = f._def.innerType), n === null && f instanceof le)
281
+ ([r, l]) => {
282
+ const n = s[r];
283
+ let i = t(l), a;
284
+ if (i instanceof ue && (a = i._def.defaultValue(), i = i._def.innerType), n === null && i instanceof le)
288
285
  return [r, n];
289
- if (f instanceof se) {
290
- const c = s.safeParse(n);
286
+ if (i instanceof se) {
287
+ const c = l.safeParse(n);
291
288
  if (c.success)
292
289
  return [r, c.data ?? a];
293
290
  }
294
- if (f instanceof ie && Array.isArray(n) && n.length) {
295
- const c = t(f._def.type);
291
+ if (i instanceof ie && Array.isArray(n) && n.length) {
292
+ const c = t(i._def.type);
296
293
  if (c instanceof Z)
297
294
  return [
298
295
  r,
@@ -304,10 +301,10 @@ const me = (e, i, t, o) => z({
304
301
  ) ?? a
305
302
  ];
306
303
  }
307
- return f instanceof Z ? [
304
+ return i instanceof Z ? [
308
305
  r,
309
306
  K(
310
- f,
307
+ i,
311
308
  n && typeof n == "object" ? n : a
312
309
  )
313
310
  ] : [r, a];
@@ -315,13 +312,13 @@ const me = (e, i, t, o) => z({
315
312
  )
316
313
  )
317
314
  };
318
- }, he = (e, i, t, o) => {
319
- const u = $(), r = $(), s = w(() => r.value === k.invalid), n = $(), f = $(!1), a = async (v = n.value) => {
320
- if (f.value)
315
+ }, he = (e, s, t, o) => {
316
+ const u = $(), r = $(), l = w(() => r.value === k.invalid), n = $(), i = $(!1), a = async (v = n.value) => {
317
+ if (i.value)
321
318
  return !0;
322
319
  const h = await e.safeParseAsync(v);
323
320
  return h.success ? (u.value = void 0, r.value = k.valid, n.value = h.data, !0) : (u.value = h.error.format(), r.value = k.invalid, !1);
324
- }, c = async () => f.value || !await a() ? !1 : (r.value = k.submitting, !0), { ignoreUpdates: b, stop: g } = ae(
321
+ }, c = async () => i.value || !await a() ? !1 : (r.value = k.submitting, !0), { ignoreUpdates: b, stop: g } = ae(
325
322
  n,
326
323
  () => {
327
324
  r.value = k.updated;
@@ -388,40 +385,40 @@ const me = (e, i, t, o) => z({
388
385
  ), O(r, async (m) => {
389
386
  var y, x, I, U, N;
390
387
  if (m === k.invalid) {
391
- const l = A(
388
+ const f = A(
392
389
  u.value
393
390
  );
394
- h("invalid", l), (y = t == null ? void 0 : t.onInvalid) == null || y.call(t, l);
391
+ h("invalid", f), (y = t == null ? void 0 : t.onInvalid) == null || y.call(t, f);
395
392
  return;
396
393
  }
397
394
  if (m === k.valid) {
398
- const l = A(n.value);
399
- h("valid", l), (x = t == null ? void 0 : t.onValid) == null || x.call(t, l), h("update:modelValue", l), (I = t == null ? void 0 : t.onUpdate) == null || I.call(t, l);
395
+ const f = A(n.value);
396
+ h("valid", f), (x = t == null ? void 0 : t.onValid) == null || x.call(t, f), h("update:modelValue", f), (I = t == null ? void 0 : t.onUpdate) == null || I.call(t, f);
400
397
  return;
401
398
  }
402
399
  if (m === k.submitting) {
403
- const l = A(n.value);
404
- h("submit", l), (U = t == null ? void 0 : t.onSubmit) == null || U.call(t, l);
400
+ const f = A(n.value);
401
+ h("submit", f), (U = t == null ? void 0 : t.onSubmit) == null || U.call(t, f);
405
402
  }
406
403
  if (m === k.updated) {
407
404
  if ((u.value || t != null && t.continuosValidation || v.continuosValidation) && await a(), !n.value || !v.modelValue || JSON.stringify(n.value) !== JSON.stringify(v.modelValue)) {
408
- const l = A(
405
+ const f = A(
409
406
  n.value
410
407
  );
411
- h("update:modelValue", l), (N = t == null ? void 0 : t.onUpdate) == null || N.call(t, l);
408
+ h("update:modelValue", f), (N = t == null ? void 0 : t.onUpdate) == null || N.call(t, f);
412
409
  }
413
410
  r.value === k.updated && (r.value = k.unknown);
414
411
  }
415
412
  }), P(() => {
416
- v.readonly && !f.value && (f.value = v.readonly);
413
+ v.readonly && !i.value && (i.value = v.readonly);
417
414
  }), O(
418
415
  () => v.readonly,
419
416
  (m) => {
420
- f.value = m;
417
+ i.value = m;
421
418
  }
422
- ), O(f, (m) => {
423
- m !== v.readonly && h("update:readonly", f.value);
424
- }), M(i, {
419
+ ), O(i, (m) => {
420
+ m !== v.readonly && h("update:readonly", i.value);
421
+ }), M(s, {
425
422
  formData: n,
426
423
  submit: c,
427
424
  validate: a,
@@ -429,8 +426,8 @@ const me = (e, i, t, o) => z({
429
426
  stopUpdatesWatch: g,
430
427
  errors: E(u),
431
428
  status: E(r),
432
- invalid: s,
433
- readonly: f
429
+ invalid: l,
430
+ readonly: i
434
431
  }), {
435
432
  formData: n,
436
433
  submit: c,
@@ -439,8 +436,8 @@ const me = (e, i, t, o) => z({
439
436
  stopUpdatesWatch: g,
440
437
  errors: E(u),
441
438
  status: E(r),
442
- invalid: s,
443
- isReadonly: f
439
+ invalid: l,
440
+ isReadonly: i
444
441
  };
445
442
  },
446
443
  render() {
@@ -482,8 +479,8 @@ const me = (e, i, t, o) => z({
482
479
  return {
483
480
  errors: u,
484
481
  status: r,
485
- invalid: s,
486
- readonly: f,
482
+ invalid: l,
483
+ readonly: i,
487
484
  formData: n,
488
485
  validate: a,
489
486
  submit: c,
@@ -494,7 +491,7 @@ const me = (e, i, t, o) => z({
494
491
  */
495
492
  VvForm: V
496
493
  };
497
- }, ye = (e, i) => z({
494
+ }, ye = (e, s) => z({
498
495
  name: "VvFormWrapper",
499
496
  props: {
500
497
  name: {
@@ -509,32 +506,32 @@ const me = (e, i, t, o) => z({
509
506
  emits: ["invalid", "valid"],
510
507
  expose: ["fields", "invalid"],
511
508
  setup(o, { emit: u }) {
512
- const r = B(e), s = B(i, void 0), n = $(/* @__PURE__ */ new Set()), f = $(/* @__PURE__ */ new Map()), { name: a } = H(o);
513
- M(i, {
509
+ const r = B(e), l = B(s, void 0), n = $(/* @__PURE__ */ new Set()), i = $(/* @__PURE__ */ new Map()), { name: a } = H(o);
510
+ M(s, {
514
511
  name: E(a),
515
- errors: f,
512
+ errors: i,
516
513
  fields: n
517
514
  }), O(
518
515
  n,
519
516
  (b) => {
520
- s != null && s.fields && b.forEach((g) => {
521
- s == null || s.fields.value.add(g);
517
+ l != null && l.fields && b.forEach((g) => {
518
+ l == null || l.fields.value.add(g);
522
519
  });
523
520
  },
524
521
  { deep: !0 }
525
522
  ), O(
526
- () => new Map(f.value),
523
+ () => new Map(i.value),
527
524
  (b, g) => {
528
- s != null && s.errors && (Array.from(g.keys()).forEach((V) => {
529
- s.errors.value.delete(V);
525
+ l != null && l.errors && (Array.from(g.keys()).forEach((V) => {
526
+ l.errors.value.delete(V);
530
527
  }), Array.from(b.keys()).forEach((V) => {
531
528
  const v = b.get(V);
532
- v && s.errors.value.set(V, v);
529
+ v && l.errors.value.set(V, v);
533
530
  }));
534
531
  },
535
532
  { deep: !0 }
536
533
  );
537
- const c = w(() => r != null && r.invalid.value ? f.value.size > 0 : !1);
534
+ const c = w(() => r != null && r.invalid.value ? i.value.size > 0 : !1);
538
535
  return O(c, () => {
539
536
  c.value ? u("invalid") : u("valid");
540
537
  }), {
@@ -544,15 +541,15 @@ const me = (e, i, t, o) => z({
544
541
  validate: r == null ? void 0 : r.validate,
545
542
  invalid: c,
546
543
  fields: n,
547
- fieldsErrors: f
544
+ fieldsErrors: i
548
545
  };
549
546
  },
550
547
  render() {
551
548
  var o, u;
552
549
  return this.tag ? p(this.tag, null, {
553
550
  default: () => {
554
- var r, s;
555
- return ((s = (r = this.$slots).default) == null ? void 0 : s.call(r, {
551
+ var r, l;
552
+ return ((l = (r = this.$slots).default) == null ? void 0 : l.call(r, {
556
553
  invalid: this.invalid,
557
554
  formData: this.formData,
558
555
  submit: this.submit,
@@ -570,7 +567,7 @@ const me = (e, i, t, o) => z({
570
567
  fieldsErrors: this.fieldsErrors
571
568
  })) ?? this.$slots.defalut;
572
569
  }
573
- }), be = (e, i) => {
570
+ }), be = (e, s) => {
574
571
  const t = z({
575
572
  name: "VvFormTemplate",
576
573
  props: {
@@ -584,9 +581,9 @@ const me = (e, i, t, o) => z({
584
581
  if (r != null && r.formData)
585
582
  return () => {
586
583
  var a;
587
- const s = typeof o.schema == "function" ? o.schema(r) : o.schema;
584
+ const l = typeof o.schema == "function" ? o.schema(r) : o.schema;
588
585
  let n;
589
- const f = s.reduce((c, b) => {
586
+ const i = l.reduce((c, b) => {
590
587
  const g = typeof b == "function" ? b(r) : b, {
591
588
  vvIs: V,
592
589
  vvName: v,
@@ -597,7 +594,7 @@ const me = (e, i, t, o) => z({
597
594
  vvType: I,
598
595
  vvDefaultValue: U,
599
596
  vvShowValid: N,
600
- vvContent: l,
597
+ vvContent: f,
601
598
  ..._
602
599
  } = g;
603
600
  if (y !== void 0) {
@@ -619,7 +616,7 @@ const me = (e, i, t, o) => z({
619
616
  }) : void 0;
620
617
  return v ? (c.push(
621
618
  p(
622
- i,
619
+ s,
623
620
  {
624
621
  name: v,
625
622
  is: V,
@@ -628,17 +625,17 @@ const me = (e, i, t, o) => z({
628
625
  showValid: N,
629
626
  props: _
630
627
  },
631
- h ?? W ?? l
628
+ h ?? W ?? f
632
629
  )
633
630
  ), c) : V ? (c.push(
634
631
  p(
635
632
  V,
636
633
  _,
637
- h ?? W ?? l
634
+ h ?? W ?? f
638
635
  )
639
636
  ), c) : (m && c.push(W), c);
640
637
  }, []);
641
- return f.push(
638
+ return i.push(
642
639
  (a = u == null ? void 0 : u.default) == null ? void 0 : a.call(u, {
643
640
  formData: r == null ? void 0 : r.formData.value,
644
641
  submit: r == null ? void 0 : r.submit,
@@ -647,22 +644,22 @@ const me = (e, i, t, o) => z({
647
644
  status: r == null ? void 0 : r.status.value,
648
645
  invalid: r == null ? void 0 : r.invalid.value
649
646
  })
650
- ), f;
647
+ ), i;
651
648
  };
652
649
  }
653
650
  });
654
651
  return t;
655
- }, R = (e, i = {}) => {
652
+ }, R = (e, s = {}) => {
656
653
  const t = Symbol(), o = Symbol(), u = Symbol(), r = ye(
657
654
  t,
658
655
  o
659
- ), s = me(
656
+ ), l = me(
660
657
  t,
661
658
  o,
662
659
  u,
663
- i
664
- ), n = be(t, s), {
665
- VvForm: f,
660
+ s
661
+ ), n = be(t, l), {
662
+ VvForm: i,
666
663
  errors: a,
667
664
  status: c,
668
665
  invalid: b,
@@ -672,11 +669,11 @@ const me = (e, i, t, o) => z({
672
669
  submit: h,
673
670
  ignoreUpdates: m,
674
671
  stopUpdatesWatch: y
675
- } = he(e, t, i, n);
672
+ } = he(e, t, s, n);
676
673
  return {
677
- VvForm: f,
674
+ VvForm: i,
678
675
  VvFormWrapper: r,
679
- VvFormField: s,
676
+ VvFormField: l,
680
677
  VvFormTemplate: n,
681
678
  formInjectionKey: t,
682
679
  formWrapperInjectionKey: o,
@@ -692,20 +689,20 @@ const me = (e, i, t, o) => z({
692
689
  stopUpdatesWatch: y
693
690
  };
694
691
  }, D = Symbol(), ke = (e) => {
695
- let i = {};
696
- return e.schema && (i = R(e.schema, e)), {
697
- ...i,
692
+ let s = {};
693
+ return e.schema && (s = R(e.schema, e)), {
694
+ ...s,
698
695
  install(t, { global: o = !1 } = {}) {
699
- t.provide(D, 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));
696
+ t.provide(D, 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));
700
697
  }
701
698
  };
702
- }, we = (e, i = {}) => te() ? R(
699
+ }, we = (e, s = {}) => te() ? R(
703
700
  e,
704
701
  {
705
702
  ...B(D, {}),
706
- ...i
703
+ ...s
707
704
  }
708
- ) : R(e, i), Oe = (e, i = {}) => R(e, i);
705
+ ) : R(e, s), Oe = (e, s = {}) => R(e, s);
709
706
  export {
710
707
  d as FormFieldType,
711
708
  ke as createForm,
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(w,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("@vueuse/core"),require("zod")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","zod"],e):(w=typeof globalThis<"u"?globalThis:w||self,e(w["@volverjs/form-vue"]={},w.Vue,w.VueUseCore,w.zod))})(this,function(w,e,$,k){"use strict";function N(r){return Array.isArray(r)}function J(r){return typeof r<"u"}function G(r){return r===null}function L(r){return typeof r=="object"}function Z(r){return typeof r=="string"}function A(r){return typeof r>"u"}const M=/^[0-9]+$/,P=["__proto__","prototype","constructor"];function E(r,o,a){const d=J(a)?a:void 0;if(!L(r)||!Z(o))return d;const i=q(o);if(i.length!==0){for(const t of i){if(t==="*")continue;const u=function(l){return l.map(f=>A(f)||G(f)?f:N(f)?u(f):f[t])};if(N(r)&&!M.test(t)?r=u(r):r=r[t],A(r)||G(r))break}return A(r)?d:r}}function K(r,o,a){if(!L(r)||!Z(o))return;const d=q(o);if(d.length===0)return;const i=d.length;for(let t=0;t<i;t++){const u=d[t];if(t===i-1){r[u]=a;return}if(u==="*"&&N(r)){const l=d.slice(t+1).join(".");for(const f of r)K(f,l,a);return}A(r[u])&&(r[u]={}),r=r[u]}}function q(r){const o=r.split(/[.]|(?:\[(\d|\*)\])/).filter(a=>!!a);return o.some(a=>P.indexOf(a)!==-1)?[]:o}var c=(r=>(r.text="text",r.number="number",r.email="email",r.password="password",r.tel="tel",r.url="url",r.search="search",r.date="date",r.time="time",r.datetimeLocal="datetime-local",r.month="month",r.week="week",r.color="color",r.select="select",r.checkbox="checkbox",r.radio="radio",r.textarea="textarea",r.radioGroup="radioGroup",r.checkboxGroup="checkboxGroup",r.combobox="combobox",r.custom="custom",r))(c||{}),O=(r=>(r.invalid="invalid",r.valid="valid",r.submitting="submitting",r.updated="updated",r.unknown="unknown",r))(O||{});const z=(r,o,a,d)=>e.defineComponent({name:"VvFormField",props:{type:{type:String,validator:i=>Object.values(c).includes(i),default:c.custom},is:{type:[Object,String],default:void 0},name:{type:[String,Number,Boolean,Symbol],required:!0},props:{type:[Object,Function],default:()=>({})},showValid:{type:Boolean,default:!1},defaultValue:{type:[String,Number,Boolean,Array,Object],default:void 0},lazyLoad:{type:Boolean,default:!1},readonly:{type:Boolean,default:void 0}},emits:["invalid","valid","update:formData","update:modelValue"],expose:["invalid","invalidLabel","errors"],setup(i,{slots:t,emit:u}){const l=e.computed({get(){if(n!=null&&n.formData)return E(Object(n.formData.value),String(i.name))},set(s){n!=null&&n.formData&&(K(Object(n.formData.value),String(i.name),s),u("update:modelValue",{newValue:l.value,formData:n==null?void 0:n.formData}))}});e.onMounted(()=>{l.value===void 0&&i.defaultValue!==void 0&&(l.value=i.defaultValue)}),e.onBeforeUnmount(()=>{y(),h()});const f=e.inject(o,void 0);f&&f.fields.value.add(i.name);const n=e.inject(r),{props:m,name:V}=e.toRefs(i),p=e.computed(()=>{if(n!=null&&n.errors.value)return E(n.errors.value,String(i.name))}),g=e.computed(()=>{var s;return(s=p.value)==null?void 0:s._errors}),v=e.computed(()=>p.value!==void 0),y=e.watch(v,()=>{v.value?(u("invalid",g.value),f&&f.errors.value.set(i.name,{_errors:g.value})):(u("valid",l.value),f&&f.errors.value.delete(i.name))}),h=e.watch(()=>n==null?void 0:n.formData,()=>{u("update:formData",n==null?void 0:n.formData)},{deep:!0}),b=s=>{l.value=s},x=e.computed(()=>{let s=m.value;return typeof s=="function"&&(s=s(n==null?void 0:n.formData)),Object.keys(s).reduce((U,I)=>(U[I]=e.unref(s[I]),U),{})}),S=e.computed(()=>{const s=x.value.readonly??i.readonly;return s===void 0?n==null?void 0:n.readonly.value:s}),C=e.computed(()=>({...x.value,name:x.value.name??i.name,invalid:v.value,valid:i.showValid?!!(!v.value&&l.value):void 0,type:(s=>{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(s))return s})(i.type),invalidLabel:g.value,modelValue:l.value,readonly:S.value,"onUpdate:modelValue":b}));return e.provide(a,{name:e.readonly(V),errors:e.readonly(p)}),{component:e.computed(()=>{if(i.type===c.custom)return{render(){var s;return((s=t.default)==null?void 0:s.call(t,{modelValue:l.value,onUpdate:b,submit:n==null?void 0:n.submit,validate:n==null?void 0:n.validate,invalid:v.value,invalidLabel:g.value,formData:n==null?void 0:n.formData.value,formErrors:n==null?void 0:n.errors.value,errors:p.value,readonly:S.value}))??t.defalut}};if(!((d==null?void 0:d.lazyLoad)??i.lazyLoad)){let s;switch(i.type){case c.select:s=e.resolveComponent("VvSelect");break;case c.checkbox:s=e.resolveComponent("VvCheckbox");break;case c.radio:s=e.resolveComponent("VvRadio");break;case c.textarea:s=e.resolveComponent("VvTextarea");break;case c.radioGroup:s=e.resolveComponent("VvRadioGroup");break;case c.checkboxGroup:s=e.resolveComponent("VvCheckboxGroup");break;case c.combobox:s=e.resolveComponent("VvCombobox");break;default:s=e.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 e.defineAsyncComponent(async()=>{switch(d!=null&&d.sideEffects&&await Promise.resolve(d.sideEffects(i.type)),i.type){case c.textarea:return import("@volverjs/ui-vue/vv-textarea");case c.radio:return import("@volverjs/ui-vue/vv-radio");case c.radioGroup:return import("@volverjs/ui-vue/vv-radio-group");case c.checkbox:return import("@volverjs/ui-vue/vv-checkbox");case c.checkboxGroup:return import("@volverjs/ui-vue/vv-checkbox-group");case c.select:return import("@volverjs/ui-vue/vv-select");case c.combobox:return import("@volverjs/ui-vue/vv-combobox")}return import("@volverjs/ui-vue/vv-input-text")})}),hasProps:C,invalid:v}},render(){return this.is?e.h(this.is,this.hasProps,this.$slots):this.type===c.custom?e.h(this.component,null,this.$slots):e.h(this.component,this.hasProps,this.$slots)}}),W=(r,o={})=>{const a=t=>{let u=t;for(;u instanceof k.ZodEffects;)u=u.innerType();return u instanceof k.ZodOptional&&(u=u._def.innerType),u},d=a(r);return{...(d instanceof k.ZodObject?d._def.unknownKeys==="passthrough":!1)?o:{},...Object.fromEntries(Object.entries(d.shape).map(([t,u])=>{const l=o[t];let f=a(u),n;if(f instanceof k.ZodDefault&&(n=f._def.defaultValue(),f=f._def.innerType),l===null&&f instanceof k.ZodNullable)return[t,l];if(f instanceof k.ZodSchema){const m=u.safeParse(l);if(m.success)return[t,m.data??n]}if(f instanceof k.ZodArray&&Array.isArray(l)&&l.length){const m=a(f._def.type);if(m instanceof k.ZodObject)return[t,l.map(V=>W(m,V&&typeof V=="object"?V:void 0))??n]}return f instanceof k.ZodObject?[t,W(f,l&&typeof l=="object"?l:n)]:[t,n]}))}},T=(r,o,a,d)=>{const i=e.ref(),t=e.ref(),u=e.computed(()=>t.value===O.invalid),l=e.ref(),f=e.ref(!1),n=async(v=l.value)=>{if(f.value)return!0;const y=await r.safeParseAsync(v);return y.success?(i.value=void 0,t.value=O.valid,l.value=y.data,!0):(i.value=y.error.format(),t.value=O.invalid,!1)},m=async()=>f.value||!await n()?!1:(t.value=O.submitting,!0),{ignoreUpdates:V,stop:p}=$.watchIgnorable(l,()=>{t.value=O.updated},{deep:!0,eventFilter:$.throttleFilter((a==null?void 0:a.updateThrottle)??500)}),g=e.defineComponent({name:"VvForm",props:{continuosValidation:{type:Boolean,default:!1},modelValue:{type:Object,default:()=>({})},readonly:{type:Boolean,default:(a==null?void 0:a.readonly)??!1},tag:{type:String,default:"form"},template:{type:[Array,Function],default:void 0}},emits:["invalid","valid","submit","update:modelValue","update:readonly"],expose:["submit","validate","errors","status","valid","invalid","readonly"],setup(v,{emit:y}){return l.value=W(r,e.toRaw(v.modelValue)),e.watch(()=>v.modelValue,h=>{if(h){const b=e.isProxy(h)?e.toRaw(h):h;if(JSON.stringify(b)===JSON.stringify(e.toRaw(l.value)))return;l.value=typeof(b==null?void 0:b.clone)=="function"?b.clone():JSON.parse(JSON.stringify(b))}},{deep:!0}),e.watch(t,async h=>{var b,x,S,C,R;if(h===O.invalid){const s=e.toRaw(i.value);y("invalid",s),(b=a==null?void 0:a.onInvalid)==null||b.call(a,s);return}if(h===O.valid){const s=e.toRaw(l.value);y("valid",s),(x=a==null?void 0:a.onValid)==null||x.call(a,s),y("update:modelValue",s),(S=a==null?void 0:a.onUpdate)==null||S.call(a,s);return}if(h===O.submitting){const s=e.toRaw(l.value);y("submit",s),(C=a==null?void 0:a.onSubmit)==null||C.call(a,s)}if(h===O.updated){if((i.value||a!=null&&a.continuosValidation||v.continuosValidation)&&await n(),!l.value||!v.modelValue||JSON.stringify(l.value)!==JSON.stringify(v.modelValue)){const s=e.toRaw(l.value);y("update:modelValue",s),(R=a==null?void 0:a.onUpdate)==null||R.call(a,s)}t.value===O.updated&&(t.value=O.unknown)}}),e.onMounted(()=>{v.readonly&&!f.value&&(f.value=v.readonly)}),e.watch(()=>v.readonly,h=>{f.value=h}),e.watch(f,h=>{h!==v.readonly&&y("update:readonly",f.value)}),e.provide(o,{formData:l,submit:m,validate:n,ignoreUpdates:V,stopUpdatesWatch:p,errors:e.readonly(i),status:e.readonly(t),invalid:u,readonly:f}),{formData:l,submit:m,validate:n,ignoreUpdates:V,stopUpdatesWatch:p,errors:e.readonly(i),status:e.readonly(t),invalid:u,isReadonly:f}},render(){const v=()=>{var y,h;return((h=(y=this.$slots)==null?void 0:y.default)==null?void 0:h.call(y,{formData:this.formData,submit:this.submit,validate:this.validate,ignoreUpdates:this.ignoreUpdates,stopUpdatesWatch:this.stopUpdatesWatch,errors:this.errors,status:this.status,invalid:this.invalid,readonly:this.isReadonly}))??this.$slots.default};return e.h(this.tag,{onSubmit:e.withModifiers(this.submit,["prevent"])},(this.template??(a==null?void 0:a.template))&&d?[e.h(d,{schema:this.template??(a==null?void 0:a.template)},{default:v})]:{default:v})}});return{errors:i,status:t,invalid:u,readonly:f,formData:l,validate:n,submit:m,ignoreUpdates:V,stopUpdatesWatch:p,VvForm:g}},H=(r,o)=>e.defineComponent({name:"VvFormWrapper",props:{name:{type:String,required:!0},tag:{type:String,default:void 0}},emits:["invalid","valid"],expose:["fields","invalid"],setup(d,{emit:i}){const t=e.inject(r),u=e.inject(o,void 0),l=e.ref(new Set),f=e.ref(new Map),{name:n}=e.toRefs(d);e.provide(o,{name:e.readonly(n),errors:f,fields:l}),e.watch(l,V=>{u!=null&&u.fields&&V.forEach(p=>{u==null||u.fields.value.add(p)})},{deep:!0}),e.watch(()=>new Map(f.value),(V,p)=>{u!=null&&u.errors&&(Array.from(p.keys()).forEach(g=>{u.errors.value.delete(g)}),Array.from(V.keys()).forEach(g=>{const v=V.get(g);v&&u.errors.value.set(g,v)}))},{deep:!0});const m=e.computed(()=>t!=null&&t.invalid.value?f.value.size>0:!1);return e.watch(m,()=>{m.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:m,fields:l,fieldsErrors:f}},render(){var d,i;return this.tag?e.h(this.tag,null,{default:()=>{var t,u;return((u=(t=this.$slots).default)==null?void 0:u.call(t,{invalid:this.invalid,formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}):((i=(d=this.$slots).default)==null?void 0:i.call(d,{invalid:this.invalid,formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}),Q=(r,o)=>{const a=e.defineComponent({name:"VvFormTemplate",props:{schema:{type:[Array,Function],required:!0}},setup(d,{slots:i}){const t=e.inject(r);if(t!=null&&t.formData)return()=>{var n;const u=typeof d.schema=="function"?d.schema(t):d.schema;let l;const f=u.reduce((m,V)=>{const p=typeof V=="function"?V(t):V,{vvIs:g,vvName:v,vvSlots:y,vvChildren:h,vvIf:b,vvElseIf:x,vvType:S,vvDefaultValue:C,vvShowValid:R,vvContent:s,...U}=p;if(b!==void 0){if(typeof b=="string"?l=!!E(Object(t.formData.value),b):typeof b=="function"?l=e.unref(b(t)):l=e.unref(b),!l)return m}else if(x!==void 0&&l!==void 0){if(l||(typeof x=="string"?l=!!E(Object(t.formData.value),x):typeof x=="function"?l=e.unref(x(t)):l=e.unref(x),!l))return m}else l=void 0;const I=h?e.h(a,{schema:h}):void 0;return v?(m.push(e.h(o,{name:v,is:g,type:S,defaultValue:C,showValid:R,props:U},y??I??s)),m):g?(m.push(e.h(g,U,y??I??s)),m):(h&&m.push(I),m)},[]);return f.push((n=i==null?void 0:i.default)==null?void 0:n.call(i,{formData:t==null?void 0:t.formData.value,submit:t==null?void 0:t.submit,validate:t==null?void 0:t.validate,errors:t==null?void 0:t.errors.value,status:t==null?void 0:t.status.value,invalid:t==null?void 0:t.invalid.value})),f}}});return a},B=(r,o={})=>{const a=Symbol(),d=Symbol(),i=Symbol(),t=H(a,d),u=z(a,d,i,o),l=Q(a,u),{VvForm:f,errors:n,status:m,invalid:V,readonly:p,formData:g,validate:v,submit:y,ignoreUpdates:h,stopUpdatesWatch:b}=T(r,a,o,l);return{VvForm:f,VvFormWrapper:t,VvFormField:u,VvFormTemplate:l,formInjectionKey:a,formWrapperInjectionKey:d,formFieldInjectionKey:i,errors:n,status:m,invalid:V,readonly:p,formData:g,validate:v,submit:y,ignoreUpdates:h,stopUpdatesWatch:b}},_=Symbol(),X=r=>{let o={};return r.schema&&(o=B(r.schema,r)),{...o,install(a,{global:d=!1}={}){a.provide(_,r),d&&(a.config.globalProperties.$vvForm=r,o!=null&&o.VvForm&&a.component("VvForm",o.VvForm),o!=null&&o.VvFormWrapper&&a.component("VvFormWrapper",o.VvFormWrapper),o!=null&&o.VvFormField&&a.component("VvFormField",o.VvFormField),o!=null&&o.VvFormTemplate&&a.component("VvFormTemplate",o.VvFormTemplate))}}},Y=(r,o={})=>e.getCurrentInstance()?B(r,{...e.inject(_,{}),...o}):B(r,o),D=(r,o={})=>B(r,o);w.FormFieldType=c,w.createForm=X,w.defaultObjectBySchema=W,w.formFactory=D,w.pluginInjectionKey=_,w.useForm=Y,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});
1
+ (function(w,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("@vueuse/core"),require("zod")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","zod"],e):(w=typeof globalThis<"u"?globalThis:w||self,e(w["@volverjs/form-vue"]={},w.Vue,w.VueUseCore,w.zod))})(this,function(w,e,$,k){"use strict";function N(r){return Array.isArray(r)}function J(r){return typeof r<"u"}function G(r){return r===null}function L(r){return typeof r=="object"}function Z(r){return typeof r=="string"}function A(r){return typeof r>"u"}const M=/^[0-9]+$/,P=["__proto__","prototype","constructor"];function E(r,u,a){const d=J(a)?a:void 0;if(!L(r)||!Z(u))return d;const i=q(u);if(i.length!==0){for(const t of i){if(t==="*")continue;const s=function(l){return l.map(o=>A(o)||G(o)?o:N(o)?s(o):o[t])};if(N(r)&&!M.test(t)?r=s(r):r=r[t],A(r)||G(r))break}return A(r)?d:r}}function K(r,u,a){if(!L(r)||!Z(u))return;const d=q(u);if(d.length===0)return;const i=d.length;for(let t=0;t<i;t++){const s=d[t];if(t===i-1){r[s]=a;return}if(s==="*"&&N(r)){const l=d.slice(t+1).join(".");for(const o of r)K(o,l,a);return}A(r[s])&&(r[s]={}),r=r[s]}}function q(r){const u=r.split(/[.]|(?:\[(\d|\*)\])/).filter(a=>!!a);return u.some(a=>P.indexOf(a)!==-1)?[]:u}var c=(r=>(r.text="text",r.number="number",r.email="email",r.password="password",r.tel="tel",r.url="url",r.search="search",r.date="date",r.time="time",r.datetimeLocal="datetime-local",r.month="month",r.week="week",r.color="color",r.select="select",r.checkbox="checkbox",r.radio="radio",r.textarea="textarea",r.radioGroup="radioGroup",r.checkboxGroup="checkboxGroup",r.combobox="combobox",r.custom="custom",r))(c||{}),O=(r=>(r.invalid="invalid",r.valid="valid",r.submitting="submitting",r.updated="updated",r.unknown="unknown",r))(O||{});const z=(r,u,a,d)=>e.defineComponent({name:"VvFormField",props:{type:{type:String,validator:i=>Object.values(c).includes(i),default:c.custom},is:{type:[Object,String],default:void 0},name:{type:[String,Number,Boolean,Symbol],required:!0},props:{type:[Object,Function],default:()=>({})},showValid:{type:Boolean,default:!1},defaultValue:{type:[String,Number,Boolean,Array,Object],default:void 0},lazyLoad:{type:Boolean,default:!1},readonly:{type:Boolean,default:void 0}},emits:["invalid","valid","update:formData","update:modelValue"],expose:["invalid","invalidLabel","errors"],setup(i,{slots:t,emit:s}){const l=e.computed({get(){if(n!=null&&n.formData)return E(Object(n.formData.value),String(i.name))},set(f){n!=null&&n.formData&&(K(Object(n.formData.value),String(i.name),f),s("update:modelValue",{newValue:l.value,formData:n==null?void 0:n.formData}))}});e.onMounted(()=>{l.value===void 0&&i.defaultValue!==void 0&&(l.value=i.defaultValue)}),e.onBeforeUnmount(()=>{y(),h()});const o=e.inject(u,void 0);o&&o.fields.value.add(i.name);const n=e.inject(r),{props:m,name:V}=e.toRefs(i),p=e.computed(()=>{if(n!=null&&n.errors.value)return E(n.errors.value,String(i.name))}),g=e.computed(()=>{var f;return(f=p.value)==null?void 0:f._errors}),v=e.computed(()=>p.value!==void 0),y=e.watch(v,()=>{v.value?(s("invalid",g.value),o&&o.errors.value.set(i.name,{_errors:g.value})):(s("valid",l.value),o&&o.errors.value.delete(i.name))}),h=e.watch(()=>n==null?void 0:n.formData,()=>{s("update:formData",n==null?void 0:n.formData)},{deep:!0}),b=f=>{l.value=f},x=e.computed(()=>{let f=m.value;return typeof f=="function"&&(f=f(n==null?void 0:n.formData)),Object.keys(f).reduce((U,I)=>(U[I]=e.unref(f[I]),U),{})}),S=e.computed(()=>n!=null&&n.readonly.value?!0:x.value.readonly??i.readonly),C=e.computed(()=>({...x.value,name:x.value.name??i.name,invalid:v.value,valid:i.showValid?!!(!v.value&&l.value):void 0,type:(f=>{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(f))return f})(i.type),invalidLabel:g.value,modelValue:l.value,readonly:S.value,"onUpdate:modelValue":b}));return e.provide(a,{name:e.readonly(V),errors:e.readonly(p)}),{component:e.computed(()=>{if(i.type===c.custom)return{render(){var f;return((f=t.default)==null?void 0:f.call(t,{modelValue:l.value,onUpdate:b,submit:n==null?void 0:n.submit,validate:n==null?void 0:n.validate,invalid:v.value,invalidLabel:g.value,formData:n==null?void 0:n.formData.value,formErrors:n==null?void 0:n.errors.value,errors:p.value,readonly:S.value}))??t.defalut}};if(!((d==null?void 0:d.lazyLoad)??i.lazyLoad)){let f;switch(i.type){case c.select:f=e.resolveComponent("VvSelect");break;case c.checkbox:f=e.resolveComponent("VvCheckbox");break;case c.radio:f=e.resolveComponent("VvRadio");break;case c.textarea:f=e.resolveComponent("VvTextarea");break;case c.radioGroup:f=e.resolveComponent("VvRadioGroup");break;case c.checkboxGroup:f=e.resolveComponent("VvCheckboxGroup");break;case c.combobox:f=e.resolveComponent("VvCombobox");break;default:f=e.resolveComponent("VvInputText")}if(typeof f!="string")return f;console.warn(`[form-vue warn]: ${f} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`)}return e.defineAsyncComponent(async()=>{switch(d!=null&&d.sideEffects&&await Promise.resolve(d.sideEffects(i.type)),i.type){case c.textarea:return import("@volverjs/ui-vue/vv-textarea");case c.radio:return import("@volverjs/ui-vue/vv-radio");case c.radioGroup:return import("@volverjs/ui-vue/vv-radio-group");case c.checkbox:return import("@volverjs/ui-vue/vv-checkbox");case c.checkboxGroup:return import("@volverjs/ui-vue/vv-checkbox-group");case c.select:return import("@volverjs/ui-vue/vv-select");case c.combobox:return import("@volverjs/ui-vue/vv-combobox")}return import("@volverjs/ui-vue/vv-input-text")})}),hasProps:C,invalid:v}},render(){return this.is?e.h(this.is,this.hasProps,this.$slots):this.type===c.custom?e.h(this.component,null,this.$slots):e.h(this.component,this.hasProps,this.$slots)}}),W=(r,u={})=>{const a=t=>{let s=t;for(;s instanceof k.ZodEffects;)s=s.innerType();return s instanceof k.ZodOptional&&(s=s._def.innerType),s},d=a(r);return{...(d instanceof k.ZodObject?d._def.unknownKeys==="passthrough":!1)?u:{},...Object.fromEntries(Object.entries(d.shape).map(([t,s])=>{const l=u[t];let o=a(s),n;if(o instanceof k.ZodDefault&&(n=o._def.defaultValue(),o=o._def.innerType),l===null&&o instanceof k.ZodNullable)return[t,l];if(o instanceof k.ZodSchema){const m=s.safeParse(l);if(m.success)return[t,m.data??n]}if(o instanceof k.ZodArray&&Array.isArray(l)&&l.length){const m=a(o._def.type);if(m instanceof k.ZodObject)return[t,l.map(V=>W(m,V&&typeof V=="object"?V:void 0))??n]}return o instanceof k.ZodObject?[t,W(o,l&&typeof l=="object"?l:n)]:[t,n]}))}},T=(r,u,a,d)=>{const i=e.ref(),t=e.ref(),s=e.computed(()=>t.value===O.invalid),l=e.ref(),o=e.ref(!1),n=async(v=l.value)=>{if(o.value)return!0;const y=await r.safeParseAsync(v);return y.success?(i.value=void 0,t.value=O.valid,l.value=y.data,!0):(i.value=y.error.format(),t.value=O.invalid,!1)},m=async()=>o.value||!await n()?!1:(t.value=O.submitting,!0),{ignoreUpdates:V,stop:p}=$.watchIgnorable(l,()=>{t.value=O.updated},{deep:!0,eventFilter:$.throttleFilter((a==null?void 0:a.updateThrottle)??500)}),g=e.defineComponent({name:"VvForm",props:{continuosValidation:{type:Boolean,default:!1},modelValue:{type:Object,default:()=>({})},readonly:{type:Boolean,default:(a==null?void 0:a.readonly)??!1},tag:{type:String,default:"form"},template:{type:[Array,Function],default:void 0}},emits:["invalid","valid","submit","update:modelValue","update:readonly"],expose:["submit","validate","errors","status","valid","invalid","readonly"],setup(v,{emit:y}){return l.value=W(r,e.toRaw(v.modelValue)),e.watch(()=>v.modelValue,h=>{if(h){const b=e.isProxy(h)?e.toRaw(h):h;if(JSON.stringify(b)===JSON.stringify(e.toRaw(l.value)))return;l.value=typeof(b==null?void 0:b.clone)=="function"?b.clone():JSON.parse(JSON.stringify(b))}},{deep:!0}),e.watch(t,async h=>{var b,x,S,C,R;if(h===O.invalid){const f=e.toRaw(i.value);y("invalid",f),(b=a==null?void 0:a.onInvalid)==null||b.call(a,f);return}if(h===O.valid){const f=e.toRaw(l.value);y("valid",f),(x=a==null?void 0:a.onValid)==null||x.call(a,f),y("update:modelValue",f),(S=a==null?void 0:a.onUpdate)==null||S.call(a,f);return}if(h===O.submitting){const f=e.toRaw(l.value);y("submit",f),(C=a==null?void 0:a.onSubmit)==null||C.call(a,f)}if(h===O.updated){if((i.value||a!=null&&a.continuosValidation||v.continuosValidation)&&await n(),!l.value||!v.modelValue||JSON.stringify(l.value)!==JSON.stringify(v.modelValue)){const f=e.toRaw(l.value);y("update:modelValue",f),(R=a==null?void 0:a.onUpdate)==null||R.call(a,f)}t.value===O.updated&&(t.value=O.unknown)}}),e.onMounted(()=>{v.readonly&&!o.value&&(o.value=v.readonly)}),e.watch(()=>v.readonly,h=>{o.value=h}),e.watch(o,h=>{h!==v.readonly&&y("update:readonly",o.value)}),e.provide(u,{formData:l,submit:m,validate:n,ignoreUpdates:V,stopUpdatesWatch:p,errors:e.readonly(i),status:e.readonly(t),invalid:s,readonly:o}),{formData:l,submit:m,validate:n,ignoreUpdates:V,stopUpdatesWatch:p,errors:e.readonly(i),status:e.readonly(t),invalid:s,isReadonly:o}},render(){const v=()=>{var y,h;return((h=(y=this.$slots)==null?void 0:y.default)==null?void 0:h.call(y,{formData:this.formData,submit:this.submit,validate:this.validate,ignoreUpdates:this.ignoreUpdates,stopUpdatesWatch:this.stopUpdatesWatch,errors:this.errors,status:this.status,invalid:this.invalid,readonly:this.isReadonly}))??this.$slots.default};return e.h(this.tag,{onSubmit:e.withModifiers(this.submit,["prevent"])},(this.template??(a==null?void 0:a.template))&&d?[e.h(d,{schema:this.template??(a==null?void 0:a.template)},{default:v})]:{default:v})}});return{errors:i,status:t,invalid:s,readonly:o,formData:l,validate:n,submit:m,ignoreUpdates:V,stopUpdatesWatch:p,VvForm:g}},H=(r,u)=>e.defineComponent({name:"VvFormWrapper",props:{name:{type:String,required:!0},tag:{type:String,default:void 0}},emits:["invalid","valid"],expose:["fields","invalid"],setup(d,{emit:i}){const t=e.inject(r),s=e.inject(u,void 0),l=e.ref(new Set),o=e.ref(new Map),{name:n}=e.toRefs(d);e.provide(u,{name:e.readonly(n),errors:o,fields:l}),e.watch(l,V=>{s!=null&&s.fields&&V.forEach(p=>{s==null||s.fields.value.add(p)})},{deep:!0}),e.watch(()=>new Map(o.value),(V,p)=>{s!=null&&s.errors&&(Array.from(p.keys()).forEach(g=>{s.errors.value.delete(g)}),Array.from(V.keys()).forEach(g=>{const v=V.get(g);v&&s.errors.value.set(g,v)}))},{deep:!0});const m=e.computed(()=>t!=null&&t.invalid.value?o.value.size>0:!1);return e.watch(m,()=>{m.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:m,fields:l,fieldsErrors:o}},render(){var d,i;return this.tag?e.h(this.tag,null,{default:()=>{var t,s;return((s=(t=this.$slots).default)==null?void 0:s.call(t,{invalid:this.invalid,formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}):((i=(d=this.$slots).default)==null?void 0:i.call(d,{invalid:this.invalid,formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}),Q=(r,u)=>{const a=e.defineComponent({name:"VvFormTemplate",props:{schema:{type:[Array,Function],required:!0}},setup(d,{slots:i}){const t=e.inject(r);if(t!=null&&t.formData)return()=>{var n;const s=typeof d.schema=="function"?d.schema(t):d.schema;let l;const o=s.reduce((m,V)=>{const p=typeof V=="function"?V(t):V,{vvIs:g,vvName:v,vvSlots:y,vvChildren:h,vvIf:b,vvElseIf:x,vvType:S,vvDefaultValue:C,vvShowValid:R,vvContent:f,...U}=p;if(b!==void 0){if(typeof b=="string"?l=!!E(Object(t.formData.value),b):typeof b=="function"?l=e.unref(b(t)):l=e.unref(b),!l)return m}else if(x!==void 0&&l!==void 0){if(l||(typeof x=="string"?l=!!E(Object(t.formData.value),x):typeof x=="function"?l=e.unref(x(t)):l=e.unref(x),!l))return m}else l=void 0;const I=h?e.h(a,{schema:h}):void 0;return v?(m.push(e.h(u,{name:v,is:g,type:S,defaultValue:C,showValid:R,props:U},y??I??f)),m):g?(m.push(e.h(g,U,y??I??f)),m):(h&&m.push(I),m)},[]);return o.push((n=i==null?void 0:i.default)==null?void 0:n.call(i,{formData:t==null?void 0:t.formData.value,submit:t==null?void 0:t.submit,validate:t==null?void 0:t.validate,errors:t==null?void 0:t.errors.value,status:t==null?void 0:t.status.value,invalid:t==null?void 0:t.invalid.value})),o}}});return a},B=(r,u={})=>{const a=Symbol(),d=Symbol(),i=Symbol(),t=H(a,d),s=z(a,d,i,u),l=Q(a,s),{VvForm:o,errors:n,status:m,invalid:V,readonly:p,formData:g,validate:v,submit:y,ignoreUpdates:h,stopUpdatesWatch:b}=T(r,a,u,l);return{VvForm:o,VvFormWrapper:t,VvFormField:s,VvFormTemplate:l,formInjectionKey:a,formWrapperInjectionKey:d,formFieldInjectionKey:i,errors:n,status:m,invalid:V,readonly:p,formData:g,validate:v,submit:y,ignoreUpdates:h,stopUpdatesWatch:b}},_=Symbol(),X=r=>{let u={};return r.schema&&(u=B(r.schema,r)),{...u,install(a,{global:d=!1}={}){a.provide(_,r),d&&(a.config.globalProperties.$vvForm=r,u!=null&&u.VvForm&&a.component("VvForm",u.VvForm),u!=null&&u.VvFormWrapper&&a.component("VvFormWrapper",u.VvFormWrapper),u!=null&&u.VvFormField&&a.component("VvFormField",u.VvFormField),u!=null&&u.VvFormTemplate&&a.component("VvFormTemplate",u.VvFormTemplate))}}},Y=(r,u={})=>e.getCurrentInstance()?B(r,{...e.inject(_,{}),...u}):B(r,u),D=(r,u={})=>B(r,u);w.FormFieldType=c,w.createForm=X,w.defaultObjectBySchema=W,w.formFactory=D,w.pluginInjectionKey=_,w.useForm=Y,Object.defineProperty(w,Symbol.toStringTag,{value:"Module"})});