es-grid-template 1.9.96 → 1.9.97

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 (42) hide show
  1. package/es/grid-component/hooks/rowFocus.d.ts +2 -1
  2. package/es/grid-component/hooks/rowFocus.js +26 -0
  3. package/es/group-component/body/TableBodyCell.d.ts +2 -0
  4. package/es/group-component/body/TableBodyCell.js +15 -30
  5. package/es/group-component/body/TableBodyCellEdit.js +21 -84
  6. package/es/group-component/body/TableBodyCellEmpty.d.ts +2 -0
  7. package/es/group-component/body/TableBodyCellEmpty.js +15 -30
  8. package/es/group-component/body/TableBodyRowGroupCell.d.ts +2 -0
  9. package/es/group-component/body/TableBodyRowGroupCell.js +15 -30
  10. package/es/group-component/hook/utils.d.ts +9 -9
  11. package/es/group-component/table/TableWrapper.js +1 -0
  12. package/es/table-component/body/TableBodyCell.js +15 -39
  13. package/es/table-component/body/TableBodyCellEdit.js +18 -69
  14. package/es/table-component/table/TableWrapper.js +1 -0
  15. package/es/table-virtuoso/body/TableBodyCell.d.ts +1 -0
  16. package/es/table-virtuoso/body/TableBodyCell.js +13 -30
  17. package/es/table-virtuoso/body/TableBodyCellRowGroup.d.ts +1 -0
  18. package/es/table-virtuoso/body/TableBodyCellRowGroup.js +13 -30
  19. package/es/table-virtuoso/body/TableBodyRow.d.ts +2 -1
  20. package/es/table-virtuoso/body/TableBodyRow.js +10 -3
  21. package/es/table-virtuoso/table/TableWrapper.js +7 -0
  22. package/lib/grid-component/hooks/rowFocus.d.ts +2 -1
  23. package/lib/grid-component/hooks/rowFocus.js +27 -0
  24. package/lib/group-component/body/TableBodyCell.d.ts +2 -0
  25. package/lib/group-component/body/TableBodyCell.js +14 -29
  26. package/lib/group-component/body/TableBodyCellEdit.js +20 -83
  27. package/lib/group-component/body/TableBodyCellEmpty.d.ts +2 -0
  28. package/lib/group-component/body/TableBodyCellEmpty.js +14 -29
  29. package/lib/group-component/body/TableBodyRowGroupCell.d.ts +2 -0
  30. package/lib/group-component/body/TableBodyRowGroupCell.js +14 -29
  31. package/lib/group-component/table/TableWrapper.js +1 -0
  32. package/lib/table-component/body/TableBodyCell.js +14 -38
  33. package/lib/table-component/body/TableBodyCellEdit.js +17 -68
  34. package/lib/table-component/table/TableWrapper.js +1 -0
  35. package/lib/table-virtuoso/body/TableBodyCell.d.ts +1 -0
  36. package/lib/table-virtuoso/body/TableBodyCell.js +12 -29
  37. package/lib/table-virtuoso/body/TableBodyCellRowGroup.d.ts +1 -0
  38. package/lib/table-virtuoso/body/TableBodyCellRowGroup.js +12 -29
  39. package/lib/table-virtuoso/body/TableBodyRow.d.ts +2 -1
  40. package/lib/table-virtuoso/body/TableBodyRow.js +10 -3
  41. package/lib/table-virtuoso/table/TableWrapper.js +7 -0
  42. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- import { notifyArrowRowFocus } from "../../grid-component/hooks/rowFocus";
1
+ import { focusArrowRow, notifyArrowRowFocus } from "../../grid-component/hooks/rowFocus";
2
2
  import Space from "rc-master-ui/es/space";
3
3
  import { getCommonPinningStyles, getFormat } from "../hook/utils";
4
4
  import Checkbox from "rc-master-ui/es/checkbox/Checkbox";
@@ -374,35 +374,18 @@ const TableBodyCell = props => {
374
374
  }
375
375
  },
376
376
  onKeyDown: e => {
377
- const flatRows = table.getRowModel().flatRows;
378
- if (e.key === 'ArrowDown' && rowNumber < flatRows.length - 1) {
379
- const nextIndex = cell.row.index + 1;
380
- // const nextIndex = rowNumber + 1
381
-
382
- const nextId = flatRows[nextIndex].id;
383
- setFocusedCell?.({
384
- colId: cell.column.id,
385
- rowId: nextId
386
- });
387
- notifyArrowRowFocus(table.getRow(nextId).original, 'arrowDown', selectionSettings?.useArrow, rowFocus);
388
- const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextId}"]`);
389
- const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
390
- if (cellFocus) {
391
- cellFocus.focus();
392
- }
393
- }
394
- if (e.key === 'ArrowUp' && rowNumber > 0) {
395
- const prevIndex = cell.row.index - 1;
396
- const nextId = flatRows[prevIndex].id;
397
- setFocusedCell?.({
398
- colId: cell.column.id,
399
- rowId: nextId
400
- });
401
- notifyArrowRowFocus(table.getRow(nextId).original, 'arrowUp', selectionSettings?.useArrow, rowFocus);
402
- const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextId}"]`);
403
- const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
404
- if (cellFocus) {
405
- cellFocus.focus();
377
+ if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
378
+ const rows = table.getRowModel().rows;
379
+ const currentIndex = rows.findIndex(row => row.id === cell.row.id);
380
+ const nextIndex = currentIndex + (e.key === 'ArrowDown' ? 1 : -1);
381
+ const nextRow = currentIndex >= 0 ? rows[nextIndex] : undefined;
382
+ if (nextRow) {
383
+ setFocusedCell?.({
384
+ colId: cell.column.id,
385
+ rowId: nextRow.id
386
+ });
387
+ focusArrowRow(e, nextRow.id, cell.column.id, () => props.scrollToRow?.(nextIndex));
388
+ notifyArrowRowFocus(nextRow.original, e.key === 'ArrowDown' ? 'arrowDown' : 'arrowUp', selectionSettings?.useArrow, rowFocus);
406
389
  }
407
390
  }
408
391
  if (e.ctrlKey && e.code === 'Space' && cell.row.getCanSelect()) {
@@ -4,6 +4,7 @@ import type { CommandClick } from "../../grid-component/type";
4
4
  import type { VirtualItem } from "@tanstack/react-virtual";
5
5
  interface TableBodyCellProps<T> {
6
6
  table: Table<T>;
7
+ scrollToRow?: (index: number) => void;
7
8
  tableId: string;
8
9
  cell: Cell<T, unknown>;
9
10
  commandClick?: (args: CommandClick<T>) => void;
@@ -1,4 +1,4 @@
1
- import { notifyArrowRowFocus } from "../../grid-component/hooks/rowFocus";
1
+ import { focusArrowRow, notifyArrowRowFocus } from "../../grid-component/hooks/rowFocus";
2
2
  import { getCommonPinningStyles } from "../hook/utils";
3
3
  import classNames from "classnames";
4
4
  import React from "react";
@@ -89,35 +89,18 @@ const TableBodyCellRowGroup = props => {
89
89
  }
90
90
  },
91
91
  onKeyDown: e => {
92
- const flatRows = table.getRowModel().flatRows;
93
- if (e.key === 'ArrowDown' && rowNumber < flatRows.length - 1) {
94
- const nextIndex = cell.row.index + 1;
95
- // const nextIndex = rowNumber + 1
96
-
97
- const nextId = flatRows[nextIndex].id;
98
- setFocusedCell?.({
99
- colId: cell.column.id,
100
- rowId: nextId
101
- });
102
- notifyArrowRowFocus(table.getRow(nextId).original, 'arrowDown', selectionSettings?.useArrow, rowFocus);
103
- const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextId}"]`);
104
- const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
105
- if (cellFocus) {
106
- cellFocus.focus();
107
- }
108
- }
109
- if (e.key === 'ArrowUp' && rowNumber > 0) {
110
- const prevIndex = cell.row.index - 1;
111
- const nextId = flatRows[prevIndex].id;
112
- setFocusedCell?.({
113
- colId: cell.column.id,
114
- rowId: nextId
115
- });
116
- notifyArrowRowFocus(table.getRow(nextId).original, 'arrowUp', selectionSettings?.useArrow, rowFocus);
117
- const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextId}"]`);
118
- const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
119
- if (cellFocus) {
120
- cellFocus.focus();
92
+ if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
93
+ const rows = table.getRowModel().rows;
94
+ const currentIndex = rows.findIndex(row => row.id === cell.row.id);
95
+ const nextIndex = currentIndex + (e.key === 'ArrowDown' ? 1 : -1);
96
+ const nextRow = currentIndex >= 0 ? rows[nextIndex] : undefined;
97
+ if (nextRow) {
98
+ setFocusedCell?.({
99
+ colId: cell.column.id,
100
+ rowId: nextRow.id
101
+ });
102
+ focusArrowRow(e, nextRow.id, cell.column.id, () => props.scrollToRow?.(nextIndex));
103
+ notifyArrowRowFocus(nextRow.original, e.key === 'ArrowDown' ? 'arrowDown' : 'arrowUp', selectionSettings?.useArrow, rowFocus);
121
104
  }
122
105
  }
123
106
  if (e.ctrlKey && e.code === 'Space' && cell.row.getCanSelect()) {
@@ -4,10 +4,11 @@ import type { CommandClick } from "../../grid-component/type";
4
4
  interface TableBodyRowProps<T> {
5
5
  tableId: string;
6
6
  table: Table<T>;
7
+ scrollToRow?: (index: number) => void;
7
8
  row: Row<T>;
8
9
  commandClick?: (args: CommandClick<T>) => void;
9
10
  editAble?: boolean;
10
11
  [key: string]: any;
11
12
  }
12
- declare const TableBodyRow: <RecordType extends object>({ tableId, table, row, virtualRow, commandClick, contextMenuItems, onContextMenu, rowheight, editAble, isEditing, isRowEditable, ...rest }: TableBodyRowProps<RecordType>) => JSX.Element;
13
+ declare const TableBodyRow: <RecordType extends object>({ tableId, table, row, scrollToRow, virtualRow, commandClick, contextMenuItems, onContextMenu, rowheight, editAble, isEditing, isRowEditable, ...rest }: TableBodyRowProps<RecordType>) => JSX.Element;
13
14
  export default TableBodyRow;
@@ -14,6 +14,7 @@ const TableBodyRow = ({
14
14
  tableId,
15
15
  table,
16
16
  row,
17
+ scrollToRow,
17
18
  virtualRow,
18
19
  commandClick,
19
20
  contextMenuItems,
@@ -133,7 +134,9 @@ const TableBodyRow = ({
133
134
  rowData: row.original,
134
135
  value: cellValue
135
136
  }) : /*#__PURE__*/React.createElement(React.Fragment, null, headertext, headertext ? ': ' : '', " ", cellContent);
136
- return /*#__PURE__*/React.createElement(TableBodyCell, _extends({}, otherCellAttributes, {
137
+ return /*#__PURE__*/React.createElement(TableBodyCell, _extends({
138
+ scrollToRow: scrollToRow
139
+ }, otherCellAttributes, {
137
140
  table: table,
138
141
  tableId: tableId,
139
142
  key: cell.id,
@@ -166,7 +169,9 @@ const TableBodyRow = ({
166
169
  const childrenData = row.subRows.map(it => it.original);
167
170
  const sumValue = sumByField(childrenData, cell.column.id);
168
171
  const sumValueFormat = numericFormatter(sumValue.toString(), numericFormatProps);
169
- return /*#__PURE__*/React.createElement(TableBodyCellRowGroup, _extends({}, otherCellAttributes, {
172
+ return /*#__PURE__*/React.createElement(TableBodyCellRowGroup, _extends({
173
+ scrollToRow: scrollToRow
174
+ }, otherCellAttributes, {
170
175
  table: table,
171
176
  tableId: tableId,
172
177
  key: cell.id,
@@ -179,7 +184,9 @@ const TableBodyRow = ({
179
184
  sumValue: sumValueFormat
180
185
  }));
181
186
  }
182
- return /*#__PURE__*/React.createElement(TableBodyCell, _extends({}, otherCellAttributes, {
187
+ return /*#__PURE__*/React.createElement(TableBodyCell, _extends({
188
+ scrollToRow: scrollToRow
189
+ }, otherCellAttributes, {
183
190
  table: table,
184
191
  tableId: tableId,
185
192
  key: cell.id,
@@ -34,6 +34,11 @@ const TableWrapper = props => {
34
34
 
35
35
  // ref cho scroll container
36
36
  const scrollRef = useRef(null);
37
+ const virtuosoRef = useRef(null);
38
+ const scrollToRow = index => virtuosoRef.current?.scrollToIndex({
39
+ index,
40
+ align: 'center'
41
+ });
37
42
  const {
38
43
  rows
39
44
  } = table.getRowModel();
@@ -126,6 +131,7 @@ const TableWrapper = props => {
126
131
  position: "relative"
127
132
  }
128
133
  }, /*#__PURE__*/React.createElement(TableVirtuoso, _extends({
134
+ ref: virtuosoRef,
129
135
  data: table.getRowModel().rows,
130
136
  totalCount: rows.length
131
137
  }, onVisibleRowsChange ? {
@@ -190,6 +196,7 @@ const TableWrapper = props => {
190
196
  return /*#__PURE__*/React.createElement(TableBodyRow, _extends({
191
197
  tableId: id,
192
198
  row: row,
199
+ scrollToRow: scrollToRow,
193
200
  table: table,
194
201
  commandClick: commandClick,
195
202
  rowheight: editAble ? 37 : rowheight,
@@ -1,4 +1,4 @@
1
- import type { MouseEvent } from 'react';
1
+ import type { KeyboardEvent, MouseEvent } from 'react';
2
2
  import type { RowFocusEventArgs } from '../type';
3
3
  type RowFocus<T> = (args: RowFocusEventArgs<T>) => void;
4
4
  /** Capture clicks even when a cell handles the event itself. */
@@ -8,4 +8,5 @@ export declare function getRowFocusHandlers<T>(rowData: T, rowFocus?: RowFocus<T
8
8
  };
9
9
  /** Notify arrow focus without changing the existing navigation or selection. */
10
10
  export declare function notifyArrowRowFocus<T>(rowData: T, method: 'arrowUp' | 'arrowDown', useArrow?: boolean, rowFocus?: RowFocus<T>): void;
11
+ export declare function focusArrowRow(event: KeyboardEvent, rowId: string, columnId: string, scrollToRow: () => void): void;
11
12
  export {};
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.focusArrowRow = focusArrowRow;
6
7
  exports.getRowFocusHandlers = getRowFocusHandlers;
7
8
  exports.notifyArrowRowFocus = notifyArrowRowFocus;
8
9
  /** Capture clicks even when a cell handles the event itself. */
@@ -29,4 +30,30 @@ function notifyArrowRowFocus(rowData, method, useArrow, rowFocus) {
29
30
  rowData,
30
31
  method
31
32
  });
33
+ }
34
+ function focusArrowRow(event, rowId, columnId, scrollToRow) {
35
+ event.preventDefault();
36
+ const source = event.currentTarget;
37
+ const body = source.closest('.ui-rc-grid-row')?.parentElement;
38
+ const row = body && Array.from(body.children).find(child => child.getAttribute('data-row-key') === rowId);
39
+ const viewport = source.closest('[data-grid-scroll], [data-virtuoso-scroller]');
40
+ const canScroll = viewport && viewport.scrollHeight > viewport.clientHeight;
41
+ if (!row) {
42
+ if (canScroll) scrollToRow();
43
+ return;
44
+ }
45
+ const cell = Array.from(row.querySelectorAll(':scope > [data-col-key]')).find(element => element.getAttribute('data-col-key') === columnId) ?? row.querySelector(':scope > .ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
46
+ cell?.focus({
47
+ preventScroll: true
48
+ });
49
+ if (canScroll) {
50
+ const header = body?.parentElement?.querySelector(':scope > .ui-rc-grid-thead');
51
+ const footer = body?.parentElement?.querySelector(':scope > .ui-rc-grid-tfoot');
52
+ const headerHeight = header?.getBoundingClientRect().height ?? 0;
53
+ const footerHeight = footer?.getBoundingClientRect().height ?? 0;
54
+ const viewportTop = viewport.getBoundingClientRect().top + viewport.clientTop;
55
+ const viewportCenter = viewportTop + (viewport.clientHeight + headerHeight - footerHeight) / 2;
56
+ const rowRect = row.getBoundingClientRect();
57
+ viewport.scrollTop += rowRect.top + rowRect.height / 2 - viewportCenter;
58
+ }
32
59
  }
@@ -1,8 +1,10 @@
1
1
  /// <reference types="react" />
2
+ import type { Virtualizer } from "@tanstack/react-virtual";
2
3
  import type { Cell, Table } from "@tanstack/react-table";
3
4
  import type { CommandClick } from "../../grid-component/type";
4
5
  interface TableBodyCellProps<T> {
5
6
  table: Table<T>;
7
+ rowVirtualizer?: Virtualizer<HTMLDivElement, HTMLDivElement>;
6
8
  tableId: string;
7
9
  cell: Cell<T, unknown>;
8
10
  commandClick?: (args: CommandClick<T>) => void;
@@ -454,35 +454,20 @@ const TableBodyCell = props => {
454
454
  }
455
455
  },
456
456
  onKeyDown: e => {
457
- const flatRows = table.getRowModel().flatRows;
458
- if (e.key === 'ArrowDown' && rowNumber < flatRows.length - 1) {
459
- const nextIndex = cell.row.index + 1;
460
- // const nextIndex = rowNumber + 1
461
-
462
- const nextId = flatRows[nextIndex].id;
463
- setFocusedCell?.({
464
- colId: cell.column.id,
465
- rowId: nextId
466
- });
467
- (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextId).original, 'arrowDown', selectionSettings?.useArrow, rowFocus);
468
- const rowQr = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextId}"]`);
469
- const cellFocus = rowQr?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
470
- if (cellFocus) {
471
- cellFocus.focus();
472
- }
473
- }
474
- if (e.key === 'ArrowUp' && rowNumber > 0) {
475
- const prevIndex = cell.row.index - 1;
476
- const nextId = flatRows[prevIndex].id;
477
- setFocusedCell?.({
478
- colId: cell.column.id,
479
- rowId: nextId
480
- });
481
- (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextId).original, 'arrowUp', selectionSettings?.useArrow, rowFocus);
482
- const rowQr = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextId}"]`);
483
- const cellFocus = rowQr?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
484
- if (cellFocus) {
485
- cellFocus.focus();
457
+ if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
458
+ const rows = table.getRowModel().rows;
459
+ const currentIndex = rows.findIndex(row => row.id === cell.row.id);
460
+ const nextIndex = currentIndex + (e.key === 'ArrowDown' ? 1 : -1);
461
+ const nextRow = currentIndex >= 0 ? rows[nextIndex] : undefined;
462
+ if (nextRow) {
463
+ setFocusedCell?.({
464
+ colId: cell.column.id,
465
+ rowId: nextRow.id
466
+ });
467
+ (0, _rowFocus.focusArrowRow)(e, nextRow.id, cell.column.id, () => props.rowVirtualizer?.scrollToIndex(nextIndex, {
468
+ align: 'center'
469
+ }));
470
+ (0, _rowFocus.notifyArrowRowFocus)(nextRow.original, e.key === 'ArrowDown' ? 'arrowDown' : 'arrowUp', selectionSettings?.useArrow, rowFocus);
486
471
  }
487
472
  }
488
473
  if (e.ctrlKey && e.code === 'Space' && cell.row.getCanSelect()) {
@@ -794,93 +794,30 @@ const TableBodyCellEdit = props => {
794
794
  }
795
795
  return;
796
796
  }
797
- if (e.key === 'ArrowDown') {
798
- // e.preventDefault()
799
- // e.stopPropagation()
800
-
801
- let nextRowIndex = rowNumber + 1;
802
- let nextRow = table.getRowModel().rows[nextRowIndex];
803
-
804
- // Nếu nextRow có children và chưa được expand, thì tìm tiếp dòng tiếp theo
805
- while (nextRow && nextRow.subRows && nextRow.subRows.length > 0) {
806
- nextRowIndex++;
807
- nextRow = table.getRowModel().rows[nextRowIndex];
797
+ if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
798
+ const rows = table.getRowModel().rows;
799
+ const currentIndex = rows.findIndex(row => row.id === rowId);
800
+ if (currentIndex < 0) return;
801
+ const step = e.key === 'ArrowDown' ? 1 : -1;
802
+ let nextIndex = currentIndex + step;
803
+ let nextRow = rows[nextIndex];
804
+ while (nextRow?.subRows.length) {
805
+ nextIndex += step;
806
+ nextRow = rows[nextIndex];
808
807
  }
809
808
  if (nextRow) {
810
- const nextRowId = nextRow.id;
811
- setFocusedCell?.({
812
- rowId: nextRowId,
813
- colId
814
- });
815
- (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextRowId).original, 'arrowDown', selectionSettings?.useArrow, rowFocus);
816
- setStartCell?.({
817
- rowId: nextRowId,
818
- colId
819
- });
820
- setEndCell?.({
821
- rowId: nextRowId,
822
- colId
823
- });
824
- setRangeState?.((0, _utils.getSelectedCellMatrix)(table, {
825
- rowId: nextRowId,
826
- colId
827
- }, {
828
- rowId: nextRowId,
829
- colId
830
- }));
831
-
832
- // columnVirtualizer.scrollToIndex(nextCol.getIndex(), { align: 'center' })
833
- // rowVirtualizer.scrollToIndex(nextRow.index, { align: 'center' })
834
-
835
- const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextRowId}"]`);
836
- const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
837
- if (cellFocus) {
838
- cellFocus.focus();
839
- }
840
- }
841
- return;
842
- }
843
- if (e.key === 'ArrowUp') {
844
- // e.preventDefault()
845
- // e.stopPropagation()
846
-
847
- // const nextRow = table.getRowModel().rows[rowNumber - 1]
848
-
849
- let prevRowIndex = rowNumber - 1;
850
- let prevRow = table.getRowModel().rows[prevRowIndex];
851
-
852
- // Nếu nextRow có children và chưa được expand, thì tìm tiếp dòng tiếp theo
853
- while (prevRow && prevRow.subRows && prevRow.subRows.length > 0) {
854
- prevRowIndex--;
855
- prevRow = table.getRowModel().rows[prevRowIndex];
856
- }
857
- if (prevRow) {
858
- const nextRowId = prevRow.id;
859
- setFocusedCell?.({
860
- rowId: nextRowId,
861
- colId
862
- });
863
- (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextRowId).original, 'arrowUp', selectionSettings?.useArrow, rowFocus);
864
- setStartCell?.({
865
- rowId: nextRowId,
866
- colId
867
- });
868
- setEndCell?.({
869
- rowId: nextRowId,
870
- colId
871
- });
872
- setRangeState?.((0, _utils.getSelectedCellMatrix)(table, {
873
- rowId: nextRowId,
874
- colId
875
- }, {
876
- rowId: nextRowId,
809
+ const nextCell = {
810
+ rowId: nextRow.id,
877
811
  colId
812
+ };
813
+ setFocusedCell?.(nextCell);
814
+ setStartCell?.(nextCell);
815
+ setEndCell?.(nextCell);
816
+ setRangeState?.((0, _utils.getSelectedCellMatrix)(table, nextCell, nextCell));
817
+ (0, _rowFocus.focusArrowRow)(e, nextRow.id, colId, () => rowVirtualizer.scrollToIndex(nextIndex, {
818
+ align: 'center'
878
819
  }));
879
- const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextRowId}"]`);
880
- const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
881
- if (cellFocus) {
882
- cellFocus.focus();
883
- }
820
+ (0, _rowFocus.notifyArrowRowFocus)(nextRow.original, e.key === 'ArrowDown' ? 'arrowDown' : 'arrowUp', selectionSettings?.useArrow, rowFocus);
884
821
  }
885
822
  return;
886
823
  }
@@ -1,8 +1,10 @@
1
1
  /// <reference types="react" />
2
+ import type { Virtualizer } from "@tanstack/react-virtual";
2
3
  import type { Cell, Table } from "@tanstack/react-table";
3
4
  import type { CommandClick } from "../../grid-component/type";
4
5
  interface TableBodyCellProps<T> {
5
6
  table: Table<T>;
7
+ rowVirtualizer?: Virtualizer<HTMLDivElement, HTMLDivElement>;
6
8
  tableId: string;
7
9
  cell: Cell<T, unknown>;
8
10
  commandClick?: (args: CommandClick<T>) => void;
@@ -99,35 +99,20 @@ const TableBodyCellEmpty = props => {
99
99
  setIsPasting?.(false);
100
100
  },
101
101
  onKeyDown: e => {
102
- const flatRows = table.getRowModel().flatRows;
103
- if (e.key === 'ArrowDown' && rowNumber < flatRows.length - 1) {
104
- const nextIndex = cell.row.index + 1;
105
- // const nextIndex = rowNumber + 1
106
-
107
- const nextId = flatRows[nextIndex].id;
108
- setFocusedCell?.({
109
- colId: cell.column.id,
110
- rowId: nextId
111
- });
112
- (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextId).original, 'arrowDown', selectionSettings?.useArrow, rowFocus);
113
- const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextId}"]`);
114
- const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
115
- if (cellFocus) {
116
- cellFocus.focus();
117
- }
118
- }
119
- if (e.key === 'ArrowUp' && rowNumber > 0) {
120
- const prevIndex = cell.row.index - 1;
121
- const nextId = flatRows[prevIndex].id;
122
- setFocusedCell?.({
123
- colId: cell.column.id,
124
- rowId: nextId
125
- });
126
- (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextId).original, 'arrowUp', selectionSettings?.useArrow, rowFocus);
127
- const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextId}"]`);
128
- const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
129
- if (cellFocus) {
130
- cellFocus.focus();
102
+ if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
103
+ const rows = table.getRowModel().rows;
104
+ const currentIndex = rows.findIndex(row => row.id === cell.row.id);
105
+ const nextIndex = currentIndex + (e.key === 'ArrowDown' ? 1 : -1);
106
+ const nextRow = currentIndex >= 0 ? rows[nextIndex] : undefined;
107
+ if (nextRow) {
108
+ setFocusedCell?.({
109
+ colId: cell.column.id,
110
+ rowId: nextRow.id
111
+ });
112
+ (0, _rowFocus.focusArrowRow)(e, nextRow.id, cell.column.id, () => props.rowVirtualizer?.scrollToIndex(nextIndex, {
113
+ align: 'center'
114
+ }));
115
+ (0, _rowFocus.notifyArrowRowFocus)(nextRow.original, e.key === 'ArrowDown' ? 'arrowDown' : 'arrowUp', selectionSettings?.useArrow, rowFocus);
131
116
  }
132
117
  }
133
118
  if (e.ctrlKey && e.code === 'Space' && cell.row.getCanSelect()) {
@@ -1,8 +1,10 @@
1
1
  /// <reference types="react" />
2
+ import type { Virtualizer } from "@tanstack/react-virtual";
2
3
  import type { Cell, Table } from "@tanstack/react-table";
3
4
  import type { CommandClick } from "../../grid-component/type";
4
5
  interface TableBodyCellProps<T> {
5
6
  table: Table<T>;
7
+ rowVirtualizer?: Virtualizer<HTMLDivElement, HTMLDivElement>;
6
8
  tableId: string;
7
9
  cell: Cell<T, unknown>;
8
10
  commandClick?: (args: CommandClick<T>) => void;
@@ -434,35 +434,20 @@ const TableBodyCell = props => {
434
434
  setIsPasting?.(false);
435
435
  },
436
436
  onKeyDown: e => {
437
- const flatRows = table.getRowModel().flatRows;
438
- if (e.key === 'ArrowDown' && rowNumber < flatRows.length - 1) {
439
- const nextIndex = cell.row.index + 1;
440
- // const nextIndex = rowNumber + 1
441
-
442
- const nextId = flatRows[nextIndex].id;
443
- setFocusedCell?.({
444
- colId: cell.column.id,
445
- rowId: nextId
446
- });
447
- (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextId).original, 'arrowDown', selectionSettings?.useArrow, rowFocus);
448
- const rowQr = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextId}"]`);
449
- const cellFocus = rowQr?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
450
- if (cellFocus) {
451
- cellFocus.focus();
452
- }
453
- }
454
- if (e.key === 'ArrowUp' && rowNumber > 0) {
455
- const prevIndex = cell.row.index - 1;
456
- const nextId = flatRows[prevIndex].id;
457
- setFocusedCell?.({
458
- colId: cell.column.id,
459
- rowId: nextId
460
- });
461
- (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextId).original, 'arrowUp', selectionSettings?.useArrow, rowFocus);
462
- const rowQr = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextId}"]`);
463
- const cellFocus = rowQr?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
464
- if (cellFocus) {
465
- cellFocus.focus();
437
+ if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
438
+ const rows = table.getRowModel().rows;
439
+ const currentIndex = rows.findIndex(row => row.id === cell.row.id);
440
+ const nextIndex = currentIndex + (e.key === 'ArrowDown' ? 1 : -1);
441
+ const nextRow = currentIndex >= 0 ? rows[nextIndex] : undefined;
442
+ if (nextRow) {
443
+ setFocusedCell?.({
444
+ colId: cell.column.id,
445
+ rowId: nextRow.id
446
+ });
447
+ (0, _rowFocus.focusArrowRow)(e, nextRow.id, cell.column.id, () => props.rowVirtualizer?.scrollToIndex(nextIndex, {
448
+ align: 'center'
449
+ }));
450
+ (0, _rowFocus.notifyArrowRowFocus)(nextRow.original, e.key === 'ArrowDown' ? 'arrowDown' : 'arrowUp', selectionSettings?.useArrow, rowFocus);
466
451
  }
467
452
  }
468
453
  if (e.ctrlKey && e.code === 'Space' && cell.row.getCanSelect()) {
@@ -202,6 +202,7 @@ const TableWrapper = props => {
202
202
  }, /*#__PURE__*/_react.default.createElement("div", {
203
203
  // id={id}
204
204
  ref: tableContainerRef,
205
+ "data-grid-scroll": true,
205
206
  style: {
206
207
  overflow: 'auto',
207
208
  //our scrollable table container
@@ -442,44 +442,20 @@ const TableBodyCell = props => {
442
442
  }
443
443
  },
444
444
  onKeyDown: e => {
445
- const flatRows = table.getRowModel().flatRows;
446
- if (e.key === 'ArrowDown' && rowNumber < flatRows.length - 1) {
447
- const nextIndex = cell.row.index + 1;
448
- // const nextIndex = rowNumber + 1
449
-
450
- const nextId = flatRows[nextIndex].id;
451
- setFocusedCell?.({
452
- colId: cell.column.id,
453
- rowId: nextId
454
- });
455
- (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextId).original, 'arrowDown', selectionSettings?.useArrow, rowFocus);
456
-
457
- // if (rowNumber < flatRows.length - 5) {
458
- // e.stopPropagation()
459
- // e.preventDefault()
460
- // rowVirtualizer.scrollToIndex(cell.row.index, {
461
- // align: 'center', // 'start' | 'center' | 'end'
462
- // })
463
- // }
464
-
465
- const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextId}"]`);
466
- const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
467
- if (cellFocus) {
468
- cellFocus.focus();
469
- }
470
- }
471
- if (e.key === 'ArrowUp' && rowNumber > 0) {
472
- const prevIndex = cell.row.index - 1;
473
- const nextId = flatRows[prevIndex].id;
474
- setFocusedCell?.({
475
- colId: cell.column.id,
476
- rowId: nextId
477
- });
478
- (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextId).original, 'arrowUp', selectionSettings?.useArrow, rowFocus);
479
- const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextId}"]`);
480
- const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
481
- if (cellFocus) {
482
- cellFocus.focus();
445
+ if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
446
+ const rows = table.getRowModel().rows;
447
+ const currentIndex = rows.findIndex(row => row.id === cell.row.id);
448
+ const nextIndex = currentIndex + (e.key === 'ArrowDown' ? 1 : -1);
449
+ const nextRow = currentIndex >= 0 ? rows[nextIndex] : undefined;
450
+ if (nextRow) {
451
+ setFocusedCell?.({
452
+ colId: cell.column.id,
453
+ rowId: nextRow.id
454
+ });
455
+ (0, _rowFocus.focusArrowRow)(e, nextRow.id, cell.column.id, () => props.rowVirtualizer?.scrollToIndex(nextIndex, {
456
+ align: 'center'
457
+ }));
458
+ (0, _rowFocus.notifyArrowRowFocus)(nextRow.original, e.key === 'ArrowDown' ? 'arrowDown' : 'arrowUp', selectionSettings?.useArrow, rowFocus);
483
459
  }
484
460
  }
485
461
  if (e.ctrlKey && e.code === 'Space' && cell.row.getCanSelect()) {