@volverjs/form-vue 0.0.14-beta.2 → 0.0.14-beta.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/dist/index.es.js CHANGED
@@ -1,71 +1,71 @@
1
- import { defineComponent as G, computed as y, onMounted as Y, onBeforeUnmount as D, inject as S, toRefs as P, watch as w, unref as I, provide as K, readonly as k, resolveComponent as g, defineAsyncComponent as j, h as x, ref as A, toRaw as U, isProxy as F, withModifiers as ee, getCurrentInstance as re } from "vue";
2
- import { watchThrottled as te } from "@vueuse/core";
3
- import { ZodObject as W, ZodDefault as ae, ZodNullable as ne, ZodSchema as oe, ZodArray as se, ZodEffects as ue, ZodOptional as ie } from "zod";
4
- function z(e) {
1
+ import { defineComponent as W, computed as g, onMounted as D, onBeforeUnmount as j, inject as I, toRefs as R, watch as E, unref as _, provide as M, readonly as p, resolveComponent as O, defineAsyncComponent as F, h as x, ref as $, toRaw as S, isProxy as ee, withModifiers as re, getCurrentInstance as te } from "vue";
2
+ import { watchThrottled as ae } from "@vueuse/core";
3
+ import { ZodObject as K, ZodDefault as ue, ZodNullable as ne, ZodSchema as le, ZodArray as se, ZodEffects as ie, ZodOptional as fe } from "zod";
4
+ function U(e) {
5
5
  return Array.isArray(e);
6
6
  }
7
- function le(e) {
7
+ function oe(e) {
8
8
  return typeof e < "u";
9
9
  }
10
- function q(e) {
10
+ function P(e) {
11
11
  return e === null;
12
12
  }
13
- function T(e) {
13
+ function H(e) {
14
14
  return typeof e == "object";
15
15
  }
16
- function H(e) {
16
+ function Q(e) {
17
17
  return typeof e == "string";
18
18
  }
19
- function _(e) {
19
+ function N(e) {
20
20
  return typeof e > "u";
21
21
  }
22
- const fe = /^[0-9]+$/, ve = ["__proto__", "prototype", "constructor"];
23
- function N(e, o, l) {
24
- const i = le(l) ? l : void 0;
25
- if (!T(e) || !H(o))
26
- return i;
27
- const n = R(o);
22
+ const de = /^[0-9]+$/, ve = ["__proto__", "prototype", "constructor"];
23
+ function G(e, l, t) {
24
+ const f = oe(t) ? t : void 0;
25
+ if (!H(e) || !Q(l))
26
+ return f;
27
+ const n = X(l);
28
28
  if (n.length !== 0) {
29
29
  for (const r of n) {
30
30
  if (r === "*")
31
31
  continue;
32
- const s = function(a) {
33
- return a.map((u) => _(u) || q(u) ? u : z(u) ? s(u) : u[r]);
32
+ const u = function(i) {
33
+ return i.map((s) => N(s) || P(s) ? s : U(s) ? u(s) : s[r]);
34
34
  };
35
- if (z(e) && !fe.test(r) ? e = s(e) : e = e[r], _(e) || q(e))
35
+ if (U(e) && !de.test(r) ? e = u(e) : e = e[r], N(e) || P(e))
36
36
  break;
37
37
  }
38
- return _(e) ? i : e;
38
+ return N(e) ? f : e;
39
39
  }
40
40
  }
41
- function Q(e, o, l) {
42
- if (!T(e) || !H(o))
41
+ function T(e, l, t) {
42
+ if (!H(e) || !Q(l))
43
43
  return;
44
- const i = R(o);
45
- if (i.length === 0)
44
+ const f = X(l);
45
+ if (f.length === 0)
46
46
  return;
47
- const n = i.length;
47
+ const n = f.length;
48
48
  for (let r = 0; r < n; r++) {
49
- const s = i[r];
49
+ const u = f[r];
50
50
  if (r === n - 1) {
51
- e[s] = l;
51
+ e[u] = t;
52
52
  return;
53
53
  }
54
- if (s === "*" && z(e)) {
55
- const a = i.slice(r + 1).join(".");
56
- for (const u of e)
57
- Q(u, a, l);
54
+ if (u === "*" && U(e)) {
55
+ const i = f.slice(r + 1).join(".");
56
+ for (const s of e)
57
+ T(s, i, t);
58
58
  return;
59
59
  }
60
- _(e[s]) && (e[s] = {}), e = e[s];
60
+ N(e[u]) && (e[u] = {}), e = e[u];
61
61
  }
62
62
  }
63
- function R(e) {
64
- const o = e.split(/[.]|(?:\[(\d|\*)\])/).filter((l) => !!l);
65
- return o.some((l) => ve.indexOf(l) !== -1) ? [] : o;
63
+ function X(e) {
64
+ const l = e.split(/[.]|(?:\[(\d|\*)\])/).filter((t) => !!t);
65
+ return l.some((t) => ve.indexOf(t) !== -1) ? [] : l;
66
66
  }
67
- var v = /* @__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))(v || {}), $ = /* @__PURE__ */ ((e) => (e.invalid = "invalid", e.valid = "valid", e))($ || {});
68
- const de = (e, o, l, i) => G({
67
+ var v = /* @__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))(v || {}), B = /* @__PURE__ */ ((e) => (e.invalid = "invalid", e.valid = "valid", e))(B || {});
68
+ const ce = (e, l, t, f) => W({
69
69
  name: "FieldComponent",
70
70
  props: {
71
71
  type: {
@@ -100,68 +100,68 @@ const de = (e, o, l, i) => G({
100
100
  },
101
101
  emits: ["invalid", "valid", "update:formData", "update:modelValue"],
102
102
  expose: ["invalid", "invalidLabel", "errors"],
103
- setup(n, { slots: r, emit: s }) {
104
- const a = y({
103
+ setup(n, { slots: r, emit: u }) {
104
+ const i = g({
105
105
  get() {
106
- if (t != null && t.formData)
107
- return N(
108
- Object(t.formData.value),
106
+ if (a != null && a.formData)
107
+ return G(
108
+ Object(a.formData.value),
109
109
  String(n.name)
110
110
  );
111
111
  },
112
- set(f) {
113
- t != null && t.formData && (Q(
114
- Object(t.formData.value),
112
+ set(d) {
113
+ a != null && a.formData && (T(
114
+ Object(a.formData.value),
115
115
  String(n.name),
116
- f
117
- ), s("update:modelValue", {
118
- newValue: a.value,
119
- formData: t == null ? void 0 : t.formData
116
+ d
117
+ ), u("update:modelValue", {
118
+ newValue: i.value,
119
+ formData: a == null ? void 0 : a.formData
120
120
  }));
121
121
  }
122
122
  });
123
- Y(() => {
124
- a.value === void 0 && n.defaultValue !== void 0 && (a.value = n.defaultValue);
125
- }), D(() => {
126
- E(), V();
123
+ D(() => {
124
+ i.value === void 0 && n.defaultValue !== void 0 && (i.value = n.defaultValue);
125
+ }), j(() => {
126
+ w(), k();
127
127
  });
128
- const u = S(o, void 0);
129
- u && u.fields.value.add(n.name);
130
- const t = S(e), { props: m, name: h } = P(n), d = y(() => {
131
- if (t != null && t.errors.value)
132
- return N(t.errors.value, String(n.name));
133
- }), c = y(() => {
134
- var f;
135
- return (f = d.value) == null ? void 0 : f._errors;
136
- }), b = y(() => d.value !== void 0), E = w(b, () => {
137
- b.value ? (s("invalid", c.value), u && u.errors.value.set(
128
+ const s = I(l, void 0);
129
+ s && s.fields.value.add(n.name);
130
+ const a = I(e), { props: o, name: h } = R(n), b = g(() => {
131
+ if (a != null && a.errors.value)
132
+ return G(a.errors.value, String(n.name));
133
+ }), c = g(() => {
134
+ var d;
135
+ return (d = b.value) == null ? void 0 : d._errors;
136
+ }), m = g(() => b.value !== void 0), w = E(m, () => {
137
+ m.value ? (u("invalid", c.value), s && s.errors.value.set(
138
138
  n.name,
139
139
  {
140
140
  _errors: c.value
141
141
  }
142
- )) : (s("valid", a.value), u && u.errors.value.delete(
142
+ )) : (u("valid", i.value), s && s.errors.value.delete(
143
143
  n.name
144
144
  ));
145
- }), V = w(
146
- () => t == null ? void 0 : t.formData,
145
+ }), k = E(
146
+ () => a == null ? void 0 : a.formData,
147
147
  () => {
148
- s("update:formData", t == null ? void 0 : t.formData);
148
+ u("update:formData", a == null ? void 0 : a.formData);
149
149
  },
150
150
  { deep: !0 }
151
- ), p = (f) => {
152
- a.value = f;
153
- }, C = y(() => {
154
- let f = m.value;
155
- return typeof f == "function" && (f = f(t == null ? void 0 : t.formData)), Object.keys(f).reduce(
156
- (O, M) => (O[M] = I(f[M]), O),
151
+ ), y = (d) => {
152
+ i.value = d;
153
+ }, V = g(() => {
154
+ let d = o.value;
155
+ return typeof d == "function" && (d = d(a == null ? void 0 : a.formData)), Object.keys(d).reduce(
156
+ (A, C) => (A[C] = _(d[C]), A),
157
157
  {}
158
158
  );
159
- }), L = y(() => ({
160
- ...C.value,
161
- name: C.value.name ?? n.name,
162
- invalid: b.value,
163
- valid: n.showValid ? !!(!b.value && a.value) : void 0,
164
- type: ((f) => {
159
+ }), z = g(() => ({
160
+ ...V.value,
161
+ name: V.value.name ?? n.name,
162
+ invalid: m.value,
163
+ valid: n.showValid ? !!(!m.value && i.value) : void 0,
164
+ type: ((d) => {
165
165
  if ([
166
166
  v.text,
167
167
  v.number,
@@ -176,69 +176,69 @@ const de = (e, o, l, i) => G({
176
176
  v.month,
177
177
  v.week,
178
178
  v.color
179
- ].includes(f))
180
- return f;
179
+ ].includes(d))
180
+ return d;
181
181
  })(n.type),
182
182
  invalidLabel: c.value,
183
- modelValue: a.value,
184
- "onUpdate:modelValue": p
183
+ modelValue: i.value,
184
+ "onUpdate:modelValue": y
185
185
  }));
186
- return K(l, {
187
- name: k(h),
188
- errors: k(d)
189
- }), { component: y(() => {
186
+ return M(t, {
187
+ name: p(h),
188
+ errors: p(b)
189
+ }), { component: g(() => {
190
190
  if (n.type === v.custom)
191
191
  return {
192
192
  render() {
193
- var f;
194
- return ((f = r.default) == null ? void 0 : f.call(r, {
195
- modelValue: a.value,
196
- onUpdate: p,
197
- submit: t == null ? void 0 : t.submit,
198
- validate: t == null ? void 0 : t.validate,
199
- invalid: b.value,
193
+ var d;
194
+ return ((d = r.default) == null ? void 0 : d.call(r, {
195
+ modelValue: i.value,
196
+ onUpdate: y,
197
+ submit: a == null ? void 0 : a.submit,
198
+ validate: a == null ? void 0 : a.validate,
199
+ invalid: m.value,
200
200
  invalidLabel: c.value,
201
- formData: t == null ? void 0 : t.formData.value,
202
- formErrors: t == null ? void 0 : t.errors.value,
203
- errors: d.value
201
+ formData: a == null ? void 0 : a.formData.value,
202
+ formErrors: a == null ? void 0 : a.errors.value,
203
+ errors: b.value
204
204
  })) ?? r.defalut;
205
205
  }
206
206
  };
207
- if (!((i == null ? void 0 : i.lazyLoad) ?? n.lazyLoad)) {
208
- let f;
207
+ if (!((f == null ? void 0 : f.lazyLoad) ?? n.lazyLoad)) {
208
+ let d;
209
209
  switch (n.type) {
210
210
  case v.select:
211
- f = g("VvSelect");
211
+ d = O("VvSelect");
212
212
  break;
213
213
  case v.checkbox:
214
- f = g("VvCheckbox");
214
+ d = O("VvCheckbox");
215
215
  break;
216
216
  case v.radio:
217
- f = g("VvRadio");
217
+ d = O("VvRadio");
218
218
  break;
219
219
  case v.textarea:
220
- f = g("VvTextarea");
220
+ d = O("VvTextarea");
221
221
  break;
222
222
  case v.radioGroup:
223
- f = g("VvRadioGroup");
223
+ d = O("VvRadioGroup");
224
224
  break;
225
225
  case v.checkboxGroup:
226
- f = g("VvCheckboxGroup");
226
+ d = O("VvCheckboxGroup");
227
227
  break;
228
228
  case v.combobox:
229
- f = g("VvCombobox");
229
+ d = O("VvCombobox");
230
230
  break;
231
231
  default:
232
- f = g("VvInputText");
232
+ d = O("VvInputText");
233
233
  }
234
- if (typeof f != "string")
235
- return f;
234
+ if (typeof d != "string")
235
+ return d;
236
236
  console.warn(
237
- `[form-vue warn]: ${f} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`
237
+ `[form-vue warn]: ${d} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`
238
238
  );
239
239
  }
240
- return j(async () => {
241
- switch (i != null && i.sideEffects && await Promise.resolve(i.sideEffects(n.type)), n.type) {
240
+ return F(async () => {
241
+ switch (f != null && f.sideEffects && await Promise.resolve(f.sideEffects(n.type)), n.type) {
242
242
  case v.textarea:
243
243
  return import("@volverjs/ui-vue/vv-textarea");
244
244
  case v.radio:
@@ -256,58 +256,58 @@ const de = (e, o, l, i) => G({
256
256
  }
257
257
  return import("@volverjs/ui-vue/vv-input-text");
258
258
  });
259
- }), hasProps: L, invalid: b };
259
+ }), hasProps: z, invalid: m };
260
260
  },
261
261
  render() {
262
262
  return this.is ? x(this.is, this.hasProps, this.$slots) : this.type === v.custom ? x(this.component, null, this.$slots) : x(this.component, this.hasProps, this.$slots);
263
263
  }
264
- }), Z = (e, o = {}) => {
265
- const l = (r) => {
266
- let s = r;
267
- for (; s instanceof ue; )
268
- s = s.innerType();
269
- return s instanceof ie && (s = s._def.innerType), s;
270
- }, i = l(e);
264
+ }), J = (e, l = {}) => {
265
+ const t = (r) => {
266
+ let u = r;
267
+ for (; u instanceof ie; )
268
+ u = u.innerType();
269
+ return u instanceof fe && (u = u._def.innerType), u;
270
+ }, f = t(e);
271
271
  return {
272
- ...(i instanceof W ? i._def.unknownKeys === "passthrough" : !1) ? o : {},
272
+ ...(f instanceof K ? f._def.unknownKeys === "passthrough" : !1) ? l : {},
273
273
  ...Object.fromEntries(
274
- Object.entries(i.shape).map(
275
- ([r, s]) => {
276
- const a = o[r];
277
- let u = l(s), t;
278
- if (u instanceof ae && (t = u._def.defaultValue(), u = u._def.innerType), a === null && u instanceof ne)
279
- return [r, a];
280
- if (u instanceof oe) {
281
- const m = s.safeParse(a);
282
- if (m.success)
283
- return [r, m.data ?? t];
274
+ Object.entries(f.shape).map(
275
+ ([r, u]) => {
276
+ const i = l[r];
277
+ let s = t(u), a;
278
+ if (s instanceof ue && (a = s._def.defaultValue(), s = s._def.innerType), i === null && s instanceof ne)
279
+ return [r, i];
280
+ if (s instanceof le) {
281
+ const o = u.safeParse(i);
282
+ if (o.success)
283
+ return [r, o.data ?? a];
284
284
  }
285
- if (u instanceof se && Array.isArray(a) && a.length) {
286
- const m = l(u._def.type);
287
- if (m instanceof W)
285
+ if (s instanceof se && Array.isArray(i) && i.length) {
286
+ const o = t(s._def.type);
287
+ if (o instanceof K)
288
288
  return [
289
289
  r,
290
- a.map(
291
- (h) => Z(
292
- m,
290
+ i.map(
291
+ (h) => J(
292
+ o,
293
293
  h && typeof h == "object" ? h : void 0
294
294
  )
295
- ) ?? t
295
+ ) ?? a
296
296
  ];
297
297
  }
298
- return u instanceof W ? [
298
+ return s instanceof K ? [
299
299
  r,
300
- Z(
301
- u,
302
- a && typeof a == "object" ? a : t
300
+ J(
301
+ s,
302
+ i && typeof i == "object" ? i : a
303
303
  )
304
- ] : [r, t];
304
+ ] : [r, a];
305
305
  }
306
306
  )
307
307
  )
308
308
  };
309
- }, ce = (e, o, l) => {
310
- const i = A(), n = A(), r = A(), s = G({
309
+ }, me = (e, l, t, f) => {
310
+ const n = $(), r = $(), u = $(), i = W({
311
311
  name: "FormComponent",
312
312
  props: {
313
313
  modelValue: {
@@ -321,85 +321,105 @@ const de = (e, o, l, i) => G({
321
321
  continuosValidation: {
322
322
  type: Boolean,
323
323
  default: !1
324
+ },
325
+ template: {
326
+ type: [Array, Function],
327
+ default: void 0
324
328
  }
325
329
  },
326
330
  emits: ["invalid", "valid", "submit", "update:modelValue"],
327
331
  expose: ["submit", "validate", "errors", "status", "valid", "invalid"],
328
- setup(a, { emit: u }) {
329
- r.value = Z(
332
+ setup(s, { emit: a }) {
333
+ u.value = J(
330
334
  e,
331
- U(a.modelValue)
332
- ), w(
333
- () => a.modelValue,
334
- (d) => {
335
- if (d) {
336
- const c = F(d) ? U(d) : d;
337
- r.value = typeof (c == null ? void 0 : c.clone) == "function" ? c.clone() : JSON.parse(JSON.stringify(c));
335
+ S(s.modelValue)
336
+ ), E(
337
+ () => s.modelValue,
338
+ (c) => {
339
+ if (c) {
340
+ const m = ee(c) ? S(c) : c;
341
+ u.value = typeof (m == null ? void 0 : m.clone) == "function" ? m.clone() : JSON.parse(JSON.stringify(m));
338
342
  }
339
343
  },
340
344
  { deep: !0 }
341
- ), te(
342
- r,
343
- (d) => {
344
- ((i.value || (l == null ? void 0 : l.continuosValidation)) ?? a.continuosValidation) && t(), (!d || !a.modelValue || JSON.stringify(d) !== JSON.stringify(a.modelValue)) && u("update:modelValue", d);
345
+ ), ae(
346
+ u,
347
+ (c) => {
348
+ var m;
349
+ ((n.value || (t == null ? void 0 : t.continuosValidation)) ?? s.continuosValidation) && o(), (!c || !s.modelValue || JSON.stringify(c) !== JSON.stringify(s.modelValue)) && (a("update:modelValue", c), (m = t == null ? void 0 : t.onUpdate) == null || m.call(t, S(c)));
345
350
  },
346
351
  {
347
352
  deep: !0,
348
- throttle: (l == null ? void 0 : l.updateThrottle) ?? a.updateThrottle
353
+ throttle: (t == null ? void 0 : t.updateThrottle) ?? s.updateThrottle
349
354
  }
350
355
  );
351
- const t = (d = r.value) => {
352
- const c = e.safeParse(d);
353
- return c.success ? (i.value = void 0, n.value = $.valid, r.value = c.data, u("update:modelValue", r.value), u("valid", c.data), !0) : (i.value = c.error.format(), n.value = $.invalid, u("invalid", i.value), !1);
354
- }, m = () => t() ? (u("submit", r.value), !0) : !1, h = y(() => n.value === $.invalid);
355
- return K(o, {
356
- formData: r,
357
- submit: m,
358
- validate: t,
359
- errors: k(i),
360
- status: k(n),
361
- invalid: h
356
+ const o = (c = u.value) => {
357
+ var w, k, y;
358
+ const m = e.safeParse(c);
359
+ return m.success ? (n.value = void 0, r.value = B.valid, u.value = m.data, a("update:modelValue", u.value), (k = t == null ? void 0 : t.onUpdate) == null || k.call(t, S(u.value)), a("valid", m.data), (y = t == null ? void 0 : t.onValid) == null || y.call(t, S(u.value)), !0) : (n.value = m.error.format(), r.value = B.invalid, a("invalid", n.value), (w = t == null ? void 0 : t.onInvalid) == null || w.call(t, S(n.value)), !1);
360
+ }, h = () => {
361
+ var c;
362
+ return o() ? (a("submit", u.value), (c = t == null ? void 0 : t.onSubmit) == null || c.call(t, S(u.value)), !0) : !1;
363
+ }, b = g(() => r.value === B.invalid);
364
+ return M(l, {
365
+ formData: u,
366
+ submit: h,
367
+ validate: o,
368
+ errors: p(n),
369
+ status: p(r),
370
+ invalid: b
362
371
  }), {
363
- formData: r,
364
- submit: m,
365
- validate: t,
366
- errors: k(i),
367
- status: k(n),
368
- invalid: h
372
+ formData: u,
373
+ submit: h,
374
+ validate: o,
375
+ errors: p(n),
376
+ status: p(r),
377
+ invalid: b
369
378
  };
370
379
  },
371
380
  render() {
381
+ const s = () => {
382
+ var a, o;
383
+ return ((o = (a = this.$slots) == null ? void 0 : a.default) == null ? void 0 : o.call(a, {
384
+ formData: this.formData,
385
+ submit: this.submit,
386
+ validate: this.validate,
387
+ errors: this.errors,
388
+ status: this.status,
389
+ invalid: this.invalid
390
+ })) ?? this.$slots.default;
391
+ };
372
392
  return x(
373
393
  "form",
374
394
  {
375
- onSubmit: ee(this.submit, ["prevent"])
395
+ onSubmit: re(this.submit, ["prevent"])
376
396
  },
377
- {
378
- default: () => {
379
- var a, u;
380
- return ((u = (a = this.$slots) == null ? void 0 : a.default) == null ? void 0 : u.call(a, {
381
- formData: this.formData,
382
- submit: this.submit,
383
- validate: this.validate,
384
- errors: this.errors,
385
- status: this.status,
386
- invalid: this.invalid
387
- })) ?? this.$slots.default;
388
- }
397
+ (this.template ?? (t == null ? void 0 : t.template)) && f ? [
398
+ x(
399
+ f,
400
+ {
401
+ schema: this.template ?? (t == null ? void 0 : t.template)
402
+ },
403
+ {
404
+ default: s
405
+ }
406
+ )
407
+ ] : {
408
+ default: s
389
409
  }
390
410
  );
391
411
  }
392
412
  });
393
413
  return {
394
- errors: i,
395
- status: n,
396
- formData: r,
414
+ errors: n,
415
+ status: r,
416
+ formData: u,
397
417
  /**
398
418
  * An hack to add types to the default slot
399
419
  */
400
- VvForm: s
420
+ VvForm: i
401
421
  };
402
- }, me = (e, o) => G({
422
+ }, he = (e, l) => W({
403
423
  name: "WrapperComponent",
404
424
  props: {
405
425
  name: {
@@ -413,51 +433,51 @@ const de = (e, o, l, i) => G({
413
433
  },
414
434
  emits: ["invalid", "valid"],
415
435
  expose: ["fields", "invalid"],
416
- setup(i, { emit: n }) {
417
- const r = S(e), s = S(o, void 0), a = A(/* @__PURE__ */ new Set()), u = A(/* @__PURE__ */ new Map()), { name: t } = P(i);
418
- K(o, {
419
- name: k(t),
420
- errors: u,
421
- fields: a
422
- }), w(
423
- a,
436
+ setup(f, { emit: n }) {
437
+ const r = I(e), u = I(l, void 0), i = $(/* @__PURE__ */ new Set()), s = $(/* @__PURE__ */ new Map()), { name: a } = R(f);
438
+ M(l, {
439
+ name: p(a),
440
+ errors: s,
441
+ fields: i
442
+ }), E(
443
+ i,
424
444
  (h) => {
425
- s != null && s.fields && h.forEach((d) => {
426
- s == null || s.fields.value.add(d);
445
+ u != null && u.fields && h.forEach((b) => {
446
+ u == null || u.fields.value.add(b);
427
447
  });
428
448
  },
429
449
  { deep: !0 }
430
- ), w(
431
- () => new Map(u.value),
432
- (h, d) => {
433
- s != null && s.errors && (Array.from(d.keys()).forEach((c) => {
434
- s.errors.value.delete(c);
450
+ ), E(
451
+ () => new Map(s.value),
452
+ (h, b) => {
453
+ u != null && u.errors && (Array.from(b.keys()).forEach((c) => {
454
+ u.errors.value.delete(c);
435
455
  }), Array.from(h.keys()).forEach((c) => {
436
- const b = h.get(c);
437
- b && s.errors.value.set(c, b);
456
+ const m = h.get(c);
457
+ m && u.errors.value.set(c, m);
438
458
  }));
439
459
  },
440
460
  { deep: !0 }
441
461
  );
442
- const m = y(() => r != null && r.invalid.value ? u.value.size > 0 : !1);
443
- return w(m, () => {
444
- m.value ? n("invalid") : n("valid");
462
+ const o = g(() => r != null && r.invalid.value ? s.value.size > 0 : !1);
463
+ return E(o, () => {
464
+ o.value ? n("invalid") : n("valid");
445
465
  }), {
446
466
  formData: r == null ? void 0 : r.formData,
447
467
  errors: r == null ? void 0 : r.errors,
448
468
  submit: r == null ? void 0 : r.submit,
449
469
  validate: r == null ? void 0 : r.validate,
450
- invalid: m,
451
- fields: a,
452
- fieldsErrors: u
470
+ invalid: o,
471
+ fields: i,
472
+ fieldsErrors: s
453
473
  };
454
474
  },
455
475
  render() {
456
- var i, n;
476
+ var f, n;
457
477
  return this.tag ? x(this.tag, null, {
458
478
  default: () => {
459
- var r, s;
460
- return ((s = (r = this.$slots).default) == null ? void 0 : s.call(r, {
479
+ var r, u;
480
+ return ((u = (r = this.$slots).default) == null ? void 0 : u.call(r, {
461
481
  invalid: this.invalid,
462
482
  formData: this.formData,
463
483
  submit: this.submit,
@@ -466,7 +486,7 @@ const de = (e, o, l, i) => G({
466
486
  fieldsErrors: this.fieldsErrors
467
487
  })) ?? this.$slots.defalut;
468
488
  }
469
- }) : ((n = (i = this.$slots).default) == null ? void 0 : n.call(i, {
489
+ }) : ((n = (f = this.$slots).default) == null ? void 0 : n.call(f, {
470
490
  invalid: this.invalid,
471
491
  formData: this.formData,
472
492
  submit: this.submit,
@@ -475,76 +495,75 @@ const de = (e, o, l, i) => G({
475
495
  fieldsErrors: this.fieldsErrors
476
496
  })) ?? this.$slots.defalut;
477
497
  }
478
- }), he = (e, o) => {
479
- const l = G({
498
+ }), be = (e, l) => {
499
+ const t = W({
480
500
  props: {
481
501
  schema: {
482
502
  type: [Array, Function],
483
503
  required: !0
484
504
  }
485
505
  },
486
- setup(i, { slots: n }) {
487
- const r = S(e);
488
- if (!(r != null && r.formData))
489
- return;
490
- const s = typeof i.schema == "function" ? i.schema(r) : i.schema;
491
- let a;
492
- return () => {
493
- var u;
494
- return s.reduce(
495
- (t, m) => {
496
- const h = typeof m == "function" ? m(r) : m, {
497
- vvIs: d,
498
- vvName: c,
499
- vvSlots: b,
500
- vvChildren: E,
501
- vvIf: V,
502
- vvElseIf: p,
503
- vvType: C,
504
- vvDefaultValue: L,
505
- vvShowValid: J,
506
- ...f
507
- } = h;
508
- if (V !== void 0) {
509
- if (typeof V == "string" ? a = !!N(
506
+ setup(f, { slots: n }) {
507
+ const r = I(e);
508
+ if (r != null && r.formData)
509
+ return () => {
510
+ var a;
511
+ const u = typeof f.schema == "function" ? f.schema(r) : f.schema;
512
+ let i;
513
+ const s = u.reduce((o, h) => {
514
+ const b = typeof h == "function" ? h(r) : h, {
515
+ vvIs: c,
516
+ vvName: m,
517
+ vvSlots: w,
518
+ vvChildren: k,
519
+ vvIf: y,
520
+ vvElseIf: V,
521
+ vvType: z,
522
+ vvDefaultValue: q,
523
+ vvShowValid: d,
524
+ vvContent: A,
525
+ ...C
526
+ } = b;
527
+ if (y !== void 0) {
528
+ if (typeof y == "string" ? i = !!G(
510
529
  Object(r.formData.value),
511
- V
512
- ) : typeof V == "function" ? a = I(V(r)) : a = I(V), !a)
513
- return t;
514
- } else if (p !== void 0 && a !== void 0) {
515
- if (a || (typeof p == "string" ? a = !!N(
530
+ y
531
+ ) : typeof y == "function" ? i = _(y(r)) : i = _(y), !i)
532
+ return o;
533
+ } else if (V !== void 0 && i !== void 0) {
534
+ if (i || (typeof V == "string" ? i = !!G(
516
535
  Object(r.formData.value),
517
- p
518
- ) : typeof p == "function" ? a = I(p(r)) : a = I(p), !a))
519
- return t;
536
+ V
537
+ ) : typeof V == "function" ? i = _(V(r)) : i = _(V), !i))
538
+ return o;
520
539
  } else
521
- a = void 0;
522
- const O = E ? x(l, {
523
- schema: E
540
+ i = void 0;
541
+ const Z = k ? x(t, {
542
+ schema: k
524
543
  }) : void 0;
525
- return c ? (t.push(
544
+ return m ? (o.push(
526
545
  x(
527
- o,
546
+ l,
528
547
  {
529
- name: c,
530
- is: d,
531
- type: C,
532
- defaultValue: L,
533
- showValid: J,
534
- props: f
548
+ name: m,
549
+ is: c,
550
+ type: z,
551
+ defaultValue: q,
552
+ showValid: d,
553
+ props: C
535
554
  },
536
- b ?? O
555
+ w ?? Z ?? A
537
556
  )
538
- ), t) : d ? (t.push(
557
+ ), o) : c ? (o.push(
539
558
  x(
540
- d,
541
- f,
542
- b ?? O
559
+ c,
560
+ C,
561
+ w ?? Z ?? A
543
562
  )
544
- ), t) : (E && t.push(O), t);
545
- },
546
- [
547
- (u = n == null ? void 0 : n.default) == null ? void 0 : u.call(n, {
563
+ ), o) : (k && o.push(Z), o);
564
+ }, []);
565
+ return s.push(
566
+ (a = n == null ? void 0 : n.default) == null ? void 0 : a.call(n, {
548
567
  formData: r == null ? void 0 : r.formData.value,
549
568
  submit: r == null ? void 0 : r.submit,
550
569
  validate: r == null ? void 0 : r.validate,
@@ -552,55 +571,58 @@ const de = (e, o, l, i) => G({
552
571
  status: r == null ? void 0 : r.status.value,
553
572
  invalid: r == null ? void 0 : r.invalid.value
554
573
  })
555
- ]
556
- );
557
- };
574
+ ), s;
575
+ };
558
576
  }
559
577
  });
560
- return l;
561
- }, B = (e, o = {}) => {
562
- const l = Symbol(), i = Symbol(), n = Symbol(), { VvForm: r, errors: s, status: a, formData: u } = ce(
578
+ return t;
579
+ }, L = (e, l = {}) => {
580
+ const t = Symbol(), f = Symbol(), n = Symbol(), r = he(
581
+ t,
582
+ f
583
+ ), u = ce(
584
+ t,
585
+ f,
586
+ n,
587
+ l
588
+ ), i = be(t, u), { VvForm: s, errors: a, status: o, formData: h } = me(
563
589
  e,
564
- l,
565
- o
566
- ), t = me(
590
+ t,
567
591
  l,
568
592
  i
569
- ), m = de(
570
- l,
571
- i,
572
- n,
573
- o
574
- ), h = he(l, m);
593
+ );
575
594
  return {
576
- VvForm: r,
577
- VvFormWrapper: t,
578
- VvFormField: m,
579
- VvFormTemplate: h,
580
- formInjectionKey: l,
581
- formWrapperInjectionKey: i,
595
+ VvForm: s,
596
+ VvFormWrapper: r,
597
+ VvFormField: u,
598
+ VvFormTemplate: i,
599
+ formInjectionKey: t,
600
+ formWrapperInjectionKey: f,
582
601
  formFieldInjectionKey: n,
583
- errors: s,
584
- status: a,
585
- formData: u
602
+ errors: a,
603
+ status: o,
604
+ formData: h
586
605
  };
587
- }, X = Symbol(), Ve = (e) => {
588
- let o = {};
589
- return e.schema && (o = B(e.schema, e)), {
590
- ...o,
591
- install(l, { global: i = !1 } = {}) {
592
- l.provide(X, e), i && (l.config.globalProperties.$vvForm = e, o != null && o.VvForm && l.component("VvForm", o.VvForm), o != null && o.VvFormWrapper && l.component("VvFormWrapper", o.VvFormWrapper), o != null && o.VvFormField && l.component("VvFormField", o.VvFormField), o != null && o.VvFormTemplate && l.component("VvFormTemplate", o.VvFormTemplate));
606
+ }, Y = Symbol(), xe = (e) => {
607
+ let l = {};
608
+ return e.schema && (l = L(e.schema, e)), {
609
+ ...l,
610
+ install(t, { global: f = !1 } = {}) {
611
+ t.provide(Y, e), f && (t.config.globalProperties.$vvForm = e, l != null && l.VvForm && t.component("VvForm", l.VvForm), l != null && l.VvFormWrapper && t.component("VvFormWrapper", l.VvFormWrapper), l != null && l.VvFormField && t.component("VvFormField", l.VvFormField), l != null && l.VvFormTemplate && t.component("VvFormTemplate", l.VvFormTemplate));
593
612
  }
594
613
  };
595
- }, ge = (e, o = {}) => re() ? B(e, {
596
- ...S(X, {}),
597
- ...o
598
- }) : B(e, o), xe = (e, o = {}) => B(e, o);
614
+ }, ke = (e, l = {}) => te() ? L(
615
+ e,
616
+ {
617
+ ...I(Y, {}),
618
+ ...l
619
+ }
620
+ ) : L(e, l), Oe = (e, l = {}) => L(e, l);
599
621
  export {
600
622
  v as FormFieldType,
601
- Ve as createForm,
602
- Z as defaultObjectBySchema,
603
- xe as formFactory,
604
- X as pluginInjectionKey,
605
- ge as useForm
623
+ xe as createForm,
624
+ J as defaultObjectBySchema,
625
+ Oe as formFactory,
626
+ Y as pluginInjectionKey,
627
+ ke as useForm
606
628
  };