Why `toDOM` do not receive the same props as a NodeView?


I am currently using a NodeView as an intermediate to access the current editor view and pass it down to a custom element.


export class CustomElementView implements NodeView {
    dom: HTMLElement
    constructor(node: Node, view: EditorView, getPos) {
        const mce = document.createElement("my-custom-element") as MyCustomElement
        // this way my custom element can interact with the editor
        mce.nodeView = { view, node, getPos }
        this.dom = mce

Is there any conceptual limitation that would prevent the same in toDOM? For example:

toDOM(node) { return [
    // problem: I miss "view" and "getPos" on toDOM
    { "data-nodeView": { node, getPos, view} }}
] }

I’ve read about Decorations but not sure if it has anything to do with that, as it seems related mostly to plugins?

Related: toDOM(Node) {} 's Node can get Parent or position?

toDOM is used in out-of-editor HTML serialization as well. Use a node view if you want to do editor-specific things.

1 Like

Makes sense thanks for the precision.

So toDOM but also parseDOM role goes beyond rendering, both are for instance needed if we want to be able to copy-paste an element within the editor (or outside of it), even if we use a NodeView for the actual rendering.