litos-ui 0.15.1 → 0.15.3
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/lib/menu/sub_menu.js +19 -19
- 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
|
};
|
package/lib/menu/sub_menu.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { addClass as
|
|
2
|
-
import
|
|
3
|
-
import { initAttr as
|
|
4
|
-
const
|
|
5
|
-
class C extends
|
|
1
|
+
import { addClass as l, $one as r, on as h, off as p, removeClass as d, toggleClass as u, $$ as n } from "ph-utils/dom";
|
|
2
|
+
import m from "../base.js";
|
|
3
|
+
import { initAttr as g, parseAttrValue as c } from "../utils/index.js";
|
|
4
|
+
const f = ":host{display:block;width:100%;overflow:hidden}.l-submenu-title{display:flex;align-items:center;padding:0 10px 0 calc(10px + var(--l-menu-level) * 15px);height:var(--l-menu-item-height);cursor:pointer;box-sizing:border-box;white-space:nowrap;position:relative;overflow:hidden;text-overflow:ellipsis;border-right:2px solid transparent;transition:color .3s,background-color .3s,border-color .3s}.l-submenu-title:hover{background-color:var(--l-primary-color-light5)}.l-menu{--l-menu-level: 1;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)}.l-menu-icon-wrap{display:inline-flex;font-size:14px;margin-right:5px}.l-submenu-arrow-icon{position:absolute;top:50%;right:10px;transition:transform .3s;transform:translate3d(0,-50%,0) rotate(90deg);color:var(--l-info-color)}:host(.collapsed) .l-submenu-arrow-icon{transform:translate3d(0,-50%,0) rotate(0)}.l-menu--collapsed{display:none}.l-menu--hide{position:absolute;visibility:hidden}:host(.is-active) .l-submenu-title{color:var(--l-primary-color)}";
|
|
5
|
+
class C extends m {
|
|
6
6
|
static baseName = "sub-menu";
|
|
7
7
|
/** 默认折叠子菜单 */
|
|
8
8
|
expanded = !1;
|
|
@@ -10,35 +10,35 @@ class C extends g {
|
|
|
10
10
|
active = !1;
|
|
11
11
|
#e;
|
|
12
12
|
connectedCallback() {
|
|
13
|
-
this.loadStyleText(
|
|
13
|
+
this.loadStyleText(f), g(this), this.expanded || l(this, "collapsed"), this.active && l(this, "is-active"), super.connectedCallback();
|
|
14
14
|
}
|
|
15
15
|
afterInit() {
|
|
16
|
-
const e =
|
|
16
|
+
const e = r(".l-menu", this.root);
|
|
17
17
|
h(e, "transitionend", this.#t);
|
|
18
18
|
}
|
|
19
19
|
beforeDestroy() {
|
|
20
|
-
const e =
|
|
20
|
+
const e = r(".l-menu", this.root);
|
|
21
21
|
p(e, "transitionend", this.#t), this.#e && clearTimeout(this.#e);
|
|
22
22
|
}
|
|
23
23
|
static get observedAttributes() {
|
|
24
24
|
return ["expanded", "active"];
|
|
25
25
|
}
|
|
26
|
-
attributeChangedCallback(e, i,
|
|
26
|
+
attributeChangedCallback(e, i, a) {
|
|
27
27
|
if (this.rendered) {
|
|
28
28
|
if (e === "expanded") {
|
|
29
|
-
const o = c(
|
|
29
|
+
const o = c(a, !1, "expanded");
|
|
30
30
|
if (this.expanded !== o) {
|
|
31
31
|
this.expanded = o;
|
|
32
|
-
const t =
|
|
32
|
+
const t = r(".l-menu", this.root);
|
|
33
33
|
if (this.expanded) {
|
|
34
|
-
d(this, "collapsed");
|
|
35
|
-
const s =
|
|
36
|
-
t.style.height = "0", d(t, "l-menu--
|
|
34
|
+
d(this, "collapsed"), l(t, "l-menu--hide"), d(t, "l-menu--collapsed");
|
|
35
|
+
const s = t.getBoundingClientRect();
|
|
36
|
+
t.style.height = "0", d(t, "l-menu--hide"), requestAnimationFrame(() => {
|
|
37
37
|
t.style.height = `${s.height}px`;
|
|
38
38
|
});
|
|
39
39
|
} else {
|
|
40
40
|
const s = t.getBoundingClientRect();
|
|
41
|
-
t.style.height = `${s.height}px`,
|
|
41
|
+
t.style.height = `${s.height}px`, l(this, "collapsed"), requestAnimationFrame(() => {
|
|
42
42
|
t.style.height = "0";
|
|
43
43
|
});
|
|
44
44
|
}
|
|
@@ -50,14 +50,14 @@ class C extends g {
|
|
|
50
50
|
}, 350);
|
|
51
51
|
}
|
|
52
52
|
} else if (e === "active") {
|
|
53
|
-
const o = c(
|
|
54
|
-
o !== this.active && (this.active = o,
|
|
53
|
+
const o = c(a, !1, "active");
|
|
54
|
+
o !== this.active && (this.active = o, u(this, "is-active"));
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
render() {
|
|
59
59
|
const e = document.createDocumentFragment(), i = n("div", { class: "l-submenu-title" });
|
|
60
|
-
if (
|
|
60
|
+
if (r('[slot="icon"]', this)) {
|
|
61
61
|
const s = n("span", { class: "l-menu-icon-wrap" });
|
|
62
62
|
s.appendChild(n("slot", { name: "icon" })), i.appendChild(s);
|
|
63
63
|
}
|
|
@@ -73,7 +73,7 @@ class C extends g {
|
|
|
73
73
|
if (!this.expanded && e.propertyName === "height") {
|
|
74
74
|
this.#e && clearTimeout(this.#e);
|
|
75
75
|
const i = e.target;
|
|
76
|
-
i.style.removeProperty("height"),
|
|
76
|
+
i.style.removeProperty("height"), l(i, "l-menu--collapsed");
|
|
77
77
|
}
|
|
78
78
|
};
|
|
79
79
|
}
|