@kdcloudjs/table 1.2.2-canary.12 → 1.2.2-canary.14
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/@kdcloudjs/table.css +1 -1
- package/dist/@kdcloudjs/table.js +1050 -459
- package/dist/@kdcloudjs/table.js.map +1 -1
- package/dist/@kdcloudjs/table.min.css +1 -1
- package/dist/@kdcloudjs/table.min.js +8 -8
- package/dist/@kdcloudjs/table.min.js.map +1 -1
- package/es/table/base/BlankComponent.d.ts +11 -0
- package/es/table/base/BlankComponent.js +61 -0
- package/es/table/base/helpers/FastScrollManager.d.ts +96 -0
- package/es/table/base/helpers/FastScrollManager.js +167 -0
- package/es/table/base/table.d.ts +13 -0
- package/es/table/base/table.js +126 -73
- package/es/table/pipeline/features/columnDrag.js +220 -242
- package/es/table/pipeline/features/columnResizeWidth.js +40 -5
- package/es/table/pipeline/features/rowDrag.js +169 -80
- package/es/table/pipeline/features/utils/touchEventUtils.d.ts +15 -0
- package/es/table/pipeline/features/utils/touchEventUtils.js +65 -0
- package/lib/table/base/BlankComponent.d.ts +11 -0
- package/lib/table/base/BlankComponent.js +75 -0
- package/lib/table/base/helpers/FastScrollManager.d.ts +96 -0
- package/lib/table/base/helpers/FastScrollManager.js +175 -0
- package/lib/table/base/table.d.ts +13 -0
- package/lib/table/base/table.js +126 -73
- package/lib/table/pipeline/features/columnDrag.js +220 -242
- package/lib/table/pipeline/features/columnResizeWidth.js +40 -5
- package/lib/table/pipeline/features/rowDrag.js +169 -80
- package/lib/table/pipeline/features/utils/touchEventUtils.d.ts +15 -0
- package/lib/table/pipeline/features/utils/touchEventUtils.js +76 -0
- package/package.json +1 -1
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 快速滚动管理器
|
|
3
|
+
* 抽取 BaseTable 中的快速滚动相关逻辑
|
|
4
|
+
*/
|
|
5
|
+
export interface FastScrollConfig {
|
|
6
|
+
/** 预渲染缓冲区大小,用于快速滚动判断 */
|
|
7
|
+
overscanSize?: number;
|
|
8
|
+
/** 快速滚动速度阈值 (像素/毫秒) */
|
|
9
|
+
velocityThreshold?: number;
|
|
10
|
+
/** 快速滚动距离倍数阈值 */
|
|
11
|
+
distanceMultiplier?: number;
|
|
12
|
+
/** 快速滚动结束等待时间 (毫秒) - 高速滚动 */
|
|
13
|
+
fastScrollEndDelayHigh?: number;
|
|
14
|
+
/** 快速滚动结束等待时间 (毫秒) - 普通滚动 */
|
|
15
|
+
fastScrollEndDelayNormal?: number;
|
|
16
|
+
/** 高速滚动速度阈值 (像素/毫秒) */
|
|
17
|
+
highVelocityThreshold?: number;
|
|
18
|
+
}
|
|
19
|
+
export interface FastScrollState {
|
|
20
|
+
lastScrollTime: number;
|
|
21
|
+
scrollVelocity: number;
|
|
22
|
+
lastOffsetY: number;
|
|
23
|
+
}
|
|
24
|
+
export interface ScrollEventData {
|
|
25
|
+
offsetY: number;
|
|
26
|
+
maxRenderHeight: number;
|
|
27
|
+
maxRenderWidth: number;
|
|
28
|
+
}
|
|
29
|
+
export interface VerticalRenderRange {
|
|
30
|
+
topIndex: number;
|
|
31
|
+
bottomIndex: number;
|
|
32
|
+
topBlank: number;
|
|
33
|
+
bottomBlank: number;
|
|
34
|
+
}
|
|
35
|
+
export interface FastScrollCallbacks {
|
|
36
|
+
onFastScrollStart: (renderData: {
|
|
37
|
+
offsetY: number;
|
|
38
|
+
maxRenderHeight: number;
|
|
39
|
+
maxRenderWidth: number;
|
|
40
|
+
verticalRenderRange: VerticalRenderRange;
|
|
41
|
+
}) => void;
|
|
42
|
+
onFastScrollEnd: (scrollData: ScrollEventData) => void;
|
|
43
|
+
getCurrentRenderRange: (offsetY: number, maxRenderHeight: number, dataLength: number) => VerticalRenderRange;
|
|
44
|
+
}
|
|
45
|
+
export declare class FastScrollManager {
|
|
46
|
+
private state;
|
|
47
|
+
private isFastScrolling;
|
|
48
|
+
private fastScrollEndTimer?;
|
|
49
|
+
private config;
|
|
50
|
+
private callbacks;
|
|
51
|
+
constructor(callbacks: FastScrollCallbacks, config?: FastScrollConfig);
|
|
52
|
+
/**
|
|
53
|
+
* 检测是否接近底部(剩余滚动距离少于两屏)
|
|
54
|
+
*/
|
|
55
|
+
private isNearBottom;
|
|
56
|
+
/**
|
|
57
|
+
* 处理滚动事件 - 检测和处理快速滚动
|
|
58
|
+
*/
|
|
59
|
+
handleScrollEvent(sizeAndOffset: ScrollEventData, currentState: {
|
|
60
|
+
offsetY: number;
|
|
61
|
+
maxRenderHeight: number;
|
|
62
|
+
maxRenderWidth: number;
|
|
63
|
+
}, dataLength: number, totalScrollHeight: number): void;
|
|
64
|
+
/**
|
|
65
|
+
* 开始快速滚动
|
|
66
|
+
*/
|
|
67
|
+
private startFastScrolling;
|
|
68
|
+
/**
|
|
69
|
+
* 重置快速滚动结束定时器
|
|
70
|
+
*/
|
|
71
|
+
private resetFastScrollEndTimer;
|
|
72
|
+
/**
|
|
73
|
+
* 结束快速滚动
|
|
74
|
+
*/
|
|
75
|
+
private endFastScrolling;
|
|
76
|
+
/**
|
|
77
|
+
* 清理资源
|
|
78
|
+
*/
|
|
79
|
+
cleanup(): void;
|
|
80
|
+
/**
|
|
81
|
+
* 获取当前是否处于快速滚动状态
|
|
82
|
+
*/
|
|
83
|
+
getIsFastScrolling(): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* 获取当前滚动速度
|
|
86
|
+
*/
|
|
87
|
+
getScrollVelocity(): number;
|
|
88
|
+
/**
|
|
89
|
+
* 清理资源
|
|
90
|
+
*/
|
|
91
|
+
destroy(): void;
|
|
92
|
+
/**
|
|
93
|
+
* 获取当前配置
|
|
94
|
+
*/
|
|
95
|
+
getConfig(): Readonly<Required<FastScrollConfig>>;
|
|
96
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.FastScrollManager = void 0;
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
|
|
9
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/classCallCheck"));
|
|
10
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/createClass"));
|
|
11
|
+
/**
|
|
12
|
+
* 快速滚动管理器
|
|
13
|
+
* 抽取 BaseTable 中的快速滚动相关逻辑
|
|
14
|
+
*/
|
|
15
|
+
var FastScrollManager = /*#__PURE__*/function () {
|
|
16
|
+
function FastScrollManager(callbacks) {
|
|
17
|
+
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
18
|
+
(0, _classCallCheck2.default)(this, FastScrollManager);
|
|
19
|
+
// 快速滚动状态
|
|
20
|
+
this.state = {
|
|
21
|
+
lastScrollTime: 0,
|
|
22
|
+
scrollVelocity: 0,
|
|
23
|
+
lastOffsetY: 0
|
|
24
|
+
};
|
|
25
|
+
// 快速滚动标志 - 作为私有属性立即更新
|
|
26
|
+
this.isFastScrolling = false;
|
|
27
|
+
this.callbacks = callbacks;
|
|
28
|
+
// 合并默认配置
|
|
29
|
+
this.config = (0, _extends2.default)({
|
|
30
|
+
overscanSize: 100,
|
|
31
|
+
velocityThreshold: 3,
|
|
32
|
+
distanceMultiplier: 3,
|
|
33
|
+
fastScrollEndDelayHigh: 200,
|
|
34
|
+
fastScrollEndDelayNormal: 150,
|
|
35
|
+
highVelocityThreshold: 5
|
|
36
|
+
}, config);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 检测是否接近底部(剩余滚动距离少于两屏)
|
|
40
|
+
*/
|
|
41
|
+
(0, _createClass2.default)(FastScrollManager, [{
|
|
42
|
+
key: "isNearBottom",
|
|
43
|
+
value: function isNearBottom(currentScrollTop, maxRenderHeight, totalScrollHeight) {
|
|
44
|
+
var remainingScrollDistance = totalScrollHeight - currentScrollTop - maxRenderHeight;
|
|
45
|
+
return remainingScrollDistance < maxRenderHeight;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 处理滚动事件 - 检测和处理快速滚动
|
|
49
|
+
*/
|
|
50
|
+
}, {
|
|
51
|
+
key: "handleScrollEvent",
|
|
52
|
+
value: function handleScrollEvent(sizeAndOffset, currentState, dataLength, totalScrollHeight) {
|
|
53
|
+
var currentTime = performance.now();
|
|
54
|
+
var deltaY = Math.abs(sizeAndOffset.offsetY - this.state.lastOffsetY);
|
|
55
|
+
var deltaTime = currentTime - this.state.lastScrollTime;
|
|
56
|
+
// 计算滚动速度 (像素/毫秒)
|
|
57
|
+
this.state.scrollVelocity = deltaTime > 0 ? deltaY / deltaTime : 0;
|
|
58
|
+
// 检测是否接近底部
|
|
59
|
+
var isNearBottom = this.isNearBottom(sizeAndOffset.offsetY, sizeAndOffset.maxRenderHeight, totalScrollHeight);
|
|
60
|
+
// 如果正在快速滚动但接近底部,提前结束快速滚动
|
|
61
|
+
if (this.isFastScrolling && isNearBottom) {
|
|
62
|
+
this.endFastScrolling(sizeAndOffset);
|
|
63
|
+
return; // 让正常渲染逻辑接管
|
|
64
|
+
}
|
|
65
|
+
// 快速滚动判断条件:
|
|
66
|
+
// 1. 滚动距离超过阈值 && 滚动速度超过阈值
|
|
67
|
+
// 2. 当前未在快速滚动状态
|
|
68
|
+
// 3. 未接近底部边界
|
|
69
|
+
var isSignificantChange = deltaY > this.config.overscanSize * this.config.distanceMultiplier;
|
|
70
|
+
var isHighVelocity = this.state.scrollVelocity > this.config.velocityThreshold;
|
|
71
|
+
var shouldStartFastScroll = (isSignificantChange || isHighVelocity) && !this.isFastScrolling && !isNearBottom; // 接近底部时不启动快速滚动
|
|
72
|
+
if (shouldStartFastScroll) {
|
|
73
|
+
this.startFastScrolling(currentState, dataLength);
|
|
74
|
+
}
|
|
75
|
+
// 重置快速滚动结束定时器
|
|
76
|
+
if (this.isFastScrolling) {
|
|
77
|
+
this.resetFastScrollEndTimer(sizeAndOffset);
|
|
78
|
+
}
|
|
79
|
+
// 更新记录
|
|
80
|
+
this.state.lastOffsetY = sizeAndOffset.offsetY;
|
|
81
|
+
this.state.lastScrollTime = currentTime;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* 开始快速滚动
|
|
85
|
+
*/
|
|
86
|
+
}, {
|
|
87
|
+
key: "startFastScrolling",
|
|
88
|
+
value: function startFastScrolling(currentState, dataLength) {
|
|
89
|
+
this.isFastScrolling = true;
|
|
90
|
+
// 获取当前渲染范围作为缓存
|
|
91
|
+
var currentVerticalRange = this.callbacks.getCurrentRenderRange(currentState.offsetY, currentState.maxRenderHeight, dataLength);
|
|
92
|
+
// 通知外部开始快速滚动
|
|
93
|
+
this.callbacks.onFastScrollStart({
|
|
94
|
+
offsetY: currentState.offsetY,
|
|
95
|
+
maxRenderHeight: currentState.maxRenderHeight,
|
|
96
|
+
maxRenderWidth: currentState.maxRenderWidth,
|
|
97
|
+
verticalRenderRange: currentVerticalRange
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* 重置快速滚动结束定时器
|
|
102
|
+
*/
|
|
103
|
+
}, {
|
|
104
|
+
key: "resetFastScrollEndTimer",
|
|
105
|
+
value: function resetFastScrollEndTimer(sizeAndOffset) {
|
|
106
|
+
var _this = this;
|
|
107
|
+
if (this.fastScrollEndTimer) {
|
|
108
|
+
clearTimeout(this.fastScrollEndTimer);
|
|
109
|
+
}
|
|
110
|
+
var waitTime = this.state.scrollVelocity > this.config.highVelocityThreshold ? this.config.fastScrollEndDelayHigh : this.config.fastScrollEndDelayNormal;
|
|
111
|
+
this.fastScrollEndTimer = window.setTimeout(function () {
|
|
112
|
+
_this.endFastScrolling(sizeAndOffset);
|
|
113
|
+
}, waitTime);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* 结束快速滚动
|
|
117
|
+
*/
|
|
118
|
+
}, {
|
|
119
|
+
key: "endFastScrolling",
|
|
120
|
+
value: function endFastScrolling(sizeAndOffset) {
|
|
121
|
+
this.isFastScrolling = false;
|
|
122
|
+
this.fastScrollEndTimer = undefined;
|
|
123
|
+
// 通知外部结束快速滚动
|
|
124
|
+
this.callbacks.onFastScrollEnd(sizeAndOffset);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* 清理资源
|
|
128
|
+
*/
|
|
129
|
+
}, {
|
|
130
|
+
key: "cleanup",
|
|
131
|
+
value: function cleanup() {
|
|
132
|
+
if (this.fastScrollEndTimer) {
|
|
133
|
+
clearTimeout(this.fastScrollEndTimer);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* 获取当前是否处于快速滚动状态
|
|
138
|
+
*/
|
|
139
|
+
}, {
|
|
140
|
+
key: "getIsFastScrolling",
|
|
141
|
+
value: function getIsFastScrolling() {
|
|
142
|
+
return this.isFastScrolling;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* 获取当前滚动速度
|
|
146
|
+
*/
|
|
147
|
+
}, {
|
|
148
|
+
key: "getScrollVelocity",
|
|
149
|
+
value: function getScrollVelocity() {
|
|
150
|
+
return this.state.scrollVelocity;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* 清理资源
|
|
154
|
+
*/
|
|
155
|
+
}, {
|
|
156
|
+
key: "destroy",
|
|
157
|
+
value: function destroy() {
|
|
158
|
+
if (this.fastScrollEndTimer) {
|
|
159
|
+
clearTimeout(this.fastScrollEndTimer);
|
|
160
|
+
this.fastScrollEndTimer = undefined;
|
|
161
|
+
}
|
|
162
|
+
this.isFastScrolling = false;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* 获取当前配置
|
|
166
|
+
*/
|
|
167
|
+
}, {
|
|
168
|
+
key: "getConfig",
|
|
169
|
+
value: function getConfig() {
|
|
170
|
+
return (0, _extends2.default)({}, this.config);
|
|
171
|
+
}
|
|
172
|
+
}]);
|
|
173
|
+
return FastScrollManager;
|
|
174
|
+
}();
|
|
175
|
+
exports.FastScrollManager = FastScrollManager;
|
|
@@ -23,6 +23,8 @@ export interface BaseTableProps {
|
|
|
23
23
|
};
|
|
24
24
|
/** 虚拟滚动开启情况下,表格中每一行的预估高度 */
|
|
25
25
|
estimatedRowHeight?: number;
|
|
26
|
+
/** 性能差浏览器和处理器,性能差则启动快速滚动优化,默认为 false */
|
|
27
|
+
isLowPerformance?: boolean;
|
|
26
28
|
/** @deprecated 表格头部是否置顶,默认为 true。请使用 isStickyHeader 代替 */
|
|
27
29
|
isStickyHead?: boolean;
|
|
28
30
|
/** 表格头部是否置顶,默认为 true */
|
|
@@ -107,6 +109,13 @@ export interface BaseTableState {
|
|
|
107
109
|
offsetX: number;
|
|
108
110
|
/** 横向虚拟滚动 最大渲染尺寸 */
|
|
109
111
|
maxRenderWidth: number;
|
|
112
|
+
/** 快速滚动时保留的上一次渲染数据 */
|
|
113
|
+
previousRenderData?: {
|
|
114
|
+
offsetY: number;
|
|
115
|
+
maxRenderHeight: number;
|
|
116
|
+
maxRenderWidth: number;
|
|
117
|
+
verticalRenderRange: VerticalRenderRange;
|
|
118
|
+
};
|
|
110
119
|
}
|
|
111
120
|
export declare class BaseTable extends React.Component<BaseTableProps, BaseTableState> {
|
|
112
121
|
static defaultProps: {
|
|
@@ -120,6 +129,7 @@ export declare class BaseTable extends React.Component<BaseTableProps, BaseTable
|
|
|
120
129
|
stickyScrollHeight: string;
|
|
121
130
|
useVirtual: string;
|
|
122
131
|
estimatedRowHeight: number;
|
|
132
|
+
isLowPerformance: boolean;
|
|
123
133
|
isLoading: boolean;
|
|
124
134
|
components: {};
|
|
125
135
|
getTableProps: typeof noop;
|
|
@@ -137,6 +147,9 @@ export declare class BaseTable extends React.Component<BaseTableProps, BaseTable
|
|
|
137
147
|
private hasScrollY;
|
|
138
148
|
private resizeObserver?;
|
|
139
149
|
private offsetY;
|
|
150
|
+
private fastScrollManager;
|
|
151
|
+
private topBlankRef;
|
|
152
|
+
private bottomBlankRef;
|
|
140
153
|
/** @deprecated BaseTable.getDoms() 已经过时,请勿调用 */
|
|
141
154
|
getDoms(): TableDOMHelper;
|
|
142
155
|
constructor(props: Readonly<BaseTableProps>);
|