Skip to content

Commit 50113b5

Browse files
nperez0111YousefED
andauthored
fix: resolve several sentry errors (#1524)
* fix: if cannot find the next block, just stop looking * refactor: if no block, then no decorations * fix: if provided undefined, do not cause runtime errors * don't touch type guards (for now) --------- Co-authored-by: yousefed <[email protected]>
1 parent 8e9195b commit 50113b5

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

packages/core/src/api/nodeConversions/nodeToBlock.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export function contentNodeToTableContent<
8282

8383
// Only merge if the last and first content are both styled text nodes and have the same styles
8484
if (
85+
first &&
8586
isStyledTextInlineContent(last) &&
8687
isStyledTextInlineContent(first) &&
8788
JSON.stringify(last.styles) === JSON.stringify(first.styles)

packages/core/src/extensions/SuggestionMenu/getDefaultSlashMenuItems.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,15 @@ function setSelectionToNextContentEditableBlock<
2020
I extends InlineContentSchema,
2121
S extends StyleSchema
2222
>(editor: BlockNoteEditor<BSchema, I, S>) {
23-
let block = editor.getTextCursorPosition().block;
23+
let block: Block<BSchema, I, S> | undefined =
24+
editor.getTextCursorPosition().block;
2425
let contentType = editor.schema.blockSchema[block.type].content;
2526

2627
while (contentType === "none") {
27-
block = editor.getTextCursorPosition().nextBlock!;
28+
block = editor.getTextCursorPosition().nextBlock;
29+
if (block === undefined) {
30+
return;
31+
}
2832
contentType = editor.schema.blockSchema[block.type].content as
2933
| "inline"
3034
| "table"

packages/core/src/extensions/TableHandles/TableHandlesPlugin.ts

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -662,32 +662,27 @@ export class TableHandlesProsemirrorPlugin<
662662
}
663663

664664
const decorations: Decoration[] = [];
665-
666-
if (newIndex === this.view.state.draggingState.originalIndex) {
667-
return DecorationSet.create(state.doc, decorations);
668-
} else if (
669-
this.view.state.draggingState.draggedCellOrientation === "row" &&
670-
!canRowBeDraggedInto(
671-
this.view.state.block,
672-
this.view.state.draggingState.originalIndex,
673-
newIndex
674-
)
675-
) {
676-
return DecorationSet.create(state.doc, decorations);
677-
} else if (
678-
this.view.state.draggingState.draggedCellOrientation === "col" &&
679-
!canColumnBeDraggedInto(
680-
this.view.state.block,
681-
this.view.state.draggingState.originalIndex,
682-
newIndex
683-
)
665+
const { block, draggingState } = this.view.state;
666+
const { originalIndex, draggedCellOrientation } = draggingState;
667+
668+
// Return empty decorations if:
669+
// - Dragging to same position
670+
// - No block exists
671+
// - Row drag not allowed
672+
// - Column drag not allowed
673+
if (
674+
newIndex === originalIndex ||
675+
!block ||
676+
(draggedCellOrientation === "row" &&
677+
!canRowBeDraggedInto(block, originalIndex, newIndex)) ||
678+
(draggedCellOrientation === "col" &&
679+
!canColumnBeDraggedInto(block, originalIndex, newIndex))
684680
) {
685681
return DecorationSet.create(state.doc, decorations);
686682
}
687683

688684
// Gets the table to show the drop cursor in.
689685
const tableResolvedPos = state.doc.resolve(this.view.tablePos + 1);
690-
const originalIndex = this.view.state.draggingState.originalIndex;
691686

692687
if (this.view.state.draggingState.draggedCellOrientation === "row") {
693688
const cellsInRow = getCellsAtRowHandle(

0 commit comments

Comments
 (0)