Skip to content

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

ParameterType
getEditor() => Editor | null | undefined
optionsVizelCommentOptions
onStateChange(state) => void

Returns

addComment

ts
addComment: (text, author?) => Promise<VizelComment | null>;

Add a comment to the current selection

Parameters

ParameterType
textstring
author?string

Returns

Promise&lt;VizelComment | null&gt;

getCommentById

ts
getCommentById: (commentId) => VizelComment | undefined;

Get a comment by its ID

Parameters

ParameterType
commentIdstring

Returns

VizelComment | undefined

loadComments

ts
loadComments: () => Promise<VizelComment[]>;

Load all comments from storage

Returns

Promise&lt;VizelComment[]&gt;

removeComment

ts
removeComment: (commentId) => Promise<void>;

Remove a comment and its mark

Parameters

ParameterType
commentIdstring

Returns

Promise&lt;void&gt;

reopenComment

ts
reopenComment: (commentId) => Promise<boolean>;

Reopen a resolved comment

Parameters

ParameterType
commentIdstring

Returns

Promise&lt;boolean&gt;

replyToComment

ts
replyToComment: (commentId, text, author?) => Promise<VizelCommentReply | null>;

Add a reply to a comment

Parameters

ParameterType
commentIdstring
textstring
author?string

Returns

Promise&lt;VizelCommentReply | null&gt;

resolveComment

ts
resolveComment: (commentId) => Promise<boolean>;

Mark a comment as resolved

Parameters

ParameterType
commentIdstring

Returns

Promise&lt;boolean&gt;

setActiveComment

ts
setActiveComment: (commentId) => void;

Set the active comment

Parameters

ParameterType
commentIdstring | 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");

Released under the MIT License.