@esmx/router-vue 3.0.0-rc.17 → 3.0.0-rc.20
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/LICENSE +1 -1
- package/README.md +563 -0
- package/README.zh-CN.md +563 -0
- package/dist/index.d.ts +6 -4
- package/dist/index.mjs +11 -4
- package/dist/index.test.d.ts +1 -0
- package/dist/index.test.mjs +206 -0
- package/dist/plugin.d.ts +61 -11
- package/dist/plugin.mjs +32 -16
- package/dist/plugin.test.d.ts +1 -0
- package/dist/plugin.test.mjs +436 -0
- package/dist/router-link.d.ts +202 -0
- package/dist/router-link.mjs +84 -0
- package/dist/router-link.test.d.ts +1 -0
- package/dist/router-link.test.mjs +456 -0
- package/dist/router-view.d.ts +31 -0
- package/dist/router-view.mjs +17 -0
- package/dist/router-view.test.d.ts +1 -0
- package/dist/router-view.test.mjs +459 -0
- package/dist/use.d.ts +198 -3
- package/dist/use.mjs +75 -9
- package/dist/use.test.d.ts +1 -0
- package/dist/use.test.mjs +461 -0
- package/dist/util.d.ts +7 -0
- package/dist/util.mjs +24 -0
- package/dist/util.test.d.ts +1 -0
- package/dist/util.test.mjs +319 -0
- package/dist/vue2.d.ts +13 -0
- package/dist/vue2.mjs +0 -0
- package/dist/vue3.d.ts +13 -0
- package/dist/vue3.mjs +0 -0
- package/package.json +31 -14
- package/src/index.test.ts +263 -0
- package/src/index.ts +16 -4
- package/src/plugin.test.ts +574 -0
- package/src/plugin.ts +92 -31
- package/src/router-link.test.ts +569 -0
- package/src/router-link.ts +148 -0
- package/src/router-view.test.ts +599 -0
- package/src/router-view.ts +62 -0
- package/src/use.test.ts +616 -0
- package/src/use.ts +307 -11
- package/src/util.test.ts +418 -0
- package/src/util.ts +32 -0
- package/src/vue2.ts +16 -0
- package/src/vue3.ts +15 -0
- package/dist/link.d.ts +0 -101
- package/dist/link.mjs +0 -103
- package/dist/symbols.d.ts +0 -3
- package/dist/symbols.mjs +0 -3
- package/dist/view.d.ts +0 -21
- package/dist/view.mjs +0 -75
- package/src/link.ts +0 -177
- package/src/symbols.ts +0 -8
- package/src/view.ts +0 -95
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import * as RouterVueModule from "./index.mjs";
|
|
3
|
+
describe("index.ts - Package Entry Point", () => {
|
|
4
|
+
describe("Composition API Exports", () => {
|
|
5
|
+
it("should export useRouter function", () => {
|
|
6
|
+
expect(RouterVueModule.useRouter).toBeDefined();
|
|
7
|
+
expect(typeof RouterVueModule.useRouter).toBe("function");
|
|
8
|
+
});
|
|
9
|
+
it("should export useRoute function", () => {
|
|
10
|
+
expect(RouterVueModule.useRoute).toBeDefined();
|
|
11
|
+
expect(typeof RouterVueModule.useRoute).toBe("function");
|
|
12
|
+
});
|
|
13
|
+
it("should export useProvideRouter function", () => {
|
|
14
|
+
expect(RouterVueModule.useProvideRouter).toBeDefined();
|
|
15
|
+
expect(typeof RouterVueModule.useProvideRouter).toBe("function");
|
|
16
|
+
});
|
|
17
|
+
it("should export useLink function", () => {
|
|
18
|
+
expect(RouterVueModule.useLink).toBeDefined();
|
|
19
|
+
expect(typeof RouterVueModule.useLink).toBe("function");
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
describe("Options API Exports", () => {
|
|
23
|
+
it("should export getRouter function", () => {
|
|
24
|
+
expect(RouterVueModule.getRouter).toBeDefined();
|
|
25
|
+
expect(typeof RouterVueModule.getRouter).toBe("function");
|
|
26
|
+
});
|
|
27
|
+
it("should export getRoute function", () => {
|
|
28
|
+
expect(RouterVueModule.getRoute).toBeDefined();
|
|
29
|
+
expect(typeof RouterVueModule.getRoute).toBe("function");
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
describe("Component Exports", () => {
|
|
33
|
+
it("should export RouterLink component", () => {
|
|
34
|
+
expect(RouterVueModule.RouterLink).toBeDefined();
|
|
35
|
+
expect(typeof RouterVueModule.RouterLink).toBe("object");
|
|
36
|
+
expect(RouterVueModule.RouterLink.name).toBe("RouterLink");
|
|
37
|
+
expect(typeof RouterVueModule.RouterLink.setup).toBe("function");
|
|
38
|
+
});
|
|
39
|
+
it("should export RouterView component", () => {
|
|
40
|
+
expect(RouterVueModule.RouterView).toBeDefined();
|
|
41
|
+
expect(typeof RouterVueModule.RouterView).toBe("object");
|
|
42
|
+
expect(RouterVueModule.RouterView.name).toBe("RouterView");
|
|
43
|
+
expect(typeof RouterVueModule.RouterView.setup).toBe("function");
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
describe("Plugin Exports", () => {
|
|
47
|
+
it("should export RouterPlugin", () => {
|
|
48
|
+
expect(RouterVueModule.RouterPlugin).toBeDefined();
|
|
49
|
+
expect(typeof RouterVueModule.RouterPlugin).toBe("object");
|
|
50
|
+
expect(typeof RouterVueModule.RouterPlugin.install).toBe(
|
|
51
|
+
"function"
|
|
52
|
+
);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
describe("Export Completeness", () => {
|
|
56
|
+
it("should export all expected functions and components", () => {
|
|
57
|
+
const expectedExports = [
|
|
58
|
+
// Composition API
|
|
59
|
+
"useRouter",
|
|
60
|
+
"useRoute",
|
|
61
|
+
"useProvideRouter",
|
|
62
|
+
"useLink",
|
|
63
|
+
// Options API
|
|
64
|
+
"getRouter",
|
|
65
|
+
"getRoute",
|
|
66
|
+
// Components
|
|
67
|
+
"RouterLink",
|
|
68
|
+
"RouterView",
|
|
69
|
+
// Plugin
|
|
70
|
+
"RouterPlugin"
|
|
71
|
+
];
|
|
72
|
+
expectedExports.forEach((exportName) => {
|
|
73
|
+
expect(RouterVueModule).toHaveProperty(exportName);
|
|
74
|
+
expect(
|
|
75
|
+
RouterVueModule[exportName]
|
|
76
|
+
).toBeDefined();
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
it("should not export unexpected items", () => {
|
|
80
|
+
const actualExports = Object.keys(RouterVueModule);
|
|
81
|
+
const expectedExports = [
|
|
82
|
+
"useRouter",
|
|
83
|
+
"useRoute",
|
|
84
|
+
"useProvideRouter",
|
|
85
|
+
"useLink",
|
|
86
|
+
"getRouter",
|
|
87
|
+
"getRoute",
|
|
88
|
+
"RouterLink",
|
|
89
|
+
"RouterView",
|
|
90
|
+
"RouterPlugin"
|
|
91
|
+
];
|
|
92
|
+
const unexpectedExports = actualExports.filter(
|
|
93
|
+
(exportName) => !expectedExports.includes(exportName)
|
|
94
|
+
);
|
|
95
|
+
expect(unexpectedExports).toEqual([]);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
describe("Function Signatures", () => {
|
|
99
|
+
it("should have correct function signatures for Composition API", () => {
|
|
100
|
+
expect(() => {
|
|
101
|
+
RouterVueModule.useRouter();
|
|
102
|
+
}).toThrow("useRouter() can only be called during setup()");
|
|
103
|
+
expect(() => {
|
|
104
|
+
RouterVueModule.useRoute();
|
|
105
|
+
}).toThrow("useRoute() can only be called during setup()");
|
|
106
|
+
expect(() => {
|
|
107
|
+
RouterVueModule.useLink({
|
|
108
|
+
to: "/test",
|
|
109
|
+
type: "push",
|
|
110
|
+
exact: "include"
|
|
111
|
+
});
|
|
112
|
+
}).toThrow("useRouter() can only be called during setup()");
|
|
113
|
+
});
|
|
114
|
+
it("should have correct function signatures for Options API", () => {
|
|
115
|
+
expect(() => {
|
|
116
|
+
try {
|
|
117
|
+
RouterVueModule.getRouter({});
|
|
118
|
+
} catch (error) {
|
|
119
|
+
expect(error.message).toContain(
|
|
120
|
+
"Router context not found"
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
}).not.toThrow();
|
|
124
|
+
expect(() => {
|
|
125
|
+
try {
|
|
126
|
+
RouterVueModule.getRoute({});
|
|
127
|
+
} catch (error) {
|
|
128
|
+
expect(error.message).toContain(
|
|
129
|
+
"Router context not found"
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
}).not.toThrow();
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
describe("Component Properties", () => {
|
|
136
|
+
it("should have RouterLink with correct properties", () => {
|
|
137
|
+
const { RouterLink } = RouterVueModule;
|
|
138
|
+
expect(RouterLink.name).toBe("RouterLink");
|
|
139
|
+
expect(RouterLink.props).toBeDefined();
|
|
140
|
+
expect(RouterLink.setup).toBeDefined();
|
|
141
|
+
expect(RouterLink.props.to).toBeDefined();
|
|
142
|
+
expect(RouterLink.props.to.required).toBe(true);
|
|
143
|
+
expect(RouterLink.props.type.default).toBe("push");
|
|
144
|
+
expect(RouterLink.props.exact.default).toBe("include");
|
|
145
|
+
expect(RouterLink.props.tag.default).toBe("a");
|
|
146
|
+
expect(RouterLink.props.event.default).toBe("click");
|
|
147
|
+
});
|
|
148
|
+
it("should have RouterView with correct properties", () => {
|
|
149
|
+
const { RouterView } = RouterVueModule;
|
|
150
|
+
expect(RouterView.name).toBe("RouterView");
|
|
151
|
+
expect(RouterView.setup).toBeDefined();
|
|
152
|
+
expect(RouterView.props).toBeUndefined();
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
describe("Plugin Interface", () => {
|
|
156
|
+
it("should have RouterPlugin with install method", () => {
|
|
157
|
+
const { RouterPlugin } = RouterVueModule;
|
|
158
|
+
expect(RouterPlugin.install).toBeDefined();
|
|
159
|
+
expect(typeof RouterPlugin.install).toBe("function");
|
|
160
|
+
expect(() => {
|
|
161
|
+
RouterPlugin.install(null);
|
|
162
|
+
}).toThrow();
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
describe("Module Structure", () => {
|
|
166
|
+
it("should be a proper ES module", () => {
|
|
167
|
+
expect(typeof RouterVueModule).toBe("object");
|
|
168
|
+
expect(RouterVueModule).not.toBeNull();
|
|
169
|
+
expect("default" in RouterVueModule).toBe(false);
|
|
170
|
+
});
|
|
171
|
+
it("should have consistent export naming", () => {
|
|
172
|
+
const functionExports = [
|
|
173
|
+
"useRouter",
|
|
174
|
+
"useRoute",
|
|
175
|
+
"useProvideRouter",
|
|
176
|
+
"useLink",
|
|
177
|
+
"getRouter",
|
|
178
|
+
"getRoute"
|
|
179
|
+
];
|
|
180
|
+
functionExports.forEach((exportName) => {
|
|
181
|
+
expect(exportName).toMatch(/^[a-z][a-zA-Z]*$/);
|
|
182
|
+
});
|
|
183
|
+
const componentExports = [
|
|
184
|
+
"RouterLink",
|
|
185
|
+
"RouterView",
|
|
186
|
+
"RouterPlugin"
|
|
187
|
+
];
|
|
188
|
+
componentExports.forEach((exportName) => {
|
|
189
|
+
expect(exportName).toMatch(/^[A-Z][a-zA-Z]*$/);
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
describe("TypeScript Integration", () => {
|
|
194
|
+
it("should provide proper TypeScript types", () => {
|
|
195
|
+
expect(typeof RouterVueModule.useRouter).toBe("function");
|
|
196
|
+
expect(typeof RouterVueModule.useRoute).toBe("function");
|
|
197
|
+
expect(typeof RouterVueModule.getRouter).toBe("function");
|
|
198
|
+
expect(typeof RouterVueModule.getRoute).toBe("function");
|
|
199
|
+
expect(RouterVueModule.RouterLink).toHaveProperty("name");
|
|
200
|
+
expect(RouterVueModule.RouterLink).toHaveProperty("props");
|
|
201
|
+
expect(RouterVueModule.RouterLink).toHaveProperty("setup");
|
|
202
|
+
expect(RouterVueModule.RouterView).toHaveProperty("name");
|
|
203
|
+
expect(RouterVueModule.RouterView).toHaveProperty("setup");
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
});
|
package/dist/plugin.d.ts
CHANGED
|
@@ -1,11 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Vue plugin for \@esmx/router integration.
|
|
3
|
+
* Registers RouterLink and RouterView components globally.
|
|
4
|
+
* Compatible with both Vue 2.7+ and Vue 3.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
*
|
|
8
|
+
* Vue 3 installation
|
|
9
|
+
*
|
|
10
|
+
* ```typescript
|
|
11
|
+
* import { createApp } from 'vue';
|
|
12
|
+
* import { Router } from '@esmx/router';
|
|
13
|
+
* import { RouterPlugin, useProvideRouter } from '@esmx/router-vue';
|
|
14
|
+
*
|
|
15
|
+
* const routes = [
|
|
16
|
+
* { path: '/', component: Home },
|
|
17
|
+
* { path: '/about', component: About }
|
|
18
|
+
* ];
|
|
19
|
+
*
|
|
20
|
+
* const router = new Router({ routes });
|
|
21
|
+
* const app = createApp({
|
|
22
|
+
* setup() {
|
|
23
|
+
* useProvideRouter(router);
|
|
24
|
+
* }
|
|
25
|
+
* });
|
|
26
|
+
*
|
|
27
|
+
* app.use(RouterPlugin);
|
|
28
|
+
* app.mount('#app');
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
*
|
|
33
|
+
* Vue 2 installation
|
|
34
|
+
*
|
|
35
|
+
* ```typescript
|
|
36
|
+
* import Vue from 'vue';
|
|
37
|
+
* import { Router } from '@esmx/router';
|
|
38
|
+
* import { RouterPlugin, useProvideRouter } from '@esmx/router-vue';
|
|
39
|
+
*
|
|
40
|
+
* const routes = [
|
|
41
|
+
* { path: '/', component: Home },
|
|
42
|
+
* { path: '/about', component: About }
|
|
43
|
+
* ];
|
|
44
|
+
*
|
|
45
|
+
* const router = new Router({ routes });
|
|
46
|
+
* Vue.use(RouterPlugin);
|
|
47
|
+
*
|
|
48
|
+
* new Vue({
|
|
49
|
+
* setup() {
|
|
50
|
+
* useProvideRouter(router);
|
|
51
|
+
* }
|
|
52
|
+
* }).$mount('#app');
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare const RouterPlugin: {
|
|
56
|
+
/**
|
|
57
|
+
* Install the router plugin.
|
|
58
|
+
* @param app Vue application instance (Vue 3) or Vue constructor (Vue 2)
|
|
59
|
+
*/
|
|
60
|
+
install(app: unknown): void;
|
|
61
|
+
};
|
package/dist/plugin.mjs
CHANGED
|
@@ -1,16 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
app
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
1
|
+
import { RouterLink } from "./router-link.mjs";
|
|
2
|
+
import { RouterView } from "./router-view.mjs";
|
|
3
|
+
import { getRoute, getRouter } from "./use.mjs";
|
|
4
|
+
import { isVue3 } from "./util.mjs";
|
|
5
|
+
export const RouterPlugin = {
|
|
6
|
+
/**
|
|
7
|
+
* Install the router plugin.
|
|
8
|
+
* @param app Vue application instance (Vue 3) or Vue constructor (Vue 2)
|
|
9
|
+
*/
|
|
10
|
+
install(app) {
|
|
11
|
+
var _a;
|
|
12
|
+
const vueApp = app;
|
|
13
|
+
const target = ((_a = vueApp.config) == null ? void 0 : _a.globalProperties) || vueApp.prototype;
|
|
14
|
+
if (!target) {
|
|
15
|
+
throw new Error("[@esmx/router-vue] Invalid Vue app instance");
|
|
16
|
+
}
|
|
17
|
+
Object.defineProperties(target, {
|
|
18
|
+
$router: {
|
|
19
|
+
get() {
|
|
20
|
+
return getRouter(isVue3 ? null : this);
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
$route: {
|
|
24
|
+
get() {
|
|
25
|
+
return getRoute(isVue3 ? null : this);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
vueApp.component("RouterLink", RouterLink);
|
|
30
|
+
vueApp.component("RouterView", RouterView);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|