@volverjs/form-vue 1.0.0-beta.23 → 1.0.0-beta.24

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
@@ -239,14 +239,16 @@ The wrapper status is invalid if at least one of the fields inside it is invalid
239
239
  ```vue
240
240
  <template>
241
241
  <VvForm>
242
+ <!-- main VvFormWrapper -->
242
243
  <VvFormWrapper v-slot="{ invalid }">
244
+ <!-- add VvFormFields to wrapper -->
243
245
  <div class="form-section">
244
246
  <span v-if="invalid">There is a validation error</span>
245
- <!-- form fields of section -->
247
+ <!-- nested VvFormWrapper -->
246
248
  <VvFormWrapper v-slot="{ invalid: groupInvalid }">
247
249
  <div class="form-section__group">
248
250
  <span v-if="groupInvalid">There is a validation error</span>
249
- <!-- form fields of the group -->
251
+ <!-- add VvFormFields to nested wrapper -->
250
252
  </div>
251
253
  </VvFormWrapper>
252
254
  </div>
@@ -279,7 +281,7 @@ It automatically bind the form data through the `name` attribute. For nested obj
279
281
  @input="onUpdate"
280
282
  >
281
283
  <small v-if="invalid" id="last-name-alert" role="alert">
282
- {{ invalidLabel.join(', ') }}
284
+ {{ invalidLabel }}
283
285
  </small>
284
286
  </VvFormField>
285
287
  </VvForm>
@@ -311,7 +313,7 @@ It automatically bind the form data through the `names` attribute. For nested ob
311
313
  <VvForm>
312
314
  <VvFormFieldsGroup
313
315
  v-slot="{ modelValue, invalids, invalidLabels, onUpdateField }"
314
- :name="['firstName', 'lastName']"
316
+ :names="['firstName', 'lastName']"
315
317
  >
316
318
  <fieldset>
317
319
  <p>
@@ -326,7 +328,7 @@ It automatically bind the form data through the `names` attribute. For nested ob
326
328
  @input="onUpdateField('firstName', $event)"
327
329
  >
328
330
  <small v-if="invalids.firstName" id="first-name-alert" role="alert">
329
- {{ invalidLabels?.firstName.join(', ') }}
331
+ {{ invalidLabels?.firstName }}
330
332
  </small>
331
333
  </p>
332
334
  <p>
@@ -341,7 +343,7 @@ It automatically bind the form data through the `names` attribute. For nested ob
341
343
  @input="onUpdateField('lastName', $event)"
342
344
  >
343
345
  <small v-if="invalids.lastName" id="last-name-alert" role="alert">
344
- {{ invalidLabels?.lastName.join(', ') }}
346
+ {{ invalidLabels?.lastName }}
345
347
  </small>
346
348
  </p>
347
349
  </fieldset>
package/dist/index.d.ts CHANGED
@@ -2,8 +2,8 @@ import { InjectionKey, Plugin } from 'vue';
2
2
  import { AnyZodObject } from 'zod';
3
3
  import { defineForm } from './VvForm';
4
4
  import { defineFormField } from './VvFormField';
5
+ import { defineFormFieldsGroup } from './VvFormFieldsGroup';
5
6
  import { defineFormWrapper } from './VvFormWrapper';
6
- import { defineFormTemplate } from './VvFormTemplate';
7
7
  import { InjectedFormData, InjectedFormWrapperData, InjectedFormFieldData, FormComposableOptions, FormPluginOptions, FormTemplateItem, Path, PathValue, FormSchema, FormTemplate } from './types';
8
8
  export declare const pluginInjectionKey: InjectionKey<FormPluginOptions>;
9
9
  export declare function createForm(options: FormPluginOptions): Plugin & Partial<ReturnType<typeof useForm>>;
@@ -934,8 +934,9 @@ export { defaultObjectBySchema } from './utils';
934
934
  type FormComponent = ReturnType<typeof defineForm>;
935
935
  type FormWrapperComponent = ReturnType<typeof defineFormWrapper>;
936
936
  type FormFieldComponent = ReturnType<typeof defineFormField>;
937
- type FormTemplateComponent = ReturnType<typeof defineFormTemplate>;
938
- export type { FormComponent, FormComposableOptions, FormFieldComponent, FormPluginOptions, FormSchema, FormTemplate, FormTemplateComponent, FormTemplateItem, FormWrapperComponent, InjectedFormData, InjectedFormFieldData, InjectedFormWrapperData, Path, PathValue, };
937
+ type FormFieldsGroupComponent = ReturnType<typeof defineFormFieldsGroup>;
938
+ type FormTemplateComponent = ReturnType<typeof defineFormFieldsGroup>;
939
+ export type { FormComponent, FormComposableOptions, FormFieldComponent, FormFieldsGroupComponent, FormPluginOptions, FormSchema, FormTemplate, FormTemplateComponent, FormTemplateItem, FormWrapperComponent, InjectedFormData, InjectedFormFieldData, InjectedFormWrapperData, Path, PathValue, };
939
940
  /**
940
941
  * @deprecated Use `useForm()` instead
941
942
  */
package/dist/index.es.js CHANGED
@@ -1,8 +1,8 @@
1
- import { ref as C, computed as O, readonly as K, defineComponent as M, toRaw as L, watch as U, isProxy as fe, onMounted as j, provide as Y, h as G, withModifiers as re, toRefs as F, inject as _, onBeforeUnmount as le, unref as Z, resolveComponent as N, defineAsyncComponent as ve, getCurrentInstance as de } from "vue";
1
+ import { ref as C, computed as O, readonly as K, defineComponent as M, toRaw as R, watch as L, isProxy as fe, onMounted as j, provide as Y, h as U, withModifiers as re, toRefs as F, inject as _, onBeforeUnmount as le, unref as Z, resolveComponent as N, defineAsyncComponent as ve, getCurrentInstance as de } from "vue";
2
2
  import { watchIgnorable as ce, throttleFilter as ye } from "@vueuse/core";
3
- import { ZodObject as H, ZodDefault as he, ZodNullable as me, ZodSchema as be, ZodArray as pe, ZodRecord as Ve, ZodEffects as te, ZodOptional as ae, ZodError as ge } from "zod";
4
- var m = /* @__PURE__ */ ((e) => (e.text = "text", e.number = "number", e.email = "email", e.password = "password", e.tel = "tel", e.url = "url", e.search = "search", e.date = "date", e.time = "time", e.datetimeLocal = "datetime-local", e.month = "month", e.week = "week", e.color = "color", e.select = "select", e.checkbox = "checkbox", e.radio = "radio", e.textarea = "textarea", e.radioGroup = "radioGroup", e.checkboxGroup = "checkboxGroup", e.combobox = "combobox", e.custom = "custom", e))(m || {}), R = /* @__PURE__ */ ((e) => (e.invalid = "invalid", e.valid = "valid", e.submitting = "submitting", e.reset = "reset", e.updated = "updated", e.unknown = "unknown", e))(R || {});
5
- function J(e, o = {}) {
3
+ import { ZodObject as H, ZodDefault as me, ZodNullable as he, ZodSchema as be, ZodArray as pe, ZodRecord as Ve, ZodEffects as te, ZodOptional as ae, ZodError as ge } from "zod";
4
+ var h = /* @__PURE__ */ ((e) => (e.text = "text", e.number = "number", e.email = "email", e.password = "password", e.tel = "tel", e.url = "url", e.search = "search", e.date = "date", e.time = "time", e.datetimeLocal = "datetime-local", e.month = "month", e.week = "week", e.color = "color", e.select = "select", e.checkbox = "checkbox", e.radio = "radio", e.textarea = "textarea", e.radioGroup = "radioGroup", e.checkboxGroup = "checkboxGroup", e.combobox = "combobox", e.custom = "custom", e))(h || {}), B = /* @__PURE__ */ ((e) => (e.invalid = "invalid", e.valid = "valid", e.submitting = "submitting", e.reset = "reset", e.updated = "updated", e.unknown = "unknown", e))(B || {});
5
+ function J(e, s = {}) {
6
6
  const r = (d) => {
7
7
  let l = d;
8
8
  for (; l instanceof te; )
@@ -15,13 +15,13 @@ function J(e, o = {}) {
15
15
  return l instanceof ae;
16
16
  }, t = r(e);
17
17
  return {
18
- ...(t instanceof H ? t._def.unknownKeys === "passthrough" : !1) ? o : {},
18
+ ...(t instanceof H ? t._def.unknownKeys === "passthrough" : !1) ? s : {},
19
19
  ...Object.fromEntries(
20
20
  Object.entries(t.shape).map(
21
21
  ([d, l]) => {
22
- const f = o[d], p = v(l);
22
+ const f = s[d], p = v(l);
23
23
  let u = r(l), y;
24
- if (u instanceof he && (y = u._def.defaultValue(), u = u._def.innerType), f === null && u instanceof me)
24
+ if (u instanceof me && (y = u._def.defaultValue(), u = u._def.innerType), f === null && u instanceof he)
25
25
  return [d, f];
26
26
  if (f == null && p)
27
27
  return [d, y];
@@ -36,9 +36,9 @@ function J(e, o = {}) {
36
36
  return [
37
37
  d,
38
38
  f.map(
39
- (h) => J(
39
+ (m) => J(
40
40
  b,
41
- h && typeof h == "object" ? h : void 0
41
+ m && typeof m == "object" ? m : void 0
42
42
  )
43
43
  )
44
44
  ];
@@ -46,7 +46,7 @@ function J(e, o = {}) {
46
46
  if (u instanceof Ve && f) {
47
47
  const b = r(u._def.valueType);
48
48
  if (b instanceof H)
49
- return [d, Object.keys(f).reduce((h, n) => (h[n] = J(b, f[n]), h), {})];
49
+ return [d, Object.keys(f).reduce((m, n) => (m[n] = J(b, f[n]), m), {})];
50
50
  }
51
51
  return u instanceof H ? [
52
52
  d,
@@ -60,28 +60,28 @@ function J(e, o = {}) {
60
60
  )
61
61
  };
62
62
  }
63
- function Oe(e, o, r, v) {
64
- const t = C(), a = C(), d = O(() => a.value === R.invalid), l = C(), f = C(!1);
63
+ function Oe(e, s, r, v) {
64
+ const t = C(), a = C(), d = O(() => a.value === B.invalid), l = C(), f = C(!1);
65
65
  let p;
66
66
  const u = async (k = l.value, g) => {
67
67
  if (p = g, f.value)
68
68
  return !0;
69
69
  const V = await e.safeParseAsync(k);
70
70
  if (!V.success) {
71
- if (a.value = R.invalid, !g)
71
+ if (a.value = B.invalid, !g)
72
72
  return t.value = V.error.format(), !1;
73
- const s = V.error.issues.filter((W) => g.has(W.path.join(".")));
74
- return s.length ? (t.value = new ge(s).format(), !1) : (t.value = void 0, !0);
73
+ const i = V.error.issues.filter((W) => g.has(W.path.join(".")));
74
+ return i.length ? (t.value = new ge(i).format(), !1) : (t.value = void 0, !0);
75
75
  }
76
- return t.value = void 0, a.value = R.valid, l.value = V.data, !0;
76
+ return t.value = void 0, a.value = B.valid, l.value = V.data, !0;
77
77
  }, y = () => {
78
78
  t.value = void 0, a.value = void 0, p = void 0;
79
79
  }, b = () => {
80
- l.value = J(e), y(), a.value = R.reset;
81
- }, h = async () => f.value || !await u() ? !1 : (a.value = R.submitting, !0), { ignoreUpdates: n, stop: w } = ce(
80
+ l.value = J(e), y(), a.value = B.reset;
81
+ }, m = async () => f.value || !await u() ? !1 : (a.value = B.submitting, !0), { ignoreUpdates: n, stop: w } = ce(
82
82
  l,
83
83
  () => {
84
- a.value = R.updated;
84
+ a.value = B.updated;
85
85
  },
86
86
  {
87
87
  deep: !0,
@@ -136,60 +136,60 @@ function Oe(e, o, r, v) {
136
136
  setup(k, { emit: g }) {
137
137
  return l.value = J(
138
138
  e,
139
- L(k.modelValue)
140
- ), U(
139
+ R(k.modelValue)
140
+ ), L(
141
141
  () => k.modelValue,
142
142
  (V) => {
143
143
  if (V) {
144
- const s = fe(V) ? L(V) : V;
145
- if (JSON.stringify(s) === JSON.stringify(L(l.value)))
144
+ const i = fe(V) ? R(V) : V;
145
+ if (JSON.stringify(i) === JSON.stringify(R(l.value)))
146
146
  return;
147
- l.value = typeof (s == null ? void 0 : s.clone) == "function" ? s.clone() : JSON.parse(JSON.stringify(s));
147
+ l.value = typeof (i == null ? void 0 : i.clone) == "function" ? i.clone() : JSON.parse(JSON.stringify(i));
148
148
  }
149
149
  },
150
150
  { deep: !0 }
151
- ), U(a, async (V) => {
152
- var s, W, A, $, q, T;
153
- if (V === R.invalid) {
154
- const B = L(t.value);
155
- g("invalid", B), (s = r == null ? void 0 : r.onInvalid) == null || s.call(
151
+ ), L(a, async (V) => {
152
+ var i, W, A, $, q, T;
153
+ if (V === B.invalid) {
154
+ const G = R(t.value);
155
+ g("invalid", G), (i = r == null ? void 0 : r.onInvalid) == null || i.call(
156
156
  r,
157
- B
157
+ G
158
158
  );
159
159
  return;
160
160
  }
161
- if (V === R.valid) {
162
- const B = L(l.value);
163
- g("valid", B), (W = r == null ? void 0 : r.onValid) == null || W.call(r, B), g("update:modelValue", B), (A = r == null ? void 0 : r.onUpdate) == null || A.call(r, B);
161
+ if (V === B.valid) {
162
+ const G = R(l.value);
163
+ g("valid", G), (W = r == null ? void 0 : r.onValid) == null || W.call(r, G), g("update:modelValue", G), (A = r == null ? void 0 : r.onUpdate) == null || A.call(r, G);
164
164
  return;
165
165
  }
166
- if (V === R.submitting) {
167
- const B = L(l.value);
168
- g("submit", B), ($ = r == null ? void 0 : r.onSubmit) == null || $.call(r, B);
166
+ if (V === B.submitting) {
167
+ const G = R(l.value);
168
+ g("submit", G), ($ = r == null ? void 0 : r.onSubmit) == null || $.call(r, G);
169
169
  return;
170
170
  }
171
- if (V === R.reset) {
172
- const B = L(l.value);
173
- g("reset", B), (q = r == null ? void 0 : r.onReset) == null || q.call(r, B);
171
+ if (V === B.reset) {
172
+ const G = R(l.value);
173
+ g("reset", G), (q = r == null ? void 0 : r.onReset) == null || q.call(r, G);
174
174
  return;
175
175
  }
176
- if (V === R.updated) {
176
+ if (V === B.updated) {
177
177
  if ((t.value || r != null && r.continuousValidation || k.continuousValidation) && await u(void 0, p), !l.value || !k.modelValue || JSON.stringify(l.value) !== JSON.stringify(k.modelValue)) {
178
- const B = L(l.value);
179
- g("update:modelValue", B), (T = r == null ? void 0 : r.onUpdate) == null || T.call(r, B);
178
+ const G = R(l.value);
179
+ g("update:modelValue", G), (T = r == null ? void 0 : r.onUpdate) == null || T.call(r, G);
180
180
  }
181
- a.value === R.updated && (a.value = R.unknown);
181
+ a.value === B.updated && (a.value = B.unknown);
182
182
  }
183
183
  }), j(() => {
184
184
  f.value = k.readonly;
185
- }), U(
185
+ }), L(
186
186
  () => k.readonly,
187
187
  (V) => {
188
188
  f.value = V;
189
189
  }
190
- ), U(f, (V) => {
190
+ ), L(f, (V) => {
191
191
  V !== k.readonly && g("update:readonly", f.value);
192
- }), Y(o, {
192
+ }), Y(s, {
193
193
  clear: y,
194
194
  errors: x,
195
195
  formData: l,
@@ -199,7 +199,7 @@ function Oe(e, o, r, v) {
199
199
  reset: b,
200
200
  status: E,
201
201
  stopUpdatesWatch: w,
202
- submit: h,
202
+ submit: m,
203
203
  validate: u
204
204
  }), {
205
205
  clear: y,
@@ -211,7 +211,7 @@ function Oe(e, o, r, v) {
211
211
  reset: b,
212
212
  status: E,
213
213
  stopUpdatesWatch: w,
214
- submit: h,
214
+ submit: m,
215
215
  validate: u
216
216
  };
217
217
  },
@@ -228,18 +228,18 @@ function Oe(e, o, r, v) {
228
228
  reset: b,
229
229
  status: E,
230
230
  stopUpdatesWatch: w,
231
- submit: h,
231
+ submit: m,
232
232
  validate: u
233
233
  })) ?? this.$slots.default;
234
234
  };
235
- return G(
235
+ return U(
236
236
  this.tag,
237
237
  {
238
238
  onSubmit: re(this.submit, ["prevent"]),
239
239
  onReset: re(this.reset, ["prevent"])
240
240
  },
241
241
  (this.template ?? (r == null ? void 0 : r.template)) && v ? [
242
- G(
242
+ U(
243
243
  v,
244
244
  {
245
245
  schema: this.template ?? (r == null ? void 0 : r.template)
@@ -264,7 +264,7 @@ function Oe(e, o, r, v) {
264
264
  reset: b,
265
265
  status: a,
266
266
  stopUpdatesWatch: w,
267
- submit: h,
267
+ submit: m,
268
268
  validate: u,
269
269
  VvForm: S
270
270
  };
@@ -288,11 +288,11 @@ function Q(e) {
288
288
  return typeof e > "u";
289
289
  }
290
290
  const xe = /^[0-9]+$/, ke = ["__proto__", "prototype", "constructor"];
291
- function z(e, o, r) {
291
+ function z(e, s, r) {
292
292
  const v = we(r) ? r : void 0;
293
- if (!ne(e) || !se(o))
293
+ if (!ne(e) || !se(s))
294
294
  return v;
295
- const t = ie(o);
295
+ const t = ie(s);
296
296
  if (t.length !== 0) {
297
297
  for (const a of t) {
298
298
  if (a === "*")
@@ -306,10 +306,10 @@ function z(e, o, r) {
306
306
  return Q(e) ? v : e;
307
307
  }
308
308
  }
309
- function ee(e, o, r) {
310
- if (!ne(e) || !se(o))
309
+ function ee(e, s, r) {
310
+ if (!ne(e) || !se(s))
311
311
  return;
312
- const v = ie(o);
312
+ const v = ie(s);
313
313
  if (v.length === 0)
314
314
  return;
315
315
  const t = v.length;
@@ -329,17 +329,17 @@ function ee(e, o, r) {
329
329
  }
330
330
  }
331
331
  function ie(e) {
332
- const o = e.split(/[.]|(?:\[(\d|\*)\])/).filter((r) => !!r);
333
- return o.some((r) => ke.indexOf(r) !== -1) ? [] : o;
332
+ const s = e.split(/[.]|(?:\[(\d|\*)\])/).filter((r) => !!r);
333
+ return s.some((r) => ke.indexOf(r) !== -1) ? [] : s;
334
334
  }
335
- function Se(e, o, r, v) {
335
+ function Se(e, s, r, v) {
336
336
  return M({
337
337
  name: "VvFormField",
338
338
  props: {
339
339
  type: {
340
340
  type: String,
341
- validator: (t) => Object.values(m).includes(t),
342
- default: m.custom
341
+ validator: (t) => Object.values(h).includes(t),
342
+ default: h.custom
343
343
  },
344
344
  is: {
345
345
  type: [Object, String],
@@ -387,7 +387,7 @@ function Se(e, o, r, v) {
387
387
  ],
388
388
  slots: Object,
389
389
  setup(t, { slots: a, emit: d }) {
390
- const { props: l, name: f } = F(t), p = _(o, void 0);
390
+ const { props: l, name: f } = F(t), p = _(s, void 0);
391
391
  p && p.fields.value.add(t.name);
392
392
  const u = _(e), y = O({
393
393
  get() {
@@ -397,11 +397,11 @@ function Se(e, o, r, v) {
397
397
  String(t.name)
398
398
  );
399
399
  },
400
- set(s) {
400
+ set(i) {
401
401
  u != null && u.formData && (ee(
402
402
  new Object(u.formData.value),
403
403
  String(t.name),
404
- s
404
+ i
405
405
  ), d("update:modelValue", {
406
406
  newValue: y.value,
407
407
  formData: u == null ? void 0 : u.formData
@@ -414,10 +414,10 @@ function Se(e, o, r, v) {
414
414
  const b = O(() => {
415
415
  if (u != null && u.errors.value)
416
416
  return z(u.errors.value, String(t.name));
417
- }), h = O(() => {
418
- var s;
419
- return (s = b.value) == null ? void 0 : s._errors;
420
- }), n = O(() => b.value !== void 0), w = U(n, () => {
417
+ }), m = O(() => {
418
+ var i;
419
+ return (i = b.value) == null ? void 0 : i._errors;
420
+ }), n = O(() => b.value !== void 0), w = L(n, () => {
421
421
  if (n.value) {
422
422
  d("invalid", b.value), p && p.errors.value.set(
423
423
  String(t.name),
@@ -428,7 +428,7 @@ function Se(e, o, r, v) {
428
428
  d("valid", y.value), p && p.errors.value.delete(
429
429
  t.name
430
430
  );
431
- }), x = U(
431
+ }), x = L(
432
432
  () => u == null ? void 0 : u.formData,
433
433
  () => {
434
434
  d("update:formData", u == null ? void 0 : u.formData);
@@ -438,12 +438,12 @@ function Se(e, o, r, v) {
438
438
  le(() => {
439
439
  w(), x();
440
440
  });
441
- const E = (s) => {
442
- s instanceof InputEvent && (s = s.target.value), y.value = s;
441
+ const E = (i) => {
442
+ i instanceof InputEvent && (i = i.target.value), y.value = i;
443
443
  }, S = O(() => {
444
- let s = l.value;
445
- return typeof s == "function" && (s = s(u == null ? void 0 : u.formData)), Object.keys(s).reduce(
446
- (W, A) => (W[A] = Z(s[A]), W),
444
+ let i = l.value;
445
+ return typeof i == "function" && (i = i(u == null ? void 0 : u.formData)), Object.keys(i).reduce(
446
+ (W, A) => (W[A] = Z(i[A]), W),
447
447
  {}
448
448
  );
449
449
  }), k = O(() => u != null && u.readonly.value ? !0 : S.value.readonly ?? t.readonly), g = O(() => ({
@@ -451,25 +451,25 @@ function Se(e, o, r, v) {
451
451
  name: S.value.name ?? t.name,
452
452
  invalid: n.value,
453
453
  valid: t.showValid ? !!(!n.value && y.value) : void 0,
454
- type: ((s) => {
454
+ type: ((i) => {
455
455
  if ([
456
- m.color,
457
- m.date,
458
- m.datetimeLocal,
459
- m.email,
460
- m.month,
461
- m.number,
462
- m.password,
463
- m.search,
464
- m.tel,
465
- m.text,
466
- m.time,
467
- m.url,
468
- m.week
469
- ].includes(s))
470
- return s;
456
+ h.color,
457
+ h.date,
458
+ h.datetimeLocal,
459
+ h.email,
460
+ h.month,
461
+ h.number,
462
+ h.password,
463
+ h.search,
464
+ h.tel,
465
+ h.text,
466
+ h.time,
467
+ h.url,
468
+ h.week
469
+ ].includes(i))
470
+ return i;
471
471
  })(t.type),
472
- invalidLabel: h.value,
472
+ invalidLabel: m.value,
473
473
  modelValue: y.value,
474
474
  readonly: k.value,
475
475
  "onUpdate:modelValue": E
@@ -478,16 +478,16 @@ function Se(e, o, r, v) {
478
478
  name: K(f),
479
479
  errors: K(b)
480
480
  }), { component: O(() => {
481
- if (t.type === m.custom)
481
+ if (t.type === h.custom)
482
482
  return {
483
483
  render() {
484
- var s;
485
- return ((s = a.default) == null ? void 0 : s.call(a, {
484
+ var i;
485
+ return ((i = a.default) == null ? void 0 : i.call(a, {
486
486
  errors: b.value,
487
487
  formData: u == null ? void 0 : u.formData.value,
488
488
  formErrors: u == null ? void 0 : u.errors.value,
489
489
  invalid: n.value,
490
- invalidLabel: h.value,
490
+ invalidLabel: m.value,
491
491
  modelValue: y.value,
492
492
  onUpdate: E,
493
493
  readonly: k.value,
@@ -497,53 +497,53 @@ function Se(e, o, r, v) {
497
497
  }
498
498
  };
499
499
  if (!((v == null ? void 0 : v.lazyLoad) ?? t.lazyLoad)) {
500
- let s;
500
+ let i;
501
501
  switch (t.type) {
502
- case m.select:
503
- s = N("VvSelect");
502
+ case h.select:
503
+ i = N("VvSelect");
504
504
  break;
505
- case m.checkbox:
506
- s = N("VvCheckbox");
505
+ case h.checkbox:
506
+ i = N("VvCheckbox");
507
507
  break;
508
- case m.radio:
509
- s = N("VvRadio");
508
+ case h.radio:
509
+ i = N("VvRadio");
510
510
  break;
511
- case m.textarea:
512
- s = N("VvTextarea");
511
+ case h.textarea:
512
+ i = N("VvTextarea");
513
513
  break;
514
- case m.radioGroup:
515
- s = N("VvRadioGroup");
514
+ case h.radioGroup:
515
+ i = N("VvRadioGroup");
516
516
  break;
517
- case m.checkboxGroup:
518
- s = N("VvCheckboxGroup");
517
+ case h.checkboxGroup:
518
+ i = N("VvCheckboxGroup");
519
519
  break;
520
- case m.combobox:
521
- s = N("VvCombobox");
520
+ case h.combobox:
521
+ i = N("VvCombobox");
522
522
  break;
523
523
  default:
524
- s = N("VvInputText");
524
+ i = N("VvInputText");
525
525
  }
526
- if (typeof s != "string")
527
- return s;
526
+ if (typeof i != "string")
527
+ return i;
528
528
  console.warn(
529
- `[form-vue warn]: ${s} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`
529
+ `[form-vue warn]: ${i} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`
530
530
  );
531
531
  }
532
532
  return ve(async () => {
533
533
  switch (v != null && v.sideEffects && await Promise.resolve(v.sideEffects(t.type)), t.type) {
534
- case m.textarea:
534
+ case h.textarea:
535
535
  return import("@volverjs/ui-vue/vv-textarea");
536
- case m.radio:
536
+ case h.radio:
537
537
  return import("@volverjs/ui-vue/vv-radio");
538
- case m.radioGroup:
538
+ case h.radioGroup:
539
539
  return import("@volverjs/ui-vue/vv-radio-group");
540
- case m.checkbox:
540
+ case h.checkbox:
541
541
  return import("@volverjs/ui-vue/vv-checkbox");
542
- case m.checkboxGroup:
542
+ case h.checkboxGroup:
543
543
  return import("@volverjs/ui-vue/vv-checkbox-group");
544
- case m.select:
544
+ case h.select:
545
545
  return import("@volverjs/ui-vue/vv-select");
546
- case m.combobox:
546
+ case h.combobox:
547
547
  return import("@volverjs/ui-vue/vv-combobox");
548
548
  }
549
549
  return import("@volverjs/ui-vue/vv-input-text");
@@ -551,11 +551,11 @@ function Se(e, o, r, v) {
551
551
  }), hasProps: g, invalid: n };
552
552
  },
553
553
  render() {
554
- return this.is ? G(this.is, this.hasProps, this.$slots) : this.type === m.custom ? G(this.component, null, this.$slots) : G(this.component, this.hasProps, this.$slots);
554
+ return this.is ? U(this.is, this.hasProps, this.$slots) : this.type === h.custom ? U(this.component, null, this.$slots) : U(this.component, this.hasProps, this.$slots);
555
555
  }
556
556
  });
557
557
  }
558
- function Ie(e, o, r) {
558
+ function Ie(e, s, r) {
559
559
  return M({
560
560
  name: "VvFormFieldsGroup",
561
561
  props: {
@@ -564,7 +564,7 @@ function Ie(e, o, r) {
564
564
  default: void 0
565
565
  },
566
566
  names: {
567
- type: [Array],
567
+ type: [Array, Object],
568
568
  required: !0
569
569
  },
570
570
  props: {
@@ -600,23 +600,23 @@ function Ie(e, o, r) {
600
600
  ],
601
601
  slots: Object,
602
602
  setup(v, { slots: t, emit: a }) {
603
- const { props: d, names: l, defaultValues: f } = F(v), p = O(() => Array.isArray(l.value) ? l.value : Object.values(l.value)), u = O(() => Array.isArray(l.value) ? l.value : Object.keys(l.value)), y = O(() => Array.isArray(l.value) ? l.value.reduce((i, c) => (i[String(c)] = c, i), {}) : l.value), b = O(() => Object.keys(y.value).reduce((i, c) => (i[String(y.value[c])] = c, i), {})), h = _(o, void 0);
604
- h && p.value.forEach((i) => {
605
- h.fields.value.add(i);
603
+ const { props: d, names: l, defaultValues: f } = F(v), p = O(() => Array.isArray(l.value) ? l.value : Object.values(l.value)), u = O(() => Array.isArray(l.value) ? l.value : Object.keys(l.value)), y = O(() => Array.isArray(l.value) ? l.value.reduce((o, c) => (o[String(c)] = c, o), {}) : l.value), b = O(() => Object.keys(y.value).reduce((o, c) => (o[String(y.value[c])] = c, o), {})), m = _(s, void 0);
604
+ m && p.value.forEach((o) => {
605
+ m.fields.value.add(o);
606
606
  });
607
607
  const n = _(e), w = O({
608
608
  get() {
609
- return n != null && n.formData ? u.value.reduce((i, c) => (i[c] = z(
609
+ return n != null && n.formData ? u.value.reduce((o, c) => (o[c] = z(
610
610
  new Object(n.formData.value),
611
611
  y.value[c]
612
- ), i), {}) : {};
612
+ ), o), {}) : {};
613
613
  },
614
- set(i) {
614
+ set(o) {
615
615
  n != null && n.formData && (u.value.forEach((c) => {
616
616
  ee(
617
617
  new Object(n.formData.value),
618
618
  y.value[c],
619
- i == null ? void 0 : i[c]
619
+ o == null ? void 0 : o[c]
620
620
  );
621
621
  }), a("update:modelValue", {
622
622
  newValue: w.value,
@@ -625,60 +625,60 @@ function Ie(e, o, r) {
625
625
  }
626
626
  });
627
627
  j(() => {
628
- f.value && p.value.forEach((i) => {
628
+ f.value && p.value.forEach((o) => {
629
629
  var c, I;
630
- ((c = f.value) == null ? void 0 : c[i]) !== void 0 && w.value[i] === void 0 && (w.value = {
630
+ ((c = f.value) == null ? void 0 : c[o]) !== void 0 && w.value[o] === void 0 && (w.value = {
631
631
  ...w.value,
632
- [i]: (I = f.value) == null ? void 0 : I[i]
632
+ [o]: (I = f.value) == null ? void 0 : I[o]
633
633
  });
634
634
  });
635
635
  });
636
636
  const x = O(() => {
637
637
  if (!(n != null && n.errors.value))
638
638
  return;
639
- const i = p.value.reduce((c, I) => {
639
+ const o = p.value.reduce((c, I) => {
640
640
  if (!n.errors.value)
641
641
  return c;
642
642
  const P = z(n.errors.value, String(I));
643
643
  return P === void 0 || (c[String(I)] = P), c;
644
644
  }, {});
645
- if (Object.keys(i).length !== 0)
646
- return i;
645
+ if (Object.keys(o).length !== 0)
646
+ return o;
647
647
  }), E = O(() => {
648
648
  if (!x.value)
649
649
  return;
650
- const i = Object.keys(x.value).reduce((c, I) => {
650
+ const o = Object.keys(x.value).reduce((c, I) => {
651
651
  var P;
652
652
  return (P = x.value) != null && P[I] && (c[b.value[I]] = x.value[I]._errors), c;
653
653
  }, {});
654
- if (Object.keys(i).length !== 0)
655
- return i;
656
- }), S = O(() => x.value !== void 0), k = O(() => u.value.reduce((i, c) => {
654
+ if (Object.keys(o).length !== 0)
655
+ return o;
656
+ }), S = O(() => x.value !== void 0), k = O(() => u.value.reduce((o, c) => {
657
657
  var I;
658
- return i[c] = !!((I = x.value) != null && I[b.value[c]]), i;
659
- }, {})), g = U(S, () => {
658
+ return o[c] = !!((I = x.value) != null && I[b.value[c]]), o;
659
+ }, {})), g = L(S, () => {
660
660
  if (S.value) {
661
- a("invalid", x.value), h && p.value.forEach((i) => {
661
+ a("invalid", x.value), m && p.value.forEach((o) => {
662
662
  var c, I;
663
- if (!((c = x.value) != null && c[i])) {
664
- h.errors.value.delete(
665
- i
663
+ if (!((c = x.value) != null && c[o])) {
664
+ m.errors.value.delete(
665
+ o
666
666
  );
667
667
  return;
668
668
  }
669
- h.errors.value.set(
670
- i,
671
- (I = x.value) == null ? void 0 : I[i]
669
+ m.errors.value.set(
670
+ o,
671
+ (I = x.value) == null ? void 0 : I[o]
672
672
  );
673
673
  });
674
674
  return;
675
675
  }
676
- a("valid", w.value), h && p.value.forEach((i) => {
677
- h.errors.value.delete(
678
- i
676
+ a("valid", w.value), m && p.value.forEach((o) => {
677
+ m.errors.value.delete(
678
+ o
679
679
  );
680
680
  });
681
- }), V = U(
681
+ }), V = L(
682
682
  () => n == null ? void 0 : n.formData,
683
683
  () => {
684
684
  a("update:formData", n == null ? void 0 : n.formData);
@@ -688,23 +688,23 @@ function Ie(e, o, r) {
688
688
  le(() => {
689
689
  g(), V();
690
690
  });
691
- const s = (i) => {
692
- w.value = i;
693
- }, W = (i, c) => {
694
- c instanceof InputEvent && (c = c.target.value), u.value.includes(i) && (w.value = {
691
+ const i = (o) => {
692
+ w.value = o;
693
+ }, W = (o, c) => {
694
+ c instanceof InputEvent && (c = c.target.value), u.value.includes(o) && (w.value = {
695
695
  ...w.value,
696
- [i]: c
696
+ [o]: c
697
697
  });
698
698
  }, A = O(() => {
699
- let i = d.value;
700
- return typeof i == "function" && (i = i(n == null ? void 0 : n.formData)), Object.keys(i).reduce(
701
- (c, I) => (c[I] = Z(i[I]), c),
699
+ let o = d.value;
700
+ return typeof o == "function" && (o = o(n == null ? void 0 : n.formData)), Object.keys(o).reduce(
701
+ (c, I) => (c[I] = Z(o[I]), c),
702
702
  {}
703
703
  );
704
- }), $ = O(() => n != null && n.readonly.value ? !0 : A.value.readonly ?? v.readonly), q = O(() => u.value.reduce((i, c) => (i[`onUpdate:${c}`] = (I) => {
704
+ }), $ = O(() => n != null && n.readonly.value ? !0 : A.value.readonly ?? v.readonly), q = O(() => u.value.reduce((o, c) => (o[`onUpdate:${c}`] = (I) => {
705
705
  W(c, I);
706
- }, i), {
707
- "onUpdate:modelValue": s
706
+ }, o), {
707
+ "onUpdate:modelValue": i
708
708
  })), T = O(() => ({
709
709
  ...q.value,
710
710
  ...A.value,
@@ -721,8 +721,8 @@ function Ie(e, o, r) {
721
721
  errors: K(x)
722
722
  }), { component: O(() => ({
723
723
  render() {
724
- var i;
725
- return ((i = t.default) == null ? void 0 : i.call(t, {
724
+ var o;
725
+ return ((o = t.default) == null ? void 0 : o.call(t, {
726
726
  errors: x.value,
727
727
  formData: n == null ? void 0 : n.formData.value,
728
728
  formErrors: n == null ? void 0 : n.errors.value,
@@ -730,7 +730,7 @@ function Ie(e, o, r) {
730
730
  invalids: k.value,
731
731
  invalidLabels: E.value,
732
732
  modelValue: w.value,
733
- onUpdate: s,
733
+ onUpdate: i,
734
734
  onUpdateField: W,
735
735
  readonly: $.value,
736
736
  submit: n == null ? void 0 : n.submit,
@@ -740,11 +740,11 @@ function Ie(e, o, r) {
740
740
  })), hasProps: T, invalid: S };
741
741
  },
742
742
  render() {
743
- return this.is ? G(this.is, this.hasProps, this.$slots) : G(this.component, null, this.$slots);
743
+ return this.is ? U(this.is, this.hasProps, this.$slots) : U(this.component, null, this.$slots);
744
744
  }
745
745
  });
746
746
  }
747
- function Ee(e, o) {
747
+ function Ee(e, s) {
748
748
  return M({
749
749
  name: "VvFormWrapper",
750
750
  props: {
@@ -773,12 +773,12 @@ function Ee(e, o) {
773
773
  ],
774
774
  slots: Object,
775
775
  setup(r, { emit: v }) {
776
- const t = _(e), a = _(o, void 0), d = C(/* @__PURE__ */ new Set()), l = C(/* @__PURE__ */ new Map()), { name: f } = F(r);
777
- Y(o, {
776
+ const t = _(e), a = _(s, void 0), d = C(/* @__PURE__ */ new Set()), l = C(/* @__PURE__ */ new Map()), { name: f } = F(r);
777
+ Y(s, {
778
778
  name: K(f),
779
779
  errors: l,
780
780
  fields: d
781
- }), U(
781
+ }), L(
782
782
  d,
783
783
  (y) => {
784
784
  a != null && a.fields && y.forEach((b) => {
@@ -786,20 +786,20 @@ function Ee(e, o) {
786
786
  });
787
787
  },
788
788
  { deep: !0 }
789
- ), U(
789
+ ), L(
790
790
  () => new Map(l.value),
791
791
  (y, b) => {
792
- a != null && a.errors && (Array.from(b.keys()).forEach((h) => {
793
- a.errors.value.delete(h);
794
- }), Array.from(y.keys()).forEach((h) => {
795
- const n = y.get(h);
796
- n && a.errors.value.set(h, n);
792
+ a != null && a.errors && (Array.from(b.keys()).forEach((m) => {
793
+ a.errors.value.delete(m);
794
+ }), Array.from(y.keys()).forEach((m) => {
795
+ const n = y.get(m);
796
+ n && a.errors.value.set(m, n);
797
797
  }));
798
798
  },
799
799
  { deep: !0 }
800
800
  );
801
801
  const p = O(() => t != null && t.invalid.value ? l.value.size > 0 : !1);
802
- U(p, () => {
802
+ L(p, () => {
803
803
  p.value ? v("invalid") : v("valid");
804
804
  });
805
805
  const u = () => (t == null ? void 0 : t.validate(void 0, d.value)) ?? Promise.resolve(!0);
@@ -831,13 +831,13 @@ function Ee(e, o) {
831
831
  validateWrapper: this.validateWrapper
832
832
  });
833
833
  };
834
- return this.tag ? G(this.tag, null, {
834
+ return this.tag ? U(this.tag, null, {
835
835
  default: r
836
836
  }) : r();
837
837
  }
838
838
  });
839
839
  }
840
- function Ae(e, o) {
840
+ function Ae(e, s) {
841
841
  const r = M({
842
842
  name: "VvFormTemplate",
843
843
  props: {
@@ -863,7 +863,7 @@ function Ae(e, o) {
863
863
  let l;
864
864
  const f = d.reduce((u, y) => {
865
865
  const b = typeof y == "function" ? y(a, v.scope) : y, {
866
- vvIs: h,
866
+ vvIs: m,
867
867
  vvName: n,
868
868
  vvSlots: w,
869
869
  vvChildren: x,
@@ -872,7 +872,7 @@ function Ae(e, o) {
872
872
  vvType: k,
873
873
  vvDefaultValue: g,
874
874
  vvShowValid: V,
875
- vvContent: s,
875
+ vvContent: i,
876
876
  ...W
877
877
  } = b;
878
878
  if (E !== void 0) {
@@ -890,31 +890,31 @@ function Ae(e, o) {
890
890
  } else
891
891
  l = void 0;
892
892
  let A;
893
- return x && (typeof h == "string" ? A = G(r, {
893
+ return x && (typeof m == "string" ? A = U(r, {
894
894
  schema: x
895
895
  }) : A = {
896
- default: ($) => G(r, {
896
+ default: ($) => U(r, {
897
897
  schema: x,
898
898
  scope: $
899
899
  })
900
900
  }), n ? (u.push(
901
- G(
902
- o,
901
+ U(
902
+ s,
903
903
  {
904
904
  name: n,
905
- is: h,
905
+ is: m,
906
906
  type: k,
907
907
  defaultValue: g,
908
908
  showValid: V,
909
909
  props: W
910
910
  },
911
- w ?? A ?? s
911
+ w ?? A ?? i
912
912
  )
913
- ), u) : h ? (u.push(
914
- G(
915
- h,
913
+ ), u) : m ? (u.push(
914
+ U(
915
+ m,
916
916
  W,
917
- w ?? A ?? s
917
+ w ?? A ?? i
918
918
  )
919
919
  ), u) : (A && ("default" in A ? u.push(A.default(v.scope)) : u.push(A)), u);
920
920
  }, []);
@@ -935,7 +935,7 @@ function Ae(e, o) {
935
935
  });
936
936
  return r;
937
937
  }
938
- function X(e, o = {}) {
938
+ function X(e, s = {}) {
939
939
  const r = Symbol("formInjectionKey"), v = Symbol("formWrapperInjectionKey"), t = Symbol("formFieldInjectionKey"), a = Symbol("formFieldsGroupInjectionKey"), d = Ee(
940
940
  r,
941
941
  v
@@ -943,7 +943,7 @@ function X(e, o = {}) {
943
943
  r,
944
944
  v,
945
945
  t,
946
- o
946
+ s
947
947
  ), f = Ie(
948
948
  r,
949
949
  v,
@@ -952,7 +952,7 @@ function X(e, o = {}) {
952
952
  clear: u,
953
953
  errors: y,
954
954
  formData: b,
955
- ignoreUpdates: h,
955
+ ignoreUpdates: m,
956
956
  invalid: n,
957
957
  readonly: w,
958
958
  reset: x,
@@ -961,7 +961,7 @@ function X(e, o = {}) {
961
961
  submit: k,
962
962
  validate: g,
963
963
  VvForm: V
964
- } = Oe(e, r, o, p);
964
+ } = Oe(e, r, s, p);
965
965
  return {
966
966
  clear: u,
967
967
  errors: y,
@@ -969,7 +969,7 @@ function X(e, o = {}) {
969
969
  formFieldInjectionKey: t,
970
970
  formInjectionKey: r,
971
971
  formWrapperInjectionKey: v,
972
- ignoreUpdates: h,
972
+ ignoreUpdates: m,
973
973
  invalid: n,
974
974
  readonly: w,
975
975
  reset: x,
@@ -985,32 +985,32 @@ function X(e, o = {}) {
985
985
  };
986
986
  }
987
987
  const oe = Symbol("pluginInjectionKey");
988
- function Ge(e) {
989
- let o = {};
990
- return e.schema && (o = X(e.schema, e)), {
991
- ...o,
988
+ function Ue(e) {
989
+ let s = {};
990
+ return e.schema && (s = X(e.schema, e)), {
991
+ ...s,
992
992
  install(r, { global: v = !1 } = {}) {
993
- r.provide(oe, e), v && (r.config.globalProperties.$vvForm = e, o != null && o.VvForm && r.component("VvForm", o.VvForm), o != null && o.VvFormWrapper && r.component("VvFormWrapper", o.VvFormWrapper), o != null && o.VvFormField && r.component("VvFormField", o.VvFormField), o != null && o.VvFormTemplate && r.component("VvFormTemplate", o.VvFormTemplate));
993
+ r.provide(oe, e), v && (r.config.globalProperties.$vvForm = e, s != null && s.VvForm && r.component("VvForm", s.VvForm), s != null && s.VvFormWrapper && r.component("VvFormWrapper", s.VvFormWrapper), s != null && s.VvFormField && r.component("VvFormField", s.VvFormField), s != null && s.VvFormFieldsGroup && r.component("VvFormFieldsGroup", s.VvFormFieldsGroup), s != null && s.VvFormTemplate && r.component("VvFormTemplate", s.VvFormTemplate));
994
994
  }
995
995
  };
996
996
  }
997
- function Ue(e, o = {}) {
997
+ function Le(e, s = {}) {
998
998
  return de() ? X(
999
999
  e,
1000
1000
  {
1001
1001
  ..._(oe, {}),
1002
- ...o
1002
+ ...s
1003
1003
  }
1004
- ) : X(e, o);
1004
+ ) : X(e, s);
1005
1005
  }
1006
- function Le(e, o = {}) {
1007
- return X(e, o);
1006
+ function Re(e, s = {}) {
1007
+ return X(e, s);
1008
1008
  }
1009
1009
  export {
1010
- m as FormFieldType,
1011
- Ge as createForm,
1010
+ h as FormFieldType,
1011
+ Ue as createForm,
1012
1012
  J as defaultObjectBySchema,
1013
- Le as formFactory,
1013
+ Re as formFactory,
1014
1014
  oe as pluginInjectionKey,
1015
- Ue as useForm
1015
+ Le as useForm
1016
1016
  };
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(A,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("@vueuse/core"),require("zod")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","zod"],e):(A=typeof globalThis<"u"?globalThis:A||self,e(A["@volverjs/form-vue"]={},A.Vue,A.VueUseCore,A.zod))})(this,function(A,e,T,B){"use strict";var p=(r=>(r.text="text",r.number="number",r.email="email",r.password="password",r.tel="tel",r.url="url",r.search="search",r.date="date",r.time="time",r.datetimeLocal="datetime-local",r.month="month",r.week="week",r.color="color",r.select="select",r.checkbox="checkbox",r.radio="radio",r.textarea="textarea",r.radioGroup="radioGroup",r.checkboxGroup="checkboxGroup",r.combobox="combobox",r.custom="custom",r))(p||{}),U=(r=>(r.invalid="invalid",r.valid="valid",r.submitting="submitting",r.reset="reset",r.updated="updated",r.unknown="unknown",r))(U||{});function L(r,f={}){const t=v=>{let u=v;for(;u instanceof B.ZodEffects;)u=u.innerType();return u instanceof B.ZodOptional&&(u=u._def.innerType),u},c=v=>{let u=v;for(;u instanceof B.ZodEffects;)u=u.innerType();return u instanceof B.ZodOptional},a=t(r);return{...(a instanceof B.ZodObject?a._def.unknownKeys==="passthrough":!1)?f:{},...Object.fromEntries(Object.entries(a.shape).map(([v,u])=>{const d=f[v],V=c(u);let l=t(u),h;if(l instanceof B.ZodDefault&&(h=l._def.defaultValue(),l=l._def.innerType),d===null&&l instanceof B.ZodNullable)return[v,d];if(d==null&&V)return[v,h];if(l instanceof B.ZodSchema){const b=u.safeParse(d);if(b.success)return[v,b.data??h]}if(l instanceof B.ZodArray&&Array.isArray(d)&&d.length){const b=t(l._def.type);if(b instanceof B.ZodObject)return[v,d.map(y=>L(b,y&&typeof y=="object"?y:void 0))]}if(l instanceof B.ZodRecord&&d){const b=t(l._def.valueType);if(b instanceof B.ZodObject)return[v,Object.keys(d).reduce((y,o)=>(y[o]=L(b,d[o]),y),{})]}return l instanceof B.ZodObject?[v,L(l,d&&typeof d=="object"?d:h)]:[v,h]}))}}function z(r,f,t,c){const a=e.ref(),n=e.ref(),v=e.computed(()=>n.value===U.invalid),u=e.ref(),d=e.ref(!1);let V;const l=async(x=u.value,w)=>{if(V=w,d.value)return!0;const g=await r.safeParseAsync(x);if(!g.success){if(n.value=U.invalid,!w)return a.value=g.error.format(),!1;const s=g.error.issues.filter(W=>w.has(W.path.join(".")));return s.length?(a.value=new B.ZodError(s).format(),!1):(a.value=void 0,!0)}return a.value=void 0,n.value=U.valid,u.value=g.data,!0},h=()=>{a.value=void 0,n.value=void 0,V=void 0},b=()=>{u.value=L(r),h(),n.value=U.reset},y=async()=>d.value||!await l()?!1:(n.value=U.submitting,!0),{ignoreUpdates:o,stop:O}=T.watchIgnorable(u,()=>{n.value=U.updated},{deep:!0,eventFilter:T.throttleFilter((t==null?void 0:t.updateThrottle)??500)}),S=e.readonly(a),E=e.readonly(n),k=e.defineComponent({name:"VvForm",props:{continuousValidation:{type:Boolean,default:!1},modelValue:{type:Object,default:()=>({})},readonly:{type:Boolean,default:(t==null?void 0:t.readonly)??!1},tag:{type:String,default:"form"},template:{type:[Array,Function],default:void 0}},emits:["invalid","submit","update:modelValue","update:readonly","valid","reset"],expose:["errors","invalid","readonly","status","submit","tag","template","valid","validate","clear","reset"],slots:Object,setup(x,{emit:w}){return u.value=L(r,e.toRaw(x.modelValue)),e.watch(()=>x.modelValue,g=>{if(g){const s=e.isProxy(g)?e.toRaw(g):g;if(JSON.stringify(s)===JSON.stringify(e.toRaw(u.value)))return;u.value=typeof(s==null?void 0:s.clone)=="function"?s.clone():JSON.parse(JSON.stringify(s))}},{deep:!0}),e.watch(n,async g=>{var s,W,R,G,$,M;if(g===U.invalid){const C=e.toRaw(a.value);w("invalid",C),(s=t==null?void 0:t.onInvalid)==null||s.call(t,C);return}if(g===U.valid){const C=e.toRaw(u.value);w("valid",C),(W=t==null?void 0:t.onValid)==null||W.call(t,C),w("update:modelValue",C),(R=t==null?void 0:t.onUpdate)==null||R.call(t,C);return}if(g===U.submitting){const C=e.toRaw(u.value);w("submit",C),(G=t==null?void 0:t.onSubmit)==null||G.call(t,C);return}if(g===U.reset){const C=e.toRaw(u.value);w("reset",C),($=t==null?void 0:t.onReset)==null||$.call(t,C);return}if(g===U.updated){if((a.value||t!=null&&t.continuousValidation||x.continuousValidation)&&await l(void 0,V),!u.value||!x.modelValue||JSON.stringify(u.value)!==JSON.stringify(x.modelValue)){const C=e.toRaw(u.value);w("update:modelValue",C),(M=t==null?void 0:t.onUpdate)==null||M.call(t,C)}n.value===U.updated&&(n.value=U.unknown)}}),e.onMounted(()=>{d.value=x.readonly}),e.watch(()=>x.readonly,g=>{d.value=g}),e.watch(d,g=>{g!==x.readonly&&w("update:readonly",d.value)}),e.provide(f,{clear:h,errors:S,formData:u,ignoreUpdates:o,invalid:v,readonly:d,reset:b,status:E,stopUpdatesWatch:O,submit:y,validate:l}),{clear:h,errors:S,formData:u,ignoreUpdates:o,invalid:v,isReadonly:d,reset:b,status:E,stopUpdatesWatch:O,submit:y,validate:l}},render(){const x=()=>{var w,g;return((g=(w=this.$slots)==null?void 0:w.default)==null?void 0:g.call(w,{clear:h,errors:S,formData:u,ignoreUpdates:o,invalid:v,readonly:d,reset:b,status:E,stopUpdatesWatch:O,submit:y,validate:l}))??this.$slots.default};return e.h(this.tag,{onSubmit:e.withModifiers(this.submit,["prevent"]),onReset:e.withModifiers(this.reset,["prevent"])},(this.template??(t==null?void 0:t.template))&&c?[e.h(c,{schema:this.template??(t==null?void 0:t.template)},{default:x})]:{default:x})}});return{clear:h,errors:a,formData:u,ignoreUpdates:o,invalid:v,readonly:d,reset:b,status:n,stopUpdatesWatch:O,submit:y,validate:l,VvForm:k}}function P(r){return Array.isArray(r)}function j(r){return typeof r<"u"}function H(r){return r===null}function Q(r){return typeof r=="object"}function X(r){return typeof r=="string"}function _(r){return typeof r>"u"}const D=/^[0-9]+$/,F=["__proto__","prototype","constructor"];function Z(r,f,t){const c=j(t)?t:void 0;if(!Q(r)||!X(f))return c;const a=Y(f);if(a.length!==0){for(const n of a){if(n==="*")continue;const v=function(u){return u.map(d=>_(d)||H(d)?d:P(d)?v(d):d[n])};if(P(r)&&!D.test(n)?r=v(r):r=r[n],_(r)||H(r))break}return _(r)?c:r}}function q(r,f,t){if(!Q(r)||!X(f))return;const c=Y(f);if(c.length===0)return;const a=c.length;for(let n=0;n<a;n++){const v=c[n];if(n===a-1){r[v]=t;return}if(v==="*"&&P(r)){const u=c.slice(n+1).join(".");for(const d of r)q(d,u,t);return}_(r[v])&&(r[v]={}),r=r[v]}}function Y(r){const f=r.split(/[.]|(?:\[(\d|\*)\])/).filter(t=>!!t);return f.some(t=>F.indexOf(t)!==-1)?[]:f}function ee(r,f,t,c){return e.defineComponent({name:"VvFormField",props:{type:{type:String,validator:a=>Object.values(p).includes(a),default:p.custom},is:{type:[Object,String],default:void 0},name:{type:[String,Number,Boolean,Symbol],required:!0},props:{type:[Object,Function],default:()=>({})},showValid:{type:Boolean,default:!1},defaultValue:{type:[String,Number,Boolean,Array,Object],default:void 0},lazyLoad:{type:Boolean,default:!1},readonly:{type:Boolean,default:void 0}},emits:["invalid","update:formData","update:modelValue","valid"],expose:["component","errors","hasProps","invalid","invalidLabel","is","type"],slots:Object,setup(a,{slots:n,emit:v}){const{props:u,name:d}=e.toRefs(a),V=e.inject(f,void 0);V&&V.fields.value.add(a.name);const l=e.inject(r),h=e.computed({get(){if(l!=null&&l.formData)return Z(new Object(l.formData.value),String(a.name))},set(s){l!=null&&l.formData&&(q(new Object(l.formData.value),String(a.name),s),v("update:modelValue",{newValue:h.value,formData:l==null?void 0:l.formData}))}});e.onMounted(()=>{h.value===void 0&&a.defaultValue!==void 0&&(h.value=a.defaultValue)});const b=e.computed(()=>{if(l!=null&&l.errors.value)return Z(l.errors.value,String(a.name))}),y=e.computed(()=>{var s;return(s=b.value)==null?void 0:s._errors}),o=e.computed(()=>b.value!==void 0),O=e.watch(o,()=>{if(o.value){v("invalid",b.value),V&&V.errors.value.set(String(a.name),b.value);return}v("valid",h.value),V&&V.errors.value.delete(a.name)}),S=e.watch(()=>l==null?void 0:l.formData,()=>{v("update:formData",l==null?void 0:l.formData)},{deep:!0});e.onBeforeUnmount(()=>{O(),S()});const E=s=>{s instanceof InputEvent&&(s=s.target.value),h.value=s},k=e.computed(()=>{let s=u.value;return typeof s=="function"&&(s=s(l==null?void 0:l.formData)),Object.keys(s).reduce((W,R)=>(W[R]=e.unref(s[R]),W),{})}),x=e.computed(()=>l!=null&&l.readonly.value?!0:k.value.readonly??a.readonly),w=e.computed(()=>({...k.value,name:k.value.name??a.name,invalid:o.value,valid:a.showValid?!!(!o.value&&h.value):void 0,type:(s=>{if([p.color,p.date,p.datetimeLocal,p.email,p.month,p.number,p.password,p.search,p.tel,p.text,p.time,p.url,p.week].includes(s))return s})(a.type),invalidLabel:y.value,modelValue:h.value,readonly:x.value,"onUpdate:modelValue":E}));return e.provide(t,{name:e.readonly(d),errors:e.readonly(b)}),{component:e.computed(()=>{if(a.type===p.custom)return{render(){var s;return((s=n.default)==null?void 0:s.call(n,{errors:b.value,formData:l==null?void 0:l.formData.value,formErrors:l==null?void 0:l.errors.value,invalid:o.value,invalidLabel:y.value,modelValue:h.value,onUpdate:E,readonly:x.value,submit:l==null?void 0:l.submit,validate:l==null?void 0:l.validate}))??n.default}};if(!((c==null?void 0:c.lazyLoad)??a.lazyLoad)){let s;switch(a.type){case p.select:s=e.resolveComponent("VvSelect");break;case p.checkbox:s=e.resolveComponent("VvCheckbox");break;case p.radio:s=e.resolveComponent("VvRadio");break;case p.textarea:s=e.resolveComponent("VvTextarea");break;case p.radioGroup:s=e.resolveComponent("VvRadioGroup");break;case p.checkboxGroup:s=e.resolveComponent("VvCheckboxGroup");break;case p.combobox:s=e.resolveComponent("VvCombobox");break;default:s=e.resolveComponent("VvInputText")}if(typeof s!="string")return s;console.warn(`[form-vue warn]: ${s} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`)}return e.defineAsyncComponent(async()=>{switch(c!=null&&c.sideEffects&&await Promise.resolve(c.sideEffects(a.type)),a.type){case p.textarea:return import("@volverjs/ui-vue/vv-textarea");case p.radio:return import("@volverjs/ui-vue/vv-radio");case p.radioGroup:return import("@volverjs/ui-vue/vv-radio-group");case p.checkbox:return import("@volverjs/ui-vue/vv-checkbox");case p.checkboxGroup:return import("@volverjs/ui-vue/vv-checkbox-group");case p.select:return import("@volverjs/ui-vue/vv-select");case p.combobox:return import("@volverjs/ui-vue/vv-combobox")}return import("@volverjs/ui-vue/vv-input-text")})}),hasProps:w,invalid:o}},render(){return this.is?e.h(this.is,this.hasProps,this.$slots):this.type===p.custom?e.h(this.component,null,this.$slots):e.h(this.component,this.hasProps,this.$slots)}})}function re(r,f,t){return e.defineComponent({name:"VvFormFieldsGroup",props:{is:{type:[Object,String],default:void 0},names:{type:[Array],required:!0},props:{type:[Object,Function],default:()=>({})},showValid:{type:Boolean,default:!1},defaultValues:{type:[Object],default:void 0},readonly:{type:Boolean,default:void 0}},emits:["invalid","update:formData","update:modelValue","valid"],expose:["component","errors","hasProps","invalid","invalidLabels","is"],slots:Object,setup(c,{slots:a,emit:n}){const{props:v,names:u,defaultValues:d}=e.toRefs(c),V=e.computed(()=>Array.isArray(u.value)?u.value:Object.values(u.value)),l=e.computed(()=>Array.isArray(u.value)?u.value:Object.keys(u.value)),h=e.computed(()=>Array.isArray(u.value)?u.value.reduce((i,m)=>(i[String(m)]=m,i),{}):u.value),b=e.computed(()=>Object.keys(h.value).reduce((i,m)=>(i[String(h.value[m])]=m,i),{})),y=e.inject(f,void 0);y&&V.value.forEach(i=>{y.fields.value.add(i)});const o=e.inject(r),O=e.computed({get(){return o!=null&&o.formData?l.value.reduce((i,m)=>(i[m]=Z(new Object(o.formData.value),h.value[m]),i),{}):{}},set(i){o!=null&&o.formData&&(l.value.forEach(m=>{q(new Object(o.formData.value),h.value[m],i==null?void 0:i[m])}),n("update:modelValue",{newValue:O.value,formData:o==null?void 0:o.formData}))}});e.onMounted(()=>{d.value&&V.value.forEach(i=>{var m,I;((m=d.value)==null?void 0:m[i])!==void 0&&O.value[i]===void 0&&(O.value={...O.value,[i]:(I=d.value)==null?void 0:I[i]})})});const S=e.computed(()=>{if(!(o!=null&&o.errors.value))return;const i=V.value.reduce((m,I)=>{if(!o.errors.value)return m;const N=Z(o.errors.value,String(I));return N===void 0||(m[String(I)]=N),m},{});if(Object.keys(i).length!==0)return i}),E=e.computed(()=>{if(!S.value)return;const i=Object.keys(S.value).reduce((m,I)=>{var N;return(N=S.value)!=null&&N[I]&&(m[b.value[I]]=S.value[I]._errors),m},{});if(Object.keys(i).length!==0)return i}),k=e.computed(()=>S.value!==void 0),x=e.computed(()=>l.value.reduce((i,m)=>{var I;return i[m]=!!((I=S.value)!=null&&I[b.value[m]]),i},{})),w=e.watch(k,()=>{if(k.value){n("invalid",S.value),y&&V.value.forEach(i=>{var m,I;if(!((m=S.value)!=null&&m[i])){y.errors.value.delete(i);return}y.errors.value.set(i,(I=S.value)==null?void 0:I[i])});return}n("valid",O.value),y&&V.value.forEach(i=>{y.errors.value.delete(i)})}),g=e.watch(()=>o==null?void 0:o.formData,()=>{n("update:formData",o==null?void 0:o.formData)},{deep:!0});e.onBeforeUnmount(()=>{w(),g()});const s=i=>{O.value=i},W=(i,m)=>{m instanceof InputEvent&&(m=m.target.value),l.value.includes(i)&&(O.value={...O.value,[i]:m})},R=e.computed(()=>{let i=v.value;return typeof i=="function"&&(i=i(o==null?void 0:o.formData)),Object.keys(i).reduce((m,I)=>(m[I]=e.unref(i[I]),m),{})}),G=e.computed(()=>o!=null&&o.readonly.value?!0:R.value.readonly??c.readonly),$=e.computed(()=>l.value.reduce((i,m)=>(i[`onUpdate:${m}`]=I=>{W(m,I)},i),{"onUpdate:modelValue":s})),M=e.computed(()=>({...$.value,...R.value,names:R.value.name??V.value,invalid:k.value,invalids:x.value,valid:c.showValid?!!(!k.value&&O.value):void 0,invalidLabels:E.value,modelValue:O.value,readonly:G.value}));return e.provide(t,{names:e.readonly(u),errors:e.readonly(S)}),{component:e.computed(()=>({render(){var i;return((i=a.default)==null?void 0:i.call(a,{errors:S.value,formData:o==null?void 0:o.formData.value,formErrors:o==null?void 0:o.errors.value,invalid:k.value,invalids:x.value,invalidLabels:E.value,modelValue:O.value,onUpdate:s,onUpdateField:W,readonly:G.value,submit:o==null?void 0:o.submit,validate:o==null?void 0:o.validate}))??a.default}})),hasProps:M,invalid:k}},render(){return this.is?e.h(this.is,this.hasProps,this.$slots):e.h(this.component,null,this.$slots)}})}function te(r,f){return e.defineComponent({name:"VvFormWrapper",props:{name:{type:String,required:!0},tag:{type:String,default:void 0}},emits:["invalid","valid"],expose:["clear","errors","fields","fieldsErrors","formData","invalid","reset","submit","tag","validate","validateWrapper"],slots:Object,setup(t,{emit:c}){const a=e.inject(r),n=e.inject(f,void 0),v=e.ref(new Set),u=e.ref(new Map),{name:d}=e.toRefs(t);e.provide(f,{name:e.readonly(d),errors:u,fields:v}),e.watch(v,h=>{n!=null&&n.fields&&h.forEach(b=>{n==null||n.fields.value.add(b)})},{deep:!0}),e.watch(()=>new Map(u.value),(h,b)=>{n!=null&&n.errors&&(Array.from(b.keys()).forEach(y=>{n.errors.value.delete(y)}),Array.from(h.keys()).forEach(y=>{const o=h.get(y);o&&n.errors.value.set(y,o)}))},{deep:!0});const V=e.computed(()=>a!=null&&a.invalid.value?u.value.size>0:!1);e.watch(V,()=>{V.value?c("invalid"):c("valid")});const l=()=>(a==null?void 0:a.validate(void 0,v.value))??Promise.resolve(!0);return{clear:a==null?void 0:a.clear,errors:a==null?void 0:a.errors,fields:v,fieldsErrors:u,formData:a==null?void 0:a.formData,invalid:V,reset:a==null?void 0:a.reset,submit:a==null?void 0:a.submit,validate:a==null?void 0:a.validate,validateWrapper:l}},render(){const t=()=>{var c,a;return(a=(c=this.$slots).default)==null?void 0:a.call(c,{clear:this.clear,errors:this.errors,fieldsErrors:this.fieldsErrors,formData:this.formData,invalid:this.invalid,reset:this.reset,submit:this.submit,validate:this.validate,validateWrapper:this.validateWrapper})};return this.tag?e.h(this.tag,null,{default:t}):t()}})}function ae(r,f){const t=e.defineComponent({name:"VvFormTemplate",props:{schema:{type:[Array,Function],required:!0},scope:{type:Object,default:()=>({})}},slots:Object,setup(c,{slots:a}){const n=e.inject(r);if(n!=null&&n.formData)return()=>{var V;const v=typeof c.schema=="function"?c.schema(n,c.scope):c.schema;let u;const d=v.reduce((l,h)=>{const b=typeof h=="function"?h(n,c.scope):h,{vvIs:y,vvName:o,vvSlots:O,vvChildren:S,vvIf:E,vvElseIf:k,vvType:x,vvDefaultValue:w,vvShowValid:g,vvContent:s,...W}=b;if(E!==void 0){if(typeof E=="string"?u=!!Z(new Object(n.formData.value),E):typeof E=="function"?u=e.unref(E(n)):u=e.unref(E),!u)return l}else if(k!==void 0&&u!==void 0){if(u||(typeof k=="string"?u=!!Z(new Object(n.formData.value),k):typeof k=="function"?u=e.unref(k(n)):u=e.unref(k),!u))return l}else u=void 0;let R;return S&&(typeof y=="string"?R=e.h(t,{schema:S}):R={default:G=>e.h(t,{schema:S,scope:G})}),o?(l.push(e.h(f,{name:o,is:y,type:x,defaultValue:w,showValid:g,props:W},O??R??s)),l):y?(l.push(e.h(y,W,O??R??s)),l):(R&&("default"in R?l.push(R.default(c.scope)):l.push(R)),l)},[]);return d.push((V=a==null?void 0:a.default)==null?void 0:V.call(a,{errors:n==null?void 0:n.errors.value,formData:n==null?void 0:n.formData.value,invalid:n==null?void 0:n.invalid.value,status:n==null?void 0:n.status.value,submit:n==null?void 0:n.submit,validate:n==null?void 0:n.validate,clear:n==null?void 0:n.clear,reset:n==null?void 0:n.reset})),d}}});return t}function K(r,f={}){const t=Symbol("formInjectionKey"),c=Symbol("formWrapperInjectionKey"),a=Symbol("formFieldInjectionKey"),n=Symbol("formFieldsGroupInjectionKey"),v=te(t,c),u=ee(t,c,a,f),d=re(t,c,n),V=ae(t,u),{clear:l,errors:h,formData:b,ignoreUpdates:y,invalid:o,readonly:O,reset:S,status:E,stopUpdatesWatch:k,submit:x,validate:w,VvForm:g}=z(r,t,f,V);return{clear:l,errors:h,formData:b,formFieldInjectionKey:a,formInjectionKey:t,formWrapperInjectionKey:c,ignoreUpdates:y,invalid:o,readonly:O,reset:S,status:E,stopUpdatesWatch:k,submit:x,validate:w,VvForm:g,VvFormField:u,VvFormFieldsGroup:d,VvFormTemplate:V,VvFormWrapper:v}}const J=Symbol("pluginInjectionKey");function ne(r){let f={};return r.schema&&(f=K(r.schema,r)),{...f,install(t,{global:c=!1}={}){t.provide(J,r),c&&(t.config.globalProperties.$vvForm=r,f!=null&&f.VvForm&&t.component("VvForm",f.VvForm),f!=null&&f.VvFormWrapper&&t.component("VvFormWrapper",f.VvFormWrapper),f!=null&&f.VvFormField&&t.component("VvFormField",f.VvFormField),f!=null&&f.VvFormTemplate&&t.component("VvFormTemplate",f.VvFormTemplate))}}}function le(r,f={}){return e.getCurrentInstance()?K(r,{...e.inject(J,{}),...f}):K(r,f)}function ue(r,f={}){return K(r,f)}A.FormFieldType=p,A.createForm=ne,A.defaultObjectBySchema=L,A.formFactory=ue,A.pluginInjectionKey=J,A.useForm=le,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})});
1
+ (function(A,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("@vueuse/core"),require("zod")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","zod"],e):(A=typeof globalThis<"u"?globalThis:A||self,e(A["@volverjs/form-vue"]={},A.Vue,A.VueUseCore,A.zod))})(this,function(A,e,T,B){"use strict";var p=(r=>(r.text="text",r.number="number",r.email="email",r.password="password",r.tel="tel",r.url="url",r.search="search",r.date="date",r.time="time",r.datetimeLocal="datetime-local",r.month="month",r.week="week",r.color="color",r.select="select",r.checkbox="checkbox",r.radio="radio",r.textarea="textarea",r.radioGroup="radioGroup",r.checkboxGroup="checkboxGroup",r.combobox="combobox",r.custom="custom",r))(p||{}),G=(r=>(r.invalid="invalid",r.valid="valid",r.submitting="submitting",r.reset="reset",r.updated="updated",r.unknown="unknown",r))(G||{});function L(r,s={}){const t=v=>{let u=v;for(;u instanceof B.ZodEffects;)u=u.innerType();return u instanceof B.ZodOptional&&(u=u._def.innerType),u},c=v=>{let u=v;for(;u instanceof B.ZodEffects;)u=u.innerType();return u instanceof B.ZodOptional},a=t(r);return{...(a instanceof B.ZodObject?a._def.unknownKeys==="passthrough":!1)?s:{},...Object.fromEntries(Object.entries(a.shape).map(([v,u])=>{const d=s[v],V=c(u);let l=t(u),h;if(l instanceof B.ZodDefault&&(h=l._def.defaultValue(),l=l._def.innerType),d===null&&l instanceof B.ZodNullable)return[v,d];if(d==null&&V)return[v,h];if(l instanceof B.ZodSchema){const b=u.safeParse(d);if(b.success)return[v,b.data??h]}if(l instanceof B.ZodArray&&Array.isArray(d)&&d.length){const b=t(l._def.type);if(b instanceof B.ZodObject)return[v,d.map(y=>L(b,y&&typeof y=="object"?y:void 0))]}if(l instanceof B.ZodRecord&&d){const b=t(l._def.valueType);if(b instanceof B.ZodObject)return[v,Object.keys(d).reduce((y,o)=>(y[o]=L(b,d[o]),y),{})]}return l instanceof B.ZodObject?[v,L(l,d&&typeof d=="object"?d:h)]:[v,h]}))}}function z(r,s,t,c){const a=e.ref(),n=e.ref(),v=e.computed(()=>n.value===G.invalid),u=e.ref(),d=e.ref(!1);let V;const l=async(x=u.value,w)=>{if(V=w,d.value)return!0;const g=await r.safeParseAsync(x);if(!g.success){if(n.value=G.invalid,!w)return a.value=g.error.format(),!1;const i=g.error.issues.filter(U=>w.has(U.path.join(".")));return i.length?(a.value=new B.ZodError(i).format(),!1):(a.value=void 0,!0)}return a.value=void 0,n.value=G.valid,u.value=g.data,!0},h=()=>{a.value=void 0,n.value=void 0,V=void 0},b=()=>{u.value=L(r),h(),n.value=G.reset},y=async()=>d.value||!await l()?!1:(n.value=G.submitting,!0),{ignoreUpdates:o,stop:O}=T.watchIgnorable(u,()=>{n.value=G.updated},{deep:!0,eventFilter:T.throttleFilter((t==null?void 0:t.updateThrottle)??500)}),S=e.readonly(a),E=e.readonly(n),k=e.defineComponent({name:"VvForm",props:{continuousValidation:{type:Boolean,default:!1},modelValue:{type:Object,default:()=>({})},readonly:{type:Boolean,default:(t==null?void 0:t.readonly)??!1},tag:{type:String,default:"form"},template:{type:[Array,Function],default:void 0}},emits:["invalid","submit","update:modelValue","update:readonly","valid","reset"],expose:["errors","invalid","readonly","status","submit","tag","template","valid","validate","clear","reset"],slots:Object,setup(x,{emit:w}){return u.value=L(r,e.toRaw(x.modelValue)),e.watch(()=>x.modelValue,g=>{if(g){const i=e.isProxy(g)?e.toRaw(g):g;if(JSON.stringify(i)===JSON.stringify(e.toRaw(u.value)))return;u.value=typeof(i==null?void 0:i.clone)=="function"?i.clone():JSON.parse(JSON.stringify(i))}},{deep:!0}),e.watch(n,async g=>{var i,U,R,W,$,M;if(g===G.invalid){const C=e.toRaw(a.value);w("invalid",C),(i=t==null?void 0:t.onInvalid)==null||i.call(t,C);return}if(g===G.valid){const C=e.toRaw(u.value);w("valid",C),(U=t==null?void 0:t.onValid)==null||U.call(t,C),w("update:modelValue",C),(R=t==null?void 0:t.onUpdate)==null||R.call(t,C);return}if(g===G.submitting){const C=e.toRaw(u.value);w("submit",C),(W=t==null?void 0:t.onSubmit)==null||W.call(t,C);return}if(g===G.reset){const C=e.toRaw(u.value);w("reset",C),($=t==null?void 0:t.onReset)==null||$.call(t,C);return}if(g===G.updated){if((a.value||t!=null&&t.continuousValidation||x.continuousValidation)&&await l(void 0,V),!u.value||!x.modelValue||JSON.stringify(u.value)!==JSON.stringify(x.modelValue)){const C=e.toRaw(u.value);w("update:modelValue",C),(M=t==null?void 0:t.onUpdate)==null||M.call(t,C)}n.value===G.updated&&(n.value=G.unknown)}}),e.onMounted(()=>{d.value=x.readonly}),e.watch(()=>x.readonly,g=>{d.value=g}),e.watch(d,g=>{g!==x.readonly&&w("update:readonly",d.value)}),e.provide(s,{clear:h,errors:S,formData:u,ignoreUpdates:o,invalid:v,readonly:d,reset:b,status:E,stopUpdatesWatch:O,submit:y,validate:l}),{clear:h,errors:S,formData:u,ignoreUpdates:o,invalid:v,isReadonly:d,reset:b,status:E,stopUpdatesWatch:O,submit:y,validate:l}},render(){const x=()=>{var w,g;return((g=(w=this.$slots)==null?void 0:w.default)==null?void 0:g.call(w,{clear:h,errors:S,formData:u,ignoreUpdates:o,invalid:v,readonly:d,reset:b,status:E,stopUpdatesWatch:O,submit:y,validate:l}))??this.$slots.default};return e.h(this.tag,{onSubmit:e.withModifiers(this.submit,["prevent"]),onReset:e.withModifiers(this.reset,["prevent"])},(this.template??(t==null?void 0:t.template))&&c?[e.h(c,{schema:this.template??(t==null?void 0:t.template)},{default:x})]:{default:x})}});return{clear:h,errors:a,formData:u,ignoreUpdates:o,invalid:v,readonly:d,reset:b,status:n,stopUpdatesWatch:O,submit:y,validate:l,VvForm:k}}function P(r){return Array.isArray(r)}function j(r){return typeof r<"u"}function H(r){return r===null}function Q(r){return typeof r=="object"}function X(r){return typeof r=="string"}function _(r){return typeof r>"u"}const D=/^[0-9]+$/,F=["__proto__","prototype","constructor"];function Z(r,s,t){const c=j(t)?t:void 0;if(!Q(r)||!X(s))return c;const a=Y(s);if(a.length!==0){for(const n of a){if(n==="*")continue;const v=function(u){return u.map(d=>_(d)||H(d)?d:P(d)?v(d):d[n])};if(P(r)&&!D.test(n)?r=v(r):r=r[n],_(r)||H(r))break}return _(r)?c:r}}function q(r,s,t){if(!Q(r)||!X(s))return;const c=Y(s);if(c.length===0)return;const a=c.length;for(let n=0;n<a;n++){const v=c[n];if(n===a-1){r[v]=t;return}if(v==="*"&&P(r)){const u=c.slice(n+1).join(".");for(const d of r)q(d,u,t);return}_(r[v])&&(r[v]={}),r=r[v]}}function Y(r){const s=r.split(/[.]|(?:\[(\d|\*)\])/).filter(t=>!!t);return s.some(t=>F.indexOf(t)!==-1)?[]:s}function ee(r,s,t,c){return e.defineComponent({name:"VvFormField",props:{type:{type:String,validator:a=>Object.values(p).includes(a),default:p.custom},is:{type:[Object,String],default:void 0},name:{type:[String,Number,Boolean,Symbol],required:!0},props:{type:[Object,Function],default:()=>({})},showValid:{type:Boolean,default:!1},defaultValue:{type:[String,Number,Boolean,Array,Object],default:void 0},lazyLoad:{type:Boolean,default:!1},readonly:{type:Boolean,default:void 0}},emits:["invalid","update:formData","update:modelValue","valid"],expose:["component","errors","hasProps","invalid","invalidLabel","is","type"],slots:Object,setup(a,{slots:n,emit:v}){const{props:u,name:d}=e.toRefs(a),V=e.inject(s,void 0);V&&V.fields.value.add(a.name);const l=e.inject(r),h=e.computed({get(){if(l!=null&&l.formData)return Z(new Object(l.formData.value),String(a.name))},set(i){l!=null&&l.formData&&(q(new Object(l.formData.value),String(a.name),i),v("update:modelValue",{newValue:h.value,formData:l==null?void 0:l.formData}))}});e.onMounted(()=>{h.value===void 0&&a.defaultValue!==void 0&&(h.value=a.defaultValue)});const b=e.computed(()=>{if(l!=null&&l.errors.value)return Z(l.errors.value,String(a.name))}),y=e.computed(()=>{var i;return(i=b.value)==null?void 0:i._errors}),o=e.computed(()=>b.value!==void 0),O=e.watch(o,()=>{if(o.value){v("invalid",b.value),V&&V.errors.value.set(String(a.name),b.value);return}v("valid",h.value),V&&V.errors.value.delete(a.name)}),S=e.watch(()=>l==null?void 0:l.formData,()=>{v("update:formData",l==null?void 0:l.formData)},{deep:!0});e.onBeforeUnmount(()=>{O(),S()});const E=i=>{i instanceof InputEvent&&(i=i.target.value),h.value=i},k=e.computed(()=>{let i=u.value;return typeof i=="function"&&(i=i(l==null?void 0:l.formData)),Object.keys(i).reduce((U,R)=>(U[R]=e.unref(i[R]),U),{})}),x=e.computed(()=>l!=null&&l.readonly.value?!0:k.value.readonly??a.readonly),w=e.computed(()=>({...k.value,name:k.value.name??a.name,invalid:o.value,valid:a.showValid?!!(!o.value&&h.value):void 0,type:(i=>{if([p.color,p.date,p.datetimeLocal,p.email,p.month,p.number,p.password,p.search,p.tel,p.text,p.time,p.url,p.week].includes(i))return i})(a.type),invalidLabel:y.value,modelValue:h.value,readonly:x.value,"onUpdate:modelValue":E}));return e.provide(t,{name:e.readonly(d),errors:e.readonly(b)}),{component:e.computed(()=>{if(a.type===p.custom)return{render(){var i;return((i=n.default)==null?void 0:i.call(n,{errors:b.value,formData:l==null?void 0:l.formData.value,formErrors:l==null?void 0:l.errors.value,invalid:o.value,invalidLabel:y.value,modelValue:h.value,onUpdate:E,readonly:x.value,submit:l==null?void 0:l.submit,validate:l==null?void 0:l.validate}))??n.default}};if(!((c==null?void 0:c.lazyLoad)??a.lazyLoad)){let i;switch(a.type){case p.select:i=e.resolveComponent("VvSelect");break;case p.checkbox:i=e.resolveComponent("VvCheckbox");break;case p.radio:i=e.resolveComponent("VvRadio");break;case p.textarea:i=e.resolveComponent("VvTextarea");break;case p.radioGroup:i=e.resolveComponent("VvRadioGroup");break;case p.checkboxGroup:i=e.resolveComponent("VvCheckboxGroup");break;case p.combobox:i=e.resolveComponent("VvCombobox");break;default:i=e.resolveComponent("VvInputText")}if(typeof i!="string")return i;console.warn(`[form-vue warn]: ${i} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`)}return e.defineAsyncComponent(async()=>{switch(c!=null&&c.sideEffects&&await Promise.resolve(c.sideEffects(a.type)),a.type){case p.textarea:return import("@volverjs/ui-vue/vv-textarea");case p.radio:return import("@volverjs/ui-vue/vv-radio");case p.radioGroup:return import("@volverjs/ui-vue/vv-radio-group");case p.checkbox:return import("@volverjs/ui-vue/vv-checkbox");case p.checkboxGroup:return import("@volverjs/ui-vue/vv-checkbox-group");case p.select:return import("@volverjs/ui-vue/vv-select");case p.combobox:return import("@volverjs/ui-vue/vv-combobox")}return import("@volverjs/ui-vue/vv-input-text")})}),hasProps:w,invalid:o}},render(){return this.is?e.h(this.is,this.hasProps,this.$slots):this.type===p.custom?e.h(this.component,null,this.$slots):e.h(this.component,this.hasProps,this.$slots)}})}function re(r,s,t){return e.defineComponent({name:"VvFormFieldsGroup",props:{is:{type:[Object,String],default:void 0},names:{type:[Array,Object],required:!0},props:{type:[Object,Function],default:()=>({})},showValid:{type:Boolean,default:!1},defaultValues:{type:[Object],default:void 0},readonly:{type:Boolean,default:void 0}},emits:["invalid","update:formData","update:modelValue","valid"],expose:["component","errors","hasProps","invalid","invalidLabels","is"],slots:Object,setup(c,{slots:a,emit:n}){const{props:v,names:u,defaultValues:d}=e.toRefs(c),V=e.computed(()=>Array.isArray(u.value)?u.value:Object.values(u.value)),l=e.computed(()=>Array.isArray(u.value)?u.value:Object.keys(u.value)),h=e.computed(()=>Array.isArray(u.value)?u.value.reduce((f,m)=>(f[String(m)]=m,f),{}):u.value),b=e.computed(()=>Object.keys(h.value).reduce((f,m)=>(f[String(h.value[m])]=m,f),{})),y=e.inject(s,void 0);y&&V.value.forEach(f=>{y.fields.value.add(f)});const o=e.inject(r),O=e.computed({get(){return o!=null&&o.formData?l.value.reduce((f,m)=>(f[m]=Z(new Object(o.formData.value),h.value[m]),f),{}):{}},set(f){o!=null&&o.formData&&(l.value.forEach(m=>{q(new Object(o.formData.value),h.value[m],f==null?void 0:f[m])}),n("update:modelValue",{newValue:O.value,formData:o==null?void 0:o.formData}))}});e.onMounted(()=>{d.value&&V.value.forEach(f=>{var m,I;((m=d.value)==null?void 0:m[f])!==void 0&&O.value[f]===void 0&&(O.value={...O.value,[f]:(I=d.value)==null?void 0:I[f]})})});const S=e.computed(()=>{if(!(o!=null&&o.errors.value))return;const f=V.value.reduce((m,I)=>{if(!o.errors.value)return m;const N=Z(o.errors.value,String(I));return N===void 0||(m[String(I)]=N),m},{});if(Object.keys(f).length!==0)return f}),E=e.computed(()=>{if(!S.value)return;const f=Object.keys(S.value).reduce((m,I)=>{var N;return(N=S.value)!=null&&N[I]&&(m[b.value[I]]=S.value[I]._errors),m},{});if(Object.keys(f).length!==0)return f}),k=e.computed(()=>S.value!==void 0),x=e.computed(()=>l.value.reduce((f,m)=>{var I;return f[m]=!!((I=S.value)!=null&&I[b.value[m]]),f},{})),w=e.watch(k,()=>{if(k.value){n("invalid",S.value),y&&V.value.forEach(f=>{var m,I;if(!((m=S.value)!=null&&m[f])){y.errors.value.delete(f);return}y.errors.value.set(f,(I=S.value)==null?void 0:I[f])});return}n("valid",O.value),y&&V.value.forEach(f=>{y.errors.value.delete(f)})}),g=e.watch(()=>o==null?void 0:o.formData,()=>{n("update:formData",o==null?void 0:o.formData)},{deep:!0});e.onBeforeUnmount(()=>{w(),g()});const i=f=>{O.value=f},U=(f,m)=>{m instanceof InputEvent&&(m=m.target.value),l.value.includes(f)&&(O.value={...O.value,[f]:m})},R=e.computed(()=>{let f=v.value;return typeof f=="function"&&(f=f(o==null?void 0:o.formData)),Object.keys(f).reduce((m,I)=>(m[I]=e.unref(f[I]),m),{})}),W=e.computed(()=>o!=null&&o.readonly.value?!0:R.value.readonly??c.readonly),$=e.computed(()=>l.value.reduce((f,m)=>(f[`onUpdate:${m}`]=I=>{U(m,I)},f),{"onUpdate:modelValue":i})),M=e.computed(()=>({...$.value,...R.value,names:R.value.name??V.value,invalid:k.value,invalids:x.value,valid:c.showValid?!!(!k.value&&O.value):void 0,invalidLabels:E.value,modelValue:O.value,readonly:W.value}));return e.provide(t,{names:e.readonly(u),errors:e.readonly(S)}),{component:e.computed(()=>({render(){var f;return((f=a.default)==null?void 0:f.call(a,{errors:S.value,formData:o==null?void 0:o.formData.value,formErrors:o==null?void 0:o.errors.value,invalid:k.value,invalids:x.value,invalidLabels:E.value,modelValue:O.value,onUpdate:i,onUpdateField:U,readonly:W.value,submit:o==null?void 0:o.submit,validate:o==null?void 0:o.validate}))??a.default}})),hasProps:M,invalid:k}},render(){return this.is?e.h(this.is,this.hasProps,this.$slots):e.h(this.component,null,this.$slots)}})}function te(r,s){return e.defineComponent({name:"VvFormWrapper",props:{name:{type:String,required:!0},tag:{type:String,default:void 0}},emits:["invalid","valid"],expose:["clear","errors","fields","fieldsErrors","formData","invalid","reset","submit","tag","validate","validateWrapper"],slots:Object,setup(t,{emit:c}){const a=e.inject(r),n=e.inject(s,void 0),v=e.ref(new Set),u=e.ref(new Map),{name:d}=e.toRefs(t);e.provide(s,{name:e.readonly(d),errors:u,fields:v}),e.watch(v,h=>{n!=null&&n.fields&&h.forEach(b=>{n==null||n.fields.value.add(b)})},{deep:!0}),e.watch(()=>new Map(u.value),(h,b)=>{n!=null&&n.errors&&(Array.from(b.keys()).forEach(y=>{n.errors.value.delete(y)}),Array.from(h.keys()).forEach(y=>{const o=h.get(y);o&&n.errors.value.set(y,o)}))},{deep:!0});const V=e.computed(()=>a!=null&&a.invalid.value?u.value.size>0:!1);e.watch(V,()=>{V.value?c("invalid"):c("valid")});const l=()=>(a==null?void 0:a.validate(void 0,v.value))??Promise.resolve(!0);return{clear:a==null?void 0:a.clear,errors:a==null?void 0:a.errors,fields:v,fieldsErrors:u,formData:a==null?void 0:a.formData,invalid:V,reset:a==null?void 0:a.reset,submit:a==null?void 0:a.submit,validate:a==null?void 0:a.validate,validateWrapper:l}},render(){const t=()=>{var c,a;return(a=(c=this.$slots).default)==null?void 0:a.call(c,{clear:this.clear,errors:this.errors,fieldsErrors:this.fieldsErrors,formData:this.formData,invalid:this.invalid,reset:this.reset,submit:this.submit,validate:this.validate,validateWrapper:this.validateWrapper})};return this.tag?e.h(this.tag,null,{default:t}):t()}})}function ae(r,s){const t=e.defineComponent({name:"VvFormTemplate",props:{schema:{type:[Array,Function],required:!0},scope:{type:Object,default:()=>({})}},slots:Object,setup(c,{slots:a}){const n=e.inject(r);if(n!=null&&n.formData)return()=>{var V;const v=typeof c.schema=="function"?c.schema(n,c.scope):c.schema;let u;const d=v.reduce((l,h)=>{const b=typeof h=="function"?h(n,c.scope):h,{vvIs:y,vvName:o,vvSlots:O,vvChildren:S,vvIf:E,vvElseIf:k,vvType:x,vvDefaultValue:w,vvShowValid:g,vvContent:i,...U}=b;if(E!==void 0){if(typeof E=="string"?u=!!Z(new Object(n.formData.value),E):typeof E=="function"?u=e.unref(E(n)):u=e.unref(E),!u)return l}else if(k!==void 0&&u!==void 0){if(u||(typeof k=="string"?u=!!Z(new Object(n.formData.value),k):typeof k=="function"?u=e.unref(k(n)):u=e.unref(k),!u))return l}else u=void 0;let R;return S&&(typeof y=="string"?R=e.h(t,{schema:S}):R={default:W=>e.h(t,{schema:S,scope:W})}),o?(l.push(e.h(s,{name:o,is:y,type:x,defaultValue:w,showValid:g,props:U},O??R??i)),l):y?(l.push(e.h(y,U,O??R??i)),l):(R&&("default"in R?l.push(R.default(c.scope)):l.push(R)),l)},[]);return d.push((V=a==null?void 0:a.default)==null?void 0:V.call(a,{errors:n==null?void 0:n.errors.value,formData:n==null?void 0:n.formData.value,invalid:n==null?void 0:n.invalid.value,status:n==null?void 0:n.status.value,submit:n==null?void 0:n.submit,validate:n==null?void 0:n.validate,clear:n==null?void 0:n.clear,reset:n==null?void 0:n.reset})),d}}});return t}function K(r,s={}){const t=Symbol("formInjectionKey"),c=Symbol("formWrapperInjectionKey"),a=Symbol("formFieldInjectionKey"),n=Symbol("formFieldsGroupInjectionKey"),v=te(t,c),u=ee(t,c,a,s),d=re(t,c,n),V=ae(t,u),{clear:l,errors:h,formData:b,ignoreUpdates:y,invalid:o,readonly:O,reset:S,status:E,stopUpdatesWatch:k,submit:x,validate:w,VvForm:g}=z(r,t,s,V);return{clear:l,errors:h,formData:b,formFieldInjectionKey:a,formInjectionKey:t,formWrapperInjectionKey:c,ignoreUpdates:y,invalid:o,readonly:O,reset:S,status:E,stopUpdatesWatch:k,submit:x,validate:w,VvForm:g,VvFormField:u,VvFormFieldsGroup:d,VvFormTemplate:V,VvFormWrapper:v}}const J=Symbol("pluginInjectionKey");function ne(r){let s={};return r.schema&&(s=K(r.schema,r)),{...s,install(t,{global:c=!1}={}){t.provide(J,r),c&&(t.config.globalProperties.$vvForm=r,s!=null&&s.VvForm&&t.component("VvForm",s.VvForm),s!=null&&s.VvFormWrapper&&t.component("VvFormWrapper",s.VvFormWrapper),s!=null&&s.VvFormField&&t.component("VvFormField",s.VvFormField),s!=null&&s.VvFormFieldsGroup&&t.component("VvFormFieldsGroup",s.VvFormFieldsGroup),s!=null&&s.VvFormTemplate&&t.component("VvFormTemplate",s.VvFormTemplate))}}}function le(r,s={}){return e.getCurrentInstance()?K(r,{...e.inject(J,{}),...s}):K(r,s)}function ue(r,s={}){return K(r,s)}A.FormFieldType=p,A.createForm=ne,A.defaultObjectBySchema=L,A.formFactory=ue,A.pluginInjectionKey=J,A.useForm=le,Object.defineProperty(A,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@volverjs/form-vue",
3
3
  "type": "module",
4
- "version": "1.0.0-beta.23",
4
+ "version": "1.0.0-beta.24",
5
5
  "description": "Vue 3 Forms with @volverjs/ui-vue",
6
6
  "author": "8 Wave S.r.l.",
7
7
  "license": "MIT",
@@ -68,7 +68,7 @@
68
68
  "@vue/test-utils": "^2.4.6",
69
69
  "copy": "^0.3.2",
70
70
  "eslint": "^9.14.0",
71
- "happy-dom": "^15.10.1",
71
+ "happy-dom": "^15.11.0",
72
72
  "typescript": "^5.6.3",
73
73
  "vite": "^5.4.10",
74
74
  "vite-plugin-dts": "^4.3.0",
@@ -36,7 +36,7 @@ export function defineFormFieldsGroup<Schema extends FormSchema>(formProvideKey:
36
36
  default: undefined,
37
37
  },
38
38
  names: {
39
- type: [Array] as PropType<
39
+ type: [Array, Object] as PropType<
40
40
  Path<z.infer<Schema>>[] | Record<string, Path<z.infer<Schema>>>
41
41
  >,
42
42
  required: true,
package/src/index.ts CHANGED
@@ -117,6 +117,9 @@ export function createForm(options: FormPluginOptions): Plugin & Partial<ReturnT
117
117
  if (toReturn?.VvFormField) {
118
118
  app.component('VvFormField', toReturn.VvFormField)
119
119
  }
120
+ if (toReturn?.VvFormFieldsGroup) {
121
+ app.component('VvFormFieldsGroup', toReturn.VvFormFieldsGroup)
122
+ }
120
123
  if (toReturn?.VvFormTemplate) {
121
124
  app.component('VvFormTemplate', toReturn.VvFormTemplate)
122
125
  }
@@ -144,12 +147,14 @@ export { defaultObjectBySchema } from './utils'
144
147
  type FormComponent = ReturnType<typeof defineForm>
145
148
  type FormWrapperComponent = ReturnType<typeof defineFormWrapper>
146
149
  type FormFieldComponent = ReturnType<typeof defineFormField>
147
- type FormTemplateComponent = ReturnType<typeof defineFormTemplate>
150
+ type FormFieldsGroupComponent = ReturnType<typeof defineFormFieldsGroup>
151
+ type FormTemplateComponent = ReturnType<typeof defineFormFieldsGroup>
148
152
 
149
153
  export type {
150
154
  FormComponent,
151
155
  FormComposableOptions,
152
156
  FormFieldComponent,
157
+ FormFieldsGroupComponent,
153
158
  FormPluginOptions,
154
159
  FormSchema,
155
160
  FormTemplate,