Update the sidebar tab rearranger to use Drag and Drop (again)

This commit is contained in:
Oliver 2026-02-22 23:53:27 -07:00
parent 60034dcee2
commit e28901dcf2
6 changed files with 213 additions and 18 deletions

View file

@ -0,0 +1,31 @@
export function performArraySort(
element,
{ list, targetIndex },
) {
// Case: same position
if (list.indexOf(el => el === element) === targetIndex) {
return Array.from(list);
};
// Case: start of array
if (targetIndex === 0) {
list = list.filter(el => el !== element);
return [element, ...list];
};
// Case: end of array
if (targetIndex === list.length - 1) {
list = list.filter(el => el !== element);
return [...list, element];
};
// Case: middle of array
const front = list
.slice(0, targetIndex)
.filter(el => el !== element);
const back = list
.slice(targetIndex)
.filter(el => el !== element);
return [...front, element, ...back];
};