tiptap: fix get bubble menu container

pull/44/head
fantasticit 2022-05-10 14:13:19 +08:00
parent 276175cb88
commit 8e10998859
1 changed files with 10 additions and 4 deletions

View File

@ -158,7 +158,9 @@ export class BubbleMenuView {
const { ranges } = selection;
const from = Math.min(...ranges.map((range) => range.$from.pos));
const to = Math.max(...ranges.map((range) => range.$to.pos));
const node = view.domAtPos(from).node as HTMLElement;
const domAtPos = view.domAtPos(from).node as HTMLElement;
const nodeDOM = view.nodeDOM(from) as HTMLElement;
const node = nodeDOM || domAtPos;
const shouldShow =
this.editor.isEditable &&
@ -179,15 +181,15 @@ export class BubbleMenuView {
this.tippy?.setProps({
getReferenceClientRect: () => {
let toMountNode;
let toMountNode = null;
if (isNodeSelection(state.selection)) {
if (this.getRenderContainer) {
if (this.getRenderContainer && node) {
toMountNode = this.getRenderContainer(node);
}
}
if (this.getRenderContainer) {
if (this.getRenderContainer && node) {
toMountNode = this.getRenderContainer(node);
}
@ -195,6 +197,10 @@ export class BubbleMenuView {
return toMountNode.getBoundingClientRect();
}
if (node && node.getBoundingClientRect) {
return node.getBoundingClientRect();
}
return posToDOMRect(view, from, to);
},
});