@analogjs/router 2.8.0-beta.9 → 2.8.0
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-debug.page-MFY2u07E.mjs +119 -0
- package/fesm2022/analogjs-router-debug.page-MFY2u07E.mjs.map +1 -0
- package/fesm2022/analogjs-router-i18n.mjs +82 -219
- package/fesm2022/analogjs-router-i18n.mjs.map +1 -1
- package/fesm2022/analogjs-router-routes-L2tt-0ms.mjs +263 -0
- package/fesm2022/analogjs-router-routes-L2tt-0ms.mjs.map +1 -0
- package/fesm2022/analogjs-router-server-actions.mjs +228 -463
- package/fesm2022/analogjs-router-server-actions.mjs.map +1 -1
- package/fesm2022/analogjs-router-server.mjs +608 -838
- package/fesm2022/analogjs-router-server.mjs.map +1 -1
- package/fesm2022/analogjs-router-tanstack-query-server.mjs +35 -85
- package/fesm2022/analogjs-router-tanstack-query-server.mjs.map +1 -1
- package/fesm2022/analogjs-router-tanstack-query.mjs +79 -127
- package/fesm2022/analogjs-router-tanstack-query.mjs.map +1 -1
- package/fesm2022/analogjs-router-tokens.mjs +14 -19
- package/fesm2022/analogjs-router-tokens.mjs.map +1 -1
- package/fesm2022/analogjs-router.mjs +882 -1324
- package/fesm2022/analogjs-router.mjs.map +1 -1
- package/package.json +2 -2
- package/types/analogjs-router-i18n.d.ts +55 -24
- package/types/analogjs-router-server-actions.d.ts +98 -107
- package/types/analogjs-router-server.d.ts +76 -116
- package/types/analogjs-router-tanstack-query-server.d.ts +33 -37
- package/types/analogjs-router-tanstack-query.d.ts +19 -24
- package/types/analogjs-router-tokens.d.ts +26 -22
- package/types/analogjs-router.d.ts +528 -348
- package/fesm2022/analogjs-router-debug.page-COcFkgRu.mjs +0 -91
- package/fesm2022/analogjs-router-debug.page-COcFkgRu.mjs.map +0 -1
|
@@ -1,1377 +1,935 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { toSignal } from '@angular/core/rxjs-interop';
|
|
12
|
-
|
|
13
|
-
const ROUTE_META_TAGS_KEY = Symbol('@analogjs/router Route Meta Tags Key');
|
|
14
|
-
const CHARSET_KEY = 'charset';
|
|
15
|
-
const HTTP_EQUIV_KEY = 'httpEquiv';
|
|
16
|
-
// httpEquiv selector key needs to be in kebab case format
|
|
17
|
-
const HTTP_EQUIV_SELECTOR_KEY = 'http-equiv';
|
|
18
|
-
const NAME_KEY = 'name';
|
|
19
|
-
const PROPERTY_KEY = 'property';
|
|
20
|
-
const CONTENT_KEY = 'content';
|
|
21
|
-
const ITEMPROP_KEY = 'itemprop';
|
|
22
|
-
function updateMetaTagsOnRouteChange() {
|
|
23
|
-
const router = inject(Router);
|
|
24
|
-
const metaService = inject(Meta);
|
|
25
|
-
router.events
|
|
26
|
-
.pipe(filter((event) => event instanceof NavigationEnd))
|
|
27
|
-
.subscribe(() => {
|
|
28
|
-
const metaTagMap = getMetaTagMap(router.routerState.snapshot.root);
|
|
29
|
-
for (const metaTagSelector in metaTagMap) {
|
|
30
|
-
const metaTag = metaTagMap[metaTagSelector];
|
|
31
|
-
metaService.updateTag(metaTag, metaTagSelector);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
function getMetaTagMap(route) {
|
|
36
|
-
const metaTagMap = {};
|
|
37
|
-
let currentRoute = route;
|
|
38
|
-
while (currentRoute) {
|
|
39
|
-
const metaTags = currentRoute.data[ROUTE_META_TAGS_KEY] ?? [];
|
|
40
|
-
for (const metaTag of metaTags) {
|
|
41
|
-
metaTagMap[getMetaTagSelector(metaTag)] = metaTag;
|
|
42
|
-
}
|
|
43
|
-
currentRoute = currentRoute.firstChild;
|
|
44
|
-
}
|
|
45
|
-
return metaTagMap;
|
|
46
|
-
}
|
|
47
|
-
function getMetaTagSelector(metaTag) {
|
|
48
|
-
if (metaTag.name) {
|
|
49
|
-
return `${NAME_KEY}="${metaTag.name}"`;
|
|
50
|
-
}
|
|
51
|
-
if (metaTag.property) {
|
|
52
|
-
return `${PROPERTY_KEY}="${metaTag.property}"`;
|
|
53
|
-
}
|
|
54
|
-
if (metaTag.httpEquiv) {
|
|
55
|
-
return `${HTTP_EQUIV_SELECTOR_KEY}="${metaTag.httpEquiv}"`;
|
|
56
|
-
}
|
|
57
|
-
if (metaTag.itemprop) {
|
|
58
|
-
return `${ITEMPROP_KEY}="${metaTag.itemprop}"`;
|
|
59
|
-
}
|
|
60
|
-
return CHARSET_KEY;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const ANALOG_META_KEY = Symbol('@analogjs/router Analog Route Metadata Key');
|
|
64
|
-
/**
|
|
65
|
-
* This variable reference is replaced with a glob of all route endpoints.
|
|
66
|
-
*/
|
|
67
|
-
let ANALOG_PAGE_ENDPOINTS = {};
|
|
68
|
-
|
|
69
|
-
function injectRouteEndpointURL(route) {
|
|
70
|
-
const routeConfig = route.routeConfig;
|
|
71
|
-
const apiPrefix = injectAPIPrefix();
|
|
72
|
-
const baseUrl = injectBaseURL();
|
|
73
|
-
const { queryParams, fragment: hash, params, parent } = route;
|
|
74
|
-
const segment = parent?.url.map((segment) => segment.path).join('/') || '';
|
|
75
|
-
const url = new URL('', import.meta.env['VITE_ANALOG_PUBLIC_BASE_URL'] ||
|
|
76
|
-
baseUrl ||
|
|
77
|
-
(typeof window !== 'undefined' && window.location.origin
|
|
78
|
-
? window.location.origin
|
|
79
|
-
: ''));
|
|
80
|
-
url.pathname = `${url.pathname.endsWith('/') ? url.pathname : url.pathname + '/'}${apiPrefix}/_analog${routeConfig[ANALOG_META_KEY].endpoint}`;
|
|
81
|
-
url.search = `${new URLSearchParams(queryParams).toString()}`;
|
|
82
|
-
url.hash = hash ?? '';
|
|
83
|
-
Object.keys(params).forEach((param) => {
|
|
84
|
-
url.pathname = url.pathname.replace(`[${param}]`, params[param]);
|
|
85
|
-
});
|
|
86
|
-
url.pathname = url.pathname.replace('**', segment);
|
|
87
|
-
return url;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function toRouteConfig(routeMeta) {
|
|
91
|
-
if (routeMeta && isRedirectRouteMeta(routeMeta)) {
|
|
92
|
-
return routeMeta;
|
|
93
|
-
}
|
|
94
|
-
let { meta, ...routeConfig } = routeMeta ?? {};
|
|
95
|
-
if (Array.isArray(meta)) {
|
|
96
|
-
routeConfig.data = { ...routeConfig.data, [ROUTE_META_TAGS_KEY]: meta };
|
|
97
|
-
}
|
|
98
|
-
else if (typeof meta === 'function') {
|
|
99
|
-
routeConfig.resolve = {
|
|
100
|
-
...routeConfig.resolve,
|
|
101
|
-
[ROUTE_META_TAGS_KEY]: meta,
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
if (!routeConfig) {
|
|
105
|
-
routeConfig = {};
|
|
106
|
-
}
|
|
107
|
-
routeConfig.runGuardsAndResolvers =
|
|
108
|
-
routeConfig.runGuardsAndResolvers ?? 'paramsOrQueryParamsChange';
|
|
109
|
-
routeConfig.resolve = {
|
|
110
|
-
...routeConfig.resolve,
|
|
111
|
-
load: async (route) => {
|
|
112
|
-
const routeConfig = route.routeConfig;
|
|
113
|
-
if (ANALOG_PAGE_ENDPOINTS[routeConfig[ANALOG_META_KEY].endpointKey]) {
|
|
114
|
-
const http = inject(HttpClient);
|
|
115
|
-
const url = injectRouteEndpointURL(route);
|
|
116
|
-
if (!!import.meta.env['VITE_ANALOG_PUBLIC_BASE_URL'] &&
|
|
117
|
-
globalThis.$fetch) {
|
|
118
|
-
return globalThis.$fetch(`${url.pathname}${url.search}`);
|
|
119
|
-
}
|
|
120
|
-
return firstValueFrom(http.get(`${url.href}`));
|
|
121
|
-
}
|
|
122
|
-
return {};
|
|
123
|
-
},
|
|
124
|
-
};
|
|
125
|
-
return routeConfig;
|
|
126
|
-
}
|
|
127
|
-
function isRedirectRouteMeta(routeMeta) {
|
|
128
|
-
return !!routeMeta.redirectTo;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// The Zone is currently enabled by default, so we wouldn't need this check.
|
|
132
|
-
// However, leaving this open space will be useful if zone.js becomes optional
|
|
133
|
-
// in the future. This means we won't have to modify the current code, and it will
|
|
134
|
-
// continue to work seamlessly.
|
|
135
|
-
const isNgZoneEnabled = typeof Zone !== 'undefined' && !!Zone.root;
|
|
136
|
-
function toMarkdownModule(markdownFileFactory) {
|
|
137
|
-
return async () => {
|
|
138
|
-
const createLoader = () => Promise.all([import('@analogjs/content'), markdownFileFactory()]);
|
|
139
|
-
const [{ parseRawContentFile, MarkdownRouteComponent, ContentRenderer }, markdownFile,] = await (isNgZoneEnabled
|
|
140
|
-
? // We are not able to use `runOutsideAngular` because we are not inside
|
|
141
|
-
// an injection context to retrieve the `NgZone` instance.
|
|
142
|
-
// The `Zone.root.run` is required when the code is running in the
|
|
143
|
-
// browser since asynchronous tasks being scheduled in the current context
|
|
144
|
-
// are a reason for unnecessary change detection cycles.
|
|
145
|
-
Zone.root.run(createLoader)
|
|
146
|
-
: createLoader());
|
|
147
|
-
const { content, attributes } = parseRawContentFile(markdownFile);
|
|
148
|
-
const { title, meta } = attributes;
|
|
149
|
-
return {
|
|
150
|
-
default: MarkdownRouteComponent,
|
|
151
|
-
routeMeta: {
|
|
152
|
-
data: { _analogContent: content },
|
|
153
|
-
title,
|
|
154
|
-
meta,
|
|
155
|
-
resolve: {
|
|
156
|
-
renderedAnalogContent: async () => {
|
|
157
|
-
const contentRenderer = inject(ContentRenderer);
|
|
158
|
-
const rendered = await contentRenderer.render(content);
|
|
159
|
-
return typeof rendered === 'string'
|
|
160
|
-
? rendered
|
|
161
|
-
: rendered.content;
|
|
162
|
-
},
|
|
163
|
-
},
|
|
164
|
-
},
|
|
165
|
-
};
|
|
166
|
-
};
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
const ENDPOINT_EXTENSION = '.server.ts';
|
|
170
|
-
const APP_DIR = 'src/app';
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* This variable reference is replaced with a glob of all page routes.
|
|
174
|
-
*/
|
|
175
|
-
let ANALOG_ROUTE_FILES = {};
|
|
176
|
-
/**
|
|
177
|
-
* This variable reference is replaced with a glob of all content routes.
|
|
178
|
-
*/
|
|
179
|
-
let ANALOG_CONTENT_ROUTE_FILES = {};
|
|
180
|
-
/**
|
|
181
|
-
* A function used to parse list of files and create configuration of routes.
|
|
182
|
-
*
|
|
183
|
-
* @param files
|
|
184
|
-
* @returns Array of routes
|
|
185
|
-
*/
|
|
186
|
-
function createRoutes(files, debug = false) {
|
|
187
|
-
const filenames = Object.keys(files);
|
|
188
|
-
if (filenames.length === 0) {
|
|
189
|
-
return [];
|
|
190
|
-
}
|
|
191
|
-
// map filenames to raw routes and group them by level
|
|
192
|
-
const rawRoutesByLevelMap = filenames.reduce((acc, filename) => {
|
|
193
|
-
const rawPath = toRawPath(filename);
|
|
194
|
-
const rawSegments = rawPath.split('/');
|
|
195
|
-
// nesting level starts at 0
|
|
196
|
-
// rawPath: /products => level: 0
|
|
197
|
-
// rawPath: /products/:id => level: 1
|
|
198
|
-
const level = rawSegments.length - 1;
|
|
199
|
-
const rawSegment = rawSegments[level];
|
|
200
|
-
const ancestorRawSegments = rawSegments.slice(0, level);
|
|
201
|
-
return {
|
|
202
|
-
...acc,
|
|
203
|
-
[level]: {
|
|
204
|
-
...acc[level],
|
|
205
|
-
[rawPath]: {
|
|
206
|
-
filename,
|
|
207
|
-
rawSegment,
|
|
208
|
-
ancestorRawSegments,
|
|
209
|
-
segment: toSegment(rawSegment),
|
|
210
|
-
level,
|
|
211
|
-
children: [],
|
|
212
|
-
},
|
|
213
|
-
},
|
|
214
|
-
};
|
|
215
|
-
}, {});
|
|
216
|
-
const allLevels = Object.keys(rawRoutesByLevelMap).map(Number);
|
|
217
|
-
const maxLevel = Math.max(...allLevels);
|
|
218
|
-
// add each raw route to its parent's children array
|
|
219
|
-
for (let level = maxLevel; level > 0; level--) {
|
|
220
|
-
const rawRoutesMap = rawRoutesByLevelMap[level];
|
|
221
|
-
const rawPaths = Object.keys(rawRoutesMap);
|
|
222
|
-
for (const rawPath of rawPaths) {
|
|
223
|
-
const rawRoute = rawRoutesMap[rawPath];
|
|
224
|
-
const parentRawPath = rawRoute.ancestorRawSegments.join('/');
|
|
225
|
-
const parentRawSegmentIndex = rawRoute.ancestorRawSegments.length - 1;
|
|
226
|
-
const parentRawSegment = rawRoute.ancestorRawSegments[parentRawSegmentIndex];
|
|
227
|
-
// create the parent level and/or raw route if it does not exist
|
|
228
|
-
// parent route won't exist for nested routes that don't have a layout route
|
|
229
|
-
rawRoutesByLevelMap[level - 1] ||= {};
|
|
230
|
-
rawRoutesByLevelMap[level - 1][parentRawPath] ||= {
|
|
231
|
-
filename: null,
|
|
232
|
-
rawSegment: parentRawSegment,
|
|
233
|
-
ancestorRawSegments: rawRoute.ancestorRawSegments.slice(0, parentRawSegmentIndex),
|
|
234
|
-
segment: toSegment(parentRawSegment),
|
|
235
|
-
level: level - 1,
|
|
236
|
-
children: [],
|
|
237
|
-
};
|
|
238
|
-
rawRoutesByLevelMap[level - 1][parentRawPath].children.push(rawRoute);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
// only take raw routes from the root level
|
|
242
|
-
// since they already contain nested routes as their children
|
|
243
|
-
const rootRawRoutesMap = rawRoutesByLevelMap[0];
|
|
244
|
-
const rawRoutes = Object.keys(rootRawRoutesMap).map((segment) => rootRawRoutesMap[segment]);
|
|
245
|
-
sortRawRoutes(rawRoutes);
|
|
246
|
-
return toRoutes(rawRoutes, files, debug);
|
|
247
|
-
}
|
|
248
|
-
function toRawPath(filename) {
|
|
249
|
-
return (filename
|
|
250
|
-
.replace(
|
|
251
|
-
// convert to relative path and remove file extension
|
|
252
|
-
/^(?:[a-zA-Z]:[\\/])?(.*?)[\\/](?:routes|pages)[\\/]|(?:[\\/](?:app[\\/](?:routes|pages)|src[\\/]content)[\\/])|(\.page\.(js|ts|analog|ag)$)|(\.(ts|md|analog|ag)$)/g, '')
|
|
253
|
-
// [[...slug]] => placeholder (named empty) which is stripped by toSegment
|
|
254
|
-
.replace(/\[\[\.\.\.([^\]]+)\]\]/g, '(opt-$1)')
|
|
255
|
-
.replace(/\[\.{3}.+\]/, '**') // [...not-found] => **
|
|
256
|
-
.replace(/\[([^\]]+)\]/g, ':$1')); // [id] => :id
|
|
257
|
-
}
|
|
258
|
-
function toSegment(rawSegment) {
|
|
259
|
-
return rawSegment
|
|
260
|
-
.replace(/index|\(.*?\)/g, '') // replace named empty segments
|
|
261
|
-
.replace(/\.|\/+/g, '/') // replace dots with slashes and remove redundant slashes
|
|
262
|
-
.replace(/^\/+|\/+$/g, ''); // remove trailing slashes
|
|
263
|
-
}
|
|
264
|
-
function createOptionalCatchAllMatcher(paramName) {
|
|
265
|
-
return (segments) => {
|
|
266
|
-
if (segments.length === 0) {
|
|
267
|
-
return null;
|
|
268
|
-
}
|
|
269
|
-
const joined = segments.map((s) => s.path).join('/');
|
|
270
|
-
return {
|
|
271
|
-
consumed: segments,
|
|
272
|
-
posParams: { [paramName]: new UrlSegment(joined, {}) },
|
|
273
|
-
};
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
function toRoutes(rawRoutes, files, debug = false) {
|
|
277
|
-
const routes = [];
|
|
278
|
-
for (const rawRoute of rawRoutes) {
|
|
279
|
-
const children = rawRoute.children.length > 0
|
|
280
|
-
? toRoutes(rawRoute.children, files, debug)
|
|
281
|
-
: undefined;
|
|
282
|
-
let module = undefined;
|
|
283
|
-
let analogMeta = undefined;
|
|
284
|
-
if (rawRoute.filename) {
|
|
285
|
-
const isMarkdownFile = rawRoute.filename.endsWith('.md');
|
|
286
|
-
if (!debug) {
|
|
287
|
-
module = isMarkdownFile
|
|
288
|
-
? toMarkdownModule(files[rawRoute.filename])
|
|
289
|
-
: files[rawRoute.filename];
|
|
290
|
-
}
|
|
291
|
-
const endpointKey = rawRoute.filename.replace(/\.page\.(ts|analog|ag)$/, ENDPOINT_EXTENSION);
|
|
292
|
-
// get endpoint path
|
|
293
|
-
const rawEndpoint = rawRoute.filename
|
|
294
|
-
.replace(/\.page\.(ts|analog|ag)$/, '')
|
|
295
|
-
.replace(/\[\[\.\.\..+\]\]/, '**')
|
|
296
|
-
.replace(/\[\.{3}.+\]/, '**') // [...not-found] => **
|
|
297
|
-
.replace(/^(.*?)\/pages/, '/pages');
|
|
298
|
-
// replace periods, remove (index) paths
|
|
299
|
-
const endpoint = (rawEndpoint || '')
|
|
300
|
-
.replace(/\./g, '/')
|
|
301
|
-
.replace(/\/\((.*?)\)$/, '/-$1-');
|
|
302
|
-
analogMeta = {
|
|
303
|
-
endpoint,
|
|
304
|
-
endpointKey,
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
// Detect Next.js-style optional catch-all at this node: [[...param]]
|
|
308
|
-
const optCatchAllMatch = rawRoute.filename?.match(/\[\[\.\.\.([^\]]+)\]\]/);
|
|
309
|
-
const optCatchAllParam = optCatchAllMatch ? optCatchAllMatch[1] : null;
|
|
310
|
-
const route = module
|
|
311
|
-
? {
|
|
312
|
-
path: rawRoute.segment,
|
|
313
|
-
loadChildren: () => module().then((m) => {
|
|
314
|
-
if (import.meta.env.DEV) {
|
|
315
|
-
const hasModuleDefault = !!m.default;
|
|
316
|
-
const hasRedirect = !!m.routeMeta?.redirectTo;
|
|
317
|
-
if (!hasModuleDefault && !hasRedirect) {
|
|
318
|
-
console.warn(`[Analog] Missing default export at ${rawRoute.filename}`);
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
const baseChild = {
|
|
322
|
-
path: '',
|
|
323
|
-
component: m.default,
|
|
324
|
-
...toRouteConfig(m.routeMeta),
|
|
325
|
-
children,
|
|
326
|
-
[ANALOG_META_KEY]: analogMeta,
|
|
327
|
-
};
|
|
328
|
-
// Base route first so static matches win, then optional catch-all matcher
|
|
329
|
-
return [
|
|
330
|
-
{
|
|
331
|
-
...baseChild,
|
|
332
|
-
},
|
|
333
|
-
...(optCatchAllParam
|
|
334
|
-
? [
|
|
335
|
-
{
|
|
336
|
-
matcher: createOptionalCatchAllMatcher(optCatchAllParam),
|
|
337
|
-
component: m.default,
|
|
338
|
-
...toRouteConfig(m.routeMeta),
|
|
339
|
-
[ANALOG_META_KEY]: analogMeta,
|
|
340
|
-
},
|
|
341
|
-
]
|
|
342
|
-
: []),
|
|
343
|
-
];
|
|
344
|
-
}),
|
|
345
|
-
}
|
|
346
|
-
: {
|
|
347
|
-
path: rawRoute.segment,
|
|
348
|
-
...(debug
|
|
349
|
-
? {
|
|
350
|
-
filename: rawRoute.filename ? rawRoute.filename : undefined,
|
|
351
|
-
isLayout: children && children.length > 0 ? true : false,
|
|
352
|
-
}
|
|
353
|
-
: {}),
|
|
354
|
-
children,
|
|
355
|
-
};
|
|
356
|
-
routes.push(route);
|
|
357
|
-
}
|
|
358
|
-
return routes;
|
|
359
|
-
}
|
|
360
|
-
function sortRawRoutes(rawRoutes) {
|
|
361
|
-
rawRoutes.sort((a, b) => {
|
|
362
|
-
let segmentA = deprioritizeSegment(a.segment);
|
|
363
|
-
let segmentB = deprioritizeSegment(b.segment);
|
|
364
|
-
// prioritize routes with fewer children
|
|
365
|
-
if (a.children.length > b.children.length) {
|
|
366
|
-
segmentA = `~${segmentA}`;
|
|
367
|
-
}
|
|
368
|
-
else if (a.children.length < b.children.length) {
|
|
369
|
-
segmentB = `~${segmentB}`;
|
|
370
|
-
}
|
|
371
|
-
return segmentA > segmentB ? 1 : -1;
|
|
372
|
-
});
|
|
373
|
-
for (const rawRoute of rawRoutes) {
|
|
374
|
-
sortRawRoutes(rawRoute.children);
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
function deprioritizeSegment(segment) {
|
|
378
|
-
// deprioritize param and wildcard segments
|
|
379
|
-
return segment.replace(':', '~~').replace('**', '~~~~');
|
|
380
|
-
}
|
|
381
|
-
const routes = createRoutes({
|
|
382
|
-
...ANALOG_ROUTE_FILES,
|
|
383
|
-
...ANALOG_CONTENT_ROUTE_FILES,
|
|
384
|
-
});
|
|
385
|
-
|
|
386
|
-
/**
|
|
387
|
-
* @deprecated Use `RouteMeta` type instead.
|
|
388
|
-
* For more info see: https://github.com/analogjs/analog/issues/223
|
|
389
|
-
*
|
|
390
|
-
* Defines additional route config metadata. This
|
|
391
|
-
* object is merged into the route config with
|
|
392
|
-
* the predefined file-based route.
|
|
393
|
-
*
|
|
394
|
-
* @usageNotes
|
|
395
|
-
*
|
|
396
|
-
* ```
|
|
397
|
-
* import { Component } from '@angular/core';
|
|
398
|
-
* import { defineRouteMeta } from '@analogjs/router';
|
|
399
|
-
*
|
|
400
|
-
* export const routeMeta = defineRouteMeta({
|
|
401
|
-
* title: 'Welcome'
|
|
402
|
-
* });
|
|
403
|
-
*
|
|
404
|
-
* @Component({
|
|
405
|
-
* template: `Home`,
|
|
406
|
-
* standalone: true,
|
|
407
|
-
* })
|
|
408
|
-
* export default class HomeComponent {}
|
|
409
|
-
* ```
|
|
410
|
-
*
|
|
411
|
-
* @param route
|
|
412
|
-
* @returns
|
|
413
|
-
*/
|
|
1
|
+
import { a as ANALOG_META_KEY, i as injectRouteEndpointURL, n as createRoutes, o as updateMetaTagsOnRouteChange, r as routes, t as injectDebugRoutes } from "./analogjs-router-routes-L2tt-0ms.mjs";
|
|
2
|
+
import * as i1 from "@angular/router";
|
|
3
|
+
import { ActivatedRoute, ROUTES, Router, RouterLink, provideRouter } from "@angular/router";
|
|
4
|
+
import * as i0 from "@angular/core";
|
|
5
|
+
import { Directive, ENVIRONMENT_INITIALIZER, ElementRef, Injectable, InjectionToken, Injector, PLATFORM_ID, Renderer2, TransferState, assertInInjectionContext, booleanAttribute, effect, inject, input, makeEnvironmentProviders, makeStateKey, output, resource, runInInjectionContext, signal } from "@angular/core";
|
|
6
|
+
import { HttpClient, HttpHeaders, HttpResponse, ɵHTTP_ROOT_INTERCEPTOR_FNS } from "@angular/common/http";
|
|
7
|
+
import { combineLatest, firstValueFrom, from, map, of } from "rxjs";
|
|
8
|
+
import { API_PREFIX, injectAPIPrefix, injectBaseURL, injectRequest } from "@analogjs/router/tokens";
|
|
9
|
+
import { isPlatformServer } from "@angular/common";
|
|
10
|
+
import { toSignal } from "@angular/core/rxjs-interop";
|
|
414
11
|
const defineRouteMeta = (route) => {
|
|
415
|
-
|
|
12
|
+
return route;
|
|
416
13
|
};
|
|
417
|
-
/**
|
|
418
|
-
* Returns the instance of Angular Router
|
|
419
|
-
*
|
|
420
|
-
* @returns The router
|
|
421
|
-
*/
|
|
422
14
|
const injectRouter = () => {
|
|
423
|
-
|
|
15
|
+
return inject(Router);
|
|
424
16
|
};
|
|
425
|
-
/**
|
|
426
|
-
* Returns the instance of the Activate Route for the component
|
|
427
|
-
*
|
|
428
|
-
* @returns The activated route
|
|
429
|
-
*/
|
|
430
17
|
const injectActivatedRoute = () => {
|
|
431
|
-
|
|
18
|
+
return inject(ActivatedRoute);
|
|
432
19
|
};
|
|
433
|
-
|
|
434
20
|
function cookieInterceptor(req, next, location = inject(PLATFORM_ID), serverRequest = injectRequest()) {
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
});
|
|
442
|
-
return next(cookiedRequest);
|
|
443
|
-
}
|
|
444
|
-
else {
|
|
445
|
-
return next(req);
|
|
446
|
-
}
|
|
21
|
+
if (isPlatformServer(location) && req.url.includes("/_analog/")) {
|
|
22
|
+
let headers = new HttpHeaders();
|
|
23
|
+
const cookies = serverRequest?.headers.cookie;
|
|
24
|
+
headers = headers.set("cookie", cookies ?? "");
|
|
25
|
+
return next(req.clone({ headers }));
|
|
26
|
+
} else return next(req);
|
|
447
27
|
}
|
|
448
|
-
|
|
449
|
-
/**
|
|
450
|
-
* Sets up providers for the Angular router, and registers
|
|
451
|
-
* file-based routes. Additional features can be provided
|
|
452
|
-
* to further configure the behavior of the router.
|
|
453
|
-
*
|
|
454
|
-
* @param features
|
|
455
|
-
* @returns Providers and features to configure the router with routes
|
|
456
|
-
*/
|
|
457
28
|
function provideFileRouter(...features) {
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
},
|
|
481
|
-
]);
|
|
29
|
+
const extraRoutesFeature = features.filter((feat) => feat.ɵkind >= 100);
|
|
30
|
+
const routerFeatures = features.filter((feat) => feat.ɵkind < 100);
|
|
31
|
+
return makeEnvironmentProviders([
|
|
32
|
+
extraRoutesFeature.map((erf) => erf.ɵproviders),
|
|
33
|
+
provideRouter(routes, ...routerFeatures),
|
|
34
|
+
{
|
|
35
|
+
provide: ENVIRONMENT_INITIALIZER,
|
|
36
|
+
multi: true,
|
|
37
|
+
useValue: () => updateMetaTagsOnRouteChange()
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
provide: ɵHTTP_ROOT_INTERCEPTOR_FNS,
|
|
41
|
+
multi: true,
|
|
42
|
+
useValue: cookieInterceptor
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
provide: API_PREFIX,
|
|
46
|
+
useFactory() {
|
|
47
|
+
return typeof ANALOG_API_PREFIX !== "undefined" ? ANALOG_API_PREFIX : "api";
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
]);
|
|
482
51
|
}
|
|
483
|
-
/**
|
|
484
|
-
* Provides extra custom routes in addition to the routes
|
|
485
|
-
* discovered from the filesystem-based routing. These routes are
|
|
486
|
-
* inserted before the filesystem-based routes, and take priority in
|
|
487
|
-
* route matching.
|
|
488
|
-
*/
|
|
489
52
|
function withExtraRoutes(routes) {
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
53
|
+
return {
|
|
54
|
+
ɵkind: 100,
|
|
55
|
+
ɵproviders: [{
|
|
56
|
+
provide: ROUTES,
|
|
57
|
+
useValue: routes,
|
|
58
|
+
multi: true
|
|
59
|
+
}]
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function injectLoad(pathOrOptions, options) {
|
|
63
|
+
return ((typeof pathOrOptions === "string" ? options : pathOrOptions)?.injector ?? inject(Injector)).get(ActivatedRoute).data.pipe(map((data) => data["load"]));
|
|
500
64
|
}
|
|
501
|
-
|
|
502
|
-
/**
|
|
503
|
-
* Get server load resolver data for the route
|
|
504
|
-
*
|
|
505
|
-
* @param route Provides the route to get server load resolver
|
|
506
|
-
* @returns Returns server load resolver data for the route
|
|
507
|
-
*/
|
|
508
65
|
async function getLoadResolver(route) {
|
|
509
|
-
|
|
66
|
+
return route.routeConfig?.resolve?.["load"]?.(route);
|
|
510
67
|
}
|
|
511
|
-
|
|
512
|
-
// Length-prefix each atom (netstring style) so no field, parameter key, or
|
|
513
|
-
// parameter value can be crafted to shift another's boundary. Without this a
|
|
514
|
-
// hash over delimiter-joined fields still collides on ambiguous inputs, e.g.
|
|
515
|
-
// `?tag=x&tag=y` and `?tag=x,y` both serialize to `tag=x,y`.
|
|
516
68
|
function encodeAtom(value) {
|
|
517
|
-
|
|
69
|
+
return `${value.length}:${value}`;
|
|
518
70
|
}
|
|
519
71
|
function sortAndConcatParams(params) {
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
atoms.push(encodeAtom(key), encodeAtom(value));
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
return atoms.join('');
|
|
72
|
+
const keys = [...new Set(params.keys())].sort();
|
|
73
|
+
const atoms = [];
|
|
74
|
+
for (const key of keys) for (const value of params.getAll(key) ?? []) atoms.push(encodeAtom(key), encodeAtom(value));
|
|
75
|
+
return atoms.join("");
|
|
528
76
|
}
|
|
529
77
|
function makeCacheKey(request, mappedRequestUrl) {
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
mappedRequestUrl,
|
|
543
|
-
serializedBody,
|
|
544
|
-
encodedParams,
|
|
545
|
-
]
|
|
546
|
-
.map(encodeAtom)
|
|
547
|
-
.join('');
|
|
548
|
-
const hash = generateHash(key);
|
|
549
|
-
return makeStateKey(hash);
|
|
78
|
+
const { params, method, responseType } = request;
|
|
79
|
+
const encodedParams = sortAndConcatParams(params);
|
|
80
|
+
let serializedBody = request.serializeBody();
|
|
81
|
+
if (serializedBody instanceof URLSearchParams) serializedBody = sortAndConcatParams(serializedBody);
|
|
82
|
+
else if (typeof serializedBody !== "string") serializedBody = "";
|
|
83
|
+
return makeStateKey(generateHash([
|
|
84
|
+
method,
|
|
85
|
+
responseType,
|
|
86
|
+
mappedRequestUrl,
|
|
87
|
+
serializedBody,
|
|
88
|
+
encodedParams
|
|
89
|
+
].map(encodeAtom).join("")));
|
|
550
90
|
}
|
|
551
|
-
/**
|
|
552
|
-
* SHA-256 round constants (first 32 bits of the fractional parts of the cube
|
|
553
|
-
* roots of the first 64 primes).
|
|
554
|
-
*/
|
|
555
91
|
const SHA256_ROUND_CONSTANTS = /* @__PURE__ */ new Uint32Array([
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
92
|
+
1116352408,
|
|
93
|
+
1899447441,
|
|
94
|
+
3049323471,
|
|
95
|
+
3921009573,
|
|
96
|
+
961987163,
|
|
97
|
+
1508970993,
|
|
98
|
+
2453635748,
|
|
99
|
+
2870763221,
|
|
100
|
+
3624381080,
|
|
101
|
+
310598401,
|
|
102
|
+
607225278,
|
|
103
|
+
1426881987,
|
|
104
|
+
1925078388,
|
|
105
|
+
2162078206,
|
|
106
|
+
2614888103,
|
|
107
|
+
3248222580,
|
|
108
|
+
3835390401,
|
|
109
|
+
4022224774,
|
|
110
|
+
264347078,
|
|
111
|
+
604807628,
|
|
112
|
+
770255983,
|
|
113
|
+
1249150122,
|
|
114
|
+
1555081692,
|
|
115
|
+
1996064986,
|
|
116
|
+
2554220882,
|
|
117
|
+
2821834349,
|
|
118
|
+
2952996808,
|
|
119
|
+
3210313671,
|
|
120
|
+
3336571891,
|
|
121
|
+
3584528711,
|
|
122
|
+
113926993,
|
|
123
|
+
338241895,
|
|
124
|
+
666307205,
|
|
125
|
+
773529912,
|
|
126
|
+
1294757372,
|
|
127
|
+
1396182291,
|
|
128
|
+
1695183700,
|
|
129
|
+
1986661051,
|
|
130
|
+
2177026350,
|
|
131
|
+
2456956037,
|
|
132
|
+
2730485921,
|
|
133
|
+
2820302411,
|
|
134
|
+
3259730800,
|
|
135
|
+
3345764771,
|
|
136
|
+
3516065817,
|
|
137
|
+
3600352804,
|
|
138
|
+
4094571909,
|
|
139
|
+
275423344,
|
|
140
|
+
430227734,
|
|
141
|
+
506948616,
|
|
142
|
+
659060556,
|
|
143
|
+
883997877,
|
|
144
|
+
958139571,
|
|
145
|
+
1322822218,
|
|
146
|
+
1537002063,
|
|
147
|
+
1747873779,
|
|
148
|
+
1955562222,
|
|
149
|
+
2024104815,
|
|
150
|
+
2227730452,
|
|
151
|
+
2361852424,
|
|
152
|
+
2428436474,
|
|
153
|
+
2756734187,
|
|
154
|
+
3204031479,
|
|
155
|
+
3329325298
|
|
567
156
|
]);
|
|
568
157
|
let textEncoder;
|
|
569
|
-
/**
|
|
570
|
-
* Generates a SHA-256 hash of a string. This mirrors Angular's `HttpTransferCache`
|
|
571
|
-
* key derivation: a synchronous SHA-256 is used because the Web Crypto API is
|
|
572
|
-
* asynchronous, whereas cache-key derivation in the interceptor must stay
|
|
573
|
-
* synchronous. The previous 32-bit DJB2 hash had a keyspace small enough for an
|
|
574
|
-
* attacker to craft colliding requests and poison the transfer cache.
|
|
575
|
-
*/
|
|
576
158
|
function generateHash(value) {
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
const temp2 = (capitalSigma0 + majFunction) >>> 0;
|
|
649
|
-
workingStateH = workingStateG;
|
|
650
|
-
workingStateG = workingStateF;
|
|
651
|
-
workingStateF = workingStateE;
|
|
652
|
-
workingStateE = (workingStateD + temp1) >>> 0;
|
|
653
|
-
workingStateD = workingStateC;
|
|
654
|
-
workingStateC = workingStateB;
|
|
655
|
-
workingStateB = workingStateA;
|
|
656
|
-
workingStateA = (temp1 + temp2) >>> 0;
|
|
657
|
-
}
|
|
658
|
-
hashState0 = (hashState0 + workingStateA) >>> 0;
|
|
659
|
-
hashState1 = (hashState1 + workingStateB) >>> 0;
|
|
660
|
-
hashState2 = (hashState2 + workingStateC) >>> 0;
|
|
661
|
-
hashState3 = (hashState3 + workingStateD) >>> 0;
|
|
662
|
-
hashState4 = (hashState4 + workingStateE) >>> 0;
|
|
663
|
-
hashState5 = (hashState5 + workingStateF) >>> 0;
|
|
664
|
-
hashState6 = (hashState6 + workingStateG) >>> 0;
|
|
665
|
-
hashState7 = (hashState7 + workingStateH) >>> 0;
|
|
666
|
-
}
|
|
667
|
-
return [
|
|
668
|
-
hashState0,
|
|
669
|
-
hashState1,
|
|
670
|
-
hashState2,
|
|
671
|
-
hashState3,
|
|
672
|
-
hashState4,
|
|
673
|
-
hashState5,
|
|
674
|
-
hashState6,
|
|
675
|
-
hashState7,
|
|
676
|
-
]
|
|
677
|
-
.map((x) => x.toString(16).padStart(8, '0'))
|
|
678
|
-
.join('');
|
|
159
|
+
textEncoder ??= new TextEncoder();
|
|
160
|
+
const inputBytes = textEncoder.encode(value);
|
|
161
|
+
let hashState0 = 1779033703;
|
|
162
|
+
let hashState1 = 3144134277;
|
|
163
|
+
let hashState2 = 1013904242;
|
|
164
|
+
let hashState3 = 2773480762;
|
|
165
|
+
let hashState4 = 1359893119;
|
|
166
|
+
let hashState5 = 2600822924;
|
|
167
|
+
let hashState6 = 528734635;
|
|
168
|
+
let hashState7 = 1541459225;
|
|
169
|
+
const messageLengthInBits = inputBytes.length * 8;
|
|
170
|
+
const paddedLengthInBytes = (inputBytes.length + 8 >> 6) + 1 << 6;
|
|
171
|
+
const paddedBytes = new Uint8Array(paddedLengthInBytes);
|
|
172
|
+
paddedBytes.set(inputBytes);
|
|
173
|
+
paddedBytes[inputBytes.length] = 128;
|
|
174
|
+
const paddedBytesView = new DataView(paddedBytes.buffer);
|
|
175
|
+
const lowBits = messageLengthInBits >>> 0;
|
|
176
|
+
const highBits = messageLengthInBits / 4294967296 >>> 0;
|
|
177
|
+
paddedBytesView.setUint32(paddedLengthInBytes - 8, highBits, false);
|
|
178
|
+
paddedBytesView.setUint32(paddedLengthInBytes - 4, lowBits, false);
|
|
179
|
+
const messageSchedule = /* @__PURE__ */ new Uint32Array(64);
|
|
180
|
+
for (let chunkOffset = 0; chunkOffset < paddedLengthInBytes; chunkOffset += 64) {
|
|
181
|
+
for (let i = 0; i < 16; i++) messageSchedule[i] = paddedBytesView.getUint32(chunkOffset + i * 4, false);
|
|
182
|
+
for (let i = 16; i < 64; i++) {
|
|
183
|
+
const prevWord15 = messageSchedule[i - 15];
|
|
184
|
+
const sigma0 = ((prevWord15 >>> 7 | prevWord15 << 25) ^ (prevWord15 >>> 18 | prevWord15 << 14) ^ prevWord15 >>> 3) >>> 0;
|
|
185
|
+
const prevWord2 = messageSchedule[i - 2];
|
|
186
|
+
const sigma1 = ((prevWord2 >>> 17 | prevWord2 << 15) ^ (prevWord2 >>> 19 | prevWord2 << 13) ^ prevWord2 >>> 10) >>> 0;
|
|
187
|
+
messageSchedule[i] = messageSchedule[i - 16] + sigma0 + messageSchedule[i - 7] + sigma1 >>> 0;
|
|
188
|
+
}
|
|
189
|
+
let workingStateA = hashState0;
|
|
190
|
+
let workingStateB = hashState1;
|
|
191
|
+
let workingStateC = hashState2;
|
|
192
|
+
let workingStateD = hashState3;
|
|
193
|
+
let workingStateE = hashState4;
|
|
194
|
+
let workingStateF = hashState5;
|
|
195
|
+
let workingStateG = hashState6;
|
|
196
|
+
let workingStateH = hashState7;
|
|
197
|
+
for (let i = 0; i < 64; i++) {
|
|
198
|
+
const capitalSigma1 = ((workingStateE >>> 6 | workingStateE << 26) ^ (workingStateE >>> 11 | workingStateE << 21) ^ (workingStateE >>> 25 | workingStateE << 7)) >>> 0;
|
|
199
|
+
const chFunction = (workingStateE & workingStateF ^ ~workingStateE & workingStateG) >>> 0;
|
|
200
|
+
const temp1 = workingStateH + capitalSigma1 + chFunction + SHA256_ROUND_CONSTANTS[i] + messageSchedule[i] >>> 0;
|
|
201
|
+
const temp2 = (((workingStateA >>> 2 | workingStateA << 30) ^ (workingStateA >>> 13 | workingStateA << 19) ^ (workingStateA >>> 22 | workingStateA << 10)) >>> 0) + ((workingStateA & workingStateB ^ workingStateA & workingStateC ^ workingStateB & workingStateC) >>> 0) >>> 0;
|
|
202
|
+
workingStateH = workingStateG;
|
|
203
|
+
workingStateG = workingStateF;
|
|
204
|
+
workingStateF = workingStateE;
|
|
205
|
+
workingStateE = workingStateD + temp1 >>> 0;
|
|
206
|
+
workingStateD = workingStateC;
|
|
207
|
+
workingStateC = workingStateB;
|
|
208
|
+
workingStateB = workingStateA;
|
|
209
|
+
workingStateA = temp1 + temp2 >>> 0;
|
|
210
|
+
}
|
|
211
|
+
hashState0 = hashState0 + workingStateA >>> 0;
|
|
212
|
+
hashState1 = hashState1 + workingStateB >>> 0;
|
|
213
|
+
hashState2 = hashState2 + workingStateC >>> 0;
|
|
214
|
+
hashState3 = hashState3 + workingStateD >>> 0;
|
|
215
|
+
hashState4 = hashState4 + workingStateE >>> 0;
|
|
216
|
+
hashState5 = hashState5 + workingStateF >>> 0;
|
|
217
|
+
hashState6 = hashState6 + workingStateG >>> 0;
|
|
218
|
+
hashState7 = hashState7 + workingStateH >>> 0;
|
|
219
|
+
}
|
|
220
|
+
return [
|
|
221
|
+
hashState0,
|
|
222
|
+
hashState1,
|
|
223
|
+
hashState2,
|
|
224
|
+
hashState3,
|
|
225
|
+
hashState4,
|
|
226
|
+
hashState5,
|
|
227
|
+
hashState6,
|
|
228
|
+
hashState7
|
|
229
|
+
].map((x) => x.toString(16).padStart(8, "0")).join("");
|
|
679
230
|
}
|
|
680
|
-
|
|
681
|
-
/**
|
|
682
|
-
* Interceptor that is server-aware when making HttpClient requests.
|
|
683
|
-
* Server-side requests use the full URL
|
|
684
|
-
* Prerendering uses the internal Nitro $fetch function, along with state transfer
|
|
685
|
-
* Client-side requests use the window.location.origin
|
|
686
|
-
*
|
|
687
|
-
* @param req HttpRequest<unknown>
|
|
688
|
-
* @param next HttpHandlerFn
|
|
689
|
-
* @returns
|
|
690
|
-
*/
|
|
691
231
|
function requestContextInterceptor(req, next) {
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
232
|
+
const apiPrefix = injectAPIPrefix();
|
|
233
|
+
const baseUrl = injectBaseURL();
|
|
234
|
+
const transferState = inject(TransferState);
|
|
235
|
+
if (typeof global !== "undefined" && global.$fetch && baseUrl && (req.url.startsWith("/") || req.url.startsWith(baseUrl) || req.url.startsWith(`/${apiPrefix}`))) {
|
|
236
|
+
const requestUrl = new URL(req.urlWithParams, baseUrl);
|
|
237
|
+
const fetchUrl = `${requestUrl.pathname}${requestUrl.search}`;
|
|
238
|
+
const storeKey = makeStateKey(`analog_${makeCacheKey(req, fetchUrl)}`);
|
|
239
|
+
const responseType = req.responseType === "arraybuffer" ? "arrayBuffer" : req.responseType;
|
|
240
|
+
return from(global.$fetch.raw(fetchUrl, {
|
|
241
|
+
method: req.method,
|
|
242
|
+
body: req.body ? req.body : void 0,
|
|
243
|
+
responseType,
|
|
244
|
+
headers: req.headers.keys().reduce((hdrs, current) => {
|
|
245
|
+
return {
|
|
246
|
+
...hdrs,
|
|
247
|
+
[current]: req.headers.get(current)
|
|
248
|
+
};
|
|
249
|
+
}, {})
|
|
250
|
+
}).then((res) => {
|
|
251
|
+
const cacheResponse = {
|
|
252
|
+
body: res._data,
|
|
253
|
+
headers: new HttpHeaders(res.headers),
|
|
254
|
+
status: 200,
|
|
255
|
+
statusText: "OK",
|
|
256
|
+
url: fetchUrl
|
|
257
|
+
};
|
|
258
|
+
const transferResponse = new HttpResponse(cacheResponse);
|
|
259
|
+
transferState.set(storeKey, cacheResponse);
|
|
260
|
+
return transferResponse;
|
|
261
|
+
}));
|
|
262
|
+
}
|
|
263
|
+
if (!import.meta.env.SSR && (req.url.startsWith("/") || req.url.includes("/_analog/"))) {
|
|
264
|
+
const toAbsoluteUrl = (url) => new URL(url, window.location.origin);
|
|
265
|
+
const requestUrl = toAbsoluteUrl(req.url).href;
|
|
266
|
+
const { pathname, search } = toAbsoluteUrl(req.urlWithParams);
|
|
267
|
+
const storeKey = makeStateKey(`analog_${makeCacheKey(req, `${pathname}${search}`)}`);
|
|
268
|
+
const cacheRestoreResponse = transferState.get(storeKey, null);
|
|
269
|
+
if (cacheRestoreResponse) {
|
|
270
|
+
transferState.remove(storeKey);
|
|
271
|
+
return of(new HttpResponse(cacheRestoreResponse));
|
|
272
|
+
}
|
|
273
|
+
return next(req.clone({ url: requestUrl }));
|
|
274
|
+
}
|
|
275
|
+
if (baseUrl && (req.url.startsWith("/") || req.url.startsWith(baseUrl))) {
|
|
276
|
+
const requestUrl = req.url.startsWith(baseUrl) && !req.url.startsWith("/") ? req.url : `${baseUrl}${req.url}`;
|
|
277
|
+
return next(req.clone({ url: requestUrl }));
|
|
278
|
+
}
|
|
279
|
+
return next(req);
|
|
280
|
+
}
|
|
281
|
+
var FormAction = class FormAction {
|
|
282
|
+
constructor() {
|
|
283
|
+
this.action = input("", ...ngDevMode ? [{ debugName: "action" }] : /* istanbul ignore next */ []);
|
|
284
|
+
this.enhanceForm = input(false, {
|
|
285
|
+
...ngDevMode ? { debugName: "enhanceForm" } : /* istanbul ignore next */ {},
|
|
286
|
+
transform: booleanAttribute
|
|
287
|
+
});
|
|
288
|
+
this.onSuccess = output();
|
|
289
|
+
this.onError = output();
|
|
290
|
+
this.state = output();
|
|
291
|
+
this.currentState = signal("idle", ...ngDevMode ? [{ debugName: "currentState" }] : /* istanbul ignore next */ []);
|
|
292
|
+
this.injector = inject(Injector);
|
|
293
|
+
this.router = inject(Router);
|
|
294
|
+
this.route = inject(ActivatedRoute);
|
|
295
|
+
this.path = this._getPath();
|
|
296
|
+
const form = inject(ElementRef).nativeElement;
|
|
297
|
+
const renderer = inject(Renderer2);
|
|
298
|
+
effect((onCleanup) => {
|
|
299
|
+
if (!this.enhanceForm()) return;
|
|
300
|
+
const previous = {
|
|
301
|
+
"data-state": form.getAttribute("data-state"),
|
|
302
|
+
"aria-busy": form.getAttribute("aria-busy")
|
|
303
|
+
};
|
|
304
|
+
const state = this.currentState();
|
|
305
|
+
renderer.setAttribute(form, "data-state", state);
|
|
306
|
+
if (state === "submitting") renderer.setAttribute(form, "aria-busy", "true");
|
|
307
|
+
else renderer.removeAttribute(form, "aria-busy");
|
|
308
|
+
onCleanup(() => {
|
|
309
|
+
for (const [name, value] of Object.entries(previous)) if (value === null) renderer.removeAttribute(form, name);
|
|
310
|
+
else renderer.setAttribute(form, name, value);
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
submitted($event) {
|
|
315
|
+
$event.preventDefault();
|
|
316
|
+
this._emitState("submitting");
|
|
317
|
+
const body = new FormData($event.target);
|
|
318
|
+
if (this.enhanceForm()) {
|
|
319
|
+
const form = $event.target;
|
|
320
|
+
try {
|
|
321
|
+
const action = this.action().trim() || form.getAttribute("action")?.trim();
|
|
322
|
+
if (form.method.toUpperCase() === "GET") this._handleEnhancedGet(body, action || this.router.url);
|
|
323
|
+
else {
|
|
324
|
+
const path = action ? new URL(action, window.location.href).toString() : this._getPath();
|
|
325
|
+
this._handleEnhancedPost(body, path, form.method);
|
|
326
|
+
}
|
|
327
|
+
} catch {
|
|
328
|
+
this._emitState("error");
|
|
329
|
+
}
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
if ($event.target.method.toUpperCase() === "GET") this._handleGet(body, this.router.url);
|
|
333
|
+
else this._handlePost(body, this.path, $event);
|
|
334
|
+
}
|
|
335
|
+
_handleGet(body, path) {
|
|
336
|
+
const params = {};
|
|
337
|
+
body.forEach((formVal, formKey) => params[formKey] = formVal);
|
|
338
|
+
this._emitState("navigate");
|
|
339
|
+
const url = path.split("?")[0];
|
|
340
|
+
this.router.navigate([url], {
|
|
341
|
+
queryParams: params,
|
|
342
|
+
onSameUrlNavigation: "reload"
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
_handlePost(body, path, $event) {
|
|
346
|
+
fetch(path, {
|
|
347
|
+
method: $event.target.method,
|
|
348
|
+
body
|
|
349
|
+
}).then((res) => {
|
|
350
|
+
if (res.ok) if (res.redirected) {
|
|
351
|
+
const redirectUrl = new URL(res.url).pathname;
|
|
352
|
+
this._emitState("redirect");
|
|
353
|
+
this.router.navigate([redirectUrl]);
|
|
354
|
+
} else if (this._isJSON(res.headers.get("Content-type"))) res.json().then((result) => {
|
|
355
|
+
this.onSuccess.emit(result);
|
|
356
|
+
this._emitState("success");
|
|
357
|
+
});
|
|
358
|
+
else res.text().then((result) => {
|
|
359
|
+
this.onSuccess.emit(result);
|
|
360
|
+
this._emitState("success");
|
|
361
|
+
});
|
|
362
|
+
else if (res.headers.get("X-Analog-Errors")) res.json().then((errors) => {
|
|
363
|
+
this.onError.emit(errors);
|
|
364
|
+
this._emitState("error");
|
|
365
|
+
});
|
|
366
|
+
else this._emitState("error");
|
|
367
|
+
}).catch((_) => {
|
|
368
|
+
this._emitState("error");
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
_getPath() {
|
|
372
|
+
const snapshot = this.route.snapshot;
|
|
373
|
+
if (snapshot.routeConfig && ANALOG_META_KEY in snapshot.routeConfig) return runInInjectionContext(this.injector, () => injectRouteEndpointURL(snapshot)).pathname;
|
|
374
|
+
return `/api/_analog/pages${window.location.pathname}`;
|
|
375
|
+
}
|
|
376
|
+
_handleEnhancedGet(body, path) {
|
|
377
|
+
const url = new URL(path, window.location.href);
|
|
378
|
+
const params = new URLSearchParams(url.search);
|
|
379
|
+
body.forEach((_value, key) => params.delete(key));
|
|
380
|
+
body.forEach((value, key) => {
|
|
381
|
+
params.append(key, value instanceof File ? value.name : value);
|
|
382
|
+
});
|
|
383
|
+
url.search = params.toString();
|
|
384
|
+
this._emitState("navigate");
|
|
385
|
+
this._navigateTo(url);
|
|
386
|
+
}
|
|
387
|
+
async _handleEnhancedPost(body, path, method) {
|
|
388
|
+
try {
|
|
389
|
+
const response = await fetch(path, {
|
|
390
|
+
method,
|
|
391
|
+
body
|
|
392
|
+
});
|
|
393
|
+
if (response.ok) if (response.redirected) {
|
|
394
|
+
this._emitState("redirect");
|
|
395
|
+
this._navigateTo(new URL(response.url, window.location.href));
|
|
396
|
+
} else {
|
|
397
|
+
const result = this._isJSON(response.headers.get("Content-type")) ? await response.json() : await response.text();
|
|
398
|
+
this.onSuccess.emit(result);
|
|
399
|
+
this._emitState("success");
|
|
400
|
+
}
|
|
401
|
+
else {
|
|
402
|
+
if (response.headers.get("X-Analog-Errors")) this.onError.emit(await response.json());
|
|
403
|
+
this._emitState("error");
|
|
404
|
+
}
|
|
405
|
+
} catch {
|
|
406
|
+
this._emitState("error");
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
_emitState(state) {
|
|
410
|
+
this.currentState.set(state);
|
|
411
|
+
this.state.emit(state);
|
|
412
|
+
}
|
|
413
|
+
_navigateTo(url) {
|
|
414
|
+
if (url.origin === window.location.origin) {
|
|
415
|
+
this.router.navigateByUrl(`${url.pathname}${url.search}${url.hash}`, { onSameUrlNavigation: "reload" });
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
window.location.assign(url.toString());
|
|
419
|
+
}
|
|
420
|
+
_isJSON(contentType) {
|
|
421
|
+
return (contentType ? contentType.split(";") : [])[0] === "application/json";
|
|
422
|
+
}
|
|
423
|
+
static {
|
|
424
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
425
|
+
minVersion: "12.0.0",
|
|
426
|
+
version: "22.2.0",
|
|
427
|
+
ngImport: i0,
|
|
428
|
+
type: FormAction,
|
|
429
|
+
deps: [],
|
|
430
|
+
target: i0.ɵɵFactoryTarget.Directive
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
static {
|
|
434
|
+
this.ɵdir = i0.ɵɵngDeclareDirective({
|
|
435
|
+
minVersion: "17.1.0",
|
|
436
|
+
version: "22.2.0",
|
|
437
|
+
type: FormAction,
|
|
438
|
+
isStandalone: true,
|
|
439
|
+
selector: "form[action],form[method],form[enhanceForm]",
|
|
440
|
+
inputs: {
|
|
441
|
+
action: {
|
|
442
|
+
classPropertyName: "action",
|
|
443
|
+
publicName: "action",
|
|
444
|
+
isSignal: true,
|
|
445
|
+
isRequired: false,
|
|
446
|
+
transformFunction: null
|
|
447
|
+
},
|
|
448
|
+
enhanceForm: {
|
|
449
|
+
classPropertyName: "enhanceForm",
|
|
450
|
+
publicName: "enhanceForm",
|
|
451
|
+
isSignal: true,
|
|
452
|
+
isRequired: false,
|
|
453
|
+
transformFunction: null
|
|
454
|
+
}
|
|
455
|
+
},
|
|
456
|
+
outputs: {
|
|
457
|
+
onSuccess: "onSuccess",
|
|
458
|
+
onError: "onError",
|
|
459
|
+
state: "state"
|
|
460
|
+
},
|
|
461
|
+
host: { listeners: { "submit": "submitted($event)" } },
|
|
462
|
+
ngImport: i0
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
467
|
+
minVersion: "12.0.0",
|
|
468
|
+
version: "22.2.0",
|
|
469
|
+
ngImport: i0,
|
|
470
|
+
type: FormAction,
|
|
471
|
+
decorators: [{
|
|
472
|
+
type: Directive,
|
|
473
|
+
args: [{
|
|
474
|
+
selector: "form[action],form[method],form[enhanceForm]",
|
|
475
|
+
host: { "(submit)": `submitted($event)` },
|
|
476
|
+
standalone: true
|
|
477
|
+
}]
|
|
478
|
+
}],
|
|
479
|
+
ctorParameters: () => [],
|
|
480
|
+
propDecorators: {
|
|
481
|
+
action: [{
|
|
482
|
+
type: i0.Input,
|
|
483
|
+
args: [{
|
|
484
|
+
isSignal: true,
|
|
485
|
+
alias: "action",
|
|
486
|
+
required: false
|
|
487
|
+
}]
|
|
488
|
+
}],
|
|
489
|
+
enhanceForm: [{
|
|
490
|
+
type: i0.Input,
|
|
491
|
+
args: [{
|
|
492
|
+
isSignal: true,
|
|
493
|
+
alias: "enhanceForm",
|
|
494
|
+
required: false
|
|
495
|
+
}]
|
|
496
|
+
}],
|
|
497
|
+
onSuccess: [{
|
|
498
|
+
type: i0.Output,
|
|
499
|
+
args: ["onSuccess"]
|
|
500
|
+
}],
|
|
501
|
+
onError: [{
|
|
502
|
+
type: i0.Output,
|
|
503
|
+
args: ["onError"]
|
|
504
|
+
}],
|
|
505
|
+
state: [{
|
|
506
|
+
type: i0.Output,
|
|
507
|
+
args: ["state"]
|
|
508
|
+
}]
|
|
509
|
+
}
|
|
510
|
+
});
|
|
967
511
|
function getPathSegmentKey(segment) {
|
|
968
|
-
|
|
512
|
+
return typeof segment === "object" ? segment.key : segment;
|
|
969
513
|
}
|
|
970
514
|
function issuePathToFieldName(path) {
|
|
971
|
-
|
|
515
|
+
return path.map((segment) => String(getPathSegmentKey(segment))).join(".");
|
|
972
516
|
}
|
|
973
517
|
function issuesToFieldErrors(issues) {
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
return errors;
|
|
982
|
-
}, Object.create(null));
|
|
518
|
+
return issues.reduce((errors, issue) => {
|
|
519
|
+
if (!issue.path?.length) return errors;
|
|
520
|
+
const fieldName = issuePathToFieldName(issue.path);
|
|
521
|
+
errors[fieldName] ??= [];
|
|
522
|
+
errors[fieldName].push(issue.message);
|
|
523
|
+
return errors;
|
|
524
|
+
}, Object.create(null));
|
|
983
525
|
}
|
|
984
526
|
function issuesToFormErrors(issues) {
|
|
985
|
-
|
|
986
|
-
.filter((issue) => !issue.path?.length)
|
|
987
|
-
.map((issue) => issue.message);
|
|
527
|
+
return issues.filter((issue) => !issue.path?.length).map((issue) => issue.message);
|
|
988
528
|
}
|
|
989
|
-
|
|
990
|
-
const DEBUG_ROUTES = new InjectionToken('@analogjs/router debug routes', {
|
|
991
|
-
providedIn: 'root',
|
|
992
|
-
factory() {
|
|
993
|
-
const debugRoutes = createRoutes({
|
|
994
|
-
...ANALOG_ROUTE_FILES,
|
|
995
|
-
...ANALOG_CONTENT_ROUTE_FILES,
|
|
996
|
-
}, true);
|
|
997
|
-
return debugRoutes;
|
|
998
|
-
},
|
|
999
|
-
});
|
|
1000
|
-
function injectDebugRoutes() {
|
|
1001
|
-
return inject(DEBUG_ROUTES);
|
|
1002
|
-
}
|
|
1003
|
-
|
|
1004
|
-
/**
|
|
1005
|
-
* Provides routes that provide additional
|
|
1006
|
-
* pages for displaying and debugging
|
|
1007
|
-
* routes.
|
|
1008
|
-
*/
|
|
1009
529
|
function withDebugRoutes() {
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
}
|
|
1021
|
-
|
|
1022
|
-
const SERVER_FN_DISPATCHER = new InjectionToken(
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
530
|
+
return {
|
|
531
|
+
ɵkind: 101,
|
|
532
|
+
ɵproviders: [{
|
|
533
|
+
provide: ROUTES,
|
|
534
|
+
useValue: [{
|
|
535
|
+
path: "__analog/routes",
|
|
536
|
+
loadComponent: () => import("./analogjs-router-debug.page-MFY2u07E.mjs")
|
|
537
|
+
}],
|
|
538
|
+
multi: true
|
|
539
|
+
}]
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
const SERVER_FN_DISPATCHER = new InjectionToken("@analogjs/router Server Function Dispatcher");
|
|
543
|
+
var ServerFnClient = class ServerFnClient {
|
|
544
|
+
constructor() {
|
|
545
|
+
this.http = inject(HttpClient);
|
|
546
|
+
this.transferState = inject(TransferState);
|
|
547
|
+
this.injector = inject(Injector);
|
|
548
|
+
this.dispatcher = inject(SERVER_FN_DISPATCHER, { optional: true });
|
|
549
|
+
}
|
|
550
|
+
get isServer() {
|
|
551
|
+
return !!this.dispatcher;
|
|
552
|
+
}
|
|
553
|
+
async call(fn, input) {
|
|
554
|
+
if (this.dispatcher) return this.dispatcher(fn, input, this.injector);
|
|
555
|
+
return firstValueFrom(fn.method === "GET" ? this.http.get(fn.url) : this.http.post(fn.url, input ?? {}));
|
|
556
|
+
}
|
|
557
|
+
stateKey(fn, input) {
|
|
558
|
+
return makeStateKey(`__analog_fn_${fn.id}_${stableInput(input)}`);
|
|
559
|
+
}
|
|
560
|
+
readSeed(fn, input) {
|
|
561
|
+
const key = this.stateKey(fn, input);
|
|
562
|
+
if (this.transferState.hasKey(key)) {
|
|
563
|
+
const value = this.transferState.get(key, void 0);
|
|
564
|
+
this.transferState.remove(key);
|
|
565
|
+
return value;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
writeSeed(fn, input, value) {
|
|
569
|
+
this.transferState.set(this.stateKey(fn, input), value);
|
|
570
|
+
}
|
|
571
|
+
static {
|
|
572
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
573
|
+
minVersion: "12.0.0",
|
|
574
|
+
version: "22.2.0",
|
|
575
|
+
ngImport: i0,
|
|
576
|
+
type: ServerFnClient,
|
|
577
|
+
deps: [],
|
|
578
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
static {
|
|
582
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
583
|
+
minVersion: "12.0.0",
|
|
584
|
+
version: "22.2.0",
|
|
585
|
+
ngImport: i0,
|
|
586
|
+
type: ServerFnClient,
|
|
587
|
+
providedIn: "root"
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
};
|
|
591
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
592
|
+
minVersion: "12.0.0",
|
|
593
|
+
version: "22.2.0",
|
|
594
|
+
ngImport: i0,
|
|
595
|
+
type: ServerFnClient,
|
|
596
|
+
decorators: [{
|
|
597
|
+
type: Injectable,
|
|
598
|
+
args: [{ providedIn: "root" }]
|
|
599
|
+
}]
|
|
600
|
+
});
|
|
1077
601
|
function provideServerFnClient() {
|
|
1078
|
-
|
|
602
|
+
return [];
|
|
1079
603
|
}
|
|
1080
|
-
|
|
1081
|
-
// params value as "idle, don't load", so an input-less read must yield a
|
|
1082
|
-
// defined-but-ignored params. It is never sent — the call uses `undefined`.
|
|
1083
|
-
const NO_INPUT = Symbol('analog.serverFn.noInput');
|
|
604
|
+
const NO_INPUT = Symbol("analog.serverFn.noInput");
|
|
1084
605
|
function injectServerFn(fn, args) {
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
client.writeSeed(fn, input, value);
|
|
1099
|
-
}
|
|
1100
|
-
return value;
|
|
1101
|
-
},
|
|
1102
|
-
});
|
|
606
|
+
assertInInjectionContext(injectServerFn);
|
|
607
|
+
const client = inject(ServerFnClient);
|
|
608
|
+
return resource({
|
|
609
|
+
params: () => args ? args() : NO_INPUT,
|
|
610
|
+
loader: async ({ params }) => {
|
|
611
|
+
const input = params === NO_INPUT ? void 0 : params;
|
|
612
|
+
const seeded = client.readSeed(fn, input);
|
|
613
|
+
if (seeded !== void 0) return seeded;
|
|
614
|
+
const value = await client.call(fn, input);
|
|
615
|
+
if (client.isServer) client.writeSeed(fn, input, value);
|
|
616
|
+
return value;
|
|
617
|
+
}
|
|
618
|
+
});
|
|
1103
619
|
}
|
|
1104
|
-
/**
|
|
1105
|
-
* Imperative binding of a server function: returns a callable that dispatches
|
|
1106
|
-
* the call through `HttpClient` (so client interceptors apply) and resolves the
|
|
1107
|
-
* result. Use for mutations and event-driven calls; use `injectServerFn` for
|
|
1108
|
-
* reactive reads.
|
|
1109
|
-
*/
|
|
1110
620
|
function injectServerFnMutation(fn) {
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
621
|
+
assertInInjectionContext(injectServerFnMutation);
|
|
622
|
+
const client = inject(ServerFnClient);
|
|
623
|
+
return (input) => client.call(fn, input);
|
|
1114
624
|
}
|
|
1115
625
|
function stableInput(input) {
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
return JSON.stringify(input);
|
|
626
|
+
if (input === void 0 || input === null) return "_";
|
|
627
|
+
return JSON.stringify(input);
|
|
1119
628
|
}
|
|
1120
|
-
|
|
1121
|
-
/**
|
|
1122
|
-
* Builds a server-function reference: the client-safe `{ __serverFn, id, url,
|
|
1123
|
-
* method }` metadata that `injectServerFn`/`ServerFnClient` dispatch through.
|
|
1124
|
-
*
|
|
1125
|
-
* Shared by both sides so they produce identical refs: the server `serverFn`
|
|
1126
|
-
* wraps this with registration + the handler, and the client build's scrub
|
|
1127
|
-
* transform emits a call to this factory in place of the server module so the
|
|
1128
|
-
* browser bundle carries only the ref, never the handler or its server imports.
|
|
1129
|
-
*
|
|
1130
|
-
* The returned value is callable-typed but throws if invoked directly — it is
|
|
1131
|
-
* always dispatched via `injectServerFn`/`ServerFnClient`, never called.
|
|
1132
|
-
*/
|
|
1133
629
|
function createServerFnRef(config) {
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
method,
|
|
1147
|
-
});
|
|
630
|
+
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.");
|
|
631
|
+
const method = config.method ?? (config.input ? "POST" : "GET");
|
|
632
|
+
const url = `/_analog/fn/${config.id}`;
|
|
633
|
+
const ref = (() => {
|
|
634
|
+
throw new Error(`serverFn "${config.id}" must be called via injectServerFn/ServerFnClient`);
|
|
635
|
+
});
|
|
636
|
+
return Object.assign(ref, {
|
|
637
|
+
__serverFn: true,
|
|
638
|
+
id: config.id,
|
|
639
|
+
url,
|
|
640
|
+
method
|
|
641
|
+
});
|
|
1148
642
|
}
|
|
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
643
|
function toRoute(path, ...args) {
|
|
1177
|
-
|
|
1178
|
-
|
|
644
|
+
const options = args[0];
|
|
645
|
+
return buildRouteLink(path, options);
|
|
1179
646
|
}
|
|
1180
|
-
/**
|
|
1181
|
-
* Internal: builds a `RouteLinkResult` from path and options.
|
|
1182
|
-
* Exported for direct use in tests (avoids generic constraints).
|
|
1183
|
-
*/
|
|
1184
647
|
function buildRouteLink(path, options) {
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
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
|
-
};
|
|
648
|
+
return {
|
|
649
|
+
path: buildPath(path, options?.params),
|
|
650
|
+
queryParams: options?.query ?? null,
|
|
651
|
+
fragment: options?.hash
|
|
652
|
+
};
|
|
1205
653
|
}
|
|
1206
654
|
function buildPath(path, params = {}) {
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
655
|
+
return ["/", ...path.split("/").filter(Boolean).flatMap((segment) => {
|
|
656
|
+
const optional = segment.match(/^\[\[\.\.\.([^\]]+)\]\]$/);
|
|
657
|
+
const catchAll = segment.match(/^\[\.\.\.([^\]]+)\]$/);
|
|
658
|
+
const dynamic = segment.match(/^\[([^\]]+)\]$/);
|
|
659
|
+
const match = optional ?? catchAll ?? dynamic;
|
|
660
|
+
if (!match) return [segment];
|
|
661
|
+
const value = params[match[1]];
|
|
662
|
+
if (value == null || Array.isArray(value) && !value.length) {
|
|
663
|
+
if (optional) return [];
|
|
664
|
+
throw new Error(`Missing required ${catchAll ? "catch-all " : ""}param "${match[1]}" for path "${path}"`);
|
|
665
|
+
}
|
|
666
|
+
return Array.isArray(value) ? value.map(String) : [String(value)];
|
|
667
|
+
})];
|
|
668
|
+
}
|
|
669
|
+
function resolveRoutePath(from, to) {
|
|
670
|
+
if (to.startsWith("/")) return to;
|
|
671
|
+
const segments = from.split("/").filter(Boolean);
|
|
672
|
+
for (const part of to.split("/")) if (part === "..") segments.pop();
|
|
673
|
+
else if (part && part !== ".") segments.push(part);
|
|
674
|
+
return "/" + segments.join("/");
|
|
675
|
+
}
|
|
676
|
+
function resolveScopedRoute(from, target, current, options) {
|
|
677
|
+
const path = resolveRoutePath(from, target);
|
|
678
|
+
const fromSegments = from.split("/").filter(Boolean);
|
|
679
|
+
const toSegments = path.split("/").filter(Boolean);
|
|
680
|
+
const params = {};
|
|
681
|
+
for (let i = 0; i < toSegments.length && toSegments[i] === fromSegments[i]; i++) {
|
|
682
|
+
const name = paramName(toSegments[i]);
|
|
683
|
+
if (name) params[name] = current[name];
|
|
684
|
+
}
|
|
685
|
+
return {
|
|
686
|
+
path,
|
|
687
|
+
options: {
|
|
688
|
+
...options,
|
|
689
|
+
params: {
|
|
690
|
+
...params,
|
|
691
|
+
...options?.params
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
function paramName(segment) {
|
|
697
|
+
return (segment.match(/^\[\[\.\.\.([^\]]+)\]\]$/) ?? segment.match(/^\[\.\.\.([^\]]+)\]$/) ?? segment.match(/^\[([^\]]+)\]$/))?.[1];
|
|
1227
698
|
}
|
|
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
699
|
function extractCatchAllParams(routePath) {
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
}
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
}
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
700
|
+
const params = [];
|
|
701
|
+
for (const segment of routePath.split("/")) {
|
|
702
|
+
const optional = segment.match(/^\[\[\.\.\.([^\]]+)\]\]$/);
|
|
703
|
+
const required = segment.match(/^\[\.\.\.([^\]]+)\]$/);
|
|
704
|
+
if (optional) params.push({
|
|
705
|
+
name: optional[1],
|
|
706
|
+
type: "optionalCatchAll"
|
|
707
|
+
});
|
|
708
|
+
else if (required) params.push({
|
|
709
|
+
name: required[1],
|
|
710
|
+
type: "catchAll"
|
|
711
|
+
});
|
|
712
|
+
}
|
|
713
|
+
return params;
|
|
714
|
+
}
|
|
715
|
+
function observeRouteParams(route, routePath) {
|
|
716
|
+
const ancestors = route.pathFromRoot ?? [route];
|
|
717
|
+
const catchAllParams = extractCatchAllParams(routePath);
|
|
718
|
+
return combineLatest([combineLatest(ancestors.map((entry) => entry.params)), combineLatest(ancestors.map((entry) => entry.url ?? of([])))]).pipe(map(([values, segments]) => {
|
|
719
|
+
const params = Object.assign({}, ...values);
|
|
720
|
+
for (const param of catchAllParams) {
|
|
721
|
+
const source = ancestors.findIndex((entry, index) => param.type === "catchAll" ? entry.routeConfig?.path === "**" : !!entry.routeConfig?.matcher && values[index][param.name] != null);
|
|
722
|
+
if (source !== -1) params[param.name] = segments[source].map((segment) => segment.path);
|
|
723
|
+
}
|
|
724
|
+
return params;
|
|
725
|
+
}));
|
|
726
|
+
}
|
|
727
|
+
function resolveArgs(fromOrOptions, options) {
|
|
728
|
+
const typed = typeof fromOrOptions === "string";
|
|
729
|
+
const injector = (typed ? options : fromOrOptions)?.injector;
|
|
730
|
+
return {
|
|
731
|
+
from: typed ? fromOrOptions : "",
|
|
732
|
+
injector,
|
|
733
|
+
route: injector ? injector.get(ActivatedRoute) : inject(ActivatedRoute)
|
|
734
|
+
};
|
|
735
|
+
}
|
|
736
|
+
function injectParams(fromOrOptions, options) {
|
|
737
|
+
const { from, injector, route } = resolveArgs(fromOrOptions, options);
|
|
738
|
+
return toSignal(observeRouteParams(route, from), {
|
|
739
|
+
requireSync: true,
|
|
740
|
+
injector
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
function injectQuery(fromOrOptions, options) {
|
|
744
|
+
const { injector, route } = resolveArgs(fromOrOptions, options);
|
|
745
|
+
return toSignal(route.queryParams, {
|
|
746
|
+
requireSync: true,
|
|
747
|
+
injector
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
function injectRouteData(fromOrOptions, options) {
|
|
751
|
+
const { injector, route } = resolveArgs(fromOrOptions, options);
|
|
752
|
+
return toSignal(route.data, {
|
|
753
|
+
requireSync: true,
|
|
754
|
+
injector
|
|
755
|
+
});
|
|
756
|
+
}
|
|
757
|
+
function injectResources(fromOrOptions, options) {
|
|
758
|
+
const { route } = resolveArgs(fromOrOptions, options);
|
|
759
|
+
return "resources" in route ? route.resources ?? {} : {};
|
|
760
|
+
}
|
|
761
|
+
var LinkTo = class LinkTo {
|
|
762
|
+
constructor() {
|
|
763
|
+
this.linkTo = input.required(...ngDevMode ? [{ debugName: "linkTo" }] : /* istanbul ignore next */ []);
|
|
764
|
+
this.from = input(...ngDevMode ? [void 0, { debugName: "from" }] : /* istanbul ignore next */ []);
|
|
765
|
+
this.routerLink = inject(RouterLink);
|
|
766
|
+
this.route = inject(ActivatedRoute);
|
|
767
|
+
this.currentParams = {};
|
|
768
|
+
}
|
|
769
|
+
ngOnChanges() {
|
|
770
|
+
const from = this.from();
|
|
771
|
+
if (from !== this.paramsFrom) {
|
|
772
|
+
this.paramsFrom = from;
|
|
773
|
+
this.paramsSubscription?.unsubscribe();
|
|
774
|
+
this.paramsSubscription = from ? observeRouteParams(this.route, from).subscribe((params) => {
|
|
775
|
+
this.currentParams = params;
|
|
776
|
+
this.update();
|
|
777
|
+
}) : void 0;
|
|
778
|
+
}
|
|
779
|
+
this.update();
|
|
780
|
+
}
|
|
781
|
+
ngOnDestroy() {
|
|
782
|
+
this.paramsSubscription?.unsubscribe();
|
|
783
|
+
}
|
|
784
|
+
update() {
|
|
785
|
+
const destination = this.linkTo();
|
|
786
|
+
const from = this.from();
|
|
787
|
+
let link = null;
|
|
788
|
+
if (destination) {
|
|
789
|
+
const { path, ...options } = typeof destination === "string" ? { path: destination } : destination;
|
|
790
|
+
if (from) {
|
|
791
|
+
const scoped = resolveScopedRoute(from, path, this.currentParams, options);
|
|
792
|
+
link = buildRouteLink(scoped.path, scoped.options);
|
|
793
|
+
} else link = buildRouteLink(path, options);
|
|
794
|
+
}
|
|
795
|
+
this.routerLink.routerLink = link?.path ?? null;
|
|
796
|
+
this.routerLink.queryParams = link?.queryParams ?? null;
|
|
797
|
+
this.routerLink.fragment = link?.fragment;
|
|
798
|
+
this.routerLink.ngOnChanges({});
|
|
799
|
+
}
|
|
800
|
+
static {
|
|
801
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
802
|
+
minVersion: "12.0.0",
|
|
803
|
+
version: "22.2.0",
|
|
804
|
+
ngImport: i0,
|
|
805
|
+
type: LinkTo,
|
|
806
|
+
deps: [],
|
|
807
|
+
target: i0.ɵɵFactoryTarget.Directive
|
|
808
|
+
});
|
|
809
|
+
}
|
|
810
|
+
static {
|
|
811
|
+
this.ɵdir = i0.ɵɵngDeclareDirective({
|
|
812
|
+
minVersion: "17.1.0",
|
|
813
|
+
version: "22.2.0",
|
|
814
|
+
type: LinkTo,
|
|
815
|
+
isStandalone: true,
|
|
816
|
+
selector: "[linkTo]",
|
|
817
|
+
inputs: {
|
|
818
|
+
linkTo: {
|
|
819
|
+
classPropertyName: "linkTo",
|
|
820
|
+
publicName: "linkTo",
|
|
821
|
+
isSignal: true,
|
|
822
|
+
isRequired: true,
|
|
823
|
+
transformFunction: null
|
|
824
|
+
},
|
|
825
|
+
from: {
|
|
826
|
+
classPropertyName: "from",
|
|
827
|
+
publicName: "from",
|
|
828
|
+
isSignal: true,
|
|
829
|
+
isRequired: false,
|
|
830
|
+
transformFunction: null
|
|
831
|
+
}
|
|
832
|
+
},
|
|
833
|
+
usesOnChanges: true,
|
|
834
|
+
hostDirectives: [{
|
|
835
|
+
directive: i1.RouterLink,
|
|
836
|
+
inputs: [
|
|
837
|
+
"target",
|
|
838
|
+
"target",
|
|
839
|
+
"queryParamsHandling",
|
|
840
|
+
"queryParamsHandling",
|
|
841
|
+
"preserveFragment",
|
|
842
|
+
"preserveFragment",
|
|
843
|
+
"skipLocationChange",
|
|
844
|
+
"skipLocationChange",
|
|
845
|
+
"replaceUrl",
|
|
846
|
+
"replaceUrl",
|
|
847
|
+
"state",
|
|
848
|
+
"state"
|
|
849
|
+
]
|
|
850
|
+
}],
|
|
851
|
+
ngImport: i0
|
|
852
|
+
});
|
|
853
|
+
}
|
|
854
|
+
};
|
|
855
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
856
|
+
minVersion: "12.0.0",
|
|
857
|
+
version: "22.2.0",
|
|
858
|
+
ngImport: i0,
|
|
859
|
+
type: LinkTo,
|
|
860
|
+
decorators: [{
|
|
861
|
+
type: Directive,
|
|
862
|
+
args: [{
|
|
863
|
+
selector: "[linkTo]",
|
|
864
|
+
standalone: true,
|
|
865
|
+
hostDirectives: [{
|
|
866
|
+
directive: RouterLink,
|
|
867
|
+
inputs: [
|
|
868
|
+
"target",
|
|
869
|
+
"queryParamsHandling",
|
|
870
|
+
"preserveFragment",
|
|
871
|
+
"skipLocationChange",
|
|
872
|
+
"replaceUrl",
|
|
873
|
+
"state"
|
|
874
|
+
]
|
|
875
|
+
}]
|
|
876
|
+
}]
|
|
877
|
+
}],
|
|
878
|
+
propDecorators: {
|
|
879
|
+
linkTo: [{
|
|
880
|
+
type: i0.Input,
|
|
881
|
+
args: [{
|
|
882
|
+
isSignal: true,
|
|
883
|
+
alias: "linkTo",
|
|
884
|
+
required: true
|
|
885
|
+
}]
|
|
886
|
+
}],
|
|
887
|
+
from: [{
|
|
888
|
+
type: i0.Input,
|
|
889
|
+
args: [{
|
|
890
|
+
isSignal: true,
|
|
891
|
+
alias: "from",
|
|
892
|
+
required: false
|
|
893
|
+
}]
|
|
894
|
+
}]
|
|
895
|
+
}
|
|
896
|
+
});
|
|
897
|
+
function isRoutePathOptionsBase(value) {
|
|
898
|
+
return !!value && typeof value === "object" && ("params" in value || "query" in value || "hash" in value);
|
|
899
|
+
}
|
|
900
|
+
function update(value, current) {
|
|
901
|
+
return typeof value === "function" ? value(current) : value;
|
|
902
|
+
}
|
|
903
|
+
function injectNavigate(from, options) {
|
|
904
|
+
const injector = options?.injector ?? inject(Injector);
|
|
905
|
+
const router = injector.get(Router);
|
|
906
|
+
const currentParams = from ? injectParams(from, { injector }) : void 0;
|
|
907
|
+
const currentQuery = from ? injectQuery(from, { injector }) : void 0;
|
|
908
|
+
return (target, ...args) => {
|
|
909
|
+
let options;
|
|
910
|
+
let extras;
|
|
911
|
+
if (args.length > 1) {
|
|
912
|
+
options = args[0];
|
|
913
|
+
extras = args[1];
|
|
914
|
+
} else if (args.length === 1) if (isRoutePathOptionsBase(args[0])) options = args[0];
|
|
915
|
+
else extras = args[0];
|
|
916
|
+
let path = target;
|
|
917
|
+
if (from && currentParams && currentQuery) {
|
|
918
|
+
const params = currentParams();
|
|
919
|
+
({path, options} = resolveScopedRoute(from, target, params, {
|
|
920
|
+
...options,
|
|
921
|
+
params: update(options?.params, params),
|
|
922
|
+
query: update(options?.query, currentQuery())
|
|
923
|
+
}));
|
|
924
|
+
}
|
|
925
|
+
const link = buildRouteLink(path, options);
|
|
926
|
+
return router.navigate(link.path, {
|
|
927
|
+
...extras,
|
|
928
|
+
queryParams: link.queryParams,
|
|
929
|
+
fragment: link.fragment
|
|
930
|
+
});
|
|
931
|
+
};
|
|
932
|
+
}
|
|
933
|
+
export { FormAction, LinkTo, SERVER_FN_DISPATCHER, ServerFnClient, createRoutes, createServerFnRef, defineRouteMeta, getLoadResolver, injectActivatedRoute, injectDebugRoutes, injectLoad, injectNavigate, injectParams, injectQuery, injectResources, injectResources as injectRouteResources, injectRouteData, injectRouteEndpointURL, injectRouter, injectServerFn, injectServerFnMutation, issuePathToFieldName, issuesToFieldErrors, issuesToFormErrors, provideFileRouter, provideServerFnClient, requestContextInterceptor, routes, toRoute, withDebugRoutes, withExtraRoutes };
|
|
1375
934
|
|
|
1376
|
-
|
|
1377
|
-
//# sourceMappingURL=analogjs-router.mjs.map
|
|
935
|
+
//# sourceMappingURL=analogjs-router.mjs.map
|