UNPKG

on-codemerge

Version:

A WYSIWYG editor for on-codemerge is a user-friendly interface that allows users to edit and view their code in real time, exactly as it will appear in the final product

63 lines (62 loc) 2.08 kB
var c = Object.defineProperty; var u = (n, e, t) => e in n ? c(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t; var s = (n, e, t) => u(n, typeof e != "symbol" ? e + "" : e, t); class l { // Храним кнопки в Map constructor(e) { s(this, "element"); s(this, "buttonElements"); this.buttonElements = /* @__PURE__ */ new Map(), this.element = this.createFooter(e); } createFooter(e) { const t = document.createElement("div"); t.className = "popup-footer"; const o = document.createElement("div"); return o.className = "popup-footer-items", e.forEach((r) => { const a = this.createButton(r); o.appendChild(a), this.buttonElements.set(r.label, a); }), t.appendChild(o), t; } createButton(e) { const t = document.createElement("button"); return t.className = this.getButtonClasses(e.variant), t.textContent = e.label, t.addEventListener("click", e.onClick), t; } getButtonClasses(e = "secondary") { const t = "popup-footer-button"; switch (e) { case "primary": return `${t} popup-footer-button-primary`; case "secondary": return `${t} popup-footer-button-secondary`; case "success": return `${t} popup-footer-button-success`; case "danger": return `${t} popup-footer-button-danger`; case "warning": return `${t} popup-footer-button-warning`; case "info": return `${t} popup-footer-button-info`; default: return `${t} popup-footer-button-secondary`; } } updateButtonCallback(e, t) { const o = this.buttonElements.get(e); if (o) { o.replaceWith(o.cloneNode(!0)); const r = this.createButton({ label: e, onClick: t, variant: o.classList.contains("popup-footer-button-primary") ? "primary" : "secondary" }); o.replaceWith(r), this.buttonElements.set(e, r); } else console.warn(`Button with label "${e}" not found.`); } getElement() { return this.element; } } export { l as PopupFooter };