export function normalizeLayoutForEditor(layout) { if (!layout?.widgets) return layout return { ...layout, widgets: layout.widgets.map((w) => ({ ...w, config: w.config && typeof w.config === 'object' ? { ...w.config } : {}, })), } } export function moveWidget(layout, index, delta) { const next = [...layout.widgets] const j = index + delta if (j < 0 || j >= next.length) return layout const t = next[index] next[index] = next[j] next[j] = t return { ...layout, widgets: next } } export function toggleWidget(layout, index) { const next = layout.widgets.map((w, i) => (i === index ? { ...w, enabled: !w.enabled } : w)) const anyOn = next.some((w) => w.enabled) if (!anyOn) return layout return { ...layout, widgets: next } }