fix(suggestion): 🐛 make clientrect prop optional as it can potentially be undefined (#2813)

This commit makes the clientRect prop optional - this means that this value can be null. This allows developers using the suggestion extension to know that they have to implement a check for the clientRect before using it.

#2795
This commit is contained in:
Dominik
2022-05-27 12:31:46 +02:00
committed by GitHub
parent 9cdd0eb3b3
commit f019f70a19
6 changed files with 59 additions and 8 deletions

View File

@@ -1,6 +1,8 @@
import { Editor, Range } from '@tiptap/core'
import { EditorState, Plugin, PluginKey } from 'prosemirror-state'
import { Decoration, DecorationSet, EditorView } from 'prosemirror-view'
import { Editor, Range } from '@tiptap/core'
import { findSuggestionMatch } from './findSuggestionMatch'
export interface SuggestionOptions<I = any> {
@@ -44,7 +46,7 @@ export interface SuggestionProps<I = any> {
items: I[],
command: (props: I) => void,
decorationNode: Element | null,
clientRect: (() => DOMRect) | null,
clientRect?: (() => DOMRect | null) | null,
}
export interface SuggestionKeyDownProps {
@@ -123,8 +125,7 @@ export function Suggestion<I = any>({
const { decorationId } = this.key?.getState(editor.state)
const currentDecorationNode = document.querySelector(`[data-decoration-id="${decorationId}"]`)
// @ts-ignore-error
return currentDecorationNode.getBoundingClientRect()
return currentDecorationNode?.getBoundingClientRect() || null
}
: null,
}