NovelEditor
novel-editorManages chapters and edits Markdown, with the outline and a preview on one screen.
Usage
Basic usage
Manage chapters on the left, write Markdown on the right, and keep the preview open.
17 characters
The river went dark.
tsx
<NovelEditor className="h-[28rem]" defaultChapters={chapters} />When to Use
Write serial fiction: manage chapters on the left (create, rename, delete, drag to reorder), edit Markdown on the right, and keep a preview open. Read the result with NovelReader.
Import
ts
import { NovelEditor } from "@hulianui/ui"Props
Inherits HTMLAttributes<HTMLDivElement> except onChange. The root needs a height, such as h-dvh.
| Name | Type | Default | Description |
|---|---|---|---|
| chapters | NovelChapter[] | — | Controlled chapters, paired with onChaptersChange |
| defaultChapters | NovelChapter[] | [] | Uncontrolled initial chapters |
| onChaptersChange | (chapters: NovelChapter[]) => void | — | Called when chapters or body text change |
| activeChapterId | string | — | Controlled chapter being edited |
| defaultActiveChapterId | string | First chapter | Uncontrolled initial chapter |
| onActiveChapterChange | (id: string) => void | — | Called when the edited chapter changes |
| onSave | (chapters: NovelChapter[]) => void | — | Shows a save button when provided |
| disabled | boolean | false | Disables editing, reordering, and deletion |
| previewClassName | string | — | Classes for the preview pane. Use them for paper color and typeface so the preview reads like the book. The editing column is unchanged |
Above 40 chapters the sidebar switches to a virtual list with move buttons, instead of combining drag-and-drop with virtualization.
Pitfalls
- Without a height on the root, the chapter list and the editor grow the page, and the preview cannot scroll on its own.
- In controlled mode, ignoring
onChaptersChangemakes typing look broken. - Delete removes the chapter immediately after the built-in confirm. Do not add another modal over the manuscript.
- The preview should look like the page being read. Use
previewClassNamefor paper and typeface. Do not paint the whole screen with the editor's chrome and lose the reading surface.