UNPKG

web-mojo

Version:

WEB-MOJO - A lightweight JavaScript framework for building data-driven web applications

3 lines (2 loc) 1.81 kB
"use strict";const t=require("./WebApp-sKJf8j1s.js");class ContextMenu extends t.View{constructor(t={}){super({tagName:"div",className:"context-menu-view dropdown",...t}),this.config=t.contextMenu||t.config||{},this.context=t.context||{}}async renderTemplate(){const t=this.config.items||[];if(0===t.length)return"";const e=this.config.icon||"bi-three-dots-horizontal",n=this.config.buttonClass||"btn btn-link text-secondary ps-3 pe-0 pt-0 pb-1",i=`context-menu-${this.id}`;return`\n <button class="${n}" type="button" id="${i}" data-bs-toggle="dropdown" aria-expanded="false">\n <i class="${e}"></i>\n </button>\n <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="${i}">\n ${t.map(t=>this.buildMenuItemHTML(t)).join("")}\n </ul>\n `}buildMenuItemHTML(t){if("divider"===t.type||t.separator)return'<li><hr class="dropdown-divider"></li>';const e=t.icon?`<i class="${t.icon} me-2"></i>`:"",n=t.label||"",i=`dropdown-item ${t.danger?"text-danger":""} ${t.disabled?"disabled":""}`,o=t.action||"";return t.href?`<li><a class="${i}" href="${t.href}" target="${t.target||"_self"}">${e}${n}</a></li>`:`<li><a class="${i}" href="#" data-action="menu-item-click" data-item-action="${o}">${e}${n}</a></li>`}async onActionMenuItemClick(t,e){t.preventDefault();const n=e.getAttribute("data-item-action");if(!n)return;const i=this.config.items.find(t=>t.action===n);i&&!i.disabled&&("function"==typeof i.handler?i.handler(this.context,t,e):this.parent.events.dispatch(n,t,e),this.closeDropdown())}closeDropdown(){const t=this.element.querySelector('[data-bs-toggle="dropdown"]');if(t){const e=window.bootstrap?.Dropdown.getInstance(t);e?.hide()}}}exports.ContextMenu=ContextMenu; //# sourceMappingURL=ContextMenu-CvFe_-pA.js.map