
Setup
Step 1: Add Comment components
- Add the
Velt Commentscomponent to the root of your app. - This component is required to render comments in your app.
- Set the
text modeprop tofalseto hide the default text comment tool.
- React / Next.js
- Other Frameworks
Step 2: Install the Velt ProseMirror extension
Step 3: Configure the ProseMirror editor with the Velt Comments plugin
AddVeltCommentsPlugin to the plugins array when creating your EditorState.
- React / Next.js
- Other Frameworks
Step 4: Add a comment button to your ProseMirror editor
Add a button that users can click to add comments after selecting text in the ProseMirror editor. Important: UseonMouseDown with preventDefault() so the browser does not move focus away from the editor before addComment reads the current selection.
- React / Next.js
- Other Frameworks
Step 5: Call addComment to add a comment
- Call this method to add a comment to selected text in the ProseMirror editor.
- Params:
AddCommentRequest. It has the following properties:editor: ProseMirrorEditorView.editorId: Id of the editor. Use this if you have multiple ProseMirror editors on the same page. (optional)context: Add custom metadata to the Comment Annotation. Learn more. (optional)
- React / Next.js
- Other Frameworks
Step 6: Render comments in ProseMirror editor
- Get the comment data from Velt SDK and render it in the ProseMirror editor.
- Params:
RenderCommentsRequest. It has the following properties:editor: ProseMirrorEditorView.editorId: Id of the editor. Use this if you have multiple ProseMirror editors on the same page. (optional)commentAnnotations: Array of Comment Annotation objects.
- React / Next.js
- Other Frameworks
Step 7: Re-apply ProseMirror comment highlights (optional)
- ProseMirror renders comment highlights as view-only overlay elements.
- The integration does not write Velt comment marks into your ProseMirror schema or saved document.
- Save your ProseMirror document normally. After you recreate the
EditorViewor replace document content, callrenderCommentsagain.
Step 8: Style the commented text
- You can style the commented text by adding CSS for the
velt-comment-textelement. - Use the
comment-availableattribute to apply styles only after comment data has loaded.
Complete Example
APIs
VeltCommentsPlugin()
Creates the ProseMirror plugin that powers Velt comments. Add it to your editor state’splugins array.
- Params:
config?:VeltCommentsPluginConfig - Returns: ProseMirror
Plugin
- React / Next.js
- Other Frameworks
addComment()
Creates a comment annotation for the currently selected text in the editor.- Signature:
async (request:AddCommentRequest) => Promise<void> - Params:
request:AddCommentRequest - Returns:
Promise<void>
- React / Next.js
- Other Frameworks
renderComments()
Renders and highlights comment annotations in the ProseMirror editor.- Signature:
(request:RenderCommentsRequest) => void - Params:
request:RenderCommentsRequest - Returns:
void
- React / Next.js
- Other Frameworks
veltCommentsPluginKey
The ProseMirrorPluginKey used by the package. Use it only for advanced inspection of plugin state.
- Params: none
- Returns:
PluginKey

