Editor
A rich text editor for articles, posts and notes, built on Tiptap: headings, lists and task lists, code blocks and links, with tables, images, search and replace and more as features you add. Its value is a Signal Forms field — HTML, JSON, Markdown or text — and its toolbar is yours, made of the library's parts. For plain text, use a Textarea; for code, the Code Editor.
Installation
It has its own entry point, @semantic-components/ui/editor, built on Tiptap — optional peers of ui: install its core where you use the editor. Each feature adds its own package; see Features.
Then its styles, in your styles.css:
@import "@semantic-components/styles/typeset.css";@import "@semantic-components/styles/nova/typeset-variables.css";@import "@semantic-components/styles/nova/editor.css";Usage
import { Component, ViewEncapsulation, signal } from '@angular/core';import { FormField, form } from '@angular/forms/signals';import { ScFrame, ScToggle, ScToolbar, ScToolbarSeparator, ScToolbarWidget, ScToolbarWidgetGroup,} from '@semantic-components/ui';import { ScEditor, ScEditorCommand, ScEditorContent,} from '@semantic-components/ui/editor';import { SiBoldIcon, SiItalicIcon, SiUnderlineIcon, SiUndoIcon,} from '@semantic-icons/lucide-icons';
@Component({ selector: 'app-editor-usage-demo', imports: [ FormField, ScFrame, ScToggle, ScToolbar, ScToolbarSeparator, ScToolbarWidget, ScToolbarWidgetGroup, ScEditor, ScEditorContent, ScEditorCommand, SiBoldIcon, SiItalicIcon, SiUnderlineIcon, SiUndoIcon, ], template: ` <div scEditor [formField]="editorForm.body" class="flex w-full max-w-lg flex-col gap-2" > <div scToolbar aria-label="Formatting"> <div scToolbarWidgetGroup aria-label="Marks"> <button scToolbarWidget scToggle scEditorCommand="bold"> <svg siBoldIcon></svg> <span class="sr-only">Bold</span> </button> <button scToolbarWidget scToggle scEditorCommand="italic"> <svg siItalicIcon></svg> <span class="sr-only">Italic</span> </button> <button scToolbarWidget scToggle scEditorCommand="underline"> <svg siUnderlineIcon></svg> <span class="sr-only">Underline</span> </button> </div> <div scToolbarSeparator></div> <button scToolbarWidget scToggle scEditorCommand="undo"> <svg siUndoIcon></svg> <span class="sr-only">Undo</span> </button> </div> <div scFrame scEditorContent ariaLabel="Message" placeholder="Start writing..." ></div> </div> `, host: { class: 'flex w-full justify-center' }, encapsulation: ViewEncapsulation.None,})export class EditorUsageDemo { private readonly model = signal({ body: '' }); private readonly editorForm = form(this.model);}Anatomy
The editor holds a toolbar — the library's Toolbar, a command beside each scToggle — and the document. The counts are optional; so are the block menu, the link popover and the features' parts (tables, images, search), each in its own entry point.
import { ScEditor, ScEditorCharCount, ScEditorCommand, ScEditorContent, ScEditorCount, ScEditorWordCount } from '@semantic-components/ui/editor';import { ScToggle, ScToolbar, ScToolbarSeparator, ScToolbarWidget, ScToolbarWidgetGroup } from '@semantic-components/ui';<div scEditor [formField]="form.body"> <!-- The toolbar: the library's Toolbar; a command beside each scToggle --> <div scToolbar aria-label="Formatting"> <div scToolbarWidgetGroup aria-label="Marks"> <button scToolbarWidget scToggle scEditorCommand="bold">…</button> </div> <div scToolbarSeparator></div> <button scToolbarWidget scToggle scEditorCommand="undo">…</button> </div>
<!-- The document --> <div scEditorContent ariaLabel="…" placeholder="…"></div>
<!-- Optional: the counts --> <div scEditorCount> <span scEditorWordCount></span> <span scEditorCharCount></span> </div></div>Features
The core, @semantic-components/ui/editor, writes text, headings, lists and task lists, quotes, code blocks and links, with undo and redo, the counts and scEditorView, in HTML, JSON or text. It needs only what Tiptap's own install asks for: @tiptap/core, @tiptap/pm and @tiptap/starter-kit. Everything else is a feature, in its own entry point with its own package: install it and provide it only when you use it. Give the editor and scEditorView the same features, so they hold the same documents.
import { Component, signal } from '@angular/core';import { FormField, form } from '@angular/forms/signals';import { ScToggle, ScToolbar, ScToolbarWidget, ScToolbarWidgetGroup,} from '@semantic-components/ui';import { ScEditor, ScEditorCommand, ScEditorContent, provideEditor,} from '@semantic-components/ui/editor';import { withMarkdown } from '@semantic-components/ui/editor/markdown';import { withScripts } from '@semantic-components/ui/editor/scripts';import { SiBoldIcon, SiSubscriptIcon, SiSuperscriptIcon,} from '@semantic-icons/lucide-icons';
@Component({ selector: 'app-note-editor', imports: [FormField, ScEditor, ScEditorCommand, ScEditorContent, ScToggle, ScToolbar, ScToolbarWidget, ScToolbarWidgetGroup, SiBoldIcon, SiSubscriptIcon, SiSuperscriptIcon], // The features of the editors in this component. providers: [provideEditor(withScripts(), withMarkdown())], template: ` <div scEditor [formField]="noteForm.body" format="markdown"> <div scToolbar aria-label="Formatting"> <div scToolbarWidgetGroup> <button scToolbarWidget scToggle scEditorCommand="bold"> <svg siBoldIcon></svg> <span class="sr-only">Bold</span> </button> <button scToolbarWidget scToggle scEditorCommand="superscript"> <svg siSuperscriptIcon></svg> <span class="sr-only">Superscript</span> </button> <button scToolbarWidget scToggle scEditorCommand="subscript"> <svg siSubscriptIcon></svg> <span class="sr-only">Subscript</span> </button> </div> </div> <div scEditorContent ariaLabel="Note"></div> </div> `,})export class NoteEditor { readonly noteForm = form(signal({ body: '' }));}| Entry point | Provide | Parts | Package |
|---|---|---|---|
/tables | withTables() | scEditorTable | @tiptap/extension-table |
/images | withImages() | scEditorUploadsscEditorImagedroppaste | @tiptap/extension-image@tiptap/extension-file-handler |
/search | withSearch() | scEditorSearchBar ([(open)])Ctrl / ⌘ + F | @tiptap/extension-find-and-replace |
/highlight | withHighlight() | scEditorHighlightscEditorHighlightColorscEditorRemoveHighlight | @tiptap/extension-highlight |
/scripts | withScripts() | scEditorCommand="superscript" / "subscript" | @tiptap/extension-superscript@tiptap/extension-subscript |
/align | withAlign() | scEditorCommand="align-left" / "align-center" / "align-right" / "align-justify" | @tiptap/extension-text-align |
/markdown | withMarkdown() | format="markdown" | @tiptap/markdown |
/bubble-menu | — | scEditorBubbleMenu | @tiptap/extension-bubble-menu |
The bubble menu has nothing to provide: scEditorBubbleMenu adds itself to the editor.
Keyboard
Tiptap's shortcuts, and Markdown as you type, each at the start of a line and followed by a space: # headings, - lists, [ ] tasks, > quotes, ``` code blocks. Some come with a feature. A browser can take a few before the editor: Ctrl + Shift + R reloads, Ctrl + Shift + J opens the console; with AltGr layouts, Ctrl + Alt is AltGr.
| Keys | Does | Needs |
|---|---|---|
| Ctrl / ⌘ + B | Bold | The core |
| Ctrl / ⌘ + I | Italic | The core |
| Ctrl / ⌘ + U | Underline | The core |
| Ctrl / ⌘ + Shift + S | Strikethrough | The core |
| Ctrl / ⌘ + E | Inline code | The core |
| Ctrl / ⌘ + Alt + 1 … 6 | Heading 1 to 6 | The core |
| Ctrl / ⌘ + Shift + 7 | Numbered list | The core |
| Ctrl / ⌘ + Shift + 8 | Bullet list | The core |
| Ctrl / ⌘ + Shift + 9 | Task list | The core |
| Ctrl / ⌘ + Shift + B | Blockquote | The core |
| Ctrl / ⌘ + Alt + C | Code block | The core |
| Ctrl / ⌘ + Z | Undo | The core |
| Ctrl / ⌘ + Shift + Z, Ctrl / ⌘ + Y | Redo | The core |
| Ctrl / ⌘ + Shift + H | Highlight | withHighlight() |
| Ctrl / ⌘ + . | Superscript | withScripts() |
| Ctrl / ⌘ + , | Subscript | withScripts() |
| Ctrl / ⌘ + Shift + L, E, R, J | Align left, centre, right, justify | withAlign() |
| Ctrl / ⌘ + F | Open the search bar | withSearch() |
| Enter, Shift + Enter | Next, previous match (in the search) | withSearch() |
| Escape | Close the search bar | withSearch() |
| ← / → | Move between the toolbar’s buttons | The core |
| Tab | Leave the toolbar; in a table, the next cell | The core |
Loading
The features are loaded with the editor, not on their own: a feature's package is small next to what every editor needs (@tiptap/core, ProseMirror, @tiptap/starter-kit), and loading it later would make the editor and scEditorView wait before showing a document. To keep the editor out of a page's first load, load the component that holds it lazily — everything, Tiptap's core too, is then split off. A lazy route (loadComponent) does the same for a page with an editor.
@defer (on viewport) { <app-note-editor />} @placeholder { <div class="h-40 rounded-lg border"></div>}Examples
The complete editor, after Tiptap's Simple Editor: undo and redo, the block type and list menus (with task lists), blockquotes and code blocks, marks, highlight colours, links, superscript and subscript, alignment, tables (from the table menu), images (pick, drop or paste one) and search and replace (Ctrl / ⌘ + F). The page layout centres the text in a column of readable width. It uses every feature: provideEditor(withAlign(), withHighlight(), withImages(), withScripts(), withSearch(), withTables()).
An article, with every tool
HTML Output:
<h1>Getting started</h1> <p>Welcome to the editor: a <strong>rich text editor</strong> built on <a href="https://tiptap.dev">Tiptap</a>, with every part written in your own template.</p> <p>Write in <strong>bold</strong>, <em>italic</em>, <u>underline</u>, <s>strike</s> or <code>code</code>, and <mark data-color="var(--sc-editor-highlight-1)" style="background-color: var(--sc-editor-highlight-1)">highlight</mark> what matters. Superscript and subscript: E = mc<sup>2</sup>, H<sub>2</sub>O.</p> <h2>Lists</h2> <ul data-type="taskList"> <li data-type="taskItem" data-checked="true"><p>Pick a block type from the heading menu</p></li> <li data-type="taskItem" data-checked="false"><p>Try a bulleted, numbered or task list</p></li> <li data-type="taskItem" data-checked="false"><p>Drop an image into the document</p></li> </ul> <h2>Code</h2> <pre><code>const editor = inject(SC_EDITOR); editor.run((chain) => chain.toggleBold());</code></pre> <h2>Tables</h2> <table> <tr><th><p>Feature</p></th><th><p>Where</p></th></tr> <tr><td><p>Tables</p></td><td><p>The table menu</p></td></tr> </table> <blockquote><p>Search with Ctrl + F, and replace what you find.</p></blockquote> <p style="text-align: center">Centred, justified, or aligned to either side.</p>
import { Component, ViewEncapsulation, signal } from '@angular/core';import { FormField, form } from '@angular/forms/signals';import { ScButton, ScCollapsible, ScCollapsiblePanel, ScCollapsibleTrigger, ScField, ScFrame, ScInput,Tables
The core and one feature, withTables(): the table menu inserts a table and edits the one at the selection, its actions disabled where they don't apply. Tab moves between cells; dragging a column's border resizes it.
Plans in a table
import { Component, ViewEncapsulation, signal } from '@angular/core';import { FormField, form } from '@angular/forms/signals';import { ScFrame, ScMenu, ScMenuContent, ScMenuItem, ScMenuPortal, ScMenuProvider, ScMenuTrigger,Images
withImages() and an [upload] handler on the editor (scEditorUploads): pick an image, or drop or paste one. Each is uploaded with its progress — cancel it there — and inserted when it resolves, named after its file.
A story with pictures
import { Component, ViewEncapsulation, signal } from '@angular/core';import { FormField, form } from '@angular/forms/signals';import { ScButton, ScFrame, ScProgress, ScProgressRange, ScProgressTrack, ScToggle, ScToolbar,Search and replace
withSearch(): the search button, or Ctrl / ⌘ + F in the document, opens the bar. Enter and Shift + Enter step through the matches, Escape closes it.
Whether the bar is open is yours: one signal, bound to what shows it and to the bar's [(open)]. Here a Collapsible, its trigger in the toolbar. The editor isn't tied to it: where a search shows is a layout choice — a panel that pushes the text down, a box over a corner, a dialog — and editors make it differently. The editor does the search (its keys, focus and matches); a Popover, a Sheet or an @if work as well.
Find and replace in a draft
import { Component, ViewEncapsulation, signal } from '@angular/core';import { FormField, form } from '@angular/forms/signals';import { ScButton, ScCollapsible, ScCollapsiblePanel, ScCollapsibleTrigger, ScFrame, ScInput, ScInputGroup,Floating toolbar
scEditorBubbleMenu shows by the selected text, here instead of a toolbar. It needs no provider: it adds itself to the editor.
A comment with a floating toolbar
import { Component, ViewEncapsulation, signal } from '@angular/core';import { FormField, form } from '@angular/forms/signals';import { ScFrame, ScToggle, ScToolbar, ScToolbarWidget, ScToolbarWidgetGroup,} from '@semantic-components/ui';import {Signal Forms
[formField] on the editor: the value is the document's HTML. required checks it, scFieldErrors shows the message once the document is left, and disabled from the schema follows the checkbox. characterLimit stops the text at 280 characters — its text, not its HTML.
A post with validation
A post of up to 280 characters.
Form state
{
"value": "",
"valid": false,
"touched": false,
"disabled": false
}import { Component, ViewEncapsulation, signal } from '@angular/core';import { FormField, disabled, form, required } from '@angular/forms/signals';import { ScButton, ScCheckbox, ScField, ScFieldDescription, ScFieldErrors, ScFrame, ScLabel,Displaying the document
scEditorView shows what the editor wrote — a published post, a preview — in the editor's styles, without an editor. The HTML is read through the editor's schema, so only what the editor can hold is shown: no scripts, no unsafe links.
Release notes, side by side
import { Component, ViewEncapsulation, signal } from '@angular/core';import { FormField, form } from '@angular/forms/signals';import { ScFrame, ScToggle, ScToolbar, ScToolbarWidget, ScToolbarWidgetGroup,} from '@semantic-components/ui';import {Formats
format picks what the form holds: html (the default), json (Tiptap's JSON, null when empty), markdown or text (plain text, a line per paragraph). Switching it rewrites the value in the new format, and scEditorView shows any of them, given the same format.
A note in three formats
JSON value (empty)
null
import { Component, ViewEncapsulation, computed, signal } from '@angular/core';import { FormField, form, required } from '@angular/forms/signals';import { ScButton, ScFrame, ScToggle, ScToggleGroup, ScToggleGroupItem, ScToolbar, ScToolbarWidget,Layout
layout on scEditorContent: default pads the text edge to edge, for a field or a comment box; page sets it in a centred column of readable width with page margins, for a document. The toolbar follows.
A letter, page or default
import { Component, ViewEncapsulation, signal } from '@angular/core';import { FormField, form } from '@angular/forms/signals';import { ScFrame, ScToggle, ScToggleGroup, ScToggleGroupItem, ScToolbar, ScToolbarWidget, ScToolbarWidgetGroup,Initial content
The form's value is the document to start with: any HTML the editor knows — headings, lists, quotes, marks.
An article to continue
import { Component, ViewEncapsulation, signal } from '@angular/core';import { FormField, form } from '@angular/forms/signals';import { ScFrame, ScToggle, ScToolbar, ScToolbarSeparator, ScToolbarWidget, ScToolbarWidgetGroup,} from '@semantic-components/ui';Read-only
readonly from the schema: the document can be read, selected and searched, not changed, and its buttons are disabled. Here it has no toolbar at all.
An article to read
import { Component, ViewEncapsulation, signal } from '@angular/core';import { FormField, form, readonly } from '@angular/forms/signals';import { ScFrame } from '@semantic-components/ui';import { ScEditor, ScEditorCharCount, ScEditorContent, ScEditorCount, ScEditorWordCount,} from '@semantic-components/ui/editor';Without counts
Every part is optional: leave out the footer and its word and character counts.
Notes without counts
import { Component, ViewEncapsulation, signal } from '@angular/core';import { FormField, form } from '@angular/forms/signals';import { ScFrame, ScToggle, ScToolbar, ScToolbarSeparator, ScToolbarWidget, ScToolbarWidgetGroup,} from '@semantic-components/ui';RTL
In a right-to-left page: the toolbar starts at the right and Left moves to the next button; the text runs from the right, list markers on the right.
RTL
import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation, signal } from '@angular/core';import { FormField, form } from '@angular/forms/signals';import { ScFrame, ScToggle, ScToolbar, ScToolbarSeparator, ScToolbarWidget, ScToolbarWidgetGroup,API reference
Every part takes class, and the buttons take disabled. What a part holds is read through its exportAs, which is its selector's name (#link="scEditorLink"). [formField] sets the editor's value, disabled, readonly, errors and touched state.
@semantic-components/ui/editor
| Part | Selector | Description |
|---|---|---|
ScEditor | [scEditor] | Inputs: format: 'html' | 'json' | 'markdown' | 'text'; characterLimit: number | null. Reads: editable(); isActive(name, attributes?); can(command); editorInstance(); contentVersion(). Does: run(command). |
ScEditorContent | div[scEditorContent] | Inputs: ariaLabel; placeholder; layout: 'default' | 'page'. |
ScEditorView | [scEditorView] | Inputs: [scEditorView]: the document; format; layout: 'default' | 'page'. |
ScEditorBlock | [scEditorBlock] | Inputs: disabled. Reads: value(): 'paragraph' | 'heading-1' … 'heading-6' | 'bullet-list' | 'ordered-list' | 'task-list' | 'quote' | 'code-block'. Does: select(block): out of a list or quote first. |
ScEditorLink | button[scEditorLink] | Reads: href(). Does: set(href, text?); remove(). |
ScEditorWordCount | span[scEditorWordCount] | Reads: wordCount(). |
ScEditorCharCount | span[scEditorCharCount] | Reads: charCount(); limit(); remaining(); limitReached(). |
ScEditorCommand | button[scEditorCommand] | Inputs: scEditorCommand: 'bold' | 'italic' | 'underline' | 'strikethrough' | 'code' | 'bullet-list' | 'ordered-list' | 'task-list' | 'quote' | 'code-block' | 'horizontal-rule' | 'clear-formatting' | 'undo' | 'redo' — and a feature's: 'align-…', 'superscript', 'subscript'; disabled. Does: Behaviour only: beside scToggle in a toolbar (every command the same size; pressed as the document says, off for one with no state) or scButton elsewhere, and scToolbarWidget in a toolbar. |
ScEditorCount | div[scEditorCount] | The counts’ row: the word and character counts side by side, at its end. |
provideEditor(...features) | function | The features of the editors and displays below. |
withExtensions(...extensions) | function | Your own Tiptap extensions, as a feature. |
editorContentExtensions(features?) | function | The document’s extensions, for generateHTML / generateJSON. |
@semantic-components/ui/editor/tables
| Part | Selector | Description |
|---|---|---|
ScEditorTable | button[scEditorTable] | Reads: inTable(); can(action). Does: select(action). |
withTables() | function | Tables. |
@semantic-components/ui/editor/images
| Part | Selector | Description |
|---|---|---|
ScEditorUploads | [scEditor][upload] | Inputs: upload: ScEditorUploadHandler; imageTypes: string[]. Reads: uploads(): { id, file, progress }[]. Does: insert(files, position?); cancel(id). |
ScEditorImage | button[scEditorImage] | Inputs: disabled. |
withImages() | function | Images, and dropping or pasting them. |
@semantic-components/ui/editor/search
| Part | Selector | Description |
|---|---|---|
ScEditorSearchBar | div[scEditorSearchBar] | Inputs: open (two-way). Does: Open is yours: bind [(open)] to the signal that shows it (a collapsible, a popover…). Opened (by you, Ctrl / ⌘ + F): focus in the search; Escape: closed, back to the text; closed: matches cleared. |
ScEditorSearchResults | [scEditorSearchResults] | Reads: count(); index(): number | null; state(): 'idle' | 'found' | 'none'. |
ScEditorSearchOption | button[scEditorSearchOption] | Inputs: [scEditorSearchOption]: 'caseSensitive' | 'wholeWord' | 'useRegex'. |
ScEditorSearchInput | [scEditorSearchInput] | A control of the search bar: its look and its action. |
ScEditorSearchPrevious | [scEditorSearchPrevious] | A control of the search bar: its look and its action. |
ScEditorSearchNext | [scEditorSearchNext] | A control of the search bar: its look and its action. |
ScEditorReplaceInput | [scEditorReplaceInput] | A control of the search bar: its look and its action. |
ScEditorReplace | [scEditorReplace] | A control of the search bar: its look and its action. |
ScEditorReplaceAll | [scEditorReplaceAll] | A control of the search bar: its look and its action. |
ScEditorSearchClose | [scEditorSearchClose] | A control of the search bar: its look and its action. |
withSearch() | function | Search and replace, Ctrl / ⌘ + F. |
@semantic-components/ui/editor/highlight
| Part | Selector | Description |
|---|---|---|
ScEditorHighlightColor | button[scEditorHighlightColor] | Inputs: [scEditorHighlightColor]: a CSS colour. |
ScEditorHighlight | [scEditorHighlight] | A control of the search bar: its look and its action. |
ScEditorRemoveHighlight | [scEditorRemoveHighlight] | A control of the search bar: its look and its action. |
withHighlight() | function | Highlights. |
@semantic-components/ui/editor/scripts
| Part | Selector | Description |
|---|---|---|
withScripts() | function | Superscript and subscript: the commands superscript, subscript (scEditorCommand). |
@semantic-components/ui/editor/align
| Part | Selector | Description |
|---|---|---|
withAlign() | function | Alignment: the commands align-left, align-center, align-right, align-justify (scEditorCommand). |
@semantic-components/ui/editor/markdown
| Part | Selector | Description |
|---|---|---|
withMarkdown() | function | format="markdown". |
@semantic-components/ui/editor/bubble-menu
| Part | Selector | Description |
|---|---|---|
ScEditorBubbleMenu | div[scEditorBubbleMenu] | Inputs: orientation; wrap. |