Hello,
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) {
this.pm = 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' }
?
Thanks