@teamnovu/kit-vue-forms 0.1.20 → 0.1.22

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.js CHANGED
@@ -1,71 +1,146 @@
1
1
  var Q = Object.defineProperty;
2
- var X = (t, e, r) => e in t ? Q(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
- var S = (t, e, r) => X(t, typeof e != "symbol" ? e + "" : e, r);
4
- import { toValue as Y, toRaw as ee, computed as v, unref as d, isRef as k, shallowRef as j, reactive as _, watch as P, toRefs as T, shallowReactive as re, toRef as I, onScopeDispose as te, triggerRef as ae, ref as J, getCurrentScope as se, onBeforeUnmount as ne, defineComponent as x, renderSlot as $, normalizeProps as M, guardReactiveProps as N, resolveComponent as ie, createBlock as H, openBlock as K, withCtx as B, resolveDynamicComponent as oe, mergeProps as le, createSlots as ce, renderList as ue } from "vue";
2
+ var X = (r, t, e) => t in r ? Q(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
3
+ var R = (r, t, e) => X(r, typeof t != "symbol" ? t + "" : t, e);
4
+ import { toValue as Y, toRaw as ee, unref as d, shallowRef as I, watch as D, computed as V, isRef as O, reactive as A, toRefs as K, shallowReactive as te, toRef as U, onScopeDispose as re, triggerRef as ae, ref as J, getCurrentScope as se, onBeforeUnmount as ne, defineComponent as C, renderSlot as k, normalizeProps as T, guardReactiveProps as N, resolveComponent as ie, createBlock as z, openBlock as H, withCtx as B, resolveDynamicComponent as oe, mergeProps as le, createSlots as ce, renderList as ue } from "vue";
5
5
  import { cloneDeep as de } from "lodash-es";
6
6
  import "zod";
7
- function g(t) {
8
- const e = Y(t), r = ee(e);
9
- return de(r);
7
+ function g(r) {
8
+ const t = Y(r), e = ee(t);
9
+ return de(e);
10
10
  }
11
- function W(t) {
12
- return t === "" ? [] : t.split(/\s*\.\s*/).filter(Boolean);
11
+ function L(r, t) {
12
+ return (e) => async (a) => {
13
+ a.preventDefault(), d(t.validationStrategy) !== "none" && await r.validateForm(), r.isValid.value && await e(r.data.value);
14
+ };
15
+ }
16
+ class fe {
17
+ constructor(t = (e) => e) {
18
+ R(this, "weakMap", /* @__PURE__ */ new WeakMap());
19
+ R(this, "map", /* @__PURE__ */ new Map());
20
+ R(this, "hashFn");
21
+ this.hashFn = t;
22
+ }
23
+ isReferenceType(t) {
24
+ return typeof t == "object" && t !== null;
25
+ }
26
+ has(t) {
27
+ const e = this.hashFn(t);
28
+ return this.isReferenceType(e) ? this.weakMap.has(e) : this.map.has(e);
29
+ }
30
+ get(t) {
31
+ const e = this.hashFn(t);
32
+ return this.isReferenceType(e) ? this.weakMap.get(e) : this.map.get(e);
33
+ }
34
+ set(t, e) {
35
+ const a = this.hashFn(t);
36
+ this.isReferenceType(a) ? this.weakMap.set(a, e) : this.map.set(a, e);
37
+ }
13
38
  }
14
- function fe(t, e) {
15
- const r = Array.isArray(e) ? e : W(e);
16
- return !!D(t, r.slice(0, -1));
39
+ function he(r, t) {
40
+ const e = /* @__PURE__ */ new Set();
41
+ return t.map((a) => {
42
+ const s = [...r.get(a) ?? []], n = s.findIndex((c) => !e.has(c)), p = (n === -1 ? [] : s.slice(n))[0];
43
+ if (p)
44
+ return e.add(p), {
45
+ id: p,
46
+ item: a
47
+ };
48
+ const v = crypto.randomUUID();
49
+ return r.set(a, s.concat([v])), e.add(v), {
50
+ id: v,
51
+ item: a
52
+ };
53
+ });
54
+ }
55
+ function G(r, t, e) {
56
+ const a = new fe(e == null ? void 0 : e.hashFn), s = r.getField(t), n = I([]);
57
+ return D(
58
+ s.data,
59
+ (c) => {
60
+ n.value = he(a, c);
61
+ },
62
+ {
63
+ immediate: !0,
64
+ flush: "sync"
65
+ }
66
+ ), {
67
+ fields: n,
68
+ push: (c) => {
69
+ const i = s.data.value ?? [];
70
+ s.setData([...i, c]);
71
+ },
72
+ remove: (c) => {
73
+ const i = s.data.value ?? [];
74
+ s.setData(
75
+ (i == null ? void 0 : i.filter((h) => h !== d(c))) ?? []
76
+ );
77
+ },
78
+ removeByIndex: (c) => {
79
+ const i = s.data.value ?? [];
80
+ s.setData((i == null ? void 0 : i.filter((h, l) => l !== c)) ?? []);
81
+ },
82
+ errors: s.errors,
83
+ dirty: s.dirty
84
+ };
17
85
  }
18
- function D(t, e) {
19
- return (Array.isArray(e) ? e : W(e)).reduce(
86
+ function W(r) {
87
+ return r === "" ? [] : r.split(/\s*\.\s*/).filter(Boolean);
88
+ }
89
+ function pe(r, t) {
90
+ const e = Array.isArray(t) ? t : W(t);
91
+ return !!S(r, e.slice(0, -1));
92
+ }
93
+ function S(r, t) {
94
+ return (Array.isArray(t) ? t : W(t)).reduce(
20
95
  (a, s) => a == null ? void 0 : a[s],
21
- t
96
+ r
22
97
  );
23
98
  }
24
- function he(t, e, r) {
25
- const a = Array.isArray(e) ? e : W(e), s = a.at(-1);
99
+ function ve(r, t, e) {
100
+ const a = Array.isArray(t) ? t : W(t), s = a.at(-1);
26
101
  if (s) {
27
102
  const n = a.slice(0, -1).reduce(
28
103
  (f, p) => ((f == null ? void 0 : f[p]) === void 0 && (f[p] = {}), f == null ? void 0 : f[p]),
29
104
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
30
- d(t)
105
+ d(r)
31
106
  );
32
- n[s] = r;
107
+ n[s] = e;
33
108
  } else {
34
- if (!k(t))
109
+ if (!O(r))
35
110
  return;
36
- t.value = r;
111
+ r.value = e;
37
112
  }
38
113
  }
39
- const L = (t, e) => v({
114
+ const Z = (r, t) => V({
40
115
  get() {
41
- return D(d(t), d(e));
116
+ return S(d(r), d(t));
42
117
  },
43
- set(r) {
44
- he(t, d(e), r);
118
+ set(e) {
119
+ ve(r, d(t), e);
45
120
  }
46
121
  });
47
- function b(t, e) {
48
- return !t && !e ? "" : !t && e ? e : !e && t ? t : `${t}.${e}`;
122
+ function b(r, t) {
123
+ return !r && !t ? "" : !r && t ? t : !t && r ? r : `${r}.${t}`;
49
124
  }
50
- function ve(t, e) {
51
- if (!e)
52
- return t;
53
- const r = `${e}.`, a = Object.fromEntries(
54
- Object.entries(t.propertyErrors).filter(([s]) => s.startsWith(r)).map(([s, n]) => [
55
- s.slice(r.length),
125
+ function me(r, t) {
126
+ if (!t)
127
+ return r;
128
+ const e = `${t}.`, a = Object.fromEntries(
129
+ Object.entries(r.propertyErrors).filter(([s]) => s.startsWith(e)).map(([s, n]) => [
130
+ s.slice(e.length),
56
131
  n
57
132
  ])
58
133
  );
59
134
  return {
60
- general: t.general,
135
+ general: r.general,
61
136
  // Keep general errors
62
137
  propertyErrors: a
63
138
  };
64
139
  }
65
- class me {
66
- constructor(e) {
67
- S(this, "rc", 1);
68
- this.drop = e;
140
+ class Ve {
141
+ constructor(t) {
142
+ R(this, "rc", 1);
143
+ this.drop = t;
69
144
  }
70
145
  inc() {
71
146
  this.rc += 1;
@@ -74,196 +149,191 @@ class me {
74
149
  this.rc > 0 && (this.rc -= 1, this.rc === 0 && this.drop && this.drop());
75
150
  }
76
151
  }
77
- function pe(t) {
78
- const r = {
152
+ function ye(r) {
153
+ const e = {
79
154
  ...{
80
155
  existsInForm: !0
81
156
  },
82
- ...t
83
- }, a = j(Object.freeze(g(r.initialValue))), s = _({
84
- value: r.value,
85
- path: r.path,
157
+ ...r
158
+ }, a = I(Object.freeze(g(e.initialValue))), s = A({
159
+ value: e.value,
160
+ path: e.path,
86
161
  initialValue: a,
87
- errors: r.errors,
162
+ errors: e.errors,
88
163
  touched: !1
89
164
  });
90
- P(
91
- j(r.initialValue),
165
+ D(
166
+ I(e.initialValue),
92
167
  () => {
93
- a.value = Object.freeze(g(r.initialValue)), s.value = g(r.initialValue);
168
+ a.value = Object.freeze(g(e.initialValue)), s.value !== d(e.initialValue) && (s.value = g(e.initialValue));
94
169
  },
95
170
  { flush: "sync" }
96
171
  );
97
- const n = v(() => JSON.stringify(s.value) !== JSON.stringify(s.initialValue)), f = (h) => {
98
- s.value = h;
172
+ const n = V(() => JSON.stringify(s.value) !== JSON.stringify(s.initialValue)), f = (m) => {
173
+ s.value = m;
99
174
  }, p = () => {
100
- var h;
101
- s.touched = !0, s.errors = [], (h = r.onBlur) == null || h.call(r);
102
- }, F = () => {
103
- var h;
104
- (h = r.onFocus) == null || h.call(r);
105
- }, V = () => {
106
- const h = s.path.split(".").at(-1) || "";
107
- d(r.existsInForm) && !/^\d+$/.test(h) && (s.value = g(s.initialValue)), s.touched = !1, s.errors = [];
108
- }, l = (h) => {
109
- n.value || f(g(h)), s.initialValue = h;
110
- }, c = (h) => {
111
- s.errors = h;
112
- }, o = () => {
175
+ var m;
176
+ s.touched = !0, s.errors = [], (m = e.onBlur) == null || m.call(e);
177
+ }, v = () => {
178
+ var m;
179
+ (m = e.onFocus) == null || m.call(e);
180
+ }, c = () => {
181
+ const m = s.path.split(".").at(-1) || "";
182
+ d(e.existsInForm) && !/^\d+$/.test(m) && (s.value = g(s.initialValue)), s.touched = !1, s.errors = [];
183
+ }, i = (m) => {
184
+ n.value || f(g(m)), s.initialValue = m;
185
+ }, h = (m) => {
186
+ s.errors = m;
187
+ }, l = () => {
113
188
  s.errors = [];
114
- }, i = T(s);
189
+ }, o = K(s);
115
190
  return {
116
- data: i.value,
117
- path: i.path,
118
- initialValue: i.initialValue,
119
- errors: i.errors,
120
- touched: i.touched,
191
+ data: o.value,
192
+ path: o.path,
193
+ initialValue: o.initialValue,
194
+ errors: o.errors,
195
+ touched: o.touched,
121
196
  dirty: n,
122
197
  setData: f,
123
- setInitialData: l,
198
+ setInitialData: i,
124
199
  onBlur: p,
125
- onFocus: F,
126
- reset: V,
127
- setErrors: c,
128
- clearErrors: o
200
+ onFocus: v,
201
+ reset: c,
202
+ setErrors: h,
203
+ clearErrors: l
129
204
  };
130
205
  }
131
- const Ve = {
206
+ const Fe = {
132
207
  keepValuesOnUnmount: !0
133
208
  };
134
- function Fe(t, e) {
135
- const r = () => D(t.initialData, e), a = j(r());
136
- return P(
137
- () => t.initialData,
209
+ function ge(r, t) {
210
+ const e = () => S(r.initialData, t), a = I(e());
211
+ return D(
212
+ () => r.initialData,
138
213
  () => {
139
- a.value = r(), ae(a);
214
+ a.value = e(), ae(a);
140
215
  },
141
216
  { flush: "sync" }
142
217
  ), a;
143
218
  }
144
- function ye(t, e, r) {
145
- const a = /* @__PURE__ */ new Map(), s = re(/* @__PURE__ */ new Map()), n = {
146
- ...Ve,
147
- ...r
148
- }, f = (o) => {
149
- const i = d(o.path);
150
- s.set(i, o);
151
- }, p = (o) => {
152
- var i;
153
- n != null && n.keepValuesOnUnmount || (i = s.get(o)) == null || i.reset(), s.delete(o);
154
- }, F = (o) => {
155
- var i;
156
- a.has(o) ? (i = a.get(o)) == null || i.inc() : a.set(o, new me(() => p(o)));
157
- }, V = (o) => {
158
- var i;
159
- a.has(o) && ((i = a.get(o)) == null || i.dec());
160
- }, l = (o) => {
161
- const { path: i } = o;
162
- if (!s.has(i)) {
163
- const A = pe({
164
- path: i,
165
- value: L(I(t, "data"), i),
166
- initialValue: Fe(t, i),
167
- existsInForm: v(() => fe(t.data, d(i))),
168
- errors: v({
219
+ function Ee(r, t, e) {
220
+ const a = /* @__PURE__ */ new Map(), s = te(/* @__PURE__ */ new Map()), n = {
221
+ ...Fe,
222
+ ...e
223
+ }, f = (l) => {
224
+ const o = d(l.path);
225
+ s.set(o, l);
226
+ }, p = (l) => {
227
+ var o;
228
+ n != null && n.keepValuesOnUnmount || (o = s.get(l)) == null || o.reset(), s.delete(l);
229
+ }, v = (l) => {
230
+ var o;
231
+ a.has(l) ? (o = a.get(l)) == null || o.inc() : a.set(l, new Ve(() => p(l)));
232
+ }, c = (l) => {
233
+ var o;
234
+ a.has(l) && ((o = a.get(l)) == null || o.dec());
235
+ }, i = (l) => {
236
+ const { path: o } = l;
237
+ if (!s.has(o)) {
238
+ const M = ye({
239
+ path: o,
240
+ value: Z(U(r, "data"), o),
241
+ initialValue: ge(r, o),
242
+ existsInForm: V(() => pe(r.data, d(o))),
243
+ errors: V({
169
244
  get() {
170
- return e.errors.value.propertyErrors[i] || [];
245
+ return t.errors.value.propertyErrors[o] || [];
171
246
  },
172
247
  set(E) {
173
- e.errors.value.propertyErrors[i] = E;
248
+ t.errors.value.propertyErrors[o] = E;
174
249
  }
175
250
  }),
176
251
  onBlur: async () => {
177
- var E, R;
252
+ var E, P;
178
253
  await Promise.all([
179
- (E = n == null ? void 0 : n.onBlur) == null ? void 0 : E.call(n, d(i)),
180
- (R = o.onBlur) == null ? void 0 : R.call(o)
254
+ (E = n == null ? void 0 : n.onBlur) == null ? void 0 : E.call(n, d(o)),
255
+ (P = l.onBlur) == null ? void 0 : P.call(l)
181
256
  ]);
182
257
  },
183
258
  onFocus: async () => {
184
- var E, R;
259
+ var E, P;
185
260
  await Promise.all([
186
- (E = n == null ? void 0 : n.onFocus) == null ? void 0 : E.call(n, d(i)),
187
- (R = o.onFocus) == null ? void 0 : R.call(o)
261
+ (E = n == null ? void 0 : n.onFocus) == null ? void 0 : E.call(n, d(o)),
262
+ (P = l.onFocus) == null ? void 0 : P.call(l)
188
263
  ]);
189
264
  }
190
265
  });
191
- f(A);
266
+ f(M);
192
267
  }
193
- const h = s.get(i);
194
- return F(i), te(() => {
195
- V(i);
196
- }), h;
197
- }, c = (o) => l(o);
268
+ const m = s.get(o);
269
+ return v(o), re(() => {
270
+ c(o);
271
+ }), m;
272
+ }, h = (l) => i(l);
198
273
  return {
199
- fields: v(() => [...s.values()]),
200
- getField: (o) => l({ path: o }),
274
+ fields: V(() => [...s.values()]),
275
+ getField: (l) => i({ path: l }),
201
276
  registerField: f,
202
277
  deregisterField: p,
203
- defineField: c
278
+ defineField: h
204
279
  };
205
280
  }
206
- function ge(t) {
207
- const e = v(() => t.fields.value.some((a) => d(a.dirty))), r = v(() => t.fields.value.some((a) => d(a.touched)));
281
+ function we(r) {
282
+ const t = V(() => r.fields.value.some((a) => d(a.dirty))), e = V(() => r.fields.value.some((a) => d(a.touched)));
208
283
  return {
209
- isDirty: e,
210
- isTouched: r
211
- };
212
- }
213
- function G(t, e) {
214
- return (r) => async (a) => {
215
- a.preventDefault(), d(e.validationStrategy) !== "none" && await t.validateForm(), t.isValid.value && await r(t.data.value);
284
+ isDirty: t,
285
+ isTouched: e
216
286
  };
217
287
  }
218
- function Ee(t) {
219
- return t.filter(
220
- (e, r, a) => a.indexOf(e) === r
288
+ function Re(r) {
289
+ return r.filter(
290
+ (t, e, a) => a.indexOf(t) === e
221
291
  );
222
292
  }
223
- function Z(...t) {
224
- return t.slice(1).reduce((e, r) => {
225
- if (!e && !r)
293
+ function q(...r) {
294
+ return r.slice(1).reduce((t, e) => {
295
+ if (!t && !e)
226
296
  return;
227
- const a = ((r == null ? void 0 : r.length) ?? 0) > 0;
228
- if (!e && ((r == null ? void 0 : r.length) ?? 0) > 0)
229
- return r;
230
- if (!a)
297
+ const a = ((e == null ? void 0 : e.length) ?? 0) > 0;
298
+ if (!t && ((e == null ? void 0 : e.length) ?? 0) > 0)
231
299
  return e;
232
- const s = (e ?? []).concat(r);
233
- return Ee(s);
234
- }, t[0]);
300
+ if (!a)
301
+ return t;
302
+ const s = (t ?? []).concat(e);
303
+ return Re(s);
304
+ }, r[0]);
235
305
  }
236
- function we(...t) {
237
- return t.map((r) => Object.keys(r)).flat().reduce((r, a) => {
238
- const s = t.map((n) => n[a]).filter(Boolean);
306
+ function De(...r) {
307
+ return r.map((e) => Object.keys(e)).flat().reduce((e, a) => {
308
+ const s = r.map((n) => n[a]).filter(Boolean);
239
309
  return {
240
- ...r,
241
- [a]: Z(...s)
310
+ ...e,
311
+ [a]: q(...s)
242
312
  };
243
313
  }, {});
244
314
  }
245
- function C(...t) {
246
- if (!t.length)
315
+ function j(...r) {
316
+ if (!r.length)
247
317
  return {
248
318
  general: [],
249
319
  propertyErrors: {}
250
320
  };
251
- const e = t[0];
252
- return t.length === 1 ? e : t.slice(1).reduce(
253
- (r, a) => ({
254
- general: Z(r.general, a.general),
255
- propertyErrors: we(r.propertyErrors ?? {}, a.propertyErrors ?? {})
321
+ const t = r[0];
322
+ return r.length === 1 ? t : r.slice(1).reduce(
323
+ (e, a) => ({
324
+ general: q(e.general, a.general),
325
+ propertyErrors: De(e.propertyErrors ?? {}, a.propertyErrors ?? {})
256
326
  }),
257
- e
327
+ t
258
328
  );
259
329
  }
260
- function O(t) {
330
+ function _(r) {
261
331
  var a;
262
- const e = (((a = t.general) == null ? void 0 : a.length) ?? 0) > 0, r = Object.entries(t.propertyErrors).filter(([, s]) => s == null ? void 0 : s.length).length > 0;
263
- return e || r;
332
+ const t = (((a = r.general) == null ? void 0 : a.length) ?? 0) > 0, e = Object.entries(r.propertyErrors).filter(([, s]) => s == null ? void 0 : s.length).length > 0;
333
+ return t || e;
264
334
  }
265
- function Re(t) {
266
- const e = t.issues.filter((a) => a.path.length === 0).map((a) => a.message), r = t.issues.filter((a) => a.path.length > 0).reduce((a, s) => {
335
+ function Pe(r) {
336
+ const t = r.issues.filter((a) => a.path.length === 0).map((a) => a.message), e = r.issues.filter((a) => a.path.length > 0).reduce((a, s) => {
267
337
  const n = s.path.join(".");
268
338
  return {
269
339
  ...a,
@@ -271,28 +341,28 @@ function Re(t) {
271
341
  };
272
342
  }, {});
273
343
  return {
274
- general: e,
275
- propertyErrors: r
344
+ general: t,
345
+ propertyErrors: e
276
346
  };
277
347
  }
278
- const y = {
348
+ const F = {
279
349
  isValid: !0,
280
350
  errors: {
281
351
  general: [],
282
352
  propertyErrors: {}
283
353
  }
284
354
  };
285
- class Pe {
286
- constructor(e) {
287
- this.schema = e;
355
+ class Se {
356
+ constructor(t) {
357
+ this.schema = t;
288
358
  }
289
- async validate(e) {
359
+ async validate(t) {
290
360
  if (!this.schema)
291
- return y;
292
- const r = await this.schema.safeParseAsync(e);
293
- if (r.success)
294
- return y;
295
- const a = Re(r.error);
361
+ return F;
362
+ const e = await this.schema.safeParseAsync(t);
363
+ if (e.success)
364
+ return F;
365
+ const a = Pe(e.error);
296
366
  return {
297
367
  isValid: !1,
298
368
  errors: {
@@ -302,138 +372,138 @@ class Pe {
302
372
  };
303
373
  }
304
374
  }
305
- class De {
306
- constructor(e) {
307
- this.validateFn = e;
375
+ class be {
376
+ constructor(t) {
377
+ this.validateFn = t;
308
378
  }
309
- async validate(e) {
379
+ async validate(t) {
310
380
  if (!this.validateFn)
311
- return y;
381
+ return F;
312
382
  try {
313
- const r = await this.validateFn(e);
314
- return r.isValid ? y : r;
315
- } catch (r) {
383
+ const e = await this.validateFn(t);
384
+ return e.isValid ? F : e;
385
+ } catch (e) {
316
386
  return {
317
387
  isValid: !1,
318
388
  errors: {
319
- general: [r.message || "Validation error"],
389
+ general: [e.message || "Validation error"],
320
390
  propertyErrors: {}
321
391
  }
322
392
  };
323
393
  }
324
394
  }
325
395
  }
326
- class Se {
327
- constructor(e, r) {
328
- S(this, "schemaValidator");
329
- S(this, "functionValidator");
330
- this.schema = e, this.validateFn = r, this.schemaValidator = new Pe(this.schema), this.functionValidator = new De(this.validateFn);
396
+ class Ie {
397
+ constructor(t, e) {
398
+ R(this, "schemaValidator");
399
+ R(this, "functionValidator");
400
+ this.schema = t, this.validateFn = e, this.schemaValidator = new Se(this.schema), this.functionValidator = new be(this.validateFn);
331
401
  }
332
- async validate(e) {
333
- const [r, a] = await Promise.all([
334
- this.schemaValidator.validate(e),
335
- this.functionValidator.validate(e)
402
+ async validate(t) {
403
+ const [e, a] = await Promise.all([
404
+ this.schemaValidator.validate(t),
405
+ this.functionValidator.validate(t)
336
406
  ]);
337
407
  return {
338
- isValid: r.isValid && a.isValid,
339
- errors: C(r.errors, a.errors)
408
+ isValid: e.isValid && a.isValid,
409
+ errors: j(e.errors, a.errors)
340
410
  };
341
411
  }
342
412
  }
343
- function U(t) {
344
- return v(() => new Se(
345
- d(t.schema),
346
- d(t.validateFn)
413
+ function x(r) {
414
+ return V(() => new Ie(
415
+ d(r.schema),
416
+ d(r.validateFn)
347
417
  ));
348
418
  }
349
- function be(t, e) {
350
- const r = _({
351
- validators: J([U(e)]),
419
+ function ke(r, t) {
420
+ const e = A({
421
+ validators: J([x(t)]),
352
422
  isValidated: !1,
353
- errors: d(e.errors) ?? y.errors
354
- }), a = (l = y.errors) => {
355
- r.errors = C(d(e.errors) ?? y.errors, l);
423
+ errors: d(t.errors) ?? F.errors
424
+ }), a = (i = F.errors) => {
425
+ e.errors = j(d(t.errors) ?? F.errors, i);
356
426
  };
357
- P(() => d(e.errors), async () => {
358
- if (r.isValidated) {
359
- const l = await n();
360
- a(l.errors);
427
+ D(() => d(t.errors), async () => {
428
+ if (e.isValidated) {
429
+ const i = await n();
430
+ a(i.errors);
361
431
  } else
362
432
  a();
363
- }, { immediate: !0 }), P(
364
- [() => r.validators],
365
- async (l) => {
366
- if (r.isValidated)
367
- if (l) {
368
- const c = await n();
369
- r.errors = c.errors;
433
+ }, { immediate: !0 }), D(
434
+ [() => e.validators],
435
+ async (i) => {
436
+ if (e.isValidated)
437
+ if (i) {
438
+ const h = await n();
439
+ e.errors = h.errors;
370
440
  } else
371
- r.errors = y.errors;
441
+ e.errors = F.errors;
372
442
  },
373
443
  { immediate: !0 }
374
- ), P([() => t.data, () => d(e.schema)], () => {
375
- r.isValidated && f();
444
+ ), D([() => r.data, () => d(t.schema)], () => {
445
+ e.isValidated && f();
376
446
  });
377
- const s = (l) => {
378
- const c = k(l) ? l : U(l);
379
- return r.validators.push(c), se() && ne(() => {
380
- r.validators = r.validators.filter(
381
- (o) => o !== c
447
+ const s = (i) => {
448
+ const h = O(i) ? i : x(i);
449
+ return e.validators.push(h), se() && ne(() => {
450
+ e.validators = e.validators.filter(
451
+ (l) => l !== h
382
452
  );
383
- }), c;
453
+ }), h;
384
454
  };
385
455
  async function n() {
386
- const l = await Promise.all(
387
- r.validators.filter((i) => d(i) !== void 0).map((i) => d(i).validate(t.data))
388
- ), c = l.every((i) => i.isValid);
389
- let { errors: o } = y;
390
- if (!c) {
391
- const i = l.map((h) => h.errors);
392
- o = C(...i);
456
+ const i = await Promise.all(
457
+ e.validators.filter((o) => d(o) !== void 0).map((o) => d(o).validate(r.data))
458
+ ), h = i.every((o) => o.isValid);
459
+ let { errors: l } = F;
460
+ if (!h) {
461
+ const o = i.map((m) => m.errors);
462
+ l = j(...o);
393
463
  }
394
464
  return {
395
- errors: o,
396
- isValid: c
465
+ errors: l,
466
+ isValid: h
397
467
  };
398
468
  }
399
469
  const f = async () => {
400
- const l = await n();
401
- return a(l.errors), r.isValidated = !0, {
402
- isValid: !O(l.errors),
403
- errors: r.errors
470
+ const i = await n();
471
+ return a(i.errors), e.isValidated = !0, {
472
+ isValid: !_(i.errors),
473
+ errors: e.errors
404
474
  };
405
- }, p = async (l) => {
406
- const c = await n();
475
+ }, p = async (i) => {
476
+ const h = await n();
407
477
  return a({
408
- general: c.errors.general,
478
+ general: h.errors.general,
409
479
  propertyErrors: {
410
- [l]: c.errors.propertyErrors[l]
480
+ [i]: h.errors.propertyErrors[i]
411
481
  }
412
482
  }), {
413
- isValid: !O(c.errors),
414
- errors: r.errors
483
+ isValid: !_(h.errors),
484
+ errors: e.errors
415
485
  };
416
- }, F = v(() => !O(r.errors)), V = () => {
417
- r.isValidated = !1, r.errors = d(e.errors) ?? y.errors;
486
+ }, v = V(() => !_(e.errors)), c = () => {
487
+ e.isValidated = !1, e.errors = d(t.errors) ?? F.errors;
418
488
  };
419
489
  return {
420
- ...T(r),
490
+ ...K(e),
421
491
  validateForm: f,
422
492
  validateField: p,
423
493
  defineValidator: s,
424
- isValid: F,
425
- reset: V
494
+ isValid: v,
495
+ reset: c
426
496
  };
427
497
  }
428
- class $e {
429
- constructor(e, r) {
430
- this.path = e, this.validator = r;
498
+ class Ae {
499
+ constructor(t, e) {
500
+ this.path = t, this.validator = e;
431
501
  }
432
- async validate(e) {
433
- const r = D(e, this.path);
502
+ async validate(t) {
503
+ const e = S(t, this.path);
434
504
  if (!this.validator)
435
- return y;
436
- const a = await this.validator.validate(r);
505
+ return F;
506
+ const a = await this.validator.validate(e);
437
507
  return {
438
508
  isValid: a.isValid,
439
509
  errors: {
@@ -447,106 +517,96 @@ class $e {
447
517
  };
448
518
  }
449
519
  }
450
- function _e(t, e, r, a) {
451
- const s = L(t.data, e), n = v(() => D(t.initialData.value, e)), f = (u) => ({
520
+ function Me(r, t, e, a) {
521
+ const s = Z(r.data, t), n = V(() => S(r.initialData.value, t)), f = (u) => ({
452
522
  ...u,
453
- path: v(() => d(u.path).replace(e + ".", "")),
454
- setData: (m) => {
455
- u.setData(m);
523
+ path: V(() => d(u.path).replace(t + ".", "")),
524
+ setData: (y) => {
525
+ u.setData(y);
456
526
  }
457
527
  }), p = (u) => {
458
- const m = b(e, u), w = t.getField(m);
528
+ const y = b(t, u), w = r.getField(y);
459
529
  return w ? f(w) : {};
460
- }, F = (u) => {
461
- const m = b(e, u.path), w = t.defineField({
530
+ }, v = (u) => {
531
+ const y = b(t, u.path), w = r.defineField({
462
532
  ...u,
463
- path: m
533
+ path: y
464
534
  });
465
535
  return f(w);
466
- }, V = v(() => t.fields.value.filter((u) => {
467
- const m = u.path.value;
468
- return m.startsWith(e + ".") || m === e;
469
- }).map((u) => f(u))), l = () => t.fields.value.filter((u) => {
470
- const m = u.path.value;
471
- return m.startsWith(e + ".") || m === e;
472
- }), c = v(
473
- () => l().some((u) => u.dirty.value)
474
- ), o = v(
475
- () => l().some((u) => u.touched.value)
476
- ), i = v(() => t.isValid.value), h = v(() => t.isValidated.value), A = v(
477
- () => ve(d(t.errors), e)
478
- ), z = {
536
+ }, c = V(() => r.fields.value.filter((u) => {
537
+ const y = u.path.value;
538
+ return y.startsWith(t + ".") || y === t;
539
+ }).map((u) => f(u))), i = () => r.fields.value.filter((u) => {
540
+ const y = u.path.value;
541
+ return y.startsWith(t + ".") || y === t;
542
+ }), h = V(() => i().some((u) => u.dirty.value)), l = V(() => i().some((u) => u.touched.value)), o = V(() => r.isValid.value), m = V(() => r.isValidated.value), M = V(() => me(d(r.errors), t)), $ = {
479
543
  data: s,
480
- fields: V,
544
+ fields: c,
481
545
  initialData: n,
482
- defineField: F,
546
+ defineField: v,
483
547
  getField: p,
484
- isDirty: c,
485
- isTouched: o,
486
- isValid: i,
487
- isValidated: h,
488
- errors: A,
548
+ isDirty: h,
549
+ isTouched: l,
550
+ isValid: o,
551
+ isValidated: m,
552
+ errors: M,
489
553
  defineValidator: (u) => {
490
- const m = k(u) ? u : U(u), w = v(
491
- () => new $e(e, d(m))
554
+ const y = O(u) ? u : x(u), w = V(
555
+ () => new Ae(t, d(y))
492
556
  );
493
- return t.defineValidator(w), m;
557
+ return r.defineValidator(w), y;
494
558
  },
495
- reset: () => l().forEach((u) => u.reset()),
496
- validateForm: () => t.validateForm(),
497
- getSubForm: (u, m) => {
498
- const w = b(e, u);
499
- return t.getSubForm(
559
+ reset: () => i().forEach((u) => u.reset()),
560
+ validateForm: () => r.validateForm(),
561
+ getSubForm: (u, y) => {
562
+ const w = b(t, u);
563
+ return r.getSubForm(
500
564
  w,
501
- m
565
+ y
502
566
  );
503
- }
504
- }, q = G(z, r ?? {});
505
- return {
506
- ...z,
507
- submitHandler: q
567
+ },
568
+ submitHandler: (u) => L($, e ?? {})(u),
569
+ useFieldArray: (u, y) => G($, u, y)
508
570
  };
571
+ return $;
509
572
  }
510
- function Ue(t) {
511
- const e = v(() => g(t.initialData)), r = J(g(e)), a = _({
512
- initialData: e,
513
- data: r
573
+ function Oe(r) {
574
+ const t = V(() => g(r.initialData)), e = J(g(t)), a = A({
575
+ initialData: t,
576
+ data: e
514
577
  });
515
- P(
516
- e,
578
+ D(
579
+ t,
517
580
  (c) => {
518
581
  a.data = g(c);
519
582
  },
520
583
  { flush: "sync" }
521
584
  );
522
- const s = be(a, t), n = ye(a, s, {
523
- keepValuesOnUnmount: t.keepValuesOnUnmount,
585
+ const s = ke(a, r), n = Ee(a, s, {
586
+ keepValuesOnUnmount: r.keepValuesOnUnmount,
524
587
  onBlur: async (c) => {
525
- d(t.validationStrategy) === "onTouch" && s.validateField(c);
588
+ d(r.validationStrategy) === "onTouch" && s.validateField(c);
526
589
  }
527
- }), f = ge(n), p = () => {
528
- r.value = g(e), s.reset();
590
+ }), f = we(n), p = () => {
591
+ e.value = g(t), s.reset();
529
592
  for (const c of n.fields.value)
530
593
  c.reset();
531
594
  };
532
- function F(c, o) {
533
- return _e(V, c, t);
534
- }
535
- const V = {
595
+ d(r.validationStrategy) === "onFormOpen" && s.validateForm();
596
+ const v = {
536
597
  ...n,
537
598
  ...s,
538
599
  ...f,
539
600
  reset: p,
540
- getSubForm: F,
541
- initialData: I(a, "initialData"),
542
- data: I(a, "data")
543
- }, l = G(V, t);
544
- return d(t.validationStrategy) === "onFormOpen" && s.validateForm(), {
545
- ...V,
546
- submitHandler: l
601
+ initialData: U(a, "initialData"),
602
+ data: U(a, "data"),
603
+ submitHandler: (c) => L(v, r)(c),
604
+ getSubForm: (c, i) => Me(v, c, r),
605
+ useFieldArray: (c, i) => G(v, c, i)
547
606
  };
607
+ return v;
548
608
  }
549
- const ke = /* @__PURE__ */ x({
609
+ const Ce = /* @__PURE__ */ C({
550
610
  __name: "Field",
551
611
  props: {
552
612
  form: {},
@@ -558,13 +618,13 @@ const ke = /* @__PURE__ */ x({
558
618
  onBlur: { type: Function },
559
619
  onFocus: { type: Function }
560
620
  },
561
- setup(t) {
562
- const e = t, r = e.form.defineField({
563
- path: e.path
564
- }), a = _(r);
565
- return (s, n) => $(s.$slots, "default", M(N(a)));
621
+ setup(r) {
622
+ const t = r, e = t.form.defineField({
623
+ path: t.path
624
+ }), a = A(e);
625
+ return (s, n) => k(s.$slots, "default", T(N(a)));
566
626
  }
567
- }), xe = /* @__PURE__ */ x({
627
+ }), Te = /* @__PURE__ */ C({
568
628
  inheritAttrs: !1,
569
629
  __name: "FormFieldWrapper",
570
630
  props: {
@@ -573,29 +633,29 @@ const ke = /* @__PURE__ */ x({
573
633
  form: {},
574
634
  path: {}
575
635
  },
576
- setup(t) {
577
- return (e, r) => {
636
+ setup(r) {
637
+ return (t, e) => {
578
638
  const a = ie("Field");
579
- return K(), H(a, {
580
- form: t.form,
581
- path: t.path
639
+ return H(), z(a, {
640
+ form: r.form,
641
+ path: r.path
582
642
  }, {
583
643
  default: B(({ errors: s, data: n, setData: f }) => [
584
- (K(), H(oe(t.component), le({ ...t.componentProps, ...e.$attrs }, {
644
+ (H(), z(oe(r.component), le({ ...r.componentProps, ...t.$attrs }, {
585
645
  "model-value": n,
586
646
  errors: s,
587
- name: t.path,
647
+ name: r.path,
588
648
  "onUpdate:modelValue": f
589
649
  }), ce({
590
650
  default: B(() => [
591
- $(e.$slots, "default")
651
+ k(t.$slots, "default")
592
652
  ]),
593
653
  _: 2
594
654
  }, [
595
- ue(e.$slots, (p, F) => ({
596
- name: F,
597
- fn: B((V) => [
598
- $(e.$slots, F, M(N(V ?? {})))
655
+ ue(t.$slots, (p, v) => ({
656
+ name: v,
657
+ fn: B((c) => [
658
+ k(t.$slots, v, T(N(c ?? {})))
599
659
  ])
600
660
  }))
601
661
  ]), 1040, ["model-value", "errors", "name", "onUpdate:modelValue"]))
@@ -604,20 +664,20 @@ const ke = /* @__PURE__ */ x({
604
664
  }, 8, ["form", "path"]);
605
665
  };
606
666
  }
607
- }), Me = /* @__PURE__ */ x({
667
+ }), Ne = /* @__PURE__ */ C({
608
668
  __name: "FormPart",
609
669
  props: {
610
670
  form: {},
611
671
  path: {}
612
672
  },
613
- setup(t) {
614
- const e = t, r = v(() => e.form.getSubForm(e.path));
615
- return (a, s) => $(a.$slots, "default", M(N({ subform: r.value })));
673
+ setup(r) {
674
+ const t = r, e = V(() => t.form.getSubForm(t.path));
675
+ return (a, s) => k(a.$slots, "default", T(N({ subform: e.value })));
616
676
  }
617
677
  });
618
678
  export {
619
- ke as Field,
620
- xe as FormFieldWrapper,
621
- Me as FormPart,
622
- Ue as useForm
679
+ Ce as Field,
680
+ Te as FormFieldWrapper,
681
+ Ne as FormPart,
682
+ Oe as useForm
623
683
  };