nuance-ui 0.1.60 → 0.1.61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.json
CHANGED
|
@@ -16,19 +16,6 @@ export interface ModalState<Props extends object = object, Resolve = unknown, Re
|
|
|
16
16
|
/** Rejects the promise created when the modal was opened */
|
|
17
17
|
reject: (reason?: Reject) => void;
|
|
18
18
|
}
|
|
19
|
-
/**
|
|
20
|
-
* Modal manager.
|
|
21
|
-
*
|
|
22
|
-
* Maintains a component registry and a reactive map of active modals.
|
|
23
|
-
* Opening a modal returns a `Promise` that resolves via `hide`
|
|
24
|
-
* or rejects via `reject` / user dismissal.
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```ts
|
|
28
|
-
* const open = $modals.create<MyProps, string>('my-modal', MyModal)
|
|
29
|
-
* const result = await open({ foo: 'bar' }) // result: string
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
19
|
export declare class ModalManager {
|
|
33
20
|
#private;
|
|
34
21
|
/** Reactive map of active modals */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { markRaw, reactive } from "vue";
|
|
2
|
+
const GLOBAL_KEY = "__nui_modal_manager__";
|
|
2
3
|
export class ModalManager {
|
|
3
|
-
static #instance = null;
|
|
4
4
|
/** Reactive map of active modals */
|
|
5
5
|
modals = reactive(/* @__PURE__ */ new Map());
|
|
6
6
|
/** Eagerly registered components (id → Component) */
|
|
@@ -11,29 +11,29 @@ export class ModalManager {
|
|
|
11
11
|
}
|
|
12
12
|
// ── Facade ──
|
|
13
13
|
static get instance() {
|
|
14
|
-
if (!
|
|
15
|
-
|
|
16
|
-
return
|
|
14
|
+
if (!globalThis[GLOBAL_KEY])
|
|
15
|
+
globalThis[GLOBAL_KEY] = new ModalManager();
|
|
16
|
+
return globalThis[GLOBAL_KEY];
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* Registers a modal component and returns a typed function to open it.
|
|
20
20
|
*/
|
|
21
21
|
create(id, component) {
|
|
22
|
-
|
|
23
|
-
return (props) =>
|
|
22
|
+
this.#registered.set(id, component);
|
|
23
|
+
return (props) => this.#show(id, props ?? {});
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* Registers a lazy modal — the component is loaded on first open.
|
|
27
27
|
*/
|
|
28
28
|
createLazy(id, loader) {
|
|
29
|
-
|
|
30
|
-
return (props) =>
|
|
29
|
+
this.#lazy.set(id, loader);
|
|
30
|
+
return (props) => this.#show(id, props ?? {});
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
33
|
* Opens a previously registered modal by its identifier.
|
|
34
34
|
*/
|
|
35
35
|
async show(id, props = {}) {
|
|
36
|
-
return
|
|
36
|
+
return this.#show(id, props);
|
|
37
37
|
}
|
|
38
38
|
/**
|
|
39
39
|
* Closes the modal and resolves its promise with the given result.
|
|
@@ -42,7 +42,7 @@ export class ModalManager {
|
|
|
42
42
|
* @param result — value the promise resolves with
|
|
43
43
|
*/
|
|
44
44
|
resolve(id, result) {
|
|
45
|
-
|
|
45
|
+
this.#resolve(id, result);
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
48
|
* Closes the modal and rejects its promise with the given reason.
|
|
@@ -51,7 +51,7 @@ export class ModalManager {
|
|
|
51
51
|
* @param reason — rejection reason
|
|
52
52
|
*/
|
|
53
53
|
reject(id, reason) {
|
|
54
|
-
|
|
54
|
+
this.#reject(id, reason);
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
57
|
* Returns the reactive state of a specific modal as `ComputedRef<ModalState>`.
|
|
@@ -59,7 +59,7 @@ export class ModalManager {
|
|
|
59
59
|
* Used inside a modal component (via {@link useModal}).
|
|
60
60
|
*/
|
|
61
61
|
state(id) {
|
|
62
|
-
return
|
|
62
|
+
return this.modals.get(id);
|
|
63
63
|
}
|
|
64
64
|
// ── Private implementation ──
|
|
65
65
|
async #show(id, props = {}) {
|