es-grid-template 1.2.0 → 1.2.2
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 +695 -0
- package/assets/index.scss +1063 -0
- package/es/grid-component/ColumnsChoose.d.ts +1 -0
- package/es/grid-component/ColumnsChoose.js +63 -28
- package/es/grid-component/ColumnsGroup/ColumnsGroup.d.ts +12 -0
- package/es/grid-component/ColumnsGroup/ColumnsGroup.js +223 -0
- package/es/grid-component/ColumnsGroup/index.d.ts +1 -0
- package/es/grid-component/ColumnsGroup/index.js +1 -0
- package/es/grid-component/ConvertColumnTable.d.ts +7 -0
- package/es/grid-component/ConvertColumnTable.js +143 -0
- package/es/grid-component/EditableCell.js +1 -1
- package/es/grid-component/GridStyle.js +1 -1
- package/es/grid-component/InternalTable.d.ts +1 -0
- package/es/grid-component/InternalTable.js +150 -249
- package/es/grid-component/TableGrid.d.ts +4 -1
- package/es/grid-component/TableGrid.js +31 -70
- package/es/grid-component/hooks/{useColumns → columns}/index.d.ts +2 -2
- package/es/grid-component/hooks/{useColumns → columns}/index.js +20 -16
- package/es/grid-component/hooks/content/HeaderContent.d.ts +11 -0
- package/es/grid-component/hooks/content/HeaderContent.js +79 -0
- package/es/grid-component/hooks/content/TooltipContent.d.ts +13 -0
- package/es/grid-component/hooks/content/TooltipContent.js +74 -0
- package/es/grid-component/hooks/useColumns.d.ts +16 -0
- package/es/grid-component/hooks/useColumns.js +280 -0
- package/es/grid-component/hooks/utils.d.ts +26 -1
- package/es/grid-component/hooks/utils.js +331 -1
- package/es/grid-component/index.js +3 -1
- package/es/grid-component/styles.scss +365 -68
- package/es/grid-component/table/Grid.d.ts +2 -0
- package/es/grid-component/table/Grid.js +18 -6
- package/es/grid-component/table/GridEdit.d.ts +4 -1
- package/es/grid-component/table/GridEdit.js +941 -307
- package/es/grid-component/table/Group.d.ts +13 -0
- package/es/grid-component/table/Group.js +154 -0
- package/es/grid-component/type.d.ts +39 -2
- package/lib/grid-component/ColumnsChoose.d.ts +1 -0
- package/lib/grid-component/ColumnsChoose.js +62 -27
- package/lib/grid-component/ColumnsGroup/ColumnsGroup.d.ts +12 -0
- package/lib/grid-component/ColumnsGroup/ColumnsGroup.js +234 -0
- package/lib/grid-component/ColumnsGroup/index.d.ts +1 -0
- package/lib/grid-component/ColumnsGroup/index.js +16 -0
- package/lib/grid-component/ConvertColumnTable.d.ts +7 -0
- package/lib/grid-component/ConvertColumnTable.js +152 -0
- package/lib/grid-component/EditableCell.js +1 -1
- package/lib/grid-component/GridStyle.js +1 -1
- package/lib/grid-component/InternalTable.d.ts +1 -0
- package/lib/grid-component/InternalTable.js +144 -249
- package/lib/grid-component/TableGrid.d.ts +4 -1
- package/lib/grid-component/TableGrid.js +26 -68
- package/lib/grid-component/hooks/{useColumns → columns}/index.d.ts +2 -2
- package/lib/grid-component/hooks/{useColumns → columns}/index.js +20 -16
- package/lib/grid-component/hooks/content/HeaderContent.d.ts +11 -0
- package/lib/grid-component/hooks/content/HeaderContent.js +86 -0
- package/lib/grid-component/hooks/content/TooltipContent.d.ts +13 -0
- package/lib/grid-component/hooks/content/TooltipContent.js +81 -0
- package/lib/grid-component/hooks/useColumns.d.ts +16 -0
- package/lib/grid-component/hooks/useColumns.js +291 -0
- package/lib/grid-component/hooks/utils.d.ts +26 -1
- package/lib/grid-component/hooks/utils.js +347 -5
- package/lib/grid-component/index.js +2 -1
- package/lib/grid-component/styles.scss +365 -68
- package/lib/grid-component/table/Grid.d.ts +2 -0
- package/lib/grid-component/table/Grid.js +18 -6
- package/lib/grid-component/table/GridEdit.d.ts +4 -1
- package/lib/grid-component/table/GridEdit.js +939 -305
- package/lib/grid-component/table/Group.d.ts +13 -0
- package/lib/grid-component/table/Group.js +163 -0
- package/lib/grid-component/type.d.ts +39 -2
- package/package.json +106 -105
|
@@ -12,7 +12,7 @@ var _classnames = _interopRequireDefault(require("classnames"));
|
|
|
12
12
|
var _antd = require("antd");
|
|
13
13
|
var _reactHookForm = require("react-hook-form");
|
|
14
14
|
var _reactHotToast = require("react-hot-toast");
|
|
15
|
-
var
|
|
15
|
+
var _columns = require("../hooks/columns");
|
|
16
16
|
var _EditableCell = _interopRequireDefault(require("../EditableCell"));
|
|
17
17
|
var _GridStyle = require("../GridStyle");
|
|
18
18
|
var _useContext = require("../useContext");
|
|
@@ -23,10 +23,13 @@ var _TableGrid = _interopRequireDefault(require("../TableGrid"));
|
|
|
23
23
|
var _hooks = require("../hooks");
|
|
24
24
|
var _Message = _interopRequireDefault(require("../../Message/Message"));
|
|
25
25
|
var _rcMasterUi = require("rc-master-ui");
|
|
26
|
+
var _useMergedState = _interopRequireDefault(require("rc-util/lib/hooks/useMergedState"));
|
|
26
27
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
27
28
|
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; }
|
|
28
29
|
// import Command from "../Command";
|
|
29
30
|
|
|
31
|
+
// import useLazyKVMap from "rc-master-ui/es/table/hooks/useLazyKVMap";
|
|
32
|
+
|
|
30
33
|
_dayjs.default.extend(_customParseFormat.default);
|
|
31
34
|
const toast = 'top-right';
|
|
32
35
|
const GridEdit = props => {
|
|
@@ -41,24 +44,37 @@ const GridEdit = props => {
|
|
|
41
44
|
selectionSettings,
|
|
42
45
|
height,
|
|
43
46
|
format,
|
|
44
|
-
// onDataChange,
|
|
45
47
|
triggerChangeData,
|
|
48
|
+
triggerChangeColumns,
|
|
46
49
|
onCellPaste,
|
|
47
50
|
onCellChange,
|
|
51
|
+
triggerPaste,
|
|
48
52
|
style,
|
|
49
53
|
getRowKey,
|
|
50
54
|
className,
|
|
51
55
|
toolbarItems,
|
|
56
|
+
defaultValue,
|
|
57
|
+
expandable,
|
|
58
|
+
onCellClick,
|
|
52
59
|
...rest
|
|
53
60
|
} = props;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
61
|
+
const {
|
|
62
|
+
mode,
|
|
63
|
+
type,
|
|
64
|
+
// checkboxOnly,
|
|
65
|
+
// hideSelectAll,
|
|
66
|
+
columnWidth
|
|
67
|
+
// selectedRowKeys,
|
|
68
|
+
// defaultSelectedRowKeys
|
|
69
|
+
} = selectionSettings || {};
|
|
58
70
|
const isSelecting = (0, _react.useRef)(false);
|
|
59
71
|
const startCell = (0, _react.useRef)(null);
|
|
72
|
+
const childrenColumnName = 'children';
|
|
60
73
|
const isSelectingRow = (0, _react.useRef)(false);
|
|
61
74
|
const rowStart = (0, _react.useRef)(null);
|
|
75
|
+
|
|
76
|
+
// const [getRecordByKey] = useLazyKVMap(dataSource, childrenColumnName, getRowKey);
|
|
77
|
+
|
|
62
78
|
const itemsAdd = [{
|
|
63
79
|
key: '10',
|
|
64
80
|
label: '10 rows'
|
|
@@ -72,71 +88,346 @@ const GridEdit = props => {
|
|
|
72
88
|
const [form] = _antd.Form.useForm();
|
|
73
89
|
const [editingKey, setEditingKey] = (0, _react.useState)('');
|
|
74
90
|
const [selectedCells, setSelectedCells] = (0, _react.useState)(new Set());
|
|
91
|
+
const [pasteCells, setPasteCells] = (0, _react.useState)(new Set());
|
|
92
|
+
const [isSelectDragging, setSelectIsDragging] = (0, _react.useState)(false);
|
|
93
|
+
const [isPasteDragging, setIsPasteDragging] = (0, _react.useState)(false); // isPasteDragging == tiếp tục hiển thị con trỏ crosshair
|
|
94
|
+
|
|
95
|
+
// const [showDraggingPoint, setShowDraggingPoint] = useState(false);
|
|
96
|
+
|
|
75
97
|
const [rowsSelected, setRowsSelected] = (0, _react.useState)(new Set());
|
|
76
|
-
const [
|
|
77
|
-
const
|
|
78
|
-
|
|
98
|
+
const [startSelectedCells, setStartSelectedCell] = (0, _react.useState)(null);
|
|
99
|
+
const [innerExpandedKeys, setInnerExpandedKeys] = _react.default.useState(() => {
|
|
100
|
+
// if (defaultExpandedRowKeys) {
|
|
101
|
+
// return defaultExpandedRowKeys;
|
|
102
|
+
// }
|
|
103
|
+
// if (defaultExpandAllRows) {
|
|
104
|
+
return (0, _hooks.findAllChildrenKeys)(dataSource, getRowKey, childrenColumnName) ?? [];
|
|
105
|
+
// }
|
|
106
|
+
// return [];
|
|
107
|
+
});
|
|
108
|
+
const mergedExpandedKeys = _react.default.useMemo(() => new Set(innerExpandedKeys || []), [innerExpandedKeys]);
|
|
109
|
+
const [mergedSelectedKeys, setMergedSelectedKeys] = (0, _useMergedState.default)([], {
|
|
110
|
+
value: []
|
|
111
|
+
});
|
|
112
|
+
const rowsFocus = _react.default.useMemo(() => {
|
|
113
|
+
return [...new Set(Array.from(selectedCells).map(item => parseInt(item.split('-')[0])))] ?? [];
|
|
114
|
+
}, [selectedCells]);
|
|
115
|
+
const onTriggerExpand = _react.default.useCallback(record => {
|
|
116
|
+
const key = getRowKey(record, dataSource.indexOf(record));
|
|
117
|
+
let newExpandedKeys;
|
|
118
|
+
const hasKey = mergedExpandedKeys.has(key);
|
|
119
|
+
if (hasKey) {
|
|
120
|
+
mergedExpandedKeys.delete(key);
|
|
121
|
+
newExpandedKeys = [...mergedExpandedKeys];
|
|
122
|
+
} else {
|
|
123
|
+
newExpandedKeys = [...mergedExpandedKeys, key];
|
|
124
|
+
}
|
|
125
|
+
setInnerExpandedKeys(newExpandedKeys);
|
|
126
|
+
}, [getRowKey, mergedExpandedKeys, dataSource]);
|
|
127
|
+
const handleAddSingle = item => {
|
|
128
|
+
const defaultRowValue = (0, _hooks.getDefaultValue)(defaultValue);
|
|
129
|
+
const rowId = defaultRowValue && defaultRowValue.id ? defaultRowValue.id : (0, _hooks.newGuid)();
|
|
130
|
+
if (item.onClick) {
|
|
131
|
+
item.onClick({
|
|
132
|
+
toolbar: item
|
|
133
|
+
});
|
|
134
|
+
} else {
|
|
135
|
+
const newData = [...dataSource, defaultValue ? {
|
|
136
|
+
...defaultRowValue,
|
|
137
|
+
id: undefined,
|
|
138
|
+
rowId
|
|
139
|
+
} : {
|
|
140
|
+
id: undefined,
|
|
141
|
+
rowId
|
|
142
|
+
}];
|
|
143
|
+
triggerChangeData?.(newData, 'Add');
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
const handleAddMulti = (item, e) => {
|
|
147
|
+
if (item.onClick) {
|
|
148
|
+
item.onClick({
|
|
149
|
+
toolbar: item
|
|
150
|
+
});
|
|
151
|
+
} else {
|
|
152
|
+
const defaultRowValue = (0, _hooks.getDefaultValue)(defaultValue);
|
|
153
|
+
const newRows = Array.from({
|
|
154
|
+
length: Number(e.key)
|
|
155
|
+
}).map(() => defaultRowValue ? {
|
|
156
|
+
...defaultRowValue,
|
|
157
|
+
id: undefined,
|
|
158
|
+
rowId: (0, _hooks.newGuid)()
|
|
159
|
+
} : {
|
|
160
|
+
id: undefined,
|
|
161
|
+
rowId: (0, _hooks.newGuid)()
|
|
162
|
+
});
|
|
163
|
+
const newData = dataSource.concat(newRows);
|
|
164
|
+
triggerChangeData?.(newData, 'Add');
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
const handleDuplicate = () => {
|
|
168
|
+
// không tính tree
|
|
169
|
+
|
|
170
|
+
// Cập nhật data mới
|
|
171
|
+
const newData = [...dataSource];
|
|
172
|
+
const duplicatedItems = rowsFocus.map(index => ({
|
|
173
|
+
...newData[index],
|
|
174
|
+
rowId: (0, _hooks.newGuid)(),
|
|
175
|
+
id: undefined,
|
|
176
|
+
isDuplicate: true
|
|
177
|
+
}));
|
|
178
|
+
|
|
179
|
+
// Vị trí chèn là ngay sau phần tử lớn nhất trong rowsFocus
|
|
180
|
+
const insertAfter = Math.max(...rowsFocus);
|
|
181
|
+
const rs = [...newData.slice(0, insertAfter + 1), ...duplicatedItems, ...newData.slice(insertAfter + 1)];
|
|
182
|
+
triggerChangeData?.(rs, 'DUPLICATE');
|
|
183
|
+
};
|
|
184
|
+
const handleInsertBefore = item => {
|
|
185
|
+
const defaultRowValue = (0, _hooks.getDefaultValue)(defaultValue);
|
|
186
|
+
const rowId = defaultRowValue && defaultRowValue.id ? defaultRowValue.id : (0, _hooks.newGuid)();
|
|
187
|
+
const record = (0, _hooks.flattenData)(childrenColumnName, dataSource)[rowsFocus[rowsFocus.length - 1]];
|
|
188
|
+
if (item.onClick) {
|
|
189
|
+
item.onClick({
|
|
190
|
+
toolbar: item
|
|
191
|
+
});
|
|
192
|
+
} else {
|
|
193
|
+
if (!record.parentId) {
|
|
194
|
+
// Cập nhật data mới
|
|
195
|
+
const newData = [...dataSource];
|
|
196
|
+
const index = newData.findIndex(obj => obj[rowKey] === record[rowKey]);
|
|
197
|
+
newData.splice(index, 0, {
|
|
198
|
+
...defaultRowValue,
|
|
199
|
+
rowId,
|
|
200
|
+
parentId: null,
|
|
201
|
+
id: undefined
|
|
202
|
+
});
|
|
203
|
+
triggerChangeData?.(newData, 'INSERT_BEFORE');
|
|
204
|
+
} else {
|
|
205
|
+
const newData = [...dataSource];
|
|
206
|
+
const parent = (0, _hooks.findItemByKey)(newData, rowKey, record.parentId);
|
|
207
|
+
|
|
208
|
+
// Cập nhật childData mới
|
|
209
|
+
const childData = parent?.children ? [...parent.children] : [];
|
|
210
|
+
const index = childData.findIndex(obj => obj[rowKey] === record[rowKey]);
|
|
211
|
+
childData.splice(index, 0, {
|
|
212
|
+
...defaultRowValue,
|
|
213
|
+
rowId,
|
|
214
|
+
parentId: record.parentId,
|
|
215
|
+
id: undefined
|
|
216
|
+
});
|
|
217
|
+
const newRowData = {
|
|
218
|
+
...parent,
|
|
219
|
+
children: childData
|
|
220
|
+
};
|
|
221
|
+
const newDataSource = (0, _hooks.updateArrayByKey)(newData, newRowData, rowKey);
|
|
222
|
+
triggerChangeData?.(newDataSource, 'INSERT_BEFORE');
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
const handleInsertAfter = item => {
|
|
227
|
+
const defaultRowValue = (0, _hooks.getDefaultValue)(defaultValue);
|
|
228
|
+
const rowId = defaultRowValue && defaultRowValue.id ? defaultRowValue.id : (0, _hooks.newGuid)();
|
|
229
|
+
const record = (0, _hooks.flattenData)(childrenColumnName, dataSource)[rowsFocus[rowsFocus.length - 1]];
|
|
230
|
+
|
|
231
|
+
// const record = getRecordByKey()
|
|
232
|
+
|
|
79
233
|
if (item.onClick) {
|
|
80
|
-
|
|
234
|
+
item.onClick({
|
|
235
|
+
toolbar: item
|
|
236
|
+
});
|
|
81
237
|
} else {
|
|
82
|
-
|
|
238
|
+
if (!record.parentId) {
|
|
239
|
+
// Cập nhật data mới
|
|
240
|
+
const newData = [...dataSource];
|
|
241
|
+
const index = newData.findIndex(obj => obj[rowKey] === record[rowKey]);
|
|
242
|
+
newData.splice(index + 1, 0, {
|
|
243
|
+
...defaultRowValue,
|
|
244
|
+
rowId,
|
|
245
|
+
parentId: null
|
|
246
|
+
});
|
|
247
|
+
triggerChangeData?.(newData, 'INSERT_AFTER');
|
|
248
|
+
} else {
|
|
249
|
+
const newData = [...dataSource];
|
|
250
|
+
const parent = (0, _hooks.findItemByKey)(newData, rowKey, record.parentId);
|
|
251
|
+
|
|
252
|
+
// Cập nhật childData mới
|
|
253
|
+
const childData = parent?.children ? [...parent.children] : [];
|
|
254
|
+
const index = childData.findIndex(obj => obj[rowKey] === record[rowKey]);
|
|
255
|
+
childData.splice(index + 1, 0, {
|
|
256
|
+
...defaultRowValue,
|
|
257
|
+
rowId,
|
|
258
|
+
parentId: record.parentId
|
|
259
|
+
});
|
|
260
|
+
const newRowData = {
|
|
261
|
+
...parent,
|
|
262
|
+
children: childData
|
|
263
|
+
};
|
|
264
|
+
const newDataSource = (0, _hooks.updateArrayByKey)(newData, newRowData, rowKey);
|
|
265
|
+
triggerChangeData?.(newDataSource, 'INSERT_BEFORE');
|
|
266
|
+
}
|
|
83
267
|
}
|
|
84
268
|
};
|
|
85
|
-
const handleDuplicate = () => {};
|
|
86
|
-
const handleInsertBefore = () => {};
|
|
87
|
-
const handleInsertAfter = () => {};
|
|
88
269
|
const handleDeleteAll = () => {};
|
|
89
270
|
const toolbarItemsBottom = (0, _react.useMemo)(() => {
|
|
90
|
-
|
|
91
|
-
return {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
271
|
+
if (!rowsFocus || rowsFocus.length === 0) {
|
|
272
|
+
return toolbarItems?.filter(it => it.position === 'Bottom' && it.visible !== false && it.key !== 'DUPLICATE' && it.key !== 'INSERT_BEFORE' && it.key !== 'INSERT_AFTER').map(item => {
|
|
273
|
+
if (item.key === 'ADD') {
|
|
274
|
+
return {
|
|
275
|
+
...item,
|
|
276
|
+
template: () => {
|
|
277
|
+
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, item.key === 'ADD' && /*#__PURE__*/_react.default.createElement("div", {
|
|
278
|
+
className: (0, _classnames.default)(`be-toolbar-item`, item?.className)
|
|
279
|
+
}, /*#__PURE__*/_react.default.createElement(_antd.Dropdown.Button, {
|
|
280
|
+
style: {
|
|
281
|
+
color: '#28c76f',
|
|
282
|
+
borderColor: '#28c76f'
|
|
283
|
+
},
|
|
284
|
+
className: 'toolbar-button toolbar-dropdown-button',
|
|
285
|
+
menu: {
|
|
286
|
+
items: itemsAdd,
|
|
287
|
+
onClick: e => handleAddMulti(item, e)
|
|
288
|
+
}
|
|
289
|
+
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
290
|
+
style: {
|
|
291
|
+
color: '#28c76f'
|
|
292
|
+
},
|
|
293
|
+
onClick: () => handleAddSingle(item)
|
|
294
|
+
}, item.title ? t ? t(item.title) : item.title : t ? t('Add item') : 'Add item'))));
|
|
100
295
|
}
|
|
101
|
-
}
|
|
102
|
-
className: (0, _classnames.default)(`be-toolbar-item ${item.className}`)
|
|
103
|
-
}, /*#__PURE__*/_react.default.createElement(_antd.Button, {
|
|
104
|
-
color: "green",
|
|
105
|
-
variant: 'outlined',
|
|
106
|
-
onClick: handleDuplicate,
|
|
107
|
-
className: "d-flex be-button"
|
|
108
|
-
}, item.title ? t ? t(item.title) : item.title : t ? t('Duplicate') : 'Duplicate')), item.key === 'INSERT_BEFORE' && item.visible !== false && editingKey && /*#__PURE__*/_react.default.createElement("div", {
|
|
109
|
-
className: (0, _classnames.default)(`be-toolbar-item ${item.className}`)
|
|
110
|
-
}, /*#__PURE__*/_react.default.createElement(_antd.Button, {
|
|
111
|
-
color: "green",
|
|
112
|
-
variant: 'outlined',
|
|
113
|
-
onClick: handleInsertBefore,
|
|
114
|
-
className: "d-flex be-button"
|
|
115
|
-
}, item.title ? t ? t(item.title) : item.title : t ? t('Insert item before') : 'Insert item before')), item.key === 'INSERT_AFTER' && item.visible !== false && editingKey && /*#__PURE__*/_react.default.createElement("div", {
|
|
116
|
-
className: (0, _classnames.default)(`be-toolbar-item ${item.className}`)
|
|
117
|
-
}, /*#__PURE__*/_react.default.createElement(_antd.Button, {
|
|
118
|
-
color: "green",
|
|
119
|
-
variant: 'outlined',
|
|
120
|
-
onClick: handleInsertAfter,
|
|
121
|
-
className: "d-flex be-button"
|
|
122
|
-
}, item.title ? t ? t(item.title) : item.title : t ? t('Insert item after') : 'Insert item after')), item.key === 'DELETE' && item.visible !== false && /*#__PURE__*/_react.default.createElement("div", {
|
|
123
|
-
className: (0, _classnames.default)(`be-toolbar-item ${item.className}`)
|
|
124
|
-
}, /*#__PURE__*/_react.default.createElement(_antd.Button, {
|
|
125
|
-
color: "primary",
|
|
126
|
-
variant: 'outlined',
|
|
127
|
-
onClick: handleDeleteAll,
|
|
128
|
-
className: "d-flex be-button"
|
|
129
|
-
}, item.title ? t ? t(item.title) : item.title : t ? t('Delete all item') : 'Delete all item')));
|
|
296
|
+
};
|
|
130
297
|
}
|
|
298
|
+
if (item.key === 'DELETE') {
|
|
299
|
+
return {
|
|
300
|
+
...item,
|
|
301
|
+
template: () => {
|
|
302
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
303
|
+
className: (0, _classnames.default)(`be-toolbar-item`, item?.className)
|
|
304
|
+
}, /*#__PURE__*/_react.default.createElement(_antd.Button, {
|
|
305
|
+
style: {
|
|
306
|
+
color: '#eb4619',
|
|
307
|
+
borderColor: '#eb4619'
|
|
308
|
+
},
|
|
309
|
+
variant: 'outlined',
|
|
310
|
+
onClick: handleDeleteAll,
|
|
311
|
+
className: "d-flex toolbar-button"
|
|
312
|
+
}, item.title ? t ? t(item.title) : item.title : t ? t('Delete all item') : 'Delete all item'));
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
return {
|
|
317
|
+
...item
|
|
318
|
+
};
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
return toolbarItems?.filter(it => it.position === 'Bottom' && it.visible !== false).map(item => {
|
|
322
|
+
if (item.key === 'ADD') {
|
|
323
|
+
return {
|
|
324
|
+
...item,
|
|
325
|
+
template: () => {
|
|
326
|
+
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, item.key === 'ADD' && /*#__PURE__*/_react.default.createElement("div", {
|
|
327
|
+
className: (0, _classnames.default)(`be-toolbar-item`, item?.className)
|
|
328
|
+
}, /*#__PURE__*/_react.default.createElement(_antd.Dropdown.Button, {
|
|
329
|
+
style: {
|
|
330
|
+
color: '#28c76f',
|
|
331
|
+
borderColor: '#28c76f'
|
|
332
|
+
},
|
|
333
|
+
className: 'toolbar-button toolbar-dropdown-button',
|
|
334
|
+
menu: {
|
|
335
|
+
items: itemsAdd,
|
|
336
|
+
onClick: e => handleAddMulti(item, e)
|
|
337
|
+
}
|
|
338
|
+
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
339
|
+
style: {
|
|
340
|
+
color: '#28c76f'
|
|
341
|
+
},
|
|
342
|
+
onClick: () => handleAddSingle(item)
|
|
343
|
+
}, item.title ? t ? t(item.title) : item.title : t ? t('Add item') : 'Add item'))));
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
if (item.key === 'DUPLICATE') {
|
|
348
|
+
return {
|
|
349
|
+
...item,
|
|
350
|
+
template: () => {
|
|
351
|
+
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, item.key === 'DUPLICATE' && item.visible !== false && rowsFocus.length > 0 && /*#__PURE__*/_react.default.createElement("div", {
|
|
352
|
+
className: (0, _classnames.default)(`be-toolbar-item`, item?.className)
|
|
353
|
+
}, /*#__PURE__*/_react.default.createElement(_antd.Button, {
|
|
354
|
+
style: {
|
|
355
|
+
color: '#28c76f',
|
|
356
|
+
borderColor: '#28c76f'
|
|
357
|
+
},
|
|
358
|
+
variant: 'outlined',
|
|
359
|
+
onClick: handleDuplicate,
|
|
360
|
+
className: "d-flex toolbar-button"
|
|
361
|
+
}, item.title ? t ? t(item.title) : item.title : t ? t('Duplicate') : 'Duplicate')));
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
if (item.key === 'INSERT_BEFORE') {
|
|
366
|
+
return {
|
|
367
|
+
...item,
|
|
368
|
+
template: () => {
|
|
369
|
+
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, item.key === 'INSERT_BEFORE' && item.visible !== false && rowsFocus.length > 0 && /*#__PURE__*/_react.default.createElement("div", {
|
|
370
|
+
className: (0, _classnames.default)(`be-toolbar-item`, item?.className)
|
|
371
|
+
}, /*#__PURE__*/_react.default.createElement(_antd.Button, {
|
|
372
|
+
style: {
|
|
373
|
+
color: '#28c76f',
|
|
374
|
+
borderColor: '#28c76f'
|
|
375
|
+
},
|
|
376
|
+
variant: 'outlined',
|
|
377
|
+
onClick: () => handleInsertBefore(item),
|
|
378
|
+
className: "d-flex toolbar-button"
|
|
379
|
+
}, item.title ? t ? t(item.title) : item.title : t ? t('Insert item before') : 'Insert item before')));
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
if (item.key === 'INSERT_AFTER') {
|
|
384
|
+
return {
|
|
385
|
+
...item,
|
|
386
|
+
template: () => {
|
|
387
|
+
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, item.key === 'INSERT_AFTER' && item.visible !== false && rowsFocus.length > 0 && /*#__PURE__*/_react.default.createElement("div", {
|
|
388
|
+
className: (0, _classnames.default)(`be-toolbar-item`, item?.className)
|
|
389
|
+
}, /*#__PURE__*/_react.default.createElement(_antd.Button, {
|
|
390
|
+
style: {
|
|
391
|
+
color: '#28c76f',
|
|
392
|
+
borderColor: '#28c76f'
|
|
393
|
+
},
|
|
394
|
+
variant: 'outlined',
|
|
395
|
+
onClick: () => handleInsertAfter(item),
|
|
396
|
+
className: "d-flex toolbar-button"
|
|
397
|
+
}, item.title ? t ? t(item.title) : item.title : t ? t('Insert item after') : 'Insert item after')));
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
if (item.key === 'DELETE') {
|
|
402
|
+
return {
|
|
403
|
+
...item,
|
|
404
|
+
template: () => {
|
|
405
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
406
|
+
className: (0, _classnames.default)(`be-toolbar-item`, item?.className)
|
|
407
|
+
}, /*#__PURE__*/_react.default.createElement(_antd.Button, {
|
|
408
|
+
style: {
|
|
409
|
+
color: '#eb4619',
|
|
410
|
+
borderColor: '#eb4619'
|
|
411
|
+
},
|
|
412
|
+
variant: 'outlined',
|
|
413
|
+
onClick: handleDeleteAll,
|
|
414
|
+
className: "d-flex toolbar-button"
|
|
415
|
+
}, item.title ? t ? t(item.title) : item.title : t ? t('Delete all item') : 'Delete all item'));
|
|
416
|
+
}
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
return {
|
|
420
|
+
...item
|
|
131
421
|
};
|
|
132
422
|
});
|
|
133
|
-
}, [toolbarItems]);
|
|
423
|
+
}, [handleAddMulti, handleAddSingle, itemsAdd, rowsFocus.length, t, toolbarItems]);
|
|
134
424
|
const {
|
|
135
425
|
control,
|
|
136
426
|
handleSubmit,
|
|
137
427
|
setValue,
|
|
138
428
|
trigger,
|
|
139
|
-
getValues
|
|
429
|
+
getValues,
|
|
430
|
+
reset
|
|
140
431
|
// formState: { errors }
|
|
141
432
|
} = (0, _reactHookForm.useForm)({
|
|
142
433
|
mode: 'onChange'
|
|
@@ -148,13 +439,16 @@ const GridEdit = props => {
|
|
|
148
439
|
const isEditing = record => record[rowKey] === editingKey;
|
|
149
440
|
(0, _react.useEffect)(() => {
|
|
150
441
|
const handleClickOutside = event => {
|
|
151
|
-
const tableBodies = document.getElementsByClassName("ui-rc-table-tbody");
|
|
152
442
|
const element = event.target;
|
|
443
|
+
const tableBodies = document.getElementsByClassName("ui-rc-table-tbody");
|
|
153
444
|
const container = document.querySelector(".be-popup-container");
|
|
154
445
|
// const containerHidden = document.querySelector(".be-popup-container.ant-picker-dropdown-hidden")
|
|
155
446
|
|
|
447
|
+
// const toolbarContainer = document.getElementsByClassName("ui-rc-toolbar");
|
|
448
|
+
const itemContainer = document.querySelector(".ui-rc-toolbar-selection-overflow-item");
|
|
156
449
|
const isInsideContainer = element.closest(".be-popup-container") && container;
|
|
157
|
-
|
|
450
|
+
const isInsideToolbar = element.closest(".ui-rc-toolbar-selection-overflow-item") && itemContainer;
|
|
451
|
+
if (isInsideContainer || isInsideToolbar) {
|
|
158
452
|
return;
|
|
159
453
|
}
|
|
160
454
|
if (tableBodies.length > 0) {
|
|
@@ -174,36 +468,237 @@ const GridEdit = props => {
|
|
|
174
468
|
document.removeEventListener("click", handleClickOutside);
|
|
175
469
|
};
|
|
176
470
|
}, []);
|
|
177
|
-
const handleMouseDown = (row, col, e) => {
|
|
471
|
+
const handleMouseDown = (record, row, col, e) => {
|
|
178
472
|
if (e.button === 2) {
|
|
179
473
|
e.stopPropagation();
|
|
180
474
|
return;
|
|
181
475
|
}
|
|
182
|
-
setSelectedCell({
|
|
183
|
-
row,
|
|
184
|
-
col
|
|
185
|
-
});
|
|
186
476
|
isSelecting.current = true;
|
|
187
477
|
startCell.current = {
|
|
188
478
|
row,
|
|
189
479
|
col
|
|
190
480
|
};
|
|
191
|
-
|
|
192
|
-
|
|
481
|
+
if (e.target.className === 'dragging-point') {
|
|
482
|
+
// e.stopPropagation()
|
|
483
|
+
// e.preventDefault()
|
|
484
|
+
} else {
|
|
485
|
+
// isSelecting.current = true;
|
|
486
|
+
// startCell.current = { row, col };
|
|
487
|
+
|
|
488
|
+
// if (!isPasteDragging) {
|
|
489
|
+
setStartSelectedCell({
|
|
490
|
+
row,
|
|
491
|
+
col
|
|
492
|
+
});
|
|
493
|
+
setSelectedCells(new Set([`${row}-${col}`]));
|
|
494
|
+
setRowsSelected(new Set());
|
|
495
|
+
// }
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
// setSelectIsDragging(true)
|
|
499
|
+
|
|
500
|
+
// isSelecting.current = true;
|
|
501
|
+
// startCell.current = { row, col };
|
|
502
|
+
//
|
|
503
|
+
// if (!isPasteDragging) {
|
|
504
|
+
// setStartSelectedCell({ row, col })
|
|
505
|
+
// setSelectedCells(new Set([`${row}-${col}`]));
|
|
506
|
+
// setRowsSelected(new Set())
|
|
507
|
+
// }
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
// const handlePointEnter = (e: any) => {
|
|
511
|
+
//
|
|
512
|
+
// if (e.button === 2) {
|
|
513
|
+
// e.stopPropagation()
|
|
514
|
+
// return
|
|
515
|
+
// }
|
|
516
|
+
//
|
|
517
|
+
// // setIsPasteDragging(true);
|
|
518
|
+
//
|
|
519
|
+
// };
|
|
520
|
+
|
|
521
|
+
// const handlePointLeave = () => {
|
|
522
|
+
//
|
|
523
|
+
// if (isPasteDragging && !isSelectDragging) {
|
|
524
|
+
// // setIsPasteDragging(false);
|
|
525
|
+
// }
|
|
526
|
+
//
|
|
527
|
+
// };
|
|
528
|
+
|
|
529
|
+
const triggerDragPaste = pastesArray => {
|
|
530
|
+
const mergedSet = new Set([...selectedCells, ...pastesArray]);
|
|
531
|
+
setSelectedCells(mergedSet);
|
|
532
|
+
setPasteCells(new Set());
|
|
533
|
+
const selectedArray = Array.from(selectedCells).map(key => {
|
|
534
|
+
const [row, col] = key.split("-").map(Number);
|
|
535
|
+
// @ts-ignore
|
|
536
|
+
const columnKey = columns[col].field;
|
|
537
|
+
|
|
538
|
+
// @ts-ignore
|
|
539
|
+
return {
|
|
540
|
+
row,
|
|
541
|
+
col,
|
|
542
|
+
value: (0, _hooks.flattenData)(childrenColumnName, dataSource)[row][columnKey]
|
|
543
|
+
};
|
|
544
|
+
// return { row, col, value: '' };
|
|
545
|
+
});
|
|
546
|
+
|
|
547
|
+
// Xác định min/max row và col để sắp xếp dữ liệu
|
|
548
|
+
const minRow = Math.min(...selectedArray.map(cell => cell.row));
|
|
549
|
+
const maxRow = Math.max(...selectedArray.map(cell => cell.row));
|
|
550
|
+
const minCol = Math.min(...selectedArray.map(cell => cell.col));
|
|
551
|
+
const maxCol = Math.max(...selectedArray.map(cell => cell.col));
|
|
552
|
+
|
|
553
|
+
// Tạo dữ liệu dạng bảng (mảng 2D)
|
|
554
|
+
const table = Array.from({
|
|
555
|
+
length: maxRow - minRow + 1
|
|
556
|
+
}, () => Array(maxCol - minCol + 1).fill(""));
|
|
557
|
+
|
|
558
|
+
// Gán giá trị vào bảng
|
|
559
|
+
selectedArray.forEach(({
|
|
560
|
+
row,
|
|
561
|
+
col,
|
|
562
|
+
value
|
|
563
|
+
}) => {
|
|
564
|
+
table[row - minRow][col - minCol] = value;
|
|
565
|
+
});
|
|
566
|
+
const newRange = (0, _hooks.addRows8)(table, (0, _hooks.getRowsPasteIndex)(pastesArray).length);
|
|
567
|
+
const record = (0, _hooks.flattenData)(childrenColumnName, dataSource)[(0, _hooks.getFirstSelectCell)(pastesArray).row];
|
|
568
|
+
if (!record.parentId) {
|
|
569
|
+
// Cập nhật data mới
|
|
570
|
+
const newData = [...dataSource];
|
|
571
|
+
|
|
572
|
+
// Lấy vị trí bắt đầu
|
|
573
|
+
// const { row: startRow, col: startCol } = selectedCell;
|
|
574
|
+
const startRow = (0, _hooks.getFirstSelectCell)(pastesArray).row;
|
|
575
|
+
const startCol = (0, _hooks.getFirstSelectCell)(selectedCells).col;
|
|
576
|
+
const pastedRows = [];
|
|
577
|
+
const pastedColumns = new Set();
|
|
578
|
+
newRange.addedRows.forEach((rowValues, rowIndex) => {
|
|
579
|
+
const targetRow = startRow + rowIndex;
|
|
580
|
+
|
|
581
|
+
// Nếu vượt quá số dòng hiện có, thêm dòng mới
|
|
582
|
+
if (targetRow >= newData.length) {
|
|
583
|
+
// @ts-ignore
|
|
584
|
+
newData.push({
|
|
585
|
+
id: undefined,
|
|
586
|
+
rowId: (0, _hooks.newGuid)()
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
rowValues.forEach((cellValue, colIndex) => {
|
|
590
|
+
const targetCol = startCol + colIndex;
|
|
591
|
+
if (targetCol >= columns.length) {
|
|
592
|
+
// Không vượt quá số cột
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
// @ts-ignore
|
|
597
|
+
const columnKey = columns[targetCol].field;
|
|
598
|
+
|
|
599
|
+
// @ts-ignore
|
|
600
|
+
newData[targetRow] = {
|
|
601
|
+
...newData[targetRow],
|
|
602
|
+
[columnKey]: typeof cellValue === 'string' ? cellValue.trim() : cellValue
|
|
603
|
+
};
|
|
604
|
+
pastedColumns.add(columnKey);
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
// Lưu dòng được paste
|
|
608
|
+
pastedRows.push(newData[targetRow]);
|
|
609
|
+
});
|
|
610
|
+
const pastedColumnsArray = Array.from(pastedColumns) ?? [];
|
|
611
|
+
triggerPaste?.(pastedRows, pastedColumnsArray, newData);
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
const handlePointDoubleClick = e => {
|
|
615
|
+
e.preventDefault();
|
|
616
|
+
e.stopPropagation();
|
|
617
|
+
const colStart = (0, _hooks.getFirstSelectCell)(selectedCells).col;
|
|
618
|
+
const colEnd = (0, _hooks.getLastSelectCell)(selectedCells).col;
|
|
619
|
+
const startPasteRow = (0, _hooks.getLastSelectCell)(selectedCells).row;
|
|
620
|
+
const newPasteCells = new Set();
|
|
621
|
+
for (let r = Math.min(startPasteRow, dataSource.length - 1) + 1; r <= Math.max(startPasteRow, dataSource.length - 1); r++) {
|
|
622
|
+
for (let c = Math.min(colStart, colStart); c <= Math.max(colStart, colEnd); c++) {
|
|
623
|
+
newPasteCells.add(`${r}-${c}`);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
triggerDragPaste(newPasteCells);
|
|
627
|
+
};
|
|
628
|
+
const handleMouseUp = () => {
|
|
629
|
+
isSelecting.current = false;
|
|
630
|
+
startCell.current = null;
|
|
631
|
+
isSelectingRow.current = false;
|
|
632
|
+
rowStart.current = null;
|
|
633
|
+
setIsPasteDragging(false);
|
|
634
|
+
setSelectIsDragging(false);
|
|
635
|
+
if (pasteCells.size > 0) {
|
|
636
|
+
triggerDragPaste(pasteCells);
|
|
637
|
+
}
|
|
193
638
|
};
|
|
194
639
|
const handleMouseEnter = (row, col) => {
|
|
195
|
-
if (!isSelecting.current || !startCell.current)
|
|
640
|
+
if (!isSelecting.current || !startCell.current) {
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
196
643
|
const {
|
|
197
644
|
row: startRow,
|
|
198
645
|
col: startCol
|
|
199
646
|
} = startCell.current;
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
647
|
+
if (!isPasteDragging) {
|
|
648
|
+
// chọn vùng copy
|
|
649
|
+
|
|
650
|
+
setSelectIsDragging(true);
|
|
651
|
+
setIsPasteDragging(false);
|
|
652
|
+
const newSelectedCells = new Set();
|
|
653
|
+
for (let r = Math.min(startRow, row); r <= Math.max(startRow, row); r++) {
|
|
654
|
+
for (let c = Math.min(startCol, col); c <= Math.max(startCol, col); c++) {
|
|
655
|
+
newSelectedCells.add(`${r}-${c}`);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
setSelectedCells(newSelectedCells);
|
|
659
|
+
} else {
|
|
660
|
+
// chọn vùng paste
|
|
661
|
+
|
|
662
|
+
setSelectIsDragging(false);
|
|
663
|
+
setIsPasteDragging(true);
|
|
664
|
+
const newSelectedCells = new Set();
|
|
665
|
+
for (let r = Math.min(startRow, row); r <= Math.max(startRow, row); r++) {
|
|
666
|
+
for (let c = Math.min(startCol, col); c <= Math.max(startCol, col); c++) {
|
|
667
|
+
newSelectedCells.add(`${r}-${c}`);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
const colStart = (0, _hooks.getFirstSelectCell)(selectedCells).col;
|
|
671
|
+
const colEnd = (0, _hooks.getLastSelectCell)(selectedCells).col;
|
|
672
|
+
const rowSelectedEnd = (0, _hooks.getLastSelectCell)(selectedCells).row;
|
|
673
|
+
if (row >= rowSelectedEnd) {
|
|
674
|
+
// kéo xuống dưới
|
|
675
|
+
|
|
676
|
+
const newPasteCells = new Set();
|
|
677
|
+
for (let r = Math.min(startRow, row) + 1; r <= Math.max(startRow, row); r++) {
|
|
678
|
+
for (let c = Math.min(colStart, col); c <= Math.max(colStart, colEnd); c++) {
|
|
679
|
+
newPasteCells.add(`${r}-${c}`);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
setPasteCells(newPasteCells);
|
|
683
|
+
}
|
|
684
|
+
if (row < rowSelectedEnd) {
|
|
685
|
+
// kéo lên trên
|
|
686
|
+
}
|
|
687
|
+
if (col > colEnd) {
|
|
688
|
+
// kéo sang phải
|
|
204
689
|
}
|
|
690
|
+
if (row < colStart) {
|
|
691
|
+
// kéo sang trái
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
// const newPasteCells = new Set()
|
|
695
|
+
// for (let r = Math.min(startRow, row) + 1; r <= Math.max(startRow, row); r++) {
|
|
696
|
+
// for (let c = Math.min(colStart, col); c <= Math.max(colStart, colEnd); c++) {
|
|
697
|
+
// newPasteCells.add(`${r}-${c}`);
|
|
698
|
+
// }
|
|
699
|
+
// }
|
|
700
|
+
// setPasteCells(newPasteCells)
|
|
205
701
|
}
|
|
206
|
-
setSelectedCells(newSelectedCells);
|
|
207
702
|
};
|
|
208
703
|
const handleClickRowHeader = (row, col) => {
|
|
209
704
|
const newSelectedCells = new Set();
|
|
@@ -272,23 +767,46 @@ const GridEdit = props => {
|
|
|
272
767
|
setRowsSelected(newSelectedRows);
|
|
273
768
|
setSelectedCells(newSelectedCells);
|
|
274
769
|
};
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
770
|
+
const handleCellClick = (indexRow, record, column) => {
|
|
771
|
+
const cellClickCallback = newOptions => {
|
|
772
|
+
if (newOptions) {
|
|
773
|
+
const newElem = {
|
|
774
|
+
...column,
|
|
775
|
+
editSelectSettings: {
|
|
776
|
+
...(column?.editSelectSettings ? {
|
|
777
|
+
...column?.editSelectSettings
|
|
778
|
+
} : {}),
|
|
779
|
+
options: newOptions
|
|
780
|
+
}
|
|
781
|
+
};
|
|
782
|
+
const rrr = (0, _hooks.updateArrayByKey)([...columns], newElem, 'field');
|
|
783
|
+
triggerChangeColumns?.(rrr, 'click');
|
|
784
|
+
}
|
|
785
|
+
};
|
|
786
|
+
if (onCellClick) {
|
|
787
|
+
onCellClick({
|
|
788
|
+
index: indexRow,
|
|
789
|
+
rowId: record.rowId,
|
|
790
|
+
cellValue: record[record.field],
|
|
791
|
+
type: "Editing",
|
|
792
|
+
field: column.field,
|
|
793
|
+
rowData: record
|
|
794
|
+
}, cellClickCallback);
|
|
795
|
+
}
|
|
280
796
|
};
|
|
281
797
|
const handleCopy = e => {
|
|
282
798
|
const selectedArray = Array.from(selectedCells).map(key => {
|
|
283
799
|
const [row, col] = key.split("-").map(Number);
|
|
284
800
|
// @ts-ignore
|
|
285
|
-
const columnKey = columns[col].
|
|
801
|
+
const columnKey = columns[col].field;
|
|
802
|
+
|
|
286
803
|
// @ts-ignore
|
|
287
804
|
return {
|
|
288
805
|
row,
|
|
289
806
|
col,
|
|
290
|
-
value: dataSource[row][columnKey]
|
|
807
|
+
value: (0, _hooks.flattenData)(childrenColumnName, dataSource)[row][columnKey]
|
|
291
808
|
};
|
|
809
|
+
// return { row, col, value: '' };
|
|
292
810
|
});
|
|
293
811
|
|
|
294
812
|
// Xác định min/max row và col để sắp xếp dữ liệu
|
|
@@ -319,133 +837,131 @@ const GridEdit = props => {
|
|
|
319
837
|
e.clipboardData.setData("text/plain", copyText);
|
|
320
838
|
(0, _Message.default)(t ? t('CopySuccessful') : 'Copy Successful');
|
|
321
839
|
};
|
|
322
|
-
const handlePaste = (
|
|
840
|
+
const handlePaste = (record, indexCol, rowNumber, e) => {
|
|
323
841
|
// const clipboard: any = (e.clipboardData || (window && window?.Clipboard)).getData("text")
|
|
324
842
|
const pasteData = e.clipboardData.getData("text/plain").trim();
|
|
325
843
|
|
|
326
844
|
// Chuyển đổi dữ liệu từ clipboard thành mảng
|
|
327
845
|
const rows = pasteData.split("\n").map(row => row.replace(/\r/g, "").split("\t"));
|
|
846
|
+
if (!record.parentId) {
|
|
847
|
+
// Cập nhật data mới
|
|
848
|
+
const newData = [...dataSource];
|
|
328
849
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
const startRow = indexRow;
|
|
332
|
-
const startCol = indexCol;
|
|
850
|
+
// @ts-ignore
|
|
851
|
+
const indexRows = newData.findIndex(it => it[rowKey] === record[rowKey]);
|
|
333
852
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
rows.forEach((rowValues, rowIndex) => {
|
|
339
|
-
const targetRow = startRow + rowIndex;
|
|
853
|
+
// Lấy vị trí bắt đầu
|
|
854
|
+
// const { row: startRow, col: startCol } = selectedCell;
|
|
855
|
+
const startRow = indexRows;
|
|
856
|
+
const startCol = indexCol;
|
|
340
857
|
|
|
341
|
-
//
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
858
|
+
// const flattData = flattenArray(newData);
|
|
859
|
+
|
|
860
|
+
const pastedRows = [];
|
|
861
|
+
const pastedColumns = new Set();
|
|
862
|
+
rows.forEach((rowValues, rowIndex) => {
|
|
863
|
+
const targetRow = startRow + rowIndex;
|
|
864
|
+
|
|
865
|
+
// Nếu vượt quá số dòng hiện có, thêm dòng mới
|
|
866
|
+
if (targetRow >= newData.length) {
|
|
867
|
+
// @ts-ignore
|
|
868
|
+
// newData.push({ id: newGuid()});
|
|
869
|
+
newData.push({
|
|
870
|
+
id: undefined,
|
|
871
|
+
rowId: (0, _hooks.newGuid)()
|
|
872
|
+
});
|
|
873
|
+
}
|
|
874
|
+
rowValues.forEach((cellValue, colIndex) => {
|
|
875
|
+
const targetCol = startCol + colIndex;
|
|
876
|
+
if (targetCol >= columns.length) {
|
|
877
|
+
// Không vượt quá số cột
|
|
878
|
+
return;
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
// @ts-ignore
|
|
882
|
+
const columnKey = columns[targetCol].field;
|
|
883
|
+
|
|
884
|
+
// @ts-ignore
|
|
885
|
+
newData[targetRow] = {
|
|
886
|
+
...newData[targetRow],
|
|
887
|
+
[columnKey]: cellValue.trim()
|
|
888
|
+
};
|
|
889
|
+
pastedColumns.add(columnKey);
|
|
347
890
|
});
|
|
348
|
-
}
|
|
349
|
-
rowValues.forEach((cellValue, colIndex) => {
|
|
350
|
-
const targetCol = startCol + colIndex;
|
|
351
|
-
if (targetCol >= columns.length) return; // Không vượt quá số cột
|
|
352
891
|
|
|
353
|
-
//
|
|
354
|
-
|
|
355
|
-
// @ts-ignore
|
|
356
|
-
newData[targetRow] = {
|
|
357
|
-
...newData[targetRow],
|
|
358
|
-
[columnKey]: cellValue.trim()
|
|
359
|
-
};
|
|
360
|
-
pastedColumns.add(columnKey);
|
|
892
|
+
// Lưu dòng được paste
|
|
893
|
+
pastedRows.push(newData[targetRow]);
|
|
361
894
|
});
|
|
895
|
+
const pastedColumnsArray = Array.from(pastedColumns) ?? [];
|
|
896
|
+
triggerPaste?.(pastedRows, pastedColumnsArray, newData);
|
|
897
|
+
} else {
|
|
898
|
+
// Cập nhật data mới
|
|
899
|
+
const newData = [...dataSource];
|
|
900
|
+
const parent = (0, _hooks.findItemByKey)(newData, rowKey, record.parentId);
|
|
362
901
|
|
|
363
|
-
//
|
|
364
|
-
|
|
365
|
-
});
|
|
366
|
-
const pastedColumnsArray = Array.from(pastedColumns) ?? [];
|
|
367
|
-
console.log(pastedColumnsArray);
|
|
368
|
-
console.log(pastedRows);
|
|
902
|
+
// Cập nhật childData mới
|
|
903
|
+
const childData = parent?.children ? [...parent.children] : [];
|
|
369
904
|
|
|
370
|
-
|
|
905
|
+
// Lấy vị trí bắt đầu
|
|
906
|
+
// const { row: startRow, col: startCol } = selectedCell;
|
|
907
|
+
const startRow = childData.findIndex(it => it[rowKey] === record[rowKey]);
|
|
908
|
+
const startCol = indexCol;
|
|
909
|
+
const pastedRows = [];
|
|
910
|
+
const pastedColumns = new Set();
|
|
911
|
+
rows.forEach((rowValues, rowIndex) => {
|
|
912
|
+
const targetRow = startRow + rowIndex;
|
|
371
913
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
914
|
+
// Nếu vượt quá số dòng hiện có, thêm dòng mới
|
|
915
|
+
if (targetRow >= childData.length) {
|
|
916
|
+
childData.push({
|
|
917
|
+
id: undefined,
|
|
918
|
+
rowId: (0, _hooks.newGuid)(),
|
|
919
|
+
parentId: parent[rowKey ?? 'id']
|
|
920
|
+
});
|
|
921
|
+
}
|
|
922
|
+
rowValues.forEach((cellValue, colIndex) => {
|
|
923
|
+
const targetCol = startCol + colIndex;
|
|
924
|
+
if (targetCol >= columns.length) {
|
|
925
|
+
// Không vượt quá số cột
|
|
926
|
+
return;
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
// @ts-ignore
|
|
930
|
+
const columnKey = columns[targetCol].field;
|
|
931
|
+
|
|
932
|
+
// @ts-ignore
|
|
933
|
+
childData[targetRow] = {
|
|
934
|
+
...childData[targetRow],
|
|
935
|
+
[columnKey]: cellValue.trim()
|
|
936
|
+
};
|
|
937
|
+
pastedColumns.add(columnKey);
|
|
938
|
+
});
|
|
939
|
+
|
|
940
|
+
// Lưu dòng được paste
|
|
941
|
+
pastedRows.push(childData[targetRow]);
|
|
942
|
+
});
|
|
943
|
+
const pastedColumnsArray = Array.from(pastedColumns) ?? [];
|
|
944
|
+
const newRowData = {
|
|
945
|
+
...parent,
|
|
946
|
+
children: childData
|
|
947
|
+
};
|
|
948
|
+
const newDataSource = (0, _hooks.updateArrayByKey)(newData, newRowData, rowKey);
|
|
949
|
+
triggerPaste?.(pastedRows, pastedColumnsArray, newDataSource);
|
|
950
|
+
}
|
|
407
951
|
};
|
|
408
952
|
const onSubmit = formData => {
|
|
409
|
-
console.log('onSubmit', formData);
|
|
410
953
|
try {
|
|
411
954
|
// const record = (await form.validateFields()) as RecordType;
|
|
412
955
|
const row = {
|
|
413
956
|
...formData
|
|
414
957
|
};
|
|
415
|
-
// const rowData = { ...record };
|
|
416
|
-
|
|
417
|
-
// columns.forEach(column => {
|
|
418
|
-
//
|
|
419
|
-
// // @ts-ignore
|
|
420
|
-
// if (column.editType === 'date' && rowData[column.dataIndex]) {
|
|
421
|
-
// // @ts-ignore
|
|
422
|
-
// rowData[column.dataIndex] = !isEmpty(record[column.dataIndex]) ? moment(row[column.dataIndex]).format() : null
|
|
423
|
-
// }
|
|
424
|
-
// });
|
|
425
|
-
|
|
426
958
|
const newData = [...dataSource];
|
|
959
|
+
|
|
427
960
|
// @ts-ignore
|
|
428
961
|
const index = newData.findIndex(item => formData[rowKey] === item[rowKey]);
|
|
429
|
-
|
|
430
|
-
// setIsManualUpdate(true);
|
|
431
|
-
|
|
962
|
+
const rs = (0, _hooks.updateArrayByKey)(dataSource, row, rowKey);
|
|
432
963
|
if (index > -1) {
|
|
433
|
-
|
|
434
|
-
newData.splice(index, 1, {
|
|
435
|
-
...item,
|
|
436
|
-
...row
|
|
437
|
-
});
|
|
438
|
-
triggerChangeData?.(newData, 'onChange');
|
|
439
|
-
|
|
440
|
-
// trigger DataChange
|
|
441
|
-
// setData(newData);
|
|
442
|
-
// onDataChange?.(newData)
|
|
443
|
-
} else {
|
|
444
|
-
newData.push(row);
|
|
445
|
-
// trigger DataChange
|
|
446
|
-
|
|
447
|
-
// setData(newData);
|
|
448
|
-
// onDataChange?.(newData)
|
|
964
|
+
triggerChangeData?.(rs, 'onChange');
|
|
449
965
|
}
|
|
450
966
|
} catch (errInfo) {
|
|
451
967
|
console.log('Validate Failed:', errInfo);
|
|
@@ -454,29 +970,18 @@ const GridEdit = props => {
|
|
|
454
970
|
const handleCellChange = args => {
|
|
455
971
|
const {
|
|
456
972
|
record,
|
|
457
|
-
type,
|
|
973
|
+
type: changeType,
|
|
458
974
|
newState,
|
|
459
975
|
prevState,
|
|
460
976
|
option,
|
|
461
977
|
field
|
|
462
978
|
} = args;
|
|
463
979
|
|
|
464
|
-
// console.log('newState', newState)
|
|
465
|
-
//
|
|
466
|
-
// console.log('getValues()', getValues())
|
|
467
|
-
|
|
468
980
|
// const newRecord = getValues()
|
|
469
981
|
|
|
470
|
-
if (
|
|
471
|
-
|
|
472
|
-
}
|
|
473
|
-
if (type === 'blur') {
|
|
474
|
-
// onCellChange
|
|
475
|
-
|
|
982
|
+
if (changeType === 'enter') {}
|
|
983
|
+
if (changeType === 'blur') {
|
|
476
984
|
const handleChangeCallback = callbackData => {
|
|
477
|
-
// const newDataUpdate = updateData(data, callbackData, rowKey as any)
|
|
478
|
-
|
|
479
|
-
console.log('callbackData', callbackData);
|
|
480
985
|
const callbackRecord = callbackData;
|
|
481
986
|
Object.entries(callbackRecord).forEach(([name, value]) => {
|
|
482
987
|
setValue(name, value);
|
|
@@ -485,7 +990,6 @@ const GridEdit = props => {
|
|
|
485
990
|
};
|
|
486
991
|
if (onCellChange) {
|
|
487
992
|
if (onCellChange.length > 1) {
|
|
488
|
-
console.log('onCellChange Callback');
|
|
489
993
|
onCellChange({
|
|
490
994
|
field,
|
|
491
995
|
indexCol: 1,
|
|
@@ -499,7 +1003,6 @@ const GridEdit = props => {
|
|
|
499
1003
|
sumValue: []
|
|
500
1004
|
}, handleChangeCallback);
|
|
501
1005
|
} else {
|
|
502
|
-
console.log('onCellChange');
|
|
503
1006
|
onCellChange({
|
|
504
1007
|
field,
|
|
505
1008
|
indexCol: 1,
|
|
@@ -515,16 +1018,15 @@ const GridEdit = props => {
|
|
|
515
1018
|
onSubmit(record);
|
|
516
1019
|
}
|
|
517
1020
|
}
|
|
518
|
-
console.log('aaaaaa blur');
|
|
519
1021
|
}
|
|
520
|
-
if (prevState && newState && prevState !== newState &&
|
|
521
|
-
console.log('enter');
|
|
1022
|
+
if (prevState && newState && prevState !== newState && changeType === 'enter') {
|
|
522
1023
|
onSubmit(record);
|
|
523
1024
|
}
|
|
524
1025
|
};
|
|
525
1026
|
const handleEdit = (record, col, editType, e) => {
|
|
526
1027
|
// @ts-ignore
|
|
527
1028
|
setEditingKey(record[rowKey]);
|
|
1029
|
+
reset();
|
|
528
1030
|
|
|
529
1031
|
// const formattedRecord = { ...record };
|
|
530
1032
|
|
|
@@ -554,19 +1056,20 @@ const GridEdit = props => {
|
|
|
554
1056
|
// });
|
|
555
1057
|
|
|
556
1058
|
if (e.key === 'Enter' || editType === 'date' || e.type === 'dblclick') {} else {
|
|
557
|
-
setValue(col.dataIndex, e.key);
|
|
1059
|
+
setValue(col.dataIndex, editType === 'numeric' ? !isNaN(Number(e.key)) ? Number(e.key) : '' : e.key);
|
|
1060
|
+
// setValue(col.dataIndex, e.key)
|
|
558
1061
|
}
|
|
559
1062
|
if (editType === 'select') {
|
|
560
1063
|
// setSearchValue(e.key)
|
|
561
1064
|
// setOpen(true)
|
|
562
1065
|
}
|
|
563
|
-
if (
|
|
1066
|
+
if (startSelectedCells?.row !== undefined && startSelectedCells?.col !== undefined) {
|
|
564
1067
|
setTimeout(() => {
|
|
565
1068
|
// const input = document.querySelector(`.ui-rc-table-row[data-row-key="${selectedCell.row}"] .cell-editing[data-col-index="${selectedCell.col}"] input`) as HTMLInputElement;
|
|
566
|
-
const input = document.querySelector(`.ui-rc-table-row .cell-editing[data-row-index="${
|
|
1069
|
+
const input = document.querySelector(`.ui-rc-table-row .cell-editing[data-row-index="${startSelectedCells.row}"].cell-editing[data-col-index="${startSelectedCells.col}"] input`);
|
|
567
1070
|
// const input = document.getElementById(`col${selectedCell.col}-record${selectedCell.row}`) as HTMLInputElement;
|
|
568
1071
|
|
|
569
|
-
const select = document.querySelector(`div.cell-editing[tabindex="${
|
|
1072
|
+
const select = document.querySelector(`div.cell-editing[tabindex="${startSelectedCells?.col}"] .ant-select-selection-search input`);
|
|
570
1073
|
if (input) {
|
|
571
1074
|
input.focus();
|
|
572
1075
|
}
|
|
@@ -579,18 +1082,21 @@ const GridEdit = props => {
|
|
|
579
1082
|
}, 0);
|
|
580
1083
|
}
|
|
581
1084
|
};
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
}
|
|
591
|
-
|
|
1085
|
+
|
|
1086
|
+
// useEffect(() => {
|
|
1087
|
+
// const tableBody = document.querySelector(".ui-rc-table-tbody");
|
|
1088
|
+
// const tableHeader = document.querySelector(".ui-rc-table-header");
|
|
1089
|
+
//
|
|
1090
|
+
// if (tableBody && tableHeader) {
|
|
1091
|
+
// tableBody.addEventListener("scroll", () => {
|
|
1092
|
+
// tableHeader.scrollLeft = tableBody.scrollLeft;
|
|
1093
|
+
// });
|
|
1094
|
+
// }
|
|
1095
|
+
// }, []);
|
|
1096
|
+
|
|
1097
|
+
const scrollToCell = (rowIndex, colIndex, cell, scrollType) => {
|
|
592
1098
|
const fixedWidth = (0, _hooks.totalFixedWidth)(columns, 'left', selectionSettings);
|
|
593
|
-
if (
|
|
1099
|
+
if (scrollType === 'horizontal') {
|
|
594
1100
|
if (tableRef.current) {
|
|
595
1101
|
tableRef.current.scrollTo({
|
|
596
1102
|
left: cell.offsetLeft - fixedWidth,
|
|
@@ -610,15 +1116,12 @@ const GridEdit = props => {
|
|
|
610
1116
|
});
|
|
611
1117
|
}
|
|
612
1118
|
};
|
|
613
|
-
const handleFocusCell = (rowIndex, colIndex, col,
|
|
1119
|
+
const handleFocusCell = (rowIndex, colIndex, col, scrollType, e) => {
|
|
614
1120
|
const isEdit = editingKey !== '';
|
|
615
|
-
// const cellEdit: any = document.querySelector(`.ui-rc-table-row[data-row-key="${rowIndex}"] .cell-editing[data-col-index="${colIndex}"]`);
|
|
616
|
-
// const cell: any = document.querySelector(`.ui-rc-table-row[data-row-key="${rowIndex}"] .cell-editable[data-col-index="${colIndex}"]`);
|
|
617
|
-
|
|
618
1121
|
const cellEdit = document.querySelector(`.ui-rc-table-row .cell-editing[data-row-index="${rowIndex}"].cell-editing[data-col-index="${colIndex}"]`);
|
|
619
1122
|
const cell = document.querySelector(`.ui-rc-table-row .cell-editable[data-row-index="${rowIndex}"].cell-editable[data-col-index="${colIndex}"]`);
|
|
620
1123
|
const updateSelection = () => {
|
|
621
|
-
|
|
1124
|
+
setStartSelectedCell({
|
|
622
1125
|
row: rowIndex,
|
|
623
1126
|
col: colIndex
|
|
624
1127
|
});
|
|
@@ -631,10 +1134,10 @@ const GridEdit = props => {
|
|
|
631
1134
|
cellEdit.focus();
|
|
632
1135
|
}
|
|
633
1136
|
}
|
|
634
|
-
if (
|
|
1137
|
+
if (scrollType === 'horizontal' && cellEdit) {
|
|
635
1138
|
scrollToCell(rowIndex, colIndex, cellEdit, 'horizontal');
|
|
636
1139
|
}
|
|
637
|
-
if (
|
|
1140
|
+
if (scrollType === 'vertical' && cell) {
|
|
638
1141
|
setEditingKey('');
|
|
639
1142
|
updateSelection();
|
|
640
1143
|
scrollToCell(rowIndex, colIndex, cellEdit, 'vertical');
|
|
@@ -650,11 +1153,52 @@ const GridEdit = props => {
|
|
|
650
1153
|
}
|
|
651
1154
|
}
|
|
652
1155
|
if (cell) {
|
|
653
|
-
scrollToCell(rowIndex, colIndex, cell,
|
|
1156
|
+
scrollToCell(rowIndex, colIndex, cell, scrollType);
|
|
654
1157
|
}
|
|
655
1158
|
}
|
|
656
1159
|
};
|
|
657
|
-
const
|
|
1160
|
+
const getCellClass = (record, rowIndex, colIndex) => {
|
|
1161
|
+
const cellKey = `${rowIndex}-${colIndex}`;
|
|
1162
|
+
const topCellKey = `${rowIndex + 1}-${colIndex}`;
|
|
1163
|
+
const leftCellKey = `${rowIndex}-${colIndex + 1}`;
|
|
1164
|
+
const rightCellKey = `${rowIndex}-${colIndex - 1}`;
|
|
1165
|
+
const isSelected = selectedCells.has(cellKey);
|
|
1166
|
+
const isTopSelected = selectedCells.has(topCellKey);
|
|
1167
|
+
const isLeftSelected = selectedCells.has(leftCellKey);
|
|
1168
|
+
const isRightSelected = selectedCells.has(rightCellKey);
|
|
1169
|
+
const isPasteSelected = pasteCells.has(cellKey);
|
|
1170
|
+
const isPasteLeftSelected = pasteCells.has(leftCellKey);
|
|
1171
|
+
const isPasteRightSelected = pasteCells.has(rightCellKey);
|
|
1172
|
+
const cellClass = isEditing(record) ? 'rc-ui-cell-editable cell-editing' : 'rc-ui-cell-editable cell-editable';
|
|
1173
|
+
const prevRecordEditing = (0, _hooks.flattenData)(childrenColumnName, dataSource)[rowIndex + 1];
|
|
1174
|
+
const cellStart = (0, _hooks.getFirstSelectCell)(selectedCells);
|
|
1175
|
+
const cellEnd = (0, _hooks.getLastSelectCell)(selectedCells);
|
|
1176
|
+
const cellPasteStart = (0, _hooks.getFirstSelectCell)(pasteCells);
|
|
1177
|
+
const cellPasteSEnd = (0, _hooks.getLastSelectCell)(pasteCells);
|
|
1178
|
+
const isPasteBottom = pasteCells.size && cellPasteSEnd && rowIndex === Math.max(cellPasteStart.row, cellPasteSEnd.row);
|
|
1179
|
+
if (!isSelected && !isPasteSelected) {
|
|
1180
|
+
const isTop = prevRecordEditing && !isEditing(prevRecordEditing) && rowIndex === Math.min(cellStart.row - 1, cellEnd?.row);
|
|
1181
|
+
const isLeft = colIndex + 1 === Math.min(cellStart.col, cellEnd?.col);
|
|
1182
|
+
const isRight = colIndex - 1 === Math.max(cellStart.col, cellEnd?.col);
|
|
1183
|
+
const isPasteLeft = colIndex + 1 === Math.min(cellPasteStart.col, cellPasteSEnd?.col);
|
|
1184
|
+
const isPasteRight = colIndex - 1 === Math.max(cellPasteStart.col, cellPasteSEnd?.col);
|
|
1185
|
+
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` : ''}` :
|
|
1186
|
+
// (isPasteLeftSelected || isPasteRightSelected) ? `${cellClass} ${isPasteLeft ? `cell-paste-border-left` : ''}` :
|
|
1187
|
+
|
|
1188
|
+
cellClass;
|
|
1189
|
+
}
|
|
1190
|
+
const isBottom = cellEnd && rowIndex === Math.max(cellStart.row, cellEnd.row);
|
|
1191
|
+
const isRight = cellEnd && colIndex === Math.max(cellStart.col, cellEnd.col);
|
|
1192
|
+
const isLeft = colIndex === Math.min(cellStart.col, cellEnd?.col);
|
|
1193
|
+
const isPasteRight = cellPasteSEnd && colIndex === Math.max(cellPasteStart.col, cellPasteSEnd.col);
|
|
1194
|
+
const isPasteLeft = colIndex === Math.min(cellPasteStart.col, cellPasteSEnd?.col);
|
|
1195
|
+
|
|
1196
|
+
// return `${cellClass} ${isBottom ? `cell-border-bottom` : ''} ${isRight ? `cell-border-right` : '' } ${isBottom && isRight ? `cell-border-end` : '' }
|
|
1197
|
+
// 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` : '' }`
|
|
1198
|
+
|
|
1199
|
+
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` : ''}`;
|
|
1200
|
+
};
|
|
1201
|
+
const convertColumns = (0, _columns.flatColumns2)(columns).map((column, colIndex) => {
|
|
658
1202
|
if (!column?.field && !column?.key) {
|
|
659
1203
|
return column;
|
|
660
1204
|
}
|
|
@@ -685,83 +1229,96 @@ const GridEdit = props => {
|
|
|
685
1229
|
}
|
|
686
1230
|
return {
|
|
687
1231
|
...column,
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
1232
|
+
onCell: (record, rowIndex) => {
|
|
1233
|
+
const rowNumber = (0, _hooks.getRowNumber)(dataSource, record[rowKey], rowKey);
|
|
1234
|
+
return {
|
|
1235
|
+
onKeyDown: event => {
|
|
1236
|
+
const key = getRowKey(record, dataSource.indexOf(record));
|
|
1237
|
+
if (event.key.length === 1 && !event.ctrlKey && !event.metaKey || event.key === 'Enter') {
|
|
1238
|
+
if (!isEditing(record) && record[rowKey] !== editingKey) {
|
|
1239
|
+
handleEdit(record, column, column.editType, event);
|
|
1240
|
+
handleCellClick(rowNumber, record, column);
|
|
1241
|
+
const hasKey = mergedExpandedKeys.has(key);
|
|
1242
|
+
if (hasKey) {
|
|
1243
|
+
// mergedExpandedKeys.delete(key);
|
|
1244
|
+
// newExpandedKeys = [...mergedExpandedKeys];
|
|
1245
|
+
} else {
|
|
1246
|
+
onTriggerExpand(record);
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
if (editingKey && editingKey !== '' && (rowNumber ?? 0) + 1 < (0, _hooks.flattenArray)(dataSource).length && event.key === 'Enter') {
|
|
1250
|
+
handleFocusCell((rowNumber ?? 0) + 1, colIndex, column, 'vertical', event);
|
|
1251
|
+
}
|
|
694
1252
|
}
|
|
695
|
-
if (
|
|
696
|
-
|
|
1253
|
+
if (event.key === 'Tab') {
|
|
1254
|
+
if (colIndex + 1 !== columns.length) {
|
|
1255
|
+
handleFocusCell(rowNumber, colIndex + 1, column, 'horizontal', event);
|
|
1256
|
+
} else {
|
|
1257
|
+
event.stopPropagation();
|
|
1258
|
+
event.preventDefault();
|
|
1259
|
+
}
|
|
697
1260
|
}
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
} else {
|
|
703
|
-
event.stopPropagation();
|
|
704
|
-
event.preventDefault();
|
|
1261
|
+
if (event.key === 'ArrowRight' && colIndex + 1 !== columns.length) {
|
|
1262
|
+
if (editingKey !== '') {} else {
|
|
1263
|
+
handleFocusCell(rowNumber, colIndex + 1, column, 'horizontal', event);
|
|
1264
|
+
}
|
|
705
1265
|
}
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
1266
|
+
if (event.key === 'ArrowLeft' && colIndex > 0) {
|
|
1267
|
+
if (!column.dataIndex && !column.key || column.field === 'index' || column.field === '#' || column.dataIndex === 'index' || column.dataIndex === '#') {
|
|
1268
|
+
event.stopPropagation();
|
|
1269
|
+
event.preventDefault();
|
|
1270
|
+
} else {
|
|
1271
|
+
if (editingKey !== '') {} else {
|
|
1272
|
+
handleFocusCell(rowNumber, colIndex - 1, column, 'horizontal', event);
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
710
1275
|
}
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
1276
|
+
if (event.key === 'ArrowDown' && (rowNumber ?? 0) + 1 < (0, _hooks.flattenArray)(dataSource).length) {
|
|
1277
|
+
handleFocusCell((rowNumber ?? 0) + 1, colIndex, column, 'vertical', event);
|
|
1278
|
+
}
|
|
1279
|
+
if (event.key === 'ArrowUp' && (rowNumber ?? 0) > 0) {
|
|
1280
|
+
handleFocusCell((rowNumber ?? 0) - 1, colIndex, column, 'vertical', event);
|
|
1281
|
+
}
|
|
1282
|
+
},
|
|
1283
|
+
onPaste: event => {
|
|
1284
|
+
if (editingKey === '') {
|
|
1285
|
+
handlePaste(record, colIndex, rowNumber, event);
|
|
715
1286
|
event.preventDefault();
|
|
716
|
-
} else {
|
|
717
|
-
if (editingKey !== '') {} else {
|
|
718
|
-
handleFocusCell(rowIndex, colIndex - 1, column, 'horizontal', event);
|
|
719
|
-
}
|
|
720
1287
|
}
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
}
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
dataIndex: column.dataIndex,
|
|
756
|
-
title: column.title,
|
|
757
|
-
'data-col-index': colIndex,
|
|
758
|
-
'data-row-index': rowIndex,
|
|
759
|
-
// colIndex: colIndex,
|
|
760
|
-
indexCol: colIndex,
|
|
761
|
-
indexRow: rowIndex,
|
|
762
|
-
editing: isEditing(record),
|
|
763
|
-
tabIndex: (rowIndex ?? 0) * columns.length + colIndex
|
|
764
|
-
}),
|
|
1288
|
+
},
|
|
1289
|
+
onCopy: e => {
|
|
1290
|
+
if (editingKey === '') {
|
|
1291
|
+
handleCopy(e);
|
|
1292
|
+
e.preventDefault();
|
|
1293
|
+
}
|
|
1294
|
+
},
|
|
1295
|
+
onDoubleClick: event => {
|
|
1296
|
+
if (!isEditing(record) && record[rowKey] !== editingKey) {
|
|
1297
|
+
handleEdit(record, column, (0, _hooks.getEditType)(column, record), event);
|
|
1298
|
+
handleCellClick(rowNumber, record, column);
|
|
1299
|
+
}
|
|
1300
|
+
},
|
|
1301
|
+
onClick: () => {
|
|
1302
|
+
if (record[rowKey] !== editingKey && editingKey !== '') {
|
|
1303
|
+
setEditingKey('');
|
|
1304
|
+
}
|
|
1305
|
+
},
|
|
1306
|
+
// className: isEditing(record) ? 'rc-ui-cell-editable cell-editing' : 'rc-ui-cell-editable cell-editable',
|
|
1307
|
+
className: getCellClass(record, rowNumber, colIndex),
|
|
1308
|
+
record,
|
|
1309
|
+
column: column,
|
|
1310
|
+
editType: (0, _hooks.getEditType)(column, record),
|
|
1311
|
+
dataIndex: column.dataIndex,
|
|
1312
|
+
title: (0, _columns.getValueCell)(column, record[column.field], format),
|
|
1313
|
+
'data-col-index': colIndex,
|
|
1314
|
+
'data-row-index': rowNumber,
|
|
1315
|
+
editing: isEditing(record),
|
|
1316
|
+
tabIndex: (rowIndex ?? 0) * columns.length + colIndex,
|
|
1317
|
+
style: isPasteDragging ? {
|
|
1318
|
+
cursor: "crosshair"
|
|
1319
|
+
} : {}
|
|
1320
|
+
};
|
|
1321
|
+
},
|
|
765
1322
|
render: (value, record, rowIndex) => {
|
|
766
1323
|
const rowNumber = (0, _hooks.getRowNumber)(dataSource, record[rowKey], rowKey);
|
|
767
1324
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
@@ -769,13 +1326,26 @@ const GridEdit = props => {
|
|
|
769
1326
|
// selected: selectedCells.has(`${record[rowKey]}-${colIndex}`)
|
|
770
1327
|
selected: selectedCells.has(`${rowNumber}-${colIndex}`)
|
|
771
1328
|
}),
|
|
772
|
-
onMouseDown: event => handleMouseDown(rowNumber, colIndex, event)
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
onMouseEnter: () => handleMouseEnter(rowNumber, colIndex)
|
|
1329
|
+
onMouseDown: event => handleMouseDown(record, rowNumber, colIndex, event),
|
|
1330
|
+
onMouseEnter: () => handleMouseEnter(rowNumber, colIndex),
|
|
1331
|
+
onMouseUp: handleMouseUp
|
|
776
1332
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
777
1333
|
className: 'ui-rc_content'
|
|
778
|
-
}, (0,
|
|
1334
|
+
}, (0, _columns.renderContent)(column, value, record, rowIndex, format)), (0, _hooks.getLastSelectCell)(selectedCells).row === rowNumber && (0, _hooks.getLastSelectCell)(selectedCells).col === colIndex && !isSelectDragging &&
|
|
1335
|
+
/*#__PURE__*/
|
|
1336
|
+
// showDraggingPoint &&
|
|
1337
|
+
_react.default.createElement("div", {
|
|
1338
|
+
className: 'dragging-point'
|
|
1339
|
+
// onMouseEnter={(event) => handlePointEnter(event)}
|
|
1340
|
+
// onMouseLeave={() => handlePointLeave()}
|
|
1341
|
+
,
|
|
1342
|
+
onMouseDown: () => {
|
|
1343
|
+
setIsPasteDragging(true);
|
|
1344
|
+
},
|
|
1345
|
+
onDoubleClick: handlePointDoubleClick
|
|
1346
|
+
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
1347
|
+
className: 'dot-point'
|
|
1348
|
+
})));
|
|
779
1349
|
}
|
|
780
1350
|
};
|
|
781
1351
|
});
|
|
@@ -803,7 +1373,12 @@ const GridEdit = props => {
|
|
|
803
1373
|
}, [convertColumns]);
|
|
804
1374
|
const mergedColumns = _react.default.useMemo(() => transformColumns(columns ?? []), [transformColumns, columns]);
|
|
805
1375
|
const bottomToolbar = () => {
|
|
806
|
-
return /*#__PURE__*/_react.default.createElement("div",
|
|
1376
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
1377
|
+
className: 'ui-rc-toolbar-bottom',
|
|
1378
|
+
style: {
|
|
1379
|
+
borderBottom: '1px solid #e0e0e0'
|
|
1380
|
+
}
|
|
1381
|
+
}, /*#__PURE__*/_react.default.createElement(_rcMasterUi.Toolbar, {
|
|
807
1382
|
style: {
|
|
808
1383
|
width: '100%'
|
|
809
1384
|
},
|
|
@@ -814,6 +1389,9 @@ const GridEdit = props => {
|
|
|
814
1389
|
// }}
|
|
815
1390
|
}));
|
|
816
1391
|
};
|
|
1392
|
+
const onSelectChange = keys => {
|
|
1393
|
+
setMergedSelectedKeys(keys);
|
|
1394
|
+
};
|
|
817
1395
|
return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement(_GridStyle.GridStyle, {
|
|
818
1396
|
heightTable: height,
|
|
819
1397
|
style: {
|
|
@@ -833,6 +1411,23 @@ const GridEdit = props => {
|
|
|
833
1411
|
}
|
|
834
1412
|
}, /*#__PURE__*/_react.default.createElement("form", {
|
|
835
1413
|
onSubmit: handleSubmit(onSubmit)
|
|
1414
|
+
}, /*#__PURE__*/_react.default.createElement(_rcMasterUi.ConfigProvider, {
|
|
1415
|
+
theme: {
|
|
1416
|
+
components: {
|
|
1417
|
+
Table: {
|
|
1418
|
+
rowHoverBg: '#eb461912',
|
|
1419
|
+
rowSelectedBg: '#eb4619',
|
|
1420
|
+
rowSelectedHoverBg: '#eb4619',
|
|
1421
|
+
cellFontSize: 12,
|
|
1422
|
+
cellFontSizeSM: 13,
|
|
1423
|
+
headerBg: '#ffffff'
|
|
1424
|
+
// cellPaddingBlock: 0,
|
|
1425
|
+
// cellPaddingBlockSM: 0,
|
|
1426
|
+
// cellPaddingInlineSM: 0,
|
|
1427
|
+
// cellPaddingInline: 0
|
|
1428
|
+
}
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
836
1431
|
}, /*#__PURE__*/_react.default.createElement(_TableGrid.default, (0, _extends2.default)({}, rest, {
|
|
837
1432
|
t: t,
|
|
838
1433
|
tableRef: tableRef,
|
|
@@ -845,6 +1440,7 @@ const GridEdit = props => {
|
|
|
845
1440
|
},
|
|
846
1441
|
className: (0, _classnames.default)(className, 'grid-editable'),
|
|
847
1442
|
rowKey: rowKey,
|
|
1443
|
+
getRowKey: getRowKey,
|
|
848
1444
|
columns: mergedColumns,
|
|
849
1445
|
showSorterTooltip: {
|
|
850
1446
|
target: 'sorter-icon'
|
|
@@ -855,13 +1451,51 @@ const GridEdit = props => {
|
|
|
855
1451
|
...selectionSettings,
|
|
856
1452
|
checkboxOnly: true
|
|
857
1453
|
} : undefined,
|
|
858
|
-
style: {
|
|
859
|
-
...style,
|
|
860
|
-
minHeight: height
|
|
861
|
-
},
|
|
862
1454
|
rowHoverable: false,
|
|
863
|
-
bottomToolbar: bottomToolbar
|
|
864
|
-
|
|
1455
|
+
bottomToolbar: bottomToolbar,
|
|
1456
|
+
expandable: {
|
|
1457
|
+
...expandable,
|
|
1458
|
+
expandedRowKeys: innerExpandedKeys,
|
|
1459
|
+
expandIcon: args => {
|
|
1460
|
+
const {
|
|
1461
|
+
record,
|
|
1462
|
+
expanded
|
|
1463
|
+
} = args;
|
|
1464
|
+
|
|
1465
|
+
// @ts-ignore
|
|
1466
|
+
if (record?.children?.length > 0 || record?.isChildren) {
|
|
1467
|
+
return expanded ? /*#__PURE__*/_react.default.createElement("button", {
|
|
1468
|
+
onClick: e => {
|
|
1469
|
+
e.preventDefault();
|
|
1470
|
+
e.stopPropagation();
|
|
1471
|
+
onTriggerExpand(record);
|
|
1472
|
+
// onExpand(record, e)
|
|
1473
|
+
},
|
|
1474
|
+
className: 'ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-expanded'
|
|
1475
|
+
}) : /*#__PURE__*/_react.default.createElement("button", {
|
|
1476
|
+
onClick: e => {
|
|
1477
|
+
e.preventDefault();
|
|
1478
|
+
e.stopPropagation();
|
|
1479
|
+
onTriggerExpand(record);
|
|
1480
|
+
// onExpand(record, e)
|
|
1481
|
+
},
|
|
1482
|
+
className: 'ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-collapsed'
|
|
1483
|
+
});
|
|
1484
|
+
} else {
|
|
1485
|
+
return /*#__PURE__*/_react.default.createElement("button", {
|
|
1486
|
+
className: 'ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-spaced'
|
|
1487
|
+
});
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
},
|
|
1491
|
+
rowSelection: columns && columns.length === 0 ? undefined : {
|
|
1492
|
+
type: mode === 'checkbox' || type === 'multiple' ? 'checkbox' : "radio",
|
|
1493
|
+
columnWidth: !mode ? 0.0000001 : columnWidth ?? 50,
|
|
1494
|
+
onChange: onSelectChange,
|
|
1495
|
+
selectedRowKeys: mergedSelectedKeys,
|
|
1496
|
+
preserveSelectedRowKeys: true
|
|
1497
|
+
}
|
|
1498
|
+
})))))), /*#__PURE__*/_react.default.createElement(_reactHotToast.Toaster, {
|
|
865
1499
|
position: toast,
|
|
866
1500
|
toastOptions: {
|
|
867
1501
|
className: 'react-hot-toast'
|