@teamnovu/kit-vue-forms 0.2.17 → 0.3.0

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