@spectrum-web-components/menu 0.16.16-overlay.9 → 0.16.16
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 +2191 -0
- package/package.json +9 -9
- package/src/Menu.d.ts +2 -9
- package/src/Menu.dev.js +39 -117
- 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 +3 -12
- package/src/MenuItem.dev.js +85 -87
- 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 +3 -3
- package/src/menu.css.js.map +1 -1
- package/stories/submenu.stories.js +125 -25
- 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.test.js +0 -7
- package/test/menu.test.js.map +2 -2
- package/test/submenu.test.js +50 -57
- 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,7 +50,6 @@ 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;
|
|
@@ -79,6 +80,7 @@ const removeEvent = new MenuItemRemovedEvent();
|
|
|
79
80
|
const _MenuItem = class extends LikeAnchor(Focusable) {
|
|
80
81
|
constructor() {
|
|
81
82
|
super();
|
|
83
|
+
this.isInSubmenu = false;
|
|
82
84
|
this.active = false;
|
|
83
85
|
this.focused = false;
|
|
84
86
|
this.selected = false;
|
|
@@ -86,9 +88,22 @@ const _MenuItem = class extends LikeAnchor(Focusable) {
|
|
|
86
88
|
this.hasSubmenu = false;
|
|
87
89
|
this.noWrap = false;
|
|
88
90
|
this.open = false;
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
+
}
|
|
92
107
|
};
|
|
93
108
|
this.menuData = {
|
|
94
109
|
focusRoot: void 0,
|
|
@@ -209,46 +224,11 @@ const _MenuItem = class extends LikeAnchor(Focusable) {
|
|
|
209
224
|
ariaHidden: true,
|
|
210
225
|
className: "button anchor hidden"
|
|
211
226
|
}) : html``}
|
|
212
|
-
<
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
.type=${"auto"}
|
|
218
|
-
@sp-opened=${(event) => {
|
|
219
|
-
this.focused = false;
|
|
220
|
-
const parentOverlay = event.composedPath().find((el) => {
|
|
221
|
-
return el !== this.overlayElement && el.localName === "sp-overlay";
|
|
222
|
-
});
|
|
223
|
-
this.overlayElement.parentOverlayToForceClose = parentOverlay;
|
|
224
|
-
}}
|
|
225
|
-
@close=${(event) => event.stopPropagation()}
|
|
226
|
-
>
|
|
227
|
-
<sp-popover
|
|
228
|
-
@change=${(event) => {
|
|
229
|
-
this.handleSubmenuChange(event);
|
|
230
|
-
this.open = false;
|
|
231
|
-
}}
|
|
232
|
-
@pointerenter=${this.handleSubmenuPointerenter}
|
|
233
|
-
@pointerleave=${this.handleSubmenuPointerleave}
|
|
234
|
-
@sp-menu-item-added-or-updated=${(event) => event.stopPropagation()}
|
|
235
|
-
>
|
|
236
|
-
<slot
|
|
237
|
-
name="submenu"
|
|
238
|
-
@slotchange=${this.manageSubmenu}
|
|
239
|
-
@sp-menu-item-removed=${(event) => {
|
|
240
|
-
event.stopPropagation();
|
|
241
|
-
}}
|
|
242
|
-
@sp-menu-item-added-or-updated=${{
|
|
243
|
-
handleEvent: (event) => {
|
|
244
|
-
event.reset(event.item);
|
|
245
|
-
},
|
|
246
|
-
capture: true
|
|
247
|
-
}}
|
|
248
|
-
@focusin=${(event) => event.stopPropagation()}
|
|
249
|
-
></slot>
|
|
250
|
-
</sp-popover>
|
|
251
|
-
</sp-overlay>
|
|
227
|
+
<slot
|
|
228
|
+
hidden
|
|
229
|
+
name="submenu"
|
|
230
|
+
@slotchange=${this.manageSubmenu}
|
|
231
|
+
></slot>
|
|
252
232
|
${this.hasSubmenu ? html`
|
|
253
233
|
<sp-icon-chevron100
|
|
254
234
|
class="spectrum-UIIcon-ChevronRight100 chevron icon"
|
|
@@ -260,10 +240,10 @@ const _MenuItem = class extends LikeAnchor(Focusable) {
|
|
|
260
240
|
const assignedElements = event.target.assignedElements({
|
|
261
241
|
flatten: true
|
|
262
242
|
});
|
|
263
|
-
this.hasSubmenu = !!assignedElements.length;
|
|
243
|
+
this.hasSubmenu = this.open || !!assignedElements.length;
|
|
264
244
|
}
|
|
265
|
-
handleRemoveActive() {
|
|
266
|
-
if (this.open) {
|
|
245
|
+
handleRemoveActive(event) {
|
|
246
|
+
if (event.type === "pointerleave" && this.hasSubmenu || this.hasSubmenu || this.open) {
|
|
267
247
|
return;
|
|
268
248
|
}
|
|
269
249
|
this.active = false;
|
|
@@ -281,10 +261,12 @@ const _MenuItem = class extends LikeAnchor(Focusable) {
|
|
|
281
261
|
this.addEventListener("pointerenter", this.closeOverlaysForRoot);
|
|
282
262
|
}
|
|
283
263
|
closeOverlaysForRoot() {
|
|
284
|
-
var _a;
|
|
285
264
|
if (this.open)
|
|
286
265
|
return;
|
|
287
|
-
|
|
266
|
+
const overalyCloseEvent = new OverlayCloseEvent({
|
|
267
|
+
root: this.menuData.focusRoot
|
|
268
|
+
});
|
|
269
|
+
this.dispatchEvent(overalyCloseEvent);
|
|
288
270
|
}
|
|
289
271
|
handleSubmenuClick() {
|
|
290
272
|
this.openOverlay();
|
|
@@ -298,47 +280,64 @@ const _MenuItem = class extends LikeAnchor(Focusable) {
|
|
|
298
280
|
this.openOverlay();
|
|
299
281
|
}
|
|
300
282
|
handlePointerleave() {
|
|
301
|
-
if (this.
|
|
283
|
+
if (this.hasSubmenu && this.open) {
|
|
302
284
|
this.leaveTimeout = setTimeout(() => {
|
|
303
285
|
delete this.leaveTimeout;
|
|
304
|
-
this.
|
|
286
|
+
if (this.closeOverlay)
|
|
287
|
+
this.closeOverlay();
|
|
305
288
|
}, POINTERLEAVE_TIMEOUT);
|
|
306
289
|
}
|
|
307
290
|
}
|
|
308
|
-
/**
|
|
309
|
-
* When there is a `change` event in the submenu for this item
|
|
310
|
-
* then we "click" this item to cascade the selection up the
|
|
311
|
-
* menu tree allowing all submenus between the initial selection
|
|
312
|
-
* and the root of the tree to have their selection changes and
|
|
313
|
-
* be closed.
|
|
314
|
-
*/
|
|
315
|
-
handleSubmenuChange(event) {
|
|
316
|
-
var _a;
|
|
317
|
-
event.stopPropagation();
|
|
318
|
-
(_a = this.menuData.selectionRoot) == null ? void 0 : _a.selectOrToggleItem(this);
|
|
319
|
-
}
|
|
320
|
-
handleSubmenuPointerenter() {
|
|
321
|
-
this.recentlyLeftChild = true;
|
|
322
|
-
}
|
|
323
|
-
async handleSubmenuPointerleave() {
|
|
324
|
-
requestAnimationFrame(() => {
|
|
325
|
-
this.recentlyLeftChild = false;
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
291
|
async openOverlay() {
|
|
329
292
|
if (!this.hasSubmenu || this.open || this.disabled) {
|
|
330
293
|
return;
|
|
331
294
|
}
|
|
332
295
|
this.open = true;
|
|
333
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;
|
|
334
330
|
const cleanup = (event) => {
|
|
335
331
|
event.stopPropagation();
|
|
332
|
+
delete this.closeOverlay;
|
|
333
|
+
returnSubmenu();
|
|
336
334
|
this.open = false;
|
|
337
335
|
this.active = false;
|
|
338
336
|
};
|
|
339
337
|
this.addEventListener("sp-closed", cleanup, {
|
|
340
338
|
once: true
|
|
341
339
|
});
|
|
340
|
+
popover.addEventListener("change", closeSubmenu);
|
|
342
341
|
}
|
|
343
342
|
updateAriaSelected() {
|
|
344
343
|
const role = this.getAttribute("role");
|
|
@@ -356,14 +355,12 @@ const _MenuItem = class extends LikeAnchor(Focusable) {
|
|
|
356
355
|
this.updateAriaSelected();
|
|
357
356
|
}
|
|
358
357
|
updated(changes) {
|
|
359
|
-
var _a;
|
|
360
358
|
super.updated(changes);
|
|
361
359
|
if (changes.has("label")) {
|
|
362
360
|
this.setAttribute("aria-label", this.label || "");
|
|
363
361
|
}
|
|
364
362
|
if (changes.has("active")) {
|
|
365
363
|
if (this.active) {
|
|
366
|
-
(_a = this.menuData.selectionRoot) == null ? void 0 : _a.closeDescendentOverlays();
|
|
367
364
|
this.addEventListener("pointerup", this.handleRemoveActive);
|
|
368
365
|
this.addEventListener("pointerleave", this.handleRemoveActive);
|
|
369
366
|
this.addEventListener("pointercancel", this.handleRemoveActive);
|
|
@@ -406,26 +403,30 @@ const _MenuItem = class extends LikeAnchor(Focusable) {
|
|
|
406
403
|
}
|
|
407
404
|
connectedCallback() {
|
|
408
405
|
super.connectedCallback();
|
|
409
|
-
this.
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
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;
|
|
413
413
|
}
|
|
414
414
|
disconnectedCallback() {
|
|
415
415
|
var _a;
|
|
416
416
|
removeEvent.reset(this);
|
|
417
|
-
(
|
|
417
|
+
if (!this.isInSubmenu) {
|
|
418
|
+
(_a = this._parentElement) == null ? void 0 : _a.dispatchEvent(removeEvent);
|
|
419
|
+
}
|
|
420
|
+
this.isInSubmenu = false;
|
|
418
421
|
super.disconnectedCallback();
|
|
419
422
|
}
|
|
420
423
|
async triggerUpdate() {
|
|
424
|
+
if (this.isInSubmenu) {
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
421
427
|
await new Promise((ready) => requestAnimationFrame(ready));
|
|
422
428
|
addOrUpdateEvent.reset(this);
|
|
423
429
|
this.dispatchEvent(addOrUpdateEvent);
|
|
424
|
-
this._parentElement = this.assignedSlot || this.parentElement;
|
|
425
|
-
if (!!this.menuData.focusRoot) {
|
|
426
|
-
this.resolveMenuDataUpdated();
|
|
427
|
-
}
|
|
428
|
-
return this.menuDataUpdated;
|
|
429
430
|
}
|
|
430
431
|
};
|
|
431
432
|
export let MenuItem = _MenuItem;
|
|
@@ -458,9 +459,6 @@ __decorateClass([
|
|
|
458
459
|
__decorateClass([
|
|
459
460
|
query(".anchor")
|
|
460
461
|
], MenuItem.prototype, "anchorElement", 2);
|
|
461
|
-
__decorateClass([
|
|
462
|
-
query("sp-overlay")
|
|
463
|
-
], MenuItem.prototype, "overlayElement", 2);
|
|
464
462
|
__decorateClass([
|
|
465
463
|
property({ type: Boolean })
|
|
466
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 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 private 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 ?open=${this.hasSubmenu && this.open}\n .placement=${this.isLTR ? 'right-start' : 'left-start'}\n .offset=${[-10, -5] as [number, number]}\n .type=${'auto'}\n @sp-opened=${(event: Event) => {\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 =\n parentOverlay;\n }}\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.selectionRoot?.closeDescendentOverlays();\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 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 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 } 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.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 public async triggerUpdate(): Promise<void> {\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 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 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;
|
|
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 * @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;AAAA,EACjB;AACJ;AAEO,aAAM,oCAAoC,MAAM;AAAA,EACnD,cAAc;AACV,UAAM,iCAAiC;AAAA,MACnC,SAAS;AAAA,MACT,UAAU;AAAA,IACd,CAAC;AAAA,EACL;AAAA,EACA,IAAI,UAAU,MAAwB;AAClC,S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"]
|
|
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
|
-
@sp-opened=${e=>{this.focused=!1;const t=e.composedPath().find(i=>i!==this.overlayElement&&i.localName==="sp-overlay");this.overlayElement.parentOverlayToForceClose=t}}
|
|
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
|