Files
CodeNomad/packages/ui/src/components/instance/shell/useGlobalPointerDrag.ts
Shantur Rathore 8ce7a9b4ee refactor(ui): modularize instance shell
Split InstanceShell2 into focused shell modules (drawer chrome/resize, session context/cache, sidebar, right panel tabs/components) to improve maintainability while preserving behavior.
2026-02-11 08:16:44 +00:00

30 lines
995 B
TypeScript

type GlobalPointerDragHandlers = {
onMouseMove: (event: MouseEvent) => void
onMouseUp: (event: MouseEvent) => void
onTouchMove: (event: TouchEvent) => void
onTouchEnd: (event: TouchEvent) => void
}
type GlobalPointerDrag = {
start: () => void
stop: () => void
}
export function useGlobalPointerDrag(handlers: GlobalPointerDragHandlers): GlobalPointerDrag {
const start = () => {
document.addEventListener("mousemove", handlers.onMouseMove)
document.addEventListener("mouseup", handlers.onMouseUp)
document.addEventListener("touchmove", handlers.onTouchMove, { passive: false })
document.addEventListener("touchend", handlers.onTouchEnd)
}
const stop = () => {
document.removeEventListener("mousemove", handlers.onMouseMove)
document.removeEventListener("mouseup", handlers.onMouseUp)
document.removeEventListener("touchmove", handlers.onTouchMove)
document.removeEventListener("touchend", handlers.onTouchEnd)
}
return { start, stop }
}