@@ -9,7 +9,7 @@ import { CursorLayer, CursorLayerCursorTypes } from "./components/canvas/layers/
99import { GraphLayer } from "./components/canvas/layers/graphLayer/GraphLayer" ;
1010import { SelectionLayer } from "./components/canvas/layers/selectionLayer/SelectionLayer" ;
1111import { TGraphColors , TGraphConstants , initGraphColors , initGraphConstants } from "./graphConfig" ;
12- import { GraphEvent , GraphEventParams , GraphEventsDefinitions } from "./graphEvents" ;
12+ import { GraphEvent , GraphEventParams , GraphEventsDefinitions , isGraphEvent } from "./graphEvents" ;
1313import { scheduler } from "./lib/Scheduler" ;
1414import { HitTest } from "./services/HitTest" ;
1515import { Layer , LayerPublicProps } from "./services/Layer" ;
@@ -335,6 +335,25 @@ export class Graph {
335335 cancelable : true ,
336336 } ) ;
337337 this . eventEmitter . dispatchEvent ( event ) ;
338+
339+ /*
340+ * !!!IMPORTANT!!!
341+ * Users or layers must be able to prevent the default drag action.
342+ * Simply subscribing to the "mousedown" event does not allow handling the event at the very end of the chain,
343+ * so manual handling of the event is required here.
344+ *
345+ * In example - NewBlockLayer prevent default drag action to allow duplicate blocks with Alt key.
346+ *
347+ * @example
348+ * ```typescript
349+ * graph.on("mousedown", (event) => {
350+ * event.preventDefault(); // Prevent drag
351+ * });
352+ * ```
353+ * */
354+ if ( eventName === "mousedown" && isGraphEvent ( event ) && ! event . isDefaultPrevented ( ) ) {
355+ this . dragService . handleMouseDown ( event ) ;
356+ }
338357 return event ;
339358 }
340359
0 commit comments