| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499 | 
							- /*!
 
-  * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
 
-  * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
 
-  * v1.0.0-beta.82
 
-  */
 
- import { Component, h, Element, Event, Listen, Prop, Watch, Method, State } from "@stencil/core";
 
- import { CSS, SLOTS, ICONS } from "./resources";
 
- import { focusElement, getSlotted, toAriaBoolean } from "../../utils/dom";
 
- import { Fragment } from "@stencil/core/internal";
 
- import { getRoundRobinIndex } from "../../utils/array";
 
- import { guid } from "../../utils/guid";
 
- import { createObserver } from "../../utils/observers";
 
- import { connectConditionalSlotComponent, disconnectConditionalSlotComponent } from "../../utils/conditionalSlot";
 
- const SUPPORTED_BUTTON_NAV_KEYS = ["ArrowUp", "ArrowDown"];
 
- const SUPPORTED_MENU_NAV_KEYS = ["ArrowUp", "ArrowDown", "End", "Home"];
 
- /**
 
-  * @slot - A slot for adding `calcite-action`s.
 
-  * @slot trigger - A slot for adding a `calcite-action` to trigger opening the menu.
 
-  * @slot tooltip - A slot for adding an tooltip for the menu.
 
-  */
 
- export class ActionMenu {
 
-   constructor() {
 
-     // --------------------------------------------------------------------------
 
-     //
 
-     //  Properties
 
-     //
 
-     // --------------------------------------------------------------------------
 
-     /**
 
-      * Indicates whether widget is expanded.
 
-      */
 
-     this.expanded = false;
 
-     /**
 
-      * Opens the action menu.
 
-      */
 
-     this.open = false;
 
-     /** Describes the type of positioning to use for the overlaid content. If your element is in a fixed container, use the 'fixed' value. */
 
-     this.overlayPositioning = "absolute";
 
-     /**
 
-      * Determines where the component will be positioned relative to the referenceElement.
 
-      * @see [PopperPlacement](https://github.com/Esri/calcite-components/blob/master/src/utils/popper.ts#L25)
 
-      */
 
-     this.placement = "auto";
 
-     this.actionElements = [];
 
-     this.mutationObserver = createObserver("mutation", () => this.getActions());
 
-     this.guid = `calcite-action-menu-${guid()}`;
 
-     this.menuId = `${this.guid}-menu`;
 
-     this.menuButtonId = `${this.guid}-menu-button`;
 
-     this.activeMenuItemIndex = -1;
 
-     // --------------------------------------------------------------------------
 
-     //
 
-     //  Component Methods
 
-     //
 
-     // --------------------------------------------------------------------------
 
-     this.connectMenuButtonEl = () => {
 
-       const { el, menuButtonId, menuId, open, label } = this;
 
-       const menuButtonEl = getSlotted(el, SLOTS.trigger) || this.defaultMenuButtonEl;
 
-       if (this.menuButtonEl === menuButtonEl) {
 
-         return;
 
-       }
 
-       this.disconnectMenuButtonEl();
 
-       this.menuButtonEl = menuButtonEl;
 
-       this.setTooltipReferenceElement();
 
-       if (!menuButtonEl) {
 
-         return;
 
-       }
 
-       menuButtonEl.active = open;
 
-       menuButtonEl.setAttribute("aria-controls", menuId);
 
-       menuButtonEl.setAttribute("aria-expanded", toAriaBoolean(open));
 
-       menuButtonEl.setAttribute("aria-haspopup", "true");
 
-       if (!menuButtonEl.id) {
 
-         menuButtonEl.id = menuButtonId;
 
-       }
 
-       if (!menuButtonEl.label) {
 
-         menuButtonEl.label = label;
 
-       }
 
-       if (!menuButtonEl.text) {
 
-         menuButtonEl.text = label;
 
-       }
 
-       menuButtonEl.addEventListener("click", this.menuButtonClick);
 
-       menuButtonEl.addEventListener("keydown", this.menuButtonKeyDown);
 
-       menuButtonEl.addEventListener("keyup", this.menuButtonKeyUp);
 
-     };
 
-     this.disconnectMenuButtonEl = () => {
 
-       const { menuButtonEl } = this;
 
-       if (!menuButtonEl) {
 
-         return;
 
-       }
 
-       menuButtonEl.removeEventListener("click", this.menuButtonClick);
 
-       menuButtonEl.removeEventListener("keydown", this.menuButtonKeyDown);
 
-       menuButtonEl.removeEventListener("keyup", this.menuButtonKeyUp);
 
-     };
 
-     this.setDefaultMenuButtonEl = (el) => {
 
-       this.defaultMenuButtonEl = el;
 
-       this.connectMenuButtonEl();
 
-     };
 
-     // --------------------------------------------------------------------------
 
-     //
 
-     //  Private Methods
 
-     //
 
-     // --------------------------------------------------------------------------
 
-     this.handleCalciteActionClick = () => {
 
-       this.open = false;
 
-       this.setFocus();
 
-     };
 
-     this.menuButtonClick = () => {
 
-       this.toggleOpen();
 
-     };
 
-     this.updateTooltip = (event) => {
 
-       const tooltips = event.target
 
-         .assignedElements({
 
-         flatten: true
 
-       })
 
-         .filter((el) => el === null || el === void 0 ? void 0 : el.matches("calcite-tooltip"));
 
-       this.tooltipEl = tooltips[0];
 
-       this.setTooltipReferenceElement();
 
-     };
 
-     this.setTooltipReferenceElement = () => {
 
-       const { tooltipEl, expanded, menuButtonEl } = this;
 
-       if (tooltipEl) {
 
-         tooltipEl.referenceElement = !expanded ? menuButtonEl : null;
 
-       }
 
-     };
 
-     this.updateAction = (action, index) => {
 
-       const { guid, activeMenuItemIndex } = this;
 
-       const id = `${guid}-action-${index}`;
 
-       action.tabIndex = -1;
 
-       action.setAttribute("role", "menuitem");
 
-       if (!action.id) {
 
-         action.id = id;
 
-       }
 
-       action.active = index === activeMenuItemIndex;
 
-     };
 
-     this.updateActions = (actions) => {
 
-       actions === null || actions === void 0 ? void 0 : actions.forEach(this.updateAction);
 
-     };
 
-     this.getActions = () => {
 
-       const { el } = this;
 
-       const actionElements = getSlotted(el, { all: true, matches: "calcite-action" });
 
-       this.updateActions(actionElements);
 
-       this.actionElements = actionElements;
 
-       this.connectMenuButtonEl();
 
-     };
 
-     this.menuButtonKeyUp = (event) => {
 
-       const { key } = event;
 
-       const { actionElements } = this;
 
-       if (!this.isValidKey(key, SUPPORTED_BUTTON_NAV_KEYS)) {
 
-         return;
 
-       }
 
-       event.preventDefault();
 
-       if (!actionElements.length) {
 
-         return;
 
-       }
 
-       this.toggleOpen(true);
 
-       this.handleActionNavigation(key, actionElements);
 
-     };
 
-     this.menuButtonKeyDown = (event) => {
 
-       const { key } = event;
 
-       if (!this.isValidKey(key, SUPPORTED_BUTTON_NAV_KEYS)) {
 
-         return;
 
-       }
 
-       event.preventDefault();
 
-     };
 
-     this.menuActionsContainerKeyDown = (event) => {
 
-       const { key } = event;
 
-       const { actionElements, activeMenuItemIndex } = this;
 
-       if (key === "Tab") {
 
-         this.open = false;
 
-         return;
 
-       }
 
-       if (key === " " || key === "Enter") {
 
-         event.preventDefault();
 
-         const action = actionElements[activeMenuItemIndex];
 
-         action ? action.click() : this.toggleOpen(false);
 
-         return;
 
-       }
 
-       if (this.isValidKey(key, SUPPORTED_MENU_NAV_KEYS)) {
 
-         event.preventDefault();
 
-       }
 
-     };
 
-     this.menuActionsContainerKeyUp = (event) => {
 
-       const { key } = event;
 
-       const { actionElements } = this;
 
-       if (key === "Escape") {
 
-         this.toggleOpen(false);
 
-         return;
 
-       }
 
-       if (!this.isValidKey(key, SUPPORTED_MENU_NAV_KEYS)) {
 
-         return;
 
-       }
 
-       event.preventDefault();
 
-       if (!actionElements.length) {
 
-         return;
 
-       }
 
-       this.handleActionNavigation(key, actionElements);
 
-     };
 
-     this.handleActionNavigation = (key, actions) => {
 
-       const currentIndex = this.activeMenuItemIndex;
 
-       if (key === "Home") {
 
-         this.activeMenuItemIndex = 0;
 
-       }
 
-       if (key === "End") {
 
-         this.activeMenuItemIndex = actions.length - 1;
 
-       }
 
-       if (key === "ArrowUp") {
 
-         this.activeMenuItemIndex = getRoundRobinIndex(Math.max(currentIndex - 1, -1), actions.length);
 
-       }
 
-       if (key === "ArrowDown") {
 
-         this.activeMenuItemIndex = getRoundRobinIndex(currentIndex + 1, actions.length);
 
-       }
 
-     };
 
-     this.toggleOpenEnd = () => {
 
-       this.setFocus();
 
-       this.el.removeEventListener("calcitePopoverOpen", this.toggleOpenEnd);
 
-     };
 
-     this.toggleOpen = (value = !this.open) => {
 
-       this.el.addEventListener("calcitePopoverOpen", this.toggleOpenEnd);
 
-       this.open = value;
 
-     };
 
-   }
 
-   // --------------------------------------------------------------------------
 
-   //
 
-   //  Lifecycle
 
-   //
 
-   // --------------------------------------------------------------------------
 
-   connectedCallback() {
 
-     var _a;
 
-     (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.observe(this.el, { childList: true, subtree: true });
 
-     this.getActions();
 
-     connectConditionalSlotComponent(this);
 
-   }
 
-   disconnectedCallback() {
 
-     var _a;
 
-     (_a = this.mutationObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
 
-     this.disconnectMenuButtonEl();
 
-     disconnectConditionalSlotComponent(this);
 
-   }
 
-   expandedHandler() {
 
-     this.open = false;
 
-     this.setTooltipReferenceElement();
 
-   }
 
-   openHandler(open) {
 
-     this.activeMenuItemIndex = this.open ? 0 : -1;
 
-     if (this.menuButtonEl) {
 
-       this.menuButtonEl.active = open;
 
-     }
 
-     this.calciteActionMenuOpenChange.emit(open);
 
-   }
 
-   closeCalciteActionMenuOnClick(event) {
 
-     const composedPath = event.composedPath();
 
-     if (composedPath.includes(this.el)) {
 
-       return;
 
-     }
 
-     this.open = false;
 
-   }
 
-   activeMenuItemIndexHandler() {
 
-     this.updateActions(this.actionElements);
 
-   }
 
-   // --------------------------------------------------------------------------
 
-   //
 
-   //  Methods
 
-   //
 
-   // --------------------------------------------------------------------------
 
-   /** Sets focus on the component. */
 
-   async setFocus() {
 
-     focusElement(this.open ? this.menuEl : this.menuButtonEl);
 
-   }
 
-   renderMenuButton() {
 
-     const { label, scale } = this;
 
-     const menuButtonSlot = (h("slot", { name: SLOTS.trigger },
 
-       h("calcite-action", { class: CSS.defaultTrigger, icon: ICONS.menu, ref: this.setDefaultMenuButtonEl, scale: scale, text: label })));
 
-     return menuButtonSlot;
 
-   }
 
-   renderMenuItems() {
 
-     const { actionElements, activeMenuItemIndex, open, menuId, menuButtonEl, label, placement, overlayPositioning, flipPlacements } = this;
 
-     const activeAction = actionElements[activeMenuItemIndex];
 
-     const activeDescendantId = (activeAction === null || activeAction === void 0 ? void 0 : activeAction.id) || null;
 
-     return (h("calcite-popover", { disablePointer: true, flipPlacements: flipPlacements, label: label, offsetDistance: 0, open: open, overlayPositioning: overlayPositioning, placement: placement, referenceElement: menuButtonEl },
 
-       h("div", { "aria-activedescendant": activeDescendantId, "aria-labelledby": menuButtonEl === null || menuButtonEl === void 0 ? void 0 : menuButtonEl.id, class: CSS.menu, id: menuId, onClick: this.handleCalciteActionClick, onKeyDown: this.menuActionsContainerKeyDown, onKeyUp: this.menuActionsContainerKeyUp, ref: (el) => (this.menuEl = el), role: "menu", tabIndex: -1 },
 
-         h("slot", null))));
 
-   }
 
-   render() {
 
-     return (h(Fragment, null,
 
-       this.renderMenuButton(),
 
-       this.renderMenuItems(),
 
-       h("slot", { name: SLOTS.tooltip, onSlotchange: this.updateTooltip })));
 
-   }
 
-   isValidKey(key, supportedKeys) {
 
-     return !!supportedKeys.find((k) => k === key);
 
-   }
 
-   static get is() { return "calcite-action-menu"; }
 
-   static get encapsulation() { return "shadow"; }
 
-   static get originalStyleUrls() { return {
 
-     "$": ["action-menu.scss"]
 
-   }; }
 
-   static get styleUrls() { return {
 
-     "$": ["action-menu.css"]
 
-   }; }
 
-   static get properties() { return {
 
-     "expanded": {
 
-       "type": "boolean",
 
-       "mutable": false,
 
-       "complexType": {
 
-         "original": "boolean",
 
-         "resolved": "boolean",
 
-         "references": {}
 
-       },
 
-       "required": false,
 
-       "optional": false,
 
-       "docs": {
 
-         "tags": [],
 
-         "text": "Indicates whether widget is expanded."
 
-       },
 
-       "attribute": "expanded",
 
-       "reflect": true,
 
-       "defaultValue": "false"
 
-     },
 
-     "flipPlacements": {
 
-       "type": "unknown",
 
-       "mutable": false,
 
-       "complexType": {
 
-         "original": "ComputedPlacement[]",
 
-         "resolved": "ComputedPlacement[]",
 
-         "references": {
 
-           "ComputedPlacement": {
 
-             "location": "import",
 
-             "path": "../../utils/popper"
 
-           }
 
-         }
 
-       },
 
-       "required": false,
 
-       "optional": true,
 
-       "docs": {
 
-         "tags": [],
 
-         "text": "Defines the available placements that can be used when a flip occurs."
 
-       }
 
-     },
 
-     "label": {
 
-       "type": "string",
 
-       "mutable": false,
 
-       "complexType": {
 
-         "original": "string",
 
-         "resolved": "string",
 
-         "references": {}
 
-       },
 
-       "required": true,
 
-       "optional": false,
 
-       "docs": {
 
-         "tags": [],
 
-         "text": "Text string for the actions menu."
 
-       },
 
-       "attribute": "label",
 
-       "reflect": false
 
-     },
 
-     "open": {
 
-       "type": "boolean",
 
-       "mutable": true,
 
-       "complexType": {
 
-         "original": "boolean",
 
-         "resolved": "boolean",
 
-         "references": {}
 
-       },
 
-       "required": false,
 
-       "optional": false,
 
-       "docs": {
 
-         "tags": [],
 
-         "text": "Opens the action menu."
 
-       },
 
-       "attribute": "open",
 
-       "reflect": true,
 
-       "defaultValue": "false"
 
-     },
 
-     "overlayPositioning": {
 
-       "type": "string",
 
-       "mutable": false,
 
-       "complexType": {
 
-         "original": "OverlayPositioning",
 
-         "resolved": "\"absolute\" | \"fixed\"",
 
-         "references": {
 
-           "OverlayPositioning": {
 
-             "location": "import",
 
-             "path": "../../utils/popper"
 
-           }
 
-         }
 
-       },
 
-       "required": false,
 
-       "optional": false,
 
-       "docs": {
 
-         "tags": [],
 
-         "text": "Describes the type of positioning to use for the overlaid content. If your element is in a fixed container, use the 'fixed' value."
 
-       },
 
-       "attribute": "overlay-positioning",
 
-       "reflect": false,
 
-       "defaultValue": "\"absolute\""
 
-     },
 
-     "placement": {
 
-       "type": "string",
 
-       "mutable": false,
 
-       "complexType": {
 
-         "original": "PopperPlacement",
 
-         "resolved": "Placement | PlacementRtl | VariationRtl",
 
-         "references": {
 
-           "PopperPlacement": {
 
-             "location": "import",
 
-             "path": "../../utils/popper"
 
-           }
 
-         }
 
-       },
 
-       "required": false,
 
-       "optional": false,
 
-       "docs": {
 
-         "tags": [{
 
-             "name": "see",
 
-             "text": "[PopperPlacement](https://github.com/Esri/calcite-components/blob/master/src/utils/popper.ts#L25)"
 
-           }],
 
-         "text": "Determines where the component will be positioned relative to the referenceElement."
 
-       },
 
-       "attribute": "placement",
 
-       "reflect": true,
 
-       "defaultValue": "\"auto\""
 
-     },
 
-     "scale": {
 
-       "type": "string",
 
-       "mutable": false,
 
-       "complexType": {
 
-         "original": "Scale",
 
-         "resolved": "\"l\" | \"m\" | \"s\"",
 
-         "references": {
 
-           "Scale": {
 
-             "location": "import",
 
-             "path": "../interfaces"
 
-           }
 
-         }
 
-       },
 
-       "required": false,
 
-       "optional": false,
 
-       "docs": {
 
-         "tags": [],
 
-         "text": "Specifies the size of the menu trigger action."
 
-       },
 
-       "attribute": "scale",
 
-       "reflect": true
 
-     }
 
-   }; }
 
-   static get states() { return {
 
-     "activeMenuItemIndex": {}
 
-   }; }
 
-   static get events() { return [{
 
-       "method": "calciteActionMenuOpenChange",
 
-       "name": "calciteActionMenuOpenChange",
 
-       "bubbles": true,
 
-       "cancelable": true,
 
-       "composed": true,
 
-       "docs": {
 
-         "tags": [],
 
-         "text": "Emitted when the open property has changed."
 
-       },
 
-       "complexType": {
 
-         "original": "any",
 
-         "resolved": "any",
 
-         "references": {}
 
-       }
 
-     }]; }
 
-   static get methods() { return {
 
-     "setFocus": {
 
-       "complexType": {
 
-         "signature": "() => Promise<void>",
 
-         "parameters": [],
 
-         "references": {
 
-           "Promise": {
 
-             "location": "global"
 
-           }
 
-         },
 
-         "return": "Promise<void>"
 
-       },
 
-       "docs": {
 
-         "text": "Sets focus on the component.",
 
-         "tags": []
 
-       }
 
-     }
 
-   }; }
 
-   static get elementRef() { return "el"; }
 
-   static get watchers() { return [{
 
-       "propName": "expanded",
 
-       "methodName": "expandedHandler"
 
-     }, {
 
-       "propName": "open",
 
-       "methodName": "openHandler"
 
-     }, {
 
-       "propName": "activeMenuItemIndex",
 
-       "methodName": "activeMenuItemIndexHandler"
 
-     }]; }
 
-   static get listeners() { return [{
 
-       "name": "click",
 
-       "method": "closeCalciteActionMenuOnClick",
 
-       "target": "window",
 
-       "capture": false,
 
-       "passive": false
 
-     }]; }
 
- }
 
 
  |