es-grid-template 1.9.63 → 1.9.64

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 (46) hide show
  1. package/es/ali-table/Grid.js +5 -2
  2. package/es/ali-table/InternalTable.js +499 -49
  3. package/es/ali-table/base-table/calculations.js +1 -1
  4. package/es/ali-table/base-table/cell/EditCell.js +14 -6
  5. package/es/ali-table/base-table/renderFilter.js +1 -1
  6. package/es/ali-table/interfaces.d.ts +2 -2
  7. package/es/ali-table/pipeline/features/columnCustom.d.ts +4 -2
  8. package/es/ali-table/pipeline/features/columnCustom.js +112 -48
  9. package/es/ali-table/utils/constants.d.ts +1 -0
  10. package/es/ali-table/utils/constants.js +1 -0
  11. package/es/ali-table/utils/convertColumnsChoose.d.ts +2 -2
  12. package/es/ali-table/utils/convertColumnsChoose.js +1 -2
  13. package/es/ali-table/utils/utility.d.ts +15 -1
  14. package/es/ali-table/utils/utility.js +399 -1
  15. package/es/grid-component/type.d.ts +2 -2
  16. package/es/group-component/hook/utils.d.ts +3 -3
  17. package/es/table-component/TableContainerEdit.js +148 -98
  18. package/es/table-component/body/EditableCell.js +9 -5
  19. package/es/table-component/body/TableBodyCellEdit.js +14 -8
  20. package/es/table-component/header/renderFilter.js +1 -1
  21. package/es/table-component/hook/utils.d.ts +1 -1
  22. package/es/table-component/hook/utils.js +2 -6
  23. package/es/table-component/useContext.d.ts +1 -1
  24. package/lib/ali-table/Grid.js +5 -2
  25. package/lib/ali-table/InternalTable.js +490 -45
  26. package/lib/ali-table/base-table/calculations.js +1 -1
  27. package/lib/ali-table/base-table/cell/EditCell.js +14 -6
  28. package/lib/ali-table/base-table/renderFilter.js +1 -1
  29. package/lib/ali-table/interfaces.d.ts +2 -2
  30. package/lib/ali-table/pipeline/features/columnCustom.d.ts +4 -2
  31. package/lib/ali-table/pipeline/features/columnCustom.js +106 -46
  32. package/lib/ali-table/utils/constants.d.ts +1 -0
  33. package/lib/ali-table/utils/constants.js +2 -1
  34. package/lib/ali-table/utils/convertColumnsChoose.d.ts +2 -2
  35. package/lib/ali-table/utils/convertColumnsChoose.js +1 -2
  36. package/lib/ali-table/utils/utility.d.ts +15 -1
  37. package/lib/ali-table/utils/utility.js +410 -2
  38. package/lib/grid-component/type.d.ts +2 -2
  39. package/lib/table-component/TableContainerEdit.js +148 -98
  40. package/lib/table-component/body/EditableCell.js +9 -5
  41. package/lib/table-component/body/TableBodyCellEdit.js +11 -7
  42. package/lib/table-component/header/renderFilter.js +1 -1
  43. package/lib/table-component/hook/utils.d.ts +1 -1
  44. package/lib/table-component/hook/utils.js +2 -6
  45. package/lib/table-component/useContext.d.ts +1 -1
  46. package/package.json +1 -1
@@ -11,6 +11,7 @@ var fusion = _interopRequireWildcard(require("@alifd/next"));
11
11
  var _locale = require("rc-master-ui/es/locale");
12
12
  var _faker = require("@faker-js/faker");
13
13
  var _react = _interopRequireWildcard(require("react"));
14
+ var _usehooksTs = require("usehooks-ts");
14
15
  require("./base-table/styles.scss");
15
16
  var _utils = require("../table-component/hook/utils");
16
17
  var _rcMasterUi = require("rc-master-ui");
@@ -29,9 +30,16 @@ var _classnames = _interopRequireDefault(require("classnames"));
29
30
  var _hooks = require("../grid-component/hooks");
30
31
  var _sweetalert2ReactContent = _interopRequireDefault(require("sweetalert2-react-content"));
31
32
  var _sweetalert = _interopRequireDefault(require("sweetalert2"));
33
+ var _utils2 = require("./utils");
34
+ var _reactNumericComponent = require("react-numeric-component");
35
+ var _moment = _interopRequireDefault(require("moment"));
32
36
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
33
37
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
34
38
  const MySwal = (0, _sweetalert2ReactContent.default)(_sweetalert.default);
39
+ const {
40
+ Paragraph,
41
+ Title
42
+ } = _rcMasterUi.Typography;
35
43
  const InternalTable = props => {
36
44
  const {
37
45
  t,
@@ -74,6 +82,8 @@ const InternalTable = props => {
74
82
  defaultValue,
75
83
  commandSettings,
76
84
  headerData,
85
+ format,
86
+ onCellClick,
77
87
  ...rest
78
88
  } = props;
79
89
  const tableRef = (0, _react.useRef)(null);
@@ -82,6 +92,7 @@ const InternalTable = props => {
82
92
  const childrenColumnName = 'children';
83
93
  const childrenKey = 'children';
84
94
  const [tableLocal] = (0, _locale.useLocale)('Table');
95
+ const [copiedText, copy] = (0, _usehooksTs.useCopyToClipboard)();
85
96
  const tableId = _react.default.useMemo(() => {
86
97
  return _faker.faker.string.alpha(20);
87
98
  }, []);
@@ -91,6 +102,9 @@ const InternalTable = props => {
91
102
  const languages = _react.default.useMemo(() => {
92
103
  return (0, _useLocale.getLocales)(lang);
93
104
  }, [lang]);
105
+
106
+ // const isCut = React.useRef<any>(false);
107
+
94
108
  const getWindowSize = () => {
95
109
  const {
96
110
  innerWidth,
@@ -115,7 +129,7 @@ const InternalTable = props => {
115
129
  const [filterState, setFilterState] = _react.default.useState(undefined);
116
130
  const [sortState, setSortState] = _react.default.useState(undefined);
117
131
  const columns = _react.default.useMemo(() => {
118
- return (0, _utils.sortByType)(propColumns, rowDnd);
132
+ return (0, _utility.sortByType)(propColumns, rowDnd);
119
133
  }, [propColumns, rowDnd]);
120
134
  const convertData = _react.default.useMemo(() => {
121
135
  if (groupAble && groupSetting && groupSetting.client !== false) {
@@ -124,18 +138,19 @@ const InternalTable = props => {
124
138
  return (0, _utils.addRowIdArray)(dataSource);
125
139
  }, [dataSource, groupAble, groupColumns, groupSetting]);
126
140
  const isDataTree = _react.default.useMemo(() => {
127
- return (0, _utils.isTreeArray)(convertData);
128
- }, [convertData]);
141
+ return (0, _utils.isTreeArray)(dataSource);
142
+ }, [dataSource]);
129
143
  const mergedData = _react.default.useMemo(() => {
130
144
  const shouldSkip = onFilter && onSorter;
131
145
  if (shouldSkip) {
132
146
  return convertData;
133
147
  }
134
-
135
- // const rs = filterDataByColumns(convertData, onFilter ? undefined : (filterState ?? defaultFilter), onSorter ? undefined : (sortState ?? defaultSorter), [], ignoreAccents)
136
148
  const rss = (0, _utility.filterDataByColumns1)(convertData, onFilter ? undefined : filterState ?? defaultFilter, onSorter ? undefined : sortState ?? defaultSorter, [], ignoreAccents);
137
149
  return rss;
138
150
  }, [convertData, filterState, ignoreAccents, sortState, onFilter, onSorter, defaultFilter, defaultSorter]);
151
+ const rowIndexMap = _react.default.useMemo(() => {
152
+ return (0, _utils.getRowIndexMap)(convertData);
153
+ }, [convertData]);
139
154
  const footerData = _react.default.useMemo(() => {
140
155
  if (!summary) {
141
156
  return undefined;
@@ -160,15 +175,15 @@ const InternalTable = props => {
160
175
  }
161
176
  return undefined;
162
177
  }, [defaultFilter]);
163
-
164
- // const columnInVisibility = React.useMemo(() => {
165
- // return getInvisibleColumns(columns)
166
- // }, [columns])
167
-
168
- const dataIds = _react.default.useMemo(() => mergedData.map(it => it.rowId), [mergedData]);
169
178
  const columnVisibility = _react.default.useMemo(() => {
170
179
  return (0, _utils.getVisibleFields)(columns);
171
180
  }, [columns]);
181
+ const dataIds = _react.default.useMemo(() => convertData.map(it => it.rowId), [convertData]);
182
+
183
+ // const columnVisibility = React.useMemo(() => {
184
+ // return getVisibleFields(columns)
185
+ // }, [columns])
186
+
172
187
  const {
173
188
  control,
174
189
  handleSubmit,
@@ -199,7 +214,7 @@ const InternalTable = props => {
199
214
  }, [onDataChange]);
200
215
  const triggerPaste = _react.default.useCallback((pastedRows, pastedColumnsArray, newData, copyRows) => {
201
216
  const handlePasteCallback = callbackData => {
202
- const rsFilterData = (0, _utils.updateOrInsert)((0, _utils.flattenArray)([...convertData]), (0, _utils.flattenArray)([...callbackData]));
217
+ const rsFilterData = (0, _utility.updateOrInsert)(convertData, (0, _utils.flattenArray)(callbackData));
203
218
  const rs = (0, _utils.unFlattenData)(rsFilterData);
204
219
  triggerChangeData(rs, {
205
220
  type: 'OnPaste'
@@ -236,13 +251,10 @@ const InternalTable = props => {
236
251
  }, [onCellPaste, convertData, triggerChangeData]);
237
252
  const onSubmit = formData => {
238
253
  try {
239
- // const record = (await form.validateFields()) as RecordType;
240
254
  const row = {
241
255
  ...formData
242
256
  };
243
-
244
- // const newData = [...dataSource]
245
- const newData = [...convertData];
257
+ const newData = convertData;
246
258
  const index = (0, _utils.flattenData)(childrenColumnName, newData).findIndex(item => formData[rowKey] === item[rowKey]);
247
259
  const rs = (0, _utils.updateArrayByKey)(newData, row, rowKey);
248
260
  if (index > -1) {
@@ -285,8 +297,7 @@ const InternalTable = props => {
285
297
  indexRow,
286
298
  rowData: record,
287
299
  rowId: key,
288
- // rowsData: [...dataSource],
289
- rowsData: [...convertData],
300
+ rowsData: convertData,
290
301
  sumValue: []
291
302
  }, handleChangeCallback);
292
303
  } else {
@@ -299,8 +310,7 @@ const InternalTable = props => {
299
310
  indexRow,
300
311
  rowData: record,
301
312
  rowId: key,
302
- // rowsData: [...dataSource],
303
- rowsData: [...convertData],
313
+ rowsData: dataSource,
304
314
  sumValue: []
305
315
  }, handleChangeCallback);
306
316
  onSubmit(record);
@@ -406,6 +416,7 @@ const InternalTable = props => {
406
416
  columns,
407
417
  mode: sortMultiple !== false ? 'multiple' : 'single',
408
418
  dataSource: convertData,
419
+ rowIndexMap,
409
420
  columnResizeMode: 'onChange',
410
421
  disableUserSelectWhenResizing: true,
411
422
  allowFiltering,
@@ -451,7 +462,9 @@ const InternalTable = props => {
451
462
  headerEditAble,
452
463
  handleCellChange,
453
464
  handleHeaderCellChange,
454
- headerData
465
+ headerData,
466
+ triggerChangeData,
467
+ onCellClick
455
468
  })).use(_pipeline.features.paginationFeature({
456
469
  pagination
457
470
  }));
@@ -462,14 +475,42 @@ const InternalTable = props => {
462
475
 
463
476
  // reorder rows after drag & drop
464
477
 
478
+ const isEditing = _react.default.useMemo(() => {
479
+ return pipeline.getStateAtKey(_constants.stateKeyIsEditing);
480
+ }, [pipeline]);
481
+ const startCell = _react.default.useMemo(() => {
482
+ return pipeline.getStateAtKey(_constants.stateKeyStartCell);
483
+ }, [pipeline]);
484
+ const endCell = _react.default.useMemo(() => {
485
+ return pipeline.getStateAtKey(_constants.stateKeyEndCell);
486
+ }, [pipeline]);
487
+ const leafColumns = _react.default.useMemo(() => {
488
+ return (0, _utils2.collectNodes)(pipeline.getColumns(), 'leaf-only');
489
+ }, [pipeline]);
490
+ const rangeState = _react.default.useMemo(() => {
491
+ return startCell && endCell ? (0, _utils.getSelectedCellMatrix1)(convertData, leafColumns, startCell, endCell) : undefined;
492
+ }, [convertData, endCell, leafColumns, startCell]);
493
+
494
+ // const rowIds = React.useMemo(() => {
495
+
496
+ // return getKeys(convertData, 'rowId')
497
+
498
+ // }, [convertData])
499
+
500
+ // const colIds = React.useMemo(() => {
501
+
502
+ // const leafColumns = collectNodes(pipeline.getColumns(), 'leaf-only')
503
+
504
+ // return getKeys(leafColumns, 'field')
505
+
506
+ // }, [pipeline])
507
+
465
508
  _react.default.useEffect(() => {
466
509
  const handleClickOutside = event => {
467
510
  if (!editAble) {
468
511
  return;
469
512
  }
470
513
  const isEditting = pipeline.getStateAtKey(_constants.stateKeyIsEditing);
471
- const startCell = pipeline.getStateAtKey(_constants.stateKeyStartCell);
472
- const endCell = pipeline.getStateAtKey(_constants.stateKeyEndCell);
473
514
  const focusedCell = pipeline.getStateAtKey(_constants.stateKeyFocusedCell);
474
515
  const element = event.target;
475
516
  const container = document.querySelector(".be-popup-container");
@@ -534,15 +575,11 @@ const InternalTable = props => {
534
575
  return () => {
535
576
  document.removeEventListener('mousedown', handleClickOutside);
536
577
  };
537
- }, [tableId, pipeline, editAble, headerEditAble]);
578
+ }, [tableId, pipeline, editAble, headerEditAble, endCell, startCell]);
538
579
  const rowsFocus = _react.default.useMemo(() => {
539
- const startCell = pipeline.getStateAtKey(_constants.stateKeyStartCell);
540
- const endCell = pipeline.getStateAtKey(_constants.stateKeyEndCell);
541
- const allRows = pipeline.getDataSource(); // flat data
542
- const rowIndexMap = (0, _utils.getRowIndexMap)(allRows);
543
580
  const selectRowIds = startCell && endCell ? (0, _utils.getRowIdsBetween3)(convertData, rowIndexMap, startCell.rowId, endCell.rowId) : [];
544
581
  return selectRowIds;
545
- }, [convertData, pipeline]);
582
+ }, [convertData, endCell, rowIndexMap, startCell]);
546
583
  function handleDragEnd(event) {
547
584
  const {
548
585
  active,
@@ -553,7 +590,7 @@ const InternalTable = props => {
553
590
 
554
591
  const oldIndex = dataIds.indexOf(active.id);
555
592
  const newIndex = dataIds.indexOf(over.id);
556
- const rs = (0, _sortable.arrayMove)(mergedData, oldIndex, newIndex); // this is just a splice util
593
+ const rs = (0, _sortable.arrayMove)(dataSource, oldIndex, newIndex); // this is just a splice util
557
594
 
558
595
  if (rowDnd?.onChange) {
559
596
  rowDnd?.onChange({
@@ -569,7 +606,7 @@ const InternalTable = props => {
569
606
  toolbar: item
570
607
  });
571
608
  } else {
572
- const filterData = (0, _utils.flattenArray)([...convertData]);
609
+ const filterData = (0, _utils.flattenArray)(convertData);
573
610
  const rs = filterData.filter(it => !rowsFocus.includes(it[rowKey]));
574
611
  const newDaa = (0, _utils.unFlattenData)(rs);
575
612
  if (commandSettings && commandSettings.confirmDialog) {
@@ -588,7 +625,7 @@ const InternalTable = props => {
588
625
  buttonsStyling: false
589
626
  }).then(async result => {
590
627
  if (result.value) {
591
- triggerChangeData?.([...newDaa], {
628
+ triggerChangeData?.(newDaa, {
592
629
  type: 'DELETE_ROWS',
593
630
  row: rowsFocus.length
594
631
  });
@@ -596,7 +633,7 @@ const InternalTable = props => {
596
633
  });
597
634
  } else {
598
635
  // không hiện dialog
599
- triggerChangeData?.([...newDaa], {
636
+ triggerChangeData?.(newDaa, {
600
637
  type: 'DELETE_ROWS',
601
638
  row: rowsFocus.length
602
639
  });
@@ -669,7 +706,7 @@ const InternalTable = props => {
669
706
  // không tính tree
670
707
 
671
708
  // Cập nhật data mới
672
- const newData = (0, _utils.flattenArray)([...convertData]);
709
+ const newData = (0, _utils.flattenArray)(convertData);
673
710
  const focusedCell = pipeline.getStateAtKey(_constants.stateKeyFocusedCell);
674
711
  const duplicatedItem = newData.find(it => it.rowId === focusedCell?.rowId);
675
712
  const duplicatedItems = [{
@@ -684,7 +721,7 @@ const InternalTable = props => {
684
721
  // const insertAfter = Math.max(...rowsFocus)
685
722
  const insertAfter = newData.findIndex(it => it[rowKey] === focusedCell?.rowId);
686
723
  const rsFilter = [...newData.slice(0, insertAfter + 1), ...duplicatedItems, ...newData.slice(insertAfter + 1)];
687
- const rs = (0, _utils.updateOrInsert)(convertData, rsFilter);
724
+ const rs = (0, _utility.updateOrInsert)(convertData, rsFilter);
688
725
  triggerChangeData?.(rs, {
689
726
  type: 'DUPLICATE'
690
727
  });
@@ -706,7 +743,7 @@ const InternalTable = props => {
706
743
  if (!record?.parentId) {
707
744
  // Cập nhật data mới
708
745
 
709
- const newData = [...convertData];
746
+ const newData = convertData;
710
747
  const newRows = Array.from({
711
748
  length: n
712
749
  }).map(() => defaultRowValue ? {
@@ -731,7 +768,7 @@ const InternalTable = props => {
731
768
  row: n
732
769
  });
733
770
  } else {
734
- const newData = [...convertData];
771
+ const newData = convertData;
735
772
  const parent = (0, _utils.findItemByKey)(newData, rowKey, record.parentId);
736
773
  const newRows = Array.from({
737
774
  length: n
@@ -747,7 +784,7 @@ const InternalTable = props => {
747
784
  });
748
785
 
749
786
  // Cập nhật childData mới
750
- const childData = parent?.children ? [...parent.children] : [];
787
+ const childData = parent?.children ? parent.children : [];
751
788
  const index = childData.findIndex(obj => obj[rowKey] === record[rowKey]);
752
789
  childData.splice(index, 0, ...newRows);
753
790
  const newRowData = {
@@ -770,7 +807,7 @@ const InternalTable = props => {
770
807
 
771
808
  // const insertAfter = Math.max(...rowsFocus)
772
809
 
773
- // const record: RecordType = flattenData(childrenColumnName, dataSource)[insertAfter]
810
+ // const record: RecordType = flattenData(childrenColumnName, convertData)[insertAfter]
774
811
 
775
812
  // const record: any = table.getRowModel().rows.find((it) => it.id === focusedCell?.rowId)?.original
776
813
  const record = convertData.find(it => it.rowId === focusedCell?.rowId);
@@ -781,7 +818,7 @@ const InternalTable = props => {
781
818
  } else {
782
819
  if (!record?.parentId) {
783
820
  // Cập nhật data mới
784
- const newData = [...convertData];
821
+ const newData = convertData;
785
822
  const newRows = Array.from({
786
823
  length: n
787
824
  }).map(() => defaultRowValue ? {
@@ -806,7 +843,7 @@ const InternalTable = props => {
806
843
  row: n
807
844
  });
808
845
  } else {
809
- const newData = [...convertData];
846
+ const newData = convertData;
810
847
  const parent = (0, _utils.findItemByKey)(newData, rowKey, record.parentId);
811
848
  const newRows = Array.from({
812
849
  length: n
@@ -828,7 +865,7 @@ const InternalTable = props => {
828
865
  // setMergedFilterKeys?.(rs)
829
866
 
830
867
  // Cập nhật childData mới
831
- const childData = parent?.children ? [...parent.children] : [];
868
+ const childData = parent?.children ? parent.children : [];
832
869
  const index = childData.findIndex(obj => obj[rowKey] === record[rowKey]);
833
870
  childData.splice(index + 1, 0, ...newRows);
834
871
  const newRowData = {
@@ -853,8 +890,7 @@ const InternalTable = props => {
853
890
  toolbar: item
854
891
  });
855
892
  } else {
856
- // const newData = [...dataSource]
857
- const newData = [...convertData];
893
+ const newData = convertData;
858
894
  let newElement;
859
895
  if (!record?.children || record?.children && record.children.length === 0) {
860
896
  newElement = {
@@ -906,6 +942,415 @@ const InternalTable = props => {
906
942
  // setInnerExpandedKeys(newExpandedKeys)
907
943
  // }
908
944
  }, [convertData, defaultValue, pipeline, triggerChangeData]);
945
+
946
+ // Copy
947
+
948
+ const copySelectionToClipboard = _react.default.useCallback(() => {
949
+ if (!startCell || !endCell) {
950
+ return;
951
+ }
952
+ const allRows = dataSource;
953
+ const rowIds = (0, _utils.getRowIdsBetween3)(convertData, rowIndexMap, startCell?.rowId ?? '', endCell?.rowId ?? '');
954
+ const colIds = (0, _utils.getColIdsBetween1)(leafColumns, startCell?.colId ?? '', endCell?.colId ?? '');
955
+ const dataToCopy = [];
956
+ rowIds.forEach(rowId => {
957
+ const row = allRows.find(r => r.rowId === rowId);
958
+ if (!row) return;
959
+ const rowData = [];
960
+ colIds.forEach(colId => {
961
+ const value = row[colId];
962
+ rowData.push(value !== undefined ? String(value) : '');
963
+ });
964
+ dataToCopy.push(rowData);
965
+ });
966
+
967
+ // Convert to TSV string
968
+ const tsv = dataToCopy.map(row => row.join('\t')).join('\n');
969
+ copy(tsv).then(() => {}).catch(() => {});
970
+ }, [startCell, endCell, dataSource, convertData, rowIndexMap, leafColumns, copy]);
971
+ _react.default.useEffect(() => {
972
+ const handleKeyDown = e => {
973
+ if (e.ctrlKey && e.key === 'c' && startCell && endCell && !isEditing) {
974
+ e.preventDefault();
975
+ copySelectionToClipboard();
976
+ }
977
+ if (e.ctrlKey && e.key === 'x' && startCell && endCell && !isEditing) {
978
+ e.preventDefault();
979
+ if (startCell && endCell) {
980
+ const tmpData = (0, _utils.flattenArray)(convertData);
981
+ const rs = tmpData.map((row, index) => {
982
+ if (!rangeState?.rowRange.includes(row.rowId)) {
983
+ return row;
984
+ }
985
+ const updatedRow = {
986
+ ...row
987
+ };
988
+ for (const field of rangeState.colRange) {
989
+ const col = leafColumns.find(it => it.field === field);
990
+ const columnIndex = leafColumns.findIndex(it => it.field === field);
991
+ if ((0, _utils.isEditable)(col, row)) {
992
+ let newValue = '';
993
+ if (col.type === 'number') {
994
+ newValue = 0;
995
+ }
996
+ if (col.type === 'boolean' || col.type === 'checkbox') {
997
+ newValue = false;
998
+ }
999
+ const cellEditType = (0, _hooks.getEditType)(col, row);
1000
+ if (col.type === 'date' || col.type === 'datetime' || col.type === 'time' || col.type === 'month' || col.type === 'week' || col.type === 'year' || col.type === 'quarter' || cellEditType === 'asyncSelect' || cellEditType === 'select' || cellEditType === 'treeSelect' || cellEditType === 'selectTable') {
1001
+ newValue = undefined;
1002
+ }
1003
+ updatedRow[col.field] = newValue;
1004
+ handleCellChange({
1005
+ key: row[rowKey],
1006
+ field: col.field,
1007
+ record: updatedRow,
1008
+ prevState: row[col.field],
1009
+ newState: newValue,
1010
+ option: '',
1011
+ indexCol: columnIndex,
1012
+ indexRow: index,
1013
+ type: e.key
1014
+ });
1015
+ }
1016
+ }
1017
+ return updatedRow;
1018
+ });
1019
+ const newData = (0, _utils.unFlattenData)(rs);
1020
+ triggerChangeData?.(newData, {
1021
+ type: 'DELETE_CONTENT'
1022
+ });
1023
+ }
1024
+ copySelectionToClipboard();
1025
+ }
1026
+ };
1027
+ document.addEventListener('keydown', handleKeyDown);
1028
+ return () => document.removeEventListener('keydown', handleKeyDown);
1029
+ }, [startCell, endCell, copySelectionToClipboard, isEditing, convertData, triggerChangeData, leafColumns, handleCellChange, rangeState?.rowRange, rangeState?.colRange]);
1030
+
1031
+ // Copy
1032
+
1033
+ // paste
1034
+
1035
+ const handlePasted = _react.default.useCallback(pasteData => {
1036
+ if (!startCell) {
1037
+ return;
1038
+ }
1039
+ const rows = pasteData.slice(0, onCellPaste?.maxRowsPaste ?? 200);
1040
+ const allRows = convertData;
1041
+ const allCols = (0, _utils2.collectNodes)(pipeline.getColumns(), 'leaf-only');
1042
+ const startRowIdx = rowIndexMap.get(startCell.rowId);
1043
+ const startColIdx = allCols.findIndex(c => c.field === startCell.colId);
1044
+
1045
+ // const record: any = allRows[startRowIdx].original
1046
+
1047
+ // const record: any = table.getRow(startCell.rowId).original
1048
+ const recordIndex = rowIndexMap.get(startCell.rowId);
1049
+ const row = recordIndex ? allRows[recordIndex] : {};
1050
+ if (!row.parentId) {
1051
+ // Cập nhật data mới
1052
+ const newData = (0, _utils.flattenArray)(convertData);
1053
+
1054
+ // Lấy vị trí bắt đầu
1055
+
1056
+ // const startRow = newData.findIndex((it) => it[rowKey as any] === record[rowKey])
1057
+ const startRow = startRowIdx;
1058
+ const startCol = startColIdx;
1059
+ const pastedRows = [];
1060
+ const pastedColumns = new Set();
1061
+ rows.forEach((rowValues, rowIndex) => {
1062
+ const targetRow = startRow + rowIndex;
1063
+
1064
+ // Nếu vượt quá số dòng hiện có, thêm dòng mới
1065
+ if (targetRow >= newData.length) {
1066
+ const newID = (0, _utils.newGuid)();
1067
+ const defaultRowValue = (0, _utils.getDefaultValue)(defaultValue);
1068
+ newData.push(defaultValue ? {
1069
+ ...defaultRowValue,
1070
+ id: undefined,
1071
+ rowId: newID
1072
+ } : {
1073
+ id: undefined,
1074
+ rowId: newID
1075
+ });
1076
+ }
1077
+ rowValues.forEach((cellValue, colIndex) => {
1078
+ const targetCol = startCol + colIndex;
1079
+ if (targetCol >= allCols.length) {
1080
+ // Không vượt quá số cột
1081
+ return;
1082
+ }
1083
+ const columnOri = allCols[targetCol];
1084
+ const isEdit = typeof columnOri?.editEnable === 'function' ? columnOri.editEnable(newData[targetRow]) : columnOri.editEnable;
1085
+ if (isEdit) {
1086
+ const columnKey = allCols[targetCol].field;
1087
+ if (columnOri.type === 'number') {
1088
+ if (cellValue.trim() === '') {
1089
+ newData[targetRow] = {
1090
+ ...newData[targetRow],
1091
+ [columnKey]: null
1092
+ };
1093
+ }
1094
+ if ((0, _utils.isFormattedNumber)(cellValue.trim()) || !isNaN(Number(cellValue.trim()))) {
1095
+ const colFormat = typeof columnOri.format === 'function' ? columnOri.format(row) : columnOri.format;
1096
+ const valuePasteFormat = (0, _utils.detectSeparators)(cellValue.trim());
1097
+ const cellFormat = (0, _hooks.getFormat)(colFormat, format);
1098
+ const thousandSeparator = valuePasteFormat?.thousandSeparator;
1099
+ const decimalSeparator = valuePasteFormat?.decimalSeparator;
1100
+ const dec = cellFormat?.decimalScale;
1101
+ const numericFormatProps = {
1102
+ thousandSeparator: (0, _utils.checkThousandSeparator)(thousandSeparator, decimalSeparator),
1103
+ decimalSeparator: (0, _utils.checkDecimalSeparator)(thousandSeparator, decimalSeparator),
1104
+ allowNegative: cellFormat?.allowNegative ?? true,
1105
+ prefix: cellFormat?.prefix,
1106
+ suffix: cellFormat?.suffix,
1107
+ decimalScale: dec,
1108
+ fixedDecimalScale: cellFormat?.fixedDecimalScale ?? false
1109
+ };
1110
+ const val = (0, _reactNumericComponent.removeNumericFormat)(cellValue.trim(), undefined, numericFormatProps);
1111
+ newData[targetRow] = {
1112
+ ...newData[targetRow],
1113
+ [columnKey]: Number(val)
1114
+ };
1115
+ }
1116
+ } else if (columnOri.type === 'data' || columnOri.type === 'datatime' || columnOri.editType === 'date' || columnOri.editType === 'datetime') {
1117
+ const isDate = (0, _utils.isDateValue)(cellValue.trim());
1118
+ const date = isDate && !(0, _utils.isEmpty)(cellValue.trim()) ? (0, _moment.default)(cellValue.trim()).format() : null;
1119
+ newData[targetRow] = {
1120
+ ...newData[targetRow],
1121
+ [columnKey]: date
1122
+ };
1123
+ } else {
1124
+ newData[targetRow] = {
1125
+ ...newData[targetRow],
1126
+ [columnKey]: cellValue.trim()
1127
+ };
1128
+ }
1129
+ pastedColumns.add(columnKey);
1130
+ }
1131
+ });
1132
+
1133
+ // Lưu dòng được paste
1134
+ pastedRows.push(newData[targetRow]);
1135
+ });
1136
+ const pastedColumnsArray = Array.from(pastedColumns) ?? [];
1137
+ const rsFilterData = (0, _utility.updateOrInsert)(convertData, newData);
1138
+ const rs = (0, _utils.unFlattenData)(rsFilterData);
1139
+ triggerPaste?.(pastedRows, pastedColumnsArray, rs, []);
1140
+ } else {
1141
+ // const parent = findItemByKey(convertData, rowKey as any, record.parentId)
1142
+ const parent = row.getParentRow()?.original;
1143
+
1144
+ // Cập nhật childData mới
1145
+ const childData = parent?.children ? [...parent.children] : [];
1146
+
1147
+ // Lấy vị trí bắt đầu
1148
+ // const { row: startRow, col: startCol } = selectedCell;
1149
+ const startRow = childData.findIndex(it => it[rowKey] === row[rowKey]);
1150
+ const startCol = startColIdx;
1151
+ const pastedRows = [];
1152
+ const pastedColumns = new Set();
1153
+ rows.forEach((rowValues, rowIndex) => {
1154
+ const targetRow = startRow + rowIndex;
1155
+
1156
+ // Nếu vượt quá số dòng hiện có, thêm dòng mới
1157
+ if (targetRow >= childData.length) {
1158
+ childData.push({
1159
+ id: undefined,
1160
+ rowId: (0, _utils.newGuid)(),
1161
+ parentId: parent[rowKey ?? 'id']
1162
+ });
1163
+ }
1164
+ rowValues.forEach((cellValue, colIndex) => {
1165
+ const targetCol = startCol + colIndex;
1166
+ if (targetCol >= allCols.length) {
1167
+ // Không vượt quá số cột
1168
+ return;
1169
+ }
1170
+ const columnTarget = allCols[targetCol];
1171
+ const columnOri = columnTarget.columnDef.meta ?? {};
1172
+ const isEdit = typeof columnOri?.editEnable === 'function' ? columnOri.editEnable(childData[targetRow]) : columnOri.editEnable;
1173
+ if (isEdit) {
1174
+ const columnKey = allCols[targetCol].id;
1175
+ if (columnOri.type === 'number') {
1176
+ if (cellValue.trim() === '') {
1177
+ childData[targetRow] = {
1178
+ ...childData[targetRow],
1179
+ [columnKey]: null
1180
+ };
1181
+ }
1182
+ if ((0, _utils.isFormattedNumber)(cellValue.trim()) || !isNaN(Number(cellValue.trim()))) {
1183
+ const colFormat = typeof columnOri.format === 'function' ? columnOri.format(row) : columnOri.format;
1184
+ const valuePasteFormat = (0, _utils.detectSeparators)(cellValue.trim());
1185
+ const cellFormat = (0, _hooks.getFormat)(colFormat, format);
1186
+ const thousandSeparator = valuePasteFormat?.thousandSeparator;
1187
+ const decimalSeparator = valuePasteFormat?.decimalSeparator;
1188
+ const dec = cellFormat?.decimalScale;
1189
+ const numericFormatProps = {
1190
+ thousandSeparator: (0, _utils.checkThousandSeparator)(thousandSeparator, decimalSeparator),
1191
+ decimalSeparator: (0, _utils.checkDecimalSeparator)(thousandSeparator, decimalSeparator),
1192
+ allowNegative: cellFormat?.allowNegative ?? true,
1193
+ prefix: cellFormat?.prefix,
1194
+ suffix: cellFormat?.suffix,
1195
+ decimalScale: dec,
1196
+ fixedDecimalScale: cellFormat?.fixedDecimalScale ?? false
1197
+ };
1198
+ const val = (0, _reactNumericComponent.removeNumericFormat)(cellValue.trim(), undefined, numericFormatProps);
1199
+ childData[targetRow] = {
1200
+ ...childData[targetRow],
1201
+ [columnKey]: Number(val)
1202
+ };
1203
+ }
1204
+ } else if (columnOri.type === 'data' || columnOri.type === 'datatime' || columnOri.editType === 'date' || columnOri.editType === 'datetime') {
1205
+ const isDate = (0, _utils.isDateValue)(cellValue.trim());
1206
+ const date = isDate && !(0, _utils.isEmpty)(cellValue.trim()) ? (0, _moment.default)(cellValue.trim()).format() : null;
1207
+ childData[targetRow] = {
1208
+ ...childData[targetRow],
1209
+ [columnKey]: date
1210
+ };
1211
+ } else {
1212
+ childData[targetRow] = {
1213
+ ...childData[targetRow],
1214
+ [columnKey]: cellValue.trim()
1215
+ };
1216
+ }
1217
+ pastedColumns.add(columnKey);
1218
+ }
1219
+ });
1220
+
1221
+ // Lưu dòng được paste
1222
+ pastedRows.push(childData[targetRow]);
1223
+ });
1224
+ const pastedColumnsArray = Array.from(pastedColumns) ?? [];
1225
+ const newRowData = {
1226
+ ...parent,
1227
+ children: childData
1228
+ }; // item đã được filter
1229
+
1230
+ const newDataSource = (0, _utils.updateArrayByKey)(convertData, newRowData, rowKey);
1231
+ triggerPaste?.(pastedRows, pastedColumnsArray, newDataSource, []);
1232
+ }
1233
+ }, [convertData, defaultValue, format, onCellPaste?.maxRowsPaste, pipeline, rowIndexMap, startCell, triggerPaste]);
1234
+ const handlePasteToTable = _react.default.useCallback((pasteData, e) => {
1235
+ if (!startCell) return;
1236
+ const rowsPasted = (0, _utils.parseExcelClipboard)(e);
1237
+ if (rowsPasted.length > (onCellPaste?.maxRowsPaste ?? 200)) {
1238
+ // bật popup thông báo
1239
+
1240
+ _rcMasterUi.Modal.confirm({
1241
+ content: /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(Paragraph, {
1242
+ style: {
1243
+ marginBottom: '.25rem',
1244
+ fontSize: 14
1245
+ }
1246
+ }, "D\u1EEF li\u1EC7u sao ch\xE9p v\u01B0\u1EE3t qu\xE1 s\u1ED1 d\xF2ng cho ph\xE9p (", onCellPaste?.maxRowsPaste ?? 200, " d\xF2ng).Ph\u1EA7n m\u1EC1n s\u1EBD ch\u1EC9 l\u1EA5y (", onCellPaste?.maxRowsPaste ?? 200, " d\xF2ng \u0111\u1EA7u ti\xEAn."), /*#__PURE__*/_react.default.createElement(Title, {
1247
+ level: 5,
1248
+ style: {
1249
+ marginTop: '.75rem'
1250
+ }
1251
+ }, "B\u1EA1n c\xF3 mu\u1ED1n ti\u1EBFp t\u1EE5c sao ch\xE9p kh\xF4ng?")),
1252
+ centered: true,
1253
+ className: 'be-popup-container',
1254
+ onOk: () => {
1255
+ handlePasted(rowsPasted);
1256
+ }
1257
+ });
1258
+ } else {
1259
+ handlePasted(rowsPasted);
1260
+ }
1261
+ }, [handlePasted, onCellPaste?.maxRowsPaste, startCell]);
1262
+
1263
+ // const handleDeleteContent = () => {
1264
+
1265
+ // if (startCell && endCell) {
1266
+
1267
+ // const tmpData = flattenArray([...convertData])
1268
+
1269
+ // const rs = tmpData.map((row, index: number) => {
1270
+
1271
+ // if (!rangeState?.rowRange.includes(row.rowId)) {
1272
+ // return row
1273
+ // }
1274
+
1275
+ // const updatedRow = { ...row }
1276
+
1277
+ // for (const colId of rangeState.colRange) {
1278
+
1279
+ // const column = leafColumns.find((it) => it.field === colId)
1280
+ // const columnIndex = leafColumns.findIndex((it) => it.field === colId)
1281
+
1282
+ // if (isEditable(column as any, row)) {
1283
+
1284
+ // let newValue: any = ''
1285
+
1286
+ // if (column.type === 'number') {
1287
+ // newValue = 0
1288
+ // }
1289
+
1290
+ // if (column.type === 'boolean' || column.type === 'checkbox') {
1291
+ // newValue = false
1292
+ // }
1293
+
1294
+ // const editType = getEditType(column as any, row)
1295
+
1296
+ // if (column.type === 'date' ||
1297
+ // column.type === 'datetime' ||
1298
+ // column.type === 'time' ||
1299
+ // column.type === 'month' ||
1300
+ // column.type === 'week' ||
1301
+ // column.type === 'year' ||
1302
+ // column.type === 'quarter' ||
1303
+ // editType === 'asyncSelect' ||
1304
+ // editType === 'select' ||
1305
+ // editType === 'treeSelect' ||
1306
+ // editType === 'selectTable'
1307
+ // ) {
1308
+ // newValue = undefined
1309
+ // }
1310
+
1311
+ // updatedRow[colId] = newValue
1312
+
1313
+ // handleCellChange({
1314
+ // key: row[rowKey] as any,
1315
+ // field: column.field ?? column.dataIndex as any,
1316
+ // record: updatedRow,
1317
+ // prevState: row[column.field],
1318
+ // newState: newValue,
1319
+ // option: '',
1320
+ // indexCol: columnIndex,
1321
+ // indexRow: index,
1322
+ // type: 'blur'
1323
+ // }
1324
+ // )
1325
+
1326
+ // }
1327
+ // }
1328
+
1329
+ // return updatedRow;
1330
+ // })
1331
+
1332
+ // const newData = unFlattenData(rs)
1333
+
1334
+ // triggerChangeData?.([...newData], { type: 'DELETE_CONTENT' })
1335
+
1336
+ // }
1337
+
1338
+ // }
1339
+
1340
+ _react.default.useEffect(() => {
1341
+ const handlePaste = e => {
1342
+ if (startCell && !isEditing) {
1343
+ e.preventDefault(); // Chặn hành vi mặc định
1344
+ const clipboardText = e.clipboardData?.getData('text/plain') ?? '';
1345
+ handlePasteToTable(clipboardText, e);
1346
+ }
1347
+ };
1348
+ document.addEventListener('paste', handlePaste);
1349
+ return () => document.removeEventListener('paste', handlePaste);
1350
+ }, [startCell, endCell, handlePasteToTable, isEditing, copiedText]);
1351
+
1352
+ // Paste
1353
+
909
1354
  const toolbarItemsBottom = _react.default.useMemo(() => {
910
1355
  // Chưa có dòng| ô được chọn
911
1356
  if (!rowsFocus || rowsFocus.length === 0) {
@@ -1494,7 +1939,7 @@ const InternalTable = props => {
1494
1939
  // {...pipeline.getProps()}
1495
1940
  ,
1496
1941
  originData: convertData,
1497
- dataSource: dataSource,
1942
+ dataSource: mergedData,
1498
1943
  originColumns: columns,
1499
1944
  groupColumns: groupColumns,
1500
1945
  setVisibleKeys: setVisibleKeys,