import Node from '@/components/node/node' ; import { DataflowState } from '@/store/dataflow/types' ; import { InteractionState } from './types' ; import store from '@/store' ; import _ from 'lodash' ; const dataflow = ( ) : DataflowState => store . state . dataflow ; /** Drags all selected nodes by (dx, dy). The dragged node does not additionally move. */ export const dragSelectedNodes = ( dragged , dx , dy ) => { _ . each ( dataflow ( ) . nodes . filter ( node => node . isSelected && node !== dragged ) , node => { node . moveBy ( dx , dy ) ; } ) ; } ; /** Deselects all selected nodes. */ export const deselectAllNodes = ( options ? ) => { const exception = options && options . exception ; _ . each ( dataflow ( ) . nodes . filter ( node => node . isSelected && node !== exception ) , node => node . deselect ( ) ) ; } ; /** Gets a list of nodes with decreasing focus score. */ export const focusNodes = ( ) : Node [ ] => { const nodes = dataflow ( ) . nodes . concat ( ) ; nodes . sort ( ( a , b ) => b . focusScore ( ) - a . focusScore ( ) ) ; return nodes ; } ; /** Gets the node with a higest focus score. */ export const focusNode = ( ) : Node | null => { const nodes = focusNodes ( ) ; return nodes . length && nodes [ 0 ] . getActiveness ( ) > 0 ? nodes [ 0 ] : null ; } ; /** Reduces every node's activeness by half. */ export const reduceAllNodeActiveness = ( options ? ) => { const exception = options && options . exception ; _ . each ( dataflow ( ) . nodes . filter ( node => node !== exception ) , node => node . reduceActiveness ( ) ) ; } ; export const moveNode = ( node , dx , dy ) => { node . moveBy ( dx , dy ) ; } ; export const moveNodes = ( nodes , dx , dy ) => { nodes . forEach ( node => node . moveBy ( dx , dy ) ) ; } ; export const keyStroke = ( state , keys , evt ) => { switch ( keys ) { case 'delete' : case state . osCtrlKey + '+d' : case state . osCtrlKey + '+x' : store . commit ( 'dataflow/removeSelectedNodes' ) ; break ; case state . osCtrlKey + '+s' : store . dispatch ( 'dataflow/saveDiagram' ) ; break ; case state . osCtrlKey + '+shift+s' : store . commit ( 'modals/openSaveAsDiagramModal' ) ; break ; case state . osCtrlKey + '+l' : store . commit ( 'modals/openLoadDiagramModal' ) ; break ; case state . osCtrlKey + '+n' : store . commit ( 'modals/openNewDiagramModal' ) ; break ; case state . osCtrlKey + '+z' : store . commit ( 'history/undo' ) ; break ; case state . osCtrlKey + '+shift+z' : store . commit ( 'history/redo' ) ; break ; case 'a' : store . commit ( 'panels/openQuickNodePanel' ) ; break ; case 'escape' : store . commit ( 'modals/closeNodeModal' ) ; break ; case 'ctrl+r' : debugger ; break ; case 'shift+s' : if ( store . state . flowsense . enabled ) { store . commit ( 'flowsense/openInput' ) ; state . shiftPressed = false ; } break ; default : let handledByNode = false ; store . state . dataflow . nodes . filter ( node => node . isSelected ) . forEach ( node => { handledByNode = handledByNode || node . onKeys ( keys ) ; } ) ; if ( ! handledByNode ) { return ; } } evt . preventDefault ( ) ; } ; /**
 * Closes Flowsense input.
 */ export const closeFlowsenseInput = ( ) => { store . commit ( 'flowsense/closeInput' ) ; } ;