When using Mouse Presence, we attach a mouse listener to the ReactFlow element and then need to transform the client coordinates to flow coordinates for dispatch. This requires the use of screenToFlowPosition
screenToFlowPosition though honours the snapToGrid config of the board, meaning the mouse cursor also gets snapped on all receiving clients
It would be helpful to have an escape hatch in screenToFlowPosition and flowToScreenPosition, so that the snapping config can be disabled
[screenToFlowPosition: (position: XYPosition) => {](
|
screenToFlowPosition: (position: XYPosition) => { |
|
const { transform, snapToGrid, snapGrid, domNode } = store.getState(); |
|
|
|
if (!domNode) { |
|
return position; |
|
} |
|
|
|
const { x: domX, y: domY } = domNode.getBoundingClientRect(); |
|
|
|
const correctedPosition = { |
|
x: position.x - domX, |
|
y: position.y - domY, |
|
}; |
|
|
|
return pointToRendererPoint(correctedPosition, transform, snapToGrid, snapGrid || [1, 1]); |
|
}, |
)
Something like this perhaps:
screenToFlowPosition: (position: XYPosition, opts: { snapToGrid?: boolean })
When using Mouse Presence, we attach a mouse listener to the ReactFlow element and then need to transform the client coordinates to flow coordinates for dispatch. This requires the use of screenToFlowPosition
screenToFlowPosition though honours the snapToGrid config of the board, meaning the mouse cursor also gets snapped on all receiving clients
It would be helpful to have an escape hatch in screenToFlowPosition and flowToScreenPosition, so that the snapping config can be disabled
[screenToFlowPosition: (position: XYPosition) => {](
xyflow/packages/react/src/hooks/useViewportHelper.ts
Lines 89 to 104 in a899f9b
Something like this perhaps: