compote-ui 0.44.0 → 0.44.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  <script lang="ts" generics="T extends RowData">
2
2
  import type { Row, RowData } from '@tanstack/table-core';
3
3
  import { createVirtualizer } from '@tanstack/svelte-virtual';
4
+ import { untrack } from 'svelte';
4
5
  import { cn } from 'tailwind-variants';
5
6
  import { PhArrowSquareOut, PhCheck, PhX } from '../../icons';
6
7
  import type { DataTableInstance } from './data-table-utils';
@@ -57,6 +58,13 @@
57
58
  function measureRowElement(node: HTMLTableRowElement) {
58
59
  $rowVirtualizer.measureElement(node);
59
60
  }
61
+
62
+ $effect(() => {
63
+ const count = rows.length;
64
+ untrack(() => {
65
+ $rowVirtualizer.setOptions({ ...$rowVirtualizer.options, count });
66
+ });
67
+ });
60
68
  </script>
61
69
 
62
70
  <tbody style="display: grid; height: {$rowVirtualizer.getTotalSize()}px; position: relative">
@@ -70,98 +78,98 @@
70
78
  {#each $rowVirtualizer.getVirtualItems() as virtualRow (virtualRow.index)}
71
79
  {@const row = rows[virtualRow.index]}
72
80
  {#if row}
73
- {@const rowSelected = getReactiveTableState(table).rowSelection[row.id] === true}
74
- <tr
75
- data-index={virtualRow.index}
76
- use:measureRowElement
77
- class={cn(
78
- 'group/row border-b border-surface-2 last:border-b-0',
79
- '[--row-bg:var(--compote-surface-1)]',
80
- 'hover:bg-well/60 hover:[--row-bg:color-mix(in_srgb,var(--compote-well)_60%,var(--compote-surface-1))]',
81
- rowSelected &&
82
- 'bg-well/60 [--row-bg:color-mix(in_srgb,var(--compote-well)_60%,var(--compote-surface-1))]'
83
- )}
84
- style="display: flex; position: absolute; transform: translateY({virtualRow.start}px); width: 100%"
85
- onclick={(event) => onRowClick?.({ row: row.original, event })}
86
- ondblclick={(event) => onRowDoubleClick?.({ row: row.original, event })}
87
- >
88
- {#if isRowSelectionEnabled}
89
- <td
90
- class="items-center justify-center bg-(--row-bg) px-3 py-2 text-center align-middle"
91
- style={joinStyles(
92
- virtualSelectionColumnSizeStyle(),
93
- 'position: sticky; left: 0; z-index: 1'
94
- )}
95
- >
96
- <input
97
- type="checkbox"
98
- aria-label="Select row"
99
- class="table-checkbox mx-auto block size-4"
100
- checked={rowSelected}
101
- disabled={!row.getCanSelect()}
102
- onchange={(e) => row.toggleSelected(e.currentTarget.checked)}
103
- />
104
- </td>
105
- {/if}
106
- {#each getReactiveCells(row, getReactiveTableState(table).columnVisibility) as cell (cell.id)}
107
- {@const columnDef = getColumnMeta(cell.column.columnDef)}
108
- <td
109
- class={cn(
110
- 'items-center truncate px-3 py-2',
111
- alignClass(columnDef?.align),
112
- justifyClass(columnDef?.align),
113
- cell.column.getIsPinned() && 'bg-(--row-bg)'
114
- )}
115
- style={joinStyles(
116
- getColumnMeta(cell.column.columnDef)?.grow
117
- ? virtualGrowColumnSizeStyle()
118
- : virtualColumnSizeStyle(cell.column.getSize()),
119
- getPinningStyle(cell.column, table, false, isRowSelectionEnabled)
120
- )}
121
- >
122
- {#if columnDef?.type === 'boolean'}
123
- {@const value = getBooleanCellValue(cell.getValue())}
124
- {#if value === true}
125
- <span
126
- class="inline-flex size-5 items-center justify-center text-success"
127
- role="img"
128
- aria-label="Yes"
129
- >
130
- <PhCheck class="size-4" />
131
- </span>
132
- {:else if value === false}
133
- <span
134
- class="inline-flex size-5 items-center justify-center text-danger"
135
- role="img"
136
- aria-label="No"
137
- >
138
- <PhX class="size-4" />
139
- </span>
140
- {:else}
141
- -
142
- {/if}
143
- {:else if columnDef?.type === 'url'}
144
- {@const value = getUrlCellValue(cell.getValue())}
145
- {#if value}
146
- <button
147
- type="button"
148
- class={cn(
149
- 'inline-flex max-w-full appearance-none items-center gap-1.5 rounded-sm border-0 bg-transparent p-0 align-middle leading-5 font-medium text-ink underline decoration-border decoration-dotted underline-offset-4 outline-none hover:text-primary focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring',
150
- justifyClass(columnDef.align)
151
- )}
152
- onclick={() => openUrlCell(value)}
153
- >
154
- <PhArrowSquareOut class="size-3.5 shrink-0" />
155
- </button>
81
+ {@const rowSelected = getReactiveTableState(table).rowSelection[row.id] === true}
82
+ <tr
83
+ data-index={virtualRow.index}
84
+ use:measureRowElement
85
+ class={cn(
86
+ 'group/row border-b border-surface-2 last:border-b-0',
87
+ '[--row-bg:var(--compote-surface-1)]',
88
+ 'hover:bg-well/60 hover:[--row-bg:color-mix(in_srgb,var(--compote-well)_60%,var(--compote-surface-1))]',
89
+ rowSelected &&
90
+ 'bg-well/60 [--row-bg:color-mix(in_srgb,var(--compote-well)_60%,var(--compote-surface-1))]'
91
+ )}
92
+ style="display: flex; position: absolute; transform: translateY({virtualRow.start}px); width: 100%"
93
+ onclick={(event) => onRowClick?.({ row: row.original, event })}
94
+ ondblclick={(event) => onRowDoubleClick?.({ row: row.original, event })}
95
+ >
96
+ {#if isRowSelectionEnabled}
97
+ <td
98
+ class="items-center justify-center bg-(--row-bg) px-3 py-2 text-center align-middle"
99
+ style={joinStyles(
100
+ virtualSelectionColumnSizeStyle(),
101
+ 'position: sticky; left: 0; z-index: 1'
102
+ )}
103
+ >
104
+ <input
105
+ type="checkbox"
106
+ aria-label="Select row"
107
+ class="table-checkbox mx-auto block size-4"
108
+ checked={rowSelected}
109
+ disabled={!row.getCanSelect()}
110
+ onchange={(e) => row.toggleSelected(e.currentTarget.checked)}
111
+ />
112
+ </td>
113
+ {/if}
114
+ {#each getReactiveCells(row, getReactiveTableState(table).columnVisibility) as cell (cell.id)}
115
+ {@const columnDef = getColumnMeta(cell.column.columnDef)}
116
+ <td
117
+ class={cn(
118
+ 'items-center truncate px-3 py-2',
119
+ alignClass(columnDef?.align),
120
+ justifyClass(columnDef?.align),
121
+ cell.column.getIsPinned() && 'bg-(--row-bg)'
122
+ )}
123
+ style={joinStyles(
124
+ getColumnMeta(cell.column.columnDef)?.grow
125
+ ? virtualGrowColumnSizeStyle()
126
+ : virtualColumnSizeStyle(cell.column.getSize()),
127
+ getPinningStyle(cell.column, table, false, isRowSelectionEnabled)
128
+ )}
129
+ >
130
+ {#if columnDef?.type === 'boolean'}
131
+ {@const value = getBooleanCellValue(cell.getValue())}
132
+ {#if value === true}
133
+ <span
134
+ class="inline-flex size-5 items-center justify-center text-success"
135
+ role="img"
136
+ aria-label="Yes"
137
+ >
138
+ <PhCheck class="size-4" />
139
+ </span>
140
+ {:else if value === false}
141
+ <span
142
+ class="inline-flex size-5 items-center justify-center text-danger"
143
+ role="img"
144
+ aria-label="No"
145
+ >
146
+ <PhX class="size-4" />
147
+ </span>
148
+ {:else}
149
+ -
150
+ {/if}
151
+ {:else if columnDef?.type === 'url'}
152
+ {@const value = getUrlCellValue(cell.getValue())}
153
+ {#if value}
154
+ <button
155
+ type="button"
156
+ class={cn(
157
+ 'inline-flex max-w-full appearance-none items-center gap-1.5 rounded-sm border-0 bg-transparent p-0 align-middle leading-5 font-medium text-ink underline decoration-border decoration-dotted underline-offset-4 outline-none hover:text-primary focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring',
158
+ justifyClass(columnDef.align)
159
+ )}
160
+ onclick={() => openUrlCell(value)}
161
+ >
162
+ <PhArrowSquareOut class="size-3.5 shrink-0" />
163
+ </button>
164
+ {:else}
165
+ -
166
+ {/if}
156
167
  {:else}
157
- -
168
+ <FlexRender content={cell.column.columnDef.cell} context={cell.getContext()} />
158
169
  {/if}
159
- {:else}
160
- <FlexRender content={cell.column.columnDef.cell} context={cell.getContext()} />
161
- {/if}
162
- </td>
163
- {/each}
164
- </tr>
170
+ </td>
171
+ {/each}
172
+ </tr>
165
173
  {/if}
166
174
  {/each}
167
175
  {/if}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "compote-ui",
3
- "version": "0.44.0",
3
+ "version": "0.44.1",
4
4
  "license": "MIT",
5
5
  "scripts": {
6
6
  "dev": "vite dev --open",