adverich-kun-ui 0.1.196 → 0.1.197
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,6 @@
|
|
|
1
|
-
import { ref as
|
|
2
|
-
|
|
1
|
+
import { ref as m, provide as A, createElementBlock as k, openBlock as v, mergeProps as h, withModifiers as B, renderSlot as D } from "vue";
|
|
2
|
+
import { useKunList as x } from "../composables/useKunList.js";
|
|
3
|
+
const K = {
|
|
3
4
|
__name: "KunList",
|
|
4
5
|
props: {
|
|
5
6
|
nav: Boolean,
|
|
@@ -8,7 +9,11 @@ const L = {
|
|
|
8
9
|
selectable: {
|
|
9
10
|
type: [Boolean, String],
|
|
10
11
|
default: !1,
|
|
11
|
-
validator: (
|
|
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,74 +25,79 @@ const L = {
|
|
|
20
25
|
}
|
|
21
26
|
},
|
|
22
27
|
emits: ["keyDown", "click:select", "update:selected"],
|
|
23
|
-
setup(
|
|
24
|
-
const
|
|
25
|
-
|
|
28
|
+
setup(l, { expose: w, emit: p }) {
|
|
29
|
+
const u = l, i = p, d = m(null), c = m([]), { selectedValues: f } = x(u);
|
|
30
|
+
watch(
|
|
31
|
+
() => u.selected,
|
|
32
|
+
(e) => {
|
|
33
|
+
f.value = u.selectable === "multiple" ? Array.isArray(e) ? [...e] : [] : e != null ? [e] : [];
|
|
34
|
+
},
|
|
35
|
+
{ immediate: !0 }
|
|
36
|
+
), watch(
|
|
37
|
+
f,
|
|
38
|
+
(e) => {
|
|
39
|
+
i(
|
|
40
|
+
"update:selected",
|
|
41
|
+
u.selectable === "multiple" ? [...e] : e[0] ?? null
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
), A("registerListItemRef", (e) => {
|
|
26
45
|
e && !c.value.includes(e) && c.value.push(e);
|
|
27
46
|
});
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
function y(e) {
|
|
38
|
-
var r;
|
|
47
|
+
function g(e) {
|
|
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
|
|
44
|
-
(
|
|
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
|
|
59
|
+
const r = n.findIndex((b) => b === document.activeElement);
|
|
50
60
|
let a = -1;
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
(
|
|
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
|
|
59
|
-
var
|
|
68
|
+
function y(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,
|
|
63
|
-
(
|
|
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
|
|
75
|
+
return w({ focusWithKey: y, focus: () => {
|
|
66
76
|
var e, t;
|
|
67
|
-
return (t = (e =
|
|
68
|
-
} }), (e, t) => (
|
|
77
|
+
return (t = (e = d.value) == null ? void 0 : e.focus) == null ? void 0 : t.call(e);
|
|
78
|
+
} }), (e, t) => (v(), k("ul", h({
|
|
69
79
|
ref_key: "ulRef",
|
|
70
|
-
ref:
|
|
80
|
+
ref: d,
|
|
71
81
|
role: "list",
|
|
72
82
|
class: ["w-full kun-list", [
|
|
73
|
-
|
|
74
|
-
|
|
83
|
+
l.bgList,
|
|
84
|
+
l.borderColor,
|
|
75
85
|
{
|
|
76
|
-
"space-y-1": !
|
|
77
|
-
"space-y-0.5":
|
|
78
|
-
"pl-4 border-l-2":
|
|
79
|
-
"p-2 rounded-md":
|
|
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:
|
|
93
|
+
onKeydown: B(g, ["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
|
-
|
|
97
|
+
D(e.$slots, "default")
|
|
88
98
|
], 16));
|
|
89
99
|
}
|
|
90
100
|
};
|
|
91
101
|
export {
|
|
92
|
-
|
|
102
|
+
K as default
|
|
93
103
|
};
|
|
@@ -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
|
+
};
|