@volverjs/form-vue 0.0.9 → 0.0.10-beta.10

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