export const updateElementInWorkspace = (workspace, payload) => {
  const { selectionState } = workspace

  if(!selectionState.dragStarted) {
    return workspace
  }

  const { currentMousePosition } = payload
  const {
    elementId,
    startElementPosition,
    startMousePosition
  } = selectionState
  const element = workspace.entities[elementId]

  return Object.assign({}, workspace, {
    ...workspace,
    entities: {
      ...workspace.entities,
      [elementId]: {
        ...element,
        position: {
          x: startElementPosition.x + currentMousePosition.x - startMousePosition.x,
          y: startElementPosition.y + currentMousePosition.y - startMousePosition.y,
        }
      }
    }
  })
}

export const addDragStartedToWorkspace = (workspace, payload) => {
  const  {
    elementId,
    elementPosition,
    mousePosition
  } = payload

  return setDragStateToWorkspace(
    workspace,
    {
      dragStarted: true,
      elementId: elementId,
      startElementPosition: elementPosition,
      startMousePosition: mousePosition
    }
  )
}

export const addDragStoppedToWorkspace = (workspace, payload) => {
  return setDragStateToWorkspace(
    workspace,
    {
      dragStarted: false
    }
  )
}

export const setDragStateToWorkspace = (workspace, dragState) => {
  return Object.assign({}, workspace, {
    ...workspace,
    selectionState: {
      ...workspace.selectionState,
      ...dragState
    }
  })
}

@@ -213,28 +213,24 @@
  const %7B
-%0A   
  element
 Id,%0A    
@@ -225,62 +225,8 @@
 ment
-Id,%0A    startElementPosition,%0A    startMousePosition%0A 
  %7D =
@@ -249,17 +249,25 @@
   const 
-e
+originalE
 lement =
@@ -293,17 +293,18 @@
 %5Belement
-I
+.i
 d%5D%0A%0A  re
@@ -416,17 +416,18 @@
 %5Belement
-I
+.i
 d%5D: %7B%0A  
@@ -435,17 +435,25 @@
      ...
-e
+originalE
 lement,%0A
@@ -485,27 +485,28 @@
      x: 
-startElemen
+element.star
 tPositio
@@ -536,26 +536,33 @@
 ion.x - 
-startMouse
+element.mouseDown
 Position
@@ -578,27 +578,28 @@
      y: 
-startElemen
+element.star
 tPositio
@@ -629,26 +629,33 @@
 ion.y - 
-startMouse
+element.mouseDown
 Position
@@ -930,17 +930,29 @@
  element
-I
+: %7B%0A        i
 d: eleme
@@ -967,20 +967,19 @@
     
+  
-startElement
+mouseDown
 Posi
@@ -984,23 +984,21 @@
 sition: 
-element
+mouse
 Position
@@ -1009,18 +1009,15 @@
     
+  
 start
-Mouse
 Posi
@@ -1014,37 +1014,39 @@
  startPosition: 
-mouse
+element
 Position%0A    %7D%0A 
@@ -1038,16 +1038,24 @@
 osition%0A
+      %7D%0A
     %7D%0A  

Save in the same place inside 'state', 'selected' & 'dragging' element