@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.
Files changed (29) hide show
  1. package/dist/@kdcloudjs/table.css +1 -1
  2. package/dist/@kdcloudjs/table.js +1050 -459
  3. package/dist/@kdcloudjs/table.js.map +1 -1
  4. package/dist/@kdcloudjs/table.min.css +1 -1
  5. package/dist/@kdcloudjs/table.min.js +8 -8
  6. package/dist/@kdcloudjs/table.min.js.map +1 -1
  7. package/es/table/base/BlankComponent.d.ts +11 -0
  8. package/es/table/base/BlankComponent.js +61 -0
  9. package/es/table/base/helpers/FastScrollManager.d.ts +96 -0
  10. package/es/table/base/helpers/FastScrollManager.js +167 -0
  11. package/es/table/base/table.d.ts +13 -0
  12. package/es/table/base/table.js +126 -73
  13. package/es/table/pipeline/features/columnDrag.js +220 -242
  14. package/es/table/pipeline/features/columnResizeWidth.js +40 -5
  15. package/es/table/pipeline/features/rowDrag.js +169 -80
  16. package/es/table/pipeline/features/utils/touchEventUtils.d.ts +15 -0
  17. package/es/table/pipeline/features/utils/touchEventUtils.js +65 -0
  18. package/lib/table/base/BlankComponent.d.ts +11 -0
  19. package/lib/table/base/BlankComponent.js +75 -0
  20. package/lib/table/base/helpers/FastScrollManager.d.ts +96 -0
  21. package/lib/table/base/helpers/FastScrollManager.js +175 -0
  22. package/lib/table/base/table.d.ts +13 -0
  23. package/lib/table/base/table.js +126 -73
  24. package/lib/table/pipeline/features/columnDrag.js +220 -242
  25. package/lib/table/pipeline/features/columnResizeWidth.js +40 -5
  26. package/lib/table/pipeline/features/rowDrag.js +169 -80
  27. package/lib/table/pipeline/features/utils/touchEventUtils.d.ts +15 -0
  28. package/lib/table/pipeline/features/utils/touchEventUtils.js +76 -0
  29. 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: !isLeaf || path.length > 1 ? undefined : function (e) {
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
- window.addEventListener('selectstart', disableSelect);
77
- // const cx = e.clientX
78
- // const width = col.width
79
- // const a = startIndex
80
- // const b = endIndex
81
- // const newColumnDragData = [...columnDragData]
82
- // let newColumn = [...columns]
83
- // let newStartIndex = startIndex
84
- // let endIdx = endIndex
85
- var columnMoved = false;
86
- var columns = pipeline.getColumns();
87
- var _pipeline$getStateAtK2 = pipeline.getStateAtKey(stateKey, {}),
88
- cloumnsTranslateData = _pipeline$getStateAtK2.cloumnsTranslateData;
89
- var cloumnsSortData = {};
90
- columns.forEach(function (item, index) {
91
- cloumnsSortData[item.code] = index;
92
- });
93
- var currentTarget = e.currentTarget;
94
- var rect = e.currentTarget.parentElement.getClientRects()[0];
95
- var startX = direction === 'rtl' ? rect.right : rect.left;
96
- var mouseDownClientX = e.clientX;
97
- var mouseDownClientY = e.clientY;
98
- var moveData = [];
99
- var allColumns = (0, _utils.collectNodes)(columns);
100
- var tableBodyClientRect = tableBody.getBoundingClientRect();
101
- var startScrollLeft = pipeline.ref.current.domHelper.virtual.scrollLeft;
102
- var updateScrollPosition = function updateScrollPosition(client) {
103
- var clientX = client.clientX;
104
- var left = tableBodyClientRect.left,
105
- width = tableBodyClientRect.width;
106
- if (clientX + SCROLL_SIZE >= left + width) {
107
- pipeline.ref.current.domHelper.virtual.scrollLeft += SCROLL_SIZE;
108
- }
109
- if (clientX - SCROLL_SIZE <= left) {
110
- pipeline.ref.current.domHelper.virtual.scrollLeft -= SCROLL_SIZE;
111
- }
112
- };
113
- function handleMouseMove(e) {
114
- var client = {
115
- clientX: e.clientX,
116
- clientY: e.clientY
117
- };
118
- var scrollDistance = pipeline.ref.current.domHelper.virtual.scrollLeft - startScrollLeft;
119
- var startPosition = startX - scrollDistance; // 表头最左边起点
120
- var offsetDistance = direction === 'rtl' ? startPosition - e.clientX : e.clientX - startPosition;
121
- updateScrollPosition(client);
122
- if (offsetDistance < 20) {
123
- return;
124
- } else {
125
- e.stopPropagation();
126
- }
127
- document.body.style.userSelect = 'none';
128
- currentTarget.style.cursor = 'move';
129
- // 循环计算每一个的位置
130
- // if (startIndex !== replaceIndex) {
131
- // const optionColumn = columns[startIndex]
132
- // const move = startIndex > replaceIndex ? 1 : -1
133
- // let index = Math.min(startIndex, replaceIndex)
134
- // while (index < Math.max(startIndex, replaceIndex)) {
135
- // const code = columns[index].code
136
- // cloumnsTranslateData[code] += move * optionColumn.width
137
- // cloumnsTranslateData[optionColumn.code] -= move * optionColumn.width
138
- // index += move
139
- // }
140
- // }
141
- // const opColumn = columns[startIndex]
142
- // let index = Math.min(startIndex, replaceIndex)
143
- // while (index <= Math.max(startIndex, replaceIndex)) {
144
- // const code = columns[index].code
145
- // if (index !== startIndex && index !== replaceIndex) {
146
- // cloumnsTranslateData[code] += opColumn.width * (index > startIndex ? -1 : 1)
147
- // cloumnsTranslateData[opColumn.code] += columns[index].width * (index < startIndex ? -1 : 1)
148
- // }
149
- // index++
150
- // }
151
- // 重置位置信息
152
- cloumnsTranslateData = {};
153
- allColumns.forEach(function (item) {
154
- cloumnsTranslateData[item.code] = 0;
155
- });
156
- // 计算平移位置
157
- var replaceIndex = 0;
158
- var totalWitdth = getColumnWidth(columns[replaceIndex]);
159
- while (totalWitdth < offsetDistance && replaceIndex < columns.length - 1) {
160
- replaceIndex++;
161
- totalWitdth += getColumnWidth(columns[replaceIndex]);
162
- }
163
- // 需要取最新startIndex, 不能直接用makeRecursiveMapper提供的startIndex(因为map时还没添加选择列、充满列等后面use添加的列)
164
- var startIndex;
165
- columns.forEach(function (column, index) {
166
- if (column.code === col.code) {
167
- startIndex = index;
168
- }
169
- });
170
- var optionColumn = columns[startIndex];
171
- var index = replaceIndex;
172
- if (startIndex > replaceIndex) {
173
- // 左移
174
- while (index < startIndex) {
175
- var _columns$index = columns[index],
176
- code = _columns$index.code,
177
- lock = _columns$index.lock,
178
- width = _columns$index.width,
179
- children = _columns$index.children;
180
- if (enableMove({
181
- code: code,
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
- window.requestAnimationFrame(function () {
220
- pipeline.setStateAtKey(stateKey, {
221
- cloumnsTranslateData: cloumnsTranslateData
222
- });
223
- moveData = [startIndex, replaceIndex];
224
- });
186
+ index++;
225
187
  }
226
- function handleMouseUp(e) {
227
- document.body.removeEventListener('mousemove', handleMouseMove);
228
- document.body.removeEventListener('mouseup', handleMouseUp);
229
- window.removeEventListener('selectstart', disableSelect);
230
- if (_isMoveWhenClicking(mouseDownClientX, mouseDownClientY, e.clientX, e.clientY)) {
231
- e.stopPropagation(); // 存在移动就阻止冒泡
232
- currentTarget.addEventListener('click', stopClickPropagation); // 阻止列头点击事件,防止拖动后触发列头过滤事件
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
- window.requestAnimationFrame(function () {
236
- // 取消阻止列头点击事件
237
- currentTarget.removeEventListener('click', stopClickPropagation);
238
- currentTarget = null;
239
- var _moveData = moveData,
240
- _moveData2 = (0, _slicedToArray2.default)(_moveData, 2),
241
- startIndex = _moveData2[0],
242
- replaceIndex = _moveData2[1];
243
- var optionColumn = columns[startIndex];
244
- // const move = startIndex > replaceIndex ? 1 : -1
245
- // let index = Math.min(startIndex, replaceIndex)
246
- // while (index < Math.max(startIndex, replaceIndex) && index > 0) {
247
- // const code = columns[index].code
248
- // cloumnsSortData[optionColumn.code] -= move
249
- // cloumnsSortData[code] += move
250
- // index += move
251
- // }
252
- var index = replaceIndex;
253
- if (startIndex > replaceIndex) {
254
- // 左移
255
- while (index < startIndex) {
256
- var _columns$index3 = columns[index],
257
- code = _columns$index3.code,
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
- var onColumnDragStopped = opts.onColumnDragStopped;
287
- // 拖拽结束返回列顺序
288
- if (onColumnDragStopped) {
289
- var _context;
290
- var isRowDragColumn = function isRowDragColumn(code) {
291
- var rowDragColumnKey = pipeline.getFeatureOptions('rowDragColumnKey');
292
- return code === rowDragColumnKey;
293
- };
294
- var newColumns = (0, _filter.default)(_context = sortColumns(columns, cloumnsSortData)).call(_context, function (column) {
295
- return column.code !== _autoFill.FILL_COLUMN_CODE && !isRowDragColumn(column.code) && !(0, _utils.isSelectColumn)(column);
296
- });
297
- // TODO drag需要在resize之后use,否则这里返回的列对应的宽度不是拖拽后的
298
- onColumnDragStopped(columnMoved, newColumns);
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
- pipeline.setStateAtKey(stateKey, {
301
- cloumnsTranslateData: null
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
- document.body.style.userSelect = '';
305
- currentTarget.style.opacity = '';
306
- currentTarget.style.cursor = '';
285
+ // TODO drag需要在resize之后use,否则这里返回的列对应的宽度不是拖拽后的
286
+ onColumnDragStopped(columnMoved, newColumns);
307
287
  }
308
- var onColumnDragStart = opts.onColumnDragStart;
309
- onColumnDragStart && onColumnDragStart(col);
310
- document.body.addEventListener('mousemove', handleMouseMove);
311
- document.body.addEventListener('mouseup', handleMouseUp);
312
- },
313
- style: 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
- var handleMouseDown = function handleMouseDown(e, col) {
85
+ // 通用的拖拽处理逻辑
86
+ var handleResize = function handleResize(startEvent, col, eventType) {
85
87
  window.addEventListener('selectstart', disableSelect);
86
88
  var changedColumnSize = {};
87
- var startX = e.clientX;
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
- e.stopPropagation();
99
- var nextSize$ = (0, _rxjs.fromEvent)(window, 'mousemove').pipe(op.takeUntil((0, _rxjs.fromEvent)(window, 'mouseup')), op.map(function (e) {
100
- var movingX = e.clientX;
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, {