Skip to content
@pyreon/rich-text · @pyreon/code
fundamentals · editors

Delete the useEffect that keeps your editor in sync.

TipTap for rich text and CodeMirror 6 for code, wrapped so the document is a writable signal. Toolbars, word counts and save buttons read it directly, and a write from outside lands in the editor without echoing back.

bun add @pyreon/rich-text @pyreon/code
Documentation
rich text
TipTap 3 on ProseMirrorMIT. The engine loads when <RichText> first renders.
code
CodeMirror 6Plus a diff editor, tabbed files and a minimap.
languages
19 grammars, loaded on first useJS, TS, JSX, TSX and JSON by default; 14 more with @pyreon/code/languages-all.
iOS and Android
hosted in a WebViewNext release, experimental. Same TipTap and CodeMirror inside.
The two Pyreon editors side by side: a rich-text editor with a toolbar (bold active because the caret is in bold text) editing release notes with a heading, a list and a quote, and a code editor showing a Pyreon component in TSX with line numbers and a cursor status bar.The two Pyreon editors side by side: a rich-text editor with a toolbar (bold active because the caret is in bold text) editing release notes with a heading, a list and a quote, and a code editor showing a Pyreon component in TSX with line numbers and a cursor status bar.
  • 7 computed values on every rich-text editor: html, text, isEmpty, characterCount, wordCount, canUndo, canRedopackages/fundamentals/rich-text/src/types.ts (RichTextEditor)
  • 19 code grammars, each fetched the first time it is usedpackages/fundamentals/code/src/languages.ts + languages-all.ts (getAvailableLanguages() returns 20 ids incl. plain)
  • 3 code editors in the box: CodeEditor, DiffEditor, TabbedEditorpackages/fundamentals/code/src/index.ts

synthetic · author-run · M3 Max · record of 2026-11-05

Every result, including where we lose →
why teams pick it

The editor work you would otherwise write by hand.

  1. The document is a signal

    editor.json (rich text) and editor.value (code) are writable signals. Read them anywhere and the UI follows; call .set() and the editor updates.

  2. One binding, no echo

    bindRichTextToSignal and bindEditorToSignal keep an editor and your store in step both ways with built-in loop guards. The code binding takes serialize and parse, so a JSON editor can drive a typed object and keep the last valid value while the user types.

  3. Counts before the editor loads

    wordCount, characterCount and isEmpty derive from the document itself, so they are right before TipTap mounts. Moving the cursor does not re-run them; isActive('bold') still follows the selection.

  4. The same editors in your native appnext release

    <CodeWebView> and <RichTextWebView> lower to a native WebView hosting the same CodeMirror and TipTap, and pyreon-native assets builds the page for you. A round trip both ways is covered by the iOS and Android device tests.

the difference

Same TipTap. The sync code goes away.

React + @tiptap/react

An update handler, an effect that pushes outside changes back in without echoing, a JSON compare, and a selector hook for toolbar state.

import { useEffect } from 'react'
import { EditorContent, useEditor, useEditorState, type JSONContent } from '@tiptap/react'
import StarterKit from '@tiptap/starter-kit'

function PostEditor({ draft, setDraft }: { draft: JSONContent; setDraft: (d: JSONContent) => void }) {
  const editor = useEditor({
    extensions: [StarterKit],
    content: draft,
    immediatelyRender: false,
    onUpdate: ({ editor }) => setDraft(editor.getJSON()),
  })

  // Push outside changes in, without echoing our own edits back.
  useEffect(() => {
    if (!editor || JSON.stringify(editor.getJSON()) === JSON.stringify(draft)) return
    editor.commands.setContent(draft, { emitUpdate: false })
  }, [editor, draft])

  const ui = useEditorState({
    editor,
    selector: ({ editor }) => ({
      bold: editor?.isActive('bold') ?? false,
      words: editor?.getText().split(/\s+/).filter(Boolean).length ?? 0,
    }),
  })

  return (
    <>
      <button
        className={ui?.bold ? 'on' : ''}
        onClick={() => editor?.chain().focus().toggleBold().run()}
      >B</button>
      <EditorContent editor={editor} />
      <p>{ui?.words ?? 0} words</p>
    </>
  )
}
with @pyreon/rich-text

The component runs once. The binding handles both directions; the toolbar and the counter read signals.

import { onUnmount } from '@pyreon/core'
import { signal } from '@pyreon/reactivity'
import { bindRichTextToSignal, createRichTextEditor, RichText, type JSONContent } from '@pyreon/rich-text'

const draft = signal<JSONContent>({ type: 'doc', content: [] })

function PostEditor() {
  const editor = createRichTextEditor({ ariaLabel: 'Post body' })
  const binding = bindRichTextToSignal({ editor, signal: draft })
  onUnmount(() => { binding.dispose(); editor.dispose() })

  return (
    <>
      <button
        class={() => (editor.isActive('bold') ? 'on' : '')}
        onClick={() => editor.chain()?.focus().toggleBold().run()}
      >B</button>
      <RichText instance={editor} />
      <p>{() => editor.wordCount()} words</p>
    </>
  )
}
coming from

Coming from @uiw/react-codemirror or @tiptap/react?

A JSON config editor that keeps the last valid value

@uiw/react-codemirror
import { useCallback, useState } from 'react'
import CodeMirror from '@uiw/react-codemirror'
import { json } from '@codemirror/lang-json'

function ConfigEditor() {
  const [config, setConfig] = useState({ host: 'localhost', port: 3000 })
  const [text, setText] = useState(() => JSON.stringify(config, null, 2))
  const [error, setError] = useState('')

  const onChange = useCallback((value: string) => {
    setText(value)
    try {
      setConfig(JSON.parse(value))
      setError('')
    } catch (e) {
      setError((e as Error).message)
    }
  }, [])

  return (
    <>
      <CodeMirror value={text} height="300px" theme="dark" extensions={[json()]} onChange={onChange} />
      <p role="alert">{error}</p>
    </>
  )
}
Pyreon

Both sides run CodeMirror 6. useEditorSignal disposes the binding when the component unmounts. Keep serialize deterministic: valid input is re-serialized, so formatting follows JSON.stringify(v, null, 2).

import { onUnmount } from '@pyreon/core'
import { signal } from '@pyreon/reactivity'
import { CodeEditor, createEditor, useEditorSignal } from '@pyreon/code'

const config = signal({ host: 'localhost', port: 3000 })
const error = signal('')

function ConfigEditor() {
  const editor = createEditor({ language: 'json', theme: 'dark' })
  useEditorSignal({
    editor,
    signal: config,
    serialize: (v) => JSON.stringify(v, null, 2),
    parse: (text) => {
      const next = JSON.parse(text)
      error.set('')
      return next
    },
    onParseError: (e) => error.set(e.message),
  })
  onUnmount(() => editor.dispose()) // CodeEditor does not dispose the instance it is handed

  return (
    <>
      <CodeEditor instance={editor} style="height: 300px" />
      <p role="alert">{error()}</p>
    </>
  )
}

useEditor + useEditorState become one instance

@tiptap/react
import { EditorContent, useEditor, useEditorState } from '@tiptap/react'
import StarterKit from '@tiptap/starter-kit'
import { Placeholder } from '@tiptap/extensions'

function Notes() {
  const editor = useEditor({
    extensions: [StarterKit, Placeholder.configure({ placeholder: 'Write a note' })],
    immediatelyRender: false,
  })
  const canUndo = useEditorState({
    editor,
    selector: ({ editor }) => editor?.can().undo() ?? false,
  })

  return (
    <>
      <button disabled={!canUndo} onClick={() => editor?.chain().focus().undo().run()}>Undo</button>
      <EditorContent editor={editor} />
    </>
  )
}
Pyreon

Your TipTap extensions carry over through extensions: [...], appended after StarterKit. placeholder is built in.

import { onUnmount } from '@pyreon/core'
import { createRichTextEditor, RichText } from '@pyreon/rich-text'

function Notes() {
  const editor = createRichTextEditor({ placeholder: 'Write a note' })
  onUnmount(() => editor.dispose())

  return (
    <>
      <button disabled={() => !editor.canUndo()} onClick={() => editor.undo()}>Undo</button>
      <RichText instance={editor} />
    </>
  )
}
try it

Type and watch the signals.

The real @pyreon/rich-text editor. The meters on the right read the editor's own signals, and "Load from outside" writes the bound signal to show an external change landing without an echo.

  • editor.​wordCount()12
  • editor.​characterCount()63
  • editor.​isEmpty()false
  • editor.​isActive('bold')false

Counts come from the document JSON, so they are right before the editor engine has even loaded, and a cursor move re-runs none of them.

@pyreon/code · read only

editor.json(), the document the bound signal carries, live in a CodeMirror editor whose value is a signal too.

benchmarks

Same engine, about the same weight.

Both wrap CodeMirror 6, so the size is mostly CodeMirror. We came out 4% heavier and print it. The Monaco row still fails to bundle, so there is no Monaco number here.

vs @uiw/react-codemirror (both wrap CodeMirror 6)Pyreonrival · lower is better
  • core editor bundle (gz)
    131 KB
    126.4 KB
    loss4% larger
Apple M3 Max · record of 2026-11-05 · overnight run, one run · author-run, syntheticFull method, every loss →
what's included

Two editors, one way of working.

  • createRichTextEditor HTML or ProseMirror JSON in; json is a writable signal out.
  • isActive() and chain() reactive toolbar state, and every TipTap command.
  • editable as a signal flip a live editor to read-only with editor.editable.set(false).
  • Accessible by default the content area is a labelled role="textbox"; placeholder reaches screen readers too.
  • createEditor code with signals for value, language, theme, cursor, selection and line count.
  • DiffEditor side by side, or inline with accept and reject per change when editable.
  • TabbedEditor multi-file editing; each tab keeps its own undo history.
  • Diagnostics and gutters setDiagnostics, line highlights and gutter markers for linters and debuggers.
  • Minimap, search, folding a canvas minimap, the search panel, fold all and unfold all.
  • Vim and Emacs keys one flag each, loaded from an optional package only when switched on.
recipes

Things to build with it.

A composer that autosaves

Bind the editor to an HTML string, save a second after the last keystroke, and show a character budget and an Undo that knows when it has nothing to undo.

import { onUnmount } from '@pyreon/core'
import { effect, signal } from '@pyreon/reactivity'
import { bindRichTextToSignal, createRichTextEditor, RichText } from '@pyreon/rich-text'

declare function saveDraft(html: string): Promise<void>

const body = signal('<p>Start writing…</p>')

function Composer() {
  const editor = createRichTextEditor({ content: body.peek(), placeholder: 'Write something', ariaLabel: 'Message' })
  const binding = bindRichTextToSignal({ editor, signal: body, format: 'html' })
  let timer: ReturnType<typeof setTimeout> | undefined
  const autosave = effect(() => {
    const html = body()
    clearTimeout(timer)
    timer = setTimeout(() => void saveDraft(html), 1000)
  })
  onUnmount(() => { clearTimeout(timer); autosave.dispose(); binding.dispose(); editor.dispose() })

  return (
    <>
      <RichText instance={editor} style="min-height: 12rem" />
      <footer>
        {() => editor.characterCount()} / 280
        <button disabled={() => !editor.canUndo()} onClick={() => editor.undo()}>Undo</button>
      </footer>
    </>
  )
}
Review a change before saving

An inline diff of two signals. With readOnly={false} each change gets accept and reject controls.

import { signal } from '@pyreon/reactivity'
import { DiffEditor } from '@pyreon/code'

const saved = signal('export const limit = 10\n')
const edited = signal('export const limit = 25\nexport const retries = 3\n')

function Review() {
  return <DiffEditor original={saved()} modified={edited()} language="typescript" inline readOnly={false} style="height: 240px" />
}
next release
The same editors in a native screen

Two hosted editors in one component. pyreon-native assets builds the pages from the CodeMirror and TipTap your app has installed.

import { signal } from '@pyreon/reactivity'
import { CodeWebView } from '@pyreon/code/webview'
import { RichTextWebView } from '@pyreon/rich-text/webview'

const code = signal('let total = 0')
const note = signal('<p>Hello from the same source</p>')
const failure = signal('')

const Editors = () => (
  <>
    <CodeWebView
      state={() => ({ value: code(), language: 'typescript', readOnly: false })}
      onChange={(v) => code.set(v)}
      onError={(m) => failure.set(m)}
    />
    <RichTextWebView
      state={() => ({ content: note(), editable: true })}
      onChange={(text) => note.set(text)}
      onError={(m) => failure.set(m)}
      grow
    />
  </>
)
api

Small APIs for both.

Every export has a reference page with its signature, an example and the mistakes people make with it.

rich text · 4
  • createRichTextEditor
  • RichText
  • bindRichTextToSignal
  • JSONContent
code · 7
  • createEditor
  • CodeEditor
  • DiffEditor
  • createTabbedEditor
  • TabbedEditor
  • bindEditorToSignal
  • useEditorSignal
languages and themes · 7
  • loadLanguage
  • registerLanguage
  • getAvailableLanguages
  • @pyreon/code/languages-all
  • darkTheme
  • lightTheme
  • resolveTheme
extras · 2
  • minimapExtension
  • openSearchPanel
native hosting · /webview · 4
  • CodeWebView
  • buildCodeHostHtml
  • RichTextWebView
  • buildRichTextHostHtml
good to know

Good to know before you start.

You own the lifecycle

An editor you create is yours to dispose. Call editor.dispose() in onUnmount, and binding.dispose() too, unless you bind with useEditorSignal, which disposes the binding for you.

Install the grammars you use

Each language is an optional peer (@codemirror/lang-*). Install the ones you load; the rest never reach your bundle.

CodeMirror itself is not lazy

Grammars and TipTap load on demand, but the CodeMirror core ships in the chunk that imports @pyreon/code. Put a code-heavy page behind lazy() or a route split.

On native it is a web editor

The hosted editors are a WebView: expect WebView start-up time and web text editing, not a SwiftUI or Compose text field. Rich text hosts StarterKit; custom extensions need your own html page.

questions

What people ask first.

Did you write your own editor engine?

No. Rich text is TipTap 3 on ProseMirror and code is CodeMirror 6, both MIT. Pyreon adds the signals, the bindings, the components and the native hosting. TipTap's paid Pro modules are not included.

Can I keep my TipTap extensions?

Yes. Pass them in extensions; they are appended after StarterKit, or set starterKit: false and bring the whole schema. editor.view() gives you the TipTap Editor once mounted.

How big is the code editor?

In our bundle run the core editor was 131.0 KB gzipped against 126.4 KB for @uiw/react-codemirror: the same CodeMirror 6, with us 4% heavier. Grammars come on top, one at a time.

Is real-time collaboration built in?

Not as a packaged integration. The pattern is TipTap's collaboration extension over a Yjs document, with createYjsDoc and syncedAwareness from @pyreon/sync/yjs for the document, transport and presence. You wire it; we do not test it end to end yet.

What changes on iOS and Android?

The editor runs in a native WebView, and <RichTextWebView>'s onChange receives the TipTap JSON as a string (a native handler cannot hold the object). On the web, JSON.parse it if you want the object. This lands in the next release and native targets are experimental.

Two real editors. Zero sync effects.

bun add @pyreon/rich-text @pyreon/code
Read the editor guide