@umijs/renderer-vue 4.0.0-rc.13
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 +3 -0
- package/dist/browser.d.ts +14 -0
- package/dist/browser.jsx +75 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +5 -0
- package/dist/routes.d.ts +11 -0
- package/dist/routes.js +44 -0
- package/dist/types.d.ts +13 -0
- package/dist/types.js +1 -0
- package/package.json +33 -0
package/README.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RouterHistory } from 'vue-router';
|
|
2
|
+
import { IRouteComponents, IRoutesById } from './types';
|
|
3
|
+
export declare const AppContextKey: unique symbol;
|
|
4
|
+
export declare function renderClient(opts: {
|
|
5
|
+
rootElement: string;
|
|
6
|
+
routes: IRoutesById;
|
|
7
|
+
routeComponents: IRouteComponents;
|
|
8
|
+
pluginManager: any;
|
|
9
|
+
basename?: string;
|
|
10
|
+
history: RouterHistory;
|
|
11
|
+
}): {
|
|
12
|
+
app: any;
|
|
13
|
+
router: any;
|
|
14
|
+
};
|
package/dist/browser.jsx
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import App from '@@/core/App.vue';
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
import { createApp } from 'vue';
|
|
5
|
+
// @ts-ignore
|
|
6
|
+
import { createRouter } from 'vue-router';
|
|
7
|
+
import { createClientRoutes } from './routes';
|
|
8
|
+
export const AppContextKey = Symbol('AppContextKey');
|
|
9
|
+
export function renderClient(opts) {
|
|
10
|
+
const routes = createClientRoutes({
|
|
11
|
+
routesById: opts.routes,
|
|
12
|
+
routeComponents: opts.routeComponents,
|
|
13
|
+
});
|
|
14
|
+
let rootContainer = App;
|
|
15
|
+
for (const key of [
|
|
16
|
+
// Lowest to the highest priority
|
|
17
|
+
'innerProvider',
|
|
18
|
+
'i18nProvider',
|
|
19
|
+
'accessProvider',
|
|
20
|
+
'dataflowProvider',
|
|
21
|
+
'outerProvider',
|
|
22
|
+
'rootContainer',
|
|
23
|
+
]) {
|
|
24
|
+
rootContainer = opts.pluginManager.applyPlugins({
|
|
25
|
+
type: 'modify',
|
|
26
|
+
key,
|
|
27
|
+
initialValue: rootContainer,
|
|
28
|
+
args: {},
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
// 路由配置
|
|
32
|
+
const routerConfig = opts.pluginManager.applyPlugins({
|
|
33
|
+
key: 'router',
|
|
34
|
+
type: 'modify',
|
|
35
|
+
initialValue: {},
|
|
36
|
+
});
|
|
37
|
+
const router = createRouter(Object.assign(Object.assign({}, routerConfig), { history: opts.history, strict: true, routes }));
|
|
38
|
+
opts.pluginManager.applyPlugins({
|
|
39
|
+
type: 'event',
|
|
40
|
+
key: 'onRouterCreated',
|
|
41
|
+
args: {
|
|
42
|
+
router,
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
const app = createApp(rootContainer);
|
|
46
|
+
opts.pluginManager.applyPlugins({
|
|
47
|
+
type: 'event',
|
|
48
|
+
key: 'onAppCreated',
|
|
49
|
+
args: {
|
|
50
|
+
app,
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
app.use(router);
|
|
54
|
+
app.mount(opts.rootElement);
|
|
55
|
+
// 注入appData 数据
|
|
56
|
+
app.provide(AppContextKey, {
|
|
57
|
+
routes: opts.routes,
|
|
58
|
+
routeComponents: opts.routeComponents,
|
|
59
|
+
clientRoutes: routes,
|
|
60
|
+
pluginManager: opts.pluginManager,
|
|
61
|
+
rootElement: opts.rootElement,
|
|
62
|
+
});
|
|
63
|
+
opts.pluginManager.applyPlugins({
|
|
64
|
+
type: 'event',
|
|
65
|
+
key: 'onMounted',
|
|
66
|
+
args: {
|
|
67
|
+
app,
|
|
68
|
+
router,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
return {
|
|
72
|
+
app,
|
|
73
|
+
router,
|
|
74
|
+
};
|
|
75
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { RouterOptions } from 'vue-router';
|
|
2
|
+
export { createMemoryHistory, createRouter, createWebHashHistory, createWebHistory, onBeforeRouteLeave, onBeforeRouteUpdate, RouterLink, RouterView, useLink, useRoute, useRouter, } from 'vue-router';
|
|
3
|
+
export { AppContextKey, renderClient } from './browser';
|
|
4
|
+
export declare type RouterConfig = Omit<RouterOptions, 'history' | 'routes'>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
export { createMemoryHistory, createRouter, createWebHashHistory, createWebHistory, onBeforeRouteLeave, onBeforeRouteUpdate, RouterLink, RouterView, useLink, useRoute, useRouter,
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
} from 'vue-router';
|
|
5
|
+
export { AppContextKey, renderClient } from './browser';
|
package/dist/routes.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IRoute, IRoutesById } from './types';
|
|
2
|
+
export declare function createClientRoutes(opts: {
|
|
3
|
+
routesById: IRoutesById;
|
|
4
|
+
routeComponents: Record<string, any>;
|
|
5
|
+
parentId?: string;
|
|
6
|
+
}): Record<string, any>[];
|
|
7
|
+
export declare function createClientRoute(opts: {
|
|
8
|
+
route: IRoute;
|
|
9
|
+
routeComponent: any;
|
|
10
|
+
parentId?: string;
|
|
11
|
+
}): Record<string, any>;
|
package/dist/routes.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export function createClientRoutes(opts) {
|
|
2
|
+
const { routesById, parentId, routeComponents } = opts;
|
|
3
|
+
return Object.keys(routesById)
|
|
4
|
+
.filter((id) => routesById[id].parentId === parentId)
|
|
5
|
+
.map((id) => {
|
|
6
|
+
const route = createClientRoute({
|
|
7
|
+
route: routesById[id],
|
|
8
|
+
routeComponent: routeComponents[id],
|
|
9
|
+
parentId,
|
|
10
|
+
});
|
|
11
|
+
const children = createClientRoutes({
|
|
12
|
+
routesById,
|
|
13
|
+
routeComponents,
|
|
14
|
+
parentId: route.id,
|
|
15
|
+
});
|
|
16
|
+
if (children.length > 0) {
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
route.children = children;
|
|
19
|
+
}
|
|
20
|
+
delete route.id;
|
|
21
|
+
return route;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export function createClientRoute(opts) {
|
|
25
|
+
const { route } = opts;
|
|
26
|
+
const { id, path, redirect } = route;
|
|
27
|
+
if (redirect) {
|
|
28
|
+
return {
|
|
29
|
+
id,
|
|
30
|
+
path,
|
|
31
|
+
redirect,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const item = {
|
|
35
|
+
id,
|
|
36
|
+
component: opts.routeComponent,
|
|
37
|
+
path,
|
|
38
|
+
};
|
|
39
|
+
if (opts.parentId === undefined && path && !path.startsWith('/')) {
|
|
40
|
+
// fix Uncaught (in promise) Error: Route paths should start with a "/": "users" should be "/users".
|
|
41
|
+
item.path = `/${path}`;
|
|
42
|
+
}
|
|
43
|
+
return item;
|
|
44
|
+
}
|
package/dist/types.d.ts
ADDED
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@umijs/renderer-vue",
|
|
3
|
+
"version": "4.0.0-rc.13",
|
|
4
|
+
"description": "@umijs/renderer-vue",
|
|
5
|
+
"homepage": "https://github.com/umijs/umi-next/tree/master/packages/renderer-vue#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,
|
|
13
|
+
"main": "dist/index.js",
|
|
14
|
+
"types": "dist/index.d.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "pnpm tsc",
|
|
20
|
+
"build:deps": "pnpm esno ../../scripts/bundleDeps.ts",
|
|
21
|
+
"dev": "pnpm build -- --watch"
|
|
22
|
+
},
|
|
23
|
+
"peerDependencies": {
|
|
24
|
+
"vue": ">=3.2.31",
|
|
25
|
+
"vue-router": ">=4.0.12"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"authors": [
|
|
31
|
+
"chencheng <sorrycc@gmail.com> (https://github.com/sorrycc)"
|
|
32
|
+
]
|
|
33
|
+
}
|