1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | "use strict";
|
23 |
|
24 | Object.defineProperty(exports, "__esModule", {
|
25 | value: true
|
26 | });
|
27 | exports.OverlayManager = void 0;
|
28 |
|
29 | class OverlayManager {
|
30 | #overlays = new WeakMap();
|
31 | #active = null;
|
32 |
|
33 | get active() {
|
34 | return this.#active;
|
35 | }
|
36 |
|
37 | async register(dialog, canForceClose = false) {
|
38 | if (typeof dialog !== "object") {
|
39 | throw new Error("Not enough parameters.");
|
40 | } else if (this.#overlays.has(dialog)) {
|
41 | throw new Error("The overlay is already registered.");
|
42 | }
|
43 |
|
44 | this.#overlays.set(dialog, {
|
45 | canForceClose
|
46 | });
|
47 | dialog.addEventListener("cancel", evt => {
|
48 | this.#active = null;
|
49 | });
|
50 | }
|
51 |
|
52 | async unregister(dialog) {
|
53 | if (!this.#overlays.has(dialog)) {
|
54 | throw new Error("The overlay does not exist.");
|
55 | } else if (this.#active === dialog) {
|
56 | throw new Error("The overlay cannot be removed while it is active.");
|
57 | }
|
58 |
|
59 | this.#overlays.delete(dialog);
|
60 | }
|
61 |
|
62 | async open(dialog) {
|
63 | if (!this.#overlays.has(dialog)) {
|
64 | throw new Error("The overlay does not exist.");
|
65 | } else if (this.#active) {
|
66 | if (this.#active === dialog) {
|
67 | throw new Error("The overlay is already active.");
|
68 | } else if (this.#overlays.get(dialog).canForceClose) {
|
69 | await this.close();
|
70 | } else {
|
71 | throw new Error("Another overlay is currently active.");
|
72 | }
|
73 | }
|
74 |
|
75 | this.#active = dialog;
|
76 | dialog.showModal();
|
77 | }
|
78 |
|
79 | async close(dialog = this.#active) {
|
80 | if (!this.#overlays.has(dialog)) {
|
81 | throw new Error("The overlay does not exist.");
|
82 | } else if (!this.#active) {
|
83 | throw new Error("The overlay is currently not active.");
|
84 | } else if (this.#active !== dialog) {
|
85 | throw new Error("Another overlay is currently active.");
|
86 | }
|
87 |
|
88 | dialog.close();
|
89 | this.#active = null;
|
90 | }
|
91 |
|
92 | }
|
93 |
|
94 | exports.OverlayManager = OverlayManager; |
\ | No newline at end of file |