chayns-api 1.0.66 → 1.0.68-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 (164) 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/chayns-api.js +2 -0
  8. package/dist/chayns-api.js.LICENSE.txt +51 -0
  9. package/dist/cjs/calls/dialogs/date.js +34 -34
  10. package/dist/cjs/calls/index.js +108 -108
  11. package/dist/cjs/calls/sendMessage.js +8 -8
  12. package/dist/cjs/calls/visibilityChangeListener.js +4 -4
  13. package/dist/cjs/components/AppDialogWrapper.js +2 -2
  14. package/dist/cjs/components/ChaynsProvider.js +1 -1
  15. package/dist/cjs/components/ErrorBoundary.js +1 -1
  16. package/dist/cjs/components/withCompatMode.js +2 -2
  17. package/dist/cjs/components/withHydrationBoundary.js +54 -0
  18. package/dist/cjs/constants/hydrationContext.js +16 -0
  19. package/dist/cjs/constants/index.js +16 -0
  20. package/dist/cjs/constants/languages.js +19 -0
  21. package/dist/cjs/hooks/geoLocationListener.js +4 -4
  22. package/dist/cjs/hooks/scrollListener.js +8 -8
  23. package/dist/cjs/hooks/useAccessToken.js +3 -3
  24. package/dist/cjs/hooks/useCurrentPage.js +2 -2
  25. package/dist/cjs/hooks/useCustomData.js +2 -2
  26. package/dist/cjs/hooks/useDevice.js +2 -2
  27. package/dist/cjs/hooks/useDialogState.js +4 -4
  28. package/dist/cjs/hooks/useEnvironment.js +2 -2
  29. package/dist/cjs/hooks/useFunctions.js +2 -2
  30. package/dist/cjs/hooks/useIsAdminMode.js +2 -2
  31. package/dist/cjs/hooks/useLanguage.js +2 -2
  32. package/dist/cjs/hooks/usePages.js +4 -4
  33. package/dist/cjs/hooks/useParameters.js +2 -2
  34. package/dist/cjs/hooks/useSite.js +2 -2
  35. package/dist/cjs/hooks/useUser.js +2 -2
  36. package/dist/cjs/hooks/useValues.js +2 -2
  37. package/dist/cjs/hooks/windowMetricsListener.js +4 -4
  38. package/dist/cjs/host/ChaynsHost.js +21 -40
  39. package/dist/cjs/host/iframe/HostIframe.js +2 -2
  40. package/dist/cjs/host/module/ModuleHost.js +5 -20
  41. package/dist/cjs/host/module/utils/loadComponent.js +98 -53
  42. package/dist/cjs/index.js +36 -1
  43. package/dist/cjs/types/IChaynsReact.js +4 -4
  44. package/dist/cjs/util/heightHelper.js +1 -1
  45. package/dist/cjs/util/url.js +1 -1
  46. package/dist/cjs/wrapper/AppWrapper.js +22 -21
  47. package/dist/cjs/wrapper/FrameWrapper.js +1 -1
  48. package/dist/cjs/wrapper/ModuleFederationWrapper.js +1 -1
  49. package/dist/esm/calls/dialogs/date.js +34 -34
  50. package/dist/esm/calls/index.js +108 -108
  51. package/dist/esm/calls/sendMessage.js +8 -8
  52. package/dist/esm/calls/visibilityChangeListener.js +4 -4
  53. package/dist/esm/components/AppDialogWrapper.js +1 -1
  54. package/dist/esm/components/withCompatMode.js +1 -1
  55. package/dist/esm/components/withHydrationBoundary.js +47 -0
  56. package/dist/esm/constants/hydrationContext.js +10 -0
  57. package/dist/esm/constants/index.js +1 -0
  58. package/dist/esm/constants/languages.js +13 -0
  59. package/dist/esm/handler/DialogHandler.js +1 -1
  60. package/dist/esm/hooks/geoLocationListener.js +4 -4
  61. package/dist/esm/hooks/scrollListener.js +8 -8
  62. package/dist/esm/hooks/useAccessToken.js +3 -3
  63. package/dist/esm/hooks/useCurrentPage.js +2 -2
  64. package/dist/esm/hooks/useCustomData.js +2 -2
  65. package/dist/esm/hooks/useDevice.js +2 -2
  66. package/dist/esm/hooks/useDialogState.js +4 -4
  67. package/dist/esm/hooks/useEnvironment.js +2 -2
  68. package/dist/esm/hooks/useFunctions.js +2 -2
  69. package/dist/esm/hooks/useIsAdminMode.js +2 -2
  70. package/dist/esm/hooks/useLanguage.js +2 -2
  71. package/dist/esm/hooks/usePages.js +4 -4
  72. package/dist/esm/hooks/useParameters.js +2 -2
  73. package/dist/esm/hooks/useSite.js +2 -2
  74. package/dist/esm/hooks/useUser.js +2 -2
  75. package/dist/esm/hooks/useValues.js +2 -2
  76. package/dist/esm/hooks/windowMetricsListener.js +4 -4
  77. package/dist/esm/host/ChaynsHost.js +18 -39
  78. package/dist/esm/host/iframe/HostIframe.js +1 -1
  79. package/dist/esm/host/module/ModuleHost.js +4 -19
  80. package/dist/esm/host/module/utils/loadComponent.js +99 -53
  81. package/dist/esm/index.js +3 -0
  82. package/dist/esm/types/IChaynsReact.js +4 -4
  83. package/dist/esm/util/url.js +2 -2
  84. package/dist/esm/wrapper/AppWrapper.js +22 -22
  85. package/dist/esm/wrapper/FrameWrapper.js +1 -1
  86. package/dist/esm/wrapper/StaticChaynsApi.js +1 -1
  87. package/dist/types/calls/dialogs/alert.d.ts +1 -1
  88. package/dist/types/calls/dialogs/chaynsDialog.d.ts +24 -24
  89. package/dist/types/calls/dialogs/close.d.ts +1 -1
  90. package/dist/types/calls/dialogs/communication.d.ts +3 -3
  91. package/dist/types/calls/dialogs/confirm.d.ts +13 -13
  92. package/dist/types/calls/dialogs/date.d.ts +96 -96
  93. package/dist/types/calls/dialogs/dropUpAlert.d.ts +5 -5
  94. package/dist/types/calls/dialogs/fileSelect.d.ts +16 -16
  95. package/dist/types/calls/dialogs/iFrame.d.ts +10 -10
  96. package/dist/types/calls/dialogs/index.d.ts +14 -14
  97. package/dist/types/calls/dialogs/input.d.ts +15 -15
  98. package/dist/types/calls/dialogs/mediaSelect.d.ts +8 -8
  99. package/dist/types/calls/dialogs/open.d.ts +1 -1
  100. package/dist/types/calls/dialogs/select.d.ts +6 -6
  101. package/dist/types/calls/dialogs/signature.d.ts +7 -7
  102. package/dist/types/calls/dialogs/toast.d.ts +1 -1
  103. package/dist/types/calls/dialogs/utils/callback.d.ts +1 -1
  104. package/dist/types/calls/dialogs/utils/is.d.ts +4 -4
  105. package/dist/types/calls/getUserInfo.d.ts +9 -9
  106. package/dist/types/calls/index.d.ts +255 -259
  107. package/dist/types/calls/sendMessage.d.ts +13 -13
  108. package/dist/types/calls/visibilityChangeListener.d.ts +9 -9
  109. package/dist/types/components/AppDialogWrapper.d.ts +5 -5
  110. package/dist/types/components/ChaynsContext.d.ts +3 -3
  111. package/dist/types/components/ChaynsProvider.d.ts +11 -11
  112. package/dist/types/components/ErrorBoundary.d.ts +13 -13
  113. package/dist/types/components/WaitUntil.d.ts +7 -7
  114. package/dist/types/components/moduleWrapper.d.ts +4 -4
  115. package/dist/types/components/withCompatMode.d.ts +13 -13
  116. package/dist/types/components/withHydrationBoundary.d.ts +17 -0
  117. package/dist/types/constants/hydrationContext.d.ts +9 -0
  118. package/dist/types/constants/index.d.ts +1 -0
  119. package/dist/types/constants/languages.d.ts +12 -0
  120. package/dist/types/handler/DialogHandler.d.ts +18 -18
  121. package/dist/types/helper/apiListenerHelper.d.ts +6 -6
  122. package/dist/types/hooks/geoLocationListener.d.ts +18 -18
  123. package/dist/types/hooks/index.d.ts +17 -17
  124. package/dist/types/hooks/scrollListener.d.ts +28 -28
  125. package/dist/types/hooks/useAccessToken.d.ts +6 -6
  126. package/dist/types/hooks/useCurrentPage.d.ts +7 -4
  127. package/dist/types/hooks/useCustomData.d.ts +4 -4
  128. package/dist/types/hooks/useDevice.d.ts +5 -5
  129. package/dist/types/hooks/useDialogState.d.ts +9 -9
  130. package/dist/types/hooks/useEnvironment.d.ts +5 -5
  131. package/dist/types/hooks/useFunctions.d.ts +5 -5
  132. package/dist/types/hooks/useIsAdminMode.d.ts +4 -4
  133. package/dist/types/hooks/useLanguage.d.ts +5 -5
  134. package/dist/types/hooks/usePages.d.ts +18 -18
  135. package/dist/types/hooks/useParameters.d.ts +5 -5
  136. package/dist/types/hooks/useSite.d.ts +5 -5
  137. package/dist/types/hooks/useUser.d.ts +5 -5
  138. package/dist/types/hooks/useValues.d.ts +5 -5
  139. package/dist/types/hooks/windowMetricsListener.d.ts +11 -11
  140. package/dist/types/host/ChaynsHost.d.ts +29 -30
  141. package/dist/types/host/iframe/HostIframe.d.ts +26 -26
  142. package/dist/types/host/iframe/utils/useUpdateData.d.ts +3 -3
  143. package/dist/types/host/module/ModuleHost.d.ts +28 -27
  144. package/dist/types/host/module/utils/loadComponent.d.ts +3 -1
  145. package/dist/types/index.d.ts +22 -19
  146. package/dist/types/types/IChaynsReact.d.ts +820 -822
  147. package/dist/types/types/dialog.d.ts +41 -41
  148. package/dist/types/util/appCall.d.ts +2 -2
  149. package/dist/types/util/deviceHelper.d.ts +7 -7
  150. package/dist/types/util/heightHelper.d.ts +1 -1
  151. package/dist/types/util/postIframeForm.d.ts +1 -1
  152. package/dist/types/util/transferNestedFunctions.d.ts +1 -1
  153. package/dist/types/util/url.d.ts +1 -1
  154. package/dist/types/wrapper/AppWrapper.d.ts +22 -22
  155. package/dist/types/wrapper/FrameWrapper.d.ts +15 -15
  156. package/dist/types/wrapper/ModuleFederationWrapper.d.ts +10 -10
  157. package/dist/types/wrapper/SsrWrapper.d.ts +11 -11
  158. package/dist/types/wrapper/StaticChaynsApi.d.ts +16 -16
  159. package/package.json +86 -78
  160. package/toolkit.config.js +20 -20
  161. package/tsconfig.json +56 -56
  162. package/dist/cjs/host/module/utils/useDynamicScript.js +0 -59
  163. package/dist/esm/host/module/utils/useDynamicScript.js +0 -50
  164. package/dist/types/host/module/utils/useDynamicScript.d.ts +0 -9
@@ -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);
@@ -1,8 +1,8 @@
1
1
  import { useContextSelector } from 'use-context-selector';
2
2
  import { ChaynsContext, ChaynsFunctionsContext } from '../components/ChaynsContext';
3
3
 
4
- /**
5
- * @category Hooks
4
+ /**
5
+ * @category Hooks
6
6
  */
7
7
  export const useDialogState = () => {
8
8
  const setResult = useContextSelector(ChaynsFunctionsContext, v => v === null || v === void 0 ? void 0 : v.setDialogResult);
@@ -20,8 +20,8 @@ export const useDialogState = () => {
20
20
  };
21
21
  };
22
22
 
23
- /**
24
- * @category Hooks
23
+ /**
24
+ * @category Hooks
25
25
  */
26
26
  export const useDialogData = () => {
27
27
  const inputData = useContextSelector(ChaynsContext, v => {
@@ -1,6 +1,6 @@
1
1
  import { useContextSelector } from 'use-context-selector';
2
2
  import { ChaynsContext } from '../components/ChaynsContext';
3
- /**
4
- * @category Hooks
3
+ /**
4
+ * @category Hooks
5
5
  */
6
6
  export const useEnvironment = () => useContextSelector(ChaynsContext, v => v === null || v === void 0 ? void 0 : v.environment);
@@ -1,7 +1,7 @@
1
1
  import { useContextSelector } from "use-context-selector";
2
2
  import { ChaynsFunctionsContext } from "../components/ChaynsContext";
3
- /**
4
- * @category Hooks
3
+ /**
4
+ * @category Hooks
5
5
  */
6
6
  export const useFunctions = () => {
7
7
  const t = useContextSelector(ChaynsFunctionsContext, f => f || {});
@@ -1,7 +1,7 @@
1
1
  import { useContextSelector } from 'use-context-selector';
2
2
  import { ChaynsContext } from '../components/ChaynsContext';
3
- /**
4
- * @category Hooks
3
+ /**
4
+ * @category Hooks
5
5
  */
6
6
  export const useIsAdminMode = () => {
7
7
  var _useContextSelector;
@@ -1,6 +1,6 @@
1
1
  import { useContextSelector } from 'use-context-selector';
2
2
  import { ChaynsContext } from '../components/ChaynsContext';
3
- /**
4
- * @category Hooks
3
+ /**
4
+ * @category Hooks
5
5
  */
6
6
  export const useLanguage = () => useContextSelector(ChaynsContext, v => v === null || v === void 0 ? void 0 : v.language);
@@ -1,8 +1,8 @@
1
1
  import { useContextSelector } from 'use-context-selector';
2
2
  import { ChaynsContext } from '../components/ChaynsContext';
3
3
  import { moduleWrapper } from '../components/moduleWrapper';
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 {
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { startTransition, useEffect, useState } from 'react';
2
2
  import HostIframe from './iframe/HostIframe';
3
3
  import ModuleHost from './module/ModuleHost';
4
4
  const ChaynsHost = _ref => {
@@ -9,7 +9,6 @@ const ChaynsHost = _ref => {
9
9
  src,
10
10
  iFrameRef = undefined,
11
11
  loadingComponent = undefined,
12
- children = undefined,
13
12
  system,
14
13
  // shallow data
15
14
  pages,
@@ -25,8 +24,23 @@ const ChaynsHost = _ref => {
25
24
  preventStagingReplacement,
26
25
  dialog
27
26
  } = _ref;
27
+ const [isVisible, setIsVisible] = useState(type !== 'client-module' && (type !== 'server-module' || !!(system !== null && system !== void 0 && system.serverUrl)));
28
+ useEffect(() => {
29
+ if (isVisible) return;
30
+ if (typeof startTransition === 'function') {
31
+ startTransition(() => {
32
+ setIsVisible(true);
33
+ });
34
+ } else {
35
+ setIsVisible(true);
36
+ }
37
+ }, []);
38
+ if (!isVisible) {
39
+ return null;
40
+ }
28
41
  switch (type) {
29
42
  case 'client-iframe':
43
+ case 'server-iframe':
30
44
  return /*#__PURE__*/React.createElement(HostIframe, {
31
45
  iFrameRef: iFrameRef,
32
46
  iFrameProps: iFrameProps,
@@ -38,6 +52,7 @@ const ChaynsHost = _ref => {
38
52
  currentPage: currentPage,
39
53
  functions: functions,
40
54
  src: src,
55
+ postForm: type === 'server-iframe',
41
56
  language: language,
42
57
  parameters: parameters,
43
58
  environment: environment,
@@ -46,6 +61,7 @@ const ChaynsHost = _ref => {
46
61
  dialog: dialog
47
62
  });
48
63
  case 'client-module':
64
+ case 'server-module':
49
65
  return /*#__PURE__*/React.createElement(ModuleHost, {
50
66
  system: system,
51
67
  pages: pages,
@@ -63,43 +79,6 @@ const ChaynsHost = _ref => {
63
79
  preventStagingReplacement: preventStagingReplacement,
64
80
  dialog: dialog
65
81
  });
66
- case 'server-iframe':
67
- return /*#__PURE__*/React.createElement(HostIframe, {
68
- iFrameRef: iFrameRef,
69
- iFrameProps: iFrameProps,
70
- pages: pages,
71
- isAdminModeActive: isAdminModeActive,
72
- site: site,
73
- user: user,
74
- device: device,
75
- currentPage: currentPage,
76
- functions: functions,
77
- src: src,
78
- postForm: true,
79
- language: language,
80
- parameters: parameters,
81
- environment: environment,
82
- customData: customData,
83
- preventStagingReplacement: preventStagingReplacement,
84
- dialog: dialog
85
- });
86
- case 'server-module':
87
- return /*#__PURE__*/React.createElement(ModuleHost, {
88
- system: system,
89
- pages: pages,
90
- isAdminModeActive: isAdminModeActive,
91
- site: site,
92
- user: user,
93
- device: device,
94
- currentPage: currentPage,
95
- functions: functions,
96
- language: language,
97
- parameters: parameters,
98
- customData: customData,
99
- environment: environment,
100
- preventStagingReplacement: preventStagingReplacement,
101
- dialog: dialog
102
- }, children);
103
82
  default:
104
83
  return null;
105
84
  }
@@ -1,4 +1,4 @@
1
- function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
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); }
2
2
  import React, { useEffect, useRef } from 'react';
3
3
  import * as comlink from 'comlink';
4
4
  import postIframeForm from '../../util/postIframeForm';
@@ -1,5 +1,4 @@
1
1
  import React, { useMemo } from 'react';
2
- import useDynamicScript from './utils/useDynamicScript';
3
2
  import loadComponent from './utils/loadComponent';
4
3
  import { replaceStagingUrl } from "../../util/url";
5
4
  const System = _ref => {
@@ -8,25 +7,10 @@ const System = _ref => {
8
7
  fallback,
9
8
  ...props
10
9
  } = _ref;
11
- const {
12
- ready,
13
- failed
14
- } = useDynamicScript({
15
- url: system === null || system === void 0 ? void 0 : system.url,
16
- scope: system === null || system === void 0 ? void 0 : system.scope
17
- });
18
- const Component = useMemo(() => {
19
- // maybe return waitcursor instead
20
- if (!system || !ready || failed) {
21
- return null;
22
- }
23
- return /*#__PURE__*/React.lazy(loadComponent(system.scope, system.module, system.url, undefined, system.preventSingleton));
24
-
25
- /* eslint-disable react-hooks/exhaustive-deps */
26
- }, [system === null || system === void 0 ? void 0 : system.scope, ready, system === null || system === void 0 ? void 0 : system.url]);
27
- return Component ? /*#__PURE__*/React.createElement(React.Suspense, {
10
+ const Component = useMemo(() => loadComponent(system.scope, system.module, globalThis.window ? system.url : system.serverUrl, undefined, system.preventSingleton), [system.scope, system.module, system.url, system.serverUrl, system.preventSingleton]);
11
+ return /*#__PURE__*/React.createElement(React.Suspense, {
28
12
  fallback: fallback || ''
29
- }, /*#__PURE__*/React.createElement(Component, props)) : fallback;
13
+ }, /*#__PURE__*/React.createElement(Component, props));
30
14
  };
31
15
  const ModuleHost = _ref2 => {
32
16
  let {
@@ -73,6 +57,7 @@ const ModuleHost = _ref2 => {
73
57
  system: {
74
58
  scope: system.scope,
75
59
  url: replaceStagingUrl(preventStagingReplacement, system.url, environment.buildEnvironment),
60
+ serverUrl: replaceStagingUrl(preventStagingReplacement, system.serverUrl, environment.buildEnvironment),
76
61
  module: system.module,
77
62
  preventSingleton: system.preventSingleton
78
63
  },
@@ -1,60 +1,106 @@
1
- /* eslint-disable */
2
- // @ts-nocheck
3
-
1
+ var _process$env$__PACKAG;
2
+ import ReactDOM from 'react-dom';
4
3
  import semver from 'semver';
5
4
  import React from 'react';
6
- import { semaphore } from './useDynamicScript';
7
- let instances = {};
8
- export default function loadComponent(scope, module, url) {
9
- let skipCompatMode = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
10
- let preventSingleton = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
11
- return async () => {
12
- // Initializes the shared scope. Fills it with known provided modules from this build and all remotes
13
- await __webpack_init_sharing__('default');
14
- const {
15
- container
16
- } = window[scope + "_list"].find(x => x.url === url); // or get the container somewhere else
17
- // Initialize the container, it may provide shared modules
18
- await container.init(__webpack_share_scopes__.default);
19
- const factory = await container.get(module);
20
- semaphore[scope].release();
21
- let ModuleMap = instances[`${scope}__${module}`];
22
- let Module;
23
- if (!ModuleMap) {
24
- ModuleMap = {};
25
- instances[`${scope}__${module}`] = ModuleMap;
26
- }
27
- if (Object.keys(ModuleMap).length > 0) {
28
- const newModule = factory();
29
- Module = ModuleMap[`${newModule.default.buildEnv}__${newModule.default.appVersion}`];
30
- if (!Module) {
31
- Module = newModule;
32
- ModuleMap[`${newModule.default.buildEnv}__${newModule.default.appVersion}`] = newModule;
33
- }
34
- } else {
35
- Module = factory();
36
- ModuleMap[`${Module.default.buildEnv}__${Module.default.appVersion}`] = Module;
5
+ import { loadRemote, registerRemotes, loadShareSync, init } from '@module-federation/runtime';
6
+ const registeredScopes = {};
7
+ const moduleMap = {};
8
+ const componentMap = {};
9
+ init({
10
+ // will be set by chayns-toolkit via DefinePlugin
11
+ name: (_process$env$__PACKAG = process.env.__PACKAGE_NAME__) !== null && _process$env$__PACKAG !== void 0 ? _process$env$__PACKAG : '',
12
+ remotes: [],
13
+ shared: {
14
+ react: {
15
+ version: React.version,
16
+ scope: 'default',
17
+ lib: () => React
18
+ },
19
+ 'react-dom': {
20
+ version: ReactDOM.version,
21
+ scope: 'default',
22
+ lib: () => ReactDOM
37
23
  }
38
- if (preventSingleton) {
39
- // Intercom :)
40
- window[scope + "_list"] = null;
24
+ }
25
+ });
26
+ export const loadModule = function (scope, module, url) {
27
+ let preventSingleton = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
28
+ if (registeredScopes[scope] !== url || preventSingleton) {
29
+ if (scope in registeredScopes) {
30
+ console.error(`[chayns-api] call registerRemote with force for scope ${scope}. url: ${url}`);
41
31
  }
42
- if (skipCompatMode) return Module;
43
- const hostVersion = semver.minVersion(React.version);
44
- const {
45
- requiredVersion,
46
- environment
47
- } = Module.default;
48
- const matchReactVersion = requiredVersion && semver.satisfies(hostVersion, requiredVersion) && !Object.keys(__webpack_share_scopes__.default.react).some(version => {
49
- return semver.gt(version, hostVersion) && semver.satisfies(version, requiredVersion) || scope === __webpack_share_scopes__.default.react[version].from.split('-').join('_');
32
+ registerRemotes([{
33
+ name: scope,
34
+ entry: url,
35
+ alias: scope
36
+ }], {
37
+ force: scope in registeredScopes || preventSingleton
38
+ });
39
+ registeredScopes[scope] = url;
40
+ moduleMap[scope] = {};
41
+ componentMap[scope] = {};
42
+ }
43
+ if (!(module in moduleMap[scope])) {
44
+ const path = `${scope}/${module.replace(/^\.\//, '')}`;
45
+ const promise = loadRemote(path);
46
+ promise.catch(e => {
47
+ console.error("[chayns-api] Failed to load module", scope, url, e);
48
+ // causes registerRemote with force = true on next attempt to load the component which tries to load the component again
49
+ registeredScopes[scope] = '';
50
50
  });
51
- if (!matchReactVersion || environment !== 'production' || process.env.NODE_ENV === 'development') {
51
+ return promise;
52
+ }
53
+ return moduleMap[scope][module];
54
+ };
55
+ const loadComponent = function (scope, module, url) {
56
+ let skipCompatMode = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
57
+ let preventSingleton = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
58
+ if (skipCompatMode) {
59
+ console.warn('[chayns-api] skipCompatMode-option is deprecated and is set automatically now');
60
+ }
61
+ if (!componentMap[scope]) {
62
+ componentMap[scope] = {};
63
+ }
64
+ if (!(module in componentMap[scope])) {
65
+ const promise = loadModule(scope, module, url, preventSingleton).then(async Module => {
66
+ if (typeof Module.default === 'function') {
67
+ return Module;
68
+ }
69
+ const hostVersion = semver.minVersion(React.version);
70
+ const {
71
+ requiredVersion,
72
+ environment
73
+ } = Module.default;
74
+ const shareScopes = await new Promise(resolve => {
75
+ loadShareSync('react', {
76
+ resolver: shareOptions => {
77
+ resolve(shareOptions);
78
+ return shareOptions[0];
79
+ }
80
+ });
81
+ });
82
+ const matchReactVersion = requiredVersion && semver.satisfies(hostVersion, requiredVersion) && !shareScopes.some(_ref => {
83
+ let {
84
+ version,
85
+ from
86
+ } = _ref;
87
+ return semver.gt(version, hostVersion) && semver.satisfies(version, requiredVersion) || scope === from.split('-').join('_');
88
+ });
89
+ if (!matchReactVersion || environment !== 'production' || process.env.NODE_ENV === 'development') {
90
+ return {
91
+ default: Module.default.CompatComponent
92
+ };
93
+ }
52
94
  return {
53
- default: Module.default.CompatComponent
95
+ default: Module.default.Component
54
96
  };
55
- }
56
- return {
57
- default: Module.default.Component
58
- };
59
- };
60
- }
97
+ });
98
+ promise.catch(e => {
99
+ console.error("[chayns-api] Failed to load component", scope, url, e);
100
+ delete componentMap[scope][module];
101
+ });
102
+ componentMap[scope][module] = /*#__PURE__*/React.lazy(() => promise);
103
+ }
104
+ return componentMap[scope][module];
105
+ };
106
+ export default loadComponent;
package/dist/esm/index.js CHANGED
@@ -8,7 +8,10 @@ export * from './hooks';
8
8
  export * from './components/WaitUntil';
9
9
  export * from './types/IChaynsReact';
10
10
  export * from './components/withCompatMode';
11
+ export * from './constants';
12
+ export { default as withHydrationBoundary } from './components/withHydrationBoundary';
11
13
  export { default as StaticChaynsApi } from './wrapper/StaticChaynsApi';
14
+ export { default as loadComponent, loadModule } from './host/module/utils/loadComponent';
12
15
  export { default as DialogHandler } from './handler/DialogHandler';
13
16
  import * as _dialog from './calls/dialogs/index';
14
17
  export { _dialog as dialog };
@@ -40,12 +40,12 @@ export let ScreenSize = /*#__PURE__*/function (ScreenSize) {
40
40
  return ScreenSize;
41
41
  }({});
42
42
 
43
- /**
44
- * @ignore
43
+ /**
44
+ * @ignore
45
45
  */
46
46
 
47
- /**
48
- * @ignore
47
+ /**
48
+ * @ignore
49
49
  */
50
50
 
51
51
  export let AccessMode = /*#__PURE__*/function (AccessMode) {
@@ -1,6 +1,6 @@
1
- import { Environment } from "../types/IChaynsReact";
1
+ import { Environment } from '../types/IChaynsReact';
2
2
  export const replaceStagingUrl = (prevent, url, environment) => {
3
- if (prevent) return url;
3
+ if (prevent || !url) return url;
4
4
  let replacedUrl = url;
5
5
  if (environment === Environment.Qa || environment === Environment.Development) {
6
6
  replacedUrl = replacedUrl.replace('tapp.chayns-static.space', 'tapp-dev.chayns-static.space');
@@ -1,4 +1,4 @@
1
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
1
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
2
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
3
3
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
4
4
  /* eslint-disable */
@@ -12,13 +12,15 @@ import getDeviceInfo, { getScreenSize } from '../util/deviceHelper';
12
12
  import getUserInfo from '../calls/getUserInfo';
13
13
  import { sendMessageToGroup, sendMessageToPage, sendMessageToUser } from '../calls/sendMessage';
14
14
  import { addApiListener, dispatchApiEvent, removeApiListener } from '../helper/apiListenerHelper';
15
+ import { DeviceLanguage } from "../constants/languages";
15
16
  let appWrapperDialogId = 0;
16
17
  export class AppWrapper {
17
18
  mapOldApiToNew(retVal) {
18
19
  var _window, _colorMode, _window2, _AppInfo$TappSelected;
19
20
  const {
20
21
  AppInfo,
21
- AppUser
22
+ AppUser,
23
+ Device
22
24
  } = retVal;
23
25
  this.accessToken = AppUser.TobitAccessToken;
24
26
  const urlParams = new URLSearchParams(location.search);
@@ -38,6 +40,10 @@ export class AppWrapper {
38
40
  // ignore
39
41
  }
40
42
  }
43
+ let language = AppInfo.Language;
44
+ if (!language) {
45
+ language = DeviceLanguage[Number.parseInt(Device === null || Device === void 0 ? void 0 : Device.LanguageID, 10)] || 'de';
46
+ }
41
47
  if (!color && urlParamsLowerCase.has('color')) {
42
48
  color = urlParamsLowerCase.get('color');
43
49
  if (!color.startsWith('#')) {
@@ -59,12 +65,11 @@ export class AppWrapper {
59
65
  runtimeEnvironment: RuntimeEnviroment.Unknown
60
66
  },
61
67
  language: {
62
- site: AppInfo.Language,
68
+ site: language,
63
69
  translation: null,
64
- device: AppInfo.Language,
65
- active: AppInfo.Language
70
+ device: language,
71
+ active: language
66
72
  },
67
- // ToDo: Find better way to detect
68
73
  site: {
69
74
  id: AppInfo.SiteID,
70
75
  locationId: AppInfo.LocationID,
@@ -103,7 +108,7 @@ export class AppWrapper {
103
108
  customData: null,
104
109
  isAdminModeActive: AppUser.AdminMode,
105
110
  currentPage: {
106
- id: ((_AppInfo$TappSelected = AppInfo.TappSelected) === null || _AppInfo$TappSelected === void 0 ? void 0 : _AppInfo$TappSelected.TappID) || tappId,
111
+ id: tappId || ((_AppInfo$TappSelected = AppInfo.TappSelected) === null || _AppInfo$TappSelected === void 0 ? void 0 : _AppInfo$TappSelected.TappID),
107
112
  siteId: AppInfo.SiteID
108
113
  },
109
114
  pages: AppInfo.Tapps.map(x => ({
@@ -515,6 +520,9 @@ export class AppWrapper {
515
520
  buttonType: -1
516
521
  });
517
522
  }
523
+ },
524
+ addAnonymousAccount: async () => {
525
+ return this.appCall(302);
518
526
  }
519
527
  });
520
528
  _defineProperty(this, "dialogs", []);
@@ -566,23 +574,15 @@ export class AppWrapper {
566
574
  }
567
575
  async init() {
568
576
  this.values = this.mapOldApiToNew(await this.appCall(18));
569
- const callbackName = `chaynsApiV5Callback_${this.counter++}`;
570
- window.disablev4AccessTokenChangeListener = true;
571
- window[callbackName] = _ref2 => {
572
- let {
573
- retVal: value
574
- } = _ref2;
575
- if ('tobitAccessToken' in value) {
576
- this.accessToken = value.tobitAccessToken;
577
- } else {
578
- this.mapOldApiToNew(value);
579
- }
580
- };
581
577
  this.appCall(66, {
582
578
  enabled: true,
583
- callback: callbackName
584
- }, {
585
- awaitResult: false
579
+ callback: value => {
580
+ if ('tobitAccessToken' in value) {
581
+ this.accessToken = value.tobitAccessToken;
582
+ } else {
583
+ this.mapOldApiToNew(value);
584
+ }
585
+ }
586
586
  });
587
587
  return undefined;
588
588
  }
@@ -1,4 +1,4 @@
1
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
1
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
2
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
3
3
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
4
4
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
@@ -1,4 +1,4 @@
1
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
1
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
2
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
3
3
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
4
4
  import { moduleWrapper } from '../components/moduleWrapper';
@@ -1 +1 @@
1
- export declare function alert(title?: string, message?: string): Promise<any> | "unsupported";
1
+ export declare function alert(title?: string, message?: string): Promise<any> | "unsupported";