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

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;
22
+ const ve = /^[0-9]+$/, ce = ["__proto__", "prototype", "constructor"];
23
+ function L(e, l, t) {
24
+ const o = de(t) ? t : void 0;
25
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) {
26
+ return o;
27
+ const u = Y(l);
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 a = function(s) {
33
+ return s.map((f) => G(f) || q(f) ? f : R(f) ? a(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 = a(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) {
41
+ function X(e, l, t) {
42
42
  if (!H(e) || !Q(l))
43
43
  return;
44
- const f = X(l);
45
- if (f.length === 0)
44
+ const o = Y(l);
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 a = o[r];
50
+ if (r === u - 1) {
51
+ e[a] = 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 (a === "*" && R(e)) {
55
+ const s = o.slice(r + 1).join(".");
56
+ for (const f of e)
57
+ X(f, s, t);
58
58
  return;
59
59
  }
60
- N(e[u]) && (e[u] = {}), e = e[u];
60
+ G(e[a]) && (e[a] = {}), e = e[a];
61
61
  }
62
62
  }
63
- function X(e) {
63
+ function Y(e) {
64
64
  const l = e.split(/[.]|(?:\[(\d|\*)\])/).filter((t) => !!t);
65
- return l.some((t) => ve.indexOf(t) !== -1) ? [] : l;
65
+ return l.some((t) => ce.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 || {}), 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, l, 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: a }) {
104
+ const s = 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
+ ), a("update:modelValue", {
118
+ newValue: s.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
+ s.value === void 0 && u.defaultValue !== void 0 && (s.value = u.defaultValue);
125
125
  }), j(() => {
126
- O(), k();
126
+ y(), V();
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(l, void 0);
129
+ f && f.fields.value.add(u.name);
130
+ const n = U(e), { props: c, name: b } = P(u), m = k(() => {
131
+ if (n != null && n.errors.value)
132
+ return L(n.errors.value, String(u.name));
133
+ }), v = k(() => {
134
+ var i;
135
+ return (i = m.value) == null ? void 0 : i._errors;
136
+ }), h = k(() => m.value !== void 0), y = I(h, () => {
137
+ h.value ? (a("invalid", v.value), f && f.errors.value.set(
138
+ u.name,
139
139
  {
140
- _errors: c.value
140
+ _errors: v.value
141
141
  }
142
- )) : (u("valid", i.value), s && s.errors.value.delete(
143
- n.name
142
+ )) : (a("valid", s.value), f && f.errors.value.delete(
143
+ u.name
144
144
  ));
145
- }), k = A(
146
- () => a == null ? void 0 : a.formData,
145
+ }), V = I(
146
+ () => n == null ? void 0 : n.formData,
147
147
  () => {
148
- u("update:formData", a == null ? void 0 : a.formData);
148
+ a("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
+ s.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: h.value,
163
+ valid: u.showValid ? !!(!h.value && s.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: v.value,
183
+ modelValue: s.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(b),
188
+ errors: S(m)
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: s.value,
196
+ onUpdate: g,
197
+ submit: n == null ? void 0 : n.submit,
198
+ validate: n == null ? void 0 : n.validate,
199
+ invalid: h.value,
200
+ invalidLabel: v.value,
201
+ formData: n == null ? void 0 : n.formData.value,
202
+ formErrors: n == null ? void 0 : n.errors.value,
203
+ errors: m.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: h };
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
264
  }), J = (e, l = {}) => {
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 a = r;
267
+ for (; a instanceof fe; )
268
+ a = a.innerType();
269
+ return a instanceof oe && (a = a._def.innerType), a;
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) ? l : {},
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, a]) => {
276
+ const s = l[r];
277
+ let f = t(a), n;
278
+ if (f instanceof ue && (n = f._def.defaultValue(), f = f._def.innerType), s === null && f instanceof le)
279
+ return [r, s];
280
+ if (f instanceof se) {
281
+ const c = a.safeParse(s);
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(s) && s.length) {
286
+ const c = t(f._def.type);
287
+ if (c instanceof K)
288
288
  return [
289
289
  r,
290
- i.map(
291
- (h) => J(
292
- o,
293
- h && typeof h == "object" ? h : void 0
290
+ s.map(
291
+ (b) => J(
292
+ c,
293
+ b && typeof b == "object" ? b : 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
+ s && typeof s == "object" ? s : 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, l, t, o) => {
310
+ const u = C(), r = C(), a = C(), s = 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
+ }, f = async () => await s() ? (r.value = x.submitting, !0) : !1, { ignoreUpdates: n, stop: c } = 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
+ ), b = 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,118 @@ 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
+ 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
+ (y) => {
351
+ if (y) {
352
+ const V = ee(y) ? E(y) : y;
353
+ a.value = typeof (V == null ? void 0 : V.clone) == "function" ? V.clone() : JSON.parse(JSON.stringify(V));
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 (y) => {
358
+ var V, g, p, A, W;
359
+ if (y === x.invalid) {
360
+ const i = E(
361
+ u.value
362
+ );
363
+ v("invalid", i), (V = t == null ? void 0 : t.onInvalid) == null || V.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);
366
+ if (y === 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 (y === 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 (y === x.updated) {
376
+ if ((u.value || t != null && t.continuosValidation || m.continuosValidation) && await s(), !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
+ });
385
+ const h = k(() => r.value === x.invalid);
364
386
  return M(l, {
365
- formData: u,
366
- submit: h,
367
- validate: o,
368
- errors: p(n),
369
- status: p(r),
370
- invalid: y
387
+ formData: a,
388
+ submit: f,
389
+ validate: s,
390
+ ignoreUpdates: n,
391
+ stopUpdatesWatch: c,
392
+ errors: S(u),
393
+ status: S(r),
394
+ invalid: h
371
395
  }), {
372
- formData: u,
373
- submit: h,
374
- validate: o,
375
- errors: p(n),
376
- status: p(r),
377
- invalid: y
396
+ formData: a,
397
+ submit: f,
398
+ validate: s,
399
+ ignoreUpdates: n,
400
+ stopUpdatesWatch: c,
401
+ errors: S(u),
402
+ status: S(r),
403
+ invalid: h
378
404
  };
379
405
  },
380
406
  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, {
407
+ const m = () => {
408
+ var v, h;
409
+ return ((h = (v = this.$slots) == null ? void 0 : v.default) == null ? void 0 : h.call(v, {
384
410
  formData: this.formData,
385
411
  submit: this.submit,
386
412
  validate: this.validate,
413
+ ignoreUpdates: this.ignoreUpdates,
414
+ stopUpdatesWatch: this.stopUpdatesWatch,
387
415
  errors: this.errors,
388
416
  status: this.status,
389
417
  invalid: this.invalid
390
418
  })) ?? this.$slots.default;
391
419
  };
392
- return x(
393
- "form",
420
+ return w(
421
+ this.tag,
394
422
  {
395
423
  onSubmit: re(this.submit, ["prevent"])
396
424
  },
397
- (this.template ?? (t == null ? void 0 : t.template)) && f ? [
398
- x(
399
- f,
425
+ (this.template ?? (t == null ? void 0 : t.template)) && o ? [
426
+ w(
427
+ o,
400
428
  {
401
429
  schema: this.template ?? (t == null ? void 0 : t.template)
402
430
  },
403
431
  {
404
- default: s
432
+ default: m
405
433
  }
406
434
  )
407
435
  ] : {
408
- default: s
436
+ default: m
409
437
  }
410
438
  );
411
439
  }
412
440
  });
413
441
  return {
414
- errors: n,
442
+ errors: u,
415
443
  status: r,
416
- formData: u,
444
+ formData: a,
445
+ validate: s,
446
+ submit: f,
447
+ ignoreUpdates: n,
448
+ stopUpdatesWatch: c,
417
449
  /**
418
450
  * An hack to add types to the default slot
419
451
  */
420
- VvForm: i
452
+ VvForm: b
421
453
  };
422
- }, he = (e, l) => W({
423
- name: "WrapperComponent",
454
+ }, be = (e, l) => z({
455
+ name: "VvFormWrapper",
424
456
  props: {
425
457
  name: {
426
458
  type: String,
@@ -433,51 +465,51 @@ const ce = (e, l, t, f) => W({
433
465
  },
434
466
  emits: ["invalid", "valid"],
435
467
  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);
468
+ setup(o, { emit: u }) {
469
+ const r = U(e), a = U(l, void 0), s = C(/* @__PURE__ */ new Set()), f = C(/* @__PURE__ */ new Map()), { name: n } = P(o);
438
470
  M(l, {
439
- name: p(a),
440
- errors: s,
441
- fields: i
442
- }), A(
443
- i,
444
- (h) => {
445
- u != null && u.fields && h.forEach((y) => {
446
- u == null || u.fields.value.add(y);
471
+ name: S(n),
472
+ errors: f,
473
+ fields: s
474
+ }), I(
475
+ s,
476
+ (b) => {
477
+ a != null && a.fields && b.forEach((m) => {
478
+ a == null || a.fields.value.add(m);
447
479
  });
448
480
  },
449
481
  { 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);
482
+ ), I(
483
+ () => new Map(f.value),
484
+ (b, m) => {
485
+ a != null && a.errors && (Array.from(m.keys()).forEach((v) => {
486
+ a.errors.value.delete(v);
487
+ }), Array.from(b.keys()).forEach((v) => {
488
+ const h = b.get(v);
489
+ h && a.errors.value.set(v, h);
458
490
  }));
459
491
  },
460
492
  { deep: !0 }
461
493
  );
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");
494
+ const c = k(() => r != null && r.invalid.value ? f.value.size > 0 : !1);
495
+ return I(c, () => {
496
+ c.value ? u("invalid") : u("valid");
465
497
  }), {
466
498
  formData: r == null ? void 0 : r.formData,
467
499
  errors: r == null ? void 0 : r.errors,
468
500
  submit: r == null ? void 0 : r.submit,
469
501
  validate: r == null ? void 0 : r.validate,
470
- invalid: o,
471
- fields: i,
472
- fieldsErrors: s
502
+ invalid: c,
503
+ fields: s,
504
+ fieldsErrors: f
473
505
  };
474
506
  },
475
507
  render() {
476
- var f, n;
477
- return this.tag ? x(this.tag, null, {
508
+ var o, u;
509
+ return this.tag ? w(this.tag, null, {
478
510
  default: () => {
479
- var r, u;
480
- return ((u = (r = this.$slots).default) == null ? void 0 : u.call(r, {
511
+ var r, a;
512
+ return ((a = (r = this.$slots).default) == null ? void 0 : a.call(r, {
481
513
  invalid: this.invalid,
482
514
  formData: this.formData,
483
515
  submit: this.submit,
@@ -486,7 +518,7 @@ const ce = (e, l, t, f) => W({
486
518
  fieldsErrors: this.fieldsErrors
487
519
  })) ?? this.$slots.defalut;
488
520
  }
489
- }) : ((n = (f = this.$slots).default) == null ? void 0 : n.call(f, {
521
+ }) : ((u = (o = this.$slots).default) == null ? void 0 : u.call(o, {
490
522
  invalid: this.invalid,
491
523
  formData: this.formData,
492
524
  submit: this.submit,
@@ -496,74 +528,75 @@ const ce = (e, l, t, f) => W({
496
528
  })) ?? this.$slots.defalut;
497
529
  }
498
530
  }), ye = (e, l) => {
499
- const t = W({
531
+ const t = z({
532
+ name: "VvFormTemplate",
500
533
  props: {
501
534
  schema: {
502
535
  type: [Array, Function],
503
536
  required: !0
504
537
  }
505
538
  },
506
- setup(f, { slots: n }) {
507
- const r = E(e);
539
+ setup(o, { slots: u }) {
540
+ const r = U(e);
508
541
  if (r != null && r.formData)
509
542
  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(
543
+ var n;
544
+ const a = typeof o.schema == "function" ? o.schema(r) : o.schema;
545
+ let s;
546
+ const f = a.reduce((c, b) => {
547
+ const m = typeof b == "function" ? b(r) : b, {
548
+ vvIs: v,
549
+ vvName: h,
550
+ vvSlots: y,
551
+ vvChildren: V,
552
+ vvIf: g,
553
+ vvElseIf: p,
554
+ vvType: A,
555
+ vvDefaultValue: W,
556
+ vvShowValid: i,
557
+ vvContent: _,
558
+ ...$
559
+ } = m;
560
+ if (g !== void 0) {
561
+ if (typeof g == "string" ? s = !!L(
529
562
  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(
563
+ g
564
+ ) : typeof g == "function" ? s = B(g(r)) : s = B(g), !s)
565
+ return c;
566
+ } else if (p !== void 0 && s !== void 0) {
567
+ if (s || (typeof p == "string" ? s = !!L(
535
568
  Object(r.formData.value),
536
- V
537
- ) : typeof V == "function" ? i = _(V(r)) : i = _(V), !i))
538
- return o;
569
+ p
570
+ ) : typeof p == "function" ? s = B(p(r)) : s = B(p), !s))
571
+ return c;
539
572
  } else
540
- i = void 0;
541
- const Z = k ? x(t, {
542
- schema: k
573
+ s = void 0;
574
+ const Z = V ? w(t, {
575
+ schema: V
543
576
  }) : void 0;
544
- return m ? (o.push(
545
- x(
577
+ return h ? (c.push(
578
+ w(
546
579
  l,
547
580
  {
548
- name: m,
549
- is: c,
550
- type: z,
551
- defaultValue: q,
552
- showValid: d,
553
- props: C
581
+ name: h,
582
+ is: v,
583
+ type: A,
584
+ defaultValue: W,
585
+ showValid: i,
586
+ props: $
554
587
  },
555
- O ?? Z ?? I
588
+ y ?? Z ?? _
556
589
  )
557
- ), o) : c ? (o.push(
558
- x(
559
- c,
560
- C,
561
- O ?? Z ?? I
590
+ ), c) : v ? (c.push(
591
+ w(
592
+ v,
593
+ $,
594
+ y ?? Z ?? _
562
595
  )
563
- ), o) : (k && o.push(Z), o);
596
+ ), c) : (V && c.push(Z), c);
564
597
  }, []);
565
- return s.push(
566
- (a = n == null ? void 0 : n.default) == null ? void 0 : a.call(n, {
598
+ return f.push(
599
+ (n = u == null ? void 0 : u.default) == null ? void 0 : n.call(u, {
567
600
  formData: r == null ? void 0 : r.formData.value,
568
601
  submit: r == null ? void 0 : r.submit,
569
602
  validate: r == null ? void 0 : r.validate,
@@ -571,58 +604,66 @@ const ce = (e, l, t, f) => W({
571
604
  status: r == null ? void 0 : r.status.value,
572
605
  invalid: r == null ? void 0 : r.invalid.value
573
606
  })
574
- ), s;
607
+ ), f;
575
608
  };
576
609
  }
577
610
  });
578
611
  return t;
579
- }, L = (e, l = {}) => {
580
- const t = Symbol(), f = Symbol(), n = Symbol(), r = he(
612
+ }, N = (e, l = {}) => {
613
+ const t = Symbol(), o = Symbol(), u = Symbol(), r = be(
581
614
  t,
582
- f
583
- ), u = ce(
615
+ o
616
+ ), a = me(
584
617
  t,
585
- f,
586
- n,
618
+ o,
619
+ u,
587
620
  l
588
- ), i = ye(t, u), { VvForm: s, errors: a, status: o, formData: h } = me(
589
- e,
590
- t,
591
- l,
592
- i
593
- );
621
+ ), s = ye(t, a), {
622
+ VvForm: f,
623
+ errors: n,
624
+ status: c,
625
+ formData: b,
626
+ validate: m,
627
+ submit: v,
628
+ ignoreUpdates: h,
629
+ stopUpdatesWatch: y
630
+ } = he(e, t, l, s);
594
631
  return {
595
- VvForm: s,
632
+ VvForm: f,
596
633
  VvFormWrapper: r,
597
- VvFormField: u,
598
- VvFormTemplate: i,
634
+ VvFormField: a,
635
+ VvFormTemplate: s,
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
+ formData: b,
642
+ validate: m,
643
+ submit: v,
644
+ ignoreUpdates: h,
645
+ stopUpdatesWatch: y
605
646
  };
606
- }, Y = Symbol(), xe = (e) => {
647
+ }, T = Symbol(), xe = (e) => {
607
648
  let l = {};
608
- return e.schema && (l = L(e.schema, e)), {
649
+ return e.schema && (l = N(e.schema, e)), {
609
650
  ...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));
651
+ install(t, { global: o = !1 } = {}) {
652
+ t.provide(T, e), o && (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));
612
653
  }
613
654
  };
614
- }, ke = (e, l = {}) => te() ? L(
655
+ }, ke = (e, l = {}) => te() ? N(
615
656
  e,
616
657
  {
617
- ...E(Y, {}),
658
+ ...U(T, {}),
618
659
  ...l
619
660
  }
620
- ) : L(e, l), we = (e, l = {}) => L(e, l);
661
+ ) : N(e, l), we = (e, l = {}) => N(e, l);
621
662
  export {
622
- v as FormFieldType,
663
+ d as FormFieldType,
623
664
  xe as createForm,
624
665
  J as defaultObjectBySchema,
625
666
  we as formFactory,
626
- Y as pluginInjectionKey,
667
+ T as pluginInjectionKey,
627
668
  ke as useForm
628
669
  };