Rich text / foldkit-richtext-dom

foldkit-richtext-dom

The browser half of a foldkit-richtext editor: it owns the contenteditable subtree, and gives an application an editor it places like any other Foldkit Bundle.

A rich-text editor cannot let a virtual DOM own its contenteditable subtree: the browser mutates that subtree directly for typing, selection, IME, and the clipboard, and rebuilding it on every keystroke fights that native behavior. This package owns the subtree instead. It renders a semantic Document into real DOM once, patches only the nodes a ChangeSet names, and turns the browser events it understands into Messages.

Who owns what

foldkit-richtext         the semantics: Document, commands, transactions, validation
foldkit-richtext-dom     the contenteditable subtree and its events       (this package)
your application         the document in its Model, and everything around the editor
foldkit-mixins-richtext  that everything, drawn as styleable views: toolbars, menus, handle

The document is never read back from the DOM. It lives in the application's Model, and the DOM is consulted only to map a browser selection to a position. Only Document, ChangeSet, and Selection values, commands, and Messages cross the boundary.

The loop

browser event → Message → update runs the command → Model holds the new document
                                                   → patch Command → DOM patched to match

An edit is a transition like any other: update decides, the Model commits, and rendering follows through a Command that patches what the ChangeSet names. Nothing edits the DOM first and reports later; an event the adapter cannot honor is prevented, not let through.

Install

This package is early: 0.x, and its API may change between minor versions.

bash
pnpm add foldkit-richtext-dom foldkit-richtext foldkit-bundle foldkit effect