es-grid-template 1.8.54 → 1.8.56

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.
@@ -21,8 +21,10 @@ import TableContainer from "../TableContainer";
21
21
  import { OperatorFeature } from "../features/operator";
22
22
  import { convertFilters, convertToObjTrue, filterByIds, filterDataByColumns, getAllRowKey, isObjEqual } from "../hook/utils";
23
23
  import TableContainerEdit from "../TableContainerEdit";
24
+ import classNames from 'classnames';
24
25
  const Grid = props => {
25
26
  const {
27
+ theme = 'light',
26
28
  t,
27
29
  id,
28
30
  prefix,
@@ -68,7 +70,7 @@ const Grid = props => {
68
70
  // const [rowSelection, setRowSelection] = React.useState<RowSelectionState>({})
69
71
 
70
72
  // const [rowSelection, setRowSelection] = React.useState<RowSelectionState>(convertToObjTrue(selectionSettings?.selectedRowKeys ?? []))
71
- const [rowSelection, setRowSelection] = React.useState(convertToObjTrue(mergedSelectedKeys));
73
+ const [rowSelection, setRowSelection] = React.useState({});
72
74
  // const [rowsSelected, setRowsSelected] = React.useState<RecordType[]>([])
73
75
 
74
76
  const [grouping, setGrouping] = React.useState([]);
@@ -122,6 +124,9 @@ const Grid = props => {
122
124
  }
123
125
  return true;
124
126
  },
127
+ initialState: {
128
+ rowSelection: {}
129
+ },
125
130
  onRowSelectionChange: setRowSelection,
126
131
  // RowSelection
127
132
 
@@ -169,49 +174,21 @@ const Grid = props => {
169
174
  }
170
175
  }
171
176
  }, [columnHidden, columnSizingInfo]);
172
-
173
- // React.useEffect(() => {
174
- // if (columnSizingInfo.isResizingColumn === false) {
175
-
176
- // const aa = updateColumnWidthsRecursive(propsColumns, columnSizing)
177
-
178
- // setColumns(aa)
179
-
180
- // }
181
-
182
- // }, [columnSizingInfo])
183
-
184
177
  React.useEffect(() => {
185
- // if (Object.keys(rowSelection) !== Object.keys(mergedSelectedKeys) && !isSelectionChange.isChange) {
186
- // setRowSelection(convertToObjTrue(mergedSelectedKeys))
187
-
188
- // }
189
-
190
178
  const isEqual = isObjEqual(convertToObjTrue(mergedSelectedKeys), rowSelection);
191
179
  if (!isEqual) {
192
- // setIsSelectionChange((prev) => ({
193
- // ...prev,
194
- // isChange: false
195
- // }))
196
- // setRowSelection(convertToObjTrue(mergedSelectedKeys))
180
+ setRowSelection(convertToObjTrue(mergedSelectedKeys));
197
181
  }
198
182
  }, [mergedSelectedKeys]);
199
183
  React.useEffect(() => {
200
184
  if (isSelectionChange.isChange) {
201
- // setManualUpdate(true)
202
185
  const aa = table.getState().rowSelection;
203
-
204
- // const dataTable = table.getRowModel().flatRows
205
-
206
186
  const ids = Object.keys(aa);
207
187
 
208
188
  // const ssss = dataTable.filter(it => ids.includes(it.id)) // lấy rowsData của trang hiện tại
209
189
  const ssss = filterByIds(ids, isSelectionChange.rowsData ?? []); // lấy rowsData của trang hiện tại
210
- // const ssss = (isSelectionChange.rowsData ?? []) as any[] // lấy rowsData của trang hiện tại
211
190
 
212
191
  const rs = ssss.map(it => it.original);
213
- // const rs = allRows.map(it => it.original)
214
-
215
192
  rowSelected?.({
216
193
  type: isSelectionChange.type,
217
194
  rowData: isSelectionChange.rowData,
@@ -279,7 +256,10 @@ const Grid = props => {
279
256
  const sensors = useSensors(useSensor(MouseSensor, {}), useSensor(TouchSensor, {}), useSensor(KeyboardSensor, {}));
280
257
  const ContainerComponent = editAble ? TableContainerEdit : TableContainer;
281
258
  return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", {
282
- className: `${prefix}-grid`,
259
+ className: classNames(`${prefix}-grid`, {
260
+ [`${prefix}-grid-light`]: theme === 'light',
261
+ [`${prefix}-grid-dark`]: theme === 'dark'
262
+ }),
283
263
  style: {
284
264
  minHeight: minHeight ?? undefined,
285
265
  maxHeight: height ?? undefined
@@ -352,7 +332,10 @@ const Grid = props => {
352
332
  paddingTop: 40
353
333
  }
354
334
  }, /*#__PURE__*/React.createElement("div", {
355
- className: `${prefix}-grid`,
335
+ className: classNames(`${prefix}-grid`, {
336
+ [`${prefix}-grid-light`]: theme === 'light',
337
+ [`${prefix}-grid-dark`]: theme === 'dark'
338
+ }),
356
339
  style: {
357
340
  // minHeight: minHeight ?? undefined,
358
341
  maxHeight: windowSize.innerHeight - 70
@@ -188,6 +188,7 @@ export type Locale = TableLocale & {
188
188
  };
189
189
  export type ColumnsTable<RecordType = AnyObject> = ColumnTable<RecordType>[];
190
190
  export type TableProps<RecordType = AnyObject> = {
191
+ theme?: 'dark' | 'light';
191
192
  title?: ReactNode | ((data: RecordType) => ReactNode);
192
193
  editAble?: boolean;
193
194
  infiniteScroll?: boolean;
@@ -103,6 +103,15 @@ const TableContainer = props => {
103
103
  settableHeight(totalHeight - topHeight - bottomHeight);
104
104
  }
105
105
  }, [id, height, editAble, minHeight]);
106
+ _react.default.useEffect(() => {
107
+ const handleClickOutside = () => {
108
+ setFocusedCell(undefined);
109
+ };
110
+ document.addEventListener('mousedown', handleClickOutside);
111
+ return () => {
112
+ document.removeEventListener('mousedown', handleClickOutside);
113
+ };
114
+ }, []);
106
115
  const visibleColumns = table.getVisibleLeafColumns();
107
116
  const fixedLeftColumns = table.getState().columnPinning.left ? visibleColumns.filter(vc => table.getState().columnPinning.left?.includes(vc.id)) : [];
108
117
  const fixedRightColumns = table.getState().columnPinning.right ? visibleColumns.filter(vc => table.getState().columnPinning.right?.includes(vc.id)) : [];
@@ -1931,14 +1931,15 @@ const TableContainerEdit = props => {
1931
1931
  }))), /*#__PURE__*/_react.default.createElement("div", {
1932
1932
  ref: bottomToolbarRef
1933
1933
  }, toolbarItemsBottom && toolbarItemsBottom.length > 0 && /*#__PURE__*/_react.default.createElement("div", {
1934
- className: 'ui-rc-toolbar-bottom'
1934
+ className: (0, _classnames.default)('ui-rc-toolbar-bottom', {
1935
+ 'ui-rc-toolbar-bottom_border-bottom': !pagination || infiniteScroll
1936
+ })
1935
1937
  // style={{ border: '0 1px 1px 1px solid #e0e0e0' }}
1936
- ,
1937
- style: {
1938
- borderBottom: '1px solid #e0e0e0',
1939
- borderRight: '1px solid #e0e0e0',
1940
- borderLeft: '1px solid #e0e0e0'
1941
- }
1938
+ // style={{
1939
+ // borderBottom: '1px solid #e0e0e0',
1940
+ // borderRight: '1px solid #e0e0e0',
1941
+ // borderLeft: '1px solid #e0e0e0'
1942
+ // }}
1942
1943
  }, /*#__PURE__*/_react.default.createElement(_rcMasterUi.Toolbar, {
1943
1944
  style: {
1944
1945
  width: '100%'
@@ -1948,9 +1949,7 @@ const TableContainerEdit = props => {
1948
1949
  onClick: ({}) => {
1949
1950
  setEditingKey('');
1950
1951
  }
1951
- })), pagination && !infiniteScroll && /*#__PURE__*/_react.default.createElement(_pagination.default
1952
- // style={{padding: '0.75rem 1rem'}}
1953
- , (0, _extends2.default)({}, pagination, {
1952
+ })), pagination && !infiniteScroll && /*#__PURE__*/_react.default.createElement(_pagination.default, (0, _extends2.default)({}, pagination, {
1954
1953
  rootClassName: 'pagination-template',
1955
1954
  showSizeChanger: true,
1956
1955
  responsive: true,
@@ -437,57 +437,65 @@ const TableBodyCell = props => {
437
437
  }
438
438
  }
439
439
  if (e.ctrlKey && e.code === 'Space' && cell.row.getCanSelect()) {
440
+ (0, _useColumns.toggleRowSelection)({
441
+ e,
442
+ cell,
443
+ setIsSelectionChange,
444
+ isSelectionChange,
445
+ selectionSettings
446
+ });
440
447
  cell.row.getToggleSelectedHandler()(e);
441
448
 
442
- // setIsSelectionChange({
443
- // isChange: true,
444
- // type: 'rowSelected',
445
- // rowData: record,
446
- // rowsData: []
447
- // })
449
+ // if (cell.row.getIsSelected()) { // nếu đã chọn
448
450
 
449
- if (cell.row.getIsSelected()) {
450
- // nếu đã chọn
451
+ // const aaa = isSelectionChange?.rowsData.filter((it) => it.id !== cell.row.id)
451
452
 
452
- const aaa = isSelectionChange?.rowsData.filter(it => it.id !== cell.row.id);
453
- setIsSelectionChange({
454
- isChange: true,
455
- type: 'rowSelected',
456
- rowData: cell.row.original,
457
- rowsData: aaa ?? []
458
- });
459
- } else {
460
- const {
461
- rowsData
462
- } = isSelectionChange ?? {};
463
- const abc = rowsData && rowsData.length > 0 ? [...rowsData] : [];
464
- abc.push(cell.row);
465
- setIsSelectionChange({
466
- isChange: true,
467
- type: 'rowSelected',
468
- rowData: cell.row.original,
469
- rowsData: abc
470
- });
471
- }
453
+ // setIsSelectionChange({
454
+ // isChange: true,
455
+ // type: 'rowSelected',
456
+ // rowData: cell.row.original,
457
+ // rowsData: aaa ?? []
458
+ // })
459
+
460
+ // } else {
461
+
462
+ // const { rowsData } = isSelectionChange ?? {}
463
+
464
+ // const abc = rowsData && rowsData.length > 0 ? [...rowsData] : []
465
+
466
+ // abc.push(cell.row)
467
+
468
+ // setIsSelectionChange({
469
+ // isChange: true,
470
+ // type: 'rowSelected',
471
+ // rowData: cell.row.original,
472
+ // rowsData: abc
473
+ // })
474
+ // }
472
475
  }
473
- }
476
+ },
477
+ onKeyUp: () => {}
474
478
 
475
479
  // onDoubleClick={() => { }}
476
480
  ,
477
481
 
478
482
  onClick: e => {
479
- if (!selectionSettings || selectionSettings.checkboxOnly !== true) {
480
- (0, _useColumns.toggleRowSelection)({
481
- e,
482
- cell,
483
- setIsSelectionChange,
484
- isSelectionChange,
485
- selectionSettings
486
- });
487
- setFocusedCell?.({
488
- colId: cell.column.id,
489
- rowId: cell.row.id
490
- });
483
+ const selection = window.getSelection();
484
+ const text = selection ? selection.toString() : "";
485
+ if (text.length > 0) {} else {
486
+ if (!selectionSettings || selectionSettings.checkboxOnly !== true) {
487
+ (0, _useColumns.toggleRowSelection)({
488
+ e,
489
+ cell,
490
+ setIsSelectionChange,
491
+ isSelectionChange,
492
+ selectionSettings
493
+ });
494
+ setFocusedCell?.({
495
+ colId: cell.column.id,
496
+ rowId: cell.row.id
497
+ });
498
+ }
491
499
  }
492
500
  }
493
501
  }, /*#__PURE__*/_react.default.createElement("div", {
@@ -248,12 +248,18 @@ const TableBodyCellEdit = props => {
248
248
  const expandIconColumnIndex = expandable?.expandIconColumnIndex;
249
249
  const record = cell.row.original;
250
250
  const columnMeta = cell.column.columnDef.meta ?? {};
251
- const cellContent = columnMeta.type === 'checkbox' ? '' : (0, _reactTable.flexRender)(cell.column.columnDef.cell, cell.getContext());
251
+ const [isOpenTooltip, setIsOpenTooltip] = _react.default.useState(false);
252
+
253
+ // const cellContent = columnMeta.type === 'checkbox' ? '' : flexRender(cell.column.columnDef.cell, cell.getContext());
252
254
  // const html = ReactDOMServer.renderToStaticMarkup(<>{cellContent}</>);
253
255
  // const hasValue = html.trim().length > 0;
254
256
 
255
257
  const rowError = dataErrors ? dataErrors.find(it => it.id === cell.row.id) : undefined;
256
258
  const message = rowError && rowError[cell.column.id]?.field === cell.column.id ? rowError[cell.column.id].message : undefined;
259
+ const tooltipContent = isOpenTooltip === false ? '' : columnMeta?.tooltipDescription ? typeof columnMeta.tooltipDescription === 'function' ? columnMeta.tooltipDescription({
260
+ value: cell.getValue(),
261
+ record
262
+ }) : columnMeta.tooltipDescription : columnMeta.template && typeof columnMeta.template !== 'function' ? columnMeta.template : cell.getValue();
257
263
  const canEdit = (0, _utils.isEditable)(cell.column.columnDef.meta, record) && isRowEditable !== false;
258
264
 
259
265
  // const allRows = table.getRowModel().rows;
@@ -435,7 +441,10 @@ const TableBodyCellEdit = props => {
435
441
  const rs = (0, _utils.unFlattenData)(rsFilterData);
436
442
  triggerPaste?.(pastedRows, colPasteds, rs, copyRows);
437
443
  };
438
- function handleMouseEnter(rowId, colId) {
444
+ function handleMouseEnter(e, rowId, colId) {
445
+ if (e.target.firstChild?.clientWidth < e.target.firstChild?.scrollWidth) {
446
+ setIsOpenTooltip(true);
447
+ }
439
448
  if (isSelecting) {
440
449
  setEndCell?.({
441
450
  rowId,
@@ -1050,12 +1059,8 @@ const TableBodyCellEdit = props => {
1050
1059
  "data-col-key": cell.column.id,
1051
1060
  "data-row-key": cell.row.id,
1052
1061
  "data-tooltip-id": `${id}-tooltip-content`,
1053
- "data-tooltip-delay-show": 500
1054
- // data-tooltip-html={!isEditing && !hasValue && !message ? undefined : ReactDOMServer.renderToStaticMarkup(<>{rowError && rowError[cell.column.id]?.field === cell.column.id ? rowError[cell.column.id].message : cellContent}</>)}
1055
- // data-tooltip-content={!isEditing && !message ? undefined : rowError && rowError[cell.column.id]?.field === cell.column.id ? rowError[cell.column.id].message : record[columnMeta.field ?? '']}
1056
- // data-tooltip-content={isEditing && message ? message : rowError && rowError[cell.column.id]?.field === cell.column.id ? rowError[cell.column.id].message : record[columnMeta.field ?? '']}
1057
- ,
1058
- "data-tooltip-html": isEditing && message ? message : rowError && rowError[cell.column.id]?.field === cell.column.id ? rowError[cell.column.id].message : _server.default.renderToStaticMarkup( /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, cellContent)),
1062
+ "data-tooltip-delay-show": 500,
1063
+ "data-tooltip-html": isEditing && message ? message : rowError && rowError[cell.column.id]?.field === cell.column.id ? rowError[cell.column.id].message : _server.default.renderToStaticMarkup( /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, tooltipContent)),
1059
1064
  className: (0, _classnames.default)(`${prefix}-grid-cell cell-editable editable `, {
1060
1065
  [`${prefix}-grid-cell-ellipsis`]: true,
1061
1066
  'cell-editing': isEditing,
@@ -1105,7 +1110,7 @@ const TableBodyCellEdit = props => {
1105
1110
  }
1106
1111
  }
1107
1112
  },
1108
- onMouseEnter: () => handleMouseEnter(cell.row.id, cell.column.id),
1113
+ onMouseEnter: e => handleMouseEnter(e, cell.row.id, cell.column.id),
1109
1114
  onMouseUp: e => handleMouseUp(e),
1110
1115
  onKeyDown: e => {
1111
1116
  if (!isEditing) {
@@ -73,8 +73,8 @@ const TableFooterCell = ({
73
73
  display: 'flex',
74
74
  ...(0, _utils.getCommonPinningStyles)(column),
75
75
  // width: column?.getSize() ?? column.getSize(),
76
- minWidth: column?.getSize(),
77
- backgroundColor: "#fafafa"
76
+ minWidth: column?.getSize()
77
+ // backgroundColor: "#fafafa",
78
78
  }
79
79
  }, column.id !== "id" && column.id !== "selection_column" ? /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, col.summaryTemplate ? col.summaryTemplate(numberValue, col.field) : (0, _reactNumericComponent.numericFormatter)(cellValue, numericFormatProps)) : '');
80
80
  };
@@ -37,11 +37,12 @@ const TableFooterRow = ({
37
37
  style: {
38
38
  display: "grid",
39
39
  width: "100%",
40
- borderBottom: "1px solid #e0e0e0",
41
- borderTop: "1px solid #e0e0e0",
40
+ // borderBottom: "1px solid #e0e0e0",
41
+ // borderTop: "1px solid #e0e0e0",
42
42
  height: 37,
43
43
  gridTemplateColumns: `${table.getVisibleLeafColumns().map(n => `${n.getSize()}fr`).join(" ")}`
44
- }
44
+ },
45
+ className: "ui-rc-grid-footer-row"
45
46
  }, visibleColumns.map(header => {
46
47
  return /*#__PURE__*/_react.default.createElement(_TableFooterCell.default, {
47
48
  key: header.id
@@ -281,7 +281,12 @@ const toggleRowSelection = props => {
281
281
  } else {
282
282
  // chỉ thêm vào row hiện tại
283
283
 
284
- checkedRows = [...prevSelected, row];
284
+ const isInclude = prevSelected.find(it => it.id === cell.row.id);
285
+ if (isInclude) {
286
+ checkedRows = [...prevSelected];
287
+ } else {
288
+ checkedRows = [...prevSelected, row];
289
+ }
285
290
  }
286
291
  setIsSelectionChange({
287
292
  isChange: true,