chayns-api 3.1.7 → 3.2.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.
- package/dist/cjs/calls/appleSafeAreaListener.js +15 -0
- package/dist/cjs/calls/index.js +7 -1
- package/dist/cjs/hooks/index.js +13 -0
- package/dist/cjs/hooks/useSafeArea.js +110 -0
- package/dist/cjs/wrapper/AppWrapper.js +42 -0
- package/dist/cjs/wrapper/FrameWrapper.js +14 -0
- package/dist/cjs/wrapper/ModuleFederationWrapper.js +4 -2
- package/dist/cjs/wrapper/SsrWrapper.js +2 -1
- package/dist/cjs/wrapper/normalizeFunctions.js +88 -0
- package/dist/esm/calls/appleSafeAreaListener.js +8 -0
- package/dist/esm/calls/index.js +3 -0
- package/dist/esm/hooks/index.js +1 -0
- package/dist/esm/hooks/useSafeArea.js +102 -0
- package/dist/esm/wrapper/AppWrapper.js +42 -0
- package/dist/esm/wrapper/FrameWrapper.js +14 -0
- package/dist/esm/wrapper/ModuleFederationWrapper.js +4 -2
- package/dist/esm/wrapper/SsrWrapper.js +2 -1
- package/dist/esm/wrapper/StaticChaynsApi.js +3 -0
- package/dist/esm/wrapper/normalizeFunctions.js +81 -0
- package/dist/types/calls/appleSafeAreaListener.d.ts +11 -0
- package/dist/types/calls/index.d.ts +17 -1
- package/dist/types/hooks/index.d.ts +1 -0
- package/dist/types/hooks/useSafeArea.d.ts +11 -0
- package/dist/types/types/IChaynsReact.d.ts +9 -0
- package/dist/types/wrapper/AppWrapper.d.ts +1 -0
- package/dist/types/wrapper/StaticChaynsApi.d.ts +3 -0
- package/dist/types/wrapper/normalizeFunctions.d.ts +2 -0
- 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;
|
package/dist/cjs/calls/index.js
CHANGED
|
@@ -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.getSafeArea = 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);
|
|
@@ -34,6 +36,8 @@ const getScrollPosition = (...args) => _moduleWrapper.moduleWrapper.current.func
|
|
|
34
36
|
exports.getScrollPosition = getScrollPosition;
|
|
35
37
|
const getWindowMetrics = (...args) => _moduleWrapper.moduleWrapper.current.functions.getWindowMetrics(...args);
|
|
36
38
|
exports.getWindowMetrics = getWindowMetrics;
|
|
39
|
+
const getSafeArea = (...args) => _moduleWrapper.moduleWrapper.current.functions.getAppleSafeArea(...args);
|
|
40
|
+
exports.getSafeArea = getSafeArea;
|
|
37
41
|
const invokeCall = (...args) => _moduleWrapper.moduleWrapper.current.functions.invokeCall(...args);
|
|
38
42
|
exports.invokeCall = invokeCall;
|
|
39
43
|
const invokePaymentCall = (...args) => _moduleWrapper.moduleWrapper.current.functions.invokePaymentCall(...args);
|
|
@@ -70,6 +74,8 @@ const removeVisibilityChangeListener = (...args) => _moduleWrapper.moduleWrapper
|
|
|
70
74
|
exports.removeVisibilityChangeListener = removeVisibilityChangeListener;
|
|
71
75
|
const removeWindowMetricsListener = (...args) => _moduleWrapper.moduleWrapper.current.functions.removeWindowMetricsListener(...args);
|
|
72
76
|
exports.removeWindowMetricsListener = removeWindowMetricsListener;
|
|
77
|
+
const removeAppleSafeAreaListener = (...args) => _moduleWrapper.moduleWrapper.current.functions.removeAppleSafeAreaListener(...args);
|
|
78
|
+
exports.removeAppleSafeAreaListener = removeAppleSafeAreaListener;
|
|
73
79
|
const selectPage = (...args) => _moduleWrapper.moduleWrapper.current.functions.selectPage(...args);
|
|
74
80
|
exports.selectPage = selectPage;
|
|
75
81
|
const scrollByY = (...args) => _moduleWrapper.moduleWrapper.current.functions.scrollByY(...args);
|
package/dist/cjs/hooks/index.js
CHANGED
|
@@ -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 () {
|
|
@@ -249,6 +261,7 @@ var _useIsAdminMode = require("./useIsAdminMode");
|
|
|
249
261
|
var _useUser = require("./useUser");
|
|
250
262
|
var _useAccessToken = require("./useAccessToken");
|
|
251
263
|
var _windowMetricsListener = require("./windowMetricsListener");
|
|
264
|
+
var _useSafeArea = require("./useSafeArea");
|
|
252
265
|
var _useDevice = require("./useDevice");
|
|
253
266
|
var _useSite = require("./useSite");
|
|
254
267
|
var _useParameters = require("./useParameters");
|
|
@@ -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
|
+
}
|
|
@@ -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;
|
|
@@ -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
|
},
|
|
@@ -330,6 +354,20 @@ class AppWrapper {
|
|
|
330
354
|
pageWidth: window.innerWidth,
|
|
331
355
|
topBarHeight: 0
|
|
332
356
|
}),
|
|
357
|
+
getAppleSafeArea: async () => {
|
|
358
|
+
var _v$top, _v$left, _v$bottom, _v$right;
|
|
359
|
+
if (this.latestAppleSafeArea) {
|
|
360
|
+
return this.latestAppleSafeArea;
|
|
361
|
+
}
|
|
362
|
+
const v = await this.appCall(300, {});
|
|
363
|
+
this.latestAppleSafeArea = {
|
|
364
|
+
top: (_v$top = v === null || v === void 0 ? void 0 : v.top) !== null && _v$top !== void 0 ? _v$top : 0,
|
|
365
|
+
left: (_v$left = v === null || v === void 0 ? void 0 : v.left) !== null && _v$left !== void 0 ? _v$left : 0,
|
|
366
|
+
bottom: (_v$bottom = v === null || v === void 0 ? void 0 : v.bottom) !== null && _v$bottom !== void 0 ? _v$bottom : 0,
|
|
367
|
+
right: (_v$right = v === null || v === void 0 ? void 0 : v.right) !== null && _v$right !== void 0 ? _v$right : 0
|
|
368
|
+
};
|
|
369
|
+
return this.latestAppleSafeArea;
|
|
370
|
+
},
|
|
333
371
|
invokeCall: async (value, callback) => {
|
|
334
372
|
return this.appCall(value.action, value.value, {
|
|
335
373
|
callback
|
|
@@ -462,6 +500,10 @@ class AppWrapper {
|
|
|
462
500
|
this.resizeListener = null;
|
|
463
501
|
}
|
|
464
502
|
},
|
|
503
|
+
removeAppleSafeAreaListener: async id => {
|
|
504
|
+
const shouldRemove = (0, _apiListener.removeApiListener)('appleSafeAreaListener', id);
|
|
505
|
+
if (shouldRemove) {}
|
|
506
|
+
},
|
|
465
507
|
selectPage: async options => {
|
|
466
508
|
var _this$values, _this$values2;
|
|
467
509
|
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);
|
|
@@ -85,6 +91,10 @@ class FrameWrapper {
|
|
|
85
91
|
if (!this.initialized) await this.ready;
|
|
86
92
|
return this.exposedFunctions.getWindowMetrics();
|
|
87
93
|
},
|
|
94
|
+
getAppleSafeArea: async () => {
|
|
95
|
+
if (!this.initialized) await this.ready;
|
|
96
|
+
return this.exposedFunctions.getAppleSafeArea();
|
|
97
|
+
},
|
|
88
98
|
invokeCall: async (value, callback) => {
|
|
89
99
|
if (!this.initialized) await this.ready;
|
|
90
100
|
return this.exposedFunctions.invokeCall(value, callback && comlink.proxy(result => callback(result)));
|
|
@@ -149,6 +159,10 @@ class FrameWrapper {
|
|
|
149
159
|
if (!this.initialized) await this.ready;
|
|
150
160
|
return this.exposedFunctions.removeWindowMetricsListener(id);
|
|
151
161
|
},
|
|
162
|
+
removeAppleSafeAreaListener: async id => {
|
|
163
|
+
if (!this.initialized) await this.ready;
|
|
164
|
+
return this.exposedFunctions.removeAppleSafeAreaListener(id);
|
|
165
|
+
},
|
|
152
166
|
removeToolbarChangeListener: async id => {
|
|
153
167
|
if (!this.initialized) await this.ready;
|
|
154
168
|
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(
|
|
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,
|
|
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,88 @@
|
|
|
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
|
+
const baseGetSafeArea = runtimeFunctions.getAppleSafeArea;
|
|
51
|
+
const getAppleSafeArea = async () => {
|
|
52
|
+
if (hasLatestValue && latestValue) {
|
|
53
|
+
return latestValue;
|
|
54
|
+
}
|
|
55
|
+
if (baseGetSafeArea) {
|
|
56
|
+
const result = await baseGetSafeArea();
|
|
57
|
+
dispatch(result);
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
const fallback = {
|
|
61
|
+
top: 0,
|
|
62
|
+
left: 0,
|
|
63
|
+
bottom: 0,
|
|
64
|
+
right: 0
|
|
65
|
+
};
|
|
66
|
+
return fallback;
|
|
67
|
+
};
|
|
68
|
+
return {
|
|
69
|
+
addAppleSafeAreaListener,
|
|
70
|
+
removeAppleSafeAreaListener,
|
|
71
|
+
getAppleSafeArea
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
const normalizeFunctions = functions => {
|
|
75
|
+
var _runtimeFunctions$add2, _runtimeFunctions$rem2, _runtimeFunctions$get;
|
|
76
|
+
const runtimeFunctions = functions;
|
|
77
|
+
if (runtimeFunctions.addAppleSafeAreaListener && runtimeFunctions.removeAppleSafeAreaListener && runtimeFunctions.getAppleSafeArea) {
|
|
78
|
+
return functions;
|
|
79
|
+
}
|
|
80
|
+
const safeAreaFunctions = createAppleSafeAreaFunctions(functions);
|
|
81
|
+
return {
|
|
82
|
+
...functions,
|
|
83
|
+
addAppleSafeAreaListener: (_runtimeFunctions$add2 = runtimeFunctions.addAppleSafeAreaListener) !== null && _runtimeFunctions$add2 !== void 0 ? _runtimeFunctions$add2 : safeAreaFunctions.addAppleSafeAreaListener,
|
|
84
|
+
removeAppleSafeAreaListener: (_runtimeFunctions$rem2 = runtimeFunctions.removeAppleSafeAreaListener) !== null && _runtimeFunctions$rem2 !== void 0 ? _runtimeFunctions$rem2 : safeAreaFunctions.removeAppleSafeAreaListener,
|
|
85
|
+
getAppleSafeArea: (_runtimeFunctions$get = runtimeFunctions.getAppleSafeArea) !== null && _runtimeFunctions$get !== void 0 ? _runtimeFunctions$get : safeAreaFunctions.getAppleSafeArea
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
exports.normalizeFunctions = normalizeFunctions;
|
package/dist/esm/calls/index.js
CHANGED
|
@@ -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);
|
|
@@ -14,6 +15,7 @@ export const getGeoLocation = (...args) => moduleWrapper.current.functions.getGe
|
|
|
14
15
|
export const getUserInfo = (...args) => moduleWrapper.current.functions.getUserInfo(...args);
|
|
15
16
|
export const getScrollPosition = (...args) => moduleWrapper.current.functions.getScrollPosition(...args);
|
|
16
17
|
export const getWindowMetrics = (...args) => moduleWrapper.current.functions.getWindowMetrics(...args);
|
|
18
|
+
export const getSafeArea = (...args) => moduleWrapper.current.functions.getAppleSafeArea(...args);
|
|
17
19
|
export const invokeCall = (...args) => moduleWrapper.current.functions.invokeCall(...args);
|
|
18
20
|
export const invokePaymentCall = (...args) => moduleWrapper.current.functions.invokePaymentCall(...args);
|
|
19
21
|
export const invokeDialogCall = (...args) => moduleWrapper.current.functions.invokeDialogCall(...args);
|
|
@@ -32,6 +34,7 @@ export const removeAccessTokenChangeListener = (...args) => moduleWrapper.curren
|
|
|
32
34
|
export const removeScrollListener = (...args) => moduleWrapper.current.functions.removeScrollListener(...args);
|
|
33
35
|
export const removeVisibilityChangeListener = (...args) => moduleWrapper.current.functions.removeVisibilityChangeListener(...args);
|
|
34
36
|
export const removeWindowMetricsListener = (...args) => moduleWrapper.current.functions.removeWindowMetricsListener(...args);
|
|
37
|
+
export const removeAppleSafeAreaListener = (...args) => moduleWrapper.current.functions.removeAppleSafeAreaListener(...args);
|
|
35
38
|
export const selectPage = (...args) => moduleWrapper.current.functions.selectPage(...args);
|
|
36
39
|
export const scrollByY = (...args) => moduleWrapper.current.functions.scrollByY(...args);
|
|
37
40
|
export const scrollToY = (...args) => moduleWrapper.current.functions.scrollToY(...args);
|
package/dist/esm/hooks/index.js
CHANGED
|
@@ -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';
|
|
@@ -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
|
+
}
|
|
@@ -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
|
},
|
|
@@ -293,6 +317,20 @@ export class AppWrapper {
|
|
|
293
317
|
pageWidth: window.innerWidth,
|
|
294
318
|
topBarHeight: 0
|
|
295
319
|
}),
|
|
320
|
+
getAppleSafeArea: async () => {
|
|
321
|
+
var _v$top, _v$left, _v$bottom, _v$right;
|
|
322
|
+
if (this.latestAppleSafeArea) {
|
|
323
|
+
return this.latestAppleSafeArea;
|
|
324
|
+
}
|
|
325
|
+
const v = await this.appCall(300, {});
|
|
326
|
+
this.latestAppleSafeArea = {
|
|
327
|
+
top: (_v$top = v === null || v === void 0 ? void 0 : v.top) !== null && _v$top !== void 0 ? _v$top : 0,
|
|
328
|
+
left: (_v$left = v === null || v === void 0 ? void 0 : v.left) !== null && _v$left !== void 0 ? _v$left : 0,
|
|
329
|
+
bottom: (_v$bottom = v === null || v === void 0 ? void 0 : v.bottom) !== null && _v$bottom !== void 0 ? _v$bottom : 0,
|
|
330
|
+
right: (_v$right = v === null || v === void 0 ? void 0 : v.right) !== null && _v$right !== void 0 ? _v$right : 0
|
|
331
|
+
};
|
|
332
|
+
return this.latestAppleSafeArea;
|
|
333
|
+
},
|
|
296
334
|
invokeCall: async (value, callback) => {
|
|
297
335
|
return this.appCall(value.action, value.value, {
|
|
298
336
|
callback
|
|
@@ -425,6 +463,10 @@ export class AppWrapper {
|
|
|
425
463
|
this.resizeListener = null;
|
|
426
464
|
}
|
|
427
465
|
},
|
|
466
|
+
removeAppleSafeAreaListener: async id => {
|
|
467
|
+
const shouldRemove = removeApiListener('appleSafeAreaListener', id);
|
|
468
|
+
if (shouldRemove) {}
|
|
469
|
+
},
|
|
428
470
|
selectPage: async options => {
|
|
429
471
|
var _this$values, _this$values2;
|
|
430
472
|
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);
|
|
@@ -81,6 +87,10 @@ export class FrameWrapper {
|
|
|
81
87
|
if (!this.initialized) await this.ready;
|
|
82
88
|
return this.exposedFunctions.getWindowMetrics();
|
|
83
89
|
},
|
|
90
|
+
getAppleSafeArea: async () => {
|
|
91
|
+
if (!this.initialized) await this.ready;
|
|
92
|
+
return this.exposedFunctions.getAppleSafeArea();
|
|
93
|
+
},
|
|
84
94
|
invokeCall: async (value, callback) => {
|
|
85
95
|
if (!this.initialized) await this.ready;
|
|
86
96
|
return this.exposedFunctions.invokeCall(value, callback && comlink.proxy(result => callback(result)));
|
|
@@ -145,6 +155,10 @@ export class FrameWrapper {
|
|
|
145
155
|
if (!this.initialized) await this.ready;
|
|
146
156
|
return this.exposedFunctions.removeWindowMetricsListener(id);
|
|
147
157
|
},
|
|
158
|
+
removeAppleSafeAreaListener: async id => {
|
|
159
|
+
if (!this.initialized) await this.ready;
|
|
160
|
+
return this.exposedFunctions.removeAppleSafeAreaListener(id);
|
|
161
|
+
},
|
|
148
162
|
removeToolbarChangeListener: async id => {
|
|
149
163
|
if (!this.initialized) await this.ready;
|
|
150
164
|
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(
|
|
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,
|
|
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);
|
|
@@ -23,6 +24,7 @@ class StaticChaynsApi {
|
|
|
23
24
|
_defineProperty(this, "getUserInfo", void 0);
|
|
24
25
|
_defineProperty(this, "getScrollPosition", void 0);
|
|
25
26
|
_defineProperty(this, "getWindowMetrics", void 0);
|
|
27
|
+
_defineProperty(this, "getAppleSafeArea", void 0);
|
|
26
28
|
_defineProperty(this, "invokeCall", void 0);
|
|
27
29
|
_defineProperty(this, "invokePaymentCall", void 0);
|
|
28
30
|
_defineProperty(this, "invokeDialogCall", void 0);
|
|
@@ -40,6 +42,7 @@ class StaticChaynsApi {
|
|
|
40
42
|
_defineProperty(this, "removeVisibilityChangeListener", void 0);
|
|
41
43
|
_defineProperty(this, "removeToolbarChangeListener", void 0);
|
|
42
44
|
_defineProperty(this, "removeWindowMetricsListener", void 0);
|
|
45
|
+
_defineProperty(this, "removeAppleSafeAreaListener", void 0);
|
|
43
46
|
_defineProperty(this, "selectPage", void 0);
|
|
44
47
|
_defineProperty(this, "scrollToY", void 0);
|
|
45
48
|
_defineProperty(this, "sendMessageToGroup", void 0);
|
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
const baseGetSafeArea = runtimeFunctions.getAppleSafeArea;
|
|
45
|
+
const getAppleSafeArea = async () => {
|
|
46
|
+
if (hasLatestValue && latestValue) {
|
|
47
|
+
return latestValue;
|
|
48
|
+
}
|
|
49
|
+
if (baseGetSafeArea) {
|
|
50
|
+
const result = await baseGetSafeArea();
|
|
51
|
+
dispatch(result);
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
const fallback = {
|
|
55
|
+
top: 0,
|
|
56
|
+
left: 0,
|
|
57
|
+
bottom: 0,
|
|
58
|
+
right: 0
|
|
59
|
+
};
|
|
60
|
+
return fallback;
|
|
61
|
+
};
|
|
62
|
+
return {
|
|
63
|
+
addAppleSafeAreaListener,
|
|
64
|
+
removeAppleSafeAreaListener,
|
|
65
|
+
getAppleSafeArea
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
export const normalizeFunctions = functions => {
|
|
69
|
+
var _runtimeFunctions$add2, _runtimeFunctions$rem2, _runtimeFunctions$get;
|
|
70
|
+
const runtimeFunctions = functions;
|
|
71
|
+
if (runtimeFunctions.addAppleSafeAreaListener && runtimeFunctions.removeAppleSafeAreaListener && runtimeFunctions.getAppleSafeArea) {
|
|
72
|
+
return functions;
|
|
73
|
+
}
|
|
74
|
+
const safeAreaFunctions = createAppleSafeAreaFunctions(functions);
|
|
75
|
+
return {
|
|
76
|
+
...functions,
|
|
77
|
+
addAppleSafeAreaListener: (_runtimeFunctions$add2 = runtimeFunctions.addAppleSafeAreaListener) !== null && _runtimeFunctions$add2 !== void 0 ? _runtimeFunctions$add2 : safeAreaFunctions.addAppleSafeAreaListener,
|
|
78
|
+
removeAppleSafeAreaListener: (_runtimeFunctions$rem2 = runtimeFunctions.removeAppleSafeAreaListener) !== null && _runtimeFunctions$rem2 !== void 0 ? _runtimeFunctions$rem2 : safeAreaFunctions.removeAppleSafeAreaListener,
|
|
79
|
+
getAppleSafeArea: (_runtimeFunctions$get = runtimeFunctions.getAppleSafeArea) !== null && _runtimeFunctions$get !== void 0 ? _runtimeFunctions$get : safeAreaFunctions.getAppleSafeArea
|
|
80
|
+
};
|
|
81
|
+
};
|
|
@@ -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
|
*/
|
|
@@ -62,6 +67,12 @@ export declare const getScrollPosition: (...args: Parameters<ChaynsReactFunction
|
|
|
62
67
|
* Returns the window metrics.
|
|
63
68
|
*/
|
|
64
69
|
export declare const getWindowMetrics: (...args: Parameters<ChaynsReactFunctions["getWindowMetrics"]>) => Promise<import("../types/IChaynsReact").WindowMetricsListenerResult>;
|
|
70
|
+
/**
|
|
71
|
+
* Returns the current safe area insets on iOS. Can be used outside of a React context
|
|
72
|
+
* (e.g. inside a redux action, thunk or service), as long as the ChaynsProvider has been
|
|
73
|
+
* mounted once.
|
|
74
|
+
*/
|
|
75
|
+
export declare const getSafeArea: (...args: Parameters<ChaynsReactFunctions["getAppleSafeArea"]>) => Promise<import("../types/IChaynsReact").AppleSafeArea>;
|
|
65
76
|
/** @internal */
|
|
66
77
|
export declare const invokeCall: (...args: Parameters<ChaynsReactFunctions["invokeCall"]>) => Promise<any>;
|
|
67
78
|
/** @internal */
|
|
@@ -134,6 +145,11 @@ export declare const removeVisibilityChangeListener: (...args: Parameters<Chayns
|
|
|
134
145
|
* @category Event listener
|
|
135
146
|
*/
|
|
136
147
|
export declare const removeWindowMetricsListener: (...args: Parameters<ChaynsReactFunctions["removeWindowMetricsListener"]>) => Promise<void>;
|
|
148
|
+
/**
|
|
149
|
+
* Removes safe area listener.
|
|
150
|
+
* @category Event listener
|
|
151
|
+
*/
|
|
152
|
+
export declare const removeAppleSafeAreaListener: (...args: Parameters<ChaynsReactFunctions["removeAppleSafeAreaListener"]>) => Promise<void>;
|
|
137
153
|
/**
|
|
138
154
|
* Select other page on chayns site.
|
|
139
155
|
*/
|
|
@@ -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';
|
|
@@ -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;
|
|
@@ -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>;
|
|
@@ -389,6 +390,7 @@ export interface ChaynsReactFunctions {
|
|
|
389
390
|
getUserInfo: (value: UserInfoQuery) => Promise<UserInfo | null>;
|
|
390
391
|
getScrollPosition: () => Promise<ScrollListenerResult>;
|
|
391
392
|
getWindowMetrics: () => Promise<WindowMetricsListenerResult>;
|
|
393
|
+
getAppleSafeArea: () => Promise<AppleSafeArea>;
|
|
392
394
|
invokeCall: (value: InvokeCall, callback?: (result: any) => void) => Promise<any>;
|
|
393
395
|
invokePaymentCall: <T>(value: InvokeCall, callback?: (result: T) => void) => Promise<T>;
|
|
394
396
|
invokeDialogCall: (value: InvokeCall, callback?: (result: any) => void) => Promise<any>;
|
|
@@ -406,6 +408,7 @@ export interface ChaynsReactFunctions {
|
|
|
406
408
|
removeVisibilityChangeListener: (value: number) => Promise<void>;
|
|
407
409
|
removeToolbarChangeListener: (value: number) => Promise<void>;
|
|
408
410
|
removeWindowMetricsListener: (value: number) => Promise<void>;
|
|
411
|
+
removeAppleSafeAreaListener: (value: number) => Promise<void>;
|
|
409
412
|
selectPage: (value: SelectPage) => Promise<void>;
|
|
410
413
|
scrollToY: (position: number, duration: number) => Promise<void>;
|
|
411
414
|
sendMessageToGroup: (groupId: number, message: IntercomMessage) => Promise<Response>;
|
|
@@ -1053,6 +1056,12 @@ export declare enum DialogIconType {
|
|
|
1053
1056
|
export type AnonymousAccountResult = {
|
|
1054
1057
|
token: string;
|
|
1055
1058
|
};
|
|
1059
|
+
export interface AppleSafeArea {
|
|
1060
|
+
top: number;
|
|
1061
|
+
left: number;
|
|
1062
|
+
bottom: number;
|
|
1063
|
+
right: number;
|
|
1064
|
+
}
|
|
1056
1065
|
export type PageMainGroupType = {
|
|
1057
1066
|
Id: 1;
|
|
1058
1067
|
Administration: 2;
|
|
@@ -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'];
|
|
@@ -13,6 +14,7 @@ declare class StaticChaynsApi implements ChaynsReactFunctions {
|
|
|
13
14
|
getUserInfo: ChaynsReactFunctions['getUserInfo'];
|
|
14
15
|
getScrollPosition: ChaynsReactFunctions['getScrollPosition'];
|
|
15
16
|
getWindowMetrics: ChaynsReactFunctions['getWindowMetrics'];
|
|
17
|
+
getAppleSafeArea: ChaynsReactFunctions['getAppleSafeArea'];
|
|
16
18
|
invokeCall: ChaynsReactFunctions['invokeCall'];
|
|
17
19
|
invokePaymentCall: ChaynsReactFunctions['invokePaymentCall'];
|
|
18
20
|
invokeDialogCall: ChaynsReactFunctions['invokeDialogCall'];
|
|
@@ -30,6 +32,7 @@ declare class StaticChaynsApi implements ChaynsReactFunctions {
|
|
|
30
32
|
removeVisibilityChangeListener: ChaynsReactFunctions['removeVisibilityChangeListener'];
|
|
31
33
|
removeToolbarChangeListener: ChaynsReactFunctions['removeToolbarChangeListener'];
|
|
32
34
|
removeWindowMetricsListener: ChaynsReactFunctions['removeWindowMetricsListener'];
|
|
35
|
+
removeAppleSafeAreaListener: ChaynsReactFunctions['removeAppleSafeAreaListener'];
|
|
33
36
|
selectPage: ChaynsReactFunctions['selectPage'];
|
|
34
37
|
scrollToY: ChaynsReactFunctions['scrollToY'];
|
|
35
38
|
sendMessageToGroup: ChaynsReactFunctions['sendMessageToGroup'];
|