@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.
Files changed (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +570 -0
  3. package/README.zh-CN.md +570 -0
  4. package/dist/index.d.ts +6 -0
  5. package/dist/index.mjs +13 -0
  6. package/dist/index.test.d.ts +1 -0
  7. package/dist/index.test.mjs +216 -0
  8. package/dist/plugin.d.ts +61 -0
  9. package/dist/plugin.mjs +41 -0
  10. package/dist/plugin.test.d.ts +1 -0
  11. package/dist/plugin.test.mjs +631 -0
  12. package/dist/router-link.d.ts +220 -0
  13. package/dist/router-link.mjs +119 -0
  14. package/dist/router-link.test.d.ts +1 -0
  15. package/dist/router-link.test.mjs +663 -0
  16. package/dist/router-view.d.ts +31 -0
  17. package/dist/router-view.mjs +15 -0
  18. package/dist/router-view.test.d.ts +1 -0
  19. package/dist/router-view.test.mjs +676 -0
  20. package/dist/run-with-context.test.d.ts +1 -0
  21. package/dist/run-with-context.test.mjs +57 -0
  22. package/dist/use.d.ts +260 -0
  23. package/dist/use.mjs +125 -0
  24. package/dist/use.test.d.ts +1 -0
  25. package/dist/use.test.mjs +381 -0
  26. package/dist/util.d.ts +20 -0
  27. package/dist/util.mjs +49 -0
  28. package/dist/util.test.d.ts +4 -0
  29. package/dist/util.test.mjs +604 -0
  30. package/dist/vue2.d.ts +15 -0
  31. package/dist/vue2.mjs +0 -0
  32. package/dist/vue3.d.ts +13 -0
  33. package/dist/vue3.mjs +0 -0
  34. package/package.json +85 -0
  35. package/src/index.test.ts +273 -0
  36. package/src/index.ts +15 -0
  37. package/src/plugin.test.ts +812 -0
  38. package/src/plugin.ts +107 -0
  39. package/src/router-link.test.ts +830 -0
  40. package/src/router-link.ts +172 -0
  41. package/src/router-view.test.ts +840 -0
  42. package/src/router-view.ts +59 -0
  43. package/src/run-with-context.test.ts +64 -0
  44. package/src/use.test.ts +484 -0
  45. package/src/use.ts +416 -0
  46. package/src/util.test.ts +760 -0
  47. package/src/util.ts +85 -0
  48. package/src/vue2.ts +18 -0
  49. package/src/vue3.ts +15 -0
package/package.json ADDED
@@ -0,0 +1,85 @@
1
+ {
2
+ "name": "@esmx/router-vue",
3
+ "description": "Vue integration for @esmx/router - A universal router that works seamlessly with both Vue 2.7+ and Vue 3",
4
+ "keywords": [
5
+ "vue",
6
+ "router",
7
+ "routing",
8
+ "vue-router",
9
+ "composition-api",
10
+ "typescript",
11
+ "universal",
12
+ "vue2",
13
+ "vue3",
14
+ "navigation",
15
+ "esmx",
16
+ "esm",
17
+ "single-page-application",
18
+ "spa",
19
+ "framework",
20
+ "frontend"
21
+ ],
22
+ "template": "library",
23
+ "scripts": {
24
+ "lint:js": "biome check --write --no-errors-on-unmatched",
25
+ "lint:css": "pnpm run lint:js",
26
+ "lint:type": "tsc --noEmit",
27
+ "test": "vitest run --pass-with-no-tests",
28
+ "coverage": "vitest run --coverage --pass-with-no-tests",
29
+ "build": "unbuild"
30
+ },
31
+ "contributors": [
32
+ {
33
+ "name": "lzxb",
34
+ "url": "https://github.com/lzxb"
35
+ },
36
+ {
37
+ "name": "RockShi1994",
38
+ "url": "https://github.com/RockShi1994"
39
+ },
40
+ {
41
+ "name": "jerrychan7",
42
+ "url": "https://github.com/jerrychan7"
43
+ },
44
+ {
45
+ "name": "wesloong",
46
+ "url": "https://github.com/wesloong"
47
+ }
48
+ ],
49
+ "peerDependencies": {
50
+ "vue": "^3.5.0 || ^2.7.0"
51
+ },
52
+ "dependencies": {
53
+ "@esmx/router": "3.0.0-rc.103"
54
+ },
55
+ "devDependencies": {
56
+ "@biomejs/biome": "2.3.7",
57
+ "@types/node": "^24.0.0",
58
+ "@vitest/coverage-v8": "3.2.4",
59
+ "typescript": "5.9.3",
60
+ "unbuild": "3.6.1",
61
+ "vitest": "3.2.4",
62
+ "vue": "3.5.23",
63
+ "vue2": "npm:vue@2.7.16"
64
+ },
65
+ "version": "3.0.0-rc.103",
66
+ "type": "module",
67
+ "private": false,
68
+ "exports": {
69
+ ".": {
70
+ "import": "./dist/index.mjs",
71
+ "types": "./dist/index.d.ts"
72
+ }
73
+ },
74
+ "module": "dist/index.mjs",
75
+ "types": "./dist/index.d.ts",
76
+ "files": [
77
+ "lib",
78
+ "src",
79
+ "dist",
80
+ "*.mjs",
81
+ "template",
82
+ "public"
83
+ ],
84
+ "gitHead": "1f2c436d0d57d587756c4012fbf5df2bebcc874f"
85
+ }
@@ -0,0 +1,273 @@
1
+ /**
2
+ * @vitest-environment happy-dom
3
+ */
4
+ import { describe, expect, it } from 'vitest';
5
+ import * as RouterVueModule from './index';
6
+
7
+ describe('index.ts - Package Entry Point', () => {
8
+ describe('Composition API Exports', () => {
9
+ it('should export useRouter function', () => {
10
+ expect(RouterVueModule.useRouter).toBeDefined();
11
+ expect(typeof RouterVueModule.useRouter).toBe('function');
12
+ });
13
+
14
+ it('should export useRoute function', () => {
15
+ expect(RouterVueModule.useRoute).toBeDefined();
16
+ expect(typeof RouterVueModule.useRoute).toBe('function');
17
+ });
18
+
19
+ it('should export useProvideRouter function', () => {
20
+ expect(RouterVueModule.useProvideRouter).toBeDefined();
21
+ expect(typeof RouterVueModule.useProvideRouter).toBe('function');
22
+ });
23
+
24
+ it('should export useLink function', () => {
25
+ expect(RouterVueModule.useLink).toBeDefined();
26
+ expect(typeof RouterVueModule.useLink).toBe('function');
27
+ });
28
+
29
+ it('should export useRouterViewDepth function', () => {
30
+ expect(RouterVueModule.useRouterViewDepth).toBeDefined();
31
+ expect(typeof RouterVueModule.useRouterViewDepth).toBe('function');
32
+ });
33
+
34
+ it('should export getRouterViewDepth function', () => {
35
+ expect(RouterVueModule.getRouterViewDepth).toBeDefined();
36
+ expect(typeof RouterVueModule.getRouterViewDepth).toBe('function');
37
+ });
38
+ });
39
+
40
+ describe('Options API Exports', () => {
41
+ it('should export getRouter function', () => {
42
+ expect(RouterVueModule.getRouter).toBeDefined();
43
+ expect(typeof RouterVueModule.getRouter).toBe('function');
44
+ });
45
+
46
+ it('should export getRoute function', () => {
47
+ expect(RouterVueModule.getRoute).toBeDefined();
48
+ expect(typeof RouterVueModule.getRoute).toBe('function');
49
+ });
50
+ });
51
+
52
+ describe('Component Exports', () => {
53
+ it('should export RouterLink component', () => {
54
+ expect(RouterVueModule.RouterLink).toBeDefined();
55
+ expect(typeof RouterVueModule.RouterLink).toBe('object');
56
+ expect(RouterVueModule.RouterLink.name).toBe('RouterLink');
57
+ expect(typeof RouterVueModule.RouterLink.setup).toBe('function');
58
+ });
59
+
60
+ it('should export RouterView component', () => {
61
+ expect(RouterVueModule.RouterView).toBeDefined();
62
+ expect(typeof RouterVueModule.RouterView).toBe('object');
63
+ expect(RouterVueModule.RouterView.name).toBe('RouterView');
64
+ expect(typeof RouterVueModule.RouterView.setup).toBe('function');
65
+ });
66
+ });
67
+
68
+ describe('Plugin Exports', () => {
69
+ it('should export RouterPlugin', () => {
70
+ expect(RouterVueModule.RouterPlugin).toBeDefined();
71
+ expect(typeof RouterVueModule.RouterPlugin).toBe('object');
72
+ expect(typeof RouterVueModule.RouterPlugin.install).toBe(
73
+ 'function'
74
+ );
75
+ });
76
+ });
77
+
78
+ describe('Export Completeness', () => {
79
+ it('should export all expected functions and components', () => {
80
+ const expectedExports = [
81
+ // Composition API
82
+ 'useRouter',
83
+ 'useRoute',
84
+ 'useProvideRouter',
85
+ 'useLink',
86
+ 'useRouterViewDepth',
87
+ 'getRouterViewDepth',
88
+ // Options API
89
+ 'getRouter',
90
+ 'getRoute',
91
+ // Components
92
+ 'RouterLink',
93
+ 'RouterView',
94
+ // Plugin
95
+ 'RouterPlugin'
96
+ ];
97
+
98
+ expectedExports.forEach((exportName) => {
99
+ expect(RouterVueModule).toHaveProperty(exportName);
100
+ expect(Object.hasOwn(RouterVueModule, exportName)).toBe(true);
101
+ });
102
+ });
103
+
104
+ it('should not export unexpected items', () => {
105
+ const actualExports = Object.keys(RouterVueModule);
106
+ const expectedExports = [
107
+ 'useRouter',
108
+ 'useRoute',
109
+ 'useProvideRouter',
110
+ 'useLink',
111
+ 'useRouterViewDepth',
112
+ 'getRouterViewDepth',
113
+ 'getRouter',
114
+ 'getRoute',
115
+ 'RouterLink',
116
+ 'RouterView',
117
+ 'RouterPlugin'
118
+ ];
119
+
120
+ // Check that we don't have unexpected exports
121
+ const unexpectedExports = actualExports.filter(
122
+ (exportName) => !expectedExports.includes(exportName)
123
+ );
124
+
125
+ expect(unexpectedExports).toEqual([]);
126
+ });
127
+ });
128
+
129
+ describe('Function Signatures', () => {
130
+ it('should have correct function signatures for Composition API', () => {
131
+ // These should throw expected errors when called without proper context
132
+ expect(() => {
133
+ RouterVueModule.useRouter();
134
+ }).toThrow(
135
+ '[@esmx/router-vue] Must be used within setup() or other composition functions'
136
+ );
137
+
138
+ expect(() => {
139
+ RouterVueModule.useRoute();
140
+ }).toThrow(
141
+ '[@esmx/router-vue] Must be used within setup() or other composition functions'
142
+ );
143
+
144
+ expect(() => {
145
+ RouterVueModule.useLink({
146
+ to: '/test',
147
+ type: 'push',
148
+ exact: 'include'
149
+ });
150
+ }).toThrow(
151
+ '[@esmx/router-vue] Must be used within setup() or other composition functions'
152
+ );
153
+ });
154
+
155
+ it('should have correct function signatures for Options API', () => {
156
+ expect(() => {
157
+ RouterVueModule.getRouter({} as Record<string, unknown>);
158
+ }).toThrow(
159
+ '[@esmx/router-vue] Router context not found. Please ensure useProvideRouter() is called in a parent component.'
160
+ );
161
+
162
+ expect(() => {
163
+ RouterVueModule.getRoute({} as Record<string, unknown>);
164
+ }).toThrow(
165
+ '[@esmx/router-vue] Router context not found. Please ensure useProvideRouter() is called in a parent component.'
166
+ );
167
+ });
168
+ });
169
+
170
+ describe('Component Properties', () => {
171
+ it('should have RouterLink with correct properties', () => {
172
+ const { RouterLink } = RouterVueModule;
173
+
174
+ expect(RouterLink.name).toBe('RouterLink');
175
+ expect(RouterLink.props).toBeDefined();
176
+ expect(RouterLink.setup).toBeDefined();
177
+
178
+ // Check required props
179
+ expect(RouterLink.props.to).toBeDefined();
180
+ expect(RouterLink.props.to.required).toBe(true);
181
+
182
+ // Check default props
183
+ expect(RouterLink.props.type.default).toBe('push');
184
+ expect(RouterLink.props.exact.default).toBe('include');
185
+ expect(RouterLink.props.tag.default).toBe('a');
186
+ expect(RouterLink.props.event.default).toBe('click');
187
+ });
188
+
189
+ it('should have RouterView with correct properties', () => {
190
+ const { RouterView } = RouterVueModule;
191
+
192
+ expect(RouterView.name).toBe('RouterView');
193
+ expect(RouterView.setup).toBeDefined();
194
+ // RouterView should not have props
195
+ expect(RouterView.props).toBeUndefined();
196
+ });
197
+ });
198
+
199
+ describe('Plugin Interface', () => {
200
+ it('should have RouterPlugin with install method', () => {
201
+ const { RouterPlugin } = RouterVueModule;
202
+
203
+ expect(RouterPlugin.install).toBeDefined();
204
+ expect(typeof RouterPlugin.install).toBe('function');
205
+
206
+ // Test plugin install signature - should throw for null input
207
+ expect(() => {
208
+ RouterPlugin.install(null);
209
+ }).toThrow('[@esmx/router-vue] Invalid Vue app instance');
210
+ });
211
+ });
212
+
213
+ describe('Module Structure', () => {
214
+ it('should be a proper ES module', () => {
215
+ // Check that the module exports are properly structured
216
+ expect(typeof RouterVueModule).toBe('object');
217
+ expect(RouterVueModule).not.toBeNull();
218
+
219
+ // Verify it's not a default export
220
+ expect('default' in RouterVueModule).toBe(false);
221
+ });
222
+
223
+ it('should have consistent export naming', () => {
224
+ // All function exports should be camelCase
225
+ const functionExports = [
226
+ 'useRouter',
227
+ 'useRoute',
228
+ 'useProvideRouter',
229
+ 'useLink',
230
+ 'useRouterViewDepth',
231
+ 'getRouterViewDepth',
232
+ 'getRouter',
233
+ 'getRoute'
234
+ ];
235
+
236
+ functionExports.forEach((exportName) => {
237
+ expect(exportName).toMatch(/^[a-z][a-zA-Z]*$/);
238
+ });
239
+
240
+ // Component exports should be PascalCase
241
+ const componentExports = [
242
+ 'RouterLink',
243
+ 'RouterView',
244
+ 'RouterPlugin'
245
+ ];
246
+
247
+ componentExports.forEach((exportName) => {
248
+ expect(exportName).toMatch(/^[A-Z][a-zA-Z]*$/);
249
+ });
250
+ });
251
+ });
252
+
253
+ describe('TypeScript Integration', () => {
254
+ it('should provide proper TypeScript types', () => {
255
+ // These checks verify that TypeScript types are properly exported
256
+ // The actual type checking is done by the TypeScript compiler
257
+
258
+ // Verify functions have proper types
259
+ expect(typeof RouterVueModule.useRouter).toBe('function');
260
+ expect(typeof RouterVueModule.useRoute).toBe('function');
261
+ expect(typeof RouterVueModule.getRouter).toBe('function');
262
+ expect(typeof RouterVueModule.getRoute).toBe('function');
263
+
264
+ // Verify components have proper structure
265
+ expect(RouterVueModule.RouterLink).toHaveProperty('name');
266
+ expect(RouterVueModule.RouterLink).toHaveProperty('props');
267
+ expect(RouterVueModule.RouterLink).toHaveProperty('setup');
268
+
269
+ expect(RouterVueModule.RouterView).toHaveProperty('name');
270
+ expect(RouterVueModule.RouterView).toHaveProperty('setup');
271
+ });
272
+ });
273
+ });
package/src/index.ts ADDED
@@ -0,0 +1,15 @@
1
+ export { RouterPlugin } from './plugin';
2
+ export { RouterLink } from './router-link';
3
+ export { RouterView } from './router-view';
4
+ export {
5
+ getRoute,
6
+ getRouter,
7
+ getRouterViewDepth,
8
+ useLink,
9
+ useProvideRouter,
10
+ useRoute,
11
+ useRouter,
12
+ useRouterViewDepth
13
+ } from './use';
14
+ export type * from './vue2';
15
+ export type * from './vue3';