@modern-js/plugin-garfish 1.5.1 → 1.5.4
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.
- package/CHANGELOG.md +9 -0
- package/dist/js/modern/cli/index.js +9 -2
- package/dist/js/modern/cli/utils.js +51 -30
- package/dist/js/modern/runtime/index.js +2 -1
- package/dist/js/modern/runtime/loadable.js +8 -1
- package/dist/js/modern/runtime/utils/MApp.js +85 -29
- package/dist/js/modern/runtime/utils/apps.js +25 -13
- package/dist/js/node/cli/index.js +9 -2
- package/dist/js/node/cli/utils.js +53 -32
- package/dist/js/node/runtime/index.js +8 -0
- package/dist/js/node/runtime/loadable.js +8 -1
- package/dist/js/node/runtime/utils/MApp.js +85 -29
- package/dist/js/node/runtime/utils/apps.js +24 -7
- package/dist/js/treeshaking/cli/index.js +12 -5
- package/dist/js/treeshaking/cli/utils.js +3 -3
- package/dist/js/treeshaking/runtime/index.js +2 -1
- package/dist/js/treeshaking/runtime/loadable.js +6 -1
- package/dist/js/treeshaking/runtime/plugin.js +5 -5
- package/dist/js/treeshaking/runtime/utils/MApp.js +100 -39
- package/dist/js/treeshaking/runtime/utils/apps.js +36 -20
- package/dist/types/runtime/index.d.ts +2 -1
- package/dist/types/runtime/loadable.d.ts +2 -1
- package/dist/types/runtime/useModuleApps.d.ts +1 -0
- package/dist/types/runtime/utils/apps.d.ts +5 -1
- package/package.json +14 -11
- package/type.d.ts +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @modern-js/plugin-garfish
|
|
2
2
|
|
|
3
|
+
## 1.5.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a1198d509: feat: bump babel 7.18.0
|
|
8
|
+
- df0694aba: fix(garfish-plugin): app static properties missing
|
|
9
|
+
- Updated dependencies [a1198d509]
|
|
10
|
+
- @modern-js/plugin-router@1.2.15
|
|
11
|
+
|
|
3
12
|
## 1.5.1
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
|
@@ -103,7 +103,8 @@ export default (({
|
|
|
103
103
|
},
|
|
104
104
|
source: {
|
|
105
105
|
alias: {
|
|
106
|
-
'@modern-js/runtime/plugins': pluginsExportsUtils.getPath()
|
|
106
|
+
'@modern-js/runtime/plugins': pluginsExportsUtils.getPath(),
|
|
107
|
+
'@modern-js/runtime/garfish': _mfPackagePath
|
|
107
108
|
}
|
|
108
109
|
},
|
|
109
110
|
tools: {
|
|
@@ -172,7 +173,7 @@ export default (({
|
|
|
172
173
|
},
|
|
173
174
|
|
|
174
175
|
addRuntimeExports() {
|
|
175
|
-
const addExportStatement = `export { default as garfish, default as masterApp } from '${_mfPackagePath}'`;
|
|
176
|
+
const addExportStatement = `export { default as garfish, default as masterApp, hoistNonReactStatics } from '${_mfPackagePath}'`;
|
|
176
177
|
logger('exportStatement', addExportStatement);
|
|
177
178
|
pluginsExportsUtils.addExport(addExportStatement);
|
|
178
179
|
runtimeExportsUtils.addExport(`export * from '${_mfPackagePath}'`);
|
|
@@ -203,6 +204,12 @@ export default (({
|
|
|
203
204
|
});
|
|
204
205
|
}
|
|
205
206
|
|
|
207
|
+
imports.push({
|
|
208
|
+
value: _runtimePluginName,
|
|
209
|
+
specifiers: [{
|
|
210
|
+
imported: 'hoistNonReactStatics'
|
|
211
|
+
}]
|
|
212
|
+
});
|
|
206
213
|
imports.push({
|
|
207
214
|
value: 'react-dom',
|
|
208
215
|
specifiers: [{
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
export const makeProvider = () => `
|
|
2
2
|
export const provider = function ({basename, dom}) {
|
|
3
3
|
return {
|
|
4
|
-
render({basename, dom, props}) {
|
|
5
|
-
|
|
6
|
-
const node = dom.querySelector('#' + MOUNT_ID) || dom;
|
|
7
|
-
const App = function () {
|
|
8
|
-
return React.createElement(SubApp, props)
|
|
9
|
-
};
|
|
10
|
-
bootstrap(App, node);
|
|
4
|
+
render({basename, dom, props, appName}) {
|
|
5
|
+
render({ props, basename, dom, appName });
|
|
11
6
|
},
|
|
12
7
|
destroy({ dom }) {
|
|
13
8
|
const node = dom.querySelector('#' + MOUNT_ID) || dom;
|
|
@@ -32,35 +27,61 @@ export const provider = function ({basename, dom}) {
|
|
|
32
27
|
if (typeof __GARFISH_EXPORTS__ !== 'undefined') {
|
|
33
28
|
__GARFISH_EXPORTS__.provider = provider;
|
|
34
29
|
}
|
|
35
|
-
`;
|
|
36
|
-
export const makeRenderFunction = code => {
|
|
37
|
-
const inGarfishToRender = `
|
|
38
|
-
const { basename, props } = arguments[0] || {};
|
|
39
|
-
let renderByGarfish = false;
|
|
40
|
-
const renderByProvider = !!basename;
|
|
41
30
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
31
|
+
function canContinueRender ({ dom, appName }) {
|
|
32
|
+
var renderByGarfish =
|
|
33
|
+
typeof __GARFISH_EXPORTS__ !== 'undefined'
|
|
34
|
+
|| typeof window !== 'undefined' && window.Garfish && window.Garfish.activeApps && window.Garfish.activeApps.some((app)=>app.appInfo.name === appName);
|
|
35
|
+
let renderByProvider = dom || appName;
|
|
36
|
+
if (renderByGarfish) {
|
|
37
|
+
// Runs in the Garfish environment and is rendered by the provider
|
|
38
|
+
if (renderByProvider) {
|
|
39
|
+
return true;
|
|
40
|
+
} else {
|
|
41
|
+
// Runs in the Garfish environment and is not rendered by the provider
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
} else {
|
|
45
|
+
// Running in a non-Garfish environment
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
46
49
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
50
|
+
function generateRouterPlugin (basename,routerConfig) {
|
|
51
|
+
if (basename) {
|
|
52
|
+
routerConfig.basename = basename;
|
|
53
|
+
if (routerConfig.supportHtml5History !== false) {
|
|
54
|
+
if (!routerConfig.historyOptions) {
|
|
55
|
+
routerConfig.historyOptions = {
|
|
56
|
+
basename: basename
|
|
57
|
+
};
|
|
58
|
+
} else {
|
|
59
|
+
routerConfig.historyOptions.basename = basename;
|
|
58
60
|
}
|
|
59
61
|
}
|
|
60
|
-
return router(routerConfig);
|
|
61
62
|
}
|
|
63
|
+
return router(routerConfig);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function generateAppWrapperAndRootDom ({ App, props, dom }) {
|
|
67
|
+
let AppWrapper = App;
|
|
68
|
+
if (props) {
|
|
69
|
+
AppWrapper = function () {
|
|
70
|
+
return React.createElement(App, props);
|
|
71
|
+
};
|
|
72
|
+
AppWrapper = hoistNonReactStatics(AppWrapper, App);
|
|
73
|
+
}
|
|
74
|
+
const mountNode = dom ? (dom.querySelector('#' + MOUNT_ID) || dom) : MOUNT_ID;
|
|
75
|
+
return { AppWrapper, mountNode }
|
|
76
|
+
}
|
|
77
|
+
`;
|
|
78
|
+
export const makeRenderFunction = code => {
|
|
79
|
+
const inGarfishToRender = `
|
|
80
|
+
const { basename, props, dom, appName } = typeof arguments[0] === 'object' && arguments[0] || {};
|
|
81
|
+
if (!canContinueRender({ dom, appName })) return null;
|
|
82
|
+
let { AppWrapper, mountNode } = generateAppWrapperAndRootDom({App, props, dom});
|
|
62
83
|
`;
|
|
63
|
-
return inGarfishToRender + code.replace(`router(`, `
|
|
84
|
+
return inGarfishToRender + code.replace(`router(`, `generateRouterPlugin(basename,`).replace('(App)', `(AppWrapper)`).replace('MOUNT_ID', 'mountNode');
|
|
64
85
|
}; // support legacy config
|
|
65
86
|
|
|
66
87
|
export function getRuntimeConfig(config) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { default } from "./plugin";
|
|
2
2
|
export { useModuleApps, useModuleApp } from "./useModuleApps";
|
|
3
|
-
export { default as Garfish, default as garfish } from 'garfish';
|
|
3
|
+
export { default as Garfish, default as garfish } from 'garfish';
|
|
4
|
+
export { default as hoistNonReactStatics } from 'hoist-non-react-statics';
|
|
@@ -144,7 +144,14 @@ export function Loadable(WrapComponent) {
|
|
|
144
144
|
style: {
|
|
145
145
|
display: showLoading ? 'none' : 'block'
|
|
146
146
|
},
|
|
147
|
-
setLoadingState: props =>
|
|
147
|
+
setLoadingState: props => {
|
|
148
|
+
// loading is not provided and there is a rendering exception
|
|
149
|
+
if (props.error && !LoadingComponent) {
|
|
150
|
+
throw props.error;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
this.setStateWithMountCheck(props);
|
|
154
|
+
}
|
|
148
155
|
}, otherProps))]
|
|
149
156
|
});
|
|
150
157
|
}
|
|
@@ -51,49 +51,101 @@ export function generateMApp(options, manifest) {
|
|
|
51
51
|
const garfishOptions = _objectSpread(_objectSpread({
|
|
52
52
|
domGetter: `#${domId}`,
|
|
53
53
|
|
|
54
|
-
beforeLoad(...args) {
|
|
55
|
-
logger('MApp beforeLoad',
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
54
|
+
beforeLoad(appInfo, ...args) {
|
|
55
|
+
logger('MApp beforeLoad', [appInfo]);
|
|
56
|
+
|
|
57
|
+
if (appInfo.activeWhen) {
|
|
58
|
+
setLoadingState({
|
|
59
|
+
isLoading: true,
|
|
60
|
+
error: null
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return beforeLoad === null || beforeLoad === void 0 ? void 0 : beforeLoad(appInfo, ...args);
|
|
61
65
|
},
|
|
62
66
|
|
|
63
|
-
beforeMount(...args) {
|
|
67
|
+
beforeMount(appInfo, ...args) {
|
|
64
68
|
logger('MApp beforeMount', args);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
+
|
|
70
|
+
if (appInfo.activeWhen) {
|
|
71
|
+
setLoadingState({
|
|
72
|
+
isLoading: false
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return beforeMount === null || beforeMount === void 0 ? void 0 : beforeMount(appInfo, ...args);
|
|
69
77
|
},
|
|
70
78
|
|
|
71
|
-
errorLoadApp(error, ...args) {
|
|
79
|
+
errorLoadApp(error, appInfo, ...args) {
|
|
72
80
|
logger('MApp errorLoadApp', error, args);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
81
|
+
|
|
82
|
+
if (appInfo.activeWhen) {
|
|
83
|
+
setLoadingState({
|
|
84
|
+
error
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return errorLoadApp === null || errorLoadApp === void 0 ? void 0 : errorLoadApp(error, appInfo, ...args);
|
|
77
89
|
},
|
|
78
90
|
|
|
79
|
-
errorMountApp(error, ...args) {
|
|
91
|
+
errorMountApp(error, appInfo, ...args) {
|
|
80
92
|
logger('MApp errorMountApp', error, args);
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
93
|
+
|
|
94
|
+
if (appInfo.activeWhen) {
|
|
95
|
+
setLoadingState({
|
|
96
|
+
error
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return errorMountApp === null || errorMountApp === void 0 ? void 0 : errorMountApp(error, appInfo, ...args);
|
|
85
101
|
},
|
|
86
102
|
|
|
87
|
-
errorUnmountApp(error, ...args) {
|
|
103
|
+
errorUnmountApp(error, appInfo, ...args) {
|
|
88
104
|
logger('MApp errorUnmountApp', error, args);
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
105
|
+
|
|
106
|
+
if (appInfo.activeWhen) {
|
|
107
|
+
setLoadingState({
|
|
108
|
+
error
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return errorUnmountApp === null || errorUnmountApp === void 0 ? void 0 : errorUnmountApp(error, appInfo, ...args);
|
|
93
113
|
}
|
|
94
114
|
|
|
95
115
|
}, otherOptions), {}, {
|
|
96
|
-
insulationVariable: [...(otherOptions.insulationVariable || []), '_SERVER_DATA']
|
|
116
|
+
insulationVariable: [...(otherOptions.insulationVariable || []), '_SERVER_DATA'],
|
|
117
|
+
customLoader: provider => {
|
|
118
|
+
const {
|
|
119
|
+
render,
|
|
120
|
+
destroy,
|
|
121
|
+
SubModuleComponent,
|
|
122
|
+
jupiter_submodule_app_key
|
|
123
|
+
} = provider;
|
|
124
|
+
const componetRenderMode = (manifest === null || manifest === void 0 ? void 0 : manifest.componentRender) && (SubModuleComponent || jupiter_submodule_app_key);
|
|
125
|
+
return {
|
|
126
|
+
mount: (...props) => {
|
|
127
|
+
if (componetRenderMode) {
|
|
128
|
+
this.setState({
|
|
129
|
+
SubModuleComponent: SubModuleComponent !== null && SubModuleComponent !== void 0 ? SubModuleComponent : jupiter_submodule_app_key
|
|
130
|
+
});
|
|
131
|
+
return undefined;
|
|
132
|
+
} else {
|
|
133
|
+
logger('MicroApp customer render', props);
|
|
134
|
+
return render === null || render === void 0 ? void 0 : render.apply(provider, props);
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
|
|
138
|
+
unmount(...props) {
|
|
139
|
+
if (componetRenderMode) {
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
logger('MicroApp customer destroy', props);
|
|
144
|
+
return destroy === null || destroy === void 0 ? void 0 : destroy.apply(provider, props);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
};
|
|
148
|
+
}
|
|
97
149
|
});
|
|
98
150
|
|
|
99
151
|
logger('MApp componentDidMount', {
|
|
@@ -115,8 +167,12 @@ export function generateMApp(options, manifest) {
|
|
|
115
167
|
}
|
|
116
168
|
|
|
117
169
|
render() {
|
|
170
|
+
const {
|
|
171
|
+
SubModuleComponent
|
|
172
|
+
} = this.state;
|
|
118
173
|
return /*#__PURE__*/_jsx("div", {
|
|
119
|
-
id: generateSubAppContainerKey()
|
|
174
|
+
id: generateSubAppContainerKey(),
|
|
175
|
+
children: SubModuleComponent && /*#__PURE__*/_jsx(SubModuleComponent, {})
|
|
120
176
|
});
|
|
121
177
|
}
|
|
122
178
|
|
|
@@ -18,12 +18,7 @@ import Garfish from 'garfish';
|
|
|
18
18
|
import { withRouter } from '@modern-js/plugin-router'; // import Loadable from 'react-loadable';
|
|
19
19
|
|
|
20
20
|
import { logger, generateSubAppContainerKey } from "../../util";
|
|
21
|
-
import { Loadable } from "../loadable";
|
|
22
|
-
// render: () => void;
|
|
23
|
-
// destroy: () => void;
|
|
24
|
-
// [SUBMODULE_APP_COMPONENT_KEY]?: React.ComponentType<any>;
|
|
25
|
-
// };
|
|
26
|
-
|
|
21
|
+
import { Loadable } from "../loadable";
|
|
27
22
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
28
23
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
29
24
|
|
|
@@ -36,7 +31,8 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
36
31
|
|
|
37
32
|
_defineProperty(this, "state", {
|
|
38
33
|
appInstance: null,
|
|
39
|
-
domId: generateSubAppContainerKey(appInfo)
|
|
34
|
+
domId: generateSubAppContainerKey(appInfo),
|
|
35
|
+
SubModuleComponent: undefined
|
|
40
36
|
});
|
|
41
37
|
|
|
42
38
|
_defineProperty(this, "unregisterHistoryListener", () => {});
|
|
@@ -65,15 +61,29 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
65
61
|
customLoader: provider => {
|
|
66
62
|
const {
|
|
67
63
|
render,
|
|
68
|
-
destroy
|
|
64
|
+
destroy,
|
|
65
|
+
SubModuleComponent,
|
|
66
|
+
jupiter_submodule_app_key
|
|
69
67
|
} = provider;
|
|
68
|
+
const componetRenderMode = (manifest === null || manifest === void 0 ? void 0 : manifest.componentRender) && (SubModuleComponent || jupiter_submodule_app_key);
|
|
70
69
|
return {
|
|
71
|
-
mount(...props) {
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
mount: (...props) => {
|
|
71
|
+
if (componetRenderMode) {
|
|
72
|
+
this.setState({
|
|
73
|
+
SubModuleComponent: SubModuleComponent !== null && SubModuleComponent !== void 0 ? SubModuleComponent : jupiter_submodule_app_key
|
|
74
|
+
});
|
|
75
|
+
return undefined;
|
|
76
|
+
} else {
|
|
77
|
+
logger('MicroApp customer render', props);
|
|
78
|
+
return render === null || render === void 0 ? void 0 : render.apply(provider, props);
|
|
79
|
+
}
|
|
74
80
|
},
|
|
75
81
|
|
|
76
82
|
unmount(...props) {
|
|
83
|
+
if (componetRenderMode) {
|
|
84
|
+
return undefined;
|
|
85
|
+
}
|
|
86
|
+
|
|
77
87
|
logger('MicroApp customer destroy', props);
|
|
78
88
|
return destroy === null || destroy === void 0 ? void 0 : destroy.apply(provider, props);
|
|
79
89
|
}
|
|
@@ -159,11 +169,13 @@ function getAppInstance(options, appInfo, manifest) {
|
|
|
159
169
|
|
|
160
170
|
render() {
|
|
161
171
|
const {
|
|
162
|
-
domId
|
|
172
|
+
domId,
|
|
173
|
+
SubModuleComponent
|
|
163
174
|
} = this.state;
|
|
164
175
|
return /*#__PURE__*/_jsx(_Fragment, {
|
|
165
176
|
children: /*#__PURE__*/_jsx("div", {
|
|
166
|
-
id: domId
|
|
177
|
+
id: domId,
|
|
178
|
+
children: SubModuleComponent && /*#__PURE__*/_jsx(SubModuleComponent, {})
|
|
167
179
|
})
|
|
168
180
|
});
|
|
169
181
|
}
|
|
@@ -120,7 +120,8 @@ var _default = ({
|
|
|
120
120
|
},
|
|
121
121
|
source: {
|
|
122
122
|
alias: {
|
|
123
|
-
'@modern-js/runtime/plugins': pluginsExportsUtils.getPath()
|
|
123
|
+
'@modern-js/runtime/plugins': pluginsExportsUtils.getPath(),
|
|
124
|
+
'@modern-js/runtime/garfish': _mfPackagePath
|
|
124
125
|
}
|
|
125
126
|
},
|
|
126
127
|
tools: {
|
|
@@ -189,7 +190,7 @@ var _default = ({
|
|
|
189
190
|
},
|
|
190
191
|
|
|
191
192
|
addRuntimeExports() {
|
|
192
|
-
const addExportStatement = `export { default as garfish, default as masterApp } from '${_mfPackagePath}'`;
|
|
193
|
+
const addExportStatement = `export { default as garfish, default as masterApp, hoistNonReactStatics } from '${_mfPackagePath}'`;
|
|
193
194
|
(0, _util.logger)('exportStatement', addExportStatement);
|
|
194
195
|
pluginsExportsUtils.addExport(addExportStatement);
|
|
195
196
|
runtimeExportsUtils.addExport(`export * from '${_mfPackagePath}'`);
|
|
@@ -220,6 +221,12 @@ var _default = ({
|
|
|
220
221
|
});
|
|
221
222
|
}
|
|
222
223
|
|
|
224
|
+
imports.push({
|
|
225
|
+
value: _runtimePluginName,
|
|
226
|
+
specifiers: [{
|
|
227
|
+
imported: 'hoistNonReactStatics'
|
|
228
|
+
}]
|
|
229
|
+
});
|
|
223
230
|
imports.push({
|
|
224
231
|
value: 'react-dom',
|
|
225
232
|
specifiers: [{
|
|
@@ -10,13 +10,8 @@ exports.setRuntimeConfig = setRuntimeConfig;
|
|
|
10
10
|
const makeProvider = () => `
|
|
11
11
|
export const provider = function ({basename, dom}) {
|
|
12
12
|
return {
|
|
13
|
-
render({basename, dom, props}) {
|
|
14
|
-
|
|
15
|
-
const node = dom.querySelector('#' + MOUNT_ID) || dom;
|
|
16
|
-
const App = function () {
|
|
17
|
-
return React.createElement(SubApp, props)
|
|
18
|
-
};
|
|
19
|
-
bootstrap(App, node);
|
|
13
|
+
render({basename, dom, props, appName}) {
|
|
14
|
+
render({ props, basename, dom, appName });
|
|
20
15
|
},
|
|
21
16
|
destroy({ dom }) {
|
|
22
17
|
const node = dom.querySelector('#' + MOUNT_ID) || dom;
|
|
@@ -41,38 +36,64 @@ export const provider = function ({basename, dom}) {
|
|
|
41
36
|
if (typeof __GARFISH_EXPORTS__ !== 'undefined') {
|
|
42
37
|
__GARFISH_EXPORTS__.provider = provider;
|
|
43
38
|
}
|
|
39
|
+
|
|
40
|
+
function canContinueRender ({ dom, appName }) {
|
|
41
|
+
var renderByGarfish =
|
|
42
|
+
typeof __GARFISH_EXPORTS__ !== 'undefined'
|
|
43
|
+
|| typeof window !== 'undefined' && window.Garfish && window.Garfish.activeApps && window.Garfish.activeApps.some((app)=>app.appInfo.name === appName);
|
|
44
|
+
let renderByProvider = dom || appName;
|
|
45
|
+
if (renderByGarfish) {
|
|
46
|
+
// Runs in the Garfish environment and is rendered by the provider
|
|
47
|
+
if (renderByProvider) {
|
|
48
|
+
return true;
|
|
49
|
+
} else {
|
|
50
|
+
// Runs in the Garfish environment and is not rendered by the provider
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
// Running in a non-Garfish environment
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function generateRouterPlugin (basename,routerConfig) {
|
|
60
|
+
if (basename) {
|
|
61
|
+
routerConfig.basename = basename;
|
|
62
|
+
if (routerConfig.supportHtml5History !== false) {
|
|
63
|
+
if (!routerConfig.historyOptions) {
|
|
64
|
+
routerConfig.historyOptions = {
|
|
65
|
+
basename: basename
|
|
66
|
+
};
|
|
67
|
+
} else {
|
|
68
|
+
routerConfig.historyOptions.basename = basename;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return router(routerConfig);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function generateAppWrapperAndRootDom ({ App, props, dom }) {
|
|
76
|
+
let AppWrapper = App;
|
|
77
|
+
if (props) {
|
|
78
|
+
AppWrapper = function () {
|
|
79
|
+
return React.createElement(App, props);
|
|
80
|
+
};
|
|
81
|
+
AppWrapper = hoistNonReactStatics(AppWrapper, App);
|
|
82
|
+
}
|
|
83
|
+
const mountNode = dom ? (dom.querySelector('#' + MOUNT_ID) || dom) : MOUNT_ID;
|
|
84
|
+
return { AppWrapper, mountNode }
|
|
85
|
+
}
|
|
44
86
|
`;
|
|
45
87
|
|
|
46
88
|
exports.makeProvider = makeProvider;
|
|
47
89
|
|
|
48
90
|
const makeRenderFunction = code => {
|
|
49
91
|
const inGarfishToRender = `
|
|
50
|
-
const { basename, props } = arguments[0] || {};
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (IS_BROWSER && window.Garfish && window.Garfish.activeApps && window.Garfish.activeApps.length !== 0) renderByGarfish = true;
|
|
55
|
-
if (IS_BROWSER && window.Garfish && window.Garfish.apps && Object.keys(window.Garfish.apps).length !== 0) renderByGarfish = true;
|
|
56
|
-
if (typeof __GARFISH_EXPORTS__ !== 'undefined') renderByGarfish = true;
|
|
57
|
-
if (renderByGarfish && !renderByProvider) return null;
|
|
58
|
-
|
|
59
|
-
function RouterPlugin (routerConfig) {
|
|
60
|
-
if (basename) {
|
|
61
|
-
routerConfig.basename = basename;
|
|
62
|
-
if (routerConfig.supportHtml5History !== false) {
|
|
63
|
-
if (!routerConfig.historyOptions) {
|
|
64
|
-
routerConfig.historyOptions = {
|
|
65
|
-
basename: basename
|
|
66
|
-
};
|
|
67
|
-
} else {
|
|
68
|
-
routerConfig.historyOptions.basename = basename;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return router(routerConfig);
|
|
73
|
-
}
|
|
92
|
+
const { basename, props, dom, appName } = typeof arguments[0] === 'object' && arguments[0] || {};
|
|
93
|
+
if (!canContinueRender({ dom, appName })) return null;
|
|
94
|
+
let { AppWrapper, mountNode } = generateAppWrapperAndRootDom({App, props, dom});
|
|
74
95
|
`;
|
|
75
|
-
return inGarfishToRender + code.replace(`router(`, `
|
|
96
|
+
return inGarfishToRender + code.replace(`router(`, `generateRouterPlugin(basename,`).replace('(App)', `(AppWrapper)`).replace('MOUNT_ID', 'mountNode');
|
|
76
97
|
}; // support legacy config
|
|
77
98
|
|
|
78
99
|
|
|
@@ -21,6 +21,12 @@ Object.defineProperty(exports, "garfish", {
|
|
|
21
21
|
return _garfish.default;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
|
+
Object.defineProperty(exports, "hoistNonReactStatics", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _hoistNonReactStatics.default;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
24
30
|
Object.defineProperty(exports, "useModuleApp", {
|
|
25
31
|
enumerable: true,
|
|
26
32
|
get: function () {
|
|
@@ -40,4 +46,6 @@ var _useModuleApps = require("./useModuleApps");
|
|
|
40
46
|
|
|
41
47
|
var _garfish = _interopRequireDefault(require("garfish"));
|
|
42
48
|
|
|
49
|
+
var _hoistNonReactStatics = _interopRequireDefault(require("hoist-non-react-statics"));
|
|
50
|
+
|
|
43
51
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -153,7 +153,14 @@ function Loadable(WrapComponent) {
|
|
|
153
153
|
style: {
|
|
154
154
|
display: showLoading ? 'none' : 'block'
|
|
155
155
|
},
|
|
156
|
-
setLoadingState: props =>
|
|
156
|
+
setLoadingState: props => {
|
|
157
|
+
// loading is not provided and there is a rendering exception
|
|
158
|
+
if (props.error && !LoadingComponent) {
|
|
159
|
+
throw props.error;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
this.setStateWithMountCheck(props);
|
|
163
|
+
}
|
|
157
164
|
}, otherProps))]
|
|
158
165
|
});
|
|
159
166
|
}
|