chayns-api 1.0.12 → 1.1.0-0

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 (227) 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 +54 -54
  7. package/dist/cjs/bootstrap.js +11 -0
  8. package/dist/cjs/calls/abstractApiListener.js +40 -0
  9. package/dist/cjs/calls/apiEventListener.js +40 -0
  10. package/dist/cjs/calls/dialogs/date.js +10 -10
  11. package/dist/cjs/calls/index.js +102 -97
  12. package/dist/cjs/calls/sendMessage.js +8 -8
  13. package/dist/cjs/calls/setVisibilityChangeListener.js +1 -0
  14. package/dist/cjs/calls/visibilityChangeListener.js +4 -4
  15. package/dist/cjs/calls/windowMetricsListener.js +18 -0
  16. package/dist/cjs/client.js +93 -0
  17. package/dist/cjs/components/App.js +32 -0
  18. package/dist/cjs/components/App.spec.js +16 -0
  19. package/dist/cjs/components/AppDialogWrapper.js +42 -0
  20. package/dist/cjs/components/Button.js +32 -0
  21. package/dist/cjs/components/ChaynsModuleProvider.js +457 -0
  22. package/dist/cjs/components/ChaynsProvider.js +5 -2
  23. package/dist/cjs/components/ChaynsProviderExposed.js +16 -0
  24. package/dist/cjs/components/Dialog.js +1 -0
  25. package/dist/cjs/components/TestProvider.js +236 -0
  26. package/dist/cjs/components/Title.js +162 -0
  27. package/dist/cjs/functions/addApiListener.js +37 -0
  28. package/dist/cjs/functions/addGeoLocationListener.js +26 -0
  29. package/dist/cjs/functions/addScrollListener.js +26 -0
  30. package/dist/cjs/functions/addWindowMetricsListener.js +37 -0
  31. package/dist/cjs/handler/DialogHandler.js +40 -0
  32. package/dist/cjs/helper/cssLoader.js +28 -0
  33. package/dist/cjs/hooks/addGeoLocationListener.js +26 -0
  34. package/dist/cjs/hooks/addScrollListener.js +26 -0
  35. package/dist/cjs/hooks/addWindowMetricsListener.js +37 -0
  36. package/dist/cjs/hooks/geoLocation.js +48 -0
  37. package/dist/cjs/hooks/geoLocationListener.js +4 -4
  38. package/dist/cjs/hooks/index.js +14 -1
  39. package/dist/cjs/hooks/scrollListener.js +8 -8
  40. package/dist/cjs/hooks/useAccessToken.js +2 -2
  41. package/dist/cjs/hooks/useAddGeoLocationListener.js +26 -0
  42. package/dist/cjs/hooks/useAddScrollListener.js +48 -0
  43. package/dist/cjs/hooks/useAddWindowMetricsListener.js +45 -0
  44. package/dist/cjs/hooks/useAdddScrollListener.js +26 -0
  45. package/dist/cjs/hooks/useCurrentPage.js +2 -2
  46. package/dist/cjs/hooks/useCustomData.js +2 -2
  47. package/dist/cjs/hooks/useDevice.js +2 -2
  48. package/dist/cjs/hooks/useDialogState.js +35 -0
  49. package/dist/cjs/hooks/useEnvironment.js +2 -2
  50. package/dist/cjs/hooks/useFunction.js +13 -0
  51. package/dist/cjs/hooks/useFunctions.js +2 -2
  52. package/dist/cjs/hooks/useIsAdminMode.js +2 -2
  53. package/dist/cjs/hooks/useLanguage.js +2 -2
  54. package/dist/cjs/hooks/usePages.js +4 -4
  55. package/dist/cjs/hooks/useParameters.js +2 -2
  56. package/dist/cjs/hooks/useSite.js +2 -2
  57. package/dist/cjs/hooks/useUser.js +2 -2
  58. package/dist/cjs/hooks/useValues.js +2 -2
  59. package/dist/cjs/hooks/windowMetrics.js +45 -0
  60. package/dist/cjs/hooks/windowMetricsListener.js +4 -4
  61. package/dist/cjs/host/ChaynsHost.js +10 -5
  62. package/dist/cjs/host/HostIframe.js +157 -0
  63. package/dist/cjs/host/ModuleHost.js +11 -0
  64. package/dist/cjs/host/iframe/HostIframe.js +5 -2
  65. package/dist/cjs/host/module/ModuleHost.js +4 -0
  66. package/dist/cjs/host/module/utils.js +25 -0
  67. package/dist/cjs/index.example.js +7 -0
  68. package/dist/cjs/index2.js +64 -0
  69. package/dist/cjs/types/DynamicApiImport.d.js +5 -0
  70. package/dist/cjs/types/DynamicImport.d.js +5 -0
  71. package/dist/cjs/types/IChaynsReact.js +22 -2
  72. package/dist/cjs/types/chayns-components.d.js +1 -0
  73. package/dist/cjs/types/chayns-logger.d.js +1 -0
  74. package/dist/cjs/types/chayns.d.js +1 -0
  75. package/dist/cjs/types/tobit-websocket-service-client.d.js +1 -0
  76. package/dist/cjs/types/toolkit-types.d.js +1 -0
  77. package/dist/cjs/util/deviceHelper.js +7 -6
  78. package/dist/cjs/util/useFunctionsContext.js +16 -0
  79. package/dist/cjs/util/useIsAdminMode.js +18 -0
  80. package/dist/cjs/util/useUser.js +16 -0
  81. package/dist/cjs/wrapper/AppWrapper.js +39 -0
  82. package/dist/cjs/wrapper/Dialog.js +35 -0
  83. package/dist/cjs/wrapper/DialogHandler.js +35 -0
  84. package/dist/cjs/wrapper/FrameWrapper.js +17 -0
  85. package/dist/cjs/wrapper/ModuleFederationWrapper.js +4 -0
  86. package/dist/esm/bootstrap.js +4 -0
  87. package/dist/esm/calls/dialogs/date.js +34 -34
  88. package/dist/esm/calls/index.js +102 -96
  89. package/dist/esm/calls/sendMessage.js +8 -8
  90. package/dist/esm/calls/visibilityChangeListener.js +4 -4
  91. package/dist/esm/client.js +8 -0
  92. package/dist/esm/components/App.js +35 -0
  93. package/dist/esm/components/App.spec.js +9 -0
  94. package/dist/esm/components/AppDialogWrapper.js +33 -0
  95. package/dist/esm/components/Button.js +34 -0
  96. package/dist/esm/components/ChaynsModuleProvider.js +517 -0
  97. package/dist/esm/components/ChaynsProvider.js +5 -2
  98. package/dist/esm/components/ChaynsProviderExposed.js +3 -0
  99. package/dist/esm/components/Dialog.js +0 -0
  100. package/dist/esm/components/TestProvider.js +308 -0
  101. package/dist/esm/components/Title.js +210 -0
  102. package/dist/esm/handler/DialogHandler.js +36 -0
  103. package/dist/esm/helper/cssLoader.js +21 -0
  104. package/dist/esm/hooks/geoLocationListener.js +4 -4
  105. package/dist/esm/hooks/index.js +2 -1
  106. package/dist/esm/hooks/scrollListener.js +8 -8
  107. package/dist/esm/hooks/useAccessToken.js +2 -2
  108. package/dist/esm/hooks/useAddGeoLocationListener.js +18 -0
  109. package/dist/esm/hooks/useAddScrollListener.js +18 -0
  110. package/dist/esm/hooks/useAddWindowMetricsListener.js +18 -0
  111. package/dist/esm/hooks/useCurrentPage.js +2 -2
  112. package/dist/esm/hooks/useCustomData.js +2 -2
  113. package/dist/esm/hooks/useDevice.js +2 -2
  114. package/dist/esm/hooks/useDialogState.js +28 -0
  115. package/dist/esm/hooks/useEnvironment.js +2 -2
  116. package/dist/esm/hooks/useFunction.js +6 -0
  117. package/dist/esm/hooks/useFunctions.js +2 -2
  118. package/dist/esm/hooks/useIsAdminMode.js +2 -2
  119. package/dist/esm/hooks/useLanguage.js +2 -2
  120. package/dist/esm/hooks/usePages.js +4 -4
  121. package/dist/esm/hooks/useParameters.js +2 -2
  122. package/dist/esm/hooks/useSite.js +2 -2
  123. package/dist/esm/hooks/useUser.js +2 -2
  124. package/dist/esm/hooks/useValues.js +2 -2
  125. package/dist/esm/hooks/windowMetricsListener.js +4 -4
  126. package/dist/esm/host/ChaynsHost.js +10 -5
  127. package/dist/esm/host/HostIframe.js +153 -0
  128. package/dist/esm/host/iframe/HostIframe.js +5 -2
  129. package/dist/esm/host/module/ModuleHost.js +4 -0
  130. package/dist/esm/index.example.js +1 -0
  131. package/dist/esm/index2.js +5 -0
  132. package/dist/esm/types/DynamicApiImport.d.js +1 -0
  133. package/dist/esm/types/DynamicImport.d.js +1 -0
  134. package/dist/esm/types/IChaynsReact.js +19 -1
  135. package/dist/esm/types/chayns-components.d.js +0 -0
  136. package/dist/esm/types/chayns-logger.d.js +0 -0
  137. package/dist/esm/types/chayns.d.js +0 -0
  138. package/dist/esm/types/tobit-websocket-service-client.d.js +0 -0
  139. package/dist/esm/types/toolkit-types.d.js +0 -0
  140. package/dist/esm/util/deviceHelper.js +7 -6
  141. package/dist/esm/util/useIsAdminMode.js +9 -0
  142. package/dist/esm/util/useUser.js +7 -0
  143. package/dist/esm/wrapper/AppWrapper.js +39 -0
  144. package/dist/esm/wrapper/Dialog.js +31 -0
  145. package/dist/esm/wrapper/DialogHandler.js +31 -0
  146. package/dist/esm/wrapper/FrameWrapper.js +17 -0
  147. package/dist/esm/wrapper/ModuleFederationWrapper.js +4 -0
  148. package/dist/types/bootstrap.d.ts +1 -0
  149. package/dist/types/calls/dialogs/alert.d.ts +1 -1
  150. package/dist/types/calls/dialogs/chaynsDialog.d.ts +24 -24
  151. package/dist/types/calls/dialogs/close.d.ts +1 -1
  152. package/dist/types/calls/dialogs/communication.d.ts +3 -3
  153. package/dist/types/calls/dialogs/confirm.d.ts +13 -13
  154. package/dist/types/calls/dialogs/date.d.ts +96 -96
  155. package/dist/types/calls/dialogs/dropUpAlert.d.ts +5 -5
  156. package/dist/types/calls/dialogs/fileSelect.d.ts +16 -16
  157. package/dist/types/calls/dialogs/iFrame.d.ts +10 -10
  158. package/dist/types/calls/dialogs/index.d.ts +14 -14
  159. package/dist/types/calls/dialogs/input.d.ts +15 -15
  160. package/dist/types/calls/dialogs/mediaSelect.d.ts +8 -8
  161. package/dist/types/calls/dialogs/open.d.ts +1 -1
  162. package/dist/types/calls/dialogs/select.d.ts +6 -6
  163. package/dist/types/calls/dialogs/signature.d.ts +7 -7
  164. package/dist/types/calls/dialogs/toast.d.ts +1 -1
  165. package/dist/types/calls/dialogs/utils/callback.d.ts +1 -1
  166. package/dist/types/calls/dialogs/utils/is.d.ts +4 -4
  167. package/dist/types/calls/getUserInfo.d.ts +9 -9
  168. package/dist/types/calls/index.d.ts +237 -233
  169. package/dist/types/calls/sendMessage.d.ts +13 -13
  170. package/dist/types/calls/visibilityChangeListener.d.ts +9 -9
  171. package/dist/types/client.d.ts +7 -0
  172. package/dist/types/components/App.d.ts +5 -0
  173. package/dist/types/components/AppDialogWrapper.d.ts +5 -0
  174. package/dist/types/components/Button.d.ts +8 -0
  175. package/dist/types/components/ChaynsContext.d.ts +3 -3
  176. package/dist/types/components/ChaynsModuleProvider.d.ts +170 -0
  177. package/dist/types/components/ChaynsProvider.d.ts +14 -14
  178. package/dist/types/components/ChaynsProviderExposed.d.ts +13 -0
  179. package/dist/types/components/Dialog.d.ts +0 -0
  180. package/dist/types/components/Title.d.ts +3 -0
  181. package/dist/types/components/WaitUntil.d.ts +8 -8
  182. package/dist/types/components/withCompatMode.d.ts +13 -13
  183. package/dist/types/handler/DialogHandler.d.ts +12 -0
  184. package/dist/types/helper/apiListenerHelper.d.ts +6 -6
  185. package/dist/types/hooks/geoLocationListener.d.ts +18 -18
  186. package/dist/types/hooks/index.d.ts +17 -16
  187. package/dist/types/hooks/scrollListener.d.ts +28 -28
  188. package/dist/types/hooks/useAccessToken.d.ts +5 -5
  189. package/dist/types/hooks/useCurrentPage.d.ts +4 -4
  190. package/dist/types/hooks/useCustomData.d.ts +4 -4
  191. package/dist/types/hooks/useDevice.d.ts +5 -5
  192. package/dist/types/hooks/useDialogState.d.ts +9 -0
  193. package/dist/types/hooks/useEnvironment.d.ts +5 -5
  194. package/dist/types/hooks/useFunction.d.ts +2 -0
  195. package/dist/types/hooks/useFunctions.d.ts +5 -5
  196. package/dist/types/hooks/useIsAdminMode.d.ts +4 -4
  197. package/dist/types/hooks/useLanguage.d.ts +5 -5
  198. package/dist/types/hooks/usePages.d.ts +18 -18
  199. package/dist/types/hooks/useParameters.d.ts +5 -5
  200. package/dist/types/hooks/useSite.d.ts +5 -5
  201. package/dist/types/hooks/useUser.d.ts +5 -5
  202. package/dist/types/hooks/useValues.d.ts +5 -5
  203. package/dist/types/hooks/windowMetricsListener.d.ts +11 -11
  204. package/dist/types/host/ChaynsHost.d.ts +30 -29
  205. package/dist/types/host/HostIframe.d.ts +20 -0
  206. package/dist/types/host/iframe/HostIframe.d.ts +26 -25
  207. package/dist/types/host/iframe/utils/useUpdateData.d.ts +3 -3
  208. package/dist/types/host/module/ModuleHost.d.ts +26 -25
  209. package/dist/types/host/module/utils/loadComponent.d.ts +1 -1
  210. package/dist/types/host/module/utils/useDynamicScript.d.ts +9 -9
  211. package/dist/types/index.d.ts +16 -16
  212. package/dist/types/index.example.d.ts +0 -0
  213. package/dist/types/types/IChaynsReact.d.ts +702 -623
  214. package/dist/types/types/dialog.d.ts +41 -41
  215. package/dist/types/util/appCall.d.ts +2 -2
  216. package/dist/types/util/deviceHelper.d.ts +7 -7
  217. package/dist/types/util/heightHelper.d.ts +1 -1
  218. package/dist/types/util/postIframeForm.d.ts +1 -1
  219. package/dist/types/util/url.d.ts +1 -1
  220. package/dist/types/wrapper/AppWrapper.d.ts +22 -18
  221. package/dist/types/wrapper/Dialog.d.ts +10 -0
  222. package/dist/types/wrapper/DialogHandler.d.ts +10 -0
  223. package/dist/types/wrapper/FrameWrapper.d.ts +15 -15
  224. package/dist/types/wrapper/ModuleFederationWrapper.d.ts +10 -10
  225. package/dist/types/wrapper/SsrWrapper.d.ts +11 -11
  226. package/package.json +75 -75
  227. package/tsconfig.json +56 -56
@@ -0,0 +1,18 @@
1
+ import { useContextSelector } from 'use-context-selector';
2
+ import { ChaynsFunctionsContext } from '../components/ChaynsContext';
3
+ import { useCallback } from 'react';
4
+ export var useAddScrollListener = function useAddScrollListener() {
5
+ var addScrollListener = useContextSelector(ChaynsFunctionsContext, function (v) {
6
+ return v === null || v === void 0 ? void 0 : v.addScrollListener;
7
+ });
8
+ var removeScrollListener = useContextSelector(ChaynsFunctionsContext, function (v) {
9
+ return v === null || v === void 0 ? void 0 : v.removeScrollListener;
10
+ });
11
+ var promise;
12
+ return useCallback(function (value, callback) {
13
+ promise = addScrollListener(value, callback);
14
+ return function () {
15
+ promise.then(removeScrollListener);
16
+ };
17
+ }, []);
18
+ };
@@ -0,0 +1,18 @@
1
+ import { useContextSelector } from 'use-context-selector';
2
+ import { ChaynsFunctionsContext } from '../components/ChaynsContext';
3
+ import { useCallback } from 'react';
4
+ export var useAddWindowMetricsListener = function useAddWindowMetricsListener() {
5
+ var addListener = useContextSelector(ChaynsFunctionsContext, function (v) {
6
+ return v === null || v === void 0 ? void 0 : v.addWindowMetricsListener;
7
+ });
8
+ var removeListener = useContextSelector(ChaynsFunctionsContext, function (v) {
9
+ return v === null || v === void 0 ? void 0 : v.removeWindowMetricsListener;
10
+ });
11
+ var promise;
12
+ return useCallback(function (callback) {
13
+ promise = addListener(callback);
14
+ return function () {
15
+ promise.then(removeListener);
16
+ };
17
+ }, []);
18
+ };
@@ -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,28 @@
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 => {
10
+ var _v$dialog;
11
+ return v === null || v === void 0 ? void 0 : (_v$dialog = v.dialog) === null || _v$dialog === void 0 ? void 0 : _v$dialog.isClosingRequested;
12
+ });
13
+ return {
14
+ closeDialog,
15
+ isClosingRequested
16
+ };
17
+ };
18
+
19
+ /**
20
+ * @category Hooks
21
+ */
22
+ export const useDialogData = () => {
23
+ const inputData = useContextSelector(ChaynsContext, v => {
24
+ var _v$dialog2;
25
+ return v === null || v === void 0 ? void 0 : (_v$dialog2 = v.dialog) === null || _v$dialog2 === void 0 ? void 0 : _v$dialog2.dialogInput;
26
+ });
27
+ return inputData;
28
+ };
@@ -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);
@@ -0,0 +1,6 @@
1
+ import { useContextSelector } from 'use-context-selector';
2
+ import { ChaynsFunctionsContext } from '../components/ChaynsContext';
3
+ export const useFunction = name => {
4
+ const t = useContextSelector(ChaynsFunctionsContext, f => f ? f[name] : null);
5
+ return t;
6
+ };
@@ -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, {
@@ -58,7 +60,8 @@ const ChaynsHost = _ref => {
58
60
  parameters: parameters,
59
61
  customData: customData,
60
62
  environment: environment,
61
- preventStagingReplacement: preventStagingReplacement
63
+ preventStagingReplacement: preventStagingReplacement,
64
+ dialog: dialog
62
65
  });
63
66
  case 'server-iframe':
64
67
  return /*#__PURE__*/React.createElement(HostIframe, {
@@ -77,7 +80,8 @@ const ChaynsHost = _ref => {
77
80
  parameters: parameters,
78
81
  environment: environment,
79
82
  customData: customData,
80
- preventStagingReplacement: preventStagingReplacement
83
+ preventStagingReplacement: preventStagingReplacement,
84
+ dialog: dialog
81
85
  });
82
86
  case 'server-module':
83
87
  return /*#__PURE__*/React.createElement(ModuleHost, {
@@ -93,7 +97,8 @@ const ChaynsHost = _ref => {
93
97
  parameters: parameters,
94
98
  customData: customData,
95
99
  environment: environment,
96
- preventStagingReplacement: preventStagingReplacement
100
+ preventStagingReplacement: preventStagingReplacement,
101
+ dialog: dialog
97
102
  }, children);
98
103
  default:
99
104
  return null;
@@ -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;
@@ -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
 
@@ -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({
@@ -43,6 +43,7 @@ const ModuleHost = _ref2 => {
43
43
  language,
44
44
  parameters,
45
45
  customData,
46
+ dialog,
46
47
  environment,
47
48
  preventStagingReplacement
48
49
  } = _ref2;
@@ -61,6 +62,9 @@ const ModuleHost = _ref2 => {
61
62
  if (user) {
62
63
  initialData.user = user;
63
64
  }
65
+ if (dialog) {
66
+ initialData.dialog = dialog;
67
+ }
64
68
  // endregion
65
69
 
66
70
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
@@ -0,0 +1 @@
1
+ import('./bootstrap');
@@ -0,0 +1,5 @@
1
+ export { default as RealChaynsProvider } from './components/ChaynsProvider';
2
+ export { default as getDeviceInfo } from './util/deviceHelper';
3
+ export { default as ChaynsHost } from './host/ChaynsHost';
4
+ export * from './calls';
5
+ export * from './hooks';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -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 = {}));
File without changes
File without changes
File without changes
File without changes
@@ -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;
@@ -0,0 +1,9 @@
1
+ import { useContextSelector } from 'use-context-selector';
2
+ import { ChaynsContext } from '../components/ChaynsContext';
3
+ export var useIsAdminMode = function useIsAdminMode() {
4
+ var _useContextSelector;
5
+
6
+ return (_useContextSelector = useContextSelector(ChaynsContext, function (v) {
7
+ return v === null || v === void 0 ? void 0 : v.isAdminModeActive;
8
+ })) !== null && _useContextSelector !== void 0 ? _useContextSelector : false;
9
+ };
@@ -0,0 +1,7 @@
1
+ import { useContextSelector } from 'use-context-selector';
2
+ import { ChaynsContext } from '../components/ChaynsContext';
3
+ export var useUser = function useUser() {
4
+ return useContextSelector(ChaynsContext, function (v) {
5
+ return v === null || v === void 0 ? void 0 : v.user;
6
+ });
7
+ };
@@ -5,12 +5,14 @@ function _toPrimitive(input, hint) { if (typeof input !== "object" || input ===
5
5
  // @ts-nocheck
6
6
 
7
7
  import throttle from 'lodash.throttle';
8
+ import DialogHandler from '../handler/DialogHandler';
8
9
  import { Environment, Font, Gender, IconType, RuntimeEnviroment, TappEvent } from '../types/IChaynsReact';
9
10
  import invokeAppCall from '../util/appCall';
10
11
  import getDeviceInfo, { getScreenSize } from '../util/deviceHelper';
11
12
  import getUserInfo from '../calls/getUserInfo';
12
13
  import { sendMessageToGroup, sendMessageToPage, sendMessageToUser } from '../calls/sendMessage';
13
14
  import { addApiListener, dispatchApiEvent, removeApiListener } from '../helper/apiListenerHelper';
15
+ let appWrapperDialogId = 0;
14
16
  export class AppWrapper {
15
17
  mapOldApiToNew(retVal) {
16
18
  var _window, _window2, _AppInfo$TappSelected;
@@ -427,12 +429,46 @@ export class AppWrapper {
427
429
  void this.appCall(19, value, {
428
430
  awaitResult: false
429
431
  });
432
+ },
433
+ createDialog: config => {
434
+ return new DialogHandler(config, this.functions.openDialog, this.functions.closeDialog);
435
+ },
436
+ openDialog: async (config, callback) => {
437
+ const currentDialogId = appWrapperDialogId++;
438
+ const eventTarget = new EventTarget();
439
+ const resolve = result => {
440
+ callback(result);
441
+ this.dispatchDialogChange(this.dialogs.filter(x => x.dialogId !== currentDialogId));
442
+ };
443
+ this.dispatchDialogChange([...this.dialogs, {
444
+ config,
445
+ resolve,
446
+ dialogId: currentDialogId,
447
+ eventTarget
448
+ }]);
449
+ return currentDialogId;
450
+ },
451
+ closeDialog: dialogId => {
452
+ const dialog = this.dialogs.find(x => x.dialogId === dialogId);
453
+ if (dialog) {
454
+ dialog.resolve({
455
+ buttonType: -1
456
+ });
457
+ }
430
458
  }
431
459
  });
460
+ _defineProperty(this, "dialogs", []);
461
+ _defineProperty(this, "dialogEventTarget", new EventTarget());
432
462
  }
433
463
  notImplemented(call) {
434
464
  console.warn(`call ${call} not implement in app`);
435
465
  }
466
+ dispatchDialogChange(detail) {
467
+ this.dialogs = detail;
468
+ this.dialogEventTarget.dispatchEvent(new CustomEvent('change', {
469
+ detail
470
+ }));
471
+ }
436
472
  appCall(action) {
437
473
  let value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
438
474
  let {
@@ -465,6 +501,9 @@ export class AppWrapper {
465
501
  });
466
502
  });
467
503
  }
504
+ getDialogEventTarget() {
505
+ return this.dialogEventTarget;
506
+ }
468
507
  async init() {
469
508
  this.values = this.mapOldApiToNew(await this.appCall(18));
470
509
  return undefined;