es-grid-template 1.9.93 → 1.9.94

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 (54) hide show
  1. package/es/grid-component/hooks/rowFocus.d.ts +11 -0
  2. package/es/grid-component/hooks/rowFocus.js +25 -0
  3. package/es/grid-component/index.d.ts +2 -2
  4. package/es/grid-component/type.d.ts +8 -0
  5. package/es/group-component/TableContainer.js +2 -0
  6. package/es/group-component/TableContainerEdit.js +2 -0
  7. package/es/group-component/body/TableBodyCell.js +4 -0
  8. package/es/group-component/body/TableBodyCellEdit.js +4 -0
  9. package/es/group-component/body/TableBodyCellEmpty.js +4 -0
  10. package/es/group-component/body/TableBodyRow.js +6 -3
  11. package/es/group-component/body/TableBodyRowGroupCell.js +4 -0
  12. package/es/group-component/hook/utils.d.ts +9 -9
  13. package/es/group-component/useContext.d.ts +2 -0
  14. package/es/index.d.ts +1 -1
  15. package/es/table-component/TableContainer.js +2 -0
  16. package/es/table-component/TableContainerEdit.js +2 -0
  17. package/es/table-component/body/TableBody.js +4 -0
  18. package/es/table-component/body/TableBodyCell.js +4 -0
  19. package/es/table-component/body/TableBodyCellEdit.js +4 -0
  20. package/es/table-component/body/TableBodyRow.js +12 -4
  21. package/es/table-component/useContext.d.ts +2 -0
  22. package/es/table-virtuoso/body/TableBodyCell.js +4 -0
  23. package/es/table-virtuoso/body/TableBodyCellRowGroup.js +4 -0
  24. package/es/table-virtuoso/body/TableBodyRow.js +4 -1
  25. package/es/table-virtuoso/table/TableContainer.js +2 -0
  26. package/es/table-virtuoso/useContext.d.ts +2 -0
  27. package/lib/grid-component/hooks/rowFocus.d.ts +11 -0
  28. package/lib/grid-component/hooks/rowFocus.js +32 -0
  29. package/lib/grid-component/index.d.ts +2 -2
  30. package/lib/grid-component/type.d.ts +8 -0
  31. package/lib/group-component/TableContainer.js +2 -0
  32. package/lib/group-component/TableContainerEdit.js +2 -0
  33. package/lib/group-component/body/TableBodyCell.js +4 -0
  34. package/lib/group-component/body/TableBodyCellEdit.js +4 -0
  35. package/lib/group-component/body/TableBodyCellEmpty.js +4 -0
  36. package/lib/group-component/body/TableBodyRow.js +6 -3
  37. package/lib/group-component/body/TableBodyRowGroupCell.js +4 -0
  38. package/lib/group-component/hook/utils.d.ts +9 -9
  39. package/lib/group-component/useContext.d.ts +2 -0
  40. package/lib/index.d.ts +1 -1
  41. package/lib/table-component/TableContainer.js +2 -0
  42. package/lib/table-component/TableContainerEdit.js +2 -0
  43. package/lib/table-component/body/TableBody.js +4 -0
  44. package/lib/table-component/body/TableBodyCell.js +4 -0
  45. package/lib/table-component/body/TableBodyCellEdit.js +4 -0
  46. package/lib/table-component/body/TableBodyRow.js +12 -4
  47. package/lib/table-component/useContext.d.ts +2 -0
  48. package/lib/table-virtuoso/body/TableBodyCell.js +4 -0
  49. package/lib/table-virtuoso/body/TableBodyCellRowGroup.js +4 -0
  50. package/lib/table-virtuoso/body/TableBodyRow.js +4 -1
  51. package/lib/table-virtuoso/table/TableContainer.js +2 -0
  52. package/lib/table-virtuoso/useContext.d.ts +2 -0
  53. package/package.json +1 -1
  54. package/CHANGELOG.md +0 -6
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getRowFocusHandlers = getRowFocusHandlers;
7
+ exports.notifyArrowRowFocus = notifyArrowRowFocus;
8
+ /** Capture clicks even when a cell handles the event itself. */
9
+ function getRowFocusHandlers(rowData, rowFocus) {
10
+ return {
11
+ onClickCapture: event => {
12
+ if (event.button === 0) rowFocus?.({
13
+ rowData,
14
+ method: 'mouseLeftClick'
15
+ });
16
+ },
17
+ onContextMenuCapture: event => {
18
+ if (event.button === 2) rowFocus?.({
19
+ rowData,
20
+ method: 'mouseRightClick'
21
+ });
22
+ }
23
+ };
24
+ }
25
+
26
+ /** Notify arrow focus without changing the existing navigation or selection. */
27
+ function notifyArrowRowFocus(rowData, method, useArrow, rowFocus) {
28
+ if (useArrow === true) rowFocus?.({
29
+ rowData,
30
+ method
31
+ });
32
+ }
@@ -1,5 +1,5 @@
1
1
  import TempTable from './TempTable';
2
- import type { ColumnsTable, TableProps, ColumnTable, CommandItem, ContextMenuItem } from './type';
2
+ import type { ColumnsTable, TableProps, ColumnTable, CommandItem, ContextMenuItem, RowFocusEventArgs } from './type';
3
3
  import type { ToolbarItem } from "rc-master-ui/es/toolbar";
4
- export type { ColumnsTable, TableProps, ColumnTable, ToolbarItem, CommandItem, ContextMenuItem };
4
+ export type { ColumnsTable, TableProps, ColumnTable, ToolbarItem, CommandItem, ContextMenuItem, RowFocusEventArgs };
5
5
  export default TempTable;
@@ -451,6 +451,8 @@ export type TableProps<RecordType = AnyObject> = {
451
451
  recordDoubleClick?: (args: RecordDoubleClickEventArgs<RecordType>) => void;
452
452
  /** Click vào row */
453
453
  recordClick?: (args: RecordDoubleClickEventArgs<RecordType>) => void;
454
+ /** Notify mouse clicks or enabled arrow-key navigation independently of row selection. */
455
+ rowFocus?: (args: RowFocusEventArgs<RecordType>) => void;
454
456
  /** Filter */
455
457
  /** Hiển thị filter nâng cao */
456
458
  showAdvanceFilter?: boolean;
@@ -789,6 +791,8 @@ export type IWrapSettings = {
789
791
  wrapMode?: IWrapMode;
790
792
  };
791
793
  export type SelectionSettings<T = AnyObject> = {
794
+ /** Invoke rowFocus on ArrowUp/ArrowDown. Defaults to false. */
795
+ useArrow?: boolean;
792
796
  mode?: 'checkbox' | 'radio';
793
797
  type?: 'single' | 'multiple';
794
798
  checkboxOnly?: boolean;
@@ -824,6 +828,10 @@ export type RowSelection<T> = {
824
828
  checkboxOnly?: boolean;
825
829
  arrowKey?: boolean;
826
830
  };
831
+ export type RowFocusEventArgs<RecordType> = {
832
+ rowData: RecordType;
833
+ method: 'mouseLeftClick' | 'mouseRightClick' | 'arrowUp' | 'arrowDown';
834
+ };
827
835
  export type RecordDoubleClickEventArgs<RecordType> = {
828
836
  rowData: RecordType;
829
837
  rowIndex: number | undefined;
@@ -38,6 +38,7 @@ const TableContainer = props => {
38
38
  expandable,
39
39
  wrapSettings,
40
40
  recordDoubleClick,
41
+ rowFocus,
41
42
  // triggerFilter,
42
43
  selectionSettings,
43
44
  isSelectionChange,
@@ -325,6 +326,7 @@ const TableContainer = props => {
325
326
  // triggerFilter,
326
327
  wrapSettings,
327
328
  recordDoubleClick,
329
+ rowFocus,
328
330
  selectionSettings,
329
331
  isSelectionChange,
330
332
  setIsSelectionChange,
@@ -86,6 +86,7 @@ const TableContainerEdit = props => {
86
86
  expandable,
87
87
  wrapSettings,
88
88
  recordDoubleClick,
89
+ rowFocus,
89
90
  // triggerFilter,
90
91
  selectionSettings,
91
92
  isSelectionChange,
@@ -2213,6 +2214,7 @@ const TableContainerEdit = props => {
2213
2214
  originData,
2214
2215
  wrapSettings,
2215
2216
  recordDoubleClick,
2217
+ rowFocus,
2216
2218
  selectionSettings: {
2217
2219
  ...selectionSettings,
2218
2220
  checkboxOnly: true
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
+ var _rowFocus = require("../../grid-component/hooks/rowFocus");
8
9
  var _space = _interopRequireDefault(require("rc-master-ui/es/space"));
9
10
  var _Command = _interopRequireDefault(require("../components/command/Command"));
10
11
  var _utils = require("../hook/utils");
@@ -164,6 +165,7 @@ const TableBodyCell = props => {
164
165
  id,
165
166
  prefix,
166
167
  focusedCell,
168
+ rowFocus,
167
169
  setFocusedCell,
168
170
  // endCell,
169
171
  // startCell,
@@ -462,6 +464,7 @@ const TableBodyCell = props => {
462
464
  colId: cell.column.id,
463
465
  rowId: nextId
464
466
  });
467
+ (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextId).original, 'arrowDown', selectionSettings?.useArrow, rowFocus);
465
468
  const rowQr = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextId}"]`);
466
469
  const cellFocus = rowQr?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
467
470
  if (cellFocus) {
@@ -475,6 +478,7 @@ const TableBodyCell = props => {
475
478
  colId: cell.column.id,
476
479
  rowId: nextId
477
480
  });
481
+ (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextId).original, 'arrowUp', selectionSettings?.useArrow, rowFocus);
478
482
  const rowQr = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextId}"]`);
479
483
  const cellFocus = rowQr?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
480
484
  if (cellFocus) {
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
+ var _rowFocus = require("../../grid-component/hooks/rowFocus");
8
9
  var _space = _interopRequireDefault(require("rc-master-ui/es/space"));
9
10
  var _Command = _interopRequireDefault(require("../components/command/Command"));
10
11
  var _utils = require("../hook/utils");
@@ -202,6 +203,7 @@ const TableBodyCellEdit = props => {
202
203
  editingKey,
203
204
  prefix,
204
205
  focusedCell,
206
+ rowFocus,
205
207
  rangeState,
206
208
  setFocusedCell,
207
209
  setEditingKey,
@@ -810,6 +812,7 @@ const TableBodyCellEdit = props => {
810
812
  rowId: nextRowId,
811
813
  colId
812
814
  });
815
+ (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextRowId).original, 'arrowDown', selectionSettings?.useArrow, rowFocus);
813
816
  setStartCell?.({
814
817
  rowId: nextRowId,
815
818
  colId
@@ -857,6 +860,7 @@ const TableBodyCellEdit = props => {
857
860
  rowId: nextRowId,
858
861
  colId
859
862
  });
863
+ (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextRowId).original, 'arrowUp', selectionSettings?.useArrow, rowFocus);
860
864
  setStartCell?.({
861
865
  rowId: nextRowId,
862
866
  colId
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
+ var _rowFocus = require("../../grid-component/hooks/rowFocus");
8
9
  var _utils = require("../hook/utils");
9
10
  var _classnames = _interopRequireDefault(require("classnames"));
10
11
  var _react = _interopRequireDefault(require("react"));
@@ -22,6 +23,7 @@ const TableBodyCellEmpty = props => {
22
23
  id,
23
24
  prefix,
24
25
  focusedCell,
26
+ rowFocus,
25
27
  setFocusedCell,
26
28
  setIsSelectionChange,
27
29
  isSelectionChange,
@@ -107,6 +109,7 @@ const TableBodyCellEmpty = props => {
107
109
  colId: cell.column.id,
108
110
  rowId: nextId
109
111
  });
112
+ (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextId).original, 'arrowDown', selectionSettings?.useArrow, rowFocus);
110
113
  const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextId}"]`);
111
114
  const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
112
115
  if (cellFocus) {
@@ -120,6 +123,7 @@ const TableBodyCellEmpty = props => {
120
123
  colId: cell.column.id,
121
124
  rowId: nextId
122
125
  });
126
+ (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextId).original, 'arrowUp', selectionSettings?.useArrow, rowFocus);
123
127
  const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextId}"]`);
124
128
  const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
125
129
  if (cellFocus) {
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = void 0;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var _rowFocus = require("../../grid-component/hooks/rowFocus");
9
10
  var _TableBodyCell = _interopRequireDefault(require("./TableBodyCell"));
10
11
  var _TableBodyCellEdit = _interopRequireDefault(require("./TableBodyCellEdit"));
11
12
  var _react = _interopRequireDefault(require("react"));
@@ -35,6 +36,7 @@ const TableBodyRow = ({
35
36
  const {
36
37
  prefix,
37
38
  recordDoubleClick,
39
+ rowFocus,
38
40
  focusedCell,
39
41
  rowClassName,
40
42
  rowEditable,
@@ -60,7 +62,7 @@ const TableBodyRow = ({
60
62
  const rowClass = typeof rowClassName === 'function' ? rowClassName(row.original, row.index, row.depth) : rowClassName;
61
63
  const rowStyles = typeof onRowStyles === 'function' ? onRowStyles(row.original, row) : onRowStyles;
62
64
  const isRowEditable = rowEditable ? rowEditable(row.original) : true;
63
- return /*#__PURE__*/_react.default.createElement("div", {
65
+ return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
64
66
  "data-index": virtualRow.index //needed for dynamic row height measurement
65
67
  ,
66
68
  ref: rowVirtualizer.measureElement //measure dynamic row height
@@ -86,7 +88,8 @@ const TableBodyRow = ({
86
88
  height: isEditing ? virtualRow.size : undefined,
87
89
  minHeight: isEditing ? undefined : virtualRow.size,
88
90
  ...rowStyles
89
- },
91
+ }
92
+ }, (0, _rowFocus.getRowFocusHandlers)(row.original, rowFocus), {
90
93
  onDoubleClick: e => {
91
94
  recordDoubleClick?.({
92
95
  e,
@@ -110,7 +113,7 @@ const TableBodyRow = ({
110
113
  field: colKey
111
114
  })(e);
112
115
  }
113
- }, fixedLeftColumns.length > 0 ? fixedLeftColumns.map(column => {
116
+ }), fixedLeftColumns.length > 0 ? fixedLeftColumns.map(column => {
114
117
  const cell = row.getVisibleCells().find(c => c.column.id === column.id);
115
118
  if (row.subRows && row.subRows.length === 0 && groupColumns?.includes(cell.column.id)) {
116
119
  return /*#__PURE__*/_react.default.createElement(_TableBodyCellEmpty.default, (0, _extends2.default)({}, rest, {
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
+ var _rowFocus = require("../../grid-component/hooks/rowFocus");
8
9
  var _space = _interopRequireDefault(require("rc-master-ui/es/space"));
9
10
  var _Command = _interopRequireDefault(require("../components/command/Command"));
10
11
  var _utils = require("../hook/utils");
@@ -164,6 +165,7 @@ const TableBodyCell = props => {
164
165
  id,
165
166
  prefix,
166
167
  focusedCell,
168
+ rowFocus,
167
169
  setFocusedCell,
168
170
  // endCell,
169
171
  // startCell,
@@ -442,6 +444,7 @@ const TableBodyCell = props => {
442
444
  colId: cell.column.id,
443
445
  rowId: nextId
444
446
  });
447
+ (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextId).original, 'arrowDown', selectionSettings?.useArrow, rowFocus);
445
448
  const rowQr = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextId}"]`);
446
449
  const cellFocus = rowQr?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
447
450
  if (cellFocus) {
@@ -455,6 +458,7 @@ const TableBodyCell = props => {
455
458
  colId: cell.column.id,
456
459
  rowId: nextId
457
460
  });
461
+ (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextId).original, 'arrowUp', selectionSettings?.useArrow, rowFocus);
458
462
  const rowQr = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextId}"]`);
459
463
  const cellFocus = rowQr?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
460
464
  if (cellFocus) {
@@ -167,7 +167,7 @@ export declare const fixColumnsLeft: <RecordType>(columns: ColumnTable<RecordTyp
167
167
  haveSum?: boolean;
168
168
  isSummary?: boolean;
169
169
  sumGroup?: boolean;
170
- summaryTemplate?: (data: number, key: string) => import("react").ReactNode | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
170
+ summaryTemplate?: (data: number, key: string) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNode;
171
171
  sorter?: boolean;
172
172
  allowFiltering?: boolean;
173
173
  allowSortering?: boolean;
@@ -179,27 +179,27 @@ export declare const fixColumnsLeft: <RecordType>(columns: ColumnTable<RecordTyp
179
179
  showFilterSearch?: boolean;
180
180
  hidden?: boolean;
181
181
  visible?: boolean;
182
- headerTooltip?: string | boolean | (() => import("react").ReactNode | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>);
182
+ headerTooltip?: string | boolean | (() => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNode);
183
183
  columnGroupText?: string;
184
184
  headerTextAlign?: import("./../../grid-component/type").ITextAlign;
185
- headerTemplate?: import("react").ReactNode | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | ((column: ColumnTable<RecordType>) => import("react").ReactNode | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>);
185
+ headerTemplate?: import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNode | ((column: ColumnTable<RecordType>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNode);
186
186
  fixedType?: import("./../../grid-component/type").FixedType;
187
187
  headerTextWrap?: boolean;
188
188
  ellipsis?: boolean;
189
189
  allowResizing?: boolean;
190
190
  align?: import("./../../grid-component/type").ITextAlign;
191
191
  textAlign?: import("./../../grid-component/type").ITextAlign;
192
- template?: import("react").ReactNode | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | ((args: import("./../../grid-component/type").ColumnTemplate<RecordType>) => import("react").ReactNode | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>);
193
- linkTemplate?: import("react").ReactNode | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | ((args: import("./../../grid-component/type").ColumnTemplate<RecordType>) => import("react").ReactNode | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>);
192
+ template?: import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNode | ((args: import("./../../grid-component/type").ColumnTemplate<RecordType>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNode);
193
+ linkTemplate?: import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNode | ((args: import("./../../grid-component/type").ColumnTemplate<RecordType>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNode);
194
194
  showTooltip?: boolean;
195
195
  tooltipDescription?: string | ((args: {
196
196
  value: any;
197
197
  rowData: RecordType;
198
- }) => import("react").ReactNode | import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>);
199
- onCellStyles?: Omit<CSSProperties, "left" | "right" | "display" | "minWidth" | "position" | "width"> | ((cellValue: any, cell: import("@tanstack/react-table").Cell<RecordType, unknown>) => Omit<CSSProperties, "left" | "right" | "display" | "minWidth" | "position" | "width">);
200
- onCellHeaderStyles?: Omit<CSSProperties, "left" | "right" | "display" | "minWidth" | "position" | "width"> | ((cell: import("@tanstack/react-table").Header<RecordType, unknown>) => Omit<CSSProperties, "left" | "right" | "display" | "minWidth" | "position" | "width">);
198
+ }) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNode);
199
+ onCellStyles?: Omit<CSSProperties, "width" | "minWidth" | "left" | "right" | "position" | "display"> | ((cellValue: any, cell: import("@tanstack/react-table").Cell<RecordType, unknown>) => Omit<CSSProperties, "width" | "minWidth" | "left" | "right" | "position" | "display">);
200
+ onCellHeaderStyles?: Omit<CSSProperties, "width" | "minWidth" | "left" | "right" | "position" | "display"> | ((cell: import("@tanstack/react-table").Header<RecordType, unknown>) => Omit<CSSProperties, "width" | "minWidth" | "left" | "right" | "position" | "display">);
201
201
  onCell?: (rowData: RecordType, index: number) => import("react").TdHTMLAttributes<HTMLTableCellElement>;
202
- onCellFooterStyles?: Omit<CSSProperties, "left" | "right" | "display" | "minWidth" | "position" | "width"> | ((cellValue: any, cell: import("@tanstack/react-table").Header<RecordType, unknown>) => Omit<CSSProperties, "left" | "right" | "display" | "minWidth" | "position" | "width">);
202
+ onCellFooterStyles?: Omit<CSSProperties, "width" | "minWidth" | "left" | "right" | "position" | "display"> | ((cellValue: any, cell: import("@tanstack/react-table").Header<RecordType, unknown>) => Omit<CSSProperties, "width" | "minWidth" | "left" | "right" | "position" | "display">);
203
203
  getValue?: (row: any, rowIndex: number) => any;
204
204
  getCellProps?: (value: any, row: any, rowIndex: number) => import("./../../grid-component/type").CellProps;
205
205
  headerCellProps?: import("./../../grid-component/type").CellProps;
@@ -1,3 +1,4 @@
1
+ import type { RowFocusEventArgs } from "../grid-component/type";
1
2
  import type { Dispatch, SetStateAction } from 'react';
2
3
  import type { ColumnTable, ExpandableConfig, IFormat, IGroupSetting, IWrapSettings, Locale, PaginationConfig, RangeState, RecordDoubleClickEventArgs, RowClassName, SelectionSettings, SourceFilter } from "./../grid-component/type";
3
4
  import type { SubmitHandler } from "react-hook-form";
@@ -19,6 +20,7 @@ export interface IContext<T> {
19
20
  setExpanded: Dispatch<SetStateAction<ExpandedState>>;
20
21
  expanded: ExpandedState;
21
22
  recordDoubleClick?: (args: RecordDoubleClickEventArgs<T>) => void;
23
+ rowFocus?: (args: RowFocusEventArgs<T>) => void;
22
24
  selectionSettings?: SelectionSettings;
23
25
  isSelectionChange?: {
24
26
  isChange: boolean;
package/lib/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { default as Dropdown } from './dropdown';
2
2
  export type { DropdownProps as DropDownProps, DropdownProps, } from './dropdown';
3
3
  export { default as GridComponent } from './grid-component';
4
- export type { ColumnsTable, TableProps, ColumnTable, CommandItem, ToolbarItem, ContextMenuItem } from './grid-component';
4
+ export type { ColumnsTable, TableProps, ColumnTable, CommandItem, ToolbarItem, ContextMenuItem, RowFocusEventArgs } from './grid-component';
5
5
  export { default as Tabs } from './tabs';
6
6
  export type { TabPaneProps, TabsProps } from './tabs';
7
7
  export { default as SelectTable } from './select-table';
@@ -36,6 +36,7 @@ const TableContainer = props => {
36
36
  expandable,
37
37
  wrapSettings,
38
38
  recordDoubleClick,
39
+ rowFocus,
39
40
  // triggerFilter,
40
41
  selectionSettings,
41
42
  isSelectionChange,
@@ -332,6 +333,7 @@ const TableContainer = props => {
332
333
  // triggerFilter,
333
334
  wrapSettings,
334
335
  recordDoubleClick,
336
+ rowFocus,
335
337
  recordClick,
336
338
  selectionSettings,
337
339
  isSelectionChange,
@@ -83,6 +83,7 @@ const TableContainerEdit = props => {
83
83
  expandable,
84
84
  wrapSettings,
85
85
  recordDoubleClick,
86
+ rowFocus,
86
87
  selectionSettings,
87
88
  isSelectionChange,
88
89
  setIsSelectionChange,
@@ -2224,6 +2225,7 @@ const TableContainerEdit = props => {
2224
2225
  originData,
2225
2226
  wrapSettings,
2226
2227
  recordDoubleClick,
2228
+ rowFocus,
2227
2229
  selectionSettings,
2228
2230
  isSelectionChange,
2229
2231
  setIsSelectionChange,
@@ -34,9 +34,13 @@ const TableBody = ({
34
34
  locale
35
35
  } = _react.default.useContext(_useContext.TableContext);
36
36
 
37
+ // Keep measured heights attached to records when expanding, sorting or filtering.
38
+ const getItemKey = _react.default.useCallback(index => rows[index].id, [rows]);
39
+
37
40
  //dynamic row height virtualization - alternatively you could use a simpler fixed row height strategy without the need for `measureElement`
38
41
  const rowVirtualizer = (0, _reactVirtual.useVirtualizer)({
39
42
  count: rows.length,
43
+ getItemKey,
40
44
  estimateSize: () => 32,
41
45
  //estimate row height for accurate scrollbar dragging
42
46
  getScrollElement: () => tableContainerRef.current,
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
+ var _rowFocus = require("../../grid-component/hooks/rowFocus");
8
9
  var _space = _interopRequireDefault(require("rc-master-ui/es/space"));
9
10
  var _Command = _interopRequireDefault(require("../components/command/Command"));
10
11
  var _utils = require("../hook/utils");
@@ -170,6 +171,7 @@ const TableBodyCell = props => {
170
171
  id,
171
172
  prefix,
172
173
  focusedCell,
174
+ rowFocus,
173
175
  setFocusedCell,
174
176
  // endCell,
175
177
  // startCell,
@@ -450,6 +452,7 @@ const TableBodyCell = props => {
450
452
  colId: cell.column.id,
451
453
  rowId: nextId
452
454
  });
455
+ (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextId).original, 'arrowDown', selectionSettings?.useArrow, rowFocus);
453
456
 
454
457
  // if (rowNumber < flatRows.length - 5) {
455
458
  // e.stopPropagation()
@@ -472,6 +475,7 @@ const TableBodyCell = props => {
472
475
  colId: cell.column.id,
473
476
  rowId: nextId
474
477
  });
478
+ (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextId).original, 'arrowUp', selectionSettings?.useArrow, rowFocus);
475
479
  const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextId}"]`);
476
480
  const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
477
481
  if (cellFocus) {
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
+ var _rowFocus = require("../../grid-component/hooks/rowFocus");
8
9
  var _space = _interopRequireDefault(require("rc-master-ui/es/space"));
9
10
  var _Command = _interopRequireDefault(require("../components/command/Command"));
10
11
  var _utils = require("../hook/utils");
@@ -199,6 +200,7 @@ const TableBodyCellEdit = props => {
199
200
  editingKey,
200
201
  prefix,
201
202
  focusedCell,
203
+ rowFocus,
202
204
  rangeState,
203
205
  setFocusedCell,
204
206
  setEditingKey,
@@ -833,6 +835,7 @@ const TableBodyCellEdit = props => {
833
835
  rowId: nextRowId,
834
836
  colId
835
837
  });
838
+ (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextRowId).original, 'arrowDown', selectionSettings?.useArrow, rowFocus);
836
839
  setStartCell?.({
837
840
  rowId: nextRowId,
838
841
  colId
@@ -871,6 +874,7 @@ const TableBodyCellEdit = props => {
871
874
  rowId: nextRowId,
872
875
  colId
873
876
  });
877
+ (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextRowId).original, 'arrowUp', selectionSettings?.useArrow, rowFocus);
874
878
  setStartCell?.({
875
879
  rowId: nextRowId,
876
880
  colId
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = void 0;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var _rowFocus = require("../../grid-component/hooks/rowFocus");
9
10
  var _TableBodyCell = _interopRequireDefault(require("./TableBodyCell"));
10
11
  var _TableBodyCellEdit = _interopRequireDefault(require("./TableBodyCellEdit"));
11
12
  var _react = _interopRequireDefault(require("react"));
@@ -32,6 +33,7 @@ const TableBodyRow = ({
32
33
  const {
33
34
  prefix,
34
35
  recordDoubleClick,
36
+ rowFocus,
35
37
  focusedCell,
36
38
  rowClassName,
37
39
  rowEditable,
@@ -61,10 +63,15 @@ const TableBodyRow = ({
61
63
  isSelected: row.getIsSelected()
62
64
  }) : onRowStyles;
63
65
  const isRowEditable = rowEditable ? rowEditable(row.original) : true;
64
- return /*#__PURE__*/_react.default.createElement("div", {
66
+
67
+ // A reused DOM row needs measuring again when its virtual index changes.
68
+ const measureRow = _react.default.useCallback(element => {
69
+ rowVirtualizer.measureElement(element);
70
+ }, [rowVirtualizer, virtualRow.index]);
71
+ return /*#__PURE__*/_react.default.createElement("div", (0, _extends2.default)({
65
72
  "data-index": virtualRow.index //needed for dynamic row height measurement
66
73
  ,
67
- ref: rowVirtualizer.measureElement //measure dynamic row height
74
+ ref: measureRow //measure dynamic row height
68
75
  ,
69
76
  key: row.id,
70
77
  "data-row-key": row.id,
@@ -87,7 +94,8 @@ const TableBodyRow = ({
87
94
  height: isEditing ? virtualRow.size : undefined,
88
95
  minHeight: isEditing ? undefined : virtualRow.size,
89
96
  ...rowStyles
90
- },
97
+ }
98
+ }, (0, _rowFocus.getRowFocusHandlers)(row.original, rowFocus), {
91
99
  onDoubleClick: e => {
92
100
  recordDoubleClick?.({
93
101
  e,
@@ -106,7 +114,7 @@ const TableBodyRow = ({
106
114
  })(e);
107
115
  // }
108
116
  }
109
- }, fixedLeftColumns.length > 0 ? fixedLeftColumns.map(column => {
117
+ }), fixedLeftColumns.length > 0 ? fixedLeftColumns.map(column => {
110
118
  const cell = row.getVisibleCells().find(c => c.column.id === column.id);
111
119
  if (editAble) {
112
120
  return /*#__PURE__*/_react.default.createElement(_TableBodyCellEdit.default, (0, _extends2.default)({}, rest, {
@@ -1,3 +1,4 @@
1
+ import type { RowFocusEventArgs } from "../grid-component/type";
1
2
  import type { Dispatch, SetStateAction } from 'react';
2
3
  import type { ColumnTable, ExpandableConfig, FilterItem, IFormat, IWrapSettings, Locale, PaginationConfig, RangeState, RecordDoubleClickEventArgs, RowClassName, SelectionSettings, SourceFilter } from "./../grid-component/type";
3
4
  import type { SubmitHandler } from "react-hook-form";
@@ -20,6 +21,7 @@ export interface IContext<T> {
20
21
  setExpanded: Dispatch<SetStateAction<ExpandedState>>;
21
22
  expanded: ExpandedState;
22
23
  recordDoubleClick?: (args: RecordDoubleClickEventArgs<T>) => void;
24
+ rowFocus?: (args: RowFocusEventArgs<T>) => void;
23
25
  recordClick?: (args: RecordDoubleClickEventArgs<T>) => void;
24
26
  selectionSettings?: SelectionSettings;
25
27
  isSelectionChange?: {
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
+ var _rowFocus = require("../../grid-component/hooks/rowFocus");
8
9
  var _space = _interopRequireDefault(require("rc-master-ui/es/space"));
9
10
  var _utils = require("../hook/utils");
10
11
  var _Checkbox = _interopRequireDefault(require("rc-master-ui/lib/checkbox/Checkbox"));
@@ -158,6 +159,7 @@ const TableBodyCell = props => {
158
159
  id,
159
160
  prefix,
160
161
  focusedCell,
162
+ rowFocus,
161
163
  setFocusedCell,
162
164
  // endCell,
163
165
  // startCell,
@@ -389,6 +391,7 @@ const TableBodyCell = props => {
389
391
  colId: cell.column.id,
390
392
  rowId: nextId
391
393
  });
394
+ (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextId).original, 'arrowDown', selectionSettings?.useArrow, rowFocus);
392
395
  const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextId}"]`);
393
396
  const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
394
397
  if (cellFocus) {
@@ -402,6 +405,7 @@ const TableBodyCell = props => {
402
405
  colId: cell.column.id,
403
406
  rowId: nextId
404
407
  });
408
+ (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextId).original, 'arrowUp', selectionSettings?.useArrow, rowFocus);
405
409
  const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextId}"]`);
406
410
  const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
407
411
  if (cellFocus) {
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.default = void 0;
8
+ var _rowFocus = require("../../grid-component/hooks/rowFocus");
8
9
  var _utils = require("../hook/utils");
9
10
  var _classnames = _interopRequireDefault(require("classnames"));
10
11
  var _react = _interopRequireDefault(require("react"));
@@ -23,6 +24,7 @@ const TableBodyCellRowGroup = props => {
23
24
  id,
24
25
  prefix,
25
26
  focusedCell,
27
+ rowFocus,
26
28
  setFocusedCell,
27
29
  expanded,
28
30
  setExpanded,
@@ -104,6 +106,7 @@ const TableBodyCellRowGroup = props => {
104
106
  colId: cell.column.id,
105
107
  rowId: nextId
106
108
  });
109
+ (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextId).original, 'arrowDown', selectionSettings?.useArrow, rowFocus);
107
110
  const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextId}"]`);
108
111
  const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
109
112
  if (cellFocus) {
@@ -117,6 +120,7 @@ const TableBodyCellRowGroup = props => {
117
120
  colId: cell.column.id,
118
121
  rowId: nextId
119
122
  });
123
+ (0, _rowFocus.notifyArrowRowFocus)(table.getRow(nextId).original, 'arrowUp', selectionSettings?.useArrow, rowFocus);
120
124
  const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextId}"]`);
121
125
  const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
122
126
  if (cellFocus) {
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.default = void 0;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var _rowFocus = require("../../grid-component/hooks/rowFocus");
9
10
  var _TableBodyCell = _interopRequireDefault(require("./TableBodyCell"));
10
11
  var _reactTable = require("@tanstack/react-table");
11
12
  var _react = _interopRequireDefault(require("react"));
@@ -33,6 +34,7 @@ const TableBodyRow = ({
33
34
  const {
34
35
  prefix,
35
36
  recordDoubleClick,
37
+ rowFocus,
36
38
  focusedCell,
37
39
  rowClassName,
38
40
  onRowStyles,
@@ -67,7 +69,8 @@ const TableBodyRow = ({
67
69
  style: {
68
70
  ...rowStyles,
69
71
  height: rowheight
70
- },
72
+ }
73
+ }, (0, _rowFocus.getRowFocusHandlers)(row.original, rowFocus), {
71
74
  onDoubleClick: e => {
72
75
  recordDoubleClick?.({
73
76
  e,
@@ -37,6 +37,7 @@ const TableContainer = props => {
37
37
  expandable,
38
38
  wrapSettings,
39
39
  recordDoubleClick,
40
+ rowFocus,
40
41
  // triggerFilter,
41
42
  selectionSettings,
42
43
  isSelectionChange,
@@ -281,6 +282,7 @@ const TableContainer = props => {
281
282
  originData,
282
283
  wrapSettings,
283
284
  recordDoubleClick,
285
+ rowFocus,
284
286
  selectionSettings,
285
287
  isSelectionChange,
286
288
  setIsSelectionChange,
@@ -1,3 +1,4 @@
1
+ import type { RowFocusEventArgs } from "../grid-component/type";
1
2
  import type { Dispatch, SetStateAction } from 'react';
2
3
  import type { ColumnTable, ExpandableConfig, IFormat, IGroupSetting, IWrapSettings, Locale, PaginationConfig, RangeState, RecordDoubleClickEventArgs, RowClassName, SelectionSettings, SourceFilter } from "../grid-component/type";
3
4
  import type { SubmitHandler } from "react-hook-form";
@@ -19,6 +20,7 @@ export interface IContext<T> {
19
20
  setExpanded: Dispatch<SetStateAction<ExpandedState>>;
20
21
  expanded: ExpandedState;
21
22
  recordDoubleClick?: (args: RecordDoubleClickEventArgs<T>) => void;
23
+ rowFocus?: (args: RowFocusEventArgs<T>) => void;
22
24
  selectionSettings?: SelectionSettings;
23
25
  isSelectionChange?: {
24
26
  isChange: boolean;