@teamnovu/kit-vue-forms 0.1.21 → 0.1.23

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