@kdcloudjs/table 1.2.2-canary.13 → 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 +525 -323
- package/dist/@kdcloudjs/table.js.map +1 -1
- package/dist/@kdcloudjs/table.min.css +1 -1
- package/dist/@kdcloudjs/table.min.js +4 -4
- package/dist/@kdcloudjs/table.min.js.map +1 -1
- 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/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
|
@@ -4,6 +4,7 @@ import _toConsumableArray from "@babel/runtime-corejs3/helpers/toConsumableArray
|
|
|
4
4
|
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
5
5
|
import { makeRecursiveMapper, mergeCellProps, collectNodes, isLeafNode, isSelectColumn } from '../../utils';
|
|
6
6
|
import { FILL_COLUMN_CODE } from './autoFill';
|
|
7
|
+
import { getEventCoordinates, hasMovedEnough, addPointerEventListeners, removePointerEventListeners } from './utils/touchEventUtils';
|
|
7
8
|
var stateKey = 'columnDrag';
|
|
8
9
|
var SCROLL_SIZE = 30;
|
|
9
10
|
function disableSelect(event) {
|
|
@@ -61,251 +62,237 @@ export function columnDrag() {
|
|
|
61
62
|
style: style
|
|
62
63
|
});
|
|
63
64
|
},
|
|
64
|
-
headerCellProps: mergeCellProps(col.headerCellProps, {
|
|
65
|
-
onMouseDown:
|
|
65
|
+
headerCellProps: mergeCellProps(col.headerCellProps, _extends(_extends({}, isLeaf && path.length === 1 ? {
|
|
66
|
+
onMouseDown: function onMouseDown(e) {
|
|
66
67
|
if (e.button !== 0 || !e.currentTarget.contains(e.target)) {
|
|
67
68
|
return;
|
|
68
69
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
//
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
if (
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
lock: lock
|
|
176
|
-
})) {
|
|
177
|
-
cloumnsTranslateData[code] += _adjustTranslation(optionColumn.width);
|
|
178
|
-
if (isLeafNode(columns[index])) {
|
|
179
|
-
cloumnsTranslateData[optionColumn.code] -= _adjustTranslation(width);
|
|
180
|
-
} else {
|
|
181
|
-
cloumnsTranslateData[optionColumn.code] -= _adjustTranslation(getColumnWidth(columns[index]));
|
|
182
|
-
moveAllChildren(children, cloumnsTranslateData, _adjustTranslation(optionColumn.width));
|
|
183
|
-
}
|
|
184
|
-
columnMoved = true;
|
|
185
|
-
}
|
|
186
|
-
index++;
|
|
187
|
-
}
|
|
188
|
-
} else if (startIndex < replaceIndex) {
|
|
189
|
-
// 右移
|
|
190
|
-
while (startIndex < index) {
|
|
191
|
-
var _columns$index2 = columns[index],
|
|
192
|
-
_code = _columns$index2.code,
|
|
193
|
-
_lock = _columns$index2.lock,
|
|
194
|
-
_width = _columns$index2.width,
|
|
195
|
-
_children = _columns$index2.children;
|
|
196
|
-
if (enableMove({
|
|
197
|
-
code: _code,
|
|
198
|
-
lock: _lock
|
|
199
|
-
})) {
|
|
200
|
-
cloumnsTranslateData[_code] -= _adjustTranslation(optionColumn.width);
|
|
201
|
-
if (isLeafNode(columns[index])) {
|
|
202
|
-
cloumnsTranslateData[optionColumn.code] += _adjustTranslation(_width);
|
|
203
|
-
} else {
|
|
204
|
-
cloumnsTranslateData[optionColumn.code] += _adjustTranslation(getColumnWidth(columns[index]));
|
|
205
|
-
moveAllChildren(_children, cloumnsTranslateData, _adjustTranslation(optionColumn.width), true);
|
|
206
|
-
}
|
|
207
|
-
columnMoved = true;
|
|
208
|
-
}
|
|
209
|
-
index--;
|
|
70
|
+
handlePointerDown(e.nativeEvent, false, e.currentTarget);
|
|
71
|
+
},
|
|
72
|
+
onTouchStart: function onTouchStart(e) {
|
|
73
|
+
// 阻止触摸事件的默认行为
|
|
74
|
+
if (e.cancelable) {
|
|
75
|
+
e.preventDefault();
|
|
76
|
+
}
|
|
77
|
+
handlePointerDown(e.nativeEvent, true, e.currentTarget);
|
|
78
|
+
}
|
|
79
|
+
} : {}), {
|
|
80
|
+
style: style
|
|
81
|
+
}))
|
|
82
|
+
});
|
|
83
|
+
// 统一的拖拽处理函数
|
|
84
|
+
function handlePointerDown(startEvent, isTouch, currentTarget) {
|
|
85
|
+
var _a;
|
|
86
|
+
window.addEventListener('selectstart', disableSelect);
|
|
87
|
+
var columnMoved = false;
|
|
88
|
+
var columns = pipeline.getColumns();
|
|
89
|
+
var _pipeline$getStateAtK2 = pipeline.getStateAtKey(stateKey, {}),
|
|
90
|
+
cloumnsTranslateData = _pipeline$getStateAtK2.cloumnsTranslateData;
|
|
91
|
+
var cloumnsSortData = {};
|
|
92
|
+
columns.forEach(function (item, index) {
|
|
93
|
+
cloumnsSortData[item.code] = index;
|
|
94
|
+
});
|
|
95
|
+
var rect = (_a = currentTarget.parentElement) === null || _a === void 0 ? void 0 : _a.getClientRects()[0];
|
|
96
|
+
if (!rect) return;
|
|
97
|
+
var startX = direction === 'rtl' ? rect.right : rect.left;
|
|
98
|
+
var startCoordinates = getEventCoordinates(startEvent);
|
|
99
|
+
var mouseDownClientX = startCoordinates.clientX;
|
|
100
|
+
var mouseDownClientY = startCoordinates.clientY;
|
|
101
|
+
var moveData = [];
|
|
102
|
+
var allColumns = collectNodes(columns);
|
|
103
|
+
var tableBodyClientRect = tableBody.getBoundingClientRect();
|
|
104
|
+
var startScrollLeft = pipeline.ref.current.domHelper.virtual.scrollLeft;
|
|
105
|
+
var updateScrollPosition = function updateScrollPosition(client) {
|
|
106
|
+
var clientX = client.clientX;
|
|
107
|
+
var left = tableBodyClientRect.left,
|
|
108
|
+
width = tableBodyClientRect.width;
|
|
109
|
+
if (clientX + SCROLL_SIZE >= left + width) {
|
|
110
|
+
pipeline.ref.current.domHelper.virtual.scrollLeft += SCROLL_SIZE;
|
|
111
|
+
}
|
|
112
|
+
if (clientX - SCROLL_SIZE <= left) {
|
|
113
|
+
pipeline.ref.current.domHelper.virtual.scrollLeft -= SCROLL_SIZE;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
function handlePointerMove(e) {
|
|
117
|
+
// 触摸事件需要阻止默认行为,防止页面滚动
|
|
118
|
+
if (isTouch && e.cancelable) {
|
|
119
|
+
e.preventDefault();
|
|
120
|
+
}
|
|
121
|
+
var coordinates = getEventCoordinates(e);
|
|
122
|
+
var client = {
|
|
123
|
+
clientX: coordinates.clientX,
|
|
124
|
+
clientY: coordinates.clientY
|
|
125
|
+
};
|
|
126
|
+
var scrollDistance = pipeline.ref.current.domHelper.virtual.scrollLeft - startScrollLeft;
|
|
127
|
+
var startPosition = startX - scrollDistance; // 表头最左边起点
|
|
128
|
+
var offsetDistance = direction === 'rtl' ? startPosition - coordinates.clientX : coordinates.clientX - startPosition;
|
|
129
|
+
updateScrollPosition(client);
|
|
130
|
+
if (offsetDistance < 20) {
|
|
131
|
+
return;
|
|
132
|
+
} else {
|
|
133
|
+
e.stopPropagation();
|
|
134
|
+
}
|
|
135
|
+
document.body.style.userSelect = 'none';
|
|
136
|
+
currentTarget.style.cursor = 'move';
|
|
137
|
+
// 重置位置信息
|
|
138
|
+
cloumnsTranslateData = {};
|
|
139
|
+
allColumns.forEach(function (item) {
|
|
140
|
+
cloumnsTranslateData[item.code] = 0;
|
|
141
|
+
});
|
|
142
|
+
// 计算平移位置
|
|
143
|
+
var replaceIndex = 0;
|
|
144
|
+
var totalWitdth = getColumnWidth(columns[replaceIndex]);
|
|
145
|
+
while (totalWitdth < offsetDistance && replaceIndex < columns.length - 1) {
|
|
146
|
+
replaceIndex++;
|
|
147
|
+
totalWitdth += getColumnWidth(columns[replaceIndex]);
|
|
148
|
+
}
|
|
149
|
+
// 需要取最新startIndex, 不能直接用makeRecursiveMapper提供的startIndex(因为map时还没添加选择列、充满列等后面use添加的列)
|
|
150
|
+
var startIndex;
|
|
151
|
+
columns.forEach(function (column, index) {
|
|
152
|
+
if (column.code === col.code) {
|
|
153
|
+
startIndex = index;
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
var optionColumn = columns[startIndex];
|
|
157
|
+
var index = replaceIndex;
|
|
158
|
+
if (startIndex > replaceIndex) {
|
|
159
|
+
// 左移
|
|
160
|
+
while (index < startIndex) {
|
|
161
|
+
var _columns$index = columns[index],
|
|
162
|
+
code = _columns$index.code,
|
|
163
|
+
lock = _columns$index.lock,
|
|
164
|
+
width = _columns$index.width,
|
|
165
|
+
children = _columns$index.children;
|
|
166
|
+
if (enableMove({
|
|
167
|
+
code: code,
|
|
168
|
+
lock: lock
|
|
169
|
+
})) {
|
|
170
|
+
cloumnsTranslateData[code] += _adjustTranslation(optionColumn.width);
|
|
171
|
+
if (isLeafNode(columns[index])) {
|
|
172
|
+
cloumnsTranslateData[optionColumn.code] -= _adjustTranslation(width);
|
|
173
|
+
} else {
|
|
174
|
+
cloumnsTranslateData[optionColumn.code] -= _adjustTranslation(getColumnWidth(columns[index]));
|
|
175
|
+
moveAllChildren(children, cloumnsTranslateData, _adjustTranslation(optionColumn.width));
|
|
210
176
|
}
|
|
177
|
+
columnMoved = true;
|
|
211
178
|
}
|
|
212
|
-
|
|
213
|
-
pipeline.setStateAtKey(stateKey, {
|
|
214
|
-
cloumnsTranslateData: cloumnsTranslateData
|
|
215
|
-
});
|
|
216
|
-
moveData = [startIndex, replaceIndex];
|
|
217
|
-
});
|
|
179
|
+
index++;
|
|
218
180
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
181
|
+
} else if (startIndex < replaceIndex) {
|
|
182
|
+
// 右移
|
|
183
|
+
while (startIndex < index) {
|
|
184
|
+
var _columns$index2 = columns[index],
|
|
185
|
+
_code = _columns$index2.code,
|
|
186
|
+
_lock = _columns$index2.lock,
|
|
187
|
+
_width = _columns$index2.width,
|
|
188
|
+
_children = _columns$index2.children;
|
|
189
|
+
if (enableMove({
|
|
190
|
+
code: _code,
|
|
191
|
+
lock: _lock
|
|
192
|
+
})) {
|
|
193
|
+
cloumnsTranslateData[_code] -= _adjustTranslation(optionColumn.width);
|
|
194
|
+
if (isLeafNode(columns[index])) {
|
|
195
|
+
cloumnsTranslateData[optionColumn.code] += _adjustTranslation(_width);
|
|
196
|
+
} else {
|
|
197
|
+
cloumnsTranslateData[optionColumn.code] += _adjustTranslation(getColumnWidth(columns[index]));
|
|
198
|
+
moveAllChildren(_children, cloumnsTranslateData, _adjustTranslation(optionColumn.width), true);
|
|
199
|
+
}
|
|
200
|
+
columnMoved = true;
|
|
226
201
|
}
|
|
202
|
+
index--;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
window.requestAnimationFrame(function () {
|
|
206
|
+
pipeline.setStateAtKey(stateKey, {
|
|
207
|
+
cloumnsTranslateData: cloumnsTranslateData
|
|
208
|
+
});
|
|
209
|
+
moveData = [startIndex, replaceIndex];
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
function handlePointerUp(e) {
|
|
213
|
+
removePointerEventListeners(document.body, {
|
|
214
|
+
onPointerMove: handlePointerMove,
|
|
215
|
+
onPointerUp: handlePointerUp
|
|
216
|
+
}, isTouch);
|
|
217
|
+
window.removeEventListener('selectstart', disableSelect);
|
|
218
|
+
var endCoordinates = getEventCoordinates(e);
|
|
219
|
+
if (hasMovedEnough(mouseDownClientX, mouseDownClientY, endCoordinates.clientX, endCoordinates.clientY)) {
|
|
220
|
+
e.stopPropagation(); // 存在移动就阻止冒泡
|
|
221
|
+
currentTarget.addEventListener('click', stopClickPropagation); // 阻止列头点击事件,防止拖动后触发列头过滤事件
|
|
222
|
+
}
|
|
227
223
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
lock = _columns$index3.lock;
|
|
252
|
-
if (enableMove({
|
|
253
|
-
code: code,
|
|
254
|
-
lock: lock
|
|
255
|
-
})) {
|
|
256
|
-
cloumnsSortData[code] += 1;
|
|
257
|
-
cloumnsSortData[optionColumn.code] -= 1;
|
|
258
|
-
columnMoved = true;
|
|
259
|
-
}
|
|
260
|
-
index++;
|
|
261
|
-
}
|
|
262
|
-
} else if (startIndex < replaceIndex) {
|
|
263
|
-
// 右移
|
|
264
|
-
while (index > startIndex) {
|
|
265
|
-
var _columns$index4 = columns[index],
|
|
266
|
-
_code2 = _columns$index4.code,
|
|
267
|
-
_lock2 = _columns$index4.lock;
|
|
268
|
-
if (enableMove({
|
|
269
|
-
code: _code2,
|
|
270
|
-
lock: _lock2
|
|
271
|
-
})) {
|
|
272
|
-
cloumnsSortData[_code2] -= 1;
|
|
273
|
-
cloumnsSortData[optionColumn.code] += 1;
|
|
274
|
-
columnMoved = true;
|
|
275
|
-
}
|
|
276
|
-
index--;
|
|
277
|
-
}
|
|
224
|
+
window.requestAnimationFrame(function () {
|
|
225
|
+
// 取消阻止列头点击事件
|
|
226
|
+
currentTarget.removeEventListener('click', stopClickPropagation);
|
|
227
|
+
currentTarget = null;
|
|
228
|
+
var _moveData = moveData,
|
|
229
|
+
_moveData2 = _slicedToArray(_moveData, 2),
|
|
230
|
+
startIndex = _moveData2[0],
|
|
231
|
+
replaceIndex = _moveData2[1];
|
|
232
|
+
var optionColumn = columns[startIndex];
|
|
233
|
+
var index = replaceIndex;
|
|
234
|
+
if (startIndex > replaceIndex) {
|
|
235
|
+
// 左移
|
|
236
|
+
while (index < startIndex) {
|
|
237
|
+
var _columns$index3 = columns[index],
|
|
238
|
+
code = _columns$index3.code,
|
|
239
|
+
lock = _columns$index3.lock;
|
|
240
|
+
if (enableMove({
|
|
241
|
+
code: code,
|
|
242
|
+
lock: lock
|
|
243
|
+
})) {
|
|
244
|
+
cloumnsSortData[code] += 1;
|
|
245
|
+
cloumnsSortData[optionColumn.code] -= 1;
|
|
246
|
+
columnMoved = true;
|
|
278
247
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
248
|
+
index++;
|
|
249
|
+
}
|
|
250
|
+
} else if (startIndex < replaceIndex) {
|
|
251
|
+
// 右移
|
|
252
|
+
while (index > startIndex) {
|
|
253
|
+
var _columns$index4 = columns[index],
|
|
254
|
+
_code2 = _columns$index4.code,
|
|
255
|
+
_lock2 = _columns$index4.lock;
|
|
256
|
+
if (enableMove({
|
|
257
|
+
code: _code2,
|
|
258
|
+
lock: _lock2
|
|
259
|
+
})) {
|
|
260
|
+
cloumnsSortData[_code2] -= 1;
|
|
261
|
+
cloumnsSortData[optionColumn.code] += 1;
|
|
262
|
+
columnMoved = true;
|
|
292
263
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
264
|
+
index--;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
var onColumnDragStopped = opts.onColumnDragStopped;
|
|
268
|
+
// 拖拽结束返回列顺序
|
|
269
|
+
if (onColumnDragStopped) {
|
|
270
|
+
var _context;
|
|
271
|
+
var isRowDragColumn = function isRowDragColumn(code) {
|
|
272
|
+
var rowDragColumnKey = pipeline.getFeatureOptions('rowDragColumnKey');
|
|
273
|
+
return code === rowDragColumnKey;
|
|
274
|
+
};
|
|
275
|
+
var newColumns = _filterInstanceProperty(_context = sortColumns(columns, cloumnsSortData)).call(_context, function (column) {
|
|
276
|
+
return column.code !== FILL_COLUMN_CODE && !isRowDragColumn(column.code) && !isSelectColumn(column);
|
|
296
277
|
});
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
currentTarget.style.cursor = '';
|
|
278
|
+
// TODO drag需要在resize之后use,否则这里返回的列对应的宽度不是拖拽后的
|
|
279
|
+
onColumnDragStopped(columnMoved, newColumns);
|
|
300
280
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
style
|
|
307
|
-
|
|
308
|
-
|
|
281
|
+
pipeline.setStateAtKey(stateKey, {
|
|
282
|
+
cloumnsTranslateData: null
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
document.body.style.userSelect = '';
|
|
286
|
+
currentTarget.style.opacity = '';
|
|
287
|
+
currentTarget.style.cursor = '';
|
|
288
|
+
}
|
|
289
|
+
var onColumnDragStart = opts.onColumnDragStart;
|
|
290
|
+
onColumnDragStart && onColumnDragStart(col);
|
|
291
|
+
addPointerEventListeners(document.body, {
|
|
292
|
+
onPointerMove: handlePointerMove,
|
|
293
|
+
onPointerUp: handlePointerUp
|
|
294
|
+
}, isTouch);
|
|
295
|
+
}
|
|
309
296
|
}));
|
|
310
297
|
};
|
|
311
298
|
}
|
|
@@ -333,13 +320,4 @@ function moveAllChildren(cols, cloumnsTranslateData, width, isMinus) {
|
|
|
333
320
|
moveAllChildren(children, cloumnsTranslateData, width);
|
|
334
321
|
}
|
|
335
322
|
});
|
|
336
|
-
}
|
|
337
|
-
function _isMoveWhenClicking(mouseDownClientX, mouseDownClientY, mouseUpClientX, mouseUpClientY) {
|
|
338
|
-
var xDiff = mouseUpClientX - mouseDownClientX;
|
|
339
|
-
var yDiff = mouseUpClientY - mouseDownClientY;
|
|
340
|
-
// 鼠标点按和松开的偏移量大于5px,认为存在移动
|
|
341
|
-
if (Math.sqrt(xDiff * xDiff + yDiff * yDiff) > 5) {
|
|
342
|
-
return true;
|
|
343
|
-
}
|
|
344
|
-
return false;
|
|
345
323
|
}
|
|
@@ -12,6 +12,7 @@ import { mergeCellProps, collectNodes, makeRecursiveMapper, isGroupColumn } from
|
|
|
12
12
|
import { internals } from '../../internals';
|
|
13
13
|
import { Classes } from '../../base/styles';
|
|
14
14
|
import { swapRTLDirection } from '../../base/utils';
|
|
15
|
+
import { getEventCoordinates } from './utils/touchEventUtils';
|
|
15
16
|
var TableHeaderCellResize = styled.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: absolute;\n top: 0;\n ", ": -5px;\n height: 100%;\n width: 10px;\n cursor: ew-resize;\n display: flex;\n flex-direction: column;\n align-items: center;\n z-index:1;\n\n &:after {\n content: \"\";\n position: absolute;\n display: block;\n ", ": calc(50% - 1px);\n width: 1px;\n height: calc(100% - 14px);\n top: 7px;\n }\n"])), function (props) {
|
|
16
17
|
return swapRTLDirection(props.direction, 'right');
|
|
17
18
|
}, function (props) {
|
|
@@ -65,10 +66,12 @@ export function columnResize() {
|
|
|
65
66
|
var _a;
|
|
66
67
|
(_a = opts.doubleClickCallback) === null || _a === void 0 ? void 0 : _a.call(opts, e, col);
|
|
67
68
|
};
|
|
68
|
-
|
|
69
|
+
// 通用的拖拽处理逻辑
|
|
70
|
+
var handleResize = function handleResize(startEvent, col, eventType) {
|
|
69
71
|
window.addEventListener('selectstart', disableSelect);
|
|
70
72
|
var changedColumnSize = {};
|
|
71
|
-
var
|
|
73
|
+
var startCoordinates = getEventCoordinates(startEvent);
|
|
74
|
+
var startX = startCoordinates.clientX;
|
|
72
75
|
var children = col.children,
|
|
73
76
|
code = col.code,
|
|
74
77
|
_col$features = col.features,
|
|
@@ -79,9 +82,22 @@ export function columnResize() {
|
|
|
79
82
|
var realMaxSize = typeof maxWidth === 'number' ? maxWidth : maxSize;
|
|
80
83
|
var columnSize = pipeline.getFeatureOptions(COLUMN_SIZE_KEY);
|
|
81
84
|
var recordColumnSize = columnSize;
|
|
82
|
-
|
|
83
|
-
var
|
|
84
|
-
|
|
85
|
+
// 根据事件类型选择不同的事件监听器
|
|
86
|
+
var moveEventName = eventType === 'mouse' ? 'mousemove' : 'touchmove';
|
|
87
|
+
var endEventName = eventType === 'mouse' ? 'mouseup' : 'touchend';
|
|
88
|
+
var moveEventOptions = eventType === 'touch' ? {
|
|
89
|
+
passive: false
|
|
90
|
+
} : undefined;
|
|
91
|
+
var endEventOptions = eventType === 'touch' ? {
|
|
92
|
+
passive: false
|
|
93
|
+
} : undefined;
|
|
94
|
+
var nextSize$ = fromEvent(window, moveEventName, moveEventOptions).pipe(op.takeUntil(fromEvent(window, endEventName, endEventOptions)), op.map(function (e) {
|
|
95
|
+
// 触摸事件需要阻止默认行为,防止页面滚动
|
|
96
|
+
if (eventType === 'touch' && e.cancelable) {
|
|
97
|
+
e.preventDefault();
|
|
98
|
+
}
|
|
99
|
+
var coordinates = getEventCoordinates(e);
|
|
100
|
+
var movingX = coordinates.clientX;
|
|
85
101
|
var nextColumnSize = _extends({}, columnSize);
|
|
86
102
|
var deltaSum = pipeline.ctx.direction === 'rtl' ? startX - movingX : movingX - startX;
|
|
87
103
|
var deltaRemaining = deltaSum;
|
|
@@ -139,6 +155,19 @@ export function columnResize() {
|
|
|
139
155
|
}
|
|
140
156
|
});
|
|
141
157
|
};
|
|
158
|
+
var handleMouseDown = function handleMouseDown(e, col) {
|
|
159
|
+
e.stopPropagation();
|
|
160
|
+
handleResize(e.nativeEvent, col, 'mouse');
|
|
161
|
+
};
|
|
162
|
+
// 触摸事件处理函数
|
|
163
|
+
var handleTouchStart = function handleTouchStart(e, col) {
|
|
164
|
+
// 阻止触摸事件的默认行为
|
|
165
|
+
if (e.cancelable) {
|
|
166
|
+
e.preventDefault();
|
|
167
|
+
}
|
|
168
|
+
e.stopPropagation();
|
|
169
|
+
handleResize(e.nativeEvent, col, 'touch');
|
|
170
|
+
};
|
|
142
171
|
var isGroup = isGroupColumn(pipeline.getColumns());
|
|
143
172
|
return pipeline.mapColumns(makeRecursiveMapper(function (col) {
|
|
144
173
|
var _a;
|
|
@@ -156,6 +185,9 @@ export function columnResize() {
|
|
|
156
185
|
},
|
|
157
186
|
onMouseDown: function onMouseDown(e) {
|
|
158
187
|
return handleMouseDown(e, col);
|
|
188
|
+
},
|
|
189
|
+
onTouchStart: function onTouchStart(e) {
|
|
190
|
+
return handleTouchStart(e, col);
|
|
159
191
|
}
|
|
160
192
|
}) : /*#__PURE__*/React.createElement(TableHeaderCellResize, {
|
|
161
193
|
direction: pipeline.ctx.direction,
|
|
@@ -165,6 +197,9 @@ export function columnResize() {
|
|
|
165
197
|
},
|
|
166
198
|
onMouseDown: function onMouseDown(e) {
|
|
167
199
|
return handleMouseDown(e, col);
|
|
200
|
+
},
|
|
201
|
+
onTouchStart: function onTouchStart(e) {
|
|
202
|
+
return handleTouchStart(e, col);
|
|
168
203
|
}
|
|
169
204
|
}))),
|
|
170
205
|
headerCellProps: mergeCellProps(col.headerCellProps, {
|