@teamnovu/kit-vue-forms 0.1.15 → 0.1.16

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