es-grid-template 1.7.22 → 1.7.24

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 (173) hide show
  1. package/es/grid-component/GridStyle.js +1 -1
  2. package/es/grid-component/InternalTable.js +5 -1
  3. package/es/grid-component/TableGrid.js +2 -2
  4. package/es/index.d.ts +1 -0
  5. package/es/index.js +3 -1
  6. package/es/table-component/ColumnsChoose.d.ts +10 -0
  7. package/es/table-component/ColumnsChoose.js +557 -0
  8. package/es/table-component/ContextMenu.d.ts +20 -0
  9. package/es/table-component/ContextMenu.js +75 -0
  10. package/es/table-component/InternalTable.d.ts +9 -0
  11. package/es/table-component/InternalTable.js +295 -0
  12. package/es/table-component/TableContainer.d.ts +22 -0
  13. package/es/table-component/TableContainer.js +130 -0
  14. package/es/table-component/TableContainerEdit.d.ts +28 -0
  15. package/es/table-component/TableContainerEdit.js +1211 -0
  16. package/es/table-component/body/EditableCell.d.ts +16 -0
  17. package/es/table-component/body/EditableCell.js +1036 -0
  18. package/es/table-component/body/TableBody.d.ts +19 -0
  19. package/es/table-component/body/TableBody.js +64 -0
  20. package/es/table-component/body/TableBodyCell.d.ts +10 -0
  21. package/es/table-component/body/TableBodyCell.js +139 -0
  22. package/es/table-component/body/TableBodyCellEdit.d.ts +15 -0
  23. package/es/table-component/body/TableBodyCellEdit.js +814 -0
  24. package/es/table-component/body/TableBodyRow.d.ts +21 -0
  25. package/es/table-component/body/TableBodyRow.js +146 -0
  26. package/es/table-component/components/ControlCheckbox.d.ts +13 -0
  27. package/es/table-component/components/ControlCheckbox.js +87 -0
  28. package/es/table-component/components/EditForm/EditForm.d.ts +27 -0
  29. package/es/table-component/components/EditForm/EditForm.js +395 -0
  30. package/es/table-component/components/EditForm/index.d.ts +1 -0
  31. package/es/table-component/components/EditForm/index.js +1 -0
  32. package/es/table-component/components/InputControl/InputControl.d.ts +27 -0
  33. package/es/table-component/components/InputControl/InputControl.js +121 -0
  34. package/es/table-component/components/InputControl/index.d.ts +1 -0
  35. package/es/table-component/components/InputControl/index.js +1 -0
  36. package/es/table-component/components/async-select/index.d.ts +11 -0
  37. package/es/table-component/components/async-select/index.js +41 -0
  38. package/es/table-component/components/async-table-select/index.d.ts +11 -0
  39. package/es/table-component/components/async-table-select/index.js +43 -0
  40. package/es/table-component/components/checkbox-control/index.d.ts +13 -0
  41. package/es/table-component/components/checkbox-control/index.js +40 -0
  42. package/es/table-component/components/checkbox-filter/CheckboxFilter.d.ts +18 -0
  43. package/es/table-component/components/checkbox-filter/CheckboxFilter.js +240 -0
  44. package/es/table-component/components/checkbox-filter/FilterSearch.d.ts +12 -0
  45. package/es/table-component/components/checkbox-filter/FilterSearch.js +36 -0
  46. package/es/table-component/components/command/Command.d.ts +9 -0
  47. package/es/table-component/components/command/Command.js +28 -0
  48. package/es/table-component/components/number/index.d.ts +10 -0
  49. package/es/table-component/components/number/index.js +42 -0
  50. package/es/table-component/components/number-range/index.d.ts +11 -0
  51. package/es/table-component/components/number-range/index.js +66 -0
  52. package/es/table-component/features/operator.d.ts +24 -0
  53. package/es/table-component/features/operator.js +62 -0
  54. package/es/table-component/footer/TableFooter.d.ts +13 -0
  55. package/es/table-component/footer/TableFooter.js +33 -0
  56. package/es/table-component/footer/TableFooterCell.d.ts +10 -0
  57. package/es/table-component/footer/TableFooterCell.js +24 -0
  58. package/es/table-component/footer/TableFooterRow.d.ts +14 -0
  59. package/es/table-component/footer/TableFooterRow.js +71 -0
  60. package/es/table-component/header/TableHead.d.ts +14 -0
  61. package/es/table-component/header/TableHead.js +60 -0
  62. package/es/table-component/header/TableHeadCell.d.ts +14 -0
  63. package/es/table-component/header/TableHeadCell.js +324 -0
  64. package/es/table-component/header/TableHeadRow.d.ts +16 -0
  65. package/es/table-component/header/TableHeadRow.js +86 -0
  66. package/es/table-component/header/renderFilter.d.ts +20 -0
  67. package/es/table-component/header/renderFilter.js +281 -0
  68. package/es/table-component/hook/constant.d.ts +73 -0
  69. package/es/table-component/hook/constant.js +240 -0
  70. package/es/table-component/hook/useColumns.d.ts +11 -0
  71. package/es/table-component/hook/useColumns.js +209 -0
  72. package/es/table-component/hook/useFilterOperator.d.ts +7 -0
  73. package/es/table-component/hook/useFilterOperator.js +33 -0
  74. package/es/table-component/hook/utils.d.ts +121 -0
  75. package/es/table-component/hook/utils.js +1727 -0
  76. package/es/table-component/index.d.ts +5 -0
  77. package/es/table-component/index.js +2 -0
  78. package/es/table-component/style.scss +1083 -0
  79. package/es/table-component/table/Grid.d.ts +23 -0
  80. package/es/table-component/table/Grid.js +310 -0
  81. package/es/table-component/table/GridEdit.d.ts +23 -0
  82. package/es/table-component/table/GridEdit.js +282 -0
  83. package/es/table-component/type.d.ts +482 -0
  84. package/es/table-component/type.js +1 -0
  85. package/es/table-component/useContext.d.ts +119 -0
  86. package/es/table-component/useContext.js +61 -0
  87. package/lib/grid-component/GridStyle.js +1 -1
  88. package/lib/grid-component/InternalTable.js +5 -1
  89. package/lib/grid-component/TableGrid.js +2 -2
  90. package/lib/index.d.ts +1 -0
  91. package/lib/index.js +8 -1
  92. package/lib/table-component/ColumnsChoose.d.ts +10 -0
  93. package/lib/table-component/ColumnsChoose.js +568 -0
  94. package/lib/table-component/ContextMenu.d.ts +20 -0
  95. package/lib/table-component/ContextMenu.js +85 -0
  96. package/lib/table-component/InternalTable.d.ts +9 -0
  97. package/lib/table-component/InternalTable.js +299 -0
  98. package/lib/table-component/TableContainer.d.ts +22 -0
  99. package/lib/table-component/TableContainer.js +137 -0
  100. package/lib/table-component/TableContainerEdit.d.ts +28 -0
  101. package/lib/table-component/TableContainerEdit.js +1220 -0
  102. package/lib/table-component/body/EditableCell.d.ts +16 -0
  103. package/lib/table-component/body/EditableCell.js +1038 -0
  104. package/lib/table-component/body/TableBody.d.ts +19 -0
  105. package/lib/table-component/body/TableBody.js +72 -0
  106. package/lib/table-component/body/TableBodyCell.d.ts +10 -0
  107. package/lib/table-component/body/TableBodyCell.js +148 -0
  108. package/lib/table-component/body/TableBodyCellEdit.d.ts +15 -0
  109. package/lib/table-component/body/TableBodyCellEdit.js +821 -0
  110. package/lib/table-component/body/TableBodyRow.d.ts +21 -0
  111. package/lib/table-component/body/TableBodyRow.js +153 -0
  112. package/lib/table-component/components/ControlCheckbox.d.ts +13 -0
  113. package/lib/table-component/components/ControlCheckbox.js +95 -0
  114. package/lib/table-component/components/EditForm/EditForm.d.ts +27 -0
  115. package/lib/table-component/components/EditForm/EditForm.js +406 -0
  116. package/lib/table-component/components/EditForm/index.d.ts +1 -0
  117. package/lib/table-component/components/EditForm/index.js +16 -0
  118. package/lib/table-component/components/InputControl/InputControl.d.ts +27 -0
  119. package/lib/table-component/components/InputControl/InputControl.js +131 -0
  120. package/lib/table-component/components/InputControl/index.d.ts +1 -0
  121. package/lib/table-component/components/InputControl/index.js +16 -0
  122. package/lib/table-component/components/async-select/index.d.ts +11 -0
  123. package/lib/table-component/components/async-select/index.js +49 -0
  124. package/lib/table-component/components/async-table-select/index.d.ts +11 -0
  125. package/lib/table-component/components/async-table-select/index.js +51 -0
  126. package/lib/table-component/components/checkbox-control/index.d.ts +13 -0
  127. package/lib/table-component/components/checkbox-control/index.js +48 -0
  128. package/lib/table-component/components/checkbox-filter/CheckboxFilter.d.ts +18 -0
  129. package/lib/table-component/components/checkbox-filter/CheckboxFilter.js +249 -0
  130. package/lib/table-component/components/checkbox-filter/FilterSearch.d.ts +12 -0
  131. package/lib/table-component/components/checkbox-filter/FilterSearch.js +44 -0
  132. package/lib/table-component/components/command/Command.d.ts +9 -0
  133. package/lib/table-component/components/command/Command.js +37 -0
  134. package/lib/table-component/components/number/index.d.ts +10 -0
  135. package/lib/table-component/components/number/index.js +50 -0
  136. package/lib/table-component/components/number-range/index.d.ts +11 -0
  137. package/lib/table-component/components/number-range/index.js +74 -0
  138. package/lib/table-component/features/operator.d.ts +24 -0
  139. package/lib/table-component/features/operator.js +67 -0
  140. package/lib/table-component/footer/TableFooter.d.ts +13 -0
  141. package/lib/table-component/footer/TableFooter.js +42 -0
  142. package/lib/table-component/footer/TableFooterCell.d.ts +10 -0
  143. package/lib/table-component/footer/TableFooterCell.js +32 -0
  144. package/lib/table-component/footer/TableFooterRow.d.ts +14 -0
  145. package/lib/table-component/footer/TableFooterRow.js +79 -0
  146. package/lib/table-component/header/TableHead.d.ts +14 -0
  147. package/lib/table-component/header/TableHead.js +69 -0
  148. package/lib/table-component/header/TableHeadCell.d.ts +14 -0
  149. package/lib/table-component/header/TableHeadCell.js +333 -0
  150. package/lib/table-component/header/TableHeadRow.d.ts +16 -0
  151. package/lib/table-component/header/TableHeadRow.js +94 -0
  152. package/lib/table-component/header/renderFilter.d.ts +20 -0
  153. package/lib/table-component/header/renderFilter.js +291 -0
  154. package/lib/table-component/hook/constant.d.ts +73 -0
  155. package/lib/table-component/hook/constant.js +247 -0
  156. package/lib/table-component/hook/useColumns.d.ts +11 -0
  157. package/lib/table-component/hook/useColumns.js +220 -0
  158. package/lib/table-component/hook/useFilterOperator.d.ts +7 -0
  159. package/lib/table-component/hook/useFilterOperator.js +40 -0
  160. package/lib/table-component/hook/utils.d.ts +121 -0
  161. package/lib/table-component/hook/utils.js +1817 -0
  162. package/lib/table-component/index.d.ts +5 -0
  163. package/lib/table-component/index.js +9 -0
  164. package/lib/table-component/style.scss +1083 -0
  165. package/lib/table-component/table/Grid.d.ts +23 -0
  166. package/lib/table-component/table/Grid.js +313 -0
  167. package/lib/table-component/table/GridEdit.d.ts +23 -0
  168. package/lib/table-component/table/GridEdit.js +284 -0
  169. package/lib/table-component/type.d.ts +482 -0
  170. package/lib/table-component/type.js +5 -0
  171. package/lib/table-component/useContext.d.ts +119 -0
  172. package/lib/table-component/useContext.js +67 -0
  173. package/package.json +3 -1
@@ -0,0 +1,821 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _reactTable = require("@tanstack/react-table");
9
+ var _space = _interopRequireDefault(require("rc-master-ui/es/space"));
10
+ var _Command = _interopRequireDefault(require("../components/command/Command"));
11
+ var _utils = require("../hook/utils");
12
+ var _Checkbox = _interopRequireDefault(require("rc-master-ui/lib/checkbox/Checkbox"));
13
+ var _classnames = _interopRequireDefault(require("classnames"));
14
+ var _react = _interopRequireDefault(require("react"));
15
+ var _useContext = require("../useContext");
16
+ var _EditableCell = _interopRequireDefault(require("./EditableCell"));
17
+ var _constant = require("../hook/constant");
18
+ // import { nonActionColumn } from "../hook/constant";
19
+
20
+ // import type { Dispatch, SetStateAction } from "react";
21
+
22
+ // import { nonActionColumn } from "../hook/constant";
23
+
24
+ const renderCellIndex = props => {
25
+ const {
26
+ parrents,
27
+ cell
28
+ } = props;
29
+ return /*#__PURE__*/_react.default.createElement("span", null, parrents.map(pr => {
30
+ return `${pr.index + 1}.`;
31
+ }), cell.row.index + 1);
32
+ };
33
+ const renderCommand = args => {
34
+ const {
35
+ cell,
36
+ commandClick
37
+ } = args;
38
+ const col = cell.column.columnDef.meta ?? {};
39
+ const record = cell.row.original;
40
+
41
+ // const commandItems = args.cell.column.columnDef?.meta?.commandItems ?? []
42
+
43
+ const commands = col.commandItems ? col.commandItems.map(it => {
44
+ return {
45
+ ...it,
46
+ visible: typeof it.visible === 'function' ? it.visible?.(record) : it.visible
47
+ };
48
+ }) : [];
49
+ return /*#__PURE__*/_react.default.createElement(_space.default, null, commands.filter(it => it.visible !== false).map(item => {
50
+ return /*#__PURE__*/_react.default.createElement(_Command.default, {
51
+ key: item.id,
52
+ item: item,
53
+ record: record,
54
+ onClick: () => {
55
+ commandClick?.({
56
+ id: item.id,
57
+ // rowId: getRowKey(record, index) as any,
58
+ rowId: record.rowId,
59
+ rowData: record,
60
+ index: cell.row.index
61
+ // rows: [...resource]
62
+ });
63
+ }
64
+ });
65
+ }));
66
+ };
67
+ const renderSelection = args => {
68
+ const {
69
+ row
70
+ } = args.cell;
71
+ return /*#__PURE__*/_react.default.createElement("div", {
72
+ style: {
73
+
74
+ // paddingLeft: `${row.depth * 2}rem`,
75
+ }
76
+ }, /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_Checkbox.default, {
77
+ checked: row.getIsSelected(),
78
+ indeterminate: row.getIsSomeSelected(),
79
+ onChange: row.getToggleSelectedHandler()
80
+ })));
81
+ };
82
+ const TableBodyCellEdit = props => {
83
+ const {
84
+ cell,
85
+ commandClick,
86
+ // tableId,
87
+ table,
88
+ isEditing,
89
+ columnVirtualizer,
90
+ rowVirtualizer
91
+ } = props;
92
+ const {
93
+ rowKey,
94
+ editingKey,
95
+ prefix,
96
+ focusedCell,
97
+ rangeState,
98
+ setFocusedCell,
99
+ setEditingKey,
100
+ setRangeState,
101
+ setRangePasteState,
102
+ endCell,
103
+ setEndCell,
104
+ isSelecting,
105
+ isPasting,
106
+ setEndPasteCell,
107
+ endPasteCell,
108
+ setIsPasting,
109
+ setIsSelecting,
110
+ setStartCell,
111
+ setStartPasteCell,
112
+ startCell,
113
+ startPasteCell,
114
+ originData,
115
+ dataSource,
116
+ triggerPaste,
117
+ handleDeleteContent,
118
+ reset,
119
+ setValue,
120
+ handleAddMulti
121
+ // expandable
122
+ } = _react.default.useContext(_useContext.TableContext);
123
+
124
+ // const expandIconColumnIndex = expandable?.expandIconColumnIndex ?? 0
125
+
126
+ const record = cell.row.original;
127
+ const canEdit = (0, _utils.isEditable)(cell.column.columnDef.meta, record);
128
+ // const allRows = table.getRowModel().rows;
129
+ const allRows = table.getRowModel().flatRows;
130
+
131
+ // const rowNumber = cell.row.index
132
+ const rowNumber = allRows.findIndex(it => it.id === cell.row.id);
133
+ const colIndex = cell.column.getIndex();
134
+ const isPinned = cell.column.getIsPinned();
135
+ const isLastLeftPinnedColumn = isPinned === "left" && cell.column.getIsLastColumn("left");
136
+ const isFirstRightPinnedColumn = isPinned === "right" && cell.column.getIsFirstColumn("right");
137
+ const isCellSelected = _react.default.useMemo(() => {
138
+ if (!startCell || !endCell) return false;
139
+ const rowIds = (0, _utils.getRowIdsBetween)(table, startCell.rowId, endCell.rowId);
140
+ const colIds = (0, _utils.getColIdsBetween)(table, startCell.colId, endCell.colId);
141
+ return rowIds.includes(cell.row.id) && colIds.includes(cell.column.id);
142
+ }, [cell.column.id, cell.row.id, endCell, startCell, table]);
143
+ const columnMeta = cell.column.columnDef.meta ?? {};
144
+ const editType = typeof columnMeta.editType === 'function' ? columnMeta.editType(record) : columnMeta.editType;
145
+ const {
146
+ rowRange,
147
+ colRange,
148
+ rowIds,
149
+ colIds,
150
+ startColIndex,
151
+ startRowIndex,
152
+ endColIndex,
153
+ endRowIndex
154
+ } = rangeState ?? {};
155
+ const pasteRangeState = (0, _utils.getSelectedCellMatrix)(table, startPasteCell, endPasteCell);
156
+ const isInRange = colRange && rowRange && rowRange.includes(cell.row.id) && colRange.includes(cell.column.id);
157
+ const isInRangePaste = pasteRangeState.rowRange && pasteRangeState.rowRange.includes(cell.row.id) && pasteRangeState.colRange.includes(cell.column.id);
158
+
159
+ // const isInRangePaste = rowRange && rowRange.includes(cell.row.id) && colRange.includes(cell.column.id);
160
+
161
+ const rowIdx = rowIds ? rowIds.indexOf(cell.row.id) : -1;
162
+ const colIdx = colIds ? colIds.indexOf(cell.column.id) : -1;
163
+ const rowIdxPaste = pasteRangeState.rowIds.indexOf(cell.row.id);
164
+ const colIdxPaste = pasteRangeState.colIds.indexOf(cell.column.id);
165
+ const isTop = rowIdx === startRowIndex;
166
+ const isBottom = rowIdx === endRowIndex;
167
+ const isLeft = colIdx === startColIndex;
168
+ const isRight = colIdx === endColIndex;
169
+ const isTopPaste = rowIdxPaste === pasteRangeState.startRowIndex;
170
+ const isBottomPaste = rowIdxPaste === pasteRangeState.endRowIndex;
171
+ const isLeftPaste = colIdxPaste === pasteRangeState.startColIndex;
172
+ const isRightPaste = colIdxPaste === pasteRangeState.endColIndex;
173
+ const parrents = cell.row.getParentRows();
174
+ if (cell.column.id === "#") {
175
+ return /*#__PURE__*/_react.default.createElement("td", {
176
+ key: cell.id,
177
+ className: (0, _classnames.default)(`${prefix}-grid-cell`, {
178
+ [`${prefix}-grid-cell-ellipsis`]: true,
179
+ [`${prefix}-grid-cell-fix-left-last`]: isLastLeftPinnedColumn,
180
+ [`${prefix}-grid-cell-fix-right-first`]: isFirstRightPinnedColumn
181
+ }),
182
+ style: {
183
+ display: 'flex',
184
+ height: '36px',
185
+ width: cell.column.getSize(),
186
+ ...(0, _utils.getCommonPinningStyles)(cell.column)
187
+ }
188
+ }, renderCellIndex({
189
+ parrents,
190
+ cell
191
+ }));
192
+ }
193
+ if (cell.column.id === "command") {
194
+ return /*#__PURE__*/_react.default.createElement("td", {
195
+ key: cell.id,
196
+ className: (0, _classnames.default)(`${prefix}-grid-cell`, {
197
+ [`${prefix}-grid-cell-ellipsis`]: true,
198
+ [`${prefix}-grid-cell-fix-left-last`]: isLastLeftPinnedColumn,
199
+ [`${prefix}-grid-cell-fix-right-first`]: isFirstRightPinnedColumn
200
+ }),
201
+ style: {
202
+ display: 'flex',
203
+ height: '36px',
204
+ width: cell.column.getSize(),
205
+ ...(0, _utils.getCommonPinningStyles)(cell.column)
206
+ }
207
+ }, renderCommand({
208
+ cell,
209
+ commandClick
210
+ }));
211
+ }
212
+ if (cell.column.id === "selection_column") {
213
+ return /*#__PURE__*/_react.default.createElement("td", {
214
+ key: cell.id,
215
+ className: (0, _classnames.default)(`${prefix}-grid-cell cell-editable111 `, {
216
+ [`${prefix}-grid-cell-ellipsis`]: true,
217
+ [`${prefix}-grid-cell-fix-left-last`]: isLastLeftPinnedColumn,
218
+ [`${prefix}-grid-cell-fix-right-first`]: isFirstRightPinnedColumn
219
+ }),
220
+ style: {
221
+ display: 'flex',
222
+ height: '36px',
223
+ width: cell.column.getSize(),
224
+ ...(0, _utils.getCommonPinningStyles)(cell.column)
225
+ }
226
+ }, renderSelection({
227
+ cell
228
+ }));
229
+ }
230
+ const triggerDragPaste = (pasteState, ctrlKey) => {
231
+ const tmpCols = table.getVisibleLeafColumns();
232
+ const rowPasteIds = (0, _utils.getRowIdsBetween)(table, startPasteCell?.rowId ?? '', endPasteCell?.rowId ?? '');
233
+ const colPasteds = (0, _utils.getColIdsBetween)(table, startPasteCell?.colId ?? '', endPasteCell?.colId ?? '');
234
+ const rowSelectIds = (0, _utils.getRowIdsBetween)(table, startCell?.rowId ?? '', endCell?.rowId ?? '');
235
+ const colSelectIds = (0, _utils.getColIdsBetween)(table, startCell?.colId ?? '', endCell?.colId ?? '');
236
+ const dataSelected = [];
237
+ rowSelectIds.forEach(rowId => {
238
+ const row = allRows.find(r => r.id === rowId);
239
+ if (!row) return;
240
+ const rowData = [];
241
+ colSelectIds.forEach(colId => {
242
+ const cellll = row.getVisibleCells().find(c => c.column.id === colId);
243
+ const value = cellll?.getValue();
244
+ rowData.push(value !== undefined ? String(value) : '');
245
+ });
246
+ dataSelected.push(rowData);
247
+ });
248
+ const copyRows = (0, _utils.flattenData)('children', dataSource).filter(it => rowSelectIds.includes(it[rowKey]));
249
+ let newRange;
250
+ if ((startRowIndex ?? 0) < (pasteRangeState.startRowIndex ?? 0)) {
251
+ // kéo xuóng
252
+ setRangeState?.((0, _utils.getSelectedCellMatrix)(table, startCell, endPasteCell));
253
+ newRange = ctrlKey ? (0, _utils.addRowsDownWithCtrl)(dataSelected, rowPasteIds.length) : (0, _utils.addRowsDown)(dataSelected, rowPasteIds.length);
254
+ } else {
255
+ // kéo lên
256
+ setStartCell?.(endCell);
257
+ setRangeState?.((0, _utils.getSelectedCellMatrix)(table, endCell, endPasteCell));
258
+ newRange = ctrlKey ? (0, _utils.addRowsUpWithCtrl)(dataSelected, rowPasteIds.length) : (0, _utils.addRowsUp)(dataSelected, rowPasteIds.length);
259
+ }
260
+
261
+ // Cập nhật data mới
262
+ const newData = (0, _utils.flattenArray)([...dataSource]);
263
+ const pastedRows = [];
264
+ newRange.addedRows.forEach((rowValues, rowIndex1) => {
265
+ const targetRow = pasteState.startRowIndex + rowIndex1;
266
+
267
+ // Nếu vượt quá số dòng hiện có, thêm dòng mới
268
+ if (targetRow >= newData.length) {
269
+ newData.push({
270
+ id: undefined,
271
+ rowId: (0, _utils.newGuid)()
272
+ });
273
+ }
274
+ rowValues.forEach((cellValue, colIndex1) => {
275
+ const targetCol = startColIndex + colIndex1;
276
+ if (targetCol >= tmpCols.length) {
277
+ // Không vượt quá số cột
278
+ return;
279
+ }
280
+ const columnKey = tmpCols[targetCol].id;
281
+ newData[targetRow] = {
282
+ ...newData[targetRow],
283
+ [columnKey]: typeof cellValue === 'string' ? cellValue.trim() : cellValue
284
+ };
285
+ });
286
+
287
+ // Lưu dòng được paste
288
+ pastedRows.push(newData[targetRow]);
289
+ });
290
+ const rsFilterData = (0, _utils.updateOrInsert)((0, _utils.flattenArray)([...originData]), newData);
291
+ const rs = (0, _utils.unFlattenData)(rsFilterData);
292
+ triggerPaste?.(pastedRows, colPasteds, rs, copyRows);
293
+
294
+ // // setRangeState?.(getSelectedCellMatrix(table, startCell, endPasteCell))
295
+
296
+ setEndCell?.(endPasteCell);
297
+ setEndPasteCell?.(undefined);
298
+ setStartPasteCell?.(undefined);
299
+ setRangePasteState?.(undefined);
300
+ };
301
+ const triggerPointPaste = (pasteState, cellStart, cellEnd, ctrlKey) => {
302
+ const tmpCols = table.getVisibleLeafColumns();
303
+ const rowPasteIds = (0, _utils.getRowIdsBetween)(table, cellStart?.rowId ?? '', cellEnd?.rowId ?? '');
304
+ const colPasteds = (0, _utils.getColIdsBetween)(table, cellStart?.colId ?? '', cellEnd?.colId ?? '');
305
+ const rowSelectIds = (0, _utils.getRowIdsBetween)(table, startCell?.rowId ?? '', endCell?.rowId ?? '');
306
+ const colSelectIds = (0, _utils.getColIdsBetween)(table, startCell?.colId ?? '', endCell?.colId ?? '');
307
+ const dataSelected = [];
308
+ rowSelectIds.forEach(rowId => {
309
+ const row = allRows.find(r => r.id === rowId);
310
+ if (!row) return;
311
+ const rowData = [];
312
+ colSelectIds.forEach(colId => {
313
+ const cellll = row.getVisibleCells().find(c => c.column.id === colId);
314
+ const value = cellll?.getValue();
315
+ rowData.push(value !== undefined ? String(value) : '');
316
+ });
317
+ dataSelected.push(rowData);
318
+ });
319
+ const copyRows = (0, _utils.flattenData)('children', dataSource).filter(it => rowSelectIds.includes(it[rowKey]));
320
+
321
+ // kéo xuóng
322
+ // setRangeState?.(getSelectedCellMatrix(table, startCell, endPasteCell))
323
+ const newRange = ctrlKey ? (0, _utils.addRowsDownWithCtrl)(dataSelected, rowPasteIds.length) : (0, _utils.addRowsDown)(dataSelected, rowPasteIds.length);
324
+
325
+ // Cập nhật data mới
326
+ const newData = (0, _utils.flattenArray)([...dataSource]);
327
+ const pastedRows = [];
328
+ newRange.addedRows.forEach((rowValues, rowIndex1) => {
329
+ const targetRow = pasteState.startRowIndex + rowIndex1;
330
+
331
+ // Nếu vượt quá số dòng hiện có, thêm dòng mới
332
+ if (targetRow >= newData.length) {
333
+ newData.push({
334
+ id: undefined,
335
+ rowId: (0, _utils.newGuid)()
336
+ });
337
+ }
338
+ rowValues.forEach((cellValue, colIndex1) => {
339
+ const targetCol = startColIndex + colIndex1;
340
+ if (targetCol >= tmpCols.length) {
341
+ // Không vượt quá số cột
342
+ return;
343
+ }
344
+ const columnKey = tmpCols[targetCol].id;
345
+ newData[targetRow] = {
346
+ ...newData[targetRow],
347
+ [columnKey]: typeof cellValue === 'string' ? cellValue.trim() : cellValue
348
+ };
349
+ });
350
+
351
+ // Lưu dòng được paste
352
+ pastedRows.push(newData[targetRow]);
353
+ });
354
+ const rsFilterData = (0, _utils.updateOrInsert)((0, _utils.flattenArray)([...originData]), newData);
355
+ const rs = (0, _utils.unFlattenData)(rsFilterData);
356
+ triggerPaste?.(pastedRows, colPasteds, rs, copyRows);
357
+ };
358
+ function handleMouseDown(rowId, colId) {
359
+ if ((startCell?.rowId !== rowId || startCell?.colId !== colId) && (endCell?.rowId !== rowId || endCell?.colId !== colId)) {
360
+ setStartCell?.({
361
+ rowId,
362
+ colId
363
+ });
364
+ setEndCell?.({
365
+ rowId,
366
+ colId
367
+ });
368
+ setIsSelecting?.(true);
369
+ setRangeState?.((0, _utils.getSelectedCellMatrix)(table, {
370
+ rowId,
371
+ colId
372
+ }, {
373
+ rowId,
374
+ colId
375
+ }));
376
+ }
377
+ if (focusedCell?.rowId !== cell.row.id || focusedCell?.colId !== cell.column.id) {
378
+ setFocusedCell?.({
379
+ rowId: cell.row.id,
380
+ colId: cell.column.id
381
+ });
382
+ }
383
+ }
384
+ function handleMouseEnter(rowId, colId) {
385
+ if (isSelecting) {
386
+ setEndCell?.({
387
+ rowId,
388
+ colId
389
+ });
390
+ }
391
+ if (isPasting) {
392
+ const absRowIndex = table.getRowModel().flatRows.findIndex(it => it.id === cell.row.id);
393
+ if ((startRowIndex ?? 0) > absRowIndex) {
394
+ // kéo lên
395
+
396
+ const startRowPaste = allRows.find(it => it.index === (startRowIndex ?? 0) - 1);
397
+ setStartPasteCell?.({
398
+ colId: startCell?.colId ?? '',
399
+ rowId: startRowPaste?.id ?? ''
400
+ });
401
+ setEndPasteCell?.({
402
+ colId: endCell?.colId ?? '',
403
+ rowId
404
+ });
405
+ setRangePasteState?.((0, _utils.getSelectedCellMatrix)(table, {
406
+ colId: startCell?.colId ?? '',
407
+ rowId: startRowPaste?.id ?? ''
408
+ }, {
409
+ colId: endCell?.colId ?? '',
410
+ rowId
411
+ }));
412
+ }
413
+ if ((startRowIndex ?? 0) < absRowIndex) {
414
+ // kéo xuống
415
+
416
+ const findIndex = allRows.findIndex(it => it.id === endCell?.rowId);
417
+ const startRowPaste = allRows[findIndex + 1];
418
+ setStartPasteCell?.({
419
+ colId: startCell?.colId ?? '',
420
+ rowId: startRowPaste?.id ?? ''
421
+ });
422
+ setEndPasteCell?.({
423
+ colId: endCell?.colId ?? '',
424
+ rowId
425
+ });
426
+ setRangePasteState?.((0, _utils.getSelectedCellMatrix)(table, {
427
+ colId: startCell?.colId ?? '',
428
+ rowId: startRowPaste?.id ?? ''
429
+ }, {
430
+ colId: endCell?.colId ?? '',
431
+ rowId
432
+ }));
433
+ }
434
+ }
435
+ }
436
+ const handlePointDoubleClick = e => {
437
+ e.preventDefault();
438
+ e.stopPropagation();
439
+ const rowEnd = table.getRowModel().flatRows[table.getRowModel().flatRows.length - 1];
440
+ const cellEnd = {
441
+ rowId: rowEnd.id,
442
+ colId: cell.column.id
443
+ };
444
+ const currentRowId = allRows.findIndex(it => it.id === cell.row.id);
445
+ const pasteStartRow = allRows[currentRowId + 1];
446
+ const cellStart = {
447
+ rowId: pasteStartRow.id,
448
+ colId: endCell?.colId ?? ''
449
+ };
450
+ const selectState = (0, _utils.getSelectedCellMatrix)(table, startCell, cellEnd);
451
+ const selectPasteState = (0, _utils.getSelectedCellMatrix)(table, cellStart, cellEnd);
452
+ setRangeState?.(selectState);
453
+ setEndCell?.(cellEnd);
454
+ triggerPointPaste(selectPasteState, cellStart, cellEnd, e.ctrlKey);
455
+ };
456
+ function handleMouseUp(e) {
457
+ setIsSelecting?.(false);
458
+ setIsPasting?.(false);
459
+ const selectState = (0, _utils.getSelectedCellMatrix)(table, startCell, endCell);
460
+ const selectPasteState = (0, _utils.getSelectedCellMatrix)(table, startPasteCell, endPasteCell);
461
+ if (endPasteCell && endCell?.rowId !== endPasteCell?.rowId && isPasting) {
462
+ triggerDragPaste(selectPasteState, e.ctrlKey);
463
+ } else {
464
+ // if ( endCell?.rowId !== rowId || endCell?.colId !== colId) {
465
+ // console.log('fffffffffffff')
466
+ // setRangeState?.(selectState)
467
+ // }
468
+
469
+ if (!(0, _utils.isObjEqual)(rangeState, selectState)) {
470
+ console.log('dfdfghh');
471
+ setRangeState?.(selectState);
472
+ }
473
+ }
474
+
475
+ // setRangePasteState(selectPasteState)
476
+ }
477
+ const handleEdit = e => {
478
+ setEditingKey?.(record[rowKey]);
479
+ // setTooltipContent('')
480
+
481
+ reset?.();
482
+
483
+ // const formattedRecord = { ...record };
484
+
485
+ if (!(0, _utils.isObjEmpty)(record)) {
486
+ Object.entries(record).forEach(([name, value]) => {
487
+ setValue?.(name, value);
488
+ });
489
+ }
490
+ if (e.key === 'Enter' || editType === 'date' || e.type === 'dblclick') {} else {
491
+ setValue(columnMeta.field, editType === 'numeric' ? !isNaN(Number(e.key)) ? Number(e.key) : '' : e.key);
492
+ }
493
+ if (editType === 'select') {
494
+
495
+ // setSearchValue(e.key)
496
+ // setOpen(true)
497
+ }
498
+ if (focusedCell?.rowId) {
499
+ setTimeout(() => {
500
+ // const input = document.querySelector(`.ui-rc-table-row .cell-editing[data-row-index="${startSelectedCells.current.row}"].cell-editing[data-col-index="${startSelectedCells.current.col}"] input`) as HTMLInputElement
501
+ // const textarea = document.querySelector(`.ui-rc-table-row .cell-editing[data-row-index="${rowNumber}"].cell-editing[data-col-index="${startSelectedCells.current.col}"] textarea`) as any
502
+ const textarea = document.querySelector(`.ui-rc-grid-row .cell-editing[data-row-key="${focusedCell.rowId}"].cell-editing[data-col-key="${focusedCell.colId}"] textarea`);
503
+ // const select = document.querySelector(`div.cell-editing[tabindex="${startSelectedCells.current.col}"] .ant-select-selection-search input`)
504
+
505
+ if (textarea) {
506
+ textarea.focus();
507
+ textarea.setSelectionRange(textarea.value.length, textarea.value.length);
508
+ }
509
+ // if (input) {
510
+ // input.focus()
511
+ // }
512
+
513
+ // if (select) {
514
+ // // @ts-ignore
515
+ // select.searchValue = e.key
516
+ // // @ts-ignore
517
+ // select.focus()
518
+ // }
519
+ }, 10);
520
+ }
521
+ };
522
+ function handleKeyDown(e, rowId, colId) {
523
+ if (e.key === 'Tab') {
524
+ e.preventDefault();
525
+ const allCols = table.getVisibleLeafColumns();
526
+ const currentColIndex = table.getColumn(colId)?.getIndex() ?? 0;
527
+ const nextCol = allCols[currentColIndex + 1];
528
+ if (nextCol) {
529
+ setFocusedCell?.({
530
+ rowId,
531
+ colId: nextCol.id
532
+ });
533
+ setStartCell?.({
534
+ rowId,
535
+ colId: nextCol.id
536
+ });
537
+ setEndCell?.({
538
+ rowId,
539
+ colId: nextCol.id
540
+ });
541
+ setRangeState?.((0, _utils.getSelectedCellMatrix)(table, {
542
+ rowId,
543
+ colId: nextCol.id
544
+ }, {
545
+ rowId,
546
+ colId: nextCol.id
547
+ }));
548
+ columnVirtualizer.scrollToIndex(nextCol.getIndex(), {
549
+ align: 'center'
550
+ });
551
+ } else {
552
+ // Nếu là cột cuối cùng, có thể nhảy xuống dòng tiếp theo
553
+
554
+ const currentRowIndex = allRows.findIndex(r => r.id === rowId);
555
+ const nextRow = allRows[currentRowIndex + 1];
556
+ const nextRowCol = allCols[2];
557
+ if (nextRow) {
558
+ setFocusedCell?.({
559
+ rowId: nextRow.id,
560
+ colId: nextRowCol.id
561
+ }); // sang dòng, cột đầu
562
+
563
+ setStartCell?.({
564
+ rowId: nextRow.id,
565
+ colId: nextRowCol.id
566
+ });
567
+ setEndCell?.({
568
+ rowId: nextRow.id,
569
+ colId: nextRowCol.id
570
+ });
571
+ setRangeState?.((0, _utils.getSelectedCellMatrix)(table, {
572
+ rowId: nextRow.id,
573
+ colId: nextRowCol.id
574
+ }, {
575
+ rowId: nextRow.id,
576
+ colId: nextRowCol.id
577
+ }));
578
+ columnVirtualizer.scrollToIndex(nextRowCol.getIndex());
579
+ rowVirtualizer.scrollToIndex(nextRow.index, {
580
+ align: 'auto'
581
+ });
582
+ }
583
+ }
584
+ }
585
+ if (e.key === 'ArrowRight') {
586
+ e.preventDefault();
587
+ e.stopPropagation();
588
+ const allCols = table.getVisibleLeafColumns().filter(it => !_constant.nonActionColumn.includes(it.id));
589
+ const currentColIndex = allCols.findIndex(it => it.id === cell.column.id);
590
+ const nextCol = allCols[currentColIndex + 1];
591
+ if (nextCol) {
592
+ setFocusedCell?.({
593
+ rowId,
594
+ colId: nextCol.id
595
+ });
596
+ setStartCell?.({
597
+ rowId,
598
+ colId: nextCol.id
599
+ });
600
+ setEndCell?.({
601
+ rowId,
602
+ colId: nextCol.id
603
+ });
604
+ setRangeState?.((0, _utils.getSelectedCellMatrix)(table, {
605
+ rowId,
606
+ colId: nextCol.id
607
+ }, {
608
+ rowId,
609
+ colId: nextCol.id
610
+ }));
611
+ columnVirtualizer.scrollToIndex(nextCol.getIndex(), {
612
+ align: 'center'
613
+ });
614
+ }
615
+ }
616
+ if (e.key === 'ArrowLeft') {
617
+ e.preventDefault();
618
+ const allCols = table.getVisibleLeafColumns().filter(it => !_constant.nonActionColumn.includes(it.id));
619
+
620
+ // const currentColIndex = table.getColumn(colId)?.getIndex() ?? 0;
621
+ const currentColIndex = allCols.findIndex(it => it.id === cell.column.id);
622
+ const nextCol = allCols[currentColIndex - 1];
623
+ if (nextCol) {
624
+ setFocusedCell?.({
625
+ rowId,
626
+ colId: nextCol.id
627
+ });
628
+ setStartCell?.({
629
+ rowId,
630
+ colId: nextCol.id
631
+ });
632
+ setEndCell?.({
633
+ rowId,
634
+ colId: nextCol.id
635
+ });
636
+ setRangeState?.((0, _utils.getSelectedCellMatrix)(table, {
637
+ rowId,
638
+ colId: nextCol.id
639
+ }, {
640
+ rowId,
641
+ colId: nextCol.id
642
+ }));
643
+ columnVirtualizer.scrollToIndex(nextCol.getIndex(), {
644
+ align: 'center'
645
+ });
646
+ }
647
+ }
648
+ if (e.key === 'Delete') {
649
+ handleDeleteContent?.();
650
+ }
651
+ if (e.key === 'Enter') {
652
+ handleEdit(e);
653
+ }
654
+ }
655
+ return /*#__PURE__*/_react.default.createElement("td", {
656
+ key: cell.id,
657
+ ref: el => {
658
+ if (focusedCell?.rowId === cell.row.id && focusedCell?.colId === cell.column.id && !isEditing) {
659
+ el?.focus();
660
+ }
661
+ },
662
+ tabIndex: focusedCell?.rowId === cell.row.id && focusedCell?.colId === cell.column.id ? 0 : -1,
663
+ "data-col-index": colIndex,
664
+ "data-row-index": rowNumber,
665
+ "data-col-key": cell.column.id,
666
+ "data-row-key": cell.row.id,
667
+ className: (0, _classnames.default)(`${prefix}-grid-cell cell-editable `, {
668
+ [`${prefix}-grid-cell-ellipsis`]: true,
669
+ 'cell-editing': isEditing,
670
+ [`${prefix}-grid-cell-selected`]: isCellSelected,
671
+ 'cell-border-bottom': !isEditing && isInRange && isBottom,
672
+ 'cell-border-right': !isEditing && isInRange && isRight,
673
+ 'cell-border-top': !isEditing && isInRange && isTop,
674
+ 'cell-border-left': !isEditing && isInRange && isLeft,
675
+ 'cell-paste-border-bottom': isInRangePaste && isBottomPaste && (pasteRangeState.endRowIndex ?? 0) > (endRowIndex ?? 0),
676
+ 'cell-paste-border-right': isInRangePaste && isRightPaste,
677
+ 'cell-paste-border-top': isInRangePaste && isTopPaste && (pasteRangeState.endRowIndex ?? 0) < (endRowIndex ?? 0),
678
+ 'cell-paste-border-left': isInRangePaste && isLeftPaste,
679
+ [`${prefix}-grid-cell-fix-left-last`]: isLastLeftPinnedColumn,
680
+ [`${prefix}-grid-cell-fix-right-first`]: isFirstRightPinnedColumn
681
+ }),
682
+ style: {
683
+ display: 'flex',
684
+ width: cell.column.getSize(),
685
+ height: '36px',
686
+ ...(0, _utils.getCommonPinningStyles)(cell.column),
687
+ cursor: isPasting ? 'crosshair' : undefined
688
+ // background: isCellSelected ? '#d0e6ff' : undefined,
689
+
690
+ // outline: focusedCell?.rowId === cell.row.id && focusedCell?.colId === cell.column.id ? '1px solid blue' : undefined,
691
+ },
692
+ onMouseDown: () => {
693
+ if (record[rowKey] === editingKey) {} else {
694
+ handleMouseDown(cell.row.id, cell.column.id);
695
+ }
696
+ if (record[rowKey] !== editingKey) {
697
+ setTimeout(() => {
698
+ setEditingKey?.('');
699
+ });
700
+ }
701
+ },
702
+ onMouseEnter: () => handleMouseEnter(cell.row.id, cell.column.id),
703
+ onMouseUp: e => handleMouseUp(e),
704
+ onMouseMove: () => {},
705
+ onKeyDown: e => {
706
+ if (!isEditing) {
707
+ handleKeyDown(e, cell.row.id, cell.column.id);
708
+ } else {
709
+ // setStartCell?.(undefined)
710
+
711
+ if (e.shiftKey && e.key === 'Enter') {} else {
712
+ if (e.key === 'Enter') {
713
+ e.preventDefault();
714
+ e.stopPropagation();
715
+ setEditingKey?.('');
716
+ const currentRowIndex = allRows.findIndex(r => r.id === cell.row.id);
717
+ const nextRow = allRows[currentRowIndex + 1];
718
+ if (nextRow) {
719
+ setFocusedCell?.({
720
+ rowId: nextRow.id,
721
+ colId: cell.column.id
722
+ });
723
+ setStartCell?.({
724
+ rowId: nextRow.id,
725
+ colId: cell.column.id
726
+ });
727
+ setEndCell?.({
728
+ rowId: nextRow.id,
729
+ colId: cell.column.id
730
+ });
731
+ setRangeState?.((0, _utils.getSelectedCellMatrix)(table, {
732
+ rowId: nextRow.id,
733
+ colId: cell.column.id
734
+ }, {
735
+ rowId: nextRow.id,
736
+ colId: cell.column.id
737
+ }));
738
+
739
+ // columnVirtualizer.scrollToIndex(nextCol.getIndex(), { align: 'center' })
740
+ } else {
741
+ const newRowId = (0, _utils.newGuid)();
742
+ handleAddMulti?.({}, 1, newRowId);
743
+ setFocusedCell?.({
744
+ rowId: newRowId,
745
+ colId: cell.column.id
746
+ });
747
+ setStartCell?.({
748
+ rowId: newRowId,
749
+ colId: cell.column.id
750
+ });
751
+ setEndCell?.({
752
+ rowId: newRowId,
753
+ colId: cell.column.id
754
+ });
755
+ setTimeout(() => {
756
+ setRangeState?.((0, _utils.getSelectedCellMatrix)(table, {
757
+ rowId: newRowId,
758
+ colId: cell.column.id
759
+ }, {
760
+ rowId: newRowId,
761
+ colId: cell.column.id
762
+ }));
763
+ // rowVirtualizer.scrollToIndex(101)
764
+ }, 0);
765
+ }
766
+ if (editingKey && editingKey !== '' && (rowNumber ?? 0) + 1 < (0, _utils.flattenArray)(dataSource).length) {
767
+
768
+ // handleFocusCell((rowNumber ?? 0) + 1, colIndex, column, 'vertical', event)
769
+ } else {
770
+ // // focus cell hiện tại và tắt edit
771
+ // handleFocusCell((rowNumber ?? 0), colIndex, column, 'vertical', event)
772
+ // setEditingKey('')
773
+
774
+ // thêm dòng mới
775
+
776
+ // handleAddSingle()
777
+ // handleFocusCell((rowNumber ?? 0) + 1, colIndex, column, 'vertical', event, true)
778
+ }
779
+ }
780
+ }
781
+ }
782
+ },
783
+ onDoubleClick: e => {
784
+ console.log('e', e);
785
+ if (!(record[rowKey] === editingKey && canEdit)) {
786
+ handleEdit(e);
787
+ }
788
+ }
789
+
790
+ // onClick={() => {
791
+ // // if (focusedCell?.rowId !== cell.row.id && focusedCell?.colId !== cell.column.id) {
792
+ // // setFocusedCell({ rowId: cell.row.id, colId: cell.column.id })
793
+ // // }
794
+
795
+ // }}
796
+ }, isEditing && canEdit ? /*#__PURE__*/_react.default.createElement(_EditableCell.default, {
797
+ cellEditing: {},
798
+ column: cell.column.columnDef.meta,
799
+ dataIndex: cell.column.id,
800
+ editType: (0, _utils.getEditType)(cell.column.columnDef.meta, record),
801
+ indexCol: cell.column.getIndex(),
802
+ indexRow: cell.row.index,
803
+ record: record
804
+ // rowKey={rowKey}
805
+ }) : /*#__PURE__*/_react.default.createElement("div", {
806
+ className: "ui-rc_cell-content"
807
+ }, (0, _reactTable.flexRender)(cell.column.columnDef.cell, cell.getContext())), !isSelecting && !isEditing && cell.row.id === endCell?.rowId && cell.column.getIndex() === rangeState?.endColIndex && /*#__PURE__*/_react.default.createElement("div", {
808
+ className: 'dragging-point',
809
+ onMouseDown: e => {
810
+ e.preventDefault();
811
+ e.stopPropagation();
812
+ if (e.button === 0) {
813
+ setIsPasting?.(true);
814
+ }
815
+ },
816
+ onDoubleClick: handlePointDoubleClick
817
+ }, /*#__PURE__*/_react.default.createElement("span", {
818
+ className: 'dot-point'
819
+ })));
820
+ };
821
+ var _default = exports.default = TableBodyCellEdit;