react-science 21.0.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.
Files changed (97) hide show
  1. package/lib/components/form/utils/validation/coerce_number_input.d.ts +3 -0
  2. package/lib/components/form/utils/validation/coerce_number_input.d.ts.map +1 -0
  3. package/lib/components/form/utils/validation/coerce_number_input.js +6 -0
  4. package/lib/components/form/utils/validation/coerce_number_input.js.map +1 -0
  5. package/lib/components/index.d.ts +1 -0
  6. package/lib/components/index.d.ts.map +1 -1
  7. package/lib/components/index.js +1 -0
  8. package/lib/components/index.js.map +1 -1
  9. package/lib/components/info-panel/InfoPanel.js +2 -2
  10. package/lib/components/info-panel/InfoPanel.js.map +1 -1
  11. package/lib/components/logger/FifoLoggerDialog.d.ts.map +1 -1
  12. package/lib/components/logger/FifoLoggerDialog.js +2 -2
  13. package/lib/components/logger/FifoLoggerDialog.js.map +1 -1
  14. package/lib/components/table/default_table_cell.d.ts +2 -1
  15. package/lib/components/table/default_table_cell.d.ts.map +1 -1
  16. package/lib/components/table/default_table_cell.js.map +1 -1
  17. package/lib/components/table/index.d.ts +2 -2
  18. package/lib/components/table/index.d.ts.map +1 -1
  19. package/lib/components/table/index.js.map +1 -1
  20. package/lib/components/table/preview_table.d.ts +2 -1
  21. package/lib/components/table/preview_table.d.ts.map +1 -1
  22. package/lib/components/table/preview_table.js.map +1 -1
  23. package/lib/components/table/preview_table_context.d.ts +2 -2
  24. package/lib/components/table/reorder_rows/draggable_row_tr.d.ts +2 -1
  25. package/lib/components/table/reorder_rows/draggable_row_tr.d.ts.map +1 -1
  26. package/lib/components/table/reorder_rows/draggable_row_tr.js.map +1 -1
  27. package/lib/components/table/reorder_rows/item_data.d.ts +3 -2
  28. package/lib/components/table/reorder_rows/item_data.d.ts.map +1 -1
  29. package/lib/components/table/reorder_rows/item_data.js.map +1 -1
  30. package/lib/components/table/reorder_rows/item_order_context.d.ts +6 -5
  31. package/lib/components/table/reorder_rows/item_order_context.d.ts.map +1 -1
  32. package/lib/components/table/reorder_rows/item_order_context.js.map +1 -1
  33. package/lib/components/table/reorder_rows/item_order_provider.d.ts +6 -5
  34. package/lib/components/table/reorder_rows/item_order_provider.d.ts.map +1 -1
  35. package/lib/components/table/reorder_rows/item_order_provider.js +1 -4
  36. package/lib/components/table/reorder_rows/item_order_provider.js.map +1 -1
  37. package/lib/components/table/table_body.d.ts +2 -1
  38. package/lib/components/table/table_body.d.ts.map +1 -1
  39. package/lib/components/table/table_body.js +1 -2
  40. package/lib/components/table/table_body.js.map +1 -1
  41. package/lib/components/table/table_features.d.ts +15 -0
  42. package/lib/components/table/table_features.d.ts.map +1 -0
  43. package/lib/components/table/table_features.js +15 -0
  44. package/lib/components/table/table_features.js.map +1 -0
  45. package/lib/components/table/table_header.d.ts +2 -1
  46. package/lib/components/table/table_header.d.ts.map +1 -1
  47. package/lib/components/table/table_header.js.map +1 -1
  48. package/lib/components/table/table_header_cell.d.ts +3 -2
  49. package/lib/components/table/table_header_cell.d.ts.map +1 -1
  50. package/lib/components/table/table_header_cell.js +1 -1
  51. package/lib/components/table/table_header_cell.js.map +1 -1
  52. package/lib/components/table/table_root.d.ts +3 -2
  53. package/lib/components/table/table_root.d.ts.map +1 -1
  54. package/lib/components/table/table_root.js +4 -4
  55. package/lib/components/table/table_root.js.map +1 -1
  56. package/lib/components/table/table_row.d.ts +5 -4
  57. package/lib/components/table/table_row.d.ts.map +1 -1
  58. package/lib/components/table/table_row.js.map +1 -1
  59. package/lib/components/table/table_row_cell.d.ts +2 -1
  60. package/lib/components/table/table_row_cell.d.ts.map +1 -1
  61. package/lib/components/table/table_row_cell.js.map +1 -1
  62. package/lib/components/table/table_scroll_container.d.ts +6 -5
  63. package/lib/components/table/table_scroll_container.d.ts.map +1 -1
  64. package/lib/components/table/table_scroll_container.js.map +1 -1
  65. package/lib/components/table/table_utils.d.ts +18 -5
  66. package/lib/components/table/table_utils.d.ts.map +1 -1
  67. package/lib/components/table/table_utils.js.map +1 -1
  68. package/lib/components/table/use_table_columns.d.ts +2 -2
  69. package/lib/components/table/use_table_columns.d.ts.map +1 -1
  70. package/lib/components/table/use_table_columns.js.map +1 -1
  71. package/lib/components/table/use_table_scroll.d.ts +2 -1
  72. package/lib/components/table/use_table_scroll.d.ts.map +1 -1
  73. package/lib/components/table/use_table_scroll.js.map +1 -1
  74. package/package.json +17 -17
  75. package/src/components/form/utils/validation/coerce_number_input.ts +6 -0
  76. package/src/components/index.ts +1 -0
  77. package/src/components/info-panel/InfoPanel.tsx +2 -2
  78. package/src/components/logger/FifoLoggerDialog.tsx +29 -28
  79. package/src/components/table/default_table_cell.tsx +3 -1
  80. package/src/components/table/index.ts +12 -3
  81. package/src/components/table/preview_table.tsx +2 -1
  82. package/src/components/table/preview_table_context.ts +1 -1
  83. package/src/components/table/reorder_rows/draggable_row_tr.tsx +2 -1
  84. package/src/components/table/reorder_rows/item_data.ts +5 -3
  85. package/src/components/table/reorder_rows/item_order_context.ts +2 -3
  86. package/src/components/table/reorder_rows/item_order_provider.tsx +13 -11
  87. package/src/components/table/table_body.tsx +16 -20
  88. package/src/components/table/table_features.ts +28 -0
  89. package/src/components/table/table_header.tsx +2 -1
  90. package/src/components/table/table_header_cell.tsx +9 -9
  91. package/src/components/table/table_root.tsx +15 -26
  92. package/src/components/table/table_row.tsx +7 -4
  93. package/src/components/table/table_row_cell.tsx +2 -1
  94. package/src/components/table/table_scroll_container.tsx +8 -5
  95. package/src/components/table/table_utils.ts +7 -4
  96. package/src/components/table/use_table_columns.ts +4 -4
  97. package/src/components/table/use_table_scroll.ts +2 -1
@@ -1,18 +1,23 @@
1
- import type { Row } from '@tanstack/react-table';
1
+ import type { Row, RowData } from '@tanstack/react-table';
2
2
  import { getReorderDestinationIndex, reorder } from '@zakodium/pdnd-esm';
3
3
  import type { ReactNode } from 'react';
4
4
  import { useCallback, useMemo, useState } from 'react';
5
5
 
6
- import type { ReorderItemCallback } from './item_order_context.js';
6
+ import type { ReactScienceTableFeatures } from '../table_features.js';
7
+
8
+ import type {
9
+ ItemOrderContextValue,
10
+ ReorderItemCallback,
11
+ } from './item_order_context.js';
7
12
  import { itemOrderContext } from './item_order_context.js';
8
13
 
9
- interface ItemOrderProviderProps<T> {
10
- items: Array<Row<T>>;
11
- onOrderChanged: (items: Array<Row<T>>) => void;
14
+ interface ItemOrderProviderProps<T extends RowData> {
15
+ items: Array<Row<ReactScienceTableFeatures, T>>;
16
+ onOrderChanged: (items: Array<Row<ReactScienceTableFeatures, T>>) => void;
12
17
  children: ReactNode;
13
18
  }
14
19
 
15
- export function ItemOrderProvider<T = unknown>(
20
+ export function ItemOrderProvider<T extends RowData = RowData>(
16
21
  props: ItemOrderProviderProps<T>,
17
22
  ) {
18
23
  // Isolated instances of this component from one another
@@ -43,13 +48,10 @@ export function ItemOrderProvider<T = unknown>(
43
48
  [items, onOrderChanged],
44
49
  );
45
50
 
46
- const value = useMemo(() => {
47
- // This assertion is necessary because the provider cannot contain the
48
- // T type instantiated by this component.
49
- const contextItems = items as Array<Row<unknown>>;
51
+ const value = useMemo<ItemOrderContextValue>(() => {
50
52
  return {
51
53
  reorderItem,
52
- items: contextItems,
54
+ items,
53
55
  instanceId,
54
56
  };
55
57
  }, [reorderItem, items, instanceId]);
@@ -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> = (row: Row<TData>) => ReactNode;
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<unknown> | undefined,
208
- ): TableRowTrRenderer<unknown> {
207
+ renderRowPreview: TableRowPreviewRenderer<TData> | undefined,
208
+ ): TableRowTrRenderer<TData> {
209
209
  if (isReorderingEnabled) {
210
210
  return getDefaultRenderDraggableRowTr(renderRowPreview);
211
211
  } else {
212
- return defaultRenderRowTr;
212
+ return (trProps, row) => <TableRowTr trProps={{ ...trProps }} row={row} />;
213
213
  }
214
214
  }
215
215
 
216
- const defaultRenderRowTr: TableRowTrRenderer<unknown> = (trProps, row) => (
217
- <TableRowTr trProps={{ ...trProps }} row={row} />
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, SortingFnOption } from '@tanstack/react-table';
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.sortingFn)[
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: SortingFnOption<TData> | undefined,
63
+ type: SortFnOption<ReactScienceTableFeatures, TData> | undefined,
64
64
  ): { asc: IconName; desc: IconName } {
65
65
  return match<
66
- SortingFnOption<TData> | undefined,
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
- Header,
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
- 'data' | 'columns' | 'getCoreRowModel' | 'getSortedRowModel'
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 = useReactTable<TData>({
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<unknown>}
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 as TanstackTable<unknown>}
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<unknown>,
390
- headers: Array<Header<unknown, unknown>>,
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>(props: TableRowTrProps<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<unknown>;
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<unknown>['scrollToRowRef'];
38
+ scrollToRowRef?: TableProps<TData>['scrollToRowRef'];
38
39
  isReorderingEnabled: boolean;
39
40
  children: ReactNode;
40
41
  }
41
42
 
42
- export function ScrollContainer(props: ScrollContainerProps) {
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 { ColumnDef, RowData } from '@tanstack/react-table';
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<ColumnDef<TData>>>(() => {
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
  */