import { handleActions } from 'utils/store' ; import { createSelector } from 'reselect' ; import Tools from 'editorTools' ; const KEY_CANVAS_MOUSE_POSITION = 'workspace.canvas.mouse.position' ; const KEY_CANVAS_TOOL_ID = 'workspace.canvas.tools.activeToolId' ; const KEY_HIGHLIGHTED_STEP = 'workspace.canvas.highlightedStep' ; const KEY_SCALE = 'workspace.canvas.scale.value' ; const KEY_SCALE_ORIGIN = 'workspace.canvas.scale.offset' ; const reducers = { [ KEY_CANVAS_MOUSE_POSITION ] : handleActions < typeof KEY_CANVAS_MOUSE_POSITION > ( { MOUSE_POSITION_CHANGED : ( _ , { payload } ) => payload , } , null ) , [ KEY_CANVAS_TOOL_ID ] : handleActions < typeof KEY_CANVAS_TOOL_ID > ( { SET_ACTIVE_TOOL_REQUESTED : ( _ , { payload } ) => payload , } , 'ADD_POINT' ) , [ KEY_HIGHLIGHTED_STEP ] : handleActions < typeof KEY_HIGHLIGHTED_STEP > ( { HIGHLIGHT_STEP_ON_CANVAS_REQUESTED : ( _ , { payload } ) => payload . symbol , UNHIGHLIGHT_STEP_ON_CANVAS_REQUESTED : ( _ , __ ) => null , } , null ) , [ KEY_SCALE ] : handleActions < typeof KEY_SCALE > ( { SET_SCALE_REQUESTED : ( _ , { payload } ) => { return payload . scale ; } , RESET_WORKSPACE_REQUESTED : ( ) => 1 , } , 1 ) , [ KEY_SCALE_ORIGIN ] : handleActions < typeof KEY_SCALE_ORIGIN > ( { SET_SCALE_OFFSET_REQUESTED : ( _ , { payload } ) => { return { top : Math . round ( payload . top ) , left : Math . round ( payload . left ) , } ; } , RESET_WORKSPACE_REQUESTED : ( ) => null , } , null ) , } ; export default reducers ; export const getHighlightedStep = ( state ) => state [ KEY_HIGHLIGHTED_STEP ] ; export const getMousePosition = ( state ) => state [ KEY_CANVAS_MOUSE_POSITION ] ; export const getActiveToolId = ( state ) => state [ KEY_CANVAS_TOOL_ID ] ; export const getState = ( state ) => state ; export const getActiveTool = createSelector ( getState , getActiveToolId , ( state , id ) => Tools [ id ] ( state ) ) ; export const getScale = ( state ) => state [ KEY_SCALE ] ; export const getScaleOrigin = ( state ) => state [ KEY_SCALE_ORIGIN ] ;