@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,30 +1,47 @@
1
- const _excluded = ["style", "setLoadingState"];
2
- function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
3
- function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
4
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
5
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
7
- import React from 'react';
8
- // eslint-disable-next-line import/no-named-as-default
9
- import Garfish from 'garfish';
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+ var __objRest = (source, exclude) => {
18
+ var target = {};
19
+ for (var prop in source)
20
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
21
+ target[prop] = source[prop];
22
+ if (source != null && __getOwnPropSymbols)
23
+ for (var prop of __getOwnPropSymbols(source)) {
24
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
25
+ target[prop] = source[prop];
26
+ }
27
+ return target;
28
+ };
29
+ import { jsx } from "react/jsx-runtime";
30
+ import React from "react";
31
+ import Garfish from "garfish";
10
32
  import { logger, generateSubAppContainerKey } from "../../util";
11
33
  import { Loadable } from "../loadable";
12
- import { jsx as _jsx } from "react/jsx-runtime";
13
- export function generateMApp(options, manifest) {
34
+ function generateMApp(options, manifest) {
14
35
  class MApp extends React.Component {
15
- constructor(...args) {
16
- super(...args);
17
- _defineProperty(this, "state", {
36
+ constructor() {
37
+ super(...arguments);
38
+ this.state = {
18
39
  domId: generateSubAppContainerKey()
19
- });
40
+ };
20
41
  }
21
42
  componentDidMount() {
22
- const {
23
- domId
24
- } = this.state;
25
- const {
26
- setLoadingState
27
- } = this.props;
43
+ const { domId } = this.state;
44
+ const { setLoadingState } = this.props;
28
45
  const {
29
46
  beforeLoad,
30
47
  beforeMount,
@@ -32,94 +49,90 @@ export function generateMApp(options, manifest) {
32
49
  errorMountApp,
33
50
  errorUnmountApp
34
51
  } = options;
35
-
36
- // start auto render able
37
- Garfish.router.setRouterConfig({
38
- listening: true
39
- });
52
+ Garfish.router.setRouterConfig({ listening: true });
40
53
  const garfishOptions = {
41
54
  domGetter: `#${domId}`,
42
55
  beforeLoad(appInfo, ...args) {
43
- logger('MApp beforeLoad', [appInfo]);
56
+ logger("MApp beforeLoad", [appInfo]);
44
57
  if (appInfo.activeWhen) {
45
58
  setLoadingState({
46
59
  isLoading: true,
47
60
  error: null
48
61
  });
49
62
  }
50
- return beforeLoad === null || beforeLoad === void 0 ? void 0 : beforeLoad(appInfo, ...args);
63
+ return beforeLoad == null ? void 0 : beforeLoad(appInfo, ...args);
51
64
  },
52
65
  beforeMount(appInfo, ...args) {
53
- logger('MApp beforeMount', args);
66
+ logger("MApp beforeMount", args);
54
67
  if (appInfo.activeWhen) {
55
68
  setLoadingState({
56
69
  isLoading: false
57
70
  });
58
71
  }
59
- return beforeMount === null || beforeMount === void 0 ? void 0 : beforeMount(appInfo, ...args);
72
+ return beforeMount == null ? void 0 : beforeMount(appInfo, ...args);
60
73
  },
61
74
  errorLoadApp(error, appInfo, ...args) {
62
- logger('MApp errorLoadApp', error, args);
75
+ logger("MApp errorLoadApp", error, args);
63
76
  if (appInfo.activeWhen) {
64
77
  setLoadingState({
65
78
  error
66
79
  });
67
80
  }
68
- return errorLoadApp === null || errorLoadApp === void 0 ? void 0 : errorLoadApp(error, appInfo, ...args);
81
+ return errorLoadApp == null ? void 0 : errorLoadApp(error, appInfo, ...args);
69
82
  },
70
83
  errorMountApp(error, appInfo, ...args) {
71
- logger('MApp errorMountApp', error, args);
84
+ logger("MApp errorMountApp", error, args);
72
85
  if (appInfo.activeWhen) {
73
86
  setLoadingState({
74
87
  error
75
88
  });
76
89
  }
77
- return errorMountApp === null || errorMountApp === void 0 ? void 0 : errorMountApp(error, appInfo, ...args);
90
+ return errorMountApp == null ? void 0 : errorMountApp(error, appInfo, ...args);
78
91
  },
79
92
  errorUnmountApp(error, appInfo, ...args) {
80
- logger('MApp errorUnmountApp', error, args);
93
+ logger("MApp errorUnmountApp", error, args);
81
94
  if (appInfo.activeWhen) {
82
95
  setLoadingState({
83
96
  error
84
97
  });
85
98
  }
86
- return errorUnmountApp === null || errorUnmountApp === void 0 ? void 0 : errorUnmountApp(error, appInfo, ...args);
99
+ return errorUnmountApp == null ? void 0 : errorUnmountApp(error, appInfo, ...args);
87
100
  },
88
- customLoader: provider => {
101
+ customLoader: (provider) => {
89
102
  const {
90
103
  render,
91
104
  destroy,
92
105
  SubModuleComponent,
93
106
  jupiter_submodule_app_key
94
107
  } = provider;
95
- const componetRenderMode = (manifest === null || manifest === void 0 ? void 0 : manifest.componentRender) && (SubModuleComponent || jupiter_submodule_app_key);
108
+ const componetRenderMode = (manifest == null ? void 0 : manifest.componentRender) && (SubModuleComponent || jupiter_submodule_app_key);
96
109
  return {
97
- mount: appInfo => {
110
+ mount: (appInfo) => {
98
111
  const transferProps = this.filterTransferProps();
99
- appInfo.props = _objectSpread(_objectSpread({}, appInfo.props), transferProps);
112
+ appInfo.props = __spreadValues(__spreadValues({}, appInfo.props), transferProps);
100
113
  if (componetRenderMode) {
101
114
  this.setState({
102
- SubModuleComponent: SubModuleComponent !== null && SubModuleComponent !== void 0 ? SubModuleComponent : jupiter_submodule_app_key
115
+ SubModuleComponent: SubModuleComponent != null ? SubModuleComponent : jupiter_submodule_app_key
103
116
  });
104
- return undefined;
117
+ return void 0;
105
118
  } else {
106
- logger('MicroApp customer render', appInfo);
107
- return render === null || render === void 0 ? void 0 : render.apply(provider, [appInfo]);
119
+ logger("MicroApp customer render", appInfo);
120
+ return render == null ? void 0 : render.apply(provider, [appInfo]);
108
121
  }
109
122
  },
110
- unmount: appInfo => {
123
+ unmount: (appInfo) => {
111
124
  const transferProps = this.filterTransferProps();
112
- appInfo.props = _objectSpread(_objectSpread({}, appInfo.props), transferProps);
125
+ appInfo.props = __spreadValues(__spreadValues({}, appInfo.props), transferProps);
113
126
  if (componetRenderMode) {
114
- return undefined;
127
+ return void 0;
115
128
  }
116
- logger('MicroApp customer destroy', appInfo);
117
- return destroy === null || destroy === void 0 ? void 0 : destroy.apply(provider, [appInfo]);
129
+ logger("MicroApp customer destroy", appInfo);
130
+ return destroy == null ? void 0 : destroy.apply(provider, [appInfo]);
118
131
  }
119
132
  };
120
133
  }
121
134
  };
122
- logger('MApp componentDidMount', {
135
+ logger("MApp componentDidMount", {
123
136
  garfishRunning: Garfish.running,
124
137
  garfishOptions
125
138
  });
@@ -128,34 +141,25 @@ export function generateMApp(options, manifest) {
128
141
  }
129
142
  }
130
143
  componentWillUnmount() {
131
- // close auto render able
132
- Garfish.router.setRouterConfig({
133
- listening: false
134
- });
135
- logger('MApp componentWillUnmount');
144
+ Garfish.router.setRouterConfig({ listening: false });
145
+ logger("MApp componentWillUnmount");
136
146
  }
137
147
  filterTransferProps() {
138
- const _this$props = this.props,
139
- {
140
- style,
141
- setLoadingState
142
- } = _this$props,
143
- others = _objectWithoutProperties(_this$props, _excluded);
148
+ const _a = this.props, { style, setLoadingState } = _a, others = __objRest(_a, ["style", "setLoadingState"]);
144
149
  return others;
145
150
  }
146
151
  render() {
147
- const {
148
- style
149
- } = this.props;
150
- const {
151
- SubModuleComponent
152
- } = this.state;
153
- return /*#__PURE__*/_jsx("div", {
154
- style: _objectSpread({}, style),
152
+ const { style } = this.props;
153
+ const { SubModuleComponent } = this.state;
154
+ return /* @__PURE__ */ jsx("div", {
155
+ style: __spreadValues({}, style),
155
156
  id: generateSubAppContainerKey(),
156
- children: SubModuleComponent && /*#__PURE__*/_jsx(SubModuleComponent, {})
157
+ children: SubModuleComponent && /* @__PURE__ */ jsx(SubModuleComponent, {})
157
158
  });
158
159
  }
159
160
  }
160
- return Loadable(MApp)(manifest === null || manifest === void 0 ? void 0 : manifest.loadable);
161
- }
161
+ return Loadable(MApp)(manifest == null ? void 0 : manifest.loadable);
162
+ }
163
+ export {
164
+ generateMApp
165
+ };
@@ -1,76 +1,138 @@
1
- const _excluded = ["match", "history", "setLoadingState"];
2
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
- function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
5
- function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
6
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
7
- // The loading logic of the current component refers to react-loadable https://github.com/jamiebuilds/react-loadable
8
- import path from 'path';
9
- import React from 'react';
10
- // eslint-disable-next-line import/no-named-as-default
11
- import Garfish from 'garfish';
12
- import { withRouter } from '@modern-js/plugin-router-legacy';
13
- // import Loadable from 'react-loadable';
14
-
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
32
+ var __async = (__this, __arguments, generator) => {
33
+ return new Promise((resolve, reject) => {
34
+ var fulfilled = (value) => {
35
+ try {
36
+ step(generator.next(value));
37
+ } catch (e) {
38
+ reject(e);
39
+ }
40
+ };
41
+ var rejected = (value) => {
42
+ try {
43
+ step(generator.throw(value));
44
+ } catch (e) {
45
+ reject(e);
46
+ }
47
+ };
48
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
49
+ step((generator = generator.apply(__this, __arguments)).next());
50
+ });
51
+ };
52
+ import { Fragment, jsx } from "react/jsx-runtime";
53
+ import { useContext, useState, useEffect, useRef } from "react";
54
+ import { RuntimeReactContext } from "@modern-js/runtime";
55
+ import Garfish from "garfish";
15
56
  import { logger, generateSubAppContainerKey } from "../../util";
16
57
  import { Loadable } from "../loadable";
17
- import { jsx as _jsx } from "react/jsx-runtime";
18
- import { Fragment as _Fragment } from "react/jsx-runtime";
58
+ function pathJoin(...args) {
59
+ const res = args.reduce((res2, path) => {
60
+ let nPath = path;
61
+ if (!nPath || typeof nPath !== "string") {
62
+ return res2;
63
+ }
64
+ if (nPath[0] !== "/") {
65
+ nPath = `/${nPath}`;
66
+ }
67
+ const lastIndex = path.length - 1;
68
+ if (nPath[lastIndex] === "/") {
69
+ nPath = nPath.substring(0, lastIndex);
70
+ }
71
+ return res2 + nPath;
72
+ }, "");
73
+ return res || "/";
74
+ }
19
75
  function getAppInstance(options, appInfo, manifest) {
20
- let locationHref = '';
21
- class MicroApp extends React.Component {
22
- constructor(...args) {
23
- super(...args);
24
- _defineProperty(this, "state", {
25
- appInstance: null,
26
- domId: generateSubAppContainerKey(appInfo),
27
- SubModuleComponent: undefined
28
- });
29
- _defineProperty(this, "unregisterHistoryListener", () => {});
76
+ let locationHref = "";
77
+ function MicroApp(props) {
78
+ var _a, _b, _c, _d, _e, _f;
79
+ const appRef = useRef(null);
80
+ const domId = generateSubAppContainerKey(appInfo);
81
+ const [SubModuleComponent, setSubModuleComponent] = useState();
82
+ const context = useContext(RuntimeReactContext);
83
+ const match = (_b = (_a = context == null ? void 0 : context.router) == null ? void 0 : _a.useRouteMatch) == null ? void 0 : _b.call(_a);
84
+ const matchs = (_d = (_c = context == null ? void 0 : context.router) == null ? void 0 : _c.useMatches) == null ? void 0 : _d.call(_c);
85
+ const location = (_f = (_e = context == null ? void 0 : context.router) == null ? void 0 : _e.useLocation) == null ? void 0 : _f.call(_e);
86
+ let basename = (options == null ? void 0 : options.basename) || "/";
87
+ if (matchs && matchs.length > 0) {
88
+ basename = pathJoin(basename, matchs[matchs.length - 1].pathname || "/");
89
+ } else if (match) {
90
+ basename = pathJoin(basename, (match == null ? void 0 : match.path) || "/");
30
91
  }
31
- async componentDidMount() {
32
- const _this$props = this.props,
33
- {
34
- match,
35
- history,
36
- setLoadingState
37
- } = _this$props,
38
- userProps = _objectWithoutProperties(_this$props, _excluded);
39
- const {
40
- domId
41
- } = this.state;
42
- const loadAppOptions = _objectSpread(_objectSpread({}, appInfo), {}, {
43
- insulationVariable: [...(appInfo.insulationVariable || []), '_SERVER_DATA'],
92
+ useEffect(() => {
93
+ if (location && locationHref !== location.pathname) {
94
+ locationHref = location.pathname;
95
+ const popStateEvent = new PopStateEvent("popstate");
96
+ popStateEvent.garfish = true;
97
+ dispatchEvent(popStateEvent);
98
+ logger(`MicroApp Garfish.loadApp popstate`);
99
+ }
100
+ }, [location]);
101
+ useEffect(() => {
102
+ const _a2 = props, { setLoadingState } = _a2, userProps = __objRest(_a2, ["setLoadingState"]);
103
+ const loadAppOptions = __spreadProps(__spreadValues({}, appInfo), {
104
+ insulationVariable: [
105
+ ...appInfo.insulationVariable || [],
106
+ "_SERVER_DATA"
107
+ ],
44
108
  domGetter: `#${domId}`,
45
- basename: path.join((options === null || options === void 0 ? void 0 : options.basename) || '/', (match === null || match === void 0 ? void 0 : match.path) || '/'),
109
+ basename,
46
110
  cache: true,
47
- props: _objectSpread(_objectSpread({}, appInfo.props), userProps),
48
- customLoader: provider => {
111
+ props: __spreadValues(__spreadValues({}, appInfo.props), userProps),
112
+ customLoader: (provider) => {
49
113
  const {
50
114
  render,
51
115
  destroy,
52
- SubModuleComponent,
116
+ SubModuleComponent: SubModuleComponent2,
53
117
  jupiter_submodule_app_key
54
118
  } = provider;
55
- const componetRenderMode = (manifest === null || manifest === void 0 ? void 0 : manifest.componentRender) && (SubModuleComponent || jupiter_submodule_app_key);
119
+ const componetRenderMode = (manifest == null ? void 0 : manifest.componentRender) && (SubModuleComponent2 || jupiter_submodule_app_key);
56
120
  return {
57
- mount: (...props) => {
121
+ mount: (...props2) => {
58
122
  if (componetRenderMode) {
59
- this.setState({
60
- SubModuleComponent: SubModuleComponent !== null && SubModuleComponent !== void 0 ? SubModuleComponent : jupiter_submodule_app_key
61
- });
62
- return undefined;
123
+ setSubModuleComponent(SubModuleComponent2);
124
+ return void 0;
63
125
  } else {
64
- logger('MicroApp customer render', props);
65
- return render === null || render === void 0 ? void 0 : render.apply(provider, props);
126
+ logger("MicroApp customer render", props2);
127
+ return render == null ? void 0 : render.apply(provider, props2);
66
128
  }
67
129
  },
68
- unmount(...props) {
130
+ unmount(...props2) {
69
131
  if (componetRenderMode) {
70
- return undefined;
132
+ return void 0;
71
133
  }
72
- logger('MicroApp customer destroy', props);
73
- return destroy === null || destroy === void 0 ? void 0 : destroy.apply(provider, props);
134
+ logger("MicroApp customer destroy", props2);
135
+ return destroy == null ? void 0 : destroy.apply(provider, props2);
74
136
  }
75
137
  };
76
138
  }
@@ -82,91 +144,78 @@ function getAppInstance(options, appInfo, manifest) {
82
144
  logger(`MicroApp Garfish.loadApp "${appInfo.name}"`, {
83
145
  loadAppOptions
84
146
  });
85
- try {
86
- const appInstance = await Garfish.loadApp(appInfo.name, loadAppOptions);
87
- if (!appInstance) {
88
- throw new Error(`MicroApp Garfish.loadApp "${appInfo.name}" result is null`);
89
- }
90
-
91
- // eslint-disable-next-line react/no-did-mount-set-state
92
- this.setState({
93
- appInstance
94
- });
95
- setLoadingState({
96
- isLoading: false
97
- });
98
- if (appInstance.mounted && appInstance.appInfo.cache) {
99
- logger(`MicroApp Garfish.loadApp "${appInfo.name}" show`, {
100
- appInfo: appInstance.appInfo,
101
- appInstance
102
- });
103
- await (appInstance === null || appInstance === void 0 ? void 0 : appInstance.show());
104
- } else {
105
- logger(`MicroApp Garfish.loadApp "${appInfo.name}" mount`, {
106
- appInfo: appInstance.appInfo,
107
- appInstance
108
- });
109
- await (appInstance === null || appInstance === void 0 ? void 0 : appInstance.mount());
110
- }
111
- this.unregisterHistoryListener = history === null || history === void 0 ? void 0 : history.listen(() => {
112
- if (locationHref !== history.location.pathname) {
113
- locationHref = history.location.pathname;
114
- const popStateEvent = new PopStateEvent('popstate');
115
- dispatchEvent(popStateEvent);
116
- logger(`MicroApp Garfish.loadApp popstate`);
147
+ function renderApp() {
148
+ return __async(this, null, function* () {
149
+ try {
150
+ const appInstance = yield Garfish.loadApp(
151
+ appInfo.name,
152
+ loadAppOptions
153
+ );
154
+ if (!appInstance) {
155
+ throw new Error(
156
+ `MicroApp Garfish.loadApp "${appInfo.name}" result is null`
157
+ );
158
+ }
159
+ appRef.current = appInstance;
160
+ setLoadingState({
161
+ isLoading: false
162
+ });
163
+ if (appInstance.mounted && appInstance.appInfo.cache) {
164
+ logger(`MicroApp Garfish.loadApp "${appInfo.name}" show`, {
165
+ appInfo: appInstance.appInfo,
166
+ appInstance
167
+ });
168
+ yield appInstance == null ? void 0 : appInstance.show();
169
+ } else {
170
+ logger(`MicroApp Garfish.loadApp "${appInfo.name}" mount`, {
171
+ appInfo: appInstance.appInfo,
172
+ appInstance
173
+ });
174
+ yield appInstance == null ? void 0 : appInstance.mount();
175
+ }
176
+ } catch (error) {
177
+ setLoadingState({
178
+ isLoading: true,
179
+ error
180
+ });
117
181
  }
118
182
  });
119
- } catch (error) {
120
- setLoadingState({
121
- isLoading: true,
122
- error
123
- });
124
183
  }
125
- }
126
- async componentWillUnmount() {
127
- var _this$unregisterHisto;
128
- const {
129
- appInstance
130
- } = this.state;
131
- (_this$unregisterHisto = this.unregisterHistoryListener) === null || _this$unregisterHisto === void 0 ? void 0 : _this$unregisterHisto.call(this);
132
- if (appInstance) {
133
- const {
134
- appInfo
135
- } = appInstance;
136
- if (appInfo.cache) {
137
- logger(`MicroApp Garfish.loadApp "${appInfo.name}" hide`);
138
- appInstance === null || appInstance === void 0 ? void 0 : appInstance.hide();
139
- } else {
140
- logger(`MicroApp Garfish.loadApp "${appInfo.name}" unmount`);
141
- appInstance === null || appInstance === void 0 ? void 0 : appInstance.unmount();
184
+ renderApp();
185
+ return () => {
186
+ var _a3, _b2;
187
+ if (appRef.current) {
188
+ const { appInfo: appInfo2 } = appRef.current;
189
+ if (appInfo2.cache) {
190
+ logger(`MicroApp Garfish.loadApp "${appInfo2.name}" hide`);
191
+ (_a3 = appRef.current) == null ? void 0 : _a3.hide();
192
+ } else {
193
+ logger(`MicroApp Garfish.loadApp "${appInfo2.name}" unmount`);
194
+ (_b2 = appRef.current) == null ? void 0 : _b2.unmount();
195
+ }
142
196
  }
143
- }
144
- }
145
- render() {
146
- const {
147
- domId,
148
- SubModuleComponent
149
- } = this.state;
150
- return /*#__PURE__*/_jsx(_Fragment, {
151
- children: /*#__PURE__*/_jsx("div", {
152
- id: domId,
153
- children: SubModuleComponent && /*#__PURE__*/_jsx(SubModuleComponent, {})
154
- })
155
- });
156
- }
197
+ };
198
+ }, []);
199
+ return /* @__PURE__ */ jsx(Fragment, {
200
+ children: /* @__PURE__ */ jsx("div", {
201
+ id: domId,
202
+ children: SubModuleComponent && /* @__PURE__ */ jsx(SubModuleComponent, {})
203
+ })
204
+ });
157
205
  }
158
- return Loadable(withRouter(MicroApp))(manifest === null || manifest === void 0 ? void 0 : manifest.loadable);
206
+ return Loadable(MicroApp)(manifest == null ? void 0 : manifest.loadable);
159
207
  }
160
- export function generateApps(options, manifest) {
161
- var _options$apps;
208
+ function generateApps(options, manifest) {
209
+ var _a;
162
210
  const apps = {};
163
- (_options$apps = options.apps) === null || _options$apps === void 0 ? void 0 : _options$apps.forEach(appInfo => {
211
+ (_a = options.apps) == null ? void 0 : _a.forEach((appInfo) => {
164
212
  const Component = getAppInstance(options, appInfo, manifest);
165
213
  appInfo.Component = Component;
166
214
  apps[appInfo.name] = Component;
167
215
  });
168
- return {
169
- apps,
170
- appInfoList: options.apps || []
171
- };
172
- }
216
+ return { apps, appInfoList: options.apps || [] };
217
+ }
218
+ export {
219
+ generateApps,
220
+ pathJoin
221
+ };
@@ -1,12 +1,12 @@
1
- import React from 'react';
2
- import ReactDOM from 'react-dom';
3
- import garfish from 'garfish';
1
+ import React from "react";
2
+ import ReactDOM from "react-dom";
3
+ import garfish from "garfish";
4
4
  import { logger } from "../../util";
5
- export default (() => {
6
- logger('setExternal ', {
7
- react: React,
8
- 'react-dom': ReactDOM
9
- });
10
- garfish.setExternal('react', React);
11
- garfish.setExternal('react-dom', ReactDOM);
12
- });
5
+ var setExternal_default = () => {
6
+ logger("setExternal ", { react: React, "react-dom": ReactDOM });
7
+ garfish.setExternal("react", React);
8
+ garfish.setExternal("react-dom", ReactDOM);
9
+ };
10
+ export {
11
+ setExternal_default as default
12
+ };
@@ -1,9 +1,11 @@
1
- /**
2
- * Tips: this package will be bundled and running in the browser, do not import from `@modern-js/utils`.
3
- */
4
- import createDebug from 'debug';
5
- export const logger = createDebug('modern-js:plugin-garfish');
6
- export const SUBMODULE_APP_COMPONENT_KEY = 'SubModuleComponent';
7
- export function generateSubAppContainerKey(moduleInfo) {
8
- return moduleInfo ? `modern_sub_app_container_${decodeURIComponent(moduleInfo === null || moduleInfo === void 0 ? void 0 : moduleInfo.name)}` : 'modern_sub_app_container';
9
- }
1
+ import createDebug from "debug";
2
+ const logger = createDebug("modern-js:plugin-garfish");
3
+ const SUBMODULE_APP_COMPONENT_KEY = "SubModuleComponent";
4
+ function generateSubAppContainerKey(moduleInfo) {
5
+ return moduleInfo ? `modern_sub_app_container_${decodeURIComponent(moduleInfo == null ? void 0 : moduleInfo.name)}` : "modern_sub_app_container";
6
+ }
7
+ export {
8
+ SUBMODULE_APP_COMPONENT_KEY,
9
+ generateSubAppContainerKey,
10
+ logger
11
+ };