feat: add maxDepth to NodeSpec for bounded recursive nesting #93
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "jim-alexander/prosemirror-model:feat/max-depth-node-spec"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Adds an optional maxDepth field to NodeSpec that limits how many times
a node type may appear in its own ancestor chain. A fast-path flag
Schema.hasMaxDepth is precomputed so schemas that don't use the feature
pay no runtime cost.
Enforcement is threaded through:
parentTypes present; viaExceeds walks both document ancestor chain
and BFS wrapping path without materialising a combined array)
All new parameters are optional — existing call sites are unchanged and
all existing behaviour is preserved for schemas that don't declare maxDepth.
This would add another subtle limitation on where nodes can appear, and thus make it even more difficult to write correct generic document-manipulation code. Its motivation doesn't seem very compelling. I suggest you use a transaction appender to fix over-deep nesting, and constrain the user interface to make it harder for people to add such nodes at a level where they shouldn't appear, instead.
Yes that’s the whole point, it’s recursive currently.
I went into lots of detail about why I don’t want to rely on that pattern and why it makes sense for the layer to also have support for limiting, can you please read my accompanying doc here: https://discuss.prosemirror.net/t/feature-request-maxdepth-on-nodespec-upstream-prosemirror-pitch/9009/3
Yes, and I didn't find those motivations convincing. It's not going to be possible to express every possible constraint in the schema (see also table squareness), so transaction appenders and extra checks in the user interface are part of the toolkit you'll have to work with.
This feature is definitely not happening. It adds a non-local type of schema constraint, so that adding a node no longer just requires checking the parent and the node, but also the node's content. It makes content matches no longer a reliable source of truth about content fitting. And more generally it adds a kind of complexity that I very much am not interested in pulling into the library. You can fork, or you can work with the primitives provided by the library. I'm not merging this.
Pull request closed