1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2024-12-01 13:20:54 +00:00

Refinements in grid.svelte

This commit is contained in:
Romein van Buren 2023-01-15 16:15:23 +01:00
parent 2e312dc7cb
commit fdd8765858
Signed by: romein
GPG Key ID: 0EFF8478ADDF6C49

View File

@ -62,6 +62,25 @@
select(item[key]); select(item[key]);
contextMenu.show(evt, item.menu); contextMenu.show(evt, item.menu);
} }
function formatValue(value) {
if (Array.isArray(value)) {
return '[...]';
}
if (typeof value === 'object') {
return '{...}';
}
if (value === undefined || value === null) {
return '';
}
if (typeof value === 'number' || typeof value === 'boolean') {
return String(value);
}
if (String(value).length <= 1000) {
return value;
}
return String(value).slice(0, 1000) + '…';
}
</script> </script>
<div class:grid={level === 0} class:subgrid={level > 0} class:contained> <div class:grid={level === 0} class:subgrid={level > 0} class:contained>
@ -77,6 +96,13 @@
{/if} {/if}
<table> <table>
<colgroup>
<col style:width="calc(15px + 0.6rem)" />
{#each columns as column}
<col />
{/each}
</colgroup>
{#if showHeaders && columns.some(col => col.title)} {#if showHeaders && columns.some(col => col.title)}
<thead> <thead>
<tr> <tr>
@ -106,10 +132,8 @@
{#each columns as column} {#each columns as column}
{@const value = item[column.key]} {@const value = item[column.key]}
<td class:right={column.right}> <td class:right={column.right} title={value}>
{#if typeof value !== 'object'} {formatValue(value)}
{value || ''}
{/if}
</td> </td>
{/each} {/each}
</tr> </tr>
@ -161,6 +185,7 @@
table { table {
border-collapse: collapse; border-collapse: collapse;
width: 100%; width: 100%;
/* table-layout: fixed; */
} }
table thead { table thead {
@ -178,6 +203,7 @@
td, th { td, th {
padding: 0.3rem; padding: 0.3rem;
text-overflow: ellipsis;
} }
td.has-toggle { td.has-toggle {
width: calc(20px + 0.3rem); width: calc(20px + 0.3rem);