import { Node , NodeInfo , DropPosition } from '../interfaces' ; export default function findPosition ( parent , dims , posX , posY ) { let result = { parent , index : 0 , where : 'before' , } ; let leftLimit = 0 , xLimit = 0 , dimRight = 0 , yLimit = 0 , xCenter = 0 , yCenter = 0 , dimDown = 0 ; for ( let i = 0 , len = dims . length ; i < len ; i ++ ) { const dim = dims [ i ] ; dimRight = dim . left + dim . outerWidth ; dimDown = dim . top + dim . outerHeight ; xCenter = dim . left + dim . outerWidth / 2 ; yCenter = dim . top + dim . outerHeight / 2 ; if ( ( xLimit && dim . left > xLimit ) || ( yLimit && yCenter >= yLimit ) || ( leftLimit && dimRight < leftLimit ) ) continue ; result . index = i ; if ( ! dim . inFlow ) { if ( posY < dimDown ) yLimit = dimDown ; if ( posX < xCenter ) { xLimit = xCenter ; result . where = 'before' ; } else { leftLimit = xCenter ; result . where = 'after' ; } } else { if ( posY < yCenter ) { result . where = 'before' ; break ; } else result . where = 'after' ; } } return result ; }