Hello!
I have a case where I would want to wrap the nodeView’s node (called here paragraphNode) in another block node (called containerNode) upon an ondrop event when something is dropped on the paragraphNode.
So within the ondrop handler that is wired up within the nodeView class I would like to get hold of the paragraphNode and in case it is not already wrapped in containerNode I would like to create a containerNode to wrap the paragraphNode. Regarding this I’d have two questions:
- How can I wrap the paragraphNode in a containerNode with the information available in the nodeView context (node, view, getPos, decorations) ?
- How could I best check if the paragraphNode is already contained by some other node, in this case containerNode?
Regarding the question 1, I have tried the following approach:
const startPosition = node.resolve(getPos()); const endPosition = node.resolve(getPos() + node.nodeSize); const range = new NodeRange(startPosition, endPosition, 0); const { tr } = view.state; tr.wrap(range, [{ type: documentSchema.nodes.containerBlock }]); view.dispatch(tr);
With this I get the error ‘RangeError: Position 52 out of range’ where 52 of course varies based on the content length.
If I modify to endPosition calculation to
const endPosition = node.resolve(getPos() + node.nodeSize - 2);
The resulting error changes to ‘TransformError: Gap is not a flat range’