@teamnovu/kit-vue-forms 0.1.7 → 0.1.8
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 +158 -152
- package/dist/utils/path.d.ts +1 -1
- package/package.json +1 -1
- package/src/utils/path.ts +19 -11
package/dist/index.js
CHANGED
|
@@ -1,51 +1,57 @@
|
|
|
1
1
|
var T = Object.defineProperty;
|
|
2
|
-
var G = (
|
|
3
|
-
var E = (
|
|
4
|
-
import { toValue as L, toRaw as Z, computed as c, unref as d,
|
|
2
|
+
var G = (r, e, t) => e in r ? T(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
|
3
|
+
var E = (r, e, t) => G(r, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
import { toValue as L, toRaw as Z, computed as c, unref as d, isRef as D, reactive as P, toRefs as W, shallowReactive as q, toRef as S, onScopeDispose as H, ref as k, watch as w, getCurrentScope as Q, onBeforeUnmount as X, defineComponent as $, renderSlot as j, normalizeProps as z, guardReactiveProps as B, resolveComponent as Y, createBlock as A, openBlock as C, withCtx as M, resolveDynamicComponent as x, mergeProps as ee } from "vue";
|
|
5
5
|
import { cloneDeep as re } from "lodash-es";
|
|
6
6
|
import "zod";
|
|
7
|
-
function g(
|
|
8
|
-
const e = L(
|
|
9
|
-
return re(
|
|
7
|
+
function g(r) {
|
|
8
|
+
const e = L(r), t = Z(e);
|
|
9
|
+
return re(t);
|
|
10
10
|
}
|
|
11
|
-
function K(
|
|
12
|
-
return
|
|
11
|
+
function K(r) {
|
|
12
|
+
return r === "" ? [] : r.split(/\s*\.\s*/).filter(Boolean);
|
|
13
13
|
}
|
|
14
|
-
function
|
|
14
|
+
function _(r, e) {
|
|
15
15
|
return (Array.isArray(e) ? e : K(e)).reduce(
|
|
16
16
|
(s, o) => s == null ? void 0 : s[o],
|
|
17
|
-
|
|
17
|
+
r
|
|
18
18
|
);
|
|
19
19
|
}
|
|
20
|
-
function te(
|
|
21
|
-
const s = Array.isArray(e) ? e : K(e), o = s.at(-1)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
function te(r, e, t) {
|
|
21
|
+
const s = Array.isArray(e) ? e : K(e), o = s.at(-1);
|
|
22
|
+
if (!o && D(r))
|
|
23
|
+
r.value = t;
|
|
24
|
+
else if (D(r)) {
|
|
25
|
+
const n = s.slice(0, -1).reduce(
|
|
26
|
+
(p, h) => p[h],
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
28
|
+
d(r)
|
|
29
|
+
);
|
|
30
|
+
n[o] = t;
|
|
31
|
+
} else
|
|
32
|
+
return;
|
|
27
33
|
}
|
|
28
|
-
const U = (
|
|
34
|
+
const U = (r, e) => c({
|
|
29
35
|
get() {
|
|
30
|
-
return
|
|
36
|
+
return _(d(r), d(e));
|
|
31
37
|
},
|
|
32
|
-
set(
|
|
33
|
-
te(
|
|
38
|
+
set(t) {
|
|
39
|
+
te(r, d(e), t);
|
|
34
40
|
}
|
|
35
41
|
});
|
|
36
|
-
function R(
|
|
37
|
-
return !
|
|
42
|
+
function R(r, e) {
|
|
43
|
+
return !r && !e ? "" : !r && e ? e : !e && r ? r : `${r}.${e}`;
|
|
38
44
|
}
|
|
39
|
-
function se(
|
|
45
|
+
function se(r, e) {
|
|
40
46
|
if (!e)
|
|
41
|
-
return
|
|
42
|
-
const
|
|
43
|
-
Object.entries(
|
|
44
|
-
([o, n]) => [o.slice(
|
|
47
|
+
return r;
|
|
48
|
+
const t = `${e}.`, s = Object.fromEntries(
|
|
49
|
+
Object.entries(r.propertyErrors).filter(([o]) => o.startsWith(t)).map(
|
|
50
|
+
([o, n]) => [o.slice(t.length), n]
|
|
45
51
|
)
|
|
46
52
|
);
|
|
47
53
|
return {
|
|
48
|
-
general:
|
|
54
|
+
general: r.general,
|
|
49
55
|
// Keep general errors
|
|
50
56
|
propertyErrors: s
|
|
51
57
|
};
|
|
@@ -62,14 +68,14 @@ class ae {
|
|
|
62
68
|
this.rc > 0 && (this.rc -= 1, this.rc === 0 && this.drop && this.drop());
|
|
63
69
|
}
|
|
64
70
|
}
|
|
65
|
-
function oe(
|
|
66
|
-
const e =
|
|
67
|
-
value:
|
|
68
|
-
path:
|
|
69
|
-
initialValue: c(() => Object.freeze(g(
|
|
70
|
-
errors:
|
|
71
|
+
function oe(r) {
|
|
72
|
+
const e = P({
|
|
73
|
+
value: r.value,
|
|
74
|
+
path: r.path,
|
|
75
|
+
initialValue: c(() => Object.freeze(g(r.initialValue))),
|
|
76
|
+
errors: r.errors,
|
|
71
77
|
touched: !1
|
|
72
|
-
}),
|
|
78
|
+
}), t = c(() => JSON.stringify(e.value) !== JSON.stringify(e.initialValue)), s = (a) => {
|
|
73
79
|
e.value = a;
|
|
74
80
|
}, o = () => {
|
|
75
81
|
e.touched = !0;
|
|
@@ -80,14 +86,14 @@ function oe(t) {
|
|
|
80
86
|
e.errors = a;
|
|
81
87
|
}, V = () => {
|
|
82
88
|
e.errors = [];
|
|
83
|
-
}, i =
|
|
89
|
+
}, i = W(e);
|
|
84
90
|
return {
|
|
85
91
|
data: i.value,
|
|
86
92
|
path: i.path,
|
|
87
93
|
initialValue: i.initialValue,
|
|
88
94
|
errors: i.errors,
|
|
89
95
|
touched: i.touched,
|
|
90
|
-
dirty:
|
|
96
|
+
dirty: t,
|
|
91
97
|
setData: s,
|
|
92
98
|
onBlur: o,
|
|
93
99
|
onFocus: n,
|
|
@@ -96,24 +102,24 @@ function oe(t) {
|
|
|
96
102
|
clearErrors: V
|
|
97
103
|
};
|
|
98
104
|
}
|
|
99
|
-
function ne(
|
|
100
|
-
const
|
|
105
|
+
function ne(r, e) {
|
|
106
|
+
const t = /* @__PURE__ */ new Map(), s = q(/* @__PURE__ */ new Map()), o = (a) => {
|
|
101
107
|
const u = d(a.path);
|
|
102
108
|
s.set(u, a);
|
|
103
109
|
}, n = (a) => {
|
|
104
110
|
s.delete(a);
|
|
105
111
|
}, p = (a) => {
|
|
106
112
|
var u;
|
|
107
|
-
|
|
113
|
+
t.has(a) ? (u = t.get(a)) == null || u.inc() : t.set(a, new ae(() => n(a)));
|
|
108
114
|
}, h = (a) => {
|
|
109
115
|
var u;
|
|
110
|
-
|
|
116
|
+
t.has(a) && ((u = t.get(a)) == null || u.dec());
|
|
111
117
|
}, V = (a) => {
|
|
112
118
|
if (!s.has(a)) {
|
|
113
119
|
const v = oe({
|
|
114
120
|
path: a,
|
|
115
|
-
value: U(
|
|
116
|
-
initialValue: c(() =>
|
|
121
|
+
value: U(S(r, "data"), a),
|
|
122
|
+
initialValue: c(() => _(r.initialData, a)),
|
|
117
123
|
errors: c({
|
|
118
124
|
get() {
|
|
119
125
|
return e.errors.value.propertyErrors[a] || [];
|
|
@@ -138,62 +144,62 @@ function ne(t, e) {
|
|
|
138
144
|
defineField: i
|
|
139
145
|
};
|
|
140
146
|
}
|
|
141
|
-
function ie(
|
|
142
|
-
const e = c(() =>
|
|
147
|
+
function ie(r) {
|
|
148
|
+
const e = c(() => r.fields.value.some((s) => d(s.dirty))), t = c(() => r.fields.value.some((s) => d(s.touched)));
|
|
143
149
|
return {
|
|
144
150
|
isDirty: e,
|
|
145
|
-
isTouched:
|
|
151
|
+
isTouched: t
|
|
146
152
|
};
|
|
147
153
|
}
|
|
148
|
-
function le(
|
|
149
|
-
return
|
|
150
|
-
(e,
|
|
154
|
+
function le(r) {
|
|
155
|
+
return r.filter(
|
|
156
|
+
(e, t, s) => s.indexOf(e) === t
|
|
151
157
|
);
|
|
152
158
|
}
|
|
153
|
-
function I(...
|
|
154
|
-
return
|
|
155
|
-
if (!e && !
|
|
159
|
+
function I(...r) {
|
|
160
|
+
return r.slice(1).reduce((e, t) => {
|
|
161
|
+
if (!e && !t)
|
|
156
162
|
return;
|
|
157
|
-
const s = ((
|
|
158
|
-
if (!e && ((
|
|
159
|
-
return
|
|
163
|
+
const s = ((t == null ? void 0 : t.length) ?? 0) > 0;
|
|
164
|
+
if (!e && ((t == null ? void 0 : t.length) ?? 0) > 0)
|
|
165
|
+
return t;
|
|
160
166
|
if (!s)
|
|
161
167
|
return e;
|
|
162
|
-
const o = (e ?? []).concat(
|
|
168
|
+
const o = (e ?? []).concat(t);
|
|
163
169
|
return le(o);
|
|
164
|
-
},
|
|
170
|
+
}, r[0]);
|
|
165
171
|
}
|
|
166
|
-
function ce(...
|
|
167
|
-
return
|
|
168
|
-
const o =
|
|
172
|
+
function ce(...r) {
|
|
173
|
+
return r.map((t) => Object.keys(t)).flat().reduce((t, s) => {
|
|
174
|
+
const o = r.map((n) => n[s]).filter(Boolean);
|
|
169
175
|
return {
|
|
170
|
-
...
|
|
176
|
+
...t,
|
|
171
177
|
[s]: I(...o)
|
|
172
178
|
};
|
|
173
179
|
}, {});
|
|
174
180
|
}
|
|
175
|
-
function
|
|
176
|
-
if (!
|
|
181
|
+
function O(...r) {
|
|
182
|
+
if (!r.length)
|
|
177
183
|
return {
|
|
178
184
|
general: [],
|
|
179
185
|
propertyErrors: {}
|
|
180
186
|
};
|
|
181
|
-
const e =
|
|
182
|
-
return
|
|
183
|
-
(
|
|
184
|
-
general: I(
|
|
185
|
-
propertyErrors: ce(
|
|
187
|
+
const e = r[0];
|
|
188
|
+
return r.length === 1 ? e : r.slice(1).reduce(
|
|
189
|
+
(t, s) => ({
|
|
190
|
+
general: I(t.general, s.general),
|
|
191
|
+
propertyErrors: ce(t.propertyErrors ?? {}, s.propertyErrors ?? {})
|
|
186
192
|
}),
|
|
187
193
|
e
|
|
188
194
|
);
|
|
189
195
|
}
|
|
190
|
-
function
|
|
196
|
+
function N(r) {
|
|
191
197
|
var s;
|
|
192
|
-
const e = (((s =
|
|
193
|
-
return e ||
|
|
198
|
+
const e = (((s = r.general) == null ? void 0 : s.length) ?? 0) > 0, t = Object.entries(r.propertyErrors).filter(([, o]) => o == null ? void 0 : o.length).length > 0;
|
|
199
|
+
return e || t;
|
|
194
200
|
}
|
|
195
|
-
function ue(
|
|
196
|
-
const e =
|
|
201
|
+
function ue(r) {
|
|
202
|
+
const e = r.issues.filter((s) => s.path.length === 0).map((s) => s.message), t = r.issues.filter((s) => s.path.length > 0).reduce((s, o) => {
|
|
197
203
|
const n = o.path.join(".");
|
|
198
204
|
return {
|
|
199
205
|
...s,
|
|
@@ -202,7 +208,7 @@ function ue(t) {
|
|
|
202
208
|
}, {});
|
|
203
209
|
return {
|
|
204
210
|
general: e,
|
|
205
|
-
propertyErrors:
|
|
211
|
+
propertyErrors: t
|
|
206
212
|
};
|
|
207
213
|
}
|
|
208
214
|
const m = {
|
|
@@ -219,10 +225,10 @@ class de {
|
|
|
219
225
|
async validate(e) {
|
|
220
226
|
if (!this.schema)
|
|
221
227
|
return m;
|
|
222
|
-
const
|
|
223
|
-
if (
|
|
228
|
+
const t = await this.schema.safeParseAsync(e);
|
|
229
|
+
if (t.success)
|
|
224
230
|
return m;
|
|
225
|
-
const s = ue(
|
|
231
|
+
const s = ue(t.error);
|
|
226
232
|
return {
|
|
227
233
|
isValid: !1,
|
|
228
234
|
errors: {
|
|
@@ -240,13 +246,13 @@ class fe {
|
|
|
240
246
|
if (!this.validateFn)
|
|
241
247
|
return m;
|
|
242
248
|
try {
|
|
243
|
-
const
|
|
244
|
-
return
|
|
245
|
-
} catch (
|
|
249
|
+
const t = await this.validateFn(e);
|
|
250
|
+
return t.isValid ? m : t;
|
|
251
|
+
} catch (t) {
|
|
246
252
|
return {
|
|
247
253
|
isValid: !1,
|
|
248
254
|
errors: {
|
|
249
|
-
general: [
|
|
255
|
+
general: [t.message || "Validation error"],
|
|
250
256
|
propertyErrors: {}
|
|
251
257
|
}
|
|
252
258
|
};
|
|
@@ -254,72 +260,72 @@ class fe {
|
|
|
254
260
|
}
|
|
255
261
|
}
|
|
256
262
|
class pe {
|
|
257
|
-
constructor(e,
|
|
263
|
+
constructor(e, t) {
|
|
258
264
|
E(this, "schemaValidator");
|
|
259
265
|
E(this, "functionValidator");
|
|
260
|
-
this.schema = e, this.validateFn =
|
|
266
|
+
this.schema = e, this.validateFn = t, this.schemaValidator = new de(this.schema), this.functionValidator = new fe(this.validateFn);
|
|
261
267
|
}
|
|
262
268
|
async validate(e) {
|
|
263
|
-
const [
|
|
269
|
+
const [t, s] = await Promise.all([
|
|
264
270
|
this.schemaValidator.validate(e),
|
|
265
271
|
this.functionValidator.validate(e)
|
|
266
272
|
]);
|
|
267
273
|
return {
|
|
268
|
-
isValid:
|
|
269
|
-
errors:
|
|
274
|
+
isValid: t.isValid && s.isValid,
|
|
275
|
+
errors: O(t.errors, s.errors)
|
|
270
276
|
};
|
|
271
277
|
}
|
|
272
278
|
}
|
|
273
|
-
function b(
|
|
279
|
+
function b(r) {
|
|
274
280
|
return c(() => new pe(
|
|
275
|
-
d(
|
|
276
|
-
d(
|
|
281
|
+
d(r.schema),
|
|
282
|
+
d(r.validateFn)
|
|
277
283
|
));
|
|
278
284
|
}
|
|
279
|
-
function he(
|
|
280
|
-
const
|
|
281
|
-
validators:
|
|
285
|
+
function he(r, e) {
|
|
286
|
+
const t = P({
|
|
287
|
+
validators: k([b(e)]),
|
|
282
288
|
isValidated: !1,
|
|
283
289
|
errors: d(e.errors) ?? m.errors
|
|
284
290
|
}), s = (i = m.errors) => {
|
|
285
|
-
|
|
291
|
+
t.errors = O(d(e.errors) ?? m.errors, i);
|
|
286
292
|
};
|
|
287
293
|
w(() => d(e.errors), async () => {
|
|
288
|
-
if (
|
|
294
|
+
if (t.isValidated) {
|
|
289
295
|
const i = await n();
|
|
290
296
|
s(i.errors);
|
|
291
297
|
} else
|
|
292
298
|
s();
|
|
293
299
|
}, { immediate: !0 }), w(
|
|
294
|
-
[() =>
|
|
300
|
+
[() => t.validators],
|
|
295
301
|
async (i) => {
|
|
296
|
-
if (
|
|
302
|
+
if (t.isValidated)
|
|
297
303
|
if (i) {
|
|
298
304
|
const a = await n();
|
|
299
|
-
|
|
305
|
+
t.errors = a.errors;
|
|
300
306
|
} else
|
|
301
|
-
|
|
307
|
+
t.errors = m.errors;
|
|
302
308
|
},
|
|
303
309
|
{ immediate: !0 }
|
|
304
|
-
), w(() =>
|
|
305
|
-
|
|
310
|
+
), w(() => r.data, () => {
|
|
311
|
+
t.isValidated && p();
|
|
306
312
|
});
|
|
307
313
|
const o = (i) => {
|
|
308
|
-
const a =
|
|
309
|
-
return
|
|
310
|
-
|
|
314
|
+
const a = D(i) ? i : b(i);
|
|
315
|
+
return t.validators.push(a), Q() && X(() => {
|
|
316
|
+
t.validators = t.validators.filter(
|
|
311
317
|
(u) => u !== a
|
|
312
318
|
);
|
|
313
319
|
}), a;
|
|
314
320
|
};
|
|
315
321
|
async function n() {
|
|
316
322
|
const i = await Promise.all(
|
|
317
|
-
|
|
323
|
+
t.validators.filter((v) => d(v) !== void 0).map((v) => d(v).validate(r.data))
|
|
318
324
|
), a = i.every((v) => v.isValid);
|
|
319
325
|
let { errors: u } = m;
|
|
320
326
|
if (!a) {
|
|
321
327
|
const v = i.map((F) => F.errors);
|
|
322
|
-
u =
|
|
328
|
+
u = O(...v);
|
|
323
329
|
}
|
|
324
330
|
return {
|
|
325
331
|
errors: u,
|
|
@@ -328,15 +334,15 @@ function he(t, e) {
|
|
|
328
334
|
}
|
|
329
335
|
const p = async () => {
|
|
330
336
|
const i = await n();
|
|
331
|
-
return s(i.errors),
|
|
332
|
-
isValid: !
|
|
333
|
-
errors:
|
|
337
|
+
return s(i.errors), t.isValidated = !0, {
|
|
338
|
+
isValid: !N(i.errors),
|
|
339
|
+
errors: t.errors
|
|
334
340
|
};
|
|
335
|
-
}, h = c(() => !
|
|
336
|
-
|
|
341
|
+
}, h = c(() => !N(t.errors)), V = () => {
|
|
342
|
+
t.isValidated = !1, t.errors = d(e.errors) ?? m.errors;
|
|
337
343
|
};
|
|
338
344
|
return {
|
|
339
|
-
...
|
|
345
|
+
...W(t),
|
|
340
346
|
validateForm: p,
|
|
341
347
|
defineValidator: o,
|
|
342
348
|
isValid: h,
|
|
@@ -344,14 +350,14 @@ function he(t, e) {
|
|
|
344
350
|
};
|
|
345
351
|
}
|
|
346
352
|
class ve {
|
|
347
|
-
constructor(e,
|
|
348
|
-
this.path = e, this.validator =
|
|
353
|
+
constructor(e, t) {
|
|
354
|
+
this.path = e, this.validator = t;
|
|
349
355
|
}
|
|
350
356
|
async validate(e) {
|
|
351
|
-
const
|
|
357
|
+
const t = _(e, this.path);
|
|
352
358
|
if (!this.validator)
|
|
353
359
|
return m;
|
|
354
|
-
const s = await this.validator.validate(
|
|
360
|
+
const s = await this.validator.validate(t);
|
|
355
361
|
return {
|
|
356
362
|
isValid: s.isValid,
|
|
357
363
|
errors: {
|
|
@@ -366,29 +372,29 @@ class ve {
|
|
|
366
372
|
};
|
|
367
373
|
}
|
|
368
374
|
}
|
|
369
|
-
function me(
|
|
370
|
-
const s = U(
|
|
375
|
+
function me(r, e, t) {
|
|
376
|
+
const s = U(r.data, e), o = c(() => _(r.initialData.value, e)), n = (l) => ({
|
|
371
377
|
...l,
|
|
372
378
|
path: c(() => d(l.path).replace(e + ".", "")),
|
|
373
379
|
setData: (f) => {
|
|
374
380
|
l.setData(f);
|
|
375
381
|
}
|
|
376
382
|
}), p = (l) => {
|
|
377
|
-
const f = R(e, l), y =
|
|
383
|
+
const f = R(e, l), y = r.getField(f);
|
|
378
384
|
return y ? n(y) : {};
|
|
379
385
|
}, h = (l) => {
|
|
380
|
-
const f = R(e, l.path), y =
|
|
386
|
+
const f = R(e, l.path), y = r.defineField({
|
|
381
387
|
...l,
|
|
382
388
|
path: f
|
|
383
389
|
});
|
|
384
390
|
return n(y);
|
|
385
|
-
}, V = c(() =>
|
|
391
|
+
}, V = c(() => r.fields.value.filter((l) => {
|
|
386
392
|
const f = l.path.value;
|
|
387
393
|
return f.startsWith(e + ".") || f === e;
|
|
388
|
-
}).map((l) => n(l))), i = () =>
|
|
394
|
+
}).map((l) => n(l))), i = () => r.fields.value.filter((l) => {
|
|
389
395
|
const f = l.path.value;
|
|
390
396
|
return f.startsWith(e + ".") || f === e;
|
|
391
|
-
}), a = c(() => i().some((l) => l.dirty.value)), u = c(() => i().some((l) => l.touched.value)), v = c(() =>
|
|
397
|
+
}), a = c(() => i().some((l) => l.dirty.value)), u = c(() => i().some((l) => l.touched.value)), v = c(() => r.isValid.value), F = c(() => r.isValidated.value), J = c(() => se(d(r.errors), e));
|
|
392
398
|
return {
|
|
393
399
|
data: s,
|
|
394
400
|
fields: V,
|
|
@@ -401,32 +407,32 @@ function me(t, e, r) {
|
|
|
401
407
|
isValidated: F,
|
|
402
408
|
errors: J,
|
|
403
409
|
defineValidator: (l) => {
|
|
404
|
-
const f =
|
|
410
|
+
const f = D(l) ? l : b(l), y = c(
|
|
405
411
|
() => new ve(e, d(f))
|
|
406
412
|
);
|
|
407
|
-
return
|
|
413
|
+
return r.defineValidator(y), f;
|
|
408
414
|
},
|
|
409
415
|
reset: () => i().forEach((l) => l.reset()),
|
|
410
|
-
validateForm: () =>
|
|
416
|
+
validateForm: () => r.validateForm(),
|
|
411
417
|
getSubForm: (l, f) => {
|
|
412
418
|
const y = R(e, l);
|
|
413
|
-
return
|
|
419
|
+
return r.getSubForm(
|
|
414
420
|
y,
|
|
415
421
|
f
|
|
416
422
|
);
|
|
417
423
|
}
|
|
418
424
|
};
|
|
419
425
|
}
|
|
420
|
-
function Pe(
|
|
421
|
-
const e = c(() => Object.freeze(g(
|
|
426
|
+
function Pe(r) {
|
|
427
|
+
const e = c(() => Object.freeze(g(r.initialData))), t = k(g(e)), s = P({
|
|
422
428
|
initialData: e,
|
|
423
|
-
data:
|
|
429
|
+
data: t
|
|
424
430
|
});
|
|
425
431
|
w(e, (a) => {
|
|
426
432
|
s.data = g(a);
|
|
427
433
|
});
|
|
428
|
-
const o = he(s,
|
|
429
|
-
|
|
434
|
+
const o = he(s, r), n = ne(s, o), p = ie(n), h = () => {
|
|
435
|
+
t.value = g(e), o.reset(), n.fields.value.forEach(
|
|
430
436
|
(a) => a.reset()
|
|
431
437
|
);
|
|
432
438
|
};
|
|
@@ -439,12 +445,12 @@ function Pe(t) {
|
|
|
439
445
|
...p,
|
|
440
446
|
reset: h,
|
|
441
447
|
getSubForm: V,
|
|
442
|
-
initialData:
|
|
443
|
-
data:
|
|
448
|
+
initialData: S(s, "initialData"),
|
|
449
|
+
data: S(s, "data")
|
|
444
450
|
};
|
|
445
451
|
return i;
|
|
446
452
|
}
|
|
447
|
-
const _e = /* @__PURE__ */
|
|
453
|
+
const _e = /* @__PURE__ */ $({
|
|
448
454
|
__name: "Field",
|
|
449
455
|
props: {
|
|
450
456
|
form: {},
|
|
@@ -453,13 +459,13 @@ const _e = /* @__PURE__ */ j({
|
|
|
453
459
|
path: {},
|
|
454
460
|
errors: {}
|
|
455
461
|
},
|
|
456
|
-
setup(
|
|
457
|
-
const e =
|
|
462
|
+
setup(r) {
|
|
463
|
+
const e = r, t = e.form.defineField({
|
|
458
464
|
path: e.path
|
|
459
|
-
}), s =
|
|
460
|
-
return (o, n) =>
|
|
465
|
+
}), s = P(t);
|
|
466
|
+
return (o, n) => j(o.$slots, "default", z(B(s)));
|
|
461
467
|
}
|
|
462
|
-
}), Se = /* @__PURE__ */
|
|
468
|
+
}), Se = /* @__PURE__ */ $({
|
|
463
469
|
inheritAttrs: !1,
|
|
464
470
|
__name: "FormFieldWrapper",
|
|
465
471
|
props: {
|
|
@@ -468,22 +474,22 @@ const _e = /* @__PURE__ */ j({
|
|
|
468
474
|
form: {},
|
|
469
475
|
path: {}
|
|
470
476
|
},
|
|
471
|
-
setup(
|
|
472
|
-
return (e,
|
|
477
|
+
setup(r) {
|
|
478
|
+
return (e, t) => {
|
|
473
479
|
const s = Y("Field");
|
|
474
|
-
return
|
|
480
|
+
return C(), A(s, {
|
|
475
481
|
form: e.form,
|
|
476
482
|
path: e.path
|
|
477
483
|
}, {
|
|
478
|
-
default:
|
|
479
|
-
(
|
|
484
|
+
default: M(({ errors: o, data: n, setData: p }) => [
|
|
485
|
+
(C(), A(x(e.component), ee({ ...e.componentProps, ...e.$attrs }, {
|
|
480
486
|
"model-value": n,
|
|
481
487
|
errors: o,
|
|
482
488
|
name: e.path,
|
|
483
489
|
"onUpdate:modelValue": p
|
|
484
490
|
}), {
|
|
485
|
-
default:
|
|
486
|
-
|
|
491
|
+
default: M(() => [
|
|
492
|
+
j(e.$slots, "default")
|
|
487
493
|
]),
|
|
488
494
|
_: 2
|
|
489
495
|
}, 1040, ["model-value", "errors", "name", "onUpdate:modelValue"]))
|
|
@@ -492,20 +498,20 @@ const _e = /* @__PURE__ */ j({
|
|
|
492
498
|
}, 8, ["form", "path"]);
|
|
493
499
|
};
|
|
494
500
|
}
|
|
495
|
-
}),
|
|
501
|
+
}), Oe = /* @__PURE__ */ $({
|
|
496
502
|
__name: "FormPart",
|
|
497
503
|
props: {
|
|
498
504
|
form: {},
|
|
499
505
|
path: {}
|
|
500
506
|
},
|
|
501
|
-
setup(
|
|
502
|
-
const e =
|
|
503
|
-
return (s, o) =>
|
|
507
|
+
setup(r) {
|
|
508
|
+
const e = r, t = c(() => e.form.getSubForm(e.path));
|
|
509
|
+
return (s, o) => j(s.$slots, "default", z(B({ subform: t.value })));
|
|
504
510
|
}
|
|
505
511
|
});
|
|
506
512
|
export {
|
|
507
513
|
_e as Field,
|
|
508
514
|
Se as FormFieldWrapper,
|
|
509
|
-
|
|
515
|
+
Oe as FormPart,
|
|
510
516
|
Pe as useForm
|
|
511
517
|
};
|
package/dist/utils/path.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Paths, PickProps, SplitPath } from '../types/util';
|
|
|
3
3
|
import { ErrorBag } from '../types/validation';
|
|
4
4
|
export declare function splitPath(path: string): string[];
|
|
5
5
|
export declare function getNestedValue<T, K extends Paths<T>>(obj: T, path: K | SplitPath<K>): PickProps<T, K>;
|
|
6
|
-
export declare function setNestedValue<T, K extends Paths<T>>(obj: T
|
|
6
|
+
export declare function setNestedValue<T, K extends Paths<T>>(obj: MaybeRef<T>, path: K | SplitPath<K>, value: PickProps<T, K>): void;
|
|
7
7
|
export declare const getLens: <T, K extends Paths<T>>(data: MaybeRef<T>, key: MaybeRef<K | SplitPath<K>>) => WritableComputedRef<PickProps<T, K>, PickProps<T, K>>;
|
|
8
8
|
type JoinPath<Base extends string, Sub extends string> = `${Base}${Base extends '' ? '' : Sub extends '' ? '' : '.'}${Sub}`;
|
|
9
9
|
export declare function joinPath<Base extends string, Sub extends string>(basePath: Base, subPath: Sub): JoinPath<Base, Sub>;
|
package/package.json
CHANGED
package/src/utils/path.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { computed, isRef,
|
|
1
|
+
import { computed, isRef, unref, type MaybeRef } from 'vue'
|
|
2
2
|
import type { Paths, PickProps, SplitPath } from '../types/util'
|
|
3
3
|
import type { ErrorBag, ValidationErrors } from '../types/validation'
|
|
4
4
|
|
|
@@ -17,19 +17,27 @@ export function getNestedValue<T, K extends Paths<T>>(obj: T, path: K | SplitPat
|
|
|
17
17
|
) as PickProps<T, K>
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
export function setNestedValue<T, K extends Paths<T>>(obj: T
|
|
20
|
+
export function setNestedValue<T, K extends Paths<T>>(obj: MaybeRef<T>, path: K | SplitPath<K>, value: PickProps<T, K>): void {
|
|
21
21
|
const keys = Array.isArray(path) ? path : splitPath(path)
|
|
22
22
|
|
|
23
23
|
const lastKey = keys.at(-1)!
|
|
24
|
-
const target = keys
|
|
25
|
-
.slice(0, -1)
|
|
26
|
-
.reduce(
|
|
27
|
-
(current, key) => current[key],
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
|
-
obj as Record<string, any>,
|
|
30
|
-
)
|
|
31
24
|
|
|
32
|
-
|
|
25
|
+
if (!lastKey && isRef(obj)) {
|
|
26
|
+
obj.value = value
|
|
27
|
+
} else if (!isRef(obj)) {
|
|
28
|
+
// We cannot do anything here as we have nothing we can assign to
|
|
29
|
+
return
|
|
30
|
+
} else {
|
|
31
|
+
const target = keys
|
|
32
|
+
.slice(0, -1)
|
|
33
|
+
.reduce(
|
|
34
|
+
(current, key) => current[key],
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
|
+
unref(obj) as Record<string, any>,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
target[lastKey] = value
|
|
40
|
+
}
|
|
33
41
|
}
|
|
34
42
|
|
|
35
43
|
export const getLens = <T, K extends Paths<T>>(data: MaybeRef<T>, key: MaybeRef<K | SplitPath<K>>) => {
|
|
@@ -38,7 +46,7 @@ export const getLens = <T, K extends Paths<T>>(data: MaybeRef<T>, key: MaybeRef<
|
|
|
38
46
|
return getNestedValue(unref(data), unref(key))
|
|
39
47
|
},
|
|
40
48
|
set(value: PickProps<T, K>) {
|
|
41
|
-
setNestedValue(
|
|
49
|
+
setNestedValue(data, unref(key), value)
|
|
42
50
|
},
|
|
43
51
|
})
|
|
44
52
|
}
|