@volverjs/form-vue 0.0.10-beta.4 → 0.0.10-beta.6

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