@volverjs/form-vue 1.1.2-beta.1 → 1.1.2

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