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