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

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: h, 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,948 @@ 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,
425
- ignoreUpdates: b,
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,
211
+ ignoreUpdates: h,
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,
435
- ignoreUpdates: b,
221
+ clear: j,
222
+ errors: I,
223
+ formData: r,
224
+ ignoreUpdates: h,
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: h,
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,
487
- ignoreUpdates: b,
276
+ clear: j,
277
+ errors: l,
278
+ formData: r,
279
+ ignoreUpdates: h,
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
+ }
500
391
  },
501
- tag: {
502
- type: String,
503
- default: void 0
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), h = 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
+ h(), 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 };
569
+ },
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, b) => (s[String(b)] = b, s), {}) : o.value), j = O(() => Object.keys(m.value).reduce((s, b) => (s[String(m.value[b])] = b, 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), h = O({
625
+ get() {
626
+ return f?.formData ? c.value.reduce((s, b) => (s[b] = N(
627
+ new Object(f.formData.value),
628
+ m.value[b]
629
+ ), s), {}) : {};
630
+ },
631
+ set(s) {
632
+ f?.formData && (c.value.forEach((b) => {
633
+ X(
634
+ new Object(f.formData.value),
635
+ m.value[b],
636
+ s?.[b]
637
+ );
638
+ }), l("update:modelValue", {
639
+ newValue: h.value,
640
+ formData: f?.formData
641
+ }));
642
+ }
643
+ });
644
+ q(() => {
645
+ r.value && d.value.forEach((s) => {
646
+ r.value?.[s] !== void 0 && h.value[s] === void 0 && (h.value = {
647
+ ...h.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
+ );
656
+ });
657
+ });
658
+ const g = O(() => {
659
+ if (!f?.errors.value)
660
+ return;
661
+ const s = d.value.reduce((b, E) => {
662
+ if (!f.errors.value)
663
+ return b;
664
+ const ee = N(f.errors.value, String(E));
665
+ return ee === void 0 || (b[String(E)] = ee), b;
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((b, E) => (g.value?.[E] && (b[j.value[E]] = g.value[E]._errors), b), {});
673
+ if (Object.keys(s).length !== 0)
674
+ return s;
675
+ }), R = O(() => g.value !== void 0), k = O(() => c.value.reduce((s, b) => (s[b] = !!g.value?.[j.value[b]], 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", h.value), y && d.value.forEach((s) => {
692
+ y.errors.value.delete(
693
+ s
694
+ );
519
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
+ h.value = s;
708
+ }, V = (s, b) => {
709
+ b instanceof InputEvent && (b = b.target.value), c.value.includes(s) && (h.value = {
710
+ ...h.value,
711
+ [s]: b
712
+ });
713
+ }, $ = O(() => {
714
+ let s = u.value;
715
+ return typeof s == "function" && (s = s(f?.formData)), Object.keys(s).reduce(
716
+ (b, E) => (b[E] = _(s[E]), b),
717
+ {}
718
+ );
719
+ }), Y = O(() => f?.readonly.value ? !0 : $.value.readonly ?? v.readonly), de = O(() => c.value.reduce((s, b) => (s[`onUpdate:${b}`] = (E) => {
720
+ V(b, E);
721
+ }, s), {
722
+ "onUpdate:modelValue": t
723
+ })), fe = O(() => ({
724
+ ...de.value,
725
+ ...$.value,
726
+ ...h.value,
727
+ modelValue: h.value,
728
+ names: $.value.name ?? d.value,
729
+ invalid: R.value,
730
+ invalids: k.value,
731
+ valid: v.showValid ? !!(!R.value && h.value) : void 0,
732
+ invalidLabels: I.value,
733
+ readonly: Y.value
734
+ }));
735
+ return T(a, {
736
+ names: G(o),
737
+ errors: G(g)
738
+ }), { component: O(() => ({
739
+ render() {
740
+ return n.default?.({
741
+ errors: g.value,
742
+ formData: f?.formData.value,
743
+ formErrors: f?.errors.value,
744
+ invalid: R.value,
745
+ invalids: k.value,
746
+ invalidLabels: I.value,
747
+ modelValue: h.value,
748
+ onUpdate: t,
749
+ onUpdateField: V,
750
+ readonly: Y.value,
751
+ submit: f?.submit,
752
+ validate: f?.validate
753
+ }) ?? n.default;
754
+ }
755
+ })), hasProps: fe, invalid: R };
756
+ },
757
+ render() {
758
+ return this.is ? F(this.is, this.hasProps, this.$slots) : F(this.component, null, this.$slots);
759
+ }
760
+ });
761
+ }
762
+ function Fe(e, i) {
763
+ return C({
764
+ name: "VvFormWrapper",
765
+ props: {
766
+ name: {
767
+ type: String,
768
+ required: !0
520
769
  },
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
- }));
770
+ tag: {
771
+ type: String,
772
+ default: void 0
531
773
  },
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;
774
+ readonly: {
775
+ type: Boolean,
776
+ default: !1
560
777
  }
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({
778
+ },
779
+ emits: ["invalid", "valid"],
780
+ expose: [
781
+ "clear",
782
+ "errors",
783
+ "fields",
784
+ "fieldsErrors",
785
+ "formData",
786
+ "invalid",
787
+ "readonly",
788
+ "reset",
789
+ "submit",
790
+ "tag",
791
+ "validate",
792
+ "validateWrapper"
793
+ ],
794
+ slots: Object,
795
+ setup(a, { emit: v }) {
796
+ 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);
797
+ A(p, (y) => {
798
+ if (y) {
799
+ v("invalid");
800
+ return;
801
+ }
802
+ v("valid");
803
+ });
804
+ const d = O(() => n?.readonly.value || a.readonly), c = {
805
+ name: G(r),
806
+ errors: o,
807
+ invalid: G(p),
808
+ readonly: G(d),
809
+ fields: u
810
+ };
811
+ T(i, c);
812
+ const m = O(() => new Map(u.value));
813
+ A(
814
+ m,
815
+ (y, f) => {
816
+ l?.fields && (f.forEach((h, g) => {
817
+ y.has(g) || l?.fields.value.delete(g);
818
+ }), y.forEach((h, g) => {
819
+ l?.fields.value.has(g) || l?.fields.value.set(g, h);
820
+ }));
821
+ },
822
+ { deep: !0 }
823
+ ), A(
824
+ o,
825
+ (y) => {
826
+ l?.errors && u.value.forEach((f) => {
827
+ if (y.has(f) || l.errors.value.delete(f), y.has(f)) {
828
+ const h = y.get(f);
829
+ h && l.errors.value.set(f, h);
830
+ }
831
+ });
832
+ },
833
+ { deep: !0 }
834
+ ), q(() => {
835
+ if (!n?.wrappers || !r.value) {
836
+ console.warn("[@volverjs/form-vue]: Invalid wrapper registration state");
837
+ return;
838
+ }
839
+ if (n.wrappers.has(r.value)) {
840
+ console.warn(`[@volverjs/form-vue]: wrapper name "${r.value}" is already used`);
841
+ return;
842
+ }
843
+ n.wrappers.set(r.value, c);
844
+ }), P(() => {
845
+ n?.wrappers && r.value && n.wrappers.delete(r.value);
846
+ });
847
+ const j = () => n?.validate(void 0, { fields: new Set(u.value.values()) }) ?? Promise.resolve(!0);
848
+ return {
849
+ errors: n?.errors,
850
+ fields: u,
851
+ fieldsErrors: o,
852
+ formData: n?.formData,
853
+ invalid: p,
854
+ readonly: d,
855
+ clear: n?.clear,
856
+ reset: n?.reset,
857
+ submit: n?.submit,
858
+ validate: n?.validate,
859
+ validateWrapper: j
860
+ };
861
+ },
862
+ render() {
863
+ const a = () => this.$slots.default?.({
864
+ errors: this.errors,
865
+ fieldsErrors: this.fieldsErrors,
866
+ formData: this.formData,
867
+ invalid: this.invalid,
868
+ readonly: this.readonly,
869
+ clear: this.clear,
870
+ reset: this.reset,
871
+ submit: this.submit,
872
+ validate: this.validate,
873
+ validateWrapper: this.validateWrapper
874
+ });
875
+ return this.tag ? F(this.tag, null, {
876
+ default: a
877
+ }) : a();
878
+ }
879
+ });
880
+ }
881
+ function ke(e, i) {
882
+ const a = C({
572
883
  name: "VvFormTemplate",
573
884
  props: {
574
885
  schema: {
575
886
  type: [Array, Function],
576
887
  required: !0
888
+ },
889
+ scope: {
890
+ type: Object,
891
+ default: () => ({})
577
892
  }
578
893
  },
579
- setup(o, { slots: u }) {
580
- const r = B(e);
581
- if (r != null && r.formData)
894
+ slots: Object,
895
+ setup(v, { slots: n }) {
896
+ const l = U(e);
897
+ if (l?.formData)
582
898
  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,
899
+ const u = typeof v.schema == "function" ? v.schema(
900
+ l,
901
+ v.scope
902
+ ) : v.schema;
903
+ let o;
904
+ const r = u.reduce((p, d) => {
905
+ const c = typeof d == "function" ? d(l, v.scope) : d, {
906
+ vvIs: m,
907
+ vvName: j,
908
+ vvSlots: y,
909
+ vvChildren: f,
910
+ vvIf: h,
911
+ vvElseIf: g,
594
912
  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;
913
+ vvDefaultValue: R,
914
+ vvShowValid: k,
915
+ vvContent: D,
916
+ ...S
917
+ } = c;
918
+ if (h !== void 0) {
919
+ if (typeof h == "string" ? o = !!N(
920
+ new Object(l.formData.value),
921
+ h
922
+ ) : typeof h == "function" ? o = _(h(l)) : o = _(h), !o)
923
+ return p;
924
+ } else if (g !== void 0 && o !== void 0) {
925
+ if (o || (typeof g == "string" ? o = !!N(
926
+ new Object(l.formData.value),
927
+ g
928
+ ) : typeof g == "function" ? o = _(g(l)) : o = _(g), !o))
929
+ return p;
612
930
  } 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,
931
+ o = void 0;
932
+ let t;
933
+ return f && (typeof m == "string" ? t = F(a, {
934
+ schema: f
935
+ }) : t = {
936
+ default: (V) => F(a, {
937
+ schema: f,
938
+ scope: V
939
+ })
940
+ }), j ? (p.push(
941
+ F(
942
+ i,
620
943
  {
621
- name: c,
622
- is: V,
944
+ name: j,
945
+ is: m,
623
946
  type: I,
624
- defaultValue: U,
625
- showValid: N,
626
- props: _
947
+ defaultValue: R,
948
+ showValid: k,
949
+ props: S
627
950
  },
628
- h ?? W ?? i
951
+ y ?? t ?? D
629
952
  )
630
- ), v) : V ? (v.push(
631
- O(
632
- V,
633
- _,
634
- h ?? W ?? i
953
+ ), p) : m ? (p.push(
954
+ F(
955
+ m,
956
+ S,
957
+ y ?? t ?? D
635
958
  )
636
- ), v) : (m && v.push(W), v);
959
+ ), p) : (t && ("default" in t ? p.push(t.default(v.scope)) : p.push(t)), p);
637
960
  }, []);
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
961
+ return r.push(
962
+ n?.default?.({
963
+ errors: l?.errors.value,
964
+ formData: l?.formData.value,
965
+ invalid: l?.invalid.value,
966
+ status: l?.status.value,
967
+ submit: l?.submit,
968
+ validate: l?.validate,
969
+ clear: l?.clear,
970
+ reset: l?.reset
646
971
  })
647
- ), f;
972
+ ), r;
648
973
  };
649
974
  }
650
975
  });
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);
976
+ return a;
977
+ }
978
+ function J(e, i = {}) {
979
+ const a = Symbol("formInjectionKey"), v = Symbol("formWrapperInjectionKey"), n = Symbol("formFieldInjectionKey"), l = Symbol("formFieldsGroupInjectionKey"), u = Fe(
980
+ a,
981
+ v
982
+ ), o = xe(
983
+ a,
984
+ v,
985
+ n,
986
+ i
987
+ ), r = Ie(
988
+ a,
989
+ v,
990
+ l
991
+ ), p = ke(a, o), d = /* @__PURE__ */ new Map(), {
992
+ clear: c,
993
+ errors: m,
994
+ formData: j,
995
+ ignoreUpdates: y,
996
+ invalid: f,
997
+ readonly: h,
998
+ reset: g,
999
+ status: I,
1000
+ stopUpdatesWatch: R,
1001
+ submit: k,
1002
+ validate: D,
1003
+ VvForm: S
1004
+ } = je(e, a, i, p, d);
673
1005
  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
1006
+ clear: c,
1007
+ errors: m,
1008
+ formData: j,
1009
+ formFieldInjectionKey: n,
1010
+ formInjectionKey: a,
1011
+ formWrapperInjectionKey: v,
1012
+ ignoreUpdates: y,
1013
+ invalid: f,
1014
+ readonly: h,
1015
+ reset: g,
1016
+ status: I,
1017
+ stopUpdatesWatch: R,
1018
+ submit: k,
1019
+ validate: D,
1020
+ wrappers: d,
1021
+ VvForm: S,
1022
+ VvFormField: o,
1023
+ VvFormFieldsGroup: r,
1024
+ VvFormTemplate: p,
1025
+ VvFormWrapper: u
690
1026
  };
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));
1027
+ }
1028
+ const se = Symbol("pluginInjectionKey");
1029
+ function Be(e) {
1030
+ let i = {};
1031
+ return e.schema && (i = J(e.schema, e)), {
1032
+ ...i,
1033
+ install(a, { global: v = !1 } = {}) {
1034
+ 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
1035
  }
698
1036
  };
699
- }, we = (e, s = {}) => te() ? R(
700
- e,
701
- {
702
- ...B(D, {}),
703
- ...s
1037
+ }
1038
+ const M = /* @__PURE__ */ new Map();
1039
+ function We(e, i = {}) {
1040
+ if (i.scope && M.has(i.scope))
1041
+ return M.get(i.scope);
1042
+ if (!me()) {
1043
+ const v = J(e, i);
1044
+ return i.scope && M.set(i.scope, v), v;
704
1045
  }
705
- ) : R(e, s), pe = (e, s = {}) => R(e, s);
1046
+ const a = J(
1047
+ e,
1048
+ {
1049
+ ...U(se, {}),
1050
+ ...i
1051
+ }
1052
+ );
1053
+ return i.scope && M.set(i.scope, a), a;
1054
+ }
1055
+ function Ue(e, i = {}) {
1056
+ return J(e, i);
1057
+ }
706
1058
  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
1059
+ w as FormFieldType,
1060
+ Be as createForm,
1061
+ Z as defaultObjectBySchema,
1062
+ Ue as formType,
1063
+ se as pluginInjectionKey,
1064
+ We as useForm
713
1065
  };