@spectrum-web-components/menu 0.14.4 → 0.15.0
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/custom-elements.json +59 -59
- package/package.json +53 -19
- package/sp-menu-divider.dev.js +3 -0
- package/sp-menu-divider.dev.js.map +7 -0
- package/sp-menu-divider.js +3 -14
- package/sp-menu-divider.js.map +7 -1
- package/sp-menu-group.dev.js +3 -0
- package/sp-menu-group.dev.js.map +7 -0
- package/sp-menu-group.js +3 -14
- package/sp-menu-group.js.map +7 -1
- package/sp-menu-item.dev.js +3 -0
- package/sp-menu-item.dev.js.map +7 -0
- package/sp-menu-item.js +3 -14
- package/sp-menu-item.js.map +7 -1
- package/sp-menu.dev.js +3 -0
- package/sp-menu.dev.js.map +7 -0
- package/sp-menu.js +3 -14
- package/sp-menu.js.map +7 -1
- package/src/Menu.dev.js +495 -0
- package/src/Menu.dev.js.map +7 -0
- package/src/Menu.js +487 -574
- package/src/Menu.js.map +7 -1
- package/src/MenuDivider.dev.js +13 -0
- package/src/MenuDivider.dev.js.map +7 -0
- package/src/MenuDivider.js +11 -25
- package/src/MenuDivider.js.map +7 -1
- package/src/MenuGroup.dev.js +82 -0
- package/src/MenuGroup.dev.js.map +7 -0
- package/src/MenuGroup.js +67 -71
- package/src/MenuGroup.js.map +7 -1
- package/src/MenuItem.dev.js +424 -0
- package/src/MenuItem.dev.js.map +7 -0
- package/src/MenuItem.js +397 -432
- package/src/MenuItem.js.map +7 -1
- package/src/index.dev.js +5 -0
- package/src/index.dev.js.map +7 -0
- package/src/index.js +5 -16
- package/src/index.js.map +7 -1
- package/src/menu-divider.css.dev.js +6 -0
- package/src/menu-divider.css.dev.js.map +7 -0
- package/src/menu-divider.css.js +3 -14
- package/src/menu-divider.css.js.map +7 -1
- package/src/menu-group.css.dev.js +8 -0
- package/src/menu-group.css.dev.js.map +7 -0
- package/src/menu-group.css.js +3 -14
- package/src/menu-group.css.js.map +7 -1
- package/src/menu-item.css.dev.js +73 -0
- package/src/menu-item.css.dev.js.map +7 -0
- package/src/menu-item.css.js +3 -14
- package/src/menu-item.css.js.map +7 -1
- package/src/menu.css.dev.js +61 -0
- package/src/menu.css.dev.js.map +7 -0
- package/src/menu.css.js +3 -14
- package/src/menu.css.js.map +7 -1
- package/src/spectrum-checkmark.css.dev.js +10 -0
- package/src/spectrum-checkmark.css.dev.js.map +7 -0
- package/src/spectrum-checkmark.css.js +3 -14
- package/src/spectrum-checkmark.css.js.map +7 -1
- package/src/spectrum-chevron.css.dev.js +10 -0
- package/src/spectrum-chevron.css.dev.js.map +7 -0
- package/src/spectrum-chevron.css.js +3 -14
- package/src/spectrum-chevron.css.js.map +7 -1
- package/src/spectrum-itemLabel.css.dev.js +6 -0
- package/src/spectrum-itemLabel.css.dev.js.map +7 -0
- package/src/spectrum-itemLabel.css.js +3 -14
- package/src/spectrum-itemLabel.css.js.map +7 -1
- package/src/spectrum-menu-divider.css.dev.js +6 -0
- package/src/spectrum-menu-divider.css.dev.js.map +7 -0
- package/src/spectrum-menu-divider.css.js +3 -14
- package/src/spectrum-menu-divider.css.js.map +7 -1
- package/src/spectrum-menu-item.css.dev.js +65 -0
- package/src/spectrum-menu-item.css.dev.js.map +7 -0
- package/src/spectrum-menu-item.css.js +3 -14
- package/src/spectrum-menu-item.css.js.map +7 -1
- package/src/spectrum-menu-sectionHeading.css.dev.js +8 -0
- package/src/spectrum-menu-sectionHeading.css.dev.js.map +7 -0
- package/src/spectrum-menu-sectionHeading.css.js +3 -14
- package/src/spectrum-menu-sectionHeading.css.js.map +7 -1
- package/src/spectrum-menu.css.dev.js +61 -0
- package/src/spectrum-menu.css.dev.js.map +7 -0
- package/src/spectrum-menu.css.js +3 -14
- package/src/spectrum-menu.css.js.map +7 -1
- package/stories/menu-group.stories.js +51 -58
- package/stories/menu-group.stories.js.map +7 -1
- package/stories/menu-item.stories.js +12 -32
- package/stories/menu-item.stories.js.map +7 -1
- package/stories/menu.stories.js +22 -35
- package/stories/menu.stories.js.map +7 -1
- package/stories/submenu.stories.js +125 -136
- package/stories/submenu.stories.js.map +7 -1
- package/test/benchmark/test-basic.js +8 -19
- package/test/benchmark/test-basic.js.map +7 -1
- package/test/menu-group.test-vrt.js +4 -15
- package/test/menu-group.test-vrt.js.map +7 -1
- package/test/menu-group.test.js +178 -168
- package/test/menu-group.test.js.map +7 -1
- package/test/menu-item.test-vrt.js +4 -15
- package/test/menu-item.test-vrt.js.map +7 -1
- package/test/menu-item.test.js +93 -99
- package/test/menu-item.test.js.map +7 -1
- package/test/menu-selects.test.js +488 -494
- package/test/menu-selects.test.js.map +7 -1
- package/test/menu.test-vrt.js +4 -15
- package/test/menu.test-vrt.js.map +7 -1
- package/test/menu.test.js +248 -257
- package/test/menu.test.js.map +7 -1
- package/test/submenu.test-vrt.js +4 -15
- package/test/submenu.test-vrt.js.map +7 -1
- package/test/submenu.test.js +452 -486
- package/test/submenu.test.js.map +7 -1
package/src/MenuItem.js
CHANGED
|
@@ -1,459 +1,424 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
import
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
import
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
import
|
|
23
|
-
import
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result)
|
|
9
|
+
__defProp(target, key, result);
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
import {
|
|
13
|
+
html
|
|
14
|
+
} from "@spectrum-web-components/base";
|
|
15
|
+
import {
|
|
16
|
+
property,
|
|
17
|
+
query
|
|
18
|
+
} from "@spectrum-web-components/base/src/decorators.js";
|
|
19
|
+
import "@spectrum-web-components/icons-ui/icons/sp-icon-checkmark100.js";
|
|
20
|
+
import { LikeAnchor } from "@spectrum-web-components/shared/src/like-anchor.js";
|
|
21
|
+
import { Focusable } from "@spectrum-web-components/shared/src/focusable.js";
|
|
22
|
+
import "@spectrum-web-components/icons-ui/icons/sp-icon-chevron100.js";
|
|
23
|
+
import chevronStyles from "@spectrum-web-components/icon/src/spectrum-icon-chevron.css.js";
|
|
24
|
+
import { openOverlay } from "@spectrum-web-components/overlay/src/loader.js";
|
|
25
|
+
import { OverlayCloseEvent } from "@spectrum-web-components/overlay/src/overlay-events.js";
|
|
26
|
+
import menuItemStyles from "./menu-item.css.js";
|
|
27
|
+
import checkmarkStyles from "@spectrum-web-components/icon/src/spectrum-icon-checkmark.css.js";
|
|
28
|
+
import { reparentChildren } from "@spectrum-web-components/shared/src/reparent-children.js";
|
|
29
|
+
import { MutationController } from "@lit-labs/observers/mutation_controller.js";
|
|
30
30
|
const POINTERLEAVE_TIMEOUT = 100;
|
|
31
31
|
export class MenuItemRemovedEvent extends Event {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
constructor() {
|
|
33
|
+
super("sp-menu-item-removed", {
|
|
34
|
+
bubbles: true,
|
|
35
|
+
composed: true
|
|
36
|
+
});
|
|
37
|
+
this.focused = false;
|
|
38
|
+
}
|
|
39
|
+
get item() {
|
|
40
|
+
return this._item;
|
|
41
|
+
}
|
|
42
|
+
reset(item) {
|
|
43
|
+
this._item = item;
|
|
44
|
+
}
|
|
45
45
|
}
|
|
46
46
|
export class MenuItemAddedOrUpdatedEvent extends Event {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
47
|
+
constructor() {
|
|
48
|
+
super("sp-menu-item-added-or-updated", {
|
|
49
|
+
bubbles: true,
|
|
50
|
+
composed: true
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
set focusRoot(root) {
|
|
54
|
+
this.item.menuData.focusRoot = this.item.menuData.focusRoot || root;
|
|
55
|
+
}
|
|
56
|
+
set selectionRoot(root) {
|
|
57
|
+
this.item.menuData.selectionRoot = this.item.menuData.selectionRoot || root;
|
|
58
|
+
}
|
|
59
|
+
get item() {
|
|
60
|
+
return this._item;
|
|
61
|
+
}
|
|
62
|
+
set currentAncestorWithSelects(ancestor) {
|
|
63
|
+
this._currentAncestorWithSelects = ancestor;
|
|
64
|
+
}
|
|
65
|
+
get currentAncestorWithSelects() {
|
|
66
|
+
return this._currentAncestorWithSelects;
|
|
67
|
+
}
|
|
68
|
+
reset(item) {
|
|
69
|
+
this._item = item;
|
|
70
|
+
this._currentAncestorWithSelects = void 0;
|
|
71
|
+
item.menuData = {
|
|
72
|
+
focusRoot: void 0,
|
|
73
|
+
selectionRoot: void 0
|
|
74
|
+
};
|
|
75
|
+
}
|
|
77
76
|
}
|
|
78
77
|
const addOrUpdateEvent = new MenuItemAddedOrUpdatedEvent();
|
|
79
78
|
const removeEvent = new MenuItemRemovedEvent();
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
this.
|
|
98
|
-
this.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
if (this.disabled) {
|
|
194
|
-
event.preventDefault();
|
|
195
|
-
event.stopImmediatePropagation();
|
|
196
|
-
event.stopPropagation();
|
|
197
|
-
return false;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
proxyFocus() {
|
|
201
|
-
this.focus();
|
|
202
|
-
}
|
|
203
|
-
shouldProxyClick() {
|
|
204
|
-
let handled = false;
|
|
205
|
-
if (this.anchorElement) {
|
|
206
|
-
this.anchorElement.click();
|
|
207
|
-
handled = true;
|
|
208
|
-
}
|
|
209
|
-
return handled;
|
|
210
|
-
}
|
|
211
|
-
breakItemChildrenCache() {
|
|
212
|
-
this._itemChildren = undefined;
|
|
213
|
-
this.triggerUpdate();
|
|
214
|
-
}
|
|
215
|
-
render() {
|
|
216
|
-
return html `
|
|
79
|
+
const _MenuItem = class extends LikeAnchor(Focusable) {
|
|
80
|
+
constructor() {
|
|
81
|
+
super();
|
|
82
|
+
this.isInSubmenu = false;
|
|
83
|
+
this.active = false;
|
|
84
|
+
this.focused = false;
|
|
85
|
+
this.selected = false;
|
|
86
|
+
this._value = "";
|
|
87
|
+
this.hasSubmenu = false;
|
|
88
|
+
this.noWrap = false;
|
|
89
|
+
this.open = false;
|
|
90
|
+
this.handleSubmenuChange = () => {
|
|
91
|
+
var _a;
|
|
92
|
+
(_a = this.menuData.selectionRoot) == null ? void 0 : _a.selectOrToggleItem(this);
|
|
93
|
+
};
|
|
94
|
+
this.handleSubmenuPointerenter = () => {
|
|
95
|
+
if (this.leaveTimeout) {
|
|
96
|
+
clearTimeout(this.leaveTimeout);
|
|
97
|
+
delete this.leaveTimeout;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
this.menuData = {
|
|
101
|
+
focusRoot: void 0,
|
|
102
|
+
selectionRoot: void 0
|
|
103
|
+
};
|
|
104
|
+
this.proxyFocus = this.proxyFocus.bind(this);
|
|
105
|
+
this.addEventListener("click", this.handleClickCapture, {
|
|
106
|
+
capture: true
|
|
107
|
+
});
|
|
108
|
+
new MutationController(this, {
|
|
109
|
+
config: {
|
|
110
|
+
characterData: true,
|
|
111
|
+
childList: true,
|
|
112
|
+
subtree: true
|
|
113
|
+
},
|
|
114
|
+
callback: () => {
|
|
115
|
+
this.breakItemChildrenCache();
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
static get styles() {
|
|
120
|
+
return [menuItemStyles, checkmarkStyles, chevronStyles];
|
|
121
|
+
}
|
|
122
|
+
get value() {
|
|
123
|
+
return this._value || this.itemText;
|
|
124
|
+
}
|
|
125
|
+
set value(value) {
|
|
126
|
+
if (value === this._value) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
this._value = value || "";
|
|
130
|
+
if (this._value) {
|
|
131
|
+
this.setAttribute("value", this._value);
|
|
132
|
+
} else {
|
|
133
|
+
this.removeAttribute("value");
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
get itemText() {
|
|
137
|
+
return this.itemChildren.content.reduce((acc, node) => acc + (node.textContent || "").trim(), "");
|
|
138
|
+
}
|
|
139
|
+
get focusElement() {
|
|
140
|
+
return this;
|
|
141
|
+
}
|
|
142
|
+
get itemChildren() {
|
|
143
|
+
if (this._itemChildren) {
|
|
144
|
+
return this._itemChildren;
|
|
145
|
+
}
|
|
146
|
+
const iconSlot = this.shadowRoot.querySelector('slot[name="icon"]');
|
|
147
|
+
const icon = !iconSlot ? [] : iconSlot.assignedElements().map((element) => {
|
|
148
|
+
const newElement = element.cloneNode(true);
|
|
149
|
+
newElement.removeAttribute("slot");
|
|
150
|
+
newElement.classList.toggle("icon");
|
|
151
|
+
return newElement;
|
|
152
|
+
});
|
|
153
|
+
const contentSlot = this.shadowRoot.querySelector("slot:not([name])");
|
|
154
|
+
const content = !contentSlot ? [] : contentSlot.assignedNodes().map((node) => node.cloneNode(true));
|
|
155
|
+
this._itemChildren = { icon, content };
|
|
156
|
+
return this._itemChildren;
|
|
157
|
+
}
|
|
158
|
+
click() {
|
|
159
|
+
if (this.disabled) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (this.shouldProxyClick()) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
super.click();
|
|
166
|
+
}
|
|
167
|
+
handleClickCapture(event) {
|
|
168
|
+
if (this.disabled) {
|
|
169
|
+
event.preventDefault();
|
|
170
|
+
event.stopImmediatePropagation();
|
|
171
|
+
event.stopPropagation();
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
proxyFocus() {
|
|
176
|
+
this.focus();
|
|
177
|
+
}
|
|
178
|
+
shouldProxyClick() {
|
|
179
|
+
let handled = false;
|
|
180
|
+
if (this.anchorElement) {
|
|
181
|
+
this.anchorElement.click();
|
|
182
|
+
handled = true;
|
|
183
|
+
}
|
|
184
|
+
return handled;
|
|
185
|
+
}
|
|
186
|
+
breakItemChildrenCache() {
|
|
187
|
+
this._itemChildren = void 0;
|
|
188
|
+
this.triggerUpdate();
|
|
189
|
+
}
|
|
190
|
+
render() {
|
|
191
|
+
return html`
|
|
217
192
|
<slot name="icon"></slot>
|
|
218
193
|
<div id="label">
|
|
219
194
|
<slot id="slot"></slot>
|
|
220
195
|
</div>
|
|
221
196
|
<slot name="value"></slot>
|
|
222
|
-
${this.selected
|
|
223
|
-
? html `
|
|
197
|
+
${this.selected ? html`
|
|
224
198
|
<sp-icon-checkmark100
|
|
225
199
|
id="selected"
|
|
226
200
|
class="spectrum-UIIcon-Checkmark100 icon checkmark"
|
|
227
201
|
></sp-icon-checkmark100>
|
|
228
|
-
`
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
className: 'button anchor hidden',
|
|
235
|
-
})
|
|
236
|
-
: html ``}
|
|
202
|
+
` : html``}
|
|
203
|
+
${this.href && this.href.length > 0 ? super.renderAnchor({
|
|
204
|
+
id: "button",
|
|
205
|
+
ariaHidden: true,
|
|
206
|
+
className: "button anchor hidden"
|
|
207
|
+
}) : html``}
|
|
237
208
|
<slot
|
|
238
209
|
hidden
|
|
239
210
|
name="submenu"
|
|
240
211
|
@slotchange=${this.manageSubmenu}
|
|
241
212
|
></slot>
|
|
242
|
-
${this.hasSubmenu
|
|
243
|
-
? html `
|
|
213
|
+
${this.hasSubmenu ? html`
|
|
244
214
|
<sp-icon-chevron100
|
|
245
215
|
class="spectrum-UIIcon-ChevronRight100 chevron icon"
|
|
246
216
|
></sp-icon-chevron100>
|
|
247
|
-
`
|
|
248
|
-
: html ``}
|
|
217
|
+
` : html``}
|
|
249
218
|
`;
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
el.slot = slotName;
|
|
325
|
-
el.isSubmenu = false;
|
|
326
|
-
};
|
|
327
|
-
},
|
|
328
|
-
});
|
|
329
|
-
const closeOverlay = openOverlay(this, 'click', popover, {
|
|
330
|
-
placement: this.isLTR ? 'right-start' : 'left-start',
|
|
331
|
-
receivesFocus: 'auto',
|
|
332
|
-
root: this.menuData.focusRoot,
|
|
333
|
-
});
|
|
334
|
-
const closeSubmenu = async () => {
|
|
335
|
-
delete this.closeOverlay;
|
|
336
|
-
(await closeOverlay)();
|
|
337
|
-
};
|
|
338
|
-
this.closeOverlay = closeSubmenu;
|
|
339
|
-
const cleanup = (event) => {
|
|
340
|
-
event.stopPropagation();
|
|
341
|
-
delete this.closeOverlay;
|
|
342
|
-
returnSubmenu();
|
|
343
|
-
this.open = false;
|
|
344
|
-
this.active = false;
|
|
219
|
+
}
|
|
220
|
+
manageSubmenu(event) {
|
|
221
|
+
const assignedElements = event.target.assignedElements({
|
|
222
|
+
flatten: true
|
|
223
|
+
});
|
|
224
|
+
this.hasSubmenu = this.open || !!assignedElements.length;
|
|
225
|
+
}
|
|
226
|
+
handleRemoveActive(event) {
|
|
227
|
+
if (event.type === "pointerleave" && this.hasSubmenu || this.hasSubmenu || this.open) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
this.active = false;
|
|
231
|
+
}
|
|
232
|
+
handlePointerdown() {
|
|
233
|
+
this.active = true;
|
|
234
|
+
}
|
|
235
|
+
firstUpdated(changes) {
|
|
236
|
+
super.firstUpdated(changes);
|
|
237
|
+
this.setAttribute("tabindex", "-1");
|
|
238
|
+
this.addEventListener("pointerdown", this.handlePointerdown);
|
|
239
|
+
if (!this.hasAttribute("id")) {
|
|
240
|
+
this.id = `sp-menu-item-${_MenuItem.instanceCount++}`;
|
|
241
|
+
}
|
|
242
|
+
this.addEventListener("pointerenter", this.closeOverlaysForRoot);
|
|
243
|
+
}
|
|
244
|
+
closeOverlaysForRoot() {
|
|
245
|
+
if (this.open)
|
|
246
|
+
return;
|
|
247
|
+
const overalyCloseEvent = new OverlayCloseEvent({
|
|
248
|
+
root: this.menuData.focusRoot
|
|
249
|
+
});
|
|
250
|
+
this.dispatchEvent(overalyCloseEvent);
|
|
251
|
+
}
|
|
252
|
+
handleSubmenuClick() {
|
|
253
|
+
this.openOverlay();
|
|
254
|
+
}
|
|
255
|
+
handlePointerenter() {
|
|
256
|
+
if (this.leaveTimeout) {
|
|
257
|
+
clearTimeout(this.leaveTimeout);
|
|
258
|
+
delete this.leaveTimeout;
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
this.openOverlay();
|
|
262
|
+
}
|
|
263
|
+
handlePointerleave() {
|
|
264
|
+
if (this.hasSubmenu && this.open) {
|
|
265
|
+
this.leaveTimeout = setTimeout(() => {
|
|
266
|
+
delete this.leaveTimeout;
|
|
267
|
+
if (this.closeOverlay)
|
|
268
|
+
this.closeOverlay();
|
|
269
|
+
}, POINTERLEAVE_TIMEOUT);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
async openOverlay() {
|
|
273
|
+
if (!this.hasSubmenu || this.open || this.disabled) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
this.open = true;
|
|
277
|
+
this.active = true;
|
|
278
|
+
const submenu = this.shadowRoot.querySelector('slot[name="submenu"]').assignedElements()[0];
|
|
279
|
+
submenu.addEventListener("pointerenter", this.handleSubmenuPointerenter);
|
|
280
|
+
submenu.addEventListener("change", this.handleSubmenuChange);
|
|
281
|
+
const popover = document.createElement("sp-popover");
|
|
282
|
+
const returnSubmenu = reparentChildren([submenu], popover, {
|
|
283
|
+
position: "beforeend",
|
|
284
|
+
prepareCallback: (el) => {
|
|
285
|
+
const slotName = el.slot;
|
|
286
|
+
el.tabIndex = 0;
|
|
287
|
+
el.removeAttribute("slot");
|
|
288
|
+
el.isSubmenu = true;
|
|
289
|
+
return (el2) => {
|
|
290
|
+
el2.tabIndex = -1;
|
|
291
|
+
el2.slot = slotName;
|
|
292
|
+
el2.isSubmenu = false;
|
|
345
293
|
};
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
this.
|
|
407
|
-
this.
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
const closeOverlay = openOverlay(this, "click", popover, {
|
|
297
|
+
placement: this.isLTR ? "right-start" : "left-start",
|
|
298
|
+
receivesFocus: "auto",
|
|
299
|
+
root: this.menuData.focusRoot
|
|
300
|
+
});
|
|
301
|
+
const closeSubmenu = async () => {
|
|
302
|
+
delete this.closeOverlay;
|
|
303
|
+
(await closeOverlay)();
|
|
304
|
+
};
|
|
305
|
+
this.closeOverlay = closeSubmenu;
|
|
306
|
+
const cleanup = (event) => {
|
|
307
|
+
event.stopPropagation();
|
|
308
|
+
delete this.closeOverlay;
|
|
309
|
+
returnSubmenu();
|
|
310
|
+
this.open = false;
|
|
311
|
+
this.active = false;
|
|
312
|
+
};
|
|
313
|
+
this.addEventListener("sp-closed", cleanup, {
|
|
314
|
+
once: true
|
|
315
|
+
});
|
|
316
|
+
popover.addEventListener("change", closeSubmenu);
|
|
317
|
+
}
|
|
318
|
+
updateAriaSelected() {
|
|
319
|
+
const role = this.getAttribute("role");
|
|
320
|
+
if (role === "option") {
|
|
321
|
+
this.setAttribute("aria-selected", this.selected ? "true" : "false");
|
|
322
|
+
} else if (role === "menuitemcheckbox" || role === "menuitemradio") {
|
|
323
|
+
this.setAttribute("aria-checked", this.selected ? "true" : "false");
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
setRole(role) {
|
|
327
|
+
this.setAttribute("role", role);
|
|
328
|
+
this.updateAriaSelected();
|
|
329
|
+
}
|
|
330
|
+
updated(changes) {
|
|
331
|
+
super.updated(changes);
|
|
332
|
+
if (changes.has("label")) {
|
|
333
|
+
this.setAttribute("aria-label", this.label || "");
|
|
334
|
+
}
|
|
335
|
+
if (changes.has("active")) {
|
|
336
|
+
if (this.active) {
|
|
337
|
+
this.addEventListener("pointerup", this.handleRemoveActive);
|
|
338
|
+
this.addEventListener("pointerleave", this.handleRemoveActive);
|
|
339
|
+
} else {
|
|
340
|
+
this.removeEventListener("pointerup", this.handleRemoveActive);
|
|
341
|
+
this.removeEventListener("pointerleave", this.handleRemoveActive);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
if (this.anchorElement) {
|
|
345
|
+
this.anchorElement.addEventListener("focus", this.proxyFocus);
|
|
346
|
+
this.anchorElement.tabIndex = -1;
|
|
347
|
+
}
|
|
348
|
+
if (changes.has("selected")) {
|
|
349
|
+
this.updateAriaSelected();
|
|
350
|
+
}
|
|
351
|
+
if (changes.has("hasSubmenu")) {
|
|
352
|
+
if (this.hasSubmenu) {
|
|
353
|
+
this.addEventListener("click", this.handleSubmenuClick);
|
|
354
|
+
this.addEventListener("pointerenter", this.handlePointerenter);
|
|
355
|
+
this.addEventListener("pointerleave", this.handlePointerleave);
|
|
356
|
+
} else if (!this.closeOverlay) {
|
|
357
|
+
this.removeEventListener("click", this.handleSubmenuClick);
|
|
358
|
+
this.removeEventListener("pointerenter", this.handlePointerenter);
|
|
359
|
+
this.removeEventListener("pointerleave", this.handlePointerleave);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
connectedCallback() {
|
|
364
|
+
super.connectedCallback();
|
|
365
|
+
this.isInSubmenu = !!this.closest('[slot="submenu"]');
|
|
366
|
+
if (this.isInSubmenu) {
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
addOrUpdateEvent.reset(this);
|
|
370
|
+
this.dispatchEvent(addOrUpdateEvent);
|
|
371
|
+
this._parentElement = this.parentElement;
|
|
372
|
+
}
|
|
373
|
+
disconnectedCallback() {
|
|
374
|
+
var _a;
|
|
375
|
+
removeEvent.reset(this);
|
|
376
|
+
if (!this.isInSubmenu) {
|
|
377
|
+
(_a = this._parentElement) == null ? void 0 : _a.dispatchEvent(removeEvent);
|
|
378
|
+
}
|
|
379
|
+
this.isInSubmenu = false;
|
|
380
|
+
super.disconnectedCallback();
|
|
381
|
+
}
|
|
382
|
+
async triggerUpdate() {
|
|
383
|
+
if (this.isInSubmenu) {
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
await new Promise((ready) => requestAnimationFrame(ready));
|
|
387
|
+
addOrUpdateEvent.reset(this);
|
|
388
|
+
this.dispatchEvent(addOrUpdateEvent);
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
export let MenuItem = _MenuItem;
|
|
427
392
|
MenuItem.instanceCount = 0;
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
], MenuItem.prototype, "active",
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
], MenuItem.prototype, "focused",
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
], MenuItem.prototype, "selected",
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
], MenuItem.prototype, "value",
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
], MenuItem.prototype, "hasSubmenu",
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
], MenuItem.prototype, "noWrap",
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
], MenuItem.prototype, "anchorElement",
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
], MenuItem.prototype, "open",
|
|
459
|
-
//# sourceMappingURL=MenuItem.js.map
|
|
393
|
+
__decorateClass([
|
|
394
|
+
property({ type: Boolean, reflect: true })
|
|
395
|
+
], MenuItem.prototype, "active", 2);
|
|
396
|
+
__decorateClass([
|
|
397
|
+
property({ type: Boolean, reflect: true })
|
|
398
|
+
], MenuItem.prototype, "focused", 2);
|
|
399
|
+
__decorateClass([
|
|
400
|
+
property({ type: Boolean, reflect: true })
|
|
401
|
+
], MenuItem.prototype, "selected", 2);
|
|
402
|
+
__decorateClass([
|
|
403
|
+
property({ type: String })
|
|
404
|
+
], MenuItem.prototype, "value", 1);
|
|
405
|
+
__decorateClass([
|
|
406
|
+
property({ type: Boolean })
|
|
407
|
+
], MenuItem.prototype, "hasSubmenu", 2);
|
|
408
|
+
__decorateClass([
|
|
409
|
+
property({
|
|
410
|
+
type: Boolean,
|
|
411
|
+
reflect: true,
|
|
412
|
+
attribute: "no-wrap",
|
|
413
|
+
hasChanged() {
|
|
414
|
+
return false;
|
|
415
|
+
}
|
|
416
|
+
})
|
|
417
|
+
], MenuItem.prototype, "noWrap", 2);
|
|
418
|
+
__decorateClass([
|
|
419
|
+
query(".anchor")
|
|
420
|
+
], MenuItem.prototype, "anchorElement", 2);
|
|
421
|
+
__decorateClass([
|
|
422
|
+
property({ type: Boolean })
|
|
423
|
+
], MenuItem.prototype, "open", 2);
|
|
424
|
+
//# sourceMappingURL=MenuItem.js.map
|