slab/parchment

registering a new blot does not add it to the allowed children of the scroll object

Closed this issue · 0 comments

Hi, I am trying to write a command line module which involves creating a new blot (CommandLine) which extends Container

I register the new blot type like so Parchment.register(CommandLine).

However when I go to instantiate one of these blots either through

this.quill.insertEmbed(0, "cli", "") or more directly this.quill.scroll.insertAt(0, "cli", ""), I get this error:

quill.js:143 Uncaught Error: [Parchment] Cannot insert cli into scroll
    at new ParchmentError (quill.js:143)
    at Scroll.ContainerBlot.insertBefore (quill.js:3461)
    at Scroll.insertBefore (quill.js:4331)
    at Scroll.ContainerBlot.appendChild (quill.js:3369)
    at Scroll.insertAt (quill.js:4316)
    at Editor.insertEmbed (quill.js:2651)
    at eval (quill.js:1424)
    at Quill.modify (quill.js:1655)
    at Quill.insertEmbed (quill.js:1423)
    at CommandLine.display (module.ts:118)

Tracing my way through the error stack, I observe that the error is thrown because scroll doesn't have the CommandLine as one of the allowedChildren

allowedChildren: Array(3)
0: ƒ Block(domNode)
1: ƒ BlockEmbed()
2: ƒ Container()

To override this, in the constructor of the module, I add:

this.quill.scroll.statics.allowedChildren.push(CommandLine)

However, I would have thought that registering this new blot type would have also added it as an allowed children of scroll. Has anyone else experienced this / can help me with this. Thanks