fix: quickinsert tippy postion wrong

This commit is contained in:
liufuwei 2022-08-17 15:39:59 +08:00
parent 57774553e0
commit 9581821b99
1 changed files with 19 additions and 2 deletions

View File

@ -8,9 +8,10 @@ import { insertMenuLRUCache, QUICK_INSERT_COMMANDS, transformToCommands } from '
import { MenuList } from 'tiptap/core/wrappers/menu-list'; import { MenuList } from 'tiptap/core/wrappers/menu-list';
export const QuickInsertPluginKey = new PluginKey('quickInsert'); export const QuickInsertPluginKey = new PluginKey('quickInsert');
const extensionName = 'quickInsert'
export const QuickInsert = Node.create({ export const QuickInsert = Node.create({
name: 'quickInsert', name: extensionName,
priority: EXTENSION_PRIORITY_HIGHEST, priority: EXTENSION_PRIORITY_HIGHEST,
@ -52,6 +53,19 @@ export const QuickInsert = Node.create({
}), }),
]; ];
}, },
addStorage() {
return {
rect: {
width: 0,
height: 0,
left: 0,
top: 0,
right: 0,
bottom: 0,
}
}
},
}).configure({ }).configure({
suggestion: { suggestion: {
items: ({ query }) => { items: ({ query }) => {
@ -79,7 +93,7 @@ export const QuickInsert = Node.create({
}); });
popup = tippy('body', { popup = tippy('body', {
getReferenceClientRect: props.clientRect, getReferenceClientRect: props.clientRect || (() => props.editor.storage[extensionName].rect),
appendTo: () => document.body, appendTo: () => document.body,
content: component.element, content: component.element,
showOnCreate: true, showOnCreate: true,
@ -93,6 +107,9 @@ export const QuickInsert = Node.create({
if (!isEditable) return; if (!isEditable) return;
component.updateProps(props); component.updateProps(props);
props.editor.storage[extensionName].rect = props.clientRect();
popup[0].setProps({ popup[0].setProps({
getReferenceClientRect: props.clientRect, getReferenceClientRect: props.clientRect,
}); });