
Setup
Step 1: Add Comment components
- Add the
Velt Commentscomponent to the root of your app. This component is required to create and render comments in your app. - Authenticate the user with
authProviderand set the Velt document before users add comments. - Set the
textModeprop tofalseto hide the default Velt text comment tool. Monaco selections are handled by@veltdev/monaco-velt-comments. - Add
VeltCommentsSidebarif you want a Google Docs-style comment sidebar.
- React / Next.js
- Other Frameworks
Step 2: Install the Velt Monaco extension
- React / Next.js
- Other Frameworks
monaco-editor is a peer dependency and must be provided by your Monaco app. The package uses the Monaco editor instance your app creates and does not bundle Monaco at runtime.
Step 3: Register the Monaco editor with Velt Comments
Register the integration on the Monaco editor instance returned bymonaco.editor.create or by @monaco-editor/react’s onMount. Keep the returned handle so you can dispose it on teardown.
- React / Next.js
- Other Frameworks
Step 4: Add a comment button to your Monaco editor
Add a button that users can click to add comments after selecting text in the Monaco editor. Important: UseonMouseDown with preventDefault() so the browser does not move focus away from Monaco before addComment reads the current selection. Keep the actual addComment call in onClick.
- 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 Monaco editor.
- Params:
AddCommentRequest. It has the following properties:editor: MonacoIStandaloneCodeEditorinstance.editorId: Id of the editor. Use this if you have multiple Monaco editors on the same page. (optional)context: Add custom metadata to the Comment Annotation. Learn more. (optional)
- React / Next.js
- Other Frameworks
context.textEditorConfig with the selected text, its 1-based occurrence index in the document, and the editor ID when one is provided.
Step 6: Render comments in Monaco editor
- Get the comment data from Velt SDK and render it in the Monaco editor.
- Params:
RenderCommentsRequest. It has the following properties:editor: MonacoIStandaloneCodeEditorinstance.editorId: Id of the editor. Use this if you have multiple Monaco editors on the same page. (optional)commentAnnotations: Array of Comment Annotation objects.
- React / Next.js
- Other Frameworks
Step 7: Re-apply Monaco comment highlights (optional)
- Monaco renders comment highlights as view-only overlay elements.
- The integration does not write Velt comment marks into your Monaco model or saved source code.
- Save your Monaco model value normally. After you call
model.setValue(...),editor.setModel(...), or load saved content, callrenderCommentsagain.
Step 8: Style the commented text
- You can style the commented text by adding CSS for the
velt-comment-textelement. - Monaco highlights are rendered as overlay elements in the outer document, so broad
velt-comment-textstyles are appropriate for this integration.
Multiple Monaco editors
When using multiple Monaco editors on the same page, provide uniqueeditorId values. The library stores editorId in context.textEditorConfig.editorId and filters annotations by that value when rendering.
TypeScript support
The package includes full TypeScript definitions.Complete Example
- React / Next.js
- Other Frameworks
APIs
registerVeltComments()
Registers the Velt comments integration on a Monaco editor instance. The call is idempotent per editor and returns a handle that tears down editor listeners, tracking decorations, overlay elements, renderer state, and local selected-comment subscriber cleanup.- Params:
editor: MonacoIStandaloneCodeEditorinstance.config:MonacoVeltCommentsConfig. (optional)
- Returns:
VeltCommentsHandle
- React / Next.js
- Other Frameworks
addComment()
Creates a Velt comment annotation for the currently selected Monaco text. The selected text and its occurrence index are stored inannotation.context.textEditorConfig; the document content is not modified.
- Params:
AddCommentRequest - Returns:
Promise<void>
- React / Next.js
- Other Frameworks
renderComments()
Resolves Velt comment annotations to Monaco ranges and renders them as stable<velt-comment-text> overlay elements positioned over the commented text.
- Params:
RenderCommentsRequest - Returns:
void
- React / Next.js
- Other Frameworks
isVeltAvailable()
Checks whether the Velt SDK is loaded onwindow.Velt.
- Params: none
- Returns:
boolean
- React / Next.js
- Other Frameworks

