Skip to main content

Setup

Step 1: Add Comment components

  • Add the Velt Comments component to the root of your app.
  • This component is required to render comments in your app.
  • Set the text mode prop to false to hide the default text comment tool.

Step 2: Install the Velt ProseMirror extension

For the examples below, also install the standard ProseMirror example packages:

Step 3: Configure the ProseMirror editor with the Velt Comments plugin

Add VeltCommentsPlugin to the plugins array when creating your EditorState.

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: Use onMouseDown with preventDefault() so the browser does not move focus away from the editor before addComment reads the current selection.

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: ProseMirror EditorView.
    • 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)

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: ProseMirror EditorView.
    • editorId: Id of the editor. Use this if you have multiple ProseMirror editors on the same page. (optional)
    • commentAnnotations: Array of Comment Annotation objects.

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 EditorView or replace document content, call renderComments again.

Step 8: Style the commented text

  • You can style the commented text by adding CSS for the velt-comment-text element.
  • Use the comment-available attribute 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’s plugins array.

addComment()

Creates a comment annotation for the currently selected text in the editor.

renderComments()

Renders and highlights comment annotations in the ProseMirror editor.

veltCommentsPluginKey

The ProseMirror PluginKey used by the package. Use it only for advanced inspection of plugin state.
  • Params: none
  • Returns: PluginKey