eleva 1.0.1 → 1.1.0
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/README.md +21 -10
- package/dist/{eleva-plugins.cjs.js → eleva-plugins.cjs} +1002 -292
- package/dist/eleva-plugins.cjs.map +1 -0
- package/dist/eleva-plugins.d.cts +1352 -0
- package/dist/eleva-plugins.d.cts.map +1 -0
- package/dist/eleva-plugins.d.ts +1352 -0
- package/dist/eleva-plugins.d.ts.map +1 -0
- package/dist/{eleva-plugins.esm.js → eleva-plugins.js} +1002 -292
- package/dist/eleva-plugins.js.map +1 -0
- package/dist/eleva-plugins.umd.js +1001 -291
- package/dist/eleva-plugins.umd.js.map +1 -1
- package/dist/eleva-plugins.umd.min.js +1 -1
- package/dist/eleva-plugins.umd.min.js.map +1 -1
- package/dist/{eleva.cjs.js → eleva.cjs} +421 -191
- package/dist/eleva.cjs.map +1 -0
- package/dist/eleva.d.cts +1329 -0
- package/dist/eleva.d.cts.map +1 -0
- package/dist/eleva.d.ts +473 -226
- package/dist/eleva.d.ts.map +1 -0
- package/dist/{eleva.esm.js → eleva.js} +422 -192
- package/dist/eleva.js.map +1 -0
- package/dist/eleva.umd.js +420 -190
- package/dist/eleva.umd.js.map +1 -1
- package/dist/eleva.umd.min.js +1 -1
- package/dist/eleva.umd.min.js.map +1 -1
- package/dist/plugins/attr.cjs +279 -0
- package/dist/plugins/attr.cjs.map +1 -0
- package/dist/plugins/attr.d.cts +101 -0
- package/dist/plugins/attr.d.cts.map +1 -0
- package/dist/plugins/attr.d.ts +101 -0
- package/dist/plugins/attr.d.ts.map +1 -0
- package/dist/plugins/attr.js +276 -0
- package/dist/plugins/attr.js.map +1 -0
- package/dist/plugins/attr.umd.js +111 -22
- package/dist/plugins/attr.umd.js.map +1 -1
- package/dist/plugins/attr.umd.min.js +1 -1
- package/dist/plugins/attr.umd.min.js.map +1 -1
- package/dist/plugins/router.cjs +1873 -0
- package/dist/plugins/router.cjs.map +1 -0
- package/dist/plugins/router.d.cts +1296 -0
- package/dist/plugins/router.d.cts.map +1 -0
- package/dist/plugins/router.d.ts +1296 -0
- package/dist/plugins/router.d.ts.map +1 -0
- package/dist/plugins/router.js +1870 -0
- package/dist/plugins/router.js.map +1 -0
- package/dist/plugins/router.umd.js +482 -186
- package/dist/plugins/router.umd.js.map +1 -1
- package/dist/plugins/router.umd.min.js +1 -1
- package/dist/plugins/router.umd.min.js.map +1 -1
- package/dist/plugins/store.cjs +920 -0
- package/dist/plugins/store.cjs.map +1 -0
- package/dist/plugins/store.d.cts +266 -0
- package/dist/plugins/store.d.cts.map +1 -0
- package/dist/plugins/store.d.ts +266 -0
- package/dist/plugins/store.d.ts.map +1 -0
- package/dist/plugins/store.js +917 -0
- package/dist/plugins/store.js.map +1 -0
- package/dist/plugins/store.umd.js +410 -85
- package/dist/plugins/store.umd.js.map +1 -1
- package/dist/plugins/store.umd.min.js +1 -1
- package/dist/plugins/store.umd.min.js.map +1 -1
- package/package.json +112 -68
- package/src/core/Eleva.js +195 -115
- package/src/index.cjs +10 -0
- package/src/index.js +11 -0
- package/src/modules/Emitter.js +68 -20
- package/src/modules/Renderer.js +82 -20
- package/src/modules/Signal.js +43 -15
- package/src/modules/TemplateEngine.js +50 -9
- package/src/plugins/Attr.js +121 -19
- package/src/plugins/Router.js +526 -181
- package/src/plugins/Store.js +448 -69
- package/src/plugins/index.js +1 -0
- package/types/core/Eleva.d.ts +263 -169
- package/types/core/Eleva.d.ts.map +1 -1
- package/types/index.d.cts +3 -0
- package/types/index.d.cts.map +1 -0
- package/types/index.d.ts +5 -0
- package/types/index.d.ts.map +1 -1
- package/types/modules/Emitter.d.ts +73 -30
- package/types/modules/Emitter.d.ts.map +1 -1
- package/types/modules/Renderer.d.ts +48 -18
- package/types/modules/Renderer.d.ts.map +1 -1
- package/types/modules/Signal.d.ts +44 -16
- package/types/modules/Signal.d.ts.map +1 -1
- package/types/modules/TemplateEngine.d.ts +46 -11
- package/types/modules/TemplateEngine.d.ts.map +1 -1
- package/types/plugins/Attr.d.ts +83 -16
- package/types/plugins/Attr.d.ts.map +1 -1
- package/types/plugins/Router.d.ts +498 -207
- package/types/plugins/Router.d.ts.map +1 -1
- package/types/plugins/Store.d.ts +211 -37
- package/types/plugins/Store.d.ts.map +1 -1
- package/dist/eleva-plugins.cjs.js.map +0 -1
- package/dist/eleva-plugins.esm.js.map +0 -1
- package/dist/eleva.cjs.js.map +0 -1
- package/dist/eleva.esm.js.map +0 -1
|
@@ -1,18 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for router plugins.
|
|
3
|
+
*/
|
|
1
4
|
export type RouterPlugin = {
|
|
2
5
|
/**
|
|
3
|
-
*
|
|
6
|
+
* Unique plugin identifier.
|
|
4
7
|
*/
|
|
5
8
|
name: string;
|
|
6
9
|
/**
|
|
7
|
-
*
|
|
10
|
+
* Plugin version (recommended to match router version).
|
|
8
11
|
*/
|
|
9
12
|
version?: string | undefined;
|
|
10
13
|
/**
|
|
11
|
-
*
|
|
14
|
+
* Installation function.
|
|
12
15
|
*/
|
|
13
|
-
install: (router: Router, options?: Record<string,
|
|
16
|
+
install: (router: Router, options?: Record<string, unknown>) => void;
|
|
14
17
|
/**
|
|
15
|
-
*
|
|
18
|
+
* Cleanup function called on router.destroy().
|
|
16
19
|
*/
|
|
17
20
|
destroy?: ((router: Router) => void | Promise<void>) | undefined;
|
|
18
21
|
};
|
|
@@ -23,16 +26,25 @@ export namespace RouterPlugin {
|
|
|
23
26
|
/**
|
|
24
27
|
* Installs the RouterPlugin into an Eleva instance.
|
|
25
28
|
*
|
|
26
|
-
* @
|
|
27
|
-
* @param {
|
|
28
|
-
* @param {
|
|
29
|
-
* @param {
|
|
30
|
-
* @param {
|
|
31
|
-
* @param {
|
|
32
|
-
* @param {string} [options.
|
|
33
|
-
* @param {
|
|
34
|
-
* @param {
|
|
35
|
-
* @param {
|
|
29
|
+
* @public
|
|
30
|
+
* @param {Eleva} eleva - The Eleva instance.
|
|
31
|
+
* @param {RouterOptions} options - Router configuration options.
|
|
32
|
+
* @param {string} options.mount - A CSS selector for the main element where the app is mounted.
|
|
33
|
+
* @param {RouteDefinition[]} options.routes - An array of route definitions.
|
|
34
|
+
* @param {'hash' | 'query' | 'history'} [options.mode='hash'] - The routing mode.
|
|
35
|
+
* @param {string} [options.queryParam='view'] - The query parameter to use in 'query' mode.
|
|
36
|
+
* @param {string} [options.viewSelector='view'] - Base selector for the view element (matched as #id, .class, [data-*], or raw selector).
|
|
37
|
+
* @param {boolean} [options.autoStart=true] - Whether to start the router automatically.
|
|
38
|
+
* @param {NavigationGuard} [options.onBeforeEach] - A global guard executed before every navigation.
|
|
39
|
+
* @param {RouteComponent} [options.globalLayout] - A global layout for all routes.
|
|
40
|
+
* @returns {Router} The created router instance.
|
|
41
|
+
* @throws {Error} If 'mount' option is not provided.
|
|
42
|
+
* @throws {Error} If 'routes' option is not an array.
|
|
43
|
+
* @throws {Error} If component registration fails during route processing.
|
|
44
|
+
* @description
|
|
45
|
+
* Registers route/layout components, sets `eleva.router`, and adds helpers
|
|
46
|
+
* (`eleva.navigate`, `eleva.getCurrentRoute`, `eleva.getRouteParams`, `eleva.getRouteQuery`).
|
|
47
|
+
* When `autoStart` is enabled, startup is scheduled via microtask.
|
|
36
48
|
*
|
|
37
49
|
* @example
|
|
38
50
|
* // main.js
|
|
@@ -54,18 +66,43 @@ export namespace RouterPlugin {
|
|
|
54
66
|
*/
|
|
55
67
|
function install(eleva: Eleva, options?: RouterOptions): Router;
|
|
56
68
|
/**
|
|
57
|
-
* Uninstalls the plugin from the Eleva instance
|
|
69
|
+
* Uninstalls the plugin from the Eleva instance.
|
|
58
70
|
*
|
|
59
|
-
* @
|
|
71
|
+
* @public
|
|
72
|
+
* @async
|
|
73
|
+
* @param {Eleva} eleva - The Eleva instance.
|
|
74
|
+
* @returns {Promise<void>}
|
|
75
|
+
* @description
|
|
76
|
+
* Destroys the router instance, removes `eleva.router`, and deletes helper methods
|
|
77
|
+
* (`eleva.navigate`, `eleva.getCurrentRoute`, `eleva.getRouteParams`, `eleva.getRouteQuery`).
|
|
60
78
|
*/
|
|
61
79
|
function uninstall(eleva: Eleva): Promise<void>;
|
|
62
80
|
}
|
|
63
81
|
export { RouterPlugin as Router };
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
export type
|
|
68
|
-
|
|
82
|
+
/**
|
|
83
|
+
* Type imports from the Eleva core library.
|
|
84
|
+
*/
|
|
85
|
+
export type Eleva = import("eleva").Eleva;
|
|
86
|
+
/**
|
|
87
|
+
* Type imports from the Eleva core library.
|
|
88
|
+
*/
|
|
89
|
+
export type ComponentDefinition = import("eleva").ComponentDefinition;
|
|
90
|
+
/**
|
|
91
|
+
* Type imports from the Eleva core library.
|
|
92
|
+
*/
|
|
93
|
+
export type Emitter = import("eleva").Emitter;
|
|
94
|
+
/**
|
|
95
|
+
* Type imports from the Eleva core library.
|
|
96
|
+
*/
|
|
97
|
+
export type MountResult = import("eleva").MountResult;
|
|
98
|
+
/**
|
|
99
|
+
* Type imports from the Eleva core library.
|
|
100
|
+
*/
|
|
101
|
+
export type UnsubscribeFunction = import("eleva").UnsubscribeFunction;
|
|
102
|
+
/**
|
|
103
|
+
* Generic type import.
|
|
104
|
+
*/
|
|
105
|
+
export type Signal<T> = import("eleva").Signal<T>;
|
|
69
106
|
/**
|
|
70
107
|
* The routing mode determines how the router manages URL state.
|
|
71
108
|
* - `hash`: Uses URL hash (e.g., `/#/path`) - works without server config
|
|
@@ -73,237 +110,359 @@ export type MountResult = any;
|
|
|
73
110
|
* - `query`: Uses query parameters (e.g., `?view=/path`) - useful for embedded apps
|
|
74
111
|
*/
|
|
75
112
|
export type RouterMode = "hash" | "history" | "query";
|
|
113
|
+
/**
|
|
114
|
+
* Route parameters extracted from the URL path.
|
|
115
|
+
*/
|
|
116
|
+
export type RouteParams = Record<string, string>;
|
|
117
|
+
/**
|
|
118
|
+
* Query parameters from the URL query string.
|
|
119
|
+
*/
|
|
120
|
+
export type QueryParams = Record<string, string>;
|
|
121
|
+
/**
|
|
122
|
+
* Navigation input parameters supporting multiple value types.
|
|
123
|
+
*/
|
|
124
|
+
export type NavigationParams = Record<string, string | number | boolean>;
|
|
125
|
+
/**
|
|
126
|
+
* Function signature for programmatic navigation.
|
|
127
|
+
*/
|
|
128
|
+
export type NavigateFunction = (location: string | NavigationTarget, params?: NavigationParams) => Promise<boolean>;
|
|
129
|
+
/**
|
|
130
|
+
* Router configuration options.
|
|
131
|
+
*/
|
|
76
132
|
export type RouterOptions = {
|
|
77
133
|
/**
|
|
78
|
-
*
|
|
134
|
+
* The routing mode to use.
|
|
79
135
|
*/
|
|
80
136
|
mode?: RouterMode | undefined;
|
|
81
137
|
/**
|
|
82
|
-
*
|
|
138
|
+
* Query parameter name for 'query' mode.
|
|
83
139
|
*/
|
|
84
140
|
queryParam?: string | undefined;
|
|
85
141
|
/**
|
|
86
|
-
*
|
|
142
|
+
* Base selector for the view element.
|
|
87
143
|
*/
|
|
88
144
|
viewSelector?: string | undefined;
|
|
89
145
|
/**
|
|
90
|
-
*
|
|
146
|
+
* CSS selector for the mount point element.
|
|
91
147
|
*/
|
|
92
148
|
mount: string;
|
|
93
149
|
/**
|
|
94
|
-
*
|
|
150
|
+
* Array of route definitions.
|
|
95
151
|
*/
|
|
96
152
|
routes: RouteDefinition[];
|
|
97
153
|
/**
|
|
98
|
-
*
|
|
154
|
+
* Default layout for all routes.
|
|
99
155
|
*/
|
|
100
|
-
globalLayout?:
|
|
156
|
+
globalLayout?: RouteComponent | undefined;
|
|
101
157
|
/**
|
|
102
|
-
*
|
|
158
|
+
* Global navigation guard.
|
|
103
159
|
*/
|
|
104
160
|
onBeforeEach?: NavigationGuard | undefined;
|
|
161
|
+
/**
|
|
162
|
+
* Whether to start the router automatically.
|
|
163
|
+
*/
|
|
164
|
+
autoStart?: boolean | undefined;
|
|
105
165
|
};
|
|
166
|
+
/**
|
|
167
|
+
* Object describing a navigation target for `router.navigate()`.
|
|
168
|
+
*/
|
|
106
169
|
export type NavigationTarget = {
|
|
107
170
|
/**
|
|
108
|
-
*
|
|
171
|
+
* The target path (can include params like '/users/:id').
|
|
109
172
|
*/
|
|
110
173
|
path: string;
|
|
111
174
|
/**
|
|
112
|
-
*
|
|
175
|
+
* Route parameters to inject.
|
|
113
176
|
*/
|
|
114
|
-
params?:
|
|
177
|
+
params?: NavigationParams | undefined;
|
|
115
178
|
/**
|
|
116
|
-
*
|
|
179
|
+
* Query parameters to append.
|
|
117
180
|
*/
|
|
118
|
-
query?:
|
|
181
|
+
query?: NavigationParams | undefined;
|
|
119
182
|
/**
|
|
120
|
-
*
|
|
183
|
+
* Whether to replace current history entry.
|
|
121
184
|
*/
|
|
122
185
|
replace?: boolean | undefined;
|
|
123
186
|
/**
|
|
124
|
-
*
|
|
187
|
+
* History state to pass.
|
|
125
188
|
*/
|
|
126
|
-
state?:
|
|
189
|
+
state?: unknown;
|
|
127
190
|
};
|
|
191
|
+
/**
|
|
192
|
+
* Saved scroll position.
|
|
193
|
+
*/
|
|
128
194
|
export type ScrollPosition = {
|
|
129
195
|
/**
|
|
130
|
-
*
|
|
196
|
+
* Horizontal scroll position.
|
|
131
197
|
*/
|
|
132
198
|
x: number;
|
|
133
199
|
/**
|
|
134
|
-
*
|
|
200
|
+
* Vertical scroll position.
|
|
135
201
|
*/
|
|
136
202
|
y: number;
|
|
137
203
|
};
|
|
204
|
+
/**
|
|
205
|
+
* Internal representation of a parsed route path segment.
|
|
206
|
+
*/
|
|
138
207
|
export type RouteSegment = {
|
|
139
208
|
/**
|
|
140
|
-
*
|
|
209
|
+
* The segment type.
|
|
141
210
|
*/
|
|
142
211
|
type: "static" | "param";
|
|
143
212
|
/**
|
|
144
|
-
*
|
|
213
|
+
* The segment value (static segments).
|
|
145
214
|
*/
|
|
146
|
-
value
|
|
215
|
+
value?: string | undefined;
|
|
147
216
|
/**
|
|
148
|
-
*
|
|
217
|
+
* The parameter name (param segments).
|
|
149
218
|
*/
|
|
150
219
|
name?: string | undefined;
|
|
151
220
|
};
|
|
221
|
+
/**
|
|
222
|
+
* Result of matching a path against route definitions.
|
|
223
|
+
*/
|
|
152
224
|
export type RouteMatch = {
|
|
153
225
|
/**
|
|
154
|
-
*
|
|
226
|
+
* The matched route definition.
|
|
155
227
|
*/
|
|
156
228
|
route: RouteDefinition;
|
|
157
229
|
/**
|
|
158
|
-
*
|
|
230
|
+
* The extracted route parameters.
|
|
159
231
|
*/
|
|
160
|
-
params:
|
|
232
|
+
params: RouteParams;
|
|
161
233
|
};
|
|
162
|
-
|
|
234
|
+
/**
|
|
235
|
+
* Arbitrary metadata attached to routes for use in guards and components.
|
|
236
|
+
*/
|
|
237
|
+
export type RouteMeta = Record<string, unknown>;
|
|
238
|
+
/**
|
|
239
|
+
* Interface for the router's error handling system.
|
|
240
|
+
*/
|
|
163
241
|
export type RouterErrorHandler = {
|
|
164
242
|
/**
|
|
165
|
-
*
|
|
243
|
+
* Throws a formatted error.
|
|
166
244
|
*/
|
|
167
|
-
handle: (error: Error, context: string, details?: Record<string,
|
|
245
|
+
handle: (error: Error, context: string, details?: Record<string, unknown>) => void;
|
|
168
246
|
/**
|
|
169
|
-
*
|
|
247
|
+
* Logs a warning.
|
|
170
248
|
*/
|
|
171
|
-
warn: (message: string, details?: Record<string,
|
|
249
|
+
warn: (message: string, details?: Record<string, unknown>) => void;
|
|
172
250
|
/**
|
|
173
|
-
*
|
|
251
|
+
* Logs an error without throwing.
|
|
174
252
|
*/
|
|
175
|
-
log: (message: string, error: Error, details?: Record<string,
|
|
253
|
+
log: (message: string, error: Error, details?: Record<string, unknown>) => void;
|
|
176
254
|
};
|
|
255
|
+
/**
|
|
256
|
+
* Callback for `router:beforeEach` event.
|
|
257
|
+
*/
|
|
177
258
|
export type NavigationContextCallback = (context: NavigationContext) => void | Promise<void>;
|
|
259
|
+
/**
|
|
260
|
+
* Callback for `router:beforeResolve` and `router:afterResolve` events.
|
|
261
|
+
*/
|
|
178
262
|
export type ResolveContextCallback = (context: ResolveContext) => void | Promise<void>;
|
|
263
|
+
/**
|
|
264
|
+
* Callback for `router:beforeRender` and `router:afterRender` events.
|
|
265
|
+
*/
|
|
179
266
|
export type RenderContextCallback = (context: RenderContext) => void | Promise<void>;
|
|
267
|
+
/**
|
|
268
|
+
* Callback for `router:scroll` event.
|
|
269
|
+
*/
|
|
180
270
|
export type ScrollContextCallback = (context: ScrollContext) => void | Promise<void>;
|
|
271
|
+
/**
|
|
272
|
+
* Callback for `router:afterEnter`, `router:afterLeave`, `router:afterEach` events.
|
|
273
|
+
*/
|
|
181
274
|
export type RouteChangeCallback = (to: RouteLocation, from: RouteLocation | null) => void | Promise<void>;
|
|
275
|
+
/**
|
|
276
|
+
* Router context injected into component setup as `ctx.router`.
|
|
277
|
+
*/
|
|
278
|
+
export type RouterContext = {
|
|
279
|
+
/**
|
|
280
|
+
* Programmatic navigation function.
|
|
281
|
+
*/
|
|
282
|
+
navigate: NavigateFunction;
|
|
283
|
+
/**
|
|
284
|
+
* Reactive signal for current route.
|
|
285
|
+
*/
|
|
286
|
+
current: Signal<RouteLocation | null>;
|
|
287
|
+
/**
|
|
288
|
+
* Reactive signal for previous route.
|
|
289
|
+
*/
|
|
290
|
+
previous: Signal<RouteLocation | null>;
|
|
291
|
+
/**
|
|
292
|
+
* Current route params (getter).
|
|
293
|
+
*/
|
|
294
|
+
params: RouteParams;
|
|
295
|
+
/**
|
|
296
|
+
* Current route query (getter).
|
|
297
|
+
*/
|
|
298
|
+
query: QueryParams;
|
|
299
|
+
/**
|
|
300
|
+
* Current route path (getter).
|
|
301
|
+
*/
|
|
302
|
+
path: string;
|
|
303
|
+
/**
|
|
304
|
+
* Current routed URL string (getter).
|
|
305
|
+
*/
|
|
306
|
+
fullUrl: string;
|
|
307
|
+
/**
|
|
308
|
+
* Current route meta (getter).
|
|
309
|
+
*/
|
|
310
|
+
meta: RouteMeta;
|
|
311
|
+
};
|
|
312
|
+
/**
|
|
313
|
+
* Callback for `router:error` event.
|
|
314
|
+
*/
|
|
182
315
|
export type RouterErrorCallback = (error: Error, to?: RouteLocation | undefined, from?: RouteLocation | null | undefined) => void | Promise<void>;
|
|
316
|
+
/**
|
|
317
|
+
* Callback for `router:ready` event.
|
|
318
|
+
*/
|
|
183
319
|
export type RouterReadyCallback = (router: Router) => void | Promise<void>;
|
|
320
|
+
/**
|
|
321
|
+
* Callback for `router:routeAdded` event.
|
|
322
|
+
*/
|
|
184
323
|
export type RouteAddedCallback = (route: RouteDefinition) => void | Promise<void>;
|
|
324
|
+
/**
|
|
325
|
+
* Callback for `router:routeRemoved` event.
|
|
326
|
+
*/
|
|
185
327
|
export type RouteRemovedCallback = (route: RouteDefinition) => void | Promise<void>;
|
|
328
|
+
/**
|
|
329
|
+
* Represents the current or target location in the router.
|
|
330
|
+
*/
|
|
186
331
|
export type RouteLocation = {
|
|
187
332
|
/**
|
|
188
|
-
*
|
|
333
|
+
* The path of the route (e.g., '/users/123').
|
|
189
334
|
*/
|
|
190
335
|
path: string;
|
|
191
336
|
/**
|
|
192
|
-
*
|
|
337
|
+
* Query parameters as key-value pairs.
|
|
193
338
|
*/
|
|
194
|
-
query:
|
|
339
|
+
query: QueryParams;
|
|
195
340
|
/**
|
|
196
|
-
*
|
|
341
|
+
* The routed URL string (path plus query).
|
|
197
342
|
*/
|
|
198
343
|
fullUrl: string;
|
|
199
344
|
/**
|
|
200
|
-
*
|
|
345
|
+
* Dynamic route parameters.
|
|
201
346
|
*/
|
|
202
|
-
params:
|
|
347
|
+
params: RouteParams;
|
|
203
348
|
/**
|
|
204
|
-
*
|
|
349
|
+
* Metadata associated with the matched route.
|
|
205
350
|
*/
|
|
206
351
|
meta: RouteMeta;
|
|
207
352
|
/**
|
|
208
|
-
*
|
|
353
|
+
* The optional name of the matched route.
|
|
209
354
|
*/
|
|
210
355
|
name?: string | undefined;
|
|
211
356
|
/**
|
|
212
|
-
*
|
|
357
|
+
* The raw route definition that was matched.
|
|
213
358
|
*/
|
|
214
359
|
matched: RouteDefinition;
|
|
215
360
|
};
|
|
216
361
|
/**
|
|
217
|
-
*
|
|
362
|
+
* Return value of a navigation guard.
|
|
218
363
|
* - `true` or `undefined/void`: Allow navigation
|
|
219
364
|
* - `false`: Abort navigation
|
|
220
365
|
* - `string`: Redirect to path
|
|
221
366
|
* - `NavigationTarget`: Redirect with options
|
|
222
367
|
*/
|
|
223
368
|
export type NavigationGuardResult = boolean | string | NavigationTarget | void;
|
|
369
|
+
/**
|
|
370
|
+
* Navigation guard function that controls navigation flow.
|
|
371
|
+
*/
|
|
224
372
|
export type NavigationGuard = (to: RouteLocation, from: RouteLocation | null) => NavigationGuardResult | Promise<NavigationGuardResult>;
|
|
373
|
+
/**
|
|
374
|
+
* Navigation hook for side effects. Does not affect navigation flow.
|
|
375
|
+
*/
|
|
225
376
|
export type NavigationHook = (to: RouteLocation, from: RouteLocation | null) => void | Promise<void>;
|
|
377
|
+
/**
|
|
378
|
+
* Context object for navigation events that plugins can modify.
|
|
379
|
+
*/
|
|
226
380
|
export type NavigationContext = {
|
|
227
381
|
/**
|
|
228
|
-
*
|
|
382
|
+
* The target route location.
|
|
229
383
|
*/
|
|
230
384
|
to: RouteLocation;
|
|
231
385
|
/**
|
|
232
|
-
*
|
|
386
|
+
* The source route location.
|
|
233
387
|
*/
|
|
234
388
|
from: RouteLocation | null;
|
|
235
389
|
/**
|
|
236
|
-
*
|
|
390
|
+
* Whether navigation has been cancelled.
|
|
237
391
|
*/
|
|
238
392
|
cancelled: boolean;
|
|
239
393
|
/**
|
|
240
|
-
*
|
|
394
|
+
* Redirect target if set.
|
|
241
395
|
*/
|
|
242
|
-
redirectTo: string |
|
|
243
|
-
path: string;
|
|
244
|
-
} | null;
|
|
396
|
+
redirectTo: string | NavigationTarget | null;
|
|
245
397
|
};
|
|
398
|
+
/**
|
|
399
|
+
* Context object for component resolution events.
|
|
400
|
+
*/
|
|
246
401
|
export type ResolveContext = {
|
|
247
402
|
/**
|
|
248
|
-
*
|
|
403
|
+
* The target route location.
|
|
249
404
|
*/
|
|
250
405
|
to: RouteLocation;
|
|
251
406
|
/**
|
|
252
|
-
*
|
|
407
|
+
* The source route location.
|
|
253
408
|
*/
|
|
254
409
|
from: RouteLocation | null;
|
|
255
410
|
/**
|
|
256
|
-
*
|
|
411
|
+
* The matched route definition.
|
|
257
412
|
*/
|
|
258
413
|
route: RouteDefinition;
|
|
259
414
|
/**
|
|
260
|
-
*
|
|
415
|
+
* The resolved layout component (available in afterResolve).
|
|
261
416
|
*/
|
|
262
417
|
layoutComponent: ComponentDefinition | null;
|
|
263
418
|
/**
|
|
264
|
-
*
|
|
419
|
+
* The resolved page component (available in afterResolve).
|
|
265
420
|
*/
|
|
266
421
|
pageComponent: ComponentDefinition | null;
|
|
267
422
|
/**
|
|
268
|
-
*
|
|
423
|
+
* Whether navigation has been cancelled.
|
|
269
424
|
*/
|
|
270
425
|
cancelled: boolean;
|
|
271
426
|
/**
|
|
272
|
-
*
|
|
427
|
+
* Redirect target if set.
|
|
273
428
|
*/
|
|
274
|
-
redirectTo: string |
|
|
275
|
-
path: string;
|
|
276
|
-
} | null;
|
|
429
|
+
redirectTo: string | NavigationTarget | null;
|
|
277
430
|
};
|
|
431
|
+
/**
|
|
432
|
+
* Context object for render events.
|
|
433
|
+
*/
|
|
278
434
|
export type RenderContext = {
|
|
279
435
|
/**
|
|
280
|
-
*
|
|
436
|
+
* The target route location.
|
|
281
437
|
*/
|
|
282
438
|
to: RouteLocation;
|
|
283
439
|
/**
|
|
284
|
-
*
|
|
440
|
+
* The source route location.
|
|
285
441
|
*/
|
|
286
442
|
from: RouteLocation | null;
|
|
287
443
|
/**
|
|
288
|
-
*
|
|
444
|
+
* The layout component being rendered.
|
|
289
445
|
*/
|
|
290
446
|
layoutComponent: ComponentDefinition | null;
|
|
291
447
|
/**
|
|
292
|
-
*
|
|
448
|
+
* The page component being rendered.
|
|
293
449
|
*/
|
|
294
450
|
pageComponent: ComponentDefinition;
|
|
295
451
|
};
|
|
452
|
+
/**
|
|
453
|
+
* Context object for scroll events.
|
|
454
|
+
*/
|
|
296
455
|
export type ScrollContext = {
|
|
297
456
|
/**
|
|
298
|
-
*
|
|
457
|
+
* The target route location.
|
|
299
458
|
*/
|
|
300
459
|
to: RouteLocation;
|
|
301
460
|
/**
|
|
302
|
-
*
|
|
461
|
+
* The source route location.
|
|
303
462
|
*/
|
|
304
463
|
from: RouteLocation | null;
|
|
305
464
|
/**
|
|
306
|
-
*
|
|
465
|
+
* Saved position (back/forward nav).
|
|
307
466
|
*/
|
|
308
467
|
savedPosition: {
|
|
309
468
|
x: number;
|
|
@@ -314,79 +473,95 @@ export type ScrollContext = {
|
|
|
314
473
|
* A component that can be rendered for a route.
|
|
315
474
|
* - `string`: Name of a registered component
|
|
316
475
|
* - `ComponentDefinition`: Inline component definition
|
|
317
|
-
* - `() =>
|
|
476
|
+
* - `() => ComponentDefinition`: Factory function returning a component
|
|
477
|
+
* - `() => Promise<ComponentDefinition>`: Async factory function
|
|
478
|
+
* - `() => Promise<{default: ComponentDefinition}>`: Lazy-loaded module (e.g., `() => import('./Page.js')`)
|
|
318
479
|
*/
|
|
319
|
-
export type RouteComponent = string | ComponentDefinition | (() => Promise<{
|
|
480
|
+
export type RouteComponent = string | ComponentDefinition | (() => ComponentDefinition | Promise<ComponentDefinition | {
|
|
320
481
|
default: ComponentDefinition;
|
|
321
482
|
}>);
|
|
483
|
+
/**
|
|
484
|
+
* Defines a route in the application.
|
|
485
|
+
*/
|
|
322
486
|
export type RouteDefinition = {
|
|
323
487
|
/**
|
|
324
|
-
*
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
488
|
+
* URL path pattern. Supports:
|
|
489
|
+
* - Static: '/about'
|
|
490
|
+
* - Dynamic params: '/users/:id'
|
|
491
|
+
* - Wildcard: '*' (catch-all, conventionally last)
|
|
328
492
|
*/
|
|
329
493
|
path: string;
|
|
330
494
|
/**
|
|
331
|
-
*
|
|
495
|
+
* The component to render for this route.
|
|
332
496
|
*/
|
|
333
497
|
component: RouteComponent;
|
|
334
498
|
/**
|
|
335
|
-
*
|
|
499
|
+
* Optional layout component to wrap the route component.
|
|
336
500
|
*/
|
|
337
|
-
layout?: RouteComponent;
|
|
501
|
+
layout?: RouteComponent | undefined;
|
|
338
502
|
/**
|
|
339
|
-
*
|
|
503
|
+
* Optional route name for programmatic navigation.
|
|
340
504
|
*/
|
|
341
505
|
name?: string | undefined;
|
|
342
506
|
/**
|
|
343
|
-
*
|
|
507
|
+
* Optional metadata (auth flags, titles, etc.).
|
|
344
508
|
*/
|
|
345
509
|
meta?: RouteMeta | undefined;
|
|
346
510
|
/**
|
|
347
|
-
*
|
|
511
|
+
* Route-specific guard before entering.
|
|
348
512
|
*/
|
|
349
513
|
beforeEnter?: NavigationGuard | undefined;
|
|
350
514
|
/**
|
|
351
|
-
*
|
|
515
|
+
* Hook after entering and component is mounted.
|
|
352
516
|
*/
|
|
353
517
|
afterEnter?: NavigationHook | undefined;
|
|
354
518
|
/**
|
|
355
|
-
*
|
|
519
|
+
* Guard before leaving this route.
|
|
356
520
|
*/
|
|
357
521
|
beforeLeave?: NavigationGuard | undefined;
|
|
358
522
|
/**
|
|
359
|
-
*
|
|
523
|
+
* Hook after leaving and component is unmounted.
|
|
360
524
|
*/
|
|
361
525
|
afterLeave?: NavigationHook | undefined;
|
|
362
526
|
/**
|
|
363
|
-
*
|
|
527
|
+
* Internal: parsed path segments (added by router).
|
|
364
528
|
*/
|
|
365
529
|
segments?: RouteSegment[] | undefined;
|
|
366
530
|
};
|
|
367
531
|
/**
|
|
532
|
+
* Represents the current or target location in the router.
|
|
368
533
|
* @typedef {Object} RouteLocation
|
|
369
|
-
* @property {string} path
|
|
370
|
-
*
|
|
371
|
-
* @property {
|
|
372
|
-
*
|
|
373
|
-
* @property {
|
|
374
|
-
*
|
|
375
|
-
* @property {
|
|
534
|
+
* @property {string} path
|
|
535
|
+
* The path of the route (e.g., '/users/123').
|
|
536
|
+
* @property {QueryParams} query
|
|
537
|
+
* Query parameters as key-value pairs.
|
|
538
|
+
* @property {string} fullUrl
|
|
539
|
+
* The routed URL string (path plus query).
|
|
540
|
+
* @property {RouteParams} params
|
|
541
|
+
* Dynamic route parameters.
|
|
542
|
+
* @property {RouteMeta} meta
|
|
543
|
+
* Metadata associated with the matched route.
|
|
544
|
+
* @property {string} [name]
|
|
545
|
+
* The optional name of the matched route.
|
|
546
|
+
* @property {RouteDefinition} matched
|
|
547
|
+
* The raw route definition that was matched.
|
|
376
548
|
* @description Represents the current or target location in the router.
|
|
377
549
|
*/
|
|
378
550
|
/**
|
|
379
|
-
*
|
|
380
|
-
* The return value of a navigation guard.
|
|
551
|
+
* Return value of a navigation guard.
|
|
381
552
|
* - `true` or `undefined/void`: Allow navigation
|
|
382
553
|
* - `false`: Abort navigation
|
|
383
554
|
* - `string`: Redirect to path
|
|
384
555
|
* - `NavigationTarget`: Redirect with options
|
|
556
|
+
* @typedef {boolean | string | NavigationTarget | void} NavigationGuardResult
|
|
385
557
|
*/
|
|
386
558
|
/**
|
|
559
|
+
* Navigation guard function that controls navigation flow.
|
|
387
560
|
* @callback NavigationGuard
|
|
388
|
-
* @param {RouteLocation} to
|
|
389
|
-
*
|
|
561
|
+
* @param {RouteLocation} to
|
|
562
|
+
* The target route location.
|
|
563
|
+
* @param {RouteLocation | null} from
|
|
564
|
+
* The source route location (null on initial).
|
|
390
565
|
* @returns {NavigationGuardResult | Promise<NavigationGuardResult>}
|
|
391
566
|
* @description A function that controls navigation flow. Runs before navigation is confirmed.
|
|
392
567
|
* @example
|
|
@@ -399,9 +574,12 @@ export type RouteDefinition = {
|
|
|
399
574
|
* };
|
|
400
575
|
*/
|
|
401
576
|
/**
|
|
577
|
+
* Navigation hook for side effects. Does not affect navigation flow.
|
|
402
578
|
* @callback NavigationHook
|
|
403
|
-
* @param {RouteLocation} to
|
|
404
|
-
*
|
|
579
|
+
* @param {RouteLocation} to
|
|
580
|
+
* The target route location.
|
|
581
|
+
* @param {RouteLocation | null} from
|
|
582
|
+
* The source route location.
|
|
405
583
|
* @returns {void | Promise<void>}
|
|
406
584
|
* @description A lifecycle hook for side effects. Does not affect navigation flow.
|
|
407
585
|
* @example
|
|
@@ -411,11 +589,16 @@ export type RouteDefinition = {
|
|
|
411
589
|
* };
|
|
412
590
|
*/
|
|
413
591
|
/**
|
|
592
|
+
* Interface for router plugins.
|
|
414
593
|
* @typedef {Object} RouterPlugin
|
|
415
|
-
* @property {string} name
|
|
416
|
-
*
|
|
417
|
-
* @property {
|
|
418
|
-
*
|
|
594
|
+
* @property {string} name
|
|
595
|
+
* Unique plugin identifier.
|
|
596
|
+
* @property {string} [version]
|
|
597
|
+
* Plugin version (recommended to match router version).
|
|
598
|
+
* @property {(router: Router, options?: Record<string, unknown>) => void} install
|
|
599
|
+
* Installation function.
|
|
600
|
+
* @property {(router: Router) => void | Promise<void>} [destroy]
|
|
601
|
+
* Cleanup function called on router.destroy().
|
|
419
602
|
* @description Interface for router plugins. Plugins can extend router functionality.
|
|
420
603
|
* @example
|
|
421
604
|
* const AnalyticsPlugin = {
|
|
@@ -429,62 +612,98 @@ export type RouteDefinition = {
|
|
|
429
612
|
* };
|
|
430
613
|
*/
|
|
431
614
|
/**
|
|
615
|
+
* Context object for navigation events that plugins can modify.
|
|
432
616
|
* @typedef {Object} NavigationContext
|
|
433
|
-
* @property {RouteLocation} to
|
|
434
|
-
*
|
|
435
|
-
* @property {
|
|
436
|
-
*
|
|
437
|
-
* @
|
|
617
|
+
* @property {RouteLocation} to
|
|
618
|
+
* The target route location.
|
|
619
|
+
* @property {RouteLocation | null} from
|
|
620
|
+
* The source route location.
|
|
621
|
+
* @property {boolean} cancelled
|
|
622
|
+
* Whether navigation has been cancelled.
|
|
623
|
+
* @property {string | NavigationTarget | null} redirectTo
|
|
624
|
+
* Redirect target if set.
|
|
625
|
+
* @description Passed to navigation events. Plugins can modify to control navigation flow.
|
|
438
626
|
*/
|
|
439
627
|
/**
|
|
628
|
+
* Context object for component resolution events.
|
|
440
629
|
* @typedef {Object} ResolveContext
|
|
441
|
-
* @property {RouteLocation} to
|
|
442
|
-
*
|
|
443
|
-
* @property {
|
|
444
|
-
*
|
|
445
|
-
* @property {
|
|
446
|
-
*
|
|
447
|
-
* @property {
|
|
448
|
-
*
|
|
630
|
+
* @property {RouteLocation} to
|
|
631
|
+
* The target route location.
|
|
632
|
+
* @property {RouteLocation | null} from
|
|
633
|
+
* The source route location.
|
|
634
|
+
* @property {RouteDefinition} route
|
|
635
|
+
* The matched route definition.
|
|
636
|
+
* @property {ComponentDefinition | null} layoutComponent
|
|
637
|
+
* The resolved layout component (available in afterResolve).
|
|
638
|
+
* @property {ComponentDefinition | null} pageComponent
|
|
639
|
+
* The resolved page component (available in afterResolve).
|
|
640
|
+
* @property {boolean} cancelled
|
|
641
|
+
* Whether navigation has been cancelled.
|
|
642
|
+
* @property {string | NavigationTarget | null} redirectTo
|
|
643
|
+
* Redirect target if set.
|
|
644
|
+
* @description Passed to component resolution events.
|
|
449
645
|
*/
|
|
450
646
|
/**
|
|
647
|
+
* Context object for render events.
|
|
451
648
|
* @typedef {Object} RenderContext
|
|
452
|
-
* @property {RouteLocation} to
|
|
453
|
-
*
|
|
454
|
-
* @property {
|
|
455
|
-
*
|
|
456
|
-
* @
|
|
649
|
+
* @property {RouteLocation} to
|
|
650
|
+
* The target route location.
|
|
651
|
+
* @property {RouteLocation | null} from
|
|
652
|
+
* The source route location.
|
|
653
|
+
* @property {ComponentDefinition | null} layoutComponent
|
|
654
|
+
* The layout component being rendered.
|
|
655
|
+
* @property {ComponentDefinition} pageComponent
|
|
656
|
+
* The page component being rendered.
|
|
657
|
+
* @description Passed to render events.
|
|
457
658
|
*/
|
|
458
659
|
/**
|
|
660
|
+
* Context object for scroll events.
|
|
459
661
|
* @typedef {Object} ScrollContext
|
|
460
|
-
* @property {RouteLocation} to
|
|
461
|
-
*
|
|
462
|
-
* @property {
|
|
463
|
-
*
|
|
662
|
+
* @property {RouteLocation} to
|
|
663
|
+
* The target route location.
|
|
664
|
+
* @property {RouteLocation | null} from
|
|
665
|
+
* The source route location.
|
|
666
|
+
* @property {{x: number, y: number} | null} savedPosition
|
|
667
|
+
* Saved position (back/forward nav).
|
|
668
|
+
* @description Passed to scroll events for plugins to handle scroll behavior.
|
|
464
669
|
*/
|
|
465
670
|
/**
|
|
466
|
-
* @typedef {string | ComponentDefinition | (() => Promise<{default: ComponentDefinition}>)} RouteComponent
|
|
467
671
|
* A component that can be rendered for a route.
|
|
468
672
|
* - `string`: Name of a registered component
|
|
469
673
|
* - `ComponentDefinition`: Inline component definition
|
|
470
|
-
* - `() =>
|
|
674
|
+
* - `() => ComponentDefinition`: Factory function returning a component
|
|
675
|
+
* - `() => Promise<ComponentDefinition>`: Async factory function
|
|
676
|
+
* - `() => Promise<{default: ComponentDefinition}>`: Lazy-loaded module (e.g., `() => import('./Page.js')`)
|
|
677
|
+
* @typedef {string | ComponentDefinition | (() => ComponentDefinition | Promise<ComponentDefinition | {default: ComponentDefinition}>)} RouteComponent
|
|
471
678
|
*/
|
|
472
679
|
/**
|
|
680
|
+
* Defines a route in the application.
|
|
473
681
|
* @typedef {Object} RouteDefinition
|
|
474
|
-
* @property {string} path
|
|
475
|
-
*
|
|
476
|
-
*
|
|
477
|
-
*
|
|
478
|
-
*
|
|
479
|
-
* @property {RouteComponent}
|
|
480
|
-
*
|
|
481
|
-
* @property {
|
|
482
|
-
*
|
|
483
|
-
* @property {
|
|
484
|
-
*
|
|
485
|
-
* @property {
|
|
486
|
-
*
|
|
682
|
+
* @property {string} path
|
|
683
|
+
* URL path pattern. Supports:
|
|
684
|
+
* - Static: '/about'
|
|
685
|
+
* - Dynamic params: '/users/:id'
|
|
686
|
+
* - Wildcard: '*' (catch-all, conventionally last)
|
|
687
|
+
* @property {RouteComponent} component
|
|
688
|
+
* The component to render for this route.
|
|
689
|
+
* @property {RouteComponent} [layout]
|
|
690
|
+
* Optional layout component to wrap the route component.
|
|
691
|
+
* @property {string} [name]
|
|
692
|
+
* Optional route name for programmatic navigation.
|
|
693
|
+
* @property {RouteMeta} [meta]
|
|
694
|
+
* Optional metadata (auth flags, titles, etc.).
|
|
695
|
+
* @property {NavigationGuard} [beforeEnter]
|
|
696
|
+
* Route-specific guard before entering.
|
|
697
|
+
* @property {NavigationHook} [afterEnter]
|
|
698
|
+
* Hook after entering and component is mounted.
|
|
699
|
+
* @property {NavigationGuard} [beforeLeave]
|
|
700
|
+
* Guard before leaving this route.
|
|
701
|
+
* @property {NavigationHook} [afterLeave]
|
|
702
|
+
* Hook after leaving and component is unmounted.
|
|
703
|
+
* @property {RouteSegment[]} [segments]
|
|
704
|
+
* Internal: parsed path segments (added by router).
|
|
487
705
|
* @description Defines a route in the application.
|
|
706
|
+
* @note Nested routes are not supported. Use shared layouts with flat routes instead.
|
|
488
707
|
* @example
|
|
489
708
|
* // Static route
|
|
490
709
|
* { path: '/about', component: AboutPage }
|
|
@@ -500,11 +719,11 @@ export type RouteDefinition = {
|
|
|
500
719
|
* beforeEnter: (to, from) => isLoggedIn() || '/login'
|
|
501
720
|
* }
|
|
502
721
|
*
|
|
503
|
-
* // Catch-all 404 route (
|
|
722
|
+
* // Catch-all 404 route (conventionally last)
|
|
504
723
|
* { path: '*', component: NotFoundPage }
|
|
505
724
|
*/
|
|
506
725
|
/**
|
|
507
|
-
* @class Router
|
|
726
|
+
* @class 🛤️ Router
|
|
508
727
|
* @classdesc A powerful, reactive, and flexible Router Plugin for Eleva.
|
|
509
728
|
* This class manages all routing logic, including state, navigation, and rendering.
|
|
510
729
|
*
|
|
@@ -530,15 +749,15 @@ export type RouteDefinition = {
|
|
|
530
749
|
* | `router:scroll` | {@link ScrollContextCallback} | No | For scroll behavior |
|
|
531
750
|
* | `router:afterEnter` | {@link RouteChangeCallback} | No | After entering route |
|
|
532
751
|
* | `router:afterEach` | {@link RouteChangeCallback} | No | Navigation complete |
|
|
533
|
-
* | `router:
|
|
752
|
+
* | `router:error` | {@link RouterErrorCallback} | No | Navigation error |
|
|
534
753
|
* | `router:routeAdded` | {@link RouteAddedCallback} | No | Dynamic route added |
|
|
535
754
|
* | `router:routeRemoved` | {@link RouteRemovedCallback} | No | Dynamic route removed |
|
|
536
755
|
*
|
|
537
756
|
* ## Reactive Signals
|
|
538
757
|
* - `currentRoute: Signal<RouteLocation | null>` - Current route info
|
|
539
758
|
* - `previousRoute: Signal<RouteLocation | null>` - Previous route info
|
|
540
|
-
* - `currentParams: Signal<
|
|
541
|
-
* - `currentQuery: Signal<
|
|
759
|
+
* - `currentParams: Signal<RouteParams>` - Current route params
|
|
760
|
+
* - `currentQuery: Signal<QueryParams>` - Current query params
|
|
542
761
|
* - `currentLayout: Signal<MountResult | null>` - Mounted layout instance
|
|
543
762
|
* - `currentView: Signal<MountResult | null>` - Mounted view instance
|
|
544
763
|
* - `isReady: Signal<boolean>` - Router readiness state
|
|
@@ -579,6 +798,7 @@ declare class Router {
|
|
|
579
798
|
* Creates an instance of the Router.
|
|
580
799
|
* @param {Eleva} eleva - The Eleva framework instance.
|
|
581
800
|
* @param {RouterOptions} options - The configuration options for the router.
|
|
801
|
+
* @throws {Error} If the routing mode is invalid.
|
|
582
802
|
*/
|
|
583
803
|
constructor(eleva: Eleva, options?: RouterOptions);
|
|
584
804
|
/** @type {Eleva} The Eleva framework instance. */
|
|
@@ -587,7 +807,7 @@ declare class Router {
|
|
|
587
807
|
options: RouterOptions;
|
|
588
808
|
/** @private @type {RouteDefinition[]} The processed list of route definitions. */
|
|
589
809
|
private routes;
|
|
590
|
-
/** @private @type {
|
|
810
|
+
/** @private @type {Emitter} The shared Eleva event emitter for global hooks. */
|
|
591
811
|
private emitter;
|
|
592
812
|
/** @private @type {boolean} A flag indicating if the router has been started. */
|
|
593
813
|
private isStarted;
|
|
@@ -595,32 +815,28 @@ declare class Router {
|
|
|
595
815
|
private _isNavigating;
|
|
596
816
|
/** @private @type {number} Counter for tracking navigation operations to prevent race conditions. */
|
|
597
817
|
private _navigationId;
|
|
598
|
-
/** @private @type {
|
|
818
|
+
/** @private @type {UnsubscribeFunction[]} A collection of cleanup functions for event listeners. */
|
|
599
819
|
private eventListeners;
|
|
600
820
|
/** @type {Signal<RouteLocation | null>} A reactive signal holding the current route's information. */
|
|
601
821
|
currentRoute: Signal<RouteLocation | null>;
|
|
602
822
|
/** @type {Signal<RouteLocation | null>} A reactive signal holding the previous route's information. */
|
|
603
823
|
previousRoute: Signal<RouteLocation | null>;
|
|
604
|
-
/** @type {Signal<
|
|
605
|
-
currentParams: Signal<
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
/** @type {Signal<
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
/** @type {Signal<import('eleva').MountResult | null>} A reactive signal for the currently mounted layout instance. */
|
|
613
|
-
currentLayout: Signal<any | null>;
|
|
614
|
-
/** @type {Signal<import('eleva').MountResult | null>} A reactive signal for the currently mounted view (page) instance. */
|
|
615
|
-
currentView: Signal<any | null>;
|
|
824
|
+
/** @type {Signal<RouteParams>} A reactive signal holding the current route's parameters. */
|
|
825
|
+
currentParams: Signal<RouteParams>;
|
|
826
|
+
/** @type {Signal<QueryParams>} A reactive signal holding the current route's query parameters. */
|
|
827
|
+
currentQuery: Signal<QueryParams>;
|
|
828
|
+
/** @type {Signal<MountResult | null>} A reactive signal for the currently mounted layout instance. */
|
|
829
|
+
currentLayout: Signal<MountResult | null>;
|
|
830
|
+
/** @type {Signal<MountResult | null>} A reactive signal for the currently mounted view (page) instance. */
|
|
831
|
+
currentView: Signal<MountResult | null>;
|
|
616
832
|
/** @type {Signal<boolean>} A reactive signal indicating if the router is ready (started and initial navigation complete). */
|
|
617
833
|
isReady: Signal<boolean>;
|
|
618
834
|
/** @private @type {Map<string, RouterPlugin>} Map of registered plugins by name. */
|
|
619
835
|
private plugins;
|
|
620
|
-
/** @private @type {
|
|
836
|
+
/** @private @type {NavigationGuard[]} Array of global before-each navigation guards. */
|
|
621
837
|
private _beforeEachGuards;
|
|
622
|
-
/** @type {
|
|
623
|
-
errorHandler:
|
|
838
|
+
/** @type {RouterErrorHandler} The error handler instance. Can be overridden by plugins. */
|
|
839
|
+
errorHandler: RouterErrorHandler;
|
|
624
840
|
/** @private @type {Map<string, {x: number, y: number}>} Saved scroll positions by route path. */
|
|
625
841
|
private _scrollPositions;
|
|
626
842
|
/**
|
|
@@ -640,7 +856,7 @@ declare class Router {
|
|
|
640
856
|
* Parses a route path string into an array of static and parameter segments.
|
|
641
857
|
* @private
|
|
642
858
|
* @param {string} path - The path pattern to parse.
|
|
643
|
-
* @returns {
|
|
859
|
+
* @returns {{type: 'static' | 'param', value?: string, name?: string}[]} An array of segment objects.
|
|
644
860
|
* @throws {Error} If the route path is not a valid string.
|
|
645
861
|
*/
|
|
646
862
|
private _parsePathIntoSegments;
|
|
@@ -654,6 +870,11 @@ declare class Router {
|
|
|
654
870
|
/**
|
|
655
871
|
* Starts the router, initializes event listeners, and performs the initial navigation.
|
|
656
872
|
* @returns {Promise<Router>} The router instance for method chaining.
|
|
873
|
+
* @listens window:hashchange In hash mode, triggers route changes.
|
|
874
|
+
* @listens window:popstate In history/query mode, triggers route changes.
|
|
875
|
+
* @emits router:ready When initialization completes successfully.
|
|
876
|
+
* @see destroy - Stop the router and clean up listeners.
|
|
877
|
+
* @see navigate - Programmatically navigate to a route.
|
|
657
878
|
*
|
|
658
879
|
* @example
|
|
659
880
|
* // Basic usage
|
|
@@ -669,13 +890,17 @@ declare class Router {
|
|
|
669
890
|
*/
|
|
670
891
|
start(): Promise<Router>;
|
|
671
892
|
/**
|
|
672
|
-
* Stops the router and cleans up
|
|
893
|
+
* Stops the router and cleans up event listeners.
|
|
894
|
+
* Unmounts the current layout instance if present.
|
|
895
|
+
* @async
|
|
673
896
|
* @returns {Promise<void>}
|
|
897
|
+
* @see start - Restart the router after destroying.
|
|
674
898
|
*/
|
|
675
899
|
destroy(): Promise<void>;
|
|
676
900
|
/**
|
|
677
901
|
* Alias for destroy(). Stops the router and cleans up all resources.
|
|
678
902
|
* Provided for semantic consistency (start/stop pattern).
|
|
903
|
+
* @async
|
|
679
904
|
* @returns {Promise<void>}
|
|
680
905
|
*
|
|
681
906
|
* @example
|
|
@@ -686,9 +911,13 @@ declare class Router {
|
|
|
686
911
|
stop(): Promise<void>;
|
|
687
912
|
/**
|
|
688
913
|
* Programmatically navigates to a new route.
|
|
914
|
+
* @async
|
|
689
915
|
* @param {string | NavigationTarget} location - The target location as a path string or navigation target object.
|
|
690
|
-
* @param {
|
|
916
|
+
* @param {NavigationParams} [params] - Route parameters (only used when location is a string).
|
|
691
917
|
* @returns {Promise<boolean>} True if navigation succeeded, false if blocked by guards or failed.
|
|
918
|
+
* @emits router:error When navigation fails due to an exception.
|
|
919
|
+
* @see start - Initialize the router before navigating.
|
|
920
|
+
* @see currentRoute - Access the current route after navigation.
|
|
692
921
|
*
|
|
693
922
|
* @example
|
|
694
923
|
* // Basic navigation
|
|
@@ -708,7 +937,7 @@ declare class Router {
|
|
|
708
937
|
* replace: true
|
|
709
938
|
* });
|
|
710
939
|
*/
|
|
711
|
-
navigate(location: string | NavigationTarget, params?:
|
|
940
|
+
navigate(location: string | NavigationTarget, params?: NavigationParams): Promise<boolean>;
|
|
712
941
|
/**
|
|
713
942
|
* Builds a URL for query mode.
|
|
714
943
|
* @private
|
|
@@ -722,37 +951,54 @@ declare class Router {
|
|
|
722
951
|
* @param {string} path - The target path with query string.
|
|
723
952
|
* @param {object} params - The target params.
|
|
724
953
|
* @param {object} query - The target query.
|
|
725
|
-
* @returns {boolean}
|
|
954
|
+
* @returns {boolean} True if the routes are the same.
|
|
726
955
|
*/
|
|
727
956
|
private _isSameRoute;
|
|
728
957
|
/**
|
|
729
958
|
* Injects dynamic parameters into a path string.
|
|
959
|
+
* Replaces `:param` placeholders with URL-encoded values from the params object.
|
|
960
|
+
*
|
|
730
961
|
* @private
|
|
962
|
+
* @param {string} path - The path pattern containing `:param` placeholders.
|
|
963
|
+
* @param {RouteParams} params - Key-value pairs to inject into the path.
|
|
964
|
+
* @returns {string} The path with all parameters replaced.
|
|
965
|
+
*
|
|
966
|
+
* @example
|
|
967
|
+
* this._buildPath('/users/:id/posts/:postId', { id: '123', postId: '456' });
|
|
968
|
+
* // Returns: '/users/123/posts/456'
|
|
731
969
|
*/
|
|
732
970
|
private _buildPath;
|
|
733
971
|
/**
|
|
734
972
|
* The handler for browser-initiated route changes (e.g., back/forward buttons).
|
|
973
|
+
*
|
|
735
974
|
* @private
|
|
975
|
+
* @async
|
|
736
976
|
* @param {boolean} [isPopState=true] - Whether this is a popstate event (back/forward navigation).
|
|
977
|
+
* @returns {Promise<void>}
|
|
978
|
+
* @emits router:error When route change handling fails.
|
|
737
979
|
*/
|
|
738
980
|
private _handleRouteChange;
|
|
739
981
|
/**
|
|
740
982
|
* Manages the core navigation lifecycle. Runs guards before committing changes.
|
|
741
|
-
* Emits lifecycle events that plugins can hook into:
|
|
742
|
-
* - router:beforeEach - Before guards run (can block/redirect via context)
|
|
743
|
-
* - router:beforeResolve - Before component resolution (can block/redirect)
|
|
744
|
-
* - router:afterResolve - After components are resolved
|
|
745
|
-
* - router:beforeRender - Before DOM rendering
|
|
746
|
-
* - router:afterRender - After DOM rendering
|
|
747
|
-
* - router:scroll - After render, for scroll behavior
|
|
748
|
-
* - router:afterEnter - After entering a route
|
|
749
|
-
* - router:afterLeave - After leaving a route
|
|
750
|
-
* - router:afterEach - After navigation completes
|
|
751
983
|
*
|
|
752
984
|
* @private
|
|
985
|
+
* @async
|
|
753
986
|
* @param {string} fullPath - The full path (e.g., '/users/123?foo=bar') to navigate to.
|
|
754
987
|
* @param {boolean} [isPopState=false] - Whether this navigation was triggered by popstate (back/forward).
|
|
755
|
-
* @returns {Promise<boolean>}
|
|
988
|
+
* @returns {Promise<boolean>} `true` if navigation succeeded, `false` if aborted.
|
|
989
|
+
* @emits router:notFound When no matching route is found.
|
|
990
|
+
* @emits router:beforeResolve Before component resolution (can block/redirect).
|
|
991
|
+
* @emits router:afterResolve After components are resolved.
|
|
992
|
+
* @emits router:afterLeave After leaving the previous route.
|
|
993
|
+
* @emits router:beforeRender Before DOM rendering.
|
|
994
|
+
* @emits router:afterRender After DOM rendering completes.
|
|
995
|
+
* @emits router:scroll After render, for scroll behavior handling.
|
|
996
|
+
* @emits router:afterEnter After entering the new route.
|
|
997
|
+
* @emits router:afterEach After navigation completes successfully.
|
|
998
|
+
* @emits router:error When an error occurs during navigation.
|
|
999
|
+
* @see _runGuards - Guard execution.
|
|
1000
|
+
* @see _resolveComponents - Component resolution.
|
|
1001
|
+
* @see _render - DOM rendering.
|
|
756
1002
|
*/
|
|
757
1003
|
private _proceedWithNavigation;
|
|
758
1004
|
/**
|
|
@@ -767,7 +1013,8 @@ declare class Router {
|
|
|
767
1013
|
* @param {RouteLocation} to - The target route location.
|
|
768
1014
|
* @param {RouteLocation | null} from - The current route location (null on initial navigation).
|
|
769
1015
|
* @param {RouteDefinition} route - The matched route definition.
|
|
770
|
-
* @returns {Promise<boolean>}
|
|
1016
|
+
* @returns {Promise<boolean>} `false` if navigation should be aborted.
|
|
1017
|
+
* @emits router:beforeEach Before guards run (can block/redirect via context).
|
|
771
1018
|
*/
|
|
772
1019
|
private _runGuards;
|
|
773
1020
|
/**
|
|
@@ -786,7 +1033,8 @@ declare class Router {
|
|
|
786
1033
|
/**
|
|
787
1034
|
* Resolves a function component definition to a component object.
|
|
788
1035
|
* @private
|
|
789
|
-
* @
|
|
1036
|
+
* @async
|
|
1037
|
+
* @param {() => ComponentDefinition | Promise<ComponentDefinition | { default: ComponentDefinition }>} def - The function to resolve.
|
|
790
1038
|
* @returns {Promise<ComponentDefinition>} The resolved component.
|
|
791
1039
|
* @throws {Error} If the function fails to load the component.
|
|
792
1040
|
*/
|
|
@@ -794,7 +1042,7 @@ declare class Router {
|
|
|
794
1042
|
/**
|
|
795
1043
|
* Validates a component definition object.
|
|
796
1044
|
* @private
|
|
797
|
-
* @param {
|
|
1045
|
+
* @param {unknown} def - The component definition to validate.
|
|
798
1046
|
* @returns {ComponentDefinition} The validated component.
|
|
799
1047
|
* @throws {Error} If the component definition is invalid.
|
|
800
1048
|
*/
|
|
@@ -802,30 +1050,47 @@ declare class Router {
|
|
|
802
1050
|
/**
|
|
803
1051
|
* Resolves a component definition to a component object.
|
|
804
1052
|
* @private
|
|
805
|
-
* @param {
|
|
1053
|
+
* @param {unknown} def - The component definition to resolve.
|
|
806
1054
|
* @returns {Promise<ComponentDefinition | null>} The resolved component or null.
|
|
807
1055
|
*/
|
|
808
1056
|
private _resolveComponent;
|
|
809
1057
|
/**
|
|
810
1058
|
* Asynchronously resolves the layout and page components for a route.
|
|
811
1059
|
* @private
|
|
1060
|
+
* @async
|
|
812
1061
|
* @param {RouteDefinition} route - The route to resolve components for.
|
|
813
1062
|
* @returns {Promise<{layoutComponent: ComponentDefinition | null, pageComponent: ComponentDefinition}>}
|
|
1063
|
+
* @throws {Error} If page component cannot be resolved.
|
|
814
1064
|
*/
|
|
815
1065
|
private _resolveComponents;
|
|
816
1066
|
/**
|
|
817
1067
|
* Renders the components for the current route into the DOM.
|
|
1068
|
+
*
|
|
1069
|
+
* Rendering algorithm:
|
|
1070
|
+
* 1. Find the mount element using options.mount selector
|
|
1071
|
+
* 2. If layoutComponent exists:
|
|
1072
|
+
* a. Mount layout to mount element
|
|
1073
|
+
* b. Find view element within layout (using viewSelector)
|
|
1074
|
+
* c. Mount page component to view element
|
|
1075
|
+
* 3. If no layoutComponent:
|
|
1076
|
+
* a. Mount page component directly to mount element
|
|
1077
|
+
* b. Set currentLayout to null
|
|
1078
|
+
*
|
|
818
1079
|
* @private
|
|
1080
|
+
* @async
|
|
819
1081
|
* @param {ComponentDefinition | null} layoutComponent - The pre-loaded layout component.
|
|
820
1082
|
* @param {ComponentDefinition} pageComponent - The pre-loaded page component.
|
|
1083
|
+
* @returns {Promise<void>}
|
|
1084
|
+
* @throws {Error} If mount element is not found in the DOM.
|
|
1085
|
+
* @throws {Error} If component mounting fails (propagated from eleva.mount).
|
|
821
1086
|
*/
|
|
822
1087
|
private _render;
|
|
823
1088
|
/**
|
|
824
1089
|
* Creates a getter function for router context properties.
|
|
825
1090
|
* @private
|
|
826
1091
|
* @param {string} property - The property name to access.
|
|
827
|
-
* @param {
|
|
828
|
-
* @returns {
|
|
1092
|
+
* @param {unknown} defaultValue - The default value if property is undefined.
|
|
1093
|
+
* @returns {() => unknown} A getter function.
|
|
829
1094
|
*/
|
|
830
1095
|
private _createRouteGetter;
|
|
831
1096
|
/**
|
|
@@ -837,9 +1102,13 @@ declare class Router {
|
|
|
837
1102
|
private _wrapComponent;
|
|
838
1103
|
/**
|
|
839
1104
|
* Recursively wraps all child components to ensure they have access to router context.
|
|
1105
|
+
* String component references are returned as-is (context injected during mount).
|
|
1106
|
+
* Objects are wrapped with router context and their children are recursively wrapped.
|
|
1107
|
+
*
|
|
840
1108
|
* @private
|
|
841
1109
|
* @param {ComponentDefinition | string} component - The component to wrap (can be a definition object or a registered component name).
|
|
842
1110
|
* @returns {ComponentDefinition | string} The wrapped component definition or the original string reference.
|
|
1111
|
+
* @see _wrapComponent - Single component wrapping.
|
|
843
1112
|
*/
|
|
844
1113
|
private _wrapComponentWithChildren;
|
|
845
1114
|
/**
|
|
@@ -850,7 +1119,15 @@ declare class Router {
|
|
|
850
1119
|
private _getCurrentLocation;
|
|
851
1120
|
/**
|
|
852
1121
|
* Parses a query string into a key-value object.
|
|
1122
|
+
* Uses URLSearchParams for robust parsing of encoded values.
|
|
1123
|
+
*
|
|
853
1124
|
* @private
|
|
1125
|
+
* @param {string} queryString - The query string to parse (without leading '?').
|
|
1126
|
+
* @returns {QueryParams} Key-value pairs from the query string.
|
|
1127
|
+
*
|
|
1128
|
+
* @example
|
|
1129
|
+
* this._parseQuery('foo=bar&baz=qux');
|
|
1130
|
+
* // Returns: { foo: 'bar', baz: 'qux' }
|
|
854
1131
|
*/
|
|
855
1132
|
private _parseQuery;
|
|
856
1133
|
/**
|
|
@@ -863,10 +1140,12 @@ declare class Router {
|
|
|
863
1140
|
/**
|
|
864
1141
|
* Adds a new route dynamically at runtime.
|
|
865
1142
|
* The route will be processed and available for navigation immediately.
|
|
1143
|
+
* Routes are inserted before the wildcard (*) route if one exists.
|
|
866
1144
|
*
|
|
867
1145
|
* @param {RouteDefinition} route - The route definition to add.
|
|
868
1146
|
* @param {RouteDefinition} [parentRoute] - Optional parent route to add as a child (not yet implemented).
|
|
869
|
-
* @returns {() => void} A function to remove the added route.
|
|
1147
|
+
* @returns {() => void} A function to remove the added route (returns no-op if route was invalid).
|
|
1148
|
+
* @emits router:routeAdded When a route is successfully added.
|
|
870
1149
|
*
|
|
871
1150
|
* @example
|
|
872
1151
|
* // Add a route dynamically
|
|
@@ -885,6 +1164,7 @@ declare class Router {
|
|
|
885
1164
|
*
|
|
886
1165
|
* @param {string} path - The path of the route to remove.
|
|
887
1166
|
* @returns {boolean} True if the route was removed, false if not found.
|
|
1167
|
+
* @emits router:routeRemoved When a route is successfully removed.
|
|
888
1168
|
*
|
|
889
1169
|
* @example
|
|
890
1170
|
* router.removeRoute('/dynamic');
|
|
@@ -949,31 +1229,40 @@ declare class Router {
|
|
|
949
1229
|
* Registers a global hook that runs after a new route component has been mounted.
|
|
950
1230
|
* @param {NavigationHook} hook - The hook function to register.
|
|
951
1231
|
* @returns {() => void} A function to unregister the hook.
|
|
1232
|
+
* @listens router:afterEnter
|
|
952
1233
|
*/
|
|
953
1234
|
onAfterEnter(hook: NavigationHook): () => void;
|
|
954
1235
|
/**
|
|
955
1236
|
* Registers a global hook that runs after a route component has been unmounted.
|
|
956
1237
|
* @param {NavigationHook} hook - The hook function to register.
|
|
957
1238
|
* @returns {() => void} A function to unregister the hook.
|
|
1239
|
+
* @listens router:afterLeave
|
|
958
1240
|
*/
|
|
959
1241
|
onAfterLeave(hook: NavigationHook): () => void;
|
|
960
1242
|
/**
|
|
961
1243
|
* Registers a global hook that runs after a navigation has been confirmed and all hooks have completed.
|
|
962
1244
|
* @param {NavigationHook} hook - The hook function to register.
|
|
963
1245
|
* @returns {() => void} A function to unregister the hook.
|
|
1246
|
+
* @listens router:afterEach
|
|
964
1247
|
*/
|
|
965
1248
|
onAfterEach(hook: NavigationHook): () => void;
|
|
966
1249
|
/**
|
|
967
1250
|
* Registers a global error handler for navigation errors.
|
|
968
1251
|
* @param {(error: Error, to?: RouteLocation, from?: RouteLocation) => void} handler - The error handler function.
|
|
969
1252
|
* @returns {() => void} A function to unregister the handler.
|
|
1253
|
+
* @listens router:error
|
|
970
1254
|
*/
|
|
971
1255
|
onError(handler: (error: Error, to?: RouteLocation, from?: RouteLocation) => void): () => void;
|
|
972
1256
|
/**
|
|
973
1257
|
* Registers a plugin with the router.
|
|
974
|
-
*
|
|
1258
|
+
* Logs a warning if the plugin is already registered.
|
|
1259
|
+
*
|
|
1260
|
+
* @param {RouterPlugin} plugin - The plugin to register (must have install method).
|
|
1261
|
+
* @param {Record<string, unknown>} [options={}] - Options to pass to plugin.install().
|
|
1262
|
+
* @returns {void}
|
|
1263
|
+
* @throws {Error} If plugin does not have an install method.
|
|
975
1264
|
*/
|
|
976
|
-
use(plugin: RouterPlugin, options?:
|
|
1265
|
+
use(plugin: RouterPlugin, options?: Record<string, unknown>): void;
|
|
977
1266
|
/**
|
|
978
1267
|
* Gets all registered plugins.
|
|
979
1268
|
* @returns {RouterPlugin[]} Array of registered plugins.
|
|
@@ -993,8 +1282,10 @@ declare class Router {
|
|
|
993
1282
|
removePlugin(name: string): boolean;
|
|
994
1283
|
/**
|
|
995
1284
|
* Sets a custom error handler. Used by error handling plugins.
|
|
996
|
-
*
|
|
1285
|
+
* Logs a warning if the provided handler is invalid (missing required methods).
|
|
1286
|
+
* @param {RouterErrorHandler} errorHandler - The error handler object with handle, warn, and log methods.
|
|
1287
|
+
* @returns {void}
|
|
997
1288
|
*/
|
|
998
|
-
setErrorHandler(errorHandler:
|
|
1289
|
+
setErrorHandler(errorHandler: RouterErrorHandler): void;
|
|
999
1290
|
}
|
|
1000
1291
|
//# sourceMappingURL=Router.d.ts.map
|