From a199fad803e70021cfbbd6b7a6ec1cfe21477dca Mon Sep 17 00:00:00 2001 From: lucaronin Date: Mon, 20 Apr 2026 18:38:51 +0200 Subject: [PATCH] fix: widen editor focus block typing --- src/hooks/editorFocusUtils.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/hooks/editorFocusUtils.ts b/src/hooks/editorFocusUtils.ts index 39a262d5..2d7e9357 100644 --- a/src/hooks/editorFocusUtils.ts +++ b/src/hooks/editorFocusUtils.ts @@ -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 + 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 {