es-grid-template 1.4.4 → 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.
@@ -10,6 +10,7 @@ type Props<T> = GridTableProps<T> & {
10
10
  triggerPaste?: (pastedRows: T[], pastedColumnsArray: string[], newData: T[]) => void;
11
11
  triggerFilter?: (queries: any) => void;
12
12
  setTooltipContent?: any;
13
+ scrollHeight?: number;
13
14
  };
14
15
  declare const Group: <RecordType extends object>(props: Props<RecordType>) => React.JSX.Element;
15
16
  export default Group;
@@ -11,8 +11,10 @@ import { Collapse2, Expand2 } from "becoxy-icons";
11
11
  const Group = props => {
12
12
  const {
13
13
  t,
14
+ id,
14
15
  columns,
15
16
  height,
17
+ scrollHeight,
16
18
  style,
17
19
  rowHoverable,
18
20
  groupAble,
@@ -97,11 +99,14 @@ const Group = props => {
97
99
  };
98
100
  return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(GridStyle, {
99
101
  $heightTable: height,
102
+ $heightScroll: scrollHeight,
100
103
  style: {
101
104
  position: 'relative'
102
- }
105
+ },
106
+ id: id
103
107
  }, /*#__PURE__*/React.createElement(TableGrid, _extends({}, rest, {
104
108
  t: t,
109
+ id: id,
105
110
  columns: columns,
106
111
  style: {
107
112
  ...style,
@@ -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 {};
@@ -9,4 +9,4 @@ var _styledComponents = _interopRequireDefault(require("styled-components"));
9
9
  const GridStyle = exports.GridStyle = _styledComponents.default.div.withConfig({
10
10
  displayName: "GridStyle",
11
11
  componentId: "es-grid-template__sc-sueu2e-0"
12
- })([".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);
12
+ })(["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);
@@ -33,6 +33,7 @@ var _modifiers = require("@dnd-kit/modifiers");
33
33
  var _core = require("@dnd-kit/core");
34
34
  var _sortable = require("@dnd-kit/sortable");
35
35
  var _reactResizable = require("react-resizable");
36
+ var _faker = require("@faker-js/faker");
36
37
  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); }
37
38
  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; }
38
39
  // import {Resizable} from "react-resizable";
@@ -153,6 +154,7 @@ const SortableHeaderCell = ({
153
154
  const InternalTable = props => {
154
155
  const {
155
156
  t,
157
+ id: tableId,
156
158
  // columns,
157
159
  columns: propsColumns,
158
160
  lang,
@@ -179,11 +181,37 @@ const InternalTable = props => {
179
181
  commandClick,
180
182
  commandSettings,
181
183
  pagination,
184
+ height: propsHeight,
185
+ summary,
182
186
  ...rest
183
187
  } = props;
188
+ const id = _react.default.useMemo(() => {
189
+ return tableId ?? _faker.faker.string.alpha(20);
190
+ // return tableId ?? newGuid()
191
+ }, [tableId]);
184
192
  const rowKey = _react.default.useMemo(() => {
185
- return editAble ? 'rowId' : propRowKey ?? 'rowId';
186
- }, [propRowKey, editAble]);
193
+ return propRowKey ?? 'rowId';
194
+ }, [propRowKey]);
195
+ const [scrollHeight, setHeight] = (0, _react.useState)(0);
196
+
197
+ // const heightt = React.useMemo(() => {
198
+ //
199
+ // const table = document.querySelector(`#${id}`)
200
+ // console.log('table', table)
201
+ //
202
+ // const title: any = table?.querySelector(`.ui-rc-table-title`)
203
+ //
204
+ // console.log('title', title)
205
+ //
206
+ // if (title) {
207
+ // const titleHeight = title.offsetHeight;
208
+ // console.log('Chiều cao:', titleHeight);
209
+ // }
210
+ //
211
+ // return (height ?? 0) - (title ? title.offsetHeight : 0)
212
+ //
213
+ // }, [height, id])
214
+
187
215
  const local = lang && lang === 'en' ? _en_US.default : _vi_VN.default;
188
216
  const buddhistLocale = {
189
217
  ...local,
@@ -205,6 +233,19 @@ const InternalTable = props => {
205
233
  return (0, _hooks.addRowIdArray)(dataSource);
206
234
  }, [dataSource]);
207
235
  const [columns, setColumns] = _react.default.useState([]);
236
+ _react.default.useEffect(() => {
237
+ // setTimeout(() => {
238
+ const table = document.querySelector(`#${id}`);
239
+ const title = table?.querySelector(`.ui-rc-table-title`);
240
+ const header = table?.querySelector(`.ui-rc-table-header`);
241
+ const paginationE = table?.querySelector(`.ui-rc-pagination`);
242
+ const toolbar = table?.querySelector(`.ui-rc-toolbar-bottom`);
243
+ const summaryE = table?.querySelector(`.ui-rc-table-summary`);
244
+ const scrollbar = table?.querySelector(`.ui-rc-table-tbody-virtual-scrollbar.ui-rc-table-tbody-virtual-scrollbar-horizontal`);
245
+ 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);
246
+ setHeight(hhh);
247
+ // })
248
+ }, [id, propsHeight, columns]);
208
249
  const tableRef = _react.default.useRef(null);
209
250
  _react.default.useEffect(() => {
210
251
  setColumns(propsColumns);
@@ -494,26 +535,46 @@ const InternalTable = props => {
494
535
  if (column === SELECTION_COLUMN) {
495
536
  return SELECTION_COLUMN;
496
537
  }
497
- if (find) {
538
+ const tmpColumn = {
539
+ ...column,
540
+ dataIndex: column.field ?? column.dataIndex,
541
+ key: column.field ?? column.key,
542
+ title: /*#__PURE__*/_react.default.createElement(SortableHeaderCell, {
543
+ columnKey: column.field
544
+ }, /*#__PURE__*/_react.default.createElement(_HeaderContent.default, {
545
+ column: {
546
+ ...column
547
+ },
548
+ t: t
549
+ })),
550
+ ellipsis: column.ellipsis !== false,
551
+ align: column.textAlign ?? column.align,
552
+ fixed: column.fixedType ?? column.fixed,
553
+ isSummary: column.isSummary ?? column.haveSum,
554
+ hidden: column.hidden ?? column.visible === false
555
+ };
556
+
557
+ // Xử lý đệ quy cho children
558
+ if (column.children?.length) {
498
559
  return {
499
- ...find
560
+ ...column,
561
+ ...tmpColumn,
562
+ children: transformColumns(column.children)
500
563
  };
501
564
  }
502
- if (!find) {
565
+ if (find) {
503
566
  return {
504
- ...column
567
+ ...find
505
568
  };
506
569
  }
507
-
508
- // Xử lý đệ quy cho children
509
- if (column.children?.length) {
570
+ if (!find) {
510
571
  return {
511
572
  ...column,
512
- children: transformColumns(column.children)
573
+ ...tmpColumn
513
574
  };
514
575
  }
515
576
  });
516
- }, [convertColumns]);
577
+ }, [convertColumns, t]);
517
578
  const mergedColumns = _react.default.useMemo(() => {
518
579
  return transformColumns(columns);
519
580
  }, [columns, transformColumns]);
@@ -607,13 +668,13 @@ const InternalTable = props => {
607
668
  };
608
669
  const triggerCommandClick = args => {
609
670
  const {
610
- id,
671
+ id: idCommand,
611
672
  rowId,
612
673
  rowData,
613
674
  index
614
675
  } = args;
615
676
  const tmpData = [...mergedData];
616
- if (id === 'DELETE') {
677
+ if (idCommand === 'DELETE') {
617
678
  // bật modal confirm
618
679
  if (commandSettings && commandSettings.confirmDialog) {
619
680
  MySwal.fire({
@@ -699,7 +760,7 @@ const InternalTable = props => {
699
760
  }
700
761
  if (commandClick) {
701
762
  commandClick({
702
- id,
763
+ id: idCommand,
703
764
  rowId,
704
765
  rowData,
705
766
  index,
@@ -710,7 +771,7 @@ const InternalTable = props => {
710
771
  // server
711
772
  if (commandClick) {
712
773
  commandClick({
713
- id,
774
+ id: idCommand,
714
775
  rowId,
715
776
  rowData,
716
777
  index,
@@ -771,6 +832,7 @@ const InternalTable = props => {
771
832
  value: dragIndex
772
833
  }, /*#__PURE__*/_react.default.createElement(TableComponent, (0, _extends2.default)({}, rest, {
773
834
  t: t,
835
+ id: id,
774
836
  locale: locale,
775
837
  tableRef: tableRef,
776
838
  dataSource: mergedData,
@@ -790,7 +852,17 @@ const InternalTable = props => {
790
852
  groupAble: groupAble,
791
853
  groupColumns: groupColumns,
792
854
  commandClick: triggerCommandClick,
793
- pagination: pagination,
855
+ summary: summary,
856
+ pagination: pagination
857
+ // scroll={{ y: 300 - 41 - 7 }} // scroll height auto, không quá 600
858
+ // scroll={{ y: scrollHeight - (summary ? 0 : 7) }} // scroll height auto, không quá 600
859
+ ,
860
+ scroll: {
861
+ y: scrollHeight - (summary ? 0 : 0)
862
+ } // scroll height auto, không quá 600
863
+ ,
864
+ height: propsHeight,
865
+ scrollHeight: scrollHeight,
794
866
  components: {
795
867
  header: {
796
868
  cell: ResizableTitle
@@ -1587,7 +1587,7 @@ function getCellsByPosition(cellSet, position = "bottom") {
1587
1587
  const minRow = Math.min(...cells.map(c => c.row));
1588
1588
  if (minRow === 0) return []; // Bỏ qua nếu rowIndex = 0
1589
1589
 
1590
- return cells.filter(c => c.row === minRow).map(c => `${c.row - 1}-${c.col}`);
1590
+ return cells.filter(c => c.row === minRow).map(c => `${c.row}-${c.col}`);
1591
1591
  }
1592
1592
  case "bottom":
1593
1593
  {
@@ -1608,7 +1608,7 @@ function getCellsByPosition(cellSet, position = "bottom") {
1608
1608
  if (minCol === 0) return []; // Bỏ qua nếu colIndex = 0
1609
1609
 
1610
1610
  // Trả về các ô cùng row, nhưng ở cột bên trái
1611
- return cells.filter(c => c.col === minCol).map(c => `${c.row}-${c.col - 1}`);
1611
+ return cells.filter(c => c.col === minCol).map(c => `${c.row}-${c.col}`);
1612
1612
  }
1613
1613
  case "right":
1614
1614
  {
@@ -1635,20 +1635,29 @@ const addBorderClass = (selectedCells, type, className, id, nextCellRight) => {
1635
1635
  }
1636
1636
  });
1637
1637
  }
1638
- if (type === 'left') {
1639
- const selectorsCells2 = typeCells.map(pos => {
1640
- const [row, col] = pos.split('-');
1641
- return `[data-row-index="${row}"][data-col-index="${Number(col) + 1}"]`;
1642
- });
1643
- const fullSelector = selectorsCells2.map(s => `.ui-rc-table-cell-fix-right-first${s}`).join(', ');
1644
- const cellsFilter2 = typeCells.length > 0 ? table?.querySelectorAll(fullSelector) : null;
1645
- if (cellsFilter2 && cellsFilter2.length > 0) {
1646
- cellsFilter2.forEach(cell => {
1647
- // cell.classList.add('has-before');
1648
- cell.classList.add('cell-border-left');
1649
- });
1650
- }
1651
- }
1638
+
1639
+ // ui-rc-table-tbody-virtual-scrollbar ui-rc-table-tbody-virtual-scrollbar-horizontal ui-rc-table-tbody-virtual-scrollbar-visible
1640
+
1641
+ // if (type === 'left') {
1642
+ //
1643
+ // const selectorsCells2 = typeCells.map((pos: any) => {
1644
+ // const [row, col] = pos.split('-');
1645
+ // return `[data-row-index="${row}"][data-col-index="${Number(col) + 1}"]`;
1646
+ // });
1647
+ //
1648
+ // const fullSelector = selectorsCells2.map(s => `.ui-rc-table-cell-fix-right-first${s}`).join(', ');
1649
+ //
1650
+ // const cellsFilter2 = typeCells.length > 0 ? table?.querySelectorAll(fullSelector) : null
1651
+ //
1652
+ // if (cellsFilter2 && cellsFilter2.length > 0) {
1653
+ //
1654
+ // cellsFilter2.forEach(cell => {
1655
+ // // cell.classList.add('has-before');
1656
+ // cell.classList.add('cell-border-left');
1657
+ // });
1658
+ // }
1659
+ //
1660
+ // }
1652
1661
  };
1653
1662
  exports.addBorderClass = addBorderClass;
1654
1663
  const removeBorderClass = (selectedCells, type, className, id) => {
@@ -1800,9 +1809,7 @@ const onAddBorderSelectedCell = (selectedCells, id) => {
1800
1809
  const col = getLastSelectCell(selectedCells).col;
1801
1810
  const cell = table?.querySelector(`.ui-rc-table-cell[data-row-index="${row}"][data-col-index="${col}"]`);
1802
1811
  const nextCellLeft = table?.querySelector(`.ui-rc-table-cell.ui-rc-table-cell-fix-left[data-row-index="${row}"][data-col-index="${col + 1}"]`);
1803
- // const nextCellRight: any = table?.querySelector(`.ui-rc-table-cell.ui-rc-table-cell-fix-right[data-row-index="${row}"][data-col-index="${col + 1}"]`)
1804
-
1805
- console.log('nextCell', nextCellLeft);
1812
+ const nextCellRight = table?.querySelector(`.ui-rc-table-cell.ui-rc-table-cell-fix-right[data-row-index="${row}"][data-col-index="${col + 1}"]`);
1806
1813
  if (cell) {
1807
1814
  cell.style.zIndex = nextCellLeft ? 3 : 1;
1808
1815
  }
@@ -1817,7 +1824,7 @@ const onAddBorderSelectedCell = (selectedCells, id) => {
1817
1824
  // thêm class border selected
1818
1825
 
1819
1826
  addBorderClass(selectedCells, 'bottom', 'cell-border-bottom', id);
1820
- addBorderClass(selectedCells, 'right', 'cell-border-right', id);
1827
+ addBorderClass(selectedCells, 'right', 'cell-border-right', id, !!nextCellRight);
1821
1828
  addBorderClass(selectedCells, 'top', 'cell-border-top', id);
1822
1829
  addBorderClass(selectedCells, 'left', 'cell-border-left', id);
1823
1830
  };