driftjs-router 0.0.15 → 0.0.17
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/dist/index-cjs.js +1 -1
- package/dist/index-es.js +320 -375
- package/dist/index.d.ts +242 -0
- package/package.json +11 -11
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
declare module 'driftjs-router' {
|
|
2
|
+
import type { Context } from 'driftjs-shared';
|
|
3
|
+
import type { CompiledModule } from 'driftjs-compiler';
|
|
4
|
+
|
|
5
|
+
export type RouteParams = Record<string, string | string[]>;
|
|
6
|
+
export type RouteQuery = Record<string, string | null | (string | null)[] | undefined>;
|
|
7
|
+
|
|
8
|
+
export interface ScrollPositionCoordinates {
|
|
9
|
+
left?: number | undefined;
|
|
10
|
+
top?: number | undefined;
|
|
11
|
+
behavior?: ScrollBehavior | undefined;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface ScrollPositionElement {
|
|
15
|
+
el: string | Element;
|
|
16
|
+
behavior?: ScrollBehavior | undefined;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type ScrollPosition = ScrollPositionCoordinates | ScrollPositionElement;
|
|
20
|
+
|
|
21
|
+
export type RouterScrollBehavior = (
|
|
22
|
+
to: RouteLocationNormalized,
|
|
23
|
+
from: RouteLocationNormalized,
|
|
24
|
+
savedPosition: ScrollPositionCoordinates | null
|
|
25
|
+
) => ScrollPosition | Promise<ScrollPosition> | false | void | null;
|
|
26
|
+
|
|
27
|
+
export type RouteComponent = any;
|
|
28
|
+
|
|
29
|
+
export interface RouteRecordRaw {
|
|
30
|
+
path: string;
|
|
31
|
+
name?: string | undefined;
|
|
32
|
+
component?: RouteComponent | undefined;
|
|
33
|
+
components?: Record<string, RouteComponent> | undefined;
|
|
34
|
+
redirect?: string | RouteLocationRaw | ((to: RouteLocation) => string | RouteLocationRaw) | undefined;
|
|
35
|
+
children?: RouteRecordRaw[] | undefined;
|
|
36
|
+
meta?: Record<string | number | symbol, any> | undefined;
|
|
37
|
+
beforeEnter?: NavigationGuard | NavigationGuard[] | undefined;
|
|
38
|
+
props?: boolean | Record<string, any> | ((route: RouteLocationNormalized) => Record<string, any>) | undefined;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface RouteRecordNormalized {
|
|
42
|
+
path: string;
|
|
43
|
+
name?: string | undefined;
|
|
44
|
+
components: Record<string, RouteComponent>;
|
|
45
|
+
children: RouteRecordNormalized[];
|
|
46
|
+
meta: Record<string | number | symbol, any>;
|
|
47
|
+
beforeEnter?: NavigationGuard[] | undefined;
|
|
48
|
+
props: Record<string, boolean | Record<string, any> | ((route: RouteLocationNormalized) => Record<string, any>)>;
|
|
49
|
+
parent?: RouteRecordNormalized | undefined;
|
|
50
|
+
regex: RegExp;
|
|
51
|
+
paramNames: string[];
|
|
52
|
+
score?: number | undefined;
|
|
53
|
+
redirect?: string | RouteLocationRaw | ((to: RouteLocation) => string | RouteLocationRaw) | undefined;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type MatchedRoute = RouteRecordNormalized;
|
|
57
|
+
|
|
58
|
+
export interface RouteLocation {
|
|
59
|
+
path: string;
|
|
60
|
+
fullPath: string;
|
|
61
|
+
query: RouteQuery;
|
|
62
|
+
hash: string;
|
|
63
|
+
params: RouteParams;
|
|
64
|
+
name?: string | undefined;
|
|
65
|
+
matched: RouteRecordNormalized[];
|
|
66
|
+
meta: Record<string | number | symbol, any>;
|
|
67
|
+
redirectedFrom?: RouteLocation | undefined;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface RouteLocationNormalized extends RouteLocation {
|
|
71
|
+
href: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface RouteLocationOptions {
|
|
75
|
+
path?: string | undefined;
|
|
76
|
+
name?: string | undefined;
|
|
77
|
+
params?: RouteParams | undefined;
|
|
78
|
+
query?: RouteQuery | undefined;
|
|
79
|
+
hash?: string | undefined;
|
|
80
|
+
replace?: boolean | undefined;
|
|
81
|
+
state?: HistoryState | undefined;
|
|
82
|
+
force?: boolean | undefined;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export type RouteLocationRaw = string | RouteLocationOptions;
|
|
86
|
+
|
|
87
|
+
export type HistoryState = Record<string, any> | null;
|
|
88
|
+
|
|
89
|
+
export type NavigationDirection = 'forward' | 'back' | 'unknown';
|
|
90
|
+
|
|
91
|
+
export interface NavigationInformation {
|
|
92
|
+
direction: NavigationDirection;
|
|
93
|
+
delta: number;
|
|
94
|
+
type: 'pop' | 'push' | 'replace';
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export type NavigationCallback = (to: string, from: string, information: NavigationInformation) => void;
|
|
98
|
+
|
|
99
|
+
export interface RouterHistory {
|
|
100
|
+
readonly base: string;
|
|
101
|
+
readonly location: string;
|
|
102
|
+
readonly state: HistoryState;
|
|
103
|
+
listen(callback: NavigationCallback): () => void;
|
|
104
|
+
push(to: string, data?: HistoryState): void;
|
|
105
|
+
replace(to: string, data?: HistoryState): void;
|
|
106
|
+
go(delta: number): void;
|
|
107
|
+
destroy(): void;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export type HistoryLocation = string;
|
|
111
|
+
|
|
112
|
+
export enum NavigationFailureType {
|
|
113
|
+
aborted = 4,
|
|
114
|
+
cancelled = 8,
|
|
115
|
+
duplicated = 16,
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface NavigationFailure extends Error {
|
|
119
|
+
type: NavigationFailureType;
|
|
120
|
+
from: RouteLocationNormalized;
|
|
121
|
+
to: RouteLocationNormalized;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export type NavigationGuardReturn = void | boolean | string | RouteLocationRaw | Error;
|
|
125
|
+
|
|
126
|
+
export type NavigationGuard = (
|
|
127
|
+
to: RouteLocationNormalized,
|
|
128
|
+
from: RouteLocationNormalized
|
|
129
|
+
) => NavigationGuardReturn | Promise<NavigationGuardReturn>;
|
|
130
|
+
|
|
131
|
+
export type NavigationHookAfter = (
|
|
132
|
+
to: RouteLocationNormalized,
|
|
133
|
+
from: RouteLocationNormalized,
|
|
134
|
+
failure?: NavigationFailure | void
|
|
135
|
+
) => any;
|
|
136
|
+
|
|
137
|
+
export interface RouterOptions {
|
|
138
|
+
history: RouterHistory;
|
|
139
|
+
routes: readonly RouteRecordRaw[];
|
|
140
|
+
scrollBehavior?: RouterScrollBehavior | undefined;
|
|
141
|
+
linkActiveClass?: string | undefined;
|
|
142
|
+
linkExactActiveClass?: string | undefined;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export interface Router {
|
|
146
|
+
readonly currentRoute: RouteLocationNormalized;
|
|
147
|
+
readonly options: RouterOptions;
|
|
148
|
+
push(to: RouteLocationRaw): Promise<NavigationFailure | void | undefined>;
|
|
149
|
+
replace(to: RouteLocationRaw): Promise<NavigationFailure | void | undefined>;
|
|
150
|
+
go(delta: number): void;
|
|
151
|
+
back(): void;
|
|
152
|
+
forward(): void;
|
|
153
|
+
beforeEach(guard: NavigationGuard): () => void;
|
|
154
|
+
beforeResolve(guard: NavigationGuard): () => void;
|
|
155
|
+
afterEach(hook: NavigationHookAfter): () => void;
|
|
156
|
+
onError(handler: (error: any) => void): () => void;
|
|
157
|
+
isReady(): Promise<void>;
|
|
158
|
+
resolve(to: RouteLocationRaw, currentLocation?: RouteLocationNormalized): RouteLocationNormalized;
|
|
159
|
+
addRoute(parentOrRoute: string | RouteRecordRaw, route?: RouteRecordRaw): () => void;
|
|
160
|
+
removeRoute(name: string): void;
|
|
161
|
+
hasRoute(name: string): boolean;
|
|
162
|
+
getRoutes(): RouteRecordNormalized[];
|
|
163
|
+
subscribe(callback: (to: RouteLocationNormalized, from: RouteLocationNormalized) => void): () => void;
|
|
164
|
+
destroy(): void;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export interface RouterViewProps {
|
|
168
|
+
name?: string | undefined;
|
|
169
|
+
route?: RouteLocationNormalized | undefined;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export interface LinkProps {
|
|
173
|
+
to: RouteLocationRaw;
|
|
174
|
+
replace?: boolean | undefined;
|
|
175
|
+
activeClass?: string | undefined;
|
|
176
|
+
exactActiveClass?: string | undefined;
|
|
177
|
+
custom?: boolean | undefined;
|
|
178
|
+
target?: string | undefined;
|
|
179
|
+
rel?: string | undefined;
|
|
180
|
+
class?: string | undefined;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export interface PathTokens {
|
|
184
|
+
regex: RegExp;
|
|
185
|
+
paramNames: string[];
|
|
186
|
+
score: number;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export interface RouteMatcher {
|
|
190
|
+
resolve(to: RouteLocationRaw, currentLocation?: RouteLocationNormalized): RouteLocationNormalized;
|
|
191
|
+
addRoute(parentOrRoute: string | RouteRecordRaw, route?: RouteRecordRaw): () => void;
|
|
192
|
+
removeRoute(name: string): void;
|
|
193
|
+
hasRoute(name: string): boolean;
|
|
194
|
+
getRoutes(): RouteRecordNormalized[];
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// History factories & helpers
|
|
198
|
+
export function createHistoryListeners(): {
|
|
199
|
+
readonly list: NavigationCallback[];
|
|
200
|
+
add(fn: NavigationCallback): () => void;
|
|
201
|
+
reset(): void;
|
|
202
|
+
};
|
|
203
|
+
export function extractHistoryState(rawState: any): HistoryState;
|
|
204
|
+
export function buildHistoryState(data: HistoryState | undefined, pos: number): Record<string, any>;
|
|
205
|
+
export function createWebHistory(base?: string): RouterHistory;
|
|
206
|
+
export function createWebHashHistory(base?: string): RouterHistory;
|
|
207
|
+
export function createMemoryHistory(initialLocation?: string, base?: string): RouterHistory;
|
|
208
|
+
|
|
209
|
+
// Path utilities
|
|
210
|
+
export function normalizePath(path: string): string;
|
|
211
|
+
export function normalizeBase(base?: string): string;
|
|
212
|
+
export function stripBase(pathname: string, base: string): string;
|
|
213
|
+
export function createHref(base: string, location: string): string;
|
|
214
|
+
export function formatHashHref(base: string, location: string): string;
|
|
215
|
+
|
|
216
|
+
// Matcher utilities
|
|
217
|
+
export function parseQuery(search: string): RouteQuery;
|
|
218
|
+
export function stringifyQuery(query: RouteQuery): string;
|
|
219
|
+
export function compilePathToRegex(path: string): PathTokens;
|
|
220
|
+
export function normalizeRouteRecord(
|
|
221
|
+
record: RouteRecordRaw,
|
|
222
|
+
parent?: RouteRecordNormalized
|
|
223
|
+
): RouteRecordNormalized;
|
|
224
|
+
export function createMatcher(routes: readonly RouteRecordRaw[]): RouteMatcher;
|
|
225
|
+
|
|
226
|
+
// Router Contexts & Core API
|
|
227
|
+
export const RouterContext: Context<Router>;
|
|
228
|
+
export const RouteContext: Context<() => RouteLocationNormalized>;
|
|
229
|
+
export const RouterDepthContext: Context<number>;
|
|
230
|
+
export const START_LOCATION_NORMALIZED: RouteLocationNormalized;
|
|
231
|
+
export function createNavigationFailure(
|
|
232
|
+
type: NavigationFailureType,
|
|
233
|
+
to: RouteLocationNormalized,
|
|
234
|
+
from: RouteLocationNormalized
|
|
235
|
+
): NavigationFailure;
|
|
236
|
+
export function isNavigationFailure(error: any, type?: NavigationFailureType): error is NavigationFailure;
|
|
237
|
+
export function createRouter(options: RouterOptions): Router;
|
|
238
|
+
|
|
239
|
+
// Native SFC Components
|
|
240
|
+
export const RouterView: CompiledModule;
|
|
241
|
+
export const Link: CompiledModule;
|
|
242
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "driftjs-router",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
4
4
|
"description": "Client-side SPA router for DriftJS with history, hash, and memory drivers, dynamic route parameters, nested routes/outlets, scroll restoration, and navigation guards.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"driftjs",
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
],
|
|
19
19
|
"main": "./dist/index-cjs.js",
|
|
20
20
|
"module": "./dist/index-es.js",
|
|
21
|
-
"types": "./
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
22
|
"exports": {
|
|
23
23
|
".": {
|
|
24
|
-
"types": "./
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
25
|
"import": "./dist/index-es.js",
|
|
26
26
|
"require": "./dist/index-cjs.js",
|
|
27
27
|
"default": "./dist/index-es.js"
|
|
@@ -29,16 +29,16 @@
|
|
|
29
29
|
},
|
|
30
30
|
"license": "MIT",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"path-to-regexp": "
|
|
33
|
-
"driftjs-dom": "0.0.
|
|
34
|
-
"driftjs-shared": "0.0.
|
|
32
|
+
"path-to-regexp": "8.4.2",
|
|
33
|
+
"driftjs-dom": "0.0.17",
|
|
34
|
+
"driftjs-shared": "0.0.17"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"typescript": "
|
|
38
|
-
"vite": "
|
|
39
|
-
"vitest": "
|
|
40
|
-
"driftjs-compiler": "0.0.
|
|
41
|
-
"driftjs-vite-plugin": "0.0.
|
|
37
|
+
"typescript": "7.0.2",
|
|
38
|
+
"vite": "8.3.1",
|
|
39
|
+
"vitest": "5.0.2",
|
|
40
|
+
"driftjs-compiler": "0.0.17",
|
|
41
|
+
"driftjs-vite-plugin": "0.0.17"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "vite build",
|