import { HoverTrigger } from './types' ; import { Offset } from '@angular-skyhook/core' ; import { RenderContext , DraggedItem } from './types' ; export function suggestHalfway < Data > ( ctx , item , rect , clientOffset ) { const { hover } = item ; const dim = ctx . horizontal ? ( rect . width || rect . right - rect . left ) : ( rect . height || rect . bottom - rect . top ) ; const start = ctx . horizontal ? rect . left : rect . top ; const targetCentre = start + dim / 2.0 ; const mouse = ctx . horizontal ? clientOffset . x : clientOffset . y ; const topHalf = mouse < targetCentre ; let suggestedIndex ; if ( ctx . listId === hover . listId ) { if ( ctx . index < hover . index ) { suggestedIndex = topHalf ? ctx . index : ctx . index + 1 ; } else { suggestedIndex = topHalf ? ctx . index - 1 : ctx . index ; } } else { suggestedIndex = topHalf ? ctx . index : ctx . index + 1 ; } return suggestedIndex ; } ; export function suggestFixed < Data > ( ctx ) { return ctx . index ; } ; export function getSuggester ( trigger ) { switch ( trigger ) { case HoverTrigger . fixed : return suggestFixed ; default : return suggestHalfway ; } }