feat: enhance CSV rendering with header support and improved styling

This commit is contained in:
2026-01-26 19:41:33 -05:00
parent 7082fc4534
commit c940fc5207
+35 -11
View File
@@ -182,13 +182,25 @@
} }
const rows = results.data as string[][]; const rows = results.data as string[][];
const [header, ...body] = rows;
const escape = (v: string) =>
v.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
const tableHtml = ` const tableHtml = `
<table class="csv-table"> <table class="csv-table">
<tbody> <thead>
${rows.map((row) => `<tr>${row.map((cell) => `<td>${cell ? cell.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;') : ''}</td>`).join('')}</tr>`).join('')} <tr>
</tbody> ${header.map((c) => `<th>${c ? escape(c) : ''}</th>`).join('')}
</table> </tr>
`; </thead>
<tbody>
${body
.map((row) => `<tr>${row.map((c) => `<td>${c ? escape(c) : ''}</td>`).join('')}</tr>`)
.join('')}
</tbody>
</table>
`;
pasteContent = tableHtml; pasteContent = tableHtml;
contentRendered = true; contentRendered = true;
@@ -959,29 +971,41 @@
} }
.csv-table { .csv-table {
border-collapse: collapse; border-collapse: separate;
border-spacing: 0;
background-color: var(--color-neutral-800); background-color: var(--color-neutral-800);
border-bottom-left-radius: 0.25rem; border-bottom-left-radius: 0.25rem;
border-bottom-right-radius: 0.25rem; border-bottom-right-radius: 0.25rem;
min-width: 100%; min-width: 100%;
} }
.csv-table tr { .csv-table thead th {
position: sticky;
top: 0;
background-color: var(--color-neutral-800);
border-bottom: 2px solid var(--color-neutral-700);
z-index: 2;
}
.csv-table tbody tr,
.csv-table thead th {
border-bottom: 1px solid var(--color-neutral-700); border-bottom: 1px solid var(--color-neutral-700);
} }
.csv-table tr:hover { .csv-table tbody tr:hover,
.csv-table thead tr:hover {
background-color: rgba(255, 255, 255, 0.05); background-color: rgba(255, 255, 255, 0.05);
} }
.csv-table td { .csv-table tbody td,
.csv-table thead th {
padding: 0.75rem 1rem; padding: 0.75rem 1rem;
text-align: left; text-align: left;
color: var(--color-neutral-300); color: var(--color-neutral-300);
white-space: nowrap; white-space: nowrap;
} }
.csv-table tr:last-child { .csv-table tbody tr:last-child {
border-bottom: none; border-bottom: none;
} }