diff --git a/views/transform/div-menu.js b/views/transform/div-menu.js new file mode 100644 index 0000000..57f341d --- /dev/null +++ b/views/transform/div-menu.js @@ -0,0 +1,278 @@ +const TS_MENU_COMPONENT = "ts-menu"; +const TS_TOGGLE_BUTTON = "ts-menu-toggle-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"; + +export class DivMenu extends HTMLElement { + constructor() { + super(); + this._menuItemsMap = new Map(); + this._targetElement = null; + this._originalChildDivs = []; + this._observer = null; + this._menuPlaceholderMessageElement = 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); + } + + connectedCallback() { + this._originalChildDivs = Array.from(this.children).filter((node) => node.nodeType === Node.ELEMENT_NODE && node.tagName === "DIV"); + this._originalChildDivs.forEach((div) => div.remove()); + + const componentHTML = ` + +