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