@teamnovu/kit-vue-forms 0.1.13 → 0.1.15

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