@umijs/renderer-react 3.5.18 → 4.0.0-beta.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/README.md +2 -0
- package/dist/app.d.ts +14 -0
- package/dist/app.js +35 -0
- package/dist/appContext.d.ts +9 -0
- package/dist/appContext.js +5 -0
- package/dist/browser.d.ts +12 -0
- package/dist/browser.js +27 -0
- package/dist/index.d.ts +2 -35
- package/dist/index.js +2 -700
- package/dist/routes.d.ts +21 -0
- package/dist/routes.js +31 -0
- package/dist/types.d.ts +9 -0
- package/dist/{renderRoutes/renderRoutes.test.d.ts → types.js} +1 -1
- package/package.json +18 -16
- package/dist/index.esm.js +0 -691
- package/dist/renderClient/renderClient.d.ts +0 -23
- package/dist/renderClient/renderClient.test.d.ts +0 -1
- package/dist/renderRoutes/Route.d.ts +0 -1
- package/dist/renderRoutes/Switch.d.ts +0 -1
- package/dist/renderRoutes/renderRoutes.d.ts +0 -14
package/README.md
CHANGED
package/dist/app.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export interface IAppContextType {
|
|
3
|
+
routes: any;
|
|
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;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IRoutesById } from './types';
|
|
2
|
+
export declare function Browser(props: {
|
|
3
|
+
routes: IRoutesById;
|
|
4
|
+
routeComponents: Record<string, any>;
|
|
5
|
+
pluginManager: any;
|
|
6
|
+
}): any;
|
|
7
|
+
export declare function renderClient(opts: {
|
|
8
|
+
rootElement?: HTMLElement;
|
|
9
|
+
routes: IRoutesById;
|
|
10
|
+
routeComponents: Record<string, any>;
|
|
11
|
+
pluginManager: any;
|
|
12
|
+
}): void;
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createBrowserHistory } from 'history';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import ReactDOM from 'react-dom';
|
|
4
|
+
import { App } from './app';
|
|
5
|
+
export function Browser(props) {
|
|
6
|
+
const historyRef = React.useRef();
|
|
7
|
+
if (historyRef.current === undefined) {
|
|
8
|
+
historyRef.current = createBrowserHistory({ window });
|
|
9
|
+
}
|
|
10
|
+
const history = historyRef.current;
|
|
11
|
+
const [state, dispatch] = React.useReducer((_, update) => update, {
|
|
12
|
+
action: history.action,
|
|
13
|
+
location: history.location,
|
|
14
|
+
});
|
|
15
|
+
React.useLayoutEffect(() => history.listen(dispatch), [history]);
|
|
16
|
+
return props.pluginManager.applyPlugins({
|
|
17
|
+
type: 'modify',
|
|
18
|
+
key: 'rootContainer',
|
|
19
|
+
initialValue: (React.createElement(App, { navigator: history, location: state.location, routes: props.routes, routeComponents: props.routeComponents, pluginManager: props.pluginManager })),
|
|
20
|
+
args: {},
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
export function renderClient(opts) {
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
const root = ReactDOM.createRoot(opts.rootElement || document.getElementById('root'));
|
|
26
|
+
root.render(React.createElement(Browser, { routes: opts.routes, routeComponents: opts.routeComponents, pluginManager: opts.pluginManager }));
|
|
27
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,35 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { match } from 'react-router-dom';
|
|
4
|
-
export interface IComponent extends FunctionComponent {
|
|
5
|
-
getInitialProps?: Function;
|
|
6
|
-
preload?: () => Promise<any>;
|
|
7
|
-
}
|
|
8
|
-
export interface IRoute {
|
|
9
|
-
path?: string;
|
|
10
|
-
exact?: boolean;
|
|
11
|
-
redirect?: string;
|
|
12
|
-
component?: IComponent | string;
|
|
13
|
-
routes?: IRoute[];
|
|
14
|
-
key?: any;
|
|
15
|
-
strict?: boolean;
|
|
16
|
-
sensitive?: boolean;
|
|
17
|
-
wrappers?: any[];
|
|
18
|
-
[k: string]: any;
|
|
19
|
-
}
|
|
20
|
-
export interface IRouteComponentProps<Params extends {
|
|
21
|
-
[K in keyof Params]?: string;
|
|
22
|
-
} = {}, Query extends {
|
|
23
|
-
[K in keyof Query]?: string;
|
|
24
|
-
} = {}> {
|
|
25
|
-
children: JSX.Element;
|
|
26
|
-
location: Location & {
|
|
27
|
-
query: Query;
|
|
28
|
-
};
|
|
29
|
-
route: IRoute;
|
|
30
|
-
routes: IRoute[];
|
|
31
|
-
history: History;
|
|
32
|
-
match: match<Params>;
|
|
33
|
-
}
|
|
34
|
-
export { default as renderClient } from './renderClient/renderClient';
|
|
35
|
-
export { default as renderRoutes } from './renderRoutes/renderRoutes';
|
|
1
|
+
export { Link, Outlet } from 'react-router-dom';
|
|
2
|
+
export * from './browser';
|