Implement children and attributes disallowing in Schema #15835
Labels
domain:dx
This issue reports a developer experience problem or possible improvement.
package:engine
squad:collaboration
Issue to be handled by the Collaboration team.
support:2
An issue reported by a commercially licensed client.
type:feature
This issue reports a feature request (an idea for a new functionality or a missing option).
Milestone
📝 Provide a description of the new feature
Right now when defining the schema, you can
register()
new elements orextend()
how existing elements behave. When you do it, you can directly specify which children/attributes are allowed on the new/updated element. Or you can set that a new element should allow the same children/attributes as another element. Or you can do both.But you can't exclude.
There's no way to disallow children/attributes for already specified element (if you want to modify its behavior).
There's no way to disallow for a new element if you want to base it on existing element (e.g. "allow all children of root, except of tables").
This is crucial for creating more complex integrations, especially if you want to structure the document (e.g. root should only include a title and structure-containers).
I haven't gone into technical details when researching this issue, so I might be missing something. Here are general guides. The way the schema extensions work is that we have a set of rules for each item. Some are direct ("allow child Z"), some are inherited ("allow same children as Y"). When the schema is changed, these rules are "compiled". For example, for element Y, we resolve all children it can have. Then we go to element X, and e.g. we take all resolved children of Y ("allow same children as Y") and add specific children declared for element X.
Finally,
SchemaCompiledItemDefinition
has only resolved items inallowIn
,allowChildren
, andallowAttributes
.Given this flow, I think it should be possible to implement
disallowChildren
anddisallowAttributes
property. You would first resolve allowed children and then remove disallowed ones. Disallows will always take precedence over allows.For example, let's have such configuration:
$block
allows attributelistItemId
,paragraph
allows attributes of block and alsotextAlign
,myCustomParagraph
allows attributes of paragraph but disallowslistItemId
.When compiling,
$block
is topmost (I wonder if we solved problem with recursion?), it allowslistItemId
. Thenparagraph
is resolved, takeslistItemId
and addstextAlign
. ThenmyCustomParagraph
is resolved, takeslistItemId, textAlign
and removeslistItemId
. If some other element wouldallowAttributesOf: 'myCustomParagraph'
then it would only gettextAlign
.The text was updated successfully, but these errors were encountered: