@umijs/renderer-react 4.0.0-rc.19 → 4.0.0-rc.21
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 +14 -2
- package/dist/appContext.js +1 -1
- package/dist/browser.js +3 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/link.d.ts +3 -10
- package/dist/link.js +1 -1
- package/dist/routeContext.d.ts +2 -1
- package/dist/routes.d.ts +2 -21
- package/dist/routes.js +4 -7
- package/dist/types.d.ts +11 -0
- package/package.json +1 -1
package/dist/appContext.d.ts
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { IClientRoute, ILoaderData, IRouteComponents, IRoutesById } from './types';
|
|
3
|
+
interface IAppCentextType {
|
|
4
|
+
routes: IRoutesById;
|
|
5
|
+
routeComponents: IRouteComponents;
|
|
6
|
+
clientRoutes: IClientRoute[];
|
|
7
|
+
pluginManager: any;
|
|
8
|
+
rootElement?: HTMLElement;
|
|
9
|
+
basename?: string;
|
|
10
|
+
clientLoaderData: ILoaderData;
|
|
11
|
+
preloadRoute: (to: string) => void;
|
|
12
|
+
}
|
|
13
|
+
export declare const AppContext: React.Context<IAppCentextType>;
|
|
14
|
+
export declare function useAppData(): IAppCentextType;
|
|
4
15
|
export declare function useClientLoaderData(): any;
|
|
16
|
+
export {};
|
package/dist/appContext.js
CHANGED
package/dist/browser.js
CHANGED
|
@@ -70,9 +70,10 @@ export function renderClient(opts) {
|
|
|
70
70
|
const [clientLoaderData, setClientLoaderData] = useState({});
|
|
71
71
|
const handleRouteChange = useCallback((p) => {
|
|
72
72
|
var _a;
|
|
73
|
-
|
|
73
|
+
// Patched routes has to id
|
|
74
|
+
const matchedRouteIds = (((_a = matchRoutes(clientRoutes, p)) === null || _a === void 0 ? void 0 : _a.map(
|
|
74
75
|
// @ts-ignore
|
|
75
|
-
(route) => route.route.id)) || [];
|
|
76
|
+
(route) => route.route.id)) || []).filter(Boolean);
|
|
76
77
|
matchedRouteIds.forEach((id) => {
|
|
77
78
|
// preload
|
|
78
79
|
// @ts-ignore
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { createBrowserHistory, createHashHistory, createMemoryHistory, History, } from 'history';
|
|
2
|
-
export { createSearchParams, matchPath, matchRoutes, Navigate, NavLink, Outlet, useLocation, useMatch, useNavigate, useOutlet, useParams, useResolvedPath, useRoutes, useSearchParams, } from 'react-router-dom';
|
|
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 } from './appContext';
|
|
4
4
|
export { renderClient } from './browser';
|
|
5
5
|
export { LinkWithPrefetch as Link } from './link';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { createBrowserHistory, createHashHistory, createMemoryHistory, } from 'history';
|
|
2
|
-
export { createSearchParams, matchPath, matchRoutes, Navigate, NavLink, Outlet, useLocation, useMatch, useNavigate, useOutlet, useParams, useResolvedPath, useRoutes, useSearchParams, } from 'react-router-dom';
|
|
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 } from './appContext';
|
|
4
4
|
export { renderClient } from './browser';
|
|
5
5
|
export { LinkWithPrefetch as Link } from './link';
|
package/dist/link.d.ts
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
import { PropsWithChildren } from 'react';
|
|
1
|
+
import React, { PropsWithChildren } from 'react';
|
|
2
|
+
import { LinkProps } from 'react-router-dom';
|
|
2
3
|
export declare function LinkWithPrefetch(props: PropsWithChildren<{
|
|
3
4
|
prefetch?: boolean;
|
|
4
|
-
|
|
5
|
-
pathname: string;
|
|
6
|
-
search: string;
|
|
7
|
-
hash: string;
|
|
8
|
-
}>;
|
|
9
|
-
replace?: boolean;
|
|
10
|
-
state?: boolean;
|
|
11
|
-
reloadDocument?: boolean;
|
|
12
|
-
}>): JSX.Element;
|
|
5
|
+
} & LinkProps & React.RefAttributes<HTMLAnchorElement>>): JSX.Element;
|
package/dist/link.js
CHANGED
|
@@ -4,5 +4,5 @@ import { useAppData } from './appContext';
|
|
|
4
4
|
export function LinkWithPrefetch(props) {
|
|
5
5
|
const appData = useAppData();
|
|
6
6
|
const to = typeof props.to === 'string' ? props.to : props.to.pathname;
|
|
7
|
-
return (React.createElement(Link, { onMouseEnter: () => props.prefetch && appData.preloadRoute(to),
|
|
7
|
+
return (React.createElement(Link, { onMouseEnter: () => props.prefetch && to && appData.preloadRoute(to), ...props }, props.children));
|
|
8
8
|
}
|
package/dist/routeContext.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { IRoute } from './types';
|
|
2
3
|
export interface IRouteContextType {
|
|
3
|
-
route:
|
|
4
|
+
route: IRoute;
|
|
4
5
|
}
|
|
5
6
|
export declare const RouteContext: React.Context<IRouteContextType | undefined>;
|
|
6
7
|
export declare function useRouteData(): IRouteContextType;
|
package/dist/routes.d.ts
CHANGED
|
@@ -1,27 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { IClientRoute, IRoutesById } from './types';
|
|
3
3
|
export declare function createClientRoutes(opts: {
|
|
4
4
|
routesById: IRoutesById;
|
|
5
5
|
routeComponents: Record<string, any>;
|
|
6
6
|
parentId?: string;
|
|
7
7
|
loadingComponent?: React.ReactNode;
|
|
8
|
-
}):
|
|
9
|
-
parentId?: string | undefined;
|
|
10
|
-
clientLoader?: (() => Promise<any>) | undefined;
|
|
11
|
-
id: string;
|
|
12
|
-
path: string | undefined;
|
|
13
|
-
index: boolean | undefined;
|
|
14
|
-
element: JSX.Element;
|
|
15
|
-
}[];
|
|
16
|
-
export declare function createClientRoute(opts: {
|
|
17
|
-
route: IRoute;
|
|
18
|
-
routeComponent: any;
|
|
19
|
-
loadingComponent?: React.ReactNode;
|
|
20
|
-
}): {
|
|
21
|
-
parentId?: string | undefined;
|
|
22
|
-
clientLoader?: (() => Promise<any>) | undefined;
|
|
23
|
-
id: string;
|
|
24
|
-
path: string | undefined;
|
|
25
|
-
index: boolean | undefined;
|
|
26
|
-
element: JSX.Element;
|
|
27
|
-
};
|
|
8
|
+
}): IClientRoute[];
|
package/dist/routes.js
CHANGED
|
@@ -20,23 +20,20 @@ export function createClientRoutes(opts) {
|
|
|
20
20
|
loadingComponent: opts.loadingComponent,
|
|
21
21
|
});
|
|
22
22
|
if (children.length > 0) {
|
|
23
|
-
// @ts-ignore
|
|
24
23
|
route.children = children;
|
|
25
24
|
// TODO: remove me
|
|
26
25
|
// compatible with @ant-design/pro-layout
|
|
27
|
-
// @ts-ignore
|
|
28
26
|
route.routes = children;
|
|
29
27
|
}
|
|
30
28
|
return route;
|
|
31
29
|
});
|
|
32
30
|
}
|
|
33
|
-
|
|
31
|
+
function createClientRoute(opts) {
|
|
34
32
|
const { route } = opts;
|
|
35
|
-
const {
|
|
33
|
+
const { redirect, ...props } = route;
|
|
36
34
|
return {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
index: index,
|
|
35
|
+
children: [],
|
|
36
|
+
routes: [],
|
|
40
37
|
element: redirect ? (React.createElement(Navigate, { to: redirect })) : (React.createElement(RouteContext.Provider, { value: {
|
|
41
38
|
route: opts.route,
|
|
42
39
|
} },
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
1
2
|
export interface IRoute {
|
|
2
3
|
id: string;
|
|
3
4
|
path?: string;
|
|
@@ -6,6 +7,16 @@ export interface IRoute {
|
|
|
6
7
|
redirect?: string;
|
|
7
8
|
clientLoader?: () => Promise<any>;
|
|
8
9
|
}
|
|
10
|
+
export interface IClientRoute {
|
|
11
|
+
id: string;
|
|
12
|
+
element: React.ReactNode;
|
|
13
|
+
children: IClientRoute[];
|
|
14
|
+
routes: IClientRoute[];
|
|
15
|
+
path?: string;
|
|
16
|
+
index?: boolean;
|
|
17
|
+
parentId?: string;
|
|
18
|
+
clientLoader?: () => Promise<any>;
|
|
19
|
+
}
|
|
9
20
|
export interface IRoutesById {
|
|
10
21
|
[id: string]: IRoute;
|
|
11
22
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/renderer-react",
|
|
3
|
-
"version": "4.0.0-rc.
|
|
3
|
+
"version": "4.0.0-rc.21",
|
|
4
4
|
"description": "@umijs/renderer-react",
|
|
5
5
|
"homepage": "https://github.com/umijs/umi-next/tree/master/packages/renderer-react#readme",
|
|
6
6
|
"bugs": "https://github.com/umijs/umi-next/issues",
|