How to map the editor state to a different shape? #1710
-
My use case is an input that when typing [
{ "type": "text", "value": "hello " },
{ "type": "attribute", "value": "world" },
{ "type": "text", "value": "!" }
]
The UI will work very similarly to this slate demo: https://www.slatejs.org/examples/mentions It looks like I can I think this may be related to a more general question: How do I traverse the editor state? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
What are you looking to do? I'm a bit lost. Are you looking to implement mentions? We have mentions working on the playground and that might help you there. As for serializing and parsing editor states, you can do:
|
Beta Was this translation helpful? Give feedback.
-
Oh, I presume you're referring to server-side content. At Meta, where we store old Draft.js based documents in a particular JSON-like format, we just run a
The example above is oversimplified, it will get hairer than that, that's why @trueadm recommended For real-time side-to-side rendering see #1825 |
Beta Was this translation helpful? Give feedback.
Oh, I presume you're referring to server-side content. At Meta, where we store old Draft.js based documents in a particular JSON-like format, we just run a
$dfs
to perform the conversionThe example above is oversimplified, it will get hairer than that, that's why @trueadm recommended
JSON.stringify(editor.getEditorState())
when possible. Also, you don't necessarily have to use$dfs
, you can do your own tree traversal starting from$getRoot()
.For real-time side-to-side rendering see #1825