@@ -68,14 +68,21 @@ export default function Canvas() {
6868 y : 0 ,
6969 width : 0 ,
7070 height : 0 ,
71- mouseX : 0 ,
72- mouseY : 0 ,
71+ pointerX : 0 ,
72+ pointerY : 0 ,
7373 } ) ;
7474 const [ cursor , setCursor ] = useState ( "default" ) ;
7575
7676 const canvas = useRef ( null ) ;
7777
78- const handleMouseDownOnElement = ( e , id , type ) => {
78+ /**
79+ * @param {PointerEvent } e
80+ * @param {* } id
81+ * @param {ObjectType[keyof ObjectType] } type
82+ */
83+ const handlePointerDownOnElement = ( e , id , type ) => {
84+ if ( ! e . isPrimary ) return ;
85+
7986 const { clientX, clientY } = e ;
8087 if ( type === ObjectType . TABLE ) {
8188 const table = tables . find ( ( t ) => t . id === id ) ;
@@ -122,7 +129,12 @@ export default function Canvas() {
122129 } ) ) ;
123130 } ;
124131
125- const handleMouseMove = ( e ) => {
132+ /**
133+ * @param {PointerEvent } e
134+ */
135+ const handlePointerMove = ( e ) => {
136+ if ( ! e . isPrimary ) return ;
137+
126138 if ( linking ) {
127139 const rect = canvas . current . getBoundingClientRect ( ) ;
128140 setLinkingLine ( {
@@ -164,34 +176,39 @@ export default function Canvas() {
164176 } else if ( areaResize . id !== - 1 ) {
165177 if ( areaResize . dir === "none" ) return ;
166178 let newDims = { ...initCoords } ;
167- delete newDims . mouseX ;
168- delete newDims . mouseY ;
169- const mouseX = e . clientX / transform . zoom ;
170- const mouseY = e . clientY / transform . zoom ;
179+ delete newDims . pointerX ;
180+ delete newDims . pointerY ;
181+ const pointerX = e . clientX / transform . zoom ;
182+ const pointerY = e . clientY / transform . zoom ;
171183 setPanning ( { isPanning : false , x : 0 , y : 0 } ) ;
172184 if ( areaResize . dir === "br" ) {
173- newDims . width = initCoords . width + ( mouseX - initCoords . mouseX ) ;
174- newDims . height = initCoords . height + ( mouseY - initCoords . mouseY ) ;
185+ newDims . width = initCoords . width + ( pointerX - initCoords . pointerX ) ;
186+ newDims . height = initCoords . height + ( pointerY - initCoords . pointerY ) ;
175187 } else if ( areaResize . dir === "tl" ) {
176- newDims . x = initCoords . x + ( mouseX - initCoords . mouseX ) ;
177- newDims . y = initCoords . y + ( mouseY - initCoords . mouseY ) ;
178- newDims . width = initCoords . width - ( mouseX - initCoords . mouseX ) ;
179- newDims . height = initCoords . height - ( mouseY - initCoords . mouseY ) ;
188+ newDims . x = initCoords . x + ( pointerX - initCoords . pointerX ) ;
189+ newDims . y = initCoords . y + ( pointerY - initCoords . pointerY ) ;
190+ newDims . width = initCoords . width - ( pointerX - initCoords . pointerX ) ;
191+ newDims . height = initCoords . height - ( pointerY - initCoords . pointerY ) ;
180192 } else if ( areaResize . dir === "tr" ) {
181- newDims . y = initCoords . y + ( mouseY - initCoords . mouseY ) ;
182- newDims . width = initCoords . width + ( mouseX - initCoords . mouseX ) ;
183- newDims . height = initCoords . height - ( mouseY - initCoords . mouseY ) ;
193+ newDims . y = initCoords . y + ( pointerY - initCoords . pointerY ) ;
194+ newDims . width = initCoords . width + ( pointerX - initCoords . pointerX ) ;
195+ newDims . height = initCoords . height - ( pointerY - initCoords . pointerY ) ;
184196 } else if ( areaResize . dir === "bl" ) {
185- newDims . x = initCoords . x + ( mouseX - initCoords . mouseX ) ;
186- newDims . width = initCoords . width - ( mouseX - initCoords . mouseX ) ;
187- newDims . height = initCoords . height + ( mouseY - initCoords . mouseY ) ;
197+ newDims . x = initCoords . x + ( pointerX - initCoords . pointerX ) ;
198+ newDims . width = initCoords . width - ( pointerX - initCoords . pointerX ) ;
199+ newDims . height = initCoords . height + ( pointerY - initCoords . pointerY ) ;
188200 }
189201
190202 updateArea ( areaResize . id , { ...newDims } ) ;
191203 }
192204 } ;
193205
194- const handleMouseDown = ( e ) => {
206+ /**
207+ * @param {PointerEvent } e
208+ */
209+ const handlePointerDown = ( e ) => {
210+ if ( ! e . isPrimary ) return ;
211+
195212 // don't pan if the sidesheet for editing a table is open
196213 if (
197214 selectedElement . element === ObjectType . TABLE &&
@@ -268,7 +285,12 @@ export default function Canvas() {
268285 }
269286 } ;
270287
271- const handleMouseUp = ( ) => {
288+ /**
289+ * @param {PointerEvent } e
290+ */
291+ const handlePointerUp = ( e ) => {
292+ if ( ! e . isPrimary ) return ;
293+
272294 if ( coordsDidUpdate ( dragging . element ) ) {
273295 const info = getMovedElementDetails ( ) ;
274296 setUndoStack ( ( prev ) => [
@@ -344,8 +366,8 @@ export default function Canvas() {
344366 y : 0 ,
345367 width : 0 ,
346368 height : 0 ,
347- mouseX : 0 ,
348- mouseY : 0 ,
369+ pointerX : 0 ,
370+ pointerY : 0 ,
349371 } ) ;
350372 } ;
351373
@@ -411,12 +433,12 @@ export default function Canvas() {
411433 const theme = localStorage . getItem ( "theme" ) ;
412434
413435 return (
414- < div className = "flex-grow h-full" id = "canvas" >
436+ < div className = "flex-grow h-full touch-none " id = "canvas" >
415437 < div ref = { canvas } className = "w-full h-full" >
416438 < svg
417- onMouseMove = { handleMouseMove }
418- onMouseDown = { handleMouseDown }
419- onMouseUp = { handleMouseUp }
439+ onPointerMove = { handlePointerMove }
440+ onPointerDown = { handlePointerDown }
441+ onPointerUp = { handlePointerUp }
420442 className = "w-full h-full"
421443 style = { {
422444 cursor : cursor ,
@@ -464,8 +486,8 @@ export default function Canvas() {
464486 < Area
465487 key = { a . id }
466488 data = { a }
467- onMouseDown = { ( e ) =>
468- handleMouseDownOnElement ( e , a . id , ObjectType . AREA )
489+ onPointerDown = { ( e ) =>
490+ handlePointerDownOnElement ( e , a . id , ObjectType . AREA )
469491 }
470492 setResize = { setAreaResize }
471493 setInitCoords = { setInitCoords }
@@ -481,8 +503,8 @@ export default function Canvas() {
481503 setHoveredTable = { setHoveredTable }
482504 handleGripField = { handleGripField }
483505 setLinkingLine = { setLinkingLine }
484- onMouseDown = { ( e ) =>
485- handleMouseDownOnElement ( e , table . id , ObjectType . TABLE )
506+ onPointerDown = { ( e ) =>
507+ handlePointerDownOnElement ( e , table . id , ObjectType . TABLE )
486508 }
487509 />
488510 ) ) }
@@ -497,8 +519,8 @@ export default function Canvas() {
497519 < Note
498520 key = { n . id }
499521 data = { n }
500- onMouseDown = { ( e ) =>
501- handleMouseDownOnElement ( e , n . id , ObjectType . NOTE )
522+ onPointerDown = { ( e ) =>
523+ handlePointerDownOnElement ( e , n . id , ObjectType . NOTE )
502524 }
503525 />
504526 ) ) }
0 commit comments