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
87 lines (86 loc) • 3.61 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 S = (n, e, t) => e in n ? f(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
var C = (n, e, t) => S(n, typeof e != "symbol" ? e + "" : e, t);
import { PopupManager as g } from "../../../core/ui/PopupManager.mjs";
class x {
constructor(e, t) {
C(this, "editor");
C(this, "table");
this.editor = e, this.table = t;
}
execute() {
this.showSortDialog();
}
showSortDialog() {
if (!this.editor) return;
const e = new g(this.editor, {
title: this.editor.t("Sort Table"),
className: "sort-dialog-popup",
closeOnClickOutside: !0,
buttons: [
{
label: this.editor.t("Cancel"),
variant: "secondary",
onClick: () => e.hide()
}
],
items: [
{
type: "custom",
id: "sort-options",
content: () => {
var s, a, d;
const t = document.createElement("div");
t.className = "p-4 space-y-4";
const l = this.table.querySelector(
".table-header-row, .table-row"
);
if (l) {
const u = l.querySelectorAll(".table-cell, .table-header-cell").length, r = document.createElement("select");
r.className = "w-full p-2 border border-gray-300 rounded-md";
for (let i = 0; i < u; i++) {
const h = document.createElement("option");
h.value = i.toString();
const b = l.querySelectorAll(".table-header-cell")[i];
b && ((s = b.textContent) != null && s.trim()) ? h.textContent = b.textContent.trim() : h.textContent = `Column ${i + 1}`, r.appendChild(h);
}
t.appendChild(r);
const o = document.createElement("select");
o.className = "w-full p-2 border border-gray-300 rounded-md";
const c = document.createElement("option");
c.value = "asc", c.textContent = ((a = this.editor) == null ? void 0 : a.t("Ascending")) || "Ascending", o.appendChild(c);
const m = document.createElement("option");
m.value = "desc", m.textContent = ((d = this.editor) == null ? void 0 : d.t("Descending")) || "Descending", o.appendChild(m), t.appendChild(o);
const p = document.createElement("button");
p.className = "w-full bg-blue-500 text-white p-2 rounded-md hover:bg-blue-600", p.textContent = this.editor.t("Sort"), p.onclick = () => {
this.performSort(
parseInt(r.value),
o.value
), e.hide();
}, t.appendChild(p);
}
return t;
}
}
]
});
e.show();
}
performSort(e, t) {
const l = Array.from(this.table.querySelectorAll(".table-row")), s = this.table.querySelector(".table-header-row");
l.length !== 0 && (l.sort((a, d) => {
const u = a.querySelectorAll(".table-cell")[e], r = d.querySelectorAll(".table-cell")[e];
if (!u || !r) return 0;
const o = u.textContent || "", c = r.textContent || "";
return t === "asc" ? o.localeCompare(c) : c.localeCompare(o);
}), s && this.table.appendChild(s), l.forEach((a) => {
this.table.appendChild(a);
}));
}
undo() {
}
}
export {
x as SortTableCommand
};