Rich text / foldkit-richtext-dom
Embed the low-level interpreter directly
To host the editable subtree outside the Bundle, call mount and attach (or mountInto / releaseMount from foldkit-richtext-dom/host):
ts
import { mount } from 'foldkit-richtext-dom'
import { attach } from 'foldkit-richtext-dom/events'
import * as RichText from 'foldkit-richtext'
function mountRawEditor(
host: HTMLElement,
content: RichText.Document,
onCommand: (command: RichText.Command) => void,
) {
let dom = mount(host.ownerDocument, content)
host.append(dom.root)
const attachment = attach(dom, { onIntent: onCommand })
return {
sync: (next: RichText.EditorState, changeSet: RichText.ChangeSet) => {
attachment.sync(next, changeSet)
dom = attachment.current()
},
detach: () => attachment.detach(),
}
}mount/adopt/patch/repair: Build, reuse server-rendered, incrementally update, or recover the DOM subtree indexed bydata-blockanddata-run.attach: Interceptsbeforeinput,keydown, composition, copy, cut, and paste so the browser cannot mutate content directly, queues state patches during IME composition, paintsspan[data-decoration="selection"]when focus moves to external controls, and scrolls the caret into view honoringscroll-padding.positionToRange/rangeToPosition: Translate between semanticPositionvalues and DOMRangeobjects.parseHtml(html, { kit, mint })(foldkit-richtext-dom/html): Sanitizes pasted HTML through a strict whitelist andsafeUrlcheck.
Current behavior and limits
- Intent reporting only:
attachreports user intent and waits for the caller to run commands and pass back the new state andChangeSet. - Container re-rendering: When a container's list of child items changes, the container re-renders in place rather than diffing each child item individually.
- Single host per ID: Each
hostIdidentifies one editor on a page, so repeating rows inside a single form cannot yet host separaterichTextInputeditors.