@module-federation/bridge-react 0.0.0-docs-remove-invalid-lark-link-20251205062649
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 +728 -0
- package/LICENSE +21 -0
- package/README.md +131 -0
- package/__tests__/bridge.spec.tsx +160 -0
- package/__tests__/createLazyComponent.spec.tsx +209 -0
- package/__tests__/prefetch.spec.ts +156 -0
- package/__tests__/router.spec.tsx +82 -0
- package/__tests__/setupTests.ts +8 -0
- package/__tests__/util.ts +36 -0
- package/dist/base.cjs.js +29 -0
- package/dist/base.d.ts +311 -0
- package/dist/base.es.js +30 -0
- package/dist/bridge-base-CPSTBjEp.mjs +211 -0
- package/dist/bridge-base-RStDxH71.js +226 -0
- package/dist/createHelpers-B_L612IN.js +190 -0
- package/dist/createHelpers-Ui5pt7je.mjs +191 -0
- package/dist/data-fetch-server-middleware.cjs.js +163 -0
- package/dist/data-fetch-server-middleware.d.ts +15 -0
- package/dist/data-fetch-server-middleware.es.js +164 -0
- package/dist/data-fetch-utils.cjs.js +24 -0
- package/dist/data-fetch-utils.d.ts +81 -0
- package/dist/data-fetch-utils.es.js +26 -0
- package/dist/index-DRSBaSu3.js +45 -0
- package/dist/index-DyQNwY2M.mjs +46 -0
- package/dist/index.cjs.js +125 -0
- package/dist/index.d.ts +299 -0
- package/dist/index.es.js +109 -0
- package/dist/index.esm-BWaKho-8.js +491 -0
- package/dist/index.esm-CPwSeCvw.mjs +492 -0
- package/dist/lazy-load-component-plugin-CSRkMmKF.js +521 -0
- package/dist/lazy-load-component-plugin-DXqhuywC.mjs +522 -0
- package/dist/lazy-load-component-plugin.cjs.js +6 -0
- package/dist/lazy-load-component-plugin.d.ts +16 -0
- package/dist/lazy-load-component-plugin.es.js +6 -0
- package/dist/lazy-utils.cjs.js +24 -0
- package/dist/lazy-utils.d.ts +149 -0
- package/dist/lazy-utils.es.js +24 -0
- package/dist/plugin.cjs.js +14 -0
- package/dist/plugin.d.ts +22 -0
- package/dist/plugin.es.js +14 -0
- package/dist/prefetch-A3QkU5oZ.js +1272 -0
- package/dist/prefetch-zMJL79zx.mjs +1273 -0
- package/dist/router-v5.cjs.js +55 -0
- package/dist/router-v5.d.ts +18 -0
- package/dist/router-v5.es.js +32 -0
- package/dist/router-v6.cjs.js +84 -0
- package/dist/router-v6.d.ts +20 -0
- package/dist/router-v6.es.js +61 -0
- package/dist/router-v7.cjs.js +83 -0
- package/dist/router-v7.d.ts +20 -0
- package/dist/router-v7.es.js +61 -0
- package/dist/router.cjs.js +82 -0
- package/dist/router.d.ts +20 -0
- package/dist/router.es.js +60 -0
- package/dist/utils-dUgb9Jkm.mjs +2016 -0
- package/dist/utils-tM9yE73c.js +2015 -0
- package/dist/v18.cjs.js +15 -0
- package/dist/v18.d.ts +114 -0
- package/dist/v18.es.js +15 -0
- package/dist/v19.cjs.js +15 -0
- package/dist/v19.d.ts +115 -0
- package/dist/v19.es.js +15 -0
- package/jest.config.ts +21 -0
- package/package.json +173 -0
- package/project.json +23 -0
- package/src/base.ts +50 -0
- package/src/index.ts +50 -0
- package/src/lazy/AwaitDataFetch.tsx +215 -0
- package/src/lazy/constant.ts +30 -0
- package/src/lazy/createLazyComponent.tsx +411 -0
- package/src/lazy/data-fetch/cache.ts +291 -0
- package/src/lazy/data-fetch/call-data-fetch.ts +13 -0
- package/src/lazy/data-fetch/data-fetch-server-middleware.ts +196 -0
- package/src/lazy/data-fetch/index.ts +16 -0
- package/src/lazy/data-fetch/inject-data-fetch.ts +109 -0
- package/src/lazy/data-fetch/prefetch.ts +112 -0
- package/src/lazy/data-fetch/runtime-plugin.ts +115 -0
- package/src/lazy/index.ts +35 -0
- package/src/lazy/logger.ts +6 -0
- package/src/lazy/types.ts +75 -0
- package/src/lazy/utils.ts +372 -0
- package/src/lazy/wrapNoSSR.tsx +10 -0
- package/src/modern-app-env.d.ts +2 -0
- package/src/plugins/lazy-load-component-plugin.spec.ts +21 -0
- package/src/plugins/lazy-load-component-plugin.ts +57 -0
- package/src/provider/context.tsx +4 -0
- package/src/provider/plugin.ts +22 -0
- package/src/provider/versions/bridge-base.tsx +150 -0
- package/src/provider/versions/legacy.ts +87 -0
- package/src/provider/versions/v18.ts +47 -0
- package/src/provider/versions/v19.ts +48 -0
- package/src/remote/RemoteAppWrapper.tsx +108 -0
- package/src/remote/base-component/component.tsx +2 -0
- package/src/remote/base-component/create.tsx +23 -0
- package/src/remote/base-component/index.tsx +10 -0
- package/src/remote/createHelpers.tsx +130 -0
- package/src/remote/router-component/component.tsx +104 -0
- package/src/remote/router-component/create.tsx +23 -0
- package/src/remote/router-component/index.tsx +10 -0
- package/src/router/default.tsx +73 -0
- package/src/router/v5.tsx +43 -0
- package/src/router/v6.tsx +74 -0
- package/src/router/v7.tsx +75 -0
- package/src/types.ts +147 -0
- package/src/utils/index.ts +44 -0
- package/src/v18.ts +9 -0
- package/src/v19.ts +9 -0
- package/tsconfig.json +42 -0
- package/tsconfig.node.json +11 -0
- package/tsconfig.spec.json +26 -0
- package/vite.config.ts +112 -0
- package/vitest.config.ts +27 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const React = require("react");
|
|
3
|
+
const index_esm = require("./index.esm-BWaKho-8.js");
|
|
4
|
+
const RouterContext = React.createContext(null);
|
|
5
|
+
const LoggerInstance = index_esm.createLogger(
|
|
6
|
+
"[ Module Federation Bridge React ]"
|
|
7
|
+
);
|
|
8
|
+
function pathJoin(...args) {
|
|
9
|
+
const res = args.reduce((res2, path) => {
|
|
10
|
+
let nPath = path;
|
|
11
|
+
if (!nPath || typeof nPath !== "string") {
|
|
12
|
+
return res2;
|
|
13
|
+
}
|
|
14
|
+
if (nPath[0] !== "/") {
|
|
15
|
+
nPath = `/${nPath}`;
|
|
16
|
+
}
|
|
17
|
+
const lastIndex = nPath.length - 1;
|
|
18
|
+
if (nPath[lastIndex] === "/") {
|
|
19
|
+
nPath = nPath.substring(0, lastIndex);
|
|
20
|
+
}
|
|
21
|
+
return res2 + nPath;
|
|
22
|
+
}, "");
|
|
23
|
+
return res || "/";
|
|
24
|
+
}
|
|
25
|
+
const getModuleName = (id) => {
|
|
26
|
+
if (!id) {
|
|
27
|
+
return id;
|
|
28
|
+
}
|
|
29
|
+
const idArray = id.split("/");
|
|
30
|
+
if (idArray.length < 2) {
|
|
31
|
+
return id;
|
|
32
|
+
}
|
|
33
|
+
return idArray[0] + "/" + idArray[1];
|
|
34
|
+
};
|
|
35
|
+
const getRootDomDefaultClassName = (moduleName) => {
|
|
36
|
+
if (!moduleName) {
|
|
37
|
+
return "";
|
|
38
|
+
}
|
|
39
|
+
const name = getModuleName(moduleName).replace(/\@/, "").replace(/\//, "-");
|
|
40
|
+
return `bridge-root-component-${name}`;
|
|
41
|
+
};
|
|
42
|
+
exports.LoggerInstance = LoggerInstance;
|
|
43
|
+
exports.RouterContext = RouterContext;
|
|
44
|
+
exports.getRootDomDefaultClassName = getRootDomDefaultClassName;
|
|
45
|
+
exports.pathJoin = pathJoin;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React__default from "react";
|
|
2
|
+
import { c as createLogger } from "./index.esm-CPwSeCvw.mjs";
|
|
3
|
+
const RouterContext = React__default.createContext(null);
|
|
4
|
+
const LoggerInstance = createLogger(
|
|
5
|
+
"[ Module Federation Bridge React ]"
|
|
6
|
+
);
|
|
7
|
+
function pathJoin(...args) {
|
|
8
|
+
const res = args.reduce((res2, path) => {
|
|
9
|
+
let nPath = path;
|
|
10
|
+
if (!nPath || typeof nPath !== "string") {
|
|
11
|
+
return res2;
|
|
12
|
+
}
|
|
13
|
+
if (nPath[0] !== "/") {
|
|
14
|
+
nPath = `/${nPath}`;
|
|
15
|
+
}
|
|
16
|
+
const lastIndex = nPath.length - 1;
|
|
17
|
+
if (nPath[lastIndex] === "/") {
|
|
18
|
+
nPath = nPath.substring(0, lastIndex);
|
|
19
|
+
}
|
|
20
|
+
return res2 + nPath;
|
|
21
|
+
}, "");
|
|
22
|
+
return res || "/";
|
|
23
|
+
}
|
|
24
|
+
const getModuleName = (id) => {
|
|
25
|
+
if (!id) {
|
|
26
|
+
return id;
|
|
27
|
+
}
|
|
28
|
+
const idArray = id.split("/");
|
|
29
|
+
if (idArray.length < 2) {
|
|
30
|
+
return id;
|
|
31
|
+
}
|
|
32
|
+
return idArray[0] + "/" + idArray[1];
|
|
33
|
+
};
|
|
34
|
+
const getRootDomDefaultClassName = (moduleName) => {
|
|
35
|
+
if (!moduleName) {
|
|
36
|
+
return "";
|
|
37
|
+
}
|
|
38
|
+
const name = getModuleName(moduleName).replace(/\@/, "").replace(/\//, "-");
|
|
39
|
+
return `bridge-root-component-${name}`;
|
|
40
|
+
};
|
|
41
|
+
export {
|
|
42
|
+
LoggerInstance as L,
|
|
43
|
+
RouterContext as R,
|
|
44
|
+
getRootDomDefaultClassName as g,
|
|
45
|
+
pathJoin as p
|
|
46
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const createHelpers = require("./createHelpers-B_L612IN.js");
|
|
4
|
+
const lazyLoadComponentPlugin = require("./lazy-load-component-plugin-CSRkMmKF.js");
|
|
5
|
+
const React = require("react");
|
|
6
|
+
const ReactRouterDOM = require("react-router-dom");
|
|
7
|
+
const index = require("./index-DRSBaSu3.js");
|
|
8
|
+
const lazyUtils = require("./utils-tM9yE73c.js");
|
|
9
|
+
const dataFetchUtils = require("./data-fetch-utils.cjs.js");
|
|
10
|
+
const prefetch = require("./prefetch-A3QkU5oZ.js");
|
|
11
|
+
function _interopNamespaceDefault(e2) {
|
|
12
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
13
|
+
if (e2) {
|
|
14
|
+
for (const k in e2) {
|
|
15
|
+
if (k !== "default") {
|
|
16
|
+
const d = Object.getOwnPropertyDescriptor(e2, k);
|
|
17
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: () => e2[k]
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
n.default = e2;
|
|
25
|
+
return Object.freeze(n);
|
|
26
|
+
}
|
|
27
|
+
const ReactRouterDOM__namespace = /* @__PURE__ */ _interopNamespaceDefault(ReactRouterDOM);
|
|
28
|
+
function e() {
|
|
29
|
+
const t = new PopStateEvent("popstate", { state: window.history.state });
|
|
30
|
+
window.dispatchEvent(t);
|
|
31
|
+
}
|
|
32
|
+
function withRouterData(WrappedComponent) {
|
|
33
|
+
const Component = React.forwardRef(function(props, ref) {
|
|
34
|
+
var _a;
|
|
35
|
+
if (props == null ? void 0 : props.basename) {
|
|
36
|
+
return /* @__PURE__ */ React.createElement(WrappedComponent, { ...props, basename: props.basename, ref });
|
|
37
|
+
}
|
|
38
|
+
let enableDispathPopstate = false;
|
|
39
|
+
let routerContextVal;
|
|
40
|
+
try {
|
|
41
|
+
ReactRouterDOM__namespace.useLocation();
|
|
42
|
+
enableDispathPopstate = true;
|
|
43
|
+
} catch {
|
|
44
|
+
enableDispathPopstate = false;
|
|
45
|
+
}
|
|
46
|
+
let basename = "/";
|
|
47
|
+
if (!props.basename && enableDispathPopstate) {
|
|
48
|
+
const ReactRouterDOMAny = ReactRouterDOM__namespace;
|
|
49
|
+
const useRouteMatch = ReactRouterDOMAny["useRouteMatch"];
|
|
50
|
+
const useHistory = ReactRouterDOMAny["useHistory"];
|
|
51
|
+
const useHref = ReactRouterDOMAny["useHref"];
|
|
52
|
+
const UNSAFE_RouteContext = ReactRouterDOMAny["UNSAFE_RouteContext"];
|
|
53
|
+
if (UNSAFE_RouteContext) {
|
|
54
|
+
if (useHref) {
|
|
55
|
+
basename = useHref == null ? void 0 : useHref("/");
|
|
56
|
+
}
|
|
57
|
+
routerContextVal = React.useContext(UNSAFE_RouteContext);
|
|
58
|
+
if (routerContextVal && routerContextVal.matches && routerContextVal.matches.length > 0) {
|
|
59
|
+
const matchIndex = routerContextVal.matches.length - 1;
|
|
60
|
+
const pathnameBase = routerContextVal.matches[matchIndex].pathnameBase;
|
|
61
|
+
basename = index.pathJoin(basename, pathnameBase || "/");
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
const match = useRouteMatch == null ? void 0 : useRouteMatch();
|
|
65
|
+
if (useHistory) {
|
|
66
|
+
const history = useHistory == null ? void 0 : useHistory();
|
|
67
|
+
basename = (_a = history == null ? void 0 : history.createHref) == null ? void 0 : _a.call(history, { pathname: "/" });
|
|
68
|
+
}
|
|
69
|
+
if (match) {
|
|
70
|
+
basename = index.pathJoin(basename, (match == null ? void 0 : match.path) || "/");
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
index.LoggerInstance.debug(`createRemoteAppComponent withRouterData >>>`, {
|
|
75
|
+
...props,
|
|
76
|
+
basename,
|
|
77
|
+
routerContextVal,
|
|
78
|
+
enableDispathPopstate
|
|
79
|
+
});
|
|
80
|
+
if (enableDispathPopstate) {
|
|
81
|
+
const location = ReactRouterDOM__namespace.useLocation();
|
|
82
|
+
const [pathname, setPathname] = React.useState(location.pathname);
|
|
83
|
+
React.useEffect(() => {
|
|
84
|
+
if (pathname !== "" && pathname !== location.pathname) {
|
|
85
|
+
index.LoggerInstance.debug(
|
|
86
|
+
`createRemoteAppComponent dispatchPopstateEnv >>>`,
|
|
87
|
+
{
|
|
88
|
+
name: props.name,
|
|
89
|
+
pathname: location.pathname
|
|
90
|
+
}
|
|
91
|
+
);
|
|
92
|
+
e();
|
|
93
|
+
}
|
|
94
|
+
setPathname(location.pathname);
|
|
95
|
+
}, [location]);
|
|
96
|
+
}
|
|
97
|
+
return /* @__PURE__ */ React.createElement(WrappedComponent, { ...props, basename, ref });
|
|
98
|
+
});
|
|
99
|
+
return React.forwardRef(function(props, ref) {
|
|
100
|
+
return /* @__PURE__ */ React.createElement(Component, { ...props, ref });
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
const RemoteApp = withRouterData(createHelpers.RemoteAppWrapper);
|
|
104
|
+
const createRemoteAppComponent = createHelpers.createRemoteAppComponentFactory(RemoteApp);
|
|
105
|
+
const createRemoteComponent = createHelpers.createDeprecatedRemoteComponentFactory(
|
|
106
|
+
createRemoteAppComponent
|
|
107
|
+
);
|
|
108
|
+
exports.createBridgeComponent = createHelpers.createBridgeComponent;
|
|
109
|
+
exports.autoFetchDataPlugin = lazyLoadComponentPlugin.autoFetchData;
|
|
110
|
+
exports.collectSSRAssets = lazyLoadComponentPlugin.collectSSRAssets;
|
|
111
|
+
exports.createLazyComponent = lazyLoadComponentPlugin.createLazyComponent;
|
|
112
|
+
exports.lazyLoadComponentPlugin = lazyLoadComponentPlugin.lazyLoadComponentPlugin;
|
|
113
|
+
exports.CacheSize = lazyUtils.CacheSize;
|
|
114
|
+
exports.CacheTime = lazyUtils.CacheTime;
|
|
115
|
+
exports.ERROR_TYPE = lazyUtils.ERROR_TYPE;
|
|
116
|
+
exports.cache = lazyUtils.cache;
|
|
117
|
+
exports.clearStore = lazyUtils.clearStore;
|
|
118
|
+
exports.configureCache = lazyUtils.configureCache;
|
|
119
|
+
exports.generateKey = lazyUtils.generateKey;
|
|
120
|
+
exports.revalidateTag = lazyUtils.revalidateTag;
|
|
121
|
+
exports.setSSREnv = lazyUtils.setSSREnv;
|
|
122
|
+
exports.callDataFetch = dataFetchUtils.callDataFetch;
|
|
123
|
+
exports.prefetch = prefetch.prefetch;
|
|
124
|
+
exports.createRemoteAppComponent = createRemoteAppComponent;
|
|
125
|
+
exports.createRemoteComponent = createRemoteComponent;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { default as default_2 } from 'react';
|
|
2
|
+
import { ForwardRefExoticComponent } from 'react';
|
|
3
|
+
import { getInstance } from '@module-federation/runtime';
|
|
4
|
+
import { ModuleFederationRuntimePlugin } from '@module-federation/runtime';
|
|
5
|
+
import * as React_2 from 'react';
|
|
6
|
+
import { ReactNode } from 'react';
|
|
7
|
+
import { RefAttributes } from 'react';
|
|
8
|
+
|
|
9
|
+
export declare const autoFetchDataPlugin: () => ModuleFederationRuntimePlugin;
|
|
10
|
+
|
|
11
|
+
export declare function cache<T>(fn: DataFetch<T>, options?: CacheOptions): DataFetch<T>;
|
|
12
|
+
|
|
13
|
+
declare interface CacheConfig {
|
|
14
|
+
maxSize?: number;
|
|
15
|
+
unstable_shouldDisable?: ({ request, }: {
|
|
16
|
+
request: Request;
|
|
17
|
+
}) => boolean | Promise<boolean>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
declare interface CacheOptions {
|
|
21
|
+
tag?: string | string[];
|
|
22
|
+
maxAge?: number;
|
|
23
|
+
revalidate?: number;
|
|
24
|
+
getKey?: <Args extends any[]>(...args: Args) => string;
|
|
25
|
+
onCache?: (info: CacheStatsInfo) => boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export declare const CacheSize: {
|
|
29
|
+
readonly KB: 1024;
|
|
30
|
+
readonly MB: number;
|
|
31
|
+
readonly GB: number;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export declare interface CacheStatsInfo {
|
|
35
|
+
status: CacheStatus;
|
|
36
|
+
key: string | symbol;
|
|
37
|
+
params: DataFetchParams;
|
|
38
|
+
result: any;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export declare type CacheStatus = 'hit' | 'stale' | 'miss';
|
|
42
|
+
|
|
43
|
+
export declare const CacheTime: {
|
|
44
|
+
readonly SECOND: 1000;
|
|
45
|
+
readonly MINUTE: number;
|
|
46
|
+
readonly HOUR: number;
|
|
47
|
+
readonly DAY: number;
|
|
48
|
+
readonly WEEK: number;
|
|
49
|
+
readonly MONTH: number;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export declare function callDataFetch(): Promise<void>;
|
|
53
|
+
|
|
54
|
+
export declare function clearStore(): void;
|
|
55
|
+
|
|
56
|
+
export declare function collectSSRAssets(options: CollectSSRAssetsOptions): default_2.ReactNode[];
|
|
57
|
+
|
|
58
|
+
export declare type CollectSSRAssetsOptions = {
|
|
59
|
+
id: string;
|
|
60
|
+
instance: ReturnType<typeof getInstance>;
|
|
61
|
+
injectScript?: boolean;
|
|
62
|
+
injectLink?: boolean;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export declare function configureCache(config: CacheConfig): void;
|
|
66
|
+
|
|
67
|
+
export declare function createBridgeComponent<T = any>(bridgeInfo: Omit<ProviderFnParams<T>, 'createRoot'>): () => {
|
|
68
|
+
render(info: RenderParams): Promise<void>;
|
|
69
|
+
destroy(info: DestroyParams): void;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export declare function createLazyComponent<T, E extends keyof T>(options: CreateLazyComponentOptions<T, E>): (props: T[E] extends (...args: any) => any ? Parameters<T[E]>[0] extends undefined ? ReactKey : Parameters<T[E]>[0] & ReactKey : ReactKey) => default_2.JSX.Element;
|
|
73
|
+
|
|
74
|
+
export declare type CreateLazyComponentOptions<T, E extends keyof T> = {
|
|
75
|
+
loader: () => Promise<T>;
|
|
76
|
+
instance: ReturnType<typeof getInstance>;
|
|
77
|
+
loading: default_2.ReactNode;
|
|
78
|
+
delayLoading?: number;
|
|
79
|
+
fallback: ReactNode | ((errorInfo: ErrorInfo) => ReactNode);
|
|
80
|
+
export?: E;
|
|
81
|
+
dataFetchParams?: DataFetchParams;
|
|
82
|
+
noSSR?: boolean;
|
|
83
|
+
injectScript?: boolean;
|
|
84
|
+
injectLink?: boolean;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export declare const createRemoteAppComponent: <T = Record<string, unknown>, E extends keyof T = keyof T>(info: LazyRemoteComponentInfo<T, E>) => ForwardRefExoticComponent<Omit<RemoteComponentProps<Record<string, unknown>>, "ref"> & RefAttributes<HTMLDivElement>>;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @deprecated createRemoteComponent is deprecated, please use createRemoteAppComponent instead!
|
|
91
|
+
*/
|
|
92
|
+
export declare const createRemoteComponent: <T = Record<string, unknown>, E extends keyof T = keyof T>(info: LazyRemoteComponentInfo<T, E>) => any;
|
|
93
|
+
|
|
94
|
+
export declare interface CreateRootOptions {
|
|
95
|
+
identifierPrefix?: string;
|
|
96
|
+
onRecoverableError?: (error: unknown, errorInfo: unknown) => void;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Options for creating a React root
|
|
101
|
+
*/
|
|
102
|
+
declare interface CreateRootOptions_2 {
|
|
103
|
+
identifierPrefix?: string;
|
|
104
|
+
onRecoverableError?: (error: unknown) => void;
|
|
105
|
+
transitionCallbacks?: unknown;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
declare type DataFetch<T> = (params: DataFetchParams) => Promise<T>;
|
|
109
|
+
|
|
110
|
+
export declare type DataFetchParams = {
|
|
111
|
+
isDowngrade: boolean;
|
|
112
|
+
_id?: string;
|
|
113
|
+
} & Record<string, unknown>;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Parameters for the destroy function
|
|
117
|
+
*/
|
|
118
|
+
export declare interface DestroyParams {
|
|
119
|
+
moduleName: string;
|
|
120
|
+
dom: HTMLElement;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export declare const ERROR_TYPE: {
|
|
124
|
+
DATA_FETCH: number;
|
|
125
|
+
LOAD_REMOTE: number;
|
|
126
|
+
UNKNOWN: number;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
declare type ErrorInfo = {
|
|
130
|
+
error: Error;
|
|
131
|
+
errorType: number;
|
|
132
|
+
dataFetchMapKey?: string;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export declare function generateKey(dataFetchOptions: DataFetchParams): string;
|
|
136
|
+
|
|
137
|
+
export declare function lazyLoadComponentPlugin(): ModuleFederationRuntimePlugin;
|
|
138
|
+
|
|
139
|
+
export declare type LazyRemoteComponentInfo<T, _E extends keyof T> = RemoteComponentParams<T>;
|
|
140
|
+
|
|
141
|
+
export declare type NoSSRRemoteInfo = {
|
|
142
|
+
name: string;
|
|
143
|
+
version: string;
|
|
144
|
+
ssrPublicPath: string;
|
|
145
|
+
ssrRemoteEntry: string;
|
|
146
|
+
globalName: string;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export declare function prefetch(options: PrefetchOptions): Promise<void>;
|
|
150
|
+
|
|
151
|
+
declare type PrefetchOptions = {
|
|
152
|
+
id: string;
|
|
153
|
+
instance: ReturnType<typeof getInstance>;
|
|
154
|
+
dataFetchParams?: DataFetchParams;
|
|
155
|
+
preloadComponentResource?: boolean;
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Parameters for the provider function
|
|
160
|
+
*/
|
|
161
|
+
export declare interface ProviderFnParams<T> {
|
|
162
|
+
rootComponent: React_2.ComponentType<T>;
|
|
163
|
+
render?: (App: React_2.ReactElement, id?: HTMLElement | string) => RootType | Promise<RootType>;
|
|
164
|
+
createRoot?: (container: Element | DocumentFragment, options?: CreateRootOptions_2) => Root_2;
|
|
165
|
+
/**
|
|
166
|
+
* Default options to pass to createRoot for React 18 and 19
|
|
167
|
+
* These options will be used when creating a root unless overridden by rootOptions in render params
|
|
168
|
+
* @example
|
|
169
|
+
* {
|
|
170
|
+
* identifierPrefix: 'app-',
|
|
171
|
+
* onRecoverableError: (err) => console.error(err)
|
|
172
|
+
* }
|
|
173
|
+
*/
|
|
174
|
+
defaultRootOptions?: CreateRootOptions_2;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Parameters for the provider function
|
|
179
|
+
*/
|
|
180
|
+
export declare interface ProviderParams {
|
|
181
|
+
moduleName?: string;
|
|
182
|
+
basename?: string;
|
|
183
|
+
memoryRoute?: {
|
|
184
|
+
entryPath: string;
|
|
185
|
+
initialState?: Record<string, unknown>;
|
|
186
|
+
};
|
|
187
|
+
style?: React_2.CSSProperties;
|
|
188
|
+
className?: string;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
declare type ReactKey = {
|
|
192
|
+
key?: default_2.Key | null;
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Parameters for the remote component loader
|
|
197
|
+
*/
|
|
198
|
+
export declare interface RemoteComponentParams<T = Record<string, unknown>, E extends keyof T = keyof T> {
|
|
199
|
+
loader: () => Promise<T>;
|
|
200
|
+
loading: React_2.ReactNode;
|
|
201
|
+
fallback: React_2.ComponentType<{
|
|
202
|
+
error: Error;
|
|
203
|
+
}>;
|
|
204
|
+
export?: E;
|
|
205
|
+
props?: T;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Parameters for the remote component
|
|
210
|
+
*/
|
|
211
|
+
export declare interface RemoteComponentProps<T = Record<string, unknown>> {
|
|
212
|
+
props?: T;
|
|
213
|
+
fallback?: React_2.ComponentType<{
|
|
214
|
+
error: Error;
|
|
215
|
+
}>;
|
|
216
|
+
loading?: React_2.ReactNode;
|
|
217
|
+
[key: string]: unknown;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Interface for a remote module provider
|
|
222
|
+
*/
|
|
223
|
+
export declare interface RemoteModule {
|
|
224
|
+
provider: () => {
|
|
225
|
+
render: (info: RenderFnParams) => void;
|
|
226
|
+
destroy: (info: {
|
|
227
|
+
dom: any;
|
|
228
|
+
}) => void;
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Parameters for the render function, extending ProviderParams
|
|
234
|
+
*/
|
|
235
|
+
export declare interface RenderFnParams extends ProviderParams {
|
|
236
|
+
dom: HTMLElement;
|
|
237
|
+
fallback?: React_2.ComponentType<{
|
|
238
|
+
error: Error;
|
|
239
|
+
}>;
|
|
240
|
+
[key: string]: unknown;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Parameters for the render function
|
|
245
|
+
*/
|
|
246
|
+
export declare interface RenderParams {
|
|
247
|
+
moduleName?: string;
|
|
248
|
+
basename?: string;
|
|
249
|
+
memoryRoute?: {
|
|
250
|
+
entryPath: string;
|
|
251
|
+
initialState?: Record<string, unknown>;
|
|
252
|
+
};
|
|
253
|
+
dom: HTMLElement;
|
|
254
|
+
/**
|
|
255
|
+
* Options to pass to createRoot for React 18 and 19
|
|
256
|
+
* @example
|
|
257
|
+
* {
|
|
258
|
+
* identifierPrefix: 'app-',
|
|
259
|
+
* onRecoverableError: (err) => console.error(err)
|
|
260
|
+
* }
|
|
261
|
+
*/
|
|
262
|
+
rootOptions?: CreateRootOptions_2;
|
|
263
|
+
[key: string]: unknown;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
export declare function revalidateTag(tag: string): void;
|
|
267
|
+
|
|
268
|
+
export declare interface Root {
|
|
269
|
+
render(children: React.ReactNode): void;
|
|
270
|
+
unmount(): void;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Interface for a React root object
|
|
275
|
+
*/
|
|
276
|
+
declare interface Root_2 {
|
|
277
|
+
render(children: React_2.ReactNode): void;
|
|
278
|
+
unmount(): void;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Type for a root element, which can be either an HTMLElement or a React root
|
|
283
|
+
*/
|
|
284
|
+
export declare type RootType = HTMLElement | Root_2;
|
|
285
|
+
|
|
286
|
+
export declare function setSSREnv({ fetchServerQuery, }: {
|
|
287
|
+
fetchServerQuery?: Record<string, unknown>;
|
|
288
|
+
}): void;
|
|
289
|
+
|
|
290
|
+
export { }
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
declare module '@module-federation/runtime-core' {
|
|
294
|
+
interface ModuleFederation {
|
|
295
|
+
createLazyComponent<T, E extends keyof T>(options: Omit<CreateLazyComponentOptions<T, E>, 'instance'>): ReturnType<typeof createLazyComponent<T, E>>;
|
|
296
|
+
prefetch(options: Omit<PrefetchOptions, 'instance'>): ReturnType<typeof prefetch>;
|
|
297
|
+
collectSSRAssets(options: Omit<Parameters<typeof collectSSRAssets>[0], 'instance'>): ReturnType<typeof collectSSRAssets>;
|
|
298
|
+
}
|
|
299
|
+
}
|
package/dist/index.es.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { R as RemoteAppWrapper, c as createDeprecatedRemoteComponentFactory, a as createRemoteAppComponentFactory } from "./createHelpers-Ui5pt7je.mjs";
|
|
2
|
+
import { b } from "./createHelpers-Ui5pt7je.mjs";
|
|
3
|
+
import { b as b2, a, c, l } from "./lazy-load-component-plugin-DXqhuywC.mjs";
|
|
4
|
+
import React__default, { forwardRef, useContext, useState, useEffect } from "react";
|
|
5
|
+
import * as ReactRouterDOM from "react-router-dom";
|
|
6
|
+
import { p as pathJoin, L as LoggerInstance } from "./index-DyQNwY2M.mjs";
|
|
7
|
+
import { C, a as a2, E, b as b3, d, c as c2, g, r, s } from "./utils-dUgb9Jkm.mjs";
|
|
8
|
+
import { callDataFetch } from "./data-fetch-utils.es.js";
|
|
9
|
+
import { p } from "./prefetch-zMJL79zx.mjs";
|
|
10
|
+
function e() {
|
|
11
|
+
const t = new PopStateEvent("popstate", { state: window.history.state });
|
|
12
|
+
window.dispatchEvent(t);
|
|
13
|
+
}
|
|
14
|
+
function withRouterData(WrappedComponent) {
|
|
15
|
+
const Component = forwardRef(function(props, ref) {
|
|
16
|
+
var _a;
|
|
17
|
+
if (props == null ? void 0 : props.basename) {
|
|
18
|
+
return /* @__PURE__ */ React__default.createElement(WrappedComponent, { ...props, basename: props.basename, ref });
|
|
19
|
+
}
|
|
20
|
+
let enableDispathPopstate = false;
|
|
21
|
+
let routerContextVal;
|
|
22
|
+
try {
|
|
23
|
+
ReactRouterDOM.useLocation();
|
|
24
|
+
enableDispathPopstate = true;
|
|
25
|
+
} catch {
|
|
26
|
+
enableDispathPopstate = false;
|
|
27
|
+
}
|
|
28
|
+
let basename = "/";
|
|
29
|
+
if (!props.basename && enableDispathPopstate) {
|
|
30
|
+
const ReactRouterDOMAny = ReactRouterDOM;
|
|
31
|
+
const useRouteMatch = ReactRouterDOMAny["useRouteMatch"];
|
|
32
|
+
const useHistory = ReactRouterDOMAny["useHistory"];
|
|
33
|
+
const useHref = ReactRouterDOMAny["useHref"];
|
|
34
|
+
const UNSAFE_RouteContext = ReactRouterDOMAny["UNSAFE_RouteContext"];
|
|
35
|
+
if (UNSAFE_RouteContext) {
|
|
36
|
+
if (useHref) {
|
|
37
|
+
basename = useHref == null ? void 0 : useHref("/");
|
|
38
|
+
}
|
|
39
|
+
routerContextVal = useContext(UNSAFE_RouteContext);
|
|
40
|
+
if (routerContextVal && routerContextVal.matches && routerContextVal.matches.length > 0) {
|
|
41
|
+
const matchIndex = routerContextVal.matches.length - 1;
|
|
42
|
+
const pathnameBase = routerContextVal.matches[matchIndex].pathnameBase;
|
|
43
|
+
basename = pathJoin(basename, pathnameBase || "/");
|
|
44
|
+
}
|
|
45
|
+
} else {
|
|
46
|
+
const match = useRouteMatch == null ? void 0 : useRouteMatch();
|
|
47
|
+
if (useHistory) {
|
|
48
|
+
const history = useHistory == null ? void 0 : useHistory();
|
|
49
|
+
basename = (_a = history == null ? void 0 : history.createHref) == null ? void 0 : _a.call(history, { pathname: "/" });
|
|
50
|
+
}
|
|
51
|
+
if (match) {
|
|
52
|
+
basename = pathJoin(basename, (match == null ? void 0 : match.path) || "/");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
LoggerInstance.debug(`createRemoteAppComponent withRouterData >>>`, {
|
|
57
|
+
...props,
|
|
58
|
+
basename,
|
|
59
|
+
routerContextVal,
|
|
60
|
+
enableDispathPopstate
|
|
61
|
+
});
|
|
62
|
+
if (enableDispathPopstate) {
|
|
63
|
+
const location = ReactRouterDOM.useLocation();
|
|
64
|
+
const [pathname, setPathname] = useState(location.pathname);
|
|
65
|
+
useEffect(() => {
|
|
66
|
+
if (pathname !== "" && pathname !== location.pathname) {
|
|
67
|
+
LoggerInstance.debug(
|
|
68
|
+
`createRemoteAppComponent dispatchPopstateEnv >>>`,
|
|
69
|
+
{
|
|
70
|
+
name: props.name,
|
|
71
|
+
pathname: location.pathname
|
|
72
|
+
}
|
|
73
|
+
);
|
|
74
|
+
e();
|
|
75
|
+
}
|
|
76
|
+
setPathname(location.pathname);
|
|
77
|
+
}, [location]);
|
|
78
|
+
}
|
|
79
|
+
return /* @__PURE__ */ React__default.createElement(WrappedComponent, { ...props, basename, ref });
|
|
80
|
+
});
|
|
81
|
+
return forwardRef(function(props, ref) {
|
|
82
|
+
return /* @__PURE__ */ React__default.createElement(Component, { ...props, ref });
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
const RemoteApp = withRouterData(RemoteAppWrapper);
|
|
86
|
+
const createRemoteAppComponent = createRemoteAppComponentFactory(RemoteApp);
|
|
87
|
+
const createRemoteComponent = createDeprecatedRemoteComponentFactory(
|
|
88
|
+
createRemoteAppComponent
|
|
89
|
+
);
|
|
90
|
+
export {
|
|
91
|
+
C as CacheSize,
|
|
92
|
+
a2 as CacheTime,
|
|
93
|
+
E as ERROR_TYPE,
|
|
94
|
+
b2 as autoFetchDataPlugin,
|
|
95
|
+
b3 as cache,
|
|
96
|
+
callDataFetch,
|
|
97
|
+
d as clearStore,
|
|
98
|
+
a as collectSSRAssets,
|
|
99
|
+
c2 as configureCache,
|
|
100
|
+
b as createBridgeComponent,
|
|
101
|
+
c as createLazyComponent,
|
|
102
|
+
createRemoteAppComponent,
|
|
103
|
+
createRemoteComponent,
|
|
104
|
+
g as generateKey,
|
|
105
|
+
l as lazyLoadComponentPlugin,
|
|
106
|
+
p as prefetch,
|
|
107
|
+
r as revalidateTag,
|
|
108
|
+
s as setSSREnv
|
|
109
|
+
};
|