@umijs/renderer-react 4.0.0-beta.7 → 4.0.0-rc.2
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 +2 -8
- package/dist/appContext.js +2 -2
- package/dist/browser.d.ts +7 -7
- package/dist/browser.js +64 -18
- package/dist/index.d.ts +5 -2
- package/dist/index.js +5 -2
- package/dist/routeContext.d.ts +6 -0
- package/dist/routeContext.js +5 -0
- package/dist/routes.d.ts +7 -3
- package/dist/routes.js +39 -10
- package/dist/types.d.ts +4 -0
- package/package.json +20 -19
- package/dist/app.d.ts +0 -14
- package/dist/app.js +0 -35
package/dist/appContext.d.ts
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
routeComponents: any;
|
|
5
|
-
clientRoutes: any;
|
|
6
|
-
pluginManager: any;
|
|
7
|
-
}
|
|
8
|
-
export declare const AppContext: React.Context<IAppContextType | undefined>;
|
|
9
|
-
export declare function useAppContext(): IAppContextType;
|
|
2
|
+
export declare const AppContext: React.Context<any>;
|
|
3
|
+
export declare function useAppData(): any;
|
package/dist/appContext.js
CHANGED
package/dist/browser.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
routeComponents: Record<string, any>;
|
|
5
|
-
pluginManager: any;
|
|
6
|
-
}): any;
|
|
1
|
+
import { History } from 'history';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { IRouteComponents, IRoutesById } from './types';
|
|
7
4
|
export declare function renderClient(opts: {
|
|
8
5
|
rootElement?: HTMLElement;
|
|
9
6
|
routes: IRoutesById;
|
|
10
|
-
routeComponents:
|
|
7
|
+
routeComponents: IRouteComponents;
|
|
11
8
|
pluginManager: any;
|
|
9
|
+
basename?: string;
|
|
10
|
+
loadingComponent?: React.ReactNode;
|
|
11
|
+
history: History;
|
|
12
12
|
}): void;
|
package/dist/browser.js
CHANGED
|
@@ -1,27 +1,73 @@
|
|
|
1
|
-
import { createBrowserHistory } from 'history';
|
|
2
1
|
import React from 'react';
|
|
3
2
|
import ReactDOM from 'react-dom';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const history = historyRef.current;
|
|
11
|
-
const [state, dispatch] = React.useReducer((_, update) => update, {
|
|
3
|
+
import { Router, useRoutes } from 'react-router-dom';
|
|
4
|
+
import { AppContext, useAppData } from './appContext';
|
|
5
|
+
import { createClientRoutes } from './routes';
|
|
6
|
+
function BrowserRoutes(props) {
|
|
7
|
+
const { history } = props;
|
|
8
|
+
const [state, setState] = React.useState({
|
|
12
9
|
action: history.action,
|
|
13
10
|
location: history.location,
|
|
14
11
|
});
|
|
15
|
-
React.useLayoutEffect(() => history.listen(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
React.useLayoutEffect(() => history.listen(setState), [history]);
|
|
13
|
+
React.useLayoutEffect(() => history.listen((location, action) => {
|
|
14
|
+
props.pluginManager.applyPlugins({
|
|
15
|
+
key: 'onRouteChange',
|
|
16
|
+
type: 'event',
|
|
17
|
+
args: {
|
|
18
|
+
routes: props.routes,
|
|
19
|
+
clientRoutes: props.clientRoutes,
|
|
20
|
+
location,
|
|
21
|
+
action,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
}), [history, props.routes, props.clientRoutes]);
|
|
25
|
+
return (React.createElement(Router, { navigator: history, location: state.location, basename: props.basename }, props.children));
|
|
26
|
+
}
|
|
27
|
+
function Routes() {
|
|
28
|
+
const { clientRoutes } = useAppData();
|
|
29
|
+
return useRoutes(clientRoutes);
|
|
22
30
|
}
|
|
23
31
|
export function renderClient(opts) {
|
|
32
|
+
const basename = opts.basename || '/';
|
|
33
|
+
const rootElement = opts.rootElement || document.getElementById('root');
|
|
34
|
+
const clientRoutes = createClientRoutes({
|
|
35
|
+
routesById: opts.routes,
|
|
36
|
+
routeComponents: opts.routeComponents,
|
|
37
|
+
loadingComponent: opts.loadingComponent,
|
|
38
|
+
});
|
|
39
|
+
let rootContainer = (React.createElement(BrowserRoutes, { basename: basename, pluginManager: opts.pluginManager, routes: opts.routes, clientRoutes: clientRoutes, history: opts.history },
|
|
40
|
+
React.createElement(Routes, null)));
|
|
41
|
+
for (const key of [
|
|
42
|
+
// Lowest to the highest priority
|
|
43
|
+
'innerProvider',
|
|
44
|
+
'i18nProvider',
|
|
45
|
+
'accessProvider',
|
|
46
|
+
'dataflowProvider',
|
|
47
|
+
'outerProvider',
|
|
48
|
+
'rootContainer',
|
|
49
|
+
]) {
|
|
50
|
+
rootContainer = opts.pluginManager.applyPlugins({
|
|
51
|
+
type: 'modify',
|
|
52
|
+
key: key,
|
|
53
|
+
initialValue: rootContainer,
|
|
54
|
+
args: {},
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const browser = (React.createElement(AppContext.Provider, { value: {
|
|
58
|
+
routes: opts.routes,
|
|
59
|
+
routeComponents: opts.routeComponents,
|
|
60
|
+
clientRoutes,
|
|
61
|
+
pluginManager: opts.pluginManager,
|
|
62
|
+
rootElement: opts.rootElement,
|
|
63
|
+
basename,
|
|
64
|
+
} }, rootContainer));
|
|
24
65
|
// @ts-ignore
|
|
25
|
-
|
|
26
|
-
|
|
66
|
+
if (ReactDOM.createRoot) {
|
|
67
|
+
// @ts-ignore
|
|
68
|
+
ReactDOM.createRoot(rootElement).render(browser);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
ReactDOM.render(browser, rootElement);
|
|
72
|
+
}
|
|
27
73
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export
|
|
1
|
+
export { createBrowserHistory, createHashHistory, createMemoryHistory, History, } from 'history';
|
|
2
|
+
export { createSearchParams, Link, matchPath, matchRoutes, NavLink, Outlet, useLocation, useMatch, useNavigate, useOutlet, useParams, useResolvedPath, useRoutes, useSearchParams, } from 'react-router-dom';
|
|
3
|
+
export { useAppData } from './appContext';
|
|
4
|
+
export { renderClient } from './browser';
|
|
5
|
+
export { useRouteData } from './routeContext';
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export
|
|
1
|
+
export { createBrowserHistory, createHashHistory, createMemoryHistory, } from 'history';
|
|
2
|
+
export { createSearchParams, Link, matchPath, matchRoutes, NavLink, Outlet, useLocation, useMatch, useNavigate, useOutlet, useParams, useResolvedPath, useRoutes, useSearchParams, } from 'react-router-dom';
|
|
3
|
+
export { useAppData } from './appContext';
|
|
4
|
+
export { renderClient } from './browser';
|
|
5
|
+
export { useRouteData } from './routeContext';
|
package/dist/routes.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { IRoute, 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
|
+
loadingComponent?: React.ReactNode;
|
|
7
8
|
}): {
|
|
9
|
+
parentId?: string | undefined;
|
|
8
10
|
id: string;
|
|
9
11
|
path: string | undefined;
|
|
10
12
|
index: boolean | undefined;
|
|
@@ -12,8 +14,10 @@ export declare function createClientRoutes(opts: {
|
|
|
12
14
|
}[];
|
|
13
15
|
export declare function createClientRoute(opts: {
|
|
14
16
|
route: IRoute;
|
|
15
|
-
|
|
17
|
+
routeComponent: any;
|
|
18
|
+
loadingComponent?: React.ReactNode;
|
|
16
19
|
}): {
|
|
20
|
+
parentId?: string | undefined;
|
|
17
21
|
id: string;
|
|
18
22
|
path: string | undefined;
|
|
19
23
|
index: boolean | undefined;
|
package/dist/routes.js
CHANGED
|
@@ -1,31 +1,60 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
import loadable from '@loadable/component';
|
|
1
14
|
import React from 'react';
|
|
15
|
+
import { Navigate } from 'react-router-dom';
|
|
16
|
+
import { RouteContext } from './routeContext';
|
|
2
17
|
export function createClientRoutes(opts) {
|
|
3
|
-
const { routesById, parentId,
|
|
18
|
+
const { routesById, parentId, routeComponents } = opts;
|
|
4
19
|
return Object.keys(routesById)
|
|
5
20
|
.filter((id) => routesById[id].parentId === parentId)
|
|
6
21
|
.map((id) => {
|
|
7
22
|
const route = createClientRoute({
|
|
8
23
|
route: routesById[id],
|
|
9
|
-
|
|
24
|
+
routeComponent: routeComponents[id],
|
|
25
|
+
loadingComponent: opts.loadingComponent,
|
|
10
26
|
});
|
|
11
27
|
const children = createClientRoutes({
|
|
12
28
|
routesById,
|
|
29
|
+
routeComponents,
|
|
13
30
|
parentId: route.id,
|
|
14
|
-
|
|
31
|
+
loadingComponent: opts.loadingComponent,
|
|
15
32
|
});
|
|
16
33
|
if (children.length > 0) {
|
|
17
34
|
// @ts-ignore
|
|
18
35
|
route.children = children;
|
|
36
|
+
// TODO: remove me
|
|
37
|
+
// compatible with @ant-design/pro-layout
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
route.routes = children;
|
|
19
40
|
}
|
|
20
41
|
return route;
|
|
21
42
|
});
|
|
22
43
|
}
|
|
23
44
|
export function createClientRoute(opts) {
|
|
24
|
-
const { route
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
45
|
+
const { route } = opts;
|
|
46
|
+
const { id, path, index, redirect } = route, props = __rest(route, ["id", "path", "index", "redirect"]);
|
|
47
|
+
return Object.assign({ id: id, path: path, index: index, element: redirect ? (React.createElement(Navigate, { to: redirect })) : (React.createElement(RouteContext.Provider, { value: {
|
|
48
|
+
route: opts.route,
|
|
49
|
+
} },
|
|
50
|
+
React.createElement(RemoteComponent, { loader: opts.routeComponent, loadingComponent: opts.loadingComponent || DefaultLoading }))) }, props);
|
|
51
|
+
}
|
|
52
|
+
function DefaultLoading() {
|
|
53
|
+
return React.createElement("div", null, "Loading...");
|
|
54
|
+
}
|
|
55
|
+
function RemoteComponent(props) {
|
|
56
|
+
const Component = loadable(props.loader, {
|
|
57
|
+
fallback: React.createElement(props.loadingComponent, null),
|
|
58
|
+
});
|
|
59
|
+
return React.createElement(Component, null);
|
|
31
60
|
}
|
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/renderer-react",
|
|
3
|
-
"version": "4.0.0-
|
|
3
|
+
"version": "4.0.0-rc.2",
|
|
4
4
|
"description": "@umijs/renderer-react",
|
|
5
|
+
"homepage": "https://github.com/umijs/umi-next/tree/master/packages/renderer-react#readme",
|
|
6
|
+
"bugs": "https://github.com/umijs/umi-next/issues",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/umijs/umi-next"
|
|
10
|
+
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"sideEffects": false,
|
|
5
13
|
"main": "dist/index.js",
|
|
6
14
|
"types": "dist/index.d.ts",
|
|
7
15
|
"files": [
|
|
@@ -12,30 +20,23 @@
|
|
|
12
20
|
"build:deps": "pnpm esno ../../scripts/bundleDeps.ts",
|
|
13
21
|
"dev": "pnpm build -- --watch"
|
|
14
22
|
},
|
|
15
|
-
"repository": {
|
|
16
|
-
"type": "git",
|
|
17
|
-
"url": "https://github.com/umijs/umi-next"
|
|
18
|
-
},
|
|
19
|
-
"authors": [
|
|
20
|
-
"chencheng <sorrycc@gmail.com> (https://github.com/sorrycc)"
|
|
21
|
-
],
|
|
22
|
-
"license": "MIT",
|
|
23
|
-
"bugs": "https://github.com/umijs/umi-next/issues",
|
|
24
|
-
"homepage": "https://github.com/umijs/umi-next/tree/master/packages/renderer-react#readme",
|
|
25
|
-
"publishConfig": {
|
|
26
|
-
"access": "public"
|
|
27
|
-
},
|
|
28
23
|
"dependencies": {
|
|
29
|
-
"
|
|
30
|
-
"
|
|
24
|
+
"@loadable/component": "5.15.2",
|
|
25
|
+
"history": "5.2.0",
|
|
26
|
+
"react-router-dom": "6.2.1"
|
|
31
27
|
},
|
|
32
28
|
"devDependencies": {
|
|
33
|
-
"react": "
|
|
34
|
-
"react-dom": "
|
|
29
|
+
"react": "17.0.2",
|
|
30
|
+
"react-dom": "17.0.2"
|
|
35
31
|
},
|
|
36
32
|
"peerDependencies": {
|
|
37
33
|
"react": ">=16.8",
|
|
38
34
|
"react-dom": ">=16.8"
|
|
39
35
|
},
|
|
40
|
-
"
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
},
|
|
39
|
+
"authors": [
|
|
40
|
+
"chencheng <sorrycc@gmail.com> (https://github.com/sorrycc)"
|
|
41
|
+
]
|
|
41
42
|
}
|
package/dist/app.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { Location } from 'history';
|
|
3
|
-
import { Navigator } from 'react-router-dom';
|
|
4
|
-
import { IRoutesById } from './types';
|
|
5
|
-
export declare function App(props: {
|
|
6
|
-
navigator: Navigator;
|
|
7
|
-
location: Location;
|
|
8
|
-
routes: IRoutesById;
|
|
9
|
-
routeComponents: Record<string, any>;
|
|
10
|
-
pluginManager: any;
|
|
11
|
-
}): JSX.Element;
|
|
12
|
-
export declare function RouteComponent(props: {
|
|
13
|
-
id: string;
|
|
14
|
-
}): JSX.Element;
|
package/dist/app.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Router, useRoutes } from 'react-router-dom';
|
|
3
|
-
import { AppContext, useAppContext } from './appContext';
|
|
4
|
-
import { createClientRoutes } from './routes';
|
|
5
|
-
export function App(props) {
|
|
6
|
-
const clientRoutes = React.useMemo(() => {
|
|
7
|
-
return createClientRoutes({
|
|
8
|
-
routesById: props.routes,
|
|
9
|
-
Component: RouteComponent,
|
|
10
|
-
});
|
|
11
|
-
}, [props.routes]);
|
|
12
|
-
return (React.createElement(AppContext.Provider, { value: {
|
|
13
|
-
routes: props.routes,
|
|
14
|
-
routeComponents: props.routeComponents,
|
|
15
|
-
pluginManager: props.pluginManager,
|
|
16
|
-
clientRoutes,
|
|
17
|
-
} },
|
|
18
|
-
React.createElement(Router, { navigator: props.navigator, location: props.location },
|
|
19
|
-
React.createElement(Routes, null))));
|
|
20
|
-
}
|
|
21
|
-
function Routes() {
|
|
22
|
-
const { clientRoutes } = useAppContext();
|
|
23
|
-
return useRoutes(clientRoutes) || clientRoutes[0].element;
|
|
24
|
-
}
|
|
25
|
-
function Loading() {
|
|
26
|
-
return React.createElement("div", null, "Loading...");
|
|
27
|
-
}
|
|
28
|
-
export function RouteComponent(props) {
|
|
29
|
-
const loader = useAppContext().routeComponents[props.id];
|
|
30
|
-
const RouteComponent = React.lazy(loader);
|
|
31
|
-
// ref: https://reactjs.org/docs/code-splitting.html
|
|
32
|
-
// TODO: replace with https://github.com/gregberge/loadable-components when we support ssr
|
|
33
|
-
return (React.createElement(React.Suspense, { fallback: React.createElement(Loading, null) },
|
|
34
|
-
React.createElement(RouteComponent, null)));
|
|
35
|
-
}
|