fix: widen editor focus block typing

This commit is contained in:
lucaronin
2026-04-20 18:38:51 +02:00
parent e956c806e5
commit a199fad803

View File

@@ -11,8 +11,8 @@ interface HeadingRange {
interface FocusableHeadingBlock {
id: string
type?: string
props?: { level?: number }
content?: Array<{ type?: string; text?: string }>
props?: { level?: number } & Record<string, unknown>
content?: unknown
}
interface TiptapChain {
@@ -56,11 +56,16 @@ function isTopLevelHeadingBlock(block: FocusableHeadingBlock): boolean {
}
function getHeadingBlockText(block: FocusableHeadingBlock | undefined): string {
return block?.content
?.filter((item) => item.type === 'text')
if (!Array.isArray(block?.content)) return ''
return block.content
.filter((item): item is { type?: string; text?: string } => (
typeof item === 'object' && item !== null
))
.filter((item) => item.type === 'text')
.map((item) => item.text ?? '')
.join('')
.trim() ?? ''
.trim()
}
function getFirstHeadingBlock(editor: FocusableEditor): FocusableHeadingBlock | undefined {