Editor Comments
ProComment 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.
import { SvRteCommentsComponent } from '@styloviz-pro/rich-editor';Demo & usage
Basic usage
Usage example — open the gallery for the full interactive demo.
An interactive demo for this component lives in the gallery.
Open live demoMore examples
Wired to a backend
`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
| Name | Type | Default | Description |
|---|---|---|---|
| editorrequired | SvRichTextEditorComponent | — | The editor the threads are anchored in. |
| threads | readonly SvRteCommentThread[] (two-way) | [] | The threads. Two-way: new threads, replies and resolutions are written back. |
| authorrequired | SvRteAuthor | — | Who is commenting. |
| activeThread | string | null (two-way) | null | The thread in focus — its passage is highlighted. Two-way. |
| loading | boolean | false | Threads are being fetched. |
| error | SvDataError | string | null | null | Fetching the threads failed. |
| clock | () => Date | () => new Date() | The clock comments are stamped with — a seam for tests. |
Outputs
| Event | Payload type | Description |
|---|---|---|
| threadCreate | SvRteCommentThread | A new thread was opened. |
| replyAdd | SvRteCommentReply | A reply was posted. |
| threadResolve | SvRteCommentThread | A thread was resolved. |
| retry | void | Fetch the threads again after an `error`. |
| threadsChange | readonly SvRteCommentThread[] | Emits the new `threads` whenever it changes — the output half of `[(threads)]`. |
| activeThreadChange | string | null | Emits 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
Bound to the names this component actually exposes.
Host class
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.