react-science 21.1.0 → 22.0.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/lib/components/info-panel/InfoPanel.js +2 -2
- package/lib/components/info-panel/InfoPanel.js.map +1 -1
- package/lib/components/logger/FifoLoggerDialog.d.ts.map +1 -1
- package/lib/components/logger/FifoLoggerDialog.js +2 -2
- package/lib/components/logger/FifoLoggerDialog.js.map +1 -1
- package/lib/components/table/default_table_cell.d.ts +2 -1
- package/lib/components/table/default_table_cell.d.ts.map +1 -1
- package/lib/components/table/default_table_cell.js.map +1 -1
- package/lib/components/table/index.d.ts +2 -2
- package/lib/components/table/index.d.ts.map +1 -1
- package/lib/components/table/index.js.map +1 -1
- package/lib/components/table/preview_table.d.ts +2 -1
- package/lib/components/table/preview_table.d.ts.map +1 -1
- package/lib/components/table/preview_table.js.map +1 -1
- package/lib/components/table/preview_table_context.d.ts +2 -2
- package/lib/components/table/reorder_rows/draggable_row_tr.d.ts +2 -1
- package/lib/components/table/reorder_rows/draggable_row_tr.d.ts.map +1 -1
- package/lib/components/table/reorder_rows/draggable_row_tr.js.map +1 -1
- package/lib/components/table/reorder_rows/item_data.d.ts +3 -2
- package/lib/components/table/reorder_rows/item_data.d.ts.map +1 -1
- package/lib/components/table/reorder_rows/item_data.js.map +1 -1
- package/lib/components/table/reorder_rows/item_order_context.d.ts +6 -5
- package/lib/components/table/reorder_rows/item_order_context.d.ts.map +1 -1
- package/lib/components/table/reorder_rows/item_order_context.js.map +1 -1
- package/lib/components/table/reorder_rows/item_order_provider.d.ts +6 -5
- package/lib/components/table/reorder_rows/item_order_provider.d.ts.map +1 -1
- package/lib/components/table/reorder_rows/item_order_provider.js +1 -4
- package/lib/components/table/reorder_rows/item_order_provider.js.map +1 -1
- package/lib/components/table/table_body.d.ts +2 -1
- package/lib/components/table/table_body.d.ts.map +1 -1
- package/lib/components/table/table_body.js +1 -2
- package/lib/components/table/table_body.js.map +1 -1
- package/lib/components/table/table_features.d.ts +15 -0
- package/lib/components/table/table_features.d.ts.map +1 -0
- package/lib/components/table/table_features.js +15 -0
- package/lib/components/table/table_features.js.map +1 -0
- package/lib/components/table/table_header.d.ts +2 -1
- package/lib/components/table/table_header.d.ts.map +1 -1
- package/lib/components/table/table_header.js.map +1 -1
- package/lib/components/table/table_header_cell.d.ts +3 -2
- package/lib/components/table/table_header_cell.d.ts.map +1 -1
- package/lib/components/table/table_header_cell.js +1 -1
- package/lib/components/table/table_header_cell.js.map +1 -1
- package/lib/components/table/table_root.d.ts +3 -2
- package/lib/components/table/table_root.d.ts.map +1 -1
- package/lib/components/table/table_root.js +4 -4
- package/lib/components/table/table_root.js.map +1 -1
- package/lib/components/table/table_row.d.ts +5 -4
- package/lib/components/table/table_row.d.ts.map +1 -1
- package/lib/components/table/table_row.js.map +1 -1
- package/lib/components/table/table_row_cell.d.ts +2 -1
- package/lib/components/table/table_row_cell.d.ts.map +1 -1
- package/lib/components/table/table_row_cell.js.map +1 -1
- package/lib/components/table/table_scroll_container.d.ts +6 -5
- package/lib/components/table/table_scroll_container.d.ts.map +1 -1
- package/lib/components/table/table_scroll_container.js.map +1 -1
- package/lib/components/table/table_utils.d.ts +18 -5
- package/lib/components/table/table_utils.d.ts.map +1 -1
- package/lib/components/table/table_utils.js.map +1 -1
- package/lib/components/table/use_table_columns.d.ts +2 -2
- package/lib/components/table/use_table_columns.d.ts.map +1 -1
- package/lib/components/table/use_table_columns.js.map +1 -1
- package/lib/components/table/use_table_scroll.d.ts +2 -1
- package/lib/components/table/use_table_scroll.d.ts.map +1 -1
- package/lib/components/table/use_table_scroll.js.map +1 -1
- package/package.json +17 -17
- package/src/components/info-panel/InfoPanel.tsx +2 -2
- package/src/components/logger/FifoLoggerDialog.tsx +29 -28
- package/src/components/table/default_table_cell.tsx +3 -1
- package/src/components/table/index.ts +12 -3
- package/src/components/table/preview_table.tsx +2 -1
- package/src/components/table/preview_table_context.ts +1 -1
- package/src/components/table/reorder_rows/draggable_row_tr.tsx +2 -1
- package/src/components/table/reorder_rows/item_data.ts +5 -3
- package/src/components/table/reorder_rows/item_order_context.ts +2 -3
- package/src/components/table/reorder_rows/item_order_provider.tsx +13 -11
- package/src/components/table/table_body.tsx +16 -20
- package/src/components/table/table_features.ts +28 -0
- package/src/components/table/table_header.tsx +2 -1
- package/src/components/table/table_header_cell.tsx +9 -9
- package/src/components/table/table_root.tsx +15 -26
- package/src/components/table/table_row.tsx +7 -4
- package/src/components/table/table_row_cell.tsx +2 -1
- package/src/components/table/table_scroll_container.tsx +8 -5
- package/src/components/table/table_utils.ts +7 -4
- package/src/components/table/use_table_columns.ts +4 -4
- package/src/components/table/use_table_scroll.ts +2 -1
|
@@ -7,6 +7,7 @@ import type { CSSProperties, ReactNode } from 'react';
|
|
|
7
7
|
import { Fragment } from 'react';
|
|
8
8
|
|
|
9
9
|
import { TableDraggableRowTr } from './reorder_rows/index.js';
|
|
10
|
+
import type { ReactScienceTableFeatures } from './table_features.js';
|
|
10
11
|
import { TableRowTr } from './table_row.js';
|
|
11
12
|
import { TableRowCell } from './table_row_cell.js';
|
|
12
13
|
import type {
|
|
@@ -17,7 +18,7 @@ import type {
|
|
|
17
18
|
} from './table_utils.js';
|
|
18
19
|
|
|
19
20
|
interface TableBodyProps<TData extends RowData> {
|
|
20
|
-
rows: Array<Row<TData>>;
|
|
21
|
+
rows: Array<Row<ReactScienceTableFeatures, TData>>;
|
|
21
22
|
tdStyle?: CSSProperties;
|
|
22
23
|
getTdProps?: GetTdProps<TData>;
|
|
23
24
|
renderRowTr: TableRowTrRenderer<TData> | undefined;
|
|
@@ -42,10 +43,7 @@ export function TableBody<TData extends RowData>(props: TableBodyProps<TData>) {
|
|
|
42
43
|
getTdProps,
|
|
43
44
|
isReorderingEnabled,
|
|
44
45
|
renderRowPreview,
|
|
45
|
-
renderRowTr = getDefaultRenderRowTr(
|
|
46
|
-
isReorderingEnabled,
|
|
47
|
-
renderRowPreview as TableRowPreviewRenderer<unknown>,
|
|
48
|
-
) as TableRowTrRenderer<TData>,
|
|
46
|
+
renderRowTr = getDefaultRenderRowTr(isReorderingEnabled, renderRowPreview),
|
|
49
47
|
virtualizer,
|
|
50
48
|
virtualizeRows,
|
|
51
49
|
emptyContent,
|
|
@@ -157,13 +155,15 @@ const EmptyState = styled.div`
|
|
|
157
155
|
gap: 0.5em;
|
|
158
156
|
`;
|
|
159
157
|
|
|
160
|
-
type TableRowRenderer<TData extends RowData> = (
|
|
158
|
+
type TableRowRenderer<TData extends RowData> = (
|
|
159
|
+
row: Row<ReactScienceTableFeatures, TData>,
|
|
160
|
+
) => ReactNode;
|
|
161
161
|
|
|
162
|
-
function TableRow<TData>({
|
|
162
|
+
function TableRow<TData extends RowData>({
|
|
163
163
|
row,
|
|
164
164
|
renderRowTr,
|
|
165
165
|
}: {
|
|
166
|
-
row: Row<TData>;
|
|
166
|
+
row: Row<ReactScienceTableFeatures, TData>;
|
|
167
167
|
renderRowTr: TableRowRenderer<TData>;
|
|
168
168
|
}) {
|
|
169
169
|
return <Fragment>{renderRowTr(row)}</Fragment>;
|
|
@@ -177,7 +177,7 @@ type RenderRowVirtualItem = VirtualItem & {
|
|
|
177
177
|
};
|
|
178
178
|
|
|
179
179
|
function getTrRenderProps<TData extends RowData>(
|
|
180
|
-
row: Row<TData>,
|
|
180
|
+
row: Row<ReactScienceTableFeatures, TData>,
|
|
181
181
|
tdStyle: CSSProperties | undefined,
|
|
182
182
|
getTdProps: GetTdProps<TData> | undefined,
|
|
183
183
|
virtualItem?: RenderRowVirtualItem,
|
|
@@ -202,24 +202,20 @@ function getTrRenderProps<TData extends RowData>(
|
|
|
202
202
|
};
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
function getDefaultRenderRowTr(
|
|
205
|
+
function getDefaultRenderRowTr<TData extends RowData>(
|
|
206
206
|
isReorderingEnabled: boolean,
|
|
207
|
-
renderRowPreview: TableRowPreviewRenderer<
|
|
208
|
-
): TableRowTrRenderer<
|
|
207
|
+
renderRowPreview: TableRowPreviewRenderer<TData> | undefined,
|
|
208
|
+
): TableRowTrRenderer<TData> {
|
|
209
209
|
if (isReorderingEnabled) {
|
|
210
210
|
return getDefaultRenderDraggableRowTr(renderRowPreview);
|
|
211
211
|
} else {
|
|
212
|
-
return
|
|
212
|
+
return (trProps, row) => <TableRowTr trProps={{ ...trProps }} row={row} />;
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
-
|
|
217
|
-
<
|
|
218
|
-
)
|
|
219
|
-
|
|
220
|
-
function getDefaultRenderDraggableRowTr(
|
|
221
|
-
renderRowPreview: TableRowPreviewRenderer<unknown> | undefined,
|
|
222
|
-
): TableRowTrRenderer<unknown> {
|
|
216
|
+
function getDefaultRenderDraggableRowTr<TData extends RowData>(
|
|
217
|
+
renderRowPreview: TableRowPreviewRenderer<TData> | undefined,
|
|
218
|
+
): TableRowTrRenderer<TData> {
|
|
223
219
|
return (trProps, row) => (
|
|
224
220
|
<TableDraggableRowTr
|
|
225
221
|
trProps={trProps}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {
|
|
2
|
+
columnVisibilityFeature,
|
|
3
|
+
createSortedRowModel,
|
|
4
|
+
rowSortingFeature,
|
|
5
|
+
sortFn_alphanumeric as sortFnAlphanumeric,
|
|
6
|
+
sortFn_alphanumericCaseSensitive as sortFnAlphanumericCaseSensitive,
|
|
7
|
+
sortFn_basic as sortFnBasic,
|
|
8
|
+
sortFn_datetime as sortFnDatetime,
|
|
9
|
+
sortFn_text as sortFnText,
|
|
10
|
+
sortFn_textCaseSensitive as sortFnTextCaseSensitive,
|
|
11
|
+
tableFeatures,
|
|
12
|
+
} from '@tanstack/react-table';
|
|
13
|
+
|
|
14
|
+
export const reactScienceTableFeatures = tableFeatures({
|
|
15
|
+
columnVisibilityFeature,
|
|
16
|
+
rowSortingFeature,
|
|
17
|
+
sortedRowModel: createSortedRowModel(),
|
|
18
|
+
sortFns: {
|
|
19
|
+
alphanumeric: sortFnAlphanumeric,
|
|
20
|
+
alphanumericCaseSensitive: sortFnAlphanumericCaseSensitive,
|
|
21
|
+
basic: sortFnBasic,
|
|
22
|
+
datetime: sortFnDatetime,
|
|
23
|
+
text: sortFnText,
|
|
24
|
+
textCaseSensitive: sortFnTextCaseSensitive,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export type ReactScienceTableFeatures = typeof reactScienceTableFeatures;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Header, RowData } from '@tanstack/react-table';
|
|
2
2
|
import type { CSSProperties } from 'react';
|
|
3
3
|
|
|
4
|
+
import type { ReactScienceTableFeatures } from './table_features.js';
|
|
4
5
|
import type { HeaderCellRenderer } from './table_header_cell.js';
|
|
5
6
|
import { TableHeaderCell } from './table_header_cell.js';
|
|
6
7
|
|
|
@@ -12,7 +13,7 @@ const headerStyle: CSSProperties = {
|
|
|
12
13
|
};
|
|
13
14
|
|
|
14
15
|
interface TableHeaderProps<TData extends RowData> {
|
|
15
|
-
headers: Array<Header<TData, unknown>>;
|
|
16
|
+
headers: Array<Header<ReactScienceTableFeatures, TData, unknown>>;
|
|
16
17
|
sticky: boolean;
|
|
17
18
|
renderHeaderCell?: HeaderCellRenderer<TData>;
|
|
18
19
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { Icon } from '@blueprintjs/core';
|
|
2
2
|
import type { IconName } from '@blueprintjs/icons';
|
|
3
|
-
import type { Header, RowData,
|
|
3
|
+
import type { Header, RowData, SortFnOption } from '@tanstack/react-table';
|
|
4
4
|
import { flexRender } from '@tanstack/react-table';
|
|
5
5
|
import type { HTMLAttributes, ReactNode } from 'react';
|
|
6
6
|
import { match } from 'ts-pattern';
|
|
7
7
|
|
|
8
|
+
import type { ReactScienceTableFeatures } from './table_features.js';
|
|
9
|
+
|
|
8
10
|
type ThProps = Pick<
|
|
9
11
|
HTMLAttributes<HTMLTableCellElement>,
|
|
10
12
|
'style' | 'onClick' | 'children'
|
|
@@ -12,11 +14,11 @@ type ThProps = Pick<
|
|
|
12
14
|
|
|
13
15
|
export type HeaderCellRenderer<TData extends RowData> = (
|
|
14
16
|
thProps: ThProps,
|
|
15
|
-
header: Header<TData, unknown>,
|
|
17
|
+
header: Header<ReactScienceTableFeatures, TData, unknown>,
|
|
16
18
|
) => ReactNode;
|
|
17
19
|
|
|
18
20
|
interface TableHeaderCellProps<TData extends RowData> {
|
|
19
|
-
header: Header<TData, unknown>;
|
|
21
|
+
header: Header<ReactScienceTableFeatures, TData, unknown>;
|
|
20
22
|
renderHeaderCell?: HeaderCellRenderer<TData>;
|
|
21
23
|
}
|
|
22
24
|
|
|
@@ -33,15 +35,13 @@ export function TableHeaderCell<TData extends RowData>(
|
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
function getThProps<TData extends RowData>(
|
|
36
|
-
header: Header<TData, unknown>,
|
|
38
|
+
header: Header<ReactScienceTableFeatures, TData, unknown>,
|
|
37
39
|
): ThProps {
|
|
38
40
|
const { column } = header;
|
|
39
41
|
|
|
40
42
|
const sorted = column.getIsSorted();
|
|
41
43
|
const canSort = column.getCanSort();
|
|
42
|
-
const sortingIcon = getSortingIcon(column.columnDef.
|
|
43
|
-
sorted || 'asc'
|
|
44
|
-
];
|
|
44
|
+
const sortingIcon = getSortingIcon(column.columnDef.sortFn)[sorted || 'asc'];
|
|
45
45
|
|
|
46
46
|
return {
|
|
47
47
|
onClick: canSort ? column.getToggleSortingHandler() : undefined,
|
|
@@ -60,10 +60,10 @@ function getThProps<TData extends RowData>(
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
function getSortingIcon<TData extends RowData>(
|
|
63
|
-
type:
|
|
63
|
+
type: SortFnOption<ReactScienceTableFeatures, TData> | undefined,
|
|
64
64
|
): { asc: IconName; desc: IconName } {
|
|
65
65
|
return match<
|
|
66
|
-
|
|
66
|
+
SortFnOption<ReactScienceTableFeatures, TData> | undefined,
|
|
67
67
|
{ asc: IconName; desc: IconName }
|
|
68
68
|
>(type)
|
|
69
69
|
.with(
|
|
@@ -1,16 +1,7 @@
|
|
|
1
1
|
import { HTMLTable } from '@blueprintjs/core';
|
|
2
2
|
import styled from '@emotion/styled';
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
RowData,
|
|
6
|
-
Table as TanstackTable,
|
|
7
|
-
TableOptions,
|
|
8
|
-
} from '@tanstack/react-table';
|
|
9
|
-
import {
|
|
10
|
-
getCoreRowModel,
|
|
11
|
-
getSortedRowModel,
|
|
12
|
-
useReactTable,
|
|
13
|
-
} from '@tanstack/react-table';
|
|
3
|
+
import type { Header, RowData, TableOptions } from '@tanstack/react-table';
|
|
4
|
+
import { useTable } from '@tanstack/react-table';
|
|
14
5
|
import { useVirtualizer } from '@tanstack/react-virtual';
|
|
15
6
|
import type {
|
|
16
7
|
CSSProperties,
|
|
@@ -28,6 +19,8 @@ import type { PreviewTablePropsContextValue } from './preview_table_context.js';
|
|
|
28
19
|
import { PreviewTablePropsContextProvider } from './preview_table_context.js';
|
|
29
20
|
import { ItemOrderProvider } from './reorder_rows/item_order_provider.js';
|
|
30
21
|
import { TableBody } from './table_body.js';
|
|
22
|
+
import type { ReactScienceTableFeatures } from './table_features.js';
|
|
23
|
+
import { reactScienceTableFeatures } from './table_features.js';
|
|
31
24
|
import { TableHeader } from './table_header.js';
|
|
32
25
|
import type { HeaderCellRenderer } from './table_header_cell.js';
|
|
33
26
|
import { ScrollContainer } from './table_scroll_container.js';
|
|
@@ -124,8 +117,8 @@ interface TableBaseProps<TData extends RowData> {
|
|
|
124
117
|
virtualizeRows?: boolean;
|
|
125
118
|
|
|
126
119
|
reactTable?: Omit<
|
|
127
|
-
TableOptions<TData>,
|
|
128
|
-
'
|
|
120
|
+
TableOptions<ReactScienceTableFeatures, TData>,
|
|
121
|
+
'features' | 'data' | 'columns'
|
|
129
122
|
>;
|
|
130
123
|
/**
|
|
131
124
|
* Props which are forwarded to the underlying HTML table element.
|
|
@@ -170,7 +163,7 @@ interface TableBaseProps<TData extends RowData> {
|
|
|
170
163
|
/**
|
|
171
164
|
* An accessor which should return a unique identifier for the row.
|
|
172
165
|
*/
|
|
173
|
-
getRowId?: TableOptions<TData>['getRowId'];
|
|
166
|
+
getRowId?: TableOptions<ReactScienceTableFeatures, TData>['getRowId'];
|
|
174
167
|
|
|
175
168
|
/**
|
|
176
169
|
* Called when the user changed the order of the rows.
|
|
@@ -267,12 +260,11 @@ export function Table<TData extends RowData>(props: TableProps<TData>) {
|
|
|
267
260
|
const isReorderingEnabled = !!onRowOrderChanged;
|
|
268
261
|
const virtualScrollElementRef = useRef<HTMLDivElement>(null);
|
|
269
262
|
const columnDefs = useTableColumns(columns);
|
|
270
|
-
const table =
|
|
263
|
+
const table = useTable({
|
|
271
264
|
...reactTable,
|
|
265
|
+
features: reactScienceTableFeatures,
|
|
272
266
|
data,
|
|
273
267
|
columns: columnDefs,
|
|
274
|
-
getCoreRowModel: getCoreRowModel(),
|
|
275
|
-
getSortedRowModel: getSortedRowModel(),
|
|
276
268
|
getRowId,
|
|
277
269
|
});
|
|
278
270
|
|
|
@@ -299,10 +291,7 @@ export function Table<TData extends RowData>(props: TableProps<TData>) {
|
|
|
299
291
|
}
|
|
300
292
|
|
|
301
293
|
const tableHeaders = table.getFlatHeaders();
|
|
302
|
-
useCheckProps(
|
|
303
|
-
props as TableProps<unknown>,
|
|
304
|
-
tableHeaders as Array<Header<unknown, unknown>>,
|
|
305
|
-
);
|
|
294
|
+
useCheckProps(props, tableHeaders);
|
|
306
295
|
|
|
307
296
|
const tablePreviewProps = useMemo<PreviewTablePropsContextValue<TData>>(
|
|
308
297
|
() => ({
|
|
@@ -320,7 +309,7 @@ export function Table<TData extends RowData>(props: TableProps<TData>) {
|
|
|
320
309
|
return (
|
|
321
310
|
<FlashedRowProvider>
|
|
322
311
|
<PreviewTablePropsContextProvider
|
|
323
|
-
value={tablePreviewProps as PreviewTablePropsContextValue<
|
|
312
|
+
value={tablePreviewProps as PreviewTablePropsContextValue<RowData>}
|
|
324
313
|
>
|
|
325
314
|
<ItemOrderProvider
|
|
326
315
|
items={rows}
|
|
@@ -331,7 +320,7 @@ export function Table<TData extends RowData>(props: TableProps<TData>) {
|
|
|
331
320
|
<ScrollContainer
|
|
332
321
|
virtualizeRows={virtualizeRows}
|
|
333
322
|
virtualizer={tanstackVirtualizer}
|
|
334
|
-
table={table
|
|
323
|
+
table={table}
|
|
335
324
|
scrollRef={
|
|
336
325
|
virtualizeRows
|
|
337
326
|
? // When virtualized, ScrollContainer will render a scrollable element associated to this ref.
|
|
@@ -385,9 +374,9 @@ export function Table<TData extends RowData>(props: TableProps<TData>) {
|
|
|
385
374
|
);
|
|
386
375
|
}
|
|
387
376
|
|
|
388
|
-
function useCheckProps(
|
|
389
|
-
props: TableProps<
|
|
390
|
-
headers: Array<Header<
|
|
377
|
+
function useCheckProps<TData extends RowData>(
|
|
378
|
+
props: TableProps<TData>,
|
|
379
|
+
headers: Array<Header<ReactScienceTableFeatures, TData, unknown>>,
|
|
391
380
|
) {
|
|
392
381
|
const { onRowOrderChanged, getRowId } = props;
|
|
393
382
|
useEffect(() => {
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import type { Row } from '@tanstack/react-table';
|
|
1
|
+
import type { Row, RowData } from '@tanstack/react-table';
|
|
2
2
|
import type { JSX } from 'react';
|
|
3
3
|
import { useRef } from 'react';
|
|
4
4
|
|
|
5
5
|
import { useFlashRowEffect } from './flash_row/use_flash_row_effect.js';
|
|
6
|
+
import type { ReactScienceTableFeatures } from './table_features.js';
|
|
6
7
|
|
|
7
|
-
export interface TableRowTrProps<RowType> {
|
|
8
|
-
row: Row<RowType>;
|
|
8
|
+
export interface TableRowTrProps<RowType extends RowData> {
|
|
9
|
+
row: Row<ReactScienceTableFeatures, RowType>;
|
|
9
10
|
trProps: JSX.IntrinsicElements['tr'];
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
export function TableRowTr<RowType>(
|
|
13
|
+
export function TableRowTr<RowType extends RowData>(
|
|
14
|
+
props: TableRowTrProps<RowType>,
|
|
15
|
+
) {
|
|
13
16
|
const { row, trProps } = props;
|
|
14
17
|
const tableRowRef = useRef<HTMLTableRowElement>(null);
|
|
15
18
|
useFlashRowEffect(row.id, tableRowRef);
|
|
@@ -2,10 +2,11 @@ import type { Cell, RowData } from '@tanstack/react-table';
|
|
|
2
2
|
import { flexRender } from '@tanstack/react-table';
|
|
3
3
|
import type { CSSProperties } from 'react';
|
|
4
4
|
|
|
5
|
+
import type { ReactScienceTableFeatures } from './table_features.js';
|
|
5
6
|
import type { GetTdProps } from './table_utils.js';
|
|
6
7
|
|
|
7
8
|
interface TableRowCellProps<TData extends RowData> {
|
|
8
|
-
cell: Cell<TData, unknown>;
|
|
9
|
+
cell: Cell<ReactScienceTableFeatures, TData, unknown>;
|
|
9
10
|
tdStyle: CSSProperties | undefined;
|
|
10
11
|
getTdProps: GetTdProps<TData> | undefined;
|
|
11
12
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import styled from '@emotion/styled';
|
|
2
|
+
import type { RowData, Table as TanstackTable } from '@tanstack/react-table';
|
|
2
3
|
import type { Virtualizer } from '@tanstack/react-virtual';
|
|
3
|
-
import type { Table as TanstackTable } from '@tanstack/table-core';
|
|
4
4
|
import type { ReactNode, RefObject } from 'react';
|
|
5
5
|
|
|
6
6
|
import { useDropMonitor } from './reorder_rows/use_drop_monitor.js';
|
|
7
|
+
import type { ReactScienceTableFeatures } from './table_features.js';
|
|
7
8
|
import type { TableProps } from './table_root.js';
|
|
8
9
|
import { useTableScroll } from './use_table_scroll.js';
|
|
9
10
|
|
|
@@ -12,7 +13,7 @@ const ScrollRefDiv = styled.div`
|
|
|
12
13
|
overflow: auto;
|
|
13
14
|
`;
|
|
14
15
|
|
|
15
|
-
interface ScrollContainerProps {
|
|
16
|
+
interface ScrollContainerProps<TData extends RowData> {
|
|
16
17
|
/**
|
|
17
18
|
* Whether the table rows are virtualized.
|
|
18
19
|
*/
|
|
@@ -24,7 +25,7 @@ interface ScrollContainerProps {
|
|
|
24
25
|
/**
|
|
25
26
|
* The tanstack table.
|
|
26
27
|
*/
|
|
27
|
-
table: TanstackTable<
|
|
28
|
+
table: TanstackTable<ReactScienceTableFeatures, TData>;
|
|
28
29
|
/**
|
|
29
30
|
* A ref to the effective scroll container.
|
|
30
31
|
*/
|
|
@@ -34,12 +35,14 @@ interface ScrollContainerProps {
|
|
|
34
35
|
* It is set by the ScrollContainer component if the table is virtualized.
|
|
35
36
|
* It is an external ref when the table is not virtualized.
|
|
36
37
|
*/
|
|
37
|
-
scrollToRowRef?: TableProps<
|
|
38
|
+
scrollToRowRef?: TableProps<TData>['scrollToRowRef'];
|
|
38
39
|
isReorderingEnabled: boolean;
|
|
39
40
|
children: ReactNode;
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
export function ScrollContainer
|
|
43
|
+
export function ScrollContainer<TData extends RowData>(
|
|
44
|
+
props: ScrollContainerProps<TData>,
|
|
45
|
+
) {
|
|
43
46
|
const {
|
|
44
47
|
virtualizeRows,
|
|
45
48
|
table,
|
|
@@ -3,7 +3,10 @@ import { createColumnHelper } from '@tanstack/react-table';
|
|
|
3
3
|
import type { ScrollToOptions } from '@tanstack/react-virtual';
|
|
4
4
|
import type { CSSProperties, ReactNode, TdHTMLAttributes } from 'react';
|
|
5
5
|
|
|
6
|
+
import type { ReactScienceTableFeatures } from './table_features.js';
|
|
7
|
+
|
|
6
8
|
export type TableColumnDef<TData extends RowData, TValue = unknown> = ColumnDef<
|
|
9
|
+
ReactScienceTableFeatures,
|
|
7
10
|
TData,
|
|
8
11
|
TValue
|
|
9
12
|
>;
|
|
@@ -11,11 +14,11 @@ export type TableColumnDef<TData extends RowData, TValue = unknown> = ColumnDef<
|
|
|
11
14
|
type TableTdProps = TdHTMLAttributes<HTMLTableCellElement>;
|
|
12
15
|
|
|
13
16
|
export type GetTdProps<TData extends RowData> = (
|
|
14
|
-
cell: Cell<TData, unknown>,
|
|
17
|
+
cell: Cell<ReactScienceTableFeatures, TData, unknown>,
|
|
15
18
|
) => TableTdProps;
|
|
16
19
|
|
|
17
20
|
export function createTableColumnHelper<TData extends RowData>() {
|
|
18
|
-
return createColumnHelper<TData>();
|
|
21
|
+
return createColumnHelper<ReactScienceTableFeatures, TData>();
|
|
19
22
|
}
|
|
20
23
|
|
|
21
24
|
export interface TableRowTrRenderProps {
|
|
@@ -28,14 +31,14 @@ export interface TableRowTrRenderProps {
|
|
|
28
31
|
|
|
29
32
|
export type TableRowTrRenderer<TData extends RowData> = (
|
|
30
33
|
trProps: TableRowTrRenderProps,
|
|
31
|
-
row: Row<TData>,
|
|
34
|
+
row: Row<ReactScienceTableFeatures, TData>,
|
|
32
35
|
) => ReactNode;
|
|
33
36
|
|
|
34
37
|
export type TableRowPreviewRenderer<TData extends RowData> = (
|
|
35
38
|
/**
|
|
36
39
|
* The row being dragged, for which to render a preview.
|
|
37
40
|
*/
|
|
38
|
-
row: Row<TData>,
|
|
41
|
+
row: Row<ReactScienceTableFeatures, TData>,
|
|
39
42
|
) => ReactNode;
|
|
40
43
|
|
|
41
44
|
interface FlashRowOptions {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RowData } from '@tanstack/react-table';
|
|
2
2
|
import { useMemo } from 'react';
|
|
3
3
|
|
|
4
4
|
import { defaultTableCell } from './default_table_cell.js';
|
|
5
5
|
import type { TableColumnDef } from './table_utils.js';
|
|
6
6
|
|
|
7
|
-
export function useTableColumns<TData extends RowData>(
|
|
8
|
-
columnDefs: Array<TableColumnDef<TData>>,
|
|
7
|
+
export function useTableColumns<TData extends RowData, TValue>(
|
|
8
|
+
columnDefs: Array<TableColumnDef<TData, TValue>>,
|
|
9
9
|
) {
|
|
10
|
-
return useMemo<Array<
|
|
10
|
+
return useMemo<Array<TableColumnDef<TData, TValue>>>(() => {
|
|
11
11
|
return columnDefs.map((columnDef) => {
|
|
12
12
|
return {
|
|
13
13
|
...columnDef,
|
|
@@ -6,6 +6,7 @@ import { useImperativeHandle } from 'react';
|
|
|
6
6
|
import { selector } from '../utils/selector.ts';
|
|
7
7
|
|
|
8
8
|
import { useFlashedRowContext } from './flash_row/flashed_row_context.js';
|
|
9
|
+
import type { ReactScienceTableFeatures } from './table_features.js';
|
|
9
10
|
import type { TableProps } from './table_root.js';
|
|
10
11
|
import type { TableVirtualScrollIntoViewOptions } from './table_utils.js';
|
|
11
12
|
|
|
@@ -25,7 +26,7 @@ export function useTableScroll<TData extends RowData>(options: {
|
|
|
25
26
|
/*
|
|
26
27
|
Tanstack table instance.
|
|
27
28
|
*/
|
|
28
|
-
table: Table<TData>;
|
|
29
|
+
table: Table<ReactScienceTableFeatures, TData>;
|
|
29
30
|
/**
|
|
30
31
|
* Tanstack virtualizer instance.
|
|
31
32
|
*/
|