@@ -128,6 +128,11 @@ type CanvasMachineContext = {
128128 hovered : string | null ;
129129 selected : string | null ;
130130 lastDropped : string | null ; // string until COMPONENT_RENDERED received, otherwise null
131+ repositionTarget : {
132+ pageX : number ;
133+ pageY : number ;
134+ target : MouseEvent [ "target" ] ;
135+ } | null ;
131136} ;
132137
133138// actions
@@ -179,16 +184,7 @@ function changeComponentLoc(
179184 context : CanvasMachineContext ,
180185 event : MOUSE_MOVE_EVENT
181186) {
182- const { target } = event . event ;
183- if ( target !== null && "closest" in target ) {
184- const parentComp = ( target as HTMLElement ) . closest ( "[data-atri-parent]" ) ;
185- const canvasZone = ( target as HTMLElement ) . closest ( "[data-atri-canvas-id]" ) ;
186- if ( parentComp !== null ) {
187- const parentCompId = parentComp . getAttribute ( "data-atri-comp-id" ) ;
188- const canvasZoneId = canvasZone ?. getAttribute ( "data-atri-canvas-id" ) ;
189- context . mousePosition = event . event ;
190- }
191- }
187+ context . repositionTarget = event . event ;
192188}
193189
194190function setRepositionDataToNull ( context : CanvasMachineContext ) {
@@ -407,6 +403,7 @@ export function createCanvasMachine(id: string) {
407403 hovered : null ,
408404 selected : null ,
409405 lastDropped : null ,
406+ repositionTarget : null ,
410407 } ,
411408 states : {
412409 [ initial ] : {
@@ -509,7 +506,8 @@ export function createCanvasMachine(id: string) {
509506 } ,
510507 states : {
511508 [ repositionIdle ] : {
512- entry : ( ) => {
509+ entry : ( context ) => {
510+ context . repositionTarget = null ;
513511 console . log ( "Entered Reposition Idle State" ) ;
514512 } ,
515513 exit : ( ) => {
@@ -519,7 +517,7 @@ export function createCanvasMachine(id: string) {
519517 [ MOUSE_MOVE ] : {
520518 target : repositionActive ,
521519 cond : isNotInTheSameParent ,
522- actions : [ "emitRepositionStarted" ] ,
520+ actions : [ "emitRepositionStarted" , "changeComponentLoc" ] ,
523521 } ,
524522 } ,
525523 } ,
@@ -536,6 +534,11 @@ export function createCanvasMachine(id: string) {
536534 cond : isInTheSameParent ,
537535 actions : [ "emitRepositionEnded" ] ,
538536 } ,
537+ [ MOUSE_MOVE ] : {
538+ target : repositionActive ,
539+ cond : isNotInTheSameParent ,
540+ actions : [ "emitRepositionStarted" , "changeComponentLoc" ] ,
541+ } ,
539542 } ,
540543 } ,
541544 } ,
0 commit comments