Our documents have exactly 6 parts that should always be there and not be deletable.
In version 0.5.1, I solved this by using a filter transform:
onFilterTransform(transform) {
let prohibited = false
const docParts = ['title', 'metadatasubtitle', 'metadataauthors', 'metadataabstract',
'metadatakeywords', 'documentcontents']
let index = 0
transform.doc.forEach(function(childNode){
if (index > 5) {
prohibited = true
} else if (docParts[index] !== childNode.type.name) {
prohibited = true
}
index++
})
if (index < 5) {
prohibited = true
}
return prohibited
}
This worked well.
For version 0.6.0, I tried to adjust it slightly, making use of the childCount property of nodes:
onFilterTransform(transform) {
let prohibited = false
const docParts = ['title', 'metadatasubtitle', 'metadataauthors', 'metadataabstract',
'metadatakeywords', 'documentcontents']
if (transform.doc.childCount === 6) { // There should always be exactly 6 parts to the document
let index = 0
transform.doc.forEach(function(childNode){
if (docParts[index] !== childNode.type.name) {
prohibited = true
}
index++
})
} else {
prohibited = true
}
return prohibited
}
However, this doesn’t work anymore. If I try to select text from the title and into the document contents and hit “backspace”, it now throws a JS error of “Content can not be wrapped in ancestor title” (title can indeed only take text content), but visually the elements are merged on screen.
What’s the suggested workaround for this?