Skip to content

Commit c776166

Browse files
authored
fix: prevent dropping into image instance (#4789)
User reported he was able to drop components into images. Added lookup for containers first and then for matching ones. Testing - add image - try to drop box into it
1 parent bc618d4 commit c776166

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

apps/builder/app/canvas/shared/use-drag-drop.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
getAncestorInstanceSelector,
3131
} from "~/shared/tree-utils";
3232
import {
33+
findClosestContainer,
3334
findClosestInstanceMatchingFragment,
3435
isTreeMatching,
3536
} from "~/shared/matcher";
@@ -67,7 +68,16 @@ const findClosestDroppableInstanceSelector = (
6768
const instances = $instances.get();
6869
const metas = $registeredComponentMetas.get();
6970

70-
let droppableIndex = -1;
71+
// prevent dropping anything into non containers like image
72+
let droppableIndex = findClosestContainer({
73+
metas,
74+
instances,
75+
instanceSelector,
76+
});
77+
if (droppableIndex === -1) {
78+
return;
79+
}
80+
instanceSelector = instanceSelector.slice(droppableIndex);
7181
if (dragPayload?.type === "insert") {
7282
const fragment = getComponentTemplateData(dragPayload.dragComponent);
7383
if (fragment) {

0 commit comments

Comments
 (0)