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
25 lines (24 loc) • 1.07 kB
JavaScript
var l = Object.defineProperty;
var i = (c, e, t) => e in c ? l(c, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : c[e] = t;
var r = (c, e, t) => i(c, typeof e != "symbol" ? e + "" : e, t);
import { createContainer as a, createLineBreak as s } from "../../../utils/helpers.mjs";
class k {
constructor(e) {
r(this, "editor");
this.editor = e;
}
execute() {
const e = this.createBlock(), t = this.editor.getContainer(), o = window.getSelection();
let n;
o && o.rangeCount > 0 ? n = o.getRangeAt(0) : (n = document.createRange(), n.selectNodeContents(t), n.collapse(!1), o == null || o.removeAllRanges(), o == null || o.addRange(n)), n.deleteContents(), n.insertNode(e), n.collapse(!1);
}
createBlock() {
const e = a("editor-block");
e.setAttribute("contenteditable", "true");
const t = a("block-content");
return t.contentEditable = "true", t.setAttribute("contenteditable", "true"), t.textContent = this.editor.t("New Block"), e.appendChild(t), e.appendChild(s()), e;
}
}
export {
k as BlockCommand
};