Closed
Description
I couldn't find any examples of what the JSON format looked like, and I wanted to be sure the format was relatively independent of Craft itself. However, the JSON uses node IDs instead of nesting the nodes themselves, which I find confusing.
For example, with these Frame contents:
<Frame>
<Canvas is={CraftContainer}>
<CraftComponent>
<TextComponent text="my text here" />
</CraftComponent>
</Canvas>
</Frame>
The JSON output from query.serialize()
is:
{
"canvas-ROOT": {
"type": {
"resolvedName": "CraftContainer"
},
"isCanvas": true,
"props": {},
"displayName": "Canvas",
"custom": {},
"nodes": [
"node-yxVcZGJj"
]
},
"node-yxVcZGJj": {
"type": {
"resolvedName": "CraftComponent"
},
"props": {
"children": [
{
"type": {},
"props": {
"text": "text component"
}
}
]
},
"displayName": "CraftComponent",
"custom": {},
"parent": "canvas-ROOT",
"_childCanvas": {
"d02fab54-ddf2-4356-b79d-5660d54915df": "canvas-u-wv625gX"
}
},
"canvas-u-wv625gX": {
"type": {
"resolvedName": "CraftContainer"
},
"isCanvas": true,
"props": {},
"displayName": "Canvas",
"custom": {},
"parent": "node-yxVcZGJj",
"nodes": [
"node-aKYJYqPZ0"
]
},
"node-aKYJYqPZ0": {
"type": {},
"props": {
"text": "my text here"
},
"displayName": "TextComponent",
"custom": {},
"parent": "canvas-u-wv625gX"
}
}
I would expect something more like:
[
{
"type": "CraftContainer",
"nodes": [
{
"type": "CraftComponent",
"nodes": [
{
"type": "TextComponent",
"props": {
"text": "my text here"
}
}
]
}
]
}
]
It would also be nice to have some examples of implementing custom serializers, like SlateJS does. I'm currently using SlateJS as a WYSIWYG React editor, but I'd love to switch to Craft for the nicer drag & drop functionality.