@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.
Files changed (37) hide show
  1. package/dist/components/Table/EditableCell/EditableSelectCell.js +15 -9
  2. package/dist/components/Table/StickyGroupParent.d.ts +7 -0
  3. package/dist/components/Table/StickyGroupParent.js +124 -0
  4. package/dist/components/Table/TableBody/TableBody.js +16 -13
  5. package/dist/components/Table/TableBody/TableBodyCell.d.ts +4 -1
  6. package/dist/components/Table/TableBody/TableBodyCell.js +4 -2
  7. package/dist/components/Table/TableBody/TableBodyRowDndContext.d.ts +6 -0
  8. package/dist/components/Table/TableBody/TableBodyRowDndContext.js +68 -0
  9. package/dist/components/Table/TableBody/TableBodyVirtualizedCore.js +42 -39
  10. package/dist/components/Table/TableBody/TableRowOverlay.d.ts +8 -0
  11. package/dist/components/Table/TableBody/TableRowOverlay.js +36 -0
  12. package/dist/components/Table/TableColGroup.js +3 -2
  13. package/dist/components/Table/TableContext/TableProvider.js +20 -5
  14. package/dist/components/Table/TableContext/types.d.ts +6 -1
  15. package/dist/components/Table/TableInner/TableInnerContainer.js +8 -1
  16. package/dist/components/Table/TableInner/TableInnerWindow.js +8 -1
  17. package/dist/components/Table/TableRow.js +28 -9
  18. package/dist/components/Table/TableRowExpanded.d.ts +4 -1
  19. package/dist/components/Table/TableRowExpanded.js +2 -1
  20. package/dist/components/Table/TableSettingsMenu/TableSettingsMenu.js +2 -2
  21. package/dist/components/Table/hooks/index.d.ts +1 -0
  22. package/dist/components/Table/hooks/index.js +1 -0
  23. package/dist/components/Table/hooks/useStickyGroupParent.d.ts +19 -0
  24. package/dist/components/Table/hooks/useStickyGroupParent.js +147 -0
  25. package/dist/components/Table/index.d.ts +1 -1
  26. package/dist/components/Table/lib/constants.d.ts +2 -0
  27. package/dist/components/Table/lib/constants.js +3 -1
  28. package/dist/components/Table/lib/createDragHandleColumn.d.ts +8 -0
  29. package/dist/components/Table/lib/createDragHandleColumn.js +23 -0
  30. package/dist/components/Table/lib/createSelectionColumn.js +7 -2
  31. package/dist/components/Table/lib/index.d.ts +3 -1
  32. package/dist/components/Table/lib/index.js +3 -1
  33. package/dist/components/Table/lib/useRowDnd.d.ts +15 -0
  34. package/dist/components/Table/lib/useRowDnd.js +32 -0
  35. package/dist/components/Table/types.d.ts +33 -0
  36. package/dist/metadata/components.json +44 -4
  37. package/package.json +1 -1
@@ -6,13 +6,14 @@ import { ScrollArea, ScrollAreaCorner, ScrollAreaScrollbar, ScrollAreaViewport }
6
6
  import { tableContainerVariants } from "../classes.js";
7
7
  import { useInfiniteScroll } from "../hooks/index.js";
8
8
  import { useContainerWidth } from "../lib/index.js";
9
+ import { StickyGroupParent } from "../StickyGroupParent.js";
9
10
  import { TableBody } from "../TableBody/index.js";
10
11
  import { TableColGroup } from "../TableColGroup.js";
11
12
  import { useTableContext } from "../TableContext/index.js";
12
13
  import { TableHead } from "../TableHead.js";
13
14
  import { TableSettingsMenuSlot } from "../TableSettingsMenu/index.js";
14
15
  const TableInnerContainer = ({ isEmpty, virtualized, showSettings, hasConsumerSettingsMenu, ariaLabel, children })=>{
15
- const { containerRef, table, virtualizerRef, tbodyRef, onEndReached, onEndReachedThreshold, onStartReached, onStartReachedThreshold, initialScrollToRowId, isLoadingPrevious } = useTableContext();
16
+ const { containerRef, table, virtualizerRef, tbodyRef, hasSubRowGrouping, onEndReached, onEndReachedThreshold, onStartReached, onStartReachedThreshold, initialScrollToRowId, isLoadingPrevious } = useTableContext();
16
17
  const testId = useTestId('container');
17
18
  const scrollRootRef = useRef(null);
18
19
  const containerWidth = useContainerWidth(containerRef);
@@ -46,6 +47,8 @@ const TableInnerContainer = ({ isEmpty, virtualized, showSettings, hasConsumerSe
46
47
  ]);
47
48
  const totalSize = table.getTotalSize();
48
49
  const tableWidth = Math.max(containerWidth, totalSize);
50
+ const hasTextDescription = table.getAllLeafColumns().some((col)=>col.columnDef.meta?.description?.type === 'text');
51
+ const headerHeight = hasTextDescription ? 48 : 32;
49
52
  return /*#__PURE__*/ jsxs(Fragment, {
50
53
  children: [
51
54
  /*#__PURE__*/ jsxs(ScrollArea, {
@@ -60,6 +63,10 @@ const TableInnerContainer = ({ isEmpty, virtualized, showSettings, hasConsumerSe
60
63
  "data-table-scroll-container": true,
61
64
  tabIndex: -1,
62
65
  children: [
66
+ hasSubRowGrouping && /*#__PURE__*/ jsx(StickyGroupParent, {
67
+ tableWidth: tableWidth,
68
+ headerHeight: headerHeight
69
+ }),
63
70
  /*#__PURE__*/ jsxs("table", {
64
71
  className: "table-fixed border-separate border-spacing-0 overflow-clip",
65
72
  style: {
@@ -4,13 +4,14 @@ import { useTestId } from "../../../utils/testId.js";
4
4
  import { ScrollArea, ScrollAreaScrollbar, ScrollAreaViewport } from "../../ScrollArea/index.js";
5
5
  import { useInfiniteScroll } from "../hooks/index.js";
6
6
  import { useContainerWidth } from "../lib/index.js";
7
+ import { StickyGroupParent } from "../StickyGroupParent.js";
7
8
  import { TableBody } from "../TableBody/index.js";
8
9
  import { TableColGroup } from "../TableColGroup.js";
9
10
  import { useTableContext } from "../TableContext/index.js";
10
11
  import { TableHead } from "../TableHead.js";
11
12
  import { TableSettingsMenuSlot } from "../TableSettingsMenu/index.js";
12
13
  const TableInnerWindow = ({ isEmpty, showSettings, hasConsumerSettingsMenu, ariaLabel, children })=>{
13
- const { table, virtualizerRef, tbodyRef, onEndReached, onEndReachedThreshold, onStartReached, onStartReachedThreshold, initialScrollToRowId, isLoadingPrevious } = useTableContext();
14
+ const { table, virtualizerRef, tbodyRef, hasSubRowGrouping, onEndReached, onEndReachedThreshold, onStartReached, onStartReachedThreshold, initialScrollToRowId, isLoadingPrevious } = useTableContext();
14
15
  const testId = useTestId('window');
15
16
  const rootRef = useRef(null);
16
17
  const scrollRef = useRef(null);
@@ -40,6 +41,8 @@ const TableInnerWindow = ({ isEmpty, showSettings, hasConsumerSettingsMenu, aria
40
41
  }, []);
41
42
  const totalSize = table.getTotalSize();
42
43
  const tableWidth = Math.max(containerWidth, totalSize);
44
+ const hasTextDescription = table.getAllLeafColumns().some((col)=>col.columnDef.meta?.description?.type === 'text');
45
+ const headerHeight = hasTextDescription ? 48 : 32;
43
46
  const tableStyles = 'table-fixed border-separate border-spacing-0';
44
47
  return /*#__PURE__*/ jsxs("div", {
45
48
  ref: rootRef,
@@ -73,6 +76,10 @@ const TableInnerWindow = ({ isEmpty, showSettings, hasConsumerSettingsMenu, aria
73
76
  ]
74
77
  })
75
78
  }),
79
+ hasSubRowGrouping && /*#__PURE__*/ jsx(StickyGroupParent, {
80
+ tableWidth: tableWidth,
81
+ headerHeight: headerHeight
82
+ }),
76
83
  /*#__PURE__*/ jsxs("table", {
77
84
  className: tableStyles,
78
85
  style: {
@@ -1,22 +1,33 @@
1
1
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import { memo } from "react";
2
+ import { memo, useCallback } from "react";
3
3
  import { cn } from "../../utils/cn.js";
4
4
  import { useTestId } from "../../utils/testId.js";
5
- import { TABLE_EXPAND_COLUMN_ID, TABLE_SELECT_COLUMN_ID } from "./lib/index.js";
5
+ import { TABLE_DRAG_HANDLE_COLUMN_ID, TABLE_EXPAND_COLUMN_ID, TABLE_SELECT_COLUMN_ID, useRowDnd } from "./lib/index.js";
6
6
  import { Td, Tr } from "./primitives/index.js";
7
7
  import { TableBodyCell } from "./TableBody/TableBodyCell.js";
8
8
  import { useTableContext } from "./TableContext/index.js";
9
9
  import { TableRowExpanded } from "./TableRowExpanded.js";
10
10
  const SYSTEM_COLUMN_IDS = new Set([
11
11
  TABLE_EXPAND_COLUMN_ID,
12
- TABLE_SELECT_COLUMN_ID
12
+ TABLE_SELECT_COLUMN_ID,
13
+ TABLE_DRAG_HANDLE_COLUMN_ID
13
14
  ]);
14
15
  const TableRowInner = ({ row, ref, 'data-index': dataIndex })=>{
15
16
  const { expandingEnabled, activeRowId } = useTableContext();
16
17
  const testId = useTestId('row');
18
+ const { canDnd, isDragging, setNodeRef, style: dndStyle, attributes, listeners } = useRowDnd(row);
17
19
  const isGroupParent = row.subRows.length > 0;
18
20
  const isSelected = isGroupParent ? row.getIsAllSubRowsSelected() : row.getIsSelected();
19
21
  const isPreviewActive = activeRowId === row.id;
22
+ const composedRef = useCallback((node)=>{
23
+ if (canDnd) setNodeRef(node);
24
+ if ('function' == typeof ref) ref(node);
25
+ else if (ref) ref.current = node;
26
+ }, [
27
+ canDnd,
28
+ setNodeRef,
29
+ ref
30
+ ]);
20
31
  if (isGroupParent) {
21
32
  const cells = row.getVisibleCells();
22
33
  const systemCells = cells.filter((c)=>SYSTEM_COLUMN_IDS.has(c.column.id));
@@ -25,7 +36,7 @@ const TableRowInner = ({ row, ref, 'data-index': dataIndex })=>{
25
36
  return /*#__PURE__*/ jsxs(Fragment, {
26
37
  children: [
27
38
  /*#__PURE__*/ jsxs(Tr, {
28
- ref: ref,
39
+ ref: composedRef,
29
40
  "data-index": dataIndex,
30
41
  "data-row-id": row.id,
31
42
  "data-testid": testId,
@@ -61,21 +72,29 @@ const TableRowInner = ({ row, ref, 'data-index': dataIndex })=>{
61
72
  return /*#__PURE__*/ jsxs(Fragment, {
62
73
  children: [
63
74
  /*#__PURE__*/ jsx(Tr, {
64
- ref: ref,
75
+ ref: composedRef,
65
76
  "data-index": dataIndex,
66
77
  "data-row-id": row.id,
67
78
  "data-testid": testId,
68
79
  className: "group/row",
69
80
  "data-selected": isSelected || void 0,
70
81
  "data-preview-active": isPreviewActive || void 0,
82
+ "data-dragging": isDragging || void 0,
71
83
  "aria-selected": isSelected || void 0,
72
84
  "data-depth": row.depth > 0 ? row.depth : void 0,
73
- children: row.getVisibleCells().map((cell)=>/*#__PURE__*/ jsx(TableBodyCell, {
74
- cell: cell
75
- }, cell.id))
85
+ style: dndStyle,
86
+ children: row.getVisibleCells().map((cell)=>{
87
+ const isDragHandle = cell.column.id === TABLE_DRAG_HANDLE_COLUMN_ID;
88
+ return /*#__PURE__*/ jsx(TableBodyCell, {
89
+ cell: cell,
90
+ dragListeners: isDragHandle ? listeners : void 0,
91
+ dragAttributes: isDragHandle ? attributes : void 0
92
+ }, cell.id);
93
+ })
76
94
  }),
77
95
  expandingEnabled && /*#__PURE__*/ jsx(TableRowExpanded, {
78
- row: row
96
+ row: row,
97
+ dndStyle: dndStyle
79
98
  })
80
99
  ]
81
100
  });
@@ -1,9 +1,12 @@
1
+ import type { CSSProperties } from 'react';
1
2
  import type { Row, RowData } from '@tanstack/react-table';
2
3
  import { type DSTableFeatures } from './lib';
3
4
  interface TableRowExpandedProps<T extends RowData> {
4
5
  row: Row<DSTableFeatures, T>;
6
+ /** When row DnD is active, pass the same transform style so expanded content moves with its parent row. */
7
+ dndStyle?: CSSProperties;
5
8
  }
6
- export declare function TableRowExpanded<T extends RowData>({ row }: TableRowExpandedProps<T>): import("react").JSX.Element | null;
9
+ export declare function TableRowExpanded<T extends RowData>({ row, dndStyle, }: TableRowExpandedProps<T>): import("react").JSX.Element | null;
7
10
  export declare namespace TableRowExpanded {
8
11
  var displayName: string;
9
12
  }
@@ -3,7 +3,7 @@ import { useTestId } from "../../utils/testId.js";
3
3
  import { TABLE_EXPAND_COLUMN_ID } from "./lib/index.js";
4
4
  import { Td, Tr } from "./primitives/index.js";
5
5
  import { useTableContext } from "./TableContext/index.js";
6
- const TableRowExpanded = ({ row })=>{
6
+ const TableRowExpanded = ({ row, dndStyle })=>{
7
7
  const { table, renderExpandedRow } = useTableContext();
8
8
  const testId = useTestId('row-expanded');
9
9
  if (!row.getIsExpanded() || !renderExpandedRow) return null;
@@ -12,6 +12,7 @@ const TableRowExpanded = ({ row })=>{
12
12
  const contentColSpan = hasExpandColumn ? visibleColumns.length - 1 : visibleColumns.length;
13
13
  return /*#__PURE__*/ jsxs(Tr, {
14
14
  "data-testid": testId,
15
+ style: dndStyle,
15
16
  children: [
16
17
  hasExpandColumn && /*#__PURE__*/ jsx(Td, {
17
18
  className: "border-b-0 border-r border-border-primary-light bg-bg-surface-2 sticky left-0"
@@ -11,7 +11,7 @@ import { DropdownMenu, DropdownMenuContent, DropdownMenuFooter, DropdownMenuLabe
11
11
  import { Separator } from "../../Separator/index.js";
12
12
  import { VStack } from "../../Stack/index.js";
13
13
  import { Tooltip, TooltipContent, TooltipTrigger } from "../../Tooltip/index.js";
14
- import { TABLE_EXPAND_COLUMN_ID, TABLE_SELECT_COLUMN_ID, collectDirectChildren } from "../lib/index.js";
14
+ import { TABLE_DRAG_HANDLE_COLUMN_ID, TABLE_EXPAND_COLUMN_ID, TABLE_SELECT_COLUMN_ID, collectDirectChildren } from "../lib/index.js";
15
15
  import { useTableContext } from "../TableContext/index.js";
16
16
  import { TableSettingsMenuContentProvider } from "./TableSettingsMenuContentContext.js";
17
17
  import { useTableSettingsMenuContext } from "./TableSettingsMenuContext.js";
@@ -47,7 +47,7 @@ const TableSettingsMenu = ({ 'data-testid': testIdProp, children, ...rest })=>{
47
47
  }, [
48
48
  menuOpen
49
49
  ]);
50
- const allColumns = table.getAllLeafColumns().filter((col)=>col.id !== TABLE_SELECT_COLUMN_ID && col.id !== TABLE_EXPAND_COLUMN_ID);
50
+ const allColumns = table.getAllLeafColumns().filter((col)=>col.id !== TABLE_SELECT_COLUMN_ID && col.id !== TABLE_EXPAND_COLUMN_ID && col.id !== TABLE_DRAG_HANDLE_COLUMN_ID);
51
51
  const filteredColumns = useMemo(()=>{
52
52
  if (!search) return allColumns;
53
53
  const lower = search.toLowerCase();
@@ -1,4 +1,5 @@
1
1
  export { useInfiniteScroll } from './infiniteScroll';
2
2
  export { useHorizontalScrollState } from './useHorizontalScrollState';
3
3
  export { useMasterCell } from './useMasterCell';
4
+ export { useStickyGroupParent } from './useStickyGroupParent';
4
5
  export { useTableState } from './useTableState';
@@ -1,4 +1,5 @@
1
1
  export { useInfiniteScroll } from "./infiniteScroll/index.js";
2
2
  export { useHorizontalScrollState } from "./useHorizontalScrollState.js";
3
3
  export { useMasterCell } from "./useMasterCell.js";
4
+ export { useStickyGroupParent } from "./useStickyGroupParent.js";
4
5
  export { useTableState } from "./useTableState.js";
@@ -0,0 +1,19 @@
1
+ import { type RefObject } from 'react';
2
+ import type { ReactTable, Row, RowData } from '@tanstack/react-table';
3
+ import type { DSTableFeatures } from '../lib';
4
+ import type { TableVirtualizerInstance } from '../TableContext/types';
5
+ export interface StickyGroupParentResult<T extends RowData> {
6
+ stickyRow: Row<DSTableFeatures, T> | null;
7
+ pushUpOffset: number;
8
+ }
9
+ interface UseStickyGroupParentOptions {
10
+ table: ReactTable<DSTableFeatures, RowData>;
11
+ scrollElementRef: RefObject<HTMLElement | null>;
12
+ useWindowScroll: boolean;
13
+ headerHeight: number;
14
+ tbodyRef: RefObject<HTMLTableSectionElement | null>;
15
+ virtualizerRef: RefObject<TableVirtualizerInstance | null>;
16
+ enabled: boolean;
17
+ }
18
+ export declare const useStickyGroupParent: <T extends RowData>(options: UseStickyGroupParentOptions) => StickyGroupParentResult<T>;
19
+ export {};
@@ -0,0 +1,147 @@
1
+ import { useCallback, useEffect, useRef, useState } from "react";
2
+ const buildGroupRanges = (table)=>{
3
+ const rows = table.getRowModel().rows;
4
+ const ranges = [];
5
+ for(let i = 0; i < rows.length; i++){
6
+ const row = rows[i];
7
+ if (0 === row.depth && row.subRows.length > 0 && row.getIsExpanded()) {
8
+ let lastChildIndex = i;
9
+ for(let j = i + 1; j < rows.length; j++)if (rows[j].depth > 0) lastChildIndex = j;
10
+ else break;
11
+ ranges.push({
12
+ row,
13
+ parentIndex: i,
14
+ lastChildIndex
15
+ });
16
+ }
17
+ }
18
+ return ranges;
19
+ };
20
+ const getRowBounds = (index, virt, tbodyScrollOffset, tbodyEl, scrollTop, scrollContainerTop)=>{
21
+ if (virt) {
22
+ const m = virt.measurementsCache[index];
23
+ if (m) return {
24
+ top: tbodyScrollOffset + m.start,
25
+ bottom: tbodyScrollOffset + m.start + m.size,
26
+ height: m.size
27
+ };
28
+ const size = virt.options.estimateSize(index);
29
+ let start = 0;
30
+ for(let i = 0; i < index; i++){
31
+ const mi = virt.measurementsCache[i];
32
+ start += mi ? mi.size : virt.options.estimateSize(i);
33
+ }
34
+ return {
35
+ top: tbodyScrollOffset + start,
36
+ bottom: tbodyScrollOffset + start + size,
37
+ height: size
38
+ };
39
+ }
40
+ if (!tbodyEl) return null;
41
+ const rowEls = tbodyEl.querySelectorAll('[data-row-id]');
42
+ const rowEl = rowEls[index];
43
+ if (!rowEl) return null;
44
+ const rect = rowEl.getBoundingClientRect();
45
+ const top = rect.top - scrollContainerTop + scrollTop;
46
+ return {
47
+ top,
48
+ bottom: top + rect.height,
49
+ height: rect.height
50
+ };
51
+ };
52
+ const useStickyGroupParent = (options)=>{
53
+ const { table, scrollElementRef, useWindowScroll, headerHeight, tbodyRef, virtualizerRef, enabled } = options;
54
+ const [stickyRow, setStickyRow] = useState(null);
55
+ const [pushUpOffset, setPushUpOffset] = useState(0);
56
+ const rafRef = useRef(0);
57
+ const prevStickyRowIdRef = useRef(null);
58
+ const compute = useCallback(()=>{
59
+ if (!enabled) {
60
+ if (null !== prevStickyRowIdRef.current) {
61
+ setStickyRow(null);
62
+ setPushUpOffset(0);
63
+ prevStickyRowIdRef.current = null;
64
+ }
65
+ return;
66
+ }
67
+ const scrollElement = scrollElementRef.current;
68
+ if (!scrollElement) return;
69
+ const scrollTop = useWindowScroll ? window.scrollY : scrollElement.scrollTop;
70
+ const headerBottom = scrollTop + headerHeight;
71
+ const tbodyEl = tbodyRef.current;
72
+ const virt = virtualizerRef.current;
73
+ let tbodyScrollOffset = 0;
74
+ let scrollContainerTop = 0;
75
+ if (tbodyEl) if (useWindowScroll) {
76
+ tbodyScrollOffset = tbodyEl.getBoundingClientRect().top + window.scrollY;
77
+ scrollContainerTop = 0;
78
+ } else {
79
+ const scrollRect = scrollElement.getBoundingClientRect();
80
+ scrollContainerTop = scrollRect.top;
81
+ tbodyScrollOffset = tbodyEl.getBoundingClientRect().top - scrollRect.top + scrollTop;
82
+ }
83
+ const ranges = buildGroupRanges(table);
84
+ let foundRow = null;
85
+ let offset = 0;
86
+ for(let i = 0; i < ranges.length; i++){
87
+ const range = ranges[i];
88
+ const parentBounds = getRowBounds(range.parentIndex, virt, tbodyScrollOffset, tbodyEl, scrollTop, scrollContainerTop);
89
+ if (!parentBounds) continue;
90
+ const lastChildBounds = getRowBounds(range.lastChildIndex, virt, tbodyScrollOffset, tbodyEl, scrollTop, scrollContainerTop);
91
+ if (lastChildBounds) {
92
+ if (parentBounds.top < headerBottom && lastChildBounds.bottom > headerBottom) {
93
+ foundRow = range.row;
94
+ const remaining = lastChildBounds.bottom - headerBottom;
95
+ offset = remaining < parentBounds.height ? -(parentBounds.height - remaining) : 0;
96
+ break;
97
+ }
98
+ }
99
+ }
100
+ const newId = foundRow?.id ?? null;
101
+ if (newId !== prevStickyRowIdRef.current || 0 !== offset) {
102
+ prevStickyRowIdRef.current = newId;
103
+ setStickyRow(foundRow);
104
+ setPushUpOffset(offset);
105
+ }
106
+ }, [
107
+ enabled,
108
+ scrollElementRef,
109
+ useWindowScroll,
110
+ headerHeight,
111
+ table,
112
+ virtualizerRef,
113
+ tbodyRef
114
+ ]);
115
+ useEffect(()=>{
116
+ if (!enabled) return;
117
+ const scrollTarget = useWindowScroll ? window : scrollElementRef.current;
118
+ if (!scrollTarget) return;
119
+ const handleScroll = ()=>{
120
+ cancelAnimationFrame(rafRef.current);
121
+ rafRef.current = requestAnimationFrame(compute);
122
+ };
123
+ compute();
124
+ scrollTarget.addEventListener('scroll', handleScroll, {
125
+ passive: true
126
+ });
127
+ return ()=>{
128
+ scrollTarget.removeEventListener('scroll', handleScroll);
129
+ cancelAnimationFrame(rafRef.current);
130
+ };
131
+ }, [
132
+ enabled,
133
+ useWindowScroll,
134
+ scrollElementRef,
135
+ compute
136
+ ]);
137
+ useEffect(()=>{
138
+ compute();
139
+ }, [
140
+ compute
141
+ ]);
142
+ return {
143
+ stickyRow,
144
+ pushUpOffset
145
+ };
146
+ };
147
+ export { useStickyGroupParent };
@@ -10,4 +10,4 @@ export { TableEmptyState } from './TableEmptyState';
10
10
  export { TableScrollHandler, TableScrollHandlerLeft, type TableScrollHandlerLeftProps, type TableScrollHandlerProps, TableScrollHandlerRight, type TableScrollHandlerRightProps, } from './TableScrollHandler';
11
11
  export { TableSettingsMenu, TableSettingsMenuItem, type TableSettingsMenuItemProps, type TableSettingsMenuProps, TableSettingsMenuReset, type TableSettingsMenuResetProps, TableSettingsMenuSearch, type TableSettingsMenuSearchProps, } from './TableSettingsMenu';
12
12
  export { TableSortTrigger, type TableSortTriggerProps } from './TableSortTrigger';
13
- export type { TableAccessorColumnDef, TableCellContext, TableColumnBase, TableColumnDef, TableColumnGroup, TableColumnMeta, TableColumnPinningState, TableColumnSizingState, TableDisplayColumnDef, TableExpandedState, TableGroupingState, TableHandle, TableOnChangeFn, TableProps, TableRow, TableRowSelectionState, TableScrollToRowOptions, TableSortingState, TableUpdater, TableVirtualized, TableVisibilityState, } from './types';
13
+ export type { TableAccessorColumnDef, TableCellContext, TableColumnBase, TableColumnDef, TableColumnGroup, TableColumnMeta, TableColumnPinningState, TableColumnSizingState, TableDisplayColumnDef, TableExpandedState, TableGroupingState, TableHandle, TableOnChangeFn, TableProps, TableRow, TableRowReorderEvent, TableRowSelectionState, TableScrollToRowOptions, TableSortingState, TableUpdater, TableVirtualized, TableVisibilityState, } from './types';
@@ -7,6 +7,8 @@ export declare const TABLE_SELECT_COLUMN_ID = "_selection";
7
7
  export declare const TABLE_SELECT_COLUMN_WIDTH = 33;
8
8
  export declare const TABLE_EXPAND_COLUMN_ID = "_expand";
9
9
  export declare const TABLE_EXPAND_COLUMN_WIDTH = 33;
10
+ export declare const TABLE_DRAG_HANDLE_COLUMN_ID = "_dragHandle";
11
+ export declare const TABLE_DRAG_HANDLE_COLUMN_WIDTH = 33;
10
12
  export declare const TABLE_END_REACHED_THRESHOLD = 200;
11
13
  export declare const TABLE_START_REACHED_THRESHOLD = 200;
12
14
  /** Minimum time (ms) between successive edge-reached callbacks. */
@@ -6,6 +6,8 @@ const TABLE_SELECT_COLUMN_ID = '_selection';
6
6
  const TABLE_SELECT_COLUMN_WIDTH = 33;
7
7
  const TABLE_EXPAND_COLUMN_ID = '_expand';
8
8
  const TABLE_EXPAND_COLUMN_WIDTH = 33;
9
+ const TABLE_DRAG_HANDLE_COLUMN_ID = '_dragHandle';
10
+ const TABLE_DRAG_HANDLE_COLUMN_WIDTH = 33;
9
11
  const TABLE_END_REACHED_THRESHOLD = 200;
10
12
  const TABLE_START_REACHED_THRESHOLD = 200;
11
13
  const SCROLL_EDGE_COOLDOWN_MS = 200;
@@ -59,4 +61,4 @@ const SORT_LABELS = {
59
61
  'Smallest on top'
60
62
  ]
61
63
  };
62
- export { SCROLL_EDGE_COOLDOWN_MS, SORT_LABELS, TABLE_END_REACHED_THRESHOLD, TABLE_EXPAND_COLUMN_ID, TABLE_EXPAND_COLUMN_WIDTH, TABLE_MIN_COLUMN_WIDTH, TABLE_PREPEND_SKELETON_ROWS, TABLE_SELECT_COLUMN_ID, TABLE_SELECT_COLUMN_WIDTH, TABLE_SKELETON_ROWS, TABLE_START_REACHED_THRESHOLD, TABLE_VIRTUALIZATION_OVERSCAN, getAlignClass, getExpandBorderClass };
64
+ export { SCROLL_EDGE_COOLDOWN_MS, SORT_LABELS, TABLE_DRAG_HANDLE_COLUMN_ID, TABLE_DRAG_HANDLE_COLUMN_WIDTH, TABLE_END_REACHED_THRESHOLD, TABLE_EXPAND_COLUMN_ID, TABLE_EXPAND_COLUMN_WIDTH, TABLE_MIN_COLUMN_WIDTH, TABLE_PREPEND_SKELETON_ROWS, TABLE_SELECT_COLUMN_ID, TABLE_SELECT_COLUMN_WIDTH, TABLE_SKELETON_ROWS, TABLE_START_REACHED_THRESHOLD, TABLE_VIRTUALIZATION_OVERSCAN, getAlignClass, getExpandBorderClass };
@@ -0,0 +1,8 @@
1
+ import type { ColumnDef, RowData } from '@tanstack/react-table';
2
+ import type { DSTableFeatures } from './dsTableFeatures';
3
+ /**
4
+ * Creates a drag-handle column for row reordering.
5
+ * Automatically injected by Table when `onRowReorder` is provided.
6
+ * The actual drag listeners are applied by `TableRow` on the cell, not here.
7
+ */
8
+ export declare const createDragHandleColumn: <T extends RowData>() => ColumnDef<DSTableFeatures, T, unknown>;
@@ -0,0 +1,23 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { GripVertical } from "../../../icons/index.js";
3
+ import { TABLE_DRAG_HANDLE_COLUMN_ID, TABLE_DRAG_HANDLE_COLUMN_WIDTH } from "./constants.js";
4
+ const createDragHandleColumn = ()=>({
5
+ id: TABLE_DRAG_HANDLE_COLUMN_ID,
6
+ size: TABLE_DRAG_HANDLE_COLUMN_WIDTH,
7
+ minSize: TABLE_DRAG_HANDLE_COLUMN_WIDTH,
8
+ maxSize: TABLE_DRAG_HANDLE_COLUMN_WIDTH,
9
+ enableSorting: false,
10
+ enableResizing: false,
11
+ enableHiding: false,
12
+ enablePinning: false,
13
+ meta: {
14
+ headerClassName: 'px-8 py-4',
15
+ cellClassName: 'px-8 py-8'
16
+ },
17
+ header: ()=>null,
18
+ cell: ()=>/*#__PURE__*/ jsx(GripVertical, {
19
+ size: "sm",
20
+ className: "text-text-tertiary"
21
+ })
22
+ });
23
+ export { createDragHandleColumn };
@@ -42,7 +42,7 @@ const SelectionCell = ({ row, table })=>{
42
42
  });
43
43
  };
44
44
  const SelectAllHeaderCell = (_props)=>{
45
- const { table } = useTableContext();
45
+ const { table, selectAllRowsEnabled, onSelectAllRows } = useTableContext();
46
46
  const checked = table.getIsAllRowsSelected();
47
47
  const { selectableCount, selectedCount } = table.getFilteredRowModel().flatRows.reduce((acc, row)=>{
48
48
  if (!row.getCanSelect()) return acc;
@@ -54,9 +54,14 @@ const SelectAllHeaderCell = (_props)=>{
54
54
  selectedCount: 0
55
55
  });
56
56
  const indeterminate = !checked && selectedCount > 0;
57
+ if (!selectAllRowsEnabled) return null;
58
+ const handleCheckedChange = ()=>{
59
+ table.toggleAllRowsSelected(!checked);
60
+ onSelectAllRows?.(!checked);
61
+ };
57
62
  return /*#__PURE__*/ jsx(Checkbox, {
58
63
  checked: indeterminate ? 'indeterminate' : checked,
59
- onCheckedChange: ()=>table.toggleAllRowsSelected(!checked),
64
+ onCheckedChange: handleCheckedChange,
60
65
  disabled: 0 === selectableCount,
61
66
  children: /*#__PURE__*/ jsx(CheckboxIndicator, {})
62
67
  });
@@ -1,6 +1,7 @@
1
1
  export { collectDirectChildren } from './collectDirectChildren';
2
- export { getAlignClass, getExpandBorderClass, SCROLL_EDGE_COOLDOWN_MS, SORT_LABELS, TABLE_END_REACHED_THRESHOLD, TABLE_EXPAND_COLUMN_ID, TABLE_EXPAND_COLUMN_WIDTH, TABLE_MIN_COLUMN_WIDTH, TABLE_PREPEND_SKELETON_ROWS, TABLE_SELECT_COLUMN_ID, TABLE_SELECT_COLUMN_WIDTH, TABLE_SKELETON_ROWS, TABLE_START_REACHED_THRESHOLD, TABLE_VIRTUALIZATION_OVERSCAN, } from './constants';
2
+ export { getAlignClass, getExpandBorderClass, SCROLL_EDGE_COOLDOWN_MS, SORT_LABELS, TABLE_DRAG_HANDLE_COLUMN_ID, TABLE_DRAG_HANDLE_COLUMN_WIDTH, TABLE_END_REACHED_THRESHOLD, TABLE_EXPAND_COLUMN_ID, TABLE_EXPAND_COLUMN_WIDTH, TABLE_MIN_COLUMN_WIDTH, TABLE_PREPEND_SKELETON_ROWS, TABLE_SELECT_COLUMN_ID, TABLE_SELECT_COLUMN_WIDTH, TABLE_SKELETON_ROWS, TABLE_START_REACHED_THRESHOLD, TABLE_VIRTUALIZATION_OVERSCAN, } from './constants';
3
3
  export { containsDirectChild } from './containsDirectChild';
4
+ export { createDragHandleColumn } from './createDragHandleColumn';
4
5
  export { createExpandColumn } from './createExpandColumn';
5
6
  export { createSelectionColumn } from './createSelectionColumn';
6
7
  export { createTableColumnHelper } from './createTableColumnHelper';
@@ -12,3 +13,4 @@ export { getRowKey } from './getRowKey';
12
13
  export { isLastPinnedLeft } from './isLastPinnedLeft';
13
14
  export { useColumnDnd } from './useColumnDnd';
14
15
  export { useContainerWidth } from './useContainerWidth';
16
+ export { useRowDnd } from './useRowDnd';
@@ -1,6 +1,7 @@
1
1
  export { collectDirectChildren } from "./collectDirectChildren.js";
2
- export { SCROLL_EDGE_COOLDOWN_MS, SORT_LABELS, TABLE_END_REACHED_THRESHOLD, TABLE_EXPAND_COLUMN_ID, TABLE_EXPAND_COLUMN_WIDTH, TABLE_MIN_COLUMN_WIDTH, TABLE_PREPEND_SKELETON_ROWS, TABLE_SELECT_COLUMN_ID, TABLE_SELECT_COLUMN_WIDTH, TABLE_SKELETON_ROWS, TABLE_START_REACHED_THRESHOLD, TABLE_VIRTUALIZATION_OVERSCAN, getAlignClass, getExpandBorderClass } from "./constants.js";
2
+ export { SCROLL_EDGE_COOLDOWN_MS, SORT_LABELS, TABLE_DRAG_HANDLE_COLUMN_ID, TABLE_DRAG_HANDLE_COLUMN_WIDTH, TABLE_END_REACHED_THRESHOLD, TABLE_EXPAND_COLUMN_ID, TABLE_EXPAND_COLUMN_WIDTH, TABLE_MIN_COLUMN_WIDTH, TABLE_PREPEND_SKELETON_ROWS, TABLE_SELECT_COLUMN_ID, TABLE_SELECT_COLUMN_WIDTH, TABLE_SKELETON_ROWS, TABLE_START_REACHED_THRESHOLD, TABLE_VIRTUALIZATION_OVERSCAN, getAlignClass, getExpandBorderClass } from "./constants.js";
3
3
  export { containsDirectChild } from "./containsDirectChild.js";
4
+ export { createDragHandleColumn } from "./createDragHandleColumn.js";
4
5
  export { createExpandColumn } from "./createExpandColumn.js";
5
6
  export { createSelectionColumn } from "./createSelectionColumn.js";
6
7
  export { createTableColumnHelper } from "./createTableColumnHelper.js";
@@ -12,3 +13,4 @@ export { getRowKey } from "./getRowKey.js";
12
13
  export { isLastPinnedLeft } from "./isLastPinnedLeft.js";
13
14
  export { useColumnDnd } from "./useColumnDnd.js";
14
15
  export { useContainerWidth } from "./useContainerWidth.js";
16
+ export { useRowDnd } from "./useRowDnd.js";
@@ -0,0 +1,15 @@
1
+ import type { CSSProperties } from 'react';
2
+ import { useSortable } from '@dnd-kit/sortable';
3
+ import type { Row, RowData } from '@tanstack/react-table';
4
+ import type { DSTableFeatures } from './dsTableFeatures';
5
+ type UseSortableReturn = ReturnType<typeof useSortable>;
6
+ export interface UseRowDndResult {
7
+ canDnd: boolean;
8
+ isDragging: boolean;
9
+ setNodeRef: UseSortableReturn['setNodeRef'];
10
+ style: CSSProperties;
11
+ attributes: UseSortableReturn['attributes'];
12
+ listeners: UseSortableReturn['listeners'];
13
+ }
14
+ export declare const useRowDnd: <T extends RowData>(row: Row<DSTableFeatures, T>) => UseRowDndResult;
15
+ export {};
@@ -0,0 +1,32 @@
1
+ import { useSortable } from "@dnd-kit/sortable";
2
+ import { CSS } from "@dnd-kit/utilities";
3
+ import { useTableContext } from "../TableContext/useTableContext.js";
4
+ const useRowDnd = (row)=>{
5
+ const { rowDndEnabled } = useTableContext();
6
+ const canDnd = rowDndEnabled && 0 === row.subRows.length;
7
+ const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({
8
+ id: row.id,
9
+ disabled: !canDnd
10
+ });
11
+ const style = canDnd ? {
12
+ transform: CSS.Translate.toString(transform ? {
13
+ ...transform,
14
+ x: 0
15
+ } : null),
16
+ transition,
17
+ ...isDragging && {
18
+ opacity: 0.5,
19
+ position: 'relative',
20
+ zIndex: 100
21
+ }
22
+ } : {};
23
+ return {
24
+ canDnd,
25
+ isDragging,
26
+ setNodeRef,
27
+ style,
28
+ attributes,
29
+ listeners
30
+ };
31
+ };
32
+ export { useRowDnd };
@@ -55,6 +55,11 @@ export interface TableColumnGroup {
55
55
  label: string;
56
56
  columns: string[];
57
57
  }
58
+ /** Event fired when a row is dragged to a new position */
59
+ export interface TableRowReorderEvent {
60
+ activeRowId: string;
61
+ overRowId: string;
62
+ }
58
63
  /** State updater — value or functional update */
59
64
  export type TableUpdater<T> = T | ((prev: T) => T);
60
65
  /** Options for the imperative `scrollToRow` method */
@@ -185,6 +190,28 @@ export interface TableProps<T> extends TestableProps {
185
190
  manualSorting?: boolean;
186
191
  rowSelection?: TableRowSelectionState;
187
192
  onRowSelectionChange?: TableOnChangeFn<TableRowSelectionState>;
193
+ /**
194
+ * Renders the master checkbox in the selection column header.
195
+ *
196
+ * Set `false` when "all rows" is not a selection the consumer can act on —
197
+ * a listing whose scope the consumer cannot express, for instance — leaving
198
+ * per-row checkboxes (shift-click range selection included) as the only way
199
+ * to select. The column itself stays, so the layout does not shift.
200
+ *
201
+ * Default: `true`.
202
+ */
203
+ enableSelectAllRows?: boolean;
204
+ /**
205
+ * Called when the master checkbox is toggled, with its new state, in
206
+ * addition to the `onRowSelectionChange` the toggle produces.
207
+ *
208
+ * The state change alone cannot identify the gesture: "every loaded row is
209
+ * selected" is also what checking the last row by hand produces. A consumer
210
+ * that treats the master checkbox as meaning more than the loaded rows —
211
+ * everything matching a server-side filter, say — needs to know the
212
+ * difference, which is what this reports.
213
+ */
214
+ onSelectAllRows?: (selected: boolean) => void;
188
215
  columnSizing?: TableColumnSizingState;
189
216
  onColumnSizingChange?: TableOnChangeFn<TableColumnSizingState>;
190
217
  columnPinning?: TableColumnPinningState;
@@ -236,6 +263,12 @@ export interface TableProps<T> extends TestableProps {
236
263
  * scroll settles. Use for deep-linking into the middle of a dataset.
237
264
  */
238
265
  initialScrollToRowId?: string;
266
+ /**
267
+ * Callback fired when a row is dragged to a new position. When provided,
268
+ * a drag-handle column is auto-injected and row DnD is enabled.
269
+ * Disabled when `getSubRows` grouping is active.
270
+ */
271
+ onRowReorder?: (event: TableRowReorderEvent) => void;
239
272
  /** Callback fired when the master cell is clicked. Receives the row ID. */
240
273
  onMasterCellClick?: (rowId: string) => void;
241
274
  /** ID of the currently active (highlighted) row, or null. Controls row highlighting via data-preview-active attribute. */