Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

fixes

Roman Pominovc5e861992413
diff --git a/apps/designer/app/canvas/shared/use-drag-drop.ts b/apps/designer/app/canvas/shared/use-drag-drop.ts
index 176f0cb034..adbad0c437 100644
--- a/apps/designer/app/canvas/shared/use-drag-drop.ts
+++ b/apps/designer/app/canvas/shared/use-drag-drop.ts
@@ -129,7 +129,7 @@ export const useDragAndDrop = () => {
},
});
- const useDragHandlers = useDrag<Instance>({
+ const dragHandlers = useDrag<Instance>({
isDragItem(element) {
if (rootInstance === undefined || element.id === "") {
return false;
@@ -210,15 +210,15 @@ export const useDragAndDrop = () => {
// because it's closer in the life cycle to when React noramlly calls the "ref" callbacks.
useLayoutEffect(() => {
dropHandlers.rootRef(document.body);
- useDragHandlers.rootRef(document.body);
+ dragHandlers.rootRef(document.body);
window.addEventListener("scroll", dropHandlers.handleScroll);
return () => {
dropHandlers.rootRef(null);
- useDragHandlers.rootRef(null);
+ dragHandlers.rootRef(null);
window.removeEventListener("scroll", dropHandlers.handleScroll);
};
- }, [useDragHandlers, dropHandlers, autoScrollHandlers]);
+ }, [dragHandlers, dropHandlers, autoScrollHandlers]);
// Handle drag from the panel
// ================================================================
diff --git a/packages/design-system/src/components/primitives/dnd/dom-utils.ts b/packages/design-system/src/components/primitives/dnd/dom-utils.ts
index b24f0dfb12..1cb47003f7 100644
--- a/packages/design-system/src/components/primitives/dnd/dom-utils.ts
+++ b/packages/design-system/src/components/primitives/dnd/dom-utils.ts
@@ -41,7 +41,10 @@ export const getLocalChildrenOrientation = (
parent.removeChild(probe);
return {
- type: probeRect.width === 0 ? "horizontal" : "vertical",
+ type:
+ probeRect.width === 0 && probeRect.height > 0
+ ? "horizontal"
+ : "vertical",
reverse: false,
};
}
diff --git a/packages/design-system/src/components/primitives/dnd/geometry-utils.ts b/packages/design-system/src/components/primitives/dnd/geometry-utils.ts
index d96221804d..fc7efd928a 100644
--- a/packages/design-system/src/components/primitives/dnd/geometry-utils.ts
+++ b/packages/design-system/src/components/primitives/dnd/geometry-utils.ts
@@ -121,12 +121,13 @@ export const getPlacementNextTo = (
? "bottom"
: "top";
- const margin = 5;
+ const getMargin = (distnaceToParentEdge: number) =>
+ Math.min(10, Math.max(0, distnaceToParentEdge)) / 2;
if (side === "top") {
return {
x: rect.left,
- y: Math.min(rect.top, Math.max(0, rect.top - margin)),
+ y: rect.top - getMargin(rect.top),
length: rect.width,
direction: "horizontal",
};
@@ -135,10 +136,10 @@ export const getPlacementNextTo = (
if (side === "bottom") {
return {
x: rect.left,
- y: Math.max(
- rect.top + rect.height,
- Math.min(parentRect.height, rect.top + rect.height + margin)
- ),
+ y:
+ rect.top +
+ rect.height +
+ getMargin(parentRect.height - rect.top - rect.height),
length: rect.width,
direction: "horizontal",
};
@@ -146,7 +147,7 @@ export const getPlacementNextTo = (
if (side === "left") {
return {
- x: Math.min(rect.left, Math.max(0, rect.left - margin)),
+ x: rect.left - getMargin(rect.left),
y: rect.top,
length: rect.height,
direction: "vertical",
@@ -154,10 +155,10 @@ export const getPlacementNextTo = (
}
return {
- x: Math.max(
- rect.left + rect.width,
- Math.min(parentRect.width, rect.left + rect.width + margin)
- ),
+ x:
+ rect.left +
+ rect.width +
+ getMargin(parentRect.width - rect.left - rect.width),
y: rect.top,
length: rect.height,
direction: "vertical",