UNPKG

@portabletext/editor

Version:

Portable Text Editor made in React

34 lines (30 loc) 864 B
import type {EditorContext} from '../editor/editor-snapshot' import type {BlockOffset} from '../types/block-offset' import type {EditorSelectionPoint} from '../types/editor' import {blockOffsetToSpanSelectionPoint} from './util.block-offset' import {blockOffsetToBlockSelectionPoint} from './util.block-offset-to-block-selection-point' /** * @public */ export function blockOffsetToSelectionPoint({ context, blockOffset, direction, }: { context: Pick<EditorContext, 'schema' | 'value'> blockOffset: BlockOffset direction: 'forward' | 'backward' }): EditorSelectionPoint | undefined { const spanSelectionPoint = blockOffsetToSpanSelectionPoint({ context, blockOffset, direction, }) if (!spanSelectionPoint) { return blockOffsetToBlockSelectionPoint({ context, blockOffset, }) } return spanSelectionPoint }