@4i/modal-manager 1.0.31 → 1.0.40

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@4i/modal-manager",
3
- "version": "1.0.31",
3
+ "version": "1.0.40",
4
4
  "description": "",
5
5
  "main": "src/index.ts",
6
6
  "scripts": {
package/readme.md CHANGED
@@ -13,6 +13,10 @@ This package simplifies the management of multiple modals, popups, notifications
13
13
  npm install @4i/modal-manager
14
14
  ```
15
15
 
16
+ ## Example
17
+
18
+ <a href="https://codesandbox.io/p/github/tonichiga/modal-manager-example/main?layout=%257B%2522sidebarPanel%2522%253A%2522GIT%2522%252C%2522rootPanelGroup%2522%253A%257B%2522direction%2522%253A%2522horizontal%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522id%2522%253A%2522ROOT_LAYOUT%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522UNKNOWN%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522clsnqfzod00063p6le9554u03%2522%252C%2522sizes%2522%253A%255B70%252C30%255D%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522EDITOR%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522EDITOR%2522%252C%2522id%2522%253A%2522clsnqfzod00023p6lo9e5ocrg%2522%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522direction%2522%253A%2522horizontal%2522%252C%2522id%2522%253A%2522SHELLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522SHELLS%2522%252C%2522id%2522%253A%2522clsnqfzod00043p6l5kpjziav%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%257D%252C%257B%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522direction%2522%253A%2522vertical%2522%252C%2522id%2522%253A%2522DEVTOOLS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522contentType%2522%253A%2522DEVTOOLS%2522%252C%2522id%2522%253A%2522clsnqfzod00053p6lleknh8sj%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%255D%252C%2522sizes%2522%253A%255B50%252C50%255D%257D%252C%2522tabbedPanels%2522%253A%257B%2522clsnqfzod00023p6lo9e5ocrg%2522%253A%257B%2522id%2522%253A%2522clsnqfzod00023p6lo9e5ocrg%2522%252C%2522tabs%2522%253A%255B%255D%257D%252C%2522clsnqfzod00053p6lleknh8sj%2522%253A%257B%2522id%2522%253A%2522clsnqfzod00053p6lleknh8sj%2522%252C%2522activeTabId%2522%253A%2522clsnqihgr00ht3p6l2nn59nq5%2522%252C%2522tabs%2522%253A%255B%257B%2522type%2522%253A%2522TASK_PORT%2522%252C%2522taskId%2522%253A%2522dev%2522%252C%2522port%2522%253A3000%252C%2522id%2522%253A%2522clsnqihgr00ht3p6l2nn59nq5%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522path%2522%253A%2522%252F%2522%257D%255D%257D%252C%2522clsnqfzod00043p6l5kpjziav%2522%253A%257B%2522id%2522%253A%2522clsnqfzod00043p6l5kpjziav%2522%252C%2522activeTabId%2522%253A%2522clsnqojb3003j3p6m98yg0rzn%2522%252C%2522tabs%2522%253A%255B%257B%2522type%2522%253A%2522TASK_LOG%2522%252C%2522taskId%2522%253A%2522dev%2522%252C%2522id%2522%253A%2522clsnqh362007k3p6lgb90p583%2522%252C%2522mode%2522%253A%2522permanent%2522%257D%252C%257B%2522id%2522%253A%2522clsnqojb3003j3p6m98yg0rzn%2522%252C%2522mode%2522%253A%2522permanent%2522%252C%2522type%2522%253A%2522TERMINAL%2522%252C%2522shellId%2522%253A%2522clsnqojh1001mdjig37kbat9k%2522%257D%255D%257D%257D%252C%2522showDevtools%2522%253Atrue%252C%2522showShells%2522%253Atrue%252C%2522showSidebar%2522%253Atrue%252C%2522sidebarPanelSize%2522%253A15%257D">Codesandbox</a>
19
+
16
20
  ## Usage
17
21
 
18
22
  #### Instance methods:
@@ -1,6 +1,7 @@
1
1
  import Manager from "./Manager";
2
2
  declare class ModalManager extends Manager {
3
3
  queue: string[];
4
+ _openModalStateCallback: null | ((state: boolean) => void);
4
5
  constructor();
5
6
  create<T>(name: string, payload: {
6
7
  modalId: number;
@@ -8,6 +9,7 @@ declare class ModalManager extends Manager {
8
9
  }): void;
9
10
  call<T>(name: string, data?: T): void;
10
11
  close<T>(position?: T): void;
12
+ getQueueState(): boolean;
11
13
  onOpenModalState(callback: (state: boolean) => void): void;
12
14
  }
13
15
  declare const modal: ModalManager;
@@ -34,6 +34,7 @@ var ModalManager = /** @class */ (function (_super) {
34
34
  _this.create = _this.create.bind(_this);
35
35
  _this.call = _this.call.bind(_this);
36
36
  _this.close = _this.close.bind(_this);
37
+ _this._openModalStateCallback = null;
37
38
  return _this;
38
39
  }
39
40
  ModalManager.prototype.create = function (name, payload) {
@@ -44,13 +45,20 @@ var ModalManager = /** @class */ (function (_super) {
44
45
  ModalManager.prototype.call = function (name, data) {
45
46
  this.create(name, { modalId: uniqueID(), data: data });
46
47
  this.queue.push(name);
48
+ this._openModalStateCallback &&
49
+ this._openModalStateCallback(this.getQueueState());
47
50
  };
48
51
  ModalManager.prototype.close = function (position) {
49
52
  this.emitter.emit(constants.CLOSE, position);
50
53
  this.queue.pop();
54
+ this._openModalStateCallback &&
55
+ this._openModalStateCallback(this.getQueueState());
56
+ };
57
+ ModalManager.prototype.getQueueState = function () {
58
+ return this.queue.length > 0;
51
59
  };
52
60
  ModalManager.prototype.onOpenModalState = function (callback) {
53
- callback(this.queue.length > 0);
61
+ this._openModalStateCallback = callback;
54
62
  };
55
63
  return ModalManager;
56
64
  }(Manager_1.default));
@@ -11,12 +11,14 @@ const constants = {
11
11
 
12
12
  class ModalManager extends Manager {
13
13
  queue: string[] = [];
14
+ _openModalStateCallback: null | ((state: boolean) => void);
14
15
 
15
16
  constructor() {
16
17
  super();
17
18
  this.create = this.create.bind(this);
18
19
  this.call = this.call.bind(this);
19
20
  this.close = this.close.bind(this);
21
+ this._openModalStateCallback = null;
20
22
  }
21
23
 
22
24
  create<T>(name: string, payload: { modalId: number; data?: T }) {
@@ -28,15 +30,23 @@ class ModalManager extends Manager {
28
30
  call<T>(name: string, data?: T) {
29
31
  this.create<T>(name, { modalId: uniqueID(), data });
30
32
  this.queue.push(name);
33
+ this._openModalStateCallback &&
34
+ this._openModalStateCallback(this.getQueueState());
31
35
  }
32
36
 
33
37
  close<T>(position?: T) {
34
38
  this.emitter.emit(constants.CLOSE, position);
35
39
  this.queue.pop();
40
+ this._openModalStateCallback &&
41
+ this._openModalStateCallback(this.getQueueState());
42
+ }
43
+
44
+ getQueueState() {
45
+ return this.queue.length > 0;
36
46
  }
37
47
 
38
48
  onOpenModalState(callback: (state: boolean) => void) {
39
- callback(this.queue.length > 0);
49
+ this._openModalStateCallback = callback;
40
50
  }
41
51
  }
42
52