Skip to content
agent-cms

Components / cms-block-editor

Block editor

A Notion-style block editor for the document body, written for agent-cms (no editor library). The body stays markdown: opening a document never changes it, untouched blocks keep their exact text, and what has no block of its own (HTML, columns, tables, toggles) is drawn as it will look and edited as markdown in place. Slash menu, markdown shortcuts, a toolbar over selected text, links, drag handles, block selection, copy and paste as markdown, image paste and drop into the media library, its own undo, IME input. Pass it as `slots.blockEditor`.

With the shadcn CLI

npx shadcn add https://agent-cms-docs.vercel.app/r/cms-block-editor.json

With the agent-cms CLI

npx @mainsoft/agent-cms add cms-block-editor

No live demo on this page: it needs a document to edit. The docs admin (/admin) uses it for every page, and the example app (examples/next) shows it too. Open the editor demo

npx @mainsoft/agent-cms add cms-block-editor

Pass it to the provider, loaded lazily (it is the largest screen part):

tsx
const CmsBlockEditor = lazy(() => import("@/components/cms/cms-block-editor"));
<CmsProvider baseUrl="/api/cms" slots={{ blockEditor: CmsBlockEditor }}>
  • Written for agent-cms, with no editor library and no extra dependency. Each block is its own small editable element; every change goes through plain functions that are tested on their own.
  • The body is still stored as markdown, so agents, the CLI, version history and search are unchanged. Opening a document never changes it, and a block you did not touch keeps its exact text (and the blank lines around it).
  • What has no block of its own (HTML, columns, tables, toggles, images with a caption) is drawn as it will look; double-click or press Enter to edit its markdown in place.
  • One column, as wide as the page it becomes. The preview opens in a window of its own (put it on a second screen); it follows every keystroke without saving. The Markdown view can still show the preview beside the text.
Do thisHow
Blocks menu/, or + beside a line
Heading, list, to-do, quote, calloutType ## , - , 1. , [] , > , > [!tip] at the start of a line
Bold, italic, strike, codeSelect text and use the toolbar, Ctrl/⌘ B, I, Shift S, E, or type **text**, *text*, ~~text~~, `text`
LinkCtrl/⌘ K, or paste a URL over selected text
Code block, dividerThree backticks then Enter; ---
Select blocksEsc, then Shift ↑/↓; or drag across them; Ctrl/⌘ A twice
Move blocksDrag the handle, or Ctrl/⌘ Shift ↑/↓
Duplicate, delete, copy as markdownThe handle's menu, Ctrl/⌘ D, Delete, Ctrl/⌘ C
ImagesPaste or drop them (they go to the media library), or /image
Undo, redoCtrl/⌘ Z, Ctrl/⌘ Shift Z
Full screenThe Full screen button in the body bar, or Ctrl/⌘ Shift F; Esc leaves. The fields fold under the top bar (Fields opens them), and the bar fades while you type
  • The editor header has a Blocks / Markdown switch; the choice is remembered in the browser. The status line shows words and reading time.