@teamnovu/kit-vue-forms 0.0.11 → 0.0.12
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/composables/useFieldRegistry.d.ts +1 -1
- package/dist/index.mjs +139 -158
- package/package.json +1 -1
- package/src/composables/useFieldRegistry.ts +13 -10
|
@@ -13,7 +13,7 @@ export declare function useFieldRegistry<T extends FormDataDefault>(formState: F
|
|
|
13
13
|
getField: <K extends Paths<T>>(path: K) => ResolvedFormField<T, K>;
|
|
14
14
|
getFields: <TData extends T>() => FieldsTuple<TData>;
|
|
15
15
|
registerField: <K extends Paths<T>>(field: ResolvedFormField<T, K>) => void;
|
|
16
|
-
defineField: <K extends Paths<T>>(options: DefineFieldOptions<PickProps<T, K>, K>) =>
|
|
16
|
+
defineField: <K extends Paths<T>>(options: DefineFieldOptions<PickProps<T, K>, K>) => ResolvedFormField<T, K>;
|
|
17
17
|
};
|
|
18
18
|
export type FieldRegistry<T extends FormDataDefault> = ReturnType<typeof useFieldRegistry<T>>;
|
|
19
19
|
export {};
|
package/dist/index.mjs
CHANGED
|
@@ -1,102 +1,80 @@
|
|
|
1
1
|
var x = Object.defineProperty;
|
|
2
2
|
var K = (e, r, t) => r in e ? x(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t;
|
|
3
3
|
var S = (e, r, t) => K(e, typeof r != "symbol" ? r + "" : r, t);
|
|
4
|
-
import { toValue as W, toRaw as
|
|
4
|
+
import { toValue as W, toRaw as I, computed as d, unref as u, reactive as m, watch as F, toRefs as O, toRef as D, ref as A, isRef as _, getCurrentScope as J, onBeforeUnmount as T, defineComponent as B, renderSlot as G, normalizeProps as L, guardReactiveProps as U } from "vue";
|
|
5
5
|
import "zod";
|
|
6
|
-
function
|
|
7
|
-
const r = W(e), t =
|
|
6
|
+
function y(e) {
|
|
7
|
+
const r = W(e), t = I(r);
|
|
8
8
|
return structuredClone(t);
|
|
9
9
|
}
|
|
10
10
|
function N(e) {
|
|
11
11
|
return e === "" ? [] : e.split(/\s*\.\s*/).filter(Boolean);
|
|
12
12
|
}
|
|
13
|
-
function
|
|
13
|
+
function w(e, r) {
|
|
14
14
|
return (Array.isArray(r) ? r : N(r)).reduce(
|
|
15
|
-
(
|
|
15
|
+
(s, a) => s == null ? void 0 : s[a],
|
|
16
16
|
e
|
|
17
17
|
);
|
|
18
18
|
}
|
|
19
19
|
function Z(e, r, t) {
|
|
20
|
-
const
|
|
21
|
-
if (
|
|
20
|
+
const s = Array.isArray(r) ? r : N(r);
|
|
21
|
+
if (s.length === 0)
|
|
22
22
|
throw new Error("Path cannot be empty");
|
|
23
|
-
const
|
|
23
|
+
const a = s.at(-1), n = s.slice(0, -1).reduce(
|
|
24
24
|
(o, v) => o[v],
|
|
25
25
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
26
|
e
|
|
27
27
|
);
|
|
28
|
-
n[
|
|
28
|
+
n[a] = t;
|
|
29
29
|
}
|
|
30
|
-
const
|
|
30
|
+
const z = (e, r) => d({
|
|
31
31
|
get() {
|
|
32
|
-
return
|
|
32
|
+
return w(u(e), u(r));
|
|
33
33
|
},
|
|
34
34
|
set(t) {
|
|
35
35
|
Z(u(e), u(r), t);
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
|
-
function
|
|
38
|
+
function E(e, r) {
|
|
39
39
|
return !e && !r ? "" : !e && r ? r : !r && e ? e : `${e}.${r}`;
|
|
40
40
|
}
|
|
41
41
|
function k(e, r) {
|
|
42
42
|
if (!r)
|
|
43
43
|
return e;
|
|
44
|
-
const t = `${r}.`,
|
|
45
|
-
Object.entries(e.propertyErrors).filter(([
|
|
46
|
-
([
|
|
44
|
+
const t = `${r}.`, s = Object.fromEntries(
|
|
45
|
+
Object.entries(e.propertyErrors).filter(([a]) => a.startsWith(t)).map(
|
|
46
|
+
([a, n]) => [a.slice(t.length), n]
|
|
47
47
|
)
|
|
48
48
|
);
|
|
49
49
|
return {
|
|
50
50
|
general: e.general,
|
|
51
51
|
// Keep general errors
|
|
52
|
-
propertyErrors:
|
|
52
|
+
propertyErrors: s
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
|
-
function q() {
|
|
56
|
-
|
|
57
|
-
setData: () => {
|
|
58
|
-
},
|
|
59
|
-
onBlur: () => {
|
|
60
|
-
},
|
|
61
|
-
onFocus: () => {
|
|
62
|
-
},
|
|
63
|
-
reset: () => {
|
|
64
|
-
},
|
|
65
|
-
setErrors: () => {
|
|
66
|
-
},
|
|
67
|
-
clearErrors: () => {
|
|
68
|
-
},
|
|
69
|
-
data: y(void 0),
|
|
70
|
-
initialValue: y(void 0),
|
|
71
|
-
path: y(""),
|
|
72
|
-
errors: y([]),
|
|
73
|
-
touched: y(!1),
|
|
74
|
-
dirty: d(() => !1)
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
function H(e) {
|
|
78
|
-
const r = w({
|
|
55
|
+
function q(e) {
|
|
56
|
+
const r = m({
|
|
79
57
|
value: e.value,
|
|
80
58
|
path: e.path,
|
|
81
|
-
initialValue: d(() => Object.freeze(
|
|
59
|
+
initialValue: d(() => Object.freeze(y(e.initialValue))),
|
|
82
60
|
errors: u(e.errors) || [],
|
|
83
61
|
touched: !1
|
|
84
62
|
});
|
|
85
|
-
|
|
63
|
+
F(() => u(e.errors), (f) => {
|
|
86
64
|
r.errors = f || [];
|
|
87
65
|
});
|
|
88
|
-
const t = d(() => JSON.stringify(r.value) !== JSON.stringify(r.initialValue)),
|
|
66
|
+
const t = d(() => JSON.stringify(r.value) !== JSON.stringify(r.initialValue)), s = (f) => {
|
|
89
67
|
r.value = f;
|
|
90
|
-
},
|
|
68
|
+
}, a = () => {
|
|
91
69
|
r.touched = !0;
|
|
92
70
|
}, n = () => {
|
|
93
71
|
}, o = () => {
|
|
94
|
-
r.value =
|
|
72
|
+
r.value = y(r.initialValue), r.touched = !1, r.errors = [];
|
|
95
73
|
}, v = (f) => {
|
|
96
74
|
r.errors = f;
|
|
97
75
|
}, l = () => {
|
|
98
76
|
r.errors = [];
|
|
99
|
-
}, c =
|
|
77
|
+
}, c = O(r);
|
|
100
78
|
return {
|
|
101
79
|
data: c.value,
|
|
102
80
|
path: c.path,
|
|
@@ -104,69 +82,72 @@ function H(e) {
|
|
|
104
82
|
errors: c.errors,
|
|
105
83
|
touched: c.touched,
|
|
106
84
|
dirty: t,
|
|
107
|
-
setData:
|
|
108
|
-
onBlur:
|
|
85
|
+
setData: s,
|
|
86
|
+
onBlur: a,
|
|
109
87
|
onFocus: n,
|
|
110
88
|
reset: o,
|
|
111
89
|
setErrors: v,
|
|
112
90
|
clearErrors: l
|
|
113
91
|
};
|
|
114
92
|
}
|
|
115
|
-
function
|
|
93
|
+
function H(e) {
|
|
116
94
|
const r = {}, t = (o) => {
|
|
117
95
|
const v = u(o.path);
|
|
118
96
|
r[v] = o;
|
|
97
|
+
}, s = (o) => {
|
|
98
|
+
if (!r[o]) {
|
|
99
|
+
const v = q({
|
|
100
|
+
path: o,
|
|
101
|
+
value: z(D(e, "data"), o),
|
|
102
|
+
initialValue: d(() => w(e.initialData, o))
|
|
103
|
+
});
|
|
104
|
+
return t(v), v;
|
|
105
|
+
}
|
|
106
|
+
return r[o];
|
|
119
107
|
};
|
|
120
108
|
return {
|
|
121
109
|
fields: r,
|
|
122
|
-
getField:
|
|
110
|
+
getField: s,
|
|
123
111
|
getFields: () => Object.values(r),
|
|
124
112
|
registerField: t,
|
|
125
|
-
defineField: (o) =>
|
|
126
|
-
const v = H({
|
|
127
|
-
...o,
|
|
128
|
-
value: $(P(e, "data"), o.path),
|
|
129
|
-
initialValue: d(() => R(e.initialData, u(o.path)))
|
|
130
|
-
});
|
|
131
|
-
return t(v), v;
|
|
132
|
-
}
|
|
113
|
+
defineField: (o) => s(o.path)
|
|
133
114
|
};
|
|
134
115
|
}
|
|
135
|
-
function
|
|
136
|
-
const r = d(() => e.getFields().some((
|
|
116
|
+
function Q(e) {
|
|
117
|
+
const r = d(() => e.getFields().some((s) => u(s.dirty))), t = d(() => e.getFields().some((s) => u(s.touched)));
|
|
137
118
|
return {
|
|
138
119
|
isDirty: r,
|
|
139
120
|
isTouched: t
|
|
140
121
|
};
|
|
141
122
|
}
|
|
142
|
-
function
|
|
123
|
+
function X(e) {
|
|
143
124
|
return e.filter(
|
|
144
|
-
(r, t,
|
|
125
|
+
(r, t, s) => s.indexOf(r) === t
|
|
145
126
|
);
|
|
146
127
|
}
|
|
147
|
-
function
|
|
128
|
+
function C(...e) {
|
|
148
129
|
return e.slice(1).reduce((r, t) => {
|
|
149
130
|
if (!r && !t)
|
|
150
131
|
return;
|
|
151
|
-
const
|
|
132
|
+
const s = ((t == null ? void 0 : t.length) ?? 0) > 0;
|
|
152
133
|
if (!r && ((t == null ? void 0 : t.length) ?? 0) > 0)
|
|
153
134
|
return t;
|
|
154
|
-
if (!
|
|
135
|
+
if (!s)
|
|
155
136
|
return r;
|
|
156
|
-
const
|
|
157
|
-
return
|
|
137
|
+
const a = (r ?? []).concat(t);
|
|
138
|
+
return X(a);
|
|
158
139
|
}, e[0]);
|
|
159
140
|
}
|
|
160
|
-
function
|
|
161
|
-
return e.map((t) => Object.keys(t)).flat().reduce((t,
|
|
162
|
-
const
|
|
141
|
+
function Y(...e) {
|
|
142
|
+
return e.map((t) => Object.keys(t)).flat().reduce((t, s) => {
|
|
143
|
+
const a = e.map((n) => n[s]).filter(Boolean);
|
|
163
144
|
return {
|
|
164
145
|
...t,
|
|
165
|
-
[
|
|
146
|
+
[s]: C(...a)
|
|
166
147
|
};
|
|
167
148
|
}, {});
|
|
168
149
|
}
|
|
169
|
-
function
|
|
150
|
+
function P(...e) {
|
|
170
151
|
if (!e.length)
|
|
171
152
|
return {
|
|
172
153
|
general: [],
|
|
@@ -174,24 +155,24 @@ function b(...e) {
|
|
|
174
155
|
};
|
|
175
156
|
const r = e[0];
|
|
176
157
|
return e.length === 1 ? r : e.slice(1).reduce(
|
|
177
|
-
(t,
|
|
178
|
-
general:
|
|
179
|
-
propertyErrors:
|
|
158
|
+
(t, s) => ({
|
|
159
|
+
general: C(t.general, s.general),
|
|
160
|
+
propertyErrors: Y(t.propertyErrors ?? {}, s.propertyErrors ?? {})
|
|
180
161
|
}),
|
|
181
162
|
r
|
|
182
163
|
);
|
|
183
164
|
}
|
|
184
|
-
function
|
|
185
|
-
var
|
|
186
|
-
const r = (((
|
|
165
|
+
function j(e) {
|
|
166
|
+
var s;
|
|
167
|
+
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;
|
|
187
168
|
return r || t;
|
|
188
169
|
}
|
|
189
|
-
function
|
|
190
|
-
const r = e.issues.filter((
|
|
191
|
-
const n =
|
|
170
|
+
function rr(e) {
|
|
171
|
+
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) => {
|
|
172
|
+
const n = a.path.join(".");
|
|
192
173
|
return {
|
|
193
|
-
...
|
|
194
|
-
[n]: [...
|
|
174
|
+
...s,
|
|
175
|
+
[n]: [...s[n] ?? [], a.message]
|
|
195
176
|
};
|
|
196
177
|
}, {});
|
|
197
178
|
return {
|
|
@@ -199,43 +180,43 @@ function er(e) {
|
|
|
199
180
|
propertyErrors: t
|
|
200
181
|
};
|
|
201
182
|
}
|
|
202
|
-
const
|
|
183
|
+
const p = {
|
|
203
184
|
isValid: !0,
|
|
204
185
|
errors: {
|
|
205
186
|
general: [],
|
|
206
187
|
propertyErrors: {}
|
|
207
188
|
}
|
|
208
189
|
};
|
|
209
|
-
class
|
|
190
|
+
class er {
|
|
210
191
|
constructor(r) {
|
|
211
192
|
this.schema = r;
|
|
212
193
|
}
|
|
213
194
|
async validate(r) {
|
|
214
195
|
if (!this.schema)
|
|
215
|
-
return
|
|
196
|
+
return p;
|
|
216
197
|
const t = await this.schema.safeParseAsync(r);
|
|
217
198
|
if (t.success)
|
|
218
|
-
return
|
|
219
|
-
const
|
|
199
|
+
return p;
|
|
200
|
+
const s = rr(t.error);
|
|
220
201
|
return {
|
|
221
202
|
isValid: !1,
|
|
222
203
|
errors: {
|
|
223
|
-
general:
|
|
224
|
-
propertyErrors:
|
|
204
|
+
general: s.general ?? [],
|
|
205
|
+
propertyErrors: s.propertyErrors ?? {}
|
|
225
206
|
}
|
|
226
207
|
};
|
|
227
208
|
}
|
|
228
209
|
}
|
|
229
|
-
class
|
|
210
|
+
class tr {
|
|
230
211
|
constructor(r) {
|
|
231
212
|
this.validateFn = r;
|
|
232
213
|
}
|
|
233
214
|
async validate(r) {
|
|
234
215
|
if (!this.validateFn)
|
|
235
|
-
return
|
|
216
|
+
return p;
|
|
236
217
|
try {
|
|
237
218
|
const t = await this.validateFn(r);
|
|
238
|
-
return t.isValid ?
|
|
219
|
+
return t.isValid ? p : t;
|
|
239
220
|
} catch (t) {
|
|
240
221
|
return {
|
|
241
222
|
isValid: !1,
|
|
@@ -251,64 +232,64 @@ class sr {
|
|
|
251
232
|
constructor(r, t) {
|
|
252
233
|
S(this, "schemaValidator");
|
|
253
234
|
S(this, "functionValidator");
|
|
254
|
-
this.schema = r, this.validateFn = t, this.schemaValidator = new
|
|
235
|
+
this.schema = r, this.validateFn = t, this.schemaValidator = new er(this.schema), this.functionValidator = new tr(this.validateFn);
|
|
255
236
|
}
|
|
256
237
|
async validate(r) {
|
|
257
|
-
const [t,
|
|
238
|
+
const [t, s] = await Promise.all([
|
|
258
239
|
this.schemaValidator.validate(r),
|
|
259
240
|
this.functionValidator.validate(r)
|
|
260
241
|
]);
|
|
261
242
|
return {
|
|
262
|
-
isValid: t.isValid &&
|
|
263
|
-
errors:
|
|
243
|
+
isValid: t.isValid && s.isValid,
|
|
244
|
+
errors: P(t.errors, s.errors)
|
|
264
245
|
};
|
|
265
246
|
}
|
|
266
247
|
}
|
|
267
|
-
function
|
|
248
|
+
function b(e) {
|
|
268
249
|
return d(() => new sr(
|
|
269
250
|
u(e.schema),
|
|
270
251
|
u(e.validateFn)
|
|
271
252
|
));
|
|
272
253
|
}
|
|
273
|
-
function
|
|
274
|
-
const t =
|
|
275
|
-
validators:
|
|
254
|
+
function ar(e, r) {
|
|
255
|
+
const t = m({
|
|
256
|
+
validators: A([b(r)]),
|
|
276
257
|
isValidated: !1,
|
|
277
|
-
errors: u(r.errors) ??
|
|
258
|
+
errors: u(r.errors) ?? p.errors
|
|
278
259
|
});
|
|
279
|
-
|
|
280
|
-
const l = await
|
|
260
|
+
F(() => u(r.errors), async () => {
|
|
261
|
+
const l = await a();
|
|
281
262
|
n(l.errors);
|
|
282
|
-
}, { immediate: !0 }),
|
|
263
|
+
}, { immediate: !0 }), F(
|
|
283
264
|
[() => t.validators],
|
|
284
265
|
async (l) => {
|
|
285
266
|
if (t.isValidated)
|
|
286
267
|
if (l) {
|
|
287
|
-
const c = await
|
|
268
|
+
const c = await a();
|
|
288
269
|
t.errors = c.errors;
|
|
289
270
|
} else
|
|
290
|
-
t.errors =
|
|
271
|
+
t.errors = p.errors;
|
|
291
272
|
},
|
|
292
273
|
{ immediate: !0 }
|
|
293
|
-
),
|
|
274
|
+
), F(() => e.data, () => {
|
|
294
275
|
t.isValidated && o();
|
|
295
276
|
});
|
|
296
|
-
const
|
|
297
|
-
const c = _(l) ? l :
|
|
298
|
-
return t.validators.push(c),
|
|
277
|
+
const s = (l) => {
|
|
278
|
+
const c = _(l) ? l : b(l);
|
|
279
|
+
return t.validators.push(c), J() && T(() => {
|
|
299
280
|
t.validators = t.validators.filter(
|
|
300
281
|
(f) => f !== c
|
|
301
282
|
);
|
|
302
283
|
}), c;
|
|
303
284
|
};
|
|
304
|
-
async function
|
|
285
|
+
async function a() {
|
|
305
286
|
const l = await Promise.all(
|
|
306
|
-
t.validators.filter((
|
|
307
|
-
), c = l.every((
|
|
308
|
-
let { errors: f } =
|
|
287
|
+
t.validators.filter((V) => u(V) !== void 0).map((V) => u(V).validate(e.data))
|
|
288
|
+
), c = l.every((V) => V.isValid);
|
|
289
|
+
let { errors: f } = p;
|
|
309
290
|
if (!c) {
|
|
310
|
-
const
|
|
311
|
-
f =
|
|
291
|
+
const V = l.map((R) => R.errors);
|
|
292
|
+
f = P(...V);
|
|
312
293
|
}
|
|
313
294
|
return {
|
|
314
295
|
errors: f,
|
|
@@ -316,37 +297,37 @@ function ir(e, r) {
|
|
|
316
297
|
};
|
|
317
298
|
}
|
|
318
299
|
const n = (l) => {
|
|
319
|
-
t.errors =
|
|
300
|
+
t.errors = P(u(r.errors) ?? p.errors, l);
|
|
320
301
|
}, o = async () => {
|
|
321
|
-
const l = await
|
|
302
|
+
const l = await a();
|
|
322
303
|
return n(l.errors), t.isValidated = !0, {
|
|
323
|
-
isValid: !
|
|
304
|
+
isValid: !j(l.errors),
|
|
324
305
|
errors: t.errors
|
|
325
306
|
};
|
|
326
|
-
}, v = d(() => !
|
|
307
|
+
}, v = d(() => !j(t.errors));
|
|
327
308
|
return {
|
|
328
|
-
...
|
|
309
|
+
...O(t),
|
|
329
310
|
validateForm: o,
|
|
330
|
-
defineValidator:
|
|
311
|
+
defineValidator: s,
|
|
331
312
|
isValid: v
|
|
332
313
|
};
|
|
333
314
|
}
|
|
334
|
-
class
|
|
315
|
+
class ir {
|
|
335
316
|
constructor(r, t) {
|
|
336
317
|
this.path = r, this.validator = t;
|
|
337
318
|
}
|
|
338
319
|
async validate(r) {
|
|
339
|
-
const t =
|
|
320
|
+
const t = w(r, this.path);
|
|
340
321
|
if (!this.validator)
|
|
341
|
-
return
|
|
342
|
-
const
|
|
322
|
+
return p;
|
|
323
|
+
const s = await this.validator.validate(t);
|
|
343
324
|
return {
|
|
344
|
-
isValid:
|
|
325
|
+
isValid: s.isValid,
|
|
345
326
|
errors: {
|
|
346
|
-
general:
|
|
347
|
-
propertyErrors:
|
|
348
|
-
Object.entries(
|
|
349
|
-
|
|
327
|
+
general: s.errors.general || [],
|
|
328
|
+
propertyErrors: s.errors.propertyErrors ? Object.fromEntries(
|
|
329
|
+
Object.entries(s.errors.propertyErrors).map(([a, n]) => [
|
|
330
|
+
E(this.path, a),
|
|
350
331
|
n
|
|
351
332
|
])
|
|
352
333
|
) : {}
|
|
@@ -354,18 +335,18 @@ class nr {
|
|
|
354
335
|
};
|
|
355
336
|
}
|
|
356
337
|
}
|
|
357
|
-
function
|
|
358
|
-
const
|
|
338
|
+
function nr(e, r, t) {
|
|
339
|
+
const s = z(e.data, r), a = d(() => w(e.initialData.value, r)), n = (i) => ({
|
|
359
340
|
...i,
|
|
360
341
|
path: d(() => u(i.path).replace(r + ".", "")),
|
|
361
342
|
setData: (h) => {
|
|
362
343
|
i.setData(h);
|
|
363
344
|
}
|
|
364
345
|
}), o = (i) => {
|
|
365
|
-
const h =
|
|
346
|
+
const h = E(r, i), g = e.getField(h);
|
|
366
347
|
return g ? n(g) : {};
|
|
367
348
|
}, v = (i) => {
|
|
368
|
-
const h =
|
|
349
|
+
const h = E(r, i.path), g = e.defineField({
|
|
369
350
|
...i,
|
|
370
351
|
path: h
|
|
371
352
|
});
|
|
@@ -376,28 +357,28 @@ function or(e, r, t) {
|
|
|
376
357
|
}).map((i) => n(i)), c = () => e.getFields().filter((i) => {
|
|
377
358
|
const h = i.path.value;
|
|
378
359
|
return h.startsWith(r + ".") || h === r;
|
|
379
|
-
}), f = d(() => c().some((i) => i.dirty.value)),
|
|
360
|
+
}), f = d(() => c().some((i) => i.dirty.value)), V = d(() => c().some((i) => i.touched.value)), R = d(() => e.isValid.value), M = d(() => e.isValidated.value), $ = d(() => k(u(e.errors), r));
|
|
380
361
|
return {
|
|
381
|
-
data:
|
|
382
|
-
initialData:
|
|
362
|
+
data: s,
|
|
363
|
+
initialData: a,
|
|
383
364
|
defineField: v,
|
|
384
365
|
getField: o,
|
|
385
366
|
getFields: l,
|
|
386
367
|
isDirty: f,
|
|
387
|
-
isTouched:
|
|
388
|
-
isValid:
|
|
389
|
-
isValidated:
|
|
390
|
-
errors:
|
|
368
|
+
isTouched: V,
|
|
369
|
+
isValid: R,
|
|
370
|
+
isValidated: M,
|
|
371
|
+
errors: $,
|
|
391
372
|
defineValidator: (i) => {
|
|
392
|
-
const h = _(i) ? i :
|
|
393
|
-
() => new
|
|
373
|
+
const h = _(i) ? i : b(i), g = d(
|
|
374
|
+
() => new ir(r, u(h))
|
|
394
375
|
);
|
|
395
376
|
return e.defineValidator(g), h;
|
|
396
377
|
},
|
|
397
378
|
reset: () => c().forEach((i) => i.reset()),
|
|
398
379
|
validateForm: () => e.validateForm(),
|
|
399
380
|
getSubForm: (i, h) => {
|
|
400
|
-
const g =
|
|
381
|
+
const g = E(r, i);
|
|
401
382
|
return e.getSubForm(
|
|
402
383
|
g,
|
|
403
384
|
h
|
|
@@ -405,30 +386,30 @@ function or(e, r, t) {
|
|
|
405
386
|
}
|
|
406
387
|
};
|
|
407
388
|
}
|
|
408
|
-
function
|
|
409
|
-
const r = d(() => Object.freeze(
|
|
389
|
+
function vr(e) {
|
|
390
|
+
const r = d(() => Object.freeze(y(e.initialData))), t = A(y(r)), s = m({
|
|
410
391
|
initialData: r,
|
|
411
392
|
data: t
|
|
412
|
-
}),
|
|
413
|
-
t.value =
|
|
393
|
+
}), a = H(s), n = ar(s, e), o = Q(a), v = () => {
|
|
394
|
+
t.value = y(r), a.getFields().forEach(
|
|
414
395
|
(f) => f.reset()
|
|
415
396
|
);
|
|
416
397
|
};
|
|
417
|
-
function l(f,
|
|
418
|
-
return
|
|
398
|
+
function l(f, V) {
|
|
399
|
+
return nr(c, f);
|
|
419
400
|
}
|
|
420
401
|
const c = {
|
|
421
|
-
...
|
|
402
|
+
...a,
|
|
422
403
|
...n,
|
|
423
404
|
...o,
|
|
424
405
|
reset: v,
|
|
425
406
|
getSubForm: l,
|
|
426
|
-
initialData:
|
|
427
|
-
data:
|
|
407
|
+
initialData: D(s, "initialData"),
|
|
408
|
+
data: D(s, "data")
|
|
428
409
|
};
|
|
429
410
|
return c;
|
|
430
411
|
}
|
|
431
|
-
const Vr = /* @__PURE__ */
|
|
412
|
+
const Vr = /* @__PURE__ */ B({
|
|
432
413
|
__name: "Field",
|
|
433
414
|
props: {
|
|
434
415
|
form: {},
|
|
@@ -441,10 +422,10 @@ const Vr = /* @__PURE__ */ T({
|
|
|
441
422
|
const r = e, t = r.form.defineField({
|
|
442
423
|
path: r.path
|
|
443
424
|
});
|
|
444
|
-
return (
|
|
425
|
+
return (s, a) => G(s.$slots, "default", L(U(m(u(t)))));
|
|
445
426
|
}
|
|
446
427
|
});
|
|
447
428
|
export {
|
|
448
429
|
Vr as Field,
|
|
449
|
-
|
|
430
|
+
vr as useForm
|
|
450
431
|
};
|
package/package.json
CHANGED
|
@@ -27,10 +27,16 @@ export function useFieldRegistry<T extends FormDataDefault>(
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
const getField = <K extends Paths<T>>(path: K): ResolvedFormField<T, K> => {
|
|
30
|
-
if (!
|
|
31
|
-
|
|
30
|
+
if (!fields[path]) {
|
|
31
|
+
const field = useField({
|
|
32
|
+
path,
|
|
33
|
+
value: getLens(toRef(formState, 'data'), path),
|
|
34
|
+
initialValue: computed(() => getNestedValue(formState.initialData, path)),
|
|
35
|
+
})
|
|
32
36
|
|
|
33
|
-
|
|
37
|
+
registerField(field)
|
|
38
|
+
|
|
39
|
+
return field
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
return fields[path] as ResolvedFormField<T, K>
|
|
@@ -40,14 +46,11 @@ export function useFieldRegistry<T extends FormDataDefault>(
|
|
|
40
46
|
return Object.values(fields) as FieldsTuple<TData>
|
|
41
47
|
}
|
|
42
48
|
|
|
43
|
-
const defineField = <K extends Paths<T>>(options: DefineFieldOptions<PickProps<T, K>, K>) => {
|
|
44
|
-
const field =
|
|
45
|
-
...options,
|
|
46
|
-
value: getLens(toRef(formState, 'data'), options.path),
|
|
47
|
-
initialValue: computed(() => getNestedValue(formState.initialData, unref(options.path))),
|
|
48
|
-
})
|
|
49
|
+
const defineField = <K extends Paths<T>>(options: DefineFieldOptions<PickProps<T, K>, K>): ResolvedFormField<T, K> => {
|
|
50
|
+
const field = getField(options.path)
|
|
49
51
|
|
|
50
|
-
|
|
52
|
+
// TODO: If more options are ever needed than only the path we have to update the field
|
|
53
|
+
// here with the new options
|
|
51
54
|
|
|
52
55
|
return field
|
|
53
56
|
}
|