fix(builder): detectar solape severo en free-drag y reordenar restaurante

This commit is contained in:
komkida91
2026-03-01 14:30:05 +01:00
parent 14eca53c91
commit 10d8fb8cae

View File

@@ -2976,13 +2976,44 @@ const state = {
function estimateFreeDragBlockHeight(block){
const type = String(block?.type || "").toLowerCase();
if (type === "menu") return 92;
if (type === "hero") return 430;
if (type === "gallery") return 310;
if (type === "map") return 330;
if (type === "contact") return 300;
if (type === "cards") return 250;
if (type === "review") return 220;
return 220;
if (type === "hero") return 520;
if (type === "gallery") return 330;
if (type === "map") return 360;
if (type === "contact") return 340;
if (type === "cards") return 280;
if (type === "review") return 250;
if (type === "social") return 280;
return 240;
}
function hasSevereFreeDragOverlap(blocks){
const list = (Array.isArray(blocks) ? blocks : [])
.filter((b)=>b && b.type !== "menu" && b.pos && Number.isFinite(Number(b.pos.x)) && Number.isFinite(Number(b.pos.y)))
.map((b)=>({
id: b.id,
x: Number(b.pos.x),
y: Number(b.pos.y),
w: Math.max(30, Math.min(100, Number(b?.data?.width || 60))),
h: estimateFreeDragBlockHeight(b)
}));
if (list.length < 2) return false;
let overlaps = 0;
for (let i = 0; i < list.length; i++){
for (let j = i + 1; j < list.length; j++){
const a = list[i];
const b = list[j];
const ax2 = a.x + a.w;
const bx2 = b.x + b.w;
const ay2 = a.y + a.h;
const by2 = b.y + b.h;
const xOverlap = Math.min(ax2, bx2) - Math.max(a.x, b.x);
const yOverlap = Math.min(ay2, by2) - Math.max(a.y, b.y);
if (xOverlap > 6 && yOverlap > 20){
overlaps += 1;
if (overlaps >= 2) return true;
}
}
}
return false;
}
function applyStackedFreeDragLayout(blocks){
const list = Array.isArray(blocks) ? blocks : [];
@@ -3083,7 +3114,7 @@ const state = {
state.settings.free_drag = hasMeaningfulFreeDragPositions(state.blocks);
}
if (state.settings.free_drag){
if (!hasMeaningfulFreeDragPositions(state.blocks)){
if (!hasMeaningfulFreeDragPositions(state.blocks) || hasSevereFreeDragOverlap(state.blocks)){
applyStackedFreeDragLayout(state.blocks);
}
normalizeDuplicatedFreeDragPositions(state.blocks);