17 lines
515 B
JavaScript
17 lines
515 B
JavaScript
|
|
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 }
|
||
|
|
}
|