es-grid-template 1.4.0 → 1.4.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/es/grid-component/EditableCell.js +46 -15
- package/es/grid-component/InternalTable.d.ts +1 -0
- package/es/grid-component/InternalTable.js +469 -113
- package/es/grid-component/TableGrid.js +46 -48
- package/es/grid-component/hooks/columns/index.d.ts +1 -1
- package/es/grid-component/hooks/columns/index.js +3 -13
- package/es/grid-component/hooks/useColumns.js +5 -2
- package/es/grid-component/hooks/utils.d.ts +17 -2
- package/es/grid-component/hooks/utils.js +24 -5
- package/es/grid-component/styles.scss +1186 -1170
- package/es/grid-component/table/Grid.d.ts +1 -0
- package/es/grid-component/table/GridEdit.d.ts +1 -0
- package/es/grid-component/table/GridEdit.js +190 -140
- package/es/grid-component/table/Group.d.ts +1 -0
- package/es/grid-component/type.d.ts +7 -2
- package/es/grid-component/useContext.d.ts +1 -0
- package/lib/grid-component/EditableCell.js +46 -15
- package/lib/grid-component/InternalTable.d.ts +1 -0
- package/lib/grid-component/InternalTable.js +469 -102
- package/lib/grid-component/TableGrid.js +45 -47
- package/lib/grid-component/hooks/columns/index.d.ts +1 -1
- package/lib/grid-component/hooks/columns/index.js +5 -15
- package/lib/grid-component/hooks/useColumns.js +4 -1
- package/lib/grid-component/hooks/utils.d.ts +17 -2
- package/lib/grid-component/hooks/utils.js +26 -6
- package/lib/grid-component/styles.scss +1186 -1170
- package/lib/grid-component/table/Grid.d.ts +1 -0
- package/lib/grid-component/table/GridEdit.d.ts +1 -0
- package/lib/grid-component/table/GridEdit.js +189 -139
- package/lib/grid-component/table/Group.d.ts +1 -0
- package/lib/grid-component/type.d.ts +7 -2
- package/lib/grid-component/useContext.d.ts +1 -0
- package/package.json +5 -5
|
@@ -12,6 +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 _yup = require("@hookform/resolvers/yup");
|
|
15
16
|
var _columns = require("../hooks/columns");
|
|
16
17
|
var _EditableCell = _interopRequireDefault(require("../EditableCell"));
|
|
17
18
|
var _GridStyle = require("../GridStyle");
|
|
@@ -25,6 +26,7 @@ var _Message = _interopRequireDefault(require("../../Message/Message"));
|
|
|
25
26
|
var _rcMasterUi = require("rc-master-ui");
|
|
26
27
|
var _becoxyIcons = require("becoxy-icons");
|
|
27
28
|
var _faker = require("@faker-js/faker");
|
|
29
|
+
var _InternalTable = require("../InternalTable");
|
|
28
30
|
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); }
|
|
29
31
|
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
32
|
const {
|
|
@@ -33,7 +35,6 @@ const {
|
|
|
33
35
|
} = _antd.Typography;
|
|
34
36
|
_dayjs.default.extend(_customParseFormat.default);
|
|
35
37
|
const toast = 'top-right';
|
|
36
|
-
// const defaultContext: ContextMenuItem[] = [
|
|
37
38
|
const defaultContext = [{
|
|
38
39
|
key: 'INSERT_BEFORE',
|
|
39
40
|
label: 'Thêm dòng bên trên',
|
|
@@ -96,6 +97,44 @@ const defaultContext = [{
|
|
|
96
97
|
key: 'INSERT_AFTER_ADV',
|
|
97
98
|
label: 'Tùy chỉnh'
|
|
98
99
|
}]
|
|
100
|
+
}, {
|
|
101
|
+
key: 'INSERT_CHILDREN',
|
|
102
|
+
// label: 'Insert item children',
|
|
103
|
+
label: 'Thêm cấp con',
|
|
104
|
+
icon: /*#__PURE__*/_react.default.createElement(_becoxyIcons.Plus, {
|
|
105
|
+
fontSize: 14
|
|
106
|
+
})
|
|
107
|
+
// children: [
|
|
108
|
+
// {
|
|
109
|
+
// parentKey: 'INSERT_AFTER',
|
|
110
|
+
// key: 'INSERT_AFTER_1',
|
|
111
|
+
// label: 'Thêm 1 dòng',
|
|
112
|
+
// row: 1
|
|
113
|
+
// },
|
|
114
|
+
// {
|
|
115
|
+
// parentKey: 'INSERT_AFTER',
|
|
116
|
+
// key: 'INSERT_AFTER_10',
|
|
117
|
+
// label: 'Thêm 10 dòng',
|
|
118
|
+
// row: 10
|
|
119
|
+
// },
|
|
120
|
+
// {
|
|
121
|
+
// parentKey: 'INSERT_AFTER',
|
|
122
|
+
// key: 'INSERT_AFTER_50',
|
|
123
|
+
// label: 'Thêm 50 dòng',
|
|
124
|
+
// row: 50
|
|
125
|
+
// },
|
|
126
|
+
// {
|
|
127
|
+
// parentKey: 'INSERT_AFTER',
|
|
128
|
+
// key: 'INSERT_AFTER_100',
|
|
129
|
+
// label: 'Thêm 100 dòng',
|
|
130
|
+
// row: 100
|
|
131
|
+
// },
|
|
132
|
+
// {
|
|
133
|
+
// parentKey: 'INSERT_AFTER',
|
|
134
|
+
// key: 'INSERT_AFTER_ADV',
|
|
135
|
+
// label: 'Tùy chỉnh'
|
|
136
|
+
// }
|
|
137
|
+
// ]
|
|
99
138
|
}, {
|
|
100
139
|
key: 'DELETE_CONTENT',
|
|
101
140
|
label: 'Xóa nội dung',
|
|
@@ -109,6 +148,37 @@ const defaultContext = [{
|
|
|
109
148
|
fontSize: 14
|
|
110
149
|
})
|
|
111
150
|
}];
|
|
151
|
+
const validateData = async (data, formSchema) => {
|
|
152
|
+
if (!formSchema) {
|
|
153
|
+
return [];
|
|
154
|
+
} else {
|
|
155
|
+
const errors = [];
|
|
156
|
+
for (let i = 0; i < data.length; i++) {
|
|
157
|
+
try {
|
|
158
|
+
await formSchema.validate(data[i], {
|
|
159
|
+
abortEarly: false
|
|
160
|
+
});
|
|
161
|
+
} catch (error) {
|
|
162
|
+
errors.push(error.inner.reduce((acc, err) => {
|
|
163
|
+
acc[err.path] = {
|
|
164
|
+
field: err.path,
|
|
165
|
+
index: i,
|
|
166
|
+
message: err.message,
|
|
167
|
+
type: err.type,
|
|
168
|
+
ref: {
|
|
169
|
+
name: err.path
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
return {
|
|
173
|
+
...acc,
|
|
174
|
+
index: i
|
|
175
|
+
};
|
|
176
|
+
}, {}));
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return errors;
|
|
180
|
+
}
|
|
181
|
+
};
|
|
112
182
|
const GridEdit = props => {
|
|
113
183
|
const {
|
|
114
184
|
id: tableId,
|
|
@@ -137,6 +207,8 @@ const GridEdit = props => {
|
|
|
137
207
|
rowEditable,
|
|
138
208
|
contextMenuItems: propsContext,
|
|
139
209
|
showDefaultContext,
|
|
210
|
+
validate,
|
|
211
|
+
setTooltipContent,
|
|
140
212
|
...rest
|
|
141
213
|
} = props;
|
|
142
214
|
const ref = (0, _react.useRef)(null);
|
|
@@ -157,6 +229,9 @@ const GridEdit = props => {
|
|
|
157
229
|
// quét vùng được paste - tiếp tục hiển thị con trỏ crosshair
|
|
158
230
|
// const isPasteDragging = useRef(false);
|
|
159
231
|
|
|
232
|
+
const visibleCols = _react.default.useMemo(() => {
|
|
233
|
+
return (0, _columns.flatColumns2)(columns.filter(it => it.visible !== false));
|
|
234
|
+
}, [columns]);
|
|
160
235
|
const id = _react.default.useMemo(() => {
|
|
161
236
|
return tableId ?? _faker.faker.string.alpha(20);
|
|
162
237
|
// return tableId ?? newGuid()
|
|
@@ -173,33 +248,17 @@ const GridEdit = props => {
|
|
|
173
248
|
}];
|
|
174
249
|
const [form] = _antd.Form.useForm();
|
|
175
250
|
const [editingKey, setEditingKey] = (0, _react.useState)('');
|
|
251
|
+
const [dataErrors, setDataErrors] = (0, _react.useState)([]);
|
|
176
252
|
const [isFilter, setIsFilter] = _react.default.useState(false);
|
|
177
253
|
const [rangeCells, setRangeCells] = (0, _react.useState)(new Set());
|
|
178
|
-
|
|
179
|
-
// const [pasteCells, setPasteCells] = 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
254
|
const [openModalAddRow, setOpenModalAddRow] = (0, _react.useState)({
|
|
189
255
|
open: false,
|
|
190
256
|
type: ''
|
|
191
257
|
});
|
|
192
258
|
const [rowsAdd, setRowsAdd] = (0, _react.useState)(1);
|
|
193
259
|
const [cellEditing, setCellEditing] = (0, _react.useState)(null);
|
|
194
|
-
|
|
195
|
-
// const [isSelectDragging, setSelectIsDragging] = useState(false)
|
|
196
|
-
|
|
197
260
|
const [isPasteDragging, setIsPasteDragging] = (0, _react.useState)(false); // isPasteDragging == tiếp tục hiển thị con trỏ crosshair
|
|
198
261
|
|
|
199
|
-
// const [rowsSelected, setRowsSelected] = useState(new Set())
|
|
200
|
-
|
|
201
|
-
// const [startSelectedCells, setStartSelectedCell] = useState<{ row: number; col: number } | null>(null)
|
|
202
|
-
|
|
203
262
|
const [innerExpandedKeys, setInnerExpandedKeys] = _react.default.useState(() => {
|
|
204
263
|
// if (defaultExpandedRowKeys) {
|
|
205
264
|
// return defaultExpandedRowKeys;
|
|
@@ -210,6 +269,16 @@ const GridEdit = props => {
|
|
|
210
269
|
// return [];
|
|
211
270
|
});
|
|
212
271
|
const mergedExpandedKeys = _react.default.useMemo(() => new Set(innerExpandedKeys || []), [innerExpandedKeys]);
|
|
272
|
+
_react.default.useEffect(() => {
|
|
273
|
+
if (validate && dataSource && dataSource.length) {
|
|
274
|
+
validateData(dataSource, validate).then(error => {
|
|
275
|
+
setDataErrors([...error]);
|
|
276
|
+
// if (getErrors) {
|
|
277
|
+
// getErrors([...error])
|
|
278
|
+
// }
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
}, [validate, dataSource]);
|
|
213
282
|
const rowsFocus = _react.default.useMemo(() => {
|
|
214
283
|
return [...new Set(Array.from(rangeCells).map(item => parseInt(item.split('-')[0])))] ?? [];
|
|
215
284
|
}, [rangeCells]);
|
|
@@ -231,8 +300,11 @@ const GridEdit = props => {
|
|
|
231
300
|
newExpandedKeys = [...mergedExpandedKeys, key];
|
|
232
301
|
}
|
|
233
302
|
setInnerExpandedKeys(newExpandedKeys);
|
|
234
|
-
|
|
235
|
-
|
|
303
|
+
//
|
|
304
|
+
// onAddBgSelectedCell(rangeCells, id)
|
|
305
|
+
// onAddBorderSelectedCell(rangeCells, id)
|
|
306
|
+
}, [getRowKey, dataSource, mergedExpandedKeys]);
|
|
307
|
+
const handleAddSingle = _react.default.useCallback(item => {
|
|
236
308
|
const defaultRowValue = (0, _hooks.getDefaultValue)(defaultValue);
|
|
237
309
|
const rowId = defaultRowValue && defaultRowValue.id ? defaultRowValue.id : (0, _hooks.newGuid)();
|
|
238
310
|
if (item && item.onClick) {
|
|
@@ -250,8 +322,8 @@ const GridEdit = props => {
|
|
|
250
322
|
}];
|
|
251
323
|
triggerChangeData?.(newData, 'Add');
|
|
252
324
|
}
|
|
253
|
-
};
|
|
254
|
-
const handleAddMulti = (item, e) => {
|
|
325
|
+
}, [dataSource, defaultValue, triggerChangeData]);
|
|
326
|
+
const handleAddMulti = _react.default.useCallback((item, e) => {
|
|
255
327
|
if (item.onClick) {
|
|
256
328
|
item.onClick({
|
|
257
329
|
toolbar: item
|
|
@@ -271,8 +343,8 @@ const GridEdit = props => {
|
|
|
271
343
|
const newData = dataSource.concat(newRows);
|
|
272
344
|
triggerChangeData?.(newData, 'Add');
|
|
273
345
|
}
|
|
274
|
-
};
|
|
275
|
-
const handleDuplicate = () => {
|
|
346
|
+
}, [dataSource, defaultValue, triggerChangeData]);
|
|
347
|
+
const handleDuplicate = _react.default.useCallback(() => {
|
|
276
348
|
// không tính tree
|
|
277
349
|
|
|
278
350
|
// Cập nhật data mới
|
|
@@ -288,10 +360,10 @@ const GridEdit = props => {
|
|
|
288
360
|
const insertAfter = Math.max(...rowsFocus);
|
|
289
361
|
const rs = [...newData.slice(0, insertAfter + 1), ...duplicatedItems, ...newData.slice(insertAfter + 1)];
|
|
290
362
|
triggerChangeData?.(rs, 'DUPLICATE');
|
|
291
|
-
};
|
|
363
|
+
}, [dataSource, rowsFocus, triggerChangeData]);
|
|
292
364
|
|
|
293
365
|
// thêm n dòng bên trên
|
|
294
|
-
const handleInsertBefore = (item, n) => {
|
|
366
|
+
const handleInsertBefore = _react.default.useCallback((item, n) => {
|
|
295
367
|
//
|
|
296
368
|
(0, _hooks.onRemoveBgSelectedCell)(selectedCells.current, id);
|
|
297
369
|
(0, _hooks.onRemoveBorderSelectedCell)(selectedCells.current, id);
|
|
@@ -370,10 +442,10 @@ const GridEdit = props => {
|
|
|
370
442
|
triggerChangeData?.(newDataSource, 'INSERT_BEFORE');
|
|
371
443
|
}
|
|
372
444
|
}
|
|
373
|
-
};
|
|
445
|
+
}, [dataSource, defaultValue, id, isFilter, rowKey, rowsFocus, triggerChangeData]);
|
|
374
446
|
|
|
375
447
|
//thêm 1 dòng bên dưới
|
|
376
|
-
const handleInsertAfter = (item, n) => {
|
|
448
|
+
const handleInsertAfter = _react.default.useCallback((item, n) => {
|
|
377
449
|
const defaultRowValue = (0, _hooks.getDefaultValue)(defaultValue);
|
|
378
450
|
const record = (0, _hooks.flattenData)(childrenColumnName, dataSource)[rowsFocus[rowsFocus.length - 1]];
|
|
379
451
|
|
|
@@ -444,8 +516,8 @@ const GridEdit = props => {
|
|
|
444
516
|
triggerChangeData?.(newDataSource, 'INSERT_BEFORE');
|
|
445
517
|
}
|
|
446
518
|
}
|
|
447
|
-
};
|
|
448
|
-
const handleInsertChild = item => {
|
|
519
|
+
}, [dataSource, defaultValue, isFilter, rowKey, rowsFocus, triggerChangeData]);
|
|
520
|
+
const handleInsertChild = _react.default.useCallback(item => {
|
|
449
521
|
const defaultRowValue = (0, _hooks.getDefaultValue)(defaultValue);
|
|
450
522
|
const rowId = defaultRowValue && defaultRowValue.id ? defaultRowValue.id : (0, _hooks.newGuid)();
|
|
451
523
|
const record = (0, _hooks.flattenData)(childrenColumnName, dataSource)[rowsFocus[rowsFocus.length - 1]];
|
|
@@ -486,8 +558,8 @@ const GridEdit = props => {
|
|
|
486
558
|
const newExpandedKeys = [...mergedExpandedKeys, key];
|
|
487
559
|
setInnerExpandedKeys(newExpandedKeys);
|
|
488
560
|
}
|
|
489
|
-
};
|
|
490
|
-
const handleDeleteRows = item => {
|
|
561
|
+
}, [dataSource, defaultValue, getRowKey, mergedExpandedKeys, rowKey, rowsFocus, triggerChangeData]);
|
|
562
|
+
const handleDeleteRows = _react.default.useCallback(item => {
|
|
491
563
|
setTimeout(() => {
|
|
492
564
|
(0, _hooks.onAddBgSelectedCell)(selectedCells.current, id);
|
|
493
565
|
(0, _hooks.onAddBorderSelectedCell)(selectedCells.current, id);
|
|
@@ -506,16 +578,16 @@ const GridEdit = props => {
|
|
|
506
578
|
});
|
|
507
579
|
triggerChangeData?.([...newData], 'DELETE_ROWS');
|
|
508
580
|
}
|
|
509
|
-
};
|
|
510
|
-
const handleDeleteAll = () => {
|
|
581
|
+
}, [dataSource, id, rowsFocus, triggerChangeData]);
|
|
582
|
+
const handleDeleteAll = _react.default.useCallback(() => {
|
|
511
583
|
triggerChangeData?.([], 'INSERT_BEFORE');
|
|
512
|
-
};
|
|
513
|
-
const handleDeleteContent = () => {
|
|
584
|
+
}, [triggerChangeData]);
|
|
585
|
+
const handleDeleteContent = _react.default.useCallback(() => {
|
|
514
586
|
if (selectedCells.current.size > 0) {
|
|
515
587
|
const newData = [...dataSource];
|
|
516
588
|
|
|
517
589
|
// colIndex => field
|
|
518
|
-
const colIndexToField = (0, _columns.flatColumns2)(
|
|
590
|
+
const colIndexToField = (0, _columns.flatColumns2)(visibleCols).map(col => col.field);
|
|
519
591
|
|
|
520
592
|
// Duyệt qua mỗi ô cần xóa
|
|
521
593
|
for (const cell of selectedCells.current) {
|
|
@@ -530,7 +602,7 @@ const GridEdit = props => {
|
|
|
530
602
|
}
|
|
531
603
|
triggerChangeData?.([...newData], 'DELETE_CONTENT');
|
|
532
604
|
}
|
|
533
|
-
};
|
|
605
|
+
}, [dataSource, triggerChangeData, visibleCols]);
|
|
534
606
|
const toolbarItemsBottom = (0, _react.useMemo)(() => {
|
|
535
607
|
if (!rowsFocus || rowsFocus.length === 0) {
|
|
536
608
|
return toolbarItems?.filter(it => it.position === 'Bottom' && it.visible !== false && it.key !== 'DUPLICATE' && it.key !== 'INSERT_BEFORE' && it.key !== 'INSERT_AFTER' && it.key !== 'DELETE_ROWS' && it.key !== 'INSERT_CHILDREN').map(item => {
|
|
@@ -695,7 +767,7 @@ const GridEdit = props => {
|
|
|
695
767
|
variant: 'outlined',
|
|
696
768
|
onClick: () => handleInsertChild(item),
|
|
697
769
|
className: "d-flex toolbar-button"
|
|
698
|
-
}, item.label ? t ? t(item.label) : item.label : t ? t('Insert item
|
|
770
|
+
}, item.label ? t ? t(item.label) : item.label : t ? t('Insert item children') : 'Insert item children')));
|
|
699
771
|
}
|
|
700
772
|
};
|
|
701
773
|
}
|
|
@@ -739,19 +811,24 @@ const GridEdit = props => {
|
|
|
739
811
|
...item
|
|
740
812
|
};
|
|
741
813
|
});
|
|
742
|
-
}, [handleAddMulti, handleAddSingle, itemsAdd, rowsFocus
|
|
814
|
+
}, [handleAddMulti, handleAddSingle, handleDeleteAll, handleDeleteRows, handleDuplicate, handleInsertAfter, handleInsertBefore, handleInsertChild, itemsAdd, rowsFocus, t, toolbarItems]);
|
|
743
815
|
const {
|
|
744
816
|
control,
|
|
745
817
|
handleSubmit,
|
|
746
818
|
setValue,
|
|
747
819
|
trigger,
|
|
748
820
|
getValues,
|
|
749
|
-
reset
|
|
821
|
+
reset,
|
|
822
|
+
formState: {
|
|
823
|
+
errors
|
|
824
|
+
}
|
|
750
825
|
} = (0, _reactHookForm.useForm)({
|
|
751
|
-
mode: 'onChange'
|
|
752
|
-
|
|
826
|
+
mode: 'onChange',
|
|
827
|
+
resolver: (0, _yup.yupResolver)(validate)
|
|
753
828
|
});
|
|
754
|
-
const isEditing = record =>
|
|
829
|
+
const isEditing = _react.default.useCallback(record => {
|
|
830
|
+
return record[rowKey] === editingKey;
|
|
831
|
+
}, [editingKey, rowKey]);
|
|
755
832
|
(0, _react.useEffect)(() => {
|
|
756
833
|
const handleClickOutside = event => {
|
|
757
834
|
const element = event.target;
|
|
@@ -796,8 +873,11 @@ const GridEdit = props => {
|
|
|
796
873
|
return () => {
|
|
797
874
|
document.removeEventListener("click", handleClickOutside);
|
|
798
875
|
};
|
|
799
|
-
}, []);
|
|
876
|
+
}, [id]);
|
|
800
877
|
const handleMouseDown = (record, row, col, e) => {
|
|
878
|
+
if (editingKey && editingKey === record[rowKey]) {
|
|
879
|
+
return;
|
|
880
|
+
}
|
|
801
881
|
if (e.button === 2) {
|
|
802
882
|
e.stopPropagation();
|
|
803
883
|
return;
|
|
@@ -853,7 +933,7 @@ const GridEdit = props => {
|
|
|
853
933
|
setTimeout(() => {
|
|
854
934
|
(0, _hooks.onAddBgSelectedCell)(cells, id);
|
|
855
935
|
(0, _hooks.onAddBorderSelectedCell)(cells, id);
|
|
856
|
-
},
|
|
936
|
+
}, 200);
|
|
857
937
|
} else {
|
|
858
938
|
(0, _hooks.onAddBgSelectedCell)(cells, id);
|
|
859
939
|
(0, _hooks.onAddBorderSelectedCell)(cells, id);
|
|
@@ -867,7 +947,9 @@ const GridEdit = props => {
|
|
|
867
947
|
};
|
|
868
948
|
const triggerDragPaste = pastesArray => {
|
|
869
949
|
const mergedSet = new Set([...selectedCells.current, ...pastesArray]);
|
|
870
|
-
const tmpCols =
|
|
950
|
+
const tmpCols = {
|
|
951
|
+
...visibleCols
|
|
952
|
+
};
|
|
871
953
|
const rowSelectedFirst = (0, _hooks.getFirstSelectCell)(selectedCells.current).row;
|
|
872
954
|
const rowPasteLast = (0, _hooks.getLastSelectCell)(pasteCells.current).row;
|
|
873
955
|
const selectedArray = Array.from(selectedCells.current).map(key => {
|
|
@@ -998,9 +1080,12 @@ const GridEdit = props => {
|
|
|
998
1080
|
// selectedCells.current = sortedSetASC(mergedSet)
|
|
999
1081
|
(0, _hooks.hideDraggingPoint)(selectedCells.current, id);
|
|
1000
1082
|
selectedCells.current = (0, _hooks.sortedSetASC)(mergedSet);
|
|
1001
|
-
(
|
|
1002
|
-
(
|
|
1003
|
-
|
|
1083
|
+
setRangeCells((0, _hooks.sortedSetASC)(mergedSet));
|
|
1084
|
+
setTimeout(() => {
|
|
1085
|
+
(0, _hooks.onAddBgSelectedCell)((0, _hooks.sortedSetASC)(mergedSet), id);
|
|
1086
|
+
(0, _hooks.onAddBorderSelectedCell)((0, _hooks.sortedSetASC)(mergedSet), id);
|
|
1087
|
+
(0, _hooks.showDraggingPoint)((0, _hooks.sortedSetASC)(mergedSet), id);
|
|
1088
|
+
}, 50);
|
|
1004
1089
|
|
|
1005
1090
|
// setPasteCells(new Set())
|
|
1006
1091
|
|
|
@@ -1024,27 +1109,6 @@ const GridEdit = props => {
|
|
|
1024
1109
|
(0, _hooks.hideDraggingPoint)(selectedCells.current, id);
|
|
1025
1110
|
triggerDragPaste(newPasteCells);
|
|
1026
1111
|
};
|
|
1027
|
-
|
|
1028
|
-
// const handleClickCell = (e: any) => {
|
|
1029
|
-
//
|
|
1030
|
-
// if (e.ctrlKey) {
|
|
1031
|
-
//
|
|
1032
|
-
// const cell: any = new Set([`${row}-${col}`])
|
|
1033
|
-
//
|
|
1034
|
-
// const found = ctrlCells.find((s: any) => isEqualSet(s, cell));
|
|
1035
|
-
//
|
|
1036
|
-
// if (found) {
|
|
1037
|
-
// const rs = ctrlCells.filter((s: any) => !isEqualSet(s, cell));
|
|
1038
|
-
//
|
|
1039
|
-
// setCtrlCells(rs)
|
|
1040
|
-
//
|
|
1041
|
-
// } else {
|
|
1042
|
-
// setCtrlCells([...ctrlCells, cell])
|
|
1043
|
-
// }
|
|
1044
|
-
//
|
|
1045
|
-
// }
|
|
1046
|
-
// }
|
|
1047
|
-
|
|
1048
1112
|
const handleMouseUp = e => {
|
|
1049
1113
|
isSelecting.current = false;
|
|
1050
1114
|
startCell.current = null;
|
|
@@ -1084,15 +1148,6 @@ const GridEdit = props => {
|
|
|
1084
1148
|
(0, _hooks.showDraggingPoint)(selectedCells.current, id);
|
|
1085
1149
|
}
|
|
1086
1150
|
};
|
|
1087
|
-
|
|
1088
|
-
// const handlePointEnter = () => {
|
|
1089
|
-
// isPointEnter.current = true;
|
|
1090
|
-
// }
|
|
1091
|
-
//
|
|
1092
|
-
// const handlePointLeave = () => {
|
|
1093
|
-
// isPointEnter.current = false;
|
|
1094
|
-
// }
|
|
1095
|
-
|
|
1096
1151
|
const handleMouseEnter = (row, col, e) => {
|
|
1097
1152
|
if (!isSelecting.current || !startCell.current) {
|
|
1098
1153
|
return;
|
|
@@ -1198,32 +1253,6 @@ const GridEdit = props => {
|
|
|
1198
1253
|
}
|
|
1199
1254
|
}
|
|
1200
1255
|
};
|
|
1201
|
-
|
|
1202
|
-
// const handleClickRowHeader = (row: any, col: any) => {
|
|
1203
|
-
//
|
|
1204
|
-
// const newSelectedCells = new Set()
|
|
1205
|
-
//
|
|
1206
|
-
// const tCols = editAbleColumns(columns)
|
|
1207
|
-
//
|
|
1208
|
-
// for (let r = Math.min(row, row); r <= Math.max(row, row); r++) {
|
|
1209
|
-
// for (let c = Math.min(tCols.length, col) + 1; c <= Math.max(tCols.length, col); c++) {
|
|
1210
|
-
// newSelectedCells.add(`${r}-${c}`)
|
|
1211
|
-
// }
|
|
1212
|
-
// }
|
|
1213
|
-
//
|
|
1214
|
-
// // setSelectedCells(newSelectedCells)
|
|
1215
|
-
//
|
|
1216
|
-
// if (selectedCells.current && selectedCells.current.size > 0) {
|
|
1217
|
-
// onRemoveBgSelectedCell(selectedCells.current, id)
|
|
1218
|
-
// }
|
|
1219
|
-
//
|
|
1220
|
-
// selectedCells.current = newSelectedCells
|
|
1221
|
-
//
|
|
1222
|
-
// onAddBgSelectedCell(newSelectedCells, id)
|
|
1223
|
-
//
|
|
1224
|
-
//
|
|
1225
|
-
// };
|
|
1226
|
-
|
|
1227
1256
|
const handleClickColHeader = (column, indexColumn) => {
|
|
1228
1257
|
const newSelectedCells = new Set();
|
|
1229
1258
|
for (let r = Math.min(dataSource.length, 0); r <= Math.max(dataSource.length - 1, 0); r++) {
|
|
@@ -1258,7 +1287,7 @@ const GridEdit = props => {
|
|
|
1258
1287
|
col
|
|
1259
1288
|
};
|
|
1260
1289
|
const newSelectedCells = new Set();
|
|
1261
|
-
const tCols = (0, _hooks.editAbleColumns)(
|
|
1290
|
+
const tCols = (0, _hooks.editAbleColumns)(visibleCols);
|
|
1262
1291
|
for (let r = Math.min(row, row); r <= Math.max(row, row); r++) {
|
|
1263
1292
|
for (let c = Math.min(tCols.length, col) + 1; c <= Math.max(tCols.length, col); c++) {
|
|
1264
1293
|
newSelectedCells.add(`${r}-${c}`);
|
|
@@ -1278,7 +1307,7 @@ const GridEdit = props => {
|
|
|
1278
1307
|
(0, _hooks.hideDraggingPoint)(selectedCells.current, id);
|
|
1279
1308
|
selectedCells.current = newSelectedCells;
|
|
1280
1309
|
rowsSelected.current = new Set([`${row}-${col}`]);
|
|
1281
|
-
(0, _hooks.onAddBgSelectedCell)(newSelectedCells, id);
|
|
1310
|
+
(0, _hooks.onAddBgSelectedCell)(newSelectedCells, id, false);
|
|
1282
1311
|
(0, _hooks.onAddBorderSelectedCell)(newSelectedCells, id);
|
|
1283
1312
|
(0, _hooks.addClassCellIndexSelected)(new Set([`${row}-${col}`]), id);
|
|
1284
1313
|
};
|
|
@@ -1420,13 +1449,13 @@ const GridEdit = props => {
|
|
|
1420
1449
|
}
|
|
1421
1450
|
rowValues.forEach((cellValue, colIndex) => {
|
|
1422
1451
|
const targetCol = startCol + colIndex;
|
|
1423
|
-
if (targetCol >=
|
|
1452
|
+
if (targetCol >= visibleCols.length) {
|
|
1424
1453
|
// Không vượt quá số cột
|
|
1425
1454
|
return;
|
|
1426
1455
|
}
|
|
1427
|
-
if (
|
|
1456
|
+
if (visibleCols[targetCol].editEnable) {
|
|
1428
1457
|
// @ts-ignore
|
|
1429
|
-
const columnKey =
|
|
1458
|
+
const columnKey = visibleCols[targetCol].field;
|
|
1430
1459
|
|
|
1431
1460
|
// @ts-ignore
|
|
1432
1461
|
newData[targetRow] = {
|
|
@@ -1469,13 +1498,13 @@ const GridEdit = props => {
|
|
|
1469
1498
|
}
|
|
1470
1499
|
rowValues.forEach((cellValue, colIndex) => {
|
|
1471
1500
|
const targetCol = startCol + colIndex;
|
|
1472
|
-
if (targetCol >=
|
|
1501
|
+
if (targetCol >= visibleCols.length) {
|
|
1473
1502
|
// Không vượt quá số cột
|
|
1474
1503
|
return;
|
|
1475
1504
|
}
|
|
1476
|
-
if (
|
|
1505
|
+
if (visibleCols[targetCol].editEnable) {
|
|
1477
1506
|
// @ts-ignore
|
|
1478
|
-
const columnKey =
|
|
1507
|
+
const columnKey = visibleCols[targetCol].field;
|
|
1479
1508
|
|
|
1480
1509
|
// @ts-ignore
|
|
1481
1510
|
childData[targetRow] = {
|
|
@@ -1734,6 +1763,7 @@ const GridEdit = props => {
|
|
|
1734
1763
|
}
|
|
1735
1764
|
};
|
|
1736
1765
|
const handleEdit = (record, col, editType, e) => {
|
|
1766
|
+
setTooltipContent('');
|
|
1737
1767
|
// @ts-ignore
|
|
1738
1768
|
setEditingKey(record[rowKey]);
|
|
1739
1769
|
setCellEditing({
|
|
@@ -1791,7 +1821,7 @@ const GridEdit = props => {
|
|
|
1791
1821
|
// }, []);
|
|
1792
1822
|
|
|
1793
1823
|
const scrollToCell = (rowIndex, colIndex, cell, scrollType) => {
|
|
1794
|
-
const fixedWidth = (0, _hooks.totalFixedWidth)(
|
|
1824
|
+
const fixedWidth = (0, _hooks.totalFixedWidth)(visibleCols, 'left', selectionSettings);
|
|
1795
1825
|
if (scrollType === 'horizontal') {
|
|
1796
1826
|
if (tableRef.current) {
|
|
1797
1827
|
tableRef.current.scrollTo({
|
|
@@ -1884,10 +1914,10 @@ const GridEdit = props => {
|
|
|
1884
1914
|
}
|
|
1885
1915
|
};
|
|
1886
1916
|
const convertColumns = (0, _columns.flatColumns2)(columns.filter(it => it.visible !== false)).map((column, colIndex) => {
|
|
1887
|
-
if (
|
|
1888
|
-
return
|
|
1917
|
+
if (column === _InternalTable.SELECTION_COLUMN) {
|
|
1918
|
+
return _InternalTable.SELECTION_COLUMN;
|
|
1889
1919
|
}
|
|
1890
|
-
if (column.
|
|
1920
|
+
if (column.field === '#') {
|
|
1891
1921
|
return {
|
|
1892
1922
|
...column,
|
|
1893
1923
|
className: 'rc-ui-cell-editable rc-ui-cell-index',
|
|
@@ -1912,7 +1942,7 @@ const GridEdit = props => {
|
|
|
1912
1942
|
setEditingKey('');
|
|
1913
1943
|
}
|
|
1914
1944
|
},
|
|
1915
|
-
tabIndex: (rowIndex ?? 0) *
|
|
1945
|
+
tabIndex: (rowIndex ?? 0) * visibleCols.length + colIndex
|
|
1916
1946
|
};
|
|
1917
1947
|
},
|
|
1918
1948
|
render: (value, record) => {
|
|
@@ -1928,7 +1958,7 @@ const GridEdit = props => {
|
|
|
1928
1958
|
}
|
|
1929
1959
|
};
|
|
1930
1960
|
}
|
|
1931
|
-
if (
|
|
1961
|
+
if (column.field === 'command') {
|
|
1932
1962
|
return {
|
|
1933
1963
|
...column
|
|
1934
1964
|
};
|
|
@@ -1979,14 +2009,16 @@ const GridEdit = props => {
|
|
|
1979
2009
|
}
|
|
1980
2010
|
}
|
|
1981
2011
|
if (event.key === 'Tab') {
|
|
1982
|
-
if (
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
2012
|
+
if (editingKey) {} else {
|
|
2013
|
+
if (colIndex + 1 !== visibleCols.length) {
|
|
2014
|
+
handleFocusCell(rowNumber, colIndex + 1, column, 'horizontal', event);
|
|
2015
|
+
} else {
|
|
2016
|
+
event.stopPropagation();
|
|
2017
|
+
event.preventDefault();
|
|
2018
|
+
}
|
|
1987
2019
|
}
|
|
1988
2020
|
}
|
|
1989
|
-
if (event.key === 'ArrowRight' && colIndex + 1 !==
|
|
2021
|
+
if (event.key === 'ArrowRight' && colIndex + 1 !== visibleCols.length) {
|
|
1990
2022
|
if (editingKey !== '') {} else {
|
|
1991
2023
|
handleFocusCell(rowNumber, colIndex + 1, column, 'horizontal', event);
|
|
1992
2024
|
}
|
|
@@ -2059,16 +2091,16 @@ const GridEdit = props => {
|
|
|
2059
2091
|
rowsSelected.current = new Set();
|
|
2060
2092
|
}
|
|
2061
2093
|
},
|
|
2062
|
-
// onMouseEnter: () => {
|
|
2063
|
-
//
|
|
2064
|
-
// },
|
|
2065
|
-
|
|
2066
2094
|
onClick: () => {
|
|
2067
2095
|
if (record[rowKey] !== editingKey && editingKey !== '') {
|
|
2068
2096
|
setEditingKey('');
|
|
2097
|
+
} else {
|
|
2098
|
+
if (editingKey) {
|
|
2099
|
+
handleCellClick(rowNumber, record, column);
|
|
2100
|
+
}
|
|
2069
2101
|
}
|
|
2070
2102
|
},
|
|
2071
|
-
className: isEditing(record) ?
|
|
2103
|
+
className: isEditing(record) ? `rc-ui-cell-editable cell-editing ${!(0, _hooks.isEditable)(column, record) ? 'disable' : ''}` : `rc-ui-cell-editable cell-editable ${!(0, _hooks.isEditable)(column, record) ? 'disable' : ''}`,
|
|
2072
2104
|
record,
|
|
2073
2105
|
column: column,
|
|
2074
2106
|
editType: (0, _hooks.getEditType)(column, record),
|
|
@@ -2085,7 +2117,7 @@ const GridEdit = props => {
|
|
|
2085
2117
|
editing: isEditing(record) && rowEditable?.(record) !== false && (0, _hooks.isEditable)(column, record),
|
|
2086
2118
|
cellEditing,
|
|
2087
2119
|
t,
|
|
2088
|
-
tabIndex: (rowIndex ?? 0) *
|
|
2120
|
+
tabIndex: (rowIndex ?? 0) * visibleCols.length + colIndex,
|
|
2089
2121
|
style: isPasteDragging ? {
|
|
2090
2122
|
cursor: "crosshair"
|
|
2091
2123
|
} : {}
|
|
@@ -2116,12 +2148,25 @@ const GridEdit = props => {
|
|
|
2116
2148
|
},
|
|
2117
2149
|
render: (value, record, rowIndex) => {
|
|
2118
2150
|
const rowNumber = (0, _hooks.getRowNumber)(dataSource, record[rowKey], rowKey);
|
|
2151
|
+
const colFormat = typeof column.format === 'function' ? column.format(record) : column.format;
|
|
2152
|
+
const cellFormat = (0, _hooks.getFormat)(colFormat, format);
|
|
2153
|
+
const rowError = dataErrors.find(it => it.index === rowNumber);
|
|
2154
|
+
const cellError = rowError && column.field && rowError[column.field]?.field === column.field ? rowError[column.field] : null;
|
|
2155
|
+
|
|
2156
|
+
// const aaa = dataErrors.find((it) => column?.field && it[column.field].field === column.field && it.index === rowNumber)
|
|
2157
|
+
// const aaa = column.field && rowError && rowError[column.field]?.field === column?.field
|
|
2158
|
+
|
|
2119
2159
|
return /*#__PURE__*/_react.default.createElement("div", {
|
|
2120
2160
|
className: (0, _classnames.default)('ui-rc_cell-content', {
|
|
2121
2161
|
// disable: !isEditable(column as any, record)
|
|
2162
|
+
isValid: column.field && rowError && rowError[column.field]?.field === column?.field
|
|
2122
2163
|
}),
|
|
2123
2164
|
onMouseDown: event => handleMouseDown(record, rowNumber, colIndex, event),
|
|
2124
|
-
onMouseEnter: event =>
|
|
2165
|
+
onMouseEnter: event => {
|
|
2166
|
+
// setTooltipContent(cellError ? cellError.message : renderContent(column as any, value, record, rowIndex, cellFormat))
|
|
2167
|
+
setTooltipContent(cellError ? cellError.message : '');
|
|
2168
|
+
handleMouseEnter(rowNumber, colIndex, event);
|
|
2169
|
+
},
|
|
2125
2170
|
onMouseUp: handleMouseUp,
|
|
2126
2171
|
onMouseMove: () => {
|
|
2127
2172
|
if (selectedCells && selectedCells.current.size > 0 && isMouseDown.current) {
|
|
@@ -2137,7 +2182,7 @@ const GridEdit = props => {
|
|
|
2137
2182
|
// }}
|
|
2138
2183
|
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
2139
2184
|
className: 'ui-rc_content'
|
|
2140
|
-
}, (0, _columns.renderContent)(column, value, record, rowIndex,
|
|
2185
|
+
}, (0, _columns.renderContent)(column, value, record, rowIndex, cellFormat)),
|
|
2141
2186
|
// selectedCells.current && selectedCells.current.size > 0 && getLastSelectCell(selectedCells.current).row === rowNumber &&
|
|
2142
2187
|
// getLastSelectCell(selectedCells.current).col === colIndex &&
|
|
2143
2188
|
// isEditable(column as any, record) &&
|
|
@@ -2161,9 +2206,9 @@ const GridEdit = props => {
|
|
|
2161
2206
|
const transformColumns = _react.default.useCallback(cols => {
|
|
2162
2207
|
// @ts-ignore
|
|
2163
2208
|
return cols.map(column => {
|
|
2164
|
-
const find = convertColumns.find(it => it
|
|
2165
|
-
if (
|
|
2166
|
-
return
|
|
2209
|
+
const find = convertColumns.find(it => it?.field === column.field);
|
|
2210
|
+
if (column === _InternalTable.SELECTION_COLUMN) {
|
|
2211
|
+
return _InternalTable.SELECTION_COLUMN;
|
|
2167
2212
|
}
|
|
2168
2213
|
if (find) {
|
|
2169
2214
|
return {
|
|
@@ -2230,6 +2275,10 @@ const GridEdit = props => {
|
|
|
2230
2275
|
}
|
|
2231
2276
|
return;
|
|
2232
2277
|
}
|
|
2278
|
+
if (args.item.key === 'INSERT_CHILDREN') {
|
|
2279
|
+
handleInsertChild(args.item);
|
|
2280
|
+
return;
|
|
2281
|
+
}
|
|
2233
2282
|
if (args.item.key === 'DELETE_ROWS') {
|
|
2234
2283
|
handleDeleteRows(args.item);
|
|
2235
2284
|
return;
|
|
@@ -2272,6 +2321,7 @@ const GridEdit = props => {
|
|
|
2272
2321
|
format,
|
|
2273
2322
|
control,
|
|
2274
2323
|
trigger,
|
|
2324
|
+
errors,
|
|
2275
2325
|
getValues,
|
|
2276
2326
|
handleCellChange,
|
|
2277
2327
|
getRowKey
|
|
@@ -2328,7 +2378,7 @@ const GridEdit = props => {
|
|
|
2328
2378
|
},
|
|
2329
2379
|
rowHoverable: false,
|
|
2330
2380
|
bottomToolbar: bottomToolbar,
|
|
2331
|
-
expandable: {
|
|
2381
|
+
expandable: expandable ? {
|
|
2332
2382
|
expandIconColumnIndex: (0, _hooks.checkChild)(dataSource) ? 3 : undefined,
|
|
2333
2383
|
...expandable,
|
|
2334
2384
|
expandedRowKeys: innerExpandedKeys,
|
|
@@ -2363,7 +2413,7 @@ const GridEdit = props => {
|
|
|
2363
2413
|
});
|
|
2364
2414
|
}
|
|
2365
2415
|
}
|
|
2366
|
-
},
|
|
2416
|
+
} : undefined,
|
|
2367
2417
|
triggerChangeColumns: triggerChangeColumns,
|
|
2368
2418
|
clickHeaderToSort: false,
|
|
2369
2419
|
isFilter: isFilter,
|