Detect changes in annotations

In addition to controlling annotation changes via our create, update, and delete APIs, we also expose a number of events that can be used to intercept annotation changes that originate in the UI by clicks from the user or that are synced from the server.

Event Use case
annotations.load Fires whenever annotations are loaded from the document.
annotations.willChange Fires whenever a user action performed via the UI (e.g. drawing) on an annotation occurs.
annotations.change Fires whenever the current annotations change due to a user action (e.g. clicking the UI) or via the API.
annotations.create Fires whenever annotations are created.
annotations.update Fires whenever annotations are updated.
annotations.delete Fires whenever annotations are deleted.
instance.addEventListener("annotations.load", loadedAnnotations => {
  console.log(loadedAnnotations);
});
instance.addEventListener("annotations.willChange", event => {
  if (event.reason === PSPDFKit.AnnotationsWillChangeReason.DRAW_START) {
    console.log("The user is drawing...");
  }
});
instance.addEventListener("annotations.change", () => {
  console.log("Something in the annotations has changed.");
});
instance.addEventListener("annotations.create", createdAnnotations => {
  console.log(createdAnnotations);
});
instance.addEventListener("annotations.update", updatedAnnotations => {
  console.log(updatedAnnotations);
});
instance.addEventListener("annotations.delete", deletedAnnotations => {
  console.log(deletedAnnotations);
});