@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
package/src/util.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { Route, Router } from '@esmx/router';
|
|
2
|
+
import type { Ref } from 'vue';
|
|
3
|
+
import { version } from 'vue';
|
|
4
|
+
|
|
5
|
+
export const isVue2 = version.startsWith('2.');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Define $router and $route properties on a target object.
|
|
9
|
+
* Used to set up global properties for Vue components.
|
|
10
|
+
*
|
|
11
|
+
* @param target - The target object to define properties on (e.g., globalProperties or prototype)
|
|
12
|
+
* @param routerGetter - Getter function for $router (can use `this` in Vue 2)
|
|
13
|
+
* @param routeGetter - Getter function for $route (can use `this` in Vue 2)
|
|
14
|
+
* @param configurable - Whether the properties should be configurable (default: false)
|
|
15
|
+
*/
|
|
16
|
+
export function defineRouterProperties(
|
|
17
|
+
target: Record<string, unknown>,
|
|
18
|
+
routerGetter: (this: unknown) => Router,
|
|
19
|
+
routeGetter: (this: unknown) => Route,
|
|
20
|
+
configurable = false
|
|
21
|
+
): void {
|
|
22
|
+
Object.defineProperties(target, {
|
|
23
|
+
$router: {
|
|
24
|
+
configurable,
|
|
25
|
+
enumerable: false,
|
|
26
|
+
get: routerGetter
|
|
27
|
+
},
|
|
28
|
+
$route: {
|
|
29
|
+
configurable,
|
|
30
|
+
enumerable: false,
|
|
31
|
+
get: routeGetter
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function createSymbolProperty<T>(symbol: symbol) {
|
|
37
|
+
return {
|
|
38
|
+
set(instance: any, value: T): void {
|
|
39
|
+
instance[symbol] = value;
|
|
40
|
+
},
|
|
41
|
+
get(instance: any): T | undefined {
|
|
42
|
+
return symbol in instance ? instance[symbol] : void 0;
|
|
43
|
+
}
|
|
44
|
+
} as const;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function createDependentProxy<T extends object>(
|
|
48
|
+
obj: T,
|
|
49
|
+
dep: Ref<any>
|
|
50
|
+
): T {
|
|
51
|
+
return new Proxy(obj, {
|
|
52
|
+
get(target, prop, receiver) {
|
|
53
|
+
dep.value;
|
|
54
|
+
return Reflect.get(target, prop, receiver);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function isESModule(obj: unknown): obj is Record<string | symbol, any> {
|
|
60
|
+
if (!obj || typeof obj !== 'object') return false;
|
|
61
|
+
const module = obj as Record<string | symbol, any>;
|
|
62
|
+
return (
|
|
63
|
+
Boolean(module.__esModule) || module[Symbol.toStringTag] === 'Module'
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function resolveComponent(component: unknown): unknown {
|
|
68
|
+
if (!component) return null;
|
|
69
|
+
|
|
70
|
+
if (isESModule(component)) {
|
|
71
|
+
return component.default || component;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (
|
|
75
|
+
component &&
|
|
76
|
+
typeof component === 'object' &&
|
|
77
|
+
!Array.isArray(component) &&
|
|
78
|
+
'default' in component &&
|
|
79
|
+
Object.keys(component).length === 1
|
|
80
|
+
) {
|
|
81
|
+
return component.default;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return component;
|
|
85
|
+
}
|
package/src/vue2.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Route, Router } from '@esmx/router';
|
|
2
|
+
import type Vue from 'vue2';
|
|
3
|
+
|
|
4
|
+
// @ts-expect-error
|
|
5
|
+
declare module 'vue/types/vue' {
|
|
6
|
+
interface Vue {
|
|
7
|
+
readonly $router: Router;
|
|
8
|
+
readonly $route: Route;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
declare module 'vue2/types/vue' {
|
|
12
|
+
interface Vue {
|
|
13
|
+
readonly $router: Router;
|
|
14
|
+
readonly $route: Route;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type { Vue };
|
package/src/vue3.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Route, Router } from '@esmx/router';
|
|
2
|
+
import type { RouterLink } from './router-link';
|
|
3
|
+
import type { RouterView } from './router-view';
|
|
4
|
+
|
|
5
|
+
declare module 'vue' {
|
|
6
|
+
interface ComponentCustomProperties {
|
|
7
|
+
readonly $router: Router;
|
|
8
|
+
readonly $route: Route;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface GlobalComponents {
|
|
12
|
+
RouterLink: typeof RouterLink;
|
|
13
|
+
RouterView: typeof RouterView;
|
|
14
|
+
}
|
|
15
|
+
}
|