@teamnovu/kit-vue-forms 0.2.8 → 0.2.9
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/index.js +180 -183
- package/package.json +1 -1
- package/src/components/FormFieldWrapper.vue +1 -0
package/dist/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
var X = Object.defineProperty;
|
|
2
2
|
var Y = (r, t, e) => t in r ? X(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
|
|
3
3
|
var R = (r, t, e) => Y(r, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
-
import { toValue as ee, toRaw as te, unref as h, shallowRef as b, watch as D, computed as
|
|
5
|
-
import { cloneDeep as
|
|
4
|
+
import { toValue as ee, toRaw as te, unref as h, shallowRef as b, watch as D, computed as m, isRef as _, reactive as A, toRefs as K, shallowReactive as re, toRef as j, onScopeDispose as ae, triggerRef as se, ref as L, getCurrentScope as ne, onBeforeUnmount as ie, defineComponent as T, renderSlot as k, normalizeProps as x, guardReactiveProps as C, createBlock as z, openBlock as H, withCtx as U, 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(r) {
|
|
8
8
|
const t = ee(r), e = te(t);
|
|
9
|
-
return
|
|
9
|
+
return de(e);
|
|
10
10
|
}
|
|
11
|
-
function
|
|
11
|
+
function fe(r) {
|
|
12
12
|
return r.filter(
|
|
13
13
|
(t, e, a) => a.indexOf(t) === e
|
|
14
14
|
);
|
|
@@ -23,10 +23,10 @@ function J(...r) {
|
|
|
23
23
|
if (!a)
|
|
24
24
|
return t;
|
|
25
25
|
const s = (t ?? []).concat(e);
|
|
26
|
-
return
|
|
26
|
+
return fe(s);
|
|
27
27
|
}, r[0]);
|
|
28
28
|
}
|
|
29
|
-
function
|
|
29
|
+
function he(...r) {
|
|
30
30
|
return r.map((e) => Object.keys(e)).flat().reduce((e, a) => {
|
|
31
31
|
const s = r.map((n) => n[a]).filter(Boolean);
|
|
32
32
|
return {
|
|
@@ -35,7 +35,7 @@ function pe(...r) {
|
|
|
35
35
|
};
|
|
36
36
|
}, {});
|
|
37
37
|
}
|
|
38
|
-
function
|
|
38
|
+
function B(...r) {
|
|
39
39
|
if (!r.length)
|
|
40
40
|
return {
|
|
41
41
|
general: [],
|
|
@@ -45,7 +45,7 @@ function j(...r) {
|
|
|
45
45
|
return r.length === 1 ? t : r.slice(1).reduce(
|
|
46
46
|
(e, a) => ({
|
|
47
47
|
general: J(e.general, a.general),
|
|
48
|
-
propertyErrors:
|
|
48
|
+
propertyErrors: he(e.propertyErrors ?? {}, a.propertyErrors ?? {})
|
|
49
49
|
}),
|
|
50
50
|
t
|
|
51
51
|
);
|
|
@@ -71,7 +71,7 @@ function Z(r, t) {
|
|
|
71
71
|
await e(u);
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
|
-
class
|
|
74
|
+
class pe {
|
|
75
75
|
constructor(t = (e) => e) {
|
|
76
76
|
R(this, "weakMap", /* @__PURE__ */ new WeakMap());
|
|
77
77
|
R(this, "map", /* @__PURE__ */ new Map());
|
|
@@ -94,30 +94,30 @@ class ve {
|
|
|
94
94
|
this.isReferenceType(a) ? this.weakMap.set(a, e) : this.map.set(a, e);
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
-
function
|
|
97
|
+
function ve(r, t, e) {
|
|
98
98
|
const a = /* @__PURE__ */ new Set();
|
|
99
99
|
return t.map((s, n) => {
|
|
100
|
-
const u = [...r.get(s) ?? []],
|
|
100
|
+
const u = [...r.get(s) ?? []], v = u.findIndex((p) => !a.has(p)), c = (v === -1 ? [] : u.slice(v))[0];
|
|
101
101
|
if (c)
|
|
102
102
|
return a.add(c), {
|
|
103
103
|
id: c,
|
|
104
104
|
item: s,
|
|
105
105
|
path: `${e}.${n}`
|
|
106
106
|
};
|
|
107
|
-
const
|
|
108
|
-
return r.set(s, u.concat([
|
|
109
|
-
id:
|
|
107
|
+
const i = crypto.randomUUID();
|
|
108
|
+
return r.set(s, u.concat([i])), a.add(i), {
|
|
109
|
+
id: i,
|
|
110
110
|
item: s,
|
|
111
111
|
path: `${e}.${n}`
|
|
112
112
|
};
|
|
113
113
|
});
|
|
114
114
|
}
|
|
115
115
|
function q(r, t, e) {
|
|
116
|
-
const a = new
|
|
116
|
+
const a = new pe(e == null ? void 0 : e.hashFn), s = r.getField(t), n = b([]);
|
|
117
117
|
return D(
|
|
118
118
|
s.data,
|
|
119
119
|
(c) => {
|
|
120
|
-
n.value =
|
|
120
|
+
n.value = ve(a, c, t);
|
|
121
121
|
},
|
|
122
122
|
{
|
|
123
123
|
immediate: !0,
|
|
@@ -126,22 +126,22 @@ function q(r, t, e) {
|
|
|
126
126
|
), {
|
|
127
127
|
items: n,
|
|
128
128
|
push: (c) => {
|
|
129
|
-
const
|
|
130
|
-
return s.setData([...
|
|
129
|
+
const i = s.data.value ?? [];
|
|
130
|
+
return s.setData([...i, c]), n.value.at(-1);
|
|
131
131
|
},
|
|
132
132
|
remove: (c) => {
|
|
133
|
-
const
|
|
134
|
-
({ id:
|
|
133
|
+
const i = s.data.value ?? [], p = n.value.findIndex(
|
|
134
|
+
({ id: o }) => o === c
|
|
135
135
|
);
|
|
136
136
|
p !== -1 && s.setData(
|
|
137
|
-
|
|
137
|
+
i.slice(0, p).concat(i.slice(p + 1))
|
|
138
138
|
);
|
|
139
139
|
},
|
|
140
|
-
insert: (c,
|
|
140
|
+
insert: (c, i) => {
|
|
141
141
|
const p = s.data.value ?? [];
|
|
142
142
|
return s.setData(
|
|
143
|
-
p.slice(0,
|
|
144
|
-
), n.value[
|
|
143
|
+
p.slice(0, i).concat([c]).concat(p.slice(i))
|
|
144
|
+
), n.value[i];
|
|
145
145
|
},
|
|
146
146
|
field: s
|
|
147
147
|
};
|
|
@@ -149,7 +149,7 @@ function q(r, t, e) {
|
|
|
149
149
|
function W(r) {
|
|
150
150
|
return r === "" ? [] : r.split(/\s*\.\s*/).filter(Boolean);
|
|
151
151
|
}
|
|
152
|
-
function
|
|
152
|
+
function me(r, t) {
|
|
153
153
|
const e = Array.isArray(t) ? t : W(t);
|
|
154
154
|
return !!I(r, e.slice(0, -1));
|
|
155
155
|
}
|
|
@@ -163,18 +163,18 @@ function ye(r, t, e) {
|
|
|
163
163
|
const a = Array.isArray(t) ? t : W(t), s = a.at(-1);
|
|
164
164
|
if (s) {
|
|
165
165
|
const n = a.slice(0, -1).reduce(
|
|
166
|
-
(u,
|
|
166
|
+
(u, v) => ((u == null ? void 0 : u[v]) === void 0 && (u[v] = {}), u == null ? void 0 : u[v]),
|
|
167
167
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
168
168
|
h(r)
|
|
169
169
|
);
|
|
170
170
|
n[s] = e;
|
|
171
171
|
} else {
|
|
172
|
-
if (!
|
|
172
|
+
if (!_(r))
|
|
173
173
|
return;
|
|
174
174
|
r.value = e;
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
|
-
const Q = (r, t) =>
|
|
177
|
+
const Q = (r, t) => m({
|
|
178
178
|
get() {
|
|
179
179
|
return I(h(r), h(t));
|
|
180
180
|
},
|
|
@@ -185,7 +185,7 @@ const Q = (r, t) => v({
|
|
|
185
185
|
function $(r, t) {
|
|
186
186
|
return !r && !t ? "" : !r && t ? t : !t && r ? r : `${r}.${t}`;
|
|
187
187
|
}
|
|
188
|
-
function
|
|
188
|
+
function Fe(r, t) {
|
|
189
189
|
if (!t)
|
|
190
190
|
return r;
|
|
191
191
|
const e = `${t}.`, a = Object.fromEntries(
|
|
@@ -200,7 +200,7 @@ function Ve(r, t) {
|
|
|
200
200
|
propertyErrors: a
|
|
201
201
|
};
|
|
202
202
|
}
|
|
203
|
-
class
|
|
203
|
+
class Ve {
|
|
204
204
|
constructor(t) {
|
|
205
205
|
R(this, "rc", 1);
|
|
206
206
|
this.drop = t;
|
|
@@ -212,7 +212,7 @@ class ge {
|
|
|
212
212
|
this.rc > 0 && (this.rc -= 1, this.rc === 0 && this.drop && this.drop());
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
|
-
function
|
|
215
|
+
function ge(r) {
|
|
216
216
|
const e = {
|
|
217
217
|
...{
|
|
218
218
|
existsInForm: !0
|
|
@@ -232,22 +232,22 @@ function we(r) {
|
|
|
232
232
|
},
|
|
233
233
|
{ flush: "sync" }
|
|
234
234
|
);
|
|
235
|
-
const n =
|
|
235
|
+
const n = m(() => JSON.stringify(s.value) !== JSON.stringify(s.initialValue)), u = (f) => {
|
|
236
236
|
s.value = f;
|
|
237
|
-
},
|
|
237
|
+
}, v = () => {
|
|
238
238
|
var f;
|
|
239
239
|
s.touched = !0, s.errors = [], (f = e.onBlur) == null || f.call(e);
|
|
240
|
-
},
|
|
240
|
+
}, F = () => {
|
|
241
241
|
var f;
|
|
242
242
|
(f = e.onFocus) == null || f.call(e);
|
|
243
243
|
}, c = () => {
|
|
244
244
|
const f = s.path.split(".").at(-1) || "";
|
|
245
245
|
h(e.existsInForm) && !/^\d+$/.test(f) && (s.value = g(s.initialValue)), s.touched = !1, s.errors = [];
|
|
246
|
-
},
|
|
246
|
+
}, i = (f) => {
|
|
247
247
|
n.value || u(g(f)), s.initialValue = f;
|
|
248
248
|
}, p = (f) => {
|
|
249
249
|
s.errors = f;
|
|
250
|
-
},
|
|
250
|
+
}, o = () => {
|
|
251
251
|
s.errors = [];
|
|
252
252
|
}, l = K(s);
|
|
253
253
|
return {
|
|
@@ -258,18 +258,18 @@ function we(r) {
|
|
|
258
258
|
touched: l.touched,
|
|
259
259
|
dirty: n,
|
|
260
260
|
setData: u,
|
|
261
|
-
setInitialData:
|
|
262
|
-
onBlur:
|
|
263
|
-
onFocus:
|
|
261
|
+
setInitialData: i,
|
|
262
|
+
onBlur: v,
|
|
263
|
+
onFocus: F,
|
|
264
264
|
reset: c,
|
|
265
265
|
setErrors: p,
|
|
266
|
-
clearErrors:
|
|
266
|
+
clearErrors: o
|
|
267
267
|
};
|
|
268
268
|
}
|
|
269
|
-
const
|
|
269
|
+
const we = {
|
|
270
270
|
keepValuesOnUnmount: !0
|
|
271
271
|
};
|
|
272
|
-
function
|
|
272
|
+
function Ee(r, t) {
|
|
273
273
|
const e = () => I(r.initialData, t), a = b(e());
|
|
274
274
|
return D(
|
|
275
275
|
() => r.initialData,
|
|
@@ -279,31 +279,31 @@ function Re(r, t) {
|
|
|
279
279
|
{ flush: "sync" }
|
|
280
280
|
), a;
|
|
281
281
|
}
|
|
282
|
-
function
|
|
282
|
+
function Re(r, t, e) {
|
|
283
283
|
const a = /* @__PURE__ */ new Map(), s = re(/* @__PURE__ */ new Map()), n = {
|
|
284
|
-
...
|
|
284
|
+
...we,
|
|
285
285
|
...e
|
|
286
|
-
}, u = (
|
|
287
|
-
const l = h(
|
|
288
|
-
s.set(l,
|
|
289
|
-
},
|
|
286
|
+
}, u = (o) => {
|
|
287
|
+
const l = h(o.path);
|
|
288
|
+
s.set(l, o);
|
|
289
|
+
}, v = (o) => {
|
|
290
290
|
var l;
|
|
291
|
-
n != null && n.keepValuesOnUnmount || (l = s.get(
|
|
292
|
-
},
|
|
291
|
+
n != null && n.keepValuesOnUnmount || (l = s.get(o)) == null || l.reset(), s.delete(o);
|
|
292
|
+
}, F = (o) => {
|
|
293
293
|
var l;
|
|
294
|
-
a.has(
|
|
295
|
-
}, c = (
|
|
294
|
+
a.has(o) ? (l = a.get(o)) == null || l.inc() : a.set(o, new Ve(() => v(o)));
|
|
295
|
+
}, c = (o) => {
|
|
296
296
|
var l;
|
|
297
|
-
a.has(
|
|
298
|
-
},
|
|
299
|
-
const { path: l } =
|
|
297
|
+
a.has(o) && ((l = a.get(o)) == null || l.dec());
|
|
298
|
+
}, i = (o) => {
|
|
299
|
+
const { path: l } = o;
|
|
300
300
|
if (!s.has(l)) {
|
|
301
|
-
const S =
|
|
301
|
+
const S = ge({
|
|
302
302
|
path: l,
|
|
303
|
-
value: Q(
|
|
304
|
-
initialValue:
|
|
305
|
-
existsInForm:
|
|
306
|
-
errors:
|
|
303
|
+
value: Q(j(r, "data"), l),
|
|
304
|
+
initialValue: Ee(r, l),
|
|
305
|
+
existsInForm: m(() => me(r.data, h(l))),
|
|
306
|
+
errors: m({
|
|
307
307
|
get() {
|
|
308
308
|
return t.errors.value.propertyErrors[l] || [];
|
|
309
309
|
},
|
|
@@ -315,40 +315,40 @@ function De(r, t, e) {
|
|
|
315
315
|
var w, P;
|
|
316
316
|
await Promise.all([
|
|
317
317
|
(w = n == null ? void 0 : n.onBlur) == null ? void 0 : w.call(n, h(l)),
|
|
318
|
-
(P =
|
|
318
|
+
(P = o.onBlur) == null ? void 0 : P.call(o)
|
|
319
319
|
]);
|
|
320
320
|
},
|
|
321
321
|
onFocus: async () => {
|
|
322
322
|
var w, P;
|
|
323
323
|
await Promise.all([
|
|
324
324
|
(w = n == null ? void 0 : n.onFocus) == null ? void 0 : w.call(n, h(l)),
|
|
325
|
-
(P =
|
|
325
|
+
(P = o.onFocus) == null ? void 0 : P.call(o)
|
|
326
326
|
]);
|
|
327
327
|
}
|
|
328
328
|
});
|
|
329
329
|
u(S);
|
|
330
330
|
}
|
|
331
331
|
const f = s.get(l);
|
|
332
|
-
return
|
|
332
|
+
return F(l), ae(() => {
|
|
333
333
|
c(l);
|
|
334
334
|
}), f;
|
|
335
|
-
}, p = (
|
|
335
|
+
}, p = (o) => i(o);
|
|
336
336
|
return {
|
|
337
|
-
fields:
|
|
338
|
-
getField: (
|
|
337
|
+
fields: m(() => [...s.values()]),
|
|
338
|
+
getField: (o) => i({ path: o }),
|
|
339
339
|
registerField: u,
|
|
340
|
-
deregisterField:
|
|
340
|
+
deregisterField: v,
|
|
341
341
|
defineField: p
|
|
342
342
|
};
|
|
343
343
|
}
|
|
344
|
-
function
|
|
345
|
-
const t =
|
|
344
|
+
function De(r) {
|
|
345
|
+
const t = m(() => r.fields.value.some((a) => h(a.dirty))), e = m(() => r.fields.value.some((a) => h(a.touched)));
|
|
346
346
|
return {
|
|
347
347
|
isDirty: t,
|
|
348
348
|
isTouched: e
|
|
349
349
|
};
|
|
350
350
|
}
|
|
351
|
-
function
|
|
351
|
+
function Pe(r) {
|
|
352
352
|
const t = r.issues.filter((a) => a.path.length === 0).map((a) => a.message), e = r.issues.filter((a) => a.path.length > 0).reduce((a, s) => {
|
|
353
353
|
const n = s.path.join(".");
|
|
354
354
|
return {
|
|
@@ -367,7 +367,7 @@ const V = {
|
|
|
367
367
|
propertyErrors: {}
|
|
368
368
|
}
|
|
369
369
|
};
|
|
370
|
-
class
|
|
370
|
+
class Se {
|
|
371
371
|
constructor(t) {
|
|
372
372
|
this.schema = t;
|
|
373
373
|
}
|
|
@@ -377,7 +377,7 @@ class Ie {
|
|
|
377
377
|
const e = await this.schema.safeParseAsync(t);
|
|
378
378
|
if (e.success)
|
|
379
379
|
return V;
|
|
380
|
-
const a =
|
|
380
|
+
const a = Pe(e.error);
|
|
381
381
|
return {
|
|
382
382
|
data: e.data,
|
|
383
383
|
errors: {
|
|
@@ -387,7 +387,7 @@ class Ie {
|
|
|
387
387
|
};
|
|
388
388
|
}
|
|
389
389
|
}
|
|
390
|
-
class
|
|
390
|
+
class Ie {
|
|
391
391
|
constructor(t) {
|
|
392
392
|
this.validateFn = t;
|
|
393
393
|
}
|
|
@@ -407,11 +407,11 @@ class $e {
|
|
|
407
407
|
}
|
|
408
408
|
}
|
|
409
409
|
}
|
|
410
|
-
class
|
|
410
|
+
class $e {
|
|
411
411
|
constructor(t, e) {
|
|
412
412
|
R(this, "schemaValidator");
|
|
413
413
|
R(this, "functionValidator");
|
|
414
|
-
this.schema = t, this.validateFn = e, this.schemaValidator = new
|
|
414
|
+
this.schema = t, this.validateFn = e, this.schemaValidator = new Se(this.schema), this.functionValidator = new Ie(this.validateFn);
|
|
415
415
|
}
|
|
416
416
|
async validate(t) {
|
|
417
417
|
const [e, a] = await Promise.all([
|
|
@@ -420,35 +420,35 @@ class be {
|
|
|
420
420
|
]);
|
|
421
421
|
return {
|
|
422
422
|
data: e.data,
|
|
423
|
-
errors:
|
|
423
|
+
errors: B(e.errors, a.errors)
|
|
424
424
|
};
|
|
425
425
|
}
|
|
426
426
|
}
|
|
427
|
-
function
|
|
428
|
-
return
|
|
427
|
+
function O(r) {
|
|
428
|
+
return m(() => new $e(
|
|
429
429
|
h(r.schema),
|
|
430
430
|
h(r.validateFn)
|
|
431
431
|
));
|
|
432
432
|
}
|
|
433
|
-
function
|
|
433
|
+
function be(r, t) {
|
|
434
434
|
const e = A({
|
|
435
|
-
validators: L([
|
|
435
|
+
validators: L([O(t)]),
|
|
436
436
|
isValidated: !1,
|
|
437
437
|
errors: h(t.errors) ?? V.errors
|
|
438
|
-
}), a = (
|
|
439
|
-
e.errors =
|
|
438
|
+
}), a = (i = V.errors) => {
|
|
439
|
+
e.errors = B(h(t.errors) ?? V.errors, i);
|
|
440
440
|
};
|
|
441
441
|
D(() => h(t.errors), async () => {
|
|
442
442
|
if (e.isValidated) {
|
|
443
|
-
const
|
|
444
|
-
a(
|
|
443
|
+
const i = await n();
|
|
444
|
+
a(i.errors);
|
|
445
445
|
} else
|
|
446
446
|
a();
|
|
447
447
|
}, { immediate: !0 }), D(
|
|
448
448
|
[() => e.validators],
|
|
449
|
-
async (
|
|
449
|
+
async (i) => {
|
|
450
450
|
if (e.isValidated)
|
|
451
|
-
if (
|
|
451
|
+
if (i) {
|
|
452
452
|
const p = await n();
|
|
453
453
|
e.errors = p.errors;
|
|
454
454
|
} else
|
|
@@ -458,59 +458,59 @@ function ke(r, t) {
|
|
|
458
458
|
), D([() => r.data, () => h(t.schema)], () => {
|
|
459
459
|
e.isValidated && u();
|
|
460
460
|
});
|
|
461
|
-
const s = (
|
|
462
|
-
const p =
|
|
463
|
-
return e.validators.push(p), ne() &&
|
|
461
|
+
const s = (i) => {
|
|
462
|
+
const p = _(i) ? i : O(i);
|
|
463
|
+
return e.validators.push(p), ne() && ie(() => {
|
|
464
464
|
e.validators = e.validators.filter(
|
|
465
|
-
(
|
|
465
|
+
(o) => o !== p
|
|
466
466
|
);
|
|
467
467
|
}), p;
|
|
468
468
|
};
|
|
469
469
|
async function n() {
|
|
470
470
|
var l;
|
|
471
|
-
const
|
|
471
|
+
const i = await Promise.all(
|
|
472
472
|
e.validators.filter((f) => h(f) !== void 0).map((f) => h(f).validate(r.data))
|
|
473
|
-
), p =
|
|
474
|
-
let { errors:
|
|
473
|
+
), p = i.every((f) => N(f));
|
|
474
|
+
let { errors: o } = V;
|
|
475
475
|
if (!p) {
|
|
476
|
-
const f =
|
|
477
|
-
|
|
476
|
+
const f = i.map((S) => S.errors);
|
|
477
|
+
o = B(...f);
|
|
478
478
|
}
|
|
479
479
|
return {
|
|
480
|
-
errors:
|
|
480
|
+
errors: o,
|
|
481
481
|
// TODO: Implement data disambiguation strategy
|
|
482
|
-
data: (l =
|
|
482
|
+
data: (l = i.findLast((f) => !!f.data)) == null ? void 0 : l.data
|
|
483
483
|
};
|
|
484
484
|
}
|
|
485
485
|
const u = async () => {
|
|
486
|
-
const
|
|
487
|
-
return a(
|
|
486
|
+
const i = await n();
|
|
487
|
+
return a(i.errors), e.isValidated = !0, {
|
|
488
488
|
errors: e.errors
|
|
489
489
|
};
|
|
490
|
-
},
|
|
490
|
+
}, v = async (i) => {
|
|
491
491
|
const p = await n();
|
|
492
492
|
return a({
|
|
493
493
|
general: p.errors.general,
|
|
494
494
|
propertyErrors: {
|
|
495
|
-
[
|
|
495
|
+
[i]: p.errors.propertyErrors[i]
|
|
496
496
|
}
|
|
497
497
|
}), {
|
|
498
498
|
data: p.data,
|
|
499
499
|
errors: e.errors
|
|
500
500
|
};
|
|
501
|
-
},
|
|
501
|
+
}, F = m(() => !G(e.errors)), c = () => {
|
|
502
502
|
e.isValidated = !1, e.errors = h(t.errors) ?? V.errors;
|
|
503
503
|
};
|
|
504
504
|
return {
|
|
505
505
|
...K(e),
|
|
506
506
|
validateForm: u,
|
|
507
|
-
validateField:
|
|
507
|
+
validateField: v,
|
|
508
508
|
defineValidator: s,
|
|
509
|
-
isValid:
|
|
509
|
+
isValid: F,
|
|
510
510
|
reset: c
|
|
511
511
|
};
|
|
512
512
|
}
|
|
513
|
-
class
|
|
513
|
+
class ke {
|
|
514
514
|
constructor(t, e) {
|
|
515
515
|
this.path = t, this.validator = e;
|
|
516
516
|
}
|
|
@@ -531,61 +531,61 @@ class Ae {
|
|
|
531
531
|
};
|
|
532
532
|
}
|
|
533
533
|
}
|
|
534
|
-
function
|
|
535
|
-
const s = Q(r.data, t), n =
|
|
534
|
+
function Ae(r, t, e, a) {
|
|
535
|
+
const s = Q(r.data, t), n = m(() => I(r.initialData.value, t)), u = (d) => ({
|
|
536
536
|
...d,
|
|
537
|
-
path:
|
|
538
|
-
setData: (
|
|
539
|
-
d.setData(
|
|
537
|
+
path: m(() => h(d.path).replace(t + ".", "")),
|
|
538
|
+
setData: (y) => {
|
|
539
|
+
d.setData(y);
|
|
540
540
|
}
|
|
541
|
-
}),
|
|
542
|
-
const
|
|
541
|
+
}), v = (d) => {
|
|
542
|
+
const y = $(t, d), E = r.getField(y);
|
|
543
543
|
return E ? u(E) : {};
|
|
544
|
-
},
|
|
545
|
-
const
|
|
544
|
+
}, F = (d) => {
|
|
545
|
+
const y = $(t, d.path), E = r.defineField({
|
|
546
546
|
...d,
|
|
547
|
-
path:
|
|
547
|
+
path: y
|
|
548
548
|
});
|
|
549
549
|
return u(E);
|
|
550
|
-
}, c =
|
|
551
|
-
const
|
|
552
|
-
return
|
|
553
|
-
}).map((d) => u(d))),
|
|
554
|
-
const
|
|
555
|
-
return
|
|
556
|
-
}), p =
|
|
550
|
+
}, c = m(() => r.fields.value.filter((d) => {
|
|
551
|
+
const y = d.path.value;
|
|
552
|
+
return y.startsWith(t + ".") || y === t;
|
|
553
|
+
}).map((d) => u(d))), i = () => r.fields.value.filter((d) => {
|
|
554
|
+
const y = d.path.value;
|
|
555
|
+
return y.startsWith(t + ".") || y === t;
|
|
556
|
+
}), p = m(() => i().some((d) => d.dirty.value)), o = m(() => i().some((d) => d.touched.value)), l = m(() => r.isValid.value), f = m(() => r.isValidated.value), S = m(() => Fe(h(r.errors), t)), M = {
|
|
557
557
|
data: s,
|
|
558
558
|
fields: c,
|
|
559
559
|
initialData: n,
|
|
560
|
-
defineField:
|
|
561
|
-
getField:
|
|
560
|
+
defineField: F,
|
|
561
|
+
getField: v,
|
|
562
562
|
isDirty: p,
|
|
563
|
-
isTouched:
|
|
563
|
+
isTouched: o,
|
|
564
564
|
isValid: l,
|
|
565
565
|
isValidated: f,
|
|
566
566
|
errors: S,
|
|
567
567
|
defineValidator: (d) => {
|
|
568
|
-
const
|
|
569
|
-
() => new
|
|
568
|
+
const y = _(d) ? d : O(d), E = m(
|
|
569
|
+
() => new ke(t, h(y))
|
|
570
570
|
);
|
|
571
|
-
return r.defineValidator(E),
|
|
571
|
+
return r.defineValidator(E), y;
|
|
572
572
|
},
|
|
573
|
-
reset: () =>
|
|
573
|
+
reset: () => i().forEach((d) => d.reset()),
|
|
574
574
|
validateForm: () => r.validateForm(),
|
|
575
|
-
getSubForm: (d,
|
|
575
|
+
getSubForm: (d, y) => {
|
|
576
576
|
const E = $(t, d);
|
|
577
577
|
return r.getSubForm(
|
|
578
578
|
E,
|
|
579
|
-
|
|
579
|
+
y
|
|
580
580
|
);
|
|
581
581
|
},
|
|
582
582
|
submitHandler: (d) => Z(M, e ?? {})(d),
|
|
583
|
-
getFieldArray: (d,
|
|
583
|
+
getFieldArray: (d, y) => q(M, d, y)
|
|
584
584
|
};
|
|
585
585
|
return M;
|
|
586
586
|
}
|
|
587
|
-
function
|
|
588
|
-
const t =
|
|
587
|
+
function xe(r) {
|
|
588
|
+
const t = m(() => g(r.initialData)), e = L(g(t)), a = A({
|
|
589
589
|
initialData: t,
|
|
590
590
|
data: e
|
|
591
591
|
});
|
|
@@ -596,32 +596,32 @@ function Te(r) {
|
|
|
596
596
|
},
|
|
597
597
|
{ flush: "sync" }
|
|
598
598
|
);
|
|
599
|
-
const s =
|
|
599
|
+
const s = be(a, r), n = Re(a, s, {
|
|
600
600
|
keepValuesOnUnmount: r.keepValuesOnUnmount,
|
|
601
601
|
onBlur: async (c) => {
|
|
602
602
|
h(r.validationStrategy) === "onTouch" && s.validateField(c);
|
|
603
603
|
}
|
|
604
|
-
}), u =
|
|
604
|
+
}), u = De(n), v = () => {
|
|
605
605
|
e.value = g(t), s.reset();
|
|
606
606
|
for (const c of n.fields.value)
|
|
607
607
|
c.reset();
|
|
608
608
|
};
|
|
609
609
|
h(r.validationStrategy) === "onFormOpen" && s.validateForm();
|
|
610
|
-
const
|
|
610
|
+
const F = {
|
|
611
611
|
...n,
|
|
612
612
|
...s,
|
|
613
613
|
...u,
|
|
614
|
-
reset:
|
|
615
|
-
initialData:
|
|
616
|
-
data:
|
|
614
|
+
reset: v,
|
|
615
|
+
initialData: j(a, "initialData"),
|
|
616
|
+
data: j(a, "data"),
|
|
617
617
|
validateForm: s.validateForm,
|
|
618
|
-
submitHandler: (c) => Z(
|
|
619
|
-
getSubForm: (c,
|
|
620
|
-
getFieldArray: (c,
|
|
618
|
+
submitHandler: (c) => Z(F, r)(c),
|
|
619
|
+
getSubForm: (c, i) => Ae(F, c, r),
|
|
620
|
+
getFieldArray: (c, i) => q(F, c, i)
|
|
621
621
|
};
|
|
622
|
-
return
|
|
622
|
+
return F;
|
|
623
623
|
}
|
|
624
|
-
const
|
|
624
|
+
const Me = /* @__PURE__ */ T({
|
|
625
625
|
__name: "Field",
|
|
626
626
|
props: {
|
|
627
627
|
form: {},
|
|
@@ -637,9 +637,9 @@ const xe = /* @__PURE__ */ C({
|
|
|
637
637
|
const t = r, e = t.form.defineField({
|
|
638
638
|
path: t.path
|
|
639
639
|
}), a = A(e);
|
|
640
|
-
return (s, n) => k(s.$slots, "default",
|
|
640
|
+
return (s, n) => k(s.$slots, "default", x(C(a)));
|
|
641
641
|
}
|
|
642
|
-
}),
|
|
642
|
+
}), Ce = /* @__PURE__ */ T({
|
|
643
643
|
inheritAttrs: !1,
|
|
644
644
|
__name: "FormFieldWrapper",
|
|
645
645
|
props: {
|
|
@@ -649,50 +649,47 @@ const xe = /* @__PURE__ */ C({
|
|
|
649
649
|
path: {}
|
|
650
650
|
},
|
|
651
651
|
setup(r) {
|
|
652
|
-
return (t, e) => {
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
_: 3
|
|
679
|
-
}, 8, ["form", "path"]);
|
|
680
|
-
};
|
|
652
|
+
return (t, e) => (H(), z(Me, {
|
|
653
|
+
form: r.form,
|
|
654
|
+
path: r.path
|
|
655
|
+
}, {
|
|
656
|
+
default: U(({ errors: a, data: s, setData: n }) => [
|
|
657
|
+
(H(), z(oe(r.component), le({ ...r.componentProps, ...t.$attrs }, {
|
|
658
|
+
"model-value": s,
|
|
659
|
+
errors: a,
|
|
660
|
+
name: r.path,
|
|
661
|
+
"onUpdate:modelValue": n
|
|
662
|
+
}), ce({
|
|
663
|
+
default: U(() => [
|
|
664
|
+
k(t.$slots, "default")
|
|
665
|
+
]),
|
|
666
|
+
_: 2
|
|
667
|
+
}, [
|
|
668
|
+
ue(t.$slots, (u, v) => ({
|
|
669
|
+
name: v,
|
|
670
|
+
fn: U((F) => [
|
|
671
|
+
k(t.$slots, v, x(C(F ?? {})))
|
|
672
|
+
])
|
|
673
|
+
}))
|
|
674
|
+
]), 1040, ["model-value", "errors", "name", "onUpdate:modelValue"]))
|
|
675
|
+
]),
|
|
676
|
+
_: 3
|
|
677
|
+
}, 8, ["form", "path"]));
|
|
681
678
|
}
|
|
682
|
-
}),
|
|
679
|
+
}), Ne = /* @__PURE__ */ T({
|
|
683
680
|
__name: "FormPart",
|
|
684
681
|
props: {
|
|
685
682
|
form: {},
|
|
686
683
|
path: {}
|
|
687
684
|
},
|
|
688
685
|
setup(r) {
|
|
689
|
-
const t = r, e =
|
|
690
|
-
return (a, s) => k(a.$slots, "default",
|
|
686
|
+
const t = r, e = m(() => t.form.getSubForm(t.path));
|
|
687
|
+
return (a, s) => k(a.$slots, "default", x(C({ subform: e.value })));
|
|
691
688
|
}
|
|
692
689
|
});
|
|
693
690
|
export {
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
691
|
+
Me as Field,
|
|
692
|
+
Ce as FormFieldWrapper,
|
|
693
|
+
Ne as FormPart,
|
|
694
|
+
xe as useForm
|
|
698
695
|
};
|
package/package.json
CHANGED
|
@@ -39,6 +39,7 @@ import { type Component } from 'vue'
|
|
|
39
39
|
import type { ComponentProps } from 'vue-component-type-helpers'
|
|
40
40
|
import type { Paths } from '../types/util.ts'
|
|
41
41
|
import type { Form, FormDataDefault } from '../types/form.ts'
|
|
42
|
+
import Field from './Field.vue'
|
|
42
43
|
|
|
43
44
|
export interface FormFieldWrapperProps<
|
|
44
45
|
TData extends FormDataDefault,
|