@module-federation/bridge-react 0.0.0-next-20240726075341 → 0.0.0-next-20240726084328
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 +2 -2
- package/dist/index.cjs.js +111 -74
- package/dist/index.d.ts +15 -7
- package/dist/index.es.js +113 -76
- package/dist/router-v5.cjs.js +80 -0
- package/dist/router-v5.d.ts +8 -0
- package/dist/router-v5.es.js +63 -0
- package/dist/router-v6.cjs.js +87 -0
- package/dist/router-v6.d.ts +11 -0
- package/dist/router-v6.es.js +64 -0
- package/package.json +12 -2
- package/src/create.tsx +19 -24
- package/src/provider.tsx +37 -23
- package/src/remote/index.tsx +78 -55
- package/src/router-v5.tsx +78 -0
- package/src/router-v6.tsx +76 -0
- package/src/router.tsx +2 -0
- package/vite.config.ts +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# @module-federation/bridge-react
|
|
2
2
|
|
|
3
|
-
## 0.0.0-next-
|
|
3
|
+
## 0.0.0-next-20240726084328
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
- @module-federation/bridge-shared@0.0.0-next-
|
|
7
|
+
- @module-federation/bridge-shared@0.0.0-next-20240726084328
|
|
8
8
|
|
|
9
9
|
## 0.3.1
|
|
10
10
|
|
package/dist/index.cjs.js
CHANGED
|
@@ -117,55 +117,70 @@ function hasArrayChanged() {
|
|
|
117
117
|
let b = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
|
|
118
118
|
return a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]));
|
|
119
119
|
}
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
);
|
|
146
|
-
providerReturn.render(renderProps);
|
|
147
|
-
});
|
|
148
|
-
return () => {
|
|
149
|
-
clearTimeout(renderTimeout);
|
|
150
|
-
setTimeout(() => {
|
|
151
|
-
var _a, _b;
|
|
152
|
-
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
|
|
153
|
-
context.LoggerInstance.log(
|
|
154
|
-
`createRemoteComponent LazyComponent destroy >>>`,
|
|
155
|
-
{ name, basename, dom: renderDom.current }
|
|
156
|
-
);
|
|
157
|
-
(_b = providerInfoRef.current) == null ? void 0 : _b.destroy({
|
|
158
|
-
dom: renderDom.current
|
|
159
|
-
});
|
|
120
|
+
const RemoteAppWrapper = React.forwardRef(function(props, ref) {
|
|
121
|
+
const RemoteApp2 = () => {
|
|
122
|
+
const {
|
|
123
|
+
name,
|
|
124
|
+
memoryRoute,
|
|
125
|
+
basename,
|
|
126
|
+
providerInfo,
|
|
127
|
+
dom,
|
|
128
|
+
className,
|
|
129
|
+
style,
|
|
130
|
+
...resProps
|
|
131
|
+
} = props;
|
|
132
|
+
const rootRef = ref && "current" in ref ? ref : React.useRef(null);
|
|
133
|
+
const renderDom = React.useRef(null);
|
|
134
|
+
const providerInfoRef = React.useRef(null);
|
|
135
|
+
React.useEffect(() => {
|
|
136
|
+
const renderTimeout = setTimeout(() => {
|
|
137
|
+
const providerReturn = providerInfo();
|
|
138
|
+
providerInfoRef.current = providerReturn;
|
|
139
|
+
let domElement = null;
|
|
140
|
+
if (dom) {
|
|
141
|
+
domElement = document.getElementById(dom.replace("#", ""));
|
|
142
|
+
rootRef.current = domElement;
|
|
143
|
+
} else {
|
|
144
|
+
domElement = rootRef.current;
|
|
160
145
|
}
|
|
146
|
+
const renderProps = {
|
|
147
|
+
name,
|
|
148
|
+
// dom: rootRef.current,
|
|
149
|
+
dom: domElement,
|
|
150
|
+
basename,
|
|
151
|
+
memoryRoute,
|
|
152
|
+
...resProps
|
|
153
|
+
};
|
|
154
|
+
renderDom.current = rootRef.current;
|
|
155
|
+
context.LoggerInstance.log(
|
|
156
|
+
`createRemoteComponent LazyComponent render >>>`,
|
|
157
|
+
renderProps
|
|
158
|
+
);
|
|
159
|
+
providerReturn.render(renderProps);
|
|
161
160
|
});
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
161
|
+
return () => {
|
|
162
|
+
clearTimeout(renderTimeout);
|
|
163
|
+
setTimeout(() => {
|
|
164
|
+
var _a, _b;
|
|
165
|
+
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
|
|
166
|
+
context.LoggerInstance.log(
|
|
167
|
+
`createRemoteComponent LazyComponent destroy >>>`,
|
|
168
|
+
{ name, basename, dom: renderDom.current }
|
|
169
|
+
);
|
|
170
|
+
(_b = providerInfoRef.current) == null ? void 0 : _b.destroy({
|
|
171
|
+
dom: renderDom.current
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
}, []);
|
|
177
|
+
return dom ? null : /* @__PURE__ */ React.createElement("div", { className: props == null ? void 0 : props.className, style: props == null ? void 0 : props.style, ref: rootRef });
|
|
178
|
+
};
|
|
179
|
+
RemoteApp2["__APP_VERSION__"] = "0.3.1";
|
|
180
|
+
return /* @__PURE__ */ React.createElement(RemoteApp2, null);
|
|
181
|
+
});
|
|
167
182
|
function withRouterData(WrappedComponent) {
|
|
168
|
-
|
|
183
|
+
const Component = React.forwardRef(function(props, ref) {
|
|
169
184
|
var _a;
|
|
170
185
|
let enableDispathPopstate = false;
|
|
171
186
|
let routerContextVal;
|
|
@@ -223,10 +238,13 @@ function withRouterData(WrappedComponent) {
|
|
|
223
238
|
setPathname(location.pathname);
|
|
224
239
|
}, [location]);
|
|
225
240
|
}
|
|
226
|
-
return /* @__PURE__ */ React.createElement(WrappedComponent, { ...props, basename });
|
|
227
|
-
};
|
|
241
|
+
return /* @__PURE__ */ React.createElement(WrappedComponent, { ...props, basename, ref });
|
|
242
|
+
});
|
|
243
|
+
return React.forwardRef(function(props, ref) {
|
|
244
|
+
return /* @__PURE__ */ React.createElement(Component, { ...props, ref });
|
|
245
|
+
});
|
|
228
246
|
}
|
|
229
|
-
const RemoteApp
|
|
247
|
+
const RemoteApp = withRouterData(RemoteAppWrapper);
|
|
230
248
|
function createLazyRemoteComponent(info) {
|
|
231
249
|
const exportName = (info == null ? void 0 : info.export) || "default";
|
|
232
250
|
return React.lazy(async () => {
|
|
@@ -243,13 +261,14 @@ function createLazyRemoteComponent(info) {
|
|
|
243
261
|
);
|
|
244
262
|
const exportFn = m2[exportName];
|
|
245
263
|
if (exportName in m2 && typeof exportFn === "function") {
|
|
246
|
-
const RemoteAppComponent = React.forwardRef((props,
|
|
264
|
+
const RemoteAppComponent = React.forwardRef((props, ref) => {
|
|
247
265
|
return /* @__PURE__ */ React.createElement(
|
|
248
|
-
RemoteApp
|
|
266
|
+
RemoteApp,
|
|
249
267
|
{
|
|
250
268
|
name: moduleName,
|
|
251
269
|
providerInfo: exportFn,
|
|
252
270
|
exportName: info.export || "default",
|
|
271
|
+
ref,
|
|
253
272
|
...props
|
|
254
273
|
}
|
|
255
274
|
);
|
|
@@ -274,10 +293,10 @@ function createLazyRemoteComponent(info) {
|
|
|
274
293
|
});
|
|
275
294
|
}
|
|
276
295
|
function createRemoteComponent(info) {
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
return /* @__PURE__ */ React.createElement(ErrorBoundary, { FallbackComponent: info.fallback }, /* @__PURE__ */ React.createElement(React.Suspense, { fallback: info.loading }, /* @__PURE__ */ React.createElement(LazyComponent, { ...props })));
|
|
280
|
-
};
|
|
296
|
+
return React.forwardRef(function(props, ref) {
|
|
297
|
+
const LazyComponent = createLazyRemoteComponent(info);
|
|
298
|
+
return /* @__PURE__ */ React.createElement(ErrorBoundary, { FallbackComponent: info.fallback }, /* @__PURE__ */ React.createElement(React.Suspense, { fallback: info.loading }, /* @__PURE__ */ React.createElement(LazyComponent, { ...props, dom: info == null ? void 0 : info.dom, ref })));
|
|
299
|
+
});
|
|
281
300
|
}
|
|
282
301
|
var client = {};
|
|
283
302
|
var m = ReactDOM;
|
|
@@ -307,32 +326,50 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
307
326
|
return () => {
|
|
308
327
|
const rootMap = /* @__PURE__ */ new Map();
|
|
309
328
|
const RawComponent = (info) => {
|
|
310
|
-
const { appInfo, propsInfo } = info;
|
|
329
|
+
const { appInfo, propsInfo, ...restProps } = info;
|
|
311
330
|
const { name, memoryRoute, basename = "/" } = appInfo;
|
|
312
|
-
return /* @__PURE__ */ React__namespace.createElement(context.RouterContext.Provider, { value: { name, basename, memoryRoute } }, /* @__PURE__ */ React__namespace.createElement(bridgeInfo.rootComponent, { ...propsInfo, basename }));
|
|
331
|
+
return /* @__PURE__ */ React__namespace.createElement(context.RouterContext.Provider, { value: { name, basename, memoryRoute } }, /* @__PURE__ */ React__namespace.createElement(bridgeInfo.rootComponent, { ...propsInfo, basename, ...restProps }));
|
|
313
332
|
};
|
|
314
333
|
return {
|
|
315
|
-
render(info) {
|
|
334
|
+
async render(info) {
|
|
316
335
|
context.LoggerInstance.log(`createBridgeComponent render Info`, info);
|
|
317
336
|
const { name, basename, memoryRoute, ...propsInfo } = info;
|
|
318
337
|
if (context.atLeastReact18(React__namespace)) {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
338
|
+
if (bridgeInfo == null ? void 0 : bridgeInfo.render) {
|
|
339
|
+
Promise.resolve(bridgeInfo == null ? void 0 : bridgeInfo.render(
|
|
340
|
+
/* @__PURE__ */ React__namespace.createElement(
|
|
341
|
+
RawComponent,
|
|
342
|
+
{
|
|
343
|
+
propsInfo,
|
|
344
|
+
appInfo: {
|
|
345
|
+
name,
|
|
346
|
+
basename,
|
|
347
|
+
memoryRoute
|
|
348
|
+
}
|
|
330
349
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
350
|
+
),
|
|
351
|
+
info.dom
|
|
352
|
+
)).then((root) => rootMap.set(info.dom, root));
|
|
353
|
+
} else {
|
|
354
|
+
const root = client.createRoot(info.dom);
|
|
355
|
+
root.render(
|
|
356
|
+
/* @__PURE__ */ React__namespace.createElement(
|
|
357
|
+
RawComponent,
|
|
358
|
+
{
|
|
359
|
+
propsInfo,
|
|
360
|
+
appInfo: {
|
|
361
|
+
name,
|
|
362
|
+
basename,
|
|
363
|
+
memoryRoute
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
)
|
|
367
|
+
);
|
|
368
|
+
rootMap.set(info.dom, root);
|
|
369
|
+
}
|
|
334
370
|
} else {
|
|
335
|
-
ReactDOM.render
|
|
371
|
+
const renderFunc = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render;
|
|
372
|
+
renderFunc(
|
|
336
373
|
/* @__PURE__ */ React__namespace.createElement(
|
|
337
374
|
RawComponent,
|
|
338
375
|
{
|
|
@@ -348,7 +385,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
348
385
|
);
|
|
349
386
|
}
|
|
350
387
|
},
|
|
351
|
-
destroy(info) {
|
|
388
|
+
async destroy(info) {
|
|
352
389
|
context.LoggerInstance.log(`createBridgeComponent destroy Info`, {
|
|
353
390
|
dom: info.dom
|
|
354
391
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { ComponentType } from 'react';
|
|
2
2
|
import { default as default_2 } from 'react';
|
|
3
|
+
import { default as default_3 } from 'react-dom/client';
|
|
3
4
|
import { ErrorInfo } from 'react';
|
|
5
|
+
import { ForwardRefExoticComponent } from 'react';
|
|
4
6
|
import { PropsWithChildren } from 'react';
|
|
7
|
+
import { PropsWithoutRef } from 'react';
|
|
5
8
|
import * as React_2 from 'react';
|
|
9
|
+
import { RefAttributes } from 'react';
|
|
6
10
|
|
|
7
11
|
export declare function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>): () => {
|
|
8
|
-
render(info: RenderFnParams & any): void
|
|
12
|
+
render(info: RenderFnParams & any): Promise<void>;
|
|
9
13
|
destroy(info: {
|
|
10
14
|
dom: HTMLElement;
|
|
11
|
-
}): void
|
|
15
|
+
}): Promise<void>;
|
|
12
16
|
rawComponent: React_2.ComponentType<T>;
|
|
13
17
|
__BRIDGE_FN__: (_args: T) => void;
|
|
14
18
|
};
|
|
@@ -18,10 +22,8 @@ export declare function createRemoteComponent<T, E extends keyof T>(info: {
|
|
|
18
22
|
loading: default_2.ReactNode;
|
|
19
23
|
fallback: ErrorBoundaryPropsWithComponent['FallbackComponent'];
|
|
20
24
|
export?: E;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
memoryRoute?: ProviderParams['memoryRoute'];
|
|
24
|
-
} & ("__BRIDGE_FN__" extends keyof (T[E] extends (...args: any) => any ? ReturnType<T[E]> : never) ? (T[E] extends (...args: any) => any ? ReturnType<T[E]> : never)["__BRIDGE_FN__"] extends (...args: any) => any ? Parameters<(T[E] extends (...args: any) => any ? ReturnType<T[E]> : never)["__BRIDGE_FN__"]>[0] : {} : {})) => default_2.JSX.Element;
|
|
25
|
+
dom?: string;
|
|
26
|
+
}): ForwardRefExoticComponent<PropsWithoutRef<ProviderParams> & RefAttributes<HTMLElement | HTMLDivElement>>;
|
|
25
27
|
|
|
26
28
|
declare type ErrorBoundaryPropsWithComponent = ErrorBoundarySharedProps & {
|
|
27
29
|
fallback?: never;
|
|
@@ -49,18 +51,24 @@ declare type FallbackProps = {
|
|
|
49
51
|
|
|
50
52
|
declare type ProviderFnParams<T> = {
|
|
51
53
|
rootComponent: React_2.ComponentType<T>;
|
|
54
|
+
render?: (App: React_2.ReactElement, id?: HTMLElement | string) => RootType | Promise<RootType>;
|
|
52
55
|
};
|
|
53
56
|
|
|
54
|
-
export declare interface ProviderParams {
|
|
57
|
+
export declare interface ProviderParams extends default_2.HTMLAttributes<HTMLDivElement> {
|
|
55
58
|
name?: string;
|
|
56
59
|
basename?: string;
|
|
57
60
|
memoryRoute?: {
|
|
58
61
|
entryPath: string;
|
|
59
62
|
};
|
|
63
|
+
props?: {
|
|
64
|
+
[key: string]: any;
|
|
65
|
+
};
|
|
60
66
|
}
|
|
61
67
|
|
|
62
68
|
export declare interface RenderFnParams extends ProviderParams {
|
|
63
69
|
dom: HTMLElement;
|
|
64
70
|
}
|
|
65
71
|
|
|
72
|
+
declare type RootType = HTMLElement | default_3.Root;
|
|
73
|
+
|
|
66
74
|
export { }
|
package/dist/index.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import React__default, { createContext, Component, createElement, isValidElement,
|
|
3
|
-
import {
|
|
2
|
+
import React__default, { createContext, Component, createElement, isValidElement, forwardRef, useRef, useEffect, useContext, useState } from "react";
|
|
3
|
+
import { L as LoggerInstance, p as pathJoin, f, a as atLeastReact18, R as RouterContext } from "./context-Bw2PEwa6.js";
|
|
4
4
|
import * as ReactRouterDOM from "react-router-dom";
|
|
5
5
|
import ReactDOM from "react-dom";
|
|
6
6
|
const ErrorBoundaryContext = createContext(null);
|
|
@@ -98,55 +98,70 @@ function hasArrayChanged() {
|
|
|
98
98
|
let b = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
|
|
99
99
|
return a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]));
|
|
100
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
|
-
providerReturn.render(renderProps);
|
|
128
|
-
});
|
|
129
|
-
return () => {
|
|
130
|
-
clearTimeout(renderTimeout);
|
|
131
|
-
setTimeout(() => {
|
|
132
|
-
var _a, _b;
|
|
133
|
-
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
|
|
134
|
-
LoggerInstance.log(
|
|
135
|
-
`createRemoteComponent LazyComponent destroy >>>`,
|
|
136
|
-
{ name, basename, dom: renderDom.current }
|
|
137
|
-
);
|
|
138
|
-
(_b = providerInfoRef.current) == null ? void 0 : _b.destroy({
|
|
139
|
-
dom: renderDom.current
|
|
140
|
-
});
|
|
101
|
+
const RemoteAppWrapper = forwardRef(function(props, ref) {
|
|
102
|
+
const RemoteApp2 = () => {
|
|
103
|
+
const {
|
|
104
|
+
name,
|
|
105
|
+
memoryRoute,
|
|
106
|
+
basename,
|
|
107
|
+
providerInfo,
|
|
108
|
+
dom,
|
|
109
|
+
className,
|
|
110
|
+
style,
|
|
111
|
+
...resProps
|
|
112
|
+
} = props;
|
|
113
|
+
const rootRef = ref && "current" in ref ? ref : useRef(null);
|
|
114
|
+
const renderDom = useRef(null);
|
|
115
|
+
const providerInfoRef = useRef(null);
|
|
116
|
+
useEffect(() => {
|
|
117
|
+
const renderTimeout = setTimeout(() => {
|
|
118
|
+
const providerReturn = providerInfo();
|
|
119
|
+
providerInfoRef.current = providerReturn;
|
|
120
|
+
let domElement = null;
|
|
121
|
+
if (dom) {
|
|
122
|
+
domElement = document.getElementById(dom.replace("#", ""));
|
|
123
|
+
rootRef.current = domElement;
|
|
124
|
+
} else {
|
|
125
|
+
domElement = rootRef.current;
|
|
141
126
|
}
|
|
127
|
+
const renderProps = {
|
|
128
|
+
name,
|
|
129
|
+
// dom: rootRef.current,
|
|
130
|
+
dom: domElement,
|
|
131
|
+
basename,
|
|
132
|
+
memoryRoute,
|
|
133
|
+
...resProps
|
|
134
|
+
};
|
|
135
|
+
renderDom.current = rootRef.current;
|
|
136
|
+
LoggerInstance.log(
|
|
137
|
+
`createRemoteComponent LazyComponent render >>>`,
|
|
138
|
+
renderProps
|
|
139
|
+
);
|
|
140
|
+
providerReturn.render(renderProps);
|
|
142
141
|
});
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
142
|
+
return () => {
|
|
143
|
+
clearTimeout(renderTimeout);
|
|
144
|
+
setTimeout(() => {
|
|
145
|
+
var _a, _b;
|
|
146
|
+
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
|
|
147
|
+
LoggerInstance.log(
|
|
148
|
+
`createRemoteComponent LazyComponent destroy >>>`,
|
|
149
|
+
{ name, basename, dom: renderDom.current }
|
|
150
|
+
);
|
|
151
|
+
(_b = providerInfoRef.current) == null ? void 0 : _b.destroy({
|
|
152
|
+
dom: renderDom.current
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
};
|
|
157
|
+
}, []);
|
|
158
|
+
return dom ? null : /* @__PURE__ */ React__default.createElement("div", { className: props == null ? void 0 : props.className, style: props == null ? void 0 : props.style, ref: rootRef });
|
|
159
|
+
};
|
|
160
|
+
RemoteApp2["__APP_VERSION__"] = "0.3.1";
|
|
161
|
+
return /* @__PURE__ */ React__default.createElement(RemoteApp2, null);
|
|
162
|
+
});
|
|
148
163
|
function withRouterData(WrappedComponent) {
|
|
149
|
-
|
|
164
|
+
const Component2 = forwardRef(function(props, ref) {
|
|
150
165
|
var _a;
|
|
151
166
|
let enableDispathPopstate = false;
|
|
152
167
|
let routerContextVal;
|
|
@@ -204,10 +219,13 @@ function withRouterData(WrappedComponent) {
|
|
|
204
219
|
setPathname(location.pathname);
|
|
205
220
|
}, [location]);
|
|
206
221
|
}
|
|
207
|
-
return /* @__PURE__ */ React__default.createElement(WrappedComponent, { ...props, basename });
|
|
208
|
-
};
|
|
222
|
+
return /* @__PURE__ */ React__default.createElement(WrappedComponent, { ...props, basename, ref });
|
|
223
|
+
});
|
|
224
|
+
return forwardRef(function(props, ref) {
|
|
225
|
+
return /* @__PURE__ */ React__default.createElement(Component2, { ...props, ref });
|
|
226
|
+
});
|
|
209
227
|
}
|
|
210
|
-
const RemoteApp
|
|
228
|
+
const RemoteApp = withRouterData(RemoteAppWrapper);
|
|
211
229
|
function createLazyRemoteComponent(info) {
|
|
212
230
|
const exportName = (info == null ? void 0 : info.export) || "default";
|
|
213
231
|
return React__default.lazy(async () => {
|
|
@@ -224,13 +242,14 @@ function createLazyRemoteComponent(info) {
|
|
|
224
242
|
);
|
|
225
243
|
const exportFn = m2[exportName];
|
|
226
244
|
if (exportName in m2 && typeof exportFn === "function") {
|
|
227
|
-
const RemoteAppComponent = forwardRef((props,
|
|
245
|
+
const RemoteAppComponent = forwardRef((props, ref) => {
|
|
228
246
|
return /* @__PURE__ */ React__default.createElement(
|
|
229
|
-
RemoteApp
|
|
247
|
+
RemoteApp,
|
|
230
248
|
{
|
|
231
249
|
name: moduleName,
|
|
232
250
|
providerInfo: exportFn,
|
|
233
251
|
exportName: info.export || "default",
|
|
252
|
+
ref,
|
|
234
253
|
...props
|
|
235
254
|
}
|
|
236
255
|
);
|
|
@@ -255,10 +274,10 @@ function createLazyRemoteComponent(info) {
|
|
|
255
274
|
});
|
|
256
275
|
}
|
|
257
276
|
function createRemoteComponent(info) {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
return /* @__PURE__ */ React__default.createElement(ErrorBoundary, { FallbackComponent: info.fallback }, /* @__PURE__ */ React__default.createElement(React__default.Suspense, { fallback: info.loading }, /* @__PURE__ */ React__default.createElement(LazyComponent, { ...props })));
|
|
261
|
-
};
|
|
277
|
+
return forwardRef(function(props, ref) {
|
|
278
|
+
const LazyComponent = createLazyRemoteComponent(info);
|
|
279
|
+
return /* @__PURE__ */ React__default.createElement(ErrorBoundary, { FallbackComponent: info.fallback }, /* @__PURE__ */ React__default.createElement(React__default.Suspense, { fallback: info.loading }, /* @__PURE__ */ React__default.createElement(LazyComponent, { ...props, dom: info == null ? void 0 : info.dom, ref })));
|
|
280
|
+
});
|
|
262
281
|
}
|
|
263
282
|
var client = {};
|
|
264
283
|
var m = ReactDOM;
|
|
@@ -288,32 +307,50 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
288
307
|
return () => {
|
|
289
308
|
const rootMap = /* @__PURE__ */ new Map();
|
|
290
309
|
const RawComponent = (info) => {
|
|
291
|
-
const { appInfo, propsInfo } = info;
|
|
310
|
+
const { appInfo, propsInfo, ...restProps } = info;
|
|
292
311
|
const { name, memoryRoute, basename = "/" } = appInfo;
|
|
293
|
-
return /* @__PURE__ */ React.createElement(RouterContext.Provider, { value: { name, basename, memoryRoute } }, /* @__PURE__ */ React.createElement(bridgeInfo.rootComponent, { ...propsInfo, basename }));
|
|
312
|
+
return /* @__PURE__ */ React.createElement(RouterContext.Provider, { value: { name, basename, memoryRoute } }, /* @__PURE__ */ React.createElement(bridgeInfo.rootComponent, { ...propsInfo, basename, ...restProps }));
|
|
294
313
|
};
|
|
295
314
|
return {
|
|
296
|
-
render(info) {
|
|
315
|
+
async render(info) {
|
|
297
316
|
LoggerInstance.log(`createBridgeComponent render Info`, info);
|
|
298
317
|
const { name, basename, memoryRoute, ...propsInfo } = info;
|
|
299
318
|
if (atLeastReact18(React)) {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
319
|
+
if (bridgeInfo == null ? void 0 : bridgeInfo.render) {
|
|
320
|
+
Promise.resolve(bridgeInfo == null ? void 0 : bridgeInfo.render(
|
|
321
|
+
/* @__PURE__ */ React.createElement(
|
|
322
|
+
RawComponent,
|
|
323
|
+
{
|
|
324
|
+
propsInfo,
|
|
325
|
+
appInfo: {
|
|
326
|
+
name,
|
|
327
|
+
basename,
|
|
328
|
+
memoryRoute
|
|
329
|
+
}
|
|
311
330
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
331
|
+
),
|
|
332
|
+
info.dom
|
|
333
|
+
)).then((root) => rootMap.set(info.dom, root));
|
|
334
|
+
} else {
|
|
335
|
+
const root = client.createRoot(info.dom);
|
|
336
|
+
root.render(
|
|
337
|
+
/* @__PURE__ */ React.createElement(
|
|
338
|
+
RawComponent,
|
|
339
|
+
{
|
|
340
|
+
propsInfo,
|
|
341
|
+
appInfo: {
|
|
342
|
+
name,
|
|
343
|
+
basename,
|
|
344
|
+
memoryRoute
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
)
|
|
348
|
+
);
|
|
349
|
+
rootMap.set(info.dom, root);
|
|
350
|
+
}
|
|
315
351
|
} else {
|
|
316
|
-
ReactDOM.render
|
|
352
|
+
const renderFunc = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render;
|
|
353
|
+
renderFunc(
|
|
317
354
|
/* @__PURE__ */ React.createElement(
|
|
318
355
|
RawComponent,
|
|
319
356
|
{
|
|
@@ -329,7 +366,7 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
329
366
|
);
|
|
330
367
|
}
|
|
331
368
|
},
|
|
332
|
-
destroy(info) {
|
|
369
|
+
async destroy(info) {
|
|
333
370
|
LoggerInstance.log(`createBridgeComponent destroy Info`, {
|
|
334
371
|
dom: info.dom
|
|
335
372
|
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const React = require("react");
|
|
4
|
+
const ReactRouterDom = require("react-router-dom/index.js");
|
|
5
|
+
const context = require("./context--mtFt3tp.cjs");
|
|
6
|
+
function _interopNamespaceDefault(e) {
|
|
7
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
8
|
+
if (e) {
|
|
9
|
+
for (const k in e) {
|
|
10
|
+
if (k !== "default") {
|
|
11
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: () => e[k]
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
n.default = e;
|
|
20
|
+
return Object.freeze(n);
|
|
21
|
+
}
|
|
22
|
+
const ReactRouterDom__namespace = /* @__PURE__ */ _interopNamespaceDefault(ReactRouterDom);
|
|
23
|
+
function WraperRouter(props) {
|
|
24
|
+
const { basename, ...propsRes } = props;
|
|
25
|
+
const routerContextProps = React.useContext(context.RouterContext) || {};
|
|
26
|
+
context.LoggerInstance.log(`WraperRouter info >>>`, {
|
|
27
|
+
...routerContextProps,
|
|
28
|
+
routerContextProps,
|
|
29
|
+
WraperRouterProps: props
|
|
30
|
+
});
|
|
31
|
+
if (!routerContextProps)
|
|
32
|
+
return /* @__PURE__ */ React.createElement(ReactRouterDom__namespace.BrowserRouter, { ...props });
|
|
33
|
+
if (routerContextProps == null ? void 0 : routerContextProps.memoryRoute) {
|
|
34
|
+
return /* @__PURE__ */ React.createElement(
|
|
35
|
+
ReactRouterDom__namespace.MemoryRouter,
|
|
36
|
+
{
|
|
37
|
+
...props,
|
|
38
|
+
initialEntries: [routerContextProps == null ? void 0 : routerContextProps.memoryRoute.entryPath]
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
return /* @__PURE__ */ React.createElement(
|
|
43
|
+
ReactRouterDom__namespace.BrowserRouter,
|
|
44
|
+
{
|
|
45
|
+
...propsRes,
|
|
46
|
+
basename: (routerContextProps == null ? void 0 : routerContextProps.basename) || basename
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
function WraperRouterProvider(props) {
|
|
51
|
+
const { router, ...propsRes } = props;
|
|
52
|
+
const routerContextProps = React.useContext(context.RouterContext) || {};
|
|
53
|
+
const routers = router.routes;
|
|
54
|
+
context.LoggerInstance.log(`WraperRouterProvider info >>>`, {
|
|
55
|
+
...routerContextProps,
|
|
56
|
+
routerContextProps,
|
|
57
|
+
WraperRouterProviderProps: props,
|
|
58
|
+
router
|
|
59
|
+
});
|
|
60
|
+
const RouterProvider = ReactRouterDom__namespace["RouterProvider"];
|
|
61
|
+
const createMemoryRouter = ReactRouterDom__namespace["createMemoryRouter"];
|
|
62
|
+
const createBrowserRouter = ReactRouterDom__namespace["createBrowserRouter"];
|
|
63
|
+
if (!routerContextProps)
|
|
64
|
+
return /* @__PURE__ */ React.createElement(RouterProvider, { ...props });
|
|
65
|
+
if (routerContextProps.memoryRoute) {
|
|
66
|
+
const MemeoryRouterInstance = createMemoryRouter(routers, {
|
|
67
|
+
initialEntries: [routerContextProps == null ? void 0 : routerContextProps.memoryRoute.entryPath]
|
|
68
|
+
});
|
|
69
|
+
return /* @__PURE__ */ React.createElement(RouterProvider, { router: MemeoryRouterInstance });
|
|
70
|
+
} else {
|
|
71
|
+
const BrowserRouterInstance = createBrowserRouter(routers, {
|
|
72
|
+
basename: routerContextProps.basename,
|
|
73
|
+
future: router.future,
|
|
74
|
+
window: router.window
|
|
75
|
+
});
|
|
76
|
+
return /* @__PURE__ */ React.createElement(RouterProvider, { ...propsRes, router: BrowserRouterInstance });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.BrowserRouter = WraperRouter;
|
|
80
|
+
exports.RouterProvider = WraperRouterProvider;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { default as default_2 } from 'react';
|
|
2
|
+
import * as ReactRouterDom from 'react-router-dom/index.js';
|
|
3
|
+
|
|
4
|
+
export declare function BrowserRouter(props: Parameters<typeof ReactRouterDom.BrowserRouter>[0] | Parameters<typeof ReactRouterDom.MemoryRouter>[0]): default_2.JSX.Element;
|
|
5
|
+
|
|
6
|
+
export declare function RouterProvider(props: Parameters<typeof ReactRouterDom.RouterProvider>[0]): default_2.JSX.Element;
|
|
7
|
+
|
|
8
|
+
export { }
|