@volverjs/form-vue 1.0.0-beta.11 → 1.0.0-beta.13

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