2025-12-04 15:24:44 +08:00
|
|
|
import { BimDialog } from '../components/dialog';
|
|
|
|
|
import type { DialogOptions } from '../components/dialog/index.type';
|
|
|
|
|
import type { ThemeConfig } from '../themes/types';
|
2025-12-08 10:02:24 +08:00
|
|
|
import { themeManager } from '../services/theme';
|
2026-01-22 15:23:57 +08:00
|
|
|
import { BaseManager } from '../core/base-manager';
|
2025-12-04 15:24:44 +08:00
|
|
|
|
2026-01-22 15:23:57 +08:00
|
|
|
export class DialogManager extends BaseManager {
|
2025-12-04 15:24:44 +08:00
|
|
|
private container: HTMLElement;
|
|
|
|
|
private activeDialogs: BimDialog[] = [];
|
|
|
|
|
|
2026-01-22 15:23:57 +08:00
|
|
|
constructor(container: HTMLElement) {
|
|
|
|
|
super();
|
2025-12-04 15:24:44 +08:00
|
|
|
this.container = container;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public create(options: Omit<DialogOptions, 'container'>): BimDialog {
|
|
|
|
|
const dialog = new BimDialog({
|
|
|
|
|
container: this.container,
|
|
|
|
|
...options,
|
|
|
|
|
onClose: () => {
|
|
|
|
|
this.activeDialogs = this.activeDialogs.filter(d => d !== dialog);
|
|
|
|
|
if (options.onClose) options.onClose();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
dialog.setTheme(themeManager.getTheme());
|
|
|
|
|
this.activeDialogs.push(dialog);
|
|
|
|
|
return dialog;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public updateTheme(theme: ThemeConfig) {
|
|
|
|
|
this.activeDialogs.forEach(dialog => {
|
|
|
|
|
if (dialog.setTheme) {
|
|
|
|
|
dialog.setTheme(theme);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-12-08 10:02:24 +08:00
|
|
|
|
|
|
|
|
public destroy() {
|
|
|
|
|
this.activeDialogs.forEach(d => d.destroy());
|
|
|
|
|
this.activeDialogs = [];
|
2026-01-22 15:23:57 +08:00
|
|
|
super.destroy();
|
2025-12-08 10:02:24 +08:00
|
|
|
}
|
2025-12-22 18:48:38 +08:00
|
|
|
}
|