Vizel API / core/src / createVizelCommentHandlers
Function: createVizelCommentHandlers()
ts
function createVizelCommentHandlers(
getEditor,
options,
onStateChange): object;Defined in: packages/core/src/comment.ts:160
Creates comment handlers for an editor.
Parameters
| Parameter | Type |
|---|---|
getEditor | () => Editor | null | undefined |
options | VizelCommentOptions |
onStateChange | (state) => void |
Returns
addComment
ts
addComment: (text, author?) => Promise<VizelComment | null>;Add a comment to the current selection
Parameters
| Parameter | Type |
|---|---|
text | string |
author? | string |
Returns
Promise<VizelComment | null>
getCommentById
ts
getCommentById: (commentId) => VizelComment | undefined;Get a comment by its ID
Parameters
| Parameter | Type |
|---|---|
commentId | string |
Returns
VizelComment | undefined
loadComments
ts
loadComments: () => Promise<VizelComment[]>;Load all comments from storage
Returns
Promise<VizelComment[]>
removeComment
ts
removeComment: (commentId) => Promise<void>;Remove a comment and its mark
Parameters
| Parameter | Type |
|---|---|
commentId | string |
Returns
Promise<void>
reopenComment
ts
reopenComment: (commentId) => Promise<boolean>;Reopen a resolved comment
Parameters
| Parameter | Type |
|---|---|
commentId | string |
Returns
Promise<boolean>
replyToComment
ts
replyToComment: (commentId, text, author?) => Promise<VizelCommentReply | null>;Add a reply to a comment
Parameters
| Parameter | Type |
|---|---|
commentId | string |
text | string |
author? | string |
Returns
Promise<VizelCommentReply | null>
resolveComment
ts
resolveComment: (commentId) => Promise<boolean>;Mark a comment as resolved
Parameters
| Parameter | Type |
|---|---|
commentId | string |
Returns
Promise<boolean>
setActiveComment
ts
setActiveComment: (commentId) => void;Set the active comment
Parameters
| Parameter | Type |
|---|---|
commentId | string | null |
Returns
void
Example
typescript
const handlers = createVizelCommentHandlers(
() => editor,
{ key: "my-comments" },
(state) => setState(prev => ({ ...prev, ...state }))
);
// Add a comment to the current selection
await handlers.addComment("Needs clarification", "Alice");
// Resolve a comment
await handlers.resolveComment(commentId);
// Reply to a comment
await handlers.replyToComment(commentId, "Fixed in latest commit", "Bob");