@@ -174,6 +174,20 @@ function setSelectedComponent(
174174 }
175175}
176176
177+ function changeComponentLoc (
178+ _context : CanvasMachineContext ,
179+ event : MOUSE_UP_EVENT
180+ ) {
181+ const { target } = event . event ;
182+ if ( target !== null && "closest" in target ) {
183+ const comp = ( target as any ) . closest ( "[data-atri-parent]" ) ;
184+ if ( comp !== null ) {
185+ const compId = comp . getAttribute ( "data-atri-comp-id" ) ;
186+ console . log ( "State: changeComponentLoc" , compId ) ;
187+ }
188+ }
189+ }
190+
177191function setLastDropped (
178192 context : CanvasMachineContext ,
179193 event : COMPONENT_CREATED_EVENT
@@ -239,6 +253,10 @@ function isLastDroppedComponent(
239253 return context . lastDropped === event . compId ;
240254}
241255
256+ function selectedNotNull ( context : CanvasMachineContext , event : MOUSE_UP_EVENT ) {
257+ return context . selected !== null ;
258+ }
259+
242260type Callback = (
243261 context : CanvasMachineContext ,
244262 event : CanvasMachineEvent
@@ -511,9 +529,14 @@ export function createCanvasMachine(id: string) {
511529 exit : ( context ) => {
512530 console . log (
513531 "Exited repositionstates repositionIdle" ,
514- repositionIdle
532+ context
515533 ) ;
516534 } ,
535+ on : {
536+ [ MOUSE_DOWN ] : {
537+ target : repositionActive ,
538+ } ,
539+ } ,
517540 } ,
518541 [ repositionActive ] : {
519542 entry : ( context ) => {
@@ -525,9 +548,16 @@ export function createCanvasMachine(id: string) {
525548 exit : ( context ) => {
526549 console . log (
527550 "Exited repositionstates repositionActive" ,
528- repositionIdle
551+ context
529552 ) ;
530553 } ,
554+ on : {
555+ [ MOUSE_UP ] : {
556+ target : repositionIdle ,
557+ cond : selectedNotNull ,
558+ actions : [ "changeComponentLoc" ] ,
559+ } ,
560+ } ,
531561 } ,
532562 } ,
533563 } ,
@@ -603,6 +633,7 @@ export function createCanvasMachine(id: string) {
603633 setSelectedComponent,
604634 setLastDropped,
605635 handleComponentRendered,
636+ changeComponentLoc,
606637 } ,
607638 }
608639 ) ;
0 commit comments