@ui-schema/kit-dnd
Version:
Drag and Drop Tools for (not only) UI-Schema
49 lines (48 loc) • 1.84 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.calcIntentDataKeys = void 0;
var _KitDnd = require("@ui-schema/kit-dnd/KitDnd");
var calcIntentDataKeys = exports.calcIntentDataKeys = function calcIntentDataKeys(_ref) {
var toIndex = _ref.toIndex,
toDataKeys = _ref.toDataKeys,
fromIndex = _ref.fromIndex,
fromDataKeys = _ref.fromDataKeys;
if (fromDataKeys.size < toDataKeys.size) {
var toRelativeLeadingKeys = toDataKeys.slice(0, fromDataKeys.size + 1);
var toIndexRelativeFirst = toRelativeLeadingKeys.last();
var willBeParent = toRelativeLeadingKeys.equals(fromDataKeys.push(fromIndex));
var _wasBeforeRelative = typeof toIndexRelativeFirst === 'number' && toRelativeLeadingKeys.splice(-1, 1).equals(fromDataKeys) && fromIndex < toIndexRelativeFirst;
return {
wasBeforeRelative: _wasBeforeRelative,
willBeParent: willBeParent,
level: _KitDnd.DndIntents.down
};
}
if (fromDataKeys.size > toDataKeys.size) {
var _willBeParent = fromDataKeys.slice(0, (toDataKeys.size || 0) + 1).equals(toDataKeys.push(toIndex));
var willBeDirectRoot = fromDataKeys.equals(toDataKeys.push(toIndex));
return {
isParent: _willBeParent && fromDataKeys.size - toDataKeys.size === 1,
willBeParent: _willBeParent,
willBeDirectRoot: willBeDirectRoot,
level: _KitDnd.DndIntents.up
};
}
var hasSameDirectRoot = fromDataKeys.equals(toDataKeys);
if (!hasSameDirectRoot) {
return {
level: _KitDnd.DndIntents["switch"]
};
}
if (fromIndex === toIndex) {
return undefined;
}
var wasBeforeRelative = fromIndex < toIndex;
return {
wasBeforeRelative: wasBeforeRelative,
level: _KitDnd.DndIntents.same,
container: wasBeforeRelative ? _KitDnd.DndIntents.down : _KitDnd.DndIntents.up
};
};