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