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