@volverjs/form-vue 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -214,7 +214,7 @@ You can also use the `VvFormField` component to render a default slot without a
214
214
  invalidLabel,
215
215
  formData,
216
216
  formErrors,
217
- erros,
217
+ errors,
218
218
  onUpdate
219
219
  }"
220
220
  name="surname"
package/dist/VvForm.d.ts CHANGED
@@ -1,12 +1,13 @@
1
1
  import { type InjectionKey } from 'vue';
2
- import type { AnyZodObject } from 'zod';
2
+ import type { AnyZodObject, ZodEffects } from 'zod';
3
3
  import type { InjectedFormData } from './types';
4
4
  export declare enum FormStatus {
5
5
  invalid = "invalid",
6
6
  valid = "valid"
7
7
  }
8
- export declare const defineForm: (schema: AnyZodObject, provideKey: InjectionKey<InjectedFormData>, options?: {
8
+ export declare const defineForm: (schema: AnyZodObject | ZodEffects<AnyZodObject>, provideKey: InjectionKey<InjectedFormData>, options?: {
9
9
  updateThrottle?: number;
10
+ continuosValidation?: boolean;
10
11
  }) => import("vue").DefineComponent<{
11
12
  modelValue: {
12
13
  type: ObjectConstructor;
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { type InjectionKey, type Plugin } from 'vue';
2
- import type { AnyZodObject } from 'zod';
2
+ import type { AnyZodObject, ZodEffects } from 'zod';
3
3
  import { defineFormField } from './VvFormField';
4
4
  import { defineForm } from './VvForm';
5
5
  import { defineFormWrapper } from './VvFormWrapper';
6
6
  import type { InjectedFormData, InjectedFormWrapperData, InjectedFormFieldData, FormComposableOptions, FormPluginOptions } from './types';
7
- export declare const formFactory: (schema: AnyZodObject, options?: FormComposableOptions) => {
7
+ export declare const formFactory: (schema: AnyZodObject | ZodEffects<AnyZodObject>, options?: FormComposableOptions) => {
8
8
  VvForm: import("vue").DefineComponent<{
9
9
  modelValue: {
10
10
  type: ObjectConstructor;
@@ -63,7 +63,7 @@ export declare const formFactory: (schema: AnyZodObject, options?: FormComposabl
63
63
  };
64
64
  export declare const pluginInjectionKey: InjectionKey<FormPluginOptions>;
65
65
  export declare const createForm: (options: FormPluginOptions) => Plugin & Partial<ReturnType<typeof useForm>>;
66
- export declare const useForm: (schema: AnyZodObject, options?: FormComposableOptions) => {
66
+ export declare const useForm: (schema: AnyZodObject | ZodEffects<AnyZodObject>, options?: FormComposableOptions) => {
67
67
  VvForm: import("vue").DefineComponent<{
68
68
  modelValue: {
69
69
  type: ObjectConstructor;
package/dist/index.es.js CHANGED
@@ -1,10 +1,10 @@
1
- import { defineComponent as w, computed as h, onMounted as q, inject as S, toRefs as G, watch as V, provide as $, readonly as A, resolveComponent as b, defineAsyncComponent as Z, h as O, ref as x, isProxy as Y, toRaw as H, withModifiers as Q } from "vue";
1
+ import { defineComponent as w, computed as h, onMounted as Z, inject as S, toRefs as G, watch as V, provide as $, readonly as M, resolveComponent as b, defineAsyncComponent as q, h as O, ref as x, isProxy as Y, toRaw as H, withModifiers as Q } from "vue";
2
2
  import { watchThrottled as X } from "@vueuse/core";
3
- import { ZodDefault as P, ZodObject as T } from "zod";
4
- function E(e) {
3
+ import { ZodEffects as P, ZodDefault as T, ZodObject as F } from "zod";
4
+ function A(e) {
5
5
  return Array.isArray(e);
6
6
  }
7
- function F(e) {
7
+ function ee(e) {
8
8
  return typeof e < "u";
9
9
  }
10
10
  function N(e) {
@@ -16,26 +16,26 @@ function L(e) {
16
16
  function D(e) {
17
17
  return typeof e == "string";
18
18
  }
19
- function M(e) {
19
+ function E(e) {
20
20
  return typeof e > "u";
21
21
  }
22
- const ee = /^[0-9]+$/, re = ["__proto__", "prototype", "constructor"];
22
+ const re = /^[0-9]+$/, te = ["__proto__", "prototype", "constructor"];
23
23
  function _(e, r, t) {
24
- const a = F(t) ? t : void 0;
24
+ const a = ee(t) ? t : void 0;
25
25
  if (!L(e) || !D(r))
26
26
  return a;
27
27
  const n = W(r);
28
28
  if (n.length !== 0) {
29
- for (const o of n) {
30
- if (o === "*")
29
+ for (const u of n) {
30
+ if (u === "*")
31
31
  continue;
32
32
  const i = function(s) {
33
- return s.map((f) => M(f) || N(f) ? f : E(f) ? i(f) : f[o]);
33
+ return s.map((f) => E(f) || N(f) ? f : A(f) ? i(f) : f[u]);
34
34
  };
35
- if (E(e) && !ee.test(o) ? e = i(e) : e = e[o], M(e) || N(e))
35
+ if (A(e) && !re.test(u) ? e = i(e) : e = e[u], E(e) || N(e))
36
36
  break;
37
37
  }
38
- return M(e) ? a : e;
38
+ return E(e) ? a : e;
39
39
  }
40
40
  }
41
41
  function U(e, r, t) {
@@ -45,27 +45,27 @@ function U(e, r, t) {
45
45
  if (a.length === 0)
46
46
  return;
47
47
  const n = a.length;
48
- for (let o = 0; o < n; o++) {
49
- const i = a[o];
50
- if (o === n - 1) {
48
+ for (let u = 0; u < n; u++) {
49
+ const i = a[u];
50
+ if (u === n - 1) {
51
51
  e[i] = t;
52
52
  return;
53
53
  }
54
- if (i === "*" && E(e)) {
55
- const s = a.slice(o + 1).join(".");
54
+ if (i === "*" && A(e)) {
55
+ const s = a.slice(u + 1).join(".");
56
56
  for (const f of e)
57
57
  U(f, s, t);
58
58
  return;
59
59
  }
60
- M(e[i]) && (e[i] = {}), e = e[i];
60
+ E(e[i]) && (e[i] = {}), e = e[i];
61
61
  }
62
62
  }
63
63
  function W(e) {
64
64
  const r = e.split(/[.]|(?:\[(\d|\*)\])/).filter((t) => !!t);
65
- return r.some((t) => re.indexOf(t) !== -1) ? [] : r;
65
+ return r.some((t) => te.indexOf(t) !== -1) ? [] : r;
66
66
  }
67
67
  var l = /* @__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))(l || {});
68
- const te = (e, r, t, a = {}) => w({
68
+ const ne = (e, r, t, a = {}) => w({
69
69
  name: "FieldComponent",
70
70
  props: {
71
71
  type: {
@@ -96,34 +96,34 @@ const te = (e, r, t, a = {}) => w({
96
96
  },
97
97
  emits: ["invalid", "valid", "update:formData", "update:modelValue"],
98
98
  expose: ["invalid", "invalidLabel", "errors"],
99
- setup(n, { slots: o, emit: i }) {
99
+ setup(n, { slots: u, emit: i }) {
100
100
  const s = h({
101
101
  get() {
102
- if (u != null && u.modelValue)
102
+ if (o != null && o.modelValue)
103
103
  return _(
104
- Object(u.modelValue.value),
104
+ Object(o.modelValue.value),
105
105
  String(n.name)
106
106
  );
107
107
  },
108
108
  set(c) {
109
- u != null && u.modelValue && (U(
110
- Object(u.modelValue.value),
109
+ o != null && o.modelValue && (U(
110
+ Object(o.modelValue.value),
111
111
  String(n.name),
112
112
  c
113
113
  ), i("update:modelValue", {
114
114
  newValue: s.value,
115
- formData: u == null ? void 0 : u.modelValue
115
+ formData: o == null ? void 0 : o.modelValue
116
116
  }));
117
117
  }
118
118
  });
119
- q(() => {
119
+ Z(() => {
120
120
  s.value === void 0 && n.defaultValue !== void 0 && (s.value = n.defaultValue);
121
121
  });
122
122
  const f = S(r, void 0);
123
123
  f && f.fields.value.add(n.name);
124
- const u = S(e), { props: d, name: m } = G(n), v = h(() => {
125
- if (u != null && u.errors.value)
126
- return _(u.errors.value, String(n.name));
124
+ const o = S(e), { props: d, name: m } = G(n), v = h(() => {
125
+ if (o != null && o.errors.value)
126
+ return _(o.errors.value, String(n.name));
127
127
  }), y = h(() => {
128
128
  var c;
129
129
  return (c = v.value) == null ? void 0 : c._errors;
@@ -135,15 +135,15 @@ const te = (e, r, t, a = {}) => w({
135
135
  n.name
136
136
  ));
137
137
  }), V(
138
- () => u == null ? void 0 : u.modelValue,
138
+ () => o == null ? void 0 : o.modelValue,
139
139
  () => {
140
- i("update:formData", u == null ? void 0 : u.modelValue);
140
+ i("update:formData", o == null ? void 0 : o.modelValue);
141
141
  },
142
142
  { deep: !0 }
143
143
  );
144
144
  const k = (c) => {
145
145
  s.value = c;
146
- }, I = h(() => typeof d.value == "function" ? d.value(u == null ? void 0 : u.modelValue) : d.value), R = h(() => ({
146
+ }, I = h(() => typeof d.value == "function" ? d.value(o == null ? void 0 : o.modelValue) : d.value), R = h(() => ({
147
147
  ...I.value,
148
148
  name: I.value.name ?? n.name,
149
149
  invalid: p.value,
@@ -172,22 +172,22 @@ const te = (e, r, t, a = {}) => w({
172
172
  "onUpdate:modelValue": k
173
173
  }));
174
174
  return $(t, {
175
- name: A(m),
176
- errors: A(v)
175
+ name: M(m),
176
+ errors: M(v)
177
177
  }), { component: h(() => {
178
178
  if (n.type === l.custom)
179
179
  return {
180
180
  render() {
181
181
  var c;
182
- return ((c = o.default) == null ? void 0 : c.call(o, {
182
+ return ((c = u.default) == null ? void 0 : c.call(u, {
183
183
  modelValue: s.value,
184
184
  onUpdate: k,
185
185
  invalid: p.value,
186
186
  invalidLabel: y.value,
187
- formData: u == null ? void 0 : u.modelValue.value,
188
- formErrors: u == null ? void 0 : u.errors.value,
187
+ formData: o == null ? void 0 : o.modelValue.value,
188
+ formErrors: o == null ? void 0 : o.errors.value,
189
189
  errors: v.value
190
- })) ?? o.defalut;
190
+ })) ?? u.defalut;
191
191
  }
192
192
  };
193
193
  if (!a.lazyLoad) {
@@ -223,7 +223,7 @@ const te = (e, r, t, a = {}) => w({
223
223
  `[form-vue warn]: ${c} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`
224
224
  );
225
225
  }
226
- return Z(async () => {
226
+ return q(async () => {
227
227
  switch (a.sideEffects && await Promise.resolve(a.sideEffects(n.type)), n.type) {
228
228
  case l.textarea:
229
229
  return import("@volverjs/ui-vue/vv-textarea");
@@ -246,44 +246,44 @@ const te = (e, r, t, a = {}) => w({
246
246
  return this.is ? O(this.is, this.hasProps, this.$slots) : this.type === l.custom ? O(this.component, null, this.$slots) : O(this.component, this.hasProps, this.$slots);
247
247
  }
248
248
  });
249
- var ne = function(r) {
250
- return ae(r) && !oe(r);
249
+ var ae = function(r) {
250
+ return ue(r) && !oe(r);
251
251
  };
252
- function ae(e) {
252
+ function ue(e) {
253
253
  return !!e && typeof e == "object";
254
254
  }
255
255
  function oe(e) {
256
256
  var r = Object.prototype.toString.call(e);
257
- return r === "[object RegExp]" || r === "[object Date]" || ie(e);
258
- }
259
- var ue = typeof Symbol == "function" && Symbol.for, le = ue ? Symbol.for("react.element") : 60103;
260
- function ie(e) {
261
- return e.$$typeof === le;
257
+ return r === "[object RegExp]" || r === "[object Date]" || se(e);
262
258
  }
259
+ var le = typeof Symbol == "function" && Symbol.for, ie = le ? Symbol.for("react.element") : 60103;
263
260
  function se(e) {
261
+ return e.$$typeof === ie;
262
+ }
263
+ function ce(e) {
264
264
  return Array.isArray(e) ? [] : {};
265
265
  }
266
266
  function j(e, r) {
267
- return r.clone !== !1 && r.isMergeableObject(e) ? g(se(e), e, r) : e;
267
+ return r.clone !== !1 && r.isMergeableObject(e) ? g(ce(e), e, r) : e;
268
268
  }
269
- function ce(e, r, t) {
269
+ function fe(e, r, t) {
270
270
  return e.concat(r).map(function(a) {
271
271
  return j(a, t);
272
272
  });
273
273
  }
274
- function fe(e, r) {
274
+ function de(e, r) {
275
275
  if (!r.customMerge)
276
276
  return g;
277
277
  var t = r.customMerge(e);
278
278
  return typeof t == "function" ? t : g;
279
279
  }
280
- function de(e) {
280
+ function me(e) {
281
281
  return Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(e).filter(function(r) {
282
282
  return Object.propertyIsEnumerable.call(e, r);
283
283
  }) : [];
284
284
  }
285
285
  function C(e) {
286
- return Object.keys(e).concat(de(e));
286
+ return Object.keys(e).concat(me(e));
287
287
  }
288
288
  function B(e, r) {
289
289
  try {
@@ -292,21 +292,21 @@ function B(e, r) {
292
292
  return !1;
293
293
  }
294
294
  }
295
- function me(e, r) {
295
+ function ve(e, r) {
296
296
  return B(e, r) && !(Object.hasOwnProperty.call(e, r) && Object.propertyIsEnumerable.call(e, r));
297
297
  }
298
- function ve(e, r, t) {
298
+ function be(e, r, t) {
299
299
  var a = {};
300
300
  return t.isMergeableObject(e) && C(e).forEach(function(n) {
301
301
  a[n] = j(e[n], t);
302
302
  }), C(r).forEach(function(n) {
303
- me(e, n) || (B(e, n) && t.isMergeableObject(r[n]) ? a[n] = fe(n, t)(e[n], r[n], t) : a[n] = j(r[n], t));
303
+ ve(e, n) || (B(e, n) && t.isMergeableObject(r[n]) ? a[n] = de(n, t)(e[n], r[n], t) : a[n] = j(r[n], t));
304
304
  }), a;
305
305
  }
306
306
  function g(e, r, t) {
307
- t = t || {}, t.arrayMerge = t.arrayMerge || ce, t.isMergeableObject = t.isMergeableObject || ne, t.cloneUnlessOtherwiseSpecified = j;
308
- var a = Array.isArray(r), n = Array.isArray(e), o = a === n;
309
- return o ? a ? t.arrayMerge(e, r, t) : ve(e, r, t) : j(r, t);
307
+ t = t || {}, t.arrayMerge = t.arrayMerge || fe, t.isMergeableObject = t.isMergeableObject || ae, t.cloneUnlessOtherwiseSpecified = j;
308
+ var a = Array.isArray(r), n = Array.isArray(e), u = a === n;
309
+ return u ? a ? t.arrayMerge(e, r, t) : be(e, r, t) : j(r, t);
310
310
  }
311
311
  g.all = function(r, t) {
312
312
  if (!Array.isArray(r))
@@ -315,13 +315,16 @@ g.all = function(r, t) {
315
315
  return g(a, n, t);
316
316
  }, {});
317
317
  };
318
- var be = g, he = be;
319
- const J = (e, r = {}) => he(
320
- Object.fromEntries(
321
- Object.entries(e.shape).map(([t, a]) => a instanceof P ? [t, a._def.defaultValue()] : a instanceof T ? [t, J(a)] : [t, void 0])
322
- ),
323
- r
324
- ), ye = (e, r, t) => w({
318
+ var he = g, ye = he;
319
+ const J = (e, r = {}) => {
320
+ const t = e instanceof P ? e.innerType().shape : e.shape;
321
+ return ye(
322
+ Object.fromEntries(
323
+ Object.entries(t).map(([a, n]) => n instanceof T ? [a, n._def.defaultValue()] : n instanceof F ? [a, J(n)] : [a, void 0])
324
+ ),
325
+ r
326
+ );
327
+ }, pe = (e, r, t) => w({
325
328
  name: "FormComponent",
326
329
  props: {
327
330
  modelValue: {
@@ -332,7 +335,7 @@ const J = (e, r = {}) => he(
332
335
  emits: ["invalid", "valid", "submit", "update:modelValue"],
333
336
  expose: ["submit", "errors", "status"],
334
337
  setup(a, { emit: n }) {
335
- const o = x(
338
+ const u = x(
336
339
  J(e, a.modelValue)
337
340
  );
338
341
  V(
@@ -340,26 +343,26 @@ const J = (e, r = {}) => he(
340
343
  (d) => {
341
344
  if (d) {
342
345
  const m = Y(d) ? H(d) : d;
343
- o.value = typeof (m == null ? void 0 : m.clone) == "function" ? m.clone() : JSON.parse(JSON.stringify(m));
346
+ u.value = typeof (m == null ? void 0 : m.clone) == "function" ? m.clone() : JSON.parse(JSON.stringify(m));
344
347
  }
345
348
  },
346
349
  { deep: !0 }
347
350
  ), X(
348
- o,
351
+ u,
349
352
  (d) => {
350
- i.value && f(), (!d || !a.modelValue || JSON.stringify(d) !== JSON.stringify(a.modelValue)) && n("update:modelValue", d);
353
+ (i.value || t != null && t.continuosValidation) && f(), (!d || !a.modelValue || JSON.stringify(d) !== JSON.stringify(a.modelValue)) && n("update:modelValue", d);
351
354
  },
352
355
  { deep: !0, throttle: (t == null ? void 0 : t.updateThrottle) ?? 500 }
353
356
  );
354
- const i = x(), s = x(), f = (d = o.value) => {
357
+ const i = x(), s = x(), f = (d = u.value) => {
355
358
  const m = e.safeParse(d);
356
- return m.success ? (i.value = void 0, s.value = "valid", o.value = m.data, n("valid", m.data), !0) : (i.value = m.error.format(), s.value = "invalid", n("invalid", i.value), !1);
357
- }, u = () => f() ? (n("submit", o.value), !0) : !1;
359
+ return m.success ? (i.value = void 0, s.value = "valid", u.value = m.data, n("valid", m.data), !0) : (i.value = m.error.format(), s.value = "invalid", n("invalid", i.value), !1);
360
+ }, o = () => f() ? (n("submit", u.value), !0) : !1;
358
361
  return $(r, {
359
- modelValue: o,
360
- submit: u,
361
- errors: A(i)
362
- }), { submit: u };
362
+ modelValue: u,
363
+ submit: o,
364
+ errors: M(i)
365
+ }), { submit: o };
363
366
  },
364
367
  render() {
365
368
  return O(
@@ -370,7 +373,7 @@ const J = (e, r = {}) => he(
370
373
  this.$slots
371
374
  );
372
375
  }
373
- }), pe = (e, r) => w({
376
+ }), Ve = (e, r) => w({
374
377
  name: "WrapperComponent",
375
378
  props: {
376
379
  name: {
@@ -385,48 +388,48 @@ const J = (e, r = {}) => he(
385
388
  emits: ["invalid", "valid"],
386
389
  expose: ["fields", "invalid"],
387
390
  setup(t, { emit: a }) {
388
- const n = S(e), o = S(r, void 0), i = x(/* @__PURE__ */ new Set()), s = x(/* @__PURE__ */ new Map()), { name: f } = G(t);
391
+ const n = S(e), u = S(r, void 0), i = x(/* @__PURE__ */ new Set()), s = x(/* @__PURE__ */ new Map()), { name: f } = G(t);
389
392
  $(r, {
390
- name: A(f),
393
+ name: M(f),
391
394
  errors: s,
392
395
  fields: i
393
396
  }), V(
394
397
  i,
395
398
  (d) => {
396
- o != null && o.fields && d.forEach((m) => {
397
- o == null || o.fields.value.add(m);
399
+ u != null && u.fields && d.forEach((m) => {
400
+ u == null || u.fields.value.add(m);
398
401
  });
399
402
  },
400
403
  { deep: !0 }
401
404
  ), V(
402
405
  () => new Map(s.value),
403
406
  (d, m) => {
404
- o != null && o.errors && (Array.from(m.keys()).forEach((v) => {
405
- o.errors.value.delete(v);
407
+ u != null && u.errors && (Array.from(m.keys()).forEach((v) => {
408
+ u.errors.value.delete(v);
406
409
  }), Array.from(d.keys()).forEach((v) => {
407
410
  const y = d.get(v);
408
- y && o.errors.value.set(v, y);
411
+ y && u.errors.value.set(v, y);
409
412
  }));
410
413
  },
411
414
  { deep: !0 }
412
415
  );
413
- const u = h(() => n != null && n.errors.value ? s.value.size > 0 : !1);
414
- return V(u, () => {
415
- u.value ? a("invalid") : a("valid");
416
- }), { formProvided: n, invalid: u, fields: i, errors: s };
416
+ const o = h(() => n != null && n.errors.value ? s.value.size > 0 : !1);
417
+ return V(o, () => {
418
+ o.value ? a("invalid") : a("valid");
419
+ }), { formProvided: n, invalid: o, fields: i, errors: s };
417
420
  },
418
421
  render() {
419
- var t, a, n, o, i, s, f, u;
422
+ var t, a, n, u, i, s, f, o;
420
423
  return this.tag ? O(
421
424
  this.tag,
422
425
  null,
423
- ((o = (n = this.$slots).default) == null ? void 0 : o.call(n, {
426
+ ((u = (n = this.$slots).default) == null ? void 0 : u.call(n, {
424
427
  invalid: this.invalid,
425
428
  formData: (t = this.formProvided) == null ? void 0 : t.modelValue,
426
429
  errors: (a = this.formProvided) == null ? void 0 : a.errors,
427
430
  fieldsErrors: this.errors
428
431
  })) ?? this.$slots.defalut
429
- ) : ((u = (f = this.$slots).default) == null ? void 0 : u.call(f, {
432
+ ) : ((o = (f = this.$slots).default) == null ? void 0 : o.call(f, {
430
433
  invalid: this.invalid,
431
434
  formData: (i = this.formProvided) == null ? void 0 : i.modelValue,
432
435
  errors: (s = this.formProvided) == null ? void 0 : s.errors,
@@ -434,24 +437,24 @@ const J = (e, r = {}) => he(
434
437
  })) ?? this.$slots.defalut;
435
438
  }
436
439
  }), K = (e, r = {}) => {
437
- const t = Symbol(), a = Symbol(), n = Symbol(), o = ye(e, t, r), i = pe(
440
+ const t = Symbol(), a = Symbol(), n = Symbol(), u = pe(e, t, r), i = Ve(
438
441
  t,
439
442
  a
440
- ), s = te(
443
+ ), s = ne(
441
444
  t,
442
445
  a,
443
446
  n,
444
447
  r
445
448
  );
446
449
  return {
447
- VvForm: o,
450
+ VvForm: u,
448
451
  VvFormWrapper: i,
449
452
  VvFormField: s,
450
453
  formInjectionKey: t,
451
454
  formWrapperInjectionKey: a,
452
455
  formFieldInjectionKey: n
453
456
  };
454
- }, z = Symbol(), Se = (e) => {
457
+ }, z = Symbol(), je = (e) => {
455
458
  let r = {};
456
459
  return e.schema && (r = K(e.schema, e)), {
457
460
  ...r,
@@ -459,15 +462,15 @@ const J = (e, r = {}) => he(
459
462
  t.provide(z, e), a && (t.config.globalProperties.$vvForm = e, r != null && r.VvForm && t.component("VvForm", r.VvForm), r != null && r.VvFormWrapper && t.component("VvFormWrapper", r.VvFormWrapper), r != null && r.VvFormField && t.component("VvFormField", r.VvFormField));
460
463
  }
461
464
  };
462
- }, je = (e, r = {}) => {
465
+ }, Ee = (e, r = {}) => {
463
466
  const t = { ...S(z, {}), ...r };
464
467
  return K(e, t);
465
468
  };
466
469
  export {
467
470
  l as FormFieldType,
468
- Se as createForm,
471
+ je as createForm,
469
472
  J as defaultObjectBySchema,
470
473
  K as formFactory,
471
474
  z as pluginInjectionKey,
472
- je as useForm
475
+ Ee as useForm
473
476
  };
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(b,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("vue"),require("@vueuse/core"),require("zod")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","zod"],n):(b=typeof globalThis<"u"?globalThis:b||self,n(b["@volverjs/form-vue"]={},b.Vue,b.VueUseCore,b.zod))})(this,function(b,n,D,M){"use strict";function S(e){return Array.isArray(e)}function U(e){return typeof e<"u"}function A(e){return e===null}function E(e){return typeof e=="object"}function C(e){return typeof e=="string"}function O(e){return typeof e>"u"}const W=/^[0-9]+$/,B=["__proto__","prototype","constructor"];function $(e,r,t){const o=U(t)?t:void 0;if(!E(e)||!C(r))return o;const a=I(r);if(a.length!==0){for(const l of a){if(l==="*")continue;const c=function(u){return u.map(d=>O(d)||A(d)?d:S(d)?c(d):d[l])};if(S(e)&&!W.test(l)?e=c(e):e=e[l],O(e)||A(e))break}return O(e)?o:e}}function k(e,r,t){if(!E(e)||!C(r))return;const o=I(r);if(o.length===0)return;const a=o.length;for(let l=0;l<a;l++){const c=o[l];if(l===a-1){e[c]=t;return}if(c==="*"&&S(e)){const u=o.slice(l+1).join(".");for(const d of e)k(d,u,t);return}O(e[c])&&(e[c]={}),e=e[c]}}function I(e){const r=e.split(/[.]|(?:\[(\d|\*)\])/).filter(t=>!!t);return r.some(t=>B.indexOf(t)!==-1)?[]:r}var s=(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))(s||{});const q=(e,r,t,o={})=>n.defineComponent({name:"FieldComponent",props:{type:{type:String,validator:a=>Object.values(s).includes(a),default:s.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}},emits:["invalid","valid","update:formData","update:modelValue"],expose:["invalid","invalidLabel","errors"],setup(a,{slots:l,emit:c}){const u=n.computed({get(){if(i!=null&&i.modelValue)return $(Object(i.modelValue.value),String(a.name))},set(f){i!=null&&i.modelValue&&(k(Object(i.modelValue.value),String(a.name),f),c("update:modelValue",{newValue:u.value,formData:i==null?void 0:i.modelValue}))}});n.onMounted(()=>{u.value===void 0&&a.defaultValue!==void 0&&(u.value=a.defaultValue)});const d=n.inject(r,void 0);d&&d.fields.value.add(a.name);const i=n.inject(e),{props:m,name:h}=n.toRefs(a),p=n.computed(()=>{if(i!=null&&i.errors.value)return $(i.errors.value,String(a.name))}),v=n.computed(()=>{var f;return(f=p.value)==null?void 0:f._errors}),V=n.computed(()=>p.value!==void 0);n.watch(V,()=>{V.value?(c("invalid",v.value),d&&d.errors.value.set(a.name,{_errors:v.value})):(c("valid",u.value),d&&d.errors.value.delete(a.name))}),n.watch(()=>i==null?void 0:i.modelValue,()=>{c("update:formData",i==null?void 0:i.modelValue)},{deep:!0});const G=f=>{u.value=f},L=n.computed(()=>typeof m.value=="function"?m.value(i==null?void 0:i.modelValue):m.value),le=n.computed(()=>({...L.value,name:L.value.name??a.name,invalid:V.value,valid:a.showValid?Boolean(!V.value&&u.value):void 0,type:(f=>{if([s.text,s.number,s.email,s.password,s.tel,s.url,s.search,s.date,s.time,s.datetimeLocal,s.month,s.week,s.color].includes(f))return f})(a.type),invalidLabel:v.value,modelValue:u.value,errors:a.is?p.value:void 0,"onUpdate:modelValue":G}));return n.provide(t,{name:n.readonly(h),errors:n.readonly(p)}),{component:n.computed(()=>{if(a.type===s.custom)return{render(){var f;return((f=l.default)==null?void 0:f.call(l,{modelValue:u.value,onUpdate:G,invalid:V.value,invalidLabel:v.value,formData:i==null?void 0:i.modelValue.value,formErrors:i==null?void 0:i.errors.value,errors:p.value}))??l.defalut}};if(!o.lazyLoad){let f;switch(a.type){case s.select:f=n.resolveComponent("VvSelect");break;case s.checkbox:f=n.resolveComponent("VvCheckbox");break;case s.radio:f=n.resolveComponent("VvRadio");break;case s.textarea:f=n.resolveComponent("VvTextarea");break;case s.radioGroup:f=n.resolveComponent("VvRadioGroup");break;case s.checkboxGroup:f=n.resolveComponent("VvCheckboxGroup");break;case s.combobox:f=n.resolveComponent("VvCombobox");break;default:f=n.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 n.defineAsyncComponent(async()=>{switch(o.sideEffects&&await Promise.resolve(o.sideEffects(a.type)),a.type){case s.textarea:return import("@volverjs/ui-vue/vv-textarea");case s.radio:return import("@volverjs/ui-vue/vv-radio");case s.radioGroup:return import("@volverjs/ui-vue/vv-radio-group");case s.checkbox:return import("@volverjs/ui-vue/vv-checkbox");case s.checkboxGroup:return import("@volverjs/ui-vue/vv-checkbox-group");case s.combobox:return import("@volverjs/ui-vue/vv-combobox")}return import("@volverjs/ui-vue/vv-input-text")})}),hasProps:le,invalid:V}},render(){return this.is?n.h(this.is,this.hasProps,this.$slots):this.type===s.custom?n.h(this.component,null,this.$slots):n.h(this.component,this.hasProps,this.$slots)}});var z=function(r){return K(r)&&!J(r)};function K(e){return!!e&&typeof e=="object"}function J(e){var r=Object.prototype.toString.call(e);return r==="[object RegExp]"||r==="[object Date]"||Y(e)}var R=typeof Symbol=="function"&&Symbol.for,Z=R?Symbol.for("react.element"):60103;function Y(e){return e.$$typeof===Z}function H(e){return Array.isArray(e)?[]:{}}function g(e,r){return r.clone!==!1&&r.isMergeableObject(e)?y(H(e),e,r):e}function Q(e,r,t){return e.concat(r).map(function(o){return g(o,t)})}function X(e,r){if(!r.customMerge)return y;var t=r.customMerge(e);return typeof t=="function"?t:y}function P(e){return Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(e).filter(function(r){return Object.propertyIsEnumerable.call(e,r)}):[]}function N(e){return Object.keys(e).concat(P(e))}function _(e,r){try{return r in e}catch{return!1}}function F(e,r){return _(e,r)&&!(Object.hasOwnProperty.call(e,r)&&Object.propertyIsEnumerable.call(e,r))}function T(e,r,t){var o={};return t.isMergeableObject(e)&&N(e).forEach(function(a){o[a]=g(e[a],t)}),N(r).forEach(function(a){F(e,a)||(_(e,a)&&t.isMergeableObject(r[a])?o[a]=X(a,t)(e[a],r[a],t):o[a]=g(r[a],t))}),o}function y(e,r,t){t=t||{},t.arrayMerge=t.arrayMerge||Q,t.isMergeableObject=t.isMergeableObject||z,t.cloneUnlessOtherwiseSpecified=g;var o=Array.isArray(r),a=Array.isArray(e),l=o===a;return l?o?t.arrayMerge(e,r,t):T(e,r,t):g(r,t)}y.all=function(r,t){if(!Array.isArray(r))throw new Error("first argument should be an array");return r.reduce(function(o,a){return y(o,a,t)},{})};var ee=y,re=ee;const j=(e,r={})=>re(Object.fromEntries(Object.entries(e.shape).map(([t,o])=>o instanceof M.ZodDefault?[t,o._def.defaultValue()]:o instanceof M.ZodObject?[t,j(o)]:[t,void 0])),r),te=(e,r,t)=>n.defineComponent({name:"FormComponent",props:{modelValue:{type:Object,default:()=>({})}},emits:["invalid","valid","submit","update:modelValue"],expose:["submit","errors","status"],setup(o,{emit:a}){const l=n.ref(j(e,o.modelValue));n.watch(()=>o.modelValue,m=>{if(m){const h=n.isProxy(m)?n.toRaw(m):m;l.value=typeof(h==null?void 0:h.clone)=="function"?h.clone():JSON.parse(JSON.stringify(h))}},{deep:!0}),D.watchThrottled(l,m=>{c.value&&d(),(!m||!o.modelValue||JSON.stringify(m)!==JSON.stringify(o.modelValue))&&a("update:modelValue",m)},{deep:!0,throttle:(t==null?void 0:t.updateThrottle)??500});const c=n.ref(),u=n.ref(),d=(m=l.value)=>{const h=e.safeParse(m);return h.success?(c.value=void 0,u.value="valid",l.value=h.data,a("valid",h.data),!0):(c.value=h.error.format(),u.value="invalid",a("invalid",c.value),!1)},i=()=>d()?(a("submit",l.value),!0):!1;return n.provide(r,{modelValue:l,submit:i,errors:n.readonly(c)}),{submit:i}},render(){return n.h("form",{onSubmit:n.withModifiers(this.submit,["prevent"])},this.$slots)}}),ne=(e,r)=>n.defineComponent({name:"WrapperComponent",props:{name:{type:String,required:!0},tag:{type:String,default:void 0}},emits:["invalid","valid"],expose:["fields","invalid"],setup(t,{emit:o}){const a=n.inject(e),l=n.inject(r,void 0),c=n.ref(new Set),u=n.ref(new Map),{name:d}=n.toRefs(t);n.provide(r,{name:n.readonly(d),errors:u,fields:c}),n.watch(c,m=>{l!=null&&l.fields&&m.forEach(h=>{l==null||l.fields.value.add(h)})},{deep:!0}),n.watch(()=>new Map(u.value),(m,h)=>{l!=null&&l.errors&&(Array.from(h.keys()).forEach(p=>{l.errors.value.delete(p)}),Array.from(m.keys()).forEach(p=>{const v=m.get(p);v&&l.errors.value.set(p,v)}))},{deep:!0});const i=n.computed(()=>a!=null&&a.errors.value?u.value.size>0:!1);return n.watch(i,()=>{i.value?o("invalid"):o("valid")}),{formProvided:a,invalid:i,fields:c,errors:u}},render(){var t,o,a,l,c,u,d,i;return this.tag?n.h(this.tag,null,((l=(a=this.$slots).default)==null?void 0:l.call(a,{invalid:this.invalid,formData:(t=this.formProvided)==null?void 0:t.modelValue,errors:(o=this.formProvided)==null?void 0:o.errors,fieldsErrors:this.errors}))??this.$slots.defalut):((i=(d=this.$slots).default)==null?void 0:i.call(d,{invalid:this.invalid,formData:(c=this.formProvided)==null?void 0:c.modelValue,errors:(u=this.formProvided)==null?void 0:u.errors,fieldsErrors:this.errors}))??this.$slots.defalut}}),x=(e,r={})=>{const t=Symbol(),o=Symbol(),a=Symbol(),l=te(e,t,r),c=ne(t,o),u=q(t,o,a,r);return{VvForm:l,VvFormWrapper:c,VvFormField:u,formInjectionKey:t,formWrapperInjectionKey:o,formFieldInjectionKey:a}},w=Symbol(),ae=e=>{let r={};return e.schema&&(r=x(e.schema,e)),{...r,install(t,{global:o=!1}={}){t.provide(w,e),o&&(t.config.globalProperties.$vvForm=e,r!=null&&r.VvForm&&t.component("VvForm",r.VvForm),r!=null&&r.VvFormWrapper&&t.component("VvFormWrapper",r.VvFormWrapper),r!=null&&r.VvFormField&&t.component("VvFormField",r.VvFormField))}}},oe=(e,r={})=>{const t={...n.inject(w,{}),...r};return x(e,t)};b.FormFieldType=s,b.createForm=ae,b.defaultObjectBySchema=j,b.formFactory=x,b.pluginInjectionKey=w,b.useForm=oe,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
1
+ (function(b,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("vue"),require("@vueuse/core"),require("zod")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","zod"],a):(b=typeof globalThis<"u"?globalThis:b||self,a(b["@volverjs/form-vue"]={},b.Vue,b.VueUseCore,b.zod))})(this,function(b,a,D,S){"use strict";function j(e){return Array.isArray(e)}function U(e){return typeof e<"u"}function E(e){return e===null}function A(e){return typeof e=="object"}function C(e){return typeof e=="string"}function O(e){return typeof e>"u"}const W=/^[0-9]+$/,B=["__proto__","prototype","constructor"];function $(e,r,t){const o=U(t)?t:void 0;if(!A(e)||!C(r))return o;const n=I(r);if(n.length!==0){for(const l of n){if(l==="*")continue;const c=function(u){return u.map(d=>O(d)||E(d)?d:j(d)?c(d):d[l])};if(j(e)&&!W.test(l)?e=c(e):e=e[l],O(e)||E(e))break}return O(e)?o:e}}function k(e,r,t){if(!A(e)||!C(r))return;const o=I(r);if(o.length===0)return;const n=o.length;for(let l=0;l<n;l++){const c=o[l];if(l===n-1){e[c]=t;return}if(c==="*"&&j(e)){const u=o.slice(l+1).join(".");for(const d of e)k(d,u,t);return}O(e[c])&&(e[c]={}),e=e[c]}}function I(e){const r=e.split(/[.]|(?:\[(\d|\*)\])/).filter(t=>!!t);return r.some(t=>B.indexOf(t)!==-1)?[]:r}var s=(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))(s||{});const q=(e,r,t,o={})=>a.defineComponent({name:"FieldComponent",props:{type:{type:String,validator:n=>Object.values(s).includes(n),default:s.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}},emits:["invalid","valid","update:formData","update:modelValue"],expose:["invalid","invalidLabel","errors"],setup(n,{slots:l,emit:c}){const u=a.computed({get(){if(i!=null&&i.modelValue)return $(Object(i.modelValue.value),String(n.name))},set(f){i!=null&&i.modelValue&&(k(Object(i.modelValue.value),String(n.name),f),c("update:modelValue",{newValue:u.value,formData:i==null?void 0:i.modelValue}))}});a.onMounted(()=>{u.value===void 0&&n.defaultValue!==void 0&&(u.value=n.defaultValue)});const d=a.inject(r,void 0);d&&d.fields.value.add(n.name);const i=a.inject(e),{props:m,name:h}=a.toRefs(n),p=a.computed(()=>{if(i!=null&&i.errors.value)return $(i.errors.value,String(n.name))}),y=a.computed(()=>{var f;return(f=p.value)==null?void 0:f._errors}),V=a.computed(()=>p.value!==void 0);a.watch(V,()=>{V.value?(c("invalid",y.value),d&&d.errors.value.set(n.name,{_errors:y.value})):(c("valid",u.value),d&&d.errors.value.delete(n.name))}),a.watch(()=>i==null?void 0:i.modelValue,()=>{c("update:formData",i==null?void 0:i.modelValue)},{deep:!0});const G=f=>{u.value=f},L=a.computed(()=>typeof m.value=="function"?m.value(i==null?void 0:i.modelValue):m.value),le=a.computed(()=>({...L.value,name:L.value.name??n.name,invalid:V.value,valid:n.showValid?Boolean(!V.value&&u.value):void 0,type:(f=>{if([s.text,s.number,s.email,s.password,s.tel,s.url,s.search,s.date,s.time,s.datetimeLocal,s.month,s.week,s.color].includes(f))return f})(n.type),invalidLabel:y.value,modelValue:u.value,errors:n.is?p.value:void 0,"onUpdate:modelValue":G}));return a.provide(t,{name:a.readonly(h),errors:a.readonly(p)}),{component:a.computed(()=>{if(n.type===s.custom)return{render(){var f;return((f=l.default)==null?void 0:f.call(l,{modelValue:u.value,onUpdate:G,invalid:V.value,invalidLabel:y.value,formData:i==null?void 0:i.modelValue.value,formErrors:i==null?void 0:i.errors.value,errors:p.value}))??l.defalut}};if(!o.lazyLoad){let f;switch(n.type){case s.select:f=a.resolveComponent("VvSelect");break;case s.checkbox:f=a.resolveComponent("VvCheckbox");break;case s.radio:f=a.resolveComponent("VvRadio");break;case s.textarea:f=a.resolveComponent("VvTextarea");break;case s.radioGroup:f=a.resolveComponent("VvRadioGroup");break;case s.checkboxGroup:f=a.resolveComponent("VvCheckboxGroup");break;case s.combobox:f=a.resolveComponent("VvCombobox");break;default:f=a.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 a.defineAsyncComponent(async()=>{switch(o.sideEffects&&await Promise.resolve(o.sideEffects(n.type)),n.type){case s.textarea:return import("@volverjs/ui-vue/vv-textarea");case s.radio:return import("@volverjs/ui-vue/vv-radio");case s.radioGroup:return import("@volverjs/ui-vue/vv-radio-group");case s.checkbox:return import("@volverjs/ui-vue/vv-checkbox");case s.checkboxGroup:return import("@volverjs/ui-vue/vv-checkbox-group");case s.combobox:return import("@volverjs/ui-vue/vv-combobox")}return import("@volverjs/ui-vue/vv-input-text")})}),hasProps:le,invalid:V}},render(){return this.is?a.h(this.is,this.hasProps,this.$slots):this.type===s.custom?a.h(this.component,null,this.$slots):a.h(this.component,this.hasProps,this.$slots)}});var K=function(r){return z(r)&&!J(r)};function z(e){return!!e&&typeof e=="object"}function J(e){var r=Object.prototype.toString.call(e);return r==="[object RegExp]"||r==="[object Date]"||Y(e)}var R=typeof Symbol=="function"&&Symbol.for,Z=R?Symbol.for("react.element"):60103;function Y(e){return e.$$typeof===Z}function H(e){return Array.isArray(e)?[]:{}}function g(e,r){return r.clone!==!1&&r.isMergeableObject(e)?v(H(e),e,r):e}function Q(e,r,t){return e.concat(r).map(function(o){return g(o,t)})}function X(e,r){if(!r.customMerge)return v;var t=r.customMerge(e);return typeof t=="function"?t:v}function P(e){return Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(e).filter(function(r){return Object.propertyIsEnumerable.call(e,r)}):[]}function N(e){return Object.keys(e).concat(P(e))}function _(e,r){try{return r in e}catch{return!1}}function T(e,r){return _(e,r)&&!(Object.hasOwnProperty.call(e,r)&&Object.propertyIsEnumerable.call(e,r))}function F(e,r,t){var o={};return t.isMergeableObject(e)&&N(e).forEach(function(n){o[n]=g(e[n],t)}),N(r).forEach(function(n){T(e,n)||(_(e,n)&&t.isMergeableObject(r[n])?o[n]=X(n,t)(e[n],r[n],t):o[n]=g(r[n],t))}),o}function v(e,r,t){t=t||{},t.arrayMerge=t.arrayMerge||Q,t.isMergeableObject=t.isMergeableObject||K,t.cloneUnlessOtherwiseSpecified=g;var o=Array.isArray(r),n=Array.isArray(e),l=o===n;return l?o?t.arrayMerge(e,r,t):F(e,r,t):g(r,t)}v.all=function(r,t){if(!Array.isArray(r))throw new Error("first argument should be an array");return r.reduce(function(o,n){return v(o,n,t)},{})};var ee=v,re=ee;const x=(e,r={})=>{const t=e instanceof S.ZodEffects?e.innerType().shape:e.shape;return re(Object.fromEntries(Object.entries(t).map(([o,n])=>n instanceof S.ZodDefault?[o,n._def.defaultValue()]:n instanceof S.ZodObject?[o,x(n)]:[o,void 0])),r)},te=(e,r,t)=>a.defineComponent({name:"FormComponent",props:{modelValue:{type:Object,default:()=>({})}},emits:["invalid","valid","submit","update:modelValue"],expose:["submit","errors","status"],setup(o,{emit:n}){const l=a.ref(x(e,o.modelValue));a.watch(()=>o.modelValue,m=>{if(m){const h=a.isProxy(m)?a.toRaw(m):m;l.value=typeof(h==null?void 0:h.clone)=="function"?h.clone():JSON.parse(JSON.stringify(h))}},{deep:!0}),D.watchThrottled(l,m=>{(c.value||t!=null&&t.continuosValidation)&&d(),(!m||!o.modelValue||JSON.stringify(m)!==JSON.stringify(o.modelValue))&&n("update:modelValue",m)},{deep:!0,throttle:(t==null?void 0:t.updateThrottle)??500});const c=a.ref(),u=a.ref(),d=(m=l.value)=>{const h=e.safeParse(m);return h.success?(c.value=void 0,u.value="valid",l.value=h.data,n("valid",h.data),!0):(c.value=h.error.format(),u.value="invalid",n("invalid",c.value),!1)},i=()=>d()?(n("submit",l.value),!0):!1;return a.provide(r,{modelValue:l,submit:i,errors:a.readonly(c)}),{submit:i}},render(){return a.h("form",{onSubmit:a.withModifiers(this.submit,["prevent"])},this.$slots)}}),ne=(e,r)=>a.defineComponent({name:"WrapperComponent",props:{name:{type:String,required:!0},tag:{type:String,default:void 0}},emits:["invalid","valid"],expose:["fields","invalid"],setup(t,{emit:o}){const n=a.inject(e),l=a.inject(r,void 0),c=a.ref(new Set),u=a.ref(new Map),{name:d}=a.toRefs(t);a.provide(r,{name:a.readonly(d),errors:u,fields:c}),a.watch(c,m=>{l!=null&&l.fields&&m.forEach(h=>{l==null||l.fields.value.add(h)})},{deep:!0}),a.watch(()=>new Map(u.value),(m,h)=>{l!=null&&l.errors&&(Array.from(h.keys()).forEach(p=>{l.errors.value.delete(p)}),Array.from(m.keys()).forEach(p=>{const y=m.get(p);y&&l.errors.value.set(p,y)}))},{deep:!0});const i=a.computed(()=>n!=null&&n.errors.value?u.value.size>0:!1);return a.watch(i,()=>{i.value?o("invalid"):o("valid")}),{formProvided:n,invalid:i,fields:c,errors:u}},render(){var t,o,n,l,c,u,d,i;return this.tag?a.h(this.tag,null,((l=(n=this.$slots).default)==null?void 0:l.call(n,{invalid:this.invalid,formData:(t=this.formProvided)==null?void 0:t.modelValue,errors:(o=this.formProvided)==null?void 0:o.errors,fieldsErrors:this.errors}))??this.$slots.defalut):((i=(d=this.$slots).default)==null?void 0:i.call(d,{invalid:this.invalid,formData:(c=this.formProvided)==null?void 0:c.modelValue,errors:(u=this.formProvided)==null?void 0:u.errors,fieldsErrors:this.errors}))??this.$slots.defalut}}),w=(e,r={})=>{const t=Symbol(),o=Symbol(),n=Symbol(),l=te(e,t,r),c=ne(t,o),u=q(t,o,n,r);return{VvForm:l,VvFormWrapper:c,VvFormField:u,formInjectionKey:t,formWrapperInjectionKey:o,formFieldInjectionKey:n}},M=Symbol(),ae=e=>{let r={};return e.schema&&(r=w(e.schema,e)),{...r,install(t,{global:o=!1}={}){t.provide(M,e),o&&(t.config.globalProperties.$vvForm=e,r!=null&&r.VvForm&&t.component("VvForm",r.VvForm),r!=null&&r.VvFormWrapper&&t.component("VvFormWrapper",r.VvFormWrapper),r!=null&&r.VvFormField&&t.component("VvFormField",r.VvFormField))}}},oe=(e,r={})=>{const t={...a.inject(M,{}),...r};return w(e,t)};b.FormFieldType=s,b.createForm=ae,b.defaultObjectBySchema=x,b.formFactory=w,b.pluginInjectionKey=M,b.useForm=oe,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
package/dist/types.d.ts CHANGED
@@ -5,6 +5,7 @@ import type { FormFieldType } from './enums'
5
5
  export type FormComposableOptions = {
6
6
  lazyLoad?: boolean
7
7
  updateThrottle?: number
8
+ continuosValidation?: boolean
8
9
  sideEffects?: (type: `${FormFieldType}`) => Promise | void
9
10
  }
10
11
 
package/dist/utils.d.ts CHANGED
@@ -1,2 +1,6 @@
1
1
  import { type z } from 'zod';
2
- export declare const defaultObjectBySchema: <Schema extends z.AnyZodObject>(schema: Schema, original?: Partial<z.TypeOf<Schema>>) => Partial<z.TypeOf<Schema>>;
2
+ export declare const defaultObjectBySchema: <Schema extends z.AnyZodObject | z.ZodEffects<z.AnyZodObject, {
3
+ [x: string]: any;
4
+ }, {
5
+ [x: string]: any;
6
+ }>>(schema: Schema, original?: Partial<z.TypeOf<Schema>>) => Partial<z.TypeOf<Schema>>;
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.2",
22
+ "version": "0.0.3",
23
23
  "engines": {
24
24
  "node": ">= 16.x"
25
25
  },
package/src/VvForm.ts CHANGED
@@ -12,7 +12,7 @@ import {
12
12
  } from 'vue'
13
13
  import { watchThrottled } from '@vueuse/core'
14
14
 
15
- import type { AnyZodObject } from 'zod'
15
+ import type { AnyZodObject, ZodEffects } from 'zod'
16
16
  import type { InjectedFormData } from './types'
17
17
  import { defaultObjectBySchema } from './utils'
18
18
 
@@ -22,10 +22,11 @@ export enum FormStatus {
22
22
  }
23
23
 
24
24
  export const defineForm = (
25
- schema: AnyZodObject,
25
+ schema: AnyZodObject | ZodEffects<AnyZodObject>,
26
26
  provideKey: InjectionKey<InjectedFormData>,
27
27
  options?: {
28
28
  updateThrottle?: number
29
+ continuosValidation?: boolean
29
30
  },
30
31
  ) => {
31
32
  return defineComponent({
@@ -61,7 +62,7 @@ export const defineForm = (
61
62
  watchThrottled(
62
63
  localModelValue,
63
64
  (newValue) => {
64
- if (errors.value) {
65
+ if (errors.value || options?.continuosValidation) {
65
66
  parseModelValue()
66
67
  }
67
68
  if (
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { type App, inject, type InjectionKey, type Plugin } from 'vue'
2
- import type { AnyZodObject } from 'zod'
2
+ import type { AnyZodObject, ZodEffects } from 'zod'
3
3
  import { defineFormField } from './VvFormField'
4
4
  import { defineForm } from './VvForm'
5
5
  import { defineFormWrapper } from './VvFormWrapper'
@@ -12,7 +12,7 @@ import type {
12
12
  } from './types'
13
13
 
14
14
  export const formFactory = (
15
- schema: AnyZodObject,
15
+ schema: AnyZodObject | ZodEffects<AnyZodObject>,
16
16
  options: FormComposableOptions = {},
17
17
  ) => {
18
18
  // create injection keys form provide/inject
@@ -78,7 +78,7 @@ export const createForm = (
78
78
  }
79
79
 
80
80
  export const useForm = (
81
- schema: AnyZodObject,
81
+ schema: AnyZodObject | ZodEffects<AnyZodObject>,
82
82
  options: FormComposableOptions = {},
83
83
  ) => {
84
84
  const hasOptions = { ...inject(pluginInjectionKey, {}), ...options }
package/src/types.d.ts CHANGED
@@ -5,6 +5,7 @@ import type { FormFieldType } from './enums'
5
5
  export type FormComposableOptions = {
6
6
  lazyLoad?: boolean
7
7
  updateThrottle?: number
8
+ continuosValidation?: boolean
8
9
  sideEffects?: (type: `${FormFieldType}`) => Promise | void
9
10
  }
10
11
 
package/src/utils.ts CHANGED
@@ -1,13 +1,23 @@
1
1
  import merge from 'deepmerge'
2
- import { type z, type AnyZodObject, ZodDefault, ZodObject } from 'zod'
2
+ import {
3
+ type z,
4
+ type AnyZodObject,
5
+ ZodDefault,
6
+ ZodObject,
7
+ ZodEffects,
8
+ } from 'zod'
3
9
 
4
- export const defaultObjectBySchema = <Schema extends AnyZodObject>(
10
+ export const defaultObjectBySchema = <
11
+ Schema extends AnyZodObject | ZodEffects<AnyZodObject>,
12
+ >(
5
13
  schema: Schema,
6
14
  original: Partial<z.infer<Schema>> = {},
7
15
  ): Partial<z.infer<Schema>> => {
16
+ const shape =
17
+ schema instanceof ZodEffects ? schema.innerType().shape : schema.shape
8
18
  return merge(
9
19
  Object.fromEntries(
10
- Object.entries(schema.shape).map(([key, value]) => {
20
+ Object.entries(shape).map(([key, value]) => {
11
21
  if (value instanceof ZodDefault) {
12
22
  return [key, value._def.defaultValue()]
13
23
  }