评论编辑器事件
创建、修改、选中或悬停评论线程和评论时,Comments 扩展会触发相应事件。使用 editor.on() 监听这些事件,以构建自定义界面或同步自己的状态。
线程事件
comments:threadCreated
创建新的评论线程时触发。
editor.on('comments:threadCreated', ({ threadId, thread, initialComment, position, threadType }) => {
// threadType: 'block' | 'inline'
console.log(`Thread ${threadId} created at ${position.from}-${position.to}`)
})comments:threadUpdated
线程数据或元数据发生变化时触发。
editor.on('comments:threadUpdated', ({ threadId, thread, changes, updatedBy }) => {
console.log(`Thread ${threadId} updated by ${updatedBy}`)
})comments:threadResolved
解决线程时触发。
editor.on('comments:threadResolved', ({ threadId, thread, resolvedBy, resolvedAt }) => {
console.log(`Thread ${threadId} resolved by ${resolvedBy} at ${resolvedAt}`)
})comments:threadUnresolved
重新打开已解决的线程时触发。
editor.on('comments:threadUnresolved', ({ threadId, thread, unresolvedBy }) => {
console.log(`Thread ${threadId} reopened by ${unresolvedBy}`)
})comments:threadDeleted
删除线程时触发。
editor.on('comments:threadDeleted', ({ threadId, thread, deletedBy, soft }) => {
// soft: whether this is a soft delete (archived) or hard delete
console.log(`Thread ${threadId} deleted by ${deletedBy}`)
})comments:threadRemovedFromDocument
从文档中移除线程标记时触发,例如删除了批注文本或归档了线程。
editor.on('comments:threadRemovedFromDocument', ({ threadId, thread, removedBy, canRestore }) => {
// removedBy: 'edit' | 'command'
console.log(`Thread ${threadId} removed from document`)
})评论事件
comments:commentCreated
向线程添加新评论时触发。
editor.on('comments:commentCreated', ({ threadId, commentId, comment, thread }) => {
console.log(`Comment ${commentId} added to thread ${threadId}`)
})comments:commentUpdated
编辑评论内容时触发。
editor.on('comments:commentUpdated', ({ threadId, commentId, comment, oldContent, newContent }) => {
console.log(`Comment ${commentId} updated`)
})comments:commentDeleted
从线程中删除评论时触发。
editor.on('comments:commentDeleted', ({ threadId, commentId, comment, deletedBy }) => {
console.log(`Comment ${commentId} deleted by ${deletedBy}`)
})选中和悬停事件
comments:threadSelected
选中线程时触发,例如用户点击评论批注。
editor.on('comments:threadSelected', ({ threadId, thread }) => {
// Show thread details in your sidebar
console.log(`Thread ${threadId} selected`)
})comments:threadUnselected
取消选中线程时触发。
editor.on('comments:threadUnselected', ({ threadId }) => {
console.log('Thread deselected')
})comments:threadHovered
用户将指针悬停在文档中的线程批注上时触发。
editor.on('comments:threadHovered', ({ threadIds, threads }) => {
console.log(`Hovering over threads: ${threadIds.join(', ')}`)
})comments:threadUnhovered
用户将指针移出线程批注时触发。
editor.on('comments:threadUnhovered', ({ threadIds }) => {
console.log('Threads unhovered')
})Related
你也可以利用这些事件与 Tracked Changes 等扩展集成。