Editor Comments

Pro

Comment threads anchored to passages of a rich text editor — the anchor travels with the document, replies and resolutions are outputs, and a thread whose text was deleted says so.

</>sv-rte-comments editorcommentsreviewcollaboration
import { SvRteCommentsComponent } from '@styloviz-pro/rich-editor';

Demo & usage

Basic usage

Pro

Usage example — open the gallery for the full interactive demo.

Pro

An interactive demo for this component lives in the gallery.

Open live demo

More examples

Wired to a backend

Pro

`threads` is a two-way model you load; the outputs are what to persist. Loading, error with retry, and empty are built in.

When to use

  • Review workflows — contracts, specs, copy — where a remark belongs to a specific passage.
  • Pair it with `svRteSuggest` when reviewers also propose wording.

Async states

  • loading
  • error
  • retry

Inputs

NameTypeDefaultDescription
editorrequiredSvRichTextEditorComponent—The editor the threads are anchored in.
threadsreadonly SvRteCommentThread[] (two-way)[]The threads. Two-way: new threads, replies and resolutions are written back.
authorrequiredSvRteAuthor—Who is commenting.
activeThreadstring | null (two-way)nullThe thread in focus — its passage is highlighted. Two-way.
loadingbooleanfalseThreads are being fetched.
errorSvDataError | string | nullnullFetching the threads failed.
clock() => Date() => new Date()The clock comments are stamped with — a seam for tests.

Outputs

EventPayload typeDescription
threadCreateSvRteCommentThreadA new thread was opened.
replyAddSvRteCommentReplyA reply was posted.
threadResolveSvRteCommentThreadA thread was resolved.
retryvoidFetch the threads again after an `error`.
threadsChangereadonly SvRteCommentThread[]Emits the new `threads` whenever it changes — the output half of `[(threads)]`.
activeThreadChangestring | nullEmits the new `activeThread` whenever it changes — the output half of `[(activeThread)]`.

Wire it to your API

This component is headless about transport: it renders what you give it and reports what the user asks for. Nothing below requires @styloviz/data — drive it from whatever you already use.

Template

Pro

Bound to the names this component actually exposes.

Host class

Pro

Drive the three async inputs from your own fetch.

  • This component does not emit a query, so it renders what you give it. Call `load()` on your own trigger and bind `threads`, `loading` and `error`.
  • Normalize failures with `toSvDataError()` from `@styloviz/core`. It derives `retryable` from the status, so a 404 does not get a "Try again" button that can only fail again.

Full walkthrough: Connecting to a backend.

Customization & theming

  • `[(activeThread)]` follows the thread in focus (clicking a passage selects its thread); `clock` stamps comments (a seam for tests).

Forms integration

  • sv-rte-comments — Output-driven, not a ControlValueAccessor. Its state is a list of threads, not a form value: `threads` is a two-way model, and each change a backend must persist is its own output (`threadCreate`, `replyAdd`, `threadResolve`).

Best practices

  • Do: Persist the document AND the threads: the anchor (`<mark data-sv-comment>`) is in the document, the discussion is in `threads`.
  • Do: Keep detached threads — the discussion is still worth having after the sentence went.
  • Don't: Don't rebuild anchors from character offsets on the server; the mark moves with edits and offsets do not.

Accessibility

  • A labelled section; each thread is an `<article>` named by its quoted passage, with comments in an ordered list.
  • The comment button keeps the editor selection (it does not take focus on mousedown), and every field has a label.

Feedback on Editor Comments

Spotted a gap in this page, or something that didn't work as described? Comments are GitHub Discussions in the public styloviz/community repo, so posting needs a GitHub account.

Loads giscus.app and GitHub — nothing is fetched until you click.