Update the sidebar tab rearranger to use Drag and Drop (again)
This commit is contained in:
parent
60034dcee2
commit
e28901dcf2
6 changed files with 213 additions and 18 deletions
31
module/utils/performArraySort.mjs
Normal file
31
module/utils/performArraySort.mjs
Normal 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];
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue