@analogjs/router 3.0.0-alpha.9 → 3.0.0-alpha.91

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.
Files changed (98) hide show
  1. package/content/package.json +4 -0
  2. package/fesm2022/analogjs-router-content.mjs +63 -0
  3. package/fesm2022/analogjs-router-content.mjs.map +1 -0
  4. package/fesm2022/analogjs-router-i18n.mjs +156 -0
  5. package/fesm2022/analogjs-router-i18n.mjs.map +1 -0
  6. package/fesm2022/analogjs-router-server-actions.mjs +2 -27
  7. package/fesm2022/analogjs-router-server.mjs +734 -105
  8. package/fesm2022/analogjs-router-server.mjs.map +1 -0
  9. package/fesm2022/analogjs-router-tanstack-query-server.mjs +71 -0
  10. package/fesm2022/analogjs-router-tanstack-query-server.mjs.map +1 -0
  11. package/fesm2022/analogjs-router-tanstack-query.mjs +39 -0
  12. package/fesm2022/analogjs-router-tanstack-query.mjs.map +1 -0
  13. package/fesm2022/analogjs-router-tokens.mjs +7 -2
  14. package/fesm2022/analogjs-router-tokens.mjs.map +1 -0
  15. package/fesm2022/analogjs-router.mjs +740 -155
  16. package/fesm2022/analogjs-router.mjs.map +1 -0
  17. package/fesm2022/debug.page.mjs +53 -31
  18. package/fesm2022/debug.page.mjs.map +1 -0
  19. package/fesm2022/provide-analog-query.mjs +72 -0
  20. package/fesm2022/provide-analog-query.mjs.map +1 -0
  21. package/fesm2022/route-files.mjs +361 -0
  22. package/fesm2022/route-files.mjs.map +1 -0
  23. package/fesm2022/routes.mjs +5 -278
  24. package/fesm2022/routes.mjs.map +1 -0
  25. package/fesm2022/src.mjs +335 -0
  26. package/fesm2022/src.mjs.map +1 -0
  27. package/i18n/package.json +4 -0
  28. package/package.json +51 -6
  29. package/tanstack-query/package.json +4 -0
  30. package/tanstack-query/server/package.json +4 -0
  31. package/types/content/src/index.d.ts +4 -0
  32. package/types/content/src/lib/debug/routes.d.ts +10 -0
  33. package/types/{src → content/src}/lib/markdown-helpers.d.ts +1 -1
  34. package/types/content/src/lib/routes.d.ts +8 -0
  35. package/types/content/src/lib/with-content-routes.d.ts +2 -0
  36. package/types/i18n/src/index.d.ts +1 -0
  37. package/types/i18n/src/provide-i18n.d.ts +92 -0
  38. package/types/server/actions/src/actions.d.ts +1 -1
  39. package/types/server/actions/src/define-action.d.ts +54 -0
  40. package/types/server/actions/src/define-api-route.d.ts +57 -0
  41. package/types/server/actions/src/define-page-load.d.ts +55 -0
  42. package/types/server/actions/src/define-server-route.d.ts +68 -0
  43. package/types/server/actions/src/index.d.ts +9 -1
  44. package/types/server/actions/src/parse-request-data.d.ts +9 -0
  45. package/types/server/actions/src/validate.d.ts +8 -0
  46. package/types/server/src/defer-reconcile-runtime.d.ts +23 -0
  47. package/types/server/src/index.d.ts +9 -2
  48. package/types/server/src/provide-server-context.d.ts +15 -1
  49. package/types/server/src/render-stream.d.ts +40 -0
  50. package/types/server/src/render.d.ts +3 -3
  51. package/types/server/src/server-fn/app-injector.d.ts +30 -0
  52. package/types/server/src/server-fn/dispatch.d.ts +56 -0
  53. package/types/server/src/server-fn/event-handler.d.ts +22 -0
  54. package/types/server/src/server-fn/interceptors.d.ts +30 -0
  55. package/types/server/src/server-fn/node-context.d.ts +14 -0
  56. package/types/server/src/server-fn/registry.d.ts +7 -0
  57. package/types/server/src/server-fn/same-origin.d.ts +46 -0
  58. package/types/server/src/server-fn/server-fn.d.ts +21 -0
  59. package/types/server/src/server-fn/ssr-dispatcher.d.ts +17 -0
  60. package/types/server/src/utils/reset-component-def-tviews.d.ts +14 -0
  61. package/types/server/src/utils/stream-html.d.ts +13 -0
  62. package/types/server/src/utils/stream-request.d.ts +24 -0
  63. package/types/src/index.d.ts +18 -6
  64. package/types/src/lib/cookie-interceptor.d.ts +1 -1
  65. package/types/src/lib/debug/debug.page.d.ts +4 -2
  66. package/types/src/lib/define-route.d.ts +6 -1
  67. package/types/src/lib/endpoints.d.ts +1 -1
  68. package/types/src/lib/form-action.directive.d.ts +12 -5
  69. package/types/src/lib/inject-load.d.ts +9 -1
  70. package/types/src/lib/inject-navigate.d.ts +56 -0
  71. package/types/src/lib/inject-typed-params.d.ts +33 -0
  72. package/types/src/lib/json-ld.d.ts +32 -0
  73. package/types/src/lib/link-to.directive.d.ts +38 -0
  74. package/types/src/lib/meta-tags.d.ts +3 -1
  75. package/types/src/lib/models.d.ts +3 -0
  76. package/types/src/lib/provide-file-router-base.d.ts +4 -0
  77. package/types/src/lib/provide-file-router.d.ts +2 -8
  78. package/types/src/lib/route-builder.d.ts +5 -0
  79. package/types/src/lib/route-files.d.ts +18 -0
  80. package/types/src/lib/route-types.d.ts +3 -2
  81. package/types/src/lib/routes.d.ts +2 -10
  82. package/types/src/lib/server-fn/dispatcher.d.ts +23 -0
  83. package/types/src/lib/server-fn/inject-server-fn.d.ts +44 -0
  84. package/types/src/lib/server-fn/server-fn-ref.d.ts +24 -0
  85. package/types/src/lib/server-fn/types.d.ts +55 -0
  86. package/types/src/lib/to-route.d.ts +246 -0
  87. package/types/src/lib/validation-errors.d.ts +7 -0
  88. package/types/tanstack-query/server/src/define-page-load-queries.d.ts +66 -0
  89. package/types/tanstack-query/server/src/index.d.ts +3 -0
  90. package/types/tanstack-query/src/constants.d.ts +9 -0
  91. package/types/tanstack-query/src/index.d.ts +2 -0
  92. package/types/tanstack-query/src/provide-analog-query.d.ts +4 -0
  93. package/types/tanstack-query/src/provide-server-analog-query.d.ts +2 -0
  94. package/types/tanstack-query/src/server-query.d.ts +16 -0
  95. package/types/tokens/src/index.d.ts +3 -1
  96. package/types/server/src/server-component-render.d.ts +0 -4
  97. package/types/server/src/tokens.d.ts +0 -7
  98. package/types/src/lib/server.component.d.ts +0 -33
@@ -1,12 +1,15 @@
1
- import { a as updateMetaTagsOnRouteChange, i as injectRouteEndpointURL, n as createRoutes, r as routes, t as injectDebugRoutes } from "./routes.mjs";
2
- import { ActivatedRoute, ROUTES, Router, provideRouter } from "@angular/router";
1
+ import { API_PREFIX, injectAPIPrefix, injectBaseURL, injectInternalServerFetch, injectRequest } from "./analogjs-router-tokens.mjs";
2
+ import { a as updateMetaTagsOnRouteChange, i as injectRouteEndpointURL, n as ANALOG_ROUTE_FILES, o as updateJsonLdOnRouteChange, r as createRoutes$1, t as ANALOG_EXTRA_ROUTE_FILE_SOURCES } from "./route-files.mjs";
3
+ import { n as createRoutes, r as routes, t as injectDebugRoutes } from "./routes.mjs";
4
+ import * as i1 from "@angular/router";
5
+ import { ActivatedRoute, ROUTES, Router, RouterLink, provideRouter } from "@angular/router";
3
6
  import * as i0 from "@angular/core";
4
- import { ChangeDetectionStrategy, Component, Directive, ENVIRONMENT_INITIALIZER, Injector, PLATFORM_ID, TransferState, effect, inject, input, makeEnvironmentProviders, makeStateKey, output, signal } from "@angular/core";
5
- import { HttpClient, HttpHeaders, HttpRequest, HttpResponse, ɵHTTP_ROOT_INTERCEPTOR_FNS } from "@angular/common/http";
6
- import { catchError, from, map, of, throwError } from "rxjs";
7
- import { API_PREFIX, injectAPIPrefix, injectBaseURL, injectInternalServerFetch, injectRequest } from "@analogjs/router/tokens";
8
- import { DomSanitizer } from "@angular/platform-browser";
7
+ import { DOCUMENT, Directive, Injectable, InjectionToken, Injector, PLATFORM_ID, TransferState, assertInInjectionContext, inject, input, makeEnvironmentProviders, makeStateKey, output, provideAppInitializer, resource, signal } from "@angular/core";
8
+ import { HttpClient, HttpHeaders, HttpResponse, ɵHTTP_ROOT_INTERCEPTOR_FNS } from "@angular/common/http";
9
+ import { combineLatest, firstValueFrom, from, map, of } from "rxjs";
10
+ import { Meta } from "@angular/platform-browser";
9
11
  import { isPlatformServer } from "@angular/common";
12
+ import { toSignal } from "@angular/core/rxjs-interop";
10
13
  //#region packages/router/src/lib/define-route.ts
11
14
  /**
12
15
  * @deprecated Use `RouteMeta` type instead.
@@ -66,26 +69,38 @@ function cookieInterceptor(req, next, location = inject(PLATFORM_ID), serverRequ
66
69
  } else return next(req);
67
70
  }
68
71
  //#endregion
69
- //#region packages/router/src/lib/provide-file-router.ts
70
- /**
71
- * Sets up providers for the Angular router, and registers
72
- * file-based routes. Additional features can be provided
73
- * to further configure the behavior of the router.
74
- *
75
- * @param features
76
- * @returns Providers and features to configure the router with routes
77
- */
78
- function provideFileRouter(...features) {
72
+ //#region packages/router/src/lib/provide-file-router-base.ts
73
+ function provideFileRouterWithRoutes(...features) {
79
74
  const extraRoutesFeature = features.filter((feat) => feat.ɵkind >= 100);
80
75
  const routerFeatures = features.filter((feat) => feat.ɵkind < 100);
81
76
  return makeEnvironmentProviders([
82
77
  extraRoutesFeature.map((erf) => erf.ɵproviders),
83
- provideRouter(routes, ...routerFeatures),
78
+ provideRouter([], ...routerFeatures),
84
79
  {
85
- provide: ENVIRONMENT_INITIALIZER,
80
+ provide: ROUTES,
86
81
  multi: true,
87
- useValue: () => updateMetaTagsOnRouteChange()
82
+ useFactory: () => {
83
+ const extraSources = inject(ANALOG_EXTRA_ROUTE_FILE_SOURCES, { optional: true }) ?? [];
84
+ if (extraSources.length === 0) return createRoutes$1(ANALOG_ROUTE_FILES, (_filename, fileLoader) => fileLoader);
85
+ const allFiles = { ...ANALOG_ROUTE_FILES };
86
+ const resolverMap = /* @__PURE__ */ new Map();
87
+ for (const source of extraSources) for (const [key, loader] of Object.entries(source.files)) {
88
+ allFiles[key] = loader;
89
+ resolverMap.set(key, source.resolveModule);
90
+ }
91
+ return createRoutes$1(allFiles, (filename, fileLoader) => {
92
+ const resolver = resolverMap.get(filename);
93
+ return resolver ? resolver(filename, fileLoader) : fileLoader;
94
+ });
95
+ }
88
96
  },
97
+ provideAppInitializer(() => {
98
+ const router = inject(Router);
99
+ const meta = inject(Meta);
100
+ const document = inject(DOCUMENT, { optional: true });
101
+ updateMetaTagsOnRouteChange(router, meta);
102
+ updateJsonLdOnRouteChange(router, document);
103
+ }),
89
104
  {
90
105
  provide: ɵHTTP_ROOT_INTERCEPTOR_FNS,
91
106
  multi: true,
@@ -99,12 +114,6 @@ function provideFileRouter(...features) {
99
114
  }
100
115
  ]);
101
116
  }
102
- /**
103
- * Provides extra custom routes in addition to the routes
104
- * discovered from the filesystem-based routing. These routes are
105
- * inserted before the filesystem-based routes, and take priority in
106
- * route matching.
107
- */
108
117
  function withExtraRoutes(routes) {
109
118
  return {
110
119
  ɵkind: 100,
@@ -116,9 +125,31 @@ function withExtraRoutes(routes) {
116
125
  };
117
126
  }
118
127
  //#endregion
128
+ //#region packages/router/src/lib/provide-file-router.ts
129
+ /**
130
+ * Sets up providers for the Angular router, and registers
131
+ * file-based routes. Additional features can be provided
132
+ * to further configure the behavior of the router.
133
+ *
134
+ * @param features
135
+ * @returns Providers and features to configure the router with routes
136
+ */
137
+ function provideFileRouter(...features) {
138
+ return provideFileRouterWithRoutes(...features);
139
+ }
140
+ //#endregion
119
141
  //#region packages/router/src/lib/inject-load.ts
120
- function injectLoad(options) {
121
- return (options?.injector ?? inject(Injector)).get(ActivatedRoute).data.pipe(map((data) => data["load"]));
142
+ function injectLoad(pathOrOptions, options) {
143
+ return ((typeof pathOrOptions === "string" ? options : pathOrOptions)?.injector ?? inject(Injector)).get(ActivatedRoute).data.pipe(map((data) => data["load"]));
144
+ }
145
+ function isResponse(value) {
146
+ return typeof value === "object" && value instanceof Response;
147
+ }
148
+ function injectLoadData(options) {
149
+ return injectLoad(options).pipe(map((result) => {
150
+ if (isResponse(result)) throw new Error("Expected page load data but received a response.");
151
+ return result;
152
+ }));
122
153
  }
123
154
  //#endregion
124
155
  //#region packages/router/src/lib/get-load-resolver.ts
@@ -133,8 +164,14 @@ async function getLoadResolver(route) {
133
164
  }
134
165
  //#endregion
135
166
  //#region packages/router/src/lib/cache-key.ts
167
+ function encodeAtom(value) {
168
+ return `${value.length}:${value}`;
169
+ }
136
170
  function sortAndConcatParams(params) {
137
- return [...params.keys()].sort().map((k) => `${k}=${params.getAll(k)}`).join("&");
171
+ const keys = [...new Set(params.keys())].sort();
172
+ const atoms = [];
173
+ for (const key of keys) for (const value of params.getAll(key) ?? []) atoms.push(encodeAtom(key), encodeAtom(value));
174
+ return atoms.join("");
138
175
  }
139
176
  function makeCacheKey(request, mappedRequestUrl) {
140
177
  const { params, method, responseType } = request;
@@ -148,19 +185,177 @@ function makeCacheKey(request, mappedRequestUrl) {
148
185
  mappedRequestUrl,
149
186
  serializedBody,
150
187
  encodedParams
151
- ].join("|")));
188
+ ].map(encodeAtom).join("")));
152
189
  }
153
- function generateHash(str) {
154
- let hash = 0;
155
- for (let i = 0, len = str.length; i < len; i++) {
156
- const chr = str.charCodeAt(i);
157
- hash = (hash << 5) - hash + chr;
158
- hash |= 0;
190
+ /**
191
+ * SHA-256 round constants (first 32 bits of the fractional parts of the cube
192
+ * roots of the first 64 primes).
193
+ */
194
+ var SHA256_ROUND_CONSTANTS = /* @__PURE__ */ new Uint32Array([
195
+ 1116352408,
196
+ 1899447441,
197
+ 3049323471,
198
+ 3921009573,
199
+ 961987163,
200
+ 1508970993,
201
+ 2453635748,
202
+ 2870763221,
203
+ 3624381080,
204
+ 310598401,
205
+ 607225278,
206
+ 1426881987,
207
+ 1925078388,
208
+ 2162078206,
209
+ 2614888103,
210
+ 3248222580,
211
+ 3835390401,
212
+ 4022224774,
213
+ 264347078,
214
+ 604807628,
215
+ 770255983,
216
+ 1249150122,
217
+ 1555081692,
218
+ 1996064986,
219
+ 2554220882,
220
+ 2821834349,
221
+ 2952996808,
222
+ 3210313671,
223
+ 3336571891,
224
+ 3584528711,
225
+ 113926993,
226
+ 338241895,
227
+ 666307205,
228
+ 773529912,
229
+ 1294757372,
230
+ 1396182291,
231
+ 1695183700,
232
+ 1986661051,
233
+ 2177026350,
234
+ 2456956037,
235
+ 2730485921,
236
+ 2820302411,
237
+ 3259730800,
238
+ 3345764771,
239
+ 3516065817,
240
+ 3600352804,
241
+ 4094571909,
242
+ 275423344,
243
+ 430227734,
244
+ 506948616,
245
+ 659060556,
246
+ 883997877,
247
+ 958139571,
248
+ 1322822218,
249
+ 1537002063,
250
+ 1747873779,
251
+ 1955562222,
252
+ 2024104815,
253
+ 2227730452,
254
+ 2361852424,
255
+ 2428436474,
256
+ 2756734187,
257
+ 3204031479,
258
+ 3329325298
259
+ ]);
260
+ var textEncoder;
261
+ /**
262
+ * Generates a SHA-256 hash of a string. This mirrors Angular's `HttpTransferCache`
263
+ * key derivation: a synchronous SHA-256 is used because the Web Crypto API is
264
+ * asynchronous, whereas cache-key derivation in the interceptor must stay
265
+ * synchronous. The previous 32-bit DJB2 hash had a keyspace small enough for an
266
+ * attacker to craft colliding requests and poison the transfer cache.
267
+ */
268
+ function generateHash(value) {
269
+ textEncoder ??= new TextEncoder();
270
+ const inputBytes = textEncoder.encode(value);
271
+ let hashState0 = 1779033703;
272
+ let hashState1 = 3144134277;
273
+ let hashState2 = 1013904242;
274
+ let hashState3 = 2773480762;
275
+ let hashState4 = 1359893119;
276
+ let hashState5 = 2600822924;
277
+ let hashState6 = 528734635;
278
+ let hashState7 = 1541459225;
279
+ const messageLengthInBits = inputBytes.length * 8;
280
+ const paddedLengthInBytes = (inputBytes.length + 8 >> 6) + 1 << 6;
281
+ const paddedBytes = new Uint8Array(paddedLengthInBytes);
282
+ paddedBytes.set(inputBytes);
283
+ paddedBytes[inputBytes.length] = 128;
284
+ const paddedBytesView = new DataView(paddedBytes.buffer);
285
+ const lowBits = messageLengthInBits >>> 0;
286
+ const highBits = messageLengthInBits / 4294967296 >>> 0;
287
+ paddedBytesView.setUint32(paddedLengthInBytes - 8, highBits, false);
288
+ paddedBytesView.setUint32(paddedLengthInBytes - 4, lowBits, false);
289
+ const messageSchedule = new Uint32Array(64);
290
+ for (let chunkOffset = 0; chunkOffset < paddedLengthInBytes; chunkOffset += 64) {
291
+ for (let i = 0; i < 16; i++) messageSchedule[i] = paddedBytesView.getUint32(chunkOffset + i * 4, false);
292
+ for (let i = 16; i < 64; i++) {
293
+ const prevWord15 = messageSchedule[i - 15];
294
+ const sigma0 = ((prevWord15 >>> 7 | prevWord15 << 25) ^ (prevWord15 >>> 18 | prevWord15 << 14) ^ prevWord15 >>> 3) >>> 0;
295
+ const prevWord2 = messageSchedule[i - 2];
296
+ const sigma1 = ((prevWord2 >>> 17 | prevWord2 << 15) ^ (prevWord2 >>> 19 | prevWord2 << 13) ^ prevWord2 >>> 10) >>> 0;
297
+ messageSchedule[i] = messageSchedule[i - 16] + sigma0 + messageSchedule[i - 7] + sigma1 >>> 0;
298
+ }
299
+ let workingStateA = hashState0;
300
+ let workingStateB = hashState1;
301
+ let workingStateC = hashState2;
302
+ let workingStateD = hashState3;
303
+ let workingStateE = hashState4;
304
+ let workingStateF = hashState5;
305
+ let workingStateG = hashState6;
306
+ let workingStateH = hashState7;
307
+ for (let i = 0; i < 64; i++) {
308
+ const capitalSigma1 = ((workingStateE >>> 6 | workingStateE << 26) ^ (workingStateE >>> 11 | workingStateE << 21) ^ (workingStateE >>> 25 | workingStateE << 7)) >>> 0;
309
+ const chFunction = (workingStateE & workingStateF ^ ~workingStateE & workingStateG) >>> 0;
310
+ const temp1 = workingStateH + capitalSigma1 + chFunction + SHA256_ROUND_CONSTANTS[i] + messageSchedule[i] >>> 0;
311
+ const temp2 = (((workingStateA >>> 2 | workingStateA << 30) ^ (workingStateA >>> 13 | workingStateA << 19) ^ (workingStateA >>> 22 | workingStateA << 10)) >>> 0) + ((workingStateA & workingStateB ^ workingStateA & workingStateC ^ workingStateB & workingStateC) >>> 0) >>> 0;
312
+ workingStateH = workingStateG;
313
+ workingStateG = workingStateF;
314
+ workingStateF = workingStateE;
315
+ workingStateE = workingStateD + temp1 >>> 0;
316
+ workingStateD = workingStateC;
317
+ workingStateC = workingStateB;
318
+ workingStateB = workingStateA;
319
+ workingStateA = temp1 + temp2 >>> 0;
320
+ }
321
+ hashState0 = hashState0 + workingStateA >>> 0;
322
+ hashState1 = hashState1 + workingStateB >>> 0;
323
+ hashState2 = hashState2 + workingStateC >>> 0;
324
+ hashState3 = hashState3 + workingStateD >>> 0;
325
+ hashState4 = hashState4 + workingStateE >>> 0;
326
+ hashState5 = hashState5 + workingStateF >>> 0;
327
+ hashState6 = hashState6 + workingStateG >>> 0;
328
+ hashState7 = hashState7 + workingStateH >>> 0;
159
329
  }
160
- return `${hash}`;
330
+ return [
331
+ hashState0,
332
+ hashState1,
333
+ hashState2,
334
+ hashState3,
335
+ hashState4,
336
+ hashState5,
337
+ hashState6,
338
+ hashState7
339
+ ].map((x) => x.toString(16).padStart(8, "0")).join("");
161
340
  }
162
341
  //#endregion
163
342
  //#region packages/router/src/lib/request-context.ts
343
+ function mergeFetchParams(requestUrl, request) {
344
+ const merged = /* @__PURE__ */ new Map();
345
+ for (const key of requestUrl.searchParams.keys()) {
346
+ const values = requestUrl.searchParams.getAll(key);
347
+ if (values.length > 0) merged.set(key, values);
348
+ }
349
+ for (const key of request.params.keys()) {
350
+ const values = request.params.getAll(key);
351
+ if (values?.length) merged.set(key, values);
352
+ }
353
+ if (merged.size === 0) return;
354
+ return [...merged.entries()].reduce((params, [key, values]) => {
355
+ params[key] = values.length === 1 ? values[0] : values;
356
+ return params;
357
+ }, {});
358
+ }
164
359
  /**
165
360
  * Interceptor that is server-aware when making HttpClient requests.
166
361
  * Server-side requests use the full URL
@@ -178,20 +373,22 @@ function requestContextInterceptor(req, next) {
178
373
  const nitroGlobal = globalThis;
179
374
  const serverFetch = injectInternalServerFetch() ?? nitroGlobal.$fetch;
180
375
  if (serverFetch && baseUrl && (req.url.startsWith("/") || req.url.startsWith(baseUrl) || req.url.startsWith(`/${apiPrefix}`))) {
181
- const requestUrl = new URL(req.url, baseUrl);
182
- const storeKey = makeStateKey(`analog_${makeCacheKey(req, new URL(requestUrl).pathname)}`);
376
+ const requestUrl = new URL(req.urlWithParams, baseUrl);
377
+ const storeKey = makeStateKey(`analog_${makeCacheKey(req, `${requestUrl.pathname}${requestUrl.search}`)}`);
183
378
  const fetchUrl = requestUrl.pathname;
379
+ const fetchParams = mergeFetchParams(requestUrl, req);
184
380
  const responseType = req.responseType === "arraybuffer" ? "arrayBuffer" : req.responseType;
185
381
  return from(serverFetch.raw(fetchUrl, {
186
382
  method: req.method,
187
383
  body: req.body ? req.body : void 0,
188
- params: requestUrl.searchParams,
384
+ params: fetchParams,
189
385
  responseType,
190
386
  headers: req.headers.keys().reduce((hdrs, current) => {
191
- return {
387
+ const value = req.headers.get(current);
388
+ return value != null ? {
192
389
  ...hdrs,
193
- [current]: req.headers.get(current)
194
- };
390
+ [current]: value
391
+ } : hdrs;
195
392
  }, {})
196
393
  }).then((res) => {
197
394
  const cacheResponse = {
@@ -207,8 +404,10 @@ function requestContextInterceptor(req, next) {
207
404
  }));
208
405
  }
209
406
  if (req.url.startsWith("/") || req.url.includes("/_analog/")) {
210
- const requestUrl = req.url.includes("/_analog/") ? req.url : `${window.location.origin}${req.url}`;
211
- const storeKey = makeStateKey(`analog_${makeCacheKey(req, new URL(requestUrl).pathname)}`);
407
+ const toAbsoluteUrl = (url) => new URL(url, window.location.origin);
408
+ const requestUrl = toAbsoluteUrl(req.url).href;
409
+ const { pathname, search } = toAbsoluteUrl(req.urlWithParams);
410
+ const storeKey = makeStateKey(`analog_${makeCacheKey(req, `${pathname}${search}`)}`);
212
411
  const cacheRestoreResponse = transferState.get(storeKey, null);
213
412
  if (cacheRestoreResponse) {
214
413
  transferState.remove(storeKey);
@@ -232,62 +431,83 @@ var FormAction = class FormAction {
232
431
  this.state = output();
233
432
  this.router = inject(Router);
234
433
  this.route = inject(ActivatedRoute);
235
- this.path = this._getPath();
434
+ this.currentState = signal("idle", ...[]);
435
+ /** Cached during construction (injection context) so inject() works. */
436
+ this._endpointUrl = this.route ? injectRouteEndpointURL(this.route.snapshot) : void 0;
236
437
  }
237
438
  submitted($event) {
238
439
  $event.preventDefault();
239
- this.state.emit("submitting");
240
- const body = new FormData($event.target);
241
- if ($event.target.method.toUpperCase() === "GET") this._handleGet(body, this.router.url);
242
- else this._handlePost(body, this.path, $event);
440
+ const form = $event.target;
441
+ this._emitState("submitting");
442
+ const body = new FormData(form);
443
+ if (form.method.toUpperCase() === "GET") this._handleGet(body, this._getGetPath(form));
444
+ else this._handlePost(body, this._getPostPath(form), form.method);
243
445
  }
244
446
  _handleGet(body, path) {
245
- const params = {};
246
- body.forEach((formVal, formKey) => params[formKey] = formVal);
247
- this.state.emit("navigate");
248
- const url = path.split("?")[0];
249
- this.router.navigate([url], {
250
- queryParams: params,
251
- onSameUrlNavigation: "reload"
447
+ const url = new URL(path, window.location.href);
448
+ const params = new URLSearchParams(url.search);
449
+ body.forEach((value, key) => {
450
+ params.append(key, value instanceof File ? value.name : value);
252
451
  });
452
+ url.search = params.toString();
453
+ this._emitState("navigate");
454
+ this._navigateTo(url);
253
455
  }
254
- _handlePost(body, path, $event) {
456
+ _handlePost(body, path, method) {
255
457
  fetch(path, {
256
- method: $event.target.method,
458
+ method,
257
459
  body
258
460
  }).then((res) => {
259
461
  if (res.ok) if (res.redirected) {
260
- const redirectUrl = new URL(res.url).pathname;
261
- this.state.emit("redirect");
262
- this.router.navigate([redirectUrl]);
462
+ this._emitState("redirect");
463
+ this._navigateTo(new URL(res.url, window.location.href));
263
464
  } else if (this._isJSON(res.headers.get("Content-type"))) res.json().then((result) => {
264
465
  this.onSuccess.emit(result);
265
- this.state.emit("success");
466
+ this._emitState("success");
266
467
  });
267
468
  else res.text().then((result) => {
268
469
  this.onSuccess.emit(result);
269
- this.state.emit("success");
470
+ this._emitState("success");
270
471
  });
271
472
  else if (res.headers.get("X-Analog-Errors")) res.json().then((errors) => {
272
473
  this.onError.emit(errors);
273
- this.state.emit("error");
474
+ this._emitState("error");
274
475
  });
275
- else this.state.emit("error");
476
+ else this._emitState("error");
276
477
  }).catch((_) => {
277
- this.state.emit("error");
478
+ this._emitState("error");
278
479
  });
279
480
  }
280
- _getPath() {
281
- if (this.route) return injectRouteEndpointURL(this.route.snapshot).pathname;
481
+ _getExplicitAction(form) {
482
+ return this.action().trim() || form.getAttribute("action")?.trim() || void 0;
483
+ }
484
+ _getGetPath(form) {
485
+ return this._getExplicitAction(form) ?? this.router.url;
486
+ }
487
+ _getPostPath(form) {
488
+ const explicitAction = this._getExplicitAction(form);
489
+ if (explicitAction) return new URL(explicitAction, window.location.href).toString();
490
+ if (this._endpointUrl) return this._endpointUrl.pathname;
282
491
  return `/api/_analog/pages${window.location.pathname}`;
283
492
  }
493
+ _emitState(state) {
494
+ this.currentState.set(state);
495
+ this.state.emit(state);
496
+ }
497
+ _navigateTo(url) {
498
+ if (url.origin === window.location.origin) {
499
+ this.router.navigateByUrl(`${url.pathname}${url.search}${url.hash}`, { onSameUrlNavigation: "reload" });
500
+ return;
501
+ }
502
+ window.location.assign(url.toString());
503
+ }
284
504
  _isJSON(contentType) {
285
505
  return (contentType ? contentType.split(";") : [])[0] === "application/json";
286
506
  }
287
507
  static {
288
508
  this.ɵfac = i0.ɵɵngDeclareFactory({
289
509
  minVersion: "12.0.0",
290
- version: "21.1.1",
510
+ version: "22.1.5",
291
511
  ngImport: i0,
292
512
  type: FormAction,
293
513
  deps: [],
@@ -297,7 +517,7 @@ var FormAction = class FormAction {
297
517
  static {
298
518
  this.ɵdir = i0.ɵɵngDeclareDirective({
299
519
  minVersion: "17.1.0",
300
- version: "21.1.1",
520
+ version: "22.1.5",
301
521
  type: FormAction,
302
522
  isStandalone: true,
303
523
  selector: "form[action],form[method]",
@@ -313,21 +533,31 @@ var FormAction = class FormAction {
313
533
  onError: "onError",
314
534
  state: "state"
315
535
  },
316
- host: { listeners: { "submit": "submitted($event)" } },
536
+ host: {
537
+ listeners: { "submit": "submitted($event)" },
538
+ properties: {
539
+ "attr.data-state": "currentState()",
540
+ "attr.aria-busy": "currentState() === \"submitting\" ? \"true\" : null"
541
+ }
542
+ },
317
543
  ngImport: i0
318
544
  });
319
545
  }
320
546
  };
321
547
  i0.ɵɵngDeclareClassMetadata({
322
548
  minVersion: "12.0.0",
323
- version: "21.1.1",
549
+ version: "22.1.5",
324
550
  ngImport: i0,
325
551
  type: FormAction,
326
552
  decorators: [{
327
553
  type: Directive,
328
554
  args: [{
329
555
  selector: "form[action],form[method]",
330
- host: { "(submit)": `submitted($event)` },
556
+ host: {
557
+ "(submit)": `submitted($event)`,
558
+ "[attr.data-state]": "currentState()",
559
+ "[attr.aria-busy]": "currentState() === \"submitting\" ? \"true\" : null"
560
+ },
331
561
  standalone: true
332
562
  }]
333
563
  }],
@@ -375,141 +605,496 @@ function withDebugRoutes() {
375
605
  };
376
606
  }
377
607
  //#endregion
378
- //#region packages/router/src/lib/server.component.ts
608
+ //#region packages/router/src/lib/validation-errors.ts
609
+ function getPathSegmentKey(segment) {
610
+ return typeof segment === "object" ? segment.key : segment;
611
+ }
612
+ function issuePathToFieldName(path) {
613
+ return path.map((segment) => String(getPathSegmentKey(segment))).join(".");
614
+ }
615
+ function issuesToFieldErrors(issues) {
616
+ return issues.reduce((errors, issue) => {
617
+ if (!issue.path?.length) return errors;
618
+ const fieldName = issuePathToFieldName(issue.path);
619
+ errors[fieldName] ??= [];
620
+ errors[fieldName].push(issue.message);
621
+ return errors;
622
+ }, {});
623
+ }
624
+ function issuesToFormErrors(issues) {
625
+ return issues.filter((issue) => !issue.path?.length).map((issue) => issue.message);
626
+ }
627
+ //#endregion
628
+ //#region packages/router/src/lib/server-fn/dispatcher.ts
629
+ var SERVER_FN_DISPATCHER = new InjectionToken("@analogjs/router Server Function Dispatcher");
630
+ //#endregion
631
+ //#region packages/router/src/lib/server-fn/inject-server-fn.ts
379
632
  /**
380
- * @description
381
- * Component that defines the bridge between the client and server-only
382
- * components. The component passes the component ID and props to the server
383
- * and retrieves the rendered HTML and outputs from the server-only component.
384
- *
385
- * Status: experimental
633
+ * Client transport for server functions. In the browser it goes through Angular
634
+ * `HttpClient`, so client `HttpInterceptorFn`s apply. During SSR the dispatcher
635
+ * token is provided, and the call short-circuits the HTTP round-trip: the
636
+ * handler runs in-process in the current request injector. Lives in the client
637
+ * entry (client-safe).
386
638
  */
387
- var ServerOnly = class ServerOnly {
639
+ var ServerFnClient = class ServerFnClient {
388
640
  constructor() {
389
- this.component = input.required(...[]);
390
- this.props = input(...[]);
391
- this.outputs = output();
392
641
  this.http = inject(HttpClient);
393
- this.sanitizer = inject(DomSanitizer);
394
- this.content = signal("", ...[]);
395
- this.route = inject(ActivatedRoute, { optional: true });
396
- this.baseURL = injectBaseURL();
397
642
  this.transferState = inject(TransferState);
398
- effect(() => {
399
- const routeComponentId = this.route?.snapshot.data["component"];
400
- const props = this.props() || {};
401
- const componentId = routeComponentId || this.component();
402
- const headers = new HttpHeaders(new Headers({
403
- "Content-type": "application/json",
404
- "X-Analog-Component": componentId
405
- }));
406
- const componentUrl = this.getComponentUrl(componentId);
407
- const httpRequest = new HttpRequest("POST", componentUrl, props, { headers });
408
- const storeKey = makeStateKey(makeCacheKey(httpRequest, new URL(componentUrl).pathname));
409
- const componentState = this.transferState.get(storeKey, null);
410
- if (componentState) {
411
- this.updateContent(componentState);
412
- this.transferState.remove(storeKey);
413
- } else this.http.request(httpRequest).pipe(map((response) => {
414
- if (response instanceof HttpResponse) return response.body;
415
- return throwError(() => ({}));
416
- }), catchError((error) => {
417
- console.log(error);
418
- return of({
419
- html: "",
420
- outputs: {}
421
- });
422
- })).subscribe((content) => this.updateContent(content));
643
+ this.injector = inject(Injector);
644
+ this.dispatcher = inject(SERVER_FN_DISPATCHER, { optional: true });
645
+ }
646
+ /** True while rendering on the server (the in-process dispatcher is provided). */
647
+ get isServer() {
648
+ return !!this.dispatcher;
649
+ }
650
+ async call(fn, input) {
651
+ if (this.dispatcher) return this.dispatcher(fn, input, this.injector);
652
+ return firstValueFrom(fn.method === "GET" ? this.http.get(fn.url) : this.http.post(fn.url, input ?? {}));
653
+ }
654
+ /** Key a read's value for TransferState hydration (fn id + input). */
655
+ stateKey(fn, input) {
656
+ return makeStateKey(`__analog_fn_${fn.id}_${stableInput(input)}`);
657
+ }
658
+ readSeed(fn, input) {
659
+ const key = this.stateKey(fn, input);
660
+ if (this.transferState.hasKey(key)) {
661
+ const value = this.transferState.get(key, void 0);
662
+ this.transferState.remove(key);
663
+ return value;
664
+ }
665
+ }
666
+ writeSeed(fn, input, value) {
667
+ this.transferState.set(this.stateKey(fn, input), value);
668
+ }
669
+ static {
670
+ this.ɵfac = i0.ɵɵngDeclareFactory({
671
+ minVersion: "12.0.0",
672
+ version: "22.1.5",
673
+ ngImport: i0,
674
+ type: ServerFnClient,
675
+ deps: [],
676
+ target: i0.ɵɵFactoryTarget.Injectable
677
+ });
678
+ }
679
+ static {
680
+ this.ɵprov = i0.ɵɵngDeclareInjectable({
681
+ minVersion: "12.0.0",
682
+ version: "22.1.5",
683
+ ngImport: i0,
684
+ type: ServerFnClient,
685
+ providedIn: "root"
686
+ });
687
+ }
688
+ };
689
+ i0.ɵɵngDeclareClassMetadata({
690
+ minVersion: "12.0.0",
691
+ version: "22.1.5",
692
+ ngImport: i0,
693
+ type: ServerFnClient,
694
+ decorators: [{
695
+ type: Injectable,
696
+ args: [{ providedIn: "root" }]
697
+ }]
698
+ });
699
+ /** No-op provider hook; ServerFnClient is `providedIn: 'root'`. */
700
+ function provideServerFnClient() {
701
+ return [];
702
+ }
703
+ var NO_INPUT = Symbol("analog.serverFn.noInput");
704
+ function injectServerFn(fn, args) {
705
+ assertInInjectionContext(injectServerFn);
706
+ const client = inject(ServerFnClient);
707
+ return resource({
708
+ params: () => args ? args() : NO_INPUT,
709
+ loader: async ({ params }) => {
710
+ const input = params === NO_INPUT ? void 0 : params;
711
+ const seeded = client.readSeed(fn, input);
712
+ if (seeded !== void 0) return seeded;
713
+ const value = await client.call(fn, input);
714
+ if (client.isServer) client.writeSeed(fn, input, value);
715
+ return value;
716
+ }
717
+ });
718
+ }
719
+ /**
720
+ * Imperative binding of a server function: returns a callable that dispatches
721
+ * the call through `HttpClient` (so client interceptors apply) and resolves the
722
+ * result. Use for mutations and event-driven calls; use `injectServerFn` for
723
+ * reactive reads.
724
+ */
725
+ function injectServerFnMutation(fn) {
726
+ assertInInjectionContext(injectServerFnMutation);
727
+ const client = inject(ServerFnClient);
728
+ return (input) => client.call(fn, input);
729
+ }
730
+ function stableInput(input) {
731
+ if (input === void 0 || input === null) return "_";
732
+ return JSON.stringify(input);
733
+ }
734
+ //#endregion
735
+ //#region packages/router/src/lib/server-fn/server-fn-ref.ts
736
+ /**
737
+ * Builds a server-function reference: the client-safe `{ __serverFn, id, url,
738
+ * method }` metadata that `injectServerFn`/`ServerFnClient` dispatch through.
739
+ *
740
+ * Shared by both sides so they produce identical refs: the server `serverFn`
741
+ * wraps this with registration + the handler, and the client build's scrub
742
+ * transform emits a call to this factory in place of the server module so the
743
+ * browser bundle carries only the ref, never the handler or its server imports.
744
+ *
745
+ * The returned value is callable-typed but throws if invoked directly — it is
746
+ * always dispatched via `injectServerFn`/`ServerFnClient`, never called.
747
+ */
748
+ function createServerFnRef(config) {
749
+ if (!config.id) throw new Error("[analog] serverFn is missing its build-derived id. Server functions require the Analog build transform (@analogjs/platform / @analogjs/vite-plugin-nitro); a raw import without it is not supported.");
750
+ const method = config.method ?? (config.input ? "POST" : "GET");
751
+ const url = `/_analog/fn/${config.id}`;
752
+ const ref = (() => {
753
+ throw new Error(`serverFn "${config.id}" must be called via injectServerFn/ServerFnClient`);
754
+ });
755
+ return Object.assign(ref, {
756
+ __serverFn: true,
757
+ id: config.id,
758
+ url,
759
+ method
760
+ });
761
+ }
762
+ //#endregion
763
+ //#region packages/router/src/lib/to-route.ts
764
+ /**
765
+ * Builds a typed route link object from a route path pattern and options.
766
+ *
767
+ * The returned object separates path, query params, and fragment for
768
+ * direct use with Angular's routerLink directive inputs.
769
+ *
770
+ * @example
771
+ * toRoute('/about')
772
+ * // → { path: ['/', 'about'], queryParams: null, fragment: undefined }
773
+ *
774
+ * toRoute('/users/[id]', { params: { id: '42' } })
775
+ * // → { path: ['/', 'users', '42'], queryParams: null, fragment: undefined }
776
+ *
777
+ * toRoute('/users/[id]', { params: { id: '42' }, query: { tab: 'settings' }, hash: 'bio' })
778
+ * // → { path: ['/', 'users', '42'], queryParams: { tab: 'settings' }, fragment: 'bio' }
779
+ *
780
+ * @example Template usage
781
+ * Compute the link in the component:
782
+ * ```ts
783
+ * readonly link = toRoute('/users/[id]', { params: { id: '42' } });
784
+ * ```
785
+ *
786
+ * ```html
787
+ * <a [routerLink]="link.path" [queryParams]="link.queryParams" [fragment]="link.fragment">
788
+ * ```
789
+ */
790
+ function toRoute(path, ...args) {
791
+ const options = args[0];
792
+ return buildRouteLink(path, options);
793
+ }
794
+ /**
795
+ * Internal: builds a `RouteLinkResult` from path and options.
796
+ * Exported for direct use in tests (avoids generic constraints).
797
+ */
798
+ function buildRouteLink(path, options) {
799
+ return {
800
+ path: buildPath(path, options?.params),
801
+ queryParams: options?.query ?? null,
802
+ fragment: options?.hash
803
+ };
804
+ }
805
+ function buildPath(path, params = {}) {
806
+ return ["/", ...path.split("/").filter(Boolean).flatMap((segment) => {
807
+ const optional = segment.match(/^\[\[\.\.\.([^\]]+)\]\]$/);
808
+ const catchAll = segment.match(/^\[\.\.\.([^\]]+)\]$/);
809
+ const dynamic = segment.match(/^\[([^\]]+)\]$/);
810
+ const match = optional ?? catchAll ?? dynamic;
811
+ if (!match) return [segment];
812
+ const value = params[match[1]];
813
+ if (value == null || Array.isArray(value) && !value.length) {
814
+ if (optional) return [];
815
+ throw new Error(`Missing required ${catchAll ? "catch-all " : ""}param "${match[1]}" for path "${path}"`);
816
+ }
817
+ return Array.isArray(value) ? value.map(String) : [String(value)];
818
+ })];
819
+ }
820
+ /** Internal: resolves `.` and `..` segments in `to` against the `from` route path. */
821
+ function resolveRoutePath(from, to) {
822
+ if (to.startsWith("/")) return to;
823
+ const segments = from.split("/").filter(Boolean);
824
+ for (const part of to.split("/")) if (part === "..") segments.pop();
825
+ else if (part && part !== ".") segments.push(part);
826
+ return "/" + segments.join("/");
827
+ }
828
+ /**
829
+ * Internal: resolves `target` against the `from` route path. Params in the
830
+ * leading segments shared with `from` default to the `current` values.
831
+ */
832
+ function resolveScopedRoute(from, target, current, options) {
833
+ const path = resolveRoutePath(from, target);
834
+ const fromSegments = from.split("/").filter(Boolean);
835
+ const toSegments = path.split("/").filter(Boolean);
836
+ const params = {};
837
+ for (let i = 0; i < toSegments.length && toSegments[i] === fromSegments[i]; i++) {
838
+ const name = paramName(toSegments[i]);
839
+ if (name) params[name] = current[name];
840
+ }
841
+ return {
842
+ path,
843
+ options: {
844
+ ...options,
845
+ params: {
846
+ ...params,
847
+ ...options?.params
848
+ }
849
+ }
850
+ };
851
+ }
852
+ function paramName(segment) {
853
+ return (segment.match(/^\[\[\.\.\.([^\]]+)\]\]$/) ?? segment.match(/^\[\.\.\.([^\]]+)\]$/) ?? segment.match(/^\[([^\]]+)\]$/))?.[1];
854
+ }
855
+ //#endregion
856
+ //#region packages/router/src/lib/inject-typed-params.ts
857
+ function extractCatchAllParams(routePath) {
858
+ const params = [];
859
+ for (const segment of routePath.split("/")) {
860
+ const optional = segment.match(/^\[\[\.\.\.([^\]]+)\]\]$/);
861
+ const required = segment.match(/^\[\.\.\.([^\]]+)\]$/);
862
+ if (optional) params.push({
863
+ name: optional[1],
864
+ type: "optionalCatchAll"
423
865
  });
866
+ else if (required) params.push({
867
+ name: required[1],
868
+ type: "catchAll"
869
+ });
870
+ }
871
+ return params;
872
+ }
873
+ /** Internal: params for `route` and its ancestors, with catch-alls as arrays. */
874
+ function observeRouteParams(route, routePath) {
875
+ const ancestors = route.pathFromRoot ?? [route];
876
+ const catchAllParams = extractCatchAllParams(routePath);
877
+ return combineLatest([combineLatest(ancestors.map((entry) => entry.params)), combineLatest(ancestors.map((entry) => entry.url ?? of([])))]).pipe(map(([values, segments]) => {
878
+ const params = Object.assign({}, ...values);
879
+ for (const param of catchAllParams) {
880
+ const source = ancestors.findIndex((entry, index) => param.type === "catchAll" ? entry.routeConfig?.path === "**" : !!entry.routeConfig?.matcher && values[index][param.name] != null);
881
+ if (source !== -1) params[param.name] = segments[source].map((segment) => segment.path);
882
+ }
883
+ return params;
884
+ }));
885
+ }
886
+ function resolveArgs(fromOrOptions, options) {
887
+ const typed = typeof fromOrOptions === "string";
888
+ const injector = (typed ? options : fromOrOptions)?.injector;
889
+ return {
890
+ from: typed ? fromOrOptions : "",
891
+ injector,
892
+ route: injector ? injector.get(ActivatedRoute) : inject(ActivatedRoute)
893
+ };
894
+ }
895
+ function injectParams(fromOrOptions, options) {
896
+ const { from, injector, route } = resolveArgs(fromOrOptions, options);
897
+ return toSignal(observeRouteParams(route, from), {
898
+ requireSync: true,
899
+ injector
900
+ });
901
+ }
902
+ function injectQuery(fromOrOptions, options) {
903
+ const { injector, route } = resolveArgs(fromOrOptions, options);
904
+ return toSignal(route.queryParams, {
905
+ requireSync: true,
906
+ injector
907
+ });
908
+ }
909
+ function injectRouteData(fromOrOptions, options) {
910
+ const { injector, route } = resolveArgs(fromOrOptions, options);
911
+ return toSignal(route.data, {
912
+ requireSync: true,
913
+ injector
914
+ });
915
+ }
916
+ function injectResources(fromOrOptions, options) {
917
+ const { route } = resolveArgs(fromOrOptions, options);
918
+ return "resources" in route ? route.resources ?? {} : {};
919
+ }
920
+ //#endregion
921
+ //#region packages/router/src/lib/link-to.directive.ts
922
+ var LinkTo = class LinkTo {
923
+ constructor() {
924
+ this.linkTo = input.required(...[]);
925
+ /** The current route's path. Enables relative destinations and param inheritance. */
926
+ this.from = input(...[]);
927
+ this.routerLink = inject(RouterLink);
928
+ this.route = inject(ActivatedRoute);
929
+ this.currentParams = {};
424
930
  }
425
- updateContent(content) {
426
- this.content.set(this.sanitizer.bypassSecurityTrustHtml(content.html));
427
- this.outputs.emit(content.outputs);
931
+ ngOnChanges() {
932
+ const from = this.from();
933
+ if (from !== this.paramsFrom) {
934
+ this.paramsFrom = from;
935
+ this.paramsSubscription?.unsubscribe();
936
+ this.paramsSubscription = from ? observeRouteParams(this.route, from).subscribe((params) => {
937
+ this.currentParams = params;
938
+ this.update();
939
+ }) : void 0;
940
+ }
941
+ this.update();
942
+ }
943
+ ngOnDestroy() {
944
+ this.paramsSubscription?.unsubscribe();
428
945
  }
429
- getComponentUrl(componentId) {
430
- let baseURL = this.baseURL;
431
- if (!baseURL && typeof window !== "undefined") baseURL = window.location.origin;
432
- return `${baseURL}/_analog/components/${componentId}`;
946
+ update() {
947
+ const destination = this.linkTo();
948
+ const from = this.from();
949
+ let link = null;
950
+ if (destination) {
951
+ const { path, ...options } = typeof destination === "string" ? { path: destination } : destination;
952
+ if (from) {
953
+ const scoped = resolveScopedRoute(from, path, this.currentParams, options);
954
+ link = buildRouteLink(scoped.path, scoped.options);
955
+ } else link = buildRouteLink(path, options);
956
+ }
957
+ this.routerLink.routerLink = link?.path ?? null;
958
+ this.routerLink.queryParams = link?.queryParams ?? null;
959
+ this.routerLink.fragment = link?.fragment;
960
+ this.routerLink.ngOnChanges({});
433
961
  }
434
962
  static {
435
963
  this.ɵfac = i0.ɵɵngDeclareFactory({
436
964
  minVersion: "12.0.0",
437
- version: "21.1.1",
965
+ version: "22.1.5",
438
966
  ngImport: i0,
439
- type: ServerOnly,
967
+ type: LinkTo,
440
968
  deps: [],
441
- target: i0.ɵɵFactoryTarget.Component
969
+ target: i0.ɵɵFactoryTarget.Directive
442
970
  });
443
971
  }
444
972
  static {
445
- this.ɵcmp = i0.ɵɵngDeclareComponent({
973
+ this.ɵdir = i0.ɵɵngDeclareDirective({
446
974
  minVersion: "17.1.0",
447
- version: "21.1.1",
448
- type: ServerOnly,
975
+ version: "22.1.5",
976
+ type: LinkTo,
449
977
  isStandalone: true,
450
- selector: "server-only,ServerOnly,Server",
978
+ selector: "[linkTo]",
451
979
  inputs: {
452
- component: {
453
- classPropertyName: "component",
454
- publicName: "component",
980
+ linkTo: {
981
+ classPropertyName: "linkTo",
982
+ publicName: "linkTo",
455
983
  isSignal: true,
456
984
  isRequired: true,
457
985
  transformFunction: null
458
986
  },
459
- props: {
460
- classPropertyName: "props",
461
- publicName: "props",
987
+ from: {
988
+ classPropertyName: "from",
989
+ publicName: "from",
462
990
  isSignal: true,
463
991
  isRequired: false,
464
992
  transformFunction: null
465
993
  }
466
994
  },
467
- outputs: { outputs: "outputs" },
468
- ngImport: i0,
469
- template: ` <div [innerHTML]="content()"></div> `,
470
- isInline: true,
471
- changeDetection: i0.ChangeDetectionStrategy.OnPush
995
+ usesOnChanges: true,
996
+ hostDirectives: [{
997
+ directive: i1.RouterLink,
998
+ inputs: [
999
+ "target",
1000
+ "target",
1001
+ "queryParamsHandling",
1002
+ "queryParamsHandling",
1003
+ "preserveFragment",
1004
+ "preserveFragment",
1005
+ "skipLocationChange",
1006
+ "skipLocationChange",
1007
+ "replaceUrl",
1008
+ "replaceUrl",
1009
+ "state",
1010
+ "state"
1011
+ ]
1012
+ }],
1013
+ ngImport: i0
472
1014
  });
473
1015
  }
474
1016
  };
475
1017
  i0.ɵɵngDeclareClassMetadata({
476
1018
  minVersion: "12.0.0",
477
- version: "21.1.1",
1019
+ version: "22.1.5",
478
1020
  ngImport: i0,
479
- type: ServerOnly,
1021
+ type: LinkTo,
480
1022
  decorators: [{
481
- type: Component,
1023
+ type: Directive,
482
1024
  args: [{
483
- selector: "server-only,ServerOnly,Server",
484
- changeDetection: ChangeDetectionStrategy.OnPush,
485
- template: ` <div [innerHTML]="content()"></div> `
1025
+ selector: "[linkTo]",
1026
+ standalone: true,
1027
+ hostDirectives: [{
1028
+ directive: RouterLink,
1029
+ inputs: [
1030
+ "target",
1031
+ "queryParamsHandling",
1032
+ "preserveFragment",
1033
+ "skipLocationChange",
1034
+ "replaceUrl",
1035
+ "state"
1036
+ ]
1037
+ }]
486
1038
  }]
487
1039
  }],
488
- ctorParameters: () => [],
489
1040
  propDecorators: {
490
- component: [{
1041
+ linkTo: [{
491
1042
  type: i0.Input,
492
1043
  args: [{
493
1044
  isSignal: true,
494
- alias: "component",
1045
+ alias: "linkTo",
495
1046
  required: true
496
1047
  }]
497
1048
  }],
498
- props: [{
1049
+ from: [{
499
1050
  type: i0.Input,
500
1051
  args: [{
501
1052
  isSignal: true,
502
- alias: "props",
1053
+ alias: "from",
503
1054
  required: false
504
1055
  }]
505
- }],
506
- outputs: [{
507
- type: i0.Output,
508
- args: ["outputs"]
509
1056
  }]
510
1057
  }
511
1058
  });
512
1059
  //#endregion
513
- export { FormAction, ServerOnly, createRoutes, defineRouteMeta, getLoadResolver, injectActivatedRoute, injectDebugRoutes, injectLoad, injectRouteEndpointURL, injectRouter, provideFileRouter, requestContextInterceptor, routes, withDebugRoutes, withExtraRoutes };
1060
+ //#region packages/router/src/lib/inject-navigate.ts
1061
+ function isRoutePathOptionsBase(value) {
1062
+ return !!value && typeof value === "object" && ("params" in value || "query" in value || "hash" in value);
1063
+ }
1064
+ function update(value, current) {
1065
+ return typeof value === "function" ? value(current) : value;
1066
+ }
1067
+ function injectNavigate(from, options) {
1068
+ const injector = options?.injector ?? inject(Injector);
1069
+ const router = injector.get(Router);
1070
+ const currentParams = from ? injectParams(from, { injector }) : void 0;
1071
+ const currentQuery = from ? injectQuery(from, { injector }) : void 0;
1072
+ return (target, ...args) => {
1073
+ let options;
1074
+ let extras;
1075
+ if (args.length > 1) {
1076
+ options = args[0];
1077
+ extras = args[1];
1078
+ } else if (args.length === 1) if (isRoutePathOptionsBase(args[0])) options = args[0];
1079
+ else extras = args[0];
1080
+ let path = target;
1081
+ if (from && currentParams && currentQuery) {
1082
+ const params = currentParams();
1083
+ ({path, options} = resolveScopedRoute(from, target, params, {
1084
+ ...options,
1085
+ params: update(options?.params, params),
1086
+ query: update(options?.query, currentQuery())
1087
+ }));
1088
+ }
1089
+ const link = buildRouteLink(path, options);
1090
+ return router.navigate(link.path, {
1091
+ ...extras,
1092
+ queryParams: link.queryParams,
1093
+ fragment: link.fragment
1094
+ });
1095
+ };
1096
+ }
1097
+ //#endregion
1098
+ export { FormAction, LinkTo, SERVER_FN_DISPATCHER, ServerFnClient, createRoutes, createServerFnRef, defineRouteMeta, getLoadResolver, injectActivatedRoute, injectDebugRoutes, injectLoad, injectLoadData, injectNavigate, injectParams, injectQuery, injectResources, injectResources as injectRouteResources, injectRouteData, injectRouteEndpointURL, injectRouter, injectServerFn, injectServerFnMutation, issuePathToFieldName, issuesToFieldErrors, issuesToFormErrors, provideFileRouter, provideServerFnClient, requestContextInterceptor, routes, toRoute, withDebugRoutes, withExtraRoutes };
514
1099
 
515
1100
  //# sourceMappingURL=analogjs-router.mjs.map