compote-ui 0.42.6 → 0.43.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.
- package/dist/components/data-table/column-helper.ts.md +96 -0
- package/dist/components/data-table/create-table.ts.md +386 -0
- package/dist/components/data-table/data-table-column-filter.svelte.md +249 -0
- package/dist/components/data-table/data-table-column-visibility.svelte.md +74 -0
- package/dist/components/data-table/{data-table-head.svelte → data-table-head.svelte.md} +1 -1
- package/dist/components/data-table/data-table-new.svelte.md +245 -0
- package/dist/components/data-table/data-table-title.svelte.md +16 -0
- package/dist/components/data-table/data-table-toolbar.svelte.md +40 -0
- package/dist/components/data-table/data-table-utils.ts.md +179 -0
- package/dist/components/data-table/{data-table-virtual-rows.svelte → data-table-virtual-rows.svelte.md} +1 -1
- package/dist/components/data-table/data-table-virtualized.svelte.md +108 -0
- package/dist/components/data-table/data-table.svelte.md +214 -0
- package/dist/components/data-table/index.ts.md +22 -0
- package/dist/components/data-table/types.ts.md +101 -0
- package/dist/components/data-table/virtual/index.ts.md +26 -0
- package/dist/components/{data-table → data-table-v8}/column-helper.d.ts +1 -1
- package/dist/components/data-table-v8/create-svelte-table.svelte.d.ts +8 -0
- package/dist/components/data-table-v8/create-svelte-table.svelte.js +85 -0
- package/dist/components/data-table-v8/create-table.svelte.d.ts +35 -0
- package/dist/components/{data-table/create-table.js → data-table-v8/create-table.svelte.js} +25 -55
- package/dist/components/data-table-v8/data-table-checkbox.css +44 -0
- package/dist/components/{data-table → data-table-v8}/data-table-column-filter.svelte +16 -19
- package/dist/components/{data-table → data-table-v8}/data-table-column-filter.svelte.d.ts +2 -2
- package/dist/components/{data-table → data-table-v8}/data-table-column-visibility.svelte +15 -14
- package/dist/components/{data-table → data-table-v8}/data-table-column-visibility.svelte.d.ts +2 -2
- package/dist/components/data-table-v8/data-table-head.svelte +200 -0
- package/dist/components/{data-table → data-table-v8}/data-table-head.svelte.d.ts +3 -3
- package/dist/components/{data-table → data-table-v8}/data-table-utils.d.ts +10 -15
- package/dist/components/{data-table → data-table-v8}/data-table-utils.js +18 -12
- package/dist/components/data-table-v8/data-table-virtual-rows.svelte +170 -0
- package/dist/components/{data-table → data-table-v8}/data-table-virtual-rows.svelte.d.ts +3 -3
- package/dist/components/{data-table → data-table-v8}/data-table-virtualized.svelte +15 -14
- package/dist/components/{data-table → data-table-v8}/data-table-virtualized.svelte.d.ts +2 -2
- package/dist/components/{data-table → data-table-v8}/data-table.svelte +40 -22
- package/dist/components/{data-table → data-table-v8}/data-table.svelte.d.ts +2 -2
- package/dist/components/data-table-v8/flex-render.svelte +35 -0
- package/dist/components/data-table-v8/flex-render.svelte.d.ts +28 -0
- package/dist/components/{data-table → data-table-v8}/index.d.ts +4 -2
- package/dist/components/{data-table → data-table-v8}/index.js +3 -1
- package/dist/components/data-table-v8/render-helpers.d.ts +13 -0
- package/dist/components/data-table-v8/render-helpers.js +23 -0
- package/dist/components/{data-table → data-table-v8}/types.d.ts +12 -2
- package/dist/components/data-table-v8/virtual/index.d.ts +3 -0
- package/dist/components/data-table-v8/virtual/index.js +2 -0
- package/package.json +9 -9
- package/dist/components/data-table/create-table.d.ts +0 -41
- package/dist/components/data-table/virtual/index.d.ts +0 -3
- package/dist/components/data-table/virtual/index.js +0 -2
- /package/dist/components/{data-table → data-table-v8}/column-helper.js +0 -0
- /package/dist/components/{data-table → data-table-v8}/data-table-title.svelte +0 -0
- /package/dist/components/{data-table → data-table-v8}/data-table-title.svelte.d.ts +0 -0
- /package/dist/components/{data-table → data-table-v8}/data-table-toolbar.svelte +0 -0
- /package/dist/components/{data-table → data-table-v8}/data-table-toolbar.svelte.d.ts +0 -0
- /package/dist/components/{data-table → data-table-v8}/types.js +0 -0
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { DataTableFeatures, DataTableInstance } from './create-table';
|
|
1
|
+
import type { Column, Header, Row, RowData, Table, TableState, VisibilityState } from '@tanstack/table-core';
|
|
3
2
|
import type { DataTableColumnMeta } from './types';
|
|
4
|
-
export type
|
|
5
|
-
|
|
6
|
-
getStart(position?: ColumnPinningPosition): number;
|
|
7
|
-
getAfter(position?: ColumnPinningPosition): number;
|
|
8
|
-
getIsLastColumn(position?: ColumnPinningPosition): boolean;
|
|
9
|
-
getIsFirstColumn(position?: ColumnPinningPosition): boolean;
|
|
10
|
-
};
|
|
3
|
+
export type DataTableInstance<T extends RowData> = Table<T>;
|
|
4
|
+
export declare function getReactiveTableState<T extends RowData>(table: DataTableInstance<T>): TableState;
|
|
11
5
|
export declare function alignClass(align: DataTableColumnMeta['align']): "text-right" | "text-center" | "text-left";
|
|
12
6
|
export declare function justifyClass(align: DataTableColumnMeta['align']): "justify-end" | "justify-center" | "justify-start";
|
|
13
7
|
export declare function sortButtonDirectionClass(align: DataTableColumnMeta['align']): "flex-row-reverse" | "flex-row";
|
|
@@ -18,16 +12,17 @@ export declare function virtualSelectionColumnSizeStyle(): string;
|
|
|
18
12
|
export declare function tableSizeStyle<T extends RowData>(table: DataTableInstance<T>, isRowSelectionEnabled: boolean): string;
|
|
19
13
|
export declare function virtualGrowColumnSizeStyle(): string;
|
|
20
14
|
export declare function virtualGroupWithGrowSizeStyle(fixedPortion: number): string;
|
|
21
|
-
export declare function resizeHandleStyle<T extends RowData>(table: DataTableInstance<T>, header: Header<
|
|
15
|
+
export declare function resizeHandleStyle<T extends RowData>(table: DataTableInstance<T>, header: Header<T, unknown>): string | undefined;
|
|
22
16
|
export declare function resizeHandleClass(headerIndex: number, headerCount: number): import("tailwind-variants").CnReturn;
|
|
23
|
-
export declare function getHeaderSortDirection<T extends RowData>(header: Header<
|
|
17
|
+
export declare function getHeaderSortDirection<T extends RowData>(header: Header<T, unknown>): false | import("@tanstack/table-core").SortDirection;
|
|
24
18
|
export declare function getHeaderSortLabel(sortDirection: false | 'asc' | 'desc'): "Sorted ascending" | "Sorted descending" | "Not sorted";
|
|
25
19
|
export declare function getHeaderAriaSort(sortDirection: false | 'asc' | 'desc'): "none" | "ascending" | "descending";
|
|
26
|
-
export declare function getAllRowsSelectionState<T extends RowData>(table: DataTableInstance<T
|
|
27
|
-
export declare function getRowSelectionState<T extends RowData>(table: DataTableInstance<T>,
|
|
28
|
-
export declare function
|
|
20
|
+
export declare function getAllRowsSelectionState<T extends RowData>(table: DataTableInstance<T>): boolean | 'indeterminate';
|
|
21
|
+
export declare function getRowSelectionState<T extends RowData>(table: DataTableInstance<T>, rowId: string): boolean;
|
|
22
|
+
export declare function getReactiveCells<T extends RowData>(row: Row<T>, columnVisibility: VisibilityState): import("@tanstack/table-core").Cell<T, unknown>[];
|
|
23
|
+
export declare function getSelectedRowCount<T extends RowData>(table: DataTableInstance<T>): number;
|
|
29
24
|
export declare function getBooleanCellValue(value: unknown): boolean | undefined;
|
|
30
|
-
export declare function getPinningStyle(column:
|
|
25
|
+
export declare function getPinningStyle<T extends RowData>(column: Column<T, unknown>, table: DataTableInstance<T>, isHeader?: boolean, isRowSelectionEnabled?: boolean): string | undefined;
|
|
31
26
|
export declare function getUrlCellValue(value: unknown): string | undefined;
|
|
32
27
|
export declare function openUrlCell(value: string): void;
|
|
33
28
|
export declare function getColumnMeta(columnDef: {
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { cn } from 'tailwind-variants';
|
|
2
|
+
export function getReactiveTableState(table) {
|
|
3
|
+
return table._svelteState ?? table.getState();
|
|
4
|
+
}
|
|
2
5
|
export function alignClass(align) {
|
|
3
6
|
return align === 'right' ? 'text-right' : align === 'center' ? 'text-center' : 'text-left';
|
|
4
7
|
}
|
|
@@ -36,7 +39,7 @@ export function virtualGroupWithGrowSizeStyle(fixedPortion) {
|
|
|
36
39
|
export function resizeHandleStyle(table, header) {
|
|
37
40
|
if (table.options.columnResizeMode !== 'onEnd')
|
|
38
41
|
return undefined;
|
|
39
|
-
const deltaOffset = table.
|
|
42
|
+
const deltaOffset = table.getState().columnSizingInfo.deltaOffset;
|
|
40
43
|
if (!header.column.getIsResizing() || deltaOffset === null)
|
|
41
44
|
return undefined;
|
|
42
45
|
return `transform: translateX(${deltaOffset}px)`;
|
|
@@ -44,8 +47,7 @@ export function resizeHandleStyle(table, header) {
|
|
|
44
47
|
export function resizeHandleClass(headerIndex, headerCount) {
|
|
45
48
|
return cn('absolute top-0 z-10 flex h-full w-2 cursor-col-resize touch-none items-center justify-center select-none before:h-4 before:w-px before:bg-border before:content-[""]', headerIndex === headerCount - 1 ? 'right-0' : '-right-1');
|
|
46
49
|
}
|
|
47
|
-
export function getHeaderSortDirection(header
|
|
48
|
-
void sortingState;
|
|
50
|
+
export function getHeaderSortDirection(header) {
|
|
49
51
|
return header.column.getIsSorted();
|
|
50
52
|
}
|
|
51
53
|
export function getHeaderSortLabel(sortDirection) {
|
|
@@ -62,18 +64,18 @@ export function getHeaderAriaSort(sortDirection) {
|
|
|
62
64
|
return 'descending';
|
|
63
65
|
return 'none';
|
|
64
66
|
}
|
|
65
|
-
export function getAllRowsSelectionState(table
|
|
66
|
-
void rowSelection;
|
|
67
|
+
export function getAllRowsSelectionState(table) {
|
|
67
68
|
const allRowsSelected = table.getIsAllRowsSelected();
|
|
68
69
|
const someRowsSelected = table.getIsSomeRowsSelected();
|
|
69
70
|
return allRowsSelected ? true : someRowsSelected ? 'indeterminate' : false;
|
|
70
71
|
}
|
|
71
|
-
export function getRowSelectionState(table,
|
|
72
|
-
void rowSelection;
|
|
72
|
+
export function getRowSelectionState(table, rowId) {
|
|
73
73
|
return table.getRow(rowId).getIsSelected();
|
|
74
74
|
}
|
|
75
|
-
export function
|
|
76
|
-
|
|
75
|
+
export function getReactiveCells(row, columnVisibility) {
|
|
76
|
+
return row.getAllCells().filter((cell) => columnVisibility[cell.column.id] !== false);
|
|
77
|
+
}
|
|
78
|
+
export function getSelectedRowCount(table) {
|
|
77
79
|
return table.getSelectedRowModel().rows.length;
|
|
78
80
|
}
|
|
79
81
|
export function getBooleanCellValue(value) {
|
|
@@ -83,7 +85,7 @@ export function getBooleanCellValue(value) {
|
|
|
83
85
|
return false;
|
|
84
86
|
return undefined;
|
|
85
87
|
}
|
|
86
|
-
export function getPinningStyle(column, isHeader = false, isRowSelectionEnabled = false) {
|
|
88
|
+
export function getPinningStyle(column, table, isHeader = false, isRowSelectionEnabled = false) {
|
|
87
89
|
const isPinned = column.getIsPinned();
|
|
88
90
|
if (!isPinned)
|
|
89
91
|
return undefined;
|
|
@@ -91,7 +93,9 @@ export function getPinningStyle(column, isHeader = false, isRowSelectionEnabled
|
|
|
91
93
|
const selectionOffset = isRowSelectionEnabled ? 40 : 0;
|
|
92
94
|
if (isPinned === 'left') {
|
|
93
95
|
const left = column.getStart('left') + selectionOffset;
|
|
94
|
-
const
|
|
96
|
+
const leftCols = table.getLeftLeafColumns();
|
|
97
|
+
const isLastLeft = leftCols[leftCols.length - 1]?.id === column.id;
|
|
98
|
+
const shadow = !isHeader && isLastLeft
|
|
95
99
|
? 'box-shadow: -4px 0 4px -4px var(--compote-border) inset'
|
|
96
100
|
: undefined;
|
|
97
101
|
return ['position: sticky', `z-index: ${zIndex}`, `left: ${left}px`, shadow]
|
|
@@ -100,7 +104,9 @@ export function getPinningStyle(column, isHeader = false, isRowSelectionEnabled
|
|
|
100
104
|
}
|
|
101
105
|
else {
|
|
102
106
|
const right = column.getAfter('right');
|
|
103
|
-
const
|
|
107
|
+
const rightCols = table.getRightLeafColumns();
|
|
108
|
+
const isFirstRight = rightCols[0]?.id === column.id;
|
|
109
|
+
const shadow = !isHeader && isFirstRight
|
|
104
110
|
? 'box-shadow: 4px 0 4px -4px var(--compote-border) inset'
|
|
105
111
|
: undefined;
|
|
106
112
|
return ['position: sticky', `z-index: ${zIndex}`, `right: ${right}px`, shadow]
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
<script lang="ts" generics="T extends RowData">
|
|
2
|
+
import type { Row, RowData } from '@tanstack/table-core';
|
|
3
|
+
import { createVirtualizer } from '@tanstack/svelte-virtual';
|
|
4
|
+
import { cn } from 'tailwind-variants';
|
|
5
|
+
import { PhArrowSquareOut, PhCheck, PhX } from '../../icons';
|
|
6
|
+
import type { DataTableInstance } from './data-table-utils';
|
|
7
|
+
import FlexRender from './flex-render.svelte';
|
|
8
|
+
import {
|
|
9
|
+
alignClass,
|
|
10
|
+
getBooleanCellValue,
|
|
11
|
+
getColumnMeta,
|
|
12
|
+
getPinningStyle,
|
|
13
|
+
getReactiveCells,
|
|
14
|
+
getReactiveTableState,
|
|
15
|
+
getUrlCellValue,
|
|
16
|
+
joinStyles,
|
|
17
|
+
justifyClass,
|
|
18
|
+
openUrlCell,
|
|
19
|
+
virtualColumnSizeStyle,
|
|
20
|
+
virtualGrowColumnSizeStyle,
|
|
21
|
+
virtualSelectionColumnSizeStyle
|
|
22
|
+
} from './data-table-utils';
|
|
23
|
+
|
|
24
|
+
type Props = {
|
|
25
|
+
rows: Row<T>[];
|
|
26
|
+
scrollContainer: HTMLDivElement;
|
|
27
|
+
isRowSelectionEnabled: boolean;
|
|
28
|
+
table: DataTableInstance<T>;
|
|
29
|
+
emptyMessage: string;
|
|
30
|
+
onRowClick?: (details: { row: T; event: MouseEvent }) => void;
|
|
31
|
+
onRowDoubleClick?: (details: { row: T; event: MouseEvent }) => void;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
let {
|
|
35
|
+
rows,
|
|
36
|
+
scrollContainer,
|
|
37
|
+
isRowSelectionEnabled,
|
|
38
|
+
table,
|
|
39
|
+
emptyMessage,
|
|
40
|
+
onRowClick,
|
|
41
|
+
onRowDoubleClick
|
|
42
|
+
}: Props = $props();
|
|
43
|
+
|
|
44
|
+
const rowVirtualizer = createVirtualizer<HTMLDivElement, HTMLTableRowElement>({
|
|
45
|
+
get count() {
|
|
46
|
+
return rows.length;
|
|
47
|
+
},
|
|
48
|
+
estimateSize: () => 37,
|
|
49
|
+
getScrollElement: () => scrollContainer,
|
|
50
|
+
measureElement:
|
|
51
|
+
typeof window !== 'undefined' && !navigator.userAgent.includes('Firefox')
|
|
52
|
+
? (element) => element.getBoundingClientRect().height
|
|
53
|
+
: undefined,
|
|
54
|
+
overscan: 5
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
function measureRowElement(node: HTMLTableRowElement) {
|
|
58
|
+
$rowVirtualizer.measureElement(node);
|
|
59
|
+
}
|
|
60
|
+
</script>
|
|
61
|
+
|
|
62
|
+
<tbody style="display: grid; height: {$rowVirtualizer.getTotalSize()}px; position: relative">
|
|
63
|
+
{#if rows.length === 0}
|
|
64
|
+
<tr style="display: flex; position: absolute; width: 100%; top: 0">
|
|
65
|
+
<td class="px-3 py-10 text-center text-sm text-ink-dim" style="flex: 1">
|
|
66
|
+
{emptyMessage}
|
|
67
|
+
</td>
|
|
68
|
+
</tr>
|
|
69
|
+
{:else}
|
|
70
|
+
{#each $rowVirtualizer.getVirtualItems() as virtualRow (virtualRow.index)}
|
|
71
|
+
{@const row = rows[virtualRow.index]}
|
|
72
|
+
{@const rowSelected = getReactiveTableState(table).rowSelection[row.id] === true}
|
|
73
|
+
<tr
|
|
74
|
+
data-index={virtualRow.index}
|
|
75
|
+
use:measureRowElement
|
|
76
|
+
class={cn(
|
|
77
|
+
'group/row border-b border-surface-2 last:border-b-0',
|
|
78
|
+
'[--row-bg:var(--compote-surface-1)]',
|
|
79
|
+
'hover:bg-well/60 hover:[--row-bg:color-mix(in_srgb,var(--compote-well)_60%,var(--compote-surface-1))]',
|
|
80
|
+
rowSelected &&
|
|
81
|
+
'bg-well/60 [--row-bg:color-mix(in_srgb,var(--compote-well)_60%,var(--compote-surface-1))]'
|
|
82
|
+
)}
|
|
83
|
+
style="display: flex; position: absolute; transform: translateY({virtualRow.start}px); width: 100%"
|
|
84
|
+
onclick={(event) => onRowClick?.({ row: row.original, event })}
|
|
85
|
+
ondblclick={(event) => onRowDoubleClick?.({ row: row.original, event })}
|
|
86
|
+
>
|
|
87
|
+
{#if isRowSelectionEnabled}
|
|
88
|
+
<td
|
|
89
|
+
class="items-center justify-center bg-(--row-bg) px-3 py-2 text-center align-middle"
|
|
90
|
+
style={joinStyles(
|
|
91
|
+
virtualSelectionColumnSizeStyle(),
|
|
92
|
+
'position: sticky; left: 0; z-index: 1'
|
|
93
|
+
)}
|
|
94
|
+
>
|
|
95
|
+
<input
|
|
96
|
+
type="checkbox"
|
|
97
|
+
aria-label="Select row"
|
|
98
|
+
class="table-checkbox mx-auto block size-4"
|
|
99
|
+
checked={rowSelected}
|
|
100
|
+
disabled={!row.getCanSelect()}
|
|
101
|
+
onchange={(e) => row.toggleSelected(e.currentTarget.checked)}
|
|
102
|
+
/>
|
|
103
|
+
</td>
|
|
104
|
+
{/if}
|
|
105
|
+
{#each getReactiveCells(row, getReactiveTableState(table).columnVisibility) as cell (cell.id)}
|
|
106
|
+
{@const columnDef = getColumnMeta(cell.column.columnDef)}
|
|
107
|
+
<td
|
|
108
|
+
class={cn(
|
|
109
|
+
'items-center truncate px-3 py-2',
|
|
110
|
+
alignClass(columnDef?.align),
|
|
111
|
+
justifyClass(columnDef?.align),
|
|
112
|
+
cell.column.getIsPinned() && 'bg-(--row-bg)'
|
|
113
|
+
)}
|
|
114
|
+
style={joinStyles(
|
|
115
|
+
getColumnMeta(cell.column.columnDef)?.grow
|
|
116
|
+
? virtualGrowColumnSizeStyle()
|
|
117
|
+
: virtualColumnSizeStyle(cell.column.getSize()),
|
|
118
|
+
getPinningStyle(cell.column, table, false, isRowSelectionEnabled)
|
|
119
|
+
)}
|
|
120
|
+
>
|
|
121
|
+
{#if columnDef?.type === 'boolean'}
|
|
122
|
+
{@const value = getBooleanCellValue(cell.getValue())}
|
|
123
|
+
{#if value === true}
|
|
124
|
+
<span
|
|
125
|
+
class="inline-flex size-5 items-center justify-center text-success"
|
|
126
|
+
role="img"
|
|
127
|
+
aria-label="Yes"
|
|
128
|
+
>
|
|
129
|
+
<PhCheck class="size-4" />
|
|
130
|
+
</span>
|
|
131
|
+
{:else if value === false}
|
|
132
|
+
<span
|
|
133
|
+
class="inline-flex size-5 items-center justify-center text-danger"
|
|
134
|
+
role="img"
|
|
135
|
+
aria-label="No"
|
|
136
|
+
>
|
|
137
|
+
<PhX class="size-4" />
|
|
138
|
+
</span>
|
|
139
|
+
{:else}
|
|
140
|
+
-
|
|
141
|
+
{/if}
|
|
142
|
+
{:else if columnDef?.type === 'url'}
|
|
143
|
+
{@const value = getUrlCellValue(cell.getValue())}
|
|
144
|
+
{#if value}
|
|
145
|
+
<button
|
|
146
|
+
type="button"
|
|
147
|
+
class={cn(
|
|
148
|
+
'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',
|
|
149
|
+
justifyClass(columnDef.align)
|
|
150
|
+
)}
|
|
151
|
+
onclick={() => openUrlCell(value)}
|
|
152
|
+
>
|
|
153
|
+
<PhArrowSquareOut class="size-3.5 shrink-0" />
|
|
154
|
+
</button>
|
|
155
|
+
{:else}
|
|
156
|
+
-
|
|
157
|
+
{/if}
|
|
158
|
+
{:else}
|
|
159
|
+
<FlexRender content={cell.column.columnDef.cell} context={cell.getContext()} />
|
|
160
|
+
{/if}
|
|
161
|
+
</td>
|
|
162
|
+
{/each}
|
|
163
|
+
</tr>
|
|
164
|
+
{/each}
|
|
165
|
+
{/if}
|
|
166
|
+
</tbody>
|
|
167
|
+
|
|
168
|
+
<style>
|
|
169
|
+
@import './data-table-checkbox.css';
|
|
170
|
+
</style>
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { Row, RowData } from '@tanstack/
|
|
2
|
-
import type {
|
|
1
|
+
import type { Row, RowData } from '@tanstack/table-core';
|
|
2
|
+
import type { DataTableInstance } from './data-table-utils';
|
|
3
3
|
declare function $$render<T extends RowData>(): {
|
|
4
4
|
props: {
|
|
5
|
-
rows: Row<
|
|
5
|
+
rows: Row<T>[];
|
|
6
6
|
scrollContainer: HTMLDivElement;
|
|
7
7
|
isRowSelectionEnabled: boolean;
|
|
8
8
|
table: DataTableInstance<T>;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
<script lang="ts" generics="T extends RowData">
|
|
2
|
-
import type { RowData } from '@tanstack/
|
|
2
|
+
import type { RowData } from '@tanstack/table-core';
|
|
3
3
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
4
|
import { cn, type ClassValue } from 'tailwind-variants';
|
|
5
|
-
import {
|
|
5
|
+
import type { DataTableInstance } from './data-table-utils';
|
|
6
6
|
import DataTableHead from './data-table-head.svelte';
|
|
7
7
|
import DataTableVirtualRows from './data-table-virtual-rows.svelte';
|
|
8
8
|
import {
|
|
9
9
|
getAllRowsSelectionState,
|
|
10
|
+
getReactiveTableState,
|
|
10
11
|
getSelectedRowCount,
|
|
11
12
|
tableSizeStyle
|
|
12
13
|
} from './data-table-utils';
|
|
@@ -32,27 +33,27 @@
|
|
|
32
33
|
|
|
33
34
|
let scrollContainerRef = $state<HTMLDivElement | undefined>(undefined);
|
|
34
35
|
|
|
35
|
-
const
|
|
36
|
-
function trackTableState() {
|
|
37
|
-
return tableStateKey;
|
|
38
|
-
}
|
|
39
|
-
|
|
36
|
+
const tableState = $derived(getReactiveTableState(table));
|
|
40
37
|
const rowModel = $derived.by(() => {
|
|
41
|
-
|
|
38
|
+
getReactiveTableState(table);
|
|
42
39
|
return table.getRowModel();
|
|
43
40
|
});
|
|
44
41
|
const headerGroups = $derived.by(() => {
|
|
45
|
-
|
|
42
|
+
getReactiveTableState(table);
|
|
46
43
|
return table.getHeaderGroups();
|
|
47
44
|
});
|
|
48
45
|
const isRowSelectionEnabled = $derived(Boolean(table.options.enableRowSelection));
|
|
49
46
|
const isMultiRowSelectionEnabled = $derived(table.options.enableMultiRowSelection !== false);
|
|
50
47
|
const headerGroupCount = $derived(headerGroups.length);
|
|
51
|
-
const allRowsSelectionState = $derived(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
48
|
+
const allRowsSelectionState = $derived.by(() => {
|
|
49
|
+
getReactiveTableState(table);
|
|
50
|
+
return getAllRowsSelectionState(table);
|
|
51
|
+
});
|
|
52
|
+
const selectedRowCount = $derived.by(() => {
|
|
53
|
+
getReactiveTableState(table);
|
|
54
|
+
return getSelectedRowCount(table);
|
|
55
|
+
});
|
|
56
|
+
const isColumnResizing = $derived(tableState.columnSizingInfo.isResizingColumn !== false);
|
|
56
57
|
</script>
|
|
57
58
|
|
|
58
59
|
<div
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { RowData } from '@tanstack/
|
|
1
|
+
import type { RowData } from '@tanstack/table-core';
|
|
2
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
3
|
import { type ClassValue } from 'tailwind-variants';
|
|
4
|
-
import {
|
|
4
|
+
import type { DataTableInstance } from './data-table-utils';
|
|
5
5
|
declare function $$render<T extends RowData>(): {
|
|
6
6
|
props: Omit<HTMLAttributes<HTMLDivElement>, "class"> & {
|
|
7
7
|
table: DataTableInstance<T>;
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
<script lang="ts" generics="T extends RowData">
|
|
2
|
-
import {
|
|
3
|
-
import type { RowData } from '@tanstack/svelte-table';
|
|
2
|
+
import type { RowData } from '@tanstack/table-core';
|
|
4
3
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
5
4
|
import { cn, type ClassValue } from 'tailwind-variants';
|
|
6
5
|
import { PhArrowSquareOut, PhCheck, PhX } from '../../icons';
|
|
7
|
-
import
|
|
8
|
-
import { type DataTableInstance } from './create-table';
|
|
6
|
+
import type { DataTableInstance } from './data-table-utils';
|
|
9
7
|
import DataTableHead from './data-table-head.svelte';
|
|
8
|
+
import FlexRender from './flex-render.svelte';
|
|
10
9
|
import {
|
|
11
10
|
alignClass,
|
|
12
11
|
columnSizeStyle,
|
|
13
|
-
getAllRowsSelectionState,
|
|
14
12
|
getBooleanCellValue,
|
|
15
13
|
getColumnMeta,
|
|
16
14
|
getPinningStyle,
|
|
17
|
-
|
|
15
|
+
getAllRowsSelectionState,
|
|
16
|
+
getReactiveCells,
|
|
17
|
+
getReactiveTableState,
|
|
18
18
|
getSelectedRowCount,
|
|
19
19
|
getUrlCellValue,
|
|
20
20
|
justifyClass,
|
|
@@ -42,9 +42,19 @@
|
|
|
42
42
|
...rest
|
|
43
43
|
}: Props = $props();
|
|
44
44
|
|
|
45
|
-
const
|
|
46
|
-
const
|
|
47
|
-
|
|
45
|
+
const tableState = $derived(getReactiveTableState(table));
|
|
46
|
+
const rowModel = $derived.by(() => {
|
|
47
|
+
getReactiveTableState(table);
|
|
48
|
+
return table.getRowModel();
|
|
49
|
+
});
|
|
50
|
+
const headerGroups = $derived.by(() => {
|
|
51
|
+
getReactiveTableState(table);
|
|
52
|
+
return table.getHeaderGroups();
|
|
53
|
+
});
|
|
54
|
+
const visibleLeafColumns = $derived.by(() => {
|
|
55
|
+
getReactiveTableState(table);
|
|
56
|
+
return table.getVisibleLeafColumns();
|
|
57
|
+
});
|
|
48
58
|
const growColumn = $derived(visibleLeafColumns.find((col) => getColumnMeta(col.columnDef)?.grow));
|
|
49
59
|
const hasGrowColumn = $derived(growColumn !== undefined);
|
|
50
60
|
const visibleColumnCount = $derived(visibleLeafColumns.length);
|
|
@@ -53,11 +63,15 @@
|
|
|
53
63
|
const tableColumnCount = $derived(visibleColumnCount + (isRowSelectionEnabled ? 1 : 0));
|
|
54
64
|
const renderedColumnCount = $derived(tableColumnCount + 1);
|
|
55
65
|
const headerGroupCount = $derived(headerGroups.length);
|
|
56
|
-
const allRowsSelectionState = $derived(
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const
|
|
66
|
+
const allRowsSelectionState = $derived.by(() => {
|
|
67
|
+
getReactiveTableState(table);
|
|
68
|
+
return getAllRowsSelectionState(table);
|
|
69
|
+
});
|
|
70
|
+
const selectedRowCount = $derived.by(() => {
|
|
71
|
+
getReactiveTableState(table);
|
|
72
|
+
return getSelectedRowCount(table);
|
|
73
|
+
});
|
|
74
|
+
const isColumnResizing = $derived(tableState.columnSizingInfo.isResizingColumn !== false);
|
|
61
75
|
</script>
|
|
62
76
|
|
|
63
77
|
<div
|
|
@@ -105,7 +119,7 @@
|
|
|
105
119
|
/>
|
|
106
120
|
<tbody>
|
|
107
121
|
{#each rowModel.rows as row (row.id)}
|
|
108
|
-
{@const rowSelected =
|
|
122
|
+
{@const rowSelected = getReactiveTableState(table).rowSelection[row.id] === true}
|
|
109
123
|
<tr
|
|
110
124
|
class={cn(
|
|
111
125
|
'group/row',
|
|
@@ -122,17 +136,17 @@
|
|
|
122
136
|
class="border-b border-surface-2 bg-(--row-bg) px-3 py-2 text-center align-middle group-last/row:border-b-0"
|
|
123
137
|
style="position: sticky; left: 0; z-index: 1"
|
|
124
138
|
>
|
|
125
|
-
<
|
|
126
|
-
|
|
139
|
+
<input
|
|
140
|
+
type="checkbox"
|
|
127
141
|
aria-label="Select row"
|
|
128
|
-
class="mx-auto size-4"
|
|
142
|
+
class="table-checkbox mx-auto block size-4"
|
|
129
143
|
checked={rowSelected}
|
|
130
144
|
disabled={!row.getCanSelect()}
|
|
131
|
-
|
|
145
|
+
onchange={(e) => row.toggleSelected(e.currentTarget.checked)}
|
|
132
146
|
/>
|
|
133
147
|
</td>
|
|
134
148
|
{/if}
|
|
135
|
-
{#each row
|
|
149
|
+
{#each getReactiveCells(row, getReactiveTableState(table).columnVisibility) as cell (cell.id)}
|
|
136
150
|
{@const columnDef = getColumnMeta(cell.column.columnDef)}
|
|
137
151
|
<td
|
|
138
152
|
class={cn(
|
|
@@ -140,7 +154,7 @@
|
|
|
140
154
|
alignClass(columnDef?.align),
|
|
141
155
|
cell.column.getIsPinned() && 'bg-(--row-bg)'
|
|
142
156
|
)}
|
|
143
|
-
style={getPinningStyle(cell.column, false, isRowSelectionEnabled)}
|
|
157
|
+
style={getPinningStyle(cell.column, table, false, isRowSelectionEnabled)}
|
|
144
158
|
>
|
|
145
159
|
{#if columnDef?.type === 'boolean'}
|
|
146
160
|
{@const value = getBooleanCellValue(cell.getValue())}
|
|
@@ -180,7 +194,7 @@
|
|
|
180
194
|
-
|
|
181
195
|
{/if}
|
|
182
196
|
{:else}
|
|
183
|
-
<FlexRender {cell} />
|
|
197
|
+
<FlexRender content={cell.column.columnDef.cell} context={cell.getContext()} />
|
|
184
198
|
{/if}
|
|
185
199
|
</td>
|
|
186
200
|
{/each}
|
|
@@ -208,3 +222,7 @@
|
|
|
208
222
|
{/if}
|
|
209
223
|
</div>
|
|
210
224
|
</div>
|
|
225
|
+
|
|
226
|
+
<style>
|
|
227
|
+
@import './data-table-checkbox.css';
|
|
228
|
+
</style>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { RowData } from '@tanstack/
|
|
1
|
+
import type { RowData } from '@tanstack/table-core';
|
|
2
2
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
3
|
import { type ClassValue } from 'tailwind-variants';
|
|
4
|
-
import {
|
|
4
|
+
import type { DataTableInstance } from './data-table-utils';
|
|
5
5
|
declare function $$render<T extends RowData>(): {
|
|
6
6
|
props: Omit<HTMLAttributes<HTMLDivElement>, "class"> & {
|
|
7
7
|
table: DataTableInstance<T>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<script
|
|
2
|
+
lang="ts"
|
|
3
|
+
generics="TData, TValue, TContext extends HeaderContext<TData, TValue> | CellContext<TData, TValue>"
|
|
4
|
+
>
|
|
5
|
+
import type { CellContext, ColumnDefTemplate, HeaderContext } from '@tanstack/table-core';
|
|
6
|
+
import { RenderComponentConfig, RenderSnippetConfig } from './render-helpers.js';
|
|
7
|
+
|
|
8
|
+
type Props = {
|
|
9
|
+
content?:
|
|
10
|
+
| (TContext extends HeaderContext<TData, TValue>
|
|
11
|
+
? ColumnDefTemplate<HeaderContext<TData, TValue>>
|
|
12
|
+
: TContext extends CellContext<TData, TValue>
|
|
13
|
+
? ColumnDefTemplate<CellContext<TData, TValue>>
|
|
14
|
+
: never)
|
|
15
|
+
| undefined;
|
|
16
|
+
context: TContext;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
let { content, context }: Props = $props();
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
{#if typeof content === 'string'}
|
|
23
|
+
{content}
|
|
24
|
+
{:else if content instanceof Function}
|
|
25
|
+
{@const result = content(context as never)}
|
|
26
|
+
{#if result instanceof RenderComponentConfig}
|
|
27
|
+
{@const { component: Component, props } = result}
|
|
28
|
+
<Component {...props} />
|
|
29
|
+
{:else if result instanceof RenderSnippetConfig}
|
|
30
|
+
{@const { snippet, params } = result}
|
|
31
|
+
{@render snippet(params)}
|
|
32
|
+
{:else}
|
|
33
|
+
{result}
|
|
34
|
+
{/if}
|
|
35
|
+
{/if}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { CellContext, ColumnDefTemplate, HeaderContext } from '@tanstack/table-core';
|
|
2
|
+
declare function $$render<TData, TValue, TContext extends HeaderContext<TData, TValue> | CellContext<TData, TValue>>(): {
|
|
3
|
+
props: {
|
|
4
|
+
content?: (TContext extends HeaderContext<TData, TValue> ? ColumnDefTemplate<HeaderContext<TData, TValue>> : TContext extends CellContext<TData, TValue> ? ColumnDefTemplate<CellContext<TData, TValue>> : never) | undefined;
|
|
5
|
+
context: TContext;
|
|
6
|
+
};
|
|
7
|
+
exports: {};
|
|
8
|
+
bindings: "";
|
|
9
|
+
slots: {};
|
|
10
|
+
events: {};
|
|
11
|
+
};
|
|
12
|
+
declare class __sveltets_Render<TData, TValue, TContext extends HeaderContext<TData, TValue> | CellContext<TData, TValue>> {
|
|
13
|
+
props(): ReturnType<typeof $$render<TData, TValue, TContext>>['props'];
|
|
14
|
+
events(): ReturnType<typeof $$render<TData, TValue, TContext>>['events'];
|
|
15
|
+
slots(): ReturnType<typeof $$render<TData, TValue, TContext>>['slots'];
|
|
16
|
+
bindings(): "";
|
|
17
|
+
exports(): {};
|
|
18
|
+
}
|
|
19
|
+
interface $$IsomorphicComponent {
|
|
20
|
+
new <TData, TValue, TContext extends HeaderContext<TData, TValue> | CellContext<TData, TValue>>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<TData, TValue, TContext>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<TData, TValue, TContext>['props']>, ReturnType<__sveltets_Render<TData, TValue, TContext>['events']>, ReturnType<__sveltets_Render<TData, TValue, TContext>['slots']>> & {
|
|
21
|
+
$$bindings?: ReturnType<__sveltets_Render<TData, TValue, TContext>['bindings']>;
|
|
22
|
+
} & ReturnType<__sveltets_Render<TData, TValue, TContext>['exports']>;
|
|
23
|
+
<TData, TValue, TContext extends HeaderContext<TData, TValue> | CellContext<TData, TValue>>(internal: unknown, props: ReturnType<__sveltets_Render<TData, TValue, TContext>['props']> & {}): ReturnType<__sveltets_Render<TData, TValue, TContext>['exports']>;
|
|
24
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any, any, any>['bindings']>;
|
|
25
|
+
}
|
|
26
|
+
declare const FlexRender: $$IsomorphicComponent;
|
|
27
|
+
type FlexRender<TData, TValue, TContext extends HeaderContext<TData, TValue> | CellContext<TData, TValue>> = InstanceType<typeof FlexRender<TData, TValue, TContext>>;
|
|
28
|
+
export default FlexRender;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export { createDataTableColumnHelper } from './column-helper';
|
|
2
|
-
export { createTable } from './create-table';
|
|
2
|
+
export { createTable } from './create-table.svelte';
|
|
3
|
+
export { renderComponent, renderSnippet } from './render-helpers';
|
|
4
|
+
export { default as FlexRender } from './flex-render.svelte';
|
|
3
5
|
export { default as Root } from './data-table.svelte';
|
|
4
6
|
export { default as Toolbar } from './data-table-toolbar.svelte';
|
|
5
7
|
export { default as Title } from './data-table-title.svelte';
|
|
6
8
|
export { default as ColumnVisibility } from './data-table-column-visibility.svelte';
|
|
7
9
|
export { default as ColumnFilter } from './data-table-column-filter.svelte';
|
|
8
|
-
export type { CreateDataTableOptions,
|
|
10
|
+
export type { CreateDataTableOptions, DataTableInstance } from './create-table.svelte';
|
|
9
11
|
export type { DataTableAlign, DataTableAccessorFnColumn, DataTableAccessorKeyColumn, DataTableColumn, DataTableColumnBase, DataTableColumnOptions, DataTableColumnType, DataTableCellPropsResolver, DataTableCellRenderProps, DataTableGroupColumn, DataTableLeafColumnBase, DataTableLeafColumn } from './types';
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { createDataTableColumnHelper } from './column-helper';
|
|
2
|
-
export { createTable } from './create-table';
|
|
2
|
+
export { createTable } from './create-table.svelte';
|
|
3
|
+
export { renderComponent, renderSnippet } from './render-helpers';
|
|
4
|
+
export { default as FlexRender } from './flex-render.svelte';
|
|
3
5
|
export { default as Root } from './data-table.svelte';
|
|
4
6
|
export { default as Toolbar } from './data-table-toolbar.svelte';
|
|
5
7
|
export { default as Title } from './data-table-title.svelte';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Component, ComponentProps, Snippet } from 'svelte';
|
|
2
|
+
export declare class RenderComponentConfig<TComponent extends Component> {
|
|
3
|
+
component: TComponent;
|
|
4
|
+
props: ComponentProps<TComponent> | Record<string, never>;
|
|
5
|
+
constructor(component: TComponent, props?: ComponentProps<TComponent> | Record<string, never>);
|
|
6
|
+
}
|
|
7
|
+
export declare class RenderSnippetConfig<TProps> {
|
|
8
|
+
snippet: Snippet<[TProps]>;
|
|
9
|
+
params: TProps;
|
|
10
|
+
constructor(snippet: Snippet<[TProps]>, params: TProps);
|
|
11
|
+
}
|
|
12
|
+
export declare function renderComponent<T extends Component<any>, Props extends ComponentProps<T>>(component: T, props?: Props): RenderComponentConfig<T>;
|
|
13
|
+
export declare function renderSnippet<TProps>(snippet: Snippet<[TProps]>, params?: TProps): RenderSnippetConfig<TProps>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export class RenderComponentConfig {
|
|
2
|
+
component;
|
|
3
|
+
props;
|
|
4
|
+
constructor(component, props = {}) {
|
|
5
|
+
this.component = component;
|
|
6
|
+
this.props = props;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export class RenderSnippetConfig {
|
|
10
|
+
snippet;
|
|
11
|
+
params;
|
|
12
|
+
constructor(snippet, params) {
|
|
13
|
+
this.snippet = snippet;
|
|
14
|
+
this.params = params;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
+
export function renderComponent(component, props = {}) {
|
|
19
|
+
return new RenderComponentConfig(component, props);
|
|
20
|
+
}
|
|
21
|
+
export function renderSnippet(snippet, params = {}) {
|
|
22
|
+
return new RenderSnippetConfig(snippet, params);
|
|
23
|
+
}
|