88 lines
3 KiB
TypeScript
88 lines
3 KiB
TypeScript
// Module ID: 12659
|
|
// Function ID: 12660
|
|
// Name: DragAndDropUtils
|
|
// Dependencies: [3, 12, 2]
|
|
// Exports: getPositionUpdates, moveItemFromTo
|
|
|
|
// Module 12659 (DragAndDropUtils)
|
|
import LoggerDefault from "Logger" /* 3 */;
|
|
import _modDef12 from "module_12" /* 12 */;
|
|
|
|
function calculatePositionDeltas(arg0) {
|
|
({ oldOrdering, newOrdering, idGetter, existingPositionGetter, ascending } = arg0);
|
|
if (ascending === undefined) {
|
|
ascending = true;
|
|
}
|
|
if (oldOrdering.length !== newOrdering.length) {
|
|
logger.warn("Arrays are not of the same length!", oldOrdering, newOrdering);
|
|
return [];
|
|
} else {
|
|
const mapped = oldOrdering.map(idGetter);
|
|
const sorted = mapped.sort();
|
|
const joined = sorted.join(":");
|
|
const mapped1 = newOrdering.map(idGetter);
|
|
const sorted1 = mapped1.sort();
|
|
const joined1 = sorted1.join(":");
|
|
if (joined !== joined1) {
|
|
logger.warn("Object IDs in the old ordering and the new ordering are not the same.", joined, joined1);
|
|
return [];
|
|
} else {
|
|
const obj2 = {};
|
|
for (let num = 0; num < length; num = num + 1) {
|
|
let idGetterResult = idGetter(oldOrdering[num]);
|
|
obj2[idGetterResult] = existingPositionGetter(oldOrdering[num]);
|
|
}
|
|
const items = [];
|
|
for (let num2 = 0; num2 < length; num2 = num2 + 1) {
|
|
let idGetterResult1 = idGetter(newOrdering[num2]);
|
|
let diff = num2;
|
|
if (!ascending) {
|
|
diff = length - 1 - num2;
|
|
}
|
|
let tmp5 = obj2[idGetterResult1] === diff && existingPositionGetter(newOrdering[num2]) === diff;
|
|
if (!tmp5) {
|
|
let obj = { id: idGetterResult1, position: diff };
|
|
let arr = items.push(obj);
|
|
}
|
|
}
|
|
if (!ascending) {
|
|
const reversed = items.reverse();
|
|
}
|
|
return items;
|
|
}
|
|
}
|
|
}
|
|
function moveItemFromTo(c9, arg1, to) {
|
|
const items = [...c9];
|
|
items.splice(arg1, 1);
|
|
items.splice(to, 0, c9[arg1]);
|
|
return items;
|
|
}
|
|
function getPositionUpdates(arg0) {
|
|
({ objectArray, fromPosition, ascending } = arg0);
|
|
({ toPosition, idGetter, existingPositionGetter } = arg0);
|
|
if (ascending === undefined) {
|
|
ascending = true;
|
|
}
|
|
let values = objectArray;
|
|
if (!Array.isArray(objectArray)) {
|
|
values = _modDef12.values(objectArray);
|
|
}
|
|
const obj2 = { oldOrdering: values, newOrdering: null, idGetter: null, existingPositionGetter: null, ascending: null };
|
|
const items = [...values];
|
|
items.splice(fromPosition, 1);
|
|
items.splice(toPosition, 0, values[fromPosition]);
|
|
obj2.newOrdering = items;
|
|
obj2.idGetter = idGetter;
|
|
obj2.existingPositionGetter = existingPositionGetter;
|
|
obj2.ascending = ascending;
|
|
return calculatePositionDeltas(obj2);
|
|
}
|
|
const logger = new LoggerDefault("DragAndDropUtils");
|
|
const size = fn(2);
|
|
const result = size.fileFinishedImporting("utils/DragAndDropUtils.tsx");
|
|
|
|
export default { moveItemFromTo, calculatePositionDeltas, getPositionUpdates };
|
|
export { calculatePositionDeltas };
|
|
export { moveItemFromTo };
|
|
export { getPositionUpdates };
|