Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 | 19x 19x 19x 19x 19x 19x 19x 18x 17x 19x 19x 18x 18x 18x 52x 18x 19x 19x 3x 3x 7x 3x 19x 19x 54x 54x 157x 54x 19x 19x 6x 52x 23x 21x 21x 21x 19x 39x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 23x 18x 18x 19x 23x 23x 23x 23x 23x 23x 18x 18x 18x 18x 2x 18x 18x 18x 18x 2x 2x 16x 3x 18x 31x 31x 18x 1x 1x 17x 17x 18x 18x 18x 18x 18x 18x 4x 3x 3x 4x 4x 14x 1x 18x 52x 52x 52x 1x 25x 25x 2500x 2500x 2500x 2500x 17x 17x 17x 25x 24x 24x 24x 5x 5x 5x 500x 500x 5x 500x 4x 4x 4x 4x 500x 2x 2x 2x 2x 2x 5x 1x | /**
* Custom "Insert Table" button for TinyMCE.
* Opens a dialog to configure rows, columns, width, and optional header row.
* The inserted table uses colgroup for equal column widths, making each
* column draggable/resizable via the TinyMCE table plugin's resize bars.
*/
function buildTableHtml(rows, cols, width, hasHeader, align) {
const numRows = Math.max(1, parseInt(rows, 10) || 3);
const numCols = Math.max(1, parseInt(cols, 10) || 3);
const isFitContent = width === "fit-content";
const cellStyle = "border: 1px solid #d1d5db; padding: 8px 12px; min-width: 40px; height: 32px;";
const thStyle = `${cellStyle} background-color: #f3f4f6; font-weight: 600; text-align: left;`;
let alignStyle = "";
if (align === "center") alignStyle = " margin-left: auto; margin-right: auto;";
else if (align === "left") alignStyle = " float: left;";
else if (align === "right") alignStyle = " float: right;";
let html = `<table style="width: ${width}; border-collapse: collapse;${alignStyle}">`;
// Percentage col widths only make sense when the table has a fixed/relative width.
// For fit-content tables, omit the colgroup so the browser sizes columns naturally.
if (!isFitContent) {
const colWidth = `${(100 / numCols).toFixed(2)}%`;
html += "<colgroup>";
for (let c = 0; c < numCols; c++) {
html += `<col style="width: ${colWidth};" />`;
}
html += "</colgroup>";
}
const bodyRows = hasHeader ? Math.max(1, numRows - 1) : numRows;
if (hasHeader) {
html += "<thead><tr>";
for (let c = 0; c < numCols; c++) {
html += `<th style="${thStyle}"> </th>`;
}
html += "</tr></thead>";
}
html += "<tbody>";
for (let r = 0; r < bodyRows; r++) {
html += "<tr>";
for (let c = 0; c < numCols; c++) {
html += `<td style="${cellStyle}"> </td>`;
}
html += "</tr>";
}
html += "</tbody></table>";
return html;
}
const WIDTH_OPTIONS = [
{ value: "100%", text: "100% — Full width" },
{ value: "75%", text: "75%" },
{ value: "50%", text: "50%" },
{ value: "25%", text: "25%" },
{ value: "fit-content", text: "Auto — fit content" },
];
/* ── Override the built-in Table Properties dialog ── */
function setupTableProperties(editor) {
editor.on("BeforeExecCommand", (e) => {
if (e.command !== "mceTableProps") return;
e.preventDefault();
const tableEl = editor.dom.getParent(editor.selection.getNode(), "table");
if (!tableEl) return;
// ── General: read current values ──
const rawWidth = editor.dom.getStyle(tableEl, "width", true) || "fit-content";
const currentWidth = WIDTH_OPTIONS.some((o) => o.value === rawWidth) ? rawWidth : "fit-content";
const firstCell = tableEl.querySelector("td, th");
const rawPadding = firstCell ? editor.dom.getStyle(firstCell, "padding") : "";
const paddingMatch = rawPadding.match(/^(\d+(?:\.\d+)?)px/);
const currentCellpadding = paddingMatch ? paddingMatch[1] : "";
const CELL_ALIGN_VALUES = ["left", "center", "right", "justify"];
const rawCellAlign = firstCell ? editor.dom.getStyle(firstCell, "text-align") : "";
const currentCellAlign = CELL_ALIGN_VALUES.includes(rawCellAlign) ? rawCellAlign : "";
const rawSpacing = editor.dom.getStyle(tableEl, "border-spacing") || "";
const spacingMatch = rawSpacing.match(/^(\d+(?:\.\d+)?)px/);
const currentCellspacing = spacingMatch ? spacingMatch[1] : "";
const currentBorder = tableEl.getAttribute("border") || "";
const ml = editor.dom.getStyle(tableEl, "margin-left");
const mr = editor.dom.getStyle(tableEl, "margin-right");
const float = editor.dom.getStyle(tableEl, "float");
let currentAlign = "";
if (ml === "auto" && mr === "auto") currentAlign = "center";
else Iif (float === "left") currentAlign = "left";
else Iif (float === "right") currentAlign = "right";
// ── Advanced: read current values ──
const currentBorderStyle = editor.dom.getStyle(tableEl, "border-style", true) || "";
const currentBorderColor = editor.dom.getStyle(tableEl, "border-color", true) || "";
const currentBgColor = editor.dom.getStyle(tableEl, "background-color", true) || "";
// ── Caption: read current values ──
const captionEl = tableEl.querySelector("caption");
const currentCaption = captionEl ? captionEl.textContent : "";
const currentCaptionSide = captionEl ? editor.dom.getStyle(captionEl, "caption-side", true) || "top" : "top";
editor.windowManager.open({
title: "Table Properties",
body: {
type: "panel",
items: [
// ── General ──
{
type: "grid",
columns: 2,
items: [
{
type: "selectbox",
name: "width",
label: "Width",
items: WIDTH_OPTIONS,
},
{
type: "selectbox",
name: "align",
label: "Alignment",
items: [
{ value: "", text: "None" },
{ value: "left", text: "Left" },
{ value: "center", text: "Center" },
{ value: "right", text: "Right" },
],
},
],
},
{
type: "grid",
columns: 3,
items: [
{ type: "input", name: "cellpadding", label: "Cell padding", inputMode: "numeric" },
{ type: "input", name: "cellspacing", label: "Cell spacing", inputMode: "numeric" },
{ type: "input", name: "border", label: "Border width", inputMode: "numeric" },
],
},
{
type: "selectbox",
name: "cellalign",
label: "Cell content alignment",
items: [
{ value: "", text: "— Default" },
{ value: "left", text: "Left" },
{ value: "center", text: "Center" },
{ value: "right", text: "Right" },
{ value: "justify", text: "Justify" },
],
},
// ── Advanced ──
{
type: "selectbox",
name: "borderstyle",
label: "Border style",
items: [
{ value: "", text: "— Default" },
{ value: "solid", text: "Solid" },
{ value: "dashed", text: "Dashed" },
{ value: "dotted", text: "Dotted" },
{ value: "double", text: "Double" },
{ value: "groove", text: "Groove" },
{ value: "ridge", text: "Ridge" },
{ value: "inset", text: "Inset" },
{ value: "outset", text: "Outset" },
{ value: "none", text: "None" },
],
},
{
type: "grid",
columns: 2,
items: [
{ type: "colorinput", name: "bordercolor", label: "Border color" },
{ type: "colorinput", name: "bgcolor", label: "Background color" },
],
},
// ── Caption ──
{
type: "input",
name: "caption",
label: "Table title",
},
{
type: "selectbox",
name: "captionside",
label: "Title position",
items: [
{ value: "top", text: "Top" },
{ value: "bottom", text: "Bottom" },
],
},
],
},
initialData: {
width: currentWidth,
align: currentAlign,
cellpadding: currentCellpadding,
cellspacing: currentCellspacing,
border: currentBorder,
borderstyle: currentBorderStyle,
bordercolor: currentBorderColor,
bgcolor: currentBgColor,
cellalign: currentCellAlign,
caption: currentCaption,
captionside: currentCaptionSide,
},
buttons: [
{ type: "cancel", text: "Cancel" },
{ type: "submit", text: "Save", primary: true },
],
onSubmit: (api) => {
const {
width,
align,
cellpadding,
cellspacing,
border,
cellalign,
borderstyle,
bordercolor,
bgcolor,
caption,
captionside,
} = api.getData();
editor.undoManager.transact(() => {
// Width
editor.dom.setStyle(tableEl, "width", width);
if (width === "fit-content") {
tableEl.querySelectorAll("col").forEach((col) => col.removeAttribute("style"));
}
// Alignment
editor.dom.setStyle(tableEl, "float", "");
editor.dom.setStyle(tableEl, "margin-left", "");
editor.dom.setStyle(tableEl, "margin-right", "");
if (align === "center") {
editor.dom.setStyle(tableEl, "margin-left", "auto");
editor.dom.setStyle(tableEl, "margin-right", "auto");
} else if (align === "left" || align === "right") {
editor.dom.setStyle(tableEl, "float", align);
}
// Cell padding and content alignment — apply CSS to every td/th
tableEl.querySelectorAll("td, th").forEach((cell) => {
editor.dom.setStyle(cell, "padding", cellpadding ? `${cellpadding}px` : "");
editor.dom.setStyle(cell, "text-align", cellalign || "");
});
// Cell spacing — use border-spacing CSS
if (cellspacing) {
editor.dom.setStyle(tableEl, "border-collapse", "separate");
editor.dom.setStyle(tableEl, "border-spacing", `${cellspacing}px`);
} else {
editor.dom.setStyle(tableEl, "border-collapse", "collapse");
editor.dom.setStyle(tableEl, "border-spacing", "");
}
// Border width attribute
border ? tableEl.setAttribute("border", border) : tableEl.removeAttribute("border");
// Advanced styles
editor.dom.setStyle(tableEl, "border-style", borderstyle || "");
editor.dom.setStyle(tableEl, "border-color", bordercolor || "");
editor.dom.setStyle(tableEl, "background-color", bgcolor || "");
// Caption / table title
let capEl = tableEl.querySelector("caption");
if (caption.trim()) {
if (!capEl) {
capEl = editor.dom.create("caption");
tableEl.insertBefore(capEl, tableEl.firstChild);
}
capEl.textContent = caption.trim();
editor.dom.setStyle(capEl, "caption-side", captionside);
} else if (capEl) {
capEl.parentNode.removeChild(capEl);
}
});
api.close();
},
});
});
}
/**
* Registers the custom `inserttable` button on the given TinyMCE editor instance.
* Call this inside the editor's `setup(editor)` callback.
*
* @param {object} editor - TinyMCE editor instance.
*/
export function setupInsertTable(editor, { disabled = false } = {}) {
setupTableProperties(editor);
editor.ui.registry.addIcon(
"inserttable-icon",
`<svg width="24" height="24" viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<path d="M20 3H4a1 1 0 0 0-1 1v16a1 1 0 0 0 1 1h16a1 1 0 0 0 1-1V4a1 1 0 0 0-1-1z
M11 17H5v-3h6v3zm0-5H5v-3h6v3zm0-5H5V4h6v3zm8 10h-6v-3h6v3zm0-5h-6v-3h6v3zm0-5h-6V4h6v3z"/>
</svg>`
);
editor.ui.registry.addButton("inserttable", {
icon: "inserttable-icon",
tooltip: "Insert Table",
onSetup: disabled ? (api) => { api.setEnabled(false); return () => {}; } : undefined,
onAction: () => {
// Tracks the last hovered cell; used by the Insert button fallback
let selected = { rows: 3, cols: 3 };
const dialogApi = editor.windowManager.open({
title: "Insert Table",
body: {
type: "panel",
items: [
{
type: "grid",
columns: 2,
items: [
{
type: "selectbox",
name: "width",
label: "Table Width",
items: [
{ value: "100%", text: "100% — Full width" },
{ value: "75%", text: "75%" },
{ value: "50%", text: "50%" },
{ value: "25%", text: "25%" },
{ value: "fit-content", text: "Auto — fit content" },
],
},
{
type: "selectbox",
name: "align",
label: "Alignment",
items: [
{ value: "", text: "None" },
{ value: "left", text: "Left" },
{ value: "center", text: "Center" },
{ value: "right", text: "Right" },
],
},
],
},
{
type: "checkbox",
name: "header",
label: "Include header row",
},
{
type: "htmlpanel",
html: `
<div style="margin-bottom: 4px; font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: #6b7280; margin-top: 15px;">
Rows × Columns
</div>
<div
id="mfe-tgrid"
style="display: grid; grid-template-columns: repeat(10, 20px); gap: 2px; cursor: pointer; width: fit-content;"
>
${Array.from({ length: 100 }, (_, i) => {
const r = Math.floor(i / 10) + 1;
const c = (i % 10) + 1;
const active = r <= 3 && c <= 3 ? " mfe-tcell-on" : "";
return `<div class="mfe-tcell${active}" data-r="${r}" data-c="${c}" style="width:20px;height:20px;border:1.5px solid #d1d5db;border-radius:2px;box-sizing:border-box;background:${r <= 3 && c <= 3 ? "#dbeafe" : "#f9fafb"};"></div>`;
}).join("")}
</div>
<div id="mfe-tlabel" style="margin-top: 6px; font-size: 12px; font-weight: 600; color: #374151;">3 × 3</div>
<style>
.mfe-tcell { transition: background .07s, border-color .07s; }
.mfe-tcell.mfe-tcell-on { background: #dbeafe !important; border-color: #3b82f6 !important; }
</style>
`,
},
],
},
initialData: {
width: "fit-content",
align: "center",
header: true,
},
buttons: [
{ type: "cancel", text: "Cancel" },
{ type: "submit", text: "Insert", primary: true },
],
onSubmit: (api) => {
const { width, align, header } = api.getData();
editor.insertContent(buildTableHtml(selected.rows, selected.cols, width, !!header, align));
api.close();
},
});
// Wire up hover and click events on the grid after TinyMCE renders the dialog
setTimeout(() => {
const grid = document.getElementById("mfe-tgrid");
const label = document.getElementById("mfe-tlabel");
if (!grid || !label) return;
const highlight = (r, c) => {
label.innerHTML = `${r} × ${c}`;
grid.querySelectorAll(".mfe-tcell").forEach((tc) => {
const on = parseInt(tc.dataset.r, 10) <= r && parseInt(tc.dataset.c, 10) <= c;
tc.classList.toggle("mfe-tcell-on", on);
});
};
grid.querySelectorAll(".mfe-tcell").forEach((cell) => {
cell.addEventListener("mouseenter", () => {
const r = parseInt(cell.dataset.r, 10);
const c = parseInt(cell.dataset.c, 10);
selected = { rows: r, cols: c };
highlight(r, c);
});
cell.addEventListener("click", () => {
const r = parseInt(cell.dataset.r, 10);
const c = parseInt(cell.dataset.c, 10);
const { width, align, header } = dialogApi.getData();
editor.insertContent(buildTableHtml(r, c, width, !!header, align));
dialogApi.close();
});
});
// Reset highlight when the mouse leaves the grid
grid.addEventListener("mouseleave", () => {
highlight(selected.rows, selected.cols);
});
}, 120);
},
});
}
|