Skip to content

API reference / Common / UDocEvents

Interface: UDocEvents ​

The public event map: event name → payload. Subscribe with UDocBase.on.

Extended by ​

Properties ​

PropertyDescription
currentPage:changed
{ page: number; previousPage: number; }
Fires when the current page changes — scrolled to, navigated to, or a document opened. page and previousPage are 0-based page indices, as UDocBase.currentPage is.
currentSheet:changed
{ sheet: number; previousSheet: number; }
Fires when the sheet shown changes — a tab clicked, UDocBase.goToSheet, a search result on another sheet, or a workbook opened or closed. sheet and previousSheet are 0-based indices, as UDocBase.currentSheet is: -1 for none.
sheets:changed
{ sheets: readonly SheetInfo[]; }
Fires when UDocBase.sheets changes — a workbook opened or closed, and a sheet's tab color becoming known as the sheet loads.
viewport:changed
{ firstVisiblePage: number; lastVisiblePage: number; zoom: number; scrollTop: number; }
Fires when the view moves — scrolled, zoomed or laid out again — once the frame showing it has painted, and only when what it reports has changed. firstVisiblePage / lastVisiblePage are the 0-based indices of the first and last pages at least partly on screen (the shown spread in spread scrolling; both -1 with none on screen), zoom is UDocBase.zoom, and scrollTop how far down the view is scrolled, in CSS px.
document:loading
{ loaded: number; total: number; percent: number | null; }
Fires as UDocBase.open reads a document's bytes — fetching its URL, reading its Blob, or once for bytes given whole: loaded of total (0 when the size isn't known), and percent (null then).
document:downloaded
{ filename: string; }
Fires when the document is handed to the browser as a download — by UDocBase.download or the toolbar's Download — with the download's file name.
document:printed
{ pageCount: number; }
Fires when pages are handed to the browser's print dialog — by UDocBase.print or the toolbar's Print, after its own print dialog — with how many; not for a print cancelled while its pages render.
panel:changed
{ panel: PanelTab | null; previousPanel: PanelTab | null; }
Fires when a side panel opens, closes or switches — by the host, the user or a document asking for its outline.
document:edited
{ composedPageCount: number; }
Fires after a local edit is applied (page edits, undo/redo) — not on merges, so a sync listener that pushes a snapshot to a peer can't loop. Wire it to peer.merge(await this.snapshot()) to keep two instances in sync.
selection:changed
Record<string, never>
Fires after a local selection change (click-select, clear) — not on presence merges, so a sync listener can't loop. Wire it to peer.mergePresence(await this.presence()) so collaborators see this one's selection.
search:changed
{ matches: readonly SearchMatch[]; activeIndex: number; }
Fires when the search's matches or its current match change — as each batch of a running UDocBase.search lands, when it runs again after an edit, and when the current match moves.
collaboration:joined
Record<string, never>
Fires when this one's join of a collaboration is answered (UDocBase.joinRemoteCollaboration, UDocBase.joinLocalCollaboration): on joining, and again on each rejoin after "collaboration:interrupted".
collaboration:interrupted
{ code: number; reason: string; }
Fires when the connection to a server's collaboration is lost; it rejoins by itself, and edits made meanwhile are sent then. code and reason are the connection's close — docs/design/node-collaboration.md lists the server's; the reason is empty for a connection lost without one. A local collaboration is never interrupted.
collaboration:failed
{ code: number; reason: string; }
Fires when an error ends the collaboration: the server refused or ended this one, or couldn't be reached to join; or the local collaboration service ended it — an edit its engine couldn't take, or its worker failing. code and reason are as for "collaboration:interrupted". Not rejoined.
collaboration:left
Record<string, never>
Fires when this one leaves the collaboration: through UDocBase.leaveCollaboration, or by opening another document or closing this one.
annotation:inserted
{ pageIndex: number; annotation: Annotation; }
Fires for each annotation added to a PDF — by the Annotate tab's tools, UDocBase.addPageAnnotation, an undo or redo, or a collaborator — once per annotation, a reply too, in page order. The annotation is read without its appearance.
annotation:updated
{ pageIndex: number; annotation: Annotation; }
Fires for each annotation changed, by any of the means "annotation:inserted" names.
annotation:removed
{ pageIndex: number; annotation: Annotation; }
Fires for each annotation removed, by any of the means "annotation:inserted" names, with the annotation as it was.
annotation:selected
| { pageIndex: number; annotation: Annotation; } | null
Fires when the selected annotation changes — null when none is selected any more.
annotation:hovered
| { pageIndex: number; annotation: Annotation; clientX: number; clientY: number; } | null
Fires when the pointer comes to rest on an annotation, in any pointer mode, or leaves it (null). clientX / clientY are browser-viewport coordinates at the change, for placing a tooltip in screen space.
annotation:clicked
{ pageIndex: number; annotation: Annotation; clientX: number; clientY: number; }
Fires for a click on an annotation, whatever the pointer mode, before the click is handled (a link followed, the annotation picked). clientX / clientY are browser-viewport coordinates at the click.