diff --git a/demos/src/Examples/Community/React/suggestion.js b/demos/src/Examples/Community/React/suggestion.js index 5f803ac99cb..89f2c34de38 100644 --- a/demos/src/Examples/Community/React/suggestion.js +++ b/demos/src/Examples/Community/React/suggestion.js @@ -1,5 +1,7 @@ -import { ReactRenderer } from '@tiptap/react' import tippy from 'tippy.js' + +import { ReactRenderer } from '@tiptap/react' + import { MentionList } from './MentionList' export default { @@ -20,6 +22,10 @@ export default { editor: props.editor, }) + if (!props.clientRect) { + return + } + popup = tippy('body', { getReferenceClientRect: props.clientRect, appendTo: () => document.body, @@ -34,6 +40,10 @@ export default { onUpdate(props) { reactRenderer.updateProps(props) + if (!props.clientRect) { + return + } + popup[0].setProps({ getReferenceClientRect: props.clientRect, }) diff --git a/demos/src/Examples/Community/Vue/suggestion.js b/demos/src/Examples/Community/Vue/suggestion.js index 3745660dec4..4b9f0c9bddb 100644 --- a/demos/src/Examples/Community/Vue/suggestion.js +++ b/demos/src/Examples/Community/Vue/suggestion.js @@ -1,5 +1,7 @@ -import { VueRenderer } from '@tiptap/vue-3' import tippy from 'tippy.js' + +import { VueRenderer } from '@tiptap/vue-3' + import MentionList from './MentionList.vue' export default { @@ -23,6 +25,10 @@ export default { editor: props.editor, }) + if (!props.clientRect) { + return + } + popup = tippy('body', { getReferenceClientRect: props.clientRect, appendTo: () => document.body, @@ -37,6 +43,10 @@ export default { onUpdate(props) { component.updateProps(props) + if (!props.clientRect) { + return + } + popup[0].setProps({ getReferenceClientRect: props.clientRect, }) diff --git a/demos/src/Experiments/Commands/Vue/suggestion.js b/demos/src/Experiments/Commands/Vue/suggestion.js index 9680693abce..8d648fa8cc9 100644 --- a/demos/src/Experiments/Commands/Vue/suggestion.js +++ b/demos/src/Experiments/Commands/Vue/suggestion.js @@ -1,5 +1,7 @@ import tippy from 'tippy.js' + import { VueRenderer } from '@tiptap/vue-3' + import CommandsList from './CommandsList.vue' export default { @@ -66,6 +68,10 @@ export default { editor: props.editor, }) + if (!props.clientRect) { + return + } + popup = tippy('body', { getReferenceClientRect: props.clientRect, appendTo: () => document.body, @@ -80,6 +86,10 @@ export default { onUpdate(props) { component.updateProps(props) + if (!props.clientRect) { + return + } + popup[0].setProps({ getReferenceClientRect: props.clientRect, }) diff --git a/demos/src/Nodes/Mention/React/suggestion.js b/demos/src/Nodes/Mention/React/suggestion.js index 911addeec94..30553f500b6 100644 --- a/demos/src/Nodes/Mention/React/suggestion.js +++ b/demos/src/Nodes/Mention/React/suggestion.js @@ -1,5 +1,7 @@ -import { ReactRenderer } from '@tiptap/react' import tippy from 'tippy.js' + +import { ReactRenderer } from '@tiptap/react' + import MentionList from './MentionList.jsx' export default { @@ -46,6 +48,10 @@ export default { editor: props.editor, }) + if (!props.clientRect) { + return + } + popup = tippy('body', { getReferenceClientRect: props.clientRect, appendTo: () => document.body, @@ -60,6 +66,10 @@ export default { onUpdate(props) { component.updateProps(props) + if (!props.clientRect) { + return + } + popup[0].setProps({ getReferenceClientRect: props.clientRect, }) diff --git a/demos/src/Nodes/Mention/Vue/suggestion.js b/demos/src/Nodes/Mention/Vue/suggestion.js index 6b8b06f5635..bd4213dfdc6 100644 --- a/demos/src/Nodes/Mention/Vue/suggestion.js +++ b/demos/src/Nodes/Mention/Vue/suggestion.js @@ -1,5 +1,7 @@ -import { VueRenderer } from '@tiptap/vue-3' import tippy from 'tippy.js' + +import { VueRenderer } from '@tiptap/vue-3' + import MentionList from './MentionList.vue' export default { @@ -24,6 +26,10 @@ export default { editor: props.editor, }) + if (!props.clientRect) { + return + } + popup = tippy('body', { getReferenceClientRect: props.clientRect, appendTo: () => document.body, @@ -38,6 +44,10 @@ export default { onUpdate(props) { component.updateProps(props) + if (!props.clientRect) { + return + } + popup[0].setProps({ getReferenceClientRect: props.clientRect, }) diff --git a/packages/suggestion/src/suggestion.ts b/packages/suggestion/src/suggestion.ts index f61fa4abf9d..82f25e48e4a 100644 --- a/packages/suggestion/src/suggestion.ts +++ b/packages/suggestion/src/suggestion.ts @@ -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 { @@ -44,7 +46,7 @@ export interface SuggestionProps { 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({ 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, }