Consider the following, example container node that accepts “child” nodes as its content:
Schema
export const myContainer: NodeSpec = {
inline: false,
group: 'block',
content: 'child+',
attrs: {},
parseDOM: [{
tag: 'p[data-node-type="my-container"]',
getAttrs: (dom: Element) => ({})
}],
toDOM(node: any): [string, any, number] {
return [
'div',
{
'data-node-type': 'my_container'
},
0
];
}
};
Use-case
- I have a
myContainer
node with exactly 1child
node. - The pos of the child node is
pos
, size is 1 - I remove the node by calling
view.dispatch(view.state.tr.delete(pos, pos + 1))
Expected
The myContainer
node is removed, because I have deleted the last remaining child
node from it (and it requires content to be child+
)
Actual
The myContainer
node is retained and a new “dummy” node of child
type is inserted inside (with default attrs).
Rationale
I see two ways to configure content:
// Zero or more
content: 'child*'
// One or more
content: 'child+'
In the first case, the container node is allowed to remain empty.
In the second case, I want to be able to tell Prosemirror, that a node without content is an invalid one, hence it must be removed from the document.