Custom NodeView and NodeSpec.toDom()

I need some clarification about the following:

when defining custom nodeViews with its own dom property, I assumed I can strip away the toDOM() in the schema. But then things like dragging seem to be broken (and the official nodeViews example also has it not stripped out). So the schema toDOM() function needs to be kept, to allow a node to be serialized for special purpose such as drag and drop ?

1 Like

Yes, a node view is used when the node is displayed inside the editor, but you’ll still need some way to turn the node into semantic HTML for copy/paste and drag/drop (and possibly also export/import, if you use HTML for that) reasons.

1 Like

@marijn thanks, makes perfect sense now.

Suggestion: maybe prosemirror could use the dom created by the nodeView to get a default serialization of the node ?

2 Likes

I also have a doubt regarding the point mentioned in this thread.

Let’s say I have custom a nodeView defined for paragraph node to process and assign some special attributes to the DOM, which otherwise would be hard to set with simple toDOM() method.

But based on reply from @marijn, if we need to keep both for drag/drop and copy/paste to function, then how should we manage the differences of logic between toDOM and nodeView, as the paragraph displayed in the editor may turn out to be different based on which one is method gets executed.

No, it may not. If you define a node view, that’s what is used inside the editable DOM. The text on the clipboard will use the toDOM method.

1 Like