Reference
Every document change is a Step.
Four faces cover the algebra; undo and AI discard are the same invert stack.
apply(doc, invert(step)) ≈ doc
// after apply(doc, step)
Property-tested as apply ∘ invert = identity on legal steps.
| Face | Meaning |
|---|---|
| Insert text | Characters into a text leaf at a path/offset |
| Delete text | Remove a text range |
| Replace node | Swap a node at path |
| Splice children | Insert/remove siblings under a parent |
map takes a Step and a Position and returns a Position′ after the step.
Untouched subtrees stay equal; touched regions translate or clamp.
Collab rebases remote steps through pending local steps with this map.
import { apply, appendText } from 'markloom'
const step = appendText(doc, blockId, '…')
const next = apply(doc, step)