Another thing that irritated me a lot about Draft.js is the fact that Entities can't be applied to the same character in content block. One more reason I had to switch to ProseMirror.
Another thing that irritated me a lot about Draft.js is the fact that Entities can't be applied to the same character in content block. One more reason I had to switch to ProseMirror.
You actually can handle things like "text-align", by adding custom data to nodes, which you can then read back via:
const alignment = node.data.get('alignment')
Where .get(key) can be anything you want.So text alignment would just be deciding on a key/value to use, and then toggling styles in your React component based on the alignment value.
That said, it doesn't handle text alignment "out of the box" if that's what you mean. It doesn't really handle anything out of the box, because you have to opt-in to anything that changes your schema. This is by design though, and it makes it a lot less complicated to use Slate than some of the other frameworks when you start building complex editors. But if you're looking for a drop-in editor that has basic features then Slate is not the right choice.
> it doesn't handle text alignment "out of the box"
That's quite alright. ProseMirror doesn't handle that out of the box too. A lot of new frameworks for rich editors surprisingly don't have that.
function MyNodeComponent(props) {
const { node } = props
const textAlign = node.get('text_align')
return <div style={{ textAlign }} {...props.attributes}>{props.children}</div>
}
Does that work for you? I'd be curious to hear what you mean by "marks but for nodes" and how you were thinking the API would look—sounds interesting!Slate is different than Draft in that it gives you full control over the rendering logic—one of the things that frustrated me when using Draft and that I wanted to solve when creating Slate. It's much more flexible than Draft in that sense.
I haven't really thought much about API or possible implementation for Marks for Nodes. My thoughts generally revolve around the idea that blocks should have extensible styling via Schema in the same way you can add custom Marks in your Schema. You should be able to change styling of the nodes within the Schema instead of overriding block simply because of the alignment or some other minor style.
Since the components are all React components you can use the same types of extending patterns you'd use in React. In this case you'd probably use a higher-order component (HOC) that handles adding to the `style` property based on the node's data. And then you could wrap all of your other blocks with it...
quote_block: alignment(QuoteBlock),
code_block: alignment(CodeBlock),
...
One of the things I started with was making sure that components are just React components, so that all of the patterns that the React ecosystem brings can be used with Slate.There are some bigger architectural things that I'd like to work on, but they're probably best handled by me since lots of context is required. But I've been marking lots of issues as "help please" [1] on GitHub. And other than those, anything marked "bug" [2] would be awesome to get help on too!
[1]: https://github.com/ianstormtaylor/slate/issues?q=is%3Aissue+...
[2]: https://github.com/ianstormtaylor/slate/issues?q=is%3Aissue+...
Just a quick question: is it possible to have text nodes that can't be edited inlined with others editables? I'm thinking of using slate to let users edit specific parts of a legal document (e.g: name, address, DOB, etc). In other words, a WYSIWYG text editor with specific fill in place holders that won't let the user mess with the other parts of the document. Thanks!
Yeah that should be possible, although there might be some weird browser inconsistencies, not totally certain on that. But check out the "Check Lists" example, the checkboxes are actually non-editable content that's rendered right in front of the editable text of the list item.
Than yes - that is certainly a one way to handle it. However this approach would apply a some alignment-related CSS class instead of applying style to the block itself.
Here's what Draft.js would return:
`<p class="align-right">Text Text Text</p>`
I would prefer if it was:
`<p style="text-align:right;">Text Text Text</p>`