I’ve got it working with NodeView
and Decoration
.
Updating my variable values through a Transaction
updates related Decoration
s which in turn updates related NodeView
s. All encapsulated nicely in a Plugin
and the variable values are now part of the state of my Plugin
. The respective NodeSpec
is also defined by the Plugin
and accessed using plugin.nodeSpecs
.
But I still have to access a variable’s value in NodeSpec.toDOM()
for copy & paste to work properly. Unfortunately I’ve only got access to the Node
and not the EditorState
, so I cannot access the variable values from my Plugin
’s state.
There are multiple potential paths forward now:
- I find a way to access a
Plugin
’s state from withinNodeSpec.toDOM()
.
I don’t think there is a proper one. - I maintain a reference the
EditorView
from within myNodeSpec
in order to access the currentEditorState
.
That doesn’t sound clean. - I allow my
Plugin
to provide aDOMSerializer
that can serialize myNodeSpec
. The problem here is the same as withtoDOM()
though: I don’t have access to theEditorState
.
So also not clean. - I put all state of a variable (label, value, etc.) directly into all
Node
s that reference it. I replace theseNode
s every that state changes.
That doesn’t sound right either. The node is only a simple variable reference with a name. Adding the value and other information to it shouldn’t be necessary.
It’s basically similar to the issue that I already have with state-sensitive text serialization, just with HTML this time:
Desired HTML output:
<span data-variable="varname">varvalue</span>
(varname
is a Node
attribute, varvalue
is Plugin
state)
Desired text output:
varvalue
Am I missing something here or is there no good solution to that problem?