fix(builder): evitar caos de layout cuando free-drag no tiene posiciones validas

This commit is contained in:
komkida91
2026-03-01 14:13:35 +01:00
parent 2cc845eb4d
commit f7a1c2dffc

View File

@@ -2940,6 +2940,15 @@ const state = {
}); });
return true; return true;
} }
function hasMeaningfulFreeDragPositions(blocks){
const nonMenu = (Array.isArray(blocks) ? blocks : []).filter((b)=>b && b.type !== "menu");
if (!nonMenu.length) return false;
const positioned = nonMenu.filter((b)=>{
const p = b && b.pos;
return p && Number.isFinite(Number(p.x)) && Number.isFinite(Number(p.y));
});
return positioned.length >= Math.max(2, Math.ceil(nonMenu.length * 0.5));
}
async function saveContent(){ async function saveContent(){
if (isSaving) return; if (isSaving) return;
isSaving = true; isSaving = true;
@@ -3013,8 +3022,14 @@ const state = {
state.blocks.forEach(b=>{ if (!b.page) b.page = "home"; }); state.blocks.forEach(b=>{ if (!b.page) b.page = "home"; });
state.settings.free_drag = false; state.settings.free_drag = false;
} else { } else {
// Restaurante usa posicionamiento libre para colocar bloques donde el usuario quiera. const savedFreeDrag = typeof state.settings.free_drag === "boolean" ? state.settings.free_drag : false;
state.settings.free_drag = initialRubro === "restaurante"; if (!savedFreeDrag){
state.settings.free_drag = false;
} else {
// Compatibilidad: si un sitio viene marcado como free_drag pero no tiene posiciones
// reales, volvemos a flujo normal para evitar superposicion de bloques.
state.settings.free_drag = hasMeaningfulFreeDragPositions(state.blocks);
}
} }
selectedBlockId = null; selectedBlockId = null;
wireSidebar(); wireSidebar();