import { EditorView } from 'prosemirror-view' ; interface TooltipPosition { bottom : number ; left : number ; } export const calculateTooltipPos = ( view ) : TooltipPosition => { const { state : { selection } } = view ; const { from , to } = selection ; const start = view . coordsAtPos ( from ) ; const end = view . coordsAtPos ( to ) ; const box = view . dom . getBoundingClientRect ( ) ; const left = Math . max ( ( start . left + end . left ) / 2 , start . left + 3 ) ; return { left : left - box . left , bottom : box . bottom - start . top } ; } ;