es-grid-template 1.3.3 → 1.3.5
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 +5 -8
- package/es/grid-component/hooks/columns/index.js +17 -16
- package/es/grid-component/hooks/content/HeaderContent.js +3 -1
- 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 +597 -209
- 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 +5 -8
- package/lib/grid-component/hooks/columns/index.js +16 -15
- package/lib/grid-component/hooks/content/HeaderContent.js +3 -1
- 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 +585 -205
- 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,66 +800,53 @@ const GridEdit = props => {
|
|
|
713
800
|
document.removeEventListener("click", handleClickOutside);
|
|
714
801
|
};
|
|
715
802
|
}, []);
|
|
716
|
-
const handleMouseDown =
|
|
717
|
-
// setEditingKey('')
|
|
718
|
-
|
|
803
|
+
const handleMouseDown = (record, row, col, e) => {
|
|
719
804
|
if (e.button === 2) {
|
|
720
805
|
e.stopPropagation();
|
|
721
806
|
return;
|
|
722
807
|
}
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
// e.stopPropagation()
|
|
730
|
-
// e.preventDefault()
|
|
731
|
-
} else {
|
|
732
|
-
// isSelecting.current = true;
|
|
733
|
-
// startCell.current = { row, col };
|
|
808
|
+
if (e.ctrlKey) {
|
|
809
|
+
isSelecting.current = true;
|
|
810
|
+
startCell.current = {
|
|
811
|
+
row,
|
|
812
|
+
col
|
|
813
|
+
};
|
|
734
814
|
|
|
735
|
-
//
|
|
736
|
-
|
|
815
|
+
// const cell: any = new Set([`${row}-${col}`])
|
|
816
|
+
|
|
817
|
+
// setCurrentCtrlCells(cell)
|
|
818
|
+
} else {
|
|
819
|
+
isSelecting.current = true;
|
|
820
|
+
startCell.current = {
|
|
737
821
|
row,
|
|
738
822
|
col
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
823
|
+
};
|
|
824
|
+
if (e.target.className === 'dragging-point') {
|
|
825
|
+
// e.stopPropagation()
|
|
826
|
+
// e.preventDefault()
|
|
827
|
+
} else {
|
|
828
|
+
setStartSelectedCell({
|
|
829
|
+
row,
|
|
830
|
+
col
|
|
831
|
+
});
|
|
832
|
+
setSelectedCells(new Set([`${row}-${col}`]));
|
|
833
|
+
setRowsSelected(new Set());
|
|
834
|
+
}
|
|
743
835
|
}
|
|
744
836
|
|
|
745
|
-
// setSelectIsDragging(true)
|
|
746
|
-
|
|
747
837
|
// isSelecting.current = true;
|
|
748
838
|
// startCell.current = { row, col };
|
|
749
839
|
//
|
|
750
|
-
// if (
|
|
751
|
-
//
|
|
840
|
+
// if (e.target.className === 'dragging-point') {
|
|
841
|
+
// // e.stopPropagation()
|
|
842
|
+
// // e.preventDefault()
|
|
843
|
+
// } else {
|
|
844
|
+
//
|
|
845
|
+
// setStartSelectedCell({row, col})
|
|
752
846
|
// setSelectedCells(new Set([`${row}-${col}`]));
|
|
753
847
|
// setRowsSelected(new Set())
|
|
754
848
|
// }
|
|
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
|
-
|
|
849
|
+
};
|
|
776
850
|
const triggerDragPaste = pastesArray => {
|
|
777
851
|
const mergedSet = new Set([...selectedCells, ...pastesArray]);
|
|
778
852
|
setSelectedCells(mergedSet);
|
|
@@ -872,18 +946,49 @@ const GridEdit = props => {
|
|
|
872
946
|
}
|
|
873
947
|
triggerDragPaste(newPasteCells);
|
|
874
948
|
};
|
|
875
|
-
|
|
949
|
+
|
|
950
|
+
// const handleClickCell = (e: any) => {
|
|
951
|
+
//
|
|
952
|
+
// if (e.ctrlKey) {
|
|
953
|
+
//
|
|
954
|
+
// const cell: any = new Set([`${row}-${col}`])
|
|
955
|
+
//
|
|
956
|
+
// const found = ctrlCells.find((s: any) => isEqualSet(s, cell));
|
|
957
|
+
//
|
|
958
|
+
// if (found) {
|
|
959
|
+
// const rs = ctrlCells.filter((s: any) => !isEqualSet(s, cell));
|
|
960
|
+
//
|
|
961
|
+
// setCtrlCells(rs)
|
|
962
|
+
//
|
|
963
|
+
// } else {
|
|
964
|
+
// setCtrlCells([...ctrlCells, cell])
|
|
965
|
+
// }
|
|
966
|
+
//
|
|
967
|
+
// }
|
|
968
|
+
// }
|
|
969
|
+
|
|
970
|
+
const handleMouseUp = e => {
|
|
876
971
|
isSelecting.current = false;
|
|
877
972
|
startCell.current = null;
|
|
878
973
|
isSelectingRow.current = false;
|
|
879
974
|
rowStart.current = null;
|
|
880
975
|
setIsPasteDragging(false);
|
|
881
976
|
setSelectIsDragging(false);
|
|
977
|
+
|
|
978
|
+
// setCurrentCtrlCells(new Set())
|
|
979
|
+
|
|
980
|
+
if (e.ctrlKey) {
|
|
981
|
+
|
|
982
|
+
// setCtrlCells([...ctrlCells, currentCtrlCells])
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
// nếu ctrlCell length > 0 thì set selectCells
|
|
986
|
+
|
|
882
987
|
if (pasteCells.size > 0) {
|
|
883
988
|
triggerDragPaste(pasteCells);
|
|
884
989
|
}
|
|
885
990
|
};
|
|
886
|
-
const handleMouseEnter = (row, col) => {
|
|
991
|
+
const handleMouseEnter = (row, col, e) => {
|
|
887
992
|
if (!isSelecting.current || !startCell.current) {
|
|
888
993
|
return;
|
|
889
994
|
}
|
|
@@ -891,6 +996,18 @@ const GridEdit = props => {
|
|
|
891
996
|
row: startRow,
|
|
892
997
|
col: startCol
|
|
893
998
|
} = startCell.current;
|
|
999
|
+
if (e.ctrlKey) {
|
|
1000
|
+
// const newCtrlCells = new Set();
|
|
1001
|
+
// for (let r = Math.min(startRow, row); r <= Math.max(startRow, row); r++) {
|
|
1002
|
+
// for (let c = Math.min(startCol, col); c <= Math.max(startCol, col); c++) {
|
|
1003
|
+
// newCtrlCells.add(`${r}-${c}`)
|
|
1004
|
+
// }
|
|
1005
|
+
// }
|
|
1006
|
+
|
|
1007
|
+
// setCurrentCtrlCells(newCtrlCells)
|
|
1008
|
+
|
|
1009
|
+
return;
|
|
1010
|
+
}
|
|
894
1011
|
if (!isPasteDragging) {
|
|
895
1012
|
// chọn vùng copy
|
|
896
1013
|
|
|
@@ -930,6 +1047,14 @@ const GridEdit = props => {
|
|
|
930
1047
|
}
|
|
931
1048
|
if (row < rowSelectedEnd) {
|
|
932
1049
|
// kéo lên trên
|
|
1050
|
+
|
|
1051
|
+
const rowSelectedStart = getFirstSelectCell(selectedCells).row;
|
|
1052
|
+
const newPasteCells = new Set();
|
|
1053
|
+
for (let r = Math.min(rowSelectedStart, row); r <= Math.max(rowSelectedStart, row) - 1; r++) {
|
|
1054
|
+
for (let c = Math.min(colStart, col); c <= Math.max(colStart, colEnd); c++) {
|
|
1055
|
+
newPasteCells.add(`${r}-${c}`);
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
933
1058
|
}
|
|
934
1059
|
if (col > colEnd) {
|
|
935
1060
|
// kéo sang phải
|
|
@@ -937,14 +1062,6 @@ const GridEdit = props => {
|
|
|
937
1062
|
if (row < colStart) {
|
|
938
1063
|
// kéo sang trái
|
|
939
1064
|
}
|
|
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
1065
|
}
|
|
949
1066
|
};
|
|
950
1067
|
const handleClickRowHeader = (row, col) => {
|
|
@@ -1042,7 +1159,7 @@ const GridEdit = props => {
|
|
|
1042
1159
|
return {
|
|
1043
1160
|
row,
|
|
1044
1161
|
col,
|
|
1045
|
-
value: flattenData(childrenColumnName, dataSource)[row][columnKey]
|
|
1162
|
+
value: flattenData(childrenColumnName, dataSource)[row][columnKey] ?? ''
|
|
1046
1163
|
};
|
|
1047
1164
|
// return { row, col, value: '' };
|
|
1048
1165
|
});
|
|
@@ -1075,22 +1192,17 @@ const GridEdit = props => {
|
|
|
1075
1192
|
e.clipboardData.setData("text/plain", copyText);
|
|
1076
1193
|
Message(t ? t('CopySuccessful') : 'Copy Successful');
|
|
1077
1194
|
};
|
|
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"));
|
|
1195
|
+
const handlePasted = (record, indexCol, rowNumber, pasteData) => {
|
|
1196
|
+
const rows = pasteData.slice(0, onCellPaste?.maxRowsPaste ?? 200);
|
|
1084
1197
|
if (!record?.parentId) {
|
|
1085
1198
|
// Cập nhật data mới
|
|
1086
1199
|
const newData = [...dataSource];
|
|
1087
1200
|
|
|
1088
|
-
//
|
|
1089
|
-
const indexRows = newData.findIndex(it => it[rowKey] === record[rowKey]);
|
|
1201
|
+
// const indexRows = newData.findIndex((it) => it[rowKey as any] === record[rowKey])
|
|
1090
1202
|
|
|
1091
1203
|
// Lấy vị trí bắt đầu
|
|
1092
1204
|
// const { row: startRow, col: startCol } = selectedCell;
|
|
1093
|
-
const startRow =
|
|
1205
|
+
const startRow = newData.findIndex(it => it[rowKey] === record[rowKey]);
|
|
1094
1206
|
const startCol = indexCol;
|
|
1095
1207
|
|
|
1096
1208
|
// const flattData = flattenArray(newData);
|
|
@@ -1189,6 +1301,167 @@ const GridEdit = props => {
|
|
|
1189
1301
|
triggerPaste?.(pastedRows, pastedColumnsArray, newDataSource);
|
|
1190
1302
|
}
|
|
1191
1303
|
};
|
|
1304
|
+
const handlePaste = (record, indexCol, rowNumber, e) => {
|
|
1305
|
+
// const clipboard: any = (e.clipboardData || (window && window?.Clipboard)).getData("text")
|
|
1306
|
+
const pasteData = e.clipboardData.getData("text/plain");
|
|
1307
|
+
|
|
1308
|
+
// Chuyển đổi dữ liệu từ clipboard thành mảng
|
|
1309
|
+
const rowsPasted = pasteData.split("\n").map(row =>
|
|
1310
|
+
// const rows = pasteData.split("\n").map((row: any) =>
|
|
1311
|
+
row.replace(/\r/g, "").split("\t"));
|
|
1312
|
+
if (rowsPasted.length > (onCellPaste?.maxRowsPaste ?? 200)) {
|
|
1313
|
+
// bật popup thông báo
|
|
1314
|
+
|
|
1315
|
+
Modal.confirm({
|
|
1316
|
+
content: /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Paragraph, {
|
|
1317
|
+
style: {
|
|
1318
|
+
marginBottom: '.25rem',
|
|
1319
|
+
fontSize: 14
|
|
1320
|
+
}
|
|
1321
|
+
}, "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, {
|
|
1322
|
+
level: 5,
|
|
1323
|
+
style: {
|
|
1324
|
+
marginTop: '.75rem'
|
|
1325
|
+
}
|
|
1326
|
+
}, "B\u1EA1n c\xF3 mu\u1ED1n ti\u1EBFp t\u1EE5c sao ch\xE9p kh\xF4ng?")),
|
|
1327
|
+
centered: true,
|
|
1328
|
+
className: 'be-popup-container',
|
|
1329
|
+
onOk: () => {
|
|
1330
|
+
handlePasted(record, indexCol, rowNumber, rowsPasted);
|
|
1331
|
+
}
|
|
1332
|
+
// footer: (_, { OkBtn, CancelBtn }) => (
|
|
1333
|
+
// <>
|
|
1334
|
+
// <OkBtn />
|
|
1335
|
+
// <CancelBtn />
|
|
1336
|
+
// </>
|
|
1337
|
+
// ),
|
|
1338
|
+
});
|
|
1339
|
+
} else {
|
|
1340
|
+
handlePasted(record, indexCol, rowNumber, rowsPasted);
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
// const rows = rowsPasted.slice(0, (onCellPaste?.maxRowsPaste ?? 200));
|
|
1344
|
+
//
|
|
1345
|
+
//
|
|
1346
|
+
// if (!record?.parentId ) {
|
|
1347
|
+
//
|
|
1348
|
+
// // Cập nhật data mới
|
|
1349
|
+
// const newData = [...dataSource];
|
|
1350
|
+
//
|
|
1351
|
+
// // @ts-ignore
|
|
1352
|
+
// const indexRows = newData.findIndex((it) => it[rowKey] === record[rowKey])
|
|
1353
|
+
//
|
|
1354
|
+
// // Lấy vị trí bắt đầu
|
|
1355
|
+
// // const { row: startRow, col: startCol } = selectedCell;
|
|
1356
|
+
// const startRow = indexRows
|
|
1357
|
+
// const startCol = indexCol
|
|
1358
|
+
//
|
|
1359
|
+
//
|
|
1360
|
+
//
|
|
1361
|
+
// // const flattData = flattenArray(newData);
|
|
1362
|
+
//
|
|
1363
|
+
// const pastedRows: RecordType[] = [];
|
|
1364
|
+
// const pastedColumns = new Set()
|
|
1365
|
+
//
|
|
1366
|
+
//
|
|
1367
|
+
// rows.forEach((rowValues: any, rowIndex: any) => {
|
|
1368
|
+
// const targetRow = startRow + rowIndex;
|
|
1369
|
+
//
|
|
1370
|
+
// // Nếu vượt quá số dòng hiện có, thêm dòng mới
|
|
1371
|
+
// if (targetRow >= newData.length) {
|
|
1372
|
+
// // @ts-ignore
|
|
1373
|
+
// // newData.push({ id: newGuid()});
|
|
1374
|
+
// newData.push({ id: undefined, rowId: newGuid()});
|
|
1375
|
+
// }
|
|
1376
|
+
//
|
|
1377
|
+
// rowValues.forEach((cellValue: any, colIndex: any) => {
|
|
1378
|
+
// const targetCol = startCol + colIndex;
|
|
1379
|
+
// if (targetCol >= columns.length) { // Không vượt quá số cột
|
|
1380
|
+
// return
|
|
1381
|
+
// }
|
|
1382
|
+
//
|
|
1383
|
+
// if (columns[targetCol].editEnable) {
|
|
1384
|
+
// // @ts-ignore
|
|
1385
|
+
// const columnKey = columns[targetCol].field;
|
|
1386
|
+
//
|
|
1387
|
+
// // @ts-ignore
|
|
1388
|
+
// newData[targetRow] = { ...newData[targetRow], [columnKey]: cellValue.trim() };
|
|
1389
|
+
// pastedColumns.add(columnKey);
|
|
1390
|
+
// }
|
|
1391
|
+
//
|
|
1392
|
+
// });
|
|
1393
|
+
//
|
|
1394
|
+
// // Lưu dòng được paste
|
|
1395
|
+
// pastedRows.push(newData[targetRow]);
|
|
1396
|
+
//
|
|
1397
|
+
// });
|
|
1398
|
+
//
|
|
1399
|
+
// const pastedColumnsArray = Array.from(pastedColumns) ?? [];
|
|
1400
|
+
//
|
|
1401
|
+
// triggerPaste?.(pastedRows, pastedColumnsArray as string[], newData)
|
|
1402
|
+
//
|
|
1403
|
+
//
|
|
1404
|
+
// } else {
|
|
1405
|
+
//
|
|
1406
|
+
// // Cập nhật data mới
|
|
1407
|
+
// const newData = [...dataSource];
|
|
1408
|
+
//
|
|
1409
|
+
// const parent = findItemByKey(newData, rowKey as any, record.parentId)
|
|
1410
|
+
//
|
|
1411
|
+
// // Cập nhật childData mới
|
|
1412
|
+
// const childData: any[] = parent?.children ? [...parent.children] : []
|
|
1413
|
+
//
|
|
1414
|
+
//
|
|
1415
|
+
// // Lấy vị trí bắt đầu
|
|
1416
|
+
// // const { row: startRow, col: startCol } = selectedCell;
|
|
1417
|
+
// const startRow = childData.findIndex((it) => it[rowKey] === record[rowKey])
|
|
1418
|
+
// const startCol = indexCol
|
|
1419
|
+
//
|
|
1420
|
+
// const pastedRows: RecordType[] = []
|
|
1421
|
+
// const pastedColumns = new Set()
|
|
1422
|
+
//
|
|
1423
|
+
//
|
|
1424
|
+
// rows.forEach((rowValues: any, rowIndex: any) => {
|
|
1425
|
+
// const targetRow = startRow + rowIndex
|
|
1426
|
+
//
|
|
1427
|
+
// // Nếu vượt quá số dòng hiện có, thêm dòng mới
|
|
1428
|
+
// if (targetRow >= childData.length) {
|
|
1429
|
+
//
|
|
1430
|
+
// childData.push({ id: undefined, rowId: newGuid(), parentId: parent[rowKey ?? 'id']})
|
|
1431
|
+
// }
|
|
1432
|
+
//
|
|
1433
|
+
// rowValues.forEach((cellValue: any, colIndex: any) => {
|
|
1434
|
+
// const targetCol = startCol + colIndex
|
|
1435
|
+
// if (targetCol >= columns.length) { // Không vượt quá số cột
|
|
1436
|
+
// return
|
|
1437
|
+
// }
|
|
1438
|
+
//
|
|
1439
|
+
// if (columns[targetCol].editEnable) {
|
|
1440
|
+
//
|
|
1441
|
+
// // @ts-ignore
|
|
1442
|
+
// const columnKey = columns[targetCol].field
|
|
1443
|
+
//
|
|
1444
|
+
// // @ts-ignore
|
|
1445
|
+
// childData[targetRow] = { ...childData[targetRow], [columnKey]: cellValue.trim() }
|
|
1446
|
+
// pastedColumns.add(columnKey)
|
|
1447
|
+
// }
|
|
1448
|
+
//
|
|
1449
|
+
// })
|
|
1450
|
+
//
|
|
1451
|
+
// // Lưu dòng được paste
|
|
1452
|
+
// pastedRows.push(childData[targetRow])
|
|
1453
|
+
//
|
|
1454
|
+
// })
|
|
1455
|
+
//
|
|
1456
|
+
// const pastedColumnsArray = Array.from(pastedColumns) ?? []
|
|
1457
|
+
//
|
|
1458
|
+
// const newRowData = {...parent, children: childData}
|
|
1459
|
+
//
|
|
1460
|
+
// const newDataSource = updateArrayByKey(newData, newRowData, rowKey as string)
|
|
1461
|
+
//
|
|
1462
|
+
// triggerPaste?.(pastedRows, pastedColumnsArray as string[], newDataSource )
|
|
1463
|
+
// }
|
|
1464
|
+
};
|
|
1192
1465
|
const onSubmit = formData => {
|
|
1193
1466
|
try {
|
|
1194
1467
|
// const record = (await form.validateFields()) as RecordType;
|
|
@@ -1214,7 +1487,10 @@ const GridEdit = props => {
|
|
|
1214
1487
|
newState,
|
|
1215
1488
|
prevState,
|
|
1216
1489
|
option,
|
|
1217
|
-
field
|
|
1490
|
+
field,
|
|
1491
|
+
indexCol,
|
|
1492
|
+
indexRow,
|
|
1493
|
+
key
|
|
1218
1494
|
} = args;
|
|
1219
1495
|
|
|
1220
1496
|
// const newRecord = getValues()
|
|
@@ -1232,26 +1508,26 @@ const GridEdit = props => {
|
|
|
1232
1508
|
if (onCellChange.length > 1) {
|
|
1233
1509
|
onCellChange({
|
|
1234
1510
|
field,
|
|
1235
|
-
indexCol
|
|
1511
|
+
indexCol,
|
|
1236
1512
|
type: 'onChange',
|
|
1237
1513
|
value: newState,
|
|
1238
1514
|
option,
|
|
1239
|
-
indexRow
|
|
1515
|
+
indexRow,
|
|
1240
1516
|
rowData: record,
|
|
1241
|
-
rowId:
|
|
1517
|
+
rowId: key,
|
|
1242
1518
|
rowsData: [],
|
|
1243
1519
|
sumValue: []
|
|
1244
1520
|
}, handleChangeCallback);
|
|
1245
1521
|
} else {
|
|
1246
1522
|
onCellChange({
|
|
1247
1523
|
field,
|
|
1248
|
-
indexCol
|
|
1524
|
+
indexCol,
|
|
1249
1525
|
type: 'onChange',
|
|
1250
1526
|
option,
|
|
1251
1527
|
value: newState,
|
|
1252
|
-
indexRow
|
|
1528
|
+
indexRow,
|
|
1253
1529
|
rowData: record,
|
|
1254
|
-
rowId:
|
|
1530
|
+
rowId: key,
|
|
1255
1531
|
rowsData: [],
|
|
1256
1532
|
sumValue: []
|
|
1257
1533
|
}, handleChangeCallback);
|
|
@@ -1360,7 +1636,7 @@ const GridEdit = props => {
|
|
|
1360
1636
|
});
|
|
1361
1637
|
}
|
|
1362
1638
|
};
|
|
1363
|
-
const handleFocusCell = (rowIndex, colIndex, col, scrollType, e) => {
|
|
1639
|
+
const handleFocusCell = (rowIndex, colIndex, col, scrollType, e, isTimeout) => {
|
|
1364
1640
|
const isEdit = editingKey !== '';
|
|
1365
1641
|
const cellEdit = document.querySelector(`.ui-rc-table-row .cell-editing[data-row-index="${rowIndex}"].cell-editing[data-col-index="${colIndex}"]`);
|
|
1366
1642
|
const cell = document.querySelector(`.ui-rc-table-row .cell-editable[data-row-index="${rowIndex}"].cell-editable[data-col-index="${colIndex}"]`);
|
|
@@ -1371,34 +1647,49 @@ const GridEdit = props => {
|
|
|
1371
1647
|
});
|
|
1372
1648
|
setSelectedCells(new Set([`${rowIndex}-${colIndex}`]));
|
|
1373
1649
|
};
|
|
1374
|
-
|
|
1375
|
-
if (
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1650
|
+
const focusNextCell = (editingCell, cellEditable) => {
|
|
1651
|
+
if (isEdit) {
|
|
1652
|
+
if (editingCell) {
|
|
1653
|
+
updateSelection();
|
|
1654
|
+
if (e?.key !== 'Tab') {
|
|
1655
|
+
editingCell.focus();
|
|
1656
|
+
}
|
|
1379
1657
|
}
|
|
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();
|
|
1658
|
+
if (scrollType === 'horizontal' && editingCell) {
|
|
1659
|
+
scrollToCell(rowIndex, colIndex, editingCell, 'horizontal');
|
|
1390
1660
|
}
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1661
|
+
if (scrollType === 'vertical' && cellEditable) {
|
|
1662
|
+
setEditingKey('');
|
|
1663
|
+
updateSelection();
|
|
1664
|
+
scrollToCell(rowIndex, colIndex, cellEdit, 'vertical');
|
|
1665
|
+
if (e?.key !== 'Tab') {
|
|
1666
|
+
cellEditable.focus();
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
} else {
|
|
1670
|
+
if (cellEditable) {
|
|
1671
|
+
updateSelection();
|
|
1672
|
+
if (e?.key !== 'Tab') {
|
|
1673
|
+
cellEditable.focus();
|
|
1674
|
+
}
|
|
1675
|
+
}
|
|
1676
|
+
if (cellEditable) {
|
|
1677
|
+
scrollToCell(rowIndex, colIndex, cellEditable, scrollType);
|
|
1397
1678
|
}
|
|
1398
1679
|
}
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1680
|
+
};
|
|
1681
|
+
if (isTimeout) {
|
|
1682
|
+
let cellEdit1 = undefined;
|
|
1683
|
+
let cell1 = undefined;
|
|
1684
|
+
setTimeout(() => {
|
|
1685
|
+
cellEdit1 = document.querySelector(`.ui-rc-table-row .cell-editing[data-row-index="${rowIndex}"].cell-editing[data-col-index="${colIndex}"]`);
|
|
1686
|
+
cell1 = document.querySelector(`.ui-rc-table-row .cell-editable[data-row-index="${rowIndex}"].cell-editable[data-col-index="${colIndex}"]`);
|
|
1687
|
+
}, 20);
|
|
1688
|
+
setTimeout(() => {
|
|
1689
|
+
focusNextCell(cellEdit1, cell1);
|
|
1690
|
+
}, 50);
|
|
1691
|
+
} else {
|
|
1692
|
+
focusNextCell(cellEdit, cell);
|
|
1402
1693
|
}
|
|
1403
1694
|
};
|
|
1404
1695
|
const getCellClass = (record, rowIndex, colIndex) => {
|
|
@@ -1421,28 +1712,25 @@ const GridEdit = props => {
|
|
|
1421
1712
|
const cellPasteSEnd = getLastSelectCell(pasteCells);
|
|
1422
1713
|
const isPasteBottom = pasteCells.size && cellPasteSEnd && rowIndex === Math.max(cellPasteStart.row, cellPasteSEnd.row);
|
|
1423
1714
|
if (!isSelected && !isPasteSelected) {
|
|
1424
|
-
const isTop = prevRecordEditing && !isEditing(prevRecordEditing) && rowIndex === Math.min(cellStart.row - 1, cellEnd?.row);
|
|
1715
|
+
// const isTop = prevRecordEditing && !isEditing(prevRecordEditing) && rowIndex === Math.min(cellStart.row - 1, cellEnd?.row);
|
|
1716
|
+
const isTop = prevRecordEditing && !isEditing(prevRecordEditing) && isTopMostInRegion(rowIndex + 1, colIndex, selectedCells);
|
|
1425
1717
|
const isLeft = colIndex + 1 === Math.min(cellStart.col, cellEnd?.col);
|
|
1426
1718
|
const isRight = colIndex - 1 === Math.max(cellStart.col, cellEnd?.col);
|
|
1427
1719
|
const isPasteLeft = colIndex + 1 === Math.min(cellPasteStart.col, cellPasteSEnd?.col);
|
|
1428
1720
|
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;
|
|
1721
|
+
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
1722
|
}
|
|
1434
|
-
const isBottom =
|
|
1435
|
-
const
|
|
1723
|
+
const isBottom = isBottomMostInRegion(rowIndex, colIndex, selectedCells);
|
|
1724
|
+
// const isBottom = isBottomMostInRanges(rowIndex, colIndex, [selectedCells, ...ctrlCells])
|
|
1725
|
+
|
|
1726
|
+
// const isRight = cellEnd && colIndex === Math.max(cellStart.col, cellEnd.col)
|
|
1727
|
+
const isRight = isRightMostInRegion(rowIndex, colIndex, selectedCells);
|
|
1436
1728
|
const isLeft = colIndex === Math.min(cellStart.col, cellEnd?.col);
|
|
1437
1729
|
const isPasteRight = cellPasteSEnd && colIndex === Math.max(cellPasteStart.col, cellPasteSEnd.col);
|
|
1438
1730
|
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
1731
|
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
1732
|
};
|
|
1445
|
-
const convertColumns = flatColumns2(columns).map((column, colIndex) => {
|
|
1733
|
+
const convertColumns = flatColumns2(columns.filter(it => it.visible !== false)).map((column, colIndex) => {
|
|
1446
1734
|
if (!column?.field && !column?.key) {
|
|
1447
1735
|
return column;
|
|
1448
1736
|
}
|
|
@@ -1500,79 +1788,97 @@ const GridEdit = props => {
|
|
|
1500
1788
|
onCell: (record, rowIndex) => {
|
|
1501
1789
|
const rowNumber = getRowNumber(dataSource, record[rowKey], rowKey);
|
|
1502
1790
|
return {
|
|
1503
|
-
// onKeyPress: () => {
|
|
1504
|
-
//
|
|
1505
|
-
// },
|
|
1506
|
-
|
|
1507
1791
|
onKeyDown: event => {
|
|
1508
1792
|
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') {
|
|
1793
|
+
if (event.key === 'Control' && event.ctrlKey) {
|
|
1794
|
+
|
|
1795
|
+
// setIsCtrlDown(true)
|
|
1796
|
+
} else {
|
|
1797
|
+
if (event.key.length === 1 && !event.ctrlKey && !event.metaKey || event.key === 'Enter') {
|
|
1798
|
+
if (record[rowKey] !== editingKey && isEditable(column, record)) {
|
|
1799
|
+
// ~~ khi editingKey = ''
|
|
1525
1800
|
event.preventDefault();
|
|
1526
1801
|
event.stopPropagation();
|
|
1527
|
-
|
|
1528
|
-
|
|
1802
|
+
handleEdit(record, column, column.editType, event);
|
|
1803
|
+
handleCellClick(rowNumber, record, column);
|
|
1804
|
+
const hasKey = mergedExpandedKeys.has(key);
|
|
1805
|
+
if (hasKey) {
|
|
1806
|
+
// mergedExpandedKeys.delete(key);
|
|
1807
|
+
// newExpandedKeys = [...mergedExpandedKeys];
|
|
1529
1808
|
} else {
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1809
|
+
onTriggerExpand(record);
|
|
1810
|
+
}
|
|
1811
|
+
} else {
|
|
1812
|
+
if (event.key === 'Enter') {
|
|
1813
|
+
event.preventDefault();
|
|
1814
|
+
event.stopPropagation();
|
|
1815
|
+
if (editingKey && editingKey !== '' && (rowNumber ?? 0) + 1 < flattenArray(dataSource).length && event.key === 'Enter') {
|
|
1816
|
+
handleFocusCell((rowNumber ?? 0) + 1, colIndex, column, 'vertical', event);
|
|
1817
|
+
} else {
|
|
1818
|
+
// // focus cell hiện tại và tắt edit
|
|
1819
|
+
// handleFocusCell((rowNumber ?? 0), colIndex, column, 'vertical', event)
|
|
1820
|
+
// setEditingKey('')
|
|
1821
|
+
|
|
1822
|
+
// thêm dòng mới
|
|
1823
|
+
|
|
1824
|
+
handleAddSingle();
|
|
1825
|
+
handleFocusCell((rowNumber ?? 0) + 1, colIndex, column, 'vertical', event, true);
|
|
1826
|
+
}
|
|
1539
1827
|
}
|
|
1540
1828
|
}
|
|
1541
1829
|
}
|
|
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);
|
|
1830
|
+
if (event.key === 'Tab') {
|
|
1831
|
+
if (colIndex + 1 !== columns.length) {
|
|
1832
|
+
handleFocusCell(rowNumber, colIndex + 1, column, 'horizontal', event);
|
|
1833
|
+
} else {
|
|
1834
|
+
event.stopPropagation();
|
|
1835
|
+
event.preventDefault();
|
|
1836
|
+
}
|
|
1554
1837
|
}
|
|
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 {
|
|
1838
|
+
if (event.key === 'ArrowRight' && colIndex + 1 !== columns.length) {
|
|
1561
1839
|
if (editingKey !== '') {} else {
|
|
1562
|
-
handleFocusCell(rowNumber, colIndex
|
|
1840
|
+
handleFocusCell(rowNumber, colIndex + 1, column, 'horizontal', event);
|
|
1563
1841
|
}
|
|
1564
1842
|
}
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1843
|
+
if (event.key === 'ArrowLeft' && colIndex > 0) {
|
|
1844
|
+
if (!column.dataIndex && !column.key || column.field === 'index' || column.field === '#' || column.dataIndex === 'index' || column.dataIndex === '#') {
|
|
1845
|
+
event.stopPropagation();
|
|
1846
|
+
event.preventDefault();
|
|
1847
|
+
} else {
|
|
1848
|
+
if (editingKey !== '') {} else {
|
|
1849
|
+
handleFocusCell(rowNumber, colIndex - 1, column, 'horizontal', event);
|
|
1850
|
+
}
|
|
1851
|
+
}
|
|
1852
|
+
}
|
|
1853
|
+
if (event.key === 'ArrowDown' && (rowNumber ?? 0) + 1 < flattenArray(dataSource).length) {
|
|
1854
|
+
if (isEditing(record) && (getEditType(column, record) === 'treeSelect' || getEditType(column, record) === 'select' || getEditType(column, record) === 'selectTable' || getEditType(column, record) === 'asyncSelect')) {
|
|
1855
|
+
event.stopPropagation();
|
|
1856
|
+
} else {
|
|
1857
|
+
handleFocusCell((rowNumber ?? 0) + 1, colIndex, column, 'vertical', event);
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
if (event.key === 'ArrowUp' && (rowNumber ?? 0) > 0) {
|
|
1861
|
+
if (isEditing(record) && (getEditType(column, record) === 'asyncSelect' || getEditType(column, record) === 'select' || getEditType(column, record) === 'selectTable' || getEditType(column, record) === 'treeSelect')) {
|
|
1862
|
+
event.stopPropagation();
|
|
1863
|
+
} else {
|
|
1864
|
+
handleFocusCell((rowNumber ?? 0) - 1, colIndex, column, 'vertical', event);
|
|
1865
|
+
}
|
|
1866
|
+
}
|
|
1867
|
+
if (event.key === 'Delete') {
|
|
1868
|
+
handleDeleteContent();
|
|
1869
|
+
}
|
|
1870
|
+
if (event.key === 'Escape') {
|
|
1871
|
+
setEditingKey('');
|
|
1872
|
+
}
|
|
1574
1873
|
}
|
|
1575
1874
|
},
|
|
1875
|
+
// onKeyUp: (event: any) => {
|
|
1876
|
+
// if (event.key === 'Control' && event.ctrlKey) {
|
|
1877
|
+
//
|
|
1878
|
+
// console.log('onKeyUp')
|
|
1879
|
+
// }
|
|
1880
|
+
// },
|
|
1881
|
+
|
|
1576
1882
|
onPaste: event => {
|
|
1577
1883
|
if (editingKey === '') {
|
|
1578
1884
|
handlePaste(record, colIndex, rowNumber, event);
|
|
@@ -1618,6 +1924,10 @@ const GridEdit = props => {
|
|
|
1618
1924
|
title: getValueCell(column, record[column.field], format),
|
|
1619
1925
|
'data-col-index': colIndex,
|
|
1620
1926
|
'data-row-index': rowNumber,
|
|
1927
|
+
// 'data-tooltip-id': "tooltip-cell-content",
|
|
1928
|
+
// 'data-tooltip-content': 'tooltip-cell-content',
|
|
1929
|
+
// 'data-tooltip-delay-show': 1000,
|
|
1930
|
+
// 'data-tooltip-content': getValueCell(column, record[column.field as any], format),
|
|
1621
1931
|
editing: isEditing(record) && rowEditable?.(record) !== false && isEditable(column, record),
|
|
1622
1932
|
cellEditing,
|
|
1623
1933
|
t,
|
|
@@ -1628,8 +1938,9 @@ const GridEdit = props => {
|
|
|
1628
1938
|
} : {}
|
|
1629
1939
|
};
|
|
1630
1940
|
},
|
|
1631
|
-
onHeaderCell: () => {
|
|
1941
|
+
onHeaderCell: (data, index) => {
|
|
1632
1942
|
return {
|
|
1943
|
+
...(column.onHeaderCell ? column.onHeaderCell?.(data, index) : {}),
|
|
1633
1944
|
onClick: () => {
|
|
1634
1945
|
handleClickColHeader(column, colIndex);
|
|
1635
1946
|
},
|
|
@@ -1655,12 +1966,18 @@ const GridEdit = props => {
|
|
|
1655
1966
|
return /*#__PURE__*/React.createElement("div", {
|
|
1656
1967
|
className: classNames('ui-rc_cell-content', {
|
|
1657
1968
|
// selected: selectedCells.has(`${record[rowKey]}-${colIndex}`)
|
|
1969
|
+
// selected: selectedCells.has(`${rowNumber}-${colIndex}`) || currentCtrlCells.has(`${rowNumber}-${colIndex}`) || mergedSets([selectedCells, ...ctrlCells]).has(`${rowNumber}-${colIndex}`),
|
|
1658
1970
|
selected: selectedCells.has(`${rowNumber}-${colIndex}`),
|
|
1659
1971
|
disable: !isEditable(column, record)
|
|
1660
1972
|
}),
|
|
1661
1973
|
onMouseDown: event => handleMouseDown(record, rowNumber, colIndex, event),
|
|
1662
|
-
onMouseEnter:
|
|
1974
|
+
onMouseEnter: event => handleMouseEnter(rowNumber, colIndex, event),
|
|
1663
1975
|
onMouseUp: handleMouseUp
|
|
1976
|
+
// onClick={(event) => {
|
|
1977
|
+
//
|
|
1978
|
+
// handleClickCell(event)
|
|
1979
|
+
//
|
|
1980
|
+
// }}
|
|
1664
1981
|
}, /*#__PURE__*/React.createElement("div", {
|
|
1665
1982
|
className: 'ui-rc_content'
|
|
1666
1983
|
}, 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 &&
|
|
@@ -1671,7 +1988,9 @@ const GridEdit = props => {
|
|
|
1671
1988
|
// onMouseEnter={(event) => handlePointEnter(event)}
|
|
1672
1989
|
// onMouseLeave={() => handlePointLeave()}
|
|
1673
1990
|
,
|
|
1674
|
-
onMouseDown:
|
|
1991
|
+
onMouseDown: e => {
|
|
1992
|
+
// e.stopPropagation()
|
|
1993
|
+
// e.preventDefault()
|
|
1675
1994
|
setIsPasteDragging(true);
|
|
1676
1995
|
},
|
|
1677
1996
|
onDoubleClick: handlePointDoubleClick
|
|
@@ -1693,6 +2012,11 @@ const GridEdit = props => {
|
|
|
1693
2012
|
...find
|
|
1694
2013
|
};
|
|
1695
2014
|
}
|
|
2015
|
+
if (!find) {
|
|
2016
|
+
return {
|
|
2017
|
+
...column
|
|
2018
|
+
};
|
|
2019
|
+
}
|
|
1696
2020
|
|
|
1697
2021
|
// Xử lý đệ quy cho children
|
|
1698
2022
|
if (column.children?.length) {
|
|
@@ -1725,18 +2049,60 @@ const GridEdit = props => {
|
|
|
1725
2049
|
setMergedSelectedKeys(keys);
|
|
1726
2050
|
};
|
|
1727
2051
|
const contextMenuClick = args => {
|
|
1728
|
-
if (args.item.
|
|
1729
|
-
|
|
2052
|
+
if (args.item?.parentKey && args.item.parentKey === 'INSERT_BEFORE') {
|
|
2053
|
+
if (args.item.key === 'INSERT_BEFORE_ADV') {
|
|
2054
|
+
// mở Modal
|
|
2055
|
+
|
|
2056
|
+
setOpenModalAddRow(prev => ({
|
|
2057
|
+
...prev,
|
|
2058
|
+
open: true,
|
|
2059
|
+
type: 'INSERT_BEFORE'
|
|
2060
|
+
}));
|
|
2061
|
+
} else {
|
|
2062
|
+
handleInsertBefore(args.item, args.item.row);
|
|
2063
|
+
}
|
|
2064
|
+
return;
|
|
1730
2065
|
}
|
|
1731
|
-
if (args.item.
|
|
1732
|
-
|
|
2066
|
+
if (args.item?.parentKey && args.item.parentKey === 'INSERT_AFTER') {
|
|
2067
|
+
if (args.item.key === 'INSERT_AFTER_ADV') {
|
|
2068
|
+
setOpenModalAddRow(prev => ({
|
|
2069
|
+
...prev,
|
|
2070
|
+
open: true,
|
|
2071
|
+
type: 'INSERT_AFTER'
|
|
2072
|
+
}));
|
|
2073
|
+
} else {
|
|
2074
|
+
handleInsertAfter(args.item, args.item.row);
|
|
2075
|
+
}
|
|
2076
|
+
return;
|
|
1733
2077
|
}
|
|
1734
2078
|
if (args.item.key === 'DELETE_ROWS') {
|
|
1735
2079
|
handleDeleteRows(args.item);
|
|
2080
|
+
return;
|
|
1736
2081
|
}
|
|
1737
2082
|
if (args.item.key === 'DELETE_CONTENT') {
|
|
1738
2083
|
handleDeleteContent();
|
|
2084
|
+
return;
|
|
2085
|
+
}
|
|
2086
|
+
};
|
|
2087
|
+
const hideModalAddRow = () => {
|
|
2088
|
+
setOpenModalAddRow(prev => ({
|
|
2089
|
+
...prev,
|
|
2090
|
+
open: false,
|
|
2091
|
+
type: ''
|
|
2092
|
+
}));
|
|
2093
|
+
setRowsAdd(1);
|
|
2094
|
+
};
|
|
2095
|
+
const onOkAddRow = () => {
|
|
2096
|
+
if (openModalAddRow.type === 'INSERT_AFTER') {
|
|
2097
|
+
handleInsertAfter({}, rowsAdd);
|
|
2098
|
+
}
|
|
2099
|
+
if (openModalAddRow.type === 'INSERT_BEFORE') {
|
|
2100
|
+
handleInsertBefore({}, rowsAdd);
|
|
1739
2101
|
}
|
|
2102
|
+
hideModalAddRow();
|
|
2103
|
+
};
|
|
2104
|
+
const onChangeRows = val => {
|
|
2105
|
+
setRowsAdd(val);
|
|
1740
2106
|
};
|
|
1741
2107
|
return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(GridStyle, {
|
|
1742
2108
|
heightTable: height,
|
|
@@ -1862,6 +2228,28 @@ const GridEdit = props => {
|
|
|
1862
2228
|
toastOptions: {
|
|
1863
2229
|
className: 'react-hot-toast'
|
|
1864
2230
|
}
|
|
1865
|
-
})
|
|
2231
|
+
}), /*#__PURE__*/React.createElement(Modal
|
|
2232
|
+
// title="Thêm dòng"
|
|
2233
|
+
, {
|
|
2234
|
+
open: openModalAddRow.open,
|
|
2235
|
+
onOk: onOkAddRow,
|
|
2236
|
+
onCancel: hideModalAddRow,
|
|
2237
|
+
okText: "Ok",
|
|
2238
|
+
cancelText: "H\u1EE7y",
|
|
2239
|
+
className: 'be-popup-container',
|
|
2240
|
+
centered: true,
|
|
2241
|
+
width: 250,
|
|
2242
|
+
closable: false
|
|
2243
|
+
}, /*#__PURE__*/React.createElement(InputNumber, {
|
|
2244
|
+
style: {
|
|
2245
|
+
width: '100%'
|
|
2246
|
+
},
|
|
2247
|
+
defaultValue: 1,
|
|
2248
|
+
value: rowsAdd,
|
|
2249
|
+
min: 1,
|
|
2250
|
+
max: 1000,
|
|
2251
|
+
onChange: onChangeRows,
|
|
2252
|
+
changeOnWheel: true
|
|
2253
|
+
})));
|
|
1866
2254
|
};
|
|
1867
2255
|
export default GridEdit;
|