chayns-api 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +30 -0
- package/.eslintrc +17 -0
- package/.github/workflows/deploy_docs.yml +28 -0
- package/LICENSE +21 -0
- package/README.md +47 -0
- package/dist/cjs/calls/dialogs/alert.js +19 -0
- package/dist/cjs/calls/dialogs/chaynsDialog.js +59 -0
- package/dist/cjs/calls/dialogs/close.js +13 -0
- package/dist/cjs/calls/dialogs/communication.js +71 -0
- package/dist/cjs/calls/dialogs/confirm.js +33 -0
- package/dist/cjs/calls/dialogs/date.js +187 -0
- package/dist/cjs/calls/dialogs/dropUpAlert.js +12 -0
- package/dist/cjs/calls/dialogs/fileSelect.js +39 -0
- package/dist/cjs/calls/dialogs/iFrame.js +43 -0
- package/dist/cjs/calls/dialogs/index.js +178 -0
- package/dist/cjs/calls/dialogs/input.js +33 -0
- package/dist/cjs/calls/dialogs/mediaSelect.js +27 -0
- package/dist/cjs/calls/dialogs/open.js +19 -0
- package/dist/cjs/calls/dialogs/select.js +55 -0
- package/dist/cjs/calls/dialogs/signature.js +24 -0
- package/dist/cjs/calls/dialogs/toast.js +18 -0
- package/dist/cjs/calls/dialogs/utils/callback.js +12 -0
- package/dist/cjs/calls/dialogs/utils/environment.js +10 -0
- package/dist/cjs/calls/dialogs/utils/is.js +21 -0
- package/dist/cjs/calls/getUserInfo.js +40 -0
- package/dist/cjs/calls/index.js +300 -0
- package/dist/cjs/calls/sendMessage.js +120 -0
- package/dist/cjs/calls/visibilityChangeListener.js +38 -0
- package/dist/cjs/client.js +93 -0
- package/dist/cjs/components/ChaynsContext.js +12 -0
- package/dist/cjs/components/ChaynsModuleProvider.js +457 -0
- package/dist/cjs/components/ChaynsProvider.js +116 -0
- package/dist/cjs/components/WaitUntil.js +31 -0
- package/dist/cjs/components/withCompatMode.js +55 -0
- package/dist/cjs/helper/apiListenerHelper.js +34 -0
- package/dist/cjs/hooks/geoLocationListener.js +50 -0
- package/dist/cjs/hooks/index.js +153 -0
- package/dist/cjs/hooks/scrollListener.js +102 -0
- package/dist/cjs/hooks/useAccessToken.js +28 -0
- package/dist/cjs/hooks/useCurrentPage.js +13 -0
- package/dist/cjs/hooks/useCustomData.js +13 -0
- package/dist/cjs/hooks/useDevice.js +13 -0
- package/dist/cjs/hooks/useEnvironment.js +13 -0
- package/dist/cjs/hooks/useFunctions.js +16 -0
- package/dist/cjs/hooks/useIsAdminMode.js +16 -0
- package/dist/cjs/hooks/useLanguage.js +13 -0
- package/dist/cjs/hooks/usePages.js +38 -0
- package/dist/cjs/hooks/useParameters.js +13 -0
- package/dist/cjs/hooks/useSite.js +13 -0
- package/dist/cjs/hooks/useUser.js +14 -0
- package/dist/cjs/hooks/useValues.js +16 -0
- package/dist/cjs/hooks/windowMetricsListener.js +58 -0
- package/dist/cjs/host/ChaynsHost.js +102 -0
- package/dist/cjs/host/iframe/HostIframe.js +133 -0
- package/dist/cjs/host/iframe/utils/useUpdateData.js +21 -0
- package/dist/cjs/host/module/ModuleHost.js +82 -0
- package/dist/cjs/host/module/PagemakerFrame.js +105 -0
- package/dist/cjs/host/module/utils/loadComponent.js +61 -0
- package/dist/cjs/host/module/utils/useDynamicScript.js +61 -0
- package/dist/cjs/index.js +117 -0
- package/dist/cjs/types/DynamicApiImport.d.js +5 -0
- package/dist/cjs/types/IChaynsReact.js +235 -0
- package/dist/cjs/types/dialog.js +5 -0
- package/dist/cjs/util/appCall.js +23 -0
- package/dist/cjs/util/deviceHelper.js +71 -0
- package/dist/cjs/util/heightHelper.js +40 -0
- package/dist/cjs/util/postIframeForm.js +32 -0
- package/dist/cjs/wrapper/AppWrapper.js +244 -0
- package/dist/cjs/wrapper/FrameWrapper.js +288 -0
- package/dist/cjs/wrapper/ModuleFederationWrapper.js +61 -0
- package/dist/cjs/wrapper/SsrWrapper.js +30 -0
- package/dist/esm/calls/dialogs/alert.js +15 -0
- package/dist/esm/calls/dialogs/chaynsDialog.js +48 -0
- package/dist/esm/calls/dialogs/close.js +7 -0
- package/dist/esm/calls/dialogs/communication.js +66 -0
- package/dist/esm/calls/dialogs/confirm.js +30 -0
- package/dist/esm/calls/dialogs/date.js +211 -0
- package/dist/esm/calls/dialogs/dropUpAlert.js +7 -0
- package/dist/esm/calls/dialogs/fileSelect.js +32 -0
- package/dist/esm/calls/dialogs/iFrame.js +37 -0
- package/dist/esm/calls/dialogs/index.js +14 -0
- package/dist/esm/calls/dialogs/input.js +26 -0
- package/dist/esm/calls/dialogs/mediaSelect.js +22 -0
- package/dist/esm/calls/dialogs/open.js +13 -0
- package/dist/esm/calls/dialogs/select.js +47 -0
- package/dist/esm/calls/dialogs/signature.js +18 -0
- package/dist/esm/calls/dialogs/toast.js +13 -0
- package/dist/esm/calls/dialogs/utils/callback.js +7 -0
- package/dist/esm/calls/dialogs/utils/environment.js +3 -0
- package/dist/esm/calls/dialogs/utils/is.js +12 -0
- package/dist/esm/calls/getUserInfo.js +33 -0
- package/dist/esm/calls/index.js +323 -0
- package/dist/esm/calls/sendMessage.js +111 -0
- package/dist/esm/calls/visibilityChangeListener.js +30 -0
- package/dist/esm/client.js +8 -0
- package/dist/esm/components/ChaynsContext.js +4 -0
- package/dist/esm/components/ChaynsModuleProvider.js +517 -0
- package/dist/esm/components/ChaynsProvider.js +109 -0
- package/dist/esm/components/WaitUntil.js +25 -0
- package/dist/esm/components/withCompatMode.js +47 -0
- package/dist/esm/helper/apiListenerHelper.js +25 -0
- package/dist/esm/hooks/geoLocationListener.js +43 -0
- package/dist/esm/hooks/index.js +16 -0
- package/dist/esm/hooks/scrollListener.js +95 -0
- package/dist/esm/hooks/useAccessToken.js +22 -0
- package/dist/esm/hooks/useCurrentPage.js +7 -0
- package/dist/esm/hooks/useCustomData.js +7 -0
- package/dist/esm/hooks/useDevice.js +6 -0
- package/dist/esm/hooks/useEnvironment.js +6 -0
- package/dist/esm/hooks/useFunctions.js +9 -0
- package/dist/esm/hooks/useIsAdminMode.js +9 -0
- package/dist/esm/hooks/useLanguage.js +6 -0
- package/dist/esm/hooks/usePages.js +32 -0
- package/dist/esm/hooks/useParameters.js +6 -0
- package/dist/esm/hooks/useSite.js +6 -0
- package/dist/esm/hooks/useUser.js +7 -0
- package/dist/esm/hooks/useValues.js +9 -0
- package/dist/esm/hooks/windowMetricsListener.js +51 -0
- package/dist/esm/host/ChaynsHost.js +95 -0
- package/dist/esm/host/iframe/HostIframe.js +124 -0
- package/dist/esm/host/iframe/utils/useUpdateData.js +14 -0
- package/dist/esm/host/module/ModuleHost.js +74 -0
- package/dist/esm/host/module/PagemakerFrame.js +97 -0
- package/dist/esm/host/module/utils/loadComponent.js +55 -0
- package/dist/esm/host/module/utils/useDynamicScript.js +50 -0
- package/dist/esm/index.js +16 -0
- package/dist/esm/types/DynamicApiImport.d.js +1 -0
- package/dist/esm/types/IChaynsReact.js +215 -0
- package/dist/esm/types/dialog.js +1 -0
- package/dist/esm/util/appCall.js +16 -0
- package/dist/esm/util/deviceHelper.js +62 -0
- package/dist/esm/util/heightHelper.js +32 -0
- package/dist/esm/util/postIframeForm.js +26 -0
- package/dist/esm/wrapper/AppWrapper.js +241 -0
- package/dist/esm/wrapper/FrameWrapper.js +279 -0
- package/dist/esm/wrapper/ModuleFederationWrapper.js +56 -0
- package/dist/esm/wrapper/SsrWrapper.js +23 -0
- package/dist/types/calls/dialogs/alert.d.ts +1 -0
- package/dist/types/calls/dialogs/chaynsDialog.d.ts +24 -0
- package/dist/types/calls/dialogs/close.d.ts +1 -0
- package/dist/types/calls/dialogs/communication.d.ts +3 -0
- package/dist/types/calls/dialogs/confirm.d.ts +13 -0
- package/dist/types/calls/dialogs/date.d.ts +96 -0
- package/dist/types/calls/dialogs/dropUpAlert.d.ts +5 -0
- package/dist/types/calls/dialogs/fileSelect.d.ts +16 -0
- package/dist/types/calls/dialogs/iFrame.d.ts +10 -0
- package/dist/types/calls/dialogs/index.d.ts +14 -0
- package/dist/types/calls/dialogs/input.d.ts +15 -0
- package/dist/types/calls/dialogs/mediaSelect.d.ts +8 -0
- package/dist/types/calls/dialogs/open.d.ts +1 -0
- package/dist/types/calls/dialogs/select.d.ts +6 -0
- package/dist/types/calls/dialogs/signature.d.ts +7 -0
- package/dist/types/calls/dialogs/toast.d.ts +1 -0
- package/dist/types/calls/dialogs/utils/callback.d.ts +1 -0
- package/dist/types/calls/dialogs/utils/environment.d.ts +3 -0
- package/dist/types/calls/dialogs/utils/is.d.ts +4 -0
- package/dist/types/calls/getUserInfo.d.ts +9 -0
- package/dist/types/calls/index.d.ts +231 -0
- package/dist/types/calls/sendMessage.d.ts +13 -0
- package/dist/types/calls/visibilityChangeListener.d.ts +9 -0
- package/dist/types/client.d.ts +7 -0
- package/dist/types/components/ChaynsContext.d.ts +3 -0
- package/dist/types/components/ChaynsModuleProvider.d.ts +170 -0
- package/dist/types/components/ChaynsProvider.d.ts +13 -0
- package/dist/types/components/WaitUntil.d.ts +7 -0
- package/dist/types/components/withCompatMode.d.ts +13 -0
- package/dist/types/helper/apiListenerHelper.d.ts +6 -0
- package/dist/types/hooks/geoLocationListener.d.ts +18 -0
- package/dist/types/hooks/index.d.ts +16 -0
- package/dist/types/hooks/scrollListener.d.ts +28 -0
- package/dist/types/hooks/useAccessToken.d.ts +5 -0
- package/dist/types/hooks/useCurrentPage.d.ts +4 -0
- package/dist/types/hooks/useCustomData.d.ts +4 -0
- package/dist/types/hooks/useDevice.d.ts +5 -0
- package/dist/types/hooks/useEnvironment.d.ts +5 -0
- package/dist/types/hooks/useFunctions.d.ts +5 -0
- package/dist/types/hooks/useIsAdminMode.d.ts +4 -0
- package/dist/types/hooks/useLanguage.d.ts +5 -0
- package/dist/types/hooks/usePages.d.ts +14 -0
- package/dist/types/hooks/useParameters.d.ts +5 -0
- package/dist/types/hooks/useSite.d.ts +5 -0
- package/dist/types/hooks/useUser.d.ts +5 -0
- package/dist/types/hooks/useValues.d.ts +5 -0
- package/dist/types/hooks/windowMetricsListener.d.ts +11 -0
- package/dist/types/host/ChaynsHost.d.ts +27 -0
- package/dist/types/host/iframe/HostIframe.d.ts +24 -0
- package/dist/types/host/iframe/utils/useUpdateData.d.ts +3 -0
- package/dist/types/host/module/ModuleHost.d.ts +23 -0
- package/dist/types/host/module/PagemakerFrame.d.ts +22 -0
- package/dist/types/host/module/utils/loadComponent.d.ts +1 -0
- package/dist/types/host/module/utils/useDynamicScript.d.ts +9 -0
- package/dist/types/index.d.ts +16 -0
- package/dist/types/types/IChaynsReact.d.ts +590 -0
- package/dist/types/types/dialog.d.ts +41 -0
- package/dist/types/util/appCall.d.ts +2 -0
- package/dist/types/util/deviceHelper.d.ts +7 -0
- package/dist/types/util/heightHelper.d.ts +1 -0
- package/dist/types/util/postIframeForm.d.ts +1 -0
- package/dist/types/wrapper/AppWrapper.d.ts +16 -0
- package/dist/types/wrapper/FrameWrapper.d.ts +15 -0
- package/dist/types/wrapper/ModuleFederationWrapper.d.ts +10 -0
- package/dist/types/wrapper/SsrWrapper.d.ts +11 -0
- package/package.json +76 -0
- package/toolkit.config.js +52 -0
- package/tsconfig.json +56 -0
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.FrameWrapper = void 0;
|
|
7
|
+
var comlink = _interopRequireWildcard(require("comlink"));
|
|
8
|
+
var _visibilityChangeListener = require("../calls/visibilityChangeListener");
|
|
9
|
+
var _apiListenerHelper = require("../helper/apiListenerHelper");
|
|
10
|
+
var _getUserInfo = _interopRequireDefault(require("../calls/getUserInfo"));
|
|
11
|
+
var _sendMessage = require("../calls/sendMessage");
|
|
12
|
+
var _heightHelper = require("../util/heightHelper");
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
15
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
16
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
17
|
+
|
|
18
|
+
class FrameWrapper {
|
|
19
|
+
resolve = null;
|
|
20
|
+
exposedFunctions = null;
|
|
21
|
+
resizeListener = null;
|
|
22
|
+
ready = new Promise(res => {
|
|
23
|
+
this.resolve = res;
|
|
24
|
+
});
|
|
25
|
+
values = null;
|
|
26
|
+
functions = {
|
|
27
|
+
addGeoLocationListener: async (value, callback) => {
|
|
28
|
+
if (!this.initialized) await this.ready;
|
|
29
|
+
return this.exposedFunctions.addGeoLocationListener(value, callback && comlink.proxy(result => callback(result)));
|
|
30
|
+
},
|
|
31
|
+
addScrollListener: async (value, callback) => {
|
|
32
|
+
if (!this.initialized) await this.ready;
|
|
33
|
+
return this.exposedFunctions.addScrollListener(value, callback && comlink.proxy(result => callback(result)));
|
|
34
|
+
},
|
|
35
|
+
addVisibilityChangeListener: async callback => (0, _visibilityChangeListener.addVisibilityChangeListener)(callback),
|
|
36
|
+
addWindowMetricsListener: async callback => {
|
|
37
|
+
if (!this.initialized) await this.ready;
|
|
38
|
+
const {
|
|
39
|
+
id,
|
|
40
|
+
shouldInitialize
|
|
41
|
+
} = (0, _apiListenerHelper.addApiListener)('windowMetricsListener', callback);
|
|
42
|
+
if (shouldInitialize) {
|
|
43
|
+
void this.exposedFunctions.addWindowMetricsListener(comlink.proxy(result => {
|
|
44
|
+
(0, _apiListenerHelper.dispatchApiEvent)('windowMetricsListener', result);
|
|
45
|
+
}));
|
|
46
|
+
window.addEventListener('resize', this.resizeListener = () => {
|
|
47
|
+
void (async () => {
|
|
48
|
+
const metrics = await this.exposedFunctions.getWindowMetrics();
|
|
49
|
+
(0, _apiListenerHelper.dispatchApiEvent)('windowMetricsListener', metrics);
|
|
50
|
+
})();
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return id;
|
|
54
|
+
},
|
|
55
|
+
customCallbackFunction: async (type, data) => {
|
|
56
|
+
if (!this.initialized) await this.ready;
|
|
57
|
+
return this.exposedFunctions.customCallbackFunction(type, data);
|
|
58
|
+
},
|
|
59
|
+
getAvailableSharingServices: async () => {
|
|
60
|
+
if (!this.initialized) await this.ready;
|
|
61
|
+
return this.exposedFunctions.getAvailableSharingServices();
|
|
62
|
+
},
|
|
63
|
+
getAccessToken: async accessToken => {
|
|
64
|
+
if (!this.initialized) await this.ready;
|
|
65
|
+
return this.exposedFunctions.getAccessToken(accessToken);
|
|
66
|
+
},
|
|
67
|
+
getGeoLocation: async value => {
|
|
68
|
+
if (!this.initialized) await this.ready;
|
|
69
|
+
return this.exposedFunctions.getGeoLocation(value);
|
|
70
|
+
},
|
|
71
|
+
getUserInfo: async query => {
|
|
72
|
+
if (!this.initialized) await this.ready;
|
|
73
|
+
return (0, _getUserInfo.default)(this, query);
|
|
74
|
+
},
|
|
75
|
+
getScrollPosition: async () => {
|
|
76
|
+
if (!this.initialized) await this.ready;
|
|
77
|
+
return this.exposedFunctions.getScrollPosition();
|
|
78
|
+
},
|
|
79
|
+
getWindowMetrics: async () => {
|
|
80
|
+
if (!this.initialized) await this.ready;
|
|
81
|
+
return this.exposedFunctions.getWindowMetrics();
|
|
82
|
+
},
|
|
83
|
+
invokeCall: async (value, callback) => {
|
|
84
|
+
if (!this.initialized) await this.ready;
|
|
85
|
+
return this.exposedFunctions.invokeCall(value, callback && comlink.proxy(result => callback(result)));
|
|
86
|
+
},
|
|
87
|
+
invokeDialogCall: async (value, callback) => {
|
|
88
|
+
if (!this.initialized) await this.ready;
|
|
89
|
+
return this.exposedFunctions.invokeDialogCall(value, callback && comlink.proxy(result => callback(result)));
|
|
90
|
+
},
|
|
91
|
+
login: async (value, callback, closeCallback) => {
|
|
92
|
+
if (!this.initialized) await this.ready;
|
|
93
|
+
return this.exposedFunctions.login(value, callback && comlink.proxy(result => callback(result)), closeCallback && comlink.proxy(() => closeCallback()));
|
|
94
|
+
},
|
|
95
|
+
logout: async () => {
|
|
96
|
+
if (!this.initialized) await this.ready;
|
|
97
|
+
return this.exposedFunctions.logout();
|
|
98
|
+
},
|
|
99
|
+
navigateBack: async () => {
|
|
100
|
+
if (!this.initialized) await this.ready;
|
|
101
|
+
return this.exposedFunctions.navigateBack();
|
|
102
|
+
},
|
|
103
|
+
openImage: async value => {
|
|
104
|
+
if (!this.initialized) await this.ready;
|
|
105
|
+
return this.exposedFunctions.openImage(value);
|
|
106
|
+
},
|
|
107
|
+
openUrl: async value => {
|
|
108
|
+
if (!this.initialized) await this.ready;
|
|
109
|
+
return this.exposedFunctions.openUrl(value);
|
|
110
|
+
},
|
|
111
|
+
openVideo: async value => {
|
|
112
|
+
if (!this.initialized) await this.ready;
|
|
113
|
+
return this.exposedFunctions.openVideo(value);
|
|
114
|
+
},
|
|
115
|
+
refreshAccessToken: async () => {
|
|
116
|
+
if (!this.initialized) await this.ready;
|
|
117
|
+
return this.exposedFunctions.refreshAccessToken();
|
|
118
|
+
},
|
|
119
|
+
refreshData: async value => {
|
|
120
|
+
if (!this.initialized) await this.ready;
|
|
121
|
+
return this.exposedFunctions.refreshData(value);
|
|
122
|
+
},
|
|
123
|
+
removeGeoLocationListener: async id => {
|
|
124
|
+
if (!this.initialized) await this.ready;
|
|
125
|
+
return this.exposedFunctions.removeGeoLocationListener(id);
|
|
126
|
+
},
|
|
127
|
+
removeScrollListener: async id => {
|
|
128
|
+
if (!this.initialized) await this.ready;
|
|
129
|
+
return this.exposedFunctions.removeScrollListener(id);
|
|
130
|
+
},
|
|
131
|
+
removeVisibilityChangeListener(number) {
|
|
132
|
+
(0, _visibilityChangeListener.removeVisibilityChangeListener)(number);
|
|
133
|
+
return Promise.resolve();
|
|
134
|
+
},
|
|
135
|
+
removeWindowMetricsListener: async id => {
|
|
136
|
+
if (!this.initialized) await this.ready;
|
|
137
|
+
const shouldRemove = (0, _apiListenerHelper.removeApiListener)('windowMetricsListener', id);
|
|
138
|
+
if (shouldRemove) {
|
|
139
|
+
void this.exposedFunctions.removeWindowMetricsListener(id);
|
|
140
|
+
if (this.resizeListener) window.removeEventListener('resize', this.resizeListener);
|
|
141
|
+
this.resizeListener = null;
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
selectPage: async options => {
|
|
145
|
+
if (!this.initialized) await this.ready;
|
|
146
|
+
await this.exposedFunctions.selectPage(options);
|
|
147
|
+
},
|
|
148
|
+
scrollToY: async (position, duration) => {
|
|
149
|
+
if (!this.initialized) await this.ready;
|
|
150
|
+
await this.exposedFunctions.scrollToY(position, duration);
|
|
151
|
+
},
|
|
152
|
+
sendMessageToGroup: async (groupId, message) => {
|
|
153
|
+
if (!this.initialized) await this.ready;
|
|
154
|
+
return (0, _sendMessage.sendMessageToGroup)(this, message, groupId);
|
|
155
|
+
},
|
|
156
|
+
sendMessageToPage: async message => {
|
|
157
|
+
if (!this.initialized) await this.ready;
|
|
158
|
+
return (0, _sendMessage.sendMessageToPage)(this, message);
|
|
159
|
+
},
|
|
160
|
+
sendMessageToUser: async (userId, message) => {
|
|
161
|
+
if (!this.initialized) await this.ready;
|
|
162
|
+
return (0, _sendMessage.sendMessageToUser)(this, message, userId);
|
|
163
|
+
},
|
|
164
|
+
setAdminMode: async enabled => {
|
|
165
|
+
if (!this.initialized) await this.ready;
|
|
166
|
+
return this.exposedFunctions.setAdminMode(enabled);
|
|
167
|
+
},
|
|
168
|
+
setDisplayTimeout: async value => {
|
|
169
|
+
if (!this.initialized) await this.ready;
|
|
170
|
+
return this.exposedFunctions.setDisplayTimeout(value);
|
|
171
|
+
},
|
|
172
|
+
setFloatingButton: async (value, callback) => {
|
|
173
|
+
var _value$items;
|
|
174
|
+
if (!this.initialized) await this.ready;
|
|
175
|
+
value.items = (_value$items = value.items) !== null && _value$items !== void 0 ? _value$items : [];
|
|
176
|
+
const itemClickFunctions = value.items.map(x => x.onClick);
|
|
177
|
+
value.items = value.items.map(x => ({
|
|
178
|
+
...x,
|
|
179
|
+
onClick: undefined
|
|
180
|
+
}));
|
|
181
|
+
const cb = callback && comlink.proxy(data => {
|
|
182
|
+
if (data !== null && data !== void 0 && data.item && itemClickFunctions[data.index]) {
|
|
183
|
+
itemClickFunctions[data.index]();
|
|
184
|
+
} else {
|
|
185
|
+
callback();
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
// @ts-ignore
|
|
189
|
+
return this.exposedFunctions.setFloatingButton(value, cb);
|
|
190
|
+
},
|
|
191
|
+
setHeight: async value => {
|
|
192
|
+
if (!this.initialized) await this.ready;
|
|
193
|
+
return this.exposedFunctions.setHeight(value);
|
|
194
|
+
},
|
|
195
|
+
setOverlay: async (value, callback) => {
|
|
196
|
+
if (!this.initialized) await this.ready;
|
|
197
|
+
return this.exposedFunctions.setOverlay(value, callback && comlink.proxy(() => callback()));
|
|
198
|
+
},
|
|
199
|
+
setRefreshScrollEnabled: async enabled => {
|
|
200
|
+
if (!this.initialized) await this.ready;
|
|
201
|
+
return this.exposedFunctions.setRefreshScrollEnabled(enabled);
|
|
202
|
+
},
|
|
203
|
+
setScanQrCode: async value => {
|
|
204
|
+
if (!this.initialized) await this.ready;
|
|
205
|
+
return this.exposedFunctions.setScanQrCode(value !== null && value !== void 0 ? value : {
|
|
206
|
+
cancel: false
|
|
207
|
+
});
|
|
208
|
+
},
|
|
209
|
+
setTempDesignSettings: async value => {
|
|
210
|
+
if (!this.initialized) await this.ready;
|
|
211
|
+
return this.exposedFunctions.setTempDesignSettings(value);
|
|
212
|
+
},
|
|
213
|
+
setWaitCursor: async value => {
|
|
214
|
+
if (!this.initialized) await this.ready;
|
|
215
|
+
return this.exposedFunctions.setWaitCursor(value);
|
|
216
|
+
},
|
|
217
|
+
storageGetItem: async (key, accessMode) => {
|
|
218
|
+
if (!this.initialized) await this.ready;
|
|
219
|
+
return this.exposedFunctions.storageGetItem(key, accessMode);
|
|
220
|
+
},
|
|
221
|
+
storageRemoveItem: async (key, accessMode) => {
|
|
222
|
+
if (!this.initialized) await this.ready;
|
|
223
|
+
return this.exposedFunctions.storageRemoveItem(key, accessMode);
|
|
224
|
+
},
|
|
225
|
+
storageSetItem: async (key, value, accessMode, tappIds) => {
|
|
226
|
+
if (!this.initialized) await this.ready;
|
|
227
|
+
return this.exposedFunctions.storageSetItem(key, value, accessMode, tappIds);
|
|
228
|
+
},
|
|
229
|
+
vibrate: async value => {
|
|
230
|
+
if (!this.initialized) await this.ready;
|
|
231
|
+
return this.exposedFunctions.vibrate(value);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
initialized = false;
|
|
235
|
+
constructor() {
|
|
236
|
+
const initialDataTag = document.querySelector('#__CHAYNS_DATA__');
|
|
237
|
+
if (initialDataTag) {
|
|
238
|
+
this.values = JSON.parse(initialDataTag.innerHTML);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
async init() {
|
|
242
|
+
if (this.initialized) return;
|
|
243
|
+
const exposed = comlink.wrap(comlink.windowEndpoint(window.parent))[window.name];
|
|
244
|
+
const dataListener = () => exposed.addDataListener(comlink.proxy(({
|
|
245
|
+
type,
|
|
246
|
+
value
|
|
247
|
+
}) => {
|
|
248
|
+
if (this.initialized) {
|
|
249
|
+
this.values[type] = value;
|
|
250
|
+
}
|
|
251
|
+
this.values[type] = value;
|
|
252
|
+
document.dispatchEvent(new CustomEvent('chayns_api_data', {
|
|
253
|
+
detail: {
|
|
254
|
+
type,
|
|
255
|
+
value
|
|
256
|
+
}
|
|
257
|
+
}));
|
|
258
|
+
}));
|
|
259
|
+
let hostReadyCallback = null;
|
|
260
|
+
await Promise.race([dataListener(), new Promise(resolve => {
|
|
261
|
+
window.addEventListener('message', hostReadyCallback = ev => {
|
|
262
|
+
if (ev.data === 'chayns-api-host-ready') {
|
|
263
|
+
void dataListener().then(resolve);
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
})]);
|
|
267
|
+
if (hostReadyCallback) window.removeEventListener('message', hostReadyCallback);
|
|
268
|
+
this.values = await exposed.getInitialData();
|
|
269
|
+
this.exposedFunctions = exposed.functions;
|
|
270
|
+
this.initialized = true;
|
|
271
|
+
this.resolve(null);
|
|
272
|
+
(0, _heightHelper.setTappHeight)(this.functions.setHeight);
|
|
273
|
+
}
|
|
274
|
+
addDataListener(cb) {
|
|
275
|
+
const listener = ev => ev.detail && cb(ev.detail);
|
|
276
|
+
document.addEventListener('chayns_api_data', listener);
|
|
277
|
+
return () => {
|
|
278
|
+
document.removeEventListener('chayns_api_data', listener);
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
getSSRData() {
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
getInitialData() {
|
|
285
|
+
return this.values;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
exports.FrameWrapper = FrameWrapper;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ModuleFederationWrapper = void 0;
|
|
7
|
+
var _visibilityChangeListener = require("../calls/visibilityChangeListener");
|
|
8
|
+
var _apiListenerHelper = require("../helper/apiListenerHelper");
|
|
9
|
+
var _getUserInfo = _interopRequireDefault(require("../calls/getUserInfo"));
|
|
10
|
+
var _sendMessage = require("../calls/sendMessage");
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
class ModuleFederationWrapper {
|
|
13
|
+
constructor(values, functions) {
|
|
14
|
+
this.values = values;
|
|
15
|
+
this.functions = {};
|
|
16
|
+
this.functions.addVisibilityChangeListener = async callback => (0, _visibilityChangeListener.addVisibilityChangeListener)(callback);
|
|
17
|
+
this.functions.removeVisibilityChangeListener = async id => (0, _visibilityChangeListener.removeVisibilityChangeListener)(id);
|
|
18
|
+
this.functions.getUserInfo = async query => (0, _getUserInfo.default)(this, query);
|
|
19
|
+
this.functions.sendMessageToGroup = async (groupId, object) => (0, _sendMessage.sendMessageToGroup)(this, object, groupId);
|
|
20
|
+
this.functions.sendMessageToPage = async object => (0, _sendMessage.sendMessageToPage)(this, object);
|
|
21
|
+
this.functions.sendMessageToUser = async (userId, object) => (0, _sendMessage.sendMessageToUser)(this, object, userId);
|
|
22
|
+
// make all functions async to be consistent with frame wrapper
|
|
23
|
+
Object.entries(functions).forEach(([k, fn]) => {
|
|
24
|
+
// eslint-disable-next-line
|
|
25
|
+
this.functions[k] = async (...args) => fn(...args);
|
|
26
|
+
});
|
|
27
|
+
this.functions.addWindowMetricsListener = async callback => {
|
|
28
|
+
const {
|
|
29
|
+
id,
|
|
30
|
+
shouldInitialize
|
|
31
|
+
} = (0, _apiListenerHelper.addApiListener)('windowMetrics', callback);
|
|
32
|
+
if (shouldInitialize) {
|
|
33
|
+
void functions.addWindowMetricsListener(value => (0, _apiListenerHelper.dispatchApiEvent)('windowMetrics', value));
|
|
34
|
+
}
|
|
35
|
+
return id;
|
|
36
|
+
};
|
|
37
|
+
this.functions.removeWindowMetricsListener = async id => {
|
|
38
|
+
const shouldRemove = (0, _apiListenerHelper.removeApiListener)('windowMetrics', id);
|
|
39
|
+
if (shouldRemove) {
|
|
40
|
+
void functions.removeWindowMetricsListener(id);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
async init() {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
addDataListener(cb) {
|
|
48
|
+
const listener = ev => ev.detail && cb(ev.detail);
|
|
49
|
+
document.addEventListener('chayns_api_data', listener);
|
|
50
|
+
return () => {
|
|
51
|
+
document.removeEventListener('chayns_api_data', listener);
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
getSSRData() {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
getInitialData() {
|
|
58
|
+
return this.values;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.ModuleFederationWrapper = ModuleFederationWrapper;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.SsrWrapper = void 0;
|
|
7
|
+
class SsrWrapper {
|
|
8
|
+
constructor(values, functions) {
|
|
9
|
+
this.initialData = values;
|
|
10
|
+
this.values = values;
|
|
11
|
+
this.functions = functions;
|
|
12
|
+
}
|
|
13
|
+
async init() {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
addDataListener(cb) {
|
|
17
|
+
const listener = ev => ev.detail && cb(ev.detail);
|
|
18
|
+
document.addEventListener('chayns_api_data', listener);
|
|
19
|
+
return () => {
|
|
20
|
+
document.removeEventListener('chayns_api_data', listener);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
getSSRData() {
|
|
24
|
+
return this.initialData;
|
|
25
|
+
}
|
|
26
|
+
getInitialData() {
|
|
27
|
+
return this.values;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.SsrWrapper = SsrWrapper;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { buttonText, buttonType, chaynsDialog } from './chaynsDialog';
|
|
2
|
+
export function alert() {
|
|
3
|
+
let title = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
4
|
+
let message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
5
|
+
return chaynsDialog({
|
|
6
|
+
'dialog': {
|
|
7
|
+
title,
|
|
8
|
+
message,
|
|
9
|
+
'buttons': [{
|
|
10
|
+
'text': buttonText.OK,
|
|
11
|
+
'buttonType': buttonType.POSITIVE
|
|
12
|
+
}]
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { open } from './open';
|
|
2
|
+
import { getCallbackName } from './utils/callback';
|
|
3
|
+
export const buttonText = {
|
|
4
|
+
'YES': {
|
|
5
|
+
'de': 'Ja',
|
|
6
|
+
'en': 'Yes',
|
|
7
|
+
'nl': 'Ja'
|
|
8
|
+
}['de'] || 'Yes',
|
|
9
|
+
// TODO: Language
|
|
10
|
+
'NO': {
|
|
11
|
+
'de': 'Nein',
|
|
12
|
+
'en': 'No',
|
|
13
|
+
'nl': 'Nee'
|
|
14
|
+
}['de'] || 'No',
|
|
15
|
+
'OK': 'OK',
|
|
16
|
+
'CANCEL': {
|
|
17
|
+
'de': 'Abbrechen',
|
|
18
|
+
'en': 'Cancel',
|
|
19
|
+
'nl': 'Annuleren'
|
|
20
|
+
}['de'] || 'Cancel'
|
|
21
|
+
};
|
|
22
|
+
export const buttonType = {
|
|
23
|
+
'CANCEL': -1,
|
|
24
|
+
'NEGATIVE': 0,
|
|
25
|
+
'POSITIVE': 1
|
|
26
|
+
};
|
|
27
|
+
export const dialogAction = {
|
|
28
|
+
'ALERT_CONFIRM': 178,
|
|
29
|
+
'INPUT': 173,
|
|
30
|
+
'SELECT': 174,
|
|
31
|
+
'DATE': 175,
|
|
32
|
+
'ADVANCED_DATE': 176,
|
|
33
|
+
'DROP_UP_ALERT': 177,
|
|
34
|
+
'MEDIA_SELECT': 179,
|
|
35
|
+
'FILE_SELECT': 180,
|
|
36
|
+
'SIGNATURE': 181,
|
|
37
|
+
'IFRAME': 191
|
|
38
|
+
};
|
|
39
|
+
export function chaynsDialog(config) {
|
|
40
|
+
const callbackName = 'chaynsDialog';
|
|
41
|
+
config.callback = getCallbackName(callbackName);
|
|
42
|
+
if (config.dialog) {
|
|
43
|
+
config.dialog.callType = dialogAction.ALERT_CONFIRM;
|
|
44
|
+
// @ts-ignore
|
|
45
|
+
return open(config.dialog).then(data => Promise.resolve(data.selection ? data : data.buttonType));
|
|
46
|
+
}
|
|
47
|
+
return "unsupported";
|
|
48
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
|
|
3
|
+
import { invokeDialogCall } from "../index";
|
|
4
|
+
export function sendData(data, isApiEvent) {
|
|
5
|
+
return invokeDialogCall({
|
|
6
|
+
action: 218,
|
|
7
|
+
value: {
|
|
8
|
+
data,
|
|
9
|
+
isApiEvent
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
const listeners = [];
|
|
14
|
+
const apiListeners = [];
|
|
15
|
+
function _dialogDataListener() {
|
|
16
|
+
let e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
17
|
+
if (!e.data || !e.data.action && typeof e.data !== 'string') {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const messageObj = e.data.action ? e.data : JSON.parse(e.data.match(/(\{(?:.*)\})/)[0]);
|
|
21
|
+
if (messageObj.action === 218) {
|
|
22
|
+
const {
|
|
23
|
+
data
|
|
24
|
+
} = messageObj.value;
|
|
25
|
+
if (messageObj.value.isApiEvent) {
|
|
26
|
+
apiListeners.forEach(listener => {
|
|
27
|
+
listener(data);
|
|
28
|
+
});
|
|
29
|
+
} else {
|
|
30
|
+
listeners.forEach(listener => {
|
|
31
|
+
listener(data);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export function addDialogDataListener(callback) {
|
|
37
|
+
let getApiEvents = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
38
|
+
if (listeners.length === 0 || apiListeners.length === 0) {
|
|
39
|
+
window.addEventListener('message', _dialogDataListener);
|
|
40
|
+
}
|
|
41
|
+
if (getApiEvents) {
|
|
42
|
+
apiListeners.push(callback);
|
|
43
|
+
} else {
|
|
44
|
+
listeners.push(callback);
|
|
45
|
+
}
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
export function removeDialogDataListener(callback) {
|
|
49
|
+
let getApiEvents = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
50
|
+
let index;
|
|
51
|
+
if (getApiEvents) {
|
|
52
|
+
index = apiListeners.indexOf(callback);
|
|
53
|
+
if (index !== -1) {
|
|
54
|
+
apiListeners.splice(index, 1);
|
|
55
|
+
}
|
|
56
|
+
} else {
|
|
57
|
+
index = listeners.indexOf(callback);
|
|
58
|
+
if (index !== -1) {
|
|
59
|
+
listeners.splice(index, 1);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (listeners.length === 0 && apiListeners.length === 0) {
|
|
63
|
+
window.removeEventListener('message', _dialogDataListener);
|
|
64
|
+
}
|
|
65
|
+
return index !== -1;
|
|
66
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { buttonText, buttonType, chaynsDialog } from './chaynsDialog';
|
|
2
|
+
export function confirm() {
|
|
3
|
+
let title = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
4
|
+
let message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
5
|
+
let config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
6
|
+
// backward compatibility
|
|
7
|
+
if (Array.isArray(config)) {
|
|
8
|
+
config = {
|
|
9
|
+
'buttons': config
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
if (!config.buttons || !Array.isArray(config.buttons)) {
|
|
13
|
+
config.buttons = [{
|
|
14
|
+
'text': buttonText.YES,
|
|
15
|
+
'buttonType': buttonType.POSITIVE
|
|
16
|
+
}, {
|
|
17
|
+
'text': buttonText.NO,
|
|
18
|
+
'buttonType': buttonType.NEGATIVE
|
|
19
|
+
}];
|
|
20
|
+
}
|
|
21
|
+
return chaynsDialog({
|
|
22
|
+
'dialog': {
|
|
23
|
+
title,
|
|
24
|
+
message,
|
|
25
|
+
'buttons': config.buttons,
|
|
26
|
+
'links': config.links,
|
|
27
|
+
'select': config.select
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|