@flight-framework/router 0.0.6 → 0.0.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/dist/chunk-MO2HMSZH.js +479 -0
- package/dist/index.d.ts +3 -343
- package/dist/index.js +33 -465
- package/dist/prefetch-CMmeei6-.d.ts +359 -0
- package/dist/react/index.d.ts +113 -0
- package/dist/react/index.js +245 -0
- package/package.json +8 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,169 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Router context value provided to all components
|
|
6
|
-
*/
|
|
7
|
-
interface RouterContextValue {
|
|
8
|
-
/** Current pathname (e.g., '/docs/routing') */
|
|
9
|
-
path: string;
|
|
10
|
-
/** URL search params as object */
|
|
11
|
-
searchParams: URLSearchParams;
|
|
12
|
-
/** Navigate to a new path */
|
|
13
|
-
navigate: (to: string, options?: NavigateOptions) => void;
|
|
14
|
-
/** Go back in history */
|
|
15
|
-
back: () => void;
|
|
16
|
-
/** Go forward in history */
|
|
17
|
-
forward: () => void;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Props for RouterProvider component
|
|
21
|
-
*/
|
|
22
|
-
interface RouterProviderProps {
|
|
23
|
-
/** Child components */
|
|
24
|
-
children: unknown;
|
|
25
|
-
/** Initial path for SSR (server passes request URL) */
|
|
26
|
-
initialPath?: string;
|
|
27
|
-
/** Base path for the router (e.g., '/app') */
|
|
28
|
-
basePath?: string;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Prefetch strategy for Link component
|
|
32
|
-
*
|
|
33
|
-
* - 'none': No prefetching (default)
|
|
34
|
-
* - 'intent': Prefetch on hover or focus (recommended for most cases)
|
|
35
|
-
* - 'render': Prefetch immediately when link renders
|
|
36
|
-
* - 'viewport': Prefetch when link enters the viewport (good for mobile)
|
|
37
|
-
*/
|
|
38
|
-
type PrefetchStrategy = 'none' | 'intent' | 'render' | 'viewport';
|
|
39
|
-
/**
|
|
40
|
-
* Priority level for prefetch requests
|
|
41
|
-
*/
|
|
42
|
-
type PrefetchPriority = 'high' | 'low' | 'auto';
|
|
43
|
-
/**
|
|
44
|
-
* Options for programmatic prefetching
|
|
45
|
-
*/
|
|
46
|
-
interface PrefetchOptions {
|
|
47
|
-
/** Priority of the prefetch request */
|
|
48
|
-
priority?: PrefetchPriority;
|
|
49
|
-
/** Include data prefetch (loaders) */
|
|
50
|
-
includeData?: boolean;
|
|
51
|
-
/** Include module prefetch (JS chunks) */
|
|
52
|
-
includeModules?: boolean;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Props for Link component
|
|
56
|
-
*/
|
|
57
|
-
interface LinkProps {
|
|
58
|
-
/** Target URL path */
|
|
59
|
-
href: string;
|
|
60
|
-
/** Child content */
|
|
61
|
-
children: unknown;
|
|
62
|
-
/** CSS class name */
|
|
63
|
-
className?: string;
|
|
64
|
-
/** Open in new tab */
|
|
65
|
-
target?: string;
|
|
66
|
-
/** Link relationship */
|
|
67
|
-
rel?: string;
|
|
68
|
-
/**
|
|
69
|
-
* Prefetch strategy for the target page.
|
|
70
|
-
*
|
|
71
|
-
* - `true` or `'intent'`: Prefetch on hover/focus
|
|
72
|
-
* - `'render'`: Prefetch when link renders
|
|
73
|
-
* - `'viewport'`: Prefetch when link enters viewport
|
|
74
|
-
* - `false` or `'none'`: No prefetching (default)
|
|
75
|
-
*
|
|
76
|
-
* @default 'none'
|
|
77
|
-
*/
|
|
78
|
-
prefetch?: boolean | PrefetchStrategy;
|
|
79
|
-
/** Replace current history entry instead of pushing */
|
|
80
|
-
replace?: boolean;
|
|
81
|
-
/** Scroll to top after navigation */
|
|
82
|
-
scroll?: boolean;
|
|
83
|
-
/** Aria label for accessibility */
|
|
84
|
-
'aria-label'?: string;
|
|
85
|
-
/** Click handler */
|
|
86
|
-
onClick?: (event: MouseEvent) => void;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Options for programmatic navigation
|
|
90
|
-
*/
|
|
91
|
-
interface NavigateOptions {
|
|
92
|
-
/** Replace current history entry instead of pushing */
|
|
93
|
-
replace?: boolean;
|
|
94
|
-
/** Scroll to top after navigation */
|
|
95
|
-
scroll?: boolean;
|
|
96
|
-
/** State data to pass to the new route */
|
|
97
|
-
state?: unknown;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Dynamic route parameters extracted from URL
|
|
101
|
-
*/
|
|
102
|
-
type RouteParams<T extends string = string> = Record<T, string>;
|
|
103
|
-
/**
|
|
104
|
-
* Search params as key-value pairs
|
|
105
|
-
*/
|
|
106
|
-
type SearchParams = Record<string, string | string[]>;
|
|
107
|
-
/**
|
|
108
|
-
* Route definition for automatic route generation
|
|
109
|
-
*/
|
|
110
|
-
interface RouteDefinition {
|
|
111
|
-
/** Route path pattern (e.g., '/docs/:slug') */
|
|
112
|
-
path: string;
|
|
113
|
-
/** Dynamic import for component */
|
|
114
|
-
component: () => Promise<{
|
|
115
|
-
default: unknown;
|
|
116
|
-
}>;
|
|
117
|
-
/** Dynamic imports for layouts (in order, root first) */
|
|
118
|
-
layouts?: Array<() => Promise<{
|
|
119
|
-
default: unknown;
|
|
120
|
-
}>>;
|
|
121
|
-
/** Dynamic import for loader function */
|
|
122
|
-
loader?: () => Promise<{
|
|
123
|
-
loader: LoaderFunction;
|
|
124
|
-
}>;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Loader function signature
|
|
128
|
-
*/
|
|
129
|
-
type LoaderFunction = (context: LoaderContext) => Promise<unknown> | unknown;
|
|
130
|
-
/**
|
|
131
|
-
* Context passed to loader functions
|
|
132
|
-
*/
|
|
133
|
-
interface LoaderContext {
|
|
134
|
-
/** Route parameters */
|
|
135
|
-
params: RouteParams;
|
|
136
|
-
/** Request object (available on server) */
|
|
137
|
-
request?: Request;
|
|
138
|
-
/** URL search params */
|
|
139
|
-
searchParams: URLSearchParams;
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Route match result
|
|
143
|
-
*/
|
|
144
|
-
interface RouteMatch {
|
|
145
|
-
/** Matched route definition */
|
|
146
|
-
route: RouteDefinition;
|
|
147
|
-
/** Extracted parameters */
|
|
148
|
-
params: RouteParams;
|
|
149
|
-
/** Matched path */
|
|
150
|
-
pathname: string;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Router Context and Provider
|
|
155
|
-
*
|
|
156
|
-
* Provides routing state to the component tree.
|
|
157
|
-
* SSR-safe: works on both server and client.
|
|
158
|
-
*/
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* React Context for router
|
|
162
|
-
* Only used if React is available
|
|
163
|
-
*/
|
|
164
|
-
declare let RouterContext: unknown;
|
|
165
|
-
declare let RouterProvider: unknown;
|
|
166
|
-
declare let useRouter: () => RouterContextValue;
|
|
1
|
+
import { L as LinkProps, R as RouteParams, S as SearchParams } from './prefetch-CMmeei6-.js';
|
|
2
|
+
export { g as LoaderContext, f as LoaderFunction, N as NavigateOptions, d as PrefetchOptions, k as PrefetchPageLinks, c as PrefetchPriority, P as PrefetchStrategy, e as RouteDefinition, h as RouteMatch, i as RouterContext, a as RouterContextValue, j as RouterProvider, b as RouterProviderProps, w as clearPrefetchCache, l as findRoute, o as generatePath, q as isActive, v as isPrefetched, m as matchRoute, n as navigate, x as observeForPrefetch, p as parseParams, s as prefetch, t as prefetchAll, z as prefetchPages, A as prefetchWhenIdle, r as redirect, y as setupIntentPrefetch, u as useRouter } from './prefetch-CMmeei6-.js';
|
|
167
3
|
|
|
168
4
|
/**
|
|
169
5
|
* @flight-framework/router - Link Component
|
|
@@ -222,46 +58,6 @@ declare function useLinkProps(href: string, options?: Partial<Omit<LinkProps, 'h
|
|
|
222
58
|
onFocus?: () => void;
|
|
223
59
|
};
|
|
224
60
|
|
|
225
|
-
/**
|
|
226
|
-
* @flight-framework/router - PrefetchPageLinks Component
|
|
227
|
-
*
|
|
228
|
-
* Renders prefetch link tags for a page. Useful for proactively
|
|
229
|
-
* prefetching pages based on user behavior (e.g., search results).
|
|
230
|
-
*
|
|
231
|
-
* This is the Flight equivalent of React Router's PrefetchPageLinks.
|
|
232
|
-
*/
|
|
233
|
-
|
|
234
|
-
declare let PrefetchPageLinks: unknown;
|
|
235
|
-
/**
|
|
236
|
-
* Prefetch multiple pages at once.
|
|
237
|
-
*
|
|
238
|
-
* Useful for prefetching a list of search results or related pages.
|
|
239
|
-
*
|
|
240
|
-
* @example
|
|
241
|
-
* ```typescript
|
|
242
|
-
* // Prefetch top 5 search results
|
|
243
|
-
* prefetchPages([
|
|
244
|
-
* '/products/1',
|
|
245
|
-
* '/products/2',
|
|
246
|
-
* '/products/3',
|
|
247
|
-
* ]);
|
|
248
|
-
* ```
|
|
249
|
-
*/
|
|
250
|
-
declare function prefetchPages(pages: string[], options?: PrefetchOptions): void;
|
|
251
|
-
/**
|
|
252
|
-
* Prefetch a page when idle.
|
|
253
|
-
*
|
|
254
|
-
* Uses requestIdleCallback if available, otherwise falls back
|
|
255
|
-
* to setTimeout.
|
|
256
|
-
*
|
|
257
|
-
* @example
|
|
258
|
-
* ```typescript
|
|
259
|
-
* // Prefetch after initial render settles
|
|
260
|
-
* prefetchWhenIdle('/dashboard');
|
|
261
|
-
* ```
|
|
262
|
-
*/
|
|
263
|
-
declare function prefetchWhenIdle(page: string, options?: PrefetchOptions): void;
|
|
264
|
-
|
|
265
61
|
/**
|
|
266
62
|
* Router Hooks
|
|
267
63
|
*
|
|
@@ -296,140 +92,4 @@ declare let useParams: <T extends RouteParams = RouteParams>() => T;
|
|
|
296
92
|
declare let useSearchParams: () => [URLSearchParams, (params: SearchParams | URLSearchParams) => void];
|
|
297
93
|
declare let usePathname: () => string;
|
|
298
94
|
|
|
299
|
-
|
|
300
|
-
* Navigation Utilities
|
|
301
|
-
*
|
|
302
|
-
* Programmatic navigation and route matching utilities.
|
|
303
|
-
*/
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* Navigate programmatically to a new path
|
|
307
|
-
*
|
|
308
|
-
* @example
|
|
309
|
-
* ```ts
|
|
310
|
-
* navigate('/docs');
|
|
311
|
-
* navigate('/login', { replace: true });
|
|
312
|
-
* navigate('/dashboard', { scroll: false, state: { from: '/home' } });
|
|
313
|
-
* ```
|
|
314
|
-
*/
|
|
315
|
-
declare function navigate(to: string, options?: NavigateOptions): void;
|
|
316
|
-
/**
|
|
317
|
-
* Match a pathname against a route pattern
|
|
318
|
-
*
|
|
319
|
-
* @example
|
|
320
|
-
* ```ts
|
|
321
|
-
* matchRoute('/docs/routing', '/docs/:slug');
|
|
322
|
-
* // Returns: { params: { slug: 'routing' }, matched: true }
|
|
323
|
-
* ```
|
|
324
|
-
*/
|
|
325
|
-
declare function matchRoute(pathname: string, pattern: string): {
|
|
326
|
-
matched: boolean;
|
|
327
|
-
params: RouteParams;
|
|
328
|
-
};
|
|
329
|
-
/**
|
|
330
|
-
* Parse parameters from a matched route
|
|
331
|
-
*
|
|
332
|
-
* @example
|
|
333
|
-
* ```ts
|
|
334
|
-
* parseParams('/blog/2024/my-post', '/blog/:year/:slug');
|
|
335
|
-
* // Returns: { year: '2024', slug: 'my-post' }
|
|
336
|
-
* ```
|
|
337
|
-
*/
|
|
338
|
-
declare function parseParams(pathname: string, pattern: string): RouteParams;
|
|
339
|
-
/**
|
|
340
|
-
* Find the best matching route from a list of route definitions
|
|
341
|
-
*/
|
|
342
|
-
declare function findRoute(pathname: string, routes: RouteDefinition[]): RouteMatch | null;
|
|
343
|
-
/**
|
|
344
|
-
* Generate a URL from a route pattern and params
|
|
345
|
-
*
|
|
346
|
-
* @example
|
|
347
|
-
* ```ts
|
|
348
|
-
* generatePath('/docs/:slug', { slug: 'routing' });
|
|
349
|
-
* // Returns: '/docs/routing'
|
|
350
|
-
* ```
|
|
351
|
-
*/
|
|
352
|
-
declare function generatePath(pattern: string, params?: RouteParams): string;
|
|
353
|
-
/**
|
|
354
|
-
* Check if current path matches a pattern
|
|
355
|
-
*/
|
|
356
|
-
declare function isActive(pattern: string): boolean;
|
|
357
|
-
/**
|
|
358
|
-
* Redirect to a new URL (full page navigation)
|
|
359
|
-
* Use this for external redirects or when you need to break out of SPA
|
|
360
|
-
*/
|
|
361
|
-
declare function redirect(url: string): never;
|
|
362
|
-
|
|
363
|
-
/**
|
|
364
|
-
* @flight-framework/router - Prefetch Utilities
|
|
365
|
-
*
|
|
366
|
-
* Universal prefetch system for Flight Framework.
|
|
367
|
-
* Works across all UI frameworks and runtimes.
|
|
368
|
-
*
|
|
369
|
-
* Features:
|
|
370
|
-
* - Multiple prefetch strategies (intent, render, viewport)
|
|
371
|
-
* - Priority-based prefetching
|
|
372
|
-
* - Module and data prefetching
|
|
373
|
-
* - IntersectionObserver for viewport detection
|
|
374
|
-
* - SSR-safe implementation
|
|
375
|
-
*/
|
|
376
|
-
|
|
377
|
-
/**
|
|
378
|
-
* Prefetch a URL with the specified options.
|
|
379
|
-
*
|
|
380
|
-
* This is the main programmatic prefetch API for Flight Framework.
|
|
381
|
-
* It creates appropriate link elements for prefetching resources.
|
|
382
|
-
*
|
|
383
|
-
* @param href - The URL to prefetch
|
|
384
|
-
* @param options - Prefetch configuration options
|
|
385
|
-
*
|
|
386
|
-
* @example
|
|
387
|
-
* ```typescript
|
|
388
|
-
* // Basic prefetch
|
|
389
|
-
* prefetch('/docs');
|
|
390
|
-
*
|
|
391
|
-
* // High priority prefetch (for critical navigation paths)
|
|
392
|
-
* prefetch('/checkout', { priority: 'high' });
|
|
393
|
-
*
|
|
394
|
-
* // Prefetch with data loaders
|
|
395
|
-
* prefetch('/products', { includeData: true });
|
|
396
|
-
* ```
|
|
397
|
-
*/
|
|
398
|
-
declare function prefetch(href: string, options?: PrefetchOptions): void;
|
|
399
|
-
/**
|
|
400
|
-
* Prefetch multiple URLs at once.
|
|
401
|
-
*
|
|
402
|
-
* @param hrefs - Array of URLs to prefetch
|
|
403
|
-
* @param options - Prefetch configuration options
|
|
404
|
-
*/
|
|
405
|
-
declare function prefetchAll(hrefs: string[], options?: PrefetchOptions): void;
|
|
406
|
-
/**
|
|
407
|
-
* Check if a URL has been prefetched.
|
|
408
|
-
*
|
|
409
|
-
* @param href - The URL to check
|
|
410
|
-
* @returns True if the URL has been prefetched
|
|
411
|
-
*/
|
|
412
|
-
declare function isPrefetched(href: string): boolean;
|
|
413
|
-
/**
|
|
414
|
-
* Clear all prefetch state (useful for testing or memory management).
|
|
415
|
-
*/
|
|
416
|
-
declare function clearPrefetchCache(): void;
|
|
417
|
-
/**
|
|
418
|
-
* Observe an element for viewport entry and trigger prefetch.
|
|
419
|
-
*
|
|
420
|
-
* @param element - The link element to observe
|
|
421
|
-
* @param href - The URL to prefetch when visible
|
|
422
|
-
* @returns Cleanup function to stop observing
|
|
423
|
-
*/
|
|
424
|
-
declare function observeForPrefetch(element: Element, href: string): () => void;
|
|
425
|
-
/**
|
|
426
|
-
* Setup intent-based prefetching for an element.
|
|
427
|
-
* Prefetches on mouseenter or focus.
|
|
428
|
-
*
|
|
429
|
-
* @param element - The link element
|
|
430
|
-
* @param href - The URL to prefetch
|
|
431
|
-
* @returns Cleanup function to remove listeners
|
|
432
|
-
*/
|
|
433
|
-
declare function setupIntentPrefetch(element: HTMLElement, href: string): () => void;
|
|
434
|
-
|
|
435
|
-
export { Link, type LinkProps, type LoaderContext, type LoaderFunction, type NavigateOptions, type PrefetchOptions, PrefetchPageLinks, type PrefetchPriority, type PrefetchStrategy, type RouteDefinition, type RouteMatch, type RouteParams, RouterContext, type RouterContextValue, RouterProvider, type RouterProviderProps, type SearchParams, clearPrefetchCache, createLink, createUsePathname, findRoute, generatePath, getPathnameServerSnapshot, getPathnameSnapshot, isActive, isPrefetched, matchRoute, navigate, observeForPrefetch, parseParams, prefetch, prefetchAll, prefetchPages, prefetchRoute, prefetchWhenIdle, redirect, setupIntentPrefetch, subscribeToPathname, useLinkProps, useParams, usePathname, useRouter, useSearchParams };
|
|
95
|
+
export { Link, LinkProps, RouteParams, SearchParams, createLink, createUsePathname, getPathnameServerSnapshot, getPathnameSnapshot, prefetchRoute, subscribeToPathname, useLinkProps, useParams, usePathname, useSearchParams };
|