Allow NodeViews to dictate it's conten.size


#1

I would like to define custom NodeView that could also render some editable content from attributes based on mode. For example to define LinkView that could expand from:

<a href="#address" title="title"><span>link<span></a>

to following when cursor is with-in the node range:

<a href=#address title=title>
  <span class=markup>[</span>
  <span class=name>link<span>
  <span class=markup>](</span>
  <span class=address>#address<span>
  <span class=markup> </span>
  <span class=title>"title"</span>
</a>

Problem I’ve run into is that if I expose span.name as contentDOM prose mirror treats my LinkView as if it’s only content was link (cursor positions anywhere in the address or markup fields remain same & edits there make cursor jump back to the end of the link|).

Would it be possible & also make sense to let nodeView’s expose contentSize field ? That would allow NodeView to render attribute and computed data with in itself.

Another alternative could be to allowing NodeView to expose multiple fields for it’s content instead of just (contentDOM) to allow ProseMirror to take care of rendering node’s children into designated containers.


#2

A node view is just a view on the node as defined by the schema. Most code will work with the node, not the view, so I don’t see how the view defining the size of the node could make sense.

If you model the node’s content as a fixed set of child nodes, you could add node views (or not) to the child nodes to control how they are rendered. Having different content areas in a single node view is not supported (and would be difficult to support, since it breaks the model of one node per view).