评论编辑器命令

评论编辑器 API 专注于在编辑器内管理评论的客户端交互,允许直接操作和自定义评论线程。

对于服务器端操作,请使用 评论 REST API 来在编辑器外管理线程和评论。

所有评论的编辑器命令

命令描述
setThread创建一个新线程,可选用户和内容数据
removeThread删除指定的线程,选项可以从 Yjs 文档中移除它
updateThread更新特定线程属性,如“已查看”状态
selectThread将编辑器聚焦在指定的线程上
unselectThread取消对选定线程的聚焦
resolveThread将线程标记为已解决
unresolveThread将线程恢复为未解决状态
createComment向线程添加新评论,包含内容和用户数据等详细信息
updateComment修改现有评论的内容和元数据
removeComment从线程中删除指定的评论

与线程交互

setThread( content, data, commentData )

在您当前的选定位置创建一个新线程。

editor.commands.setThread({
  content: '这是一个新线程',
  data: { authorId: '123' },
  commentData: { authorId: '123' },
})

removeThread( id, deleteThread )

删除具有给定 ID 的线程。如果未提供 ID,则将删除当前选定位置的线程。如果将 deleteThread 设置为 true,则该线程也将从 Yjs 文档中删除。

editor.commands.removeThread({
  id: '101',
  deleteThread: true,
})

updateThread( id, data )

更新具有指定 ID 的线程的属性。

editor.commands.updateThread({
  id: '101',
  data: { seen: true },
})

selectThread( options )

选择具有指定 ID 的线程。如果将 selectAround 设置为 true,编辑器将创建一个覆盖整个线程的选定范围。

editor.commands.selectThread({
  id: '101',
})

选项

  • id (string):要选择的线程 ID。
  • selectAround (boolean,默认值:false):如果为 true,则选择线程周围的内容。
  • focus (boolean,默认值:true):如果为 true,选择线程后将聚焦编辑器。
  • scrollIntoView (boolean,默认值:true):如果为 true,滚动编辑器以使所选线程可见。
  • updateSelection (boolean,默认值:true):如果为 true,更新编辑器的选区到所选线程。
  • triggerClick (boolean,默认值:false):如果为 true,模拟一次点击。

unselectThread()

取消当前选定线程的选择。

editor.commands.unselectThread()

resolveThread( id )

将具有指定 ID 的线程标记为已解决。

editor.commands.resolveThread({
  id: '101',
})

unresolveThread( id )

将具有指定 ID 的线程恢复为未解决状态。

editor.commands.unresolveThread({
  id: '101',
})

处理评论

createComment( threadId, content, data )

在具有指定线程 ID 的线程上创建一个新评论。

editor.commands.createComment({
  threadId: '101',
  content: '这是一个新评论',
  data: { authorId: '123' },
})

updateComment( threadId, id, content, data )

更新具有指定 ID 的评论,该评论位于具有给定线程 ID 的线程上。

editor.commands.updateComment({
  threadId: '101',
  id: '456',
  content: '现在这是新内容',
  data: { edited: true },
})

removeComment( threadId, id )

从具有给定线程 ID 的线程中删除具有指定 ID 的评论。

editor.commands.removeComment({
  threadId: '101',
  id: '456',
})