react-science 16.0.0 → 16.1.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/table/flash_row/flashed_row_context.d.ts +3 -0
- package/lib/components/table/flash_row/flashed_row_context.d.ts.map +1 -0
- package/lib/components/table/flash_row/flashed_row_context.js +10 -0
- package/lib/components/table/flash_row/flashed_row_context.js.map +1 -0
- package/lib/components/table/{reorder_rows/dropped_item_provider.d.ts → flash_row/flashed_row_provider.d.ts} +2 -2
- package/lib/components/table/flash_row/flashed_row_provider.d.ts.map +1 -0
- package/lib/components/table/flash_row/flashed_row_provider.js +8 -0
- package/lib/components/table/flash_row/flashed_row_provider.js.map +1 -0
- package/lib/components/table/flash_row/use_flash_row_effect.d.ts +3 -0
- package/lib/components/table/flash_row/use_flash_row_effect.d.ts.map +1 -0
- package/lib/components/table/flash_row/use_flash_row_effect.js +21 -0
- package/lib/components/table/flash_row/use_flash_row_effect.js.map +1 -0
- package/lib/components/table/index.d.ts +1 -0
- package/lib/components/table/index.d.ts.map +1 -1
- package/lib/components/table/index.js +1 -0
- package/lib/components/table/index.js.map +1 -1
- package/lib/components/table/preview_table.d.ts +5 -0
- package/lib/components/table/preview_table.d.ts.map +1 -0
- package/lib/components/table/preview_table.js +8 -0
- package/lib/components/table/preview_table.js.map +1 -0
- package/lib/components/table/preview_table_context.d.ts +9 -0
- package/lib/components/table/preview_table_context.d.ts.map +1 -0
- package/lib/components/table/preview_table_context.js +15 -0
- package/lib/components/table/preview_table_context.js.map +1 -0
- package/lib/components/table/reorder_rows/draggable_row_tr.d.ts +3 -3
- package/lib/components/table/reorder_rows/draggable_row_tr.d.ts.map +1 -1
- package/lib/components/table/reorder_rows/draggable_row_tr.js +14 -20
- package/lib/components/table/reorder_rows/draggable_row_tr.js.map +1 -1
- package/lib/components/table/reorder_rows/table_drag_row_handler.d.ts +3 -1
- package/lib/components/table/reorder_rows/table_drag_row_handler.d.ts.map +1 -1
- package/lib/components/table/reorder_rows/table_drag_row_handler.js +12 -2
- package/lib/components/table/reorder_rows/table_drag_row_handler.js.map +1 -1
- package/lib/components/table/reorder_rows/use_drop_monitor.js +4 -4
- package/lib/components/table/reorder_rows/use_drop_monitor.js.map +1 -1
- package/lib/components/table/table_body.d.ts.map +1 -1
- package/lib/components/table/table_body.js +3 -3
- package/lib/components/table/table_body.js.map +1 -1
- package/lib/components/table/table_root.d.ts +5 -1
- package/lib/components/table/table_root.d.ts.map +1 -1
- package/lib/components/table/table_root.js +44 -45
- package/lib/components/table/table_root.js.map +1 -1
- package/lib/components/table/table_row.d.ts +8 -0
- package/lib/components/table/table_row.d.ts.map +1 -0
- package/lib/components/table/table_row.js +10 -0
- package/lib/components/table/table_row.js.map +1 -0
- package/lib/components/table/table_scroll_container.d.ts +33 -0
- package/lib/components/table/table_scroll_container.d.ts.map +1 -0
- package/lib/components/table/table_scroll_container.js +33 -0
- package/lib/components/table/table_scroll_container.js.map +1 -0
- package/lib/components/table/table_utils.d.ts +13 -4
- package/lib/components/table/table_utils.d.ts.map +1 -1
- package/lib/components/table/use_table_scroll.d.ts +20 -1
- package/lib/components/table/use_table_scroll.d.ts.map +1 -1
- package/lib/components/table/use_table_scroll.js +16 -8
- package/lib/components/table/use_table_scroll.js.map +1 -1
- package/package.json +1 -1
- package/src/components/table/flash_row/flashed_row_context.ts +23 -0
- package/src/components/table/flash_row/flashed_row_provider.tsx +13 -0
- package/src/components/table/flash_row/use_flash_row_effect.ts +30 -0
- package/src/components/table/index.ts +1 -0
- package/src/components/table/preview_table.tsx +18 -0
- package/src/components/table/preview_table_context.ts +33 -0
- package/src/components/table/reorder_rows/draggable_row_tr.tsx +21 -27
- package/src/components/table/reorder_rows/table_drag_row_handler.tsx +25 -4
- package/src/components/table/reorder_rows/use_drop_monitor.ts +4 -4
- package/src/components/table/table_body.tsx +6 -8
- package/src/components/table/table_root.tsx +112 -123
- package/src/components/table/table_row.tsx +17 -0
- package/src/components/table/table_scroll_container.tsx +103 -0
- package/src/components/table/table_utils.ts +20 -4
- package/src/components/table/use_table_scroll.ts +48 -20
- package/lib/components/table/reorder_rows/dropped_item_context.d.ts +0 -3
- package/lib/components/table/reorder_rows/dropped_item_context.d.ts.map +0 -1
- package/lib/components/table/reorder_rows/dropped_item_context.js +0 -10
- package/lib/components/table/reorder_rows/dropped_item_context.js.map +0 -1
- package/lib/components/table/reorder_rows/dropped_item_provider.d.ts.map +0 -1
- package/lib/components/table/reorder_rows/dropped_item_provider.js +0 -8
- package/lib/components/table/reorder_rows/dropped_item_provider.js.map +0 -1
- package/src/components/table/reorder_rows/dropped_item_context.ts +0 -23
- package/src/components/table/reorder_rows/dropped_item_provider.tsx +0 -13
|
@@ -18,7 +18,7 @@ export function createTableColumnHelper<TData extends RowData>() {
|
|
|
18
18
|
return createColumnHelper<TData>();
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export interface
|
|
21
|
+
export interface TableRowTrRenderProps {
|
|
22
22
|
className: string;
|
|
23
23
|
style: CSSProperties;
|
|
24
24
|
children: ReactNode;
|
|
@@ -27,7 +27,7 @@ export interface TableRowTrProps {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export type TableRowTrRenderer<TData extends RowData> = (
|
|
30
|
-
trProps:
|
|
30
|
+
trProps: TableRowTrRenderProps,
|
|
31
31
|
row: Row<TData>,
|
|
32
32
|
) => ReactNode;
|
|
33
33
|
|
|
@@ -38,10 +38,26 @@ export type TableRowPreviewRenderer<TData extends RowData> = (
|
|
|
38
38
|
row: Row<TData>,
|
|
39
39
|
) => ReactNode;
|
|
40
40
|
|
|
41
|
+
interface FlashRowOptions {
|
|
42
|
+
/**
|
|
43
|
+
* Whether to flash the row when scrolling into view.
|
|
44
|
+
* The option is only supported when there is no scroll animation, i.e. `behavior` is not `smooth`.
|
|
45
|
+
*/
|
|
46
|
+
flashRow?: boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type TableScrollIntoViewOptions = ScrollIntoViewOptions &
|
|
50
|
+
FlashRowOptions;
|
|
51
|
+
export type TableVirtualScrollIntoViewOptions = ScrollToOptions &
|
|
52
|
+
FlashRowOptions;
|
|
53
|
+
|
|
41
54
|
export interface VirtualScroller {
|
|
42
|
-
scrollIntoView: (
|
|
55
|
+
scrollIntoView: (
|
|
56
|
+
id: string,
|
|
57
|
+
options?: TableVirtualScrollIntoViewOptions,
|
|
58
|
+
) => void;
|
|
43
59
|
}
|
|
44
60
|
|
|
45
61
|
export interface Scroller {
|
|
46
|
-
scrollIntoView: (id: string, options?:
|
|
62
|
+
scrollIntoView: (id: string, options?: TableScrollIntoViewOptions) => void;
|
|
47
63
|
}
|
|
@@ -1,26 +1,46 @@
|
|
|
1
1
|
import type { RowData, Table } from '@tanstack/react-table';
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Virtualizer,
|
|
6
|
-
} from '@tanstack/react-virtual';
|
|
7
|
-
import { useImperativeHandle, useRef } from 'react';
|
|
2
|
+
import type { Virtualizer } from '@tanstack/react-virtual';
|
|
3
|
+
import type { RefObject } from 'react';
|
|
4
|
+
import { useImperativeHandle } from 'react';
|
|
8
5
|
|
|
6
|
+
import { useFlashedRowContext } from './flash_row/flashed_row_context.js';
|
|
9
7
|
import type { TableProps } from './table_root.js';
|
|
8
|
+
import type { TableVirtualScrollIntoViewOptions } from './table_utils.js';
|
|
10
9
|
|
|
11
|
-
export function useTableScroll<TData extends RowData>(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
export function useTableScroll<TData extends RowData>(options: {
|
|
11
|
+
/**
|
|
12
|
+
* The user provided ref to attach the scroll callbacks to.
|
|
13
|
+
*/
|
|
14
|
+
scrollToRowRef: TableProps<TData>['scrollToRowRef'];
|
|
15
|
+
/**
|
|
16
|
+
* Whether the table rows are virtualized.
|
|
17
|
+
*/
|
|
18
|
+
virtualizeRows: TableProps<TData>['virtualizeRows'];
|
|
19
|
+
/**
|
|
20
|
+
* A ref to the effective scroll container.
|
|
21
|
+
*/
|
|
22
|
+
scrollRef: RefObject<Element>;
|
|
23
|
+
/*
|
|
24
|
+
Tanstack table instance.
|
|
25
|
+
*/
|
|
26
|
+
table: Table<TData>;
|
|
27
|
+
/**
|
|
28
|
+
* Tanstack virtualizer instance.
|
|
29
|
+
*/
|
|
30
|
+
virtualizer: Virtualizer<HTMLDivElement, Element>;
|
|
31
|
+
}) {
|
|
32
|
+
const [, setFlashedRow] = useFlashedRowContext();
|
|
33
|
+
const { scrollToRowRef, virtualizeRows, scrollRef, table, virtualizer } =
|
|
34
|
+
options;
|
|
18
35
|
|
|
19
36
|
// @ts-expect-error We cannot call the hook conditionally to satisfy the type checker
|
|
20
37
|
useImperativeHandle(scrollToRowRef, () => {
|
|
21
38
|
if (virtualizeRows) {
|
|
22
39
|
return {
|
|
23
|
-
scrollIntoView(
|
|
40
|
+
scrollIntoView(
|
|
41
|
+
id: string,
|
|
42
|
+
options?: TableVirtualScrollIntoViewOptions,
|
|
43
|
+
) {
|
|
24
44
|
const sortedRows = table.getRowModel().rows; // Get sorted rows
|
|
25
45
|
const rowIndex = sortedRows.findIndex((row) => row.id === id); // Find the index of the row by ID
|
|
26
46
|
if (rowIndex === -1) {
|
|
@@ -29,14 +49,21 @@ export function useTableScroll<TData extends RowData>(
|
|
|
29
49
|
console.warn(
|
|
30
50
|
`Could not scroll to row with ID ${id}, the row does not exist`,
|
|
31
51
|
);
|
|
52
|
+
} else {
|
|
53
|
+
virtualizer.scrollToIndex(rowIndex, options);
|
|
54
|
+
if (options?.flashRow && options.behavior !== 'smooth') {
|
|
55
|
+
setFlashedRow(sortedRows[rowIndex].id);
|
|
56
|
+
}
|
|
32
57
|
}
|
|
33
|
-
virtualizer.scrollToIndex(rowIndex, options);
|
|
34
58
|
},
|
|
35
59
|
};
|
|
36
60
|
} else {
|
|
37
61
|
return {
|
|
38
|
-
scrollIntoView(
|
|
39
|
-
|
|
62
|
+
scrollIntoView(
|
|
63
|
+
id: string,
|
|
64
|
+
options?: TableVirtualScrollIntoViewOptions,
|
|
65
|
+
) {
|
|
66
|
+
const element = scrollRef.current?.querySelector(
|
|
40
67
|
`tr[data-row-id="${id}"]`,
|
|
41
68
|
);
|
|
42
69
|
if (!element) {
|
|
@@ -46,10 +73,11 @@ export function useTableScroll<TData extends RowData>(
|
|
|
46
73
|
);
|
|
47
74
|
}
|
|
48
75
|
element?.scrollIntoView(options);
|
|
76
|
+
if (options?.flashRow && options.behavior !== 'smooth') {
|
|
77
|
+
setFlashedRow(id);
|
|
78
|
+
}
|
|
49
79
|
},
|
|
50
80
|
};
|
|
51
81
|
}
|
|
52
|
-
}, [virtualizeRows, table, virtualizer]);
|
|
53
|
-
|
|
54
|
-
return tableRef;
|
|
82
|
+
}, [virtualizeRows, scrollRef, table, virtualizer, setFlashedRow]);
|
|
55
83
|
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export declare const droppedItemContext: import("react").Context<[string | undefined, import("react").Dispatch<import("react").SetStateAction<string | undefined>>] | null>;
|
|
2
|
-
export declare function useDroppedItemContext(): [string | undefined, import("react").Dispatch<import("react").SetStateAction<string | undefined>>];
|
|
3
|
-
//# sourceMappingURL=dropped_item_context.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dropped_item_context.d.ts","sourceRoot":"","sources":["../../../../src/components/table/reorder_rows/dropped_item_context.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,kBAAkB,oIAE9B,CAAC;AAEF,wBAAgB,qBAAqB,uGAUpC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { createContext, useContext } from 'react';
|
|
2
|
-
export const droppedItemContext = createContext(null);
|
|
3
|
-
export function useDroppedItemContext() {
|
|
4
|
-
const context = useContext(droppedItemContext);
|
|
5
|
-
if (!context) {
|
|
6
|
-
throw new Error('useDroppedItemId must be used within a DroppedItemProvider');
|
|
7
|
-
}
|
|
8
|
-
return context;
|
|
9
|
-
}
|
|
10
|
-
//# sourceMappingURL=dropped_item_context.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dropped_item_context.js","sourceRoot":"","sources":["../../../../src/components/table/reorder_rows/dropped_item_context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAOlD,MAAM,CAAC,MAAM,kBAAkB,GAAG,aAAa,CAC7C,IAAI,CACL,CAAC;AAEF,MAAM,UAAU,qBAAqB;IACnC,MAAM,OAAO,GAAG,UAAU,CAAC,kBAAkB,CAAC,CAAC;IAE/C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACb,4DAA4D,CAC7D,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dropped_item_provider.d.ts","sourceRoot":"","sources":["../../../../src/components/table/reorder_rows/dropped_item_provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIvC,wBAAgB,mBAAmB,CAAC,KAAK,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,2CAOjE"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useState } from 'react';
|
|
3
|
-
import { droppedItemContext } from './dropped_item_context.js';
|
|
4
|
-
export function DroppedItemProvider(props) {
|
|
5
|
-
const value = useState();
|
|
6
|
-
return (_jsx(droppedItemContext.Provider, { value: value, children: props.children }));
|
|
7
|
-
}
|
|
8
|
-
//# sourceMappingURL=dropped_item_provider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dropped_item_provider.js","sourceRoot":"","sources":["../../../../src/components/table/reorder_rows/dropped_item_provider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D,MAAM,UAAU,mBAAmB,CAAC,KAA8B;IAChE,MAAM,KAAK,GAAG,QAAQ,EAAU,CAAC;IACjC,OAAO,CACL,KAAC,kBAAkB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YACtC,KAAK,CAAC,QAAQ,GACa,CAC/B,CAAC;AACJ,CAAC"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { useState } from 'react';
|
|
2
|
-
import { createContext, useContext } from 'react';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* ID of the dropped item
|
|
6
|
-
*/
|
|
7
|
-
type DroppedItemContextValue = ReturnType<typeof useState<string>>;
|
|
8
|
-
|
|
9
|
-
export const droppedItemContext = createContext<DroppedItemContextValue | null>(
|
|
10
|
-
null,
|
|
11
|
-
);
|
|
12
|
-
|
|
13
|
-
export function useDroppedItemContext() {
|
|
14
|
-
const context = useContext(droppedItemContext);
|
|
15
|
-
|
|
16
|
-
if (!context) {
|
|
17
|
-
throw new Error(
|
|
18
|
-
'useDroppedItemId must be used within a DroppedItemProvider',
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return context;
|
|
23
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { useState } from 'react';
|
|
2
|
-
import type { ReactNode } from 'react';
|
|
3
|
-
|
|
4
|
-
import { droppedItemContext } from './dropped_item_context.js';
|
|
5
|
-
|
|
6
|
-
export function DroppedItemProvider(props: { children: ReactNode }) {
|
|
7
|
-
const value = useState<string>();
|
|
8
|
-
return (
|
|
9
|
-
<droppedItemContext.Provider value={value}>
|
|
10
|
-
{props.children}
|
|
11
|
-
</droppedItemContext.Provider>
|
|
12
|
-
);
|
|
13
|
-
}
|