Cramflack is a project mainly written in JavaScript, it's free.
A sequel to painter
A not quite ground up rewrite of painter
The basic concept is to represent a document state as a persistent tree of non-destructive edits.