Make the DialogManager more ESM-y

This commit is contained in:
Oliver 2025-11-21 19:56:07 -07:00
parent 382ca50bb5
commit 41034854eb

View file

@ -1,14 +1,15 @@
import { Ask } from "../apps/Ask.mjs";
export class DialogManager {
/** @type {Map<string, Promise>} */
static #promises = new Map();
static #dialogs = new Map();
const promises = new Map();
static async close(id) {
this.#dialogs.get(id)?.close();
this.#dialogs.delete(id);
this.#promises.delete(id);
/** @type {Map<string, ApplicationV2>} */
const dialogs = new Map();
export function close(id) {
dialogs.get(id)?.close();
dialogs.delete(id);
promises.delete(id);
};
/**
@ -22,7 +23,7 @@ export class DialogManager {
* @param {AskOptions} opts
* @returns {AskResult}
*/
static async ask(
export async function ask(
data,
{
onlyOneWaiting = true,
@ -44,13 +45,13 @@ export class DialogManager {
const id = data.id;
// Don't do multi-thread waiting
if (this.#dialogs.has(id)) {
const app = this.#dialogs.get(id);
if (dialogs.has(id)) {
const app = dialogs.get(id);
app.bringToFront();
if (onlyOneWaiting) {
return { state: `fronted` };
} else {
return this.#promises.get(id);
return promises.get(id);
};
};
@ -88,21 +89,26 @@ export class DialogManager {
...data,
alwaysUseAnswerObject,
onClose: () => {
this.#dialogs.delete(id);
this.#promises.delete(id);
dialogs.delete(id);
promises.delete(id);
resolve({ state: `prompted` });
},
onConfirm: (answers) => resolve({ state: `prompted`, answers }),
});
app.render({ force: true });
this.#dialogs.set(id, app);
dialogs.set(id, app);
});
this.#promises.set(id, promise);
promises.set(id, promise);
return promise;
};
static get size() {
return this.#dialogs.size;
export function size() {
return dialogs.size;
};
export const DialogManager = {
close,
ask,
size,
};