Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
format(format, value) {
this.scroll.update();
let nativeRange = this.getNativeRange();
if (nativeRange == null || !nativeRange.native.collapsed || Parchment.query(format, Parchment.Scope.BLOCK)) return;
if (nativeRange.start.node !== this.cursor.textNode) {
let blot = Parchment.find(nativeRange.start.node, false);
if (blot == null) return;
// TODO Give blot ability to not split
if (blot instanceof Parchment.Leaf) {
let after = blot.split(nativeRange.start.offset);
blot.parent.insertBefore(this.cursor, after);
} else {
blot.insertBefore(this.cursor, nativeRange.start.node); // Should never happen
}
this.cursor.attach();
}
this.cursor.format(format, value);
this.scroll.optimize();
this.setNativeRange(this.cursor.textNode, this.cursor.textNode.data.length);
this.update();
}
show(img) {
// keep track of this img element
this.img = img;
const rect = this.img.getBoundingClientRect();
const rootRect = this.quill.root.getBoundingClientRect();
this.showBox(rect, rootRect);
// 移动游标到图片右侧
let blot = Parchment.find(img);
let index = blot.offset(this.quill.scroll);
console.log('image index', index);
this.quill.setSelection(index + 1, 0);
//鼠标点击,删除键等操作的时候,去掉选中态
this.quill.once('editor-change',()=>{this.hide();});
}
let indexes = positions.map((position) => {
let [node, offset] = position;
let blot = Parchment.find(node, true);
let index = blot.offset(this.scroll);
if (offset === 0) {
return index;
} else if (blot instanceof Parchment.Container) {
return index + blot.length();
} else {
return index + blot.index(node, offset);
}
});
let start = Math.min(...indexes), end = Math.max(...indexes);
public getEmbedBlotForFocusedElement() {
if (!(document.activeElement instanceof Element)) {
return;
}
let activeElement = document.activeElement;
if (!activeElement.classList.contains("js-embed")) {
const closestEmbed = activeElement.closest(".js-embed");
if (!closestEmbed) {
return;
}
activeElement = closestEmbed;
}
return Parchment.find(activeElement);
}
(event, clickedElement) => {
if (isEditorWalledEvent(event)) {
return;
}
const embed = Parchment.find(clickedElement);
if (embed instanceof FocusableEmbedBlot) {
embed.focus();
}
},
this.quill.container,
[].slice.call(this.domNode.querySelectorAll('*')).forEach(function(node) {
let blot = Parchment.find(node);
if (blot == null) {
node.parentNode.removeChild(node);
} else if (blot instanceof Parchment.Embed) {
blot.remove();
} else {
blot.unwrap();
}
});
}
this.editor.root.addEventListener('click', (event) => {
let blot = Parchment.find(event.target, true);
if (blot instanceof EmbedImageBlot) {
let values = blot.value(blot.domNode)['embed-image'];
values.existingBlot = blot;
this.showEmbedImageModal(values);
}
if (blot instanceof EmbedContentBlot) {
let content = blot.value(blot.domNode)['embed-content'];
content.existingBlot = blot;
this.showEmbedContentModal(content);
}
});
},