@esmx/router-vue 3.0.0-rc.103
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 +21 -0
- package/README.md +570 -0
- package/README.zh-CN.md +570 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.mjs +13 -0
- package/dist/index.test.d.ts +1 -0
- package/dist/index.test.mjs +216 -0
- package/dist/plugin.d.ts +61 -0
- package/dist/plugin.mjs +41 -0
- package/dist/plugin.test.d.ts +1 -0
- package/dist/plugin.test.mjs +631 -0
- package/dist/router-link.d.ts +220 -0
- package/dist/router-link.mjs +119 -0
- package/dist/router-link.test.d.ts +1 -0
- package/dist/router-link.test.mjs +663 -0
- package/dist/router-view.d.ts +31 -0
- package/dist/router-view.mjs +15 -0
- package/dist/router-view.test.d.ts +1 -0
- package/dist/router-view.test.mjs +676 -0
- package/dist/run-with-context.test.d.ts +1 -0
- package/dist/run-with-context.test.mjs +57 -0
- package/dist/use.d.ts +260 -0
- package/dist/use.mjs +125 -0
- package/dist/use.test.d.ts +1 -0
- package/dist/use.test.mjs +381 -0
- package/dist/util.d.ts +20 -0
- package/dist/util.mjs +49 -0
- package/dist/util.test.d.ts +4 -0
- package/dist/util.test.mjs +604 -0
- package/dist/vue2.d.ts +15 -0
- package/dist/vue2.mjs +0 -0
- package/dist/vue3.d.ts +13 -0
- package/dist/vue3.mjs +0 -0
- package/package.json +85 -0
- package/src/index.test.ts +273 -0
- package/src/index.ts +15 -0
- package/src/plugin.test.ts +812 -0
- package/src/plugin.ts +107 -0
- package/src/router-link.test.ts +830 -0
- package/src/router-link.ts +172 -0
- package/src/router-view.test.ts +840 -0
- package/src/router-view.ts +59 -0
- package/src/run-with-context.test.ts +64 -0
- package/src/use.test.ts +484 -0
- package/src/use.ts +416 -0
- package/src/util.test.ts +760 -0
- package/src/util.ts +85 -0
- package/src/vue2.ts +18 -0
- package/src/vue3.ts +15 -0
|
@@ -0,0 +1,216 @@
|
|
|
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
|
+
it("should export useRouterViewDepth function", () => {
|
|
22
|
+
expect(RouterVueModule.useRouterViewDepth).toBeDefined();
|
|
23
|
+
expect(typeof RouterVueModule.useRouterViewDepth).toBe("function");
|
|
24
|
+
});
|
|
25
|
+
it("should export getRouterViewDepth function", () => {
|
|
26
|
+
expect(RouterVueModule.getRouterViewDepth).toBeDefined();
|
|
27
|
+
expect(typeof RouterVueModule.getRouterViewDepth).toBe("function");
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
describe("Options API Exports", () => {
|
|
31
|
+
it("should export getRouter function", () => {
|
|
32
|
+
expect(RouterVueModule.getRouter).toBeDefined();
|
|
33
|
+
expect(typeof RouterVueModule.getRouter).toBe("function");
|
|
34
|
+
});
|
|
35
|
+
it("should export getRoute function", () => {
|
|
36
|
+
expect(RouterVueModule.getRoute).toBeDefined();
|
|
37
|
+
expect(typeof RouterVueModule.getRoute).toBe("function");
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
describe("Component Exports", () => {
|
|
41
|
+
it("should export RouterLink component", () => {
|
|
42
|
+
expect(RouterVueModule.RouterLink).toBeDefined();
|
|
43
|
+
expect(typeof RouterVueModule.RouterLink).toBe("object");
|
|
44
|
+
expect(RouterVueModule.RouterLink.name).toBe("RouterLink");
|
|
45
|
+
expect(typeof RouterVueModule.RouterLink.setup).toBe("function");
|
|
46
|
+
});
|
|
47
|
+
it("should export RouterView component", () => {
|
|
48
|
+
expect(RouterVueModule.RouterView).toBeDefined();
|
|
49
|
+
expect(typeof RouterVueModule.RouterView).toBe("object");
|
|
50
|
+
expect(RouterVueModule.RouterView.name).toBe("RouterView");
|
|
51
|
+
expect(typeof RouterVueModule.RouterView.setup).toBe("function");
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
describe("Plugin Exports", () => {
|
|
55
|
+
it("should export RouterPlugin", () => {
|
|
56
|
+
expect(RouterVueModule.RouterPlugin).toBeDefined();
|
|
57
|
+
expect(typeof RouterVueModule.RouterPlugin).toBe("object");
|
|
58
|
+
expect(typeof RouterVueModule.RouterPlugin.install).toBe(
|
|
59
|
+
"function"
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
describe("Export Completeness", () => {
|
|
64
|
+
it("should export all expected functions and components", () => {
|
|
65
|
+
const expectedExports = [
|
|
66
|
+
// Composition API
|
|
67
|
+
"useRouter",
|
|
68
|
+
"useRoute",
|
|
69
|
+
"useProvideRouter",
|
|
70
|
+
"useLink",
|
|
71
|
+
"useRouterViewDepth",
|
|
72
|
+
"getRouterViewDepth",
|
|
73
|
+
// Options API
|
|
74
|
+
"getRouter",
|
|
75
|
+
"getRoute",
|
|
76
|
+
// Components
|
|
77
|
+
"RouterLink",
|
|
78
|
+
"RouterView",
|
|
79
|
+
// Plugin
|
|
80
|
+
"RouterPlugin"
|
|
81
|
+
];
|
|
82
|
+
expectedExports.forEach((exportName) => {
|
|
83
|
+
expect(RouterVueModule).toHaveProperty(exportName);
|
|
84
|
+
expect(Object.hasOwn(RouterVueModule, exportName)).toBe(true);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
it("should not export unexpected items", () => {
|
|
88
|
+
const actualExports = Object.keys(RouterVueModule);
|
|
89
|
+
const expectedExports = [
|
|
90
|
+
"useRouter",
|
|
91
|
+
"useRoute",
|
|
92
|
+
"useProvideRouter",
|
|
93
|
+
"useLink",
|
|
94
|
+
"useRouterViewDepth",
|
|
95
|
+
"getRouterViewDepth",
|
|
96
|
+
"getRouter",
|
|
97
|
+
"getRoute",
|
|
98
|
+
"RouterLink",
|
|
99
|
+
"RouterView",
|
|
100
|
+
"RouterPlugin"
|
|
101
|
+
];
|
|
102
|
+
const unexpectedExports = actualExports.filter(
|
|
103
|
+
(exportName) => !expectedExports.includes(exportName)
|
|
104
|
+
);
|
|
105
|
+
expect(unexpectedExports).toEqual([]);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
describe("Function Signatures", () => {
|
|
109
|
+
it("should have correct function signatures for Composition API", () => {
|
|
110
|
+
expect(() => {
|
|
111
|
+
RouterVueModule.useRouter();
|
|
112
|
+
}).toThrow(
|
|
113
|
+
"[@esmx/router-vue] Must be used within setup() or other composition functions"
|
|
114
|
+
);
|
|
115
|
+
expect(() => {
|
|
116
|
+
RouterVueModule.useRoute();
|
|
117
|
+
}).toThrow(
|
|
118
|
+
"[@esmx/router-vue] Must be used within setup() or other composition functions"
|
|
119
|
+
);
|
|
120
|
+
expect(() => {
|
|
121
|
+
RouterVueModule.useLink({
|
|
122
|
+
to: "/test",
|
|
123
|
+
type: "push",
|
|
124
|
+
exact: "include"
|
|
125
|
+
});
|
|
126
|
+
}).toThrow(
|
|
127
|
+
"[@esmx/router-vue] Must be used within setup() or other composition functions"
|
|
128
|
+
);
|
|
129
|
+
});
|
|
130
|
+
it("should have correct function signatures for Options API", () => {
|
|
131
|
+
expect(() => {
|
|
132
|
+
RouterVueModule.getRouter({});
|
|
133
|
+
}).toThrow(
|
|
134
|
+
"[@esmx/router-vue] Router context not found. Please ensure useProvideRouter() is called in a parent component."
|
|
135
|
+
);
|
|
136
|
+
expect(() => {
|
|
137
|
+
RouterVueModule.getRoute({});
|
|
138
|
+
}).toThrow(
|
|
139
|
+
"[@esmx/router-vue] Router context not found. Please ensure useProvideRouter() is called in a parent component."
|
|
140
|
+
);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
describe("Component Properties", () => {
|
|
144
|
+
it("should have RouterLink with correct properties", () => {
|
|
145
|
+
const { RouterLink } = RouterVueModule;
|
|
146
|
+
expect(RouterLink.name).toBe("RouterLink");
|
|
147
|
+
expect(RouterLink.props).toBeDefined();
|
|
148
|
+
expect(RouterLink.setup).toBeDefined();
|
|
149
|
+
expect(RouterLink.props.to).toBeDefined();
|
|
150
|
+
expect(RouterLink.props.to.required).toBe(true);
|
|
151
|
+
expect(RouterLink.props.type.default).toBe("push");
|
|
152
|
+
expect(RouterLink.props.exact.default).toBe("include");
|
|
153
|
+
expect(RouterLink.props.tag.default).toBe("a");
|
|
154
|
+
expect(RouterLink.props.event.default).toBe("click");
|
|
155
|
+
});
|
|
156
|
+
it("should have RouterView with correct properties", () => {
|
|
157
|
+
const { RouterView } = RouterVueModule;
|
|
158
|
+
expect(RouterView.name).toBe("RouterView");
|
|
159
|
+
expect(RouterView.setup).toBeDefined();
|
|
160
|
+
expect(RouterView.props).toBeUndefined();
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
describe("Plugin Interface", () => {
|
|
164
|
+
it("should have RouterPlugin with install method", () => {
|
|
165
|
+
const { RouterPlugin } = RouterVueModule;
|
|
166
|
+
expect(RouterPlugin.install).toBeDefined();
|
|
167
|
+
expect(typeof RouterPlugin.install).toBe("function");
|
|
168
|
+
expect(() => {
|
|
169
|
+
RouterPlugin.install(null);
|
|
170
|
+
}).toThrow("[@esmx/router-vue] Invalid Vue app instance");
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
describe("Module Structure", () => {
|
|
174
|
+
it("should be a proper ES module", () => {
|
|
175
|
+
expect(typeof RouterVueModule).toBe("object");
|
|
176
|
+
expect(RouterVueModule).not.toBeNull();
|
|
177
|
+
expect("default" in RouterVueModule).toBe(false);
|
|
178
|
+
});
|
|
179
|
+
it("should have consistent export naming", () => {
|
|
180
|
+
const functionExports = [
|
|
181
|
+
"useRouter",
|
|
182
|
+
"useRoute",
|
|
183
|
+
"useProvideRouter",
|
|
184
|
+
"useLink",
|
|
185
|
+
"useRouterViewDepth",
|
|
186
|
+
"getRouterViewDepth",
|
|
187
|
+
"getRouter",
|
|
188
|
+
"getRoute"
|
|
189
|
+
];
|
|
190
|
+
functionExports.forEach((exportName) => {
|
|
191
|
+
expect(exportName).toMatch(/^[a-z][a-zA-Z]*$/);
|
|
192
|
+
});
|
|
193
|
+
const componentExports = [
|
|
194
|
+
"RouterLink",
|
|
195
|
+
"RouterView",
|
|
196
|
+
"RouterPlugin"
|
|
197
|
+
];
|
|
198
|
+
componentExports.forEach((exportName) => {
|
|
199
|
+
expect(exportName).toMatch(/^[A-Z][a-zA-Z]*$/);
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
});
|
|
203
|
+
describe("TypeScript Integration", () => {
|
|
204
|
+
it("should provide proper TypeScript types", () => {
|
|
205
|
+
expect(typeof RouterVueModule.useRouter).toBe("function");
|
|
206
|
+
expect(typeof RouterVueModule.useRoute).toBe("function");
|
|
207
|
+
expect(typeof RouterVueModule.getRouter).toBe("function");
|
|
208
|
+
expect(typeof RouterVueModule.getRoute).toBe("function");
|
|
209
|
+
expect(RouterVueModule.RouterLink).toHaveProperty("name");
|
|
210
|
+
expect(RouterVueModule.RouterLink).toHaveProperty("props");
|
|
211
|
+
expect(RouterVueModule.RouterLink).toHaveProperty("setup");
|
|
212
|
+
expect(RouterVueModule.RouterView).toHaveProperty("name");
|
|
213
|
+
expect(RouterVueModule.RouterView).toHaveProperty("setup");
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
});
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { RouterLink } from "./router-link.mjs";
|
|
2
|
+
import { RouterView } from "./router-view.mjs";
|
|
3
|
+
import { getRoute, getRouter } from "./use.mjs";
|
|
4
|
+
import { defineRouterProperties, isVue2 } 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
|
+
if (!app) {
|
|
13
|
+
throw new Error("[@esmx/router-vue] Invalid Vue app instance");
|
|
14
|
+
}
|
|
15
|
+
const vueApp = app;
|
|
16
|
+
const target = ((_a = vueApp.config) == null ? void 0 : _a.globalProperties) || vueApp.prototype;
|
|
17
|
+
if (!target) {
|
|
18
|
+
throw new Error("[@esmx/router-vue] Invalid Vue app instance");
|
|
19
|
+
}
|
|
20
|
+
if (isVue2) {
|
|
21
|
+
defineRouterProperties(
|
|
22
|
+
target,
|
|
23
|
+
function() {
|
|
24
|
+
return getRouter(this);
|
|
25
|
+
},
|
|
26
|
+
function() {
|
|
27
|
+
return getRoute(this);
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
} else {
|
|
31
|
+
const throwError = () => {
|
|
32
|
+
throw new Error(
|
|
33
|
+
"[@esmx/router-vue] Router not provided. Please call useProvideRouter() in your root component setup."
|
|
34
|
+
);
|
|
35
|
+
};
|
|
36
|
+
defineRouterProperties(target, throwError, throwError, true);
|
|
37
|
+
}
|
|
38
|
+
vueApp.component("RouterLink", RouterLink);
|
|
39
|
+
vueApp.component("RouterView", RouterView);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|