@volverjs/form-vue 1.0.0-beta.9 → 1.0.0

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,336 +1,105 @@
1
- import { defineComponent as z, computed as w, onMounted as P, onBeforeUnmount as j, inject as B, toRefs as H, watch as p, unref as C, provide as M, readonly as E, resolveComponent as S, defineAsyncComponent as F, h as O, ref as $, toRaw as A, 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 Z, ZodDefault as ue, ZodNullable as le, ZodSchema as se, ZodArray as ie, ZodEffects as fe, ZodOptional as oe } from "zod";
4
- function J(e) {
5
- return Array.isArray(e);
6
- }
7
- function de(e) {
8
- return typeof e < "u";
9
- }
10
- function q(e) {
11
- return e === null;
12
- }
13
- function Q(e) {
14
- return typeof e == "object";
15
- }
16
- function X(e) {
17
- return typeof e == "string";
18
- }
19
- function G(e) {
20
- return typeof e > "u";
21
- }
22
- const ve = /^[0-9]+$/, ce = ["__proto__", "prototype", "constructor"];
23
- function L(e, s, t) {
24
- const o = de(t) ? t : void 0;
25
- if (!Q(e) || !X(s))
26
- return o;
27
- const u = T(s);
28
- if (u.length !== 0) {
29
- for (const r of u) {
30
- if (r === "*")
31
- continue;
32
- const l = function(n) {
33
- return n.map((f) => G(f) || q(f) ? f : J(f) ? l(f) : f[r]);
34
- };
35
- if (J(e) && !ve.test(r) ? e = l(e) : e = e[r], G(e) || q(e))
36
- break;
37
- }
38
- return G(e) ? o : e;
39
- }
40
- }
41
- function Y(e, s, t) {
42
- if (!Q(e) || !X(s))
43
- return;
44
- const o = T(s);
45
- if (o.length === 0)
46
- return;
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
- return;
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);
58
- return;
59
- }
60
- G(e[l]) && (e[l] = {}), e = e[l];
61
- }
62
- }
63
- function T(e) {
64
- const s = e.split(/[.]|(?:\[(\d|\*)\])/).filter((t) => !!t);
65
- return s.some((t) => ce.indexOf(t) !== -1) ? [] : s;
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 me = (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
- },
84
- 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
- );
115
- },
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
- }));
125
- }
126
- });
127
- P(() => {
128
- n.value === void 0 && u.defaultValue !== void 0 && (n.value = u.defaultValue);
129
- }), j(() => {
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 } = H(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 = p(c, () => {
141
- c.value ? (l("invalid", V.value), f && f.errors.value.set(
142
- u.name,
143
- {
144
- _errors: V.value
145
- }
146
- )) : (l("valid", n.value), f && f.errors.value.delete(
147
- u.name
148
- ));
149
- }), m = p(
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
- (_, W) => (_[W] = C(i[W]), _),
161
- {}
162
- );
163
- }), I = w(() => a != null && a.readonly.value ? !0 : x.value.readonly ?? u.readonly), U = 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: E(b),
193
- errors: E(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;
211
- }
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.`
244
- );
245
- }
246
- return F(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");
262
- }
263
- return import("@volverjs/ui-vue/vv-input-text");
264
- });
265
- }), hasProps: U, invalid: c };
266
- },
267
- render() {
268
- return this.is ? O(this.is, this.hasProps, this.$slots) : this.type === d.custom ? O(this.component, null, this.$slots) : O(this.component, this.hasProps, this.$slots);
269
- }
270
- }), K = (e, s = {}) => {
271
- const t = (r) => {
272
- let l = r;
273
- for (; l instanceof fe; )
274
- l = l.innerType();
275
- return l instanceof oe && (l = l._def.innerType), l;
276
- }, o = t(e);
1
+ import { ref as L, computed as O, readonly as G, defineComponent as C, h as F, withModifiers as te, toRaw as B, watch as A, isProxy as ve, onMounted as q, provide as T, toRefs as Q, useId as oe, inject as U, onBeforeUnmount as P, unref as _, resolveComponent as W, defineAsyncComponent as ce, getCurrentInstance as me } from "vue";
2
+ import { watchIgnorable as pe, throttleFilter as ye } from "@vueuse/core";
3
+ import { ZodObject as K, ZodDefault as he, ZodNullable as be, ZodSchema as ge, ZodArray as Ve, ZodRecord as we, ZodEffects as re, ZodOptional as ae, ZodError as De } from "zod";
4
+ var w = /* @__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))(w || {}), x = /* @__PURE__ */ ((e) => (e.invalid = "invalid", e.valid = "valid", e.submitting = "submitting", e.reset = "reset", e.updated = "updated", e.unknown = "unknown", e))(x || {});
5
+ function Z(e, i = {}) {
6
+ const a = (u) => {
7
+ let o = u;
8
+ for (; o instanceof re; )
9
+ o = o.innerType();
10
+ return o instanceof ae && (o = o._def.innerType), o;
11
+ }, v = (u) => {
12
+ let o = u;
13
+ for (; o instanceof re; )
14
+ o = o.innerType();
15
+ return o instanceof ae;
16
+ }, n = a(e);
277
17
  return {
278
- ...(o instanceof Z ? o._def.unknownKeys === "passthrough" : !1) ? s : {},
18
+ ...(n instanceof K ? n._def.unknownKeys === "passthrough" : !1) ? i : {},
279
19
  ...Object.fromEntries(
280
- Object.entries(o.shape).map(
281
- ([r, l]) => {
282
- const n = s[r];
283
- let f = t(l), a;
284
- if (f instanceof ue && (a = f._def.defaultValue(), f = f._def.innerType), n === null && f instanceof le)
285
- return [r, n];
286
- if (f instanceof se) {
287
- const v = l.safeParse(n);
288
- if (v.success)
289
- return [r, v.data ?? a];
20
+ Object.entries(n.shape).map(
21
+ ([u, o]) => {
22
+ const r = i[u], p = v(o);
23
+ let d = a(o), c;
24
+ if (d instanceof he && (c = d._def.defaultValue(), d = d._def.innerType), r === null && d instanceof be)
25
+ return [u, r];
26
+ if (r == null && p)
27
+ return [u, c];
28
+ if (d instanceof ge) {
29
+ const m = o.safeParse(r);
30
+ if (m.success)
31
+ return [u, m.data ?? c];
290
32
  }
291
- if (f instanceof ie && Array.isArray(n) && n.length) {
292
- const v = t(f._def.type);
293
- if (v instanceof Z)
33
+ if (d instanceof Ve && Array.isArray(r) && r.length) {
34
+ const m = a(d._def.type);
35
+ if (m instanceof K)
294
36
  return [
295
- r,
296
- n.map(
297
- (b) => K(
298
- v,
299
- b && typeof b == "object" ? b : void 0
37
+ u,
38
+ r.map(
39
+ (j) => Z(
40
+ m,
41
+ j && typeof j == "object" ? j : void 0
300
42
  )
301
- ) ?? a
43
+ )
302
44
  ];
303
45
  }
304
- return f instanceof Z ? [
305
- r,
306
- K(
307
- f,
308
- n && typeof n == "object" ? n : a
46
+ if (d instanceof we && r) {
47
+ const m = a(d._def.valueType);
48
+ if (m instanceof K)
49
+ return [u, Object.keys(r).reduce((j, y) => (j[y] = Z(m, r[y]), j), {})];
50
+ }
51
+ return d instanceof K ? [
52
+ u,
53
+ Z(
54
+ d,
55
+ r && typeof r == "object" ? r : c
309
56
  )
310
- ] : [r, a];
57
+ ] : [u, c];
311
58
  }
312
59
  )
313
60
  )
314
61
  };
315
- }, he = (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)
62
+ }
63
+ function je(e, i, a, v, n) {
64
+ const l = L(), u = L(), o = O(() => u.value === x.invalid), r = L(), p = L(!1);
65
+ let d;
66
+ const c = (D) => {
67
+ const S = Z(e, D);
68
+ if (a?.class) {
69
+ const t = a.class;
70
+ return new t(S);
71
+ }
72
+ return S;
73
+ }, m = async (D = r.value, S) => {
74
+ if (d = S?.fields, p.value)
318
75
  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 } = ae(
322
- n,
76
+ const t = S?.superRefine ? await e.superRefine(S.superRefine).safeParseAsync(D) : await e.safeParseAsync(D);
77
+ if (!t.success) {
78
+ if (u.value = x.invalid, !d?.size)
79
+ return l.value = t.error.format(), !1;
80
+ const V = t.error.issues.filter(
81
+ ($) => d?.has($.path.join("."))
82
+ );
83
+ return V.length ? (l.value = new De(V).format(), !1) : (l.value = void 0, !0);
84
+ }
85
+ return l.value = void 0, u.value = x.valid, r.value = c(t.data), !0;
86
+ }, j = () => {
87
+ l.value = void 0, u.value = void 0, d = void 0;
88
+ }, y = () => {
89
+ r.value = c(), j(), u.value = x.reset;
90
+ }, f = async (D) => p.value || !await m(void 0, D) ? !1 : (u.value = x.submitting, !0), { ignoreUpdates: b, stop: g } = pe(
91
+ r,
323
92
  () => {
324
- r.value = k.updated;
93
+ u.value = x.updated;
325
94
  },
326
95
  {
327
96
  deep: !0,
328
- eventFilter: ne((t == null ? void 0 : t.updateThrottle) ?? 500)
97
+ eventFilter: ye(a?.updateThrottle ?? 500)
329
98
  }
330
- ), V = z({
99
+ ), I = G(l), R = G(u), k = C({
331
100
  name: "VvForm",
332
101
  props: {
333
- continuosValidation: {
102
+ continuousValidation: {
334
103
  type: Boolean,
335
104
  default: !1
336
105
  },
@@ -340,7 +109,7 @@ const me = (e, s, t, o) => z({
340
109
  },
341
110
  readonly: {
342
111
  type: Boolean,
343
- default: (t == null ? void 0 : t.readonly) ?? !1
112
+ default: a?.readonly ?? !1
344
113
  },
345
114
  tag: {
346
115
  type: String,
@@ -349,365 +118,947 @@ const me = (e, s, t, o) => z({
349
118
  template: {
350
119
  type: [Array, Function],
351
120
  default: void 0
121
+ },
122
+ superRefine: {
123
+ type: Function,
124
+ default: void 0
125
+ },
126
+ validateFields: {
127
+ type: Array,
128
+ default: void 0
352
129
  }
353
130
  },
354
131
  emits: [
355
132
  "invalid",
356
- "valid",
357
133
  "submit",
358
134
  "update:modelValue",
359
- "update:readonly"
135
+ "update:readonly",
136
+ "valid",
137
+ "reset"
360
138
  ],
361
139
  expose: [
362
- "submit",
363
- "validate",
364
140
  "errors",
141
+ "invalid",
142
+ "readonly",
365
143
  "status",
144
+ "submit",
145
+ "tag",
146
+ "template",
366
147
  "valid",
367
- "invalid",
368
- "readonly"
148
+ "validate",
149
+ "clear",
150
+ "reset"
369
151
  ],
370
- setup(c, { emit: h }) {
371
- return n.value = K(
372
- e,
373
- A(c.modelValue)
374
- ), p(
375
- () => c.modelValue,
376
- (m) => {
377
- if (m) {
378
- const y = ee(m) ? A(m) : m;
379
- if (JSON.stringify(y) === JSON.stringify(A(n.value)))
152
+ slots: Object,
153
+ setup(D, { emit: S }) {
154
+ return r.value = c(B(D.modelValue)), A(
155
+ () => D.modelValue,
156
+ (t) => {
157
+ if (t) {
158
+ const V = ve(t) ? B(t) : t;
159
+ if (JSON.stringify(V) === JSON.stringify(B(r.value)))
380
160
  return;
381
- n.value = typeof (y == null ? void 0 : y.clone) == "function" ? y.clone() : JSON.parse(JSON.stringify(y));
161
+ r.value = typeof V?.clone == "function" ? V.clone() : JSON.parse(JSON.stringify(V));
382
162
  }
383
163
  },
384
164
  { deep: !0 }
385
- ), p(r, async (m) => {
386
- var y, x, I, U, N;
387
- if (m === k.invalid) {
388
- const i = A(
389
- u.value
165
+ ), A(u, async (t) => {
166
+ if (t === x.invalid) {
167
+ const V = B(l.value);
168
+ S("invalid", V), a?.onInvalid?.(
169
+ V
390
170
  );
391
- h("invalid", i), (y = t == null ? void 0 : t.onInvalid) == null || y.call(t, i);
392
171
  return;
393
172
  }
394
- if (m === k.valid) {
395
- const i = A(n.value);
396
- 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);
173
+ if (t === x.valid) {
174
+ const V = B(r.value);
175
+ S("valid", V), a?.onValid?.(V), S("update:modelValue", V), a?.onUpdate?.(V);
397
176
  return;
398
177
  }
399
- if (m === k.submitting) {
400
- const i = A(n.value);
401
- h("submit", i), (U = t == null ? void 0 : t.onSubmit) == null || U.call(t, i);
178
+ if (t === x.submitting) {
179
+ const V = B(r.value);
180
+ S("submit", V), a?.onSubmit?.(V);
181
+ return;
402
182
  }
403
- if (m === k.updated) {
404
- if ((u.value || t != null && t.continuosValidation || c.continuosValidation) && await a(), !n.value || !c.modelValue || JSON.stringify(n.value) !== JSON.stringify(c.modelValue)) {
405
- const i = A(
406
- n.value
407
- );
408
- h("update:modelValue", i), (N = t == null ? void 0 : t.onUpdate) == null || N.call(t, i);
183
+ if (t === x.reset) {
184
+ const V = B(r.value);
185
+ S("reset", V), a?.onReset?.(V);
186
+ return;
187
+ }
188
+ if (t === x.updated) {
189
+ if ((l.value || a?.continuousValidation || D.continuousValidation) && await m(void 0, {
190
+ superRefine: D.superRefine,
191
+ fields: d ?? new Set(D.validateFields)
192
+ }), !r.value || !D.modelValue || JSON.stringify(r.value) !== JSON.stringify(D.modelValue)) {
193
+ const V = B(r.value);
194
+ S("update:modelValue", V), a?.onUpdate?.(V);
409
195
  }
410
- r.value === k.updated && (r.value = k.unknown);
196
+ u.value === x.updated && (u.value = x.unknown);
411
197
  }
412
- }), P(() => {
413
- f.value = c.readonly;
414
- }), p(
415
- () => c.readonly,
416
- (m) => {
417
- f.value = m;
198
+ }), q(() => {
199
+ p.value = D.readonly;
200
+ }), A(
201
+ () => D.readonly,
202
+ (t) => {
203
+ p.value = t;
418
204
  }
419
- ), p(f, (m) => {
420
- m !== c.readonly && h("update:readonly", f.value);
421
- }), M(s, {
422
- formData: n,
423
- submit: v,
424
- validate: a,
205
+ ), A(p, (t) => {
206
+ t !== D.readonly && S("update:readonly", p.value);
207
+ }), T(i, {
208
+ clear: j,
209
+ errors: I,
210
+ formData: r,
425
211
  ignoreUpdates: b,
212
+ invalid: o,
213
+ readonly: p,
214
+ reset: y,
215
+ status: R,
426
216
  stopUpdatesWatch: g,
427
- errors: E(u),
428
- status: E(r),
429
- invalid: l,
430
- readonly: f
217
+ submit: f,
218
+ validate: m,
219
+ wrappers: n
431
220
  }), {
432
- formData: n,
433
- submit: v,
434
- validate: a,
221
+ clear: j,
222
+ errors: I,
223
+ formData: r,
435
224
  ignoreUpdates: b,
225
+ invalid: o,
226
+ isReadonly: p,
227
+ reset: y,
228
+ status: R,
436
229
  stopUpdatesWatch: g,
437
- errors: E(u),
438
- status: E(r),
439
- invalid: l,
440
- isReadonly: f
230
+ submit: () => f({
231
+ superRefine: D.superRefine,
232
+ fields: new Set(D.validateFields)
233
+ }),
234
+ validate: m,
235
+ wrappers: n
441
236
  };
442
237
  },
443
238
  render() {
444
- const c = () => {
445
- var h, m;
446
- return ((m = (h = this.$slots) == null ? void 0 : h.default) == null ? void 0 : m.call(h, {
447
- formData: this.formData,
448
- submit: this.submit,
449
- validate: this.validate,
450
- ignoreUpdates: this.ignoreUpdates,
451
- stopUpdatesWatch: this.stopUpdatesWatch,
452
- errors: this.errors,
453
- status: this.status,
454
- invalid: this.invalid,
455
- readonly: this.isReadonly
456
- })) ?? this.$slots.default;
457
- };
458
- return O(
239
+ const D = () => this.$slots?.default?.({
240
+ errors: I.value,
241
+ formData: r.value,
242
+ invalid: o.value,
243
+ readonly: p.value,
244
+ status: R.value,
245
+ wrappers: n,
246
+ clear: j,
247
+ ignoreUpdates: b,
248
+ reset: y,
249
+ stopUpdatesWatch: g,
250
+ submit: f,
251
+ validate: m
252
+ }) ?? this.$slots.default;
253
+ return F(
459
254
  this.tag,
460
255
  {
461
- onSubmit: re(this.submit, ["prevent"])
256
+ onSubmit: te(this.submit, ["prevent"]),
257
+ onReset: te(this.reset, ["prevent"])
462
258
  },
463
- (this.template ?? (t == null ? void 0 : t.template)) && o ? [
464
- O(
465
- o,
259
+ (this.template ?? a?.template) && v ? [
260
+ F(
261
+ v,
466
262
  {
467
- schema: this.template ?? (t == null ? void 0 : t.template)
263
+ schema: this.template ?? a?.template
468
264
  },
469
265
  {
470
- default: c
266
+ default: D
471
267
  }
472
268
  )
473
269
  ] : {
474
- default: c
270
+ default: D
475
271
  }
476
272
  );
477
273
  }
478
274
  });
479
275
  return {
480
- errors: u,
481
- status: r,
482
- invalid: l,
483
- readonly: f,
484
- formData: n,
485
- validate: a,
486
- submit: v,
276
+ clear: j,
277
+ errors: l,
278
+ formData: r,
487
279
  ignoreUpdates: b,
280
+ invalid: o,
281
+ readonly: p,
282
+ reset: y,
283
+ status: u,
284
+ wrappers: n,
488
285
  stopUpdatesWatch: g,
489
- /**
490
- * An hack to add types to the default slot
491
- */
492
- VvForm: V
286
+ submit: f,
287
+ validate: m,
288
+ VvForm: k
493
289
  };
494
- }, ye = (e, s) => z({
495
- name: "VvFormWrapper",
496
- props: {
497
- name: {
498
- type: String,
499
- required: !0
290
+ }
291
+ function H(e) {
292
+ return Array.isArray(e);
293
+ }
294
+ function Oe(e) {
295
+ return !1;
296
+ }
297
+ function ne(e) {
298
+ return e === null;
299
+ }
300
+ function le(e) {
301
+ return typeof e == "object";
302
+ }
303
+ function ue(e) {
304
+ return typeof e == "string";
305
+ }
306
+ function z(e) {
307
+ return typeof e > "u";
308
+ }
309
+ const Se = /^[0-9]+$/, Re = ["__proto__", "prototype", "constructor"];
310
+ function N(e, i, a) {
311
+ const v = Oe() ? a : void 0;
312
+ if (!le(e) || !ue(i))
313
+ return v;
314
+ const n = ie(i);
315
+ if (n.length !== 0) {
316
+ for (const l of n) {
317
+ if (l === "*")
318
+ continue;
319
+ const u = function(o) {
320
+ return o.map((r) => z(r) || ne(r) ? r : H(r) ? u(r) : r[l]);
321
+ };
322
+ if (H(e) && !Se.test(l) ? e = u(e) : e = e[l], z(e) || ne(e))
323
+ break;
324
+ }
325
+ return z(e) ? v : e;
326
+ }
327
+ }
328
+ function X(e, i, a) {
329
+ if (!le(e) || !ue(i))
330
+ return;
331
+ const v = ie(i);
332
+ if (v.length === 0)
333
+ return;
334
+ const n = v.length;
335
+ for (let l = 0; l < n; l++) {
336
+ const u = v[l];
337
+ if (l === n - 1) {
338
+ e[u] = a;
339
+ return;
340
+ }
341
+ if (u === "*" && H(e)) {
342
+ const o = v.slice(l + 1).join(".");
343
+ for (const r of e)
344
+ X(r, o, a);
345
+ return;
346
+ }
347
+ z(e[u]) && (e[u] = {}), e = e[u];
348
+ }
349
+ }
350
+ function ie(e) {
351
+ const i = e.split(/[.]|(?:\[(\d|\*)\])/).filter((a) => !!a);
352
+ return i.some((a) => Re.indexOf(a) !== -1) ? [] : i;
353
+ }
354
+ function xe(e, i, a, v) {
355
+ return C({
356
+ name: "VvFormField",
357
+ props: {
358
+ type: {
359
+ type: String,
360
+ validator: (n) => Object.values(w).includes(n),
361
+ default: w.custom
362
+ },
363
+ is: {
364
+ type: [Object, String],
365
+ default: void 0
366
+ },
367
+ name: {
368
+ type: [String, Number, Boolean, Symbol],
369
+ required: !0
370
+ },
371
+ props: {
372
+ type: [Object, Function],
373
+ default: () => ({})
374
+ },
375
+ showValid: {
376
+ type: Boolean,
377
+ default: !1
378
+ },
379
+ defaultValue: {
380
+ type: [String, Number, Boolean, Array, Object],
381
+ default: void 0
382
+ },
383
+ lazyLoad: {
384
+ type: Boolean,
385
+ default: !1
386
+ },
387
+ readonly: {
388
+ type: Boolean,
389
+ default: void 0
390
+ }
391
+ },
392
+ emits: [
393
+ "invalid",
394
+ "update:formData",
395
+ "update:modelValue",
396
+ "valid"
397
+ ],
398
+ expose: [
399
+ "component",
400
+ "errors",
401
+ "hasProps",
402
+ "invalid",
403
+ "invalidLabel",
404
+ "is",
405
+ "type"
406
+ ],
407
+ slots: Object,
408
+ setup(n, { slots: l, emit: u }) {
409
+ const { props: o, name: r } = Q(n), p = oe(), d = U(i, void 0);
410
+ d && d.fields.value.set(p, n.name);
411
+ const c = U(e), m = O({
412
+ get() {
413
+ if (c?.formData)
414
+ return N(
415
+ new Object(c.formData.value),
416
+ String(n.name)
417
+ );
418
+ },
419
+ set(t) {
420
+ c?.formData && (X(
421
+ new Object(c.formData.value),
422
+ String(n.name),
423
+ t
424
+ ), u("update:modelValue", {
425
+ newValue: m.value,
426
+ formData: c?.formData
427
+ }));
428
+ }
429
+ });
430
+ q(() => {
431
+ m.value === void 0 && n.defaultValue !== void 0 && (m.value = n.defaultValue);
432
+ }), P(() => {
433
+ d && d.fields.value.delete(p);
434
+ });
435
+ const j = O(() => {
436
+ if (c?.errors.value)
437
+ return N(c.errors.value, String(n.name));
438
+ }), y = O(() => j.value?._errors), f = O(() => j.value !== void 0), b = A(f, (t) => {
439
+ if (t) {
440
+ u("invalid", j.value), d && d.errors.value.set(
441
+ String(n.name),
442
+ j.value
443
+ );
444
+ return;
445
+ }
446
+ u("valid", m.value), d && d.errors.value.delete(
447
+ n.name
448
+ );
449
+ }), g = A(
450
+ () => c?.formData,
451
+ () => {
452
+ u("update:formData", c?.formData);
453
+ },
454
+ { deep: !0 }
455
+ );
456
+ P(() => {
457
+ b(), g();
458
+ });
459
+ const I = (t) => {
460
+ t instanceof InputEvent && (t = t.target.value), m.value = t;
461
+ }, R = O(() => {
462
+ let t = o.value;
463
+ return typeof t == "function" && (t = t(c?.formData)), Object.keys(t).reduce(
464
+ (V, $) => (V[$] = _(t[$]), V),
465
+ {}
466
+ );
467
+ }), k = O(() => c?.readonly.value || d?.readonly.value ? !0 : R.value.readonly ?? n.readonly), D = O(() => ({
468
+ ...R.value,
469
+ name: R.value.name ?? n.name,
470
+ invalid: f.value,
471
+ valid: n.showValid ? !!(!f.value && m.value) : void 0,
472
+ type: ((t) => {
473
+ if ([
474
+ w.color,
475
+ w.date,
476
+ w.datetimeLocal,
477
+ w.email,
478
+ w.month,
479
+ w.number,
480
+ w.password,
481
+ w.search,
482
+ w.tel,
483
+ w.text,
484
+ w.time,
485
+ w.url,
486
+ w.week
487
+ ].includes(t))
488
+ return t;
489
+ })(n.type),
490
+ invalidLabel: y.value,
491
+ modelValue: m.value,
492
+ readonly: k.value,
493
+ "onUpdate:modelValue": I
494
+ }));
495
+ return T(a, {
496
+ name: G(r),
497
+ errors: G(j)
498
+ }), { component: O(() => {
499
+ if (n.type === w.custom)
500
+ return {
501
+ render() {
502
+ return l.default?.({
503
+ errors: j.value,
504
+ formData: c?.formData.value,
505
+ formErrors: c?.errors.value,
506
+ invalid: f.value,
507
+ invalidLabel: y.value,
508
+ modelValue: m.value,
509
+ readonly: k.value,
510
+ onUpdate: I,
511
+ submit: c?.submit,
512
+ validate: c?.validate
513
+ }) ?? l.default;
514
+ }
515
+ };
516
+ if (!(v?.lazyLoad ?? n.lazyLoad)) {
517
+ let t;
518
+ switch (n.type) {
519
+ case w.select:
520
+ t = W("VvSelect");
521
+ break;
522
+ case w.checkbox:
523
+ t = W("VvCheckbox");
524
+ break;
525
+ case w.radio:
526
+ t = W("VvRadio");
527
+ break;
528
+ case w.textarea:
529
+ t = W("VvTextarea");
530
+ break;
531
+ case w.radioGroup:
532
+ t = W("VvRadioGroup");
533
+ break;
534
+ case w.checkboxGroup:
535
+ t = W("VvCheckboxGroup");
536
+ break;
537
+ case w.combobox:
538
+ t = W("VvCombobox");
539
+ break;
540
+ default:
541
+ t = W("VvInputText");
542
+ }
543
+ if (typeof t != "string")
544
+ return t;
545
+ console.warn(
546
+ `[@volverjs/form-vue]: ${t} not found, the component will be loaded asynchronously. To avoid this warning, please set "lazyLoad" option.`
547
+ );
548
+ }
549
+ return ce(async () => {
550
+ switch (v?.sideEffects && await Promise.resolve(v.sideEffects(n.type)), n.type) {
551
+ case w.textarea:
552
+ return import("@volverjs/ui-vue/vv-textarea");
553
+ case w.radio:
554
+ return import("@volverjs/ui-vue/vv-radio");
555
+ case w.radioGroup:
556
+ return import("@volverjs/ui-vue/vv-radio-group");
557
+ case w.checkbox:
558
+ return import("@volverjs/ui-vue/vv-checkbox");
559
+ case w.checkboxGroup:
560
+ return import("@volverjs/ui-vue/vv-checkbox-group");
561
+ case w.select:
562
+ return import("@volverjs/ui-vue/vv-select");
563
+ case w.combobox:
564
+ return import("@volverjs/ui-vue/vv-combobox");
565
+ }
566
+ return import("@volverjs/ui-vue/vv-input-text");
567
+ });
568
+ }), hasProps: D, invalid: f };
500
569
  },
501
- tag: {
502
- type: String,
503
- default: void 0
570
+ render() {
571
+ return this.is ? F(this.is, this.hasProps, this.$slots) : this.type === w.custom ? F(this.component, null, this.$slots) : F(this.component, this.hasProps, this.$slots);
504
572
  }
505
- },
506
- emits: ["invalid", "valid"],
507
- expose: ["fields", "invalid"],
508
- setup(o, { emit: u }) {
509
- const r = B(e), l = B(s, void 0), n = $(/* @__PURE__ */ new Set()), f = $(/* @__PURE__ */ new Map()), { name: a } = H(o);
510
- M(s, {
511
- name: E(a),
512
- errors: f,
513
- fields: n
514
- }), p(
515
- n,
516
- (b) => {
517
- l != null && l.fields && b.forEach((g) => {
518
- l == null || l.fields.value.add(g);
573
+ });
574
+ }
575
+ function Ie(e, i, a) {
576
+ return C({
577
+ name: "VvFormFieldsGroup",
578
+ props: {
579
+ is: {
580
+ type: [Object, String],
581
+ default: void 0
582
+ },
583
+ names: {
584
+ type: [Array, Object],
585
+ required: !0
586
+ },
587
+ props: {
588
+ type: [Object, Function],
589
+ default: () => ({})
590
+ },
591
+ showValid: {
592
+ type: Boolean,
593
+ default: !1
594
+ },
595
+ defaultValues: {
596
+ type: [Object],
597
+ default: void 0
598
+ },
599
+ readonly: {
600
+ type: Boolean,
601
+ default: void 0
602
+ }
603
+ },
604
+ emits: [
605
+ "invalid",
606
+ "update:formData",
607
+ "update:modelValue",
608
+ "valid"
609
+ ],
610
+ expose: [
611
+ "component",
612
+ "errors",
613
+ "hasProps",
614
+ "invalid",
615
+ "invalidLabels",
616
+ "is"
617
+ ],
618
+ slots: Object,
619
+ setup(v, { slots: n, emit: l }) {
620
+ const { props: u, names: o, defaultValues: r } = Q(v), p = oe(), d = O(() => Array.isArray(o.value) ? o.value : Object.values(o.value)), c = O(() => Array.isArray(o.value) ? o.value : Object.keys(o.value)), m = O(() => Array.isArray(o.value) ? o.value.reduce((s, h) => (s[String(h)] = h, s), {}) : o.value), j = O(() => Object.keys(m.value).reduce((s, h) => (s[String(m.value[h])] = h, s), {})), y = U(i, void 0);
621
+ y && d.value.forEach((s) => {
622
+ y.fields.value.set(`${p}-${s}`, s);
623
+ });
624
+ const f = U(e), b = O({
625
+ get() {
626
+ return f?.formData ? c.value.reduce((s, h) => (s[h] = N(
627
+ new Object(f.formData.value),
628
+ m.value[h]
629
+ ), s), {}) : {};
630
+ },
631
+ set(s) {
632
+ f?.formData && (c.value.forEach((h) => {
633
+ X(
634
+ new Object(f.formData.value),
635
+ m.value[h],
636
+ s?.[h]
637
+ );
638
+ }), l("update:modelValue", {
639
+ newValue: b.value,
640
+ formData: f?.formData
641
+ }));
642
+ }
643
+ });
644
+ q(() => {
645
+ r.value && d.value.forEach((s) => {
646
+ r.value?.[s] !== void 0 && b.value[s] === void 0 && (b.value = {
647
+ ...b.value,
648
+ [s]: r.value?.[s]
649
+ });
650
+ });
651
+ }), P(() => {
652
+ y && d.value.forEach((s) => {
653
+ y.fields.value.delete(
654
+ `${p}-${s}`
655
+ );
519
656
  });
657
+ });
658
+ const g = O(() => {
659
+ if (!f?.errors.value)
660
+ return;
661
+ const s = d.value.reduce((h, E) => {
662
+ if (!f.errors.value)
663
+ return h;
664
+ const ee = N(f.errors.value, String(E));
665
+ return ee === void 0 || (h[String(E)] = ee), h;
666
+ }, {});
667
+ if (Object.keys(s).length !== 0)
668
+ return s;
669
+ }), I = O(() => {
670
+ if (!g.value)
671
+ return;
672
+ const s = Object.keys(g.value).reduce((h, E) => (g.value?.[E] && (h[j.value[E]] = g.value[E]._errors), h), {});
673
+ if (Object.keys(s).length !== 0)
674
+ return s;
675
+ }), R = O(() => g.value !== void 0), k = O(() => c.value.reduce((s, h) => (s[h] = !!g.value?.[j.value[h]], s), {})), D = A(R, () => {
676
+ if (R.value) {
677
+ l("invalid", g.value), y && d.value.forEach((s) => {
678
+ if (!g.value?.[s]) {
679
+ y.errors.value.delete(
680
+ s
681
+ );
682
+ return;
683
+ }
684
+ y.errors.value.set(
685
+ s,
686
+ g.value?.[s]
687
+ );
688
+ });
689
+ return;
690
+ }
691
+ l("valid", b.value), y && d.value.forEach((s) => {
692
+ y.errors.value.delete(
693
+ s
694
+ );
695
+ });
696
+ }), S = A(
697
+ () => f?.formData,
698
+ () => {
699
+ l("update:formData", f?.formData);
700
+ },
701
+ { deep: !0 }
702
+ );
703
+ P(() => {
704
+ D(), S();
705
+ });
706
+ const t = (s) => {
707
+ b.value = s;
708
+ }, V = (s, h) => {
709
+ h instanceof InputEvent && (h = h.target.value), c.value.includes(s) && (b.value = {
710
+ ...b.value,
711
+ [s]: h
712
+ });
713
+ }, $ = O(() => {
714
+ let s = u.value;
715
+ return typeof s == "function" && (s = s(f?.formData)), Object.keys(s).reduce(
716
+ (h, E) => (h[E] = _(s[E]), h),
717
+ {}
718
+ );
719
+ }), Y = O(() => f?.readonly.value ? !0 : $.value.readonly ?? v.readonly), de = O(() => c.value.reduce((s, h) => (s[`onUpdate:${h}`] = (E) => {
720
+ V(h, E);
721
+ }, s), {
722
+ "onUpdate:modelValue": t
723
+ })), fe = O(() => ({
724
+ ...de.value,
725
+ ...$.value,
726
+ names: $.value.name ?? d.value,
727
+ invalid: R.value,
728
+ invalids: k.value,
729
+ valid: v.showValid ? !!(!R.value && b.value) : void 0,
730
+ invalidLabels: I.value,
731
+ modelValue: b.value,
732
+ readonly: Y.value
733
+ }));
734
+ return T(a, {
735
+ names: G(o),
736
+ errors: G(g)
737
+ }), { component: O(() => ({
738
+ render() {
739
+ return n.default?.({
740
+ errors: g.value,
741
+ formData: f?.formData.value,
742
+ formErrors: f?.errors.value,
743
+ invalid: R.value,
744
+ invalids: k.value,
745
+ invalidLabels: I.value,
746
+ modelValue: b.value,
747
+ onUpdate: t,
748
+ onUpdateField: V,
749
+ readonly: Y.value,
750
+ submit: f?.submit,
751
+ validate: f?.validate
752
+ }) ?? n.default;
753
+ }
754
+ })), hasProps: fe, invalid: R };
755
+ },
756
+ render() {
757
+ return this.is ? F(this.is, this.hasProps, this.$slots) : F(this.component, null, this.$slots);
758
+ }
759
+ });
760
+ }
761
+ function Fe(e, i) {
762
+ return C({
763
+ name: "VvFormWrapper",
764
+ props: {
765
+ name: {
766
+ type: String,
767
+ required: !0
520
768
  },
521
- { deep: !0 }
522
- ), p(
523
- () => new Map(f.value),
524
- (b, g) => {
525
- l != null && l.errors && (Array.from(g.keys()).forEach((V) => {
526
- l.errors.value.delete(V);
527
- }), Array.from(b.keys()).forEach((V) => {
528
- const c = b.get(V);
529
- c && l.errors.value.set(V, c);
530
- }));
769
+ tag: {
770
+ type: String,
771
+ default: void 0
531
772
  },
532
- { deep: !0 }
533
- );
534
- const v = w(() => r != null && r.invalid.value ? f.value.size > 0 : !1);
535
- return p(v, () => {
536
- v.value ? u("invalid") : u("valid");
537
- }), {
538
- formData: r == null ? void 0 : r.formData,
539
- errors: r == null ? void 0 : r.errors,
540
- submit: r == null ? void 0 : r.submit,
541
- validate: r == null ? void 0 : r.validate,
542
- invalid: v,
543
- fields: n,
544
- fieldsErrors: f
545
- };
546
- },
547
- render() {
548
- var o, u;
549
- return this.tag ? O(this.tag, null, {
550
- default: () => {
551
- var r, l;
552
- return ((l = (r = this.$slots).default) == null ? void 0 : l.call(r, {
553
- invalid: this.invalid,
554
- formData: this.formData,
555
- submit: this.submit,
556
- validate: this.validate,
557
- errors: this.errors,
558
- fieldsErrors: this.fieldsErrors
559
- })) ?? this.$slots.defalut;
773
+ readonly: {
774
+ type: Boolean,
775
+ default: !1
560
776
  }
561
- }) : ((u = (o = this.$slots).default) == null ? void 0 : u.call(o, {
562
- invalid: this.invalid,
563
- formData: this.formData,
564
- submit: this.submit,
565
- validate: this.validate,
566
- errors: this.errors,
567
- fieldsErrors: this.fieldsErrors
568
- })) ?? this.$slots.defalut;
569
- }
570
- }), be = (e, s) => {
571
- const t = z({
777
+ },
778
+ emits: ["invalid", "valid"],
779
+ expose: [
780
+ "clear",
781
+ "errors",
782
+ "fields",
783
+ "fieldsErrors",
784
+ "formData",
785
+ "invalid",
786
+ "readonly",
787
+ "reset",
788
+ "submit",
789
+ "tag",
790
+ "validate",
791
+ "validateWrapper"
792
+ ],
793
+ slots: Object,
794
+ setup(a, { emit: v }) {
795
+ const n = U(e), l = U(i, void 0), u = L(/* @__PURE__ */ new Map()), o = L(/* @__PURE__ */ new Map()), { name: r } = Q(a), p = O(() => n?.invalid.value ? o.value.size > 0 : !1);
796
+ A(p, (y) => {
797
+ if (y) {
798
+ v("invalid");
799
+ return;
800
+ }
801
+ v("valid");
802
+ });
803
+ const d = O(() => n?.readonly.value || a.readonly), c = {
804
+ name: G(r),
805
+ errors: o,
806
+ invalid: G(p),
807
+ readonly: G(d),
808
+ fields: u
809
+ };
810
+ T(i, c);
811
+ const m = O(() => new Map(u.value));
812
+ A(
813
+ m,
814
+ (y, f) => {
815
+ l?.fields && (f.forEach((b, g) => {
816
+ y.has(g) || l?.fields.value.delete(g);
817
+ }), y.forEach((b, g) => {
818
+ l?.fields.value.has(g) || l?.fields.value.set(g, b);
819
+ }));
820
+ },
821
+ { deep: !0 }
822
+ ), A(
823
+ o,
824
+ (y) => {
825
+ l?.errors && u.value.forEach((f) => {
826
+ if (y.has(f) || l.errors.value.delete(f), y.has(f)) {
827
+ const b = y.get(f);
828
+ b && l.errors.value.set(f, b);
829
+ }
830
+ });
831
+ },
832
+ { deep: !0 }
833
+ ), q(() => {
834
+ if (!n?.wrappers || !r.value) {
835
+ console.warn("[@volverjs/form-vue]: Invalid wrapper registration state");
836
+ return;
837
+ }
838
+ if (n.wrappers.has(r.value)) {
839
+ console.warn(`[@volverjs/form-vue]: wrapper name "${r.value}" is already used`);
840
+ return;
841
+ }
842
+ n.wrappers.set(r.value, c);
843
+ }), P(() => {
844
+ n?.wrappers && r.value && n.wrappers.delete(r.value);
845
+ });
846
+ const j = () => n?.validate(void 0, { fields: new Set(u.value.values()) }) ?? Promise.resolve(!0);
847
+ return {
848
+ errors: n?.errors,
849
+ fields: u,
850
+ fieldsErrors: o,
851
+ formData: n?.formData,
852
+ invalid: p,
853
+ readonly: d,
854
+ clear: n?.clear,
855
+ reset: n?.reset,
856
+ submit: n?.submit,
857
+ validate: n?.validate,
858
+ validateWrapper: j
859
+ };
860
+ },
861
+ render() {
862
+ const a = () => this.$slots.default?.({
863
+ errors: this.errors,
864
+ fieldsErrors: this.fieldsErrors,
865
+ formData: this.formData,
866
+ invalid: this.invalid,
867
+ readonly: this.readonly,
868
+ clear: this.clear,
869
+ reset: this.reset,
870
+ submit: this.submit,
871
+ validate: this.validate,
872
+ validateWrapper: this.validateWrapper
873
+ });
874
+ return this.tag ? F(this.tag, null, {
875
+ default: a
876
+ }) : a();
877
+ }
878
+ });
879
+ }
880
+ function ke(e, i) {
881
+ const a = C({
572
882
  name: "VvFormTemplate",
573
883
  props: {
574
884
  schema: {
575
885
  type: [Array, Function],
576
886
  required: !0
887
+ },
888
+ scope: {
889
+ type: Object,
890
+ default: () => ({})
577
891
  }
578
892
  },
579
- setup(o, { slots: u }) {
580
- const r = B(e);
581
- if (r != null && r.formData)
893
+ slots: Object,
894
+ setup(v, { slots: n }) {
895
+ const l = U(e);
896
+ if (l?.formData)
582
897
  return () => {
583
- var a;
584
- const l = typeof o.schema == "function" ? o.schema(r) : o.schema;
585
- let n;
586
- const f = l.reduce((v, b) => {
587
- const g = typeof b == "function" ? b(r) : b, {
588
- vvIs: V,
589
- vvName: c,
590
- vvSlots: h,
591
- vvChildren: m,
592
- vvIf: y,
593
- vvElseIf: x,
898
+ const u = typeof v.schema == "function" ? v.schema(
899
+ l,
900
+ v.scope
901
+ ) : v.schema;
902
+ let o;
903
+ const r = u.reduce((p, d) => {
904
+ const c = typeof d == "function" ? d(l, v.scope) : d, {
905
+ vvIs: m,
906
+ vvName: j,
907
+ vvSlots: y,
908
+ vvChildren: f,
909
+ vvIf: b,
910
+ vvElseIf: g,
594
911
  vvType: I,
595
- vvDefaultValue: U,
596
- vvShowValid: N,
597
- vvContent: i,
598
- ..._
599
- } = g;
600
- if (y !== void 0) {
601
- if (typeof y == "string" ? n = !!L(
602
- Object(r.formData.value),
603
- y
604
- ) : typeof y == "function" ? n = C(y(r)) : n = C(y), !n)
605
- return v;
606
- } else if (x !== void 0 && n !== void 0) {
607
- if (n || (typeof x == "string" ? n = !!L(
608
- Object(r.formData.value),
609
- x
610
- ) : typeof x == "function" ? n = C(x(r)) : n = C(x), !n))
611
- return v;
912
+ vvDefaultValue: R,
913
+ vvShowValid: k,
914
+ vvContent: D,
915
+ ...S
916
+ } = c;
917
+ if (b !== void 0) {
918
+ if (typeof b == "string" ? o = !!N(
919
+ new Object(l.formData.value),
920
+ b
921
+ ) : typeof b == "function" ? o = _(b(l)) : o = _(b), !o)
922
+ return p;
923
+ } else if (g !== void 0 && o !== void 0) {
924
+ if (o || (typeof g == "string" ? o = !!N(
925
+ new Object(l.formData.value),
926
+ g
927
+ ) : typeof g == "function" ? o = _(g(l)) : o = _(g), !o))
928
+ return p;
612
929
  } else
613
- n = void 0;
614
- const W = m ? O(t, {
615
- schema: m
616
- }) : void 0;
617
- return c ? (v.push(
618
- O(
619
- s,
930
+ o = void 0;
931
+ let t;
932
+ return f && (typeof m == "string" ? t = F(a, {
933
+ schema: f
934
+ }) : t = {
935
+ default: (V) => F(a, {
936
+ schema: f,
937
+ scope: V
938
+ })
939
+ }), j ? (p.push(
940
+ F(
941
+ i,
620
942
  {
621
- name: c,
622
- is: V,
943
+ name: j,
944
+ is: m,
623
945
  type: I,
624
- defaultValue: U,
625
- showValid: N,
626
- props: _
946
+ defaultValue: R,
947
+ showValid: k,
948
+ props: S
627
949
  },
628
- h ?? W ?? i
950
+ y ?? t ?? D
629
951
  )
630
- ), v) : V ? (v.push(
631
- O(
632
- V,
633
- _,
634
- h ?? W ?? i
952
+ ), p) : m ? (p.push(
953
+ F(
954
+ m,
955
+ S,
956
+ y ?? t ?? D
635
957
  )
636
- ), v) : (m && v.push(W), v);
958
+ ), p) : (t && ("default" in t ? p.push(t.default(v.scope)) : p.push(t)), p);
637
959
  }, []);
638
- return f.push(
639
- (a = u == null ? void 0 : u.default) == null ? void 0 : a.call(u, {
640
- formData: r == null ? void 0 : r.formData.value,
641
- submit: r == null ? void 0 : r.submit,
642
- validate: r == null ? void 0 : r.validate,
643
- errors: r == null ? void 0 : r.errors.value,
644
- status: r == null ? void 0 : r.status.value,
645
- invalid: r == null ? void 0 : r.invalid.value
960
+ return r.push(
961
+ n?.default?.({
962
+ errors: l?.errors.value,
963
+ formData: l?.formData.value,
964
+ invalid: l?.invalid.value,
965
+ status: l?.status.value,
966
+ submit: l?.submit,
967
+ validate: l?.validate,
968
+ clear: l?.clear,
969
+ reset: l?.reset
646
970
  })
647
- ), f;
971
+ ), r;
648
972
  };
649
973
  }
650
974
  });
651
- return t;
652
- }, R = (e, s = {}) => {
653
- const t = Symbol(), o = Symbol(), u = Symbol(), r = ye(
654
- t,
655
- o
656
- ), l = me(
657
- t,
658
- o,
659
- u,
660
- s
661
- ), n = be(t, l), {
662
- VvForm: f,
663
- errors: a,
664
- status: v,
665
- invalid: b,
666
- readonly: g,
667
- formData: V,
668
- validate: c,
669
- submit: h,
670
- ignoreUpdates: m,
671
- stopUpdatesWatch: y
672
- } = he(e, t, s, n);
975
+ return a;
976
+ }
977
+ function J(e, i = {}) {
978
+ const a = Symbol("formInjectionKey"), v = Symbol("formWrapperInjectionKey"), n = Symbol("formFieldInjectionKey"), l = Symbol("formFieldsGroupInjectionKey"), u = Fe(
979
+ a,
980
+ v
981
+ ), o = xe(
982
+ a,
983
+ v,
984
+ n,
985
+ i
986
+ ), r = Ie(
987
+ a,
988
+ v,
989
+ l
990
+ ), p = ke(a, o), d = /* @__PURE__ */ new Map(), {
991
+ clear: c,
992
+ errors: m,
993
+ formData: j,
994
+ ignoreUpdates: y,
995
+ invalid: f,
996
+ readonly: b,
997
+ reset: g,
998
+ status: I,
999
+ stopUpdatesWatch: R,
1000
+ submit: k,
1001
+ validate: D,
1002
+ VvForm: S
1003
+ } = je(e, a, i, p, d);
673
1004
  return {
674
- VvForm: f,
675
- VvFormWrapper: r,
676
- VvFormField: l,
677
- VvFormTemplate: n,
678
- formInjectionKey: t,
679
- formWrapperInjectionKey: o,
680
- formFieldInjectionKey: u,
681
- errors: a,
682
- status: v,
683
- invalid: b,
684
- readonly: g,
685
- formData: V,
686
- validate: c,
687
- submit: h,
688
- ignoreUpdates: m,
689
- stopUpdatesWatch: y
1005
+ clear: c,
1006
+ errors: m,
1007
+ formData: j,
1008
+ formFieldInjectionKey: n,
1009
+ formInjectionKey: a,
1010
+ formWrapperInjectionKey: v,
1011
+ ignoreUpdates: y,
1012
+ invalid: f,
1013
+ readonly: b,
1014
+ reset: g,
1015
+ status: I,
1016
+ stopUpdatesWatch: R,
1017
+ submit: k,
1018
+ validate: D,
1019
+ wrappers: d,
1020
+ VvForm: S,
1021
+ VvFormField: o,
1022
+ VvFormFieldsGroup: r,
1023
+ VvFormTemplate: p,
1024
+ VvFormWrapper: u
690
1025
  };
691
- }, D = Symbol(), ke = (e) => {
692
- let s = {};
693
- return e.schema && (s = R(e.schema, e)), {
694
- ...s,
695
- install(t, { global: o = !1 } = {}) {
696
- 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));
1026
+ }
1027
+ const se = Symbol("pluginInjectionKey");
1028
+ function Be(e) {
1029
+ let i = {};
1030
+ return e.schema && (i = J(e.schema, e)), {
1031
+ ...i,
1032
+ install(a, { global: v = !1 } = {}) {
1033
+ a.provide(se, e), v && (a.config.globalProperties.$vvForm = e, i?.VvForm && a.component("VvForm", i.VvForm), i?.VvFormWrapper && a.component("VvFormWrapper", i.VvFormWrapper), i?.VvFormField && a.component("VvFormField", i.VvFormField), i?.VvFormFieldsGroup && a.component("VvFormFieldsGroup", i.VvFormFieldsGroup), i?.VvFormTemplate && a.component("VvFormTemplate", i.VvFormTemplate));
697
1034
  }
698
1035
  };
699
- }, we = (e, s = {}) => te() ? R(
700
- e,
701
- {
702
- ...B(D, {}),
703
- ...s
1036
+ }
1037
+ const M = /* @__PURE__ */ new Map();
1038
+ function We(e, i = {}) {
1039
+ if (i.scope && M.has(i.scope))
1040
+ return M.get(i.scope);
1041
+ if (!me()) {
1042
+ const v = J(e, i);
1043
+ return i.scope && M.set(i.scope, v), v;
704
1044
  }
705
- ) : R(e, s), pe = (e, s = {}) => R(e, s);
1045
+ const a = J(
1046
+ e,
1047
+ {
1048
+ ...U(se, {}),
1049
+ ...i
1050
+ }
1051
+ );
1052
+ return i.scope && M.set(i.scope, a), a;
1053
+ }
1054
+ function Ue(e, i = {}) {
1055
+ return J(e, i);
1056
+ }
706
1057
  export {
707
- d as FormFieldType,
708
- ke as createForm,
709
- K as defaultObjectBySchema,
710
- pe as formFactory,
711
- D as pluginInjectionKey,
712
- we as useForm
1058
+ w as FormFieldType,
1059
+ Be as createForm,
1060
+ Z as defaultObjectBySchema,
1061
+ Ue as formType,
1062
+ se as pluginInjectionKey,
1063
+ We as useForm
713
1064
  };