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