import { Coords } from '@remirror/core' ; import { Positioner , selectionPositioner } from '@remirror/extension-positioner' ; import type { Annotation } from './annotation-types' ; type MinimalAnnotation = Pick < Annotation , 'from' | 'to' > & { text : string | undefined ; } ; returns type GetAnnotationsAt = ( pos : number ) => MinimalAnnotation [ ] ; remarks export function createCenteredAnnotationPositioner ( getAnnotationsAt ) { return selectionPositioner . clone ( { getActive : ( props ) => { const { state , view } = props ; if ( ! state . selection . empty ) { return [ ] ; } const annotations = getAnnotationsAt ( state . selection . from ) ; if ( annotations . length === 0 ) { return [ ] ; } const shortestAnnotation = annotations . sort ( ( annotation1 , annotation2 ) => ( annotation1 . text ?? '' ) . length - ( annotation2 . text ?? '' ) . length ) [ 0 ] ; if ( ! shortestAnnotation ) { return [ ] ; } const from = view . coordsAtPos ( shortestAnnotation . from ) ; const to = view . coordsAtPos ( shortestAnnotation . to ) ; return [ { from , to } ] ; } , } ) ; }