diff --git a/docs/src/demos/Guide/NodeViews/TableOfContents/Component.vue b/docs/src/demos/Guide/NodeViews/TableOfContents/Component.vue
index 00dcfb3f..22ea1f62 100644
--- a/docs/src/demos/Guide/NodeViews/TableOfContents/Component.vue
+++ b/docs/src/demos/Guide/NodeViews/TableOfContents/Component.vue
@@ -7,7 +7,9 @@
v-for="(heading, index) in headings"
:key="index"
>
- {{ heading.text }}
+
+ {{ heading.text }}
+
@@ -38,17 +40,41 @@ export default {
handleUpdate() {
const headings = []
- this.editor.state.doc.descendants(node => {
+ this.editor.state.doc.descendants((node, pos) => {
if (node.type.name === 'heading') {
+ const id = `heading-${headings.length + 1}`
+
+ if (node.attrs.id !== id) {
+ this.updateNodeAttributes(node, pos, {
+ id,
+ })
+ }
+
headings.push({
level: node.attrs.level,
text: node.textContent,
+ id,
})
}
})
this.headings = headings
},
+ updateNodeAttributes(node, pos, attributes) {
+ const { state } = this.editor.view
+ const transaction = state.tr.setNodeMarkup(pos, undefined, {
+ ...node.attrs,
+ ...attributes,
+ })
+
+ console.log(pos, undefined, {
+ ...node.attrs,
+ ...attributes,
+ })
+
+ // TODO: Why is that not needed? 🤔
+ this.editor.view.dispatch(transaction)
+ },
},
mounted() {
@@ -58,10 +84,6 @@ export default {
}
-
-