@teamnovu/kit-vue-forms 0.1.15 → 0.1.17

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