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
@@ -1,7 +1,7 @@
1
1
  import { useContextSelector } from 'use-context-selector';
2
2
  import { ChaynsContext } from '../components/ChaynsContext';
3
3
 
4
- /**
5
- * @category Hooks
4
+ /**
5
+ * @category Hooks
6
6
  */
7
7
  export const useCurrentPage = () => useContextSelector(ChaynsContext, v => v === null || v === void 0 ? void 0 : v.currentPage);
@@ -1,7 +1,7 @@
1
1
  import { useContextSelector } from 'use-context-selector';
2
2
  import { ChaynsContext } from '../components/ChaynsContext';
3
3
 
4
- /**
5
- * @category Hooks
4
+ /**
5
+ * @category Hooks
6
6
  */
7
7
  export const useCustomData = () => useContextSelector(ChaynsContext, v => v === null || v === void 0 ? void 0 : v.customData);
@@ -1,6 +1,6 @@
1
1
  import { useContextSelector } from 'use-context-selector';
2
2
  import { ChaynsContext } from '../components/ChaynsContext';
3
- /**
4
- * @category Hooks
3
+ /**
4
+ * @category Hooks
5
5
  */
6
6
  export const useDevice = () => useContextSelector(ChaynsContext, v => v === null || v === void 0 ? void 0 : v.device);
@@ -0,0 +1,24 @@
1
+ import { useContextSelector } from "use-context-selector";
2
+ import { ChaynsContext, ChaynsFunctionsContext } from "../components/ChaynsContext";
3
+
4
+ /**
5
+ * @category Hooks
6
+ */
7
+ export const useDialogState = () => {
8
+ const closeDialog = useContextSelector(ChaynsFunctionsContext, v => v === null || v === void 0 ? void 0 : v.closeDialog);
9
+ const isClosingRequested = useContextSelector(ChaynsContext, v => (v === null || v === void 0 ? void 0 : v.dialog).isClosingRequested);
10
+ return {
11
+ closeDialog,
12
+ isClosingRequested
13
+ };
14
+ };
15
+
16
+ /**
17
+ * @category Hooks
18
+ */
19
+ export const useDialogData = () => {
20
+ const inputData = useContextSelector(ChaynsContext, v => (v === null || v === void 0 ? void 0 : v.dialog).dialogInput);
21
+ return {
22
+ inputData
23
+ };
24
+ };
@@ -1,6 +1,6 @@
1
1
  import { useContextSelector } from 'use-context-selector';
2
2
  import { ChaynsContext } from '../components/ChaynsContext';
3
- /**
4
- * @category Hooks
3
+ /**
4
+ * @category Hooks
5
5
  */
6
6
  export const useEnvironment = () => useContextSelector(ChaynsContext, v => v === null || v === void 0 ? void 0 : v.environment);
@@ -1,7 +1,7 @@
1
1
  import { useContextSelector } from "use-context-selector";
2
2
  import { ChaynsFunctionsContext } from "../components/ChaynsContext";
3
- /**
4
- * @category Hooks
3
+ /**
4
+ * @category Hooks
5
5
  */
6
6
  export const useFunctions = () => {
7
7
  const t = useContextSelector(ChaynsFunctionsContext, f => f || {});
@@ -1,7 +1,7 @@
1
1
  import { useContextSelector } from 'use-context-selector';
2
2
  import { ChaynsContext } from '../components/ChaynsContext';
3
- /**
4
- * @category Hooks
3
+ /**
4
+ * @category Hooks
5
5
  */
6
6
  export const useIsAdminMode = () => {
7
7
  var _useContextSelector;
@@ -1,6 +1,6 @@
1
1
  import { useContextSelector } from 'use-context-selector';
2
2
  import { ChaynsContext } from '../components/ChaynsContext';
3
- /**
4
- * @category Hooks
3
+ /**
4
+ * @category Hooks
5
5
  */
6
6
  export const useLanguage = () => useContextSelector(ChaynsContext, v => v === null || v === void 0 ? void 0 : v.language);
@@ -1,8 +1,8 @@
1
1
  import { useContextSelector } from 'use-context-selector';
2
2
  import { ChaynsContext } from '../components/ChaynsContext';
3
3
  import { moduleWrapper } from "../components/ChaynsProvider";
4
- /**
5
- * @category Hooks
4
+ /**
5
+ * @category Hooks
6
6
  */
7
7
  export const usePages = function () {
8
8
  let {
@@ -16,8 +16,8 @@ export const usePages = function () {
16
16
  }
17
17
  return pages;
18
18
  };
19
- /**
20
- * @category Hooks
19
+ /**
20
+ * @category Hooks
21
21
  */
22
22
  export const usePage = _ref => {
23
23
  let {
@@ -1,6 +1,6 @@
1
1
  import { useContextSelector } from 'use-context-selector';
2
2
  import { ChaynsContext } from '../components/ChaynsContext';
3
- /**
4
- * @category Hooks
3
+ /**
4
+ * @category Hooks
5
5
  */
6
6
  export const useParameters = () => useContextSelector(ChaynsContext, v => (v === null || v === void 0 ? void 0 : v.parameters) || []);
@@ -1,6 +1,6 @@
1
1
  import { useContextSelector } from 'use-context-selector';
2
2
  import { ChaynsContext } from '../components/ChaynsContext';
3
- /**
4
- * @category Hooks
3
+ /**
4
+ * @category Hooks
5
5
  */
6
6
  export const useSite = () => useContextSelector(ChaynsContext, v => v === null || v === void 0 ? void 0 : v.site);
@@ -1,6 +1,6 @@
1
1
  import { useContextSelector } from 'use-context-selector';
2
2
  import { ChaynsContext } from '../components/ChaynsContext';
3
- /**
4
- * @category Hooks
3
+ /**
4
+ * @category Hooks
5
5
  */
6
6
  export const useUser = () => useContextSelector(ChaynsContext, v => (v === null || v === void 0 ? void 0 : v.user) || {});
@@ -1,7 +1,7 @@
1
1
  import { useContextSelector } from 'use-context-selector';
2
2
  import { ChaynsContext } from '../components/ChaynsContext';
3
- /**
4
- * @category Hooks
3
+ /**
4
+ * @category Hooks
5
5
  */
6
6
  export const useValues = () => {
7
7
  const t = useContextSelector(ChaynsContext, v => v || {});
@@ -2,8 +2,8 @@ import { useContextSelector } from 'use-context-selector';
2
2
  import { useCallback, useEffect, useRef, useState } from 'react';
3
3
  import { ChaynsFunctionsContext } from '../components/ChaynsContext';
4
4
  import { ScreenSize } from '../types/IChaynsReact';
5
- /**
6
- * @category Hooks
5
+ /**
6
+ * @category Hooks
7
7
  */
8
8
  export const useWindowMetricsListener = () => {
9
9
  const addListener = useContextSelector(ChaynsFunctionsContext, v => v.addWindowMetricsListener);
@@ -18,8 +18,8 @@ export const useWindowMetricsListener = () => {
18
18
  // eslint-disable-next-line react-hooks/exhaustive-deps
19
19
  }, []);
20
20
  };
21
- /**
22
- * @category Hooks
21
+ /**
22
+ * @category Hooks
23
23
  */
24
24
  export const useWindowMetrics = function () {
25
25
  let {
@@ -22,7 +22,8 @@ const ChaynsHost = _ref => {
22
22
  parameters,
23
23
  customData,
24
24
  environment,
25
- preventStagingReplacement
25
+ preventStagingReplacement,
26
+ dialog
26
27
  } = _ref;
27
28
  switch (type) {
28
29
  case 'client-iframe':
@@ -41,7 +42,8 @@ const ChaynsHost = _ref => {
41
42
  parameters: parameters,
42
43
  environment: environment,
43
44
  customData: customData,
44
- preventStagingReplacement: preventStagingReplacement
45
+ preventStagingReplacement: preventStagingReplacement,
46
+ dialog: dialog
45
47
  });
46
48
  case 'client-module':
47
49
  return /*#__PURE__*/React.createElement(ModuleHost, {
@@ -77,7 +79,8 @@ const ChaynsHost = _ref => {
77
79
  parameters: parameters,
78
80
  environment: environment,
79
81
  customData: customData,
80
- preventStagingReplacement: preventStagingReplacement
82
+ preventStagingReplacement: preventStagingReplacement,
83
+ dialog: dialog
81
84
  });
82
85
  case 'server-module':
83
86
  return /*#__PURE__*/React.createElement(ModuleHost, {
@@ -22,7 +22,8 @@ const HostIframe = _ref => {
22
22
  parameters,
23
23
  environment,
24
24
  customData,
25
- preventStagingReplacement
25
+ preventStagingReplacement,
26
+ dialog
26
27
  } = _ref;
27
28
  const eventTarget = useRef();
28
29
  const ref = useRef();
@@ -48,7 +49,8 @@ const HostIframe = _ref => {
48
49
  language,
49
50
  parameters,
50
51
  environment,
51
- customData
52
+ customData,
53
+ dialog
52
54
  };
53
55
  // endregion
54
56
 
@@ -60,7 +62,7 @@ const HostIframe = _ref => {
60
62
  if (postForm) {
61
63
  var _await$functions$getA;
62
64
  const accessToken = (_await$functions$getA = await functions.getAccessToken()) !== null && _await$functions$getA !== void 0 ? _await$functions$getA : {};
63
- void postIframeForm(replaceStagingUrl(preventStagingReplacement, src, environment.runtimeEnvironment), JSON.stringify({
65
+ void postIframeForm(replaceStagingUrl(preventStagingReplacement, src, environment.buildEnvironment), JSON.stringify({
64
66
  ...initialData,
65
67
  pages: undefined,
66
68
  ...accessToken
@@ -108,6 +110,7 @@ const HostIframe = _ref => {
108
110
  useUpdateData(eventTarget.current, 'parameters', parameters);
109
111
  useUpdateData(eventTarget.current, 'environment', environment);
110
112
  useUpdateData(eventTarget.current, 'customData', customData);
113
+ useUpdateData(eventTarget.current, 'dialog', dialog);
111
114
  // endregion
112
115
 
113
116
  return /*#__PURE__*/React.createElement("iframe", _extends({
@@ -1,3 +1,9 @@
1
+ export let DialogButtonType;
2
+ (function (DialogButtonType) {
3
+ DialogButtonType[DialogButtonType["OK"] = 1] = "OK";
4
+ DialogButtonType[DialogButtonType["CANCEL"] = -1] = "CANCEL";
5
+ DialogButtonType[DialogButtonType["NEGATIVE"] = 0] = "NEGATIVE";
6
+ })(DialogButtonType || (DialogButtonType = {}));
1
7
  export let ScreenSize;
2
8
  (function (ScreenSize) {
3
9
  ScreenSize[ScreenSize["XS"] = 0] = "XS";
@@ -235,4 +241,16 @@ var selectType;
235
241
  (function (selectType) {
236
242
  selectType[selectType["DEFAULT"] = 0] = "DEFAULT";
237
243
  selectType[selectType["ICON"] = 1] = "ICON";
238
- })(selectType || (selectType = {}));
244
+ })(selectType || (selectType = {}));
245
+ export let DialogType;
246
+ (function (DialogType) {
247
+ DialogType["ALERT"] = "alert";
248
+ DialogType["CONFIRM"] = "confirm";
249
+ DialogType["DATE"] = "date";
250
+ DialogType["FILE_SELECT"] = "fileSelect";
251
+ DialogType["IFRAME"] = "iframe";
252
+ DialogType["MODULE"] = "module";
253
+ DialogType["INPUT"] = "input";
254
+ DialogType["SELECT"] = "select";
255
+ DialogType["TOAST"] = "toast";
256
+ })(DialogType || (DialogType = {}));
@@ -29,7 +29,7 @@ const getDeviceInfo = (userAgent, acceptHeader) => {
29
29
  result.accessToken = undefined; // TODO
30
30
  result.os = parsedUA === null || parsedUA === void 0 ? void 0 : parsedUA.os;
31
31
  if (typeof window !== 'undefined') {
32
- result.screenSize = getScreenSize(window.innerWidth);
32
+ result.screenSize = getScreenSize(window.innerWidth, window.innerHeight);
33
33
  } else {
34
34
  // estimate size over user agent, very inaccurate, could be improved by setting a cookie with the screensize
35
35
  const screenSizeByUA = /mobi/i.test(userAgent) ? ScreenSize.SM : ScreenSize.XL;
@@ -42,15 +42,16 @@ const getDeviceInfo = (userAgent, acceptHeader) => {
42
42
  export const getClientDeviceInfo = () => ({
43
43
  isTouch: navigator.maxTouchPoints > 0 && window.matchMedia('(pointer: coarse)')
44
44
  });
45
- export const getScreenSize = width => {
45
+ export const getScreenSize = (width, height) => {
46
+ const size = Math.max(width, height);
46
47
  let value;
47
- if (width > 1200) {
48
+ if (size > 1200) {
48
49
  value = ScreenSize.XL;
49
- } else if (width > 993) {
50
+ } else if (size > 993) {
50
51
  value = ScreenSize.LG;
51
- } else if (width > 769) {
52
+ } else if (size > 769) {
52
53
  value = ScreenSize.MD;
53
- } else if (width > 556) {
54
+ } else if (size > 556) {
54
55
  value = ScreenSize.SM;
55
56
  } else {
56
57
  value = ScreenSize.XS;
@@ -1,14 +1,17 @@
1
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
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
4
  /* eslint-disable */
3
5
  // @ts-nocheck
4
6
 
7
+ import throttle from 'lodash.throttle';
5
8
  import { Environment, Font, Gender, IconType, RuntimeEnviroment, TappEvent } from '../types/IChaynsReact';
6
- import invokeAppCall from "../util/appCall";
7
- import getDeviceInfo, { getScreenSize } from "../util/deviceHelper";
8
- import { removeVisibilityChangeListener } from "../calls/visibilityChangeListener";
9
- import getUserInfo from "../calls/getUserInfo";
10
- import { sendMessageToGroup, sendMessageToPage, sendMessageToUser } from "../calls/sendMessage";
11
- import { addApiListener, dispatchApiEvent } from "../helper/apiListenerHelper";
9
+ import invokeAppCall from '../util/appCall';
10
+ import getDeviceInfo, { getScreenSize } from '../util/deviceHelper';
11
+ import getUserInfo from '../calls/getUserInfo';
12
+ import { sendMessageToGroup, sendMessageToPage, sendMessageToUser } from '../calls/sendMessage';
13
+ import { addApiListener, dispatchApiEvent, removeApiListener } from '../helper/apiListenerHelper';
14
+ let appWrapperDialogId = 0;
12
15
  export class AppWrapper {
13
16
  mapOldApiToNew(retVal) {
14
17
  var _window, _window2, _AppInfo$TappSelected;
@@ -85,57 +88,91 @@ export class AppWrapper {
85
88
  };
86
89
  }
87
90
  constructor() {
91
+ var _this = this;
88
92
  _defineProperty(this, "values", null);
89
- _defineProperty(this, "accessToken", "");
93
+ _defineProperty(this, "accessToken", '');
90
94
  _defineProperty(this, "counter", 0);
91
95
  _defineProperty(this, "functions", {
92
96
  getAccessToken: async () => ({
93
97
  accessToken: this.accessToken
94
98
  }),
95
- // addGeoLocationListener: async (value , callback) => {
96
- // return invokeAppCall({
97
- // 'action': 14,
98
- // 'value': {
99
- // 'permanent': false,
100
- // callback: callback
101
- // }
102
- // });
103
- // },
104
- // addScrollListener: async (value, callback) => {
105
- //
106
- // },
99
+ addGeoLocationListener: async (value, callback) => {
100
+ const {
101
+ id,
102
+ shouldInitialize
103
+ } = addApiListener('geoLocationListener', callback);
104
+ if (shouldInitialize) {
105
+ this.appCall(14, {
106
+ permanent: true
107
+ }, {
108
+ callback: v => {
109
+ var _v$accuracy, _v$code;
110
+ dispatchApiEvent('geoLocationListener', {
111
+ latitude: v.latitude,
112
+ longitude: v.longitude,
113
+ accuracy: (_v$accuracy = v.accuracy) !== null && _v$accuracy !== void 0 ? _v$accuracy : null,
114
+ speed: v.speed,
115
+ code: (_v$code = v.code) !== null && _v$code !== void 0 ? _v$code : null
116
+ });
117
+ }
118
+ });
119
+ }
120
+ return id;
121
+ },
122
+ addScrollListener: async (value, callback) => {
123
+ let throttledCallback = callback;
124
+ if (value.throttle) {
125
+ throttledCallback = throttle(callback, value.throttle);
126
+ }
127
+ const {
128
+ id,
129
+ shouldInitialize
130
+ } = addApiListener('scrollListener', throttledCallback);
131
+ if (shouldInitialize) {
132
+ window.addEventListener('scroll', this.scrollListener = () => {
133
+ void (async () => {
134
+ dispatchApiEvent('scrollListener', {
135
+ scrollX: window.scrollX,
136
+ scrollY: window.scrollY
137
+ });
138
+ })();
139
+ });
140
+ }
141
+ return id;
142
+ },
107
143
  addVisibilityChangeListener: async callback => {
144
+ const {
145
+ id,
146
+ shouldInitialize
147
+ } = addApiListener('visibilityChangeListener', callback);
148
+ if (shouldInitialize) {
149
+ this.appCall(60, {}, {
150
+ callback: v => {
151
+ dispatchApiEvent('visibilityChangeListener', {
152
+ isVisible: v.tappEvent === TappEvent.OnShow,
153
+ tappEvent: v.tappEvent
154
+ });
155
+ }
156
+ });
157
+ }
158
+ return id;
159
+ },
160
+ addWindowMetricsListener: async callback => {
108
161
  const {
109
162
  id,
110
163
  shouldInitialize
111
164
  } = addApiListener('windowMetricsListener', callback);
112
- this.appCall(60, {}, {
113
- callback: v => {
114
- console.log("v", v);
115
- dispatchApiEvent("windowMetricsListener", {
116
- isVisible: v.tappEvent === TappEvent.OnShow,
117
- tappEvent: v.tappEvent
118
- });
119
- }
120
- });
165
+ if (shouldInitialize) {
166
+ window.addEventListener('resize', this.resizeListener = () => {
167
+ void (async () => {
168
+ dispatchApiEvent('windowMetricsListener', await this.functions.getWindowMetrics());
169
+ })();
170
+ });
171
+ }
121
172
  return id;
122
173
  },
123
- // addWindowMetricsListener: async (callback) => {
124
- // const { id, shouldInitialize } = addApiListener('windowMetricsListener', callback);
125
- //
126
- // if (shouldInitialize) {
127
- // window.addEventListener('resize', this.resizeListener = () => {
128
- // void (async() => {
129
- // dispatchApiEvent('windowMetricsListener', {
130
- //
131
- // });
132
- // })();
133
- // })
134
- // }
135
- // return id;
136
- // },
137
174
  customCallbackFunction: async () => {
138
- this.notImplemented("customCallbackFunction");
175
+ this.notImplemented('customCallbackFunction');
139
176
  },
140
177
  getAvailableSharingServices: async () => {
141
178
  const res = await this.appCall(79);
@@ -224,9 +261,9 @@ export class AppWrapper {
224
261
  awaitResult: false
225
262
  });
226
263
  },
227
- // openUrl: async (value) => {
228
- //
229
- // },
264
+ openUrl: async value => {
265
+ window.open(value.url);
266
+ },
230
267
  openVideo: async value => {
231
268
  this.appCall(15, {
232
269
  url: value.url
@@ -240,19 +277,41 @@ export class AppWrapper {
240
277
  });
241
278
  },
242
279
  refreshData: async value => {
243
- this.notImplemented("refreshData");
244
- },
245
- // removeGeoLocationListener: async (id) => {
246
- // },
247
- // removeScrollListener: async (id) => {
248
- // },
249
- removeVisibilityChangeListener(number) {
250
- removeVisibilityChangeListener(number);
251
- return Promise.resolve();
252
- },
253
- // removeWindowMetricsListener: async (id) => {
254
- //
255
- // },
280
+ this.notImplemented('refreshData');
281
+ },
282
+ removeGeoLocationListener: async id => {
283
+ const {
284
+ shouldRemove
285
+ } = removeApiListener('geoLocationListener', id);
286
+ if (shouldRemove) {
287
+ // App does not support removal of request geo location call with permanent true which makes this a no-op
288
+ }
289
+ },
290
+ removeScrollListener: async id => {
291
+ const {
292
+ shouldRemove
293
+ } = removeApiListener('scrollListener', id);
294
+ if (shouldRemove && this.scrollListener) {
295
+ window.removeEventListener('scroll', this.scrollListener);
296
+ this.scrollListener = null;
297
+ }
298
+ },
299
+ removeVisibilityChangeListener: async id => {
300
+ const {
301
+ shouldRemove
302
+ } = removeApiListener('visibilityChangeListener', id);
303
+ if (shouldRemove) {
304
+ // App does not support removal of onActivate callback which makes this a no-op
305
+ }
306
+ },
307
+ removeWindowMetricsListener: async id => {
308
+ const shouldRemove = removeApiListener('windowMetricsListener', id);
309
+ if (shouldRemove) {
310
+ void this.exposedFunctions.removeWindowMetricsListener(id);
311
+ if (this.resizeListener) window.removeEventListener('resize', this.resizeListener);
312
+ this.resizeListener = null;
313
+ }
314
+ },
256
315
  selectPage: async options => {
257
316
  void this.appCall(2, {
258
317
  id: options.id,
@@ -283,7 +342,7 @@ export class AppWrapper {
283
342
  return sendMessageToUser(this, message, userId);
284
343
  },
285
344
  setAdminMode: async () => {
286
- this.notImplemented("setAdminMode");
345
+ this.notImplemented('setAdminMode');
287
346
  },
288
347
  setDisplayTimeout: async enabled => {
289
348
  this.appCall(94, {
@@ -308,10 +367,10 @@ export class AppWrapper {
308
367
  }, callback));
309
368
  },
310
369
  setHeight: async () => {
311
- this.notImplemented("setOverlay");
370
+ this.notImplemented('setOverlay');
312
371
  },
313
372
  setOverlay: async () => {
314
- this.notImplemented("setOverlay");
373
+ this.notImplemented('setOverlay');
315
374
  },
316
375
  setRefreshScrollEnabled: async isEnabled => {
317
376
  this.appCall(0, {
@@ -327,7 +386,7 @@ export class AppWrapper {
327
386
  return await this.appCall(34, value);
328
387
  },
329
388
  setTempDesignSettings: async () => {
330
- this.notImplemented("setTempDesignSettings");
389
+ this.notImplemented('setTempDesignSettings');
331
390
  },
332
391
  setWaitCursor: async value => {
333
392
  void this.appCall(1, {
@@ -370,12 +429,44 @@ export class AppWrapper {
370
429
  void this.appCall(19, value, {
371
430
  awaitResult: false
372
431
  });
432
+ },
433
+ openDialog: async function () {
434
+ return _this.openDialog(...arguments);
435
+ },
436
+ createDialog: config => {
437
+ return {
438
+ close: async value => {
439
+ this.dialogs.find(x => x.dialogId === dialogId).eventTarget.dispatchEvent(new CustomEvent('close', {
440
+ detail: data
441
+ }));
442
+ },
443
+ open: async () => {
444
+ return await this.openDialog(config);
445
+ }
446
+ };
447
+ },
448
+ closeDialog: (dialogId, data) => {
449
+ try {
450
+ this.dialogs.find(x => x.dialogId === dialogId).eventTarget.dispatchEvent(new CustomEvent('requestClose', {
451
+ detail: data
452
+ }));
453
+ } catch (e) {
454
+ console.error(e);
455
+ }
373
456
  }
374
457
  });
458
+ _defineProperty(this, "dialogs", []);
459
+ _defineProperty(this, "dialogEventTarget", new EventTarget());
375
460
  }
376
461
  notImplemented(call) {
377
462
  console.warn(`call ${call} not implement in app`);
378
463
  }
464
+ dispatchDialogChange(detail) {
465
+ this.dialogs = detail;
466
+ this.dialogEventTarget.dispatchEvent(new CustomEvent('change', {
467
+ detail
468
+ }));
469
+ }
379
470
  appCall(action) {
380
471
  let value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
381
472
  let {
@@ -401,13 +492,30 @@ export class AppWrapper {
401
492
  }
402
493
  resolve((_v$retVal2 = v === null || v === void 0 ? void 0 : v.retVal) !== null && _v$retVal2 !== void 0 ? _v$retVal2 : v);
403
494
  };
404
- value.callback = "window." + callbackName;
495
+ value.callback = 'window.' + callbackName;
405
496
  invokeAppCall({
406
497
  action,
407
498
  value
408
499
  });
409
500
  });
410
501
  }
502
+ async openDialog(config) {
503
+ const currentDialogId = appWrapperDialogId;
504
+ const res = await new Promise(resolve => {
505
+ const eventTarget = new EventTarget();
506
+ this.dispatchDialogChange([...(this.dialogs || []), {
507
+ config,
508
+ resolve,
509
+ dialogId: appWrapperDialogId++,
510
+ eventTarget
511
+ }]);
512
+ });
513
+ this.dispatchDialogChange(this.dialogs.filter(x => x.dialogId !== currentDialogId));
514
+ return res;
515
+ }
516
+ getDialogEventTarget() {
517
+ return this.dialogEventTarget;
518
+ }
411
519
  async init() {
412
520
  this.values = this.mapOldApiToNew(await this.appCall(18));
413
521
  return undefined;
@@ -425,4 +533,13 @@ export class AppWrapper {
425
533
  getInitialData() {
426
534
  return this.values;
427
535
  }
536
+ createDialog(config) {
537
+ return {
538
+ close: () => {},
539
+ open: async () => {
540
+ const dialog = await functions.openDialog(config);
541
+ return dialog;
542
+ }
543
+ };
544
+ }
428
545
  }