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 Jan 6, 2025
1 parent 80d3784 commit 790937a
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 @@ -111,6 +111,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 @@ -47,6 +47,9 @@ function draggable(WrappedComponent) {
dragStart = DEFAULT_HANDLER,
dragMove = DEFAULT_HANDLER,
dragEnd = DEFAULT_HANDLER,
onPointerDown,
onPointerMove,
onPointerUp,
...rest
}, ref) {
const { canvas } = useContext(SVGContext)
Expand All @@ -63,6 +66,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 @@ -77,6 +81,7 @@ function draggable(WrappedComponent) {
dragMove({ currentTarget, x, y, pointerId: event.pointerId }, difference)
coords.current = { x, y }
}
onPointerMove?.(event)
}

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

return (
Expand Down

0 comments on commit 790937a

Please sign in to comment.