From 36aaa5bee5ae59ef84ee02c10c3468be884b3330 Mon Sep 17 00:00:00 2001 From: Nick the Sick Date: Thu, 13 Mar 2025 10:03:02 +0100 Subject: [PATCH 1/4] fix: if cannot find the next block, just stop looking --- .../extensions/SuggestionMenu/getDefaultSlashMenuItems.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/core/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts b/packages/core/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts index fb6fbad7ec..cecaaeabd3 100644 --- a/packages/core/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts +++ b/packages/core/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts @@ -20,11 +20,15 @@ function setSelectionToNextContentEditableBlock< I extends InlineContentSchema, S extends StyleSchema >(editor: BlockNoteEditor) { - let block = editor.getTextCursorPosition().block; + let block: Block | undefined = + editor.getTextCursorPosition().block; let contentType = editor.schema.blockSchema[block.type].content; while (contentType === "none") { - block = editor.getTextCursorPosition().nextBlock!; + block = editor.getTextCursorPosition().nextBlock; + if (block === undefined) { + return; + } contentType = editor.schema.blockSchema[block.type].content as | "inline" | "table" From 86f39c96ad4b9162e4e0b3182a42bda4d934cc72 Mon Sep 17 00:00:00 2001 From: Nick the Sick Date: Thu, 13 Mar 2025 10:23:27 +0100 Subject: [PATCH 2/4] refactor: if no block, then no decorations --- .../TableHandles/TableHandlesPlugin.ts | 35 ++++++++----------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/packages/core/src/extensions/TableHandles/TableHandlesPlugin.ts b/packages/core/src/extensions/TableHandles/TableHandlesPlugin.ts index 87a15fb6db..b49b175dde 100644 --- a/packages/core/src/extensions/TableHandles/TableHandlesPlugin.ts +++ b/packages/core/src/extensions/TableHandles/TableHandlesPlugin.ts @@ -656,32 +656,27 @@ export class TableHandlesProsemirrorPlugin< } const decorations: Decoration[] = []; - - if (newIndex === this.view.state.draggingState.originalIndex) { - return DecorationSet.create(state.doc, decorations); - } else if ( - this.view.state.draggingState.draggedCellOrientation === "row" && - !canRowBeDraggedInto( - this.view.state.block, - this.view.state.draggingState.originalIndex, - newIndex - ) - ) { - return DecorationSet.create(state.doc, decorations); - } else if ( - this.view.state.draggingState.draggedCellOrientation === "col" && - !canColumnBeDraggedInto( - this.view.state.block, - this.view.state.draggingState.originalIndex, - newIndex - ) + const { block, draggingState } = this.view.state; + const { originalIndex, draggedCellOrientation } = draggingState; + + // Return empty decorations if: + // - Dragging to same position + // - No block exists + // - Row drag not allowed + // - Column drag not allowed + if ( + newIndex === originalIndex || + !block || + (draggedCellOrientation === "row" && + !canRowBeDraggedInto(block, originalIndex, newIndex)) || + (draggedCellOrientation === "col" && + !canColumnBeDraggedInto(block, originalIndex, newIndex)) ) { return DecorationSet.create(state.doc, decorations); } // Gets the table to show the drop cursor in. const tableResolvedPos = state.doc.resolve(this.view.tablePos + 1); - const originalIndex = this.view.state.draggingState.originalIndex; if (this.view.state.draggingState.draggedCellOrientation === "row") { const cellsInRow = getCellsAtRowHandle( From db4ce6047c8685d782e57fe2989d7eb3e98177c7 Mon Sep 17 00:00:00 2001 From: Nick the Sick Date: Thu, 13 Mar 2025 12:19:19 +0100 Subject: [PATCH 3/4] fix: if provided undefined, do not cause runtime errors --- .../core/src/schema/inlineContent/types.ts | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/core/src/schema/inlineContent/types.ts b/packages/core/src/schema/inlineContent/types.ts index 7625bd206b..d3bfe0a4e6 100644 --- a/packages/core/src/schema/inlineContent/types.ts +++ b/packages/core/src/schema/inlineContent/types.ts @@ -126,19 +126,27 @@ export type PartialInlineContent< > = PartialInlineContentElement[] | string; export function isLinkInlineContent( - content: InlineContent + content: InlineContent | undefined ): content is Link { - return content.type === "link"; + return content !== undefined && content.type === "link"; } export function isPartialLinkInlineContent( - content: PartialInlineContentElement + content: PartialInlineContentElement | undefined ): content is PartialLink { - return typeof content !== "string" && content.type === "link"; + return ( + content !== undefined && + typeof content !== "string" && + content.type === "link" + ); } export function isStyledTextInlineContent( - content: PartialInlineContentElement + content: PartialInlineContentElement | undefined ): content is StyledText { - return typeof content !== "string" && content.type === "text"; + return ( + content !== undefined && + typeof content !== "string" && + content.type === "text" + ); } From 4c81741285c5e3c3e1b37524a34536bed458c0d9 Mon Sep 17 00:00:00 2001 From: yousefed Date: Mon, 17 Mar 2025 18:51:57 +0100 Subject: [PATCH 4/4] don't touch type guards (for now) --- .../src/api/nodeConversions/nodeToBlock.ts | 1 + .../core/src/schema/inlineContent/types.ts | 20 ++++++------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/packages/core/src/api/nodeConversions/nodeToBlock.ts b/packages/core/src/api/nodeConversions/nodeToBlock.ts index 9e1c95238c..671121a609 100644 --- a/packages/core/src/api/nodeConversions/nodeToBlock.ts +++ b/packages/core/src/api/nodeConversions/nodeToBlock.ts @@ -82,6 +82,7 @@ export function contentNodeToTableContent< // Only merge if the last and first content are both styled text nodes and have the same styles if ( + first && isStyledTextInlineContent(last) && isStyledTextInlineContent(first) && JSON.stringify(last.styles) === JSON.stringify(first.styles) diff --git a/packages/core/src/schema/inlineContent/types.ts b/packages/core/src/schema/inlineContent/types.ts index d3bfe0a4e6..7625bd206b 100644 --- a/packages/core/src/schema/inlineContent/types.ts +++ b/packages/core/src/schema/inlineContent/types.ts @@ -126,27 +126,19 @@ export type PartialInlineContent< > = PartialInlineContentElement[] | string; export function isLinkInlineContent( - content: InlineContent | undefined + content: InlineContent ): content is Link { - return content !== undefined && content.type === "link"; + return content.type === "link"; } export function isPartialLinkInlineContent( - content: PartialInlineContentElement | undefined + content: PartialInlineContentElement ): content is PartialLink { - return ( - content !== undefined && - typeof content !== "string" && - content.type === "link" - ); + return typeof content !== "string" && content.type === "link"; } export function isStyledTextInlineContent( - content: PartialInlineContentElement | undefined + content: PartialInlineContentElement ): content is StyledText { - return ( - content !== undefined && - typeof content !== "string" && - content.type === "text" - ); + return typeof content !== "string" && content.type === "text"; }