es-grid-template 1.8.71 → 1.8.72
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/grid-component/TempTable.js +2 -1
- package/es/group-component/ColumnsChoose.d.ts +13 -0
- package/es/group-component/ColumnsChoose.js +211 -0
- package/es/group-component/ColumnsGroup/ColumnsGroup.d.ts +12 -0
- package/es/group-component/ColumnsGroup/ColumnsGroup.js +230 -0
- package/es/group-component/ColumnsGroup/index.d.ts +1 -0
- package/es/group-component/ColumnsGroup/index.js +1 -0
- package/es/group-component/ContextMenu.d.ts +19 -0
- package/es/group-component/ContextMenu.js +74 -0
- package/es/group-component/InternalTable.d.ts +8 -0
- package/es/group-component/InternalTable.js +224 -0
- package/es/group-component/TableContainer.d.ts +49 -0
- package/es/group-component/TableContainer.js +375 -0
- package/es/group-component/TableContainerEdit.d.ts +48 -0
- package/es/group-component/TableContainerEdit.js +2068 -0
- package/es/group-component/body/EditableCell.d.ts +16 -0
- package/es/group-component/body/EditableCell.js +1066 -0
- package/es/group-component/body/TableBody.d.ts +14 -0
- package/es/group-component/body/TableBody.js +82 -0
- package/es/group-component/body/TableBodyCell.d.ts +12 -0
- package/es/group-component/body/TableBodyCell.js +587 -0
- package/es/group-component/body/TableBodyCellEdit.d.ts +17 -0
- package/es/group-component/body/TableBodyCellEdit.js +1398 -0
- package/es/group-component/body/TableBodyCellEmpty.d.ts +12 -0
- package/es/group-component/body/TableBodyCellEmpty.js +149 -0
- package/es/group-component/body/TableBodyRow.d.ts +21 -0
- package/es/group-component/body/TableBodyRow.js +199 -0
- package/es/group-component/body/TableBodyRowGroupCell.d.ts +12 -0
- package/es/group-component/body/TableBodyRowGroupCell.js +567 -0
- package/es/group-component/components/ControlCheckbox.d.ts +13 -0
- package/es/group-component/components/ControlCheckbox.js +84 -0
- package/es/group-component/components/EditForm/EditForm.d.ts +27 -0
- package/es/group-component/components/EditForm/EditForm.js +394 -0
- package/es/group-component/components/EditForm/index.d.ts +1 -0
- package/es/group-component/components/EditForm/index.js +1 -0
- package/es/group-component/components/InputControl/InputControl.d.ts +27 -0
- package/es/group-component/components/InputControl/InputControl.js +118 -0
- package/es/group-component/components/InputControl/index.d.ts +1 -0
- package/es/group-component/components/InputControl/index.js +1 -0
- package/es/group-component/components/async-select/index.d.ts +11 -0
- package/es/group-component/components/async-select/index.js +38 -0
- package/es/group-component/components/async-table-select/index.d.ts +11 -0
- package/es/group-component/components/async-table-select/index.js +40 -0
- package/es/group-component/components/checkbox-control/index.d.ts +13 -0
- package/es/group-component/components/checkbox-control/index.js +40 -0
- package/es/group-component/components/checkbox-filter/CheckboxFilter.d.ts +18 -0
- package/es/group-component/components/checkbox-filter/CheckboxFilter.js +258 -0
- package/es/group-component/components/checkbox-filter/FilterSearch.d.ts +12 -0
- package/es/group-component/components/checkbox-filter/FilterSearch.js +36 -0
- package/es/group-component/components/command/Command.d.ts +10 -0
- package/es/group-component/components/command/Command.js +35 -0
- package/es/group-component/components/number/index.d.ts +12 -0
- package/es/group-component/components/number/index.js +42 -0
- package/es/group-component/components/number-range/index.d.ts +13 -0
- package/es/group-component/components/number-range/index.js +79 -0
- package/es/group-component/features/operator.d.ts +24 -0
- package/es/group-component/features/operator.js +62 -0
- package/es/group-component/footer/TableFooter.d.ts +7 -0
- package/es/group-component/footer/TableFooter.js +34 -0
- package/es/group-component/footer/TableFooterCell.d.ts +7 -0
- package/es/group-component/footer/TableFooterCell.js +66 -0
- package/es/group-component/footer/TableFooterRow.d.ts +8 -0
- package/es/group-component/footer/TableFooterRow.js +30 -0
- package/es/group-component/header/TableHead.d.ts +15 -0
- package/es/group-component/header/TableHead.js +98 -0
- package/es/group-component/header/TableHeadCell.d.ts +15 -0
- package/es/group-component/header/TableHeadCell.js +310 -0
- package/es/group-component/header/TableHeadCell2.d.ts +17 -0
- package/es/group-component/header/TableHeadCell2.js +321 -0
- package/es/group-component/header/TableHeadGroupCell.d.ts +17 -0
- package/es/group-component/header/TableHeadGroupCell.js +94 -0
- package/es/group-component/header/TableHeadRow.d.ts +15 -0
- package/es/group-component/header/TableHeadRow.js +52 -0
- package/es/group-component/header/renderFilter.d.ts +20 -0
- package/es/group-component/header/renderFilter.js +291 -0
- package/es/group-component/hook/convert.d.ts +1 -0
- package/es/group-component/hook/convert.js +28 -0
- package/es/group-component/hook/useColumns.d.ts +28 -0
- package/es/group-component/hook/useColumns.js +306 -0
- package/es/group-component/hook/useFilterOperator.d.ts +7 -0
- package/es/group-component/hook/useFilterOperator.js +33 -0
- package/es/group-component/hook/utils.d.ts +220 -0
- package/es/group-component/hook/utils.js +2340 -0
- package/es/group-component/index.d.ts +2 -0
- package/es/group-component/index.js +2 -0
- package/es/group-component/style.d.ts +22 -0
- package/es/group-component/style.js +48 -0
- package/es/group-component/style.scss +1438 -0
- package/es/group-component/table/Grid.d.ts +33 -0
- package/es/group-component/table/Grid.js +438 -0
- package/es/group-component/table/TableWrapper.d.ts +33 -0
- package/es/group-component/table/TableWrapper.js +250 -0
- package/es/group-component/useContext.d.ts +100 -0
- package/es/group-component/useContext.js +21 -0
- package/es/table-component/InternalTable.js +6 -1
- package/es/table-component/TableContainer.js +4 -2
- package/es/table-component/body/TableBodyCell.js +49 -40
- package/es/table-component/body/TableBodyRow.js +4 -1
- package/es/table-component/hook/utils.d.ts +1 -0
- package/es/table-component/hook/utils.js +15 -7
- package/es/table-component/style.js +1 -1
- package/es/table-component/table/Grid.js +3 -0
- package/es/table-component/useContext.d.ts +5 -0
- package/es/table-virtuoso/InternalTable.js +2 -2
- package/es/table-virtuoso/body/TableBodyCell.js +2 -7
- package/es/table-virtuoso/body/TableBodyCellRowGroup.d.ts +14 -0
- package/es/table-virtuoso/body/TableBodyCellRowGroup.js +196 -0
- package/es/table-virtuoso/body/TableBodyRow.d.ts +1 -1
- package/es/table-virtuoso/body/TableBodyRow.js +43 -1
- package/es/table-virtuoso/hook/utils.d.ts +1 -0
- package/es/table-virtuoso/hook/utils.js +29 -0
- package/es/table-virtuoso/style.js +3 -1
- package/es/table-virtuoso/table/Grid.js +2 -2
- package/es/table-virtuoso/table/TableWrapper.d.ts +7 -1
- package/es/table-virtuoso/table/TableWrapper.js +24 -5
- package/es/table-virtuoso/useContext.d.ts +6 -3
- package/es/table-virtuoso/useContext.js +18 -0
- package/lib/grid-component/TempTable.js +2 -1
- package/lib/group-component/ColumnsChoose.d.ts +13 -0
- package/lib/group-component/ColumnsChoose.js +221 -0
- package/lib/group-component/ColumnsGroup/ColumnsGroup.d.ts +12 -0
- package/lib/group-component/ColumnsGroup/ColumnsGroup.js +241 -0
- package/lib/group-component/ColumnsGroup/index.d.ts +1 -0
- package/lib/group-component/ColumnsGroup/index.js +16 -0
- package/lib/group-component/ContextMenu.d.ts +19 -0
- package/lib/group-component/ContextMenu.js +83 -0
- package/lib/group-component/InternalTable.d.ts +8 -0
- package/lib/group-component/InternalTable.js +233 -0
- package/lib/group-component/TableContainer.d.ts +49 -0
- package/lib/group-component/TableContainer.js +382 -0
- package/lib/group-component/TableContainerEdit.d.ts +48 -0
- package/lib/group-component/TableContainerEdit.js +2075 -0
- package/lib/group-component/body/EditableCell.d.ts +16 -0
- package/lib/group-component/body/EditableCell.js +1075 -0
- package/lib/group-component/body/TableBody.d.ts +14 -0
- package/lib/group-component/body/TableBody.js +91 -0
- package/lib/group-component/body/TableBodyCell.d.ts +12 -0
- package/lib/group-component/body/TableBodyCell.js +595 -0
- package/lib/group-component/body/TableBodyCellEdit.d.ts +17 -0
- package/lib/group-component/body/TableBodyCellEdit.js +1405 -0
- package/lib/group-component/body/TableBodyCellEmpty.d.ts +12 -0
- package/lib/group-component/body/TableBodyCellEmpty.js +156 -0
- package/lib/group-component/body/TableBodyRow.d.ts +21 -0
- package/lib/group-component/body/TableBodyRow.js +206 -0
- package/lib/group-component/body/TableBodyRowGroupCell.d.ts +12 -0
- package/lib/group-component/body/TableBodyRowGroupCell.js +575 -0
- package/lib/group-component/components/ControlCheckbox.d.ts +13 -0
- package/lib/group-component/components/ControlCheckbox.js +92 -0
- package/lib/group-component/components/EditForm/EditForm.d.ts +27 -0
- package/lib/group-component/components/EditForm/EditForm.js +404 -0
- package/lib/group-component/components/EditForm/index.d.ts +1 -0
- package/lib/group-component/components/EditForm/index.js +16 -0
- package/lib/group-component/components/InputControl/InputControl.d.ts +27 -0
- package/lib/group-component/components/InputControl/InputControl.js +127 -0
- package/lib/group-component/components/InputControl/index.d.ts +1 -0
- package/lib/group-component/components/InputControl/index.js +16 -0
- package/lib/group-component/components/async-select/index.d.ts +11 -0
- package/lib/group-component/components/async-select/index.js +47 -0
- package/lib/group-component/components/async-table-select/index.d.ts +11 -0
- package/lib/group-component/components/async-table-select/index.js +49 -0
- package/lib/group-component/components/checkbox-control/index.d.ts +13 -0
- package/lib/group-component/components/checkbox-control/index.js +48 -0
- package/lib/group-component/components/checkbox-filter/CheckboxFilter.d.ts +18 -0
- package/lib/group-component/components/checkbox-filter/CheckboxFilter.js +267 -0
- package/lib/group-component/components/checkbox-filter/FilterSearch.d.ts +12 -0
- package/lib/group-component/components/checkbox-filter/FilterSearch.js +44 -0
- package/lib/group-component/components/command/Command.d.ts +10 -0
- package/lib/group-component/components/command/Command.js +44 -0
- package/lib/group-component/components/number/index.d.ts +12 -0
- package/lib/group-component/components/number/index.js +50 -0
- package/lib/group-component/components/number-range/index.d.ts +13 -0
- package/lib/group-component/components/number-range/index.js +87 -0
- package/lib/group-component/features/operator.d.ts +24 -0
- package/lib/group-component/features/operator.js +67 -0
- package/lib/group-component/footer/TableFooter.d.ts +7 -0
- package/lib/group-component/footer/TableFooter.js +44 -0
- package/lib/group-component/footer/TableFooterCell.d.ts +7 -0
- package/lib/group-component/footer/TableFooterCell.js +75 -0
- package/lib/group-component/footer/TableFooterRow.d.ts +8 -0
- package/lib/group-component/footer/TableFooterRow.js +37 -0
- package/lib/group-component/header/TableHead.d.ts +15 -0
- package/lib/group-component/header/TableHead.js +107 -0
- package/lib/group-component/header/TableHeadCell.d.ts +15 -0
- package/lib/group-component/header/TableHeadCell.js +319 -0
- package/lib/group-component/header/TableHeadCell2.d.ts +17 -0
- package/lib/group-component/header/TableHeadCell2.js +330 -0
- package/lib/group-component/header/TableHeadGroupCell.d.ts +17 -0
- package/lib/group-component/header/TableHeadGroupCell.js +103 -0
- package/lib/group-component/header/TableHeadRow.d.ts +15 -0
- package/lib/group-component/header/TableHeadRow.js +59 -0
- package/lib/group-component/header/renderFilter.d.ts +20 -0
- package/lib/group-component/header/renderFilter.js +301 -0
- package/lib/group-component/hook/convert.d.ts +1 -0
- package/lib/group-component/hook/convert.js +34 -0
- package/lib/group-component/hook/useColumns.d.ts +28 -0
- package/lib/group-component/hook/useColumns.js +318 -0
- package/lib/group-component/hook/useFilterOperator.d.ts +7 -0
- package/lib/group-component/hook/useFilterOperator.js +40 -0
- package/lib/group-component/hook/utils.d.ts +220 -0
- package/lib/group-component/hook/utils.js +2468 -0
- package/lib/group-component/index.d.ts +2 -0
- package/lib/group-component/index.js +9 -0
- package/lib/group-component/style.d.ts +22 -0
- package/lib/group-component/style.js +55 -0
- package/lib/group-component/style.scss +1438 -0
- package/lib/group-component/table/Grid.d.ts +33 -0
- package/lib/group-component/table/Grid.js +443 -0
- package/lib/group-component/table/TableWrapper.d.ts +33 -0
- package/lib/group-component/table/TableWrapper.js +259 -0
- package/lib/group-component/useContext.d.ts +100 -0
- package/lib/group-component/useContext.js +27 -0
- package/lib/table-component/InternalTable.js +6 -1
- package/lib/table-component/TableContainer.js +4 -2
- package/lib/table-component/body/TableBodyCell.js +49 -40
- package/lib/table-component/body/TableBodyRow.js +4 -1
- package/lib/table-component/hook/utils.d.ts +1 -0
- package/lib/table-component/hook/utils.js +16 -7
- package/lib/table-component/style.js +1 -1
- package/lib/table-component/table/Grid.js +3 -0
- package/lib/table-component/useContext.d.ts +5 -0
- package/lib/table-virtuoso/InternalTable.js +2 -2
- package/lib/table-virtuoso/body/TableBodyCell.js +2 -7
- package/lib/table-virtuoso/body/TableBodyCellRowGroup.d.ts +14 -0
- package/lib/table-virtuoso/body/TableBodyCellRowGroup.js +203 -0
- package/lib/table-virtuoso/body/TableBodyRow.d.ts +1 -1
- package/lib/table-virtuoso/body/TableBodyRow.js +43 -1
- package/lib/table-virtuoso/hook/utils.d.ts +1 -0
- package/lib/table-virtuoso/hook/utils.js +32 -1
- package/lib/table-virtuoso/style.js +3 -1
- package/lib/table-virtuoso/table/Grid.js +2 -2
- package/lib/table-virtuoso/table/TableWrapper.d.ts +7 -1
- package/lib/table-virtuoso/table/TableWrapper.js +24 -5
- package/lib/table-virtuoso/useContext.d.ts +6 -3
- package/lib/table-virtuoso/useContext.js +18 -0
- package/package.json +1 -1
|
@@ -0,0 +1,1398 @@
|
|
|
1
|
+
import { flexRender } from "@tanstack/react-table";
|
|
2
|
+
import Space from "rc-master-ui/es/space";
|
|
3
|
+
import Command from "../components/command/Command";
|
|
4
|
+
import ReactDOMServer from 'react-dom/server';
|
|
5
|
+
import { addRowsDown, addRowsDownWithCtrl, addRowsUp, addRowsUpWithCtrl, findFirst, flattenArray, flattenData, getColIdsBetween, getCommonPinningStyles, getEditType, getRowIdsBetween, getSelectedCellMatrix, isEditable, isObjEmpty, isObjEqual, newGuid, unFlattenData, updateOrInsert } from "../hook/utils";
|
|
6
|
+
import Checkbox from "rc-master-ui/es/checkbox/Checkbox";
|
|
7
|
+
import classNames from "classnames";
|
|
8
|
+
import React from "react";
|
|
9
|
+
import { TableContext } from "../useContext";
|
|
10
|
+
import EditableCell from "./EditableCell";
|
|
11
|
+
import { nonActionColumn } from "../../grid-component/hooks";
|
|
12
|
+
import { toggleRowSelection } from "../hook/useColumns";
|
|
13
|
+
import { unGroupData } from "../../table-virtuoso/hook/utils";
|
|
14
|
+
const renderCellIndex = props => {
|
|
15
|
+
const {
|
|
16
|
+
parrents,
|
|
17
|
+
cell,
|
|
18
|
+
pagination
|
|
19
|
+
} = props;
|
|
20
|
+
if (parrents && parrents.length > 0) {
|
|
21
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
22
|
+
className: "ui-rc_cell-content"
|
|
23
|
+
}, parrents.map(pr => {
|
|
24
|
+
return `${pr.index + 1}.`;
|
|
25
|
+
}), cell.row.index + 1);
|
|
26
|
+
}
|
|
27
|
+
if (pagination && pagination.onChange) {
|
|
28
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
29
|
+
className: "ui-rc_cell-content"
|
|
30
|
+
}, cell.row.index + (pagination ? ((pagination.currentPage ?? 1) - 1) * (pagination?.pageSize ?? 0) : 0) + 1);
|
|
31
|
+
}
|
|
32
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
33
|
+
className: "ui-rc_cell-content"
|
|
34
|
+
}, cell.row.index + 1);
|
|
35
|
+
};
|
|
36
|
+
const renderCommand = args => {
|
|
37
|
+
const {
|
|
38
|
+
cell,
|
|
39
|
+
commandClick,
|
|
40
|
+
id,
|
|
41
|
+
data
|
|
42
|
+
} = args;
|
|
43
|
+
const col = cell.column.columnDef.meta ?? {};
|
|
44
|
+
const record = cell.row.original;
|
|
45
|
+
|
|
46
|
+
// const commandItems = args.cell.column.columnDef?.meta?.commandItems ?? []
|
|
47
|
+
|
|
48
|
+
const commands = col.commandItems ? col.commandItems.map(it => {
|
|
49
|
+
return {
|
|
50
|
+
...it,
|
|
51
|
+
visible: typeof it.visible === 'function' ? it.visible?.(record) : it.visible
|
|
52
|
+
};
|
|
53
|
+
}) : [];
|
|
54
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
55
|
+
className: "ui-rc_cell-content"
|
|
56
|
+
}, /*#__PURE__*/React.createElement(Space, null, commands.filter(it => it.visible !== false).map(item => {
|
|
57
|
+
return /*#__PURE__*/React.createElement(Command, {
|
|
58
|
+
id: id,
|
|
59
|
+
key: item.id,
|
|
60
|
+
item: item,
|
|
61
|
+
record: record,
|
|
62
|
+
onClick: () => {
|
|
63
|
+
commandClick?.({
|
|
64
|
+
id: item.id,
|
|
65
|
+
// rowId: getRowKey(record, index) as any,
|
|
66
|
+
rowId: record.rowId,
|
|
67
|
+
rowData: record,
|
|
68
|
+
index: cell.row.index,
|
|
69
|
+
rows: [...data]
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
})));
|
|
74
|
+
};
|
|
75
|
+
const renderSelection = args => {
|
|
76
|
+
const {
|
|
77
|
+
row
|
|
78
|
+
} = args.cell;
|
|
79
|
+
const {
|
|
80
|
+
cell,
|
|
81
|
+
expandIconColumnIndex,
|
|
82
|
+
isDataTree,
|
|
83
|
+
expanded,
|
|
84
|
+
setExpanded
|
|
85
|
+
} = args;
|
|
86
|
+
const {
|
|
87
|
+
selectionSettings,
|
|
88
|
+
setIsSelectionChange,
|
|
89
|
+
isSelectionChange
|
|
90
|
+
} = args;
|
|
91
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
92
|
+
style: {
|
|
93
|
+
|
|
94
|
+
// paddingLeft: `${row.depth * 2}rem`,
|
|
95
|
+
}
|
|
96
|
+
}, cell.column.getIndex() === expandIconColumnIndex && isDataTree && /*#__PURE__*/React.createElement("div", {
|
|
97
|
+
className: "ui-rc-table-row-expand-trigger",
|
|
98
|
+
style: {
|
|
99
|
+
paddingLeft: `${cell.row.depth * 25}px`
|
|
100
|
+
}
|
|
101
|
+
}, /*#__PURE__*/React.createElement("div", null, cell.row.getCanExpand() ? /*#__PURE__*/React.createElement("button", {
|
|
102
|
+
// onClick: row.getToggleExpandedHandler(),
|
|
103
|
+
onClick: e => {
|
|
104
|
+
e.stopPropagation();
|
|
105
|
+
e.preventDefault();
|
|
106
|
+
const keys = Object.keys(expanded);
|
|
107
|
+
// @ts-ignore
|
|
108
|
+
const tmp = {
|
|
109
|
+
...expanded
|
|
110
|
+
};
|
|
111
|
+
if (keys.includes(cell.row.id)) {
|
|
112
|
+
delete tmp[cell.row.id];
|
|
113
|
+
setExpanded(tmp);
|
|
114
|
+
} else {
|
|
115
|
+
setExpanded(old => ({
|
|
116
|
+
...old,
|
|
117
|
+
[cell.row.id]: true
|
|
118
|
+
}));
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
style: {
|
|
122
|
+
cursor: "pointer"
|
|
123
|
+
},
|
|
124
|
+
className: "ui-rc-table-row-expand"
|
|
125
|
+
}, cell.row.getIsExpanded() ? /*#__PURE__*/React.createElement("span", {
|
|
126
|
+
className: "ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-expanded"
|
|
127
|
+
}) : /*#__PURE__*/React.createElement("span", {
|
|
128
|
+
className: "ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-collapsed"
|
|
129
|
+
})) : /*#__PURE__*/React.createElement("span", {
|
|
130
|
+
className: "ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-spaced"
|
|
131
|
+
}))), /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Checkbox, {
|
|
132
|
+
checked: row.getIsSelected() || row.getIsAllSubRowsSelected(),
|
|
133
|
+
indeterminate: row.getIsSomeSelected() && selectionSettings && selectionSettings.mode === 'checkbox' && selectionSettings.type !== 'single'
|
|
134
|
+
// indeterminate={row.getIsSomeSelected() }
|
|
135
|
+
// onChange={(e) => {
|
|
136
|
+
|
|
137
|
+
// row.getToggleSelectedHandler()(e)
|
|
138
|
+
|
|
139
|
+
// if (row.getIsSelected()) { // nếu đã chọn
|
|
140
|
+
|
|
141
|
+
// const aaa = isSelectionChange?.rowsData.filter((it) => it.id !== row.id)
|
|
142
|
+
|
|
143
|
+
// setIsSelectionChange({
|
|
144
|
+
// isChange: true,
|
|
145
|
+
// type: 'rowSelected',
|
|
146
|
+
// rowData: row.original,
|
|
147
|
+
// rowsData: aaa ?? []
|
|
148
|
+
// })
|
|
149
|
+
|
|
150
|
+
// } else {
|
|
151
|
+
|
|
152
|
+
// const { rowsData } = isSelectionChange ?? {}
|
|
153
|
+
|
|
154
|
+
// const abc = rowsData && rowsData.length > 0 ? [...rowsData] : []
|
|
155
|
+
|
|
156
|
+
// abc.push(row)
|
|
157
|
+
|
|
158
|
+
// setIsSelectionChange({
|
|
159
|
+
// isChange: true,
|
|
160
|
+
// type: 'rowSelected',
|
|
161
|
+
// rowData: row.original,
|
|
162
|
+
// rowsData: abc
|
|
163
|
+
// })
|
|
164
|
+
// }
|
|
165
|
+
|
|
166
|
+
// }}
|
|
167
|
+
,
|
|
168
|
+
|
|
169
|
+
onChange: e => {
|
|
170
|
+
toggleRowSelection({
|
|
171
|
+
e,
|
|
172
|
+
cell,
|
|
173
|
+
setIsSelectionChange,
|
|
174
|
+
isSelectionChange,
|
|
175
|
+
selectionSettings
|
|
176
|
+
});
|
|
177
|
+
},
|
|
178
|
+
disabled: !row.getCanSelect()
|
|
179
|
+
})));
|
|
180
|
+
};
|
|
181
|
+
const TableBodyCellEdit = props => {
|
|
182
|
+
const {
|
|
183
|
+
cell,
|
|
184
|
+
commandClick,
|
|
185
|
+
// tableId,
|
|
186
|
+
table,
|
|
187
|
+
isEditing,
|
|
188
|
+
isRowEditable,
|
|
189
|
+
columnVirtualizer,
|
|
190
|
+
rowVirtualizer
|
|
191
|
+
// virtualRow
|
|
192
|
+
} = props;
|
|
193
|
+
const {
|
|
194
|
+
id,
|
|
195
|
+
rowKey,
|
|
196
|
+
editingKey,
|
|
197
|
+
prefix,
|
|
198
|
+
focusedCell,
|
|
199
|
+
rangeState,
|
|
200
|
+
setFocusedCell,
|
|
201
|
+
setEditingKey,
|
|
202
|
+
setRangeState,
|
|
203
|
+
setRangePasteState,
|
|
204
|
+
endCell,
|
|
205
|
+
setEndCell,
|
|
206
|
+
isSelecting,
|
|
207
|
+
isPasting,
|
|
208
|
+
setEndPasteCell,
|
|
209
|
+
endPasteCell,
|
|
210
|
+
setIsPasting,
|
|
211
|
+
setIsSelecting,
|
|
212
|
+
setStartCell,
|
|
213
|
+
setStartPasteCell,
|
|
214
|
+
startCell,
|
|
215
|
+
startPasteCell,
|
|
216
|
+
originData,
|
|
217
|
+
dataSource,
|
|
218
|
+
triggerPaste,
|
|
219
|
+
handleDeleteContent,
|
|
220
|
+
reset,
|
|
221
|
+
setValue,
|
|
222
|
+
getValues,
|
|
223
|
+
handleCellChange,
|
|
224
|
+
handleCellChangeAndAddRow,
|
|
225
|
+
dataErrors,
|
|
226
|
+
expanded,
|
|
227
|
+
setExpanded,
|
|
228
|
+
expandable,
|
|
229
|
+
isDataTree,
|
|
230
|
+
handleCellClick,
|
|
231
|
+
isSelectionChange,
|
|
232
|
+
setIsSelectionChange,
|
|
233
|
+
selectionSettings,
|
|
234
|
+
pagination,
|
|
235
|
+
handleAddMulti,
|
|
236
|
+
groupColumns
|
|
237
|
+
} = React.useContext(TableContext);
|
|
238
|
+
const expandIconColumnIndex = expandable?.expandIconColumnIndex;
|
|
239
|
+
const record = cell.row.original;
|
|
240
|
+
const columnMeta = cell.column.columnDef.meta ?? {};
|
|
241
|
+
const [isOpenTooltip, setIsOpenTooltip] = React.useState(false);
|
|
242
|
+
const rowError = dataErrors ? dataErrors.find(it => it.id === cell.row.id) : undefined;
|
|
243
|
+
const message = rowError && rowError[cell.column.id]?.field === cell.column.id ? rowError[cell.column.id].message : undefined;
|
|
244
|
+
const tooltipContent = isOpenTooltip === false ? '' : columnMeta?.tooltipDescription ? typeof columnMeta.tooltipDescription === 'function' ? columnMeta.tooltipDescription({
|
|
245
|
+
value: cell.getValue(),
|
|
246
|
+
record
|
|
247
|
+
}) : columnMeta.tooltipDescription : columnMeta.template && typeof columnMeta.template !== 'function' ? columnMeta.template : cell.getValue();
|
|
248
|
+
const canEdit = isEditable(cell.column.columnDef.meta, record) && isRowEditable !== false;
|
|
249
|
+
|
|
250
|
+
// const allRows = table.getRowModel().rows;
|
|
251
|
+
const allRows = table.getRowModel().flatRows;
|
|
252
|
+
|
|
253
|
+
// const rowNumber = virtualRow.index
|
|
254
|
+
const rowNumber = allRows.findIndex(it => it.id === cell.row.id);
|
|
255
|
+
const colIndex = cell.column.getIndex();
|
|
256
|
+
const isPinned = cell.column.getIsPinned();
|
|
257
|
+
const isLastLeftPinnedColumn = isPinned === "left" && cell.column.getIsLastColumn("left");
|
|
258
|
+
const isFirstRightPinnedColumn = isPinned === "right" && cell.column.getIsFirstColumn("right");
|
|
259
|
+
const selectRowIds = React.useMemo(() => {
|
|
260
|
+
return startCell && endCell ? getRowIdsBetween(table, startCell.rowId, endCell.rowId) : [];
|
|
261
|
+
}, [endCell, startCell, table]);
|
|
262
|
+
const isCellSelected = React.useMemo(() => {
|
|
263
|
+
if (!startCell || !endCell) return false;
|
|
264
|
+
|
|
265
|
+
// const rowIds = getRowIdsBetween(table, startCell.rowId, endCell.rowId);
|
|
266
|
+
const colIds = getColIdsBetween(table, startCell.colId, endCell.colId);
|
|
267
|
+
return selectRowIds.includes(cell.row.id) && colIds.includes(cell.column.id);
|
|
268
|
+
}, [cell.column.id, cell.row.id, endCell, selectRowIds, startCell, table]);
|
|
269
|
+
const editType = typeof columnMeta.editType === 'function' ? columnMeta.editType(record) : columnMeta.editType;
|
|
270
|
+
const {
|
|
271
|
+
rowRange,
|
|
272
|
+
colRange,
|
|
273
|
+
rowIds,
|
|
274
|
+
colIds,
|
|
275
|
+
startColIndex,
|
|
276
|
+
startRowIndex,
|
|
277
|
+
endColIndex,
|
|
278
|
+
endRowIndex
|
|
279
|
+
} = rangeState ?? {};
|
|
280
|
+
const pasteRangeState = getSelectedCellMatrix(table, startPasteCell, endPasteCell);
|
|
281
|
+
const isInRange = colRange && rowRange && rowRange.includes(cell.row.id) && colRange.includes(cell.column.id);
|
|
282
|
+
const isInRangePaste = pasteRangeState.rowRange && pasteRangeState.rowRange.includes(cell.row.id) && pasteRangeState.colRange.includes(cell.column.id);
|
|
283
|
+
|
|
284
|
+
// const isInRangePaste = rowRange && rowRange.includes(cell.row.id) && colRange.includes(cell.column.id);
|
|
285
|
+
|
|
286
|
+
const rowIdx = rowIds ? rowIds.indexOf(cell.row.id) : -1;
|
|
287
|
+
const colIdx = colIds ? colIds.indexOf(cell.column.id) : -1;
|
|
288
|
+
const rowIdxPaste = pasteRangeState.rowIds.indexOf(cell.row.id);
|
|
289
|
+
const colIdxPaste = pasteRangeState.colIds.indexOf(cell.column.id);
|
|
290
|
+
const isTop = rowIdx === startRowIndex;
|
|
291
|
+
const isBottom = rowIdx === endRowIndex;
|
|
292
|
+
const isLeft = colIdx === startColIndex;
|
|
293
|
+
const isRight = colIdx === endColIndex;
|
|
294
|
+
const isTopPaste = rowIdxPaste === pasteRangeState.startRowIndex;
|
|
295
|
+
const isBottomPaste = rowIdxPaste === pasteRangeState.endRowIndex;
|
|
296
|
+
const isLeftPaste = colIdxPaste === pasteRangeState.startColIndex;
|
|
297
|
+
const isRightPaste = colIdxPaste === pasteRangeState.endColIndex;
|
|
298
|
+
const parrents = cell.row.getParentRows();
|
|
299
|
+
const triggerDragPaste = (pasteState, ctrlKey) => {
|
|
300
|
+
const tmpCols = table.getVisibleLeafColumns();
|
|
301
|
+
const rowPasteIds = getRowIdsBetween(table, startPasteCell?.rowId ?? '', endPasteCell?.rowId ?? '');
|
|
302
|
+
const colPasteds = getColIdsBetween(table, startPasteCell?.colId ?? '', endPasteCell?.colId ?? '');
|
|
303
|
+
const rowSelectIds = getRowIdsBetween(table, startCell?.rowId ?? '', endCell?.rowId ?? '');
|
|
304
|
+
const colSelectIds = getColIdsBetween(table, startCell?.colId ?? '', endCell?.colId ?? '');
|
|
305
|
+
const dataSelected = [];
|
|
306
|
+
rowSelectIds.forEach(rowId => {
|
|
307
|
+
const row = allRows.find(r => r.id === rowId);
|
|
308
|
+
if (!row) return;
|
|
309
|
+
const rowData = [];
|
|
310
|
+
colSelectIds.forEach(colId => {
|
|
311
|
+
const cellll = row.getVisibleCells().find(c => c.column.id === colId);
|
|
312
|
+
const value = cellll?.getValue();
|
|
313
|
+
rowData.push(value !== undefined ? value : '');
|
|
314
|
+
});
|
|
315
|
+
dataSelected.push(rowData);
|
|
316
|
+
});
|
|
317
|
+
const copyRows = flattenData('children', dataSource).filter(it => rowSelectIds.includes(it[rowKey]));
|
|
318
|
+
let newRange;
|
|
319
|
+
if ((startRowIndex ?? 0) < (pasteRangeState.startRowIndex ?? 0)) {
|
|
320
|
+
// kéo xuóng
|
|
321
|
+
setRangeState?.(getSelectedCellMatrix(table, startCell, endPasteCell));
|
|
322
|
+
newRange = ctrlKey ? addRowsDownWithCtrl(dataSelected, rowPasteIds.length) : addRowsDown(dataSelected, rowPasteIds.length);
|
|
323
|
+
} else {
|
|
324
|
+
// kéo lên
|
|
325
|
+
setStartCell?.(endCell);
|
|
326
|
+
setRangeState?.(getSelectedCellMatrix(table, endCell, endPasteCell));
|
|
327
|
+
newRange = ctrlKey ? addRowsUpWithCtrl(dataSelected, rowPasteIds.length) : addRowsUp(dataSelected, rowPasteIds.length);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// Cập nhật data mới
|
|
331
|
+
const newData = flattenArray([...dataSource]);
|
|
332
|
+
const pastedRows = [];
|
|
333
|
+
newRange.addedRows.forEach((rowValues, rowIndex1) => {
|
|
334
|
+
const targetRow = pasteState.startRowIndex + rowIndex1;
|
|
335
|
+
|
|
336
|
+
// Nếu vượt quá số dòng hiện có, thêm dòng mới
|
|
337
|
+
if (targetRow >= newData.length) {
|
|
338
|
+
newData.push({
|
|
339
|
+
id: undefined,
|
|
340
|
+
rowId: newGuid()
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
rowValues.forEach((cellValue, colIndex1) => {
|
|
344
|
+
const targetCol = startColIndex + colIndex1;
|
|
345
|
+
if (targetCol >= tmpCols.length) {
|
|
346
|
+
// Không vượt quá số cột
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
const columnKey = tmpCols[targetCol].id;
|
|
350
|
+
const disable = !isEditable(tmpCols[targetCol].columnDef.meta, record);
|
|
351
|
+
if (!disable) {
|
|
352
|
+
newData[targetRow] = {
|
|
353
|
+
...newData[targetRow],
|
|
354
|
+
[columnKey]: typeof cellValue === 'string' ? cellValue.trim() : cellValue
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
// Lưu dòng được paste
|
|
360
|
+
pastedRows.push(newData[targetRow]);
|
|
361
|
+
});
|
|
362
|
+
const rsFilterData = updateOrInsert(flattenArray([...originData]), newData);
|
|
363
|
+
const rs = unFlattenData(rsFilterData);
|
|
364
|
+
triggerPaste?.(pastedRows, colPasteds, rs, copyRows);
|
|
365
|
+
|
|
366
|
+
// // setRangeState?.(getSelectedCellMatrix(table, startCell, endPasteCell))
|
|
367
|
+
|
|
368
|
+
setEndCell?.(endPasteCell);
|
|
369
|
+
setEndPasteCell?.(undefined);
|
|
370
|
+
setStartPasteCell?.(undefined);
|
|
371
|
+
setRangePasteState?.(undefined);
|
|
372
|
+
};
|
|
373
|
+
const triggerDragPasteGroup = (pasteState, ctrlKey) => {
|
|
374
|
+
const tmpCols = table.getVisibleLeafColumns();
|
|
375
|
+
const rowPasteIds = getRowIdsBetween(table, startPasteCell?.rowId ?? '', endPasteCell?.rowId ?? '');
|
|
376
|
+
const colPasteds = getColIdsBetween(table, startPasteCell?.colId ?? '', endPasteCell?.colId ?? '');
|
|
377
|
+
const rowSelectIds = getRowIdsBetween(table, startCell?.rowId ?? '', endCell?.rowId ?? '');
|
|
378
|
+
const colSelectIds = getColIdsBetween(table, startCell?.colId ?? '', endCell?.colId ?? '');
|
|
379
|
+
const dataSelected = [];
|
|
380
|
+
rowSelectIds.forEach(rowId => {
|
|
381
|
+
const row = allRows.find(r => r.id === rowId);
|
|
382
|
+
if (!row) return;
|
|
383
|
+
const rowData = [];
|
|
384
|
+
colSelectIds.forEach(colId => {
|
|
385
|
+
const cellll = row.getVisibleCells().find(c => c.column.id === colId);
|
|
386
|
+
const value = cellll?.getValue();
|
|
387
|
+
rowData.push(value !== undefined ? value : '');
|
|
388
|
+
});
|
|
389
|
+
dataSelected.push(rowData);
|
|
390
|
+
});
|
|
391
|
+
const copyRows = flattenData('children', dataSource).filter(it => rowSelectIds.includes(it[rowKey]));
|
|
392
|
+
// const copyRows = flattenData('children', originData).filter((it) => rowSelectIds.includes(it[rowKey]))
|
|
393
|
+
|
|
394
|
+
let newRange;
|
|
395
|
+
if ((startRowIndex ?? 0) < (pasteRangeState.startRowIndex ?? 0)) {
|
|
396
|
+
// kéo xuóng
|
|
397
|
+
setRangeState?.(getSelectedCellMatrix(table, startCell, endPasteCell));
|
|
398
|
+
newRange = ctrlKey ? addRowsDownWithCtrl(dataSelected, rowPasteIds.length) : addRowsDown(dataSelected, rowPasteIds.length);
|
|
399
|
+
} else {
|
|
400
|
+
// kéo lên
|
|
401
|
+
setStartCell?.(endCell);
|
|
402
|
+
setRangeState?.(getSelectedCellMatrix(table, endCell, endPasteCell));
|
|
403
|
+
newRange = ctrlKey ? addRowsUpWithCtrl(dataSelected, rowPasteIds.length) : addRowsUp(dataSelected, rowPasteIds.length);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// Cập nhật data mới
|
|
407
|
+
const newData = flattenArray([...dataSource]);
|
|
408
|
+
const pastedRows = [];
|
|
409
|
+
newRange.addedRows.forEach((rowValues, rowIndex1) => {
|
|
410
|
+
const targetRow = pasteState.startRowIndex + rowIndex1;
|
|
411
|
+
|
|
412
|
+
// Nếu vượt quá số dòng hiện có, thêm dòng mới
|
|
413
|
+
if (targetRow >= newData.length) {
|
|
414
|
+
newData.push({
|
|
415
|
+
id: undefined,
|
|
416
|
+
rowId: newGuid()
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
rowValues.forEach((cellValue, colIndex1) => {
|
|
420
|
+
const targetCol = startColIndex + colIndex1;
|
|
421
|
+
if (targetCol >= tmpCols.length) {
|
|
422
|
+
// Không vượt quá số cột
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
const columnKey = tmpCols[targetCol].id;
|
|
426
|
+
const disable = !isEditable(tmpCols[targetCol].columnDef.meta, record);
|
|
427
|
+
if (!disable) {
|
|
428
|
+
newData[targetRow] = {
|
|
429
|
+
...newData[targetRow],
|
|
430
|
+
[columnKey]: typeof cellValue === 'string' ? cellValue.trim() : cellValue
|
|
431
|
+
};
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
// Lưu dòng được paste
|
|
436
|
+
pastedRows.push(newData[targetRow]);
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
// return
|
|
440
|
+
|
|
441
|
+
const rsFilterData = updateOrInsert(flattenArray([...dataSource]), newData);
|
|
442
|
+
// const rsFilterData = updateOrInsert(flattenArray([...originData]), newData)
|
|
443
|
+
|
|
444
|
+
const rs = unFlattenData(rsFilterData);
|
|
445
|
+
const dta = unGroupData(rs, originData);
|
|
446
|
+
triggerPaste?.(pastedRows, colPasteds, dta, copyRows);
|
|
447
|
+
|
|
448
|
+
// // setRangeState?.(getSelectedCellMatrix(table, startCell, endPasteCell))
|
|
449
|
+
|
|
450
|
+
setEndCell?.(endPasteCell);
|
|
451
|
+
setEndPasteCell?.(undefined);
|
|
452
|
+
setStartPasteCell?.(undefined);
|
|
453
|
+
setRangePasteState?.(undefined);
|
|
454
|
+
};
|
|
455
|
+
const triggerPointPaste = (pasteState, cellStart, cellEnd, ctrlKey) => {
|
|
456
|
+
const tmpCols = table.getVisibleLeafColumns();
|
|
457
|
+
const rowPasteIds = getRowIdsBetween(table, cellStart?.rowId ?? '', cellEnd?.rowId ?? '');
|
|
458
|
+
const colPasteds = getColIdsBetween(table, cellStart?.colId ?? '', cellEnd?.colId ?? '');
|
|
459
|
+
const rowSelectIds = getRowIdsBetween(table, startCell?.rowId ?? '', endCell?.rowId ?? '');
|
|
460
|
+
const colSelectIds = getColIdsBetween(table, startCell?.colId ?? '', endCell?.colId ?? '');
|
|
461
|
+
const dataSelected = [];
|
|
462
|
+
rowSelectIds.forEach(rowId => {
|
|
463
|
+
const row = allRows.find(r => r.id === rowId);
|
|
464
|
+
if (!row) return;
|
|
465
|
+
const rowData = [];
|
|
466
|
+
colSelectIds.forEach(colId => {
|
|
467
|
+
const cellll = row.getVisibleCells().find(c => c.column.id === colId);
|
|
468
|
+
const value = cellll?.getValue();
|
|
469
|
+
rowData.push(value !== undefined ? value : '');
|
|
470
|
+
});
|
|
471
|
+
dataSelected.push(rowData);
|
|
472
|
+
});
|
|
473
|
+
const copyRows = flattenData('children', dataSource).filter(it => rowSelectIds.includes(it[rowKey]));
|
|
474
|
+
|
|
475
|
+
// kéo xuóng
|
|
476
|
+
// setRangeState?.(getSelectedCellMatrix(table, startCell, endPasteCell))
|
|
477
|
+
const newRange = ctrlKey ? addRowsDownWithCtrl(dataSelected, rowPasteIds.length) : addRowsDown(dataSelected, rowPasteIds.length);
|
|
478
|
+
|
|
479
|
+
// Cập nhật data mới
|
|
480
|
+
const newData = flattenArray([...dataSource]);
|
|
481
|
+
const pastedRows = [];
|
|
482
|
+
newRange.addedRows.forEach((rowValues, rowIndex1) => {
|
|
483
|
+
const targetRow = pasteState.startRowIndex + rowIndex1;
|
|
484
|
+
|
|
485
|
+
// Nếu vượt quá số dòng hiện có, thêm dòng mới
|
|
486
|
+
// if (targetRow >= newData.length) {
|
|
487
|
+
|
|
488
|
+
// newData.push({ id: undefined, rowId: newGuid() })
|
|
489
|
+
// }
|
|
490
|
+
|
|
491
|
+
rowValues.forEach((cellValue, colIndex1) => {
|
|
492
|
+
const targetCol = startColIndex + colIndex1;
|
|
493
|
+
if (targetCol >= tmpCols.length) {
|
|
494
|
+
// Không vượt quá số cột
|
|
495
|
+
return;
|
|
496
|
+
}
|
|
497
|
+
const columnKey = tmpCols[targetCol].id;
|
|
498
|
+
newData[targetRow] = {
|
|
499
|
+
...newData[targetRow],
|
|
500
|
+
[columnKey]: typeof cellValue === 'string' ? cellValue.trim() : cellValue
|
|
501
|
+
};
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
// Lưu dòng được paste
|
|
505
|
+
pastedRows.push(newData[targetRow]);
|
|
506
|
+
});
|
|
507
|
+
const rsFilterData = updateOrInsert(flattenArray([...originData]), newData);
|
|
508
|
+
const rs = unFlattenData(rsFilterData);
|
|
509
|
+
triggerPaste?.(pastedRows, colPasteds, rs, copyRows);
|
|
510
|
+
};
|
|
511
|
+
function handleMouseEnter(e, rowId, colId) {
|
|
512
|
+
if (e.target.firstChild?.clientWidth < e.target.firstChild?.scrollWidth) {
|
|
513
|
+
setIsOpenTooltip(true);
|
|
514
|
+
}
|
|
515
|
+
if (isSelecting) {
|
|
516
|
+
setEndCell?.({
|
|
517
|
+
rowId,
|
|
518
|
+
colId
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
if (isPasting) {
|
|
522
|
+
const absRowIndex = table.getRowModel().flatRows.findIndex(it => it.id === cell.row.id);
|
|
523
|
+
if ((startRowIndex ?? 0) > absRowIndex) {
|
|
524
|
+
// kéo lên
|
|
525
|
+
|
|
526
|
+
const startRowPaste = allRows.find(it => it.index === (startRowIndex ?? 0) - 1);
|
|
527
|
+
setStartPasteCell?.({
|
|
528
|
+
colId: startCell?.colId ?? '',
|
|
529
|
+
rowId: startRowPaste?.id ?? ''
|
|
530
|
+
});
|
|
531
|
+
setEndPasteCell?.({
|
|
532
|
+
colId: endCell?.colId ?? '',
|
|
533
|
+
rowId
|
|
534
|
+
});
|
|
535
|
+
setRangePasteState?.(getSelectedCellMatrix(table, {
|
|
536
|
+
colId: startCell?.colId ?? '',
|
|
537
|
+
rowId: startRowPaste?.id ?? ''
|
|
538
|
+
}, {
|
|
539
|
+
colId: endCell?.colId ?? '',
|
|
540
|
+
rowId
|
|
541
|
+
}));
|
|
542
|
+
}
|
|
543
|
+
if ((startRowIndex ?? 0) < absRowIndex) {
|
|
544
|
+
// kéo xuống
|
|
545
|
+
|
|
546
|
+
const findIndex = allRows.findIndex(it => it.id === endCell?.rowId);
|
|
547
|
+
const startRowPaste = allRows[findIndex + 1];
|
|
548
|
+
setStartPasteCell?.({
|
|
549
|
+
colId: startCell?.colId ?? '',
|
|
550
|
+
rowId: startRowPaste?.id ?? ''
|
|
551
|
+
});
|
|
552
|
+
setEndPasteCell?.({
|
|
553
|
+
colId: endCell?.colId ?? '',
|
|
554
|
+
rowId
|
|
555
|
+
});
|
|
556
|
+
setRangePasteState?.(getSelectedCellMatrix(table, {
|
|
557
|
+
colId: startCell?.colId ?? '',
|
|
558
|
+
rowId: startRowPaste?.id ?? ''
|
|
559
|
+
}, {
|
|
560
|
+
colId: endCell?.colId ?? '',
|
|
561
|
+
rowId
|
|
562
|
+
}));
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
const handlePointDoubleClick = e => {
|
|
567
|
+
e.preventDefault();
|
|
568
|
+
e.stopPropagation();
|
|
569
|
+
const rowEnd = table.getRowModel().flatRows[table.getRowModel().flatRows.length - 1];
|
|
570
|
+
const cellEnd = {
|
|
571
|
+
rowId: rowEnd.id,
|
|
572
|
+
colId: cell.column.id
|
|
573
|
+
};
|
|
574
|
+
const currentRowId = allRows.findIndex(it => it.id === cell.row.id);
|
|
575
|
+
const pasteStartRow = allRows[currentRowId + 1];
|
|
576
|
+
const cellStart = {
|
|
577
|
+
rowId: pasteStartRow.id,
|
|
578
|
+
colId: endCell?.colId ?? ''
|
|
579
|
+
};
|
|
580
|
+
const selectState = getSelectedCellMatrix(table, startCell, cellEnd);
|
|
581
|
+
const selectPasteState = getSelectedCellMatrix(table, cellStart, cellEnd);
|
|
582
|
+
setRangeState?.(selectState);
|
|
583
|
+
setEndCell?.(cellEnd);
|
|
584
|
+
triggerPointPaste(selectPasteState, cellStart, cellEnd, e.ctrlKey);
|
|
585
|
+
};
|
|
586
|
+
function handleMouseUp(e) {
|
|
587
|
+
setIsSelecting?.(false);
|
|
588
|
+
setIsPasting?.(false);
|
|
589
|
+
const selectState = getSelectedCellMatrix(table, startCell, endCell);
|
|
590
|
+
const selectPasteState = getSelectedCellMatrix(table, startPasteCell, endPasteCell);
|
|
591
|
+
if (endPasteCell && endCell?.rowId !== endPasteCell?.rowId && isPasting) {
|
|
592
|
+
// triggerDragPaste(selectPasteState, e.ctrlKey)
|
|
593
|
+
|
|
594
|
+
if (groupColumns && groupColumns.length > 0) {
|
|
595
|
+
triggerDragPasteGroup(selectPasteState, e.ctrlKey);
|
|
596
|
+
} else {
|
|
597
|
+
triggerDragPaste(selectPasteState, e.ctrlKey);
|
|
598
|
+
}
|
|
599
|
+
} else {
|
|
600
|
+
// if ( endCell?.rowId !== rowId || endCell?.colId !== colId) {
|
|
601
|
+
// setRangeState?.(selectState)
|
|
602
|
+
// }
|
|
603
|
+
|
|
604
|
+
if (!isObjEqual(rangeState, selectState)) {
|
|
605
|
+
setRangeState?.(selectState);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
// setRangePasteState(selectPasteState)
|
|
610
|
+
}
|
|
611
|
+
const handleEdit = (e, isKeyDown) => {
|
|
612
|
+
setEditingKey?.(record[rowKey]);
|
|
613
|
+
// setTooltipContent('')
|
|
614
|
+
|
|
615
|
+
handleCellClick?.(rowNumber, record, columnMeta, record[rowKey], record[columnMeta.field ?? '']);
|
|
616
|
+
reset?.();
|
|
617
|
+
|
|
618
|
+
// const formattedRecord = { ...record };
|
|
619
|
+
|
|
620
|
+
if (!isObjEmpty(record)) {
|
|
621
|
+
Object.entries(record).forEach(([name, value]) => {
|
|
622
|
+
setValue?.(name, value);
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
if (isKeyDown) {
|
|
626
|
+
if (e.key === 'Enter' || editType === 'date' || e.type === 'dblclick') {} else {
|
|
627
|
+
setValue(columnMeta.field, editType === 'numeric' ? !isNaN(Number(e.key)) ? Number(e.key) : '' : e.key);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
if (editType === 'select') {
|
|
631
|
+
|
|
632
|
+
// setSearchValue(e.key)
|
|
633
|
+
// setOpen(true)
|
|
634
|
+
}
|
|
635
|
+
if (focusedCell?.rowId) {
|
|
636
|
+
setTimeout(() => {
|
|
637
|
+
// const input = document.querySelector(`.ui-rc-table-row .cell-editing[data-row-index="${startSelectedCells.current.row}"].cell-editing[data-col-index="${startSelectedCells.current.col}"] input`) as HTMLInputElement
|
|
638
|
+
// const textarea = document.querySelector(`.ui-rc-table-row .cell-editing[data-row-index="${rowNumber}"].cell-editing[data-col-index="${startSelectedCells.current.col}"] textarea`) as any
|
|
639
|
+
const textarea = document.querySelector(`.ui-rc-grid-row .cell-editing[data-row-key="${focusedCell.rowId}"].cell-editing[data-col-key="${focusedCell.colId}"] textarea`);
|
|
640
|
+
// const select = document.querySelector(`div.cell-editing[tabindex="${startSelectedCells.current.col}"] .ant-select-selection-search input`)
|
|
641
|
+
|
|
642
|
+
if (textarea) {
|
|
643
|
+
textarea.focus();
|
|
644
|
+
textarea.setSelectionRange(textarea.value.length, textarea.value.length);
|
|
645
|
+
}
|
|
646
|
+
// if (input) {
|
|
647
|
+
// input.focus()
|
|
648
|
+
// }
|
|
649
|
+
|
|
650
|
+
// if (select) {
|
|
651
|
+
// // @ts-ignore
|
|
652
|
+
// select.searchValue = e.key
|
|
653
|
+
// // @ts-ignore
|
|
654
|
+
// select.focus()
|
|
655
|
+
// }
|
|
656
|
+
}, 10);
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
function handleKeyDown(e, rowId, colId) {
|
|
660
|
+
if (e.key === 'Tab') {
|
|
661
|
+
e.preventDefault();
|
|
662
|
+
const allCols = table.getVisibleLeafColumns();
|
|
663
|
+
const currentColIndex = table.getColumn(colId)?.getIndex() ?? 0;
|
|
664
|
+
const nextCol = allCols[currentColIndex + 1];
|
|
665
|
+
if (nextCol) {
|
|
666
|
+
setFocusedCell?.({
|
|
667
|
+
rowId,
|
|
668
|
+
colId: nextCol.id
|
|
669
|
+
});
|
|
670
|
+
setStartCell?.({
|
|
671
|
+
rowId,
|
|
672
|
+
colId: nextCol.id
|
|
673
|
+
});
|
|
674
|
+
setEndCell?.({
|
|
675
|
+
rowId,
|
|
676
|
+
colId: nextCol.id
|
|
677
|
+
});
|
|
678
|
+
setRangeState?.(getSelectedCellMatrix(table, {
|
|
679
|
+
rowId,
|
|
680
|
+
colId: nextCol.id
|
|
681
|
+
}, {
|
|
682
|
+
rowId,
|
|
683
|
+
colId: nextCol.id
|
|
684
|
+
}));
|
|
685
|
+
columnVirtualizer.scrollToIndex(nextCol.getIndex(), {
|
|
686
|
+
align: 'center'
|
|
687
|
+
});
|
|
688
|
+
} else {
|
|
689
|
+
// Nếu là cột cuối cùng, có thể nhảy xuống dòng tiếp theo
|
|
690
|
+
|
|
691
|
+
const currentRowIndex = allRows.findIndex(r => r.id === rowId);
|
|
692
|
+
const nextRow = allRows[currentRowIndex + 1];
|
|
693
|
+
const nextRowCol = allCols[2];
|
|
694
|
+
if (nextRow) {
|
|
695
|
+
setFocusedCell?.({
|
|
696
|
+
rowId: nextRow.id,
|
|
697
|
+
colId: nextRowCol.id
|
|
698
|
+
}); // sang dòng, cột đầu
|
|
699
|
+
|
|
700
|
+
setStartCell?.({
|
|
701
|
+
rowId: nextRow.id,
|
|
702
|
+
colId: nextRowCol.id
|
|
703
|
+
});
|
|
704
|
+
setEndCell?.({
|
|
705
|
+
rowId: nextRow.id,
|
|
706
|
+
colId: nextRowCol.id
|
|
707
|
+
});
|
|
708
|
+
setRangeState?.(getSelectedCellMatrix(table, {
|
|
709
|
+
rowId: nextRow.id,
|
|
710
|
+
colId: nextRowCol.id
|
|
711
|
+
}, {
|
|
712
|
+
rowId: nextRow.id,
|
|
713
|
+
colId: nextRowCol.id
|
|
714
|
+
}));
|
|
715
|
+
columnVirtualizer.scrollToIndex(nextRowCol.getIndex());
|
|
716
|
+
rowVirtualizer.scrollToIndex(nextRow.index, {
|
|
717
|
+
align: 'auto'
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
if (e.key === 'ArrowRight') {
|
|
724
|
+
e.preventDefault();
|
|
725
|
+
e.stopPropagation();
|
|
726
|
+
const allCols = table.getVisibleLeafColumns().filter(it => !nonActionColumn.includes(it.id));
|
|
727
|
+
const currentColIndex = allCols.findIndex(it => it.id === cell.column.id);
|
|
728
|
+
const nextCol = allCols[currentColIndex + 1];
|
|
729
|
+
if (nextCol) {
|
|
730
|
+
setFocusedCell?.({
|
|
731
|
+
rowId,
|
|
732
|
+
colId: nextCol.id
|
|
733
|
+
});
|
|
734
|
+
setStartCell?.({
|
|
735
|
+
rowId,
|
|
736
|
+
colId: nextCol.id
|
|
737
|
+
});
|
|
738
|
+
setEndCell?.({
|
|
739
|
+
rowId,
|
|
740
|
+
colId: nextCol.id
|
|
741
|
+
});
|
|
742
|
+
setRangeState?.(getSelectedCellMatrix(table, {
|
|
743
|
+
rowId,
|
|
744
|
+
colId: nextCol.id
|
|
745
|
+
}, {
|
|
746
|
+
rowId,
|
|
747
|
+
colId: nextCol.id
|
|
748
|
+
}));
|
|
749
|
+
columnVirtualizer.scrollToIndex(nextCol.getIndex(), {
|
|
750
|
+
align: 'center'
|
|
751
|
+
});
|
|
752
|
+
}
|
|
753
|
+
return;
|
|
754
|
+
}
|
|
755
|
+
if (e.key === 'ArrowLeft') {
|
|
756
|
+
e.preventDefault();
|
|
757
|
+
const allCols = table.getVisibleLeafColumns().filter(it => !nonActionColumn.includes(it.id));
|
|
758
|
+
|
|
759
|
+
// const currentColIndex = table.getColumn(colId)?.getIndex() ?? 0;
|
|
760
|
+
const currentColIndex = allCols.findIndex(it => it.id === cell.column.id);
|
|
761
|
+
const nextCol = allCols[currentColIndex - 1];
|
|
762
|
+
if (nextCol) {
|
|
763
|
+
setFocusedCell?.({
|
|
764
|
+
rowId,
|
|
765
|
+
colId: nextCol.id
|
|
766
|
+
});
|
|
767
|
+
setStartCell?.({
|
|
768
|
+
rowId,
|
|
769
|
+
colId: nextCol.id
|
|
770
|
+
});
|
|
771
|
+
setEndCell?.({
|
|
772
|
+
rowId,
|
|
773
|
+
colId: nextCol.id
|
|
774
|
+
});
|
|
775
|
+
setRangeState?.(getSelectedCellMatrix(table, {
|
|
776
|
+
rowId,
|
|
777
|
+
colId: nextCol.id
|
|
778
|
+
}, {
|
|
779
|
+
rowId,
|
|
780
|
+
colId: nextCol.id
|
|
781
|
+
}));
|
|
782
|
+
columnVirtualizer.scrollToIndex(nextCol.getIndex(), {
|
|
783
|
+
align: 'center'
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
return;
|
|
787
|
+
}
|
|
788
|
+
if (e.key === 'ArrowDown') {
|
|
789
|
+
// e.preventDefault()
|
|
790
|
+
// e.stopPropagation()
|
|
791
|
+
|
|
792
|
+
let nextRowIndex = rowNumber + 1;
|
|
793
|
+
let nextRow = table.getRowModel().rows[nextRowIndex];
|
|
794
|
+
|
|
795
|
+
// Nếu nextRow có children và chưa được expand, thì tìm tiếp dòng tiếp theo
|
|
796
|
+
while (nextRow && nextRow.subRows && nextRow.subRows.length > 0) {
|
|
797
|
+
nextRowIndex++;
|
|
798
|
+
nextRow = table.getRowModel().rows[nextRowIndex];
|
|
799
|
+
}
|
|
800
|
+
if (nextRow) {
|
|
801
|
+
const nextRowId = nextRow.id;
|
|
802
|
+
setFocusedCell?.({
|
|
803
|
+
rowId: nextRowId,
|
|
804
|
+
colId
|
|
805
|
+
});
|
|
806
|
+
setStartCell?.({
|
|
807
|
+
rowId: nextRowId,
|
|
808
|
+
colId
|
|
809
|
+
});
|
|
810
|
+
setEndCell?.({
|
|
811
|
+
rowId: nextRowId,
|
|
812
|
+
colId
|
|
813
|
+
});
|
|
814
|
+
setRangeState?.(getSelectedCellMatrix(table, {
|
|
815
|
+
rowId: nextRowId,
|
|
816
|
+
colId
|
|
817
|
+
}, {
|
|
818
|
+
rowId: nextRowId,
|
|
819
|
+
colId
|
|
820
|
+
}));
|
|
821
|
+
|
|
822
|
+
// columnVirtualizer.scrollToIndex(nextCol.getIndex(), { align: 'center' })
|
|
823
|
+
// rowVirtualizer.scrollToIndex(nextRow.index, { align: 'center' })
|
|
824
|
+
|
|
825
|
+
const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextRowId}"]`);
|
|
826
|
+
const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
|
|
827
|
+
if (cellFocus) {
|
|
828
|
+
cellFocus.focus();
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
return;
|
|
832
|
+
}
|
|
833
|
+
if (e.key === 'ArrowUp') {
|
|
834
|
+
// e.preventDefault()
|
|
835
|
+
// e.stopPropagation()
|
|
836
|
+
|
|
837
|
+
// const nextRow = table.getRowModel().rows[rowNumber - 1]
|
|
838
|
+
|
|
839
|
+
let prevRowIndex = rowNumber - 1;
|
|
840
|
+
let prevRow = table.getRowModel().rows[prevRowIndex];
|
|
841
|
+
|
|
842
|
+
// Nếu nextRow có children và chưa được expand, thì tìm tiếp dòng tiếp theo
|
|
843
|
+
while (prevRow && prevRow.subRows && prevRow.subRows.length > 0) {
|
|
844
|
+
prevRowIndex--;
|
|
845
|
+
prevRow = table.getRowModel().rows[prevRowIndex];
|
|
846
|
+
}
|
|
847
|
+
if (prevRow) {
|
|
848
|
+
const nextRowId = prevRow.id;
|
|
849
|
+
setFocusedCell?.({
|
|
850
|
+
rowId: nextRowId,
|
|
851
|
+
colId
|
|
852
|
+
});
|
|
853
|
+
setStartCell?.({
|
|
854
|
+
rowId: nextRowId,
|
|
855
|
+
colId
|
|
856
|
+
});
|
|
857
|
+
setEndCell?.({
|
|
858
|
+
rowId: nextRowId,
|
|
859
|
+
colId
|
|
860
|
+
});
|
|
861
|
+
setRangeState?.(getSelectedCellMatrix(table, {
|
|
862
|
+
rowId: nextRowId,
|
|
863
|
+
colId
|
|
864
|
+
}, {
|
|
865
|
+
rowId: nextRowId,
|
|
866
|
+
colId
|
|
867
|
+
}));
|
|
868
|
+
const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${nextRowId}"]`);
|
|
869
|
+
const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
|
|
870
|
+
if (cellFocus) {
|
|
871
|
+
cellFocus.focus();
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
return;
|
|
875
|
+
}
|
|
876
|
+
if (e.key === 'Delete') {
|
|
877
|
+
handleDeleteContent?.();
|
|
878
|
+
return;
|
|
879
|
+
}
|
|
880
|
+
if (e.key === 'Enter') {
|
|
881
|
+
e.preventDefault();
|
|
882
|
+
e.stopPropagation();
|
|
883
|
+
handleEdit(e, true);
|
|
884
|
+
return;
|
|
885
|
+
}
|
|
886
|
+
if (e.key.length === 1 && !e.ctrlKey) {
|
|
887
|
+
e.preventDefault();
|
|
888
|
+
e.stopPropagation();
|
|
889
|
+
handleEdit(e, true);
|
|
890
|
+
// setValue(cell.column.id, editType === 'numeric' ? (!isNaN(Number(e.key)) ? Number(e.key) : '') : e.key)
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
function handleMouseDown(rowId, colId) {
|
|
894
|
+
setIsSelecting?.(true);
|
|
895
|
+
if (startCell?.rowId !== rowId || startCell?.colId !== colId || endCell?.rowId !== rowId || endCell?.colId !== colId) {
|
|
896
|
+
setStartCell?.({
|
|
897
|
+
rowId,
|
|
898
|
+
colId
|
|
899
|
+
});
|
|
900
|
+
setEndCell?.({
|
|
901
|
+
rowId,
|
|
902
|
+
colId
|
|
903
|
+
});
|
|
904
|
+
setRangeState?.(getSelectedCellMatrix(table, {
|
|
905
|
+
rowId,
|
|
906
|
+
colId
|
|
907
|
+
}, {
|
|
908
|
+
rowId,
|
|
909
|
+
colId
|
|
910
|
+
}));
|
|
911
|
+
}
|
|
912
|
+
if (focusedCell?.rowId !== cell.row.id || focusedCell?.colId !== cell.column.id) {
|
|
913
|
+
setFocusedCell?.({
|
|
914
|
+
rowId: cell.row.id,
|
|
915
|
+
colId: cell.column.id
|
|
916
|
+
});
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
const handleMouseDownIndex = rowId => {
|
|
920
|
+
setIsSelecting?.(true);
|
|
921
|
+
const allColumns = table.getVisibleLeafColumns().filter(it => !nonActionColumn.includes(it.id));
|
|
922
|
+
const firstCOlSpin = findFirst(allColumns);
|
|
923
|
+
const startCol = allColumns[0].id;
|
|
924
|
+
const endCol = allColumns[allColumns.length - 1].id;
|
|
925
|
+
setStartCell?.({
|
|
926
|
+
rowId,
|
|
927
|
+
colId: startCol
|
|
928
|
+
});
|
|
929
|
+
setEndCell?.({
|
|
930
|
+
rowId,
|
|
931
|
+
colId: endCol
|
|
932
|
+
});
|
|
933
|
+
if (firstCOlSpin) {
|
|
934
|
+
setFocusedCell?.({
|
|
935
|
+
rowId: cell.row.id,
|
|
936
|
+
colId: firstCOlSpin.id
|
|
937
|
+
});
|
|
938
|
+
} else {
|
|
939
|
+
const firstCOlVisible = allColumns[0];
|
|
940
|
+
setFocusedCell?.({
|
|
941
|
+
rowId: cell.row.id,
|
|
942
|
+
colId: firstCOlVisible.id
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
setRangeState?.(getSelectedCellMatrix(table, {
|
|
946
|
+
rowId,
|
|
947
|
+
colId: startCol
|
|
948
|
+
}, {
|
|
949
|
+
rowId,
|
|
950
|
+
colId: endCol
|
|
951
|
+
}));
|
|
952
|
+
};
|
|
953
|
+
const handleMouseEnterIndex = rowId => {
|
|
954
|
+
if (isSelecting) {
|
|
955
|
+
const allColumns = table.getVisibleLeafColumns().filter(it => !nonActionColumn.includes(it.id));
|
|
956
|
+
|
|
957
|
+
// const firstCOl = findFirst(allColumns)
|
|
958
|
+
|
|
959
|
+
// const startCol = allColumns[0].id
|
|
960
|
+
const endCol = allColumns[allColumns.length - 1].id;
|
|
961
|
+
|
|
962
|
+
// setStartCell?.({ rowId, colId: startCol });
|
|
963
|
+
setEndCell?.({
|
|
964
|
+
rowId,
|
|
965
|
+
colId: endCol
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
};
|
|
969
|
+
const handleMouseUpIndex = () => {
|
|
970
|
+
setIsSelecting?.(false);
|
|
971
|
+
// setIsPasting?.(false);
|
|
972
|
+
|
|
973
|
+
const selectState = getSelectedCellMatrix(table, startCell, endCell);
|
|
974
|
+
if (!isObjEqual(rangeState, selectState)) {
|
|
975
|
+
setRangeState?.(selectState);
|
|
976
|
+
}
|
|
977
|
+
};
|
|
978
|
+
if (cell.column.id === "#") {
|
|
979
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
980
|
+
key: cell.id,
|
|
981
|
+
className: classNames(`${prefix}-grid-cell ${prefix}-grid-cell-index editable`, {
|
|
982
|
+
[`${prefix}-grid-cell-ellipsis`]: true,
|
|
983
|
+
[`${prefix}-grid-cell-fix-left-last`]: isLastLeftPinnedColumn,
|
|
984
|
+
[`${prefix}-grid-cell-fix-right-first`]: isFirstRightPinnedColumn,
|
|
985
|
+
[`${prefix}-grid-cell-text-center`]: columnMeta?.textAlign === 'center',
|
|
986
|
+
[`${prefix}-grid-cell-text-right`]: columnMeta?.textAlign === 'right',
|
|
987
|
+
// [`${prefix}-grid-cell-index-selected`]: rowRange?.includes(cell.row.id),
|
|
988
|
+
[`${prefix}-grid-cell-index-selected`]: selectRowIds?.includes(cell.row.id)
|
|
989
|
+
}),
|
|
990
|
+
style: {
|
|
991
|
+
display: 'flex',
|
|
992
|
+
height: '36px',
|
|
993
|
+
userSelect: 'none',
|
|
994
|
+
width: cell.column.getSize(),
|
|
995
|
+
// flexBasis: cell.column.getSize(),
|
|
996
|
+
minWidth: cell.column.getSize(),
|
|
997
|
+
// flex: 1,
|
|
998
|
+
// maxWidth: cell.column.getSize(),
|
|
999
|
+
...getCommonPinningStyles(cell.column)
|
|
1000
|
+
},
|
|
1001
|
+
onMouseDown: () => {
|
|
1002
|
+
if (record[rowKey] === editingKey) {
|
|
1003
|
+
setFocusedCell?.({
|
|
1004
|
+
rowId: cell.row.id,
|
|
1005
|
+
colId: cell.column.id
|
|
1006
|
+
});
|
|
1007
|
+
} else {
|
|
1008
|
+
handleMouseDownIndex(cell.row.id);
|
|
1009
|
+
if (editingKey) {
|
|
1010
|
+
setTimeout(() => {
|
|
1011
|
+
setEditingKey?.('');
|
|
1012
|
+
reset?.();
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
// reset?.()
|
|
1017
|
+
}
|
|
1018
|
+
},
|
|
1019
|
+
onMouseEnter: () => {
|
|
1020
|
+
handleMouseEnterIndex(cell.row.id);
|
|
1021
|
+
},
|
|
1022
|
+
onMouseUp: handleMouseUpIndex
|
|
1023
|
+
// onMouseUp={() => {
|
|
1024
|
+
|
|
1025
|
+
// handleMouseUpIndex()
|
|
1026
|
+
|
|
1027
|
+
// }}
|
|
1028
|
+
}, cell.column.getIndex() === expandIconColumnIndex && isDataTree && /*#__PURE__*/React.createElement("div", {
|
|
1029
|
+
className: "ui-rc-table-row-expand-trigger",
|
|
1030
|
+
style: {
|
|
1031
|
+
paddingLeft: `${cell.row.depth * 25}px`
|
|
1032
|
+
}
|
|
1033
|
+
}, /*#__PURE__*/React.createElement("div", null, cell.row.getCanExpand() ? /*#__PURE__*/React.createElement("button", {
|
|
1034
|
+
// onClick: row.getToggleExpandedHandler(),
|
|
1035
|
+
onClick: e => {
|
|
1036
|
+
e.stopPropagation();
|
|
1037
|
+
e.preventDefault();
|
|
1038
|
+
const keys = Object.keys(expanded);
|
|
1039
|
+
// @ts-ignore
|
|
1040
|
+
const tmp = {
|
|
1041
|
+
...expanded
|
|
1042
|
+
};
|
|
1043
|
+
if (keys.includes(cell.row.id)) {
|
|
1044
|
+
delete tmp[cell.row.id];
|
|
1045
|
+
setExpanded(tmp);
|
|
1046
|
+
} else {
|
|
1047
|
+
setExpanded(old => ({
|
|
1048
|
+
...old,
|
|
1049
|
+
[cell.row.id]: true
|
|
1050
|
+
}));
|
|
1051
|
+
}
|
|
1052
|
+
},
|
|
1053
|
+
style: {
|
|
1054
|
+
cursor: "pointer"
|
|
1055
|
+
},
|
|
1056
|
+
className: "ui-rc-table-row-expand"
|
|
1057
|
+
}, cell.row.getIsExpanded() ? /*#__PURE__*/React.createElement("span", {
|
|
1058
|
+
className: "ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-expanded"
|
|
1059
|
+
}) : /*#__PURE__*/React.createElement("span", {
|
|
1060
|
+
className: "ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-collapsed"
|
|
1061
|
+
})) : /*#__PURE__*/React.createElement("span", {
|
|
1062
|
+
className: "ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-spaced"
|
|
1063
|
+
}))), renderCellIndex({
|
|
1064
|
+
parrents,
|
|
1065
|
+
cell,
|
|
1066
|
+
pagination
|
|
1067
|
+
}));
|
|
1068
|
+
}
|
|
1069
|
+
if (cell.column.id === "command") {
|
|
1070
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
1071
|
+
key: cell.id,
|
|
1072
|
+
className: classNames(`${prefix}-grid-cell ${prefix}-grid-cell-command editable`, {
|
|
1073
|
+
[`${prefix}-grid-cell-ellipsis`]: true,
|
|
1074
|
+
[`${prefix}-grid-cell-fix-left-last`]: isLastLeftPinnedColumn,
|
|
1075
|
+
[`${prefix}-grid-cell-fix-right-first`]: isFirstRightPinnedColumn,
|
|
1076
|
+
[`${prefix}-grid-cell-text-center`]: columnMeta?.textAlign === 'center',
|
|
1077
|
+
[`${prefix}-grid-cell-text-right`]: columnMeta?.textAlign === 'right'
|
|
1078
|
+
}),
|
|
1079
|
+
style: {
|
|
1080
|
+
display: 'flex',
|
|
1081
|
+
height: '36px',
|
|
1082
|
+
width: cell.column.getSize(),
|
|
1083
|
+
minWidth: cell.column.getSize(),
|
|
1084
|
+
// flex: 1,
|
|
1085
|
+
// maxWidth: cell.column.getSize(),
|
|
1086
|
+
...getCommonPinningStyles(cell.column)
|
|
1087
|
+
}
|
|
1088
|
+
}, renderCommand({
|
|
1089
|
+
cell,
|
|
1090
|
+
commandClick,
|
|
1091
|
+
id,
|
|
1092
|
+
data: originData
|
|
1093
|
+
}));
|
|
1094
|
+
}
|
|
1095
|
+
if (cell.column.id === "selection_column") {
|
|
1096
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
1097
|
+
key: cell.id,
|
|
1098
|
+
className: classNames(`${prefix}-grid-cell ${prefix}-grid-cell-selection editable`, {
|
|
1099
|
+
[`${prefix}-grid-cell-ellipsis`]: true,
|
|
1100
|
+
[`${prefix}-grid-cell-fix-left-last`]: isLastLeftPinnedColumn,
|
|
1101
|
+
[`${prefix}-grid-cell-fix-right-first`]: isFirstRightPinnedColumn,
|
|
1102
|
+
[`${prefix}-grid-cell-text-center`]: columnMeta?.textAlign === 'center',
|
|
1103
|
+
[`${prefix}-grid-cell-text-right`]: columnMeta?.textAlign === 'right'
|
|
1104
|
+
}),
|
|
1105
|
+
style: {
|
|
1106
|
+
display: 'flex',
|
|
1107
|
+
height: '36px',
|
|
1108
|
+
width: cell.column.getSize(),
|
|
1109
|
+
minWidth: cell.column.getSize(),
|
|
1110
|
+
// flex: 1,
|
|
1111
|
+
// maxWidth: cell.column.getSize(),
|
|
1112
|
+
...getCommonPinningStyles(cell.column)
|
|
1113
|
+
}
|
|
1114
|
+
}, cell.column.id === "selection_column" && renderSelection({
|
|
1115
|
+
cell,
|
|
1116
|
+
table,
|
|
1117
|
+
selectionSettings,
|
|
1118
|
+
setIsSelectionChange,
|
|
1119
|
+
expanded,
|
|
1120
|
+
isDataTree,
|
|
1121
|
+
setExpanded,
|
|
1122
|
+
expandIconColumnIndex,
|
|
1123
|
+
isSelectionChange
|
|
1124
|
+
}));
|
|
1125
|
+
}
|
|
1126
|
+
const handleChange = () => {
|
|
1127
|
+
const currentRowIndex = allRows.findIndex(r => r.id === editingKey);
|
|
1128
|
+
const formState = getValues();
|
|
1129
|
+
const itemState = getValues(cell.column.id);
|
|
1130
|
+
const prevState = record[cell.column.id];
|
|
1131
|
+
const newState = itemState;
|
|
1132
|
+
if (newState !== prevState) {
|
|
1133
|
+
handleCellChange?.({
|
|
1134
|
+
key: cell.row.id,
|
|
1135
|
+
field: cell.column.id,
|
|
1136
|
+
record: formState,
|
|
1137
|
+
prevState,
|
|
1138
|
+
newState,
|
|
1139
|
+
option: newState,
|
|
1140
|
+
indexCol: cell.column.getIndex(),
|
|
1141
|
+
indexRow: currentRowIndex,
|
|
1142
|
+
type: 'blur'
|
|
1143
|
+
});
|
|
1144
|
+
} else {}
|
|
1145
|
+
};
|
|
1146
|
+
const handleChangeAndCreateRow = () => {
|
|
1147
|
+
const currentRowIndex = allRows.findIndex(r => r.id === editingKey);
|
|
1148
|
+
const formState = getValues();
|
|
1149
|
+
const itemState = getValues(cell.column.id);
|
|
1150
|
+
const prevState = record[cell.column.id];
|
|
1151
|
+
const newState = itemState;
|
|
1152
|
+
if (newState !== prevState) {
|
|
1153
|
+
// vừa cell change + add new row
|
|
1154
|
+
handleCellChangeAndAddRow?.({
|
|
1155
|
+
key: cell.row.id,
|
|
1156
|
+
field: cell.column.id,
|
|
1157
|
+
record: formState,
|
|
1158
|
+
prevState,
|
|
1159
|
+
newState,
|
|
1160
|
+
option: newState,
|
|
1161
|
+
indexCol: cell.column.getIndex(),
|
|
1162
|
+
indexRow: currentRowIndex,
|
|
1163
|
+
type: 'blur'
|
|
1164
|
+
});
|
|
1165
|
+
} else {
|
|
1166
|
+
// chỉ add new row
|
|
1167
|
+
|
|
1168
|
+
const newRowId = newGuid();
|
|
1169
|
+
handleAddMulti?.({}, 1, newRowId);
|
|
1170
|
+
setFocusedCell?.({
|
|
1171
|
+
rowId: newRowId,
|
|
1172
|
+
colId: cell.column.id
|
|
1173
|
+
});
|
|
1174
|
+
setStartCell?.({
|
|
1175
|
+
rowId: newRowId,
|
|
1176
|
+
colId: cell.column.id
|
|
1177
|
+
});
|
|
1178
|
+
setEndCell?.({
|
|
1179
|
+
rowId: newRowId,
|
|
1180
|
+
colId: cell.column.id
|
|
1181
|
+
});
|
|
1182
|
+
setTimeout(() => {
|
|
1183
|
+
setRangeState?.(getSelectedCellMatrix(table, {
|
|
1184
|
+
rowId: newRowId,
|
|
1185
|
+
colId: cell.column.id
|
|
1186
|
+
}, {
|
|
1187
|
+
rowId: newRowId,
|
|
1188
|
+
colId: cell.column.id
|
|
1189
|
+
}));
|
|
1190
|
+
});
|
|
1191
|
+
setTimeout(() => {
|
|
1192
|
+
const row = document.querySelector(`.ui-rc-grid-row[data-row-key="${newRowId}"]`);
|
|
1193
|
+
const cellFocus = row?.querySelector('.ui-rc-grid-cell:not(.ui-rc-grid-cell-selection)');
|
|
1194
|
+
if (cellFocus) {
|
|
1195
|
+
cellFocus.scrollIntoView({
|
|
1196
|
+
behavior: "smooth",
|
|
1197
|
+
block: "start"
|
|
1198
|
+
});
|
|
1199
|
+
cellFocus.focus();
|
|
1200
|
+
}
|
|
1201
|
+
}, 100);
|
|
1202
|
+
}
|
|
1203
|
+
};
|
|
1204
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
1205
|
+
key: cell.id,
|
|
1206
|
+
ref: el => {
|
|
1207
|
+
if (focusedCell?.rowId === cell.row.id && focusedCell?.colId === cell.column.id && !isEditing) {
|
|
1208
|
+
el?.focus();
|
|
1209
|
+
}
|
|
1210
|
+
},
|
|
1211
|
+
tabIndex: focusedCell?.rowId === cell.row.id && focusedCell?.colId === cell.column.id ? 0 : -1,
|
|
1212
|
+
"data-col-index": colIndex,
|
|
1213
|
+
"data-row-index": rowNumber,
|
|
1214
|
+
"data-col-key": cell.column.id,
|
|
1215
|
+
"data-row-key": cell.row.id,
|
|
1216
|
+
"data-tooltip-id": `${id}-tooltip-content`,
|
|
1217
|
+
"data-tooltip-delay-show": 500,
|
|
1218
|
+
"data-tooltip-html": isEditing && message ? message : rowError && rowError[cell.column.id]?.field === cell.column.id ? rowError[cell.column.id].message : ReactDOMServer.renderToStaticMarkup( /*#__PURE__*/React.createElement(React.Fragment, null, tooltipContent)),
|
|
1219
|
+
className: classNames(`${prefix}-grid-cell cell-editable editable `, {
|
|
1220
|
+
[`${prefix}-grid-cell-ellipsis`]: true,
|
|
1221
|
+
'cell-editing': isEditing,
|
|
1222
|
+
// disable: !isEditable(cell.column.columnDef.meta as any, record),
|
|
1223
|
+
disable: !canEdit,
|
|
1224
|
+
isValid: !isEditing && rowError && rowError[cell.column.id]?.field === cell.column.id,
|
|
1225
|
+
[`${prefix}-grid-cell-selected`]: isCellSelected,
|
|
1226
|
+
'cell-border-bottom': !isEditing && isInRange && isBottom,
|
|
1227
|
+
'cell-border-right': !isEditing && isInRange && isRight,
|
|
1228
|
+
'cell-border-top': !isEditing && isInRange && isTop,
|
|
1229
|
+
'cell-border-left': !isEditing && isInRange && isLeft,
|
|
1230
|
+
'cell-paste-border-bottom': isInRangePaste && isBottomPaste && (pasteRangeState.endRowIndex ?? 0) > (endRowIndex ?? 0),
|
|
1231
|
+
'cell-paste-border-right': isInRangePaste && isRightPaste,
|
|
1232
|
+
'cell-paste-border-top': isInRangePaste && isTopPaste && (pasteRangeState.endRowIndex ?? 0) < (endRowIndex ?? 0),
|
|
1233
|
+
'cell-paste-border-left': isInRangePaste && isLeftPaste,
|
|
1234
|
+
[`${prefix}-grid-cell-fix-left-last`]: isLastLeftPinnedColumn,
|
|
1235
|
+
[`${prefix}-grid-cell-fix-right-first`]: isFirstRightPinnedColumn,
|
|
1236
|
+
[`${prefix}-grid-cell-text-center`]: columnMeta?.textAlign === 'center',
|
|
1237
|
+
[`${prefix}-grid-cell-text-right`]: columnMeta?.textAlign === 'right' || columnMeta.type === 'number'
|
|
1238
|
+
}),
|
|
1239
|
+
style: {
|
|
1240
|
+
display: 'flex',
|
|
1241
|
+
width: cell.column.getSize(),
|
|
1242
|
+
minWidth: cell.column.getSize(),
|
|
1243
|
+
// flex: 1,
|
|
1244
|
+
// maxWidth: cell.column.getSize(),
|
|
1245
|
+
height: '36px',
|
|
1246
|
+
...getCommonPinningStyles(cell.column),
|
|
1247
|
+
cursor: isPasting ? 'crosshair' : undefined
|
|
1248
|
+
},
|
|
1249
|
+
onMouseDown: () => {
|
|
1250
|
+
if (record[rowKey] === editingKey) {
|
|
1251
|
+
setFocusedCell?.({
|
|
1252
|
+
rowId: cell.row.id,
|
|
1253
|
+
colId: cell.column.id
|
|
1254
|
+
});
|
|
1255
|
+
if (canEdit) {
|
|
1256
|
+
handleCellClick?.(rowNumber, record, columnMeta, record[rowKey], record[columnMeta.field ?? '']);
|
|
1257
|
+
}
|
|
1258
|
+
} else {
|
|
1259
|
+
handleMouseDown(cell.row.id, cell.column.id);
|
|
1260
|
+
if (editingKey) {
|
|
1261
|
+
setTimeout(() => {
|
|
1262
|
+
setEditingKey?.('');
|
|
1263
|
+
reset?.();
|
|
1264
|
+
});
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
},
|
|
1268
|
+
onMouseEnter: e => handleMouseEnter(e, cell.row.id, cell.column.id),
|
|
1269
|
+
onMouseUp: e => handleMouseUp(e),
|
|
1270
|
+
onKeyDown: e => {
|
|
1271
|
+
if (!isEditing) {
|
|
1272
|
+
handleKeyDown(e, cell.row.id, cell.column.id);
|
|
1273
|
+
} else {
|
|
1274
|
+
if (e.shiftKey && e.key === 'Enter') {
|
|
1275
|
+
e.preventDefault();
|
|
1276
|
+
e.stopPropagation();
|
|
1277
|
+
} else {
|
|
1278
|
+
if (e.key === 'Enter') {
|
|
1279
|
+
e.preventDefault();
|
|
1280
|
+
e.stopPropagation();
|
|
1281
|
+
const currentRowIndex = allRows.findIndex(r => r.id === cell.row.id);
|
|
1282
|
+
const nextRow = allRows[currentRowIndex + 1];
|
|
1283
|
+
if (nextRow) {
|
|
1284
|
+
setFocusedCell?.({
|
|
1285
|
+
rowId: nextRow.id,
|
|
1286
|
+
colId: cell.column.id
|
|
1287
|
+
});
|
|
1288
|
+
setStartCell?.({
|
|
1289
|
+
rowId: nextRow.id,
|
|
1290
|
+
colId: cell.column.id
|
|
1291
|
+
});
|
|
1292
|
+
setEndCell?.({
|
|
1293
|
+
rowId: nextRow.id,
|
|
1294
|
+
colId: cell.column.id
|
|
1295
|
+
});
|
|
1296
|
+
setRangeState?.(getSelectedCellMatrix(table, {
|
|
1297
|
+
rowId: nextRow.id,
|
|
1298
|
+
colId: cell.column.id
|
|
1299
|
+
}, {
|
|
1300
|
+
rowId: nextRow.id,
|
|
1301
|
+
colId: cell.column.id
|
|
1302
|
+
}));
|
|
1303
|
+
rowVirtualizer.scrollToIndex(nextRow.index, {
|
|
1304
|
+
align: 'center'
|
|
1305
|
+
});
|
|
1306
|
+
handleChange();
|
|
1307
|
+
} else {
|
|
1308
|
+
handleChangeAndCreateRow();
|
|
1309
|
+
}
|
|
1310
|
+
setEditingKey?.('');
|
|
1311
|
+
reset?.();
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
},
|
|
1316
|
+
onDoubleClick: e => {
|
|
1317
|
+
if (!canEdit) {
|
|
1318
|
+
e.stopPropagation();
|
|
1319
|
+
e.preventDefault();
|
|
1320
|
+
return;
|
|
1321
|
+
}
|
|
1322
|
+
if (!(record[rowKey] === editingKey && canEdit)) {
|
|
1323
|
+
handleEdit(e);
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
}, isEditing && canEdit ? /*#__PURE__*/React.createElement(EditableCell, {
|
|
1327
|
+
cellEditing: {},
|
|
1328
|
+
column: cell.column.columnDef.meta,
|
|
1329
|
+
dataIndex: cell.column.id,
|
|
1330
|
+
editType: getEditType(cell.column.columnDef.meta, record),
|
|
1331
|
+
indexCol: cell.column.getIndex(),
|
|
1332
|
+
indexRow: cell.row.index,
|
|
1333
|
+
record: record
|
|
1334
|
+
// rowKey={rowKey}
|
|
1335
|
+
}) : /*#__PURE__*/React.createElement("div", {
|
|
1336
|
+
className: classNames('ui-rc_cell-content', {
|
|
1337
|
+
'select-cell': ['select', 'selectTable', 'asyncSelect'].includes(getEditType(columnMeta, record))
|
|
1338
|
+
})
|
|
1339
|
+
}, cell.column.getIndex() === expandIconColumnIndex && isDataTree && /*#__PURE__*/React.createElement("div", {
|
|
1340
|
+
className: "ui-rc-table-row-expand-trigger",
|
|
1341
|
+
style: {
|
|
1342
|
+
paddingLeft: `${cell.row.depth * 25}px`
|
|
1343
|
+
}
|
|
1344
|
+
}, /*#__PURE__*/React.createElement("div", null, cell.row.getCanExpand() ? /*#__PURE__*/React.createElement("button", {
|
|
1345
|
+
// onClick: row.getToggleExpandedHandler(),
|
|
1346
|
+
onClick: e => {
|
|
1347
|
+
e.stopPropagation();
|
|
1348
|
+
e.preventDefault();
|
|
1349
|
+
const keys = Object.keys(expanded);
|
|
1350
|
+
// @ts-ignore
|
|
1351
|
+
const tmp = {
|
|
1352
|
+
...expanded
|
|
1353
|
+
};
|
|
1354
|
+
if (keys.includes(cell.row.id)) {
|
|
1355
|
+
delete tmp[cell.row.id];
|
|
1356
|
+
setExpanded(tmp);
|
|
1357
|
+
} else {
|
|
1358
|
+
setExpanded(old => ({
|
|
1359
|
+
...old,
|
|
1360
|
+
[cell.row.id]: true
|
|
1361
|
+
}));
|
|
1362
|
+
}
|
|
1363
|
+
},
|
|
1364
|
+
style: {
|
|
1365
|
+
cursor: "pointer"
|
|
1366
|
+
},
|
|
1367
|
+
className: "ui-rc-table-row-expand"
|
|
1368
|
+
}, cell.row.getIsExpanded() ? /*#__PURE__*/React.createElement("span", {
|
|
1369
|
+
className: "ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-expanded"
|
|
1370
|
+
}) : /*#__PURE__*/React.createElement("span", {
|
|
1371
|
+
className: "ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-collapsed"
|
|
1372
|
+
})) : /*#__PURE__*/React.createElement("span", {
|
|
1373
|
+
className: "ui-rc-table-row-expand-icon ui-rc-table-row-expand-icon-spaced"
|
|
1374
|
+
}))), flexRender(cell.column.columnDef.cell, cell.getContext()), (editType === 'select' || editType === 'selectTable' || editType === 'asyncSelect' || editType === 'treeSelect') && canEdit && /*#__PURE__*/React.createElement("span", {
|
|
1375
|
+
className: 'caret-down',
|
|
1376
|
+
onClick: e => {
|
|
1377
|
+
handleEdit(e);
|
|
1378
|
+
// setEditingKey?.(cell.row.id)
|
|
1379
|
+
}
|
|
1380
|
+
})), !isSelecting && !isEditing && rowRange &&
|
|
1381
|
+
// rowNumber === rangeState?.endRowIndex &&
|
|
1382
|
+
cell.row.id === rowRange[rowRange?.length - 1] && cell.column.getIndex() === rangeState?.endColIndex && /*#__PURE__*/React.createElement("div", {
|
|
1383
|
+
className: 'dragging-point',
|
|
1384
|
+
onMouseDown: e => {
|
|
1385
|
+
e.preventDefault();
|
|
1386
|
+
e.stopPropagation();
|
|
1387
|
+
if (e.button === 0) {
|
|
1388
|
+
setIsPasting?.(true);
|
|
1389
|
+
}
|
|
1390
|
+
},
|
|
1391
|
+
onDoubleClick: handlePointDoubleClick
|
|
1392
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
1393
|
+
className: 'dot-point'
|
|
1394
|
+
})), !isEditing && rowError && rowError[cell.column.id]?.field === cell.column.id && /*#__PURE__*/React.createElement("span", {
|
|
1395
|
+
className: "isValid"
|
|
1396
|
+
}));
|
|
1397
|
+
};
|
|
1398
|
+
export default TableBodyCellEdit;
|