@texuli/editor
v0.18.0
Published
Rich text editor for Svelte 5 on the @texuli/core editor texels: owned document model, transforms, history, Markdown in and out, and a sink-free rendering.
Maintainers
Readme
@texuli/editor
A rich text editor for Svelte 5: headings, lists, todo lists, quotes, code,
dividers, media references, and the strong, em, strike, code and link marks,
with undo and redo, input-method composition, Markdown shortcuts, a roving
formatting toolbar, a link dialog, safe paste, and Markdown in and out. The
document is an owned, closed model (the @texuli/core editor texels), and
the rendering is sink-free: no {@html}, no innerHTML, every link through
the URL policy. It is part of Texuli, "Small pieces.
Infinite possibilities.": an MIT Svelte 5 component library by Dailybot, Inc.
In the stack: layer L4, a domain package on the @texuli/core editor texels, @texuli/primitives, the @texuli/tokens token engine and the texuli components. @texuli/pages builds on it.
Status: in development (pre-1.0).
@texuli/editoris published on npm as0.18.0, with provenance (first published as0.5.0; the publish workflow publishes it aftertexuli). Under 0.x a new minor (0.18.0) may contain breaking changes, so pin the exact version or use^0.18.0, which accepts only 0.18.x. The architecture contract is ADR-003 in DECISIONS and EDITOR_ARCHITECTURE.
Install
npm install @texuli/editorIn the Texuli workspace, depend on it as
"@texuli/editor": "workspace:*". It builds on @texuli/core,
@texuli/primitives, @texuli/tokens and texuli; svelte (^5.57.2) is a
peer dependency. Import the token stylesheet once
(@texuli/tokens/base.css); the editor imports its own CSS.
Quick start
<script lang="ts">
import { RichTextEditor } from '@texuli/editor/editor';
import { documentToMarkdown, markdownToDocument } from '@texuli/editor/markdown';
// Untrusted Markdown (agent output, stored text) reads at the untrusted tier.
const { doc } = markdownToDocument('# Plan\n\n- [ ] Draft the **brief**\n- [x] Book the room');
let markdown = $state(documentToMarkdown(doc));
</script>
<RichTextEditor value={doc} label="Notes" onChange={(next) => (markdown = documentToMarkdown(next))} />value is read on mount and whenever a new document arrives from outside
(history restarts); the editor's own edits arrive through onChange. Keep a
held document in $state.raw, not $state, so it is not deep-proxied.
Subpaths
| Import | What it gives you | Doc |
| --- | --- | --- |
| @texuli/editor/editor | RichTextEditor (toolbar, link dialog and surface), EditorSurface, the DOM selection mapping | editor-surface |
| @texuli/editor/toolbar | EditorToolbar, the roving formatting toolbar | editor-toolbar |
| @texuli/editor/block-menu | BlockTypeMenu, the block-type menu button (paragraph, headings, lists, quote, code; one undo step) | editor-block-menu |
| @texuli/editor/emoji | EditorEmojiButton, the toolbar emoji button with EmojiPicker in a popover; the :shortcode: rule is the controller's shortcodes lookup | editor-emoji |
| @texuli/editor/export | DialectExport, the export-for-chat panel (Slack, Discord, WhatsApp, Telegram, Teams, Google Chat, Mattermost, plain text) with the losses shown | editor-export |
| @texuli/editor/link-dialog | LinkDialog, link editing through the URL policy | editor-link-dialog |
| @texuli/editor/controller | EditorController, the headless editor (history, commands, composition guard, announcements), and DEFAULT_EDITOR_LABELS | editor-controller |
| @texuli/editor/markdown | markdownToDocument and documentToMarkdown: framework-free Markdown in and out; importMarkdown (Paste as Markdown) and documentToDialect (chat formats) | editor-markdown |
| @texuli/editor/paste | Framework-free clipboard import: HTML through the shared DOM-free reader (@texuli/core/html), plain text and the editor's JSON format | editor-paste |
| @texuli/editor | The editor, toolbar, link dialog, controller and paste in one barrel (not the Markdown codec), plus EDITOR_PACKAGE_VERSION | — |
Each subpath has its own gzip budget in texuli.budgets.json
(pnpm size --filter @texuli/editor). The editor surface bundles the core
editor texels, so @texuli/editor/editor measures about 34 KiB gzip;
@texuli/editor/markdown about 8.5 KiB, and ./paste and ./controller
load no UI.
New in 0.6.0
Ships in 0.6.0; the 0.5.0 release predates it: host inline extensions
(G48). Mentions and references register a sigil from a closed set
(createInlineExtensions in @texuli/core/editor-model) and round-trip
through @texuli/editor/markdown as <sigil>{id|label} with an
extension mark that keeps their id; the editor renders them as a
tx-editor-extension span
(editor-markdown).
Key guarantees
- No HTML sinks. Every node and mark renders through owned Svelte components with text interpolation only. Raw HTML in Markdown stays literal text; pasted HTML goes through an owned tokenizer and an element allowlist; nothing is ever parsed as markup into the page.
- Links and media pass the URL policy. Links typed in the dialog pass
safeHrefat the editor'strust(untrustedby default) and are checked again at render; a refused one renders as text. Pasted and Markdown links are checked at theuntrustedtier. Links getrel="noopener noreferrer nofollow"and notarget. Media blocks are resolved by the host (resolveMedia) and theirsrcpassessafeImageSrc. - Bounded, linear input. Documents are capped (2,000 blocks, 200,000 characters, depth 4) and Markdown at 100,000 characters; reading and writing Markdown stay linear on hostile input (the tests read and write 18 such inputs at the cap within a bound each).
- Accessible editing. One
contenteditabletextbox with a name; Tab indents only inside lists and Escape then Tab leaves the editor;aria-readonlyin read-only mode; mark, block, list, undo, paste and refusal changes are announced politely through the core announcer. - Input methods. Between
compositionstartandcompositionendthe model is not touched; the composed text is applied as one step. - Styles use
--tx-*tokens and logical properties only, with forced-colors mappings.
What is not done yet
- Copy writes no
application/x-texuli-editor+jsondata yet (the native copy runs; paste reads that format when present). Drop is refused. - No “Paste as Markdown” command, no block-type menu (the toolbar has heading buttons) and no drag handles.
- No browser behavior scenario, axe sweep, CSP matrix row or
tests/perflimit for the editor yet; the long-document posture is a design budget, not a measured result. - Tree adapters to blocks and the catalog are planned in those packages.
Tests: pnpm vitest run packages/editor (the model, hostile paste and
link-policy cases, the component, the Markdown codec and the docs coverage).
Examples: editor-basic, editor-toolbar and editor-long-document in
@texuli/examples, with light and dark visual baselines.
Documentation
- The model, transforms, history and keymap: core-editor
- Decisions: ADR-003 in DECISIONS and EDITOR_ARCHITECTURE
- Source: github.com/DailybotHQ/texuli · Issues: github.com/DailybotHQ/texuli/issues
Contributing
Contributions are welcome; start at the GitHub repository.
License
MIT © Dailybot, Inc. Powered by Dailybot.
