Change Request: Pass raw event object to subscription handlers

I think all handlers should get passed the raw event because why not!?

A few times I find myself in need of the raw event when handling a user action.

For example: I’m currently setting up a custom contextMenu and need access to the raw event in order to place the context menu near the cursor. My first naive approach was to use the pos passed to me and then do a coordsAtPos but this yields awkward behavior in that I can trigger the context menu to the right of a text node and the pos will be within the node, resulting in a menu near the node and not near my cursor.

Most event handlers don’t directly correspond to a DOM event, so the request to do this for all handlers is, well, not really on-point.

For some of them, such as contextMenu, it does make certain degree of sense, though I’m actually more inclined to pass some select information (such as button number for click events and coordinates for all mouse events) so that we don’t end up coupling handlers to DOM types, and can test them without awkwardly faking DOM events.

Sounds fair, my only concern is that by not passing the raw event there may be future cases not addressed by the information passed. I suppose we can let those use cases show themselves and address them then.

tl;dr: I like coords for mouse events!

yes, coords for mouse events would solve my current problem with subscriptions as well

I hit another use case which leads me to believe that passing the raw event would be best.

I have an image figure where clicking on it should pop open a custom modal to edit the figure.

Using pm.on.clickOn.add((pos, node, nodePos) => { ...}) I can detect if the node type matches my figure. The problem is that a click on the margins of the figure trigger the handler. So if I have a centered figure using margin: 0 auto; then clicking anywhere on the side of the figure will trigger the edit modal.

To fix this, I have ProseMirror pass me the raw event and test event.target to make sure the click was on the actual figure and not on the margins.

Implemented (by passing the raw event) in this patch. Will be part of the release that I’ll put out this week.