Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
25 lines
864 B
Plaintext
25 lines
864 B
Plaintext
import { moveItem } from '../../../utils/array.mjs';
|
|
import { mixNumber } from '../../../utils/mix/number.mjs';
|
|
|
|
function checkReorder(order, value, offset, velocity) {
|
|
if (!velocity)
|
|
return order;
|
|
const index = order.findIndex((item) => item.value === value);
|
|
if (index === -1)
|
|
return order;
|
|
const nextOffset = velocity > 0 ? 1 : -1;
|
|
const nextItem = order[index + nextOffset];
|
|
if (!nextItem)
|
|
return order;
|
|
const item = order[index];
|
|
const nextLayout = nextItem.layout;
|
|
const nextItemCenter = mixNumber(nextLayout.min, nextLayout.max, 0.5);
|
|
if ((nextOffset === 1 && item.layout.max + offset > nextItemCenter) ||
|
|
(nextOffset === -1 && item.layout.min + offset < nextItemCenter)) {
|
|
return moveItem(order, index, index + nextOffset);
|
|
}
|
|
return order;
|
|
}
|
|
|
|
export { checkReorder };
|