Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
handler: (text, selection) => {
const delta = new Delta()
.retain(selection.index - 3)
.delete(4) // 1 more for the enter.
.insert("\n", { "code-block": true });
this.quill.updateContents(delta, Quill.sources.USER);
this.quill.setSelection(selection.index - 3, 0, Quill.sources.USER);
},
},
if (!(lastBlot instanceof ExternalEmbedBlot)) {
return;
}
// Filter out click events that aren't below the last item in the document.
const blotRect = (lastBlot.domNode as HTMLElement).getBoundingClientRect();
const bottomOfBlot = blotRect.bottom;
if (event.y <= bottomOfBlot) {
// The click not on the bottom section of the document.
return;
}
const newline = new BlockBlot(BlockBlot.create("\n"));
newline.insertInto(this.quill.scroll);
this.quill.update(Quill.sources.USER);
this.quill.setSelection(this.quill.scroll.length(), 0, Quill.sources.USER);
};
}
return true;
}
// Bail out if the blot contents are not plain text or a link.
const firstBlotName = (line as any).children.head.statics.blotName;
if ((line as BlockBlot).children.length > 1 || !["text", "link"].includes(firstBlotName)) {
return true;
}
let textContent = line.domNode.textContent || "";
textContent = textContent.trim();
if (isAllowedUrl(textContent)) {
const embedInsertionModule: EmbedInsertionModule = this.quill.getModule("embed/insertion");
const index = line.offset();
this.quill.deleteText(index, line.length(), Quill.sources.USER);
this.quill.insertText(index, "\n", Quill.sources.USER);
this.quill.setSelection(index, 0, Quill.sources.USER);
embedInsertionModule.scrapeMedia(textContent);
return false;
}
return true;
};
() => {
if ((this.quill as any).selection.composing) {
return;
}
this.quill.update(Quill.sources.USER);
const selection = this.quill.getSelection();
const codeBlocks = (this.quill.scroll.descendants(
blot => blot instanceof CodeBlockBlot,
0,
this.quill.scroll.length() - 1,
) as any) as CodeBlockBlot[];
if (codeBlocks.length === 0) {
return; // Nothing to do here.
}
codeBlocks.forEach(code => {
code.highlight();
});
this.quill.update(Quill.sources.SILENT);
const hasFocus = this.quill.hasFocus();
this.quill.update(Quill.sources.USER);
const selection = this.quill.getSelection();
const codeBlocks = (this.quill.scroll.descendants(
blot => blot instanceof CodeBlockBlot,
0,
this.quill.scroll.length() - 1,
) as any) as CodeBlockBlot[];
if (codeBlocks.length === 0) {
return; // Nothing to do here.
}
codeBlocks.forEach(code => {
code.highlight();
});
this.quill.update(Quill.sources.SILENT);
const hasFocus = this.quill.hasFocus();
if (selection && hasFocus) {
this.quill.setSelection(selection, Quill.sources.SILENT);
}
},
SyntaxModule.THROTTLE_DURATION,
private createAutoCompleteBlot(): MentionAutoCompleteBlot | null {
const { currentSelection, mentionSelection } = this.props;
if (!currentSelection || !mentionSelection) {
return null;
}
this.quill.formatText(
mentionSelection.index,
mentionSelection.length,
"mention-autocomplete",
true,
Quill.sources.API,
);
this.quill.setSelection(currentSelection.index, 0, Quill.sources.API);
// Get the autoCompleteBlot
const autoCompleteBlot = getBlotAtIndex(this.quill, currentSelection.index - 1, MentionAutoCompleteBlot)!;
return autoCompleteBlot;
}
private insertEmojiBlot = (event: React.SyntheticEvent) => {
const range = this.quill.getSelection(true);
this.quill.insertEmbed(
range.index,
"emoji",
{
emojiChar: this.emojiChar,
},
Quill.sources.USER,
);
this.quill.setSelection(range.index + 1, 0, Quill.sources.SILENT);
this.props.closeMenuHandler(event);
};
private codeFormatter = (menuItemData: IMenuItemData) => {
if (!this.props.currentSelection) {
return;
}
this.quill.removeFormat(
this.props.currentSelection.index,
this.props.currentSelection.length,
Quill.sources.API,
);
this.quill.formatText(
this.props.currentSelection.index,
this.props.currentSelection.length,
"codeInline",
!menuItemData.active,
Quill.sources.USER,
);
};
}
handler: (range, context) => {
if (
rangeContainsBlot(this.quill, CodeBlockBlot, range) ||
rangeContainsBlot(this.quill, CodeBlot, range)
) {
return;
}
this.quill.format(format, !context.format[format], Quill.sources.USER);
},
};
public createEmbed = (embedValue: IEmbedValue) => {
const externalEmbed = Parchment.create("embed-external", embedValue) as ExternalEmbedBlot;
insertBlockBlotAt(this.quill, this.quill.getLastGoodSelection().index, externalEmbed);
this.quill.update(Quill.sources.USER);
externalEmbed.focus();
};