Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public dragover = throttle(50, (event: DragEvent) => {
const pos = this.view.posAtCoords({ left: event.clientX, top: event.clientY });
if (pos) {
const {
dragging,
state: { doc, schema },
} = this.view;
const target = dragging?.slice
? dropPoint(doc, pos.pos, dragging.slice) ?? pos.pos
: insertPoint(doc, pos.pos, schema.image) ?? pos.pos;
if (target === this.target) {
// This line resets the timeout.
this.scheduleRemoval(100);
return;
}
this.target = target;
this.updateDecorationSet();
this.scheduleRemoval(100);
}
});
view.dragging = null
if (!e.dataTransfer) return
let eventPos = view.posAtCoords(eventCoords(e))
if (!eventPos) return
let $mouse = view.state.doc.resolve(eventPos.pos)
if (!$mouse) return
let slice = dragging && dragging.slice ||
parseFromClipboard(view, e.dataTransfer.getData(brokenClipboardAPI ? "Text" : "text/plain"),
brokenClipboardAPI ? null : e.dataTransfer.getData("text/html"), false, $mouse)
if (!slice) return
e.preventDefault()
if (view.someProp("handleDrop", f => f(view, e, slice, dragging && dragging.move))) return
let insertPos = slice ? dropPoint(view.state.doc, $mouse.pos, slice) : $mouse.pos
if (insertPos == null) insertPos = $mouse.pos
let tr = view.state.tr
if (dragging && dragging.move) tr.deleteSelection()
let pos = tr.mapping.map(insertPos)
let isNode = slice.openStart == 0 && slice.openEnd == 0 && slice.content.childCount == 1
let beforeInsert = tr.doc
if (isNode)
tr.replaceRangeWith(pos, pos, slice.content.firstChild)
else
tr.replaceRange(pos, pos, slice)
if (tr.doc.eq(beforeInsert)) return
let $pos = tr.doc.resolve(pos)
if (isNode && NodeSelection.isSelectable(slice.content.firstChild) &&
public dragover(event) {
const pos = this.editorView.posAtCoords({ left: event.clientX, top: event.clientY });
if (pos) {
let target = pos.pos;
if (this.editorView.dragging && this.editorView.dragging.slice) {
target = dropPoint(this.editorView.state.doc, target, this.editorView.dragging.slice);
if (target == null) {
target = pos.pos;
}
}
this.setCursor(target);
this.scheduleRemoval(5000);
}
}