@teamnovu/kit-vue-forms 0.0.19 → 0.0.21
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/Field.vue.d.ts +7 -7
- package/dist/index.js +99 -98
- package/package.json +2 -1
- package/src/components/Field.vue +1 -4
- package/src/utils/general.ts +3 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Form } from '../types/form.ts';
|
|
2
2
|
import { Paths, PickProps } from '../types/util.ts';
|
|
3
3
|
import { UseFieldOptions } from '../composables/useField.ts';
|
|
4
|
-
import { VNodeProps, AllowedComponentProps, ComponentCustomProps, PublicProps, ShallowUnwrapRef, VNode } from 'vue';
|
|
4
|
+
import { VNodeProps, AllowedComponentProps, ComponentCustomProps, PublicProps, ShallowUnwrapRef, Ref, VNode } from 'vue';
|
|
5
5
|
import { ValidationErrors, ErrorMessage } from '../index.js';
|
|
6
6
|
export interface FieldProps<TData extends object, TPath extends string> extends UseFieldOptions<PickProps<TData, TPath>, TPath> {
|
|
7
7
|
form: Form<TData>;
|
|
@@ -12,12 +12,12 @@ declare const _default: <TData extends object, TPath extends Paths<TData>>(__VLS
|
|
|
12
12
|
attrs: any;
|
|
13
13
|
slots: {
|
|
14
14
|
default?(_: {
|
|
15
|
-
data: PickProps<TData, TPath
|
|
16
|
-
path: TPath
|
|
17
|
-
initialValue: PickProps<TData, TPath
|
|
18
|
-
errors: ValidationErrors
|
|
19
|
-
touched: boolean
|
|
20
|
-
dirty: boolean
|
|
15
|
+
data: Ref<PickProps<TData, TPath>, PickProps<TData, TPath>>;
|
|
16
|
+
path: Ref<TPath, TPath>;
|
|
17
|
+
initialValue: Readonly< Ref<PickProps<TData, TPath>, PickProps<TData, TPath>>>;
|
|
18
|
+
errors: Ref<ValidationErrors>;
|
|
19
|
+
touched: Ref<boolean>;
|
|
20
|
+
dirty: Ref<boolean>;
|
|
21
21
|
setData: (newData: PickProps<TData, TPath>) => void;
|
|
22
22
|
onBlur: () => void;
|
|
23
23
|
onFocus: () => void;
|
package/dist/index.js
CHANGED
|
@@ -1,49 +1,50 @@
|
|
|
1
1
|
var T = Object.defineProperty;
|
|
2
2
|
var G = (e, r, t) => r in e ? T(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t;
|
|
3
|
-
var
|
|
4
|
-
import { toValue as L, toRaw as Z, computed as u, unref as d, reactive as
|
|
3
|
+
var P = (e, r, t) => G(e, typeof r != "symbol" ? r + "" : r, t);
|
|
4
|
+
import { toValue as L, toRaw as Z, computed as u, unref as d, reactive as b, toRefs as N, toRef as _, ref as W, watch as y, isRef as z, getCurrentScope as q, onBeforeUnmount as H, defineComponent as S, renderSlot as j, normalizeProps as M, guardReactiveProps as B, resolveComponent as Q, createBlock as O, openBlock as $, withCtx as A, resolveDynamicComponent as X, mergeProps as Y } from "vue";
|
|
5
|
+
import { cloneDeep as x } from "lodash-es";
|
|
5
6
|
import "zod";
|
|
6
7
|
function g(e) {
|
|
7
8
|
const r = L(e), t = Z(r);
|
|
8
|
-
return
|
|
9
|
+
return x(t);
|
|
9
10
|
}
|
|
10
11
|
function K(e) {
|
|
11
12
|
return e === "" ? [] : e.split(/\s*\.\s*/).filter(Boolean);
|
|
12
13
|
}
|
|
13
|
-
function
|
|
14
|
+
function E(e, r) {
|
|
14
15
|
return (Array.isArray(r) ? r : K(r)).reduce(
|
|
15
16
|
(s, a) => s == null ? void 0 : s[a],
|
|
16
17
|
e
|
|
17
18
|
);
|
|
18
19
|
}
|
|
19
|
-
function
|
|
20
|
+
function rr(e, r, t) {
|
|
20
21
|
const s = Array.isArray(r) ? r : K(r);
|
|
21
22
|
if (s.length === 0)
|
|
22
23
|
throw new Error("Path cannot be empty");
|
|
23
|
-
const a = s.at(-1),
|
|
24
|
+
const a = s.at(-1), n = s.slice(0, -1).reduce(
|
|
24
25
|
(h, c) => h[c],
|
|
25
26
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
27
|
e
|
|
27
28
|
);
|
|
28
|
-
|
|
29
|
+
n[a] = t;
|
|
29
30
|
}
|
|
30
31
|
const U = (e, r) => u({
|
|
31
32
|
get() {
|
|
32
|
-
return
|
|
33
|
+
return E(d(e), d(r));
|
|
33
34
|
},
|
|
34
35
|
set(t) {
|
|
35
|
-
|
|
36
|
+
rr(d(e), d(r), t);
|
|
36
37
|
}
|
|
37
38
|
});
|
|
38
39
|
function F(e, r) {
|
|
39
40
|
return !e && !r ? "" : !e && r ? r : !r && e ? e : `${e}.${r}`;
|
|
40
41
|
}
|
|
41
|
-
function
|
|
42
|
+
function er(e, r) {
|
|
42
43
|
if (!r)
|
|
43
44
|
return e;
|
|
44
45
|
const t = `${r}.`, s = Object.fromEntries(
|
|
45
46
|
Object.entries(e.propertyErrors).filter(([a]) => a.startsWith(t)).map(
|
|
46
|
-
([a,
|
|
47
|
+
([a, n]) => [a.slice(t.length), n]
|
|
47
48
|
)
|
|
48
49
|
);
|
|
49
50
|
return {
|
|
@@ -52,8 +53,8 @@ function rr(e, r) {
|
|
|
52
53
|
propertyErrors: s
|
|
53
54
|
};
|
|
54
55
|
}
|
|
55
|
-
function
|
|
56
|
-
const r =
|
|
56
|
+
function tr(e) {
|
|
57
|
+
const r = b({
|
|
57
58
|
value: e.value,
|
|
58
59
|
path: e.path,
|
|
59
60
|
initialValue: u(() => Object.freeze(g(e.initialValue))),
|
|
@@ -63,12 +64,12 @@ function er(e) {
|
|
|
63
64
|
r.value = f;
|
|
64
65
|
}, a = () => {
|
|
65
66
|
r.touched = !0;
|
|
66
|
-
},
|
|
67
|
+
}, n = () => {
|
|
67
68
|
}, h = () => {
|
|
68
69
|
r.value = g(r.initialValue), r.touched = !1, r.errors = [];
|
|
69
70
|
}, c = (f) => {
|
|
70
71
|
r.errors = f;
|
|
71
|
-
},
|
|
72
|
+
}, o = () => {
|
|
72
73
|
r.errors = [];
|
|
73
74
|
}, l = N(r);
|
|
74
75
|
return {
|
|
@@ -80,22 +81,22 @@ function er(e) {
|
|
|
80
81
|
dirty: t,
|
|
81
82
|
setData: s,
|
|
82
83
|
onBlur: a,
|
|
83
|
-
onFocus:
|
|
84
|
+
onFocus: n,
|
|
84
85
|
reset: h,
|
|
85
86
|
setErrors: c,
|
|
86
|
-
clearErrors:
|
|
87
|
+
clearErrors: o
|
|
87
88
|
};
|
|
88
89
|
}
|
|
89
|
-
function
|
|
90
|
+
function sr(e, r) {
|
|
90
91
|
const t = {}, s = (c) => {
|
|
91
|
-
const
|
|
92
|
-
t[
|
|
92
|
+
const o = d(c.path);
|
|
93
|
+
t[o] = c;
|
|
93
94
|
}, a = (c) => {
|
|
94
95
|
if (!t[c]) {
|
|
95
|
-
const
|
|
96
|
+
const o = tr({
|
|
96
97
|
path: c,
|
|
97
|
-
value: U(
|
|
98
|
-
initialValue: u(() =>
|
|
98
|
+
value: U(_(e, "data"), c),
|
|
99
|
+
initialValue: u(() => E(e.initialData, c)),
|
|
99
100
|
errors: u({
|
|
100
101
|
get() {
|
|
101
102
|
return r.errors.value.propertyErrors[c] || [];
|
|
@@ -105,7 +106,7 @@ function tr(e, r) {
|
|
|
105
106
|
}
|
|
106
107
|
})
|
|
107
108
|
});
|
|
108
|
-
return s(
|
|
109
|
+
return s(o), o;
|
|
109
110
|
}
|
|
110
111
|
return t[c];
|
|
111
112
|
};
|
|
@@ -117,14 +118,14 @@ function tr(e, r) {
|
|
|
117
118
|
defineField: (c) => a(c.path)
|
|
118
119
|
};
|
|
119
120
|
}
|
|
120
|
-
function
|
|
121
|
+
function ar(e) {
|
|
121
122
|
const r = u(() => e.getFields().some((s) => d(s.dirty))), t = u(() => e.getFields().some((s) => d(s.touched)));
|
|
122
123
|
return {
|
|
123
124
|
isDirty: r,
|
|
124
125
|
isTouched: t
|
|
125
126
|
};
|
|
126
127
|
}
|
|
127
|
-
function
|
|
128
|
+
function or(e) {
|
|
128
129
|
return e.filter(
|
|
129
130
|
(r, t, s) => s.indexOf(r) === t
|
|
130
131
|
);
|
|
@@ -139,19 +140,19 @@ function k(...e) {
|
|
|
139
140
|
if (!s)
|
|
140
141
|
return r;
|
|
141
142
|
const a = (r ?? []).concat(t);
|
|
142
|
-
return
|
|
143
|
+
return or(a);
|
|
143
144
|
}, e[0]);
|
|
144
145
|
}
|
|
145
|
-
function
|
|
146
|
+
function nr(...e) {
|
|
146
147
|
return e.map((t) => Object.keys(t)).flat().reduce((t, s) => {
|
|
147
|
-
const a = e.map((
|
|
148
|
+
const a = e.map((n) => n[s]).filter(Boolean);
|
|
148
149
|
return {
|
|
149
150
|
...t,
|
|
150
151
|
[s]: k(...a)
|
|
151
152
|
};
|
|
152
153
|
}, {});
|
|
153
154
|
}
|
|
154
|
-
function
|
|
155
|
+
function D(...e) {
|
|
155
156
|
if (!e.length)
|
|
156
157
|
return {
|
|
157
158
|
general: [],
|
|
@@ -161,7 +162,7 @@ function R(...e) {
|
|
|
161
162
|
return e.length === 1 ? r : e.slice(1).reduce(
|
|
162
163
|
(t, s) => ({
|
|
163
164
|
general: k(t.general, s.general),
|
|
164
|
-
propertyErrors:
|
|
165
|
+
propertyErrors: nr(t.propertyErrors ?? {}, s.propertyErrors ?? {})
|
|
165
166
|
}),
|
|
166
167
|
r
|
|
167
168
|
);
|
|
@@ -171,12 +172,12 @@ function C(e) {
|
|
|
171
172
|
const r = (((s = e.general) == null ? void 0 : s.length) ?? 0) > 0, t = Object.entries(e.propertyErrors).filter(([, a]) => a == null ? void 0 : a.length).length > 0;
|
|
172
173
|
return r || t;
|
|
173
174
|
}
|
|
174
|
-
function
|
|
175
|
+
function ir(e) {
|
|
175
176
|
const r = e.issues.filter((s) => s.path.length === 0).map((s) => s.message), t = e.issues.filter((s) => s.path.length > 0).reduce((s, a) => {
|
|
176
|
-
const
|
|
177
|
+
const n = a.path.join(".");
|
|
177
178
|
return {
|
|
178
179
|
...s,
|
|
179
|
-
[
|
|
180
|
+
[n]: [...s[n] ?? [], a.message]
|
|
180
181
|
};
|
|
181
182
|
}, {});
|
|
182
183
|
return {
|
|
@@ -191,7 +192,7 @@ const m = {
|
|
|
191
192
|
propertyErrors: {}
|
|
192
193
|
}
|
|
193
194
|
};
|
|
194
|
-
class
|
|
195
|
+
class lr {
|
|
195
196
|
constructor(r) {
|
|
196
197
|
this.schema = r;
|
|
197
198
|
}
|
|
@@ -201,7 +202,7 @@ class ir {
|
|
|
201
202
|
const t = await this.schema.safeParseAsync(r);
|
|
202
203
|
if (t.success)
|
|
203
204
|
return m;
|
|
204
|
-
const s =
|
|
205
|
+
const s = ir(t.error);
|
|
205
206
|
return {
|
|
206
207
|
isValid: !1,
|
|
207
208
|
errors: {
|
|
@@ -211,7 +212,7 @@ class ir {
|
|
|
211
212
|
};
|
|
212
213
|
}
|
|
213
214
|
}
|
|
214
|
-
class
|
|
215
|
+
class cr {
|
|
215
216
|
constructor(r) {
|
|
216
217
|
this.validateFn = r;
|
|
217
218
|
}
|
|
@@ -232,11 +233,11 @@ class lr {
|
|
|
232
233
|
}
|
|
233
234
|
}
|
|
234
235
|
}
|
|
235
|
-
class
|
|
236
|
+
class ur {
|
|
236
237
|
constructor(r, t) {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
this.schema = r, this.validateFn = t, this.schemaValidator = new
|
|
238
|
+
P(this, "schemaValidator");
|
|
239
|
+
P(this, "functionValidator");
|
|
240
|
+
this.schema = r, this.validateFn = t, this.schemaValidator = new lr(this.schema), this.functionValidator = new cr(this.validateFn);
|
|
240
241
|
}
|
|
241
242
|
async validate(r) {
|
|
242
243
|
const [t, s] = await Promise.all([
|
|
@@ -245,30 +246,30 @@ class cr {
|
|
|
245
246
|
]);
|
|
246
247
|
return {
|
|
247
248
|
isValid: t.isValid && s.isValid,
|
|
248
|
-
errors:
|
|
249
|
+
errors: D(t.errors, s.errors)
|
|
249
250
|
};
|
|
250
251
|
}
|
|
251
252
|
}
|
|
252
|
-
function
|
|
253
|
-
return u(() => new
|
|
253
|
+
function R(e) {
|
|
254
|
+
return u(() => new ur(
|
|
254
255
|
d(e.schema),
|
|
255
256
|
d(e.validateFn)
|
|
256
257
|
));
|
|
257
258
|
}
|
|
258
|
-
function
|
|
259
|
-
const t =
|
|
260
|
-
validators: W([
|
|
259
|
+
function dr(e, r) {
|
|
260
|
+
const t = b({
|
|
261
|
+
validators: W([R(r)]),
|
|
261
262
|
isValidated: !1,
|
|
262
263
|
errors: d(r.errors) ?? m.errors
|
|
263
264
|
});
|
|
264
265
|
y(() => d(r.errors), async () => {
|
|
265
|
-
const
|
|
266
|
-
o
|
|
266
|
+
const o = await a();
|
|
267
|
+
n(o.errors);
|
|
267
268
|
}, { immediate: !0 }), y(
|
|
268
269
|
[() => t.validators],
|
|
269
|
-
async (
|
|
270
|
+
async (o) => {
|
|
270
271
|
if (t.isValidated)
|
|
271
|
-
if (
|
|
272
|
+
if (o) {
|
|
272
273
|
const l = await a();
|
|
273
274
|
t.errors = l.errors;
|
|
274
275
|
} else
|
|
@@ -278,8 +279,8 @@ function ur(e, r) {
|
|
|
278
279
|
), y(() => e.data, () => {
|
|
279
280
|
t.isValidated && h();
|
|
280
281
|
});
|
|
281
|
-
const s = (
|
|
282
|
-
const l = z(
|
|
282
|
+
const s = (o) => {
|
|
283
|
+
const l = z(o) ? o : R(o);
|
|
283
284
|
return t.validators.push(l), q() && H(() => {
|
|
284
285
|
t.validators = t.validators.filter(
|
|
285
286
|
(f) => f !== l
|
|
@@ -287,25 +288,25 @@ function ur(e, r) {
|
|
|
287
288
|
}), l;
|
|
288
289
|
};
|
|
289
290
|
async function a() {
|
|
290
|
-
const
|
|
291
|
+
const o = await Promise.all(
|
|
291
292
|
t.validators.filter((v) => d(v) !== void 0).map((v) => d(v).validate(e.data))
|
|
292
|
-
), l =
|
|
293
|
+
), l = o.every((v) => v.isValid);
|
|
293
294
|
let { errors: f } = m;
|
|
294
295
|
if (!l) {
|
|
295
|
-
const v =
|
|
296
|
-
f =
|
|
296
|
+
const v = o.map((w) => w.errors);
|
|
297
|
+
f = D(...v);
|
|
297
298
|
}
|
|
298
299
|
return {
|
|
299
300
|
errors: f,
|
|
300
301
|
isValid: l
|
|
301
302
|
};
|
|
302
303
|
}
|
|
303
|
-
const
|
|
304
|
-
t.errors =
|
|
304
|
+
const n = (o) => {
|
|
305
|
+
t.errors = D(d(r.errors) ?? m.errors, o);
|
|
305
306
|
}, h = async () => {
|
|
306
|
-
const
|
|
307
|
-
return o
|
|
308
|
-
isValid: !C(
|
|
307
|
+
const o = await a();
|
|
308
|
+
return n(o.errors), t.isValidated = !0, {
|
|
309
|
+
isValid: !C(o.errors),
|
|
309
310
|
errors: t.errors
|
|
310
311
|
};
|
|
311
312
|
}, c = u(() => !C(t.errors));
|
|
@@ -316,12 +317,12 @@ function ur(e, r) {
|
|
|
316
317
|
isValid: c
|
|
317
318
|
};
|
|
318
319
|
}
|
|
319
|
-
class
|
|
320
|
+
class fr {
|
|
320
321
|
constructor(r, t) {
|
|
321
322
|
this.path = r, this.validator = t;
|
|
322
323
|
}
|
|
323
324
|
async validate(r) {
|
|
324
|
-
const t =
|
|
325
|
+
const t = E(r, this.path);
|
|
325
326
|
if (!this.validator)
|
|
326
327
|
return m;
|
|
327
328
|
const s = await this.validator.validate(t);
|
|
@@ -330,17 +331,17 @@ class dr {
|
|
|
330
331
|
errors: {
|
|
331
332
|
general: s.errors.general || [],
|
|
332
333
|
propertyErrors: s.errors.propertyErrors ? Object.fromEntries(
|
|
333
|
-
Object.entries(s.errors.propertyErrors).map(([a,
|
|
334
|
+
Object.entries(s.errors.propertyErrors).map(([a, n]) => [
|
|
334
335
|
F(this.path, a),
|
|
335
|
-
|
|
336
|
+
n
|
|
336
337
|
])
|
|
337
338
|
) : {}
|
|
338
339
|
}
|
|
339
340
|
};
|
|
340
341
|
}
|
|
341
342
|
}
|
|
342
|
-
function
|
|
343
|
-
const s = U(e.data, r), a = u(() =>
|
|
343
|
+
function pr(e, r, t) {
|
|
344
|
+
const s = U(e.data, r), a = u(() => E(e.initialData.value, r)), n = (i) => ({
|
|
344
345
|
...i,
|
|
345
346
|
path: u(() => d(i.path).replace(r + ".", "")),
|
|
346
347
|
setData: (p) => {
|
|
@@ -348,34 +349,34 @@ function fr(e, r, t) {
|
|
|
348
349
|
}
|
|
349
350
|
}), h = (i) => {
|
|
350
351
|
const p = F(r, i), V = e.getField(p);
|
|
351
|
-
return V ?
|
|
352
|
+
return V ? n(V) : {};
|
|
352
353
|
}, c = (i) => {
|
|
353
354
|
const p = F(r, i.path), V = e.defineField({
|
|
354
355
|
...i,
|
|
355
356
|
path: p
|
|
356
357
|
});
|
|
357
|
-
return
|
|
358
|
-
},
|
|
358
|
+
return n(V);
|
|
359
|
+
}, o = () => e.getFields().filter((i) => {
|
|
359
360
|
const p = i.path.value;
|
|
360
361
|
return p.startsWith(r + ".") || p === r;
|
|
361
|
-
}).map((i) =>
|
|
362
|
+
}).map((i) => n(i)), l = () => e.getFields().filter((i) => {
|
|
362
363
|
const p = i.path.value;
|
|
363
364
|
return p.startsWith(r + ".") || p === r;
|
|
364
|
-
}), f = u(() => l().some((i) => i.dirty.value)), v = u(() => l().some((i) => i.touched.value)),
|
|
365
|
+
}), f = u(() => l().some((i) => i.dirty.value)), v = u(() => l().some((i) => i.touched.value)), w = u(() => e.isValid.value), I = u(() => e.isValidated.value), J = u(() => er(d(e.errors), r));
|
|
365
366
|
return {
|
|
366
367
|
data: s,
|
|
367
368
|
initialData: a,
|
|
368
369
|
defineField: c,
|
|
369
370
|
getField: h,
|
|
370
|
-
getFields:
|
|
371
|
+
getFields: o,
|
|
371
372
|
isDirty: f,
|
|
372
373
|
isTouched: v,
|
|
373
|
-
isValid:
|
|
374
|
+
isValid: w,
|
|
374
375
|
isValidated: I,
|
|
375
376
|
errors: J,
|
|
376
377
|
defineValidator: (i) => {
|
|
377
|
-
const p = z(i) ? i :
|
|
378
|
-
() => new
|
|
378
|
+
const p = z(i) ? i : R(i), V = u(
|
|
379
|
+
() => new fr(r, d(p))
|
|
379
380
|
);
|
|
380
381
|
return e.defineValidator(V), p;
|
|
381
382
|
},
|
|
@@ -390,34 +391,34 @@ function fr(e, r, t) {
|
|
|
390
391
|
}
|
|
391
392
|
};
|
|
392
393
|
}
|
|
393
|
-
function
|
|
394
|
-
const r = u(() => Object.freeze(g(e.initialData))), t = W(g(r)), s =
|
|
394
|
+
function wr(e) {
|
|
395
|
+
const r = u(() => Object.freeze(g(e.initialData))), t = W(g(r)), s = b({
|
|
395
396
|
initialData: r,
|
|
396
397
|
data: t
|
|
397
398
|
});
|
|
398
399
|
y(r, (f) => {
|
|
399
400
|
s.data = g(f);
|
|
400
401
|
});
|
|
401
|
-
const a =
|
|
402
|
-
t.value = g(r),
|
|
402
|
+
const a = dr(s, e), n = sr(s, a), h = ar(n), c = () => {
|
|
403
|
+
t.value = g(r), n.getFields().forEach(
|
|
403
404
|
(f) => f.reset()
|
|
404
405
|
);
|
|
405
406
|
};
|
|
406
|
-
function
|
|
407
|
-
return
|
|
407
|
+
function o(f, v) {
|
|
408
|
+
return pr(l, f);
|
|
408
409
|
}
|
|
409
410
|
const l = {
|
|
410
|
-
...
|
|
411
|
+
...n,
|
|
411
412
|
...a,
|
|
412
413
|
...h,
|
|
413
414
|
reset: c,
|
|
414
|
-
getSubForm:
|
|
415
|
-
initialData:
|
|
416
|
-
data:
|
|
415
|
+
getSubForm: o,
|
|
416
|
+
initialData: _(s, "initialData"),
|
|
417
|
+
data: _(s, "data")
|
|
417
418
|
};
|
|
418
419
|
return l;
|
|
419
420
|
}
|
|
420
|
-
const
|
|
421
|
+
const Pr = /* @__PURE__ */ S({
|
|
421
422
|
__name: "Field",
|
|
422
423
|
props: {
|
|
423
424
|
form: {},
|
|
@@ -429,10 +430,10 @@ const Er = /* @__PURE__ */ S({
|
|
|
429
430
|
setup(e) {
|
|
430
431
|
const r = e, t = r.form.defineField({
|
|
431
432
|
path: r.path
|
|
432
|
-
})
|
|
433
|
-
return (
|
|
433
|
+
});
|
|
434
|
+
return (s, a) => j(s.$slots, "default", M(B(d(t))));
|
|
434
435
|
}
|
|
435
|
-
}),
|
|
436
|
+
}), _r = /* @__PURE__ */ S({
|
|
436
437
|
inheritAttrs: !1,
|
|
437
438
|
__name: "FormFieldWrapper",
|
|
438
439
|
props: {
|
|
@@ -448,9 +449,9 @@ const Er = /* @__PURE__ */ S({
|
|
|
448
449
|
form: r.form,
|
|
449
450
|
path: r.path
|
|
450
451
|
}, {
|
|
451
|
-
default: A(({ errors: a, data:
|
|
452
|
+
default: A(({ errors: a, data: n, setData: h }) => [
|
|
452
453
|
($(), O(X(r.component), Y({ ...r.componentProps, ...r.$attrs }, {
|
|
453
|
-
"model-value":
|
|
454
|
+
"model-value": n,
|
|
454
455
|
errors: a,
|
|
455
456
|
name: r.path,
|
|
456
457
|
"onUpdate:modelValue": h
|
|
@@ -465,7 +466,7 @@ const Er = /* @__PURE__ */ S({
|
|
|
465
466
|
}, 8, ["form", "path"]);
|
|
466
467
|
};
|
|
467
468
|
}
|
|
468
|
-
}),
|
|
469
|
+
}), Dr = /* @__PURE__ */ S({
|
|
469
470
|
__name: "FormPart",
|
|
470
471
|
props: {
|
|
471
472
|
form: {},
|
|
@@ -477,8 +478,8 @@ const Er = /* @__PURE__ */ S({
|
|
|
477
478
|
}
|
|
478
479
|
});
|
|
479
480
|
export {
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
481
|
+
Pr as Field,
|
|
482
|
+
_r as FormFieldWrapper,
|
|
483
|
+
Dr as FormPart,
|
|
484
|
+
wr as useForm
|
|
484
485
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teamnovu/kit-vue-forms",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.21",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@vueuse/core": "^13.5.0",
|
|
33
|
+
"lodash-es": "^4.17.21",
|
|
33
34
|
"vue-component-type-helpers": "^3.0.5",
|
|
34
35
|
"zod": "^4"
|
|
35
36
|
},
|
package/src/components/Field.vue
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<slot v-bind="
|
|
2
|
+
<slot v-bind="field" />
|
|
3
3
|
</template>
|
|
4
4
|
|
|
5
5
|
<script
|
|
6
6
|
setup lang="ts"
|
|
7
7
|
generic="TData extends object, TPath extends Paths<TData>"
|
|
8
8
|
>
|
|
9
|
-
import { reactive } from 'vue'
|
|
10
9
|
import type { Form } from '../types/form.ts'
|
|
11
10
|
import type { Paths, PickProps } from '../types/util.ts'
|
|
12
11
|
import type { UseFieldOptions } from '../composables/useField.ts'
|
|
@@ -20,6 +19,4 @@ const props = defineProps<FieldProps<TData, TPath>>()
|
|
|
20
19
|
const field = props.form.defineField({
|
|
21
20
|
path: props.path,
|
|
22
21
|
})
|
|
23
|
-
|
|
24
|
-
const slotData = reactive(field)
|
|
25
22
|
</script>
|
package/src/utils/general.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { toRaw, toValue
|
|
1
|
+
import { type MaybeRefOrGetter, toRaw, toValue } from 'vue'
|
|
2
|
+
import { cloneDeep } from 'lodash-es'
|
|
2
3
|
|
|
3
4
|
export function cloneRefValue<T>(ref: MaybeRefOrGetter<T> | MaybeRefOrGetter<Readonly<T>>): T {
|
|
4
5
|
const unreffed = toValue(ref)
|
|
5
6
|
const raw = toRaw(unreffed)
|
|
6
|
-
return
|
|
7
|
+
return cloneDeep(raw) as T
|
|
7
8
|
}
|