compote-ui 0.36.2 → 0.37.0
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.
|
@@ -5,12 +5,11 @@
|
|
|
5
5
|
import { cn, type ClassValue } from 'tailwind-variants';
|
|
6
6
|
import { PhArrowSquareOut, PhCaretDown, PhCaretUp, PhCheck, PhX } from '../../icons';
|
|
7
7
|
import Checkbox from '../checkbox/checkbox.svelte';
|
|
8
|
-
import {
|
|
9
|
-
import type {
|
|
8
|
+
import { type DataTableFeatures, type DataTableInstance } from './create-table';
|
|
9
|
+
import type { DataTableColumnMeta } from './types';
|
|
10
10
|
|
|
11
11
|
type Props = Omit<HTMLAttributes<HTMLDivElement>, 'class'> & {
|
|
12
12
|
table: DataTableInstance<T>;
|
|
13
|
-
columns: DataTableColumn<T>[];
|
|
14
13
|
caption?: string;
|
|
15
14
|
emptyMessage?: string;
|
|
16
15
|
class?: ClassValue;
|
|
@@ -18,18 +17,17 @@
|
|
|
18
17
|
|
|
19
18
|
let {
|
|
20
19
|
table,
|
|
21
|
-
columns,
|
|
22
20
|
caption,
|
|
23
21
|
emptyMessage = 'No rows found',
|
|
24
22
|
class: className,
|
|
25
23
|
...rest
|
|
26
24
|
}: Props = $props();
|
|
27
25
|
|
|
28
|
-
function alignClass(align:
|
|
26
|
+
function alignClass(align: DataTableColumnMeta['align']) {
|
|
29
27
|
return align === 'right' ? 'text-right' : align === 'center' ? 'text-center' : 'text-left';
|
|
30
28
|
}
|
|
31
29
|
|
|
32
|
-
function justifyClass(align:
|
|
30
|
+
function justifyClass(align: DataTableColumnMeta['align']) {
|
|
33
31
|
return align === 'right'
|
|
34
32
|
? 'justify-end'
|
|
35
33
|
: align === 'center'
|
|
@@ -37,7 +35,7 @@
|
|
|
37
35
|
: 'justify-start';
|
|
38
36
|
}
|
|
39
37
|
|
|
40
|
-
function sortButtonDirectionClass(align:
|
|
38
|
+
function sortButtonDirectionClass(align: DataTableColumnMeta['align']) {
|
|
41
39
|
return align === 'right' ? 'flex-row-reverse' : 'flex-row';
|
|
42
40
|
}
|
|
43
41
|
|
|
@@ -157,30 +155,8 @@
|
|
|
157
155
|
window.open(value, '_blank', 'noopener,noreferrer');
|
|
158
156
|
}
|
|
159
157
|
|
|
160
|
-
function
|
|
161
|
-
return
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
function isLeafColumn(column: DataTableColumn<T>): column is DataTableLeafColumn<T> {
|
|
165
|
-
return !isGroupColumn(column);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function findColumnById(
|
|
169
|
-
columnId: string,
|
|
170
|
-
candidates: DataTableColumn<T>[]
|
|
171
|
-
): DataTableColumn<T> | undefined {
|
|
172
|
-
for (const column of candidates) {
|
|
173
|
-
if (isGroupColumn(column)) {
|
|
174
|
-
if ((column.id ?? column.header) === columnId) return column;
|
|
175
|
-
|
|
176
|
-
const found = findColumnById(columnId, column.columns);
|
|
177
|
-
if (found) return found;
|
|
178
|
-
|
|
179
|
-
continue;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
if (isLeafColumn(column) && getColumnId(column) === columnId) return column;
|
|
183
|
-
}
|
|
158
|
+
function getColumnMeta(columnDef: { meta?: unknown }): DataTableColumnMeta | undefined {
|
|
159
|
+
return columnDef.meta as DataTableColumnMeta | undefined;
|
|
184
160
|
}
|
|
185
161
|
|
|
186
162
|
const tableStateKey = $derived(JSON.stringify(table.store.state));
|
|
@@ -258,7 +234,7 @@
|
|
|
258
234
|
</th>
|
|
259
235
|
{/if}
|
|
260
236
|
{#each visibleHeaders as header, headerIndex (header.id)}
|
|
261
|
-
{@const columnDef =
|
|
237
|
+
{@const columnDef = getColumnMeta(header.column.columnDef)}
|
|
262
238
|
{@const sortDirection = getHeaderSortDirection(header, table.store.state.sorting)}
|
|
263
239
|
<th
|
|
264
240
|
class={cn(
|
|
@@ -344,7 +320,7 @@
|
|
|
344
320
|
</td>
|
|
345
321
|
{/if}
|
|
346
322
|
{#each row.getVisibleCells() as cell (cell.id)}
|
|
347
|
-
{@const columnDef =
|
|
323
|
+
{@const columnDef = getColumnMeta(cell.column.columnDef)}
|
|
348
324
|
<td
|
|
349
325
|
class={cn(
|
|
350
326
|
'truncate px-3 py-2',
|
|
@@ -2,11 +2,9 @@ import type { RowData } from '@tanstack/svelte-table';
|
|
|
2
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
3
|
import { type ClassValue } from 'tailwind-variants';
|
|
4
4
|
import { type DataTableInstance } from './create-table';
|
|
5
|
-
import type { DataTableColumn } from './types';
|
|
6
5
|
declare function $$render<T extends RowData>(): {
|
|
7
6
|
props: Omit<HTMLAttributes<HTMLDivElement>, "class"> & {
|
|
8
7
|
table: DataTableInstance<T>;
|
|
9
|
-
columns: DataTableColumn<T>[];
|
|
10
8
|
caption?: string;
|
|
11
9
|
emptyMessage?: string;
|
|
12
10
|
class?: ClassValue;
|
|
@@ -49,3 +49,9 @@ export type DataTableGroupColumn<T extends RowData> = DataTableColumnBase & {
|
|
|
49
49
|
formatLocale?: never;
|
|
50
50
|
};
|
|
51
51
|
export type DataTableColumn<T extends RowData> = DataTableLeafColumn<T> | DataTableGroupColumn<T>;
|
|
52
|
+
export type DataTableColumnMeta = {
|
|
53
|
+
align?: DataTableAlign;
|
|
54
|
+
type?: DataTableColumnType;
|
|
55
|
+
formatOptions?: Intl.NumberFormatOptions;
|
|
56
|
+
formatLocale?: string;
|
|
57
|
+
};
|