chayns-api 2.6.0-beta.9 → 2.6.1

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.
@@ -17,13 +17,14 @@ const System = ({
17
17
  }) => {
18
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]);
19
19
  if (!globalThis.window) {
20
- var _system$scope, _moduleContext$_syste;
20
+ var _moduleContext$system;
21
21
  const moduleContext = (0, _react.useContext)(_moduleContext.ModuleContext);
22
- (_moduleContext$_syste = moduleContext[_system$scope = system.scope]) !== null && _moduleContext$_syste !== void 0 ? _moduleContext$_syste : moduleContext[_system$scope] = {
22
+ const info = (_moduleContext$system = moduleContext[system.scope]) !== null && _moduleContext$system !== void 0 ? _moduleContext$system : {
23
23
  url: system.url,
24
24
  modules: new Set()
25
25
  };
26
- moduleContext[system.scope].modules.add(system.module);
26
+ info.modules.add(system.module);
27
+ moduleContext[system.scope] = info;
27
28
  }
28
29
  return _react.default.createElement(_react.default.Suspense, {
29
30
  fallback: fallback || ''
@@ -4,26 +4,50 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.collectCssChunks = void 0;
7
- const collectCssChunks = modules => {
8
- const instance = globalThis.moduleFederationRuntime.getInstance();
9
- const p = Object.values(modules).map(module => {
10
- const info = instance.snapshotHandler.manifestCache.get(module.url);
7
+ const remoteInfoCache = {};
8
+ const loadRemoteInfo = async url => {
9
+ if (!url.endsWith('/mf-manifest.json')) {
10
+ return null;
11
+ }
12
+ if (remoteInfoCache[url]) {
13
+ return remoteInfoCache[url];
14
+ }
15
+ const res = await fetch(url);
16
+ if (res.status === 200) {
17
+ const info = await res.json();
18
+ remoteInfoCache[url] = info;
19
+ return info;
20
+ }
21
+ if (res.status === 404) {
22
+ remoteInfoCache[url] = null;
23
+ return null;
24
+ }
25
+ throw new Error(`Could not load remote info from ${url}`);
26
+ };
27
+ const collectCssChunks = async modules => {
28
+ const p = Object.values(modules).map(async module => {
29
+ const info = await loadRemoteInfo(module.url);
11
30
  const chunks = [];
12
31
  info === null || info === void 0 || info.exposes.forEach(exposes => {
13
- if (exposes.path && module.modules.has(exposes.path)) {
32
+ if (module.modules.has(exposes.path)) {
14
33
  var _exposes$assets$css, _exposes$assets;
15
34
  const {
16
35
  sync = [],
17
36
  async = []
18
37
  } = (_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 : {};
19
- [...sync, ...async].forEach(chunk => {
38
+ sync.forEach(chunk => {
20
39
  const url = new URL(chunk, module.url);
21
40
  chunks.push(`<link rel="stylesheet" href="${url}">`);
22
41
  });
42
+ async.forEach(chunk => {
43
+ const url = new URL(chunk, module.url);
44
+ chunks.push(`<link rel="preload" href="${url}" as="style" onload="this.rel='stylesheet'">`);
45
+ });
23
46
  }
24
47
  });
25
48
  return chunks;
26
49
  });
27
- return p.flat().join('');
50
+ const r = await Promise.allSettled(p);
51
+ return r.flatMap(v => v.status === 'fulfilled' ? v.value : []).join('');
28
52
  };
29
53
  exports.collectCssChunks = collectCssChunks;
@@ -9,13 +9,14 @@ const System = ({
9
9
  }) => {
10
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
11
  if (!globalThis.window) {
12
- var _system$scope, _moduleContext$_syste;
12
+ var _moduleContext$system;
13
13
  const moduleContext = useContext(ModuleContext);
14
- (_moduleContext$_syste = moduleContext[_system$scope = system.scope]) !== null && _moduleContext$_syste !== void 0 ? _moduleContext$_syste : moduleContext[_system$scope] = {
14
+ const info = (_moduleContext$system = moduleContext[system.scope]) !== null && _moduleContext$system !== void 0 ? _moduleContext$system : {
15
15
  url: system.url,
16
16
  modules: new Set()
17
17
  };
18
- moduleContext[system.scope].modules.add(system.module);
18
+ info.modules.add(system.module);
19
+ moduleContext[system.scope] = info;
19
20
  }
20
21
  return React.createElement(React.Suspense, {
21
22
  fallback: fallback || ''
@@ -1,22 +1,46 @@
1
- export const collectCssChunks = modules => {
2
- const instance = globalThis.moduleFederationRuntime.getInstance();
3
- const p = Object.values(modules).map(module => {
4
- const info = instance.snapshotHandler.manifestCache.get(module.url);
1
+ const remoteInfoCache = {};
2
+ const loadRemoteInfo = async url => {
3
+ if (!url.endsWith('/mf-manifest.json')) {
4
+ return null;
5
+ }
6
+ if (remoteInfoCache[url]) {
7
+ return remoteInfoCache[url];
8
+ }
9
+ const res = await fetch(url);
10
+ if (res.status === 200) {
11
+ const info = await res.json();
12
+ remoteInfoCache[url] = info;
13
+ return info;
14
+ }
15
+ if (res.status === 404) {
16
+ remoteInfoCache[url] = null;
17
+ return null;
18
+ }
19
+ throw new Error(`Could not load remote info from ${url}`);
20
+ };
21
+ export const collectCssChunks = async modules => {
22
+ const p = Object.values(modules).map(async module => {
23
+ const info = await loadRemoteInfo(module.url);
5
24
  const chunks = [];
6
25
  info === null || info === void 0 || info.exposes.forEach(exposes => {
7
- if (exposes.path && module.modules.has(exposes.path)) {
26
+ if (module.modules.has(exposes.path)) {
8
27
  var _exposes$assets$css, _exposes$assets;
9
28
  const {
10
29
  sync = [],
11
30
  async = []
12
31
  } = (_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 : {};
13
- [...sync, ...async].forEach(chunk => {
32
+ sync.forEach(chunk => {
14
33
  const url = new URL(chunk, module.url);
15
34
  chunks.push(`<link rel="stylesheet" href="${url}">`);
16
35
  });
36
+ async.forEach(chunk => {
37
+ const url = new URL(chunk, module.url);
38
+ chunks.push(`<link rel="preload" href="${url}" as="style" onload="this.rel='stylesheet'">`);
39
+ });
17
40
  }
18
41
  });
19
42
  return chunks;
20
43
  });
21
- return p.flat().join('');
44
+ const r = await Promise.allSettled(p);
45
+ return r.flatMap(v => v.status === 'fulfilled' ? v.value : []).join('');
22
46
  };
@@ -83,6 +83,10 @@ export interface BaseDialog {
83
83
  config?: any;
84
84
  };
85
85
  hideDragHandle?: boolean;
86
+ onLinkClick?: (attributes: {
87
+ [key: string]: string;
88
+ }) => void;
89
+ footer?: string;
86
90
  }
87
91
  export type Dialog<T = object> = BaseDialog & (DialogAlert | DialogConfirm | DialogInput | DialogModule<T> | DialogIFrame<T> | DialogSelect | DialogDate | DialogToast | DialogSignature | DialogFileSelect);
88
92
  export interface DialogSignature {
@@ -1,2 +1,8 @@
1
1
  import { ModuleContextValueType } from '../constants';
2
- export declare const collectCssChunks: (modules: ModuleContextValueType) => string;
2
+ /**
3
+ * Collects the css chunks from all modules rendered during SSR
4
+ * @experimental Handling for async chunks is not final and subject to change.
5
+ * Eventually a parameter for the rendered html might be added to analyze the async chunks
6
+ * @param modules
7
+ */
8
+ 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.6.0-beta.9",
3
+ "version": "2.6.1",
4
4
  "description": "new chayns api",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",