chayns-api 1.1.0-2 → 1.1.0-4

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 (76) hide show
  1. package/dist/cjs/calls/dialogs/chaynsDialog.js +3 -6
  2. package/dist/cjs/calls/dialogs/date.js +29 -2
  3. package/dist/cjs/calls/dialogs/fileSelect.js +1 -2
  4. package/dist/cjs/calls/dialogs/input.js +2 -3
  5. package/dist/cjs/calls/dialogs/select.js +2 -3
  6. package/dist/cjs/calls/getUserInfo.js +1 -2
  7. package/dist/cjs/calls/index.js +93 -82
  8. package/dist/cjs/components/AppDialogWrapper.js +7 -7
  9. package/dist/cjs/components/ChaynsContext.js +2 -4
  10. package/dist/cjs/components/ChaynsProvider.js +10 -13
  11. package/dist/cjs/components/ErrorBoundary.js +31 -0
  12. package/dist/cjs/components/moduleWrapper.js +9 -0
  13. package/dist/cjs/components/withCompatMode.js +8 -7
  14. package/dist/cjs/components/withHydrationBoundary.js +57 -0
  15. package/dist/cjs/constants/hydrationContext.js +16 -0
  16. package/dist/cjs/constants/index.js +16 -0
  17. package/dist/cjs/handler/DialogHandler.js +4 -2
  18. package/dist/cjs/hooks/useAccessToken.js +1 -0
  19. package/dist/cjs/hooks/useDialogState.js +2 -2
  20. package/dist/cjs/hooks/usePages.js +2 -2
  21. package/dist/cjs/host/ChaynsHost.js +1 -2
  22. package/dist/cjs/host/iframe/HostIframe.js +4 -6
  23. package/dist/cjs/host/iframe/utils/useUpdateData.js +1 -2
  24. package/dist/cjs/host/module/ModuleHost.js +8 -24
  25. package/dist/cjs/host/module/utils/loadComponent.js +58 -51
  26. package/dist/cjs/index.js +48 -5
  27. package/dist/cjs/types/IChaynsReact.js +140 -107
  28. package/dist/cjs/util/appCall.js +3 -4
  29. package/dist/cjs/util/deviceHelper.js +18 -13
  30. package/dist/cjs/util/transferNestedFunctions.js +36 -0
  31. package/dist/cjs/wrapper/AppWrapper.js +69 -11
  32. package/dist/cjs/wrapper/FrameWrapper.js +16 -5
  33. package/dist/cjs/wrapper/StaticChaynsApi.js +22 -0
  34. package/dist/esm/calls/index.js +22 -1
  35. package/dist/esm/components/AppDialogWrapper.js +4 -3
  36. package/dist/esm/components/ChaynsProvider.js +6 -7
  37. package/dist/esm/components/ErrorBoundary.js +23 -0
  38. package/dist/esm/components/moduleWrapper.js +3 -0
  39. package/dist/esm/components/withCompatMode.js +5 -4
  40. package/dist/esm/components/withHydrationBoundary.js +50 -0
  41. package/dist/esm/constants/hydrationContext.js +10 -0
  42. package/dist/esm/constants/index.js +1 -0
  43. package/dist/esm/handler/DialogHandler.js +6 -4
  44. package/dist/esm/hooks/useAccessToken.js +1 -0
  45. package/dist/esm/hooks/useDialogState.js +2 -2
  46. package/dist/esm/hooks/usePages.js +1 -1
  47. package/dist/esm/host/iframe/HostIframe.js +1 -2
  48. package/dist/esm/host/module/ModuleHost.js +5 -20
  49. package/dist/esm/host/module/utils/loadComponent.js +58 -50
  50. package/dist/esm/index.js +6 -1
  51. package/dist/esm/types/IChaynsReact.js +142 -87
  52. package/dist/esm/util/appCall.js +2 -2
  53. package/dist/esm/util/deviceHelper.js +17 -11
  54. package/dist/esm/util/transferNestedFunctions.js +32 -0
  55. package/dist/esm/wrapper/AppWrapper.js +70 -11
  56. package/dist/esm/wrapper/FrameWrapper.js +16 -5
  57. package/dist/esm/wrapper/StaticChaynsApi.js +20 -0
  58. package/dist/types/calls/index.d.ts +19 -5
  59. package/dist/types/components/AppDialogWrapper.d.ts +2 -2
  60. package/dist/types/components/ChaynsProvider.d.ts +1 -4
  61. package/dist/types/components/ErrorBoundary.d.ts +13 -0
  62. package/dist/types/components/moduleWrapper.d.ts +4 -0
  63. package/dist/types/components/withHydrationBoundary.d.ts +16 -0
  64. package/dist/types/constants/hydrationContext.d.ts +8 -0
  65. package/dist/types/constants/index.d.ts +1 -0
  66. package/dist/types/handler/DialogHandler.d.ts +0 -1
  67. package/dist/types/hooks/useAccessToken.d.ts +1 -0
  68. package/dist/types/host/module/ModuleHost.d.ts +1 -0
  69. package/dist/types/host/module/utils/loadComponent.d.ts +1 -1
  70. package/dist/types/index.d.ts +6 -1
  71. package/dist/types/types/IChaynsReact.d.ts +136 -28
  72. package/dist/types/util/deviceHelper.d.ts +2 -2
  73. package/dist/types/util/transferNestedFunctions.d.ts +1 -0
  74. package/dist/types/wrapper/StaticChaynsApi.d.ts +9 -0
  75. package/package.json +26 -22
  76. package/toolkit.config.js +20 -0
@@ -12,8 +12,8 @@ var _deviceHelper = _interopRequireWildcard(require("../util/deviceHelper"));
12
12
  var _getUserInfo = _interopRequireDefault(require("../calls/getUserInfo"));
13
13
  var _sendMessage = require("../calls/sendMessage");
14
14
  var _apiListenerHelper = require("../helper/apiListenerHelper");
15
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
16
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
16
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
17
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
18
  /* eslint-disable */
19
19
  // @ts-nocheck
@@ -23,12 +23,28 @@ class AppWrapper {
23
23
  values = null;
24
24
  accessToken = '';
25
25
  mapOldApiToNew(retVal) {
26
- var _window, _window2, _AppInfo$TappSelected;
26
+ var _window, _colorMode, _window2, _AppInfo$TappSelected;
27
27
  const {
28
28
  AppInfo,
29
29
  AppUser
30
30
  } = retVal;
31
31
  this.accessToken = AppUser.TobitAccessToken;
32
+ const urlParams = new URLSearchParams(location.search);
33
+ const urlParamsLowerCase = new URLSearchParams(location.search.toLowerCase());
34
+ let tappId = urlParamsLowerCase.get('tappid');
35
+ let colorMode = urlParamsLowerCase.get('colormode');
36
+ if (colorMode) {
37
+ try {
38
+ colorMode = Number.parseInt(colorMode, 10);
39
+ } catch {}
40
+ }
41
+ if (tappId) {
42
+ try {
43
+ tappId = Number.parseInt(tappId, 10);
44
+ } catch {
45
+ // ignore
46
+ }
47
+ }
32
48
  return {
33
49
  device: (0, _deviceHelper.default)(navigator.userAgent, 'image/webp'),
34
50
  environment: {
@@ -56,7 +72,7 @@ class AppWrapper {
56
72
  docked: false
57
73
  },
58
74
  title: AppInfo.Title,
59
- colorMode: AppInfo.colorMode,
75
+ colorMode: (_colorMode = colorMode) !== null && _colorMode !== void 0 ? _colorMode : AppInfo.colorMode,
60
76
  color: AppInfo.color,
61
77
  domain: AppInfo.domain,
62
78
  font: {
@@ -68,7 +84,7 @@ class AppWrapper {
68
84
  locationPersonId: AppInfo.LocationPersonId,
69
85
  urlHash: (_window2 = window) === null || _window2 === void 0 ? void 0 : _window2.location.hash.replace('#', '')
70
86
  },
71
- parameters: Object.fromEntries(new URLSearchParams(location.search)),
87
+ parameters: Object.fromEntries(urlParams),
72
88
  user: {
73
89
  firstName: AppUser.FirstName,
74
90
  lastName: AppUser.LastName,
@@ -80,7 +96,7 @@ class AppWrapper {
80
96
  customData: null,
81
97
  isAdminModeActive: AppUser.AdminMode,
82
98
  currentPage: {
83
- id: (_AppInfo$TappSelected = AppInfo.TappSelected) === null || _AppInfo$TappSelected === void 0 ? void 0 : _AppInfo$TappSelected.TappID,
99
+ id: ((_AppInfo$TappSelected = AppInfo.TappSelected) === null || _AppInfo$TappSelected === void 0 ? void 0 : _AppInfo$TappSelected.TappID) || tappId,
84
100
  siteId: AppInfo.SiteID
85
101
  },
86
102
  pages: AppInfo.Tapps.map(x => ({
@@ -151,12 +167,13 @@ class AppWrapper {
151
167
  permanent: true
152
168
  }, {
153
169
  callback: v => {
154
- var _v$accuracy, _v$code;
170
+ var _v$accuracy, _v$isAccurate, _v$code;
155
171
  (0, _apiListenerHelper.dispatchApiEvent)('geoLocationListener', {
156
172
  latitude: v.latitude,
157
173
  longitude: v.longitude,
158
174
  accuracy: (_v$accuracy = v.accuracy) !== null && _v$accuracy !== void 0 ? _v$accuracy : null,
159
175
  speed: v.speed,
176
+ isAccurate: (_v$isAccurate = v.isAccurate) !== null && _v$isAccurate !== void 0 ? _v$isAccurate : null,
160
177
  code: (_v$code = v.code) !== null && _v$code !== void 0 ? _v$code : null
161
178
  });
162
179
  }
@@ -202,6 +219,23 @@ class AppWrapper {
202
219
  }
203
220
  return id;
204
221
  },
222
+ addToolbarChangeListener: async callback => {
223
+ const {
224
+ id,
225
+ shouldInitialize
226
+ } = (0, _apiListenerHelper.addApiListener)('toolbarChangeListener', callback);
227
+ if (shouldInitialize) {
228
+ this.appCall(293, {}, {
229
+ callback: v => {
230
+ (0, _apiListenerHelper.dispatchApiEvent)('toolbarChangeListener', {
231
+ isVisible: v.isVisible,
232
+ toolbarHeight: v.toolbarHeight
233
+ });
234
+ }
235
+ });
236
+ }
237
+ return id;
238
+ },
205
239
  addWindowMetricsListener: async callback => {
206
240
  const {
207
241
  id,
@@ -227,13 +261,15 @@ class AppWrapper {
227
261
  };
228
262
  },
229
263
  getGeoLocation: async () => {
264
+ var _res$accuracy, _res$isAccurate, _res$code;
230
265
  const res = await this.appCall(14);
231
266
  return {
232
267
  latitude: res.latitude,
233
268
  longitude: res.longitude,
234
269
  speed: res.speed,
235
- code: res.code,
236
- isAccurate: res.isAccurate
270
+ accuracy: (_res$accuracy = res.accuracy) !== null && _res$accuracy !== void 0 ? _res$accuracy : null,
271
+ isAccurate: (_res$isAccurate = res.isAccurate) !== null && _res$isAccurate !== void 0 ? _res$isAccurate : null,
272
+ code: (_res$code = res.code) !== null && _res$code !== void 0 ? _res$code : null
237
273
  };
238
274
  },
239
275
  getUserInfo: async query => {
@@ -264,7 +300,7 @@ class AppWrapper {
264
300
  window[callbackName] = ({
265
301
  retVal
266
302
  }) => {
267
- callback === null || callback === void 0 ? void 0 : callback(retVal);
303
+ callback === null || callback === void 0 || callback(retVal);
268
304
  delete window[callbackName];
269
305
  };
270
306
  const callObj = {
@@ -294,6 +330,7 @@ class AppWrapper {
294
330
  },
295
331
  openImage: async value => {
296
332
  this.appCall(4, {
333
+ urls: value.items.map(x => x.url),
297
334
  items: value.items.map(x => ({
298
335
  url: x.url,
299
336
  title: x.title,
@@ -348,6 +385,14 @@ class AppWrapper {
348
385
  // App does not support removal of onActivate callback which makes this a no-op
349
386
  }
350
387
  },
388
+ removeToolbarChangeListener: async id => {
389
+ const {
390
+ shouldRemove
391
+ } = (0, _apiListenerHelper.removeApiListener)('toolbarChangeListener', id);
392
+ if (shouldRemove) {
393
+ // App does not support removal of onToolbarBarRemove callback which makes this a no-op
394
+ }
395
+ },
351
396
  removeWindowMetricsListener: async id => {
352
397
  const shouldRemove = (0, _apiListenerHelper.removeApiListener)('windowMetricsListener', id);
353
398
  if (shouldRemove) {
@@ -361,7 +406,7 @@ class AppWrapper {
361
406
  id: options.id,
362
407
  showName: options.showName,
363
408
  position: options.position,
364
- params: options.params
409
+ params: new URLSearchParams(options.params).toString() || undefined
365
410
  }, {
366
411
  awaitResult: false
367
412
  });
@@ -508,6 +553,19 @@ class AppWrapper {
508
553
  }
509
554
  async init() {
510
555
  this.values = this.mapOldApiToNew(await this.appCall(18));
556
+ const callbackName = `chaynsApiV5Callback_${this.counter++}`;
557
+ window.disablev4AccessTokenChangeListener = true;
558
+ window[callbackName] = ({
559
+ retVal: value
560
+ }) => {
561
+ this.mapOldApiToNew(value);
562
+ };
563
+ this.appCall(66, {
564
+ enabled: true,
565
+ callback: callbackName
566
+ }, {
567
+ awaitResult: false
568
+ });
511
569
  return undefined;
512
570
  }
513
571
  getSSRData() {
@@ -12,8 +12,8 @@ var _getUserInfo = _interopRequireDefault(require("../calls/getUserInfo"));
12
12
  var _sendMessage = require("../calls/sendMessage");
13
13
  var _heightHelper = require("../util/heightHelper");
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
16
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
15
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
16
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
17
17
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
18
18
 
19
19
  class FrameWrapper {
@@ -34,6 +34,10 @@ class FrameWrapper {
34
34
  return this.exposedFunctions.addScrollListener(value, callback && comlink.proxy(result => callback(result)));
35
35
  },
36
36
  addVisibilityChangeListener: async callback => (0, _visibilityChangeListener.addVisibilityChangeListener)(callback),
37
+ addToolbarChangeListener: async callback => {
38
+ if (!this.initialized) await this.ready;
39
+ return this.exposedFunctions.addToolbarChangeListener(callback && comlink.proxy(result => callback(result)));
40
+ },
37
41
  addWindowMetricsListener: async callback => {
38
42
  if (!this.initialized) await this.ready;
39
43
  const {
@@ -105,6 +109,10 @@ class FrameWrapper {
105
109
  if (!this.initialized) await this.ready;
106
110
  return this.exposedFunctions.openImage(value);
107
111
  },
112
+ openMedia: async value => {
113
+ if (!this.initialized) await this.ready;
114
+ return this.exposedFunctions.openMedia(value);
115
+ },
108
116
  openUrl: async value => {
109
117
  if (!this.initialized) await this.ready;
110
118
  return this.exposedFunctions.openUrl(value);
@@ -142,6 +150,10 @@ class FrameWrapper {
142
150
  this.resizeListener = null;
143
151
  }
144
152
  },
153
+ removeToolbarChangeListener: async id => {
154
+ if (!this.initialized) await this.ready;
155
+ return this.exposedFunctions.removeToolbarChangeListener(id);
156
+ },
145
157
  selectPage: async options => {
146
158
  if (!this.initialized) await this.ready;
147
159
  await this.exposedFunctions.selectPage(options);
@@ -246,9 +258,9 @@ class FrameWrapper {
246
258
  if (!this.initialized) await this.ready;
247
259
  return this.exposedFunctions.openDialog(config, comlink.proxy(callback));
248
260
  },
249
- setDialogResult: async result => {
261
+ setDialogResult: async (buttonType, result) => {
250
262
  if (!this.initialized) await this.ready;
251
- return this.exposedFunctions.setDialogResult(result);
263
+ return this.exposedFunctions.setDialogResult(buttonType, result);
252
264
  },
253
265
  dispatchEventToDialogClient: async (dialogId, data) => {
254
266
  if (!this.initialized) await this.ready;
@@ -303,7 +315,6 @@ class FrameWrapper {
303
315
  if (this.initialized) {
304
316
  this.values[type] = value;
305
317
  }
306
- this.values[type] = value;
307
318
  document.dispatchEvent(new CustomEvent('chayns_api_data', {
308
319
  detail: {
309
320
  type,
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _moduleWrapper = require("../components/moduleWrapper");
8
+ var _FrameWrapper = require("./FrameWrapper");
9
+ class StaticChaynsApi {
10
+ constructor() {
11
+ const wrapper = new _FrameWrapper.FrameWrapper();
12
+ _moduleWrapper.moduleWrapper.current = wrapper;
13
+ this._wrapper = wrapper;
14
+ this.ready = wrapper.init();
15
+ this.addDataListener = wrapper.addDataListener;
16
+ Object.entries(wrapper.functions).forEach(([k, v]) => {
17
+ this[k] = v;
18
+ });
19
+ }
20
+ getSite = () => this._wrapper.values.site;
21
+ }
22
+ var _default = exports.default = StaticChaynsApi;
@@ -1,4 +1,4 @@
1
- import { moduleWrapper } from '../components/ChaynsProvider';
1
+ import { moduleWrapper } from '../components/moduleWrapper';
2
2
  /**
3
3
  * This adds a listener to determine your location.
4
4
  * @category Event listener
@@ -20,6 +20,14 @@ export const addScrollListener = function () {
20
20
  export const addVisibilityChangeListener = function () {
21
21
  return moduleWrapper.current.functions.addVisibilityChangeListener(...arguments);
22
22
  };
23
+ /**
24
+ * This method will be executed when the toolbar gets displayed or hidden.
25
+ * @category Event listener
26
+ */
27
+ export const addToolbarChangeListener = function () {
28
+ return moduleWrapper.current.functions.addToolbarChangeListener(...arguments);
29
+ };
30
+
23
31
  /**
24
32
  * This adds a listener to get the actual height of the page.
25
33
  * @category Event listener
@@ -101,6 +109,12 @@ export const navigateBack = function () {
101
109
  export const openImage = function () {
102
110
  return moduleWrapper.current.functions.openImage(...arguments);
103
111
  };
112
+ /**
113
+ * The images and videos specified in the items array is shown in gallery mode.
114
+ */
115
+ export const openMedia = function () {
116
+ return moduleWrapper.current.functions.openMedia(...arguments);
117
+ };
104
118
  /**
105
119
  * Opens an URL in the chayns environment.
106
120
  */
@@ -132,6 +146,13 @@ export const refreshAccessToken = function () {
132
146
  export const removeGeoLocationListener = function () {
133
147
  return moduleWrapper.current.functions.removeGeoLocationListener(...arguments);
134
148
  };
149
+ /**
150
+ * This removes a listener for changing toolbar visibility
151
+ * @category Event listener
152
+ */
153
+ export const removeToolbarChangeListener = function () {
154
+ return moduleWrapper.current.functions.removeToolbarChangeListener(...arguments);
155
+ };
135
156
  /**
136
157
  * Removes scroll listener.
137
158
  * @category Event listener
@@ -2,6 +2,7 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
2
2
  import React, { useEffect, useState } from 'react';
3
3
  import ChaynsHost from '../host/ChaynsHost';
4
4
  import { useFunctions, useValues } from '../hooks';
5
+ import ErrorBoundary from "./ErrorBoundary";
5
6
  const AppDialogWrapper = _ref => {
6
7
  let {
7
8
  dialogEventTarget
@@ -18,16 +19,16 @@ const AppDialogWrapper = _ref => {
18
19
  });
19
20
  });
20
21
  }, []);
21
- return /*#__PURE__*/React.createElement(ChaynsHost, _extends({
22
+ return /*#__PURE__*/React.createElement(ErrorBoundary, null, /*#__PURE__*/React.createElement(ChaynsHost, _extends({
22
23
  type: "client-module",
23
24
  system: {
24
25
  module: './AppWrapper',
25
- url: 'https://tapp-staging.chayns-static.space/api/dialog-v2/v1/remoteEntry.js',
26
+ url: 'https://tapp.chayns-static.space/api/dialog-v2/v1/remoteEntry.js',
26
27
  scope: 'dialog_v2'
27
28
  }
28
29
  }, data, {
29
30
  functions: functions,
30
31
  customData: dialogData
31
- }));
32
+ })));
32
33
  };
33
34
  export default AppDialogWrapper;
@@ -7,12 +7,11 @@ import { FrameWrapper } from '../wrapper/FrameWrapper';
7
7
  import { ModuleFederationWrapper } from '../wrapper/ModuleFederationWrapper';
8
8
  import { SsrWrapper } from '../wrapper/SsrWrapper';
9
9
  import { ChaynsContext, ChaynsFunctionsContext } from './ChaynsContext';
10
- import AppDialogWrapper from "./AppDialogWrapper";
10
+ import AppDialogWrapper from './AppDialogWrapper';
11
+ import { moduleWrapper } from './moduleWrapper';
11
12
 
12
13
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
13
- export const moduleWrapper = {
14
- current: undefined
15
- };
14
+
16
15
  const isServer = typeof window === 'undefined';
17
16
  const InitialDataProvider = /*#__PURE__*/React.memo(_ref => {
18
17
  let {
@@ -58,7 +57,7 @@ const ChaynsProvider = _ref2 => {
58
57
  var _deviceInfo$app$name, _deviceInfo$app;
59
58
  const deviceInfo = getDeviceInfo(navigator.userAgent, '');
60
59
  // load framewrapper in Chaynsweb in app (window.self === window.top)
61
- if ([AppName.Chayns, AppName.ChaynsLauncher].includes((_deviceInfo$app$name = (_deviceInfo$app = deviceInfo.app) === null || _deviceInfo$app === void 0 ? void 0 : _deviceInfo$app.name) !== null && _deviceInfo$app$name !== void 0 ? _deviceInfo$app$name : AppName.Unknown) && window.self === window.top) {
60
+ if ([AppName.Chayns, AppName.ChaynsLauncher, AppName.Sidekick, AppName.TobitChat].includes((_deviceInfo$app$name = (_deviceInfo$app = deviceInfo.app) === null || _deviceInfo$app === void 0 ? void 0 : _deviceInfo$app.name) !== null && _deviceInfo$app$name !== void 0 ? _deviceInfo$app$name : AppName.Unknown) && window.self === window.top) {
62
61
  customWrapper.current = new AppWrapper();
63
62
  } else {
64
63
  customWrapper.current = new FrameWrapper();
@@ -83,7 +82,7 @@ const ChaynsProvider = _ref2 => {
83
82
  return undefined;
84
83
  });
85
84
  });
86
- if (customWrapper.current.values) {
85
+ if (customWrapper.current.values && !isModule) {
87
86
  setState({
88
87
  ...customWrapper.current.values
89
88
  });
@@ -94,7 +93,7 @@ const ChaynsProvider = _ref2 => {
94
93
  if (isModule) {
95
94
  setState(data);
96
95
  if (data) {
97
- moduleWrapper.current.values = data;
96
+ customWrapper.current.values = data;
98
97
  }
99
98
  }
100
99
  }, [data, isModule]);
@@ -0,0 +1,23 @@
1
+ import React from "react";
2
+ export default class ErrorBoundary extends React.Component {
3
+ constructor(props) {
4
+ super(props);
5
+ this.state = {
6
+ hasError: false
7
+ };
8
+ }
9
+ static getDerivedStateFromError() {
10
+ return {
11
+ hasError: true
12
+ };
13
+ }
14
+ componentDidCatch(error, errorInfo) {
15
+ console.error(error, errorInfo);
16
+ }
17
+ render() {
18
+ if (this.state.hasError) {
19
+ return null;
20
+ }
21
+ return this.props.children;
22
+ }
23
+ }
@@ -0,0 +1,3 @@
1
+ export const moduleWrapper = {
2
+ current: undefined
3
+ };
@@ -3,6 +3,7 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
3
3
 
4
4
  import React, { PureComponent } from 'react';
5
5
  import ReactDOM from 'react-dom';
6
+ import ErrorBoundary from './ErrorBoundary';
6
7
  let ReactDOMClient;
7
8
  try {
8
9
  ReactDOMClient = require('react-dom/client');
@@ -20,9 +21,9 @@ export const withCompatMode = Component => {
20
21
  const {
21
22
  innerRef
22
23
  } = this.props;
23
- const component = /*#__PURE__*/React.createElement(Component, _extends({}, this.props, {
24
+ const component = /*#__PURE__*/React.createElement(ErrorBoundary, null, /*#__PURE__*/React.createElement(Component, _extends({}, this.props, {
24
25
  ref: innerRef
25
- }));
26
+ })));
26
27
  if (typeof ((_ReactDOMClient = ReactDOMClient) === null || _ReactDOMClient === void 0 ? void 0 : _ReactDOMClient.createRoot) === 'function') {
27
28
  this.root = ReactDOMClient.createRoot(this.ref.current);
28
29
  this.root.render(component);
@@ -34,9 +35,9 @@ export const withCompatMode = Component => {
34
35
  const {
35
36
  innerRef
36
37
  } = this.props;
37
- const component = /*#__PURE__*/React.createElement(Component, _extends({}, this.props, {
38
+ const component = /*#__PURE__*/React.createElement(ErrorBoundary, null, /*#__PURE__*/React.createElement(Component, _extends({}, this.props, {
38
39
  ref: innerRef
39
- }));
40
+ })));
40
41
  if (this.root) {
41
42
  this.root.render(component);
42
43
  } else {
@@ -0,0 +1,50 @@
1
+ import React, { useContext, useEffect, useState } from 'react';
2
+ import { HydrationContext } from '../constants';
3
+ const withHydrationBoundary = (Component, initializer, useHydrationId) => {
4
+ return _ref => {
5
+ let {
6
+ id: idProp,
7
+ children
8
+ } = _ref;
9
+ let value;
10
+ if (!globalThis.window) {
11
+ value = useContext(HydrationContext);
12
+ }
13
+ const id = useHydrationId ? useHydrationId() : idProp;
14
+ if (!id) {
15
+ throw new Error('hydration boundary was not given a id which is required');
16
+ }
17
+ const [store] = useState(() => {
18
+ let initialValue = undefined;
19
+ if (globalThis.window) {
20
+ const htmlId = `__INITIAL_DATA_${id}__`;
21
+ const $elem = document.getElementById(htmlId);
22
+ if ($elem) {
23
+ initialValue = JSON.parse($elem.innerHTML);
24
+ }
25
+ }
26
+ const s = initializer(initialValue);
27
+ if (!globalThis.window) {
28
+ if (id in value) {
29
+ console.warn(`Dehydration function for id "${id}" has been defined multiple times. This can have two reasons. The children cause suspension and therefor the hydration boundary has to mount from scratch again. You can avoid this by adding a Suspense around the children. The id is not unique. This has to be fixed or might cause hydration issues.`);
30
+ }
31
+ value[id] = {
32
+ getState: s.getState,
33
+ abort: s.abort
34
+ };
35
+ }
36
+ return s;
37
+ });
38
+ useEffect(() => {
39
+ const htmlId = `__INITIAL_DATA_${id}__`;
40
+ const $elem = document.getElementById(htmlId);
41
+ if ($elem) {
42
+ $elem.remove();
43
+ }
44
+ }, []);
45
+ return /*#__PURE__*/React.createElement(Component, {
46
+ value: store
47
+ }, children);
48
+ };
49
+ };
50
+ export default withHydrationBoundary;
@@ -0,0 +1,10 @@
1
+ import { createContext } from 'react';
2
+ export let HydrationContext;
3
+
4
+ // force single context on server-side (fake sharing)
5
+ if (!globalThis.window && globalThis._hydrationContext) {
6
+ HydrationContext = globalThis._hydrationContext;
7
+ } else {
8
+ HydrationContext = /*#__PURE__*/createContext({});
9
+ globalThis._hydrationContext = HydrationContext;
10
+ }
@@ -0,0 +1 @@
1
+ export * from './hydrationContext';
@@ -1,6 +1,6 @@
1
1
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
3
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
2
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
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
  export default class DialogHandler {
5
5
  constructor(config, open, close, dispatchEvent, addDataListener) {
6
6
  _defineProperty(this, "isOpen", false);
@@ -23,9 +23,11 @@ export default class DialogHandler {
23
23
  };
24
24
  this.isOpen = true;
25
25
  this.dialogId = await this._open(this._config, callback);
26
- console.log('dialogId', this.dialogId);
26
+
27
+ // console.log('dialogId', this.dialogId);
28
+
27
29
  this._addDataListener(this.dialogId, data => {
28
- console.log('[DialogHandler]dataListener', this.dialogId, data);
30
+ // console.log('[DialogHandler]dataListener', this.dialogId, data);
29
31
  this.listeners.forEach(cb => cb(data));
30
32
  });
31
33
  });
@@ -4,6 +4,7 @@ import { ChaynsFunctionsContext } from "../components/ChaynsContext";
4
4
 
5
5
  /**
6
6
  * @category Hooks
7
+ * @deprecated Use {@link getAccessToken} instead
7
8
  */
8
9
  export const useAccessToken = accessToken => {
9
10
  const [token, setToken] = useState(null);
@@ -10,7 +10,7 @@ export const useDialogState = () => {
10
10
  const addDataListener = useContextSelector(ChaynsFunctionsContext, v => v === null || v === void 0 ? void 0 : v.addDialogHostEventListener);
11
11
  const isClosingRequested = useContextSelector(ChaynsContext, v => {
12
12
  var _v$dialog;
13
- return v === null || v === void 0 ? void 0 : (_v$dialog = v.dialog) === null || _v$dialog === void 0 ? void 0 : _v$dialog.isClosingRequested;
13
+ return v === null || v === void 0 || (_v$dialog = v.dialog) === null || _v$dialog === void 0 ? void 0 : _v$dialog.isClosingRequested;
14
14
  });
15
15
  return {
16
16
  setResult,
@@ -26,7 +26,7 @@ export const useDialogState = () => {
26
26
  export const useDialogData = () => {
27
27
  const inputData = useContextSelector(ChaynsContext, v => {
28
28
  var _v$dialog2;
29
- return v === null || v === void 0 ? void 0 : (_v$dialog2 = v.dialog) === null || _v$dialog2 === void 0 ? void 0 : _v$dialog2.dialogInput;
29
+ return v === null || v === void 0 || (_v$dialog2 = v.dialog) === null || _v$dialog2 === void 0 ? void 0 : _v$dialog2.dialogInput;
30
30
  });
31
31
  return inputData;
32
32
  };
@@ -1,6 +1,6 @@
1
1
  import { useContextSelector } from 'use-context-selector';
2
2
  import { ChaynsContext } from '../components/ChaynsContext';
3
- import { moduleWrapper } from "../components/ChaynsProvider";
3
+ import { moduleWrapper } from '../components/moduleWrapper';
4
4
  /**
5
5
  * @category Hooks
6
6
  */
@@ -31,10 +31,9 @@ const HostIframe = _ref => {
31
31
  if (!eventTarget.current) {
32
32
  eventTarget.current = global.document ? document.createElement('div') : undefined; // global.EventTarget ? new EventTarget() : undefined
33
33
  }
34
-
35
34
  const setHeight = value => {
36
35
  if (ref.current) {
37
- ref.current.height = `${value}px`;
36
+ ref.current.style.height = `${value}px`;
38
37
  }
39
38
  };
40
39
 
@@ -1,5 +1,4 @@
1
1
  import React, { useMemo } from 'react';
2
- import useDynamicScript from './utils/useDynamicScript';
3
2
  import loadComponent from './utils/loadComponent';
4
3
  import { replaceStagingUrl } from "../../util/url";
5
4
  const System = _ref => {
@@ -8,25 +7,10 @@ const System = _ref => {
8
7
  fallback,
9
8
  ...props
10
9
  } = _ref;
11
- const {
12
- ready,
13
- failed
14
- } = useDynamicScript({
15
- url: system === null || system === void 0 ? void 0 : system.url,
16
- scope: system === null || system === void 0 ? void 0 : system.scope
17
- });
18
- const Component = useMemo(() => {
19
- // maybe return waitcursor instead
20
- if (!system || !ready || failed) {
21
- return null;
22
- }
23
- return /*#__PURE__*/React.lazy(loadComponent(system.scope, system.module, system.url));
24
-
25
- /* eslint-disable react-hooks/exhaustive-deps */
26
- }, [system === null || system === void 0 ? void 0 : system.scope, ready, system === null || system === void 0 ? void 0 : system.url]);
27
- return Component ? /*#__PURE__*/React.createElement(React.Suspense, {
10
+ const Component = useMemo(() => loadComponent(system.scope, system.module, system.url, undefined, system.preventSingleton), [system.scope, system.module, system.url, system.preventSingleton]);
11
+ return /*#__PURE__*/React.createElement(React.Suspense, {
28
12
  fallback: fallback || ''
29
- }, /*#__PURE__*/React.createElement(Component, props)) : fallback;
13
+ }, /*#__PURE__*/React.createElement(Component, props));
30
14
  };
31
15
  const ModuleHost = _ref2 => {
32
16
  let {
@@ -73,7 +57,8 @@ const ModuleHost = _ref2 => {
73
57
  system: {
74
58
  scope: system.scope,
75
59
  url: replaceStagingUrl(preventStagingReplacement, system.url, environment.buildEnvironment),
76
- module: system.module
60
+ module: system.module,
61
+ preventSingleton: system.preventSingleton
77
62
  },
78
63
  data: initialData,
79
64
  functions: functions,