Rich text / foldkit-richtext

Building operations

Prefer Edit.* over hand-written literals; the builder fills type and the return type is narrowed to that variant:

ts
const result = RichText.apply(state, [
  RichText.Edit.insertText(Text.at(5, 'after'), '!'),
  RichText.Edit.addMark(Text, 'Bold'),
])

Builders accept a NodeId or a Node.make reference interchangeably and validate shape immediately: a bad mark, offset, or from > to throws at the call site. Edit.splitBlock additionally takes the two new identities as strings or ids (NodeId.make rejects empties). Document-dependent failures — missing nodes, block targets, out-of-bounds ranges, unresolvable selections, reused split identities — still return apply diagnostics (MissingText, MissingNode, InvalidRange, InvalidSelection, InvalidInput), and raw wire input still decodes to InvalidInput. Edit builds values only; it reads no document and owns no state.