adverich-kun-ui 0.1.479 → 0.1.481

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.
@@ -1,5 +1,5 @@
1
- import { ref as l, provide as s, createElementBlock as h, openBlock as y, mergeProps as x, withModifiers as S, renderSlot as w } from "vue";
2
- const b = {
1
+ import { ref as u, computed as b, provide as w, watch as x, createElementBlock as S, openBlock as E, mergeProps as F, withModifiers as O, renderSlot as _ } from "vue";
2
+ const k = {
3
3
  __name: "KunForm",
4
4
  props: {
5
5
  gap: {
@@ -13,51 +13,77 @@ const b = {
13
13
  maxWidth: {
14
14
  type: String,
15
15
  default: "max-w-full"
16
+ },
17
+ modelValue: {
18
+ // v-model para exponer validez
19
+ type: Boolean,
20
+ default: !0
21
+ },
22
+ validateOn: {
23
+ // submit, lazy, input
24
+ type: String,
25
+ default: "submit"
16
26
  }
17
27
  },
18
- emits: ["submit"],
19
- setup(o, { expose: u, emit: f }) {
20
- const i = o, d = f, a = l([]), r = l(!0);
21
- function p(e) {
22
- a.value.push(e);
28
+ emits: ["update:modelValue", "submit"],
29
+ setup(s, { expose: d, emit: f }) {
30
+ const i = s, n = f, a = u([]), l = u(!0), c = u(!1), p = u(null), m = b(() => l.value);
31
+ function v(e) {
32
+ a.value.includes(e) || a.value.push(e);
23
33
  }
24
- function c(e) {
34
+ function y(e) {
25
35
  a.value = a.value.filter((t) => t !== e);
26
36
  }
27
- async function n() {
37
+ async function o() {
28
38
  const e = await Promise.all(
29
- a.value.map(async (t) => await t.validate())
39
+ a.value.map(async (t) => typeof t.validate == "function" ? await t.validate() : !0)
30
40
  );
31
- return r.value = e.every((t) => t === !0), { valid: r.value };
41
+ return l.value = e.every((t) => t === !0), n("update:modelValue", l.value), { valid: l.value };
32
42
  }
33
- function m() {
43
+ function g() {
34
44
  a.value.forEach((e) => {
35
- e.reset && e.reset();
36
- });
45
+ typeof e.reset == "function" && e.reset();
46
+ }), r();
37
47
  }
38
- function v() {
48
+ function r() {
39
49
  a.value.forEach((e) => {
40
- e.resetValidation && e.resetValidation();
41
- });
42
- }
43
- function g(e) {
44
- e && typeof e.preventDefault == "function" && e.preventDefault(), n().then(({ valid: t }) => {
45
- t && d("submit", e);
46
- });
47
- }
48
- return s("registerField", p), s("unregisterField", c), u({
49
- validate: n,
50
- reset: m,
51
- resetValidation: v
52
- }), (e, t) => (y(), h("form", x({
53
- onSubmit: S(g, ["prevent"]),
50
+ typeof e.resetValidation == "function" && e.resetValidation();
51
+ }), l.value = !0, n("update:modelValue", !0);
52
+ }
53
+ async function h(e) {
54
+ if (i.validateOn === "submit") {
55
+ const { valid: t } = await o();
56
+ t && n("submit", e);
57
+ } else
58
+ n("submit", e);
59
+ }
60
+ function V() {
61
+ i.validateOn === "input" && o();
62
+ }
63
+ return w("kunForm", {
64
+ registerField: v,
65
+ unregisterField: y,
66
+ onFieldChange: V,
67
+ validateOn: i.validateOn
68
+ }), d({
69
+ validate: o,
70
+ reset: g,
71
+ resetValidation: r,
72
+ valid: m,
73
+ isDirty: c
74
+ }), x(l, (e) => {
75
+ n("update:modelValue", e);
76
+ }), (e, t) => (E(), S("form", F({
77
+ ref_key: "formEl",
78
+ ref: p,
79
+ class: `flex flex-col w-full ${i.gap} ${i.padding} ${i.maxWidth}`,
54
80
  novalidate: "",
55
- class: `flex flex-col w-full ${i.gap} ${i.padding} ${i.maxWidth}`
81
+ onSubmit: O(h, ["prevent"])
56
82
  }, e.$attrs), [
57
- w(e.$slots, "default")
83
+ _(e.$slots, "default")
58
84
  ], 16));
59
85
  }
60
86
  };
61
87
  export {
62
- b as default
88
+ k as default
63
89
  };
@@ -1,69 +1,68 @@
1
- import { ref as w, computed as q, watch as G, nextTick as T } from "vue";
2
- import { format as d, clamp as x, toRawNumberString as D, fromRawString as y } from "./numberFormatUtils.js";
3
- function W(i, s) {
4
- const l = w(""), c = w(null), k = w(null), R = w(!1), m = w(0);
1
+ import { ref as S, computed as q, watch as G, nextTick as y } from "vue";
2
+ import { format as h, clamp as x, toRawNumberString as D, fromRawString as C } from "./numberFormatUtils.js";
3
+ function W(i, o) {
4
+ const l = S(""), c = S(null), k = S(null), R = S(!1), s = S(0);
5
5
  let t = "";
6
6
  const F = q(() => {
7
7
  const e = Number(i.precision);
8
8
  return e > 0 ? e + 1 : 1;
9
9
  });
10
- function h(e) {
10
+ function v(e) {
11
11
  return Number(i.precision) === 0 ? e === "" ? "0" : e.replace(/^0+(\d)/, "$1") : e.padStart(F.value, "0");
12
12
  }
13
13
  G(
14
14
  [() => i.modelValue, () => i.precision],
15
15
  ([e, n], [r, u]) => {
16
- const N = Number(n) !== Number(u);
17
16
  if (e == null || isNaN(e))
18
- l.value = d(0, { ...i, precision: n }), t = "0".repeat(Number(n) + 1);
17
+ l.value = h(0, { ...i, precision: n }), t = "0".repeat(Number(n) + 1);
19
18
  else {
20
- const v = parseFloat(e), o = x(v, i.min, i.max);
21
- N && (t = D(o, Number(n))), t.length < Number(n) + 1 && (t = t.padStart(Number(n) + 1, "0")), l.value = d(o, { ...i, precision: n });
19
+ const N = parseFloat(e), g = x(N, i.min, i.max);
20
+ t = D(g, Number(n)), t.length < Number(n) + 1 && (t = t.padStart(Number(n) + 1, "0")), l.value = h(g, { ...i, precision: n });
22
21
  }
23
22
  },
24
23
  { immediate: !0 }
25
24
  );
26
25
  function K(e) {
27
- const { key: n, target: r } = e, u = /^[0-9]$/.test(n), N = n === "Backspace", v = n === "Delete", o = ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(n), b = e.ctrlKey || e.metaKey, f = n === "Home", U = n === "End";
26
+ const { key: n, target: r } = e, u = /^[0-9]$/.test(n), N = n === "Backspace", g = n === "Delete", b = ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(n), d = e.ctrlKey || e.metaKey, m = n === "Home", U = n === "End";
28
27
  if (n === "Tab")
29
28
  return;
30
- if (f) {
31
- T(() => {
29
+ if (m) {
30
+ y(() => {
32
31
  if (!c.value) return;
33
- const S = l.value.search(/\d/);
34
- c.value.setSelectionRange(S, S);
32
+ const w = l.value.search(/\d/);
33
+ c.value.setSelectionRange(w, w);
35
34
  });
36
35
  return;
37
36
  }
38
37
  if (U) {
39
- T(() => {
38
+ y(() => {
40
39
  if (!c.value) return;
41
40
  const a = l.value;
42
41
  c.value.setSelectionRange(a.length, a.length);
43
42
  });
44
43
  return;
45
44
  }
46
- if (o || b) return;
45
+ if (b || d) return;
47
46
  const V = B(l.value, r.selectionStart);
48
47
  e.preventDefault();
49
48
  const L = Number(i.precision) + 1;
50
49
  for (; t.length < L; )
51
50
  t = "0" + t;
52
- const g = A(l.value, V);
51
+ const f = A(l.value, V);
53
52
  if (u)
54
- t = t.substring(0, g) + n + t.substring(g), m.value = g + 1;
53
+ t = t.substring(0, f) + n + t.substring(f), s.value = f + 1;
55
54
  else if (N && V > 0) {
56
- const a = A(l.value, V), S = a - 1;
55
+ const a = A(l.value, V), w = a - 1;
57
56
  if (t.length <= Number(i.precision) + 1) {
58
57
  const j = Math.max(0, a - 1);
59
- t = t.slice(0, j) + t.slice(a), t = h(t), m.value = a, C();
58
+ t = t.slice(0, j) + t.slice(a), t = v(t), s.value = a, T();
60
59
  return;
61
60
  }
62
- a > 0 && (t = t.slice(0, S) + t.slice(a), t = h(t), m.value = S);
63
- } else v && V < l.value.length && g < t.length && (t = t.substring(0, g) + t.substring(g + 1), m.value = g);
64
- for (t = h(t); t.length < L; )
61
+ a > 0 && (t = t.slice(0, w) + t.slice(a), t = v(t), s.value = w);
62
+ } else g && V < l.value.length && f < t.length && (t = t.substring(0, f) + t.substring(f + 1), s.value = f);
63
+ for (t = v(t); t.length < L; )
65
64
  t = "0" + t;
66
- C();
65
+ T();
67
66
  }
68
67
  function A(e, n) {
69
68
  let r = 0;
@@ -93,45 +92,45 @@ function W(i, s) {
93
92
  const r = e.search(/\d/);
94
93
  return n < r && (n = r), n;
95
94
  }
96
- function C() {
95
+ function T() {
97
96
  const e = Number(i.precision) + 1;
98
97
  t.padStart(e, "0");
99
- const n = Math.max(1, t.length - Number(i.precision)), r = t.slice(0, n) || "0", u = t.slice(n).padEnd(Number(i.precision), "0").slice(0, Number(i.precision)), N = `${r}.${u}`, v = parseFloat(N), o = x(v, i.min, i.max);
100
- t = D(o, Number(i.precision)), l.value = d(o, i), s("update:modelValue", o), s("input", o), T(() => {
98
+ const n = Math.max(1, t.length - Number(i.precision)), r = t.slice(0, n) || "0", u = t.slice(n).padEnd(Number(i.precision), "0").slice(0, Number(i.precision)), N = `${r}.${u}`, g = parseFloat(N), b = x(g, i.min, i.max);
99
+ t = D(b, Number(i.precision)), l.value = h(b, i), o("update:modelValue", b), o("input", b), y(() => {
101
100
  if (c.value)
102
101
  try {
103
- const b = l.value;
104
- let f = $(b, m.value);
105
- for (; f < b.length && !/\d/.test(b[f]); )
106
- f++;
107
- c.value.setSelectionRange(f, f);
102
+ const d = l.value;
103
+ let m = $(d, s.value);
104
+ for (; m < d.length && !/\d/.test(d[m]); )
105
+ m++;
106
+ c.value.setSelectionRange(m, m);
108
107
  } catch {
109
108
  c.value.setSelectionRange(l.value.length, l.value.length);
110
109
  }
111
110
  });
112
111
  }
113
112
  function E() {
114
- R.value = !1, t = h(t);
115
- const e = y(t, Number(i.precision)), n = x(e, i.min, i.max);
116
- t = D(n, Number(i.precision)), t = h(t), l.value = d(n, i), s("update:modelValue", n), s("blur");
113
+ R.value = !1, t = v(t);
114
+ const e = C(t, Number(i.precision)), n = x(e, i.min, i.max);
115
+ t = D(n, Number(i.precision)), t = v(t), l.value = h(n, i), o("update:modelValue", n), o("blur");
117
116
  }
118
117
  function M() {
119
118
  var n;
120
119
  R.value = !0;
121
120
  const e = ((n = c.value) == null ? void 0 : n.selectionStart) || 0;
122
- m.value = A(l.value, e), s("focus");
121
+ s.value = A(l.value, e), o("focus");
123
122
  }
124
123
  function H() {
125
- let e = y(t, Number(i.precision)) || 0;
126
- e = x(e + Number(i.step), i.min, i.max), t = D(e, Number(i.precision)), l.value = d(e, i), s("update:modelValue", e);
124
+ let e = C(t, Number(i.precision)) || 0;
125
+ e = x(e + Number(i.step), i.min, i.max), t = D(e, Number(i.precision)), l.value = h(e, i), o("update:modelValue", e);
127
126
  }
128
127
  function I() {
129
- let e = y(t, Number(i.precision)) || 0;
130
- e = x(e - Number(i.step), i.min, i.max), t = D(e, Number(i.precision)), l.value = d(e, i), s("update:modelValue", e);
128
+ let e = C(t, Number(i.precision)) || 0;
129
+ e = x(e - Number(i.step), i.min, i.max), t = D(e, Number(i.precision)), l.value = h(e, i), o("update:modelValue", e);
131
130
  }
132
131
  function z() {
133
132
  var e;
134
- t = "0".repeat(Number(i.precision) + 1), m.value = Number(i.precision) + 1, C(), (e = c.value) == null || e.focus();
133
+ t = "0".repeat(Number(i.precision) + 1), s.value = Number(i.precision) + 1, T(), (e = c.value) == null || e.focus();
135
134
  }
136
135
  return {
137
136
  inputValue: l,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adverich-kun-ui",
3
- "version": "0.1.479",
3
+ "version": "0.1.481",
4
4
  "type": "module",
5
5
  "description": "Una librería de componentes Vue.js con Tailwind CSS",
6
6
  "main": "dist/index.js",