@teamnovu/kit-vue-forms 0.0.18 → 0.0.20

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,11 +1,12 @@
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 _ = (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 E, toRefs as N, toRef as D, 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";
3
+ var D = (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 E, 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 structuredClone(t);
9
+ return x(t);
9
10
  }
10
11
  function K(e) {
11
12
  return e === "" ? [] : e.split(/\s*\.\s*/).filter(Boolean);
@@ -16,7 +17,7 @@ function w(e, r) {
16
17
  e
17
18
  );
18
19
  }
19
- function x(e, r, t) {
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");
@@ -32,13 +33,13 @@ const U = (e, r) => u({
32
33
  return w(d(e), d(r));
33
34
  },
34
35
  set(t) {
35
- x(d(e), d(r), t);
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 rr(e, r) {
42
+ function er(e, r) {
42
43
  if (!r)
43
44
  return e;
44
45
  const t = `${r}.`, s = Object.fromEntries(
@@ -52,7 +53,7 @@ function rr(e, r) {
52
53
  propertyErrors: s
53
54
  };
54
55
  }
55
- function er(e) {
56
+ function tr(e) {
56
57
  const r = E({
57
58
  value: e.value,
58
59
  path: e.path,
@@ -86,15 +87,15 @@ function er(e) {
86
87
  clearErrors: n
87
88
  };
88
89
  }
89
- function tr(e, r) {
90
+ function sr(e, r) {
90
91
  const t = {}, s = (c) => {
91
92
  const n = d(c.path);
92
93
  t[n] = c;
93
94
  }, a = (c) => {
94
95
  if (!t[c]) {
95
- const n = er({
96
+ const n = tr({
96
97
  path: c,
97
- value: U(D(e, "data"), c),
98
+ value: U(_(e, "data"), c),
98
99
  initialValue: u(() => w(e.initialData, c)),
99
100
  errors: u({
100
101
  get() {
@@ -117,14 +118,14 @@ function tr(e, r) {
117
118
  defineField: (c) => a(c.path)
118
119
  };
119
120
  }
120
- function sr(e) {
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 ar(e) {
128
+ function or(e) {
128
129
  return e.filter(
129
130
  (r, t, s) => s.indexOf(r) === t
130
131
  );
@@ -139,10 +140,10 @@ function k(...e) {
139
140
  if (!s)
140
141
  return r;
141
142
  const a = (r ?? []).concat(t);
142
- return ar(a);
143
+ return or(a);
143
144
  }, e[0]);
144
145
  }
145
- function or(...e) {
146
+ function nr(...e) {
146
147
  return e.map((t) => Object.keys(t)).flat().reduce((t, s) => {
147
148
  const a = e.map((o) => o[s]).filter(Boolean);
148
149
  return {
@@ -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: or(t.propertyErrors ?? {}, s.propertyErrors ?? {})
165
+ propertyErrors: nr(t.propertyErrors ?? {}, s.propertyErrors ?? {})
165
166
  }),
166
167
  r
167
168
  );
@@ -171,7 +172,7 @@ 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 nr(e) {
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
177
  const o = a.path.join(".");
177
178
  return {
@@ -191,7 +192,7 @@ const m = {
191
192
  propertyErrors: {}
192
193
  }
193
194
  };
194
- class ir {
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 = nr(t.error);
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 lr {
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 cr {
236
+ class ur {
236
237
  constructor(r, t) {
237
- _(this, "schemaValidator");
238
- _(this, "functionValidator");
239
- this.schema = r, this.validateFn = t, this.schemaValidator = new ir(this.schema), this.functionValidator = new lr(this.validateFn);
238
+ D(this, "schemaValidator");
239
+ D(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([
@@ -250,12 +251,12 @@ class cr {
250
251
  }
251
252
  }
252
253
  function b(e) {
253
- return u(() => new cr(
254
+ return u(() => new ur(
254
255
  d(e.schema),
255
256
  d(e.validateFn)
256
257
  ));
257
258
  }
258
- function ur(e, r) {
259
+ function dr(e, r) {
259
260
  const t = E({
260
261
  validators: W([b(r)]),
261
262
  isValidated: !1,
@@ -316,7 +317,7 @@ function ur(e, r) {
316
317
  isValid: c
317
318
  };
318
319
  }
319
- class dr {
320
+ class fr {
320
321
  constructor(r, t) {
321
322
  this.path = r, this.validator = t;
322
323
  }
@@ -339,7 +340,7 @@ class dr {
339
340
  };
340
341
  }
341
342
  }
342
- function fr(e, r, t) {
343
+ function pr(e, r, t) {
343
344
  const s = U(e.data, r), a = u(() => w(e.initialData.value, r)), o = (i) => ({
344
345
  ...i,
345
346
  path: u(() => d(i.path).replace(r + ".", "")),
@@ -361,7 +362,7 @@ function fr(e, r, t) {
361
362
  }).map((i) => o(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)), P = u(() => e.isValid.value), I = u(() => e.isValidated.value), J = u(() => rr(d(e.errors), r));
365
+ }), f = u(() => l().some((i) => i.dirty.value)), v = u(() => l().some((i) => i.touched.value)), P = 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,
@@ -375,7 +376,7 @@ function fr(e, r, t) {
375
376
  errors: J,
376
377
  defineValidator: (i) => {
377
378
  const p = z(i) ? i : b(i), V = u(
378
- () => new dr(r, d(p))
379
+ () => new fr(r, d(p))
379
380
  );
380
381
  return e.defineValidator(V), p;
381
382
  },
@@ -390,7 +391,7 @@ function fr(e, r, t) {
390
391
  }
391
392
  };
392
393
  }
393
- function Fr(e) {
394
+ function wr(e) {
394
395
  const r = u(() => Object.freeze(g(e.initialData))), t = W(g(r)), s = E({
395
396
  initialData: r,
396
397
  data: t
@@ -398,13 +399,13 @@ function Fr(e) {
398
399
  y(r, (f) => {
399
400
  s.data = g(f);
400
401
  });
401
- const a = ur(s, e), o = tr(s, a), h = sr(o), c = () => {
402
+ const a = dr(s, e), o = sr(s, a), h = ar(o), c = () => {
402
403
  t.value = g(r), o.getFields().forEach(
403
404
  (f) => f.reset()
404
405
  );
405
406
  };
406
407
  function n(f, v) {
407
- return fr(l, f);
408
+ return pr(l, f);
408
409
  }
409
410
  const l = {
410
411
  ...o,
@@ -412,12 +413,12 @@ function Fr(e) {
412
413
  ...h,
413
414
  reset: c,
414
415
  getSubForm: n,
415
- initialData: D(s, "initialData"),
416
- data: D(s, "data")
416
+ initialData: _(s, "initialData"),
417
+ data: _(s, "data")
417
418
  };
418
419
  return l;
419
420
  }
420
- const Er = /* @__PURE__ */ S({
421
+ const Pr = /* @__PURE__ */ S({
421
422
  __name: "Field",
422
423
  props: {
423
424
  form: {},
@@ -432,7 +433,7 @@ const Er = /* @__PURE__ */ S({
432
433
  }), s = E(t);
433
434
  return (a, o) => j(a.$slots, "default", M(B(s)));
434
435
  }
435
- }), wr = /* @__PURE__ */ S({
436
+ }), Dr = /* @__PURE__ */ S({
436
437
  inheritAttrs: !1,
437
438
  __name: "FormFieldWrapper",
438
439
  props: {
@@ -465,7 +466,7 @@ const Er = /* @__PURE__ */ S({
465
466
  }, 8, ["form", "path"]);
466
467
  };
467
468
  }
468
- }), Pr = /* @__PURE__ */ S({
469
+ }), _r = /* @__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
- Er as Field,
481
- wr as FormFieldWrapper,
482
- Pr as FormPart,
483
- Fr as useForm
481
+ Pr as Field,
482
+ Dr as FormFieldWrapper,
483
+ _r as FormPart,
484
+ wr as useForm
484
485
  };
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@teamnovu/kit-vue-forms",
3
- "version": "0.0.18",
3
+ "version": "0.0.20",
4
4
  "description": "",
5
- "main": "index.js",
5
+ "main": "dist/index.js",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  ".": {
9
9
  "types": "./dist/index.d.ts",
10
- "import": "./dist/index.mjs"
10
+ "import": "./dist/index.js"
11
11
  }
12
12
  },
13
13
  "keywords": [
@@ -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
  },
@@ -1,7 +1,8 @@
1
- import { toRaw, toValue, type MaybeRefOrGetter } from 'vue'
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 structuredClone(raw) as T
7
+ return cloneDeep(raw) as T
7
8
  }