Rich text / foldkit-mixins-richtext
Move and reorder blocks with a handle
Anchor blockHandle beside the active block using blockAnchor from foldkit-richtext-dom/toolbar:
ts
import { blockAnchor } from 'foldkit-richtext-dom/toolbar'
import { blockHandle } from 'foldkit-mixins-richtext'
const [outermost] = RichText.blocksAt(model.document, model.editor.selection)
outermost === undefined
? h.empty
: h.div(
[h.Key(outermost.id), h.OnMount(blockAnchor({ hostId: 'body', node: outermost.id, gap: 8 }))],
[
blockHandle<Message>()(
{ document: model.document, hostId: 'body', node: outermost.id, wrap: edited },
h,
),
],
)Key the wrapper with h.Key(outermost.id) so blockAnchor and blockDrag rebind whenever the target block changes. The grip drags blocks anywhere allowed by the vocabulary, while the up and down buttons reorder siblings within the current container.
| Slot | Capability | Renders |
|---|---|---|
root | Container | role="group" handle wrapper |
grip | Interactive | Drag grip with data-handle="grip" |
up | Interactive | Move-up button with data-handle="up" |
down | Interactive | Move-down button with data-handle="down" |