Focus the delete button in a confirm dialog

To focus the Delete button instead of Cancel when the delete annotation dialog opens, register an annotations.willChange event listener:

instance.addEventListener("annotations.willChange", (event) => {
const annotation = event.annotations.get(0);
if (
event.reason ===
NutrientViewer.AnnotationsWillChangeReason.DELETE_START
) {
console.log("Will open deletion confirmation dialog");
// We need to wrap the logic in a `setTimeOut()`, because the modal will be rendered on the next tick.
setTimeout(function () {
// The button is in the context of the Nutrient Web SDK viewer.
const buttons = instance.contentDocument.querySelectorAll(
'[role="alertdialog"] button'
);
console.log(buttons);
const button = buttons
.values()
.find((button) => button.innerText === "Delete");
if (button) {
button.focus();
console.warn("Delete confirmation button focused.");
} else {
console.warn("Delete confirmation button not found.");
}
}, 0);
}
});