@portabletext/editor
Version:
Portable Text Editor made in React
23 lines (16 loc) • 546 B
text/typescript
import type {EditorSelectionPoint} from '../types/editor'
import {isKeyedSegment} from '../utils'
export function getBlockKeyFromSelectionPoint(point: EditorSelectionPoint) {
const blockPathSegment = point.path.at(0)
if (isKeyedSegment(blockPathSegment)) {
return blockPathSegment._key
}
return undefined
}
export function getChildKeyFromSelectionPoint(point: EditorSelectionPoint) {
const childPathSegment = point.path.at(2)
if (isKeyedSegment(childPathSegment)) {
return childPathSegment._key
}
return undefined
}