Comments
Installation
npm install @udecode/plate-comments
Usage
import { CommentsPlugin } from '@udecode/plate-comments/react';
const editor = createPlateEditor({
plugins: [
// ...otherPlugins,
CommentsPlugin,
],
});
Keyboard Shortcuts
Key | Description |
---|---|
Cmd + Shift + M | Add a comment on the selected text. |
Plugins
CommentsPlugin
Transforms
editor.tf.insert.comment
Insert a new comment mark.
editor.api.comment.updateComment
Updates an existing comment.
editor.api.comment.addRawComment
Adds a new raw comment.
editor.api.comment.addComment
Adds a new comment.
editor.api.comment.removeComment
Removes a comment.
editor.api.comment.resetNewCommentValue
Resets the value of a new comment.
Store State
CommentStoreState
Utils
findCommentNode
Finds the comment node in the editor.
findCommentNodeById
Finds the comment node in the editor by its ID.
getCommentCount
Gets the count of comments in a comment node.
getCommentKey
Generates a comment key based on the provided ID.
getCommentKeyId
Extracts the comment ID from a comment key.
getCommentKeys
Returns an array of comment keys present in the given node.
getCommentNodeEntries
Returns an array of node entries for comment nodes in the editor.
getCommentNodesById
Returns an array of node entries for comment nodes with a specific ID in the editor.
getCommentPosition
Calculates the position of a comment node relative to the editor.
getCommentUrl
Generates a URL with a query parameter for a specific comment ID.
getElementAbsolutePosition
Calculates the absolute position of an HTML element relative to the document.
isCommentKey
Checks if a given key is a comment key.
isCommentNodeById
Checks if a given node is a comment with the specified ID.
isCommentText
Checks if a given node is a comment text node.
removeCommentMark
Removes the comment mark from the editor.
unsetCommentNodesById
Unsets comment nodes with the specified ID from the editor.
Components
CommentUser
An interface representing a user who can make comments.
TComment
Interface for comment data.
TCommentText
Interface for text nodes that can contain comments.
<CommentProvider>
A jotai provider for comment data.
<CommentDeleteButton>
A button component for deleting a comment.
<CommentEditButton>
A button component for editing a comment.
<CommentEditCancelButton>
Button component for canceling comment edits.
<CommentEditSaveButton>
<CommentEditTextarea>
A textarea component for editing a comment.
<CommentNewSubmitButton>
A button component for submitting a new comment.
<CommentNewTextarea>
A textarea component for adding a new comment.
<CommentResolveButton>
Button component for resolving/unresolving comments.
<CommentUserName>
Component for displaying a comment user's name.
<CommentsPositioner>
Hooks
useActiveCommentNode
A custom hook that retrieves the active comment node based on the active comment ID.
useCommentAddButton
A custom hook that provides functionality for adding a comment mark to the selected text and setting focus to the comment textarea.
useCommentItemContentState
A state hook for the comment item content component.
useCommentLeaf
A behavior hook for the comment leaf component.
useCommentValue
A custom hook that focuses and selects the text inside a textarea.
useCommentsResolved
A custom hook that returns an array of resolved comments.
useCommentsShowResolvedButton
A custom hook that returns the props for a button component used to show resolved comments.