@portabletext/editor
Version:
Portable Text Editor made in React
21 lines (17 loc) • 456 B
text/typescript
import {
isPortableTextSpan,
isPortableTextTextBlock,
type PortableTextBlock,
} from '@sanity/types'
import {getTextBlockText} from './util.get-text-block-text'
/**
* @public
*/
export function isEmptyTextBlock(block: PortableTextBlock) {
if (!isPortableTextTextBlock(block)) {
return false
}
const onlyText = block.children.every(isPortableTextSpan)
const blockText = getTextBlockText(block)
return onlyText && blockText === ''
}