Birch UI v0.1
Pricing

CommentsDocument

Anchor comment threads to text, reply, resolve and delete them, and keep them through DOCX import and export in Birch UI Document Editor.

Open .md

A comment is anchored to a range of text and starts a thread that others can reply to and resolve. Threads appear in a margin lane beside the pages, each card level with the text it belongs to and joined to it by a connector line. Cards that would overlap are stacked; the selected thread stays beside its text and its neighbours move out of the way. Clicking a card selects its text, and moving the cursor into commented text selects its card, which then shows the reply box and the Resolve and Delete buttons.

When the editor is narrower than 760 px the lane collapses to a strip of icons, one per thread, and the selected thread opens over the page. Tracked changes share the lane as balloons (see Track changes). Pass commentsLayout: 'panel' for the earlier behaviour, a plain list in document order that does not follow the text.

Select text and press Ctrl+Alt+M, or use the comment button, to open a draft in the panel. Ctrl+Enter posts it and Escape cancels.

Comments API#

TypeScript
editor.setSelection(212, 236);
const id = editor.addComment('Should this exclude gross negligence?'); // null when nothing is selected

if (id) {
  editor.replyToComment(id, 'Yes, and wilful misconduct.', { author: 'Daniel Brandt' });
  editor.editComment(id, 'Should this exclude gross negligence and fraud?');
  editor.resolveComment(id); // resolveComment(id, false) reopens
  editor.selectComment(id);
  editor.deleteComment(id);
}

editor.on('commentsChange', ({ comments }) => saveThreads(comments));

editReply(threadId, replyId, text) and deleteReply(threadId, replyId) change a single reply. In the panel people can edit their own comments and edit or delete their own replies. Resolved threads collapse to one line and Show resolved hides them.

addComment returns null when the selection is empty or the editor is read-only. Pass { author, date } to record comments made elsewhere, for example when importing from your own review system.

getComments() returns the threads in document order:

TypeScript
interface CommentThread {
  id: string;
  author: string;
  date: string; // ISO 8601
  text: string;
  resolved: boolean;
  replies: { id: string; author: string; date: string; text: string }[];
}

Threads are part of DocumentData.comments, and the anchors are comment marks in the content that carry the thread id. A comment can span several paragraphs and comments can overlap. If its text is deleted, the thread disappears from the panel and from getJSON(); undoing the deletion brings it back.

Keyboard#

Ctrl+Alt+M starts a comment on the selection, F6 moves from the document to the comments, the arrow keys move between threads, Tab reaches the actions and the reply box of a thread, and Escape goes back to the commented text.

Mentions#

TypeScript
createDocumentEditor(host, {
  mentions: {
    search: (query) => directory.search(query), // Person[] or a promise: { id, name, email? }
    onMention: ({ person, threadId, text }) => notify(person.id, threadId, text),
  },
});

Typing @ in a comment or a reply opens a list of people; the arrow keys choose, Enter or Tab inserts the name and Escape closes the list. The name appears in the comment text as @Name, and the comment or reply also records who was mentioned and where: mentions: [{ start, length, name, email? }]. onMention runs once for each person when the comment is posted.

TypeScript
editor.addComment('@Daniel Brandt is thirty days right?', {
  mentions: [{ start: 0, length: 14, name: 'Daniel Brandt', email: '[email protected]' }],
});
editor.getComments()[0].mentions; // the same list; replies carry their own

In a DOCX file a mention is written as a run in the Mention style, inside a mailto: link when the person has an e-mail address, and it is read back into mentions on import. The people a Word document knows about (word/people.xml) are kept in DocumentData.people and written back.

DOCX#

Comments export to comments.xml with commentRangeStart, commentRangeEnd and commentReference markers in the document, and replies and the resolved state go into commentsExtended.xml, the part Word 2013 and later use for threads. Word and LibreOffice show them as threaded comments, and importing a Word file restores threads, replies, authors, dates and resolved state.

Hide the panel with commentsPanel: false if you build your own comment UI on top of the API. Comment highlighting is hidden when markup is hidden.

↑ ↓ to move, Enter to open, Esc to close