Observe Document Editor Visibility

If you need to be notified when Document Editor is displayed or hidden, use the viewState.change event listener to check whether or not Document Editor is being displayed:

// Add the event listener to the instance.
instance.addEventListener(
  "viewState.change",
  (viewState, previousState) => {
    // Check if the current view state is "document_editor."
    if (
      viewState.interactionMode?.toLowerCase() === "document_editor"
    ) {
      console.log("Document Editor Displaying");
    }
    // If the previous view state is "document_editor," the document editor was closed.
    if (
      previousState.interactionMode?.toLowerCase() === "document_editor"
    ) {
      console.log("Document Editor Hidden");
    }
  }
);

This has been tested with PSPDFKit for Web 2020.6.4.