Event contract
| Event | Payload | Trigger |
|---|---|---|
| change | html, json, css, revision | Applied document/styles change, including undo |
| selectionChange | from, to, text, revision | Selection change |
| warning | ImportReport plus source: paste/drop/import | Import requiring review |
| error | Error | Processing failure |
Constructor onChange handles change. on(name, listener) returns unsubscribe; off requires the same event name and function. Independent event ordering is not a server transaction protocol.
Source drafts
HTML/Markdown emit change after successful validation. Invalid drafts do not become the canonical document. Events do not write to a server; queues, retries and authentication belong to your application.
Revision and cleanup
Capture revision with a range for asynchronous work. Selection changes and document mutations are different. Release application-owned resources before destroy; ViText clears its own managed listeners. Storage, document.
const off = editor.on('change', ({ html, css, json, revision }) => {
console.log({ html, css, json, revision });
});
editor.on('warning', report => console.log(report.warnings));
off();