@zstackui/qiankun 2.6.3-beta-5

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.
Files changed (155) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +116 -0
  3. package/dist/index.umd.js +8681 -0
  4. package/dist/index.umd.js.map +1 -0
  5. package/dist/index.umd.min.js +4 -0
  6. package/dist/index.umd.min.js.map +1 -0
  7. package/dist/src/__tests__/globalState.test.d.ts +5 -0
  8. package/dist/src/__tests__/utils.test.d.ts +1 -0
  9. package/dist/src/addons/engineFlag.d.ts +6 -0
  10. package/dist/src/addons/index.d.ts +6 -0
  11. package/dist/src/addons/runtimePublicPath.d.ts +6 -0
  12. package/dist/src/apis.d.ts +7 -0
  13. package/dist/src/effects.d.ts +3 -0
  14. package/dist/src/error.d.ts +3 -0
  15. package/dist/src/errorHandler.d.ts +7 -0
  16. package/dist/src/globalState.d.ts +7 -0
  17. package/dist/src/index.d.ts +11 -0
  18. package/dist/src/interfaces.d.ts +107 -0
  19. package/dist/src/loader.d.ts +8 -0
  20. package/dist/src/prefetch.d.ts +14 -0
  21. package/dist/src/sandbox/__tests__/common.test.d.ts +5 -0
  22. package/dist/src/sandbox/__tests__/proxySandbox.test.d.ts +10 -0
  23. package/dist/src/sandbox/common.d.ts +21 -0
  24. package/dist/src/sandbox/index.d.ts +40 -0
  25. package/dist/src/sandbox/legacy/__tests__/sandbox.test.d.ts +5 -0
  26. package/dist/src/sandbox/legacy/sandbox.d.ts +28 -0
  27. package/dist/src/sandbox/patchers/__tests__/css.test.d.ts +5 -0
  28. package/dist/src/sandbox/patchers/__tests__/interval.test.d.ts +5 -0
  29. package/dist/src/sandbox/patchers/css.d.ts +17 -0
  30. package/dist/src/sandbox/patchers/dynamicAppend/__tests__/common.test.d.ts +1 -0
  31. package/dist/src/sandbox/patchers/dynamicAppend/common.d.ts +22 -0
  32. package/dist/src/sandbox/patchers/dynamicAppend/forLooseSandbox.d.ts +17 -0
  33. package/dist/src/sandbox/patchers/dynamicAppend/forStrictSandbox.d.ts +12 -0
  34. package/dist/src/sandbox/patchers/dynamicAppend/index.d.ts +6 -0
  35. package/dist/src/sandbox/patchers/historyListener.d.ts +5 -0
  36. package/dist/src/sandbox/patchers/index.d.ts +9 -0
  37. package/dist/src/sandbox/patchers/interval.d.ts +5 -0
  38. package/dist/src/sandbox/patchers/windowListener.d.ts +5 -0
  39. package/dist/src/sandbox/proxySandbox.d.ts +23 -0
  40. package/dist/src/sandbox/snapshotSandbox.d.ts +20 -0
  41. package/dist/src/utils.d.ts +44 -0
  42. package/dist/src/version.d.ts +1 -0
  43. package/es/addons/engineFlag.d.ts +6 -0
  44. package/es/addons/engineFlag.js +50 -0
  45. package/es/addons/index.d.ts +6 -0
  46. package/es/addons/index.js +13 -0
  47. package/es/addons/runtimePublicPath.d.ts +6 -0
  48. package/es/addons/runtimePublicPath.js +57 -0
  49. package/es/apis.d.ts +7 -0
  50. package/es/apis.js +278 -0
  51. package/es/effects.d.ts +3 -0
  52. package/es/effects.js +33 -0
  53. package/es/error.d.ts +3 -0
  54. package/es/error.js +16 -0
  55. package/es/errorHandler.d.ts +7 -0
  56. package/es/errorHandler.js +13 -0
  57. package/es/globalState.d.ts +7 -0
  58. package/es/globalState.js +101 -0
  59. package/es/index.d.ts +11 -0
  60. package/es/index.js +11 -0
  61. package/es/interfaces.d.ts +107 -0
  62. package/es/interfaces.js +8 -0
  63. package/es/loader.d.ts +8 -0
  64. package/es/loader.js +600 -0
  65. package/es/prefetch.d.ts +14 -0
  66. package/es/prefetch.js +125 -0
  67. package/es/sandbox/common.d.ts +21 -0
  68. package/es/sandbox/common.js +157 -0
  69. package/es/sandbox/index.d.ts +40 -0
  70. package/es/sandbox/index.js +105 -0
  71. package/es/sandbox/legacy/sandbox.d.ts +28 -0
  72. package/es/sandbox/legacy/sandbox.js +142 -0
  73. package/es/sandbox/patchers/css.d.ts +17 -0
  74. package/es/sandbox/patchers/css.js +186 -0
  75. package/es/sandbox/patchers/dynamicAppend/common.d.ts +22 -0
  76. package/es/sandbox/patchers/dynamicAppend/common.js +306 -0
  77. package/es/sandbox/patchers/dynamicAppend/forLooseSandbox.d.ts +17 -0
  78. package/es/sandbox/patchers/dynamicAppend/forLooseSandbox.js +77 -0
  79. package/es/sandbox/patchers/dynamicAppend/forStrictSandbox.d.ts +12 -0
  80. package/es/sandbox/patchers/dynamicAppend/forStrictSandbox.js +103 -0
  81. package/es/sandbox/patchers/dynamicAppend/index.d.ts +6 -0
  82. package/es/sandbox/patchers/dynamicAppend/index.js +6 -0
  83. package/es/sandbox/patchers/historyListener.d.ts +5 -0
  84. package/es/sandbox/patchers/historyListener.js +54 -0
  85. package/es/sandbox/patchers/index.d.ts +9 -0
  86. package/es/sandbox/patchers/index.js +45 -0
  87. package/es/sandbox/patchers/interval.d.ts +5 -0
  88. package/es/sandbox/patchers/interval.js +34 -0
  89. package/es/sandbox/patchers/windowListener.d.ts +5 -0
  90. package/es/sandbox/patchers/windowListener.js +34 -0
  91. package/es/sandbox/proxySandbox.d.ts +23 -0
  92. package/es/sandbox/proxySandbox.js +315 -0
  93. package/es/sandbox/snapshotSandbox.d.ts +20 -0
  94. package/es/sandbox/snapshotSandbox.js +59 -0
  95. package/es/utils.d.ts +44 -0
  96. package/es/utils.js +215 -0
  97. package/es/version.d.ts +1 -0
  98. package/es/version.js +1 -0
  99. package/lib/addons/engineFlag.d.ts +6 -0
  100. package/lib/addons/engineFlag.js +55 -0
  101. package/lib/addons/index.d.ts +6 -0
  102. package/lib/addons/index.js +21 -0
  103. package/lib/addons/runtimePublicPath.d.ts +6 -0
  104. package/lib/addons/runtimePublicPath.js +63 -0
  105. package/lib/apis.d.ts +7 -0
  106. package/lib/apis.js +288 -0
  107. package/lib/effects.d.ts +3 -0
  108. package/lib/effects.js +42 -0
  109. package/lib/error.d.ts +3 -0
  110. package/lib/error.js +23 -0
  111. package/lib/errorHandler.d.ts +7 -0
  112. package/lib/errorHandler.js +33 -0
  113. package/lib/globalState.d.ts +7 -0
  114. package/lib/globalState.js +110 -0
  115. package/lib/index.d.ts +11 -0
  116. package/lib/index.js +89 -0
  117. package/lib/interfaces.d.ts +107 -0
  118. package/lib/interfaces.js +14 -0
  119. package/lib/loader.d.ts +8 -0
  120. package/lib/loader.js +606 -0
  121. package/lib/prefetch.d.ts +14 -0
  122. package/lib/prefetch.js +132 -0
  123. package/lib/sandbox/common.d.ts +21 -0
  124. package/lib/sandbox/common.js +169 -0
  125. package/lib/sandbox/index.d.ts +40 -0
  126. package/lib/sandbox/index.js +123 -0
  127. package/lib/sandbox/legacy/sandbox.d.ts +28 -0
  128. package/lib/sandbox/legacy/sandbox.js +148 -0
  129. package/lib/sandbox/patchers/css.d.ts +17 -0
  130. package/lib/sandbox/patchers/css.js +193 -0
  131. package/lib/sandbox/patchers/dynamicAppend/common.d.ts +22 -0
  132. package/lib/sandbox/patchers/dynamicAppend/common.js +322 -0
  133. package/lib/sandbox/patchers/dynamicAppend/forLooseSandbox.d.ts +17 -0
  134. package/lib/sandbox/patchers/dynamicAppend/forLooseSandbox.js +84 -0
  135. package/lib/sandbox/patchers/dynamicAppend/forStrictSandbox.d.ts +12 -0
  136. package/lib/sandbox/patchers/dynamicAppend/forStrictSandbox.js +110 -0
  137. package/lib/sandbox/patchers/dynamicAppend/index.d.ts +6 -0
  138. package/lib/sandbox/patchers/dynamicAppend/index.js +19 -0
  139. package/lib/sandbox/patchers/historyListener.d.ts +5 -0
  140. package/lib/sandbox/patchers/historyListener.js +62 -0
  141. package/lib/sandbox/patchers/index.d.ts +9 -0
  142. package/lib/sandbox/patchers/index.js +57 -0
  143. package/lib/sandbox/patchers/interval.d.ts +5 -0
  144. package/lib/sandbox/patchers/interval.js +42 -0
  145. package/lib/sandbox/patchers/windowListener.d.ts +5 -0
  146. package/lib/sandbox/patchers/windowListener.js +42 -0
  147. package/lib/sandbox/proxySandbox.d.ts +23 -0
  148. package/lib/sandbox/proxySandbox.js +321 -0
  149. package/lib/sandbox/snapshotSandbox.d.ts +20 -0
  150. package/lib/sandbox/snapshotSandbox.js +65 -0
  151. package/lib/utils.d.ts +44 -0
  152. package/lib/utils.js +240 -0
  153. package/lib/version.d.ts +1 -0
  154. package/lib/version.js +7 -0
  155. package/package.json +137 -0
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @author Kuitos
3
+ * @since 2019-11-12
4
+ */
5
+ import type { FrameworkLifeCycles } from '../interfaces';
6
+ export default function getAddOn(global: Window, publicPath?: string): FrameworkLifeCycles<any>;
@@ -0,0 +1,57 @@
1
+ function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
2
+ function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
3
+ import { __awaiter } from "tslib";
4
+ var rawPublicPath = window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__;
5
+ export default function getAddOn(global) {
6
+ var publicPath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '/';
7
+ var hasMountedOnce = false;
8
+ return {
9
+ beforeLoad: function beforeLoad() {
10
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee() {
11
+ return _regenerator().w(function (_context) {
12
+ while (1) switch (_context.n) {
13
+ case 0:
14
+ // eslint-disable-next-line no-param-reassign
15
+ global.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ = publicPath;
16
+ case 1:
17
+ return _context.a(2);
18
+ }
19
+ }, _callee);
20
+ }));
21
+ },
22
+ beforeMount: function beforeMount() {
23
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee2() {
24
+ return _regenerator().w(function (_context2) {
25
+ while (1) switch (_context2.n) {
26
+ case 0:
27
+ if (hasMountedOnce) {
28
+ // eslint-disable-next-line no-param-reassign
29
+ global.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ = publicPath;
30
+ }
31
+ case 1:
32
+ return _context2.a(2);
33
+ }
34
+ }, _callee2);
35
+ }));
36
+ },
37
+ beforeUnmount: function beforeUnmount() {
38
+ return __awaiter(this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee3() {
39
+ return _regenerator().w(function (_context3) {
40
+ while (1) switch (_context3.n) {
41
+ case 0:
42
+ if (rawPublicPath === undefined) {
43
+ // eslint-disable-next-line no-param-reassign
44
+ delete global.__INJECTED_PUBLIC_PATH_BY_QIANKUN__;
45
+ } else {
46
+ // eslint-disable-next-line no-param-reassign
47
+ global.__INJECTED_PUBLIC_PATH_BY_QIANKUN__ = rawPublicPath;
48
+ }
49
+ hasMountedOnce = true;
50
+ case 1:
51
+ return _context3.a(2);
52
+ }
53
+ }, _callee3);
54
+ }));
55
+ }
56
+ };
57
+ }
package/es/apis.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import type { FrameworkConfiguration, FrameworkLifeCycles, LoadableApp, MicroApp, ObjectType, RegistrableApp } from './interfaces';
2
+ export declare let frameworkConfiguration: FrameworkConfiguration;
3
+ export declare function registerMicroApps<T extends ObjectType>(apps: Array<RegistrableApp<T>>, lifeCycles?: FrameworkLifeCycles<T>): void;
4
+ export declare function loadMicroApp<T extends ObjectType>(app: LoadableApp<T>, configuration?: FrameworkConfiguration & {
5
+ autoStart?: boolean;
6
+ }, lifeCycles?: FrameworkLifeCycles<T>): MicroApp;
7
+ export declare function start(opts?: FrameworkConfiguration): void;
package/es/apis.js ADDED
@@ -0,0 +1,278 @@
1
+ import _noop from "lodash/noop";
2
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
4
+ function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
5
+ function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
6
+ import { __awaiter, __rest } from "tslib";
7
+ import { mountRootParcel, registerApplication, start as startSingleSpa } from 'single-spa';
8
+ import { loadApp } from './loader';
9
+ import { doPrefetchStrategy } from './prefetch';
10
+ import { Deferred, getContainerXPath, toArray } from './utils';
11
+ var microApps = [];
12
+ export var frameworkConfiguration = {};
13
+ var started = false;
14
+ var defaultUrlRerouteOnly = true;
15
+ var frameworkStartedDefer = new Deferred();
16
+ var autoDowngradeForLowVersionBrowser = function autoDowngradeForLowVersionBrowser(configuration) {
17
+ var sandbox = configuration.sandbox,
18
+ singular = configuration.singular;
19
+ if (sandbox) {
20
+ if (!window.Proxy) {
21
+ console.warn('[qiankun] Miss window.Proxy, proxySandbox will degenerate into snapshotSandbox');
22
+ if (singular === false) {
23
+ console.warn('[qiankun] Setting singular as false may cause unexpected behavior while your browser not support window.Proxy');
24
+ }
25
+ return Object.assign(Object.assign({}, configuration), {
26
+ sandbox: _typeof(sandbox) === 'object' ? Object.assign(Object.assign({}, sandbox), {
27
+ loose: true
28
+ }) : {
29
+ loose: true
30
+ }
31
+ });
32
+ }
33
+ }
34
+ return configuration;
35
+ };
36
+ export function registerMicroApps(apps, lifeCycles) {
37
+ var _this = this;
38
+ // Each app only needs to be registered once
39
+ var unregisteredApps = apps.filter(function (app) {
40
+ return !microApps.some(function (registeredApp) {
41
+ return registeredApp.name === app.name;
42
+ });
43
+ });
44
+ microApps = [].concat(_toConsumableArray(microApps), _toConsumableArray(unregisteredApps));
45
+ unregisteredApps.forEach(function (app) {
46
+ var name = app.name,
47
+ activeRule = app.activeRule,
48
+ _app$loader = app.loader,
49
+ loader = _app$loader === void 0 ? _noop : _app$loader,
50
+ props = app.props,
51
+ appConfig = __rest(app, ["name", "activeRule", "loader", "props"]);
52
+ registerApplication({
53
+ name: name,
54
+ app: function app() {
55
+ return __awaiter(_this, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee3() {
56
+ var _this2 = this;
57
+ var _a, mount, otherMicroAppConfigs, _t;
58
+ return _regenerator().w(function (_context3) {
59
+ while (1) switch (_context3.n) {
60
+ case 0:
61
+ loader(true);
62
+ _context3.n = 1;
63
+ return frameworkStartedDefer.promise;
64
+ case 1:
65
+ _context3.n = 2;
66
+ return loadApp(Object.assign({
67
+ name: name,
68
+ props: props
69
+ }, appConfig), frameworkConfiguration, lifeCycles);
70
+ case 2:
71
+ _t = _context3.v;
72
+ _a = _t();
73
+ mount = _a.mount;
74
+ otherMicroAppConfigs = __rest(_a, ["mount"]);
75
+ return _context3.a(2, Object.assign({
76
+ mount: [function () {
77
+ return __awaiter(_this2, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee() {
78
+ return _regenerator().w(function (_context) {
79
+ while (1) switch (_context.n) {
80
+ case 0:
81
+ return _context.a(2, loader(true));
82
+ }
83
+ }, _callee);
84
+ }));
85
+ }].concat(_toConsumableArray(toArray(mount)), [function () {
86
+ return __awaiter(_this2, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee2() {
87
+ return _regenerator().w(function (_context2) {
88
+ while (1) switch (_context2.n) {
89
+ case 0:
90
+ return _context2.a(2, loader(false));
91
+ }
92
+ }, _callee2);
93
+ }));
94
+ }])
95
+ }, otherMicroAppConfigs));
96
+ }
97
+ }, _callee3);
98
+ }));
99
+ },
100
+ activeWhen: activeRule,
101
+ customProps: props
102
+ });
103
+ });
104
+ }
105
+ var appConfigPromiseGetterMap = new Map();
106
+ var containerMicroAppsMap = new Map();
107
+ export function loadMicroApp(app, configuration, lifeCycles) {
108
+ var _this3 = this;
109
+ var _a;
110
+ var props = app.props,
111
+ name = app.name;
112
+ var container = 'container' in app ? app.container : undefined;
113
+ // Must compute the container xpath at beginning to keep it consist around app running
114
+ // If we compute it every time, the container dom structure most probably been changed and result in a different xpath value
115
+ var containerXPath = getContainerXPath(container);
116
+ var appContainerXPathKey = "".concat(name, "-").concat(containerXPath);
117
+ var microApp;
118
+ var wrapParcelConfigForRemount = function wrapParcelConfigForRemount(config) {
119
+ var microAppConfig = config;
120
+ if (container) {
121
+ if (containerXPath) {
122
+ var containerMicroApps = containerMicroAppsMap.get(appContainerXPathKey);
123
+ if (containerMicroApps === null || containerMicroApps === void 0 ? void 0 : containerMicroApps.length) {
124
+ var mount = [function () {
125
+ return __awaiter(_this3, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee4() {
126
+ var prevLoadMicroApps, prevLoadMicroAppsWhichNotBroken;
127
+ return _regenerator().w(function (_context4) {
128
+ while (1) switch (_context4.n) {
129
+ case 0:
130
+ // While there are multiple micro apps mounted on the same container, we must wait until the prev instances all had unmounted
131
+ // Otherwise it will lead some concurrent issues
132
+ prevLoadMicroApps = containerMicroApps.slice(0, containerMicroApps.indexOf(microApp));
133
+ prevLoadMicroAppsWhichNotBroken = prevLoadMicroApps.filter(function (v) {
134
+ return v.getStatus() !== 'LOAD_ERROR' && v.getStatus() !== 'SKIP_BECAUSE_BROKEN';
135
+ });
136
+ _context4.n = 1;
137
+ return Promise.all(prevLoadMicroAppsWhichNotBroken.map(function (v) {
138
+ return v.unmountPromise;
139
+ }));
140
+ case 1:
141
+ return _context4.a(2);
142
+ }
143
+ }, _callee4);
144
+ }));
145
+ }].concat(_toConsumableArray(toArray(microAppConfig.mount)));
146
+ microAppConfig = Object.assign(Object.assign({}, config), {
147
+ mount: mount
148
+ });
149
+ }
150
+ }
151
+ }
152
+ return Object.assign(Object.assign({}, microAppConfig), {
153
+ // empty bootstrap hook which should not run twice while it calling from cached micro app
154
+ bootstrap: function bootstrap() {
155
+ return Promise.resolve();
156
+ }
157
+ });
158
+ };
159
+ /**
160
+ * using name + container xpath as the micro app instance id,
161
+ * it means if you rendering a micro app to a dom which have been rendered before,
162
+ * the micro app would not load and evaluate its lifecycles again
163
+ */
164
+ var memorizedLoadingFn = function memorizedLoadingFn() {
165
+ return __awaiter(_this3, void 0, void 0, /*#__PURE__*/_regenerator().m(function _callee5() {
166
+ var userConfiguration, $$cacheLifecycleByAppName, parcelConfigGetterPromise, _parcelConfigGetterPromise, parcelConfigObjectGetterPromise, _t2, _t3, _t4, _t5, _t6;
167
+ return _regenerator().w(function (_context5) {
168
+ while (1) switch (_context5.n) {
169
+ case 0:
170
+ userConfiguration = autoDowngradeForLowVersionBrowser(configuration !== null && configuration !== void 0 ? configuration : Object.assign(Object.assign({}, frameworkConfiguration), {
171
+ singular: false
172
+ }));
173
+ $$cacheLifecycleByAppName = userConfiguration.$$cacheLifecycleByAppName;
174
+ if (!container) {
175
+ _context5.n = 4;
176
+ break;
177
+ }
178
+ if (!$$cacheLifecycleByAppName) {
179
+ _context5.n = 2;
180
+ break;
181
+ }
182
+ parcelConfigGetterPromise = appConfigPromiseGetterMap.get(name);
183
+ if (!parcelConfigGetterPromise) {
184
+ _context5.n = 2;
185
+ break;
186
+ }
187
+ _t2 = wrapParcelConfigForRemount;
188
+ _context5.n = 1;
189
+ return parcelConfigGetterPromise;
190
+ case 1:
191
+ _t3 = _context5.v;
192
+ return _context5.a(2, _t2(_t3(container)));
193
+ case 2:
194
+ if (!containerXPath) {
195
+ _context5.n = 4;
196
+ break;
197
+ }
198
+ _parcelConfigGetterPromise = appConfigPromiseGetterMap.get(appContainerXPathKey);
199
+ if (!_parcelConfigGetterPromise) {
200
+ _context5.n = 4;
201
+ break;
202
+ }
203
+ _t4 = wrapParcelConfigForRemount;
204
+ _context5.n = 3;
205
+ return _parcelConfigGetterPromise;
206
+ case 3:
207
+ _t5 = _context5.v;
208
+ return _context5.a(2, _t4(_t5(container)));
209
+ case 4:
210
+ parcelConfigObjectGetterPromise = loadApp(app, userConfiguration, lifeCycles);
211
+ if (container) {
212
+ if ($$cacheLifecycleByAppName) {
213
+ appConfigPromiseGetterMap.set(name, parcelConfigObjectGetterPromise);
214
+ } else if (containerXPath) appConfigPromiseGetterMap.set(appContainerXPathKey, parcelConfigObjectGetterPromise);
215
+ }
216
+ _context5.n = 5;
217
+ return parcelConfigObjectGetterPromise;
218
+ case 5:
219
+ _t6 = _context5.v;
220
+ return _context5.a(2, _t6(container));
221
+ }
222
+ }, _callee5);
223
+ }));
224
+ };
225
+ if (!started && (configuration === null || configuration === void 0 ? void 0 : configuration.autoStart) !== false) {
226
+ // We need to invoke start method of single-spa as the popstate event should be dispatched while the main app calling pushState/replaceState automatically,
227
+ // but in single-spa it will check the start status before it dispatch popstate
228
+ // see https://github.com/single-spa/single-spa/blob/f28b5963be1484583a072c8145ac0b5a28d91235/src/navigation/navigation-events.js#L101
229
+ // ref https://github.com/umijs/qiankun/pull/1071
230
+ startSingleSpa({
231
+ urlRerouteOnly: (_a = frameworkConfiguration.urlRerouteOnly) !== null && _a !== void 0 ? _a : defaultUrlRerouteOnly
232
+ });
233
+ }
234
+ microApp = mountRootParcel(memorizedLoadingFn, Object.assign({
235
+ domElement: document.createElement('div')
236
+ }, props));
237
+ if (container) {
238
+ if (containerXPath) {
239
+ // Store the microApps which they mounted on the same container
240
+ var microAppsRef = containerMicroAppsMap.get(appContainerXPathKey) || [];
241
+ microAppsRef.push(microApp);
242
+ containerMicroAppsMap.set(appContainerXPathKey, microAppsRef);
243
+ var cleanup = function cleanup() {
244
+ var index = microAppsRef.indexOf(microApp);
245
+ microAppsRef.splice(index, 1);
246
+ // @ts-ignore
247
+ microApp = null;
248
+ };
249
+ // gc after unmount
250
+ microApp.unmountPromise.then(cleanup).catch(cleanup);
251
+ }
252
+ }
253
+ return microApp;
254
+ }
255
+ export function start() {
256
+ var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
257
+ frameworkConfiguration = Object.assign({
258
+ prefetch: true,
259
+ singular: true,
260
+ sandbox: true
261
+ }, opts);
262
+ var _frameworkConfigurati = frameworkConfiguration,
263
+ prefetch = _frameworkConfigurati.prefetch,
264
+ sandbox = _frameworkConfigurati.sandbox,
265
+ singular = _frameworkConfigurati.singular,
266
+ _frameworkConfigurati2 = _frameworkConfigurati.urlRerouteOnly,
267
+ urlRerouteOnly = _frameworkConfigurati2 === void 0 ? defaultUrlRerouteOnly : _frameworkConfigurati2,
268
+ importEntryOpts = __rest(frameworkConfiguration, ["prefetch", "sandbox", "singular", "urlRerouteOnly"]);
269
+ if (prefetch) {
270
+ doPrefetchStrategy(microApps, prefetch, importEntryOpts);
271
+ }
272
+ frameworkConfiguration = autoDowngradeForLowVersionBrowser(frameworkConfiguration);
273
+ startSingleSpa({
274
+ urlRerouteOnly: urlRerouteOnly
275
+ });
276
+ started = true;
277
+ frameworkStartedDefer.resolve();
278
+ }
@@ -0,0 +1,3 @@
1
+ export declare function setDefaultMountApp(defaultAppLink: string): void;
2
+ export declare function runDefaultMountEffects(defaultAppLink: string): void;
3
+ export declare function runAfterFirstMounted(effect: () => void): void;
package/es/effects.js ADDED
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @author Kuitos
3
+ * @since 2019-02-19
4
+ */
5
+ import { getMountedApps, navigateToUrl } from 'single-spa';
6
+ var firstMountLogLabel = '[qiankun] first app mounted';
7
+ if (process.env.NODE_ENV === 'development') {
8
+ console.time(firstMountLogLabel);
9
+ }
10
+ export function setDefaultMountApp(defaultAppLink) {
11
+ // can not use addEventListener once option for ie support
12
+ window.addEventListener('single-spa:no-app-change', function listener() {
13
+ var mountedApps = getMountedApps();
14
+ if (!mountedApps.length) {
15
+ navigateToUrl(defaultAppLink);
16
+ }
17
+ window.removeEventListener('single-spa:no-app-change', listener);
18
+ });
19
+ }
20
+ export function runDefaultMountEffects(defaultAppLink) {
21
+ console.warn('[qiankun] runDefaultMountEffects will be removed in next version, please use setDefaultMountApp instead');
22
+ setDefaultMountApp(defaultAppLink);
23
+ }
24
+ export function runAfterFirstMounted(effect) {
25
+ // can not use addEventListener once option for ie support
26
+ window.addEventListener('single-spa:first-mount', function listener() {
27
+ if (process.env.NODE_ENV === 'development') {
28
+ console.timeEnd(firstMountLogLabel);
29
+ }
30
+ effect();
31
+ window.removeEventListener('single-spa:first-mount', listener);
32
+ });
33
+ }
package/es/error.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export declare class QiankunError extends Error {
2
+ constructor(message: string);
3
+ }
package/es/error.js ADDED
@@ -0,0 +1,16 @@
1
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
2
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
+ import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
4
+ import _isNativeReflectConstruct from "@babel/runtime/helpers/esm/isNativeReflectConstruct";
5
+ import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
6
+ import _inherits from "@babel/runtime/helpers/esm/inherits";
7
+ import _wrapNativeSuper from "@babel/runtime/helpers/esm/wrapNativeSuper";
8
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
9
+ export var QiankunError = /*#__PURE__*/function (_Error) {
10
+ function QiankunError(message) {
11
+ _classCallCheck(this, QiankunError);
12
+ return _callSuper(this, QiankunError, ["[qiankun]: ".concat(message)]);
13
+ }
14
+ _inherits(QiankunError, _Error);
15
+ return _createClass(QiankunError);
16
+ }(/*#__PURE__*/_wrapNativeSuper(Error));
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @author Kuitos
3
+ * @since 2020-02-21
4
+ */
5
+ export { addErrorHandler, removeErrorHandler } from 'single-spa';
6
+ export declare function addGlobalUncaughtErrorHandler(errorHandler: OnErrorEventHandlerNonNull): void;
7
+ export declare function removeGlobalUncaughtErrorHandler(errorHandler: (...args: any[]) => any): void;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @author Kuitos
3
+ * @since 2020-02-21
4
+ */
5
+ export { addErrorHandler, removeErrorHandler } from 'single-spa';
6
+ export function addGlobalUncaughtErrorHandler(errorHandler) {
7
+ window.addEventListener('error', errorHandler);
8
+ window.addEventListener('unhandledrejection', errorHandler);
9
+ }
10
+ export function removeGlobalUncaughtErrorHandler(errorHandler) {
11
+ window.removeEventListener('error', errorHandler);
12
+ window.removeEventListener('unhandledrejection', errorHandler);
13
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @author dbkillerf6
3
+ * @since 2020-04-10
4
+ */
5
+ import type { MicroAppStateActions } from './interfaces';
6
+ export declare function initGlobalState(state?: Record<string, any>): MicroAppStateActions;
7
+ export declare function getMicroAppStateActions(id: string, isMaster?: boolean): MicroAppStateActions;
@@ -0,0 +1,101 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ import _cloneDeep from "lodash/cloneDeep";
3
+ /**
4
+ * @author dbkillerf6
5
+ * @since 2020-04-10
6
+ */
7
+ var globalState = {};
8
+ var deps = {};
9
+ // 触发全局监听
10
+ function emitGlobal(state, prevState) {
11
+ Object.keys(deps).forEach(function (id) {
12
+ if (deps[id] instanceof Function) {
13
+ deps[id](_cloneDeep(state), _cloneDeep(prevState));
14
+ }
15
+ });
16
+ }
17
+ export function initGlobalState() {
18
+ var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
19
+ if (process.env.NODE_ENV === 'development') {
20
+ console.warn("[qiankun] globalState tools will be removed in 3.0, pls don't use it!");
21
+ }
22
+ if (state === globalState) {
23
+ console.warn('[qiankun] state has not changed!');
24
+ } else {
25
+ var prevGlobalState = _cloneDeep(globalState);
26
+ globalState = _cloneDeep(state);
27
+ emitGlobal(globalState, prevGlobalState);
28
+ }
29
+ return getMicroAppStateActions("global-".concat(+new Date()), true);
30
+ }
31
+ export function getMicroAppStateActions(id, isMaster) {
32
+ return {
33
+ /**
34
+ * onGlobalStateChange 全局依赖监听
35
+ *
36
+ * 收集 setState 时所需要触发的依赖
37
+ *
38
+ * 限制条件:每个子应用只有一个激活状态的全局监听,新监听覆盖旧监听,若只是监听部分属性,请使用 onGlobalStateChange
39
+ *
40
+ * 这么设计是为了减少全局监听滥用导致的内存爆炸
41
+ *
42
+ * 依赖数据结构为:
43
+ * {
44
+ * {id}: callback
45
+ * }
46
+ *
47
+ * @param callback
48
+ * @param fireImmediately
49
+ */
50
+ onGlobalStateChange: function onGlobalStateChange(callback, fireImmediately) {
51
+ if (!(callback instanceof Function)) {
52
+ console.error('[qiankun] callback must be function!');
53
+ return;
54
+ }
55
+ if (deps[id]) {
56
+ console.warn("[qiankun] '".concat(id, "' global listener already exists before this, new listener will overwrite it."));
57
+ }
58
+ deps[id] = callback;
59
+ if (fireImmediately) {
60
+ var cloneState = _cloneDeep(globalState);
61
+ callback(cloneState, cloneState);
62
+ }
63
+ },
64
+ /**
65
+ * setGlobalState 更新 store 数据
66
+ *
67
+ * 1. 对输入 state 的第一层属性做校验,只有初始化时声明过的第一层(bucket)属性才会被更改
68
+ * 2. 修改 store 并触发全局监听
69
+ *
70
+ * @param state
71
+ */
72
+ setGlobalState: function setGlobalState() {
73
+ var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
74
+ if (state === globalState) {
75
+ console.warn('[qiankun] state has not changed!');
76
+ return false;
77
+ }
78
+ var changeKeys = [];
79
+ var prevGlobalState = _cloneDeep(globalState);
80
+ globalState = _cloneDeep(Object.keys(state).reduce(function (_globalState, changeKey) {
81
+ if (isMaster || _globalState.hasOwnProperty(changeKey)) {
82
+ changeKeys.push(changeKey);
83
+ return Object.assign(_globalState, _defineProperty({}, changeKey, state[changeKey]));
84
+ }
85
+ console.warn("[qiankun] '".concat(changeKey, "' not declared when init state\uFF01"));
86
+ return _globalState;
87
+ }, globalState));
88
+ if (changeKeys.length === 0) {
89
+ console.warn('[qiankun] state has not changed!');
90
+ return false;
91
+ }
92
+ emitGlobal(globalState, prevGlobalState);
93
+ return true;
94
+ },
95
+ // 注销该应用下的依赖
96
+ offGlobalStateChange: function offGlobalStateChange() {
97
+ delete deps[id];
98
+ return true;
99
+ }
100
+ };
101
+ }
package/es/index.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @author Kuitos
3
+ * @since 2019-04-25
4
+ */
5
+ export { loadMicroApp, registerMicroApps, start } from './apis';
6
+ export { initGlobalState } from './globalState';
7
+ export { getCurrentRunningApp as __internalGetCurrentRunningApp } from './sandbox';
8
+ export * from './errorHandler';
9
+ export * from './effects';
10
+ export * from './interfaces';
11
+ export { prefetchImmediately as prefetchApps } from './prefetch';
package/es/index.js ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @author Kuitos
3
+ * @since 2019-04-25
4
+ */
5
+ export { loadMicroApp, registerMicroApps, start } from './apis';
6
+ export { initGlobalState } from './globalState';
7
+ export { getCurrentRunningApp as __internalGetCurrentRunningApp } from './sandbox';
8
+ export * from './errorHandler';
9
+ export * from './effects';
10
+ export * from './interfaces';
11
+ export { prefetchImmediately as prefetchApps } from './prefetch';