@@ -175,14 +175,15 @@ export class ConnectionLayer extends Layer<
175175
176176 protected handleMouseDown = ( nativeEvent : GraphMouseEvent ) => {
177177 const target = nativeEvent . detail . target ;
178- const event = extractNativeGraphMouseEvent ( nativeEvent ) ;
179- if ( ! event || ! target || ! this . root ?. ownerDocument ) {
178+ const initEvent = extractNativeGraphMouseEvent ( nativeEvent ) ;
179+ if ( ! initEvent || ! target || ! this . root ?. ownerDocument ) {
180180 return ;
181181 }
182+
182183 if (
183184 this . enabled &&
184185 ( ( this . context . graph . rootStore . settings . getConfigFlag ( "useBlocksAnchors" ) && target instanceof Anchor ) ||
185- ( isShiftKeyEvent ( event ) && isBlock ( target ) ) )
186+ ( isShiftKeyEvent ( initEvent ) && isBlock ( target ) ) )
186187 ) {
187188 // Get the source component state
188189 const sourceComponent = target . connectedState ;
@@ -196,7 +197,7 @@ export class ConnectionLayer extends Layer<
196197 nativeEvent . stopPropagation ( ) ;
197198 this . context . graph . dragService . startDrag (
198199 {
199- onStart : ( event , coords ) => this . onStartConnection ( event , new Point ( coords [ 0 ] , coords [ 1 ] ) ) ,
200+ onStart : ( _event , coords ) => this . onStartConnection ( target , new Point ( coords [ 0 ] , coords [ 1 ] ) ) ,
200201 onUpdate : ( event , coords ) => this . onMoveNewConnection ( event , new Point ( coords [ 0 ] , coords [ 1 ] ) ) ,
201202 onEnd : ( _event , coords ) => this . onEndNewConnection ( new Point ( coords [ 0 ] , coords [ 1 ] ) ) ,
202203 } ,
@@ -290,18 +291,11 @@ export class ConnectionLayer extends Layer<
290291 return undefined ;
291292 }
292293
293- private onStartConnection ( event : MouseEvent , point : Point ) {
294- const sourceComponent = this . context . graph . getElementOverPoint ( point , [ Block , Anchor ] ) ;
295-
294+ private onStartConnection ( sourceComponent : Block | Anchor , worldCoords : Point ) {
296295 if ( ! sourceComponent ) {
297296 return ;
298297 }
299298
300- this . sourceComponent = sourceComponent . connectedState ;
301-
302- // Use world coordinates from point instead of screen coordinates
303- this . startState = new Point ( point . x , point . y ) ;
304-
305299 this . context . graph . executеDefaultEventAction (
306300 "connection-create-start" ,
307301 {
@@ -312,19 +306,25 @@ export class ConnectionLayer extends Layer<
312306 anchorId : sourceComponent instanceof Anchor ? sourceComponent . connectedState . id : undefined ,
313307 } ,
314308 ( ) => {
309+ this . sourceComponent = sourceComponent . connectedState ;
315310 if ( sourceComponent instanceof Block ) {
316311 this . context . graph . api . selectBlocks ( [ this . sourceComponent . id ] , true , ESelectionStrategy . REPLACE ) ;
312+ this . startState = new Point ( worldCoords . x , worldCoords . y ) ;
317313 } else if ( sourceComponent instanceof Anchor ) {
314+ const point = sourceComponent . getPosition ( ) ;
315+ this . startState = new Point ( point . x , point . y ) ;
318316 this . context . graph . api . setAnchorSelection ( sourceComponent . props . blockId , sourceComponent . props . id , true ) ;
319317 }
318+
319+ // Use world coordinates from point instead of screen coordinates
320320 }
321321 ) ;
322322
323323 this . performRender ( ) ;
324324 }
325325
326326 private onMoveNewConnection ( event : MouseEvent , point : Point ) {
327- if ( ! this . startState ) {
327+ if ( ! this . startState || ! this . sourceComponent ) {
328328 return ;
329329 }
330330
0 commit comments