Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(quill, bounds) {
super(quill, bounds);
this.quill.on(Emitter.events.EDITOR_CHANGE, (type, range, oldRange, source) => {
if (type !== Emitter.events.SELECTION_CHANGE) return;
if (range != null && range.length > 0 && source === Emitter.sources.USER) {
this.show();
// Lock our width so we will expand beyond our offsetParent boundaries
this.root.style.left = '0px';
this.root.style.width = '';
this.root.style.width = this.root.offsetWidth + 'px';
let lines = this.quill.getLines(range.index, range.length);
if (lines.length === 1) {
this.position(this.quill.getBounds(range));
} else {
let lastLine = lines[lines.length - 1];
let index = this.quill.getIndex(lastLine);
let length = Math.min(lastLine.length() - 1, range.index + range.length - index);
let bounds = this.quill.getBounds(new Range(index, length));
this.position(bounds);
listen() {
super.listen();
this.root.querySelector('.ql-close').addEventListener('click', () => {
this.root.classList.remove('ql-editing');
});
this.quill.on(Emitter.events.SCROLL_OPTIMIZE, () => {
// Let selection be restored by toolbar handlers before repositioning
setTimeout(() => {
if (this.root.classList.contains('ql-hidden')) return;
let range = this.quill.getSelection();
if (range != null) {
this.position(this.quill.getBounds(range));
}
}, 1);
});
}
this.quill.on(Emitter.events.EDITOR_CHANGE, (type, range, oldRange, source) => {
if (type !== Emitter.events.SELECTION_CHANGE) return;
if (range != null && range.length > 0 && source === Emitter.sources.USER) {
this.show();
// Lock our width so we will expand beyond our offsetParent boundaries
this.root.style.left = '0px';
this.root.style.width = '';
this.root.style.width = this.root.offsetWidth + 'px';
let lines = this.quill.getLines(range.index, range.length);
if (lines.length === 1) {
this.position(this.quill.getBounds(range));
} else {
let lastLine = lines[lines.length - 1];
let index = this.quill.getIndex(lastLine);
let length = Math.min(lastLine.length() - 1, range.index + range.length - index);
let bounds = this.quill.getBounds(new Range(index, length));
this.position(bounds);
}
} else {
this.edit('link', this.preview.textContent);
}
event.preventDefault();
});
this.root.querySelector('a.ql-remove').addEventListener('click', (event) => {
if (this.linkRange != null) {
let range = this.linkRange;
this.restoreFocus();
this.quill.formatText(range, 'link', false, Emitter.sources.USER);
delete this.linkRange;
}
event.preventDefault();
this.hide();
});
this.quill.on(Emitter.events.SELECTION_CHANGE, (range, oldRange, source) => {
if (range == null) return;
if (range.length === 0 && source === Emitter.sources.USER) {
let [link, offset] = this.quill.scroll.descendant(LinkBlot, range.index);
if (link != null) {
this.linkRange = new Range(range.index - offset, link.length());
let preview = LinkBlot.formats(link.domNode);
this.preview.textContent = preview;
this.preview.setAttribute('href', preview);
this.show();
this.position(this.quill.getBounds(this.linkRange));
return;
}
} else {
delete this.linkRange;
}
this.hide();
setupSelectionListener() {
this.quill.on(Emitter.events.EDITOR_CHANGE, this.handleEditorChange);
}
fillSelect(select, FONTS);
} else if (select.classList.contains('ql-header')) {
fillSelect(select, HEADERS);
} else if (select.classList.contains('ql-size')) {
fillSelect(select, SIZES);
}
}
return new Picker(select);
}
});
let update = () => {
this.pickers.forEach(function(picker) {
picker.update();
});
};
this.quill.on(Emitter.events.EDITOR_CHANGE, update);
}