@teamnovu/kit-vue-forms 0.2.8 → 0.2.10
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 +145 -146
- package/package.json +1 -1
- package/src/components/FormFieldWrapper.vue +4 -1
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
|
|
5
|
-
import { cloneDeep as
|
|
4
|
+
import { toValue as ee, toRaw as te, unref as h, shallowRef as $, 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 oe, defineComponent as T, renderSlot as k, normalizeProps as x, guardReactiveProps as C, createBlock as z, openBlock as H, withCtx as U, resolveDynamicComponent as ie, 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,10 +94,10 @@ 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,
|
|
@@ -113,11 +113,11 @@ function me(r, t, e) {
|
|
|
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 = $([]);
|
|
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,
|
|
@@ -149,11 +149,11 @@ 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
|
-
return !!
|
|
154
|
+
return !!b(r, e.slice(0, -1));
|
|
155
155
|
}
|
|
156
|
-
function
|
|
156
|
+
function b(r, t) {
|
|
157
157
|
return (Array.isArray(t) ? t : W(t)).reduce(
|
|
158
158
|
(a, s) => a == null ? void 0 : a[s],
|
|
159
159
|
r
|
|
@@ -163,29 +163,29 @@ 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
|
-
return
|
|
179
|
+
return b(h(r), h(t));
|
|
180
180
|
},
|
|
181
181
|
set(e) {
|
|
182
182
|
ye(r, h(t), e);
|
|
183
183
|
}
|
|
184
184
|
});
|
|
185
|
-
function
|
|
185
|
+
function I(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,13 +212,13 @@ 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
|
|
219
219
|
},
|
|
220
220
|
...r
|
|
221
|
-
}, a =
|
|
221
|
+
}, a = $(Object.freeze(g(e.initialValue))), s = A({
|
|
222
222
|
value: e.value,
|
|
223
223
|
path: e.path,
|
|
224
224
|
initialValue: a,
|
|
@@ -226,18 +226,18 @@ function we(r) {
|
|
|
226
226
|
touched: !1
|
|
227
227
|
});
|
|
228
228
|
D(
|
|
229
|
-
|
|
229
|
+
$(e.initialValue),
|
|
230
230
|
() => {
|
|
231
231
|
a.value = Object.freeze(g(e.initialValue)), s.value !== h(e.initialValue) && (s.value = g(e.initialValue));
|
|
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 = () => {
|
|
@@ -259,18 +259,18 @@ function we(r) {
|
|
|
259
259
|
dirty: n,
|
|
260
260
|
setData: u,
|
|
261
261
|
setInitialData: o,
|
|
262
|
-
onBlur:
|
|
263
|
-
onFocus:
|
|
262
|
+
onBlur: v,
|
|
263
|
+
onFocus: F,
|
|
264
264
|
reset: c,
|
|
265
265
|
setErrors: p,
|
|
266
266
|
clearErrors: i
|
|
267
267
|
};
|
|
268
268
|
}
|
|
269
|
-
const
|
|
269
|
+
const we = {
|
|
270
270
|
keepValuesOnUnmount: !0
|
|
271
271
|
};
|
|
272
|
-
function
|
|
273
|
-
const e = () =>
|
|
272
|
+
function Ee(r, t) {
|
|
273
|
+
const e = () => b(r.initialData, t), a = $(e());
|
|
274
274
|
return D(
|
|
275
275
|
() => r.initialData,
|
|
276
276
|
() => {
|
|
@@ -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
286
|
}, u = (i) => {
|
|
287
287
|
const l = h(i.path);
|
|
288
288
|
s.set(l, i);
|
|
289
|
-
},
|
|
289
|
+
}, v = (i) => {
|
|
290
290
|
var l;
|
|
291
291
|
n != null && n.keepValuesOnUnmount || (l = s.get(i)) == null || l.reset(), s.delete(i);
|
|
292
|
-
},
|
|
292
|
+
}, F = (i) => {
|
|
293
293
|
var l;
|
|
294
|
-
a.has(i) ? (l = a.get(i)) == null || l.inc() : a.set(i, new
|
|
294
|
+
a.has(i) ? (l = a.get(i)) == null || l.inc() : a.set(i, new Ve(() => v(i)));
|
|
295
295
|
}, c = (i) => {
|
|
296
296
|
var l;
|
|
297
297
|
a.has(i) && ((l = a.get(i)) == null || l.dec());
|
|
298
298
|
}, o = (i) => {
|
|
299
299
|
const { path: l } = i;
|
|
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
|
},
|
|
@@ -329,26 +329,26 @@ function De(r, t, e) {
|
|
|
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
335
|
}, p = (i) => o(i);
|
|
336
336
|
return {
|
|
337
|
-
fields:
|
|
337
|
+
fields: m(() => [...s.values()]),
|
|
338
338
|
getField: (i) => o({ path: i }),
|
|
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 be {
|
|
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 Ie {
|
|
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 be(this.validateFn);
|
|
415
415
|
}
|
|
416
416
|
async validate(t) {
|
|
417
417
|
const [e, a] = await Promise.all([
|
|
@@ -420,23 +420,23 @@ 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 Ie(
|
|
429
429
|
h(r.schema),
|
|
430
430
|
h(r.validateFn)
|
|
431
431
|
));
|
|
432
432
|
}
|
|
433
|
-
function
|
|
433
|
+
function $e(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
438
|
}), a = (o = V.errors) => {
|
|
439
|
-
e.errors =
|
|
439
|
+
e.errors = B(h(t.errors) ?? V.errors, o);
|
|
440
440
|
};
|
|
441
441
|
D(() => h(t.errors), async () => {
|
|
442
442
|
if (e.isValidated) {
|
|
@@ -459,7 +459,7 @@ function ke(r, t) {
|
|
|
459
459
|
e.isValidated && u();
|
|
460
460
|
});
|
|
461
461
|
const s = (o) => {
|
|
462
|
-
const p =
|
|
462
|
+
const p = _(o) ? o : O(o);
|
|
463
463
|
return e.validators.push(p), ne() && oe(() => {
|
|
464
464
|
e.validators = e.validators.filter(
|
|
465
465
|
(i) => i !== p
|
|
@@ -474,7 +474,7 @@ function ke(r, t) {
|
|
|
474
474
|
let { errors: i } = V;
|
|
475
475
|
if (!p) {
|
|
476
476
|
const f = o.map((S) => S.errors);
|
|
477
|
-
i =
|
|
477
|
+
i = B(...f);
|
|
478
478
|
}
|
|
479
479
|
return {
|
|
480
480
|
errors: i,
|
|
@@ -487,7 +487,7 @@ function ke(r, t) {
|
|
|
487
487
|
return a(o.errors), e.isValidated = !0, {
|
|
488
488
|
errors: e.errors
|
|
489
489
|
};
|
|
490
|
-
},
|
|
490
|
+
}, v = async (o) => {
|
|
491
491
|
const p = await n();
|
|
492
492
|
return a({
|
|
493
493
|
general: p.errors.general,
|
|
@@ -498,24 +498,24 @@ function ke(r, t) {
|
|
|
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
|
}
|
|
517
517
|
async validate(t) {
|
|
518
|
-
const e =
|
|
518
|
+
const e = b(t, this.path);
|
|
519
519
|
if (!this.validator)
|
|
520
520
|
return V;
|
|
521
521
|
const a = await this.validator.validate(e);
|
|
@@ -524,68 +524,68 @@ class Ae {
|
|
|
524
524
|
general: a.errors.general || [],
|
|
525
525
|
propertyErrors: a.errors.propertyErrors ? Object.fromEntries(
|
|
526
526
|
Object.entries(a.errors.propertyErrors).map(
|
|
527
|
-
([s, n]) => [
|
|
527
|
+
([s, n]) => [I(this.path, s), n]
|
|
528
528
|
)
|
|
529
529
|
) : {}
|
|
530
530
|
}
|
|
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(() => b(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 = I(t, d), E = r.getField(y);
|
|
543
543
|
return E ? u(E) : {};
|
|
544
|
-
},
|
|
545
|
-
const
|
|
544
|
+
}, F = (d) => {
|
|
545
|
+
const y = I(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
|
|
550
|
+
}, c = m(() => r.fields.value.filter((d) => {
|
|
551
|
+
const y = d.path.value;
|
|
552
|
+
return y.startsWith(t + ".") || y === t;
|
|
553
553
|
}).map((d) => u(d))), o = () => r.fields.value.filter((d) => {
|
|
554
|
-
const
|
|
555
|
-
return
|
|
556
|
-
}), p =
|
|
554
|
+
const y = d.path.value;
|
|
555
|
+
return y.startsWith(t + ".") || y === t;
|
|
556
|
+
}), p = m(() => o().some((d) => d.dirty.value)), i = m(() => o().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
563
|
isTouched: i,
|
|
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
573
|
reset: () => o().forEach((d) => d.reset()),
|
|
574
574
|
validateForm: () => r.validateForm(),
|
|
575
|
-
getSubForm: (d,
|
|
576
|
-
const E =
|
|
575
|
+
getSubForm: (d, y) => {
|
|
576
|
+
const E = I(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 = $e(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, o) =>
|
|
620
|
-
getFieldArray: (c, o) => q(
|
|
618
|
+
submitHandler: (c) => Z(F, r)(c),
|
|
619
|
+
getSubForm: (c, o) => Ae(F, c, r),
|
|
620
|
+
getFieldArray: (c, o) => q(F, c, o)
|
|
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,49 @@ 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
|
-
|
|
679
|
-
|
|
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, onBlur: u, onFocus: v }) => [
|
|
657
|
+
(H(), z(ie(r.component), le({ ...r.componentProps, ...t.$attrs }, {
|
|
658
|
+
"on-blur": u,
|
|
659
|
+
"on-focus": v,
|
|
660
|
+
"model-value": s,
|
|
661
|
+
errors: a,
|
|
662
|
+
name: r.path,
|
|
663
|
+
"onUpdate:modelValue": n
|
|
664
|
+
}), ce({
|
|
665
|
+
default: U(() => [
|
|
666
|
+
k(t.$slots, "default")
|
|
667
|
+
]),
|
|
668
|
+
_: 2
|
|
669
|
+
}, [
|
|
670
|
+
ue(t.$slots, (F, c) => ({
|
|
671
|
+
name: c,
|
|
672
|
+
fn: U((o) => [
|
|
673
|
+
k(t.$slots, c, x(C(o ?? {})))
|
|
674
|
+
])
|
|
675
|
+
}))
|
|
676
|
+
]), 1040, ["on-blur", "on-focus", "model-value", "errors", "name", "onUpdate:modelValue"]))
|
|
677
|
+
]),
|
|
678
|
+
_: 3
|
|
679
|
+
}, 8, ["form", "path"]));
|
|
681
680
|
}
|
|
682
|
-
}),
|
|
681
|
+
}), Ne = /* @__PURE__ */ T({
|
|
683
682
|
__name: "FormPart",
|
|
684
683
|
props: {
|
|
685
684
|
form: {},
|
|
686
685
|
path: {}
|
|
687
686
|
},
|
|
688
687
|
setup(r) {
|
|
689
|
-
const t = r, e =
|
|
690
|
-
return (a, s) => k(a.$slots, "default",
|
|
688
|
+
const t = r, e = m(() => t.form.getSubForm(t.path));
|
|
689
|
+
return (a, s) => k(a.$slots, "default", x(C({ subform: e.value })));
|
|
691
690
|
}
|
|
692
691
|
});
|
|
693
692
|
export {
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
693
|
+
Me as Field,
|
|
694
|
+
Ce as FormFieldWrapper,
|
|
695
|
+
Ne as FormPart,
|
|
696
|
+
xe as useForm
|
|
698
697
|
};
|
package/package.json
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<Field
|
|
3
|
-
v-slot="{ errors, data, setData }"
|
|
3
|
+
v-slot="{ errors, data, setData, onBlur, onFocus }"
|
|
4
4
|
:form="form"
|
|
5
5
|
:path="path"
|
|
6
6
|
>
|
|
7
7
|
<component
|
|
8
8
|
:is="component"
|
|
9
9
|
v-bind="{...componentProps, ...$attrs}"
|
|
10
|
+
:on-blur="onBlur"
|
|
11
|
+
:on-focus="onFocus"
|
|
10
12
|
:model-value="data"
|
|
11
13
|
:errors="errors"
|
|
12
14
|
:name="path"
|
|
@@ -39,6 +41,7 @@ import { type Component } from 'vue'
|
|
|
39
41
|
import type { ComponentProps } from 'vue-component-type-helpers'
|
|
40
42
|
import type { Paths } from '../types/util.ts'
|
|
41
43
|
import type { Form, FormDataDefault } from '../types/form.ts'
|
|
44
|
+
import Field from './Field.vue'
|
|
42
45
|
|
|
43
46
|
export interface FormFieldWrapperProps<
|
|
44
47
|
TData extends FormDataDefault,
|