This commit is contained in:
@@ -194,9 +194,8 @@ function initMoveObserver(
|
|||||||
},
|
},
|
||||||
callbackThreshold,
|
callbackThreshold,
|
||||||
);
|
);
|
||||||
|
const updatePosition = throttle<MouseEvent | TouchEvent | DragEvent>(
|
||||||
// update position for mouse, touch, and drag events (drag event extends mouse event)
|
(evt) => {
|
||||||
function handleUpdatePositionEvent(evt: MouseEvent | TouchEvent) {
|
|
||||||
const target = getEventTarget(evt);
|
const target = getEventTarget(evt);
|
||||||
const { clientX, clientY } = isTouchEvent(evt)
|
const { clientX, clientY } = isTouchEvent(evt)
|
||||||
? evt.changedTouches[0]
|
? evt.changedTouches[0]
|
||||||
@@ -210,29 +209,10 @@ function initMoveObserver(
|
|||||||
id: mirror.getId(target as INode),
|
id: mirror.getId(target as INode),
|
||||||
timeOffset: Date.now() - timeBaseline,
|
timeOffset: Date.now() - timeBaseline,
|
||||||
});
|
});
|
||||||
}
|
// it is possible DragEvent is undefined even on devices
|
||||||
|
// that support event 'drag'
|
||||||
// separate call for non-drag events, in case DragEvent is not defined
|
|
||||||
const updatePosition = throttle<MouseEvent | TouchEvent>(
|
|
||||||
(evt) => {
|
|
||||||
handleUpdatePositionEvent(evt);
|
|
||||||
wrappedCb(
|
wrappedCb(
|
||||||
evt instanceof MouseEvent
|
typeof DragEvent !== 'undefined' && evt instanceof DragEvent
|
||||||
? IncrementalSource.MouseMove
|
|
||||||
: IncrementalSource.TouchMove,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
threshold,
|
|
||||||
{
|
|
||||||
trailing: false,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
// call for drag events, when DragEvent is defined
|
|
||||||
const updateDragPosition = throttle<MouseEvent | TouchEvent | DragEvent>(
|
|
||||||
(evt) => {
|
|
||||||
handleUpdatePositionEvent(evt);
|
|
||||||
wrappedCb(
|
|
||||||
evt instanceof DragEvent
|
|
||||||
? IncrementalSource.Drag
|
? IncrementalSource.Drag
|
||||||
: evt instanceof MouseEvent
|
: evt instanceof MouseEvent
|
||||||
? IncrementalSource.MouseMove
|
? IncrementalSource.MouseMove
|
||||||
@@ -244,13 +224,10 @@ function initMoveObserver(
|
|||||||
trailing: false,
|
trailing: false,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
// it is possible DragEvent is undefined even on devices
|
|
||||||
// that support event 'drag'
|
|
||||||
const dragEventDefined = typeof DragEvent !== 'undefined';
|
|
||||||
const handlers = [
|
const handlers = [
|
||||||
on('mousemove', updatePosition, doc),
|
on('mousemove', updatePosition, doc),
|
||||||
on('touchmove', updatePosition, doc),
|
on('touchmove', updatePosition, doc),
|
||||||
on('drag', dragEventDefined ? updateDragPosition : updatePosition, doc),
|
on('drag', updatePosition, doc),
|
||||||
];
|
];
|
||||||
return () => {
|
return () => {
|
||||||
handlers.forEach((h) => h());
|
handlers.forEach((h) => h());
|
||||||
|
|||||||
Reference in New Issue
Block a user