Skip to content

Commit b5f5536

Browse files
Reposition subscribers implemented
1 parent 88e8c9c commit b5f5536

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

‎packages/atri-app-core/src/api/canvasApi.ts‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
83126
subscribeCanvasMachine("select", (context) => {
84127
window.parent?.postMessage({ type: "select", id: context.selected }, "*");
85128
});

‎packages/atri-app-core/src/canvasMachine.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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

197198
function setRepositionDataToNull(context: CanvasMachineContext) {
198199
context.newParent = null;
199200
context.newCanvasZone = null;
201+
context.mousePosition = null;
200202
}
201203

202204
function setLastDropped(

0 commit comments

Comments
 (0)