How to add "Paste-Behaviors" like in Word

This came up with many customer requests, and as everyone wants different things, pasting becomes a bit of a “how do we do things” question.

In Word, Microsoft solves the issue of “when pasting, do we match formatting, do we keep the text, etc..” by having a little dropdown menu pop up where the user can select how their text should be interpreted.

For us, the following behaviors need to be available:

  1. Certain Nodes should be kept (e.g. we have “sections” that can be labeled). By default, only when they are set to defining they are kept during paste, but some people would like to have defining=false nodes also be kept when pasting
  2. Match formatting and paste
  3. Paste as raw text (strip formatting)
  4. Interpret text as Markdown and paste
  5. Finally, the current default behavior (defined=false nodes are lost, etc..)

How would one go about adding this to ProseMirror? Many thanks in advance!

The library already supports shift-paste for plain text. You could define other modifier combinations and use handlePaste to run your own logic when they are held. Or do this through custom menu items, which I think should also be possible on modern browsers, which will let you read the clipboard, to some extent, with Clipboard.read.

Would I do this via just handlePaste, or a custom command handler that first opens up a menu, and then eventually send the “handle paste” command to ProseMirror?

handlePaste handles native paste events, not something that users would pick from a menu.