@volverjs/form-vue 1.0.0-beta.1 → 1.0.0-beta.3

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