@volverjs/form-vue 0.0.3 → 0.0.4

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
@@ -54,6 +54,7 @@ const form = createForm({
54
54
  schema
55
55
  // lazyLoad: boolean - default false
56
56
  // updateThrottle: number - default 500
57
+ // continuosValidation: boolean - default false
57
58
  // sideEffects?: (data: any) => void
58
59
  })
59
60
 
@@ -131,6 +132,31 @@ The throttle can be changed with the `updateThrottle` option.
131
132
  </template>
132
133
  ```
133
134
 
135
+ The `continuosValidation` can be passed through options or with VvForm prop.
136
+ With this field the validation doesn't stop and continue also after a validaton success.
137
+
138
+ ```vue
139
+ <script lang="ts" setup>
140
+ import { ref } from 'vue'
141
+
142
+ const { VvForm, VvFormField } = useForm(MyZodSchema, {
143
+ lazyLoad: true
144
+ // continuosValidation: true
145
+ })
146
+
147
+ const formData = ref({
148
+ name: '',
149
+ surname: ''
150
+ })
151
+ </script>
152
+
153
+ <template>
154
+ <VvForm v-model="formData" :continuosValidation="true">
155
+ <!-- form fields -->
156
+ </VvForm>
157
+ </template>
158
+ ```
159
+
134
160
  ### VvFormWrapper
135
161
 
136
162
  `VvFormWrapper` gives you the validation status of a part of your form.
@@ -250,6 +276,86 @@ Or a custom component.
250
276
  </template>
251
277
  ```
252
278
 
279
+ ## Nested VvFormField
280
+
281
+ In some use cases can be usefull nest `VvFormField`.
282
+ For example let's assume:
283
+
284
+ - a shopping list that is a field of our model (ex: ToDo list)
285
+ - the sum of all products of the shopping list cannot be 0
286
+ - we don't know all the products a priori
287
+
288
+ So our ToDo model and shopping list are structured like:
289
+
290
+ ```javascript
291
+ const toDo = {
292
+ shoppingList: {
293
+ bread: 0,
294
+ milk: 0,
295
+ tomato: 0,
296
+ potato: 0,
297
+ ...
298
+ }
299
+ }
300
+ ```
301
+
302
+ Our Zod schema can be:
303
+
304
+ ```typescript
305
+ const toDoSchema = z.object({
306
+ shoppingList: z
307
+ .object({})
308
+ .default({})
309
+ .superRefine((value, ctx) => {
310
+ const shoppingList = value as Record<string, number>
311
+ if (
312
+ Object.keys(value).length &&
313
+ !Object.keys(value).find((key) => shoppingList[key] > 0)
314
+ ) {
315
+ ctx.addIssue({
316
+ code: z.ZodIssueCode.custom,
317
+ message: i18n.global.t('atLeastOneProduct')
318
+ })
319
+ }
320
+ })
321
+ })
322
+ ```
323
+
324
+ And the Vue component:
325
+
326
+ ```vue
327
+ <script setup lang="ts">
328
+ const { VvForm, VvFormField } = useForm(toDoSchema, {
329
+ lazyLoad: true,
330
+ continuosValidation: true
331
+ })
332
+
333
+ // shopping list data, const or async
334
+ const shoppingList = {
335
+ bread: 0,
336
+ milk: 0,
337
+ tomato: 0,
338
+ potato: 0
339
+ }
340
+ </script>
341
+
342
+ <template>
343
+ <VvForm>
344
+ <VvFormField v-slot="{ invalid, invalidLabel }" name="shoppingList">
345
+ <VvFormField
346
+ v-for="key in Object.keys(shoppingList)"
347
+ :key="key"
348
+ :name="`shoppingList.${key}`"
349
+ :label="$t(key)"
350
+ />
351
+ <small v-if="invalid" class="input-counter__hint">{{
352
+ invalidLabel[0]
353
+ }}</small>
354
+ </VvFormField>
355
+ </VvForm>
356
+ </template>
357
+ ```
358
+
253
359
  ## Composable
254
360
 
255
361
  `useForm` can be used to create a form programmatically inside a Vue 3 Component.
@@ -268,6 +374,7 @@ The default settings are inherited from the plugin (if it was defined).
268
374
  const { VvForm, VvFormWrapper, VvFormField } = useForm(schema, {
269
375
  // lazyLoad: boolean - default false
270
376
  // updateThrottle: number - default 500
377
+ // continuosValidation: true - default false
271
378
  // sideEffects?: (formData: any) => void
272
379
  })
273
380
  </script>
@@ -297,6 +404,7 @@ const schema = z.object({
297
404
  const { VvForm, VvFormWrapper, VvFormField } = formFactory(schema, {
298
405
  // lazyLoad: boolean - default false
299
406
  // updateThrottle: number - default 500
407
+ // continuosValidation: true - default false
300
408
  // sideEffects?: (data: any) => void
301
409
  })
302
410
 
package/dist/VvForm.d.ts CHANGED
@@ -13,6 +13,10 @@ export declare const defineForm: (schema: AnyZodObject | ZodEffects<AnyZodObject
13
13
  type: ObjectConstructor;
14
14
  default: () => {};
15
15
  };
16
+ continuosValidation: {
17
+ type: BooleanConstructor;
18
+ default: boolean;
19
+ };
16
20
  }, {
17
21
  submit: () => boolean;
18
22
  }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("valid" | "invalid" | "submit" | "update:modelValue")[], "valid" | "invalid" | "submit" | "update:modelValue", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
@@ -20,6 +24,10 @@ export declare const defineForm: (schema: AnyZodObject | ZodEffects<AnyZodObject
20
24
  type: ObjectConstructor;
21
25
  default: () => {};
22
26
  };
27
+ continuosValidation: {
28
+ type: BooleanConstructor;
29
+ default: boolean;
30
+ };
23
31
  }>> & {
24
32
  onValid?: ((...args: any[]) => any) | undefined;
25
33
  onInvalid?: ((...args: any[]) => any) | undefined;
@@ -27,4 +35,5 @@ export declare const defineForm: (schema: AnyZodObject | ZodEffects<AnyZodObject
27
35
  "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
28
36
  }, {
29
37
  modelValue: Record<string, any>;
38
+ continuosValidation: boolean;
30
39
  }>;
package/dist/index.d.ts CHANGED
@@ -10,6 +10,10 @@ export declare const formFactory: (schema: AnyZodObject | ZodEffects<AnyZodObjec
10
10
  type: ObjectConstructor;
11
11
  default: () => {};
12
12
  };
13
+ continuosValidation: {
14
+ type: BooleanConstructor;
15
+ default: boolean;
16
+ };
13
17
  }, {
14
18
  submit: () => boolean;
15
19
  }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("valid" | "invalid" | "submit" | "update:modelValue")[], "valid" | "invalid" | "submit" | "update:modelValue", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
@@ -17,6 +21,10 @@ export declare const formFactory: (schema: AnyZodObject | ZodEffects<AnyZodObjec
17
21
  type: ObjectConstructor;
18
22
  default: () => {};
19
23
  };
24
+ continuosValidation: {
25
+ type: BooleanConstructor;
26
+ default: boolean;
27
+ };
20
28
  }>> & {
21
29
  onValid?: ((...args: any[]) => any) | undefined;
22
30
  onInvalid?: ((...args: any[]) => any) | undefined;
@@ -24,6 +32,7 @@ export declare const formFactory: (schema: AnyZodObject | ZodEffects<AnyZodObjec
24
32
  "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
25
33
  }, {
26
34
  modelValue: Record<string, any>;
35
+ continuosValidation: boolean;
27
36
  }>;
28
37
  VvFormWrapper: import("vue").DefineComponent<{
29
38
  name: {
@@ -69,6 +78,10 @@ export declare const useForm: (schema: AnyZodObject | ZodEffects<AnyZodObject>,
69
78
  type: ObjectConstructor;
70
79
  default: () => {};
71
80
  };
81
+ continuosValidation: {
82
+ type: BooleanConstructor;
83
+ default: boolean;
84
+ };
72
85
  }, {
73
86
  submit: () => boolean;
74
87
  }, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("valid" | "invalid" | "submit" | "update:modelValue")[], "valid" | "invalid" | "submit" | "update:modelValue", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
@@ -76,6 +89,10 @@ export declare const useForm: (schema: AnyZodObject | ZodEffects<AnyZodObject>,
76
89
  type: ObjectConstructor;
77
90
  default: () => {};
78
91
  };
92
+ continuosValidation: {
93
+ type: BooleanConstructor;
94
+ default: boolean;
95
+ };
79
96
  }>> & {
80
97
  onValid?: ((...args: any[]) => any) | undefined;
81
98
  onInvalid?: ((...args: any[]) => any) | undefined;
@@ -83,6 +100,7 @@ export declare const useForm: (schema: AnyZodObject | ZodEffects<AnyZodObject>,
83
100
  "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
84
101
  }, {
85
102
  modelValue: Record<string, any>;
103
+ continuosValidation: boolean;
86
104
  }>;
87
105
  VvFormWrapper: import("vue").DefineComponent<{
88
106
  name: {
package/dist/index.es.js CHANGED
@@ -1,4 +1,4 @@
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";
1
+ import { defineComponent as w, computed as h, onMounted as Z, inject as S, toRefs as G, watch as V, provide as k, 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
3
  import { ZodEffects as P, ZodDefault as T, ZodObject as F } from "zod";
4
4
  function A(e) {
@@ -26,13 +26,13 @@ function _(e, r, t) {
26
26
  return a;
27
27
  const n = W(r);
28
28
  if (n.length !== 0) {
29
- for (const u of n) {
30
- if (u === "*")
29
+ for (const o of n) {
30
+ if (o === "*")
31
31
  continue;
32
- const i = function(s) {
33
- return s.map((f) => E(f) || N(f) ? f : A(f) ? i(f) : f[u]);
32
+ const s = function(i) {
33
+ return i.map((f) => E(f) || N(f) ? f : A(f) ? s(f) : f[o]);
34
34
  };
35
- if (A(e) && !re.test(u) ? e = i(e) : e = e[u], E(e) || N(e))
35
+ if (A(e) && !re.test(o) ? e = s(e) : e = e[o], E(e) || N(e))
36
36
  break;
37
37
  }
38
38
  return E(e) ? a : e;
@@ -45,19 +45,19 @@ function U(e, r, t) {
45
45
  if (a.length === 0)
46
46
  return;
47
47
  const n = a.length;
48
- for (let u = 0; u < n; u++) {
49
- const i = a[u];
50
- if (u === n - 1) {
51
- e[i] = t;
48
+ for (let o = 0; o < n; o++) {
49
+ const s = a[o];
50
+ if (o === n - 1) {
51
+ e[s] = t;
52
52
  return;
53
53
  }
54
- if (i === "*" && A(e)) {
55
- const s = a.slice(u + 1).join(".");
54
+ if (s === "*" && A(e)) {
55
+ const i = a.slice(o + 1).join(".");
56
56
  for (const f of e)
57
- U(f, s, t);
57
+ U(f, i, t);
58
58
  return;
59
59
  }
60
- E(e[i]) && (e[i] = {}), e = e[i];
60
+ E(e[s]) && (e[s] = {}), e = e[s];
61
61
  }
62
62
  }
63
63
  function W(e) {
@@ -96,58 +96,58 @@ const ne = (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: u, emit: i }) {
100
- const s = h({
99
+ setup(n, { slots: o, emit: s }) {
100
+ const i = h({
101
101
  get() {
102
- if (o != null && o.modelValue)
102
+ if (u != null && u.modelValue)
103
103
  return _(
104
- Object(o.modelValue.value),
104
+ Object(u.modelValue.value),
105
105
  String(n.name)
106
106
  );
107
107
  },
108
108
  set(c) {
109
- o != null && o.modelValue && (U(
110
- Object(o.modelValue.value),
109
+ u != null && u.modelValue && (U(
110
+ Object(u.modelValue.value),
111
111
  String(n.name),
112
112
  c
113
- ), i("update:modelValue", {
114
- newValue: s.value,
115
- formData: o == null ? void 0 : o.modelValue
113
+ ), s("update:modelValue", {
114
+ newValue: i.value,
115
+ formData: u == null ? void 0 : u.modelValue
116
116
  }));
117
117
  }
118
118
  });
119
119
  Z(() => {
120
- s.value === void 0 && n.defaultValue !== void 0 && (s.value = n.defaultValue);
120
+ i.value === void 0 && n.defaultValue !== void 0 && (i.value = n.defaultValue);
121
121
  });
122
122
  const f = S(r, void 0);
123
123
  f && f.fields.value.add(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));
124
+ const u = S(e), { props: v, name: m } = G(n), d = h(() => {
125
+ if (u != null && u.errors.value)
126
+ return _(u.errors.value, String(n.name));
127
127
  }), y = h(() => {
128
128
  var c;
129
- return (c = v.value) == null ? void 0 : c._errors;
130
- }), p = h(() => v.value !== void 0);
129
+ return (c = d.value) == null ? void 0 : c._errors;
130
+ }), p = h(() => d.value !== void 0);
131
131
  V(p, () => {
132
- p.value ? (i("invalid", y.value), f && f.errors.value.set(n.name, {
132
+ p.value ? (s("invalid", y.value), f && f.errors.value.set(n.name, {
133
133
  _errors: y.value
134
- })) : (i("valid", s.value), f && f.errors.value.delete(
134
+ })) : (s("valid", i.value), f && f.errors.value.delete(
135
135
  n.name
136
136
  ));
137
137
  }), V(
138
- () => o == null ? void 0 : o.modelValue,
138
+ () => u == null ? void 0 : u.modelValue,
139
139
  () => {
140
- i("update:formData", o == null ? void 0 : o.modelValue);
140
+ s("update:formData", u == null ? void 0 : u.modelValue);
141
141
  },
142
142
  { deep: !0 }
143
143
  );
144
- const k = (c) => {
145
- s.value = c;
146
- }, I = h(() => typeof d.value == "function" ? d.value(o == null ? void 0 : o.modelValue) : d.value), R = h(() => ({
144
+ const $ = (c) => {
145
+ i.value = c;
146
+ }, I = h(() => typeof v.value == "function" ? v.value(u == null ? void 0 : u.modelValue) : v.value), R = h(() => ({
147
147
  ...I.value,
148
148
  name: I.value.name ?? n.name,
149
149
  invalid: p.value,
150
- valid: n.showValid ? Boolean(!p.value && s.value) : void 0,
150
+ valid: n.showValid ? Boolean(!p.value && i.value) : void 0,
151
151
  type: ((c) => {
152
152
  if ([
153
153
  l.text,
@@ -167,27 +167,27 @@ const ne = (e, r, t, a = {}) => w({
167
167
  return c;
168
168
  })(n.type),
169
169
  invalidLabel: y.value,
170
- modelValue: s.value,
171
- errors: n.is ? v.value : void 0,
172
- "onUpdate:modelValue": k
170
+ modelValue: i.value,
171
+ errors: n.is ? d.value : void 0,
172
+ "onUpdate:modelValue": $
173
173
  }));
174
- return $(t, {
174
+ return k(t, {
175
175
  name: M(m),
176
- errors: M(v)
176
+ errors: M(d)
177
177
  }), { component: h(() => {
178
178
  if (n.type === l.custom)
179
179
  return {
180
180
  render() {
181
181
  var c;
182
- return ((c = u.default) == null ? void 0 : c.call(u, {
183
- modelValue: s.value,
184
- onUpdate: k,
182
+ return ((c = o.default) == null ? void 0 : c.call(o, {
183
+ modelValue: i.value,
184
+ onUpdate: $,
185
185
  invalid: p.value,
186
186
  invalidLabel: y.value,
187
- formData: o == null ? void 0 : o.modelValue.value,
188
- formErrors: o == null ? void 0 : o.errors.value,
189
- errors: v.value
190
- })) ?? u.defalut;
187
+ formData: u == null ? void 0 : u.modelValue.value,
188
+ formErrors: u == null ? void 0 : u.errors.value,
189
+ errors: d.value
190
+ })) ?? o.defalut;
191
191
  }
192
192
  };
193
193
  if (!a.lazyLoad) {
@@ -247,12 +247,12 @@ const ne = (e, r, t, a = {}) => w({
247
247
  }
248
248
  });
249
249
  var ae = function(r) {
250
- return ue(r) && !oe(r);
250
+ return oe(r) && !ue(r);
251
251
  };
252
- function ue(e) {
252
+ function oe(e) {
253
253
  return !!e && typeof e == "object";
254
254
  }
255
- function oe(e) {
255
+ function ue(e) {
256
256
  var r = Object.prototype.toString.call(e);
257
257
  return r === "[object RegExp]" || r === "[object Date]" || se(e);
258
258
  }
@@ -305,8 +305,8 @@ function be(e, r, t) {
305
305
  }
306
306
  function g(e, r, t) {
307
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);
308
+ var a = Array.isArray(r), n = Array.isArray(e), o = a === n;
309
+ return o ? 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))
@@ -330,39 +330,43 @@ const J = (e, r = {}) => {
330
330
  modelValue: {
331
331
  type: Object,
332
332
  default: () => ({})
333
+ },
334
+ continuosValidation: {
335
+ type: Boolean,
336
+ default: !1
333
337
  }
334
338
  },
335
339
  emits: ["invalid", "valid", "submit", "update:modelValue"],
336
340
  expose: ["submit", "errors", "status"],
337
341
  setup(a, { emit: n }) {
338
- const u = x(
342
+ const o = x(
339
343
  J(e, a.modelValue)
340
- );
344
+ ), s = (t == null ? void 0 : t.continuosValidation) || a.continuosValidation;
341
345
  V(
342
346
  () => a.modelValue,
343
- (d) => {
344
- if (d) {
345
- const m = Y(d) ? H(d) : d;
346
- u.value = typeof (m == null ? void 0 : m.clone) == "function" ? m.clone() : JSON.parse(JSON.stringify(m));
347
+ (m) => {
348
+ if (m) {
349
+ const d = Y(m) ? H(m) : m;
350
+ o.value = typeof (d == null ? void 0 : d.clone) == "function" ? d.clone() : JSON.parse(JSON.stringify(d));
347
351
  }
348
352
  },
349
353
  { deep: !0 }
350
354
  ), X(
351
- u,
352
- (d) => {
353
- (i.value || t != null && t.continuosValidation) && f(), (!d || !a.modelValue || JSON.stringify(d) !== JSON.stringify(a.modelValue)) && n("update:modelValue", d);
355
+ o,
356
+ (m) => {
357
+ (i.value || s) && u(), (!m || !a.modelValue || JSON.stringify(m) !== JSON.stringify(a.modelValue)) && n("update:modelValue", m);
354
358
  },
355
359
  { deep: !0, throttle: (t == null ? void 0 : t.updateThrottle) ?? 500 }
356
360
  );
357
- const i = x(), s = x(), f = (d = u.value) => {
358
- const m = e.safeParse(d);
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;
361
- return $(r, {
362
- modelValue: u,
363
- submit: o,
361
+ const i = x(), f = x(), u = (m = o.value) => {
362
+ const d = e.safeParse(m);
363
+ return d.success ? (i.value = void 0, f.value = "valid", o.value = d.data, n("valid", d.data), !0) : (i.value = d.error.format(), f.value = "invalid", n("invalid", i.value), !1);
364
+ }, v = () => u() ? (n("submit", o.value), !0) : !1;
365
+ return k(r, {
366
+ modelValue: o,
367
+ submit: v,
364
368
  errors: M(i)
365
- }), { submit: o };
369
+ }), { submit: v };
366
370
  },
367
371
  render() {
368
372
  return O(
@@ -388,68 +392,68 @@ const J = (e, r = {}) => {
388
392
  emits: ["invalid", "valid"],
389
393
  expose: ["fields", "invalid"],
390
394
  setup(t, { emit: a }) {
391
- const n = S(e), u = S(r, void 0), i = x(/* @__PURE__ */ new Set()), s = x(/* @__PURE__ */ new Map()), { name: f } = G(t);
392
- $(r, {
395
+ const n = S(e), o = S(r, void 0), s = x(/* @__PURE__ */ new Set()), i = x(/* @__PURE__ */ new Map()), { name: f } = G(t);
396
+ k(r, {
393
397
  name: M(f),
394
- errors: s,
395
- fields: i
398
+ errors: i,
399
+ fields: s
396
400
  }), V(
397
- i,
398
- (d) => {
399
- u != null && u.fields && d.forEach((m) => {
400
- u == null || u.fields.value.add(m);
401
+ s,
402
+ (v) => {
403
+ o != null && o.fields && v.forEach((m) => {
404
+ o == null || o.fields.value.add(m);
401
405
  });
402
406
  },
403
407
  { deep: !0 }
404
408
  ), V(
405
- () => new Map(s.value),
406
- (d, m) => {
407
- u != null && u.errors && (Array.from(m.keys()).forEach((v) => {
408
- u.errors.value.delete(v);
409
- }), Array.from(d.keys()).forEach((v) => {
410
- const y = d.get(v);
411
- y && u.errors.value.set(v, y);
409
+ () => new Map(i.value),
410
+ (v, m) => {
411
+ o != null && o.errors && (Array.from(m.keys()).forEach((d) => {
412
+ o.errors.value.delete(d);
413
+ }), Array.from(v.keys()).forEach((d) => {
414
+ const y = v.get(d);
415
+ y && o.errors.value.set(d, y);
412
416
  }));
413
417
  },
414
418
  { deep: !0 }
415
419
  );
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 };
420
+ const u = h(() => n != null && n.errors.value ? i.value.size > 0 : !1);
421
+ return V(u, () => {
422
+ u.value ? a("invalid") : a("valid");
423
+ }), { formProvided: n, invalid: u, fields: s, errors: i };
420
424
  },
421
425
  render() {
422
- var t, a, n, u, i, s, f, o;
426
+ var t, a, n, o, s, i, f, u;
423
427
  return this.tag ? O(
424
428
  this.tag,
425
429
  null,
426
- ((u = (n = this.$slots).default) == null ? void 0 : u.call(n, {
430
+ ((o = (n = this.$slots).default) == null ? void 0 : o.call(n, {
427
431
  invalid: this.invalid,
428
432
  formData: (t = this.formProvided) == null ? void 0 : t.modelValue,
429
433
  errors: (a = this.formProvided) == null ? void 0 : a.errors,
430
434
  fieldsErrors: this.errors
431
435
  })) ?? this.$slots.defalut
432
- ) : ((o = (f = this.$slots).default) == null ? void 0 : o.call(f, {
436
+ ) : ((u = (f = this.$slots).default) == null ? void 0 : u.call(f, {
433
437
  invalid: this.invalid,
434
- formData: (i = this.formProvided) == null ? void 0 : i.modelValue,
435
- errors: (s = this.formProvided) == null ? void 0 : s.errors,
438
+ formData: (s = this.formProvided) == null ? void 0 : s.modelValue,
439
+ errors: (i = this.formProvided) == null ? void 0 : i.errors,
436
440
  fieldsErrors: this.errors
437
441
  })) ?? this.$slots.defalut;
438
442
  }
439
443
  }), K = (e, r = {}) => {
440
- const t = Symbol(), a = Symbol(), n = Symbol(), u = pe(e, t, r), i = Ve(
444
+ const t = Symbol(), a = Symbol(), n = Symbol(), o = pe(e, t, r), s = Ve(
441
445
  t,
442
446
  a
443
- ), s = ne(
447
+ ), i = ne(
444
448
  t,
445
449
  a,
446
450
  n,
447
451
  r
448
452
  );
449
453
  return {
450
- VvForm: u,
451
- VvFormWrapper: i,
452
- VvFormField: s,
454
+ VvForm: o,
455
+ VvFormWrapper: s,
456
+ VvFormField: i,
453
457
  formInjectionKey: t,
454
458
  formWrapperInjectionKey: a,
455
459
  formFieldInjectionKey: n
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
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"})});
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 B=/^[0-9]+$/,W=["__proto__","prototype","constructor"];function k(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 u=function(c){return c.map(d=>O(d)||E(d)?d:j(d)?u(d):d[l])};if(j(e)&&!B.test(l)?e=u(e):e=e[l],O(e)||E(e))break}return O(e)?o:e}}function $(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 u=o[l];if(l===n-1){e[u]=t;return}if(u==="*"&&j(e)){const c=o.slice(l+1).join(".");for(const d of e)$(d,c,t);return}O(e[u])&&(e[u]={}),e=e[u]}}function I(e){const r=e.split(/[.]|(?:\[(\d|\*)\])/).filter(t=>!!t);return r.some(t=>W.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:u}){const c=a.computed({get(){if(i!=null&&i.modelValue)return k(Object(i.modelValue.value),String(n.name))},set(f){i!=null&&i.modelValue&&($(Object(i.modelValue.value),String(n.name),f),u("update:modelValue",{newValue:c.value,formData:i==null?void 0:i.modelValue}))}});a.onMounted(()=>{c.value===void 0&&n.defaultValue!==void 0&&(c.value=n.defaultValue)});const d=a.inject(r,void 0);d&&d.fields.value.add(n.name);const i=a.inject(e),{props:y,name:h}=a.toRefs(n),m=a.computed(()=>{if(i!=null&&i.errors.value)return k(i.errors.value,String(n.name))}),p=a.computed(()=>{var f;return(f=m.value)==null?void 0:f._errors}),V=a.computed(()=>m.value!==void 0);a.watch(V,()=>{V.value?(u("invalid",p.value),d&&d.errors.value.set(n.name,{_errors:p.value})):(u("valid",c.value),d&&d.errors.value.delete(n.name))}),a.watch(()=>i==null?void 0:i.modelValue,()=>{u("update:formData",i==null?void 0:i.modelValue)},{deep:!0});const G=f=>{c.value=f},L=a.computed(()=>typeof y.value=="function"?y.value(i==null?void 0:i.modelValue):y.value),le=a.computed(()=>({...L.value,name:L.value.name??n.name,invalid:V.value,valid:n.showValid?Boolean(!V.value&&c.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:p.value,modelValue:c.value,errors:n.is?m.value:void 0,"onUpdate:modelValue":G}));return a.provide(t,{name:a.readonly(h),errors:a.readonly(m)}),{component:a.computed(()=>{if(n.type===s.custom)return{render(){var f;return((f=l.default)==null?void 0:f.call(l,{modelValue:c.value,onUpdate:G,invalid:V.value,invalidLabel:p.value,formData:i==null?void 0:i.modelValue.value,formErrors:i==null?void 0:i.errors.value,errors:m.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:()=>({})},continuosValidation:{type:Boolean,default:!1}},emits:["invalid","valid","submit","update:modelValue"],expose:["submit","errors","status"],setup(o,{emit:n}){const l=a.ref(x(e,o.modelValue)),u=(t==null?void 0:t.continuosValidation)||o.continuosValidation;a.watch(()=>o.modelValue,h=>{if(h){const m=a.isProxy(h)?a.toRaw(h):h;l.value=typeof(m==null?void 0:m.clone)=="function"?m.clone():JSON.parse(JSON.stringify(m))}},{deep:!0}),D.watchThrottled(l,h=>{(c.value||u)&&i(),(!h||!o.modelValue||JSON.stringify(h)!==JSON.stringify(o.modelValue))&&n("update:modelValue",h)},{deep:!0,throttle:(t==null?void 0:t.updateThrottle)??500});const c=a.ref(),d=a.ref(),i=(h=l.value)=>{const m=e.safeParse(h);return m.success?(c.value=void 0,d.value="valid",l.value=m.data,n("valid",m.data),!0):(c.value=m.error.format(),d.value="invalid",n("invalid",c.value),!1)},y=()=>i()?(n("submit",l.value),!0):!1;return a.provide(r,{modelValue:l,submit:y,errors:a.readonly(c)}),{submit:y}},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),u=a.ref(new Set),c=a.ref(new Map),{name:d}=a.toRefs(t);a.provide(r,{name:a.readonly(d),errors:c,fields:u}),a.watch(u,y=>{l!=null&&l.fields&&y.forEach(h=>{l==null||l.fields.value.add(h)})},{deep:!0}),a.watch(()=>new Map(c.value),(y,h)=>{l!=null&&l.errors&&(Array.from(h.keys()).forEach(m=>{l.errors.value.delete(m)}),Array.from(y.keys()).forEach(m=>{const p=y.get(m);p&&l.errors.value.set(m,p)}))},{deep:!0});const i=a.computed(()=>n!=null&&n.errors.value?c.value.size>0:!1);return a.watch(i,()=>{i.value?o("invalid"):o("valid")}),{formProvided:n,invalid:i,fields:u,errors:c}},render(){var t,o,n,l,u,c,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:(u=this.formProvided)==null?void 0:u.modelValue,errors:(c=this.formProvided)==null?void 0:c.errors,fieldsErrors:this.errors}))??this.$slots.defalut}}),w=(e,r={})=>{const t=Symbol(),o=Symbol(),n=Symbol(),l=te(e,t,r),u=ne(t,o),c=q(t,o,n,r);return{VvForm:l,VvFormWrapper:u,VvFormField:c,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/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.3",
22
+ "version": "0.0.4",
23
23
  "engines": {
24
24
  "node": ">= 16.x"
25
25
  },
package/src/VvForm.ts CHANGED
@@ -36,6 +36,10 @@ export const defineForm = (
36
36
  type: Object,
37
37
  default: () => ({}),
38
38
  },
39
+ continuosValidation: {
40
+ type: Boolean,
41
+ default: false,
42
+ },
39
43
  },
40
44
  emits: ['invalid', 'valid', 'submit', 'update:modelValue'],
41
45
  expose: ['submit', 'errors', 'status'],
@@ -43,6 +47,10 @@ export const defineForm = (
43
47
  const localModelValue = ref(
44
48
  defaultObjectBySchema(schema, props.modelValue),
45
49
  )
50
+
51
+ const keepValidation =
52
+ options?.continuosValidation || props.continuosValidation
53
+
46
54
  watch(
47
55
  () => props.modelValue,
48
56
  (newValue) => {
@@ -62,7 +70,7 @@ export const defineForm = (
62
70
  watchThrottled(
63
71
  localModelValue,
64
72
  (newValue) => {
65
- if (errors.value || options?.continuosValidation) {
73
+ if (errors.value || keepValidation) {
66
74
  parseModelValue()
67
75
  }
68
76
  if (