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.
- package/.babelrc +30 -30
- package/.eslintrc +17 -17
- package/.github/workflows/deploy_docs.yml +28 -28
- package/.github/workflows/publish.yml +21 -21
- package/LICENSE +21 -21
- package/README.md +54 -54
- package/dist/cjs/calls/dialogs/date.js +34 -34
- package/dist/cjs/calls/index.js +108 -108
- package/dist/cjs/calls/sendMessage.js +8 -8
- package/dist/cjs/calls/visibilityChangeListener.js +4 -4
- package/dist/cjs/components/AppDialogWrapper.js +2 -2
- package/dist/cjs/components/ChaynsProvider.js +1 -1
- package/dist/cjs/components/ErrorBoundary.js +1 -1
- package/dist/cjs/components/withCompatMode.js +2 -2
- package/dist/cjs/components/withHydrationBoundary.js +54 -0
- package/dist/cjs/constants/hydrationContext.js +16 -0
- package/dist/cjs/constants/index.js +16 -0
- package/dist/cjs/hooks/geoLocationListener.js +4 -4
- package/dist/cjs/hooks/scrollListener.js +8 -8
- package/dist/cjs/hooks/useAccessToken.js +3 -3
- package/dist/cjs/hooks/useCurrentPage.js +2 -2
- package/dist/cjs/hooks/useCustomData.js +2 -2
- package/dist/cjs/hooks/useDevice.js +2 -2
- package/dist/cjs/hooks/useDialogState.js +4 -4
- package/dist/cjs/hooks/useEnvironment.js +2 -2
- package/dist/cjs/hooks/useFunctions.js +2 -2
- package/dist/cjs/hooks/useIsAdminMode.js +2 -2
- package/dist/cjs/hooks/useLanguage.js +2 -2
- package/dist/cjs/hooks/usePages.js +4 -4
- package/dist/cjs/hooks/useParameters.js +2 -2
- package/dist/cjs/hooks/useSite.js +2 -2
- package/dist/cjs/hooks/useUser.js +2 -2
- package/dist/cjs/hooks/useValues.js +2 -2
- package/dist/cjs/hooks/windowMetricsListener.js +4 -4
- package/dist/cjs/host/ChaynsHost.js +21 -40
- package/dist/cjs/host/iframe/HostIframe.js +2 -2
- package/dist/cjs/host/module/ModuleHost.js +5 -23
- package/dist/cjs/host/module/utils/loadComponent.js +98 -53
- package/dist/cjs/host/module/utils/useDynamicScript.js +7 -5
- package/dist/cjs/index.js +36 -1
- package/dist/cjs/types/IChaynsReact.js +4 -4
- package/dist/cjs/util/heightHelper.js +1 -1
- package/dist/cjs/util/url.js +1 -1
- package/dist/cjs/wrapper/AppWrapper.js +6 -6
- package/dist/cjs/wrapper/FrameWrapper.js +1 -1
- package/dist/cjs/wrapper/ModuleFederationWrapper.js +1 -1
- package/dist/esm/calls/dialogs/date.js +34 -34
- package/dist/esm/calls/index.js +108 -108
- package/dist/esm/calls/sendMessage.js +8 -8
- package/dist/esm/calls/visibilityChangeListener.js +4 -4
- package/dist/esm/components/AppDialogWrapper.js +1 -1
- package/dist/esm/components/withCompatMode.js +1 -1
- package/dist/esm/components/withHydrationBoundary.js +47 -0
- package/dist/esm/constants/hydrationContext.js +10 -0
- package/dist/esm/constants/index.js +1 -0
- package/dist/esm/handler/DialogHandler.js +1 -1
- package/dist/esm/hooks/geoLocationListener.js +4 -4
- package/dist/esm/hooks/scrollListener.js +8 -8
- package/dist/esm/hooks/useAccessToken.js +3 -3
- package/dist/esm/hooks/useCurrentPage.js +2 -2
- package/dist/esm/hooks/useCustomData.js +2 -2
- package/dist/esm/hooks/useDevice.js +2 -2
- package/dist/esm/hooks/useDialogState.js +4 -4
- package/dist/esm/hooks/useEnvironment.js +2 -2
- package/dist/esm/hooks/useFunctions.js +2 -2
- package/dist/esm/hooks/useIsAdminMode.js +2 -2
- package/dist/esm/hooks/useLanguage.js +2 -2
- package/dist/esm/hooks/usePages.js +4 -4
- package/dist/esm/hooks/useParameters.js +2 -2
- package/dist/esm/hooks/useSite.js +2 -2
- package/dist/esm/hooks/useUser.js +2 -2
- package/dist/esm/hooks/useValues.js +2 -2
- package/dist/esm/hooks/windowMetricsListener.js +4 -4
- package/dist/esm/host/ChaynsHost.js +18 -39
- package/dist/esm/host/iframe/HostIframe.js +1 -1
- package/dist/esm/host/module/ModuleHost.js +4 -22
- package/dist/esm/host/module/utils/loadComponent.js +99 -53
- package/dist/esm/index.js +3 -0
- package/dist/esm/types/IChaynsReact.js +4 -4
- package/dist/esm/util/url.js +2 -2
- package/dist/esm/wrapper/AppWrapper.js +6 -6
- package/dist/esm/wrapper/FrameWrapper.js +1 -1
- package/dist/esm/wrapper/StaticChaynsApi.js +1 -1
- package/dist/types/calls/dialogs/alert.d.ts +1 -1
- package/dist/types/calls/dialogs/chaynsDialog.d.ts +24 -24
- package/dist/types/calls/dialogs/close.d.ts +1 -1
- package/dist/types/calls/dialogs/communication.d.ts +3 -3
- package/dist/types/calls/dialogs/confirm.d.ts +13 -13
- package/dist/types/calls/dialogs/date.d.ts +96 -96
- package/dist/types/calls/dialogs/dropUpAlert.d.ts +5 -5
- package/dist/types/calls/dialogs/fileSelect.d.ts +16 -16
- package/dist/types/calls/dialogs/iFrame.d.ts +10 -10
- package/dist/types/calls/dialogs/index.d.ts +14 -14
- package/dist/types/calls/dialogs/input.d.ts +15 -15
- package/dist/types/calls/dialogs/mediaSelect.d.ts +8 -8
- package/dist/types/calls/dialogs/open.d.ts +1 -1
- package/dist/types/calls/dialogs/select.d.ts +6 -6
- package/dist/types/calls/dialogs/signature.d.ts +7 -7
- package/dist/types/calls/dialogs/toast.d.ts +1 -1
- package/dist/types/calls/dialogs/utils/callback.d.ts +1 -1
- package/dist/types/calls/dialogs/utils/is.d.ts +4 -4
- package/dist/types/calls/getUserInfo.d.ts +9 -9
- package/dist/types/calls/index.d.ts +255 -255
- package/dist/types/calls/sendMessage.d.ts +13 -13
- package/dist/types/calls/visibilityChangeListener.d.ts +9 -9
- package/dist/types/components/AppDialogWrapper.d.ts +5 -5
- package/dist/types/components/ChaynsContext.d.ts +3 -3
- package/dist/types/components/ChaynsProvider.d.ts +11 -11
- package/dist/types/components/ErrorBoundary.d.ts +13 -13
- package/dist/types/components/WaitUntil.d.ts +7 -7
- package/dist/types/components/moduleWrapper.d.ts +4 -4
- package/dist/types/components/withCompatMode.d.ts +13 -13
- package/dist/types/components/withHydrationBoundary.d.ts +17 -0
- package/dist/types/constants/hydrationContext.d.ts +9 -0
- package/dist/types/constants/index.d.ts +1 -0
- package/dist/types/constants/languages.d.ts +12 -12
- package/dist/types/handler/DialogHandler.d.ts +24 -24
- package/dist/types/helper/apiListenerHelper.d.ts +6 -6
- package/dist/types/hooks/geoLocationListener.d.ts +18 -18
- package/dist/types/hooks/index.d.ts +17 -17
- package/dist/types/hooks/scrollListener.d.ts +28 -28
- package/dist/types/hooks/useAccessToken.d.ts +6 -6
- package/dist/types/hooks/useCurrentPage.d.ts +7 -4
- package/dist/types/hooks/useCustomData.d.ts +4 -4
- package/dist/types/hooks/useDevice.d.ts +5 -5
- package/dist/types/hooks/useDialogState.d.ts +9 -9
- package/dist/types/hooks/useEnvironment.d.ts +5 -5
- package/dist/types/hooks/useFunctions.d.ts +5 -5
- package/dist/types/hooks/useIsAdminMode.d.ts +4 -4
- package/dist/types/hooks/useLanguage.d.ts +5 -5
- package/dist/types/hooks/usePages.d.ts +18 -18
- package/dist/types/hooks/useParameters.d.ts +5 -5
- package/dist/types/hooks/useSite.d.ts +5 -5
- package/dist/types/hooks/useUser.d.ts +5 -5
- package/dist/types/hooks/useValues.d.ts +5 -5
- package/dist/types/hooks/windowMetricsListener.d.ts +11 -11
- package/dist/types/host/ChaynsHost.d.ts +29 -30
- package/dist/types/host/iframe/HostIframe.d.ts +26 -26
- package/dist/types/host/iframe/utils/useUpdateData.d.ts +3 -3
- package/dist/types/host/module/ModuleHost.d.ts +28 -27
- package/dist/types/host/module/utils/loadComponent.d.ts +3 -1
- package/dist/types/host/module/utils/useDynamicScript.d.ts +9 -9
- package/dist/types/index.d.ts +23 -20
- package/dist/types/types/IChaynsReact.d.ts +860 -860
- package/dist/types/types/dialog.d.ts +41 -41
- package/dist/types/util/appCall.d.ts +2 -2
- package/dist/types/util/deviceHelper.d.ts +7 -7
- package/dist/types/util/heightHelper.d.ts +1 -1
- package/dist/types/util/is.d.ts +5 -5
- package/dist/types/util/postIframeForm.d.ts +1 -1
- package/dist/types/util/transferNestedFunctions.d.ts +1 -1
- package/dist/types/util/url.d.ts +1 -1
- package/dist/types/wrapper/AppWrapper.d.ts +19 -19
- package/dist/types/wrapper/FrameWrapper.d.ts +15 -15
- package/dist/types/wrapper/ModuleFederationWrapper.d.ts +10 -10
- package/dist/types/wrapper/SsrWrapper.d.ts +11 -11
- package/dist/types/wrapper/StaticChaynsApi.d.ts +16 -16
- package/package.json +87 -79
- package/toolkit.config.js +20 -20
- package/tsconfig.json +56 -56
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function _extends() {
|
|
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(
|
|
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,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() {
|
|
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
|
-
|
|
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))
|
|
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
|
-
|
|
2
|
-
|
|
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 {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
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.
|
|
95
|
+
default: Module.default.Component
|
|
54
96
|
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
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;
|