chayns-api 2.5.0-beta.0 → 2.6.0-beta.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.
@@ -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
@@ -167,6 +167,18 @@ var _loadComponent = _interopRequireWildcard(require("./host/module/utils/loadCo
167
167
  var _DialogHandler = _interopRequireDefault(require("./handler/DialogHandler"));
168
168
  var _dialog = _interopRequireWildcard(require("./calls/dialogs/index"));
169
169
  exports.dialog = _dialog;
170
+ var _plugins = require("./plugins");
171
+ Object.keys(_plugins).forEach(function (key) {
172
+ if (key === "default" || key === "__esModule") return;
173
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
174
+ if (key in exports && exports[key] === _plugins[key]) return;
175
+ Object.defineProperty(exports, key, {
176
+ enumerable: true,
177
+ get: function () {
178
+ return _plugins[key];
179
+ }
180
+ });
181
+ });
170
182
  var _initModuleFederationSharing = require("./util/initModuleFederationSharing");
171
183
  Object.keys(_initModuleFederationSharing).forEach(function (key) {
172
184
  if (key === "default" || key === "__esModule") return;
@@ -203,6 +215,18 @@ Object.keys(_appStorage).forEach(function (key) {
203
215
  }
204
216
  });
205
217
  });
218
+ var _collectCssChunks = require("./util/collectCssChunks");
219
+ Object.keys(_collectCssChunks).forEach(function (key) {
220
+ if (key === "default" || key === "__esModule") return;
221
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
222
+ if (key in exports && exports[key] === _collectCssChunks[key]) return;
223
+ Object.defineProperty(exports, key, {
224
+ enumerable: true,
225
+ get: function () {
226
+ return _collectCssChunks[key];
227
+ }
228
+ });
229
+ });
206
230
  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
231
  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
232
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SSRManifestPlugin = void 0;
7
+ const SSRManifestPlugin = () => {
8
+ return {
9
+ name: 'ssr-manifest',
10
+ loadRemoteSnapshot(args) {
11
+ var _ref, _ref$ssrPublicPath;
12
+ if (args.from !== 'manifest') {
13
+ return args;
14
+ }
15
+ (_ref$ssrPublicPath = (_ref = args.remoteSnapshot).ssrPublicPath) !== null && _ref$ssrPublicPath !== void 0 ? _ref$ssrPublicPath : _ref.ssrPublicPath = new URL('.', args.manifestUrl).href;
16
+ if ('remoteEntry' in args.remoteSnapshot) {
17
+ var _args$remoteSnapshot, _args$remoteSnapshot$;
18
+ (_args$remoteSnapshot$ = (_args$remoteSnapshot = args.remoteSnapshot).ssrRemoteEntry) !== null && _args$remoteSnapshot$ !== void 0 ? _args$remoteSnapshot$ : _args$remoteSnapshot.ssrRemoteEntry = args.remoteSnapshot.remoteEntry;
19
+ }
20
+ if ('remoteEntryType' in args.remoteSnapshot) {
21
+ var _args$remoteSnapshot2, _args$remoteSnapshot3;
22
+ (_args$remoteSnapshot3 = (_args$remoteSnapshot2 = args.remoteSnapshot).ssrRemoteEntryType) !== null && _args$remoteSnapshot3 !== void 0 ? _args$remoteSnapshot3 : _args$remoteSnapshot2.ssrRemoteEntryType = args.remoteSnapshot.remoteEntryType;
23
+ }
24
+ return args;
25
+ }
26
+ };
27
+ };
28
+ exports.SSRManifestPlugin = SSRManifestPlugin;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "SSRManifestPlugin", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _SSRManifestPlugin.SSRManifestPlugin;
10
+ }
11
+ });
12
+ var _SSRManifestPlugin = require("./SSRManifestPlugin");
@@ -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;
@@ -13,7 +13,8 @@ try {
13
13
  ReactDOMClient = require('react-dom/client');
14
14
  } catch (e) {}
15
15
  const initModuleFederationSharing = ({
16
- name
16
+ name,
17
+ plugins = []
17
18
  }) => {
18
19
  if (globalThis.moduleFederationRuntime) {
19
20
  return;
@@ -50,7 +51,7 @@ const initModuleFederationSharing = ({
50
51
  name: name !== null && name !== void 0 ? name : '',
51
52
  remotes: [],
52
53
  shared,
53
- plugins: [(0, _SequentialLoadPlugin.SequentialLoadPlugin)()]
54
+ plugins: [(0, _SequentialLoadPlugin.SequentialLoadPlugin)(), ...plugins]
54
55
  });
55
56
  };
56
57
  exports.initModuleFederationSharing = initModuleFederationSharing;
@@ -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
@@ -15,6 +15,8 @@ export { default as loadComponent, loadModule } from './host/module/utils/loadCo
15
15
  export { default as DialogHandler } from './handler/DialogHandler';
16
16
  import * as _dialog from './calls/dialogs/index';
17
17
  export { _dialog as dialog };
18
+ export * from './plugins';
18
19
  export * from './util/initModuleFederationSharing';
19
20
  export * from './util/bindChaynsApi';
20
- export * from './util/appStorage';
21
+ export * from './util/appStorage';
22
+ export * from './util/collectCssChunks';
@@ -0,0 +1,21 @@
1
+ export const SSRManifestPlugin = () => {
2
+ return {
3
+ name: 'ssr-manifest',
4
+ loadRemoteSnapshot(args) {
5
+ var _ref, _ref$ssrPublicPath;
6
+ if (args.from !== 'manifest') {
7
+ return args;
8
+ }
9
+ (_ref$ssrPublicPath = (_ref = args.remoteSnapshot).ssrPublicPath) !== null && _ref$ssrPublicPath !== void 0 ? _ref$ssrPublicPath : _ref.ssrPublicPath = new URL('.', args.manifestUrl).href;
10
+ if ('remoteEntry' in args.remoteSnapshot) {
11
+ var _args$remoteSnapshot, _args$remoteSnapshot$;
12
+ (_args$remoteSnapshot$ = (_args$remoteSnapshot = args.remoteSnapshot).ssrRemoteEntry) !== null && _args$remoteSnapshot$ !== void 0 ? _args$remoteSnapshot$ : _args$remoteSnapshot.ssrRemoteEntry = args.remoteSnapshot.remoteEntry;
13
+ }
14
+ if ('remoteEntryType' in args.remoteSnapshot) {
15
+ var _args$remoteSnapshot2, _args$remoteSnapshot3;
16
+ (_args$remoteSnapshot3 = (_args$remoteSnapshot2 = args.remoteSnapshot).ssrRemoteEntryType) !== null && _args$remoteSnapshot3 !== void 0 ? _args$remoteSnapshot3 : _args$remoteSnapshot2.ssrRemoteEntryType = args.remoteSnapshot.remoteEntryType;
17
+ }
18
+ return args;
19
+ }
20
+ };
21
+ };
@@ -0,0 +1 @@
1
+ export { SSRManifestPlugin } from './SSRManifestPlugin';
@@ -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
+ };
@@ -7,7 +7,8 @@ try {
7
7
  } catch (e) {}
8
8
  export const initModuleFederationSharing = _ref => {
9
9
  let {
10
- name
10
+ name,
11
+ plugins = []
11
12
  } = _ref;
12
13
  if (globalThis.moduleFederationRuntime) {
13
14
  return;
@@ -44,6 +45,6 @@ export const initModuleFederationSharing = _ref => {
44
45
  name: name !== null && name !== void 0 ? name : '',
45
46
  remotes: [],
46
47
  shared,
47
- plugins: [SequentialLoadPlugin()]
48
+ plugins: [SequentialLoadPlugin(), ...plugins]
48
49
  });
49
50
  };
@@ -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>;
@@ -14,6 +14,8 @@ export { default as StaticChaynsApi } from './wrapper/StaticChaynsApi';
14
14
  export { default as loadComponent, loadModule } from './host/module/utils/loadComponent';
15
15
  export { default as DialogHandler } from './handler/DialogHandler';
16
16
  export * as dialog from './calls/dialogs/index';
17
+ export * from './plugins';
17
18
  export * from './util/initModuleFederationSharing';
18
19
  export * from './util/bindChaynsApi';
19
20
  export * from './util/appStorage';
21
+ export * from './util/collectCssChunks';
@@ -0,0 +1,5 @@
1
+ import type { FederationRuntimePlugin } from '@module-federation/enhanced/runtime';
2
+ /**
3
+ * Adds SSR metadata and resolves public path when using manifest
4
+ */
5
+ export declare const SSRManifestPlugin: () => FederationRuntimePlugin;
@@ -0,0 +1 @@
1
+ export { SSRManifestPlugin } from './SSRManifestPlugin';
@@ -0,0 +1,2 @@
1
+ import { ModuleContextValueType } from '../constants';
2
+ export declare const collectCssChunks: (modules: ModuleContextValueType) => Promise<string>;
@@ -1,3 +1,4 @@
1
- export declare const initModuleFederationSharing: ({ name }: {
1
+ export declare const initModuleFederationSharing: ({ name, plugins }: {
2
2
  name: any;
3
+ plugins?: never[] | undefined;
3
4
  }) => void;
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.1",
4
4
  "description": "new chayns api",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",