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.

SlotCapabilityRenders
rootContainerrole="group" handle wrapper
gripInteractiveDrag grip with data-handle="grip"
upInteractiveMove-up button with data-handle="up"
downInteractiveMove-down button with data-handle="down"