Rich text / foldkit-richtext
Named node references
Node.make('text-1') declares a reusable identity. Its .id is a validated
NodeId, .at(offset, affinity) constructs a Position, and .read(document)
returns the node from that document or undefined. Narrow the returned node's
type before reading text or block-specific fields.
Keep references in application definitions; persist IDs and content, not reference methods. The reference is immutable and holds no content. Read it against the next document to see an edit, or against an older snapshot to inspect that version. Two references with the same ID address the same node within a document; neither reserves the ID or inserts anything. Document validation still rejects duplicate content IDs. IDs are document-local: using a reference with another document looks up that same ID there, without an ownership or authorization guarantee.
at validates offset shape and affinity, but cannot prove the node exists, is
text, or is long enough. apply checks those conditions against the current
document. A Position remains a resolved offset and must still be mapped through
edits; a Node reference does not turn it into a collaborative anchor (see
Shared documents for one that is). read
performs a linear lookup, intended for application reads rather than bulk editing.