@analogjs/router 2.7.5 → 2.8.0-beta.10
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/fesm2022/analogjs-router-i18n.mjs +9 -0
- package/fesm2022/analogjs-router-i18n.mjs.map +1 -1
- package/fesm2022/analogjs-router-server-actions.mjs +470 -1
- package/fesm2022/analogjs-router-server-actions.mjs.map +1 -1
- package/fesm2022/analogjs-router-server.mjs +6 -1
- package/fesm2022/analogjs-router-server.mjs.map +1 -1
- package/fesm2022/analogjs-router-tanstack-query-server.mjs +90 -0
- package/fesm2022/analogjs-router-tanstack-query-server.mjs.map +1 -0
- package/fesm2022/analogjs-router-tanstack-query.mjs +142 -0
- package/fesm2022/analogjs-router-tanstack-query.mjs.map +1 -0
- package/fesm2022/analogjs-router.mjs +371 -17
- package/fesm2022/analogjs-router.mjs.map +1 -1
- package/package.json +17 -3
- package/types/analogjs-router-server-actions.d.ts +265 -2
- package/types/analogjs-router-tanstack-query-server.d.ts +70 -0
- package/types/analogjs-router-tanstack-query.d.ts +33 -0
- package/types/analogjs-router.d.ts +197 -17
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { makeStateKey, makeEnvironmentProviders, ENVIRONMENT_INITIALIZER, inject, TransferState, DestroyRef, PLATFORM_ID } from '@angular/core';
|
|
2
|
+
import { isPlatformServer } from '@angular/common';
|
|
3
|
+
import { Router, ResolveEnd } from '@angular/router';
|
|
4
|
+
import { QueryClient, hydrate } from '@tanstack/angular-query-experimental';
|
|
5
|
+
import { lastValueFrom } from 'rxjs';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Route-data key under `ActivatedRoute.data['load']` that holds the
|
|
9
|
+
* `DehydratedState` produced by `definePageLoadQueries`. The Router-
|
|
10
|
+
* events hydrator in `provideAnalogQuery()` looks for this key on
|
|
11
|
+
* `ResolveEnd` and merges the dehydrated payload into the active
|
|
12
|
+
* `QueryClient`, so component-issued queries hit a warm cache on
|
|
13
|
+
* first render.
|
|
14
|
+
*/
|
|
15
|
+
const ANALOG_QUERIES_KEY = '__analogQueries';
|
|
16
|
+
|
|
17
|
+
const ANALOG_QUERY_STATE_KEY = makeStateKey('analog_query_state');
|
|
18
|
+
function provideAnalogQuery() {
|
|
19
|
+
return makeEnvironmentProviders([
|
|
20
|
+
{
|
|
21
|
+
provide: ENVIRONMENT_INITIALIZER,
|
|
22
|
+
multi: true,
|
|
23
|
+
useValue() {
|
|
24
|
+
if (import.meta.env.SSR) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const transferState = inject(TransferState);
|
|
28
|
+
const client = inject(QueryClient);
|
|
29
|
+
const dehydratedState = transferState.get(ANALOG_QUERY_STATE_KEY, null);
|
|
30
|
+
if (dehydratedState) {
|
|
31
|
+
hydrate(client, dehydratedState);
|
|
32
|
+
transferState.remove(ANALOG_QUERY_STATE_KEY);
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
provide: ENVIRONMENT_INITIALIZER,
|
|
38
|
+
multi: true,
|
|
39
|
+
useValue() {
|
|
40
|
+
const router = inject(Router, { optional: true });
|
|
41
|
+
if (!router) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const client = inject(QueryClient);
|
|
45
|
+
const destroyRef = inject(DestroyRef);
|
|
46
|
+
// On the server, also mirror any dehydrated load payloads into
|
|
47
|
+
// `TransferState` so Angular's own serializer can include them in
|
|
48
|
+
// the `ng-state` script — we can't rely on
|
|
49
|
+
// `provideServerAnalogQuery()`'s `BEFORE_APP_SERIALIZED` running
|
|
50
|
+
// before Angular's `TRANSFER_STATE_SERIALIZATION_PROVIDERS`.
|
|
51
|
+
const transferState = isPlatformServer(inject(PLATFORM_ID))
|
|
52
|
+
? inject(TransferState)
|
|
53
|
+
: null;
|
|
54
|
+
const subscription = router.events.subscribe((event) => {
|
|
55
|
+
if (event instanceof ResolveEnd) {
|
|
56
|
+
mergeRouteSnapshot(event.state.root, client, transferState);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
destroyRef.onDestroy(() => subscription.unsubscribe());
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
]);
|
|
63
|
+
}
|
|
64
|
+
function mergeRouteSnapshot(snapshot, client, transferState) {
|
|
65
|
+
const load = snapshot.data?.['load'];
|
|
66
|
+
if (load && typeof load === 'object' && ANALOG_QUERIES_KEY in load) {
|
|
67
|
+
const dehydrated = load[ANALOG_QUERIES_KEY];
|
|
68
|
+
if (dehydrated) {
|
|
69
|
+
hydrate(client, dehydrated);
|
|
70
|
+
if (transferState) {
|
|
71
|
+
const existing = transferState.get(ANALOG_QUERY_STATE_KEY, null);
|
|
72
|
+
transferState.set(ANALOG_QUERY_STATE_KEY, existing ? mergeDehydrated(existing, dehydrated) : dehydrated);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
for (const child of snapshot.children) {
|
|
77
|
+
mergeRouteSnapshot(child, client, transferState);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function mergeDehydrated(base, next) {
|
|
81
|
+
// Last-writer-wins on duplicate `queryHash`: child route resolves run
|
|
82
|
+
// after parent resolves, so the later entry is the fresher one and
|
|
83
|
+
// matches `hydrate()`'s own newer-wins semantics for the QueryClient.
|
|
84
|
+
const queriesByHash = new Map(base.queries.map((query) => [query.queryHash, query]));
|
|
85
|
+
for (const query of next.queries) {
|
|
86
|
+
queriesByHash.set(query.queryHash, query);
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
mutations: [...base.mutations, ...next.mutations],
|
|
90
|
+
queries: [...queriesByHash.values()],
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function buildUrl(base, params) {
|
|
95
|
+
if (!params)
|
|
96
|
+
return base;
|
|
97
|
+
const parts = [];
|
|
98
|
+
for (const [key, value] of Object.entries(params)) {
|
|
99
|
+
if (value === undefined || value === null)
|
|
100
|
+
continue;
|
|
101
|
+
const k = encodeURIComponent(key);
|
|
102
|
+
if (Array.isArray(value)) {
|
|
103
|
+
for (const item of value) {
|
|
104
|
+
parts.push(`${k}=${encodeURIComponent(String(item))}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
parts.push(`${k}=${encodeURIComponent(String(value))}`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (parts.length === 0)
|
|
112
|
+
return base;
|
|
113
|
+
const separator = base.includes('?') ? '&' : '?';
|
|
114
|
+
return `${base}${separator}${parts.join('&')}`;
|
|
115
|
+
}
|
|
116
|
+
function serverQueryOptions(http, url, options) {
|
|
117
|
+
const { query, ...rest } = options;
|
|
118
|
+
return {
|
|
119
|
+
...rest,
|
|
120
|
+
queryFn: () => lastValueFrom(http.get(buildUrl(url, query))),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function serverMutationOptions(http, url, options) {
|
|
124
|
+
return {
|
|
125
|
+
mutationFn: (body) => lastValueFrom(http.post(url, body)),
|
|
126
|
+
...options,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function serverInfiniteQueryOptions(http, url, options) {
|
|
130
|
+
const { query: buildQuery, ...rest } = options;
|
|
131
|
+
return {
|
|
132
|
+
...rest,
|
|
133
|
+
queryFn: (context) => lastValueFrom(http.get(buildUrl(url, buildQuery(context)))),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Generated bundle index. Do not edit.
|
|
139
|
+
*/
|
|
140
|
+
|
|
141
|
+
export { ANALOG_QUERIES_KEY, ANALOG_QUERY_STATE_KEY, provideAnalogQuery, serverInfiniteQueryOptions, serverMutationOptions, serverQueryOptions };
|
|
142
|
+
//# sourceMappingURL=analogjs-router-tanstack-query.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analogjs-router-tanstack-query.mjs","sources":["../../../../packages/router/tanstack-query/src/constants.ts","../../../../packages/router/tanstack-query/src/provide-analog-query.ts","../../../../packages/router/tanstack-query/src/server-query.ts","../../../../packages/router/tanstack-query/src/analogjs-router-tanstack-query.ts"],"sourcesContent":["/**\n * Route-data key under `ActivatedRoute.data['load']` that holds the\n * `DehydratedState` produced by `definePageLoadQueries`. The Router-\n * events hydrator in `provideAnalogQuery()` looks for this key on\n * `ResolveEnd` and merges the dehydrated payload into the active\n * `QueryClient`, so component-issued queries hit a warm cache on\n * first render.\n */\nexport const ANALOG_QUERIES_KEY: '__analogQueries' = '__analogQueries';\n","import {\n DestroyRef,\n ENVIRONMENT_INITIALIZER,\n PLATFORM_ID,\n TransferState,\n inject,\n makeEnvironmentProviders,\n makeStateKey,\n} from '@angular/core';\nimport type { EnvironmentProviders, StateKey } from '@angular/core';\nimport { isPlatformServer } from '@angular/common';\nimport { ResolveEnd, Router } from '@angular/router';\nimport type { ActivatedRouteSnapshot } from '@angular/router';\nimport { QueryClient, hydrate } from '@tanstack/angular-query-experimental';\nimport type { DehydratedState } from '@tanstack/angular-query-experimental';\n\nimport { ANALOG_QUERIES_KEY } from './constants';\n\nexport const ANALOG_QUERY_STATE_KEY: StateKey<DehydratedState> =\n makeStateKey<DehydratedState>('analog_query_state');\n\nexport function provideAnalogQuery(): EnvironmentProviders {\n return makeEnvironmentProviders([\n {\n provide: ENVIRONMENT_INITIALIZER,\n multi: true,\n useValue() {\n if (import.meta.env.SSR) {\n return;\n }\n\n const transferState = inject(TransferState);\n const client = inject(QueryClient);\n const dehydratedState = transferState.get<DehydratedState | null>(\n ANALOG_QUERY_STATE_KEY,\n null,\n );\n\n if (dehydratedState) {\n hydrate(client, dehydratedState);\n transferState.remove(ANALOG_QUERY_STATE_KEY);\n }\n },\n },\n {\n provide: ENVIRONMENT_INITIALIZER,\n multi: true,\n useValue() {\n const router = inject(Router, { optional: true });\n if (!router) {\n return;\n }\n\n const client = inject(QueryClient);\n const destroyRef = inject(DestroyRef);\n // On the server, also mirror any dehydrated load payloads into\n // `TransferState` so Angular's own serializer can include them in\n // the `ng-state` script — we can't rely on\n // `provideServerAnalogQuery()`'s `BEFORE_APP_SERIALIZED` running\n // before Angular's `TRANSFER_STATE_SERIALIZATION_PROVIDERS`.\n const transferState = isPlatformServer(inject(PLATFORM_ID))\n ? inject(TransferState)\n : null;\n\n const subscription = router.events.subscribe((event) => {\n if (event instanceof ResolveEnd) {\n mergeRouteSnapshot(event.state.root, client, transferState);\n }\n });\n\n destroyRef.onDestroy(() => subscription.unsubscribe());\n },\n },\n ]);\n}\n\nfunction mergeRouteSnapshot(\n snapshot: ActivatedRouteSnapshot,\n client: QueryClient,\n transferState: TransferState | null,\n): void {\n const load = snapshot.data?.['load'];\n if (load && typeof load === 'object' && ANALOG_QUERIES_KEY in load) {\n const dehydrated = (load as Record<string, unknown>)[ANALOG_QUERIES_KEY] as\n | DehydratedState\n | undefined;\n if (dehydrated) {\n hydrate(client, dehydrated);\n if (transferState) {\n const existing = transferState.get<DehydratedState | null>(\n ANALOG_QUERY_STATE_KEY,\n null,\n );\n transferState.set(\n ANALOG_QUERY_STATE_KEY,\n existing ? mergeDehydrated(existing, dehydrated) : dehydrated,\n );\n }\n }\n }\n for (const child of snapshot.children) {\n mergeRouteSnapshot(child, client, transferState);\n }\n}\n\nfunction mergeDehydrated(\n base: DehydratedState,\n next: DehydratedState,\n): DehydratedState {\n // Last-writer-wins on duplicate `queryHash`: child route resolves run\n // after parent resolves, so the later entry is the fresher one and\n // matches `hydrate()`'s own newer-wins semantics for the QueryClient.\n const queriesByHash = new Map(\n base.queries.map((query) => [query.queryHash, query]),\n );\n for (const query of next.queries) {\n queriesByHash.set(query.queryHash, query);\n }\n return {\n mutations: [...base.mutations, ...next.mutations],\n queries: [...queriesByHash.values()],\n };\n}\n","import type { HttpClient } from '@angular/common/http';\nimport { lastValueFrom } from 'rxjs';\nimport type {\n CreateQueryOptions,\n CreateMutationOptions,\n CreateInfiniteQueryOptions,\n DefaultError,\n InfiniteData,\n QueryKey,\n} from '@tanstack/angular-query-experimental';\nimport type {\n ServerRouteHandler,\n InferRouteQuery,\n InferRouteBody,\n InferRouteResult,\n} from '@analogjs/router/server/actions';\n\nfunction buildUrl(base: string, params?: Record<string, unknown>): string {\n if (!params) return base;\n const parts: string[] = [];\n for (const [key, value] of Object.entries(params)) {\n if (value === undefined || value === null) continue;\n const k = encodeURIComponent(key);\n if (Array.isArray(value)) {\n for (const item of value) {\n parts.push(`${k}=${encodeURIComponent(String(item))}`);\n }\n } else {\n parts.push(`${k}=${encodeURIComponent(String(value))}`);\n }\n }\n if (parts.length === 0) return base;\n const separator = base.includes('?') ? '&' : '?';\n return `${base}${separator}${parts.join('&')}`;\n}\n\nexport function serverQueryOptions<\n TRoute extends ServerRouteHandler<any, any, any>,\n TError = DefaultError,\n TData = InferRouteResult<TRoute>,\n TQueryKey extends QueryKey = QueryKey,\n>(\n http: HttpClient,\n url: string,\n options: { queryKey: TQueryKey; query?: InferRouteQuery<TRoute> } & Omit<\n CreateQueryOptions<InferRouteResult<TRoute>, TError, TData, TQueryKey>,\n 'queryKey' | 'queryFn'\n >,\n): CreateQueryOptions<InferRouteResult<TRoute>, TError, TData, TQueryKey> {\n const { query, ...rest } = options;\n return {\n ...rest,\n queryFn: () =>\n lastValueFrom(\n http.get<InferRouteResult<TRoute>>(\n buildUrl(url, query as Record<string, any>),\n ),\n ),\n } as CreateQueryOptions<InferRouteResult<TRoute>, TError, TData, TQueryKey>;\n}\n\nexport function serverMutationOptions<\n TRoute extends ServerRouteHandler<any, any, any>,\n TError = DefaultError,\n TOnMutateResult = unknown,\n>(\n http: HttpClient,\n url: string,\n options?: Omit<\n CreateMutationOptions<\n InferRouteResult<TRoute>,\n TError,\n InferRouteBody<TRoute>,\n TOnMutateResult\n >,\n 'mutationFn'\n >,\n): CreateMutationOptions<\n InferRouteResult<TRoute>,\n TError,\n InferRouteBody<TRoute>,\n TOnMutateResult\n> {\n return {\n mutationFn: (body: InferRouteBody<TRoute>) =>\n lastValueFrom(http.post<InferRouteResult<TRoute>>(url, body)),\n ...options,\n } as CreateMutationOptions<\n InferRouteResult<TRoute>,\n TError,\n InferRouteBody<TRoute>,\n TOnMutateResult\n >;\n}\n\nexport function serverInfiniteQueryOptions<\n TRoute extends ServerRouteHandler<any, any, any>,\n TError = DefaultError,\n TData = InfiniteData<InferRouteResult<TRoute>>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n http: HttpClient,\n url: string,\n options: {\n queryKey: TQueryKey;\n query: (context: { pageParam: TPageParam }) => InferRouteQuery<TRoute>;\n initialPageParam: TPageParam;\n getNextPageParam: (\n lastPage: InferRouteResult<TRoute>,\n allPages: InferRouteResult<TRoute>[],\n ) => TPageParam | undefined | null;\n } & Omit<\n CreateInfiniteQueryOptions<\n InferRouteResult<TRoute>,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n 'queryKey' | 'queryFn' | 'initialPageParam' | 'getNextPageParam'\n >,\n): CreateInfiniteQueryOptions<\n InferRouteResult<TRoute>,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> {\n const { query: buildQuery, ...rest } = options;\n return {\n ...rest,\n queryFn: (context: { pageParam: TPageParam }) =>\n lastValueFrom(\n http.get<InferRouteResult<TRoute>>(\n buildUrl(url, buildQuery(context) as Record<string, any>),\n ),\n ),\n } as CreateInfiniteQueryOptions<\n InferRouteResult<TRoute>,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >;\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;AAAA;;;;;;;AAOG;AACI,MAAM,kBAAkB,GAAsB;;MCUxC,sBAAsB,GACjC,YAAY,CAAkB,oBAAoB;SAEpC,kBAAkB,GAAA;AAChC,IAAA,OAAO,wBAAwB,CAAC;AAC9B,QAAA;AACE,YAAA,OAAO,EAAE,uBAAuB;AAChC,YAAA,KAAK,EAAE,IAAI;YACX,QAAQ,GAAA;gBACN,IAAI,MAAM,C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,EAAE,KAA4B,CAAC,CAC5C,CACF;KACsE;AAC7E;SAEgB,qBAAqB,CAKnC,IAAgB,EAChB,GAAW,EACX,OAQC,EAAA;IAOD,OAAO;AACL,QAAA,UAAU,EAAE,CAAC,IAA4B,KACvC,aAAa,CAAC,IAAI,CAAC,IAAI,CAA2B,GAAG,EAAE,IAAI,CAAC,CAAC;AAC/D,QAAA,GAAG,OAAO;KAMX;AACH;SAEgB,0BAA0B,CAOxC,IAAgB,EAChB,GAAW,EACX,OAiBC,EAAA;IAQD,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,GAAG,OAAO;IAC9C,OAAO;AACL,QAAA,GAAG,IAAI;QACP,OAAO,EAAE,CAAC,OAAkC,KAC1C,aAAa,CACX,IAAI,CAAC,GAAG,CACN,QAAQ,CAAC,GAAG,EAAE,UAAU,CAAC,OAAO,CAAwB,CAAC,CAC1D,CACF;KAOJ;AACH;;ACjJA;;AAEG;;;;"}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as i1 from '@angular/router';
|
|
2
|
+
import { Router, NavigationEnd, UrlSegment, ActivatedRoute, provideRouter, ROUTES, UrlSegmentGroup, PRIMARY_OUTLET, DefaultUrlSerializer, UrlTree, RouterLink } from '@angular/router';
|
|
2
3
|
import * as i0 from '@angular/core';
|
|
3
|
-
import { inject, PLATFORM_ID, makeEnvironmentProviders, ENVIRONMENT_INITIALIZER, Injector, makeStateKey, TransferState, input, output, Directive, InjectionToken, Injectable, assertInInjectionContext, resource } from '@angular/core';
|
|
4
|
+
import { inject, PLATFORM_ID, makeEnvironmentProviders, ENVIRONMENT_INITIALIZER, Injector, makeStateKey, TransferState, input, booleanAttribute, output, signal, ElementRef, Renderer2, effect, runInInjectionContext, Directive, InjectionToken, Injectable, assertInInjectionContext, resource } from '@angular/core';
|
|
4
5
|
import { HttpClient, HttpHeaders, ɵHTTP_ROOT_INTERCEPTOR_FNS as _HTTP_ROOT_INTERCEPTOR_FNS, HttpResponse } from '@angular/common/http';
|
|
5
|
-
import { firstValueFrom, map, from, of } from 'rxjs';
|
|
6
|
+
import { firstValueFrom, map, from, of, combineLatest } from 'rxjs';
|
|
6
7
|
import { Meta } from '@angular/platform-browser';
|
|
7
8
|
import { filter } from 'rxjs/operators';
|
|
8
9
|
import { injectAPIPrefix, injectBaseURL, injectRequest, API_PREFIX } from '@analogjs/router/tokens';
|
|
9
10
|
import { isPlatformServer } from '@angular/common';
|
|
11
|
+
import { toSignal } from '@angular/core/rxjs-interop';
|
|
10
12
|
|
|
11
13
|
const ROUTE_META_TAGS_KEY = Symbol('@analogjs/router Route Meta Tags Key');
|
|
12
14
|
const CHARSET_KEY = 'charset';
|
|
@@ -761,17 +763,71 @@ class FormAction {
|
|
|
761
763
|
constructor() {
|
|
762
764
|
this.action = input('', /* @ts-ignore */
|
|
763
765
|
...(ngDevMode ? [{ debugName: "action" }] : /* istanbul ignore next */ []));
|
|
766
|
+
this.enhanceForm = input(false, { ...(ngDevMode ? { debugName: "enhanceForm" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
767
|
+
// eslint-disable-next-line @angular-eslint/no-output-on-prefix
|
|
764
768
|
this.onSuccess = output();
|
|
769
|
+
// eslint-disable-next-line @angular-eslint/no-output-on-prefix
|
|
765
770
|
this.onError = output();
|
|
766
771
|
this.state = output();
|
|
772
|
+
this.currentState = signal('idle', /* @ts-ignore */
|
|
773
|
+
...(ngDevMode ? [{ debugName: "currentState" }] : /* istanbul ignore next */ []));
|
|
774
|
+
this.injector = inject(Injector);
|
|
767
775
|
this.router = inject(Router);
|
|
768
776
|
this.route = inject(ActivatedRoute);
|
|
769
777
|
this.path = this._getPath();
|
|
778
|
+
const form = inject((ElementRef)).nativeElement;
|
|
779
|
+
const renderer = inject(Renderer2);
|
|
780
|
+
effect((onCleanup) => {
|
|
781
|
+
if (!this.enhanceForm()) {
|
|
782
|
+
return;
|
|
783
|
+
}
|
|
784
|
+
const previous = {
|
|
785
|
+
'data-state': form.getAttribute('data-state'),
|
|
786
|
+
'aria-busy': form.getAttribute('aria-busy'),
|
|
787
|
+
};
|
|
788
|
+
const state = this.currentState();
|
|
789
|
+
renderer.setAttribute(form, 'data-state', state);
|
|
790
|
+
if (state === 'submitting') {
|
|
791
|
+
renderer.setAttribute(form, 'aria-busy', 'true');
|
|
792
|
+
}
|
|
793
|
+
else {
|
|
794
|
+
renderer.removeAttribute(form, 'aria-busy');
|
|
795
|
+
}
|
|
796
|
+
onCleanup(() => {
|
|
797
|
+
for (const [name, value] of Object.entries(previous)) {
|
|
798
|
+
if (value === null) {
|
|
799
|
+
renderer.removeAttribute(form, name);
|
|
800
|
+
}
|
|
801
|
+
else {
|
|
802
|
+
renderer.setAttribute(form, name, value);
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
});
|
|
806
|
+
});
|
|
770
807
|
}
|
|
771
808
|
submitted($event) {
|
|
772
809
|
$event.preventDefault();
|
|
773
|
-
this.
|
|
810
|
+
this._emitState('submitting');
|
|
774
811
|
const body = new FormData($event.target);
|
|
812
|
+
if (this.enhanceForm()) {
|
|
813
|
+
const form = $event.target;
|
|
814
|
+
try {
|
|
815
|
+
const action = this.action().trim() || form.getAttribute('action')?.trim();
|
|
816
|
+
if (form.method.toUpperCase() === 'GET') {
|
|
817
|
+
this._handleEnhancedGet(body, action || this.router.url);
|
|
818
|
+
}
|
|
819
|
+
else {
|
|
820
|
+
const path = action
|
|
821
|
+
? new URL(action, window.location.href).toString()
|
|
822
|
+
: this._getPath();
|
|
823
|
+
void this._handleEnhancedPost(body, path, form.method);
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
catch {
|
|
827
|
+
this._emitState('error');
|
|
828
|
+
}
|
|
829
|
+
return;
|
|
830
|
+
}
|
|
775
831
|
if ($event.target.method.toUpperCase() === 'GET') {
|
|
776
832
|
this._handleGet(body, this.router.url);
|
|
777
833
|
}
|
|
@@ -782,7 +838,7 @@ class FormAction {
|
|
|
782
838
|
_handleGet(body, path) {
|
|
783
839
|
const params = {};
|
|
784
840
|
body.forEach((formVal, formKey) => (params[formKey] = formVal));
|
|
785
|
-
this.
|
|
841
|
+
this._emitState('navigate');
|
|
786
842
|
const url = path.split('?')[0];
|
|
787
843
|
this.router.navigate([url], {
|
|
788
844
|
queryParams: params,
|
|
@@ -798,19 +854,19 @@ class FormAction {
|
|
|
798
854
|
if (res.ok) {
|
|
799
855
|
if (res.redirected) {
|
|
800
856
|
const redirectUrl = new URL(res.url).pathname;
|
|
801
|
-
this.
|
|
857
|
+
this._emitState('redirect');
|
|
802
858
|
this.router.navigate([redirectUrl]);
|
|
803
859
|
}
|
|
804
860
|
else if (this._isJSON(res.headers.get('Content-type'))) {
|
|
805
861
|
res.json().then((result) => {
|
|
806
862
|
this.onSuccess.emit(result);
|
|
807
|
-
this.
|
|
863
|
+
this._emitState('success');
|
|
808
864
|
});
|
|
809
865
|
}
|
|
810
866
|
else {
|
|
811
867
|
res.text().then((result) => {
|
|
812
868
|
this.onSuccess.emit(result);
|
|
813
|
-
this.
|
|
869
|
+
this._emitState('success');
|
|
814
870
|
});
|
|
815
871
|
}
|
|
816
872
|
}
|
|
@@ -818,42 +874,118 @@ class FormAction {
|
|
|
818
874
|
if (res.headers.get('X-Analog-Errors')) {
|
|
819
875
|
res.json().then((errors) => {
|
|
820
876
|
this.onError.emit(errors);
|
|
821
|
-
this.
|
|
877
|
+
this._emitState('error');
|
|
822
878
|
});
|
|
823
879
|
}
|
|
824
880
|
else {
|
|
825
|
-
this.
|
|
881
|
+
this._emitState('error');
|
|
826
882
|
}
|
|
827
883
|
}
|
|
828
884
|
})
|
|
829
885
|
.catch((_) => {
|
|
830
|
-
this.
|
|
886
|
+
this._emitState('error');
|
|
831
887
|
});
|
|
832
888
|
}
|
|
833
889
|
_getPath() {
|
|
834
|
-
|
|
835
|
-
|
|
890
|
+
const snapshot = this.route.snapshot;
|
|
891
|
+
if (snapshot.routeConfig && ANALOG_META_KEY in snapshot.routeConfig) {
|
|
892
|
+
return runInInjectionContext(this.injector, () => injectRouteEndpointURL(snapshot)).pathname;
|
|
836
893
|
}
|
|
837
894
|
return `/api/_analog/pages${window.location.pathname}`;
|
|
838
895
|
}
|
|
896
|
+
_handleEnhancedGet(body, path) {
|
|
897
|
+
const url = new URL(path, window.location.href);
|
|
898
|
+
const params = new URLSearchParams(url.search);
|
|
899
|
+
body.forEach((_value, key) => params.delete(key));
|
|
900
|
+
body.forEach((value, key) => {
|
|
901
|
+
params.append(key, value instanceof File ? value.name : value);
|
|
902
|
+
});
|
|
903
|
+
url.search = params.toString();
|
|
904
|
+
this._emitState('navigate');
|
|
905
|
+
this._navigateTo(url);
|
|
906
|
+
}
|
|
907
|
+
async _handleEnhancedPost(body, path, method) {
|
|
908
|
+
try {
|
|
909
|
+
const response = await fetch(path, { method, body });
|
|
910
|
+
if (response.ok) {
|
|
911
|
+
if (response.redirected) {
|
|
912
|
+
this._emitState('redirect');
|
|
913
|
+
this._navigateTo(new URL(response.url, window.location.href));
|
|
914
|
+
}
|
|
915
|
+
else {
|
|
916
|
+
const result = this._isJSON(response.headers.get('Content-type'))
|
|
917
|
+
? await response.json()
|
|
918
|
+
: await response.text();
|
|
919
|
+
this.onSuccess.emit(result);
|
|
920
|
+
this._emitState('success');
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
else {
|
|
924
|
+
if (response.headers.get('X-Analog-Errors')) {
|
|
925
|
+
this.onError.emit(await response.json());
|
|
926
|
+
}
|
|
927
|
+
this._emitState('error');
|
|
928
|
+
}
|
|
929
|
+
}
|
|
930
|
+
catch {
|
|
931
|
+
this._emitState('error');
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
_emitState(state) {
|
|
935
|
+
this.currentState.set(state);
|
|
936
|
+
this.state.emit(state);
|
|
937
|
+
}
|
|
938
|
+
_navigateTo(url) {
|
|
939
|
+
if (url.origin === window.location.origin) {
|
|
940
|
+
void this.router.navigateByUrl(`${url.pathname}${url.search}${url.hash}`, {
|
|
941
|
+
onSameUrlNavigation: 'reload',
|
|
942
|
+
});
|
|
943
|
+
return;
|
|
944
|
+
}
|
|
945
|
+
window.location.assign(url.toString());
|
|
946
|
+
}
|
|
839
947
|
_isJSON(contentType) {
|
|
840
948
|
const mime = contentType ? contentType.split(';') : [];
|
|
841
949
|
const essence = mime[0];
|
|
842
950
|
return essence === 'application/json';
|
|
843
951
|
}
|
|
844
952
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.5", ngImport: i0, type: FormAction, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
845
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.1.5", type: FormAction, isStandalone: true, selector: "form[action],form[method]", inputs: { action: { classPropertyName: "action", publicName: "action", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { onSuccess: "onSuccess", onError: "onError", state: "state" }, host: { listeners: { "submit": "submitted($event)" } }, ngImport: i0 }); }
|
|
953
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.1.5", type: FormAction, isStandalone: true, selector: "form[action],form[method],form[enhanceForm]", inputs: { action: { classPropertyName: "action", publicName: "action", isSignal: true, isRequired: false, transformFunction: null }, enhanceForm: { classPropertyName: "enhanceForm", publicName: "enhanceForm", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { onSuccess: "onSuccess", onError: "onError", state: "state" }, host: { listeners: { "submit": "submitted($event)" } }, ngImport: i0 }); }
|
|
846
954
|
}
|
|
847
955
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.5", ngImport: i0, type: FormAction, decorators: [{
|
|
848
956
|
type: Directive,
|
|
849
957
|
args: [{
|
|
850
|
-
selector
|
|
958
|
+
// eslint-disable-next-line @angular-eslint/directive-selector
|
|
959
|
+
selector: 'form[action],form[method],form[enhanceForm]',
|
|
851
960
|
host: {
|
|
852
961
|
'(submit)': `submitted($event)`,
|
|
853
962
|
},
|
|
854
963
|
standalone: true,
|
|
855
964
|
}]
|
|
856
|
-
}], propDecorators: { action: [{ type: i0.Input, args: [{ isSignal: true, alias: "action", required: false }] }], onSuccess: [{ type: i0.Output, args: ["onSuccess"] }], onError: [{ type: i0.Output, args: ["onError"] }], state: [{ type: i0.Output, args: ["state"] }] } });
|
|
965
|
+
}], ctorParameters: () => [], propDecorators: { action: [{ type: i0.Input, args: [{ isSignal: true, alias: "action", required: false }] }], enhanceForm: [{ type: i0.Input, args: [{ isSignal: true, alias: "enhanceForm", required: false }] }], onSuccess: [{ type: i0.Output, args: ["onSuccess"] }], onError: [{ type: i0.Output, args: ["onError"] }], state: [{ type: i0.Output, args: ["state"] }] } });
|
|
966
|
+
|
|
967
|
+
function getPathSegmentKey(segment) {
|
|
968
|
+
return typeof segment === 'object' ? segment.key : segment;
|
|
969
|
+
}
|
|
970
|
+
function issuePathToFieldName(path) {
|
|
971
|
+
return path.map((segment) => String(getPathSegmentKey(segment))).join('.');
|
|
972
|
+
}
|
|
973
|
+
function issuesToFieldErrors(issues) {
|
|
974
|
+
return issues.reduce((errors, issue) => {
|
|
975
|
+
if (!issue.path?.length) {
|
|
976
|
+
return errors;
|
|
977
|
+
}
|
|
978
|
+
const fieldName = issuePathToFieldName(issue.path);
|
|
979
|
+
errors[fieldName] ??= [];
|
|
980
|
+
errors[fieldName].push(issue.message);
|
|
981
|
+
return errors;
|
|
982
|
+
}, Object.create(null));
|
|
983
|
+
}
|
|
984
|
+
function issuesToFormErrors(issues) {
|
|
985
|
+
return issues
|
|
986
|
+
.filter((issue) => !issue.path?.length)
|
|
987
|
+
.map((issue) => issue.message);
|
|
988
|
+
}
|
|
857
989
|
|
|
858
990
|
const DEBUG_ROUTES = new InjectionToken('@analogjs/router debug routes', {
|
|
859
991
|
providedIn: 'root',
|
|
@@ -1015,9 +1147,231 @@ function createServerFnRef(config) {
|
|
|
1015
1147
|
});
|
|
1016
1148
|
}
|
|
1017
1149
|
|
|
1150
|
+
/**
|
|
1151
|
+
* Builds a typed route link object from a route path pattern and options.
|
|
1152
|
+
*
|
|
1153
|
+
* The returned object separates path, query params, and fragment for
|
|
1154
|
+
* direct use with Angular's routerLink directive inputs.
|
|
1155
|
+
*
|
|
1156
|
+
* @example
|
|
1157
|
+
* toRoute('/about')
|
|
1158
|
+
* // → { path: ['/', 'about'], queryParams: null, fragment: undefined }
|
|
1159
|
+
*
|
|
1160
|
+
* toRoute('/users/[id]', { params: { id: '42' } })
|
|
1161
|
+
* // → { path: ['/', 'users', '42'], queryParams: null, fragment: undefined }
|
|
1162
|
+
*
|
|
1163
|
+
* toRoute('/users/[id]', { params: { id: '42' }, query: { tab: 'settings' }, hash: 'bio' })
|
|
1164
|
+
* // → { path: ['/', 'users', '42'], queryParams: { tab: 'settings' }, fragment: 'bio' }
|
|
1165
|
+
*
|
|
1166
|
+
* @example Template usage
|
|
1167
|
+
* Compute the link in the component:
|
|
1168
|
+
* ```ts
|
|
1169
|
+
* readonly link = toRoute('/users/[id]', { params: { id: '42' } });
|
|
1170
|
+
* ```
|
|
1171
|
+
*
|
|
1172
|
+
* ```html
|
|
1173
|
+
* <a [routerLink]="link.path" [queryParams]="link.queryParams" [fragment]="link.fragment">
|
|
1174
|
+
* ```
|
|
1175
|
+
*/
|
|
1176
|
+
function toRoute(path, ...args) {
|
|
1177
|
+
const options = args[0];
|
|
1178
|
+
return buildRouteLink(path, options);
|
|
1179
|
+
}
|
|
1180
|
+
/**
|
|
1181
|
+
* Internal: builds a `RouteLinkResult` from path and options.
|
|
1182
|
+
* Exported for direct use in tests (avoids generic constraints).
|
|
1183
|
+
*/
|
|
1184
|
+
function buildRouteLink(path, options) {
|
|
1185
|
+
const resolvedPath = buildPath(path, options?.params);
|
|
1186
|
+
let queryParams = null;
|
|
1187
|
+
if (options?.query) {
|
|
1188
|
+
const filtered = {};
|
|
1189
|
+
let hasEntries = false;
|
|
1190
|
+
for (const [key, value] of Object.entries(options.query)) {
|
|
1191
|
+
if (value !== undefined) {
|
|
1192
|
+
filtered[key] = value;
|
|
1193
|
+
hasEntries = true;
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
if (hasEntries) {
|
|
1197
|
+
queryParams = filtered;
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
return {
|
|
1201
|
+
path: resolvedPath,
|
|
1202
|
+
queryParams,
|
|
1203
|
+
fragment: options?.hash,
|
|
1204
|
+
};
|
|
1205
|
+
}
|
|
1206
|
+
function buildPath(path, params = {}) {
|
|
1207
|
+
const segments = path
|
|
1208
|
+
.split('/')
|
|
1209
|
+
.filter(Boolean)
|
|
1210
|
+
.flatMap((segment) => {
|
|
1211
|
+
const optional = segment.match(/^\[\[\.\.\.([^\]]+)\]\]$/);
|
|
1212
|
+
const catchAll = segment.match(/^\[\.\.\.([^\]]+)\]$/);
|
|
1213
|
+
const dynamic = segment.match(/^\[([^\]]+)\]$/);
|
|
1214
|
+
const match = optional ?? catchAll ?? dynamic;
|
|
1215
|
+
if (!match)
|
|
1216
|
+
return [segment];
|
|
1217
|
+
const value = params[match[1]];
|
|
1218
|
+
if (value == null || (Array.isArray(value) && !value.length)) {
|
|
1219
|
+
if (optional)
|
|
1220
|
+
return [];
|
|
1221
|
+
throw new Error(`Missing required ${catchAll ? 'catch-all ' : ''}param "${match[1]}" for path "${path}"`);
|
|
1222
|
+
}
|
|
1223
|
+
return Array.isArray(value) ? value.map(String) : [String(value)];
|
|
1224
|
+
});
|
|
1225
|
+
// A separate root command keeps slashes inside parameter values in one segment.
|
|
1226
|
+
return ['/', ...segments];
|
|
1227
|
+
}
|
|
1228
|
+
/** Internal URL serialization for programmatic navigation. */
|
|
1229
|
+
function buildUrl(path, options) {
|
|
1230
|
+
const link = buildRouteLink(path, options);
|
|
1231
|
+
const segments = link.path.slice(1).map((path) => new UrlSegment(path, {}));
|
|
1232
|
+
const root = new UrlSegmentGroup([], {
|
|
1233
|
+
[PRIMARY_OUTLET]: new UrlSegmentGroup(segments, {}),
|
|
1234
|
+
});
|
|
1235
|
+
return new DefaultUrlSerializer().serialize(new UrlTree(root, link.queryParams ?? {}, link.fragment ?? null));
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
class LinkTo {
|
|
1239
|
+
constructor() {
|
|
1240
|
+
this.linkTo = input.required(/* @ts-ignore */
|
|
1241
|
+
...(ngDevMode ? [{ debugName: "linkTo" }] : /* istanbul ignore next */ []));
|
|
1242
|
+
this.routerLink = inject(RouterLink);
|
|
1243
|
+
}
|
|
1244
|
+
ngOnChanges() {
|
|
1245
|
+
const destination = this.linkTo();
|
|
1246
|
+
const link = destination
|
|
1247
|
+
? typeof destination === 'string'
|
|
1248
|
+
? buildRouteLink(destination)
|
|
1249
|
+
: buildRouteLink(destination.path, destination)
|
|
1250
|
+
: null;
|
|
1251
|
+
this.routerLink.routerLink = link?.path ?? null;
|
|
1252
|
+
this.routerLink.queryParams = link?.queryParams ?? null;
|
|
1253
|
+
this.routerLink.fragment = link?.fragment;
|
|
1254
|
+
// Direct input assignments must also refresh href and RouterLinkActive.
|
|
1255
|
+
this.routerLink.ngOnChanges({});
|
|
1256
|
+
}
|
|
1257
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.5", ngImport: i0, type: LinkTo, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
|
|
1258
|
+
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.1.5", type: LinkTo, isStandalone: true, selector: "[linkTo]", inputs: { linkTo: { classPropertyName: "linkTo", publicName: "linkTo", isSignal: true, isRequired: true, transformFunction: null } }, usesOnChanges: true, hostDirectives: [{ directive: i1.RouterLink, inputs: ["target", "target", "queryParamsHandling", "queryParamsHandling", "preserveFragment", "preserveFragment", "skipLocationChange", "skipLocationChange", "replaceUrl", "replaceUrl", "state", "state"] }], ngImport: i0 }); }
|
|
1259
|
+
}
|
|
1260
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.5", ngImport: i0, type: LinkTo, decorators: [{
|
|
1261
|
+
type: Directive,
|
|
1262
|
+
args: [{
|
|
1263
|
+
// eslint-disable-next-line @angular-eslint/directive-selector
|
|
1264
|
+
selector: '[linkTo]',
|
|
1265
|
+
standalone: true,
|
|
1266
|
+
hostDirectives: [
|
|
1267
|
+
{
|
|
1268
|
+
directive: RouterLink,
|
|
1269
|
+
inputs: [
|
|
1270
|
+
'target',
|
|
1271
|
+
'queryParamsHandling',
|
|
1272
|
+
'preserveFragment',
|
|
1273
|
+
'skipLocationChange',
|
|
1274
|
+
'replaceUrl',
|
|
1275
|
+
'state',
|
|
1276
|
+
],
|
|
1277
|
+
},
|
|
1278
|
+
],
|
|
1279
|
+
}]
|
|
1280
|
+
}], propDecorators: { linkTo: [{ type: i0.Input, args: [{ isSignal: true, alias: "linkTo", required: true }] }] } });
|
|
1281
|
+
|
|
1282
|
+
function isRoutePathOptionsBase(value) {
|
|
1283
|
+
return (!!value &&
|
|
1284
|
+
typeof value === 'object' &&
|
|
1285
|
+
('params' in value || 'query' in value || 'hash' in value));
|
|
1286
|
+
}
|
|
1287
|
+
/**
|
|
1288
|
+
* Injects a typed navigate function.
|
|
1289
|
+
*
|
|
1290
|
+
* @example
|
|
1291
|
+
* ```ts
|
|
1292
|
+
* const navigate = injectNavigate();
|
|
1293
|
+
*
|
|
1294
|
+
* navigate('/users/[id]', { params: { id: '42' } }); // ✅
|
|
1295
|
+
* navigate('/users/[id]', { params: { id: 42 } }); // ✅
|
|
1296
|
+
*
|
|
1297
|
+
* // With navigation extras
|
|
1298
|
+
* navigate('/users/[id]', { params: { id: '42' } }, { replaceUrl: true });
|
|
1299
|
+
* ```
|
|
1300
|
+
*/
|
|
1301
|
+
function injectNavigate() {
|
|
1302
|
+
const router = inject(Router);
|
|
1303
|
+
const navigate = (path, ...args) => {
|
|
1304
|
+
let options;
|
|
1305
|
+
let extras;
|
|
1306
|
+
if (args.length > 1) {
|
|
1307
|
+
options = args[0];
|
|
1308
|
+
extras = args[1];
|
|
1309
|
+
}
|
|
1310
|
+
else if (args.length === 1) {
|
|
1311
|
+
if (isRoutePathOptionsBase(args[0])) {
|
|
1312
|
+
options = args[0];
|
|
1313
|
+
}
|
|
1314
|
+
else {
|
|
1315
|
+
extras = args[0];
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
const url = buildUrl(path, options);
|
|
1319
|
+
return router.navigateByUrl(url, extras);
|
|
1320
|
+
};
|
|
1321
|
+
return navigate;
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
function extractCatchAllParams(routePath) {
|
|
1325
|
+
const params = [];
|
|
1326
|
+
for (const segment of routePath.split('/')) {
|
|
1327
|
+
const optional = segment.match(/^\[\[\.\.\.([^\]]+)\]\]$/);
|
|
1328
|
+
const required = segment.match(/^\[\.\.\.([^\]]+)\]$/);
|
|
1329
|
+
if (optional) {
|
|
1330
|
+
params.push({ name: optional[1], type: 'optionalCatchAll' });
|
|
1331
|
+
}
|
|
1332
|
+
else if (required) {
|
|
1333
|
+
params.push({ name: required[1], type: 'catchAll' });
|
|
1334
|
+
}
|
|
1335
|
+
}
|
|
1336
|
+
return params;
|
|
1337
|
+
}
|
|
1338
|
+
/** Read raw route params; catch-all segments are returned as arrays. */
|
|
1339
|
+
function injectParams(_from, options) {
|
|
1340
|
+
const injector = options?.injector;
|
|
1341
|
+
const route = injector
|
|
1342
|
+
? injector.get(ActivatedRoute)
|
|
1343
|
+
: inject(ActivatedRoute);
|
|
1344
|
+
const ancestors = route.pathFromRoot ?? [route];
|
|
1345
|
+
const catchAllParams = extractCatchAllParams(_from);
|
|
1346
|
+
return toSignal(combineLatest([
|
|
1347
|
+
combineLatest(ancestors.map((entry) => entry.params)),
|
|
1348
|
+
combineLatest(ancestors.map((entry) => entry.url ?? of([]))),
|
|
1349
|
+
]).pipe(map(([values, segments]) => {
|
|
1350
|
+
const params = Object.assign({}, ...values);
|
|
1351
|
+
for (const param of catchAllParams) {
|
|
1352
|
+
const source = ancestors.findIndex((entry, index) => param.type === 'catchAll'
|
|
1353
|
+
? entry.routeConfig?.path === '**'
|
|
1354
|
+
: !!entry.routeConfig?.matcher &&
|
|
1355
|
+
values[index][param.name] != null);
|
|
1356
|
+
if (source !== -1) {
|
|
1357
|
+
params[param.name] = segments[source].map((segment) => segment.path);
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
return params;
|
|
1361
|
+
})), { requireSync: true, injector });
|
|
1362
|
+
}
|
|
1363
|
+
/** Read raw query params as a signal. No schema coercion is performed. */
|
|
1364
|
+
function injectQuery(_from, options) {
|
|
1365
|
+
const injector = options?.injector;
|
|
1366
|
+
const route = injector
|
|
1367
|
+
? injector.get(ActivatedRoute)
|
|
1368
|
+
: inject(ActivatedRoute);
|
|
1369
|
+
return toSignal(route.queryParams.pipe(map((params) => params)), { requireSync: true, injector });
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1018
1372
|
/**
|
|
1019
1373
|
* Generated bundle index. Do not edit.
|
|
1020
1374
|
*/
|
|
1021
1375
|
|
|
1022
|
-
export { FormAction, SERVER_FN_DISPATCHER, ServerFnClient, createRoutes, createServerFnRef, defineRouteMeta, getLoadResolver, injectActivatedRoute, injectDebugRoutes, injectLoad, injectRouteEndpointURL, injectRouter, injectServerFn, injectServerFnMutation, provideFileRouter, provideServerFnClient, requestContextInterceptor, routes, withDebugRoutes, withExtraRoutes };
|
|
1376
|
+
export { FormAction, LinkTo, SERVER_FN_DISPATCHER, ServerFnClient, createRoutes, createServerFnRef, defineRouteMeta, getLoadResolver, injectActivatedRoute, injectDebugRoutes, injectLoad, injectNavigate, injectParams, injectQuery, injectRouteEndpointURL, injectRouter, injectServerFn, injectServerFnMutation, issuePathToFieldName, issuesToFieldErrors, issuesToFormErrors, provideFileRouter, provideServerFnClient, requestContextInterceptor, routes, toRoute, withDebugRoutes, withExtraRoutes };
|
|
1023
1377
|
//# sourceMappingURL=analogjs-router.mjs.map
|