Suggestions
Suggest insertions and deletions, then accept or reject them.
Suggestion mode records edits instead of applying them. A reader accepts or rejects each one. Suggestions are marks and block attributes in the document, so they sync with collaboration and undo with the edit that created them.
Install
npx shadcn@latest add https://blockcn.com/r/suggestions.jsonThe comments add-on is optional. When both are installed, suggestion cards render inside the comments sidebar.
Wire it in
getCurrentUser returns { id, name, color? }. Without a user, suggesting mode applies edits directly. chrome: false keeps the toggle out of Editor.Chrome, which hides while the editor is read-only.
"use client";
import { Editor } from "@/components/editor/Editor";
import { useEditor } from "@/components/editor/useEditor";
import { createBlockcnEditor } from "@/components/editor/preset";
import { suggestions } from "@/components/editor/suggestions/suggestionsAddon";
import { SuggestionCards } from "@/components/editor/suggestions/SuggestionCards";
import { SuggestionModeToggle } from "@/components/editor/suggestions/SuggestionModeToggle";
const kit = createBlockcnEditor({
addons: [suggestions({ getCurrentUser: () => ({ id: "ada", name: "Ada" }), chrome: false })],
});
export function Page() {
const editor = useEditor({ extensions: kit.extensions, content: "<p>Hello</p>" });
return (
<Editor editor={editor}>
<SuggestionModeToggle />
<Editor.Frame>
<Editor.Content />
<Editor.Chrome />
</Editor.Frame>
{/* Skip this when CommentsSidebar is mounted. It shows the cards itself. */}
<SuggestionCards />
</Editor>
);
}Modes
The toggle has three modes.
- Editing. Typing changes the document. Suggestions that are already there stay visible.
- Suggesting. Text you insert is marked as an insertion. Text you delete stays in the document, struck through, until someone accepts it. Replacing a selection is one suggestion.
- Viewing. The document does not change. Accept and reject still work.
What is tracked
In suggesting mode:
- Inserting, deleting, and replacing text inside a text block, including a code block and paste that stays in that block. Replace all is tracked match by match.
- Deleting across blocks, or pasting several paragraphs into one. Reject puts the blocks back as they were, including a picture or rule inside the deletion; Accept joins them, as the edit did.
- Inserting or deleting a top-level block.
- Turn into, including a heading level change. Reject restores the previous block type.
These apply immediately, even in suggesting mode:
- Bold, italic, color, highlight, and links.
- Enter, which splits a block, and Backspace at the start of a block, which joins it with the previous one.
- Table rows, columns, and merged cells.
- Dragging a block.
- An empty paragraph added so the document does not end on a heading.
Deleting text you yourself just suggested removes that suggestion instead of striking it through. One undo removes the suggestion and the edit together.
Code blocks take no formatting marks. They accept marks in the codeAnnotation group (CODE_ANNOTATION_GROUP), which the suggestion marks join, so a custom annotation mark can sit on code text the same way.
Accept and reject
Each card has Accept and Reject. Accept all and Reject all show when there is more than one. Accepting an insertion keeps the text and drops the mark. Accepting a deletion removes the text. Reject does the opposite. A replacement is one id, so one decision covers both halves.
Authors get a colour from color, or from a fixed palette. Insertions are underlined and deletions are struck through, so the state is not colour alone.
Export
Suggested text stays in the document until it is accepted or rejected. HTML export keeps insertions as <ins> and deletions as <del>, with the author in the title. Markdown writes them as inline <ins> and <del> too. Accept the suggestions you want to keep before you export a clean copy.