I am trying to use prosemirror-inputrules
to automatically apply my custom transformations. But I am stuck at a stubborn tr.setMeta is not a function
error. I looked through the console.error
stack trace and tried reading the prosemirror-inputrules
source code, but I could not understand where is the error coming from. Any help? Below is my code to reproduce the error:
import * as React from "react";
import {EditorState, Plugin} from "prosemirror-state";
import {EditorView} from "prosemirror-view";
import {Schema, DOMParser} from "prosemirror-model";
import {keymap} from "prosemirror-keymap";
import {baseKeymap} from "prosemirror-commands";
import {inputRules, InputRule} from "prosemirror-inputrules";
export default Editor = () => {
React.useEffect(() => {
const mySchema = new Schema({
nodes: {
text: {},
paragraph: {
content: "text*",
toDOM() {return ["p", 0]},
parseDOM: [{tag: "p"}]
},
doc: {
content: "paragraph+"
}
}
});
window.view = new EditorView(document.querySelector("#editor"), {
state: EditorState.create({
doc: DOMParser.fromSchema(mySchema).parse(document.querySelector("#content")),
plugins: [(schema => inputRules({
rules: [new InputRule(
/\s-\s/,
(state, match, start, end) => {
return (transformationState, dispatch) => {
// Transformation...
};
}
)]
}))(mySchema), keymap(baseKeymap), new Plugin({props: {}})]
})
});
});
return (
<div>
<div id="editor"/>
<div id="content"/>
</div>
);
};