chayns-api 1.1.0-2 → 1.1.0-21
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/chayns-api.js +2 -0
- package/dist/chayns-api.js.LICENSE.txt +41 -0
- package/dist/cjs/calls/dialogs/chaynsDialog.js +3 -6
- package/dist/cjs/calls/dialogs/date.js +29 -2
- package/dist/cjs/calls/dialogs/fileSelect.js +1 -2
- package/dist/cjs/calls/dialogs/input.js +2 -3
- package/dist/cjs/calls/dialogs/select.js +2 -3
- package/dist/cjs/calls/getUserInfo.js +1 -2
- package/dist/cjs/calls/index.js +93 -82
- package/dist/cjs/calls/toolbarChangeListener.js +1 -0
- package/dist/cjs/components/AppDialogWrapper.js +7 -7
- package/dist/cjs/components/ChaynsContext.js +2 -4
- package/dist/cjs/components/ChaynsProvider.js +10 -13
- package/dist/cjs/components/ErrorBoundary.js +31 -0
- package/dist/cjs/components/moduleWrapper.js +9 -0
- package/dist/cjs/components/withCompatMode.js +8 -7
- 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/constants/languages.js +19 -0
- package/dist/cjs/handler/DialogHandler.js +4 -2
- package/dist/cjs/hooks/useAccessToken.js +1 -0
- package/dist/cjs/hooks/useDialogState.js +2 -2
- package/dist/cjs/hooks/usePages.js +2 -2
- package/dist/cjs/host/ChaynsHost.js +21 -41
- package/dist/cjs/host/iframe/HostIframe.js +4 -6
- package/dist/cjs/host/iframe/utils/useUpdateData.js +1 -2
- package/dist/cjs/host/module/ModuleHost.js +9 -24
- package/dist/cjs/host/module/Test3.js +141 -0
- package/dist/cjs/host/module/utils/loadComponent.js +94 -49
- package/dist/cjs/index.js +63 -5
- package/dist/cjs/types/IChaynsReact.js +140 -107
- package/dist/cjs/util/appCall.js +3 -4
- package/dist/cjs/util/deviceHelper.js +18 -13
- package/dist/cjs/util/transferNestedFunctions.js +39 -0
- package/dist/cjs/util/url.js +1 -1
- package/dist/cjs/wrapper/AppWrapper.js +79 -16
- package/dist/cjs/wrapper/FrameWrapper.js +16 -5
- package/dist/cjs/wrapper/StaticChaynsApi.js +22 -0
- package/dist/esm/calls/index.js +22 -1
- package/dist/esm/calls/toolbarChangeListener.js +0 -0
- package/dist/esm/components/AppDialogWrapper.js +4 -3
- package/dist/esm/components/ChaynsProvider.js +6 -7
- package/dist/esm/components/ErrorBoundary.js +23 -0
- package/dist/esm/components/moduleWrapper.js +3 -0
- package/dist/esm/components/withCompatMode.js +5 -4
- 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/constants/languages.js +13 -0
- package/dist/esm/handler/DialogHandler.js +6 -4
- package/dist/esm/hooks/useAccessToken.js +1 -0
- package/dist/esm/hooks/useDialogState.js +2 -2
- package/dist/esm/hooks/usePages.js +1 -1
- package/dist/esm/host/ChaynsHost.js +18 -39
- package/dist/esm/host/iframe/HostIframe.js +1 -2
- package/dist/esm/host/module/ModuleHost.js +6 -20
- package/dist/esm/host/module/Test3.js +135 -0
- package/dist/esm/host/module/utils/loadComponent.js +95 -49
- package/dist/esm/index.js +7 -1
- package/dist/esm/types/IChaynsReact.js +142 -87
- package/dist/esm/util/appCall.js +2 -2
- package/dist/esm/util/deviceHelper.js +17 -11
- package/dist/esm/util/transferNestedFunctions.js +35 -0
- package/dist/esm/util/url.js +2 -2
- package/dist/esm/wrapper/AppWrapper.js +80 -16
- package/dist/esm/wrapper/FrameWrapper.js +16 -5
- package/dist/esm/wrapper/StaticChaynsApi.js +20 -0
- package/dist/types/calls/index.d.ts +19 -5
- package/dist/types/calls/toolbarChangeListener.d.ts +0 -0
- package/dist/types/components/AppDialogWrapper.d.ts +2 -2
- package/dist/types/components/ChaynsProvider.d.ts +1 -4
- package/dist/types/components/ErrorBoundary.d.ts +13 -0
- package/dist/types/components/moduleWrapper.d.ts +4 -0
- 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 -0
- package/dist/types/handler/DialogHandler.d.ts +0 -1
- package/dist/types/hooks/useAccessToken.d.ts +1 -0
- package/dist/types/hooks/useCurrentPage.d.ts +4 -1
- package/dist/types/host/ChaynsHost.d.ts +0 -1
- package/dist/types/host/module/ModuleHost.d.ts +2 -0
- package/dist/types/host/module/Test3.d.ts +8 -0
- package/dist/types/host/module/utils/loadComponent.d.ts +3 -1
- package/dist/types/index.d.ts +7 -1
- package/dist/types/types/IChaynsReact.d.ts +136 -28
- package/dist/types/util/deviceHelper.d.ts +2 -2
- package/dist/types/util/transferNestedFunctions.d.ts +1 -0
- package/dist/types/wrapper/StaticChaynsApi.d.ts +9 -0
- package/package.json +33 -22
- package/toolkit.config.js +20 -0
|
@@ -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 === 'server-iframe' || type === 'server-module' && (system === null || system === void 0 ? 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
|
}
|
|
@@ -31,10 +31,9 @@ const HostIframe = _ref => {
|
|
|
31
31
|
if (!eventTarget.current) {
|
|
32
32
|
eventTarget.current = global.document ? document.createElement('div') : undefined; // global.EventTarget ? new EventTarget() : undefined
|
|
33
33
|
}
|
|
34
|
-
|
|
35
34
|
const setHeight = value => {
|
|
36
35
|
if (ref.current) {
|
|
37
|
-
ref.current.height = `${value}px`;
|
|
36
|
+
ref.current.style.height = `${value}px`;
|
|
38
37
|
}
|
|
39
38
|
};
|
|
40
39
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React, { useMemo } from 'react';
|
|
2
|
-
import useDynamicScript from './utils/useDynamicScript';
|
|
3
2
|
import loadComponent from './utils/loadComponent';
|
|
4
3
|
import { replaceStagingUrl } from "../../util/url";
|
|
5
4
|
const System = _ref => {
|
|
@@ -8,25 +7,10 @@ const System = _ref => {
|
|
|
8
7
|
fallback,
|
|
9
8
|
...props
|
|
10
9
|
} = _ref;
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
failed
|
|
14
|
-
} = useDynamicScript({
|
|
15
|
-
url: system === null || system === void 0 ? void 0 : system.url,
|
|
16
|
-
scope: system === null || system === void 0 ? void 0 : system.scope
|
|
17
|
-
});
|
|
18
|
-
const Component = useMemo(() => {
|
|
19
|
-
// maybe return waitcursor instead
|
|
20
|
-
if (!system || !ready || failed) {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
return /*#__PURE__*/React.lazy(loadComponent(system.scope, system.module, system.url));
|
|
24
|
-
|
|
25
|
-
/* eslint-disable react-hooks/exhaustive-deps */
|
|
26
|
-
}, [system === null || system === void 0 ? void 0 : system.scope, ready, system === null || system === void 0 ? void 0 : system.url]);
|
|
27
|
-
return Component ? /*#__PURE__*/React.createElement(React.Suspense, {
|
|
10
|
+
const Component = useMemo(() => loadComponent(system.scope, system.module, globalThis.window ? system.url : system.serverUrl, undefined, system.preventSingleton), [system.scope, system.module, system.url, system.serverUrl, system.preventSingleton]);
|
|
11
|
+
return /*#__PURE__*/React.createElement(React.Suspense, {
|
|
28
12
|
fallback: fallback || ''
|
|
29
|
-
}, /*#__PURE__*/React.createElement(Component, props))
|
|
13
|
+
}, /*#__PURE__*/React.createElement(Component, props));
|
|
30
14
|
};
|
|
31
15
|
const ModuleHost = _ref2 => {
|
|
32
16
|
let {
|
|
@@ -73,7 +57,9 @@ const ModuleHost = _ref2 => {
|
|
|
73
57
|
system: {
|
|
74
58
|
scope: system.scope,
|
|
75
59
|
url: replaceStagingUrl(preventStagingReplacement, system.url, environment.buildEnvironment),
|
|
76
|
-
|
|
60
|
+
serverUrl: replaceStagingUrl(preventStagingReplacement, system.serverUrl, environment.buildEnvironment),
|
|
61
|
+
module: system.module,
|
|
62
|
+
preventSingleton: system.preventSingleton
|
|
77
63
|
},
|
|
78
64
|
data: initialData,
|
|
79
65
|
functions: functions,
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { semaphore } from "./utils/useDynamicScript";
|
|
2
|
+
import Semaphore from "semaphore-async-await";
|
|
3
|
+
import loadComponent from "./utils/loadComponent";
|
|
4
|
+
import React from "react";
|
|
5
|
+
const Test = () => {
|
|
6
|
+
return /*#__PURE__*/React.createElement("div", null, "Test12");
|
|
7
|
+
};
|
|
8
|
+
const Test2 = _ref => {
|
|
9
|
+
let {
|
|
10
|
+
fallback
|
|
11
|
+
} = _ref;
|
|
12
|
+
return /*#__PURE__*/React.createElement("div", null, fallback);
|
|
13
|
+
};
|
|
14
|
+
let status = 'pending';
|
|
15
|
+
let error = false;
|
|
16
|
+
function wrapPromise(promise) {
|
|
17
|
+
console.log("nice2222");
|
|
18
|
+
let response;
|
|
19
|
+
const suspender = promise.then(res => {
|
|
20
|
+
console.log("settttttt");
|
|
21
|
+
status = 'success';
|
|
22
|
+
response = res;
|
|
23
|
+
}, err => {
|
|
24
|
+
console.error(err);
|
|
25
|
+
status = 'error';
|
|
26
|
+
response = err;
|
|
27
|
+
});
|
|
28
|
+
const read = () => {
|
|
29
|
+
console.log("status", status);
|
|
30
|
+
switch (status) {
|
|
31
|
+
case 'pending':
|
|
32
|
+
throw suspender;
|
|
33
|
+
case 'error':
|
|
34
|
+
throw response;
|
|
35
|
+
default:
|
|
36
|
+
return response;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
console.log("nice33333");
|
|
40
|
+
return {
|
|
41
|
+
read
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export function fetchData(url) {
|
|
45
|
+
console.log("ahhh");
|
|
46
|
+
const promise = fetch(url).then(async res => {
|
|
47
|
+
var t = await res.json();
|
|
48
|
+
console.log("tttt", t);
|
|
49
|
+
return {
|
|
50
|
+
test: 1
|
|
51
|
+
};
|
|
52
|
+
});
|
|
53
|
+
return wrapPromise(promise);
|
|
54
|
+
}
|
|
55
|
+
let Raw = Test;
|
|
56
|
+
const Component = _ref2 => {
|
|
57
|
+
let {
|
|
58
|
+
fallback,
|
|
59
|
+
system
|
|
60
|
+
} = _ref2;
|
|
61
|
+
//
|
|
62
|
+
// return <div>Nice</div>;
|
|
63
|
+
|
|
64
|
+
const p = new Promise(async res => {
|
|
65
|
+
if (!global.window) {
|
|
66
|
+
Raw = Test2;
|
|
67
|
+
res(true);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const args = {
|
|
71
|
+
url: system.url,
|
|
72
|
+
scope: system === null || system === void 0 ? void 0 : system.scope
|
|
73
|
+
};
|
|
74
|
+
if (!args.url) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
const element = document.createElement('script');
|
|
78
|
+
element.src = args.url;
|
|
79
|
+
element.type = 'text/javascript';
|
|
80
|
+
element.async = true;
|
|
81
|
+
if (!(args.scope in semaphore)) {
|
|
82
|
+
semaphore[args.scope] = new Semaphore(1);
|
|
83
|
+
}
|
|
84
|
+
(async () => {
|
|
85
|
+
await semaphore[args.scope].acquire();
|
|
86
|
+
element.onload = async () => {
|
|
87
|
+
await new Promise(r => setTimeout(r, 3000));
|
|
88
|
+
console.log('dsajkhdkjashdkjashdkashjkdhsjakhdkjsa');
|
|
89
|
+
const listKey = args.scope + "_list";
|
|
90
|
+
if (!window[listKey]) window[listKey] = [];
|
|
91
|
+
window[listKey].push({
|
|
92
|
+
url: args.url,
|
|
93
|
+
container: window[args.scope]
|
|
94
|
+
});
|
|
95
|
+
window[args.scope] = null;
|
|
96
|
+
const tt = () => new Promise(async r2 => {
|
|
97
|
+
var test1 = await (await loadComponent(system.scope, system.module, system.url, undefined, system.preventSingleton))();
|
|
98
|
+
console.log("ööööö", test1.default);
|
|
99
|
+
r2(test1.default);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// return React.lazy(tt);
|
|
103
|
+
Raw = await tt();
|
|
104
|
+
res(true);
|
|
105
|
+
console.log("Raw", Raw);
|
|
106
|
+
};
|
|
107
|
+
element.onerror = () => {
|
|
108
|
+
console.log("errorrrrrrrrrrrr");
|
|
109
|
+
res(false);
|
|
110
|
+
};
|
|
111
|
+
document.head.appendChild(element);
|
|
112
|
+
})();
|
|
113
|
+
});
|
|
114
|
+
const l = wrapPromise(p);
|
|
115
|
+
console.error("l.read", status);
|
|
116
|
+
l.read();
|
|
117
|
+
console.error("l.read2", error, Raw);
|
|
118
|
+
// !system || !ready || failed
|
|
119
|
+
|
|
120
|
+
if (error) {
|
|
121
|
+
return /*#__PURE__*/React.createElement(Test, null);
|
|
122
|
+
}
|
|
123
|
+
if (global.window) {
|
|
124
|
+
return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Raw, {
|
|
125
|
+
fallback: fallback
|
|
126
|
+
}));
|
|
127
|
+
}
|
|
128
|
+
return /*#__PURE__*/React.createElement(Raw, {
|
|
129
|
+
fallback: fallback
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
/* eslint-disable react-hooks/exhaustive-deps */
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export default Component;
|
|
@@ -1,55 +1,101 @@
|
|
|
1
|
-
|
|
2
|
-
// @ts-nocheck
|
|
3
|
-
|
|
1
|
+
import ReactDOM from 'react-dom';
|
|
4
2
|
import semver from 'semver';
|
|
5
3
|
import React from 'react';
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (!ModuleMap) {
|
|
25
|
-
ModuleMap = {};
|
|
26
|
-
instances[`${scope}__${module}`] = ModuleMap;
|
|
4
|
+
import { loadRemote, registerRemotes, loadShareSync, init } from '@module-federation/runtime';
|
|
5
|
+
const registeredScopes = {};
|
|
6
|
+
const moduleMap = {};
|
|
7
|
+
const componentMap = {};
|
|
8
|
+
init({
|
|
9
|
+
// @ts-expect-error will be set by chayns-toolkit via DefinePlugin
|
|
10
|
+
name: process.env.__PACKAGE_NAME__,
|
|
11
|
+
remotes: [],
|
|
12
|
+
shared: {
|
|
13
|
+
react: {
|
|
14
|
+
version: React.version,
|
|
15
|
+
scope: 'default',
|
|
16
|
+
lib: () => React
|
|
17
|
+
},
|
|
18
|
+
'react-dom': {
|
|
19
|
+
version: ReactDOM.version,
|
|
20
|
+
scope: 'default',
|
|
21
|
+
lib: () => ReactDOM
|
|
27
22
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
} else {
|
|
36
|
-
Module = factory();
|
|
37
|
-
ModuleMap[`${Module.default.buildEnv}__${Module.default.appVersion}`] = Module;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
export const loadModule = function (scope, module, url) {
|
|
26
|
+
let preventSingleton = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
27
|
+
if (registeredScopes[scope] !== url || preventSingleton) {
|
|
28
|
+
if (scope in registeredScopes) {
|
|
29
|
+
console.error(`[chayns-api] call registerRemote with force for scope ${scope}. url: ${url}`);
|
|
38
30
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
31
|
+
registerRemotes([{
|
|
32
|
+
name: scope,
|
|
33
|
+
entry: url,
|
|
34
|
+
alias: scope
|
|
35
|
+
}], {
|
|
36
|
+
force: scope in registeredScopes
|
|
37
|
+
});
|
|
38
|
+
registeredScopes[scope] = url;
|
|
39
|
+
moduleMap[scope] = {};
|
|
40
|
+
componentMap[scope] = {};
|
|
41
|
+
}
|
|
42
|
+
if (!(module in moduleMap[scope])) {
|
|
43
|
+
const path = `${scope}/${module.replace(/^\.\//, '')}`;
|
|
44
|
+
const promise = loadRemote(path);
|
|
45
|
+
promise.catch(e => {
|
|
46
|
+
console.error("[chayns-api] Failed to load module", scope, url, e);
|
|
47
|
+
// causes registerRemote with force = true on next attempt to load the component which tries to load the component again
|
|
48
|
+
registeredScopes[scope] = '';
|
|
49
|
+
});
|
|
50
|
+
return promise;
|
|
51
|
+
}
|
|
52
|
+
return moduleMap[scope][module];
|
|
53
|
+
};
|
|
54
|
+
const loadComponent = function (scope, module, url) {
|
|
55
|
+
let skipCompatMode = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
56
|
+
let preventSingleton = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
57
|
+
if (skipCompatMode) {
|
|
58
|
+
console.warn('[chayns-api] skipCompatMode-option is deprecated and is set automatically now');
|
|
59
|
+
}
|
|
60
|
+
if (!componentMap[scope]) {
|
|
61
|
+
componentMap[scope] = {};
|
|
62
|
+
}
|
|
63
|
+
if (!(module in componentMap[scope])) {
|
|
64
|
+
const promise = loadModule(scope, module, url, preventSingleton).then(async Module => {
|
|
65
|
+
if (typeof Module.default === 'function') {
|
|
66
|
+
return Module;
|
|
67
|
+
}
|
|
68
|
+
const hostVersion = semver.minVersion(React.version);
|
|
69
|
+
const {
|
|
70
|
+
requiredVersion,
|
|
71
|
+
environment
|
|
72
|
+
} = Module.default;
|
|
73
|
+
const shareScopes = await new Promise(resolve => {
|
|
74
|
+
loadShareSync('react', {
|
|
75
|
+
resolver: shareOptions => {
|
|
76
|
+
resolve(shareOptions);
|
|
77
|
+
return shareOptions[0];
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
const matchReactVersion = requiredVersion && semver.satisfies(hostVersion, requiredVersion) && !shareScopes.some(t => {
|
|
82
|
+
const {
|
|
83
|
+
version,
|
|
84
|
+
from
|
|
85
|
+
} = t;
|
|
86
|
+
return semver.gt(version, hostVersion) && semver.satisfies(version, requiredVersion) || scope === from.split('-').join('_');
|
|
87
|
+
});
|
|
88
|
+
if (!matchReactVersion || environment !== 'production' || process.env.NODE_ENV === 'development') {
|
|
89
|
+
return {
|
|
90
|
+
default: Module.default.CompatComponent
|
|
91
|
+
};
|
|
92
|
+
}
|
|
47
93
|
return {
|
|
48
|
-
default: Module.default.
|
|
94
|
+
default: Module.default.Component
|
|
49
95
|
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
96
|
+
});
|
|
97
|
+
componentMap[scope][module] = /*#__PURE__*/React.lazy(() => promise);
|
|
98
|
+
}
|
|
99
|
+
return componentMap[scope][module];
|
|
100
|
+
};
|
|
101
|
+
export default loadComponent;
|
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import './util/transferNestedFunctions';
|
|
1
2
|
export { default as ChaynsProvider } from './components/ChaynsProvider';
|
|
2
|
-
export { default as getDeviceInfo, getScreenSize } from './util/deviceHelper';
|
|
3
|
+
export { default as getDeviceInfo, getScreenSize, getClientDeviceInfo } from './util/deviceHelper';
|
|
3
4
|
export { default as ChaynsHost } from './host/ChaynsHost';
|
|
4
5
|
export { withCompatMode } from './components/withCompatMode';
|
|
5
6
|
export * from './calls';
|
|
@@ -7,6 +8,11 @@ export * from './hooks';
|
|
|
7
8
|
export * from './components/WaitUntil';
|
|
8
9
|
export * from './types/IChaynsReact';
|
|
9
10
|
export * from './components/withCompatMode';
|
|
11
|
+
export * from './constants';
|
|
12
|
+
export { default as withHydrationBoundary } from './components/withHydrationBoundary';
|
|
13
|
+
export { default as StaticChaynsApi } from './wrapper/StaticChaynsApi';
|
|
14
|
+
export { default as loadComponent, loadModule } from './host/module/utils/loadComponent';
|
|
15
|
+
export { default as DialogHandler } from './handler/DialogHandler';
|
|
10
16
|
import * as _dialog from './calls/dialogs/index';
|
|
11
17
|
export { _dialog as dialog };
|
|
12
18
|
export * from './types/IChaynsReact';
|