Defining a plugin


I’m trying to create a ProseMirror plugin and I’m having some issues right now, hoping someone here can help. I’ve been looking at the prosemirror-plugin-base by mattkerbowitz, but it’s not working the way I’d expect it to when I try to access the option value passed into the ProseMirror constructor.

I’ve got this to define the option, just copy/pasted from the plugin-base and changed the name

import { defineOption } from "./../../../prosemirror/dist/edit"
import { MyPlugin } from "./plugin"

defineOption('myPlugin', false, (pm, value) => {
  // --- value is always false here
  if (value){ 
    pm.mod.myPlugin = new MyPlugin(pm, value)

and the plug in ./plugin is simply

export class MyPlugin {
  constructor(pm, options) { = pm;
    //setup default options and override with passed in options
    for(let option in options) {
     this.options[option] = options[option];
  console.log('constructor hit')

On the client to use the plugin, I’ve imported the plugin to make sure it’s evaluated, and I’m trying to use it with this code below

  const editor = new ProseMirror({
    place: document.getElementById('demo'),
    myPlugin: { some: 'option' },
    menuBar: true,
    autoInput: true,
    tooltipMenu: {selectedBlockMenu: true}

My issue is that in the update function passed to defineOption() the value is always false. What do I have to do to know that the myPlugin option was provided to the current pm instance, and its value was { some: 'option' } ?


Your code looks correct (except for missing closing brace on the class, which I guess was a copy-paste mistake). This is pretty much what the plugins in the distribution are doing as well, and I can’t explain why it wouldn’t work in your case.

(Note that in 0.8.0 defining plugins will be more straightforward, using plugin objects rather than defineOption)

Do you have a planned release window for 0.8.0?

At least a few weeks away, possibly more, depending on how well the work goes. So you probably shouldn’t wait for it.

If anyone else sees this issue, I was able to grab the option’s parameters on the pm instance by just accessing it off the pm instance directly like this

defineOption('myPlugin', false, (pm, value) => {
  // --- value is always false here
  // but we can get it off of pm
  let value = pm.mod.myPlugin.options;