Document Editor
A Docs-style workspace with a menu bar, a full toolbar, a heading outline, anchored comment threads, version history and autosave.
A Docs-style workspace: a title bar with star, location and save status, a File / Edit / View / Insert / Format / Tools / Help menu bar with a searchable command list, a full toolbar (zoom, text style, font, font size, paint format, colors, comments, alignment and formatting marks), a collapsible heading outline, and a comments panel. Insert adds images, tables, checklists, syntax-highlighted code blocks and callouts, and pastes from Google Docs, Word or Notion come in clean. Comments anchor to the selected text and support replies, reactions and resolving. Edits autosave through onSave, and every save adds an entry to version history.
Installation
$ pnpm dlx shadcn@latest add @editorcn-pro/document-editor
The CLI also installs the Image Placeholder and Table extensions.
Usage
import { DocumentEditor } from "@/components/templates/document-editor";
export const Doc = ({ doc, user }) => (
<DocumentEditor
currentUser={user}
initialTitle={doc.title}
initialContent={doc.content}
initialComments={doc.comments}
onSave={({ title, content }) => saveDocument(doc.id, { title, content })}
onCommentsChange={(comments) => saveComments(doc.id, comments)}
onShare={() => openShareDialog(doc.id)}
/>
);onSave runs 800ms after the last edit. Return a promise to keep the status on "Saving…" until it resolves; a rejected promise shows "Couldn't save". Comment anchors are stored in the document as <span data-comment-id="…">, so save the content and the comments together.
Each thread's highlight color can be changed from its ⋯ menu. The choice is stored on the comment as color, so it comes back through onCommentsChange. Threads without a color use commentColor, which accepts any CSS color.
Props
| Prop | Type | Description |
|---|---|---|
initialContent | Content | Tiptap JSON or HTML to start with |
initialTitle | string | Document title, default Untitled Document |
initialComments | DocumentComment[] | Comment threads, matched to anchors by id |
currentUser | DocumentUser | Author of new comments and replies |
onSave | function | Gets { title, content } after edits settle |
onCommentsChange | function | Gets every comment after a change |
onShare | function | Shows a Share button when set |
onCall | function | Shows a call button when set |
initialStarred | boolean | Starts the document starred |
onStarChange | function | Gets the new starred state |
location | string[] | Folder path shown from the folder button |
savedLabel | string | Status text after a save, default Saved |
commentColor | string | Default highlight color, default amber |
className | string | Outer container classes |