es-grid-template 1.7.23 → 1.7.25

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 (163) hide show
  1. package/es/index.d.ts +1 -0
  2. package/es/index.js +3 -1
  3. package/es/table-component/ColumnsChoose.d.ts +13 -0
  4. package/es/table-component/ColumnsChoose.js +206 -0
  5. package/es/table-component/ContextMenu.d.ts +20 -0
  6. package/es/table-component/ContextMenu.js +75 -0
  7. package/es/table-component/InternalTable.d.ts +9 -0
  8. package/es/table-component/InternalTable.js +308 -0
  9. package/es/table-component/TableContainer.d.ts +31 -0
  10. package/es/table-component/TableContainer.js +249 -0
  11. package/es/table-component/TableContainerEdit.d.ts +31 -0
  12. package/es/table-component/TableContainerEdit.js +1301 -0
  13. package/es/table-component/body/EditableCell.d.ts +16 -0
  14. package/es/table-component/body/EditableCell.js +1039 -0
  15. package/es/table-component/body/TableBody.d.ts +19 -0
  16. package/es/table-component/body/TableBody.js +64 -0
  17. package/es/table-component/body/TableBodyCell.d.ts +12 -0
  18. package/es/table-component/body/TableBodyCell.js +149 -0
  19. package/es/table-component/body/TableBodyCellEdit.d.ts +16 -0
  20. package/es/table-component/body/TableBodyCellEdit.js +931 -0
  21. package/es/table-component/body/TableBodyRow.d.ts +21 -0
  22. package/es/table-component/body/TableBodyRow.js +151 -0
  23. package/es/table-component/components/ControlCheckbox.d.ts +13 -0
  24. package/es/table-component/components/ControlCheckbox.js +84 -0
  25. package/es/table-component/components/EditForm/EditForm.d.ts +27 -0
  26. package/es/table-component/components/EditForm/EditForm.js +395 -0
  27. package/es/table-component/components/EditForm/index.d.ts +1 -0
  28. package/es/table-component/components/EditForm/index.js +1 -0
  29. package/es/table-component/components/InputControl/InputControl.d.ts +27 -0
  30. package/es/table-component/components/InputControl/InputControl.js +121 -0
  31. package/es/table-component/components/InputControl/index.d.ts +1 -0
  32. package/es/table-component/components/InputControl/index.js +1 -0
  33. package/es/table-component/components/async-select/index.d.ts +11 -0
  34. package/es/table-component/components/async-select/index.js +41 -0
  35. package/es/table-component/components/async-table-select/index.d.ts +11 -0
  36. package/es/table-component/components/async-table-select/index.js +44 -0
  37. package/es/table-component/components/checkbox-control/index.d.ts +13 -0
  38. package/es/table-component/components/checkbox-control/index.js +40 -0
  39. package/es/table-component/components/checkbox-filter/CheckboxFilter.d.ts +18 -0
  40. package/es/table-component/components/checkbox-filter/CheckboxFilter.js +240 -0
  41. package/es/table-component/components/checkbox-filter/FilterSearch.d.ts +12 -0
  42. package/es/table-component/components/checkbox-filter/FilterSearch.js +36 -0
  43. package/es/table-component/components/command/Command.d.ts +10 -0
  44. package/es/table-component/components/command/Command.js +33 -0
  45. package/es/table-component/components/number/index.d.ts +10 -0
  46. package/es/table-component/components/number/index.js +42 -0
  47. package/es/table-component/components/number-range/index.d.ts +11 -0
  48. package/es/table-component/components/number-range/index.js +66 -0
  49. package/es/table-component/features/operator.d.ts +24 -0
  50. package/es/table-component/features/operator.js +62 -0
  51. package/es/table-component/footer/TableFooter.d.ts +13 -0
  52. package/es/table-component/footer/TableFooter.js +33 -0
  53. package/es/table-component/footer/TableFooterCell.d.ts +10 -0
  54. package/es/table-component/footer/TableFooterCell.js +66 -0
  55. package/es/table-component/footer/TableFooterRow.d.ts +14 -0
  56. package/es/table-component/footer/TableFooterRow.js +73 -0
  57. package/es/table-component/header/TableHead.d.ts +14 -0
  58. package/es/table-component/header/TableHead.js +60 -0
  59. package/es/table-component/header/TableHeadCell.d.ts +14 -0
  60. package/es/table-component/header/TableHeadCell.js +343 -0
  61. package/es/table-component/header/TableHeadRow.d.ts +16 -0
  62. package/es/table-component/header/TableHeadRow.js +76 -0
  63. package/es/table-component/header/renderFilter.d.ts +20 -0
  64. package/es/table-component/header/renderFilter.js +281 -0
  65. package/es/table-component/hook/constant.d.ts +73 -0
  66. package/es/table-component/hook/constant.js +240 -0
  67. package/es/table-component/hook/useColumns.d.ts +9 -0
  68. package/es/table-component/hook/useColumns.js +169 -0
  69. package/es/table-component/hook/useFilterOperator.d.ts +7 -0
  70. package/es/table-component/hook/useFilterOperator.js +33 -0
  71. package/es/table-component/hook/utils.d.ts +133 -0
  72. package/es/table-component/hook/utils.js +1870 -0
  73. package/es/table-component/index.d.ts +5 -0
  74. package/es/table-component/index.js +2 -0
  75. package/es/table-component/style.scss +1129 -0
  76. package/es/table-component/table/Grid.d.ts +24 -0
  77. package/es/table-component/table/Grid.js +234 -0
  78. package/es/table-component/type.d.ts +513 -0
  79. package/es/table-component/type.js +1 -0
  80. package/es/table-component/useContext.d.ts +74 -0
  81. package/es/table-component/useContext.js +15 -0
  82. package/lib/index.d.ts +1 -0
  83. package/lib/index.js +8 -1
  84. package/lib/table-component/ColumnsChoose.d.ts +13 -0
  85. package/lib/table-component/ColumnsChoose.js +216 -0
  86. package/lib/table-component/ContextMenu.d.ts +20 -0
  87. package/lib/table-component/ContextMenu.js +85 -0
  88. package/lib/table-component/InternalTable.d.ts +9 -0
  89. package/lib/table-component/InternalTable.js +313 -0
  90. package/lib/table-component/TableContainer.d.ts +31 -0
  91. package/lib/table-component/TableContainer.js +257 -0
  92. package/lib/table-component/TableContainerEdit.d.ts +31 -0
  93. package/lib/table-component/TableContainerEdit.js +1310 -0
  94. package/lib/table-component/body/EditableCell.d.ts +16 -0
  95. package/lib/table-component/body/EditableCell.js +1041 -0
  96. package/lib/table-component/body/TableBody.d.ts +19 -0
  97. package/lib/table-component/body/TableBody.js +72 -0
  98. package/lib/table-component/body/TableBodyCell.d.ts +12 -0
  99. package/lib/table-component/body/TableBodyCell.js +158 -0
  100. package/lib/table-component/body/TableBodyCellEdit.d.ts +16 -0
  101. package/lib/table-component/body/TableBodyCellEdit.js +938 -0
  102. package/lib/table-component/body/TableBodyRow.d.ts +21 -0
  103. package/lib/table-component/body/TableBodyRow.js +158 -0
  104. package/lib/table-component/components/ControlCheckbox.d.ts +13 -0
  105. package/lib/table-component/components/ControlCheckbox.js +92 -0
  106. package/lib/table-component/components/EditForm/EditForm.d.ts +27 -0
  107. package/lib/table-component/components/EditForm/EditForm.js +406 -0
  108. package/lib/table-component/components/EditForm/index.d.ts +1 -0
  109. package/lib/table-component/components/EditForm/index.js +16 -0
  110. package/lib/table-component/components/InputControl/InputControl.d.ts +27 -0
  111. package/lib/table-component/components/InputControl/InputControl.js +131 -0
  112. package/lib/table-component/components/InputControl/index.d.ts +1 -0
  113. package/lib/table-component/components/InputControl/index.js +16 -0
  114. package/lib/table-component/components/async-select/index.d.ts +11 -0
  115. package/lib/table-component/components/async-select/index.js +49 -0
  116. package/lib/table-component/components/async-table-select/index.d.ts +11 -0
  117. package/lib/table-component/components/async-table-select/index.js +53 -0
  118. package/lib/table-component/components/checkbox-control/index.d.ts +13 -0
  119. package/lib/table-component/components/checkbox-control/index.js +48 -0
  120. package/lib/table-component/components/checkbox-filter/CheckboxFilter.d.ts +18 -0
  121. package/lib/table-component/components/checkbox-filter/CheckboxFilter.js +249 -0
  122. package/lib/table-component/components/checkbox-filter/FilterSearch.d.ts +12 -0
  123. package/lib/table-component/components/checkbox-filter/FilterSearch.js +44 -0
  124. package/lib/table-component/components/command/Command.d.ts +10 -0
  125. package/lib/table-component/components/command/Command.js +42 -0
  126. package/lib/table-component/components/number/index.d.ts +10 -0
  127. package/lib/table-component/components/number/index.js +50 -0
  128. package/lib/table-component/components/number-range/index.d.ts +11 -0
  129. package/lib/table-component/components/number-range/index.js +74 -0
  130. package/lib/table-component/features/operator.d.ts +24 -0
  131. package/lib/table-component/features/operator.js +67 -0
  132. package/lib/table-component/footer/TableFooter.d.ts +13 -0
  133. package/lib/table-component/footer/TableFooter.js +42 -0
  134. package/lib/table-component/footer/TableFooterCell.d.ts +10 -0
  135. package/lib/table-component/footer/TableFooterCell.js +76 -0
  136. package/lib/table-component/footer/TableFooterRow.d.ts +14 -0
  137. package/lib/table-component/footer/TableFooterRow.js +81 -0
  138. package/lib/table-component/header/TableHead.d.ts +14 -0
  139. package/lib/table-component/header/TableHead.js +69 -0
  140. package/lib/table-component/header/TableHeadCell.d.ts +14 -0
  141. package/lib/table-component/header/TableHeadCell.js +352 -0
  142. package/lib/table-component/header/TableHeadRow.d.ts +16 -0
  143. package/lib/table-component/header/TableHeadRow.js +84 -0
  144. package/lib/table-component/header/renderFilter.d.ts +20 -0
  145. package/lib/table-component/header/renderFilter.js +291 -0
  146. package/lib/table-component/hook/constant.d.ts +73 -0
  147. package/lib/table-component/hook/constant.js +247 -0
  148. package/lib/table-component/hook/useColumns.d.ts +9 -0
  149. package/lib/table-component/hook/useColumns.js +180 -0
  150. package/lib/table-component/hook/useFilterOperator.d.ts +7 -0
  151. package/lib/table-component/hook/useFilterOperator.js +40 -0
  152. package/lib/table-component/hook/utils.d.ts +133 -0
  153. package/lib/table-component/hook/utils.js +1969 -0
  154. package/lib/table-component/index.d.ts +5 -0
  155. package/lib/table-component/index.js +9 -0
  156. package/lib/table-component/style.scss +1129 -0
  157. package/lib/table-component/table/Grid.d.ts +24 -0
  158. package/lib/table-component/table/Grid.js +236 -0
  159. package/lib/table-component/type.d.ts +513 -0
  160. package/lib/table-component/type.js +5 -0
  161. package/lib/table-component/useContext.d.ts +74 -0
  162. package/lib/table-component/useContext.js +21 -0
  163. package/package.json +4 -2
@@ -0,0 +1,1301 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import React, { Fragment } from "react";
3
+ import TableBody from "./body/TableBody";
4
+ import TableHead from "./header/TableHead";
5
+ import { checkDecimalSeparator, checkThousandSeparator, detectSeparators, findItemByKey, flattenArray, flattenData, getAllRowKey, getColIdsBetween, getDefaultValue, getFormat, getRowIdsBetween, getSelectedCellMatrix, isEditable, isFormattedNumber, newGuid, sumSize, unFlattenData, updateArrayByKey, updateOrInsert } from "./hook/utils";
6
+ import { useVirtualizer } from "@tanstack/react-virtual";
7
+ import { useForm } from 'react-hook-form';
8
+ import { Button, Modal, Typography, Dropdown } from "antd";
9
+ import Pagination from "rc-master-ui/es/pagination";
10
+ import { numericFormatter, removeNumericFormat } from "react-numeric-component";
11
+ import { TableContext } from "./useContext";
12
+ import { yupResolver } from "@hookform/resolvers/yup";
13
+ import { Toolbar } from "rc-master-ui";
14
+ import classNames from "classnames";
15
+ import { Maximize, Minimize } from "becoxy-icons";
16
+ import { ColumnsChoose } from "./ColumnsChoose";
17
+ import TableFooter from "./footer/TableFooter";
18
+ const {
19
+ Paragraph,
20
+ Title
21
+ } = Typography;
22
+ const validateData = async (data, formSchema) => {
23
+ if (!formSchema) {
24
+ return [];
25
+ } else {
26
+ const errors = [];
27
+ for (let i = 0; i < data.length; i++) {
28
+ try {
29
+ await formSchema.validate(data[i], {
30
+ abortEarly: false
31
+ });
32
+ } catch (error) {
33
+ errors.push(error.inner.reduce((acc, err) => {
34
+ acc[err.path] = {
35
+ field: err.path,
36
+ index: i,
37
+ message: err.message,
38
+ type: err.type,
39
+ ref: {
40
+ name: err.path
41
+ }
42
+ };
43
+ return {
44
+ ...acc,
45
+ index: i,
46
+ id: data[i].rowId
47
+ };
48
+ }, {}));
49
+ }
50
+ }
51
+ return errors;
52
+ }
53
+ };
54
+ const TableContainerEdit = props => {
55
+ const {
56
+ t,
57
+ table,
58
+ id,
59
+ prefix,
60
+ commandClick,
61
+ editAble,
62
+ rowKey,
63
+ format,
64
+ dataSource,
65
+ originData,
66
+ expandable,
67
+ wrapSettings,
68
+ recordDoubleClick,
69
+ // triggerFilter,
70
+ selectionSettings,
71
+ setIsSelectionChange,
72
+ onContextMenu,
73
+ contextMenuItems,
74
+ setSorterChange,
75
+ setFilterChange,
76
+ // tableHeight,
77
+ onCellPaste,
78
+ // triggerPaste,
79
+ validate,
80
+ // triggerChangeData,
81
+ onCellChange,
82
+ onDataChange,
83
+ defaultValue,
84
+ toolbarItems,
85
+ mergedFilterKeys,
86
+ setMergedFilterKeys,
87
+ expanded,
88
+ setExpanded,
89
+ onBlur,
90
+ fullScreen,
91
+ pagination,
92
+ showToolbar,
93
+ actionTemplate,
94
+ showColumnChoose,
95
+ height,
96
+ summary,
97
+ locale,
98
+ groupColumns,
99
+ columns,
100
+ propsColumns,
101
+ triggerChangeColumns,
102
+ columnHidden
103
+ } = props;
104
+ const containerRef = React.useRef(null);
105
+ const bottomToolbarRef = React.useRef(null);
106
+ const topToolbarRef = React.useRef(null);
107
+ const childrenColumnName = 'children';
108
+
109
+ // const visibleColumns = table.getVisibleLeafColumns()
110
+
111
+ // //The virtualizers need to know the scrollable container element
112
+ const tableContainerRef = React.useRef(null);
113
+ const visibleColumns = table.getVisibleLeafColumns();
114
+ const fixedLeftColumns = table.getState().columnPinning.left ? visibleColumns.filter(vc => table.getState().columnPinning.left?.includes(vc.id)) : [];
115
+ const fixedRightColumns = table.getState().columnPinning.right ? visibleColumns.filter(vc => table.getState().columnPinning.right?.includes(vc.id)) : [];
116
+
117
+ //we are using a slightly different virtualization strategy for columns (compared to virtual rows) in order to support dynamic row heights
118
+ const columnVirtualizer = useVirtualizer({
119
+ count: visibleColumns.length,
120
+ estimateSize: index => visibleColumns[index].getSize(),
121
+ //estimate width of each column for accurate scrollbar dragging
122
+ getScrollElement: () => tableContainerRef.current,
123
+ horizontal: true,
124
+ // measureElement(element) {
125
+
126
+ // return element?.getBoundingClientRect().width;
127
+ // },
128
+
129
+ measureElement: typeof window !== 'undefined' && navigator.userAgent.indexOf('Firefox') === -1 ? element => element?.getBoundingClientRect().height : undefined,
130
+ overscan: 1 //how many columns to render on each side off screen each way (adjust this for performance)
131
+ });
132
+ const columnSizingState = table.getState().columnSizing;
133
+ const itemsAdd = React.useMemo(() => {
134
+ return [{
135
+ key: '10',
136
+ label: `10 ${t ? t('rows') : 'rows'}`
137
+ }, {
138
+ key: '50',
139
+ label: `50 ${t ? t('rows') : 'rows'}`
140
+ }, {
141
+ key: '100',
142
+ label: `100 ${t ? t('rows') : 'rows'}`
143
+ }];
144
+ }, [t]);
145
+ const [dataErrors, setDataErrors] = React.useState([]);
146
+ React.useEffect(() => {
147
+ requestAnimationFrame(() => {
148
+ columnVirtualizer.measure();
149
+ });
150
+ }, [columnSizingState, columnVirtualizer]);
151
+ React.useEffect(() => {
152
+ if (validate && dataSource && dataSource.length) {
153
+ validateData(dataSource, validate).then(error => {
154
+ setDataErrors([...error]);
155
+ // if (getErrors) {
156
+ // getErrors([...error])
157
+ // }
158
+ });
159
+ }
160
+ }, [validate, dataSource]);
161
+ const virtualColumns = columnVirtualizer.getVirtualItems();
162
+ const cacheColumns = columnVirtualizer.measurementsCache;
163
+ const rightCols = table.getState().columnPinning.right?.length ? [...cacheColumns].slice(-(table.getState().columnPinning.right?.length ?? 0)) : [];
164
+ const leftCols = [...cacheColumns].slice(0, table.getState().columnPinning.left?.length ?? 0);
165
+ const rightWidth = sumSize(rightCols);
166
+ const leftWidth = sumSize(leftCols);
167
+
168
+ //different virtualization strategy for columns - instead of absolute and translateY, we add empty columns to the left and right
169
+ let virtualPaddingLeft;
170
+ let virtualPaddingRight;
171
+ const pdRight = columnVirtualizer.getTotalSize() - (virtualColumns[virtualColumns.length - 1]?.end ?? 0);
172
+ if (columnVirtualizer && virtualColumns?.length) {
173
+ virtualPaddingLeft = fixedLeftColumns && fixedLeftColumns.length > 0 ? (virtualColumns[0]?.start ?? 0) - leftWidth > 0 ? (virtualColumns[0]?.start ?? 0) - leftWidth : 0 : virtualColumns[0]?.start ?? 0;
174
+
175
+ // virtualPaddingLeft = leftCols.length === rss.length ? (virtualColumns[0]?.start ?? 0) : 0;
176
+ // columnVirtualizer.getTotalSize() - (virtualColumns[virtualColumns.length - 1]?.end ?? 0) - rightWidth > 0 ? columnVirtualizer.getTotalSize() - (virtualColumns[virtualColumns.length - 1]?.end ?? 0) - rightWidth : 0;
177
+ virtualPaddingRight = fixedRightColumns && fixedRightColumns.length > 0 ? pdRight - rightWidth > 0 ? pdRight - rightWidth : 0 : pdRight;
178
+ // virtualPaddingRight = columnVirtualizer.getTotalSize() - (virtualColumns[virtualColumns.length - 1]?.end ?? 0)
179
+ }
180
+ const [editingKey, setEditingKey] = React.useState('');
181
+ const [rangeState, setRangeState] = React.useState({
182
+ startRowIndex: undefined,
183
+ endRowIndex: undefined,
184
+ startColIndex: undefined,
185
+ endColIndex: undefined,
186
+ rowIds: [],
187
+ colIds: [],
188
+ colRange: [],
189
+ rowRange: []
190
+ });
191
+ const [rangePasteState, setRangePasteState] = React.useState({
192
+ startRowIndex: undefined,
193
+ endRowIndex: undefined,
194
+ startColIndex: undefined,
195
+ endColIndex: undefined,
196
+ rowIds: [],
197
+ colIds: [],
198
+ colRange: [],
199
+ rowRange: []
200
+ });
201
+ const [focusedCell, setFocusedCell] = React.useState(undefined);
202
+ const [startCell, setStartCell] = React.useState(undefined);
203
+ const [endCell, setEndCell] = React.useState(undefined);
204
+ const [startPasteCell, setStartPasteCell] = React.useState(undefined);
205
+ const [endPasteCell, setEndPasteCell] = React.useState(undefined);
206
+ const [isSelecting, setIsSelecting] = React.useState(false);
207
+ const [isPasting, setIsPasting] = React.useState(false);
208
+ const [isFullScreen] = React.useState(false);
209
+ const [tableHeight, settableHeight] = React.useState(0);
210
+ const rowsFocus = React.useMemo(() => {
211
+ return startCell && endCell ? getRowIdsBetween(table, startCell.rowId, endCell.rowId) : [];
212
+ }, [endCell, startCell, table]);
213
+ const copySelectionToClipboard = React.useCallback(() => {
214
+ if (!startCell || !endCell) return;
215
+
216
+ // const allRows = table.getRowModel().rows;
217
+ const allRows = table.getRowModel().flatRows;
218
+ // const allColumns = table.getAllLeafColumns();
219
+
220
+ const rowIds = getRowIdsBetween(table, startCell.rowId, endCell.rowId);
221
+ const colIds = getColIdsBetween(table, startCell.colId, endCell.colId);
222
+ const dataToCopy = [];
223
+ rowIds.forEach(rowId => {
224
+ const row = allRows.find(r => r.id === rowId);
225
+ if (!row) return;
226
+ const rowData = [];
227
+ colIds.forEach(colId => {
228
+ const cellll = row.getVisibleCells().find(c => c.column.id === colId);
229
+ const value = cellll?.getValue();
230
+ rowData.push(value !== undefined ? String(value) : '');
231
+ });
232
+ dataToCopy.push(rowData);
233
+ });
234
+
235
+ // Convert to TSV string
236
+ const tsv = dataToCopy.map(row => row.join('\t')).join('\n');
237
+
238
+ // Copy to clipboard
239
+ navigator.clipboard.writeText(tsv).then(() => {});
240
+ }, [startCell, endCell, table]);
241
+ const triggerChangeData = React.useCallback(newData => {
242
+ onDataChange?.(newData);
243
+ }, [onDataChange]);
244
+ const triggerPaste = React.useCallback((pastedRows, pastedColumnsArray, newData, copyRows) => {
245
+ const handlePasteCallback = callbackData => {
246
+ const rsFilterData = updateOrInsert(flattenArray([...dataSource]), callbackData);
247
+ const rs = unFlattenData(rsFilterData);
248
+ triggerChangeData(rs);
249
+ };
250
+ if (onCellPaste && onCellPaste.onPasted) {
251
+ if (onCellPaste.onPasted.length > 1) {
252
+ // có callback
253
+ onCellPaste.onPasted({
254
+ pasteData: pastedRows,
255
+ copyRows,
256
+ type: 'onPaste',
257
+ data: dataSource,
258
+ pastedColumns: pastedColumnsArray
259
+ }, handlePasteCallback);
260
+ } else {
261
+ // không có callback
262
+ onCellPaste.onPasted({
263
+ pasteData: pastedRows,
264
+ type: 'onPaste',
265
+ copyRows,
266
+ data: dataSource,
267
+ pastedColumns: pastedColumnsArray
268
+ }, handlePasteCallback);
269
+ triggerChangeData(newData);
270
+ }
271
+ } else {
272
+ triggerChangeData(newData);
273
+ }
274
+ }, [dataSource, onCellPaste, triggerChangeData]);
275
+ const handlePasted = React.useCallback(pasteData => {
276
+ if (!startCell) {
277
+ return;
278
+ }
279
+ const rows = pasteData.slice(0, onCellPaste?.maxRowsPaste ?? 200);
280
+
281
+ // const allRows = table.getRowModel().rows;
282
+ const allRows = table.getRowModel().flatRows;
283
+ const allCols = table.getVisibleLeafColumns();
284
+ const startRowIdx = allRows.findIndex(r => r.id === startCell.rowId);
285
+ const startColIdx = allCols.findIndex(c => c.id === startCell.colId);
286
+
287
+ // const record: any = allRows[startRowIdx].original
288
+
289
+ const record = table.getRow(startCell.rowId).original;
290
+ const row = table.getRow(startCell.rowId);
291
+ if (!row.parentId) {
292
+ // Cập nhật data mới
293
+ const newData = flattenArray([...dataSource]);
294
+
295
+ // Lấy vị trí bắt đầu
296
+
297
+ // const startRow = newData.findIndex((it) => it[rowKey as any] === record[rowKey])
298
+ const startRow = startRowIdx;
299
+ const startCol = startColIdx;
300
+ const pastedRows = [];
301
+ const pastedColumns = new Set();
302
+ rows.forEach((rowValues, rowIndex) => {
303
+ const targetRow = startRow + rowIndex;
304
+
305
+ // Nếu vượt quá số dòng hiện có, thêm dòng mới
306
+ if (targetRow >= newData.length) {
307
+ newData.push({
308
+ id: undefined,
309
+ rowId: newGuid()
310
+ });
311
+ }
312
+ rowValues.forEach((cellValue, colIndex) => {
313
+ const targetCol = startCol + colIndex;
314
+ if (targetCol >= allCols.length) {
315
+ // Không vượt quá số cột
316
+ return;
317
+ }
318
+ const columnTarget = allCols[targetCol];
319
+ const columnOri = columnTarget.columnDef.meta ?? {};
320
+ const isEdit = typeof columnOri?.editEnable === 'function' ? columnOri.editEnable(newData[targetRow]) : columnOri.editEnable;
321
+ if (isEdit) {
322
+ const columnKey = allCols[targetCol].id;
323
+ if (columnOri.type === 'number' && isFormattedNumber(cellValue.trim())) {
324
+ const colFormat = typeof columnOri.format === 'function' ? columnOri.format(record) : columnOri.format;
325
+ const valuePasteFormat = detectSeparators(cellValue.trim());
326
+ const cellFormat = getFormat(colFormat, format);
327
+ const thousandSeparator = valuePasteFormat?.thousandSeparator ?? cellFormat?.thousandSeparator;
328
+ const decimalSeparator = valuePasteFormat?.decimalSeparator ?? cellFormat?.decimalSeparator;
329
+ const dec = cellFormat?.decimalScale;
330
+ const numericFormatProps = {
331
+ thousandSeparator: checkThousandSeparator(thousandSeparator, decimalSeparator),
332
+ decimalSeparator: checkDecimalSeparator(thousandSeparator, decimalSeparator),
333
+ allowNegative: cellFormat?.allowNegative ?? true,
334
+ prefix: cellFormat?.prefix,
335
+ suffix: cellFormat?.suffix,
336
+ decimalScale: dec,
337
+ fixedDecimalScale: cellFormat?.fixedDecimalScale ?? false
338
+ };
339
+ const val = removeNumericFormat(cellValue.trim(), undefined, numericFormatProps);
340
+ newData[targetRow] = {
341
+ ...newData[targetRow],
342
+ [columnKey]: Number(val)
343
+ };
344
+ } else {
345
+ newData[targetRow] = {
346
+ ...newData[targetRow],
347
+ [columnKey]: cellValue.trim()
348
+ };
349
+ }
350
+ pastedColumns.add(columnKey);
351
+ }
352
+ });
353
+
354
+ // Lưu dòng được paste
355
+ pastedRows.push(newData[targetRow]);
356
+ });
357
+ const pastedColumnsArray = Array.from(pastedColumns) ?? [];
358
+ const rsFilterData = updateOrInsert(flattenArray([...originData]), newData);
359
+ const rs = unFlattenData(rsFilterData);
360
+ triggerPaste?.(pastedRows, pastedColumnsArray, rs, []);
361
+ } else {
362
+ // const parent = findItemByKey(dataSource, rowKey as any, record.parentId)
363
+ const parent = row.getParentRow()?.original;
364
+
365
+ // Cập nhật childData mới
366
+ const childData = parent?.children ? [...parent.children] : [];
367
+
368
+ // Lấy vị trí bắt đầu
369
+ // const { row: startRow, col: startCol } = selectedCell;
370
+ const startRow = childData.findIndex(it => it[rowKey] === record[rowKey]);
371
+ const startCol = startColIdx;
372
+ const pastedRows = [];
373
+ const pastedColumns = new Set();
374
+ rows.forEach((rowValues, rowIndex) => {
375
+ const targetRow = startRow + rowIndex;
376
+
377
+ // Nếu vượt quá số dòng hiện có, thêm dòng mới
378
+ if (targetRow >= childData.length) {
379
+ childData.push({
380
+ id: undefined,
381
+ rowId: newGuid(),
382
+ parentId: parent[rowKey ?? 'id']
383
+ });
384
+ }
385
+ rowValues.forEach((cellValue, colIndex) => {
386
+ const targetCol = startCol + colIndex;
387
+ if (targetCol >= allCols.length) {
388
+ // Không vượt quá số cột
389
+ return;
390
+ }
391
+ const columnTarget = allCols[targetCol];
392
+
393
+ // const isEdit = typeof columnTarget.editEnable === 'function' ? columnTarget.editEnable(childData[targetRow]) : columnTarget.editEnable
394
+
395
+ const columnOri = columnTarget.columnDef.meta ?? {};
396
+ const isEdit = typeof columnOri?.editEnable === 'function' ? columnOri.editEnable(childData[targetRow]) : columnOri.editEnable;
397
+ if (isEdit) {
398
+ const columnKey = allCols[targetCol].id;
399
+ childData[targetRow] = {
400
+ ...childData[targetRow],
401
+ [columnKey]: cellValue.trim()
402
+ };
403
+ pastedColumns.add(columnKey);
404
+ }
405
+ });
406
+
407
+ // Lưu dòng được paste
408
+ pastedRows.push(childData[targetRow]);
409
+ });
410
+ const pastedColumnsArray = Array.from(pastedColumns) ?? [];
411
+ const newRowData = {
412
+ ...parent,
413
+ children: childData
414
+ }; // item đã được filter
415
+
416
+ const newDataSource = updateArrayByKey(originData, newRowData, rowKey);
417
+ triggerPaste?.(pastedRows, pastedColumnsArray, newDataSource, []);
418
+ }
419
+ }, [dataSource, format, onCellPaste?.maxRowsPaste, originData, rowKey, startCell, table, triggerPaste]);
420
+ const handlePasteToTable = React.useCallback(pasteData => {
421
+ if (!startCell) return;
422
+
423
+ // const pastedRows = pasted.trim().split('\n').map(row => row.split('\t'));
424
+
425
+ // Chuyển đổi dữ liệu từ clipboard thành mảng
426
+ const rowsPasted = pasteData.split("\n").filter(row => row !== '').map(row =>
427
+ // const rows = pasteData.split("\n").map((row: any) =>
428
+ row.replace(/\r/g, "").split("\t"));
429
+ if (rowsPasted.length > (onCellPaste?.maxRowsPaste ?? 200)) {
430
+ // bật popup thông báo
431
+
432
+ Modal.confirm({
433
+ content: /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Paragraph, {
434
+ style: {
435
+ marginBottom: '.25rem',
436
+ fontSize: 14
437
+ }
438
+ }, "D\u1EEF li\u1EC7u sao ch\xE9p v\u01B0\u1EE3t qu\xE1 s\u1ED1 d\xF2ng cho ph\xE9p (500 d\xF2ng).Ph\u1EA7n m\u1EC1n s\u1EBD ch\u1EC9 l\u1EA5y 500 d\xF2ng \u0111\u1EA7u ti\xEAn."), /*#__PURE__*/React.createElement(Title, {
439
+ level: 5,
440
+ style: {
441
+ marginTop: '.75rem'
442
+ }
443
+ }, "B\u1EA1n c\xF3 mu\u1ED1n ti\u1EBFp t\u1EE5c sao ch\xE9p kh\xF4ng?")),
444
+ centered: true,
445
+ className: 'be-popup-container',
446
+ onOk: () => {
447
+ handlePasted(rowsPasted);
448
+ }
449
+ // footer: (_, { OkBtn, CancelBtn }) => (
450
+ // <>
451
+ // <OkBtn />
452
+ // <CancelBtn />
453
+ // </>
454
+ // ),
455
+ });
456
+ } else {
457
+ handlePasted(rowsPasted);
458
+ }
459
+ }, [handlePasted, onCellPaste?.maxRowsPaste, startCell]);
460
+ React.useEffect(() => {
461
+ const handleKeyDown = e => {
462
+ if (e.ctrlKey && e.key === 'c' && startCell && endCell) {
463
+ e.preventDefault();
464
+ copySelectionToClipboard();
465
+ }
466
+ };
467
+ window.addEventListener('keydown', handleKeyDown);
468
+ return () => window.removeEventListener('keydown', handleKeyDown);
469
+ }, [startCell, endCell, table, copySelectionToClipboard]);
470
+ React.useEffect(() => {
471
+ const handlePaste = e => {
472
+ if (startCell) {
473
+ e.preventDefault(); // Chặn hành vi mặc định
474
+ const clipboardText = e.clipboardData?.getData('text/plain') ?? '';
475
+ handlePasteToTable(clipboardText);
476
+ }
477
+ };
478
+ window.addEventListener('paste', handlePaste);
479
+ return () => window.removeEventListener('paste', handlePaste);
480
+ }, [startCell, endCell, table, handlePasteToTable]);
481
+ React.useEffect(() => {
482
+ const handleClickOutside = event => {
483
+ const element = event.target;
484
+ const container = document.querySelector(".be-popup-container");
485
+ const containerContextMenu = document.querySelector(".popup-context-menu");
486
+ const tableBody = document.querySelector(`#${id} .ui-rc-grid-tbody`);
487
+ const itemContainer = document.querySelector(`#${id} .ui-rc-toolbar-selection-overflow-item`);
488
+ const itemHeader = document.querySelector(`#${id} .ui-rc-table-thead`);
489
+ const isInsideContainer = element.closest(".be-popup-container") && container;
490
+ const isInsideContainerContext = containerContextMenu && element.closest(".popup-context-menu");
491
+ const isInsideToolbar = element.closest(`.ui-rc-toolbar-selection-overflow-item`) && itemContainer;
492
+ const isInsideHeader = itemHeader && itemHeader.contains(event.target);
493
+ if (isInsideContainer || isInsideToolbar || isInsideHeader || isInsideContainerContext) {
494
+ return;
495
+ }
496
+ if (containerRef.current && tableBody && !tableBody.contains(event.target)) {
497
+ if (editingKey) {
498
+ onBlur?.(dataSource);
499
+ }
500
+ setTimeout(() => {
501
+ setEditingKey('');
502
+ // editingKey.current = ''
503
+ });
504
+ setEndCell(undefined);
505
+ setStartCell(undefined);
506
+ setRangeState(undefined);
507
+ }
508
+ };
509
+
510
+ // document.addEventListener('click', handleClickOutside)
511
+ document.addEventListener('mousedown', handleClickOutside);
512
+ // document.addEventListener('touchstart', handleClickOutside)
513
+
514
+ return () => {
515
+ // document.removeEventListener('click', handleClickOutside)
516
+ document.removeEventListener('mousedown', handleClickOutside);
517
+ // document.removeEventListener('touchstart', handleClickOutside)
518
+ };
519
+ }, [dataSource, editingKey, id, onBlur]);
520
+ React.useEffect(() => {
521
+ const totalHeight = height;
522
+ if (totalHeight && topToolbarRef.current && bottomToolbarRef.current) {
523
+ settableHeight(totalHeight - topToolbarRef.current.offsetHeight - bottomToolbarRef.current.offsetHeight);
524
+ }
525
+ }, [id, height, editAble]);
526
+ const {
527
+ control,
528
+ handleSubmit,
529
+ setValue,
530
+ // trigger,
531
+ getValues,
532
+ reset,
533
+ formState: {
534
+ errors
535
+ }
536
+ } = useForm({
537
+ mode: 'onChange',
538
+ resolver: validate ? yupResolver(validate) : undefined
539
+ });
540
+ const onSubmit = formData => {
541
+ try {
542
+ // const record = (await form.validateFields()) as RecordType;
543
+ const row = {
544
+ ...formData
545
+ };
546
+
547
+ // const newData = [...dataSource]
548
+ const newData = [...originData];
549
+
550
+ // @ts-ignore
551
+ const index = flattenData(childrenColumnName, newData).findIndex(item => formData[rowKey] === item[rowKey]);
552
+ const rs = updateArrayByKey(newData, row, rowKey);
553
+ if (index > -1) {
554
+ triggerChangeData?.(rs);
555
+ }
556
+ } catch (errInfo) {
557
+ console.log('Validate Failed:', errInfo);
558
+ }
559
+ };
560
+ const handleCellChange = args => {
561
+ const {
562
+ record,
563
+ type: changeType,
564
+ newState,
565
+ prevState,
566
+ option,
567
+ field,
568
+ indexCol,
569
+ indexRow,
570
+ key
571
+ } = args;
572
+ if (changeType === 'blur') {
573
+ const handleChangeCallback = callbackData => {
574
+ const callbackRecord = callbackData;
575
+ Object.entries(callbackRecord).forEach(([name, value]) => {
576
+ setValue(name, value);
577
+ });
578
+ onSubmit(callbackRecord);
579
+ };
580
+ if (onCellChange) {
581
+ if (onCellChange.length > 1) {
582
+ onCellChange({
583
+ field,
584
+ indexCol,
585
+ type: 'onChange',
586
+ value: newState,
587
+ option,
588
+ indexRow,
589
+ rowData: record,
590
+ rowId: key,
591
+ // rowsData: [...dataSource],
592
+ rowsData: [...originData],
593
+ sumValue: []
594
+ }, handleChangeCallback);
595
+ } else {
596
+ onCellChange({
597
+ field,
598
+ indexCol,
599
+ type: 'onChange',
600
+ option,
601
+ value: newState,
602
+ indexRow,
603
+ rowData: record,
604
+ rowId: key,
605
+ // rowsData: [...dataSource],
606
+ rowsData: [...originData],
607
+ sumValue: []
608
+ }, handleChangeCallback);
609
+ onSubmit(record);
610
+ }
611
+ }
612
+ }
613
+ if (prevState && newState && prevState !== newState && changeType === 'enter') {
614
+ onSubmit(record);
615
+ }
616
+ };
617
+ const handleAddMulti = React.useCallback((item, n, newId) => {
618
+ if (item.onClick) {
619
+ item.onClick({
620
+ toolbar: item
621
+ });
622
+ } else {
623
+ const defaultRowValue = getDefaultValue(defaultValue);
624
+ const newRows = Array.from({
625
+ length: n
626
+ }).map(() => defaultRowValue ? {
627
+ ...defaultRowValue,
628
+ id: undefined,
629
+ rowId: n === 1 && newId ? newId : newGuid()
630
+ } : {
631
+ id: undefined,
632
+ rowId: n === 1 && newId ? newId : newGuid()
633
+ });
634
+ const kkk = getAllRowKey(newRows) ?? [];
635
+ const rs = mergedFilterKeys ? [...mergedFilterKeys, ...kkk] : [...kkk];
636
+ setMergedFilterKeys?.(rs);
637
+ const newData = dataSource.concat(newRows);
638
+ triggerChangeData?.(newData);
639
+ }
640
+ }, [dataSource, defaultValue, mergedFilterKeys, setMergedFilterKeys, triggerChangeData]);
641
+ const handleDuplicate = React.useCallback(() => {
642
+ // không tính tree
643
+
644
+ // Cập nhật data mới
645
+ const newData = flattenArray([...dataSource]);
646
+
647
+ // const duplicatedItems = rowsFocus.map(index => ({ ...newData[index], rowId: newGuid(), id: undefined, isDuplicate: true }))
648
+
649
+ const duplicatedItem = table.getRowModel().flatRows.find(it => it.id === focusedCell?.rowId);
650
+ setStartCell(focusedCell);
651
+ setEndCell(focusedCell);
652
+ setRangeState(getSelectedCellMatrix(table, focusedCell, focusedCell));
653
+ const duplicatedItems = [{
654
+ ...duplicatedItem?.original,
655
+ rowId: newGuid(),
656
+ id: undefined,
657
+ isDuplicate: true
658
+ }];
659
+
660
+ // Vị trí chèn là ngay sau phần tử lớn nhất trong rowsFocus
661
+
662
+ // const insertAfter = Math.max(...rowsFocus)
663
+ const insertAfter = newData.findIndex(it => it[rowKey] === focusedCell?.rowId);
664
+ const rsFilter = [...newData.slice(0, insertAfter + 1), ...duplicatedItems, ...newData.slice(insertAfter + 1)];
665
+
666
+ // const rs = updateOrInsertInOrder(originData, rsFilter)
667
+ const rs = updateOrInsert(originData, rsFilter);
668
+ // const rs2 = mergeWithFilter(originData, rsFilter)
669
+
670
+ triggerChangeData?.(rs);
671
+ }, [dataSource, focusedCell, originData, rowKey, table, triggerChangeData]);
672
+
673
+ // thêm n dòng bên trên
674
+ const handleInsertBefore = React.useCallback((item, n) => {
675
+ const defaultRowValue = getDefaultValue(defaultValue);
676
+
677
+ // const record: any = table.getRowModel().rows.find((it) => it.id === rowsFocus[rowsFocus.length - 1])?.original
678
+ const record = table.getRowModel().flatRows.find(it => it.id === rowsFocus[rowsFocus.length - 1])?.original;
679
+ if (item.onClick) {
680
+ item.onClick({
681
+ toolbar: item
682
+ });
683
+ } else {
684
+ if (!record?.parentId) {
685
+ // Cập nhật data mới
686
+
687
+ const newData = [...originData];
688
+ const newRows = Array.from({
689
+ length: n
690
+ }).map(() => defaultRowValue ? {
691
+ ...defaultRowValue,
692
+ id: undefined,
693
+ rowId: newGuid()
694
+ } : {
695
+ id: undefined,
696
+ rowId: newGuid()
697
+ });
698
+ const kkk = getAllRowKey(newRows) ?? [];
699
+ const rs = mergedFilterKeys ? [...mergedFilterKeys, ...kkk] : [...kkk];
700
+ setMergedFilterKeys?.(rs);
701
+ const index = newData.findIndex(obj => obj[rowKey] === record[rowKey]);
702
+ newData.splice(index, 0, ...newRows);
703
+ triggerChangeData?.(newData);
704
+ } else {
705
+ const newData = [...originData];
706
+ const parent = findItemByKey(newData, rowKey, record.parentId);
707
+ const newRows = Array.from({
708
+ length: n
709
+ }).map(() => defaultRowValue ? {
710
+ ...defaultRowValue,
711
+ id: undefined,
712
+ rowId: newGuid(),
713
+ parentId: parent.rowId
714
+ } : {
715
+ id: undefined,
716
+ rowId: newGuid(),
717
+ parentId: parent.rowId
718
+ });
719
+
720
+ // Cập nhật childData mới
721
+ const childData = parent?.children ? [...parent.children] : [];
722
+ const index = childData.findIndex(obj => obj[rowKey] === record[rowKey]);
723
+ childData.splice(index, 0, ...newRows);
724
+ const newRowData = {
725
+ ...parent,
726
+ children: childData
727
+ };
728
+ const newDataSource = updateArrayByKey(newData, newRowData, rowKey);
729
+ triggerChangeData?.(newDataSource);
730
+ }
731
+ }
732
+ }, [defaultValue, mergedFilterKeys, originData, rowKey, rowsFocus, setMergedFilterKeys, table, triggerChangeData]);
733
+
734
+ //thêm 1 dòng bên dưới
735
+ const handleInsertAfter = React.useCallback((item, n) => {
736
+ const defaultRowValue = getDefaultValue(defaultValue);
737
+
738
+ // const insertAfter = Math.max(...rowsFocus)
739
+
740
+ // const record: RecordType = flattenData(childrenColumnName, dataSource)[insertAfter]
741
+
742
+ // const record: any = table.getRowModel().rows.find((it) => it.id === focusedCell?.rowId)?.original
743
+ const record = table.getRowModel().flatRows.find(it => it.id === focusedCell?.rowId)?.original;
744
+ if (item.onClick) {
745
+ item.onClick({
746
+ toolbar: item
747
+ });
748
+ } else {
749
+ if (!record?.parentId) {
750
+ // Cập nhật data mới
751
+ const newData = [...originData];
752
+ const newRows = Array.from({
753
+ length: n
754
+ }).map(() => defaultRowValue ? {
755
+ ...defaultRowValue,
756
+ id: undefined,
757
+ rowId: newGuid()
758
+ } : {
759
+ id: undefined,
760
+ rowId: newGuid()
761
+ });
762
+ const kkk = getAllRowKey(newRows) ?? [];
763
+ const rs = mergedFilterKeys ? [...mergedFilterKeys, ...kkk] : [...kkk];
764
+ setMergedFilterKeys?.(rs);
765
+ const index = newData.findIndex(obj => obj[rowKey] === record[rowKey]);
766
+ newData.splice(index + 1, 0, ...newRows);
767
+ triggerChangeData?.(newData);
768
+ } else {
769
+ const newData = [...originData];
770
+ const parent = findItemByKey(newData, rowKey, record.parentId);
771
+ const newRows = Array.from({
772
+ length: n
773
+ }).map(() => defaultRowValue ? {
774
+ ...defaultRowValue,
775
+ id: undefined,
776
+ rowId: newGuid(),
777
+ parentId: parent.rowId
778
+ } : {
779
+ id: undefined,
780
+ rowId: newGuid(),
781
+ parentId: parent.rowId
782
+ });
783
+ const kkk = getAllRowKey(newRows) ?? [];
784
+ const rs = mergedFilterKeys ? [...mergedFilterKeys, ...kkk] : [...kkk];
785
+ setMergedFilterKeys?.(rs);
786
+
787
+ // Cập nhật childData mới
788
+ const childData = parent?.children ? [...parent.children] : [];
789
+ const index = childData.findIndex(obj => obj[rowKey] === record[rowKey]);
790
+ childData.splice(index + 1, 0, ...newRows);
791
+ const newRowData = {
792
+ ...parent,
793
+ children: childData
794
+ };
795
+ const newDataSource = updateArrayByKey(newData, newRowData, rowKey);
796
+ triggerChangeData?.(newDataSource);
797
+ }
798
+ }
799
+ }, [defaultValue, table, focusedCell?.rowId, originData, mergedFilterKeys, setMergedFilterKeys, triggerChangeData, rowKey]);
800
+ const handleInsertChild = React.useCallback(item => {
801
+ const defaultRowValue = getDefaultValue(defaultValue);
802
+ const rowId = newGuid();
803
+ const record = table.getRowModel().rows.find(it => it.id === focusedCell?.rowId)?.original;
804
+ if (item.onClick) {
805
+ item.onClick({
806
+ toolbar: item
807
+ });
808
+ } else {
809
+ // const newData = [...dataSource]
810
+ const newData = [...originData];
811
+ let newElement;
812
+ if (!record.children || record.children.length === 0) {
813
+ newElement = {
814
+ ...record,
815
+ children: [{
816
+ ...defaultRowValue,
817
+ parentId: record.rowId,
818
+ rowId
819
+ }]
820
+ };
821
+ } else {
822
+ newElement = {
823
+ ...record,
824
+ children: [...record.children, {
825
+ ...defaultRowValue,
826
+ parentId: record.rowId,
827
+ rowId
828
+ }]
829
+ };
830
+ }
831
+ const rs = mergedFilterKeys ? [...mergedFilterKeys, rowId] : [rowId];
832
+ setMergedFilterKeys?.(rs);
833
+ const newDataSource = updateArrayByKey(newData, newElement, rowKey);
834
+ triggerChangeData?.(newDataSource);
835
+ }
836
+ setTimeout(() => {
837
+ const row = table.getRowModel().rows.find(it => it.id === focusedCell?.rowId);
838
+ if (row) {
839
+ setExpanded(old => ({
840
+ ...old,
841
+ [row.id]: true
842
+ }));
843
+ }
844
+ }, 10);
845
+
846
+ // const hasKey = mergedExpandedKeys.has(key)
847
+ // if (!hasKey) {
848
+ // const newExpandedKeys = [...mergedExpandedKeys, key]
849
+ // setInnerExpandedKeys(newExpandedKeys)
850
+ // }
851
+ }, [defaultValue, focusedCell?.rowId, mergedFilterKeys, originData, rowKey, setExpanded, setMergedFilterKeys, table, triggerChangeData]);
852
+ const handleDeleteRows = React.useCallback(item => {
853
+ if (item.onClick) {
854
+ item.onClick({
855
+ toolbar: item
856
+ });
857
+ } else {
858
+ const filterData = flattenArray([...originData]);
859
+ const rs = filterData.filter(it => !rowsFocus.includes(it[rowKey]));
860
+ const newDaa = unFlattenData(rs);
861
+ triggerChangeData?.([...newDaa]);
862
+ }
863
+ }, [originData, rowKey, rowsFocus, triggerChangeData]);
864
+ const handleDeleteAll = React.useCallback(() => {
865
+ triggerChangeData?.([]);
866
+ }, [triggerChangeData]);
867
+ const handleDeleteContent = React.useCallback(() => {
868
+ if (startCell && endCell) {
869
+ const tmpData = flattenArray([...dataSource]);
870
+ const rs = tmpData.map(row => {
871
+ if (!rangeState?.rowRange.includes(row.rowId)) {
872
+ return row;
873
+ }
874
+ const updatedRow = {
875
+ ...row
876
+ };
877
+ for (const colId of rangeState.colRange) {
878
+ const column = table.getVisibleFlatColumns().find(it => it.id === colId)?.columnDef.meta;
879
+ if (isEditable(column, row)) {
880
+ updatedRow[colId] = '';
881
+ }
882
+ }
883
+ return updatedRow;
884
+ });
885
+ const newData = unFlattenData(rs);
886
+ triggerChangeData?.([...newData]);
887
+ }
888
+ }, [dataSource, endCell, rangeState, startCell, table, triggerChangeData]);
889
+ const toolbarItemsBottom = React.useMemo(() => {
890
+ if (!rowsFocus || rowsFocus.length === 0) {
891
+ return toolbarItems?.filter(it => it.position === 'Bottom' && it.visible !== false && it.key !== 'DUPLICATE' && it.key !== 'INSERT_BEFORE' && it.key !== 'INSERT_AFTER' && it.key !== 'DELETE_ROWS' && it.key !== 'INSERT_CHILDREN').map(item => {
892
+ if (item.key === 'ADD') {
893
+ return {
894
+ ...item,
895
+ template: () => {
896
+ return /*#__PURE__*/React.createElement(Fragment, null, item.key === 'ADD' && /*#__PURE__*/React.createElement("div", {
897
+ className: classNames(`be-toolbar-item`, item?.className)
898
+ }, /*#__PURE__*/React.createElement(Dropdown.Button, {
899
+ overlayClassName: 'be-popup-container',
900
+ trigger: ['click'],
901
+ style: {
902
+ color: '#28c76f',
903
+ borderColor: '#28c76f'
904
+ },
905
+ className: 'toolbar-button toolbar-dropdown-button',
906
+ menu: {
907
+ items: itemsAdd,
908
+ onClick: e => handleAddMulti(item, Number(e.key))
909
+ }
910
+ }, /*#__PURE__*/React.createElement("span", {
911
+ style: {
912
+ color: '#28c76f'
913
+ },
914
+ onClick: () => handleAddMulti(item, 1)
915
+ }, item.label ? t ? t(item.label) : item.label : t ? t('Add item') : 'Add item'))));
916
+ }
917
+ };
918
+ }
919
+ if (item.key === 'DELETE') {
920
+ return {
921
+ ...item,
922
+ template: () => {
923
+ return /*#__PURE__*/React.createElement("div", {
924
+ className: classNames(`be-toolbar-item`, item?.className)
925
+ }, /*#__PURE__*/React.createElement(Button, {
926
+ style: {
927
+ color: '#eb4619',
928
+ borderColor: '#eb4619'
929
+ },
930
+ variant: 'outlined',
931
+ onClick: handleDeleteAll,
932
+ className: "d-flex toolbar-button"
933
+ }, item.label ? t ? t(item.label) : item.label : t ? t('Delete all item') : 'Delete all item'));
934
+ }
935
+ };
936
+ }
937
+ return {
938
+ ...item
939
+ };
940
+ });
941
+ }
942
+ return toolbarItems?.filter(it => it.position === 'Bottom' && it.visible !== false).map(item => {
943
+ if (item.key === 'ADD') {
944
+ return {
945
+ ...item,
946
+ template: () => {
947
+ return /*#__PURE__*/React.createElement(Fragment, null, item.key === 'ADD' && /*#__PURE__*/React.createElement("div", {
948
+ className: classNames(`be-toolbar-item`, item?.className)
949
+ }, /*#__PURE__*/React.createElement(Dropdown.Button, {
950
+ overlayClassName: 'be-popup-container',
951
+ style: {
952
+ color: '#28c76f',
953
+ borderColor: '#28c76f'
954
+ },
955
+ className: 'toolbar-button toolbar-dropdown-button',
956
+ menu: {
957
+ items: itemsAdd,
958
+ onClick: e => handleAddMulti(item, Number(e.key))
959
+ }
960
+ }, /*#__PURE__*/React.createElement("span", {
961
+ style: {
962
+ color: '#28c76f'
963
+ },
964
+ onClick: () => handleAddMulti(item, 1)
965
+ }, item.label ? t ? t(item.label) : item.label : t ? t('Add item') : 'Add item'))));
966
+ }
967
+ };
968
+ }
969
+ if (item.key === 'DUPLICATE') {
970
+ return {
971
+ ...item,
972
+ template: () => {
973
+ return /*#__PURE__*/React.createElement(Fragment, null, item.key === 'DUPLICATE' && item.visible !== false && rowsFocus.length > 0 && /*#__PURE__*/React.createElement("div", {
974
+ className: classNames(`be-toolbar-item`, item?.className)
975
+ }, /*#__PURE__*/React.createElement(Button, {
976
+ style: {
977
+ color: '#28c76f',
978
+ borderColor: '#28c76f'
979
+ },
980
+ variant: 'outlined',
981
+ onClick: handleDuplicate,
982
+ className: "d-flex toolbar-button"
983
+ }, item.label ? t ? t(item.label) : item.label : t ? t('Duplicate') : 'Duplicate')));
984
+ }
985
+ };
986
+ }
987
+ if (item.key === 'INSERT_BEFORE') {
988
+ return {
989
+ ...item,
990
+ template: () => {
991
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", {
992
+ className: classNames(`be-toolbar-item`, item?.className)
993
+ }, /*#__PURE__*/React.createElement(Dropdown.Button, {
994
+ overlayClassName: 'be-popup-container',
995
+ style: {
996
+ color: '#28c76f',
997
+ borderColor: '#28c76f'
998
+ },
999
+ className: 'toolbar-button toolbar-dropdown-button',
1000
+ menu: {
1001
+ items: itemsAdd,
1002
+ onClick: e => handleInsertBefore(item, Number(e.key))
1003
+ }
1004
+ }, /*#__PURE__*/React.createElement("span", {
1005
+ style: {
1006
+ color: '#28c76f'
1007
+ },
1008
+ onClick: () => handleInsertBefore(item, 1)
1009
+ }, item.label ? t ? t(item.label) : item.label : t ? t('Insert item before') : 'Insert item before'))));
1010
+ }
1011
+ };
1012
+ }
1013
+ if (item.key === 'INSERT_AFTER') {
1014
+ return {
1015
+ ...item,
1016
+ template: () => {
1017
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", {
1018
+ className: classNames(`be-toolbar-item`, item?.className)
1019
+ }, /*#__PURE__*/React.createElement(Dropdown.Button, {
1020
+ overlayClassName: 'be-popup-container',
1021
+ style: {
1022
+ color: '#28c76f',
1023
+ borderColor: '#28c76f'
1024
+ },
1025
+ className: 'toolbar-button toolbar-dropdown-button',
1026
+ menu: {
1027
+ items: itemsAdd,
1028
+ onClick: e => handleInsertAfter(item, Number(e.key))
1029
+ }
1030
+ }, /*#__PURE__*/React.createElement("span", {
1031
+ style: {
1032
+ color: '#28c76f'
1033
+ },
1034
+ onClick: () => handleInsertAfter(item, 1)
1035
+ }, item.label ? t ? t(item.label) : item.label : t ? t('Insert item after') : 'Insert item after'))));
1036
+ }
1037
+ };
1038
+ }
1039
+ if (item.key === 'INSERT_CHILDREN') {
1040
+ return {
1041
+ ...item,
1042
+ template: () => {
1043
+ return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", {
1044
+ className: classNames(`be-toolbar-item`, item?.className)
1045
+ }, /*#__PURE__*/React.createElement(Button, {
1046
+ style: {
1047
+ color: '#28c76f',
1048
+ borderColor: '#28c76f'
1049
+ },
1050
+ variant: 'outlined',
1051
+ onClick: () => handleInsertChild(item),
1052
+ className: "d-flex toolbar-button"
1053
+ }, item.label ? t ? t(item.label) : item.label : t ? t('Insert item children') : 'Insert item children')));
1054
+ }
1055
+ };
1056
+ }
1057
+ if (item.key === 'DELETE') {
1058
+ return {
1059
+ ...item,
1060
+ template: () => {
1061
+ return /*#__PURE__*/React.createElement("div", {
1062
+ className: classNames(`be-toolbar-item`, item?.className)
1063
+ }, /*#__PURE__*/React.createElement(Button, {
1064
+ style: {
1065
+ color: '#eb4619',
1066
+ borderColor: '#eb4619'
1067
+ },
1068
+ variant: 'outlined',
1069
+ onClick: handleDeleteAll,
1070
+ className: "d-flex toolbar-button"
1071
+ }, item.label ? t ? t(item.label) : item.label : t ? t('Delete all item') : 'Delete all item'));
1072
+ }
1073
+ };
1074
+ }
1075
+ if (item.key === 'DELETE_ROWS') {
1076
+ return {
1077
+ ...item,
1078
+ template: () => {
1079
+ return /*#__PURE__*/React.createElement("div", {
1080
+ className: classNames(`be-toolbar-item`, item?.className)
1081
+ }, /*#__PURE__*/React.createElement(Button, {
1082
+ style: {
1083
+ color: '#eb4619',
1084
+ borderColor: '#eb4619'
1085
+ },
1086
+ variant: 'outlined',
1087
+ onClick: () => handleDeleteRows(item),
1088
+ className: "d-flex toolbar-button"
1089
+ }, t ? `${t('Delete')} ${rowsFocus.length} ${t('row')}` : `Delete ${rowsFocus.length} item`));
1090
+ }
1091
+ };
1092
+ }
1093
+ return {
1094
+ ...item
1095
+ };
1096
+ });
1097
+ }, [handleAddMulti, handleDeleteAll, handleDeleteRows, handleDuplicate, handleInsertAfter, handleInsertBefore, handleInsertChild, itemsAdd, rowsFocus, t, toolbarItems]);
1098
+ return /*#__PURE__*/React.createElement("div", {
1099
+ ref: containerRef,
1100
+ id: id
1101
+ }, (showToolbar !== false || fullScreen !== false || showColumnChoose) && /*#__PURE__*/React.createElement("div", {
1102
+ ref: topToolbarRef,
1103
+ className: classNames(`${prefix}-grid-top-toolbar`, {})
1104
+ }, /*#__PURE__*/React.createElement("div", {
1105
+ style: {
1106
+ display: 'flex',
1107
+ justifyContent: 'space-between',
1108
+ alignItems: 'center',
1109
+ gap: '.75rem'
1110
+ }
1111
+ }, toolbarItems && toolbarItems?.length > 0 && /*#__PURE__*/React.createElement("div", {
1112
+ style: {
1113
+ flex: 1,
1114
+ overflow: 'hidden'
1115
+ }
1116
+ }, /*#__PURE__*/React.createElement(Toolbar, {
1117
+ items: (toolbarItems ?? []).filter(it => it.position !== 'Bottom'),
1118
+ mode: 'scroll'
1119
+ })), fullScreen !== false && (isFullScreen ? /*#__PURE__*/React.createElement(Minimize, {
1120
+ fontSize: 16
1121
+ // onClick={() => handleFullScreen?.()}
1122
+ ,
1123
+ "data-tooltip-id": "tooltip-icon",
1124
+ "data-tooltip-content": t ? t('Minimized') : 'Minimized'
1125
+ }) : /*#__PURE__*/React.createElement(Maximize, {
1126
+ fontSize: 16
1127
+ // onClick={() => handleFullScreen?.()}
1128
+ ,
1129
+ "data-tooltip-id": "tooltip-icon",
1130
+ "data-tooltip-content": t ? t('Full screen') : 'Full screen'
1131
+ })), /*#__PURE__*/React.createElement("div", {
1132
+ style: {
1133
+ display: 'flex',
1134
+ justifyContent: 'space-between',
1135
+ alignItems: 'center',
1136
+ gap: '.75rem'
1137
+ }
1138
+ }, pagination && pagination.onChange && pagination?.position && pagination?.position[0] === 'topRight' && /*#__PURE__*/React.createElement(Pagination, _extends({
1139
+ showSizeChanger: true,
1140
+ responsive: true,
1141
+ size: 'small',
1142
+ rootClassName: 'top-pagination',
1143
+ showTotal: (total, range) =>
1144
+ // @ts-ignore
1145
+ `${range[0]}-${range[1]} / ${total} ${t ? t(pagination?.locale?.items ?? 'items') : 'items'}`
1146
+ }, pagination)), typeof actionTemplate === 'function' ? actionTemplate() : actionTemplate, showColumnChoose && /*#__PURE__*/React.createElement(ColumnsChoose, {
1147
+ columns: columns,
1148
+ originColumns: propsColumns,
1149
+ t: t,
1150
+ columnsGroup: groupColumns,
1151
+ triggerChangeColumns: triggerChangeColumns,
1152
+ columnHidden: columnHidden
1153
+ })))), /*#__PURE__*/React.createElement("form", {
1154
+ onSubmit: handleSubmit(onSubmit)
1155
+ }, /*#__PURE__*/React.createElement("div", {
1156
+ // className="container"
1157
+ className: classNames(`${prefix}-grid-container`, {
1158
+ 'ui-rc-table-ping-right': tableContainerRef && (tableContainerRef.current?.scrollLeft ?? 0) >= 0 && (tableContainerRef.current?.scrollLeft ?? 0) + (tableContainerRef.current?.clientWidth ?? 0) < (tableContainerRef.current?.scrollWidth ?? 0),
1159
+ 'ui-rc-table-ping-left': tableContainerRef && (tableContainerRef.current?.scrollLeft ?? 0) > 0
1160
+ }),
1161
+ ref: tableContainerRef,
1162
+ style: {
1163
+ overflow: 'auto',
1164
+ //our scrollable table container
1165
+ position: 'relative',
1166
+ //needed for sticky header
1167
+ height: tableHeight //should be a fixed height
1168
+ }
1169
+ }, /*#__PURE__*/React.createElement(TableContext.Provider, {
1170
+ value: {
1171
+ locale,
1172
+ prefix,
1173
+ id,
1174
+ rowKey,
1175
+ format,
1176
+ expandable,
1177
+ expanded,
1178
+ setExpanded,
1179
+ dataSource,
1180
+ originData,
1181
+ wrapSettings,
1182
+ recordDoubleClick,
1183
+ selectionSettings,
1184
+ setIsSelectionChange,
1185
+ onContextMenu,
1186
+ setSorterChange,
1187
+ setFilterChange,
1188
+ rangeState,
1189
+ setRangeState,
1190
+ rangePasteState,
1191
+ setRangePasteState,
1192
+ focusedCell,
1193
+ setFocusedCell,
1194
+ startCell,
1195
+ editingKey,
1196
+ endCell,
1197
+ isSelecting,
1198
+ isPasting,
1199
+ startPasteCell,
1200
+ endPasteCell,
1201
+ setEditingKey,
1202
+ setEndCell,
1203
+ setIsSelecting,
1204
+ setStartCell,
1205
+ setIsPasting,
1206
+ setEndPasteCell,
1207
+ setStartPasteCell,
1208
+ //
1209
+ control,
1210
+ // trigger,
1211
+ errors,
1212
+ getValues,
1213
+ setValue,
1214
+ reset,
1215
+ handleCellChange,
1216
+ triggerPaste,
1217
+ handleDeleteContent,
1218
+ handleAddMulti,
1219
+ dataErrors
1220
+ }
1221
+ }, /*#__PURE__*/React.createElement("table", {
1222
+ // className={`${prefix}-grid-container`}
1223
+ style: {
1224
+ display: 'grid',
1225
+ minWidth: table.getTotalSize()
1226
+ }
1227
+ }, /*#__PURE__*/React.createElement(TableHead, {
1228
+ tableContainerRef: tableContainerRef,
1229
+ columnVirtualizer: columnVirtualizer,
1230
+ table: table,
1231
+ virtualPaddingLeft: virtualPaddingLeft,
1232
+ virtualPaddingRight: virtualPaddingRight,
1233
+ fixedLeftColumns: fixedLeftColumns,
1234
+ fixedRightColumns: fixedRightColumns
1235
+ }), /*#__PURE__*/React.createElement(TableBody, {
1236
+ tableId: id,
1237
+ columnVirtualizer: columnVirtualizer,
1238
+ table: table,
1239
+ tableContainerRef: tableContainerRef,
1240
+ virtualPaddingLeft: virtualPaddingLeft,
1241
+ virtualPaddingRight: virtualPaddingRight,
1242
+ fixedLeftColumns: fixedLeftColumns,
1243
+ fixedRightColumns: fixedRightColumns,
1244
+ commandClick: commandClick,
1245
+ editAble: editAble,
1246
+ contextMenuItems: contextMenuItems
1247
+ }), summary && /*#__PURE__*/React.createElement(TableFooter, {
1248
+ columnVirtualizer: columnVirtualizer,
1249
+ table: table,
1250
+ virtualPaddingLeft: virtualPaddingLeft,
1251
+ virtualPaddingRight: virtualPaddingRight,
1252
+ fixedLeftColumns: fixedLeftColumns,
1253
+ fixedRightColumns: fixedRightColumns
1254
+ }))))), /*#__PURE__*/React.createElement("div", {
1255
+ ref: bottomToolbarRef
1256
+ }, toolbarItemsBottom && toolbarItemsBottom.length > 0 && /*#__PURE__*/React.createElement("div", {
1257
+ className: 'ui-rc-toolbar-bottom'
1258
+ // style={{ border: '0 1px 1px 1px solid #e0e0e0' }}
1259
+ ,
1260
+ style: {
1261
+ borderBottom: '1px solid #e0e0e0',
1262
+ borderRight: '1px solid #e0e0e0',
1263
+ borderLeft: '1px solid #e0e0e0'
1264
+ }
1265
+ }, /*#__PURE__*/React.createElement(Toolbar, {
1266
+ style: {
1267
+ width: '100%'
1268
+ },
1269
+ items: toolbarItemsBottom ?? [],
1270
+ mode: 'scroll',
1271
+ onClick: ({}) => {
1272
+ setEditingKey('');
1273
+ }
1274
+ })), pagination && /*#__PURE__*/React.createElement(Pagination
1275
+ // style={{padding: '0.75rem 1rem'}}
1276
+ , _extends({}, pagination, {
1277
+ rootClassName: 'pagination-template',
1278
+ showSizeChanger: true,
1279
+ responsive: true,
1280
+ size: 'small',
1281
+ total: pagination.total,
1282
+ pageSize: pagination.onChange ? pagination.pageSize : table.getState().pagination.pageSize,
1283
+ pageSizeOptions: [20, 50, 100, 1000, 10000],
1284
+ onChange: (page, pageSize) => {
1285
+ if (pagination.onChange) {
1286
+ pagination.onChange(page, pageSize);
1287
+ } else {
1288
+ table.setPageIndex(page - 1);
1289
+ table.setPageSize(pageSize);
1290
+ }
1291
+ },
1292
+ showTotal: (total, range) => `${numericFormatter((range[0] ?? 0).toString(), {
1293
+ thousandSeparator: '.'
1294
+ })}-${numericFormatter((range[1] ?? 0).toString(), {
1295
+ thousandSeparator: '.'
1296
+ })} / ${numericFormatter((total ?? 0).toString(), {
1297
+ thousandSeparator: '.'
1298
+ })} items`
1299
+ }))));
1300
+ };
1301
+ export default TableContainerEdit;