const USER_PROVIDED_MENU_BUTTON_CLASS = "div-menu-button"; const TS_POPUP = "ts-menu-popup"; const TS_LIST = "ts-menu-list"; const TS_PLACEHOLDER_MESSAGE = "ts-menu-placeholder-message"; const TS_LIST_ITEM = "ts-menu-list-item"; const TS_ITEM_ACTION = "ts-menu-item-action"; const TS_ITEM_IS_SELECTED = "ts-item-is-selected"; const TS_CONTENT_CLOSE_BUTTON = "ts-content-close-button"; const TAILWIND_HIDDEN_CLASS = "hidden"; const TS_MENU_BUTTON_STATE_DISABLED = "ts-menu-button--disabled"; // New constants for menu label states const TS_MENU_LABEL_IN_MENU_STATE = "ts-menu-label--in-menu"; const TS_MENU_LABEL_DISPLAYED_STATE = "ts-menu-label--displayed"; // // Prereq: child divs must have prop data-value, and a label element // the label element must have class "menu-label" // The child divs will be moved to the target element when selected // The target element must be specified by the attribute target-id on the custom element // The menu button must have the class div-menu-button export class DivMenu extends HTMLElement { constructor() { super(); this._menuItemsMap = new Map(); this._targetElement = null; this._originalChildDivs = []; this._observer = null; this._menuPlaceholderMessageElement = null; this._menuButton = null; this._toggleMenu = this._toggleMenu.bind(this); this._handleMenuItemClick = this._handleMenuItemClick.bind(this); this._handleClickOutside = this._handleClickOutside.bind(this); this._handleContentClose = this._handleContentClose.bind(this); this._handleMutations = this._handleMutations.bind(this); this._checkMenuPlaceholderAndButton = this._checkMenuPlaceholderAndButton.bind(this); this._clearFormElements = this._clearFormElements.bind(this); this._refreshTargetOrder = this._refreshTargetOrder.bind(this); // Bind new method } connectedCallback() { this._menuButton = this.querySelector(`.${USER_PROVIDED_MENU_BUTTON_CLASS}`); if (!this._menuButton) { console.error(`TabSelectorMenu: User-provided menu button with class '${USER_PROVIDED_MENU_BUTTON_CLASS}' not found.`); } this._originalChildDivs = Array.from(this.children).filter((node) => node.nodeType === Node.ELEMENT_NODE && node.tagName === "DIV" && !node.classList.contains(USER_PROVIDED_MENU_BUTTON_CLASS)); this._originalChildDivs.forEach((div) => div.remove()); const componentPopupHTML = `