@4i/modal-manager 1.0.73 → 1.0.80
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/package.json
CHANGED
@@ -1,7 +1,18 @@
|
|
1
1
|
import Manager from "./Manager";
|
2
|
+
interface QueueState {
|
3
|
+
queue: string[];
|
4
|
+
closedModalName?: string | undefined;
|
5
|
+
lastOpenedModal?: string | undefined;
|
6
|
+
}
|
7
|
+
interface ModalState {
|
8
|
+
isHaveOpenModals: boolean;
|
9
|
+
queue: string[];
|
10
|
+
closedModalName?: string | undefined;
|
11
|
+
lastOpenedModal?: string | undefined;
|
12
|
+
}
|
2
13
|
export declare class ModalManager extends Manager {
|
3
14
|
queue: string[];
|
4
|
-
_openModalStateCallback: null | ((
|
15
|
+
_openModalStateCallback: null | ((props: ModalState) => void);
|
5
16
|
constructor();
|
6
17
|
create<T>(name: string, payload: {
|
7
18
|
modalId: number;
|
@@ -9,8 +20,13 @@ export declare class ModalManager extends Manager {
|
|
9
20
|
}): void;
|
10
21
|
call<T>(name: string, data?: T): void;
|
11
22
|
close<T>(position?: T): void;
|
12
|
-
getQueueState():
|
13
|
-
|
23
|
+
getQueueState({ queue, closedModalName, lastOpenedModal }: QueueState): {
|
24
|
+
isHaveOpenModals: boolean;
|
25
|
+
queue: string[];
|
26
|
+
lastOpenedModal: string | undefined;
|
27
|
+
closedModalName: string | undefined;
|
28
|
+
};
|
29
|
+
onOpenModalState(callback: (state: ModalState) => void): void;
|
14
30
|
}
|
15
31
|
declare const modal: ModalManager;
|
16
32
|
export default modal;
|
@@ -44,19 +44,33 @@ var ModalManager = /** @class */ (function (_super) {
|
|
44
44
|
this.emitter.emit(constants.CHANGE, this.name, this.data);
|
45
45
|
};
|
46
46
|
ModalManager.prototype.call = function (name, data) {
|
47
|
+
var _a;
|
47
48
|
this.create(name, { modalId: uniqueID(), data: data });
|
49
|
+
var lastOpenedModal = name;
|
48
50
|
this.queue.push(name);
|
49
|
-
this._openModalStateCallback
|
50
|
-
this.
|
51
|
+
(_a = this._openModalStateCallback) === null || _a === void 0 ? void 0 : _a.call(this, this.getQueueState({
|
52
|
+
queue: this.queue,
|
53
|
+
lastOpenedModal: lastOpenedModal,
|
54
|
+
}));
|
51
55
|
};
|
52
56
|
ModalManager.prototype.close = function (position) {
|
57
|
+
var _a;
|
53
58
|
this.emitter.emit(constants.CLOSE, position);
|
59
|
+
var closedModalName = this.queue[this.queue.length - 1];
|
54
60
|
this.queue.pop();
|
55
|
-
this._openModalStateCallback
|
56
|
-
this.
|
61
|
+
(_a = this._openModalStateCallback) === null || _a === void 0 ? void 0 : _a.call(this, this.getQueueState({
|
62
|
+
queue: this.queue,
|
63
|
+
closedModalName: closedModalName,
|
64
|
+
}));
|
57
65
|
};
|
58
|
-
ModalManager.prototype.getQueueState = function () {
|
59
|
-
|
66
|
+
ModalManager.prototype.getQueueState = function (_a) {
|
67
|
+
var queue = _a.queue, closedModalName = _a.closedModalName, lastOpenedModal = _a.lastOpenedModal;
|
68
|
+
return {
|
69
|
+
isHaveOpenModals: queue.length > 0,
|
70
|
+
queue: queue,
|
71
|
+
lastOpenedModal: lastOpenedModal,
|
72
|
+
closedModalName: closedModalName,
|
73
|
+
};
|
60
74
|
};
|
61
75
|
ModalManager.prototype.onOpenModalState = function (callback) {
|
62
76
|
this._openModalStateCallback = callback;
|
@@ -9,9 +9,22 @@ const constants = {
|
|
9
9
|
CLOSE: "close",
|
10
10
|
};
|
11
11
|
|
12
|
+
interface QueueState {
|
13
|
+
queue: string[];
|
14
|
+
closedModalName?: string | undefined;
|
15
|
+
lastOpenedModal?: string | undefined;
|
16
|
+
}
|
17
|
+
|
18
|
+
interface ModalState {
|
19
|
+
isHaveOpenModals: boolean;
|
20
|
+
queue: string[];
|
21
|
+
closedModalName?: string | undefined;
|
22
|
+
lastOpenedModal?: string | undefined;
|
23
|
+
}
|
24
|
+
|
12
25
|
export class ModalManager extends Manager {
|
13
26
|
queue: string[] = [];
|
14
|
-
_openModalStateCallback: null | ((
|
27
|
+
_openModalStateCallback: null | ((props: ModalState) => void);
|
15
28
|
|
16
29
|
constructor() {
|
17
30
|
super();
|
@@ -29,23 +42,40 @@ export class ModalManager extends Manager {
|
|
29
42
|
|
30
43
|
call<T>(name: string, data?: T) {
|
31
44
|
this.create<T>(name, { modalId: uniqueID(), data });
|
45
|
+
const lastOpenedModal = name;
|
32
46
|
this.queue.push(name);
|
33
|
-
|
34
|
-
|
47
|
+
|
48
|
+
this._openModalStateCallback?.(
|
49
|
+
this.getQueueState({
|
50
|
+
queue: this.queue,
|
51
|
+
lastOpenedModal,
|
52
|
+
})
|
53
|
+
);
|
35
54
|
}
|
36
55
|
|
37
56
|
close<T>(position?: T) {
|
38
57
|
this.emitter.emit(constants.CLOSE, position);
|
58
|
+
const closedModalName = this.queue[this.queue.length - 1];
|
39
59
|
this.queue.pop();
|
40
|
-
|
41
|
-
|
60
|
+
|
61
|
+
this._openModalStateCallback?.(
|
62
|
+
this.getQueueState({
|
63
|
+
queue: this.queue,
|
64
|
+
closedModalName,
|
65
|
+
})
|
66
|
+
);
|
42
67
|
}
|
43
68
|
|
44
|
-
getQueueState() {
|
45
|
-
return
|
69
|
+
getQueueState({ queue, closedModalName, lastOpenedModal }: QueueState) {
|
70
|
+
return {
|
71
|
+
isHaveOpenModals: queue.length > 0,
|
72
|
+
queue,
|
73
|
+
lastOpenedModal: lastOpenedModal,
|
74
|
+
closedModalName,
|
75
|
+
};
|
46
76
|
}
|
47
77
|
|
48
|
-
onOpenModalState(callback: (state:
|
78
|
+
onOpenModalState(callback: (state: ModalState) => void) {
|
49
79
|
this._openModalStateCallback = callback;
|
50
80
|
}
|
51
81
|
}
|