Move closingPrevented to a property

This commit is contained in:
Wolfsblvt
2024-07-14 22:37:22 +02:00
parent 7b7c1121bb
commit 367da588cd

View File

@@ -135,6 +135,7 @@ export class Popup {
/** @type {Promise<any>} */ #promise; /** @type {Promise<any>} */ #promise;
/** @type {(result: any) => any} */ #resolver; /** @type {(result: any) => any} */ #resolver;
/** @type {boolean} */ #isClosingPrevented;
/** /**
* Constructs a new Popup object with the given text content, type, inputValue, and options * Constructs a new Popup object with the given text content, type, inputValue, and options
@@ -342,7 +343,7 @@ export class Popup {
// It seems to just call 'close' on the dialog even if the 'cancel' event was prevented. // It seems to just call 'close' on the dialog even if the 'cancel' event was prevented.
// Here, we just say that close should not happen if the dalog has no result. // Here, we just say that close should not happen if the dalog has no result.
const closeListener = async (evt) => { const closeListener = async (evt) => {
if (this.result === undefined) { if (this.#isClosingPrevented) {
evt.preventDefault(); evt.preventDefault();
evt.stopPropagation(); evt.stopPropagation();
this.dlg.showModal(); this.dlg.showModal();
@@ -495,6 +496,7 @@ export class Popup {
if (this.onClosing) { if (this.onClosing) {
const shouldClose = this.onClosing(this); const shouldClose = this.onClosing(this);
if (!shouldClose) { if (!shouldClose) {
this.#isClosingPrevented = true;
// Set values back if we cancel out of closing the popup // Set values back if we cancel out of closing the popup
this.value = undefined; this.value = undefined;
this.result = undefined; this.result = undefined;
@@ -502,6 +504,7 @@ export class Popup {
return undefined; return undefined;
} }
} }
this.#isClosingPrevented = false;
Popup.util.lastResult = { value, result, inputResults: this.inputResults }; Popup.util.lastResult = { value, result, inputResults: this.inputResults };
this.#hide(); this.#hide();