es-grid-template 1.3.0 → 1.3.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.
Files changed (51) hide show
  1. package/assets/index.css +16 -0
  2. package/assets/index.scss +37 -3
  3. package/es/grid-component/CheckboxFilter.js +4 -0
  4. package/es/grid-component/CheckboxFilter2.d.ts +20 -0
  5. package/es/grid-component/CheckboxFilter2.js +248 -0
  6. package/es/grid-component/ColumnsGroup/ColumnsGroup.js +4 -4
  7. package/es/grid-component/ContextMenu.js +1 -0
  8. package/es/grid-component/ConvertColumnTable.js +1 -0
  9. package/es/grid-component/EditableCell.js +11 -8
  10. package/es/grid-component/InternalTable.js +47 -11
  11. package/es/grid-component/TableGrid.d.ts +3 -0
  12. package/es/grid-component/TableGrid.js +71 -7
  13. package/es/grid-component/hooks/columns/index.js +14 -45
  14. package/es/grid-component/hooks/content/HeaderContent.js +54 -58
  15. package/es/grid-component/hooks/useColumns.d.ts +4 -2
  16. package/es/grid-component/hooks/useColumns.js +32 -13
  17. package/es/grid-component/hooks/utils.d.ts +9 -0
  18. package/es/grid-component/hooks/utils.js +278 -1
  19. package/es/grid-component/number-range/index.d.ts +10 -0
  20. package/es/grid-component/number-range/index.js +59 -0
  21. package/es/grid-component/styles.scss +24 -0
  22. package/es/grid-component/table/Grid.d.ts +3 -0
  23. package/es/grid-component/table/GridEdit.js +360 -106
  24. package/es/grid-component/table/Group.d.ts +1 -0
  25. package/es/grid-component/table/Group.js +1 -1
  26. package/es/grid-component/type.d.ts +2 -1
  27. package/lib/grid-component/CheckboxFilter.js +4 -0
  28. package/lib/grid-component/CheckboxFilter2.d.ts +20 -0
  29. package/lib/grid-component/CheckboxFilter2.js +257 -0
  30. package/lib/grid-component/ColumnsGroup/ColumnsGroup.js +4 -4
  31. package/lib/grid-component/ContextMenu.js +1 -0
  32. package/lib/grid-component/ConvertColumnTable.js +1 -0
  33. package/lib/grid-component/EditableCell.js +11 -8
  34. package/lib/grid-component/InternalTable.js +41 -10
  35. package/lib/grid-component/TableGrid.d.ts +3 -0
  36. package/lib/grid-component/TableGrid.js +68 -7
  37. package/lib/grid-component/hooks/columns/index.js +14 -45
  38. package/lib/grid-component/hooks/content/HeaderContent.js +53 -55
  39. package/lib/grid-component/hooks/useColumns.d.ts +4 -2
  40. package/lib/grid-component/hooks/useColumns.js +31 -12
  41. package/lib/grid-component/hooks/utils.d.ts +9 -0
  42. package/lib/grid-component/hooks/utils.js +293 -4
  43. package/lib/grid-component/number-range/index.d.ts +10 -0
  44. package/lib/grid-component/number-range/index.js +67 -0
  45. package/lib/grid-component/styles.scss +24 -0
  46. package/lib/grid-component/table/Grid.d.ts +3 -0
  47. package/lib/grid-component/table/GridEdit.js +358 -104
  48. package/lib/grid-component/table/Group.d.ts +1 -0
  49. package/lib/grid-component/table/Group.js +1 -1
  50. package/lib/grid-component/type.d.ts +2 -1
  51. package/package.json +109 -108
@@ -24,16 +24,19 @@ var _hooks = require("../hooks");
24
24
  var _Message = _interopRequireDefault(require("../../Message/Message"));
25
25
  var _rcMasterUi = require("rc-master-ui");
26
26
  var _useMergedState = _interopRequireDefault(require("rc-util/lib/hooks/useMergedState"));
27
+ var _becoxyIcons = require("becoxy-icons");
27
28
  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); }
28
29
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
29
30
  // import Command from "../Command";
30
31
 
32
+ // import {ContextInfo, ContextMenuItem} from "../type";
31
33
  // import useLazyKVMap from "rc-master-ui/es/table/hooks/useLazyKVMap";
32
34
 
33
35
  _dayjs.default.extend(_customParseFormat.default);
34
36
  const toast = 'top-right';
35
37
  const GridEdit = props => {
36
38
  const {
39
+ id,
37
40
  tableRef,
38
41
  t,
39
42
  columns,
@@ -68,6 +71,7 @@ const GridEdit = props => {
68
71
  // selectedRowKeys,
69
72
  // defaultSelectedRowKeys
70
73
  } = selectionSettings || {};
74
+ const ref = (0, _react.useRef)(null);
71
75
  const isSelecting = (0, _react.useRef)(false);
72
76
  const startCell = (0, _react.useRef)(null);
73
77
  const childrenColumnName = 'children';
@@ -88,6 +92,7 @@ const GridEdit = props => {
88
92
  }];
89
93
  const [form] = _antd.Form.useForm();
90
94
  const [editingKey, setEditingKey] = (0, _react.useState)('');
95
+ const [isFilter, setIsFilter] = _react.default.useState(false);
91
96
  const [selectedCells, setSelectedCells] = (0, _react.useState)(new Set());
92
97
  const [pasteCells, setPasteCells] = (0, _react.useState)(new Set());
93
98
  const [cellEditing, setCellEditing] = (0, _react.useState)(null);
@@ -112,6 +117,33 @@ const GridEdit = props => {
112
117
  const rowsFocus = _react.default.useMemo(() => {
113
118
  return [...new Set(Array.from(selectedCells).map(item => parseInt(item.split('-')[0])))] ?? [];
114
119
  }, [selectedCells]);
120
+ const contextMenuItems = _react.default.useMemo(() => {
121
+ return [{
122
+ key: 'INSERT_BEFORE',
123
+ label: 'Thêm dòng bên trên',
124
+ icon: /*#__PURE__*/_react.default.createElement(_becoxyIcons.Plus, {
125
+ fontSize: 14
126
+ })
127
+ }, {
128
+ key: 'INSERT_AFTER',
129
+ label: 'Thêm dòng bên dưới',
130
+ icon: /*#__PURE__*/_react.default.createElement(_becoxyIcons.Plus, {
131
+ fontSize: 14
132
+ })
133
+ }, {
134
+ key: 'DELETE_CONTENT',
135
+ label: 'Xóa nội dung',
136
+ icon: /*#__PURE__*/_react.default.createElement(_becoxyIcons.Trash2, {
137
+ fontSize: 14
138
+ })
139
+ }, {
140
+ key: 'DELETE_ROWS',
141
+ label: 'Xóa dòng',
142
+ icon: /*#__PURE__*/_react.default.createElement(_becoxyIcons.Trash2, {
143
+ fontSize: 14
144
+ })
145
+ }];
146
+ }, []);
115
147
  const onTriggerExpand = _react.default.useCallback(record => {
116
148
  const key = getRowKey(record, dataSource.indexOf(record));
117
149
  let newExpandedKeys;
@@ -181,9 +213,12 @@ const GridEdit = props => {
181
213
  const rs = [...newData.slice(0, insertAfter + 1), ...duplicatedItems, ...newData.slice(insertAfter + 1)];
182
214
  triggerChangeData?.(rs, 'DUPLICATE');
183
215
  };
184
- const handleInsertBefore = item => {
216
+
217
+ // thêm n dòng bên trên
218
+ const handleInsertBefore = (item, n) => {
185
219
  const defaultRowValue = (0, _hooks.getDefaultValue)(defaultValue);
186
- const rowId = defaultRowValue && defaultRowValue.id ? defaultRowValue.id : (0, _hooks.newGuid)();
220
+ // const rowId = defaultRowValue && defaultRowValue.id ? defaultRowValue.id : newGuid()
221
+
187
222
  const record = (0, _hooks.flattenData)(childrenColumnName, dataSource)[rowsFocus[rowsFocus.length - 1]];
188
223
  if (item.onClick) {
189
224
  item.onClick({
@@ -193,27 +228,55 @@ const GridEdit = props => {
193
228
  if (!record?.parentId) {
194
229
  // Cập nhật data mới
195
230
  const newData = [...dataSource];
196
- const index = newData.findIndex(obj => obj[rowKey] === record[rowKey]);
197
- newData.splice(index, 0, {
231
+ const newRows = Array.from({
232
+ length: n
233
+ }).map(() => defaultRowValue ? isFilter ? {
198
234
  ...defaultRowValue,
199
- rowId,
200
- parentId: null,
201
- id: undefined
235
+ id: undefined,
236
+ rowId: (0, _hooks.newGuid)(),
237
+ isFilterState: true
238
+ } : {
239
+ ...defaultRowValue,
240
+ id: undefined,
241
+ rowId: (0, _hooks.newGuid)()
242
+ } : isFilter ? {
243
+ id: undefined,
244
+ rowId: (0, _hooks.newGuid)(),
245
+ isFilterState: true
246
+ } : {
247
+ id: undefined,
248
+ rowId: (0, _hooks.newGuid)()
202
249
  });
250
+ const index = newData.findIndex(obj => obj[rowKey] === record[rowKey]);
251
+ newData.splice(index, 0, ...newRows);
203
252
  triggerChangeData?.(newData, 'INSERT_BEFORE');
204
253
  } else {
205
254
  const newData = [...dataSource];
255
+ const newRows = Array.from({
256
+ length: n
257
+ }).map(() => defaultRowValue ? isFilter ? {
258
+ ...defaultRowValue,
259
+ id: undefined,
260
+ rowId: (0, _hooks.newGuid)(),
261
+ isFilterState: true
262
+ } : {
263
+ ...defaultRowValue,
264
+ id: undefined,
265
+ rowId: (0, _hooks.newGuid)()
266
+ } : isFilter ? {
267
+ id: undefined,
268
+ rowId: (0, _hooks.newGuid)(),
269
+ isFilterState: true
270
+ } : {
271
+ id: undefined,
272
+ rowId: (0, _hooks.newGuid)()
273
+ });
206
274
  const parent = (0, _hooks.findItemByKey)(newData, rowKey, record.parentId);
207
275
 
208
276
  // Cập nhật childData mới
209
277
  const childData = parent?.children ? [...parent.children] : [];
210
278
  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
- });
279
+ childData.splice(index, 0, ...newRows);
217
280
  const newRowData = {
218
281
  ...parent,
219
282
  children: childData
@@ -223,9 +286,13 @@ const GridEdit = props => {
223
286
  }
224
287
  }
225
288
  };
226
- const handleInsertAfter = item => {
289
+
290
+ //thêm 1 dòng bên dưới
291
+ const handleInsertAfter = (item, n) => {
227
292
  const defaultRowValue = (0, _hooks.getDefaultValue)(defaultValue);
228
- const rowId = defaultRowValue && defaultRowValue.id ? defaultRowValue.id : (0, _hooks.newGuid)();
293
+
294
+ // const rowId = defaultRowValue && defaultRowValue.id ? defaultRowValue.id : newGuid()
295
+
229
296
  const record = (0, _hooks.flattenData)(childrenColumnName, dataSource)[rowsFocus[rowsFocus.length - 1]];
230
297
 
231
298
  // const record = getRecordByKey()
@@ -238,25 +305,57 @@ const GridEdit = props => {
238
305
  if (!record?.parentId) {
239
306
  // Cập nhật data mới
240
307
  const newData = [...dataSource];
241
- const index = newData.findIndex(obj => obj[rowKey] === record[rowKey]);
242
- newData.splice(index + 1, 0, {
308
+ const newRows = Array.from({
309
+ length: n
310
+ }).map(() => defaultRowValue ? isFilter ? {
311
+ ...defaultRowValue,
312
+ id: undefined,
313
+ rowId: (0, _hooks.newGuid)(),
314
+ isFilterState: true
315
+ } : {
243
316
  ...defaultRowValue,
244
- rowId,
245
- parentId: null
317
+ id: undefined,
318
+ rowId: (0, _hooks.newGuid)()
319
+ } : isFilter ? {
320
+ id: undefined,
321
+ rowId: (0, _hooks.newGuid)(),
322
+ isFilterState: true
323
+ } : {
324
+ id: undefined,
325
+ rowId: (0, _hooks.newGuid)()
246
326
  });
327
+ const index = newData.findIndex(obj => obj[rowKey] === record[rowKey]);
328
+
329
+ // newData.splice(index + 1, 0, { ...defaultRowValue, rowId, parentId: null })
330
+ newData.splice(index + 1, 0, ...newRows);
247
331
  triggerChangeData?.(newData, 'INSERT_AFTER');
248
332
  } else {
249
333
  const newData = [...dataSource];
334
+ const newRows = Array.from({
335
+ length: n
336
+ }).map(() => defaultRowValue ? isFilter ? {
337
+ ...defaultRowValue,
338
+ id: undefined,
339
+ rowId: (0, _hooks.newGuid)(),
340
+ isFilterState: true
341
+ } : {
342
+ ...defaultRowValue,
343
+ id: undefined,
344
+ rowId: (0, _hooks.newGuid)()
345
+ } : isFilter ? {
346
+ id: undefined,
347
+ rowId: (0, _hooks.newGuid)(),
348
+ isFilterState: true
349
+ } : {
350
+ id: undefined,
351
+ rowId: (0, _hooks.newGuid)()
352
+ });
250
353
  const parent = (0, _hooks.findItemByKey)(newData, rowKey, record.parentId);
251
354
 
252
355
  // Cập nhật childData mới
253
356
  const childData = parent?.children ? [...parent.children] : [];
254
357
  const index = childData.findIndex(obj => obj[rowKey] === record[rowKey]);
255
- childData.splice(index + 1, 0, {
256
- ...defaultRowValue,
257
- rowId,
258
- parentId: record.parentId
259
- });
358
+ childData.splice(index + 1, 0, ...newRows);
260
359
  const newRowData = {
261
360
  ...parent,
262
361
  children: childData
@@ -308,12 +407,49 @@ const GridEdit = props => {
308
407
  setInnerExpandedKeys(newExpandedKeys);
309
408
  }
310
409
  };
410
+ const handleDeleteRows = item => {
411
+ if (item.onClick) {
412
+ item.onClick({
413
+ toolbar: item
414
+ });
415
+ } else {
416
+ const newData = [...dataSource];
417
+ const indexesToDelete = [...rowsFocus];
418
+
419
+ // Sắp xếp giảm dần để xóa từ cuối lên đầu
420
+ indexesToDelete.sort((a, b) => b - a).forEach(index => {
421
+ newData.splice(index, 1);
422
+ });
423
+ triggerChangeData?.([...newData], 'DELETE_ROWS');
424
+ }
425
+ };
311
426
  const handleDeleteAll = () => {
312
427
  triggerChangeData?.([], 'INSERT_BEFORE');
313
428
  };
429
+ const handleDeleteContent = () => {
430
+ if (selectedCells.size > 0) {
431
+ const newData = [...dataSource];
432
+
433
+ // colIndex => field
434
+ const colIndexToField = (0, _columns.flatColumns2)(columns).map(col => col.field);
435
+
436
+ // Duyệt qua mỗi ô cần xóa
437
+ for (const cell of selectedCells) {
438
+ const [rowIndexStr, colIndexStr] = cell.split("-");
439
+ const rowIndex = Number(rowIndexStr);
440
+ const colIndex = Number(colIndexStr);
441
+ const field = colIndexToField[colIndex];
442
+ if (newData[rowIndex] && field && field in newData[rowIndex]) {
443
+ // @ts-ignore
444
+ newData[rowIndex][field] = '';
445
+ }
446
+ }
447
+ triggerChangeData?.([...newData], 'DELETE_CONTENT');
448
+ }
449
+ };
314
450
  const toolbarItemsBottom = (0, _react.useMemo)(() => {
315
451
  if (!rowsFocus || rowsFocus.length === 0) {
316
- return toolbarItems?.filter(it => it.position === 'Bottom' && it.visible !== false && it.key !== 'DUPLICATE' && it.key !== 'INSERT_BEFORE' && it.key !== 'INSERT_AFTER' && it.key !== 'INSERT_CHILDREN').map(item => {
452
+ 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 => {
317
453
  if (item.key === 'ADD') {
318
454
  return {
319
455
  ...item,
@@ -321,6 +457,7 @@ const GridEdit = props => {
321
457
  return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, item.key === 'ADD' && /*#__PURE__*/_react.default.createElement("div", {
322
458
  className: (0, _classnames.default)(`be-toolbar-item`, item?.className)
323
459
  }, /*#__PURE__*/_react.default.createElement(_antd.Dropdown.Button, {
460
+ overlayClassName: 'be-popup-container',
324
461
  style: {
325
462
  color: '#28c76f',
326
463
  borderColor: '#28c76f'
@@ -370,6 +507,7 @@ const GridEdit = props => {
370
507
  return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, item.key === 'ADD' && /*#__PURE__*/_react.default.createElement("div", {
371
508
  className: (0, _classnames.default)(`be-toolbar-item`, item?.className)
372
509
  }, /*#__PURE__*/_react.default.createElement(_antd.Dropdown.Button, {
510
+ overlayClassName: 'be-popup-container',
373
511
  style: {
374
512
  color: '#28c76f',
375
513
  borderColor: '#28c76f'
@@ -410,17 +548,25 @@ const GridEdit = props => {
410
548
  return {
411
549
  ...item,
412
550
  template: () => {
413
- return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, item.key === 'INSERT_BEFORE' && item.visible !== false && rowsFocus.length > 0 && /*#__PURE__*/_react.default.createElement("div", {
551
+ return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
414
552
  className: (0, _classnames.default)(`be-toolbar-item`, item?.className)
415
- }, /*#__PURE__*/_react.default.createElement(_antd.Button, {
553
+ }, /*#__PURE__*/_react.default.createElement(_antd.Dropdown.Button, {
554
+ overlayClassName: 'be-popup-container',
416
555
  style: {
417
556
  color: '#28c76f',
418
557
  borderColor: '#28c76f'
419
558
  },
420
- variant: 'outlined',
421
- onClick: () => handleInsertBefore(item),
422
- className: "d-flex toolbar-button"
423
- }, item.label ? t ? t(item.label) : item.label : t ? t('Insert item before') : 'Insert item before')));
559
+ className: 'toolbar-button toolbar-dropdown-button',
560
+ menu: {
561
+ items: itemsAdd,
562
+ onClick: e => handleInsertBefore(item, Number(e.key))
563
+ }
564
+ }, /*#__PURE__*/_react.default.createElement("span", {
565
+ style: {
566
+ color: '#28c76f'
567
+ },
568
+ onClick: () => handleInsertBefore(item, 1)
569
+ }, item.label ? t ? t(item.label) : item.label : t ? t('Insert item before') : 'Insert item before'))));
424
570
  }
425
571
  };
426
572
  }
@@ -428,17 +574,25 @@ const GridEdit = props => {
428
574
  return {
429
575
  ...item,
430
576
  template: () => {
431
- return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, item.key === 'INSERT_AFTER' && item.visible !== false && rowsFocus.length > 0 && /*#__PURE__*/_react.default.createElement("div", {
577
+ return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement("div", {
432
578
  className: (0, _classnames.default)(`be-toolbar-item`, item?.className)
433
- }, /*#__PURE__*/_react.default.createElement(_antd.Button, {
579
+ }, /*#__PURE__*/_react.default.createElement(_antd.Dropdown.Button, {
580
+ overlayClassName: 'be-popup-container',
434
581
  style: {
435
582
  color: '#28c76f',
436
583
  borderColor: '#28c76f'
437
584
  },
438
- variant: 'outlined',
439
- onClick: () => handleInsertAfter(item),
440
- className: "d-flex toolbar-button"
441
- }, item.label ? t ? t(item.label) : item.label : t ? t('Insert item after') : 'Insert item after')));
585
+ className: 'toolbar-button toolbar-dropdown-button',
586
+ menu: {
587
+ items: itemsAdd,
588
+ onClick: e => handleInsertAfter(item, Number(e.key))
589
+ }
590
+ }, /*#__PURE__*/_react.default.createElement("span", {
591
+ style: {
592
+ color: '#28c76f'
593
+ },
594
+ onClick: () => handleInsertAfter(item, 1)
595
+ }, item.label ? t ? t(item.label) : item.label : t ? t('Insert item after') : 'Insert item after'))));
442
596
  }
443
597
  };
444
598
  }
@@ -478,6 +632,24 @@ const GridEdit = props => {
478
632
  }
479
633
  };
480
634
  }
635
+ if (item.key === 'DELETE_ROWS') {
636
+ return {
637
+ ...item,
638
+ template: () => {
639
+ return /*#__PURE__*/_react.default.createElement("div", {
640
+ className: (0, _classnames.default)(`be-toolbar-item`, item?.className)
641
+ }, /*#__PURE__*/_react.default.createElement(_antd.Button, {
642
+ style: {
643
+ color: '#eb4619',
644
+ borderColor: '#eb4619'
645
+ },
646
+ variant: 'outlined',
647
+ onClick: () => handleDeleteRows(item),
648
+ className: "d-flex toolbar-button"
649
+ }, t ? `${t('Delete')} ${rowsFocus.length} ${t('row')}` : `Delete ${rowsFocus.length} item`));
650
+ }
651
+ };
652
+ }
481
653
  return {
482
654
  ...item
483
655
  };
@@ -502,35 +674,55 @@ const GridEdit = props => {
502
674
  (0, _react.useEffect)(() => {
503
675
  const handleClickOutside = event => {
504
676
  const element = event.target;
505
- const tableBodies = document.getElementsByClassName("ui-rc-table-tbody");
677
+
678
+ // const tableId = id ? document.getElementById(id) : undefined
679
+ // const tableBodies = document.getElementsByClassName("ui-rc-table-tbody");
506
680
  const container = document.querySelector(".be-popup-container");
681
+ const tableBody = document.querySelector(`#${id} .ui-rc-table-tbody`);
507
682
  // const containerHidden = document.querySelector(".be-popup-container.ant-picker-dropdown-hidden")
508
683
 
509
684
  // const toolbarContainer = document.getElementsByClassName("ui-rc-toolbar");
510
- const itemContainer = document.querySelector(".ui-rc-toolbar-selection-overflow-item");
685
+ const itemContainer = document.querySelector(`#${id} .ui-rc-toolbar-selection-overflow-item`);
686
+ const itemHeader = document.querySelector(`#${id} .ui-rc-table-thead`);
511
687
  const isInsideContainer = element.closest(".be-popup-container") && container;
512
- const isInsideToolbar = element.closest(".ui-rc-toolbar-selection-overflow-item") && itemContainer;
513
- if (isInsideContainer || isInsideToolbar) {
688
+ const isInsideToolbar = element.closest(`.ui-rc-toolbar-selection-overflow-item`) && itemContainer;
689
+ const isInsideHeader = itemHeader && itemHeader.contains(event.target);
690
+ if (isInsideContainer || isInsideToolbar || isInsideHeader) {
514
691
  return;
515
692
  }
516
- if (tableBodies.length > 0) {
517
- const tableBody = tableBodies[0]; // Chọn tbody đầu tiên (nếu có nhiều)
518
-
519
- if (!tableBody.contains(event.target)) {
520
- setEditingKey('');
521
- isSelecting.current = false;
522
- startCell.current = null;
523
- setSelectedCells(new Set());
524
- setRowsSelected(new Set());
525
- } else {}
693
+
694
+ // if (ref.current && !ref.current.contains(event.target)) {
695
+ // if (ref.current && tableId && !tableId.contains(event.target as Node)) {
696
+
697
+ if (ref.current && tableBody && !tableBody.contains(event.target)) {
698
+ setEditingKey('');
699
+ isSelecting.current = false;
700
+ startCell.current = null;
701
+ setSelectedCells(new Set());
702
+ setRowsSelected(new Set());
526
703
  }
704
+
705
+ // if (tableBodies.length > 0) {
706
+ // const tableBody = tableBodies[0]; // Chọn tbody đầu tiên (nếu có nhiều)
707
+ //
708
+ // if (!tableBody.contains(event.target as Node)) {
709
+ // setEditingKey('')
710
+ // isSelecting.current = false;
711
+ // startCell.current = null;
712
+ // setSelectedCells(new Set())
713
+ // setRowsSelected(new Set())
714
+ // } else {
715
+ //
716
+ // }
717
+ // }
527
718
  };
528
719
  document.addEventListener("click", handleClickOutside);
529
720
  return () => {
530
721
  document.removeEventListener("click", handleClickOutside);
531
722
  };
532
723
  }, []);
533
- const handleMouseDown = (record, row, col, e) => {
724
+ const handleMouseDown = (0, _react.useCallback)((record, row, col, e) => {
725
+ setEditingKey('');
534
726
  if (e.button === 2) {
535
727
  e.stopPropagation();
536
728
  return;
@@ -567,7 +759,7 @@ const GridEdit = props => {
567
759
  // setSelectedCells(new Set([`${row}-${col}`]));
568
760
  // setRowsSelected(new Set())
569
761
  // }
570
- };
762
+ }, []);
571
763
 
572
764
  // const handlePointEnter = (e: any) => {
573
765
  //
@@ -772,25 +964,15 @@ const GridEdit = props => {
772
964
  }
773
965
  setSelectedCells(newSelectedCells);
774
966
  };
775
-
776
- // const handleClickColHeader = (column: ColumnTable, indexColumn: number) => {
777
- //
778
- // const newSelectedCells = new Set();
779
- //
780
- // for (let r = Math.min(dataSource.length, 0); r <= Math.max(dataSource.length - 1, 0); r++) {
781
- // for (let c = Math.min(indexColumn, indexColumn); c <= Math.max(indexColumn, indexColumn); c++) {
782
- // newSelectedCells.add(`${r}-${c}`)
783
- // }
784
- // }
785
- //
786
- // // console.log('newSelectedCells', newSelectedCells)
787
- // // setSelectedCells(newSelectedCells)
788
- //
789
- // setSelectedCells(new Set(newSelectedCells));
790
- // // forceUpdate();
791
- // setUpdateKey((prev) => prev + 1); // Cập nhật key để trigger re-render
792
- // }
793
-
967
+ const handleClickColHeader = (column, indexColumn) => {
968
+ const newSelectedCells = new Set();
969
+ for (let r = Math.min(dataSource.length, 0); r <= Math.max(dataSource.length - 1, 0); r++) {
970
+ for (let c = Math.min(indexColumn, indexColumn); c <= Math.max(indexColumn, indexColumn); c++) {
971
+ newSelectedCells.add(`${r}-${c}`);
972
+ }
973
+ }
974
+ setSelectedCells(new Set(newSelectedCells));
975
+ };
794
976
  const handleMouseDownColIndex = (row, col, e) => {
795
977
  if (e.button === 2) {
796
978
  e.stopPropagation();
@@ -823,7 +1005,7 @@ const GridEdit = props => {
823
1005
  }
824
1006
  const newSelectedCells = new Set();
825
1007
  for (let r = Math.min(startRow, row); r <= Math.max(startRow, row); r++) {
826
- for (let c = Math.min(columns.length, col) + 1; c <= Math.max(columns.length, col); c++) {
1008
+ for (let c = Math.min((0, _hooks.editAbleColumns)(columns).length, col) + 1; c <= Math.max((0, _hooks.editAbleColumns)(columns).length, col); c++) {
827
1009
  newSelectedCells.add(`${r}-${c}`);
828
1010
  }
829
1011
  }
@@ -861,7 +1043,7 @@ const GridEdit = props => {
861
1043
  const selectedArray = Array.from(selectedCells).map(key => {
862
1044
  const [row, col] = key.split("-").map(Number);
863
1045
  // @ts-ignore
864
- const columnKey = columns[col].field;
1046
+ const columnKey = (0, _hooks.editAbleColumns)(columns)[col - 1].field;
865
1047
 
866
1048
  // @ts-ignore
867
1049
  return {
@@ -940,16 +1122,17 @@ const GridEdit = props => {
940
1122
  // Không vượt quá số cột
941
1123
  return;
942
1124
  }
943
-
944
- // @ts-ignore
945
- const columnKey = columns[targetCol].field;
946
-
947
- // @ts-ignore
948
- newData[targetRow] = {
949
- ...newData[targetRow],
950
- [columnKey]: cellValue.trim()
951
- };
952
- pastedColumns.add(columnKey);
1125
+ if (columns[targetCol].editEnable) {
1126
+ // @ts-ignore
1127
+ const columnKey = columns[targetCol].field;
1128
+
1129
+ // @ts-ignore
1130
+ newData[targetRow] = {
1131
+ ...newData[targetRow],
1132
+ [columnKey]: cellValue.trim()
1133
+ };
1134
+ pastedColumns.add(columnKey);
1135
+ }
953
1136
  });
954
1137
 
955
1138
  // Lưu dòng được paste
@@ -988,16 +1171,17 @@ const GridEdit = props => {
988
1171
  // Không vượt quá số cột
989
1172
  return;
990
1173
  }
991
-
992
- // @ts-ignore
993
- const columnKey = columns[targetCol].field;
994
-
995
- // @ts-ignore
996
- childData[targetRow] = {
997
- ...childData[targetRow],
998
- [columnKey]: cellValue.trim()
999
- };
1000
- pastedColumns.add(columnKey);
1174
+ if (columns[targetCol].editEnable) {
1175
+ // @ts-ignore
1176
+ const columnKey = columns[targetCol].field;
1177
+
1178
+ // @ts-ignore
1179
+ childData[targetRow] = {
1180
+ ...childData[targetRow],
1181
+ [columnKey]: cellValue.trim()
1182
+ };
1183
+ pastedColumns.add(columnKey);
1184
+ }
1001
1185
  });
1002
1186
 
1003
1187
  // Lưu dòng được paste
@@ -1296,7 +1480,7 @@ const GridEdit = props => {
1296
1480
  tabIndex: (rowIndex ?? 0) * columns.length + colIndex
1297
1481
  };
1298
1482
  },
1299
- render: (value, record, rowIndex) => {
1483
+ render: (value, record) => {
1300
1484
  const rowNumber = (0, _hooks.getRowNumber)(dataSource, record[rowKey], rowKey);
1301
1485
  return /*#__PURE__*/_react.default.createElement("div", {
1302
1486
  className: (0, _classnames.default)('ui-rc_cell-content ui-rc_cell-content--index', {
@@ -1305,10 +1489,11 @@ const GridEdit = props => {
1305
1489
  }),
1306
1490
  onMouseDown: event => handleMouseDownColIndex(rowNumber, colIndex, event),
1307
1491
  onMouseEnter: event => handleMouseEnterColIndex(rowNumber, colIndex, event),
1308
- onClick: () => handleClickRowHeader(rowNumber, colIndex)
1492
+ onClick: () => handleClickRowHeader(rowNumber, colIndex),
1493
+ onMouseUp: handleMouseUp
1309
1494
  }, /*#__PURE__*/_react.default.createElement("div", {
1310
1495
  className: 'ui-rc_content'
1311
- }, rowIndex + 1));
1496
+ }, (0, _hooks.findItemPath)(dataSource, record, rowKey)));
1312
1497
  }
1313
1498
  };
1314
1499
  }
@@ -1322,6 +1507,10 @@ const GridEdit = props => {
1322
1507
  onCell: (record, rowIndex) => {
1323
1508
  const rowNumber = (0, _hooks.getRowNumber)(dataSource, record[rowKey], rowKey);
1324
1509
  return {
1510
+ // onKeyPress: () => {
1511
+ //
1512
+ // },
1513
+
1325
1514
  onKeyDown: event => {
1326
1515
  const key = getRowKey(record, dataSource.indexOf(record));
1327
1516
  if (event.key.length === 1 && !event.ctrlKey && !event.metaKey || event.key === 'Enter') {
@@ -1387,6 +1576,9 @@ const GridEdit = props => {
1387
1576
  if (event.key === 'ArrowUp' && (rowNumber ?? 0) > 0) {
1388
1577
  handleFocusCell((rowNumber ?? 0) - 1, colIndex, column, 'vertical', event);
1389
1578
  }
1579
+ if (event.key === 'Delete') {
1580
+ handleDeleteContent();
1581
+ }
1390
1582
  },
1391
1583
  onPaste: event => {
1392
1584
  if (editingKey === '') {
@@ -1406,6 +1598,19 @@ const GridEdit = props => {
1406
1598
  handleCellClick(rowNumber, record, column);
1407
1599
  }
1408
1600
  },
1601
+ onContextMenu: () => {
1602
+ // isSelecting.current = true;
1603
+ // startCell.current = { row: rowNumber, col: colIndex };
1604
+
1605
+ if (selectedCells.size === 0) {
1606
+ setStartSelectedCell({
1607
+ row: rowNumber,
1608
+ col: colIndex
1609
+ });
1610
+ setSelectedCells(new Set([`${rowNumber}-${colIndex}`]));
1611
+ setRowsSelected(new Set());
1612
+ }
1613
+ },
1409
1614
  onClick: () => {
1410
1615
  if (record[rowKey] !== editingKey && editingKey !== '') {
1411
1616
  setEditingKey('');
@@ -1430,19 +1635,42 @@ const GridEdit = props => {
1430
1635
  } : {}
1431
1636
  };
1432
1637
  },
1638
+ onHeaderCell: () => {
1639
+ return {
1640
+ onClick: () => {
1641
+ handleClickColHeader(column, colIndex);
1642
+ },
1643
+ onCopy: e => {
1644
+ if (editingKey === '') {
1645
+ handleCopy(e);
1646
+ e.preventDefault();
1647
+ }
1648
+ },
1649
+ onPaste: event => {
1650
+ if (editingKey === '') {
1651
+ handlePaste(dataSource[0], colIndex, 0, event);
1652
+ event.preventDefault();
1653
+ }
1654
+ },
1655
+ style: {
1656
+ userSelect: 'none'
1657
+ }
1658
+ };
1659
+ },
1433
1660
  render: (value, record, rowIndex) => {
1434
1661
  const rowNumber = (0, _hooks.getRowNumber)(dataSource, record[rowKey], rowKey);
1435
1662
  return /*#__PURE__*/_react.default.createElement("div", {
1436
1663
  className: (0, _classnames.default)('ui-rc_cell-content', {
1437
1664
  // selected: selectedCells.has(`${record[rowKey]}-${colIndex}`)
1438
- selected: selectedCells.has(`${rowNumber}-${colIndex}`)
1665
+ selected: selectedCells.has(`${rowNumber}-${colIndex}`),
1666
+ disable: !(0, _hooks.isEditable)(column, record)
1439
1667
  }),
1440
1668
  onMouseDown: event => handleMouseDown(record, rowNumber, colIndex, event),
1441
1669
  onMouseEnter: () => handleMouseEnter(rowNumber, colIndex),
1442
1670
  onMouseUp: handleMouseUp
1443
1671
  }, /*#__PURE__*/_react.default.createElement("div", {
1444
1672
  className: 'ui-rc_content'
1445
- }, (0, _columns.renderContent)(column, value, record, rowIndex, format)), selectedCells && selectedCells.size > 0 && (0, _hooks.getLastSelectCell)(selectedCells).row === rowNumber && (0, _hooks.getLastSelectCell)(selectedCells).col === colIndex && (0, _hooks.isEditable)(column, record) !== false && !isSelectDragging &&
1673
+ }, (0, _columns.renderContent)(column, value, record, rowIndex, format)), selectedCells && selectedCells.size > 0 && (0, _hooks.getLastSelectCell)(selectedCells).row === rowNumber && (0, _hooks.getLastSelectCell)(selectedCells).col === colIndex && (0, _hooks.isEditable)(column, record) && !isSelectDragging && rowIndex !== dataSource.length - 1 &&
1446
1674
  /*#__PURE__*/
1447
1675
  // showDraggingPoint &&
1448
1676
  _react.default.createElement("div", {
@@ -1503,11 +1731,26 @@ const GridEdit = props => {
1503
1731
  const onSelectChange = keys => {
1504
1732
  setMergedSelectedKeys(keys);
1505
1733
  };
1734
+ const contextMenuClick = args => {
1735
+ if (args.item.key === 'INSERT_BEFORE') {
1736
+ handleInsertAfter(args.item, 1);
1737
+ }
1738
+ if (args.item.key === 'INSERT_AFTER') {
1739
+ handleInsertBefore(args.item, 1);
1740
+ }
1741
+ if (args.item.key === 'DELETE_ROWS') {
1742
+ handleDeleteRows(args.item);
1743
+ }
1744
+ if (args.item.key === 'DELETE_CONTENT') {
1745
+ handleDeleteContent();
1746
+ }
1747
+ };
1506
1748
  return /*#__PURE__*/_react.default.createElement(_react.Fragment, null, /*#__PURE__*/_react.default.createElement(_GridStyle.GridStyle, {
1507
1749
  heightTable: height,
1508
1750
  style: {
1509
1751
  position: 'relative'
1510
- }
1752
+ },
1753
+ ref: ref
1511
1754
  // onMouseUp={handleMouseUp}
1512
1755
  }, /*#__PURE__*/_react.default.createElement(_useContext.TableContext.Provider, {
1513
1756
  value: {
@@ -1529,7 +1772,7 @@ const GridEdit = props => {
1529
1772
  rowHoverBg: '#eb461912',
1530
1773
  rowSelectedBg: '#eb4619',
1531
1774
  rowSelectedHoverBg: '#eb4619',
1532
- cellFontSize: 12,
1775
+ // cellFontSize: 12,
1533
1776
  cellFontSizeSM: 13,
1534
1777
  headerBg: '#ffffff',
1535
1778
  cellPaddingBlockSM: 7
@@ -1542,11 +1785,13 @@ const GridEdit = props => {
1542
1785
  }
1543
1786
  }, /*#__PURE__*/_react.default.createElement(_TableGrid.default, (0, _extends2.default)({}, rest, {
1544
1787
  t: t,
1788
+ id: id,
1545
1789
  tableRef: tableRef,
1546
1790
  dataSource: dataSource,
1547
1791
  components: {
1548
1792
  ...components,
1549
1793
  body: {
1794
+ // wrapper: () => <div></div>,
1550
1795
  cell: _EditableCell.default
1551
1796
  // cell: () => <EditableCell />,
1552
1797
  }
@@ -1559,11 +1804,15 @@ const GridEdit = props => {
1559
1804
  target: 'sorter-icon'
1560
1805
  },
1561
1806
  format: format,
1562
- toolbarItems: toolbarItems,
1807
+ toolbarItems: toolbarItems
1808
+ // selectionSettings={selectionSettings ? {...selectionSettings, checkboxOnly: true} : undefined}
1809
+ ,
1563
1810
  selectionSettings: selectionSettings ? {
1564
1811
  ...selectionSettings,
1565
1812
  checkboxOnly: true
1566
- } : undefined,
1813
+ } : {
1814
+ checkboxOnly: true
1815
+ },
1567
1816
  rowHoverable: false,
1568
1817
  bottomToolbar: bottomToolbar,
1569
1818
  expandable: {
@@ -1603,13 +1852,18 @@ const GridEdit = props => {
1603
1852
  }
1604
1853
  },
1605
1854
  triggerChangeColumns: triggerChangeColumns,
1855
+ clickHeaderToSort: false,
1606
1856
  rowSelection: columns && columns.length === 0 ? undefined : {
1607
1857
  type: mode === 'checkbox' || type === 'multiple' ? 'checkbox' : "radio",
1608
1858
  columnWidth: !mode ? 0.0000001 : columnWidth ?? 50,
1609
1859
  onChange: onSelectChange,
1610
1860
  selectedRowKeys: mergedSelectedKeys,
1611
1861
  preserveSelectedRowKeys: true
1612
- }
1862
+ },
1863
+ isFilter: isFilter,
1864
+ setIsFilter: setIsFilter,
1865
+ contextMenuItems: contextMenuItems,
1866
+ contextMenuClick: contextMenuClick
1613
1867
  })))))), /*#__PURE__*/_react.default.createElement(_reactHotToast.Toaster, {
1614
1868
  position: toast,
1615
1869
  toastOptions: {