Skip to content

Commit bed0d68

Browse files
Updated isInTheSameParent to handle edge cases
1 parent 5d9787a commit bed0d68

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,27 @@ function isInTheSameParent(
264264
context: CanvasMachineContext,
265265
event: MOUSE_MOVE_EVENT
266266
) {
267-
const { target } = event.event;
268-
if (target !== null && "closest" in target) {
269-
const comp = (target as any).closest("[data-atri-parent]");
270-
if (comp !== null) {
271-
const compId = comp.getAttribute("data-atri-comp-id");
272-
return compId === context.selected;
267+
const newTarget = event.event.target;
268+
const currTarget = context.mousePosition?.target;
269+
if (
270+
newTarget !== null &&
271+
"closest" in newTarget &&
272+
currTarget !== null &&
273+
"closest" in currTarget!
274+
) {
275+
const newParent = (newTarget as HTMLElement).closest("[data-atri-parent]");
276+
const currParent = (currTarget as HTMLElement).closest(
277+
"[data-atri-parent]"
278+
);
279+
if (newParent !== null && currParent !== null) {
280+
const newParentCompId = newParent.getAttribute("data-atri-comp-id");
281+
const currParentCompId = currParent.getAttribute("data-atri-comp-id");
282+
console.log(
283+
"Reposition isNotInTheSameParent",
284+
newParentCompId,
285+
currParentCompId
286+
);
287+
return newParentCompId === currParentCompId;
273288
}
274289
}
275290
return false;

0 commit comments

Comments
 (0)