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