chayns-api 1.1.0-23 → 1.1.0-24

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.
@@ -77,9 +77,21 @@ const loadComponent = (scope, module, url, skipCompatMode = false, preventSingle
77
77
  environment
78
78
  } = Module.default;
79
79
  const shareScopes = await new Promise(resolve => {
80
+ // @ts-expect-error
81
+ if (typeof __webpack_share_scopes__ !== 'undefined') {
82
+ // @ts-expect-error
83
+ const shareScopes = __webpack_share_scopes__.default;
84
+ console.log('__webpack_share_scopes__', shareScopes);
85
+ const shareList = Object.entries(shareScopes.react).map(([k, v]) => ({
86
+ version: k,
87
+ from: v.from
88
+ }));
89
+ resolve(shareList);
90
+ }
80
91
  (0, _runtime.loadShareSync)('react', {
81
92
  resolver: shareOptions => {
82
93
  resolve(shareOptions);
94
+ console.log('mf runtime share scopes', shareOptions);
83
95
  return shareOptions[0];
84
96
  }
85
97
  });
@@ -72,18 +72,33 @@ const loadComponent = function (scope, module, url) {
72
72
  environment
73
73
  } = Module.default;
74
74
  const shareScopes = await new Promise(resolve => {
75
+ // @ts-expect-error
76
+ if (typeof __webpack_share_scopes__ !== 'undefined') {
77
+ // @ts-expect-error
78
+ const shareScopes = __webpack_share_scopes__.default;
79
+ console.log('__webpack_share_scopes__', shareScopes);
80
+ const shareList = Object.entries(shareScopes.react).map(_ref => {
81
+ let [k, v] = _ref;
82
+ return {
83
+ version: k,
84
+ from: v.from
85
+ };
86
+ });
87
+ resolve(shareList);
88
+ }
75
89
  loadShareSync('react', {
76
90
  resolver: shareOptions => {
77
91
  resolve(shareOptions);
92
+ console.log('mf runtime share scopes', shareOptions);
78
93
  return shareOptions[0];
79
94
  }
80
95
  });
81
96
  });
82
- const matchReactVersion = requiredVersion && semver.satisfies(hostVersion, requiredVersion) && !shareScopes.some(_ref => {
97
+ const matchReactVersion = requiredVersion && semver.satisfies(hostVersion, requiredVersion) && !shareScopes.some(_ref2 => {
83
98
  let {
84
99
  version,
85
100
  from
86
- } = _ref;
101
+ } = _ref2;
87
102
  return semver.gt(version, hostVersion) && semver.satisfies(version, requiredVersion) || scope === from.split('-').join('_');
88
103
  });
89
104
  if (!matchReactVersion || environment !== 'production' || process.env.NODE_ENV === 'development') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chayns-api",
3
- "version": "1.1.0-23",
3
+ "version": "1.1.0-24",
4
4
  "description": "new chayns api",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -1,59 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.semaphore = exports.default = void 0;
7
- var _react = _interopRequireWildcard(require("react"));
8
- var _semaphoreAsyncAwait = _interopRequireDefault(require("semaphore-async-await"));
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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 = {};
13
- const useDynamicScript = args => {
14
- const [ready, setReady] = _react.default.useState(false);
15
- const [failed, setFailed] = _react.default.useState(false);
16
- (0, _react.useEffect)(() => {
17
- if (!args.url) {
18
- return undefined;
19
- }
20
- const element = document.createElement('script');
21
- element.src = args.url;
22
- element.type = 'text/javascript';
23
- element.async = true;
24
- setReady(false);
25
- setFailed(false);
26
- if (!(args.scope in semaphore)) {
27
- semaphore[args.scope] = new _semaphoreAsyncAwait.default(1);
28
- }
29
- (async () => {
30
- await semaphore[args.scope].acquire();
31
- element.onload = () => {
32
- setReady(true);
33
- const listKey = args.scope + "_list";
34
- if (!window[listKey]) window[listKey] = [];
35
- window[listKey].push({
36
- url: args.url,
37
- container: window[args.scope]
38
- });
39
- window[args.scope] = null;
40
- };
41
- element.onerror = () => {
42
- setReady(false);
43
- setFailed(true);
44
- };
45
- document.head.appendChild(element);
46
- })();
47
- return () => {
48
- semaphore[args.scope].release();
49
- if (document.head.contains(element)) {
50
- document.head.removeChild(element);
51
- }
52
- };
53
- }, [args.url]);
54
- return {
55
- ready,
56
- failed
57
- };
58
- };
59
- var _default = exports.default = useDynamicScript;
@@ -1,50 +0,0 @@
1
- import React, { useEffect } from 'react';
2
- import Semaphore from 'semaphore-async-await';
3
- export const semaphore = {};
4
- const useDynamicScript = args => {
5
- const [ready, setReady] = React.useState(false);
6
- const [failed, setFailed] = React.useState(false);
7
- useEffect(() => {
8
- if (!args.url) {
9
- return undefined;
10
- }
11
- const element = document.createElement('script');
12
- element.src = args.url;
13
- element.type = 'text/javascript';
14
- element.async = true;
15
- setReady(false);
16
- setFailed(false);
17
- if (!(args.scope in semaphore)) {
18
- semaphore[args.scope] = new Semaphore(1);
19
- }
20
- (async () => {
21
- await semaphore[args.scope].acquire();
22
- element.onload = () => {
23
- setReady(true);
24
- const listKey = args.scope + "_list";
25
- if (!window[listKey]) window[listKey] = [];
26
- window[listKey].push({
27
- url: args.url,
28
- container: window[args.scope]
29
- });
30
- window[args.scope] = null;
31
- };
32
- element.onerror = () => {
33
- setReady(false);
34
- setFailed(true);
35
- };
36
- document.head.appendChild(element);
37
- })();
38
- return () => {
39
- semaphore[args.scope].release();
40
- if (document.head.contains(element)) {
41
- document.head.removeChild(element);
42
- }
43
- };
44
- }, [args.url]);
45
- return {
46
- ready,
47
- failed
48
- };
49
- };
50
- export default useDynamicScript;
@@ -1,9 +0,0 @@
1
- export declare const semaphore: {};
2
- declare const useDynamicScript: (args: {
3
- url: string | undefined;
4
- scope: string | undefined;
5
- }) => {
6
- ready: boolean;
7
- failed: boolean;
8
- };
9
- export default useDynamicScript;