@@ -469,6 +469,20 @@ class EoDrawCanvas extends ReactNextElement implements EoDrawCanvasProps {
469469 } ) ;
470470 } ;
471471
472+ @event ( { type : "canvas.copy" } )
473+ accessor #canvasCopy! : EventEmitter < void > ;
474+
475+ #handleCanvasCopy = ( ) => {
476+ this . #canvasCopy. emit ( ) ;
477+ } ;
478+
479+ @event ( { type : "canvas.paste" } )
480+ accessor #canvasPaste! : EventEmitter < void > ;
481+
482+ #handleCanvasPaste = ( ) => {
483+ this . #canvasPaste. emit ( ) ;
484+ } ;
485+
472486 @method ( )
473487 async dropNode ( {
474488 id,
@@ -720,6 +734,8 @@ class EoDrawCanvas extends ReactNextElement implements EoDrawCanvasProps {
720734 onScaleChange = { this . #handleScaleChange}
721735 onEdgeViewChange = { this . #handleEdgeViewChange}
722736 onDecoratorViewChange = { this . #handleDecoratorViewChange}
737+ onCanvasCopy = { this . #handleCanvasCopy}
738+ onCanvasPaste = { this . #handleCanvasPaste}
723739 />
724740 ) ;
725741 }
@@ -742,6 +758,8 @@ export interface EoDrawCanvasComponentProps extends EoDrawCanvasProps {
742758 onContainerContainerChange ( detail : MoveCellPayload [ ] ) : void ;
743759 onScaleChange ( scale : number ) : void ;
744760 onCanvasContextMenu ( detail : PositionTuple ) : void ;
761+ onCanvasCopy ( ) : void ;
762+ onCanvasPaste ( ) : void ;
745763}
746764
747765export interface DrawCanvasRef {
@@ -808,6 +826,8 @@ function LegacyEoDrawCanvasComponent(
808826 onEdgeViewChange,
809827 onDecoratorViewChange,
810828 onCanvasContextMenu,
829+ onCanvasCopy,
830+ onCanvasPaste,
811831 } : EoDrawCanvasComponentProps ,
812832 ref : React . Ref < DrawCanvasRef >
813833) {
@@ -1388,6 +1408,24 @@ function LegacyEoDrawCanvasComponent(
13881408 } ,
13891409 [ onCanvasContextMenu , onSwitchActiveTarget ]
13901410 ) ;
1411+ // istanbul ignore next
1412+ const handleCanvasKeyDown = useCallback (
1413+ ( event : React . KeyboardEvent < SVGElement > ) => {
1414+ const modKey = / M a c | i P o d | i P h o n e | i P a d / . test ( navigator . platform )
1415+ ? "metaKey"
1416+ : "ctrlKey" ;
1417+ if ( event [ modKey ] ) {
1418+ if ( event . key === "c" ) {
1419+ onCanvasCopy ( ) ;
1420+ event . preventDefault ( ) ;
1421+ } else if ( event . key === "v" ) {
1422+ onCanvasPaste ( ) ;
1423+ event . preventDefault ( ) ;
1424+ }
1425+ }
1426+ } ,
1427+ [ onCanvasCopy , onCanvasPaste ]
1428+ ) ;
13911429 useEffect ( ( ) => {
13921430 const root = rootRef . current ;
13931431 if ( ! root || dragBehavior !== "lasso" ) {
@@ -1440,6 +1478,7 @@ function LegacyEoDrawCanvasComponent(
14401478 return (
14411479 < HoverStateContext . Provider value = { hoverStateContextValue } >
14421480 < svg
1481+ onKeyDown = { handleCanvasKeyDown }
14431482 onContextMenu = { handleCanvasContextMenu }
14441483 width = "100%"
14451484 height = "100%"
0 commit comments