@umijs/renderer-react 4.0.7 → 4.0.8
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/dist/appContext.d.ts +0 -0
- package/dist/appContext.js +14 -10
- package/dist/browser.d.ts +0 -0
- package/dist/browser.js +206 -153
- package/dist/index.d.ts +2 -1
- package/dist/index.js +8 -7
- package/dist/link.d.ts +0 -0
- package/dist/link.js +15 -5
- package/dist/routeContext.d.ts +0 -0
- package/dist/routeContext.js +3 -3
- package/dist/routes.d.ts +0 -0
- package/dist/routes.js +78 -55
- package/dist/server.d.ts +0 -0
- package/dist/server.js +102 -54
- package/dist/types.d.ts +0 -0
- package/dist/types.js +1 -1
- package/dist/useFetcher.d.ts +1 -1
- package/dist/useFetcher.js +11 -9
- package/dist/withRouter.d.ts +17 -0
- package/dist/withRouter.js +43 -0
- package/package.json +4 -3
package/dist/appContext.d.ts
CHANGED
|
File without changes
|
package/dist/appContext.js
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { useRouteData } from
|
|
3
|
-
export
|
|
2
|
+
import { useRouteData } from "./routeContext";
|
|
3
|
+
export var AppContext = /*#__PURE__*/React.createContext({});
|
|
4
4
|
export function useAppData() {
|
|
5
|
-
|
|
5
|
+
return React.useContext(AppContext);
|
|
6
6
|
}
|
|
7
7
|
export function useServerLoaderData() {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
var route = useRouteData();
|
|
9
|
+
var appData = useAppData();
|
|
10
|
+
return {
|
|
11
|
+
data: appData.serverLoaderData[route.route.id]
|
|
12
|
+
};
|
|
11
13
|
}
|
|
12
14
|
export function useClientLoaderData() {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
var route = useRouteData();
|
|
16
|
+
var appData = useAppData();
|
|
17
|
+
return {
|
|
18
|
+
data: appData.clientLoaderData[route.route.id]
|
|
19
|
+
};
|
|
20
|
+
}
|
package/dist/browser.d.ts
CHANGED
|
File without changes
|
package/dist/browser.js
CHANGED
|
@@ -1,167 +1,220 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
|
3
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
4
|
+
import React, { useCallback, useEffect, useState } from 'react'; // compatible with < react@18 in @umijs/preset-umi/src/features/react
|
|
5
|
+
|
|
3
6
|
import ReactDOM from 'react-dom/client';
|
|
4
7
|
import { matchRoutes, Router, useRoutes } from 'react-router-dom';
|
|
5
|
-
import { AppContext, useAppData } from
|
|
6
|
-
import { createClientRoutes } from
|
|
8
|
+
import { AppContext, useAppData } from "./appContext";
|
|
9
|
+
import { createClientRoutes } from "./routes";
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
|
|
7
12
|
function BrowserRoutes(props) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
13
|
+
var history = props.history;
|
|
14
|
+
|
|
15
|
+
var _React$useState = React.useState({
|
|
16
|
+
action: history.action,
|
|
17
|
+
location: history.location
|
|
18
|
+
}),
|
|
19
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
20
|
+
state = _React$useState2[0],
|
|
21
|
+
setState = _React$useState2[1];
|
|
22
|
+
|
|
23
|
+
React.useLayoutEffect(function () {
|
|
24
|
+
return history.listen(setState);
|
|
25
|
+
}, [history]);
|
|
26
|
+
React.useLayoutEffect(function () {
|
|
27
|
+
function onRouteChange(opts) {
|
|
28
|
+
props.pluginManager.applyPlugins({
|
|
29
|
+
key: 'onRouteChange',
|
|
30
|
+
type: 'event',
|
|
31
|
+
args: {
|
|
32
|
+
routes: props.routes,
|
|
33
|
+
clientRoutes: props.clientRoutes,
|
|
34
|
+
location: opts.location,
|
|
35
|
+
action: opts.action
|
|
26
36
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
history.listen(onRouteChange);
|
|
41
|
+
onRouteChange({
|
|
42
|
+
location: state.location,
|
|
43
|
+
action: state.action
|
|
44
|
+
});
|
|
45
|
+
}, [history, props.routes, props.clientRoutes]);
|
|
46
|
+
return /*#__PURE__*/_jsx(Router, {
|
|
47
|
+
navigator: history,
|
|
48
|
+
location: state.location,
|
|
49
|
+
basename: props.basename,
|
|
50
|
+
children: props.children
|
|
51
|
+
});
|
|
31
52
|
}
|
|
53
|
+
|
|
32
54
|
export function Routes() {
|
|
33
|
-
|
|
34
|
-
|
|
55
|
+
var _useAppData = useAppData(),
|
|
56
|
+
clientRoutes = _useAppData.clientRoutes;
|
|
57
|
+
|
|
58
|
+
return useRoutes(clientRoutes);
|
|
35
59
|
}
|
|
36
60
|
export function renderClient(opts) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
},
|
|
50
|
-
});
|
|
51
|
-
let rootContainer = (React.createElement(BrowserRoutes, { basename: basename, pluginManager: opts.pluginManager, routes: opts.routes, clientRoutes: clientRoutes, history: opts.history },
|
|
52
|
-
React.createElement(Routes, null)));
|
|
53
|
-
for (const key of [
|
|
54
|
-
// Lowest to the highest priority
|
|
55
|
-
'innerProvider',
|
|
56
|
-
'i18nProvider',
|
|
57
|
-
'accessProvider',
|
|
58
|
-
'dataflowProvider',
|
|
59
|
-
'outerProvider',
|
|
60
|
-
'rootContainer',
|
|
61
|
-
]) {
|
|
62
|
-
rootContainer = opts.pluginManager.applyPlugins({
|
|
63
|
-
type: 'modify',
|
|
64
|
-
key: key,
|
|
65
|
-
initialValue: rootContainer,
|
|
66
|
-
args: {},
|
|
67
|
-
});
|
|
61
|
+
var basename = opts.basename || '/';
|
|
62
|
+
var rootElement = opts.rootElement || document.getElementById('root');
|
|
63
|
+
var clientRoutes = createClientRoutes({
|
|
64
|
+
routesById: opts.routes,
|
|
65
|
+
routeComponents: opts.routeComponents,
|
|
66
|
+
loadingComponent: opts.loadingComponent
|
|
67
|
+
});
|
|
68
|
+
opts.pluginManager.applyPlugins({
|
|
69
|
+
key: 'patchClientRoutes',
|
|
70
|
+
type: 'event',
|
|
71
|
+
args: {
|
|
72
|
+
routes: clientRoutes
|
|
68
73
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
var rootContainer = /*#__PURE__*/_jsx(BrowserRoutes, {
|
|
77
|
+
basename: basename,
|
|
78
|
+
pluginManager: opts.pluginManager,
|
|
79
|
+
routes: opts.routes,
|
|
80
|
+
clientRoutes: clientRoutes,
|
|
81
|
+
history: opts.history,
|
|
82
|
+
children: /*#__PURE__*/_jsx(Routes, {})
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
for (var _i = 0, _arr = [// Lowest to the highest priority
|
|
86
|
+
'innerProvider', 'i18nProvider', 'accessProvider', 'dataflowProvider', 'outerProvider', 'rootContainer']; _i < _arr.length; _i++) {
|
|
87
|
+
var key = _arr[_i];
|
|
88
|
+
rootContainer = opts.pluginManager.applyPlugins({
|
|
89
|
+
type: 'modify',
|
|
90
|
+
key: key,
|
|
91
|
+
initialValue: rootContainer,
|
|
92
|
+
args: {}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
var Browser = function Browser() {
|
|
97
|
+
var _useState = useState({}),
|
|
98
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
99
|
+
clientLoaderData = _useState2[0],
|
|
100
|
+
setClientLoaderData = _useState2[1];
|
|
101
|
+
|
|
102
|
+
var _useState3 = useState( // @ts-ignore
|
|
103
|
+
window.__UMI_LOADER_DATA__ || {}),
|
|
104
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
105
|
+
serverLoaderData = _useState4[0],
|
|
106
|
+
setServerLoaderData = _useState4[1];
|
|
107
|
+
|
|
108
|
+
var handleRouteChange = useCallback(function (id, isFirst) {
|
|
109
|
+
var _matchRoutes;
|
|
110
|
+
|
|
111
|
+
// Patched routes has to id
|
|
112
|
+
var matchedRouteIds = (((_matchRoutes = matchRoutes(clientRoutes, id)) === null || _matchRoutes === void 0 ? void 0 : _matchRoutes.map( // @ts-ignore
|
|
113
|
+
function (route) {
|
|
114
|
+
return route.route.id;
|
|
115
|
+
})) || []).filter(Boolean);
|
|
116
|
+
matchedRouteIds.forEach(function (id) {
|
|
117
|
+
var _opts$routes$id, _opts$routes$id2;
|
|
118
|
+
|
|
119
|
+
// preload
|
|
72
120
|
// @ts-ignore
|
|
73
|
-
window.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
// preload
|
|
83
|
-
// @ts-ignore
|
|
84
|
-
const manifest = window.__umi_manifest__;
|
|
85
|
-
if (manifest) {
|
|
86
|
-
const routeIdReplaced = id.replace(/[\/\-]/g, '_');
|
|
87
|
-
const preloadId = `preload-${routeIdReplaced}.js`;
|
|
88
|
-
if (!document.getElementById(preloadId)) {
|
|
89
|
-
const keys = Object.keys(manifest).filter((k) => k.startsWith(routeIdReplaced + '.'));
|
|
90
|
-
keys.forEach((key) => {
|
|
91
|
-
if (!/\.(js|css)$/.test(key)) {
|
|
92
|
-
throw Error(`preload not support ${key} file`);
|
|
93
|
-
}
|
|
94
|
-
let file = manifest[key];
|
|
95
|
-
const link = document.createElement('link');
|
|
96
|
-
link.rel = 'preload';
|
|
97
|
-
link.as = 'style';
|
|
98
|
-
if (key.endsWith('.js')) {
|
|
99
|
-
link.as = 'script';
|
|
100
|
-
link.id = preloadId;
|
|
101
|
-
}
|
|
102
|
-
// publicPath already in the manifest,
|
|
103
|
-
// but if runtimePublicPath is true, we need to replace it
|
|
104
|
-
if (opts.runtimePublicPath) {
|
|
105
|
-
file = file.replace(new RegExp(`^${opts.publicPath}`),
|
|
106
|
-
// @ts-ignore
|
|
107
|
-
window.publicPath);
|
|
108
|
-
}
|
|
109
|
-
link.href = file;
|
|
110
|
-
document.head.appendChild(link);
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
// server loader
|
|
115
|
-
if (!isFirst && opts.routes[id].hasServerLoader) {
|
|
116
|
-
fetch('/__serverLoader?route=' + id)
|
|
117
|
-
.then((d) => d.json())
|
|
118
|
-
.then((data) => {
|
|
119
|
-
// setServerLoaderData when startTransition because if ssr is enabled,
|
|
120
|
-
// the component may being hydrated and setLoaderData will break the hydration
|
|
121
|
-
React.startTransition(() => {
|
|
122
|
-
setServerLoaderData((d) => ({ ...d, [id]: data }));
|
|
123
|
-
});
|
|
124
|
-
})
|
|
125
|
-
.catch(console.error);
|
|
126
|
-
}
|
|
127
|
-
// client loader
|
|
128
|
-
// onPatchClientRoutes 添加的 route 在 opts.routes 里是不存在的
|
|
129
|
-
const clientLoader = (_a = opts.routes[id]) === null || _a === void 0 ? void 0 : _a.clientLoader;
|
|
130
|
-
if (clientLoader && !clientLoaderData[id]) {
|
|
131
|
-
clientLoader().then((data) => {
|
|
132
|
-
setClientLoaderData((d) => ({ ...d, [id]: data }));
|
|
133
|
-
});
|
|
134
|
-
}
|
|
121
|
+
var manifest = window.__umi_manifest__;
|
|
122
|
+
|
|
123
|
+
if (manifest) {
|
|
124
|
+
var routeIdReplaced = id.replace(/[\/\-]/g, '_');
|
|
125
|
+
var preloadId = "preload-".concat(routeIdReplaced, ".js");
|
|
126
|
+
|
|
127
|
+
if (!document.getElementById(preloadId)) {
|
|
128
|
+
var keys = Object.keys(manifest).filter(function (k) {
|
|
129
|
+
return k.startsWith(routeIdReplaced + '.');
|
|
135
130
|
});
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
131
|
+
keys.forEach(function (key) {
|
|
132
|
+
if (!/\.(js|css)$/.test(key)) {
|
|
133
|
+
throw Error("preload not support ".concat(key, " file"));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
var file = manifest[key];
|
|
137
|
+
var link = document.createElement('link');
|
|
138
|
+
link.rel = 'preload';
|
|
139
|
+
link.as = 'style';
|
|
140
|
+
|
|
141
|
+
if (key.endsWith('.js')) {
|
|
142
|
+
link.as = 'script';
|
|
143
|
+
link.id = preloadId;
|
|
144
|
+
} // publicPath already in the manifest,
|
|
145
|
+
// but if runtimePublicPath is true, we need to replace it
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
if (opts.runtimePublicPath) {
|
|
149
|
+
file = file.replace(new RegExp("^".concat(opts.publicPath)), // @ts-ignore
|
|
150
|
+
window.publicPath);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
link.href = file;
|
|
154
|
+
document.head.appendChild(link);
|
|
141
155
|
});
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
156
|
+
}
|
|
157
|
+
} // server loader
|
|
158
|
+
// use ?. since routes patched with patchClientRoutes is not exists in opts.routes
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
if (!isFirst && (_opts$routes$id = opts.routes[id]) !== null && _opts$routes$id !== void 0 && _opts$routes$id.hasServerLoader) {
|
|
162
|
+
fetch('/__serverLoader?route=' + id).then(function (d) {
|
|
163
|
+
return d.json();
|
|
164
|
+
}).then(function (data) {
|
|
165
|
+
// setServerLoaderData when startTransition because if ssr is enabled,
|
|
166
|
+
// the component may being hydrated and setLoaderData will break the hydration
|
|
167
|
+
React.startTransition(function () {
|
|
168
|
+
setServerLoaderData(function (d) {
|
|
169
|
+
return _objectSpread(_objectSpread({}, d), {}, _defineProperty({}, id, data));
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
}).catch(console.error);
|
|
173
|
+
} // client loader
|
|
174
|
+
// onPatchClientRoutes 添加的 route 在 opts.routes 里是不存在的
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
var clientLoader = (_opts$routes$id2 = opts.routes[id]) === null || _opts$routes$id2 === void 0 ? void 0 : _opts$routes$id2.clientLoader;
|
|
178
|
+
|
|
179
|
+
if (clientLoader && !clientLoaderData[id]) {
|
|
180
|
+
clientLoader().then(function (data) {
|
|
181
|
+
setClientLoaderData(function (d) {
|
|
182
|
+
return _objectSpread(_objectSpread({}, d), {}, _defineProperty({}, id, data));
|
|
183
|
+
});
|
|
184
|
+
});
|
|
165
185
|
}
|
|
186
|
+
});
|
|
187
|
+
}, [clientLoaderData]);
|
|
188
|
+
useEffect(function () {
|
|
189
|
+
handleRouteChange(window.location.pathname, true);
|
|
190
|
+
return opts.history.listen(function (e) {
|
|
191
|
+
handleRouteChange(e.location.pathname);
|
|
192
|
+
});
|
|
193
|
+
}, []);
|
|
194
|
+
return /*#__PURE__*/_jsx(AppContext.Provider, {
|
|
195
|
+
value: {
|
|
196
|
+
routes: opts.routes,
|
|
197
|
+
routeComponents: opts.routeComponents,
|
|
198
|
+
clientRoutes: clientRoutes,
|
|
199
|
+
pluginManager: opts.pluginManager,
|
|
200
|
+
rootElement: opts.rootElement,
|
|
201
|
+
basename: basename,
|
|
202
|
+
clientLoaderData: clientLoaderData,
|
|
203
|
+
serverLoaderData: serverLoaderData,
|
|
204
|
+
preloadRoute: handleRouteChange
|
|
205
|
+
},
|
|
206
|
+
children: rootContainer
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
if (opts.hydrate) {
|
|
211
|
+
ReactDOM.hydrateRoot(rootElement, /*#__PURE__*/_jsx(Browser, {}));
|
|
212
|
+
} else {
|
|
213
|
+
if (ReactDOM.createRoot) {
|
|
214
|
+
ReactDOM.createRoot(rootElement).render( /*#__PURE__*/_jsx(Browser, {}));
|
|
215
|
+
} else {
|
|
216
|
+
// @ts-ignore
|
|
217
|
+
ReactDOM.render( /*#__PURE__*/_jsx(Browser, {}), rootElement);
|
|
166
218
|
}
|
|
167
|
-
}
|
|
219
|
+
}
|
|
220
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export { createBrowserHistory, createHashHistory, createMemoryHistory, History, } from 'history';
|
|
1
|
+
export { createBrowserHistory, createHashHistory, createMemoryHistory, type History, } from 'history';
|
|
2
2
|
export { createSearchParams, matchPath, matchRoutes, Navigate, NavLink, Outlet, resolvePath, useLocation, useMatch, useNavigate, useOutlet, useOutletContext, useParams, useResolvedPath, useRoutes, useSearchParams, } from 'react-router-dom';
|
|
3
3
|
export { useAppData, useClientLoaderData, useServerLoaderData, } from './appContext';
|
|
4
4
|
export { renderClient } from './browser';
|
|
5
5
|
export { LinkWithPrefetch as Link } from './link';
|
|
6
6
|
export { useRouteData } from './routeContext';
|
|
7
7
|
export { __useFetcher } from './useFetcher';
|
|
8
|
+
export { withRouter, type RouteComponentProps } from './withRouter';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export { createBrowserHistory, createHashHistory, createMemoryHistory
|
|
2
|
-
export { createSearchParams, matchPath, matchRoutes, Navigate, NavLink, Outlet, resolvePath, useLocation, useMatch, useNavigate, useOutlet, useOutletContext, useParams, useResolvedPath, useRoutes, useSearchParams
|
|
3
|
-
export { useAppData, useClientLoaderData, useServerLoaderData
|
|
4
|
-
export { renderClient } from
|
|
5
|
-
export { LinkWithPrefetch as Link } from
|
|
6
|
-
export { useRouteData } from
|
|
7
|
-
export { __useFetcher } from
|
|
1
|
+
export { createBrowserHistory, createHashHistory, createMemoryHistory } from 'history';
|
|
2
|
+
export { createSearchParams, matchPath, matchRoutes, Navigate, NavLink, Outlet, resolvePath, useLocation, useMatch, useNavigate, useOutlet, useOutletContext, useParams, useResolvedPath, useRoutes, useSearchParams } from 'react-router-dom';
|
|
3
|
+
export { useAppData, useClientLoaderData, useServerLoaderData } from "./appContext";
|
|
4
|
+
export { renderClient } from "./browser";
|
|
5
|
+
export { LinkWithPrefetch as Link } from "./link";
|
|
6
|
+
export { useRouteData } from "./routeContext";
|
|
7
|
+
export { __useFetcher } from "./useFetcher";
|
|
8
|
+
export { withRouter } from "./withRouter";
|
package/dist/link.d.ts
CHANGED
|
File without changes
|
package/dist/link.js
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
|
1
2
|
import React from 'react';
|
|
2
3
|
import { Link } from 'react-router-dom';
|
|
3
|
-
import { useAppData } from
|
|
4
|
+
import { useAppData } from "./appContext";
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
6
|
export function LinkWithPrefetch(props) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
var appData = useAppData();
|
|
8
|
+
var to = typeof props.to === 'string' ? props.to : props.to.pathname;
|
|
9
|
+
return /*#__PURE__*/_jsx(Link, _objectSpread(_objectSpread({
|
|
10
|
+
onMouseEnter: function onMouseEnter() {
|
|
11
|
+
var _appData$preloadRoute;
|
|
12
|
+
|
|
13
|
+
return props.prefetch && to && ((_appData$preloadRoute = appData.preloadRoute) === null || _appData$preloadRoute === void 0 ? void 0 : _appData$preloadRoute.call(appData, to));
|
|
14
|
+
}
|
|
15
|
+
}, props), {}, {
|
|
16
|
+
children: props.children
|
|
17
|
+
}));
|
|
18
|
+
}
|
package/dist/routeContext.d.ts
CHANGED
|
File without changes
|
package/dist/routeContext.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
export
|
|
2
|
+
export var RouteContext = /*#__PURE__*/React.createContext(undefined);
|
|
3
3
|
export function useRouteData() {
|
|
4
|
-
|
|
5
|
-
}
|
|
4
|
+
return React.useContext(RouteContext);
|
|
5
|
+
}
|
package/dist/routes.d.ts
CHANGED
|
File without changes
|
package/dist/routes.js
CHANGED
|
@@ -1,68 +1,91 @@
|
|
|
1
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
2
|
+
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
|
3
|
+
var _excluded = ["redirect"];
|
|
1
4
|
// @ts-ignore
|
|
2
5
|
import React from 'react';
|
|
3
6
|
import { generatePath, Navigate, useParams } from 'react-router-dom';
|
|
4
|
-
import { RouteContext } from
|
|
7
|
+
import { RouteContext } from "./routeContext";
|
|
8
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
9
|
export function createClientRoutes(opts) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
routesById,
|
|
17
|
-
routeComponents,
|
|
18
|
-
parentId: route.id,
|
|
19
|
-
loadingComponent: opts.loadingComponent,
|
|
20
|
-
});
|
|
21
|
-
if (children.length > 0) {
|
|
22
|
-
route.children = children;
|
|
23
|
-
// TODO: remove me
|
|
24
|
-
// compatible with @ant-design/pro-layout
|
|
25
|
-
route.routes = children;
|
|
26
|
-
}
|
|
27
|
-
return route;
|
|
10
|
+
var routesById = opts.routesById,
|
|
11
|
+
parentId = opts.parentId,
|
|
12
|
+
routeComponents = opts.routeComponents;
|
|
13
|
+
return Object.keys(routesById).filter(function (id) {
|
|
14
|
+
return routesById[id].parentId === parentId;
|
|
15
|
+
}).map(function (id) {
|
|
16
|
+
var route = createClientRoute({
|
|
17
|
+
route: routesById[id],
|
|
18
|
+
routeComponent: routeComponents[id],
|
|
19
|
+
loadingComponent: opts.loadingComponent
|
|
28
20
|
});
|
|
21
|
+
var children = createClientRoutes({
|
|
22
|
+
routesById: routesById,
|
|
23
|
+
routeComponents: routeComponents,
|
|
24
|
+
parentId: route.id,
|
|
25
|
+
loadingComponent: opts.loadingComponent
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
if (children.length > 0) {
|
|
29
|
+
route.children = children; // TODO: remove me
|
|
30
|
+
// compatible with @ant-design/pro-layout
|
|
31
|
+
|
|
32
|
+
route.routes = children;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return route;
|
|
36
|
+
});
|
|
29
37
|
}
|
|
38
|
+
|
|
30
39
|
function NavigateWithParams(props) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
var params = useParams();
|
|
41
|
+
|
|
42
|
+
var propsWithParams = _objectSpread(_objectSpread({}, props), {}, {
|
|
43
|
+
to: generatePath(props.to, params)
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
return /*#__PURE__*/_jsx(Navigate, _objectSpread({}, propsWithParams));
|
|
37
47
|
}
|
|
48
|
+
|
|
38
49
|
function createClientRoute(opts) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
50
|
+
var route = opts.route;
|
|
51
|
+
|
|
52
|
+
var redirect = route.redirect,
|
|
53
|
+
props = _objectWithoutProperties(route, _excluded);
|
|
54
|
+
|
|
55
|
+
return _objectSpread({
|
|
56
|
+
element: redirect ? /*#__PURE__*/_jsx(NavigateWithParams, {
|
|
57
|
+
to: redirect
|
|
58
|
+
}) : /*#__PURE__*/_jsx(RouteContext.Provider, {
|
|
59
|
+
value: {
|
|
60
|
+
route: opts.route
|
|
61
|
+
},
|
|
62
|
+
children: /*#__PURE__*/_jsx(RemoteComponent, {
|
|
63
|
+
loader: opts.routeComponent,
|
|
64
|
+
loadingComponent: opts.loadingComponent || DefaultLoading
|
|
65
|
+
})
|
|
66
|
+
})
|
|
67
|
+
}, props);
|
|
48
68
|
}
|
|
69
|
+
|
|
49
70
|
function DefaultLoading() {
|
|
50
|
-
|
|
71
|
+
return /*#__PURE__*/_jsx("div", {});
|
|
51
72
|
}
|
|
73
|
+
|
|
52
74
|
function RemoteComponent(props) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
75
|
+
var useSuspense = true; // !!React.startTransition;
|
|
76
|
+
|
|
77
|
+
if (useSuspense) {
|
|
78
|
+
var Component = props.loader;
|
|
79
|
+
return /*#__PURE__*/_jsx(React.Suspense, {
|
|
80
|
+
fallback: /*#__PURE__*/_jsx(props.loadingComponent, {}),
|
|
81
|
+
children: /*#__PURE__*/_jsx(Component, {})
|
|
82
|
+
});
|
|
83
|
+
} else {
|
|
84
|
+
return null; // // @ts-ignore
|
|
85
|
+
// import loadable from '@loadable/component';
|
|
86
|
+
// const Component = loadable(props.loader, {
|
|
87
|
+
// fallback: <props.loadingComponent />,
|
|
88
|
+
// });
|
|
89
|
+
// return <Component />;
|
|
90
|
+
}
|
|
91
|
+
}
|
package/dist/server.d.ts
CHANGED
|
File without changes
|
package/dist/server.js
CHANGED
|
@@ -1,59 +1,107 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
1
4
|
import React from 'react';
|
|
2
5
|
import { StaticRouter } from 'react-router-dom/server';
|
|
3
|
-
import { AppContext } from
|
|
4
|
-
import { Routes } from
|
|
5
|
-
import { createClientRoutes } from
|
|
6
|
+
import { AppContext } from "./appContext";
|
|
7
|
+
import { Routes } from "./browser";
|
|
8
|
+
import { createClientRoutes } from "./routes";
|
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
6
11
|
// Get the root React component for ReactDOMServer.renderToString
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
const components = { ...opts.routeComponents };
|
|
10
|
-
const clientRoutes = createClientRoutes({
|
|
11
|
-
routesById: opts.routes,
|
|
12
|
-
routeComponents: components,
|
|
13
|
-
});
|
|
14
|
-
let rootContainer = (React.createElement(StaticRouter, { basename: basename, location: opts.location },
|
|
15
|
-
React.createElement(Routes, null)));
|
|
16
|
-
for (const key of [
|
|
17
|
-
// Lowest to the highest priority
|
|
18
|
-
'innerProvider',
|
|
19
|
-
'i18nProvider',
|
|
20
|
-
'accessProvider',
|
|
21
|
-
'dataflowProvider',
|
|
22
|
-
'outerProvider',
|
|
23
|
-
'rootContainer',
|
|
24
|
-
]) {
|
|
25
|
-
rootContainer = opts.pluginManager.applyPlugins({
|
|
26
|
-
type: 'modify',
|
|
27
|
-
key: key,
|
|
28
|
-
initialValue: rootContainer,
|
|
29
|
-
args: {},
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
return (React.createElement(Html, { loaderData: opts.loaderData, manifest: opts.manifest },
|
|
33
|
-
React.createElement(AppContext.Provider, { value: {
|
|
34
|
-
routes: opts.routes,
|
|
35
|
-
routeComponents: opts.routeComponents,
|
|
36
|
-
clientRoutes,
|
|
37
|
-
pluginManager: opts.pluginManager,
|
|
38
|
-
basename,
|
|
39
|
-
clientLoaderData: {},
|
|
40
|
-
serverLoaderData: opts.loaderData,
|
|
41
|
-
} }, rootContainer)));
|
|
12
|
+
export function getClientRootComponent(_x) {
|
|
13
|
+
return _getClientRootComponent.apply(this, arguments);
|
|
42
14
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
15
|
+
|
|
16
|
+
function _getClientRootComponent() {
|
|
17
|
+
_getClientRootComponent = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(opts) {
|
|
18
|
+
var basename, components, clientRoutes, rootContainer, _i, _arr, key;
|
|
19
|
+
|
|
20
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
21
|
+
while (1) {
|
|
22
|
+
switch (_context.prev = _context.next) {
|
|
23
|
+
case 0:
|
|
24
|
+
basename = '/';
|
|
25
|
+
components = _objectSpread({}, opts.routeComponents);
|
|
26
|
+
clientRoutes = createClientRoutes({
|
|
27
|
+
routesById: opts.routes,
|
|
28
|
+
routeComponents: components
|
|
29
|
+
});
|
|
30
|
+
rootContainer = /*#__PURE__*/_jsx(StaticRouter, {
|
|
31
|
+
basename: basename,
|
|
32
|
+
location: opts.location,
|
|
33
|
+
children: /*#__PURE__*/_jsx(Routes, {})
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
for (_i = 0, _arr = [// Lowest to the highest priority
|
|
37
|
+
'innerProvider', 'i18nProvider', 'accessProvider', 'dataflowProvider', 'outerProvider', 'rootContainer']; _i < _arr.length; _i++) {
|
|
38
|
+
key = _arr[_i];
|
|
39
|
+
rootContainer = opts.pluginManager.applyPlugins({
|
|
40
|
+
type: 'modify',
|
|
41
|
+
key: key,
|
|
42
|
+
initialValue: rootContainer,
|
|
43
|
+
args: {}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return _context.abrupt("return", /*#__PURE__*/_jsx(Html, {
|
|
48
|
+
loaderData: opts.loaderData,
|
|
49
|
+
manifest: opts.manifest,
|
|
50
|
+
children: /*#__PURE__*/_jsx(AppContext.Provider, {
|
|
51
|
+
value: {
|
|
52
|
+
routes: opts.routes,
|
|
53
|
+
routeComponents: opts.routeComponents,
|
|
54
|
+
clientRoutes: clientRoutes,
|
|
55
|
+
pluginManager: opts.pluginManager,
|
|
56
|
+
basename: basename,
|
|
57
|
+
clientLoaderData: {},
|
|
58
|
+
serverLoaderData: opts.loaderData
|
|
59
|
+
},
|
|
60
|
+
children: rootContainer
|
|
61
|
+
})
|
|
62
|
+
}));
|
|
63
|
+
|
|
64
|
+
case 6:
|
|
65
|
+
case "end":
|
|
66
|
+
return _context.stop();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}, _callee);
|
|
70
|
+
}));
|
|
71
|
+
return _getClientRootComponent.apply(this, arguments);
|
|
59
72
|
}
|
|
73
|
+
|
|
74
|
+
function Html(_ref) {
|
|
75
|
+
var children = _ref.children,
|
|
76
|
+
loaderData = _ref.loaderData,
|
|
77
|
+
manifest = _ref.manifest;
|
|
78
|
+
// TODO: 处理 head 标签,比如 favicon.ico 的一致性
|
|
79
|
+
// TODO: root 支持配置
|
|
80
|
+
return /*#__PURE__*/_jsxs("html", {
|
|
81
|
+
lang: "en",
|
|
82
|
+
children: [/*#__PURE__*/_jsxs("head", {
|
|
83
|
+
children: [/*#__PURE__*/_jsx("meta", {
|
|
84
|
+
charSet: "utf-8"
|
|
85
|
+
}), /*#__PURE__*/_jsx("meta", {
|
|
86
|
+
name: "viewport",
|
|
87
|
+
content: "width=device-width, initial-scale=1"
|
|
88
|
+
}), manifest.assets['umi.css'] && /*#__PURE__*/_jsx("link", {
|
|
89
|
+
rel: "stylesheet",
|
|
90
|
+
href: manifest.assets['umi.css']
|
|
91
|
+
})]
|
|
92
|
+
}), /*#__PURE__*/_jsxs("body", {
|
|
93
|
+
children: [/*#__PURE__*/_jsx("noscript", {
|
|
94
|
+
dangerouslySetInnerHTML: {
|
|
95
|
+
__html: "<b>Enable JavaScript to run this app.</b>"
|
|
96
|
+
}
|
|
97
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
98
|
+
id: "root",
|
|
99
|
+
children: children
|
|
100
|
+
}), /*#__PURE__*/_jsx("script", {
|
|
101
|
+
dangerouslySetInnerHTML: {
|
|
102
|
+
__html: "window.__UMI_LOADER_DATA__ = ".concat(JSON.stringify(loaderData))
|
|
103
|
+
}
|
|
104
|
+
})]
|
|
105
|
+
})]
|
|
106
|
+
});
|
|
107
|
+
}
|
package/dist/types.d.ts
CHANGED
|
File without changes
|
package/dist/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/dist/useFetcher.d.ts
CHANGED
package/dist/useFetcher.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { useLocation } from 'react-router-dom';
|
|
2
|
-
import { useAppData } from
|
|
2
|
+
import { useAppData } from "./appContext";
|
|
3
3
|
export function __useFetcher() {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
4
|
+
var _useAppData = useAppData(),
|
|
5
|
+
preloadRoute = _useAppData.preloadRoute;
|
|
6
|
+
|
|
7
|
+
var location = useLocation();
|
|
8
|
+
return {
|
|
9
|
+
load: function load(path) {
|
|
10
|
+
preloadRoute(path || location.pathname);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -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,43 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { useLocation, useNavigate, useParams } from 'react-router-dom';
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
+
export function withRouter(Component) {
|
|
6
|
+
function ComponentWithRouterProp(props) {
|
|
7
|
+
var location = useLocation();
|
|
8
|
+
var navigate = useNavigate();
|
|
9
|
+
var params = useParams();
|
|
10
|
+
var match = {
|
|
11
|
+
params: params
|
|
12
|
+
};
|
|
13
|
+
var history = {
|
|
14
|
+
back: function back() {
|
|
15
|
+
return navigate(-1);
|
|
16
|
+
},
|
|
17
|
+
goBack: function goBack() {
|
|
18
|
+
return navigate(-1);
|
|
19
|
+
},
|
|
20
|
+
location: location,
|
|
21
|
+
push: function push(url, state) {
|
|
22
|
+
return navigate(url, {
|
|
23
|
+
state: state
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
replace: function replace(url, state) {
|
|
27
|
+
return navigate(url, {
|
|
28
|
+
replace: true,
|
|
29
|
+
state: state
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
return /*#__PURE__*/_jsx(Component, _objectSpread(_objectSpread({}, props), {}, {
|
|
34
|
+
history: history,
|
|
35
|
+
location: location,
|
|
36
|
+
match: match,
|
|
37
|
+
params: params,
|
|
38
|
+
navigate: navigate
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return ComponentWithRouterProp;
|
|
43
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/renderer-react",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.8",
|
|
4
4
|
"description": "@umijs/renderer-react",
|
|
5
5
|
"homepage": "https://github.com/umijs/umi/tree/master/packages/renderer-react#readme",
|
|
6
6
|
"bugs": "https://github.com/umijs/umi/issues",
|
|
@@ -16,12 +16,13 @@
|
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
18
|
"scripts": {
|
|
19
|
-
"build": "pnpm
|
|
19
|
+
"build": "pnpm father build",
|
|
20
20
|
"build:deps": "umi-scripts bundleDeps",
|
|
21
|
-
"dev": "pnpm
|
|
21
|
+
"dev": "pnpm father dev",
|
|
22
22
|
"test": "umi-scripts jest-turbo"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
+
"@babel/runtime": "7.17.9",
|
|
25
26
|
"@loadable/component": "5.15.2",
|
|
26
27
|
"history": "5.3.0",
|
|
27
28
|
"react-router-dom": "6.3.0"
|