@umijs/renderer-react 3.5.20 → 4.0.0-beta.12

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.
@@ -0,0 +1,21 @@
1
+ /// <reference types="react" />
2
+ import { IRoute, IRoutesById } from './types';
3
+ export declare function createClientRoutes(opts: {
4
+ routesById: IRoutesById;
5
+ parentId?: string;
6
+ Component: any;
7
+ }): {
8
+ id: string;
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
+ };
package/dist/routes.js ADDED
@@ -0,0 +1,32 @@
1
+ import React from 'react';
2
+ import { Navigate } from 'react-router-dom';
3
+ export function createClientRoutes(opts) {
4
+ const { routesById, parentId, Component } = opts;
5
+ return Object.keys(routesById)
6
+ .filter((id) => routesById[id].parentId === parentId)
7
+ .map((id) => {
8
+ const route = createClientRoute({
9
+ route: routesById[id],
10
+ Component,
11
+ });
12
+ const children = createClientRoutes({
13
+ routesById,
14
+ parentId: route.id,
15
+ Component,
16
+ });
17
+ if (children.length > 0) {
18
+ // @ts-ignore
19
+ route.children = children;
20
+ }
21
+ return route;
22
+ });
23
+ }
24
+ export function createClientRoute(opts) {
25
+ const { route, Component } = opts;
26
+ return {
27
+ id: route.id,
28
+ path: route.path,
29
+ index: route.index,
30
+ element: route.redirect ? (React.createElement(Navigate, { to: route.redirect })) : (React.createElement(Component, { id: route.id })),
31
+ };
32
+ }
@@ -0,0 +1,10 @@
1
+ export interface IRoute {
2
+ id: string;
3
+ path?: string;
4
+ index?: boolean;
5
+ parentId?: string;
6
+ redirect?: string;
7
+ }
8
+ export interface IRoutesById {
9
+ [id: string]: IRoute;
10
+ }
@@ -1 +1 @@
1
- export {};
1
+ export {};
package/package.json CHANGED
@@ -1,39 +1,42 @@
1
1
  {
2
2
  "name": "@umijs/renderer-react",
3
- "version": "3.5.20",
3
+ "version": "4.0.0-beta.12",
4
4
  "description": "@umijs/renderer-react",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "files": [
8
- "dist"
9
- ],
5
+ "homepage": "https://github.com/umijs/umi-next/tree/master/packages/renderer-react#readme",
6
+ "bugs": "https://github.com/umijs/umi-next/issues",
10
7
  "repository": {
11
8
  "type": "git",
12
- "url": "https://github.com/umijs/umi"
9
+ "url": "https://github.com/umijs/umi-next"
13
10
  },
14
- "keywords": [
15
- "umi"
16
- ],
11
+ "license": "MIT",
17
12
  "sideEffects": false,
18
- "authors": [
19
- "chencheng <sorrycc@gmail.com> (https://github.com/sorrycc)"
13
+ "main": "dist/index.js",
14
+ "types": "dist/index.d.ts",
15
+ "files": [
16
+ "dist"
20
17
  ],
21
- "license": "MIT",
22
- "bugs": "http://github.com/umijs/umi/issues",
23
- "homepage": "https://github.com/umijs/umi/tree/master/packages/renderer-react#readme",
24
- "publishConfig": {
25
- "access": "public"
18
+ "scripts": {
19
+ "build": "pnpm tsc",
20
+ "build:deps": "pnpm esno ../../scripts/bundleDeps.ts",
21
+ "dev": "pnpm build -- --watch"
26
22
  },
27
23
  "dependencies": {
28
- "@types/react": "^16.9.43",
29
- "@types/react-dom": "^16.9.8",
30
- "@types/react-router-config": "^5.0.2",
31
- "@umijs/runtime": "3.5.20",
32
- "react-router-config": "5.1.1"
24
+ "@loadable/component": "5.15.0",
25
+ "history": "5.1.0",
26
+ "react-router-dom": "6.0.2"
27
+ },
28
+ "devDependencies": {
29
+ "react": "18.0.0-alpha-f2c381131-20211004",
30
+ "react-dom": "18.0.0-alpha-f2c381131-20211004"
33
31
  },
34
32
  "peerDependencies": {
35
- "react": "16.x || 17.x",
36
- "react-dom": "16.x || 17.x"
33
+ "react": ">=16.8",
34
+ "react-dom": ">=16.8"
37
35
  },
38
- "module": "dist/index.esm.js"
36
+ "publishConfig": {
37
+ "access": "public"
38
+ },
39
+ "authors": [
40
+ "chencheng <sorrycc@gmail.com> (https://github.com/sorrycc)"
41
+ ]
39
42
  }