es-grid-template 1.9.73 → 1.9.75

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.
@@ -9,12 +9,13 @@ import { booleanOperator, findItemPath, isEditable, isObjEmpty, nonActionColumn,
9
9
  import classNames from 'classnames';
10
10
  import { Dropdown, Select, Space, Button } from 'rc-master-ui';
11
11
  import { addRowsDown, addRowsDownWithCtrl, addRowsUp, addRowsUpWithCtrl, convertFilters, extendsObject,
12
+ // findFirst,
12
13
  // flattenArray,
13
14
  flattenData, getColIdsBetween1, getDefaultOperator, getDragRightData, getEditType, getKeys, getNextColumn, getNextColumn1, getPrevColumn, getRowIdsBetween3,
14
15
  // getRowIndexMap,
15
16
  getSelectedCellMatrix1, getTypeFilter,
16
17
  // isObjEqual,
17
- newGuid } from "../../../table-component/hook/utils";
18
+ newGuid, unFlattenData, updateOrInsert } from "../../../table-component/hook/utils";
18
19
  import { renderFilter } from "../../base-table/renderFilter";
19
20
  import { renderValueCell } from "../../../table-component/hook/useColumns";
20
21
  import EditCell from "../../base-table/cell/EditCell";
@@ -23,7 +24,7 @@ import { stateKeyResize, stateKeyColumnFilter, stateKeyFilter, stateKeyPaginatio
23
24
  // state For edit
24
25
  stateKeyEndCell, stateKeyEndPasteCell, stateKeyStartCell, stateKeyStartPasteCell, stateKeyFocusedCell, stateKeyEditCellSettings, stateKeyIsEditing, stateKeyIsPasting, stateKeyIsSelecting } from "../../utils/constants";
25
26
  import { getColumnsAtLevel } from "../../base-table/utils";
26
- import { unFlattenData, updateOrInsert } from "../../utils/utility";
27
+ // import { unFlattenData } from '../../utils/utility';
27
28
  // import { getMaxDepth } from '../../utils/utility';
28
29
 
29
30
  function clamp(min, x, max) {
@@ -50,6 +51,7 @@ export function columnCustom(opts) {
50
51
  wrapSettings,
51
52
  // ignoreAccents,
52
53
  dataSource,
54
+ dataFlatten,
53
55
  isDataTree,
54
56
  defaultSorter,
55
57
  defaultFilter,
@@ -440,7 +442,7 @@ export function columnCustom(opts) {
440
442
  }
441
443
 
442
444
  // Cập nhật data mới
443
- const newData = allRows;
445
+ const newData = dataFlatten;
444
446
  const pastedRows = [];
445
447
  if (pasteState.type === 'down' || pasteState.type === 'up') {
446
448
  newRange.addedRows.forEach((rowValues, rowIndex1) => {
@@ -508,7 +510,7 @@ export function columnCustom(opts) {
508
510
  }
509
511
 
510
512
  // const rsFilterData = updateOrInsert(dataSource, newData)
511
- const rsFilterData = updateOrInsert(allRows, newData);
513
+ const rsFilterData = updateOrInsert(dataFlatten, newData);
512
514
  const rs = unFlattenData(rsFilterData);
513
515
  triggerPaste?.(pastedRows, colPasteds, rs, copyRows);
514
516
  pipeline.setStateAtKey(stateKeyEndCell, endPasteCell);
@@ -535,7 +537,7 @@ export function columnCustom(opts) {
535
537
  const newRange = ctrlKey ? addRowsDownWithCtrl(dataSelected, rowsPasteId.length) : addRowsDown(dataSelected, rowsPasteId.length);
536
538
 
537
539
  // Cập nhật data mới
538
- const newData = allRows;
540
+ const newData = dataFlatten;
539
541
  const pastedRows = [];
540
542
  newRange.addedRows.forEach((rowValues, rowIndex1) => {
541
543
  const targetRow = pasteState?.startRowIndex + rowIndex1;
@@ -557,7 +559,7 @@ export function columnCustom(opts) {
557
559
  });
558
560
 
559
561
  // const rsFilterData = updateOrInsert(dataSource, newData)
560
- const rsFilterData = updateOrInsert(dataSource, newData);
562
+ const rsFilterData = updateOrInsert(dataFlatten, newData);
561
563
  const rs = unFlattenData(rsFilterData);
562
564
  triggerPaste?.(pastedRows, colsPastedId, rs, copyRows);
563
565
  };
@@ -1061,6 +1063,73 @@ export function columnCustom(opts) {
1061
1063
  pipeline.setStateAtKey(stateKeyEndCell, cellEnd);
1062
1064
  triggerPointPaste(selectPasteState, cellStart, cellEnd, e.ctrlKey);
1063
1065
  };
1066
+
1067
+ // cell Số thứ tự
1068
+
1069
+ const handleMouseDownIndex = rowId => {
1070
+ // setIsSelecting?.(true);
1071
+ pipeline.setStateAtKey(stateKeyIsSelecting, true);
1072
+ const allColumns = allCols.filter(it => !nonActionColumn.includes(it.field));
1073
+
1074
+ // const firstCOlSpin = findFirst(allColumns)
1075
+
1076
+ const startCol = allColumns[0].field;
1077
+ const endCol = allColumns[allColumns.length - 1].field;
1078
+
1079
+ // setStartCell?.({ rowId, colId: startCol });
1080
+ // setEndCell?.({ rowId, colId: endCol });
1081
+
1082
+ pipeline.setStateAtKey(stateKeyStartCell, {
1083
+ rowId,
1084
+ colId: startCol
1085
+ });
1086
+ pipeline.setStateAtKey(stateKeyEndCell, {
1087
+ rowId,
1088
+ colId: endCol
1089
+ });
1090
+
1091
+ // if (firstCOlSpin) {
1092
+ // setFocusedCell?.({ rowId: cell.row.id, colId: firstCOlSpin.id })
1093
+ // } else {
1094
+ // const firstCOlVisible = allColumns[0]
1095
+ // setFocusedCell?.({ rowId: cell.row.id, colId: firstCOlVisible.id })
1096
+ // }
1097
+ pipeline.setStateAtKey(stateKeyFocusedCell, {
1098
+ rowId,
1099
+ colId: startCol
1100
+ });
1101
+
1102
+ // setRangeState?.(getSelectedCellMatrix(table, { rowId, colId: startCol }, { rowId, colId: endCol }))
1103
+ };
1104
+ const handleMouseEnterIndex = rowId => {
1105
+ if (isSelecting) {
1106
+ const allColumns = allCols.filter(it => !nonActionColumn.includes(it.field));
1107
+
1108
+ // const firstCOl = findFirst(allColumns)
1109
+
1110
+ // const startCol = allColumns[0].id
1111
+ const endCol = allColumns[allColumns.length - 1].field;
1112
+
1113
+ // // setStartCell?.({ rowId, colId: startCol });
1114
+ // setEndCell?.({ rowId, colId: endCol });
1115
+ pipeline.setStateAtKey(stateKeyEndCell, {
1116
+ rowId,
1117
+ colId: endCol
1118
+ });
1119
+ }
1120
+ };
1121
+ const handleMouseUpIndex = () => {
1122
+ // setIsSelecting?.(false);
1123
+
1124
+ pipeline.setStateAtKey(stateKeyIsSelecting, false);
1125
+
1126
+ // const selectState = getSelectedCellMatrix(table, startCell, endCell)
1127
+
1128
+ // if (!isObjEqual(rangeState, selectState)) {
1129
+
1130
+ // setRangeState?.(selectState)
1131
+ // }
1132
+ };
1064
1133
  pipeline.mapColumns(makeRecursiveMapper((col, params) => {
1065
1134
  const {
1066
1135
  startIndex,
@@ -1213,6 +1282,7 @@ export function columnCustom(opts) {
1213
1282
  // cell Index
1214
1283
  if (col.field === '#') {
1215
1284
  const prevContent = col.template;
1285
+ const prevGetCellProps = col?.getCellProps;
1216
1286
  return {
1217
1287
  ...col,
1218
1288
  lock: !!col.fixed,
@@ -1247,7 +1317,73 @@ export function columnCustom(opts) {
1247
1317
  overflow: 'visible',
1248
1318
  position: 'relative'
1249
1319
  }
1250
- })
1320
+ }),
1321
+ getCellProps(value, record, rowIndex) {
1322
+ const prevCellProps = prevGetCellProps?.(value, record, rowIndex);
1323
+
1324
+ // const isCellSelected = (!startCell || !endCell) ? false : selectRowIds.includes(record.rowId) && cols.includes(col.field);
1325
+
1326
+ return mergeCellProps(prevCellProps, {
1327
+ // @ts-ignore
1328
+ 'data-col-key': col.field,
1329
+ ref: el => {
1330
+ if (focusedCell?.rowId === record.rowId && focusedCell?.colId === col.field && !isEditing.editing) {
1331
+ el?.focus({
1332
+ preventScroll: true
1333
+ });
1334
+ }
1335
+ },
1336
+ style: {
1337
+ ...prevCellProps?.style,
1338
+ userSelect: 'none'
1339
+ // padding: cellEditing ? 0 : undefined
1340
+ // ...cellStyles,
1341
+ },
1342
+ className: classNames(prevCellProps?.className, `${prefix}-grid-cell`, {
1343
+ [`${prefix}-grid-cell-ellipsis`]: !wrapSettings || !(wrapSettings && (wrapSettings.wrapMode === 'Both' || wrapSettings.wrapMode === 'Content')),
1344
+ [`${prefix}-grid-cell-wrap`]: wrapSettings && (wrapSettings.wrapMode === 'Both' || wrapSettings.wrapMode === 'Content'),
1345
+ [`${prefix}-grid-cell-text-center`]: col?.textAlign === 'center',
1346
+ [`${prefix}-grid-cell-text-right`]: col?.textAlign === 'right' || col.type === 'number',
1347
+ [`${prefix}-grid-cell-index-selected`]: selectRowIds?.includes(record.rowId),
1348
+ 'no-hover': editAble
1349
+
1350
+ // isValid: !isEditing && rowError && rowError[col.field]?.field === col.field,
1351
+ // [`${prefix}-grid-cell-selected`]: isCellSelected,
1352
+ }),
1353
+ onMouseDown: e => {
1354
+ prevCellProps?.onMouseDown?.(e);
1355
+ if (editAble) {
1356
+ // if (record[rowKey] === editingKey) {
1357
+ if (isEditing.editing) {
1358
+ // setFocusedCell?.({ rowId: cell.row.id, colId: cell.column.id })
1359
+ } else {
1360
+ handleMouseDownIndex(record.rowId);
1361
+ if (isEditing.editing) {
1362
+ setTimeout(() => {
1363
+ // setEditingKey?.('')
1364
+ pipeline.setStateAtKey(stateKeyIsEditing, defaultCellEditing);
1365
+ reset?.();
1366
+ });
1367
+ }
1368
+ }
1369
+ }
1370
+ },
1371
+ onMouseEnter: e => {
1372
+ prevCellProps?.onMouseEnter?.(e);
1373
+ // Edit
1374
+
1375
+ if (editAble) {
1376
+ handleMouseEnterIndex(record.rowId);
1377
+ }
1378
+ },
1379
+ onMouseUp: e => {
1380
+ prevCellProps?.onMouseUp?.(e);
1381
+ if (editAble) {
1382
+ handleMouseUpIndex();
1383
+ }
1384
+ }
1385
+ });
1386
+ }
1251
1387
  };
1252
1388
  }
1253
1389
 
@@ -1514,9 +1650,6 @@ export function columnCustom(opts) {
1514
1650
  }),
1515
1651
  getCellProps(value, record, rowIndex) {
1516
1652
  const prevCellProps = prevGetCellProps?.(value, record, rowIndex);
1517
-
1518
- // console.log('record', record)
1519
-
1520
1653
  const fomatedValue = ['color', 'checkbox', 'field'].includes(col.type ?? '') ? '' : renderValueCell(col, value, record, rowIndex, 0, format, false);
1521
1654
  const tooltipContent = isOpenTooltip === false ? '' : col?.tooltipDescription ? typeof col.tooltipDescription === 'function' ? col.tooltipDescription({
1522
1655
  value,
@@ -25,4 +25,15 @@ export declare function filterVisibleColumns<T extends ColumnTable>(columns: T[]
25
25
  export declare const sortByType: (arr: ColumnTable[], rowDnd?: RowDnd) => ColumnTable[];
26
26
  export declare function getVisibleColumnFields<T extends ColumnTable>(columns: T[]): string[];
27
27
  export declare const getOnlyInA: (a: string[], b: string[]) => string[];
28
+ export declare const buildParentMap: <T extends {
29
+ id: string;
30
+ rowId: string;
31
+ children?: T[];
32
+ }>(tree: T[]) => Map<string, T>;
33
+ export declare const flattenTree: <T extends {
34
+ children?: T[];
35
+ }>(tree: T[]) => T[];
36
+ export declare const flattenTree2: <T extends {
37
+ children?: T[];
38
+ }>(tree: T[]) => Omit<T, 'children'>[];
28
39
  export {};
@@ -699,4 +699,53 @@ export function getVisibleColumnFields(columns) {
699
699
  export const getOnlyInA = (a, b) => {
700
700
  const setB = new Set(b);
701
701
  return a.filter(item => !setB.has(item));
702
+ };
703
+ export const buildParentMap = tree => {
704
+ const parentMap = new Map();
705
+ const stack = [...tree];
706
+ while (stack.length) {
707
+ const node = stack.pop();
708
+ const children = node.children;
709
+ if (!children?.length) continue;
710
+ for (let i = 0; i < children.length; i++) {
711
+ const child = children[i];
712
+ parentMap.set(child.rowId, node);
713
+ stack.push(child);
714
+ }
715
+ }
716
+ return parentMap;
717
+ };
718
+ export const flattenTree = tree => {
719
+ const result = [];
720
+ const stack = [...tree];
721
+ while (stack.length) {
722
+ const node = stack.pop();
723
+ result.push(node);
724
+ const children = node.children;
725
+ if (children?.length) {
726
+ // Push ngược để giữ nguyên thứ tự tree
727
+ for (let i = children.length - 1; i >= 0; i--) {
728
+ stack.push(children[i]);
729
+ }
730
+ }
731
+ }
732
+ return result;
733
+ };
734
+ export const flattenTree2 = tree => {
735
+ const result = [];
736
+ const stack = [...tree];
737
+ while (stack.length) {
738
+ const node = stack.pop();
739
+ const {
740
+ children,
741
+ ...item
742
+ } = node;
743
+ result.push(item);
744
+ if (children?.length) {
745
+ for (let i = children.length - 1; i >= 0; i--) {
746
+ stack.push(children[i]);
747
+ }
748
+ }
749
+ }
750
+ return result;
702
751
  };
@@ -196,10 +196,10 @@ export declare const fixColumnsLeft: <RecordType>(columns: ColumnTable<RecordTyp
196
196
  value: any;
197
197
  rowData: RecordType;
198
198
  }) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>> | import("react").ReactNode);
199
- onCellStyles?: Omit<CSSProperties, "left" | "right" | "display" | "width" | "minWidth" | "position"> | ((cellValue: any, cell: import("@tanstack/react-table").Cell<RecordType, unknown>) => Omit<CSSProperties, "left" | "right" | "display" | "width" | "minWidth" | "position">);
200
- onCellHeaderStyles?: Omit<CSSProperties, "left" | "right" | "display" | "width" | "minWidth" | "position"> | ((cell: import("@tanstack/react-table").Header<RecordType, unknown>) => Omit<CSSProperties, "left" | "right" | "display" | "width" | "minWidth" | "position">);
199
+ onCellStyles?: Omit<CSSProperties, "width" | "minWidth" | "left" | "right" | "position" | "display"> | ((cellValue: any, cell: import("@tanstack/react-table").Cell<RecordType, unknown>) => Omit<CSSProperties, "width" | "minWidth" | "left" | "right" | "position" | "display">);
200
+ onCellHeaderStyles?: Omit<CSSProperties, "width" | "minWidth" | "left" | "right" | "position" | "display"> | ((cell: import("@tanstack/react-table").Header<RecordType, unknown>) => Omit<CSSProperties, "width" | "minWidth" | "left" | "right" | "position" | "display">);
201
201
  onCell?: (rowData: RecordType, index: number) => import("react").TdHTMLAttributes<HTMLTableCellElement>;
202
- onCellFooterStyles?: Omit<CSSProperties, "left" | "right" | "display" | "width" | "minWidth" | "position"> | ((cellValue: any, cell: import("@tanstack/react-table").Header<RecordType, unknown>) => Omit<CSSProperties, "left" | "right" | "display" | "width" | "minWidth" | "position">);
202
+ onCellFooterStyles?: Omit<CSSProperties, "width" | "minWidth" | "left" | "right" | "position" | "display"> | ((cellValue: any, cell: import("@tanstack/react-table").Header<RecordType, unknown>) => Omit<CSSProperties, "width" | "minWidth" | "left" | "right" | "position" | "display">);
203
203
  getValue?: (row: any, rowIndex: number) => any;
204
204
  getCellProps?: (value: any, row: any, rowIndex: number) => import("./../../grid-component/type").CellProps;
205
205
  headerCellProps?: import("./../../grid-component/type").CellProps;
@@ -170,12 +170,17 @@ const Grid = props => {
170
170
  // debugTable: true
171
171
  });
172
172
  React.useEffect(() => {
173
+ setIsSelectionChange(prev => ({
174
+ ...prev,
175
+ isChange: false
176
+ }));
173
177
  if (!isSelectionChange.isChange) {
174
178
  if (mergedSelectedKeys.length === 0) {
175
179
  setIsSelectionChange(prev => ({
176
180
  ...prev,
177
181
  rowsData: []
178
182
  }));
183
+ setRowSelection(convertToObjTrue(mergedSelectedKeys));
179
184
  } else {
180
185
  const abc = flattenArray(dataSource);
181
186
  const selectedKeySet = new Set(mergedSelectedKeys);
@@ -186,8 +191,14 @@ const Grid = props => {
186
191
  rowsData: result
187
192
  }));
188
193
  }
194
+ } else {
195
+ if (mergedSelectedKeys.length === 0) {
196
+ setRowSelection(convertToObjTrue(mergedSelectedKeys));
197
+ }
189
198
  }
190
- }, [mergedSelectedKeys, dataSource]);
199
+ }, [mergedSelectedKeys, dataSource, isSelectionChange.isChange]);
200
+ // }, [mergedSelectedKeys, dataSource])
201
+
191
202
  React.useEffect(() => {
192
203
  if (defaultFilter) {
193
204
  const a = revertConvertFilters(defaultFilter);
@@ -179,7 +179,6 @@ const Grid = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
179
179
 
180
180
  // setColumns(cols)
181
181
  } else {
182
- console.log('setColumns');
183
182
  setColumns(cols);
184
183
  // pipeline.columns(cols)
185
184