UNPKG

@atlaskit/pragmatic-drag-and-drop-react-beautiful-dnd-migration

Version:

An optional Pragmatic drag and drop package that enables rapid migration from react-beautiful-dnd to Pragmatic drag and drop

50 lines (49 loc) 2.65 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } // eslint-disable-next-line import/no-extraneous-dependencies export var idleState = { draggingFromThisWith: null, draggingOverWith: null, isDraggingOver: false }; export function reducer(state, action) { if (action.type === 'DRAG_START') { var _action$payload = action.payload, droppableId = _action$payload.droppableId, start = _action$payload.start; var draggableId = start.draggableId, source = start.source; var isDraggingOver = source.droppableId === droppableId; var draggingOverWith = isDraggingOver ? draggableId : null; var isDraggingFrom = source.droppableId === droppableId; var draggingFromThisWith = isDraggingFrom ? draggableId : null; return _objectSpread(_objectSpread({}, state), {}, { isDraggingOver: isDraggingOver, draggingFromThisWith: draggingFromThisWith, draggingOverWith: draggingOverWith }); } if (action.type === 'DRAG_UPDATE') { var _action$payload2 = action.payload, _droppableId = _action$payload2.droppableId, update = _action$payload2.update; var _update$destination = update.destination, destination = _update$destination === void 0 ? null : _update$destination, _draggableId = update.draggableId, _source = update.source; var _isDraggingOver = (destination === null || destination === void 0 ? void 0 : destination.droppableId) === _droppableId; var _draggingOverWith = _isDraggingOver ? _draggableId : null; var _isDraggingFrom = _source.droppableId === _droppableId; var _draggingFromThisWith = _isDraggingFrom ? _draggableId : null; return _objectSpread(_objectSpread({}, state), {}, { isDraggingOver: _isDraggingOver, draggingFromThisWith: _draggingFromThisWith, draggingOverWith: _draggingOverWith }); } if (action.type === 'DRAG_CLEAR') { return idleState; } return state; }