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