es-grid-template 1.4.3 → 1.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  interface GridProps {
3
- $heightTable?: number | string;
3
+ $heightTable?: number;
4
+ $heightScroll?: number;
4
5
  }
5
6
  export declare const GridStyle: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, GridProps>> & string;
6
7
  export {};
@@ -2,4 +2,4 @@ import styled from "styled-components";
2
2
  export const GridStyle = styled.div.withConfig({
3
3
  displayName: "GridStyle",
4
4
  componentId: "es-grid-template__sc-sueu2e-0"
5
- })([".ui-rc-table-container{min-height:", ";}.ui-rc-toolbar-bottom{position:relative;padding:.25rem 1rem;background-color:#ffffff;&::before{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:100%;bottom:0;left:0;}&::after{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:100%;bottom:0;visibility:visible;right:0;}.toolbar-button{border-radius:0;.ant-btn{border-radius:0;}}}.ui-rc-pagination{border-bottom:1px solid #e0e0e0;border-top:1px solid #e0e0e0;margin:0;padding:.75rem 1rem;background-color:#ffffff;.ui-rc-pagination-total-text{order:2;margin-left:auto;}&::before{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:50px;bottom:0;left:0;}&::after{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:50px;bottom:0;visibility:visible;right:0;}&.pagination-template{position:relative;&::before{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:100%;bottom:0;left:0;}&::after{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:100%;bottom:0;visibility:visible;right:0;}}}.react-resizable{position:relative;background-clip:padding-box;}.rc-resizable-handle{position:absolute;right:0px;bottom:0;z-index:1;width:5px;height:100%;cursor:col-resize;&.none{cursor:auto;display:none;}}"], props => props.$heightTable ? typeof props.$heightTable === 'string' ? props.$heightTable : `${props.$heightTable}px` : undefined);
5
+ })(["height:", ";.ui-rc-table.ui-rc-table-virtual.ui-rc-table-scroll-horizontal{.ui-rc-table-container{padding-bottom:8px;border-bottom:1px solid #e0e0e0;}}.ui-rc-table-container{.ui-rc-table-tbody-virtual.ui-rc-table-tbody{min-height:", ";}}.ui-rc-toolbar-bottom{position:relative;padding:.25rem 1rem;background-color:#ffffff;&::before{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:100%;bottom:0;left:0;}&::after{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:100%;bottom:0;visibility:visible;right:0;}.toolbar-button{border-radius:0;.ant-btn{border-radius:0;}}}.ui-rc-pagination{border-bottom:1px solid #e0e0e0;border-top:1px solid #e0e0e0;margin:0;padding:.75rem 1rem;background-color:#ffffff;.ui-rc-pagination-total-text{order:2;margin-left:auto;}&::before{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:50px;bottom:0;left:0;}&::after{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:50px;bottom:0;visibility:visible;right:0;}&.pagination-template{position:relative;&::before{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:100%;bottom:0;left:0;}&::after{content:\"\";position:absolute;border-left:1px solid #e0e0e0;height:100%;bottom:0;visibility:visible;right:0;}}}.react-resizable{position:relative;background-clip:padding-box;}.rc-resizable-handle{position:absolute;right:0px;bottom:0;z-index:1;width:5px;height:100%;cursor:col-resize;&.none{cursor:auto;display:none;}}"], props => props.$heightTable ? `${props.$heightTable}px` : undefined, props => props.$heightScroll ? `${props.$heightScroll}px` : undefined);
@@ -30,6 +30,7 @@ import { closestCenter, DndContext, DragOverlay, PointerSensor, useSensor, useSe
30
30
  import { arrayMove, horizontalListSortingStrategy, SortableContext, useSortable } from "@dnd-kit/sortable";
31
31
  // import {CSS} from "@dnd-kit/utilities";
32
32
  import { Resizable } from "react-resizable";
33
+ import { faker } from "@faker-js/faker";
33
34
  dayjs.extend(customParseFormat);
34
35
  const MySwal = withReactContent(Swal);
35
36
  const ASCEND = 'ascend';
@@ -142,6 +143,7 @@ const SortableHeaderCell = ({
142
143
  const InternalTable = props => {
143
144
  const {
144
145
  t,
146
+ id: tableId,
145
147
  // columns,
146
148
  columns: propsColumns,
147
149
  lang,
@@ -168,11 +170,37 @@ const InternalTable = props => {
168
170
  commandClick,
169
171
  commandSettings,
170
172
  pagination,
173
+ height: propsHeight,
174
+ summary,
171
175
  ...rest
172
176
  } = props;
177
+ const id = React.useMemo(() => {
178
+ return tableId ?? faker.string.alpha(20);
179
+ // return tableId ?? newGuid()
180
+ }, [tableId]);
173
181
  const rowKey = React.useMemo(() => {
174
182
  return propRowKey ?? 'rowId';
175
183
  }, [propRowKey]);
184
+ const [scrollHeight, setHeight] = useState(0);
185
+
186
+ // const heightt = React.useMemo(() => {
187
+ //
188
+ // const table = document.querySelector(`#${id}`)
189
+ // console.log('table', table)
190
+ //
191
+ // const title: any = table?.querySelector(`.ui-rc-table-title`)
192
+ //
193
+ // console.log('title', title)
194
+ //
195
+ // if (title) {
196
+ // const titleHeight = title.offsetHeight;
197
+ // console.log('Chiều cao:', titleHeight);
198
+ // }
199
+ //
200
+ // return (height ?? 0) - (title ? title.offsetHeight : 0)
201
+ //
202
+ // }, [height, id])
203
+
176
204
  const local = lang && lang === 'en' ? en : vi;
177
205
  const buddhistLocale = {
178
206
  ...local,
@@ -194,6 +222,19 @@ const InternalTable = props => {
194
222
  return addRowIdArray(dataSource);
195
223
  }, [dataSource]);
196
224
  const [columns, setColumns] = React.useState([]);
225
+ React.useEffect(() => {
226
+ // setTimeout(() => {
227
+ const table = document.querySelector(`#${id}`);
228
+ const title = table?.querySelector(`.ui-rc-table-title`);
229
+ const header = table?.querySelector(`.ui-rc-table-header`);
230
+ const paginationE = table?.querySelector(`.ui-rc-pagination`);
231
+ const toolbar = table?.querySelector(`.ui-rc-toolbar-bottom`);
232
+ const summaryE = table?.querySelector(`.ui-rc-table-summary`);
233
+ const scrollbar = table?.querySelector(`.ui-rc-table-tbody-virtual-scrollbar.ui-rc-table-tbody-virtual-scrollbar-horizontal`);
234
+ const hhh = (propsHeight ?? 0) - (title ? title.offsetHeight : 0) - (header ? header.offsetHeight : 0) - (paginationE ? paginationE.offsetHeight : 0) - (toolbar ? toolbar.offsetHeight : 0) - (summaryE ? summaryE.offsetHeight : 0) - (scrollbar ? scrollbar.offsetHeight : 0);
235
+ setHeight(hhh);
236
+ // })
237
+ }, [id, propsHeight, columns]);
197
238
  const tableRef = React.useRef(null);
198
239
  React.useEffect(() => {
199
240
  setColumns(propsColumns);
@@ -352,6 +393,12 @@ const InternalTable = props => {
352
393
  if (transformedColumn.field === '#') {
353
394
  return {
354
395
  ...transformedColumn,
396
+ title: () => /*#__PURE__*/React.createElement(HeaderContent, {
397
+ column: {
398
+ ...column
399
+ },
400
+ t: t
401
+ }),
355
402
  onCell: () => ({
356
403
  className: 'cell-number'
357
404
  }),
@@ -366,6 +413,12 @@ const InternalTable = props => {
366
413
  if (transformedColumn.field === 'command') {
367
414
  return {
368
415
  ...transformedColumn,
416
+ title: () => /*#__PURE__*/React.createElement(HeaderContent, {
417
+ column: {
418
+ ...column
419
+ },
420
+ t: t
421
+ }),
369
422
  onCell: () => ({
370
423
  className: 'cell-number',
371
424
  style: {
@@ -471,26 +524,46 @@ const InternalTable = props => {
471
524
  if (column === SELECTION_COLUMN) {
472
525
  return SELECTION_COLUMN;
473
526
  }
474
- if (find) {
527
+ const tmpColumn = {
528
+ ...column,
529
+ dataIndex: column.field ?? column.dataIndex,
530
+ key: column.field ?? column.key,
531
+ title: /*#__PURE__*/React.createElement(SortableHeaderCell, {
532
+ columnKey: column.field
533
+ }, /*#__PURE__*/React.createElement(HeaderContent, {
534
+ column: {
535
+ ...column
536
+ },
537
+ t: t
538
+ })),
539
+ ellipsis: column.ellipsis !== false,
540
+ align: column.textAlign ?? column.align,
541
+ fixed: column.fixedType ?? column.fixed,
542
+ isSummary: column.isSummary ?? column.haveSum,
543
+ hidden: column.hidden ?? column.visible === false
544
+ };
545
+
546
+ // Xử lý đệ quy cho children
547
+ if (column.children?.length) {
475
548
  return {
476
- ...find
549
+ ...column,
550
+ ...tmpColumn,
551
+ children: transformColumns(column.children)
477
552
  };
478
553
  }
479
- if (!find) {
554
+ if (find) {
480
555
  return {
481
- ...column
556
+ ...find
482
557
  };
483
558
  }
484
-
485
- // Xử lý đệ quy cho children
486
- if (column.children?.length) {
559
+ if (!find) {
487
560
  return {
488
561
  ...column,
489
- children: transformColumns(column.children)
562
+ ...tmpColumn
490
563
  };
491
564
  }
492
565
  });
493
- }, [convertColumns]);
566
+ }, [convertColumns, t]);
494
567
  const mergedColumns = React.useMemo(() => {
495
568
  return transformColumns(columns);
496
569
  }, [columns, transformColumns]);
@@ -584,13 +657,13 @@ const InternalTable = props => {
584
657
  };
585
658
  const triggerCommandClick = args => {
586
659
  const {
587
- id,
660
+ id: idCommand,
588
661
  rowId,
589
662
  rowData,
590
663
  index
591
664
  } = args;
592
665
  const tmpData = [...mergedData];
593
- if (id === 'DELETE') {
666
+ if (idCommand === 'DELETE') {
594
667
  // bật modal confirm
595
668
  if (commandSettings && commandSettings.confirmDialog) {
596
669
  MySwal.fire({
@@ -676,7 +749,7 @@ const InternalTable = props => {
676
749
  }
677
750
  if (commandClick) {
678
751
  commandClick({
679
- id,
752
+ id: idCommand,
680
753
  rowId,
681
754
  rowData,
682
755
  index,
@@ -687,7 +760,7 @@ const InternalTable = props => {
687
760
  // server
688
761
  if (commandClick) {
689
762
  commandClick({
690
- id,
763
+ id: idCommand,
691
764
  rowId,
692
765
  rowData,
693
766
  index,
@@ -748,6 +821,7 @@ const InternalTable = props => {
748
821
  value: dragIndex
749
822
  }, /*#__PURE__*/React.createElement(TableComponent, _extends({}, rest, {
750
823
  t: t,
824
+ id: id,
751
825
  locale: locale,
752
826
  tableRef: tableRef,
753
827
  dataSource: mergedData,
@@ -767,7 +841,17 @@ const InternalTable = props => {
767
841
  groupAble: groupAble,
768
842
  groupColumns: groupColumns,
769
843
  commandClick: triggerCommandClick,
770
- pagination: pagination,
844
+ summary: summary,
845
+ pagination: pagination
846
+ // scroll={{ y: 300 - 41 - 7 }} // scroll height auto, không quá 600
847
+ // scroll={{ y: scrollHeight - (summary ? 0 : 7) }} // scroll height auto, không quá 600
848
+ ,
849
+ scroll: {
850
+ y: scrollHeight - (summary ? 0 : 0)
851
+ } // scroll height auto, không quá 600
852
+ ,
853
+ height: propsHeight,
854
+ scrollHeight: scrollHeight,
771
855
  components: {
772
856
  header: {
773
857
  cell: ResizableTitle
@@ -29,8 +29,8 @@ const HeaderContent = props => {
29
29
  return columnGroupText ?? headerText;
30
30
  }, [columnGroupText, headerText]);
31
31
  const tooltip = React.useMemo(() => {
32
- return headerTooltip ?? columnGroupText ?? headerText;
33
- }, [columnGroupText, headerText, headerTooltip]);
32
+ return headerTooltip ?? t ? t(columnGroupText ?? headerText) : columnGroupText ?? headerText;
33
+ }, [columnGroupText, headerText, headerTooltip, t]);
34
34
  //
35
35
  //
36
36
  // const [isOpen, setIsOpen] = useState(false)
@@ -67,9 +67,7 @@ const HeaderContent = props => {
67
67
  // style={{flex: 1, overflow: 'hidden', textOverflow: 'ellipsis', wordBreak: 'keep-all'}}
68
68
  // style={{flex: 1}}
69
69
  className: classnames('', {}),
70
- "data-tooltip-id": "tooltip-header"
71
- // data-tooltip-id="tooltip-cell-content"
72
- ,
70
+ "data-tooltip-id": "tooltip-header",
73
71
  "data-tooltip-content": tooltip,
74
72
  "data-tooltip-offset": 16
75
73
  }, headerTemplate ? getTemplate(headerTemplate) : t ? t(text) : text));
@@ -276,8 +276,7 @@ const useColumns = config => {
276
276
  className: classNames(transformedColumn?.onCell?.(data, index).className ?? '', {
277
277
  'cell-group': groupColumns && data.children,
278
278
  'cell-group-fixed': groupColumns && data.children && col.field === firstNonGroupColumn?.field
279
- }),
280
- 'data-tooltip-id': "tooltip-cell-content"
279
+ })
281
280
  // onMouseEnter: () => {
282
281
  // onMouseHover(data, col as any)
283
282
  // },
@@ -121,12 +121,14 @@ export declare const sortedSetASC: (setValue: any) => Set<unknown>;
121
121
  export declare const sortedSetDSC: (setValue: any) => Set<unknown>;
122
122
  export declare function getBottomRowCells(cellSet: any): any[];
123
123
  export declare function getCellsByPosition(cellSet: any, position?: string): any[];
124
- export declare const addBorderClass: (selectedCells: any, type: string, className: string, id?: string) => void;
124
+ export declare const addBorderClass: (selectedCells: any, type: string, className: string, id?: string, nextCellRight?: boolean) => void;
125
125
  export declare const removeBorderClass: (selectedCells: any, type: string, className: string, id?: string) => void;
126
126
  export declare const removeBorderClass2: (className: string, id?: string) => void;
127
127
  export declare const onAddBgSelectedCell: (selectedCells: any, id?: string, isFocusCellIndex?: boolean) => void;
128
- export declare const onAddBorderSelectedCell: (selectedCells: any, id?: string) => void;
129
128
  export declare const onRemoveBgSelectedCell: (selectedCells: any, id?: string, rowsSelected?: any) => void;
129
+ export declare const onAddBgCellIndex: (selectedCells: any, id?: string, isFocusCellIndex?: boolean) => void;
130
+ export declare const onRemoveBgCellIndex: (selectedCells: any, id?: string, rowsSelected?: any) => void;
131
+ export declare const onAddBorderSelectedCell: (selectedCells: any, id?: string) => void;
130
132
  export declare const onRemoveBorderSelectedCell: (selectedCells: any, id?: string) => void;
131
133
  export declare const addClassBorderPasteCell: (pasteCells: any, type: 'up' | 'down', id?: string) => void;
132
134
  export declare const removeClassBorderPasteCell: (pasteCells: any, type: 'up' | 'down', id?: string) => void;
@@ -134,3 +136,5 @@ export declare const addClassCellIndexSelected: (rowsSelected: any, id?: string)
134
136
  export declare const removeClassCellIndexSelected: (rowsSelected: any, id?: string) => void;
135
137
  export declare const showDraggingPoint: (selectedCells: any, id?: any) => void;
136
138
  export declare const hideDraggingPoint: (selectedCells: any, id?: any) => void;
139
+ export declare const isRangeCell: (selectedCells: any, type: string, rowIndex: number, colIndex: number) => boolean;
140
+ export declare const isSelectedCell: (selectedCells: any, rowIndex: number, colIndex: number) => any;
@@ -443,12 +443,9 @@ export const getDefaultValue = defaultValue => {
443
443
  export const addRowIdArray = inputArray => {
444
444
  if (inputArray) {
445
445
  return inputArray.map(item => {
446
- if (item.children && item.children.length > 0) {
447
- // item.children = convertArrayWithIndent(item.children)
446
+ if (typeof item.children !== "string" && item.children && item.children.length > 0) {
448
447
  item.children = addRowIdArray(item.children);
449
448
  }
450
-
451
- // return { ...item, rowId: item.rowId ? item.rowId : (item.id ? item.id : newGuid())}
452
449
  return {
453
450
  ...item,
454
451
  rowId: item.rowId ?? item.id ?? newGuid()
@@ -1494,7 +1491,7 @@ export function getCellsByPosition(cellSet, position = "bottom") {
1494
1491
  const minRow = Math.min(...cells.map(c => c.row));
1495
1492
  if (minRow === 0) return []; // Bỏ qua nếu rowIndex = 0
1496
1493
 
1497
- return cells.filter(c => c.row === minRow).map(c => `${c.row - 1}-${c.col}`);
1494
+ return cells.filter(c => c.row === minRow).map(c => `${c.row}-${c.col}`);
1498
1495
  }
1499
1496
  case "bottom":
1500
1497
  {
@@ -1515,7 +1512,7 @@ export function getCellsByPosition(cellSet, position = "bottom") {
1515
1512
  if (minCol === 0) return []; // Bỏ qua nếu colIndex = 0
1516
1513
 
1517
1514
  // Trả về các ô cùng row, nhưng ở cột bên trái
1518
- return cells.filter(c => c.col === minCol).map(c => `${c.row}-${c.col - 1}`);
1515
+ return cells.filter(c => c.col === minCol).map(c => `${c.row}-${c.col}`);
1519
1516
  }
1520
1517
  case "right":
1521
1518
  {
@@ -1526,7 +1523,7 @@ export function getCellsByPosition(cellSet, position = "bottom") {
1526
1523
  return [];
1527
1524
  }
1528
1525
  }
1529
- export const addBorderClass = (selectedCells, type, className, id) => {
1526
+ export const addBorderClass = (selectedCells, type, className, id, nextCellRight) => {
1530
1527
  const table = document.querySelector(`#${id}`);
1531
1528
  const typeCells = getCellsByPosition(selectedCells, type);
1532
1529
  const selectorsCells = typeCells.map(pos => {
@@ -1537,8 +1534,34 @@ export const addBorderClass = (selectedCells, type, className, id) => {
1537
1534
  if (cellsFilter && cellsFilter.length > 0) {
1538
1535
  cellsFilter.forEach(cell => {
1539
1536
  cell.classList.add(className);
1537
+ if (nextCellRight) {
1538
+ cell.style.zIndex = 1;
1539
+ }
1540
1540
  });
1541
1541
  }
1542
+
1543
+ // ui-rc-table-tbody-virtual-scrollbar ui-rc-table-tbody-virtual-scrollbar-horizontal ui-rc-table-tbody-virtual-scrollbar-visible
1544
+
1545
+ // if (type === 'left') {
1546
+ //
1547
+ // const selectorsCells2 = typeCells.map((pos: any) => {
1548
+ // const [row, col] = pos.split('-');
1549
+ // return `[data-row-index="${row}"][data-col-index="${Number(col) + 1}"]`;
1550
+ // });
1551
+ //
1552
+ // const fullSelector = selectorsCells2.map(s => `.ui-rc-table-cell-fix-right-first${s}`).join(', ');
1553
+ //
1554
+ // const cellsFilter2 = typeCells.length > 0 ? table?.querySelectorAll(fullSelector) : null
1555
+ //
1556
+ // if (cellsFilter2 && cellsFilter2.length > 0) {
1557
+ //
1558
+ // cellsFilter2.forEach(cell => {
1559
+ // // cell.classList.add('has-before');
1560
+ // cell.classList.add('cell-border-left');
1561
+ // });
1562
+ // }
1563
+ //
1564
+ // }
1542
1565
  };
1543
1566
  export const removeBorderClass = (selectedCells, type, className, id) => {
1544
1567
  const table = document.querySelector(`#${id}`);
@@ -1569,10 +1592,20 @@ export const onAddBgSelectedCell = (selectedCells, id, isFocusCellIndex) => {
1569
1592
  return `[data-row-index="${row1}"][data-col-index="${col1}"]`;
1570
1593
  });
1571
1594
  const table = document.querySelector(`#${id}`);
1595
+
1596
+ //// xóa class các ô đã chọn trước đó
1597
+ const cellsSelected = table ? table?.querySelectorAll('.ui-rc-table-cell.selected-bg') : null;
1598
+ if (cellsSelected) {
1599
+ cellsSelected.forEach(cell => {
1600
+ cell.classList.remove('selected-bg');
1601
+ });
1602
+ }
1603
+
1604
+ /// thêm class
1572
1605
  const cells = table && selectors.length > 0 ? table?.querySelectorAll(selectors.join(',')) : null;
1573
1606
  if (cells) {
1574
1607
  cells.forEach(cell => {
1575
- cell.classList.add('selected');
1608
+ cell.classList.add('selected-bg');
1576
1609
  });
1577
1610
  }
1578
1611
  const rowsArray = [...new Set([...selectedCells].map(item => item.split("-")[0]))];
@@ -1604,35 +1637,47 @@ export const onAddBgSelectedCell = (selectedCells, id, isFocusCellIndex) => {
1604
1637
  // addBorderClass(selectedCells, 'top', 'cell-border-top', id)
1605
1638
  // addBorderClass(selectedCells, 'left', 'cell-border-left', id)
1606
1639
  };
1607
- export const onAddBorderSelectedCell = (selectedCells, id) => {
1640
+ export const onRemoveBgSelectedCell = (selectedCells, id, rowsSelected) => {
1608
1641
  const table = document.querySelector(`#${id}`);
1609
-
1610
- // tăng z-index để hiển thị round point paste
1611
- const row = getLastSelectCell(selectedCells).row;
1612
- const col = getLastSelectCell(selectedCells).col;
1613
- const cell = table?.querySelector(`.ui-rc-table-cell[data-row-index="${row}"][data-col-index="${col}"]`);
1614
- if (cell) {
1615
- cell.style.zIndex = 1;
1642
+ const cells = table ? table?.querySelectorAll('.ui-rc-table-cell.selected-bg') : null;
1643
+ if (cells) {
1644
+ cells.forEach(cell => {
1645
+ cell.classList.remove('selected-bg');
1646
+ });
1616
1647
  }
1617
- if (cell && (cell.classList.contains('ui-rc-table-cell-fix-left') || cell.classList.contains('ui-rc-table-cell-fix-right'))) {
1618
- cell.style.zIndex = 3;
1648
+ const cellsIndex = table ? table?.querySelectorAll('.ui-rc-table-cell.focus') : null;
1649
+ if (cellsIndex) {
1650
+ cellsIndex.forEach(cell => {
1651
+ cell.classList.remove('focus');
1652
+ });
1619
1653
  }
1620
1654
 
1621
- // thêm class border selected
1655
+ // xóa class selected ô STT
1622
1656
 
1623
- addBorderClass(selectedCells, 'bottom', 'cell-border-bottom', id);
1624
- addBorderClass(selectedCells, 'right', 'cell-border-right', id);
1625
- addBorderClass(selectedCells, 'top', 'cell-border-top', id);
1626
- addBorderClass(selectedCells, 'left', 'cell-border-left', id);
1657
+ if (rowsSelected && rowsSelected.size > 0) {
1658
+ const rowsSelectedArray = [...new Set([...rowsSelected].map(item => item.split("-")[0]))];
1659
+ const rowsSelectedSelectors = rowsSelectedArray.map(r => `.rc-ui-cell-index[data-row-index="${r}"]`).join(", ");
1660
+ const cellsSelectedIndex = table && rowsSelectedSelectors.length > 0 ? table?.querySelectorAll(rowsSelectedSelectors) : null;
1661
+ if (cellsSelectedIndex) {
1662
+ cellsSelectedIndex.forEach(cell => {
1663
+ cell.classList.remove('selected');
1664
+ });
1665
+ }
1666
+ }
1627
1667
  };
1628
- export const onRemoveBgSelectedCell = (selectedCells, id, rowsSelected) => {
1668
+ export const onAddBgCellIndex = (selectedCells, id, isFocusCellIndex) => {
1629
1669
  const table = document.querySelector(`#${id}`);
1630
- const cells = table ? table?.querySelectorAll('.ui-rc-table-cell.selected') : null;
1631
- if (cells) {
1632
- cells.forEach(cell => {
1633
- cell.classList.remove('selected');
1670
+ const rowsArray = [...new Set([...selectedCells].map(item => item.split("-")[0]))];
1671
+ const rowsSelectors = rowsArray.map(r => `.rc-ui-cell-index[data-row-index="${r}"]`).join(", ");
1672
+ const cellsIndex = table && rowsSelectors.length > 0 ? table?.querySelectorAll(rowsSelectors) : null;
1673
+ if (cellsIndex && isFocusCellIndex !== false) {
1674
+ cellsIndex.forEach(cell => {
1675
+ cell.classList.add('focus');
1634
1676
  });
1635
1677
  }
1678
+ };
1679
+ export const onRemoveBgCellIndex = (selectedCells, id, rowsSelected) => {
1680
+ const table = document.querySelector(`#${id}`);
1636
1681
  const cellsIndex = table ? table?.querySelectorAll('.ui-rc-table-cell.focus') : null;
1637
1682
  if (cellsIndex) {
1638
1683
  cellsIndex.forEach(cell => {
@@ -1653,6 +1698,33 @@ export const onRemoveBgSelectedCell = (selectedCells, id, rowsSelected) => {
1653
1698
  }
1654
1699
  }
1655
1700
  };
1701
+ export const onAddBorderSelectedCell = (selectedCells, id) => {
1702
+ const table = document.querySelector(`#${id}`);
1703
+
1704
+ // tăng z-index để hiển thị round point paste
1705
+ const row = getLastSelectCell(selectedCells).row;
1706
+ const col = getLastSelectCell(selectedCells).col;
1707
+ const cell = table?.querySelector(`.ui-rc-table-cell[data-row-index="${row}"][data-col-index="${col}"]`);
1708
+ const nextCellLeft = table?.querySelector(`.ui-rc-table-cell.ui-rc-table-cell-fix-left[data-row-index="${row}"][data-col-index="${col + 1}"]`);
1709
+ const nextCellRight = table?.querySelector(`.ui-rc-table-cell.ui-rc-table-cell-fix-right[data-row-index="${row}"][data-col-index="${col + 1}"]`);
1710
+ if (cell) {
1711
+ cell.style.zIndex = nextCellLeft ? 3 : 1;
1712
+ }
1713
+ if (cell && (cell.classList.contains('ui-rc-table-cell-fix-left') || cell.classList.contains('ui-rc-table-cell-fix-right'))) {
1714
+ cell.style.zIndex = 3;
1715
+ }
1716
+ removeBorderClass2('cell-border-bottom', id);
1717
+ removeBorderClass2('cell-border-top', id);
1718
+ removeBorderClass2('cell-border-right', id);
1719
+ removeBorderClass2('cell-border-left', id);
1720
+
1721
+ // thêm class border selected
1722
+
1723
+ addBorderClass(selectedCells, 'bottom', 'cell-border-bottom', id);
1724
+ addBorderClass(selectedCells, 'right', 'cell-border-right', id, !!nextCellRight);
1725
+ addBorderClass(selectedCells, 'top', 'cell-border-top', id);
1726
+ addBorderClass(selectedCells, 'left', 'cell-border-left', id);
1727
+ };
1656
1728
  export const onRemoveBorderSelectedCell = (selectedCells, id) => {
1657
1729
  const table = document.querySelector(`#${id}`);
1658
1730
 
@@ -1660,13 +1732,11 @@ export const onRemoveBorderSelectedCell = (selectedCells, id) => {
1660
1732
 
1661
1733
  const row = getLastSelectCell(selectedCells).row;
1662
1734
  const col = getLastSelectCell(selectedCells).col;
1663
-
1664
- // const cell: any = table?.querySelector(`.ui-rc-table-cell[data-row-index="${row}"][data-col-index="${col}"]`)
1665
1735
  const cell = table?.querySelector(`.ui-rc-table-cell[data-row-index="${row}"][data-col-index="${col}"]`);
1666
1736
  if (cell) {
1667
1737
  cell.style.zIndex = 0;
1668
1738
  }
1669
- if (cell && cell.classList.contains('ui-rc-table-cell-fix-left')) {
1739
+ if (cell && (cell.classList.contains('ui-rc-table-cell-fix-left') || cell.classList.contains('ui-rc-table-cell-fix-right'))) {
1670
1740
  cell.style.zIndex = 2;
1671
1741
  }
1672
1742
 
@@ -1676,10 +1746,6 @@ export const onRemoveBorderSelectedCell = (selectedCells, id) => {
1676
1746
  removeBorderClass2('cell-border-top', id);
1677
1747
  removeBorderClass2('cell-border-right', id);
1678
1748
  removeBorderClass2('cell-border-left', id);
1679
-
1680
- // removeBorderClass(selectedCells, 'right', 'cell-border-right', id)
1681
- // removeBorderClass(selectedCells, 'top', 'cell-border-top', id)
1682
- // removeBorderClass(selectedCells, 'left', 'cell-border-left', id)
1683
1749
  };
1684
1750
  export const addClassBorderPasteCell = (pasteCells, type, id) => {
1685
1751
  // thêm class border
@@ -1701,6 +1767,8 @@ export const removeClassBorderPasteCell = (pasteCells, type, id) => {
1701
1767
  removeBorderClass(pasteCells, 'top', 'cell-paste-border-top', id);
1702
1768
  removeBorderClass(pasteCells, 'left', 'cell-paste-border-left', id);
1703
1769
  };
1770
+
1771
+ ///////////////////////////////
1704
1772
  export const addClassCellIndexSelected = (rowsSelected, id) => {
1705
1773
  // thêm class selected vào ô STT
1706
1774
  const table = document.querySelector(`#${id}`);
@@ -1710,7 +1778,7 @@ export const addClassCellIndexSelected = (rowsSelected, id) => {
1710
1778
  const cellsSelectedIndex = table && rowsSelectedSelectors.length > 0 ? table?.querySelectorAll(rowsSelectedSelectors) : null;
1711
1779
  if (cellsSelectedIndex) {
1712
1780
  cellsSelectedIndex.forEach(cell => {
1713
- cell.classList.add('selected');
1781
+ cell.classList.add('selected-index');
1714
1782
  });
1715
1783
  }
1716
1784
  }
@@ -1724,7 +1792,7 @@ export const removeClassCellIndexSelected = (rowsSelected, id) => {
1724
1792
  const cellsSelectedIndex = table && rowsSelectedSelectors.length > 0 ? table?.querySelectorAll(rowsSelectedSelectors) : null;
1725
1793
  if (cellsSelectedIndex) {
1726
1794
  cellsSelectedIndex.forEach(cell => {
1727
- cell.classList.remove('selected');
1795
+ cell.classList.remove('selected-index');
1728
1796
  });
1729
1797
  }
1730
1798
  }
@@ -1733,7 +1801,19 @@ export const showDraggingPoint = (selectedCells, id) => {
1733
1801
  const row = getLastSelectCell(selectedCells).row;
1734
1802
  const col = getLastSelectCell(selectedCells).col;
1735
1803
  const table = document.querySelector(`#${id}`);
1804
+
1805
+ // tăng z-index để hiển thị round point paste
1806
+
1736
1807
  const cell = table?.querySelector(`.ui-rc-table-cell[data-row-index="${row}"][data-col-index="${col}"]`);
1808
+
1809
+ // if (cell) {
1810
+ // cell.style.zIndex = 1
1811
+ // }
1812
+ //
1813
+ // if (cell && (cell.classList.contains('ui-rc-table-cell-fix-left') || cell.classList.contains('ui-rc-table-cell-fix-right'))) {
1814
+ // cell.style.zIndex = 3;
1815
+ // }
1816
+
1737
1817
  const point = cell?.querySelector('.dragging-point');
1738
1818
  if (point) {
1739
1819
  point.classList.add('show');
@@ -1743,19 +1823,37 @@ export const showDraggingPoint = (selectedCells, id) => {
1743
1823
  export const hideDraggingPoint = (selectedCells, id) => {
1744
1824
  const table = document.querySelector(`#${id}`);
1745
1825
 
1746
- // const point = table?.querySelector('.dragging-point.show')
1747
- // const points = document.querySelectorAll('.dragging-point.show')
1748
- const points = table?.querySelectorAll('.dragging-point.show');
1826
+ // xóa z-index về mặc định
1749
1827
 
1750
- // if (point) {
1751
- // point.classList.add('hidden')
1752
- // point.classList.remove('show')
1753
- // }
1828
+ const row = getLastSelectCell(selectedCells).row;
1829
+ const col = getLastSelectCell(selectedCells).col;
1830
+ const cell = table?.querySelector(`.ui-rc-table-cell[data-row-index="${row}"][data-col-index="${col}"]`);
1831
+ // const cellRight: any = table?.querySelector(`.ui-rc-table.ui-rc-table-ping-left:not(.ui-rc-table.ui-rc-table-ping-right) .ui-rc-table-tbody .rc-ui-cell-editable.cell-editable.ui-rc-table-cell-fix-right.ui-rc-table-cell[data-row-index="${row}"][data-col-index="${col + 1}"]`)
1754
1832
 
1833
+ if (cell) {
1834
+ cell.style.zIndex = 0;
1835
+ }
1836
+ if (cell && (cell.classList.contains('ui-rc-table-cell-fix-left') || cell.classList.contains('ui-rc-table-cell-fix-right'))) {
1837
+ // cell.style.zIndex = cellRight ? 1 : 2
1838
+ cell.style.zIndex = 2;
1839
+ }
1840
+ const points = table?.querySelectorAll('.dragging-point.show');
1755
1841
  if (points && points.length > 0) {
1756
- points.forEach(cell => {
1757
- cell.classList.add('hidden');
1758
- cell.classList.remove('show');
1842
+ points.forEach(c => {
1843
+ c.classList.add('hidden');
1844
+ c.classList.remove('show');
1759
1845
  });
1760
1846
  }
1847
+ };
1848
+ export const isRangeCell = (selectedCells, type, rowIndex, colIndex) => {
1849
+ const typeCells = getCellsByPosition(selectedCells, type);
1850
+ const key = `${rowIndex}-${colIndex}`;
1851
+ return typeCells.includes(key);
1852
+ };
1853
+ export const isSelectedCell = (selectedCells, rowIndex, colIndex) => {
1854
+ if (selectedCells.size === 1) {
1855
+ return false;
1856
+ }
1857
+ const key = `${rowIndex}-${colIndex}`;
1858
+ return selectedCells.has(key);
1761
1859
  };