core-graphics
Version:
A core library for creating shape-based graphic editors
44 lines (35 loc) • 1.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = cursorStateReducer;
var _declarations = require('../../declarations');
var _icepick = require('icepick');
var i = _interopRequireWildcard(_icepick);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function updateCursorState(state, cursor) {
return i.assocIn(state, ['mouse', 'cursor'], cursor);
}
function cursorStateReducer(currentState, ev) {
var mode = currentState.mode;
if ((0, _declarations.isResizingMode)(mode)) {
var cursor = mode.payload.handle.cursor;
return updateCursorState(currentState, cursor);
}
if ((0, _declarations.isMovingMode)(mode)) {
return updateCursorState(currentState, 'move');
}
if ((0, _declarations.isDrawingShapeMode)(mode)) {
var shapesDeclarations = currentState.shapesDeclarations;
var shapeType = mode.payload.shapeType;
var drawingModeCursor = shapesDeclarations[shapeType].drawingModeCursor;
return updateCursorState(currentState, drawingModeCursor);
}
if ((0, _declarations.isRubberBandSelectionMode)(mode)) {
return updateCursorState(currentState, 'default');
}
if ((0, _declarations.isMovingViewportMode)(mode)) {
return updateCursorState(currentState, mode.payload.moving ? 'move' : 'default');
}
return i.merge(currentState, { mouse: { cursor: null } });
}