chayns-api 1.0.8 → 1.0.10-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (137) hide show
  1. package/.babelrc +30 -30
  2. package/.eslintrc +17 -17
  3. package/.github/workflows/deploy_docs.yml +28 -28
  4. package/.github/workflows/publish.yml +21 -21
  5. package/LICENSE +21 -21
  6. package/README.md +47 -47
  7. package/dist/cjs/calls/dialogs/date.js +10 -10
  8. package/dist/cjs/calls/index.js +102 -97
  9. package/dist/cjs/calls/sendMessage.js +8 -8
  10. package/dist/cjs/calls/visibilityChangeListener.js +4 -4
  11. package/dist/cjs/components/AppDialogWrapper.js +40 -0
  12. package/dist/cjs/components/ChaynsProvider.js +5 -2
  13. package/dist/cjs/components/withCompatMode.js +3 -0
  14. package/dist/cjs/hooks/geoLocationListener.js +4 -4
  15. package/dist/cjs/hooks/index.js +14 -1
  16. package/dist/cjs/hooks/scrollListener.js +8 -8
  17. package/dist/cjs/hooks/useAccessToken.js +2 -2
  18. package/dist/cjs/hooks/useCurrentPage.js +2 -2
  19. package/dist/cjs/hooks/useCustomData.js +2 -2
  20. package/dist/cjs/hooks/useDevice.js +2 -2
  21. package/dist/cjs/hooks/useDialogState.js +31 -0
  22. package/dist/cjs/hooks/useEnvironment.js +2 -2
  23. package/dist/cjs/hooks/useFunctions.js +2 -2
  24. package/dist/cjs/hooks/useIsAdminMode.js +2 -2
  25. package/dist/cjs/hooks/useLanguage.js +2 -2
  26. package/dist/cjs/hooks/usePages.js +4 -4
  27. package/dist/cjs/hooks/useParameters.js +2 -2
  28. package/dist/cjs/hooks/useSite.js +2 -2
  29. package/dist/cjs/hooks/useUser.js +2 -2
  30. package/dist/cjs/hooks/useValues.js +2 -2
  31. package/dist/cjs/hooks/windowMetricsListener.js +4 -4
  32. package/dist/cjs/host/ChaynsHost.js +6 -3
  33. package/dist/cjs/host/iframe/HostIframe.js +6 -3
  34. package/dist/cjs/types/IChaynsReact.js +22 -2
  35. package/dist/cjs/util/deviceHelper.js +7 -6
  36. package/dist/cjs/wrapper/AppWrapper.js +173 -59
  37. package/dist/cjs/wrapper/FrameWrapper.js +16 -1
  38. package/dist/cjs/wrapper/ModuleFederationWrapper.js +11 -0
  39. package/dist/esm/calls/dialogs/date.js +34 -34
  40. package/dist/esm/calls/index.js +102 -96
  41. package/dist/esm/calls/sendMessage.js +8 -8
  42. package/dist/esm/calls/visibilityChangeListener.js +4 -4
  43. package/dist/esm/components/AppDialogWrapper.js +31 -0
  44. package/dist/esm/components/ChaynsProvider.js +5 -2
  45. package/dist/esm/components/withCompatMode.js +3 -0
  46. package/dist/esm/hooks/geoLocationListener.js +4 -4
  47. package/dist/esm/hooks/index.js +2 -1
  48. package/dist/esm/hooks/scrollListener.js +8 -8
  49. package/dist/esm/hooks/useAccessToken.js +2 -2
  50. package/dist/esm/hooks/useCurrentPage.js +2 -2
  51. package/dist/esm/hooks/useCustomData.js +2 -2
  52. package/dist/esm/hooks/useDevice.js +2 -2
  53. package/dist/esm/hooks/useDialogState.js +24 -0
  54. package/dist/esm/hooks/useEnvironment.js +2 -2
  55. package/dist/esm/hooks/useFunctions.js +2 -2
  56. package/dist/esm/hooks/useIsAdminMode.js +2 -2
  57. package/dist/esm/hooks/useLanguage.js +2 -2
  58. package/dist/esm/hooks/usePages.js +4 -4
  59. package/dist/esm/hooks/useParameters.js +2 -2
  60. package/dist/esm/hooks/useSite.js +2 -2
  61. package/dist/esm/hooks/useUser.js +2 -2
  62. package/dist/esm/hooks/useValues.js +2 -2
  63. package/dist/esm/hooks/windowMetricsListener.js +4 -4
  64. package/dist/esm/host/ChaynsHost.js +6 -3
  65. package/dist/esm/host/iframe/HostIframe.js +6 -3
  66. package/dist/esm/types/IChaynsReact.js +19 -1
  67. package/dist/esm/util/deviceHelper.js +7 -6
  68. package/dist/esm/wrapper/AppWrapper.js +182 -65
  69. package/dist/esm/wrapper/FrameWrapper.js +19 -2
  70. package/dist/esm/wrapper/ModuleFederationWrapper.js +11 -0
  71. package/dist/types/calls/dialogs/alert.d.ts +1 -1
  72. package/dist/types/calls/dialogs/chaynsDialog.d.ts +24 -24
  73. package/dist/types/calls/dialogs/close.d.ts +1 -1
  74. package/dist/types/calls/dialogs/communication.d.ts +3 -3
  75. package/dist/types/calls/dialogs/confirm.d.ts +13 -13
  76. package/dist/types/calls/dialogs/date.d.ts +96 -96
  77. package/dist/types/calls/dialogs/dropUpAlert.d.ts +5 -5
  78. package/dist/types/calls/dialogs/fileSelect.d.ts +16 -16
  79. package/dist/types/calls/dialogs/iFrame.d.ts +10 -10
  80. package/dist/types/calls/dialogs/index.d.ts +14 -14
  81. package/dist/types/calls/dialogs/input.d.ts +15 -15
  82. package/dist/types/calls/dialogs/mediaSelect.d.ts +8 -8
  83. package/dist/types/calls/dialogs/open.d.ts +1 -1
  84. package/dist/types/calls/dialogs/select.d.ts +6 -6
  85. package/dist/types/calls/dialogs/signature.d.ts +7 -7
  86. package/dist/types/calls/dialogs/toast.d.ts +1 -1
  87. package/dist/types/calls/dialogs/utils/callback.d.ts +1 -1
  88. package/dist/types/calls/dialogs/utils/is.d.ts +4 -4
  89. package/dist/types/calls/getUserInfo.d.ts +9 -9
  90. package/dist/types/calls/index.d.ts +237 -233
  91. package/dist/types/calls/sendMessage.d.ts +13 -13
  92. package/dist/types/calls/visibilityChangeListener.d.ts +9 -9
  93. package/dist/types/components/AppDialogWrapper.d.ts +5 -0
  94. package/dist/types/components/ChaynsContext.d.ts +3 -3
  95. package/dist/types/components/ChaynsProvider.d.ts +14 -13
  96. package/dist/types/components/WaitUntil.d.ts +8 -7
  97. package/dist/types/components/withCompatMode.d.ts +13 -13
  98. package/dist/types/helper/apiListenerHelper.d.ts +6 -6
  99. package/dist/types/hooks/geoLocationListener.d.ts +18 -18
  100. package/dist/types/hooks/index.d.ts +17 -16
  101. package/dist/types/hooks/scrollListener.d.ts +28 -28
  102. package/dist/types/hooks/useAccessToken.d.ts +5 -5
  103. package/dist/types/hooks/useCurrentPage.d.ts +4 -4
  104. package/dist/types/hooks/useCustomData.d.ts +4 -4
  105. package/dist/types/hooks/useDevice.d.ts +5 -5
  106. package/dist/types/hooks/useDialogState.d.ts +9 -0
  107. package/dist/types/hooks/useEnvironment.d.ts +5 -5
  108. package/dist/types/hooks/useFunctions.d.ts +5 -5
  109. package/dist/types/hooks/useIsAdminMode.d.ts +4 -4
  110. package/dist/types/hooks/useLanguage.d.ts +5 -5
  111. package/dist/types/hooks/usePages.d.ts +18 -18
  112. package/dist/types/hooks/useParameters.d.ts +5 -5
  113. package/dist/types/hooks/useSite.d.ts +5 -5
  114. package/dist/types/hooks/useUser.d.ts +5 -5
  115. package/dist/types/hooks/useValues.d.ts +5 -5
  116. package/dist/types/hooks/windowMetricsListener.d.ts +11 -11
  117. package/dist/types/host/ChaynsHost.d.ts +30 -29
  118. package/dist/types/host/iframe/HostIframe.d.ts +26 -25
  119. package/dist/types/host/iframe/utils/useUpdateData.d.ts +3 -3
  120. package/dist/types/host/module/ModuleHost.d.ts +25 -24
  121. package/dist/types/host/module/utils/loadComponent.d.ts +1 -1
  122. package/dist/types/host/module/utils/useDynamicScript.d.ts +9 -9
  123. package/dist/types/index.d.ts +16 -16
  124. package/dist/types/types/IChaynsReact.d.ts +700 -622
  125. package/dist/types/types/dialog.d.ts +41 -41
  126. package/dist/types/util/appCall.d.ts +2 -2
  127. package/dist/types/util/deviceHelper.d.ts +7 -7
  128. package/dist/types/util/heightHelper.d.ts +1 -1
  129. package/dist/types/util/postIframeForm.d.ts +1 -1
  130. package/dist/types/util/url.d.ts +1 -1
  131. package/dist/types/wrapper/AppWrapper.d.ts +27 -18
  132. package/dist/types/wrapper/FrameWrapper.d.ts +15 -15
  133. package/dist/types/wrapper/ModuleFederationWrapper.d.ts +10 -10
  134. package/dist/types/wrapper/SsrWrapper.d.ts +11 -11
  135. package/package.json +75 -76
  136. package/tsconfig.json +56 -56
  137. package/toolkit.config.js +0 -52
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.useEnvironment = void 0;
7
7
  var _useContextSelector = require("use-context-selector");
8
8
  var _ChaynsContext = require("../components/ChaynsContext");
9
- /**
10
- * @category Hooks
9
+ /**
10
+ * @category Hooks
11
11
  */
12
12
  const useEnvironment = () => (0, _useContextSelector.useContextSelector)(_ChaynsContext.ChaynsContext, v => v === null || v === void 0 ? void 0 : v.environment);
13
13
  exports.useEnvironment = useEnvironment;
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.useFunctions = void 0;
7
7
  var _useContextSelector = require("use-context-selector");
8
8
  var _ChaynsContext = require("../components/ChaynsContext");
9
- /**
10
- * @category Hooks
9
+ /**
10
+ * @category Hooks
11
11
  */
12
12
  const useFunctions = () => {
13
13
  const t = (0, _useContextSelector.useContextSelector)(_ChaynsContext.ChaynsFunctionsContext, f => f || {});
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.useIsAdminMode = void 0;
7
7
  var _useContextSelector2 = require("use-context-selector");
8
8
  var _ChaynsContext = require("../components/ChaynsContext");
9
- /**
10
- * @category Hooks
9
+ /**
10
+ * @category Hooks
11
11
  */
12
12
  const useIsAdminMode = () => {
13
13
  var _useContextSelector;
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.useLanguage = void 0;
7
7
  var _useContextSelector = require("use-context-selector");
8
8
  var _ChaynsContext = require("../components/ChaynsContext");
9
- /**
10
- * @category Hooks
9
+ /**
10
+ * @category Hooks
11
11
  */
12
12
  const useLanguage = () => (0, _useContextSelector.useContextSelector)(_ChaynsContext.ChaynsContext, v => v === null || v === void 0 ? void 0 : v.language);
13
13
  exports.useLanguage = useLanguage;
@@ -7,8 +7,8 @@ exports.usePages = exports.usePage = exports.getPage = void 0;
7
7
  var _useContextSelector = require("use-context-selector");
8
8
  var _ChaynsContext = require("../components/ChaynsContext");
9
9
  var _ChaynsProvider = require("../components/ChaynsProvider");
10
- /**
11
- * @category Hooks
10
+ /**
11
+ * @category Hooks
12
12
  */
13
13
  const usePages = ({
14
14
  siteId
@@ -21,8 +21,8 @@ const usePages = ({
21
21
  }
22
22
  return pages;
23
23
  };
24
- /**
25
- * @category Hooks
24
+ /**
25
+ * @category Hooks
26
26
  */
27
27
  exports.usePages = usePages;
28
28
  const usePage = ({
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.useParameters = void 0;
7
7
  var _useContextSelector = require("use-context-selector");
8
8
  var _ChaynsContext = require("../components/ChaynsContext");
9
- /**
10
- * @category Hooks
9
+ /**
10
+ * @category Hooks
11
11
  */
12
12
  const useParameters = () => (0, _useContextSelector.useContextSelector)(_ChaynsContext.ChaynsContext, v => (v === null || v === void 0 ? void 0 : v.parameters) || []);
13
13
  exports.useParameters = useParameters;
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.useSite = void 0;
7
7
  var _useContextSelector = require("use-context-selector");
8
8
  var _ChaynsContext = require("../components/ChaynsContext");
9
- /**
10
- * @category Hooks
9
+ /**
10
+ * @category Hooks
11
11
  */
12
12
  const useSite = () => (0, _useContextSelector.useContextSelector)(_ChaynsContext.ChaynsContext, v => v === null || v === void 0 ? void 0 : v.site);
13
13
  exports.useSite = useSite;
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.useUser = void 0;
7
7
  var _useContextSelector = require("use-context-selector");
8
8
  var _ChaynsContext = require("../components/ChaynsContext");
9
- /**
10
- * @category Hooks
9
+ /**
10
+ * @category Hooks
11
11
  */
12
12
  const useUser = () => (0, _useContextSelector.useContextSelector)(_ChaynsContext.ChaynsContext, v => (v === null || v === void 0 ? void 0 : v.user) || {});
13
13
  exports.useUser = useUser;
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.useValues = void 0;
7
7
  var _useContextSelector = require("use-context-selector");
8
8
  var _ChaynsContext = require("../components/ChaynsContext");
9
- /**
10
- * @category Hooks
9
+ /**
10
+ * @category Hooks
11
11
  */
12
12
  const useValues = () => {
13
13
  const t = (0, _useContextSelector.useContextSelector)(_ChaynsContext.ChaynsContext, v => v || {});
@@ -8,8 +8,8 @@ var _useContextSelector = require("use-context-selector");
8
8
  var _react = require("react");
9
9
  var _ChaynsContext = require("../components/ChaynsContext");
10
10
  var _IChaynsReact = require("../types/IChaynsReact");
11
- /**
12
- * @category Hooks
11
+ /**
12
+ * @category Hooks
13
13
  */
14
14
  const useWindowMetricsListener = () => {
15
15
  const addListener = (0, _useContextSelector.useContextSelector)(_ChaynsContext.ChaynsFunctionsContext, v => v.addWindowMetricsListener);
@@ -24,8 +24,8 @@ const useWindowMetricsListener = () => {
24
24
  // eslint-disable-next-line react-hooks/exhaustive-deps
25
25
  }, []);
26
26
  };
27
- /**
28
- * @category Hooks
27
+ /**
28
+ * @category Hooks
29
29
  */
30
30
  exports.useWindowMetricsListener = useWindowMetricsListener;
31
31
  const useWindowMetrics = ({
@@ -28,7 +28,8 @@ const ChaynsHost = ({
28
28
  parameters,
29
29
  customData,
30
30
  environment,
31
- preventStagingReplacement
31
+ preventStagingReplacement,
32
+ dialog
32
33
  }) => {
33
34
  switch (type) {
34
35
  case 'client-iframe':
@@ -47,7 +48,8 @@ const ChaynsHost = ({
47
48
  parameters: parameters,
48
49
  environment: environment,
49
50
  customData: customData,
50
- preventStagingReplacement: preventStagingReplacement
51
+ preventStagingReplacement: preventStagingReplacement,
52
+ dialog: dialog
51
53
  });
52
54
  case 'client-module':
53
55
  return /*#__PURE__*/_react.default.createElement(_ModuleHost.default, {
@@ -83,7 +85,8 @@ const ChaynsHost = ({
83
85
  parameters: parameters,
84
86
  environment: environment,
85
87
  customData: customData,
86
- preventStagingReplacement: preventStagingReplacement
88
+ preventStagingReplacement: preventStagingReplacement,
89
+ dialog: dialog
87
90
  });
88
91
  case 'server-module':
89
92
  return /*#__PURE__*/_react.default.createElement(_ModuleHost.default, {
@@ -30,7 +30,8 @@ const HostIframe = ({
30
30
  parameters,
31
31
  environment,
32
32
  customData,
33
- preventStagingReplacement
33
+ preventStagingReplacement,
34
+ dialog
34
35
  }) => {
35
36
  const eventTarget = (0, _react.useRef)();
36
37
  const ref = (0, _react.useRef)();
@@ -56,7 +57,8 @@ const HostIframe = ({
56
57
  language,
57
58
  parameters,
58
59
  environment,
59
- customData
60
+ customData,
61
+ dialog
60
62
  };
61
63
  // endregion
62
64
 
@@ -68,7 +70,7 @@ const HostIframe = ({
68
70
  if (postForm) {
69
71
  var _await$functions$getA;
70
72
  const accessToken = (_await$functions$getA = await functions.getAccessToken()) !== null && _await$functions$getA !== void 0 ? _await$functions$getA : {};
71
- void (0, _postIframeForm.default)((0, _url.replaceStagingUrl)(preventStagingReplacement, src, environment.runtimeEnvironment), JSON.stringify({
73
+ void (0, _postIframeForm.default)((0, _url.replaceStagingUrl)(preventStagingReplacement, src, environment.buildEnvironment), JSON.stringify({
72
74
  ...initialData,
73
75
  pages: undefined,
74
76
  ...accessToken
@@ -116,6 +118,7 @@ const HostIframe = ({
116
118
  (0, _useUpdateData.default)(eventTarget.current, 'parameters', parameters);
117
119
  (0, _useUpdateData.default)(eventTarget.current, 'environment', environment);
118
120
  (0, _useUpdateData.default)(eventTarget.current, 'customData', customData);
121
+ (0, _useUpdateData.default)(eventTarget.current, 'dialog', dialog);
119
122
  // endregion
120
123
 
121
124
  return /*#__PURE__*/_react.default.createElement("iframe", _extends({
@@ -3,7 +3,14 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.TappEvent = exports.SharingApp = exports.ScreenSize = exports.ScanQrCodeCodeType = exports.ScanQrCodeCameraTypes = exports.RuntimeEnviroment = exports.Language = exports.IconType = exports.Gender = exports.Font = exports.FloatingButtonPosition = exports.Environment = exports.DeviceOs = exports.ColorMode = exports.BrowserName = exports.AppName = exports.AccessMode = void 0;
6
+ exports.TappEvent = exports.SharingApp = exports.ScreenSize = exports.ScanQrCodeCodeType = exports.ScanQrCodeCameraTypes = exports.RuntimeEnviroment = exports.Language = exports.IconType = exports.Gender = exports.Font = exports.FloatingButtonPosition = exports.Environment = exports.DialogType = exports.DialogButtonType = exports.DeviceOs = exports.ColorMode = exports.BrowserName = exports.AppName = exports.AccessMode = void 0;
7
+ let DialogButtonType;
8
+ exports.DialogButtonType = DialogButtonType;
9
+ (function (DialogButtonType) {
10
+ DialogButtonType[DialogButtonType["OK"] = 1] = "OK";
11
+ DialogButtonType[DialogButtonType["CANCEL"] = -1] = "CANCEL";
12
+ DialogButtonType[DialogButtonType["NEGATIVE"] = 0] = "NEGATIVE";
13
+ })(DialogButtonType || (exports.DialogButtonType = DialogButtonType = {}));
7
14
  let ScreenSize;
8
15
  exports.ScreenSize = ScreenSize;
9
16
  (function (ScreenSize) {
@@ -258,4 +265,17 @@ var selectType;
258
265
  (function (selectType) {
259
266
  selectType[selectType["DEFAULT"] = 0] = "DEFAULT";
260
267
  selectType[selectType["ICON"] = 1] = "ICON";
261
- })(selectType || (selectType = {}));
268
+ })(selectType || (selectType = {}));
269
+ let DialogType;
270
+ exports.DialogType = DialogType;
271
+ (function (DialogType) {
272
+ DialogType["ALERT"] = "alert";
273
+ DialogType["CONFIRM"] = "confirm";
274
+ DialogType["DATE"] = "date";
275
+ DialogType["FILE_SELECT"] = "fileSelect";
276
+ DialogType["IFRAME"] = "iframe";
277
+ DialogType["MODULE"] = "module";
278
+ DialogType["INPUT"] = "input";
279
+ DialogType["SELECT"] = "select";
280
+ DialogType["TOAST"] = "toast";
281
+ })(DialogType || (exports.DialogType = DialogType = {}));
@@ -35,7 +35,7 @@ const getDeviceInfo = (userAgent, acceptHeader) => {
35
35
  result.accessToken = undefined; // TODO
36
36
  result.os = parsedUA === null || parsedUA === void 0 ? void 0 : parsedUA.os;
37
37
  if (typeof window !== 'undefined') {
38
- result.screenSize = getScreenSize(window.innerWidth);
38
+ result.screenSize = getScreenSize(window.innerWidth, window.innerHeight);
39
39
  } else {
40
40
  // estimate size over user agent, very inaccurate, could be improved by setting a cookie with the screensize
41
41
  const screenSizeByUA = /mobi/i.test(userAgent) ? _IChaynsReact.ScreenSize.SM : _IChaynsReact.ScreenSize.XL;
@@ -49,15 +49,16 @@ const getClientDeviceInfo = () => ({
49
49
  isTouch: navigator.maxTouchPoints > 0 && window.matchMedia('(pointer: coarse)')
50
50
  });
51
51
  exports.getClientDeviceInfo = getClientDeviceInfo;
52
- const getScreenSize = width => {
52
+ const getScreenSize = (width, height) => {
53
+ const size = Math.max(width, height);
53
54
  let value;
54
- if (width > 1200) {
55
+ if (size > 1200) {
55
56
  value = _IChaynsReact.ScreenSize.XL;
56
- } else if (width > 993) {
57
+ } else if (size > 993) {
57
58
  value = _IChaynsReact.ScreenSize.LG;
58
- } else if (width > 769) {
59
+ } else if (size > 769) {
59
60
  value = _IChaynsReact.ScreenSize.MD;
60
- } else if (width > 556) {
61
+ } else if (size > 556) {
61
62
  value = _IChaynsReact.ScreenSize.SM;
62
63
  } else {
63
64
  value = _IChaynsReact.ScreenSize.XS;
@@ -4,10 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.AppWrapper = void 0;
7
+ var _lodash = _interopRequireDefault(require("lodash.throttle"));
7
8
  var _IChaynsReact = require("../types/IChaynsReact");
8
9
  var _appCall = _interopRequireDefault(require("../util/appCall"));
9
10
  var _deviceHelper = _interopRequireWildcard(require("../util/deviceHelper"));
10
- var _visibilityChangeListener = require("../calls/visibilityChangeListener");
11
11
  var _getUserInfo = _interopRequireDefault(require("../calls/getUserInfo"));
12
12
  var _sendMessage = require("../calls/sendMessage");
13
13
  var _apiListenerHelper = require("../helper/apiListenerHelper");
@@ -17,9 +17,10 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
17
17
  /* eslint-disable */
18
18
  // @ts-nocheck
19
19
 
20
+ let appWrapperDialogId = 0;
20
21
  class AppWrapper {
21
22
  values = null;
22
- accessToken = "";
23
+ accessToken = '';
23
24
  mapOldApiToNew(retVal) {
24
25
  var _window, _window2, _AppInfo$TappSelected;
25
26
  const {
@@ -98,6 +99,12 @@ class AppWrapper {
98
99
  notImplemented(call) {
99
100
  console.warn(`call ${call} not implement in app`);
100
101
  }
102
+ dispatchDialogChange(detail) {
103
+ this.dialogs = detail;
104
+ this.dialogEventTarget.dispatchEvent(new CustomEvent('change', {
105
+ detail
106
+ }));
107
+ }
101
108
  counter = 0;
102
109
  appCall(action, value = {}, {
103
110
  callback,
@@ -122,7 +129,7 @@ class AppWrapper {
122
129
  }
123
130
  resolve((_v$retVal2 = v === null || v === void 0 ? void 0 : v.retVal) !== null && _v$retVal2 !== void 0 ? _v$retVal2 : v);
124
131
  };
125
- value.callback = "window." + callbackName;
132
+ value.callback = 'window.' + callbackName;
126
133
  (0, _appCall.default)({
127
134
  action,
128
135
  value
@@ -133,50 +140,83 @@ class AppWrapper {
133
140
  getAccessToken: async () => ({
134
141
  accessToken: this.accessToken
135
142
  }),
136
- // addGeoLocationListener: async (value , callback) => {
137
- // return invokeAppCall({
138
- // 'action': 14,
139
- // 'value': {
140
- // 'permanent': false,
141
- // callback: callback
142
- // }
143
- // });
144
- // },
145
- // addScrollListener: async (value, callback) => {
146
- //
147
- // },
143
+ addGeoLocationListener: async (value, callback) => {
144
+ const {
145
+ id,
146
+ shouldInitialize
147
+ } = (0, _apiListenerHelper.addApiListener)('geoLocationListener', callback);
148
+ if (shouldInitialize) {
149
+ this.appCall(14, {
150
+ permanent: true
151
+ }, {
152
+ callback: v => {
153
+ var _v$accuracy, _v$code;
154
+ (0, _apiListenerHelper.dispatchApiEvent)('geoLocationListener', {
155
+ latitude: v.latitude,
156
+ longitude: v.longitude,
157
+ accuracy: (_v$accuracy = v.accuracy) !== null && _v$accuracy !== void 0 ? _v$accuracy : null,
158
+ speed: v.speed,
159
+ code: (_v$code = v.code) !== null && _v$code !== void 0 ? _v$code : null
160
+ });
161
+ }
162
+ });
163
+ }
164
+ return id;
165
+ },
166
+ addScrollListener: async (value, callback) => {
167
+ let throttledCallback = callback;
168
+ if (value.throttle) {
169
+ throttledCallback = (0, _lodash.default)(callback, value.throttle);
170
+ }
171
+ const {
172
+ id,
173
+ shouldInitialize
174
+ } = (0, _apiListenerHelper.addApiListener)('scrollListener', throttledCallback);
175
+ if (shouldInitialize) {
176
+ window.addEventListener('scroll', this.scrollListener = () => {
177
+ void (async () => {
178
+ (0, _apiListenerHelper.dispatchApiEvent)('scrollListener', {
179
+ scrollX: window.scrollX,
180
+ scrollY: window.scrollY
181
+ });
182
+ })();
183
+ });
184
+ }
185
+ return id;
186
+ },
148
187
  addVisibilityChangeListener: async callback => {
188
+ const {
189
+ id,
190
+ shouldInitialize
191
+ } = (0, _apiListenerHelper.addApiListener)('visibilityChangeListener', callback);
192
+ if (shouldInitialize) {
193
+ this.appCall(60, {}, {
194
+ callback: v => {
195
+ (0, _apiListenerHelper.dispatchApiEvent)('visibilityChangeListener', {
196
+ isVisible: v.tappEvent === _IChaynsReact.TappEvent.OnShow,
197
+ tappEvent: v.tappEvent
198
+ });
199
+ }
200
+ });
201
+ }
202
+ return id;
203
+ },
204
+ addWindowMetricsListener: async callback => {
149
205
  const {
150
206
  id,
151
207
  shouldInitialize
152
208
  } = (0, _apiListenerHelper.addApiListener)('windowMetricsListener', callback);
153
- this.appCall(60, {}, {
154
- callback: v => {
155
- console.log("v", v);
156
- (0, _apiListenerHelper.dispatchApiEvent)("windowMetricsListener", {
157
- isVisible: v.tappEvent === _IChaynsReact.TappEvent.OnShow,
158
- tappEvent: v.tappEvent
159
- });
160
- }
161
- });
209
+ if (shouldInitialize) {
210
+ window.addEventListener('resize', this.resizeListener = () => {
211
+ void (async () => {
212
+ (0, _apiListenerHelper.dispatchApiEvent)('windowMetricsListener', await this.functions.getWindowMetrics());
213
+ })();
214
+ });
215
+ }
162
216
  return id;
163
217
  },
164
- // addWindowMetricsListener: async (callback) => {
165
- // const { id, shouldInitialize } = addApiListener('windowMetricsListener', callback);
166
- //
167
- // if (shouldInitialize) {
168
- // window.addEventListener('resize', this.resizeListener = () => {
169
- // void (async() => {
170
- // dispatchApiEvent('windowMetricsListener', {
171
- //
172
- // });
173
- // })();
174
- // })
175
- // }
176
- // return id;
177
- // },
178
218
  customCallbackFunction: async () => {
179
- this.notImplemented("customCallbackFunction");
219
+ this.notImplemented('customCallbackFunction');
180
220
  },
181
221
  getAvailableSharingServices: async () => {
182
222
  const res = await this.appCall(79);
@@ -264,9 +304,9 @@ class AppWrapper {
264
304
  awaitResult: false
265
305
  });
266
306
  },
267
- // openUrl: async (value) => {
268
- //
269
- // },
307
+ openUrl: async value => {
308
+ window.open(value.url);
309
+ },
270
310
  openVideo: async value => {
271
311
  this.appCall(15, {
272
312
  url: value.url
@@ -280,19 +320,41 @@ class AppWrapper {
280
320
  });
281
321
  },
282
322
  refreshData: async value => {
283
- this.notImplemented("refreshData");
284
- },
285
- // removeGeoLocationListener: async (id) => {
286
- // },
287
- // removeScrollListener: async (id) => {
288
- // },
289
- removeVisibilityChangeListener(number) {
290
- (0, _visibilityChangeListener.removeVisibilityChangeListener)(number);
291
- return Promise.resolve();
292
- },
293
- // removeWindowMetricsListener: async (id) => {
294
- //
295
- // },
323
+ this.notImplemented('refreshData');
324
+ },
325
+ removeGeoLocationListener: async id => {
326
+ const {
327
+ shouldRemove
328
+ } = (0, _apiListenerHelper.removeApiListener)('geoLocationListener', id);
329
+ if (shouldRemove) {
330
+ // App does not support removal of request geo location call with permanent true which makes this a no-op
331
+ }
332
+ },
333
+ removeScrollListener: async id => {
334
+ const {
335
+ shouldRemove
336
+ } = (0, _apiListenerHelper.removeApiListener)('scrollListener', id);
337
+ if (shouldRemove && this.scrollListener) {
338
+ window.removeEventListener('scroll', this.scrollListener);
339
+ this.scrollListener = null;
340
+ }
341
+ },
342
+ removeVisibilityChangeListener: async id => {
343
+ const {
344
+ shouldRemove
345
+ } = (0, _apiListenerHelper.removeApiListener)('visibilityChangeListener', id);
346
+ if (shouldRemove) {
347
+ // App does not support removal of onActivate callback which makes this a no-op
348
+ }
349
+ },
350
+ removeWindowMetricsListener: async id => {
351
+ const shouldRemove = (0, _apiListenerHelper.removeApiListener)('windowMetricsListener', id);
352
+ if (shouldRemove) {
353
+ void this.exposedFunctions.removeWindowMetricsListener(id);
354
+ if (this.resizeListener) window.removeEventListener('resize', this.resizeListener);
355
+ this.resizeListener = null;
356
+ }
357
+ },
296
358
  selectPage: async options => {
297
359
  void this.appCall(2, {
298
360
  id: options.id,
@@ -323,7 +385,7 @@ class AppWrapper {
323
385
  return (0, _sendMessage.sendMessageToUser)(this, message, userId);
324
386
  },
325
387
  setAdminMode: async () => {
326
- this.notImplemented("setAdminMode");
388
+ this.notImplemented('setAdminMode');
327
389
  },
328
390
  setDisplayTimeout: async enabled => {
329
391
  this.appCall(94, {
@@ -348,10 +410,10 @@ class AppWrapper {
348
410
  }, callback));
349
411
  },
350
412
  setHeight: async () => {
351
- this.notImplemented("setOverlay");
413
+ this.notImplemented('setOverlay');
352
414
  },
353
415
  setOverlay: async () => {
354
- this.notImplemented("setOverlay");
416
+ this.notImplemented('setOverlay');
355
417
  },
356
418
  setRefreshScrollEnabled: async isEnabled => {
357
419
  this.appCall(0, {
@@ -367,7 +429,7 @@ class AppWrapper {
367
429
  return await this.appCall(34, value);
368
430
  },
369
431
  setTempDesignSettings: async () => {
370
- this.notImplemented("setTempDesignSettings");
432
+ this.notImplemented('setTempDesignSettings');
371
433
  },
372
434
  setWaitCursor: async value => {
373
435
  void this.appCall(1, {
@@ -410,8 +472,51 @@ class AppWrapper {
410
472
  void this.appCall(19, value, {
411
473
  awaitResult: false
412
474
  });
475
+ },
476
+ openDialog: async (...args) => {
477
+ return this.openDialog(...args);
478
+ },
479
+ createDialog: config => {
480
+ return {
481
+ close: async value => {
482
+ this.dialogs.find(x => x.dialogId === dialogId).eventTarget.dispatchEvent(new CustomEvent('close', {
483
+ detail: data
484
+ }));
485
+ },
486
+ open: async () => {
487
+ return await this.openDialog(config);
488
+ }
489
+ };
490
+ },
491
+ closeDialog: (dialogId, data) => {
492
+ try {
493
+ this.dialogs.find(x => x.dialogId === dialogId).eventTarget.dispatchEvent(new CustomEvent('requestClose', {
494
+ detail: data
495
+ }));
496
+ } catch (e) {
497
+ console.error(e);
498
+ }
413
499
  }
414
500
  };
501
+ async openDialog(config) {
502
+ const currentDialogId = appWrapperDialogId;
503
+ const res = await new Promise(resolve => {
504
+ const eventTarget = new EventTarget();
505
+ this.dispatchDialogChange([...(this.dialogs || []), {
506
+ config,
507
+ resolve,
508
+ dialogId: appWrapperDialogId++,
509
+ eventTarget
510
+ }]);
511
+ });
512
+ this.dispatchDialogChange(this.dialogs.filter(x => x.dialogId !== currentDialogId));
513
+ return res;
514
+ }
515
+ dialogs = [];
516
+ dialogEventTarget = new EventTarget();
517
+ getDialogEventTarget() {
518
+ return this.dialogEventTarget;
519
+ }
415
520
  async init() {
416
521
  this.values = this.mapOldApiToNew(await this.appCall(18));
417
522
  return undefined;
@@ -429,5 +534,14 @@ class AppWrapper {
429
534
  getInitialData() {
430
535
  return this.values;
431
536
  }
537
+ createDialog(config) {
538
+ return {
539
+ close: () => {},
540
+ open: async () => {
541
+ const dialog = await functions.openDialog(config);
542
+ return dialog;
543
+ }
544
+ };
545
+ }
432
546
  }
433
547
  exports.AppWrapper = AppWrapper;
@@ -233,7 +233,22 @@ class FrameWrapper {
233
233
  scrollByY: async (value, duration) => {
234
234
  if (!this.initialized) await this.ready;
235
235
  return this.exposedFunctions.scrollByY(value, duration);
236
- }
236
+ },
237
+ createDialog: config => {
238
+ return {
239
+ close: async (buttonType, data) => {
240
+ await this.exposedFunctions.closeDialog(buttonType, data);
241
+ },
242
+ open: async () => {
243
+ return await this.exposedFunctions.openDialog(config);
244
+ }
245
+ };
246
+ },
247
+ closeDialog: async (buttonType, value) => {
248
+ if (!this.initialized) await this.ready;
249
+ return this.exposedFunctions.closeDialog(buttonType, value);
250
+ },
251
+ openDialog: async value => {}
237
252
  };
238
253
  initialized = false;
239
254
  constructor() {
@@ -24,6 +24,17 @@ class ModuleFederationWrapper {
24
24
  // eslint-disable-next-line
25
25
  this.functions[k] = async (...args) => fn(...args);
26
26
  });
27
+ this.functions.createDialog = config => {
28
+ return {
29
+ close: (buttonType, data) => {
30
+ return functions.closeDialog(buttonType, data);
31
+ },
32
+ open: async () => {
33
+ const dialog = await functions.openDialog(config);
34
+ return dialog;
35
+ }
36
+ };
37
+ };
27
38
  this.functions.addWindowMetricsListener = async callback => {
28
39
  const {
29
40
  id,