@volverjs/form-vue 0.0.11 → 0.0.12-beta.2

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
@@ -1,10 +1,10 @@
1
1
  import { defineComponent as G, computed as y, onMounted as R, onBeforeUnmount as T, inject as O, toRefs as U, watch as w, provide as z, readonly as k, resolveComponent as g, defineAsyncComponent as D, h as x, ref as E, toRaw as Z, isProxy as j, withModifiers as F, unref as C, getCurrentInstance as ee } from "vue";
2
2
  import { watchThrottled as re } from "@vueuse/core";
3
- import { ZodObject as J, ZodDefault as te, ZodNullable as ae, ZodSchema as ne, ZodEffects as se } from "zod";
4
- function _(e) {
3
+ import { ZodObject as J, ZodDefault as te, ZodNullable as ae, ZodSchema as ne, ZodEffects as se, ZodOptional as oe } from "zod";
4
+ function A(e) {
5
5
  return Array.isArray(e);
6
6
  }
7
- function oe(e) {
7
+ function ue(e) {
8
8
  return typeof e < "u";
9
9
  }
10
10
  function M(e) {
@@ -19,53 +19,53 @@ function P(e) {
19
19
  function $(e) {
20
20
  return typeof e > "u";
21
21
  }
22
- const ue = /^[0-9]+$/, ie = ["__proto__", "prototype", "constructor"];
22
+ const ie = /^[0-9]+$/, le = ["__proto__", "prototype", "constructor"];
23
23
  function N(e, s, l) {
24
- const o = oe(l) ? l : void 0;
24
+ const u = ue(l) ? l : void 0;
25
25
  if (!q(e) || !P(s))
26
- return o;
26
+ return u;
27
27
  const n = Q(s);
28
28
  if (n.length !== 0) {
29
29
  for (const r of n) {
30
30
  if (r === "*")
31
31
  continue;
32
- const u = function(a) {
33
- return a.map((i) => $(i) || M(i) ? i : _(i) ? u(i) : i[r]);
32
+ const o = function(a) {
33
+ return a.map((i) => $(i) || M(i) ? i : A(i) ? o(i) : i[r]);
34
34
  };
35
- if (_(e) && !ue.test(r) ? e = u(e) : e = e[r], $(e) || M(e))
35
+ if (A(e) && !ie.test(r) ? e = o(e) : e = e[r], $(e) || M(e))
36
36
  break;
37
37
  }
38
- return $(e) ? o : e;
38
+ return $(e) ? u : e;
39
39
  }
40
40
  }
41
41
  function H(e, s, l) {
42
42
  if (!q(e) || !P(s))
43
43
  return;
44
- const o = Q(s);
45
- if (o.length === 0)
44
+ const u = Q(s);
45
+ if (u.length === 0)
46
46
  return;
47
- const n = o.length;
47
+ const n = u.length;
48
48
  for (let r = 0; r < n; r++) {
49
- const u = o[r];
49
+ const o = u[r];
50
50
  if (r === n - 1) {
51
- e[u] = l;
51
+ e[o] = l;
52
52
  return;
53
53
  }
54
- if (u === "*" && _(e)) {
55
- const a = o.slice(r + 1).join(".");
54
+ if (o === "*" && A(e)) {
55
+ const a = u.slice(r + 1).join(".");
56
56
  for (const i of e)
57
57
  H(i, a, l);
58
58
  return;
59
59
  }
60
- $(e[u]) && (e[u] = {}), e = e[u];
60
+ $(e[o]) && (e[o] = {}), e = e[o];
61
61
  }
62
62
  }
63
63
  function Q(e) {
64
64
  const s = e.split(/[.]|(?:\[(\d|\*)\])/).filter((l) => !!l);
65
- return s.some((l) => ie.indexOf(l) !== -1) ? [] : s;
65
+ return s.some((l) => le.indexOf(l) !== -1) ? [] : s;
66
66
  }
67
67
  var f = /* @__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 = "datetimeLocal", 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))(f || {}), L = /* @__PURE__ */ ((e) => (e.invalid = "invalid", e.valid = "valid", e))(L || {});
68
- const le = (e, s, l, o) => G({
68
+ const fe = (e, s, l, u) => G({
69
69
  name: "FieldComponent",
70
70
  props: {
71
71
  type: {
@@ -100,7 +100,7 @@ const le = (e, s, l, o) => G({
100
100
  },
101
101
  emits: ["invalid", "valid", "update:formData", "update:modelValue"],
102
102
  expose: ["invalid", "invalidLabel", "errors"],
103
- setup(n, { slots: r, emit: u }) {
103
+ setup(n, { slots: r, emit: o }) {
104
104
  const a = y({
105
105
  get() {
106
106
  if (t != null && t.formData)
@@ -114,7 +114,7 @@ const le = (e, s, l, o) => G({
114
114
  Object(t.formData.value),
115
115
  String(n.name),
116
116
  v
117
- ), u("update:modelValue", {
117
+ ), o("update:modelValue", {
118
118
  newValue: a.value,
119
119
  formData: t == null ? void 0 : t.formData
120
120
  }));
@@ -134,18 +134,18 @@ const le = (e, s, l, o) => G({
134
134
  var v;
135
135
  return (v = d.value) == null ? void 0 : v._errors;
136
136
  }), b = y(() => d.value !== void 0), S = w(b, () => {
137
- b.value ? (u("invalid", c.value), i && i.errors.value.set(
137
+ b.value ? (o("invalid", c.value), i && i.errors.value.set(
138
138
  n.name,
139
139
  {
140
140
  _errors: c.value
141
141
  }
142
- )) : (u("valid", a.value), i && i.errors.value.delete(
142
+ )) : (o("valid", a.value), i && i.errors.value.delete(
143
143
  n.name
144
144
  ));
145
145
  }), V = w(
146
146
  () => t == null ? void 0 : t.formData,
147
147
  () => {
148
- u("update:formData", t == null ? void 0 : t.formData);
148
+ o("update:formData", t == null ? void 0 : t.formData);
149
149
  },
150
150
  { deep: !0 }
151
151
  ), p = (v) => {
@@ -198,7 +198,7 @@ const le = (e, s, l, o) => G({
198
198
  })) ?? r.defalut;
199
199
  }
200
200
  };
201
- if (!((o == null ? void 0 : o.lazyLoad) ?? n.lazyLoad)) {
201
+ if (!((u == null ? void 0 : u.lazyLoad) ?? n.lazyLoad)) {
202
202
  let v;
203
203
  switch (n.type) {
204
204
  case f.select:
@@ -232,7 +232,7 @@ const le = (e, s, l, o) => G({
232
232
  );
233
233
  }
234
234
  return D(async () => {
235
- switch (o != null && o.sideEffects && await Promise.resolve(o.sideEffects(n.type)), n.type) {
235
+ switch (u != null && u.sideEffects && await Promise.resolve(u.sideEffects(n.type)), n.type) {
236
236
  case f.textarea:
237
237
  return import("@volverjs/ui-vue/vv-textarea");
238
238
  case f.radio:
@@ -257,22 +257,24 @@ const le = (e, s, l, o) => G({
257
257
  }
258
258
  }), X = (e, s = {}) => {
259
259
  const l = (r) => {
260
- let u = r;
261
- for (; u instanceof se; )
262
- u = u.innerType();
263
- return u;
264
- }, o = l(e);
260
+ let o = r;
261
+ for (; o instanceof se; )
262
+ o = o.innerType();
263
+ for (; o instanceof oe; )
264
+ o = o._def.innerType;
265
+ return o;
266
+ }, u = l(e);
265
267
  return {
266
- ...(o instanceof J ? o._def.unknownKeys === "passthrough" : !1) ? s : {},
268
+ ...(u instanceof J ? u._def.unknownKeys === "passthrough" : !1) ? s : {},
267
269
  ...Object.fromEntries(
268
- Object.entries(o.shape).map(
269
- ([r, u]) => {
270
- const a = s[r], i = l(u);
270
+ Object.entries(u.shape).map(
271
+ ([r, o]) => {
272
+ const a = s[r], i = l(o);
271
273
  let t;
272
274
  if (i instanceof te && (t = i._def.defaultValue()), a === null && i instanceof ae)
273
275
  return [r, a];
274
276
  if (i instanceof ne) {
275
- const m = u.safeParse(a);
277
+ const m = o.safeParse(a);
276
278
  if (m.success)
277
279
  return [r, m.data ?? t];
278
280
  }
@@ -287,8 +289,8 @@ const le = (e, s, l, o) => G({
287
289
  )
288
290
  )
289
291
  };
290
- }, fe = (e, s, l) => {
291
- const o = E(), n = E(), r = E(), u = G({
292
+ }, ve = (e, s, l) => {
293
+ const u = E(), n = E(), r = E(), o = G({
292
294
  name: "FormComponent",
293
295
  props: {
294
296
  modelValue: {
@@ -322,7 +324,7 @@ const le = (e, s, l, o) => G({
322
324
  ), re(
323
325
  r,
324
326
  (d) => {
325
- ((o.value || (l == null ? void 0 : l.continuosValidation)) ?? a.continuosValidation) && t(), (!d || !a.modelValue || JSON.stringify(d) !== JSON.stringify(a.modelValue)) && i("update:modelValue", d);
327
+ ((u.value || (l == null ? void 0 : l.continuosValidation)) ?? a.continuosValidation) && t(), (!d || !a.modelValue || JSON.stringify(d) !== JSON.stringify(a.modelValue)) && i("update:modelValue", d);
326
328
  },
327
329
  {
328
330
  deep: !0,
@@ -331,20 +333,20 @@ const le = (e, s, l, o) => G({
331
333
  );
332
334
  const t = (d = r.value) => {
333
335
  const c = e.safeParse(d);
334
- return c.success ? (o.value = void 0, n.value = L.valid, r.value = c.data, i("update:modelValue", r.value), i("valid", c.data), !0) : (o.value = c.error.format(), n.value = L.invalid, i("invalid", o.value), !1);
336
+ return c.success ? (u.value = void 0, n.value = L.valid, r.value = c.data, i("update:modelValue", r.value), i("valid", c.data), !0) : (u.value = c.error.format(), n.value = L.invalid, i("invalid", u.value), !1);
335
337
  }, m = () => t() ? (i("submit", r.value), !0) : !1, h = y(() => n.value === L.invalid);
336
338
  return z(s, {
337
339
  formData: r,
338
340
  submit: m,
339
341
  validate: t,
340
- errors: k(o),
342
+ errors: k(u),
341
343
  status: k(n),
342
344
  invalid: h
343
345
  }), {
344
346
  formData: r,
345
347
  submit: m,
346
348
  validate: t,
347
- errors: k(o),
349
+ errors: k(u),
348
350
  status: k(n),
349
351
  invalid: h
350
352
  };
@@ -372,15 +374,15 @@ const le = (e, s, l, o) => G({
372
374
  }
373
375
  });
374
376
  return {
375
- errors: o,
377
+ errors: u,
376
378
  status: n,
377
379
  formData: r,
378
380
  /**
379
381
  * An hack to add types to the default slot
380
382
  */
381
- VvForm: u
383
+ VvForm: o
382
384
  };
383
- }, ve = (e, s) => G({
385
+ }, de = (e, s) => G({
384
386
  name: "WrapperComponent",
385
387
  props: {
386
388
  name: {
@@ -394,8 +396,8 @@ const le = (e, s, l, o) => G({
394
396
  },
395
397
  emits: ["invalid", "valid"],
396
398
  expose: ["fields", "invalid"],
397
- setup(o, { emit: n }) {
398
- const r = O(e), u = O(s, void 0), a = E(/* @__PURE__ */ new Set()), i = E(/* @__PURE__ */ new Map()), { name: t } = U(o);
399
+ setup(u, { emit: n }) {
400
+ const r = O(e), o = O(s, void 0), a = E(/* @__PURE__ */ new Set()), i = E(/* @__PURE__ */ new Map()), { name: t } = U(u);
399
401
  z(s, {
400
402
  name: k(t),
401
403
  errors: i,
@@ -403,19 +405,19 @@ const le = (e, s, l, o) => G({
403
405
  }), w(
404
406
  a,
405
407
  (h) => {
406
- u != null && u.fields && h.forEach((d) => {
407
- u == null || u.fields.value.add(d);
408
+ o != null && o.fields && h.forEach((d) => {
409
+ o == null || o.fields.value.add(d);
408
410
  });
409
411
  },
410
412
  { deep: !0 }
411
413
  ), w(
412
414
  () => new Map(i.value),
413
415
  (h, d) => {
414
- u != null && u.errors && (Array.from(d.keys()).forEach((c) => {
415
- u.errors.value.delete(c);
416
+ o != null && o.errors && (Array.from(d.keys()).forEach((c) => {
417
+ o.errors.value.delete(c);
416
418
  }), Array.from(h.keys()).forEach((c) => {
417
419
  const b = h.get(c);
418
- b && u.errors.value.set(c, b);
420
+ b && o.errors.value.set(c, b);
419
421
  }));
420
422
  },
421
423
  { deep: !0 }
@@ -434,11 +436,11 @@ const le = (e, s, l, o) => G({
434
436
  };
435
437
  },
436
438
  render() {
437
- var o, n;
439
+ var u, n;
438
440
  return this.tag ? x(this.tag, null, {
439
441
  default: () => {
440
- var r, u;
441
- return ((u = (r = this.$slots).default) == null ? void 0 : u.call(r, {
442
+ var r, o;
443
+ return ((o = (r = this.$slots).default) == null ? void 0 : o.call(r, {
442
444
  invalid: this.invalid,
443
445
  formData: this.formData,
444
446
  submit: this.submit,
@@ -447,7 +449,7 @@ const le = (e, s, l, o) => G({
447
449
  fieldsErrors: this.fieldsErrors
448
450
  })) ?? this.$slots.defalut;
449
451
  }
450
- }) : ((n = (o = this.$slots).default) == null ? void 0 : n.call(o, {
452
+ }) : ((n = (u = this.$slots).default) == null ? void 0 : n.call(u, {
451
453
  invalid: this.invalid,
452
454
  formData: this.formData,
453
455
  submit: this.submit,
@@ -456,7 +458,7 @@ const le = (e, s, l, o) => G({
456
458
  fieldsErrors: this.fieldsErrors
457
459
  })) ?? this.$slots.defalut;
458
460
  }
459
- }), de = (e, s) => {
461
+ }), ce = (e, s) => {
460
462
  const l = G({
461
463
  props: {
462
464
  schema: {
@@ -464,15 +466,15 @@ const le = (e, s, l, o) => G({
464
466
  required: !0
465
467
  }
466
468
  },
467
- setup(o, { slots: n }) {
469
+ setup(u, { slots: n }) {
468
470
  const r = O(e);
469
471
  if (!(r != null && r.formData))
470
472
  return;
471
- const u = typeof o.schema == "function" ? o.schema(r) : o.schema;
473
+ const o = typeof u.schema == "function" ? u.schema(r) : u.schema;
472
474
  let a;
473
475
  return () => {
474
476
  var i;
475
- return u.reduce(
477
+ return o.reduce(
476
478
  (t, m) => {
477
479
  const h = typeof m == "function" ? m(r) : m, {
478
480
  vvIs: d,
@@ -500,7 +502,7 @@ const le = (e, s, l, o) => G({
500
502
  return t;
501
503
  } else
502
504
  a = void 0;
503
- const A = S ? x(l, {
505
+ const _ = S ? x(l, {
504
506
  schema: S
505
507
  }) : void 0;
506
508
  return c ? (t.push(
@@ -514,15 +516,15 @@ const le = (e, s, l, o) => G({
514
516
  showValid: K,
515
517
  props: v
516
518
  },
517
- b ?? A
519
+ b ?? _
518
520
  )
519
521
  ), t) : d ? (t.push(
520
522
  x(
521
523
  d,
522
524
  v,
523
- b ?? A
525
+ b ?? _
524
526
  )
525
- ), t) : (S && t.push(A), t);
527
+ ), t) : (S && t.push(_), t);
526
528
  },
527
529
  [
528
530
  (i = n == null ? void 0 : n.default) == null ? void 0 : i.call(n, {
@@ -540,48 +542,48 @@ const le = (e, s, l, o) => G({
540
542
  });
541
543
  return l;
542
544
  }, B = (e, s = {}) => {
543
- const l = Symbol(), o = Symbol(), n = Symbol(), { VvForm: r, errors: u, status: a, formData: i } = fe(
545
+ const l = Symbol(), u = Symbol(), n = Symbol(), { VvForm: r, errors: o, status: a, formData: i } = ve(
544
546
  e,
545
547
  l,
546
548
  s
547
- ), t = ve(
549
+ ), t = de(
548
550
  l,
549
- o
550
- ), m = le(
551
+ u
552
+ ), m = fe(
551
553
  l,
552
- o,
554
+ u,
553
555
  n,
554
556
  s
555
- ), h = de(l, m);
557
+ ), h = ce(l, m);
556
558
  return {
557
559
  VvForm: r,
558
560
  VvFormWrapper: t,
559
561
  VvFormField: m,
560
562
  VvFormTemplate: h,
561
563
  formInjectionKey: l,
562
- formWrapperInjectionKey: o,
564
+ formWrapperInjectionKey: u,
563
565
  formFieldInjectionKey: n,
564
- errors: u,
566
+ errors: o,
565
567
  status: a,
566
568
  formData: i
567
569
  };
568
- }, Y = Symbol(), be = (e) => {
570
+ }, Y = Symbol(), pe = (e) => {
569
571
  let s = {};
570
572
  return e.schema && (s = B(e.schema, e)), {
571
573
  ...s,
572
- install(l, { global: o = !1 } = {}) {
573
- l.provide(Y, e), o && (l.config.globalProperties.$vvForm = e, s != null && s.VvForm && l.component("VvForm", s.VvForm), s != null && s.VvFormWrapper && l.component("VvFormWrapper", s.VvFormWrapper), s != null && s.VvFormField && l.component("VvFormField", s.VvFormField), s != null && s.VvFormTemplate && l.component("VvFormTemplate", s.VvFormTemplate));
574
+ install(l, { global: u = !1 } = {}) {
575
+ l.provide(Y, e), u && (l.config.globalProperties.$vvForm = e, s != null && s.VvForm && l.component("VvForm", s.VvForm), s != null && s.VvFormWrapper && l.component("VvFormWrapper", s.VvFormWrapper), s != null && s.VvFormField && l.component("VvFormField", s.VvFormField), s != null && s.VvFormTemplate && l.component("VvFormTemplate", s.VvFormTemplate));
574
576
  }
575
577
  };
576
- }, pe = (e, s = {}) => ee() ? B(e, {
578
+ }, ye = (e, s = {}) => ee() ? B(e, {
577
579
  ...O(Y, {}),
578
580
  ...s
579
- }) : B(e, s), ye = (e, s = {}) => B(e, s);
581
+ }) : B(e, s), Ve = (e, s = {}) => B(e, s);
580
582
  export {
581
583
  f as FormFieldType,
582
- be as createForm,
584
+ pe as createForm,
583
585
  X as defaultObjectBySchema,
584
- ye as formFactory,
586
+ Ve as formFactory,
585
587
  Y as pluginInjectionKey,
586
- pe as useForm
588
+ ye as useForm
587
589
  };
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(p,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("vue"),require("@vueuse/core"),require("zod")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","zod"],r):(p=typeof globalThis<"u"?globalThis:p||self,r(p["@volverjs/form-vue"]={},p.Vue,p.VueUseCore,p.zod))})(this,function(p,r,Z,x){"use strict";function I(e){return Array.isArray(e)}function z(e){return typeof e<"u"}function G(e){return e===null}function W(e){return typeof e=="object"}function A(e){return typeof e=="string"}function k(e){return typeof e>"u"}const M=/^[0-9]+$/,U=["__proto__","prototype","constructor"];function C(e,s,f){const i=z(f)?f:void 0;if(!W(e)||!A(s))return i;const o=K(s);if(o.length!==0){for(const t of o){if(t==="*")continue;const l=function(a){return a.map(u=>k(u)||G(u)?u:I(u)?l(u):u[t])};if(I(e)&&!M.test(t)?e=l(e):e=e[t],k(e)||G(e))break}return k(e)?i:e}}function _(e,s,f){if(!W(e)||!A(s))return;const i=K(s);if(i.length===0)return;const o=i.length;for(let t=0;t<o;t++){const l=i[t];if(t===o-1){e[l]=f;return}if(l==="*"&&I(e)){const a=i.slice(t+1).join(".");for(const u of e)_(u,a,f);return}k(e[l])&&(e[l]={}),e=e[l]}}function K(e){const s=e.split(/[.]|(?:\[(\d|\*)\])/).filter(f=>!!f);return s.some(f=>U.indexOf(f)!==-1)?[]:s}var d=(e=>(e.text="text",e.number="number",e.email="email",e.password="password",e.tel="tel",e.url="url",e.search="search",e.date="date",e.time="time",e.datetimeLocal="datetimeLocal",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||{}),O=(e=>(e.invalid="invalid",e.valid="valid",e))(O||{});const J=(e,s,f,i)=>r.defineComponent({name:"FieldComponent",props:{type:{type:String,validator:o=>Object.values(d).includes(o),default:d.custom},is:{type:[Object,String],default:void 0},name:{type:[String,Number,Boolean,Symbol],required:!0},props:{type:[Object,Function],default:()=>({})},showValid:{type:Boolean,default:!1},defaultValue:{type:[String,Number,Boolean,Array,Object],default:void 0},lazyLoad:{type:Boolean,default:!1}},emits:["invalid","valid","update:formData","update:modelValue"],expose:["invalid","invalidLabel","errors"],setup(o,{slots:t,emit:l}){const a=r.computed({get(){if(n!=null&&n.formData)return C(Object(n.formData.value),String(o.name))},set(c){n!=null&&n.formData&&(_(Object(n.formData.value),String(o.name),c),l("update:modelValue",{newValue:a.value,formData:n==null?void 0:n.formData}))}});r.onMounted(()=>{a.value===void 0&&o.defaultValue!==void 0&&(a.value=o.defaultValue)}),r.onBeforeUnmount(()=>{w(),g()});const u=r.inject(s,void 0);u&&u.fields.value.add(o.name);const n=r.inject(e),{props:h,name:y}=r.toRefs(o),m=r.computed(()=>{if(n!=null&&n.errors.value)return C(n.errors.value,String(o.name))}),v=r.computed(()=>{var c;return(c=m.value)==null?void 0:c._errors}),b=r.computed(()=>m.value!==void 0),w=r.watch(b,()=>{b.value?(l("invalid",v.value),u&&u.errors.value.set(o.name,{_errors:v.value})):(l("valid",a.value),u&&u.errors.value.delete(o.name))}),g=r.watch(()=>n==null?void 0:n.formData,()=>{l("update:formData",n==null?void 0:n.formData)},{deep:!0}),V=c=>{a.value=c},E=r.computed(()=>typeof h.value=="function"?h.value(n==null?void 0:n.formData):h.value),L=r.computed(()=>({...E.value,name:E.value.name??o.name,invalid:b.value,valid:o.showValid?!!(!b.value&&a.value):void 0,type:(c=>{if([d.text,d.number,d.email,d.password,d.tel,d.url,d.search,d.date,d.time,d.datetimeLocal,d.month,d.week,d.color].includes(c))return c})(o.type),invalidLabel:v.value,modelValue:a.value,"onUpdate:modelValue":V}));return r.provide(f,{name:r.readonly(y),errors:r.readonly(m)}),{component:r.computed(()=>{if(o.type===d.custom)return{render(){var c;return((c=t.default)==null?void 0:c.call(t,{modelValue:a.value,onUpdate:V,submit:n==null?void 0:n.submit,validate:n==null?void 0:n.validate,invalid:b.value,invalidLabel:v.value,formData:n==null?void 0:n.formData.value,formErrors:n==null?void 0:n.errors.value,errors:m.value}))??t.defalut}};if(!((i==null?void 0:i.lazyLoad)??o.lazyLoad)){let c;switch(o.type){case d.select:c=r.resolveComponent("VvSelect");break;case d.checkbox:c=r.resolveComponent("VvCheckbox");break;case d.radio:c=r.resolveComponent("VvRadio");break;case d.textarea:c=r.resolveComponent("VvTextarea");break;case d.radioGroup:c=r.resolveComponent("VvRadioGroup");break;case d.checkboxGroup:c=r.resolveComponent("VvCheckboxGroup");break;case d.combobox:c=r.resolveComponent("VvCombobox");break;default:c=r.resolveComponent("VvInputText")}if(typeof c!="string")return c;console.warn(`[form-vue warn]: ${c} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`)}return r.defineAsyncComponent(async()=>{switch(i!=null&&i.sideEffects&&await Promise.resolve(i.sideEffects(o.type)),o.type){case d.textarea:return import("@volverjs/ui-vue/vv-textarea");case d.radio:return import("@volverjs/ui-vue/vv-radio");case d.radioGroup:return import("@volverjs/ui-vue/vv-radio-group");case d.checkbox:return import("@volverjs/ui-vue/vv-checkbox");case d.checkboxGroup:return import("@volverjs/ui-vue/vv-checkbox-group");case d.select:return import("@volverjs/ui-vue/vv-select");case d.combobox:return import("@volverjs/ui-vue/vv-combobox")}return import("@volverjs/ui-vue/vv-input-text")})}),hasProps:L,invalid:b}},render(){return this.is?r.h(this.is,this.hasProps,this.$slots):this.type===d.custom?r.h(this.component,null,this.$slots):r.h(this.component,this.hasProps,this.$slots)}}),$=(e,s={})=>{const f=t=>{let l=t;for(;l instanceof x.ZodEffects;)l=l.innerType();return l},i=f(e);return{...(i instanceof x.ZodObject?i._def.unknownKeys==="passthrough":!1)?s:{},...Object.fromEntries(Object.entries(i.shape).map(([t,l])=>{const a=s[t],u=f(l);let n;if(u instanceof x.ZodDefault&&(n=u._def.defaultValue()),a===null&&u instanceof x.ZodNullable)return[t,a];if(u instanceof x.ZodSchema){const h=l.safeParse(a);if(h.success)return[t,h.data??n]}return u instanceof x.ZodObject?[t,$(u,a&&typeof a=="object"?a:{})]:[t,n]}))}},P=(e,s,f)=>{const i=r.ref(),o=r.ref(),t=r.ref(),l=r.defineComponent({name:"FormComponent",props:{modelValue:{type:Object,default:()=>({})},updateThrottle:{type:Number,default:500},continuosValidation:{type:Boolean,default:!1}},emits:["invalid","valid","submit","update:modelValue"],expose:["submit","validate","errors","status","valid","invalid"],setup(a,{emit:u}){t.value=$(e,r.toRaw(a.modelValue)),r.watch(()=>a.modelValue,m=>{if(m){const v=r.isProxy(m)?r.toRaw(m):m;t.value=typeof(v==null?void 0:v.clone)=="function"?v.clone():JSON.parse(JSON.stringify(v))}},{deep:!0}),Z.watchThrottled(t,m=>{((i.value||(f==null?void 0:f.continuosValidation))??a.continuosValidation)&&n(),(!m||!a.modelValue||JSON.stringify(m)!==JSON.stringify(a.modelValue))&&u("update:modelValue",m)},{deep:!0,throttle:(f==null?void 0:f.updateThrottle)??a.updateThrottle});const n=(m=t.value)=>{const v=e.safeParse(m);return v.success?(i.value=void 0,o.value=O.valid,t.value=v.data,u("update:modelValue",t.value),u("valid",v.data),!0):(i.value=v.error.format(),o.value=O.invalid,u("invalid",i.value),!1)},h=()=>n()?(u("submit",t.value),!0):!1,y=r.computed(()=>o.value===O.invalid);return r.provide(s,{formData:t,submit:h,validate:n,errors:r.readonly(i),status:r.readonly(o),invalid:y}),{formData:t,submit:h,validate:n,errors:r.readonly(i),status:r.readonly(o),invalid:y}},render(){return r.h("form",{onSubmit:r.withModifiers(this.submit,["prevent"])},{default:()=>{var a,u;return((u=(a=this.$slots)==null?void 0:a.default)==null?void 0:u.call(a,{formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,status:this.status,invalid:this.invalid}))??this.$slots.default}})}});return{errors:i,status:o,formData:t,VvForm:l}},T=(e,s)=>r.defineComponent({name:"WrapperComponent",props:{name:{type:String,required:!0},tag:{type:String,default:void 0}},emits:["invalid","valid"],expose:["fields","invalid"],setup(i,{emit:o}){const t=r.inject(e),l=r.inject(s,void 0),a=r.ref(new Set),u=r.ref(new Map),{name:n}=r.toRefs(i);r.provide(s,{name:r.readonly(n),errors:u,fields:a}),r.watch(a,y=>{l!=null&&l.fields&&y.forEach(m=>{l==null||l.fields.value.add(m)})},{deep:!0}),r.watch(()=>new Map(u.value),(y,m)=>{l!=null&&l.errors&&(Array.from(m.keys()).forEach(v=>{l.errors.value.delete(v)}),Array.from(y.keys()).forEach(v=>{const b=y.get(v);b&&l.errors.value.set(v,b)}))},{deep:!0});const h=r.computed(()=>t!=null&&t.invalid.value?u.value.size>0:!1);return r.watch(h,()=>{h.value?o("invalid"):o("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:h,fields:a,fieldsErrors:u}},render(){var i,o;return this.tag?r.h(this.tag,null,{default:()=>{var t,l;return((l=(t=this.$slots).default)==null?void 0:l.call(t,{invalid:this.invalid,formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}):((o=(i=this.$slots).default)==null?void 0:o.call(i,{invalid:this.invalid,formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}),R=(e,s)=>{const f=r.defineComponent({props:{schema:{type:[Array,Function],required:!0}},setup(i,{slots:o}){const t=r.inject(e);if(!(t!=null&&t.formData))return;const l=typeof i.schema=="function"?i.schema(t):i.schema;let a;return()=>{var u;return l.reduce((n,h)=>{const y=typeof h=="function"?h(t):h,{vvIs:m,vvName:v,vvSlots:b,vvChildren:w,vvIf:g,vvElseIf:V,vvType:E,vvDefaultValue:L,vvShowValid:q,...c}=y;if(g!==void 0){if(typeof g=="string"?a=!!C(Object(t.formData.value),g):typeof g=="function"?a=r.unref(g(t)):a=r.unref(g),!a)return n}else if(V!==void 0&&a!==void 0){if(a||(typeof V=="string"?a=!!C(Object(t.formData.value),V):typeof V=="function"?a=r.unref(V(t)):a=r.unref(V),!a))return n}else a=void 0;const N=w?r.h(f,{schema:w}):void 0;return v?(n.push(r.h(s,{name:v,is:m,type:E,defaultValue:L,showValid:q,props:c},b??N)),n):m?(n.push(r.h(m,c,b??N)),n):(w&&n.push(N),n)},[(u=o==null?void 0:o.default)==null?void 0:u.call(o,{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})])}}});return f},S=(e,s={})=>{const f=Symbol(),i=Symbol(),o=Symbol(),{VvForm:t,errors:l,status:a,formData:u}=P(e,f,s),n=T(f,i),h=J(f,i,o,s),y=R(f,h);return{VvForm:t,VvFormWrapper:n,VvFormField:h,VvFormTemplate:y,formInjectionKey:f,formWrapperInjectionKey:i,formFieldInjectionKey:o,errors:l,status:a,formData:u}},B=Symbol(),H=e=>{let s={};return e.schema&&(s=S(e.schema,e)),{...s,install(f,{global:i=!1}={}){f.provide(B,e),i&&(f.config.globalProperties.$vvForm=e,s!=null&&s.VvForm&&f.component("VvForm",s.VvForm),s!=null&&s.VvFormWrapper&&f.component("VvFormWrapper",s.VvFormWrapper),s!=null&&s.VvFormField&&f.component("VvFormField",s.VvFormField),s!=null&&s.VvFormTemplate&&f.component("VvFormTemplate",s.VvFormTemplate))}}},Q=(e,s={})=>r.getCurrentInstance()?S(e,{...r.inject(B,{}),...s}):S(e,s),X=(e,s={})=>S(e,s);p.FormFieldType=d,p.createForm=H,p.defaultObjectBySchema=$,p.formFactory=X,p.pluginInjectionKey=B,p.useForm=Q,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
1
+ (function(p,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("vue"),require("@vueuse/core"),require("zod")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","zod"],r):(p=typeof globalThis<"u"?globalThis:p||self,r(p["@volverjs/form-vue"]={},p.Vue,p.VueUseCore,p.zod))})(this,function(p,r,q,x){"use strict";function I(e){return Array.isArray(e)}function M(e){return typeof e<"u"}function G(e){return e===null}function W(e){return typeof e=="object"}function _(e){return typeof e=="string"}function k(e){return typeof e>"u"}const U=/^[0-9]+$/,z=["__proto__","prototype","constructor"];function C(e,s,f){const l=M(f)?f:void 0;if(!W(e)||!_(s))return l;const o=K(s);if(o.length!==0){for(const t of o){if(t==="*")continue;const i=function(a){return a.map(u=>k(u)||G(u)?u:I(u)?i(u):u[t])};if(I(e)&&!U.test(t)?e=i(e):e=e[t],k(e)||G(e))break}return k(e)?l:e}}function A(e,s,f){if(!W(e)||!_(s))return;const l=K(s);if(l.length===0)return;const o=l.length;for(let t=0;t<o;t++){const i=l[t];if(t===o-1){e[i]=f;return}if(i==="*"&&I(e)){const a=l.slice(t+1).join(".");for(const u of e)A(u,a,f);return}k(e[i])&&(e[i]={}),e=e[i]}}function K(e){const s=e.split(/[.]|(?:\[(\d|\*)\])/).filter(f=>!!f);return s.some(f=>z.indexOf(f)!==-1)?[]:s}var d=(e=>(e.text="text",e.number="number",e.email="email",e.password="password",e.tel="tel",e.url="url",e.search="search",e.date="date",e.time="time",e.datetimeLocal="datetimeLocal",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||{}),O=(e=>(e.invalid="invalid",e.valid="valid",e))(O||{});const J=(e,s,f,l)=>r.defineComponent({name:"FieldComponent",props:{type:{type:String,validator:o=>Object.values(d).includes(o),default:d.custom},is:{type:[Object,String],default:void 0},name:{type:[String,Number,Boolean,Symbol],required:!0},props:{type:[Object,Function],default:()=>({})},showValid:{type:Boolean,default:!1},defaultValue:{type:[String,Number,Boolean,Array,Object],default:void 0},lazyLoad:{type:Boolean,default:!1}},emits:["invalid","valid","update:formData","update:modelValue"],expose:["invalid","invalidLabel","errors"],setup(o,{slots:t,emit:i}){const a=r.computed({get(){if(n!=null&&n.formData)return C(Object(n.formData.value),String(o.name))},set(c){n!=null&&n.formData&&(A(Object(n.formData.value),String(o.name),c),i("update:modelValue",{newValue:a.value,formData:n==null?void 0:n.formData}))}});r.onMounted(()=>{a.value===void 0&&o.defaultValue!==void 0&&(a.value=o.defaultValue)}),r.onBeforeUnmount(()=>{w(),g()});const u=r.inject(s,void 0);u&&u.fields.value.add(o.name);const n=r.inject(e),{props:h,name:y}=r.toRefs(o),m=r.computed(()=>{if(n!=null&&n.errors.value)return C(n.errors.value,String(o.name))}),v=r.computed(()=>{var c;return(c=m.value)==null?void 0:c._errors}),b=r.computed(()=>m.value!==void 0),w=r.watch(b,()=>{b.value?(i("invalid",v.value),u&&u.errors.value.set(o.name,{_errors:v.value})):(i("valid",a.value),u&&u.errors.value.delete(o.name))}),g=r.watch(()=>n==null?void 0:n.formData,()=>{i("update:formData",n==null?void 0:n.formData)},{deep:!0}),V=c=>{a.value=c},E=r.computed(()=>typeof h.value=="function"?h.value(n==null?void 0:n.formData):h.value),L=r.computed(()=>({...E.value,name:E.value.name??o.name,invalid:b.value,valid:o.showValid?!!(!b.value&&a.value):void 0,type:(c=>{if([d.text,d.number,d.email,d.password,d.tel,d.url,d.search,d.date,d.time,d.datetimeLocal,d.month,d.week,d.color].includes(c))return c})(o.type),invalidLabel:v.value,modelValue:a.value,"onUpdate:modelValue":V}));return r.provide(f,{name:r.readonly(y),errors:r.readonly(m)}),{component:r.computed(()=>{if(o.type===d.custom)return{render(){var c;return((c=t.default)==null?void 0:c.call(t,{modelValue:a.value,onUpdate:V,submit:n==null?void 0:n.submit,validate:n==null?void 0:n.validate,invalid:b.value,invalidLabel:v.value,formData:n==null?void 0:n.formData.value,formErrors:n==null?void 0:n.errors.value,errors:m.value}))??t.defalut}};if(!((l==null?void 0:l.lazyLoad)??o.lazyLoad)){let c;switch(o.type){case d.select:c=r.resolveComponent("VvSelect");break;case d.checkbox:c=r.resolveComponent("VvCheckbox");break;case d.radio:c=r.resolveComponent("VvRadio");break;case d.textarea:c=r.resolveComponent("VvTextarea");break;case d.radioGroup:c=r.resolveComponent("VvRadioGroup");break;case d.checkboxGroup:c=r.resolveComponent("VvCheckboxGroup");break;case d.combobox:c=r.resolveComponent("VvCombobox");break;default:c=r.resolveComponent("VvInputText")}if(typeof c!="string")return c;console.warn(`[form-vue warn]: ${c} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`)}return r.defineAsyncComponent(async()=>{switch(l!=null&&l.sideEffects&&await Promise.resolve(l.sideEffects(o.type)),o.type){case d.textarea:return import("@volverjs/ui-vue/vv-textarea");case d.radio:return import("@volverjs/ui-vue/vv-radio");case d.radioGroup:return import("@volverjs/ui-vue/vv-radio-group");case d.checkbox:return import("@volverjs/ui-vue/vv-checkbox");case d.checkboxGroup:return import("@volverjs/ui-vue/vv-checkbox-group");case d.select:return import("@volverjs/ui-vue/vv-select");case d.combobox:return import("@volverjs/ui-vue/vv-combobox")}return import("@volverjs/ui-vue/vv-input-text")})}),hasProps:L,invalid:b}},render(){return this.is?r.h(this.is,this.hasProps,this.$slots):this.type===d.custom?r.h(this.component,null,this.$slots):r.h(this.component,this.hasProps,this.$slots)}}),$=(e,s={})=>{const f=t=>{let i=t;for(;i instanceof x.ZodEffects;)i=i.innerType();for(;i instanceof x.ZodOptional;)i=i._def.innerType;return i},l=f(e);return{...(l instanceof x.ZodObject?l._def.unknownKeys==="passthrough":!1)?s:{},...Object.fromEntries(Object.entries(l.shape).map(([t,i])=>{const a=s[t],u=f(i);let n;if(u instanceof x.ZodDefault&&(n=u._def.defaultValue()),a===null&&u instanceof x.ZodNullable)return[t,a];if(u instanceof x.ZodSchema){const h=i.safeParse(a);if(h.success)return[t,h.data??n]}return u instanceof x.ZodObject?[t,$(u,a&&typeof a=="object"?a:{})]:[t,n]}))}},P=(e,s,f)=>{const l=r.ref(),o=r.ref(),t=r.ref(),i=r.defineComponent({name:"FormComponent",props:{modelValue:{type:Object,default:()=>({})},updateThrottle:{type:Number,default:500},continuosValidation:{type:Boolean,default:!1}},emits:["invalid","valid","submit","update:modelValue"],expose:["submit","validate","errors","status","valid","invalid"],setup(a,{emit:u}){t.value=$(e,r.toRaw(a.modelValue)),r.watch(()=>a.modelValue,m=>{if(m){const v=r.isProxy(m)?r.toRaw(m):m;t.value=typeof(v==null?void 0:v.clone)=="function"?v.clone():JSON.parse(JSON.stringify(v))}},{deep:!0}),q.watchThrottled(t,m=>{((l.value||(f==null?void 0:f.continuosValidation))??a.continuosValidation)&&n(),(!m||!a.modelValue||JSON.stringify(m)!==JSON.stringify(a.modelValue))&&u("update:modelValue",m)},{deep:!0,throttle:(f==null?void 0:f.updateThrottle)??a.updateThrottle});const n=(m=t.value)=>{const v=e.safeParse(m);return v.success?(l.value=void 0,o.value=O.valid,t.value=v.data,u("update:modelValue",t.value),u("valid",v.data),!0):(l.value=v.error.format(),o.value=O.invalid,u("invalid",l.value),!1)},h=()=>n()?(u("submit",t.value),!0):!1,y=r.computed(()=>o.value===O.invalid);return r.provide(s,{formData:t,submit:h,validate:n,errors:r.readonly(l),status:r.readonly(o),invalid:y}),{formData:t,submit:h,validate:n,errors:r.readonly(l),status:r.readonly(o),invalid:y}},render(){return r.h("form",{onSubmit:r.withModifiers(this.submit,["prevent"])},{default:()=>{var a,u;return((u=(a=this.$slots)==null?void 0:a.default)==null?void 0:u.call(a,{formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,status:this.status,invalid:this.invalid}))??this.$slots.default}})}});return{errors:l,status:o,formData:t,VvForm:i}},T=(e,s)=>r.defineComponent({name:"WrapperComponent",props:{name:{type:String,required:!0},tag:{type:String,default:void 0}},emits:["invalid","valid"],expose:["fields","invalid"],setup(l,{emit:o}){const t=r.inject(e),i=r.inject(s,void 0),a=r.ref(new Set),u=r.ref(new Map),{name:n}=r.toRefs(l);r.provide(s,{name:r.readonly(n),errors:u,fields:a}),r.watch(a,y=>{i!=null&&i.fields&&y.forEach(m=>{i==null||i.fields.value.add(m)})},{deep:!0}),r.watch(()=>new Map(u.value),(y,m)=>{i!=null&&i.errors&&(Array.from(m.keys()).forEach(v=>{i.errors.value.delete(v)}),Array.from(y.keys()).forEach(v=>{const b=y.get(v);b&&i.errors.value.set(v,b)}))},{deep:!0});const h=r.computed(()=>t!=null&&t.invalid.value?u.value.size>0:!1);return r.watch(h,()=>{h.value?o("invalid"):o("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:h,fields:a,fieldsErrors:u}},render(){var l,o;return this.tag?r.h(this.tag,null,{default:()=>{var t,i;return((i=(t=this.$slots).default)==null?void 0:i.call(t,{invalid:this.invalid,formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}):((o=(l=this.$slots).default)==null?void 0:o.call(l,{invalid:this.invalid,formData:this.formData,submit:this.submit,validate:this.validate,errors:this.errors,fieldsErrors:this.fieldsErrors}))??this.$slots.defalut}}),R=(e,s)=>{const f=r.defineComponent({props:{schema:{type:[Array,Function],required:!0}},setup(l,{slots:o}){const t=r.inject(e);if(!(t!=null&&t.formData))return;const i=typeof l.schema=="function"?l.schema(t):l.schema;let a;return()=>{var u;return i.reduce((n,h)=>{const y=typeof h=="function"?h(t):h,{vvIs:m,vvName:v,vvSlots:b,vvChildren:w,vvIf:g,vvElseIf:V,vvType:E,vvDefaultValue:L,vvShowValid:Z,...c}=y;if(g!==void 0){if(typeof g=="string"?a=!!C(Object(t.formData.value),g):typeof g=="function"?a=r.unref(g(t)):a=r.unref(g),!a)return n}else if(V!==void 0&&a!==void 0){if(a||(typeof V=="string"?a=!!C(Object(t.formData.value),V):typeof V=="function"?a=r.unref(V(t)):a=r.unref(V),!a))return n}else a=void 0;const N=w?r.h(f,{schema:w}):void 0;return v?(n.push(r.h(s,{name:v,is:m,type:E,defaultValue:L,showValid:Z,props:c},b??N)),n):m?(n.push(r.h(m,c,b??N)),n):(w&&n.push(N),n)},[(u=o==null?void 0:o.default)==null?void 0:u.call(o,{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})])}}});return f},S=(e,s={})=>{const f=Symbol(),l=Symbol(),o=Symbol(),{VvForm:t,errors:i,status:a,formData:u}=P(e,f,s),n=T(f,l),h=J(f,l,o,s),y=R(f,h);return{VvForm:t,VvFormWrapper:n,VvFormField:h,VvFormTemplate:y,formInjectionKey:f,formWrapperInjectionKey:l,formFieldInjectionKey:o,errors:i,status:a,formData:u}},B=Symbol(),H=e=>{let s={};return e.schema&&(s=S(e.schema,e)),{...s,install(f,{global:l=!1}={}){f.provide(B,e),l&&(f.config.globalProperties.$vvForm=e,s!=null&&s.VvForm&&f.component("VvForm",s.VvForm),s!=null&&s.VvFormWrapper&&f.component("VvFormWrapper",s.VvFormWrapper),s!=null&&s.VvFormField&&f.component("VvFormField",s.VvFormField),s!=null&&s.VvFormTemplate&&f.component("VvFormTemplate",s.VvFormTemplate))}}},Q=(e,s={})=>r.getCurrentInstance()?S(e,{...r.inject(B,{}),...s}):S(e,s),X=(e,s={})=>S(e,s);p.FormFieldType=d,p.createForm=H,p.defaultObjectBySchema=$,p.formFactory=X,p.pluginInjectionKey=B,p.useForm=Q,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -19,7 +19,7 @@
19
19
  "bugs": {
20
20
  "url": "https://github.com/volverjs/form-vue/issues"
21
21
  },
22
- "version": "0.0.11",
22
+ "version": "0.0.12-beta.2",
23
23
  "engines": {
24
24
  "node": ">= 16.x"
25
25
  },
@@ -38,31 +38,31 @@
38
38
  "@volverjs/ui-vue": "0.0.6-beta.7",
39
39
  "@vueuse/core": "^10.1.2",
40
40
  "ts-dot-prop": "^2.1.2",
41
- "vue": "^3.2.47",
41
+ "vue": "^3.3.2",
42
42
  "zod": "^3.21.4"
43
43
  },
44
44
  "devDependencies": {
45
- "@playwright/experimental-ct-vue": "^1.32.3",
45
+ "@playwright/experimental-ct-vue": "1.32.3",
46
46
  "@testing-library/vue": "^7.0.0",
47
- "@typescript-eslint/eslint-plugin": "^5.59.2",
48
- "@typescript-eslint/parser": "^5.59.2",
49
- "@vitejs/plugin-vue": "^4.2.1",
50
- "@volverjs/style": "^0.1.8",
51
- "@vue/compiler-sfc": "^3.2.47",
52
- "@vue/runtime-core": "^3.2.47",
47
+ "@typescript-eslint/eslint-plugin": "^5.59.6",
48
+ "@typescript-eslint/parser": "^5.59.6",
49
+ "@vitejs/plugin-vue": "^4.2.3",
50
+ "@volverjs/style": "^0.1.10",
51
+ "@vue/compiler-sfc": "^3.3.2",
52
+ "@vue/runtime-core": "^3.3.2",
53
53
  "@vue/test-utils": "^2.3.2",
54
54
  "copy": "^0.3.2",
55
- "eslint": "^8.39.0",
55
+ "eslint": "^8.40.0",
56
56
  "eslint-config-prettier": "^8.8.0",
57
57
  "eslint-plugin-prettier": "^4.2.1",
58
- "happy-dom": "^9.10.4",
58
+ "happy-dom": "^9.18.3",
59
59
  "prettier": "^2.8.8",
60
60
  "typescript": "^5.0.4",
61
- "vite": "^4.3.4",
61
+ "vite": "^4.3.7",
62
62
  "vite-plugin-eslint": "^1.8.1",
63
63
  "vite-plugin-externalize-deps": "^0.6.0",
64
64
  "vitest": "^0.30.1",
65
- "vue-tsc": "^1.6.3"
65
+ "vue-tsc": "^1.6.5"
66
66
  },
67
67
  "typesVersions": {
68
68
  "*": {
package/src/utils.ts CHANGED
@@ -7,6 +7,7 @@ import {
7
7
  ZodEffects,
8
8
  ZodSchema,
9
9
  ZodNullable,
10
+ ZodOptional,
10
11
  } from 'zod'
11
12
  import type { FormSchema } from './types'
12
13
 
@@ -15,12 +16,19 @@ export const defaultObjectBySchema = <Schema extends FormSchema>(
15
16
  original: Partial<z.infer<Schema>> = {},
16
17
  ): Partial<z.infer<Schema>> => {
17
18
  const getInnerType = <Type extends ZodTypeAny>(
18
- schema: Type | ZodEffects<Type> | ZodEffects<ZodEffects<Type>>,
19
+ schema:
20
+ | Type
21
+ | ZodEffects<Type>
22
+ | ZodEffects<ZodEffects<Type>>
23
+ | ZodOptional<Type>,
19
24
  ) => {
20
25
  let toReturn = schema
21
26
  while (toReturn instanceof ZodEffects) {
22
27
  toReturn = toReturn.innerType()
23
28
  }
29
+ while (toReturn instanceof ZodOptional) {
30
+ toReturn = toReturn._def.innerType
31
+ }
24
32
  return toReturn
25
33
  }
26
34
  const innerType = getInnerType<AnyZodObject>(schema)