Tiptap: Disable Drop

Created on 15 Feb 2019  路  2Comments  路  Source: ueberdosis/tiptap

Is there an easy way to disable being able to drop things into the editor?

Most helpful comment

When #202 is merged you can use this snippet Released with [email protected]

new Editor({
  extensions: [],
  onDrop(view, event, slice, moved) {
    // return true to stop the drop event
    // this will just prevent drop from external sources
    return !moved;
  },
});

In the mean time use this: This is for versions older than 1.14.0

new Editor({
  extensions: [],
  onPaste(view, { type }, slice, moved = false) {
    // moved is unset on paste events so the fallback of false is used

    // skip paste events
    if (type === 'paste') return false;

    return !moved;
  },
});

All 2 comments

When #202 is merged you can use this snippet Released with [email protected]

new Editor({
  extensions: [],
  onDrop(view, event, slice, moved) {
    // return true to stop the drop event
    // this will just prevent drop from external sources
    return !moved;
  },
});

In the mean time use this: This is for versions older than 1.14.0

new Editor({
  extensions: [],
  onPaste(view, { type }, slice, moved = false) {
    // moved is unset on paste events so the fallback of false is used

    // skip paste events
    if (type === 'paste') return false;

    return !moved;
  },
});

My current solution, not very well tested:

new Editor({
  extensions: [],
  // tell ProseMirror to ignore drop event
  editorProps: { handleDOMEvents: {
    drop: (view, e) => { e.preventDefault(); },
  } },
  // hide the drop position indicator
  dropCursor: { width: 0, color: 'transparent' },
});
Was this page helpful?
0 / 5 - 0 ratings

Related issues

leandromatos picture leandromatos  路  4Comments

glavdir picture glavdir  路  3Comments

jetacpp picture jetacpp  路  3Comments

dolbex picture dolbex  路  3Comments

santicros picture santicros  路  3Comments