So my image is a node view. And the image has a form and text input to update the src
value.
I’m trying to have the form behaves like a native HTML form where, for example, entering in the text input will automatically submit the form(this got me to messing in the stopEvent()
to no avail…haha)
I’m currently trying the method as demonstrated in the footnote example. Main thing I’m now trying to achieve is to pre-populate the src
value when creating the innerView
:
class Image {
constructor(node, view, getPos) {
// ...
const { src, alt } = node.attrs;
const textInput = document.createElement("div"); // this element is appended to the form element
this.innerView = new EditorView(textInput, {
state: EditorState.create({
doc: this.node,
// doc: Node.fromJSON(schema, doc),
plugins: [
keymap({
"Mod-z": () => undo(this.outerView.state, this.outerView.dispatch),
"Mod-y": () => redo(this.outerView.state, this.outerView.dispatch),
}),
],
}),
dispatchTransaction: this.dispatchInner.bind(this),
});
I can’t find out a way to populate the src
value to the this.node
. So I tried to create the doc
manually with Node.fromJSON(schema, doc)
:
const doc = {
type: "doc",
content: [
{
type: "paragraph",
content: [{ type: "text", text: src }],
},
],
};
Which manages to show my src
. But, unlike passing the this.node
to the doc
, the undo and redo commands don’t seem to do anything inside the input.
Am I on the right track to building such use case inside a node view? I could use some pointers…