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

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 24/Consulting
3
+ Copyright (c) 2024 8 Wave
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -10,11 +10,11 @@
10
10
 
11
11
  <br>
12
12
 
13
- #### proudly powered by
13
+ maintained with ❤️ by
14
14
 
15
15
  <br>
16
16
 
17
- [![24/Consulting](docs/static/24consulting.svg)](https://24consulting.it)
17
+ [![8 Wave](docs/static/8wave.svg)](https://8wave.it)
18
18
 
19
19
  <br>
20
20
 
package/dist/index.es.js CHANGED
@@ -1,4 +1,4 @@
1
- import { defineComponent as z, computed as w, onMounted as P, onBeforeUnmount as j, inject as B, toRefs as H, watch as O, unref as C, provide as M, readonly as E, resolveComponent as S, defineAsyncComponent as F, h as p, ref as $, toRaw as A, isProxy as ee, withModifiers as re, getCurrentInstance as te } from "vue";
1
+ import { defineComponent as z, computed as w, onMounted as P, onBeforeUnmount as j, inject as B, toRefs as H, watch as p, unref as C, provide as M, readonly as E, resolveComponent as S, defineAsyncComponent as F, h as O, ref as $, toRaw as A, isProxy as ee, withModifiers as re, getCurrentInstance as te } from "vue";
2
2
  import { watchIgnorable as ae, throttleFilter as ne } from "@vueuse/core";
3
3
  import { ZodObject as Z, ZodDefault as ue, ZodNullable as le, ZodSchema as se, ZodArray as ie, ZodEffects as fe, ZodOptional as oe } from "zod";
4
4
  function J(e) {
@@ -30,7 +30,7 @@ function L(e, s, t) {
30
30
  if (r === "*")
31
31
  continue;
32
32
  const l = function(n) {
33
- return n.map((i) => G(i) || q(i) ? i : J(i) ? l(i) : i[r]);
33
+ return n.map((f) => G(f) || q(f) ? f : J(f) ? l(f) : f[r]);
34
34
  };
35
35
  if (J(e) && !ve.test(r) ? e = l(e) : e = e[r], G(e) || q(e))
36
36
  break;
@@ -53,8 +53,8 @@ function Y(e, s, t) {
53
53
  }
54
54
  if (l === "*" && J(e)) {
55
55
  const n = o.slice(r + 1).join(".");
56
- for (const i of e)
57
- Y(i, n, t);
56
+ for (const f of e)
57
+ Y(f, n, t);
58
58
  return;
59
59
  }
60
60
  G(e[l]) && (e[l] = {}), e = e[l];
@@ -113,11 +113,11 @@ const me = (e, s, t, o) => z({
113
113
  String(u.name)
114
114
  );
115
115
  },
116
- set(f) {
116
+ set(i) {
117
117
  a != null && a.formData && (Y(
118
118
  Object(a.formData.value),
119
119
  String(u.name),
120
- f
120
+ i
121
121
  ), l("update:modelValue", {
122
122
  newValue: n.value,
123
123
  formData: a == null ? void 0 : a.formData
@@ -129,43 +129,43 @@ const me = (e, s, t, o) => z({
129
129
  }), j(() => {
130
130
  h(), m();
131
131
  });
132
- const i = B(s, void 0);
133
- i && i.fields.value.add(u.name);
134
- const a = B(e), { props: c, name: b } = H(u), g = w(() => {
132
+ const f = B(s, void 0);
133
+ f && f.fields.value.add(u.name);
134
+ const a = B(e), { props: v, 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 f;
139
- return (f = g.value) == null ? void 0 : f._errors;
140
- }), v = w(() => g.value !== void 0), h = O(v, () => {
141
- v.value ? (l("invalid", V.value), i && i.errors.value.set(
138
+ var i;
139
+ return (i = g.value) == null ? void 0 : i._errors;
140
+ }), c = w(() => g.value !== void 0), h = p(c, () => {
141
+ c.value ? (l("invalid", V.value), f && f.errors.value.set(
142
142
  u.name,
143
143
  {
144
144
  _errors: V.value
145
145
  }
146
- )) : (l("valid", n.value), i && i.errors.value.delete(
146
+ )) : (l("valid", n.value), f && f.errors.value.delete(
147
147
  u.name
148
148
  ));
149
- }), m = O(
149
+ }), m = p(
150
150
  () => a == null ? void 0 : a.formData,
151
151
  () => {
152
152
  l("update:formData", a == null ? void 0 : a.formData);
153
153
  },
154
154
  { deep: !0 }
155
- ), y = (f) => {
156
- n.value = f;
155
+ ), y = (i) => {
156
+ n.value = i;
157
157
  }, x = 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]), _),
158
+ let i = v.value;
159
+ return typeof i == "function" && (i = i(a == null ? void 0 : a.formData)), Object.keys(i).reduce(
160
+ (_, W) => (_[W] = C(i[W]), _),
161
161
  {}
162
162
  );
163
163
  }), I = w(() => a != null && a.readonly.value ? !0 : x.value.readonly ?? u.readonly), U = w(() => ({
164
164
  ...x.value,
165
165
  name: x.value.name ?? u.name,
166
- invalid: v.value,
167
- valid: u.showValid ? !!(!v.value && n.value) : void 0,
168
- type: ((f) => {
166
+ invalid: c.value,
167
+ valid: u.showValid ? !!(!c.value && n.value) : void 0,
168
+ type: ((i) => {
169
169
  if ([
170
170
  d.text,
171
171
  d.number,
@@ -180,8 +180,8 @@ const me = (e, s, t, o) => z({
180
180
  d.month,
181
181
  d.week,
182
182
  d.color
183
- ].includes(f))
184
- return f;
183
+ ].includes(i))
184
+ return i;
185
185
  })(u.type),
186
186
  invalidLabel: V.value,
187
187
  modelValue: n.value,
@@ -195,13 +195,13 @@ const me = (e, s, t, o) => z({
195
195
  if (u.type === d.custom)
196
196
  return {
197
197
  render() {
198
- var f;
199
- return ((f = r.default) == null ? void 0 : f.call(r, {
198
+ var i;
199
+ return ((i = r.default) == null ? void 0 : i.call(r, {
200
200
  modelValue: n.value,
201
201
  onUpdate: y,
202
202
  submit: a == null ? void 0 : a.submit,
203
203
  validate: a == null ? void 0 : a.validate,
204
- invalid: v.value,
204
+ invalid: c.value,
205
205
  invalidLabel: V.value,
206
206
  formData: a == null ? void 0 : a.formData.value,
207
207
  formErrors: a == null ? void 0 : a.errors.value,
@@ -211,36 +211,36 @@ const me = (e, s, t, o) => z({
211
211
  }
212
212
  };
213
213
  if (!((o == null ? void 0 : o.lazyLoad) ?? u.lazyLoad)) {
214
- let f;
214
+ let i;
215
215
  switch (u.type) {
216
216
  case d.select:
217
- f = S("VvSelect");
217
+ i = S("VvSelect");
218
218
  break;
219
219
  case d.checkbox:
220
- f = S("VvCheckbox");
220
+ i = S("VvCheckbox");
221
221
  break;
222
222
  case d.radio:
223
- f = S("VvRadio");
223
+ i = S("VvRadio");
224
224
  break;
225
225
  case d.textarea:
226
- f = S("VvTextarea");
226
+ i = S("VvTextarea");
227
227
  break;
228
228
  case d.radioGroup:
229
- f = S("VvRadioGroup");
229
+ i = S("VvRadioGroup");
230
230
  break;
231
231
  case d.checkboxGroup:
232
- f = S("VvCheckboxGroup");
232
+ i = S("VvCheckboxGroup");
233
233
  break;
234
234
  case d.combobox:
235
- f = S("VvCombobox");
235
+ i = S("VvCombobox");
236
236
  break;
237
237
  default:
238
- f = S("VvInputText");
238
+ i = S("VvInputText");
239
239
  }
240
- if (typeof f != "string")
241
- return f;
240
+ if (typeof i != "string")
241
+ return i;
242
242
  console.warn(
243
- `[form-vue warn]: ${f} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`
243
+ `[form-vue warn]: ${i} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`
244
244
  );
245
245
  }
246
246
  return F(async () => {
@@ -262,10 +262,10 @@ const me = (e, s, t, o) => z({
262
262
  }
263
263
  return import("@volverjs/ui-vue/vv-input-text");
264
264
  });
265
- }), hasProps: U, invalid: v };
265
+ }), hasProps: U, invalid: c };
266
266
  },
267
267
  render() {
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);
268
+ return this.is ? O(this.is, this.hasProps, this.$slots) : this.type === d.custom ? O(this.component, null, this.$slots) : O(this.component, this.hasProps, this.$slots);
269
269
  }
270
270
  }), K = (e, s = {}) => {
271
271
  const t = (r) => {
@@ -280,31 +280,31 @@ const me = (e, s, t, o) => z({
280
280
  Object.entries(o.shape).map(
281
281
  ([r, l]) => {
282
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)
283
+ let f = t(l), a;
284
+ if (f instanceof ue && (a = f._def.defaultValue(), f = f._def.innerType), n === null && f instanceof le)
285
285
  return [r, n];
286
- if (i instanceof se) {
287
- const c = l.safeParse(n);
288
- if (c.success)
289
- return [r, c.data ?? a];
286
+ if (f instanceof se) {
287
+ const v = l.safeParse(n);
288
+ if (v.success)
289
+ return [r, v.data ?? a];
290
290
  }
291
- if (i instanceof ie && Array.isArray(n) && n.length) {
292
- const c = t(i._def.type);
293
- if (c instanceof Z)
291
+ if (f instanceof ie && Array.isArray(n) && n.length) {
292
+ const v = t(f._def.type);
293
+ if (v instanceof Z)
294
294
  return [
295
295
  r,
296
296
  n.map(
297
297
  (b) => K(
298
- c,
298
+ v,
299
299
  b && typeof b == "object" ? b : void 0
300
300
  )
301
301
  ) ?? a
302
302
  ];
303
303
  }
304
- return i instanceof Z ? [
304
+ return f instanceof Z ? [
305
305
  r,
306
306
  K(
307
- i,
307
+ f,
308
308
  n && typeof n == "object" ? n : a
309
309
  )
310
310
  ] : [r, a];
@@ -313,12 +313,12 @@ const me = (e, s, t, o) => z({
313
313
  )
314
314
  };
315
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)
316
+ const u = $(), r = $(), l = w(() => r.value === k.invalid), n = $(), f = $(!1), a = async (c = n.value) => {
317
+ if (f.value)
318
318
  return !0;
319
- const h = await e.safeParseAsync(v);
319
+ const h = await e.safeParseAsync(c);
320
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);
321
- }, c = async () => i.value || !await a() ? !1 : (r.value = k.submitting, !0), { ignoreUpdates: b, stop: g } = ae(
321
+ }, v = async () => f.value || !await a() ? !1 : (r.value = k.submitting, !0), { ignoreUpdates: b, stop: g } = ae(
322
322
  n,
323
323
  () => {
324
324
  r.value = k.updated;
@@ -367,12 +367,12 @@ const me = (e, s, t, o) => z({
367
367
  "invalid",
368
368
  "readonly"
369
369
  ],
370
- setup(v, { emit: h }) {
370
+ setup(c, { emit: h }) {
371
371
  return n.value = K(
372
372
  e,
373
- A(v.modelValue)
374
- ), O(
375
- () => v.modelValue,
373
+ A(c.modelValue)
374
+ ), p(
375
+ () => c.modelValue,
376
376
  (m) => {
377
377
  if (m) {
378
378
  const y = ee(m) ? A(m) : m;
@@ -382,66 +382,66 @@ const me = (e, s, t, o) => z({
382
382
  }
383
383
  },
384
384
  { deep: !0 }
385
- ), O(r, async (m) => {
385
+ ), p(r, async (m) => {
386
386
  var y, x, I, U, N;
387
387
  if (m === k.invalid) {
388
- const f = A(
388
+ const i = A(
389
389
  u.value
390
390
  );
391
- h("invalid", f), (y = t == null ? void 0 : t.onInvalid) == null || y.call(t, f);
391
+ h("invalid", i), (y = t == null ? void 0 : t.onInvalid) == null || y.call(t, i);
392
392
  return;
393
393
  }
394
394
  if (m === k.valid) {
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);
395
+ const i = A(n.value);
396
+ h("valid", i), (x = t == null ? void 0 : t.onValid) == null || x.call(t, i), h("update:modelValue", i), (I = t == null ? void 0 : t.onUpdate) == null || I.call(t, i);
397
397
  return;
398
398
  }
399
399
  if (m === k.submitting) {
400
- const f = A(n.value);
401
- h("submit", f), (U = t == null ? void 0 : t.onSubmit) == null || U.call(t, f);
400
+ const i = A(n.value);
401
+ h("submit", i), (U = t == null ? void 0 : t.onSubmit) == null || U.call(t, i);
402
402
  }
403
403
  if (m === k.updated) {
404
- if ((u.value || t != null && t.continuosValidation || v.continuosValidation) && await a(), !n.value || !v.modelValue || JSON.stringify(n.value) !== JSON.stringify(v.modelValue)) {
405
- const f = A(
404
+ if ((u.value || t != null && t.continuosValidation || c.continuosValidation) && await a(), !n.value || !c.modelValue || JSON.stringify(n.value) !== JSON.stringify(c.modelValue)) {
405
+ const i = A(
406
406
  n.value
407
407
  );
408
- h("update:modelValue", f), (N = t == null ? void 0 : t.onUpdate) == null || N.call(t, f);
408
+ h("update:modelValue", i), (N = t == null ? void 0 : t.onUpdate) == null || N.call(t, i);
409
409
  }
410
410
  r.value === k.updated && (r.value = k.unknown);
411
411
  }
412
412
  }), P(() => {
413
- v.readonly && !i.value && (i.value = v.readonly);
414
- }), O(
415
- () => v.readonly,
413
+ f.value = c.readonly;
414
+ }), p(
415
+ () => c.readonly,
416
416
  (m) => {
417
- i.value = m;
417
+ f.value = m;
418
418
  }
419
- ), O(i, (m) => {
420
- m !== v.readonly && h("update:readonly", i.value);
419
+ ), p(f, (m) => {
420
+ m !== c.readonly && h("update:readonly", f.value);
421
421
  }), M(s, {
422
422
  formData: n,
423
- submit: c,
423
+ submit: v,
424
424
  validate: a,
425
425
  ignoreUpdates: b,
426
426
  stopUpdatesWatch: g,
427
427
  errors: E(u),
428
428
  status: E(r),
429
429
  invalid: l,
430
- readonly: i
430
+ readonly: f
431
431
  }), {
432
432
  formData: n,
433
- submit: c,
433
+ submit: v,
434
434
  validate: a,
435
435
  ignoreUpdates: b,
436
436
  stopUpdatesWatch: g,
437
437
  errors: E(u),
438
438
  status: E(r),
439
439
  invalid: l,
440
- isReadonly: i
440
+ isReadonly: f
441
441
  };
442
442
  },
443
443
  render() {
444
- const v = () => {
444
+ const c = () => {
445
445
  var h, m;
446
446
  return ((m = (h = this.$slots) == null ? void 0 : h.default) == null ? void 0 : m.call(h, {
447
447
  formData: this.formData,
@@ -455,23 +455,23 @@ const me = (e, s, t, o) => z({
455
455
  readonly: this.isReadonly
456
456
  })) ?? this.$slots.default;
457
457
  };
458
- return p(
458
+ return O(
459
459
  this.tag,
460
460
  {
461
461
  onSubmit: re(this.submit, ["prevent"])
462
462
  },
463
463
  (this.template ?? (t == null ? void 0 : t.template)) && o ? [
464
- p(
464
+ O(
465
465
  o,
466
466
  {
467
467
  schema: this.template ?? (t == null ? void 0 : t.template)
468
468
  },
469
469
  {
470
- default: v
470
+ default: c
471
471
  }
472
472
  )
473
473
  ] : {
474
- default: v
474
+ default: c
475
475
  }
476
476
  );
477
477
  }
@@ -480,10 +480,10 @@ const me = (e, s, t, o) => z({
480
480
  errors: u,
481
481
  status: r,
482
482
  invalid: l,
483
- readonly: i,
483
+ readonly: f,
484
484
  formData: n,
485
485
  validate: a,
486
- submit: c,
486
+ submit: v,
487
487
  ignoreUpdates: b,
488
488
  stopUpdatesWatch: g,
489
489
  /**
@@ -506,12 +506,12 @@ const me = (e, s, t, o) => z({
506
506
  emits: ["invalid", "valid"],
507
507
  expose: ["fields", "invalid"],
508
508
  setup(o, { emit: u }) {
509
- const r = B(e), l = B(s, void 0), n = $(/* @__PURE__ */ new Set()), i = $(/* @__PURE__ */ new Map()), { name: a } = H(o);
509
+ const r = B(e), l = B(s, void 0), n = $(/* @__PURE__ */ new Set()), f = $(/* @__PURE__ */ new Map()), { name: a } = H(o);
510
510
  M(s, {
511
511
  name: E(a),
512
- errors: i,
512
+ errors: f,
513
513
  fields: n
514
- }), O(
514
+ }), p(
515
515
  n,
516
516
  (b) => {
517
517
  l != null && l.fields && b.forEach((g) => {
@@ -519,34 +519,34 @@ const me = (e, s, t, o) => z({
519
519
  });
520
520
  },
521
521
  { deep: !0 }
522
- ), O(
523
- () => new Map(i.value),
522
+ ), p(
523
+ () => new Map(f.value),
524
524
  (b, g) => {
525
525
  l != null && l.errors && (Array.from(g.keys()).forEach((V) => {
526
526
  l.errors.value.delete(V);
527
527
  }), Array.from(b.keys()).forEach((V) => {
528
- const v = b.get(V);
529
- v && l.errors.value.set(V, v);
528
+ const c = b.get(V);
529
+ c && l.errors.value.set(V, c);
530
530
  }));
531
531
  },
532
532
  { deep: !0 }
533
533
  );
534
- const c = w(() => r != null && r.invalid.value ? i.value.size > 0 : !1);
535
- return O(c, () => {
536
- c.value ? u("invalid") : u("valid");
534
+ const v = w(() => r != null && r.invalid.value ? f.value.size > 0 : !1);
535
+ return p(v, () => {
536
+ v.value ? u("invalid") : u("valid");
537
537
  }), {
538
538
  formData: r == null ? void 0 : r.formData,
539
539
  errors: r == null ? void 0 : r.errors,
540
540
  submit: r == null ? void 0 : r.submit,
541
541
  validate: r == null ? void 0 : r.validate,
542
- invalid: c,
542
+ invalid: v,
543
543
  fields: n,
544
- fieldsErrors: i
544
+ fieldsErrors: f
545
545
  };
546
546
  },
547
547
  render() {
548
548
  var o, u;
549
- return this.tag ? p(this.tag, null, {
549
+ return this.tag ? O(this.tag, null, {
550
550
  default: () => {
551
551
  var r, l;
552
552
  return ((l = (r = this.$slots).default) == null ? void 0 : l.call(r, {
@@ -583,10 +583,10 @@ const me = (e, s, t, o) => z({
583
583
  var a;
584
584
  const l = typeof o.schema == "function" ? o.schema(r) : o.schema;
585
585
  let n;
586
- const i = l.reduce((c, b) => {
586
+ const f = l.reduce((v, b) => {
587
587
  const g = typeof b == "function" ? b(r) : b, {
588
588
  vvIs: V,
589
- vvName: v,
589
+ vvName: c,
590
590
  vvSlots: h,
591
591
  vvChildren: m,
592
592
  vvIf: y,
@@ -594,7 +594,7 @@ const me = (e, s, t, o) => z({
594
594
  vvType: I,
595
595
  vvDefaultValue: U,
596
596
  vvShowValid: N,
597
- vvContent: f,
597
+ vvContent: i,
598
598
  ..._
599
599
  } = g;
600
600
  if (y !== void 0) {
@@ -602,40 +602,40 @@ const me = (e, s, t, o) => z({
602
602
  Object(r.formData.value),
603
603
  y
604
604
  ) : typeof y == "function" ? n = C(y(r)) : n = C(y), !n)
605
- return c;
605
+ return v;
606
606
  } else if (x !== void 0 && n !== void 0) {
607
607
  if (n || (typeof x == "string" ? n = !!L(
608
608
  Object(r.formData.value),
609
609
  x
610
610
  ) : typeof x == "function" ? n = C(x(r)) : n = C(x), !n))
611
- return c;
611
+ return v;
612
612
  } else
613
613
  n = void 0;
614
- const W = m ? p(t, {
614
+ const W = m ? O(t, {
615
615
  schema: m
616
616
  }) : void 0;
617
- return v ? (c.push(
618
- p(
617
+ return c ? (v.push(
618
+ O(
619
619
  s,
620
620
  {
621
- name: v,
621
+ name: c,
622
622
  is: V,
623
623
  type: I,
624
624
  defaultValue: U,
625
625
  showValid: N,
626
626
  props: _
627
627
  },
628
- h ?? W ?? f
628
+ h ?? W ?? i
629
629
  )
630
- ), c) : V ? (c.push(
631
- p(
630
+ ), v) : V ? (v.push(
631
+ O(
632
632
  V,
633
633
  _,
634
- h ?? W ?? f
634
+ h ?? W ?? i
635
635
  )
636
- ), c) : (m && c.push(W), c);
636
+ ), v) : (m && v.push(W), v);
637
637
  }, []);
638
- return i.push(
638
+ return f.push(
639
639
  (a = u == null ? void 0 : u.default) == null ? void 0 : a.call(u, {
640
640
  formData: r == null ? void 0 : r.formData.value,
641
641
  submit: r == null ? void 0 : r.submit,
@@ -644,7 +644,7 @@ const me = (e, s, t, o) => z({
644
644
  status: r == null ? void 0 : r.status.value,
645
645
  invalid: r == null ? void 0 : r.invalid.value
646
646
  })
647
- ), i;
647
+ ), f;
648
648
  };
649
649
  }
650
650
  });
@@ -659,19 +659,19 @@ const me = (e, s, t, o) => z({
659
659
  u,
660
660
  s
661
661
  ), n = be(t, l), {
662
- VvForm: i,
662
+ VvForm: f,
663
663
  errors: a,
664
- status: c,
664
+ status: v,
665
665
  invalid: b,
666
666
  readonly: g,
667
667
  formData: V,
668
- validate: v,
668
+ validate: c,
669
669
  submit: h,
670
670
  ignoreUpdates: m,
671
671
  stopUpdatesWatch: y
672
672
  } = he(e, t, s, n);
673
673
  return {
674
- VvForm: i,
674
+ VvForm: f,
675
675
  VvFormWrapper: r,
676
676
  VvFormField: l,
677
677
  VvFormTemplate: n,
@@ -679,11 +679,11 @@ const me = (e, s, t, o) => z({
679
679
  formWrapperInjectionKey: o,
680
680
  formFieldInjectionKey: u,
681
681
  errors: a,
682
- status: c,
682
+ status: v,
683
683
  invalid: b,
684
684
  readonly: g,
685
685
  formData: V,
686
- validate: v,
686
+ validate: c,
687
687
  submit: h,
688
688
  ignoreUpdates: m,
689
689
  stopUpdatesWatch: y
@@ -702,12 +702,12 @@ const me = (e, s, t, o) => z({
702
702
  ...B(D, {}),
703
703
  ...s
704
704
  }
705
- ) : R(e, s), Oe = (e, s = {}) => R(e, s);
705
+ ) : R(e, s), pe = (e, s = {}) => R(e, s);
706
706
  export {
707
707
  d as FormFieldType,
708
708
  ke as createForm,
709
709
  K as defaultObjectBySchema,
710
- Oe as formFactory,
710
+ pe as formFactory,
711
711
  D as pluginInjectionKey,
712
712
  we as useForm
713
713
  };
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,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"})});
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(f=>A(f)||G(f)?f:N(f)?s(f):f[t])};if(N(r)&&!M.test(t)?r=s(r):r=r[t],A(r)||G(r))break}return A(r)?d:r}}function K(r,u,a){if(!L(r)||!Z(u))return;const d=q(u);if(d.length===0)return;const i=d.length;for(let t=0;t<i;t++){const s=d[t];if(t===i-1){r[s]=a;return}if(s==="*"&&N(r)){const l=d.slice(t+1).join(".");for(const f of r)K(f,l,a);return}A(r[s])&&(r[s]={}),r=r[s]}}function q(r){const u=r.split(/[.]|(?:\[(\d|\*)\])/).filter(a=>!!a);return u.some(a=>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(o){n!=null&&n.formData&&(K(Object(n.formData.value),String(i.name),o),s("update:modelValue",{newValue:l.value,formData:n==null?void 0:n.formData}))}});e.onMounted(()=>{l.value===void 0&&i.defaultValue!==void 0&&(l.value=i.defaultValue)}),e.onBeforeUnmount(()=>{y(),h()});const f=e.inject(u,void 0);f&&f.fields.value.add(i.name);const n=e.inject(r),{props: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 o;return(o=p.value)==null?void 0:o._errors}),v=e.computed(()=>p.value!==void 0),y=e.watch(v,()=>{v.value?(s("invalid",g.value),f&&f.errors.value.set(i.name,{_errors:g.value})):(s("valid",l.value),f&&f.errors.value.delete(i.name))}),h=e.watch(()=>n==null?void 0:n.formData,()=>{s("update:formData",n==null?void 0:n.formData)},{deep:!0}),b=o=>{l.value=o},x=e.computed(()=>{let o=m.value;return typeof o=="function"&&(o=o(n==null?void 0:n.formData)),Object.keys(o).reduce((U,I)=>(U[I]=e.unref(o[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:(o=>{if([c.text,c.number,c.email,c.password,c.tel,c.url,c.search,c.date,c.time,c.datetimeLocal,c.month,c.week,c.color].includes(o))return o})(i.type),invalidLabel:g.value,modelValue:l.value,readonly:S.value,"onUpdate:modelValue":b}));return e.provide(a,{name:e.readonly(V),errors:e.readonly(p)}),{component:e.computed(()=>{if(i.type===c.custom)return{render(){var o;return((o=t.default)==null?void 0:o.call(t,{modelValue:l.value,onUpdate:b,submit:n==null?void 0:n.submit,validate:n==null?void 0:n.validate,invalid: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 o;switch(i.type){case c.select:o=e.resolveComponent("VvSelect");break;case c.checkbox:o=e.resolveComponent("VvCheckbox");break;case c.radio:o=e.resolveComponent("VvRadio");break;case c.textarea:o=e.resolveComponent("VvTextarea");break;case c.radioGroup:o=e.resolveComponent("VvRadioGroup");break;case c.checkboxGroup:o=e.resolveComponent("VvCheckboxGroup");break;case c.combobox:o=e.resolveComponent("VvCombobox");break;default:o=e.resolveComponent("VvInputText")}if(typeof o!="string")return o;console.warn(`[form-vue warn]: ${o} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`)}return e.defineAsyncComponent(async()=>{switch(d!=null&&d.sideEffects&&await Promise.resolve(d.sideEffects(i.type)),i.type){case c.textarea:return import("@volverjs/ui-vue/vv-textarea");case c.radio:return import("@volverjs/ui-vue/vv-radio");case c.radioGroup:return import("@volverjs/ui-vue/vv-radio-group");case c.checkbox:return import("@volverjs/ui-vue/vv-checkbox");case c.checkboxGroup:return import("@volverjs/ui-vue/vv-checkbox-group");case c.select:return import("@volverjs/ui-vue/vv-select");case c.combobox:return import("@volverjs/ui-vue/vv-combobox")}return import("@volverjs/ui-vue/vv-input-text")})}),hasProps: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 f=a(s),n;if(f instanceof k.ZodDefault&&(n=f._def.defaultValue(),f=f._def.innerType),l===null&&f instanceof k.ZodNullable)return[t,l];if(f instanceof k.ZodSchema){const m=s.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,u,a,d)=>{const i=e.ref(),t=e.ref(),s=e.computed(()=>t.value===O.invalid),l=e.ref(),f=e.ref(!1),n=async(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 o=e.toRaw(i.value);y("invalid",o),(b=a==null?void 0:a.onInvalid)==null||b.call(a,o);return}if(h===O.valid){const o=e.toRaw(l.value);y("valid",o),(x=a==null?void 0:a.onValid)==null||x.call(a,o),y("update:modelValue",o),(S=a==null?void 0:a.onUpdate)==null||S.call(a,o);return}if(h===O.submitting){const o=e.toRaw(l.value);y("submit",o),(C=a==null?void 0:a.onSubmit)==null||C.call(a,o)}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 o=e.toRaw(l.value);y("update:modelValue",o),(R=a==null?void 0:a.onUpdate)==null||R.call(a,o)}t.value===O.updated&&(t.value=O.unknown)}}),e.onMounted(()=>{f.value=v.readonly}),e.watch(()=>v.readonly,h=>{f.value=h}),e.watch(f,h=>{h!==v.readonly&&y("update:readonly",f.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:f}),{formData:l,submit:m,validate:n,ignoreUpdates:V,stopUpdatesWatch:p,errors:e.readonly(i),status:e.readonly(t),invalid:s,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:s,readonly:f,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),f=e.ref(new Map),{name:n}=e.toRefs(d);e.provide(u,{name:e.readonly(n),errors:f,fields:l}),e.watch(l,V=>{s!=null&&s.fields&&V.forEach(p=>{s==null||s.fields.value.add(p)})},{deep:!0}),e.watch(()=>new Map(f.value),(V,p)=>{s!=null&&s.errors&&(Array.from(p.keys()).forEach(g=>{s.errors.value.delete(g)}),Array.from(V.keys()).forEach(g=>{const v=V.get(g);v&&s.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,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 f=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:o,...U}=p;if(b!==void 0){if(typeof b=="string"?l=!!E(Object(t.formData.value),b):typeof b=="function"?l=e.unref(b(t)):l=e.unref(b),!l)return 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??o)),m):g?(m.push(e.h(g,U,y??I??o)),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,u={})=>{const a=Symbol(),d=Symbol(),i=Symbol(),t=H(a,d),s=z(a,d,i,u),l=Q(a,s),{VvForm:f,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:f,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"})});
@@ -3,7 +3,7 @@ import { type IgnoredUpdater } from '@vueuse/core';
3
3
  import { type z, type TypeOf } from 'zod';
4
4
  import type { FormComponentOptions, FormSchema, FormTemplate, InjectedFormData } from './types';
5
5
  import { FormStatus } from './enums';
6
- export declare const defineForm: <Schema extends FormSchema>(schema: Schema, provideKey: InjectionKey<InjectedFormData<Schema>>, options?: FormComponentOptions<Schema> | undefined, VvFormTemplate?: Component) => {
6
+ export declare const defineForm: <Schema extends FormSchema>(schema: Schema, provideKey: InjectionKey<InjectedFormData<Schema>>, options?: FormComponentOptions<Schema>, VvFormTemplate?: Component) => {
7
7
  errors: Ref<z.inferFormattedError<Schema, string> | undefined>;
8
8
  status: Ref<FormStatus | undefined>;
9
9
  invalid: import("vue").ComputedRef<boolean>;
@@ -187,12 +187,12 @@ export declare const defineForm: <Schema extends FormSchema>(schema: Schema, pro
187
187
  }, {}, string, {}> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & (new () => {
188
188
  $slots: {
189
189
  default: (_: {
190
- formData: unknown extends Partial<z.TypeOf<Schema>> | undefined ? undefined : Partial<z.TypeOf<Schema>> | undefined;
190
+ formData: unknown extends Partial<TypeOf<Schema>> | undefined ? undefined : Partial<TypeOf<Schema>> | undefined;
191
191
  submit: () => Promise<boolean>;
192
192
  validate: () => Promise<boolean>;
193
193
  ignoreUpdates: IgnoredUpdater;
194
194
  stopUpdatesWatch: WatchStopHandle;
195
- errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema, string>>>>;
195
+ errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema>>>>;
196
196
  status: Ref<DeepReadonly<`${FormStatus}` | undefined>>;
197
197
  invalid: Ref<DeepReadonly<boolean>>;
198
198
  readonly: Ref<boolean>;
@@ -17,7 +17,7 @@ export declare const defineFormField: <Schema extends FormSchema>(formProvideKey
17
17
  required: true;
18
18
  };
19
19
  props: {
20
- type: PropType<Partial<z.TypeOf<Schema> | ((formData?: Ref<ObjectConstructor>) => Partial<z.TypeOf<Schema>> | undefined) | undefined>>;
20
+ type: PropType<Partial<z.TypeOf<Schema> | ((formData?: Ref<ObjectConstructor>) => Partial<z.infer<Schema>> | undefined) | undefined>>;
21
21
  default: () => {};
22
22
  };
23
23
  showValid: {
@@ -75,7 +75,7 @@ export declare const defineFormField: <Schema extends FormSchema>(formProvideKey
75
75
  required: true;
76
76
  };
77
77
  props: {
78
- type: PropType<Partial<z.TypeOf<Schema> | ((formData?: Ref<ObjectConstructor>) => Partial<z.TypeOf<Schema>> | undefined) | undefined>>;
78
+ type: PropType<Partial<z.TypeOf<Schema> | ((formData?: Ref<ObjectConstructor>) => Partial<z.infer<Schema>> | undefined) | undefined>>;
79
79
  default: () => {};
80
80
  };
81
81
  showValid: {
@@ -102,10 +102,10 @@ export declare const defineFormField: <Schema extends FormSchema>(formProvideKey
102
102
  }, {
103
103
  type: "number" | "text" | "email" | "password" | "tel" | "url" | "search" | "date" | "time" | "datetime-local" | "month" | "week" | "color" | "select" | "checkbox" | "radio" | "textarea" | "radioGroup" | "checkboxGroup" | "combobox" | "custom";
104
104
  props: [{
105
- type: PropType<Partial<z.TypeOf<Schema> | ((formData?: Ref<ObjectConstructor>) => Partial<z.TypeOf<Schema>> | undefined) | undefined>>;
105
+ type: PropType<Partial<z.TypeOf<Schema> | ((formData?: Ref<ObjectConstructor>) => Partial<z.infer<Schema>> | undefined) | undefined>>;
106
106
  default: () => {};
107
107
  }] extends [import("vue").Prop<infer V, infer D>] ? unknown extends V ? import("@vue/shared").IfAny<V, V, D> : V : {
108
- type: PropType<Partial<z.TypeOf<Schema> | ((formData?: Ref<ObjectConstructor>) => Partial<z.TypeOf<Schema>> | undefined) | undefined>>;
108
+ type: PropType<Partial<z.TypeOf<Schema> | ((formData?: Ref<ObjectConstructor>) => Partial<z.infer<Schema>> | undefined) | undefined>>;
109
109
  default: () => {};
110
110
  };
111
111
  is: Component;
@@ -52,7 +52,7 @@ export declare const defineFormTemplate: <Schema extends FormSchema>(formProvide
52
52
  formData: unknown extends Partial<TypeOf<Schema>> | undefined ? undefined : Partial<TypeOf<Schema>> | undefined;
53
53
  submit: () => Promise<boolean>;
54
54
  validate: () => Promise<boolean>;
55
- errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema, string>>>>;
55
+ errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema>>>>;
56
56
  status: Ref<DeepReadonly<`${FormStatus}` | undefined>>;
57
57
  invalid: Ref<DeepReadonly<boolean>>;
58
58
  }) => any;
@@ -98,7 +98,7 @@ export declare const defineFormWrapper: <Schema extends FormSchema>(formProvideK
98
98
  formData: unknown extends Partial<TypeOf<Schema>> | undefined ? undefined : Partial<TypeOf<Schema>> | undefined;
99
99
  submit: () => Promise<boolean>;
100
100
  validate: () => Promise<boolean>;
101
- errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema, string>>>>;
101
+ errors: Readonly<Ref<DeepReadonly<z.inferFormattedError<Schema>>>>;
102
102
  fieldsErrors: Map<string, Record<string, {
103
103
  _errors: string[];
104
104
  }>>;
@@ -1,3 +1,3 @@
1
1
  import { type z } from 'zod';
2
2
  import type { FormSchema } from './types';
3
- export declare const defaultObjectBySchema: <Schema extends FormSchema>(schema: Schema, original?: Partial<z.TypeOf<Schema>> & Record<string, unknown>) => Partial<z.TypeOf<Schema>>;
3
+ export declare const defaultObjectBySchema: <Schema extends FormSchema>(schema: Schema, original?: Partial<z.infer<Schema>> & Record<string, unknown>) => Partial<z.infer<Schema>>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@volverjs/form-vue",
3
3
  "description": "Vue 3 Forms with @volverjs/ui-vue",
4
- "author": "24/Consulting",
4
+ "author": "8 Wave",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "form",
@@ -19,7 +19,7 @@
19
19
  "bugs": {
20
20
  "url": "https://github.com/volverjs/form-vue/issues"
21
21
  },
22
- "version": "1.0.0-beta.8",
22
+ "version": "1.0.0-beta.9",
23
23
  "engines": {
24
24
  "node": ">= 16.x"
25
25
  },
@@ -35,35 +35,35 @@
35
35
  "*.d.ts"
36
36
  ],
37
37
  "dependencies": {
38
- "@volverjs/ui-vue": "0.0.10-beta.27",
39
- "@vueuse/core": "^10.7.2",
38
+ "@volverjs/ui-vue": "0.0.10-beta.29",
39
+ "@vueuse/core": "^10.9.0",
40
40
  "ts-dot-prop": "^2.1.3",
41
- "vue": "^3.4.15",
41
+ "vue": "^3.4.21",
42
42
  "zod": "^3.22.4"
43
43
  },
44
44
  "devDependencies": {
45
- "@playwright/experimental-ct-vue": "1.41.1",
46
- "@testing-library/vue": "^8.0.1",
47
- "@typescript-eslint/eslint-plugin": "^6.20.0",
48
- "@vitejs/plugin-vue": "^5.0.3",
45
+ "@playwright/experimental-ct-vue": "1.42.1",
46
+ "@testing-library/vue": "^8.0.3",
47
+ "@typescript-eslint/eslint-plugin": "^7.3.1",
48
+ "@vitejs/plugin-vue": "^5.0.4",
49
49
  "@volverjs/style": "^0.1.11",
50
- "@vue/compiler-sfc": "^3.4.15",
51
- "@vue/eslint-config-typescript": "^12.0.0",
52
- "@vue/runtime-core": "^3.4.15",
53
- "@vue/test-utils": "^2.4.4",
50
+ "@vue/compiler-sfc": "^3.4.21",
51
+ "@vue/eslint-config-typescript": "^13.0.0",
52
+ "@vue/runtime-core": "^3.4.21",
53
+ "@vue/test-utils": "^2.4.5",
54
54
  "copy": "^0.3.2",
55
- "eslint": "^8.56.0",
55
+ "eslint": "^8.57.0",
56
56
  "eslint-config-prettier": "^9.1.0",
57
57
  "eslint-plugin-prettier": "^5.1.3",
58
- "eslint-plugin-vue": "^9.21.0",
59
- "happy-dom": "^13.3.5",
60
- "prettier": "^3.2.4",
61
- "typescript": "^5.3.3",
62
- "vite": "^5.0.12",
63
- "vite-plugin-dts": "^3.7.2",
58
+ "eslint-plugin-vue": "^9.23.0",
59
+ "happy-dom": "^14.3.1",
60
+ "prettier": "^3.2.5",
61
+ "typescript": "^5.4.3",
62
+ "vite": "^5.2.2",
63
+ "vite-plugin-dts": "^3.7.3",
64
64
  "vite-plugin-eslint": "^1.8.1",
65
65
  "vite-plugin-externalize-deps": "^0.8.0",
66
- "vitest": "^1.2.2"
66
+ "vitest": "^1.4.0"
67
67
  },
68
68
  "typesVersions": {
69
69
  "*": {
package/src/VvForm.ts CHANGED
@@ -202,12 +202,10 @@ export const defineForm = <Schema extends FormSchema>(
202
202
  }
203
203
  })
204
204
 
205
+ // readonly
205
206
  onMounted(() => {
206
- if (props.readonly && !readonly.value) {
207
- readonly.value = props.readonly
208
- }
207
+ readonly.value = props.readonly
209
208
  })
210
-
211
209
  watch(
212
210
  () => props.readonly,
213
211
  (newValue) => {
@@ -273,10 +271,10 @@ export const defineForm = <Schema extends FormSchema>(
273
271
  default: defaultSlot,
274
272
  },
275
273
  ),
276
- ]
274
+ ]
277
275
  : {
278
276
  default: defaultSlot,
279
- },
277
+ },
280
278
  )
281
279
  },
282
280
  })