@viveeditor/ext-comments
v1.1.0
Published
Comments for viveEditor: anchored comment marks and a validated thread store kept beside the document.
Maintainers
Readme
@viveeditor/ext-comments
Comments for viveEditor: anchored comment marks and a validated thread store kept beside the document.
Part of viveEditor, a free, open-source rich text editor.
Install
npm install @viveeditor/ext-comments @viveeditor/coreUsage
import { Editor } from '@viveeditor/core'
import '@viveeditor/core/style.css'
import { Comments } from '@viveeditor/ext-comments'
import { createCommentId, createThreadStore } from '@viveeditor/ext-comments/threads'
import '@viveeditor/ext-comments/style.css'
const editor = await Editor.create(document.querySelector('#editor'), {
extensions: [Comments],
})
const threads = createThreadStore(savedThreads)
const id = createCommentId()
if (editor.commands.addComment(id)) {
threads.apply({
type: 'create',
thread: {
id,
resolved: false,
comments: [
{
id: createCommentId(),
author: { id: 'u1', name: 'Ada' },
body: 'Please check this number.',
created: new Date().toISOString(),
},
],
},
})
}The document only stores where a comment is anchored (<span data-vive-comment="id">). Threads live outside the document: save threads.toJSON() next to the content and pass it back to createThreadStore or threads.load(), which drop anything that does not pass validation. Comment bodies are plain text. Pasted content loses its comment anchors; text moved by drag and drop keeps them. Code blocks cannot hold comments.
Published HTML keeps the anchors only when the sanitizer runs with comments: 'keep'; the default removes them.
License
MIT
