es-grid-template 1.9.73 → 1.9.74
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.
- package/es/ali-table/Grid.js +0 -1
- package/es/ali-table/InternalTable.js +169 -29
- package/es/ali-table/base-table/html-table.js +1 -1
- package/es/ali-table/base-table/styles.d.ts +1 -0
- package/es/ali-table/base-table/styles.js +2 -1
- package/es/ali-table/pipeline/features/columnCustom.d.ts +1 -0
- package/es/ali-table/pipeline/features/columnCustom.js +143 -10
- package/es/ali-table/utils/utility.d.ts +11 -0
- package/es/ali-table/utils/utility.js +49 -0
- package/es/group-component/hook/utils.d.ts +3 -3
- package/lib/ali-table/Grid.js +0 -1
- package/lib/ali-table/InternalTable.js +167 -27
- package/lib/ali-table/base-table/html-table.js +1 -1
- package/lib/ali-table/base-table/styles.d.ts +1 -0
- package/lib/ali-table/base-table/styles.js +2 -1
- package/lib/ali-table/pipeline/features/columnCustom.d.ts +1 -0
- package/lib/ali-table/pipeline/features/columnCustom.js +144 -12
- package/lib/ali-table/utils/utility.d.ts +11 -0
- package/lib/ali-table/utils/utility.js +55 -3
- package/package.json +2 -2
|
@@ -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
|
|
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 =
|
|
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(
|
|
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 =
|
|
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(
|
|
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" | "
|
|
200
|
-
onCellHeaderStyles?: Omit<CSSProperties, "left" | "right" | "
|
|
199
|
+
onCellStyles?: Omit<CSSProperties, "left" | "right" | "position" | "display" | "minWidth" | "width"> | ((cellValue: any, cell: import("@tanstack/react-table").Cell<RecordType, unknown>) => Omit<CSSProperties, "left" | "right" | "position" | "display" | "minWidth" | "width">);
|
|
200
|
+
onCellHeaderStyles?: Omit<CSSProperties, "left" | "right" | "position" | "display" | "minWidth" | "width"> | ((cell: import("@tanstack/react-table").Header<RecordType, unknown>) => Omit<CSSProperties, "left" | "right" | "position" | "display" | "minWidth" | "width">);
|
|
201
201
|
onCell?: (rowData: RecordType, index: number) => import("react").TdHTMLAttributes<HTMLTableCellElement>;
|
|
202
|
-
onCellFooterStyles?: Omit<CSSProperties, "left" | "right" | "
|
|
202
|
+
onCellFooterStyles?: Omit<CSSProperties, "left" | "right" | "position" | "display" | "minWidth" | "width"> | ((cellValue: any, cell: import("@tanstack/react-table").Header<RecordType, unknown>) => Omit<CSSProperties, "left" | "right" | "position" | "display" | "minWidth" | "width">);
|
|
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;
|
package/lib/ali-table/Grid.js
CHANGED
|
@@ -85,6 +85,7 @@ const InternalTable = props => {
|
|
|
85
85
|
headerData,
|
|
86
86
|
format,
|
|
87
87
|
onCellClick,
|
|
88
|
+
commandClick,
|
|
88
89
|
...rest
|
|
89
90
|
} = props;
|
|
90
91
|
const tableRef = (0, _react.useRef)(null);
|
|
@@ -149,6 +150,9 @@ const InternalTable = props => {
|
|
|
149
150
|
}
|
|
150
151
|
return (0, _utils.addRowIdArray)(dataSource);
|
|
151
152
|
}, [dataSource, groupAble, groupColumns, groupSetting]);
|
|
153
|
+
const dataFlatten = _react.default.useMemo(() => {
|
|
154
|
+
return (0, _utils.flattenArray)(convertData);
|
|
155
|
+
}, [convertData]);
|
|
152
156
|
const isDataTree = _react.default.useMemo(() => {
|
|
153
157
|
return (0, _utils.isTreeArray)(convertData);
|
|
154
158
|
}, [convertData]);
|
|
@@ -161,8 +165,8 @@ const InternalTable = props => {
|
|
|
161
165
|
return rss;
|
|
162
166
|
}, [convertData, filterState, ignoreAccents, sortState, onFilter, onSorter, defaultFilter, defaultSorter]);
|
|
163
167
|
const rowIndexMap = _react.default.useMemo(() => {
|
|
164
|
-
return (0, _utils.getRowIndexMap)(
|
|
165
|
-
}, [
|
|
168
|
+
return (0, _utils.getRowIndexMap)(dataFlatten);
|
|
169
|
+
}, [dataFlatten]);
|
|
166
170
|
const footerData = _react.default.useMemo(() => {
|
|
167
171
|
if (!summary) {
|
|
168
172
|
return undefined;
|
|
@@ -236,7 +240,8 @@ const InternalTable = props => {
|
|
|
236
240
|
}, [onDataChange]);
|
|
237
241
|
const triggerPaste = _react.default.useCallback((pastedRows, pastedColumnsArray, newData, copyRows) => {
|
|
238
242
|
const handlePasteCallback = callbackData => {
|
|
239
|
-
const rsFilterData =
|
|
243
|
+
// const rsFilterData = updateOrInsert(convertData as any, flattenArray(callbackData))
|
|
244
|
+
const rsFilterData = (0, _utils.updateOrInsert)((0, _utils.flattenArray)([...convertData]), (0, _utils.flattenArray)([...callbackData]));
|
|
240
245
|
const rs = (0, _utils.unFlattenData)(rsFilterData);
|
|
241
246
|
triggerChangeData(rs, {
|
|
242
247
|
type: 'OnPaste'
|
|
@@ -557,6 +562,7 @@ const InternalTable = props => {
|
|
|
557
562
|
groupColumns,
|
|
558
563
|
mode: sortMultiple !== false ? 'multiple' : 'single',
|
|
559
564
|
dataSource: convertData,
|
|
565
|
+
dataFlatten: dataFlatten,
|
|
560
566
|
rowIndexMap,
|
|
561
567
|
columnResizeMode: 'onChange',
|
|
562
568
|
disableUserSelectWhenResizing: true,
|
|
@@ -623,7 +629,9 @@ const InternalTable = props => {
|
|
|
623
629
|
// }
|
|
624
630
|
|
|
625
631
|
// reorder rows after drag & drop
|
|
626
|
-
|
|
632
|
+
const parentMap = _react.default.useMemo(() => {
|
|
633
|
+
return (0, _utility.buildParentMap)(convertData);
|
|
634
|
+
}, [convertData]);
|
|
627
635
|
const isEditing = _react.default.useMemo(() => {
|
|
628
636
|
return pipeline.getStateAtKey(_constants.stateKeyIsEditing);
|
|
629
637
|
}, [pipeline]);
|
|
@@ -726,9 +734,9 @@ const InternalTable = props => {
|
|
|
726
734
|
};
|
|
727
735
|
}, [tableId, pipeline, editAble, headerEditAble, endCell, startCell]);
|
|
728
736
|
const rowsFocus = _react.default.useMemo(() => {
|
|
729
|
-
const selectRowIds = startCell && endCell ? (0, _utils.getRowIdsBetween3)(
|
|
737
|
+
const selectRowIds = startCell && endCell ? (0, _utils.getRowIdsBetween3)(dataFlatten, rowIndexMap, startCell.rowId, endCell.rowId) : [];
|
|
730
738
|
return selectRowIds;
|
|
731
|
-
}, [
|
|
739
|
+
}, [dataFlatten, endCell, rowIndexMap, startCell]);
|
|
732
740
|
function handleDragEnd(event) {
|
|
733
741
|
const {
|
|
734
742
|
active,
|
|
@@ -827,7 +835,7 @@ const InternalTable = props => {
|
|
|
827
835
|
// không tính tree
|
|
828
836
|
|
|
829
837
|
// Cập nhật data mới
|
|
830
|
-
const newData =
|
|
838
|
+
const newData = dataFlatten;
|
|
831
839
|
const focusedCell = pipeline.getStateAtKey(_constants.stateKeyFocusedCell);
|
|
832
840
|
const duplicatedItem = newData.find(it => it.rowId === focusedCell?.rowId);
|
|
833
841
|
const duplicatedItems = [{
|
|
@@ -842,11 +850,11 @@ const InternalTable = props => {
|
|
|
842
850
|
// const insertAfter = Math.max(...rowsFocus)
|
|
843
851
|
const insertAfter = newData.findIndex(it => it[rowKey] === focusedCell?.rowId);
|
|
844
852
|
const rsFilter = [...newData.slice(0, insertAfter + 1), ...duplicatedItems, ...newData.slice(insertAfter + 1)];
|
|
845
|
-
const rs = (0,
|
|
853
|
+
const rs = (0, _utils.updateOrInsert)(dataFlatten, rsFilter);
|
|
846
854
|
triggerChangeData?.(rs, {
|
|
847
855
|
type: 'DUPLICATE'
|
|
848
856
|
});
|
|
849
|
-
}, [
|
|
857
|
+
}, [dataFlatten, pipeline, triggerChangeData]);
|
|
850
858
|
|
|
851
859
|
// thêm n dòng bên trên
|
|
852
860
|
const handleInsertBefore = _react.default.useCallback((item, n) => {
|
|
@@ -1070,8 +1078,8 @@ const InternalTable = props => {
|
|
|
1070
1078
|
if (!startCell || !endCell) {
|
|
1071
1079
|
return;
|
|
1072
1080
|
}
|
|
1073
|
-
const allRows =
|
|
1074
|
-
const rowIds = (0, _utils.getRowIdsBetween3)(
|
|
1081
|
+
const allRows = pipeline.getDataSource();
|
|
1082
|
+
const rowIds = (0, _utils.getRowIdsBetween3)(dataFlatten, rowIndexMap, startCell?.rowId ?? '', endCell?.rowId ?? '');
|
|
1075
1083
|
const colIds = (0, _utils.getColIdsBetween1)(leafColumns, startCell?.colId ?? '', endCell?.colId ?? '');
|
|
1076
1084
|
const dataToCopy = [];
|
|
1077
1085
|
rowIds.forEach(rowId => {
|
|
@@ -1088,14 +1096,14 @@ const InternalTable = props => {
|
|
|
1088
1096
|
// Convert to TSV string
|
|
1089
1097
|
const tsv = dataToCopy.map(row => row.join('\t')).join('\n');
|
|
1090
1098
|
copy(tsv).then(() => {}).catch(() => {});
|
|
1091
|
-
}, [startCell, endCell,
|
|
1099
|
+
}, [startCell, endCell, pipeline, dataFlatten, rowIndexMap, leafColumns, copy]);
|
|
1092
1100
|
_react.default.useEffect(() => {
|
|
1093
1101
|
const handleKeyDown = e => {
|
|
1094
|
-
if (e.ctrlKey && e.key === 'c' && startCell && endCell && !isEditing) {
|
|
1095
|
-
e.preventDefault();
|
|
1102
|
+
if (e.ctrlKey && e.key === 'c' && startCell && endCell && !isEditing.editing) {
|
|
1103
|
+
// e.preventDefault();
|
|
1096
1104
|
copySelectionToClipboard();
|
|
1097
1105
|
}
|
|
1098
|
-
if (e.ctrlKey && e.key === 'x' && startCell && endCell && !isEditing) {
|
|
1106
|
+
if (e.ctrlKey && e.key === 'x' && startCell && endCell && !isEditing.editing) {
|
|
1099
1107
|
e.preventDefault();
|
|
1100
1108
|
if (startCell && endCell) {
|
|
1101
1109
|
const tmpData = (0, _utils.flattenArray)(convertData);
|
|
@@ -1147,7 +1155,8 @@ const InternalTable = props => {
|
|
|
1147
1155
|
};
|
|
1148
1156
|
document.addEventListener('keydown', handleKeyDown);
|
|
1149
1157
|
return () => document.removeEventListener('keydown', handleKeyDown);
|
|
1150
|
-
}, [startCell, endCell, copySelectionToClipboard, isEditing, convertData, triggerChangeData, leafColumns, rangeState?.rowRange, rangeState?.colRange]);
|
|
1158
|
+
}, [startCell, endCell, copySelectionToClipboard, isEditing, convertData, triggerChangeData, leafColumns, rangeState?.rowRange, rangeState?.colRange, handleCellChange]);
|
|
1159
|
+
|
|
1151
1160
|
// }, [startCell, endCell, copySelectionToClipboard, isEditing, convertData, triggerChangeData, leafColumns, handleCellChange, rangeState?.rowRange, rangeState?.colRange]);
|
|
1152
1161
|
|
|
1153
1162
|
// Copy
|
|
@@ -1159,7 +1168,9 @@ const InternalTable = props => {
|
|
|
1159
1168
|
return;
|
|
1160
1169
|
}
|
|
1161
1170
|
const rows = pasteData.slice(0, onCellPaste?.maxRowsPaste ?? 200);
|
|
1162
|
-
|
|
1171
|
+
|
|
1172
|
+
// const allRows = convertData
|
|
1173
|
+
const allRows = dataFlatten;
|
|
1163
1174
|
const allCols = (0, _utils2.collectNodes)(pipeline.getColumns(), 'leaf-only');
|
|
1164
1175
|
const startRowIdx = rowIndexMap.get(startCell.rowId);
|
|
1165
1176
|
const startColIdx = allCols.findIndex(c => c.field === startCell.colId);
|
|
@@ -1171,7 +1182,7 @@ const InternalTable = props => {
|
|
|
1171
1182
|
const row = recordIndex ? allRows[recordIndex] : {};
|
|
1172
1183
|
if (!row.parentId) {
|
|
1173
1184
|
// Cập nhật data mới
|
|
1174
|
-
const newData =
|
|
1185
|
+
const newData = dataFlatten;
|
|
1175
1186
|
|
|
1176
1187
|
// Lấy vị trí bắt đầu
|
|
1177
1188
|
|
|
@@ -1256,12 +1267,14 @@ const InternalTable = props => {
|
|
|
1256
1267
|
pastedRows.push(newData[targetRow]);
|
|
1257
1268
|
});
|
|
1258
1269
|
const pastedColumnsArray = Array.from(pastedColumns) ?? [];
|
|
1259
|
-
const rsFilterData = (0,
|
|
1270
|
+
const rsFilterData = (0, _utils.updateOrInsert)(dataFlatten, newData);
|
|
1260
1271
|
const rs = (0, _utils.unFlattenData)(rsFilterData);
|
|
1261
1272
|
triggerPaste?.(pastedRows, pastedColumnsArray, rs, []);
|
|
1262
1273
|
} else {
|
|
1263
1274
|
// const parent = findItemByKey(convertData, rowKey as any, record.parentId)
|
|
1264
|
-
const parent = row.getParentRow()?.original
|
|
1275
|
+
// const parent: any = row.getParentRow()?.original
|
|
1276
|
+
|
|
1277
|
+
const parent = parentMap.get(row.rowId);
|
|
1265
1278
|
|
|
1266
1279
|
// Cập nhật childData mới
|
|
1267
1280
|
const childData = parent?.children ? [...parent.children] : [];
|
|
@@ -1289,11 +1302,14 @@ const InternalTable = props => {
|
|
|
1289
1302
|
// Không vượt quá số cột
|
|
1290
1303
|
return;
|
|
1291
1304
|
}
|
|
1292
|
-
|
|
1293
|
-
const
|
|
1305
|
+
|
|
1306
|
+
// const columnTarget = allCols[targetCol]
|
|
1307
|
+
|
|
1308
|
+
// const columnOri: any = columnTarget.columnDef.meta ?? {}
|
|
1309
|
+
const columnOri = allCols[targetCol];
|
|
1294
1310
|
const isEdit = typeof columnOri?.editEnable === 'function' ? columnOri.editEnable(childData[targetRow]) : columnOri.editEnable;
|
|
1295
1311
|
if (isEdit) {
|
|
1296
|
-
const columnKey = allCols[targetCol].
|
|
1312
|
+
const columnKey = allCols[targetCol].field;
|
|
1297
1313
|
if (columnOri.type === 'number') {
|
|
1298
1314
|
if (cellValue.trim() === '') {
|
|
1299
1315
|
childData[targetRow] = {
|
|
@@ -1352,7 +1368,7 @@ const InternalTable = props => {
|
|
|
1352
1368
|
const newDataSource = (0, _utils.updateArrayByKey)(convertData, newRowData, rowKey);
|
|
1353
1369
|
triggerPaste?.(pastedRows, pastedColumnsArray, newDataSource, []);
|
|
1354
1370
|
}
|
|
1355
|
-
}, [
|
|
1371
|
+
}, [startCell, onCellPaste?.maxRowsPaste, dataFlatten, pipeline, rowIndexMap, triggerPaste, defaultValue, format, parentMap, convertData]);
|
|
1356
1372
|
const handlePasteToTable = _react.default.useCallback((pasteData, e) => {
|
|
1357
1373
|
if (!startCell) return;
|
|
1358
1374
|
const rowsPasted = (0, _utils.parseExcelClipboard)(e);
|
|
@@ -1383,7 +1399,7 @@ const InternalTable = props => {
|
|
|
1383
1399
|
}, [handlePasted, onCellPaste?.maxRowsPaste, startCell]);
|
|
1384
1400
|
_react.default.useEffect(() => {
|
|
1385
1401
|
const handlePaste = e => {
|
|
1386
|
-
if (startCell && !isEditing) {
|
|
1402
|
+
if (startCell && !isEditing.editing) {
|
|
1387
1403
|
e.preventDefault(); // Chặn hành vi mặc định
|
|
1388
1404
|
const clipboardText = e.clipboardData?.getData('text/plain') ?? '';
|
|
1389
1405
|
handlePasteToTable(clipboardText, e);
|
|
@@ -1905,6 +1921,128 @@ const InternalTable = props => {
|
|
|
1905
1921
|
}
|
|
1906
1922
|
return toolbarItems.filter(it => it.position !== 'Bottom' && it.fixedRight);
|
|
1907
1923
|
}, [toolbarItems]);
|
|
1924
|
+
const triggerCommandClick = args => {
|
|
1925
|
+
const {
|
|
1926
|
+
id: idCommand,
|
|
1927
|
+
rowId,
|
|
1928
|
+
rowData,
|
|
1929
|
+
index
|
|
1930
|
+
} = args;
|
|
1931
|
+
const tmpData = [...dataSource];
|
|
1932
|
+
if (idCommand === 'DELETE') {
|
|
1933
|
+
// bật modal confirm
|
|
1934
|
+
if (commandSettings && commandSettings.confirmDialog) {
|
|
1935
|
+
MySwal.fire({
|
|
1936
|
+
title: t ? t('Confirm') : 'Confirm',
|
|
1937
|
+
text: t ? t('Do you want to delete item?') : 'Do you want to delete item?',
|
|
1938
|
+
// icon: 'warning',
|
|
1939
|
+
allowOutsideClick: false,
|
|
1940
|
+
showCancelButton: true,
|
|
1941
|
+
confirmButtonText: t ? t('Delete') : 'Delete',
|
|
1942
|
+
cancelButtonText: t ? t('Cancel') : 'Cancel',
|
|
1943
|
+
customClass: {
|
|
1944
|
+
confirmButton: 'be-button btn-primary',
|
|
1945
|
+
cancelButton: 'be-button btn-danger ms-1'
|
|
1946
|
+
},
|
|
1947
|
+
buttonsStyling: false
|
|
1948
|
+
}).then(async result => {
|
|
1949
|
+
if (result.value) {
|
|
1950
|
+
if (!commandSettings || commandSettings && commandSettings.client !== false) {
|
|
1951
|
+
// client
|
|
1952
|
+
|
|
1953
|
+
// kiểm tra dòng hiện tại có parent
|
|
1954
|
+
|
|
1955
|
+
let newData = [];
|
|
1956
|
+
if (rowData?.parentId) {
|
|
1957
|
+
const parent = (0, _utils.findItemByKey)(tmpData, rowKey, rowData.parentId);
|
|
1958
|
+
const childData = parent?.children ? [...parent.children] : [];
|
|
1959
|
+
const findIndex = childData.findIndex(obj => obj[rowKey] === rowData[rowKey]);
|
|
1960
|
+
childData.splice(Number(findIndex), 1);
|
|
1961
|
+
const newRowData = {
|
|
1962
|
+
...parent,
|
|
1963
|
+
children: childData
|
|
1964
|
+
};
|
|
1965
|
+
// const newDataSource = updateArrayByKey(tmpData, newRowData, rowKey as string)
|
|
1966
|
+
newData = (0, _utils.updateArrayByKey)(tmpData, newRowData, rowKey);
|
|
1967
|
+
} else {
|
|
1968
|
+
tmpData.splice(Number(index), 1);
|
|
1969
|
+
newData = [...tmpData];
|
|
1970
|
+
}
|
|
1971
|
+
if (commandClick) {
|
|
1972
|
+
commandClick({
|
|
1973
|
+
id: idCommand,
|
|
1974
|
+
rowId: rowData.rowId,
|
|
1975
|
+
rowData,
|
|
1976
|
+
index,
|
|
1977
|
+
rows: [...newData]
|
|
1978
|
+
});
|
|
1979
|
+
}
|
|
1980
|
+
} else {
|
|
1981
|
+
// server ~~ không làm gì
|
|
1982
|
+
if (commandClick) {
|
|
1983
|
+
commandClick({
|
|
1984
|
+
id: idCommand,
|
|
1985
|
+
rowId: rowData.rowId,
|
|
1986
|
+
rowData,
|
|
1987
|
+
index,
|
|
1988
|
+
rows: [...convertData]
|
|
1989
|
+
});
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1992
|
+
} else if (result.dismiss === MySwal.DismissReason.cancel) {}
|
|
1993
|
+
});
|
|
1994
|
+
} else {
|
|
1995
|
+
// -------------------
|
|
1996
|
+
|
|
1997
|
+
if (!commandSettings || commandSettings && commandSettings.client !== false) {
|
|
1998
|
+
// client
|
|
1999
|
+
|
|
2000
|
+
let newData2 = [];
|
|
2001
|
+
if (rowData?.parentId) {
|
|
2002
|
+
const parent = (0, _utils.findItemByKey)(convertData, rowKey, rowData.parentId);
|
|
2003
|
+
const childData = parent?.children ? [...parent.children] : [];
|
|
2004
|
+
const findIndex = childData.findIndex(obj => obj[rowKey] === rowData[rowKey]);
|
|
2005
|
+
childData.splice(Number(findIndex), 1);
|
|
2006
|
+
const newRowData = {
|
|
2007
|
+
...parent,
|
|
2008
|
+
children: childData
|
|
2009
|
+
};
|
|
2010
|
+
newData2 = (0, _utils.updateArrayByKey)(tmpData, newRowData, rowKey);
|
|
2011
|
+
} else {
|
|
2012
|
+
tmpData.splice(Number(index), 1);
|
|
2013
|
+
newData2 = [...tmpData];
|
|
2014
|
+
}
|
|
2015
|
+
if (commandClick) {
|
|
2016
|
+
commandClick({
|
|
2017
|
+
id: idCommand,
|
|
2018
|
+
rowId,
|
|
2019
|
+
rowData,
|
|
2020
|
+
index,
|
|
2021
|
+
rows: [...newData2]
|
|
2022
|
+
});
|
|
2023
|
+
}
|
|
2024
|
+
} else {
|
|
2025
|
+
// server
|
|
2026
|
+
if (commandClick) {
|
|
2027
|
+
commandClick({
|
|
2028
|
+
id: idCommand,
|
|
2029
|
+
rowId,
|
|
2030
|
+
rowData,
|
|
2031
|
+
index,
|
|
2032
|
+
rows: [...convertData]
|
|
2033
|
+
});
|
|
2034
|
+
}
|
|
2035
|
+
}
|
|
2036
|
+
}
|
|
2037
|
+
} else {
|
|
2038
|
+
if (commandClick) {
|
|
2039
|
+
commandClick({
|
|
2040
|
+
...args,
|
|
2041
|
+
rows: convertData
|
|
2042
|
+
});
|
|
2043
|
+
}
|
|
2044
|
+
}
|
|
2045
|
+
};
|
|
1908
2046
|
return /*#__PURE__*/_react.default.createElement(_rcMasterUi.ConfigProvider, {
|
|
1909
2047
|
locale: language,
|
|
1910
2048
|
theme: {
|
|
@@ -2000,7 +2138,8 @@ const InternalTable = props => {
|
|
|
2000
2138
|
toolbarItemTopRight: toolbarItemTopRight,
|
|
2001
2139
|
toolbarItemsTop: toolbarItemsTop,
|
|
2002
2140
|
toolbarItemsBottom: toolbarItemsBottom,
|
|
2003
|
-
isDataTree: isDataTree
|
|
2141
|
+
isDataTree: isDataTree,
|
|
2142
|
+
commandClick: triggerCommandClick
|
|
2004
2143
|
})), /*#__PURE__*/_react.default.createElement(_rcMasterUi.Modal, {
|
|
2005
2144
|
open: isFullScreen,
|
|
2006
2145
|
footer: null,
|
|
@@ -2058,7 +2197,8 @@ const InternalTable = props => {
|
|
|
2058
2197
|
defaultFilter: defaultFilter,
|
|
2059
2198
|
defaultSorter: defaultSorter,
|
|
2060
2199
|
dataRowIds: dataIds,
|
|
2061
|
-
editAble: editAble
|
|
2200
|
+
editAble: editAble,
|
|
2201
|
+
commandClick: triggerCommandClick
|
|
2062
2202
|
}))))))));
|
|
2063
2203
|
};
|
|
2064
2204
|
var _default = exports.default = InternalTable;
|