Step 3: Configure the Quill editor with the Velt Comments module
React / Next.js
Other Frameworks
import { useEffect, useRef, useState } from 'react';import Quill from 'quill';import { QuillVeltComments } from '@veltdev/quill-velt-comments';// Register the module with Quill (once, outside component)Quill.register('modules/veltComments', QuillVeltComments);function QuillEditor() { const editorRef = useRef(null); const [quill, setQuill] = useState(null); useEffect(() => { if (!editorRef.current) return; const quillInstance = new Quill(editorRef.current, { theme: 'snow', modules: { veltComments: { persistVeltMarks: true, }, }, }); setQuill(quillInstance); }, []); return <div ref={editorRef} />;}
import Quill from 'quill';import { QuillVeltComments } from '@veltdev/quill-velt-comments';// Register the module with QuillQuill.register('modules/veltComments', QuillVeltComments);// Create editor with the module enabledconst quill = new Quill('#editor', { theme: 'snow', modules: { veltComments: { persistVeltMarks: true, }, },});
Step 4: Add a comment button to your Quill editor
Add a button that users can click to add comments after selecting text.
When clicking a button, the browser moves focus to the button which clears the editor selection. You must save the selection on mousedown (before focus changes) and restore it before adding the comment.
React / Next.js
Other Frameworks
import { useCallback, useRef } from 'react';import { addComment } from '@veltdev/quill-velt-comments';// Inside your QuillEditor component from Step 3:const savedSelectionRef = useRef(null);const handleAddComment = useCallback(() => { if (quill) { if (savedSelectionRef.current) { quill.setSelection(savedSelectionRef.current.index, savedSelectionRef.current.length); } addComment({ editor: quill }); savedSelectionRef.current = null; }}, [quill]);// In your JSX:<button onMouseDown={(e) => { e.preventDefault(); const sel = quill?.getSelection(); if (sel?.length > 0) savedSelectionRef.current = sel; }} onClick={handleAddComment}> Add Comment</button>
Unlike Tiptap, Quill does not have a built-in bubble menu. You will need to create your own comment button or toolbar item.
Step 5: Call addComment to add a comment
Call this method to add a comment to selected text in the Quill editor. You can use this when the user clicks on the comment button or presses a keyboard shortcut.
By default, Velt comment marks (<velt-comment-text>) are persisted by the Velt SDK. When the editor loads and the Velt SDK initializes, the marks will be automatically added to the editor.
If you plan to store the contents of the Quill editor on your end with the comment marks already included, you can disable this feature.