Introducing a new way to review your PRs.

Read the announcement

frappe / frappe-ui

The all-in-one toolkit for modern frontends. High-quality components, app recipes and AI-ready docs.

View on GitHub

28 documents · Updated Nov 23, 2026

docs / rich-text-editor-molecule

Rich text editor molecule

The rich text editor molecule is a composable document-authoring surface for comments, articles, notes, wiki pages, and other interfaces that need structured text. It connects a content value to an extensible editor engine, then lets the host choose the visible content area, menus, media controls, and surrounding actions.

Public integration surface

The public surface is exposed from src/…/index.ts through the frappe-ui/editor entry point. <Editor> owns the editor lifecycle and content binding, while the host places the visible building blocks in its slot or uses useEditor when the editor must live outside the component.

SurfaceRole
EditorRenderless owner for content, edit state, placeholder, uploads, and editor events.
useEditorLower-level engine for a host that must create or own the editor instance.
EditorContentMounts the editing surface.
EditorFixedMenuRenders a persistent menu row.
EditorBubbleMenuRenders controls near a text selection.
EditorFloatingMenuRenders controls near an empty block.
EditorTableMenuRenders controls for the active table.
EditorDropZoneExtends file-drop coverage around the editor surface.

The host supplies a required extensions array. The content value uses one v-model whose shape is selected by format: HTML by default, JSON, or Markdown when the Markdown extension is also loaded. Content changes emit change, and focus, blur, and transaction events provide the main state signals for surrounding UI. editable and placeholder can change at runtime; the extension set defines the editor at creation time.

flowchart LR
  Host[Authoring interface] --> Editor[Editor lifecycle and content]
  Editor --> Content[EditorContent]
  Editor --> Menus[Fixed, bubble, floating menus]
  Editor --> Table[Table menu]
  Editor --> Drop[Drop zone]
  Extensions[Kit and extensions] --> Editor
  Editor --> Value[HTML, JSON, or Markdown value]

References: src/…/index.ts• L6-165 src/…/Editor.vue• L9-118 src/…/useEditor.ts• L22-42

Extension and node-view architecture

Extensions define the document capabilities that an editor instance can parse, display, and edit. Kits group related capabilities for common authoring contexts, while individual extensions let an application add or replace a feature without changing the editor shell.

CommentKit provides a lighter writing set for comments and replies. RichTextKit adds document features such as tables, tasks, embeds, slash commands, color, highlight, and alignment. InlineKit constrains the document to one block for titles and names. A kit member can be configured or removed with Kit.configure, and app-specific extensions can be added beside the kit.

Node views give structured nodes their own interactive presentation inside the document. They support richer blocks such as media, attachments, embeds, image groups, code blocks, and a table of contents. The shared node-view boundary keeps position checks, document lookups, extension attributes, and delayed updates safe when the document or editor view changes.

ConceptPurpose
ExtensionAdds a mark, node, command, or editor behavior.
KitSupplies a named bundle of related extensions.
Node viewPresents an interactive structured node inside the document.
Suggestion extensionConnects a trigger such as @, #, /, or : to a filtered menu and insertion action.

References: src/…/kits.ts• L130-221 src/…/kits.ts• L223-291 src/…/kits.ts• L294-361 src/…/node-view.ts• L17-97

Editing menus and floating controls

Menus separate the commands a surface offers from the way the controls are placed. A MenuItem[] can be reused in a fixed row, a selection-anchored bubble, or an empty-line floating menu, so the host can change layout without rewriting command behavior.

Predefined menu items report whether their capability is loaded and whether the current editor state can run the command. Unsupported items hide, while temporarily unavailable commands disable. This lets one toolbar preset adapt to different kits without presenting controls for features the editor does not have.

The bubble menu follows the current text selection. The floating menu follows an empty block. Both accept a narrow placement contract with side, alignment, movement, scroll, and visibility controls. Their defaults differ: the bubble menu opens above the selection and the floating menu opens to the right of the empty block.

The main menu groups are:

  • Text marks and blocks, including bold, italic, headings, lists, quotes, and alignment.
  • Insert actions for links, media, embeds, tables, and horizontal rules.
  • History actions for undo and redo.
  • Table actions for row, column, cell, and table changes.

References: src/…/menu.ts• L23-110 src/…/menu.ts• L134-298 src/…/menu.ts• L300-451 src/…/EditorFixedMenu.vue• L7-20 src/…/EditorBubbleMenu.vue• L14-51 src/…/EditorFloatingMenu.vue• L14-51

Media and table interactions

Media editing uses one upload contract for images, videos, and attachments. The host provides an upload function that returns a file_url; progress reporting and cancellation are available through the request options. Media can enter through menu actions, paste, or drops on the editing surface. EditorDropZone also accepts files on surrounding chrome and inserts them at the end of the document.

When an upload finishes, the related media node receives the result and becomes part of the document. Image groups, viewers, resizing, video controls, attachments, and iframe dialogs extend this basic path with focused authoring interactions. The upload and node-view boundaries account for delayed work so a completed upload does not write into a destroyed or stale editor view.

Tables provide a separate interaction model from normal text. EditorTableMenu anchors to the visible table rather than the moving text selection, and its controls support rows, columns, headers, merge or split, cell color, and table deletion. The same toolbar can remain mounted in editors without tables because unavailable table commands remove themselves.

Table navigation has two modes. A selected cell is a navigation target with no caret; Enter, typing, or a second click enters cell editing. Arrow keys move between cells in navigation mode, Tab moves across cells, and vertical edge movement leaves the table. Mod+A grows selection from cell content to the full table before normal document selection.

References: src/…/media-upload-types.ts• L43-75 src/…/EditorTableMenu.vue• L25-37 src/…/menu.ts• L300-426 src/…/table-navigation.ts• L1-19 src/…/table-navigation.ts• L187-257

Keyboard behavior

Keyboard behavior keeps common text commands available while giving suggestions, code blocks, and tables focused rules. The editor uses the platform modifier key for formatting and history commands, and suggestion menus take control of navigation keys while they are open.

ContextMain behavior
Text editingModifier shortcuts toggle marks, open the link editor, and control undo or redo.
Suggestion menuArrow keys move through items, Enter selects, and Escape closes the menu.
Code blockTab and Shift+Tab indent or dedent.
Table navigationArrow keys move cells, Tab changes cells, and Enter or Escape changes cell mode.
Image selectionModifier-Shift-G groups selected images.

The table rules avoid trapping keyboard users in the grid. At the top and bottom edges, navigation moves back into the document. In read-only mode, the table navigation layer does not take control of normal selection behavior.

References: src/…/table-navigation.ts• L327-429 src/…/toggle-code-shortcut.ts• L1-14 src/…/slash-commands-extension.ts• L183-216 docs/…/editor.md• L205-223

Styling boundary

EditorContent owns the editor element and supplies the default prose typography. It also accepts host classes for size and layout. A Tailwind Typography size class such as prose-sm or prose-lg replaces the default prose-v3 size choice; a prose font-size token can scale the full content system without changing each block separately.

The editor stylesheet is loaded by frappe-ui/editor, so content styles do not depend on another component stylesheet. It covers editor focus and placeholder states, selected nodes, task lists, links, tables, table selections, drop cursors, and structured node presentation. The host remains responsible for the outer layout, toolbar chrome, spacing around the editor, and application-specific node styling.

The content element shares its class attribute with the editor engine. EditorContent adds and removes only the classes it owns, which preserves engine state classes such as focus and selected-node markers. This is the boundary that allows host styling and editor state styling to work together.

References: src/…/EditorContent.vue• L31-87 src/…/EditorContent.vue• L121-145 src/…/style.css• L1-25 src/…/style.css• L137-218

Change checklist

When these files or sections are changed, remember to consider these:

  • Changes to Editor.vue or useEditor.ts must keep v-model, format, event, editable, and upload behavior aligned.
  • Changes to a kit member must keep its companion nodes, marks, and menus available as one capability set.
  • Changes to menu availability must preserve the difference between hidden unsupported commands and disabled state-dependent commands.
  • Changes to media upload results must keep the required file_url contract and delayed editor writes safe.
  • Changes to table navigation must keep cell selection, table menus, and keyboard escape behavior consistent.
  • Changes to EditorContent classes must preserve both host classes and engine-owned state classes.

Important failure modes

TriggerConsequenceGuard
Markdown format without the Markdown extensionContent cannot round-trip through the requested format.Load Markdown with the editor extensions.
Upload result without file_urlThe media node has no usable source.Return an UploadedMedia object with file_url.
Table menu used without the table capabilityTable actions have no schema support.Menu items check live table availability and hide.
Host class binding replaces the editor class listFocus, selection, and content styles stop working.Let EditorContent preserve engine-owned classes.
Changing extensions after editor creationThe editor keeps its original capabilities.Recreate the editor when its capability set must change.

Key files

FileWhy to read it
src/…/index.tsPublic exports for the editor, kits, extensions, menus, and types.
src/…/Editor.vueComponent-level integration contract and slot model.
src/…/useEditor.tsContent, lifecycle, format, and upload behavior.
src/…/kits.tsCapability bundles for comment, document, and inline authoring.
src/…/menu.tsMenu item contract, command behavior, and toolbar presets.
src/…/EditorTableMenu.vueTable toolbar placement and context-menu behavior.
src/…/table-navigation.tsKeyboard and pointer interaction model for tables.
src/…/EditorContent.vueContent mounting and styling boundary.
src/…/style.cssShared editor and structured-content styles.

Related pages: Component library, Input controls, Overlays and navigation, Editor and list molecules, Code editor molecule, Layout and feedback