mdui 2.0.0 → 2.0.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/components/avatar/index.js +2 -1
- package/components/badge/index.js +2 -1
- package/components/bottom-app-bar/index.d.ts +2 -2
- package/components/bottom-app-bar/index.js +4 -3
- package/components/button/button-base.d.ts +2 -2
- package/components/button/button-base.js +15 -14
- package/components/button/index.js +2 -1
- package/components/button-icon/index.js +2 -1
- package/components/card/index.d.ts +1 -1
- package/components/card/index.js +5 -2
- package/components/checkbox/index.js +7 -10
- package/components/checkbox/style.js +1 -1
- package/components/chip/index.js +2 -1
- package/components/circular-progress/index.js +3 -3
- package/components/collapse/collapse-item-style.js +1 -1
- package/components/collapse/collapse-item.d.ts +2 -1
- package/components/collapse/collapse-item.js +23 -20
- package/components/collapse/collapse.d.ts +6 -6
- package/components/collapse/collapse.js +57 -34
- package/components/dialog/index.d.ts +3 -2
- package/components/dialog/index.js +27 -23
- package/components/divider/index.js +2 -1
- package/components/dropdown/index.d.ts +4 -5
- package/components/dropdown/index.js +56 -51
- package/components/fab/index.d.ts +1 -0
- package/components/fab/index.js +10 -5
- package/components/icon/index.js +2 -1
- package/components/layout/helper.d.ts +5 -6
- package/components/layout/helper.js +42 -48
- package/components/layout/layout-item-base.js +1 -2
- package/components/layout/layout-item.js +3 -3
- package/components/layout/layout-main.js +2 -1
- package/components/layout/layout.js +2 -1
- package/components/linear-progress/index.js +3 -3
- package/components/list/list-item.js +3 -2
- package/components/list/list-subheader.js +2 -1
- package/components/list/list.js +2 -1
- package/components/menu/menu-item.d.ts +1 -0
- package/components/menu/menu-item.js +45 -28
- package/components/menu/menu.d.ts +4 -1
- package/components/menu/menu.js +82 -56
- package/components/navigation-bar/navigation-bar-item-style.js +1 -1
- package/components/navigation-bar/navigation-bar-item.d.ts +6 -2
- package/components/navigation-bar/navigation-bar-item.js +26 -10
- package/components/navigation-bar/navigation-bar.d.ts +6 -6
- package/components/navigation-bar/navigation-bar.js +49 -42
- package/components/navigation-drawer/index.d.ts +5 -1
- package/components/navigation-drawer/index.js +62 -41
- package/components/navigation-rail/navigation-rail-item-style.js +1 -1
- package/components/navigation-rail/navigation-rail-item.d.ts +6 -2
- package/components/navigation-rail/navigation-rail-item.js +20 -8
- package/components/navigation-rail/navigation-rail.d.ts +4 -5
- package/components/navigation-rail/navigation-rail.js +51 -44
- package/components/radio/radio-group.d.ts +6 -4
- package/components/radio/radio-group.js +61 -48
- package/components/radio/radio-style.js +1 -1
- package/components/radio/radio.d.ts +3 -2
- package/components/radio/radio.js +24 -17
- package/components/range-slider/index.js +7 -9
- package/components/ripple/index.js +2 -1
- package/components/segmented-button/segmented-button-group.d.ts +6 -3
- package/components/segmented-button/segmented-button-group.js +84 -69
- package/components/segmented-button/segmented-button.d.ts +2 -2
- package/components/segmented-button/segmented-button.js +5 -4
- package/components/select/index.d.ts +2 -2
- package/components/select/index.js +26 -24
- package/components/slider/index.js +7 -9
- package/components/slider/slider-base-style.js +1 -1
- package/components/slider/slider-base.js +1 -5
- package/components/snackbar/index.js +2 -1
- package/components/switch/index.js +6 -9
- package/components/switch/style.js +1 -1
- package/components/tabs/tab-panel.js +2 -1
- package/components/tabs/tab-style.js +1 -1
- package/components/tabs/tab.js +10 -5
- package/components/tabs/tabs-style.js +1 -1
- package/components/tabs/tabs.d.ts +6 -5
- package/components/tabs/tabs.js +52 -38
- package/components/text-field/index.d.ts +2 -2
- package/components/text-field/index.js +32 -54
- package/components/text-field/style.js +1 -1
- package/components/tooltip/index.d.ts +5 -5
- package/components/tooltip/index.js +30 -25
- package/components/top-app-bar/top-app-bar-title-style.js +1 -1
- package/components/top-app-bar/top-app-bar-title.js +16 -12
- package/components/top-app-bar/top-app-bar.d.ts +2 -2
- package/components/top-app-bar/top-app-bar.js +6 -4
- package/custom-elements.json +3776 -3481
- package/functions/getTheme.js +3 -3
- package/functions/snackbar.js +1 -2
- package/functions/utils/colorScheme.js +2 -2
- package/html-data.zh-cn.json +727 -727
- package/mdui.esm.js +8 -8
- package/mdui.global.js +8 -8
- package/package.json +7 -7
- package/web-types.zh-cn.json +1265 -1265
|
@@ -5,9 +5,8 @@ import '@mdui/jq/methods/get.js';
|
|
|
5
5
|
import { isNodeName } from '@mdui/jq/shared/helper.js';
|
|
6
6
|
import { observeResize } from '@mdui/shared/helpers/observeResize.js';
|
|
7
7
|
export class LayoutManager {
|
|
8
|
-
constructor(
|
|
8
|
+
constructor() {
|
|
9
9
|
this.states = [];
|
|
10
|
-
this.$layout = $(element);
|
|
11
10
|
}
|
|
12
11
|
/**
|
|
13
12
|
* 注册 `<mdui-layout-main>`
|
|
@@ -29,15 +28,9 @@ export class LayoutManager {
|
|
|
29
28
|
this.states.push(state);
|
|
30
29
|
// 监听元素尺寸变化
|
|
31
30
|
state.observeResize = observeResize(state.element, () => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
state.element.isModal) {
|
|
36
|
-
this.updateLayout(state.element, { width: 0 });
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
this.updateLayout(state.element);
|
|
40
|
-
}
|
|
31
|
+
this.updateLayout(state.element, {
|
|
32
|
+
width: this.isNoWidth(state) ? 0 : undefined,
|
|
33
|
+
});
|
|
41
34
|
});
|
|
42
35
|
this.items = undefined;
|
|
43
36
|
this.resort();
|
|
@@ -48,14 +41,13 @@ export class LayoutManager {
|
|
|
48
41
|
* 取消注册 `<mdui-layout-item>`
|
|
49
42
|
*/
|
|
50
43
|
unregisterItem(element) {
|
|
51
|
-
var _a;
|
|
52
44
|
const index = this.states.findIndex((item) => item.element === element);
|
|
53
45
|
if (index < 0) {
|
|
54
46
|
return;
|
|
55
47
|
}
|
|
56
48
|
// 取消监听尺寸变化
|
|
57
49
|
const item = this.states[index];
|
|
58
|
-
|
|
50
|
+
item.observeResize?.unobserve();
|
|
59
51
|
this.items = undefined;
|
|
60
52
|
// 移除一个元素,并从下一个元素开始更新
|
|
61
53
|
this.states.splice(index, 1);
|
|
@@ -68,16 +60,19 @@ export class LayoutManager {
|
|
|
68
60
|
*/
|
|
69
61
|
getItems() {
|
|
70
62
|
if (!this.items) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
63
|
+
const items = this.states.map((state) => state.element);
|
|
64
|
+
this.items = items.sort((a, b) => {
|
|
65
|
+
const position = a.compareDocumentPosition(b);
|
|
66
|
+
if (position & Node.DOCUMENT_POSITION_FOLLOWING) {
|
|
67
|
+
return -1;
|
|
68
|
+
}
|
|
69
|
+
else if (position & Node.DOCUMENT_POSITION_PRECEDING) {
|
|
70
|
+
return 1;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
return 0;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
81
76
|
}
|
|
82
77
|
return this.items;
|
|
83
78
|
}
|
|
@@ -93,12 +88,6 @@ export class LayoutManager {
|
|
|
93
88
|
getItemsAndMain() {
|
|
94
89
|
return [...this.getItems(), this.getMain()].filter((i) => i);
|
|
95
90
|
}
|
|
96
|
-
/**
|
|
97
|
-
* 检查指定 `<mdui-layout-item>` 元素是否已注册
|
|
98
|
-
*/
|
|
99
|
-
hasItem(element) {
|
|
100
|
-
return this.getItems().includes(element);
|
|
101
|
-
}
|
|
102
91
|
/**
|
|
103
92
|
* 更新 `order` 值,更新完后重新计算布局
|
|
104
93
|
*/
|
|
@@ -115,8 +104,8 @@ export class LayoutManager {
|
|
|
115
104
|
const state = element
|
|
116
105
|
? {
|
|
117
106
|
element,
|
|
118
|
-
width: size
|
|
119
|
-
height: size
|
|
107
|
+
width: size?.width,
|
|
108
|
+
height: size?.height,
|
|
120
109
|
}
|
|
121
110
|
: undefined;
|
|
122
111
|
const index = state
|
|
@@ -127,7 +116,6 @@ export class LayoutManager {
|
|
|
127
116
|
}
|
|
128
117
|
Object.assign(this.states[index], state);
|
|
129
118
|
this.states.forEach((currState, currIndex) => {
|
|
130
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
131
119
|
if (currIndex < index) {
|
|
132
120
|
return;
|
|
133
121
|
}
|
|
@@ -135,24 +123,22 @@ export class LayoutManager {
|
|
|
135
123
|
const placement = currState.element.layoutPlacement;
|
|
136
124
|
// 前一个元素
|
|
137
125
|
const prevState = currIndex > 0 ? this.states[currIndex - 1] : undefined;
|
|
138
|
-
const top =
|
|
139
|
-
const right =
|
|
140
|
-
const bottom =
|
|
141
|
-
const left =
|
|
126
|
+
const top = prevState?.top ?? 0;
|
|
127
|
+
const right = prevState?.right ?? 0;
|
|
128
|
+
const bottom = prevState?.bottom ?? 0;
|
|
129
|
+
const left = prevState?.left ?? 0;
|
|
142
130
|
Object.assign(currState, { top, right, bottom, left });
|
|
143
131
|
switch (placement) {
|
|
144
132
|
case 'top':
|
|
145
|
-
currState.top += (_e = currState.height) !== null && _e !== void 0 ? _e : currState.element.offsetHeight;
|
|
146
|
-
break;
|
|
147
|
-
case 'right':
|
|
148
|
-
currState.right += (_f = currState.width) !== null && _f !== void 0 ? _f : currState.element.offsetWidth;
|
|
149
|
-
break;
|
|
150
133
|
case 'bottom':
|
|
151
|
-
currState
|
|
152
|
-
|
|
134
|
+
currState[placement] +=
|
|
135
|
+
currState.height ?? currState.element.offsetHeight;
|
|
153
136
|
break;
|
|
137
|
+
case 'right':
|
|
154
138
|
case 'left':
|
|
155
|
-
currState
|
|
139
|
+
currState[placement] +=
|
|
140
|
+
(this.isNoWidth(currState) ? 0 : currState.width) ??
|
|
141
|
+
currState.element.offsetWidth;
|
|
156
142
|
break;
|
|
157
143
|
}
|
|
158
144
|
currState.height = currState.width = undefined;
|
|
@@ -181,9 +167,8 @@ export class LayoutManager {
|
|
|
181
167
|
resort() {
|
|
182
168
|
const items = this.getItems();
|
|
183
169
|
this.states.sort((a, b) => {
|
|
184
|
-
|
|
185
|
-
const
|
|
186
|
-
const bOrder = (_b = b.element.order) !== null && _b !== void 0 ? _b : 0;
|
|
170
|
+
const aOrder = a.element.order ?? 0;
|
|
171
|
+
const bOrder = b.element.order ?? 0;
|
|
187
172
|
if (aOrder > bOrder) {
|
|
188
173
|
return 1;
|
|
189
174
|
}
|
|
@@ -199,6 +184,15 @@ export class LayoutManager {
|
|
|
199
184
|
return 0;
|
|
200
185
|
});
|
|
201
186
|
}
|
|
187
|
+
/**
|
|
188
|
+
* 组件宽度是否为 0
|
|
189
|
+
* mdui-navigation-drawer 较为特殊,在为模态化时,占据的宽度为 0
|
|
190
|
+
*/
|
|
191
|
+
isNoWidth(state) {
|
|
192
|
+
return (isNodeName(state.element, 'mdui-navigation-drawer') &&
|
|
193
|
+
// @ts-ignore
|
|
194
|
+
state.element.isModal);
|
|
195
|
+
}
|
|
202
196
|
}
|
|
203
197
|
const layoutManagerMap = new WeakMap();
|
|
204
198
|
/**
|
|
@@ -206,7 +200,7 @@ const layoutManagerMap = new WeakMap();
|
|
|
206
200
|
*/
|
|
207
201
|
export const getLayout = (element) => {
|
|
208
202
|
if (!layoutManagerMap.has(element)) {
|
|
209
|
-
layoutManagerMap.set(element, new LayoutManager(
|
|
203
|
+
layoutManagerMap.set(element, new LayoutManager());
|
|
210
204
|
}
|
|
211
205
|
return layoutManagerMap.get(element);
|
|
212
206
|
};
|
|
@@ -18,8 +18,7 @@ export class LayoutItemBase extends LitElement {
|
|
|
18
18
|
}
|
|
19
19
|
// order 变更时,需要重新调整布局
|
|
20
20
|
onOrderChange() {
|
|
21
|
-
|
|
22
|
-
(_a = this.layoutManager) === null || _a === void 0 ? void 0 : _a.updateOrder();
|
|
21
|
+
this.layoutManager?.updateOrder();
|
|
23
22
|
}
|
|
24
23
|
connectedCallback() {
|
|
25
24
|
super.connectedCallback();
|
|
@@ -18,7 +18,7 @@ import { layoutItemStyle } from './layout-item-style.js';
|
|
|
18
18
|
*
|
|
19
19
|
* @slot - 可以是任意内容
|
|
20
20
|
*/
|
|
21
|
-
|
|
21
|
+
let LayoutItem = class LayoutItem extends LayoutItemBase {
|
|
22
22
|
constructor() {
|
|
23
23
|
super(...arguments);
|
|
24
24
|
/**
|
|
@@ -36,8 +36,7 @@ export let LayoutItem = class LayoutItem extends LayoutItemBase {
|
|
|
36
36
|
}
|
|
37
37
|
// placement 变更时,需要重新调整布局
|
|
38
38
|
onPlacementChange() {
|
|
39
|
-
|
|
40
|
-
(_a = this.layoutManager) === null || _a === void 0 ? void 0 : _a.updateLayout(this);
|
|
39
|
+
this.layoutManager?.updateLayout(this);
|
|
41
40
|
}
|
|
42
41
|
render() {
|
|
43
42
|
return html `<slot></slot>`;
|
|
@@ -56,3 +55,4 @@ __decorate([
|
|
|
56
55
|
LayoutItem = __decorate([
|
|
57
56
|
customElement('mdui-layout-item')
|
|
58
57
|
], LayoutItem);
|
|
58
|
+
export { LayoutItem };
|
|
@@ -18,7 +18,7 @@ import { layoutMainStyle } from './layout-main-style.js';
|
|
|
18
18
|
*
|
|
19
19
|
* @slot - 可以是任意内容
|
|
20
20
|
*/
|
|
21
|
-
|
|
21
|
+
let LayoutMain = class LayoutMain extends LitElement {
|
|
22
22
|
connectedCallback() {
|
|
23
23
|
super.connectedCallback();
|
|
24
24
|
const parentElement = this.parentElement;
|
|
@@ -44,3 +44,4 @@ LayoutMain.styles = [
|
|
|
44
44
|
LayoutMain = __decorate([
|
|
45
45
|
customElement('mdui-layout-main')
|
|
46
46
|
], LayoutMain);
|
|
47
|
+
export { LayoutMain };
|
|
@@ -17,7 +17,7 @@ import { layoutStyle } from './layout-style.js';
|
|
|
17
17
|
*
|
|
18
18
|
* @slot - 可以是 [`<mdui-top-app-bar>`](/docs/2/components/top-app-bar)、[`<mdui-bottom-app-bar>`](/docs/2/components/bottom-app-bar)、[`<mdui-navigation-bar>`](/docs/2/components/navigation-bar)、[`<mdui-navigation-drawer>`](/docs/2/components/navigation-drawer)、[`<mdui-navigation-rail>`](/docs/2/components/navigation-rail)、`<mdui-layout-item>`、`<mdui-layout-main>` 元素
|
|
19
19
|
*/
|
|
20
|
-
|
|
20
|
+
let Layout = class Layout extends LitElement {
|
|
21
21
|
constructor() {
|
|
22
22
|
super(...arguments);
|
|
23
23
|
/**
|
|
@@ -41,3 +41,4 @@ __decorate([
|
|
|
41
41
|
Layout = __decorate([
|
|
42
42
|
customElement('mdui-layout')
|
|
43
43
|
], Layout);
|
|
44
|
+
export { Layout };
|
|
@@ -16,7 +16,7 @@ import { style } from './style.js';
|
|
|
16
16
|
*
|
|
17
17
|
* @cssprop --shape-corner - 组件的圆角大小。可以指定一个具体的像素值;但更推荐[引用设计令牌](/docs/2/styles/design-tokens#shape-corner)
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
let LinearProgress = class LinearProgress extends LitElement {
|
|
20
20
|
constructor() {
|
|
21
21
|
super(...arguments);
|
|
22
22
|
/**
|
|
@@ -25,12 +25,11 @@ export let LinearProgress = class LinearProgress extends LitElement {
|
|
|
25
25
|
this.max = 1;
|
|
26
26
|
}
|
|
27
27
|
render() {
|
|
28
|
-
var _a;
|
|
29
28
|
const isDeterminate = !isUndefined(this.value);
|
|
30
29
|
if (isDeterminate) {
|
|
31
30
|
const value = this.value;
|
|
32
31
|
return html `<div part="indicator" class="determinate" style="${styleMap({
|
|
33
|
-
width: `${(value / Math.max(
|
|
32
|
+
width: `${(value / Math.max(this.max ?? value, value)) * 100}%`,
|
|
34
33
|
})}"></div>`;
|
|
35
34
|
}
|
|
36
35
|
return html `<div part="indicator" class="indeterminate"></div>`;
|
|
@@ -46,3 +45,4 @@ __decorate([
|
|
|
46
45
|
LinearProgress = __decorate([
|
|
47
46
|
customElement('mdui-linear-progress')
|
|
48
47
|
], LinearProgress);
|
|
48
|
+
export { LinearProgress };
|
|
@@ -43,7 +43,7 @@ import { listItemStyle } from './list-item-style.js';
|
|
|
43
43
|
* @cssprop --shape-corner - 列表项的圆角大小。可以指定一个具体的像素值;但更推荐[引用设计令牌](/docs/2/styles/design-tokens#shape-corner)
|
|
44
44
|
* @cssprop --shape-corner-rounded - 指定了 `rounded` 时,列表项的圆角大小。可以指定一个具体的像素值;但更推荐[引用设计令牌](/docs/2/styles/design-tokens#shape-corner)
|
|
45
45
|
*/
|
|
46
|
-
|
|
46
|
+
let ListItem = class ListItem extends AnchorMixin(RippleMixin(FocusableMixin(LitElement))) {
|
|
47
47
|
constructor() {
|
|
48
48
|
super(...arguments);
|
|
49
49
|
/**
|
|
@@ -81,7 +81,7 @@ export let ListItem = class ListItem extends AnchorMixin(RippleMixin(FocusableMi
|
|
|
81
81
|
return this.focusDisabled;
|
|
82
82
|
}
|
|
83
83
|
get focusElement() {
|
|
84
|
-
return this.href ? this.itemRef.value : this;
|
|
84
|
+
return this.href && !this.disabled ? this.itemRef.value : this;
|
|
85
85
|
}
|
|
86
86
|
get focusDisabled() {
|
|
87
87
|
return this.href ? this.disabled : this.disabled || this.nonclickable;
|
|
@@ -184,3 +184,4 @@ __decorate([
|
|
|
184
184
|
ListItem = __decorate([
|
|
185
185
|
customElement('mdui-list-item')
|
|
186
186
|
], ListItem);
|
|
187
|
+
export { ListItem };
|
|
@@ -16,7 +16,7 @@ import { listSubheaderStyle } from './list-subheader-style.js';
|
|
|
16
16
|
*
|
|
17
17
|
* @slot - 文本
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
let ListSubheader = class ListSubheader extends LitElement {
|
|
20
20
|
render() {
|
|
21
21
|
return html `<slot></slot>`;
|
|
22
22
|
}
|
|
@@ -28,3 +28,4 @@ ListSubheader.styles = [
|
|
|
28
28
|
ListSubheader = __decorate([
|
|
29
29
|
customElement('mdui-list-subheader')
|
|
30
30
|
], ListSubheader);
|
|
31
|
+
export { ListSubheader };
|
package/components/list/list.js
CHANGED
|
@@ -16,7 +16,7 @@ import { listStyle } from './list-style.js';
|
|
|
16
16
|
*
|
|
17
17
|
* @slot - `<mdui-list-item>` 元素
|
|
18
18
|
*/
|
|
19
|
-
|
|
19
|
+
let List = class List extends LitElement {
|
|
20
20
|
render() {
|
|
21
21
|
return html `<slot></slot>`;
|
|
22
22
|
}
|
|
@@ -25,3 +25,4 @@ List.styles = [componentStyle, listStyle];
|
|
|
25
25
|
List = __decorate([
|
|
26
26
|
customElement('mdui-list')
|
|
27
27
|
], List);
|
|
28
|
+
export { List };
|
|
@@ -90,6 +90,7 @@ export declare class MenuItem extends MenuItem_base {
|
|
|
90
90
|
private readonly containerRef;
|
|
91
91
|
private readonly submenuRef;
|
|
92
92
|
private readonly hasSlotController;
|
|
93
|
+
private readonly definedController;
|
|
93
94
|
constructor();
|
|
94
95
|
protected get focusDisabled(): boolean;
|
|
95
96
|
protected get focusElement(): HTMLElement;
|
|
@@ -12,6 +12,7 @@ import '@mdui/jq/methods/innerWidth.js';
|
|
|
12
12
|
import '@mdui/jq/methods/width.js';
|
|
13
13
|
import { isUndefined } from '@mdui/jq/shared/helper.js';
|
|
14
14
|
import '@mdui/jq/static/contains.js';
|
|
15
|
+
import { DefinedController } from '@mdui/shared/controllers/defined.js';
|
|
15
16
|
import { HasSlotController } from '@mdui/shared/controllers/has-slot.js';
|
|
16
17
|
import { watch } from '@mdui/shared/decorators/watch.js';
|
|
17
18
|
import { animateTo, stopAnimations } from '@mdui/shared/helpers/animate.js';
|
|
@@ -61,7 +62,7 @@ import { menuItemStyle } from './menu-item-style.js';
|
|
|
61
62
|
* @csspart selected-icon - 选中状态的图标
|
|
62
63
|
* @csspart submenu - 子菜单元素
|
|
63
64
|
*/
|
|
64
|
-
|
|
65
|
+
let MenuItem = class MenuItem extends AnchorMixin(RippleMixin(FocusableMixin(LitElement))) {
|
|
65
66
|
constructor() {
|
|
66
67
|
super();
|
|
67
68
|
/**
|
|
@@ -72,11 +73,11 @@ export let MenuItem = class MenuItem extends AnchorMixin(RippleMixin(FocusableMi
|
|
|
72
73
|
* 是否打开子菜单
|
|
73
74
|
*/
|
|
74
75
|
this.submenuOpen = false;
|
|
75
|
-
//
|
|
76
|
+
// 是否已选中该菜单项。由 <mdui-menu> 控制该参数
|
|
76
77
|
this.selected = false;
|
|
77
|
-
//
|
|
78
|
+
// 是否使用更紧凑的布局。由 <mdui-menu> 控制该参数
|
|
78
79
|
this.dense = false;
|
|
79
|
-
// 是否可聚焦。由 mdui-menu 控制该参数
|
|
80
|
+
// 是否可聚焦。由 <mdui-menu> 控制该参数
|
|
80
81
|
this.focusable = false;
|
|
81
82
|
// 每一个 menu-item 元素都添加一个唯一的 key
|
|
82
83
|
this.key = uniqueId();
|
|
@@ -84,6 +85,9 @@ export let MenuItem = class MenuItem extends AnchorMixin(RippleMixin(FocusableMi
|
|
|
84
85
|
this.containerRef = createRef();
|
|
85
86
|
this.submenuRef = createRef();
|
|
86
87
|
this.hasSlotController = new HasSlotController(this, '[default]', 'icon', 'end-icon', 'end-text', 'submenu', 'custom');
|
|
88
|
+
this.definedController = new DefinedController(this, {
|
|
89
|
+
relatedElements: [''],
|
|
90
|
+
});
|
|
87
91
|
this.onOuterClick = this.onOuterClick.bind(this);
|
|
88
92
|
this.onFocus = this.onFocus.bind(this);
|
|
89
93
|
this.onBlur = this.onBlur.bind(this);
|
|
@@ -96,7 +100,7 @@ export let MenuItem = class MenuItem extends AnchorMixin(RippleMixin(FocusableMi
|
|
|
96
100
|
return this.disabled || !this.focusable;
|
|
97
101
|
}
|
|
98
102
|
get focusElement() {
|
|
99
|
-
return this.href ? this.containerRef.value : this;
|
|
103
|
+
return this.href && !this.disabled ? this.containerRef.value : this;
|
|
100
104
|
}
|
|
101
105
|
get rippleDisabled() {
|
|
102
106
|
return this.disabled;
|
|
@@ -109,15 +113,20 @@ export let MenuItem = class MenuItem extends AnchorMixin(RippleMixin(FocusableMi
|
|
|
109
113
|
}
|
|
110
114
|
async onOpenChange() {
|
|
111
115
|
const hasUpdated = this.hasUpdated;
|
|
116
|
+
// 默认为关闭状态。因此首次渲染时,且为关闭状态,不执行
|
|
117
|
+
if (!this.submenuOpen && !hasUpdated) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
await this.definedController.whenDefined();
|
|
121
|
+
if (!hasUpdated) {
|
|
122
|
+
await this.updateComplete;
|
|
123
|
+
}
|
|
112
124
|
const easingLinear = getEasing(this, 'linear');
|
|
113
125
|
const easingEmphasizedDecelerate = getEasing(this, 'emphasized-decelerate');
|
|
114
126
|
const easingEmphasizedAccelerate = getEasing(this, 'emphasized-accelerate');
|
|
115
127
|
// 打开
|
|
116
128
|
// 要区分是否首次渲染,首次渲染时不触发事件,不执行动画;非首次渲染,触发事件,执行动画
|
|
117
129
|
if (this.submenuOpen) {
|
|
118
|
-
if (!hasUpdated) {
|
|
119
|
-
await this.updateComplete;
|
|
120
|
-
}
|
|
121
130
|
if (hasUpdated) {
|
|
122
131
|
const requestOpen = emit(this, 'submenu-open', {
|
|
123
132
|
cancelable: true,
|
|
@@ -143,10 +152,8 @@ export let MenuItem = class MenuItem extends AnchorMixin(RippleMixin(FocusableMi
|
|
|
143
152
|
if (hasUpdated) {
|
|
144
153
|
emit(this, 'submenu-opened');
|
|
145
154
|
}
|
|
146
|
-
return;
|
|
147
155
|
}
|
|
148
|
-
|
|
149
|
-
if (!this.submenuOpen && hasUpdated) {
|
|
156
|
+
else {
|
|
150
157
|
const requestClose = emit(this, 'submenu-close', {
|
|
151
158
|
cancelable: true,
|
|
152
159
|
});
|
|
@@ -159,13 +166,17 @@ export let MenuItem = class MenuItem extends AnchorMixin(RippleMixin(FocusableMi
|
|
|
159
166
|
animateTo(this.submenuRef.value, [{ transform: 'scaleY(1)' }, { transform: 'scaleY(0.45)' }], { duration, easing: easingEmphasizedAccelerate }),
|
|
160
167
|
animateTo(this.submenuRef.value, [{ opacity: 1 }, { opacity: 1, offset: 0.875 }, { opacity: 0 }], { duration, easing: easingLinear }),
|
|
161
168
|
]);
|
|
162
|
-
this.submenuRef.value
|
|
169
|
+
if (this.submenuRef.value) {
|
|
170
|
+
this.submenuRef.value.hidden = true;
|
|
171
|
+
}
|
|
163
172
|
emit(this, 'submenu-closed');
|
|
164
173
|
}
|
|
165
174
|
}
|
|
166
175
|
connectedCallback() {
|
|
167
176
|
super.connectedCallback();
|
|
168
|
-
|
|
177
|
+
this.definedController.whenDefined().then(() => {
|
|
178
|
+
document.addEventListener('pointerdown', this.onOuterClick);
|
|
179
|
+
});
|
|
169
180
|
}
|
|
170
181
|
disconnectedCallback() {
|
|
171
182
|
super.disconnectedCallback();
|
|
@@ -173,12 +184,14 @@ export let MenuItem = class MenuItem extends AnchorMixin(RippleMixin(FocusableMi
|
|
|
173
184
|
}
|
|
174
185
|
firstUpdated(changedProperties) {
|
|
175
186
|
super.firstUpdated(changedProperties);
|
|
176
|
-
this.
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
187
|
+
this.definedController.whenDefined().then(() => {
|
|
188
|
+
this.addEventListener('focus', this.onFocus);
|
|
189
|
+
this.addEventListener('blur', this.onBlur);
|
|
190
|
+
this.addEventListener('click', this.onClick);
|
|
191
|
+
this.addEventListener('keydown', this.onKeydown);
|
|
192
|
+
this.addEventListener('mouseenter', this.onMouseEnter);
|
|
193
|
+
this.addEventListener('mouseleave', this.onMouseLeave);
|
|
194
|
+
});
|
|
182
195
|
}
|
|
183
196
|
render() {
|
|
184
197
|
const hasSubmenu = this.hasSubmenu;
|
|
@@ -205,6 +218,7 @@ export let MenuItem = class MenuItem extends AnchorMixin(RippleMixin(FocusableMi
|
|
|
205
218
|
className,
|
|
206
219
|
content: this.renderInner(useDefaultEndIcon, hasIcon),
|
|
207
220
|
refDirective: ref(this.containerRef),
|
|
221
|
+
tabIndex: this.focusable ? 0 : -1,
|
|
208
222
|
})
|
|
209
223
|
: html `<div part="container" ${ref(this.containerRef)} class="${className}">${this.renderInner(useDefaultEndIcon, hasIcon)}</div>`} ${when(hasSubmenu, () => html `<slot name="submenu" ${ref(this.submenuRef)} part="submenu" class="submenu" hidden></slot>`)}`;
|
|
210
224
|
}
|
|
@@ -262,15 +276,16 @@ export let MenuItem = class MenuItem extends AnchorMixin(RippleMixin(FocusableMi
|
|
|
262
276
|
}
|
|
263
277
|
onKeydown(event) {
|
|
264
278
|
// 切换子菜单打开状态
|
|
265
|
-
if (
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
279
|
+
if (this.disabled || !this.hasSubmenu) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
if (!this.submenuOpen && event.key === 'Enter') {
|
|
283
|
+
event.stopPropagation();
|
|
284
|
+
this.submenuOpen = true;
|
|
285
|
+
}
|
|
286
|
+
if (this.submenuOpen && event.key === 'Escape') {
|
|
287
|
+
event.stopPropagation();
|
|
288
|
+
this.submenuOpen = false;
|
|
274
289
|
}
|
|
275
290
|
}
|
|
276
291
|
onMouseEnter() {
|
|
@@ -298,6 +313,7 @@ export let MenuItem = class MenuItem extends AnchorMixin(RippleMixin(FocusableMi
|
|
|
298
313
|
this.submenuOpen = false;
|
|
299
314
|
}, this.submenuCloseDelay || 50);
|
|
300
315
|
}
|
|
316
|
+
// 更新子菜单的位置
|
|
301
317
|
updateSubmenuPositioner() {
|
|
302
318
|
const $window = $(window);
|
|
303
319
|
const $submenu = $(this.submenuRef.value);
|
|
@@ -410,3 +426,4 @@ __decorate([
|
|
|
410
426
|
MenuItem = __decorate([
|
|
411
427
|
customElement('mdui-menu-item')
|
|
412
428
|
], MenuItem);
|
|
429
|
+
export { MenuItem };
|
|
@@ -71,8 +71,9 @@ export declare class Menu extends LitElement {
|
|
|
71
71
|
submenuCloseDelay: number;
|
|
72
72
|
private selectedKeys;
|
|
73
73
|
private readonly childrenItems;
|
|
74
|
-
private
|
|
74
|
+
private isInitial;
|
|
75
75
|
private lastActiveItems;
|
|
76
|
+
private readonly definedController;
|
|
76
77
|
private get items();
|
|
77
78
|
private get itemsEnabled();
|
|
78
79
|
private get isSingle();
|
|
@@ -95,6 +96,8 @@ export declare class Menu extends LitElement {
|
|
|
95
96
|
blur(): void;
|
|
96
97
|
protected firstUpdated(changedProperties: PropertyValues): void;
|
|
97
98
|
protected render(): TemplateResult;
|
|
99
|
+
private setSelectedKeys;
|
|
100
|
+
private setValue;
|
|
98
101
|
private getSiblingsItems;
|
|
99
102
|
private updateFocusable;
|
|
100
103
|
private updateSelected;
|