@arim-aisdc/public-components 2.3.16 → 2.3.17
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/dist/components/TableMax/TableBody/components/Total.d.ts +7 -0
- package/dist/components/TableMax/TableBody/components/Total.js +63 -0
- package/dist/components/TableMax/TableBody/index.d.ts +4 -1
- package/dist/components/TableMax/TableBody/index.js +20 -7
- package/dist/components/TableMax/TableBody/index.less +8 -4
- package/dist/components/TableMax/TableHeader/Cell.js +16 -32
- package/dist/components/TableMax/TableHeader/index.less +31 -8
- package/dist/components/TableMax/TableMax.js +9 -9
- package/dist/components/TableMax/components/ColumnSort/customSortFns.d.ts +8 -8
- package/dist/components/TableMax/hooks/useColumnResize.d.ts +9 -0
- package/dist/components/TableMax/hooks/useColumnResize.js +162 -0
- package/dist/components/TableMax/type.d.ts +2 -0
- package/package.json +1 -1
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
import { getPinningStyle } from "../../TableHeader/utils";
|
|
8
|
+
import "../../TableBody/index.less";
|
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
+
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
11
|
+
export var Total = function Total(_ref) {
|
|
12
|
+
var table = _ref.table,
|
|
13
|
+
totalDatas = _ref.totalDatas,
|
|
14
|
+
shadowColumnInfo = _ref.shadowColumnInfo,
|
|
15
|
+
rowHeight = _ref.rowHeight;
|
|
16
|
+
var leftLastColumnId = shadowColumnInfo.leftLastColumnId,
|
|
17
|
+
rightFirstColumnId = shadowColumnInfo.rightFirstColumnId;
|
|
18
|
+
var footerGroups = table.getFooterGroups();
|
|
19
|
+
|
|
20
|
+
// 公共样式对象,避免重复创建
|
|
21
|
+
var rowStyle = {
|
|
22
|
+
width: '100%',
|
|
23
|
+
position: 'sticky',
|
|
24
|
+
bottom: '-0.5px',
|
|
25
|
+
left: '0px',
|
|
26
|
+
zIndex: 200
|
|
27
|
+
};
|
|
28
|
+
var cellWrapperStyle = {
|
|
29
|
+
boxSizing: 'border-box',
|
|
30
|
+
borderTop: '1px solid var(--tableColor2)',
|
|
31
|
+
borderBottom: '1px solid var(--tableColor2)',
|
|
32
|
+
height: "100%"
|
|
33
|
+
};
|
|
34
|
+
return /*#__PURE__*/_jsx(_Fragment, {
|
|
35
|
+
children: footerGroups.map(function (footerGroup) {
|
|
36
|
+
var id = footerGroup.id,
|
|
37
|
+
headers = footerGroup.headers;
|
|
38
|
+
return /*#__PURE__*/_jsx("tr", {
|
|
39
|
+
className: "tbody-tr",
|
|
40
|
+
style: rowStyle,
|
|
41
|
+
children: headers.map(function (header) {
|
|
42
|
+
var headerId = header.id,
|
|
43
|
+
colSpan = header.colSpan;
|
|
44
|
+
var pinningStyle = getPinningStyle(header, table);
|
|
45
|
+
var cellStyle = _objectSpread(_objectSpread({}, pinningStyle), {}, {
|
|
46
|
+
height: "".concat(rowHeight - 1, "px")
|
|
47
|
+
});
|
|
48
|
+
var cellClassNames = ['tbody-tr-td', headerId === leftLastColumnId && 'thead-tr-th-cell-fix-left-last', headerId === rightFirstColumnId && 'thead-tr-th-cell-fix-right-first'].filter(Boolean).join(' ');
|
|
49
|
+
return /*#__PURE__*/_jsx("td", {
|
|
50
|
+
colSpan: colSpan,
|
|
51
|
+
style: cellStyle,
|
|
52
|
+
className: cellClassNames,
|
|
53
|
+
children: /*#__PURE__*/_jsx("div", {
|
|
54
|
+
className: "table-max-cell-wrapper",
|
|
55
|
+
style: cellWrapperStyle,
|
|
56
|
+
children: totalDatas === null || totalDatas === void 0 ? void 0 : totalDatas[headerId]
|
|
57
|
+
})
|
|
58
|
+
}, headerId);
|
|
59
|
+
})
|
|
60
|
+
}, id);
|
|
61
|
+
})
|
|
62
|
+
});
|
|
63
|
+
};
|
|
@@ -71,6 +71,9 @@ type TableBodyPropsType = {
|
|
|
71
71
|
tableTooltip: boolean;
|
|
72
72
|
compactMode: boolean;
|
|
73
73
|
onEditValueChange?: (field: string, value: any, extra?: any) => void;
|
|
74
|
+
hasTotalRow?: boolean;
|
|
75
|
+
totalDatas?: any[];
|
|
74
76
|
};
|
|
75
|
-
declare const TableBody: ({ tableBodyRef, table, tableId, theme, reorderRow, rowSelectedId, setRowSelectedId, rowHighLightId, setRowHighLightId, selectedRowChange, onSelectChange, canSelection, selectionWithoutChecked, tableContainerWidth, selectedRowDragging, setSelectedRowDragging, canRowDrag, rowKey, loading, rowClassName, cellClassName, rowStyle, getCellProps, rowHeight, renderSubComponent, onRowMouseEnter, onRowMouseLeave, onRowMouseClick, onRowMouseDoubleClick, disableDragRowIds, selectRowWhenClick, datas, canEditRowWhenDClick, editingRowId, handleEditRowWhenDClick, dragBeforeStart, shadowColumnInfo, getContextMenu, onClickContextMenu, getRowHoverTipConfig, tableTooltip, compactMode, onEditValueChange, }: TableBodyPropsType) => import("react/jsx-runtime").JSX.Element;
|
|
77
|
+
declare const TableBody: ({ tableBodyRef, table, tableId, theme, reorderRow, rowSelectedId, setRowSelectedId, rowHighLightId, setRowHighLightId, selectedRowChange, onSelectChange, canSelection, selectionWithoutChecked, tableContainerWidth, selectedRowDragging, setSelectedRowDragging, canRowDrag, rowKey, loading, rowClassName, cellClassName, rowStyle, getCellProps, rowHeight, renderSubComponent, onRowMouseEnter, onRowMouseLeave, onRowMouseClick, onRowMouseDoubleClick, disableDragRowIds, selectRowWhenClick, datas, canEditRowWhenDClick, editingRowId, handleEditRowWhenDClick, dragBeforeStart, shadowColumnInfo, getContextMenu, onClickContextMenu, getRowHoverTipConfig, tableTooltip, compactMode, onEditValueChange, hasTotalRow, totalDatas }: TableBodyPropsType) => import("react/jsx-runtime").JSX.Element;
|
|
76
78
|
export default TableBody;
|
|
79
|
+
export declare const MemoizedTableBody: ({ tableBodyRef, table, tableId, theme, reorderRow, rowSelectedId, setRowSelectedId, rowHighLightId, setRowHighLightId, selectedRowChange, onSelectChange, canSelection, selectionWithoutChecked, tableContainerWidth, selectedRowDragging, setSelectedRowDragging, canRowDrag, rowKey, loading, rowClassName, cellClassName, rowStyle, getCellProps, rowHeight, renderSubComponent, onRowMouseEnter, onRowMouseLeave, onRowMouseClick, onRowMouseDoubleClick, disableDragRowIds, selectRowWhenClick, datas, canEditRowWhenDClick, editingRowId, handleEditRowWhenDClick, dragBeforeStart, shadowColumnInfo, getContextMenu, onClickContextMenu, getRowHoverTipConfig, tableTooltip, compactMode, onEditValueChange, hasTotalRow, totalDatas }: TableBodyPropsType) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -18,16 +18,17 @@ import { CustomDragLayer } from "../components/CustomDragerLayer";
|
|
|
18
18
|
// import RowContent from "../components/RowContent";
|
|
19
19
|
import { DropSide } from "../type";
|
|
20
20
|
import { events, useEventBus } from "../../..";
|
|
21
|
-
import { useCallback, useMemo, useState } from 'react';
|
|
21
|
+
import React, { useCallback, useMemo, useState } from 'react';
|
|
22
22
|
import { createPortal } from 'react-dom';
|
|
23
23
|
import { useConfig } from "../../ConfigProvider";
|
|
24
24
|
import Empty from "../../Empty";
|
|
25
25
|
import Row from "./Row";
|
|
26
26
|
import ContextMenu from "./contextMenu/ContextMenu";
|
|
27
27
|
import "./index.less";
|
|
28
|
+
import { Total } from "./components/Total";
|
|
28
29
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
29
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
30
30
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
31
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
31
32
|
var TableBody = function TableBody(_ref) {
|
|
32
33
|
var _headerGroups, _table$getRowModel$ro2;
|
|
33
34
|
var tableBodyRef = _ref.tableBodyRef,
|
|
@@ -72,7 +73,9 @@ var TableBody = function TableBody(_ref) {
|
|
|
72
73
|
getRowHoverTipConfig = _ref.getRowHoverTipConfig,
|
|
73
74
|
tableTooltip = _ref.tableTooltip,
|
|
74
75
|
compactMode = _ref.compactMode,
|
|
75
|
-
onEditValueChange = _ref.onEditValueChange
|
|
76
|
+
onEditValueChange = _ref.onEditValueChange,
|
|
77
|
+
hasTotalRow = _ref.hasTotalRow,
|
|
78
|
+
totalDatas = _ref.totalDatas;
|
|
76
79
|
var _useConfig = useConfig(),
|
|
77
80
|
root = _useConfig.root;
|
|
78
81
|
var headerGroups = table.getHeaderGroups();
|
|
@@ -379,7 +382,7 @@ var TableBody = function TableBody(_ref) {
|
|
|
379
382
|
return !loading && datas.length !== 0 && ((_table$getRowModel$ro = table.getRowModel().rows) === null || _table$getRowModel$ro === void 0 ? void 0 : _table$getRowModel$ro.length) !== 0;
|
|
380
383
|
}, [loading, datas.length, (_table$getRowModel$ro2 = table.getRowModel().rows) === null || _table$getRowModel$ro2 === void 0 ? void 0 : _table$getRowModel$ro2.length]);
|
|
381
384
|
|
|
382
|
-
// console.log('
|
|
385
|
+
// console.log('rowHeight :>>', rowHeight);
|
|
383
386
|
|
|
384
387
|
return (
|
|
385
388
|
/*#__PURE__*/
|
|
@@ -409,9 +412,16 @@ var TableBody = function TableBody(_ref) {
|
|
|
409
412
|
width: size
|
|
410
413
|
}, header.id);
|
|
411
414
|
})
|
|
412
|
-
}), /*#__PURE__*/
|
|
415
|
+
}), /*#__PURE__*/_jsxs("tbody", {
|
|
413
416
|
id: "table-max-tableBody-tbody-".concat(tableId),
|
|
414
|
-
children: TBodyContent()
|
|
417
|
+
children: [TBodyContent(), /*#__PURE__*/_jsx(_Fragment, {
|
|
418
|
+
children: hasTotalRow && /*#__PURE__*/_jsx(Total, {
|
|
419
|
+
table: table,
|
|
420
|
+
totalDatas: totalDatas,
|
|
421
|
+
shadowColumnInfo: shadowColumnInfo,
|
|
422
|
+
rowHeight: rowHeight
|
|
423
|
+
})
|
|
424
|
+
})]
|
|
415
425
|
})]
|
|
416
426
|
})
|
|
417
427
|
}) : LoadingAndEmptyContent(), /*#__PURE__*/_jsx(ContextMenu, _objectSpread(_objectSpread({}, contextMenuData), {}, {
|
|
@@ -421,4 +431,7 @@ var TableBody = function TableBody(_ref) {
|
|
|
421
431
|
})
|
|
422
432
|
);
|
|
423
433
|
};
|
|
424
|
-
export default TableBody;
|
|
434
|
+
export default TableBody;
|
|
435
|
+
export var MemoizedTableBody = /*#__PURE__*/React.memo(TableBody, function (prev, next) {
|
|
436
|
+
return prev.table.options.data === next.table.options.data;
|
|
437
|
+
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
table {
|
|
2
2
|
table-layout: fixed;
|
|
3
|
-
|
|
4
|
-
td {
|
|
5
|
-
|
|
6
|
-
}
|
|
3
|
+
border-collapse: collapse;
|
|
4
|
+
// td {
|
|
5
|
+
// border: 0;
|
|
6
|
+
// }
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
.tbody {
|
|
@@ -186,6 +186,10 @@ table {
|
|
|
186
186
|
pointer-events: none;
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
+
.thead-tr-th-cell {
|
|
190
|
+
background: @globalColor0;
|
|
191
|
+
}
|
|
192
|
+
|
|
189
193
|
.table-max-row-tooltip-wrapper {
|
|
190
194
|
left: 50% !important;
|
|
191
195
|
transform: translateX(-50%) !important;
|
|
@@ -17,14 +17,14 @@ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToAr
|
|
|
17
17
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
18
18
|
import { flexRender } from '@tanstack/react-table';
|
|
19
19
|
import { Tooltip } from 'antd';
|
|
20
|
-
import { useMemo
|
|
20
|
+
import { useMemo } from 'react';
|
|
21
21
|
import { useDrag, useDrop } from 'react-dnd';
|
|
22
|
-
import { createPortal } from 'react-dom';
|
|
23
22
|
import { useConfig } from "../../ConfigProvider";
|
|
24
23
|
import { ColumnType } from "../TableMax";
|
|
25
24
|
import { ColumnFilter } from "../components/ColumnFilterV2";
|
|
26
25
|
import Sort from "../components/ColumnSort";
|
|
27
26
|
import "./index.less";
|
|
27
|
+
import { useColumnResize } from "../hooks/useColumnResize";
|
|
28
28
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
29
29
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
30
30
|
var reorderColumn = function reorderColumn(draggedColumnId, targetColumnId, columnOrder) {
|
|
@@ -32,7 +32,6 @@ var reorderColumn = function reorderColumn(draggedColumnId, targetColumnId, colu
|
|
|
32
32
|
return _toConsumableArray(columnOrder);
|
|
33
33
|
};
|
|
34
34
|
var Cell = function Cell(_ref) {
|
|
35
|
-
var _tableContentRef$curr;
|
|
36
35
|
var tableContentRef = _ref.tableContentRef,
|
|
37
36
|
header = _ref.header,
|
|
38
37
|
table = _ref.table,
|
|
@@ -81,33 +80,26 @@ var Cell = function Cell(_ref) {
|
|
|
81
80
|
var columns = useMemo(function () {
|
|
82
81
|
return columnDef.columns;
|
|
83
82
|
}, [header]);
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
|
|
84
|
+
// 使用自定义Hook
|
|
85
|
+
var _useColumnResize = useColumnResize({
|
|
86
|
+
header: header,
|
|
87
|
+
table: table,
|
|
88
|
+
tableContentRef: tableContentRef,
|
|
89
|
+
rootContainer: root
|
|
87
90
|
}),
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
setInitPosition = _useState2[1];
|
|
91
|
-
return /*#__PURE__*/_jsxs("div", {
|
|
91
|
+
handleResizeStart = _useColumnResize.handleResizeStart;
|
|
92
|
+
return /*#__PURE__*/_jsx("div", {
|
|
92
93
|
ref: function ref(node) {
|
|
93
94
|
dropRef(node);
|
|
94
|
-
dragRef(disableColumnDrag || cannotDragColumn.includes(header.column.id) || header.column.getIsPinned() ? null : node);
|
|
95
|
+
dragRef(disableColumnDrag || cannotDragColumn.includes(header.column.id) || header.column.getIsPinned() || header.column.getIsResizing() ? null : node);
|
|
95
96
|
},
|
|
96
|
-
children:
|
|
97
|
+
children: /*#__PURE__*/_jsxs("div", {
|
|
97
98
|
className: "cell-wapper ".concat(columns ? 'wapper-top-parent' : '', " table-max-header-cell-wrapper"),
|
|
98
99
|
ref: previewRef,
|
|
99
100
|
style: _objectSpread({
|
|
100
101
|
transform: header.column.parent || columns || !hasGroup ? 'translateY(0px)' : 'translateY(-20px)'
|
|
101
102
|
}, getHeaderCellProps === null || getHeaderCellProps === void 0 ? void 0 : getHeaderCellProps(columns)),
|
|
102
|
-
onMouseDown: function onMouseDown(e) {
|
|
103
|
-
var elem = tableContentRef === null || tableContentRef === void 0 ? void 0 : tableContentRef.current;
|
|
104
|
-
var clientRect = elem === null || elem === void 0 ? void 0 : elem.getBoundingClientRect();
|
|
105
|
-
var y = clientRect === null || clientRect === void 0 ? void 0 : clientRect.top;
|
|
106
|
-
setInitPosition({
|
|
107
|
-
x: e.clientX,
|
|
108
|
-
y: y
|
|
109
|
-
});
|
|
110
|
-
},
|
|
111
103
|
children: [/*#__PURE__*/_jsx("div", {
|
|
112
104
|
className: "cell-left",
|
|
113
105
|
onClick: header.column.getToggleSortingHandler(),
|
|
@@ -143,18 +135,10 @@ var Cell = function Cell(_ref) {
|
|
|
143
135
|
}) : null]
|
|
144
136
|
}) : null, /*#__PURE__*/_jsx("div", {
|
|
145
137
|
className: "cell-resize-handler ".concat(header.column.getIsResizing() ? 'column-is-resizing' : ''),
|
|
146
|
-
onMouseDown:
|
|
147
|
-
onTouchStart
|
|
138
|
+
onMouseDown: handleResizeStart
|
|
139
|
+
// onTouchStart={handleResizeStart}
|
|
148
140
|
})]
|
|
149
|
-
})
|
|
150
|
-
className: 'column-resizing-divide-line',
|
|
151
|
-
style: {
|
|
152
|
-
left: initPosition.x,
|
|
153
|
-
top: initPosition.y,
|
|
154
|
-
height: (_tableContentRef$curr = tableContentRef.current) === null || _tableContentRef$curr === void 0 ? void 0 : _tableContentRef$curr.clientHeight,
|
|
155
|
-
transform: "translateX(".concat(table.getState().columnSizingInfo.deltaOffset || 0, "px)")
|
|
156
|
-
}
|
|
157
|
-
}), root ? document.querySelector(root) : document.body) : null]
|
|
141
|
+
})
|
|
158
142
|
});
|
|
159
143
|
};
|
|
160
144
|
export default Cell;
|
|
@@ -42,6 +42,7 @@ table {
|
|
|
42
42
|
display: flex;
|
|
43
43
|
align-items: center;
|
|
44
44
|
justify-content: space-between;
|
|
45
|
+
height: 100%;
|
|
45
46
|
|
|
46
47
|
.cell-left-header {
|
|
47
48
|
display: -webkit-box;
|
|
@@ -76,6 +77,14 @@ table {
|
|
|
76
77
|
display: inline-block;
|
|
77
78
|
// opacity: 1;
|
|
78
79
|
}
|
|
80
|
+
&:hover {
|
|
81
|
+
.sort-flag {
|
|
82
|
+
display: flex;
|
|
83
|
+
}
|
|
84
|
+
.filter-icon {
|
|
85
|
+
display: inline-block;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
79
88
|
|
|
80
89
|
.cell-resize-handler {
|
|
81
90
|
position: absolute;
|
|
@@ -95,22 +104,29 @@ table {
|
|
|
95
104
|
top: 0%;
|
|
96
105
|
height: 100%;
|
|
97
106
|
z-index: 99999;
|
|
107
|
+
cursor: ew-resize;
|
|
98
108
|
}
|
|
99
109
|
}
|
|
100
110
|
|
|
111
|
+
.cell-resize-handler::after {
|
|
112
|
+
content: '';
|
|
113
|
+
position: absolute;
|
|
114
|
+
right: 0;
|
|
115
|
+
top: 0;
|
|
116
|
+
bottom: 0;
|
|
117
|
+
width: 5px;
|
|
118
|
+
cursor: ew-resize;
|
|
119
|
+
}
|
|
120
|
+
|
|
101
121
|
.column-resizer.column-is-resizing {
|
|
102
122
|
height: 60%;
|
|
103
123
|
top: 20%;
|
|
104
124
|
}
|
|
105
125
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
.filter-icon {
|
|
111
|
-
display: inline-block;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
114
130
|
}
|
|
115
131
|
|
|
116
132
|
.table-thead-tr:nth-last-child(2) {
|
|
@@ -227,3 +243,10 @@ table {
|
|
|
227
243
|
// background-color: #000;
|
|
228
244
|
background-color: green;
|
|
229
245
|
}
|
|
246
|
+
.column-resizing-divide-line {
|
|
247
|
+
will-change: transform;
|
|
248
|
+
backface-visibility: hidden;
|
|
249
|
+
transform: translate3d(0, 0, 0);
|
|
250
|
+
contain: strict;
|
|
251
|
+
cursor: ew-resize;
|
|
252
|
+
}
|
|
@@ -26,7 +26,7 @@ import dayjs from 'dayjs';
|
|
|
26
26
|
import { cloneDeep, debounce } from 'lodash';
|
|
27
27
|
import React, { useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
28
28
|
import { useConfig } from "../ConfigProvider";
|
|
29
|
-
import TableBody from "./TableBody";
|
|
29
|
+
import TableBody, { MemoizedTableBody } from "./TableBody";
|
|
30
30
|
import TableHeader from "./TableHeader";
|
|
31
31
|
import { InputType } from "./components/ColumnEdit";
|
|
32
32
|
import { setDefaultFilterFn } from "./components/ColumnFilterV2";
|
|
@@ -140,7 +140,7 @@ var TableMax = function TableMax(_ref) {
|
|
|
140
140
|
getCellProps = _ref.getCellProps,
|
|
141
141
|
getHeaderCellProps = _ref.getHeaderCellProps,
|
|
142
142
|
_ref$rowHeight = _ref.rowHeight,
|
|
143
|
-
rowHeight = _ref$rowHeight === void 0 ?
|
|
143
|
+
rowHeight = _ref$rowHeight === void 0 ? 42 : _ref$rowHeight,
|
|
144
144
|
_ref$defaultColumnFil = _ref.defaultColumnFilters,
|
|
145
145
|
defaultColumnFilters = _ref$defaultColumnFil === void 0 ? [] : _ref$defaultColumnFil,
|
|
146
146
|
getColumnFiltersData = _ref.getColumnFiltersData,
|
|
@@ -185,7 +185,9 @@ var TableMax = function TableMax(_ref) {
|
|
|
185
185
|
_ref$disableColumnDra = _ref.disableColumnDrag,
|
|
186
186
|
disableColumnDrag = _ref$disableColumnDra === void 0 ? false : _ref$disableColumnDra,
|
|
187
187
|
request = _ref.request,
|
|
188
|
-
onEditValueChange = _ref.onEditValueChange
|
|
188
|
+
onEditValueChange = _ref.onEditValueChange,
|
|
189
|
+
hasTotalRow = _ref.hasTotalRow,
|
|
190
|
+
totalDatas = _ref.totalDatas;
|
|
189
191
|
var tableMaxRef = useRef(null);
|
|
190
192
|
// 表格元素
|
|
191
193
|
var tableContentRef = useRef(null);
|
|
@@ -965,10 +967,6 @@ var TableMax = function TableMax(_ref) {
|
|
|
965
967
|
getPinShadowInfo();
|
|
966
968
|
}, [getPinShadowInfo]);
|
|
967
969
|
|
|
968
|
-
// useEffect(() => {
|
|
969
|
-
// console.log(table.getState().columnSizing, 111);
|
|
970
|
-
// }, [table.getState().columnSizing]);
|
|
971
|
-
|
|
972
970
|
// 获取展示阴影的列
|
|
973
971
|
var shadowColumnInfo = useMemo(function () {
|
|
974
972
|
var _pop, _shift;
|
|
@@ -1046,7 +1044,9 @@ var TableMax = function TableMax(_ref) {
|
|
|
1046
1044
|
getRowHoverTipConfig: getRowHoverTipConfig,
|
|
1047
1045
|
tableTooltip: tableTooltip,
|
|
1048
1046
|
compactMode: compactMode,
|
|
1049
|
-
onEditValueChange: onEditValueChange
|
|
1047
|
+
onEditValueChange: onEditValueChange,
|
|
1048
|
+
hasTotalRow: hasTotalRow,
|
|
1049
|
+
totalDatas: totalDatas
|
|
1050
1050
|
};
|
|
1051
1051
|
var changeCompactMode = function changeCompactMode() {
|
|
1052
1052
|
setCompactMode(!compactMode);
|
|
@@ -1198,7 +1198,7 @@ var TableMax = function TableMax(_ref) {
|
|
|
1198
1198
|
style: {
|
|
1199
1199
|
width: "100%"
|
|
1200
1200
|
},
|
|
1201
|
-
children: /*#__PURE__*/_jsx(TableBody, _objectSpread({}, tableBodyProps))
|
|
1201
|
+
children: table.getState().columnSizingInfo.isResizingColumn ? /*#__PURE__*/_jsx(MemoizedTableBody, _objectSpread({}, tableBodyProps)) : /*#__PURE__*/_jsx(TableBody, _objectSpread({}, tableBodyProps))
|
|
1202
1202
|
})]
|
|
1203
1203
|
})
|
|
1204
1204
|
}), pagination && /*#__PURE__*/_jsx("div", {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { TableMaxColumnType } from "../../type";
|
|
2
|
-
export declare const numberSortFn: (rowA: any, rowB: any, columnId: string) =>
|
|
3
|
-
export declare const stringSortFn: (rowA: any, rowB: any, columnId: string) =>
|
|
4
|
-
export declare const numberOrStringSortFn: (rowA: any, rowB: any, columnId: string) =>
|
|
5
|
-
export declare const timeSortFn: (rowA: any, rowB: any, columnId: string) =>
|
|
2
|
+
export declare const numberSortFn: (rowA: any, rowB: any, columnId: string) => 0 | 1 | -1;
|
|
3
|
+
export declare const stringSortFn: (rowA: any, rowB: any, columnId: string) => 0 | 1 | -1;
|
|
4
|
+
export declare const numberOrStringSortFn: (rowA: any, rowB: any, columnId: string) => 0 | 1 | -1;
|
|
5
|
+
export declare const timeSortFn: (rowA: any, rowB: any, columnId: string) => 0 | 1 | -1;
|
|
6
6
|
declare const customSortFns: {
|
|
7
|
-
numberSortFn: (rowA: any, rowB: any, columnId: string) =>
|
|
8
|
-
stringSortFn: (rowA: any, rowB: any, columnId: string) =>
|
|
9
|
-
timeSortFn: (rowA: any, rowB: any, columnId: string) =>
|
|
10
|
-
numberOrStringSortFn: (rowA: any, rowB: any, columnId: string) =>
|
|
7
|
+
numberSortFn: (rowA: any, rowB: any, columnId: string) => 0 | 1 | -1;
|
|
8
|
+
stringSortFn: (rowA: any, rowB: any, columnId: string) => 0 | 1 | -1;
|
|
9
|
+
timeSortFn: (rowA: any, rowB: any, columnId: string) => 0 | 1 | -1;
|
|
10
|
+
numberOrStringSortFn: (rowA: any, rowB: any, columnId: string) => 0 | 1 | -1;
|
|
11
11
|
};
|
|
12
12
|
export default customSortFns;
|
|
13
13
|
export type SortFnType = keyof typeof customSortFns | undefined;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Header, Table } from '@tanstack/react-table';
|
|
2
|
+
export declare const useColumnResize: <T>({ header, table, tableContentRef, rootContainer }: {
|
|
3
|
+
header: Header<T, unknown>;
|
|
4
|
+
table: Table<T>;
|
|
5
|
+
tableContentRef: React.RefObject<HTMLDivElement>;
|
|
6
|
+
rootContainer?: string;
|
|
7
|
+
}) => {
|
|
8
|
+
handleResizeStart: (e: React.MouseEvent) => void;
|
|
9
|
+
};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
// hooks/useColumnResize.ts
|
|
8
|
+
import { useEffect, useRef, useCallback } from 'react';
|
|
9
|
+
export var useColumnResize = function useColumnResize(_ref) {
|
|
10
|
+
var header = _ref.header,
|
|
11
|
+
table = _ref.table,
|
|
12
|
+
tableContentRef = _ref.tableContentRef,
|
|
13
|
+
rootContainer = _ref.rootContainer;
|
|
14
|
+
// DOM元素引用
|
|
15
|
+
var resizeLineRef = useRef(null);
|
|
16
|
+
var overlayRef = useRef(null);
|
|
17
|
+
|
|
18
|
+
// 状态和位置引用
|
|
19
|
+
var isResizingRef = useRef(false);
|
|
20
|
+
var startXRef = useRef(0);
|
|
21
|
+
var startWidthRef = useRef(0);
|
|
22
|
+
var containerHeightRef = useRef(0);
|
|
23
|
+
var rafIdRef = useRef(0);
|
|
24
|
+
var lastClientXRef = useRef(0); // 新增:记录最后的位置
|
|
25
|
+
|
|
26
|
+
// 初始化创建DOM元素
|
|
27
|
+
useEffect(function () {
|
|
28
|
+
var container = rootContainer ? document.querySelector(rootContainer) : document.body;
|
|
29
|
+
if (!container) return;
|
|
30
|
+
|
|
31
|
+
// 创建分割线
|
|
32
|
+
var resizeLine = document.createElement('div');
|
|
33
|
+
resizeLine.className = 'column-resizing-divide-line';
|
|
34
|
+
Object.assign(resizeLine.style, {
|
|
35
|
+
position: 'fixed',
|
|
36
|
+
pointerEvents: 'none',
|
|
37
|
+
zIndex: '1000',
|
|
38
|
+
display: 'none',
|
|
39
|
+
width: '1px',
|
|
40
|
+
backgroundColor: '#1890ff',
|
|
41
|
+
willChange: 'transform',
|
|
42
|
+
transition: 'none',
|
|
43
|
+
top: '0',
|
|
44
|
+
height: '0',
|
|
45
|
+
transform: 'translate3d(0,0,0)'
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// 创建遮罩层
|
|
49
|
+
var overlay = document.createElement('div');
|
|
50
|
+
overlay.className = 'column-resize-overlay';
|
|
51
|
+
Object.assign(overlay.style, {
|
|
52
|
+
position: 'fixed',
|
|
53
|
+
top: '0',
|
|
54
|
+
left: '0',
|
|
55
|
+
width: '100vw',
|
|
56
|
+
height: '100vh',
|
|
57
|
+
zIndex: '9998',
|
|
58
|
+
cursor: 'ew-resize',
|
|
59
|
+
display: 'none',
|
|
60
|
+
pointerEvents: 'auto',
|
|
61
|
+
backgroundColor: 'transparent'
|
|
62
|
+
});
|
|
63
|
+
container.appendChild(resizeLine);
|
|
64
|
+
container.appendChild(overlay);
|
|
65
|
+
resizeLineRef.current = resizeLine;
|
|
66
|
+
overlayRef.current = overlay;
|
|
67
|
+
return function () {
|
|
68
|
+
cancelAnimationFrame(rafIdRef.current);
|
|
69
|
+
if (resizeLine.parentNode) container.removeChild(resizeLine);
|
|
70
|
+
if (overlay.parentNode) container.removeChild(overlay);
|
|
71
|
+
};
|
|
72
|
+
}, [rootContainer]);
|
|
73
|
+
|
|
74
|
+
// 更新分割线位置
|
|
75
|
+
var updateResizeLinePosition = useCallback(function (x, height) {
|
|
76
|
+
if (!resizeLineRef.current) return;
|
|
77
|
+
lastClientXRef.current = x; // 更新最后的位置
|
|
78
|
+
resizeLineRef.current.style.transform = "translate3d(".concat(x, "px, 0, 0)");
|
|
79
|
+
resizeLineRef.current.style.height = "".concat(height, "px");
|
|
80
|
+
}, []);
|
|
81
|
+
|
|
82
|
+
// 处理拖动开始
|
|
83
|
+
var handleResizeStart = useCallback(function (e) {
|
|
84
|
+
e.preventDefault();
|
|
85
|
+
e.stopPropagation();
|
|
86
|
+
var elem = tableContentRef.current;
|
|
87
|
+
var clientRect = elem === null || elem === void 0 ? void 0 : elem.getBoundingClientRect();
|
|
88
|
+
var containerTop = (clientRect === null || clientRect === void 0 ? void 0 : clientRect.top) || 0;
|
|
89
|
+
var containerHeight = (clientRect === null || clientRect === void 0 ? void 0 : clientRect.height) || 0;
|
|
90
|
+
|
|
91
|
+
// 设置初始状态
|
|
92
|
+
isResizingRef.current = true;
|
|
93
|
+
startXRef.current = e.clientX;
|
|
94
|
+
startWidthRef.current = header.column.getSize();
|
|
95
|
+
containerHeightRef.current = containerHeight;
|
|
96
|
+
lastClientXRef.current = e.clientX;
|
|
97
|
+
|
|
98
|
+
// 显示并定位元素
|
|
99
|
+
if (resizeLineRef.current) {
|
|
100
|
+
resizeLineRef.current.style.top = "".concat(containerTop, "px");
|
|
101
|
+
resizeLineRef.current.style.display = 'block';
|
|
102
|
+
updateResizeLinePosition(e.clientX, containerHeight);
|
|
103
|
+
}
|
|
104
|
+
if (overlayRef.current) {
|
|
105
|
+
overlayRef.current.style.display = 'block';
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// 设置全局样式
|
|
109
|
+
document.body.classList.add('column-resizing');
|
|
110
|
+
document.body.style.cursor = 'ew-resize';
|
|
111
|
+
document.body.style.userSelect = 'none';
|
|
112
|
+
|
|
113
|
+
// 移动处理函数
|
|
114
|
+
var onMove = function onMove(moveEvent) {
|
|
115
|
+
if (!isResizingRef.current) return;
|
|
116
|
+
rafIdRef.current = requestAnimationFrame(function () {
|
|
117
|
+
updateResizeLinePosition(moveEvent.clientX, containerHeight);
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// 结束处理函数
|
|
122
|
+
var onEnd = function onEnd() {
|
|
123
|
+
if (!isResizingRef.current) return;
|
|
124
|
+
cancelAnimationFrame(rafIdRef.current);
|
|
125
|
+
|
|
126
|
+
// 立即更新列宽(关键修改点)
|
|
127
|
+
var finalDelta = lastClientXRef.current - startXRef.current;
|
|
128
|
+
var newWidth = Math.max(20, startWidthRef.current + finalDelta);
|
|
129
|
+
table.setColumnSizing(function (old) {
|
|
130
|
+
return _objectSpread(_objectSpread({}, old), {}, _defineProperty({}, header.column.id, newWidth));
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// 隐藏元素
|
|
134
|
+
if (resizeLineRef.current) {
|
|
135
|
+
resizeLineRef.current.style.display = 'none';
|
|
136
|
+
}
|
|
137
|
+
if (overlayRef.current) {
|
|
138
|
+
overlayRef.current.style.display = 'none';
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// 恢复全局样式
|
|
142
|
+
document.body.classList.remove('column-resizing');
|
|
143
|
+
document.body.style.cursor = '';
|
|
144
|
+
document.body.style.userSelect = '';
|
|
145
|
+
isResizingRef.current = false;
|
|
146
|
+
document.removeEventListener('mousemove', onMove);
|
|
147
|
+
document.removeEventListener('mouseup', onEnd);
|
|
148
|
+
};
|
|
149
|
+
document.addEventListener('mousemove', onMove, {
|
|
150
|
+
passive: true
|
|
151
|
+
});
|
|
152
|
+
document.addEventListener('mouseup', onEnd, {
|
|
153
|
+
once: true
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// 调用原始处理程序
|
|
157
|
+
header.getResizeHandler()(e);
|
|
158
|
+
}, [header, table, tableContentRef, updateResizeLinePosition]);
|
|
159
|
+
return {
|
|
160
|
+
handleResizeStart: handleResizeStart
|
|
161
|
+
};
|
|
162
|
+
};
|
|
@@ -312,6 +312,8 @@ export type TableMaxProps = {
|
|
|
312
312
|
request?: (...params: any[]) => Promise<Blob>;
|
|
313
313
|
/**编辑时修改组件值时触发的事件 */
|
|
314
314
|
onEditValueChange?: (field: string, value: any, extra?: any) => void;
|
|
315
|
+
hasTotalRow?: boolean;
|
|
316
|
+
totalDatas?: any[];
|
|
315
317
|
};
|
|
316
318
|
export interface TableMaxColumnType {
|
|
317
319
|
/**每一列的id是唯一的 */
|