@@ -30,7 +30,8 @@ export type Events =
3030 | KeyUpEvent
3131 | KeyDownEvent
3232 | MouseUpOnExistingPointEvent
33- | MouseWheelEvent ;
33+ | MouseWheelEvent
34+ | contextMenuEvent ;
3435
3536export type OnEvent = ( event : Events , operations : Operations ) => void ;
3637
@@ -118,6 +119,11 @@ export interface KeyDownEvent {
118119 event : KeyboardEvent ;
119120}
120121
122+ export interface contextMenuEvent {
123+ type : 'context_menu_event' ;
124+ event : MouseEvent ;
125+ }
126+
121127export interface Operations {
122128 addPoint ( at : Coordinates ) : PointId ;
123129 movePoint ( pointId : PointId , to : Coordinates ) : void ;
@@ -420,7 +426,7 @@ const useAnnotationEngine = ({
420426 operations ,
421427 ) ;
422428 }
423-
429+
424430 return onEvent (
425431 {
426432 type : 'mouse_move_event' ,
@@ -469,6 +475,17 @@ const useAnnotationEngine = ({
469475 ) ;
470476 } ) ;
471477
478+ const handleContextMenu = ( event : MouseEvent ) =>
479+ handleEvent ( ( ) => {
480+ onEvent (
481+ {
482+ type : 'context_menu_event' ,
483+ event,
484+ } ,
485+ operations ,
486+ ) ;
487+ } ) ;
488+
472489 if ( currentCanvasRef ) {
473490 const canvasRenderingContext = currentCanvasRef . getContext ( '2d' ) ;
474491
@@ -479,6 +496,7 @@ const useAnnotationEngine = ({
479496 currentCanvasRef . addEventListener ( 'wheel' , handleMouseWheel ) ;
480497 document . addEventListener ( 'keyup' , handleKeyUp ) ;
481498 document . addEventListener ( 'keydown' , handleKeyDown ) ;
499+ currentCanvasRef . addEventListener ( "contextmenu" , handleContextMenu ) ;
482500 currentCanvasRef . width = currentCanvasRef . offsetWidth ;
483501 currentCanvasRef . height = currentCanvasRef . offsetHeight ;
484502 renderingContextRef . current = canvasRenderingContext ;
@@ -493,6 +511,7 @@ const useAnnotationEngine = ({
493511 currentCanvasRef . removeEventListener ( 'mousedown' , handleMouseDown ) ;
494512 currentCanvasRef . removeEventListener ( 'mousemove' , handleMouseMove ) ;
495513 currentCanvasRef . removeEventListener ( 'wheel' , handleMouseWheel ) ;
514+ currentCanvasRef . removeEventListener ( "contextmenu" , handleContextMenu ) ;
496515 document . removeEventListener ( 'keyup' , handleKeyUp ) ;
497516 document . removeEventListener ( 'keydown' , handleKeyDown ) ;
498517 }
0 commit comments