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