chayns-api 1.0.0 → 1.0.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 (205) hide show
  1. package/dist/cjs/bootstrap.js +11 -0
  2. package/dist/cjs/calls/abstractApiListener.js +40 -0
  3. package/dist/cjs/calls/apiEventListener.js +40 -0
  4. package/dist/cjs/calls/dialogs/alert.js +2 -0
  5. package/dist/cjs/calls/dialogs/chaynsDialog.js +8 -2
  6. package/dist/cjs/calls/dialogs/close.js +2 -0
  7. package/dist/cjs/calls/dialogs/communication.js +16 -1
  8. package/dist/cjs/calls/dialogs/confirm.js +4 -0
  9. package/dist/cjs/calls/dialogs/date.js +53 -36
  10. package/dist/cjs/calls/dialogs/dropUpAlert.js +3 -0
  11. package/dist/cjs/calls/dialogs/fileSelect.js +10 -0
  12. package/dist/cjs/calls/dialogs/iFrame.js +8 -0
  13. package/dist/cjs/calls/dialogs/index.js +27 -0
  14. package/dist/cjs/calls/dialogs/input.js +6 -0
  15. package/dist/cjs/calls/dialogs/mediaSelect.js +7 -0
  16. package/dist/cjs/calls/dialogs/open.js +2 -0
  17. package/dist/cjs/calls/dialogs/select.js +9 -0
  18. package/dist/cjs/calls/dialogs/signature.js +5 -0
  19. package/dist/cjs/calls/dialogs/toast.js +3 -0
  20. package/dist/cjs/calls/dialogs/utils/callback.js +2 -0
  21. package/dist/cjs/calls/dialogs/utils/is.js +4 -0
  22. package/dist/cjs/calls/getUserInfo.js +11 -0
  23. package/dist/cjs/calls/index.js +155 -3
  24. package/dist/cjs/calls/sendMessage.js +26 -0
  25. package/dist/cjs/calls/setVisibilityChangeListener.js +1 -0
  26. package/dist/cjs/calls/visibilityChangeListener.js +12 -1
  27. package/dist/cjs/calls/windowMetricsListener.js +18 -0
  28. package/dist/cjs/components/App.js +32 -0
  29. package/dist/cjs/components/App.spec.js +16 -0
  30. package/dist/cjs/components/Button.js +32 -0
  31. package/dist/cjs/components/ChaynsContext.js +4 -2
  32. package/dist/cjs/components/ChaynsProvider.js +28 -6
  33. package/dist/cjs/components/ChaynsProviderExposed.js +16 -0
  34. package/dist/cjs/components/TestProvider.js +236 -0
  35. package/dist/cjs/components/Title.js +162 -0
  36. package/dist/cjs/components/WaitUntil.js +5 -0
  37. package/dist/cjs/components/withCompatMode.js +16 -1
  38. package/dist/cjs/functions/addApiListener.js +37 -0
  39. package/dist/cjs/functions/addGeoLocationListener.js +26 -0
  40. package/dist/cjs/functions/addScrollListener.js +26 -0
  41. package/dist/cjs/functions/addWindowMetricsListener.js +37 -0
  42. package/dist/cjs/helper/apiListenerHelper.js +9 -0
  43. package/dist/cjs/helper/cssLoader.js +28 -0
  44. package/dist/cjs/hooks/addGeoLocationListener.js +26 -0
  45. package/dist/cjs/hooks/addScrollListener.js +26 -0
  46. package/dist/cjs/hooks/addWindowMetricsListener.js +37 -0
  47. package/dist/cjs/hooks/geoLocation.js +48 -0
  48. package/dist/cjs/hooks/geoLocationListener.js +11 -2
  49. package/dist/cjs/hooks/index.js +16 -0
  50. package/dist/cjs/hooks/scrollListener.js +23 -4
  51. package/dist/cjs/hooks/useAccessToken.js +5 -0
  52. package/dist/cjs/hooks/useAddGeoLocationListener.js +26 -0
  53. package/dist/cjs/hooks/useAddScrollListener.js +48 -0
  54. package/dist/cjs/hooks/useAddWindowMetricsListener.js +45 -0
  55. package/dist/cjs/hooks/useAdddScrollListener.js +26 -0
  56. package/dist/cjs/hooks/useCurrentPage.js +4 -0
  57. package/dist/cjs/hooks/useCustomData.js +4 -0
  58. package/dist/cjs/hooks/useDevice.js +4 -0
  59. package/dist/cjs/hooks/useEnvironment.js +4 -0
  60. package/dist/cjs/hooks/useFunctions.js +4 -0
  61. package/dist/cjs/hooks/useIsAdminMode.js +5 -0
  62. package/dist/cjs/hooks/useLanguage.js +4 -0
  63. package/dist/cjs/hooks/usePages.js +12 -0
  64. package/dist/cjs/hooks/useParameters.js +4 -0
  65. package/dist/cjs/hooks/useSite.js +4 -0
  66. package/dist/cjs/hooks/useUser.js +4 -0
  67. package/dist/cjs/hooks/useValues.js +4 -0
  68. package/dist/cjs/hooks/windowMetrics.js +45 -0
  69. package/dist/cjs/hooks/windowMetricsListener.js +12 -2
  70. package/dist/cjs/host/ChaynsHost.js +12 -0
  71. package/dist/cjs/host/{module/PagemakerFrame.js → HostIframe.js} +75 -23
  72. package/dist/cjs/host/ModuleHost.js +11 -0
  73. package/dist/cjs/host/iframe/HostIframe.js +30 -23
  74. package/dist/cjs/host/iframe/utils/useUpdateData.js +3 -0
  75. package/dist/cjs/host/module/ModuleHost.js +13 -3
  76. package/dist/cjs/host/module/utils/loadComponent.js +18 -1
  77. package/dist/cjs/host/module/utils/useDynamicScript.js +18 -0
  78. package/dist/cjs/host/module/utils.js +25 -0
  79. package/dist/cjs/index.example.js +7 -0
  80. package/dist/cjs/index.js +19 -0
  81. package/dist/cjs/index2.js +64 -0
  82. package/dist/cjs/types/DynamicImport.d.js +5 -0
  83. package/dist/cjs/types/IChaynsReact.js +47 -0
  84. package/dist/cjs/types/chayns-components.d.js +1 -0
  85. package/dist/cjs/types/chayns-logger.d.js +1 -0
  86. package/dist/cjs/types/chayns.d.js +1 -0
  87. package/dist/cjs/types/tobit-websocket-service-client.d.js +1 -0
  88. package/dist/cjs/types/toolkit-types.d.js +1 -0
  89. package/dist/cjs/util/appCall.js +4 -1
  90. package/dist/cjs/util/deviceHelper.js +17 -2
  91. package/dist/cjs/util/heightHelper.js +9 -0
  92. package/dist/cjs/util/postIframeForm.js +5 -0
  93. package/dist/cjs/util/useFunctionsContext.js +16 -0
  94. package/dist/cjs/util/useIsAdminMode.js +18 -0
  95. package/dist/cjs/util/useUser.js +16 -0
  96. package/dist/cjs/wrapper/AppWrapper.js +144 -119
  97. package/dist/cjs/wrapper/FrameWrapper.js +248 -215
  98. package/dist/cjs/wrapper/ModuleFederationWrapper.js +27 -2
  99. package/dist/cjs/wrapper/SsrWrapper.js +8 -0
  100. package/dist/esm/bootstrap.js +4 -0
  101. package/dist/esm/calls/dialogs/alert.js +4 -4
  102. package/dist/esm/calls/dialogs/chaynsDialog.js +11 -7
  103. package/dist/esm/calls/dialogs/communication.js +26 -15
  104. package/dist/esm/calls/dialogs/confirm.js +8 -5
  105. package/dist/esm/calls/dialogs/date.js +94 -85
  106. package/dist/esm/calls/dialogs/dropUpAlert.js +1 -1
  107. package/dist/esm/calls/dialogs/fileSelect.js +62 -23
  108. package/dist/esm/calls/dialogs/iFrame.js +10 -7
  109. package/dist/esm/calls/dialogs/input.js +5 -2
  110. package/dist/esm/calls/dialogs/mediaSelect.js +55 -18
  111. package/dist/esm/calls/dialogs/open.js +2 -2
  112. package/dist/esm/calls/dialogs/select.js +9 -5
  113. package/dist/esm/calls/dialogs/signature.js +2 -0
  114. package/dist/esm/calls/dialogs/toast.js +11 -6
  115. package/dist/esm/calls/dialogs/utils/callback.js +5 -3
  116. package/dist/esm/calls/dialogs/utils/is.js +3 -1
  117. package/dist/esm/calls/getUserInfo.js +92 -32
  118. package/dist/esm/calls/index.js +276 -124
  119. package/dist/esm/calls/sendMessage.js +221 -91
  120. package/dist/esm/calls/visibilityChangeListener.js +15 -10
  121. package/dist/esm/components/App.js +35 -0
  122. package/dist/esm/components/App.spec.js +9 -0
  123. package/dist/esm/components/Button.js +34 -0
  124. package/dist/esm/components/ChaynsContext.js +3 -3
  125. package/dist/esm/components/ChaynsProvider.js +86 -45
  126. package/dist/esm/components/ChaynsProviderExposed.js +3 -0
  127. package/dist/esm/components/TestProvider.js +308 -0
  128. package/dist/esm/components/Title.js +210 -0
  129. package/dist/esm/components/WaitUntil.js +86 -21
  130. package/dist/esm/components/withCompatMode.js +77 -35
  131. package/dist/esm/helper/apiListenerHelper.js +15 -10
  132. package/dist/esm/helper/cssLoader.js +21 -0
  133. package/dist/esm/hooks/geoLocationListener.js +46 -20
  134. package/dist/esm/hooks/scrollListener.js +86 -50
  135. package/dist/esm/hooks/useAccessToken.js +28 -6
  136. package/dist/esm/hooks/useAddGeoLocationListener.js +18 -0
  137. package/dist/esm/hooks/useAddScrollListener.js +18 -0
  138. package/dist/esm/hooks/useAddWindowMetricsListener.js +18 -0
  139. package/dist/esm/hooks/useCurrentPage.js +6 -2
  140. package/dist/esm/hooks/useCustomData.js +6 -2
  141. package/dist/esm/hooks/useDevice.js +6 -1
  142. package/dist/esm/hooks/useEnvironment.js +6 -1
  143. package/dist/esm/hooks/useFunctions.js +5 -2
  144. package/dist/esm/hooks/useIsAdminMode.js +6 -2
  145. package/dist/esm/hooks/useLanguage.js +6 -1
  146. package/dist/esm/hooks/usePages.js +27 -14
  147. package/dist/esm/hooks/useParameters.js +6 -1
  148. package/dist/esm/hooks/useSite.js +6 -1
  149. package/dist/esm/hooks/useUser.js +6 -1
  150. package/dist/esm/hooks/useValues.js +5 -2
  151. package/dist/esm/hooks/windowMetricsListener.js +44 -18
  152. package/dist/esm/host/ChaynsHost.js +30 -21
  153. package/dist/esm/host/HostIframe.js +153 -0
  154. package/dist/esm/host/iframe/HostIframe.js +142 -86
  155. package/dist/esm/host/iframe/utils/useUpdateData.js +6 -4
  156. package/dist/esm/host/module/ModuleHost.js +49 -42
  157. package/dist/esm/host/module/utils/loadComponent.js +85 -47
  158. package/dist/esm/host/module/utils/useDynamicScript.js +74 -27
  159. package/dist/esm/index.example.js +1 -0
  160. package/dist/esm/index2.js +5 -0
  161. package/dist/esm/types/DynamicImport.d.js +1 -0
  162. package/dist/esm/types/IChaynsReact.js +61 -14
  163. package/dist/esm/types/chayns-components.d.js +0 -0
  164. package/dist/esm/types/chayns-logger.d.js +0 -0
  165. package/dist/esm/types/chayns.d.js +0 -0
  166. package/dist/esm/types/tobit-websocket-service-client.d.js +0 -0
  167. package/dist/esm/types/toolkit-types.d.js +0 -0
  168. package/dist/esm/util/appCall.js +4 -2
  169. package/dist/esm/util/deviceHelper.js +33 -11
  170. package/dist/esm/util/heightHelper.js +13 -10
  171. package/dist/esm/util/postIframeForm.js +57 -25
  172. package/dist/esm/util/useIsAdminMode.js +9 -0
  173. package/dist/esm/util/useUser.js +7 -0
  174. package/dist/esm/wrapper/AppWrapper.js +762 -179
  175. package/dist/esm/wrapper/FrameWrapper.js +1509 -258
  176. package/dist/esm/wrapper/ModuleFederationWrapper.js +284 -47
  177. package/dist/esm/wrapper/SsrWrapper.js +65 -19
  178. package/dist/types/bootstrap.d.ts +1 -0
  179. package/dist/types/calls/dialogs/confirm.d.ts +1 -1
  180. package/dist/types/calls/dialogs/date.d.ts +4 -4
  181. package/dist/types/calls/dialogs/dropUpAlert.d.ts +1 -1
  182. package/dist/types/calls/dialogs/fileSelect.d.ts +1 -1
  183. package/dist/types/calls/dialogs/iFrame.d.ts +1 -1
  184. package/dist/types/calls/dialogs/input.d.ts +1 -1
  185. package/dist/types/calls/dialogs/mediaSelect.d.ts +1 -1
  186. package/dist/types/calls/dialogs/signature.d.ts +1 -1
  187. package/dist/types/components/App.d.ts +5 -0
  188. package/dist/types/components/Button.d.ts +8 -0
  189. package/dist/types/components/ChaynsProvider.d.ts +1 -1
  190. package/dist/types/components/ChaynsProviderExposed.d.ts +13 -0
  191. package/dist/types/components/Title.d.ts +3 -0
  192. package/dist/types/components/WaitUntil.d.ts +1 -1
  193. package/dist/types/components/withCompatMode.d.ts +1 -1
  194. package/dist/types/hooks/useAccessToken.d.ts +1 -1
  195. package/dist/types/host/ChaynsHost.d.ts +2 -1
  196. package/dist/types/host/{module/PagemakerFrame.d.ts → HostIframe.d.ts} +5 -7
  197. package/dist/types/host/iframe/HostIframe.d.ts +1 -1
  198. package/dist/types/host/module/ModuleHost.d.ts +2 -2
  199. package/dist/types/index.example.d.ts +0 -0
  200. package/dist/types/types/IChaynsReact.d.ts +14 -14
  201. package/package.json +1 -1
  202. package/dist/cjs/calls/dialogs/utils/environment.js +0 -10
  203. package/dist/esm/calls/dialogs/utils/environment.js +0 -3
  204. package/dist/esm/host/module/PagemakerFrame.js +0 -97
  205. package/dist/types/calls/dialogs/utils/environment.d.ts +0 -3
@@ -3,7 +3,11 @@ import { ChaynsContext } from '../components/ChaynsContext';
3
3
  /**
4
4
  * @category Hooks
5
5
  */
6
- export const useIsAdminMode = () => {
6
+
7
+ export var useIsAdminMode = function useIsAdminMode() {
7
8
  var _useContextSelector;
8
- return (_useContextSelector = useContextSelector(ChaynsContext, v => v === null || v === void 0 ? void 0 : v.isAdminModeActive)) !== null && _useContextSelector !== void 0 ? _useContextSelector : false;
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;
9
13
  };
@@ -1,6 +1,11 @@
1
1
  import { useContextSelector } from 'use-context-selector';
2
2
  import { ChaynsContext } from '../components/ChaynsContext';
3
+
3
4
  /**
4
5
  * @category Hooks
5
6
  */
6
- export const useLanguage = () => useContextSelector(ChaynsContext, v => v === null || v === void 0 ? void 0 : v.language);
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
+ };
@@ -1,32 +1,45 @@
1
1
  import { useContextSelector } from 'use-context-selector';
2
2
  import { ChaynsContext } from '../components/ChaynsContext';
3
+
3
4
  /**
4
5
  * @category Hooks
5
6
  */
6
- export const usePages = function () {
7
- let {
8
- siteId
9
- } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
7
+ export var usePages = function usePages() {
8
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
10
9
  siteId: undefined
11
- };
12
- const pages = useContextSelector(ChaynsContext, v => v.pages);
10
+ },
11
+ siteId = _ref.siteId;
12
+
13
+ var pages = useContextSelector(ChaynsContext, function (v) {
14
+ return v.pages;
15
+ });
16
+
13
17
  if (siteId) {
14
- pages.filter(tapp => tapp.siteId === siteId);
18
+ pages.filter(function (tapp) {
19
+ return tapp.siteId === siteId;
20
+ });
15
21
  }
22
+
16
23
  return pages;
17
24
  };
18
25
  /**
19
26
  * @category Hooks
20
27
  */
21
- export const usePage = _ref => {
22
- let {
23
- id,
24
- siteId
25
- } = _ref;
26
- const pages = useContextSelector(ChaynsContext, v => v.pages);
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
+
27
36
  if (id) {
28
37
  var _pages$find;
29
- return (_pages$find = pages.find(x => x.id === id && (!siteId || x.siteId === siteId))) !== null && _pages$find !== void 0 ? _pages$find : null;
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
42
  }
43
+
31
44
  return null;
32
45
  };
@@ -1,6 +1,11 @@
1
1
  import { useContextSelector } from 'use-context-selector';
2
2
  import { ChaynsContext } from '../components/ChaynsContext';
3
+
3
4
  /**
4
5
  * @category Hooks
5
6
  */
6
- export const useParameters = () => useContextSelector(ChaynsContext, v => (v === null || v === void 0 ? void 0 : v.parameters) || []);
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
+ };
@@ -1,6 +1,11 @@
1
1
  import { useContextSelector } from 'use-context-selector';
2
2
  import { ChaynsContext } from '../components/ChaynsContext';
3
+
3
4
  /**
4
5
  * @category Hooks
5
6
  */
6
- export const useSite = () => useContextSelector(ChaynsContext, v => v === null || v === void 0 ? void 0 : v.site);
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
+ };
@@ -1,7 +1,12 @@
1
1
  import { useContextSelector } from 'use-context-selector';
2
2
  import { ChaynsContext } from '../components/ChaynsContext';
3
+
3
4
  /**
4
5
  * @category Hooks
5
6
  */
6
7
  // @ts-ignore
7
- export const useUser = () => useContextSelector(ChaynsContext, v => (v === null || v === void 0 ? void 0 : v.user) || {});
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
+ };
@@ -1,9 +1,12 @@
1
1
  import { useContextSelector } from 'use-context-selector';
2
2
  import { ChaynsContext } from '../components/ChaynsContext';
3
+
3
4
  /**
4
5
  * @category Hooks
5
6
  */
6
- export const useValues = () => {
7
- const t = useContextSelector(ChaynsContext, v => v || {});
7
+ export var useValues = function useValues() {
8
+ var t = useContextSelector(ChaynsContext, function (v) {
9
+ return v || {};
10
+ });
8
11
  return t;
9
12
  };
@@ -1,3 +1,15 @@
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
+
1
13
  import { useContextSelector } from 'use-context-selector';
2
14
  import { useCallback, useEffect, useRef, useState } from 'react';
3
15
  import { ChaynsFunctionsContext } from '../components/ChaynsContext';
@@ -5,27 +17,34 @@ import { ScreenSize } from '../types/IChaynsReact';
5
17
  /**
6
18
  * @category Hooks
7
19
  */
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 => {
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) {
13
30
  promiseRef.current = addListener(callback);
14
- return () => {
31
+ return function () {
15
32
  var _promiseRef$current;
33
+
16
34
  void ((_promiseRef$current = promiseRef.current) === null || _promiseRef$current === void 0 ? void 0 : _promiseRef$current.then(removeListener));
17
- };
18
- // eslint-disable-next-line react-hooks/exhaustive-deps
35
+ }; // eslint-disable-next-line react-hooks/exhaustive-deps
19
36
  }, []);
20
37
  };
21
38
  /**
22
39
  * @category Hooks
23
40
  */
24
- export const useWindowMetrics = function () {
25
- let {
26
- enabled = true
27
- } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
28
- const [value, setValue] = useState({
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({
29
48
  bottomBarHeight: 0,
30
49
  offsetTop: 0,
31
50
  pageHeight: 0,
@@ -33,18 +52,25 @@ export const useWindowMetrics = function () {
33
52
  topBarHeight: 0,
34
53
  windowHeight: 0,
35
54
  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;
36
63
  });
37
- const addListener = useWindowMetricsListener();
38
- const getWindowMetrics = useContextSelector(ChaynsFunctionsContext, v => v.getWindowMetrics);
39
- useEffect(() => {
64
+ useEffect(function () {
40
65
  if (enabled) {
41
- return addListener(v => {
66
+ return addListener(function (v) {
42
67
  setValue(v);
43
68
  });
44
69
  }
70
+
45
71
  return undefined;
46
72
  }, [enabled, addListener]);
47
- useEffect(() => {
73
+ useEffect(function () {
48
74
  void getWindowMetrics().then(setValue);
49
75
  }, [getWindowMetrics]);
50
76
  return value;
@@ -1,27 +1,30 @@
1
1
  import React from 'react';
2
2
  import HostIframe from './iframe/HostIframe';
3
3
  import ModuleHost from './module/ModuleHost';
4
- const ChaynsHost = _ref => {
5
- let {
6
- type,
7
- iFrameProps,
8
- functions,
9
- src,
10
- iFrameRef = undefined,
11
- children = undefined,
12
- system,
13
- // shallow data
14
- pages,
15
- language,
16
- isAdminModeActive,
17
- site,
18
- user,
19
- currentPage,
20
- device,
21
- parameters,
22
- customData,
23
- environment
24
- } = _ref;
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
+
25
28
  switch (type) {
26
29
  case 'client-iframe':
27
30
  return /*#__PURE__*/React.createElement(HostIframe, {
@@ -40,6 +43,7 @@ const ChaynsHost = _ref => {
40
43
  environment: environment,
41
44
  customData: customData
42
45
  });
46
+
43
47
  case 'client-module':
44
48
  return /*#__PURE__*/React.createElement(ModuleHost, {
45
49
  system: system,
@@ -49,12 +53,14 @@ const ChaynsHost = _ref => {
49
53
  user: user,
50
54
  device: device,
51
55
  currentPage: currentPage,
56
+ children: loadingComponent,
52
57
  functions: functions,
53
58
  language: language,
54
59
  parameters: parameters,
55
60
  customData: customData,
56
61
  environment: environment
57
62
  });
63
+
58
64
  case 'server-iframe':
59
65
  return /*#__PURE__*/React.createElement(HostIframe, {
60
66
  iFrameRef: iFrameRef,
@@ -73,6 +79,7 @@ const ChaynsHost = _ref => {
73
79
  environment: environment,
74
80
  customData: customData
75
81
  });
82
+
76
83
  case 'server-module':
77
84
  return /*#__PURE__*/React.createElement(ModuleHost, {
78
85
  system: system,
@@ -88,8 +95,10 @@ const ChaynsHost = _ref => {
88
95
  customData: customData,
89
96
  environment: environment
90
97
  }, children);
98
+
91
99
  default:
92
100
  return null;
93
101
  }
94
102
  };
103
+
95
104
  export default ChaynsHost;
@@ -0,0 +1,153 @@
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
+ import React, { useEffect, useRef } from 'react';
10
+ import * as comlink from 'comlink';
11
+ import postIframeForm from '../util/postIframeForm';
12
+
13
+ var HostIframe = function HostIframe(_ref) {
14
+ var iFrameProps = _ref.iFrameProps,
15
+ src = _ref.src,
16
+ _ref$postForm = _ref.postForm,
17
+ postForm = _ref$postForm === void 0 ? false : _ref$postForm,
18
+ iFrameRef = _ref.iFrameRef,
19
+ pages = _ref.pages,
20
+ isAdminModeActive = _ref.isAdminModeActive,
21
+ site = _ref.site,
22
+ user = _ref.user,
23
+ currentPage = _ref.currentPage,
24
+ functions = _ref.functions,
25
+ device = _ref.device;
26
+ var eventTarget = useRef();
27
+
28
+ var _ref2 = useRef();
29
+
30
+ var currentDataRef = useRef();
31
+
32
+ if (!eventTarget.current) {
33
+ eventTarget.current = global.EventTarget ? new EventTarget() : undefined;
34
+ }
35
+
36
+ var setHeight = function setHeight(value) {
37
+ if (_ref2.current) {
38
+ _ref2.current.height = "".concat(value, "px");
39
+ }
40
+ }; // region initialData
41
+
42
+
43
+ var initialData = {
44
+ site: site,
45
+ isAdminModeActive: isAdminModeActive,
46
+ pages: pages,
47
+ currentPage: currentPage,
48
+ device: device,
49
+ user: user
50
+ }; // endregion
51
+
52
+ currentDataRef.current = initialData; // region postIframeForm
53
+
54
+ useEffect(function () {
55
+ if (postForm) {
56
+ void postIframeForm(src, JSON.stringify(_objectSpread(_objectSpread({}, initialData), {}, {
57
+ pages: undefined
58
+ })), 'chayns', iFrameProps.name);
59
+ } // eslint-disable-next-line react-hooks/exhaustive-deps
60
+
61
+ }, []); // endregion
62
+
63
+ console.debug('functions', functions); // region expose data and functions to iframe
64
+
65
+ useEffect(function () {
66
+ var _ref$current;
67
+
68
+ if ((_ref$current = _ref2.current) !== null && _ref$current !== void 0 && _ref$current.contentWindow) {
69
+ var obj = _defineProperty({}, iFrameProps.name, {
70
+ functions: _objectSpread(_objectSpread({}, functions), {}, {
71
+ setHeight: setHeight
72
+ }),
73
+ addDataListener: function addDataListener(cb) {
74
+ if (eventTarget.current) eventTarget.current.addEventListener('data_update', function (e) {
75
+ return e.detail && cb(e.detail);
76
+ });
77
+ },
78
+ getInitialData: function getInitialData() {
79
+ return currentDataRef.current;
80
+ }
81
+ });
82
+
83
+ comlink.expose(obj, comlink.windowEndpoint(_ref2.current.contentWindow));
84
+
85
+ _ref2.current.contentWindow.postMessage('chayns-api-host-ready', '*'); // https://github.com/GoogleChromeLabs/comlink/pull/469 might be better approach once released
86
+
87
+
88
+ return function () {
89
+ delete obj[iFrameProps.name];
90
+ };
91
+ }
92
+
93
+ return undefined; // eslint-disable-next-line react-hooks/exhaustive-deps
94
+ }, []); // endregion
95
+ // region dispatch data update
96
+
97
+ useEffect(function () {
98
+ if (eventTarget.current) {
99
+ eventTarget.current.dispatchEvent(new CustomEvent('data_update', {
100
+ detail: {
101
+ type: 'isAdminModeActive',
102
+ value: isAdminModeActive
103
+ }
104
+ }));
105
+ }
106
+ }, [isAdminModeActive]);
107
+ useEffect(function () {
108
+ if (eventTarget.current) {
109
+ eventTarget.current.dispatchEvent(new CustomEvent('data_update', {
110
+ detail: {
111
+ type: 'user',
112
+ value: user
113
+ }
114
+ }));
115
+ }
116
+ }, [user]);
117
+ useEffect(function () {
118
+ if (eventTarget.current) {
119
+ eventTarget.current.dispatchEvent(new CustomEvent('data_update', {
120
+ detail: {
121
+ type: 'site',
122
+ value: site
123
+ }
124
+ }));
125
+ }
126
+ }, [site]);
127
+ useEffect(function () {
128
+ if (eventTarget.current) {
129
+ eventTarget.current.dispatchEvent(new CustomEvent('data_update', {
130
+ detail: {
131
+ type: 'pages',
132
+ value: pages
133
+ }
134
+ }));
135
+ }
136
+ }, [pages]); // endregion
137
+
138
+ return /*#__PURE__*/React.createElement("iframe", _extends({
139
+ ref: function ref(r) {
140
+ _ref2.current = r;
141
+
142
+ if (iFrameRef) {
143
+ // eslint-disable-next-line no-param-reassign
144
+ iFrameRef.current = r;
145
+ }
146
+ },
147
+ title: " "
148
+ }, iFrameProps, {
149
+ src: postForm ? undefined : src
150
+ }));
151
+ };
152
+
153
+ export default HostIframe;