@simpleview/cms-foundation 0.0.20 → 0.0.21

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.
@@ -1,2451 +0,0 @@
1
- // node_modules/react-router/dist/development/chunk-EF7DTUVF.mjs
2
- import * as React from "react";
3
- import * as React2 from "react";
4
- import * as React3 from "react";
5
- import * as React4 from "react";
6
- import * as React9 from "react";
7
- import * as React8 from "react";
8
- import * as React7 from "react";
9
- import * as React6 from "react";
10
- import * as React5 from "react";
11
- import * as React10 from "react";
12
- import * as React11 from "react";
13
- function invariant(value, message) {
14
- if (value === false || value === null || typeof value === "undefined") {
15
- throw new Error(message);
16
- }
17
- }
18
- function warning(cond, message) {
19
- if (!cond) {
20
- if (typeof console !== "undefined") console.warn(message);
21
- try {
22
- throw new Error(message);
23
- } catch (e) {
24
- }
25
- }
26
- }
27
- function createPath({
28
- pathname = "/",
29
- search = "",
30
- hash = ""
31
- }) {
32
- if (search && search !== "?")
33
- pathname += search.charAt(0) === "?" ? search : "?" + search;
34
- if (hash && hash !== "#")
35
- pathname += hash.charAt(0) === "#" ? hash : "#" + hash;
36
- return pathname;
37
- }
38
- function parsePath(path) {
39
- let parsedPath = {};
40
- if (path) {
41
- let hashIndex = path.indexOf("#");
42
- if (hashIndex >= 0) {
43
- parsedPath.hash = path.substring(hashIndex);
44
- path = path.substring(0, hashIndex);
45
- }
46
- let searchIndex = path.indexOf("?");
47
- if (searchIndex >= 0) {
48
- parsedPath.search = path.substring(searchIndex);
49
- path = path.substring(0, searchIndex);
50
- }
51
- if (path) {
52
- parsedPath.pathname = path;
53
- }
54
- }
55
- return parsedPath;
56
- }
57
- var _map;
58
- _map = /* @__PURE__ */ new WeakMap();
59
- function matchRoutes(routes, locationArg, basename = "/") {
60
- return matchRoutesImpl(routes, locationArg, basename, false);
61
- }
62
- function matchRoutesImpl(routes, locationArg, basename, allowPartial) {
63
- let location = typeof locationArg === "string" ? parsePath(locationArg) : locationArg;
64
- let pathname = stripBasename(location.pathname || "/", basename);
65
- if (pathname == null) {
66
- return null;
67
- }
68
- let branches = flattenRoutes(routes);
69
- rankRouteBranches(branches);
70
- let matches = null;
71
- for (let i = 0; matches == null && i < branches.length; ++i) {
72
- let decoded = decodePath(pathname);
73
- matches = matchRouteBranch(
74
- branches[i],
75
- decoded,
76
- allowPartial
77
- );
78
- }
79
- return matches;
80
- }
81
- function convertRouteMatchToUiMatch(match, loaderData) {
82
- let { route, pathname, params } = match;
83
- return {
84
- id: route.id,
85
- pathname,
86
- params,
87
- data: loaderData[route.id],
88
- handle: route.handle
89
- };
90
- }
91
- function flattenRoutes(routes, branches = [], parentsMeta = [], parentPath = "") {
92
- let flattenRoute = (route, index, relativePath) => {
93
- let meta = {
94
- relativePath: relativePath === void 0 ? route.path || "" : relativePath,
95
- caseSensitive: route.caseSensitive === true,
96
- childrenIndex: index,
97
- route
98
- };
99
- if (meta.relativePath.startsWith("/")) {
100
- invariant(
101
- meta.relativePath.startsWith(parentPath),
102
- `Absolute route path "${meta.relativePath}" nested under path "${parentPath}" is not valid. An absolute child route path must start with the combined path of all its parent routes.`
103
- );
104
- meta.relativePath = meta.relativePath.slice(parentPath.length);
105
- }
106
- let path = joinPaths([parentPath, meta.relativePath]);
107
- let routesMeta = parentsMeta.concat(meta);
108
- if (route.children && route.children.length > 0) {
109
- invariant(
110
- // Our types know better, but runtime JS may not!
111
- // @ts-expect-error
112
- route.index !== true,
113
- `Index routes must not have child routes. Please remove all child routes from route path "${path}".`
114
- );
115
- flattenRoutes(route.children, branches, routesMeta, path);
116
- }
117
- if (route.path == null && !route.index) {
118
- return;
119
- }
120
- branches.push({
121
- path,
122
- score: computeScore(path, route.index),
123
- routesMeta
124
- });
125
- };
126
- routes.forEach((route, index) => {
127
- if (route.path === "" || !route.path?.includes("?")) {
128
- flattenRoute(route, index);
129
- } else {
130
- for (let exploded of explodeOptionalSegments(route.path)) {
131
- flattenRoute(route, index, exploded);
132
- }
133
- }
134
- });
135
- return branches;
136
- }
137
- function explodeOptionalSegments(path) {
138
- let segments = path.split("/");
139
- if (segments.length === 0) return [];
140
- let [first, ...rest] = segments;
141
- let isOptional = first.endsWith("?");
142
- let required = first.replace(/\?$/, "");
143
- if (rest.length === 0) {
144
- return isOptional ? [required, ""] : [required];
145
- }
146
- let restExploded = explodeOptionalSegments(rest.join("/"));
147
- let result = [];
148
- result.push(
149
- ...restExploded.map(
150
- (subpath) => subpath === "" ? required : [required, subpath].join("/")
151
- )
152
- );
153
- if (isOptional) {
154
- result.push(...restExploded);
155
- }
156
- return result.map(
157
- (exploded) => path.startsWith("/") && exploded === "" ? "/" : exploded
158
- );
159
- }
160
- function rankRouteBranches(branches) {
161
- branches.sort(
162
- (a, b) => a.score !== b.score ? b.score - a.score : compareIndexes(
163
- a.routesMeta.map((meta) => meta.childrenIndex),
164
- b.routesMeta.map((meta) => meta.childrenIndex)
165
- )
166
- );
167
- }
168
- var paramRe = /^:[\w-]+$/;
169
- var dynamicSegmentValue = 3;
170
- var indexRouteValue = 2;
171
- var emptySegmentValue = 1;
172
- var staticSegmentValue = 10;
173
- var splatPenalty = -2;
174
- var isSplat = (s) => s === "*";
175
- function computeScore(path, index) {
176
- let segments = path.split("/");
177
- let initialScore = segments.length;
178
- if (segments.some(isSplat)) {
179
- initialScore += splatPenalty;
180
- }
181
- if (index) {
182
- initialScore += indexRouteValue;
183
- }
184
- return segments.filter((s) => !isSplat(s)).reduce(
185
- (score, segment) => score + (paramRe.test(segment) ? dynamicSegmentValue : segment === "" ? emptySegmentValue : staticSegmentValue),
186
- initialScore
187
- );
188
- }
189
- function compareIndexes(a, b) {
190
- let siblings = a.length === b.length && a.slice(0, -1).every((n, i) => n === b[i]);
191
- return siblings ? (
192
- // If two routes are siblings, we should try to match the earlier sibling
193
- // first. This allows people to have fine-grained control over the matching
194
- // behavior by simply putting routes with identical paths in the order they
195
- // want them tried.
196
- a[a.length - 1] - b[b.length - 1]
197
- ) : (
198
- // Otherwise, it doesn't really make sense to rank non-siblings by index,
199
- // so they sort equally.
200
- 0
201
- );
202
- }
203
- function matchRouteBranch(branch, pathname, allowPartial = false) {
204
- let { routesMeta } = branch;
205
- let matchedParams = {};
206
- let matchedPathname = "/";
207
- let matches = [];
208
- for (let i = 0; i < routesMeta.length; ++i) {
209
- let meta = routesMeta[i];
210
- let end = i === routesMeta.length - 1;
211
- let remainingPathname = matchedPathname === "/" ? pathname : pathname.slice(matchedPathname.length) || "/";
212
- let match = matchPath(
213
- { path: meta.relativePath, caseSensitive: meta.caseSensitive, end },
214
- remainingPathname
215
- );
216
- let route = meta.route;
217
- if (!match && end && allowPartial && !routesMeta[routesMeta.length - 1].route.index) {
218
- match = matchPath(
219
- {
220
- path: meta.relativePath,
221
- caseSensitive: meta.caseSensitive,
222
- end: false
223
- },
224
- remainingPathname
225
- );
226
- }
227
- if (!match) {
228
- return null;
229
- }
230
- Object.assign(matchedParams, match.params);
231
- matches.push({
232
- // TODO: Can this as be avoided?
233
- params: matchedParams,
234
- pathname: joinPaths([matchedPathname, match.pathname]),
235
- pathnameBase: normalizePathname(
236
- joinPaths([matchedPathname, match.pathnameBase])
237
- ),
238
- route
239
- });
240
- if (match.pathnameBase !== "/") {
241
- matchedPathname = joinPaths([matchedPathname, match.pathnameBase]);
242
- }
243
- }
244
- return matches;
245
- }
246
- function matchPath(pattern, pathname) {
247
- if (typeof pattern === "string") {
248
- pattern = { path: pattern, caseSensitive: false, end: true };
249
- }
250
- let [matcher, compiledParams] = compilePath(
251
- pattern.path,
252
- pattern.caseSensitive,
253
- pattern.end
254
- );
255
- let match = pathname.match(matcher);
256
- if (!match) return null;
257
- let matchedPathname = match[0];
258
- let pathnameBase = matchedPathname.replace(/(.)\/+$/, "$1");
259
- let captureGroups = match.slice(1);
260
- let params = compiledParams.reduce(
261
- (memo2, { paramName, isOptional }, index) => {
262
- if (paramName === "*") {
263
- let splatValue = captureGroups[index] || "";
264
- pathnameBase = matchedPathname.slice(0, matchedPathname.length - splatValue.length).replace(/(.)\/+$/, "$1");
265
- }
266
- const value = captureGroups[index];
267
- if (isOptional && !value) {
268
- memo2[paramName] = void 0;
269
- } else {
270
- memo2[paramName] = (value || "").replace(/%2F/g, "/");
271
- }
272
- return memo2;
273
- },
274
- {}
275
- );
276
- return {
277
- params,
278
- pathname: matchedPathname,
279
- pathnameBase,
280
- pattern
281
- };
282
- }
283
- function compilePath(path, caseSensitive = false, end = true) {
284
- warning(
285
- path === "*" || !path.endsWith("*") || path.endsWith("/*"),
286
- `Route path "${path}" will be treated as if it were "${path.replace(/\*$/, "/*")}" because the \`*\` character must always follow a \`/\` in the pattern. To get rid of this warning, please change the route path to "${path.replace(/\*$/, "/*")}".`
287
- );
288
- let params = [];
289
- let regexpSource = "^" + path.replace(/\/*\*?$/, "").replace(/^\/*/, "/").replace(/[\\.*+^${}|()[\]]/g, "\\$&").replace(
290
- /\/:([\w-]+)(\?)?/g,
291
- (_, paramName, isOptional) => {
292
- params.push({ paramName, isOptional: isOptional != null });
293
- return isOptional ? "/?([^\\/]+)?" : "/([^\\/]+)";
294
- }
295
- );
296
- if (path.endsWith("*")) {
297
- params.push({ paramName: "*" });
298
- regexpSource += path === "*" || path === "/*" ? "(.*)$" : "(?:\\/(.+)|\\/*)$";
299
- } else if (end) {
300
- regexpSource += "\\/*$";
301
- } else if (path !== "" && path !== "/") {
302
- regexpSource += "(?:(?=\\/|$))";
303
- } else {
304
- }
305
- let matcher = new RegExp(regexpSource, caseSensitive ? void 0 : "i");
306
- return [matcher, params];
307
- }
308
- function decodePath(value) {
309
- try {
310
- return value.split("/").map((v) => decodeURIComponent(v).replace(/\//g, "%2F")).join("/");
311
- } catch (error) {
312
- warning(
313
- false,
314
- `The URL path "${value}" could not be decoded because it is a malformed URL segment. This is probably due to a bad percent encoding (${error}).`
315
- );
316
- return value;
317
- }
318
- }
319
- function stripBasename(pathname, basename) {
320
- if (basename === "/") return pathname;
321
- if (!pathname.toLowerCase().startsWith(basename.toLowerCase())) {
322
- return null;
323
- }
324
- let startIndex = basename.endsWith("/") ? basename.length - 1 : basename.length;
325
- let nextChar = pathname.charAt(startIndex);
326
- if (nextChar && nextChar !== "/") {
327
- return null;
328
- }
329
- return pathname.slice(startIndex) || "/";
330
- }
331
- function resolvePath(to, fromPathname = "/") {
332
- let {
333
- pathname: toPathname,
334
- search = "",
335
- hash = ""
336
- } = typeof to === "string" ? parsePath(to) : to;
337
- let pathname = toPathname ? toPathname.startsWith("/") ? toPathname : resolvePathname(toPathname, fromPathname) : fromPathname;
338
- return {
339
- pathname,
340
- search: normalizeSearch(search),
341
- hash: normalizeHash(hash)
342
- };
343
- }
344
- function resolvePathname(relativePath, fromPathname) {
345
- let segments = fromPathname.replace(/\/+$/, "").split("/");
346
- let relativeSegments = relativePath.split("/");
347
- relativeSegments.forEach((segment) => {
348
- if (segment === "..") {
349
- if (segments.length > 1) segments.pop();
350
- } else if (segment !== ".") {
351
- segments.push(segment);
352
- }
353
- });
354
- return segments.length > 1 ? segments.join("/") : "/";
355
- }
356
- function getInvalidPathError(char, field, dest, path) {
357
- return `Cannot include a '${char}' character in a manually specified \`to.${field}\` field [${JSON.stringify(
358
- path
359
- )}]. Please separate it out to the \`to.${dest}\` field. Alternatively you may provide the full path as a string in <Link to="..."> and the router will parse it for you.`;
360
- }
361
- function getPathContributingMatches(matches) {
362
- return matches.filter(
363
- (match, index) => index === 0 || match.route.path && match.route.path.length > 0
364
- );
365
- }
366
- function getResolveToMatches(matches) {
367
- let pathMatches = getPathContributingMatches(matches);
368
- return pathMatches.map(
369
- (match, idx) => idx === pathMatches.length - 1 ? match.pathname : match.pathnameBase
370
- );
371
- }
372
- function resolveTo(toArg, routePathnames, locationPathname, isPathRelative = false) {
373
- let to;
374
- if (typeof toArg === "string") {
375
- to = parsePath(toArg);
376
- } else {
377
- to = { ...toArg };
378
- invariant(
379
- !to.pathname || !to.pathname.includes("?"),
380
- getInvalidPathError("?", "pathname", "search", to)
381
- );
382
- invariant(
383
- !to.pathname || !to.pathname.includes("#"),
384
- getInvalidPathError("#", "pathname", "hash", to)
385
- );
386
- invariant(
387
- !to.search || !to.search.includes("#"),
388
- getInvalidPathError("#", "search", "hash", to)
389
- );
390
- }
391
- let isEmptyPath = toArg === "" || to.pathname === "";
392
- let toPathname = isEmptyPath ? "/" : to.pathname;
393
- let from;
394
- if (toPathname == null) {
395
- from = locationPathname;
396
- } else {
397
- let routePathnameIndex = routePathnames.length - 1;
398
- if (!isPathRelative && toPathname.startsWith("..")) {
399
- let toSegments = toPathname.split("/");
400
- while (toSegments[0] === "..") {
401
- toSegments.shift();
402
- routePathnameIndex -= 1;
403
- }
404
- to.pathname = toSegments.join("/");
405
- }
406
- from = routePathnameIndex >= 0 ? routePathnames[routePathnameIndex] : "/";
407
- }
408
- let path = resolvePath(to, from);
409
- let hasExplicitTrailingSlash = toPathname && toPathname !== "/" && toPathname.endsWith("/");
410
- let hasCurrentTrailingSlash = (isEmptyPath || toPathname === ".") && locationPathname.endsWith("/");
411
- if (!path.pathname.endsWith("/") && (hasExplicitTrailingSlash || hasCurrentTrailingSlash)) {
412
- path.pathname += "/";
413
- }
414
- return path;
415
- }
416
- var joinPaths = (paths) => paths.join("/").replace(/\/\/+/g, "/");
417
- var normalizePathname = (pathname) => pathname.replace(/\/+$/, "").replace(/^\/*/, "/");
418
- var normalizeSearch = (search) => !search || search === "?" ? "" : search.startsWith("?") ? search : "?" + search;
419
- var normalizeHash = (hash) => !hash || hash === "#" ? "" : hash.startsWith("#") ? hash : "#" + hash;
420
- function isRouteErrorResponse(error) {
421
- return error != null && typeof error.status === "number" && typeof error.statusText === "string" && typeof error.internal === "boolean" && "data" in error;
422
- }
423
- var validMutationMethodsArr = [
424
- "POST",
425
- "PUT",
426
- "PATCH",
427
- "DELETE"
428
- ];
429
- var validMutationMethods = new Set(
430
- validMutationMethodsArr
431
- );
432
- var validRequestMethodsArr = [
433
- "GET",
434
- ...validMutationMethodsArr
435
- ];
436
- var validRequestMethods = new Set(validRequestMethodsArr);
437
- var ResetLoaderDataSymbol = Symbol("ResetLoaderData");
438
- var DataRouterContext = React.createContext(null);
439
- DataRouterContext.displayName = "DataRouter";
440
- var DataRouterStateContext = React.createContext(null);
441
- DataRouterStateContext.displayName = "DataRouterState";
442
- var RSCRouterContext = React.createContext(false);
443
- function useIsRSCRouterContext() {
444
- return React.useContext(RSCRouterContext);
445
- }
446
- var ViewTransitionContext = React.createContext({
447
- isTransitioning: false
448
- });
449
- ViewTransitionContext.displayName = "ViewTransition";
450
- var FetchersContext = React.createContext(
451
- /* @__PURE__ */ new Map()
452
- );
453
- FetchersContext.displayName = "Fetchers";
454
- var AwaitContext = React.createContext(null);
455
- AwaitContext.displayName = "Await";
456
- var NavigationContext = React.createContext(
457
- null
458
- );
459
- NavigationContext.displayName = "Navigation";
460
- var LocationContext = React.createContext(
461
- null
462
- );
463
- LocationContext.displayName = "Location";
464
- var RouteContext = React.createContext({
465
- outlet: null,
466
- matches: [],
467
- isDataRoute: false
468
- });
469
- RouteContext.displayName = "Route";
470
- var RouteErrorContext = React.createContext(null);
471
- RouteErrorContext.displayName = "RouteError";
472
- var ENABLE_DEV_WARNINGS = true;
473
- function useHref(to, { relative } = {}) {
474
- invariant(
475
- useInRouterContext(),
476
- // TODO: This error is probably because they somehow have 2 versions of the
477
- // router loaded. We can help them understand how to avoid that.
478
- `useHref() may be used only in the context of a <Router> component.`
479
- );
480
- let { basename, navigator } = React2.useContext(NavigationContext);
481
- let { hash, pathname, search } = useResolvedPath(to, { relative });
482
- let joinedPathname = pathname;
483
- if (basename !== "/") {
484
- joinedPathname = pathname === "/" ? basename : joinPaths([basename, pathname]);
485
- }
486
- return navigator.createHref({ pathname: joinedPathname, search, hash });
487
- }
488
- function useInRouterContext() {
489
- return React2.useContext(LocationContext) != null;
490
- }
491
- function useLocation() {
492
- invariant(
493
- useInRouterContext(),
494
- // TODO: This error is probably because they somehow have 2 versions of the
495
- // router loaded. We can help them understand how to avoid that.
496
- `useLocation() may be used only in the context of a <Router> component.`
497
- );
498
- return React2.useContext(LocationContext).location;
499
- }
500
- var navigateEffectWarning = `You should call navigate() in a React.useEffect(), not when your component is first rendered.`;
501
- function useIsomorphicLayoutEffect(cb) {
502
- let isStatic = React2.useContext(NavigationContext).static;
503
- if (!isStatic) {
504
- React2.useLayoutEffect(cb);
505
- }
506
- }
507
- function useNavigate() {
508
- let { isDataRoute } = React2.useContext(RouteContext);
509
- return isDataRoute ? useNavigateStable() : useNavigateUnstable();
510
- }
511
- function useNavigateUnstable() {
512
- invariant(
513
- useInRouterContext(),
514
- // TODO: This error is probably because they somehow have 2 versions of the
515
- // router loaded. We can help them understand how to avoid that.
516
- `useNavigate() may be used only in the context of a <Router> component.`
517
- );
518
- let dataRouterContext = React2.useContext(DataRouterContext);
519
- let { basename, navigator } = React2.useContext(NavigationContext);
520
- let { matches } = React2.useContext(RouteContext);
521
- let { pathname: locationPathname } = useLocation();
522
- let routePathnamesJson = JSON.stringify(getResolveToMatches(matches));
523
- let activeRef = React2.useRef(false);
524
- useIsomorphicLayoutEffect(() => {
525
- activeRef.current = true;
526
- });
527
- let navigate = React2.useCallback(
528
- (to, options = {}) => {
529
- warning(activeRef.current, navigateEffectWarning);
530
- if (!activeRef.current) return;
531
- if (typeof to === "number") {
532
- navigator.go(to);
533
- return;
534
- }
535
- let path = resolveTo(
536
- to,
537
- JSON.parse(routePathnamesJson),
538
- locationPathname,
539
- options.relative === "path"
540
- );
541
- if (dataRouterContext == null && basename !== "/") {
542
- path.pathname = path.pathname === "/" ? basename : joinPaths([basename, path.pathname]);
543
- }
544
- (!!options.replace ? navigator.replace : navigator.push)(
545
- path,
546
- options.state,
547
- options
548
- );
549
- },
550
- [
551
- basename,
552
- navigator,
553
- routePathnamesJson,
554
- locationPathname,
555
- dataRouterContext
556
- ]
557
- );
558
- return navigate;
559
- }
560
- var OutletContext = React2.createContext(null);
561
- function useOutlet(context) {
562
- let outlet = React2.useContext(RouteContext).outlet;
563
- if (outlet) {
564
- return /* @__PURE__ */ React2.createElement(OutletContext.Provider, { value: context }, outlet);
565
- }
566
- return outlet;
567
- }
568
- function useResolvedPath(to, { relative } = {}) {
569
- let { matches } = React2.useContext(RouteContext);
570
- let { pathname: locationPathname } = useLocation();
571
- let routePathnamesJson = JSON.stringify(getResolveToMatches(matches));
572
- return React2.useMemo(
573
- () => resolveTo(
574
- to,
575
- JSON.parse(routePathnamesJson),
576
- locationPathname,
577
- relative === "path"
578
- ),
579
- [to, routePathnamesJson, locationPathname, relative]
580
- );
581
- }
582
- function useRoutesImpl(routes, locationArg, dataRouterState, future) {
583
- invariant(
584
- useInRouterContext(),
585
- // TODO: This error is probably because they somehow have 2 versions of the
586
- // router loaded. We can help them understand how to avoid that.
587
- `useRoutes() may be used only in the context of a <Router> component.`
588
- );
589
- let { navigator } = React2.useContext(NavigationContext);
590
- let { matches: parentMatches } = React2.useContext(RouteContext);
591
- let routeMatch = parentMatches[parentMatches.length - 1];
592
- let parentParams = routeMatch ? routeMatch.params : {};
593
- let parentPathname = routeMatch ? routeMatch.pathname : "/";
594
- let parentPathnameBase = routeMatch ? routeMatch.pathnameBase : "/";
595
- let parentRoute = routeMatch && routeMatch.route;
596
- if (ENABLE_DEV_WARNINGS) {
597
- let parentPath = parentRoute && parentRoute.path || "";
598
- warningOnce(
599
- parentPathname,
600
- !parentRoute || parentPath.endsWith("*") || parentPath.endsWith("*?"),
601
- `You rendered descendant <Routes> (or called \`useRoutes()\`) at "${parentPathname}" (under <Route path="${parentPath}">) but the parent route path has no trailing "*". This means if you navigate deeper, the parent won't match anymore and therefore the child routes will never render.
602
-
603
- Please change the parent <Route path="${parentPath}"> to <Route path="${parentPath === "/" ? "*" : `${parentPath}/*`}">.`
604
- );
605
- }
606
- let locationFromContext = useLocation();
607
- let location;
608
- if (locationArg) {
609
- let parsedLocationArg = typeof locationArg === "string" ? parsePath(locationArg) : locationArg;
610
- invariant(
611
- parentPathnameBase === "/" || parsedLocationArg.pathname?.startsWith(parentPathnameBase),
612
- `When overriding the location using \`<Routes location>\` or \`useRoutes(routes, location)\`, the location pathname must begin with the portion of the URL pathname that was matched by all parent routes. The current pathname base is "${parentPathnameBase}" but pathname "${parsedLocationArg.pathname}" was given in the \`location\` prop.`
613
- );
614
- location = parsedLocationArg;
615
- } else {
616
- location = locationFromContext;
617
- }
618
- let pathname = location.pathname || "/";
619
- let remainingPathname = pathname;
620
- if (parentPathnameBase !== "/") {
621
- let parentSegments = parentPathnameBase.replace(/^\//, "").split("/");
622
- let segments = pathname.replace(/^\//, "").split("/");
623
- remainingPathname = "/" + segments.slice(parentSegments.length).join("/");
624
- }
625
- let matches = matchRoutes(routes, { pathname: remainingPathname });
626
- if (ENABLE_DEV_WARNINGS) {
627
- warning(
628
- parentRoute || matches != null,
629
- `No routes matched location "${location.pathname}${location.search}${location.hash}" `
630
- );
631
- warning(
632
- matches == null || matches[matches.length - 1].route.element !== void 0 || matches[matches.length - 1].route.Component !== void 0 || matches[matches.length - 1].route.lazy !== void 0,
633
- `Matched leaf route at location "${location.pathname}${location.search}${location.hash}" does not have an element or Component. This means it will render an <Outlet /> with a null value by default resulting in an "empty" page.`
634
- );
635
- }
636
- let renderedMatches = _renderMatches(
637
- matches && matches.map(
638
- (match) => Object.assign({}, match, {
639
- params: Object.assign({}, parentParams, match.params),
640
- pathname: joinPaths([
641
- parentPathnameBase,
642
- // Re-encode pathnames that were decoded inside matchRoutes
643
- navigator.encodeLocation ? navigator.encodeLocation(match.pathname).pathname : match.pathname
644
- ]),
645
- pathnameBase: match.pathnameBase === "/" ? parentPathnameBase : joinPaths([
646
- parentPathnameBase,
647
- // Re-encode pathnames that were decoded inside matchRoutes
648
- navigator.encodeLocation ? navigator.encodeLocation(match.pathnameBase).pathname : match.pathnameBase
649
- ])
650
- })
651
- ),
652
- parentMatches,
653
- dataRouterState,
654
- future
655
- );
656
- if (locationArg && renderedMatches) {
657
- return /* @__PURE__ */ React2.createElement(
658
- LocationContext.Provider,
659
- {
660
- value: {
661
- location: {
662
- pathname: "/",
663
- search: "",
664
- hash: "",
665
- state: null,
666
- key: "default",
667
- ...location
668
- },
669
- navigationType: "POP"
670
- /* Pop */
671
- }
672
- },
673
- renderedMatches
674
- );
675
- }
676
- return renderedMatches;
677
- }
678
- function DefaultErrorComponent() {
679
- let error = useRouteError();
680
- let message = isRouteErrorResponse(error) ? `${error.status} ${error.statusText}` : error instanceof Error ? error.message : JSON.stringify(error);
681
- let stack = error instanceof Error ? error.stack : null;
682
- let lightgrey = "rgba(200,200,200, 0.5)";
683
- let preStyles = { padding: "0.5rem", backgroundColor: lightgrey };
684
- let codeStyles = { padding: "2px 4px", backgroundColor: lightgrey };
685
- let devInfo = null;
686
- if (ENABLE_DEV_WARNINGS) {
687
- console.error(
688
- "Error handled by React Router default ErrorBoundary:",
689
- error
690
- );
691
- devInfo = /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement("p", null, "\u{1F4BF} Hey developer \u{1F44B}"), /* @__PURE__ */ React2.createElement("p", null, "You can provide a way better UX than this when your app throws errors by providing your own ", /* @__PURE__ */ React2.createElement("code", { style: codeStyles }, "ErrorBoundary"), " or", " ", /* @__PURE__ */ React2.createElement("code", { style: codeStyles }, "errorElement"), " prop on your route."));
692
- }
693
- return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement("h2", null, "Unexpected Application Error!"), /* @__PURE__ */ React2.createElement("h3", { style: { fontStyle: "italic" } }, message), stack ? /* @__PURE__ */ React2.createElement("pre", { style: preStyles }, stack) : null, devInfo);
694
- }
695
- var defaultErrorElement = /* @__PURE__ */ React2.createElement(DefaultErrorComponent, null);
696
- var RenderErrorBoundary = class extends React2.Component {
697
- constructor(props) {
698
- super(props);
699
- this.state = {
700
- location: props.location,
701
- revalidation: props.revalidation,
702
- error: props.error
703
- };
704
- }
705
- static getDerivedStateFromError(error) {
706
- return { error };
707
- }
708
- static getDerivedStateFromProps(props, state) {
709
- if (state.location !== props.location || state.revalidation !== "idle" && props.revalidation === "idle") {
710
- return {
711
- error: props.error,
712
- location: props.location,
713
- revalidation: props.revalidation
714
- };
715
- }
716
- return {
717
- error: props.error !== void 0 ? props.error : state.error,
718
- location: state.location,
719
- revalidation: props.revalidation || state.revalidation
720
- };
721
- }
722
- componentDidCatch(error, errorInfo) {
723
- console.error(
724
- "React Router caught the following error during render",
725
- error,
726
- errorInfo
727
- );
728
- }
729
- render() {
730
- return this.state.error !== void 0 ? /* @__PURE__ */ React2.createElement(RouteContext.Provider, { value: this.props.routeContext }, /* @__PURE__ */ React2.createElement(
731
- RouteErrorContext.Provider,
732
- {
733
- value: this.state.error,
734
- children: this.props.component
735
- }
736
- )) : this.props.children;
737
- }
738
- };
739
- function RenderedRoute({ routeContext, match, children }) {
740
- let dataRouterContext = React2.useContext(DataRouterContext);
741
- if (dataRouterContext && dataRouterContext.static && dataRouterContext.staticContext && (match.route.errorElement || match.route.ErrorBoundary)) {
742
- dataRouterContext.staticContext._deepestRenderedBoundaryId = match.route.id;
743
- }
744
- return /* @__PURE__ */ React2.createElement(RouteContext.Provider, { value: routeContext }, children);
745
- }
746
- function _renderMatches(matches, parentMatches = [], dataRouterState = null, future = null) {
747
- if (matches == null) {
748
- if (!dataRouterState) {
749
- return null;
750
- }
751
- if (dataRouterState.errors) {
752
- matches = dataRouterState.matches;
753
- } else if (parentMatches.length === 0 && !dataRouterState.initialized && dataRouterState.matches.length > 0) {
754
- matches = dataRouterState.matches;
755
- } else {
756
- return null;
757
- }
758
- }
759
- let renderedMatches = matches;
760
- let errors = dataRouterState?.errors;
761
- if (errors != null) {
762
- let errorIndex = renderedMatches.findIndex(
763
- (m) => m.route.id && errors?.[m.route.id] !== void 0
764
- );
765
- invariant(
766
- errorIndex >= 0,
767
- `Could not find a matching route for errors on route IDs: ${Object.keys(
768
- errors
769
- ).join(",")}`
770
- );
771
- renderedMatches = renderedMatches.slice(
772
- 0,
773
- Math.min(renderedMatches.length, errorIndex + 1)
774
- );
775
- }
776
- let renderFallback = false;
777
- let fallbackIndex = -1;
778
- if (dataRouterState) {
779
- for (let i = 0; i < renderedMatches.length; i++) {
780
- let match = renderedMatches[i];
781
- if (match.route.HydrateFallback || match.route.hydrateFallbackElement) {
782
- fallbackIndex = i;
783
- }
784
- if (match.route.id) {
785
- let { loaderData, errors: errors2 } = dataRouterState;
786
- let needsToRunLoader = match.route.loader && !loaderData.hasOwnProperty(match.route.id) && (!errors2 || errors2[match.route.id] === void 0);
787
- if (match.route.lazy || needsToRunLoader) {
788
- renderFallback = true;
789
- if (fallbackIndex >= 0) {
790
- renderedMatches = renderedMatches.slice(0, fallbackIndex + 1);
791
- } else {
792
- renderedMatches = [renderedMatches[0]];
793
- }
794
- break;
795
- }
796
- }
797
- }
798
- }
799
- return renderedMatches.reduceRight((outlet, match, index) => {
800
- let error;
801
- let shouldRenderHydrateFallback = false;
802
- let errorElement = null;
803
- let hydrateFallbackElement = null;
804
- if (dataRouterState) {
805
- error = errors && match.route.id ? errors[match.route.id] : void 0;
806
- errorElement = match.route.errorElement || defaultErrorElement;
807
- if (renderFallback) {
808
- if (fallbackIndex < 0 && index === 0) {
809
- warningOnce(
810
- "route-fallback",
811
- false,
812
- "No `HydrateFallback` element provided to render during initial hydration"
813
- );
814
- shouldRenderHydrateFallback = true;
815
- hydrateFallbackElement = null;
816
- } else if (fallbackIndex === index) {
817
- shouldRenderHydrateFallback = true;
818
- hydrateFallbackElement = match.route.hydrateFallbackElement || null;
819
- }
820
- }
821
- }
822
- let matches2 = parentMatches.concat(renderedMatches.slice(0, index + 1));
823
- let getChildren = () => {
824
- let children;
825
- if (error) {
826
- children = errorElement;
827
- } else if (shouldRenderHydrateFallback) {
828
- children = hydrateFallbackElement;
829
- } else if (match.route.Component) {
830
- children = /* @__PURE__ */ React2.createElement(match.route.Component, null);
831
- } else if (match.route.element) {
832
- children = match.route.element;
833
- } else {
834
- children = outlet;
835
- }
836
- return /* @__PURE__ */ React2.createElement(
837
- RenderedRoute,
838
- {
839
- match,
840
- routeContext: {
841
- outlet,
842
- matches: matches2,
843
- isDataRoute: dataRouterState != null
844
- },
845
- children
846
- }
847
- );
848
- };
849
- return dataRouterState && (match.route.ErrorBoundary || match.route.errorElement || index === 0) ? /* @__PURE__ */ React2.createElement(
850
- RenderErrorBoundary,
851
- {
852
- location: dataRouterState.location,
853
- revalidation: dataRouterState.revalidation,
854
- component: errorElement,
855
- error,
856
- children: getChildren(),
857
- routeContext: { outlet: null, matches: matches2, isDataRoute: true }
858
- }
859
- ) : getChildren();
860
- }, null);
861
- }
862
- function getDataRouterConsoleError(hookName) {
863
- return `${hookName} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`;
864
- }
865
- function useDataRouterContext(hookName) {
866
- let ctx = React2.useContext(DataRouterContext);
867
- invariant(ctx, getDataRouterConsoleError(hookName));
868
- return ctx;
869
- }
870
- function useDataRouterState(hookName) {
871
- let state = React2.useContext(DataRouterStateContext);
872
- invariant(state, getDataRouterConsoleError(hookName));
873
- return state;
874
- }
875
- function useRouteContext(hookName) {
876
- let route = React2.useContext(RouteContext);
877
- invariant(route, getDataRouterConsoleError(hookName));
878
- return route;
879
- }
880
- function useCurrentRouteId(hookName) {
881
- let route = useRouteContext(hookName);
882
- let thisRoute = route.matches[route.matches.length - 1];
883
- invariant(
884
- thisRoute.route.id,
885
- `${hookName} can only be used on routes that contain a unique "id"`
886
- );
887
- return thisRoute.route.id;
888
- }
889
- function useRouteId() {
890
- return useCurrentRouteId(
891
- "useRouteId"
892
- /* UseRouteId */
893
- );
894
- }
895
- function useNavigation() {
896
- let state = useDataRouterState(
897
- "useNavigation"
898
- /* UseNavigation */
899
- );
900
- return state.navigation;
901
- }
902
- function useMatches() {
903
- let { matches, loaderData } = useDataRouterState(
904
- "useMatches"
905
- /* UseMatches */
906
- );
907
- return React2.useMemo(
908
- () => matches.map((m) => convertRouteMatchToUiMatch(m, loaderData)),
909
- [matches, loaderData]
910
- );
911
- }
912
- function useRouteError() {
913
- let error = React2.useContext(RouteErrorContext);
914
- let state = useDataRouterState(
915
- "useRouteError"
916
- /* UseRouteError */
917
- );
918
- let routeId = useCurrentRouteId(
919
- "useRouteError"
920
- /* UseRouteError */
921
- );
922
- if (error !== void 0) {
923
- return error;
924
- }
925
- return state.errors?.[routeId];
926
- }
927
- function useNavigateStable() {
928
- let { router } = useDataRouterContext(
929
- "useNavigate"
930
- /* UseNavigateStable */
931
- );
932
- let id = useCurrentRouteId(
933
- "useNavigate"
934
- /* UseNavigateStable */
935
- );
936
- let activeRef = React2.useRef(false);
937
- useIsomorphicLayoutEffect(() => {
938
- activeRef.current = true;
939
- });
940
- let navigate = React2.useCallback(
941
- async (to, options = {}) => {
942
- warning(activeRef.current, navigateEffectWarning);
943
- if (!activeRef.current) return;
944
- if (typeof to === "number") {
945
- router.navigate(to);
946
- } else {
947
- await router.navigate(to, { fromRouteId: id, ...options });
948
- }
949
- },
950
- [router, id]
951
- );
952
- return navigate;
953
- }
954
- var alreadyWarned = {};
955
- function warningOnce(key, cond, message) {
956
- if (!cond && !alreadyWarned[key]) {
957
- alreadyWarned[key] = true;
958
- warning(false, message);
959
- }
960
- }
961
- var alreadyWarned2 = {};
962
- function warnOnce(condition, message) {
963
- if (!condition && !alreadyWarned2[message]) {
964
- alreadyWarned2[message] = true;
965
- console.warn(message);
966
- }
967
- }
968
- var MemoizedDataRoutes = React3.memo(DataRoutes);
969
- function DataRoutes({
970
- routes,
971
- future,
972
- state
973
- }) {
974
- return useRoutesImpl(routes, void 0, state, future);
975
- }
976
- function Outlet(props) {
977
- return useOutlet(props.context);
978
- }
979
- function Router({
980
- basename: basenameProp = "/",
981
- children = null,
982
- location: locationProp,
983
- navigationType = "POP",
984
- navigator,
985
- static: staticProp = false
986
- }) {
987
- invariant(
988
- !useInRouterContext(),
989
- `You cannot render a <Router> inside another <Router>. You should never have more than one in your app.`
990
- );
991
- let basename = basenameProp.replace(/^\/*/, "/");
992
- let navigationContext = React3.useMemo(
993
- () => ({
994
- basename,
995
- navigator,
996
- static: staticProp,
997
- future: {}
998
- }),
999
- [basename, navigator, staticProp]
1000
- );
1001
- if (typeof locationProp === "string") {
1002
- locationProp = parsePath(locationProp);
1003
- }
1004
- let {
1005
- pathname = "/",
1006
- search = "",
1007
- hash = "",
1008
- state = null,
1009
- key = "default"
1010
- } = locationProp;
1011
- let locationContext = React3.useMemo(() => {
1012
- let trailingPathname = stripBasename(pathname, basename);
1013
- if (trailingPathname == null) {
1014
- return null;
1015
- }
1016
- return {
1017
- location: {
1018
- pathname: trailingPathname,
1019
- search,
1020
- hash,
1021
- state,
1022
- key
1023
- },
1024
- navigationType
1025
- };
1026
- }, [basename, pathname, search, hash, state, key, navigationType]);
1027
- warning(
1028
- locationContext != null,
1029
- `<Router basename="${basename}"> is not able to match the URL "${pathname}${search}${hash}" because it does not start with the basename, so the <Router> won't render anything.`
1030
- );
1031
- if (locationContext == null) {
1032
- return null;
1033
- }
1034
- return /* @__PURE__ */ React3.createElement(NavigationContext.Provider, { value: navigationContext }, /* @__PURE__ */ React3.createElement(LocationContext.Provider, { children, value: locationContext }));
1035
- }
1036
- var defaultMethod = "get";
1037
- var defaultEncType = "application/x-www-form-urlencoded";
1038
- function isHtmlElement(object) {
1039
- return object != null && typeof object.tagName === "string";
1040
- }
1041
- function isButtonElement(object) {
1042
- return isHtmlElement(object) && object.tagName.toLowerCase() === "button";
1043
- }
1044
- function isFormElement(object) {
1045
- return isHtmlElement(object) && object.tagName.toLowerCase() === "form";
1046
- }
1047
- function isInputElement(object) {
1048
- return isHtmlElement(object) && object.tagName.toLowerCase() === "input";
1049
- }
1050
- function isModifiedEvent(event) {
1051
- return !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey);
1052
- }
1053
- function shouldProcessLinkClick(event, target) {
1054
- return event.button === 0 && // Ignore everything but left clicks
1055
- (!target || target === "_self") && // Let browser handle "target=_blank" etc.
1056
- !isModifiedEvent(event);
1057
- }
1058
- var _formDataSupportsSubmitter = null;
1059
- function isFormDataSubmitterSupported() {
1060
- if (_formDataSupportsSubmitter === null) {
1061
- try {
1062
- new FormData(
1063
- document.createElement("form"),
1064
- // @ts-expect-error if FormData supports the submitter parameter, this will throw
1065
- 0
1066
- );
1067
- _formDataSupportsSubmitter = false;
1068
- } catch (e) {
1069
- _formDataSupportsSubmitter = true;
1070
- }
1071
- }
1072
- return _formDataSupportsSubmitter;
1073
- }
1074
- var supportedFormEncTypes = /* @__PURE__ */ new Set([
1075
- "application/x-www-form-urlencoded",
1076
- "multipart/form-data",
1077
- "text/plain"
1078
- ]);
1079
- function getFormEncType(encType) {
1080
- if (encType != null && !supportedFormEncTypes.has(encType)) {
1081
- warning(
1082
- false,
1083
- `"${encType}" is not a valid \`encType\` for \`<Form>\`/\`<fetcher.Form>\` and will default to "${defaultEncType}"`
1084
- );
1085
- return null;
1086
- }
1087
- return encType;
1088
- }
1089
- function getFormSubmissionInfo(target, basename) {
1090
- let method;
1091
- let action;
1092
- let encType;
1093
- let formData;
1094
- let body;
1095
- if (isFormElement(target)) {
1096
- let attr = target.getAttribute("action");
1097
- action = attr ? stripBasename(attr, basename) : null;
1098
- method = target.getAttribute("method") || defaultMethod;
1099
- encType = getFormEncType(target.getAttribute("enctype")) || defaultEncType;
1100
- formData = new FormData(target);
1101
- } else if (isButtonElement(target) || isInputElement(target) && (target.type === "submit" || target.type === "image")) {
1102
- let form = target.form;
1103
- if (form == null) {
1104
- throw new Error(
1105
- `Cannot submit a <button> or <input type="submit"> without a <form>`
1106
- );
1107
- }
1108
- let attr = target.getAttribute("formaction") || form.getAttribute("action");
1109
- action = attr ? stripBasename(attr, basename) : null;
1110
- method = target.getAttribute("formmethod") || form.getAttribute("method") || defaultMethod;
1111
- encType = getFormEncType(target.getAttribute("formenctype")) || getFormEncType(form.getAttribute("enctype")) || defaultEncType;
1112
- formData = new FormData(form, target);
1113
- if (!isFormDataSubmitterSupported()) {
1114
- let { name, type, value } = target;
1115
- if (type === "image") {
1116
- let prefix = name ? `${name}.` : "";
1117
- formData.append(`${prefix}x`, "0");
1118
- formData.append(`${prefix}y`, "0");
1119
- } else if (name) {
1120
- formData.append(name, value);
1121
- }
1122
- }
1123
- } else if (isHtmlElement(target)) {
1124
- throw new Error(
1125
- `Cannot submit element that is not <form>, <button>, or <input type="submit|image">`
1126
- );
1127
- } else {
1128
- method = defaultMethod;
1129
- action = null;
1130
- encType = defaultEncType;
1131
- body = target;
1132
- }
1133
- if (formData && encType === "text/plain") {
1134
- body = formData;
1135
- formData = void 0;
1136
- }
1137
- return { action, method: method.toLowerCase(), encType, formData, body };
1138
- }
1139
- var objectProtoNames = Object.getOwnPropertyNames(Object.prototype).sort().join("\0");
1140
- function createHtml(html) {
1141
- return { __html: html };
1142
- }
1143
- function invariant2(value, message) {
1144
- if (value === false || value === null || typeof value === "undefined") {
1145
- throw new Error(message);
1146
- }
1147
- }
1148
- var SingleFetchRedirectSymbol = Symbol("SingleFetchRedirect");
1149
- function singleFetchUrl(reqUrl, basename, extension) {
1150
- let url = typeof reqUrl === "string" ? new URL(
1151
- reqUrl,
1152
- // This can be called during the SSR flow via PrefetchPageLinksImpl so
1153
- // don't assume window is available
1154
- typeof window === "undefined" ? "server://singlefetch/" : window.location.origin
1155
- ) : reqUrl;
1156
- if (url.pathname === "/") {
1157
- url.pathname = `_root.${extension}`;
1158
- } else if (basename && stripBasename(url.pathname, basename) === "/") {
1159
- url.pathname = `${basename.replace(/\/$/, "")}/_root.${extension}`;
1160
- } else {
1161
- url.pathname = `${url.pathname.replace(/\/$/, "")}.${extension}`;
1162
- }
1163
- return url;
1164
- }
1165
- async function loadRouteModule(route, routeModulesCache) {
1166
- if (route.id in routeModulesCache) {
1167
- return routeModulesCache[route.id];
1168
- }
1169
- try {
1170
- let routeModule = await import(
1171
- /* @vite-ignore */
1172
- /* webpackIgnore: true */
1173
- route.module
1174
- );
1175
- routeModulesCache[route.id] = routeModule;
1176
- return routeModule;
1177
- } catch (error) {
1178
- console.error(
1179
- `Error loading route module \`${route.module}\`, reloading page...`
1180
- );
1181
- console.error(error);
1182
- if (window.__reactRouterContext && window.__reactRouterContext.isSpaMode && // @ts-expect-error
1183
- import.meta.hot) {
1184
- throw error;
1185
- }
1186
- window.location.reload();
1187
- return new Promise(() => {
1188
- });
1189
- }
1190
- }
1191
- function getKeyedLinksForMatches(matches, routeModules, manifest) {
1192
- let descriptors = matches.map((match) => {
1193
- let module = routeModules[match.route.id];
1194
- let route = manifest.routes[match.route.id];
1195
- return [
1196
- route && route.css ? route.css.map((href) => ({ rel: "stylesheet", href })) : [],
1197
- module?.links?.() || []
1198
- ];
1199
- }).flat(2);
1200
- let preloads = getModuleLinkHrefs(matches, manifest);
1201
- return dedupeLinkDescriptors(descriptors, preloads);
1202
- }
1203
- function isPageLinkDescriptor(object) {
1204
- return object != null && typeof object.page === "string";
1205
- }
1206
- function isHtmlLinkDescriptor(object) {
1207
- if (object == null) {
1208
- return false;
1209
- }
1210
- if (object.href == null) {
1211
- return object.rel === "preload" && typeof object.imageSrcSet === "string" && typeof object.imageSizes === "string";
1212
- }
1213
- return typeof object.rel === "string" && typeof object.href === "string";
1214
- }
1215
- async function getKeyedPrefetchLinks(matches, manifest, routeModules) {
1216
- let links = await Promise.all(
1217
- matches.map(async (match) => {
1218
- let route = manifest.routes[match.route.id];
1219
- if (route) {
1220
- let mod = await loadRouteModule(route, routeModules);
1221
- return mod.links ? mod.links() : [];
1222
- }
1223
- return [];
1224
- })
1225
- );
1226
- return dedupeLinkDescriptors(
1227
- links.flat(1).filter(isHtmlLinkDescriptor).filter((link) => link.rel === "stylesheet" || link.rel === "preload").map(
1228
- (link) => link.rel === "stylesheet" ? { ...link, rel: "prefetch", as: "style" } : { ...link, rel: "prefetch" }
1229
- )
1230
- );
1231
- }
1232
- function getNewMatchesForLinks(page, nextMatches, currentMatches, manifest, location, mode) {
1233
- let isNew = (match, index) => {
1234
- if (!currentMatches[index]) return true;
1235
- return match.route.id !== currentMatches[index].route.id;
1236
- };
1237
- let matchPathChanged = (match, index) => {
1238
- return (
1239
- // param change, /users/123 -> /users/456
1240
- currentMatches[index].pathname !== match.pathname || // splat param changed, which is not present in match.path
1241
- // e.g. /files/images/avatar.jpg -> files/finances.xls
1242
- currentMatches[index].route.path?.endsWith("*") && currentMatches[index].params["*"] !== match.params["*"]
1243
- );
1244
- };
1245
- if (mode === "assets") {
1246
- return nextMatches.filter(
1247
- (match, index) => isNew(match, index) || matchPathChanged(match, index)
1248
- );
1249
- }
1250
- if (mode === "data") {
1251
- return nextMatches.filter((match, index) => {
1252
- let manifestRoute = manifest.routes[match.route.id];
1253
- if (!manifestRoute || !manifestRoute.hasLoader) {
1254
- return false;
1255
- }
1256
- if (isNew(match, index) || matchPathChanged(match, index)) {
1257
- return true;
1258
- }
1259
- if (match.route.shouldRevalidate) {
1260
- let routeChoice = match.route.shouldRevalidate({
1261
- currentUrl: new URL(
1262
- location.pathname + location.search + location.hash,
1263
- window.origin
1264
- ),
1265
- currentParams: currentMatches[0]?.params || {},
1266
- nextUrl: new URL(page, window.origin),
1267
- nextParams: match.params,
1268
- defaultShouldRevalidate: true
1269
- });
1270
- if (typeof routeChoice === "boolean") {
1271
- return routeChoice;
1272
- }
1273
- }
1274
- return true;
1275
- });
1276
- }
1277
- return [];
1278
- }
1279
- function getModuleLinkHrefs(matches, manifest, { includeHydrateFallback } = {}) {
1280
- return dedupeHrefs(
1281
- matches.map((match) => {
1282
- let route = manifest.routes[match.route.id];
1283
- if (!route) return [];
1284
- let hrefs = [route.module];
1285
- if (route.clientActionModule) {
1286
- hrefs = hrefs.concat(route.clientActionModule);
1287
- }
1288
- if (route.clientLoaderModule) {
1289
- hrefs = hrefs.concat(route.clientLoaderModule);
1290
- }
1291
- if (includeHydrateFallback && route.hydrateFallbackModule) {
1292
- hrefs = hrefs.concat(route.hydrateFallbackModule);
1293
- }
1294
- if (route.imports) {
1295
- hrefs = hrefs.concat(route.imports);
1296
- }
1297
- return hrefs;
1298
- }).flat(1)
1299
- );
1300
- }
1301
- function dedupeHrefs(hrefs) {
1302
- return [...new Set(hrefs)];
1303
- }
1304
- function sortKeys(obj) {
1305
- let sorted = {};
1306
- let keys = Object.keys(obj).sort();
1307
- for (let key of keys) {
1308
- sorted[key] = obj[key];
1309
- }
1310
- return sorted;
1311
- }
1312
- function dedupeLinkDescriptors(descriptors, preloads) {
1313
- let set = /* @__PURE__ */ new Set();
1314
- let preloadsSet = new Set(preloads);
1315
- return descriptors.reduce((deduped, descriptor) => {
1316
- let alreadyModulePreload = preloads && !isPageLinkDescriptor(descriptor) && descriptor.as === "script" && descriptor.href && preloadsSet.has(descriptor.href);
1317
- if (alreadyModulePreload) {
1318
- return deduped;
1319
- }
1320
- let key = JSON.stringify(sortKeys(descriptor));
1321
- if (!set.has(key)) {
1322
- set.add(key);
1323
- deduped.push({ key, link: descriptor });
1324
- }
1325
- return deduped;
1326
- }, []);
1327
- }
1328
- function isFogOfWarEnabled(routeDiscovery, ssr) {
1329
- return routeDiscovery.mode === "lazy" && ssr === true;
1330
- }
1331
- function getPartialManifest({ sri, ...manifest }, router) {
1332
- let routeIds = new Set(router.state.matches.map((m) => m.route.id));
1333
- let segments = router.state.location.pathname.split("/").filter(Boolean);
1334
- let paths = ["/"];
1335
- segments.pop();
1336
- while (segments.length > 0) {
1337
- paths.push(`/${segments.join("/")}`);
1338
- segments.pop();
1339
- }
1340
- paths.forEach((path) => {
1341
- let matches = matchRoutes(router.routes, path, router.basename);
1342
- if (matches) {
1343
- matches.forEach((m) => routeIds.add(m.route.id));
1344
- }
1345
- });
1346
- let initialRoutes = [...routeIds].reduce(
1347
- (acc, id) => Object.assign(acc, { [id]: manifest.routes[id] }),
1348
- {}
1349
- );
1350
- return {
1351
- ...manifest,
1352
- routes: initialRoutes,
1353
- sri: sri ? true : void 0
1354
- };
1355
- }
1356
- function useDataRouterContext2() {
1357
- let context = React8.useContext(DataRouterContext);
1358
- invariant2(
1359
- context,
1360
- "You must render this element inside a <DataRouterContext.Provider> element"
1361
- );
1362
- return context;
1363
- }
1364
- function useDataRouterStateContext() {
1365
- let context = React8.useContext(DataRouterStateContext);
1366
- invariant2(
1367
- context,
1368
- "You must render this element inside a <DataRouterStateContext.Provider> element"
1369
- );
1370
- return context;
1371
- }
1372
- var FrameworkContext = React8.createContext(void 0);
1373
- FrameworkContext.displayName = "FrameworkContext";
1374
- function useFrameworkContext() {
1375
- let context = React8.useContext(FrameworkContext);
1376
- invariant2(
1377
- context,
1378
- "You must render this element inside a <HydratedRouter> element"
1379
- );
1380
- return context;
1381
- }
1382
- function usePrefetchBehavior(prefetch, theirElementProps) {
1383
- let frameworkContext = React8.useContext(FrameworkContext);
1384
- let [maybePrefetch, setMaybePrefetch] = React8.useState(false);
1385
- let [shouldPrefetch, setShouldPrefetch] = React8.useState(false);
1386
- let { onFocus, onBlur, onMouseEnter, onMouseLeave, onTouchStart } = theirElementProps;
1387
- let ref = React8.useRef(null);
1388
- React8.useEffect(() => {
1389
- if (prefetch === "render") {
1390
- setShouldPrefetch(true);
1391
- }
1392
- if (prefetch === "viewport") {
1393
- let callback = (entries) => {
1394
- entries.forEach((entry) => {
1395
- setShouldPrefetch(entry.isIntersecting);
1396
- });
1397
- };
1398
- let observer = new IntersectionObserver(callback, { threshold: 0.5 });
1399
- if (ref.current) observer.observe(ref.current);
1400
- return () => {
1401
- observer.disconnect();
1402
- };
1403
- }
1404
- }, [prefetch]);
1405
- React8.useEffect(() => {
1406
- if (maybePrefetch) {
1407
- let id = setTimeout(() => {
1408
- setShouldPrefetch(true);
1409
- }, 100);
1410
- return () => {
1411
- clearTimeout(id);
1412
- };
1413
- }
1414
- }, [maybePrefetch]);
1415
- let setIntent = () => {
1416
- setMaybePrefetch(true);
1417
- };
1418
- let cancelIntent = () => {
1419
- setMaybePrefetch(false);
1420
- setShouldPrefetch(false);
1421
- };
1422
- if (!frameworkContext) {
1423
- return [false, ref, {}];
1424
- }
1425
- if (prefetch !== "intent") {
1426
- return [shouldPrefetch, ref, {}];
1427
- }
1428
- return [
1429
- shouldPrefetch,
1430
- ref,
1431
- {
1432
- onFocus: composeEventHandlers(onFocus, setIntent),
1433
- onBlur: composeEventHandlers(onBlur, cancelIntent),
1434
- onMouseEnter: composeEventHandlers(onMouseEnter, setIntent),
1435
- onMouseLeave: composeEventHandlers(onMouseLeave, cancelIntent),
1436
- onTouchStart: composeEventHandlers(onTouchStart, setIntent)
1437
- }
1438
- ];
1439
- }
1440
- function composeEventHandlers(theirHandler, ourHandler) {
1441
- return (event) => {
1442
- theirHandler && theirHandler(event);
1443
- if (!event.defaultPrevented) {
1444
- ourHandler(event);
1445
- }
1446
- };
1447
- }
1448
- function getActiveMatches(matches, errors, isSpaMode) {
1449
- if (isSpaMode && !isHydrated) {
1450
- return [matches[0]];
1451
- }
1452
- if (errors) {
1453
- let errorIdx = matches.findIndex((m) => errors[m.route.id] !== void 0);
1454
- return matches.slice(0, errorIdx + 1);
1455
- }
1456
- return matches;
1457
- }
1458
- var CRITICAL_CSS_DATA_ATTRIBUTE = "data-react-router-critical-css";
1459
- function Links() {
1460
- let { isSpaMode, manifest, routeModules, criticalCss } = useFrameworkContext();
1461
- let { errors, matches: routerMatches } = useDataRouterStateContext();
1462
- let matches = getActiveMatches(routerMatches, errors, isSpaMode);
1463
- let keyedLinks = React8.useMemo(
1464
- () => getKeyedLinksForMatches(matches, routeModules, manifest),
1465
- [matches, routeModules, manifest]
1466
- );
1467
- return /* @__PURE__ */ React8.createElement(React8.Fragment, null, typeof criticalCss === "string" ? /* @__PURE__ */ React8.createElement(
1468
- "style",
1469
- {
1470
- ...{ [CRITICAL_CSS_DATA_ATTRIBUTE]: "" },
1471
- dangerouslySetInnerHTML: { __html: criticalCss }
1472
- }
1473
- ) : null, typeof criticalCss === "object" ? /* @__PURE__ */ React8.createElement(
1474
- "link",
1475
- {
1476
- ...{ [CRITICAL_CSS_DATA_ATTRIBUTE]: "" },
1477
- rel: "stylesheet",
1478
- href: criticalCss.href
1479
- }
1480
- ) : null, keyedLinks.map(
1481
- ({ key, link }) => isPageLinkDescriptor(link) ? /* @__PURE__ */ React8.createElement(PrefetchPageLinks, { key, ...link }) : /* @__PURE__ */ React8.createElement("link", { key, ...link })
1482
- ));
1483
- }
1484
- function PrefetchPageLinks({
1485
- page,
1486
- ...dataLinkProps
1487
- }) {
1488
- let { router } = useDataRouterContext2();
1489
- let matches = React8.useMemo(
1490
- () => matchRoutes(router.routes, page, router.basename),
1491
- [router.routes, page, router.basename]
1492
- );
1493
- if (!matches) {
1494
- return null;
1495
- }
1496
- return /* @__PURE__ */ React8.createElement(PrefetchPageLinksImpl, { page, matches, ...dataLinkProps });
1497
- }
1498
- function useKeyedPrefetchLinks(matches) {
1499
- let { manifest, routeModules } = useFrameworkContext();
1500
- let [keyedPrefetchLinks, setKeyedPrefetchLinks] = React8.useState([]);
1501
- React8.useEffect(() => {
1502
- let interrupted = false;
1503
- void getKeyedPrefetchLinks(matches, manifest, routeModules).then(
1504
- (links) => {
1505
- if (!interrupted) {
1506
- setKeyedPrefetchLinks(links);
1507
- }
1508
- }
1509
- );
1510
- return () => {
1511
- interrupted = true;
1512
- };
1513
- }, [matches, manifest, routeModules]);
1514
- return keyedPrefetchLinks;
1515
- }
1516
- function PrefetchPageLinksImpl({
1517
- page,
1518
- matches: nextMatches,
1519
- ...linkProps
1520
- }) {
1521
- let location = useLocation();
1522
- let { manifest, routeModules } = useFrameworkContext();
1523
- let { basename } = useDataRouterContext2();
1524
- let { loaderData, matches } = useDataRouterStateContext();
1525
- let newMatchesForData = React8.useMemo(
1526
- () => getNewMatchesForLinks(
1527
- page,
1528
- nextMatches,
1529
- matches,
1530
- manifest,
1531
- location,
1532
- "data"
1533
- ),
1534
- [page, nextMatches, matches, manifest, location]
1535
- );
1536
- let newMatchesForAssets = React8.useMemo(
1537
- () => getNewMatchesForLinks(
1538
- page,
1539
- nextMatches,
1540
- matches,
1541
- manifest,
1542
- location,
1543
- "assets"
1544
- ),
1545
- [page, nextMatches, matches, manifest, location]
1546
- );
1547
- let dataHrefs = React8.useMemo(() => {
1548
- if (page === location.pathname + location.search + location.hash) {
1549
- return [];
1550
- }
1551
- let routesParams = /* @__PURE__ */ new Set();
1552
- let foundOptOutRoute = false;
1553
- nextMatches.forEach((m) => {
1554
- let manifestRoute = manifest.routes[m.route.id];
1555
- if (!manifestRoute || !manifestRoute.hasLoader) {
1556
- return;
1557
- }
1558
- if (!newMatchesForData.some((m2) => m2.route.id === m.route.id) && m.route.id in loaderData && routeModules[m.route.id]?.shouldRevalidate) {
1559
- foundOptOutRoute = true;
1560
- } else if (manifestRoute.hasClientLoader) {
1561
- foundOptOutRoute = true;
1562
- } else {
1563
- routesParams.add(m.route.id);
1564
- }
1565
- });
1566
- if (routesParams.size === 0) {
1567
- return [];
1568
- }
1569
- let url = singleFetchUrl(page, basename, "data");
1570
- if (foundOptOutRoute && routesParams.size > 0) {
1571
- url.searchParams.set(
1572
- "_routes",
1573
- nextMatches.filter((m) => routesParams.has(m.route.id)).map((m) => m.route.id).join(",")
1574
- );
1575
- }
1576
- return [url.pathname + url.search];
1577
- }, [
1578
- basename,
1579
- loaderData,
1580
- location,
1581
- manifest,
1582
- newMatchesForData,
1583
- nextMatches,
1584
- page,
1585
- routeModules
1586
- ]);
1587
- let moduleHrefs = React8.useMemo(
1588
- () => getModuleLinkHrefs(newMatchesForAssets, manifest),
1589
- [newMatchesForAssets, manifest]
1590
- );
1591
- let keyedPrefetchLinks = useKeyedPrefetchLinks(newMatchesForAssets);
1592
- return /* @__PURE__ */ React8.createElement(React8.Fragment, null, dataHrefs.map((href) => /* @__PURE__ */ React8.createElement("link", { key: href, rel: "prefetch", as: "fetch", href, ...linkProps })), moduleHrefs.map((href) => /* @__PURE__ */ React8.createElement("link", { key: href, rel: "modulepreload", href, ...linkProps })), keyedPrefetchLinks.map(({ key, link }) => (
1593
- // these don't spread `linkProps` because they are full link descriptors
1594
- // already with their own props
1595
- /* @__PURE__ */ React8.createElement("link", { key, ...link })
1596
- )));
1597
- }
1598
- function Meta() {
1599
- let { isSpaMode, routeModules } = useFrameworkContext();
1600
- let {
1601
- errors,
1602
- matches: routerMatches,
1603
- loaderData
1604
- } = useDataRouterStateContext();
1605
- let location = useLocation();
1606
- let _matches = getActiveMatches(routerMatches, errors, isSpaMode);
1607
- let error = null;
1608
- if (errors) {
1609
- error = errors[_matches[_matches.length - 1].route.id];
1610
- }
1611
- let meta = [];
1612
- let leafMeta = null;
1613
- let matches = [];
1614
- for (let i = 0; i < _matches.length; i++) {
1615
- let _match = _matches[i];
1616
- let routeId = _match.route.id;
1617
- let data2 = loaderData[routeId];
1618
- let params = _match.params;
1619
- let routeModule = routeModules[routeId];
1620
- let routeMeta = [];
1621
- let match = {
1622
- id: routeId,
1623
- data: data2,
1624
- meta: [],
1625
- params: _match.params,
1626
- pathname: _match.pathname,
1627
- handle: _match.route.handle,
1628
- error
1629
- };
1630
- matches[i] = match;
1631
- if (routeModule?.meta) {
1632
- routeMeta = typeof routeModule.meta === "function" ? routeModule.meta({
1633
- data: data2,
1634
- params,
1635
- location,
1636
- matches,
1637
- error
1638
- }) : Array.isArray(routeModule.meta) ? [...routeModule.meta] : routeModule.meta;
1639
- } else if (leafMeta) {
1640
- routeMeta = [...leafMeta];
1641
- }
1642
- routeMeta = routeMeta || [];
1643
- if (!Array.isArray(routeMeta)) {
1644
- throw new Error(
1645
- "The route at " + _match.route.path + " returns an invalid value. All route meta functions must return an array of meta objects.\n\nTo reference the meta function API, see https://remix.run/route/meta"
1646
- );
1647
- }
1648
- match.meta = routeMeta;
1649
- matches[i] = match;
1650
- meta = [...routeMeta];
1651
- leafMeta = meta;
1652
- }
1653
- return /* @__PURE__ */ React8.createElement(React8.Fragment, null, meta.flat().map((metaProps) => {
1654
- if (!metaProps) {
1655
- return null;
1656
- }
1657
- if ("tagName" in metaProps) {
1658
- let { tagName, ...rest } = metaProps;
1659
- if (!isValidMetaTag(tagName)) {
1660
- console.warn(
1661
- `A meta object uses an invalid tagName: ${tagName}. Expected either 'link' or 'meta'`
1662
- );
1663
- return null;
1664
- }
1665
- let Comp = tagName;
1666
- return /* @__PURE__ */ React8.createElement(Comp, { key: JSON.stringify(rest), ...rest });
1667
- }
1668
- if ("title" in metaProps) {
1669
- return /* @__PURE__ */ React8.createElement("title", { key: "title" }, String(metaProps.title));
1670
- }
1671
- if ("charset" in metaProps) {
1672
- metaProps.charSet ?? (metaProps.charSet = metaProps.charset);
1673
- delete metaProps.charset;
1674
- }
1675
- if ("charSet" in metaProps && metaProps.charSet != null) {
1676
- return typeof metaProps.charSet === "string" ? /* @__PURE__ */ React8.createElement("meta", { key: "charSet", charSet: metaProps.charSet }) : null;
1677
- }
1678
- if ("script:ld+json" in metaProps) {
1679
- try {
1680
- let json = JSON.stringify(metaProps["script:ld+json"]);
1681
- return /* @__PURE__ */ React8.createElement(
1682
- "script",
1683
- {
1684
- key: `script:ld+json:${json}`,
1685
- type: "application/ld+json",
1686
- dangerouslySetInnerHTML: { __html: json }
1687
- }
1688
- );
1689
- } catch (err) {
1690
- return null;
1691
- }
1692
- }
1693
- return /* @__PURE__ */ React8.createElement("meta", { key: JSON.stringify(metaProps), ...metaProps });
1694
- }));
1695
- }
1696
- function isValidMetaTag(tagName) {
1697
- return typeof tagName === "string" && /^(meta|link)$/.test(tagName);
1698
- }
1699
- var isHydrated = false;
1700
- function Scripts(props) {
1701
- let {
1702
- manifest,
1703
- serverHandoffString,
1704
- isSpaMode,
1705
- renderMeta,
1706
- routeDiscovery,
1707
- ssr
1708
- } = useFrameworkContext();
1709
- let { router, static: isStatic, staticContext } = useDataRouterContext2();
1710
- let { matches: routerMatches } = useDataRouterStateContext();
1711
- let isRSCRouterContext = useIsRSCRouterContext();
1712
- let enableFogOfWar = isFogOfWarEnabled(routeDiscovery, ssr);
1713
- if (renderMeta) {
1714
- renderMeta.didRenderScripts = true;
1715
- }
1716
- let matches = getActiveMatches(routerMatches, null, isSpaMode);
1717
- React8.useEffect(() => {
1718
- isHydrated = true;
1719
- }, []);
1720
- let initialScripts = React8.useMemo(() => {
1721
- if (isRSCRouterContext) {
1722
- return null;
1723
- }
1724
- let streamScript = "window.__reactRouterContext.stream = new ReadableStream({start(controller){window.__reactRouterContext.streamController = controller;}}).pipeThrough(new TextEncoderStream());";
1725
- let contextScript = staticContext ? `window.__reactRouterContext = ${serverHandoffString};${streamScript}` : " ";
1726
- let routeModulesScript = !isStatic ? " " : `${manifest.hmr?.runtime ? `import ${JSON.stringify(manifest.hmr.runtime)};` : ""}${!enableFogOfWar ? `import ${JSON.stringify(manifest.url)}` : ""};
1727
- ${matches.map((match, routeIndex) => {
1728
- let routeVarName = `route${routeIndex}`;
1729
- let manifestEntry = manifest.routes[match.route.id];
1730
- invariant2(manifestEntry, `Route ${match.route.id} not found in manifest`);
1731
- let {
1732
- clientActionModule,
1733
- clientLoaderModule,
1734
- clientMiddlewareModule,
1735
- hydrateFallbackModule,
1736
- module
1737
- } = manifestEntry;
1738
- let chunks = [
1739
- ...clientActionModule ? [
1740
- {
1741
- module: clientActionModule,
1742
- varName: `${routeVarName}_clientAction`
1743
- }
1744
- ] : [],
1745
- ...clientLoaderModule ? [
1746
- {
1747
- module: clientLoaderModule,
1748
- varName: `${routeVarName}_clientLoader`
1749
- }
1750
- ] : [],
1751
- ...clientMiddlewareModule ? [
1752
- {
1753
- module: clientMiddlewareModule,
1754
- varName: `${routeVarName}_clientMiddleware`
1755
- }
1756
- ] : [],
1757
- ...hydrateFallbackModule ? [
1758
- {
1759
- module: hydrateFallbackModule,
1760
- varName: `${routeVarName}_HydrateFallback`
1761
- }
1762
- ] : [],
1763
- { module, varName: `${routeVarName}_main` }
1764
- ];
1765
- if (chunks.length === 1) {
1766
- return `import * as ${routeVarName} from ${JSON.stringify(module)};`;
1767
- }
1768
- let chunkImportsSnippet = chunks.map((chunk) => `import * as ${chunk.varName} from "${chunk.module}";`).join("\n");
1769
- let mergedChunksSnippet = `const ${routeVarName} = {${chunks.map((chunk) => `...${chunk.varName}`).join(",")}};`;
1770
- return [chunkImportsSnippet, mergedChunksSnippet].join("\n");
1771
- }).join("\n")}
1772
- ${enableFogOfWar ? (
1773
- // Inline a minimal manifest with the SSR matches
1774
- `window.__reactRouterManifest = ${JSON.stringify(
1775
- getPartialManifest(manifest, router),
1776
- null,
1777
- 2
1778
- )};`
1779
- ) : ""}
1780
- window.__reactRouterRouteModules = {${matches.map((match, index) => `${JSON.stringify(match.route.id)}:route${index}`).join(",")}};
1781
-
1782
- import(${JSON.stringify(manifest.entry.module)});`;
1783
- return /* @__PURE__ */ React8.createElement(React8.Fragment, null, /* @__PURE__ */ React8.createElement(
1784
- "script",
1785
- {
1786
- ...props,
1787
- suppressHydrationWarning: true,
1788
- dangerouslySetInnerHTML: createHtml(contextScript),
1789
- type: void 0
1790
- }
1791
- ), /* @__PURE__ */ React8.createElement(
1792
- "script",
1793
- {
1794
- ...props,
1795
- suppressHydrationWarning: true,
1796
- dangerouslySetInnerHTML: createHtml(routeModulesScript),
1797
- type: "module",
1798
- async: true
1799
- }
1800
- ));
1801
- }, []);
1802
- let preloads = isHydrated || isRSCRouterContext ? [] : dedupe(
1803
- manifest.entry.imports.concat(
1804
- getModuleLinkHrefs(matches, manifest, {
1805
- includeHydrateFallback: true
1806
- })
1807
- )
1808
- );
1809
- let sri = typeof manifest.sri === "object" ? manifest.sri : {};
1810
- warnOnce(
1811
- !isRSCRouterContext,
1812
- "The <Scripts /> element is a no-op when using RSC and can be safely removed."
1813
- );
1814
- return isHydrated || isRSCRouterContext ? null : /* @__PURE__ */ React8.createElement(React8.Fragment, null, typeof manifest.sri === "object" ? /* @__PURE__ */ React8.createElement(
1815
- "script",
1816
- {
1817
- "rr-importmap": "",
1818
- type: "importmap",
1819
- suppressHydrationWarning: true,
1820
- dangerouslySetInnerHTML: {
1821
- __html: JSON.stringify({
1822
- integrity: sri
1823
- })
1824
- }
1825
- }
1826
- ) : null, !enableFogOfWar ? /* @__PURE__ */ React8.createElement(
1827
- "link",
1828
- {
1829
- rel: "modulepreload",
1830
- href: manifest.url,
1831
- crossOrigin: props.crossOrigin,
1832
- integrity: sri[manifest.url],
1833
- suppressHydrationWarning: true
1834
- }
1835
- ) : null, /* @__PURE__ */ React8.createElement(
1836
- "link",
1837
- {
1838
- rel: "modulepreload",
1839
- href: manifest.entry.module,
1840
- crossOrigin: props.crossOrigin,
1841
- integrity: sri[manifest.entry.module],
1842
- suppressHydrationWarning: true
1843
- }
1844
- ), preloads.map((path) => /* @__PURE__ */ React8.createElement(
1845
- "link",
1846
- {
1847
- key: path,
1848
- rel: "modulepreload",
1849
- href: path,
1850
- crossOrigin: props.crossOrigin,
1851
- integrity: sri[path],
1852
- suppressHydrationWarning: true
1853
- }
1854
- )), initialScripts);
1855
- }
1856
- function dedupe(array) {
1857
- return [...new Set(array)];
1858
- }
1859
- function mergeRefs(...refs) {
1860
- return (value) => {
1861
- refs.forEach((ref) => {
1862
- if (typeof ref === "function") {
1863
- ref(value);
1864
- } else if (ref != null) {
1865
- ref.current = value;
1866
- }
1867
- });
1868
- };
1869
- }
1870
- var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
1871
- try {
1872
- if (isBrowser) {
1873
- window.__reactRouterVersion = // @ts-expect-error
1874
- "7.7.0";
1875
- }
1876
- } catch (e) {
1877
- }
1878
- function HistoryRouter({
1879
- basename,
1880
- children,
1881
- history
1882
- }) {
1883
- let [state, setStateImpl] = React10.useState({
1884
- action: history.action,
1885
- location: history.location
1886
- });
1887
- let setState = React10.useCallback(
1888
- (newState) => {
1889
- React10.startTransition(() => setStateImpl(newState));
1890
- },
1891
- [setStateImpl]
1892
- );
1893
- React10.useLayoutEffect(() => history.listen(setState), [history, setState]);
1894
- return /* @__PURE__ */ React10.createElement(
1895
- Router,
1896
- {
1897
- basename,
1898
- children,
1899
- location: state.location,
1900
- navigationType: state.action,
1901
- navigator: history
1902
- }
1903
- );
1904
- }
1905
- HistoryRouter.displayName = "unstable_HistoryRouter";
1906
- var ABSOLUTE_URL_REGEX2 = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
1907
- var Link = React10.forwardRef(
1908
- function LinkWithRef({
1909
- onClick,
1910
- discover = "render",
1911
- prefetch = "none",
1912
- relative,
1913
- reloadDocument,
1914
- replace: replace2,
1915
- state,
1916
- target,
1917
- to,
1918
- preventScrollReset,
1919
- viewTransition,
1920
- ...rest
1921
- }, forwardedRef) {
1922
- let { basename } = React10.useContext(NavigationContext);
1923
- let isAbsolute = typeof to === "string" && ABSOLUTE_URL_REGEX2.test(to);
1924
- let absoluteHref;
1925
- let isExternal = false;
1926
- if (typeof to === "string" && isAbsolute) {
1927
- absoluteHref = to;
1928
- if (isBrowser) {
1929
- try {
1930
- let currentUrl = new URL(window.location.href);
1931
- let targetUrl = to.startsWith("//") ? new URL(currentUrl.protocol + to) : new URL(to);
1932
- let path = stripBasename(targetUrl.pathname, basename);
1933
- if (targetUrl.origin === currentUrl.origin && path != null) {
1934
- to = path + targetUrl.search + targetUrl.hash;
1935
- } else {
1936
- isExternal = true;
1937
- }
1938
- } catch (e) {
1939
- warning(
1940
- false,
1941
- `<Link to="${to}"> contains an invalid URL which will probably break when clicked - please update to a valid URL path.`
1942
- );
1943
- }
1944
- }
1945
- }
1946
- let href = useHref(to, { relative });
1947
- let [shouldPrefetch, prefetchRef, prefetchHandlers] = usePrefetchBehavior(
1948
- prefetch,
1949
- rest
1950
- );
1951
- let internalOnClick = useLinkClickHandler(to, {
1952
- replace: replace2,
1953
- state,
1954
- target,
1955
- preventScrollReset,
1956
- relative,
1957
- viewTransition
1958
- });
1959
- function handleClick(event) {
1960
- if (onClick) onClick(event);
1961
- if (!event.defaultPrevented) {
1962
- internalOnClick(event);
1963
- }
1964
- }
1965
- let link = (
1966
- // eslint-disable-next-line jsx-a11y/anchor-has-content
1967
- /* @__PURE__ */ React10.createElement(
1968
- "a",
1969
- {
1970
- ...rest,
1971
- ...prefetchHandlers,
1972
- href: absoluteHref || href,
1973
- onClick: isExternal || reloadDocument ? onClick : handleClick,
1974
- ref: mergeRefs(forwardedRef, prefetchRef),
1975
- target,
1976
- "data-discover": !isAbsolute && discover === "render" ? "true" : void 0
1977
- }
1978
- )
1979
- );
1980
- return shouldPrefetch && !isAbsolute ? /* @__PURE__ */ React10.createElement(React10.Fragment, null, link, /* @__PURE__ */ React10.createElement(PrefetchPageLinks, { page: href })) : link;
1981
- }
1982
- );
1983
- Link.displayName = "Link";
1984
- var NavLink = React10.forwardRef(
1985
- function NavLinkWithRef({
1986
- "aria-current": ariaCurrentProp = "page",
1987
- caseSensitive = false,
1988
- className: classNameProp = "",
1989
- end = false,
1990
- style: styleProp,
1991
- to,
1992
- viewTransition,
1993
- children,
1994
- ...rest
1995
- }, ref) {
1996
- let path = useResolvedPath(to, { relative: rest.relative });
1997
- let location = useLocation();
1998
- let routerState = React10.useContext(DataRouterStateContext);
1999
- let { navigator, basename } = React10.useContext(NavigationContext);
2000
- let isTransitioning = routerState != null && // Conditional usage is OK here because the usage of a data router is static
2001
- // eslint-disable-next-line react-hooks/rules-of-hooks
2002
- useViewTransitionState(path) && viewTransition === true;
2003
- let toPathname = navigator.encodeLocation ? navigator.encodeLocation(path).pathname : path.pathname;
2004
- let locationPathname = location.pathname;
2005
- let nextLocationPathname = routerState && routerState.navigation && routerState.navigation.location ? routerState.navigation.location.pathname : null;
2006
- if (!caseSensitive) {
2007
- locationPathname = locationPathname.toLowerCase();
2008
- nextLocationPathname = nextLocationPathname ? nextLocationPathname.toLowerCase() : null;
2009
- toPathname = toPathname.toLowerCase();
2010
- }
2011
- if (nextLocationPathname && basename) {
2012
- nextLocationPathname = stripBasename(nextLocationPathname, basename) || nextLocationPathname;
2013
- }
2014
- const endSlashPosition = toPathname !== "/" && toPathname.endsWith("/") ? toPathname.length - 1 : toPathname.length;
2015
- let isActive = locationPathname === toPathname || !end && locationPathname.startsWith(toPathname) && locationPathname.charAt(endSlashPosition) === "/";
2016
- let isPending = nextLocationPathname != null && (nextLocationPathname === toPathname || !end && nextLocationPathname.startsWith(toPathname) && nextLocationPathname.charAt(toPathname.length) === "/");
2017
- let renderProps = {
2018
- isActive,
2019
- isPending,
2020
- isTransitioning
2021
- };
2022
- let ariaCurrent = isActive ? ariaCurrentProp : void 0;
2023
- let className;
2024
- if (typeof classNameProp === "function") {
2025
- className = classNameProp(renderProps);
2026
- } else {
2027
- className = [
2028
- classNameProp,
2029
- isActive ? "active" : null,
2030
- isPending ? "pending" : null,
2031
- isTransitioning ? "transitioning" : null
2032
- ].filter(Boolean).join(" ");
2033
- }
2034
- let style = typeof styleProp === "function" ? styleProp(renderProps) : styleProp;
2035
- return /* @__PURE__ */ React10.createElement(
2036
- Link,
2037
- {
2038
- ...rest,
2039
- "aria-current": ariaCurrent,
2040
- className,
2041
- ref,
2042
- style,
2043
- to,
2044
- viewTransition
2045
- },
2046
- typeof children === "function" ? children(renderProps) : children
2047
- );
2048
- }
2049
- );
2050
- NavLink.displayName = "NavLink";
2051
- var Form = React10.forwardRef(
2052
- ({
2053
- discover = "render",
2054
- fetcherKey,
2055
- navigate,
2056
- reloadDocument,
2057
- replace: replace2,
2058
- state,
2059
- method = defaultMethod,
2060
- action,
2061
- onSubmit,
2062
- relative,
2063
- preventScrollReset,
2064
- viewTransition,
2065
- ...props
2066
- }, forwardedRef) => {
2067
- let submit = useSubmit();
2068
- let formAction = useFormAction(action, { relative });
2069
- let formMethod = method.toLowerCase() === "get" ? "get" : "post";
2070
- let isAbsolute = typeof action === "string" && ABSOLUTE_URL_REGEX2.test(action);
2071
- let submitHandler = (event) => {
2072
- onSubmit && onSubmit(event);
2073
- if (event.defaultPrevented) return;
2074
- event.preventDefault();
2075
- let submitter = event.nativeEvent.submitter;
2076
- let submitMethod = submitter?.getAttribute("formmethod") || method;
2077
- submit(submitter || event.currentTarget, {
2078
- fetcherKey,
2079
- method: submitMethod,
2080
- navigate,
2081
- replace: replace2,
2082
- state,
2083
- relative,
2084
- preventScrollReset,
2085
- viewTransition
2086
- });
2087
- };
2088
- return /* @__PURE__ */ React10.createElement(
2089
- "form",
2090
- {
2091
- ref: forwardedRef,
2092
- method: formMethod,
2093
- action: formAction,
2094
- onSubmit: reloadDocument ? onSubmit : submitHandler,
2095
- ...props,
2096
- "data-discover": !isAbsolute && discover === "render" ? "true" : void 0
2097
- }
2098
- );
2099
- }
2100
- );
2101
- Form.displayName = "Form";
2102
- function ScrollRestoration({
2103
- getKey,
2104
- storageKey,
2105
- ...props
2106
- }) {
2107
- let remixContext = React10.useContext(FrameworkContext);
2108
- let { basename } = React10.useContext(NavigationContext);
2109
- let location = useLocation();
2110
- let matches = useMatches();
2111
- useScrollRestoration({ getKey, storageKey });
2112
- let ssrKey = React10.useMemo(
2113
- () => {
2114
- if (!remixContext || !getKey) return null;
2115
- let userKey = getScrollRestorationKey(
2116
- location,
2117
- matches,
2118
- basename,
2119
- getKey
2120
- );
2121
- return userKey !== location.key ? userKey : null;
2122
- },
2123
- // Nah, we only need this the first time for the SSR render
2124
- // eslint-disable-next-line react-hooks/exhaustive-deps
2125
- []
2126
- );
2127
- if (!remixContext || remixContext.isSpaMode) {
2128
- return null;
2129
- }
2130
- let restoreScroll = ((storageKey2, restoreKey) => {
2131
- if (!window.history.state || !window.history.state.key) {
2132
- let key = Math.random().toString(32).slice(2);
2133
- window.history.replaceState({ key }, "");
2134
- }
2135
- try {
2136
- let positions = JSON.parse(sessionStorage.getItem(storageKey2) || "{}");
2137
- let storedY = positions[restoreKey || window.history.state.key];
2138
- if (typeof storedY === "number") {
2139
- window.scrollTo(0, storedY);
2140
- }
2141
- } catch (error) {
2142
- console.error(error);
2143
- sessionStorage.removeItem(storageKey2);
2144
- }
2145
- }).toString();
2146
- return /* @__PURE__ */ React10.createElement(
2147
- "script",
2148
- {
2149
- ...props,
2150
- suppressHydrationWarning: true,
2151
- dangerouslySetInnerHTML: {
2152
- __html: `(${restoreScroll})(${JSON.stringify(
2153
- storageKey || SCROLL_RESTORATION_STORAGE_KEY
2154
- )}, ${JSON.stringify(ssrKey)})`
2155
- }
2156
- }
2157
- );
2158
- }
2159
- ScrollRestoration.displayName = "ScrollRestoration";
2160
- function getDataRouterConsoleError2(hookName) {
2161
- return `${hookName} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`;
2162
- }
2163
- function useDataRouterContext3(hookName) {
2164
- let ctx = React10.useContext(DataRouterContext);
2165
- invariant(ctx, getDataRouterConsoleError2(hookName));
2166
- return ctx;
2167
- }
2168
- function useDataRouterState2(hookName) {
2169
- let state = React10.useContext(DataRouterStateContext);
2170
- invariant(state, getDataRouterConsoleError2(hookName));
2171
- return state;
2172
- }
2173
- function useLinkClickHandler(to, {
2174
- target,
2175
- replace: replaceProp,
2176
- state,
2177
- preventScrollReset,
2178
- relative,
2179
- viewTransition
2180
- } = {}) {
2181
- let navigate = useNavigate();
2182
- let location = useLocation();
2183
- let path = useResolvedPath(to, { relative });
2184
- return React10.useCallback(
2185
- (event) => {
2186
- if (shouldProcessLinkClick(event, target)) {
2187
- event.preventDefault();
2188
- let replace2 = replaceProp !== void 0 ? replaceProp : createPath(location) === createPath(path);
2189
- navigate(to, {
2190
- replace: replace2,
2191
- state,
2192
- preventScrollReset,
2193
- relative,
2194
- viewTransition
2195
- });
2196
- }
2197
- },
2198
- [
2199
- location,
2200
- navigate,
2201
- path,
2202
- replaceProp,
2203
- state,
2204
- target,
2205
- to,
2206
- preventScrollReset,
2207
- relative,
2208
- viewTransition
2209
- ]
2210
- );
2211
- }
2212
- var fetcherId = 0;
2213
- var getUniqueFetcherId = () => `__${String(++fetcherId)}__`;
2214
- function useSubmit() {
2215
- let { router } = useDataRouterContext3(
2216
- "useSubmit"
2217
- /* UseSubmit */
2218
- );
2219
- let { basename } = React10.useContext(NavigationContext);
2220
- let currentRouteId = useRouteId();
2221
- return React10.useCallback(
2222
- async (target, options = {}) => {
2223
- let { action, method, encType, formData, body } = getFormSubmissionInfo(
2224
- target,
2225
- basename
2226
- );
2227
- if (options.navigate === false) {
2228
- let key = options.fetcherKey || getUniqueFetcherId();
2229
- await router.fetch(key, currentRouteId, options.action || action, {
2230
- preventScrollReset: options.preventScrollReset,
2231
- formData,
2232
- body,
2233
- formMethod: options.method || method,
2234
- formEncType: options.encType || encType,
2235
- flushSync: options.flushSync
2236
- });
2237
- } else {
2238
- await router.navigate(options.action || action, {
2239
- preventScrollReset: options.preventScrollReset,
2240
- formData,
2241
- body,
2242
- formMethod: options.method || method,
2243
- formEncType: options.encType || encType,
2244
- replace: options.replace,
2245
- state: options.state,
2246
- fromRouteId: currentRouteId,
2247
- flushSync: options.flushSync,
2248
- viewTransition: options.viewTransition
2249
- });
2250
- }
2251
- },
2252
- [router, basename, currentRouteId]
2253
- );
2254
- }
2255
- function useFormAction(action, { relative } = {}) {
2256
- let { basename } = React10.useContext(NavigationContext);
2257
- let routeContext = React10.useContext(RouteContext);
2258
- invariant(routeContext, "useFormAction must be used inside a RouteContext");
2259
- let [match] = routeContext.matches.slice(-1);
2260
- let path = { ...useResolvedPath(action ? action : ".", { relative }) };
2261
- let location = useLocation();
2262
- if (action == null) {
2263
- path.search = location.search;
2264
- let params = new URLSearchParams(path.search);
2265
- let indexValues = params.getAll("index");
2266
- let hasNakedIndexParam = indexValues.some((v) => v === "");
2267
- if (hasNakedIndexParam) {
2268
- params.delete("index");
2269
- indexValues.filter((v) => v).forEach((v) => params.append("index", v));
2270
- let qs = params.toString();
2271
- path.search = qs ? `?${qs}` : "";
2272
- }
2273
- }
2274
- if ((!action || action === ".") && match.route.index) {
2275
- path.search = path.search ? path.search.replace(/^\?/, "?index&") : "?index";
2276
- }
2277
- if (basename !== "/") {
2278
- path.pathname = path.pathname === "/" ? basename : joinPaths([basename, path.pathname]);
2279
- }
2280
- return createPath(path);
2281
- }
2282
- var SCROLL_RESTORATION_STORAGE_KEY = "react-router-scroll-positions";
2283
- var savedScrollPositions = {};
2284
- function getScrollRestorationKey(location, matches, basename, getKey) {
2285
- let key = null;
2286
- if (getKey) {
2287
- if (basename !== "/") {
2288
- key = getKey(
2289
- {
2290
- ...location,
2291
- pathname: stripBasename(location.pathname, basename) || location.pathname
2292
- },
2293
- matches
2294
- );
2295
- } else {
2296
- key = getKey(location, matches);
2297
- }
2298
- }
2299
- if (key == null) {
2300
- key = location.key;
2301
- }
2302
- return key;
2303
- }
2304
- function useScrollRestoration({
2305
- getKey,
2306
- storageKey
2307
- } = {}) {
2308
- let { router } = useDataRouterContext3(
2309
- "useScrollRestoration"
2310
- /* UseScrollRestoration */
2311
- );
2312
- let { restoreScrollPosition, preventScrollReset } = useDataRouterState2(
2313
- "useScrollRestoration"
2314
- /* UseScrollRestoration */
2315
- );
2316
- let { basename } = React10.useContext(NavigationContext);
2317
- let location = useLocation();
2318
- let matches = useMatches();
2319
- let navigation = useNavigation();
2320
- React10.useEffect(() => {
2321
- window.history.scrollRestoration = "manual";
2322
- return () => {
2323
- window.history.scrollRestoration = "auto";
2324
- };
2325
- }, []);
2326
- usePageHide(
2327
- React10.useCallback(() => {
2328
- if (navigation.state === "idle") {
2329
- let key = getScrollRestorationKey(location, matches, basename, getKey);
2330
- savedScrollPositions[key] = window.scrollY;
2331
- }
2332
- try {
2333
- sessionStorage.setItem(
2334
- storageKey || SCROLL_RESTORATION_STORAGE_KEY,
2335
- JSON.stringify(savedScrollPositions)
2336
- );
2337
- } catch (error) {
2338
- warning(
2339
- false,
2340
- `Failed to save scroll positions in sessionStorage, <ScrollRestoration /> will not work properly (${error}).`
2341
- );
2342
- }
2343
- window.history.scrollRestoration = "auto";
2344
- }, [navigation.state, getKey, basename, location, matches, storageKey])
2345
- );
2346
- if (typeof document !== "undefined") {
2347
- React10.useLayoutEffect(() => {
2348
- try {
2349
- let sessionPositions = sessionStorage.getItem(
2350
- storageKey || SCROLL_RESTORATION_STORAGE_KEY
2351
- );
2352
- if (sessionPositions) {
2353
- savedScrollPositions = JSON.parse(sessionPositions);
2354
- }
2355
- } catch (e) {
2356
- }
2357
- }, [storageKey]);
2358
- React10.useLayoutEffect(() => {
2359
- let disableScrollRestoration = router?.enableScrollRestoration(
2360
- savedScrollPositions,
2361
- () => window.scrollY,
2362
- getKey ? (location2, matches2) => getScrollRestorationKey(location2, matches2, basename, getKey) : void 0
2363
- );
2364
- return () => disableScrollRestoration && disableScrollRestoration();
2365
- }, [router, basename, getKey]);
2366
- React10.useLayoutEffect(() => {
2367
- if (restoreScrollPosition === false) {
2368
- return;
2369
- }
2370
- if (typeof restoreScrollPosition === "number") {
2371
- window.scrollTo(0, restoreScrollPosition);
2372
- return;
2373
- }
2374
- try {
2375
- if (location.hash) {
2376
- let el = document.getElementById(
2377
- decodeURIComponent(location.hash.slice(1))
2378
- );
2379
- if (el) {
2380
- el.scrollIntoView();
2381
- return;
2382
- }
2383
- }
2384
- } catch {
2385
- warning(
2386
- false,
2387
- `"${location.hash.slice(
2388
- 1
2389
- )}" is not a decodable element ID. The view will not scroll to it.`
2390
- );
2391
- }
2392
- if (preventScrollReset === true) {
2393
- return;
2394
- }
2395
- window.scrollTo(0, 0);
2396
- }, [location, restoreScrollPosition, preventScrollReset]);
2397
- }
2398
- }
2399
- function usePageHide(callback, options) {
2400
- let { capture } = options || {};
2401
- React10.useEffect(() => {
2402
- let opts = capture != null ? { capture } : void 0;
2403
- window.addEventListener("pagehide", callback, opts);
2404
- return () => {
2405
- window.removeEventListener("pagehide", callback, opts);
2406
- };
2407
- }, [callback, capture]);
2408
- }
2409
- function useViewTransitionState(to, opts = {}) {
2410
- let vtContext = React10.useContext(ViewTransitionContext);
2411
- invariant(
2412
- vtContext != null,
2413
- "`useViewTransitionState` must be used within `react-router-dom`'s `RouterProvider`. Did you accidentally import `RouterProvider` from `react-router`?"
2414
- );
2415
- let { basename } = useDataRouterContext3(
2416
- "useViewTransitionState"
2417
- /* useViewTransitionState */
2418
- );
2419
- let path = useResolvedPath(to, { relative: opts.relative });
2420
- if (!vtContext.isTransitioning) {
2421
- return false;
2422
- }
2423
- let currentPath = stripBasename(vtContext.currentLocation.pathname, basename) || vtContext.currentLocation.pathname;
2424
- let nextPath = stripBasename(vtContext.nextLocation.pathname, basename) || vtContext.nextLocation.pathname;
2425
- return matchPath(path.pathname, nextPath) != null || matchPath(path.pathname, currentPath) != null;
2426
- }
2427
-
2428
- export {
2429
- Outlet,
2430
- Links,
2431
- Meta,
2432
- Scripts,
2433
- Link,
2434
- ScrollRestoration
2435
- };
2436
- /*! Bundled license information:
2437
-
2438
- react-router/dist/development/chunk-EF7DTUVF.mjs:
2439
- react-router/dist/development/index.mjs:
2440
- (**
2441
- * react-router v7.7.0
2442
- *
2443
- * Copyright (c) Remix Software Inc.
2444
- *
2445
- * This source code is licensed under the MIT license found in the
2446
- * LICENSE.md file in the root directory of this source tree.
2447
- *
2448
- * @license MIT
2449
- *)
2450
- */
2451
- //# sourceMappingURL=chunk-EE5DCIH7.js.map