Attaching an externally created menu system to PM commands

In my implementation, I have a menu system I like and use for my site that I want to also use for editor functions like changing various options, even the basic stuff like setting marks or adding the varied types of special-purpose paragraphs I have.

My question is about the pros and cons of that and how easy it is to attach PM commands to those pre-defined menu items for when they are selected. The examples use the prosemirror-menu module, although for me that seems too limiting.

Ultimately this gets down to external code being able to trigger commands for my editor, which in turn would keep everything immutable as those commands would be using the transform object as all my PM commands do. It seems I could have a menu view that attached the commands for various features to the onclick of the menu items, is that the way to go?

Commands are just functions. You can call them from wherever you fancy.

I’ve done this. The one trick to it is not to let the menu steal focus from the editor.

I got it working, and I set the focus back to the editor in the onclick handler in line with what you did. As long as I export the commands I want, I can put them anywhere and keep my PM doc immutable.