How to use the quill/core.sources function in quill

To help you get started, we’ve selected a few quill examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vanilla / vanilla / plugins / rich-editor / src / scripts / quill / MarkdownModule.ts View on Github external
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);
            },
        },
github vanilla / vanilla / plugins / rich-editor / src / scripts / quill / NewLineClickInsertionModule.ts View on Github external
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);
    };
}
github vanilla / vanilla / plugins / rich-editor / src / scripts / quill / KeyboardBindings.ts View on Github external
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;
    };
github vanilla / vanilla / plugins / rich-editor / src / scripts / quill / SyntaxModule.ts View on Github external
() => {
            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();
github vanilla / vanilla / plugins / rich-editor / src / scripts / quill / SyntaxModule.ts View on Github external
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,
github vanilla / vanilla / plugins / rich-editor / src / scripts / toolbars / MentionToolbar.tsx View on Github external
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;
    }
github vanilla / vanilla / plugins / rich-editor / src / scripts / components / popovers / pieces / EmojiButton.tsx View on Github external
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);
    };
github vanilla / vanilla / plugins / rich-editor / src / scripts / components / toolbars / pieces / InlineToolbarItems.tsx View on Github external
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,
        );
    };
}
github vanilla / vanilla / plugins / rich-editor / src / scripts / quill / KeyboardBindings.ts View on Github external
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);
            },
        };
github vanilla / vanilla / plugins / rich-editor / src / scripts / quill / EmbedInsertionModule.ts View on Github external
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();
    };