@arim-aisdc/public-components 2.3.48 → 2.3.50
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/BaseInfo/BaseInfo.d.ts +1 -1
- package/dist/components/TableMax/TableBody/{Row.d.ts → OriginalRow.d.ts} +2 -2
- package/dist/components/TableMax/TableBody/{Row.js → OriginalRow.js} +2 -2
- package/dist/components/TableMax/TableBody/OriginalTableBody.d.ts +76 -0
- package/dist/components/TableMax/TableBody/OriginalTableBody.js +509 -0
- package/dist/components/TableMax/TableBody/TableBody.d.ts +3 -0
- package/dist/components/TableMax/TableBody/TableBody.js +15 -0
- package/dist/components/TableMax/TableBody/VirtualRow.d.ts +63 -0
- package/dist/components/TableMax/TableBody/VirtualRow.js +479 -0
- package/dist/components/TableMax/TableBody/VirtualTableBody.d.ts +75 -0
- package/dist/components/TableMax/TableBody/VirtualTableBody.js +423 -0
- package/dist/components/TableMax/TableBody/components/Total.js +86 -27
- package/dist/components/TableMax/TableBody/index.d.ts +3 -75
- package/dist/components/TableMax/TableBody/index.js +4 -519
- package/dist/components/TableMax/TableBody/index.less +14 -2
- package/dist/components/TableMax/TableHeader/OriginalTableHeader.d.ts +21 -0
- package/dist/components/TableMax/TableHeader/OriginalTableHeader.js +86 -0
- package/dist/components/TableMax/TableHeader/TableHeader.d.ts +2 -0
- package/dist/components/TableMax/TableHeader/TableHeader.js +14 -0
- package/dist/components/TableMax/TableHeader/VirtualTableHeader/ColGroup.d.ts +11 -0
- package/dist/components/TableMax/TableHeader/VirtualTableHeader/ColGroup.js +33 -0
- package/dist/components/TableMax/TableHeader/VirtualTableHeader/PinnedColumns.d.ts +19 -0
- package/dist/components/TableMax/TableHeader/VirtualTableHeader/PinnedColumns.js +46 -0
- package/dist/components/TableMax/TableHeader/VirtualTableHeader/ScrollColumns.d.ts +18 -0
- package/dist/components/TableMax/TableHeader/VirtualTableHeader/ScrollColumns.js +47 -0
- package/dist/components/TableMax/TableHeader/VirtualTableHeader/VirtualColumns.d.ts +19 -0
- package/dist/components/TableMax/TableHeader/VirtualTableHeader/VirtualColumns.js +49 -0
- package/dist/components/TableMax/TableHeader/VirtualTableHeader/VirtualPadding.d.ts +7 -0
- package/dist/components/TableMax/TableHeader/VirtualTableHeader/VirtualPadding.js +16 -0
- package/dist/components/TableMax/TableHeader/VirtualTableHeader/index.d.ts +4 -0
- package/dist/components/TableMax/TableHeader/VirtualTableHeader/index.js +79 -0
- package/dist/components/TableMax/TableHeader/VirtualTableHeader/index.less +225 -0
- package/dist/components/TableMax/TableHeader/index.d.ts +3 -20
- package/dist/components/TableMax/TableHeader/index.js +3 -90
- package/dist/components/TableMax/TableHeader/utils.d.ts +1 -0
- package/dist/components/TableMax/TableHeader/utils.js +17 -10
- package/dist/components/TableMax/TableMax.js +169 -123
- package/dist/components/TableMax/components/ColumnEdit/index.d.ts +1 -0
- package/dist/components/TableMax/components/ColumnEdit/index.js +5 -1
- package/dist/components/TableMax/components/ColumnSort/customSortFns.d.ts +8 -8
- package/dist/components/TableMax/contexts/VirtualScroll/VirtualScrollContext.d.ts +3 -0
- package/dist/components/TableMax/contexts/VirtualScroll/VirtualScrollContext.js +2 -0
- package/dist/components/TableMax/contexts/VirtualScroll/VirtualScrollProvider.d.ts +3 -0
- package/dist/components/TableMax/contexts/VirtualScroll/VirtualScrollProvider.js +26 -0
- package/dist/components/TableMax/contexts/VirtualScroll/index.d.ts +3 -0
- package/dist/components/TableMax/contexts/VirtualScroll/index.js +4 -0
- package/dist/components/TableMax/contexts/VirtualScroll/types.d.ts +33 -0
- package/dist/components/TableMax/contexts/VirtualScroll/types.js +1 -0
- package/dist/components/TableMax/contexts/index.d.ts +1 -0
- package/dist/components/TableMax/contexts/index.js +1 -0
- package/dist/components/TableMax/hooks/useColumnWidth copy.js +15 -6
- package/dist/components/TableMax/hooks/useDragDrop.d.ts +27 -0
- package/dist/components/TableMax/hooks/useDragDrop.js +167 -0
- package/dist/components/TableMax/hooks/useTableComponents.d.ts +6 -0
- package/dist/components/TableMax/hooks/useTableComponents.js +19 -0
- package/dist/components/TableMax/hooks/useVirtualCalculations.d.ts +25 -0
- package/dist/components/TableMax/hooks/useVirtualCalculations.js +113 -0
- package/dist/components/TableMax/hooks/useVirtualScroll.d.ts +4 -0
- package/dist/components/TableMax/hooks/useVirtualScroll.js +30 -0
- package/dist/components/TableMax/tableMax.less +22 -5
- package/dist/components/TableMax/type.d.ts +2 -0
- package/package.json +2 -1
|
@@ -31,7 +31,8 @@ export var EditableCell = function EditableCell(_ref) {
|
|
|
31
31
|
getEditOptionsFn = _ref.getEditOptionsFn,
|
|
32
32
|
_ref$editComDisabled = _ref.editComDisabled,
|
|
33
33
|
editComDisabled = _ref$editComDisabled === void 0 ? false : _ref$editComDisabled,
|
|
34
|
-
onEditValueChange = _ref.onEditValueChange
|
|
34
|
+
onEditValueChange = _ref.onEditValueChange,
|
|
35
|
+
width = _ref.width;
|
|
35
36
|
var getEditComponent = function getEditComponent(dataIndex) {
|
|
36
37
|
switch (editComType) {
|
|
37
38
|
case InputType.InputNumber:
|
|
@@ -92,6 +93,9 @@ export var EditableCell = function EditableCell(_ref) {
|
|
|
92
93
|
};
|
|
93
94
|
return /*#__PURE__*/_jsx("div", {
|
|
94
95
|
className: "table-max-cell-wrapper",
|
|
96
|
+
style: {
|
|
97
|
+
width: "".concat(width, "px")
|
|
98
|
+
},
|
|
95
99
|
children: editing ? /*#__PURE__*/_jsx(Form.Item, {
|
|
96
100
|
name: dataIndex,
|
|
97
101
|
style: {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { TableMaxColumnType } from "../../type";
|
|
2
|
-
export declare const numberSortFn: (rowA: any, rowB: any, columnId: string) => 1 |
|
|
3
|
-
export declare const stringSortFn: (rowA: any, rowB: any, columnId: string) => 1 |
|
|
4
|
-
export declare const numberOrStringSortFn: (rowA: any, rowB: any, columnId: string) => 1 |
|
|
5
|
-
export declare const timeSortFn: (rowA: any, rowB: any, columnId: string) => 1 |
|
|
2
|
+
export declare const numberSortFn: (rowA: any, rowB: any, columnId: string) => 1 | 0 | -1;
|
|
3
|
+
export declare const stringSortFn: (rowA: any, rowB: any, columnId: string) => 1 | 0 | -1;
|
|
4
|
+
export declare const numberOrStringSortFn: (rowA: any, rowB: any, columnId: string) => 1 | 0 | -1;
|
|
5
|
+
export declare const timeSortFn: (rowA: any, rowB: any, columnId: string) => 1 | 0 | -1;
|
|
6
6
|
declare const customSortFns: {
|
|
7
|
-
numberSortFn: (rowA: any, rowB: any, columnId: string) => 1 |
|
|
8
|
-
stringSortFn: (rowA: any, rowB: any, columnId: string) => 1 |
|
|
9
|
-
timeSortFn: (rowA: any, rowB: any, columnId: string) => 1 |
|
|
10
|
-
numberOrStringSortFn: (rowA: any, rowB: any, columnId: string) => 1 |
|
|
7
|
+
numberSortFn: (rowA: any, rowB: any, columnId: string) => 1 | 0 | -1;
|
|
8
|
+
stringSortFn: (rowA: any, rowB: any, columnId: string) => 1 | 0 | -1;
|
|
9
|
+
timeSortFn: (rowA: any, rowB: any, columnId: string) => 1 | 0 | -1;
|
|
10
|
+
numberOrStringSortFn: (rowA: any, rowB: any, columnId: string) => 1 | 0 | -1;
|
|
11
11
|
};
|
|
12
12
|
export default customSortFns;
|
|
13
13
|
export type SortFnType = keyof typeof customSortFns | undefined;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// contexts/VirtualScrollProvider.tsx
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { VirtualScrollContext } from "./VirtualScrollContext";
|
|
4
|
+
import { useVirtualCalculations } from "../../hooks/useVirtualCalculations";
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
export var VirtualScrollProvider = function VirtualScrollProvider(_ref) {
|
|
7
|
+
var children = _ref.children,
|
|
8
|
+
table = _ref.table,
|
|
9
|
+
config = _ref.config,
|
|
10
|
+
tableHeaderRef = _ref.tableHeaderRef,
|
|
11
|
+
tableBodyRef = _ref.tableBodyRef;
|
|
12
|
+
var _useVirtualCalculatio = useVirtualCalculations(table, config, tableHeaderRef, tableBodyRef),
|
|
13
|
+
state = _useVirtualCalculatio.state,
|
|
14
|
+
isVirtualEnabled = _useVirtualCalculatio.isVirtualEnabled;
|
|
15
|
+
var contextValue = React.useMemo(function () {
|
|
16
|
+
return {
|
|
17
|
+
config: config,
|
|
18
|
+
state: state,
|
|
19
|
+
isVirtualEnabled: isVirtualEnabled
|
|
20
|
+
};
|
|
21
|
+
}, [config, state, isVirtualEnabled]);
|
|
22
|
+
return /*#__PURE__*/_jsx(VirtualScrollContext.Provider, {
|
|
23
|
+
value: contextValue,
|
|
24
|
+
children: children
|
|
25
|
+
});
|
|
26
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Table } from '@tanstack/react-table';
|
|
3
|
+
import { Virtualizer } from '@tanstack/react-virtual';
|
|
4
|
+
export interface VirtualScrollConfig {
|
|
5
|
+
openVirtualColumns?: boolean;
|
|
6
|
+
openVirtualRows?: boolean;
|
|
7
|
+
rowHeight?: number;
|
|
8
|
+
columnOverscan?: number;
|
|
9
|
+
rowOverscan?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface VirtualScrollState {
|
|
12
|
+
columnVirtualizer: Virtualizer<HTMLDivElement, Element> | null;
|
|
13
|
+
virtualColumns: any[];
|
|
14
|
+
virtualPaddingLeft: number;
|
|
15
|
+
virtualPaddingRight: number;
|
|
16
|
+
rowVirtualizer: Virtualizer<HTMLDivElement, Element> | null;
|
|
17
|
+
virtualRows: any[];
|
|
18
|
+
leftPinnedColumns: any[];
|
|
19
|
+
rightPinnedColumns: any[];
|
|
20
|
+
scrollableColumns: any[];
|
|
21
|
+
}
|
|
22
|
+
export interface VirtualScrollContextType {
|
|
23
|
+
config: VirtualScrollConfig;
|
|
24
|
+
state: VirtualScrollState;
|
|
25
|
+
isVirtualEnabled: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface VirtualScrollProviderProps {
|
|
28
|
+
children: React.ReactNode;
|
|
29
|
+
table: Table<any>;
|
|
30
|
+
config: VirtualScrollConfig;
|
|
31
|
+
tableHeaderRef: React.RefObject<HTMLDivElement>;
|
|
32
|
+
tableBodyRef: React.RefObject<HTMLDivElement>;
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './VirtualScroll';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./VirtualScroll";
|
|
@@ -72,7 +72,8 @@ export var useColumnWidth = function useColumnWidth(_ref) {
|
|
|
72
72
|
if (prevState.tableContainerWidth > 0 && newWidth > prevState.tableContainerWidth) {
|
|
73
73
|
if (totalVisibleWidth < newWidth) {
|
|
74
74
|
// 计算剩余宽度
|
|
75
|
-
|
|
75
|
+
// const remainWidth = newWidth - totalVisibleWidth - 10;
|
|
76
|
+
var remainWidth = newWidth - totalVisibleWidth;
|
|
76
77
|
var unselectedCount = visibleColumns.length;
|
|
77
78
|
|
|
78
79
|
// 如果有未排除的列,均匀分配剩余宽度
|
|
@@ -91,7 +92,8 @@ export var useColumnWidth = function useColumnWidth(_ref) {
|
|
|
91
92
|
}
|
|
92
93
|
} else if (prevState.tableContainerWidth > 0 && newWidth < prevState.tableContainerWidth && JSON.stringify(prevState.initColumnsSizeMap) !== '{}') {
|
|
93
94
|
// 容器变小时,重新计算
|
|
94
|
-
|
|
95
|
+
// const reducedWidth = newWidth - totalVisibleWidth -10;
|
|
96
|
+
var reducedWidth = newWidth - totalVisibleWidth;
|
|
95
97
|
var _unselectedCount = visibleColumns.length;
|
|
96
98
|
if (_unselectedCount > 0) {
|
|
97
99
|
var _averageWidth = reducedWidth / _unselectedCount;
|
|
@@ -152,7 +154,10 @@ export var useColumnWidth = function useColumnWidth(_ref) {
|
|
|
152
154
|
//列宽减少
|
|
153
155
|
var newVisibleColumnsSizing = prevState.columnSizing;
|
|
154
156
|
delete newVisibleColumnsSizing[key];
|
|
155
|
-
|
|
157
|
+
|
|
158
|
+
// const containerWidth = getTableWidth() - 10 || 0;
|
|
159
|
+
var containerWidth = getTableWidth() || 0;
|
|
160
|
+
|
|
156
161
|
// 计算当前总宽度
|
|
157
162
|
var totalWidth = Object.values(newVisibleColumnsSizing).reduce(function (sum, width) {
|
|
158
163
|
return Number(sum || 0) + Number(width || 0);
|
|
@@ -197,7 +202,8 @@ export var useColumnWidth = function useColumnWidth(_ref) {
|
|
|
197
202
|
var allColumnWidth = Object.values(columnsSizeMap).reduce(function (sum, width) {
|
|
198
203
|
return sum + Number(width || 0);
|
|
199
204
|
}, 0);
|
|
200
|
-
|
|
205
|
+
// let remainTableContainerWidth = currentWidth - allColumnWidth - 10;
|
|
206
|
+
var remainTableContainerWidth = currentWidth - allColumnWidth;
|
|
201
207
|
var newColumnSizeMap = _objectSpread({}, columnsSizeMap);
|
|
202
208
|
|
|
203
209
|
// 处理未设置宽度的列
|
|
@@ -211,7 +217,8 @@ export var useColumnWidth = function useColumnWidth(_ref) {
|
|
|
211
217
|
allColumnWidth = Object.values(newColumnSizeMap).reduce(function (sum, width) {
|
|
212
218
|
return sum + Number(width || 0);
|
|
213
219
|
}, 0);
|
|
214
|
-
remainTableContainerWidth = currentWidth - allColumnWidth - 10;
|
|
220
|
+
// remainTableContainerWidth = currentWidth - allColumnWidth - 10;
|
|
221
|
+
remainTableContainerWidth = currentWidth - allColumnWidth;
|
|
215
222
|
}
|
|
216
223
|
|
|
217
224
|
// 分配剩余宽度
|
|
@@ -315,7 +322,9 @@ export var useColumnWidth = function useColumnWidth(_ref) {
|
|
|
315
322
|
var totalWidth = Object.values(newVisibleColumnsSizing).reduce(function (sum, width) {
|
|
316
323
|
return Number(sum || 0) + Number(width || 0);
|
|
317
324
|
}, 0);
|
|
318
|
-
|
|
325
|
+
|
|
326
|
+
// const containerWidth = getTableWidth() - 10 || 0;
|
|
327
|
+
var containerWidth = getTableWidth() || 0;
|
|
319
328
|
|
|
320
329
|
// 处理列宽变大
|
|
321
330
|
if (widthDiff > 0) {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { DropSide, IMenuOptionsType } from "../type";
|
|
2
|
+
export declare const useDragDrop: (tableId: string, table: any, reorderRow?: any, getContextMenu?: (params: {
|
|
3
|
+
row: any;
|
|
4
|
+
column: any;
|
|
5
|
+
}) => IMenuOptionsType) => {
|
|
6
|
+
dragDropState: {
|
|
7
|
+
hoverRowIndex: number;
|
|
8
|
+
dropSide: DropSide;
|
|
9
|
+
contextMenuData: {
|
|
10
|
+
visible: boolean;
|
|
11
|
+
clientX: number;
|
|
12
|
+
clientY: number;
|
|
13
|
+
row: {};
|
|
14
|
+
column: {};
|
|
15
|
+
options: any[];
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
clearHoverRowIndex: () => void;
|
|
19
|
+
changeHoverRow: ({ target, origin }: {
|
|
20
|
+
target: any;
|
|
21
|
+
origin: any;
|
|
22
|
+
}) => void;
|
|
23
|
+
handleCellContextMenu: (e: React.MouseEvent, cell: any) => void;
|
|
24
|
+
closeContextMenu: () => void;
|
|
25
|
+
dropEmptyRef: import("react-dnd").ConnectDropTarget;
|
|
26
|
+
dropTableEmptyRef: import("react-dnd").ConnectDropTarget;
|
|
27
|
+
};
|
|
@@ -0,0 +1,167 @@
|
|
|
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
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
8
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
10
|
+
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; }
|
|
11
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
12
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
|
+
// hooks/useDragDrop.ts
|
|
14
|
+
import { useState, useCallback } from 'react';
|
|
15
|
+
import { useDrop } from 'react-dnd';
|
|
16
|
+
import { events, useEventBus } from "../../..";
|
|
17
|
+
import { DropSide } from "../type";
|
|
18
|
+
export var useDragDrop = function useDragDrop(tableId, table, reorderRow, getContextMenu) {
|
|
19
|
+
var _useState = useState(undefined),
|
|
20
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
21
|
+
hoverRowIndex = _useState2[0],
|
|
22
|
+
setHoverRowIndex = _useState2[1];
|
|
23
|
+
var _useState3 = useState(undefined),
|
|
24
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
25
|
+
dropSide = _useState4[0],
|
|
26
|
+
setDropSide = _useState4[1];
|
|
27
|
+
var _useState5 = useState({
|
|
28
|
+
visible: false,
|
|
29
|
+
clientX: 0,
|
|
30
|
+
clientY: 0,
|
|
31
|
+
row: {},
|
|
32
|
+
column: {},
|
|
33
|
+
options: []
|
|
34
|
+
}),
|
|
35
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
36
|
+
contextMenuData = _useState6[0],
|
|
37
|
+
setContextMenuData = _useState6[1];
|
|
38
|
+
|
|
39
|
+
// 清除hover行信息
|
|
40
|
+
var clearHoverRowIndex = useCallback(function () {
|
|
41
|
+
setHoverRowIndex(undefined);
|
|
42
|
+
}, []);
|
|
43
|
+
|
|
44
|
+
// 当前table在hover时进行广播
|
|
45
|
+
var publishCurTableHoveringEvent = function publishCurTableHoveringEvent() {
|
|
46
|
+
events.emit('TABLE_HOVERING', tableId);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// 接收广播:其他table在hover时,取消当前table的hover
|
|
50
|
+
var receiveCurTableHoveringEvent = useCallback(function (hoveringTableId) {
|
|
51
|
+
if (hoveringTableId !== tableId) {
|
|
52
|
+
clearHoverRowIndex();
|
|
53
|
+
}
|
|
54
|
+
}, [tableId, clearHoverRowIndex]);
|
|
55
|
+
useEventBus('TABLE_HOVERING', receiveCurTableHoveringEvent);
|
|
56
|
+
|
|
57
|
+
// 拖动时,即时修改hover信息
|
|
58
|
+
var changeHoverRow = useCallback(function (_ref) {
|
|
59
|
+
var _origin$draggedRow, _origin$draggedRows;
|
|
60
|
+
var target = _ref.target,
|
|
61
|
+
origin = _ref.origin;
|
|
62
|
+
publishCurTableHoveringEvent();
|
|
63
|
+
var targetRowIndex = target === null || target === void 0 ? void 0 : target.index;
|
|
64
|
+
var originRowIndex = origin === null || origin === void 0 || (_origin$draggedRow = origin.draggedRow) === null || _origin$draggedRow === void 0 ? void 0 : _origin$draggedRow.index;
|
|
65
|
+
var originRowIndexList = (origin === null || origin === void 0 || (_origin$draggedRows = origin.draggedRows) === null || _origin$draggedRows === void 0 ? void 0 : _origin$draggedRows.map(function (row) {
|
|
66
|
+
return row.index;
|
|
67
|
+
})) || [];
|
|
68
|
+
if (tableId === origin.sourceTableId && originRowIndexList.includes(targetRowIndex)) {
|
|
69
|
+
clearHoverRowIndex();
|
|
70
|
+
} else if (targetRowIndex !== hoverRowIndex) {
|
|
71
|
+
setHoverRowIndex(targetRowIndex);
|
|
72
|
+
if (tableId !== origin.sourceTableId) {
|
|
73
|
+
setDropSide(DropSide.Top);
|
|
74
|
+
} else {
|
|
75
|
+
setDropSide(targetRowIndex > originRowIndex ? DropSide.Bottom : DropSide.Top);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}, [hoverRowIndex, tableId, clearHoverRowIndex]);
|
|
79
|
+
|
|
80
|
+
// 拖动到最后一行下面的空白处,在最后一行数据上展示预览位置
|
|
81
|
+
var addToLast = useCallback(function () {
|
|
82
|
+
publishCurTableHoveringEvent();
|
|
83
|
+
var lastIndex = table.getRowModel().rows.length - 1;
|
|
84
|
+
if (lastIndex !== hoverRowIndex || lastIndex === hoverRowIndex && dropSide !== DropSide.Bottom) {
|
|
85
|
+
setHoverRowIndex(lastIndex);
|
|
86
|
+
setDropSide(DropSide.Bottom);
|
|
87
|
+
}
|
|
88
|
+
}, [hoverRowIndex, dropSide, table]);
|
|
89
|
+
|
|
90
|
+
// cell右键菜单
|
|
91
|
+
var handleCellContextMenu = useCallback(function (e, cell) {
|
|
92
|
+
if (getContextMenu) {
|
|
93
|
+
var options = getContextMenu({
|
|
94
|
+
row: cell.row.original,
|
|
95
|
+
column: cell.column.columnDef
|
|
96
|
+
});
|
|
97
|
+
setContextMenuData({
|
|
98
|
+
visible: options.length > 0,
|
|
99
|
+
clientX: e.clientX,
|
|
100
|
+
clientY: e.clientY,
|
|
101
|
+
row: cell.row.original,
|
|
102
|
+
column: cell.column.columnDef,
|
|
103
|
+
options: options
|
|
104
|
+
});
|
|
105
|
+
e.preventDefault();
|
|
106
|
+
}
|
|
107
|
+
}, [getContextMenu]);
|
|
108
|
+
|
|
109
|
+
// 关闭菜单
|
|
110
|
+
var closeContextMenu = useCallback(function () {
|
|
111
|
+
setContextMenuData(function (prev) {
|
|
112
|
+
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
113
|
+
visible: false
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
}, []);
|
|
117
|
+
|
|
118
|
+
// Drop hooks
|
|
119
|
+
var _useDrop = useDrop({
|
|
120
|
+
accept: 'TABLE_ROW',
|
|
121
|
+
drop: function drop(formDatas) {
|
|
122
|
+
return reorderRow === null || reorderRow === void 0 ? void 0 : reorderRow(formDatas, {
|
|
123
|
+
hoverRow: {
|
|
124
|
+
index: 0
|
|
125
|
+
},
|
|
126
|
+
targetTableId: tableId
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}),
|
|
130
|
+
_useDrop2 = _slicedToArray(_useDrop, 2),
|
|
131
|
+
dropEmptyRef = _useDrop2[1];
|
|
132
|
+
var _useDrop3 = useDrop({
|
|
133
|
+
accept: 'TABLE_ROW',
|
|
134
|
+
drop: function drop(formDatas, monitor) {
|
|
135
|
+
if (monitor.didDrop()) {
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
clearHoverRowIndex();
|
|
139
|
+
return reorderRow === null || reorderRow === void 0 ? void 0 : reorderRow(formDatas, {
|
|
140
|
+
hoverRow: undefined,
|
|
141
|
+
targetTableId: tableId
|
|
142
|
+
});
|
|
143
|
+
},
|
|
144
|
+
hover: function hover(item, monitor) {
|
|
145
|
+
if (monitor.isOver({
|
|
146
|
+
shallow: true
|
|
147
|
+
}) && monitor.canDrop()) {
|
|
148
|
+
addToLast();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}),
|
|
152
|
+
_useDrop4 = _slicedToArray(_useDrop3, 2),
|
|
153
|
+
dropTableEmptyRef = _useDrop4[1];
|
|
154
|
+
return {
|
|
155
|
+
dragDropState: {
|
|
156
|
+
hoverRowIndex: hoverRowIndex,
|
|
157
|
+
dropSide: dropSide,
|
|
158
|
+
contextMenuData: contextMenuData
|
|
159
|
+
},
|
|
160
|
+
clearHoverRowIndex: clearHoverRowIndex,
|
|
161
|
+
changeHoverRow: changeHoverRow,
|
|
162
|
+
handleCellContextMenu: handleCellContextMenu,
|
|
163
|
+
closeContextMenu: closeContextMenu,
|
|
164
|
+
dropEmptyRef: dropEmptyRef,
|
|
165
|
+
dropTableEmptyRef: dropTableEmptyRef
|
|
166
|
+
};
|
|
167
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { OriginalTableHeader, VirtualTableHeader } from "../TableHeader";
|
|
3
|
+
import { OriginalTableBody, VirtualTableBody } from "../TableBody";
|
|
4
|
+
import { useIsVirtualEnabled } from "./useVirtualScroll";
|
|
5
|
+
export var useTableComponents = function useTableComponents() {
|
|
6
|
+
var isVirtualEnabled = useIsVirtualEnabled();
|
|
7
|
+
return useMemo(function () {
|
|
8
|
+
if (isVirtualEnabled) {
|
|
9
|
+
return {
|
|
10
|
+
TableHeader: VirtualTableHeader,
|
|
11
|
+
TableBody: VirtualTableBody
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
TableHeader: OriginalTableHeader,
|
|
16
|
+
TableBody: OriginalTableBody
|
|
17
|
+
};
|
|
18
|
+
}, [isVirtualEnabled]);
|
|
19
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { VirtualScrollConfig } from '../contexts';
|
|
2
|
+
export declare const useVirtualCalculations: (table: any, config: VirtualScrollConfig, tableHeaderRef: React.RefObject<HTMLDivElement>, tableBodyRef: React.RefObject<HTMLDivElement>) => {
|
|
3
|
+
state: {
|
|
4
|
+
columnVirtualizer: import("@tanstack/virtual-core").Virtualizer<HTMLDivElement, Element>;
|
|
5
|
+
virtualColumns: import("@tanstack/virtual-core").VirtualItem[];
|
|
6
|
+
virtualPaddingLeft: any;
|
|
7
|
+
virtualPaddingRight: number;
|
|
8
|
+
rowVirtualizer: import("@tanstack/virtual-core").Virtualizer<HTMLDivElement, Element>;
|
|
9
|
+
virtualRows: import("@tanstack/virtual-core").VirtualItem[];
|
|
10
|
+
leftPinnedColumns: any;
|
|
11
|
+
rightPinnedColumns: any;
|
|
12
|
+
scrollableColumns: any;
|
|
13
|
+
};
|
|
14
|
+
isVirtualEnabled: boolean;
|
|
15
|
+
};
|
|
16
|
+
export declare const separateColumns: (table: any, openVirtualColumns: boolean) => {
|
|
17
|
+
leftPinnedColumns: any;
|
|
18
|
+
rightPinnedColumns: any;
|
|
19
|
+
scrollableColumns: any;
|
|
20
|
+
};
|
|
21
|
+
export declare const calculateVirtualPadding: (virtualColumns: any[], totalSize: number) => {
|
|
22
|
+
left: any;
|
|
23
|
+
right: number;
|
|
24
|
+
};
|
|
25
|
+
export declare const shouldEnableVirtualization: (config: VirtualScrollConfig) => boolean;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// hooks/useVirtualCalculations.ts
|
|
2
|
+
import { useEffect, useMemo } from 'react';
|
|
3
|
+
import { useVirtualizer } from '@tanstack/react-virtual';
|
|
4
|
+
export var useVirtualCalculations = function useVirtualCalculations(table, config, tableHeaderRef, tableBodyRef) {
|
|
5
|
+
var isVirtualEnabled = shouldEnableVirtualization(config);
|
|
6
|
+
var visibleColumns = table.getVisibleLeafColumns();
|
|
7
|
+
|
|
8
|
+
// 列分类
|
|
9
|
+
var _useMemo = useMemo(function () {
|
|
10
|
+
return separateColumns(table, !!config.openVirtualColumns);
|
|
11
|
+
}, [visibleColumns, config.openVirtualColumns, table.getState().columnPinning]),
|
|
12
|
+
leftPinnedColumns = _useMemo.leftPinnedColumns,
|
|
13
|
+
rightPinnedColumns = _useMemo.rightPinnedColumns,
|
|
14
|
+
scrollableColumns = _useMemo.scrollableColumns;
|
|
15
|
+
|
|
16
|
+
// 列虚拟化配置
|
|
17
|
+
var columnVirtualizerConfig = useMemo(function () {
|
|
18
|
+
if (!config.openVirtualColumns) return null;
|
|
19
|
+
return {
|
|
20
|
+
count: scrollableColumns.length,
|
|
21
|
+
estimateSize: function estimateSize(index) {
|
|
22
|
+
return scrollableColumns[index].getSize();
|
|
23
|
+
},
|
|
24
|
+
getScrollElement: function getScrollElement() {
|
|
25
|
+
return tableBodyRef.current;
|
|
26
|
+
},
|
|
27
|
+
horizontal: true,
|
|
28
|
+
overscan: config.columnOverscan || 3
|
|
29
|
+
};
|
|
30
|
+
}, [config.openVirtualColumns, scrollableColumns.length, config.columnOverscan, tableBodyRef.current]);
|
|
31
|
+
var columnVirtualizer = columnVirtualizerConfig ? useVirtualizer(columnVirtualizerConfig) : null;
|
|
32
|
+
var virtualColumns = config.openVirtualColumns ? (columnVirtualizer === null || columnVirtualizer === void 0 ? void 0 : columnVirtualizer.getVirtualItems()) || [] : [];
|
|
33
|
+
var _useMemo2 = useMemo(function () {
|
|
34
|
+
return calculateVirtualPadding(virtualColumns, (columnVirtualizer === null || columnVirtualizer === void 0 ? void 0 : columnVirtualizer.getTotalSize()) || 0);
|
|
35
|
+
}, [virtualColumns, columnVirtualizer]),
|
|
36
|
+
virtualPaddingLeft = _useMemo2.left,
|
|
37
|
+
virtualPaddingRight = _useMemo2.right;
|
|
38
|
+
|
|
39
|
+
// 行虚拟化配置 - 包含 rowHeight 依赖
|
|
40
|
+
var rows = table.getRowModel().rows;
|
|
41
|
+
var rowVirtualizerConfig = useMemo(function () {
|
|
42
|
+
if (!config.openVirtualRows) return null;
|
|
43
|
+
return {
|
|
44
|
+
count: rows.length,
|
|
45
|
+
estimateSize: function estimateSize() {
|
|
46
|
+
return config.rowHeight || 50;
|
|
47
|
+
},
|
|
48
|
+
// 使用 config.rowHeight
|
|
49
|
+
getScrollElement: function getScrollElement() {
|
|
50
|
+
return tableBodyRef.current;
|
|
51
|
+
},
|
|
52
|
+
overscan: config.rowOverscan || 10
|
|
53
|
+
};
|
|
54
|
+
}, [config.openVirtualRows, rows.length, config.rowHeight,
|
|
55
|
+
// 关键:包含 rowHeight 依赖
|
|
56
|
+
config.rowOverscan, tableBodyRef.current]);
|
|
57
|
+
var rowVirtualizer = rowVirtualizerConfig ? useVirtualizer(rowVirtualizerConfig) : null;
|
|
58
|
+
|
|
59
|
+
// 响应 rowHeight 变化
|
|
60
|
+
useEffect(function () {
|
|
61
|
+
if (rowVirtualizer && config.openVirtualRows) {
|
|
62
|
+
// 当 rowHeight 变化时,重新测量所有行
|
|
63
|
+
rowVirtualizer.measure();
|
|
64
|
+
}
|
|
65
|
+
}, [config.rowHeight, rowVirtualizer, config.openVirtualRows]);
|
|
66
|
+
var virtualRows = config.openVirtualRows ? (rowVirtualizer === null || rowVirtualizer === void 0 ? void 0 : rowVirtualizer.getVirtualItems()) || [] : [];
|
|
67
|
+
var state = useMemo(function () {
|
|
68
|
+
return {
|
|
69
|
+
columnVirtualizer: columnVirtualizer,
|
|
70
|
+
virtualColumns: virtualColumns,
|
|
71
|
+
virtualPaddingLeft: virtualPaddingLeft,
|
|
72
|
+
virtualPaddingRight: virtualPaddingRight,
|
|
73
|
+
rowVirtualizer: rowVirtualizer,
|
|
74
|
+
virtualRows: virtualRows,
|
|
75
|
+
leftPinnedColumns: leftPinnedColumns,
|
|
76
|
+
rightPinnedColumns: rightPinnedColumns,
|
|
77
|
+
scrollableColumns: scrollableColumns
|
|
78
|
+
};
|
|
79
|
+
}, [columnVirtualizer, virtualColumns, virtualPaddingLeft, virtualPaddingRight, rowVirtualizer, virtualRows, leftPinnedColumns, rightPinnedColumns, scrollableColumns]);
|
|
80
|
+
return {
|
|
81
|
+
state: state,
|
|
82
|
+
isVirtualEnabled: isVirtualEnabled
|
|
83
|
+
};
|
|
84
|
+
};
|
|
85
|
+
export var separateColumns = function separateColumns(table, openVirtualColumns) {
|
|
86
|
+
// if (!openVirtualColumns) {
|
|
87
|
+
// return {
|
|
88
|
+
// leftPinnedColumns: [],
|
|
89
|
+
// rightPinnedColumns: [],
|
|
90
|
+
// scrollableColumns: visibleColumns,
|
|
91
|
+
// };
|
|
92
|
+
// }
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
leftPinnedColumns: table.getLeftVisibleLeafColumns(),
|
|
96
|
+
rightPinnedColumns: table.getRightVisibleLeafColumns(),
|
|
97
|
+
scrollableColumns: table.getCenterVisibleLeafColumns()
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
export var calculateVirtualPadding = function calculateVirtualPadding(virtualColumns, totalSize) {
|
|
101
|
+
var _virtualColumns$0$sta, _virtualColumns$, _virtualColumns$end, _virtualColumns;
|
|
102
|
+
if (!virtualColumns.length) return {
|
|
103
|
+
left: 0,
|
|
104
|
+
right: 0
|
|
105
|
+
};
|
|
106
|
+
return {
|
|
107
|
+
left: (_virtualColumns$0$sta = (_virtualColumns$ = virtualColumns[0]) === null || _virtualColumns$ === void 0 ? void 0 : _virtualColumns$.start) !== null && _virtualColumns$0$sta !== void 0 ? _virtualColumns$0$sta : 0,
|
|
108
|
+
right: totalSize - ((_virtualColumns$end = (_virtualColumns = virtualColumns[virtualColumns.length - 1]) === null || _virtualColumns === void 0 ? void 0 : _virtualColumns.end) !== null && _virtualColumns$end !== void 0 ? _virtualColumns$end : 0)
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
export var shouldEnableVirtualization = function shouldEnableVirtualization(config) {
|
|
112
|
+
return !!(config.openVirtualColumns || config.openVirtualRows);
|
|
113
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const useVirtualScroll: () => import("../contexts").VirtualScrollContextType;
|
|
2
|
+
export declare const useVirtualConfig: () => import("../contexts").VirtualScrollConfig;
|
|
3
|
+
export declare const useVirtualState: () => import("../contexts").VirtualScrollState;
|
|
4
|
+
export declare const useIsVirtualEnabled: () => boolean;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useContext, useMemo } from 'react';
|
|
2
|
+
import { VirtualScrollContext } from "../contexts";
|
|
3
|
+
export var useVirtualScroll = function useVirtualScroll() {
|
|
4
|
+
var context = useContext(VirtualScrollContext);
|
|
5
|
+
if (!context) {
|
|
6
|
+
throw new Error('useVirtualScroll must be used within VirtualScrollProvider');
|
|
7
|
+
}
|
|
8
|
+
return context;
|
|
9
|
+
};
|
|
10
|
+
export var useVirtualConfig = function useVirtualConfig() {
|
|
11
|
+
var _useVirtualScroll = useVirtualScroll(),
|
|
12
|
+
config = _useVirtualScroll.config;
|
|
13
|
+
return useMemo(function () {
|
|
14
|
+
return config;
|
|
15
|
+
}, [config]);
|
|
16
|
+
};
|
|
17
|
+
export var useVirtualState = function useVirtualState() {
|
|
18
|
+
var _useVirtualScroll2 = useVirtualScroll(),
|
|
19
|
+
state = _useVirtualScroll2.state;
|
|
20
|
+
return useMemo(function () {
|
|
21
|
+
return state;
|
|
22
|
+
}, [state]);
|
|
23
|
+
};
|
|
24
|
+
export var useIsVirtualEnabled = function useIsVirtualEnabled() {
|
|
25
|
+
var _useVirtualScroll3 = useVirtualScroll(),
|
|
26
|
+
isVirtualEnabled = _useVirtualScroll3.isVirtualEnabled;
|
|
27
|
+
return useMemo(function () {
|
|
28
|
+
return isVirtualEnabled;
|
|
29
|
+
}, [isVirtualEnabled]);
|
|
30
|
+
};
|
|
@@ -138,9 +138,26 @@
|
|
|
138
138
|
margin: 0;
|
|
139
139
|
// flex: 1;
|
|
140
140
|
justify-content: space-between;
|
|
141
|
+
// overflow-y: scroll;
|
|
141
142
|
.cell-wapper {
|
|
142
143
|
line-height: @global-table-max-header-cell-wapper-line-height;
|
|
143
144
|
}
|
|
145
|
+
|
|
146
|
+
&::-webkit-scrollbar {
|
|
147
|
+
width: 10px;
|
|
148
|
+
height: 10px;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
&::-webkit-scrollbar-track, &::-webkit-scrollbar-corner {
|
|
152
|
+
background: @global-table-max-scrollbar-track !important;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
&::-webkit-scrollbar-thumb {
|
|
156
|
+
border-radius: 20px;
|
|
157
|
+
border: 6px solid transparent !important;
|
|
158
|
+
background: @scrollThumb !important;
|
|
159
|
+
background-clip: padding-box !important;
|
|
160
|
+
}
|
|
144
161
|
}
|
|
145
162
|
|
|
146
163
|
.table-header-scroll {
|
|
@@ -263,18 +280,18 @@
|
|
|
263
280
|
.table-max-content-compact {
|
|
264
281
|
// 紧凑模式
|
|
265
282
|
.cell-wapper {
|
|
266
|
-
line-height:
|
|
283
|
+
line-height: 22px !important;
|
|
267
284
|
padding: 4px 2px !important;
|
|
268
285
|
height: 24px !important;
|
|
269
286
|
}
|
|
270
287
|
|
|
271
288
|
.tbody-tr-td, .table-thead-tr {
|
|
272
|
-
height:
|
|
273
|
-
line-height:
|
|
289
|
+
height:30px !important;
|
|
290
|
+
line-height: 30px !important;
|
|
274
291
|
|
|
275
292
|
.table-max-cell-wrapper {
|
|
276
|
-
padding:
|
|
277
|
-
line-height:
|
|
293
|
+
padding: 0 2px;
|
|
294
|
+
line-height: 28px;
|
|
278
295
|
}
|
|
279
296
|
}
|
|
280
297
|
}
|