litos-ui 0.15.1 → 0.15.2
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/lib/menu/index.d.ts +1 -1
- package/lib/menu/index.js +20 -20
- package/package.json +1 -1
package/lib/menu/index.d.ts
CHANGED
package/lib/menu/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { on as c, off as u, $$ as h, $ as
|
|
1
|
+
import { on as c, off as u, $$ as h, $ as o, iterate as a, $one as f } from "ph-utils/dom";
|
|
2
2
|
import m from "../base.js";
|
|
3
3
|
import { initAttr as b } from "../utils/index.js";
|
|
4
4
|
const p = ":host{--l-menu-width: 240px;--l-menu-height: auto;--l-menu-color: #333333;--l-menu-background: #ffffff;--l-menu-level: 0;--l-menu-item-height: 40px;--l-menu-active-color: var(--l-primary-color, #722ed1);--l-menu-active-background: var(--l-primary-color-light5, #f9f0ff);display:block;width:var(--l-menu-width);height:var(--l-menu-height);font-size:14px;position:relative;color:var(--l-menu-color);background:var(--l-menu-background);box-sizing:border-box;transition:height .3s,width .3s;overflow:hidden;border-right:1px solid var(--l-border-color, #dedede)}";
|
|
5
|
-
class
|
|
5
|
+
class k extends m {
|
|
6
6
|
static baseName = "menu";
|
|
7
7
|
/** 当前选中的菜单项 key 数组, 用 , 分割 */
|
|
8
|
-
|
|
8
|
+
selectedIndex = "";
|
|
9
9
|
/** 水平/垂直菜单 */
|
|
10
10
|
orientation = "vertical";
|
|
11
11
|
/** 主题 */
|
|
@@ -20,12 +20,12 @@ class x extends m {
|
|
|
20
20
|
), this.loadStyleText(p), super.connectedCallback();
|
|
21
21
|
}
|
|
22
22
|
static get observedAttributes() {
|
|
23
|
-
return ["selected-
|
|
23
|
+
return ["selected-index", "orientation"];
|
|
24
24
|
}
|
|
25
25
|
attributeChangedCallback(e, s, t) {
|
|
26
26
|
if (this.rendered) {
|
|
27
|
-
if (e === "selected-
|
|
28
|
-
this.
|
|
27
|
+
if (e === "selected-index")
|
|
28
|
+
this.selectedIndex !== t && this.updateSelectedKeys(t);
|
|
29
29
|
else if (e === "orientation") {
|
|
30
30
|
const i = this.classList;
|
|
31
31
|
i.remove(`l-menu--${s}`), i.add(`l-menu--${t}`);
|
|
@@ -33,7 +33,7 @@ class x extends m {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
afterInit() {
|
|
36
|
-
c(this, "click", this.#t), this.updateSelectedKeys(this.
|
|
36
|
+
c(this, "click", this.#t), this.updateSelectedKeys(this.selectedIndex);
|
|
37
37
|
}
|
|
38
38
|
beforeDestroy() {
|
|
39
39
|
u(this, "click", this.#t);
|
|
@@ -51,11 +51,11 @@ class x extends m {
|
|
|
51
51
|
let t = 0, i = "", n;
|
|
52
52
|
const l = [];
|
|
53
53
|
do {
|
|
54
|
-
const
|
|
55
|
-
if (["L-MENU", "BODY"].includes(
|
|
54
|
+
const d = e.tagName;
|
|
55
|
+
if (["L-MENU", "BODY"].includes(d))
|
|
56
56
|
break;
|
|
57
|
-
const r = e.getAttribute("
|
|
58
|
-
r && (i || (i = r), l.unshift(r), s && s(e, r)), t === 0 && (
|
|
57
|
+
const r = e.getAttribute("index");
|
|
58
|
+
r && (i || (i = r), l.unshift(r), s && s(e, r)), t === 0 && (d === "L-MENU-ITEM" ? (t = 1, n = e) : d === "L-SUB-MENU" && (n = e, t = 2)), e = e.parentElement;
|
|
59
59
|
} while (t >= 0);
|
|
60
60
|
return { type: t, key: i, keyPaths: l, target: n };
|
|
61
61
|
}
|
|
@@ -70,15 +70,15 @@ class x extends m {
|
|
|
70
70
|
* @param collapseOther - 可选参数,默认为 false。是否折叠其他子菜单。
|
|
71
71
|
*/
|
|
72
72
|
expandSubmenus(e, s = !1) {
|
|
73
|
-
const t =
|
|
74
|
-
|
|
75
|
-
const n = i.getAttribute("
|
|
73
|
+
const t = o("l-sub-menu[index]", this);
|
|
74
|
+
a(t, (i) => {
|
|
75
|
+
const n = i.getAttribute("index") || "";
|
|
76
76
|
e.includes(n) ? i.setAttribute("expanded", "") : s && i.removeAttribute("expanded");
|
|
77
77
|
});
|
|
78
78
|
}
|
|
79
79
|
updateSelectedKeys(e) {
|
|
80
|
-
this.
|
|
81
|
-
const s = f(`l-menu-item[
|
|
80
|
+
this.selectedIndex = e;
|
|
81
|
+
const s = f(`l-menu-item[index="${e}"]`, this);
|
|
82
82
|
if (s) {
|
|
83
83
|
const t = this.#e(s, (i) => {
|
|
84
84
|
i.setAttribute("active", ""), i.setAttribute("expanded", "");
|
|
@@ -87,9 +87,9 @@ class x extends m {
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
#i(e) {
|
|
90
|
-
const s =
|
|
91
|
-
|
|
92
|
-
const i = t.getAttribute("
|
|
90
|
+
const s = o("l-menu-item[active]", this);
|
|
91
|
+
a(s, (t) => {
|
|
92
|
+
const i = t.getAttribute("index") || "";
|
|
93
93
|
e.includes(i) || this.#e(t, (n, l) => {
|
|
94
94
|
e.includes(l) || (n.removeAttribute("expanded"), n.removeAttribute("active"));
|
|
95
95
|
});
|
|
@@ -97,5 +97,5 @@ class x extends m {
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
export {
|
|
100
|
-
|
|
100
|
+
k as default
|
|
101
101
|
};
|