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
47 lines (46 loc) • 1.87 kB
JavaScript
/*! on-codemerge v1.3.1 @author Pavel Kuzmin @license MIT @homepage https://s00d.github.io/on-codemerge/ @repository git+https://github.com/s00d/on-codemerge.git Copyright (c) 2026 Pavel Kuzmin - Built on 2026-07-02T13:39:17.947Z */
var o = Object.defineProperty;
var c = (e, t, i) => t in e ? o(e, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[t] = i;
var l = (e, t, i) => c(e, typeof t != "symbol" ? t + "" : t, i);
class s {
constructor(t) {
l(this, "name", "duplicateBlock");
l(this, "editor");
l(this, "originalBlock", null);
l(this, "duplicatedBlock", null);
this.editor = t;
}
setData(t) {
this.originalBlock = t.block;
}
execute() {
var i;
if (!this.originalBlock || !this.isValidBlock(this.originalBlock)) return;
this.duplicatedBlock = this.originalBlock.cloneNode(!0);
const t = this.duplicatedBlock.querySelector(".block-content");
t && (t.textContent = this.editor.t("Duplicated Block"), t.contentEditable = "true"), this.duplicatedBlock.classList.remove("active"), this.duplicatedBlock.setAttribute("contenteditable", "false"), (i = this.originalBlock.parentNode) == null || i.insertBefore(
this.duplicatedBlock,
this.originalBlock.nextSibling
), this.focusBlock(this.duplicatedBlock);
}
undo() {
this.duplicatedBlock && this.duplicatedBlock.remove();
}
redo() {
var t;
this.originalBlock && this.duplicatedBlock && ((t = this.originalBlock.parentNode) == null || t.insertBefore(
this.duplicatedBlock,
this.originalBlock.nextSibling
));
}
isValidBlock(t) {
return t.classList.contains("editor-block");
}
focusBlock(t) {
const i = t.querySelector(".block-content");
i && i.contentEditable === "true" && (i.contentEditable = "true", t.classList.add("active"));
}
}
export {
s as DuplicateBlockCommand
};