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
58 lines (57 loc) • 2.28 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 f = Object.defineProperty;
var m = (s, e, o) => e in s ? f(s, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : s[e] = o;
var h = (s, e, o) => m(s, typeof e != "symbol" ? e + "" : e, o);
import { TableCell as d } from "./TableCell.mjs";
import { createContainer as a } from "../../../utils/helpers.mjs";
class u {
constructor(e, o) {
h(this, "element");
h(this, "editor");
this.element = a("html-editor-table table-modern"), this.editor = o, this.initialize(e);
}
initialize({ hasHeader: e, rows: o, cols: c }) {
if (this.element.className = "html-editor-table table-modern", e) {
const r = a("table-header-row");
for (let t = 0; t < c; t++) {
const l = a("table-header-cell");
l.textContent = `Column ${t + 1}`, r.appendChild(l), new d(l, this.editor);
}
this.element.appendChild(r);
}
for (let r = 0; r < o; r++) {
const t = a("table-row");
for (let l = 0; l < c; l++) {
const i = a("table-cell");
i.textContent = `Cell ${r + 1} - ${l + 1}`, t.appendChild(i), new d(i, this.editor);
}
this.element.appendChild(t);
}
}
getElement() {
return this.element;
}
focusFirstCell() {
const e = this.element.querySelector(".table-header-cell, .table-cell");
e instanceof HTMLElement && new d(e, this.editor).focus();
}
adjustColumnWidths() {
const e = this.element.querySelectorAll(".table-header-row, .table-row");
if (e.length === 0) return;
const r = e[0].querySelectorAll(".table-header-cell, .table-cell").length;
for (let t = 0; t < r; t++) {
let l = 0;
for (const i of e) {
const n = i.querySelectorAll(".table-header-cell, .table-cell")[t];
n && n instanceof HTMLElement && n.offsetWidth > l && (l = n.offsetWidth);
}
for (const i of e) {
const n = i.querySelectorAll(".table-header-cell, .table-cell")[t];
n && n instanceof HTMLElement && (n.style.width = `${l}px`);
}
}
}
}
export {
u as Table
};