Reputation: 214
I've managed to set up ngx-quill in angular 7 and I would need to create a custom text blot which would look as follows (simplified):
... /*** Custom blot: [its editable text content] ***/ ...
I have to be able to do the following:
My custom blot so far:
/**
* REGISTER BLOT: CUSTOM
*/
var Embed = Quill.import('blots/embed');
class QuillBlotCustom extends Embed {
static blotName: string = 'cmd-custom';
static className: string = 'quill-cmd-custom';
static tagName: string = 'span';
static create(value: { cmd: any, ... }) {
let node = super.create(value);
const content = value.cmd.content ? value.cmd.content : '';
node.innerHTML = `<span>${value.cmd.prefix}${value.cmd.title}: <span contenteditable=true>${content}</span>${value.cmd.postfix}</span>`;
node.style.color = value.cmd.color;
node.style.backgroundColor = value.cmd.bgColor;
node.setAttribute('valueCmd', JSON.stringify(value.cmd));
node.addEventListener('keydown', function(e) {
// handling Enter key
if (e.keyCode === 13) {
e.preventDefault();
// HOW TO ACCESS QUILL INSTANCE FROM HERE?
}
});
setTimeout(() => {
return node;
}
static value(node) {
const val = {
cmd: JSON.parse(node.getAttribute('valueCmd')),
//text: node.firstElementChild.firstElementChild.firstElementChild.innerText,
node: node
};
val.cmd.content = node.firstElementChild.firstElementChild.firstElementChild.innerText
return val;
}
update(mutations: MutationRecord[], context: {[key: string]: any}) {
console.log('update');
}
}
Quill.register({
'formats/cmd-custom': QuillBlotCustom
});
I can easily create such a blot with arbitrary content by calling
const cmd = ...;
this.quill.insertEmbed(range.index, 'cmd-custom', { cmd: cmd });
And then I'm stuck at how to proceed from this point.
So:
Every help is appreciated! :)
Upvotes: 3
Views: 1780
Reputation: 11
Although likely not the answer you're looking for I may have some insight for you.
By the way I'm currently struggling with this same issue and was coming here to look for guidance on what the best practice may be.
A potential solution for you however is to add and expose your own functions on the Blot. From their you can attach whatever you'd like from your constructor to the node itself before returning it.
Then when you have a modification of data external to quill you can use quill to query all your blots of a type to then call those external functions.
Upvotes: 1