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
@@ -824,77 +824,26 @@ const TableBodyCellEdit = props => {
824
824
  }
825
825
  return;
826
826
  }
827
- if (e.key === 'ArrowDown') {
828
- // e.preventDefault()
829
- // e.stopPropagation()
830
-
831
- const nextRow = table.getRowModel().rows[rowNumber + 1];
832
- if (nextRow) {
833
- const nextRowId = nextRow.id;
834
- setFocusedCell?.({
835
- rowId: nextRowId,
836
- colId
837
- });
838
- (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextRowId).original, 'arrowDown', selectionSettings?.useArrow, rowFocus);
839
- setStartCell?.({
840
- rowId: nextRowId,
841
- colId
842
- });
843
- setEndCell?.({
844
- rowId: nextRowId,
845
- colId
846
- });
847
- setRangeState?.((0, _utils.getSelectedCellMatrix)(table, {
848
- rowId: nextRowId,
849
- colId
850
- }, {
851
- rowId: nextRowId,
852
- colId
853
- }));
854
-
855
- // columnVirtualizer.scrollToIndex(nextCol.getIndex(), { align: 'center' })
856
- // rowVirtualizer.scrollToIndex(nextRow.index, { align: 'center' })
857
-
858
- const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextRowId}"]`);
859
- const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
860
- if (cellFocus) {
861
- cellFocus.focus();
862
- }
863
- }
864
- return;
865
- }
866
- if (e.key === 'ArrowUp') {
867
- // e.preventDefault()
868
- // e.stopPropagation()
869
-
870
- const nextRow = table.getRowModel().rows[rowNumber - 1];
827
+ if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
828
+ const rows = table.getRowModel().rows;
829
+ const currentIndex = rows.findIndex(row => row.id === rowId);
830
+ if (currentIndex < 0) return;
831
+ const step = e.key === 'ArrowDown' ? 1 : -1;
832
+ const nextIndex = currentIndex + step;
833
+ const nextRow = rows[nextIndex];
871
834
  if (nextRow) {
872
- const nextRowId = nextRow.id;
873
- setFocusedCell?.({
874
- rowId: nextRowId,
875
- colId
876
- });
877
- (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextRowId).original, 'arrowUp', selectionSettings?.useArrow, rowFocus);
878
- setStartCell?.({
879
- rowId: nextRowId,
880
- colId
881
- });
882
- setEndCell?.({
883
- rowId: nextRowId,
884
- colId
885
- });
886
- setRangeState?.((0, _utils.getSelectedCellMatrix)(table, {
887
- rowId: nextRowId,
888
- colId
889
- }, {
890
- rowId: nextRowId,
835
+ const nextCell = {
836
+ rowId: nextRow.id,
891
837
  colId
838
+ };
839
+ setFocusedCell?.(nextCell);
840
+ setStartCell?.(nextCell);
841
+ setEndCell?.(nextCell);
842
+ setRangeState?.((0, _utils.getSelectedCellMatrix)(table, nextCell, nextCell));
843
+ (0, _rowFocus.focusArrowRow)(e, nextRow.id, colId, () => rowVirtualizer.scrollToIndex(nextIndex, {
844
+ align: 'center'
892
845
  }));
893
- const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextRowId}"]`);
894
- const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
895
- if (cellFocus) {
896
- cellFocus.focus();
897
- }
846
+ (0, _rowFocus.notifyArrowRowFocus)(nextRow.original, e.key === 'ArrowDown' ? 'arrowDown' : 'arrowUp', selectionSettings?.useArrow, rowFocus);
898
847
  }
899
848
  return;
900
849
  }
@@ -255,6 +255,7 @@ const TableWrapper = props => {
255
255
  }, /*#__PURE__*/_react.default.createElement("div", {
256
256
  // id={id}
257
257
  ref: tableContainerRef,
258
+ "data-grid-scroll": true,
258
259
  style: {
259
260
  overflow: 'auto',
260
261
  //our scrollable table container
@@ -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;
@@ -381,35 +381,18 @@ const TableBodyCell = props => {
381
381
  }
382
382
  },
383
383
  onKeyDown: e => {
384
- const flatRows = table.getRowModel().flatRows;
385
- if (e.key === 'ArrowDown' && rowNumber < flatRows.length - 1) {
386
- const nextIndex = cell.row.index + 1;
387
- // const nextIndex = rowNumber + 1
388
-
389
- const nextId = flatRows[nextIndex].id;
390
- setFocusedCell?.({
391
- colId: cell.column.id,
392
- rowId: nextId
393
- });
394
- (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextId).original, 'arrowDown', selectionSettings?.useArrow, rowFocus);
395
- const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextId}"]`);
396
- const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
397
- if (cellFocus) {
398
- cellFocus.focus();
399
- }
400
- }
401
- if (e.key === 'ArrowUp' && rowNumber > 0) {
402
- const prevIndex = cell.row.index - 1;
403
- const nextId = flatRows[prevIndex].id;
404
- setFocusedCell?.({
405
- colId: cell.column.id,
406
- rowId: nextId
407
- });
408
- (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextId).original, 'arrowUp', selectionSettings?.useArrow, rowFocus);
409
- const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextId}"]`);
410
- const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
411
- if (cellFocus) {
412
- cellFocus.focus();
384
+ if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
385
+ const rows = table.getRowModel().rows;
386
+ const currentIndex = rows.findIndex(row => row.id === cell.row.id);
387
+ const nextIndex = currentIndex + (e.key === 'ArrowDown' ? 1 : -1);
388
+ const nextRow = currentIndex >= 0 ? rows[nextIndex] : undefined;
389
+ if (nextRow) {
390
+ setFocusedCell?.({
391
+ colId: cell.column.id,
392
+ rowId: nextRow.id
393
+ });
394
+ (0, _rowFocus.focusArrowRow)(e, nextRow.id, cell.column.id, () => props.scrollToRow?.(nextIndex));
395
+ (0, _rowFocus.notifyArrowRowFocus)(nextRow.original, e.key === 'ArrowDown' ? 'arrowDown' : 'arrowUp', selectionSettings?.useArrow, rowFocus);
413
396
  }
414
397
  }
415
398
  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;
@@ -96,35 +96,18 @@ const TableBodyCellRowGroup = props => {
96
96
  }
97
97
  },
98
98
  onKeyDown: e => {
99
- const flatRows = table.getRowModel().flatRows;
100
- if (e.key === 'ArrowDown' && rowNumber < flatRows.length - 1) {
101
- const nextIndex = cell.row.index + 1;
102
- // const nextIndex = rowNumber + 1
103
-
104
- const nextId = flatRows[nextIndex].id;
105
- setFocusedCell?.({
106
- colId: cell.column.id,
107
- rowId: nextId
108
- });
109
- (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextId).original, 'arrowDown', selectionSettings?.useArrow, rowFocus);
110
- const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextId}"]`);
111
- const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
112
- if (cellFocus) {
113
- cellFocus.focus();
114
- }
115
- }
116
- if (e.key === 'ArrowUp' && rowNumber > 0) {
117
- const prevIndex = cell.row.index - 1;
118
- const nextId = flatRows[prevIndex].id;
119
- setFocusedCell?.({
120
- colId: cell.column.id,
121
- rowId: nextId
122
- });
123
- (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextId).original, 'arrowUp', selectionSettings?.useArrow, rowFocus);
124
- const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextId}"]`);
125
- const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
126
- if (cellFocus) {
127
- cellFocus.focus();
99
+ if (e.key === 'ArrowDown' || e.key === 'ArrowUp') {
100
+ const rows = table.getRowModel().rows;
101
+ const currentIndex = rows.findIndex(row => row.id === cell.row.id);
102
+ const nextIndex = currentIndex + (e.key === 'ArrowDown' ? 1 : -1);
103
+ const nextRow = currentIndex >= 0 ? rows[nextIndex] : undefined;
104
+ if (nextRow) {
105
+ setFocusedCell?.({
106
+ colId: cell.column.id,
107
+ rowId: nextRow.id
108
+ });
109
+ (0, _rowFocus.focusArrowRow)(e, nextRow.id, cell.column.id, () => props.scrollToRow?.(nextIndex));
110
+ (0, _rowFocus.notifyArrowRowFocus)(nextRow.original, e.key === 'ArrowDown' ? 'arrowDown' : 'arrowUp', selectionSettings?.useArrow, rowFocus);
128
111
  }
129
112
  }
130
113
  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;
@@ -21,6 +21,7 @@ const TableBodyRow = ({
21
21
  tableId,
22
22
  table,
23
23
  row,
24
+ scrollToRow,
24
25
  virtualRow,
25
26
  commandClick,
26
27
  contextMenuItems,
@@ -140,7 +141,9 @@ const TableBodyRow = ({
140
141
  rowData: row.original,
141
142
  value: cellValue
142
143
  }) : /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, headertext, headertext ? ': ' : '', " ", cellContent);
143
- return /*#__PURE__*/_react.default.createElement(_TableBodyCell.default, (0, _extends2.default)({}, otherCellAttributes, {
144
+ return /*#__PURE__*/_react.default.createElement(_TableBodyCell.default, (0, _extends2.default)({
145
+ scrollToRow: scrollToRow
146
+ }, otherCellAttributes, {
144
147
  table: table,
145
148
  tableId: tableId,
146
149
  key: cell.id,
@@ -173,7 +176,9 @@ const TableBodyRow = ({
173
176
  const childrenData = row.subRows.map(it => it.original);
174
177
  const sumValue = (0, _hooks.sumByField)(childrenData, cell.column.id);
175
178
  const sumValueFormat = (0, _reactNumericComponent.numericFormatter)(sumValue.toString(), numericFormatProps);
176
- return /*#__PURE__*/_react.default.createElement(_TableBodyCellRowGroup.default, (0, _extends2.default)({}, otherCellAttributes, {
179
+ return /*#__PURE__*/_react.default.createElement(_TableBodyCellRowGroup.default, (0, _extends2.default)({
180
+ scrollToRow: scrollToRow
181
+ }, otherCellAttributes, {
177
182
  table: table,
178
183
  tableId: tableId,
179
184
  key: cell.id,
@@ -186,7 +191,9 @@ const TableBodyRow = ({
186
191
  sumValue: sumValueFormat
187
192
  }));
188
193
  }
189
- return /*#__PURE__*/_react.default.createElement(_TableBodyCell.default, (0, _extends2.default)({}, otherCellAttributes, {
194
+ return /*#__PURE__*/_react.default.createElement(_TableBodyCell.default, (0, _extends2.default)({
195
+ scrollToRow: scrollToRow
196
+ }, otherCellAttributes, {
190
197
  table: table,
191
198
  tableId: tableId,
192
199
  key: cell.id,
@@ -45,6 +45,11 @@ const TableWrapper = props => {
45
45
 
46
46
  // ref cho scroll container
47
47
  const scrollRef = (0, _react.useRef)(null);
48
+ const virtuosoRef = (0, _react.useRef)(null);
49
+ const scrollToRow = index => virtuosoRef.current?.scrollToIndex({
50
+ index,
51
+ align: 'center'
52
+ });
48
53
  const {
49
54
  rows
50
55
  } = table.getRowModel();
@@ -137,6 +142,7 @@ const TableWrapper = props => {
137
142
  position: "relative"
138
143
  }
139
144
  }, /*#__PURE__*/_react.default.createElement(_reactVirtuoso.TableVirtuoso, (0, _extends2.default)({
145
+ ref: virtuosoRef,
140
146
  data: table.getRowModel().rows,
141
147
  totalCount: rows.length
142
148
  }, onVisibleRowsChange ? {
@@ -201,6 +207,7 @@ const TableWrapper = props => {
201
207
  return /*#__PURE__*/_react.default.createElement(_TableBodyRow.default, (0, _extends2.default)({
202
208
  tableId: id,
203
209
  row: row,
210
+ scrollToRow: scrollToRow,
204
211
  table: table,
205
212
  commandClick: commandClick,
206
213
  rowheight: editAble ? 37 : rowheight,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-grid-template",
3
- "version": "1.9.96",
3
+ "version": "1.9.97",
4
4
  "description": "es-grid-template",
5
5
  "keywords": [
6
6
  "react",