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

61 lines (60 loc) 1.82 kB
var p = Object.defineProperty; var s = (l, t, e) => t in l ? p(l, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : l[t] = e; var a = (l, t, e) => s(l, typeof t != "symbol" ? t + "" : t, e); import { PopupManager as i } from "../../../core/ui/PopupManager.mjs"; import { SUPPORTED_LANGUAGES as c } from "../constants.mjs"; class d { constructor(t) { a(this, "popup"); a(this, "callback", null); a(this, "languageSelect", ""); a(this, "codeInput", "plaintext"); this.popup = new i(t, { title: t.t("Insert Code Block"), className: "code-block-modal", closeOnClickOutside: !0, items: [ { type: "list", label: t.t("Language"), id: "language", options: c, value: this.codeInput, onChange: (e) => this.languageSelect = e.toString() }, { type: "textarea", label: "Code", id: "code", placeholder: t.t("Enter your code here..."), onChange: (e) => this.codeInput = e.toString() } ], buttons: [ { label: "Cancel", variant: "secondary", onClick: () => this.popup.hide() }, { label: "Save", variant: "primary", onClick: () => this.handleSubmit() } ] }); } handleSubmit() { const t = this.languageSelect, e = this.codeInput.trim(); e && this.callback && (this.callback(e, t), this.popup.hide()); } show(t, e = "", o = "plaintext") { this.callback = t, this.popup.setValue("language", o), this.popup.setValue("code", e), this.popup.show(), this.popup.setFocus("code"); } destroy() { this.popup.destroy(), this.callback = null, this.popup = null; } } export { d as CodeBlockModal };