chayns-api 1.0.1 → 1.0.2
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/dist/cjs/calls/dialogs/alert.js +0 -2
- package/dist/cjs/calls/dialogs/chaynsDialog.js +2 -8
- package/dist/cjs/calls/dialogs/close.js +0 -2
- package/dist/cjs/calls/dialogs/communication.js +1 -16
- package/dist/cjs/calls/dialogs/confirm.js +0 -4
- package/dist/cjs/calls/dialogs/date.js +36 -53
- package/dist/cjs/calls/dialogs/dropUpAlert.js +0 -3
- package/dist/cjs/calls/dialogs/fileSelect.js +0 -10
- package/dist/cjs/calls/dialogs/iFrame.js +0 -8
- package/dist/cjs/calls/dialogs/index.js +0 -27
- package/dist/cjs/calls/dialogs/input.js +0 -6
- package/dist/cjs/calls/dialogs/mediaSelect.js +0 -7
- package/dist/cjs/calls/dialogs/open.js +0 -2
- package/dist/cjs/calls/dialogs/select.js +0 -9
- package/dist/cjs/calls/dialogs/signature.js +0 -5
- package/dist/cjs/calls/dialogs/toast.js +0 -3
- package/dist/cjs/calls/dialogs/utils/callback.js +0 -2
- package/dist/cjs/calls/dialogs/utils/environment.js +10 -0
- package/dist/cjs/calls/dialogs/utils/is.js +0 -4
- package/dist/cjs/calls/getUserInfo.js +0 -11
- package/dist/cjs/calls/index.js +3 -155
- package/dist/cjs/calls/sendMessage.js +0 -26
- package/dist/cjs/calls/visibilityChangeListener.js +1 -12
- package/dist/cjs/components/ChaynsContext.js +2 -4
- package/dist/cjs/components/ChaynsProvider.js +6 -28
- package/dist/cjs/components/WaitUntil.js +0 -5
- package/dist/cjs/components/withCompatMode.js +1 -16
- package/dist/cjs/helper/apiListenerHelper.js +0 -9
- package/dist/cjs/hooks/geoLocationListener.js +2 -11
- package/dist/cjs/hooks/index.js +6 -16
- package/dist/cjs/hooks/scrollListener.js +4 -23
- package/dist/cjs/hooks/useAccessToken.js +0 -5
- package/dist/cjs/hooks/useCurrentPage.js +0 -4
- package/dist/cjs/hooks/useCustomData.js +0 -4
- package/dist/cjs/hooks/useDevice.js +0 -4
- package/dist/cjs/hooks/useEnvironment.js +0 -4
- package/dist/cjs/hooks/useFunctions.js +0 -4
- package/dist/cjs/hooks/useIsAdminMode.js +0 -5
- package/dist/cjs/hooks/useLanguage.js +0 -4
- package/dist/cjs/hooks/usePages.js +22 -14
- package/dist/cjs/hooks/useParameters.js +0 -4
- package/dist/cjs/hooks/useSite.js +0 -4
- package/dist/cjs/hooks/useUser.js +0 -5
- package/dist/cjs/hooks/useValues.js +0 -4
- package/dist/cjs/hooks/windowMetricsListener.js +2 -12
- package/dist/cjs/host/ChaynsHost.js +0 -10
- package/dist/cjs/host/iframe/HostIframe.js +23 -30
- package/dist/cjs/host/iframe/utils/useUpdateData.js +0 -3
- package/dist/cjs/host/module/ModuleHost.js +3 -13
- package/dist/cjs/host/{HostIframe.js → module/PagemakerFrame.js} +23 -75
- package/dist/cjs/host/module/utils/loadComponent.js +1 -18
- package/dist/cjs/host/module/utils/useDynamicScript.js +0 -18
- package/dist/cjs/index.js +0 -19
- package/dist/cjs/types/IChaynsReact.js +27 -48
- package/dist/cjs/util/appCall.js +1 -4
- package/dist/cjs/util/deviceHelper.js +4 -21
- package/dist/cjs/util/heightHelper.js +0 -9
- package/dist/cjs/util/postIframeForm.js +0 -5
- package/dist/cjs/wrapper/AppWrapper.js +318 -159
- package/dist/cjs/wrapper/FrameWrapper.js +215 -248
- package/dist/cjs/wrapper/ModuleFederationWrapper.js +2 -27
- package/dist/cjs/wrapper/SsrWrapper.js +0 -8
- package/dist/esm/calls/dialogs/alert.js +4 -4
- package/dist/esm/calls/dialogs/chaynsDialog.js +7 -11
- package/dist/esm/calls/dialogs/communication.js +15 -26
- package/dist/esm/calls/dialogs/confirm.js +5 -8
- package/dist/esm/calls/dialogs/date.js +85 -94
- package/dist/esm/calls/dialogs/dropUpAlert.js +1 -1
- package/dist/esm/calls/dialogs/fileSelect.js +23 -62
- package/dist/esm/calls/dialogs/iFrame.js +7 -10
- package/dist/esm/calls/dialogs/input.js +2 -5
- package/dist/esm/calls/dialogs/mediaSelect.js +18 -55
- package/dist/esm/calls/dialogs/open.js +2 -2
- package/dist/esm/calls/dialogs/select.js +5 -9
- package/dist/esm/calls/dialogs/signature.js +0 -2
- package/dist/esm/calls/dialogs/toast.js +6 -11
- package/dist/esm/calls/dialogs/utils/callback.js +3 -5
- package/dist/esm/calls/dialogs/utils/environment.js +3 -0
- package/dist/esm/calls/dialogs/utils/is.js +1 -3
- package/dist/esm/calls/getUserInfo.js +32 -92
- package/dist/esm/calls/index.js +124 -276
- package/dist/esm/calls/sendMessage.js +91 -221
- package/dist/esm/calls/visibilityChangeListener.js +10 -15
- package/dist/esm/components/ChaynsContext.js +3 -3
- package/dist/esm/components/ChaynsProvider.js +45 -86
- package/dist/esm/components/WaitUntil.js +21 -86
- package/dist/esm/components/withCompatMode.js +35 -77
- package/dist/esm/helper/apiListenerHelper.js +10 -15
- package/dist/esm/hooks/geoLocationListener.js +20 -46
- package/dist/esm/hooks/index.js +1 -1
- package/dist/esm/hooks/scrollListener.js +50 -86
- package/dist/esm/hooks/useAccessToken.js +6 -28
- package/dist/esm/hooks/useCurrentPage.js +2 -6
- package/dist/esm/hooks/useCustomData.js +2 -6
- package/dist/esm/hooks/useDevice.js +1 -6
- package/dist/esm/hooks/useEnvironment.js +1 -6
- package/dist/esm/hooks/useFunctions.js +2 -5
- package/dist/esm/hooks/useIsAdminMode.js +2 -6
- package/dist/esm/hooks/useLanguage.js +1 -6
- package/dist/esm/hooks/usePages.js +34 -27
- package/dist/esm/hooks/useParameters.js +1 -6
- package/dist/esm/hooks/useSite.js +1 -6
- package/dist/esm/hooks/useUser.js +1 -7
- package/dist/esm/hooks/useValues.js +2 -5
- package/dist/esm/hooks/windowMetricsListener.js +18 -44
- package/dist/esm/host/ChaynsHost.js +22 -29
- package/dist/esm/host/iframe/HostIframe.js +86 -142
- package/dist/esm/host/iframe/utils/useUpdateData.js +4 -6
- package/dist/esm/host/module/ModuleHost.js +42 -49
- package/dist/esm/host/module/PagemakerFrame.js +97 -0
- package/dist/esm/host/module/utils/loadComponent.js +47 -85
- package/dist/esm/host/module/utils/useDynamicScript.js +27 -74
- package/dist/esm/types/IChaynsReact.js +37 -61
- package/dist/esm/util/appCall.js +2 -4
- package/dist/esm/util/deviceHelper.js +12 -36
- package/dist/esm/util/heightHelper.js +10 -13
- package/dist/esm/util/postIframeForm.js +25 -57
- package/dist/esm/wrapper/AppWrapper.js +380 -781
- package/dist/esm/wrapper/FrameWrapper.js +258 -1509
- package/dist/esm/wrapper/ModuleFederationWrapper.js +47 -284
- package/dist/esm/wrapper/SsrWrapper.js +19 -65
- package/dist/types/calls/dialogs/confirm.d.ts +1 -1
- package/dist/types/calls/dialogs/date.d.ts +4 -4
- package/dist/types/calls/dialogs/dropUpAlert.d.ts +1 -1
- package/dist/types/calls/dialogs/fileSelect.d.ts +1 -1
- package/dist/types/calls/dialogs/iFrame.d.ts +1 -1
- package/dist/types/calls/dialogs/input.d.ts +1 -1
- package/dist/types/calls/dialogs/mediaSelect.d.ts +1 -1
- package/dist/types/calls/dialogs/signature.d.ts +1 -1
- package/dist/types/calls/dialogs/utils/environment.d.ts +3 -0
- package/dist/types/calls/index.d.ts +0 -6
- package/dist/types/components/ChaynsProvider.d.ts +1 -1
- package/dist/types/components/WaitUntil.d.ts +1 -1
- package/dist/types/components/withCompatMode.d.ts +1 -1
- package/dist/types/hooks/index.d.ts +1 -1
- package/dist/types/hooks/useAccessToken.d.ts +1 -1
- package/dist/types/hooks/usePages.d.ts +4 -0
- package/dist/types/host/ChaynsHost.d.ts +1 -1
- package/dist/types/host/iframe/HostIframe.d.ts +1 -1
- package/dist/types/host/module/ModuleHost.d.ts +2 -2
- package/dist/types/host/{HostIframe.d.ts → module/PagemakerFrame.d.ts} +7 -5
- package/dist/types/types/IChaynsReact.d.ts +55 -24
- package/dist/types/util/deviceHelper.d.ts +2 -2
- package/dist/types/wrapper/AppWrapper.d.ts +6 -4
- package/package.json +1 -1
- package/dist/cjs/bootstrap.js +0 -11
- package/dist/cjs/calls/abstractApiListener.js +0 -40
- package/dist/cjs/calls/apiEventListener.js +0 -40
- package/dist/cjs/calls/setVisibilityChangeListener.js +0 -1
- package/dist/cjs/calls/windowMetricsListener.js +0 -18
- package/dist/cjs/components/App.js +0 -32
- package/dist/cjs/components/App.spec.js +0 -16
- package/dist/cjs/components/Button.js +0 -32
- package/dist/cjs/components/ChaynsProviderExposed.js +0 -16
- package/dist/cjs/components/TestProvider.js +0 -236
- package/dist/cjs/components/Title.js +0 -162
- package/dist/cjs/functions/addApiListener.js +0 -37
- package/dist/cjs/functions/addGeoLocationListener.js +0 -26
- package/dist/cjs/functions/addScrollListener.js +0 -26
- package/dist/cjs/functions/addWindowMetricsListener.js +0 -37
- package/dist/cjs/helper/cssLoader.js +0 -28
- package/dist/cjs/hooks/addGeoLocationListener.js +0 -26
- package/dist/cjs/hooks/addScrollListener.js +0 -26
- package/dist/cjs/hooks/addWindowMetricsListener.js +0 -37
- package/dist/cjs/hooks/geoLocation.js +0 -48
- package/dist/cjs/hooks/useAddGeoLocationListener.js +0 -26
- package/dist/cjs/hooks/useAddScrollListener.js +0 -48
- package/dist/cjs/hooks/useAddWindowMetricsListener.js +0 -45
- package/dist/cjs/hooks/useAdddScrollListener.js +0 -26
- package/dist/cjs/hooks/windowMetrics.js +0 -45
- package/dist/cjs/host/ModuleHost.js +0 -11
- package/dist/cjs/host/module/utils.js +0 -25
- package/dist/cjs/index.example.js +0 -7
- package/dist/cjs/index2.js +0 -64
- package/dist/cjs/types/DynamicImport.d.js +0 -5
- package/dist/cjs/types/chayns-components.d.js +0 -1
- package/dist/cjs/types/chayns-logger.d.js +0 -1
- package/dist/cjs/types/chayns.d.js +0 -1
- package/dist/cjs/types/tobit-websocket-service-client.d.js +0 -1
- package/dist/cjs/types/toolkit-types.d.js +0 -1
- package/dist/cjs/util/useFunctionsContext.js +0 -16
- package/dist/cjs/util/useIsAdminMode.js +0 -18
- package/dist/cjs/util/useUser.js +0 -16
- package/dist/esm/bootstrap.js +0 -4
- package/dist/esm/components/App.js +0 -35
- package/dist/esm/components/App.spec.js +0 -9
- package/dist/esm/components/Button.js +0 -34
- package/dist/esm/components/ChaynsProviderExposed.js +0 -3
- package/dist/esm/components/TestProvider.js +0 -308
- package/dist/esm/components/Title.js +0 -210
- package/dist/esm/helper/cssLoader.js +0 -21
- package/dist/esm/hooks/useAddGeoLocationListener.js +0 -18
- package/dist/esm/hooks/useAddScrollListener.js +0 -18
- package/dist/esm/hooks/useAddWindowMetricsListener.js +0 -18
- package/dist/esm/host/HostIframe.js +0 -153
- package/dist/esm/index.example.js +0 -1
- package/dist/esm/index2.js +0 -5
- package/dist/esm/types/DynamicImport.d.js +0 -1
- package/dist/esm/types/chayns-components.d.js +0 -0
- package/dist/esm/types/chayns-logger.d.js +0 -0
- package/dist/esm/types/chayns.d.js +0 -0
- package/dist/esm/types/tobit-websocket-service-client.d.js +0 -0
- package/dist/esm/types/toolkit-types.d.js +0 -0
- package/dist/esm/util/useIsAdminMode.js +0 -9
- package/dist/esm/util/useUser.js +0 -7
- package/dist/types/bootstrap.d.ts +0 -1
- package/dist/types/components/App.d.ts +0 -5
- package/dist/types/components/Button.d.ts +0 -8
- package/dist/types/components/ChaynsProviderExposed.d.ts +0 -13
- package/dist/types/components/Title.d.ts +0 -3
- package/dist/types/index.example.d.ts +0 -0
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { useContextSelector } from 'use-context-selector';
|
|
2
2
|
import { ChaynsContext } from '../components/ChaynsContext';
|
|
3
|
-
|
|
4
3
|
/**
|
|
5
4
|
* @category Hooks
|
|
6
5
|
*/
|
|
7
|
-
export
|
|
8
|
-
return useContextSelector(ChaynsContext, function (v) {
|
|
9
|
-
return v === null || v === void 0 ? void 0 : v.environment;
|
|
10
|
-
});
|
|
11
|
-
};
|
|
6
|
+
export const useEnvironment = () => useContextSelector(ChaynsContext, v => v === null || v === void 0 ? void 0 : v.environment);
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { useContextSelector } from "use-context-selector";
|
|
2
2
|
import { ChaynsFunctionsContext } from "../components/ChaynsContext";
|
|
3
|
-
|
|
4
3
|
/**
|
|
5
4
|
* @category Hooks
|
|
6
5
|
*/
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
return f || {};
|
|
10
|
-
});
|
|
6
|
+
export const useFunctions = () => {
|
|
7
|
+
const t = useContextSelector(ChaynsFunctionsContext, f => f || {});
|
|
11
8
|
return t;
|
|
12
9
|
};
|
|
@@ -3,11 +3,7 @@ import { ChaynsContext } from '../components/ChaynsContext';
|
|
|
3
3
|
/**
|
|
4
4
|
* @category Hooks
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
export var useIsAdminMode = function useIsAdminMode() {
|
|
6
|
+
export const useIsAdminMode = () => {
|
|
8
7
|
var _useContextSelector;
|
|
9
|
-
|
|
10
|
-
return (_useContextSelector = useContextSelector(ChaynsContext, function (v) {
|
|
11
|
-
return v === null || v === void 0 ? void 0 : v.isAdminModeActive;
|
|
12
|
-
})) !== null && _useContextSelector !== void 0 ? _useContextSelector : false;
|
|
8
|
+
return (_useContextSelector = useContextSelector(ChaynsContext, v => v === null || v === void 0 ? void 0 : v.isAdminModeActive)) !== null && _useContextSelector !== void 0 ? _useContextSelector : false;
|
|
13
9
|
};
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { useContextSelector } from 'use-context-selector';
|
|
2
2
|
import { ChaynsContext } from '../components/ChaynsContext';
|
|
3
|
-
|
|
4
3
|
/**
|
|
5
4
|
* @category Hooks
|
|
6
5
|
*/
|
|
7
|
-
export
|
|
8
|
-
return useContextSelector(ChaynsContext, function (v) {
|
|
9
|
-
return v === null || v === void 0 ? void 0 : v.language;
|
|
10
|
-
});
|
|
11
|
-
};
|
|
6
|
+
export const useLanguage = () => useContextSelector(ChaynsContext, v => v === null || v === void 0 ? void 0 : v.language);
|
|
@@ -1,45 +1,52 @@
|
|
|
1
1
|
import { useContextSelector } from 'use-context-selector';
|
|
2
2
|
import { ChaynsContext } from '../components/ChaynsContext';
|
|
3
|
-
|
|
3
|
+
import { moduleWrapper } from "../components/ChaynsProvider";
|
|
4
4
|
/**
|
|
5
5
|
* @category Hooks
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
8
|
-
|
|
7
|
+
export const usePages = function () {
|
|
8
|
+
let {
|
|
9
|
+
siteId
|
|
10
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
9
11
|
siteId: undefined
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var pages = useContextSelector(ChaynsContext, function (v) {
|
|
14
|
-
return v.pages;
|
|
15
|
-
});
|
|
16
|
-
|
|
12
|
+
};
|
|
13
|
+
const pages = useContextSelector(ChaynsContext, v => v.pages);
|
|
17
14
|
if (siteId) {
|
|
18
|
-
pages.filter(
|
|
19
|
-
return tapp.siteId === siteId;
|
|
20
|
-
});
|
|
15
|
+
pages.filter(tapp => tapp.siteId === siteId);
|
|
21
16
|
}
|
|
22
|
-
|
|
23
17
|
return pages;
|
|
24
18
|
};
|
|
25
19
|
/**
|
|
26
20
|
* @category Hooks
|
|
27
21
|
*/
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
});
|
|
35
|
-
|
|
22
|
+
export const usePage = _ref => {
|
|
23
|
+
let {
|
|
24
|
+
id,
|
|
25
|
+
siteId
|
|
26
|
+
} = _ref;
|
|
27
|
+
const pages = useContextSelector(ChaynsContext, v => v.pages);
|
|
36
28
|
if (id) {
|
|
37
29
|
var _pages$find;
|
|
38
|
-
|
|
39
|
-
return (_pages$find = pages.find(function (x) {
|
|
40
|
-
return x.id === id && (!siteId || x.siteId === siteId);
|
|
41
|
-
})) !== null && _pages$find !== void 0 ? _pages$find : null;
|
|
30
|
+
return (_pages$find = pages.find(x => x.id === id && (!siteId || x.siteId === siteId))) !== null && _pages$find !== void 0 ? _pages$find : null;
|
|
42
31
|
}
|
|
43
|
-
|
|
44
32
|
return null;
|
|
33
|
+
};
|
|
34
|
+
export const getPage = function () {
|
|
35
|
+
var _pages$find3;
|
|
36
|
+
let {
|
|
37
|
+
id,
|
|
38
|
+
siteId
|
|
39
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
40
|
+
id: null,
|
|
41
|
+
siteId: null
|
|
42
|
+
};
|
|
43
|
+
const {
|
|
44
|
+
pages,
|
|
45
|
+
currentPage
|
|
46
|
+
} = moduleWrapper.current.values;
|
|
47
|
+
if (id) {
|
|
48
|
+
var _pages$find2;
|
|
49
|
+
return (_pages$find2 = pages.find(x => x.id === id && (!siteId || x.siteId === siteId))) !== null && _pages$find2 !== void 0 ? _pages$find2 : null;
|
|
50
|
+
}
|
|
51
|
+
return (_pages$find3 = pages.find(x => x.id === currentPage.id && x.siteId === currentPage.siteId || !x.siteId)) !== null && _pages$find3 !== void 0 ? _pages$find3 : null;
|
|
45
52
|
};
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { useContextSelector } from 'use-context-selector';
|
|
2
2
|
import { ChaynsContext } from '../components/ChaynsContext';
|
|
3
|
-
|
|
4
3
|
/**
|
|
5
4
|
* @category Hooks
|
|
6
5
|
*/
|
|
7
|
-
export
|
|
8
|
-
return useContextSelector(ChaynsContext, function (v) {
|
|
9
|
-
return (v === null || v === void 0 ? void 0 : v.parameters) || [];
|
|
10
|
-
});
|
|
11
|
-
};
|
|
6
|
+
export const useParameters = () => useContextSelector(ChaynsContext, v => (v === null || v === void 0 ? void 0 : v.parameters) || []);
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { useContextSelector } from 'use-context-selector';
|
|
2
2
|
import { ChaynsContext } from '../components/ChaynsContext';
|
|
3
|
-
|
|
4
3
|
/**
|
|
5
4
|
* @category Hooks
|
|
6
5
|
*/
|
|
7
|
-
export
|
|
8
|
-
return useContextSelector(ChaynsContext, function (v) {
|
|
9
|
-
return v === null || v === void 0 ? void 0 : v.site;
|
|
10
|
-
});
|
|
11
|
-
};
|
|
6
|
+
export const useSite = () => useContextSelector(ChaynsContext, v => v === null || v === void 0 ? void 0 : v.site);
|
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
import { useContextSelector } from 'use-context-selector';
|
|
2
2
|
import { ChaynsContext } from '../components/ChaynsContext';
|
|
3
|
-
|
|
4
3
|
/**
|
|
5
4
|
* @category Hooks
|
|
6
5
|
*/
|
|
7
|
-
|
|
8
|
-
export var useUser = function useUser() {
|
|
9
|
-
return useContextSelector(ChaynsContext, function (v) {
|
|
10
|
-
return (v === null || v === void 0 ? void 0 : v.user) || {};
|
|
11
|
-
});
|
|
12
|
-
};
|
|
6
|
+
export const useUser = () => useContextSelector(ChaynsContext, v => (v === null || v === void 0 ? void 0 : v.user) || {});
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { useContextSelector } from 'use-context-selector';
|
|
2
2
|
import { ChaynsContext } from '../components/ChaynsContext';
|
|
3
|
-
|
|
4
3
|
/**
|
|
5
4
|
* @category Hooks
|
|
6
5
|
*/
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
return v || {};
|
|
10
|
-
});
|
|
6
|
+
export const useValues = () => {
|
|
7
|
+
const t = useContextSelector(ChaynsContext, v => v || {});
|
|
11
8
|
return t;
|
|
12
9
|
};
|
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
-
|
|
3
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
-
|
|
5
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6
|
-
|
|
7
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
8
|
-
|
|
9
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
10
|
-
|
|
11
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
|
-
|
|
13
1
|
import { useContextSelector } from 'use-context-selector';
|
|
14
2
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
15
3
|
import { ChaynsFunctionsContext } from '../components/ChaynsContext';
|
|
@@ -17,34 +5,27 @@ import { ScreenSize } from '../types/IChaynsReact';
|
|
|
17
5
|
/**
|
|
18
6
|
* @category Hooks
|
|
19
7
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
var removeListener = useContextSelector(ChaynsFunctionsContext, function (v) {
|
|
26
|
-
return v.removeWindowMetricsListener;
|
|
27
|
-
});
|
|
28
|
-
var promiseRef = useRef();
|
|
29
|
-
return useCallback(function (callback) {
|
|
8
|
+
export const useWindowMetricsListener = () => {
|
|
9
|
+
const addListener = useContextSelector(ChaynsFunctionsContext, v => v.addWindowMetricsListener);
|
|
10
|
+
const removeListener = useContextSelector(ChaynsFunctionsContext, v => v.removeWindowMetricsListener);
|
|
11
|
+
const promiseRef = useRef();
|
|
12
|
+
return useCallback(callback => {
|
|
30
13
|
promiseRef.current = addListener(callback);
|
|
31
|
-
return
|
|
14
|
+
return () => {
|
|
32
15
|
var _promiseRef$current;
|
|
33
|
-
|
|
34
16
|
void ((_promiseRef$current = promiseRef.current) === null || _promiseRef$current === void 0 ? void 0 : _promiseRef$current.then(removeListener));
|
|
35
|
-
};
|
|
17
|
+
};
|
|
18
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
36
19
|
}, []);
|
|
37
20
|
};
|
|
38
21
|
/**
|
|
39
22
|
* @category Hooks
|
|
40
23
|
*/
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
var _useState = useState({
|
|
24
|
+
export const useWindowMetrics = function () {
|
|
25
|
+
let {
|
|
26
|
+
enabled = true
|
|
27
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
28
|
+
const [value, setValue] = useState({
|
|
48
29
|
bottomBarHeight: 0,
|
|
49
30
|
offsetTop: 0,
|
|
50
31
|
pageHeight: 0,
|
|
@@ -52,25 +33,18 @@ export var useWindowMetrics = function useWindowMetrics() {
|
|
|
52
33
|
topBarHeight: 0,
|
|
53
34
|
windowHeight: 0,
|
|
54
35
|
pageSize: ScreenSize.XS
|
|
55
|
-
}),
|
|
56
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
57
|
-
value = _useState2[0],
|
|
58
|
-
setValue = _useState2[1];
|
|
59
|
-
|
|
60
|
-
var addListener = useWindowMetricsListener();
|
|
61
|
-
var getWindowMetrics = useContextSelector(ChaynsFunctionsContext, function (v) {
|
|
62
|
-
return v.getWindowMetrics;
|
|
63
36
|
});
|
|
64
|
-
|
|
37
|
+
const addListener = useWindowMetricsListener();
|
|
38
|
+
const getWindowMetrics = useContextSelector(ChaynsFunctionsContext, v => v.getWindowMetrics);
|
|
39
|
+
useEffect(() => {
|
|
65
40
|
if (enabled) {
|
|
66
|
-
return addListener(
|
|
41
|
+
return addListener(v => {
|
|
67
42
|
setValue(v);
|
|
68
43
|
});
|
|
69
44
|
}
|
|
70
|
-
|
|
71
45
|
return undefined;
|
|
72
46
|
}, [enabled, addListener]);
|
|
73
|
-
useEffect(
|
|
47
|
+
useEffect(() => {
|
|
74
48
|
void getWindowMetrics().then(setValue);
|
|
75
49
|
}, [getWindowMetrics]);
|
|
76
50
|
return value;
|
|
@@ -1,30 +1,28 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import HostIframe from './iframe/HostIframe';
|
|
3
3
|
import ModuleHost from './module/ModuleHost';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
environment = _ref.environment;
|
|
27
|
-
|
|
4
|
+
const ChaynsHost = _ref => {
|
|
5
|
+
let {
|
|
6
|
+
type,
|
|
7
|
+
iFrameProps,
|
|
8
|
+
functions,
|
|
9
|
+
src,
|
|
10
|
+
iFrameRef = undefined,
|
|
11
|
+
loadingComponent = undefined,
|
|
12
|
+
children = undefined,
|
|
13
|
+
system,
|
|
14
|
+
// shallow data
|
|
15
|
+
pages,
|
|
16
|
+
language,
|
|
17
|
+
isAdminModeActive,
|
|
18
|
+
site,
|
|
19
|
+
user,
|
|
20
|
+
currentPage,
|
|
21
|
+
device,
|
|
22
|
+
parameters,
|
|
23
|
+
customData,
|
|
24
|
+
environment
|
|
25
|
+
} = _ref;
|
|
28
26
|
switch (type) {
|
|
29
27
|
case 'client-iframe':
|
|
30
28
|
return /*#__PURE__*/React.createElement(HostIframe, {
|
|
@@ -43,7 +41,6 @@ var ChaynsHost = function ChaynsHost(_ref) {
|
|
|
43
41
|
environment: environment,
|
|
44
42
|
customData: customData
|
|
45
43
|
});
|
|
46
|
-
|
|
47
44
|
case 'client-module':
|
|
48
45
|
return /*#__PURE__*/React.createElement(ModuleHost, {
|
|
49
46
|
system: system,
|
|
@@ -60,7 +57,6 @@ var ChaynsHost = function ChaynsHost(_ref) {
|
|
|
60
57
|
customData: customData,
|
|
61
58
|
environment: environment
|
|
62
59
|
});
|
|
63
|
-
|
|
64
60
|
case 'server-iframe':
|
|
65
61
|
return /*#__PURE__*/React.createElement(HostIframe, {
|
|
66
62
|
iFrameRef: iFrameRef,
|
|
@@ -79,7 +75,6 @@ var ChaynsHost = function ChaynsHost(_ref) {
|
|
|
79
75
|
environment: environment,
|
|
80
76
|
customData: customData
|
|
81
77
|
});
|
|
82
|
-
|
|
83
78
|
case 'server-module':
|
|
84
79
|
return /*#__PURE__*/React.createElement(ModuleHost, {
|
|
85
80
|
system: system,
|
|
@@ -95,10 +90,8 @@ var ChaynsHost = function ChaynsHost(_ref) {
|
|
|
95
90
|
customData: customData,
|
|
96
91
|
environment: environment
|
|
97
92
|
}, children);
|
|
98
|
-
|
|
99
93
|
default:
|
|
100
94
|
return null;
|
|
101
95
|
}
|
|
102
96
|
};
|
|
103
|
-
|
|
104
97
|
export default ChaynsHost;
|
|
@@ -1,158 +1,103 @@
|
|
|
1
|
-
function _extends() { _extends = Object.assign
|
|
2
|
-
|
|
3
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
-
|
|
5
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
6
|
-
|
|
7
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
|
-
|
|
9
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
10
|
-
|
|
11
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
12
|
-
|
|
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); }
|
|
13
2
|
import React, { useEffect, useRef } from 'react';
|
|
14
3
|
import * as comlink from 'comlink';
|
|
15
4
|
import postIframeForm from '../../util/postIframeForm';
|
|
16
5
|
import useUpdateData from './utils/useUpdateData';
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
var currentDataRef = useRef();
|
|
40
|
-
|
|
6
|
+
const HostIframe = _ref => {
|
|
7
|
+
let {
|
|
8
|
+
iFrameProps,
|
|
9
|
+
src,
|
|
10
|
+
postForm = false,
|
|
11
|
+
iFrameRef,
|
|
12
|
+
// shallow data
|
|
13
|
+
pages,
|
|
14
|
+
isAdminModeActive,
|
|
15
|
+
site,
|
|
16
|
+
user,
|
|
17
|
+
currentPage,
|
|
18
|
+
functions,
|
|
19
|
+
device,
|
|
20
|
+
language,
|
|
21
|
+
parameters,
|
|
22
|
+
environment,
|
|
23
|
+
customData
|
|
24
|
+
} = _ref;
|
|
25
|
+
const eventTarget = useRef();
|
|
26
|
+
const ref = useRef();
|
|
27
|
+
const currentDataRef = useRef();
|
|
41
28
|
if (!eventTarget.current) {
|
|
42
29
|
eventTarget.current = global.document ? document.createElement('div') : undefined; // global.EventTarget ? new EventTarget() : undefined
|
|
43
30
|
}
|
|
44
31
|
|
|
45
|
-
|
|
46
|
-
if (
|
|
47
|
-
|
|
32
|
+
const setHeight = value => {
|
|
33
|
+
if (ref.current) {
|
|
34
|
+
ref.current.height = `${value}px`;
|
|
48
35
|
}
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
site
|
|
54
|
-
isAdminModeActive
|
|
55
|
-
pages
|
|
56
|
-
currentPage
|
|
57
|
-
device
|
|
58
|
-
user
|
|
59
|
-
language
|
|
60
|
-
parameters
|
|
61
|
-
environment
|
|
62
|
-
customData
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
_context.t1 = _yield$functions$getA = _context.sent;
|
|
85
|
-
_context.t0 = _context.t1 !== null;
|
|
86
|
-
|
|
87
|
-
if (!_context.t0) {
|
|
88
|
-
_context.next = 7;
|
|
89
|
-
break;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
_context.t0 = _yield$functions$getA !== void 0;
|
|
93
|
-
|
|
94
|
-
case 7:
|
|
95
|
-
if (!_context.t0) {
|
|
96
|
-
_context.next = 11;
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
_context.t2 = _yield$functions$getA;
|
|
101
|
-
_context.next = 12;
|
|
102
|
-
break;
|
|
103
|
-
|
|
104
|
-
case 11:
|
|
105
|
-
_context.t2 = {};
|
|
106
|
-
|
|
107
|
-
case 12:
|
|
108
|
-
accessToken = _context.t2;
|
|
109
|
-
void postIframeForm(src, JSON.stringify(_objectSpread(_objectSpread({}, initialData), {}, {
|
|
110
|
-
pages: undefined
|
|
111
|
-
}, accessToken)), 'chayns', iFrameProps.name);
|
|
112
|
-
|
|
113
|
-
case 14:
|
|
114
|
-
case "end":
|
|
115
|
-
return _context.stop();
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}, _callee);
|
|
119
|
-
}))(); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// region initialData
|
|
39
|
+
const initialData = {
|
|
40
|
+
site,
|
|
41
|
+
isAdminModeActive,
|
|
42
|
+
pages,
|
|
43
|
+
currentPage,
|
|
44
|
+
device,
|
|
45
|
+
user,
|
|
46
|
+
language,
|
|
47
|
+
parameters,
|
|
48
|
+
environment,
|
|
49
|
+
customData
|
|
50
|
+
};
|
|
51
|
+
// endregion
|
|
52
|
+
|
|
53
|
+
currentDataRef.current = initialData;
|
|
54
|
+
|
|
55
|
+
// region postIframeForm
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
(async () => {
|
|
58
|
+
if (postForm) {
|
|
59
|
+
var _await$functions$getA;
|
|
60
|
+
const accessToken = (_await$functions$getA = await functions.getAccessToken()) !== null && _await$functions$getA !== void 0 ? _await$functions$getA : {};
|
|
61
|
+
void postIframeForm(src, JSON.stringify({
|
|
62
|
+
...initialData,
|
|
63
|
+
pages: undefined,
|
|
64
|
+
...accessToken
|
|
65
|
+
}), 'chayns', iFrameProps.name);
|
|
66
|
+
}
|
|
67
|
+
})();
|
|
68
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
69
|
+
}, []);
|
|
70
|
+
// endregion
|
|
120
71
|
|
|
121
|
-
}, []); // endregion
|
|
122
72
|
// region expose data and functions to iframe
|
|
123
|
-
|
|
124
|
-
useEffect(function () {
|
|
73
|
+
useEffect(() => {
|
|
125
74
|
var _ref$current;
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
getInitialData: function getInitialData() {
|
|
138
|
-
return currentDataRef.current;
|
|
75
|
+
if ((_ref$current = ref.current) !== null && _ref$current !== void 0 && _ref$current.contentWindow) {
|
|
76
|
+
const obj = {
|
|
77
|
+
[iFrameProps.name]: {
|
|
78
|
+
functions: {
|
|
79
|
+
...functions,
|
|
80
|
+
setHeight
|
|
81
|
+
},
|
|
82
|
+
addDataListener: cb => {
|
|
83
|
+
if (eventTarget.current) eventTarget.current.addEventListener('data_update', e => e.detail && cb(e.detail));
|
|
84
|
+
},
|
|
85
|
+
getInitialData: () => currentDataRef.current
|
|
139
86
|
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
return function () {
|
|
87
|
+
};
|
|
88
|
+
comlink.expose(obj, comlink.windowEndpoint(ref.current.contentWindow));
|
|
89
|
+
ref.current.contentWindow.postMessage('chayns-api-host-ready', '*');
|
|
90
|
+
// https://github.com/GoogleChromeLabs/comlink/pull/469 might be better approach once released
|
|
91
|
+
return () => {
|
|
148
92
|
delete obj[iFrameProps.name];
|
|
149
93
|
};
|
|
150
94
|
}
|
|
95
|
+
return undefined;
|
|
96
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
97
|
+
}, []);
|
|
98
|
+
// endregion
|
|
151
99
|
|
|
152
|
-
return undefined; // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
153
|
-
}, []); // endregion
|
|
154
100
|
// region dispatch data update
|
|
155
|
-
|
|
156
101
|
useUpdateData(eventTarget.current, 'isAdminModeActive', isAdminModeActive);
|
|
157
102
|
useUpdateData(eventTarget.current, 'user', user);
|
|
158
103
|
useUpdateData(eventTarget.current, 'site', site);
|
|
@@ -160,12 +105,12 @@ var HostIframe = function HostIframe(_ref) {
|
|
|
160
105
|
useUpdateData(eventTarget.current, 'language', language);
|
|
161
106
|
useUpdateData(eventTarget.current, 'parameters', parameters);
|
|
162
107
|
useUpdateData(eventTarget.current, 'environment', environment);
|
|
163
|
-
useUpdateData(eventTarget.current, 'customData', customData);
|
|
108
|
+
useUpdateData(eventTarget.current, 'customData', customData);
|
|
109
|
+
// endregion
|
|
164
110
|
|
|
165
111
|
return /*#__PURE__*/React.createElement("iframe", _extends({
|
|
166
|
-
ref:
|
|
167
|
-
|
|
168
|
-
|
|
112
|
+
ref: r => {
|
|
113
|
+
ref.current = r;
|
|
169
114
|
if (iFrameRef) {
|
|
170
115
|
// eslint-disable-next-line no-param-reassign
|
|
171
116
|
iFrameRef.current = r;
|
|
@@ -176,5 +121,4 @@ var HostIframe = function HostIframe(_ref) {
|
|
|
176
121
|
src: postForm ? undefined : src
|
|
177
122
|
}));
|
|
178
123
|
};
|
|
179
|
-
|
|
180
124
|
export default HostIframe;
|