chayns-api 2.5.0-beta.0 → 2.6.0-beta.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.
@@ -24,4 +24,15 @@ Object.keys(_DefaultLoginDialogOptions).forEach(function (key) {
24
24
  return _DefaultLoginDialogOptions[key];
25
25
  }
26
26
  });
27
+ });
28
+ var _moduleContext = require("./moduleContext");
29
+ Object.keys(_moduleContext).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (key in exports && exports[key] === _moduleContext[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _moduleContext[key];
36
+ }
37
+ });
27
38
  });
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ModuleContext = void 0;
7
+ var _react = require("react");
8
+ let ModuleContext = exports.ModuleContext = void 0;
9
+ if (!globalThis.window && globalThis._moduleContext) {
10
+ exports.ModuleContext = ModuleContext = globalThis._moduleContext;
11
+ } else {
12
+ exports.ModuleContext = ModuleContext = (0, _react.createContext)({});
13
+ globalThis._moduleContext = ModuleContext;
14
+ }
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
+ var _moduleContext = require("../../constants/moduleContext");
8
9
  var _loadComponent = _interopRequireDefault(require("./utils/loadComponent"));
9
10
  var _url = require("../../util/url");
10
11
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -16,6 +17,15 @@ const System = ({
16
17
  ...props
17
18
  }) => {
18
19
  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]);
20
+ if (!globalThis.window) {
21
+ var _system$scope, _moduleContext$_syste;
22
+ const moduleContext = (0, _react.useContext)(_moduleContext.ModuleContext);
23
+ (_moduleContext$_syste = moduleContext[_system$scope = system.scope]) !== null && _moduleContext$_syste !== void 0 ? _moduleContext$_syste : moduleContext[_system$scope] = {
24
+ url: new URL('mf-manifest.json', system.url).toString(),
25
+ modules: new Set()
26
+ };
27
+ moduleContext[system.scope].modules.add(system.module);
28
+ }
19
29
  return _react.default.createElement(_react.default.Suspense, {
20
30
  fallback: fallback || ''
21
31
  }, _react.default.createElement(Component, props));
package/dist/cjs/index.js CHANGED
@@ -203,6 +203,18 @@ Object.keys(_appStorage).forEach(function (key) {
203
203
  }
204
204
  });
205
205
  });
206
+ var _collectCssChunks = require("./util/collectCssChunks");
207
+ Object.keys(_collectCssChunks).forEach(function (key) {
208
+ if (key === "default" || key === "__esModule") return;
209
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
210
+ if (key in exports && exports[key] === _collectCssChunks[key]) return;
211
+ Object.defineProperty(exports, key, {
212
+ enumerable: true,
213
+ get: function () {
214
+ return _collectCssChunks[key];
215
+ }
216
+ });
217
+ });
206
218
  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); }
207
219
  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; }
208
220
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.collectCssChunks = void 0;
7
+ const remoteInfoCache = {};
8
+ const loadRemoteInfo = async url => {
9
+ if (remoteInfoCache[url]) {
10
+ return remoteInfoCache[url];
11
+ }
12
+ const res = await fetch(url);
13
+ if (res.status === 200) {
14
+ const info = await res.json();
15
+ remoteInfoCache[url] = info;
16
+ return info;
17
+ }
18
+ if (res.status === 404) {
19
+ remoteInfoCache[url] = null;
20
+ return null;
21
+ }
22
+ throw new Error(`Could not load remote info from ${url}`);
23
+ };
24
+ const collectCssChunks = async modules => {
25
+ const p = Object.values(modules).map(async module => {
26
+ const info = await loadRemoteInfo(module.url);
27
+ const chunks = [];
28
+ info === null || info === void 0 || info.exposes.forEach(exposes => {
29
+ if (module.modules.has(exposes.path)) {
30
+ var _exposes$assets$css, _exposes$assets;
31
+ const {
32
+ sync = [],
33
+ async = []
34
+ } = (_exposes$assets$css = (_exposes$assets = exposes.assets) === null || _exposes$assets === void 0 ? void 0 : _exposes$assets.css) !== null && _exposes$assets$css !== void 0 ? _exposes$assets$css : {};
35
+ [...sync, ...async].forEach(chunk => {
36
+ const url = new URL(chunk, module.url);
37
+ chunks.push(`<link rel="stylesheet" href="${url}">`);
38
+ });
39
+ }
40
+ });
41
+ return chunks;
42
+ });
43
+ const r = await Promise.allSettled(p);
44
+ return r.flatMap(v => v.status === 'fulfilled' ? v.value : []).join('');
45
+ };
46
+ exports.collectCssChunks = collectCssChunks;
@@ -1,2 +1,3 @@
1
1
  export * from './hydrationContext';
2
- export * from './DefaultLoginDialogOptions';
2
+ export * from './DefaultLoginDialogOptions';
3
+ export * from './moduleContext';
@@ -0,0 +1,8 @@
1
+ import { createContext } from 'react';
2
+ export let ModuleContext;
3
+ if (!globalThis.window && globalThis._moduleContext) {
4
+ ModuleContext = globalThis._moduleContext;
5
+ } else {
6
+ ModuleContext = createContext({});
7
+ globalThis._moduleContext = ModuleContext;
8
+ }
@@ -1,4 +1,5 @@
1
- import React, { useMemo } from 'react';
1
+ import React, { useContext, useMemo } from 'react';
2
+ import { ModuleContext } from '../../constants/moduleContext';
2
3
  import loadComponent from './utils/loadComponent';
3
4
  import { replaceStagingUrl } from "../../util/url";
4
5
  const System = _ref => {
@@ -8,6 +9,15 @@ const System = _ref => {
8
9
  ...props
9
10
  } = _ref;
10
11
  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]);
12
+ if (!globalThis.window) {
13
+ var _system$scope, _moduleContext$_syste;
14
+ const moduleContext = useContext(ModuleContext);
15
+ (_moduleContext$_syste = moduleContext[_system$scope = system.scope]) !== null && _moduleContext$_syste !== void 0 ? _moduleContext$_syste : moduleContext[_system$scope] = {
16
+ url: new URL('mf-manifest.json', system.url).toString(),
17
+ modules: new Set()
18
+ };
19
+ moduleContext[system.scope].modules.add(system.module);
20
+ }
11
21
  return React.createElement(React.Suspense, {
12
22
  fallback: fallback || ''
13
23
  }, React.createElement(Component, props));
package/dist/esm/index.js CHANGED
@@ -17,4 +17,5 @@ import * as _dialog from './calls/dialogs/index';
17
17
  export { _dialog as dialog };
18
18
  export * from './util/initModuleFederationSharing';
19
19
  export * from './util/bindChaynsApi';
20
- export * from './util/appStorage';
20
+ export * from './util/appStorage';
21
+ export * from './util/collectCssChunks';
@@ -0,0 +1,39 @@
1
+ const remoteInfoCache = {};
2
+ const loadRemoteInfo = async url => {
3
+ if (remoteInfoCache[url]) {
4
+ return remoteInfoCache[url];
5
+ }
6
+ const res = await fetch(url);
7
+ if (res.status === 200) {
8
+ const info = await res.json();
9
+ remoteInfoCache[url] = info;
10
+ return info;
11
+ }
12
+ if (res.status === 404) {
13
+ remoteInfoCache[url] = null;
14
+ return null;
15
+ }
16
+ throw new Error(`Could not load remote info from ${url}`);
17
+ };
18
+ export const collectCssChunks = async modules => {
19
+ const p = Object.values(modules).map(async module => {
20
+ const info = await loadRemoteInfo(module.url);
21
+ const chunks = [];
22
+ info === null || info === void 0 || info.exposes.forEach(exposes => {
23
+ if (module.modules.has(exposes.path)) {
24
+ var _exposes$assets$css, _exposes$assets;
25
+ const {
26
+ sync = [],
27
+ async = []
28
+ } = (_exposes$assets$css = (_exposes$assets = exposes.assets) === null || _exposes$assets === void 0 ? void 0 : _exposes$assets.css) !== null && _exposes$assets$css !== void 0 ? _exposes$assets$css : {};
29
+ [...sync, ...async].forEach(chunk => {
30
+ const url = new URL(chunk, module.url);
31
+ chunks.push(`<link rel="stylesheet" href="${url}">`);
32
+ });
33
+ }
34
+ });
35
+ return chunks;
36
+ });
37
+ const r = await Promise.allSettled(p);
38
+ return r.flatMap(v => v.status === 'fulfilled' ? v.value : []).join('');
39
+ };
@@ -1,2 +1,3 @@
1
1
  export * from './hydrationContext';
2
2
  export * from './DefaultLoginDialogOptions';
3
+ export * from './moduleContext';
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ export type ModuleContextValueType = Record<string, {
3
+ url: string;
4
+ modules: Set<string>;
5
+ }>;
6
+ export declare let ModuleContext: React.Context<ModuleContextValueType>;
@@ -17,3 +17,4 @@ export * as dialog from './calls/dialogs/index';
17
17
  export * from './util/initModuleFederationSharing';
18
18
  export * from './util/bindChaynsApi';
19
19
  export * from './util/appStorage';
20
+ export * from './util/collectCssChunks';
@@ -0,0 +1,2 @@
1
+ import { ModuleContextValueType } from '../constants';
2
+ export declare const collectCssChunks: (modules: ModuleContextValueType) => Promise<string>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chayns-api",
3
- "version": "2.5.0-beta.0",
3
+ "version": "2.6.0-beta.0",
4
4
  "description": "new chayns api",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",