Slate: Void nodes can contain blocks?

Created on 3 Apr 2018  路  6Comments  路  Source: ianstormtaylor/slate

Do you want to request a _feature_ or report a _bug_?

Either a bug or a question :)

What's the current behavior?

The current behavior is that as of https://github.com/ianstormtaylor/slate/pull/1663/files#diff-4a9856aa0d6cae32f324558beae45156, isVoid blocks can now contain child blocks as opposed to only text nodes. Consider:

/** @jsx h */
import h from '../../helper/hyperscript';

// This test case verifies an image block cannot conatin other block types.
export const input = (
  <value>
    <document>
      <title>Title</title>
      <image src="https://www.notarealimage.png" />
      <image src="https://www.notarealimage.png"><h6>Images - Header</h6></image>
      <image src="https://www.notarealimage.png"><blcode>Images - BlockCode</blcode></image>
      <image src="https://www.notarealimage.png"><quote>Images - Quote</quote></image>
      <image src="https://www.notarealimage.png"><title>Images - Title</title></image>
      <image src="https://www.notarealimage.png"><p>Images - Paragraph</p></image>
      <image src="https://www.notarealimage.png">
        <ol><oli>Images - OrderedListItem</oli></ol>
      </image>
      <image src="https://www.notarealimage.png">
        <ul><uli>Images - OrderedListItem</uli></ul>
      </image>
      <image src="https://www.notarealimage.png"><b><i><u><c>Images - Marks</c></u></i></b></image>
      <image src="https://www.notarealimage.png">
        <table><tr><td>Images - Table</td></tr></table>
      </image>
      <p>Paragraph</p>
    </document>
  </value>
);

export const output = (
  <value>
    <document>
      <title>Title</title>
      <image src="https://www.notarealimage.png" />
      <image src="https://www.notarealimage.png" />
      <image src="https://www.notarealimage.png" />
      <image src="https://www.notarealimage.png" />
      <image src="https://www.notarealimage.png" />
      <image src="https://www.notarealimage.png" />
      <image src="https://www.notarealimage.png" />
      <image src="https://www.notarealimage.png" />
      <image src="https://www.notarealimage.png" />
      <image src="https://www.notarealimage.png" />
      <p>Paragraph</p>
    </document>
  </value>
);

This test case (perhaps a bit contrived) verified that malformed image blocks with children would have their children removed by the schema rules. Now what happens is that these non-text-node children are allowed to exist.

What's the expected behavior?

I'm not sure. The documentation says a void block has one text child, and the PR description seems to indicate that the intention is to give the void block the ability to have arbitrary text, but the removal of the validation rule suggests that the intention is to allow void blocks to have arbitrary children. But I can't help but wonder what the point of the void node is then in that case?

Happy to submit a PR if that's the direction we need to go. Just wanted to check in and get my mental model straightened out at least :)

Thanks for your time

question

Most helpful comment

I've been working on an isAtomic schema controlled option for blocks for an issue here: https://github.com/ianstormtaylor/slate/issues/1654

But it's really early and I'm still working on developing the test cases up front. Lots of corner cases.

All 6 comments

Watching ~

I don't see why not 馃槃 But more seriously, I think it would be nice for the restriction on void nodes content to be completely lifted, so yeah if someone wants to put blocks in their void blocks they could. I personally don't have a use case for it yet, but I might in the future.

(This may unlock interesting use cases where an entire document is represented in the children of a void block鈥攆or nested editors.)

But I can't help but wonder what the point of the void node is then in that case?

That's a very good question indeed!

I think the only distinction is that as far as the editor is concerned, they are an opaque data structure, which impacts editing behaviors. Although this might be incorrect, so I'd welcome anyone trying to arrive at the correct definition if so.

(It sounds like the documentation needs to be updated.)

This is a cool concept, but yeah at the very least the documentation needs to be updated to reflect this. We're approaching kind of an interesting space where we can have mergability of nodes controlled with isVoid (this sounds like what you're suggesting but maybe not) as opposed to controlling whether a node is directly editable and has children.

So in this new model we're sort of transitioning towards, do you see isVoid nodes having editable children? Might need a new name in that case.

So in this new model we're sort of transitioning towards, do you see isVoid nodes having editable children? Might need a new name in that case.

If we do that, I'd assume that any editable node with the void then would be managed 100% by the consumer, rather than Slate?

I think isVoid will remain as a node whose content is out of the concern of Slate, and treated as a single, atomic block.

We might need to introduce isAtomic or similar if people want to have nodes that are atomic but still controlled by Slate. I haven't really thought that through though.

I've been working on an isAtomic schema controlled option for blocks for an issue here: https://github.com/ianstormtaylor/slate/issues/1654

But it's really early and I'm still working on developing the test cases up front. Lots of corner cases.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ianstormtaylor picture ianstormtaylor  路  3Comments

markolofsen picture markolofsen  路  3Comments

ianstormtaylor picture ianstormtaylor  路  3Comments

vdms picture vdms  路  3Comments

bunterWolf picture bunterWolf  路  3Comments