es-grid-template 1.3.3 → 1.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/index.css +10 -0
- package/assets/index.scss +15 -0
- package/es/grid-component/ContextMenu.js +4 -1
- package/es/grid-component/EditableCell.js +60 -18
- package/es/grid-component/TableGrid.js +1 -7
- package/es/grid-component/hooks/columns/index.js +13 -16
- package/es/grid-component/hooks/useColumns.js +2 -1
- package/es/grid-component/hooks/utils.d.ts +13 -0
- package/es/grid-component/hooks/utils.js +136 -4
- package/es/grid-component/number/index.d.ts +10 -0
- package/es/grid-component/number/index.js +39 -0
- package/es/grid-component/styles.scss +15 -0
- package/es/grid-component/table/GridEdit.js +575 -204
- package/es/grid-component/type.d.ts +3 -0
- package/es/grid-component/useContext.d.ts +2 -0
- package/lib/grid-component/ContextMenu.js +4 -1
- package/lib/grid-component/EditableCell.js +61 -18
- package/lib/grid-component/TableGrid.js +1 -7
- package/lib/grid-component/hooks/columns/index.js +12 -15
- package/lib/grid-component/hooks/useColumns.js +2 -1
- package/lib/grid-component/hooks/utils.d.ts +13 -0
- package/lib/grid-component/hooks/utils.js +150 -7
- package/lib/grid-component/number/index.d.ts +10 -0
- package/lib/grid-component/number/index.js +47 -0
- package/lib/grid-component/styles.scss +15 -0
- package/lib/grid-component/table/GridEdit.js +563 -200
- package/lib/grid-component/type.d.ts +3 -0
- package/lib/grid-component/useContext.d.ts +2 -0
- package/package.json +1 -1
|
@@ -29,11 +29,92 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
|
|
|
29
29
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
30
30
|
// import Command from "../Command";
|
|
31
31
|
|
|
32
|
+
// import type {ContextMenuItem} from "../type";
|
|
32
33
|
// import {ContextInfo, ContextMenuItem} from "../type";
|
|
33
34
|
// import useLazyKVMap from "rc-master-ui/es/table/hooks/useLazyKVMap";
|
|
34
35
|
|
|
36
|
+
const {
|
|
37
|
+
Paragraph,
|
|
38
|
+
Title
|
|
39
|
+
} = _antd.Typography;
|
|
35
40
|
_dayjs.default.extend(_customParseFormat.default);
|
|
36
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.default.createElement(_becoxyIcons.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.default.createElement(_becoxyIcons.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.default.createElement(_becoxyIcons.Trash2, {
|
|
109
|
+
fontSize: 14
|
|
110
|
+
})
|
|
111
|
+
}, {
|
|
112
|
+
key: 'DELETE_ROWS',
|
|
113
|
+
label: 'Xóa dòng',
|
|
114
|
+
icon: /*#__PURE__*/_react.default.createElement(_becoxyIcons.Trash2, {
|
|
115
|
+
fontSize: 14
|
|
116
|
+
})
|
|
117
|
+
}];
|
|
37
118
|
const GridEdit = props => {
|
|
38
119
|
const {
|
|
39
120
|
id,
|
|
@@ -60,6 +141,8 @@ const GridEdit = props => {
|
|
|
60
141
|
expandable,
|
|
61
142
|
onCellClick,
|
|
62
143
|
rowEditable,
|
|
144
|
+
contextMenuItems: propsContext,
|
|
145
|
+
showDefaultContext,
|
|
63
146
|
...rest
|
|
64
147
|
} = props;
|
|
65
148
|
const {
|
|
@@ -94,6 +177,21 @@ const GridEdit = props => {
|
|
|
94
177
|
const [editingKey, setEditingKey] = (0, _react.useState)('');
|
|
95
178
|
const [isFilter, setIsFilter] = _react.default.useState(false);
|
|
96
179
|
const [selectedCells, setSelectedCells] = (0, _react.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] = (0, _react.useState)({
|
|
189
|
+
open: false,
|
|
190
|
+
type: ''
|
|
191
|
+
});
|
|
192
|
+
// const [openModalPaste, setOpenModalPaste] = useState(defaultModalPaste)
|
|
193
|
+
|
|
194
|
+
const [rowsAdd, setRowsAdd] = (0, _react.useState)(1);
|
|
97
195
|
const [pasteCells, setPasteCells] = (0, _react.useState)(new Set());
|
|
98
196
|
const [cellEditing, setCellEditing] = (0, _react.useState)(null);
|
|
99
197
|
const [isSelectDragging, setSelectIsDragging] = (0, _react.useState)(false);
|
|
@@ -118,32 +216,12 @@ const GridEdit = props => {
|
|
|
118
216
|
return [...new Set(Array.from(selectedCells).map(item => parseInt(item.split('-')[0])))] ?? [];
|
|
119
217
|
}, [selectedCells]);
|
|
120
218
|
const contextMenuItems = _react.default.useMemo(() => {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}, {
|
|
128
|
-
key: 'INSERT_AFTER',
|
|
129
|
-
label: 'Thêm dòng bên dưới',
|
|
130
|
-
icon: /*#__PURE__*/_react.default.createElement(_becoxyIcons.Plus, {
|
|
131
|
-
fontSize: 14
|
|
132
|
-
})
|
|
133
|
-
}, {
|
|
134
|
-
key: 'DELETE_CONTENT',
|
|
135
|
-
label: 'Xóa nội dung',
|
|
136
|
-
icon: /*#__PURE__*/_react.default.createElement(_becoxyIcons.Trash2, {
|
|
137
|
-
fontSize: 14
|
|
138
|
-
})
|
|
139
|
-
}, {
|
|
140
|
-
key: 'DELETE_ROWS',
|
|
141
|
-
label: 'Xóa dòng',
|
|
142
|
-
icon: /*#__PURE__*/_react.default.createElement(_becoxyIcons.Trash2, {
|
|
143
|
-
fontSize: 14
|
|
144
|
-
})
|
|
145
|
-
}];
|
|
146
|
-
}, []);
|
|
219
|
+
const a = showDefaultContext !== false ? [...defaultContext] : [];
|
|
220
|
+
const b = propsContext ? [...propsContext, {
|
|
221
|
+
type: 'divider'
|
|
222
|
+
}] : [];
|
|
223
|
+
return [...b, ...a];
|
|
224
|
+
}, [propsContext, showDefaultContext]);
|
|
147
225
|
const onTriggerExpand = _react.default.useCallback(record => {
|
|
148
226
|
const key = getRowKey(record, dataSource.indexOf(record));
|
|
149
227
|
let newExpandedKeys;
|
|
@@ -458,6 +536,7 @@ const GridEdit = props => {
|
|
|
458
536
|
className: (0, _classnames.default)(`be-toolbar-item`, item?.className)
|
|
459
537
|
}, /*#__PURE__*/_react.default.createElement(_antd.Dropdown.Button, {
|
|
460
538
|
overlayClassName: 'be-popup-container',
|
|
539
|
+
trigger: ['click'],
|
|
461
540
|
style: {
|
|
462
541
|
color: '#28c76f',
|
|
463
542
|
borderColor: '#28c76f'
|
|
@@ -668,8 +747,6 @@ const GridEdit = props => {
|
|
|
668
747
|
// defaultValues,
|
|
669
748
|
// resolver: yupResolver(formSchema)
|
|
670
749
|
});
|
|
671
|
-
|
|
672
|
-
// @ts-ignore
|
|
673
750
|
const isEditing = record => record[rowKey] === editingKey;
|
|
674
751
|
(0, _react.useEffect)(() => {
|
|
675
752
|
const handleClickOutside = event => {
|
|
@@ -678,6 +755,7 @@ const GridEdit = props => {
|
|
|
678
755
|
// const tableId = id ? document.getElementById(id) : undefined
|
|
679
756
|
// const tableBodies = document.getElementsByClassName("ui-rc-table-tbody");
|
|
680
757
|
const container = document.querySelector(".be-popup-container");
|
|
758
|
+
const containerContextMenu = document.querySelector(".popup-context-menu");
|
|
681
759
|
const tableBody = document.querySelector(`#${id} .ui-rc-table-tbody`);
|
|
682
760
|
// const containerHidden = document.querySelector(".be-popup-container.ant-picker-dropdown-hidden")
|
|
683
761
|
|
|
@@ -685,9 +763,10 @@ const GridEdit = props => {
|
|
|
685
763
|
const itemContainer = document.querySelector(`#${id} .ui-rc-toolbar-selection-overflow-item`);
|
|
686
764
|
const itemHeader = document.querySelector(`#${id} .ui-rc-table-thead`);
|
|
687
765
|
const isInsideContainer = element.closest(".be-popup-container") && container;
|
|
766
|
+
const isInsideContainerContext = containerContextMenu && element.closest(".popup-context-menu");
|
|
688
767
|
const isInsideToolbar = element.closest(`.ui-rc-toolbar-selection-overflow-item`) && itemContainer;
|
|
689
768
|
const isInsideHeader = itemHeader && itemHeader.contains(event.target);
|
|
690
|
-
if (isInsideContainer || isInsideToolbar || isInsideHeader) {
|
|
769
|
+
if (isInsideContainer || isInsideToolbar || isInsideHeader || isInsideContainerContext) {
|
|
691
770
|
return;
|
|
692
771
|
}
|
|
693
772
|
|
|
@@ -721,66 +800,55 @@ const GridEdit = props => {
|
|
|
721
800
|
document.removeEventListener("click", handleClickOutside);
|
|
722
801
|
};
|
|
723
802
|
}, []);
|
|
724
|
-
const handleMouseDown = (
|
|
803
|
+
const handleMouseDown = (record, row, col, e) => {
|
|
725
804
|
// setEditingKey('')
|
|
726
805
|
|
|
727
806
|
if (e.button === 2) {
|
|
728
807
|
e.stopPropagation();
|
|
729
808
|
return;
|
|
730
809
|
}
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
// e.stopPropagation()
|
|
738
|
-
// e.preventDefault()
|
|
739
|
-
} else {
|
|
740
|
-
// isSelecting.current = true;
|
|
741
|
-
// startCell.current = { row, col };
|
|
810
|
+
if (e.ctrlKey) {
|
|
811
|
+
isSelecting.current = true;
|
|
812
|
+
startCell.current = {
|
|
813
|
+
row,
|
|
814
|
+
col
|
|
815
|
+
};
|
|
742
816
|
|
|
743
|
-
//
|
|
744
|
-
|
|
817
|
+
// const cell: any = new Set([`${row}-${col}`])
|
|
818
|
+
|
|
819
|
+
// setCurrentCtrlCells(cell)
|
|
820
|
+
} else {
|
|
821
|
+
isSelecting.current = true;
|
|
822
|
+
startCell.current = {
|
|
745
823
|
row,
|
|
746
824
|
col
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
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
|
+
}
|
|
751
837
|
}
|
|
752
838
|
|
|
753
|
-
// setSelectIsDragging(true)
|
|
754
|
-
|
|
755
839
|
// isSelecting.current = true;
|
|
756
840
|
// startCell.current = { row, col };
|
|
757
841
|
//
|
|
758
|
-
// if (
|
|
759
|
-
//
|
|
842
|
+
// if (e.target.className === 'dragging-point') {
|
|
843
|
+
// // e.stopPropagation()
|
|
844
|
+
// // e.preventDefault()
|
|
845
|
+
// } else {
|
|
846
|
+
//
|
|
847
|
+
// setStartSelectedCell({row, col})
|
|
760
848
|
// setSelectedCells(new Set([`${row}-${col}`]));
|
|
761
849
|
// setRowsSelected(new Set())
|
|
762
850
|
// }
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
// const handlePointEnter = (e: any) => {
|
|
766
|
-
//
|
|
767
|
-
// if (e.button === 2) {
|
|
768
|
-
// e.stopPropagation()
|
|
769
|
-
// return
|
|
770
|
-
// }
|
|
771
|
-
//
|
|
772
|
-
// // setIsPasteDragging(true);
|
|
773
|
-
//
|
|
774
|
-
// };
|
|
775
|
-
|
|
776
|
-
// const handlePointLeave = () => {
|
|
777
|
-
//
|
|
778
|
-
// if (isPasteDragging && !isSelectDragging) {
|
|
779
|
-
// // setIsPasteDragging(false);
|
|
780
|
-
// }
|
|
781
|
-
//
|
|
782
|
-
// };
|
|
783
|
-
|
|
851
|
+
};
|
|
784
852
|
const triggerDragPaste = pastesArray => {
|
|
785
853
|
const mergedSet = new Set([...selectedCells, ...pastesArray]);
|
|
786
854
|
setSelectedCells(mergedSet);
|
|
@@ -880,18 +948,49 @@ const GridEdit = props => {
|
|
|
880
948
|
}
|
|
881
949
|
triggerDragPaste(newPasteCells);
|
|
882
950
|
};
|
|
883
|
-
|
|
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 => {
|
|
884
973
|
isSelecting.current = false;
|
|
885
974
|
startCell.current = null;
|
|
886
975
|
isSelectingRow.current = false;
|
|
887
976
|
rowStart.current = null;
|
|
888
977
|
setIsPasteDragging(false);
|
|
889
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
|
+
|
|
890
989
|
if (pasteCells.size > 0) {
|
|
891
990
|
triggerDragPaste(pasteCells);
|
|
892
991
|
}
|
|
893
992
|
};
|
|
894
|
-
const handleMouseEnter = (row, col) => {
|
|
993
|
+
const handleMouseEnter = (row, col, e) => {
|
|
895
994
|
if (!isSelecting.current || !startCell.current) {
|
|
896
995
|
return;
|
|
897
996
|
}
|
|
@@ -899,6 +998,18 @@ const GridEdit = props => {
|
|
|
899
998
|
row: startRow,
|
|
900
999
|
col: startCol
|
|
901
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
|
+
}
|
|
902
1013
|
if (!isPasteDragging) {
|
|
903
1014
|
// chọn vùng copy
|
|
904
1015
|
|
|
@@ -945,14 +1056,6 @@ const GridEdit = props => {
|
|
|
945
1056
|
if (row < colStart) {
|
|
946
1057
|
// kéo sang trái
|
|
947
1058
|
}
|
|
948
|
-
|
|
949
|
-
// const newPasteCells = new Set()
|
|
950
|
-
// for (let r = Math.min(startRow, row) + 1; r <= Math.max(startRow, row); r++) {
|
|
951
|
-
// for (let c = Math.min(colStart, col); c <= Math.max(colStart, colEnd); c++) {
|
|
952
|
-
// newPasteCells.add(`${r}-${c}`);
|
|
953
|
-
// }
|
|
954
|
-
// }
|
|
955
|
-
// setPasteCells(newPasteCells)
|
|
956
1059
|
}
|
|
957
1060
|
};
|
|
958
1061
|
const handleClickRowHeader = (row, col) => {
|
|
@@ -1083,22 +1186,17 @@ const GridEdit = props => {
|
|
|
1083
1186
|
e.clipboardData.setData("text/plain", copyText);
|
|
1084
1187
|
(0, _Message.default)(t ? t('CopySuccessful') : 'Copy Successful');
|
|
1085
1188
|
};
|
|
1086
|
-
const
|
|
1087
|
-
|
|
1088
|
-
const pasteData = e.clipboardData.getData("text/plain").trim();
|
|
1089
|
-
|
|
1090
|
-
// Chuyển đổi dữ liệu từ clipboard thành mảng
|
|
1091
|
-
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);
|
|
1092
1191
|
if (!record?.parentId) {
|
|
1093
1192
|
// Cập nhật data mới
|
|
1094
1193
|
const newData = [...dataSource];
|
|
1095
1194
|
|
|
1096
|
-
//
|
|
1097
|
-
const indexRows = newData.findIndex(it => it[rowKey] === record[rowKey]);
|
|
1195
|
+
// const indexRows = newData.findIndex((it) => it[rowKey as any] === record[rowKey])
|
|
1098
1196
|
|
|
1099
1197
|
// Lấy vị trí bắt đầu
|
|
1100
1198
|
// const { row: startRow, col: startCol } = selectedCell;
|
|
1101
|
-
const startRow =
|
|
1199
|
+
const startRow = newData.findIndex(it => it[rowKey] === record[rowKey]);
|
|
1102
1200
|
const startCol = indexCol;
|
|
1103
1201
|
|
|
1104
1202
|
// const flattData = flattenArray(newData);
|
|
@@ -1197,6 +1295,167 @@ const GridEdit = props => {
|
|
|
1197
1295
|
triggerPaste?.(pastedRows, pastedColumnsArray, newDataSource);
|
|
1198
1296
|
}
|
|
1199
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
|
+
_antd.Modal.confirm({
|
|
1310
|
+
content: /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.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.default.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
|
+
};
|
|
1200
1459
|
const onSubmit = formData => {
|
|
1201
1460
|
try {
|
|
1202
1461
|
// const record = (await form.validateFields()) as RecordType;
|
|
@@ -1222,7 +1481,10 @@ const GridEdit = props => {
|
|
|
1222
1481
|
newState,
|
|
1223
1482
|
prevState,
|
|
1224
1483
|
option,
|
|
1225
|
-
field
|
|
1484
|
+
field,
|
|
1485
|
+
indexCol,
|
|
1486
|
+
indexRow,
|
|
1487
|
+
key
|
|
1226
1488
|
} = args;
|
|
1227
1489
|
|
|
1228
1490
|
// const newRecord = getValues()
|
|
@@ -1240,26 +1502,26 @@ const GridEdit = props => {
|
|
|
1240
1502
|
if (onCellChange.length > 1) {
|
|
1241
1503
|
onCellChange({
|
|
1242
1504
|
field,
|
|
1243
|
-
indexCol
|
|
1505
|
+
indexCol,
|
|
1244
1506
|
type: 'onChange',
|
|
1245
1507
|
value: newState,
|
|
1246
1508
|
option,
|
|
1247
|
-
indexRow
|
|
1509
|
+
indexRow,
|
|
1248
1510
|
rowData: record,
|
|
1249
|
-
rowId:
|
|
1511
|
+
rowId: key,
|
|
1250
1512
|
rowsData: [],
|
|
1251
1513
|
sumValue: []
|
|
1252
1514
|
}, handleChangeCallback);
|
|
1253
1515
|
} else {
|
|
1254
1516
|
onCellChange({
|
|
1255
1517
|
field,
|
|
1256
|
-
indexCol
|
|
1518
|
+
indexCol,
|
|
1257
1519
|
type: 'onChange',
|
|
1258
1520
|
option,
|
|
1259
1521
|
value: newState,
|
|
1260
|
-
indexRow
|
|
1522
|
+
indexRow,
|
|
1261
1523
|
rowData: record,
|
|
1262
|
-
rowId:
|
|
1524
|
+
rowId: key,
|
|
1263
1525
|
rowsData: [],
|
|
1264
1526
|
sumValue: []
|
|
1265
1527
|
}, handleChangeCallback);
|
|
@@ -1368,7 +1630,7 @@ const GridEdit = props => {
|
|
|
1368
1630
|
});
|
|
1369
1631
|
}
|
|
1370
1632
|
};
|
|
1371
|
-
const handleFocusCell = (rowIndex, colIndex, col, scrollType, e) => {
|
|
1633
|
+
const handleFocusCell = (rowIndex, colIndex, col, scrollType, e, isTimeout) => {
|
|
1372
1634
|
const isEdit = editingKey !== '';
|
|
1373
1635
|
const cellEdit = document.querySelector(`.ui-rc-table-row .cell-editing[data-row-index="${rowIndex}"].cell-editing[data-col-index="${colIndex}"]`);
|
|
1374
1636
|
const cell = document.querySelector(`.ui-rc-table-row .cell-editable[data-row-index="${rowIndex}"].cell-editable[data-col-index="${colIndex}"]`);
|
|
@@ -1379,34 +1641,49 @@ const GridEdit = props => {
|
|
|
1379
1641
|
});
|
|
1380
1642
|
setSelectedCells(new Set([`${rowIndex}-${colIndex}`]));
|
|
1381
1643
|
};
|
|
1382
|
-
|
|
1383
|
-
if (
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1644
|
+
const focusNextCell = (editingCell, cellEditable) => {
|
|
1645
|
+
if (isEdit) {
|
|
1646
|
+
if (editingCell) {
|
|
1647
|
+
updateSelection();
|
|
1648
|
+
if (e?.key !== 'Tab') {
|
|
1649
|
+
editingCell.focus();
|
|
1650
|
+
}
|
|
1387
1651
|
}
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
scrollToCell(rowIndex, colIndex, cellEdit, 'horizontal');
|
|
1391
|
-
}
|
|
1392
|
-
if (scrollType === 'vertical' && cell) {
|
|
1393
|
-
setEditingKey('');
|
|
1394
|
-
updateSelection();
|
|
1395
|
-
scrollToCell(rowIndex, colIndex, cellEdit, 'vertical');
|
|
1396
|
-
if (e?.key !== 'Tab') {
|
|
1397
|
-
cell.focus();
|
|
1652
|
+
if (scrollType === 'horizontal' && editingCell) {
|
|
1653
|
+
scrollToCell(rowIndex, colIndex, editingCell, 'horizontal');
|
|
1398
1654
|
}
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
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);
|
|
1405
1672
|
}
|
|
1406
1673
|
}
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
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);
|
|
1410
1687
|
}
|
|
1411
1688
|
};
|
|
1412
1689
|
const getCellClass = (record, rowIndex, colIndex) => {
|
|
@@ -1429,25 +1706,22 @@ const GridEdit = props => {
|
|
|
1429
1706
|
const cellPasteSEnd = (0, _hooks.getLastSelectCell)(pasteCells);
|
|
1430
1707
|
const isPasteBottom = pasteCells.size && cellPasteSEnd && rowIndex === Math.max(cellPasteStart.row, cellPasteSEnd.row);
|
|
1431
1708
|
if (!isSelected && !isPasteSelected) {
|
|
1432
|
-
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) && (0, _hooks.isTopMostInRegion)(rowIndex + 1, colIndex, selectedCells);
|
|
1433
1711
|
const isLeft = colIndex + 1 === Math.min(cellStart.col, cellEnd?.col);
|
|
1434
1712
|
const isRight = colIndex - 1 === Math.max(cellStart.col, cellEnd?.col);
|
|
1435
1713
|
const isPasteLeft = colIndex + 1 === Math.min(cellPasteStart.col, cellPasteSEnd?.col);
|
|
1436
1714
|
const isPasteRight = colIndex - 1 === Math.max(cellPasteStart.col, cellPasteSEnd?.col);
|
|
1437
|
-
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` : ''}` :
|
|
1438
|
-
// (isPasteLeftSelected || isPasteRightSelected) ? `${cellClass} ${isPasteLeft ? `cell-paste-border-left` : ''}` :
|
|
1439
|
-
|
|
1440
|
-
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;
|
|
1441
1716
|
}
|
|
1442
|
-
const isBottom =
|
|
1443
|
-
const
|
|
1717
|
+
const isBottom = (0, _hooks.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 = (0, _hooks.isRightMostInRegion)(rowIndex, colIndex, selectedCells);
|
|
1444
1722
|
const isLeft = colIndex === Math.min(cellStart.col, cellEnd?.col);
|
|
1445
1723
|
const isPasteRight = cellPasteSEnd && colIndex === Math.max(cellPasteStart.col, cellPasteSEnd.col);
|
|
1446
1724
|
const isPasteLeft = colIndex === Math.min(cellPasteStart.col, cellPasteSEnd?.col);
|
|
1447
|
-
|
|
1448
|
-
// return `${cellClass} ${isBottom ? `cell-border-bottom` : ''} ${isRight ? `cell-border-right` : '' } ${isBottom && isRight ? `cell-border-end` : '' }
|
|
1449
|
-
// 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` : '' }`
|
|
1450
|
-
|
|
1451
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` : ''}`;
|
|
1452
1726
|
};
|
|
1453
1727
|
const convertColumns = (0, _columns.flatColumns2)(columns).map((column, colIndex) => {
|
|
@@ -1508,79 +1782,97 @@ const GridEdit = props => {
|
|
|
1508
1782
|
onCell: (record, rowIndex) => {
|
|
1509
1783
|
const rowNumber = (0, _hooks.getRowNumber)(dataSource, record[rowKey], rowKey);
|
|
1510
1784
|
return {
|
|
1511
|
-
// onKeyPress: () => {
|
|
1512
|
-
//
|
|
1513
|
-
// },
|
|
1514
|
-
|
|
1515
1785
|
onKeyDown: event => {
|
|
1516
1786
|
const key = getRowKey(record, dataSource.indexOf(record));
|
|
1517
|
-
if (event.key
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
const hasKey = mergedExpandedKeys.has(key);
|
|
1525
|
-
if (hasKey) {
|
|
1526
|
-
// mergedExpandedKeys.delete(key);
|
|
1527
|
-
// newExpandedKeys = [...mergedExpandedKeys];
|
|
1528
|
-
} else {
|
|
1529
|
-
onTriggerExpand(record);
|
|
1530
|
-
}
|
|
1531
|
-
} else {
|
|
1532
|
-
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 && (0, _hooks.isEditable)(column, record)) {
|
|
1793
|
+
// ~~ khi editingKey = ''
|
|
1533
1794
|
event.preventDefault();
|
|
1534
1795
|
event.stopPropagation();
|
|
1535
|
-
|
|
1536
|
-
|
|
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];
|
|
1537
1802
|
} else {
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1803
|
+
onTriggerExpand(record);
|
|
1804
|
+
}
|
|
1805
|
+
} else {
|
|
1806
|
+
if (event.key === 'Enter') {
|
|
1807
|
+
event.preventDefault();
|
|
1808
|
+
event.stopPropagation();
|
|
1809
|
+
if (editingKey && editingKey !== '' && (rowNumber ?? 0) + 1 < (0, _hooks.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
|
+
}
|
|
1547
1821
|
}
|
|
1548
1822
|
}
|
|
1549
1823
|
}
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
}
|
|
1558
|
-
}
|
|
1559
|
-
if (event.key === 'ArrowRight' && colIndex + 1 !== columns.length) {
|
|
1560
|
-
if (editingKey !== '') {} else {
|
|
1561
|
-
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
|
+
}
|
|
1562
1831
|
}
|
|
1563
|
-
|
|
1564
|
-
if (event.key === 'ArrowLeft' && colIndex > 0) {
|
|
1565
|
-
if (!column.dataIndex && !column.key || column.field === 'index' || column.field === '#' || column.dataIndex === 'index' || column.dataIndex === '#') {
|
|
1566
|
-
event.stopPropagation();
|
|
1567
|
-
event.preventDefault();
|
|
1568
|
-
} else {
|
|
1832
|
+
if (event.key === 'ArrowRight' && colIndex + 1 !== columns.length) {
|
|
1569
1833
|
if (editingKey !== '') {} else {
|
|
1570
|
-
handleFocusCell(rowNumber, colIndex
|
|
1834
|
+
handleFocusCell(rowNumber, colIndex + 1, column, 'horizontal', event);
|
|
1571
1835
|
}
|
|
1572
1836
|
}
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
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 < (0, _hooks.flattenArray)(dataSource).length) {
|
|
1848
|
+
if (isEditing(record) && ((0, _hooks.getEditType)(column, record) === 'treeSelect' || (0, _hooks.getEditType)(column, record) === 'select' || (0, _hooks.getEditType)(column, record) === 'selectTable' || (0, _hooks.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) && ((0, _hooks.getEditType)(column, record) === 'asyncSelect' || (0, _hooks.getEditType)(column, record) === 'select' || (0, _hooks.getEditType)(column, record) === 'selectTable' || (0, _hooks.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
|
+
}
|
|
1582
1867
|
}
|
|
1583
1868
|
},
|
|
1869
|
+
// onKeyUp: (event: any) => {
|
|
1870
|
+
// if (event.key === 'Control' && event.ctrlKey) {
|
|
1871
|
+
//
|
|
1872
|
+
// console.log('onKeyUp')
|
|
1873
|
+
// }
|
|
1874
|
+
// },
|
|
1875
|
+
|
|
1584
1876
|
onPaste: event => {
|
|
1585
1877
|
if (editingKey === '') {
|
|
1586
1878
|
handlePaste(record, colIndex, rowNumber, event);
|
|
@@ -1636,8 +1928,9 @@ const GridEdit = props => {
|
|
|
1636
1928
|
} : {}
|
|
1637
1929
|
};
|
|
1638
1930
|
},
|
|
1639
|
-
onHeaderCell: () => {
|
|
1931
|
+
onHeaderCell: (data, index) => {
|
|
1640
1932
|
return {
|
|
1933
|
+
...(column.onHeaderCell ? column.onHeaderCell?.(data, index) : {}),
|
|
1641
1934
|
onClick: () => {
|
|
1642
1935
|
handleClickColHeader(column, colIndex);
|
|
1643
1936
|
},
|
|
@@ -1663,12 +1956,18 @@ const GridEdit = props => {
|
|
|
1663
1956
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
1664
1957
|
className: (0, _classnames.default)('ui-rc_cell-content', {
|
|
1665
1958
|
// selected: selectedCells.has(`${record[rowKey]}-${colIndex}`)
|
|
1959
|
+
// selected: selectedCells.has(`${rowNumber}-${colIndex}`) || currentCtrlCells.has(`${rowNumber}-${colIndex}`) || mergedSets([selectedCells, ...ctrlCells]).has(`${rowNumber}-${colIndex}`),
|
|
1666
1960
|
selected: selectedCells.has(`${rowNumber}-${colIndex}`),
|
|
1667
1961
|
disable: !(0, _hooks.isEditable)(column, record)
|
|
1668
1962
|
}),
|
|
1669
1963
|
onMouseDown: event => handleMouseDown(record, rowNumber, colIndex, event),
|
|
1670
|
-
onMouseEnter:
|
|
1964
|
+
onMouseEnter: event => handleMouseEnter(rowNumber, colIndex, event),
|
|
1671
1965
|
onMouseUp: handleMouseUp
|
|
1966
|
+
// onClick={(event) => {
|
|
1967
|
+
//
|
|
1968
|
+
// handleClickCell(event)
|
|
1969
|
+
//
|
|
1970
|
+
// }}
|
|
1672
1971
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
1673
1972
|
className: 'ui-rc_content'
|
|
1674
1973
|
}, (0, _columns.renderContent)(column, value, record, rowIndex, format)), selectedCells && selectedCells.size > 0 && (0, _hooks.getLastSelectCell)(selectedCells).row === rowNumber && (0, _hooks.getLastSelectCell)(selectedCells).col === colIndex && (0, _hooks.isEditable)(column, record) && !isSelectDragging && rowIndex !== dataSource.length - 1 &&
|
|
@@ -1733,19 +2032,61 @@ const GridEdit = props => {
|
|
|
1733
2032
|
setMergedSelectedKeys(keys);
|
|
1734
2033
|
};
|
|
1735
2034
|
const contextMenuClick = args => {
|
|
1736
|
-
if (args.item.
|
|
1737
|
-
|
|
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;
|
|
1738
2048
|
}
|
|
1739
|
-
if (args.item.
|
|
1740
|
-
|
|
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;
|
|
1741
2060
|
}
|
|
1742
2061
|
if (args.item.key === 'DELETE_ROWS') {
|
|
1743
2062
|
handleDeleteRows(args.item);
|
|
2063
|
+
return;
|
|
1744
2064
|
}
|
|
1745
2065
|
if (args.item.key === 'DELETE_CONTENT') {
|
|
1746
2066
|
handleDeleteContent();
|
|
2067
|
+
return;
|
|
1747
2068
|
}
|
|
1748
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
|
+
};
|
|
1749
2090
|
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement(_GridStyle.GridStyle, {
|
|
1750
2091
|
heightTable: height,
|
|
1751
2092
|
style: {
|
|
@@ -1870,6 +2211,28 @@ const GridEdit = props => {
|
|
|
1870
2211
|
toastOptions: {
|
|
1871
2212
|
className: 'react-hot-toast'
|
|
1872
2213
|
}
|
|
1873
|
-
})
|
|
2214
|
+
}), /*#__PURE__*/_react.default.createElement(_antd.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.default.createElement(_rcMasterUi.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
|
+
})));
|
|
1874
2237
|
};
|
|
1875
2238
|
var _default = exports.default = GridEdit;
|