UNPKG

@wulperstudio/cms

Version:
64 lines (59 loc) 2.02 kB
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray"; import _extends from "@babel/runtime/helpers/esm/extends"; import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; export var reorderColumn = function reorderColumn(list, startIndex, endIndex) { var result = Array.from(list); var _result$splice = result.splice(startIndex, 1), _result$splice2 = _slicedToArray(_result$splice, 1), removed = _result$splice2[0]; result.splice(endIndex, 0, removed); return result; }; export var reorderData = function reorderData(_ref) { var itemMap = _ref.itemMap, source = _ref.source, destination = _ref.destination; // const current: Array<T> = [...itemMap[source.droppableId]]; var current = _extends({}, itemMap == null ? void 0 : itemMap.filter(function (e) { return e.id === source.droppableId; })[0]); // // const next: Array<T> = [...itemMap[destination.droppableId]]; var next = _extends({}, itemMap == null ? void 0 : itemMap.filter(function (e) { return e.id === destination.droppableId; })[0]); // // const target: T = current[source.index]; var target = current.items[source.index]; // // moving to same list if (source.droppableId === destination.droppableId) { var reordered = reorderColumn(current.items, source.index, destination.index); var _result = _extends({}, itemMap.map(function (e) { if (e.id === current.id) { var data = _extends({}, current, { items: reordered }); return data; } return e; })); return { itemMap: _result }; } // moving to different list // remove from original current.items.splice(source.index, 1); // // insert into next next.items.splice(destination.index, 0, target); var result = _toConsumableArray(itemMap.map(function (e) { if (e.id === next.id) { return next; } if (e.id === current.id) { return current; } return e; })); return { itemMap: result }; };