@octanejs/tanstack-router 0.2.6 → 0.2.8
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 +48 -0
- package/package.json +4 -3
- package/src/Matches.tsrx +1 -1
- package/src/Transitioner.tsrx +3 -3
- package/src/compiled/Matches.tsrx +266 -0
- package/src/compiled/bindings.ts +40 -0
- package/src/compiled.ts +32 -0
- package/src/fileRoute.ts +3 -2
- package/src/frameworkTypes.ts +11 -8
- package/src/hookBindings.ts +396 -0
- package/src/hooks.ts +17 -374
- package/src/index.ts +2 -0
- package/src/lazyRouteComponent.ts +6 -50
- package/src/lazyRouteLoader.ts +49 -0
- package/src/route.ts +181 -0
- package/src/routerStateBinding.ts +41 -0
- package/src/useRouterState.ts +3 -35
package/src/route.ts
CHANGED
|
@@ -12,6 +12,7 @@ import type {
|
|
|
12
12
|
AnyContext,
|
|
13
13
|
AnyRoute,
|
|
14
14
|
AnyRouter,
|
|
15
|
+
Constrain,
|
|
15
16
|
ConstrainLiteral,
|
|
16
17
|
ErrorComponentProps,
|
|
17
18
|
NotFoundError,
|
|
@@ -233,6 +234,96 @@ export class Route<
|
|
|
233
234
|
declare useLoaderData: UseLoaderDataRoute<TId>;
|
|
234
235
|
declare useNavigate: () => UseNavigateResult<TFullPath>;
|
|
235
236
|
declare Link: LinkComponentRoute<TFullPath>;
|
|
237
|
+
// These core combinators return this same binding instance. Only their
|
|
238
|
+
// children/file metadata changes; the ordinary bound methods stay available.
|
|
239
|
+
declare addChildren: <const TNewChildren>(
|
|
240
|
+
children: Constrain<TNewChildren, ReadonlyArray<AnyRoute> | Record<string, AnyRoute>>,
|
|
241
|
+
) => Route<
|
|
242
|
+
TRegister,
|
|
243
|
+
TParentRoute,
|
|
244
|
+
TPath,
|
|
245
|
+
TFullPath,
|
|
246
|
+
TCustomId,
|
|
247
|
+
TId,
|
|
248
|
+
TSearchValidator,
|
|
249
|
+
TParams,
|
|
250
|
+
TRouterContext,
|
|
251
|
+
TRouteContextFn,
|
|
252
|
+
TBeforeLoadFn,
|
|
253
|
+
TLoaderDeps,
|
|
254
|
+
TLoaderFn,
|
|
255
|
+
TNewChildren,
|
|
256
|
+
TFileRouteTypes,
|
|
257
|
+
TSSR,
|
|
258
|
+
TServerMiddlewares,
|
|
259
|
+
THandlers
|
|
260
|
+
>;
|
|
261
|
+
declare _addFileChildren: <const TNewChildren>(
|
|
262
|
+
children: TNewChildren,
|
|
263
|
+
) => Route<
|
|
264
|
+
TRegister,
|
|
265
|
+
TParentRoute,
|
|
266
|
+
TPath,
|
|
267
|
+
TFullPath,
|
|
268
|
+
TCustomId,
|
|
269
|
+
TId,
|
|
270
|
+
TSearchValidator,
|
|
271
|
+
TParams,
|
|
272
|
+
TRouterContext,
|
|
273
|
+
TRouteContextFn,
|
|
274
|
+
TBeforeLoadFn,
|
|
275
|
+
TLoaderDeps,
|
|
276
|
+
TLoaderFn,
|
|
277
|
+
TNewChildren,
|
|
278
|
+
TFileRouteTypes,
|
|
279
|
+
TSSR,
|
|
280
|
+
TServerMiddlewares,
|
|
281
|
+
THandlers
|
|
282
|
+
>;
|
|
283
|
+
declare _addFileTypes: <TNewFileRouteTypes>() => Route<
|
|
284
|
+
TRegister,
|
|
285
|
+
TParentRoute,
|
|
286
|
+
TPath,
|
|
287
|
+
TFullPath,
|
|
288
|
+
TCustomId,
|
|
289
|
+
TId,
|
|
290
|
+
TSearchValidator,
|
|
291
|
+
TParams,
|
|
292
|
+
TRouterContext,
|
|
293
|
+
TRouteContextFn,
|
|
294
|
+
TBeforeLoadFn,
|
|
295
|
+
TLoaderDeps,
|
|
296
|
+
TLoaderFn,
|
|
297
|
+
TChildren,
|
|
298
|
+
TNewFileRouteTypes,
|
|
299
|
+
TSSR,
|
|
300
|
+
TServerMiddlewares,
|
|
301
|
+
THandlers
|
|
302
|
+
>;
|
|
303
|
+
declare lazy: (
|
|
304
|
+
...args: Parameters<
|
|
305
|
+
RouteCore<
|
|
306
|
+
TRegister,
|
|
307
|
+
TParentRoute,
|
|
308
|
+
TPath,
|
|
309
|
+
TFullPath,
|
|
310
|
+
TCustomId,
|
|
311
|
+
TId,
|
|
312
|
+
TSearchValidator,
|
|
313
|
+
TParams,
|
|
314
|
+
TRouterContext,
|
|
315
|
+
TRouteContextFn,
|
|
316
|
+
TBeforeLoadFn,
|
|
317
|
+
TLoaderDeps,
|
|
318
|
+
TLoaderFn,
|
|
319
|
+
TChildren,
|
|
320
|
+
TFileRouteTypes,
|
|
321
|
+
TSSR,
|
|
322
|
+
TServerMiddlewares,
|
|
323
|
+
THandlers
|
|
324
|
+
>['lazy']
|
|
325
|
+
>
|
|
326
|
+
) => this;
|
|
236
327
|
|
|
237
328
|
/** @deprecated Use the `createRoute` function instead. */
|
|
238
329
|
constructor(
|
|
@@ -313,6 +404,96 @@ export class RootRoute<
|
|
|
313
404
|
declare useLoaderData: UseLoaderDataRoute<RootRouteId>;
|
|
314
405
|
declare useNavigate: () => UseNavigateResult<'/'>;
|
|
315
406
|
declare Link: LinkComponentRoute<'/'>;
|
|
407
|
+
// These core combinators return this same binding instance. Only their
|
|
408
|
+
// children/file metadata changes; the ordinary bound methods stay available.
|
|
409
|
+
declare addChildren: <const TNewChildren>(
|
|
410
|
+
children: Constrain<TNewChildren, ReadonlyArray<AnyRoute> | Record<string, AnyRoute>>,
|
|
411
|
+
) => Route<
|
|
412
|
+
TRegister,
|
|
413
|
+
any,
|
|
414
|
+
'/',
|
|
415
|
+
'/',
|
|
416
|
+
string,
|
|
417
|
+
RootRouteId,
|
|
418
|
+
TSearchValidator,
|
|
419
|
+
{},
|
|
420
|
+
TRouterContext,
|
|
421
|
+
TRouteContextFn,
|
|
422
|
+
TBeforeLoadFn,
|
|
423
|
+
TLoaderDeps,
|
|
424
|
+
TLoaderFn,
|
|
425
|
+
TNewChildren,
|
|
426
|
+
TFileRouteTypes,
|
|
427
|
+
TSSR,
|
|
428
|
+
TServerMiddlewares,
|
|
429
|
+
THandlers
|
|
430
|
+
>;
|
|
431
|
+
declare _addFileChildren: <const TNewChildren>(
|
|
432
|
+
children: TNewChildren,
|
|
433
|
+
) => Route<
|
|
434
|
+
TRegister,
|
|
435
|
+
any,
|
|
436
|
+
'/',
|
|
437
|
+
'/',
|
|
438
|
+
string,
|
|
439
|
+
RootRouteId,
|
|
440
|
+
TSearchValidator,
|
|
441
|
+
{},
|
|
442
|
+
TRouterContext,
|
|
443
|
+
TRouteContextFn,
|
|
444
|
+
TBeforeLoadFn,
|
|
445
|
+
TLoaderDeps,
|
|
446
|
+
TLoaderFn,
|
|
447
|
+
TNewChildren,
|
|
448
|
+
TFileRouteTypes,
|
|
449
|
+
TSSR,
|
|
450
|
+
TServerMiddlewares,
|
|
451
|
+
THandlers
|
|
452
|
+
>;
|
|
453
|
+
declare _addFileTypes: <TNewFileRouteTypes>() => Route<
|
|
454
|
+
TRegister,
|
|
455
|
+
any,
|
|
456
|
+
'/',
|
|
457
|
+
'/',
|
|
458
|
+
string,
|
|
459
|
+
RootRouteId,
|
|
460
|
+
TSearchValidator,
|
|
461
|
+
{},
|
|
462
|
+
TRouterContext,
|
|
463
|
+
TRouteContextFn,
|
|
464
|
+
TBeforeLoadFn,
|
|
465
|
+
TLoaderDeps,
|
|
466
|
+
TLoaderFn,
|
|
467
|
+
TChildren,
|
|
468
|
+
TNewFileRouteTypes,
|
|
469
|
+
TSSR,
|
|
470
|
+
TServerMiddlewares,
|
|
471
|
+
THandlers
|
|
472
|
+
>;
|
|
473
|
+
declare lazy: (
|
|
474
|
+
...args: Parameters<
|
|
475
|
+
RouteCore<
|
|
476
|
+
TRegister,
|
|
477
|
+
any,
|
|
478
|
+
'/',
|
|
479
|
+
'/',
|
|
480
|
+
string,
|
|
481
|
+
RootRouteId,
|
|
482
|
+
TSearchValidator,
|
|
483
|
+
{},
|
|
484
|
+
TRouterContext,
|
|
485
|
+
TRouteContextFn,
|
|
486
|
+
TBeforeLoadFn,
|
|
487
|
+
TLoaderDeps,
|
|
488
|
+
TLoaderFn,
|
|
489
|
+
TChildren,
|
|
490
|
+
TFileRouteTypes,
|
|
491
|
+
TSSR,
|
|
492
|
+
TServerMiddlewares,
|
|
493
|
+
THandlers
|
|
494
|
+
>['lazy']
|
|
495
|
+
>
|
|
496
|
+
) => this;
|
|
316
497
|
|
|
317
498
|
/** @deprecated Use `createRootRoute()` instead. */
|
|
318
499
|
constructor(
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// The reactive base every router hook reads through: subscribe to the router's
|
|
2
|
+
// canonical snapshot store (`router.stores.__store`) and select a slice.
|
|
3
|
+
import { useStore } from './useStore';
|
|
4
|
+
import type { useRouter as StandardUseRouter } from './context';
|
|
5
|
+
import { splitSlot, subSlot } from './internal';
|
|
6
|
+
import type { AnyRouter, RegisteredRouter, RouterState } from '@tanstack/router-core';
|
|
7
|
+
import type { StructuralSharingOption, ValidateSelected } from './structuralSharing';
|
|
8
|
+
|
|
9
|
+
export type UseRouterStateOptions<TRouter extends AnyRouter, TSelected, TStructuralSharing> = {
|
|
10
|
+
router?: TRouter;
|
|
11
|
+
select?: (
|
|
12
|
+
state: RouterState<TRouter['routeTree']>,
|
|
13
|
+
) => ValidateSelected<TRouter, TSelected, TStructuralSharing>;
|
|
14
|
+
} & StructuralSharingOption<TRouter, TSelected, TStructuralSharing>;
|
|
15
|
+
|
|
16
|
+
export type UseRouterStateResult<TRouter extends AnyRouter, TSelected> = unknown extends TSelected
|
|
17
|
+
? RouterState<TRouter['routeTree']>
|
|
18
|
+
: TSelected;
|
|
19
|
+
|
|
20
|
+
export function createUseRouterState(useRouter: typeof StandardUseRouter) {
|
|
21
|
+
function useRouterState<
|
|
22
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
23
|
+
TSelected = unknown,
|
|
24
|
+
TStructuralSharing extends boolean = boolean,
|
|
25
|
+
>(
|
|
26
|
+
opts?: UseRouterStateOptions<TRouter, TSelected, TStructuralSharing>,
|
|
27
|
+
): UseRouterStateResult<TRouter, TSelected>;
|
|
28
|
+
function useRouterState(...args: any[]): any {
|
|
29
|
+
const [user, slot] = splitSlot(args);
|
|
30
|
+
const opts = (user[0] ?? {}) as { select?: (s: any) => any; router?: any };
|
|
31
|
+
const router = useRouter(opts.router ? { router: opts.router } : undefined);
|
|
32
|
+
return useStore(
|
|
33
|
+
router.stores.__store,
|
|
34
|
+
opts.select ?? ((s: any) => s),
|
|
35
|
+
undefined,
|
|
36
|
+
subSlot(slot, 'rs'),
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return useRouterState;
|
|
41
|
+
}
|
package/src/useRouterState.ts
CHANGED
|
@@ -1,37 +1,5 @@
|
|
|
1
|
-
// The reactive base every router hook reads through: subscribe to the router's
|
|
2
|
-
// canonical snapshot store (`router.stores.__store`) and select a slice.
|
|
3
|
-
import { useStore } from './useStore';
|
|
4
1
|
import { useRouter } from './context';
|
|
5
|
-
import {
|
|
6
|
-
import type { AnyRouter, RegisteredRouter, RouterState } from '@tanstack/router-core';
|
|
7
|
-
import type { StructuralSharingOption, ValidateSelected } from './structuralSharing';
|
|
2
|
+
import { createUseRouterState } from './routerStateBinding';
|
|
8
3
|
|
|
9
|
-
export type UseRouterStateOptions
|
|
10
|
-
|
|
11
|
-
select?: (
|
|
12
|
-
state: RouterState<TRouter['routeTree']>,
|
|
13
|
-
) => ValidateSelected<TRouter, TSelected, TStructuralSharing>;
|
|
14
|
-
} & StructuralSharingOption<TRouter, TSelected, TStructuralSharing>;
|
|
15
|
-
|
|
16
|
-
export type UseRouterStateResult<TRouter extends AnyRouter, TSelected> = unknown extends TSelected
|
|
17
|
-
? RouterState<TRouter['routeTree']>
|
|
18
|
-
: TSelected;
|
|
19
|
-
|
|
20
|
-
export function useRouterState<
|
|
21
|
-
TRouter extends AnyRouter = RegisteredRouter,
|
|
22
|
-
TSelected = unknown,
|
|
23
|
-
TStructuralSharing extends boolean = boolean,
|
|
24
|
-
>(
|
|
25
|
-
opts?: UseRouterStateOptions<TRouter, TSelected, TStructuralSharing>,
|
|
26
|
-
): UseRouterStateResult<TRouter, TSelected>;
|
|
27
|
-
export function useRouterState(...args: any[]): any {
|
|
28
|
-
const [user, slot] = splitSlot(args);
|
|
29
|
-
const opts = (user[0] ?? {}) as { select?: (s: any) => any; router?: any };
|
|
30
|
-
const router = useRouter(opts.router ? { router: opts.router } : undefined);
|
|
31
|
-
return useStore(
|
|
32
|
-
router.stores.__store,
|
|
33
|
-
opts.select ?? ((s: any) => s),
|
|
34
|
-
undefined,
|
|
35
|
-
subSlot(slot, 'rs'),
|
|
36
|
-
);
|
|
37
|
-
}
|
|
4
|
+
export type { UseRouterStateOptions, UseRouterStateResult } from './routerStateBinding';
|
|
5
|
+
export const useRouterState = createUseRouterState(useRouter);
|