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.

delete more of the old code

Roman Pominova6fdb77228c2
diff --git a/apps/designer/app/shared/dom-utils/find-closest-child.ts b/apps/designer/app/shared/dom-utils/find-closest-child.ts
deleted file mode 100644
index d88c6bb8c7..0000000000
--- a/apps/designer/app/shared/dom-utils/find-closest-child.ts
+++ /dev/null
@@ -1,66 +0,0 @@
-import type { Coordinate, ClosestChildInfo } from "./types";
-
-const calculateDistance = (coordinate: Coordinate, rect: DOMRect): number => {
- const distanceX = Math.max(
- rect.left - coordinate.x,
- 0,
- coordinate.x - rect.right
- );
- const distanceY = Math.max(
- rect.top - coordinate.y,
- 0,
- coordinate.y - rect.bottom
- );
- return Math.sqrt(distanceX * distanceX + distanceY * distanceY);
-};
-
-const sortNumbers = (a: number, b: number): number => a - b;
-
-// There is a gotcha with relative position, it can have top/right/bottom/left too and so will not
-// be positioned by layout, but we ignore this for now.
-const isPositionedElement = (
- element: Element,
- getComputedStyle: (element: Element) => CSSStyleDeclaration
-): boolean => {
- const { position } = getComputedStyle(element);
- return position !== "static" && position !== "relative";
-};
-
-/**
- * Find the closest element relative to coordinates inside a parent element.
- */
-export const findClosestChild = (
- parentElement: Element,
- coordinate: Coordinate,
- getBoundingClientRect: (element: Element) => DOMRect,
- getComputedStyle: (element: Element) => CSSStyleDeclaration
-): ClosestChildInfo | void => {
- // Collect bounding client rects for all children.
- if (parentElement.children.length === 0) return;
-
- // Find the closest child by coordinate
- const distances = [];
- const distanceElementMap = new Map();
- for (const child of parentElement.children) {
- if (isPositionedElement(child, getComputedStyle)) continue;
- const rect = getBoundingClientRect(child);
- const distance = calculateDistance(coordinate, rect);
- distances.push(distance);
- distanceElementMap.set(distance, child);
- }
-
- distances.sort(sortNumbers);
-
- // For now we are only interested if we are nearing the element from the top or bottom
- const element = distanceElementMap.get(distances[0]);
- const rect = getBoundingClientRect(element);
-
- const relativePosition =
- coordinate.y - rect.top < 0
- ? "before"
- : coordinate.y - rect.bottom > 0
- ? "after"
- : "inside";
-
- return { element, relativePosition };
-};
diff --git a/apps/designer/app/shared/dom-utils/find-insertion-index.ts b/apps/designer/app/shared/dom-utils/find-insertion-index.ts
deleted file mode 100644
index 4cc3e4d2d9..0000000000
--- a/apps/designer/app/shared/dom-utils/find-insertion-index.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import type { DragOverInfo, ClosestChildInfo } from "./types";
-
-export const findInsertionIndex = (
- dragOver: DragOverInfo,
- closestChildInfo: ClosestChildInfo
-): number => {
- const index = [...(dragOver.element?.children || [])].indexOf(
- closestChildInfo.element
- );
- let insertionIndex = 0;
- if (closestChildInfo.relativePosition == "inside") {
- if (dragOver.edge === "top") insertionIndex = index;
- else if (dragOver.edge === "bottom") insertionIndex = index + 1;
- else return 0;
- } else {
- insertionIndex =
- closestChildInfo.relativePosition === "before" ? index - 1 : index + 1;
- }
- if (insertionIndex < 0) return 0;
- return insertionIndex;
-};
diff --git a/apps/designer/app/shared/dom-utils/index.ts b/apps/designer/app/shared/dom-utils/index.ts
deleted file mode 100644
index e4b75bccde..0000000000
--- a/apps/designer/app/shared/dom-utils/index.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-export * from "./find-closest-child";
-export * from "./find-insertion-index";
-export * from "./get-drag-over-info";