Rich text / foldkit-richtext-dom
Position toolbars, block handles, and menus
The editor renders only its host element. foldkit-richtext-dom/toolbar provides plain views and Mount positioning helpers for surrounding chrome, while foldkit-mixins-richtext provides fully restyleable Slot versions.
Marks and floating toolbars
marksToolbar({ state, toMessage, marks? }) renders buttons for the standard marks (or a custom list) using markActive(state, mark) to reflect caret/selection state. Pair it with selectionAnchor to float over a text range (assuming model holds { document, editor } and h is Foldkit's HtmlBuilder):
import * as RichText from 'foldkit-richtext'
import { marksToolbar, selectionAnchor } from 'foldkit-richtext-dom/toolbar'
RichText.coversText(model.editor.selection)
? h.div(
[h.OnMount(selectionAnchor({ hostId: 'body', gap: 8 }))],
[
marksToolbar({
state: { ...model.editor, document: model.document },
toMessage: mark => edited(Message.ToggledMark({ mark })),
})(h),
],
)
: h.emptyselectionAnchor writes position: fixed, top, left, and data-placement (top or bottom) whenever the selection, scroll, or viewport changes. Pass caret: true to anchor below a collapsed caret (for example, for a slash menu).
Anchor and drag blocks
blockAnchor({ hostId, node, gap, side? })positions an element beside blocknode(defaulting to the left edge, or'above'/'inside-end'for block toolbars), updating on DOM patches, scrolls, resizes, and element size changes.blockDrag({ hostId, node })makes the mounted element drag blocknodeto any target allowed byRichText.moveTargets. It marks[data-richtext-drop]at the drop edge, setsdata-richtext-draggingon the dragged block, auto-scrolls within 48 px of the viewport edge, cancels cleanly on Escape or cancelled pointers, and dispatchesMovedBlockon release.
Because Mounts read arguments once on insertion, key anchored elements by h.Key(node) whenever node can change.
Slash menu helpers
foldkit-richtext-dom/editor exports slashEntries, slashQuery, and slashMenu so your menu view and the Bundle's Enter handler agree on matches and order:
import { slashEntries, slashMenu, slashQuery } from 'foldkit-richtext-dom/editor'
slashQuery('see /head') // 'head'
slashMenu(slashEntries, 'see /head', 0)?.highlighted?.label // 'Heading 1'menuTextOf(view) from foldkit-richtext-dom/editor-bundle reads the active query text while respecting Message.DismissedSlash (Escape), keeping the menu closed until a new / query begins.