chayns-api 3.1.6 → 3.2.0-beta.0

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 (33) hide show
  1. package/dist/cjs/calls/appleSafeAreaListener.js +15 -0
  2. package/dist/cjs/calls/index.js +5 -1
  3. package/dist/cjs/hooks/index.js +21 -1
  4. package/dist/cjs/hooks/useSafeArea.js +110 -0
  5. package/dist/cjs/hooks/useValuesWithOverrides.js +37 -0
  6. package/dist/cjs/types/IChaynsReact.js +14 -12
  7. package/dist/cjs/wrapper/AppWrapper.js +29 -1
  8. package/dist/cjs/wrapper/FrameWrapper.js +10 -0
  9. package/dist/cjs/wrapper/ModuleFederationWrapper.js +4 -2
  10. package/dist/cjs/wrapper/SsrWrapper.js +2 -1
  11. package/dist/cjs/wrapper/normalizeFunctions.js +68 -0
  12. package/dist/esm/calls/appleSafeAreaListener.js +8 -0
  13. package/dist/esm/calls/index.js +2 -0
  14. package/dist/esm/hooks/index.js +3 -1
  15. package/dist/esm/hooks/useSafeArea.js +102 -0
  16. package/dist/esm/hooks/useValuesWithOverrides.js +30 -0
  17. package/dist/esm/types/IChaynsReact.js +13 -11
  18. package/dist/esm/wrapper/AppWrapper.js +30 -2
  19. package/dist/esm/wrapper/FrameWrapper.js +10 -0
  20. package/dist/esm/wrapper/ModuleFederationWrapper.js +4 -2
  21. package/dist/esm/wrapper/SsrWrapper.js +2 -1
  22. package/dist/esm/wrapper/StaticChaynsApi.js +2 -0
  23. package/dist/esm/wrapper/normalizeFunctions.js +61 -0
  24. package/dist/types/calls/appleSafeAreaListener.d.ts +11 -0
  25. package/dist/types/calls/index.d.ts +13 -3
  26. package/dist/types/hooks/index.d.ts +2 -0
  27. package/dist/types/hooks/useSafeArea.d.ts +11 -0
  28. package/dist/types/hooks/useValuesWithOverrides.d.ts +2 -0
  29. package/dist/types/types/IChaynsReact.d.ts +14 -3
  30. package/dist/types/wrapper/AppWrapper.d.ts +1 -0
  31. package/dist/types/wrapper/StaticChaynsApi.d.ts +3 -1
  32. package/dist/types/wrapper/normalizeFunctions.d.ts +2 -0
  33. package/package.json +1 -1
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.addAppleSafeAreaListener = void 0;
7
+ var _index = require("./index");
8
+ const addAppleSafeAreaListener = ({
9
+ callback
10
+ }) => {
11
+ void (0, _index.invokeCall)({
12
+ action: 300
13
+ }, callback);
14
+ };
15
+ exports.addAppleSafeAreaListener = addAppleSafeAreaListener;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.vibrate = exports.user = exports.storageSetItem = exports.storageRemoveItem = exports.storageGetItem = exports.site = exports.setWaitCursor = exports.setTempDesignSettings = exports.setScanQrCode = exports.setRefreshScrollEnabled = exports.setOverlay = exports.setHeight = exports.setFloatingButton = exports.setDisplayTimeout = exports.setCustomCookie = exports.setAdminMode = exports.sendMessageToUser = exports.sendMessageToPage = exports.sendMessageToGroup = exports.selectPage = exports.scrollToY = exports.scrollByY = exports.removeWindowMetricsListener = exports.removeVisibilityChangeListener = exports.removeToolbarChangeListener = exports.removeScrollListener = exports.removeGeoLocationListener = exports.removeAccessTokenChangeListener = exports.refreshData = exports.refreshAccessToken = exports.redirect = exports.parameters = exports.pages = exports.openVideo = exports.openUrl = exports.openMedia = exports.openImage = exports.navigateBack = exports.logout = exports.login = exports.language = exports.invokePaymentCall = exports.invokeDialogCall = exports.invokeCall = exports.getWindowMetrics = exports.getUserInfo = exports.getUser = exports.getStyleSettings = exports.getSite = exports.getScrollPosition = exports.getParameters = exports.getPages = exports.getLanguage = exports.getGeoLocation = exports.getEnvironment = exports.getDialogData = exports.getDevice = exports.getCustomFunction = exports.getCustomCookie = exports.getCurrentPage = exports.getChaynsHistoryLayer = exports.getAvailableSharingServices = exports.getAccessToken = exports.environment = exports.device = exports.customCallbackFunction = exports.createDialog = exports.addWindowMetricsListener = exports.addVisibilityChangeListener = exports.addToolbarChangeListener = exports.addScrollListener = exports.addGeoLocationListener = exports.addAnonymousAccount = exports.addAccessTokenChangeListener = void 0;
6
+ exports.vibrate = exports.user = exports.storageSetItem = exports.storageRemoveItem = exports.storageGetItem = exports.site = exports.setWaitCursor = exports.setTempDesignSettings = exports.setScanQrCode = exports.setRefreshScrollEnabled = exports.setOverlay = exports.setHeight = exports.setFloatingButton = exports.setDisplayTimeout = exports.setCustomCookie = exports.setAdminMode = exports.sendMessageToUser = exports.sendMessageToPage = exports.sendMessageToGroup = exports.selectPage = exports.scrollToY = exports.scrollByY = exports.removeWindowMetricsListener = exports.removeVisibilityChangeListener = exports.removeToolbarChangeListener = exports.removeScrollListener = exports.removeGeoLocationListener = exports.removeAppleSafeAreaListener = exports.removeAccessTokenChangeListener = exports.refreshData = exports.refreshAccessToken = exports.redirect = exports.parameters = exports.pages = exports.openVideo = exports.openUrl = exports.openMedia = exports.openImage = exports.navigateBack = exports.logout = exports.login = exports.language = exports.invokePaymentCall = exports.invokeDialogCall = exports.invokeCall = exports.getWindowMetrics = exports.getUserInfo = exports.getUser = exports.getStyleSettings = exports.getSite = exports.getScrollPosition = exports.getParameters = exports.getPages = exports.getLanguage = exports.getGeoLocation = exports.getEnvironment = exports.getDialogData = exports.getDevice = exports.getCustomFunction = exports.getCustomCookie = exports.getCurrentPage = exports.getChaynsHistoryLayer = exports.getAvailableSharingServices = exports.getAccessToken = exports.environment = exports.device = exports.customCallbackFunction = exports.createDialog = exports.addWindowMetricsListener = exports.addVisibilityChangeListener = exports.addToolbarChangeListener = exports.addScrollListener = exports.addGeoLocationListener = exports.addAppleSafeAreaListener = exports.addAnonymousAccount = exports.addAccessTokenChangeListener = void 0;
7
7
  var _moduleWrapper = require("../components/moduleWrapper");
8
8
  var _HistoryLayerContext = require("../contexts/HistoryLayerContext");
9
9
  const addGeoLocationListener = (...args) => _moduleWrapper.moduleWrapper.current.functions.addGeoLocationListener(...args);
@@ -18,6 +18,8 @@ const addAccessTokenChangeListener = (...args) => _moduleWrapper.moduleWrapper.c
18
18
  exports.addAccessTokenChangeListener = addAccessTokenChangeListener;
19
19
  const addWindowMetricsListener = (...args) => _moduleWrapper.moduleWrapper.current.functions.addWindowMetricsListener(...args);
20
20
  exports.addWindowMetricsListener = addWindowMetricsListener;
21
+ const addAppleSafeAreaListener = (...args) => _moduleWrapper.moduleWrapper.current.functions.addAppleSafeAreaListener(...args);
22
+ exports.addAppleSafeAreaListener = addAppleSafeAreaListener;
21
23
  const customCallbackFunction = (...args) => _moduleWrapper.moduleWrapper.current.functions.customCallbackFunction(...args);
22
24
  exports.customCallbackFunction = customCallbackFunction;
23
25
  const getAccessToken = (...args) => _moduleWrapper.moduleWrapper.current.functions.getAccessToken(...args);
@@ -70,6 +72,8 @@ const removeVisibilityChangeListener = (...args) => _moduleWrapper.moduleWrapper
70
72
  exports.removeVisibilityChangeListener = removeVisibilityChangeListener;
71
73
  const removeWindowMetricsListener = (...args) => _moduleWrapper.moduleWrapper.current.functions.removeWindowMetricsListener(...args);
72
74
  exports.removeWindowMetricsListener = removeWindowMetricsListener;
75
+ const removeAppleSafeAreaListener = (...args) => _moduleWrapper.moduleWrapper.current.functions.removeAppleSafeAreaListener(...args);
76
+ exports.removeAppleSafeAreaListener = removeAppleSafeAreaListener;
73
77
  const selectPage = (...args) => _moduleWrapper.moduleWrapper.current.functions.selectPage(...args);
74
78
  exports.selectPage = selectPage;
75
79
  const scrollByY = (...args) => _moduleWrapper.moduleWrapper.current.functions.scrollByY(...args);
@@ -177,6 +177,18 @@ Object.defineProperty(exports, "useParameters", {
177
177
  return _useParameters.useParameters;
178
178
  }
179
179
  });
180
+ Object.defineProperty(exports, "useSafeArea", {
181
+ enumerable: true,
182
+ get: function () {
183
+ return _useSafeArea.useSafeArea;
184
+ }
185
+ });
186
+ Object.defineProperty(exports, "useSafeAreaListener", {
187
+ enumerable: true,
188
+ get: function () {
189
+ return _useSafeArea.useSafeAreaListener;
190
+ }
191
+ });
180
192
  Object.defineProperty(exports, "useScrollListener", {
181
193
  enumerable: true,
182
194
  get: function () {
@@ -225,6 +237,12 @@ Object.defineProperty(exports, "useValues", {
225
237
  return _useValues.useValues;
226
238
  }
227
239
  });
240
+ Object.defineProperty(exports, "useValuesWithOverrides", {
241
+ enumerable: true,
242
+ get: function () {
243
+ return _useValuesWithOverrides.useValuesWithOverrides;
244
+ }
245
+ });
228
246
  Object.defineProperty(exports, "useWindowMetrics", {
229
247
  enumerable: true,
230
248
  get: function () {
@@ -243,6 +261,7 @@ var _useIsAdminMode = require("./useIsAdminMode");
243
261
  var _useUser = require("./useUser");
244
262
  var _useAccessToken = require("./useAccessToken");
245
263
  var _windowMetricsListener = require("./windowMetricsListener");
264
+ var _useSafeArea = require("./useSafeArea");
246
265
  var _useDevice = require("./useDevice");
247
266
  var _useSite = require("./useSite");
248
267
  var _useParameters = require("./useParameters");
@@ -258,4 +277,5 @@ var _useCustomCallbackFunction = require("./useCustomCallbackFunction");
258
277
  var _useCustomFunction = require("./useCustomFunction");
259
278
  var _useStyleSettings = require("./useStyleSettings");
260
279
  var _useChaynsApiId = require("./useChaynsApiId");
261
- var _history = require("./history");
280
+ var _history = require("./history");
281
+ var _useValuesWithOverrides = require("./useValuesWithOverrides");
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useSafeAreaListener = exports.useSafeArea = void 0;
7
+ var _reactCompilerRuntime = require("react-compiler-runtime");
8
+ var _react = require("react");
9
+ var _IChaynsReact = require("../types/IChaynsReact");
10
+ var _context = require("./context");
11
+ const SAFE_AREA_SUPPORT_CONFIG = {
12
+ [_IChaynsReact.AppName.Team]: 1072,
13
+ [_IChaynsReact.AppName.CityApp]: 7250,
14
+ [_IChaynsReact.AppName.Chayns]: 7250,
15
+ [_IChaynsReact.AppName.Sidekick]: 2120,
16
+ [_IChaynsReact.AppName.TobitChat]: 2077
17
+ };
18
+ const isSafeAreaSupported = (os, app) => {
19
+ var _SAFE_AREA_SUPPORT_CO;
20
+ if (!os || !['iOS', 'Mac OS'].includes(os)) {
21
+ return false;
22
+ }
23
+ if (!app) {
24
+ return false;
25
+ }
26
+ const minVersion = (_SAFE_AREA_SUPPORT_CO = SAFE_AREA_SUPPORT_CONFIG[app.name]) !== null && _SAFE_AREA_SUPPORT_CO !== void 0 ? _SAFE_AREA_SUPPORT_CO : null;
27
+ if (minVersion === null) {
28
+ return false;
29
+ }
30
+ return app.appVersion >= minVersion;
31
+ };
32
+ const useSafeAreaListener = () => {
33
+ const addListener = (0, _context.useFunctionsSelector)(f => f.addAppleSafeAreaListener);
34
+ const removeListener = (0, _context.useFunctionsSelector)(f => f.removeAppleSafeAreaListener);
35
+ const promiseRef = (0, _react.useRef)();
36
+ return (0, _react.useCallback)(callback => {
37
+ promiseRef.current = addListener(callback);
38
+ return () => {
39
+ var _promiseRef$current;
40
+ void ((_promiseRef$current = promiseRef.current) === null || _promiseRef$current === void 0 ? void 0 : _promiseRef$current.then(removeListener));
41
+ };
42
+ }, []);
43
+ };
44
+ exports.useSafeAreaListener = useSafeAreaListener;
45
+ const useSafeArea = t0 => {
46
+ const $ = (0, _reactCompilerRuntime.c)(11);
47
+ let t1;
48
+ if ($[0] !== t0) {
49
+ t1 = t0 === undefined ? {} : t0;
50
+ $[0] = t0;
51
+ $[1] = t1;
52
+ } else {
53
+ t1 = $[1];
54
+ }
55
+ const {
56
+ enabled: t2
57
+ } = t1;
58
+ const enabled = t2 === undefined ? true : t2;
59
+ let t3;
60
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
61
+ t3 = {
62
+ top: 0,
63
+ left: 0,
64
+ bottom: 0,
65
+ right: 0
66
+ };
67
+ $[2] = t3;
68
+ } else {
69
+ t3 = $[2];
70
+ }
71
+ const [value, setValue] = (0, _react.useState)(t3);
72
+ const addListener = useSafeAreaListener();
73
+ const device = (0, _context.useValuesSelector)(_temp);
74
+ let t4;
75
+ if ($[3] !== device.app || $[4] !== device.os) {
76
+ t4 = isSafeAreaSupported(device.os, device.app);
77
+ $[3] = device.app;
78
+ $[4] = device.os;
79
+ $[5] = t4;
80
+ } else {
81
+ t4 = $[5];
82
+ }
83
+ const isSupported = t4;
84
+ let t5;
85
+ let t6;
86
+ if ($[6] !== addListener || $[7] !== enabled || $[8] !== isSupported) {
87
+ t5 = () => {
88
+ if (enabled && isSupported) {
89
+ return addListener(v_0 => {
90
+ setValue(v_0);
91
+ });
92
+ }
93
+ };
94
+ t6 = [enabled, isSupported, addListener];
95
+ $[6] = addListener;
96
+ $[7] = enabled;
97
+ $[8] = isSupported;
98
+ $[9] = t5;
99
+ $[10] = t6;
100
+ } else {
101
+ t5 = $[9];
102
+ t6 = $[10];
103
+ }
104
+ (0, _react.useEffect)(t5, t6);
105
+ return value;
106
+ };
107
+ exports.useSafeArea = useSafeArea;
108
+ function _temp(v) {
109
+ return v.device;
110
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useValuesWithOverrides = void 0;
7
+ var _reactCompilerRuntime = require("react-compiler-runtime");
8
+ var _react = require("react");
9
+ var _useValues = require("./useValues");
10
+ const useValuesWithOverrides = overrideFactory => {
11
+ const $ = (0, _reactCompilerRuntime.c)(6);
12
+ const base = (0, _useValues.useValues)();
13
+ let t0;
14
+ if ($[0] !== base || $[1] !== overrideFactory) {
15
+ t0 = overrideFactory(base);
16
+ $[0] = base;
17
+ $[1] = overrideFactory;
18
+ $[2] = t0;
19
+ } else {
20
+ t0 = $[2];
21
+ }
22
+ const overrides = t0;
23
+ let t1;
24
+ if ($[3] !== base || $[4] !== overrides) {
25
+ t1 = {
26
+ ...base,
27
+ ...overrides
28
+ };
29
+ $[3] = base;
30
+ $[4] = overrides;
31
+ $[5] = t1;
32
+ } else {
33
+ t1 = $[5];
34
+ }
35
+ return t1;
36
+ };
37
+ exports.useValuesWithOverrides = useValuesWithOverrides;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.selectType = exports.WeekDayType = exports.ToastType = exports.TappEvent = exports.SnapshotType = exports.SharingApp = exports.ScreenSize = exports.ScanQrCodeCodeType = exports.ScanQrCodeCameraTypes = exports.RuntimeEnviroment = exports.MediaType = exports.LoginState = exports.Language = exports.IconType = exports.IconStyle = exports.IOSFeedbackVibration = exports.Gender = exports.Font = exports.FloatingButtonPosition = exports.FloatingButtonAnimation = exports.Environment = exports.DialogType = exports.DialogSelectType = exports.DialogInputType = exports.DialogIconType = exports.DialogButtonType = exports.DialogAnimation = exports.DeviceOs = exports.DesignSettingsUpdateTappViewModes = exports.DesignSettingsUpdateSeasonTypes = exports.DesignSettingsUpdateGalleryAnimationTypes = exports.DesignSettingsUpdateCoverTypes = exports.DesignSettingsUpdateBackgroundType = exports.DateType = exports.ColorMode = exports.BrowserName = exports.AppName = exports.AppFlavor = exports.AccessMode = void 0;
6
+ exports.selectType = exports.WeekDayType = exports.ToastType = exports.TappEvent = exports.SnapshotType = exports.SharingApp = exports.ScreenSize = exports.ScanQrCodeCodeType = exports.ScanQrCodeCameraTypes = exports.RuntimeEnvironment = exports.RuntimeEnviroment = exports.MediaType = exports.LoginState = exports.Language = exports.IconType = exports.IconStyle = exports.IOSFeedbackVibration = exports.Gender = exports.Font = exports.FloatingButtonPosition = exports.FloatingButtonAnimation = exports.Environment = exports.DialogType = exports.DialogSelectType = exports.DialogInputType = exports.DialogIconType = exports.DialogButtonType = exports.DialogAnimation = exports.DeviceOs = exports.DesignSettingsUpdateTappViewModes = exports.DesignSettingsUpdateSeasonTypes = exports.DesignSettingsUpdateGalleryAnimationTypes = exports.DesignSettingsUpdateCoverTypes = exports.DesignSettingsUpdateBackgroundType = exports.DateType = exports.ColorMode = exports.BrowserName = exports.AppName = exports.AppFlavor = exports.AccessMode = void 0;
7
7
  let DateType = exports.DateType = function (DateType) {
8
8
  DateType[DateType["DATE"] = 0] = "DATE";
9
9
  DateType[DateType["TIME"] = 1] = "TIME";
@@ -223,17 +223,19 @@ let Language = exports.Language = function (Language) {
223
223
  Language["Ukrainian"] = "uk";
224
224
  return Language;
225
225
  }({});
226
- let RuntimeEnviroment = exports.RuntimeEnviroment = function (RuntimeEnviroment) {
227
- RuntimeEnviroment[RuntimeEnviroment["Unknown"] = 0] = "Unknown";
228
- RuntimeEnviroment[RuntimeEnviroment["ChaynsDe"] = 1] = "ChaynsDe";
229
- RuntimeEnviroment[RuntimeEnviroment["ChaynsWeb"] = 2] = "ChaynsWeb";
230
- RuntimeEnviroment[RuntimeEnviroment["ChaynsRuntime"] = 3] = "ChaynsRuntime";
231
- RuntimeEnviroment[RuntimeEnviroment["IntercomPlugin"] = 4] = "IntercomPlugin";
232
- RuntimeEnviroment[RuntimeEnviroment["PagemakerPlugin"] = 5] = "PagemakerPlugin";
233
- RuntimeEnviroment[RuntimeEnviroment["Dialog"] = 6] = "Dialog";
234
- RuntimeEnviroment[RuntimeEnviroment["App"] = 7] = "App";
235
- return RuntimeEnviroment;
236
- }({});
226
+ let RuntimeEnvironment = exports.RuntimeEnvironment = function (RuntimeEnvironment) {
227
+ RuntimeEnvironment[RuntimeEnvironment["Unknown"] = 0] = "Unknown";
228
+ RuntimeEnvironment[RuntimeEnvironment["ChaynsDe"] = 1] = "ChaynsDe";
229
+ RuntimeEnvironment[RuntimeEnvironment["ChaynsWeb"] = 2] = "ChaynsWeb";
230
+ RuntimeEnvironment[RuntimeEnvironment["ChaynsRuntime"] = 3] = "ChaynsRuntime";
231
+ RuntimeEnvironment[RuntimeEnvironment["IntercomPlugin"] = 4] = "IntercomPlugin";
232
+ RuntimeEnvironment[RuntimeEnvironment["PagemakerPlugin"] = 5] = "PagemakerPlugin";
233
+ RuntimeEnvironment[RuntimeEnvironment["Dialog"] = 6] = "Dialog";
234
+ RuntimeEnvironment[RuntimeEnvironment["App"] = 7] = "App";
235
+ RuntimeEnvironment[RuntimeEnvironment["RemotePlugin"] = 8] = "RemotePlugin";
236
+ return RuntimeEnvironment;
237
+ }({});
238
+ const RuntimeEnviroment = exports.RuntimeEnviroment = RuntimeEnvironment;
237
239
  let DeviceOs = exports.DeviceOs = function (DeviceOs) {
238
240
  DeviceOs["Unknown"] = "unknown";
239
241
  DeviceOs["Android"] = "android";
@@ -22,6 +22,7 @@ class AppWrapper {
22
22
  values = null;
23
23
  history = null;
24
24
  accessToken = '';
25
+ latestAppleSafeArea = null;
25
26
  listeners = [];
26
27
  customFunctions = {};
27
28
  nextDialogEventId = 0;
@@ -91,7 +92,7 @@ class AppWrapper {
91
92
  }),
92
93
  environment: {
93
94
  buildEnvironment: _IChaynsReact.Environment.Production,
94
- runtimeEnvironment: _IChaynsReact.RuntimeEnviroment.App
95
+ runtimeEnvironment: _IChaynsReact.RuntimeEnvironment.App
95
96
  },
96
97
  language: {
97
98
  site: AppInfo.Language || 'de',
@@ -287,6 +288,29 @@ class AppWrapper {
287
288
  }
288
289
  return id;
289
290
  },
291
+ addAppleSafeAreaListener: async callback => {
292
+ const {
293
+ id,
294
+ shouldInitialize
295
+ } = (0, _apiListener.addApiListener)('appleSafeAreaListener', callback);
296
+ if (this.latestAppleSafeArea) {
297
+ callback(this.latestAppleSafeArea);
298
+ }
299
+ if (shouldInitialize) {
300
+ void this.appCall(300, {}, {
301
+ callback: v => {
302
+ this.latestAppleSafeArea = {
303
+ top: v.top,
304
+ left: v.left,
305
+ bottom: v.bottom,
306
+ right: v.right
307
+ };
308
+ (0, _apiListener.dispatchApiEvent)('appleSafeAreaListener', this.latestAppleSafeArea);
309
+ }
310
+ });
311
+ }
312
+ return id;
313
+ },
290
314
  customCallbackFunction: async () => {
291
315
  this.notImplemented('customCallbackFunction');
292
316
  },
@@ -462,6 +486,10 @@ class AppWrapper {
462
486
  this.resizeListener = null;
463
487
  }
464
488
  },
489
+ removeAppleSafeAreaListener: async id => {
490
+ const shouldRemove = (0, _apiListener.removeApiListener)('appleSafeAreaListener', id);
491
+ if (shouldRemove) {}
492
+ },
465
493
  selectPage: async options => {
466
494
  var _this$values, _this$values2;
467
495
  if ((_this$values = this.values) !== null && _this$values !== void 0 && (_this$values = _this$values.site) !== null && _this$values !== void 0 && _this$values.id && options.siteId && options.siteId !== ((_this$values2 = this.values) === null || _this$values2 === void 0 || (_this$values2 = _this$values2.site) === null || _this$values2 === void 0 ? void 0 : _this$values2.id)) {
@@ -53,6 +53,12 @@ class FrameWrapper {
53
53
  callback(result);
54
54
  }));
55
55
  },
56
+ addAppleSafeAreaListener: async callback => {
57
+ if (!this.initialized) await this.ready;
58
+ return this.exposedFunctions.addAppleSafeAreaListener(comlink.proxy(result => {
59
+ callback(result);
60
+ }));
61
+ },
56
62
  customCallbackFunction: async (type, data) => {
57
63
  if (!this.initialized) await this.ready;
58
64
  return this.exposedFunctions.customCallbackFunction(type, data);
@@ -149,6 +155,10 @@ class FrameWrapper {
149
155
  if (!this.initialized) await this.ready;
150
156
  return this.exposedFunctions.removeWindowMetricsListener(id);
151
157
  },
158
+ removeAppleSafeAreaListener: async id => {
159
+ if (!this.initialized) await this.ready;
160
+ return this.exposedFunctions.removeAppleSafeAreaListener(id);
161
+ },
152
162
  removeToolbarChangeListener: async id => {
153
163
  if (!this.initialized) await this.ready;
154
164
  return this.exposedFunctions.removeToolbarChangeListener(id);
@@ -9,6 +9,7 @@ var _rootLayer = require("../utils/history/rootLayer");
9
9
  var _visibilityChangeListener = require("../calls/visibilityChangeListener");
10
10
  var _getUserInfo = _interopRequireDefault(require("../calls/getUserInfo"));
11
11
  var _sendMessage = require("../calls/sendMessage");
12
+ var _normalizeFunctions = require("./normalizeFunctions");
12
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
14
  class ModuleFederationWrapper {
14
15
  history = (0, _rootLayer.getOrInitRootChaynsHistoryLayer)().rootLayer;
@@ -16,6 +17,7 @@ class ModuleFederationWrapper {
16
17
  listeners = [];
17
18
  chaynsApiId = null;
18
19
  constructor(values, functions, customFunctions) {
20
+ const normalizedFunctions = (0, _normalizeFunctions.normalizeFunctions)(functions);
19
21
  this.values = values;
20
22
  this.functions = {};
21
23
  this.functions.addVisibilityChangeListener = async callback => (0, _visibilityChangeListener.addVisibilityChangeListener)(callback);
@@ -24,14 +26,14 @@ class ModuleFederationWrapper {
24
26
  this.functions.sendMessageToGroup = async (groupId, object) => (0, _sendMessage.sendMessageToGroup)(this, object, groupId);
25
27
  this.functions.sendMessageToPage = async object => (0, _sendMessage.sendMessageToPage)(this, object);
26
28
  this.functions.sendMessageToUser = async (userId, object) => (0, _sendMessage.sendMessageToUser)(this, object, userId);
27
- Object.entries(functions).forEach(([k, fn]) => {
29
+ Object.entries(normalizedFunctions).forEach(([k, fn]) => {
28
30
  this.functions[k] = async (...args) => fn(...args);
29
31
  });
30
32
  if (customFunctions) {
31
33
  this.customFunctions = customFunctions;
32
34
  }
33
35
  this.functions.createDialog = config => {
34
- return new _DialogHandler.default(config, functions.openDialog, functions.closeDialog, functions.dispatchEventToDialogClient, functions.addDialogClientEventListener);
36
+ return new _DialogHandler.default(config, normalizedFunctions.openDialog, normalizedFunctions.closeDialog, normalizedFunctions.dispatchEventToDialogClient, normalizedFunctions.addDialogClientEventListener);
35
37
  };
36
38
  }
37
39
  async init() {
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.SsrWrapper = void 0;
7
+ var _normalizeFunctions = require("./normalizeFunctions");
7
8
  class SsrWrapper {
8
9
  history = null;
9
10
  listeners = [];
@@ -11,7 +12,7 @@ class SsrWrapper {
11
12
  constructor(values, functions, customFunctions) {
12
13
  this.initialData = values;
13
14
  this.values = values;
14
- this.functions = functions;
15
+ this.functions = (0, _normalizeFunctions.normalizeFunctions)(functions);
15
16
  this.customFunctions = customFunctions !== null && customFunctions !== void 0 ? customFunctions : {};
16
17
  }
17
18
  async init() {
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.normalizeFunctions = void 0;
7
+ const createAppleSafeAreaFunctions = functions => {
8
+ var _runtimeFunctions$add, _runtimeFunctions$rem;
9
+ const runtimeFunctions = functions;
10
+ const baseAddListener = (_runtimeFunctions$add = runtimeFunctions.addAppleSafeAreaListener) !== null && _runtimeFunctions$add !== void 0 ? _runtimeFunctions$add : callback => {
11
+ if (functions.invokeCall) {
12
+ void functions.invokeCall({
13
+ action: 300
14
+ }, callback);
15
+ }
16
+ return Promise.resolve(-1);
17
+ };
18
+ const baseRemoveListener = (_runtimeFunctions$rem = runtimeFunctions.removeAppleSafeAreaListener) !== null && _runtimeFunctions$rem !== void 0 ? _runtimeFunctions$rem : () => Promise.resolve();
19
+ let upstreamListenerId = null;
20
+ let hasLatestValue = false;
21
+ let latestValue = null;
22
+ let counter = 0;
23
+ const listeners = {};
24
+ const dispatch = value => {
25
+ latestValue = value;
26
+ hasLatestValue = true;
27
+ Object.values(listeners).forEach(listener => listener(value));
28
+ };
29
+ const addAppleSafeAreaListener = callback => {
30
+ const id = ++counter;
31
+ listeners[id] = callback;
32
+ if (hasLatestValue && latestValue) {
33
+ callback(latestValue);
34
+ }
35
+ if (!upstreamListenerId) {
36
+ upstreamListenerId = baseAddListener(result => {
37
+ dispatch(result);
38
+ });
39
+ }
40
+ return Promise.resolve(id);
41
+ };
42
+ const removeAppleSafeAreaListener = id => {
43
+ delete listeners[id];
44
+ if (Object.keys(listeners).length === 0 && upstreamListenerId) {
45
+ void upstreamListenerId.then(listenerId => baseRemoveListener(listenerId));
46
+ upstreamListenerId = null;
47
+ }
48
+ return Promise.resolve();
49
+ };
50
+ return {
51
+ addAppleSafeAreaListener,
52
+ removeAppleSafeAreaListener
53
+ };
54
+ };
55
+ const normalizeFunctions = functions => {
56
+ var _runtimeFunctions$add2, _runtimeFunctions$rem2;
57
+ const runtimeFunctions = functions;
58
+ if (runtimeFunctions.addAppleSafeAreaListener && runtimeFunctions.removeAppleSafeAreaListener) {
59
+ return functions;
60
+ }
61
+ const safeAreaFunctions = createAppleSafeAreaFunctions(functions);
62
+ return {
63
+ ...functions,
64
+ addAppleSafeAreaListener: (_runtimeFunctions$add2 = runtimeFunctions.addAppleSafeAreaListener) !== null && _runtimeFunctions$add2 !== void 0 ? _runtimeFunctions$add2 : safeAreaFunctions.addAppleSafeAreaListener,
65
+ removeAppleSafeAreaListener: (_runtimeFunctions$rem2 = runtimeFunctions.removeAppleSafeAreaListener) !== null && _runtimeFunctions$rem2 !== void 0 ? _runtimeFunctions$rem2 : safeAreaFunctions.removeAppleSafeAreaListener
66
+ };
67
+ };
68
+ exports.normalizeFunctions = normalizeFunctions;
@@ -0,0 +1,8 @@
1
+ import { invokeCall } from './index';
2
+ export const addAppleSafeAreaListener = ({
3
+ callback
4
+ }) => {
5
+ void invokeCall({
6
+ action: 300
7
+ }, callback);
8
+ };
@@ -6,6 +6,7 @@ export const addVisibilityChangeListener = (...args) => moduleWrapper.current.fu
6
6
  export const addToolbarChangeListener = (...args) => moduleWrapper.current.functions.addToolbarChangeListener(...args);
7
7
  export const addAccessTokenChangeListener = (...args) => moduleWrapper.current.functions.addAccessTokenChangeListener(...args);
8
8
  export const addWindowMetricsListener = (...args) => moduleWrapper.current.functions.addWindowMetricsListener(...args);
9
+ export const addAppleSafeAreaListener = (...args) => moduleWrapper.current.functions.addAppleSafeAreaListener(...args);
9
10
  export const customCallbackFunction = (...args) => moduleWrapper.current.functions.customCallbackFunction(...args);
10
11
  export const getAccessToken = (...args) => moduleWrapper.current.functions.getAccessToken(...args);
11
12
  export const getAvailableSharingServices = (...args) => moduleWrapper.current.functions.getAvailableSharingServices(...args);
@@ -32,6 +33,7 @@ export const removeAccessTokenChangeListener = (...args) => moduleWrapper.curren
32
33
  export const removeScrollListener = (...args) => moduleWrapper.current.functions.removeScrollListener(...args);
33
34
  export const removeVisibilityChangeListener = (...args) => moduleWrapper.current.functions.removeVisibilityChangeListener(...args);
34
35
  export const removeWindowMetricsListener = (...args) => moduleWrapper.current.functions.removeWindowMetricsListener(...args);
36
+ export const removeAppleSafeAreaListener = (...args) => moduleWrapper.current.functions.removeAppleSafeAreaListener(...args);
35
37
  export const selectPage = (...args) => moduleWrapper.current.functions.selectPage(...args);
36
38
  export const scrollByY = (...args) => moduleWrapper.current.functions.scrollByY(...args);
37
39
  export const scrollToY = (...args) => moduleWrapper.current.functions.scrollToY(...args);
@@ -4,6 +4,7 @@ export { useIsAdminMode } from './useIsAdminMode';
4
4
  export { useUser } from './useUser';
5
5
  export { useAccessToken } from './useAccessToken';
6
6
  export { useWindowMetrics, useWindowMetricsListener } from './windowMetricsListener';
7
+ export { useSafeArea, useSafeAreaListener } from './useSafeArea';
7
8
  export { useDevice } from './useDevice';
8
9
  export { useSite } from './useSite';
9
10
  export { useParameters } from './useParameters';
@@ -19,4 +20,5 @@ export { useCustomCallbackFunction } from './useCustomCallbackFunction';
19
20
  export { useCustomFunction } from './useCustomFunction';
20
21
  export { useStyleSettings } from './useStyleSettings';
21
22
  export { useChaynsApiId } from './useChaynsApiId';
22
- export { useChaynsHistoryLayer, useChaynsHistoryRoute, useChaynsHistoryParams, useChaynsHistoryHash, useChaynsHistoryState, useChaynsHistoryNavigate, useChaynsHistoryBlock, useChaynsHistoryEvent, useChaynsHistoryChildLayer, useChaynsHistoryActiveChild } from './history';
23
+ export { useChaynsHistoryLayer, useChaynsHistoryRoute, useChaynsHistoryParams, useChaynsHistoryHash, useChaynsHistoryState, useChaynsHistoryNavigate, useChaynsHistoryBlock, useChaynsHistoryEvent, useChaynsHistoryChildLayer, useChaynsHistoryActiveChild } from './history';
24
+ export { useValuesWithOverrides } from './useValuesWithOverrides';
@@ -0,0 +1,102 @@
1
+ import { c as _c } from "react-compiler-runtime";
2
+ import { useCallback, useEffect, useRef, useState } from 'react';
3
+ import { AppName } from '../types/IChaynsReact';
4
+ import { useFunctionsSelector, useValuesSelector } from './context';
5
+ const SAFE_AREA_SUPPORT_CONFIG = {
6
+ [AppName.Team]: 1072,
7
+ [AppName.CityApp]: 7250,
8
+ [AppName.Chayns]: 7250,
9
+ [AppName.Sidekick]: 2120,
10
+ [AppName.TobitChat]: 2077
11
+ };
12
+ const isSafeAreaSupported = (os, app) => {
13
+ var _SAFE_AREA_SUPPORT_CO;
14
+ if (!os || !['iOS', 'Mac OS'].includes(os)) {
15
+ return false;
16
+ }
17
+ if (!app) {
18
+ return false;
19
+ }
20
+ const minVersion = (_SAFE_AREA_SUPPORT_CO = SAFE_AREA_SUPPORT_CONFIG[app.name]) !== null && _SAFE_AREA_SUPPORT_CO !== void 0 ? _SAFE_AREA_SUPPORT_CO : null;
21
+ if (minVersion === null) {
22
+ return false;
23
+ }
24
+ return app.appVersion >= minVersion;
25
+ };
26
+ export const useSafeAreaListener = () => {
27
+ const addListener = useFunctionsSelector(f => f.addAppleSafeAreaListener);
28
+ const removeListener = useFunctionsSelector(f => f.removeAppleSafeAreaListener);
29
+ const promiseRef = useRef();
30
+ return useCallback(callback => {
31
+ promiseRef.current = addListener(callback);
32
+ return () => {
33
+ var _promiseRef$current;
34
+ void ((_promiseRef$current = promiseRef.current) === null || _promiseRef$current === void 0 ? void 0 : _promiseRef$current.then(removeListener));
35
+ };
36
+ }, []);
37
+ };
38
+ export const useSafeArea = t0 => {
39
+ const $ = _c(11);
40
+ let t1;
41
+ if ($[0] !== t0) {
42
+ t1 = t0 === undefined ? {} : t0;
43
+ $[0] = t0;
44
+ $[1] = t1;
45
+ } else {
46
+ t1 = $[1];
47
+ }
48
+ const {
49
+ enabled: t2
50
+ } = t1;
51
+ const enabled = t2 === undefined ? true : t2;
52
+ let t3;
53
+ if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
54
+ t3 = {
55
+ top: 0,
56
+ left: 0,
57
+ bottom: 0,
58
+ right: 0
59
+ };
60
+ $[2] = t3;
61
+ } else {
62
+ t3 = $[2];
63
+ }
64
+ const [value, setValue] = useState(t3);
65
+ const addListener = useSafeAreaListener();
66
+ const device = useValuesSelector(_temp);
67
+ let t4;
68
+ if ($[3] !== device.app || $[4] !== device.os) {
69
+ t4 = isSafeAreaSupported(device.os, device.app);
70
+ $[3] = device.app;
71
+ $[4] = device.os;
72
+ $[5] = t4;
73
+ } else {
74
+ t4 = $[5];
75
+ }
76
+ const isSupported = t4;
77
+ let t5;
78
+ let t6;
79
+ if ($[6] !== addListener || $[7] !== enabled || $[8] !== isSupported) {
80
+ t5 = () => {
81
+ if (enabled && isSupported) {
82
+ return addListener(v_0 => {
83
+ setValue(v_0);
84
+ });
85
+ }
86
+ };
87
+ t6 = [enabled, isSupported, addListener];
88
+ $[6] = addListener;
89
+ $[7] = enabled;
90
+ $[8] = isSupported;
91
+ $[9] = t5;
92
+ $[10] = t6;
93
+ } else {
94
+ t5 = $[9];
95
+ t6 = $[10];
96
+ }
97
+ useEffect(t5, t6);
98
+ return value;
99
+ };
100
+ function _temp(v) {
101
+ return v.device;
102
+ }
@@ -0,0 +1,30 @@
1
+ import { c as _c } from "react-compiler-runtime";
2
+ import { useMemo } from 'react';
3
+ import { useValues } from './useValues';
4
+ export const useValuesWithOverrides = overrideFactory => {
5
+ const $ = _c(6);
6
+ const base = useValues();
7
+ let t0;
8
+ if ($[0] !== base || $[1] !== overrideFactory) {
9
+ t0 = overrideFactory(base);
10
+ $[0] = base;
11
+ $[1] = overrideFactory;
12
+ $[2] = t0;
13
+ } else {
14
+ t0 = $[2];
15
+ }
16
+ const overrides = t0;
17
+ let t1;
18
+ if ($[3] !== base || $[4] !== overrides) {
19
+ t1 = {
20
+ ...base,
21
+ ...overrides
22
+ };
23
+ $[3] = base;
24
+ $[4] = overrides;
25
+ $[5] = t1;
26
+ } else {
27
+ t1 = $[5];
28
+ }
29
+ return t1;
30
+ };
@@ -217,17 +217,19 @@ export let Language = function (Language) {
217
217
  Language["Ukrainian"] = "uk";
218
218
  return Language;
219
219
  }({});
220
- export let RuntimeEnviroment = function (RuntimeEnviroment) {
221
- RuntimeEnviroment[RuntimeEnviroment["Unknown"] = 0] = "Unknown";
222
- RuntimeEnviroment[RuntimeEnviroment["ChaynsDe"] = 1] = "ChaynsDe";
223
- RuntimeEnviroment[RuntimeEnviroment["ChaynsWeb"] = 2] = "ChaynsWeb";
224
- RuntimeEnviroment[RuntimeEnviroment["ChaynsRuntime"] = 3] = "ChaynsRuntime";
225
- RuntimeEnviroment[RuntimeEnviroment["IntercomPlugin"] = 4] = "IntercomPlugin";
226
- RuntimeEnviroment[RuntimeEnviroment["PagemakerPlugin"] = 5] = "PagemakerPlugin";
227
- RuntimeEnviroment[RuntimeEnviroment["Dialog"] = 6] = "Dialog";
228
- RuntimeEnviroment[RuntimeEnviroment["App"] = 7] = "App";
229
- return RuntimeEnviroment;
230
- }({});
220
+ export let RuntimeEnvironment = function (RuntimeEnvironment) {
221
+ RuntimeEnvironment[RuntimeEnvironment["Unknown"] = 0] = "Unknown";
222
+ RuntimeEnvironment[RuntimeEnvironment["ChaynsDe"] = 1] = "ChaynsDe";
223
+ RuntimeEnvironment[RuntimeEnvironment["ChaynsWeb"] = 2] = "ChaynsWeb";
224
+ RuntimeEnvironment[RuntimeEnvironment["ChaynsRuntime"] = 3] = "ChaynsRuntime";
225
+ RuntimeEnvironment[RuntimeEnvironment["IntercomPlugin"] = 4] = "IntercomPlugin";
226
+ RuntimeEnvironment[RuntimeEnvironment["PagemakerPlugin"] = 5] = "PagemakerPlugin";
227
+ RuntimeEnvironment[RuntimeEnvironment["Dialog"] = 6] = "Dialog";
228
+ RuntimeEnvironment[RuntimeEnvironment["App"] = 7] = "App";
229
+ RuntimeEnvironment[RuntimeEnvironment["RemotePlugin"] = 8] = "RemotePlugin";
230
+ return RuntimeEnvironment;
231
+ }({});
232
+ export const RuntimeEnviroment = RuntimeEnvironment;
231
233
  export let DeviceOs = function (DeviceOs) {
232
234
  DeviceOs["Unknown"] = "unknown";
233
235
  DeviceOs["Android"] = "android";
@@ -8,7 +8,7 @@ import { DefaultLoginDialogOptions } from '../constants';
8
8
  import { DeviceLanguage } from '../constants/languages';
9
9
  import DialogHandler from '../handler/DialogHandler';
10
10
  import { addApiListener, dispatchApiEvent, removeApiListener } from '../utils/apiListener';
11
- import { AppName, DialogButtonType, DialogType, Environment, Font, Gender, IconType, LoginState, RuntimeEnviroment, TappEvent } from '../types/IChaynsReact';
11
+ import { AppName, DialogButtonType, DialogType, Environment, Font, Gender, IconType, LoginState, RuntimeEnvironment, TappEvent } from '../types/IChaynsReact';
12
12
  import invokeAppCall from '../utils/appCall';
13
13
  import { addAppStorageListener, clearAppStorage, isAppStorageAvailable, setAppStorageItem } from '../utils/appStorage';
14
14
  import getDeviceInfo, { getScreenSize } from '../utils/deviceHelper';
@@ -80,7 +80,7 @@ export class AppWrapper {
80
80
  }),
81
81
  environment: {
82
82
  buildEnvironment: Environment.Production,
83
- runtimeEnvironment: RuntimeEnviroment.App
83
+ runtimeEnvironment: RuntimeEnvironment.App
84
84
  },
85
85
  language: {
86
86
  site: AppInfo.Language || 'de',
@@ -148,6 +148,7 @@ export class AppWrapper {
148
148
  _defineProperty(this, "values", null);
149
149
  _defineProperty(this, "history", null);
150
150
  _defineProperty(this, "accessToken", '');
151
+ _defineProperty(this, "latestAppleSafeArea", null);
151
152
  _defineProperty(this, "listeners", []);
152
153
  _defineProperty(this, "customFunctions", {});
153
154
  _defineProperty(this, "nextDialogEventId", 0);
@@ -250,6 +251,29 @@ export class AppWrapper {
250
251
  }
251
252
  return id;
252
253
  },
254
+ addAppleSafeAreaListener: async callback => {
255
+ const {
256
+ id,
257
+ shouldInitialize
258
+ } = addApiListener('appleSafeAreaListener', callback);
259
+ if (this.latestAppleSafeArea) {
260
+ callback(this.latestAppleSafeArea);
261
+ }
262
+ if (shouldInitialize) {
263
+ void this.appCall(300, {}, {
264
+ callback: v => {
265
+ this.latestAppleSafeArea = {
266
+ top: v.top,
267
+ left: v.left,
268
+ bottom: v.bottom,
269
+ right: v.right
270
+ };
271
+ dispatchApiEvent('appleSafeAreaListener', this.latestAppleSafeArea);
272
+ }
273
+ });
274
+ }
275
+ return id;
276
+ },
253
277
  customCallbackFunction: async () => {
254
278
  this.notImplemented('customCallbackFunction');
255
279
  },
@@ -425,6 +449,10 @@ export class AppWrapper {
425
449
  this.resizeListener = null;
426
450
  }
427
451
  },
452
+ removeAppleSafeAreaListener: async id => {
453
+ const shouldRemove = removeApiListener('appleSafeAreaListener', id);
454
+ if (shouldRemove) {}
455
+ },
428
456
  selectPage: async options => {
429
457
  var _this$values, _this$values2;
430
458
  if ((_this$values = this.values) !== null && _this$values !== void 0 && (_this$values = _this$values.site) !== null && _this$values !== void 0 && _this$values.id && options.siteId && options.siteId !== ((_this$values2 = this.values) === null || _this$values2 === void 0 || (_this$values2 = _this$values2.site) === null || _this$values2 === void 0 ? void 0 : _this$values2.id)) {
@@ -49,6 +49,12 @@ export class FrameWrapper {
49
49
  callback(result);
50
50
  }));
51
51
  },
52
+ addAppleSafeAreaListener: async callback => {
53
+ if (!this.initialized) await this.ready;
54
+ return this.exposedFunctions.addAppleSafeAreaListener(comlink.proxy(result => {
55
+ callback(result);
56
+ }));
57
+ },
52
58
  customCallbackFunction: async (type, data) => {
53
59
  if (!this.initialized) await this.ready;
54
60
  return this.exposedFunctions.customCallbackFunction(type, data);
@@ -145,6 +151,10 @@ export class FrameWrapper {
145
151
  if (!this.initialized) await this.ready;
146
152
  return this.exposedFunctions.removeWindowMetricsListener(id);
147
153
  },
154
+ removeAppleSafeAreaListener: async id => {
155
+ if (!this.initialized) await this.ready;
156
+ return this.exposedFunctions.removeAppleSafeAreaListener(id);
157
+ },
148
158
  removeToolbarChangeListener: async id => {
149
159
  if (!this.initialized) await this.ready;
150
160
  return this.exposedFunctions.removeToolbarChangeListener(id);
@@ -6,6 +6,7 @@ import { getOrInitRootChaynsHistoryLayer } from '../utils/history/rootLayer';
6
6
  import { addVisibilityChangeListener, removeVisibilityChangeListener } from '../calls/visibilityChangeListener';
7
7
  import getUserInfo from '../calls/getUserInfo';
8
8
  import { sendMessageToGroup, sendMessageToPage, sendMessageToUser } from '../calls/sendMessage';
9
+ import { normalizeFunctions } from './normalizeFunctions';
9
10
  export class ModuleFederationWrapper {
10
11
  constructor(values, functions, customFunctions) {
11
12
  _defineProperty(this, "values", void 0);
@@ -23,6 +24,7 @@ export class ModuleFederationWrapper {
23
24
  _defineProperty(this, "emitChange", () => {
24
25
  this.listeners.forEach(l => l());
25
26
  });
27
+ const normalizedFunctions = normalizeFunctions(functions);
26
28
  this.values = values;
27
29
  this.functions = {};
28
30
  this.functions.addVisibilityChangeListener = async callback => addVisibilityChangeListener(callback);
@@ -31,14 +33,14 @@ export class ModuleFederationWrapper {
31
33
  this.functions.sendMessageToGroup = async (groupId, object) => sendMessageToGroup(this, object, groupId);
32
34
  this.functions.sendMessageToPage = async object => sendMessageToPage(this, object);
33
35
  this.functions.sendMessageToUser = async (userId, object) => sendMessageToUser(this, object, userId);
34
- Object.entries(functions).forEach(([k, fn]) => {
36
+ Object.entries(normalizedFunctions).forEach(([k, fn]) => {
35
37
  this.functions[k] = async (...args) => fn(...args);
36
38
  });
37
39
  if (customFunctions) {
38
40
  this.customFunctions = customFunctions;
39
41
  }
40
42
  this.functions.createDialog = config => {
41
- return new DialogHandler(config, functions.openDialog, functions.closeDialog, functions.dispatchEventToDialogClient, functions.addDialogClientEventListener);
43
+ return new DialogHandler(config, normalizedFunctions.openDialog, normalizedFunctions.closeDialog, normalizedFunctions.dispatchEventToDialogClient, normalizedFunctions.addDialogClientEventListener);
42
44
  };
43
45
  }
44
46
  async init() {
@@ -1,6 +1,7 @@
1
1
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
2
2
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
3
3
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
4
+ import { normalizeFunctions } from './normalizeFunctions';
4
5
  export class SsrWrapper {
5
6
  constructor(values, functions, customFunctions) {
6
7
  _defineProperty(this, "initialData", void 0);
@@ -21,7 +22,7 @@ export class SsrWrapper {
21
22
  });
22
23
  this.initialData = values;
23
24
  this.values = values;
24
- this.functions = functions;
25
+ this.functions = normalizeFunctions(functions);
25
26
  this.customFunctions = customFunctions !== null && customFunctions !== void 0 ? customFunctions : {};
26
27
  }
27
28
  async init() {
@@ -15,6 +15,7 @@ class StaticChaynsApi {
15
15
  _defineProperty(this, "addVisibilityChangeListener", void 0);
16
16
  _defineProperty(this, "addToolbarChangeListener", void 0);
17
17
  _defineProperty(this, "addWindowMetricsListener", void 0);
18
+ _defineProperty(this, "addAppleSafeAreaListener", void 0);
18
19
  _defineProperty(this, "customCallbackFunction", void 0);
19
20
  _defineProperty(this, "getAvailableSharingServices", void 0);
20
21
  _defineProperty(this, "getAccessToken", void 0);
@@ -40,6 +41,7 @@ class StaticChaynsApi {
40
41
  _defineProperty(this, "removeVisibilityChangeListener", void 0);
41
42
  _defineProperty(this, "removeToolbarChangeListener", void 0);
42
43
  _defineProperty(this, "removeWindowMetricsListener", void 0);
44
+ _defineProperty(this, "removeAppleSafeAreaListener", void 0);
43
45
  _defineProperty(this, "selectPage", void 0);
44
46
  _defineProperty(this, "scrollToY", void 0);
45
47
  _defineProperty(this, "sendMessageToGroup", void 0);
@@ -0,0 +1,61 @@
1
+ const createAppleSafeAreaFunctions = functions => {
2
+ var _runtimeFunctions$add, _runtimeFunctions$rem;
3
+ const runtimeFunctions = functions;
4
+ const baseAddListener = (_runtimeFunctions$add = runtimeFunctions.addAppleSafeAreaListener) !== null && _runtimeFunctions$add !== void 0 ? _runtimeFunctions$add : callback => {
5
+ if (functions.invokeCall) {
6
+ void functions.invokeCall({
7
+ action: 300
8
+ }, callback);
9
+ }
10
+ return Promise.resolve(-1);
11
+ };
12
+ const baseRemoveListener = (_runtimeFunctions$rem = runtimeFunctions.removeAppleSafeAreaListener) !== null && _runtimeFunctions$rem !== void 0 ? _runtimeFunctions$rem : () => Promise.resolve();
13
+ let upstreamListenerId = null;
14
+ let hasLatestValue = false;
15
+ let latestValue = null;
16
+ let counter = 0;
17
+ const listeners = {};
18
+ const dispatch = value => {
19
+ latestValue = value;
20
+ hasLatestValue = true;
21
+ Object.values(listeners).forEach(listener => listener(value));
22
+ };
23
+ const addAppleSafeAreaListener = callback => {
24
+ const id = ++counter;
25
+ listeners[id] = callback;
26
+ if (hasLatestValue && latestValue) {
27
+ callback(latestValue);
28
+ }
29
+ if (!upstreamListenerId) {
30
+ upstreamListenerId = baseAddListener(result => {
31
+ dispatch(result);
32
+ });
33
+ }
34
+ return Promise.resolve(id);
35
+ };
36
+ const removeAppleSafeAreaListener = id => {
37
+ delete listeners[id];
38
+ if (Object.keys(listeners).length === 0 && upstreamListenerId) {
39
+ void upstreamListenerId.then(listenerId => baseRemoveListener(listenerId));
40
+ upstreamListenerId = null;
41
+ }
42
+ return Promise.resolve();
43
+ };
44
+ return {
45
+ addAppleSafeAreaListener,
46
+ removeAppleSafeAreaListener
47
+ };
48
+ };
49
+ export const normalizeFunctions = functions => {
50
+ var _runtimeFunctions$add2, _runtimeFunctions$rem2;
51
+ const runtimeFunctions = functions;
52
+ if (runtimeFunctions.addAppleSafeAreaListener && runtimeFunctions.removeAppleSafeAreaListener) {
53
+ return functions;
54
+ }
55
+ const safeAreaFunctions = createAppleSafeAreaFunctions(functions);
56
+ return {
57
+ ...functions,
58
+ addAppleSafeAreaListener: (_runtimeFunctions$add2 = runtimeFunctions.addAppleSafeAreaListener) !== null && _runtimeFunctions$add2 !== void 0 ? _runtimeFunctions$add2 : safeAreaFunctions.addAppleSafeAreaListener,
59
+ removeAppleSafeAreaListener: (_runtimeFunctions$rem2 = runtimeFunctions.removeAppleSafeAreaListener) !== null && _runtimeFunctions$rem2 !== void 0 ? _runtimeFunctions$rem2 : safeAreaFunctions.removeAppleSafeAreaListener
60
+ };
61
+ };
@@ -0,0 +1,11 @@
1
+ import { AppleSafeArea } from '../types/IChaynsReact';
2
+ export interface AddAppleSafeAreaListenerOptions {
3
+ callback: (safeArea: AppleSafeArea) => void;
4
+ }
5
+ /**
6
+ * Directly invokes the Apple Safe Area listener call.
7
+ * This is used internally by the module wrapper.
8
+ *
9
+ * @internal
10
+ */
11
+ export declare const addAppleSafeAreaListener: ({ callback }: AddAppleSafeAreaListenerOptions) => void;
@@ -28,7 +28,12 @@ export declare const addAccessTokenChangeListener: (...args: Parameters<ChaynsRe
28
28
  * This adds a listener to get the actual height of the page.
29
29
  * @category Event listener
30
30
  */
31
- export declare const addWindowMetricsListener: (...args: Parameters<ChaynsReactFunctions["addWindowMetricsListener"]>) => Promise<number>; /**
31
+ export declare const addWindowMetricsListener: (...args: Parameters<ChaynsReactFunctions["addWindowMetricsListener"]>) => Promise<number>;
32
+ /**
33
+ * This adds a listener to get the safe area insets on iOS.
34
+ * @category Event listener
35
+ */
36
+ export declare const addAppleSafeAreaListener: (...args: Parameters<ChaynsReactFunctions["addAppleSafeAreaListener"]>) => Promise<number>; /**
32
37
  * Allows a custom callback function to be defined. Prefer usage via useCustomCallbackFunction when possible
33
38
  * @deprecated Use customFunction/useCustomFunction-interface instead if possible
34
39
  */
@@ -134,6 +139,11 @@ export declare const removeVisibilityChangeListener: (...args: Parameters<Chayns
134
139
  * @category Event listener
135
140
  */
136
141
  export declare const removeWindowMetricsListener: (...args: Parameters<ChaynsReactFunctions["removeWindowMetricsListener"]>) => Promise<void>;
142
+ /**
143
+ * Removes safe area listener.
144
+ * @category Event listener
145
+ */
146
+ export declare const removeAppleSafeAreaListener: (...args: Parameters<ChaynsReactFunctions["removeAppleSafeAreaListener"]>) => Promise<void>;
137
147
  /**
138
148
  * Select other page on chayns site.
139
149
  */
@@ -253,7 +263,7 @@ export declare const getParameters: () => {
253
263
  export declare const getPages: () => import("../types/IChaynsReact").Page[];
254
264
  export declare const getEnvironment: () => {
255
265
  buildEnvironment: import("../types/IChaynsReact").Environment;
256
- runtimeEnvironment: import("../types/IChaynsReact").RuntimeEnviroment | string;
266
+ runtimeEnvironment: import("../types/IChaynsReact").RuntimeEnvironment | string;
257
267
  };
258
268
  export declare const getStyleSettings: () => import("../types/IChaynsReact").ChaynsStyleSettings | undefined;
259
269
  export declare const getDialogData: <T = any>() => T;
@@ -279,7 +289,7 @@ export declare const parameters: {
279
289
  export declare const pages: import("../types/IChaynsReact").Page[];
280
290
  export declare const environment: {
281
291
  buildEnvironment: import("../types/IChaynsReact").Environment;
282
- runtimeEnvironment: import("../types/IChaynsReact").RuntimeEnviroment | string;
292
+ runtimeEnvironment: import("../types/IChaynsReact").RuntimeEnvironment | string;
283
293
  };
284
294
  /**
285
295
  * Redirects the user to the given destination. On the server side a 307 or 308 (depending on the isPermanent flag) redirect response is generated. On the client side a window.location.href change is performed.
@@ -4,6 +4,7 @@ export { useIsAdminMode } from './useIsAdminMode';
4
4
  export { useUser } from './useUser';
5
5
  export { useAccessToken } from './useAccessToken';
6
6
  export { useWindowMetrics, useWindowMetricsListener } from './windowMetricsListener';
7
+ export { useSafeArea, useSafeAreaListener } from './useSafeArea';
7
8
  export { useDevice } from './useDevice';
8
9
  export { useSite } from './useSite';
9
10
  export { useParameters } from './useParameters';
@@ -20,3 +21,4 @@ export { useCustomFunction } from './useCustomFunction';
20
21
  export { useStyleSettings } from './useStyleSettings';
21
22
  export { useChaynsApiId } from './useChaynsApiId';
22
23
  export { useChaynsHistoryLayer, useChaynsHistoryRoute, useChaynsHistoryParams, useChaynsHistoryHash, useChaynsHistoryState, useChaynsHistoryNavigate, useChaynsHistoryBlock, useChaynsHistoryEvent, useChaynsHistoryChildLayer, useChaynsHistoryActiveChild, type UseChaynsHistoryRouteResult, type UseChaynsHistoryActiveChildResult, type UseChaynsHistoryBlockOptions, } from './history';
24
+ export { useValuesWithOverrides } from './useValuesWithOverrides';
@@ -0,0 +1,11 @@
1
+ import { AppleSafeArea } from '../types/IChaynsReact';
2
+ /**
3
+ * @category Hooks
4
+ */
5
+ export declare const useSafeAreaListener: () => (callback: (result: AppleSafeArea) => void) => () => void;
6
+ /**
7
+ * @category Hooks
8
+ */
9
+ export declare const useSafeArea: ({ enabled }?: {
10
+ enabled?: boolean | undefined;
11
+ }) => AppleSafeArea;
@@ -0,0 +1,2 @@
1
+ import { ChaynsReactValues } from '../types/IChaynsReact';
2
+ export declare const useValuesWithOverrides: (overrideFactory: (base: ChaynsReactValues) => Partial<ChaynsReactValues>) => ChaynsReactValues;
@@ -339,7 +339,7 @@ export interface ChaynsReactValues {
339
339
  };
340
340
  environment: {
341
341
  buildEnvironment: Environment;
342
- runtimeEnvironment: RuntimeEnviroment | string;
342
+ runtimeEnvironment: RuntimeEnvironment | string;
343
343
  };
344
344
  customData: any;
345
345
  dialog: {
@@ -376,6 +376,7 @@ export interface ChaynsReactFunctions {
376
376
  addVisibilityChangeListener: (callback: (result: VisibilityChangeListenerResult) => void) => Promise<number>;
377
377
  addToolbarChangeListener: (callback: (result: ToolbarChangeListenerResult) => void) => Promise<number>;
378
378
  addWindowMetricsListener: (callback: (result: WindowMetricsListenerResult) => void) => Promise<number>;
379
+ addAppleSafeAreaListener: (callback: (result: AppleSafeArea) => void) => Promise<number>;
379
380
  customCallbackFunction: (type: string, data: unknown) => Promise<unknown>;
380
381
  getAvailableSharingServices: () => Promise<AvailableSharingServices>;
381
382
  getAccessToken: (value?: AccessToken) => Promise<AccessTokenResult>;
@@ -406,6 +407,7 @@ export interface ChaynsReactFunctions {
406
407
  removeVisibilityChangeListener: (value: number) => Promise<void>;
407
408
  removeToolbarChangeListener: (value: number) => Promise<void>;
408
409
  removeWindowMetricsListener: (value: number) => Promise<void>;
410
+ removeAppleSafeAreaListener: (value: number) => Promise<void>;
409
411
  selectPage: (value: SelectPage) => Promise<void>;
410
412
  scrollToY: (position: number, duration: number) => Promise<void>;
411
413
  sendMessageToGroup: (groupId: number, message: IntercomMessage) => Promise<Response>;
@@ -921,7 +923,7 @@ export declare enum Language {
921
923
  Polish = "pl",
922
924
  Ukrainian = "uk"
923
925
  }
924
- export declare enum RuntimeEnviroment {
926
+ export declare enum RuntimeEnvironment {
925
927
  Unknown = 0,
926
928
  ChaynsDe = 1,
927
929
  ChaynsWeb = 2,// ?
@@ -929,8 +931,11 @@ export declare enum RuntimeEnviroment {
929
931
  IntercomPlugin = 4,
930
932
  PagemakerPlugin = 5,
931
933
  Dialog = 6,
932
- App = 7
934
+ App = 7,
935
+ /** Module Federation plugin with unspecified host */
936
+ RemotePlugin = 8
933
937
  }
938
+ export declare const RuntimeEnviroment: typeof RuntimeEnvironment;
934
939
  export declare enum DeviceOs {
935
940
  Unknown = "unknown",
936
941
  Android = "android",
@@ -1050,6 +1055,12 @@ export declare enum DialogIconType {
1050
1055
  export type AnonymousAccountResult = {
1051
1056
  token: string;
1052
1057
  };
1058
+ export interface AppleSafeArea {
1059
+ top: number;
1060
+ left: number;
1061
+ bottom: number;
1062
+ right: number;
1063
+ }
1053
1064
  export type PageMainGroupType = {
1054
1065
  Id: 1;
1055
1066
  Administration: 2;
@@ -3,6 +3,7 @@ export declare class AppWrapper implements IChaynsReact {
3
3
  values: ChaynsReactValues;
4
4
  history: IChaynsReact['history'];
5
5
  accessToken: string;
6
+ latestAppleSafeArea: null;
6
7
  listeners: (() => void)[];
7
8
  customFunctions: {};
8
9
  nextDialogEventId: number;
@@ -5,6 +5,7 @@ declare class StaticChaynsApi implements ChaynsReactFunctions {
5
5
  addVisibilityChangeListener: ChaynsReactFunctions['addVisibilityChangeListener'];
6
6
  addToolbarChangeListener: ChaynsReactFunctions['addToolbarChangeListener'];
7
7
  addWindowMetricsListener: ChaynsReactFunctions['addWindowMetricsListener'];
8
+ addAppleSafeAreaListener: ChaynsReactFunctions['addAppleSafeAreaListener'];
8
9
  customCallbackFunction: ChaynsReactFunctions['customCallbackFunction'];
9
10
  getAvailableSharingServices: ChaynsReactFunctions['getAvailableSharingServices'];
10
11
  getAccessToken: ChaynsReactFunctions['getAccessToken'];
@@ -30,6 +31,7 @@ declare class StaticChaynsApi implements ChaynsReactFunctions {
30
31
  removeVisibilityChangeListener: ChaynsReactFunctions['removeVisibilityChangeListener'];
31
32
  removeToolbarChangeListener: ChaynsReactFunctions['removeToolbarChangeListener'];
32
33
  removeWindowMetricsListener: ChaynsReactFunctions['removeWindowMetricsListener'];
34
+ removeAppleSafeAreaListener: ChaynsReactFunctions['removeAppleSafeAreaListener'];
33
35
  selectPage: ChaynsReactFunctions['selectPage'];
34
36
  scrollToY: ChaynsReactFunctions['scrollToY'];
35
37
  sendMessageToGroup: ChaynsReactFunctions['sendMessageToGroup'];
@@ -90,7 +92,7 @@ declare class StaticChaynsApi implements ChaynsReactFunctions {
90
92
  getPages: () => import("../types/IChaynsReact").Page[];
91
93
  getEnvironment: () => {
92
94
  buildEnvironment: import("../types/IChaynsReact").Environment;
93
- runtimeEnvironment: import("../types/IChaynsReact").RuntimeEnviroment | string;
95
+ runtimeEnvironment: import("../types/IChaynsReact").RuntimeEnvironment | string;
94
96
  };
95
97
  getStyleSettings: () => import("../types/IChaynsReact").ChaynsStyleSettings | undefined;
96
98
  getCustomFunction: (key: string) => (...args: any[]) => Promise<any>;
@@ -0,0 +1,2 @@
1
+ import { ChaynsReactFunctions } from '../types/IChaynsReact';
2
+ export declare const normalizeFunctions: (functions: ChaynsReactFunctions) => ChaynsReactFunctions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chayns-api",
3
- "version": "3.1.6",
3
+ "version": "3.2.0-beta.0",
4
4
  "description": "new chayns api",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",