chayns-api 3.6.7 → 3.6.9

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.
@@ -4,21 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.addAppleSafeAreaListener = void 0;
7
+ var _index = require("./index");
7
8
  const addAppleSafeAreaListener = ({
8
- callback,
9
- invokeCall
9
+ callback
10
10
  }) => {
11
- void invokeCall({
11
+ void (0, _index.invokeCall)({
12
12
  action: 300
13
- }, result => {
14
- const value = result && 'retVal' in result ? result.retVal : result;
15
- callback({
16
- top: 0,
17
- left: 0,
18
- bottom: 0,
19
- right: 0,
20
- ...value
21
- });
22
- });
13
+ }, callback);
23
14
  };
24
15
  exports.addAppleSafeAreaListener = addAppleSafeAreaListener;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ const reloadChaynsCss = systemFontSize => {
4
+ const currentLink = document.querySelector('link[rel="stylesheet"][href*="style-staging.tobit.cloud/css/"], ' + 'link[rel="stylesheet"][href*="style.tobit.cloud/css/"]');
5
+ if (!currentLink) {
6
+ console.warn('Stylesheet nicht gefunden.');
7
+ return;
8
+ }
9
+ const url = new URL(currentLink.href);
10
+ url.searchParams.set('systemFontSize', String(systemFontSize));
11
+ const newLink = document.createElement('link');
12
+ newLink.rel = 'stylesheet';
13
+ newLink.type = 'text/css';
14
+ newLink.href = url.toString();
15
+ newLink.onload = () => {
16
+ currentLink.remove();
17
+ };
18
+ newLink.onerror = () => {
19
+ newLink.remove();
20
+ console.error('[chayns-api] Error loading chayns-css with systemFontSize:', systemFontSize);
21
+ };
22
+ currentLink.after(newLink);
23
+ };
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.AppWrapper = void 0;
7
7
  var _lodash = _interopRequireDefault(require("lodash.throttle"));
8
8
  var _getUserInfo = _interopRequireDefault(require("../calls/getUserInfo"));
9
- var _appleSafeAreaListener = require("../calls/appleSafeAreaListener");
10
9
  var _sendMessage = require("../calls/sendMessage");
11
10
  var _constants = require("../constants");
12
11
  var _trustedDomains = require("../constants/trustedDomains");
@@ -167,13 +166,6 @@ class AppWrapper {
167
166
  console.warn(`call ${call} not implement in app`);
168
167
  }
169
168
  counter = 0;
170
- getCallbackName() {
171
- let callbackName;
172
- do {
173
- callbackName = `chaynsApiV5Callback_${this.counter++}`;
174
- } while (callbackName in window);
175
- return callbackName;
176
- }
177
169
  appCall(action, value = {}, {
178
170
  callback,
179
171
  awaitResult = true
@@ -186,7 +178,7 @@ class AppWrapper {
186
178
  return;
187
179
  }
188
180
  return new Promise(resolve => {
189
- const callbackName = this.getCallbackName();
181
+ const callbackName = `chaynsApiV5Callback_${this.counter++}`;
190
182
  window[callbackName] = v => {
191
183
  var _v$retVal2;
192
184
  if (callback) {
@@ -305,19 +297,26 @@ class AppWrapper {
305
297
  const {
306
298
  id,
307
299
  shouldInitialize
308
- } = (0, _apiListener.addApiListener)('appleSafeAreaListener', value => {
309
- this.latestAppleSafeArea = value;
310
- callback(value);
311
- });
300
+ } = (0, _apiListener.addApiListener)('appleSafeAreaListener', callback);
312
301
  if (this.latestAppleSafeArea) {
313
302
  callback(this.latestAppleSafeArea);
314
303
  }
315
304
  if (shouldInitialize) {
316
- (0, _appleSafeAreaListener.addAppleSafeAreaListener)({
317
- invokeCall: this.functions.invokeCall,
318
- callback: value => {
319
- this.latestAppleSafeArea = value;
320
- (0, _apiListener.dispatchApiEvent)('appleSafeAreaListener', value);
305
+ void this.appCall(300, {}, {
306
+ callback: v => {
307
+ this.latestAppleSafeArea = {
308
+ top: v.top,
309
+ left: v.left,
310
+ bottom: v.bottom,
311
+ right: v.right,
312
+ ...(v.hingeAngle === undefined ? {} : {
313
+ hingeAngle: v.hingeAngle
314
+ }),
315
+ ...(v.hingeStatus === undefined ? {} : {
316
+ hingeStatus: v.hingeStatus
317
+ })
318
+ };
319
+ (0, _apiListener.dispatchApiEvent)('appleSafeAreaListener', this.latestAppleSafeArea);
321
320
  }
322
321
  });
323
322
  }
@@ -367,19 +366,24 @@ class AppWrapper {
367
366
  topBarHeight: 0
368
367
  }),
369
368
  getAppleSafeArea: async () => {
369
+ var _v$top, _v$left, _v$bottom, _v$right;
370
370
  if (this.latestAppleSafeArea) {
371
371
  return this.latestAppleSafeArea;
372
372
  }
373
- let resolveValue;
374
- const result = new Promise(resolve => {
375
- resolveValue = resolve;
376
- });
377
- const id = await this.functions.addAppleSafeAreaListener(resolveValue);
378
- try {
379
- return await result;
380
- } finally {
381
- await this.functions.removeAppleSafeAreaListener(id);
382
- }
373
+ const v = await this.appCall(300, {});
374
+ this.latestAppleSafeArea = {
375
+ top: (_v$top = v === null || v === void 0 ? void 0 : v.top) !== null && _v$top !== void 0 ? _v$top : 0,
376
+ left: (_v$left = v === null || v === void 0 ? void 0 : v.left) !== null && _v$left !== void 0 ? _v$left : 0,
377
+ bottom: (_v$bottom = v === null || v === void 0 ? void 0 : v.bottom) !== null && _v$bottom !== void 0 ? _v$bottom : 0,
378
+ right: (_v$right = v === null || v === void 0 ? void 0 : v.right) !== null && _v$right !== void 0 ? _v$right : 0,
379
+ ...((v === null || v === void 0 ? void 0 : v.hingeAngle) === undefined ? {} : {
380
+ hingeAngle: v.hingeAngle
381
+ }),
382
+ ...((v === null || v === void 0 ? void 0 : v.hingeStatus) === undefined ? {} : {
383
+ hingeStatus: v.hingeStatus
384
+ })
385
+ };
386
+ return this.latestAppleSafeArea;
383
387
  },
384
388
  invokeCall: async (value, callback) => {
385
389
  return this.appCall(value.action, value.value, {
@@ -392,7 +396,7 @@ class AppWrapper {
392
396
  });
393
397
  },
394
398
  invokeDialogCall: async (value, callback) => {
395
- const callbackName = this.getCallbackName();
399
+ const callbackName = `chaynsApiV5Callback_${this.counter++}`;
396
400
  window[callbackName] = ({
397
401
  retVal
398
402
  }) => {
@@ -522,7 +526,8 @@ class AppWrapper {
522
526
  }
523
527
  },
524
528
  removeAppleSafeAreaListener: async id => {
525
- (0, _apiListener.removeApiListener)('appleSafeAreaListener', id);
529
+ const shouldRemove = (0, _apiListener.removeApiListener)('appleSafeAreaListener', id);
530
+ if (shouldRemove) {}
526
531
  },
527
532
  selectPage: async options => {
528
533
  var _this$values, _this$values2;
@@ -810,7 +815,8 @@ class AppWrapper {
810
815
  enabled: true
811
816
  }, {
812
817
  callback: ({
813
- colorMode
818
+ colorMode,
819
+ systemFontSize
814
820
  }) => {
815
821
  this.values = {
816
822
  ...this.values,
@@ -825,6 +831,9 @@ class AppWrapper {
825
831
  value: this.values.site
826
832
  }
827
833
  }));
834
+ if (typeof systemFontSize === 'number' && systemFontSize > 0) {
835
+ reloadChaynsCss(systemFontSize);
836
+ }
828
837
  },
829
838
  awaitResult: true
830
839
  });
@@ -4,67 +4,66 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.normalizeFunctions = void 0;
7
- var _appleSafeAreaListener = require("../calls/appleSafeAreaListener");
8
- var _apiListener = require("../utils/apiListener");
9
7
  const createAppleSafeAreaFunctions = functions => {
8
+ var _runtimeFunctions$add, _runtimeFunctions$rem;
10
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;
11
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
+ };
12
29
  const addAppleSafeAreaListener = callback => {
13
- const handleValue = value => {
14
- latestValue = value;
15
- callback(value);
16
- };
17
- if (runtimeFunctions.addAppleSafeAreaListener) {
18
- return runtimeFunctions.addAppleSafeAreaListener(handleValue);
19
- }
20
- const {
21
- id,
22
- shouldInitialize
23
- } = (0, _apiListener.addApiListener)('appleSafeAreaListener', handleValue);
24
- if (latestValue) {
30
+ const id = ++counter;
31
+ listeners[id] = callback;
32
+ if (hasLatestValue && latestValue) {
25
33
  callback(latestValue);
26
34
  }
27
- if (shouldInitialize && runtimeFunctions.invokeCall) {
28
- (0, _appleSafeAreaListener.addAppleSafeAreaListener)({
29
- invokeCall: runtimeFunctions.invokeCall,
30
- callback: value => {
31
- latestValue = value;
32
- (0, _apiListener.dispatchApiEvent)('appleSafeAreaListener', value);
33
- }
35
+ if (!upstreamListenerId) {
36
+ upstreamListenerId = baseAddListener(result => {
37
+ dispatch(result);
34
38
  });
35
39
  }
36
40
  return Promise.resolve(id);
37
41
  };
38
42
  const removeAppleSafeAreaListener = id => {
39
- if (runtimeFunctions.addAppleSafeAreaListener) {
40
- var _runtimeFunctions$rem, _runtimeFunctions$rem2;
41
- return (_runtimeFunctions$rem = (_runtimeFunctions$rem2 = runtimeFunctions.removeAppleSafeAreaListener) === null || _runtimeFunctions$rem2 === void 0 ? void 0 : _runtimeFunctions$rem2.call(runtimeFunctions, id)) !== null && _runtimeFunctions$rem !== void 0 ? _runtimeFunctions$rem : Promise.resolve();
43
+ delete listeners[id];
44
+ if (Object.keys(listeners).length === 0 && upstreamListenerId) {
45
+ void upstreamListenerId.then(listenerId => baseRemoveListener(listenerId));
46
+ upstreamListenerId = null;
42
47
  }
43
- (0, _apiListener.removeApiListener)('appleSafeAreaListener', id);
44
48
  return Promise.resolve();
45
49
  };
50
+ const baseGetSafeArea = runtimeFunctions.getAppleSafeArea;
46
51
  const getAppleSafeArea = async () => {
47
- if (latestValue) {
52
+ if (hasLatestValue && latestValue) {
48
53
  return latestValue;
49
54
  }
50
- if (!runtimeFunctions.addAppleSafeAreaListener && !runtimeFunctions.invokeCall) {
51
- return {
52
- top: 0,
53
- left: 0,
54
- bottom: 0,
55
- right: 0
56
- };
57
- }
58
- let resolveValue;
59
- const result = new Promise(resolve => {
60
- resolveValue = resolve;
61
- });
62
- const id = await addAppleSafeAreaListener(resolveValue);
63
- try {
64
- return await result;
65
- } finally {
66
- await removeAppleSafeAreaListener(id);
55
+ if (baseGetSafeArea) {
56
+ const result = await baseGetSafeArea();
57
+ dispatch(result);
58
+ return result;
67
59
  }
60
+ const fallback = {
61
+ top: 0,
62
+ left: 0,
63
+ bottom: 0,
64
+ right: 0
65
+ };
66
+ return fallback;
68
67
  };
69
68
  return {
70
69
  addAppleSafeAreaListener,
@@ -1,17 +1,8 @@
1
+ import { invokeCall } from './index';
1
2
  export const addAppleSafeAreaListener = ({
2
- callback,
3
- invokeCall
3
+ callback
4
4
  }) => {
5
5
  void invokeCall({
6
6
  action: 300
7
- }, result => {
8
- const value = result && 'retVal' in result ? result.retVal : result;
9
- callback({
10
- top: 0,
11
- left: 0,
12
- bottom: 0,
13
- right: 0,
14
- ...value
15
- });
16
- });
7
+ }, callback);
17
8
  };
@@ -0,0 +1,21 @@
1
+ const reloadChaynsCss = systemFontSize => {
2
+ const currentLink = document.querySelector('link[rel="stylesheet"][href*="style-staging.tobit.cloud/css/"], ' + 'link[rel="stylesheet"][href*="style.tobit.cloud/css/"]');
3
+ if (!currentLink) {
4
+ console.warn('Stylesheet nicht gefunden.');
5
+ return;
6
+ }
7
+ const url = new URL(currentLink.href);
8
+ url.searchParams.set('systemFontSize', String(systemFontSize));
9
+ const newLink = document.createElement('link');
10
+ newLink.rel = 'stylesheet';
11
+ newLink.type = 'text/css';
12
+ newLink.href = url.toString();
13
+ newLink.onload = () => {
14
+ currentLink.remove();
15
+ };
16
+ newLink.onerror = () => {
17
+ newLink.remove();
18
+ console.error('[chayns-api] Error loading chayns-css with systemFontSize:', systemFontSize);
19
+ };
20
+ currentLink.after(newLink);
21
+ };
@@ -3,7 +3,6 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
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
4
  import throttle from 'lodash.throttle';
5
5
  import getUserInfo from '../calls/getUserInfo';
6
- import { addAppleSafeAreaListener as addNativeAppleSafeAreaListener } from '../calls/appleSafeAreaListener';
7
6
  import { sendMessageToGroup, sendMessageToPage, sendMessageToUser } from '../calls/sendMessage';
8
7
  import { DefaultLoginDialogOptions } from '../constants';
9
8
  import { DefaultTrustedDomains } from '../constants/trustedDomains';
@@ -261,19 +260,26 @@ export class AppWrapper {
261
260
  const {
262
261
  id,
263
262
  shouldInitialize
264
- } = addApiListener('appleSafeAreaListener', value => {
265
- this.latestAppleSafeArea = value;
266
- callback(value);
267
- });
263
+ } = addApiListener('appleSafeAreaListener', callback);
268
264
  if (this.latestAppleSafeArea) {
269
265
  callback(this.latestAppleSafeArea);
270
266
  }
271
267
  if (shouldInitialize) {
272
- addNativeAppleSafeAreaListener({
273
- invokeCall: this.functions.invokeCall,
274
- callback: value => {
275
- this.latestAppleSafeArea = value;
276
- dispatchApiEvent('appleSafeAreaListener', value);
268
+ void this.appCall(300, {}, {
269
+ callback: v => {
270
+ this.latestAppleSafeArea = {
271
+ top: v.top,
272
+ left: v.left,
273
+ bottom: v.bottom,
274
+ right: v.right,
275
+ ...(v.hingeAngle === undefined ? {} : {
276
+ hingeAngle: v.hingeAngle
277
+ }),
278
+ ...(v.hingeStatus === undefined ? {} : {
279
+ hingeStatus: v.hingeStatus
280
+ })
281
+ };
282
+ dispatchApiEvent('appleSafeAreaListener', this.latestAppleSafeArea);
277
283
  }
278
284
  });
279
285
  }
@@ -323,19 +329,24 @@ export class AppWrapper {
323
329
  topBarHeight: 0
324
330
  }),
325
331
  getAppleSafeArea: async () => {
332
+ var _v$top, _v$left, _v$bottom, _v$right;
326
333
  if (this.latestAppleSafeArea) {
327
334
  return this.latestAppleSafeArea;
328
335
  }
329
- let resolveValue;
330
- const result = new Promise(resolve => {
331
- resolveValue = resolve;
332
- });
333
- const id = await this.functions.addAppleSafeAreaListener(resolveValue);
334
- try {
335
- return await result;
336
- } finally {
337
- await this.functions.removeAppleSafeAreaListener(id);
338
- }
336
+ const v = await this.appCall(300, {});
337
+ this.latestAppleSafeArea = {
338
+ top: (_v$top = v === null || v === void 0 ? void 0 : v.top) !== null && _v$top !== void 0 ? _v$top : 0,
339
+ left: (_v$left = v === null || v === void 0 ? void 0 : v.left) !== null && _v$left !== void 0 ? _v$left : 0,
340
+ bottom: (_v$bottom = v === null || v === void 0 ? void 0 : v.bottom) !== null && _v$bottom !== void 0 ? _v$bottom : 0,
341
+ right: (_v$right = v === null || v === void 0 ? void 0 : v.right) !== null && _v$right !== void 0 ? _v$right : 0,
342
+ ...((v === null || v === void 0 ? void 0 : v.hingeAngle) === undefined ? {} : {
343
+ hingeAngle: v.hingeAngle
344
+ }),
345
+ ...((v === null || v === void 0 ? void 0 : v.hingeStatus) === undefined ? {} : {
346
+ hingeStatus: v.hingeStatus
347
+ })
348
+ };
349
+ return this.latestAppleSafeArea;
339
350
  },
340
351
  invokeCall: async (value, callback) => {
341
352
  return this.appCall(value.action, value.value, {
@@ -348,7 +359,7 @@ export class AppWrapper {
348
359
  });
349
360
  },
350
361
  invokeDialogCall: async (value, callback) => {
351
- const callbackName = this.getCallbackName();
362
+ const callbackName = `chaynsApiV5Callback_${this.counter++}`;
352
363
  window[callbackName] = ({
353
364
  retVal
354
365
  }) => {
@@ -478,7 +489,8 @@ export class AppWrapper {
478
489
  }
479
490
  },
480
491
  removeAppleSafeAreaListener: async id => {
481
- removeApiListener('appleSafeAreaListener', id);
492
+ const shouldRemove = removeApiListener('appleSafeAreaListener', id);
493
+ if (shouldRemove) {}
482
494
  },
483
495
  selectPage: async options => {
484
496
  var _this$values, _this$values2;
@@ -752,13 +764,6 @@ export class AppWrapper {
752
764
  notImplemented(call) {
753
765
  console.warn(`call ${call} not implement in app`);
754
766
  }
755
- getCallbackName() {
756
- let callbackName;
757
- do {
758
- callbackName = `chaynsApiV5Callback_${this.counter++}`;
759
- } while (callbackName in window);
760
- return callbackName;
761
- }
762
767
  appCall(action, value = {}, {
763
768
  callback,
764
769
  awaitResult = true
@@ -771,7 +776,7 @@ export class AppWrapper {
771
776
  return;
772
777
  }
773
778
  return new Promise(resolve => {
774
- const callbackName = this.getCallbackName();
779
+ const callbackName = `chaynsApiV5Callback_${this.counter++}`;
775
780
  window[callbackName] = v => {
776
781
  var _v$retVal2;
777
782
  if (callback) {
@@ -816,7 +821,8 @@ export class AppWrapper {
816
821
  enabled: true
817
822
  }, {
818
823
  callback: ({
819
- colorMode
824
+ colorMode,
825
+ systemFontSize
820
826
  }) => {
821
827
  this.values = {
822
828
  ...this.values,
@@ -831,6 +837,9 @@ export class AppWrapper {
831
837
  value: this.values.site
832
838
  }
833
839
  }));
840
+ if (typeof systemFontSize === 'number' && systemFontSize > 0) {
841
+ reloadChaynsCss(systemFontSize);
842
+ }
834
843
  },
835
844
  awaitResult: true
836
845
  });
@@ -1,64 +1,63 @@
1
- import { addAppleSafeAreaListener as addNativeAppleSafeAreaListener } from '../calls/appleSafeAreaListener';
2
- import { addApiListener, dispatchApiEvent, removeApiListener } from '../utils/apiListener';
3
1
  const createAppleSafeAreaFunctions = functions => {
2
+ var _runtimeFunctions$add, _runtimeFunctions$rem;
4
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;
5
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
+ };
6
23
  const addAppleSafeAreaListener = callback => {
7
- const handleValue = value => {
8
- latestValue = value;
9
- callback(value);
10
- };
11
- if (runtimeFunctions.addAppleSafeAreaListener) {
12
- return runtimeFunctions.addAppleSafeAreaListener(handleValue);
13
- }
14
- const {
15
- id,
16
- shouldInitialize
17
- } = addApiListener('appleSafeAreaListener', handleValue);
18
- if (latestValue) {
24
+ const id = ++counter;
25
+ listeners[id] = callback;
26
+ if (hasLatestValue && latestValue) {
19
27
  callback(latestValue);
20
28
  }
21
- if (shouldInitialize && runtimeFunctions.invokeCall) {
22
- addNativeAppleSafeAreaListener({
23
- invokeCall: runtimeFunctions.invokeCall,
24
- callback: value => {
25
- latestValue = value;
26
- dispatchApiEvent('appleSafeAreaListener', value);
27
- }
29
+ if (!upstreamListenerId) {
30
+ upstreamListenerId = baseAddListener(result => {
31
+ dispatch(result);
28
32
  });
29
33
  }
30
34
  return Promise.resolve(id);
31
35
  };
32
36
  const removeAppleSafeAreaListener = id => {
33
- if (runtimeFunctions.addAppleSafeAreaListener) {
34
- var _runtimeFunctions$rem, _runtimeFunctions$rem2;
35
- return (_runtimeFunctions$rem = (_runtimeFunctions$rem2 = runtimeFunctions.removeAppleSafeAreaListener) === null || _runtimeFunctions$rem2 === void 0 ? void 0 : _runtimeFunctions$rem2.call(runtimeFunctions, id)) !== null && _runtimeFunctions$rem !== void 0 ? _runtimeFunctions$rem : Promise.resolve();
37
+ delete listeners[id];
38
+ if (Object.keys(listeners).length === 0 && upstreamListenerId) {
39
+ void upstreamListenerId.then(listenerId => baseRemoveListener(listenerId));
40
+ upstreamListenerId = null;
36
41
  }
37
- removeApiListener('appleSafeAreaListener', id);
38
42
  return Promise.resolve();
39
43
  };
44
+ const baseGetSafeArea = runtimeFunctions.getAppleSafeArea;
40
45
  const getAppleSafeArea = async () => {
41
- if (latestValue) {
46
+ if (hasLatestValue && latestValue) {
42
47
  return latestValue;
43
48
  }
44
- if (!runtimeFunctions.addAppleSafeAreaListener && !runtimeFunctions.invokeCall) {
45
- return {
46
- top: 0,
47
- left: 0,
48
- bottom: 0,
49
- right: 0
50
- };
51
- }
52
- let resolveValue;
53
- const result = new Promise(resolve => {
54
- resolveValue = resolve;
55
- });
56
- const id = await addAppleSafeAreaListener(resolveValue);
57
- try {
58
- return await result;
59
- } finally {
60
- await removeAppleSafeAreaListener(id);
49
+ if (baseGetSafeArea) {
50
+ const result = await baseGetSafeArea();
51
+ dispatch(result);
52
+ return result;
61
53
  }
54
+ const fallback = {
55
+ top: 0,
56
+ left: 0,
57
+ bottom: 0,
58
+ right: 0
59
+ };
60
+ return fallback;
62
61
  };
63
62
  return {
64
63
  addAppleSafeAreaListener,
@@ -1,11 +1,11 @@
1
- import { AppleSafeArea, ChaynsReactFunctions } from '../types/IChaynsReact';
1
+ import { AppleSafeArea } from '../types/IChaynsReact';
2
2
  export interface AddAppleSafeAreaListenerOptions {
3
3
  callback: (safeArea: AppleSafeArea) => void;
4
- invokeCall: ChaynsReactFunctions['invokeCall'];
5
4
  }
6
5
  /**
7
- * Registers the native safe-area callback, preserving the complete result including optional
8
- * iPhone Duo hinge metadata. Callers must use the API listener registry to share this callback.
6
+ * Directly invokes the Apple Safe Area listener call.
7
+ * This is used internally by the module wrapper.
8
+ *
9
9
  * @internal
10
10
  */
11
- export declare const addAppleSafeAreaListener: ({ callback, invokeCall }: AddAppleSafeAreaListenerOptions) => void;
11
+ export declare const addAppleSafeAreaListener: ({ callback }: AddAppleSafeAreaListenerOptions) => void;
@@ -0,0 +1 @@
1
+ declare const reloadChaynsCss: (systemFontSize: number) => void;
@@ -14,7 +14,6 @@ export declare class AppWrapper implements IChaynsReact {
14
14
  chaynsApiId: string;
15
15
  notImplemented(call: string): void;
16
16
  counter: number;
17
- private getCallbackName;
18
17
  appCall(action: any, value?: unknown, { callback, awaitResult }?: {
19
18
  awaitResult?: boolean | undefined;
20
19
  }): Promise<unknown> | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chayns-api",
3
- "version": "3.6.7",
3
+ "version": "3.6.9",
4
4
  "description": "new chayns api",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -23,8 +23,7 @@ let listenerIds;
23
23
  let root;
24
24
  let currentValue;
25
25
 
26
- const emit = (value) => {
27
- const call = nativeCalls.findLast(({ action }) => action === 300);
26
+ const emit = (value, call = nativeCalls.at(-1)) => {
28
27
  const callbackName = call.value.callback.replace(/^window\./, '');
29
28
  window[callbackName]({ retVal: value });
30
29
  };
@@ -72,10 +71,10 @@ test('exports the three native hinge status values through the public entry poin
72
71
 
73
72
  for (const hingeStatus of Object.values(HingeStatus)) {
74
73
  test(`preserves ${hingeStatus} and a zero angle in a direct safe-area request`, async () => {
75
- const expected = { ...insets, hingeAngle: 0, hingeStatus, additionalNativeValue: 42 };
74
+ const expected = { ...insets, hingeAngle: 0, hingeStatus };
76
75
  const pending = wrapper.functions.getAppleSafeArea();
77
76
  assert.equal(nativeCalls[0].action, 300);
78
- emit(expected);
77
+ emit({ ...expected, unrelated: 'ignored' });
79
78
  assert.deepEqual(await pending, expected);
80
79
  assert.deepEqual(await wrapper.functions.getAppleSafeArea(), expected);
81
80
  assert.equal(nativeCalls.length, 1);
@@ -103,9 +102,10 @@ test('retains the existing zero-inset fallback for an absent native response', a
103
102
  test('updates the listener cache and new subscribers when only hinge metadata changes', async () => {
104
103
  const values = [];
105
104
  await subscribe((value) => values.push(value));
105
+ const stream = nativeCalls[0];
106
106
  for (const hingeStatus of Object.values(HingeStatus)) {
107
107
  const expected = { ...insets, hingeAngle: 90, hingeStatus };
108
- emit(expected);
108
+ emit(expected, stream);
109
109
  assert.deepEqual(values.at(-1), expected);
110
110
  assert.deepEqual(await wrapper.functions.getAppleSafeArea(), expected);
111
111
  }
@@ -124,69 +124,38 @@ test('stops delivering native updates to removed listeners', async () => {
124
124
  assert.deepEqual(values, []);
125
125
  });
126
126
 
127
- test('shares one native callback between compatibility wrappers and keeps remaining listeners active', async () => {
127
+ test('passes hinge updates through the existing compatibility fallback unchanged', async () => {
128
128
  let dispatch;
129
- let calls = 0;
130
- const host = {
129
+ const functions = normalizeFunctions({
131
130
  invokeCall: (options, callback) => {
132
131
  assert.equal(options.action, 300);
133
- calls += 1;
134
132
  dispatch = callback;
135
133
  return Promise.resolve();
136
134
  },
137
- };
138
- const first = normalizeFunctions(host);
139
- const second = normalizeFunctions(host);
140
- const firstValues = [];
141
- const secondValues = [];
142
- const firstId = await first.addAppleSafeAreaListener((value) => firstValues.push(value));
143
- const secondId = await second.addAppleSafeAreaListener((value) => secondValues.push(value));
144
- try {
145
- assert.equal(calls, 1);
146
- const expected = { ...insets, hingeAngle: 90, hingeStatus: HingeStatus.PartiallyOpen };
147
- dispatch(expected);
148
- assert.deepEqual(firstValues, [expected]);
149
- assert.deepEqual(secondValues, [expected]);
150
- assert.deepEqual(await first.getAppleSafeArea(), expected);
151
- assert.deepEqual(await second.getAppleSafeArea(), expected);
152
- await first.removeAppleSafeAreaListener(firstId);
153
- const opened = { ...expected, hingeAngle: 180, hingeStatus: HingeStatus.FullyOpen };
154
- dispatch(opened);
155
- assert.deepEqual(firstValues, [expected]);
156
- assert.deepEqual(secondValues, [expected, opened]);
157
- } finally {
158
- await first.removeAppleSafeAreaListener(firstId);
159
- await second.removeAppleSafeAreaListener(secondId);
160
- }
161
- });
162
-
163
- test('shares the active native callback with concurrent getters and preserves subsequent hinge updates', async () => {
135
+ });
164
136
  const values = [];
165
- await subscribe((value) => values.push(value));
166
- const first = wrapper.functions.getAppleSafeArea();
167
- const second = wrapper.functions.getAppleSafeArea();
168
- assert.equal(nativeCalls.length, 1);
169
- const closed = { ...insets, hingeAngle: 0, hingeStatus: HingeStatus.Closed };
170
- emit(closed); // Only the most recently registered native callback is called.
171
- assert.deepEqual(await Promise.all([first, second]), [closed, closed]);
172
- const opened = { ...insets, hingeAngle: 180, hingeStatus: HingeStatus.FullyOpen };
173
- emit(opened);
174
- assert.deepEqual(values, [closed, opened]);
175
- assert.deepEqual(await wrapper.functions.getAppleSafeArea(), opened);
176
- assert.equal(nativeCalls.length, 1);
137
+ const id = await functions.addAppleSafeAreaListener((value) => values.push(value));
138
+ const expected = { ...insets, hingeAngle: 90, hingeStatus: HingeStatus.PartiallyOpen };
139
+ dispatch(expected);
140
+ assert.deepEqual(values, [expected]);
141
+ assert.deepEqual(await functions.getAppleSafeArea(), expected);
142
+ await functions.removeAppleSafeAreaListener(id);
143
+ dispatch({ ...expected, hingeStatus: HingeStatus.FullyOpen });
144
+ assert.deepEqual(values, [expected]);
177
145
  });
178
146
 
179
147
  test('updates the actual hook through native folding events with identical insets', async () => {
180
148
  await renderHook();
149
+ const stream = nativeCalls[0];
181
150
  for (const hingeStatus of Object.values(HingeStatus)) {
182
151
  const expected = { ...insets, hingeAngle: 90, hingeStatus };
183
- await act(async () => emit(expected));
152
+ await act(async () => emit(expected, stream));
184
153
  assert.deepEqual(currentValue, expected);
185
154
  }
186
155
  assert.equal(nativeCalls.length, 1);
187
156
  const beforeCleanup = currentValue;
188
157
  await renderHook(false);
189
- emit({ ...insets, hingeAngle: 0, hingeStatus: HingeStatus.Closed });
158
+ emit({ ...insets, hingeAngle: 0, hingeStatus: HingeStatus.Closed }, stream);
190
159
  assert.equal(currentValue, beforeCleanup);
191
160
  });
192
161
 
@@ -205,29 +174,3 @@ test('does not register native listeners on unsupported runtimes', async () => {
205
174
  assert.equal(nativeCalls.length, 0);
206
175
  assert.deepEqual(currentValue, { top: 0, left: 0, bottom: 0, right: 0 });
207
176
  });
208
-
209
- for (const useDialogCall of [false, true]) {
210
- test(`keeps the safe-area callback intact when another wrapper registers a ${useDialogCall ? 'dialog' : 'regular'} call`, async () => {
211
- const values = [];
212
- await subscribe((value) => values.push(value));
213
- const safeAreaCallback = nativeCalls.at(-1).value.callback.replace(/^window\./, '');
214
- const other = new AppWrapper();
215
- let dialogResult;
216
- const pending = useDialogCall
217
- ? other.functions.invokeDialogCall({ action: 999, value: {} }, (value) => { dialogResult = value; })
218
- : other.functions.invokeCall({ action: 999, value: {} });
219
- const otherCallback = nativeCalls.at(-1).value.callback.replace(/^window\./, '');
220
- assert.notEqual(otherCallback, safeAreaCallback);
221
- window[otherCallback]({ retVal: { success: true } });
222
- const callResult = await pending;
223
- assert.deepEqual(useDialogCall ? dialogResult : callResult, { success: true });
224
- const updates = Array.from({ length: 181 }, (_, hingeAngle) => {
225
- let hingeStatus = HingeStatus.PartiallyOpen;
226
- if (hingeAngle === 0) hingeStatus = HingeStatus.Closed;
227
- if (hingeAngle === 180) hingeStatus = HingeStatus.FullyOpen;
228
- return { ...insets, hingeAngle, hingeStatus };
229
- });
230
- updates.forEach(emit);
231
- assert.deepEqual(values, updates);
232
- });
233
- }