Expanding/Collapsing view content

I would like my editor to support expanding/collapsing block content. I’ve got a structured document schema where the document is composed of sections, and each section is composed of a title followed by the usual cast of block players. I’d like to let the user collapse a section to only show the title, if they wanted. I don’t want the “expanded/collapsed” state to be part of the document since I am allowing collaboration and am willing to let this state be non-persistent for the time being. I have attempted this with a node view, but I can’t seem to convince the editor view instance that it needs to update.

After thinking about the problem more, it seems like a plugin is the right tact, but I’m not entirely sure how just yet. I’m just looking for confirmation that a) this is possible with Prosemirror and b) decorations are the way to go. (I’m still riding around in training wheels with this library…)

Node views can observe the node decorations that apply to them. So the most straightforward way to do this is probably to have a plugin managing information about collapsed nodes as a set of node decorations, along with a node view that responds to such decorations by hiding its content (and maybe shows a control that allows the user to fire the transactions that hide/show the node).

1 Like

Thanks. I’ve about got it.

Ok, I lied. I don’t “about have it”. I was errantly putting the “collapsed/expanded” state in the view, but I see this needs to be deco. However, my UI is in the node view. Does the UI have access to the plugin’s decorations/state?

The view’s update method gets called with a list of decorations.

1 Like