mirror of https://github.com/fantasticit/think.git
tiptap: improve drag
This commit is contained in:
parent
e4f6c03576
commit
3ee0c5e095
|
@ -35,6 +35,7 @@ export const Dragable = Extension.create({
|
||||||
|
|
||||||
function drag(e) {
|
function drag(e) {
|
||||||
if (!currentNode || currentNode.nodeType !== 1) return;
|
if (!currentNode || currentNode.nodeType !== 1) return;
|
||||||
|
|
||||||
let pos = null;
|
let pos = null;
|
||||||
const desc = editorView.docView.nearestDesc(currentNode, true);
|
const desc = editorView.docView.nearestDesc(currentNode, true);
|
||||||
|
|
||||||
|
@ -56,12 +57,14 @@ export const Dragable = Extension.create({
|
||||||
return [
|
return [
|
||||||
new Plugin({
|
new Plugin({
|
||||||
view(view) {
|
view(view) {
|
||||||
|
if (view.editable) {
|
||||||
editorView = view;
|
editorView = view;
|
||||||
dropElement = document.createElement('div');
|
dropElement = document.createElement('div');
|
||||||
dropElement.setAttribute('draggable', 'true');
|
dropElement.setAttribute('draggable', 'true');
|
||||||
dropElement.className = 'drag-handler';
|
dropElement.className = 'drag-handler';
|
||||||
dropElement.addEventListener('dragstart', drag);
|
dropElement.addEventListener('dragstart', drag);
|
||||||
view.dom.parentElement.appendChild(dropElement);
|
view.dom.parentElement.appendChild(dropElement);
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
update(view) {
|
update(view) {
|
||||||
|
@ -78,6 +81,8 @@ export const Dragable = Extension.create({
|
||||||
props: {
|
props: {
|
||||||
handleDOMEvents: {
|
handleDOMEvents: {
|
||||||
drop() {
|
drop() {
|
||||||
|
if (!dropElement) return;
|
||||||
|
|
||||||
dropElement.style.opacity = 0;
|
dropElement.style.opacity = 0;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const node = document.querySelector('.ProseMirror-hideselection');
|
const node = document.querySelector('.ProseMirror-hideselection');
|
||||||
|
@ -87,10 +92,15 @@ export const Dragable = Extension.create({
|
||||||
}, 50);
|
}, 50);
|
||||||
},
|
},
|
||||||
mousemove(view, event) {
|
mousemove(view, event) {
|
||||||
|
if (!dropElement) return;
|
||||||
|
|
||||||
const coords = { left: event.clientX, top: event.clientY };
|
const coords = { left: event.clientX, top: event.clientY };
|
||||||
const pos = view.posAtCoords(coords);
|
const pos = view.posAtCoords(coords);
|
||||||
|
|
||||||
if (!pos) return;
|
if (!pos) {
|
||||||
|
dropElement.style.opacity = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let node = view.domAtPos(pos.pos);
|
let node = view.domAtPos(pos.pos);
|
||||||
|
|
||||||
|
@ -104,10 +114,12 @@ export const Dragable = Extension.create({
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!node || !node.getBoundingClientRect) {
|
if (!node || !node.getBoundingClientRect) {
|
||||||
|
dropElement.style.opacity = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node?.classList?.contains('node-title') || node?.classList?.contains('node-table')) {
|
if (node?.classList?.contains('node-title') || node?.classList?.contains('node-table')) {
|
||||||
|
dropElement.style.opacity = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,6 +134,10 @@ export const Dragable = Extension.create({
|
||||||
dropElement.style.top = rect.top + 6 + 'px';
|
dropElement.style.top = rect.top + 6 + 'px';
|
||||||
dropElement.style.opacity = 1;
|
dropElement.style.opacity = 1;
|
||||||
},
|
},
|
||||||
|
mouseleave() {
|
||||||
|
if (!dropElement || currentNode) return;
|
||||||
|
dropElement.style.opacity = 0;
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|
Loading…
Reference in New Issue