@portabletext/editor
Version:
Portable Text Editor made in React
30 lines (27 loc) • 506 B
text/typescript
import {
isPortableTextTextBlock,
type KeyedSegment,
type PortableTextBlock,
} from '@sanity/types'
import type {EditorSelectionPoint} from '../types/editor'
/**
* @public
*/
export function getBlockStartPoint({
node,
path,
}: {
node: PortableTextBlock
path: [KeyedSegment]
}): EditorSelectionPoint {
if (isPortableTextTextBlock(node)) {
return {
path: [...path, 'children', {_key: node.children[0]._key}],
offset: 0,
}
}
return {
path,
offset: 0,
}
}