fix(builder): ordenar template restaurante en carga sin tocar drag libre
This commit is contained in:
@@ -3027,6 +3027,42 @@ const state = {
|
||||
y += estimateFreeDragBlockHeight(b) + 22;
|
||||
});
|
||||
}
|
||||
function applyRestaurantTemplateOrder(blocks){
|
||||
const list = Array.isArray(blocks) ? blocks : [];
|
||||
const rank = {
|
||||
menu: 0,
|
||||
hero: 1,
|
||||
cards: 2,
|
||||
gallery: 3,
|
||||
review: 4,
|
||||
contact: 5,
|
||||
social: 6,
|
||||
map: 7
|
||||
};
|
||||
const indexed = list.map((b, i)=>({ b, i }));
|
||||
indexed.sort((a, z)=>{
|
||||
const ar = Object.prototype.hasOwnProperty.call(rank, a.b?.type) ? rank[a.b.type] : 99;
|
||||
const zr = Object.prototype.hasOwnProperty.call(rank, z.b?.type) ? rank[z.b.type] : 99;
|
||||
if (ar !== zr) return ar - zr;
|
||||
return a.i - z.i;
|
||||
});
|
||||
let y = 20;
|
||||
indexed.forEach(({ b })=>{
|
||||
if (!b) return;
|
||||
b.data = (b.data && typeof b.data === "object") ? b.data : {};
|
||||
if (b.type === "menu"){
|
||||
b.data.width = 100;
|
||||
b.pos = { x: 20, y };
|
||||
y += estimateFreeDragBlockHeight(b) + 18;
|
||||
return;
|
||||
}
|
||||
const currentWidth = Number(b?.data?.width || 92);
|
||||
b.data.width = snapBlockWidth(b.type, currentWidth);
|
||||
b.pos = { x: 20, y };
|
||||
y += estimateFreeDragBlockHeight(b) + 22;
|
||||
});
|
||||
return indexed.map((x)=>x.b);
|
||||
}
|
||||
async function saveContent(){
|
||||
if (isSaving) return;
|
||||
isSaving = true;
|
||||
@@ -3104,10 +3140,14 @@ const state = {
|
||||
// Solo restaurante mantiene modo libre por requerimiento del usuario.
|
||||
state.settings.free_drag = isRestaurante;
|
||||
if (isRestaurante){
|
||||
if (!hasMeaningfulFreeDragPositions(state.blocks) || hasSevereFreeDragOverlap(state.blocks)){
|
||||
const needsTemplateRepair = !state.settings.restaurant_layout_repaired_v1;
|
||||
if (needsTemplateRepair){
|
||||
state.blocks = applyRestaurantTemplateOrder(state.blocks);
|
||||
state.settings.restaurant_layout_repaired_v1 = true;
|
||||
} else if (!hasMeaningfulFreeDragPositions(state.blocks) || hasSevereFreeDragOverlap(state.blocks)){
|
||||
applyStackedFreeDragLayout(state.blocks);
|
||||
normalizeDuplicatedFreeDragPositions(state.blocks);
|
||||
}
|
||||
normalizeDuplicatedFreeDragPositions(state.blocks);
|
||||
}
|
||||
}
|
||||
selectedBlockId = null;
|
||||
@@ -3138,7 +3178,8 @@ const state = {
|
||||
}
|
||||
state.blocks = t.blocks.map(b=>({ ...b, id: makeId(), page: (BUILDER_MODE==="ub24" ? "home" : b.page) }));
|
||||
if (state.settings.free_drag){
|
||||
applyStackedFreeDragLayout(state.blocks);
|
||||
state.blocks = applyRestaurantTemplateOrder(state.blocks);
|
||||
state.settings.restaurant_layout_repaired_v1 = true;
|
||||
}
|
||||
selectedBlockId = null;
|
||||
renderInspector(); renderPreview();
|
||||
|
||||
Reference in New Issue
Block a user