UNPKG

@portabletext/editor

Version:

Portable Text Editor made in React

35 lines (31 loc) 673 B
import { isPortableTextSpan, isPortableTextTextBlock, type KeyedSegment, type PortableTextBlock, } from '@sanity/types' import type {EditorSelectionPoint} from '../types/editor' /** * @public */ export function getBlockEndPoint({ node, path, }: { node: PortableTextBlock path: [KeyedSegment] }): EditorSelectionPoint { if (isPortableTextTextBlock(node)) { const lastChild = node.children[node.children.length - 1] if (lastChild) { return { path: [...path, 'children', {_key: lastChild._key}], offset: isPortableTextSpan(lastChild) ? lastChild.text.length : 0, } } } return { path, offset: 0, } }