Skip to content

Commit

Permalink
decorate draggable event handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
eatyourgreens committed Dec 16, 2024
1 parent b7e94f7 commit 09e19d6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ function InteractionLayer({

function onFinish(event) {
event?.preventDefault?.()
event?.stopPropagation?.()
setCreating(false)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ function draggable(WrappedComponent) {
dragStart = DEFAULT_HANDLER,
dragMove = DEFAULT_HANDLER,
dragEnd = DEFAULT_HANDLER,
onPointerDown,
onPointerMove,
onPointerUp,
...rest
}, ref) {
const { canvas } = useContext(SVGContext)
Expand All @@ -62,6 +65,7 @@ function draggable(WrappedComponent) {
setDragging(true)
pointerId.current = event.pointerId
dragStart({ x, y, pointerId: event.pointerId })
onPointerDown?.(event)
wrappedComponent.current?.setPointerCapture(event.pointerId)
}

Expand All @@ -76,6 +80,7 @@ function draggable(WrappedComponent) {
dragMove({ currentTarget, x, y, pointerId: event.pointerId }, difference)
coords.current = { x, y }
}
onPointerMove?.(event)
}

function onDragEnd(event) {
Expand All @@ -87,6 +92,7 @@ function draggable(WrappedComponent) {
coords.current = { x: null, y: null }
setDragging(false)
pointerId.current = -1
onPointerUp?.(event)
}

return (
Expand Down

0 comments on commit 09e19d6

Please sign in to comment.