adverich-kun-ui 0.1.196 → 0.1.198

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,4 +1,5 @@
1
- import { ref as f, provide as p, computed as A, createElementBlock as D, openBlock as h, mergeProps as B, withModifiers as I, renderSlot as S } from "vue";
1
+ import { ref as m, watch as w, provide as k, createElementBlock as v, openBlock as B, mergeProps as D, withModifiers as h, renderSlot as x } from "vue";
2
+ import { useKunList as S } from "../composables/useKunList.js";
2
3
  const L = {
3
4
  __name: "KunList",
4
5
  props: {
@@ -8,7 +9,11 @@ const L = {
8
9
  selectable: {
9
10
  type: [Boolean, String],
10
11
  default: !1,
11
- validator: (o) => ["single", "multiple", !0, !1].includes(o)
12
+ validator: (l) => ["single", "multiple", !0, !1].includes(l)
13
+ },
14
+ selected: {
15
+ type: [Array, String, Number, Boolean, Object, null],
16
+ default: null
12
17
  },
13
18
  bgList: {
14
19
  type: String,
@@ -20,71 +25,76 @@ const L = {
20
25
  }
21
26
  },
22
27
  emits: ["keyDown", "click:select", "update:selected"],
23
- setup(o, { expose: g, emit: w }) {
24
- const d = o, i = w, m = f(null), c = f([]), s = f([]);
25
- p("registerListItemRef", (e) => {
28
+ setup(l, { expose: p, emit: g }) {
29
+ const u = l, i = g, d = m(null), c = m([]), { selectedValues: f } = S(u);
30
+ w(
31
+ () => u.selected,
32
+ (e) => {
33
+ f.value = u.selectable === "multiple" ? Array.isArray(e) ? [...e] : [] : e != null ? [e] : [];
34
+ },
35
+ { immediate: !0 }
36
+ ), w(
37
+ f,
38
+ (e) => {
39
+ i(
40
+ "update:selected",
41
+ u.selectable === "multiple" ? [...e] : e[0] ?? null
42
+ );
43
+ }
44
+ ), k("registerListItemRef", (e) => {
26
45
  e && !c.value.includes(e) && c.value.push(e);
27
46
  });
28
- const b = A(
29
- () => d.selectable === "multiple" || d.selectable === !0
30
- );
31
- function v(e) {
32
- !d.selectable || e == null || (b.value ? (s.value.includes(e) ? s.value = s.value.filter((n) => n !== e) : s.value.push(e), i("update:selected", [...s.value])) : (s.value = [e], i("update:selected", e)));
33
- }
34
- p("kunListContext", {
35
- toggleItem: v
36
- });
37
47
  function y(e) {
38
- var r;
48
+ var o;
39
49
  i("keyDown", e);
40
50
  const t = e.key, n = c.value.filter(Boolean);
41
51
  if (!(!n.length || !["ArrowUp", "ArrowDown", "Enter"].includes(t))) {
42
52
  if (t === "Enter") {
43
- const l = document.activeElement;
44
- (l == null ? void 0 : l.getAttribute("role")) === "menuitem" && l.click();
53
+ const r = document.activeElement;
54
+ (r == null ? void 0 : r.getAttribute("role")) === "menuitem" && r.click();
45
55
  return;
46
56
  }
47
57
  if (t === "ArrowUp" || t === "ArrowDown") {
48
58
  e.preventDefault();
49
- const l = n.findIndex((x) => x === document.activeElement);
59
+ const r = n.findIndex((A) => A === document.activeElement);
50
60
  let a = -1;
51
- l === -1 ? a = t === "ArrowDown" ? 0 : n.length - 1 : t === "ArrowDown" ? a = (l + 1) % n.length : t === "ArrowUp" && (a = (l - 1 + n.length) % n.length);
52
- const u = n[a];
53
- (r = u == null ? void 0 : u.focus) == null || r.call(u);
61
+ r === -1 ? a = t === "ArrowDown" ? 0 : n.length - 1 : t === "ArrowDown" ? a = (r + 1) % n.length : t === "ArrowUp" && (a = (r - 1 + n.length) % n.length);
62
+ const s = n[a];
63
+ (o = s == null ? void 0 : s.focus) == null || o.call(s);
54
64
  return;
55
65
  }
56
66
  }
57
67
  }
58
- function k(e = "ArrowDown") {
59
- var l;
68
+ function b(e = "ArrowDown") {
69
+ var r;
60
70
  const t = c.value.filter(Boolean);
61
71
  if (!t.length) return;
62
- const n = e === "ArrowDown" ? 0 : t.length - 1, r = t[n];
63
- (l = r == null ? void 0 : r.focus) == null || l.call(r);
72
+ const n = e === "ArrowDown" ? 0 : t.length - 1, o = t[n];
73
+ (r = o == null ? void 0 : o.focus) == null || r.call(o);
64
74
  }
65
- return g({ focusWithKey: k, focus: () => {
75
+ return p({ focusWithKey: b, focus: () => {
66
76
  var e, t;
67
- return (t = (e = m.value) == null ? void 0 : e.focus) == null ? void 0 : t.call(e);
68
- } }), (e, t) => (h(), D("ul", B({
77
+ return (t = (e = d.value) == null ? void 0 : e.focus) == null ? void 0 : t.call(e);
78
+ } }), (e, t) => (B(), v("ul", D({
69
79
  ref_key: "ulRef",
70
- ref: m,
80
+ ref: d,
71
81
  role: "list",
72
82
  class: ["w-full kun-list", [
73
- o.bgList,
74
- o.borderColor,
83
+ l.bgList,
84
+ l.borderColor,
75
85
  {
76
- "space-y-1": !o.dense,
77
- "space-y-0.5": o.dense,
78
- "pl-4 border-l-2": o.sub,
79
- "p-2 rounded-md": o.nav
86
+ "space-y-1": !l.dense,
87
+ "space-y-0.5": l.dense,
88
+ "pl-4 border-l-2": l.sub,
89
+ "p-2 rounded-md": l.nav
80
90
  }
81
91
  ]],
82
92
  tabindex: "-1",
83
- onKeydown: I(y, ["prevent"]),
93
+ onKeydown: h(y, ["prevent"]),
84
94
  onSelect: t[0] || (t[0] = (n) => i("click:select", n.detail)),
85
95
  onSelected: t[1] || (t[1] = (n) => i("update:selected", n.detail))
86
96
  }, e.$attrs), [
87
- S(e.$slots, "default")
97
+ x(e.$slots, "default")
88
98
  ], 16));
89
99
  }
90
100
  };
@@ -0,0 +1,26 @@
1
+ import { ref as c, provide as f } from "vue";
2
+ const a = Symbol("kun-list");
3
+ function g(i) {
4
+ const e = c([]);
5
+ function t(l) {
6
+ if (!i.selectable || i.disabled || l == null) return;
7
+ const s = i.selectable === "multiple";
8
+ i.selectable === "single" ? e.value[0] !== l && (e.value = [l]) : s && (e.value.indexOf(l) === -1 ? e.value = [...e.value, l] : e.value = e.value.filter((u) => u !== l));
9
+ }
10
+ function n(l) {
11
+ return e.value.includes(l);
12
+ }
13
+ return f(a, {
14
+ toggleItem: t,
15
+ isSelected: n,
16
+ isMultiple: () => i.selectable === "multiple",
17
+ isSingle: () => i.selectable === "single"
18
+ }), {
19
+ selectedValues: e,
20
+ toggleItem: t,
21
+ isSelected: n
22
+ };
23
+ }
24
+ export {
25
+ g as useKunList
26
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adverich-kun-ui",
3
- "version": "0.1.196",
3
+ "version": "0.1.198",
4
4
  "type": "module",
5
5
  "description": "Una librería de componentes Vue.js con Tailwind CSS",
6
6
  "main": "dist/index.js",