Hello everyone,
I am currently facing an issue with the root node in ProseMirror where the root appears to be a table
node instead of the usual doc
node. I have confirmed this by using the descendants
method to traverse the nodes and by checking view.state.doc.nodeAt(0)
.
Here’s the snippet I used for traversal:
view.state.doc.descendants((node, pos) => {
console.log('Node type:', node.type.name, 'at pos:', pos);
});
// Node type: table at pos: 0
// Node type: table_row at pos: 1
// Node type: table_header at pos: 2
// Node type: paragraph at pos: 3
// Node type: table_header at pos: 6
// Node type: paragraph at pos: 7
// Node type: paragraph at pos: 12
However, the situation gets even more confusing. When I print the JSON representation of the document using view.state.doc.toJSON()
, the root node shows up as doc
, which is what I would expect.
console.log(JSON.stringify(view.state.doc.toJSON(), null, 2));
// {
// "type": "doc",
// "content": [
// {
// "type": "table",
// "attrs": {
// "widthSet": "",
// "changingWidthSet": "",
// "rootWidth": 0,
// "delay": 0
// },
// "content": [
// {
// "type": "table_row",
// "content": [
// {
// "type": "table_header",
// "attrs": {
// "colspan": 1,
// "rowspan": 1,
// "alignment": "left"
// },
// "content": [
// {
// "type": "paragraph",
// "attrs": {
// "indent": 0,
// "align": "none"
// }
// }
// ]
// },
// {
// "type": "table_header",
// "attrs": {
// "colspan": 1,
// "rowspan": 1,
// "alignment": "left"
// },
// "content": [
// {
// "type": "paragraph",
// "attrs": {
// "indent": 0,
// "align": "none"
// }
// }
// ]
// }
// ]
// }
// ]
// },
// {
// "type": "paragraph",
// "attrs": {
// "indent": 0,
// "align": "none"
// }
// }
// ]
// }