Move closingPrevented to a property

367da588cd8356245a71ab2a534e67596ac51886

Wolfsblvt <wolfsblvt@gmail.com>

1 files changed, +4 -1Ignore whitespace
public/scripts/popup.js+4 -1
@@ -135,6 +135,7 @@ export class Popup {
135135
136 /** @type {Promise<any>} */ #promise;136 /** @type {Promise<any>} */ #promise;
137 /** @type {(result: any) => any} */ #resolver;137 /** @type {(result: any) => any} */ #resolver;
138 /** @type {boolean} */ #isClosingPrevented;
138139
139 /**140 /**
140 * Constructs a new Popup object with the given text content, type, inputValue, and options141 * Constructs a new Popup object with the given text content, type, inputValue, and options
@@ -342,7 +343,7 @@ export class Popup {
342 // It seems to just call 'close' on the dialog even if the 'cancel' event was prevented.343 // It seems to just call 'close' on the dialog even if the 'cancel' event was prevented.
343 // Here, we just say that close should not happen if the dalog has no result.344 // Here, we just say that close should not happen if the dalog has no result.
344 const closeListener = async (evt) => {345 const closeListener = async (evt) => {
345 if (this.result === undefined) {346 if (this.#isClosingPrevented) {
346 evt.preventDefault();347 evt.preventDefault();
347 evt.stopPropagation();348 evt.stopPropagation();
348 this.dlg.showModal();349 this.dlg.showModal();
@@ -495,6 +496,7 @@ export class Popup {
495 if (this.onClosing) {496 if (this.onClosing) {
496 const shouldClose = this.onClosing(this);497 const shouldClose = this.onClosing(this);
497 if (!shouldClose) {498 if (!shouldClose) {
499 this.#isClosingPrevented = true;
498 // Set values back if we cancel out of closing the popup500 // Set values back if we cancel out of closing the popup
499 this.value = undefined;501 this.value = undefined;
500 this.result = undefined;502 this.result = undefined;
@@ -502,6 +504,7 @@ export class Popup {
502 return undefined;504 return undefined;
503 }505 }
504 }506 }
507 this.#isClosingPrevented = false;
505508
506 Popup.util.lastResult = { value, result, inputResults: this.inputResults };509 Popup.util.lastResult = { value, result, inputResults: this.inputResults };
507 this.#hide();510 this.#hide();