@@ -68,14 +68,21 @@ export default function Canvas() {
68
68
y : 0 ,
69
69
width : 0 ,
70
70
height : 0 ,
71
- mouseX : 0 ,
72
- mouseY : 0 ,
71
+ pointerX : 0 ,
72
+ pointerY : 0 ,
73
73
} ) ;
74
74
const [ cursor , setCursor ] = useState ( "default" ) ;
75
75
76
76
const canvas = useRef ( null ) ;
77
77
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
+
79
86
const { clientX, clientY } = e ;
80
87
if ( type === ObjectType . TABLE ) {
81
88
const table = tables . find ( ( t ) => t . id === id ) ;
@@ -122,7 +129,12 @@ export default function Canvas() {
122
129
} ) ) ;
123
130
} ;
124
131
125
- const handleMouseMove = ( e ) => {
132
+ /**
133
+ * @param {PointerEvent } e
134
+ */
135
+ const handlePointerMove = ( e ) => {
136
+ if ( ! e . isPrimary ) return ;
137
+
126
138
if ( linking ) {
127
139
const rect = canvas . current . getBoundingClientRect ( ) ;
128
140
setLinkingLine ( {
@@ -164,34 +176,39 @@ export default function Canvas() {
164
176
} else if ( areaResize . id !== - 1 ) {
165
177
if ( areaResize . dir === "none" ) return ;
166
178
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 ;
171
183
setPanning ( { isPanning : false , x : 0 , y : 0 } ) ;
172
184
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 ) ;
175
187
} 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 ) ;
180
192
} 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 ) ;
184
196
} 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 ) ;
188
200
}
189
201
190
202
updateArea ( areaResize . id , { ...newDims } ) ;
191
203
}
192
204
} ;
193
205
194
- const handleMouseDown = ( e ) => {
206
+ /**
207
+ * @param {PointerEvent } e
208
+ */
209
+ const handlePointerDown = ( e ) => {
210
+ if ( ! e . isPrimary ) return ;
211
+
195
212
// don't pan if the sidesheet for editing a table is open
196
213
if (
197
214
selectedElement . element === ObjectType . TABLE &&
@@ -268,7 +285,12 @@ export default function Canvas() {
268
285
}
269
286
} ;
270
287
271
- const handleMouseUp = ( ) => {
288
+ /**
289
+ * @param {PointerEvent } e
290
+ */
291
+ const handlePointerUp = ( e ) => {
292
+ if ( ! e . isPrimary ) return ;
293
+
272
294
if ( coordsDidUpdate ( dragging . element ) ) {
273
295
const info = getMovedElementDetails ( ) ;
274
296
setUndoStack ( ( prev ) => [
@@ -344,8 +366,8 @@ export default function Canvas() {
344
366
y : 0 ,
345
367
width : 0 ,
346
368
height : 0 ,
347
- mouseX : 0 ,
348
- mouseY : 0 ,
369
+ pointerX : 0 ,
370
+ pointerY : 0 ,
349
371
} ) ;
350
372
} ;
351
373
@@ -411,12 +433,12 @@ export default function Canvas() {
411
433
const theme = localStorage . getItem ( "theme" ) ;
412
434
413
435
return (
414
- < div className = "flex-grow h-full" id = "canvas" >
436
+ < div className = "flex-grow h-full touch-none " id = "canvas" >
415
437
< div ref = { canvas } className = "w-full h-full" >
416
438
< svg
417
- onMouseMove = { handleMouseMove }
418
- onMouseDown = { handleMouseDown }
419
- onMouseUp = { handleMouseUp }
439
+ onPointerMove = { handlePointerMove }
440
+ onPointerDown = { handlePointerDown }
441
+ onPointerUp = { handlePointerUp }
420
442
className = "w-full h-full"
421
443
style = { {
422
444
cursor : cursor ,
@@ -464,8 +486,8 @@ export default function Canvas() {
464
486
< Area
465
487
key = { a . id }
466
488
data = { a }
467
- onMouseDown = { ( e ) =>
468
- handleMouseDownOnElement ( e , a . id , ObjectType . AREA )
489
+ onPointerDown = { ( e ) =>
490
+ handlePointerDownOnElement ( e , a . id , ObjectType . AREA )
469
491
}
470
492
setResize = { setAreaResize }
471
493
setInitCoords = { setInitCoords }
@@ -481,8 +503,8 @@ export default function Canvas() {
481
503
setHoveredTable = { setHoveredTable }
482
504
handleGripField = { handleGripField }
483
505
setLinkingLine = { setLinkingLine }
484
- onMouseDown = { ( e ) =>
485
- handleMouseDownOnElement ( e , table . id , ObjectType . TABLE )
506
+ onPointerDown = { ( e ) =>
507
+ handlePointerDownOnElement ( e , table . id , ObjectType . TABLE )
486
508
}
487
509
/>
488
510
) ) }
@@ -497,8 +519,8 @@ export default function Canvas() {
497
519
< Note
498
520
key = { n . id }
499
521
data = { n }
500
- onMouseDown = { ( e ) =>
501
- handleMouseDownOnElement ( e , n . id , ObjectType . NOTE )
522
+ onPointerDown = { ( e ) =>
523
+ handlePointerDownOnElement ( e , n . id , ObjectType . NOTE )
502
524
}
503
525
/>
504
526
) ) }
0 commit comments