Hi! I have a simple custom node defined as such:
export const RootBlock = Node.create({
name: "rootblock",
group: "rootblock",
content: "block", // Ensure only one block element inside the rootblock
draggable: true, // Make the node draggable
selectable: true, // Node isn't selectable
inline: false, // Node is a block-level element
priority: 1000, // Priority for node resolution
}).
and a custom Doc as such:
const Document = Node.create({
name: 'doc',
topNode: true,
content: "rootblock+",
})
The purpose is simple. Each rootnode can only hold 1 block. I use this to add attributes, define custom functionality and allow for a custom handle to DND the block without worrying about selecting all the text below it etc.
However, I am running into a few issues:
-
when i select text that bleeds across multiple rootblocks, the fragment from/to is always different than the view.selection from/to. i can delete without errors if the selection is made via keyboard. but if I drag select via mouse, often, i will run into a Uncaught RangeError: Position x outside of fragment (since the fragment seems to be constrained to the 1 rootblock and not across blocks). This causes problems for future adding blocks (via Enter key) and sometimes, will eventually lead to this error also: Failed to execute ‘insertBefore’ on ‘Node’: The node before which the new node is to be inserted is not a child of this node. Any thoughts how to resolve?
-
having a rootnode above the block also affects the ability to convert text across multiple rootblocks to bullets / lists, and vice versa. also when i key down / up (if the selection starts in the middle of the text), the behavior is different than under default block settings. i wonder if there’s an easy way to configure the “rootblock wrapper” without causing all these side effects.
Alternatively, I tried embedding the attributes / functionalities with the different block types (paragraph, heading, etc) but this causes DND issues and other complications.
Any recommendation how to approach this? In general, I need custom attributes, ability to DND via a drag handle, ability to work with DOM and appendTransaction, which I’ve generally been able to do with the rootblock wrapper.
Thanks in advance!