@modern-js/plugin-garfish 2.0.0-beta.6 → 2.0.0
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 +39 -0
- package/dist/js/modern/cli/index.js +6 -17
- package/dist/js/modern/cli/utils.js +7 -4
- package/dist/js/modern/runtime/plugin.js +1 -1
- package/dist/js/modern/runtime/utils/apps.js +138 -124
- package/dist/js/node/cli/index.js +6 -23
- package/dist/js/node/cli/utils.js +7 -4
- package/dist/js/node/runtime/plugin.js +1 -1
- package/dist/js/node/runtime/utils/apps.js +140 -125
- package/dist/js/treeshaking/cli/index.js +5 -10
- package/dist/js/treeshaking/cli/utils.js +2 -2
- package/dist/js/treeshaking/runtime/plugin.js +1 -1
- package/dist/js/treeshaking/runtime/utils/apps.js +229 -287
- package/dist/types/cli/index.d.ts +4 -7
- package/dist/types/runtime/loadable.d.ts +1 -2
- package/dist/types/runtime/useModuleApps.d.ts +9 -9
- package/dist/types/runtime/utils/apps.d.ts +1 -0
- package/package.json +11 -10
- package/type.d.ts +5 -0
- package/dist/js/modern/cli/types.js +0 -0
- package/dist/js/node/cli/types.js +0 -0
- package/dist/js/treeshaking/cli/types.js +0 -1
- package/dist/types/cli/types.d.ts +0 -6
|
@@ -72,151 +72,165 @@ var __async = (__this, __arguments, generator) => {
|
|
|
72
72
|
};
|
|
73
73
|
var apps_exports = {};
|
|
74
74
|
__export(apps_exports, {
|
|
75
|
-
generateApps: () => generateApps
|
|
75
|
+
generateApps: () => generateApps,
|
|
76
|
+
pathJoin: () => pathJoin
|
|
76
77
|
});
|
|
77
78
|
module.exports = __toCommonJS(apps_exports);
|
|
78
79
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
79
|
-
var
|
|
80
|
-
var
|
|
80
|
+
var import_react = require("react");
|
|
81
|
+
var import_runtime = require("@modern-js/runtime");
|
|
81
82
|
var import_garfish = __toESM(require("garfish"));
|
|
82
|
-
var import_runtime = require("@modern-js/plugin-router-v5/runtime");
|
|
83
83
|
var import_util = require("../../util");
|
|
84
84
|
var import_loadable = require("../loadable");
|
|
85
|
+
function pathJoin(...args) {
|
|
86
|
+
const res = args.reduce((res2, path) => {
|
|
87
|
+
let nPath = path;
|
|
88
|
+
if (!nPath || typeof nPath !== "string") {
|
|
89
|
+
return res2;
|
|
90
|
+
}
|
|
91
|
+
if (nPath[0] !== "/") {
|
|
92
|
+
nPath = `/${nPath}`;
|
|
93
|
+
}
|
|
94
|
+
const lastIndex = nPath.length - 1;
|
|
95
|
+
if (nPath[lastIndex] === "/") {
|
|
96
|
+
nPath = nPath.substring(0, lastIndex);
|
|
97
|
+
}
|
|
98
|
+
return res2 + nPath;
|
|
99
|
+
}, "");
|
|
100
|
+
return res || "/";
|
|
101
|
+
}
|
|
85
102
|
function getAppInstance(options, appInfo, manifest) {
|
|
86
103
|
let locationHref = "";
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
104
|
+
function MicroApp(props) {
|
|
105
|
+
var _a, _b, _c, _d, _e, _f;
|
|
106
|
+
const appRef = (0, import_react.useRef)(null);
|
|
107
|
+
const domId = (0, import_util.generateSubAppContainerKey)(appInfo);
|
|
108
|
+
const [SubModuleComponent, setSubModuleComponent] = (0, import_react.useState)();
|
|
109
|
+
const context = (0, import_react.useContext)(import_runtime.RuntimeReactContext);
|
|
110
|
+
const match = (_b = (_a = context == null ? void 0 : context.router) == null ? void 0 : _a.useRouteMatch) == null ? void 0 : _b.call(_a);
|
|
111
|
+
const matchs = (_d = (_c = context == null ? void 0 : context.router) == null ? void 0 : _c.useMatches) == null ? void 0 : _d.call(_c);
|
|
112
|
+
const location = (_f = (_e = context == null ? void 0 : context.router) == null ? void 0 : _e.useLocation) == null ? void 0 : _f.call(_e);
|
|
113
|
+
let basename = (options == null ? void 0 : options.basename) || "/";
|
|
114
|
+
if (matchs && matchs.length > 0) {
|
|
115
|
+
basename = pathJoin(basename, matchs[matchs.length - 1].pathname || "/");
|
|
116
|
+
} else if (match) {
|
|
117
|
+
basename = pathJoin(basename, (match == null ? void 0 : match.path) || "/");
|
|
97
118
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
(0, import_util.logger)("MicroApp customer destroy", props);
|
|
136
|
-
return destroy == null ? void 0 : destroy.apply(provider, props);
|
|
119
|
+
(0, import_react.useEffect)(() => {
|
|
120
|
+
if (location && locationHref !== location.pathname && !import_garfish.default.running) {
|
|
121
|
+
locationHref = location.pathname;
|
|
122
|
+
const popStateEvent = new PopStateEvent("popstate");
|
|
123
|
+
popStateEvent.garfish = true;
|
|
124
|
+
dispatchEvent(popStateEvent);
|
|
125
|
+
(0, import_util.logger)(`MicroApp Garfish.loadApp popstate`);
|
|
126
|
+
}
|
|
127
|
+
}, [location]);
|
|
128
|
+
(0, import_react.useEffect)(() => {
|
|
129
|
+
const _a2 = props, { setLoadingState } = _a2, userProps = __objRest(_a2, ["setLoadingState"]);
|
|
130
|
+
const loadAppOptions = __spreadProps(__spreadValues({}, appInfo), {
|
|
131
|
+
insulationVariable: [
|
|
132
|
+
...appInfo.insulationVariable || [],
|
|
133
|
+
"_SERVER_DATA"
|
|
134
|
+
],
|
|
135
|
+
domGetter: `#${domId}`,
|
|
136
|
+
basename,
|
|
137
|
+
cache: true,
|
|
138
|
+
props: __spreadValues(__spreadValues({}, appInfo.props), userProps),
|
|
139
|
+
customLoader: (provider) => {
|
|
140
|
+
const {
|
|
141
|
+
render,
|
|
142
|
+
destroy,
|
|
143
|
+
SubModuleComponent: SubModuleComponent2,
|
|
144
|
+
jupiter_submodule_app_key
|
|
145
|
+
} = provider;
|
|
146
|
+
const componetRenderMode = (manifest == null ? void 0 : manifest.componentRender) && (SubModuleComponent2 || jupiter_submodule_app_key);
|
|
147
|
+
return {
|
|
148
|
+
mount: (...props2) => {
|
|
149
|
+
if (componetRenderMode) {
|
|
150
|
+
setSubModuleComponent(SubModuleComponent2);
|
|
151
|
+
return void 0;
|
|
152
|
+
} else {
|
|
153
|
+
(0, import_util.logger)("MicroApp customer render", props2);
|
|
154
|
+
return render == null ? void 0 : render.apply(provider, props2);
|
|
137
155
|
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
156
|
+
},
|
|
157
|
+
unmount(...props2) {
|
|
158
|
+
if (componetRenderMode) {
|
|
159
|
+
return void 0;
|
|
160
|
+
}
|
|
161
|
+
(0, import_util.logger)("MicroApp customer destroy", props2);
|
|
162
|
+
return destroy == null ? void 0 : destroy.apply(provider, props2);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
setLoadingState({
|
|
168
|
+
isLoading: true,
|
|
169
|
+
error: null
|
|
170
|
+
});
|
|
171
|
+
(0, import_util.logger)(`MicroApp Garfish.loadApp "${appInfo.name}"`, {
|
|
172
|
+
loadAppOptions
|
|
173
|
+
});
|
|
174
|
+
function renderApp() {
|
|
175
|
+
return __async(this, null, function* () {
|
|
176
|
+
try {
|
|
177
|
+
const appInstance = yield import_garfish.default.loadApp(
|
|
178
|
+
appInfo.name,
|
|
179
|
+
loadAppOptions
|
|
153
180
|
);
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
(0, import_util.logger)(`MicroApp Garfish.loadApp "${appInfo.name}" show`, {
|
|
163
|
-
appInfo: appInstance.appInfo,
|
|
164
|
-
appInstance
|
|
181
|
+
if (!appInstance) {
|
|
182
|
+
throw new Error(
|
|
183
|
+
`MicroApp Garfish.loadApp "${appInfo.name}" result is null`
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
appRef.current = appInstance;
|
|
187
|
+
setLoadingState({
|
|
188
|
+
isLoading: false
|
|
165
189
|
});
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
190
|
+
if (appInstance.mounted && appInstance.appInfo.cache) {
|
|
191
|
+
(0, import_util.logger)(`MicroApp Garfish.loadApp "${appInfo.name}" show`, {
|
|
192
|
+
appInfo: appInstance.appInfo,
|
|
193
|
+
appInstance
|
|
194
|
+
});
|
|
195
|
+
yield appInstance == null ? void 0 : appInstance.show();
|
|
196
|
+
} else {
|
|
197
|
+
(0, import_util.logger)(`MicroApp Garfish.loadApp "${appInfo.name}" mount`, {
|
|
198
|
+
appInfo: appInstance.appInfo,
|
|
199
|
+
appInstance
|
|
200
|
+
});
|
|
201
|
+
yield appInstance == null ? void 0 : appInstance.mount();
|
|
202
|
+
}
|
|
203
|
+
} catch (error) {
|
|
204
|
+
setLoadingState({
|
|
205
|
+
isLoading: true,
|
|
206
|
+
error
|
|
171
207
|
});
|
|
172
|
-
yield appInstance == null ? void 0 : appInstance.mount();
|
|
173
208
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
});
|
|
182
|
-
} catch (error) {
|
|
183
|
-
setLoadingState({
|
|
184
|
-
isLoading: true,
|
|
185
|
-
error
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
componentWillUnmount() {
|
|
191
|
-
return __async(this, null, function* () {
|
|
192
|
-
var _a;
|
|
193
|
-
const { appInstance } = this.state;
|
|
194
|
-
(_a = this.unregisterHistoryListener) == null ? void 0 : _a.call(this);
|
|
195
|
-
if (appInstance) {
|
|
196
|
-
const { appInfo: appInfo2 } = appInstance;
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
renderApp();
|
|
212
|
+
return () => {
|
|
213
|
+
var _a3, _b2;
|
|
214
|
+
if (appRef.current) {
|
|
215
|
+
const { appInfo: appInfo2 } = appRef.current;
|
|
197
216
|
if (appInfo2.cache) {
|
|
198
217
|
(0, import_util.logger)(`MicroApp Garfish.loadApp "${appInfo2.name}" hide`);
|
|
199
|
-
|
|
218
|
+
(_a3 = appRef.current) == null ? void 0 : _a3.hide();
|
|
200
219
|
} else {
|
|
201
220
|
(0, import_util.logger)(`MicroApp Garfish.loadApp "${appInfo2.name}" unmount`);
|
|
202
|
-
|
|
221
|
+
(_b2 = appRef.current) == null ? void 0 : _b2.unmount();
|
|
203
222
|
}
|
|
204
223
|
}
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
})
|
|
214
|
-
});
|
|
215
|
-
}
|
|
224
|
+
};
|
|
225
|
+
}, []);
|
|
226
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
|
|
227
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
|
|
228
|
+
id: domId,
|
|
229
|
+
children: SubModuleComponent && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SubModuleComponent, {})
|
|
230
|
+
})
|
|
231
|
+
});
|
|
216
232
|
}
|
|
217
|
-
return (0, import_loadable.Loadable)((0
|
|
218
|
-
manifest == null ? void 0 : manifest.loadable
|
|
219
|
-
);
|
|
233
|
+
return (0, import_loadable.Loadable)(MicroApp)(manifest == null ? void 0 : manifest.loadable);
|
|
220
234
|
}
|
|
221
235
|
function generateApps(options, manifest) {
|
|
222
236
|
var _a;
|
|
@@ -230,5 +244,6 @@ function generateApps(options, manifest) {
|
|
|
230
244
|
}
|
|
231
245
|
// Annotate the CommonJS export names for ESM import in node:
|
|
232
246
|
0 && (module.exports = {
|
|
233
|
-
generateApps
|
|
247
|
+
generateApps,
|
|
248
|
+
pathJoin
|
|
234
249
|
});
|
|
@@ -150,11 +150,9 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
150
150
|
};
|
|
151
151
|
}
|
|
152
152
|
};
|
|
153
|
-
import path from "path";
|
|
154
153
|
import { createRuntimeExportsUtils, PLUGIN_SCHEMAS } from "@modern-js/utils";
|
|
155
154
|
import { logger } from "../util";
|
|
156
155
|
import { getRuntimeConfig, makeProvider, makeRenderFunction, setRuntimeConfig, generateAsyncEntry } from "./utils";
|
|
157
|
-
import "./types";
|
|
158
156
|
var externals = {
|
|
159
157
|
"react-dom": "react-dom",
|
|
160
158
|
react: "react"
|
|
@@ -173,13 +171,12 @@ function getDefaultMicroFrontedConfig(microFrontend) {
|
|
|
173
171
|
}, microFrontend);
|
|
174
172
|
}
|
|
175
173
|
var cli_default = function() {
|
|
176
|
-
var ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, _pluginName = ref.pluginName, pluginName = _pluginName === void 0 ? "@modern-js/plugin-garfish" : _pluginName, _runtimePluginName = ref.runtimePluginName, runtimePluginName = _runtimePluginName === void 0 ? "@modern-js/runtime/plugins" : _runtimePluginName
|
|
174
|
+
var ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, _pluginName = ref.pluginName, pluginName = _pluginName === void 0 ? "@modern-js/plugin-garfish" : _pluginName, _runtimePluginName = ref.runtimePluginName, runtimePluginName = _runtimePluginName === void 0 ? "@modern-js/runtime/plugins" : _runtimePluginName;
|
|
177
175
|
return {
|
|
178
176
|
name: "@modern-js/plugin-garfish",
|
|
179
177
|
setup: function(param) {
|
|
180
178
|
var useAppContext = param.useAppContext, useResolvedConfigContext = param.useResolvedConfigContext, useConfigContext = param.useConfigContext;
|
|
181
179
|
var pluginsExportsUtils;
|
|
182
|
-
var runtimeExportsUtils;
|
|
183
180
|
return {
|
|
184
181
|
validateSchema: function validateSchema() {
|
|
185
182
|
return PLUGIN_SCHEMAS["@modern-js/plugin-garfish"];
|
|
@@ -221,7 +218,6 @@ var cli_default = function() {
|
|
|
221
218
|
logger("useConfig", useConfig);
|
|
222
219
|
var config = useAppContext();
|
|
223
220
|
pluginsExportsUtils = createRuntimeExportsUtils(config.internalDirectory, "plugins");
|
|
224
|
-
runtimeExportsUtils = createRuntimeExportsUtils(config.internalDirectory, "index");
|
|
225
221
|
var disableCssExtract = ((ref = useConfig.output) === null || ref === void 0 ? void 0 : ref.disableCssExtract) || false;
|
|
226
222
|
if ((ref1 = useConfig.deploy) === null || ref1 === void 0 ? void 0 : ref1.microFrontend) {
|
|
227
223
|
var ref2;
|
|
@@ -237,7 +233,7 @@ var cli_default = function() {
|
|
|
237
233
|
source: {
|
|
238
234
|
alias: {
|
|
239
235
|
"@modern-js/runtime/plugins": pluginsExportsUtils.getPath(),
|
|
240
|
-
"@modern-js/runtime/garfish":
|
|
236
|
+
"@modern-js/runtime/garfish": "@modern-js/plugin-garfish/runtime"
|
|
241
237
|
}
|
|
242
238
|
},
|
|
243
239
|
tools: {
|
|
@@ -251,9 +247,9 @@ var cli_default = function() {
|
|
|
251
247
|
var ref, ref1;
|
|
252
248
|
var resolveOptions = useResolvedConfigContext();
|
|
253
249
|
if (resolveOptions === null || resolveOptions === void 0 ? void 0 : (ref = resolveOptions.deploy) === null || ref === void 0 ? void 0 : ref.microFrontend) {
|
|
254
|
-
var ref2, ref3;
|
|
250
|
+
var ref2, ref3, ref4;
|
|
255
251
|
chain.output.libraryTarget("umd");
|
|
256
|
-
if ((resolveOptions === null || resolveOptions === void 0 ? void 0 : (
|
|
252
|
+
if (!((ref2 = useConfig.dev) === null || ref2 === void 0 ? void 0 : ref2.assetPrefix) && (resolveOptions === null || resolveOptions === void 0 ? void 0 : (ref3 = resolveOptions.server) === null || ref3 === void 0 ? void 0 : ref3.port) && env === "development") {
|
|
257
253
|
chain.output.publicPath("//localhost:".concat(resolveOptions.server.port, "/"));
|
|
258
254
|
}
|
|
259
255
|
if (webpack.BannerPlugin) {
|
|
@@ -263,7 +259,7 @@ var cli_default = function() {
|
|
|
263
259
|
}
|
|
264
260
|
]);
|
|
265
261
|
}
|
|
266
|
-
var
|
|
262
|
+
var ref5 = getDefaultMicroFrontedConfig((ref4 = resolveOptions.deploy) === null || ref4 === void 0 ? void 0 : ref4.microFrontend), enableHtmlEntry = ref5.enableHtmlEntry, externalBasicLibrary = ref5.externalBasicLibrary;
|
|
267
263
|
if (externalBasicLibrary) {
|
|
268
264
|
chain.externals(externals);
|
|
269
265
|
}
|
|
@@ -292,7 +288,6 @@ var cli_default = function() {
|
|
|
292
288
|
var addExportStatement = "export { default as garfish, default as masterApp, hoistNonReactStatics } from '".concat(pluginName, "/runtime'");
|
|
293
289
|
logger("exportStatement", addExportStatement);
|
|
294
290
|
pluginsExportsUtils.addExport(addExportStatement);
|
|
295
|
-
runtimeExportsUtils.addExport("export * from '".concat(mfPackagePath, "/runtime'"));
|
|
296
291
|
},
|
|
297
292
|
modifyEntryImports: function modifyEntryImports(param) {
|
|
298
293
|
var entrypoint = param.entrypoint, imports = param.imports;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
var makeProvider = function() {
|
|
2
|
-
return "\nexport const provider = function ({basename, dom}) {\n return {\n render({basename, dom, props, appName}) {\n render({ props, basename, dom, appName });\n },\n destroy({ dom }) {\n const node = dom.querySelector('#' + MOUNT_ID) || dom;\n\n if (node) {\n if (IS_REACT18) {\n root.unmount();\n } else {\n unmountComponentAtNode(node);\n }\n }\n },\n SubModuleComponent: (props) => {\n const SubApp = render({props, basename});\n\n return createPortal(<SubApp />, dom.querySelector('#' + MOUNT_ID) || dom);\n },\n jupiter_submodule_app_key: (props) => {\n const SubApp = render({props, basename});\n\n return createPortal(<SubApp />, dom.querySelector('#' + MOUNT_ID) || dom);\n }\n }\n};\n\nif (typeof __GARFISH_EXPORTS__ !== 'undefined') {\n __GARFISH_EXPORTS__.provider = provider;\n}\n\nfunction canContinueRender ({ dom, appName }) {\n var renderByGarfish =\n typeof __GARFISH_EXPORTS__ !== 'undefined'\n || typeof window !== 'undefined' && window.Garfish && window.Garfish.activeApps && window.Garfish.activeApps.some((app)=>app.appInfo.name === appName);\n let renderByProvider = dom || appName;\n if (renderByGarfish) {\n // Runs in the Garfish environment and is rendered by the provider\n if (renderByProvider) {\n return true;\n } else {\n // Runs in the Garfish environment and is not rendered by the provider\n return false;\n }\n } else {\n // Running in a non-Garfish environment\n return true;\n }\n}\n\nfunction generateRouterPlugin (basename,routerConfig) {\n if (basename) {\n routerConfig.basename = basename;\n if (routerConfig.supportHtml5History !== false) {\n if (!routerConfig.historyOptions) {\n routerConfig.historyOptions = {\n basename: basename\n };\n } else {\n routerConfig.historyOptions.basename = basename;\n }\n }\n }\n return router(routerConfig);\n}\n\nfunction generateAppWrapperAndRootDom ({ App, props, dom }) {\n let AppWrapper = App;\n if (
|
|
2
|
+
return "\nexport const provider = function ({basename, dom}) {\n return {\n render({basename, dom, props, appName}) {\n render({ props, basename, dom, appName });\n },\n destroy({ dom }) {\n const node = dom.querySelector('#' + MOUNT_ID) || dom;\n\n if (node) {\n if (IS_REACT18) {\n root.unmount();\n } else {\n unmountComponentAtNode(node);\n }\n }\n },\n SubModuleComponent: (props) => {\n const SubApp = render({props, basename});\n\n return createPortal(<SubApp />, dom.querySelector('#' + MOUNT_ID) || dom);\n },\n jupiter_submodule_app_key: (props) => {\n const SubApp = render({props, basename});\n\n return createPortal(<SubApp />, dom.querySelector('#' + MOUNT_ID) || dom);\n }\n }\n};\n\nif (typeof __GARFISH_EXPORTS__ !== 'undefined') {\n __GARFISH_EXPORTS__.provider = provider;\n}\n\nfunction canContinueRender ({ dom, appName }) {\n var renderByGarfish =\n typeof __GARFISH_EXPORTS__ !== 'undefined'\n || typeof window !== 'undefined' && window.Garfish && window.Garfish.activeApps && window.Garfish.activeApps.some((app)=>app.appInfo.name === appName);\n let renderByProvider = dom || appName;\n if (renderByGarfish) {\n // Runs in the Garfish environment and is rendered by the provider\n if (renderByProvider) {\n return true;\n } else {\n // Runs in the Garfish environment and is not rendered by the provider\n return false;\n }\n } else {\n // Running in a non-Garfish environment\n return true;\n }\n}\n\nfunction generateRouterPlugin (basename,routerConfig) {\n if (basename) {\n routerConfig.basename = basename;\n if (routerConfig.supportHtml5History !== false) {\n if (!routerConfig.historyOptions) {\n routerConfig.historyOptions = {\n basename: basename\n };\n } else {\n routerConfig.historyOptions.basename = basename;\n }\n }\n }\n return router(routerConfig);\n}\n\nfunction generateAppWrapperAndRootDom ({ App, props: garfishProps, dom }) {\n let AppWrapper = App;\n if (garfishProps) {\n AppWrapper = function (props) {\n return React.createElement(App, { ...garfishProps, ...props });\n };\n AppWrapper = hoistNonReactStatics(AppWrapper, App);\n }\n const mountNode = dom ? (dom.querySelector('#' + MOUNT_ID) || dom) : document.getElementById(MOUNT_ID);\n return { AppWrapper, mountNode }\n}\n";
|
|
3
3
|
};
|
|
4
4
|
var makeRenderFunction = function(code) {
|
|
5
5
|
var inGarfishToRender = "\n const { basename, props, dom, appName } = typeof arguments[0] === 'object' && arguments[0] || {};\n if (!canContinueRender({ dom, appName })) return null;\n let { AppWrapper, mountNode } = generateAppWrapperAndRootDom({App, props, dom});\n ";
|
|
6
|
-
return inGarfishToRender + code.replace("router(", "generateRouterPlugin(basename,").replace("(App)", "(AppWrapper)").replace(/MOUNT_ID/g, "mountNode").replace("bootstrap(AppWrapper, mountNode, root", "bootstrap(AppWrapper, mountNode, root = IS_REACT18 ? ReactDOM.createRoot(mountNode) : null");
|
|
6
|
+
return inGarfishToRender + code.replace("router(", "generateRouterPlugin(basename,").replace("(App)", "(AppWrapper)").replace(/MOUNT_ID/g, "mountNode").replace("bootstrap(AppWrapper, mountNode, root", "bootstrap(AppWrapper, mountNode, root = IS_REACT18 ? ReactDOM.createRoot(mountNode) : null").replace("customBootstrap(AppWrapper)", "customBootstrap(AppWrapper, mountNode)");
|
|
7
7
|
};
|
|
8
8
|
function getRuntimeConfig(config) {
|
|
9
9
|
var ref;
|
|
@@ -461,7 +461,7 @@ var plugin_default = function(config) {
|
|
|
461
461
|
logger("GarfishProvider state", this.state);
|
|
462
462
|
return /* @__PURE__ */ jsx(GarfishProvider, {
|
|
463
463
|
value: this.state,
|
|
464
|
-
children: /* @__PURE__ */ jsx(App, _objectSpread({}, this.props
|
|
464
|
+
children: /* @__PURE__ */ jsx(App, _objectSpread({}, this.props))
|
|
465
465
|
});
|
|
466
466
|
}
|
|
467
467
|
}
|