chayns-api 1.1.9 → 1.2.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 (160) 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/calls/dialogs/date.js +34 -34
  8. package/dist/cjs/calls/index.js +108 -108
  9. package/dist/cjs/calls/sendMessage.js +8 -8
  10. package/dist/cjs/calls/visibilityChangeListener.js +4 -4
  11. package/dist/cjs/components/AppDialogWrapper.js +2 -2
  12. package/dist/cjs/components/ChaynsProvider.js +1 -1
  13. package/dist/cjs/components/ErrorBoundary.js +1 -1
  14. package/dist/cjs/components/withCompatMode.js +2 -2
  15. package/dist/cjs/components/withHydrationBoundary.js +54 -0
  16. package/dist/cjs/constants/hydrationContext.js +16 -0
  17. package/dist/cjs/constants/index.js +16 -0
  18. package/dist/cjs/hooks/geoLocationListener.js +4 -4
  19. package/dist/cjs/hooks/scrollListener.js +8 -8
  20. package/dist/cjs/hooks/useAccessToken.js +3 -3
  21. package/dist/cjs/hooks/useCurrentPage.js +2 -2
  22. package/dist/cjs/hooks/useCustomData.js +2 -2
  23. package/dist/cjs/hooks/useDevice.js +2 -2
  24. package/dist/cjs/hooks/useDialogState.js +4 -4
  25. package/dist/cjs/hooks/useEnvironment.js +2 -2
  26. package/dist/cjs/hooks/useFunctions.js +2 -2
  27. package/dist/cjs/hooks/useIsAdminMode.js +2 -2
  28. package/dist/cjs/hooks/useLanguage.js +2 -2
  29. package/dist/cjs/hooks/usePages.js +4 -4
  30. package/dist/cjs/hooks/useParameters.js +2 -2
  31. package/dist/cjs/hooks/useSite.js +2 -2
  32. package/dist/cjs/hooks/useUser.js +2 -2
  33. package/dist/cjs/hooks/useValues.js +2 -2
  34. package/dist/cjs/hooks/windowMetricsListener.js +4 -4
  35. package/dist/cjs/host/ChaynsHost.js +21 -40
  36. package/dist/cjs/host/iframe/HostIframe.js +2 -2
  37. package/dist/cjs/host/module/ModuleHost.js +5 -23
  38. package/dist/cjs/host/module/utils/loadComponent.js +98 -53
  39. package/dist/cjs/host/module/utils/useDynamicScript.js +7 -5
  40. package/dist/cjs/index.js +36 -1
  41. package/dist/cjs/types/IChaynsReact.js +4 -4
  42. package/dist/cjs/util/heightHelper.js +1 -1
  43. package/dist/cjs/util/url.js +1 -1
  44. package/dist/cjs/wrapper/AppWrapper.js +6 -6
  45. package/dist/cjs/wrapper/FrameWrapper.js +1 -1
  46. package/dist/cjs/wrapper/ModuleFederationWrapper.js +1 -1
  47. package/dist/esm/calls/dialogs/date.js +34 -34
  48. package/dist/esm/calls/index.js +108 -108
  49. package/dist/esm/calls/sendMessage.js +8 -8
  50. package/dist/esm/calls/visibilityChangeListener.js +4 -4
  51. package/dist/esm/components/AppDialogWrapper.js +1 -1
  52. package/dist/esm/components/withCompatMode.js +1 -1
  53. package/dist/esm/components/withHydrationBoundary.js +47 -0
  54. package/dist/esm/constants/hydrationContext.js +10 -0
  55. package/dist/esm/constants/index.js +1 -0
  56. package/dist/esm/handler/DialogHandler.js +1 -1
  57. package/dist/esm/hooks/geoLocationListener.js +4 -4
  58. package/dist/esm/hooks/scrollListener.js +8 -8
  59. package/dist/esm/hooks/useAccessToken.js +3 -3
  60. package/dist/esm/hooks/useCurrentPage.js +2 -2
  61. package/dist/esm/hooks/useCustomData.js +2 -2
  62. package/dist/esm/hooks/useDevice.js +2 -2
  63. package/dist/esm/hooks/useDialogState.js +4 -4
  64. package/dist/esm/hooks/useEnvironment.js +2 -2
  65. package/dist/esm/hooks/useFunctions.js +2 -2
  66. package/dist/esm/hooks/useIsAdminMode.js +2 -2
  67. package/dist/esm/hooks/useLanguage.js +2 -2
  68. package/dist/esm/hooks/usePages.js +4 -4
  69. package/dist/esm/hooks/useParameters.js +2 -2
  70. package/dist/esm/hooks/useSite.js +2 -2
  71. package/dist/esm/hooks/useUser.js +2 -2
  72. package/dist/esm/hooks/useValues.js +2 -2
  73. package/dist/esm/hooks/windowMetricsListener.js +4 -4
  74. package/dist/esm/host/ChaynsHost.js +18 -39
  75. package/dist/esm/host/iframe/HostIframe.js +1 -1
  76. package/dist/esm/host/module/ModuleHost.js +4 -22
  77. package/dist/esm/host/module/utils/loadComponent.js +99 -53
  78. package/dist/esm/index.js +3 -0
  79. package/dist/esm/types/IChaynsReact.js +4 -4
  80. package/dist/esm/util/url.js +2 -2
  81. package/dist/esm/wrapper/AppWrapper.js +6 -6
  82. package/dist/esm/wrapper/FrameWrapper.js +1 -1
  83. package/dist/esm/wrapper/StaticChaynsApi.js +1 -1
  84. package/dist/types/calls/dialogs/alert.d.ts +1 -1
  85. package/dist/types/calls/dialogs/chaynsDialog.d.ts +24 -24
  86. package/dist/types/calls/dialogs/close.d.ts +1 -1
  87. package/dist/types/calls/dialogs/communication.d.ts +3 -3
  88. package/dist/types/calls/dialogs/confirm.d.ts +13 -13
  89. package/dist/types/calls/dialogs/date.d.ts +96 -96
  90. package/dist/types/calls/dialogs/dropUpAlert.d.ts +5 -5
  91. package/dist/types/calls/dialogs/fileSelect.d.ts +16 -16
  92. package/dist/types/calls/dialogs/iFrame.d.ts +10 -10
  93. package/dist/types/calls/dialogs/index.d.ts +14 -14
  94. package/dist/types/calls/dialogs/input.d.ts +15 -15
  95. package/dist/types/calls/dialogs/mediaSelect.d.ts +8 -8
  96. package/dist/types/calls/dialogs/open.d.ts +1 -1
  97. package/dist/types/calls/dialogs/select.d.ts +6 -6
  98. package/dist/types/calls/dialogs/signature.d.ts +7 -7
  99. package/dist/types/calls/dialogs/toast.d.ts +1 -1
  100. package/dist/types/calls/dialogs/utils/callback.d.ts +1 -1
  101. package/dist/types/calls/dialogs/utils/is.d.ts +4 -4
  102. package/dist/types/calls/getUserInfo.d.ts +9 -9
  103. package/dist/types/calls/index.d.ts +255 -255
  104. package/dist/types/calls/sendMessage.d.ts +13 -13
  105. package/dist/types/calls/visibilityChangeListener.d.ts +9 -9
  106. package/dist/types/components/AppDialogWrapper.d.ts +5 -5
  107. package/dist/types/components/ChaynsContext.d.ts +3 -3
  108. package/dist/types/components/ChaynsProvider.d.ts +11 -11
  109. package/dist/types/components/ErrorBoundary.d.ts +13 -13
  110. package/dist/types/components/WaitUntil.d.ts +7 -7
  111. package/dist/types/components/moduleWrapper.d.ts +4 -4
  112. package/dist/types/components/withCompatMode.d.ts +13 -13
  113. package/dist/types/components/withHydrationBoundary.d.ts +17 -0
  114. package/dist/types/constants/hydrationContext.d.ts +9 -0
  115. package/dist/types/constants/index.d.ts +1 -0
  116. package/dist/types/constants/languages.d.ts +12 -12
  117. package/dist/types/handler/DialogHandler.d.ts +24 -24
  118. package/dist/types/helper/apiListenerHelper.d.ts +6 -6
  119. package/dist/types/hooks/geoLocationListener.d.ts +18 -18
  120. package/dist/types/hooks/index.d.ts +17 -17
  121. package/dist/types/hooks/scrollListener.d.ts +28 -28
  122. package/dist/types/hooks/useAccessToken.d.ts +6 -6
  123. package/dist/types/hooks/useCurrentPage.d.ts +7 -4
  124. package/dist/types/hooks/useCustomData.d.ts +4 -4
  125. package/dist/types/hooks/useDevice.d.ts +5 -5
  126. package/dist/types/hooks/useDialogState.d.ts +9 -9
  127. package/dist/types/hooks/useEnvironment.d.ts +5 -5
  128. package/dist/types/hooks/useFunctions.d.ts +5 -5
  129. package/dist/types/hooks/useIsAdminMode.d.ts +4 -4
  130. package/dist/types/hooks/useLanguage.d.ts +5 -5
  131. package/dist/types/hooks/usePages.d.ts +18 -18
  132. package/dist/types/hooks/useParameters.d.ts +5 -5
  133. package/dist/types/hooks/useSite.d.ts +5 -5
  134. package/dist/types/hooks/useUser.d.ts +5 -5
  135. package/dist/types/hooks/useValues.d.ts +5 -5
  136. package/dist/types/hooks/windowMetricsListener.d.ts +11 -11
  137. package/dist/types/host/ChaynsHost.d.ts +29 -30
  138. package/dist/types/host/iframe/HostIframe.d.ts +26 -26
  139. package/dist/types/host/iframe/utils/useUpdateData.d.ts +3 -3
  140. package/dist/types/host/module/ModuleHost.d.ts +28 -27
  141. package/dist/types/host/module/utils/loadComponent.d.ts +3 -1
  142. package/dist/types/host/module/utils/useDynamicScript.d.ts +9 -9
  143. package/dist/types/index.d.ts +23 -20
  144. package/dist/types/types/IChaynsReact.d.ts +860 -860
  145. package/dist/types/types/dialog.d.ts +41 -41
  146. package/dist/types/util/appCall.d.ts +2 -2
  147. package/dist/types/util/deviceHelper.d.ts +7 -7
  148. package/dist/types/util/heightHelper.d.ts +1 -1
  149. package/dist/types/util/is.d.ts +5 -5
  150. package/dist/types/util/postIframeForm.d.ts +1 -1
  151. package/dist/types/util/transferNestedFunctions.d.ts +1 -1
  152. package/dist/types/util/url.d.ts +1 -1
  153. package/dist/types/wrapper/AppWrapper.d.ts +19 -19
  154. package/dist/types/wrapper/FrameWrapper.d.ts +15 -15
  155. package/dist/types/wrapper/ModuleFederationWrapper.d.ts +10 -10
  156. package/dist/types/wrapper/SsrWrapper.d.ts +11 -11
  157. package/dist/types/wrapper/StaticChaynsApi.d.ts +16 -16
  158. package/package.json +87 -79
  159. package/toolkit.config.js +20 -20
  160. package/tsconfig.json +56 -56
@@ -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
  /* eslint-disable react/jsx-props-no-spreading */
3
3
 
4
4
  import React, { PureComponent } from 'react';
@@ -0,0 +1,47 @@
1
+ import React, { useContext, useEffect, useState } from 'react';
2
+ import { HydrationContext } from '../constants';
3
+ const withHydrationBoundary = (Component, initializer, useHydrationId) => {
4
+ return _ref => {
5
+ let {
6
+ id: idProp,
7
+ children
8
+ } = _ref;
9
+ let value;
10
+ if (!globalThis.window) {
11
+ value = useContext(HydrationContext);
12
+ }
13
+ const id = useHydrationId ? useHydrationId() : idProp;
14
+ if (!id) {
15
+ throw new Error('hydration boundary was not given a id which is required');
16
+ }
17
+ const [store] = useState(() => {
18
+ if (!globalThis.window && id in value) {
19
+ return value[id];
20
+ }
21
+ let initialValue = undefined;
22
+ if (globalThis.window) {
23
+ const htmlId = `__INITIAL_DATA_${id}__`;
24
+ const $elem = document.getElementById(htmlId);
25
+ if ($elem) {
26
+ initialValue = JSON.parse($elem.innerHTML);
27
+ }
28
+ }
29
+ const s = initializer(initialValue, id);
30
+ if (!globalThis.window) {
31
+ value[id] = s;
32
+ }
33
+ return s;
34
+ });
35
+ useEffect(() => {
36
+ const htmlId = `__INITIAL_DATA_${id}__`;
37
+ const $elem = document.getElementById(htmlId);
38
+ if ($elem) {
39
+ $elem.remove();
40
+ }
41
+ }, []);
42
+ return /*#__PURE__*/React.createElement(Component, {
43
+ value: store
44
+ }, children);
45
+ };
46
+ };
47
+ export default withHydrationBoundary;
@@ -0,0 +1,10 @@
1
+ import { createContext } from 'react';
2
+ export let HydrationContext;
3
+
4
+ // force single context on server-side (fake sharing)
5
+ if (!globalThis.window && globalThis._hydrationContext) {
6
+ HydrationContext = globalThis._hydrationContext;
7
+ } else {
8
+ HydrationContext = /*#__PURE__*/createContext({});
9
+ globalThis._hydrationContext = HydrationContext;
10
+ }
@@ -0,0 +1 @@
1
+ export * from './hydrationContext';
@@ -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
  export default class DialogHandler {
@@ -1,8 +1,8 @@
1
1
  import { useContextSelector } from 'use-context-selector';
2
2
  import { useCallback, useEffect, useRef, useState } from 'react';
3
3
  import { ChaynsFunctionsContext } from '../components/ChaynsContext';
4
- /**
5
- * @category Hooks
4
+ /**
5
+ * @category Hooks
6
6
  */
7
7
  export const useGeoLocationListener = () => {
8
8
  const addListener = useContextSelector(ChaynsFunctionsContext, v => v.addGeoLocationListener);
@@ -17,8 +17,8 @@ export const useGeoLocationListener = () => {
17
17
  // eslint-disable-next-line react-hooks/exhaustive-deps
18
18
  }, []);
19
19
  };
20
- /**
21
- * @category Hooks
20
+ /**
21
+ * @category Hooks
22
22
  */
23
23
  export const useGeoLocation = function () {
24
24
  let {
@@ -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 { useWindowMetrics } from './windowMetricsListener';
5
- /**
6
- * @category Hooks
5
+ /**
6
+ * @category Hooks
7
7
  */
8
8
  export const useScrollListener = () => {
9
9
  const addListener = useContextSelector(ChaynsFunctionsContext, v => v.addScrollListener);
@@ -18,8 +18,8 @@ export const useScrollListener = () => {
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 useScrollPosition = function () {
25
25
  let {
@@ -46,8 +46,8 @@ export const useScrollPosition = function () {
46
46
  }, [getScrollPosition]);
47
47
  return value;
48
48
  };
49
- /**
50
- * @category Hooks
49
+ /**
50
+ * @category Hooks
51
51
  */
52
52
  export const useScrollOffsetTop = function () {
53
53
  let {
@@ -69,8 +69,8 @@ export const useScrollOffsetTop = function () {
69
69
  }
70
70
  return 0;
71
71
  };
72
- /**
73
- * @category Hooks
72
+ /**
73
+ * @category Hooks
74
74
  */
75
75
  export const useScrollOffsetBottom = function () {
76
76
  let {
@@ -2,9 +2,9 @@ import { useEffect, useState } from "react";
2
2
  import { useContextSelector } from "use-context-selector";
3
3
  import { ChaynsFunctionsContext } from "../components/ChaynsContext";
4
4
 
5
- /**
6
- * @category Hooks
7
- * @deprecated Use {@link getAccessToken} instead
5
+ /**
6
+ * @category Hooks
7
+ * @deprecated Use {@link getAccessToken} instead
8
8
  */
9
9
  export const useAccessToken = accessToken => {
10
10
  const [token, setToken] = useState(null);
@@ -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);
@@ -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,28 +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 (failed) {
21
- throw new Error('failed to load component');
22
- }
23
- if (!system || !ready) {
24
- return null;
25
- }
26
- return /*#__PURE__*/React.lazy(loadComponent(system.scope, system.module, system.url, undefined, system.preventSingleton));
27
-
28
- /* eslint-disable react-hooks/exhaustive-deps */
29
- }, [system === null || system === void 0 ? void 0 : system.scope, ready, failed, system === null || system === void 0 ? void 0 : system.url]);
30
- 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, {
31
12
  fallback: fallback || ''
32
- }, /*#__PURE__*/React.createElement(Component, props)) : fallback;
13
+ }, /*#__PURE__*/React.createElement(Component, props));
33
14
  };
34
15
  const ModuleHost = _ref2 => {
35
16
  let {
@@ -76,6 +57,7 @@ const ModuleHost = _ref2 => {
76
57
  system: {
77
58
  scope: system.scope,
78
59
  url: replaceStagingUrl(preventStagingReplacement, system.url, environment.buildEnvironment),
60
+ serverUrl: replaceStagingUrl(preventStagingReplacement, system.serverUrl, environment.buildEnvironment),
79
61
  module: system.module,
80
62
  preventSingleton: system.preventSingleton
81
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;