Trying to optimize button-driven transactions

Hi there!

I’m very newbie to ProseMirror. Trying to glue some things form here and there, I recently managed to dispatch transactions via buttons and event listeners; however, I feel this is a bit hardcoded and would like to know, based on your experiences, about a better way to do this.

Here is my example: I’ve defined a pretty basic schema, using pretty basic plugins and some outside buttons to serve as menubar. Events are bound to button elements like this:

buttonElement.addEventListener("click", (event) => {
  toggleMark(customSchema.marks.bold)(this.view.state, this.view.dispatch, this.view);
});

After reading the custom menu example, I can see that logic is specified via plugins and a MenuView class, but can’t seem to figure how to build those plugins and how to handle context-based events (e.g. highlighting/hiding buttons if selection contains specific node/mark).

Thank you in advance for any help provided!