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