@emamid/svelte-data-table 0.0.22 → 1.0.2
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/DataTable.svelte +303 -239
- package/dist/DataTable.svelte.d.ts +30 -60
- package/dist/DataTableDataCell.svelte +157 -90
- package/dist/DataTableDataCell.svelte.d.ts +18 -27
- package/dist/DataTableHeaderCell.svelte +63 -21
- package/dist/DataTableHeaderCell.svelte.d.ts +9 -23
- package/dist/DataTableIcon.svelte +25 -0
- package/dist/DataTableIcon.svelte.d.ts +9 -0
- package/dist/DataTableRow.svelte +150 -80
- package/dist/DataTableRow.svelte.d.ts +26 -34
- package/dist/cells/Actions.d.ts +1 -1
- package/dist/cells/Actions.js +10 -11
- package/dist/cells/ActionsCell.svelte +56 -33
- package/dist/cells/ActionsCell.svelte.d.ts +9 -47
- package/dist/cells/ButtonCell.svelte +58 -16
- package/dist/cells/ButtonCell.svelte.d.ts +11 -20
- package/dist/cells/CheckboxCell.svelte +72 -19
- package/dist/cells/CheckboxCell.svelte.d.ts +11 -22
- package/dist/cells/InputCell.svelte +93 -48
- package/dist/cells/InputCell.svelte.d.ts +14 -25
- package/dist/cells/MultiSelectCell.svelte +85 -25
- package/dist/cells/MultiSelectCell.svelte.d.ts +15 -26
- package/dist/cells/NumberInputCell.svelte +90 -44
- package/dist/cells/NumberInputCell.svelte.d.ts +13 -24
- package/dist/cells/RadioCell.svelte +66 -0
- package/dist/cells/RadioCell.svelte.d.ts +12 -0
- package/dist/cells/RangeCell.svelte +66 -17
- package/dist/cells/RangeCell.svelte.d.ts +13 -22
- package/dist/cells/SelectCell.svelte +87 -25
- package/dist/cells/SelectCell.svelte.d.ts +15 -26
- package/dist/cells/SpinCell.svelte +91 -42
- package/dist/cells/SpinCell.svelte.d.ts +13 -28
- package/dist/cells/TabWrapper.svelte +23 -21
- package/dist/cells/TabWrapper.svelte.d.ts +10 -22
- package/dist/cells/index.d.ts +3 -5
- package/dist/cells/index.js +3 -5
- package/dist/common.d.ts +199 -53
- package/dist/common.js +30 -11
- package/dist/index.d.ts +8 -2
- package/dist/index.js +8 -1
- package/dist/themes/active.d.ts +4 -0
- package/dist/themes/active.js +12 -0
- package/dist/themes/daisyUI.d.ts +2 -0
- package/dist/themes/daisyUI.js +47 -0
- package/dist/themes/default.d.ts +2 -0
- package/dist/themes/default.js +57 -0
- package/dist/themes/iconify.d.ts +2 -0
- package/dist/themes/iconify.js +33 -0
- package/dist/themes/index.d.ts +4 -0
- package/dist/themes/index.js +4 -0
- package/package.json +28 -32
- package/dist/DataTable.doc.d.ts +0 -81
- package/dist/DataTable.doc.js +0 -81
- package/dist/cells/ActionsCell.doc.d.ts +0 -28
- package/dist/cells/ActionsCell.doc.js +0 -28
- package/dist/cells/ButtonCell.doc.d.ts +0 -9
- package/dist/cells/ButtonCell.doc.js +0 -9
- package/dist/cells/CheckboxCell.doc.d.ts +0 -6
- package/dist/cells/CheckboxCell.doc.js +0 -6
- package/dist/cells/InputCell.doc.d.ts +0 -6
- package/dist/cells/InputCell.doc.js +0 -6
- package/dist/cells/MultiSelectCell.doc.d.ts +0 -8
- package/dist/cells/MultiSelectCell.doc.js +0 -8
- package/dist/cells/NumberInputCell.doc.d.ts +0 -6
- package/dist/cells/NumberInputCell.doc.js +0 -6
- package/dist/cells/RangeCell.doc.d.ts +0 -7
- package/dist/cells/RangeCell.doc.js +0 -7
- package/dist/cells/RatingCell.doc.d.ts +0 -7
- package/dist/cells/RatingCell.doc.js +0 -7
- package/dist/cells/RatingCell.svelte +0 -13
- package/dist/cells/RatingCell.svelte.d.ts +0 -22
- package/dist/cells/SelectCell.doc.d.ts +0 -8
- package/dist/cells/SelectCell.doc.js +0 -8
- package/dist/cells/SpinCell.doc.d.ts +0 -13
- package/dist/cells/SpinCell.doc.js +0 -13
- package/dist/cells/TabWrapper.doc.d.ts +0 -5
- package/dist/cells/TabWrapper.doc.js +0 -5
- package/dist/cells/ToggleCell.doc.d.ts +0 -6
- package/dist/cells/ToggleCell.doc.js +0 -6
- package/dist/cells/ToggleCell.svelte +0 -21
- package/dist/cells/ToggleCell.svelte.d.ts +0 -23
package/dist/DataTable.svelte
CHANGED
|
@@ -1,230 +1,291 @@
|
|
|
1
|
-
<script
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { setContext } from 'svelte';
|
|
3
|
+
|
|
4
|
+
import type {
|
|
5
|
+
ActionEvent,
|
|
6
|
+
ColumnConfig,
|
|
7
|
+
DataCellChangedEvent,
|
|
8
|
+
DataCellDragEvent,
|
|
9
|
+
DataCellDropEvent,
|
|
10
|
+
DataCellEvent,
|
|
11
|
+
DataTableContext,
|
|
12
|
+
DataTableTheme,
|
|
13
|
+
EnterAction,
|
|
14
|
+
GetItemKeyFunction,
|
|
15
|
+
HeaderEvent,
|
|
16
|
+
RowBoolean,
|
|
17
|
+
RowClassFunction,
|
|
18
|
+
RowDragEvent,
|
|
19
|
+
RowDropBoolean,
|
|
20
|
+
RowDropEvent,
|
|
21
|
+
RowEvent,
|
|
22
|
+
SortFunction,
|
|
23
|
+
} from './common';
|
|
24
|
+
|
|
25
|
+
import {
|
|
26
|
+
dataTableContextName,
|
|
27
|
+
getColumnID,
|
|
28
|
+
joinPartClasses,
|
|
29
|
+
} from './common';
|
|
30
|
+
|
|
31
|
+
import { activeTheme } from './themes';
|
|
32
|
+
|
|
33
|
+
import DataTableHeaderCell from './DataTableHeaderCell.svelte';
|
|
34
|
+
import DataTableRow from './DataTableRow.svelte';
|
|
35
|
+
|
|
36
|
+
interface Props {
|
|
37
|
+
allowRowDrag?: RowBoolean;
|
|
38
|
+
allowRowDrop?: RowDropBoolean;
|
|
39
|
+
columns?: ColumnConfig[];
|
|
40
|
+
enterAction?: EnterAction;
|
|
41
|
+
itemKey?: string | null;
|
|
42
|
+
items?: any[];
|
|
43
|
+
onaction?: (event: ActionEvent) => void;
|
|
44
|
+
onbutton?: (event: DataCellEvent) => void;
|
|
45
|
+
oncellchanged?: (event: DataCellChangedEvent) => void;
|
|
46
|
+
oncellclick?: (event: DataCellEvent) => void;
|
|
47
|
+
oncelldragstart?: (event: DataCellDragEvent) => void;
|
|
48
|
+
oncelldropped?: (event: DataCellDropEvent) => void;
|
|
49
|
+
onenterpressed?: (event: DataCellEvent) => void;
|
|
50
|
+
onheaderclick?: (event: HeaderEvent) => void;
|
|
51
|
+
onnexttab?: (event: DataCellEvent) => void;
|
|
52
|
+
onprevtab?: (event: DataCellEvent) => void;
|
|
53
|
+
onrowclick?: (event: RowEvent) => void;
|
|
54
|
+
onrowdragstart?: (event: RowDragEvent) => void;
|
|
55
|
+
onrowdropped?: (event: RowDropEvent) => void;
|
|
56
|
+
reverseSort?: boolean;
|
|
57
|
+
sortColumnID?: string | null;
|
|
58
|
+
sortFunction?: SortFunction;
|
|
59
|
+
sortKey?: string;
|
|
60
|
+
theme?: DataTableTheme;
|
|
61
|
+
trClassGetter?: RowClassFunction;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let {
|
|
65
|
+
allowRowDrag = false,
|
|
66
|
+
allowRowDrop = !!allowRowDrag,
|
|
67
|
+
columns = [],
|
|
68
|
+
enterAction = 'next',
|
|
69
|
+
itemKey = null,
|
|
70
|
+
items = [],
|
|
71
|
+
onaction,
|
|
72
|
+
onbutton,
|
|
73
|
+
oncellchanged,
|
|
74
|
+
oncellclick,
|
|
75
|
+
oncelldragstart,
|
|
76
|
+
oncelldropped,
|
|
77
|
+
onenterpressed,
|
|
78
|
+
onheaderclick,
|
|
79
|
+
onnexttab,
|
|
80
|
+
onprevtab,
|
|
81
|
+
onrowclick,
|
|
82
|
+
onrowdragstart,
|
|
83
|
+
onrowdropped,
|
|
84
|
+
reverseSort = $bindable(false),
|
|
85
|
+
sortColumnID = $bindable(null),
|
|
86
|
+
sortFunction = $bindable(undefined),
|
|
87
|
+
sortKey = $bindable(''),
|
|
88
|
+
theme,
|
|
89
|
+
trClassGetter,
|
|
90
|
+
}: Props = $props();
|
|
91
|
+
|
|
92
|
+
let sortedItems = $derived.by(() => {
|
|
93
|
+
let tempItems = sortFunction
|
|
94
|
+
? items.toSorted(sortFunction)
|
|
95
|
+
: sortKey
|
|
96
|
+
? items.toSorted(sortBySortKey)
|
|
97
|
+
: [...items];
|
|
98
|
+
if (reverseSort) {
|
|
99
|
+
return tempItems.toReversed();
|
|
100
|
+
}
|
|
101
|
+
return tempItems;
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
let focusedColumnKeyID: any = $state(null);
|
|
105
|
+
let focusedItemKey: any = $state(null);
|
|
106
|
+
|
|
107
|
+
let context = $state<DataTableContext>({
|
|
108
|
+
// svelte-ignore state_referenced_locally
|
|
109
|
+
items,
|
|
110
|
+
// svelte-ignore state_referenced_locally
|
|
111
|
+
theme,
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
setContext(dataTableContextName, context);
|
|
115
|
+
|
|
116
|
+
const sortBySortKey: SortFunction = (a: any, b: any) => {
|
|
117
|
+
let aValue = a[sortKey];
|
|
118
|
+
let bValue = b[sortKey];
|
|
119
|
+
|
|
120
|
+
if (aValue === bValue) {
|
|
121
|
+
return 0;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (typeof aValue === 'string' && typeof bValue === 'string') {
|
|
125
|
+
return aValue.localeCompare(bValue);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (typeof aValue === 'number' && typeof bValue === 'number') {
|
|
129
|
+
return aValue - bValue;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (typeof aValue === 'number' || typeof bValue === 'number') {
|
|
133
|
+
return (aValue || 0) - (bValue || 0);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (typeof aValue === 'string' || typeof bValue === 'string') {
|
|
137
|
+
return (aValue || '').localeCompare(bValue || '');
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return JSON.stringify(aValue).localeCompare(JSON.stringify(bValue));
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const getItemKey: GetItemKeyFunction = (item?: any) =>
|
|
144
|
+
item ? (itemKey ? item[itemKey] || null : items.indexOf(item).toString()) : null;
|
|
145
|
+
|
|
146
|
+
const getClasses = (element: string) => joinPartClasses(
|
|
147
|
+
'table',
|
|
148
|
+
element, [
|
|
149
|
+
activeTheme,
|
|
150
|
+
theme,
|
|
151
|
+
],
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
const internalColumns: ColumnConfig[] = $derived(columns.map((column) => {
|
|
155
|
+
return {
|
|
156
|
+
...column,
|
|
157
|
+
sortKey: column.sortKey || column.key,
|
|
158
|
+
id: column.id || column.key,
|
|
159
|
+
};
|
|
160
|
+
}));
|
|
161
|
+
|
|
162
|
+
const focusableColumns = $derived(internalColumns.filter((column) => column.canFocus));
|
|
163
|
+
|
|
164
|
+
const prevTab = (event: DataCellEvent) => {
|
|
165
|
+
const { item, column } = event;
|
|
166
|
+
let nextColumn: ColumnConfig | null = null;
|
|
167
|
+
let nextItem: any | null = null;
|
|
168
|
+
if (column === focusableColumns[0]) {
|
|
169
|
+
if (item !== sortedItems[0]) {
|
|
170
|
+
nextColumn = focusableColumns[focusableColumns.length - 1];
|
|
171
|
+
nextItem = sortedItems[sortedItems.indexOf(item) - 1];
|
|
172
|
+
}
|
|
173
|
+
} else {
|
|
174
|
+
nextColumn = focusableColumns[focusableColumns.indexOf(column) - 1];
|
|
175
|
+
nextItem = item;
|
|
176
|
+
}
|
|
177
|
+
focusedColumnKeyID = getColumnID(nextColumn);
|
|
178
|
+
focusedItemKey = getItemKey(nextItem);
|
|
179
|
+
onprevtab?.(event);
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
const nextTab = (event: DataCellEvent) => {
|
|
183
|
+
const { item, column } = event;
|
|
184
|
+
let nextColumn: ColumnConfig | null = null;
|
|
185
|
+
let nextItem: any | null = null;
|
|
186
|
+
if (column === focusableColumns.at(-1)) {
|
|
187
|
+
if (item !== sortedItems.at(-1)) {
|
|
188
|
+
nextColumn = focusableColumns[0];
|
|
189
|
+
nextItem = sortedItems[sortedItems.indexOf(item) + 1];
|
|
190
|
+
}
|
|
191
|
+
} else {
|
|
192
|
+
nextColumn = focusableColumns[focusableColumns.indexOf(column) + 1];
|
|
193
|
+
nextItem = item;
|
|
194
|
+
}
|
|
195
|
+
focusedColumnKeyID = getColumnID(nextColumn);
|
|
196
|
+
focusedItemKey = getItemKey(nextItem);
|
|
197
|
+
onnexttab?.(event);
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
const enterPressed = (event: DataCellEvent) => {
|
|
201
|
+
if (enterAction === 'stay') {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
if (enterAction === 'next') {
|
|
205
|
+
return nextTab(event);
|
|
206
|
+
}
|
|
207
|
+
const { item } = event;
|
|
208
|
+
const itemIndex = sortedItems.indexOf(item);
|
|
209
|
+
if (itemIndex !== sortedItems.length - 1) {
|
|
210
|
+
focusedItemKey = getItemKey(sortedItems[itemIndex + 1]);
|
|
211
|
+
}
|
|
212
|
+
onenterpressed?.(event);
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
const cellClicked = (event: DataCellEvent) => {
|
|
216
|
+
const { column, item } = event;
|
|
217
|
+
focusedColumnKeyID = null;
|
|
218
|
+
focusedItemKey = null;
|
|
219
|
+
if (column.canFocus) {
|
|
220
|
+
focusedColumnKeyID = getColumnID(column);
|
|
221
|
+
focusedItemKey = getItemKey(item);
|
|
222
|
+
}
|
|
223
|
+
oncellclick?.({ column, item });
|
|
224
|
+
onrowclick?.({ item });
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
const cellDragEnd = (_event: DataCellDragEvent) => {
|
|
228
|
+
context.draggedColumn = undefined;
|
|
229
|
+
context.draggedItem = undefined;
|
|
230
|
+
context.dragType = undefined;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const cellDragStart = (event: DataCellDragEvent) => {
|
|
234
|
+
context.draggedColumn = event.sourceColumn;
|
|
235
|
+
context.draggedItem = event.sourceItem;
|
|
236
|
+
context.dragType = 'cell';
|
|
237
|
+
oncelldragstart?.(event);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const headerClicked = (column: ColumnConfig) => {
|
|
241
|
+
if (column.id && column.canSort) {
|
|
242
|
+
if (sortColumnID === column.id) {
|
|
243
|
+
reverseSort = !reverseSort;
|
|
244
|
+
} else {
|
|
245
|
+
reverseSort = false;
|
|
246
|
+
sortColumnID = column.id;
|
|
247
|
+
sortKey = column.sortKey || '';
|
|
248
|
+
sortFunction = column.sortFunction;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
onheaderclick?.({ column, sortColumnID, sortKey, sortFunction, reverseSort });
|
|
252
|
+
} else {
|
|
253
|
+
onheaderclick?.({ column });
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
const rowDragEnd = (_event: RowDragEvent) => {
|
|
258
|
+
context.dragType = undefined;
|
|
259
|
+
context.draggedItem = undefined;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const rowDragStart = (event: RowDragEvent) => {
|
|
263
|
+
context.draggedColumn = undefined;
|
|
264
|
+
context.draggedItem = event.sourceItem;
|
|
265
|
+
context.dragType = 'row';
|
|
266
|
+
onrowdragstart?.(event);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
let tableClass = $derived(getClasses('table'));
|
|
270
|
+
let theadClass = $derived(getClasses('thead'));
|
|
271
|
+
let theadTRClass = $derived(getClasses('theadTR'));
|
|
272
|
+
let tbodyClass = $derived(getClasses('tbody'));
|
|
211
273
|
</script>
|
|
212
274
|
|
|
213
|
-
<
|
|
214
|
-
<
|
|
215
|
-
{
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
<TableBody {tableBodyClass}>
|
|
275
|
+
<table class={tableClass}>
|
|
276
|
+
<thead class={theadClass}>
|
|
277
|
+
<tr class={theadTRClass}>
|
|
278
|
+
{#each internalColumns as column}
|
|
279
|
+
<DataTableHeaderCell
|
|
280
|
+
{column}
|
|
281
|
+
isSorted={!!sortColumnID && getColumnID(column) === sortColumnID}
|
|
282
|
+
{reverseSort}
|
|
283
|
+
onclick={() => headerClicked(column)}
|
|
284
|
+
/>
|
|
285
|
+
{/each}
|
|
286
|
+
</tr>
|
|
287
|
+
</thead>
|
|
288
|
+
<tbody class={tbodyClass}>
|
|
228
289
|
{#each sortedItems as item}
|
|
229
290
|
{@const isRowFocused = !!focusedItemKey && focusedItemKey === getItemKey(item)}
|
|
230
291
|
<DataTableRow
|
|
@@ -232,21 +293,24 @@ const headerClicked = (column) => {
|
|
|
232
293
|
{allowRowDrop}
|
|
233
294
|
columns={internalColumns}
|
|
234
295
|
{focusedColumnKeyID}
|
|
235
|
-
{getTRClass}
|
|
236
296
|
{isRowFocused}
|
|
237
297
|
{item}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
298
|
+
{onaction}
|
|
299
|
+
{onbutton}
|
|
300
|
+
{oncellchanged}
|
|
301
|
+
oncellclick={cellClicked}
|
|
302
|
+
oncelldragend={cellDragEnd}
|
|
303
|
+
oncelldragstart={cellDragStart}
|
|
304
|
+
{oncelldropped}
|
|
305
|
+
onenterpressed={enterPressed}
|
|
306
|
+
onnexttab={nextTab}
|
|
307
|
+
onprevtab={prevTab}
|
|
308
|
+
{onrowclick}
|
|
309
|
+
ondragend={rowDragEnd}
|
|
310
|
+
ondragstart={rowDragStart}
|
|
311
|
+
ondropped={onrowdropped}
|
|
312
|
+
{trClassGetter}
|
|
249
313
|
/>
|
|
250
314
|
{/each}
|
|
251
|
-
</
|
|
252
|
-
</
|
|
315
|
+
</tbody>
|
|
316
|
+
</table>
|
|
@@ -1,61 +1,31 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
tdClassOverride?: string | undefined;
|
|
29
|
-
tdFocusedClassAppend?: string | undefined;
|
|
30
|
-
tdFocusedClassOverride?: string | undefined;
|
|
31
|
-
trClassAppend?: string | undefined;
|
|
32
|
-
trClassOverride?: string | undefined;
|
|
33
|
-
trClassGetter?: RowClassFunction | null | undefined;
|
|
34
|
-
striped?: boolean | undefined;
|
|
35
|
-
hoverable?: boolean | undefined;
|
|
36
|
-
noborder?: boolean | undefined;
|
|
37
|
-
shadow?: boolean | undefined;
|
|
38
|
-
color?: string | undefined;
|
|
39
|
-
customColor?: string | undefined;
|
|
40
|
-
};
|
|
41
|
-
events: {
|
|
42
|
-
action: any;
|
|
43
|
-
cellChanged: any;
|
|
44
|
-
cellDragStart: CustomEvent<any>;
|
|
45
|
-
cellDropped: CustomEvent<any>;
|
|
46
|
-
rowClicked: CustomEvent<any>;
|
|
47
|
-
rowDragStart: CustomEvent<any>;
|
|
48
|
-
rowDropped: CustomEvent<any>;
|
|
49
|
-
cellClicked: CustomEvent<any>;
|
|
50
|
-
headerClicked: CustomEvent<any>;
|
|
51
|
-
} & {
|
|
52
|
-
[evt: string]: CustomEvent<any>;
|
|
53
|
-
};
|
|
54
|
-
slots: {};
|
|
55
|
-
};
|
|
56
|
-
export type DataTableProps = typeof __propDef.props;
|
|
57
|
-
export type DataTableEvents = typeof __propDef.events;
|
|
58
|
-
export type DataTableSlots = typeof __propDef.slots;
|
|
59
|
-
export default class DataTable extends SvelteComponent<DataTableProps, DataTableEvents, DataTableSlots> {
|
|
1
|
+
import type { ActionEvent, ColumnConfig, DataCellChangedEvent, DataCellDragEvent, DataCellDropEvent, DataCellEvent, DataTableTheme, EnterAction, HeaderEvent, RowBoolean, RowClassFunction, RowDragEvent, RowDropBoolean, RowDropEvent, RowEvent, SortFunction } from './common';
|
|
2
|
+
interface Props {
|
|
3
|
+
allowRowDrag?: RowBoolean;
|
|
4
|
+
allowRowDrop?: RowDropBoolean;
|
|
5
|
+
columns?: ColumnConfig[];
|
|
6
|
+
enterAction?: EnterAction;
|
|
7
|
+
itemKey?: string | null;
|
|
8
|
+
items?: any[];
|
|
9
|
+
onaction?: (event: ActionEvent) => void;
|
|
10
|
+
onbutton?: (event: DataCellEvent) => void;
|
|
11
|
+
oncellchanged?: (event: DataCellChangedEvent) => void;
|
|
12
|
+
oncellclick?: (event: DataCellEvent) => void;
|
|
13
|
+
oncelldragstart?: (event: DataCellDragEvent) => void;
|
|
14
|
+
oncelldropped?: (event: DataCellDropEvent) => void;
|
|
15
|
+
onenterpressed?: (event: DataCellEvent) => void;
|
|
16
|
+
onheaderclick?: (event: HeaderEvent) => void;
|
|
17
|
+
onnexttab?: (event: DataCellEvent) => void;
|
|
18
|
+
onprevtab?: (event: DataCellEvent) => void;
|
|
19
|
+
onrowclick?: (event: RowEvent) => void;
|
|
20
|
+
onrowdragstart?: (event: RowDragEvent) => void;
|
|
21
|
+
onrowdropped?: (event: RowDropEvent) => void;
|
|
22
|
+
reverseSort?: boolean;
|
|
23
|
+
sortColumnID?: string | null;
|
|
24
|
+
sortFunction?: SortFunction;
|
|
25
|
+
sortKey?: string;
|
|
26
|
+
theme?: DataTableTheme;
|
|
27
|
+
trClassGetter?: RowClassFunction;
|
|
60
28
|
}
|
|
61
|
-
|
|
29
|
+
declare const DataTable: import("svelte").Component<Props, {}, "reverseSort" | "sortColumnID" | "sortFunction" | "sortKey">;
|
|
30
|
+
type DataTable = ReturnType<typeof DataTable>;
|
|
31
|
+
export default DataTable;
|