UNPKG

qtsd-fork

Version:

Do not use this please

79 lines (68 loc) 2.02 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; exports.default = dragOperation; var _without = require('lodash/without'); var _without2 = _interopRequireDefault(_without); var _dragDrop = require('../actions/dragDrop'); var _registry = require('../actions/registry'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var initialState = { itemType: null, item: null, sourceId: null, targetIds: [], dropResult: null, didDrop: false, isSourcePublic: null }; function dragOperation() { var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState; var action = arguments[1]; switch (action.type) { case _dragDrop.BEGIN_DRAG: return _extends({}, state, { itemType: action.itemType, item: action.item, sourceId: action.sourceId, isSourcePublic: action.isSourcePublic, dropResult: null, didDrop: false }); case _dragDrop.PUBLISH_DRAG_SOURCE: return _extends({}, state, { isSourcePublic: true }); case _dragDrop.HOVER: return _extends({}, state, { targetIds: action.targetIds }); case _registry.REMOVE_TARGET: if (state.targetIds.indexOf(action.targetId) === -1) { return state; } return _extends({}, state, { targetIds: (0, _without2.default)(state.targetIds, action.targetId) }); case _dragDrop.DROP: return _extends({}, state, { dropResult: action.dropResult, didDrop: true, targetIds: [] }); case _dragDrop.END_DRAG: return _extends({}, state, { itemType: null, item: null, sourceId: null, dropResult: null, didDrop: false, isSourcePublic: null, targetIds: [] }); default: return state; } }