File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed
packages/atri-app-core/src Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -80,6 +80,49 @@ subscribeCanvasMachine("upWhileDrag", (context) => {
8080 ) ;
8181 }
8282} ) ;
83+
84+ subscribeCanvasMachine ( "reposition" , ( context ) => {
85+ const canvasZone = ( context . mousePosition ! . target as HTMLElement ) . closest (
86+ "[data-atri-canvas-id]"
87+ ) ;
88+ const parentEl = ( context . mousePosition ! . target as HTMLElement ) . closest (
89+ "[data-atri-parent]"
90+ ) ;
91+ if ( canvasZone ) {
92+ let id = CANVAS_ZONE_ROOT_ID ;
93+ if ( parentEl ) {
94+ id = parentEl . getAttribute ( "data-atri-comp-id" ) ! ;
95+ }
96+ window . parent . postMessage (
97+ {
98+ type : "REDROP_SUCCESSFUL" ,
99+ parent : {
100+ id : id ,
101+ index :
102+ id === CANVAS_ZONE_ROOT_ID
103+ ? getComponentIndexInsideCanvasZone (
104+ canvasZone . getAttribute ( "data-atri-canvas-id" ) ! ,
105+ context . mousePosition !
106+ )
107+ : getComponentIndexInsideParentComponent (
108+ id ,
109+ context . mousePosition !
110+ ) ,
111+ canvasZoneId : canvasZone . getAttribute ( "data-atri-canvas-id" ) ,
112+ } ,
113+ } ,
114+ "*"
115+ ) ;
116+ } else {
117+ window . parent . postMessage (
118+ {
119+ type : "REDROP_FAILED" ,
120+ } ,
121+ "*"
122+ ) ;
123+ }
124+ } ) ;
125+
83126subscribeCanvasMachine ( "select" , ( context ) => {
84127 window . parent ?. postMessage ( { type : "select" , id : context . selected } , "*" ) ;
85128} ) ;
Original file line number Diff line number Diff line change @@ -190,13 +190,15 @@ function changeComponentLoc(
190190 const canvasZoneId = canvasZone ?. getAttribute ( "data-atri-canvas-id" ) ;
191191 context . newParent = parentCompId ;
192192 context . newCanvasZone = canvasZoneId ! ;
193+ context . mousePosition = event . event ;
193194 }
194195 }
195196}
196197
197198function setRepositionDataToNull ( context : CanvasMachineContext ) {
198199 context . newParent = null ;
199200 context . newCanvasZone = null ;
201+ context . mousePosition = null ;
200202}
201203
202204function setLastDropped (
You can’t perform that action at this time.
0 commit comments