chayns-api 3.0.1 → 3.1.0-beta.1

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.
Files changed (142) hide show
  1. package/dist/cjs/calls/index.js +4 -1
  2. package/dist/cjs/calls/visibilityChangeListener.js +4 -4
  3. package/dist/cjs/components/ChaynsProvider.js +34 -6
  4. package/dist/cjs/components/withHydrationBoundary.js +2 -2
  5. package/dist/cjs/constants/index.js +0 -22
  6. package/dist/cjs/contexts/HistoryLayerContext.js +89 -0
  7. package/dist/cjs/contexts/index.js +38 -0
  8. package/dist/cjs/handler/history/FrameHistoryLayer.js +100 -0
  9. package/dist/cjs/handler/history/HistoryLayer.js +321 -0
  10. package/dist/cjs/handler/history/index.js +19 -0
  11. package/dist/cjs/hooks/history.js +454 -0
  12. package/dist/cjs/hooks/index.js +62 -1
  13. package/dist/cjs/host/ChaynsHost.js +113 -54
  14. package/dist/cjs/host/iframe/HostIframe.js +70 -5
  15. package/dist/cjs/host/module/ModuleHost.js +50 -44
  16. package/dist/cjs/index.js +139 -6
  17. package/dist/cjs/types/history.js +1 -0
  18. package/dist/cjs/umd.index.js +2 -2
  19. package/dist/cjs/utils/EventBus.js +33 -0
  20. package/dist/cjs/{util → utils}/appStorage.js +2 -2
  21. package/dist/cjs/utils/equality.js +19 -0
  22. package/dist/cjs/utils/history/BlockRegistry.js +153 -0
  23. package/dist/cjs/utils/history/NavigationQueue.js +389 -0
  24. package/dist/cjs/utils/history/layerTree.js +32 -0
  25. package/dist/cjs/utils/history/nativeBackHandling.js +61 -0
  26. package/dist/cjs/utils/history/navigationIndex.js +74 -0
  27. package/dist/cjs/utils/history/rootLayer.js +213 -0
  28. package/dist/cjs/utils/history/segments.js +15 -0
  29. package/dist/cjs/utils/history/stateProjector.js +156 -0
  30. package/dist/cjs/utils/history/url.js +47 -0
  31. package/dist/cjs/utils/history/window.js +9 -0
  32. package/dist/cjs/wrapper/AppWrapper.js +24 -24
  33. package/dist/cjs/wrapper/FrameWrapper.js +35 -2
  34. package/dist/cjs/wrapper/ModuleFederationWrapper.js +2 -0
  35. package/dist/cjs/wrapper/StaticChaynsApi.js +1 -1
  36. package/dist/esm/calls/index.js +2 -0
  37. package/dist/esm/calls/visibilityChangeListener.js +1 -1
  38. package/dist/esm/components/ChaynsProvider.js +34 -6
  39. package/dist/esm/components/withHydrationBoundary.js +1 -1
  40. package/dist/esm/constants/index.js +1 -3
  41. package/dist/esm/contexts/HistoryLayerContext.js +76 -0
  42. package/dist/esm/contexts/index.js +3 -0
  43. package/dist/esm/handler/history/FrameHistoryLayer.js +105 -0
  44. package/dist/esm/handler/history/HistoryLayer.js +321 -0
  45. package/dist/esm/handler/history/index.js +2 -0
  46. package/dist/esm/hooks/history.js +428 -0
  47. package/dist/esm/hooks/index.js +2 -1
  48. package/dist/esm/host/ChaynsHost.js +113 -54
  49. package/dist/esm/host/iframe/HostIframe.js +70 -5
  50. package/dist/esm/host/module/ModuleHost.js +50 -44
  51. package/dist/esm/index.js +15 -6
  52. package/dist/esm/types/history.js +1 -0
  53. package/dist/esm/umd.index.js +2 -2
  54. package/dist/esm/utils/EventBus.js +31 -0
  55. package/dist/esm/{util → utils}/appStorage.js +1 -1
  56. package/dist/esm/utils/equality.js +12 -0
  57. package/dist/esm/utils/history/BlockRegistry.js +151 -0
  58. package/dist/esm/utils/history/NavigationQueue.js +386 -0
  59. package/dist/esm/utils/history/layerTree.js +24 -0
  60. package/dist/esm/utils/history/nativeBackHandling.js +59 -0
  61. package/dist/esm/utils/history/navigationIndex.js +62 -0
  62. package/dist/esm/utils/history/rootLayer.js +205 -0
  63. package/dist/esm/utils/history/segments.js +7 -0
  64. package/dist/esm/utils/history/stateProjector.js +147 -0
  65. package/dist/esm/utils/history/url.js +40 -0
  66. package/dist/esm/utils/history/window.js +3 -0
  67. package/dist/esm/wrapper/AppWrapper.js +6 -6
  68. package/dist/esm/wrapper/FrameWrapper.js +35 -2
  69. package/dist/esm/wrapper/ModuleFederationWrapper.js +2 -0
  70. package/dist/esm/wrapper/StaticChaynsApi.js +2 -1
  71. package/dist/types/calls/index.d.ts +5 -0
  72. package/dist/types/components/ChaynsProvider.d.ts +21 -0
  73. package/dist/types/constants/index.d.ts +0 -2
  74. package/dist/types/contexts/HistoryLayerContext.d.ts +33 -0
  75. package/dist/types/contexts/index.d.ts +3 -0
  76. package/dist/types/handler/history/FrameHistoryLayer.d.ts +99 -0
  77. package/dist/types/handler/history/HistoryLayer.d.ts +117 -0
  78. package/dist/types/handler/history/index.d.ts +2 -0
  79. package/dist/types/hooks/history.d.ts +89 -0
  80. package/dist/types/hooks/index.d.ts +1 -0
  81. package/dist/types/host/ChaynsHost.d.ts +12 -0
  82. package/dist/types/host/iframe/HostIframe.d.ts +4 -0
  83. package/dist/types/host/module/ModuleHost.d.ts +4 -0
  84. package/dist/types/index.d.ts +15 -6
  85. package/dist/types/types/IChaynsReact.d.ts +3 -0
  86. package/dist/types/types/history.d.ts +74 -0
  87. package/dist/types/umd.index.d.ts +2 -2
  88. package/dist/types/utils/EventBus.d.ts +10 -0
  89. package/dist/types/{util → utils}/collectCssChunks.d.ts +1 -1
  90. package/dist/types/utils/equality.d.ts +2 -0
  91. package/dist/types/utils/history/BlockRegistry.d.ts +45 -0
  92. package/dist/types/utils/history/NavigationQueue.d.ts +118 -0
  93. package/dist/types/utils/history/layerTree.d.ts +10 -0
  94. package/dist/types/utils/history/nativeBackHandling.d.ts +47 -0
  95. package/dist/types/utils/history/navigationIndex.d.ts +17 -0
  96. package/dist/types/utils/history/rootLayer.d.ts +42 -0
  97. package/dist/types/utils/history/segments.d.ts +2 -0
  98. package/dist/types/utils/history/stateProjector.d.ts +24 -0
  99. package/dist/types/utils/history/url.d.ts +17 -0
  100. package/dist/types/utils/history/window.d.ts +1 -0
  101. package/dist/types/wrapper/FrameWrapper.d.ts +1 -0
  102. package/dist/types/wrapper/StaticChaynsApi.d.ts +1 -0
  103. package/package.json +2 -1
  104. /package/dist/cjs/{constants → contexts}/hydrationContext.js +0 -0
  105. /package/dist/cjs/{constants → contexts}/moduleContext.js +0 -0
  106. /package/dist/cjs/{helper/apiListenerHelper.js → utils/apiListener.js} +0 -0
  107. /package/dist/cjs/{util → utils}/appCall.js +0 -0
  108. /package/dist/cjs/{util → utils}/bindChaynsApi.js +0 -0
  109. /package/dist/cjs/{util → utils}/collectCssChunks.js +0 -0
  110. /package/dist/cjs/{util → utils}/deviceHelper.js +0 -0
  111. /package/dist/cjs/{util → utils}/heightHelper.js +0 -0
  112. /package/dist/cjs/{util → utils}/initModuleFederationSharing.js +0 -0
  113. /package/dist/cjs/{util → utils}/is.js +0 -0
  114. /package/dist/cjs/{util → utils}/postIframeForm.js +0 -0
  115. /package/dist/cjs/{util → utils}/transferNestedFunctions.js +0 -0
  116. /package/dist/cjs/{util → utils}/url.js +0 -0
  117. /package/dist/esm/{constants → contexts}/hydrationContext.js +0 -0
  118. /package/dist/esm/{constants → contexts}/moduleContext.js +0 -0
  119. /package/dist/esm/{helper/apiListenerHelper.js → utils/apiListener.js} +0 -0
  120. /package/dist/esm/{util → utils}/appCall.js +0 -0
  121. /package/dist/esm/{util → utils}/bindChaynsApi.js +0 -0
  122. /package/dist/esm/{util → utils}/collectCssChunks.js +0 -0
  123. /package/dist/esm/{util → utils}/deviceHelper.js +0 -0
  124. /package/dist/esm/{util → utils}/heightHelper.js +0 -0
  125. /package/dist/esm/{util → utils}/initModuleFederationSharing.js +0 -0
  126. /package/dist/esm/{util → utils}/is.js +0 -0
  127. /package/dist/esm/{util → utils}/postIframeForm.js +0 -0
  128. /package/dist/esm/{util → utils}/transferNestedFunctions.js +0 -0
  129. /package/dist/esm/{util → utils}/url.js +0 -0
  130. /package/dist/types/{constants → contexts}/hydrationContext.d.ts +0 -0
  131. /package/dist/types/{constants → contexts}/moduleContext.d.ts +0 -0
  132. /package/dist/types/{helper/apiListenerHelper.d.ts → utils/apiListener.d.ts} +0 -0
  133. /package/dist/types/{util → utils}/appCall.d.ts +0 -0
  134. /package/dist/types/{util → utils}/appStorage.d.ts +0 -0
  135. /package/dist/types/{util → utils}/bindChaynsApi.d.ts +0 -0
  136. /package/dist/types/{util → utils}/deviceHelper.d.ts +0 -0
  137. /package/dist/types/{util → utils}/heightHelper.d.ts +0 -0
  138. /package/dist/types/{util → utils}/initModuleFederationSharing.d.ts +0 -0
  139. /package/dist/types/{util → utils}/is.d.ts +0 -0
  140. /package/dist/types/{util → utils}/postIframeForm.d.ts +0 -0
  141. /package/dist/types/{util → utils}/transferNestedFunctions.d.ts +0 -0
  142. /package/dist/types/{util → utils}/url.d.ts +0 -0
package/dist/cjs/index.js CHANGED
@@ -15,9 +15,28 @@ var _exportNames = {
15
15
  loadComponent: true,
16
16
  loadModule: true,
17
17
  DialogHandler: true,
18
+ initRootChaynsHistoryLayer: true,
19
+ getOrInitRootChaynsHistoryLayer: true,
20
+ NavigationQueue: true,
21
+ BlockRegistry: true,
22
+ projectToUrl: true,
23
+ parseFromUrl: true,
24
+ projectToState: true,
25
+ applyStateToTree: true,
26
+ diffIncomingState: true,
27
+ hasChaynsHistoryState: true,
28
+ getChaynsHistoryActiveChain: true,
29
+ findChaynsHistoryLayerById: true,
30
+ isInChaynsHistoryActiveChain: true,
18
31
  dialog: true,
19
32
  getChaynsApi: true
20
33
  };
34
+ Object.defineProperty(exports, "BlockRegistry", {
35
+ enumerable: true,
36
+ get: function () {
37
+ return _BlockRegistry.BlockRegistry;
38
+ }
39
+ });
21
40
  Object.defineProperty(exports, "ChaynsHost", {
22
41
  enumerable: true,
23
42
  get: function () {
@@ -36,19 +55,49 @@ Object.defineProperty(exports, "DialogHandler", {
36
55
  return _DialogHandler.default;
37
56
  }
38
57
  });
58
+ Object.defineProperty(exports, "NavigationQueue", {
59
+ enumerable: true,
60
+ get: function () {
61
+ return _NavigationQueue.NavigationQueue;
62
+ }
63
+ });
39
64
  Object.defineProperty(exports, "StaticChaynsApi", {
40
65
  enumerable: true,
41
66
  get: function () {
42
67
  return _StaticChaynsApi.default;
43
68
  }
44
69
  });
70
+ Object.defineProperty(exports, "applyStateToTree", {
71
+ enumerable: true,
72
+ get: function () {
73
+ return _stateProjector.applyStateToTree;
74
+ }
75
+ });
45
76
  exports.dialog = void 0;
77
+ Object.defineProperty(exports, "diffIncomingState", {
78
+ enumerable: true,
79
+ get: function () {
80
+ return _stateProjector.diffIncomingState;
81
+ }
82
+ });
83
+ Object.defineProperty(exports, "findChaynsHistoryLayerById", {
84
+ enumerable: true,
85
+ get: function () {
86
+ return _layerTree.findChaynsHistoryLayerById;
87
+ }
88
+ });
46
89
  Object.defineProperty(exports, "getChaynsApi", {
47
90
  enumerable: true,
48
91
  get: function () {
49
92
  return _moduleWrapper.getChaynsApi;
50
93
  }
51
94
  });
95
+ Object.defineProperty(exports, "getChaynsHistoryActiveChain", {
96
+ enumerable: true,
97
+ get: function () {
98
+ return _layerTree.getChaynsHistoryActiveChain;
99
+ }
100
+ });
52
101
  Object.defineProperty(exports, "getClientDeviceInfo", {
53
102
  enumerable: true,
54
103
  get: function () {
@@ -61,12 +110,36 @@ Object.defineProperty(exports, "getDeviceInfo", {
61
110
  return _deviceHelper.default;
62
111
  }
63
112
  });
113
+ Object.defineProperty(exports, "getOrInitRootChaynsHistoryLayer", {
114
+ enumerable: true,
115
+ get: function () {
116
+ return _rootLayer.getOrInitRootChaynsHistoryLayer;
117
+ }
118
+ });
64
119
  Object.defineProperty(exports, "getScreenSize", {
65
120
  enumerable: true,
66
121
  get: function () {
67
122
  return _deviceHelper.getScreenSize;
68
123
  }
69
124
  });
125
+ Object.defineProperty(exports, "hasChaynsHistoryState", {
126
+ enumerable: true,
127
+ get: function () {
128
+ return _stateProjector.hasChaynsHistoryState;
129
+ }
130
+ });
131
+ Object.defineProperty(exports, "initRootChaynsHistoryLayer", {
132
+ enumerable: true,
133
+ get: function () {
134
+ return _rootLayer.initRootChaynsHistoryLayer;
135
+ }
136
+ });
137
+ Object.defineProperty(exports, "isInChaynsHistoryActiveChain", {
138
+ enumerable: true,
139
+ get: function () {
140
+ return _layerTree.isInChaynsHistoryActiveChain;
141
+ }
142
+ });
70
143
  Object.defineProperty(exports, "loadComponent", {
71
144
  enumerable: true,
72
145
  get: function () {
@@ -79,6 +152,24 @@ Object.defineProperty(exports, "loadModule", {
79
152
  return _loadComponent.loadModule;
80
153
  }
81
154
  });
155
+ Object.defineProperty(exports, "parseFromUrl", {
156
+ enumerable: true,
157
+ get: function () {
158
+ return _url.parseFromUrl;
159
+ }
160
+ });
161
+ Object.defineProperty(exports, "projectToState", {
162
+ enumerable: true,
163
+ get: function () {
164
+ return _stateProjector.projectToState;
165
+ }
166
+ });
167
+ Object.defineProperty(exports, "projectToUrl", {
168
+ enumerable: true,
169
+ get: function () {
170
+ return _url.projectToUrl;
171
+ }
172
+ });
82
173
  Object.defineProperty(exports, "withCompatMode", {
83
174
  enumerable: true,
84
175
  get: function () {
@@ -92,7 +183,7 @@ Object.defineProperty(exports, "withHydrationBoundary", {
92
183
  }
93
184
  });
94
185
  var _ChaynsProvider = _interopRequireDefault(require("./components/ChaynsProvider"));
95
- var _deviceHelper = _interopRequireWildcard(require("./util/deviceHelper"));
186
+ var _deviceHelper = _interopRequireWildcard(require("./utils/deviceHelper"));
96
187
  var _ChaynsHost = _interopRequireDefault(require("./host/ChaynsHost"));
97
188
  var _withCompatMode = require("./components/withCompatMode");
98
189
  var _calls = require("./calls");
@@ -143,7 +234,19 @@ Object.keys(_IChaynsReact).forEach(function (key) {
143
234
  }
144
235
  });
145
236
  });
146
- var _is = require("./util/is");
237
+ var _history = require("./types/history");
238
+ Object.keys(_history).forEach(function (key) {
239
+ if (key === "default" || key === "__esModule") return;
240
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
241
+ if (key in exports && exports[key] === _history[key]) return;
242
+ Object.defineProperty(exports, key, {
243
+ enumerable: true,
244
+ get: function () {
245
+ return _history[key];
246
+ }
247
+ });
248
+ });
249
+ var _is = require("./utils/is");
147
250
  Object.keys(_is).forEach(function (key) {
148
251
  if (key === "default" || key === "__esModule") return;
149
252
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
@@ -171,6 +274,24 @@ var _withHydrationBoundary = _interopRequireDefault(require("./components/withHy
171
274
  var _StaticChaynsApi = _interopRequireDefault(require("./wrapper/StaticChaynsApi"));
172
275
  var _loadComponent = _interopRequireWildcard(require("./host/module/utils/loadComponent"));
173
276
  var _DialogHandler = _interopRequireDefault(require("./handler/DialogHandler"));
277
+ var _history2 = require("./handler/history");
278
+ Object.keys(_history2).forEach(function (key) {
279
+ if (key === "default" || key === "__esModule") return;
280
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
281
+ if (key in exports && exports[key] === _history2[key]) return;
282
+ Object.defineProperty(exports, key, {
283
+ enumerable: true,
284
+ get: function () {
285
+ return _history2[key];
286
+ }
287
+ });
288
+ });
289
+ var _rootLayer = require("./utils/history/rootLayer");
290
+ var _NavigationQueue = require("./utils/history/NavigationQueue");
291
+ var _BlockRegistry = require("./utils/history/BlockRegistry");
292
+ var _url = require("./utils/history/url");
293
+ var _stateProjector = require("./utils/history/stateProjector");
294
+ var _layerTree = require("./utils/history/layerTree");
174
295
  var _dialog = _interopRequireWildcard(require("./calls/dialogs/index"));
175
296
  exports.dialog = _dialog;
176
297
  var _plugins = require("./plugins");
@@ -185,7 +306,7 @@ Object.keys(_plugins).forEach(function (key) {
185
306
  }
186
307
  });
187
308
  });
188
- var _initModuleFederationSharing = require("./util/initModuleFederationSharing");
309
+ var _initModuleFederationSharing = require("./utils/initModuleFederationSharing");
189
310
  Object.keys(_initModuleFederationSharing).forEach(function (key) {
190
311
  if (key === "default" || key === "__esModule") return;
191
312
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
@@ -197,7 +318,7 @@ Object.keys(_initModuleFederationSharing).forEach(function (key) {
197
318
  }
198
319
  });
199
320
  });
200
- var _bindChaynsApi = require("./util/bindChaynsApi");
321
+ var _bindChaynsApi = require("./utils/bindChaynsApi");
201
322
  Object.keys(_bindChaynsApi).forEach(function (key) {
202
323
  if (key === "default" || key === "__esModule") return;
203
324
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
@@ -209,7 +330,7 @@ Object.keys(_bindChaynsApi).forEach(function (key) {
209
330
  }
210
331
  });
211
332
  });
212
- var _appStorage = require("./util/appStorage");
333
+ var _appStorage = require("./utils/appStorage");
213
334
  Object.keys(_appStorage).forEach(function (key) {
214
335
  if (key === "default" || key === "__esModule") return;
215
336
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
@@ -221,7 +342,7 @@ Object.keys(_appStorage).forEach(function (key) {
221
342
  }
222
343
  });
223
344
  });
224
- var _collectCssChunks = require("./util/collectCssChunks");
345
+ var _collectCssChunks = require("./utils/collectCssChunks");
225
346
  Object.keys(_collectCssChunks).forEach(function (key) {
226
347
  if (key === "default" || key === "__esModule") return;
227
348
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
@@ -233,6 +354,18 @@ Object.keys(_collectCssChunks).forEach(function (key) {
233
354
  }
234
355
  });
235
356
  });
357
+ var _contexts = require("./contexts");
358
+ Object.keys(_contexts).forEach(function (key) {
359
+ if (key === "default" || key === "__esModule") return;
360
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
361
+ if (key in exports && exports[key] === _contexts[key]) return;
362
+ Object.defineProperty(exports, key, {
363
+ enumerable: true,
364
+ get: function () {
365
+ return _contexts[key];
366
+ }
367
+ });
368
+ });
236
369
  var _moduleWrapper = require("./components/moduleWrapper");
237
370
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
238
371
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -0,0 +1 @@
1
+ "use strict";
@@ -42,7 +42,7 @@ Object.defineProperty(exports, "getScreenSize", {
42
42
  return _deviceHelper.getScreenSize;
43
43
  }
44
44
  });
45
- var _deviceHelper = _interopRequireWildcard(require("./util/deviceHelper"));
45
+ var _deviceHelper = _interopRequireWildcard(require("./utils/deviceHelper"));
46
46
  var _calls = require("./calls");
47
47
  Object.keys(_calls).forEach(function (key) {
48
48
  if (key === "default" || key === "__esModule") return;
@@ -67,7 +67,7 @@ Object.keys(_IChaynsReact).forEach(function (key) {
67
67
  }
68
68
  });
69
69
  });
70
- var _is = require("./util/is");
70
+ var _is = require("./utils/is");
71
71
  Object.keys(_is).forEach(function (key) {
72
72
  if (key === "default" || key === "__esModule") return;
73
73
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.EventBus = void 0;
7
+ class EventBus {
8
+ listeners = new Map();
9
+ on(type, handler) {
10
+ let set = this.listeners.get(type);
11
+ if (!set) {
12
+ set = new Set();
13
+ this.listeners.set(type, set);
14
+ }
15
+ set.add(handler);
16
+ return () => set.delete(handler);
17
+ }
18
+ emit(type, event) {
19
+ const set = this.listeners.get(type);
20
+ if (!set) return;
21
+ for (const fn of [...set]) {
22
+ try {
23
+ fn(event);
24
+ } catch (err) {
25
+ console.error('[chaynsHistory] listener threw', err);
26
+ }
27
+ }
28
+ }
29
+ clear() {
30
+ this.listeners.clear();
31
+ }
32
+ }
33
+ exports.EventBus = EventBus;
@@ -9,7 +9,7 @@ exports.getAppStorageItem = getAppStorageItem;
9
9
  exports.isAppStorageAvailable = isAppStorageAvailable;
10
10
  exports.removeAppStorageItem = removeAppStorageItem;
11
11
  exports.setAppStorageItem = setAppStorageItem;
12
- var _apiListenerHelper = require("../helper/apiListenerHelper");
12
+ var _apiListener = require("./apiListener");
13
13
  var _IChaynsReact = require("../types/IChaynsReact");
14
14
  function isAppStorageAvailable() {
15
15
  var _this$values$device$a, _this$values$device$a2;
@@ -83,7 +83,7 @@ async function addAppStorageListener(storeName, prefix, callback, callbackPrefix
83
83
  const callbackName = `${callbackPrefix}_${this.counter++}`;
84
84
  const {
85
85
  shouldInitialize
86
- } = (0, _apiListenerHelper.addApiListener)(`appStorageListener/${storeName}`, callback);
86
+ } = (0, _apiListener.addApiListener)(`appStorageListener/${storeName}`, callback);
87
87
  const handleValue = value => {
88
88
  var _value$key;
89
89
  if (value.action === 0 && (_value$key = value.key) !== null && _value$key !== void 0 && _value$key.startsWith(prefix)) {
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.shallowEqualArr = shallowEqualArr;
7
+ exports.shallowEqualObj = shallowEqualObj;
8
+ function shallowEqualArr(a, b) {
9
+ if (a.length !== b.length) return false;
10
+ for (let i = 0; i < a.length; i++) if (a[i] !== b[i]) return false;
11
+ return true;
12
+ }
13
+ function shallowEqualObj(a, b) {
14
+ const ak = Object.keys(a);
15
+ const bk = Object.keys(b);
16
+ if (ak.length !== bk.length) return false;
17
+ for (const k of ak) if (a[k] !== b[k]) return false;
18
+ return true;
19
+ }
@@ -0,0 +1,153 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.BlockRegistry = void 0;
7
+ const BLOCK_TIMEOUT_MS = 30000;
8
+ let _nextId = 1;
9
+ class BlockRegistry {
10
+ layerBlocks = new Map();
11
+ changeListeners = new Set();
12
+ beforeUnloadCount = 0;
13
+ beforeUnloadHandler = e => {
14
+ e.preventDefault();
15
+ Reflect.set(e, 'returnValue', '');
16
+ };
17
+ add(layer, callback, opts = {}) {
18
+ var _opts$scope, _opts$isBeforeUnload;
19
+ const entry = {
20
+ id: String(_nextId++),
21
+ callback,
22
+ opts: {
23
+ scope: (_opts$scope = opts.scope) !== null && _opts$scope !== void 0 ? _opts$scope : 'local',
24
+ isBeforeUnload: (_opts$isBeforeUnload = opts.isBeforeUnload) !== null && _opts$isBeforeUnload !== void 0 ? _opts$isBeforeUnload : false
25
+ }
26
+ };
27
+ let set = this.layerBlocks.get(layer.id);
28
+ if (!set) {
29
+ set = new Set();
30
+ this.layerBlocks.set(layer.id, set);
31
+ }
32
+ set.add(entry);
33
+ if (entry.opts.isBeforeUnload) {
34
+ this.incrementBeforeUnload();
35
+ }
36
+ this.notifyChange();
37
+ return () => this.remove(layer.id, entry);
38
+ }
39
+ remove(layerId, entry) {
40
+ const set = this.layerBlocks.get(layerId);
41
+ if (!set) return;
42
+ const didDelete = set.delete(entry);
43
+ if (!didDelete) return;
44
+ if (set.size === 0) this.layerBlocks.delete(layerId);
45
+ if (entry.opts.isBeforeUnload) {
46
+ this.decrementBeforeUnload();
47
+ }
48
+ this.notifyChange();
49
+ }
50
+ removeAllForLayer(layerId) {
51
+ const set = this.layerBlocks.get(layerId);
52
+ if (!set) return;
53
+ for (const entry of set) {
54
+ if (entry.opts.isBeforeUnload) this.decrementBeforeUnload();
55
+ }
56
+ this.layerBlocks.delete(layerId);
57
+ this.notifyChange();
58
+ }
59
+ subscribeToChanges(listener) {
60
+ this.changeListeners.add(listener);
61
+ return () => {
62
+ this.changeListeners.delete(listener);
63
+ };
64
+ }
65
+ collectApplicableBlocks(targetLayer) {
66
+ const result = [];
67
+ const localSet = this.layerBlocks.get(targetLayer.id);
68
+ if (localSet) {
69
+ for (const entry of localSet) {
70
+ result.push(entry);
71
+ }
72
+ }
73
+ this.collectGlobalFromActiveDescendants(targetLayer, result);
74
+ return result;
75
+ }
76
+ hasActiveBlocks(rootLayer) {
77
+ return this.collectActiveChainBlocks(rootLayer).length > 0;
78
+ }
79
+ async checkActiveBlocks(rootLayer) {
80
+ const blocks = this.collectActiveChainBlocks(rootLayer);
81
+ if (blocks.length === 0) return true;
82
+ const results = await Promise.all(blocks.map(b => this.runBlock(b)));
83
+ return results.every(Boolean);
84
+ }
85
+ collectActiveChainBlocks(rootLayer) {
86
+ const result = [];
87
+ this.collectFromActiveChain(rootLayer, result);
88
+ return result;
89
+ }
90
+ collectGlobalFromActiveDescendants(layer, out) {
91
+ const activeChildId = layer.getActiveChildId();
92
+ if (!activeChildId) return;
93
+ const child = layer.getChildLayer(activeChildId);
94
+ if (!child) return;
95
+ const childSet = this.layerBlocks.get(child.id);
96
+ if (childSet) {
97
+ for (const entry of childSet) {
98
+ if (entry.opts.scope === 'global') {
99
+ out.push(entry);
100
+ }
101
+ }
102
+ }
103
+ this.collectGlobalFromActiveDescendants(child, out);
104
+ }
105
+ collectFromActiveChain(layer, out) {
106
+ const set = this.layerBlocks.get(layer.id);
107
+ if (set) {
108
+ for (const entry of set) {
109
+ out.push(entry);
110
+ }
111
+ }
112
+ const activeChildId = layer.getActiveChildId();
113
+ if (!activeChildId) return;
114
+ const child = layer.getChildLayer(activeChildId);
115
+ if (!child) return;
116
+ this.collectFromActiveChain(child, out);
117
+ }
118
+ async checkBlocks(targetLayer) {
119
+ const blocks = this.collectApplicableBlocks(targetLayer);
120
+ if (blocks.length === 0) return true;
121
+ const results = await Promise.all(blocks.map(b => this.runBlock(b)));
122
+ return results.every(Boolean);
123
+ }
124
+ async runBlock(entry) {
125
+ try {
126
+ const result = await Promise.race([entry.callback(), new Promise(resolve => setTimeout(() => {
127
+ resolve(false);
128
+ }, BLOCK_TIMEOUT_MS))]);
129
+ return result;
130
+ } catch {
131
+ return false;
132
+ }
133
+ }
134
+ incrementBeforeUnload() {
135
+ this.beforeUnloadCount++;
136
+ if (this.beforeUnloadCount === 1 && typeof window !== 'undefined') {
137
+ window.addEventListener('beforeunload', this.beforeUnloadHandler);
138
+ }
139
+ }
140
+ decrementBeforeUnload() {
141
+ if (this.beforeUnloadCount === 0) return;
142
+ this.beforeUnloadCount--;
143
+ if (this.beforeUnloadCount === 0 && typeof window !== 'undefined') {
144
+ window.removeEventListener('beforeunload', this.beforeUnloadHandler);
145
+ }
146
+ }
147
+ notifyChange() {
148
+ for (const listener of this.changeListeners) {
149
+ listener();
150
+ }
151
+ }
152
+ }
153
+ exports.BlockRegistry = BlockRegistry;