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