decord/source/utils/DragAndDropUtils.tsx

89 lines
3 KiB
TypeScript
Raw Normal View History

// Module ID: 12545
// Function ID: 12546
// Name: DragAndDropUtils
2026-07-29 08:29:29 +00:00
// Dependencies: [3, 12, 2]
// Exports: getPositionUpdates, moveItemFromTo
2026-07-23 10:11:24 +00:00
// Module 12545 (DragAndDropUtils)
import LoggerDefault from "Logger" /* 3 */;
import _modDef12 from "module_12" /* 12 */;
2026-08-24 06:08:38 +00:00
2026-07-20 16:05:17 +00:00
function calculatePositionDeltas(arg0) {
({ oldOrdering, newOrdering, idGetter, existingPositionGetter, ascending } = arg0);
if (ascending === undefined) {
ascending = true;
}
if (oldOrdering.length !== newOrdering.length) {
2026-08-24 06:08:38 +00:00
logger.warn("Arrays are not of the same length!", oldOrdering, newOrdering);
2026-07-20 16:05:17 +00:00
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) {
2026-08-24 06:08:38 +00:00
logger.warn("Object IDs in the old ordering and the new ordering are not the same.", joined, joined1);
2026-07-20 16:05:17 +00:00
return [];
} else {
const obj2 = {};
2026-07-20 16:05:17 +00:00
for (let num = 0; num < length; num = num + 1) {
let idGetterResult = idGetter(oldOrdering[num]);
obj2[idGetterResult] = existingPositionGetter(oldOrdering[num]);
2026-07-20 16:05:17 +00:00
}
const items = [];
2026-07-29 08:29:29 +00:00
for (let num2 = 0; num2 < length; num2 = num2 + 1) {
let idGetterResult1 = idGetter(newOrdering[num2]);
let diff = num2;
2026-07-20 16:05:17 +00:00
if (!ascending) {
2026-07-29 08:29:29 +00:00
diff = length - 1 - num2;
2026-07-20 16:05:17 +00:00
}
let tmp5 = obj2[idGetterResult1] === diff && existingPositionGetter(newOrdering[num2]) === diff;
2026-07-29 08:29:29 +00:00
if (!tmp5) {
let obj = { id: idGetterResult1, position: diff };
2026-07-20 16:05:17 +00:00
let arr = items.push(obj);
}
}
if (!ascending) {
const reversed = items.reverse();
}
return items;
}
}
}
2026-07-29 08:29:29 +00:00
function moveItemFromTo(c9, arg1, to) {
const items = [...c9];
items.splice(arg1, 1);
items.splice(to, 0, c9[arg1]);
2026-07-20 16:05:17 +00:00
return items;
}
function getPositionUpdates(arg0) {
2026-07-29 08:29:29 +00:00
({ objectArray, fromPosition, ascending } = arg0);
({ toPosition, idGetter, existingPositionGetter } = arg0);
2026-07-20 16:05:17 +00:00
if (ascending === undefined) {
ascending = true;
}
let values = objectArray;
if (!Array.isArray(objectArray)) {
values = _modDef12.values(objectArray);
2026-07-20 16:05:17 +00:00
}
const obj2 = { oldOrdering: values, newOrdering: null, idGetter: null, existingPositionGetter: null, ascending: null };
2026-07-29 08:29:29 +00:00
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);
2026-07-20 16:05:17 +00:00
}
const logger = new LoggerDefault("DragAndDropUtils");
const size = fn(2);
const result = size.fileFinishedImporting("utils/DragAndDropUtils.tsx");
2026-07-20 16:05:17 +00:00
export default { moveItemFromTo, calculatePositionDeltas, getPositionUpdates };
export { calculatePositionDeltas };
export { moveItemFromTo };
export { getPositionUpdates };