@stealthscale/provider-router 0.1.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,689 +1,2 @@
1
- import { n as __reExport, t as __exportAll } from "./rolldown-runtime-BBjsoOtd.js";
2
- import { createElement } from "react";
3
- import { c } from "react/compiler-runtime";
4
- import { jsx } from "react/jsx-runtime";
5
- export * from "@tanstack/react-router";
6
- //#region src/tanstack.ts
7
- var tanstack_exports = /* @__PURE__ */ __exportAll({});
8
- import * as import__tanstack_react_router from "@tanstack/react-router";
9
- __reExport(tanstack_exports, import__tanstack_react_router);
10
- //#endregion
11
- //#region src/compile.ts
12
- /**
13
- * Compiles declarations into routes under a parent, without touching the parent.
14
- */
15
- /**
16
- * Reads the page a declaration draws with, loading it on first navigation where it is lazy.
17
- *
18
- * @param component - The page, or the importer that resolves to one.
19
- * @returns The component the route draws.
20
- */
21
- function pageOf(component) {
22
- return "load" in component ? (0, tanstack_exports.lazyRouteComponent)(component.load, component.export) : component;
23
- }
24
- /**
25
- * Draws a layout around whatever the route below it draws.
26
- *
27
- * @param drawn - The layout component the caller registered.
28
- * @param options - The options the declaration stated for this layout.
29
- * @returns A component the pathless route draws.
30
- */
31
- function framed(drawn, options) {
32
- /**
33
- * Draws the layout around the route below it.
34
- *
35
- * @returns The frame, holding the outlet.
36
- */
37
- return function Layout() {
38
- return createElement(drawn, { options }, createElement(tanstack_exports.Outlet));
39
- };
40
- }
41
- /**
42
- * Records a route as a child of another, or as one the caller places itself.
43
- *
44
- * @param building - The state this compilation has built up.
45
- * @param under - The route it hangs under.
46
- * @param route - The route being placed.
47
- */
48
- function place(building, under, route) {
49
- if (under === building.options.parent) {
50
- building.top.push(route);
51
- return;
52
- }
53
- const siblings = building.children.get(under) ?? [];
54
- siblings.push(route);
55
- building.children.set(under, siblings);
56
- }
57
- /**
58
- * Returns an id no sibling of a route has used yet.
59
- *
60
- * @param building - The state this compilation has built up.
61
- * @param under - The route the id has to be unique among the children of.
62
- * @param name - The layout's name, which the id is derived from.
63
- * @returns The id, suffixed where the plain one is already used.
64
- */
65
- function freeId(building, under, name) {
66
- const used = building.taken.get(under) ?? /* @__PURE__ */ new Set();
67
- building.taken.set(under, used);
68
- let id = `_${name}`;
69
- let next = 2;
70
- while (used.has(id)) {
71
- id = `_${name}${String(next)}`;
72
- next += 1;
73
- }
74
- used.add(id);
75
- return id;
76
- }
77
- /**
78
- * Builds the pathless routes a declaration's layouts need, reusing one already built.
79
- *
80
- * @remarks
81
- * Two declarations share a frame where they name the same layouts with the same options. A frame
82
- * is a route, so two declarations wanting different options need two of them. The key is the JSON
83
- * of the names and the options together, which no pair of different chains can produce.
84
- * @param building - The state this compilation has built up.
85
- * @param declaration - The declaration whose layouts are being built.
86
- * @param under - The route the outermost layout hangs under.
87
- * @returns The route the declaration's own route hangs under.
88
- * @throws {@link Error} Where a layout nothing provides is named, or where one a route above
89
- * already draws is named again.
90
- */
91
- function framing(building, declaration, under) {
92
- const names = [...building.applied.get(under) ?? []];
93
- let current = under;
94
- for (const name of declaration.layout ?? []) {
95
- const drawn = building.options.layouts?.[name];
96
- if (drawn === void 0) throw new Error(`The route ${declaration.id} names the layout ${name}, which is absent.`);
97
- if (names.includes(name)) throw new Error(`The route ${declaration.id} names the layout ${name}, which a route above it already draws.`);
98
- names.push(name);
99
- const key = JSON.stringify([names, declaration.layoutOptions ?? null]);
100
- const built = building.frames.get(current) ?? /* @__PURE__ */ new Map();
101
- building.frames.set(current, built);
102
- const existing = built.get(key);
103
- const above = current;
104
- if (existing === void 0) {
105
- const frame = (0, tanstack_exports.createRoute)({
106
- component: framed(drawn, declaration.layoutOptions),
107
- getParentRoute: () => above,
108
- id: freeId(building, above, name)
109
- });
110
- place(building, above, frame);
111
- built.set(key, frame);
112
- current = frame;
113
- } else current = existing;
114
- building.applied.set(current, [...names]);
115
- }
116
- return current;
117
- }
118
- /**
119
- * Builds the route one declaration compiles to.
120
- *
121
- * @param building - The state this compilation has built up.
122
- * @param declaration - The route being compiled.
123
- * @param under - The route it hangs under, frames included.
124
- * @returns The route, drawing the declaration's page under the frames it named.
125
- */
126
- function routeOf(building, declaration, under) {
127
- const { errorComponent } = building.options;
128
- const { id, navigation, when } = declaration;
129
- return (0, tanstack_exports.createRoute)({
130
- component: pageOf(declaration.component),
131
- getParentRoute: () => under,
132
- path: declaration.path,
133
- staticData: { declared: {
134
- id,
135
- ...navigation === void 0 ? {} : { navigation }
136
- } },
137
- ...errorComponent === void 0 ? {} : { errorComponent: errorComponent(declaration) },
138
- ...declaration.search === void 0 ? {} : { validateSearch: declaration.search },
139
- ...when === void 0 ? {} : { beforeLoad: gate(building, declaration, when) }
140
- });
141
- }
142
- /**
143
- * Builds the check a route runs before it is entered.
144
- *
145
- * @remarks
146
- * The evaluator is read once here rather than inside the check, so a declaration stating a
147
- * condition with no evaluator is refused while the tree is built rather than on a navigation.
148
- * @param building - The state this compilation has built up.
149
- * @param declaration - The route being compiled.
150
- * @param when - The condition the declaration stated.
151
- * @returns The check, which the route runs before it loads.
152
- * @throws {@link Error} Where no evaluator was given.
153
- */
154
- function gate(building, declaration, when) {
155
- const { evaluate } = building.options;
156
- if (evaluate === void 0) throw new Error(`The route ${declaration.id} states a condition and no evaluator was given.`);
157
- return () => {
158
- if (!evaluate(when)) throw (0, tanstack_exports.notFound)();
159
- };
160
- }
161
- /**
162
- * Compiles one declaration, and whatever it nests under, first.
163
- *
164
- * @param building - The state this compilation has built up.
165
- * @param declaration - The route being compiled.
166
- * @param seen - The ids being compiled further up this chain, which detects a cycle.
167
- * @returns The route the declaration compiled to.
168
- * @throws {@link Error} Where a parent is absent or the parents form a cycle.
169
- */
170
- function compiledFor(building, declaration, seen) {
171
- const already = building.compiled.get(declaration.id);
172
- if (already !== void 0) return already;
173
- if (seen.has(declaration.id)) throw new Error(`The route ${declaration.id} nests under itself.`);
174
- const above = declaration.parent;
175
- let under = building.options.parent;
176
- if (above !== void 0) {
177
- const owner = building.byId.get(above);
178
- if (owner === void 0) throw new Error(`The route ${declaration.id} names the parent ${above}, which is absent.`);
179
- under = compiledFor(building, owner, /* @__PURE__ */ new Set([...seen, declaration.id]));
180
- }
181
- const inside = framing(building, declaration, under);
182
- const route = routeOf(building, declaration, inside);
183
- place(building, inside, route);
184
- building.applied.set(route, building.applied.get(inside) ?? []);
185
- building.compiled.set(declaration.id, route);
186
- return route;
187
- }
188
- /**
189
- * Refuses a declaration this package cannot honour, before any of them is compiled.
190
- *
191
- * @remarks
192
- * A screen maps to a route and a route decides the whole screen, so a page drawn beside another
193
- * as a pane has no route to be. The library agrees: `Outlet` takes no name, one route matches per
194
- * level, and two outlets in one component draw the same child twice.
195
- * @param declarations - The routes to compile.
196
- * @throws {@link Error} Where one states an outlet.
197
- */
198
- function refuse(declarations) {
199
- for (const declaration of declarations) if (declaration.outlet !== void 0) throw new Error(`The route ${declaration.id} states the outlet ${declaration.outlet}. A screen is whatever its route draws, so there is no pane to draw a second page in.`);
200
- }
201
- /**
202
- * Indexes declarations by id, refusing a second one that claims an id already taken.
203
- *
204
- * @param declarations - The routes to compile.
205
- * @returns Each declaration against its id.
206
- * @throws {@link Error} Where two declarations share an id.
207
- */
208
- function indexed(declarations) {
209
- const byId = /* @__PURE__ */ new Map();
210
- for (const declaration of declarations) {
211
- if (byId.has(declaration.id)) throw new Error(`Two routes declare the id ${declaration.id}.`);
212
- byId.set(declaration.id, declaration);
213
- }
214
- return byId;
215
- }
216
- /**
217
- * Compiles declarations into routes under the parent a caller states.
218
- *
219
- * @remarks
220
- * Pure with respect to the caller. It creates routes and never mutates the parent, so a second
221
- * call returns a second set of routes sharing no object with the first. That is what keeps two
222
- * routers in one process from reading each other's tree through the library's process-wide cache.
223
- * Compile every contributor's declarations in one call. Two calls under one parent cannot see
224
- * each other's paths, and `routeMap` reports the collision once the tree is assembled.
225
- * @param declarations - The routes to compile, in any order.
226
- * @param options - The parent, and what the declarations may name.
227
- * @returns The routes to place in the parent's own `addChildren` call.
228
- * @throws {@link Error} Where two declarations share an id, where one names a parent or a layout
229
- * nothing provides, where one names a layout a route above it already draws, where parents form a
230
- * cycle, where one states a condition and no evaluator was given, or where one states an outlet.
231
- */
232
- function compileRoutes(declarations, options) {
233
- refuse(declarations);
234
- const building = {
235
- applied: /* @__PURE__ */ new Map(),
236
- byId: indexed(declarations),
237
- children: /* @__PURE__ */ new Map(),
238
- compiled: /* @__PURE__ */ new Map(),
239
- frames: /* @__PURE__ */ new Map(),
240
- options,
241
- taken: /* @__PURE__ */ new Map(),
242
- top: []
243
- };
244
- for (const declaration of declarations) compiledFor(building, declaration, /* @__PURE__ */ new Set());
245
- for (const [route, children] of building.children) route.addChildren(children);
246
- return building.top;
247
- }
248
- //#endregion
249
- //#region src/reference.ts
250
- /**
251
- * Reads the id a target names.
252
- *
253
- * @param to - A reference, or the bare id.
254
- * @returns The full id the route was declared under.
255
- */
256
- function idOf(to) {
257
- return typeof to === "string" ? to : to.id;
258
- }
259
- //#endregion
260
- //#region src/declared.ts
261
- /**
262
- * Reads the id and the menu entry a matched route carries, or nothing where it carries neither.
263
- *
264
- * @remarks
265
- * A route carries its id in `staticData`, which is where the library keeps whatever a route wants
266
- * to carry. The compiler writes it for a route built from a declaration and `namedRoute` writes
267
- * it for one written in code, so a menu, a breadcrumb or a telemetry hook reads what it needs off
268
- * the match either way. The shape is checked rather than trusted, because `staticData` is untyped
269
- * by design and a route may carry anything under the same name. The checked object itself is
270
- * returned, so every read of one route gives one reference.
271
- * @param match - A match, as `useMatches` returns one.
272
- * @returns The id and the menu entry it carries, or nothing.
273
- */
274
- function declaredOf(match) {
275
- const { staticData } = match;
276
- const data = "declared" in staticData ? staticData.declared : void 0;
277
- if (typeof data !== "object" || data === null) return void 0;
278
- if (!("id" in data) || typeof data.id !== "string") return void 0;
279
- return data;
280
- }
281
- /**
282
- * Reads the name the deepest named route the page is on goes by.
283
- *
284
- * @remarks
285
- * The deepest match rather than the first, because a named route nested under another is the page
286
- * a person is looking at. A page drawn entirely from unnamed routes returns nothing.
287
- * The selector returns the object the route carries rather than a copy of it. A route's static
288
- * data is fixed once the tree is built, so the reference is the same one until a different route
289
- * matches, and a navigation that left the page alone re-renders nothing.
290
- * @returns The id and the menu entry, or nothing where no matched route carries either.
291
- */
292
- function useDeclaredRoute() {
293
- const $ = c(2);
294
- if ($[0] !== "c34505ba38c7bb5d21152f0227a85b702acb84f4f34b78cbac48bf4ade5e9158") {
295
- for (let $i = 0; $i < 2; $i += 1) $[$i] = Symbol.for("react.memo_cache_sentinel");
296
- $[0] = "c34505ba38c7bb5d21152f0227a85b702acb84f4f34b78cbac48bf4ade5e9158";
297
- }
298
- let t0;
299
- if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
300
- t0 = { select: _temp };
301
- $[1] = t0;
302
- } else t0 = $[1];
303
- return (0, tanstack_exports.useMatches)(t0);
304
- }
305
- /**
306
- * Reads the parameters of the page being drawn, typed by the reference the caller holds.
307
- *
308
- * @remarks
309
- * A compiled route is outside the tree an application registered, so `useParams` types against a
310
- * tree the route is not in. The parameters are read off the match instead, and the reference
311
- * carries their names. This checks at run time that the page really is the route the reference
312
- * names before it makes the claim.
313
- * The selector returns the id and the parameters alone, which are strings. Structural sharing
314
- * compares them, so a navigation that changed neither re-renders nothing.
315
- * @param to - A reference to the route the calling component draws.
316
- * @returns The parameters the route's path named.
317
- * @throws {@link Error} Where the page being drawn is not the route the reference names.
318
- */
319
- function _temp(matches) {
320
- return declaredIn(matches);
321
- }
322
- function useRouteParams(to) {
323
- const $ = c(2);
324
- if ($[0] !== "c34505ba38c7bb5d21152f0227a85b702acb84f4f34b78cbac48bf4ade5e9158") {
325
- for (let $i = 0; $i < 2; $i += 1) $[$i] = Symbol.for("react.memo_cache_sentinel");
326
- $[0] = "c34505ba38c7bb5d21152f0227a85b702acb84f4f34b78cbac48bf4ade5e9158";
327
- }
328
- let t0;
329
- if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
330
- t0 = {
331
- select: _temp2,
332
- structuralSharing: true
333
- };
334
- $[1] = t0;
335
- } else t0 = $[1];
336
- const drawn = (0, tanstack_exports.useMatches)(t0);
337
- const wanted = idOf(to);
338
- if (drawn.id !== wanted) throw new Error(`The page being drawn is not ${wanted}, so its parameters are not that route's.`);
339
- return drawn.params;
340
- }
341
- /**
342
- * Reads the name the deepest matched route that carries one goes by.
343
- *
344
- * @param matches - Every matched route, outermost first.
345
- * @returns The id and the menu entry it carries, or nothing where no match carries an id.
346
- */
347
- function _temp2(matches) {
348
- return drawnIn(matches);
349
- }
350
- function declaredIn(matches) {
351
- let deepest;
352
- for (const match of matches) {
353
- const declared = declaredOf(match);
354
- if (declared !== void 0) deepest = declared;
355
- }
356
- return deepest;
357
- }
358
- /**
359
- * Reads the id and the parameters of the deepest matched route that carries an id.
360
- *
361
- * @param matches - Every matched route, outermost first.
362
- * @returns The id and the parameters, with no id where none of them carries one.
363
- */
364
- function drawnIn(matches) {
365
- let deepest = { params: {} };
366
- for (const match of matches) {
367
- const declared = declaredOf(match);
368
- if (declared !== void 0) deepest = {
369
- id: declared.id,
370
- params: match.params
371
- };
372
- }
373
- return deepest;
374
- }
375
- //#endregion
376
- //#region src/defaults.ts
377
- /**
378
- * How a router in this design system behaves before an application says otherwise.
379
- */
380
- /**
381
- * The options every application's router starts from, spread before its own.
382
- *
383
- * @remarks
384
- * A route preloads on intent, which is when the pointer rests on a link or the link takes focus,
385
- * so a page is usually loaded before it is asked for.
386
- * A preloaded route never counts as fresh on its own. The query client decides freshness for
387
- * everything it loads, and a router keeping its own staleness would serve a copy the client had
388
- * already replaced.
389
- * Scroll position is restored on the way back, because a person returning to a list expects to be
390
- * where they left it rather than at the top.
391
- */
392
- const routerDefaults = {
393
- defaultPreload: "intent",
394
- defaultPreloadStaleTime: 0,
395
- scrollRestoration: true
396
- };
397
- //#endregion
398
- //#region src/map.ts
399
- /**
400
- * Gives a route written in code the id everything else links to it by.
401
- *
402
- * @remarks
403
- * A route carries its id in `staticData`, which is where the compiler writes the id of a route
404
- * built from a declaration. One mechanism names both, so a link does not need to know which of
405
- * the two it is pointing at.
406
- * @param id - The id to name the route under.
407
- * @returns The static data to spread into `createRoute`.
408
- */
409
- function namedRoute(id) {
410
- return { staticData: { declared: { id } } };
411
- }
412
- /**
413
- * Reads every id a tree names, against the route that draws it.
414
- *
415
- * @remarks
416
- * Derived from the tree rather than collected beside it, so a route written in code and a route
417
- * built from a declaration reach the map the same way. The walk also reports two routes that
418
- * serve one URL, which a development build reports as a duplicate route and a production build
419
- * resolves by keeping the first and dropping the rest in silence.
420
- * @param tree - The assembled tree, as `createRouter` takes it.
421
- * @returns Every id, against its route.
422
- * @throws {@link Error} Where two routes carry one id, or where two serve one path under a shared
423
- * parent.
424
- */
425
- function routeMap(tree) {
426
- const named = /* @__PURE__ */ new Map();
427
- collect(tree, named);
428
- return named;
429
- }
430
- /**
431
- * Walks a route's descendants, naming each one and refusing a repeated path.
432
- *
433
- * @param route - The route whose children are read.
434
- * @param named - The map built so far.
435
- * @throws {@link Error} Where two routes carry one id, or where two serve one path here.
436
- */
437
- function collect(route, named) {
438
- const claimed = /* @__PURE__ */ new Set();
439
- for (const path of pathsUnder(route)) {
440
- if (claimed.has(path)) throw new Error(`Two routes serve the path ${path} under the same parent.`);
441
- claimed.add(path);
442
- }
443
- for (const child of childrenOf(route)) {
444
- identify(child, named);
445
- collect(child, named);
446
- }
447
- }
448
- /**
449
- * Records the id a route carries, where it carries one.
450
- *
451
- * @param route - The route to read.
452
- * @param named - The map built so far.
453
- * @throws {@link Error} Where another route already carries the same id.
454
- */
455
- function identify(route, named) {
456
- const options = route.options;
457
- const data = "staticData" in options ? options.staticData : void 0;
458
- const declared = typeof data === "object" && data !== null ? declaredOf({ staticData: data }) : void 0;
459
- if (declared === void 0) return;
460
- if (named.has(declared.id)) throw new Error(`Two routes are named ${declared.id}.`);
461
- named.set(declared.id, route);
462
- }
463
- /**
464
- * Writes a path the one way the library reads it: the slashes around it trimmed, and one leading
465
- * slash put back.
466
- *
467
- * @remarks
468
- * `home`, `/home` and `home/` are one route to the library, so the check reads all three as
469
- * `/home`.
470
- */
471
- function normalised(path) {
472
- const trimmed = (0, tanstack_exports.trimPath)(path);
473
- return trimmed === "/" ? trimmed : `/${trimmed}`;
474
- }
475
- /**
476
- * Lists the paths a route's descendants serve at its own level, each written the one way the
477
- * library reads it.
478
- *
479
- * @remarks
480
- * A pathless route consumes no segment of a URL, so whatever sits below one is served at the
481
- * level of the route above it. The walk goes through a pathless route rather than stopping at
482
- * it.
483
- * @param route - The route whose level is being read.
484
- * @returns One path per descendant served at this level.
485
- */
486
- function pathsUnder(route) {
487
- const paths = [];
488
- for (const child of childrenOf(route)) {
489
- const options = child.options;
490
- const path = "path" in options ? options.path : void 0;
491
- if (typeof path === "string") paths.push(normalised(path));
492
- else paths.push(...pathsUnder(child));
493
- }
494
- return paths;
495
- }
496
- /**
497
- * Reads the children a route holds.
498
- *
499
- * @remarks
500
- * The library types a route's children as `any`, because a typed tree names each one. Nothing
501
- * here reads more than the options every route carries.
502
- * @param route - The route to read.
503
- * @returns Its children, or none where it holds none.
504
- */
505
- function childrenOf(route) {
506
- return route.children ?? [];
507
- }
508
- //#endregion
509
- //#region src/options.ts
510
- /**
511
- * Collects what every router in this design system starts from, as an object a caller spreads.
512
- */
513
- /**
514
- * Collects the options every router in this design system starts from.
515
- *
516
- * @remarks
517
- * An object to spread rather than a factory that calls `createRouter`. The library states
518
- * forty-eight router options, and a factory would expose the few it thought of and hide the rest.
519
- * Spreading leaves every one of them the caller's to set, the four stated here included.
520
- * @param context - The context the router hands a loader, holding the route map where a caller compiled
521
- * declarations.
522
- * @returns The options, to spread into `createRouter` before the caller's own.
523
- */
524
- function routerOptions(context) {
525
- return {
526
- ...routerDefaults,
527
- context
528
- };
529
- }
530
- //#endregion
531
- //#region src/href.ts
532
- /**
533
- * Resolves a declared id to a path, with the parameters the path names filled in.
534
- *
535
- * @remarks
536
- * Throwing is deliberate in all three cases. Interpolation otherwise returns a path with a
537
- * literal `$id` still in it, and a route the library has not worked a full path out for yet
538
- * returns the site root. A link that navigates somewhere wrong is worse than one that fails where
539
- * somebody wrote it.
540
- * @param map - The map every route is named in.
541
- * @param to - A reference to the route, or the bare id one carries.
542
- * @param params - The parameters the path names, typed by the reference where one was given.
543
- * @returns The path, ready to navigate to.
544
- * @throws {@link Error} Where the map holds no such id, where no router has processed the tree the
545
- * route was placed in, or where a parameter the path names is missing.
546
- */
547
- function routeHref(map, to, params) {
548
- const id = idOf(to);
549
- const route = map.get(id);
550
- if (route === void 0) throw new Error(`No route is declared with the id ${id}.`);
551
- if (route.fullPath === void 0) throw new Error(`The route ${id} has no path yet, because no router has processed the tree it was placed in.`);
552
- const { interpolatedPath, isMissingParams } = (0, tanstack_exports.interpolatePath)({
553
- params: params ?? {},
554
- path: route.fullPath
555
- });
556
- if (isMissingParams) throw new Error(`The route ${id} names a parameter that was not given.`);
557
- return interpolatedPath;
558
- }
559
- /**
560
- * Reads the map every route is named in, from the router's own context.
561
- *
562
- * @remarks
563
- * The map reaches a component through the router's own context rather than a provider of this
564
- * package's own, so an application mounts nothing extra to make a link by id work.
565
- * Take the map rather than a resolved path where the route is chosen after the render: a hook
566
- * cannot run inside an event handler, and `routeHref` can.
567
- * @returns Every id the router knows, against the route that serves it.
568
- * @throws {@link Error} Where the router was built without one.
569
- */
570
- function useRouteMap() {
571
- const $ = c(2);
572
- if ($[0] !== "f9b02b582b5a25eab6d75eb5816b5bc3afae5d65206cbae9cdf2983138656269") {
573
- for (let $i = 0; $i < 2; $i += 1) $[$i] = Symbol.for("react.memo_cache_sentinel");
574
- $[0] = "f9b02b582b5a25eab6d75eb5816b5bc3afae5d65206cbae9cdf2983138656269";
575
- }
576
- let t0;
577
- if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
578
- t0 = { strict: false };
579
- $[1] = t0;
580
- } else t0 = $[1];
581
- const context = (0, tanstack_exports.useRouteContext)(t0);
582
- if (context.routes === void 0) throw new Error("The router context holds no route map, so no id can be resolved. Pass one to routerOptions.");
583
- return context.routes;
584
- }
585
- /**
586
- * Resolves a reference to a path, through the map the router context holds.
587
- *
588
- * @remarks
589
- * A hook, so the route has to be known while the component renders. Use `useRouteMap` where the
590
- * route is chosen later, such as in the handler of a row a person clicked.
591
- * @param to - A reference to the route, or the bare id one carries.
592
- * @param params - The parameters the path names, typed by the reference where one was given.
593
- * @returns The path, ready to navigate to.
594
- * @throws {@link Error} Where no map is in the router context, where it holds no such id, or where
595
- * a parameter the path names is missing.
596
- */
597
- function useRouteHref(to, params) {
598
- const $ = c(5);
599
- if ($[0] !== "f9b02b582b5a25eab6d75eb5816b5bc3afae5d65206cbae9cdf2983138656269") {
600
- for (let $i = 0; $i < 5; $i += 1) $[$i] = Symbol.for("react.memo_cache_sentinel");
601
- $[0] = "f9b02b582b5a25eab6d75eb5816b5bc3afae5d65206cbae9cdf2983138656269";
602
- }
603
- const t0 = useRouteMap();
604
- let t1;
605
- if ($[1] !== params || $[2] !== t0 || $[3] !== to) {
606
- t1 = routeHref(t0, to, params);
607
- $[1] = params;
608
- $[2] = t0;
609
- $[3] = to;
610
- $[4] = t1;
611
- } else t1 = $[4];
612
- return t1;
613
- }
614
- //#endregion
615
- //#region src/link.tsx
616
- /**
617
- * Links to a route by the id a manifest declared it under.
618
- *
619
- * @remarks
620
- * A declared route is outside the tree an application registered, so `Link` refuses its path at
621
- * compile time. This resolves the id at run time and hands the library a plain string, which is
622
- * the one place in this package where a path is not checked by the compiler.
623
- * @param props - The declared id, its parameters, and whatever else the library's `Link` takes.
624
- * @returns An anchor to the resolved path.
625
- */
626
- function RouteLink(t0) {
627
- const $ = c(8);
628
- if ($[0] !== "3b765330fa72187c6e8334d53589d37c8de26d61a15e49011148486e2debe539") {
629
- for (let $i = 0; $i < 8; $i += 1) $[$i] = Symbol.for("react.memo_cache_sentinel");
630
- $[0] = "3b765330fa72187c6e8334d53589d37c8de26d61a15e49011148486e2debe539";
631
- }
632
- let params;
633
- let rest;
634
- let to;
635
- if ($[1] !== t0) {
636
- ({params, to, ...rest} = t0);
637
- $[1] = t0;
638
- $[2] = params;
639
- $[3] = rest;
640
- $[4] = to;
641
- } else {
642
- params = $[2];
643
- rest = $[3];
644
- to = $[4];
645
- }
646
- const t1 = useRouteHref(to, params);
647
- let t2;
648
- if ($[5] !== rest || $[6] !== t1) {
649
- t2 = /* @__PURE__ */ jsx(tanstack_exports.Link, {
650
- ...rest,
651
- to: t1
652
- });
653
- $[5] = rest;
654
- $[6] = t1;
655
- $[7] = t2;
656
- } else t2 = $[7];
657
- return t2;
658
- }
659
- //#endregion
660
- //#region src/root.ts
661
- /**
662
- * Builds a root route whose context holds whatever the application states and the route map.
663
- *
664
- * @remarks
665
- * Calling the library's `createRootRoute` instead leaves the context typed as empty, and the
666
- * first sign of it is `createRouter` refusing the options `routerOptions` returned. The error
667
- * then names the router rather than the root, which is the file that has to change.
668
- * @returns The root route factory, to call with the route's own options.
669
- */
670
- function createAppRootRoute() {
671
- return (0, tanstack_exports.createRootRouteWithContext)();
672
- }
673
- __reExport(/* @__PURE__ */ __exportAll({
674
- RouteLink: () => RouteLink,
675
- compileRoutes: () => compileRoutes,
676
- createAppRootRoute: () => createAppRootRoute,
677
- declaredOf: () => declaredOf,
678
- namedRoute: () => namedRoute,
679
- routeHref: () => routeHref,
680
- routeMap: () => routeMap,
681
- routerDefaults: () => routerDefaults,
682
- routerOptions: () => routerOptions,
683
- useDeclaredRoute: () => useDeclaredRoute,
684
- useRouteHref: () => useRouteHref,
685
- useRouteMap: () => useRouteMap,
686
- useRouteParams: () => useRouteParams
687
- }), tanstack_exports);
688
- //#endregion
689
- export { RouteLink, compileRoutes, createAppRootRoute, declaredOf, namedRoute, routeHref, routeMap, routerDefaults, routerOptions, useDeclaredRoute, useRouteHref, useRouteMap, useRouteParams };
1
+ import { A as routerDefaults, C as routerOptions, D as routeHref, E as RouteLink, F as compileRoutes, I as basepathOf, M as useDeclaredRoute, N as useRouteParams, O as useRouteHref, P as useRouteSearch, S as createAppRootRoute, T as routeMap, _ as useMatches, a as createLink, b as useRouter, c as createRoute, d as isRedirect, f as notFound, g as useLocation, h as useLinkProps, i as RouterProvider, j as declaredOf, k as useRouteMap, l as createRouter, m as useChildMatches, n as Outlet, o as createMemoryHistory, p as redirect, r as RouterContextProvider, s as createRootRoute, t as Navigate, u as isNotFound, v as useNavigate, w as namedRoute, x as useRouterState, y as useRouteContext } from "./shared-D7o15Y7B.js";
2
+ export { Navigate, Outlet, RouteLink, RouterContextProvider, RouterProvider, basepathOf, compileRoutes, createAppRootRoute, createLink, createMemoryHistory, createRootRoute, createRoute, createRouter, declaredOf, isNotFound, isRedirect, namedRoute, notFound, redirect, routeHref, routeMap, routerDefaults, routerOptions, useChildMatches, useDeclaredRoute, useLinkProps, useLocation, useMatches, useNavigate, useRouteContext, useRouteHref, useRouteMap, useRouteParams, useRouteSearch, useRouter, useRouterState };