Skip to content

Commit b20cd5a

Browse files
committed
refactor: clean up code formatting and remove unused overflow indicator functions
1 parent 9aea761 commit b20cd5a

File tree

4 files changed

+206
-135
lines changed

4 files changed

+206
-135
lines changed

media/context-menu.js

Lines changed: 60 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,8 @@ function showContextMenuAt(x, y) {
322322
const hasOverflow =
323323
cellContent &&
324324
cellContent instanceof HTMLElement &&
325-
cellContent.scrollWidth > cellContent.clientWidth + 2;
325+
(cellContent.scrollWidth > cellContent.clientWidth + 2 ||
326+
cellContent.scrollHeight > cellContent.clientHeight + 2);
326327
const shouldShow =
327328
raw.truncated ||
328329
value.length > 80 ||
@@ -597,9 +598,6 @@ function toggleRowMultiline() {
597598
if (tableWrapper && typeof window.refreshVirtualTable === "function") {
598599
window.refreshVirtualTable(tableWrapper);
599600
}
600-
if (table && typeof window.scheduleCellOverflowIndicators === "function") {
601-
window.scheduleCellOverflowIndicators(table);
602-
}
603601
return;
604602
}
605603

@@ -627,9 +625,6 @@ function toggleRowMultiline() {
627625
if (tableWrapper && typeof window.refreshVirtualTable === "function") {
628626
window.refreshVirtualTable(tableWrapper);
629627
}
630-
if (table && typeof window.scheduleCellOverflowIndicators === "function") {
631-
window.scheduleCellOverflowIndicators(table);
632-
}
633628
}
634629

635630
function getExpandedRowHeight(row, minHeight) {
@@ -705,7 +700,8 @@ function copyColumnData() {
705700
);
706701

707702
const tableWrapper = table.closest(".enhanced-table-wrapper");
708-
/** @type {any} */ const vs = tableWrapper && tableWrapper.__virtualTableState;
703+
/** @type {any} */ const vs =
704+
tableWrapper && tableWrapper.__virtualTableState;
709705

710706
// Get column header
711707
const header = table.querySelector(`thead th:nth-child(${columnIndex + 1})`);
@@ -813,7 +809,8 @@ function copyTableDataAsJSON() {
813809
}
814810

815811
const tableWrapper = table.closest(".enhanced-table-wrapper");
816-
/** @type {any} */ const vs = tableWrapper && tableWrapper.__virtualTableState;
812+
/** @type {any} */ const vs =
813+
tableWrapper && tableWrapper.__virtualTableState;
817814

818815
// Get column headers
819816
const headers = table.querySelectorAll("thead th");
@@ -913,22 +910,30 @@ function getCellUnderlyingValue(cell) {
913910
10
914911
);
915912
const rowEl = cell.closest("tr");
916-
const localIndex = parseInt(rowEl?.getAttribute("data-local-index") || "", 10);
913+
const localIndex = parseInt(
914+
rowEl?.getAttribute("data-local-index") || "",
915+
10
916+
);
917917
if (!Number.isFinite(colIndex) || !Number.isFinite(localIndex)) {
918918
return null;
919919
}
920920

921-
/** @type {any} */ const vs = /** @type {any} */ (wrapper).__virtualTableState;
921+
/** @type {any} */ const vs = /** @type {any} */ (wrapper)
922+
.__virtualTableState;
922923
if (vs && vs.enabled === true && Array.isArray(vs.pageData)) {
923924
const row = vs.pageData[localIndex];
924925
if (Array.isArray(row) && colIndex >= 0 && colIndex < row.length) {
925926
return row[colIndex];
926927
}
927928
}
928929

929-
const tableId = wrapper.getAttribute("data-table-id") || wrapper.dataset.tableId || "";
930+
const tableId =
931+
wrapper.getAttribute("data-table-id") || wrapper.dataset.tableId || "";
930932
/** @type {any} */ const stash = /** @type {any} */ (window).__tableDataStash;
931-
const payload = tableId && stash && typeof stash.get === "function" ? stash.get(tableId) : null;
933+
const payload =
934+
tableId && stash && typeof stash.get === "function"
935+
? stash.get(tableId)
936+
: null;
932937
if (payload && Array.isArray(payload.pageData)) {
933938
const row = payload.pageData[localIndex];
934939
if (Array.isArray(row) && colIndex >= 0 && colIndex < row.length) {
@@ -948,7 +953,8 @@ function getCellRawValue(cell) {
948953
const cellContent = cell.querySelector(".cell-content");
949954
if (cellContent) {
950955
const original = cellContent.getAttribute("data-original-value") || "";
951-
const truncated = cellContent.getAttribute("data-original-truncated") === "true";
956+
const truncated =
957+
cellContent.getAttribute("data-original-truncated") === "true";
952958
const isNull =
953959
cellContent.querySelector("em") &&
954960
(cellContent.textContent || "").trim() === "NULL";
@@ -1023,7 +1029,11 @@ function getJsonInfoForCell(cell) {
10231029
if (parsed === null || typeof parsed !== "object") {
10241030
return null;
10251031
}
1026-
return { parsed, formatted: JSON.stringify(parsed, null, 2), truncated: raw.truncated };
1032+
return {
1033+
parsed,
1034+
formatted: JSON.stringify(parsed, null, 2),
1035+
truncated: raw.truncated,
1036+
};
10271037
} catch {
10281038
return null;
10291039
}
@@ -1323,7 +1333,9 @@ function createHexDump(bytes, maxBytes) {
13231333

13241334
function downloadBytes(bytes, filename, mime) {
13251335
try {
1326-
const blob = new Blob([bytes], { type: mime || "application/octet-stream" });
1336+
const blob = new Blob([bytes], {
1337+
type: mime || "application/octet-stream",
1338+
});
13271339
const url = URL.createObjectURL(blob);
13281340
const a = document.createElement("a");
13291341
a.href = url;
@@ -1344,7 +1356,11 @@ function requestDownloadBytes(bytes, filename, mime) {
13441356
const maxBytes = 20 * 1024 * 1024; // 20MB (keeps message passing reasonable)
13451357
if (bytes && bytes.length > maxBytes) {
13461358
if (typeof showError === "function") {
1347-
showError(`Blob too large to download from the viewer (${formatBytes(bytes.length)}).`);
1359+
showError(
1360+
`Blob too large to download from the viewer (${formatBytes(
1361+
bytes.length
1362+
)}).`
1363+
);
13481364
}
13491365
return;
13501366
}
@@ -1481,7 +1497,9 @@ function showBlobViewerDialog(opts) {
14811497
img.className = "blob-viewer-image";
14821498
img.alt = "Image blob preview";
14831499
try {
1484-
objectUrl = URL.createObjectURL(new Blob([opts.bytes], { type: opts.mime }));
1500+
objectUrl = URL.createObjectURL(
1501+
new Blob([opts.bytes], { type: opts.mime })
1502+
);
14851503
img.src = objectUrl;
14861504
} catch (_) {
14871505
// ignore
@@ -1567,7 +1585,10 @@ function showBlobViewerDialog(opts) {
15671585
}
15681586
return;
15691587
}
1570-
copyToClipboard(bytesToBase64(opts.bytes), `Base64 copied (${opts.sizeText})`);
1588+
copyToClipboard(
1589+
bytesToBase64(opts.bytes),
1590+
`Base64 copied (${opts.sizeText})`
1591+
);
15711592
});
15721593
copyHexBtn.addEventListener("click", () => {
15731594
const maxBytes = 1 * 1024 * 1024;
@@ -1615,7 +1636,14 @@ function formatJsonWithSyntaxHighlighting(jsonString) {
16151636
/("(?:\\u[a-fA-F0-9]{4}|\\[^u]|[^\\"])*"(?:\\s*:)?|\btrue\b|\bfalse\b|\bnull\b|-?\d+(?:\.\d+)?(?:[eE][+\-]?\d+)?|[{}\[\],:])/g;
16161637

16171638
return escaped.replace(tokenRegex, (match) => {
1618-
if (match === "{" || match === "}" || match === "[" || match === "]" || match === "," || match === ":") {
1639+
if (
1640+
match === "{" ||
1641+
match === "}" ||
1642+
match === "[" ||
1643+
match === "]" ||
1644+
match === "," ||
1645+
match === ":"
1646+
) {
16191647
return `<span class="json-punctuation">${match}</span>`;
16201648
}
16211649
if (match === "true" || match === "false") {
@@ -1922,7 +1950,8 @@ function getContextMenuActions(cell) {
19221950
const table = cell.closest(".data-table");
19231951
if (table) {
19241952
const tableWrapper = table.closest(".enhanced-table-wrapper");
1925-
/** @type {any} */ const vs = tableWrapper && tableWrapper.__virtualTableState;
1953+
/** @type {any} */ const vs =
1954+
tableWrapper && tableWrapper.__virtualTableState;
19261955
const rowCount =
19271956
vs && vs.enabled === true
19281957
? (vs.order || []).length
@@ -2619,10 +2648,13 @@ function highlightForeignKeyTarget(tableWrapper) {
26192648

26202649
const foreignKeyInfo = window.pendingForeignKeyHighlight;
26212650
const wrapper =
2622-
tableWrapper && tableWrapper.classList && tableWrapper.classList.contains("enhanced-table-wrapper")
2651+
tableWrapper &&
2652+
tableWrapper.classList &&
2653+
tableWrapper.classList.contains("enhanced-table-wrapper")
26232654
? tableWrapper
26242655
: tableWrapper && tableWrapper.querySelector
2625-
? tableWrapper.querySelector(".enhanced-table-wrapper") || tableWrapper.closest(".enhanced-table-wrapper")
2656+
? tableWrapper.querySelector(".enhanced-table-wrapper") ||
2657+
tableWrapper.closest(".enhanced-table-wrapper")
26262658
: null;
26272659

26282660
const table = (wrapper || tableWrapper).querySelector(".data-table");
@@ -2668,7 +2700,11 @@ function highlightForeignKeyTarget(tableWrapper) {
26682700

26692701
if (pos !== -1) {
26702702
const scrollContainer = wrapper.querySelector(".table-scroll-container");
2671-
if (scrollContainer && Array.isArray(vs.prefix) && vs.prefix[pos] !== undefined) {
2703+
if (
2704+
scrollContainer &&
2705+
Array.isArray(vs.prefix) &&
2706+
vs.prefix[pos] !== undefined
2707+
) {
26722708
scrollContainer.scrollTop = Math.max(0, Math.floor(vs.prefix[pos]));
26732709
if (typeof window.refreshVirtualTable === "function") {
26742710
window.refreshVirtualTable(wrapper);

0 commit comments

Comments
 (0)