mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-01-02 22:11:35 +00:00
e390c0dd15
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
35 lines
1.3 KiB
TypeScript
35 lines
1.3 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: 2022 The HedgeDoc developers (see AUTHORS file)
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
import { useEffect } from 'react'
|
|
|
|
/**
|
|
* Registers event listener for pointer movement and pointer release on the window object.
|
|
*
|
|
* @param onPointerMovement is triggered if the user moves the pointer over the window
|
|
* @param onPointerRelease is triggered if the pointer is released (touch end or mouse up)
|
|
*/
|
|
export const useBindPointerMovementEventOnWindow = (
|
|
onPointerMovement: (event: MouseEvent | TouchEvent) => void,
|
|
onPointerRelease: () => void
|
|
): void => {
|
|
useEffect(() => {
|
|
const pointerMovement = onPointerMovement
|
|
const pointerRelease = onPointerRelease
|
|
window.addEventListener('touchmove', pointerMovement)
|
|
window.addEventListener('mousemove', pointerMovement)
|
|
window.addEventListener('touchcancel', pointerRelease)
|
|
window.addEventListener('touchend', pointerRelease)
|
|
window.addEventListener('mouseup', pointerRelease)
|
|
|
|
return () => {
|
|
window.removeEventListener('touchmove', pointerMovement)
|
|
window.removeEventListener('mousemove', pointerMovement)
|
|
window.removeEventListener('touchcancel', pointerRelease)
|
|
window.removeEventListener('touchend', pointerRelease)
|
|
window.removeEventListener('mouseup', pointerRelease)
|
|
}
|
|
}, [onPointerMovement, onPointerRelease])
|
|
}
|