es-grid-template 1.3.3 → 1.3.4
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.
- package/assets/index.css +10 -0
- package/assets/index.scss +15 -0
- package/es/grid-component/ContextMenu.js +4 -1
- package/es/grid-component/EditableCell.js +60 -18
- package/es/grid-component/TableGrid.js +1 -7
- package/es/grid-component/hooks/columns/index.js +13 -16
- package/es/grid-component/hooks/useColumns.js +2 -1
- package/es/grid-component/hooks/utils.d.ts +13 -0
- package/es/grid-component/hooks/utils.js +136 -4
- package/es/grid-component/number/index.d.ts +10 -0
- package/es/grid-component/number/index.js +39 -0
- package/es/grid-component/styles.scss +15 -0
- package/es/grid-component/table/GridEdit.js +575 -204
- package/es/grid-component/type.d.ts +3 -0
- package/es/grid-component/useContext.d.ts +2 -0
- package/lib/grid-component/ContextMenu.js +4 -1
- package/lib/grid-component/EditableCell.js +61 -18
- package/lib/grid-component/TableGrid.js +1 -7
- package/lib/grid-component/hooks/columns/index.js +12 -15
- package/lib/grid-component/hooks/useColumns.js +2 -1
- package/lib/grid-component/hooks/utils.d.ts +13 -0
- package/lib/grid-component/hooks/utils.js +150 -7
- package/lib/grid-component/number/index.d.ts +10 -0
- package/lib/grid-component/number/index.js +47 -0
- package/lib/grid-component/styles.scss +15 -0
- package/lib/grid-component/table/GridEdit.js +563 -200
- package/lib/grid-component/type.d.ts +3 -0
- package/lib/grid-component/useContext.d.ts +2 -0
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import React, { Fragment,
|
|
2
|
+
import React, { Fragment, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
3
|
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
4
4
|
import classNames from "classnames";
|
|
5
|
-
import { Button, Dropdown, Form } from "antd";
|
|
5
|
+
import { Button, Dropdown, Form, Modal, Typography } from "antd";
|
|
6
6
|
import { useForm } from 'react-hook-form';
|
|
7
7
|
import { Toaster } from "react-hot-toast";
|
|
8
8
|
import { flatColumns2, getValueCell, renderContent } from "../hooks/columns";
|
|
@@ -13,19 +13,108 @@ import dayjs from "dayjs";
|
|
|
13
13
|
import 'dayjs/locale/es';
|
|
14
14
|
import 'dayjs/locale/vi';
|
|
15
15
|
import TableGrid from "../TableGrid";
|
|
16
|
-
import { addRows8, checkChild, editAbleColumns, findAllChildrenKeys, findItemByKey, findItemPath, flattenArray, flattenData, getDefaultValue, getEditType, getFirstSelectCell, getLastSelectCell, getRowNumber, getRowsPasteIndex,
|
|
16
|
+
import { addRows8, checkChild, editAbleColumns, findAllChildrenKeys, findItemByKey, findItemPath, flattenArray, flattenData, getDefaultValue, getEditType, getFirstSelectCell, getLastSelectCell, getRowNumber, getRowsPasteIndex,
|
|
17
|
+
// isBottomMostInRanges,
|
|
18
|
+
isBottomMostInRegion,
|
|
19
|
+
// isContinuous,
|
|
20
|
+
isEditable,
|
|
21
|
+
// isEqualSet,
|
|
22
|
+
isObjEmpty, isRightMostInRegion, isTopMostInRegion,
|
|
23
|
+
// mergedSets,
|
|
24
|
+
newGuid, totalFixedWidth, updateArrayByKey } from "../hooks";
|
|
17
25
|
import Message from "../../Message/Message";
|
|
18
26
|
// import Command from "../Command";
|
|
19
27
|
|
|
20
|
-
import { Toolbar, ConfigProvider } from "rc-master-ui";
|
|
28
|
+
import { Toolbar, ConfigProvider, InputNumber } from "rc-master-ui";
|
|
21
29
|
import classnames from "classnames";
|
|
22
30
|
import useMergedState from "rc-util/es/hooks/useMergedState";
|
|
23
31
|
import { Plus, Trash2 } from "becoxy-icons";
|
|
32
|
+
// import type {ContextMenuItem} from "../type";
|
|
24
33
|
// import {ContextInfo, ContextMenuItem} from "../type";
|
|
25
34
|
// import useLazyKVMap from "rc-master-ui/es/table/hooks/useLazyKVMap";
|
|
26
35
|
|
|
36
|
+
const {
|
|
37
|
+
Paragraph,
|
|
38
|
+
Title
|
|
39
|
+
} = Typography;
|
|
27
40
|
dayjs.extend(customParseFormat);
|
|
28
41
|
const toast = 'top-right';
|
|
42
|
+
// const defaultContext: ContextMenuItem[] = [
|
|
43
|
+
const defaultContext = [{
|
|
44
|
+
key: 'INSERT_BEFORE',
|
|
45
|
+
label: 'Thêm dòng bên trên',
|
|
46
|
+
icon: /*#__PURE__*/React.createElement(Plus, {
|
|
47
|
+
fontSize: 14
|
|
48
|
+
}),
|
|
49
|
+
children: [{
|
|
50
|
+
parentKey: 'INSERT_BEFORE',
|
|
51
|
+
key: 'INSERT_BEFORE_1',
|
|
52
|
+
label: 'Thêm 1 dòng',
|
|
53
|
+
row: 1
|
|
54
|
+
}, {
|
|
55
|
+
parentKey: 'INSERT_BEFORE',
|
|
56
|
+
key: 'INSERT_BEFORE_10',
|
|
57
|
+
label: 'Thêm 10 dòng',
|
|
58
|
+
row: 10
|
|
59
|
+
}, {
|
|
60
|
+
parentKey: 'INSERT_BEFORE',
|
|
61
|
+
key: 'INSERT_BEFORE_50',
|
|
62
|
+
label: 'Thêm 50 dòng',
|
|
63
|
+
row: 50
|
|
64
|
+
}, {
|
|
65
|
+
parentKey: 'INSERT_BEFORE',
|
|
66
|
+
key: 'INSERT_BEFORE_100',
|
|
67
|
+
label: 'Thêm 100 dòng',
|
|
68
|
+
row: 100
|
|
69
|
+
}, {
|
|
70
|
+
parentKey: 'INSERT_BEFORE',
|
|
71
|
+
key: 'INSERT_BEFORE_ADV',
|
|
72
|
+
label: 'Tùy chỉnh'
|
|
73
|
+
}]
|
|
74
|
+
}, {
|
|
75
|
+
key: 'INSERT_AFTER',
|
|
76
|
+
label: 'Thêm dòng bên dưới',
|
|
77
|
+
icon: /*#__PURE__*/React.createElement(Plus, {
|
|
78
|
+
fontSize: 14
|
|
79
|
+
}),
|
|
80
|
+
children: [{
|
|
81
|
+
parentKey: 'INSERT_AFTER',
|
|
82
|
+
key: 'INSERT_AFTER_1',
|
|
83
|
+
label: 'Thêm 1 dòng',
|
|
84
|
+
row: 1
|
|
85
|
+
}, {
|
|
86
|
+
parentKey: 'INSERT_AFTER',
|
|
87
|
+
key: 'INSERT_AFTER_10',
|
|
88
|
+
label: 'Thêm 10 dòng',
|
|
89
|
+
row: 10
|
|
90
|
+
}, {
|
|
91
|
+
parentKey: 'INSERT_AFTER',
|
|
92
|
+
key: 'INSERT_AFTER_50',
|
|
93
|
+
label: 'Thêm 50 dòng',
|
|
94
|
+
row: 50
|
|
95
|
+
}, {
|
|
96
|
+
parentKey: 'INSERT_AFTER',
|
|
97
|
+
key: 'INSERT_AFTER_100',
|
|
98
|
+
label: 'Thêm 100 dòng',
|
|
99
|
+
row: 100
|
|
100
|
+
}, {
|
|
101
|
+
parentKey: 'INSERT_AFTER',
|
|
102
|
+
key: 'INSERT_AFTER_ADV',
|
|
103
|
+
label: 'Tùy chỉnh'
|
|
104
|
+
}]
|
|
105
|
+
}, {
|
|
106
|
+
key: 'DELETE_CONTENT',
|
|
107
|
+
label: 'Xóa nội dung',
|
|
108
|
+
icon: /*#__PURE__*/React.createElement(Trash2, {
|
|
109
|
+
fontSize: 14
|
|
110
|
+
})
|
|
111
|
+
}, {
|
|
112
|
+
key: 'DELETE_ROWS',
|
|
113
|
+
label: 'Xóa dòng',
|
|
114
|
+
icon: /*#__PURE__*/React.createElement(Trash2, {
|
|
115
|
+
fontSize: 14
|
|
116
|
+
})
|
|
117
|
+
}];
|
|
29
118
|
const GridEdit = props => {
|
|
30
119
|
const {
|
|
31
120
|
id,
|
|
@@ -52,6 +141,8 @@ const GridEdit = props => {
|
|
|
52
141
|
expandable,
|
|
53
142
|
onCellClick,
|
|
54
143
|
rowEditable,
|
|
144
|
+
contextMenuItems: propsContext,
|
|
145
|
+
showDefaultContext,
|
|
55
146
|
...rest
|
|
56
147
|
} = props;
|
|
57
148
|
const {
|
|
@@ -86,6 +177,21 @@ const GridEdit = props => {
|
|
|
86
177
|
const [editingKey, setEditingKey] = useState('');
|
|
87
178
|
const [isFilter, setIsFilter] = React.useState(false);
|
|
88
179
|
const [selectedCells, setSelectedCells] = useState(new Set());
|
|
180
|
+
|
|
181
|
+
// const defaultModalPaste = {open: false, rowIndex: -1, colIndex: -1, record: {}, rowsPasted: []}
|
|
182
|
+
|
|
183
|
+
// const [isCtrlDown, setIsCtrlDown] = useState(false)
|
|
184
|
+
|
|
185
|
+
// const [ctrlCells, setCtrlCells] = useState<any>([])
|
|
186
|
+
// const [currentCtrlCells, setCurrentCtrlCells] = useState<any>(new Set())
|
|
187
|
+
|
|
188
|
+
const [openModalAddRow, setOpenModalAddRow] = useState({
|
|
189
|
+
open: false,
|
|
190
|
+
type: ''
|
|
191
|
+
});
|
|
192
|
+
// const [openModalPaste, setOpenModalPaste] = useState(defaultModalPaste)
|
|
193
|
+
|
|
194
|
+
const [rowsAdd, setRowsAdd] = useState(1);
|
|
89
195
|
const [pasteCells, setPasteCells] = useState(new Set());
|
|
90
196
|
const [cellEditing, setCellEditing] = useState(null);
|
|
91
197
|
const [isSelectDragging, setSelectIsDragging] = useState(false);
|
|
@@ -110,32 +216,12 @@ const GridEdit = props => {
|
|
|
110
216
|
return [...new Set(Array.from(selectedCells).map(item => parseInt(item.split('-')[0])))] ?? [];
|
|
111
217
|
}, [selectedCells]);
|
|
112
218
|
const contextMenuItems = React.useMemo(() => {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}, {
|
|
120
|
-
key: 'INSERT_AFTER',
|
|
121
|
-
label: 'Thêm dòng bên dưới',
|
|
122
|
-
icon: /*#__PURE__*/React.createElement(Plus, {
|
|
123
|
-
fontSize: 14
|
|
124
|
-
})
|
|
125
|
-
}, {
|
|
126
|
-
key: 'DELETE_CONTENT',
|
|
127
|
-
label: 'Xóa nội dung',
|
|
128
|
-
icon: /*#__PURE__*/React.createElement(Trash2, {
|
|
129
|
-
fontSize: 14
|
|
130
|
-
})
|
|
131
|
-
}, {
|
|
132
|
-
key: 'DELETE_ROWS',
|
|
133
|
-
label: 'Xóa dòng',
|
|
134
|
-
icon: /*#__PURE__*/React.createElement(Trash2, {
|
|
135
|
-
fontSize: 14
|
|
136
|
-
})
|
|
137
|
-
}];
|
|
138
|
-
}, []);
|
|
219
|
+
const a = showDefaultContext !== false ? [...defaultContext] : [];
|
|
220
|
+
const b = propsContext ? [...propsContext, {
|
|
221
|
+
type: 'divider'
|
|
222
|
+
}] : [];
|
|
223
|
+
return [...b, ...a];
|
|
224
|
+
}, [propsContext, showDefaultContext]);
|
|
139
225
|
const onTriggerExpand = React.useCallback(record => {
|
|
140
226
|
const key = getRowKey(record, dataSource.indexOf(record));
|
|
141
227
|
let newExpandedKeys;
|
|
@@ -450,6 +536,7 @@ const GridEdit = props => {
|
|
|
450
536
|
className: classnames(`be-toolbar-item`, item?.className)
|
|
451
537
|
}, /*#__PURE__*/React.createElement(Dropdown.Button, {
|
|
452
538
|
overlayClassName: 'be-popup-container',
|
|
539
|
+
trigger: ['click'],
|
|
453
540
|
style: {
|
|
454
541
|
color: '#28c76f',
|
|
455
542
|
borderColor: '#28c76f'
|
|
@@ -660,8 +747,6 @@ const GridEdit = props => {
|
|
|
660
747
|
// defaultValues,
|
|
661
748
|
// resolver: yupResolver(formSchema)
|
|
662
749
|
});
|
|
663
|
-
|
|
664
|
-
// @ts-ignore
|
|
665
750
|
const isEditing = record => record[rowKey] === editingKey;
|
|
666
751
|
useEffect(() => {
|
|
667
752
|
const handleClickOutside = event => {
|
|
@@ -670,6 +755,7 @@ const GridEdit = props => {
|
|
|
670
755
|
// const tableId = id ? document.getElementById(id) : undefined
|
|
671
756
|
// const tableBodies = document.getElementsByClassName("ui-rc-table-tbody");
|
|
672
757
|
const container = document.querySelector(".be-popup-container");
|
|
758
|
+
const containerContextMenu = document.querySelector(".popup-context-menu");
|
|
673
759
|
const tableBody = document.querySelector(`#${id} .ui-rc-table-tbody`);
|
|
674
760
|
// const containerHidden = document.querySelector(".be-popup-container.ant-picker-dropdown-hidden")
|
|
675
761
|
|
|
@@ -677,9 +763,10 @@ const GridEdit = props => {
|
|
|
677
763
|
const itemContainer = document.querySelector(`#${id} .ui-rc-toolbar-selection-overflow-item`);
|
|
678
764
|
const itemHeader = document.querySelector(`#${id} .ui-rc-table-thead`);
|
|
679
765
|
const isInsideContainer = element.closest(".be-popup-container") && container;
|
|
766
|
+
const isInsideContainerContext = containerContextMenu && element.closest(".popup-context-menu");
|
|
680
767
|
const isInsideToolbar = element.closest(`.ui-rc-toolbar-selection-overflow-item`) && itemContainer;
|
|
681
768
|
const isInsideHeader = itemHeader && itemHeader.contains(event.target);
|
|
682
|
-
if (isInsideContainer || isInsideToolbar || isInsideHeader) {
|
|
769
|
+
if (isInsideContainer || isInsideToolbar || isInsideHeader || isInsideContainerContext) {
|
|
683
770
|
return;
|
|
684
771
|
}
|
|
685
772
|
|
|
@@ -713,66 +800,55 @@ const GridEdit = props => {
|
|
|
713
800
|
document.removeEventListener("click", handleClickOutside);
|
|
714
801
|
};
|
|
715
802
|
}, []);
|
|
716
|
-
const handleMouseDown =
|
|
803
|
+
const handleMouseDown = (record, row, col, e) => {
|
|
717
804
|
// setEditingKey('')
|
|
718
805
|
|
|
719
806
|
if (e.button === 2) {
|
|
720
807
|
e.stopPropagation();
|
|
721
808
|
return;
|
|
722
809
|
}
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
// e.stopPropagation()
|
|
730
|
-
// e.preventDefault()
|
|
731
|
-
} else {
|
|
732
|
-
// isSelecting.current = true;
|
|
733
|
-
// startCell.current = { row, col };
|
|
810
|
+
if (e.ctrlKey) {
|
|
811
|
+
isSelecting.current = true;
|
|
812
|
+
startCell.current = {
|
|
813
|
+
row,
|
|
814
|
+
col
|
|
815
|
+
};
|
|
734
816
|
|
|
735
|
-
//
|
|
736
|
-
|
|
817
|
+
// const cell: any = new Set([`${row}-${col}`])
|
|
818
|
+
|
|
819
|
+
// setCurrentCtrlCells(cell)
|
|
820
|
+
} else {
|
|
821
|
+
isSelecting.current = true;
|
|
822
|
+
startCell.current = {
|
|
737
823
|
row,
|
|
738
824
|
col
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
825
|
+
};
|
|
826
|
+
if (e.target.className === 'dragging-point') {
|
|
827
|
+
// e.stopPropagation()
|
|
828
|
+
// e.preventDefault()
|
|
829
|
+
} else {
|
|
830
|
+
setStartSelectedCell({
|
|
831
|
+
row,
|
|
832
|
+
col
|
|
833
|
+
});
|
|
834
|
+
setSelectedCells(new Set([`${row}-${col}`]));
|
|
835
|
+
setRowsSelected(new Set());
|
|
836
|
+
}
|
|
743
837
|
}
|
|
744
838
|
|
|
745
|
-
// setSelectIsDragging(true)
|
|
746
|
-
|
|
747
839
|
// isSelecting.current = true;
|
|
748
840
|
// startCell.current = { row, col };
|
|
749
841
|
//
|
|
750
|
-
// if (
|
|
751
|
-
//
|
|
842
|
+
// if (e.target.className === 'dragging-point') {
|
|
843
|
+
// // e.stopPropagation()
|
|
844
|
+
// // e.preventDefault()
|
|
845
|
+
// } else {
|
|
846
|
+
//
|
|
847
|
+
// setStartSelectedCell({row, col})
|
|
752
848
|
// setSelectedCells(new Set([`${row}-${col}`]));
|
|
753
849
|
// setRowsSelected(new Set())
|
|
754
850
|
// }
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
// const handlePointEnter = (e: any) => {
|
|
758
|
-
//
|
|
759
|
-
// if (e.button === 2) {
|
|
760
|
-
// e.stopPropagation()
|
|
761
|
-
// return
|
|
762
|
-
// }
|
|
763
|
-
//
|
|
764
|
-
// // setIsPasteDragging(true);
|
|
765
|
-
//
|
|
766
|
-
// };
|
|
767
|
-
|
|
768
|
-
// const handlePointLeave = () => {
|
|
769
|
-
//
|
|
770
|
-
// if (isPasteDragging && !isSelectDragging) {
|
|
771
|
-
// // setIsPasteDragging(false);
|
|
772
|
-
// }
|
|
773
|
-
//
|
|
774
|
-
// };
|
|
775
|
-
|
|
851
|
+
};
|
|
776
852
|
const triggerDragPaste = pastesArray => {
|
|
777
853
|
const mergedSet = new Set([...selectedCells, ...pastesArray]);
|
|
778
854
|
setSelectedCells(mergedSet);
|
|
@@ -872,18 +948,49 @@ const GridEdit = props => {
|
|
|
872
948
|
}
|
|
873
949
|
triggerDragPaste(newPasteCells);
|
|
874
950
|
};
|
|
875
|
-
|
|
951
|
+
|
|
952
|
+
// const handleClickCell = (e: any) => {
|
|
953
|
+
//
|
|
954
|
+
// if (e.ctrlKey) {
|
|
955
|
+
//
|
|
956
|
+
// const cell: any = new Set([`${row}-${col}`])
|
|
957
|
+
//
|
|
958
|
+
// const found = ctrlCells.find((s: any) => isEqualSet(s, cell));
|
|
959
|
+
//
|
|
960
|
+
// if (found) {
|
|
961
|
+
// const rs = ctrlCells.filter((s: any) => !isEqualSet(s, cell));
|
|
962
|
+
//
|
|
963
|
+
// setCtrlCells(rs)
|
|
964
|
+
//
|
|
965
|
+
// } else {
|
|
966
|
+
// setCtrlCells([...ctrlCells, cell])
|
|
967
|
+
// }
|
|
968
|
+
//
|
|
969
|
+
// }
|
|
970
|
+
// }
|
|
971
|
+
|
|
972
|
+
const handleMouseUp = e => {
|
|
876
973
|
isSelecting.current = false;
|
|
877
974
|
startCell.current = null;
|
|
878
975
|
isSelectingRow.current = false;
|
|
879
976
|
rowStart.current = null;
|
|
880
977
|
setIsPasteDragging(false);
|
|
881
978
|
setSelectIsDragging(false);
|
|
979
|
+
|
|
980
|
+
// setCurrentCtrlCells(new Set())
|
|
981
|
+
|
|
982
|
+
if (e.ctrlKey) {
|
|
983
|
+
|
|
984
|
+
// setCtrlCells([...ctrlCells, currentCtrlCells])
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
// nếu ctrlCell length > 0 thì set selectCells
|
|
988
|
+
|
|
882
989
|
if (pasteCells.size > 0) {
|
|
883
990
|
triggerDragPaste(pasteCells);
|
|
884
991
|
}
|
|
885
992
|
};
|
|
886
|
-
const handleMouseEnter = (row, col) => {
|
|
993
|
+
const handleMouseEnter = (row, col, e) => {
|
|
887
994
|
if (!isSelecting.current || !startCell.current) {
|
|
888
995
|
return;
|
|
889
996
|
}
|
|
@@ -891,6 +998,18 @@ const GridEdit = props => {
|
|
|
891
998
|
row: startRow,
|
|
892
999
|
col: startCol
|
|
893
1000
|
} = startCell.current;
|
|
1001
|
+
if (e.ctrlKey) {
|
|
1002
|
+
// const newCtrlCells = new Set();
|
|
1003
|
+
// for (let r = Math.min(startRow, row); r <= Math.max(startRow, row); r++) {
|
|
1004
|
+
// for (let c = Math.min(startCol, col); c <= Math.max(startCol, col); c++) {
|
|
1005
|
+
// newCtrlCells.add(`${r}-${c}`)
|
|
1006
|
+
// }
|
|
1007
|
+
// }
|
|
1008
|
+
|
|
1009
|
+
// setCurrentCtrlCells(newCtrlCells)
|
|
1010
|
+
|
|
1011
|
+
return;
|
|
1012
|
+
}
|
|
894
1013
|
if (!isPasteDragging) {
|
|
895
1014
|
// chọn vùng copy
|
|
896
1015
|
|
|
@@ -937,14 +1056,6 @@ const GridEdit = props => {
|
|
|
937
1056
|
if (row < colStart) {
|
|
938
1057
|
// kéo sang trái
|
|
939
1058
|
}
|
|
940
|
-
|
|
941
|
-
// const newPasteCells = new Set()
|
|
942
|
-
// for (let r = Math.min(startRow, row) + 1; r <= Math.max(startRow, row); r++) {
|
|
943
|
-
// for (let c = Math.min(colStart, col); c <= Math.max(colStart, colEnd); c++) {
|
|
944
|
-
// newPasteCells.add(`${r}-${c}`);
|
|
945
|
-
// }
|
|
946
|
-
// }
|
|
947
|
-
// setPasteCells(newPasteCells)
|
|
948
1059
|
}
|
|
949
1060
|
};
|
|
950
1061
|
const handleClickRowHeader = (row, col) => {
|
|
@@ -1075,22 +1186,17 @@ const GridEdit = props => {
|
|
|
1075
1186
|
e.clipboardData.setData("text/plain", copyText);
|
|
1076
1187
|
Message(t ? t('CopySuccessful') : 'Copy Successful');
|
|
1077
1188
|
};
|
|
1078
|
-
const
|
|
1079
|
-
|
|
1080
|
-
const pasteData = e.clipboardData.getData("text/plain").trim();
|
|
1081
|
-
|
|
1082
|
-
// Chuyển đổi dữ liệu từ clipboard thành mảng
|
|
1083
|
-
const rows = pasteData.split("\n").map(row => row.replace(/\r/g, "").split("\t"));
|
|
1189
|
+
const handlePasted = (record, indexCol, rowNumber, pasteData) => {
|
|
1190
|
+
const rows = pasteData.slice(0, onCellPaste?.maxRowsPaste ?? 200);
|
|
1084
1191
|
if (!record?.parentId) {
|
|
1085
1192
|
// Cập nhật data mới
|
|
1086
1193
|
const newData = [...dataSource];
|
|
1087
1194
|
|
|
1088
|
-
//
|
|
1089
|
-
const indexRows = newData.findIndex(it => it[rowKey] === record[rowKey]);
|
|
1195
|
+
// const indexRows = newData.findIndex((it) => it[rowKey as any] === record[rowKey])
|
|
1090
1196
|
|
|
1091
1197
|
// Lấy vị trí bắt đầu
|
|
1092
1198
|
// const { row: startRow, col: startCol } = selectedCell;
|
|
1093
|
-
const startRow =
|
|
1199
|
+
const startRow = newData.findIndex(it => it[rowKey] === record[rowKey]);
|
|
1094
1200
|
const startCol = indexCol;
|
|
1095
1201
|
|
|
1096
1202
|
// const flattData = flattenArray(newData);
|
|
@@ -1189,6 +1295,167 @@ const GridEdit = props => {
|
|
|
1189
1295
|
triggerPaste?.(pastedRows, pastedColumnsArray, newDataSource);
|
|
1190
1296
|
}
|
|
1191
1297
|
};
|
|
1298
|
+
const handlePaste = (record, indexCol, rowNumber, e) => {
|
|
1299
|
+
// const clipboard: any = (e.clipboardData || (window && window?.Clipboard)).getData("text")
|
|
1300
|
+
const pasteData = e.clipboardData.getData("text/plain").trim();
|
|
1301
|
+
|
|
1302
|
+
// Chuyển đổi dữ liệu từ clipboard thành mảng
|
|
1303
|
+
const rowsPasted = pasteData.split("\n").map(row =>
|
|
1304
|
+
// const rows = pasteData.split("\n").map((row: any) =>
|
|
1305
|
+
row.replace(/\r/g, "").split("\t"));
|
|
1306
|
+
if (rowsPasted.length > (onCellPaste?.maxRowsPaste ?? 200)) {
|
|
1307
|
+
// bật popup thông báo
|
|
1308
|
+
|
|
1309
|
+
Modal.confirm({
|
|
1310
|
+
content: /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Paragraph, {
|
|
1311
|
+
style: {
|
|
1312
|
+
marginBottom: '.25rem',
|
|
1313
|
+
fontSize: 14
|
|
1314
|
+
}
|
|
1315
|
+
}, "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, {
|
|
1316
|
+
level: 5,
|
|
1317
|
+
style: {
|
|
1318
|
+
marginTop: '.75rem'
|
|
1319
|
+
}
|
|
1320
|
+
}, "B\u1EA1n c\xF3 mu\u1ED1n ti\u1EBFp t\u1EE5c sao ch\xE9p kh\xF4ng?")),
|
|
1321
|
+
centered: true,
|
|
1322
|
+
className: 'be-popup-container',
|
|
1323
|
+
onOk: () => {
|
|
1324
|
+
handlePasted(record, indexCol, rowNumber, rowsPasted);
|
|
1325
|
+
}
|
|
1326
|
+
// footer: (_, { OkBtn, CancelBtn }) => (
|
|
1327
|
+
// <>
|
|
1328
|
+
// <OkBtn />
|
|
1329
|
+
// <CancelBtn />
|
|
1330
|
+
// </>
|
|
1331
|
+
// ),
|
|
1332
|
+
});
|
|
1333
|
+
} else {
|
|
1334
|
+
handlePasted(record, indexCol, rowNumber, rowsPasted);
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
// const rows = rowsPasted.slice(0, (onCellPaste?.maxRowsPaste ?? 200));
|
|
1338
|
+
//
|
|
1339
|
+
//
|
|
1340
|
+
// if (!record?.parentId ) {
|
|
1341
|
+
//
|
|
1342
|
+
// // Cập nhật data mới
|
|
1343
|
+
// const newData = [...dataSource];
|
|
1344
|
+
//
|
|
1345
|
+
// // @ts-ignore
|
|
1346
|
+
// const indexRows = newData.findIndex((it) => it[rowKey] === record[rowKey])
|
|
1347
|
+
//
|
|
1348
|
+
// // Lấy vị trí bắt đầu
|
|
1349
|
+
// // const { row: startRow, col: startCol } = selectedCell;
|
|
1350
|
+
// const startRow = indexRows
|
|
1351
|
+
// const startCol = indexCol
|
|
1352
|
+
//
|
|
1353
|
+
//
|
|
1354
|
+
//
|
|
1355
|
+
// // const flattData = flattenArray(newData);
|
|
1356
|
+
//
|
|
1357
|
+
// const pastedRows: RecordType[] = [];
|
|
1358
|
+
// const pastedColumns = new Set()
|
|
1359
|
+
//
|
|
1360
|
+
//
|
|
1361
|
+
// rows.forEach((rowValues: any, rowIndex: any) => {
|
|
1362
|
+
// const targetRow = startRow + rowIndex;
|
|
1363
|
+
//
|
|
1364
|
+
// // Nếu vượt quá số dòng hiện có, thêm dòng mới
|
|
1365
|
+
// if (targetRow >= newData.length) {
|
|
1366
|
+
// // @ts-ignore
|
|
1367
|
+
// // newData.push({ id: newGuid()});
|
|
1368
|
+
// newData.push({ id: undefined, rowId: newGuid()});
|
|
1369
|
+
// }
|
|
1370
|
+
//
|
|
1371
|
+
// rowValues.forEach((cellValue: any, colIndex: any) => {
|
|
1372
|
+
// const targetCol = startCol + colIndex;
|
|
1373
|
+
// if (targetCol >= columns.length) { // Không vượt quá số cột
|
|
1374
|
+
// return
|
|
1375
|
+
// }
|
|
1376
|
+
//
|
|
1377
|
+
// if (columns[targetCol].editEnable) {
|
|
1378
|
+
// // @ts-ignore
|
|
1379
|
+
// const columnKey = columns[targetCol].field;
|
|
1380
|
+
//
|
|
1381
|
+
// // @ts-ignore
|
|
1382
|
+
// newData[targetRow] = { ...newData[targetRow], [columnKey]: cellValue.trim() };
|
|
1383
|
+
// pastedColumns.add(columnKey);
|
|
1384
|
+
// }
|
|
1385
|
+
//
|
|
1386
|
+
// });
|
|
1387
|
+
//
|
|
1388
|
+
// // Lưu dòng được paste
|
|
1389
|
+
// pastedRows.push(newData[targetRow]);
|
|
1390
|
+
//
|
|
1391
|
+
// });
|
|
1392
|
+
//
|
|
1393
|
+
// const pastedColumnsArray = Array.from(pastedColumns) ?? [];
|
|
1394
|
+
//
|
|
1395
|
+
// triggerPaste?.(pastedRows, pastedColumnsArray as string[], newData)
|
|
1396
|
+
//
|
|
1397
|
+
//
|
|
1398
|
+
// } else {
|
|
1399
|
+
//
|
|
1400
|
+
// // Cập nhật data mới
|
|
1401
|
+
// const newData = [...dataSource];
|
|
1402
|
+
//
|
|
1403
|
+
// const parent = findItemByKey(newData, rowKey as any, record.parentId)
|
|
1404
|
+
//
|
|
1405
|
+
// // Cập nhật childData mới
|
|
1406
|
+
// const childData: any[] = parent?.children ? [...parent.children] : []
|
|
1407
|
+
//
|
|
1408
|
+
//
|
|
1409
|
+
// // Lấy vị trí bắt đầu
|
|
1410
|
+
// // const { row: startRow, col: startCol } = selectedCell;
|
|
1411
|
+
// const startRow = childData.findIndex((it) => it[rowKey] === record[rowKey])
|
|
1412
|
+
// const startCol = indexCol
|
|
1413
|
+
//
|
|
1414
|
+
// const pastedRows: RecordType[] = []
|
|
1415
|
+
// const pastedColumns = new Set()
|
|
1416
|
+
//
|
|
1417
|
+
//
|
|
1418
|
+
// rows.forEach((rowValues: any, rowIndex: any) => {
|
|
1419
|
+
// const targetRow = startRow + rowIndex
|
|
1420
|
+
//
|
|
1421
|
+
// // Nếu vượt quá số dòng hiện có, thêm dòng mới
|
|
1422
|
+
// if (targetRow >= childData.length) {
|
|
1423
|
+
//
|
|
1424
|
+
// childData.push({ id: undefined, rowId: newGuid(), parentId: parent[rowKey ?? 'id']})
|
|
1425
|
+
// }
|
|
1426
|
+
//
|
|
1427
|
+
// rowValues.forEach((cellValue: any, colIndex: any) => {
|
|
1428
|
+
// const targetCol = startCol + colIndex
|
|
1429
|
+
// if (targetCol >= columns.length) { // Không vượt quá số cột
|
|
1430
|
+
// return
|
|
1431
|
+
// }
|
|
1432
|
+
//
|
|
1433
|
+
// if (columns[targetCol].editEnable) {
|
|
1434
|
+
//
|
|
1435
|
+
// // @ts-ignore
|
|
1436
|
+
// const columnKey = columns[targetCol].field
|
|
1437
|
+
//
|
|
1438
|
+
// // @ts-ignore
|
|
1439
|
+
// childData[targetRow] = { ...childData[targetRow], [columnKey]: cellValue.trim() }
|
|
1440
|
+
// pastedColumns.add(columnKey)
|
|
1441
|
+
// }
|
|
1442
|
+
//
|
|
1443
|
+
// })
|
|
1444
|
+
//
|
|
1445
|
+
// // Lưu dòng được paste
|
|
1446
|
+
// pastedRows.push(childData[targetRow])
|
|
1447
|
+
//
|
|
1448
|
+
// })
|
|
1449
|
+
//
|
|
1450
|
+
// const pastedColumnsArray = Array.from(pastedColumns) ?? []
|
|
1451
|
+
//
|
|
1452
|
+
// const newRowData = {...parent, children: childData}
|
|
1453
|
+
//
|
|
1454
|
+
// const newDataSource = updateArrayByKey(newData, newRowData, rowKey as string)
|
|
1455
|
+
//
|
|
1456
|
+
// triggerPaste?.(pastedRows, pastedColumnsArray as string[], newDataSource )
|
|
1457
|
+
// }
|
|
1458
|
+
};
|
|
1192
1459
|
const onSubmit = formData => {
|
|
1193
1460
|
try {
|
|
1194
1461
|
// const record = (await form.validateFields()) as RecordType;
|
|
@@ -1214,7 +1481,10 @@ const GridEdit = props => {
|
|
|
1214
1481
|
newState,
|
|
1215
1482
|
prevState,
|
|
1216
1483
|
option,
|
|
1217
|
-
field
|
|
1484
|
+
field,
|
|
1485
|
+
indexCol,
|
|
1486
|
+
indexRow,
|
|
1487
|
+
key
|
|
1218
1488
|
} = args;
|
|
1219
1489
|
|
|
1220
1490
|
// const newRecord = getValues()
|
|
@@ -1232,26 +1502,26 @@ const GridEdit = props => {
|
|
|
1232
1502
|
if (onCellChange.length > 1) {
|
|
1233
1503
|
onCellChange({
|
|
1234
1504
|
field,
|
|
1235
|
-
indexCol
|
|
1505
|
+
indexCol,
|
|
1236
1506
|
type: 'onChange',
|
|
1237
1507
|
value: newState,
|
|
1238
1508
|
option,
|
|
1239
|
-
indexRow
|
|
1509
|
+
indexRow,
|
|
1240
1510
|
rowData: record,
|
|
1241
|
-
rowId:
|
|
1511
|
+
rowId: key,
|
|
1242
1512
|
rowsData: [],
|
|
1243
1513
|
sumValue: []
|
|
1244
1514
|
}, handleChangeCallback);
|
|
1245
1515
|
} else {
|
|
1246
1516
|
onCellChange({
|
|
1247
1517
|
field,
|
|
1248
|
-
indexCol
|
|
1518
|
+
indexCol,
|
|
1249
1519
|
type: 'onChange',
|
|
1250
1520
|
option,
|
|
1251
1521
|
value: newState,
|
|
1252
|
-
indexRow
|
|
1522
|
+
indexRow,
|
|
1253
1523
|
rowData: record,
|
|
1254
|
-
rowId:
|
|
1524
|
+
rowId: key,
|
|
1255
1525
|
rowsData: [],
|
|
1256
1526
|
sumValue: []
|
|
1257
1527
|
}, handleChangeCallback);
|
|
@@ -1360,7 +1630,7 @@ const GridEdit = props => {
|
|
|
1360
1630
|
});
|
|
1361
1631
|
}
|
|
1362
1632
|
};
|
|
1363
|
-
const handleFocusCell = (rowIndex, colIndex, col, scrollType, e) => {
|
|
1633
|
+
const handleFocusCell = (rowIndex, colIndex, col, scrollType, e, isTimeout) => {
|
|
1364
1634
|
const isEdit = editingKey !== '';
|
|
1365
1635
|
const cellEdit = document.querySelector(`.ui-rc-table-row .cell-editing[data-row-index="${rowIndex}"].cell-editing[data-col-index="${colIndex}"]`);
|
|
1366
1636
|
const cell = document.querySelector(`.ui-rc-table-row .cell-editable[data-row-index="${rowIndex}"].cell-editable[data-col-index="${colIndex}"]`);
|
|
@@ -1371,34 +1641,49 @@ const GridEdit = props => {
|
|
|
1371
1641
|
});
|
|
1372
1642
|
setSelectedCells(new Set([`${rowIndex}-${colIndex}`]));
|
|
1373
1643
|
};
|
|
1374
|
-
|
|
1375
|
-
if (
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1644
|
+
const focusNextCell = (editingCell, cellEditable) => {
|
|
1645
|
+
if (isEdit) {
|
|
1646
|
+
if (editingCell) {
|
|
1647
|
+
updateSelection();
|
|
1648
|
+
if (e?.key !== 'Tab') {
|
|
1649
|
+
editingCell.focus();
|
|
1650
|
+
}
|
|
1379
1651
|
}
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
scrollToCell(rowIndex, colIndex, cellEdit, 'horizontal');
|
|
1383
|
-
}
|
|
1384
|
-
if (scrollType === 'vertical' && cell) {
|
|
1385
|
-
setEditingKey('');
|
|
1386
|
-
updateSelection();
|
|
1387
|
-
scrollToCell(rowIndex, colIndex, cellEdit, 'vertical');
|
|
1388
|
-
if (e?.key !== 'Tab') {
|
|
1389
|
-
cell.focus();
|
|
1652
|
+
if (scrollType === 'horizontal' && editingCell) {
|
|
1653
|
+
scrollToCell(rowIndex, colIndex, editingCell, 'horizontal');
|
|
1390
1654
|
}
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1655
|
+
if (scrollType === 'vertical' && cellEditable) {
|
|
1656
|
+
setEditingKey('');
|
|
1657
|
+
updateSelection();
|
|
1658
|
+
scrollToCell(rowIndex, colIndex, cellEdit, 'vertical');
|
|
1659
|
+
if (e?.key !== 'Tab') {
|
|
1660
|
+
cellEditable.focus();
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
} else {
|
|
1664
|
+
if (cellEditable) {
|
|
1665
|
+
updateSelection();
|
|
1666
|
+
if (e?.key !== 'Tab') {
|
|
1667
|
+
cellEditable.focus();
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
if (cellEditable) {
|
|
1671
|
+
scrollToCell(rowIndex, colIndex, cellEditable, scrollType);
|
|
1397
1672
|
}
|
|
1398
1673
|
}
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1674
|
+
};
|
|
1675
|
+
if (isTimeout) {
|
|
1676
|
+
let cellEdit1 = undefined;
|
|
1677
|
+
let cell1 = undefined;
|
|
1678
|
+
setTimeout(() => {
|
|
1679
|
+
cellEdit1 = document.querySelector(`.ui-rc-table-row .cell-editing[data-row-index="${rowIndex}"].cell-editing[data-col-index="${colIndex}"]`);
|
|
1680
|
+
cell1 = document.querySelector(`.ui-rc-table-row .cell-editable[data-row-index="${rowIndex}"].cell-editable[data-col-index="${colIndex}"]`);
|
|
1681
|
+
}, 20);
|
|
1682
|
+
setTimeout(() => {
|
|
1683
|
+
focusNextCell(cellEdit1, cell1);
|
|
1684
|
+
}, 50);
|
|
1685
|
+
} else {
|
|
1686
|
+
focusNextCell(cellEdit, cell);
|
|
1402
1687
|
}
|
|
1403
1688
|
};
|
|
1404
1689
|
const getCellClass = (record, rowIndex, colIndex) => {
|
|
@@ -1421,25 +1706,22 @@ const GridEdit = props => {
|
|
|
1421
1706
|
const cellPasteSEnd = getLastSelectCell(pasteCells);
|
|
1422
1707
|
const isPasteBottom = pasteCells.size && cellPasteSEnd && rowIndex === Math.max(cellPasteStart.row, cellPasteSEnd.row);
|
|
1423
1708
|
if (!isSelected && !isPasteSelected) {
|
|
1424
|
-
const isTop = prevRecordEditing && !isEditing(prevRecordEditing) && rowIndex === Math.min(cellStart.row - 1, cellEnd?.row);
|
|
1709
|
+
// const isTop = prevRecordEditing && !isEditing(prevRecordEditing) && rowIndex === Math.min(cellStart.row - 1, cellEnd?.row);
|
|
1710
|
+
const isTop = prevRecordEditing && !isEditing(prevRecordEditing) && isTopMostInRegion(rowIndex + 1, colIndex, selectedCells);
|
|
1425
1711
|
const isLeft = colIndex + 1 === Math.min(cellStart.col, cellEnd?.col);
|
|
1426
1712
|
const isRight = colIndex - 1 === Math.max(cellStart.col, cellEnd?.col);
|
|
1427
1713
|
const isPasteLeft = colIndex + 1 === Math.min(cellPasteStart.col, cellPasteSEnd?.col);
|
|
1428
1714
|
const isPasteRight = colIndex - 1 === Math.max(cellPasteStart.col, cellPasteSEnd?.col);
|
|
1429
|
-
return isTopSelected || isLeftSelected || isRightSelected ? `${cellClass} ${isTop ? `cell-border-top` : ''} ${isLeft ? `cell-border-left` : ''} ${isPasteBottom ? `cell-paste-border-bottom` : ''} ${isRight ? `next-cell-border-left` : ''}` : isPasteLeftSelected || isPasteRightSelected ? `${cellClass} ${isPasteLeft ? `cell-paste-border-left` : ''} ${isPasteRight ? `next-cell-paste-border-left` : ''}` :
|
|
1430
|
-
// (isPasteLeftSelected || isPasteRightSelected) ? `${cellClass} ${isPasteLeft ? `cell-paste-border-left` : ''}` :
|
|
1431
|
-
|
|
1432
|
-
cellClass;
|
|
1715
|
+
return isTopSelected || isLeftSelected || isRightSelected ? `${cellClass} ${isTop ? `cell-border-top` : ''} ${isLeft ? `cell-border-left` : ''} ${isPasteBottom ? `cell-paste-border-bottom` : ''} ${isRight ? `next-cell-border-left` : ''}` : isPasteLeftSelected || isPasteRightSelected ? `${cellClass} ${isPasteLeft ? `cell-paste-border-left` : ''} ${isPasteRight ? `next-cell-paste-border-left` : ''}` : cellClass;
|
|
1433
1716
|
}
|
|
1434
|
-
const isBottom =
|
|
1435
|
-
const
|
|
1717
|
+
const isBottom = isBottomMostInRegion(rowIndex, colIndex, selectedCells);
|
|
1718
|
+
// const isBottom = isBottomMostInRanges(rowIndex, colIndex, [selectedCells, ...ctrlCells])
|
|
1719
|
+
|
|
1720
|
+
// const isRight = cellEnd && colIndex === Math.max(cellStart.col, cellEnd.col)
|
|
1721
|
+
const isRight = isRightMostInRegion(rowIndex, colIndex, selectedCells);
|
|
1436
1722
|
const isLeft = colIndex === Math.min(cellStart.col, cellEnd?.col);
|
|
1437
1723
|
const isPasteRight = cellPasteSEnd && colIndex === Math.max(cellPasteStart.col, cellPasteSEnd.col);
|
|
1438
1724
|
const isPasteLeft = colIndex === Math.min(cellPasteStart.col, cellPasteSEnd?.col);
|
|
1439
|
-
|
|
1440
|
-
// return `${cellClass} ${isBottom ? `cell-border-bottom` : ''} ${isRight ? `cell-border-right` : '' } ${isBottom && isRight ? `cell-border-end` : '' }
|
|
1441
|
-
// return `${cellClass} ${isPasteBottom ? `cell-paste-border-bottom` : ''} ${isBottom ? `cell-border-bottom` : ''} ${isRight ? `cell-border-right` : '' } ${isLeft ? `fixed-cell-border-left` : '' } ${isBottom && isRight ? `cell-border-end` : '' }`
|
|
1442
|
-
|
|
1443
1725
|
return `${cellClass} ${isPasteBottom ? `cell-paste-border-bottom` : ''} ${isPasteSelected && isPasteRight ? `cell-paste-border-right` : ''} ${isPasteSelected && isPasteLeft ? `fixed-cell-paste-border-left` : ''} ${isBottom ? `cell-border-bottom` : ''} ${isRight ? `cell-border-right` : ''} ${isLeft ? `fixed-cell-border-left` : ''} ${isBottom && isRight ? `cell-border-end` : ''}`;
|
|
1444
1726
|
};
|
|
1445
1727
|
const convertColumns = flatColumns2(columns).map((column, colIndex) => {
|
|
@@ -1500,79 +1782,97 @@ const GridEdit = props => {
|
|
|
1500
1782
|
onCell: (record, rowIndex) => {
|
|
1501
1783
|
const rowNumber = getRowNumber(dataSource, record[rowKey], rowKey);
|
|
1502
1784
|
return {
|
|
1503
|
-
// onKeyPress: () => {
|
|
1504
|
-
//
|
|
1505
|
-
// },
|
|
1506
|
-
|
|
1507
1785
|
onKeyDown: event => {
|
|
1508
1786
|
const key = getRowKey(record, dataSource.indexOf(record));
|
|
1509
|
-
if (event.key
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
const hasKey = mergedExpandedKeys.has(key);
|
|
1517
|
-
if (hasKey) {
|
|
1518
|
-
// mergedExpandedKeys.delete(key);
|
|
1519
|
-
// newExpandedKeys = [...mergedExpandedKeys];
|
|
1520
|
-
} else {
|
|
1521
|
-
onTriggerExpand(record);
|
|
1522
|
-
}
|
|
1523
|
-
} else {
|
|
1524
|
-
if (event.key === 'Enter') {
|
|
1787
|
+
if (event.key === 'Control' && event.ctrlKey) {
|
|
1788
|
+
|
|
1789
|
+
// setIsCtrlDown(true)
|
|
1790
|
+
} else {
|
|
1791
|
+
if (event.key.length === 1 && !event.ctrlKey && !event.metaKey || event.key === 'Enter') {
|
|
1792
|
+
if (record[rowKey] !== editingKey && isEditable(column, record)) {
|
|
1793
|
+
// ~~ khi editingKey = ''
|
|
1525
1794
|
event.preventDefault();
|
|
1526
1795
|
event.stopPropagation();
|
|
1527
|
-
|
|
1528
|
-
|
|
1796
|
+
handleEdit(record, column, column.editType, event);
|
|
1797
|
+
handleCellClick(rowNumber, record, column);
|
|
1798
|
+
const hasKey = mergedExpandedKeys.has(key);
|
|
1799
|
+
if (hasKey) {
|
|
1800
|
+
// mergedExpandedKeys.delete(key);
|
|
1801
|
+
// newExpandedKeys = [...mergedExpandedKeys];
|
|
1529
1802
|
} else {
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1803
|
+
onTriggerExpand(record);
|
|
1804
|
+
}
|
|
1805
|
+
} else {
|
|
1806
|
+
if (event.key === 'Enter') {
|
|
1807
|
+
event.preventDefault();
|
|
1808
|
+
event.stopPropagation();
|
|
1809
|
+
if (editingKey && editingKey !== '' && (rowNumber ?? 0) + 1 < flattenArray(dataSource).length && event.key === 'Enter') {
|
|
1810
|
+
handleFocusCell((rowNumber ?? 0) + 1, colIndex, column, 'vertical', event);
|
|
1811
|
+
} else {
|
|
1812
|
+
// // focus cell hiện tại và tắt edit
|
|
1813
|
+
// handleFocusCell((rowNumber ?? 0), colIndex, column, 'vertical', event)
|
|
1814
|
+
// setEditingKey('')
|
|
1815
|
+
|
|
1816
|
+
// thêm dòng mới
|
|
1817
|
+
|
|
1818
|
+
handleAddSingle();
|
|
1819
|
+
handleFocusCell((rowNumber ?? 0) + 1, colIndex, column, 'vertical', event, true);
|
|
1820
|
+
}
|
|
1539
1821
|
}
|
|
1540
1822
|
}
|
|
1541
1823
|
}
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
}
|
|
1550
|
-
}
|
|
1551
|
-
if (event.key === 'ArrowRight' && colIndex + 1 !== columns.length) {
|
|
1552
|
-
if (editingKey !== '') {} else {
|
|
1553
|
-
handleFocusCell(rowNumber, colIndex + 1, column, 'horizontal', event);
|
|
1824
|
+
if (event.key === 'Tab') {
|
|
1825
|
+
if (colIndex + 1 !== columns.length) {
|
|
1826
|
+
handleFocusCell(rowNumber, colIndex + 1, column, 'horizontal', event);
|
|
1827
|
+
} else {
|
|
1828
|
+
event.stopPropagation();
|
|
1829
|
+
event.preventDefault();
|
|
1830
|
+
}
|
|
1554
1831
|
}
|
|
1555
|
-
|
|
1556
|
-
if (event.key === 'ArrowLeft' && colIndex > 0) {
|
|
1557
|
-
if (!column.dataIndex && !column.key || column.field === 'index' || column.field === '#' || column.dataIndex === 'index' || column.dataIndex === '#') {
|
|
1558
|
-
event.stopPropagation();
|
|
1559
|
-
event.preventDefault();
|
|
1560
|
-
} else {
|
|
1832
|
+
if (event.key === 'ArrowRight' && colIndex + 1 !== columns.length) {
|
|
1561
1833
|
if (editingKey !== '') {} else {
|
|
1562
|
-
handleFocusCell(rowNumber, colIndex
|
|
1834
|
+
handleFocusCell(rowNumber, colIndex + 1, column, 'horizontal', event);
|
|
1563
1835
|
}
|
|
1564
1836
|
}
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1837
|
+
if (event.key === 'ArrowLeft' && colIndex > 0) {
|
|
1838
|
+
if (!column.dataIndex && !column.key || column.field === 'index' || column.field === '#' || column.dataIndex === 'index' || column.dataIndex === '#') {
|
|
1839
|
+
event.stopPropagation();
|
|
1840
|
+
event.preventDefault();
|
|
1841
|
+
} else {
|
|
1842
|
+
if (editingKey !== '') {} else {
|
|
1843
|
+
handleFocusCell(rowNumber, colIndex - 1, column, 'horizontal', event);
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
if (event.key === 'ArrowDown' && (rowNumber ?? 0) + 1 < flattenArray(dataSource).length) {
|
|
1848
|
+
if (isEditing(record) && (getEditType(column, record) === 'treeSelect' || getEditType(column, record) === 'select' || getEditType(column, record) === 'selectTable' || getEditType(column, record) === 'asyncSelect')) {
|
|
1849
|
+
event.stopPropagation();
|
|
1850
|
+
} else {
|
|
1851
|
+
handleFocusCell((rowNumber ?? 0) + 1, colIndex, column, 'vertical', event);
|
|
1852
|
+
}
|
|
1853
|
+
}
|
|
1854
|
+
if (event.key === 'ArrowUp' && (rowNumber ?? 0) > 0) {
|
|
1855
|
+
if (isEditing(record) && (getEditType(column, record) === 'asyncSelect' || getEditType(column, record) === 'select' || getEditType(column, record) === 'selectTable' || getEditType(column, record) === 'treeSelect')) {
|
|
1856
|
+
event.stopPropagation();
|
|
1857
|
+
} else {
|
|
1858
|
+
handleFocusCell((rowNumber ?? 0) - 1, colIndex, column, 'vertical', event);
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
if (event.key === 'Delete') {
|
|
1862
|
+
handleDeleteContent();
|
|
1863
|
+
}
|
|
1864
|
+
if (event.key === 'Escape') {
|
|
1865
|
+
setEditingKey('');
|
|
1866
|
+
}
|
|
1574
1867
|
}
|
|
1575
1868
|
},
|
|
1869
|
+
// onKeyUp: (event: any) => {
|
|
1870
|
+
// if (event.key === 'Control' && event.ctrlKey) {
|
|
1871
|
+
//
|
|
1872
|
+
// console.log('onKeyUp')
|
|
1873
|
+
// }
|
|
1874
|
+
// },
|
|
1875
|
+
|
|
1576
1876
|
onPaste: event => {
|
|
1577
1877
|
if (editingKey === '') {
|
|
1578
1878
|
handlePaste(record, colIndex, rowNumber, event);
|
|
@@ -1628,8 +1928,9 @@ const GridEdit = props => {
|
|
|
1628
1928
|
} : {}
|
|
1629
1929
|
};
|
|
1630
1930
|
},
|
|
1631
|
-
onHeaderCell: () => {
|
|
1931
|
+
onHeaderCell: (data, index) => {
|
|
1632
1932
|
return {
|
|
1933
|
+
...(column.onHeaderCell ? column.onHeaderCell?.(data, index) : {}),
|
|
1633
1934
|
onClick: () => {
|
|
1634
1935
|
handleClickColHeader(column, colIndex);
|
|
1635
1936
|
},
|
|
@@ -1655,12 +1956,18 @@ const GridEdit = props => {
|
|
|
1655
1956
|
return /*#__PURE__*/React.createElement("div", {
|
|
1656
1957
|
className: classNames('ui-rc_cell-content', {
|
|
1657
1958
|
// selected: selectedCells.has(`${record[rowKey]}-${colIndex}`)
|
|
1959
|
+
// selected: selectedCells.has(`${rowNumber}-${colIndex}`) || currentCtrlCells.has(`${rowNumber}-${colIndex}`) || mergedSets([selectedCells, ...ctrlCells]).has(`${rowNumber}-${colIndex}`),
|
|
1658
1960
|
selected: selectedCells.has(`${rowNumber}-${colIndex}`),
|
|
1659
1961
|
disable: !isEditable(column, record)
|
|
1660
1962
|
}),
|
|
1661
1963
|
onMouseDown: event => handleMouseDown(record, rowNumber, colIndex, event),
|
|
1662
|
-
onMouseEnter:
|
|
1964
|
+
onMouseEnter: event => handleMouseEnter(rowNumber, colIndex, event),
|
|
1663
1965
|
onMouseUp: handleMouseUp
|
|
1966
|
+
// onClick={(event) => {
|
|
1967
|
+
//
|
|
1968
|
+
// handleClickCell(event)
|
|
1969
|
+
//
|
|
1970
|
+
// }}
|
|
1664
1971
|
}, /*#__PURE__*/React.createElement("div", {
|
|
1665
1972
|
className: 'ui-rc_content'
|
|
1666
1973
|
}, renderContent(column, value, record, rowIndex, format)), selectedCells && selectedCells.size > 0 && getLastSelectCell(selectedCells).row === rowNumber && getLastSelectCell(selectedCells).col === colIndex && isEditable(column, record) && !isSelectDragging && rowIndex !== dataSource.length - 1 &&
|
|
@@ -1725,19 +2032,61 @@ const GridEdit = props => {
|
|
|
1725
2032
|
setMergedSelectedKeys(keys);
|
|
1726
2033
|
};
|
|
1727
2034
|
const contextMenuClick = args => {
|
|
1728
|
-
if (args.item.
|
|
1729
|
-
|
|
2035
|
+
if (args.item?.parentKey && args.item.parentKey === 'INSERT_BEFORE') {
|
|
2036
|
+
if (args.item.key === 'INSERT_BEFORE_ADV') {
|
|
2037
|
+
// mở Modal
|
|
2038
|
+
|
|
2039
|
+
setOpenModalAddRow(prev => ({
|
|
2040
|
+
...prev,
|
|
2041
|
+
open: true,
|
|
2042
|
+
type: 'INSERT_BEFORE'
|
|
2043
|
+
}));
|
|
2044
|
+
} else {
|
|
2045
|
+
handleInsertBefore(args.item, args.item.row);
|
|
2046
|
+
}
|
|
2047
|
+
return;
|
|
1730
2048
|
}
|
|
1731
|
-
if (args.item.
|
|
1732
|
-
|
|
2049
|
+
if (args.item?.parentKey && args.item.parentKey === 'INSERT_AFTER') {
|
|
2050
|
+
if (args.item.key === 'INSERT_AFTER_ADV') {
|
|
2051
|
+
setOpenModalAddRow(prev => ({
|
|
2052
|
+
...prev,
|
|
2053
|
+
open: true,
|
|
2054
|
+
type: 'INSERT_AFTER'
|
|
2055
|
+
}));
|
|
2056
|
+
} else {
|
|
2057
|
+
handleInsertAfter(args.item, args.item.row);
|
|
2058
|
+
}
|
|
2059
|
+
return;
|
|
1733
2060
|
}
|
|
1734
2061
|
if (args.item.key === 'DELETE_ROWS') {
|
|
1735
2062
|
handleDeleteRows(args.item);
|
|
2063
|
+
return;
|
|
1736
2064
|
}
|
|
1737
2065
|
if (args.item.key === 'DELETE_CONTENT') {
|
|
1738
2066
|
handleDeleteContent();
|
|
2067
|
+
return;
|
|
1739
2068
|
}
|
|
1740
2069
|
};
|
|
2070
|
+
const hideModalAddRow = () => {
|
|
2071
|
+
setOpenModalAddRow(prev => ({
|
|
2072
|
+
...prev,
|
|
2073
|
+
open: false,
|
|
2074
|
+
type: ''
|
|
2075
|
+
}));
|
|
2076
|
+
setRowsAdd(1);
|
|
2077
|
+
};
|
|
2078
|
+
const onOkAddRow = () => {
|
|
2079
|
+
if (openModalAddRow.type === 'INSERT_AFTER') {
|
|
2080
|
+
handleInsertAfter({}, rowsAdd);
|
|
2081
|
+
}
|
|
2082
|
+
if (openModalAddRow.type === 'INSERT_BEFORE') {
|
|
2083
|
+
handleInsertBefore({}, rowsAdd);
|
|
2084
|
+
}
|
|
2085
|
+
hideModalAddRow();
|
|
2086
|
+
};
|
|
2087
|
+
const onChangeRows = val => {
|
|
2088
|
+
setRowsAdd(val);
|
|
2089
|
+
};
|
|
1741
2090
|
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(GridStyle, {
|
|
1742
2091
|
heightTable: height,
|
|
1743
2092
|
style: {
|
|
@@ -1862,6 +2211,28 @@ const GridEdit = props => {
|
|
|
1862
2211
|
toastOptions: {
|
|
1863
2212
|
className: 'react-hot-toast'
|
|
1864
2213
|
}
|
|
1865
|
-
})
|
|
2214
|
+
}), /*#__PURE__*/React.createElement(Modal
|
|
2215
|
+
// title="Thêm dòng"
|
|
2216
|
+
, {
|
|
2217
|
+
open: openModalAddRow.open,
|
|
2218
|
+
onOk: onOkAddRow,
|
|
2219
|
+
onCancel: hideModalAddRow,
|
|
2220
|
+
okText: "Ok",
|
|
2221
|
+
cancelText: "H\u1EE7y",
|
|
2222
|
+
className: 'be-popup-container',
|
|
2223
|
+
centered: true,
|
|
2224
|
+
width: 250,
|
|
2225
|
+
closable: false
|
|
2226
|
+
}, /*#__PURE__*/React.createElement(InputNumber, {
|
|
2227
|
+
style: {
|
|
2228
|
+
width: '100%'
|
|
2229
|
+
},
|
|
2230
|
+
defaultValue: 1,
|
|
2231
|
+
value: rowsAdd,
|
|
2232
|
+
min: 1,
|
|
2233
|
+
max: 1000,
|
|
2234
|
+
onChange: onChangeRows,
|
|
2235
|
+
changeOnWheel: true
|
|
2236
|
+
})));
|
|
1866
2237
|
};
|
|
1867
2238
|
export default GridEdit;
|