es-grid-template 1.3.2 → 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 -17
- 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/number-range/index.d.ts +2 -1
- package/es/grid-component/number-range/index.js +21 -17
- package/es/grid-component/styles.scss +15 -0
- package/es/grid-component/table/GridEdit.js +577 -205
- package/es/grid-component/table/Group.js +8 -0
- 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 -16
- 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/number-range/index.d.ts +2 -1
- package/lib/grid-component/number-range/index.js +21 -17
- package/lib/grid-component/styles.scss +15 -0
- package/lib/grid-component/table/GridEdit.js +565 -201
- package/lib/grid-component/table/Group.js +8 -0
- package/lib/grid-component/type.d.ts +3 -0
- package/lib/grid-component/useContext.d.ts +2 -0
- package/package.json +109 -109
|
@@ -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,65 +800,55 @@ const GridEdit = props => {
|
|
|
713
800
|
document.removeEventListener("click", handleClickOutside);
|
|
714
801
|
};
|
|
715
802
|
}, []);
|
|
716
|
-
const handleMouseDown =
|
|
717
|
-
setEditingKey('')
|
|
803
|
+
const handleMouseDown = (record, row, col, e) => {
|
|
804
|
+
// setEditingKey('')
|
|
805
|
+
|
|
718
806
|
if (e.button === 2) {
|
|
719
807
|
e.stopPropagation();
|
|
720
808
|
return;
|
|
721
809
|
}
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
// e.stopPropagation()
|
|
729
|
-
// e.preventDefault()
|
|
730
|
-
} else {
|
|
731
|
-
// isSelecting.current = true;
|
|
732
|
-
// startCell.current = { row, col };
|
|
810
|
+
if (e.ctrlKey) {
|
|
811
|
+
isSelecting.current = true;
|
|
812
|
+
startCell.current = {
|
|
813
|
+
row,
|
|
814
|
+
col
|
|
815
|
+
};
|
|
733
816
|
|
|
734
|
-
//
|
|
735
|
-
|
|
817
|
+
// const cell: any = new Set([`${row}-${col}`])
|
|
818
|
+
|
|
819
|
+
// setCurrentCtrlCells(cell)
|
|
820
|
+
} else {
|
|
821
|
+
isSelecting.current = true;
|
|
822
|
+
startCell.current = {
|
|
736
823
|
row,
|
|
737
824
|
col
|
|
738
|
-
}
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
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
|
+
}
|
|
742
837
|
}
|
|
743
838
|
|
|
744
|
-
// setSelectIsDragging(true)
|
|
745
|
-
|
|
746
839
|
// isSelecting.current = true;
|
|
747
840
|
// startCell.current = { row, col };
|
|
748
841
|
//
|
|
749
|
-
// if (
|
|
750
|
-
//
|
|
842
|
+
// if (e.target.className === 'dragging-point') {
|
|
843
|
+
// // e.stopPropagation()
|
|
844
|
+
// // e.preventDefault()
|
|
845
|
+
// } else {
|
|
846
|
+
//
|
|
847
|
+
// setStartSelectedCell({row, col})
|
|
751
848
|
// setSelectedCells(new Set([`${row}-${col}`]));
|
|
752
849
|
// setRowsSelected(new Set())
|
|
753
850
|
// }
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
// const handlePointEnter = (e: any) => {
|
|
757
|
-
//
|
|
758
|
-
// if (e.button === 2) {
|
|
759
|
-
// e.stopPropagation()
|
|
760
|
-
// return
|
|
761
|
-
// }
|
|
762
|
-
//
|
|
763
|
-
// // setIsPasteDragging(true);
|
|
764
|
-
//
|
|
765
|
-
// };
|
|
766
|
-
|
|
767
|
-
// const handlePointLeave = () => {
|
|
768
|
-
//
|
|
769
|
-
// if (isPasteDragging && !isSelectDragging) {
|
|
770
|
-
// // setIsPasteDragging(false);
|
|
771
|
-
// }
|
|
772
|
-
//
|
|
773
|
-
// };
|
|
774
|
-
|
|
851
|
+
};
|
|
775
852
|
const triggerDragPaste = pastesArray => {
|
|
776
853
|
const mergedSet = new Set([...selectedCells, ...pastesArray]);
|
|
777
854
|
setSelectedCells(mergedSet);
|
|
@@ -871,18 +948,49 @@ const GridEdit = props => {
|
|
|
871
948
|
}
|
|
872
949
|
triggerDragPaste(newPasteCells);
|
|
873
950
|
};
|
|
874
|
-
|
|
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 => {
|
|
875
973
|
isSelecting.current = false;
|
|
876
974
|
startCell.current = null;
|
|
877
975
|
isSelectingRow.current = false;
|
|
878
976
|
rowStart.current = null;
|
|
879
977
|
setIsPasteDragging(false);
|
|
880
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
|
+
|
|
881
989
|
if (pasteCells.size > 0) {
|
|
882
990
|
triggerDragPaste(pasteCells);
|
|
883
991
|
}
|
|
884
992
|
};
|
|
885
|
-
const handleMouseEnter = (row, col) => {
|
|
993
|
+
const handleMouseEnter = (row, col, e) => {
|
|
886
994
|
if (!isSelecting.current || !startCell.current) {
|
|
887
995
|
return;
|
|
888
996
|
}
|
|
@@ -890,6 +998,18 @@ const GridEdit = props => {
|
|
|
890
998
|
row: startRow,
|
|
891
999
|
col: startCol
|
|
892
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
|
+
}
|
|
893
1013
|
if (!isPasteDragging) {
|
|
894
1014
|
// chọn vùng copy
|
|
895
1015
|
|
|
@@ -936,14 +1056,6 @@ const GridEdit = props => {
|
|
|
936
1056
|
if (row < colStart) {
|
|
937
1057
|
// kéo sang trái
|
|
938
1058
|
}
|
|
939
|
-
|
|
940
|
-
// const newPasteCells = new Set()
|
|
941
|
-
// for (let r = Math.min(startRow, row) + 1; r <= Math.max(startRow, row); r++) {
|
|
942
|
-
// for (let c = Math.min(colStart, col); c <= Math.max(colStart, colEnd); c++) {
|
|
943
|
-
// newPasteCells.add(`${r}-${c}`);
|
|
944
|
-
// }
|
|
945
|
-
// }
|
|
946
|
-
// setPasteCells(newPasteCells)
|
|
947
1059
|
}
|
|
948
1060
|
};
|
|
949
1061
|
const handleClickRowHeader = (row, col) => {
|
|
@@ -1074,22 +1186,17 @@ const GridEdit = props => {
|
|
|
1074
1186
|
e.clipboardData.setData("text/plain", copyText);
|
|
1075
1187
|
Message(t ? t('CopySuccessful') : 'Copy Successful');
|
|
1076
1188
|
};
|
|
1077
|
-
const
|
|
1078
|
-
|
|
1079
|
-
const pasteData = e.clipboardData.getData("text/plain").trim();
|
|
1080
|
-
|
|
1081
|
-
// Chuyển đổi dữ liệu từ clipboard thành mảng
|
|
1082
|
-
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);
|
|
1083
1191
|
if (!record?.parentId) {
|
|
1084
1192
|
// Cập nhật data mới
|
|
1085
1193
|
const newData = [...dataSource];
|
|
1086
1194
|
|
|
1087
|
-
//
|
|
1088
|
-
const indexRows = newData.findIndex(it => it[rowKey] === record[rowKey]);
|
|
1195
|
+
// const indexRows = newData.findIndex((it) => it[rowKey as any] === record[rowKey])
|
|
1089
1196
|
|
|
1090
1197
|
// Lấy vị trí bắt đầu
|
|
1091
1198
|
// const { row: startRow, col: startCol } = selectedCell;
|
|
1092
|
-
const startRow =
|
|
1199
|
+
const startRow = newData.findIndex(it => it[rowKey] === record[rowKey]);
|
|
1093
1200
|
const startCol = indexCol;
|
|
1094
1201
|
|
|
1095
1202
|
// const flattData = flattenArray(newData);
|
|
@@ -1188,6 +1295,167 @@ const GridEdit = props => {
|
|
|
1188
1295
|
triggerPaste?.(pastedRows, pastedColumnsArray, newDataSource);
|
|
1189
1296
|
}
|
|
1190
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
|
+
};
|
|
1191
1459
|
const onSubmit = formData => {
|
|
1192
1460
|
try {
|
|
1193
1461
|
// const record = (await form.validateFields()) as RecordType;
|
|
@@ -1213,7 +1481,10 @@ const GridEdit = props => {
|
|
|
1213
1481
|
newState,
|
|
1214
1482
|
prevState,
|
|
1215
1483
|
option,
|
|
1216
|
-
field
|
|
1484
|
+
field,
|
|
1485
|
+
indexCol,
|
|
1486
|
+
indexRow,
|
|
1487
|
+
key
|
|
1217
1488
|
} = args;
|
|
1218
1489
|
|
|
1219
1490
|
// const newRecord = getValues()
|
|
@@ -1231,26 +1502,26 @@ const GridEdit = props => {
|
|
|
1231
1502
|
if (onCellChange.length > 1) {
|
|
1232
1503
|
onCellChange({
|
|
1233
1504
|
field,
|
|
1234
|
-
indexCol
|
|
1505
|
+
indexCol,
|
|
1235
1506
|
type: 'onChange',
|
|
1236
1507
|
value: newState,
|
|
1237
1508
|
option,
|
|
1238
|
-
indexRow
|
|
1509
|
+
indexRow,
|
|
1239
1510
|
rowData: record,
|
|
1240
|
-
rowId:
|
|
1511
|
+
rowId: key,
|
|
1241
1512
|
rowsData: [],
|
|
1242
1513
|
sumValue: []
|
|
1243
1514
|
}, handleChangeCallback);
|
|
1244
1515
|
} else {
|
|
1245
1516
|
onCellChange({
|
|
1246
1517
|
field,
|
|
1247
|
-
indexCol
|
|
1518
|
+
indexCol,
|
|
1248
1519
|
type: 'onChange',
|
|
1249
1520
|
option,
|
|
1250
1521
|
value: newState,
|
|
1251
|
-
indexRow
|
|
1522
|
+
indexRow,
|
|
1252
1523
|
rowData: record,
|
|
1253
|
-
rowId:
|
|
1524
|
+
rowId: key,
|
|
1254
1525
|
rowsData: [],
|
|
1255
1526
|
sumValue: []
|
|
1256
1527
|
}, handleChangeCallback);
|
|
@@ -1359,7 +1630,7 @@ const GridEdit = props => {
|
|
|
1359
1630
|
});
|
|
1360
1631
|
}
|
|
1361
1632
|
};
|
|
1362
|
-
const handleFocusCell = (rowIndex, colIndex, col, scrollType, e) => {
|
|
1633
|
+
const handleFocusCell = (rowIndex, colIndex, col, scrollType, e, isTimeout) => {
|
|
1363
1634
|
const isEdit = editingKey !== '';
|
|
1364
1635
|
const cellEdit = document.querySelector(`.ui-rc-table-row .cell-editing[data-row-index="${rowIndex}"].cell-editing[data-col-index="${colIndex}"]`);
|
|
1365
1636
|
const cell = document.querySelector(`.ui-rc-table-row .cell-editable[data-row-index="${rowIndex}"].cell-editable[data-col-index="${colIndex}"]`);
|
|
@@ -1370,34 +1641,49 @@ const GridEdit = props => {
|
|
|
1370
1641
|
});
|
|
1371
1642
|
setSelectedCells(new Set([`${rowIndex}-${colIndex}`]));
|
|
1372
1643
|
};
|
|
1373
|
-
|
|
1374
|
-
if (
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1644
|
+
const focusNextCell = (editingCell, cellEditable) => {
|
|
1645
|
+
if (isEdit) {
|
|
1646
|
+
if (editingCell) {
|
|
1647
|
+
updateSelection();
|
|
1648
|
+
if (e?.key !== 'Tab') {
|
|
1649
|
+
editingCell.focus();
|
|
1650
|
+
}
|
|
1378
1651
|
}
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
scrollToCell(rowIndex, colIndex, cellEdit, 'horizontal');
|
|
1382
|
-
}
|
|
1383
|
-
if (scrollType === 'vertical' && cell) {
|
|
1384
|
-
setEditingKey('');
|
|
1385
|
-
updateSelection();
|
|
1386
|
-
scrollToCell(rowIndex, colIndex, cellEdit, 'vertical');
|
|
1387
|
-
if (e?.key !== 'Tab') {
|
|
1388
|
-
cell.focus();
|
|
1652
|
+
if (scrollType === 'horizontal' && editingCell) {
|
|
1653
|
+
scrollToCell(rowIndex, colIndex, editingCell, 'horizontal');
|
|
1389
1654
|
}
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
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);
|
|
1396
1672
|
}
|
|
1397
1673
|
}
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
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);
|
|
1401
1687
|
}
|
|
1402
1688
|
};
|
|
1403
1689
|
const getCellClass = (record, rowIndex, colIndex) => {
|
|
@@ -1420,25 +1706,22 @@ const GridEdit = props => {
|
|
|
1420
1706
|
const cellPasteSEnd = getLastSelectCell(pasteCells);
|
|
1421
1707
|
const isPasteBottom = pasteCells.size && cellPasteSEnd && rowIndex === Math.max(cellPasteStart.row, cellPasteSEnd.row);
|
|
1422
1708
|
if (!isSelected && !isPasteSelected) {
|
|
1423
|
-
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);
|
|
1424
1711
|
const isLeft = colIndex + 1 === Math.min(cellStart.col, cellEnd?.col);
|
|
1425
1712
|
const isRight = colIndex - 1 === Math.max(cellStart.col, cellEnd?.col);
|
|
1426
1713
|
const isPasteLeft = colIndex + 1 === Math.min(cellPasteStart.col, cellPasteSEnd?.col);
|
|
1427
1714
|
const isPasteRight = colIndex - 1 === Math.max(cellPasteStart.col, cellPasteSEnd?.col);
|
|
1428
|
-
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` : ''}` :
|
|
1429
|
-
// (isPasteLeftSelected || isPasteRightSelected) ? `${cellClass} ${isPasteLeft ? `cell-paste-border-left` : ''}` :
|
|
1430
|
-
|
|
1431
|
-
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;
|
|
1432
1716
|
}
|
|
1433
|
-
const isBottom =
|
|
1434
|
-
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);
|
|
1435
1722
|
const isLeft = colIndex === Math.min(cellStart.col, cellEnd?.col);
|
|
1436
1723
|
const isPasteRight = cellPasteSEnd && colIndex === Math.max(cellPasteStart.col, cellPasteSEnd.col);
|
|
1437
1724
|
const isPasteLeft = colIndex === Math.min(cellPasteStart.col, cellPasteSEnd?.col);
|
|
1438
|
-
|
|
1439
|
-
// return `${cellClass} ${isBottom ? `cell-border-bottom` : ''} ${isRight ? `cell-border-right` : '' } ${isBottom && isRight ? `cell-border-end` : '' }
|
|
1440
|
-
// 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` : '' }`
|
|
1441
|
-
|
|
1442
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` : ''}`;
|
|
1443
1726
|
};
|
|
1444
1727
|
const convertColumns = flatColumns2(columns).map((column, colIndex) => {
|
|
@@ -1499,79 +1782,97 @@ const GridEdit = props => {
|
|
|
1499
1782
|
onCell: (record, rowIndex) => {
|
|
1500
1783
|
const rowNumber = getRowNumber(dataSource, record[rowKey], rowKey);
|
|
1501
1784
|
return {
|
|
1502
|
-
// onKeyPress: () => {
|
|
1503
|
-
//
|
|
1504
|
-
// },
|
|
1505
|
-
|
|
1506
1785
|
onKeyDown: event => {
|
|
1507
1786
|
const key = getRowKey(record, dataSource.indexOf(record));
|
|
1508
|
-
if (event.key
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
const hasKey = mergedExpandedKeys.has(key);
|
|
1516
|
-
if (hasKey) {
|
|
1517
|
-
// mergedExpandedKeys.delete(key);
|
|
1518
|
-
// newExpandedKeys = [...mergedExpandedKeys];
|
|
1519
|
-
} else {
|
|
1520
|
-
onTriggerExpand(record);
|
|
1521
|
-
}
|
|
1522
|
-
} else {
|
|
1523
|
-
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 = ''
|
|
1524
1794
|
event.preventDefault();
|
|
1525
1795
|
event.stopPropagation();
|
|
1526
|
-
|
|
1527
|
-
|
|
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];
|
|
1528
1802
|
} else {
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
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
|
+
}
|
|
1538
1821
|
}
|
|
1539
1822
|
}
|
|
1540
1823
|
}
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
}
|
|
1549
|
-
}
|
|
1550
|
-
if (event.key === 'ArrowRight' && colIndex + 1 !== columns.length) {
|
|
1551
|
-
if (editingKey !== '') {} else {
|
|
1552
|
-
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
|
+
}
|
|
1553
1831
|
}
|
|
1554
|
-
|
|
1555
|
-
if (event.key === 'ArrowLeft' && colIndex > 0) {
|
|
1556
|
-
if (!column.dataIndex && !column.key || column.field === 'index' || column.field === '#' || column.dataIndex === 'index' || column.dataIndex === '#') {
|
|
1557
|
-
event.stopPropagation();
|
|
1558
|
-
event.preventDefault();
|
|
1559
|
-
} else {
|
|
1832
|
+
if (event.key === 'ArrowRight' && colIndex + 1 !== columns.length) {
|
|
1560
1833
|
if (editingKey !== '') {} else {
|
|
1561
|
-
handleFocusCell(rowNumber, colIndex
|
|
1834
|
+
handleFocusCell(rowNumber, colIndex + 1, column, 'horizontal', event);
|
|
1562
1835
|
}
|
|
1563
1836
|
}
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
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
|
+
}
|
|
1573
1867
|
}
|
|
1574
1868
|
},
|
|
1869
|
+
// onKeyUp: (event: any) => {
|
|
1870
|
+
// if (event.key === 'Control' && event.ctrlKey) {
|
|
1871
|
+
//
|
|
1872
|
+
// console.log('onKeyUp')
|
|
1873
|
+
// }
|
|
1874
|
+
// },
|
|
1875
|
+
|
|
1575
1876
|
onPaste: event => {
|
|
1576
1877
|
if (editingKey === '') {
|
|
1577
1878
|
handlePaste(record, colIndex, rowNumber, event);
|
|
@@ -1627,8 +1928,9 @@ const GridEdit = props => {
|
|
|
1627
1928
|
} : {}
|
|
1628
1929
|
};
|
|
1629
1930
|
},
|
|
1630
|
-
onHeaderCell: () => {
|
|
1931
|
+
onHeaderCell: (data, index) => {
|
|
1631
1932
|
return {
|
|
1933
|
+
...(column.onHeaderCell ? column.onHeaderCell?.(data, index) : {}),
|
|
1632
1934
|
onClick: () => {
|
|
1633
1935
|
handleClickColHeader(column, colIndex);
|
|
1634
1936
|
},
|
|
@@ -1654,12 +1956,18 @@ const GridEdit = props => {
|
|
|
1654
1956
|
return /*#__PURE__*/React.createElement("div", {
|
|
1655
1957
|
className: classNames('ui-rc_cell-content', {
|
|
1656
1958
|
// selected: selectedCells.has(`${record[rowKey]}-${colIndex}`)
|
|
1959
|
+
// selected: selectedCells.has(`${rowNumber}-${colIndex}`) || currentCtrlCells.has(`${rowNumber}-${colIndex}`) || mergedSets([selectedCells, ...ctrlCells]).has(`${rowNumber}-${colIndex}`),
|
|
1657
1960
|
selected: selectedCells.has(`${rowNumber}-${colIndex}`),
|
|
1658
1961
|
disable: !isEditable(column, record)
|
|
1659
1962
|
}),
|
|
1660
1963
|
onMouseDown: event => handleMouseDown(record, rowNumber, colIndex, event),
|
|
1661
|
-
onMouseEnter:
|
|
1964
|
+
onMouseEnter: event => handleMouseEnter(rowNumber, colIndex, event),
|
|
1662
1965
|
onMouseUp: handleMouseUp
|
|
1966
|
+
// onClick={(event) => {
|
|
1967
|
+
//
|
|
1968
|
+
// handleClickCell(event)
|
|
1969
|
+
//
|
|
1970
|
+
// }}
|
|
1663
1971
|
}, /*#__PURE__*/React.createElement("div", {
|
|
1664
1972
|
className: 'ui-rc_content'
|
|
1665
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 &&
|
|
@@ -1724,19 +2032,61 @@ const GridEdit = props => {
|
|
|
1724
2032
|
setMergedSelectedKeys(keys);
|
|
1725
2033
|
};
|
|
1726
2034
|
const contextMenuClick = args => {
|
|
1727
|
-
if (args.item.
|
|
1728
|
-
|
|
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;
|
|
1729
2048
|
}
|
|
1730
|
-
if (args.item.
|
|
1731
|
-
|
|
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;
|
|
1732
2060
|
}
|
|
1733
2061
|
if (args.item.key === 'DELETE_ROWS') {
|
|
1734
2062
|
handleDeleteRows(args.item);
|
|
2063
|
+
return;
|
|
1735
2064
|
}
|
|
1736
2065
|
if (args.item.key === 'DELETE_CONTENT') {
|
|
1737
2066
|
handleDeleteContent();
|
|
2067
|
+
return;
|
|
1738
2068
|
}
|
|
1739
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
|
+
};
|
|
1740
2090
|
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(GridStyle, {
|
|
1741
2091
|
heightTable: height,
|
|
1742
2092
|
style: {
|
|
@@ -1861,6 +2211,28 @@ const GridEdit = props => {
|
|
|
1861
2211
|
toastOptions: {
|
|
1862
2212
|
className: 'react-hot-toast'
|
|
1863
2213
|
}
|
|
1864
|
-
})
|
|
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
|
+
})));
|
|
1865
2237
|
};
|
|
1866
2238
|
export default GridEdit;
|