Citation queries and subscriptions

Read citation snapshots, subscribe to changes, and export collaborative JSON.

Import getCitation, getCitations, getSources, and subscribeCitations from @tiptap-pro/extension-smart-citations. Pass an editor configured with Smart Citations. See citation snapshot fields for the result shape.

Queries read the current editor and source state without dispatching transactions. They throw CitationError if the extension is missing. subscribeCitations also throws if the editor has been destroyed.

ExportResult
getCitation({ editor, id })A Citation snapshot or undefined if the ID is absent.
getCitations({ editor, filter })A frozen readonly Citation[] ordered by first range position, then ID. The optional CitationFilter combines status and sourceId when both are supplied.
getSources(editor)A frozen readonly SourceSnapshot[] in insertion order.
subscribeCitations({ editor, listener })An unsubscribe function. The listener receives a CitationChange with read-only changedIds and removedIds arrays.

Listeners run when document edits or source updates change a citation. Changes to ranges also count. Cursor movement alone does not notify. Subscriptions survive unmounting and remounting the editor. Destroying the editor detaches listeners, and calling the unsubscribe function more than once is safe. Smart Citations reports listener errors in a microtask after notifying the other listeners.

See the review sidebar example for subscription setup and cleanup.

Export collaborative JSON

Use getCollaborativeCitationJSON(options) to export ProseMirror JSON with merged node citations. GetCollaborativeCitationJSONOptions takes the fragment: XmlFragment used by Tiptap Collaboration. A plain Yjs fragment export can omit node citations merged from other collaborators.

Use the Yjs document and field from your Collaboration setup. If you passed a fragment directly to Collaboration.configure(), pass that same fragment here.

import { getCollaborativeCitationJSON } from '@tiptap-pro/extension-smart-citations/collaboration'

const json = getCollaborativeCitationJSON({ fragment: ydoc.getXmlFragment(field) })