Document and ranges

HTML, JSON, CSS and revision-bearing positions.

1.0.0-beta.6 · Local build · desktop

Canonical document

HTML, JSON and text getters read the last applied document. An invalid source draft is separate. getJSON returns an independent DocumentNode; changing that returned object does not mutate the editor. CSS is separate and must be stored/restored with JSON.

Revision snapshots

Change events expose html/json/css/revision of their own revision. Lazy getter fields retain that snapshot when read later, after another edit or destroy. Spreading/serializing an event is supported. CSS-only changes increase the revision too.

Positions

SelectionInfo contains from, to, text and revision. Positions follow the structured document model and are not offsets into getText(). Captured ranges must retain their revision for delayed replacement. A stale result throws StaleDocumentError rather than overwriting newer edits.

Plain replacements

replaceText accepts non-overlapping ranges within text blocks, without inline atoms or replacement line breaks. Literal markup remains text. Transformations preserve supported marks and styles. Methods, events.

interface DocumentNode {
  type: string;
  attrs?: Record<string, unknown>;
  content?: DocumentNode[];
  marks?: { type: string; attrs?: Record<string, unknown> }[];
  text?: string;
}
interface SelectionInfo { from: number; to: number; text: string; revision: number }
interface TextEdit { from: number; to: number; text: string }
interface ImageAttributes { src: string; alt?: string; title?: string; width?: number; height?: number }

Search documentation

No results. Try different words.

All documentation