@benjavicente/angular-router-experimental 1.142.11 → 1.142.12
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/fesm2022/tanstack-angular-router-experimental-experimental.mjs +192 -187
- package/dist/fesm2022/tanstack-angular-router-experimental.mjs +1145 -1160
- package/dist/types/tanstack-angular-router-experimental-experimental.d.ts +39 -35
- package/dist/types/tanstack-angular-router-experimental.d.ts +56 -42
- package/package.json +5 -4
- package/src/Match.ts +37 -22
- package/src/Matches.ts +5 -2
- package/src/RouterProvider.ts +3 -0
- package/src/document/build-match-managed-document.ts +1 -1
- package/src/document/install-unified-document-sync.ts +6 -3
- package/src/document/provide-tanstack-body-managed-tags.ts +2 -2
- package/src/document/provide-tanstack-document-title.ts +4 -5
- package/src/document/provide-tanstack-head-managed-tags.ts +2 -2
- package/src/index.ts +5 -2
- package/src/injectCanGoBack.ts +2 -2
- package/src/injectLocation.ts +11 -8
- package/src/injectMatch.ts +45 -34
- package/src/injectMatchRoute.ts +4 -5
- package/src/injectMatches.ts +9 -9
- package/src/injectRouterState.ts +15 -10
- package/src/routerStores.ts +25 -52
- package/src/store/injectSelector.ts +62 -0
- package/src/store/injectStore.ts +33 -0
- package/src/transitioner.ts +12 -25
- package/src/injectStore.ts +0 -87
|
@@ -22,6 +22,42 @@ export declare function injectRouteErrorHandler<TRouter extends AnyRouter = Regi
|
|
|
22
22
|
export { }
|
|
23
23
|
|
|
24
24
|
|
|
25
|
+
declare module '@benjavicente/router-core' {
|
|
26
|
+
interface RouterOptionsExtensions {
|
|
27
|
+
/**
|
|
28
|
+
* The default `component` a route should use if no component is provided.
|
|
29
|
+
*
|
|
30
|
+
* @default Outlet
|
|
31
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/solid/api/router/RouterOptionsType#defaultcomponent-property)
|
|
32
|
+
*/
|
|
33
|
+
defaultComponent?: RouteComponent;
|
|
34
|
+
/**
|
|
35
|
+
* The default `errorComponent` a route should use if no error component is provided.
|
|
36
|
+
*
|
|
37
|
+
* @default ErrorComponent
|
|
38
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/solid/api/router/RouterOptionsType#defaulterrorcomponent-property)
|
|
39
|
+
* @link [Guide](https://tanstack.com/router/latest/docs/framework/solid/guide/data-loading#handling-errors-with-routeoptionserrorcomponent)
|
|
40
|
+
*/
|
|
41
|
+
defaultErrorComponent?: ErrorRouteComponent;
|
|
42
|
+
/**
|
|
43
|
+
* The default `pendingComponent` a route should use if no pending component is provided.
|
|
44
|
+
*
|
|
45
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/solid/api/router/RouterOptionsType#defaultpendingcomponent-property)
|
|
46
|
+
* @link [Guide](https://tanstack.com/router/latest/docs/framework/solid/guide/data-loading#showing-a-pending-component)
|
|
47
|
+
*/
|
|
48
|
+
defaultPendingComponent?: RouteComponent;
|
|
49
|
+
/**
|
|
50
|
+
* The default `notFoundComponent` a route should use if no notFound component is provided.
|
|
51
|
+
*
|
|
52
|
+
* @default NotFound
|
|
53
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/solid/api/router/RouterOptionsType#defaultnotfoundcomponent-property)
|
|
54
|
+
* @link [Guide](https://tanstack.com/router/latest/docs/framework/solid/guide/not-found-errors#default-router-wide-not-found-handling)
|
|
55
|
+
*/
|
|
56
|
+
defaultNotFoundComponent?: RouteComponent;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
|
|
25
61
|
declare module '@benjavicente/router-core' {
|
|
26
62
|
interface UpdatableRouteOptionsExtensions {
|
|
27
63
|
component?: RouteComponent;
|
|
@@ -60,44 +96,12 @@ declare module '@benjavicente/router-core' {
|
|
|
60
96
|
|
|
61
97
|
|
|
62
98
|
declare module '@benjavicente/router-core' {
|
|
63
|
-
interface
|
|
64
|
-
/**
|
|
65
|
-
* The default `component` a route should use if no component is provided.
|
|
66
|
-
*
|
|
67
|
-
* @default Outlet
|
|
68
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/solid/api/router/RouterOptionsType#defaultcomponent-property)
|
|
69
|
-
*/
|
|
70
|
-
defaultComponent?: RouteComponent;
|
|
71
|
-
/**
|
|
72
|
-
* The default `errorComponent` a route should use if no error component is provided.
|
|
73
|
-
*
|
|
74
|
-
* @default ErrorComponent
|
|
75
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/solid/api/router/RouterOptionsType#defaulterrorcomponent-property)
|
|
76
|
-
* @link [Guide](https://tanstack.com/router/latest/docs/framework/solid/guide/data-loading#handling-errors-with-routeoptionserrorcomponent)
|
|
77
|
-
*/
|
|
78
|
-
defaultErrorComponent?: ErrorRouteComponent;
|
|
79
|
-
/**
|
|
80
|
-
* The default `pendingComponent` a route should use if no pending component is provided.
|
|
81
|
-
*
|
|
82
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/solid/api/router/RouterOptionsType#defaultpendingcomponent-property)
|
|
83
|
-
* @link [Guide](https://tanstack.com/router/latest/docs/framework/solid/guide/data-loading#showing-a-pending-component)
|
|
84
|
-
*/
|
|
85
|
-
defaultPendingComponent?: RouteComponent;
|
|
86
|
-
/**
|
|
87
|
-
* The default `notFoundComponent` a route should use if no notFound component is provided.
|
|
88
|
-
*
|
|
89
|
-
* @default NotFound
|
|
90
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/solid/api/router/RouterOptionsType#defaultnotfoundcomponent-property)
|
|
91
|
-
* @link [Guide](https://tanstack.com/router/latest/docs/framework/solid/guide/not-found-errors#default-router-wide-not-found-handling)
|
|
92
|
-
*/
|
|
93
|
-
defaultNotFoundComponent?: RouteComponent;
|
|
99
|
+
interface RouterReadableStore<TValue> extends Readable<TValue> {
|
|
94
100
|
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
declare module '@benjavicente/router-core' {
|
|
99
101
|
interface RouterStores<in out TRouteTree extends AnyRoute> {
|
|
102
|
+
/** Maps each active routeId to the matchId of its child in the match tree. */
|
|
100
103
|
childMatchIdByRouteId: RouterReadableStore<Record<string, string>>;
|
|
104
|
+
/** Maps each pending routeId to true for quick lookup. */
|
|
101
105
|
pendingRouteIds: RouterReadableStore<Record<string, boolean>>;
|
|
102
106
|
}
|
|
103
107
|
}
|
|
@@ -28,6 +28,7 @@ import { HistoryAction } from '@benjavicente/history';
|
|
|
28
28
|
import { HistoryLocation } from '@benjavicente/history';
|
|
29
29
|
import { HistoryState } from '@benjavicente/history';
|
|
30
30
|
import { InjectionToken } from '@angular/core';
|
|
31
|
+
import { Injector } from '@angular/core';
|
|
31
32
|
import { InputSignal } from '@angular/core';
|
|
32
33
|
import { isRedirect } from '@benjavicente/router-core';
|
|
33
34
|
import { lazyFn } from '@benjavicente/router-core';
|
|
@@ -40,7 +41,6 @@ import { MakeRouteMatchUnion } from '@benjavicente/router-core';
|
|
|
40
41
|
import { MaskOptions } from '@benjavicente/router-core';
|
|
41
42
|
import { MatchRouteOptions } from '@benjavicente/router-core';
|
|
42
43
|
import { NavigateOptions } from '@benjavicente/router-core';
|
|
43
|
-
import { NoInfer as NoInfer_2 } from '@benjavicente/router-core';
|
|
44
44
|
import { notFound } from '@benjavicente/router-core';
|
|
45
45
|
import { NotFoundError } from '@benjavicente/router-core';
|
|
46
46
|
import { ParsedLocation } from '@benjavicente/router-core';
|
|
@@ -158,6 +158,10 @@ export declare function buildManagedDocumentContent(router: AnyRouter): ManagedD
|
|
|
158
158
|
*/
|
|
159
159
|
export declare function buildMatchManagedDocumentContent(router: AnyRouter): ManagedDocumentContent;
|
|
160
160
|
|
|
161
|
+
declare type CompatibilityInjectStoreOptions<TSelected> = CreateSignalOptions<TSelected> & {
|
|
162
|
+
injector?: Injector;
|
|
163
|
+
};
|
|
164
|
+
|
|
161
165
|
export { createBrowserHistory }
|
|
162
166
|
|
|
163
167
|
export { CreateFileRoute }
|
|
@@ -277,7 +281,7 @@ export declare type InjectMatchResult<TRouter extends AnyRouter, TFrom, TStrict
|
|
|
277
281
|
|
|
278
282
|
export declare type InjectMatchRoute<out TFrom> = <TRouter extends AnyRouter = RegisteredRouter, TSelected = unknown>(opts?: InjectMatchBaseOptions<TRouter, TFrom, true, true, TSelected>) => Angular.Signal<InjectMatchResult<TRouter, TFrom, true, TSelected>>;
|
|
279
283
|
|
|
280
|
-
export declare function injectMatchRoute<TRouter extends AnyRouter = RegisteredRouter>(): <const TFrom extends string = string, const TTo extends string | undefined = undefined, const TMaskFrom extends string = TFrom, const TMaskTo extends string = "">(opts: InjectMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>) => Angular.Signal<false | Expand<ResolveRoute<TRouter, TFrom,
|
|
284
|
+
export declare function injectMatchRoute<TRouter extends AnyRouter = RegisteredRouter>(): <const TFrom extends string = string, const TTo extends string | undefined = undefined, const TMaskFrom extends string = TFrom, const TMaskTo extends string = "">(opts: InjectMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>) => Angular.Signal<false | Expand<ResolveRoute<TRouter, TFrom, TTo>["types"]["allParams"]>>;
|
|
281
285
|
|
|
282
286
|
export declare type InjectMatchRouteOptions<TRouter extends AnyRouter = RegisteredRouter, TFrom extends string = string, TTo extends string | undefined = undefined, TMaskFrom extends string = TFrom, TMaskTo extends string = ''> = ToSubOptionsProps<TRouter, TFrom, TTo> & DeepPartial<MakeOptionalSearchParams<TRouter, TFrom, TTo>> & DeepPartial<MakeOptionalPathParams<TRouter, TFrom, TTo>> & MaskOptions<TRouter, TMaskFrom, TMaskTo> & MatchRouteOptions;
|
|
283
287
|
|
|
@@ -335,7 +339,9 @@ export declare type InjectSearchRoute<out TFrom> = <TRouter extends AnyRouter =
|
|
|
335
339
|
*/
|
|
336
340
|
export declare function injectSsrScrollRestorationScript(): void;
|
|
337
341
|
|
|
338
|
-
export declare function injectStore<TState, TSelected = NoInfer<TState>>(
|
|
342
|
+
export declare function injectStore<TState, TSelected = NoInfer<TState>>(store: SelectionSource<TState>, selector?: (state: NoInfer<TState>) => TSelected, options?: CompatibilityInjectStoreOptions<TSelected>): Signal<TSelected>;
|
|
343
|
+
|
|
344
|
+
export declare function injectStore<TState, TSelected = NoInfer<TState>>(store: SelectionSource<TState> | (() => SelectionSource<TState>), selector?: (state: NoInfer<TState>) => TSelected, options?: CompatibilityInjectStoreOptions<TSelected>): Signal<TSelected>;
|
|
339
345
|
|
|
340
346
|
declare class InternalFileRouteFactory<TFilePath extends keyof FileRoutesByPath, TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'], TId extends RouteConstraints['TId'] = FileRoutesByPath[TFilePath]['id'], TPath extends RouteConstraints['TPath'] = FileRoutesByPath[TFilePath]['path'], TFullPath extends RouteConstraints['TFullPath'] = FileRoutesByPath[TFilePath]['fullPath']> {
|
|
341
347
|
createRoute: <TRegister = Register, TSearchValidator = undefined, TParams = ResolveParams<TPath>, TRouteContextFn = AnyContext, TBeforeLoadFn = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderFn = undefined, TChildren = unknown, TSSR = unknown, TMiddlewares = unknown, THandlers = undefined>(options?: FileBaseRouteOptions<TRegister, TParentRoute, TId, TPath, TSearchValidator, TParams, TLoaderDeps, TLoaderFn, AnyContext, TRouteContextFn, TBeforeLoadFn, AnyContext, TSSR, TMiddlewares, THandlers> & UpdatableRouteOptions<TParentRoute, TId, TFullPath, TParams, TSearchValidator, TLoaderFn, TLoaderDeps, AnyContext, TRouteContextFn, TBeforeLoadFn>) => Route_2<TRegister, TParentRoute, TPath, TFullPath, TFilePath, TId, TSearchValidator, TParams, AnyContext, TRouteContextFn, TBeforeLoadFn, TLoaderDeps, TLoaderFn, TChildren, unknown, TSSR, TMiddlewares, THandlers>;
|
|
@@ -484,10 +490,6 @@ export declare function provideTanstackRouter({ router, context, options, }: Tan
|
|
|
484
490
|
useFactory?: undefined;
|
|
485
491
|
})[];
|
|
486
492
|
|
|
487
|
-
declare type ReadableStore<TState> = {
|
|
488
|
-
state: TState;
|
|
489
|
-
};
|
|
490
|
-
|
|
491
493
|
export { redirect }
|
|
492
494
|
|
|
493
495
|
export { Register }
|
|
@@ -556,6 +558,7 @@ export declare class RouteMatch {
|
|
|
556
558
|
matchId: InputSignal<string>;
|
|
557
559
|
router: AnyRouter;
|
|
558
560
|
match: Signal<AnyRouteMatch | undefined>;
|
|
561
|
+
private matchSignal;
|
|
559
562
|
matchData: Signal<{
|
|
560
563
|
key: string | undefined;
|
|
561
564
|
route: AnyRoute;
|
|
@@ -604,6 +607,13 @@ export declare class RouterProvider<TRouter extends AnyRouter = RegisteredRouter
|
|
|
604
607
|
|
|
605
608
|
export { RouterState }
|
|
606
609
|
|
|
610
|
+
declare type SelectionSource<T> = {
|
|
611
|
+
get: () => T;
|
|
612
|
+
subscribe: (listener: (value: T) => void) => {
|
|
613
|
+
unsubscribe: () => void;
|
|
614
|
+
};
|
|
615
|
+
};
|
|
616
|
+
|
|
607
617
|
export declare type ShouldBlockFn<TRouter extends AnyRouter = RegisteredRouter> = (args: ShouldBlockFnArgs<TRouter>) => boolean | Promise<boolean>;
|
|
608
618
|
|
|
609
619
|
declare type ShouldBlockFnArgs<TRouter extends AnyRouter = RegisteredRouter> = {
|
|
@@ -645,6 +655,42 @@ export declare type UseBlockerOpts<TRouter extends AnyRouter = RegisteredRouter,
|
|
|
645
655
|
export { }
|
|
646
656
|
|
|
647
657
|
|
|
658
|
+
declare module '@benjavicente/router-core' {
|
|
659
|
+
interface RouterOptionsExtensions {
|
|
660
|
+
/**
|
|
661
|
+
* The default `component` a route should use if no component is provided.
|
|
662
|
+
*
|
|
663
|
+
* @default Outlet
|
|
664
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/solid/api/router/RouterOptionsType#defaultcomponent-property)
|
|
665
|
+
*/
|
|
666
|
+
defaultComponent?: RouteComponent;
|
|
667
|
+
/**
|
|
668
|
+
* The default `errorComponent` a route should use if no error component is provided.
|
|
669
|
+
*
|
|
670
|
+
* @default ErrorComponent
|
|
671
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/solid/api/router/RouterOptionsType#defaulterrorcomponent-property)
|
|
672
|
+
* @link [Guide](https://tanstack.com/router/latest/docs/framework/solid/guide/data-loading#handling-errors-with-routeoptionserrorcomponent)
|
|
673
|
+
*/
|
|
674
|
+
defaultErrorComponent?: ErrorRouteComponent;
|
|
675
|
+
/**
|
|
676
|
+
* The default `pendingComponent` a route should use if no pending component is provided.
|
|
677
|
+
*
|
|
678
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/solid/api/router/RouterOptionsType#defaultpendingcomponent-property)
|
|
679
|
+
* @link [Guide](https://tanstack.com/router/latest/docs/framework/solid/guide/data-loading#showing-a-pending-component)
|
|
680
|
+
*/
|
|
681
|
+
defaultPendingComponent?: RouteComponent;
|
|
682
|
+
/**
|
|
683
|
+
* The default `notFoundComponent` a route should use if no notFound component is provided.
|
|
684
|
+
*
|
|
685
|
+
* @default NotFound
|
|
686
|
+
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/solid/api/router/RouterOptionsType#defaultnotfoundcomponent-property)
|
|
687
|
+
* @link [Guide](https://tanstack.com/router/latest/docs/framework/solid/guide/not-found-errors#default-router-wide-not-found-handling)
|
|
688
|
+
*/
|
|
689
|
+
defaultNotFoundComponent?: RouteComponent;
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
|
|
648
694
|
declare module '@benjavicente/router-core' {
|
|
649
695
|
interface UpdatableRouteOptionsExtensions {
|
|
650
696
|
component?: RouteComponent;
|
|
@@ -683,44 +729,12 @@ declare module '@benjavicente/router-core' {
|
|
|
683
729
|
|
|
684
730
|
|
|
685
731
|
declare module '@benjavicente/router-core' {
|
|
686
|
-
interface
|
|
687
|
-
/**
|
|
688
|
-
* The default `component` a route should use if no component is provided.
|
|
689
|
-
*
|
|
690
|
-
* @default Outlet
|
|
691
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/solid/api/router/RouterOptionsType#defaultcomponent-property)
|
|
692
|
-
*/
|
|
693
|
-
defaultComponent?: RouteComponent;
|
|
694
|
-
/**
|
|
695
|
-
* The default `errorComponent` a route should use if no error component is provided.
|
|
696
|
-
*
|
|
697
|
-
* @default ErrorComponent
|
|
698
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/solid/api/router/RouterOptionsType#defaulterrorcomponent-property)
|
|
699
|
-
* @link [Guide](https://tanstack.com/router/latest/docs/framework/solid/guide/data-loading#handling-errors-with-routeoptionserrorcomponent)
|
|
700
|
-
*/
|
|
701
|
-
defaultErrorComponent?: ErrorRouteComponent;
|
|
702
|
-
/**
|
|
703
|
-
* The default `pendingComponent` a route should use if no pending component is provided.
|
|
704
|
-
*
|
|
705
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/solid/api/router/RouterOptionsType#defaultpendingcomponent-property)
|
|
706
|
-
* @link [Guide](https://tanstack.com/router/latest/docs/framework/solid/guide/data-loading#showing-a-pending-component)
|
|
707
|
-
*/
|
|
708
|
-
defaultPendingComponent?: RouteComponent;
|
|
709
|
-
/**
|
|
710
|
-
* The default `notFoundComponent` a route should use if no notFound component is provided.
|
|
711
|
-
*
|
|
712
|
-
* @default NotFound
|
|
713
|
-
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/solid/api/router/RouterOptionsType#defaultnotfoundcomponent-property)
|
|
714
|
-
* @link [Guide](https://tanstack.com/router/latest/docs/framework/solid/guide/not-found-errors#default-router-wide-not-found-handling)
|
|
715
|
-
*/
|
|
716
|
-
defaultNotFoundComponent?: RouteComponent;
|
|
732
|
+
interface RouterReadableStore<TValue> extends Readable<TValue> {
|
|
717
733
|
}
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
declare module '@benjavicente/router-core' {
|
|
722
734
|
interface RouterStores<in out TRouteTree extends AnyRoute> {
|
|
735
|
+
/** Maps each active routeId to the matchId of its child in the match tree. */
|
|
723
736
|
childMatchIdByRouteId: RouterReadableStore<Record<string, string>>;
|
|
737
|
+
/** Maps each pending routeId to true for quick lookup. */
|
|
724
738
|
pendingRouteIds: RouterReadableStore<Record<string, boolean>>;
|
|
725
739
|
}
|
|
726
740
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@benjavicente/angular-router-experimental",
|
|
3
|
-
"version": "1.142.
|
|
3
|
+
"version": "1.142.12",
|
|
4
4
|
"description": "Modern and scalable routing for Angular applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -50,10 +50,11 @@
|
|
|
50
50
|
"node": ">=20.19"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
+
"@benjavicente/history": "^1.161.6",
|
|
54
|
+
"@benjavicente/router-core": "^1.169.2",
|
|
55
|
+
"@tanstack/store": "^0.9.3",
|
|
53
56
|
"isbot": "^5.1.22",
|
|
54
|
-
"tslib": "^2.3.0"
|
|
55
|
-
"@benjavicente/history": "1.161.6",
|
|
56
|
-
"@benjavicente/router-core": "1.168.9"
|
|
57
|
+
"tslib": "^2.3.0"
|
|
57
58
|
},
|
|
58
59
|
"devDependencies": {
|
|
59
60
|
"@analogjs/vitest-angular": "^2.2.1",
|
package/src/Match.ts
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
rootRouteId,
|
|
17
17
|
} from '@benjavicente/router-core'
|
|
18
18
|
import { injectRouter } from './injectRouter'
|
|
19
|
-
import { injectStore } from './injectStore'
|
|
19
|
+
import { injectStore } from './store/injectStore'
|
|
20
20
|
import { DefaultNotFoundComponent } from './DefaultNotFound'
|
|
21
21
|
import { MATCH_CONTEXT_INJECTOR_TOKEN } from './matchInjectorToken'
|
|
22
22
|
import { injectRender } from './renderer/injectRender'
|
|
@@ -24,6 +24,12 @@ import { ERROR_STATE_INJECTOR_TOKEN } from './injectErrorState'
|
|
|
24
24
|
import { injectIsCatchingError } from './renderer/injectIsCatchingError'
|
|
25
25
|
import type { Signal } from '@angular/core'
|
|
26
26
|
import type { NearestMatchContextValue } from './matchInjectorToken'
|
|
27
|
+
import type { AnyRouteMatch } from '@benjavicente/router-core'
|
|
28
|
+
|
|
29
|
+
const dummyMatchStore = {
|
|
30
|
+
get: () => undefined as AnyRouteMatch | undefined,
|
|
31
|
+
subscribe: () => ({ unsubscribe: () => {} }),
|
|
32
|
+
}
|
|
27
33
|
|
|
28
34
|
function injectOnRendered({
|
|
29
35
|
parentRouteIsRoot,
|
|
@@ -35,7 +41,7 @@ function injectOnRendered({
|
|
|
35
41
|
const destroyRef = inject(DestroyRef)
|
|
36
42
|
const location = injectStore(
|
|
37
43
|
router.stores.resolvedLocation,
|
|
38
|
-
(resolvedLocation) => resolvedLocation?.state
|
|
44
|
+
(resolvedLocation) => resolvedLocation?.state?.__TSR_key,
|
|
39
45
|
)
|
|
40
46
|
const loadedAt = injectStore(router.stores.loadedAt, (value) => value)
|
|
41
47
|
|
|
@@ -68,8 +74,8 @@ function injectOnRendered({
|
|
|
68
74
|
router.emit({
|
|
69
75
|
type: 'onRendered',
|
|
70
76
|
...getLocationChangeInfo(
|
|
71
|
-
router.stores.location.
|
|
72
|
-
router.stores.resolvedLocation.
|
|
77
|
+
router.stores.location.get(),
|
|
78
|
+
router.stores.resolvedLocation.get(),
|
|
73
79
|
),
|
|
74
80
|
})
|
|
75
81
|
},
|
|
@@ -84,6 +90,7 @@ function injectOnRendered({
|
|
|
84
90
|
template: '',
|
|
85
91
|
standalone: true,
|
|
86
92
|
host: {
|
|
93
|
+
hidden: '',
|
|
87
94
|
'[attr.data-matchId]': 'matchId()',
|
|
88
95
|
},
|
|
89
96
|
})
|
|
@@ -93,11 +100,12 @@ export class RouteMatch {
|
|
|
93
100
|
router = injectRouter()
|
|
94
101
|
|
|
95
102
|
match = computed(() => {
|
|
96
|
-
|
|
97
|
-
return matchId
|
|
98
|
-
? this.router.stores.activeMatchStoresById.get(matchId)?.state
|
|
99
|
-
: undefined
|
|
103
|
+
return this.matchSignal()
|
|
100
104
|
})
|
|
105
|
+
private matchSignal = injectStore(
|
|
106
|
+
() => this.router.stores.matchStores.get(this.matchId()) ?? dummyMatchStore,
|
|
107
|
+
(value) => value,
|
|
108
|
+
)
|
|
101
109
|
|
|
102
110
|
matchData = computed(() => {
|
|
103
111
|
const match = this.match()
|
|
@@ -141,16 +149,17 @@ export class RouteMatch {
|
|
|
141
149
|
return this.resolvedNoSsr() || !!match._displayPending
|
|
142
150
|
})
|
|
143
151
|
|
|
144
|
-
parentRouteIdSignal = computed(
|
|
145
|
-
() => this.matchData()?.parentRouteId ?? '',
|
|
146
|
-
)
|
|
152
|
+
parentRouteIdSignal = computed(() => this.matchData()?.parentRouteId ?? '')
|
|
147
153
|
rootRouteIdSignal = computed(() => rootRouteId)
|
|
148
154
|
|
|
149
155
|
hasPendingMatch = computed(() => {
|
|
150
156
|
const routeId = this.matchData()?.route.id
|
|
151
157
|
return routeId ? Boolean(this.pendingRouteIds()[routeId]) : false
|
|
152
158
|
})
|
|
153
|
-
pendingRouteIds = injectStore(
|
|
159
|
+
pendingRouteIds = injectStore(
|
|
160
|
+
this.router.stores.pendingRouteIds,
|
|
161
|
+
(ids) => ids,
|
|
162
|
+
)
|
|
154
163
|
nearestMatchContext: NearestMatchContextValue = {
|
|
155
164
|
matchId: this.matchId,
|
|
156
165
|
routeId: computed(() => this.matchData()?.route.id),
|
|
@@ -258,23 +267,27 @@ export class RouteMatch {
|
|
|
258
267
|
selector: 'outlet,[outlet]',
|
|
259
268
|
template: '',
|
|
260
269
|
standalone: true,
|
|
270
|
+
host: {
|
|
271
|
+
hidden: '',
|
|
272
|
+
},
|
|
261
273
|
})
|
|
262
274
|
export class Outlet {
|
|
263
275
|
router = injectRouter()
|
|
264
276
|
nearestMatch = inject(MATCH_CONTEXT_INJECTOR_TOKEN)
|
|
265
277
|
|
|
266
|
-
currentMatch =
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
278
|
+
currentMatch = injectStore(
|
|
279
|
+
() => {
|
|
280
|
+
const matchId = this.nearestMatch.matchId()
|
|
281
|
+
return matchId
|
|
282
|
+
? (this.router.stores.matchStores.get(matchId) ?? dummyMatchStore)
|
|
283
|
+
: dummyMatchStore
|
|
284
|
+
},
|
|
285
|
+
(value) => value,
|
|
286
|
+
)
|
|
272
287
|
|
|
273
288
|
routeId = computed(() => this.currentMatch()?.routeId as string)
|
|
274
289
|
|
|
275
|
-
route = computed(
|
|
276
|
-
() => this.router.routesById[this.routeId()] as AnyRoute,
|
|
277
|
-
)
|
|
290
|
+
route = computed(() => this.router.routesById[this.routeId()] as AnyRoute)
|
|
278
291
|
|
|
279
292
|
parentGlobalNotFound = computed(
|
|
280
293
|
() => this.currentMatch()?.globalNotFound ?? false,
|
|
@@ -310,7 +323,9 @@ export class Outlet {
|
|
|
310
323
|
})
|
|
311
324
|
}
|
|
312
325
|
|
|
313
|
-
type CalledIfFunction<T> = T extends (...args: Array<any>) => any
|
|
326
|
+
type CalledIfFunction<T> = T extends (...args: Array<any>) => any
|
|
327
|
+
? ReturnType<T>
|
|
328
|
+
: T
|
|
314
329
|
|
|
315
330
|
function getComponent<T>(routeComponent: T): CalledIfFunction<T> {
|
|
316
331
|
if (typeof routeComponent === 'function') {
|
package/src/Matches.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Component } from '@angular/core'
|
|
2
2
|
import { injectRouter } from './injectRouter'
|
|
3
|
-
import { injectStore } from './injectStore'
|
|
3
|
+
import { injectStore } from './store/injectStore'
|
|
4
4
|
import { injectRender } from './renderer/injectRender'
|
|
5
5
|
import { RouteMatch } from './Match'
|
|
6
6
|
import { injectSsrScrollRestorationScript } from './ssr-scroll-restoration'
|
|
@@ -10,11 +10,14 @@ import { injectTransitionerSetup } from './transitioner'
|
|
|
10
10
|
selector: 'router-matches',
|
|
11
11
|
template: '',
|
|
12
12
|
standalone: true,
|
|
13
|
+
host: {
|
|
14
|
+
hidden: '',
|
|
15
|
+
},
|
|
13
16
|
})
|
|
14
17
|
export class Matches {
|
|
15
18
|
router = injectRouter()
|
|
16
19
|
|
|
17
|
-
private matchId = injectStore(this.router.stores.
|
|
20
|
+
private matchId = injectStore(this.router.stores.firstId, (id) => id)
|
|
18
21
|
|
|
19
22
|
private ssrScrollRestoration = injectSsrScrollRestorationScript()
|
|
20
23
|
|
package/src/RouterProvider.ts
CHANGED
|
@@ -75,6 +75,9 @@ export function provideTanstackRouter({
|
|
|
75
75
|
selector: 'router-provider,[router-provider]',
|
|
76
76
|
template: '',
|
|
77
77
|
standalone: true,
|
|
78
|
+
host: {
|
|
79
|
+
hidden: '',
|
|
80
|
+
},
|
|
78
81
|
})
|
|
79
82
|
export class RouterProvider<TRouter extends AnyRouter = RegisteredRouter> {
|
|
80
83
|
readonly injectedContext: RouterInputs<TRouter>['context'] = inject(
|
|
@@ -16,7 +16,7 @@ export function buildMatchManagedDocumentContent(
|
|
|
16
16
|
router: AnyRouter,
|
|
17
17
|
): ManagedDocumentContent {
|
|
18
18
|
const nonce = router.options.ssr?.nonce
|
|
19
|
-
const matches = router.stores.
|
|
19
|
+
const matches = router.stores.matches.get()
|
|
20
20
|
const title = selectTitle(matches)
|
|
21
21
|
const metaTags = selectMetaTags(matches, nonce)
|
|
22
22
|
const links = selectConstructedLinks(matches, nonce)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DOCUMENT } from '@angular/common'
|
|
2
2
|
import * as Angular from '@angular/core'
|
|
3
|
-
import { injectStore } from '../injectStore'
|
|
3
|
+
import { injectStore } from '../store/injectStore'
|
|
4
4
|
import { buildMatchManagedDocumentContent } from './build-match-managed-document'
|
|
5
5
|
import {
|
|
6
6
|
collectDehydrationScriptManagedTags,
|
|
@@ -9,7 +9,10 @@ import {
|
|
|
9
9
|
import { areManagedDocumentContentsEqual } from './document-equality'
|
|
10
10
|
import { createManagedTagCollection } from './managed-dom'
|
|
11
11
|
import type { AnyRouter } from '@benjavicente/router-core'
|
|
12
|
-
import type {
|
|
12
|
+
import type {
|
|
13
|
+
ManagedDocumentContent,
|
|
14
|
+
ManagedTagCollection,
|
|
15
|
+
} from './managed-document-types'
|
|
13
16
|
|
|
14
17
|
function applyManagedDocumentContent({
|
|
15
18
|
document,
|
|
@@ -45,7 +48,7 @@ export function installUnifiedTanstackDocumentSync(injectedRouter: AnyRouter) {
|
|
|
45
48
|
})
|
|
46
49
|
const destroyRef = Angular.inject(Angular.DestroyRef)
|
|
47
50
|
const activeMatches = injectStore(
|
|
48
|
-
injectedRouter.stores.
|
|
51
|
+
injectedRouter.stores.matches,
|
|
49
52
|
(matches) => matches,
|
|
50
53
|
)
|
|
51
54
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DOCUMENT } from '@angular/common'
|
|
2
2
|
import * as Angular from '@angular/core'
|
|
3
|
-
import { injectStore } from '../injectStore'
|
|
3
|
+
import { injectStore } from '../store/injectStore'
|
|
4
4
|
import { buildMatchManagedDocumentContent } from './build-match-managed-document'
|
|
5
5
|
import { collectDehydrationScriptManagedTags } from './document-dehydration'
|
|
6
6
|
import { areManagedTagArraysEqual } from './document-equality'
|
|
@@ -20,7 +20,7 @@ export function installTanstackBodyManagedTags(injectedRouter: AnyRouter) {
|
|
|
20
20
|
})
|
|
21
21
|
const destroyRef = Angular.inject(Angular.DestroyRef)
|
|
22
22
|
const activeMatches = injectStore(
|
|
23
|
-
injectedRouter.stores.
|
|
23
|
+
injectedRouter.stores.matches,
|
|
24
24
|
(matches) => matches,
|
|
25
25
|
)
|
|
26
26
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DOCUMENT } from '@angular/common'
|
|
2
2
|
import * as Angular from '@angular/core'
|
|
3
|
-
import { injectStore } from '../injectStore'
|
|
3
|
+
import { injectStore } from '../store/injectStore'
|
|
4
4
|
import { buildMatchManagedDocumentContent } from './build-match-managed-document'
|
|
5
5
|
import { TANSTACK_DOCUMENT_ROUTER } from './document-router-token'
|
|
6
6
|
import type { AnyRouter } from '@benjavicente/router-core'
|
|
@@ -10,14 +10,13 @@ export function installTanstackDocumentTitle(injectedRouter: AnyRouter) {
|
|
|
10
10
|
const document = Angular.inject(DOCUMENT)
|
|
11
11
|
const destroyRef = Angular.inject(Angular.DestroyRef)
|
|
12
12
|
const activeMatches = injectStore(
|
|
13
|
-
injectedRouter.stores.
|
|
13
|
+
injectedRouter.stores.matches,
|
|
14
14
|
(matches) => matches,
|
|
15
15
|
)
|
|
16
16
|
|
|
17
17
|
const initialTitle = document.title
|
|
18
|
-
let currentTitle: string | undefined =
|
|
19
|
-
injectedRouter
|
|
20
|
-
).title
|
|
18
|
+
let currentTitle: string | undefined =
|
|
19
|
+
buildMatchManagedDocumentContent(injectedRouter).title
|
|
21
20
|
|
|
22
21
|
const applyTitle = (next?: string) => {
|
|
23
22
|
if (next !== undefined) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DOCUMENT } from '@angular/common'
|
|
2
2
|
import * as Angular from '@angular/core'
|
|
3
|
-
import { injectStore } from '../injectStore'
|
|
3
|
+
import { injectStore } from '../store/injectStore'
|
|
4
4
|
import { buildMatchManagedDocumentContent } from './build-match-managed-document'
|
|
5
5
|
import { areManagedTagArraysEqual } from './document-equality'
|
|
6
6
|
import { TANSTACK_DOCUMENT_ROUTER } from './document-router-token'
|
|
@@ -16,7 +16,7 @@ export function installTanstackHeadManagedTags(injectedRouter: AnyRouter) {
|
|
|
16
16
|
})
|
|
17
17
|
const destroyRef = Angular.inject(Angular.DestroyRef)
|
|
18
18
|
const activeMatches = injectStore(
|
|
19
|
-
injectedRouter.stores.
|
|
19
|
+
injectedRouter.stores.matches,
|
|
20
20
|
(matches) => matches,
|
|
21
21
|
)
|
|
22
22
|
|
package/src/index.ts
CHANGED
|
@@ -54,7 +54,10 @@ export {
|
|
|
54
54
|
type InjectMatchesBaseOptions,
|
|
55
55
|
type InjectMatchesResult,
|
|
56
56
|
} from './injectMatches'
|
|
57
|
-
export {
|
|
57
|
+
export {
|
|
58
|
+
injectMatchRoute,
|
|
59
|
+
type InjectMatchRouteOptions,
|
|
60
|
+
} from './injectMatchRoute'
|
|
58
61
|
|
|
59
62
|
// Injection functions
|
|
60
63
|
export { injectRouter } from './injectRouter'
|
|
@@ -125,7 +128,7 @@ export { injectCanGoBack } from './injectCanGoBack'
|
|
|
125
128
|
|
|
126
129
|
export { injectErrorState } from './injectErrorState'
|
|
127
130
|
|
|
128
|
-
export { injectStore } from './injectStore'
|
|
131
|
+
export { injectStore } from './store/injectStore'
|
|
129
132
|
|
|
130
133
|
// Link
|
|
131
134
|
export { type LinkOptions as LinkInputOptions, Link } from './Link'
|
package/src/injectCanGoBack.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { injectRouter } from './injectRouter'
|
|
2
|
-
import { injectStore } from './injectStore'
|
|
2
|
+
import { injectStore } from './store/injectStore'
|
|
3
3
|
|
|
4
4
|
export function injectCanGoBack() {
|
|
5
5
|
const router = injectRouter()
|
|
6
6
|
|
|
7
7
|
return injectStore(
|
|
8
8
|
router.stores.location,
|
|
9
|
-
(location) => location.state
|
|
9
|
+
(location) => (location.state?.__TSR_index ?? 0) !== 0,
|
|
10
10
|
)
|
|
11
11
|
}
|
package/src/injectLocation.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { deepEqual } from '@benjavicente/router-core'
|
|
2
2
|
import { injectRouter } from './injectRouter'
|
|
3
|
-
import { injectStore } from './injectStore'
|
|
3
|
+
import { injectStore } from './store/injectStore'
|
|
4
|
+
import type * as Angular from '@angular/core'
|
|
4
5
|
import type {
|
|
5
6
|
AnyRouter,
|
|
6
7
|
RegisteredRouter,
|
|
7
8
|
RouterState,
|
|
8
9
|
} from '@benjavicente/router-core'
|
|
9
|
-
import type * as Angular from '@angular/core'
|
|
10
10
|
|
|
11
11
|
export interface InjectLocationOptions<TRouter extends AnyRouter, TSelected> {
|
|
12
12
|
select?: (
|
|
@@ -29,10 +29,13 @@ export function injectLocation<
|
|
|
29
29
|
): Angular.Signal<InjectLocationResult<TRouter, TSelected>> {
|
|
30
30
|
const router = injectRouter<TRouter>()
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
router.stores.location
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
if (!opts?.select) {
|
|
33
|
+
return injectStore(router.stores.location) as Angular.Signal<
|
|
34
|
+
InjectLocationResult<TRouter, TSelected>
|
|
35
|
+
>
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return injectStore(router.stores.location, opts.select, {
|
|
39
|
+
equal: deepEqual,
|
|
40
|
+
}) as Angular.Signal<InjectLocationResult<TRouter, TSelected>>
|
|
38
41
|
}
|