I wonder if anybody could pinpoint what I might be doing wrong here.
I am trying to create a “custom html” node. All seems fine except on copy paste cut operations i sometimes get “Maximum call stack size exceeded” errors. This is in function compareDeep(a, b) {
This happens when I click on the node twice … so it might be that I am doing the selection of the node wrong.
I have defined it in the schema as
custom_html: {
content: "block+",
group: "block",
defining: true, // node is considered an important parent node during replace operations
selectable: true,
atom: true, // though this isn't a leaf node, it doesn't have directly editable content and should be treated as a single unit in the view.
draggable: false, // does not work !!!
// isolating: true, // When enabled (default is false), the sides of nodes of this type count as boundaries that regular editing operations, like backspacing or lifting, won't cross.
attrs: {
dom: {
default: {}
}
},
parseDOM: [{
tag: 'div',
getAttrs: dom => {
return { dom: dom };
}
// getContent: dom => {
// return 'This is the content of it.'
// }
}],
toDOM(node) {
// console.log('node');
// console.log(node.attrs.dom);
// let n = document.createElement("div");
// n.innerHTML = '<p>Something</p>';
let newClone = node.attrs.dom.cloneNode(true)
// newClone.addEventListener("click", ()=>{ console.log('mouseup');}
return newClone;
}
},
And my NodeView looks like this
import {
// Selection,
// TextSelection,
NodeSelection
// AllSelection
} from "prosemirror-state"
export default class DOMinatorCustomHtmlView {
constructor(node, view, getPos) {
// We'll need these later
this.node = node
this.view = view
this.getPos = getPos
this.dom = node.attrs.dom.cloneNode(true);
this.dom.addEventListener("mousedown", event => {
this.view.dispatch(this.view.state.tr.setSelection(
NodeSelection.create(
this.view.state.doc,
this.getPos()
)));
});
}
selectNode() {
this.dom.classList.add("ProseMirror-selectednode")
}
deselectNode() {
this.dom.classList.remove("ProseMirror-selectednode")
}
update(node, decorations) {
console.log('update --- DOMinatorCustomHtmlView');
}
stopEvent(event) {
if(event.type === 'mousedown'){
return true;
}
return false;
}
ignoreMutation() {
return true;
}
// Called when the node view is removed from the editor or the whole editor is destroyed.
destroy() {
this.dom.remove();
console.log('destroy --- DOMinatorCustomHtmlView');
}
}
You will find all code here. The repo is very easy to get up and running (2 min) if like to see what is happening.