@kdcloudjs/table 1.2.2-canary.13 → 1.2.2-canary.14-hotfix
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 +540 -331
- 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/base/BlankComponent.d.ts +0 -1
- package/es/table/base/BlankComponent.js +16 -9
- 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 +0 -1
- package/lib/table/base/BlankComponent.js +15 -8
- 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 +2 -1
|
@@ -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, {
|
|
@@ -10,6 +10,7 @@ import cx from 'classnames';
|
|
|
10
10
|
import { Classes } from '../../base/styles';
|
|
11
11
|
import { FeatureName } from '../const';
|
|
12
12
|
import { internals } from '../../internals';
|
|
13
|
+
import { getEventCoordinates, getEventTarget } from './utils/touchEventUtils';
|
|
13
14
|
export var ROW_DRAG_COLUMN_CODE = '$_row_drag_column_&';
|
|
14
15
|
export var rowDragKey = 'rowDragKey';
|
|
15
16
|
export var rowDragOptionsKey = 'rowDragOptions';
|
|
@@ -29,15 +30,14 @@ var defaultRowDragColumn = {
|
|
|
29
30
|
},
|
|
30
31
|
render: function render(value, row, rowIndex) {
|
|
31
32
|
return /*#__PURE__*/React.createElement("svg", {
|
|
32
|
-
viewBox:
|
|
33
|
-
version:
|
|
34
|
-
xmlns:
|
|
35
|
-
"data-icon":
|
|
36
|
-
width:
|
|
37
|
-
height:
|
|
33
|
+
viewBox: "0 0 1024 1024",
|
|
34
|
+
version: "1.1",
|
|
35
|
+
xmlns: "http://www.w3.org/1999/xlink",
|
|
36
|
+
"data-icon": "drag",
|
|
37
|
+
width: "16",
|
|
38
|
+
height: "16"
|
|
38
39
|
}, /*#__PURE__*/React.createElement("path", {
|
|
39
|
-
d:
|
|
40
|
-
"p-id": '4278'
|
|
40
|
+
d: "M298.688 192a64 64 0 1 0 128 0 64 64 0 0 0-128 0z m298.624 0a64 64 0 1 0 128 0 64 64 0 0 0-128 0zM298.688 512a64 64 0 1 0 128 0 64 64 0 0 0-128 0z m298.624 0a64 64 0 1 0 128 0 64 64 0 0 0-128 0z m-298.624 320a64 64 0 1 0 128 0 64 64 0 0 0-128 0z m298.624 0a64 64 0 1 0 128 0 64 64 0 0 0-128 0z"
|
|
41
41
|
}));
|
|
42
42
|
}
|
|
43
43
|
};
|
|
@@ -67,19 +67,19 @@ export function rowDrag(opt) {
|
|
|
67
67
|
var treeModeOptions = getTreeModeOptions();
|
|
68
68
|
var rowDragOptions = getRowDragOptions();
|
|
69
69
|
var allowDragIntoRow = !!treeModeOptions && (rowDragOptions === null || rowDragOptions === void 0 ? void 0 : rowDragOptions.allowDragIntoRow);
|
|
70
|
-
var isLeave = !
|
|
70
|
+
var isLeave = !isPointerOnDropTarget(event, dropZoneTarget);
|
|
71
71
|
var overIndex = -1;
|
|
72
72
|
var direction = 'bottom';
|
|
73
73
|
if (!isLeave && dataSource.length > 0) {
|
|
74
|
-
var overDragItem = getDragRowItem(event
|
|
74
|
+
var overDragItem = getDragRowItem(getEventTarget(event), dropZoneTarget, dataSource);
|
|
75
75
|
if (overDragItem) {
|
|
76
76
|
var rowIndex = overDragItem.rowIndex,
|
|
77
77
|
cell = overDragItem.cell;
|
|
78
78
|
overIndex = rowIndex;
|
|
79
|
-
direction = getDirection(cell, event.clientY, allowDragIntoRow);
|
|
79
|
+
direction = getDirection(cell, getEventCoordinates(event).clientY, allowDragIntoRow);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
-
if (overIndex === -1 && dataSource.length > 0 && dropZoneTarget.contains(event
|
|
82
|
+
if (overIndex === -1 && dataSource.length > 0 && dropZoneTarget.contains(getEventTarget(event))) {
|
|
83
83
|
overIndex = dataSource.length - 1;
|
|
84
84
|
direction = 'bottom';
|
|
85
85
|
}
|
|
@@ -155,9 +155,25 @@ export function rowDrag(opt) {
|
|
|
155
155
|
}
|
|
156
156
|
};
|
|
157
157
|
var onMouseDown = function onMouseDown(event) {
|
|
158
|
+
handlePointerDown(event.nativeEvent);
|
|
159
|
+
};
|
|
160
|
+
// PC 单据移动端显示,兼容移动端的拖拽事件
|
|
161
|
+
var onTouchStart = function onTouchStart(event) {
|
|
162
|
+
// 尝试阻止触摸事件的默认行为,防止页面滚动
|
|
163
|
+
try {
|
|
164
|
+
if (event.cancelable) {
|
|
165
|
+
event.preventDefault();
|
|
166
|
+
}
|
|
167
|
+
} catch (error) {
|
|
168
|
+
// 忽略passive event listener错误
|
|
169
|
+
console.warn('preventDefault failed in passive touch event listener');
|
|
170
|
+
}
|
|
171
|
+
handlePointerDown(event.nativeEvent);
|
|
172
|
+
};
|
|
173
|
+
// 统一的拖拽处理函数
|
|
174
|
+
var handlePointerDown = function handlePointerDown(startEvent) {
|
|
158
175
|
var _a;
|
|
159
|
-
var
|
|
160
|
-
var startDataItem = getDragRowItem(mouseDownEvent.target, tableBody, dataSource);
|
|
176
|
+
var startDataItem = getDragRowItem(getEventTarget(startEvent), tableBody, dataSource);
|
|
161
177
|
if (!startDataItem || startDataItem.code !== rowDragColumn.code) return;
|
|
162
178
|
if ((_a = opt === null || opt === void 0 ? void 0 : opt.isDisabled) === null || _a === void 0 ? void 0 : _a.call(opt, startDataItem.row, startDataItem.rowIndex)) return;
|
|
163
179
|
var isValidDrag = false;
|
|
@@ -169,7 +185,7 @@ export function rowDrag(opt) {
|
|
|
169
185
|
var intervalId = null;
|
|
170
186
|
var expandRowTimeoutId = null;
|
|
171
187
|
var expandRowCallBackList = [];
|
|
172
|
-
var updateScrollPosition = function updateScrollPosition(tableBody,
|
|
188
|
+
var updateScrollPosition = function updateScrollPosition(tableBody, moveEvent) {
|
|
173
189
|
if (opt === null || opt === void 0 ? void 0 : opt.suppressScrollMove) return;
|
|
174
190
|
if (timeoutId) {
|
|
175
191
|
clearTimeout(timeoutId);
|
|
@@ -178,7 +194,7 @@ export function rowDrag(opt) {
|
|
|
178
194
|
clearInterval(intervalId);
|
|
179
195
|
}
|
|
180
196
|
if (!tableBody) return;
|
|
181
|
-
var moveOffset = getScrollMoveOffset(tableBody,
|
|
197
|
+
var moveOffset = getScrollMoveOffset(tableBody, moveEvent);
|
|
182
198
|
if (moveOffset === 0) {
|
|
183
199
|
return;
|
|
184
200
|
}
|
|
@@ -188,30 +204,53 @@ export function rowDrag(opt) {
|
|
|
188
204
|
}, 50);
|
|
189
205
|
}, 500);
|
|
190
206
|
};
|
|
191
|
-
var handleDragStart = function handleDragStart(
|
|
207
|
+
var handleDragStart = function handleDragStart(event) {
|
|
192
208
|
var _a;
|
|
193
|
-
|
|
209
|
+
// 屏蔽默认事件,防止文本选择、框选等
|
|
210
|
+
try {
|
|
211
|
+
if (event.cancelable) {
|
|
212
|
+
event.preventDefault();
|
|
213
|
+
}
|
|
214
|
+
} catch (error) {
|
|
215
|
+
// 忽略passive event listener错误
|
|
216
|
+
console.warn('preventDefault failed in passive event listener');
|
|
217
|
+
}
|
|
218
|
+
// 禁用页面的文本选择
|
|
219
|
+
document.body.style.userSelect = 'none';
|
|
220
|
+
document.body.style.webkitUserSelect = 'none';
|
|
221
|
+
// 添加拖拽状态的CSS类,可以在样式中进一步控制
|
|
222
|
+
document.body.classList.add('row-dragging');
|
|
223
|
+
dragElement = createDragElement(event, tableBody); // 创建拖拽悬浮框
|
|
194
224
|
var isTreeTable = !!pipeline.getFeatureOptions('treeModeOptions');
|
|
195
225
|
dragLine = createDragLine(isTreeTable); // 创建拖拽插入指示线
|
|
196
226
|
var dragText = (opt === null || opt === void 0 ? void 0 : opt.rowDragText) ? (_a = opt === null || opt === void 0 ? void 0 : opt.rowDragText) === null || _a === void 0 ? void 0 : _a.call(opt, startDataItem.row, startDataItem.rowIndex) : "\u7B2C".concat(startDataItem.rowIndex, "\u884C\u5185\u5BB9");
|
|
197
227
|
setDragText(dragElement, dragText); // 设置悬浮框显示文本
|
|
198
228
|
artTable.classList.add(cx(Classes.rowDragging));
|
|
199
229
|
rowDragApi.setDragStatus('start');
|
|
200
|
-
var dragEvent = createDropTargetEvent(currentDropZone,
|
|
230
|
+
var dragEvent = createDropTargetEvent(currentDropZone, event, startDataItem, currentDropZone);
|
|
201
231
|
onDragStart(dragEvent);
|
|
202
232
|
};
|
|
203
|
-
var handleDragMove = function handleDragMove(
|
|
233
|
+
var handleDragMove = function handleDragMove(moveEvent) {
|
|
204
234
|
var _a;
|
|
235
|
+
// 尝试屏蔽默认事件,在passive监听器中可能会失败
|
|
236
|
+
try {
|
|
237
|
+
if (moveEvent.cancelable) {
|
|
238
|
+
moveEvent.preventDefault();
|
|
239
|
+
}
|
|
240
|
+
} catch (error) {
|
|
241
|
+
// 忽略passive event listener错误
|
|
242
|
+
console.warn('preventDefault failed in passive event listener');
|
|
243
|
+
}
|
|
205
244
|
var isRTL = pipeline.ctx.direction === 'rtl';
|
|
206
|
-
positionDragElemment(dragElement,
|
|
245
|
+
positionDragElemment(dragElement, moveEvent, isRTL); // 更新拖拽悬浮框位置
|
|
207
246
|
rowDragApi.setDragStatus('dragging');
|
|
208
247
|
setDragElementIcon(dragElement, 'move');
|
|
209
248
|
var rowDropZones = rowDragApi.getRowDropZone();
|
|
210
249
|
var validDropZones = _concatInstanceProperty(rowDropZones).call(rowDropZones, currentDropZone); // 可放置区域加上自身
|
|
211
250
|
var dropTarget = _findInstanceProperty(validDropZones).call(validDropZones, function (zone) {
|
|
212
|
-
return
|
|
251
|
+
return isPointerOnDropTarget(moveEvent, zone.getContainer());
|
|
213
252
|
}) || null;
|
|
214
|
-
updateScrollPosition(dropTarget === null || dropTarget === void 0 ? void 0 : dropTarget.getContainer(),
|
|
253
|
+
updateScrollPosition(dropTarget === null || dropTarget === void 0 ? void 0 : dropTarget.getContainer(), moveEvent); // 拖拽到底时让滚动条可以滚动
|
|
215
254
|
if (dropTarget !== lastDropTarget) {
|
|
216
255
|
// 拖拽离开表格
|
|
217
256
|
if (lastDropTarget !== null && dropTarget === null) {
|
|
@@ -219,7 +258,7 @@ export function rowDrag(opt) {
|
|
|
219
258
|
setDragElementIcon(dragElement, 'notAllowed');
|
|
220
259
|
hiddenDragLine(dragLine);
|
|
221
260
|
lastDropTarget.getContainer().classList.remove(Classes.rowDragNoData);
|
|
222
|
-
var dragEvent = createDropTargetEvent(lastDropTarget,
|
|
261
|
+
var dragEvent = createDropTargetEvent(lastDropTarget, moveEvent, startDataItem, currentDropZone);
|
|
223
262
|
lastDropTarget.onDragLeave(dragEvent);
|
|
224
263
|
}
|
|
225
264
|
}
|
|
@@ -239,7 +278,7 @@ export function rowDrag(opt) {
|
|
|
239
278
|
dragLine.classList.remove(Classes.treeTableRowDragLine);
|
|
240
279
|
}
|
|
241
280
|
}
|
|
242
|
-
var _dragEvent = createDropTargetEvent(dropTarget,
|
|
281
|
+
var _dragEvent = createDropTargetEvent(dropTarget, moveEvent, startDataItem, currentDropZone);
|
|
243
282
|
dropTarget.onDragEnter(_dragEvent);
|
|
244
283
|
}
|
|
245
284
|
}
|
|
@@ -251,7 +290,7 @@ export function rowDrag(opt) {
|
|
|
251
290
|
positionDragLine({
|
|
252
291
|
lineElement: dragLine,
|
|
253
292
|
dragZone: dropTarget,
|
|
254
|
-
event:
|
|
293
|
+
event: moveEvent,
|
|
255
294
|
isRTL: isRTL
|
|
256
295
|
});
|
|
257
296
|
}
|
|
@@ -268,7 +307,7 @@ export function rowDrag(opt) {
|
|
|
268
307
|
onCollapse = treeModeOptions.onCollapse;
|
|
269
308
|
// 鼠标悬停所在的拖拽行信息
|
|
270
309
|
var dataSource = dropTarget.tableParams.getDataSource();
|
|
271
|
-
var dragItem = getDragRowItem(
|
|
310
|
+
var dragItem = getDragRowItem(getEventTarget(moveEvent), dropTarget.getContainer(), dataSource);
|
|
272
311
|
if (!dragItem) return;
|
|
273
312
|
var row = dragItem.row;
|
|
274
313
|
var _row$treeMetaKey = row[treeMetaKey],
|
|
@@ -283,15 +322,20 @@ export function rowDrag(opt) {
|
|
|
283
322
|
}, 1000);
|
|
284
323
|
}
|
|
285
324
|
if (dropTarget.onDragging) {
|
|
286
|
-
var _dragEvent2 = createDropTargetEvent(dropTarget,
|
|
325
|
+
var _dragEvent2 = createDropTargetEvent(dropTarget, moveEvent, startDataItem, currentDropZone);
|
|
287
326
|
dropTarget.onDragging(_dragEvent2);
|
|
288
327
|
}
|
|
289
328
|
}
|
|
290
329
|
};
|
|
291
|
-
var handleDragStop = function handleDragStop(
|
|
330
|
+
var handleDragStop = function handleDragStop(endEvent) {
|
|
292
331
|
if (!isValidDrag) {
|
|
293
332
|
return;
|
|
294
333
|
}
|
|
334
|
+
// 恢复默认的文本选择功能
|
|
335
|
+
document.body.style.userSelect = '';
|
|
336
|
+
document.body.style.webkitUserSelect = '';
|
|
337
|
+
// 移除拖拽状态的CSS类
|
|
338
|
+
document.body.classList.remove('row-dragging');
|
|
295
339
|
removeElement(dragElement);
|
|
296
340
|
removeElement(dragLine);
|
|
297
341
|
artTable.classList.remove(cx(Classes.rowDragging));
|
|
@@ -306,10 +350,10 @@ export function rowDrag(opt) {
|
|
|
306
350
|
});
|
|
307
351
|
var validDropZones = _concatInstanceProperty(rowDropZones).call(rowDropZones, currentDropZone);
|
|
308
352
|
var dropTarget = _findInstanceProperty(validDropZones).call(validDropZones, function (zone) {
|
|
309
|
-
return
|
|
353
|
+
return isPointerOnDropTarget(endEvent, zone.getContainer());
|
|
310
354
|
});
|
|
311
355
|
if (dropTarget && dropTarget.onDragStop) {
|
|
312
|
-
var dragEvent = createDropTargetEvent(dropTarget,
|
|
356
|
+
var dragEvent = createDropTargetEvent(dropTarget, endEvent, startDataItem, currentDropZone);
|
|
313
357
|
dropTarget.onDragStop(dragEvent);
|
|
314
358
|
}
|
|
315
359
|
while (expandRowCallBackList.length > 0) {
|
|
@@ -317,32 +361,73 @@ export function rowDrag(opt) {
|
|
|
317
361
|
callback();
|
|
318
362
|
}
|
|
319
363
|
};
|
|
320
|
-
|
|
321
|
-
var
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
var
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
364
|
+
// 判断是鼠标事件还是触摸事件,分别监听对应的移动和结束事件
|
|
365
|
+
var isTouchEvent = ('touches' in startEvent);
|
|
366
|
+
if (isTouchEvent) {
|
|
367
|
+
// 触摸事件处理
|
|
368
|
+
var touchmove$ = fromEvent(window, 'touchmove', {
|
|
369
|
+
passive: false
|
|
370
|
+
});
|
|
371
|
+
var touchend$ = fromEvent(window, 'touchend', {
|
|
372
|
+
passive: false
|
|
373
|
+
});
|
|
374
|
+
var touchDragMove$ = touchmove$.pipe(filter(function (moveEvent) {
|
|
375
|
+
var coordinates = getEventCoordinates(moveEvent);
|
|
376
|
+
var startCoordinates = getEventCoordinates(startEvent);
|
|
377
|
+
var moveClientY = coordinates.clientY;
|
|
378
|
+
var startClientY = startCoordinates.clientY;
|
|
379
|
+
// 上下移动偏移量大于5才是有效的拖拽
|
|
380
|
+
if (Math.abs(moveClientY - startClientY) > 5) {
|
|
381
|
+
isValidDrag = true;
|
|
382
|
+
}
|
|
383
|
+
return isValidDrag;
|
|
384
|
+
}), map(function (moveEvent) {
|
|
385
|
+
if (!isDragging) {
|
|
386
|
+
isDragging = true;
|
|
387
|
+
handleDragStart(startEvent);
|
|
388
|
+
handleDragMove(startEvent);
|
|
389
|
+
}
|
|
390
|
+
handleDragMove(moveEvent);
|
|
391
|
+
}), takeUntil(touchend$));
|
|
392
|
+
touchDragMove$.subscribe();
|
|
393
|
+
var touchDragEnd$ = touchend$.pipe(map(function (endEvent) {
|
|
394
|
+
handleDragStop(endEvent);
|
|
395
|
+
})).subscribe({
|
|
396
|
+
next: function next() {
|
|
397
|
+
touchDragEnd$.unsubscribe();
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
} else {
|
|
401
|
+
// 鼠标事件处理
|
|
402
|
+
var mousemove$ = fromEvent(window, 'mousemove');
|
|
403
|
+
var mouseup$ = fromEvent(window, 'mouseup');
|
|
404
|
+
var rowDragMove$ = mousemove$.pipe(filter(function (moveEvent) {
|
|
405
|
+
var coordinates = getEventCoordinates(moveEvent);
|
|
406
|
+
var startCoordinates = getEventCoordinates(startEvent);
|
|
407
|
+
var moveClientY = coordinates.clientY;
|
|
408
|
+
var startClientY = startCoordinates.clientY;
|
|
409
|
+
// 上下移动偏移量大于5才是有效的拖拽
|
|
410
|
+
if (Math.abs(moveClientY - startClientY) > 5) {
|
|
411
|
+
isValidDrag = true;
|
|
412
|
+
}
|
|
413
|
+
return isValidDrag;
|
|
414
|
+
}), map(function (moveEvent) {
|
|
415
|
+
if (!isDragging) {
|
|
416
|
+
isDragging = true;
|
|
417
|
+
handleDragStart(startEvent);
|
|
418
|
+
handleDragMove(startEvent);
|
|
419
|
+
}
|
|
420
|
+
handleDragMove(moveEvent);
|
|
421
|
+
}), takeUntil(mouseup$));
|
|
422
|
+
rowDragMove$.subscribe();
|
|
423
|
+
var rowDragEnd$ = mouseup$.pipe(map(function (endEvent) {
|
|
424
|
+
handleDragStop(endEvent);
|
|
425
|
+
})).subscribe({
|
|
426
|
+
next: function next() {
|
|
427
|
+
rowDragEnd$.unsubscribe();
|
|
428
|
+
}
|
|
429
|
+
});
|
|
430
|
+
}
|
|
346
431
|
};
|
|
347
432
|
var rowDragColumn = (opt === null || opt === void 0 ? void 0 : opt.rowDragColumn) || defaultRowDragColumn;
|
|
348
433
|
pipeline.setFeatureOptions('rowDragColumnKey', rowDragColumn.code);
|
|
@@ -351,7 +436,8 @@ export function rowDrag(opt) {
|
|
|
351
436
|
nextColumns.unshift(rowDragColumn);
|
|
352
437
|
pipeline.columns(nextColumns);
|
|
353
438
|
pipeline.addTableProps({
|
|
354
|
-
onMouseDown: onMouseDown
|
|
439
|
+
onMouseDown: onMouseDown,
|
|
440
|
+
onTouchStart: onTouchStart
|
|
355
441
|
});
|
|
356
442
|
pipeline.appendRowPropsGetter(function (row, rowIndex) {
|
|
357
443
|
var _cx;
|
|
@@ -421,13 +507,13 @@ function isEleInFooter(target) {
|
|
|
421
507
|
}
|
|
422
508
|
return false;
|
|
423
509
|
}
|
|
424
|
-
function createDragElement(
|
|
510
|
+
function createDragElement(event, tableBody) {
|
|
425
511
|
var _context3, _context4;
|
|
426
512
|
var ELEMENT_TEMPLATE = _concatInstanceProperty(_context3 = _concatInstanceProperty(_context4 = "<div class='".concat(Classes.rowDragElement, "'>\n <span class='")).call(_context4, Classes.rowDragElementIcon, "'></span>\n <div class='")).call(_context3, Classes.rowDragElementLabel, "'></div>\n </div>");
|
|
427
513
|
var element = document.createElement('div');
|
|
428
514
|
element.innerHTML = ELEMENT_TEMPLATE;
|
|
429
515
|
var dragElement = element.firstChild;
|
|
430
|
-
var targetRow = findTargetRow(
|
|
516
|
+
var targetRow = findTargetRow(getEventTarget(event), tableBody);
|
|
431
517
|
if (targetRow) {
|
|
432
518
|
var rect = targetRow.getBoundingClientRect();
|
|
433
519
|
dragElement.style.height = rect.height + 'px';
|
|
@@ -472,9 +558,9 @@ function positionDragLine(_ref) {
|
|
|
472
558
|
lineElement.style.display = 'block';
|
|
473
559
|
}
|
|
474
560
|
// 鼠标悬停所在的拖拽行信息
|
|
475
|
-
var dragItem = getDragRowItem(event
|
|
561
|
+
var dragItem = getDragRowItem(getEventTarget(event), tableContainer, dataSource);
|
|
476
562
|
if (!dragItem) {
|
|
477
|
-
if (dataSource.length > 0 && tableContainer.contains(event
|
|
563
|
+
if (dataSource.length > 0 && tableContainer.contains(getEventTarget(event))) {
|
|
478
564
|
var _context5, _context6;
|
|
479
565
|
var _rowIndex = dataSource.length - 1;
|
|
480
566
|
var _row = dataSource[_rowIndex];
|
|
@@ -503,7 +589,7 @@ function positionDragLine(_ref) {
|
|
|
503
589
|
rowIndex = dragItem.rowIndex,
|
|
504
590
|
row = dragItem.row;
|
|
505
591
|
var allowDragInto = isTreeTable && allowDragIntoRow;
|
|
506
|
-
var direction = getDirection(cell, event.clientY, allowDragInto);
|
|
592
|
+
var direction = getDirection(cell, getEventCoordinates(event).clientY, allowDragInto);
|
|
507
593
|
var targetCell = isTreeTable ? tableContainer.querySelector(_concatInstanceProperty(_context7 = "tr[data-rowindex=\"".concat(rowIndex, "\"] .")).call(_context7, Classes.tableExtendCell)) : cell;
|
|
508
594
|
if (!targetCell) return;
|
|
509
595
|
var _getLinePosition2 = getLinePosition({
|
|
@@ -541,8 +627,9 @@ function positionDragElemment(element, event, isRTL) {
|
|
|
541
627
|
var browserWidth = (_b = (_a = document.body) === null || _a === void 0 ? void 0 : _a.clientWidth) !== null && _b !== void 0 ? _b : window.innerHeight || ((_c = document.documentElement) === null || _c === void 0 ? void 0 : _c.clientWidth) || 0;
|
|
542
628
|
var browserHeight = (_e = (_d = document.body) === null || _d === void 0 ? void 0 : _d.clientHeight) !== null && _e !== void 0 ? _e : window.innerHeight || ((_f = document.documentElement) === null || _f === void 0 ? void 0 : _f.clientHeight) || 0;
|
|
543
629
|
var offsetParentSize = getElementRectWithOffset(element.offsetParent);
|
|
544
|
-
var
|
|
545
|
-
|
|
630
|
+
var _getEventCoordinates = getEventCoordinates(event),
|
|
631
|
+
clientX = _getEventCoordinates.clientX,
|
|
632
|
+
clientY = _getEventCoordinates.clientY;
|
|
546
633
|
var top = clientY - offsetParentSize.top - eleHeight / 2;
|
|
547
634
|
var left = clientX - offsetParentSize.left;
|
|
548
635
|
var right = Math.max(browserWidth - clientX, 0);
|
|
@@ -558,12 +645,11 @@ function positionDragElemment(element, event, isRTL) {
|
|
|
558
645
|
right = Math.max(browserWidth + windowScrollX - element.clientWidth, 0);
|
|
559
646
|
}
|
|
560
647
|
if (isRTL) {
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
648
|
+
element.style.right = right + 'px';
|
|
649
|
+
} else {
|
|
650
|
+
element.style.left = left + 'px';
|
|
564
651
|
}
|
|
565
|
-
element.style.
|
|
566
|
-
element.style.top = "".concat(top, "px");
|
|
652
|
+
element.style.top = top + 'px';
|
|
567
653
|
}
|
|
568
654
|
function getElementRectWithOffset(el) {
|
|
569
655
|
var offsetElementRect = el.getBoundingClientRect();
|
|
@@ -630,12 +716,13 @@ function setDragElementIcon(element, iconName) {
|
|
|
630
716
|
elementIcon.appendChild(iconElement);
|
|
631
717
|
}
|
|
632
718
|
function clearElementChildren(element) {
|
|
633
|
-
while (element
|
|
719
|
+
while (element === null || element === void 0 ? void 0 : element.firstChild) {
|
|
634
720
|
element.removeChild(element.firstChild);
|
|
635
721
|
}
|
|
636
722
|
}
|
|
637
|
-
function getScrollMoveOffset(tableBody,
|
|
638
|
-
var
|
|
723
|
+
function getScrollMoveOffset(tableBody, moveEvent) {
|
|
724
|
+
var _getEventCoordinates2 = getEventCoordinates(moveEvent),
|
|
725
|
+
clientY = _getEventCoordinates2.clientY;
|
|
639
726
|
var tableBodyClientRect = tableBody.getBoundingClientRect();
|
|
640
727
|
var top = tableBodyClientRect.top,
|
|
641
728
|
height = tableBodyClientRect.height;
|
|
@@ -653,15 +740,19 @@ function setDragText(element, dragText) {
|
|
|
653
740
|
var stringNode = document.createTextNode(dragTextString);
|
|
654
741
|
elementIcon.appendChild(stringNode);
|
|
655
742
|
}
|
|
656
|
-
function
|
|
657
|
-
|
|
743
|
+
function isPointerOnDropTarget(pointerEvent, target) {
|
|
744
|
+
var eventTarget = getEventTarget(pointerEvent);
|
|
745
|
+
return target.contains(eventTarget);
|
|
658
746
|
}
|
|
659
747
|
function createDropTargetEvent(dropZone, event, dragItem, startDropZone) {
|
|
660
748
|
var dropZoneTarget = dropZone.getContainer();
|
|
661
749
|
var startDropZoneTagret = startDropZone.getContainer();
|
|
662
750
|
var rect = dropZoneTarget.getBoundingClientRect();
|
|
663
|
-
var
|
|
664
|
-
|
|
751
|
+
var _getEventCoordinates3 = getEventCoordinates(event),
|
|
752
|
+
clientX = _getEventCoordinates3.clientX,
|
|
753
|
+
clientY = _getEventCoordinates3.clientY;
|
|
754
|
+
var x = clientX - rect.left;
|
|
755
|
+
var y = clientY - rect.top;
|
|
665
756
|
var startDropZoneOptions = startDropZone.tableParams.getRowDragOptions();
|
|
666
757
|
var startCommonParams = startDropZoneOptions === null || startDropZoneOptions === void 0 ? void 0 : startDropZoneOptions.commonParams;
|
|
667
758
|
var targetEvent = {
|
|
@@ -718,10 +809,8 @@ var getLinePosition = function getLinePosition(_ref2) {
|
|
|
718
809
|
paddingRight = _getElementSize3.paddingRight;
|
|
719
810
|
var expandCellRect = cell.getBoundingClientRect();
|
|
720
811
|
var _row$treeMetaKey2 = row[treeMetaKey],
|
|
721
|
-
rowKey = _row$treeMetaKey2.rowKey,
|
|
722
812
|
depth = _row$treeMetaKey2.depth,
|
|
723
|
-
isLeaf = _row$treeMetaKey2.isLeaf
|
|
724
|
-
expanded = _row$treeMetaKey2.expanded;
|
|
813
|
+
isLeaf = _row$treeMetaKey2.isLeaf;
|
|
725
814
|
var addWidth = isLeaf ? iconWidth + iconGap : 0;
|
|
726
815
|
var indent = iconIndent + depth * indentSize + addWidth;
|
|
727
816
|
var x = expandCellRect.x,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare function getEventCoordinates(event: MouseEvent | TouchEvent): {
|
|
2
|
+
clientX: number;
|
|
3
|
+
clientY: number;
|
|
4
|
+
};
|
|
5
|
+
export declare function getEventTarget(event: MouseEvent | TouchEvent): EventTarget;
|
|
6
|
+
export declare function isTouchEvent(event: MouseEvent | TouchEvent): event is TouchEvent;
|
|
7
|
+
export declare function addPointerEventListeners(element: Element | Window | Document, handlers: {
|
|
8
|
+
onPointerMove: (e: MouseEvent | TouchEvent) => void;
|
|
9
|
+
onPointerUp: (e: MouseEvent | TouchEvent) => void;
|
|
10
|
+
}, isTouchStart: boolean): void;
|
|
11
|
+
export declare function removePointerEventListeners(element: Element | Window | Document, handlers: {
|
|
12
|
+
onPointerMove: (e: MouseEvent | TouchEvent) => void;
|
|
13
|
+
onPointerUp: (e: MouseEvent | TouchEvent) => void;
|
|
14
|
+
}, isTouchStart: boolean): void;
|
|
15
|
+
export declare function hasMovedEnough(startX: number, startY: number, endX: number, endY: number, threshold?: number): boolean;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// 统一获取事件坐标的函数
|
|
2
|
+
export function getEventCoordinates(event) {
|
|
3
|
+
if ('touches' in event && event.touches.length > 0) {
|
|
4
|
+
return {
|
|
5
|
+
clientX: event.touches[0].clientX,
|
|
6
|
+
clientY: event.touches[0].clientY
|
|
7
|
+
};
|
|
8
|
+
} else if ('changedTouches' in event && event.changedTouches.length > 0) {
|
|
9
|
+
return {
|
|
10
|
+
clientX: event.changedTouches[0].clientX,
|
|
11
|
+
clientY: event.changedTouches[0].clientY
|
|
12
|
+
};
|
|
13
|
+
} else {
|
|
14
|
+
return {
|
|
15
|
+
clientX: event.clientX,
|
|
16
|
+
clientY: event.clientY
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
// 获取事件目标元素
|
|
21
|
+
export function getEventTarget(event) {
|
|
22
|
+
if ('touches' in event && event.touches.length > 0) {
|
|
23
|
+
return document.elementFromPoint(event.touches[0].clientX, event.touches[0].clientY);
|
|
24
|
+
}
|
|
25
|
+
// 处理touchend事件,此时touches为空,需要使用changedTouches
|
|
26
|
+
if ('changedTouches' in event && event.changedTouches.length > 0) {
|
|
27
|
+
return document.elementFromPoint(event.changedTouches[0].clientX, event.changedTouches[0].clientY);
|
|
28
|
+
}
|
|
29
|
+
return event.target;
|
|
30
|
+
}
|
|
31
|
+
// 判断是否为触摸事件
|
|
32
|
+
export function isTouchEvent(event) {
|
|
33
|
+
return 'touches' in event;
|
|
34
|
+
}
|
|
35
|
+
// 为元素添加统一的指针事件监听器
|
|
36
|
+
export function addPointerEventListeners(element, handlers, isTouchStart) {
|
|
37
|
+
if (isTouchStart) {
|
|
38
|
+
element.addEventListener('touchmove', handlers.onPointerMove, {
|
|
39
|
+
passive: false
|
|
40
|
+
});
|
|
41
|
+
element.addEventListener('touchend', handlers.onPointerUp, {
|
|
42
|
+
passive: false
|
|
43
|
+
});
|
|
44
|
+
} else {
|
|
45
|
+
element.addEventListener('mousemove', handlers.onPointerMove);
|
|
46
|
+
element.addEventListener('mouseup', handlers.onPointerUp);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// 移除统一的指针事件监听器
|
|
50
|
+
export function removePointerEventListeners(element, handlers, isTouchStart) {
|
|
51
|
+
if (isTouchStart) {
|
|
52
|
+
element.removeEventListener('touchmove', handlers.onPointerMove);
|
|
53
|
+
element.removeEventListener('touchend', handlers.onPointerUp);
|
|
54
|
+
} else {
|
|
55
|
+
element.removeEventListener('mousemove', handlers.onPointerMove);
|
|
56
|
+
element.removeEventListener('mouseup', handlers.onPointerUp);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// 检查是否移动了足够的距离(用于区分点击和拖拽)
|
|
60
|
+
export function hasMovedEnough(startX, startY, endX, endY) {
|
|
61
|
+
var threshold = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 5;
|
|
62
|
+
var xDiff = endX - startX;
|
|
63
|
+
var yDiff = endY - startY;
|
|
64
|
+
return Math.sqrt(xDiff * xDiff + yDiff * yDiff) > threshold;
|
|
65
|
+
}
|