@umijs/renderer-react 4.0.0-beta.9 → 4.0.0-canary-20240513.3
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/LICENSE +21 -0
- package/dist/appContext.d.ts +24 -6
- package/dist/appContext.js +92 -3
- package/dist/browser.d.ts +86 -9
- package/dist/browser.js +289 -23
- package/dist/dataFetcher.d.ts +5 -0
- package/dist/dataFetcher.js +21 -0
- package/dist/html.d.ts +3 -0
- package/dist/html.js +171 -0
- package/dist/index.d.ts +10 -2
- package/dist/index.js +9 -2
- package/dist/link.d.ts +5 -0
- package/dist/link.js +22 -0
- package/dist/routeContext.d.ts +7 -0
- package/dist/routeContext.js +5 -0
- package/dist/routes.d.ts +6 -18
- package/dist/routes.js +102 -27
- package/dist/server.d.ts +2 -0
- package/dist/server.js +67 -0
- package/dist/types.d.ts +73 -1
- package/dist/types.js +1 -1
- package/dist/useFetcher.d.ts +3 -0
- package/dist/useFetcher.js +12 -0
- package/dist/withRouter.d.ts +17 -0
- package/dist/withRouter.js +41 -0
- package/package.json +19 -15
- package/dist/app.d.ts +0 -14
- package/dist/app.js +0 -48
package/dist/html.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
+
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
4
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
5
|
+
var _excluded = ["content"],
|
|
6
|
+
_excluded2 = ["content"];
|
|
7
|
+
import React from 'react';
|
|
8
|
+
var RE_URL = /^(http:|https:)?\/\//;
|
|
9
|
+
function isUrl(str) {
|
|
10
|
+
return RE_URL.test(str) || str.startsWith('/') && !str.startsWith('/*') || str.startsWith('./') || str.startsWith('../');
|
|
11
|
+
}
|
|
12
|
+
var EnableJsScript = function EnableJsScript() {
|
|
13
|
+
return /*#__PURE__*/React.createElement("noscript", {
|
|
14
|
+
dangerouslySetInnerHTML: {
|
|
15
|
+
__html: "<b>Enable JavaScript to run this app.</b>"
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
var GlobalDataScript = function GlobalDataScript(props) {
|
|
20
|
+
var loaderData = props.loaderData,
|
|
21
|
+
htmlPageOpts = props.htmlPageOpts,
|
|
22
|
+
manifest = props.manifest;
|
|
23
|
+
return /*#__PURE__*/React.createElement("script", {
|
|
24
|
+
suppressHydrationWarning: true,
|
|
25
|
+
dangerouslySetInnerHTML: {
|
|
26
|
+
__html: "window.__UMI_LOADER_DATA__ = ".concat(JSON.stringify(loaderData || {}), "; window.__UMI_METADATA_LOADER_DATA__ = ").concat(JSON.stringify(htmlPageOpts || {}), "; window.__UMI_BUILD_MANIFEST_DATA__ = ").concat(JSON.stringify(manifest) || {})
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
function normalizeScripts(script) {
|
|
31
|
+
var extraProps = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
32
|
+
if (typeof script === 'string') {
|
|
33
|
+
return isUrl(script) ? _objectSpread({
|
|
34
|
+
src: script
|
|
35
|
+
}, extraProps) : {
|
|
36
|
+
content: script
|
|
37
|
+
};
|
|
38
|
+
} else if (_typeof(script) === 'object') {
|
|
39
|
+
return _objectSpread(_objectSpread({}, script), extraProps);
|
|
40
|
+
} else {
|
|
41
|
+
throw new Error("Invalid script type: ".concat(_typeof(script)));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function generatorStyle(style) {
|
|
45
|
+
return isUrl(style) ? {
|
|
46
|
+
type: 'link',
|
|
47
|
+
href: style
|
|
48
|
+
} : {
|
|
49
|
+
type: 'style',
|
|
50
|
+
content: style
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
var HydrateMetadata = function HydrateMetadata(props) {
|
|
54
|
+
var _htmlPageOpts$favicon, _htmlPageOpts$keyword, _htmlPageOpts$metas, _htmlPageOpts$links, _htmlPageOpts$styles, _htmlPageOpts$headScr;
|
|
55
|
+
var htmlPageOpts = props.htmlPageOpts;
|
|
56
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, (htmlPageOpts === null || htmlPageOpts === void 0 ? void 0 : htmlPageOpts.title) && /*#__PURE__*/React.createElement("title", null, htmlPageOpts.title), htmlPageOpts === null || htmlPageOpts === void 0 || (_htmlPageOpts$favicon = htmlPageOpts.favicons) === null || _htmlPageOpts$favicon === void 0 ? void 0 : _htmlPageOpts$favicon.map(function (favicon, key) {
|
|
57
|
+
return /*#__PURE__*/React.createElement("link", {
|
|
58
|
+
key: key,
|
|
59
|
+
rel: "shortcut icon",
|
|
60
|
+
href: favicon
|
|
61
|
+
});
|
|
62
|
+
}), (htmlPageOpts === null || htmlPageOpts === void 0 ? void 0 : htmlPageOpts.description) && /*#__PURE__*/React.createElement("meta", {
|
|
63
|
+
name: "description",
|
|
64
|
+
content: htmlPageOpts.description
|
|
65
|
+
}), (htmlPageOpts === null || htmlPageOpts === void 0 || (_htmlPageOpts$keyword = htmlPageOpts.keywords) === null || _htmlPageOpts$keyword === void 0 ? void 0 : _htmlPageOpts$keyword.length) && /*#__PURE__*/React.createElement("meta", {
|
|
66
|
+
name: "keywords",
|
|
67
|
+
content: htmlPageOpts.keywords.join(',')
|
|
68
|
+
}), htmlPageOpts === null || htmlPageOpts === void 0 || (_htmlPageOpts$metas = htmlPageOpts.metas) === null || _htmlPageOpts$metas === void 0 ? void 0 : _htmlPageOpts$metas.map(function (em) {
|
|
69
|
+
return /*#__PURE__*/React.createElement("meta", {
|
|
70
|
+
key: em.name,
|
|
71
|
+
name: em.name,
|
|
72
|
+
content: em.content
|
|
73
|
+
});
|
|
74
|
+
}), htmlPageOpts === null || htmlPageOpts === void 0 || (_htmlPageOpts$links = htmlPageOpts.links) === null || _htmlPageOpts$links === void 0 ? void 0 : _htmlPageOpts$links.map(function (link, key) {
|
|
75
|
+
return /*#__PURE__*/React.createElement("link", _extends({
|
|
76
|
+
key: key
|
|
77
|
+
}, link));
|
|
78
|
+
}), htmlPageOpts === null || htmlPageOpts === void 0 || (_htmlPageOpts$styles = htmlPageOpts.styles) === null || _htmlPageOpts$styles === void 0 ? void 0 : _htmlPageOpts$styles.map(function (style, key) {
|
|
79
|
+
var _generatorStyle = generatorStyle(style),
|
|
80
|
+
type = _generatorStyle.type,
|
|
81
|
+
href = _generatorStyle.href,
|
|
82
|
+
content = _generatorStyle.content;
|
|
83
|
+
if (type === 'link') {
|
|
84
|
+
return /*#__PURE__*/React.createElement("link", {
|
|
85
|
+
key: key,
|
|
86
|
+
rel: "stylesheet",
|
|
87
|
+
href: href
|
|
88
|
+
});
|
|
89
|
+
} else if (type === 'style') {
|
|
90
|
+
return /*#__PURE__*/React.createElement("style", {
|
|
91
|
+
key: key
|
|
92
|
+
}, content);
|
|
93
|
+
}
|
|
94
|
+
}), htmlPageOpts === null || htmlPageOpts === void 0 || (_htmlPageOpts$headScr = htmlPageOpts.headScripts) === null || _htmlPageOpts$headScr === void 0 ? void 0 : _htmlPageOpts$headScr.map(function (script, key) {
|
|
95
|
+
var _normalizeScripts = normalizeScripts(script),
|
|
96
|
+
content = _normalizeScripts.content,
|
|
97
|
+
rest = _objectWithoutProperties(_normalizeScripts, _excluded);
|
|
98
|
+
return /*#__PURE__*/React.createElement("script", _extends({
|
|
99
|
+
dangerouslySetInnerHTML: {
|
|
100
|
+
__html: content
|
|
101
|
+
},
|
|
102
|
+
key: key
|
|
103
|
+
}, rest));
|
|
104
|
+
}));
|
|
105
|
+
};
|
|
106
|
+
export function Html(_ref) {
|
|
107
|
+
var _htmlPageOpts$scripts;
|
|
108
|
+
var children = _ref.children,
|
|
109
|
+
loaderData = _ref.loaderData,
|
|
110
|
+
manifest = _ref.manifest,
|
|
111
|
+
htmlPageOpts = _ref.htmlPageOpts,
|
|
112
|
+
renderFromRoot = _ref.renderFromRoot,
|
|
113
|
+
__SPECIAL_HTML_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = _ref.__SPECIAL_HTML_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
|
|
114
|
+
mountElementId = _ref.mountElementId;
|
|
115
|
+
// TODO: 处理 head 标签,比如 favicon.ico 的一致性
|
|
116
|
+
// TODO: root 支持配置
|
|
117
|
+
if (__SPECIAL_HTML_DO_NOT_USE_OR_YOU_WILL_BE_FIRED) {
|
|
118
|
+
return /*#__PURE__*/React.createElement("html", null, /*#__PURE__*/React.createElement("head", null), /*#__PURE__*/React.createElement("body", null, /*#__PURE__*/React.createElement(EnableJsScript, null), /*#__PURE__*/React.createElement("div", {
|
|
119
|
+
id: mountElementId
|
|
120
|
+
}, children), /*#__PURE__*/React.createElement(GlobalDataScript, {
|
|
121
|
+
manifest: manifest,
|
|
122
|
+
loaderData: loaderData,
|
|
123
|
+
htmlPageOpts: htmlPageOpts
|
|
124
|
+
})));
|
|
125
|
+
}
|
|
126
|
+
if (renderFromRoot) {
|
|
127
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(EnableJsScript, null), /*#__PURE__*/React.createElement("div", {
|
|
128
|
+
id: mountElementId
|
|
129
|
+
}, children), /*#__PURE__*/React.createElement(GlobalDataScript, {
|
|
130
|
+
manifest: manifest,
|
|
131
|
+
loaderData: loaderData,
|
|
132
|
+
htmlPageOpts: htmlPageOpts
|
|
133
|
+
}));
|
|
134
|
+
}
|
|
135
|
+
var serverBuildManifest = typeof window === 'undefined' ? manifest : window.__UMI_BUILD_MANIFEST_DATA__;
|
|
136
|
+
return (
|
|
137
|
+
/*#__PURE__*/
|
|
138
|
+
// FIXME: Resolve the hydrate warning for suppressHydrationWarning(3)
|
|
139
|
+
React.createElement("html", {
|
|
140
|
+
suppressHydrationWarning: true,
|
|
141
|
+
lang: (htmlPageOpts === null || htmlPageOpts === void 0 ? void 0 : htmlPageOpts.lang) || 'en'
|
|
142
|
+
}, /*#__PURE__*/React.createElement("head", null, /*#__PURE__*/React.createElement("meta", {
|
|
143
|
+
charSet: "utf-8"
|
|
144
|
+
}), /*#__PURE__*/React.createElement("meta", {
|
|
145
|
+
name: "viewport",
|
|
146
|
+
content: "width=device-width, initial-scale=1"
|
|
147
|
+
}), (serverBuildManifest === null || serverBuildManifest === void 0 ? void 0 : serverBuildManifest.assets['umi.css']) && /*#__PURE__*/React.createElement("link", {
|
|
148
|
+
suppressHydrationWarning: true,
|
|
149
|
+
rel: "stylesheet",
|
|
150
|
+
href: manifest === null || manifest === void 0 ? void 0 : manifest.assets['umi.css']
|
|
151
|
+
}), /*#__PURE__*/React.createElement(HydrateMetadata, {
|
|
152
|
+
htmlPageOpts: htmlPageOpts
|
|
153
|
+
})), /*#__PURE__*/React.createElement("body", null, /*#__PURE__*/React.createElement(EnableJsScript, null), /*#__PURE__*/React.createElement("div", {
|
|
154
|
+
id: mountElementId
|
|
155
|
+
}, children), /*#__PURE__*/React.createElement(GlobalDataScript, {
|
|
156
|
+
manifest: manifest,
|
|
157
|
+
loaderData: loaderData,
|
|
158
|
+
htmlPageOpts: htmlPageOpts
|
|
159
|
+
}), htmlPageOpts === null || htmlPageOpts === void 0 || (_htmlPageOpts$scripts = htmlPageOpts.scripts) === null || _htmlPageOpts$scripts === void 0 ? void 0 : _htmlPageOpts$scripts.map(function (script, key) {
|
|
160
|
+
var _normalizeScripts2 = normalizeScripts(script),
|
|
161
|
+
content = _normalizeScripts2.content,
|
|
162
|
+
rest = _objectWithoutProperties(_normalizeScripts2, _excluded2);
|
|
163
|
+
return /*#__PURE__*/React.createElement("script", _extends({
|
|
164
|
+
dangerouslySetInnerHTML: {
|
|
165
|
+
__html: content
|
|
166
|
+
},
|
|
167
|
+
key: key
|
|
168
|
+
}, rest));
|
|
169
|
+
})))
|
|
170
|
+
);
|
|
171
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export
|
|
1
|
+
export { createBrowserHistory, createHashHistory, createMemoryHistory, type History, } from 'history';
|
|
2
|
+
export { Helmet, HelmetProvider } from 'react-helmet-async';
|
|
3
|
+
export { createSearchParams, generatePath, matchPath, matchRoutes, Navigate, NavLink, Outlet, resolvePath, useLocation, useMatch, useNavigate, useOutlet, useOutletContext, useParams, useResolvedPath, useRoutes, useSearchParams, } from 'react-router-dom';
|
|
4
|
+
export { useAppData, useClientLoaderData, useLoaderData, useRouteProps, useSelectedRoutes, useServerLoaderData, } from './appContext';
|
|
5
|
+
export { renderClient, __getRoot } from './browser';
|
|
6
|
+
export { LinkWithPrefetch as Link } from './link';
|
|
7
|
+
export { useRouteData } from './routeContext';
|
|
8
|
+
export type { ClientLoader } from './types';
|
|
9
|
+
export { __useFetcher } from './useFetcher';
|
|
10
|
+
export { withRouter, type RouteComponentProps } from './withRouter';
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export
|
|
1
|
+
export { createBrowserHistory, createHashHistory, createMemoryHistory } from 'history';
|
|
2
|
+
export { Helmet, HelmetProvider } from 'react-helmet-async';
|
|
3
|
+
export { createSearchParams, generatePath, matchPath, matchRoutes, Navigate, NavLink, Outlet, resolvePath, useLocation, useMatch, useNavigate, useOutlet, useOutletContext, useParams, useResolvedPath, useRoutes, useSearchParams } from 'react-router-dom';
|
|
4
|
+
export { useAppData, useClientLoaderData, useLoaderData, useRouteProps, useSelectedRoutes, useServerLoaderData } from "./appContext";
|
|
5
|
+
export { renderClient, __getRoot } from "./browser";
|
|
6
|
+
export { LinkWithPrefetch as Link } from "./link";
|
|
7
|
+
export { useRouteData } from "./routeContext";
|
|
8
|
+
export { __useFetcher } from "./useFetcher";
|
|
9
|
+
export { withRouter } from "./withRouter";
|
package/dist/link.d.ts
ADDED
package/dist/link.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["prefetch"];
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { Link } from 'react-router-dom';
|
|
6
|
+
import { useAppData } from "./appContext";
|
|
7
|
+
export function LinkWithPrefetch(props) {
|
|
8
|
+
var _props$to;
|
|
9
|
+
var prefetch = props.prefetch,
|
|
10
|
+
linkProps = _objectWithoutProperties(props, _excluded);
|
|
11
|
+
var appData = useAppData();
|
|
12
|
+
var to = typeof props.to === 'string' ? props.to : (_props$to = props.to) === null || _props$to === void 0 ? void 0 : _props$to.pathname;
|
|
13
|
+
// compatible with old code
|
|
14
|
+
// which to might be undefined
|
|
15
|
+
if (!to) return null;
|
|
16
|
+
return /*#__PURE__*/React.createElement(Link, _extends({
|
|
17
|
+
onMouseEnter: function onMouseEnter() {
|
|
18
|
+
var _appData$preloadRoute;
|
|
19
|
+
return prefetch && to && ((_appData$preloadRoute = appData.preloadRoute) === null || _appData$preloadRoute === void 0 ? void 0 : _appData$preloadRoute.call(appData, to));
|
|
20
|
+
}
|
|
21
|
+
}, linkProps), props.children);
|
|
22
|
+
}
|
package/dist/routes.d.ts
CHANGED
|
@@ -1,21 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { IClientRoute, IRoutesById } from './types';
|
|
3
3
|
export declare function createClientRoutes(opts: {
|
|
4
4
|
routesById: IRoutesById;
|
|
5
|
+
routeComponents: Record<string, any>;
|
|
5
6
|
parentId?: string;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
path: string | undefined;
|
|
10
|
-
index: boolean | undefined;
|
|
11
|
-
element: JSX.Element;
|
|
12
|
-
}[];
|
|
13
|
-
export declare function createClientRoute(opts: {
|
|
14
|
-
route: IRoute;
|
|
15
|
-
Component: any;
|
|
16
|
-
}): {
|
|
17
|
-
id: string;
|
|
18
|
-
path: string | undefined;
|
|
19
|
-
index: boolean | undefined;
|
|
20
|
-
element: JSX.Element;
|
|
21
|
-
};
|
|
7
|
+
loadingComponent?: React.ReactNode;
|
|
8
|
+
reactRouter5Compat?: boolean;
|
|
9
|
+
}): IClientRoute[];
|
package/dist/routes.js
CHANGED
|
@@ -1,32 +1,107 @@
|
|
|
1
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
4
|
+
var _excluded = ["redirect"];
|
|
5
|
+
// @ts-ignore
|
|
1
6
|
import React from 'react';
|
|
2
|
-
import { Navigate } from 'react-router-dom';
|
|
7
|
+
import { generatePath, Navigate, useParams, Outlet } from 'react-router-dom';
|
|
8
|
+
import { RouteContext, useRouteData } from "./routeContext";
|
|
9
|
+
import { useAppData } from "./appContext";
|
|
3
10
|
export function createClientRoutes(opts) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
var routesById = opts.routesById,
|
|
12
|
+
parentId = opts.parentId,
|
|
13
|
+
routeComponents = opts.routeComponents;
|
|
14
|
+
return Object.keys(routesById).filter(function (id) {
|
|
15
|
+
return routesById[id].parentId === parentId;
|
|
16
|
+
}).map(function (id) {
|
|
17
|
+
var route = createClientRoute(_objectSpread({
|
|
18
|
+
route: routesById[id],
|
|
19
|
+
routeComponent: routeComponents[id],
|
|
20
|
+
loadingComponent: opts.loadingComponent,
|
|
21
|
+
reactRouter5Compat: opts.reactRouter5Compat
|
|
22
|
+
}, opts.reactRouter5Compat && {
|
|
23
|
+
// TODO: 这个不准,没考虑 patchClientRoutes 的场景
|
|
24
|
+
hasChildren: Object.keys(routesById).filter(function (rid) {
|
|
25
|
+
return routesById[rid].parentId === id;
|
|
26
|
+
}).length > 0
|
|
27
|
+
}));
|
|
28
|
+
var children = createClientRoutes({
|
|
29
|
+
routesById: routesById,
|
|
30
|
+
routeComponents: routeComponents,
|
|
31
|
+
parentId: route.id,
|
|
32
|
+
loadingComponent: opts.loadingComponent,
|
|
33
|
+
reactRouter5Compat: opts.reactRouter5Compat
|
|
22
34
|
});
|
|
35
|
+
if (children.length > 0) {
|
|
36
|
+
route.children = children;
|
|
37
|
+
// TODO: remove me
|
|
38
|
+
// compatible with @ant-design/pro-layout
|
|
39
|
+
route.routes = children;
|
|
40
|
+
}
|
|
41
|
+
return route;
|
|
42
|
+
});
|
|
23
43
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
44
|
+
function NavigateWithParams(props) {
|
|
45
|
+
var params = useParams();
|
|
46
|
+
var propsWithParams = _objectSpread(_objectSpread({}, props), {}, {
|
|
47
|
+
to: generatePath(props.to, params)
|
|
48
|
+
});
|
|
49
|
+
return /*#__PURE__*/React.createElement(Navigate, _extends({
|
|
50
|
+
replace: true
|
|
51
|
+
}, propsWithParams));
|
|
32
52
|
}
|
|
53
|
+
function createClientRoute(opts) {
|
|
54
|
+
var route = opts.route;
|
|
55
|
+
var redirect = route.redirect,
|
|
56
|
+
props = _objectWithoutProperties(route, _excluded);
|
|
57
|
+
var Remote = opts.reactRouter5Compat ? RemoteComponentReactRouter5 : RemoteComponent;
|
|
58
|
+
return _objectSpread({
|
|
59
|
+
element: redirect ? /*#__PURE__*/React.createElement(NavigateWithParams, {
|
|
60
|
+
to: redirect
|
|
61
|
+
}) : /*#__PURE__*/React.createElement(RouteContext.Provider, {
|
|
62
|
+
value: {
|
|
63
|
+
route: opts.route
|
|
64
|
+
}
|
|
65
|
+
}, /*#__PURE__*/React.createElement(Remote, {
|
|
66
|
+
loader: /*#__PURE__*/React.memo(opts.routeComponent),
|
|
67
|
+
loadingComponent: opts.loadingComponent || DefaultLoading,
|
|
68
|
+
hasChildren: opts.hasChildren
|
|
69
|
+
}))
|
|
70
|
+
}, props);
|
|
71
|
+
}
|
|
72
|
+
function DefaultLoading() {
|
|
73
|
+
return /*#__PURE__*/React.createElement("div", null);
|
|
74
|
+
}
|
|
75
|
+
function RemoteComponentReactRouter5(props) {
|
|
76
|
+
var _useRouteData = useRouteData(),
|
|
77
|
+
route = _useRouteData.route;
|
|
78
|
+
var _useAppData = useAppData(),
|
|
79
|
+
history = _useAppData.history,
|
|
80
|
+
clientRoutes = _useAppData.clientRoutes;
|
|
81
|
+
var params = useParams();
|
|
82
|
+
var match = {
|
|
83
|
+
params: params,
|
|
84
|
+
isExact: true,
|
|
85
|
+
path: route.path,
|
|
86
|
+
url: history.location.pathname
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// staticContext 没有兼容 好像没看到对应的兼容写法
|
|
90
|
+
var Component = props.loader;
|
|
91
|
+
return /*#__PURE__*/React.createElement(React.Suspense, {
|
|
92
|
+
fallback: /*#__PURE__*/React.createElement(props.loadingComponent, null)
|
|
93
|
+
}, /*#__PURE__*/React.createElement(Component, {
|
|
94
|
+
location: history.location,
|
|
95
|
+
match: match,
|
|
96
|
+
history: history,
|
|
97
|
+
params: params,
|
|
98
|
+
route: route,
|
|
99
|
+
routes: clientRoutes
|
|
100
|
+
}, props.hasChildren && /*#__PURE__*/React.createElement(Outlet, null)));
|
|
101
|
+
}
|
|
102
|
+
function RemoteComponent(props) {
|
|
103
|
+
var Component = props.loader;
|
|
104
|
+
return /*#__PURE__*/React.createElement(React.Suspense, {
|
|
105
|
+
fallback: /*#__PURE__*/React.createElement(props.loadingComponent, null)
|
|
106
|
+
}, /*#__PURE__*/React.createElement(Component, null));
|
|
107
|
+
}
|
package/dist/server.d.ts
ADDED
package/dist/server.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
2
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
3
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { StaticRouter } from 'react-router-dom/server';
|
|
6
|
+
import { AppContext } from "./appContext";
|
|
7
|
+
import { Routes } from "./browser";
|
|
8
|
+
import { Html } from "./html";
|
|
9
|
+
import { createClientRoutes } from "./routes";
|
|
10
|
+
// Get the root React component for ReactDOMServer.renderToString
|
|
11
|
+
export function getClientRootComponent(_x) {
|
|
12
|
+
return _getClientRootComponent.apply(this, arguments);
|
|
13
|
+
}
|
|
14
|
+
function _getClientRootComponent() {
|
|
15
|
+
_getClientRootComponent = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(opts) {
|
|
16
|
+
var basename, components, clientRoutes, rootContainer, _i, _arr, key, app;
|
|
17
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
18
|
+
while (1) switch (_context.prev = _context.next) {
|
|
19
|
+
case 0:
|
|
20
|
+
basename = '/';
|
|
21
|
+
components = _objectSpread({}, opts.routeComponents); // todo 参数对齐
|
|
22
|
+
clientRoutes = createClientRoutes({
|
|
23
|
+
routesById: opts.routes,
|
|
24
|
+
routeComponents: components
|
|
25
|
+
});
|
|
26
|
+
opts.pluginManager.applyPlugins({
|
|
27
|
+
key: 'patchClientRoutes',
|
|
28
|
+
type: 'event',
|
|
29
|
+
args: {
|
|
30
|
+
routes: clientRoutes
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
rootContainer = /*#__PURE__*/React.createElement(StaticRouter, {
|
|
34
|
+
basename: basename,
|
|
35
|
+
location: opts.location
|
|
36
|
+
}, /*#__PURE__*/React.createElement(Routes, null));
|
|
37
|
+
for (_i = 0, _arr = [
|
|
38
|
+
// Lowest to the highest priority
|
|
39
|
+
'innerProvider', 'i18nProvider', 'accessProvider', 'dataflowProvider', 'outerProvider', 'rootContainer']; _i < _arr.length; _i++) {
|
|
40
|
+
key = _arr[_i];
|
|
41
|
+
rootContainer = opts.pluginManager.applyPlugins({
|
|
42
|
+
type: 'modify',
|
|
43
|
+
key: key,
|
|
44
|
+
initialValue: rootContainer,
|
|
45
|
+
args: {}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
app = /*#__PURE__*/React.createElement(AppContext.Provider, {
|
|
49
|
+
value: {
|
|
50
|
+
routes: opts.routes,
|
|
51
|
+
routeComponents: opts.routeComponents,
|
|
52
|
+
clientRoutes: clientRoutes,
|
|
53
|
+
pluginManager: opts.pluginManager,
|
|
54
|
+
basename: basename,
|
|
55
|
+
clientLoaderData: {},
|
|
56
|
+
serverLoaderData: opts.loaderData
|
|
57
|
+
}
|
|
58
|
+
}, rootContainer);
|
|
59
|
+
return _context.abrupt("return", /*#__PURE__*/React.createElement(Html, opts, app));
|
|
60
|
+
case 8:
|
|
61
|
+
case "end":
|
|
62
|
+
return _context.stop();
|
|
63
|
+
}
|
|
64
|
+
}, _callee);
|
|
65
|
+
}));
|
|
66
|
+
return _getClientRootComponent.apply(this, arguments);
|
|
67
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,10 +1,82 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { IhtmlPageOpts, ServerLoader } from '@umijs/server/dist/types';
|
|
3
|
+
import type { RouteMatch, RouteObject } from 'react-router-dom';
|
|
4
|
+
declare global {
|
|
5
|
+
interface Window {
|
|
6
|
+
__UMI_LOADER_DATA__: any;
|
|
7
|
+
__UMI_METADATA_LOADER_DATA__: any;
|
|
8
|
+
__UMI_BUILD_MANIFEST_DATA__: any;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
declare type ClientLoaderFunctionArgs = {
|
|
12
|
+
serverLoader: ServerLoader;
|
|
13
|
+
};
|
|
14
|
+
export declare type ClientLoader = ((args: ClientLoaderFunctionArgs) => Promise<any>) & {
|
|
15
|
+
hydrate?: boolean;
|
|
16
|
+
};
|
|
17
|
+
export interface IRouteSSRProps {
|
|
18
|
+
clientLoader?: ClientLoader;
|
|
19
|
+
hasServerLoader?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface IRouteConventionExportProps {
|
|
22
|
+
routeProps?: Record<string, any>;
|
|
23
|
+
}
|
|
24
|
+
export interface IRoute extends IRouteSSRProps, IRouteConventionExportProps {
|
|
2
25
|
id: string;
|
|
3
26
|
path?: string;
|
|
4
27
|
index?: boolean;
|
|
5
28
|
parentId?: string;
|
|
6
29
|
redirect?: string;
|
|
7
30
|
}
|
|
31
|
+
export interface IClientRoute extends IRoute {
|
|
32
|
+
element: React.ReactNode;
|
|
33
|
+
children?: IClientRoute[];
|
|
34
|
+
routes?: IClientRoute[];
|
|
35
|
+
}
|
|
36
|
+
export interface ISelectedRoute extends IRoute, RouteObject {
|
|
37
|
+
}
|
|
38
|
+
export interface ISelectedRoutes extends RouteMatch {
|
|
39
|
+
route: ISelectedRoute;
|
|
40
|
+
}
|
|
8
41
|
export interface IRoutesById {
|
|
9
42
|
[id: string]: IRoute;
|
|
10
43
|
}
|
|
44
|
+
export interface IRouteComponents {
|
|
45
|
+
[id: string]: any;
|
|
46
|
+
}
|
|
47
|
+
export interface ILoaderData {
|
|
48
|
+
[routeKey: string]: any;
|
|
49
|
+
}
|
|
50
|
+
interface IHtmlHydrateOptions {
|
|
51
|
+
htmlPageOpts?: IhtmlPageOpts;
|
|
52
|
+
renderFromRoot?: boolean;
|
|
53
|
+
__SPECIAL_HTML_DO_NOT_USE_OR_YOU_WILL_BE_FIRED?: boolean;
|
|
54
|
+
mountElementId?: string;
|
|
55
|
+
}
|
|
56
|
+
export interface IRootComponentOptions extends IHtmlHydrateOptions {
|
|
57
|
+
routes: IRoutesById;
|
|
58
|
+
routeComponents: IRouteComponents;
|
|
59
|
+
pluginManager: any;
|
|
60
|
+
location: string;
|
|
61
|
+
loaderData: {
|
|
62
|
+
[routeKey: string]: any;
|
|
63
|
+
};
|
|
64
|
+
manifest: any;
|
|
65
|
+
}
|
|
66
|
+
export interface IHtmlProps extends IHtmlHydrateOptions {
|
|
67
|
+
children?: React.ReactNode;
|
|
68
|
+
loaderData?: {
|
|
69
|
+
[routeKey: string]: any;
|
|
70
|
+
};
|
|
71
|
+
manifest?: any;
|
|
72
|
+
}
|
|
73
|
+
export declare type IScript = Partial<{
|
|
74
|
+
async: boolean;
|
|
75
|
+
charset: string;
|
|
76
|
+
content: string;
|
|
77
|
+
crossOrigin: string | null;
|
|
78
|
+
defer: boolean;
|
|
79
|
+
src: string;
|
|
80
|
+
type: string;
|
|
81
|
+
}> | string;
|
|
82
|
+
export {};
|
package/dist/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useLocation } from 'react-router-dom';
|
|
2
|
+
import { useAppData } from "./appContext";
|
|
3
|
+
export function __useFetcher() {
|
|
4
|
+
var _useAppData = useAppData(),
|
|
5
|
+
preloadRoute = _useAppData.preloadRoute;
|
|
6
|
+
var location = useLocation();
|
|
7
|
+
return {
|
|
8
|
+
load: function load(path) {
|
|
9
|
+
preloadRoute(path || location.pathname);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useLocation, useNavigate, useParams } from 'react-router-dom';
|
|
3
|
+
export interface RouteComponentProps<T = ReturnType<typeof useParams>> {
|
|
4
|
+
history?: {
|
|
5
|
+
back: () => void;
|
|
6
|
+
goBack: () => void;
|
|
7
|
+
location: ReturnType<typeof useLocation>;
|
|
8
|
+
push: (url: string, state?: any) => void;
|
|
9
|
+
};
|
|
10
|
+
location?: ReturnType<typeof useLocation>;
|
|
11
|
+
match?: {
|
|
12
|
+
params: T;
|
|
13
|
+
};
|
|
14
|
+
params?: T;
|
|
15
|
+
navigate?: ReturnType<typeof useNavigate>;
|
|
16
|
+
}
|
|
17
|
+
export declare function withRouter<P extends RouteComponentProps<P>>(Component: React.ComponentType<P>): (props: P) => JSX.Element;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { useLocation, useNavigate, useParams } from 'react-router-dom';
|
|
4
|
+
export function withRouter(Component) {
|
|
5
|
+
function ComponentWithRouterProp(props) {
|
|
6
|
+
var location = useLocation();
|
|
7
|
+
var navigate = useNavigate();
|
|
8
|
+
var params = useParams();
|
|
9
|
+
var match = {
|
|
10
|
+
params: params
|
|
11
|
+
};
|
|
12
|
+
var history = {
|
|
13
|
+
back: function back() {
|
|
14
|
+
return navigate(-1);
|
|
15
|
+
},
|
|
16
|
+
goBack: function goBack() {
|
|
17
|
+
return navigate(-1);
|
|
18
|
+
},
|
|
19
|
+
location: location,
|
|
20
|
+
push: function push(url, state) {
|
|
21
|
+
return navigate(url, {
|
|
22
|
+
state: state
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
replace: function replace(url, state) {
|
|
26
|
+
return navigate(url, {
|
|
27
|
+
replace: true,
|
|
28
|
+
state: state
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
return /*#__PURE__*/React.createElement(Component, _extends({}, props, {
|
|
33
|
+
history: history,
|
|
34
|
+
location: location,
|
|
35
|
+
match: match,
|
|
36
|
+
params: params,
|
|
37
|
+
navigate: navigate
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
return ComponentWithRouterProp;
|
|
41
|
+
}
|