chayns-api 1.1.0-11 → 1.1.0-18
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/components/withHydrationBoundary.js +4 -8
- package/dist/cjs/host/ChaynsHost.js +20 -23
- package/dist/cjs/host/module/ModuleHost.js +2 -20
- package/dist/cjs/host/module/utils/loadComponent.js +75 -41
- package/dist/cjs/host/module/utils/useDynamicScript.js +4 -6
- package/dist/cjs/index.js +8 -1
- package/dist/cjs/util/url.js +1 -1
- package/dist/esm/components/withHydrationBoundary.js +4 -8
- package/dist/esm/host/ChaynsHost.js +18 -23
- package/dist/esm/host/module/ModuleHost.js +2 -20
- package/dist/esm/host/module/utils/loadComponent.js +77 -43
- package/dist/esm/index.js +1 -1
- package/dist/esm/util/url.js +2 -2
- package/dist/types/host/ChaynsHost.d.ts +0 -1
- package/dist/types/host/module/ModuleHost.d.ts +1 -0
- package/dist/types/host/module/utils/loadComponent.d.ts +3 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +1 -1
- package/dist/chayns-api.js +0 -2
- package/dist/chayns-api.js.LICENSE.txt +0 -41
- package/dist/cjs/calls/toolbarChangeListener.js +0 -1
- package/dist/cjs/host/module/Test3.js +0 -141
- package/dist/esm/calls/toolbarChangeListener.js +0 -0
- package/dist/esm/host/module/Test3.js +0 -135
- package/dist/types/calls/toolbarChangeListener.d.ts +0 -0
- package/dist/types/host/module/Test3.d.ts +0 -8
|
@@ -22,6 +22,9 @@ const withHydrationBoundary = (Component, initializer, useHydrationId) => {
|
|
|
22
22
|
throw new Error('hydration boundary was not given a id which is required');
|
|
23
23
|
}
|
|
24
24
|
const [store] = (0, _react.useState)(() => {
|
|
25
|
+
if (!globalThis.window && id in value) {
|
|
26
|
+
return value[id];
|
|
27
|
+
}
|
|
25
28
|
let initialValue = undefined;
|
|
26
29
|
if (globalThis.window) {
|
|
27
30
|
const htmlId = `__INITIAL_DATA_${id}__`;
|
|
@@ -32,14 +35,7 @@ const withHydrationBoundary = (Component, initializer, useHydrationId) => {
|
|
|
32
35
|
}
|
|
33
36
|
const s = initializer(initialValue);
|
|
34
37
|
if (!globalThis.window) {
|
|
35
|
-
|
|
36
|
-
console.warn(`Dehydration function for id "${id}" has been defined multiple times. This can have two reasons. The children cause suspension and therefor the hydration boundary has to mount from scratch again. You can avoid this by adding a Suspense around the children. The id is not unique. This has to be fixed or might cause hydration issues.`);
|
|
37
|
-
}
|
|
38
|
-
value[id] = {
|
|
39
|
-
getState: s.getState,
|
|
40
|
-
abort: s.abort,
|
|
41
|
-
type: s.type
|
|
42
|
-
};
|
|
38
|
+
value[id] = s;
|
|
43
39
|
}
|
|
44
40
|
return s;
|
|
45
41
|
});
|
|
@@ -4,10 +4,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var _react =
|
|
7
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _HostIframe = _interopRequireDefault(require("./iframe/HostIframe"));
|
|
9
9
|
var _ModuleHost = _interopRequireDefault(require("./module/ModuleHost"));
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
12
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
11
13
|
const ChaynsHost = ({
|
|
12
14
|
type,
|
|
13
15
|
iFrameProps,
|
|
@@ -15,7 +17,6 @@ const ChaynsHost = ({
|
|
|
15
17
|
src,
|
|
16
18
|
iFrameRef = undefined,
|
|
17
19
|
loadingComponent = undefined,
|
|
18
|
-
children = undefined,
|
|
19
20
|
system,
|
|
20
21
|
// shallow data
|
|
21
22
|
pages,
|
|
@@ -31,8 +32,23 @@ const ChaynsHost = ({
|
|
|
31
32
|
preventStagingReplacement,
|
|
32
33
|
dialog
|
|
33
34
|
}) => {
|
|
35
|
+
const [isVisible, setIsVisible] = (0, _react.useState)(type === 'server-iframe' || type === 'server-module' && (system === null || system === void 0 ? void 0 : system.serverUrl));
|
|
36
|
+
(0, _react.useEffect)(() => {
|
|
37
|
+
if (isVisible) return;
|
|
38
|
+
if (typeof _react.startTransition === 'function') {
|
|
39
|
+
(0, _react.startTransition)(() => {
|
|
40
|
+
setIsVisible(true);
|
|
41
|
+
});
|
|
42
|
+
} else {
|
|
43
|
+
setIsVisible(true);
|
|
44
|
+
}
|
|
45
|
+
}, []);
|
|
46
|
+
if (!isVisible) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
34
49
|
switch (type) {
|
|
35
50
|
case 'client-iframe':
|
|
51
|
+
case 'server-iframe':
|
|
36
52
|
return /*#__PURE__*/_react.default.createElement(_HostIframe.default, {
|
|
37
53
|
iFrameRef: iFrameRef,
|
|
38
54
|
iFrameProps: iFrameProps,
|
|
@@ -44,6 +60,7 @@ const ChaynsHost = ({
|
|
|
44
60
|
currentPage: currentPage,
|
|
45
61
|
functions: functions,
|
|
46
62
|
src: src,
|
|
63
|
+
postForm: type === 'server-iframe',
|
|
47
64
|
language: language,
|
|
48
65
|
parameters: parameters,
|
|
49
66
|
environment: environment,
|
|
@@ -51,8 +68,8 @@ const ChaynsHost = ({
|
|
|
51
68
|
preventStagingReplacement: preventStagingReplacement,
|
|
52
69
|
dialog: dialog
|
|
53
70
|
});
|
|
54
|
-
case 'server-module':
|
|
55
71
|
case 'client-module':
|
|
72
|
+
case 'server-module':
|
|
56
73
|
return /*#__PURE__*/_react.default.createElement(_ModuleHost.default, {
|
|
57
74
|
system: system,
|
|
58
75
|
pages: pages,
|
|
@@ -70,26 +87,6 @@ const ChaynsHost = ({
|
|
|
70
87
|
preventStagingReplacement: preventStagingReplacement,
|
|
71
88
|
dialog: dialog
|
|
72
89
|
});
|
|
73
|
-
case 'server-iframe':
|
|
74
|
-
return /*#__PURE__*/_react.default.createElement(_HostIframe.default, {
|
|
75
|
-
iFrameRef: iFrameRef,
|
|
76
|
-
iFrameProps: iFrameProps,
|
|
77
|
-
pages: pages,
|
|
78
|
-
isAdminModeActive: isAdminModeActive,
|
|
79
|
-
site: site,
|
|
80
|
-
user: user,
|
|
81
|
-
device: device,
|
|
82
|
-
currentPage: currentPage,
|
|
83
|
-
functions: functions,
|
|
84
|
-
src: src,
|
|
85
|
-
postForm: true,
|
|
86
|
-
language: language,
|
|
87
|
-
parameters: parameters,
|
|
88
|
-
environment: environment,
|
|
89
|
-
customData: customData,
|
|
90
|
-
preventStagingReplacement: preventStagingReplacement,
|
|
91
|
-
dialog: dialog
|
|
92
|
-
});
|
|
93
90
|
default:
|
|
94
91
|
return null;
|
|
95
92
|
}
|
|
@@ -4,37 +4,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var _runtime = require("@module-federation/runtime");
|
|
8
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
-
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
10
8
|
var _loadComponent = _interopRequireDefault(require("./utils/loadComponent"));
|
|
11
9
|
var _url = require("../../util/url");
|
|
12
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
11
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
14
12
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
15
|
-
(0, _runtime.init)({
|
|
16
|
-
// @ts-expect-error will be set by chayns-toolkit via DefinePlugin
|
|
17
|
-
name: process.env.__PACKAGE_NAME__,
|
|
18
|
-
remotes: [],
|
|
19
|
-
shared: {
|
|
20
|
-
react: {
|
|
21
|
-
version: _react.default.version,
|
|
22
|
-
scope: 'default',
|
|
23
|
-
lib: () => _react.default
|
|
24
|
-
},
|
|
25
|
-
'react-dom': {
|
|
26
|
-
version: _reactDom.default.version,
|
|
27
|
-
scope: 'default',
|
|
28
|
-
lib: () => _reactDom.default
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
13
|
const System = ({
|
|
33
14
|
system,
|
|
34
15
|
fallback,
|
|
35
16
|
...props
|
|
36
17
|
}) => {
|
|
37
|
-
const Component = (0, _react.useMemo)(() => (0, _loadComponent.default)(system.scope, system.module, system.url, undefined, system.preventSingleton), [system.scope, system.module, system.url, system.preventSingleton]);
|
|
18
|
+
const Component = (0, _react.useMemo)(() => (0, _loadComponent.default)(system.scope, system.module, globalThis.window ? system.url : system.serverUrl, undefined, system.preventSingleton), [system.scope, system.module, system.url, system.serverUrl, system.preventSingleton]);
|
|
38
19
|
return /*#__PURE__*/_react.default.createElement(_react.default.Suspense, {
|
|
39
20
|
fallback: fallback || ''
|
|
40
21
|
}, /*#__PURE__*/_react.default.createElement(Component, props));
|
|
@@ -83,6 +64,7 @@ const ModuleHost = ({
|
|
|
83
64
|
system: {
|
|
84
65
|
scope: system.scope,
|
|
85
66
|
url: (0, _url.replaceStagingUrl)(preventStagingReplacement, system.url, environment.buildEnvironment),
|
|
67
|
+
serverUrl: (0, _url.replaceStagingUrl)(preventStagingReplacement, system.serverUrl, environment.buildEnvironment),
|
|
86
68
|
module: system.module,
|
|
87
69
|
preventSingleton: system.preventSingleton
|
|
88
70
|
},
|
|
@@ -3,17 +3,33 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default =
|
|
6
|
+
exports.loadModule = exports.default = void 0;
|
|
7
|
+
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
7
8
|
var _semver = _interopRequireDefault(require("semver"));
|
|
8
9
|
var _react = _interopRequireDefault(require("react"));
|
|
9
10
|
var _runtime = require("@module-federation/runtime");
|
|
10
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
12
|
const registeredScopes = {};
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
const moduleMap = {};
|
|
14
|
+
const componentMap = {};
|
|
15
|
+
(0, _runtime.init)({
|
|
16
|
+
// @ts-expect-error will be set by chayns-toolkit via DefinePlugin
|
|
17
|
+
name: process.env.__PACKAGE_NAME__,
|
|
18
|
+
remotes: [],
|
|
19
|
+
shared: {
|
|
20
|
+
react: {
|
|
21
|
+
version: _react.default.version,
|
|
22
|
+
scope: 'default',
|
|
23
|
+
lib: () => _react.default
|
|
24
|
+
},
|
|
25
|
+
'react-dom': {
|
|
26
|
+
version: _reactDom.default.version,
|
|
27
|
+
scope: 'default',
|
|
28
|
+
lib: () => _reactDom.default
|
|
29
|
+
}
|
|
16
30
|
}
|
|
31
|
+
});
|
|
32
|
+
const loadModule = (scope, module, url, preventSingleton = false) => {
|
|
17
33
|
if (registeredScopes[scope] !== url || preventSingleton) {
|
|
18
34
|
(0, _runtime.registerRemotes)([{
|
|
19
35
|
name: scope,
|
|
@@ -23,46 +39,64 @@ function loadComponent(scope, module, url, skipCompatMode = false, preventSingle
|
|
|
23
39
|
force: scope in registeredScopes
|
|
24
40
|
});
|
|
25
41
|
registeredScopes[scope] = url;
|
|
26
|
-
|
|
42
|
+
moduleMap[scope] = {};
|
|
43
|
+
componentMap[scope] = {};
|
|
27
44
|
}
|
|
28
|
-
if (!(module in
|
|
45
|
+
if (!(module in moduleMap[scope])) {
|
|
29
46
|
const path = `${scope}/${module.replace(/^\.\//, '')}`;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
47
|
+
const promise = (0, _runtime.loadRemote)(path);
|
|
48
|
+
promise.catch(() => {
|
|
49
|
+
// causes registerRemote with force = true on next attempt to load the component which tries to load the component again
|
|
50
|
+
registeredScopes[scope] = '';
|
|
51
|
+
});
|
|
52
|
+
return promise;
|
|
53
|
+
}
|
|
54
|
+
return moduleMap[scope][module];
|
|
55
|
+
};
|
|
56
|
+
exports.loadModule = loadModule;
|
|
57
|
+
const loadComponent = (scope, module, url, skipCompatMode = false, preventSingleton = 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.default.minVersion(_react.default.version);
|
|
70
|
+
const {
|
|
71
|
+
requiredVersion,
|
|
72
|
+
environment
|
|
73
|
+
} = Module.default;
|
|
74
|
+
const shareScopes = await new Promise(resolve => {
|
|
75
|
+
(0, _runtime.loadShareSync)('react', {
|
|
76
|
+
resolver: shareOptions => {
|
|
77
|
+
resolve(shareOptions);
|
|
78
|
+
return shareOptions[0];
|
|
79
|
+
}
|
|
55
80
|
});
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
81
|
+
});
|
|
82
|
+
const matchReactVersion = requiredVersion && _semver.default.satisfies(hostVersion, requiredVersion) && !shareScopes.some(t => {
|
|
83
|
+
const {
|
|
84
|
+
version,
|
|
85
|
+
from
|
|
86
|
+
} = t;
|
|
87
|
+
return _semver.default.gt(version, hostVersion) && _semver.default.satisfies(version, requiredVersion) || scope === from.split('-').join('_');
|
|
88
|
+
});
|
|
89
|
+
if (!matchReactVersion || environment !== 'production' || process.env.NODE_ENV === 'development') {
|
|
61
90
|
return {
|
|
62
|
-
default: Module.default.
|
|
91
|
+
default: Module.default.CompatComponent
|
|
63
92
|
};
|
|
64
|
-
}
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
default: Module.default.Component
|
|
96
|
+
};
|
|
65
97
|
});
|
|
98
|
+
componentMap[scope][module] = /*#__PURE__*/_react.default.lazy(() => promise);
|
|
66
99
|
}
|
|
67
|
-
return
|
|
68
|
-
}
|
|
100
|
+
return componentMap[scope][module];
|
|
101
|
+
};
|
|
102
|
+
var _default = exports.default = loadComponent;
|
|
@@ -7,10 +7,9 @@ exports.semaphore = exports.default = void 0;
|
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _semaphoreAsyncAwait = _interopRequireDefault(require("semaphore-async-await"));
|
|
9
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
function _getRequireWildcardCache(
|
|
11
|
-
function _interopRequireWildcard(
|
|
12
|
-
const semaphore = {};
|
|
13
|
-
exports.semaphore = semaphore;
|
|
10
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
11
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
12
|
+
const semaphore = exports.semaphore = {};
|
|
14
13
|
const useDynamicScript = args => {
|
|
15
14
|
const [ready, setReady] = _react.default.useState(false);
|
|
16
15
|
const [failed, setFailed] = _react.default.useState(false);
|
|
@@ -57,5 +56,4 @@ const useDynamicScript = args => {
|
|
|
57
56
|
failed
|
|
58
57
|
};
|
|
59
58
|
};
|
|
60
|
-
var _default = useDynamicScript;
|
|
61
|
-
exports.default = _default;
|
|
59
|
+
var _default = exports.default = useDynamicScript;
|
package/dist/cjs/index.js
CHANGED
|
@@ -13,6 +13,7 @@ var _exportNames = {
|
|
|
13
13
|
withHydrationBoundary: true,
|
|
14
14
|
StaticChaynsApi: true,
|
|
15
15
|
loadComponent: true,
|
|
16
|
+
loadModule: true,
|
|
16
17
|
DialogHandler: true,
|
|
17
18
|
dialog: true
|
|
18
19
|
};
|
|
@@ -65,6 +66,12 @@ Object.defineProperty(exports, "loadComponent", {
|
|
|
65
66
|
return _loadComponent.default;
|
|
66
67
|
}
|
|
67
68
|
});
|
|
69
|
+
Object.defineProperty(exports, "loadModule", {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
get: function () {
|
|
72
|
+
return _loadComponent.loadModule;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
68
75
|
Object.defineProperty(exports, "withCompatMode", {
|
|
69
76
|
enumerable: true,
|
|
70
77
|
get: function () {
|
|
@@ -155,7 +162,7 @@ Object.keys(_constants).forEach(function (key) {
|
|
|
155
162
|
});
|
|
156
163
|
var _withHydrationBoundary = _interopRequireDefault(require("./components/withHydrationBoundary"));
|
|
157
164
|
var _StaticChaynsApi = _interopRequireDefault(require("./wrapper/StaticChaynsApi"));
|
|
158
|
-
var _loadComponent =
|
|
165
|
+
var _loadComponent = _interopRequireWildcard(require("./host/module/utils/loadComponent"));
|
|
159
166
|
var _DialogHandler = _interopRequireDefault(require("./handler/DialogHandler"));
|
|
160
167
|
var _dialog = _interopRequireWildcard(require("./calls/dialogs/index"));
|
|
161
168
|
exports.dialog = _dialog;
|
package/dist/cjs/util/url.js
CHANGED
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.replaceStagingUrl = void 0;
|
|
7
7
|
var _IChaynsReact = require("../types/IChaynsReact");
|
|
8
8
|
const replaceStagingUrl = (prevent, url, environment) => {
|
|
9
|
-
if (prevent) return url;
|
|
9
|
+
if (prevent || !url) return url;
|
|
10
10
|
let replacedUrl = url;
|
|
11
11
|
if (environment === _IChaynsReact.Environment.Qa || environment === _IChaynsReact.Environment.Development) {
|
|
12
12
|
replacedUrl = replacedUrl.replace('tapp.chayns-static.space', 'tapp-dev.chayns-static.space');
|
|
@@ -15,6 +15,9 @@ const withHydrationBoundary = (Component, initializer, useHydrationId) => {
|
|
|
15
15
|
throw new Error('hydration boundary was not given a id which is required');
|
|
16
16
|
}
|
|
17
17
|
const [store] = useState(() => {
|
|
18
|
+
if (!globalThis.window && id in value) {
|
|
19
|
+
return value[id];
|
|
20
|
+
}
|
|
18
21
|
let initialValue = undefined;
|
|
19
22
|
if (globalThis.window) {
|
|
20
23
|
const htmlId = `__INITIAL_DATA_${id}__`;
|
|
@@ -25,14 +28,7 @@ const withHydrationBoundary = (Component, initializer, useHydrationId) => {
|
|
|
25
28
|
}
|
|
26
29
|
const s = initializer(initialValue);
|
|
27
30
|
if (!globalThis.window) {
|
|
28
|
-
|
|
29
|
-
console.warn(`Dehydration function for id "${id}" has been defined multiple times. This can have two reasons. The children cause suspension and therefor the hydration boundary has to mount from scratch again. You can avoid this by adding a Suspense around the children. The id is not unique. This has to be fixed or might cause hydration issues.`);
|
|
30
|
-
}
|
|
31
|
-
value[id] = {
|
|
32
|
-
getState: s.getState,
|
|
33
|
-
abort: s.abort,
|
|
34
|
-
type: s.type
|
|
35
|
-
};
|
|
31
|
+
value[id] = s;
|
|
36
32
|
}
|
|
37
33
|
return s;
|
|
38
34
|
});
|
|
@@ -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,
|
|
@@ -45,8 +60,8 @@ const ChaynsHost = _ref => {
|
|
|
45
60
|
preventStagingReplacement: preventStagingReplacement,
|
|
46
61
|
dialog: dialog
|
|
47
62
|
});
|
|
48
|
-
case 'server-module':
|
|
49
63
|
case 'client-module':
|
|
64
|
+
case 'server-module':
|
|
50
65
|
return /*#__PURE__*/React.createElement(ModuleHost, {
|
|
51
66
|
system: system,
|
|
52
67
|
pages: pages,
|
|
@@ -64,26 +79,6 @@ const ChaynsHost = _ref => {
|
|
|
64
79
|
preventStagingReplacement: preventStagingReplacement,
|
|
65
80
|
dialog: dialog
|
|
66
81
|
});
|
|
67
|
-
case 'server-iframe':
|
|
68
|
-
return /*#__PURE__*/React.createElement(HostIframe, {
|
|
69
|
-
iFrameRef: iFrameRef,
|
|
70
|
-
iFrameProps: iFrameProps,
|
|
71
|
-
pages: pages,
|
|
72
|
-
isAdminModeActive: isAdminModeActive,
|
|
73
|
-
site: site,
|
|
74
|
-
user: user,
|
|
75
|
-
device: device,
|
|
76
|
-
currentPage: currentPage,
|
|
77
|
-
functions: functions,
|
|
78
|
-
src: src,
|
|
79
|
-
postForm: true,
|
|
80
|
-
language: language,
|
|
81
|
-
parameters: parameters,
|
|
82
|
-
environment: environment,
|
|
83
|
-
customData: customData,
|
|
84
|
-
preventStagingReplacement: preventStagingReplacement,
|
|
85
|
-
dialog: dialog
|
|
86
|
-
});
|
|
87
82
|
default:
|
|
88
83
|
return null;
|
|
89
84
|
}
|
|
@@ -1,32 +1,13 @@
|
|
|
1
|
-
import { init } from '@module-federation/runtime';
|
|
2
1
|
import React, { useMemo } from 'react';
|
|
3
|
-
import ReactDOM from 'react-dom';
|
|
4
2
|
import loadComponent from './utils/loadComponent';
|
|
5
3
|
import { replaceStagingUrl } from "../../util/url";
|
|
6
|
-
init({
|
|
7
|
-
// @ts-expect-error will be set by chayns-toolkit via DefinePlugin
|
|
8
|
-
name: process.env.__PACKAGE_NAME__,
|
|
9
|
-
remotes: [],
|
|
10
|
-
shared: {
|
|
11
|
-
react: {
|
|
12
|
-
version: React.version,
|
|
13
|
-
scope: 'default',
|
|
14
|
-
lib: () => React
|
|
15
|
-
},
|
|
16
|
-
'react-dom': {
|
|
17
|
-
version: ReactDOM.version,
|
|
18
|
-
scope: 'default',
|
|
19
|
-
lib: () => ReactDOM
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
4
|
const System = _ref => {
|
|
24
5
|
let {
|
|
25
6
|
system,
|
|
26
7
|
fallback,
|
|
27
8
|
...props
|
|
28
9
|
} = _ref;
|
|
29
|
-
const Component = useMemo(() => loadComponent(system.scope, system.module, system.url, undefined, system.preventSingleton), [system.scope, system.module, system.url, system.preventSingleton]);
|
|
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]);
|
|
30
11
|
return /*#__PURE__*/React.createElement(React.Suspense, {
|
|
31
12
|
fallback: fallback || ''
|
|
32
13
|
}, /*#__PURE__*/React.createElement(Component, props));
|
|
@@ -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,14 +1,29 @@
|
|
|
1
|
+
import ReactDOM from 'react-dom';
|
|
1
2
|
import semver from 'semver';
|
|
2
3
|
import React from 'react';
|
|
3
|
-
import { loadRemote, registerRemotes, loadShareSync } from '@module-federation/runtime';
|
|
4
|
+
import { loadRemote, registerRemotes, loadShareSync, init } from '@module-federation/runtime';
|
|
4
5
|
const registeredScopes = {};
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
|
22
|
+
}
|
|
11
23
|
}
|
|
24
|
+
});
|
|
25
|
+
export const loadModule = function (scope, module, url) {
|
|
26
|
+
let preventSingleton = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
12
27
|
if (registeredScopes[scope] !== url || preventSingleton) {
|
|
13
28
|
registerRemotes([{
|
|
14
29
|
name: scope,
|
|
@@ -18,46 +33,65 @@ export default function loadComponent(scope, module, url) {
|
|
|
18
33
|
force: scope in registeredScopes
|
|
19
34
|
});
|
|
20
35
|
registeredScopes[scope] = url;
|
|
21
|
-
|
|
36
|
+
moduleMap[scope] = {};
|
|
37
|
+
componentMap[scope] = {};
|
|
22
38
|
}
|
|
23
|
-
if (!(module in
|
|
39
|
+
if (!(module in moduleMap[scope])) {
|
|
24
40
|
const path = `${scope}/${module.replace(/^\.\//, '')}`;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
const promise = loadRemote(path);
|
|
42
|
+
promise.catch(() => {
|
|
43
|
+
// causes registerRemote with force = true on next attempt to load the component which tries to load the component again
|
|
44
|
+
registeredScopes[scope] = '';
|
|
45
|
+
});
|
|
46
|
+
return promise;
|
|
47
|
+
}
|
|
48
|
+
return moduleMap[scope][module];
|
|
49
|
+
};
|
|
50
|
+
const loadComponent = function (scope, module, url) {
|
|
51
|
+
let skipCompatMode = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
52
|
+
let preventSingleton = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
53
|
+
if (skipCompatMode) {
|
|
54
|
+
console.warn('[chayns-api] skipCompatMode-option is deprecated and is set automatically now');
|
|
55
|
+
}
|
|
56
|
+
if (!componentMap[scope]) {
|
|
57
|
+
componentMap[scope] = {};
|
|
58
|
+
}
|
|
59
|
+
if (!(module in componentMap[scope])) {
|
|
60
|
+
const promise = loadModule(scope, module, url, preventSingleton).then(async Module => {
|
|
61
|
+
if (typeof Module.default === 'function') {
|
|
62
|
+
return Module;
|
|
63
|
+
}
|
|
64
|
+
const hostVersion = semver.minVersion(React.version);
|
|
65
|
+
const {
|
|
66
|
+
requiredVersion,
|
|
67
|
+
environment
|
|
68
|
+
} = Module.default;
|
|
69
|
+
const shareScopes = await new Promise(resolve => {
|
|
70
|
+
loadShareSync('react', {
|
|
71
|
+
resolver: shareOptions => {
|
|
72
|
+
resolve(shareOptions);
|
|
73
|
+
return shareOptions[0];
|
|
74
|
+
}
|
|
50
75
|
});
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
76
|
+
});
|
|
77
|
+
const matchReactVersion = requiredVersion && semver.satisfies(hostVersion, requiredVersion) && !shareScopes.some(t => {
|
|
78
|
+
const {
|
|
79
|
+
version,
|
|
80
|
+
from
|
|
81
|
+
} = t;
|
|
82
|
+
return semver.gt(version, hostVersion) && semver.satisfies(version, requiredVersion) || scope === from.split('-').join('_');
|
|
83
|
+
});
|
|
84
|
+
if (!matchReactVersion || environment !== 'production' || process.env.NODE_ENV === 'development') {
|
|
56
85
|
return {
|
|
57
|
-
default: Module.default.
|
|
86
|
+
default: Module.default.CompatComponent
|
|
58
87
|
};
|
|
59
|
-
}
|
|
88
|
+
}
|
|
89
|
+
return {
|
|
90
|
+
default: Module.default.Component
|
|
91
|
+
};
|
|
60
92
|
});
|
|
93
|
+
componentMap[scope][module] = /*#__PURE__*/React.lazy(() => promise);
|
|
61
94
|
}
|
|
62
|
-
return
|
|
63
|
-
}
|
|
95
|
+
return componentMap[scope][module];
|
|
96
|
+
};
|
|
97
|
+
export default loadComponent;
|