@ui-schema/kit-dnd
Version:
Drag and Drop Tools for (not only) UI-Schema
24 lines (23 loc) • 1.04 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.moveDraggedValue = void 0;
var _immutable = require("immutable");
var moveDraggedValue = exports.moveDraggedValue = function moveDraggedValue(store, fromKeys, fromIndex, toKeys, toIndex) {
var item = store.getIn(fromKeys.push(fromIndex));
store = store.updateIn(fromKeys, function () {
var list = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : (0, _immutable.List)();
if ('splice' in list) {
return list.splice(fromIndex, 1);
}
throw new Error('try to move item from list, which is not of type list ' + fromKeys.push(fromIndex).toJS().join('.'));
}).updateIn(toKeys, function () {
var list = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : (0, _immutable.List)();
if ('splice' in list) {
return list.splice(toIndex, 0, item);
}
throw new Error('try to move item to list, which is not of type list ' + toKeys.push(toIndex).toJS().join('.'));
});
return store;
};