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