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