fix(builder): evitar solape en free-drag y auto-reparar posiciones duplicadas
This commit is contained in:
@@ -742,10 +742,11 @@ const state = {
|
|||||||
if (key === "fast") return "12s";
|
if (key === "fast") return "12s";
|
||||||
return "18s";
|
return "18s";
|
||||||
}
|
}
|
||||||
function getDefaultPos(){
|
function getDefaultPos(seedIndex){
|
||||||
const base = 20;
|
const base = 20;
|
||||||
const gap = 120;
|
const gap = 120;
|
||||||
const i = state.blocks.length;
|
const raw = Number(seedIndex);
|
||||||
|
const i = Number.isFinite(raw) && raw >= 0 ? Math.floor(raw) : state.blocks.length;
|
||||||
return { x: base + (i % 2) * 220, y: base + Math.floor(i / 2) * gap };
|
return { x: base + (i % 2) * 220, y: base + Math.floor(i / 2) * gap };
|
||||||
}
|
}
|
||||||
function defaultData(type){
|
function defaultData(type){
|
||||||
@@ -1548,7 +1549,7 @@ const state = {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const visibleBlocks = state.blocks.filter(isBlockVisibleInCanvas);
|
const visibleBlocks = state.blocks.filter(isBlockVisibleInCanvas);
|
||||||
visibleBlocks.forEach((block)=>{
|
visibleBlocks.forEach((block, idx)=>{
|
||||||
const el = document.createElement("div");
|
const el = document.createElement("div");
|
||||||
el.className = "block";
|
el.className = "block";
|
||||||
if (!state.settings.free_drag){ el.removeAttribute("draggable"); }
|
if (!state.settings.free_drag){ el.removeAttribute("draggable"); }
|
||||||
@@ -1556,7 +1557,7 @@ const state = {
|
|||||||
el.dataset.blockType = block.type;
|
el.dataset.blockType = block.type;
|
||||||
el.id = block.id;
|
el.id = block.id;
|
||||||
if (state.settings.free_drag){
|
if (state.settings.free_drag){
|
||||||
const pos = block.pos || getDefaultPos();
|
const pos = block.pos || getDefaultPos(idx);
|
||||||
block.pos = pos;
|
block.pos = pos;
|
||||||
el.style.position = "absolute";
|
el.style.position = "absolute";
|
||||||
el.style.left = "0px";
|
el.style.left = "0px";
|
||||||
@@ -2949,6 +2950,20 @@ const state = {
|
|||||||
});
|
});
|
||||||
return positioned.length >= Math.max(2, Math.ceil(nonMenu.length * 0.5));
|
return positioned.length >= Math.max(2, Math.ceil(nonMenu.length * 0.5));
|
||||||
}
|
}
|
||||||
|
function normalizeDuplicatedFreeDragPositions(blocks){
|
||||||
|
const list = Array.isArray(blocks) ? blocks : [];
|
||||||
|
const positioned = list.filter((b)=>b && b.pos && Number.isFinite(Number(b.pos.x)) && Number.isFinite(Number(b.pos.y)));
|
||||||
|
if (positioned.length < 3) return false;
|
||||||
|
const unique = new Set(positioned.map((b)=>`${Math.round(Number(b.pos.x))}:${Math.round(Number(b.pos.y))}`));
|
||||||
|
if (unique.size >= Math.max(3, Math.ceil(positioned.length * 0.6))) return false;
|
||||||
|
let seq = 0;
|
||||||
|
list.forEach((b)=>{
|
||||||
|
if (!b || b.type === "menu") return;
|
||||||
|
b.pos = getDefaultPos(seq);
|
||||||
|
seq += 1;
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
async function saveContent(){
|
async function saveContent(){
|
||||||
if (isSaving) return;
|
if (isSaving) return;
|
||||||
isSaving = true;
|
isSaving = true;
|
||||||
@@ -3030,6 +3045,9 @@ const state = {
|
|||||||
// reales, volvemos a flujo normal para evitar superposicion de bloques.
|
// reales, volvemos a flujo normal para evitar superposicion de bloques.
|
||||||
state.settings.free_drag = hasMeaningfulFreeDragPositions(state.blocks);
|
state.settings.free_drag = hasMeaningfulFreeDragPositions(state.blocks);
|
||||||
}
|
}
|
||||||
|
if (state.settings.free_drag){
|
||||||
|
normalizeDuplicatedFreeDragPositions(state.blocks);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
selectedBlockId = null;
|
selectedBlockId = null;
|
||||||
wireSidebar();
|
wireSidebar();
|
||||||
|
|||||||
Reference in New Issue
Block a user