@spectrum-web-components/menu 0.30.1-overlay.42 → 0.31.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 +2159 -0
- package/package.json +9 -9
- package/src/Menu.d.ts +3 -11
- package/src/Menu.dev.js +60 -139
- package/src/Menu.dev.js.map +2 -2
- package/src/Menu.js +3 -6
- package/src/Menu.js.map +3 -3
- package/src/MenuGroup.dev.js +3 -1
- package/src/MenuGroup.dev.js.map +2 -2
- package/src/MenuGroup.js +5 -3
- package/src/MenuGroup.js.map +2 -2
- package/src/MenuItem.d.ts +5 -18
- package/src/MenuItem.dev.js +84 -102
- package/src/MenuItem.dev.js.map +3 -3
- package/src/MenuItem.js +12 -31
- package/src/MenuItem.js.map +3 -3
- package/src/menu-item.css.dev.js +1 -1
- package/src/menu-item.css.dev.js.map +1 -1
- package/src/menu-item.css.js +1 -1
- package/src/menu-item.css.js.map +1 -1
- package/src/menu.css.dev.js +1 -1
- package/src/menu.css.dev.js.map +1 -1
- package/src/menu.css.js +1 -1
- package/src/menu.css.js.map +1 -1
- package/stories/submenu.stories.js +20 -26
- package/stories/submenu.stories.js.map +3 -3
- package/test/menu-group.test.js +1 -14
- package/test/menu-group.test.js.map +2 -2
- package/test/menu-selects.test.js +1 -3
- package/test/menu-selects.test.js.map +2 -2
- package/test/menu.test.js +0 -7
- package/test/menu.test.js.map +2 -2
- package/test/submenu.test.js +83 -198
- package/test/submenu.test.js.map +2 -2
package/src/MenuItem.dev.js
CHANGED
|
@@ -22,10 +22,12 @@ import { LikeAnchor } from "@spectrum-web-components/shared/src/like-anchor.js";
|
|
|
22
22
|
import { Focusable } from "@spectrum-web-components/shared/src/focusable.js";
|
|
23
23
|
import "@spectrum-web-components/icons-ui/icons/sp-icon-chevron100.js";
|
|
24
24
|
import chevronStyles from "@spectrum-web-components/icon/src/spectrum-icon-chevron.css.js";
|
|
25
|
+
import { openOverlay } from "@spectrum-web-components/overlay/src/loader.js";
|
|
26
|
+
import { OverlayCloseEvent } from "@spectrum-web-components/overlay/src/overlay-events.js";
|
|
25
27
|
import menuItemStyles from "./menu-item.css.js";
|
|
26
28
|
import checkmarkStyles from "@spectrum-web-components/icon/src/spectrum-icon-checkmark.css.js";
|
|
29
|
+
import { reparentChildren } from "@spectrum-web-components/shared/src/reparent-children.js";
|
|
27
30
|
import { MutationController } from "@lit-labs/observers/mutation-controller.js";
|
|
28
|
-
import "@spectrum-web-components/overlay/sp-overlay.js";
|
|
29
31
|
const POINTERLEAVE_TIMEOUT = 100;
|
|
30
32
|
export class MenuItemRemovedEvent extends Event {
|
|
31
33
|
constructor() {
|
|
@@ -48,14 +50,10 @@ export class MenuItemAddedOrUpdatedEvent extends Event {
|
|
|
48
50
|
bubbles: true,
|
|
49
51
|
composed: true
|
|
50
52
|
});
|
|
51
|
-
this.menuCascade = /* @__PURE__ */ new WeakMap();
|
|
52
53
|
}
|
|
53
54
|
set focusRoot(root) {
|
|
54
55
|
this.item.menuData.focusRoot = this.item.menuData.focusRoot || root;
|
|
55
56
|
}
|
|
56
|
-
set parentMenu(menu) {
|
|
57
|
-
this.item.menuData.parentMenu = this.item.menuData.parentMenu || menu;
|
|
58
|
-
}
|
|
59
57
|
set selectionRoot(root) {
|
|
60
58
|
this.item.menuData.selectionRoot = this.item.menuData.selectionRoot || root;
|
|
61
59
|
}
|
|
@@ -82,6 +80,7 @@ const removeEvent = new MenuItemRemovedEvent();
|
|
|
82
80
|
const _MenuItem = class extends LikeAnchor(Focusable) {
|
|
83
81
|
constructor() {
|
|
84
82
|
super();
|
|
83
|
+
this.isInSubmenu = false;
|
|
85
84
|
this.active = false;
|
|
86
85
|
this.focused = false;
|
|
87
86
|
this.selected = false;
|
|
@@ -89,14 +88,25 @@ const _MenuItem = class extends LikeAnchor(Focusable) {
|
|
|
89
88
|
this.hasSubmenu = false;
|
|
90
89
|
this.noWrap = false;
|
|
91
90
|
this.open = false;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
91
|
+
/**
|
|
92
|
+
* When there is a `change` event in the submenu for this item
|
|
93
|
+
* then we "click" this item to cascade the selection up the
|
|
94
|
+
* menu tree allowing all submenus between the initial selection
|
|
95
|
+
* and the root of the tree to have their selection changes and
|
|
96
|
+
* be closed.
|
|
97
|
+
*/
|
|
98
|
+
this.handleSubmenuChange = () => {
|
|
99
|
+
var _a;
|
|
100
|
+
(_a = this.menuData.selectionRoot) == null ? void 0 : _a.selectOrToggleItem(this);
|
|
101
|
+
};
|
|
102
|
+
this.handleSubmenuPointerenter = () => {
|
|
103
|
+
if (this.leaveTimeout) {
|
|
104
|
+
clearTimeout(this.leaveTimeout);
|
|
105
|
+
delete this.leaveTimeout;
|
|
106
|
+
}
|
|
96
107
|
};
|
|
97
108
|
this.menuData = {
|
|
98
109
|
focusRoot: void 0,
|
|
99
|
-
parentMenu: void 0,
|
|
100
110
|
selectionRoot: void 0
|
|
101
111
|
};
|
|
102
112
|
this.proxyFocus = this.proxyFocus.bind(this);
|
|
@@ -214,40 +224,11 @@ const _MenuItem = class extends LikeAnchor(Focusable) {
|
|
|
214
224
|
ariaHidden: true,
|
|
215
225
|
className: "button anchor hidden"
|
|
216
226
|
}) : html``}
|
|
217
|
-
<
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
.offset=${[-10, -5]}
|
|
223
|
-
.type=${"auto"}
|
|
224
|
-
@close=${(event) => event.stopPropagation()}
|
|
225
|
-
>
|
|
226
|
-
<sp-popover
|
|
227
|
-
@change=${(event) => {
|
|
228
|
-
this.handleSubmenuChange(event);
|
|
229
|
-
this.open = false;
|
|
230
|
-
}}
|
|
231
|
-
@pointerenter=${this.handleSubmenuPointerenter}
|
|
232
|
-
@pointerleave=${this.handleSubmenuPointerleave}
|
|
233
|
-
@sp-menu-item-added-or-updated=${(event) => event.stopPropagation()}
|
|
234
|
-
>
|
|
235
|
-
<slot
|
|
236
|
-
name="submenu"
|
|
237
|
-
@slotchange=${this.manageSubmenu}
|
|
238
|
-
@sp-menu-item-removed=${(event) => {
|
|
239
|
-
event.stopPropagation();
|
|
240
|
-
}}
|
|
241
|
-
@sp-menu-item-added-or-updated=${{
|
|
242
|
-
handleEvent: (event) => {
|
|
243
|
-
event.reset(event.item);
|
|
244
|
-
},
|
|
245
|
-
capture: true
|
|
246
|
-
}}
|
|
247
|
-
@focusin=${(event) => event.stopPropagation()}
|
|
248
|
-
></slot>
|
|
249
|
-
</sp-popover>
|
|
250
|
-
</sp-overlay>
|
|
227
|
+
<slot
|
|
228
|
+
hidden
|
|
229
|
+
name="submenu"
|
|
230
|
+
@slotchange=${this.manageSubmenu}
|
|
231
|
+
></slot>
|
|
251
232
|
${this.hasSubmenu ? html`
|
|
252
233
|
<sp-icon-chevron100
|
|
253
234
|
class="spectrum-UIIcon-ChevronRight100 chevron icon"
|
|
@@ -259,10 +240,10 @@ const _MenuItem = class extends LikeAnchor(Focusable) {
|
|
|
259
240
|
const assignedElements = event.target.assignedElements({
|
|
260
241
|
flatten: true
|
|
261
242
|
});
|
|
262
|
-
this.hasSubmenu = !!assignedElements.length;
|
|
243
|
+
this.hasSubmenu = this.open || !!assignedElements.length;
|
|
263
244
|
}
|
|
264
|
-
handleRemoveActive() {
|
|
265
|
-
if (this.open) {
|
|
245
|
+
handleRemoveActive(event) {
|
|
246
|
+
if (event.type === "pointerleave" && this.hasSubmenu || this.hasSubmenu || this.open) {
|
|
266
247
|
return;
|
|
267
248
|
}
|
|
268
249
|
this.active = false;
|
|
@@ -280,15 +261,14 @@ const _MenuItem = class extends LikeAnchor(Focusable) {
|
|
|
280
261
|
this.addEventListener("pointerenter", this.closeOverlaysForRoot);
|
|
281
262
|
}
|
|
282
263
|
closeOverlaysForRoot() {
|
|
283
|
-
var _a;
|
|
284
264
|
if (this.open)
|
|
285
265
|
return;
|
|
286
|
-
|
|
266
|
+
const overalyCloseEvent = new OverlayCloseEvent({
|
|
267
|
+
root: this.menuData.focusRoot
|
|
268
|
+
});
|
|
269
|
+
this.dispatchEvent(overalyCloseEvent);
|
|
287
270
|
}
|
|
288
|
-
handleSubmenuClick(
|
|
289
|
-
if (event.composedPath().includes(this.overlayElement)) {
|
|
290
|
-
return;
|
|
291
|
-
}
|
|
271
|
+
handleSubmenuClick() {
|
|
292
272
|
this.openOverlay();
|
|
293
273
|
}
|
|
294
274
|
handlePointerenter() {
|
|
@@ -300,54 +280,64 @@ const _MenuItem = class extends LikeAnchor(Focusable) {
|
|
|
300
280
|
this.openOverlay();
|
|
301
281
|
}
|
|
302
282
|
handlePointerleave() {
|
|
303
|
-
if (this.
|
|
283
|
+
if (this.hasSubmenu && this.open) {
|
|
304
284
|
this.leaveTimeout = setTimeout(() => {
|
|
305
285
|
delete this.leaveTimeout;
|
|
306
|
-
this.
|
|
286
|
+
if (this.closeOverlay)
|
|
287
|
+
this.closeOverlay();
|
|
307
288
|
}, POINTERLEAVE_TIMEOUT);
|
|
308
289
|
}
|
|
309
290
|
}
|
|
310
|
-
/**
|
|
311
|
-
* When there is a `change` event in the submenu for this item
|
|
312
|
-
* then we "click" this item to cascade the selection up the
|
|
313
|
-
* menu tree allowing all submenus between the initial selection
|
|
314
|
-
* and the root of the tree to have their selection changes and
|
|
315
|
-
* be closed.
|
|
316
|
-
*/
|
|
317
|
-
handleSubmenuChange(event) {
|
|
318
|
-
var _a;
|
|
319
|
-
event.stopPropagation();
|
|
320
|
-
(_a = this.menuData.selectionRoot) == null ? void 0 : _a.selectOrToggleItem(this);
|
|
321
|
-
}
|
|
322
|
-
handleSubmenuPointerenter() {
|
|
323
|
-
this.recentlyLeftChild = true;
|
|
324
|
-
}
|
|
325
|
-
async handleSubmenuPointerleave() {
|
|
326
|
-
requestAnimationFrame(() => {
|
|
327
|
-
this.recentlyLeftChild = false;
|
|
328
|
-
});
|
|
329
|
-
}
|
|
330
|
-
handleSubmenuOpen(event) {
|
|
331
|
-
this.focused = false;
|
|
332
|
-
const parentOverlay = event.composedPath().find((el) => {
|
|
333
|
-
return el !== this.overlayElement && el.localName === "sp-overlay";
|
|
334
|
-
});
|
|
335
|
-
this.overlayElement.parentOverlayToForceClose = parentOverlay;
|
|
336
|
-
}
|
|
337
291
|
async openOverlay() {
|
|
338
292
|
if (!this.hasSubmenu || this.open || this.disabled) {
|
|
339
293
|
return;
|
|
340
294
|
}
|
|
341
295
|
this.open = true;
|
|
342
296
|
this.active = true;
|
|
297
|
+
const submenu = this.shadowRoot.querySelector(
|
|
298
|
+
'slot[name="submenu"]'
|
|
299
|
+
).assignedElements()[0];
|
|
300
|
+
submenu.addEventListener(
|
|
301
|
+
"pointerenter",
|
|
302
|
+
this.handleSubmenuPointerenter
|
|
303
|
+
);
|
|
304
|
+
submenu.addEventListener("change", this.handleSubmenuChange);
|
|
305
|
+
const popover = document.createElement("sp-popover");
|
|
306
|
+
const returnSubmenu = reparentChildren([submenu], popover, {
|
|
307
|
+
position: "beforeend",
|
|
308
|
+
prepareCallback: (el) => {
|
|
309
|
+
const slotName = el.slot;
|
|
310
|
+
el.tabIndex = 0;
|
|
311
|
+
el.removeAttribute("slot");
|
|
312
|
+
el.isSubmenu = true;
|
|
313
|
+
return (el2) => {
|
|
314
|
+
el2.tabIndex = -1;
|
|
315
|
+
el2.slot = slotName;
|
|
316
|
+
el2.isSubmenu = false;
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
const closeOverlay = openOverlay(this, "click", popover, {
|
|
321
|
+
placement: this.isLTR ? "right-start" : "left-start",
|
|
322
|
+
receivesFocus: "auto",
|
|
323
|
+
root: this.menuData.focusRoot
|
|
324
|
+
});
|
|
325
|
+
const closeSubmenu = async () => {
|
|
326
|
+
delete this.closeOverlay;
|
|
327
|
+
(await closeOverlay)();
|
|
328
|
+
};
|
|
329
|
+
this.closeOverlay = closeSubmenu;
|
|
343
330
|
const cleanup = (event) => {
|
|
344
331
|
event.stopPropagation();
|
|
332
|
+
delete this.closeOverlay;
|
|
333
|
+
returnSubmenu();
|
|
345
334
|
this.open = false;
|
|
346
335
|
this.active = false;
|
|
347
336
|
};
|
|
348
337
|
this.addEventListener("sp-closed", cleanup, {
|
|
349
338
|
once: true
|
|
350
339
|
});
|
|
340
|
+
popover.addEventListener("change", closeSubmenu);
|
|
351
341
|
}
|
|
352
342
|
updateAriaSelected() {
|
|
353
343
|
const role = this.getAttribute("role");
|
|
@@ -365,14 +355,12 @@ const _MenuItem = class extends LikeAnchor(Focusable) {
|
|
|
365
355
|
this.updateAriaSelected();
|
|
366
356
|
}
|
|
367
357
|
updated(changes) {
|
|
368
|
-
var _a;
|
|
369
358
|
super.updated(changes);
|
|
370
359
|
if (changes.has("label")) {
|
|
371
360
|
this.setAttribute("aria-label", this.label || "");
|
|
372
361
|
}
|
|
373
362
|
if (changes.has("active")) {
|
|
374
363
|
if (this.active) {
|
|
375
|
-
(_a = this.menuData.selectionRoot) == null ? void 0 : _a.closeDescendentOverlays();
|
|
376
364
|
this.addEventListener("pointerup", this.handleRemoveActive);
|
|
377
365
|
this.addEventListener("pointerleave", this.handleRemoveActive);
|
|
378
366
|
this.addEventListener("pointercancel", this.handleRemoveActive);
|
|
@@ -400,7 +388,6 @@ const _MenuItem = class extends LikeAnchor(Focusable) {
|
|
|
400
388
|
this.addEventListener("click", this.handleSubmenuClick);
|
|
401
389
|
this.addEventListener("pointerenter", this.handlePointerenter);
|
|
402
390
|
this.addEventListener("pointerleave", this.handlePointerleave);
|
|
403
|
-
this.addEventListener("sp-opened", this.handleSubmenuOpen);
|
|
404
391
|
} else if (!this.closeOverlay) {
|
|
405
392
|
this.removeEventListener("click", this.handleSubmenuClick);
|
|
406
393
|
this.removeEventListener(
|
|
@@ -411,37 +398,35 @@ const _MenuItem = class extends LikeAnchor(Focusable) {
|
|
|
411
398
|
"pointerleave",
|
|
412
399
|
this.handlePointerleave
|
|
413
400
|
);
|
|
414
|
-
this.removeEventListener("sp-opened", this.handleSubmenuOpen);
|
|
415
401
|
}
|
|
416
402
|
}
|
|
417
403
|
}
|
|
418
404
|
connectedCallback() {
|
|
419
405
|
super.connectedCallback();
|
|
420
|
-
this.
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
406
|
+
this.isInSubmenu = !!this.closest('[slot="submenu"]');
|
|
407
|
+
if (this.isInSubmenu) {
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
addOrUpdateEvent.reset(this);
|
|
411
|
+
this.dispatchEvent(addOrUpdateEvent);
|
|
412
|
+
this._parentElement = this.parentElement;
|
|
424
413
|
}
|
|
425
414
|
disconnectedCallback() {
|
|
426
415
|
var _a;
|
|
427
416
|
removeEvent.reset(this);
|
|
428
|
-
(
|
|
417
|
+
if (!this.isInSubmenu) {
|
|
418
|
+
(_a = this._parentElement) == null ? void 0 : _a.dispatchEvent(removeEvent);
|
|
419
|
+
}
|
|
420
|
+
this.isInSubmenu = false;
|
|
429
421
|
super.disconnectedCallback();
|
|
430
422
|
}
|
|
431
423
|
async triggerUpdate() {
|
|
432
|
-
if (this.
|
|
424
|
+
if (this.isInSubmenu) {
|
|
433
425
|
return;
|
|
434
426
|
}
|
|
435
|
-
this.willTriggerUpdate = true;
|
|
436
427
|
await new Promise((ready) => requestAnimationFrame(ready));
|
|
437
428
|
addOrUpdateEvent.reset(this);
|
|
438
429
|
this.dispatchEvent(addOrUpdateEvent);
|
|
439
|
-
this._parentElement = this.assignedSlot || this.parentElement;
|
|
440
|
-
if (!!this.menuData.focusRoot) {
|
|
441
|
-
this.resolveMenuDataUpdated();
|
|
442
|
-
}
|
|
443
|
-
this.willTriggerUpdate = false;
|
|
444
|
-
return this.menuDataUpdated;
|
|
445
430
|
}
|
|
446
431
|
};
|
|
447
432
|
export let MenuItem = _MenuItem;
|
|
@@ -474,9 +459,6 @@ __decorateClass([
|
|
|
474
459
|
__decorateClass([
|
|
475
460
|
query(".anchor")
|
|
476
461
|
], MenuItem.prototype, "anchorElement", 2);
|
|
477
|
-
__decorateClass([
|
|
478
|
-
query("sp-overlay")
|
|
479
|
-
], MenuItem.prototype, "overlayElement", 2);
|
|
480
462
|
__decorateClass([
|
|
481
463
|
property({ type: Boolean })
|
|
482
464
|
], MenuItem.prototype, "open", 2);
|
package/src/MenuItem.dev.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["MenuItem.ts"],
|
|
4
|
-
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n html,\n PropertyValues,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport {\n property,\n query,\n} from '@spectrum-web-components/base/src/decorators.js';\n\nimport '@spectrum-web-components/icons-ui/icons/sp-icon-checkmark100.js';\nimport { LikeAnchor } from '@spectrum-web-components/shared/src/like-anchor.js';\nimport { Focusable } from '@spectrum-web-components/shared/src/focusable.js';\nimport '@spectrum-web-components/icons-ui/icons/sp-icon-chevron100.js';\nimport chevronStyles from '@spectrum-web-components/icon/src/spectrum-icon-chevron.css.js';\n\nimport menuItemStyles from './menu-item.css.js';\nimport checkmarkStyles from '@spectrum-web-components/icon/src/spectrum-icon-checkmark.css.js';\nimport type { Menu } from './Menu.dev.js'\nimport { MutationController } from '@lit-labs/observers/mutation-controller.js';\nimport '@spectrum-web-components/overlay/sp-overlay.js';\nimport { OverlayBase } from 'overlay/src/OverlayBase.js';\n\n/**\n * Duration during which a pointing device can leave an `<sp-menu-item>` element\n * and return to it or to the submenu opened from it before closing that submenu.\n **/\nconst POINTERLEAVE_TIMEOUT = 100;\n\nexport class MenuItemRemovedEvent extends Event {\n constructor() {\n super('sp-menu-item-removed', {\n bubbles: true,\n composed: true,\n });\n }\n get item(): MenuItem {\n return this._item;\n }\n _item!: MenuItem;\n focused = false;\n reset(item: MenuItem): void {\n this._item = item;\n }\n}\n\nexport class MenuItemAddedOrUpdatedEvent extends Event {\n constructor() {\n super('sp-menu-item-added-or-updated', {\n bubbles: true,\n composed: true,\n });\n }\n menuCascade = new WeakMap<\n HTMLElement,\n {\n hadFocusRoot: boolean;\n ancestorWithSelects?: HTMLElement;\n }\n >();\n set focusRoot(root: Menu | undefined) {\n this.item.menuData.focusRoot = this.item.menuData.focusRoot || root;\n }\n set parentMenu(menu: Menu | undefined) {\n this.item.menuData.parentMenu = this.item.menuData.parentMenu || menu;\n }\n set selectionRoot(root: Menu) {\n this.item.menuData.selectionRoot =\n this.item.menuData.selectionRoot || root;\n }\n get item(): MenuItem {\n return this._item;\n }\n _item!: MenuItem;\n set currentAncestorWithSelects(ancestor: Menu | undefined) {\n this._currentAncestorWithSelects = ancestor;\n }\n get currentAncestorWithSelects(): Menu | undefined {\n return this._currentAncestorWithSelects;\n }\n _currentAncestorWithSelects?: Menu;\n reset(item: MenuItem): void {\n this._item = item;\n this._currentAncestorWithSelects = undefined;\n item.menuData = {\n focusRoot: undefined,\n selectionRoot: undefined,\n };\n }\n}\n\nexport type MenuItemChildren = { icon: Element[]; content: Node[] };\n\nconst addOrUpdateEvent = new MenuItemAddedOrUpdatedEvent();\nconst removeEvent = new MenuItemRemovedEvent();\n\n/**\n * @element sp-menu-item\n *\n * @slot - text content to display within the Menu Item\n * @slot icon - icon element to be placed at the start of the Menu Item\n * @slot value - content placed at the end of the Menu Item like values, keyboard shortcuts, etc.\n * @fires sp-menu-item-added - announces the item has been added so a parent menu can take ownerships\n * @fires sp-menu-item-removed - announces when removed from the DOM so the parent menu can remove ownership and update selected state\n */\nexport class MenuItem extends LikeAnchor(Focusable) {\n public static override get styles(): CSSResultArray {\n return [menuItemStyles, checkmarkStyles, chevronStyles];\n }\n\n static instanceCount = 0;\n\n @property({ type: Boolean, reflect: true })\n public active = false;\n\n @property({ type: Boolean, reflect: true })\n public focused = false;\n\n @property({ type: Boolean, reflect: true })\n public selected = false;\n\n @property({ type: String })\n public get value(): string {\n return this._value || this.itemText;\n }\n\n public set value(value: string) {\n if (value === this._value) {\n return;\n }\n this._value = value || '';\n if (this._value) {\n this.setAttribute('value', this._value);\n } else {\n this.removeAttribute('value');\n }\n }\n\n private _value = '';\n\n /**\n * @private\n */\n public get itemText(): string {\n return this.itemChildren.content.reduce(\n (acc, node) => acc + (node.textContent || '').trim(),\n ''\n );\n }\n\n @property({ type: Boolean })\n public hasSubmenu = false;\n\n @property({\n type: Boolean,\n reflect: true,\n attribute: 'no-wrap',\n hasChanged() {\n return false;\n },\n })\n public noWrap = false;\n\n @query('.anchor')\n private anchorElement!: HTMLAnchorElement;\n\n @query('sp-overlay')\n public overlayElement!: OverlayBase;\n\n public override get focusElement(): HTMLElement {\n return this;\n }\n\n public get itemChildren(): MenuItemChildren {\n if (this._itemChildren) {\n return this._itemChildren;\n }\n\n const iconSlot = this.shadowRoot?.querySelector(\n 'slot[name=\"icon\"]'\n ) as HTMLSlotElement;\n const icon = !iconSlot\n ? []\n : iconSlot.assignedElements().map((element) => {\n const newElement = element.cloneNode(true) as HTMLElement;\n newElement.removeAttribute('slot');\n newElement.classList.toggle('icon');\n return newElement;\n });\n const contentSlot = this.shadowRoot?.querySelector(\n 'slot:not([name])'\n ) as HTMLSlotElement;\n const content = !contentSlot\n ? []\n : contentSlot.assignedNodes().map((node) => node.cloneNode(true));\n this._itemChildren = { icon, content };\n\n return this._itemChildren;\n }\n\n private _itemChildren?: MenuItemChildren;\n\n constructor() {\n super();\n this.proxyFocus = this.proxyFocus.bind(this);\n\n this.addEventListener('click', this.handleClickCapture, {\n capture: true,\n });\n\n new MutationController(this, {\n config: {\n characterData: true,\n childList: true,\n subtree: true,\n },\n callback: () => {\n this.breakItemChildrenCache();\n },\n });\n }\n\n @property({ type: Boolean })\n public open = false;\n\n public override click(): void {\n if (this.disabled) {\n return;\n }\n\n if (this.shouldProxyClick()) {\n return;\n }\n\n super.click();\n }\n\n private handleClickCapture(event: Event): void | boolean {\n if (this.disabled) {\n event.preventDefault();\n event.stopImmediatePropagation();\n event.stopPropagation();\n return false;\n }\n }\n\n private proxyFocus(): void {\n this.focus();\n }\n\n private shouldProxyClick(): boolean {\n let handled = false;\n if (this.anchorElement) {\n this.anchorElement.click();\n handled = true;\n }\n return handled;\n }\n\n protected breakItemChildrenCache(): void {\n this._itemChildren = undefined;\n this.triggerUpdate();\n }\n\n protected override render(): TemplateResult {\n return html`\n <slot name=\"icon\"></slot>\n <div id=\"label\">\n <slot id=\"slot\"></slot>\n </div>\n <slot name=\"value\"></slot>\n ${this.selected\n ? html`\n <sp-icon-checkmark100\n id=\"selected\"\n class=\"spectrum-UIIcon-Checkmark100 icon checkmark\"\n ></sp-icon-checkmark100>\n `\n : html``}\n ${this.href && this.href.length > 0\n ? super.renderAnchor({\n id: 'button',\n ariaHidden: true,\n className: 'button anchor hidden',\n })\n : html``}\n <sp-overlay\n .triggerElement=${this as HTMLElement}\n ?disabled=${!this.hasSubmenu}\n ?open=${this.hasSubmenu && this.open}\n .placement=${this.isLTR ? 'right-start' : 'left-start'}\n .offset=${[-10, -5] as [number, number]}\n .type=${'auto'}\n @close=${(event: Event) => event.stopPropagation()}\n >\n <sp-popover\n @change=${(event: Event) => {\n this.handleSubmenuChange(event);\n this.open = false;\n }}\n @pointerenter=${this.handleSubmenuPointerenter}\n @pointerleave=${this.handleSubmenuPointerleave}\n @sp-menu-item-added-or-updated=${(event: Event) =>\n event.stopPropagation()}\n >\n <slot\n name=\"submenu\"\n @slotchange=${this.manageSubmenu}\n @sp-menu-item-removed=${(event: Event) => {\n event.stopPropagation();\n }}\n @sp-menu-item-added-or-updated=${{\n handleEvent: (\n event: MenuItemAddedOrUpdatedEvent\n ) => {\n event.reset(event.item);\n },\n capture: true,\n }}\n @focusin=${(event: Event) => event.stopPropagation()}\n ></slot>\n </sp-popover>\n </sp-overlay>\n ${this.hasSubmenu\n ? html`\n <sp-icon-chevron100\n class=\"spectrum-UIIcon-ChevronRight100 chevron icon\"\n ></sp-icon-chevron100>\n `\n : html``}\n `;\n }\n\n protected manageSubmenu(event: Event & { target: HTMLSlotElement }): void {\n const assignedElements = event.target.assignedElements({\n flatten: true,\n });\n this.hasSubmenu = !!assignedElements.length;\n }\n\n private handleRemoveActive(): void {\n if (this.open) {\n return;\n }\n this.active = false;\n }\n\n private handlePointerdown(): void {\n this.active = true;\n }\n\n protected override firstUpdated(changes: PropertyValues): void {\n super.firstUpdated(changes);\n this.setAttribute('tabindex', '-1');\n this.addEventListener('pointerdown', this.handlePointerdown);\n if (!this.hasAttribute('id')) {\n this.id = `sp-menu-item-${MenuItem.instanceCount++}`;\n }\n this.addEventListener('pointerenter', this.closeOverlaysForRoot);\n }\n\n protected closeOverlaysForRoot(): void {\n if (this.open) return;\n this.menuData.parentMenu?.closeDescendentOverlays();\n }\n\n public closeOverlay?: () => Promise<void>;\n\n protected handleSubmenuClick(event: Event): void {\n if (event.composedPath().includes(this.overlayElement)) {\n return;\n }\n this.openOverlay();\n }\n\n protected handlePointerenter(): void {\n if (this.leaveTimeout) {\n clearTimeout(this.leaveTimeout);\n delete this.leaveTimeout;\n return;\n }\n this.openOverlay();\n }\n\n protected leaveTimeout?: ReturnType<typeof setTimeout>;\n protected recentlyLeftChild = false;\n\n protected handlePointerleave(): void {\n if (this.open && !this.recentlyLeftChild) {\n this.leaveTimeout = setTimeout(() => {\n delete this.leaveTimeout;\n this.open = false;\n }, POINTERLEAVE_TIMEOUT);\n }\n }\n\n /**\n * When there is a `change` event in the submenu for this item\n * then we \"click\" this item to cascade the selection up the\n * menu tree allowing all submenus between the initial selection\n * and the root of the tree to have their selection changes and\n * be closed.\n */\n protected handleSubmenuChange(event: Event): void {\n event.stopPropagation();\n this.menuData.selectionRoot?.selectOrToggleItem(this);\n }\n\n protected handleSubmenuPointerenter(): void {\n this.recentlyLeftChild = true;\n }\n\n protected async handleSubmenuPointerleave(): Promise<void> {\n requestAnimationFrame(() => {\n this.recentlyLeftChild = false;\n });\n }\n\n protected handleSubmenuOpen(event: Event): void {\n this.focused = false;\n const parentOverlay = event.composedPath().find((el) => {\n return (\n el !== this.overlayElement &&\n (el as HTMLElement).localName === 'sp-overlay'\n );\n }) as OverlayBase;\n this.overlayElement.parentOverlayToForceClose = parentOverlay;\n }\n\n public async openOverlay(): Promise<void> {\n if (!this.hasSubmenu || this.open || this.disabled) {\n return;\n }\n this.open = true;\n this.active = true;\n const cleanup = (event: Event): void => {\n event.stopPropagation();\n this.open = false;\n this.active = false;\n };\n this.addEventListener('sp-closed', cleanup as EventListener, {\n once: true,\n });\n }\n\n updateAriaSelected(): void {\n const role = this.getAttribute('role');\n if (role === 'option') {\n this.setAttribute(\n 'aria-selected',\n this.selected ? 'true' : 'false'\n );\n } else if (role === 'menuitemcheckbox' || role === 'menuitemradio') {\n this.setAttribute('aria-checked', this.selected ? 'true' : 'false');\n }\n }\n\n public setRole(role: string): void {\n this.setAttribute('role', role);\n this.updateAriaSelected();\n }\n\n protected override updated(changes: PropertyValues<this>): void {\n super.updated(changes);\n if (changes.has('label')) {\n this.setAttribute('aria-label', this.label || '');\n }\n if (changes.has('active')) {\n if (this.active) {\n this.menuData.selectionRoot?.closeDescendentOverlays();\n this.addEventListener('pointerup', this.handleRemoveActive);\n this.addEventListener('pointerleave', this.handleRemoveActive);\n this.addEventListener('pointercancel', this.handleRemoveActive);\n } else {\n this.removeEventListener('pointerup', this.handleRemoveActive);\n this.removeEventListener(\n 'pointerleave',\n this.handleRemoveActive\n );\n this.removeEventListener(\n 'pointercancel',\n this.handleRemoveActive\n );\n }\n }\n if (this.anchorElement) {\n this.anchorElement.addEventListener('focus', this.proxyFocus);\n this.anchorElement.tabIndex = -1;\n }\n if (changes.has('selected')) {\n this.updateAriaSelected();\n }\n if (changes.has('hasSubmenu')) {\n if (this.hasSubmenu) {\n this.addEventListener('click', this.handleSubmenuClick);\n this.addEventListener('pointerenter', this.handlePointerenter);\n this.addEventListener('pointerleave', this.handlePointerleave);\n this.addEventListener('sp-opened', this.handleSubmenuOpen);\n } else if (!this.closeOverlay) {\n this.removeEventListener('click', this.handleSubmenuClick);\n this.removeEventListener(\n 'pointerenter',\n this.handlePointerenter\n );\n this.removeEventListener(\n 'pointerleave',\n this.handlePointerleave\n );\n this.removeEventListener('sp-opened', this.handleSubmenuOpen);\n }\n }\n }\n\n public override connectedCallback(): void {\n super.connectedCallback();\n this.menuDataUpdated = new Promise(\n (res) => (this.resolveMenuDataUpdated = res)\n );\n this.triggerUpdate();\n }\n\n _parentElement!: HTMLElement;\n\n public override disconnectedCallback(): void {\n removeEvent.reset(this);\n this._parentElement?.dispatchEvent(removeEvent);\n super.disconnectedCallback();\n }\n\n private willTriggerUpdate = false;\n\n public async triggerUpdate(): Promise<void> {\n if (this.willTriggerUpdate) {\n return;\n }\n this.willTriggerUpdate = true;\n await new Promise((ready) => requestAnimationFrame(ready));\n addOrUpdateEvent.reset(this);\n this.dispatchEvent(addOrUpdateEvent);\n this._parentElement =\n this.assignedSlot || (this.parentElement as HTMLElement);\n if (!!this.menuData.focusRoot) {\n this.resolveMenuDataUpdated();\n }\n this.willTriggerUpdate = false;\n return this.menuDataUpdated;\n }\n\n protected menuDataUpdated!: Promise<void>;\n protected resolveMenuDataUpdated = (): void => {\n return;\n };\n\n public menuData: {\n focusRoot?: Menu;\n parentMenu?: Menu;\n selectionRoot?: Menu;\n } = {\n focusRoot: undefined,\n parentMenu: undefined,\n selectionRoot: undefined,\n };\n}\n\ndeclare global {\n interface GlobalEventHandlersEventMap {\n 'sp-menu-item-added-or-updated': MenuItemAddedOrUpdatedEvent;\n 'sp-menu-item-removed': MenuItemRemovedEvent;\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;AAYA;AAAA,EAEI;AAAA,OAGG;AACP;AAAA,EACI;AAAA,EACA;AAAA,OACG;AAEP,OAAO;AACP,SAAS,kBAAkB;AAC3B,SAAS,iBAAiB;AAC1B,OAAO;AACP,OAAO,mBAAmB;
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n html,\n PropertyValues,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport {\n property,\n query,\n} from '@spectrum-web-components/base/src/decorators.js';\n\nimport '@spectrum-web-components/icons-ui/icons/sp-icon-checkmark100.js';\nimport { LikeAnchor } from '@spectrum-web-components/shared/src/like-anchor.js';\nimport { Focusable } from '@spectrum-web-components/shared/src/focusable.js';\nimport '@spectrum-web-components/icons-ui/icons/sp-icon-chevron100.js';\nimport chevronStyles from '@spectrum-web-components/icon/src/spectrum-icon-chevron.css.js';\nimport { openOverlay } from '@spectrum-web-components/overlay/src/loader.js';\nimport { OverlayCloseEvent } from '@spectrum-web-components/overlay/src/overlay-events.js';\n\nimport menuItemStyles from './menu-item.css.js';\nimport checkmarkStyles from '@spectrum-web-components/icon/src/spectrum-icon-checkmark.css.js';\nimport type { Menu } from './Menu.dev.js'\nimport type { OverlayOpenCloseDetail } from '@spectrum-web-components/overlay';\nimport { reparentChildren } from '@spectrum-web-components/shared/src/reparent-children.js';\nimport { MutationController } from '@lit-labs/observers/mutation-controller.js';\n\n/**\n * Duration during which a pointing device can leave an `<sp-menu-item>` element\n * and return to it or to the submenu opened from it before closing that submenu.\n **/\nconst POINTERLEAVE_TIMEOUT = 100;\n\nexport class MenuItemRemovedEvent extends Event {\n constructor() {\n super('sp-menu-item-removed', {\n bubbles: true,\n composed: true,\n });\n }\n get item(): MenuItem {\n return this._item;\n }\n _item!: MenuItem;\n focused = false;\n reset(item: MenuItem): void {\n this._item = item;\n }\n}\n\nexport class MenuItemAddedOrUpdatedEvent extends Event {\n constructor() {\n super('sp-menu-item-added-or-updated', {\n bubbles: true,\n composed: true,\n });\n }\n set focusRoot(root: Menu | undefined) {\n this.item.menuData.focusRoot = this.item.menuData.focusRoot || root;\n }\n set selectionRoot(root: Menu) {\n this.item.menuData.selectionRoot =\n this.item.menuData.selectionRoot || root;\n }\n get item(): MenuItem {\n return this._item;\n }\n _item!: MenuItem;\n set currentAncestorWithSelects(ancestor: Menu | undefined) {\n this._currentAncestorWithSelects = ancestor;\n }\n get currentAncestorWithSelects(): Menu | undefined {\n return this._currentAncestorWithSelects;\n }\n _currentAncestorWithSelects?: Menu;\n reset(item: MenuItem): void {\n this._item = item;\n this._currentAncestorWithSelects = undefined;\n item.menuData = {\n focusRoot: undefined,\n selectionRoot: undefined,\n };\n }\n}\n\nexport type MenuItemChildren = { icon: Element[]; content: Node[] };\n\nconst addOrUpdateEvent = new MenuItemAddedOrUpdatedEvent();\nconst removeEvent = new MenuItemRemovedEvent();\n\n/**\n * @element sp-menu-item\n *\n * @slot - text content to display within the Menu Item\n * @slot icon - icon element to be placed at the start of the Menu Item\n * @slot value - content placed at the end of the Menu Item like values, keyboard shortcuts, etc.\n * @slot submenu - content placed in a submenu\n * @fires sp-menu-item-added - announces the item has been added so a parent menu can take ownerships\n * @fires sp-menu-item-removed - announces when removed from the DOM so the parent menu can remove ownership and update selected state\n */\nexport class MenuItem extends LikeAnchor(Focusable) {\n public static override get styles(): CSSResultArray {\n return [menuItemStyles, checkmarkStyles, chevronStyles];\n }\n\n static instanceCount = 0;\n\n private isInSubmenu = false;\n\n @property({ type: Boolean, reflect: true })\n public active = false;\n\n @property({ type: Boolean, reflect: true })\n public focused = false;\n\n @property({ type: Boolean, reflect: true })\n public selected = false;\n\n @property({ type: String })\n public get value(): string {\n return this._value || this.itemText;\n }\n\n public set value(value: string) {\n if (value === this._value) {\n return;\n }\n this._value = value || '';\n if (this._value) {\n this.setAttribute('value', this._value);\n } else {\n this.removeAttribute('value');\n }\n }\n\n private _value = '';\n\n /**\n * @private\n */\n public get itemText(): string {\n return this.itemChildren.content.reduce(\n (acc, node) => acc + (node.textContent || '').trim(),\n ''\n );\n }\n\n @property({ type: Boolean })\n public hasSubmenu = false;\n\n @property({\n type: Boolean,\n reflect: true,\n attribute: 'no-wrap',\n hasChanged() {\n return false;\n },\n })\n public noWrap = false;\n\n @query('.anchor')\n private anchorElement!: HTMLAnchorElement;\n\n public override get focusElement(): HTMLElement {\n return this;\n }\n\n public get itemChildren(): MenuItemChildren {\n if (this._itemChildren) {\n return this._itemChildren;\n }\n\n const iconSlot = this.shadowRoot?.querySelector(\n 'slot[name=\"icon\"]'\n ) as HTMLSlotElement;\n const icon = !iconSlot\n ? []\n : iconSlot.assignedElements().map((element) => {\n const newElement = element.cloneNode(true) as HTMLElement;\n newElement.removeAttribute('slot');\n newElement.classList.toggle('icon');\n return newElement;\n });\n const contentSlot = this.shadowRoot?.querySelector(\n 'slot:not([name])'\n ) as HTMLSlotElement;\n const content = !contentSlot\n ? []\n : contentSlot.assignedNodes().map((node) => node.cloneNode(true));\n this._itemChildren = { icon, content };\n\n return this._itemChildren;\n }\n\n private _itemChildren?: MenuItemChildren;\n\n constructor() {\n super();\n this.proxyFocus = this.proxyFocus.bind(this);\n\n this.addEventListener('click', this.handleClickCapture, {\n capture: true,\n });\n\n new MutationController(this, {\n config: {\n characterData: true,\n childList: true,\n subtree: true,\n },\n callback: () => {\n this.breakItemChildrenCache();\n },\n });\n }\n\n @property({ type: Boolean })\n public open = false;\n\n public override click(): void {\n if (this.disabled) {\n return;\n }\n\n if (this.shouldProxyClick()) {\n return;\n }\n\n super.click();\n }\n\n private handleClickCapture(event: Event): void | boolean {\n if (this.disabled) {\n event.preventDefault();\n event.stopImmediatePropagation();\n event.stopPropagation();\n return false;\n }\n }\n\n private proxyFocus(): void {\n this.focus();\n }\n\n private shouldProxyClick(): boolean {\n let handled = false;\n if (this.anchorElement) {\n this.anchorElement.click();\n handled = true;\n }\n return handled;\n }\n\n protected breakItemChildrenCache(): void {\n this._itemChildren = undefined;\n this.triggerUpdate();\n }\n\n protected override render(): TemplateResult {\n return html`\n <slot name=\"icon\"></slot>\n <div id=\"label\">\n <slot id=\"slot\"></slot>\n </div>\n <slot name=\"value\"></slot>\n ${this.selected\n ? html`\n <sp-icon-checkmark100\n id=\"selected\"\n class=\"spectrum-UIIcon-Checkmark100 icon checkmark\"\n ></sp-icon-checkmark100>\n `\n : html``}\n ${this.href && this.href.length > 0\n ? super.renderAnchor({\n id: 'button',\n ariaHidden: true,\n className: 'button anchor hidden',\n })\n : html``}\n <slot\n hidden\n name=\"submenu\"\n @slotchange=${this.manageSubmenu}\n ></slot>\n ${this.hasSubmenu\n ? html`\n <sp-icon-chevron100\n class=\"spectrum-UIIcon-ChevronRight100 chevron icon\"\n ></sp-icon-chevron100>\n `\n : html``}\n `;\n }\n\n protected manageSubmenu(event: Event & { target: HTMLSlotElement }): void {\n const assignedElements = event.target.assignedElements({\n flatten: true,\n });\n this.hasSubmenu = this.open || !!assignedElements.length;\n }\n\n private handleRemoveActive(event: Event): void {\n if (\n (event.type === 'pointerleave' && this.hasSubmenu) ||\n this.hasSubmenu ||\n this.open\n ) {\n return;\n }\n this.active = false;\n }\n\n private handlePointerdown(): void {\n this.active = true;\n }\n\n protected override firstUpdated(changes: PropertyValues): void {\n super.firstUpdated(changes);\n this.setAttribute('tabindex', '-1');\n this.addEventListener('pointerdown', this.handlePointerdown);\n if (!this.hasAttribute('id')) {\n this.id = `sp-menu-item-${MenuItem.instanceCount++}`;\n }\n this.addEventListener('pointerenter', this.closeOverlaysForRoot);\n }\n\n protected closeOverlaysForRoot(): void {\n if (this.open) return;\n const overalyCloseEvent = new OverlayCloseEvent({\n root: this.menuData.focusRoot,\n });\n this.dispatchEvent(overalyCloseEvent);\n }\n\n public closeOverlay?: () => Promise<void>;\n\n protected handleSubmenuClick(): void {\n this.openOverlay();\n }\n\n protected handlePointerenter(): void {\n if (this.leaveTimeout) {\n clearTimeout(this.leaveTimeout);\n delete this.leaveTimeout;\n return;\n }\n this.openOverlay();\n }\n\n protected leaveTimeout?: ReturnType<typeof setTimeout>;\n\n protected handlePointerleave(): void {\n if (this.hasSubmenu && this.open) {\n this.leaveTimeout = setTimeout(() => {\n delete this.leaveTimeout;\n if (this.closeOverlay) this.closeOverlay();\n }, POINTERLEAVE_TIMEOUT);\n }\n }\n\n /**\n * When there is a `change` event in the submenu for this item\n * then we \"click\" this item to cascade the selection up the\n * menu tree allowing all submenus between the initial selection\n * and the root of the tree to have their selection changes and\n * be closed.\n */\n protected handleSubmenuChange = (): void => {\n this.menuData.selectionRoot?.selectOrToggleItem(this);\n };\n\n protected handleSubmenuPointerenter = (): void => {\n if (this.leaveTimeout) {\n clearTimeout(this.leaveTimeout);\n delete this.leaveTimeout;\n }\n };\n\n public async openOverlay(): Promise<void> {\n if (!this.hasSubmenu || this.open || this.disabled) {\n return;\n }\n this.open = true;\n this.active = true;\n const submenu = (\n this.shadowRoot.querySelector(\n 'slot[name=\"submenu\"]'\n ) as HTMLSlotElement\n ).assignedElements()[0] as Menu;\n submenu.addEventListener(\n 'pointerenter',\n this.handleSubmenuPointerenter\n );\n submenu.addEventListener('change', this.handleSubmenuChange);\n const popover = document.createElement('sp-popover');\n const returnSubmenu = reparentChildren([submenu], popover, {\n position: 'beforeend',\n prepareCallback: (el) => {\n const slotName = el.slot;\n el.tabIndex = 0;\n el.removeAttribute('slot');\n el.isSubmenu = true;\n return (el) => {\n el.tabIndex = -1;\n el.slot = slotName;\n el.isSubmenu = false;\n };\n },\n });\n const closeOverlay = openOverlay(this, 'click', popover, {\n placement: this.isLTR ? 'right-start' : 'left-start',\n receivesFocus: 'auto',\n root: this.menuData.focusRoot,\n });\n const closeSubmenu = async (): Promise<void> => {\n delete this.closeOverlay;\n (await closeOverlay)();\n };\n this.closeOverlay = closeSubmenu;\n const cleanup = (event: CustomEvent<OverlayOpenCloseDetail>): void => {\n event.stopPropagation();\n delete this.closeOverlay;\n returnSubmenu();\n this.open = false;\n this.active = false;\n };\n this.addEventListener('sp-closed', cleanup as EventListener, {\n once: true,\n });\n popover.addEventListener('change', closeSubmenu);\n }\n\n updateAriaSelected(): void {\n const role = this.getAttribute('role');\n if (role === 'option') {\n this.setAttribute(\n 'aria-selected',\n this.selected ? 'true' : 'false'\n );\n } else if (role === 'menuitemcheckbox' || role === 'menuitemradio') {\n this.setAttribute('aria-checked', this.selected ? 'true' : 'false');\n }\n }\n\n public setRole(role: string): void {\n this.setAttribute('role', role);\n this.updateAriaSelected();\n }\n\n protected override updated(changes: PropertyValues<this>): void {\n super.updated(changes);\n if (changes.has('label')) {\n this.setAttribute('aria-label', this.label || '');\n }\n if (changes.has('active')) {\n if (this.active) {\n this.addEventListener('pointerup', this.handleRemoveActive);\n this.addEventListener('pointerleave', this.handleRemoveActive);\n this.addEventListener('pointercancel', this.handleRemoveActive);\n } else {\n this.removeEventListener('pointerup', this.handleRemoveActive);\n this.removeEventListener(\n 'pointerleave',\n this.handleRemoveActive\n );\n this.removeEventListener(\n 'pointercancel',\n this.handleRemoveActive\n );\n }\n }\n if (this.anchorElement) {\n this.anchorElement.addEventListener('focus', this.proxyFocus);\n this.anchorElement.tabIndex = -1;\n }\n if (changes.has('selected')) {\n this.updateAriaSelected();\n }\n if (changes.has('hasSubmenu')) {\n if (this.hasSubmenu) {\n this.addEventListener('click', this.handleSubmenuClick);\n this.addEventListener('pointerenter', this.handlePointerenter);\n this.addEventListener('pointerleave', this.handlePointerleave);\n } else if (!this.closeOverlay) {\n this.removeEventListener('click', this.handleSubmenuClick);\n this.removeEventListener(\n 'pointerenter',\n this.handlePointerenter\n );\n this.removeEventListener(\n 'pointerleave',\n this.handlePointerleave\n );\n }\n }\n }\n\n public override connectedCallback(): void {\n super.connectedCallback();\n this.isInSubmenu = !!this.closest('[slot=\"submenu\"]');\n if (this.isInSubmenu) {\n return;\n }\n addOrUpdateEvent.reset(this);\n this.dispatchEvent(addOrUpdateEvent);\n this._parentElement = this.parentElement as HTMLElement;\n }\n\n _parentElement!: HTMLElement;\n\n public override disconnectedCallback(): void {\n removeEvent.reset(this);\n if (!this.isInSubmenu) {\n this._parentElement?.dispatchEvent(removeEvent);\n }\n this.isInSubmenu = false;\n super.disconnectedCallback();\n }\n\n public async triggerUpdate(): Promise<void> {\n if (this.isInSubmenu) {\n return;\n }\n await new Promise((ready) => requestAnimationFrame(ready));\n addOrUpdateEvent.reset(this);\n this.dispatchEvent(addOrUpdateEvent);\n }\n\n public menuData: {\n focusRoot?: Menu;\n selectionRoot?: Menu;\n } = {\n focusRoot: undefined,\n selectionRoot: undefined,\n };\n}\n\ndeclare global {\n interface GlobalEventHandlersEventMap {\n 'sp-menu-item-added-or-updated': MenuItemAddedOrUpdatedEvent;\n 'sp-menu-item-removed': MenuItemRemovedEvent;\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;AAYA;AAAA,EAEI;AAAA,OAGG;AACP;AAAA,EACI;AAAA,EACA;AAAA,OACG;AAEP,OAAO;AACP,SAAS,kBAAkB;AAC3B,SAAS,iBAAiB;AAC1B,OAAO;AACP,OAAO,mBAAmB;AAC1B,SAAS,mBAAmB;AAC5B,SAAS,yBAAyB;AAElC,OAAO,oBAAoB;AAC3B,OAAO,qBAAqB;AAG5B,SAAS,wBAAwB;AACjC,SAAS,0BAA0B;AAMnC,MAAM,uBAAuB;AAEtB,aAAM,6BAA6B,MAAM;AAAA,EAC5C,cAAc;AACV,UAAM,wBAAwB;AAAA,MAC1B,SAAS;AAAA,MACT,UAAU;AAAA,IACd,CAAC;AAML,mBAAU;AAAA,EALV;AAAA,EACA,IAAI,OAAiB;AACjB,WAAO,KAAK;AAAA,EAChB;AAAA,EAGA,MAAM,MAAsB;AACxB,SAAK,QAAQ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X;AAAA,EACJ,CAAC;AAAA,GAzDQ,SA0DF;AAGC;AAAA,EADP,MAAM,SAAS;AAAA,GA5DP,SA6DD;AAwDD;AAAA,EADN,SAAS,EAAE,MAAM,QAAQ,CAAC;AAAA,GApHlB,SAqHF;",
|
|
6
|
+
"names": ["el"]
|
|
7
7
|
}
|
package/src/MenuItem.js
CHANGED
|
@@ -1,44 +1,25 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var f=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var o=(h,r,e,t)=>{for(var i=t>1?void 0:t?E(r,e):r,a=h.length-1,s;a>=0;a--)(s=h[a])&&(i=(t?s(r,e,i):s(i))||i);return t&&i&&f(r,e,i),i};import{html as u}from"@spectrum-web-components/base";import{property as l,query as y}from"@spectrum-web-components/base/src/decorators.js";import"@spectrum-web-components/icons-ui/icons/sp-icon-checkmark100.js";import{LikeAnchor as S}from"@spectrum-web-components/shared/src/like-anchor.js";import{Focusable as C}from"@spectrum-web-components/shared/src/focusable.js";import"@spectrum-web-components/icons-ui/icons/sp-icon-chevron100.js";import g from"@spectrum-web-components/icon/src/spectrum-icon-chevron.css.js";import{openOverlay as R}from"@spectrum-web-components/overlay/src/loader.js";import{OverlayCloseEvent as A}from"@spectrum-web-components/overlay/src/overlay-events.js";import k from"./menu-item.css.js";import L from"@spectrum-web-components/icon/src/spectrum-icon-checkmark.css.js";import{reparentChildren as T}from"@spectrum-web-components/shared/src/reparent-children.js";import{MutationController as M}from"@lit-labs/observers/mutation-controller.js";const O=100;export class MenuItemRemovedEvent extends Event{constructor(){super("sp-menu-item-removed",{bubbles:!0,composed:!0});this.focused=!1}get item(){return this._item}reset(e){this._item=e}}export class MenuItemAddedOrUpdatedEvent extends Event{constructor(){super("sp-menu-item-added-or-updated",{bubbles:!0,composed:!0})}set focusRoot(e){this.item.menuData.focusRoot=this.item.menuData.focusRoot||e}set selectionRoot(e){this.item.menuData.selectionRoot=this.item.menuData.selectionRoot||e}get item(){return this._item}set currentAncestorWithSelects(e){this._currentAncestorWithSelects=e}get currentAncestorWithSelects(){return this._currentAncestorWithSelects}reset(e){this._item=e,this._currentAncestorWithSelects=void 0,e.menuData={focusRoot:void 0,selectionRoot:void 0}}}const m=new MenuItemAddedOrUpdatedEvent,b=new MenuItemRemovedEvent,v=class extends S(C){constructor(){super();this.isInSubmenu=!1;this.active=!1;this.focused=!1;this.selected=!1;this._value="";this.hasSubmenu=!1;this.noWrap=!1;this.open=!1;this.handleSubmenuChange=()=>{var e;(e=this.menuData.selectionRoot)==null||e.selectOrToggleItem(this)};this.handleSubmenuPointerenter=()=>{this.leaveTimeout&&(clearTimeout(this.leaveTimeout),delete this.leaveTimeout)};this.menuData={focusRoot:void 0,selectionRoot:void 0};this.proxyFocus=this.proxyFocus.bind(this),this.addEventListener("click",this.handleClickCapture,{capture:!0}),new M(this,{config:{characterData:!0,childList:!0,subtree:!0},callback:()=>{this.breakItemChildrenCache()}})}static get styles(){return[k,L,g]}get value(){return this._value||this.itemText}set value(e){e!==this._value&&(this._value=e||"",this._value?this.setAttribute("value",this._value):this.removeAttribute("value"))}get itemText(){return this.itemChildren.content.reduce((e,t)=>e+(t.textContent||"").trim(),"")}get focusElement(){return this}get itemChildren(){var s,d;if(this._itemChildren)return this._itemChildren;const e=(s=this.shadowRoot)==null?void 0:s.querySelector('slot[name="icon"]'),t=e?e.assignedElements().map(n=>{const c=n.cloneNode(!0);return c.removeAttribute("slot"),c.classList.toggle("icon"),c}):[],i=(d=this.shadowRoot)==null?void 0:d.querySelector("slot:not([name])"),a=i?i.assignedNodes().map(n=>n.cloneNode(!0)):[];return this._itemChildren={icon:t,content:a},this._itemChildren}click(){this.disabled||this.shouldProxyClick()||super.click()}handleClickCapture(e){if(this.disabled)return e.preventDefault(),e.stopImmediatePropagation(),e.stopPropagation(),!1}proxyFocus(){this.focus()}shouldProxyClick(){let e=!1;return this.anchorElement&&(this.anchorElement.click(),e=!0),e}breakItemChildrenCache(){this._itemChildren=void 0,this.triggerUpdate()}render(){return u`
|
|
2
2
|
<slot name="icon"></slot>
|
|
3
3
|
<div id="label">
|
|
4
4
|
<slot id="slot"></slot>
|
|
5
5
|
</div>
|
|
6
6
|
<slot name="value"></slot>
|
|
7
|
-
${this.selected?
|
|
7
|
+
${this.selected?u`
|
|
8
8
|
<sp-icon-checkmark100
|
|
9
9
|
id="selected"
|
|
10
10
|
class="spectrum-UIIcon-Checkmark100 icon checkmark"
|
|
11
11
|
></sp-icon-checkmark100>
|
|
12
|
-
`:
|
|
13
|
-
${this.href&&this.href.length>0?super.renderAnchor({id:"button",ariaHidden:!0,className:"button anchor hidden"}):
|
|
14
|
-
<
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
.type=${"auto"}
|
|
21
|
-
@close=${e=>e.stopPropagation()}
|
|
22
|
-
>
|
|
23
|
-
<sp-popover
|
|
24
|
-
@change=${e=>{this.handleSubmenuChange(e),this.open=!1}}
|
|
25
|
-
@pointerenter=${this.handleSubmenuPointerenter}
|
|
26
|
-
@pointerleave=${this.handleSubmenuPointerleave}
|
|
27
|
-
@sp-menu-item-added-or-updated=${e=>e.stopPropagation()}
|
|
28
|
-
>
|
|
29
|
-
<slot
|
|
30
|
-
name="submenu"
|
|
31
|
-
@slotchange=${this.manageSubmenu}
|
|
32
|
-
@sp-menu-item-removed=${e=>{e.stopPropagation()}}
|
|
33
|
-
@sp-menu-item-added-or-updated=${{handleEvent:e=>{e.reset(e.item)},capture:!0}}
|
|
34
|
-
@focusin=${e=>e.stopPropagation()}
|
|
35
|
-
></slot>
|
|
36
|
-
</sp-popover>
|
|
37
|
-
</sp-overlay>
|
|
38
|
-
${this.hasSubmenu?a`
|
|
12
|
+
`:u``}
|
|
13
|
+
${this.href&&this.href.length>0?super.renderAnchor({id:"button",ariaHidden:!0,className:"button anchor hidden"}):u``}
|
|
14
|
+
<slot
|
|
15
|
+
hidden
|
|
16
|
+
name="submenu"
|
|
17
|
+
@slotchange=${this.manageSubmenu}
|
|
18
|
+
></slot>
|
|
19
|
+
${this.hasSubmenu?u`
|
|
39
20
|
<sp-icon-chevron100
|
|
40
21
|
class="spectrum-UIIcon-ChevronRight100 chevron icon"
|
|
41
22
|
></sp-icon-chevron100>
|
|
42
|
-
`:
|
|
43
|
-
`}manageSubmenu(e){const t=e.target.assignedElements({flatten:!0});this.hasSubmenu
|
|
23
|
+
`:u``}
|
|
24
|
+
`}manageSubmenu(e){const t=e.target.assignedElements({flatten:!0});this.hasSubmenu=this.open||!!t.length}handleRemoveActive(e){e.type==="pointerleave"&&this.hasSubmenu||this.hasSubmenu||this.open||(this.active=!1)}handlePointerdown(){this.active=!0}firstUpdated(e){super.firstUpdated(e),this.setAttribute("tabindex","-1"),this.addEventListener("pointerdown",this.handlePointerdown),this.hasAttribute("id")||(this.id=`sp-menu-item-${v.instanceCount++}`),this.addEventListener("pointerenter",this.closeOverlaysForRoot)}closeOverlaysForRoot(){if(this.open)return;const e=new A({root:this.menuData.focusRoot});this.dispatchEvent(e)}handleSubmenuClick(){this.openOverlay()}handlePointerenter(){if(this.leaveTimeout){clearTimeout(this.leaveTimeout),delete this.leaveTimeout;return}this.openOverlay()}handlePointerleave(){this.hasSubmenu&&this.open&&(this.leaveTimeout=setTimeout(()=>{delete this.leaveTimeout,this.closeOverlay&&this.closeOverlay()},O))}async openOverlay(){if(!this.hasSubmenu||this.open||this.disabled)return;this.open=!0,this.active=!0;const e=this.shadowRoot.querySelector('slot[name="submenu"]').assignedElements()[0];e.addEventListener("pointerenter",this.handleSubmenuPointerenter),e.addEventListener("change",this.handleSubmenuChange);const t=document.createElement("sp-popover"),i=T([e],t,{position:"beforeend",prepareCallback:n=>{const c=n.slot;return n.tabIndex=0,n.removeAttribute("slot"),n.isSubmenu=!0,p=>{p.tabIndex=-1,p.slot=c,p.isSubmenu=!1}}}),a=R(this,"click",t,{placement:this.isLTR?"right-start":"left-start",receivesFocus:"auto",root:this.menuData.focusRoot}),s=async()=>{delete this.closeOverlay,(await a)()};this.closeOverlay=s;const d=n=>{n.stopPropagation(),delete this.closeOverlay,i(),this.open=!1,this.active=!1};this.addEventListener("sp-closed",d,{once:!0}),t.addEventListener("change",s)}updateAriaSelected(){const e=this.getAttribute("role");e==="option"?this.setAttribute("aria-selected",this.selected?"true":"false"):(e==="menuitemcheckbox"||e==="menuitemradio")&&this.setAttribute("aria-checked",this.selected?"true":"false")}setRole(e){this.setAttribute("role",e),this.updateAriaSelected()}updated(e){super.updated(e),e.has("label")&&this.setAttribute("aria-label",this.label||""),e.has("active")&&(this.active?(this.addEventListener("pointerup",this.handleRemoveActive),this.addEventListener("pointerleave",this.handleRemoveActive),this.addEventListener("pointercancel",this.handleRemoveActive)):(this.removeEventListener("pointerup",this.handleRemoveActive),this.removeEventListener("pointerleave",this.handleRemoveActive),this.removeEventListener("pointercancel",this.handleRemoveActive))),this.anchorElement&&(this.anchorElement.addEventListener("focus",this.proxyFocus),this.anchorElement.tabIndex=-1),e.has("selected")&&this.updateAriaSelected(),e.has("hasSubmenu")&&(this.hasSubmenu?(this.addEventListener("click",this.handleSubmenuClick),this.addEventListener("pointerenter",this.handlePointerenter),this.addEventListener("pointerleave",this.handlePointerleave)):this.closeOverlay||(this.removeEventListener("click",this.handleSubmenuClick),this.removeEventListener("pointerenter",this.handlePointerenter),this.removeEventListener("pointerleave",this.handlePointerleave)))}connectedCallback(){super.connectedCallback(),this.isInSubmenu=!!this.closest('[slot="submenu"]'),!this.isInSubmenu&&(m.reset(this),this.dispatchEvent(m),this._parentElement=this.parentElement)}disconnectedCallback(){var e;b.reset(this),this.isInSubmenu||(e=this._parentElement)==null||e.dispatchEvent(b),this.isInSubmenu=!1,super.disconnectedCallback()}async triggerUpdate(){this.isInSubmenu||(await new Promise(e=>requestAnimationFrame(e)),m.reset(this),this.dispatchEvent(m))}};export let MenuItem=v;MenuItem.instanceCount=0,o([l({type:Boolean,reflect:!0})],MenuItem.prototype,"active",2),o([l({type:Boolean,reflect:!0})],MenuItem.prototype,"focused",2),o([l({type:Boolean,reflect:!0})],MenuItem.prototype,"selected",2),o([l({type:String})],MenuItem.prototype,"value",1),o([l({type:Boolean})],MenuItem.prototype,"hasSubmenu",2),o([l({type:Boolean,reflect:!0,attribute:"no-wrap",hasChanged(){return!1}})],MenuItem.prototype,"noWrap",2),o([y(".anchor")],MenuItem.prototype,"anchorElement",2),o([l({type:Boolean})],MenuItem.prototype,"open",2);
|
|
44
25
|
//# sourceMappingURL=MenuItem.js.map
|