chayns-api 1.0.1 → 1.0.2

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 (211) hide show
  1. package/dist/cjs/calls/dialogs/alert.js +0 -2
  2. package/dist/cjs/calls/dialogs/chaynsDialog.js +2 -8
  3. package/dist/cjs/calls/dialogs/close.js +0 -2
  4. package/dist/cjs/calls/dialogs/communication.js +1 -16
  5. package/dist/cjs/calls/dialogs/confirm.js +0 -4
  6. package/dist/cjs/calls/dialogs/date.js +36 -53
  7. package/dist/cjs/calls/dialogs/dropUpAlert.js +0 -3
  8. package/dist/cjs/calls/dialogs/fileSelect.js +0 -10
  9. package/dist/cjs/calls/dialogs/iFrame.js +0 -8
  10. package/dist/cjs/calls/dialogs/index.js +0 -27
  11. package/dist/cjs/calls/dialogs/input.js +0 -6
  12. package/dist/cjs/calls/dialogs/mediaSelect.js +0 -7
  13. package/dist/cjs/calls/dialogs/open.js +0 -2
  14. package/dist/cjs/calls/dialogs/select.js +0 -9
  15. package/dist/cjs/calls/dialogs/signature.js +0 -5
  16. package/dist/cjs/calls/dialogs/toast.js +0 -3
  17. package/dist/cjs/calls/dialogs/utils/callback.js +0 -2
  18. package/dist/cjs/calls/dialogs/utils/environment.js +10 -0
  19. package/dist/cjs/calls/dialogs/utils/is.js +0 -4
  20. package/dist/cjs/calls/getUserInfo.js +0 -11
  21. package/dist/cjs/calls/index.js +3 -155
  22. package/dist/cjs/calls/sendMessage.js +0 -26
  23. package/dist/cjs/calls/visibilityChangeListener.js +1 -12
  24. package/dist/cjs/components/ChaynsContext.js +2 -4
  25. package/dist/cjs/components/ChaynsProvider.js +6 -28
  26. package/dist/cjs/components/WaitUntil.js +0 -5
  27. package/dist/cjs/components/withCompatMode.js +1 -16
  28. package/dist/cjs/helper/apiListenerHelper.js +0 -9
  29. package/dist/cjs/hooks/geoLocationListener.js +2 -11
  30. package/dist/cjs/hooks/index.js +6 -16
  31. package/dist/cjs/hooks/scrollListener.js +4 -23
  32. package/dist/cjs/hooks/useAccessToken.js +0 -5
  33. package/dist/cjs/hooks/useCurrentPage.js +0 -4
  34. package/dist/cjs/hooks/useCustomData.js +0 -4
  35. package/dist/cjs/hooks/useDevice.js +0 -4
  36. package/dist/cjs/hooks/useEnvironment.js +0 -4
  37. package/dist/cjs/hooks/useFunctions.js +0 -4
  38. package/dist/cjs/hooks/useIsAdminMode.js +0 -5
  39. package/dist/cjs/hooks/useLanguage.js +0 -4
  40. package/dist/cjs/hooks/usePages.js +22 -14
  41. package/dist/cjs/hooks/useParameters.js +0 -4
  42. package/dist/cjs/hooks/useSite.js +0 -4
  43. package/dist/cjs/hooks/useUser.js +0 -5
  44. package/dist/cjs/hooks/useValues.js +0 -4
  45. package/dist/cjs/hooks/windowMetricsListener.js +2 -12
  46. package/dist/cjs/host/ChaynsHost.js +0 -10
  47. package/dist/cjs/host/iframe/HostIframe.js +23 -30
  48. package/dist/cjs/host/iframe/utils/useUpdateData.js +0 -3
  49. package/dist/cjs/host/module/ModuleHost.js +3 -13
  50. package/dist/cjs/host/{HostIframe.js → module/PagemakerFrame.js} +23 -75
  51. package/dist/cjs/host/module/utils/loadComponent.js +1 -18
  52. package/dist/cjs/host/module/utils/useDynamicScript.js +0 -18
  53. package/dist/cjs/index.js +0 -19
  54. package/dist/cjs/types/IChaynsReact.js +27 -48
  55. package/dist/cjs/util/appCall.js +1 -4
  56. package/dist/cjs/util/deviceHelper.js +4 -21
  57. package/dist/cjs/util/heightHelper.js +0 -9
  58. package/dist/cjs/util/postIframeForm.js +0 -5
  59. package/dist/cjs/wrapper/AppWrapper.js +318 -159
  60. package/dist/cjs/wrapper/FrameWrapper.js +215 -248
  61. package/dist/cjs/wrapper/ModuleFederationWrapper.js +2 -27
  62. package/dist/cjs/wrapper/SsrWrapper.js +0 -8
  63. package/dist/esm/calls/dialogs/alert.js +4 -4
  64. package/dist/esm/calls/dialogs/chaynsDialog.js +7 -11
  65. package/dist/esm/calls/dialogs/communication.js +15 -26
  66. package/dist/esm/calls/dialogs/confirm.js +5 -8
  67. package/dist/esm/calls/dialogs/date.js +85 -94
  68. package/dist/esm/calls/dialogs/dropUpAlert.js +1 -1
  69. package/dist/esm/calls/dialogs/fileSelect.js +23 -62
  70. package/dist/esm/calls/dialogs/iFrame.js +7 -10
  71. package/dist/esm/calls/dialogs/input.js +2 -5
  72. package/dist/esm/calls/dialogs/mediaSelect.js +18 -55
  73. package/dist/esm/calls/dialogs/open.js +2 -2
  74. package/dist/esm/calls/dialogs/select.js +5 -9
  75. package/dist/esm/calls/dialogs/signature.js +0 -2
  76. package/dist/esm/calls/dialogs/toast.js +6 -11
  77. package/dist/esm/calls/dialogs/utils/callback.js +3 -5
  78. package/dist/esm/calls/dialogs/utils/environment.js +3 -0
  79. package/dist/esm/calls/dialogs/utils/is.js +1 -3
  80. package/dist/esm/calls/getUserInfo.js +32 -92
  81. package/dist/esm/calls/index.js +124 -276
  82. package/dist/esm/calls/sendMessage.js +91 -221
  83. package/dist/esm/calls/visibilityChangeListener.js +10 -15
  84. package/dist/esm/components/ChaynsContext.js +3 -3
  85. package/dist/esm/components/ChaynsProvider.js +45 -86
  86. package/dist/esm/components/WaitUntil.js +21 -86
  87. package/dist/esm/components/withCompatMode.js +35 -77
  88. package/dist/esm/helper/apiListenerHelper.js +10 -15
  89. package/dist/esm/hooks/geoLocationListener.js +20 -46
  90. package/dist/esm/hooks/index.js +1 -1
  91. package/dist/esm/hooks/scrollListener.js +50 -86
  92. package/dist/esm/hooks/useAccessToken.js +6 -28
  93. package/dist/esm/hooks/useCurrentPage.js +2 -6
  94. package/dist/esm/hooks/useCustomData.js +2 -6
  95. package/dist/esm/hooks/useDevice.js +1 -6
  96. package/dist/esm/hooks/useEnvironment.js +1 -6
  97. package/dist/esm/hooks/useFunctions.js +2 -5
  98. package/dist/esm/hooks/useIsAdminMode.js +2 -6
  99. package/dist/esm/hooks/useLanguage.js +1 -6
  100. package/dist/esm/hooks/usePages.js +34 -27
  101. package/dist/esm/hooks/useParameters.js +1 -6
  102. package/dist/esm/hooks/useSite.js +1 -6
  103. package/dist/esm/hooks/useUser.js +1 -7
  104. package/dist/esm/hooks/useValues.js +2 -5
  105. package/dist/esm/hooks/windowMetricsListener.js +18 -44
  106. package/dist/esm/host/ChaynsHost.js +22 -29
  107. package/dist/esm/host/iframe/HostIframe.js +86 -142
  108. package/dist/esm/host/iframe/utils/useUpdateData.js +4 -6
  109. package/dist/esm/host/module/ModuleHost.js +42 -49
  110. package/dist/esm/host/module/PagemakerFrame.js +97 -0
  111. package/dist/esm/host/module/utils/loadComponent.js +47 -85
  112. package/dist/esm/host/module/utils/useDynamicScript.js +27 -74
  113. package/dist/esm/types/IChaynsReact.js +37 -61
  114. package/dist/esm/util/appCall.js +2 -4
  115. package/dist/esm/util/deviceHelper.js +12 -36
  116. package/dist/esm/util/heightHelper.js +10 -13
  117. package/dist/esm/util/postIframeForm.js +25 -57
  118. package/dist/esm/wrapper/AppWrapper.js +380 -781
  119. package/dist/esm/wrapper/FrameWrapper.js +258 -1509
  120. package/dist/esm/wrapper/ModuleFederationWrapper.js +47 -284
  121. package/dist/esm/wrapper/SsrWrapper.js +19 -65
  122. package/dist/types/calls/dialogs/confirm.d.ts +1 -1
  123. package/dist/types/calls/dialogs/date.d.ts +4 -4
  124. package/dist/types/calls/dialogs/dropUpAlert.d.ts +1 -1
  125. package/dist/types/calls/dialogs/fileSelect.d.ts +1 -1
  126. package/dist/types/calls/dialogs/iFrame.d.ts +1 -1
  127. package/dist/types/calls/dialogs/input.d.ts +1 -1
  128. package/dist/types/calls/dialogs/mediaSelect.d.ts +1 -1
  129. package/dist/types/calls/dialogs/signature.d.ts +1 -1
  130. package/dist/types/calls/dialogs/utils/environment.d.ts +3 -0
  131. package/dist/types/calls/index.d.ts +0 -6
  132. package/dist/types/components/ChaynsProvider.d.ts +1 -1
  133. package/dist/types/components/WaitUntil.d.ts +1 -1
  134. package/dist/types/components/withCompatMode.d.ts +1 -1
  135. package/dist/types/hooks/index.d.ts +1 -1
  136. package/dist/types/hooks/useAccessToken.d.ts +1 -1
  137. package/dist/types/hooks/usePages.d.ts +4 -0
  138. package/dist/types/host/ChaynsHost.d.ts +1 -1
  139. package/dist/types/host/iframe/HostIframe.d.ts +1 -1
  140. package/dist/types/host/module/ModuleHost.d.ts +2 -2
  141. package/dist/types/host/{HostIframe.d.ts → module/PagemakerFrame.d.ts} +7 -5
  142. package/dist/types/types/IChaynsReact.d.ts +55 -24
  143. package/dist/types/util/deviceHelper.d.ts +2 -2
  144. package/dist/types/wrapper/AppWrapper.d.ts +6 -4
  145. package/package.json +1 -1
  146. package/dist/cjs/bootstrap.js +0 -11
  147. package/dist/cjs/calls/abstractApiListener.js +0 -40
  148. package/dist/cjs/calls/apiEventListener.js +0 -40
  149. package/dist/cjs/calls/setVisibilityChangeListener.js +0 -1
  150. package/dist/cjs/calls/windowMetricsListener.js +0 -18
  151. package/dist/cjs/components/App.js +0 -32
  152. package/dist/cjs/components/App.spec.js +0 -16
  153. package/dist/cjs/components/Button.js +0 -32
  154. package/dist/cjs/components/ChaynsProviderExposed.js +0 -16
  155. package/dist/cjs/components/TestProvider.js +0 -236
  156. package/dist/cjs/components/Title.js +0 -162
  157. package/dist/cjs/functions/addApiListener.js +0 -37
  158. package/dist/cjs/functions/addGeoLocationListener.js +0 -26
  159. package/dist/cjs/functions/addScrollListener.js +0 -26
  160. package/dist/cjs/functions/addWindowMetricsListener.js +0 -37
  161. package/dist/cjs/helper/cssLoader.js +0 -28
  162. package/dist/cjs/hooks/addGeoLocationListener.js +0 -26
  163. package/dist/cjs/hooks/addScrollListener.js +0 -26
  164. package/dist/cjs/hooks/addWindowMetricsListener.js +0 -37
  165. package/dist/cjs/hooks/geoLocation.js +0 -48
  166. package/dist/cjs/hooks/useAddGeoLocationListener.js +0 -26
  167. package/dist/cjs/hooks/useAddScrollListener.js +0 -48
  168. package/dist/cjs/hooks/useAddWindowMetricsListener.js +0 -45
  169. package/dist/cjs/hooks/useAdddScrollListener.js +0 -26
  170. package/dist/cjs/hooks/windowMetrics.js +0 -45
  171. package/dist/cjs/host/ModuleHost.js +0 -11
  172. package/dist/cjs/host/module/utils.js +0 -25
  173. package/dist/cjs/index.example.js +0 -7
  174. package/dist/cjs/index2.js +0 -64
  175. package/dist/cjs/types/DynamicImport.d.js +0 -5
  176. package/dist/cjs/types/chayns-components.d.js +0 -1
  177. package/dist/cjs/types/chayns-logger.d.js +0 -1
  178. package/dist/cjs/types/chayns.d.js +0 -1
  179. package/dist/cjs/types/tobit-websocket-service-client.d.js +0 -1
  180. package/dist/cjs/types/toolkit-types.d.js +0 -1
  181. package/dist/cjs/util/useFunctionsContext.js +0 -16
  182. package/dist/cjs/util/useIsAdminMode.js +0 -18
  183. package/dist/cjs/util/useUser.js +0 -16
  184. package/dist/esm/bootstrap.js +0 -4
  185. package/dist/esm/components/App.js +0 -35
  186. package/dist/esm/components/App.spec.js +0 -9
  187. package/dist/esm/components/Button.js +0 -34
  188. package/dist/esm/components/ChaynsProviderExposed.js +0 -3
  189. package/dist/esm/components/TestProvider.js +0 -308
  190. package/dist/esm/components/Title.js +0 -210
  191. package/dist/esm/helper/cssLoader.js +0 -21
  192. package/dist/esm/hooks/useAddGeoLocationListener.js +0 -18
  193. package/dist/esm/hooks/useAddScrollListener.js +0 -18
  194. package/dist/esm/hooks/useAddWindowMetricsListener.js +0 -18
  195. package/dist/esm/host/HostIframe.js +0 -153
  196. package/dist/esm/index.example.js +0 -1
  197. package/dist/esm/index2.js +0 -5
  198. package/dist/esm/types/DynamicImport.d.js +0 -1
  199. package/dist/esm/types/chayns-components.d.js +0 -0
  200. package/dist/esm/types/chayns-logger.d.js +0 -0
  201. package/dist/esm/types/chayns.d.js +0 -0
  202. package/dist/esm/types/tobit-websocket-service-client.d.js +0 -0
  203. package/dist/esm/types/toolkit-types.d.js +0 -0
  204. package/dist/esm/util/useIsAdminMode.js +0 -9
  205. package/dist/esm/util/useUser.js +0 -7
  206. package/dist/types/bootstrap.d.ts +0 -1
  207. package/dist/types/components/App.d.ts +0 -5
  208. package/dist/types/components/Button.d.ts +0 -8
  209. package/dist/types/components/ChaynsProviderExposed.d.ts +0 -13
  210. package/dist/types/components/Title.d.ts +0 -3
  211. package/dist/types/index.example.d.ts +0 -0
@@ -1,11 +1,6 @@
1
1
  import { useContextSelector } from 'use-context-selector';
2
2
  import { ChaynsContext } from '../components/ChaynsContext';
3
-
4
3
  /**
5
4
  * @category Hooks
6
5
  */
7
- export var useEnvironment = function useEnvironment() {
8
- return useContextSelector(ChaynsContext, function (v) {
9
- return v === null || v === void 0 ? void 0 : v.environment;
10
- });
11
- };
6
+ export const useEnvironment = () => useContextSelector(ChaynsContext, v => v === null || v === void 0 ? void 0 : v.environment);
@@ -1,12 +1,9 @@
1
1
  import { useContextSelector } from "use-context-selector";
2
2
  import { ChaynsFunctionsContext } from "../components/ChaynsContext";
3
-
4
3
  /**
5
4
  * @category Hooks
6
5
  */
7
- export var useFunctions = function useFunctions() {
8
- var t = useContextSelector(ChaynsFunctionsContext, function (f) {
9
- return f || {};
10
- });
6
+ export const useFunctions = () => {
7
+ const t = useContextSelector(ChaynsFunctionsContext, f => f || {});
11
8
  return t;
12
9
  };
@@ -3,11 +3,7 @@ import { ChaynsContext } from '../components/ChaynsContext';
3
3
  /**
4
4
  * @category Hooks
5
5
  */
6
-
7
- export var useIsAdminMode = function useIsAdminMode() {
6
+ export const useIsAdminMode = () => {
8
7
  var _useContextSelector;
9
-
10
- return (_useContextSelector = useContextSelector(ChaynsContext, function (v) {
11
- return v === null || v === void 0 ? void 0 : v.isAdminModeActive;
12
- })) !== null && _useContextSelector !== void 0 ? _useContextSelector : false;
8
+ return (_useContextSelector = useContextSelector(ChaynsContext, v => v === null || v === void 0 ? void 0 : v.isAdminModeActive)) !== null && _useContextSelector !== void 0 ? _useContextSelector : false;
13
9
  };
@@ -1,11 +1,6 @@
1
1
  import { useContextSelector } from 'use-context-selector';
2
2
  import { ChaynsContext } from '../components/ChaynsContext';
3
-
4
3
  /**
5
4
  * @category Hooks
6
5
  */
7
- export var useLanguage = function useLanguage() {
8
- return useContextSelector(ChaynsContext, function (v) {
9
- return v === null || v === void 0 ? void 0 : v.language;
10
- });
11
- };
6
+ export const useLanguage = () => useContextSelector(ChaynsContext, v => v === null || v === void 0 ? void 0 : v.language);
@@ -1,45 +1,52 @@
1
1
  import { useContextSelector } from 'use-context-selector';
2
2
  import { ChaynsContext } from '../components/ChaynsContext';
3
-
3
+ import { moduleWrapper } from "../components/ChaynsProvider";
4
4
  /**
5
5
  * @category Hooks
6
6
  */
7
- export var usePages = function usePages() {
8
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
7
+ export const usePages = function () {
8
+ let {
9
+ siteId
10
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
9
11
  siteId: undefined
10
- },
11
- siteId = _ref.siteId;
12
-
13
- var pages = useContextSelector(ChaynsContext, function (v) {
14
- return v.pages;
15
- });
16
-
12
+ };
13
+ const pages = useContextSelector(ChaynsContext, v => v.pages);
17
14
  if (siteId) {
18
- pages.filter(function (tapp) {
19
- return tapp.siteId === siteId;
20
- });
15
+ pages.filter(tapp => tapp.siteId === siteId);
21
16
  }
22
-
23
17
  return pages;
24
18
  };
25
19
  /**
26
20
  * @category Hooks
27
21
  */
28
-
29
- export var usePage = function usePage(_ref2) {
30
- var id = _ref2.id,
31
- siteId = _ref2.siteId;
32
- var pages = useContextSelector(ChaynsContext, function (v) {
33
- return v.pages;
34
- });
35
-
22
+ export const usePage = _ref => {
23
+ let {
24
+ id,
25
+ siteId
26
+ } = _ref;
27
+ const pages = useContextSelector(ChaynsContext, v => v.pages);
36
28
  if (id) {
37
29
  var _pages$find;
38
-
39
- return (_pages$find = pages.find(function (x) {
40
- return x.id === id && (!siteId || x.siteId === siteId);
41
- })) !== null && _pages$find !== void 0 ? _pages$find : null;
30
+ return (_pages$find = pages.find(x => x.id === id && (!siteId || x.siteId === siteId))) !== null && _pages$find !== void 0 ? _pages$find : null;
42
31
  }
43
-
44
32
  return null;
33
+ };
34
+ export const getPage = function () {
35
+ var _pages$find3;
36
+ let {
37
+ id,
38
+ siteId
39
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
40
+ id: null,
41
+ siteId: null
42
+ };
43
+ const {
44
+ pages,
45
+ currentPage
46
+ } = moduleWrapper.current.values;
47
+ if (id) {
48
+ var _pages$find2;
49
+ return (_pages$find2 = pages.find(x => x.id === id && (!siteId || x.siteId === siteId))) !== null && _pages$find2 !== void 0 ? _pages$find2 : null;
50
+ }
51
+ return (_pages$find3 = pages.find(x => x.id === currentPage.id && x.siteId === currentPage.siteId || !x.siteId)) !== null && _pages$find3 !== void 0 ? _pages$find3 : null;
45
52
  };
@@ -1,11 +1,6 @@
1
1
  import { useContextSelector } from 'use-context-selector';
2
2
  import { ChaynsContext } from '../components/ChaynsContext';
3
-
4
3
  /**
5
4
  * @category Hooks
6
5
  */
7
- export var useParameters = function useParameters() {
8
- return useContextSelector(ChaynsContext, function (v) {
9
- return (v === null || v === void 0 ? void 0 : v.parameters) || [];
10
- });
11
- };
6
+ export const useParameters = () => useContextSelector(ChaynsContext, v => (v === null || v === void 0 ? void 0 : v.parameters) || []);
@@ -1,11 +1,6 @@
1
1
  import { useContextSelector } from 'use-context-selector';
2
2
  import { ChaynsContext } from '../components/ChaynsContext';
3
-
4
3
  /**
5
4
  * @category Hooks
6
5
  */
7
- export var useSite = function useSite() {
8
- return useContextSelector(ChaynsContext, function (v) {
9
- return v === null || v === void 0 ? void 0 : v.site;
10
- });
11
- };
6
+ export const useSite = () => useContextSelector(ChaynsContext, v => v === null || v === void 0 ? void 0 : v.site);
@@ -1,12 +1,6 @@
1
1
  import { useContextSelector } from 'use-context-selector';
2
2
  import { ChaynsContext } from '../components/ChaynsContext';
3
-
4
3
  /**
5
4
  * @category Hooks
6
5
  */
7
- // @ts-ignore
8
- export var useUser = function useUser() {
9
- return useContextSelector(ChaynsContext, function (v) {
10
- return (v === null || v === void 0 ? void 0 : v.user) || {};
11
- });
12
- };
6
+ export const useUser = () => useContextSelector(ChaynsContext, v => (v === null || v === void 0 ? void 0 : v.user) || {});
@@ -1,12 +1,9 @@
1
1
  import { useContextSelector } from 'use-context-selector';
2
2
  import { ChaynsContext } from '../components/ChaynsContext';
3
-
4
3
  /**
5
4
  * @category Hooks
6
5
  */
7
- export var useValues = function useValues() {
8
- var t = useContextSelector(ChaynsContext, function (v) {
9
- return v || {};
10
- });
6
+ export const useValues = () => {
7
+ const t = useContextSelector(ChaynsContext, v => v || {});
11
8
  return t;
12
9
  };
@@ -1,15 +1,3 @@
1
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
-
3
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
-
5
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
6
-
7
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
8
-
9
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
10
-
11
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
-
13
1
  import { useContextSelector } from 'use-context-selector';
14
2
  import { useCallback, useEffect, useRef, useState } from 'react';
15
3
  import { ChaynsFunctionsContext } from '../components/ChaynsContext';
@@ -17,34 +5,27 @@ import { ScreenSize } from '../types/IChaynsReact';
17
5
  /**
18
6
  * @category Hooks
19
7
  */
20
-
21
- export var useWindowMetricsListener = function useWindowMetricsListener() {
22
- var addListener = useContextSelector(ChaynsFunctionsContext, function (v) {
23
- return v.addWindowMetricsListener;
24
- });
25
- var removeListener = useContextSelector(ChaynsFunctionsContext, function (v) {
26
- return v.removeWindowMetricsListener;
27
- });
28
- var promiseRef = useRef();
29
- return useCallback(function (callback) {
8
+ export const useWindowMetricsListener = () => {
9
+ const addListener = useContextSelector(ChaynsFunctionsContext, v => v.addWindowMetricsListener);
10
+ const removeListener = useContextSelector(ChaynsFunctionsContext, v => v.removeWindowMetricsListener);
11
+ const promiseRef = useRef();
12
+ return useCallback(callback => {
30
13
  promiseRef.current = addListener(callback);
31
- return function () {
14
+ return () => {
32
15
  var _promiseRef$current;
33
-
34
16
  void ((_promiseRef$current = promiseRef.current) === null || _promiseRef$current === void 0 ? void 0 : _promiseRef$current.then(removeListener));
35
- }; // eslint-disable-next-line react-hooks/exhaustive-deps
17
+ };
18
+ // eslint-disable-next-line react-hooks/exhaustive-deps
36
19
  }, []);
37
20
  };
38
21
  /**
39
22
  * @category Hooks
40
23
  */
41
-
42
- export var useWindowMetrics = function useWindowMetrics() {
43
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
44
- _ref$enabled = _ref.enabled,
45
- enabled = _ref$enabled === void 0 ? true : _ref$enabled;
46
-
47
- var _useState = useState({
24
+ export const useWindowMetrics = function () {
25
+ let {
26
+ enabled = true
27
+ } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
28
+ const [value, setValue] = useState({
48
29
  bottomBarHeight: 0,
49
30
  offsetTop: 0,
50
31
  pageHeight: 0,
@@ -52,25 +33,18 @@ export var useWindowMetrics = function useWindowMetrics() {
52
33
  topBarHeight: 0,
53
34
  windowHeight: 0,
54
35
  pageSize: ScreenSize.XS
55
- }),
56
- _useState2 = _slicedToArray(_useState, 2),
57
- value = _useState2[0],
58
- setValue = _useState2[1];
59
-
60
- var addListener = useWindowMetricsListener();
61
- var getWindowMetrics = useContextSelector(ChaynsFunctionsContext, function (v) {
62
- return v.getWindowMetrics;
63
36
  });
64
- useEffect(function () {
37
+ const addListener = useWindowMetricsListener();
38
+ const getWindowMetrics = useContextSelector(ChaynsFunctionsContext, v => v.getWindowMetrics);
39
+ useEffect(() => {
65
40
  if (enabled) {
66
- return addListener(function (v) {
41
+ return addListener(v => {
67
42
  setValue(v);
68
43
  });
69
44
  }
70
-
71
45
  return undefined;
72
46
  }, [enabled, addListener]);
73
- useEffect(function () {
47
+ useEffect(() => {
74
48
  void getWindowMetrics().then(setValue);
75
49
  }, [getWindowMetrics]);
76
50
  return value;
@@ -1,30 +1,28 @@
1
1
  import React from 'react';
2
2
  import HostIframe from './iframe/HostIframe';
3
3
  import ModuleHost from './module/ModuleHost';
4
-
5
- var ChaynsHost = function ChaynsHost(_ref) {
6
- var type = _ref.type,
7
- iFrameProps = _ref.iFrameProps,
8
- functions = _ref.functions,
9
- src = _ref.src,
10
- _ref$iFrameRef = _ref.iFrameRef,
11
- iFrameRef = _ref$iFrameRef === void 0 ? undefined : _ref$iFrameRef,
12
- _ref$loadingComponent = _ref.loadingComponent,
13
- loadingComponent = _ref$loadingComponent === void 0 ? undefined : _ref$loadingComponent,
14
- _ref$children = _ref.children,
15
- children = _ref$children === void 0 ? undefined : _ref$children,
16
- system = _ref.system,
17
- pages = _ref.pages,
18
- language = _ref.language,
19
- isAdminModeActive = _ref.isAdminModeActive,
20
- site = _ref.site,
21
- user = _ref.user,
22
- currentPage = _ref.currentPage,
23
- device = _ref.device,
24
- parameters = _ref.parameters,
25
- customData = _ref.customData,
26
- environment = _ref.environment;
27
-
4
+ const ChaynsHost = _ref => {
5
+ let {
6
+ type,
7
+ iFrameProps,
8
+ functions,
9
+ src,
10
+ iFrameRef = undefined,
11
+ loadingComponent = undefined,
12
+ children = undefined,
13
+ system,
14
+ // shallow data
15
+ pages,
16
+ language,
17
+ isAdminModeActive,
18
+ site,
19
+ user,
20
+ currentPage,
21
+ device,
22
+ parameters,
23
+ customData,
24
+ environment
25
+ } = _ref;
28
26
  switch (type) {
29
27
  case 'client-iframe':
30
28
  return /*#__PURE__*/React.createElement(HostIframe, {
@@ -43,7 +41,6 @@ var ChaynsHost = function ChaynsHost(_ref) {
43
41
  environment: environment,
44
42
  customData: customData
45
43
  });
46
-
47
44
  case 'client-module':
48
45
  return /*#__PURE__*/React.createElement(ModuleHost, {
49
46
  system: system,
@@ -60,7 +57,6 @@ var ChaynsHost = function ChaynsHost(_ref) {
60
57
  customData: customData,
61
58
  environment: environment
62
59
  });
63
-
64
60
  case 'server-iframe':
65
61
  return /*#__PURE__*/React.createElement(HostIframe, {
66
62
  iFrameRef: iFrameRef,
@@ -79,7 +75,6 @@ var ChaynsHost = function ChaynsHost(_ref) {
79
75
  environment: environment,
80
76
  customData: customData
81
77
  });
82
-
83
78
  case 'server-module':
84
79
  return /*#__PURE__*/React.createElement(ModuleHost, {
85
80
  system: system,
@@ -95,10 +90,8 @@ var ChaynsHost = function ChaynsHost(_ref) {
95
90
  customData: customData,
96
91
  environment: environment
97
92
  }, children);
98
-
99
93
  default:
100
94
  return null;
101
95
  }
102
96
  };
103
-
104
97
  export default ChaynsHost;
@@ -1,158 +1,103 @@
1
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
-
3
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
4
-
5
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
6
-
7
- 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; }
8
-
9
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
10
-
11
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
12
-
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
13
2
  import React, { useEffect, useRef } from 'react';
14
3
  import * as comlink from 'comlink';
15
4
  import postIframeForm from '../../util/postIframeForm';
16
5
  import useUpdateData from './utils/useUpdateData';
17
-
18
- var HostIframe = function HostIframe(_ref) {
19
- var iFrameProps = _ref.iFrameProps,
20
- src = _ref.src,
21
- _ref$postForm = _ref.postForm,
22
- postForm = _ref$postForm === void 0 ? false : _ref$postForm,
23
- iFrameRef = _ref.iFrameRef,
24
- pages = _ref.pages,
25
- isAdminModeActive = _ref.isAdminModeActive,
26
- site = _ref.site,
27
- user = _ref.user,
28
- currentPage = _ref.currentPage,
29
- functions = _ref.functions,
30
- device = _ref.device,
31
- language = _ref.language,
32
- parameters = _ref.parameters,
33
- environment = _ref.environment,
34
- customData = _ref.customData;
35
- var eventTarget = useRef();
36
-
37
- var _ref3 = useRef();
38
-
39
- var currentDataRef = useRef();
40
-
6
+ const HostIframe = _ref => {
7
+ let {
8
+ iFrameProps,
9
+ src,
10
+ postForm = false,
11
+ iFrameRef,
12
+ // shallow data
13
+ pages,
14
+ isAdminModeActive,
15
+ site,
16
+ user,
17
+ currentPage,
18
+ functions,
19
+ device,
20
+ language,
21
+ parameters,
22
+ environment,
23
+ customData
24
+ } = _ref;
25
+ const eventTarget = useRef();
26
+ const ref = useRef();
27
+ const currentDataRef = useRef();
41
28
  if (!eventTarget.current) {
42
29
  eventTarget.current = global.document ? document.createElement('div') : undefined; // global.EventTarget ? new EventTarget() : undefined
43
30
  }
44
31
 
45
- var setHeight = function setHeight(value) {
46
- if (_ref3.current) {
47
- _ref3.current.height = "".concat(value, "px");
32
+ const setHeight = value => {
33
+ if (ref.current) {
34
+ ref.current.height = `${value}px`;
48
35
  }
49
- }; // region initialData
50
-
51
-
52
- var initialData = {
53
- site: site,
54
- isAdminModeActive: isAdminModeActive,
55
- pages: pages,
56
- currentPage: currentPage,
57
- device: device,
58
- user: user,
59
- language: language,
60
- parameters: parameters,
61
- environment: environment,
62
- customData: customData
63
- }; // endregion
64
-
65
- currentDataRef.current = initialData; // region postIframeForm
66
-
67
- useEffect(function () {
68
- _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
69
- var _yield$functions$getA, accessToken;
70
-
71
- return regeneratorRuntime.wrap(function _callee$(_context) {
72
- while (1) {
73
- switch (_context.prev = _context.next) {
74
- case 0:
75
- if (!postForm) {
76
- _context.next = 14;
77
- break;
78
- }
79
-
80
- _context.next = 3;
81
- return functions.getAccessToken();
82
-
83
- case 3:
84
- _context.t1 = _yield$functions$getA = _context.sent;
85
- _context.t0 = _context.t1 !== null;
86
-
87
- if (!_context.t0) {
88
- _context.next = 7;
89
- break;
90
- }
91
-
92
- _context.t0 = _yield$functions$getA !== void 0;
93
-
94
- case 7:
95
- if (!_context.t0) {
96
- _context.next = 11;
97
- break;
98
- }
99
-
100
- _context.t2 = _yield$functions$getA;
101
- _context.next = 12;
102
- break;
103
-
104
- case 11:
105
- _context.t2 = {};
106
-
107
- case 12:
108
- accessToken = _context.t2;
109
- void postIframeForm(src, JSON.stringify(_objectSpread(_objectSpread({}, initialData), {}, {
110
- pages: undefined
111
- }, accessToken)), 'chayns', iFrameProps.name);
112
-
113
- case 14:
114
- case "end":
115
- return _context.stop();
116
- }
117
- }
118
- }, _callee);
119
- }))(); // eslint-disable-next-line react-hooks/exhaustive-deps
36
+ };
37
+
38
+ // region initialData
39
+ const initialData = {
40
+ site,
41
+ isAdminModeActive,
42
+ pages,
43
+ currentPage,
44
+ device,
45
+ user,
46
+ language,
47
+ parameters,
48
+ environment,
49
+ customData
50
+ };
51
+ // endregion
52
+
53
+ currentDataRef.current = initialData;
54
+
55
+ // region postIframeForm
56
+ useEffect(() => {
57
+ (async () => {
58
+ if (postForm) {
59
+ var _await$functions$getA;
60
+ const accessToken = (_await$functions$getA = await functions.getAccessToken()) !== null && _await$functions$getA !== void 0 ? _await$functions$getA : {};
61
+ void postIframeForm(src, JSON.stringify({
62
+ ...initialData,
63
+ pages: undefined,
64
+ ...accessToken
65
+ }), 'chayns', iFrameProps.name);
66
+ }
67
+ })();
68
+ // eslint-disable-next-line react-hooks/exhaustive-deps
69
+ }, []);
70
+ // endregion
120
71
 
121
- }, []); // endregion
122
72
  // region expose data and functions to iframe
123
-
124
- useEffect(function () {
73
+ useEffect(() => {
125
74
  var _ref$current;
126
-
127
- if ((_ref$current = _ref3.current) !== null && _ref$current !== void 0 && _ref$current.contentWindow) {
128
- var obj = _defineProperty({}, iFrameProps.name, {
129
- functions: _objectSpread(_objectSpread({}, functions), {}, {
130
- setHeight: setHeight
131
- }),
132
- addDataListener: function addDataListener(cb) {
133
- if (eventTarget.current) eventTarget.current.addEventListener('data_update', function (e) {
134
- return e.detail && cb(e.detail);
135
- });
136
- },
137
- getInitialData: function getInitialData() {
138
- return currentDataRef.current;
75
+ if ((_ref$current = ref.current) !== null && _ref$current !== void 0 && _ref$current.contentWindow) {
76
+ const obj = {
77
+ [iFrameProps.name]: {
78
+ functions: {
79
+ ...functions,
80
+ setHeight
81
+ },
82
+ addDataListener: cb => {
83
+ if (eventTarget.current) eventTarget.current.addEventListener('data_update', e => e.detail && cb(e.detail));
84
+ },
85
+ getInitialData: () => currentDataRef.current
139
86
  }
140
- });
141
-
142
- comlink.expose(obj, comlink.windowEndpoint(_ref3.current.contentWindow));
143
-
144
- _ref3.current.contentWindow.postMessage('chayns-api-host-ready', '*'); // https://github.com/GoogleChromeLabs/comlink/pull/469 might be better approach once released
145
-
146
-
147
- return function () {
87
+ };
88
+ comlink.expose(obj, comlink.windowEndpoint(ref.current.contentWindow));
89
+ ref.current.contentWindow.postMessage('chayns-api-host-ready', '*');
90
+ // https://github.com/GoogleChromeLabs/comlink/pull/469 might be better approach once released
91
+ return () => {
148
92
  delete obj[iFrameProps.name];
149
93
  };
150
94
  }
95
+ return undefined;
96
+ // eslint-disable-next-line react-hooks/exhaustive-deps
97
+ }, []);
98
+ // endregion
151
99
 
152
- return undefined; // eslint-disable-next-line react-hooks/exhaustive-deps
153
- }, []); // endregion
154
100
  // region dispatch data update
155
-
156
101
  useUpdateData(eventTarget.current, 'isAdminModeActive', isAdminModeActive);
157
102
  useUpdateData(eventTarget.current, 'user', user);
158
103
  useUpdateData(eventTarget.current, 'site', site);
@@ -160,12 +105,12 @@ var HostIframe = function HostIframe(_ref) {
160
105
  useUpdateData(eventTarget.current, 'language', language);
161
106
  useUpdateData(eventTarget.current, 'parameters', parameters);
162
107
  useUpdateData(eventTarget.current, 'environment', environment);
163
- useUpdateData(eventTarget.current, 'customData', customData); // endregion
108
+ useUpdateData(eventTarget.current, 'customData', customData);
109
+ // endregion
164
110
 
165
111
  return /*#__PURE__*/React.createElement("iframe", _extends({
166
- ref: function ref(r) {
167
- _ref3.current = r;
168
-
112
+ ref: r => {
113
+ ref.current = r;
169
114
  if (iFrameRef) {
170
115
  // eslint-disable-next-line no-param-reassign
171
116
  iFrameRef.current = r;
@@ -176,5 +121,4 @@ var HostIframe = function HostIframe(_ref) {
176
121
  src: postForm ? undefined : src
177
122
  }));
178
123
  };
179
-
180
124
  export default HostIframe;