Very Basic Custom Input Rule

Hey there,

im getting into prosemirror right now and im having a hard time since my js-knowledge is a bit rusty… Im got the Dino-Example (Link) running yesterday (yay :smiley: ) and currently im trying to implement a very basic input-rule.

Therefore i used this code:

let plugins = exampleSetup({schema: this.dinoSchema, menuContent: menu.fullMenu}); 
let dinoInput = new InputRule(/---$/, "test");
plugins.push(inputRules({dinoInput}))
window.view = new EditorView(document.querySelector("#editor"), {
  state: EditorState.create({
    doc: startDoc,
    // Pass exampleSetup our schema and the menu we created
    plugins: plugins
  })
})

When i run this im getting an error whenever i type something in the editor:

Uncaught TypeError: Cannot read property 'length' of undefined
at run (index.es.js?f95e:75)
at Plugin.handleTextInput (index.es.js?f95e:51)
at eval (index.es.js?576a:2654)
at EditorView.someProp (index.es.js?576a:4795)
at readDOMChange (index.es.js?576a:2654)
at DOMObserver.eval [as handleDOMChange] (index.es.js?576a:3238)
at DOMObserver.flush (index.es.js?576a:3155)
at MutationObserver.DOMObserver.observer (index.es.js?576a:3022)

Does anyone know what is going on here or what i can do to implement it the right way?

Sorry if im doing rookie-mistakes here :frowning:

I think you are using inputRules() incorrectly, please double check the API docs at https://prosemirror.net/docs/ref/#inputrules.inputRules .

Probably. My understanding so far is that i create an InputRule and use inputRule() to create a Plugin out of it. Is there anything wrong with that process? Are you aware of what exactly im doing wrong?

Thanks for the reply :slight_smile:

The docs ask for the argument to be an object with an array of rules in its rules property, so something like {rules: [dinoInput]}. Reading docs closely will save you a lot of time.

Im ashamed now :frowning:

Thank you for the quick response. I try to improve in the doc-reading department!