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
46 lines (45 loc) • 1.94 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 p = Object.defineProperty;
var f = (n, e, t) => e in n ? p(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
var i = (n, e, t) => f(n, typeof e != "symbol" ? e + "" : e, t);
class u {
constructor(e, t, l = "horizontal") {
i(this, "cell");
i(this, "direction");
this.cell = t, this.direction = l;
}
execute() {
this.direction === "horizontal" ? this.splitRight() : this.splitDown();
}
splitRight() {
const e = this.cell.parentElement;
if (!e) return;
const t = parseInt(this.cell.dataset.colspan || "1", 10);
if (!(t <= 1)) {
this.cell.dataset.colspan = "1";
for (let l = 1; l < t; l++) {
const s = document.createElement("div");
s.className = this.cell.className, s.contentEditable = "true", s.textContent = "", e.insertBefore(s, this.cell.nextSibling);
}
}
}
splitDown() {
const e = this.cell.parentElement, t = e.parentElement;
if (!e || !t) return;
const l = Array.from(t.querySelectorAll(".table-row, .table-header-row")), s = l.indexOf(e), a = Array.from(e.querySelectorAll(".table-cell, .table-header-cell")).indexOf(this.cell), h = parseInt(this.cell.dataset.rowspan || "1", 10);
if (!(h <= 1)) {
this.cell.dataset.rowspan = "1";
for (let o = 1; o < h; o++) {
const c = l[s + o];
if (!c) continue;
const r = document.createElement("div");
r.className = this.cell.className, r.contentEditable = "true", r.textContent = "";
const d = c.querySelectorAll(".table-cell, .table-header-cell");
d.length > a ? c.insertBefore(r, d[a]) : c.appendChild(r);
}
}
}
}
export {
u as SplitCellCommand
};