@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.
Files changed (55) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +563 -0
  3. package/README.zh-CN.md +563 -0
  4. package/dist/index.d.ts +6 -4
  5. package/dist/index.mjs +11 -4
  6. package/dist/index.test.d.ts +1 -0
  7. package/dist/index.test.mjs +206 -0
  8. package/dist/plugin.d.ts +61 -11
  9. package/dist/plugin.mjs +32 -16
  10. package/dist/plugin.test.d.ts +1 -0
  11. package/dist/plugin.test.mjs +436 -0
  12. package/dist/router-link.d.ts +202 -0
  13. package/dist/router-link.mjs +84 -0
  14. package/dist/router-link.test.d.ts +1 -0
  15. package/dist/router-link.test.mjs +456 -0
  16. package/dist/router-view.d.ts +31 -0
  17. package/dist/router-view.mjs +17 -0
  18. package/dist/router-view.test.d.ts +1 -0
  19. package/dist/router-view.test.mjs +459 -0
  20. package/dist/use.d.ts +198 -3
  21. package/dist/use.mjs +75 -9
  22. package/dist/use.test.d.ts +1 -0
  23. package/dist/use.test.mjs +461 -0
  24. package/dist/util.d.ts +7 -0
  25. package/dist/util.mjs +24 -0
  26. package/dist/util.test.d.ts +1 -0
  27. package/dist/util.test.mjs +319 -0
  28. package/dist/vue2.d.ts +13 -0
  29. package/dist/vue2.mjs +0 -0
  30. package/dist/vue3.d.ts +13 -0
  31. package/dist/vue3.mjs +0 -0
  32. package/package.json +31 -14
  33. package/src/index.test.ts +263 -0
  34. package/src/index.ts +16 -4
  35. package/src/plugin.test.ts +574 -0
  36. package/src/plugin.ts +92 -31
  37. package/src/router-link.test.ts +569 -0
  38. package/src/router-link.ts +148 -0
  39. package/src/router-view.test.ts +599 -0
  40. package/src/router-view.ts +62 -0
  41. package/src/use.test.ts +616 -0
  42. package/src/use.ts +307 -11
  43. package/src/util.test.ts +418 -0
  44. package/src/util.ts +32 -0
  45. package/src/vue2.ts +16 -0
  46. package/src/vue3.ts +15 -0
  47. package/dist/link.d.ts +0 -101
  48. package/dist/link.mjs +0 -103
  49. package/dist/symbols.d.ts +0 -3
  50. package/dist/symbols.mjs +0 -3
  51. package/dist/view.d.ts +0 -21
  52. package/dist/view.mjs +0 -75
  53. package/src/link.ts +0 -177
  54. package/src/symbols.ts +0 -8
  55. package/src/view.ts +0 -95
@@ -0,0 +1,148 @@
1
+ import type {
2
+ RouteLayerOptions,
3
+ RouteLocationInput,
4
+ RouteMatchType,
5
+ RouterLinkType
6
+ } from '@esmx/router';
7
+ import { type PropType, defineComponent, h } from 'vue';
8
+ import { useLink } from './use';
9
+ import { isVue3 } from './util';
10
+
11
+ /**
12
+ * RouterLink component for navigation.
13
+ * Renders an anchor tag with proper navigation behavior and active state management.
14
+ *
15
+ * @param props - Component properties
16
+ * @param props.to - Target route location to navigate to
17
+ * @param props.type - Navigation type ('push' | 'replace' | 'pushWindow' | 'replaceWindow' | 'pushLayer')
18
+ * @param props.replace - Use type='replace' instead
19
+ * @param props.exact - How to match the active state ('include' | 'exact' | 'route')
20
+ * @param props.activeClass - CSS class to apply when link is active
21
+ * @param props.event - Event(s) that trigger navigation
22
+ * @param props.tag - Custom tag to render instead of 'a'
23
+ * @param props.layerOptions - Layer options for layer-based navigation
24
+ * @param slots - Component slots
25
+ * @param slots.default - Default slot content
26
+ * @returns Vue component instance
27
+ *
28
+ * @example
29
+ * ```vue
30
+ * <template>
31
+ * <nav>
32
+ * <!-- Basic navigation -->
33
+ * <RouterLink to="/home">Home</RouterLink>
34
+ * <RouterLink to="/about">About</RouterLink>
35
+ *
36
+ * <!-- With custom styling -->
37
+ * <RouterLink
38
+ * to="/dashboard"
39
+ * active-class="nav-active"
40
+ * >
41
+ * Dashboard
42
+ * </RouterLink>
43
+ *
44
+ * <!-- Replace navigation -->
45
+ * <RouterLink to="/login" type="replace">Login</RouterLink>
46
+ *
47
+ * <!-- Custom tag and exact matching -->
48
+ * <RouterLink
49
+ * to="/contact"
50
+ * exact="exact"
51
+ * tag="button"
52
+ * class="btn"
53
+ * >
54
+ * Contact
55
+ * </RouterLink>
56
+ * </nav>
57
+ * </template>
58
+ * ```
59
+ */
60
+ export const RouterLink = defineComponent({
61
+ name: 'RouterLink',
62
+ props: {
63
+ /**
64
+ * Target route location to navigate to.
65
+ * Can be a string path or route location object.
66
+ * @example '/home' | { path: '/user', query: { id: '123' } }
67
+ */
68
+ to: {
69
+ type: [String, Object] as PropType<RouteLocationInput>,
70
+ required: true
71
+ },
72
+ /**
73
+ * Navigation type for the link.
74
+ * @default 'push'
75
+ * @example 'push' | 'replace' | 'pushWindow' | 'replaceWindow' | 'pushLayer'
76
+ */
77
+ type: { type: String as PropType<RouterLinkType>, default: 'push' },
78
+ /**
79
+ * @deprecated Use 'type="replace"' instead
80
+ * @example replace={true} → type="replace"
81
+ */
82
+ replace: { type: Boolean, default: false },
83
+ /**
84
+ * How to match the active state.
85
+ * - 'include': Match if current route includes this path
86
+ * - 'exact': Match only if routes are exactly the same
87
+ * - 'route': Match based on route configuration
88
+ * @default 'include'
89
+ */
90
+ exact: { type: String as PropType<RouteMatchType>, default: 'include' },
91
+ /**
92
+ * CSS class to apply when link is active (route matches).
93
+ * @example 'nav-active' | 'selected'
94
+ */
95
+ activeClass: { type: String },
96
+ /**
97
+ * Event(s) that trigger navigation. Can be string or array of strings.
98
+ * @default 'click'
99
+ * @example 'click' | ['click', 'mouseenter']
100
+ */
101
+ event: {
102
+ type: [String, Array] as PropType<string | string[]>,
103
+ default: 'click'
104
+ },
105
+ /**
106
+ * Custom tag to render instead of 'a'.
107
+ * @default 'a'
108
+ * @example 'button' | 'div' | 'span'
109
+ */
110
+ tag: { type: String, default: 'a' },
111
+ /**
112
+ * Layer options for layer-based navigation.
113
+ * Only used when type='pushLayer'.
114
+ * @example { zIndex: 1000, autoPush: false, routerOptions: { mode: 'memory' } }
115
+ */
116
+ layerOptions: { type: Object as PropType<RouteLayerOptions> }
117
+ },
118
+
119
+ setup(props, { slots }) {
120
+ const link = useLink(props);
121
+
122
+ return () => {
123
+ const data = link.value;
124
+
125
+ // Generate event handlers with proper type transformation for Vue 2/3 compatibility
126
+ const eventHandlers = data.getEventHandlers(
127
+ isVue3
128
+ ? (name: string): string =>
129
+ `on${name.charAt(0).toUpperCase()}${name.slice(1)}`
130
+ : undefined
131
+ );
132
+
133
+ const props = {};
134
+ if (isVue3) {
135
+ Object.assign(props, data.attributes, eventHandlers);
136
+ } else {
137
+ const { class: className, ...attrs } = data.attributes;
138
+ Object.assign(props, {
139
+ attrs,
140
+ class: className,
141
+ on: eventHandlers
142
+ });
143
+ }
144
+
145
+ return h(data.tag, props, slots.default?.());
146
+ };
147
+ }
148
+ });