@wallarm-org/design-system 1.16.0 → 1.18.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/Table/EditableCell/EditableSelectCell.js +15 -9
- package/dist/components/Table/StickyGroupParent.d.ts +7 -0
- package/dist/components/Table/StickyGroupParent.js +124 -0
- package/dist/components/Table/TableBody/TableBody.js +16 -13
- package/dist/components/Table/TableBody/TableBodyCell.d.ts +4 -1
- package/dist/components/Table/TableBody/TableBodyCell.js +4 -2
- package/dist/components/Table/TableBody/TableBodyRowDndContext.d.ts +6 -0
- package/dist/components/Table/TableBody/TableBodyRowDndContext.js +68 -0
- package/dist/components/Table/TableBody/TableBodyVirtualizedCore.js +42 -39
- package/dist/components/Table/TableBody/TableRowOverlay.d.ts +8 -0
- package/dist/components/Table/TableBody/TableRowOverlay.js +36 -0
- package/dist/components/Table/TableColGroup.js +3 -2
- package/dist/components/Table/TableContext/TableProvider.js +20 -5
- package/dist/components/Table/TableContext/types.d.ts +6 -1
- package/dist/components/Table/TableInner/TableInnerContainer.js +8 -1
- package/dist/components/Table/TableInner/TableInnerWindow.js +8 -1
- package/dist/components/Table/TableRow.js +28 -9
- package/dist/components/Table/TableRowExpanded.d.ts +4 -1
- package/dist/components/Table/TableRowExpanded.js +2 -1
- package/dist/components/Table/TableSettingsMenu/TableSettingsMenu.js +2 -2
- package/dist/components/Table/hooks/index.d.ts +1 -0
- package/dist/components/Table/hooks/index.js +1 -0
- package/dist/components/Table/hooks/useStickyGroupParent.d.ts +19 -0
- package/dist/components/Table/hooks/useStickyGroupParent.js +147 -0
- package/dist/components/Table/index.d.ts +1 -1
- package/dist/components/Table/lib/constants.d.ts +2 -0
- package/dist/components/Table/lib/constants.js +3 -1
- package/dist/components/Table/lib/createDragHandleColumn.d.ts +8 -0
- package/dist/components/Table/lib/createDragHandleColumn.js +23 -0
- package/dist/components/Table/lib/createSelectionColumn.js +7 -2
- package/dist/components/Table/lib/index.d.ts +3 -1
- package/dist/components/Table/lib/index.js +3 -1
- package/dist/components/Table/lib/useRowDnd.d.ts +15 -0
- package/dist/components/Table/lib/useRowDnd.js +32 -0
- package/dist/components/Table/types.d.ts +33 -0
- package/dist/metadata/components.json +44 -4
- package/package.json +1 -1
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useMemo } from "react";
|
|
3
3
|
import { Select } from "@ark-ui/react/select";
|
|
4
|
+
import { ChevronDown } from "../../../icons/index.js";
|
|
4
5
|
import { cn } from "../../../utils/cn.js";
|
|
5
6
|
import { useTestId } from "../../../utils/testId.js";
|
|
6
7
|
import { Select as index_js_Select, SelectContent, SelectOption, SelectOptionIndicator, SelectOptionText, SelectPositioner, createListCollection } from "../../Select/index.js";
|
|
7
|
-
import { editableCellPlaceholder, editableCellValue, editableCellVariants } from "./classes.js";
|
|
8
|
+
import { editableCellIcon, editableCellPlaceholder, editableCellValue, editableCellVariants } from "./classes.js";
|
|
8
9
|
const EditableSelectCell = ({ value, onCommit, items, children, placeholder = 'Select…', className, ref, 'data-testid': testIdProp, ...rest })=>{
|
|
9
10
|
const testId = useTestId(void 0, testIdProp);
|
|
10
11
|
const collection = useMemo(()=>createListCollection({
|
|
@@ -29,20 +30,25 @@ const EditableSelectCell = ({ value, onCommit, items, children, placeholder = 'S
|
|
|
29
30
|
className: "h-full",
|
|
30
31
|
children: /*#__PURE__*/ jsx(Select.Trigger, {
|
|
31
32
|
asChild: true,
|
|
32
|
-
children: /*#__PURE__*/
|
|
33
|
+
children: /*#__PURE__*/ jsxs("div", {
|
|
33
34
|
...rest,
|
|
34
35
|
ref: ref,
|
|
35
36
|
"data-slot": "editable-select-cell",
|
|
36
37
|
className: cn(editableCellVariants({
|
|
37
38
|
state: 'idle'
|
|
38
39
|
}), 'data-[state=open]:border-border-strong-brand data-[state=open]:bg-bg-surface-1 data-[state=open]:hover:bg-bg-surface-1', className),
|
|
39
|
-
children:
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
children: [
|
|
41
|
+
hasValue ? /*#__PURE__*/ jsx("span", {
|
|
42
|
+
className: editableCellValue,
|
|
43
|
+
children: children
|
|
44
|
+
}) : /*#__PURE__*/ jsx("span", {
|
|
45
|
+
className: editableCellPlaceholder,
|
|
46
|
+
children: placeholder
|
|
47
|
+
}),
|
|
48
|
+
/*#__PURE__*/ jsx(ChevronDown, {
|
|
49
|
+
className: cn(editableCellIcon, 'transition-transform group-data-[state=open]/cell:rotate-180')
|
|
50
|
+
})
|
|
51
|
+
]
|
|
46
52
|
})
|
|
47
53
|
})
|
|
48
54
|
}),
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef } from "react";
|
|
3
|
+
import { cn } from "../../utils/cn.js";
|
|
4
|
+
import { useStickyGroupParent } from "./hooks/index.js";
|
|
5
|
+
import { TABLE_DRAG_HANDLE_COLUMN_ID, TABLE_EXPAND_COLUMN_ID, TABLE_SELECT_COLUMN_ID } from "./lib/index.js";
|
|
6
|
+
import { Td, Tr } from "./primitives/index.js";
|
|
7
|
+
import { TableBodyCell } from "./TableBody/TableBodyCell.js";
|
|
8
|
+
import { TableColGroup } from "./TableColGroup.js";
|
|
9
|
+
import { useTableContext } from "./TableContext/index.js";
|
|
10
|
+
const SYSTEM_COLUMN_IDS = new Set([
|
|
11
|
+
TABLE_EXPAND_COLUMN_ID,
|
|
12
|
+
TABLE_SELECT_COLUMN_ID,
|
|
13
|
+
TABLE_DRAG_HANDLE_COLUMN_ID
|
|
14
|
+
]);
|
|
15
|
+
const StickyGroupParent = ({ tableWidth, headerHeight })=>{
|
|
16
|
+
const { table, containerRef, tbodyRef, virtualizerRef, virtualized } = useTableContext();
|
|
17
|
+
const useWindowScroll = 'window' === virtualized;
|
|
18
|
+
const { stickyRow, pushUpOffset } = useStickyGroupParent({
|
|
19
|
+
table,
|
|
20
|
+
scrollElementRef: containerRef,
|
|
21
|
+
useWindowScroll,
|
|
22
|
+
headerHeight,
|
|
23
|
+
tbodyRef,
|
|
24
|
+
virtualizerRef,
|
|
25
|
+
enabled: true
|
|
26
|
+
});
|
|
27
|
+
const rowRef = useRef(null);
|
|
28
|
+
const prevExpandedRef = useRef(null);
|
|
29
|
+
const prevStickyIdRef = useRef(null);
|
|
30
|
+
useEffect(()=>{
|
|
31
|
+
if (!stickyRow) {
|
|
32
|
+
prevExpandedRef.current = null;
|
|
33
|
+
prevStickyIdRef.current = null;
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const isExpanded = stickyRow.getIsExpanded();
|
|
37
|
+
const isSameRow = prevStickyIdRef.current === stickyRow.id;
|
|
38
|
+
if (isSameRow && true === prevExpandedRef.current && !isExpanded) {
|
|
39
|
+
const scrollElement = containerRef.current;
|
|
40
|
+
if (scrollElement) {
|
|
41
|
+
const tbodyEl = tbodyRef.current;
|
|
42
|
+
if (tbodyEl) {
|
|
43
|
+
const rowEl = tbodyEl.querySelector(`[data-row-id="${stickyRow.id}"]`);
|
|
44
|
+
if (rowEl instanceof HTMLElement) if (useWindowScroll) {
|
|
45
|
+
const rect = rowEl.getBoundingClientRect();
|
|
46
|
+
window.scrollTo({
|
|
47
|
+
top: window.scrollY + rect.top - headerHeight
|
|
48
|
+
});
|
|
49
|
+
} else scrollElement.scrollTop = rowEl.offsetTop + (tbodyEl.offsetTop || 0) - headerHeight;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
prevExpandedRef.current = isExpanded;
|
|
54
|
+
prevStickyIdRef.current = stickyRow.id;
|
|
55
|
+
}, [
|
|
56
|
+
stickyRow,
|
|
57
|
+
containerRef,
|
|
58
|
+
tbodyRef,
|
|
59
|
+
useWindowScroll,
|
|
60
|
+
headerHeight
|
|
61
|
+
]);
|
|
62
|
+
if (!stickyRow) return null;
|
|
63
|
+
const cells = stickyRow.getVisibleCells();
|
|
64
|
+
const systemCells = cells.filter((c)=>SYSTEM_COLUMN_IDS.has(c.column.id));
|
|
65
|
+
const dataCells = cells.filter((c)=>!SYSTEM_COLUMN_IDS.has(c.column.id));
|
|
66
|
+
const firstDataCell = dataCells[0];
|
|
67
|
+
const isSelected = stickyRow.getIsAllSubRowsSelected();
|
|
68
|
+
return /*#__PURE__*/ jsx("div", {
|
|
69
|
+
className: "sticky z-20 h-0 overflow-visible pointer-events-none",
|
|
70
|
+
style: {
|
|
71
|
+
top: headerHeight
|
|
72
|
+
},
|
|
73
|
+
"aria-hidden": "true",
|
|
74
|
+
children: /*#__PURE__*/ jsx("div", {
|
|
75
|
+
className: "overflow-hidden",
|
|
76
|
+
style: {
|
|
77
|
+
height: rowRef.current?.offsetHeight ?? 40
|
|
78
|
+
},
|
|
79
|
+
children: /*#__PURE__*/ jsx("div", {
|
|
80
|
+
style: {
|
|
81
|
+
transform: pushUpOffset ? `translateY(${pushUpOffset}px)` : void 0
|
|
82
|
+
},
|
|
83
|
+
children: /*#__PURE__*/ jsxs("table", {
|
|
84
|
+
className: "table-fixed border-separate border-spacing-0 pointer-events-auto",
|
|
85
|
+
style: {
|
|
86
|
+
width: tableWidth
|
|
87
|
+
},
|
|
88
|
+
children: [
|
|
89
|
+
/*#__PURE__*/ jsx(TableColGroup, {
|
|
90
|
+
tableWidth: tableWidth
|
|
91
|
+
}),
|
|
92
|
+
/*#__PURE__*/ jsx("tbody", {
|
|
93
|
+
children: /*#__PURE__*/ jsxs(Tr, {
|
|
94
|
+
ref: rowRef,
|
|
95
|
+
className: "group/row",
|
|
96
|
+
"data-selected": isSelected || void 0,
|
|
97
|
+
children: [
|
|
98
|
+
systemCells.map((cell)=>/*#__PURE__*/ jsx(TableBodyCell, {
|
|
99
|
+
cell: cell,
|
|
100
|
+
disablePinnedShadow: true
|
|
101
|
+
}, cell.id)),
|
|
102
|
+
firstDataCell && /*#__PURE__*/ jsx(TableBodyCell, {
|
|
103
|
+
cell: firstDataCell,
|
|
104
|
+
className: "border-r-0",
|
|
105
|
+
disablePinnedShadow: true
|
|
106
|
+
}),
|
|
107
|
+
dataCells.slice(1).map((cell)=>/*#__PURE__*/ jsx(Td, {
|
|
108
|
+
className: cn('border-b border-border-primary-light bg-bg-surface-2 overlay', 'group-hover/row:overlay-states-primary-hover group-data-[selected]/row:overlay-states-primary-active'),
|
|
109
|
+
style: {
|
|
110
|
+
width: cell.column.getSize()
|
|
111
|
+
},
|
|
112
|
+
"aria-hidden": "true"
|
|
113
|
+
}, cell.id))
|
|
114
|
+
]
|
|
115
|
+
})
|
|
116
|
+
})
|
|
117
|
+
]
|
|
118
|
+
})
|
|
119
|
+
})
|
|
120
|
+
})
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
StickyGroupParent.displayName = 'StickyGroupParent';
|
|
124
|
+
export { StickyGroupParent };
|
|
@@ -5,6 +5,7 @@ import { TBody } from "../primitives/index.js";
|
|
|
5
5
|
import { useTableContext } from "../TableContext/index.js";
|
|
6
6
|
import { TableLoadingState } from "../TableLoadingState.js";
|
|
7
7
|
import { TableRow } from "../TableRow.js";
|
|
8
|
+
import { TableBodyRowDndContext } from "./TableBodyRowDndContext.js";
|
|
8
9
|
import { TableBodyVirtualizedContainer } from "./TableBodyVirtualizedContainer.js";
|
|
9
10
|
import { TableBodyVirtualizedWindow } from "./TableBodyVirtualizedWindow.js";
|
|
10
11
|
const TableBody = ()=>{
|
|
@@ -17,19 +18,21 @@ const TableBody = ()=>{
|
|
|
17
18
|
return /*#__PURE__*/ jsx(TableBodyVirtualizedContainer, {});
|
|
18
19
|
}
|
|
19
20
|
virtualizerRef.current = null;
|
|
20
|
-
return /*#__PURE__*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
21
|
+
return /*#__PURE__*/ jsx(TableBodyRowDndContext, {
|
|
22
|
+
children: /*#__PURE__*/ jsxs(TBody, {
|
|
23
|
+
ref: tbodyRef,
|
|
24
|
+
"data-testid": testId,
|
|
25
|
+
children: [
|
|
26
|
+
isLoadingPrevious && /*#__PURE__*/ jsx(TableLoadingState, {
|
|
27
|
+
position: "start",
|
|
28
|
+
count: TABLE_PREPEND_SKELETON_ROWS
|
|
29
|
+
}),
|
|
30
|
+
rows.map((row)=>/*#__PURE__*/ jsx(TableRow, {
|
|
31
|
+
row: row
|
|
32
|
+
}, row.id)),
|
|
33
|
+
isLoading && /*#__PURE__*/ jsx(TableLoadingState, {})
|
|
34
|
+
]
|
|
35
|
+
})
|
|
33
36
|
});
|
|
34
37
|
};
|
|
35
38
|
TableBody.displayName = 'TableBody';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { useSortable } from '@dnd-kit/sortable';
|
|
1
2
|
import { type Cell, type RowData } from '@tanstack/react-table';
|
|
2
3
|
import { type DSTableFeatures } from '../lib';
|
|
3
4
|
interface TableBodyCellProps<T extends RowData> {
|
|
@@ -5,8 +6,10 @@ interface TableBodyCellProps<T extends RowData> {
|
|
|
5
6
|
colSpan?: number;
|
|
6
7
|
className?: string;
|
|
7
8
|
disablePinnedShadow?: boolean;
|
|
9
|
+
dragListeners?: ReturnType<typeof useSortable>['listeners'];
|
|
10
|
+
dragAttributes?: ReturnType<typeof useSortable>['attributes'];
|
|
8
11
|
}
|
|
9
|
-
export declare function TableBodyCell<T extends RowData>({ cell, colSpan, className, disablePinnedShadow, }: TableBodyCellProps<T>): import("react").JSX.Element;
|
|
12
|
+
export declare function TableBodyCell<T extends RowData>({ cell, colSpan, className, disablePinnedShadow, dragListeners, dragAttributes, }: TableBodyCellProps<T>): import("react").JSX.Element;
|
|
10
13
|
export declare namespace TableBodyCell {
|
|
11
14
|
var displayName: string;
|
|
12
15
|
}
|
|
@@ -8,7 +8,7 @@ import { TABLE_EXPAND_COLUMN_ID, getAlignClass, getExpandBorderClass, getPinning
|
|
|
8
8
|
import { Td } from "../primitives/index.js";
|
|
9
9
|
import { useTableContext } from "../TableContext/index.js";
|
|
10
10
|
import { TableMasterCellActions } from "../TableMasterCellActions.js";
|
|
11
|
-
const TableBodyCell = ({ cell, colSpan, className, disablePinnedShadow })=>{
|
|
11
|
+
const TableBodyCell = ({ cell, colSpan, className, disablePinnedShadow, dragListeners, dragAttributes })=>{
|
|
12
12
|
const { allLeafColumns, masterColumnId } = useTableContext();
|
|
13
13
|
const testId = useTestId('body-cell');
|
|
14
14
|
const column = cell.column;
|
|
@@ -61,7 +61,7 @@ const TableBodyCell = ({ cell, colSpan, className, disablePinnedShadow })=>{
|
|
|
61
61
|
};
|
|
62
62
|
return /*#__PURE__*/ jsx(Td, {
|
|
63
63
|
"data-testid": testId,
|
|
64
|
-
className: cn(getAlignClass(meta), getExpandBorderClass(isExpandColumn, cell.row.depth), isCut && 'pr-0', (isMasterTrigger || tooltipText) && 'cursor-pointer', meta?.cellClassName, className),
|
|
64
|
+
className: cn(getAlignClass(meta), getExpandBorderClass(isExpandColumn, cell.row.depth), isCut && 'pr-0', (isMasterTrigger || tooltipText) && 'cursor-pointer', dragListeners && 'cursor-grab active:cursor-grabbing', meta?.cellClassName, className),
|
|
65
65
|
pinned: 'start' === isPinned,
|
|
66
66
|
lastPinnedLeft: disablePinnedShadow ? false : lastLeft,
|
|
67
67
|
expanded: isExpandedToggle,
|
|
@@ -76,6 +76,8 @@ const TableBodyCell = ({ cell, colSpan, className, disablePinnedShadow })=>{
|
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
78
|
colSpan: colSpan,
|
|
79
|
+
...dragListeners,
|
|
80
|
+
...dragAttributes,
|
|
79
81
|
children: renderContent()
|
|
80
82
|
});
|
|
81
83
|
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useMemo, useState } from "react";
|
|
3
|
+
import { DndContext, DragOverlay, KeyboardSensor, PointerSensor, closestCenter, useSensor, useSensors } from "@dnd-kit/core";
|
|
4
|
+
import { SortableContext, verticalListSortingStrategy } from "@dnd-kit/sortable";
|
|
5
|
+
import { useTableContext } from "../TableContext/index.js";
|
|
6
|
+
import { TableRowOverlay } from "./TableRowOverlay.js";
|
|
7
|
+
const TableBodyRowDndContext = ({ children })=>{
|
|
8
|
+
const { rowDndEnabled, onRowReorder } = useTableContext();
|
|
9
|
+
if (!rowDndEnabled) return children;
|
|
10
|
+
return /*#__PURE__*/ jsx(TableBodyRowDndContextInner, {
|
|
11
|
+
onRowReorder: onRowReorder,
|
|
12
|
+
children: children
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
const TableBodyRowDndContextInner = ({ children, onRowReorder })=>{
|
|
16
|
+
const { table } = useTableContext();
|
|
17
|
+
const rows = table.getRowModel().rows;
|
|
18
|
+
const rowIds = useMemo(()=>rows.map((r)=>r.id), [
|
|
19
|
+
rows
|
|
20
|
+
]);
|
|
21
|
+
const [activeRow, setActiveRow] = useState(null);
|
|
22
|
+
const sensors = useSensors(useSensor(PointerSensor, {
|
|
23
|
+
activationConstraint: {
|
|
24
|
+
distance: 5
|
|
25
|
+
}
|
|
26
|
+
}), useSensor(KeyboardSensor));
|
|
27
|
+
const handleDragStart = useCallback((event)=>{
|
|
28
|
+
const row = rows.find((r)=>r.id === String(event.active.id));
|
|
29
|
+
setActiveRow(row ?? null);
|
|
30
|
+
}, [
|
|
31
|
+
rows
|
|
32
|
+
]);
|
|
33
|
+
const handleDragEnd = useCallback((event)=>{
|
|
34
|
+
setActiveRow(null);
|
|
35
|
+
const { active, over } = event;
|
|
36
|
+
if (!over || active.id === over.id) return;
|
|
37
|
+
onRowReorder?.({
|
|
38
|
+
activeRowId: String(active.id),
|
|
39
|
+
overRowId: String(over.id)
|
|
40
|
+
});
|
|
41
|
+
}, [
|
|
42
|
+
onRowReorder
|
|
43
|
+
]);
|
|
44
|
+
const handleDragCancel = useCallback(()=>{
|
|
45
|
+
setActiveRow(null);
|
|
46
|
+
}, []);
|
|
47
|
+
return /*#__PURE__*/ jsxs(DndContext, {
|
|
48
|
+
sensors: sensors,
|
|
49
|
+
collisionDetection: closestCenter,
|
|
50
|
+
onDragStart: handleDragStart,
|
|
51
|
+
onDragEnd: handleDragEnd,
|
|
52
|
+
onDragCancel: handleDragCancel,
|
|
53
|
+
children: [
|
|
54
|
+
/*#__PURE__*/ jsx(SortableContext, {
|
|
55
|
+
items: rowIds,
|
|
56
|
+
strategy: verticalListSortingStrategy,
|
|
57
|
+
children: children
|
|
58
|
+
}),
|
|
59
|
+
/*#__PURE__*/ jsx(DragOverlay, {
|
|
60
|
+
children: activeRow ? /*#__PURE__*/ jsx(TableRowOverlay, {
|
|
61
|
+
row: activeRow
|
|
62
|
+
}) : null
|
|
63
|
+
})
|
|
64
|
+
]
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
TableBodyRowDndContext.displayName = 'TableBodyRowDndContext';
|
|
68
|
+
export { TableBodyRowDndContext };
|
|
@@ -5,6 +5,7 @@ import { TBody, Td, Tr } from "../primitives/index.js";
|
|
|
5
5
|
import { useTableContext } from "../TableContext/index.js";
|
|
6
6
|
import { TableLoadingState } from "../TableLoadingState.js";
|
|
7
7
|
import { TableRow } from "../TableRow.js";
|
|
8
|
+
import { TableBodyRowDndContext } from "./TableBodyRowDndContext.js";
|
|
8
9
|
const TableBodyVirtualizedCore = ({ tbodyRef, virtualizer })=>{
|
|
9
10
|
const { table, isLoading, isLoadingPrevious } = useTableContext();
|
|
10
11
|
const testId = useTestId('body');
|
|
@@ -14,45 +15,47 @@ const TableBodyVirtualizedCore = ({ tbodyRef, virtualizer })=>{
|
|
|
14
15
|
const rows = table.getRowModel().rows;
|
|
15
16
|
const colSpan = table.getVisibleLeafColumns().length;
|
|
16
17
|
const scrollMargin = virtualizer.options.scrollMargin;
|
|
17
|
-
return /*#__PURE__*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
row
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
18
|
+
return /*#__PURE__*/ jsx(TableBodyRowDndContext, {
|
|
19
|
+
children: /*#__PURE__*/ jsxs(TBody, {
|
|
20
|
+
ref: tbodyRef,
|
|
21
|
+
"data-testid": testId,
|
|
22
|
+
children: [
|
|
23
|
+
isLoadingPrevious && /*#__PURE__*/ jsx(TableLoadingState, {
|
|
24
|
+
position: "start",
|
|
25
|
+
count: TABLE_PREPEND_SKELETON_ROWS
|
|
26
|
+
}),
|
|
27
|
+
virtualRows.length > 0 && /*#__PURE__*/ jsx(Tr, {
|
|
28
|
+
children: /*#__PURE__*/ jsx(Td, {
|
|
29
|
+
style: {
|
|
30
|
+
height: `${(virtualRows[0]?.start ?? 0) - scrollMargin}px`,
|
|
31
|
+
padding: 0,
|
|
32
|
+
border: 'none'
|
|
33
|
+
},
|
|
34
|
+
colSpan: colSpan
|
|
35
|
+
})
|
|
36
|
+
}, "spacer-top"),
|
|
37
|
+
virtualRows.map((virtualRow)=>{
|
|
38
|
+
const row = rows.at(virtualRow.index);
|
|
39
|
+
if (row) return /*#__PURE__*/ jsx(TableRow, {
|
|
40
|
+
row: row,
|
|
41
|
+
"data-index": virtualRow.index,
|
|
42
|
+
ref: measureElement
|
|
43
|
+
}, row.id);
|
|
44
|
+
return null;
|
|
45
|
+
}),
|
|
46
|
+
isLoading && /*#__PURE__*/ jsx(TableLoadingState, {}),
|
|
47
|
+
virtualRows.length > 0 && /*#__PURE__*/ jsx(Tr, {
|
|
48
|
+
children: /*#__PURE__*/ jsx(Td, {
|
|
49
|
+
style: {
|
|
50
|
+
height: `${totalSize - (virtualRows[virtualRows.length - 1]?.end ?? 0)}px`,
|
|
51
|
+
padding: 0,
|
|
52
|
+
border: 'none'
|
|
53
|
+
},
|
|
54
|
+
colSpan: colSpan
|
|
55
|
+
})
|
|
56
|
+
}, "spacer-bottom")
|
|
57
|
+
]
|
|
58
|
+
})
|
|
56
59
|
});
|
|
57
60
|
};
|
|
58
61
|
TableBodyVirtualizedCore.displayName = 'TableBodyVirtualizedCore';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { FC } from 'react';
|
|
2
|
+
import { type Row, type RowData } from '@tanstack/react-table';
|
|
3
|
+
import { type DSTableFeatures } from '../lib';
|
|
4
|
+
interface TableRowOverlayProps<T extends RowData> {
|
|
5
|
+
row: Row<DSTableFeatures, T>;
|
|
6
|
+
}
|
|
7
|
+
export declare const TableRowOverlay: FC<TableRowOverlayProps<RowData>>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { flexRender } from "@tanstack/react-table";
|
|
3
|
+
import { cn } from "../../../utils/cn.js";
|
|
4
|
+
import { getAlignClass } from "../lib/index.js";
|
|
5
|
+
import { Td, Tr } from "../primitives/index.js";
|
|
6
|
+
import { useTableContext } from "../TableContext/index.js";
|
|
7
|
+
const TableRowOverlayInner = ({ row })=>{
|
|
8
|
+
const { table } = useTableContext();
|
|
9
|
+
const visibleColumns = table.getVisibleLeafColumns();
|
|
10
|
+
return /*#__PURE__*/ jsx("table", {
|
|
11
|
+
className: "w-full table-fixed border-collapse",
|
|
12
|
+
style: {
|
|
13
|
+
tableLayout: 'fixed'
|
|
14
|
+
},
|
|
15
|
+
children: /*#__PURE__*/ jsx("tbody", {
|
|
16
|
+
children: /*#__PURE__*/ jsx(Tr, {
|
|
17
|
+
className: "pointer-events-none shadow-lg opacity-90 bg-bg-primary",
|
|
18
|
+
children: row.getVisibleCells().map((cell)=>{
|
|
19
|
+
const column = visibleColumns.find((c)=>c.id === cell.column.id);
|
|
20
|
+
const meta = cell.column.columnDef.meta;
|
|
21
|
+
return /*#__PURE__*/ jsx(Td, {
|
|
22
|
+
pinned: false,
|
|
23
|
+
className: cn(getAlignClass(meta), meta?.cellClassName),
|
|
24
|
+
style: {
|
|
25
|
+
width: column?.getSize()
|
|
26
|
+
},
|
|
27
|
+
children: flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
28
|
+
}, cell.id);
|
|
29
|
+
})
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
const TableRowOverlay = TableRowOverlayInner;
|
|
35
|
+
TableRowOverlay.displayName = 'TableRowOverlay';
|
|
36
|
+
export { TableRowOverlay };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { TABLE_EXPAND_COLUMN_ID, TABLE_SELECT_COLUMN_ID } from "./lib/index.js";
|
|
2
|
+
import { TABLE_DRAG_HANDLE_COLUMN_ID, TABLE_EXPAND_COLUMN_ID, TABLE_SELECT_COLUMN_ID } from "./lib/index.js";
|
|
3
3
|
import { useTableContext } from "./TableContext/index.js";
|
|
4
4
|
const SYSTEM_COLUMN_IDS = new Set([
|
|
5
5
|
TABLE_SELECT_COLUMN_ID,
|
|
6
|
-
TABLE_EXPAND_COLUMN_ID
|
|
6
|
+
TABLE_EXPAND_COLUMN_ID,
|
|
7
|
+
TABLE_DRAG_HANDLE_COLUMN_ID
|
|
7
8
|
]);
|
|
8
9
|
const TableColGroup = ({ tableWidth })=>{
|
|
9
10
|
const { table } = useTableContext();
|
|
@@ -5,7 +5,7 @@ import { SortableContext, arrayMove, horizontalListSortingStrategy, sortableKeyb
|
|
|
5
5
|
import { useTable } from "@tanstack/react-table";
|
|
6
6
|
import { useControlled } from "../../../hooks/index.js";
|
|
7
7
|
import { useTableState } from "../hooks/index.js";
|
|
8
|
-
import { TABLE_EXPAND_COLUMN_ID, TABLE_MIN_COLUMN_WIDTH, TABLE_SELECT_COLUMN_ID, TABLE_SKELETON_ROWS, TABLE_VIRTUALIZATION_OVERSCAN, createExpandColumn, createSelectionColumn, dsTableFeatures } from "../lib/index.js";
|
|
8
|
+
import { TABLE_DRAG_HANDLE_COLUMN_ID, TABLE_EXPAND_COLUMN_ID, TABLE_MIN_COLUMN_WIDTH, TABLE_SELECT_COLUMN_ID, TABLE_SKELETON_ROWS, TABLE_VIRTUALIZATION_OVERSCAN, createDragHandleColumn, createExpandColumn, createSelectionColumn, dsTableFeatures } from "../lib/index.js";
|
|
9
9
|
import { TableContext } from "./TableContext.js";
|
|
10
10
|
const toTanStackPinning = (p, pinnedLeft)=>({
|
|
11
11
|
start: [
|
|
@@ -15,7 +15,7 @@ const toTanStackPinning = (p, pinnedLeft)=>({
|
|
|
15
15
|
end: p?.right ?? []
|
|
16
16
|
});
|
|
17
17
|
const TableProvider = (props)=>{
|
|
18
|
-
const { data, columns, isLoading = false, isLoadingPrevious = false, skeletonCount = TABLE_SKELETON_ROWS, children, getRowId, sorting: sortingProp, onSortingChange, manualSorting = false, rowSelection: rowSelectionProp, onRowSelectionChange, columnSizing: columnSizingProp, onColumnSizingChange, columnPinning: columnPinningProp, onColumnPinningChange, columnOrder: columnOrderProp, onColumnOrderChange, grouping: groupingProp, onGroupingChange, expanded: expandedProp, onExpandedChange, renderGroupRow, getSubRows, renderExpandedRow, columnVisibility: columnVisibilityProp, onColumnVisibilityChange, defaultColumnVisibility, defaultColumnOrder, columnGroups, virtualized, estimateRowHeight, overscan = TABLE_VIRTUALIZATION_OVERSCAN, onEndReached, onEndReachedThreshold, onStartReached, onStartReachedThreshold, initialScrollToRowId, onMasterCellClick, activeRowId: activeRowIdProp, onSettingsOpenChange } = props;
|
|
18
|
+
const { data, columns, isLoading = false, isLoadingPrevious = false, skeletonCount = TABLE_SKELETON_ROWS, children, getRowId, sorting: sortingProp, onSortingChange, manualSorting = false, rowSelection: rowSelectionProp, onRowSelectionChange, enableSelectAllRows = true, onSelectAllRows, columnSizing: columnSizingProp, onColumnSizingChange, columnPinning: columnPinningProp, onColumnPinningChange, columnOrder: columnOrderProp, onColumnOrderChange, grouping: groupingProp, onGroupingChange, expanded: expandedProp, onExpandedChange, renderGroupRow, getSubRows, renderExpandedRow, columnVisibility: columnVisibilityProp, onColumnVisibilityChange, defaultColumnVisibility, defaultColumnOrder, columnGroups, virtualized, estimateRowHeight, overscan = TABLE_VIRTUALIZATION_OVERSCAN, onEndReached, onEndReachedThreshold, onStartReached, onStartReachedThreshold, initialScrollToRowId, onRowReorder, onMasterCellClick, activeRowId: activeRowIdProp, onSettingsOpenChange } = props;
|
|
19
19
|
const masterCellActiveRowId = activeRowIdProp ?? null;
|
|
20
20
|
const sortingEnabled = !!onSortingChange;
|
|
21
21
|
const selectionEnabled = !!onRowSelectionChange;
|
|
@@ -24,6 +24,7 @@ const TableProvider = (props)=>{
|
|
|
24
24
|
const columnDndEnabled = !!onColumnOrderChange;
|
|
25
25
|
const groupingEnabled = !!groupingProp || !!onGroupingChange;
|
|
26
26
|
const subRowGroupingEnabled = !!renderGroupRow && !!getSubRows;
|
|
27
|
+
const rowDndEnabled = !!onRowReorder && !subRowGroupingEnabled;
|
|
27
28
|
const expandingEnabled = !!renderExpandedRow || !!onExpandedChange || subRowGroupingEnabled;
|
|
28
29
|
const visibilityEnabled = !!onColumnVisibilityChange;
|
|
29
30
|
const mergedColumns = useMemo(()=>{
|
|
@@ -31,6 +32,7 @@ const TableProvider = (props)=>{
|
|
|
31
32
|
const prefix = [];
|
|
32
33
|
if (expandingEnabled && !subRowGroupingEnabled) prefix.push(createExpandColumn());
|
|
33
34
|
if (selectionEnabled) prefix.push(createSelectionColumn());
|
|
35
|
+
if (rowDndEnabled) prefix.push(createDragHandleColumn());
|
|
34
36
|
const firstRow = data[0];
|
|
35
37
|
const withAutoMeta = cols.map((col)=>{
|
|
36
38
|
if (!firstRow || !('accessorKey' in col) || col.meta?.sortType) return col;
|
|
@@ -71,7 +73,8 @@ const TableProvider = (props)=>{
|
|
|
71
73
|
data,
|
|
72
74
|
selectionEnabled,
|
|
73
75
|
expandingEnabled,
|
|
74
|
-
subRowGroupingEnabled
|
|
76
|
+
subRowGroupingEnabled,
|
|
77
|
+
rowDndEnabled
|
|
75
78
|
]);
|
|
76
79
|
const masterColumnId = useMemo(()=>{
|
|
77
80
|
if (0 === columns.length) return null;
|
|
@@ -85,13 +88,15 @@ const TableProvider = (props)=>{
|
|
|
85
88
|
const ids = [];
|
|
86
89
|
if (expandingEnabled && !subRowGroupingEnabled) ids.push(TABLE_EXPAND_COLUMN_ID);
|
|
87
90
|
if (selectionEnabled) ids.push(TABLE_SELECT_COLUMN_ID);
|
|
91
|
+
if (rowDndEnabled) ids.push(TABLE_DRAG_HANDLE_COLUMN_ID);
|
|
88
92
|
if (masterColumnId) ids.push(masterColumnId);
|
|
89
93
|
return ids;
|
|
90
94
|
}, [
|
|
91
95
|
masterColumnId,
|
|
92
96
|
expandingEnabled,
|
|
93
97
|
selectionEnabled,
|
|
94
|
-
subRowGroupingEnabled
|
|
98
|
+
subRowGroupingEnabled,
|
|
99
|
+
rowDndEnabled
|
|
95
100
|
]);
|
|
96
101
|
const [sorting, handleSortingChange] = useTableState(sortingProp, [], onSortingChange);
|
|
97
102
|
const [rowSelection, handleRowSelectionChange] = useTableState(rowSelectionProp, {}, onRowSelectionChange);
|
|
@@ -191,9 +196,11 @@ const TableProvider = (props)=>{
|
|
|
191
196
|
resizingEnabled,
|
|
192
197
|
pinningEnabled,
|
|
193
198
|
columnDndEnabled,
|
|
199
|
+
rowDndEnabled,
|
|
194
200
|
groupingEnabled,
|
|
195
201
|
expandingEnabled,
|
|
196
202
|
visibilityEnabled,
|
|
203
|
+
hasSubRowGrouping: !!getSubRows,
|
|
197
204
|
virtualized,
|
|
198
205
|
renderExpandedRow: renderExpandedRow,
|
|
199
206
|
estimateRowHeight,
|
|
@@ -206,6 +213,8 @@ const TableProvider = (props)=>{
|
|
|
206
213
|
alwaysPinnedLeft,
|
|
207
214
|
masterColumnId,
|
|
208
215
|
lastSelectedRowIndexRef,
|
|
216
|
+
selectAllRowsEnabled: enableSelectAllRows,
|
|
217
|
+
onSelectAllRows,
|
|
209
218
|
containerRef,
|
|
210
219
|
tbodyRef,
|
|
211
220
|
virtualizerRef,
|
|
@@ -214,6 +223,7 @@ const TableProvider = (props)=>{
|
|
|
214
223
|
onStartReached,
|
|
215
224
|
onStartReachedThreshold,
|
|
216
225
|
initialScrollToRowId,
|
|
226
|
+
onRowReorder,
|
|
217
227
|
onMasterCellClick,
|
|
218
228
|
activeRowId: masterCellActiveRowId,
|
|
219
229
|
onSettingsOpenChange
|
|
@@ -227,9 +237,11 @@ const TableProvider = (props)=>{
|
|
|
227
237
|
resizingEnabled,
|
|
228
238
|
pinningEnabled,
|
|
229
239
|
columnDndEnabled,
|
|
240
|
+
rowDndEnabled,
|
|
230
241
|
groupingEnabled,
|
|
231
242
|
expandingEnabled,
|
|
232
243
|
visibilityEnabled,
|
|
244
|
+
getSubRows,
|
|
233
245
|
virtualized,
|
|
234
246
|
renderExpandedRow,
|
|
235
247
|
estimateRowHeight,
|
|
@@ -246,9 +258,12 @@ const TableProvider = (props)=>{
|
|
|
246
258
|
onStartReached,
|
|
247
259
|
onStartReachedThreshold,
|
|
248
260
|
initialScrollToRowId,
|
|
261
|
+
onRowReorder,
|
|
249
262
|
masterCellActiveRowId,
|
|
250
263
|
onMasterCellClick,
|
|
251
|
-
onSettingsOpenChange
|
|
264
|
+
onSettingsOpenChange,
|
|
265
|
+
enableSelectAllRows,
|
|
266
|
+
onSelectAllRows
|
|
252
267
|
]);
|
|
253
268
|
useEffect(()=>{
|
|
254
269
|
if (!selectionEnabled) return;
|
|
@@ -2,7 +2,7 @@ import type { ReactNode, RefObject } from 'react';
|
|
|
2
2
|
import type { Column, ColumnVisibilityState, ReactTable, Row, RowData } from '@tanstack/react-table';
|
|
3
3
|
import type { Virtualizer } from '@tanstack/react-virtual';
|
|
4
4
|
import type { DSTableFeatures } from '../lib';
|
|
5
|
-
import type { TableColumnGroup, TableProps, TableVirtualized } from '../types';
|
|
5
|
+
import type { TableColumnGroup, TableProps, TableRowReorderEvent, TableVirtualized } from '../types';
|
|
6
6
|
/**
|
|
7
7
|
* Union covers both virtualizer flavors used by the Table (`useVirtualizer`
|
|
8
8
|
* with HTMLElement scroll container and `useWindowVirtualizer` with Window).
|
|
@@ -19,9 +19,11 @@ export interface TableContextValue<T extends RowData> {
|
|
|
19
19
|
resizingEnabled: boolean;
|
|
20
20
|
pinningEnabled: boolean;
|
|
21
21
|
columnDndEnabled: boolean;
|
|
22
|
+
rowDndEnabled: boolean;
|
|
22
23
|
groupingEnabled: boolean;
|
|
23
24
|
expandingEnabled: boolean;
|
|
24
25
|
visibilityEnabled: boolean;
|
|
26
|
+
hasSubRowGrouping: boolean;
|
|
25
27
|
virtualized: TableVirtualized | undefined;
|
|
26
28
|
renderExpandedRow?: (row: Row<DSTableFeatures, T>) => ReactNode;
|
|
27
29
|
estimateRowHeight?: (index: number) => number;
|
|
@@ -32,6 +34,8 @@ export interface TableContextValue<T extends RowData> {
|
|
|
32
34
|
columnGroups?: TableColumnGroup[];
|
|
33
35
|
setColumnOrder: (order: string[]) => void;
|
|
34
36
|
lastSelectedRowIndexRef: RefObject<number | null>;
|
|
37
|
+
selectAllRowsEnabled: boolean;
|
|
38
|
+
onSelectAllRows?: (selected: boolean) => void;
|
|
35
39
|
alwaysPinnedLeft: string[];
|
|
36
40
|
masterColumnId: string | null;
|
|
37
41
|
containerRef: RefObject<HTMLDivElement | null>;
|
|
@@ -42,6 +46,7 @@ export interface TableContextValue<T extends RowData> {
|
|
|
42
46
|
onStartReached?: () => void;
|
|
43
47
|
onStartReachedThreshold?: number;
|
|
44
48
|
initialScrollToRowId?: string;
|
|
49
|
+
onRowReorder?: (event: TableRowReorderEvent) => void;
|
|
45
50
|
onMasterCellClick?: (rowId: string) => void;
|
|
46
51
|
activeRowId: string | null;
|
|
47
52
|
onSettingsOpenChange?: (open: boolean) => void;
|