@volverjs/form-vue 1.0.0-beta.3 → 1.0.0-beta.31

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