Rich text / foldkit-richtext
A small edit
bash
pnpm add foldkit-richtext effectts
import * as RichText from 'foldkit-richtext'
const Text = RichText.Node.make('text-1')
const paragraph = RichText.Paragraph.make({
type: 'Paragraph',
id: RichText.NodeId.make('paragraph-1'),
children: [RichText.Text.make({
type: 'Text',
id: Text.id,
text: 'Hello',
marks: ['Bold'],
})],
})
const document = RichText.Document.make({ version: 1, children: [paragraph] })
const result = RichText.apply({ document, selection: null }, [
RichText.Edit.insertText(Text.at(5, 'after'), '!'),
])
if (result.ok) {
// The parent reducer installs result.state in its Model.
const editedDocument = result.state.document
void editedDocument
}Schema constructors validate the value; IDs are supplied by the caller and must
be unique across blocks and text runs. apply validates state and operations,
then applies operations in array order. A later invalid operation rejects the
whole transaction. No partially edited state is returned, and inputs are not
mutated. result.error is a stable diagnostic code, without raw validation internals.