Questionable .children requirement for void types
See original GitHub issueDo you want to request a feature or report a bug?
Not really a bug, more a design consern
What’s the current behavior?
First off, I just want to say that Slate has become really great with the latest release. I am amazed how good the APIs have become, making it a proper editor toolkit with much freedom create the editor you want.
However there is one pretty bad design fault in the latest version in my opinion - and that is the requirement of void nodes to have a .children
with at least one Text
node inside it. This doesn’t make much sense to me, and seems like something that is forced there to work around the problems we have had with void node selections.
It feels weird to require an arbitrary property and a text node inside our non-text elements (as void blocks are supposed to be), just to support the selection model. Could not this be handled outside the value itself?
This makes it really hard to make the editor a truly controlled component if your value model is slightly different. I’m implementing an editor with the new version of Slate to use Portable Text (https://github.com/portabletext/portabletext) as the native value format. I had great success in this using the new APIs. For instance, I was able to replace the whole built in marks model to fit the marks model of Portable Text and the text blocks are now truly Portable Text inside the editor, meaning we don’t have to convert from and to the different formats.
With this freedom in mind, it feels really limiting that we can’t have a void object in the value with the data structure we’d like. It means that the editor value and the outside value can no longer be the same object anymore if void elements are supposed to have a custom structure. I expected the text blocks to be the problem here, and not the void ones, so this was a big surprise.
What’s the expected behavior?
That we are free to have void blocks or inlines modelled as we’d like in the actual editor value. Say like:
{type: 'image', url: 'http...'}
and not like
{type: 'image', url: 'http...', children: [{text: ''}]}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:10
- Comments:13 (5 by maintainers)
Top GitHub Comments
Hi, We are in need of this feature for our project use case. Is there a way for us to have void nodes without children or with empty children array and no empty text nodes inside? Is there any overrides / patches available anywhere that i can refer to?
FWIW this is what we currently do.