@modern-js/plugin-garfish 2.0.0-beta.3 → 2.0.0-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 (58) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/dist/js/modern/cli/index.js +167 -157
  3. package/dist/js/modern/cli/types.js +0 -0
  4. package/dist/js/modern/cli/utils.js +31 -23
  5. package/dist/js/modern/global.d.js +0 -0
  6. package/dist/js/modern/index.js +5 -2
  7. package/dist/js/modern/modern-app.env.d.js +0 -0
  8. package/dist/js/modern/runtime/global.d.js +0 -0
  9. package/dist/js/modern/runtime/index.js +12 -4
  10. package/dist/js/modern/runtime/loadable.js +74 -56
  11. package/dist/js/modern/runtime/plugin.js +114 -79
  12. package/dist/js/modern/runtime/useModuleApps.js +40 -26
  13. package/dist/js/modern/runtime/utils/Context.js +6 -3
  14. package/dist/js/modern/runtime/utils/MApp.js +76 -72
  15. package/dist/js/modern/runtime/utils/apps.js +181 -132
  16. package/dist/js/modern/runtime/utils/setExternal.js +11 -11
  17. package/dist/js/modern/util.js +11 -9
  18. package/dist/js/node/cli/index.js +191 -169
  19. package/dist/js/node/cli/types.js +0 -0
  20. package/dist/js/node/cli/utils.js +53 -30
  21. package/dist/js/node/global.d.js +0 -0
  22. package/dist/js/node/index.js +31 -24
  23. package/dist/js/node/modern-app.env.d.js +0 -0
  24. package/dist/js/node/runtime/global.d.js +0 -0
  25. package/dist/js/node/runtime/index.js +42 -43
  26. package/dist/js/node/runtime/loadable.js +97 -61
  27. package/dist/js/node/runtime/plugin.js +147 -95
  28. package/dist/js/node/runtime/useModuleApps.js +67 -34
  29. package/dist/js/node/runtime/utils/Context.js +35 -10
  30. package/dist/js/node/runtime/utils/MApp.js +109 -84
  31. package/dist/js/node/runtime/utils/apps.js +210 -135
  32. package/dist/js/node/runtime/utils/setExternal.js +37 -18
  33. package/dist/js/node/util.js +40 -19
  34. package/dist/js/treeshaking/cli/index.js +403 -284
  35. package/dist/js/treeshaking/cli/types.js +1 -0
  36. package/dist/js/treeshaking/cli/utils.js +28 -31
  37. package/dist/js/treeshaking/global.d.js +1 -0
  38. package/dist/js/treeshaking/index.js +3 -2
  39. package/dist/js/treeshaking/modern-app.env.d.js +1 -0
  40. package/dist/js/treeshaking/runtime/global.d.js +1 -0
  41. package/dist/js/treeshaking/runtime/index.js +5 -4
  42. package/dist/js/treeshaking/runtime/loadable.js +230 -109
  43. package/dist/js/treeshaking/runtime/plugin.js +469 -168
  44. package/dist/js/treeshaking/runtime/useModuleApps.js +55 -31
  45. package/dist/js/treeshaking/runtime/utils/Context.js +3 -3
  46. package/dist/js/treeshaking/runtime/utils/MApp.js +348 -180
  47. package/dist/js/treeshaking/runtime/utils/apps.js +472 -224
  48. package/dist/js/treeshaking/runtime/utils/setExternal.js +12 -11
  49. package/dist/js/treeshaking/util.js +7 -9
  50. package/dist/types/cli/index.d.ts +3 -0
  51. package/dist/types/cli/types.d.ts +6 -0
  52. package/dist/types/runtime/index.d.ts +1 -1
  53. package/dist/types/runtime/loadable.d.ts +1 -2
  54. package/dist/types/runtime/plugin.d.ts +2 -0
  55. package/dist/types/runtime/utils/apps.d.ts +1 -0
  56. package/dist/types/runtime/utils/setExternal.d.ts +1 -0
  57. package/package.json +25 -20
  58. package/type.d.ts +5 -6
@@ -1,236 +1,484 @@
1
- import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
- import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
5
- import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
6
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
7
- import _createClass from "@babel/runtime/helpers/esm/createClass";
8
- import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
9
- import _inherits from "@babel/runtime/helpers/esm/inherits";
10
- import _createSuper from "@babel/runtime/helpers/esm/createSuper";
11
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
12
- var _excluded = ["match", "history", "setLoadingState"];
13
- // The loading logic of the current component refers to react-loadable https://github.com/jamiebuilds/react-loadable
14
- import path from 'path';
15
- import React from 'react';
16
- // eslint-disable-next-line import/no-named-as-default
17
- import Garfish from 'garfish';
18
- import { withRouter } from '@modern-js/plugin-router-legacy';
19
- // import Loadable from 'react-loadable';
20
-
1
+ function _arrayLikeToArray(arr, len) {
2
+ if (len == null || len > arr.length) len = arr.length;
3
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
4
+ return arr2;
5
+ }
6
+ function _arrayWithHoles(arr) {
7
+ if (Array.isArray(arr)) return arr;
8
+ }
9
+ function _arrayWithoutHoles(arr) {
10
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
11
+ }
12
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
13
+ try {
14
+ var info = gen[key](arg);
15
+ var value = info.value;
16
+ } catch (error) {
17
+ reject(error);
18
+ return;
19
+ }
20
+ if (info.done) {
21
+ resolve(value);
22
+ } else {
23
+ Promise.resolve(value).then(_next, _throw);
24
+ }
25
+ }
26
+ function _asyncToGenerator(fn) {
27
+ return function() {
28
+ var self = this, args = arguments;
29
+ return new Promise(function(resolve, reject) {
30
+ var gen = fn.apply(self, args);
31
+ function _next(value) {
32
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
33
+ }
34
+ function _throw(err) {
35
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
36
+ }
37
+ _next(undefined);
38
+ });
39
+ };
40
+ }
41
+ function _defineProperty(obj, key, value) {
42
+ if (key in obj) {
43
+ Object.defineProperty(obj, key, {
44
+ value: value,
45
+ enumerable: true,
46
+ configurable: true,
47
+ writable: true
48
+ });
49
+ } else {
50
+ obj[key] = value;
51
+ }
52
+ return obj;
53
+ }
54
+ function _iterableToArray(iter) {
55
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
56
+ }
57
+ function _iterableToArrayLimit(arr, i) {
58
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
59
+ if (_i == null) return;
60
+ var _arr = [];
61
+ var _n = true;
62
+ var _d = false;
63
+ var _s, _e;
64
+ try {
65
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
66
+ _arr.push(_s.value);
67
+ if (i && _arr.length === i) break;
68
+ }
69
+ } catch (err) {
70
+ _d = true;
71
+ _e = err;
72
+ } finally{
73
+ try {
74
+ if (!_n && _i["return"] != null) _i["return"]();
75
+ } finally{
76
+ if (_d) throw _e;
77
+ }
78
+ }
79
+ return _arr;
80
+ }
81
+ function _nonIterableRest() {
82
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
83
+ }
84
+ function _nonIterableSpread() {
85
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
86
+ }
87
+ function _objectSpread(target) {
88
+ for(var i = 1; i < arguments.length; i++){
89
+ var source = arguments[i] != null ? arguments[i] : {};
90
+ var ownKeys = Object.keys(source);
91
+ if (typeof Object.getOwnPropertySymbols === "function") {
92
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
93
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
94
+ }));
95
+ }
96
+ ownKeys.forEach(function(key) {
97
+ _defineProperty(target, key, source[key]);
98
+ });
99
+ }
100
+ return target;
101
+ }
102
+ function ownKeys(object, enumerableOnly) {
103
+ var keys = Object.keys(object);
104
+ if (Object.getOwnPropertySymbols) {
105
+ var symbols = Object.getOwnPropertySymbols(object);
106
+ if (enumerableOnly) {
107
+ symbols = symbols.filter(function(sym) {
108
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
109
+ });
110
+ }
111
+ keys.push.apply(keys, symbols);
112
+ }
113
+ return keys;
114
+ }
115
+ function _objectSpreadProps(target, source) {
116
+ source = source != null ? source : {};
117
+ if (Object.getOwnPropertyDescriptors) {
118
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
119
+ } else {
120
+ ownKeys(Object(source)).forEach(function(key) {
121
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
122
+ });
123
+ }
124
+ return target;
125
+ }
126
+ function _objectWithoutProperties(source, excluded) {
127
+ if (source == null) return {};
128
+ var target = _objectWithoutPropertiesLoose(source, excluded);
129
+ var key, i;
130
+ if (Object.getOwnPropertySymbols) {
131
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
132
+ for(i = 0; i < sourceSymbolKeys.length; i++){
133
+ key = sourceSymbolKeys[i];
134
+ if (excluded.indexOf(key) >= 0) continue;
135
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
136
+ target[key] = source[key];
137
+ }
138
+ }
139
+ return target;
140
+ }
141
+ function _objectWithoutPropertiesLoose(source, excluded) {
142
+ if (source == null) return {};
143
+ var target = {};
144
+ var sourceKeys = Object.keys(source);
145
+ var key, i;
146
+ for(i = 0; i < sourceKeys.length; i++){
147
+ key = sourceKeys[i];
148
+ if (excluded.indexOf(key) >= 0) continue;
149
+ target[key] = source[key];
150
+ }
151
+ return target;
152
+ }
153
+ function _slicedToArray(arr, i) {
154
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
155
+ }
156
+ function _toConsumableArray(arr) {
157
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
158
+ }
159
+ function _unsupportedIterableToArray(o, minLen) {
160
+ if (!o) return;
161
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
162
+ var n = Object.prototype.toString.call(o).slice(8, -1);
163
+ if (n === "Object" && o.constructor) n = o.constructor.name;
164
+ if (n === "Map" || n === "Set") return Array.from(n);
165
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
166
+ }
167
+ var __generator = this && this.__generator || function(thisArg, body) {
168
+ var f, y, t, g, _ = {
169
+ label: 0,
170
+ sent: function() {
171
+ if (t[0] & 1) throw t[1];
172
+ return t[1];
173
+ },
174
+ trys: [],
175
+ ops: []
176
+ };
177
+ return g = {
178
+ next: verb(0),
179
+ "throw": verb(1),
180
+ "return": verb(2)
181
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
182
+ return this;
183
+ }), g;
184
+ function verb(n) {
185
+ return function(v) {
186
+ return step([
187
+ n,
188
+ v
189
+ ]);
190
+ };
191
+ }
192
+ function step(op) {
193
+ if (f) throw new TypeError("Generator is already executing.");
194
+ while(_)try {
195
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
196
+ if (y = 0, t) op = [
197
+ op[0] & 2,
198
+ t.value
199
+ ];
200
+ switch(op[0]){
201
+ case 0:
202
+ case 1:
203
+ t = op;
204
+ break;
205
+ case 4:
206
+ _.label++;
207
+ return {
208
+ value: op[1],
209
+ done: false
210
+ };
211
+ case 5:
212
+ _.label++;
213
+ y = op[1];
214
+ op = [
215
+ 0
216
+ ];
217
+ continue;
218
+ case 7:
219
+ op = _.ops.pop();
220
+ _.trys.pop();
221
+ continue;
222
+ default:
223
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
224
+ _ = 0;
225
+ continue;
226
+ }
227
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
228
+ _.label = op[1];
229
+ break;
230
+ }
231
+ if (op[0] === 6 && _.label < t[1]) {
232
+ _.label = t[1];
233
+ t = op;
234
+ break;
235
+ }
236
+ if (t && _.label < t[2]) {
237
+ _.label = t[2];
238
+ _.ops.push(op);
239
+ break;
240
+ }
241
+ if (t[2]) _.ops.pop();
242
+ _.trys.pop();
243
+ continue;
244
+ }
245
+ op = body.call(thisArg, _);
246
+ } catch (e) {
247
+ op = [
248
+ 6,
249
+ e
250
+ ];
251
+ y = 0;
252
+ } finally{
253
+ f = t = 0;
254
+ }
255
+ if (op[0] & 5) throw op[1];
256
+ return {
257
+ value: op[0] ? op[1] : void 0,
258
+ done: true
259
+ };
260
+ }
261
+ };
262
+ import { Fragment, jsx } from "react/jsx-runtime";
263
+ import { useContext, useState, useEffect, useRef } from "react";
264
+ import { RuntimeReactContext } from "@modern-js/runtime";
265
+ import Garfish from "garfish";
21
266
  import { logger, generateSubAppContainerKey } from "../../util";
22
267
  import { Loadable } from "../loadable";
23
- import { jsx as _jsx } from "react/jsx-runtime";
24
- import { Fragment as _Fragment } from "react/jsx-runtime";
25
- function getAppInstance(options, appInfo, manifest) {
26
- var locationHref = '';
27
- var MicroApp = /*#__PURE__*/function (_React$Component) {
28
- _inherits(MicroApp, _React$Component);
29
- var _super = _createSuper(MicroApp);
30
- function MicroApp() {
31
- var _this;
32
- _classCallCheck(this, MicroApp);
33
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
268
+ function pathJoin() {
269
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
34
270
  args[_key] = arguments[_key];
35
- }
36
- _this = _super.call.apply(_super, [this].concat(args));
37
- _defineProperty(_assertThisInitialized(_this), "state", {
38
- appInstance: null,
39
- domId: generateSubAppContainerKey(appInfo),
40
- SubModuleComponent: undefined
41
- });
42
- _defineProperty(_assertThisInitialized(_this), "unregisterHistoryListener", function () {});
43
- return _this;
44
271
  }
45
- _createClass(MicroApp, [{
46
- key: "componentDidMount",
47
- value: function () {
48
- var _componentDidMount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
49
- var _this2 = this;
50
- var _this$props, match, history, setLoadingState, userProps, domId, loadAppOptions, appInstance;
51
- return _regeneratorRuntime().wrap(function _callee$(_context) {
52
- while (1) {
53
- switch (_context.prev = _context.next) {
54
- case 0:
55
- _this$props = this.props, match = _this$props.match, history = _this$props.history, setLoadingState = _this$props.setLoadingState, userProps = _objectWithoutProperties(_this$props, _excluded);
56
- domId = this.state.domId;
57
- loadAppOptions = _objectSpread(_objectSpread({}, appInfo), {}, {
58
- insulationVariable: [].concat(_toConsumableArray(appInfo.insulationVariable || []), ['_SERVER_DATA']),
59
- domGetter: "#".concat(domId),
60
- basename: path.join((options === null || options === void 0 ? void 0 : options.basename) || '/', (match === null || match === void 0 ? void 0 : match.path) || '/'),
61
- cache: true,
62
- props: _objectSpread(_objectSpread({}, appInfo.props), userProps),
63
- customLoader: function customLoader(provider) {
64
- var render = provider.render,
65
- destroy = provider.destroy,
66
- SubModuleComponent = provider.SubModuleComponent,
67
- jupiter_submodule_app_key = provider.jupiter_submodule_app_key;
68
- var componetRenderMode = (manifest === null || manifest === void 0 ? void 0 : manifest.componentRender) && (SubModuleComponent || jupiter_submodule_app_key);
69
- return {
70
- mount: function mount() {
71
- if (componetRenderMode) {
72
- _this2.setState({
73
- SubModuleComponent: SubModuleComponent !== null && SubModuleComponent !== void 0 ? SubModuleComponent : jupiter_submodule_app_key
74
- });
75
- return undefined;
76
- } else {
77
- for (var _len2 = arguments.length, props = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
78
- props[_key2] = arguments[_key2];
272
+ var res = args.reduce(function(res2, path) {
273
+ var nPath = path;
274
+ if (!nPath || typeof nPath !== "string") {
275
+ return res2;
276
+ }
277
+ if (nPath[0] !== "/") {
278
+ nPath = "/".concat(nPath);
279
+ }
280
+ var lastIndex = path.length - 1;
281
+ if (nPath[lastIndex] === "/") {
282
+ nPath = nPath.substring(0, lastIndex);
283
+ }
284
+ return res2 + nPath;
285
+ }, "");
286
+ return res || "/";
287
+ }
288
+ function getAppInstance(options, appInfo, manifest) {
289
+ var MicroApp = function MicroApp(props) {
290
+ var ref, ref1, ref2, ref3, ref4, ref5;
291
+ var appRef = useRef(null);
292
+ var domId = generateSubAppContainerKey(appInfo);
293
+ var ref6 = _slicedToArray(useState(), 2), SubModuleComponent = ref6[0], setSubModuleComponent = ref6[1];
294
+ var context = useContext(RuntimeReactContext);
295
+ var match = context === null || context === void 0 ? void 0 : (ref = context.router) === null || ref === void 0 ? void 0 : (ref1 = ref.useRouteMatch) === null || ref1 === void 0 ? void 0 : ref1.call(ref);
296
+ var matchs = context === null || context === void 0 ? void 0 : (ref2 = context.router) === null || ref2 === void 0 ? void 0 : (ref3 = ref2.useMatches) === null || ref3 === void 0 ? void 0 : ref3.call(ref2);
297
+ var location = context === null || context === void 0 ? void 0 : (ref4 = context.router) === null || ref4 === void 0 ? void 0 : (ref5 = ref4.useLocation) === null || ref5 === void 0 ? void 0 : ref5.call(ref4);
298
+ var basename = (options === null || options === void 0 ? void 0 : options.basename) || "/";
299
+ if (matchs && matchs.length > 0) {
300
+ basename = pathJoin(basename, matchs[matchs.length - 1].pathname || "/");
301
+ } else if (match) {
302
+ basename = pathJoin(basename, (match === null || match === void 0 ? void 0 : match.path) || "/");
303
+ }
304
+ useEffect(function() {
305
+ if (location && locationHref !== location.pathname) {
306
+ locationHref = location.pathname;
307
+ var popStateEvent = new PopStateEvent("popstate");
308
+ popStateEvent.garfish = true;
309
+ dispatchEvent(popStateEvent);
310
+ logger("MicroApp Garfish.loadApp popstate");
311
+ }
312
+ }, [
313
+ location
314
+ ]);
315
+ useEffect(function() {
316
+ var setLoadingState = props.setLoadingState, userProps = _objectWithoutProperties(props, [
317
+ "setLoadingState"
318
+ ]);
319
+ var loadAppOptions = _objectSpreadProps(_objectSpread({}, appInfo), {
320
+ insulationVariable: _toConsumableArray(appInfo.insulationVariable || []).concat([
321
+ "_SERVER_DATA"
322
+ ]),
323
+ domGetter: "#".concat(domId),
324
+ basename: basename,
325
+ cache: true,
326
+ props: _objectSpread({}, appInfo.props, userProps),
327
+ customLoader: function(provider) {
328
+ var render = provider.render, destroy = provider.destroy, SubModuleComponent2 = provider.SubModuleComponent, jupiter_submodule_app_key = provider.jupiter_submodule_app_key;
329
+ var componetRenderMode = (manifest === null || manifest === void 0 ? void 0 : manifest.componentRender) && (SubModuleComponent2 || jupiter_submodule_app_key);
330
+ return {
331
+ mount: function() {
332
+ for(var _len = arguments.length, props2 = new Array(_len), _key = 0; _key < _len; _key++){
333
+ props2[_key] = arguments[_key];
334
+ }
335
+ if (componetRenderMode) {
336
+ setSubModuleComponent(SubModuleComponent2);
337
+ return void 0;
338
+ } else {
339
+ logger("MicroApp customer render", props2);
340
+ return render === null || render === void 0 ? void 0 : render.apply(provider, props2);
79
341
  }
80
- logger('MicroApp customer render', props);
81
- return render === null || render === void 0 ? void 0 : render.apply(provider, props);
82
- }
83
342
  },
84
343
  unmount: function unmount() {
85
- if (componetRenderMode) {
86
- return undefined;
87
- }
88
- for (var _len3 = arguments.length, props = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
89
- props[_key3] = arguments[_key3];
90
- }
91
- logger('MicroApp customer destroy', props);
92
- return destroy === null || destroy === void 0 ? void 0 : destroy.apply(provider, props);
344
+ for(var _len = arguments.length, props2 = new Array(_len), _key = 0; _key < _len; _key++){
345
+ props2[_key] = arguments[_key];
346
+ }
347
+ if (componetRenderMode) {
348
+ return void 0;
349
+ }
350
+ logger("MicroApp customer destroy", props2);
351
+ return destroy === null || destroy === void 0 ? void 0 : destroy.apply(provider, props2);
93
352
  }
94
- };
95
- }
96
- });
97
- setLoadingState({
98
- isLoading: true,
99
- error: null
100
- });
101
- logger("MicroApp Garfish.loadApp \"".concat(appInfo.name, "\""), {
102
- loadAppOptions: loadAppOptions
103
- });
104
- _context.prev = 5;
105
- _context.next = 8;
106
- return Garfish.loadApp(appInfo.name, loadAppOptions);
107
- case 8:
108
- appInstance = _context.sent;
109
- if (appInstance) {
110
- _context.next = 11;
111
- break;
112
- }
113
- throw new Error("MicroApp Garfish.loadApp \"".concat(appInfo.name, "\" result is null"));
114
- case 11:
115
- // eslint-disable-next-line react/no-did-mount-set-state
116
- this.setState({
117
- appInstance: appInstance
118
- });
119
- setLoadingState({
120
- isLoading: false
121
- });
122
- if (!(appInstance.mounted && appInstance.appInfo.cache)) {
123
- _context.next = 19;
124
- break;
125
- }
126
- logger("MicroApp Garfish.loadApp \"".concat(appInfo.name, "\" show"), {
127
- appInfo: appInstance.appInfo,
128
- appInstance: appInstance
129
- });
130
- _context.next = 17;
131
- return appInstance === null || appInstance === void 0 ? void 0 : appInstance.show();
132
- case 17:
133
- _context.next = 22;
134
- break;
135
- case 19:
136
- logger("MicroApp Garfish.loadApp \"".concat(appInfo.name, "\" mount"), {
137
- appInfo: appInstance.appInfo,
138
- appInstance: appInstance
139
- });
140
- _context.next = 22;
141
- return appInstance === null || appInstance === void 0 ? void 0 : appInstance.mount();
142
- case 22:
143
- this.unregisterHistoryListener = history === null || history === void 0 ? void 0 : history.listen(function () {
144
- if (locationHref !== history.location.pathname) {
145
- locationHref = history.location.pathname;
146
- var popStateEvent = new PopStateEvent('popstate');
147
- dispatchEvent(popStateEvent);
148
- logger("MicroApp Garfish.loadApp popstate");
149
- }
150
- });
151
- _context.next = 28;
152
- break;
153
- case 25:
154
- _context.prev = 25;
155
- _context.t0 = _context["catch"](5);
156
- setLoadingState({
157
- isLoading: true,
158
- error: _context.t0
159
- });
160
- case 28:
161
- case "end":
162
- return _context.stop();
163
- }
353
+ };
354
+ }
355
+ });
356
+ setLoadingState({
357
+ isLoading: true,
358
+ error: null
359
+ });
360
+ logger('MicroApp Garfish.loadApp "'.concat(appInfo.name, '"'), {
361
+ loadAppOptions: loadAppOptions
362
+ });
363
+ function renderApp() {
364
+ return _renderApp.apply(this, arguments);
164
365
  }
165
- }, _callee, this, [[5, 25]]);
166
- }));
167
- function componentDidMount() {
168
- return _componentDidMount.apply(this, arguments);
169
- }
170
- return componentDidMount;
171
- }()
172
- }, {
173
- key: "componentWillUnmount",
174
- value: function () {
175
- var _componentWillUnmount = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
176
- var _this$unregisterHisto;
177
- var appInstance, _appInfo;
178
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
179
- while (1) {
180
- switch (_context2.prev = _context2.next) {
181
- case 0:
182
- appInstance = this.state.appInstance;
183
- (_this$unregisterHisto = this.unregisterHistoryListener) === null || _this$unregisterHisto === void 0 ? void 0 : _this$unregisterHisto.call(this);
184
- if (appInstance) {
185
- _appInfo = appInstance.appInfo;
186
- if (_appInfo.cache) {
187
- logger("MicroApp Garfish.loadApp \"".concat(_appInfo.name, "\" hide"));
188
- appInstance === null || appInstance === void 0 ? void 0 : appInstance.hide();
366
+ function _renderApp() {
367
+ _renderApp = _asyncToGenerator(function() {
368
+ var appInstance, error;
369
+ return __generator(this, function(_state) {
370
+ switch(_state.label){
371
+ case 0:
372
+ _state.trys.push([
373
+ 0,
374
+ 6,
375
+ ,
376
+ 7
377
+ ]);
378
+ return [
379
+ 4,
380
+ Garfish.loadApp(appInfo.name, loadAppOptions)
381
+ ];
382
+ case 1:
383
+ appInstance = _state.sent();
384
+ if (!appInstance) {
385
+ throw new Error('MicroApp Garfish.loadApp "'.concat(appInfo.name, '" result is null'));
386
+ }
387
+ appRef.current = appInstance;
388
+ setLoadingState({
389
+ isLoading: false
390
+ });
391
+ if (!(appInstance.mounted && appInstance.appInfo.cache)) return [
392
+ 3,
393
+ 3
394
+ ];
395
+ logger('MicroApp Garfish.loadApp "'.concat(appInfo.name, '" show'), {
396
+ appInfo: appInstance.appInfo,
397
+ appInstance: appInstance
398
+ });
399
+ return [
400
+ 4,
401
+ appInstance === null || appInstance === void 0 ? void 0 : appInstance.show()
402
+ ];
403
+ case 2:
404
+ _state.sent();
405
+ return [
406
+ 3,
407
+ 5
408
+ ];
409
+ case 3:
410
+ logger('MicroApp Garfish.loadApp "'.concat(appInfo.name, '" mount'), {
411
+ appInfo: appInstance.appInfo,
412
+ appInstance: appInstance
413
+ });
414
+ return [
415
+ 4,
416
+ appInstance === null || appInstance === void 0 ? void 0 : appInstance.mount()
417
+ ];
418
+ case 4:
419
+ _state.sent();
420
+ _state.label = 5;
421
+ case 5:
422
+ return [
423
+ 3,
424
+ 7
425
+ ];
426
+ case 6:
427
+ error = _state.sent();
428
+ setLoadingState({
429
+ isLoading: true,
430
+ error: error
431
+ });
432
+ return [
433
+ 3,
434
+ 7
435
+ ];
436
+ case 7:
437
+ return [
438
+ 2
439
+ ];
440
+ }
441
+ });
442
+ });
443
+ return _renderApp.apply(this, arguments);
444
+ }
445
+ renderApp();
446
+ return function() {
447
+ if (appRef.current) {
448
+ var _current = appRef.current, appInfo2 = _current.appInfo;
449
+ if (appInfo2.cache) {
450
+ var ref;
451
+ logger('MicroApp Garfish.loadApp "'.concat(appInfo2.name, '" hide'));
452
+ (ref = appRef.current) === null || ref === void 0 ? void 0 : ref.hide();
189
453
  } else {
190
- logger("MicroApp Garfish.loadApp \"".concat(_appInfo.name, "\" unmount"));
191
- appInstance === null || appInstance === void 0 ? void 0 : appInstance.unmount();
454
+ var ref1;
455
+ logger('MicroApp Garfish.loadApp "'.concat(appInfo2.name, '" unmount'));
456
+ (ref1 = appRef.current) === null || ref1 === void 0 ? void 0 : ref1.unmount();
192
457
  }
193
- }
194
- case 3:
195
- case "end":
196
- return _context2.stop();
197
- }
198
- }
199
- }, _callee2, this);
200
- }));
201
- function componentWillUnmount() {
202
- return _componentWillUnmount.apply(this, arguments);
203
- }
204
- return componentWillUnmount;
205
- }()
206
- }, {
207
- key: "render",
208
- value: function render() {
209
- var _this$state = this.state,
210
- domId = _this$state.domId,
211
- SubModuleComponent = _this$state.SubModuleComponent;
212
- return /*#__PURE__*/_jsx(_Fragment, {
213
- children: /*#__PURE__*/_jsx("div", {
214
- id: domId,
215
- children: SubModuleComponent && /*#__PURE__*/_jsx(SubModuleComponent, {})
216
- })
458
+ }
459
+ };
460
+ }, []);
461
+ return /* @__PURE__ */ jsx(Fragment, {
462
+ children: /* @__PURE__ */ jsx("div", {
463
+ id: domId,
464
+ children: SubModuleComponent && /* @__PURE__ */ jsx(SubModuleComponent, {})
465
+ })
217
466
  });
218
- }
219
- }]);
220
- return MicroApp;
221
- }(React.Component);
222
- return Loadable(withRouter(MicroApp))(manifest === null || manifest === void 0 ? void 0 : manifest.loadable);
223
- }
224
- export function generateApps(options, manifest) {
225
- var _options$apps;
226
- var apps = {};
227
- (_options$apps = options.apps) === null || _options$apps === void 0 ? void 0 : _options$apps.forEach(function (appInfo) {
228
- var Component = getAppInstance(options, appInfo, manifest);
229
- appInfo.Component = Component;
230
- apps[appInfo.name] = Component;
231
- });
232
- return {
233
- apps: apps,
234
- appInfoList: options.apps || []
235
- };
236
- }
467
+ };
468
+ var locationHref = "";
469
+ return Loadable(MicroApp)(manifest === null || manifest === void 0 ? void 0 : manifest.loadable);
470
+ }
471
+ function generateApps(options, manifest) {
472
+ var ref;
473
+ var apps = {};
474
+ (ref = options.apps) === null || ref === void 0 ? void 0 : ref.forEach(function(appInfo) {
475
+ var Component = getAppInstance(options, appInfo, manifest);
476
+ appInfo.Component = Component;
477
+ apps[appInfo.name] = Component;
478
+ });
479
+ return {
480
+ apps: apps,
481
+ appInfoList: options.apps || []
482
+ };
483
+ }
484
+ export { generateApps, pathJoin };