@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 CHANGED
@@ -1,51 +1,57 @@
1
1
  var T = Object.defineProperty;
2
- var G = (t, e, r) => e in t ? T(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
- var E = (t, e, r) => G(t, typeof e != "symbol" ? e + "" : e, r);
4
- import { toValue as L, toRaw as Z, computed as c, unref as d, reactive as D, toRefs as N, shallowReactive as q, toRef as _, onScopeDispose as H, ref as W, watch as w, isRef as k, getCurrentScope as Q, onBeforeUnmount as X, defineComponent as j, renderSlot as O, normalizeProps as z, guardReactiveProps as B, resolveComponent as Y, createBlock as $, openBlock as A, withCtx as C, resolveDynamicComponent as x, mergeProps as ee } from "vue";
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(t) {
8
- const e = L(t), r = Z(e);
9
- return re(r);
7
+ function g(r) {
8
+ const e = L(r), t = Z(e);
9
+ return re(t);
10
10
  }
11
- function K(t) {
12
- return t === "" ? [] : t.split(/\s*\.\s*/).filter(Boolean);
11
+ function K(r) {
12
+ return r === "" ? [] : r.split(/\s*\.\s*/).filter(Boolean);
13
13
  }
14
- function P(t, e) {
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
- t
17
+ r
18
18
  );
19
19
  }
20
- function te(t, e, r) {
21
- const s = Array.isArray(e) ? e : K(e), o = s.at(-1), n = s.slice(0, -1).reduce(
22
- (p, h) => p[h],
23
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
24
- t
25
- );
26
- n[o] = o ? r : n;
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 = (t, e) => c({
34
+ const U = (r, e) => c({
29
35
  get() {
30
- return P(d(t), d(e));
36
+ return _(d(r), d(e));
31
37
  },
32
- set(r) {
33
- te(d(t), d(e), r);
38
+ set(t) {
39
+ te(r, d(e), t);
34
40
  }
35
41
  });
36
- function R(t, e) {
37
- return !t && !e ? "" : !t && e ? e : !e && t ? t : `${t}.${e}`;
42
+ function R(r, e) {
43
+ return !r && !e ? "" : !r && e ? e : !e && r ? r : `${r}.${e}`;
38
44
  }
39
- function se(t, e) {
45
+ function se(r, e) {
40
46
  if (!e)
41
- return t;
42
- const r = `${e}.`, s = Object.fromEntries(
43
- Object.entries(t.propertyErrors).filter(([o]) => o.startsWith(r)).map(
44
- ([o, n]) => [o.slice(r.length), n]
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: t.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(t) {
66
- const e = D({
67
- value: t.value,
68
- path: t.path,
69
- initialValue: c(() => Object.freeze(g(t.initialValue))),
70
- errors: t.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
- }), r = c(() => JSON.stringify(e.value) !== JSON.stringify(e.initialValue)), s = (a) => {
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 = N(e);
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: r,
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(t, e) {
100
- const r = /* @__PURE__ */ new Map(), s = q(/* @__PURE__ */ new Map()), o = (a) => {
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
- r.has(a) ? (u = r.get(a)) == null || u.inc() : r.set(a, new ae(() => n(a)));
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
- r.has(a) && ((u = r.get(a)) == null || u.dec());
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(_(t, "data"), a),
116
- initialValue: c(() => P(t.initialData, a)),
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(t) {
142
- const e = c(() => t.fields.value.some((s) => d(s.dirty))), r = c(() => t.fields.value.some((s) => d(s.touched)));
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: r
151
+ isTouched: t
146
152
  };
147
153
  }
148
- function le(t) {
149
- return t.filter(
150
- (e, r, s) => s.indexOf(e) === r
154
+ function le(r) {
155
+ return r.filter(
156
+ (e, t, s) => s.indexOf(e) === t
151
157
  );
152
158
  }
153
- function I(...t) {
154
- return t.slice(1).reduce((e, r) => {
155
- if (!e && !r)
159
+ function I(...r) {
160
+ return r.slice(1).reduce((e, t) => {
161
+ if (!e && !t)
156
162
  return;
157
- const s = ((r == null ? void 0 : r.length) ?? 0) > 0;
158
- if (!e && ((r == null ? void 0 : r.length) ?? 0) > 0)
159
- return r;
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(r);
168
+ const o = (e ?? []).concat(t);
163
169
  return le(o);
164
- }, t[0]);
170
+ }, r[0]);
165
171
  }
166
- function ce(...t) {
167
- return t.map((r) => Object.keys(r)).flat().reduce((r, s) => {
168
- const o = t.map((n) => n[s]).filter(Boolean);
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
- ...r,
176
+ ...t,
171
177
  [s]: I(...o)
172
178
  };
173
179
  }, {});
174
180
  }
175
- function S(...t) {
176
- if (!t.length)
181
+ function O(...r) {
182
+ if (!r.length)
177
183
  return {
178
184
  general: [],
179
185
  propertyErrors: {}
180
186
  };
181
- const e = t[0];
182
- return t.length === 1 ? e : t.slice(1).reduce(
183
- (r, s) => ({
184
- general: I(r.general, s.general),
185
- propertyErrors: ce(r.propertyErrors ?? {}, s.propertyErrors ?? {})
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 M(t) {
196
+ function N(r) {
191
197
  var s;
192
- const e = (((s = t.general) == null ? void 0 : s.length) ?? 0) > 0, r = Object.entries(t.propertyErrors).filter(([, o]) => o == null ? void 0 : o.length).length > 0;
193
- return e || r;
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(t) {
196
- const e = t.issues.filter((s) => s.path.length === 0).map((s) => s.message), r = t.issues.filter((s) => s.path.length > 0).reduce((s, o) => {
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: r
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 r = await this.schema.safeParseAsync(e);
223
- if (r.success)
228
+ const t = await this.schema.safeParseAsync(e);
229
+ if (t.success)
224
230
  return m;
225
- const s = ue(r.error);
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 r = await this.validateFn(e);
244
- return r.isValid ? m : r;
245
- } catch (r) {
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: [r.message || "Validation error"],
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, r) {
263
+ constructor(e, t) {
258
264
  E(this, "schemaValidator");
259
265
  E(this, "functionValidator");
260
- this.schema = e, this.validateFn = r, this.schemaValidator = new de(this.schema), this.functionValidator = new fe(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 [r, s] = await Promise.all([
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: r.isValid && s.isValid,
269
- errors: S(r.errors, s.errors)
274
+ isValid: t.isValid && s.isValid,
275
+ errors: O(t.errors, s.errors)
270
276
  };
271
277
  }
272
278
  }
273
- function b(t) {
279
+ function b(r) {
274
280
  return c(() => new pe(
275
- d(t.schema),
276
- d(t.validateFn)
281
+ d(r.schema),
282
+ d(r.validateFn)
277
283
  ));
278
284
  }
279
- function he(t, e) {
280
- const r = D({
281
- validators: W([b(e)]),
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
- r.errors = S(d(e.errors) ?? m.errors, i);
291
+ t.errors = O(d(e.errors) ?? m.errors, i);
286
292
  };
287
293
  w(() => d(e.errors), async () => {
288
- if (r.isValidated) {
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
- [() => r.validators],
300
+ [() => t.validators],
295
301
  async (i) => {
296
- if (r.isValidated)
302
+ if (t.isValidated)
297
303
  if (i) {
298
304
  const a = await n();
299
- r.errors = a.errors;
305
+ t.errors = a.errors;
300
306
  } else
301
- r.errors = m.errors;
307
+ t.errors = m.errors;
302
308
  },
303
309
  { immediate: !0 }
304
- ), w(() => t.data, () => {
305
- r.isValidated && p();
310
+ ), w(() => r.data, () => {
311
+ t.isValidated && p();
306
312
  });
307
313
  const o = (i) => {
308
- const a = k(i) ? i : b(i);
309
- return r.validators.push(a), Q() && X(() => {
310
- r.validators = r.validators.filter(
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
- r.validators.filter((v) => d(v) !== void 0).map((v) => d(v).validate(t.data))
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 = S(...v);
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), r.isValidated = !0, {
332
- isValid: !M(i.errors),
333
- errors: r.errors
337
+ return s(i.errors), t.isValidated = !0, {
338
+ isValid: !N(i.errors),
339
+ errors: t.errors
334
340
  };
335
- }, h = c(() => !M(r.errors)), V = () => {
336
- r.isValidated = !1, r.errors = d(e.errors) ?? m.errors;
341
+ }, h = c(() => !N(t.errors)), V = () => {
342
+ t.isValidated = !1, t.errors = d(e.errors) ?? m.errors;
337
343
  };
338
344
  return {
339
- ...N(r),
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, r) {
348
- this.path = e, this.validator = r;
353
+ constructor(e, t) {
354
+ this.path = e, this.validator = t;
349
355
  }
350
356
  async validate(e) {
351
- const r = P(e, this.path);
357
+ const t = _(e, this.path);
352
358
  if (!this.validator)
353
359
  return m;
354
- const s = await this.validator.validate(r);
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(t, e, r) {
370
- const s = U(t.data, e), o = c(() => P(t.initialData.value, e)), n = (l) => ({
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 = t.getField(f);
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 = t.defineField({
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(() => t.fields.value.filter((l) => {
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 = () => t.fields.value.filter((l) => {
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(() => t.isValid.value), F = c(() => t.isValidated.value), J = c(() => se(d(t.errors), e));
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 = k(l) ? l : b(l), y = c(
410
+ const f = D(l) ? l : b(l), y = c(
405
411
  () => new ve(e, d(f))
406
412
  );
407
- return t.defineValidator(y), f;
413
+ return r.defineValidator(y), f;
408
414
  },
409
415
  reset: () => i().forEach((l) => l.reset()),
410
- validateForm: () => t.validateForm(),
416
+ validateForm: () => r.validateForm(),
411
417
  getSubForm: (l, f) => {
412
418
  const y = R(e, l);
413
- return t.getSubForm(
419
+ return r.getSubForm(
414
420
  y,
415
421
  f
416
422
  );
417
423
  }
418
424
  };
419
425
  }
420
- function Pe(t) {
421
- const e = c(() => Object.freeze(g(t.initialData))), r = W(g(e)), s = D({
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: r
429
+ data: t
424
430
  });
425
431
  w(e, (a) => {
426
432
  s.data = g(a);
427
433
  });
428
- const o = he(s, t), n = ne(s, o), p = ie(n), h = () => {
429
- r.value = g(e), o.reset(), n.fields.value.forEach(
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: _(s, "initialData"),
443
- data: _(s, "data")
448
+ initialData: S(s, "initialData"),
449
+ data: S(s, "data")
444
450
  };
445
451
  return i;
446
452
  }
447
- const _e = /* @__PURE__ */ j({
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(t) {
457
- const e = t, r = e.form.defineField({
462
+ setup(r) {
463
+ const e = r, t = e.form.defineField({
458
464
  path: e.path
459
- }), s = D(r);
460
- return (o, n) => O(o.$slots, "default", z(B(s)));
465
+ }), s = P(t);
466
+ return (o, n) => j(o.$slots, "default", z(B(s)));
461
467
  }
462
- }), Se = /* @__PURE__ */ j({
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(t) {
472
- return (e, r) => {
477
+ setup(r) {
478
+ return (e, t) => {
473
479
  const s = Y("Field");
474
- return A(), $(s, {
480
+ return C(), A(s, {
475
481
  form: e.form,
476
482
  path: e.path
477
483
  }, {
478
- default: C(({ errors: o, data: n, setData: p }) => [
479
- (A(), $(x(e.component), ee({ ...e.componentProps, ...e.$attrs }, {
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: C(() => [
486
- O(e.$slots, "default")
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
- }), be = /* @__PURE__ */ j({
501
+ }), Oe = /* @__PURE__ */ $({
496
502
  __name: "FormPart",
497
503
  props: {
498
504
  form: {},
499
505
  path: {}
500
506
  },
501
- setup(t) {
502
- const e = t, r = c(() => e.form.getSubForm(e.path));
503
- return (s, o) => O(s.$slots, "default", z(B({ subform: r.value })));
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
- be as FormPart,
515
+ Oe as FormPart,
510
516
  Pe as useForm
511
517
  };
@@ -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, path: K | SplitPath<K>, value: PickProps<T, K>): void;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamnovu/kit-vue-forms",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
package/src/utils/path.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { computed, isRef, reactive, shallowRef, triggerRef, unref, watch, type MaybeRef } from 'vue'
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, path: K | SplitPath<K>, value: PickProps<T, K>): void {
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
- target[lastKey] = lastKey ? value : target
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(unref(data), unref(key), value)
49
+ setNestedValue(data, unref(key), value)
42
50
  },
43
51
  })
44
52
  }