import mixins from 'vue-typed-mixins' ; import normalizeWheel from 'normalize-wheel' ; import { deviceSupportHelpers } from '@/components/mixins/deviceSupportHelpers' ; import { nodeIndex } from '@/components/mixins/nodeIndex' ; import { getMousePosition } from '@/views/canvasHelpers' ; export const moveNodeWorkflow = mixins ( deviceSupportHelpers , nodeIndex ) . extend ( { data ( ) { return { moveLastPosition : [ 0 , 0 ] , } ; } , methods : { moveWorkflow ( e ) { const offsetPosition = this . $store . getters . getNodeViewOffsetPosition ; const [ x , y ] = getMousePosition ( e ) ; const nodeViewOffsetPositionX = offsetPosition [ 0 ] + ( x - this . moveLastPosition [ 0 ] ) ; const nodeViewOffsetPositionY = offsetPosition [ 1 ] + ( y - this . moveLastPosition [ 1 ] ) ; this . $store . commit ( 'setNodeViewOffsetPosition' , { newOffset : [ nodeViewOffsetPositionX , nodeViewOffsetPositionY ] } ) ; this . moveLastPosition [ 0 ] = x ; this . moveLastPosition [ 1 ] = y ; } , mouseDownMoveWorkflow ( e ) { if ( this . isCtrlKeyPressed ( e ) === false ) { return ; } if ( this . $store . getters . isActionActive ( 'dragActive' ) ) { return ; } this . $store . commit ( 'setNodeViewMoveInProgress' , true ) ; const [ x , y ] = getMousePosition ( e ) ; this . moveLastPosition [ 0 ] = x ; this . moveLastPosition [ 1 ] = y ; this . $el . addEventListener ( 'mousemove' , this . mouseMoveNodeWorkflow ) ; } , mouseUpMoveWorkflow ( e ) { if ( this . $store . getters . isNodeViewMoveInProgress === false ) { return ; } this . $el . removeEventListener ( 'mousemove' , this . mouseMoveNodeWorkflow ) ; this . $store . commit ( 'setNodeViewMoveInProgress' , false ) ; } , mouseMoveNodeWorkflow ( e ) { if ( e . target && ! e . target . id . includes ( 'node-view' ) ) { return ; } if ( this . $store . getters . isActionActive ( 'dragActive' ) ) { return ; } if ( e . buttons === 0 ) { this . mouseUp ( e ) ; return ; } this . moveWorkflow ( e ) ; } , wheelMoveWorkflow ( e ) { const normalized = normalizeWheel ( e ) ; const offsetPosition = this . $store . getters . getNodeViewOffsetPosition ; const nodeViewOffsetPositionX = offsetPosition [ 0 ] - ( e . shiftKey ? normalized . pixelY : normalized . pixelX ) ; const nodeViewOffsetPositionY = offsetPosition [ 1 ] - ( e . shiftKey ? normalized . pixelX : normalized . pixelY ) ; this . $store . commit ( 'setNodeViewOffsetPosition' , { newOffset : [ nodeViewOffsetPositionX , nodeViewOffsetPositionY ] } ) ; } , } , } ) ;