tiptap: disable drop in title

pull/163/head
fantasticit 2022-08-15 16:16:41 +08:00
parent e7772bbc3b
commit d4889108c6
1 changed files with 14 additions and 2 deletions

View File

@ -120,10 +120,23 @@ export const Dragable = Extension.create({
drop: (view, event: DragEvent) => { drop: (view, event: DragEvent) => {
if (!view.editable || !dragHandleDOM) return false; if (!view.editable || !dragHandleDOM) return false;
const eventPos = view.posAtCoords({ left: event.clientX, top: event.clientY });
if (!eventPos) {
return true;
}
const $mouse = view.state.doc.resolve(eventPos.pos);
/**
* title
*/
if ($mouse?.parent?.type?.name === 'title') {
return true;
}
if (dragging) { if (dragging) {
const tr = removePossibleTable(view, event); const tr = removePossibleTable(view, event);
dragging = false; dragging = false;
if (tr) { if (tr) {
view.dispatch(tr); view.dispatch(tr);
event.preventDefault(); event.preventDefault();
@ -166,7 +179,6 @@ export const Dragable = Extension.create({
}, },
keydown: () => { keydown: () => {
if (!editorView.editable || !dragHandleDOM) return false; if (!editorView.editable || !dragHandleDOM) return false;
dragHandleDOM.classList.remove('show');
hideDragHandleDOM(); hideDragHandleDOM();
return false; return false;
}, },