@pyreon/router 0.11.5 → 0.11.7
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 +14 -12
- package/lib/index.js.map +1 -1
- package/lib/types/index.d.ts +9 -9
- package/package.json +13 -13
- package/src/components.tsx +23 -23
- package/src/index.ts +7 -7
- package/src/loader.ts +4 -4
- package/src/match.ts +41 -41
- package/src/router.ts +86 -86
- package/src/scroll.ts +12 -12
- package/src/tests/loader.test.ts +210 -210
- package/src/tests/match.test.ts +202 -202
- package/src/tests/router.test.ts +1483 -1422
- package/src/tests/setup.ts +1 -1
- package/src/types.ts +12 -12
package/src/tests/setup.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ComponentFn } from
|
|
1
|
+
import type { ComponentFn } from '@pyreon/core'
|
|
2
2
|
|
|
3
3
|
export type { ComponentFn }
|
|
4
4
|
|
|
@@ -51,7 +51,7 @@ export interface RouteMeta {
|
|
|
51
51
|
/** If true, guards can redirect to login */
|
|
52
52
|
requiresAuth?: boolean
|
|
53
53
|
/** Scroll behavior for this route */
|
|
54
|
-
scrollBehavior?:
|
|
54
|
+
scrollBehavior?: 'top' | 'restore' | 'none'
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
// ─── Resolved route ───────────────────────────────────────────────────────────
|
|
@@ -71,7 +71,7 @@ export interface ResolvedRoute<
|
|
|
71
71
|
|
|
72
72
|
// ─── Lazy component ───────────────────────────────────────────────────────────
|
|
73
73
|
|
|
74
|
-
export const LAZY_SYMBOL = Symbol(
|
|
74
|
+
export const LAZY_SYMBOL = Symbol('pyreon.lazy')
|
|
75
75
|
|
|
76
76
|
export interface LazyComponent {
|
|
77
77
|
readonly [LAZY_SYMBOL]: true
|
|
@@ -95,7 +95,7 @@ export function lazy(
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
export function isLazy(c: RouteComponent): c is LazyComponent {
|
|
98
|
-
return typeof c ===
|
|
98
|
+
return typeof c === 'object' && c !== null && (c as LazyComponent)[LAZY_SYMBOL] === true
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
export type RouteComponent = ComponentFn | LazyComponent
|
|
@@ -186,12 +186,12 @@ export type ScrollBehaviorFn = (
|
|
|
186
186
|
to: ResolvedRoute,
|
|
187
187
|
from: ResolvedRoute,
|
|
188
188
|
savedPosition: number | null,
|
|
189
|
-
) =>
|
|
189
|
+
) => 'top' | 'restore' | 'none' | number
|
|
190
190
|
|
|
191
191
|
export interface RouterOptions {
|
|
192
192
|
routes: RouteRecord[]
|
|
193
193
|
/** "hash" (default) uses location.hash; "history" uses pushState */
|
|
194
|
-
mode?:
|
|
194
|
+
mode?: 'hash' | 'history'
|
|
195
195
|
/**
|
|
196
196
|
* Base path for the application. Used when deploying to a sub-path
|
|
197
197
|
* (e.g. `"/app"` for `https://example.com/app/`).
|
|
@@ -203,7 +203,7 @@ export interface RouterOptions {
|
|
|
203
203
|
* Global scroll behavior. Per-route meta.scrollBehavior takes precedence.
|
|
204
204
|
* Default: "top"
|
|
205
205
|
*/
|
|
206
|
-
scrollBehavior?: ScrollBehaviorFn |
|
|
206
|
+
scrollBehavior?: ScrollBehaviorFn | 'top' | 'restore' | 'none'
|
|
207
207
|
/**
|
|
208
208
|
* Initial URL for SSR. On the server, window.location is unavailable;
|
|
209
209
|
* pass the request URL here so the router resolves the correct route.
|
|
@@ -231,7 +231,7 @@ export interface RouterOptions {
|
|
|
231
231
|
* - `"add"` — ensures paths always end with `/`
|
|
232
232
|
* - `"ignore"` — no normalization
|
|
233
233
|
*/
|
|
234
|
-
trailingSlash?:
|
|
234
|
+
trailingSlash?: 'strip' | 'add' | 'ignore'
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
// ─── Router interface ─────────────────────────────────────────────────────────
|
|
@@ -278,11 +278,11 @@ export interface Router {
|
|
|
278
278
|
|
|
279
279
|
// ─── Internal router instance ─────────────────────────────────────────────────
|
|
280
280
|
|
|
281
|
-
import type { Computed, Signal } from
|
|
281
|
+
import type { Computed, Signal } from '@pyreon/reactivity'
|
|
282
282
|
|
|
283
283
|
export interface RouterInstance extends Router {
|
|
284
284
|
routes: RouteRecord[]
|
|
285
|
-
mode:
|
|
285
|
+
mode: 'hash' | 'history'
|
|
286
286
|
/** Normalized base path (e.g. "/app"), empty string if none */
|
|
287
287
|
_base: string
|
|
288
288
|
_currentPath: Signal<string>
|
|
@@ -291,8 +291,8 @@ export interface RouterInstance extends Router {
|
|
|
291
291
|
_loadingSignal: Signal<number>
|
|
292
292
|
_resolve(rawPath: string): ResolvedRoute
|
|
293
293
|
_scrollPositions: Map<string, number>
|
|
294
|
-
_scrollBehavior: RouterOptions[
|
|
295
|
-
_onError: RouterOptions[
|
|
294
|
+
_scrollBehavior: RouterOptions['scrollBehavior']
|
|
295
|
+
_onError: RouterOptions['onError']
|
|
296
296
|
_maxCacheSize: number
|
|
297
297
|
/**
|
|
298
298
|
* Current RouterView nesting depth. Incremented by each RouterView as it
|