UNPKG

lml-main

Version:

This is now a mono repository published into many standalone packages.

53 lines 1.84 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const actions_1 = require("../../allocation/actions"); exports.initialDraggingState = { drag: { refId: null, type: null, }, drop: { refId: null, type: null, count: 0, }, }; exports.draggingReducer = (state = exports.initialDraggingState, action) => { switch (action.type) { case actions_1.SET_DRAG_TARGET: { return setDragTarget(state, action); } case actions_1.SET_DROP_TARGET: { return setDropTarget(state, action); } case actions_1.RESET_DRAG_AND_DROP: { return resetDragAndDrop(state, action); } case actions_1.RESET_DROP_TARGET: { return resetDropTarget(state, action); } default: { return state; } } }; const setDragTarget = (state, action) => (Object.assign({}, state, { drag: { type: action.draggingType, refId: action.refId, } })); const setDropTarget = (state, action) => (Object.assign({}, state, { drop: { type: action.draggingType, refId: action.refId, count: isCurrentTarget(state, action) ? state.drop.count + 1 : 0, } })); const resetDropTarget = (state, action) => { const c = isCurrentTarget(state, action); return Object.assign({}, state, { drop: { type: c ? action.draggingType : state.drop.type, refId: c ? action.refId : state.drop.refId, count: c ? state.drop.count - 1 : 0, } }); }; const resetDragAndDrop = (state, action) => (Object.assign({}, exports.initialDraggingState)); const isCurrentTarget = (state, action) => action.draggingType === state.drop.type && action.refId === state.drop.refId; //# sourceMappingURL=dragging.js.map