@axdspub/axiom-ui-forms 0.3.2 → 0.3.3-experimental.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/library/esm/_virtual/index10.js +2 -2
  2. package/library/esm/_virtual/index11.js +2 -2
  3. package/library/esm/_virtual/index12.js +2 -2
  4. package/library/esm/_virtual/index13.js +2 -2
  5. package/library/esm/_virtual/index15.js +2 -2
  6. package/library/esm/_virtual/index8.js +2 -2
  7. package/library/esm/_virtual/index8.js.map +1 -1
  8. package/library/esm/_virtual/index9.js +2 -2
  9. package/library/esm/node_modules/ajv/dist/compile/index.js +1 -1
  10. package/library/esm/node_modules/ajv/dist/vocabularies/applicator/index.js +1 -1
  11. package/library/esm/node_modules/ajv/dist/vocabularies/core/index.js +1 -1
  12. package/library/esm/node_modules/ajv/dist/vocabularies/format/index.js +1 -1
  13. package/library/esm/node_modules/ajv/dist/vocabularies/validation/index.js +1 -1
  14. package/library/esm/node_modules/json-schema-traverse/index.js +1 -1
  15. package/library/esm/node_modules/style-to-object/cjs/index.js +1 -1
  16. package/library/esm/src/Form/Creator/FormContextProvider.js +2 -2
  17. package/library/esm/src/Form/Creator/FormContextProvider.js.map +1 -1
  18. package/library/esm/src/Form/Creator/NavElement.js +1 -1
  19. package/library/esm/src/Form/Creator/Page.js +1 -1
  20. package/library/esm/src/Form/Creator/Wizard.js +1 -1
  21. package/package.json +8 -2
  22. package/library/esm/_virtual/index16.js +0 -4
  23. package/library/esm/_virtual/index16.js.map +0 -1
  24. package/library/esm/_virtual/index17.js +0 -4
  25. package/library/esm/_virtual/index17.js.map +0 -1
  26. package/library/esm/node_modules/react-router/dist/development/chunk-NL6KNZEE.js +0 -1731
  27. package/library/esm/node_modules/react-router/dist/development/chunk-NL6KNZEE.js.map +0 -1
  28. package/library/esm/node_modules/react-router/node_modules/cookie/dist/index.js +0 -250
  29. package/library/esm/node_modules/react-router/node_modules/cookie/dist/index.js.map +0 -1
@@ -1,1731 +0,0 @@
1
- import * as React from 'react';
2
- import '../../../../_virtual/index8.js';
3
-
4
- /**
5
- * react-router v7.6.2
6
- *
7
- * Copyright (c) Remix Software Inc.
8
- *
9
- * This source code is licensed under the MIT license found in the
10
- * LICENSE.md file in the root directory of this source tree.
11
- *
12
- * @license MIT
13
- */
14
- function invariant(value, message) {
15
- if (value === false || value === null || typeof value === "undefined") {
16
- throw new Error(message);
17
- }
18
- }
19
- function warning(cond, message) {
20
- if (!cond) {
21
- if (typeof console !== "undefined") console.warn(message);
22
- try {
23
- throw new Error(message);
24
- } catch (e) {
25
- }
26
- }
27
- }
28
- function createPath({
29
- pathname = "/",
30
- search = "",
31
- hash = ""
32
- }) {
33
- if (search && search !== "?")
34
- pathname += search.charAt(0) === "?" ? search : "?" + search;
35
- if (hash && hash !== "#")
36
- pathname += hash.charAt(0) === "#" ? hash : "#" + hash;
37
- return pathname;
38
- }
39
- function parsePath(path) {
40
- let parsedPath = {};
41
- if (path) {
42
- let hashIndex = path.indexOf("#");
43
- if (hashIndex >= 0) {
44
- parsedPath.hash = path.substring(hashIndex);
45
- path = path.substring(0, hashIndex);
46
- }
47
- let searchIndex = path.indexOf("?");
48
- if (searchIndex >= 0) {
49
- parsedPath.search = path.substring(searchIndex);
50
- path = path.substring(0, searchIndex);
51
- }
52
- if (path) {
53
- parsedPath.pathname = path;
54
- }
55
- }
56
- return parsedPath;
57
- }
58
- function matchRoutes(routes, locationArg, basename = "/") {
59
- return matchRoutesImpl(routes, locationArg, basename, false);
60
- }
61
- function matchRoutesImpl(routes, locationArg, basename, allowPartial) {
62
- let location = typeof locationArg === "string" ? parsePath(locationArg) : locationArg;
63
- let pathname = stripBasename(location.pathname || "/", basename);
64
- if (pathname == null) {
65
- return null;
66
- }
67
- let branches = flattenRoutes(routes);
68
- rankRouteBranches(branches);
69
- let matches = null;
70
- for (let i = 0; matches == null && i < branches.length; ++i) {
71
- let decoded = decodePath(pathname);
72
- matches = matchRouteBranch(
73
- branches[i],
74
- decoded,
75
- allowPartial
76
- );
77
- }
78
- return matches;
79
- }
80
- function flattenRoutes(routes, branches = [], parentsMeta = [], parentPath = "") {
81
- let flattenRoute = (route, index, relativePath) => {
82
- let meta = {
83
- relativePath: relativePath === void 0 ? route.path || "" : relativePath,
84
- caseSensitive: route.caseSensitive === true,
85
- childrenIndex: index,
86
- route
87
- };
88
- if (meta.relativePath.startsWith("/")) {
89
- invariant(
90
- meta.relativePath.startsWith(parentPath),
91
- `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.`
92
- );
93
- meta.relativePath = meta.relativePath.slice(parentPath.length);
94
- }
95
- let path = joinPaths([parentPath, meta.relativePath]);
96
- let routesMeta = parentsMeta.concat(meta);
97
- if (route.children && route.children.length > 0) {
98
- invariant(
99
- // Our types know better, but runtime JS may not!
100
- // @ts-expect-error
101
- route.index !== true,
102
- `Index routes must not have child routes. Please remove all child routes from route path "${path}".`
103
- );
104
- flattenRoutes(route.children, branches, routesMeta, path);
105
- }
106
- if (route.path == null && !route.index) {
107
- return;
108
- }
109
- branches.push({
110
- path,
111
- score: computeScore(path, route.index),
112
- routesMeta
113
- });
114
- };
115
- routes.forEach((route, index) => {
116
- if (route.path === "" || !route.path?.includes("?")) {
117
- flattenRoute(route, index);
118
- } else {
119
- for (let exploded of explodeOptionalSegments(route.path)) {
120
- flattenRoute(route, index, exploded);
121
- }
122
- }
123
- });
124
- return branches;
125
- }
126
- function explodeOptionalSegments(path) {
127
- let segments = path.split("/");
128
- if (segments.length === 0) return [];
129
- let [first, ...rest] = segments;
130
- let isOptional = first.endsWith("?");
131
- let required = first.replace(/\?$/, "");
132
- if (rest.length === 0) {
133
- return isOptional ? [required, ""] : [required];
134
- }
135
- let restExploded = explodeOptionalSegments(rest.join("/"));
136
- let result = [];
137
- result.push(
138
- ...restExploded.map(
139
- (subpath) => subpath === "" ? required : [required, subpath].join("/")
140
- )
141
- );
142
- if (isOptional) {
143
- result.push(...restExploded);
144
- }
145
- return result.map(
146
- (exploded) => path.startsWith("/") && exploded === "" ? "/" : exploded
147
- );
148
- }
149
- function rankRouteBranches(branches) {
150
- branches.sort(
151
- (a, b) => a.score !== b.score ? b.score - a.score : compareIndexes(
152
- a.routesMeta.map((meta) => meta.childrenIndex),
153
- b.routesMeta.map((meta) => meta.childrenIndex)
154
- )
155
- );
156
- }
157
- var paramRe = /^:[\w-]+$/;
158
- var dynamicSegmentValue = 3;
159
- var indexRouteValue = 2;
160
- var emptySegmentValue = 1;
161
- var staticSegmentValue = 10;
162
- var splatPenalty = -2;
163
- var isSplat = (s) => s === "*";
164
- function computeScore(path, index) {
165
- let segments = path.split("/");
166
- let initialScore = segments.length;
167
- if (segments.some(isSplat)) {
168
- initialScore += splatPenalty;
169
- }
170
- if (index) {
171
- initialScore += indexRouteValue;
172
- }
173
- return segments.filter((s) => !isSplat(s)).reduce(
174
- (score, segment) => score + (paramRe.test(segment) ? dynamicSegmentValue : segment === "" ? emptySegmentValue : staticSegmentValue),
175
- initialScore
176
- );
177
- }
178
- function compareIndexes(a, b) {
179
- let siblings = a.length === b.length && a.slice(0, -1).every((n, i) => n === b[i]);
180
- return siblings ? (
181
- // If two routes are siblings, we should try to match the earlier sibling
182
- // first. This allows people to have fine-grained control over the matching
183
- // behavior by simply putting routes with identical paths in the order they
184
- // want them tried.
185
- a[a.length - 1] - b[b.length - 1]
186
- ) : (
187
- // Otherwise, it doesn't really make sense to rank non-siblings by index,
188
- // so they sort equally.
189
- 0
190
- );
191
- }
192
- function matchRouteBranch(branch, pathname, allowPartial = false) {
193
- let { routesMeta } = branch;
194
- let matchedParams = {};
195
- let matchedPathname = "/";
196
- let matches = [];
197
- for (let i = 0; i < routesMeta.length; ++i) {
198
- let meta = routesMeta[i];
199
- let end = i === routesMeta.length - 1;
200
- let remainingPathname = matchedPathname === "/" ? pathname : pathname.slice(matchedPathname.length) || "/";
201
- let match = matchPath(
202
- { path: meta.relativePath, caseSensitive: meta.caseSensitive, end },
203
- remainingPathname
204
- );
205
- let route = meta.route;
206
- if (!match && end && allowPartial && !routesMeta[routesMeta.length - 1].route.index) {
207
- match = matchPath(
208
- {
209
- path: meta.relativePath,
210
- caseSensitive: meta.caseSensitive,
211
- end: false
212
- },
213
- remainingPathname
214
- );
215
- }
216
- if (!match) {
217
- return null;
218
- }
219
- Object.assign(matchedParams, match.params);
220
- matches.push({
221
- // TODO: Can this as be avoided?
222
- params: matchedParams,
223
- pathname: joinPaths([matchedPathname, match.pathname]),
224
- pathnameBase: normalizePathname(
225
- joinPaths([matchedPathname, match.pathnameBase])
226
- ),
227
- route
228
- });
229
- if (match.pathnameBase !== "/") {
230
- matchedPathname = joinPaths([matchedPathname, match.pathnameBase]);
231
- }
232
- }
233
- return matches;
234
- }
235
- function matchPath(pattern, pathname) {
236
- if (typeof pattern === "string") {
237
- pattern = { path: pattern, caseSensitive: false, end: true };
238
- }
239
- let [matcher, compiledParams] = compilePath(
240
- pattern.path,
241
- pattern.caseSensitive,
242
- pattern.end
243
- );
244
- let match = pathname.match(matcher);
245
- if (!match) return null;
246
- let matchedPathname = match[0];
247
- let pathnameBase = matchedPathname.replace(/(.)\/+$/, "$1");
248
- let captureGroups = match.slice(1);
249
- let params = compiledParams.reduce(
250
- (memo2, { paramName, isOptional }, index) => {
251
- if (paramName === "*") {
252
- let splatValue = captureGroups[index] || "";
253
- pathnameBase = matchedPathname.slice(0, matchedPathname.length - splatValue.length).replace(/(.)\/+$/, "$1");
254
- }
255
- const value = captureGroups[index];
256
- if (isOptional && !value) {
257
- memo2[paramName] = void 0;
258
- } else {
259
- memo2[paramName] = (value || "").replace(/%2F/g, "/");
260
- }
261
- return memo2;
262
- },
263
- {}
264
- );
265
- return {
266
- params,
267
- pathname: matchedPathname,
268
- pathnameBase,
269
- pattern
270
- };
271
- }
272
- function compilePath(path, caseSensitive = false, end = true) {
273
- warning(
274
- path === "*" || !path.endsWith("*") || path.endsWith("/*"),
275
- `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(/\*$/, "/*")}".`
276
- );
277
- let params = [];
278
- let regexpSource = "^" + path.replace(/\/*\*?$/, "").replace(/^\/*/, "/").replace(/[\\.*+^${}|()[\]]/g, "\\$&").replace(
279
- /\/:([\w-]+)(\?)?/g,
280
- (_, paramName, isOptional) => {
281
- params.push({ paramName, isOptional: isOptional != null });
282
- return isOptional ? "/?([^\\/]+)?" : "/([^\\/]+)";
283
- }
284
- );
285
- if (path.endsWith("*")) {
286
- params.push({ paramName: "*" });
287
- regexpSource += path === "*" || path === "/*" ? "(.*)$" : "(?:\\/(.+)|\\/*)$";
288
- } else if (end) {
289
- regexpSource += "\\/*$";
290
- } else if (path !== "" && path !== "/") {
291
- regexpSource += "(?:(?=\\/|$))";
292
- } else ;
293
- let matcher = new RegExp(regexpSource, caseSensitive ? void 0 : "i");
294
- return [matcher, params];
295
- }
296
- function decodePath(value) {
297
- try {
298
- return value.split("/").map((v) => decodeURIComponent(v).replace(/\//g, "%2F")).join("/");
299
- } catch (error) {
300
- warning(
301
- false,
302
- `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}).`
303
- );
304
- return value;
305
- }
306
- }
307
- function stripBasename(pathname, basename) {
308
- if (basename === "/") return pathname;
309
- if (!pathname.toLowerCase().startsWith(basename.toLowerCase())) {
310
- return null;
311
- }
312
- let startIndex = basename.endsWith("/") ? basename.length - 1 : basename.length;
313
- let nextChar = pathname.charAt(startIndex);
314
- if (nextChar && nextChar !== "/") {
315
- return null;
316
- }
317
- return pathname.slice(startIndex) || "/";
318
- }
319
- function resolvePath(to, fromPathname = "/") {
320
- let {
321
- pathname: toPathname,
322
- search = "",
323
- hash = ""
324
- } = typeof to === "string" ? parsePath(to) : to;
325
- let pathname = toPathname ? toPathname.startsWith("/") ? toPathname : resolvePathname(toPathname, fromPathname) : fromPathname;
326
- return {
327
- pathname,
328
- search: normalizeSearch(search),
329
- hash: normalizeHash(hash)
330
- };
331
- }
332
- function resolvePathname(relativePath, fromPathname) {
333
- let segments = fromPathname.replace(/\/+$/, "").split("/");
334
- let relativeSegments = relativePath.split("/");
335
- relativeSegments.forEach((segment) => {
336
- if (segment === "..") {
337
- if (segments.length > 1) segments.pop();
338
- } else if (segment !== ".") {
339
- segments.push(segment);
340
- }
341
- });
342
- return segments.length > 1 ? segments.join("/") : "/";
343
- }
344
- function getInvalidPathError(char, field, dest, path) {
345
- return `Cannot include a '${char}' character in a manually specified \`to.${field}\` field [${JSON.stringify(
346
- path
347
- )}]. 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.`;
348
- }
349
- function getPathContributingMatches(matches) {
350
- return matches.filter(
351
- (match, index) => index === 0 || match.route.path && match.route.path.length > 0
352
- );
353
- }
354
- function getResolveToMatches(matches) {
355
- let pathMatches = getPathContributingMatches(matches);
356
- return pathMatches.map(
357
- (match, idx) => idx === pathMatches.length - 1 ? match.pathname : match.pathnameBase
358
- );
359
- }
360
- function resolveTo(toArg, routePathnames, locationPathname, isPathRelative = false) {
361
- let to;
362
- if (typeof toArg === "string") {
363
- to = parsePath(toArg);
364
- } else {
365
- to = { ...toArg };
366
- invariant(
367
- !to.pathname || !to.pathname.includes("?"),
368
- getInvalidPathError("?", "pathname", "search", to)
369
- );
370
- invariant(
371
- !to.pathname || !to.pathname.includes("#"),
372
- getInvalidPathError("#", "pathname", "hash", to)
373
- );
374
- invariant(
375
- !to.search || !to.search.includes("#"),
376
- getInvalidPathError("#", "search", "hash", to)
377
- );
378
- }
379
- let isEmptyPath = toArg === "" || to.pathname === "";
380
- let toPathname = isEmptyPath ? "/" : to.pathname;
381
- let from;
382
- if (toPathname == null) {
383
- from = locationPathname;
384
- } else {
385
- let routePathnameIndex = routePathnames.length - 1;
386
- if (!isPathRelative && toPathname.startsWith("..")) {
387
- let toSegments = toPathname.split("/");
388
- while (toSegments[0] === "..") {
389
- toSegments.shift();
390
- routePathnameIndex -= 1;
391
- }
392
- to.pathname = toSegments.join("/");
393
- }
394
- from = routePathnameIndex >= 0 ? routePathnames[routePathnameIndex] : "/";
395
- }
396
- let path = resolvePath(to, from);
397
- let hasExplicitTrailingSlash = toPathname && toPathname !== "/" && toPathname.endsWith("/");
398
- let hasCurrentTrailingSlash = (isEmptyPath || toPathname === ".") && locationPathname.endsWith("/");
399
- if (!path.pathname.endsWith("/") && (hasExplicitTrailingSlash || hasCurrentTrailingSlash)) {
400
- path.pathname += "/";
401
- }
402
- return path;
403
- }
404
- var joinPaths = (paths) => paths.join("/").replace(/\/\/+/g, "/");
405
- var normalizePathname = (pathname) => pathname.replace(/\/+$/, "").replace(/^\/*/, "/");
406
- var normalizeSearch = (search) => !search || search === "?" ? "" : search.startsWith("?") ? search : "?" + search;
407
- var normalizeHash = (hash) => !hash || hash === "#" ? "" : hash.startsWith("#") ? hash : "#" + hash;
408
- function isRouteErrorResponse(error) {
409
- return error != null && typeof error.status === "number" && typeof error.statusText === "string" && typeof error.internal === "boolean" && "data" in error;
410
- }
411
-
412
- // lib/router/router.ts
413
- var validMutationMethodsArr = [
414
- "POST",
415
- "PUT",
416
- "PATCH",
417
- "DELETE"
418
- ];
419
- new Set(
420
- validMutationMethodsArr
421
- );
422
- var validRequestMethodsArr = [
423
- "GET",
424
- ...validMutationMethodsArr
425
- ];
426
- new Set(validRequestMethodsArr);
427
- var DataRouterContext = React.createContext(null);
428
- DataRouterContext.displayName = "DataRouter";
429
- var DataRouterStateContext = React.createContext(null);
430
- DataRouterStateContext.displayName = "DataRouterState";
431
- var ViewTransitionContext = React.createContext({
432
- isTransitioning: false
433
- });
434
- ViewTransitionContext.displayName = "ViewTransition";
435
- var FetchersContext = React.createContext(
436
- /* @__PURE__ */ new Map()
437
- );
438
- FetchersContext.displayName = "Fetchers";
439
- var AwaitContext = React.createContext(null);
440
- AwaitContext.displayName = "Await";
441
- var NavigationContext = React.createContext(
442
- null
443
- );
444
- NavigationContext.displayName = "Navigation";
445
- var LocationContext = React.createContext(
446
- null
447
- );
448
- LocationContext.displayName = "Location";
449
- var RouteContext = React.createContext({
450
- outlet: null,
451
- matches: [],
452
- isDataRoute: false
453
- });
454
- RouteContext.displayName = "Route";
455
- var RouteErrorContext = React.createContext(null);
456
- RouteErrorContext.displayName = "RouteError";
457
- function useHref(to, { relative } = {}) {
458
- invariant(
459
- useInRouterContext(),
460
- // TODO: This error is probably because they somehow have 2 versions of the
461
- // router loaded. We can help them understand how to avoid that.
462
- `useHref() may be used only in the context of a <Router> component.`
463
- );
464
- let { basename, navigator } = React.useContext(NavigationContext);
465
- let { hash, pathname, search } = useResolvedPath(to, { relative });
466
- let joinedPathname = pathname;
467
- if (basename !== "/") {
468
- joinedPathname = pathname === "/" ? basename : joinPaths([basename, pathname]);
469
- }
470
- return navigator.createHref({ pathname: joinedPathname, search, hash });
471
- }
472
- function useInRouterContext() {
473
- return React.useContext(LocationContext) != null;
474
- }
475
- function useLocation() {
476
- invariant(
477
- useInRouterContext(),
478
- // TODO: This error is probably because they somehow have 2 versions of the
479
- // router loaded. We can help them understand how to avoid that.
480
- `useLocation() may be used only in the context of a <Router> component.`
481
- );
482
- return React.useContext(LocationContext).location;
483
- }
484
- var navigateEffectWarning = `You should call navigate() in a React.useEffect(), not when your component is first rendered.`;
485
- function useIsomorphicLayoutEffect(cb) {
486
- let isStatic = React.useContext(NavigationContext).static;
487
- if (!isStatic) {
488
- React.useLayoutEffect(cb);
489
- }
490
- }
491
- function useNavigate() {
492
- let { isDataRoute } = React.useContext(RouteContext);
493
- return isDataRoute ? useNavigateStable() : useNavigateUnstable();
494
- }
495
- function useNavigateUnstable() {
496
- invariant(
497
- useInRouterContext(),
498
- // TODO: This error is probably because they somehow have 2 versions of the
499
- // router loaded. We can help them understand how to avoid that.
500
- `useNavigate() may be used only in the context of a <Router> component.`
501
- );
502
- let dataRouterContext = React.useContext(DataRouterContext);
503
- let { basename, navigator } = React.useContext(NavigationContext);
504
- let { matches } = React.useContext(RouteContext);
505
- let { pathname: locationPathname } = useLocation();
506
- let routePathnamesJson = JSON.stringify(getResolveToMatches(matches));
507
- let activeRef = React.useRef(false);
508
- useIsomorphicLayoutEffect(() => {
509
- activeRef.current = true;
510
- });
511
- let navigate = React.useCallback(
512
- (to, options = {}) => {
513
- warning(activeRef.current, navigateEffectWarning);
514
- if (!activeRef.current) return;
515
- if (typeof to === "number") {
516
- navigator.go(to);
517
- return;
518
- }
519
- let path = resolveTo(
520
- to,
521
- JSON.parse(routePathnamesJson),
522
- locationPathname,
523
- options.relative === "path"
524
- );
525
- if (dataRouterContext == null && basename !== "/") {
526
- path.pathname = path.pathname === "/" ? basename : joinPaths([basename, path.pathname]);
527
- }
528
- (!!options.replace ? navigator.replace : navigator.push)(
529
- path,
530
- options.state,
531
- options
532
- );
533
- },
534
- [
535
- basename,
536
- navigator,
537
- routePathnamesJson,
538
- locationPathname,
539
- dataRouterContext
540
- ]
541
- );
542
- return navigate;
543
- }
544
- React.createContext(null);
545
- function useParams() {
546
- let { matches } = React.useContext(RouteContext);
547
- let routeMatch = matches[matches.length - 1];
548
- return routeMatch ? routeMatch.params : {};
549
- }
550
- function useResolvedPath(to, { relative } = {}) {
551
- let { matches } = React.useContext(RouteContext);
552
- let { pathname: locationPathname } = useLocation();
553
- let routePathnamesJson = JSON.stringify(getResolveToMatches(matches));
554
- return React.useMemo(
555
- () => resolveTo(
556
- to,
557
- JSON.parse(routePathnamesJson),
558
- locationPathname,
559
- relative === "path"
560
- ),
561
- [to, routePathnamesJson, locationPathname, relative]
562
- );
563
- }
564
- function useRoutesImpl(routes, locationArg, dataRouterState, future) {
565
- invariant(
566
- useInRouterContext(),
567
- // TODO: This error is probably because they somehow have 2 versions of the
568
- // router loaded. We can help them understand how to avoid that.
569
- `useRoutes() may be used only in the context of a <Router> component.`
570
- );
571
- let { navigator } = React.useContext(NavigationContext);
572
- let { matches: parentMatches } = React.useContext(RouteContext);
573
- let routeMatch = parentMatches[parentMatches.length - 1];
574
- let parentParams = routeMatch ? routeMatch.params : {};
575
- let parentPathname = routeMatch ? routeMatch.pathname : "/";
576
- let parentPathnameBase = routeMatch ? routeMatch.pathnameBase : "/";
577
- let parentRoute = routeMatch && routeMatch.route;
578
- {
579
- let parentPath = parentRoute && parentRoute.path || "";
580
- warningOnce(
581
- parentPathname,
582
- !parentRoute || parentPath.endsWith("*") || parentPath.endsWith("*?"),
583
- `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.
584
-
585
- Please change the parent <Route path="${parentPath}"> to <Route path="${parentPath === "/" ? "*" : `${parentPath}/*`}">.`
586
- );
587
- }
588
- let locationFromContext = useLocation();
589
- let location;
590
- {
591
- location = locationFromContext;
592
- }
593
- let pathname = location.pathname || "/";
594
- let remainingPathname = pathname;
595
- if (parentPathnameBase !== "/") {
596
- let parentSegments = parentPathnameBase.replace(/^\//, "").split("/");
597
- let segments = pathname.replace(/^\//, "").split("/");
598
- remainingPathname = "/" + segments.slice(parentSegments.length).join("/");
599
- }
600
- let matches = matchRoutes(routes, { pathname: remainingPathname });
601
- {
602
- warning(
603
- parentRoute || matches != null,
604
- `No routes matched location "${location.pathname}${location.search}${location.hash}" `
605
- );
606
- warning(
607
- 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,
608
- `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.`
609
- );
610
- }
611
- let renderedMatches = _renderMatches(
612
- matches && matches.map(
613
- (match) => Object.assign({}, match, {
614
- params: Object.assign({}, parentParams, match.params),
615
- pathname: joinPaths([
616
- parentPathnameBase,
617
- // Re-encode pathnames that were decoded inside matchRoutes
618
- navigator.encodeLocation ? navigator.encodeLocation(match.pathname).pathname : match.pathname
619
- ]),
620
- pathnameBase: match.pathnameBase === "/" ? parentPathnameBase : joinPaths([
621
- parentPathnameBase,
622
- // Re-encode pathnames that were decoded inside matchRoutes
623
- navigator.encodeLocation ? navigator.encodeLocation(match.pathnameBase).pathname : match.pathnameBase
624
- ])
625
- })
626
- ),
627
- parentMatches,
628
- dataRouterState,
629
- future
630
- );
631
- return renderedMatches;
632
- }
633
- function DefaultErrorComponent() {
634
- let error = useRouteError();
635
- let message = isRouteErrorResponse(error) ? `${error.status} ${error.statusText}` : error instanceof Error ? error.message : JSON.stringify(error);
636
- let stack = error instanceof Error ? error.stack : null;
637
- let lightgrey = "rgba(200,200,200, 0.5)";
638
- let preStyles = { padding: "0.5rem", backgroundColor: lightgrey };
639
- let codeStyles = { padding: "2px 4px", backgroundColor: lightgrey };
640
- let devInfo = null;
641
- {
642
- console.error(
643
- "Error handled by React Router default ErrorBoundary:",
644
- error
645
- );
646
- devInfo = /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("p", null, "\u{1F4BF} Hey developer \u{1F44B}"), /* @__PURE__ */ React.createElement("p", null, "You can provide a way better UX than this when your app throws errors by providing your own ", /* @__PURE__ */ React.createElement("code", { style: codeStyles }, "ErrorBoundary"), " or", " ", /* @__PURE__ */ React.createElement("code", { style: codeStyles }, "errorElement"), " prop on your route."));
647
- }
648
- return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("h2", null, "Unexpected Application Error!"), /* @__PURE__ */ React.createElement("h3", { style: { fontStyle: "italic" } }, message), stack ? /* @__PURE__ */ React.createElement("pre", { style: preStyles }, stack) : null, devInfo);
649
- }
650
- var defaultErrorElement = /* @__PURE__ */ React.createElement(DefaultErrorComponent, null);
651
- var RenderErrorBoundary = class extends React.Component {
652
- constructor(props) {
653
- super(props);
654
- this.state = {
655
- location: props.location,
656
- revalidation: props.revalidation,
657
- error: props.error
658
- };
659
- }
660
- static getDerivedStateFromError(error) {
661
- return { error };
662
- }
663
- static getDerivedStateFromProps(props, state) {
664
- if (state.location !== props.location || state.revalidation !== "idle" && props.revalidation === "idle") {
665
- return {
666
- error: props.error,
667
- location: props.location,
668
- revalidation: props.revalidation
669
- };
670
- }
671
- return {
672
- error: props.error !== void 0 ? props.error : state.error,
673
- location: state.location,
674
- revalidation: props.revalidation || state.revalidation
675
- };
676
- }
677
- componentDidCatch(error, errorInfo) {
678
- console.error(
679
- "React Router caught the following error during render",
680
- error,
681
- errorInfo
682
- );
683
- }
684
- render() {
685
- return this.state.error !== void 0 ? /* @__PURE__ */ React.createElement(RouteContext.Provider, { value: this.props.routeContext }, /* @__PURE__ */ React.createElement(
686
- RouteErrorContext.Provider,
687
- {
688
- value: this.state.error,
689
- children: this.props.component
690
- }
691
- )) : this.props.children;
692
- }
693
- };
694
- function RenderedRoute({ routeContext, match, children }) {
695
- let dataRouterContext = React.useContext(DataRouterContext);
696
- if (dataRouterContext && dataRouterContext.static && dataRouterContext.staticContext && (match.route.errorElement || match.route.ErrorBoundary)) {
697
- dataRouterContext.staticContext._deepestRenderedBoundaryId = match.route.id;
698
- }
699
- return /* @__PURE__ */ React.createElement(RouteContext.Provider, { value: routeContext }, children);
700
- }
701
- function _renderMatches(matches, parentMatches = [], dataRouterState = null, future = null) {
702
- if (matches == null) {
703
- if (!dataRouterState) {
704
- return null;
705
- }
706
- if (dataRouterState.errors) {
707
- matches = dataRouterState.matches;
708
- } else if (parentMatches.length === 0 && !dataRouterState.initialized && dataRouterState.matches.length > 0) {
709
- matches = dataRouterState.matches;
710
- } else {
711
- return null;
712
- }
713
- }
714
- let renderedMatches = matches;
715
- let errors = dataRouterState?.errors;
716
- if (errors != null) {
717
- let errorIndex = renderedMatches.findIndex(
718
- (m) => m.route.id && errors?.[m.route.id] !== void 0
719
- );
720
- invariant(
721
- errorIndex >= 0,
722
- `Could not find a matching route for errors on route IDs: ${Object.keys(
723
- errors
724
- ).join(",")}`
725
- );
726
- renderedMatches = renderedMatches.slice(
727
- 0,
728
- Math.min(renderedMatches.length, errorIndex + 1)
729
- );
730
- }
731
- let renderFallback = false;
732
- let fallbackIndex = -1;
733
- if (dataRouterState) {
734
- for (let i = 0; i < renderedMatches.length; i++) {
735
- let match = renderedMatches[i];
736
- if (match.route.HydrateFallback || match.route.hydrateFallbackElement) {
737
- fallbackIndex = i;
738
- }
739
- if (match.route.id) {
740
- let { loaderData, errors: errors2 } = dataRouterState;
741
- let needsToRunLoader = match.route.loader && !loaderData.hasOwnProperty(match.route.id) && (!errors2 || errors2[match.route.id] === void 0);
742
- if (match.route.lazy || needsToRunLoader) {
743
- renderFallback = true;
744
- if (fallbackIndex >= 0) {
745
- renderedMatches = renderedMatches.slice(0, fallbackIndex + 1);
746
- } else {
747
- renderedMatches = [renderedMatches[0]];
748
- }
749
- break;
750
- }
751
- }
752
- }
753
- }
754
- return renderedMatches.reduceRight((outlet, match, index) => {
755
- let error;
756
- let shouldRenderHydrateFallback = false;
757
- let errorElement = null;
758
- let hydrateFallbackElement = null;
759
- if (dataRouterState) {
760
- error = errors && match.route.id ? errors[match.route.id] : void 0;
761
- errorElement = match.route.errorElement || defaultErrorElement;
762
- if (renderFallback) {
763
- if (fallbackIndex < 0 && index === 0) {
764
- warningOnce(
765
- "route-fallback",
766
- false,
767
- "No `HydrateFallback` element provided to render during initial hydration"
768
- );
769
- shouldRenderHydrateFallback = true;
770
- hydrateFallbackElement = null;
771
- } else if (fallbackIndex === index) {
772
- shouldRenderHydrateFallback = true;
773
- hydrateFallbackElement = match.route.hydrateFallbackElement || null;
774
- }
775
- }
776
- }
777
- let matches2 = parentMatches.concat(renderedMatches.slice(0, index + 1));
778
- let getChildren = () => {
779
- let children;
780
- if (error) {
781
- children = errorElement;
782
- } else if (shouldRenderHydrateFallback) {
783
- children = hydrateFallbackElement;
784
- } else if (match.route.Component) {
785
- children = /* @__PURE__ */ React.createElement(match.route.Component, null);
786
- } else if (match.route.element) {
787
- children = match.route.element;
788
- } else {
789
- children = outlet;
790
- }
791
- return /* @__PURE__ */ React.createElement(
792
- RenderedRoute,
793
- {
794
- match,
795
- routeContext: {
796
- outlet,
797
- matches: matches2,
798
- isDataRoute: dataRouterState != null
799
- },
800
- children
801
- }
802
- );
803
- };
804
- return dataRouterState && (match.route.ErrorBoundary || match.route.errorElement || index === 0) ? /* @__PURE__ */ React.createElement(
805
- RenderErrorBoundary,
806
- {
807
- location: dataRouterState.location,
808
- revalidation: dataRouterState.revalidation,
809
- component: errorElement,
810
- error,
811
- children: getChildren(),
812
- routeContext: { outlet: null, matches: matches2, isDataRoute: true }
813
- }
814
- ) : getChildren();
815
- }, null);
816
- }
817
- function getDataRouterConsoleError(hookName) {
818
- return `${hookName} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`;
819
- }
820
- function useDataRouterContext(hookName) {
821
- let ctx = React.useContext(DataRouterContext);
822
- invariant(ctx, getDataRouterConsoleError(hookName));
823
- return ctx;
824
- }
825
- function useDataRouterState(hookName) {
826
- let state = React.useContext(DataRouterStateContext);
827
- invariant(state, getDataRouterConsoleError(hookName));
828
- return state;
829
- }
830
- function useRouteContext(hookName) {
831
- let route = React.useContext(RouteContext);
832
- invariant(route, getDataRouterConsoleError(hookName));
833
- return route;
834
- }
835
- function useCurrentRouteId(hookName) {
836
- let route = useRouteContext(hookName);
837
- let thisRoute = route.matches[route.matches.length - 1];
838
- invariant(
839
- thisRoute.route.id,
840
- `${hookName} can only be used on routes that contain a unique "id"`
841
- );
842
- return thisRoute.route.id;
843
- }
844
- function useRouteId() {
845
- return useCurrentRouteId("useRouteId" /* UseRouteId */);
846
- }
847
- function useRouteError() {
848
- let error = React.useContext(RouteErrorContext);
849
- let state = useDataRouterState("useRouteError" /* UseRouteError */);
850
- let routeId = useCurrentRouteId("useRouteError" /* UseRouteError */);
851
- if (error !== void 0) {
852
- return error;
853
- }
854
- return state.errors?.[routeId];
855
- }
856
- function useNavigateStable() {
857
- let { router } = useDataRouterContext("useNavigate" /* UseNavigateStable */);
858
- let id = useCurrentRouteId("useNavigate" /* UseNavigateStable */);
859
- let activeRef = React.useRef(false);
860
- useIsomorphicLayoutEffect(() => {
861
- activeRef.current = true;
862
- });
863
- let navigate = React.useCallback(
864
- async (to, options = {}) => {
865
- warning(activeRef.current, navigateEffectWarning);
866
- if (!activeRef.current) return;
867
- if (typeof to === "number") {
868
- router.navigate(to);
869
- } else {
870
- await router.navigate(to, { fromRouteId: id, ...options });
871
- }
872
- },
873
- [router, id]
874
- );
875
- return navigate;
876
- }
877
- var alreadyWarned = {};
878
- function warningOnce(key, cond, message) {
879
- if (!cond && !alreadyWarned[key]) {
880
- alreadyWarned[key] = true;
881
- warning(false, message);
882
- }
883
- }
884
- React.memo(DataRoutes);
885
- function DataRoutes({
886
- routes,
887
- future,
888
- state
889
- }) {
890
- return useRoutesImpl(routes, void 0, state, future);
891
- }
892
-
893
- // lib/dom/dom.ts
894
- var defaultMethod = "get";
895
- var defaultEncType = "application/x-www-form-urlencoded";
896
- function isHtmlElement(object) {
897
- return object != null && typeof object.tagName === "string";
898
- }
899
- function isButtonElement(object) {
900
- return isHtmlElement(object) && object.tagName.toLowerCase() === "button";
901
- }
902
- function isFormElement(object) {
903
- return isHtmlElement(object) && object.tagName.toLowerCase() === "form";
904
- }
905
- function isInputElement(object) {
906
- return isHtmlElement(object) && object.tagName.toLowerCase() === "input";
907
- }
908
- function isModifiedEvent(event) {
909
- return !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey);
910
- }
911
- function shouldProcessLinkClick(event, target) {
912
- return event.button === 0 && // Ignore everything but left clicks
913
- (!target || target === "_self") && // Let browser handle "target=_blank" etc.
914
- !isModifiedEvent(event);
915
- }
916
- var _formDataSupportsSubmitter = null;
917
- function isFormDataSubmitterSupported() {
918
- if (_formDataSupportsSubmitter === null) {
919
- try {
920
- new FormData(
921
- document.createElement("form"),
922
- // @ts-expect-error if FormData supports the submitter parameter, this will throw
923
- 0
924
- );
925
- _formDataSupportsSubmitter = false;
926
- } catch (e) {
927
- _formDataSupportsSubmitter = true;
928
- }
929
- }
930
- return _formDataSupportsSubmitter;
931
- }
932
- var supportedFormEncTypes = /* @__PURE__ */ new Set([
933
- "application/x-www-form-urlencoded",
934
- "multipart/form-data",
935
- "text/plain"
936
- ]);
937
- function getFormEncType(encType) {
938
- if (encType != null && !supportedFormEncTypes.has(encType)) {
939
- warning(
940
- false,
941
- `"${encType}" is not a valid \`encType\` for \`<Form>\`/\`<fetcher.Form>\` and will default to "${defaultEncType}"`
942
- );
943
- return null;
944
- }
945
- return encType;
946
- }
947
- function getFormSubmissionInfo(target, basename) {
948
- let method;
949
- let action;
950
- let encType;
951
- let formData;
952
- let body;
953
- if (isFormElement(target)) {
954
- let attr = target.getAttribute("action");
955
- action = attr ? stripBasename(attr, basename) : null;
956
- method = target.getAttribute("method") || defaultMethod;
957
- encType = getFormEncType(target.getAttribute("enctype")) || defaultEncType;
958
- formData = new FormData(target);
959
- } else if (isButtonElement(target) || isInputElement(target) && (target.type === "submit" || target.type === "image")) {
960
- let form = target.form;
961
- if (form == null) {
962
- throw new Error(
963
- `Cannot submit a <button> or <input type="submit"> without a <form>`
964
- );
965
- }
966
- let attr = target.getAttribute("formaction") || form.getAttribute("action");
967
- action = attr ? stripBasename(attr, basename) : null;
968
- method = target.getAttribute("formmethod") || form.getAttribute("method") || defaultMethod;
969
- encType = getFormEncType(target.getAttribute("formenctype")) || getFormEncType(form.getAttribute("enctype")) || defaultEncType;
970
- formData = new FormData(form, target);
971
- if (!isFormDataSubmitterSupported()) {
972
- let { name, type, value } = target;
973
- if (type === "image") {
974
- let prefix = name ? `${name}.` : "";
975
- formData.append(`${prefix}x`, "0");
976
- formData.append(`${prefix}y`, "0");
977
- } else if (name) {
978
- formData.append(name, value);
979
- }
980
- }
981
- } else if (isHtmlElement(target)) {
982
- throw new Error(
983
- `Cannot submit element that is not <form>, <button>, or <input type="submit|image">`
984
- );
985
- } else {
986
- method = defaultMethod;
987
- action = null;
988
- encType = defaultEncType;
989
- body = target;
990
- }
991
- if (formData && encType === "text/plain") {
992
- body = formData;
993
- formData = void 0;
994
- }
995
- return { action, method: method.toLowerCase(), encType, formData, body };
996
- }
997
-
998
- // lib/dom/ssr/invariant.ts
999
- function invariant2(value, message) {
1000
- if (value === false || value === null || typeof value === "undefined") {
1001
- throw new Error(message);
1002
- }
1003
- }
1004
-
1005
- // lib/dom/ssr/routeModules.ts
1006
- async function loadRouteModule(route, routeModulesCache) {
1007
- if (route.id in routeModulesCache) {
1008
- return routeModulesCache[route.id];
1009
- }
1010
- try {
1011
- let routeModule = await import(
1012
- /* @vite-ignore */
1013
- /* webpackIgnore: true */
1014
- route.module
1015
- );
1016
- routeModulesCache[route.id] = routeModule;
1017
- return routeModule;
1018
- } catch (error) {
1019
- console.error(
1020
- `Error loading route module \`${route.module}\`, reloading page...`
1021
- );
1022
- console.error(error);
1023
- if (window.__reactRouterContext && window.__reactRouterContext.isSpaMode && // @ts-expect-error
1024
- import.meta.hot) {
1025
- throw error;
1026
- }
1027
- window.location.reload();
1028
- return new Promise(() => {
1029
- });
1030
- }
1031
- }
1032
- function isHtmlLinkDescriptor(object) {
1033
- if (object == null) {
1034
- return false;
1035
- }
1036
- if (object.href == null) {
1037
- return object.rel === "preload" && typeof object.imageSrcSet === "string" && typeof object.imageSizes === "string";
1038
- }
1039
- return typeof object.rel === "string" && typeof object.href === "string";
1040
- }
1041
- async function getKeyedPrefetchLinks(matches, manifest, routeModules) {
1042
- let links = await Promise.all(
1043
- matches.map(async (match) => {
1044
- let route = manifest.routes[match.route.id];
1045
- if (route) {
1046
- let mod = await loadRouteModule(route, routeModules);
1047
- return mod.links ? mod.links() : [];
1048
- }
1049
- return [];
1050
- })
1051
- );
1052
- return dedupeLinkDescriptors(
1053
- links.flat(1).filter(isHtmlLinkDescriptor).filter((link) => link.rel === "stylesheet" || link.rel === "preload").map(
1054
- (link) => link.rel === "stylesheet" ? { ...link, rel: "prefetch", as: "style" } : { ...link, rel: "prefetch" }
1055
- )
1056
- );
1057
- }
1058
- function getNewMatchesForLinks(page, nextMatches, currentMatches, manifest, location, mode) {
1059
- let isNew = (match, index) => {
1060
- if (!currentMatches[index]) return true;
1061
- return match.route.id !== currentMatches[index].route.id;
1062
- };
1063
- let matchPathChanged = (match, index) => {
1064
- return (
1065
- // param change, /users/123 -> /users/456
1066
- currentMatches[index].pathname !== match.pathname || // splat param changed, which is not present in match.path
1067
- // e.g. /files/images/avatar.jpg -> files/finances.xls
1068
- currentMatches[index].route.path?.endsWith("*") && currentMatches[index].params["*"] !== match.params["*"]
1069
- );
1070
- };
1071
- if (mode === "assets") {
1072
- return nextMatches.filter(
1073
- (match, index) => isNew(match, index) || matchPathChanged(match, index)
1074
- );
1075
- }
1076
- if (mode === "data") {
1077
- return nextMatches.filter((match, index) => {
1078
- let manifestRoute = manifest.routes[match.route.id];
1079
- if (!manifestRoute || !manifestRoute.hasLoader) {
1080
- return false;
1081
- }
1082
- if (isNew(match, index) || matchPathChanged(match, index)) {
1083
- return true;
1084
- }
1085
- if (match.route.shouldRevalidate) {
1086
- let routeChoice = match.route.shouldRevalidate({
1087
- currentUrl: new URL(
1088
- location.pathname + location.search + location.hash,
1089
- window.origin
1090
- ),
1091
- currentParams: currentMatches[0]?.params || {},
1092
- nextUrl: new URL(page, window.origin),
1093
- nextParams: match.params,
1094
- defaultShouldRevalidate: true
1095
- });
1096
- if (typeof routeChoice === "boolean") {
1097
- return routeChoice;
1098
- }
1099
- }
1100
- return true;
1101
- });
1102
- }
1103
- return [];
1104
- }
1105
- function getModuleLinkHrefs(matches, manifest, { includeHydrateFallback } = {}) {
1106
- return dedupeHrefs(
1107
- matches.map((match) => {
1108
- let route = manifest.routes[match.route.id];
1109
- if (!route) return [];
1110
- let hrefs = [route.module];
1111
- if (route.clientActionModule) {
1112
- hrefs = hrefs.concat(route.clientActionModule);
1113
- }
1114
- if (route.clientLoaderModule) {
1115
- hrefs = hrefs.concat(route.clientLoaderModule);
1116
- }
1117
- if (includeHydrateFallback && route.hydrateFallbackModule) {
1118
- hrefs = hrefs.concat(route.hydrateFallbackModule);
1119
- }
1120
- if (route.imports) {
1121
- hrefs = hrefs.concat(route.imports);
1122
- }
1123
- return hrefs;
1124
- }).flat(1)
1125
- );
1126
- }
1127
- function dedupeHrefs(hrefs) {
1128
- return [...new Set(hrefs)];
1129
- }
1130
- function sortKeys(obj) {
1131
- let sorted = {};
1132
- let keys = Object.keys(obj).sort();
1133
- for (let key of keys) {
1134
- sorted[key] = obj[key];
1135
- }
1136
- return sorted;
1137
- }
1138
- function dedupeLinkDescriptors(descriptors, preloads) {
1139
- let set = /* @__PURE__ */ new Set();
1140
- new Set(preloads);
1141
- return descriptors.reduce((deduped, descriptor) => {
1142
- let key = JSON.stringify(sortKeys(descriptor));
1143
- if (!set.has(key)) {
1144
- set.add(key);
1145
- deduped.push({ key, link: descriptor });
1146
- }
1147
- return deduped;
1148
- }, []);
1149
- }
1150
- Object.getOwnPropertyNames(Object.prototype).sort().join("\0");
1151
- var NO_BODY_STATUS_CODES = /* @__PURE__ */ new Set([100, 101, 204, 205]);
1152
- function singleFetchUrl(reqUrl, basename) {
1153
- let url = typeof reqUrl === "string" ? new URL(
1154
- reqUrl,
1155
- // This can be called during the SSR flow via PrefetchPageLinksImpl so
1156
- // don't assume window is available
1157
- typeof window === "undefined" ? "server://singlefetch/" : window.location.origin
1158
- ) : reqUrl;
1159
- if (url.pathname === "/") {
1160
- url.pathname = "_root.data";
1161
- } else if (basename && stripBasename(url.pathname, basename) === "/") {
1162
- url.pathname = `${basename.replace(/\/$/, "")}/_root.data`;
1163
- } else {
1164
- url.pathname = `${url.pathname.replace(/\/$/, "")}.data`;
1165
- }
1166
- return url;
1167
- }
1168
-
1169
- // lib/dom/ssr/components.tsx
1170
- function useDataRouterContext2() {
1171
- let context = React.useContext(DataRouterContext);
1172
- invariant2(
1173
- context,
1174
- "You must render this element inside a <DataRouterContext.Provider> element"
1175
- );
1176
- return context;
1177
- }
1178
- function useDataRouterStateContext() {
1179
- let context = React.useContext(DataRouterStateContext);
1180
- invariant2(
1181
- context,
1182
- "You must render this element inside a <DataRouterStateContext.Provider> element"
1183
- );
1184
- return context;
1185
- }
1186
- var FrameworkContext = React.createContext(void 0);
1187
- FrameworkContext.displayName = "FrameworkContext";
1188
- function useFrameworkContext() {
1189
- let context = React.useContext(FrameworkContext);
1190
- invariant2(
1191
- context,
1192
- "You must render this element inside a <HydratedRouter> element"
1193
- );
1194
- return context;
1195
- }
1196
- function usePrefetchBehavior(prefetch, theirElementProps) {
1197
- let frameworkContext = React.useContext(FrameworkContext);
1198
- let [maybePrefetch, setMaybePrefetch] = React.useState(false);
1199
- let [shouldPrefetch, setShouldPrefetch] = React.useState(false);
1200
- let { onFocus, onBlur, onMouseEnter, onMouseLeave, onTouchStart } = theirElementProps;
1201
- let ref = React.useRef(null);
1202
- React.useEffect(() => {
1203
- if (prefetch === "render") {
1204
- setShouldPrefetch(true);
1205
- }
1206
- if (prefetch === "viewport") {
1207
- let callback = (entries) => {
1208
- entries.forEach((entry) => {
1209
- setShouldPrefetch(entry.isIntersecting);
1210
- });
1211
- };
1212
- let observer = new IntersectionObserver(callback, { threshold: 0.5 });
1213
- if (ref.current) observer.observe(ref.current);
1214
- return () => {
1215
- observer.disconnect();
1216
- };
1217
- }
1218
- }, [prefetch]);
1219
- React.useEffect(() => {
1220
- if (maybePrefetch) {
1221
- let id = setTimeout(() => {
1222
- setShouldPrefetch(true);
1223
- }, 100);
1224
- return () => {
1225
- clearTimeout(id);
1226
- };
1227
- }
1228
- }, [maybePrefetch]);
1229
- let setIntent = () => {
1230
- setMaybePrefetch(true);
1231
- };
1232
- let cancelIntent = () => {
1233
- setMaybePrefetch(false);
1234
- setShouldPrefetch(false);
1235
- };
1236
- if (!frameworkContext) {
1237
- return [false, ref, {}];
1238
- }
1239
- if (prefetch !== "intent") {
1240
- return [shouldPrefetch, ref, {}];
1241
- }
1242
- return [
1243
- shouldPrefetch,
1244
- ref,
1245
- {
1246
- onFocus: composeEventHandlers(onFocus, setIntent),
1247
- onBlur: composeEventHandlers(onBlur, cancelIntent),
1248
- onMouseEnter: composeEventHandlers(onMouseEnter, setIntent),
1249
- onMouseLeave: composeEventHandlers(onMouseLeave, cancelIntent),
1250
- onTouchStart: composeEventHandlers(onTouchStart, setIntent)
1251
- }
1252
- ];
1253
- }
1254
- function composeEventHandlers(theirHandler, ourHandler) {
1255
- return (event) => {
1256
- theirHandler && theirHandler(event);
1257
- if (!event.defaultPrevented) {
1258
- ourHandler(event);
1259
- }
1260
- };
1261
- }
1262
- function PrefetchPageLinks({
1263
- page,
1264
- ...dataLinkProps
1265
- }) {
1266
- let { router } = useDataRouterContext2();
1267
- let matches = React.useMemo(
1268
- () => matchRoutes(router.routes, page, router.basename),
1269
- [router.routes, page, router.basename]
1270
- );
1271
- if (!matches) {
1272
- return null;
1273
- }
1274
- return /* @__PURE__ */ React.createElement(PrefetchPageLinksImpl, { page, matches, ...dataLinkProps });
1275
- }
1276
- function useKeyedPrefetchLinks(matches) {
1277
- let { manifest, routeModules } = useFrameworkContext();
1278
- let [keyedPrefetchLinks, setKeyedPrefetchLinks] = React.useState([]);
1279
- React.useEffect(() => {
1280
- let interrupted = false;
1281
- void getKeyedPrefetchLinks(matches, manifest, routeModules).then(
1282
- (links) => {
1283
- if (!interrupted) {
1284
- setKeyedPrefetchLinks(links);
1285
- }
1286
- }
1287
- );
1288
- return () => {
1289
- interrupted = true;
1290
- };
1291
- }, [matches, manifest, routeModules]);
1292
- return keyedPrefetchLinks;
1293
- }
1294
- function PrefetchPageLinksImpl({
1295
- page,
1296
- matches: nextMatches,
1297
- ...linkProps
1298
- }) {
1299
- let location = useLocation();
1300
- let { manifest, routeModules } = useFrameworkContext();
1301
- let { basename } = useDataRouterContext2();
1302
- let { loaderData, matches } = useDataRouterStateContext();
1303
- let newMatchesForData = React.useMemo(
1304
- () => getNewMatchesForLinks(
1305
- page,
1306
- nextMatches,
1307
- matches,
1308
- manifest,
1309
- location,
1310
- "data"
1311
- ),
1312
- [page, nextMatches, matches, manifest, location]
1313
- );
1314
- let newMatchesForAssets = React.useMemo(
1315
- () => getNewMatchesForLinks(
1316
- page,
1317
- nextMatches,
1318
- matches,
1319
- manifest,
1320
- location,
1321
- "assets"
1322
- ),
1323
- [page, nextMatches, matches, manifest, location]
1324
- );
1325
- let dataHrefs = React.useMemo(() => {
1326
- if (page === location.pathname + location.search + location.hash) {
1327
- return [];
1328
- }
1329
- let routesParams = /* @__PURE__ */ new Set();
1330
- let foundOptOutRoute = false;
1331
- nextMatches.forEach((m) => {
1332
- let manifestRoute = manifest.routes[m.route.id];
1333
- if (!manifestRoute || !manifestRoute.hasLoader) {
1334
- return;
1335
- }
1336
- if (!newMatchesForData.some((m2) => m2.route.id === m.route.id) && m.route.id in loaderData && routeModules[m.route.id]?.shouldRevalidate) {
1337
- foundOptOutRoute = true;
1338
- } else if (manifestRoute.hasClientLoader) {
1339
- foundOptOutRoute = true;
1340
- } else {
1341
- routesParams.add(m.route.id);
1342
- }
1343
- });
1344
- if (routesParams.size === 0) {
1345
- return [];
1346
- }
1347
- let url = singleFetchUrl(page, basename);
1348
- if (foundOptOutRoute && routesParams.size > 0) {
1349
- url.searchParams.set(
1350
- "_routes",
1351
- nextMatches.filter((m) => routesParams.has(m.route.id)).map((m) => m.route.id).join(",")
1352
- );
1353
- }
1354
- return [url.pathname + url.search];
1355
- }, [
1356
- basename,
1357
- loaderData,
1358
- location,
1359
- manifest,
1360
- newMatchesForData,
1361
- nextMatches,
1362
- page,
1363
- routeModules
1364
- ]);
1365
- let moduleHrefs = React.useMemo(
1366
- () => getModuleLinkHrefs(newMatchesForAssets, manifest),
1367
- [newMatchesForAssets, manifest]
1368
- );
1369
- let keyedPrefetchLinks = useKeyedPrefetchLinks(newMatchesForAssets);
1370
- return /* @__PURE__ */ React.createElement(React.Fragment, null, dataHrefs.map((href2) => /* @__PURE__ */ React.createElement("link", { key: href2, rel: "prefetch", as: "fetch", href: href2, ...linkProps })), moduleHrefs.map((href2) => /* @__PURE__ */ React.createElement("link", { key: href2, rel: "modulepreload", href: href2, ...linkProps })), keyedPrefetchLinks.map(({ key, link }) => (
1371
- // these don't spread `linkProps` because they are full link descriptors
1372
- // already with their own props
1373
- /* @__PURE__ */ React.createElement("link", { key, ...link })
1374
- )));
1375
- }
1376
- function mergeRefs(...refs) {
1377
- return (value) => {
1378
- refs.forEach((ref) => {
1379
- if (typeof ref === "function") {
1380
- ref(value);
1381
- } else if (ref != null) {
1382
- ref.current = value;
1383
- }
1384
- });
1385
- };
1386
- }
1387
-
1388
- // lib/dom/lib.tsx
1389
- var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
1390
- try {
1391
- if (isBrowser) {
1392
- window.__reactRouterVersion = "7.6.2";
1393
- }
1394
- } catch (e) {
1395
- }
1396
- var ABSOLUTE_URL_REGEX2 = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
1397
- var Link = React.forwardRef(
1398
- function LinkWithRef({
1399
- onClick,
1400
- discover = "render",
1401
- prefetch = "none",
1402
- relative,
1403
- reloadDocument,
1404
- replace: replace2,
1405
- state,
1406
- target,
1407
- to,
1408
- preventScrollReset,
1409
- viewTransition,
1410
- ...rest
1411
- }, forwardedRef) {
1412
- let { basename } = React.useContext(NavigationContext);
1413
- let isAbsolute = typeof to === "string" && ABSOLUTE_URL_REGEX2.test(to);
1414
- let absoluteHref;
1415
- let isExternal = false;
1416
- if (typeof to === "string" && isAbsolute) {
1417
- absoluteHref = to;
1418
- if (isBrowser) {
1419
- try {
1420
- let currentUrl = new URL(window.location.href);
1421
- let targetUrl = to.startsWith("//") ? new URL(currentUrl.protocol + to) : new URL(to);
1422
- let path = stripBasename(targetUrl.pathname, basename);
1423
- if (targetUrl.origin === currentUrl.origin && path != null) {
1424
- to = path + targetUrl.search + targetUrl.hash;
1425
- } else {
1426
- isExternal = true;
1427
- }
1428
- } catch (e) {
1429
- warning(
1430
- false,
1431
- `<Link to="${to}"> contains an invalid URL which will probably break when clicked - please update to a valid URL path.`
1432
- );
1433
- }
1434
- }
1435
- }
1436
- let href2 = useHref(to, { relative });
1437
- let [shouldPrefetch, prefetchRef, prefetchHandlers] = usePrefetchBehavior(
1438
- prefetch,
1439
- rest
1440
- );
1441
- let internalOnClick = useLinkClickHandler(to, {
1442
- replace: replace2,
1443
- state,
1444
- target,
1445
- preventScrollReset,
1446
- relative,
1447
- viewTransition
1448
- });
1449
- function handleClick(event) {
1450
- if (onClick) onClick(event);
1451
- if (!event.defaultPrevented) {
1452
- internalOnClick(event);
1453
- }
1454
- }
1455
- let link = (
1456
- // eslint-disable-next-line jsx-a11y/anchor-has-content
1457
- /* @__PURE__ */ React.createElement(
1458
- "a",
1459
- {
1460
- ...rest,
1461
- ...prefetchHandlers,
1462
- href: absoluteHref || href2,
1463
- onClick: isExternal || reloadDocument ? onClick : handleClick,
1464
- ref: mergeRefs(forwardedRef, prefetchRef),
1465
- target,
1466
- "data-discover": !isAbsolute && discover === "render" ? "true" : void 0
1467
- }
1468
- )
1469
- );
1470
- return shouldPrefetch && !isAbsolute ? /* @__PURE__ */ React.createElement(React.Fragment, null, link, /* @__PURE__ */ React.createElement(PrefetchPageLinks, { page: href2 })) : link;
1471
- }
1472
- );
1473
- Link.displayName = "Link";
1474
- var NavLink = React.forwardRef(
1475
- function NavLinkWithRef({
1476
- "aria-current": ariaCurrentProp = "page",
1477
- caseSensitive = false,
1478
- className: classNameProp = "",
1479
- end = false,
1480
- style: styleProp,
1481
- to,
1482
- viewTransition,
1483
- children,
1484
- ...rest
1485
- }, ref) {
1486
- let path = useResolvedPath(to, { relative: rest.relative });
1487
- let location = useLocation();
1488
- let routerState = React.useContext(DataRouterStateContext);
1489
- let { navigator, basename } = React.useContext(NavigationContext);
1490
- let isTransitioning = routerState != null && // Conditional usage is OK here because the usage of a data router is static
1491
- // eslint-disable-next-line react-hooks/rules-of-hooks
1492
- useViewTransitionState(path) && viewTransition === true;
1493
- let toPathname = navigator.encodeLocation ? navigator.encodeLocation(path).pathname : path.pathname;
1494
- let locationPathname = location.pathname;
1495
- let nextLocationPathname = routerState && routerState.navigation && routerState.navigation.location ? routerState.navigation.location.pathname : null;
1496
- if (!caseSensitive) {
1497
- locationPathname = locationPathname.toLowerCase();
1498
- nextLocationPathname = nextLocationPathname ? nextLocationPathname.toLowerCase() : null;
1499
- toPathname = toPathname.toLowerCase();
1500
- }
1501
- if (nextLocationPathname && basename) {
1502
- nextLocationPathname = stripBasename(nextLocationPathname, basename) || nextLocationPathname;
1503
- }
1504
- const endSlashPosition = toPathname !== "/" && toPathname.endsWith("/") ? toPathname.length - 1 : toPathname.length;
1505
- let isActive = locationPathname === toPathname || !end && locationPathname.startsWith(toPathname) && locationPathname.charAt(endSlashPosition) === "/";
1506
- let isPending = nextLocationPathname != null && (nextLocationPathname === toPathname || !end && nextLocationPathname.startsWith(toPathname) && nextLocationPathname.charAt(toPathname.length) === "/");
1507
- let renderProps = {
1508
- isActive,
1509
- isPending,
1510
- isTransitioning
1511
- };
1512
- let ariaCurrent = isActive ? ariaCurrentProp : void 0;
1513
- let className;
1514
- if (typeof classNameProp === "function") {
1515
- className = classNameProp(renderProps);
1516
- } else {
1517
- className = [
1518
- classNameProp,
1519
- isActive ? "active" : null,
1520
- isPending ? "pending" : null,
1521
- isTransitioning ? "transitioning" : null
1522
- ].filter(Boolean).join(" ");
1523
- }
1524
- let style = typeof styleProp === "function" ? styleProp(renderProps) : styleProp;
1525
- return /* @__PURE__ */ React.createElement(
1526
- Link,
1527
- {
1528
- ...rest,
1529
- "aria-current": ariaCurrent,
1530
- className,
1531
- ref,
1532
- style,
1533
- to,
1534
- viewTransition
1535
- },
1536
- typeof children === "function" ? children(renderProps) : children
1537
- );
1538
- }
1539
- );
1540
- NavLink.displayName = "NavLink";
1541
- var Form = React.forwardRef(
1542
- ({
1543
- discover = "render",
1544
- fetcherKey,
1545
- navigate,
1546
- reloadDocument,
1547
- replace: replace2,
1548
- state,
1549
- method = defaultMethod,
1550
- action,
1551
- onSubmit,
1552
- relative,
1553
- preventScrollReset,
1554
- viewTransition,
1555
- ...props
1556
- }, forwardedRef) => {
1557
- let submit = useSubmit();
1558
- let formAction = useFormAction(action, { relative });
1559
- let formMethod = method.toLowerCase() === "get" ? "get" : "post";
1560
- let isAbsolute = typeof action === "string" && ABSOLUTE_URL_REGEX2.test(action);
1561
- let submitHandler = (event) => {
1562
- onSubmit && onSubmit(event);
1563
- if (event.defaultPrevented) return;
1564
- event.preventDefault();
1565
- let submitter = event.nativeEvent.submitter;
1566
- let submitMethod = submitter?.getAttribute("formmethod") || method;
1567
- submit(submitter || event.currentTarget, {
1568
- fetcherKey,
1569
- method: submitMethod,
1570
- navigate,
1571
- replace: replace2,
1572
- state,
1573
- relative,
1574
- preventScrollReset,
1575
- viewTransition
1576
- });
1577
- };
1578
- return /* @__PURE__ */ React.createElement(
1579
- "form",
1580
- {
1581
- ref: forwardedRef,
1582
- method: formMethod,
1583
- action: formAction,
1584
- onSubmit: reloadDocument ? onSubmit : submitHandler,
1585
- ...props,
1586
- "data-discover": !isAbsolute && discover === "render" ? "true" : void 0
1587
- }
1588
- );
1589
- }
1590
- );
1591
- Form.displayName = "Form";
1592
- function getDataRouterConsoleError2(hookName) {
1593
- return `${hookName} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`;
1594
- }
1595
- function useDataRouterContext3(hookName) {
1596
- let ctx = React.useContext(DataRouterContext);
1597
- invariant(ctx, getDataRouterConsoleError2(hookName));
1598
- return ctx;
1599
- }
1600
- function useLinkClickHandler(to, {
1601
- target,
1602
- replace: replaceProp,
1603
- state,
1604
- preventScrollReset,
1605
- relative,
1606
- viewTransition
1607
- } = {}) {
1608
- let navigate = useNavigate();
1609
- let location = useLocation();
1610
- let path = useResolvedPath(to, { relative });
1611
- return React.useCallback(
1612
- (event) => {
1613
- if (shouldProcessLinkClick(event, target)) {
1614
- event.preventDefault();
1615
- let replace2 = replaceProp !== void 0 ? replaceProp : createPath(location) === createPath(path);
1616
- navigate(to, {
1617
- replace: replace2,
1618
- state,
1619
- preventScrollReset,
1620
- relative,
1621
- viewTransition
1622
- });
1623
- }
1624
- },
1625
- [
1626
- location,
1627
- navigate,
1628
- path,
1629
- replaceProp,
1630
- state,
1631
- target,
1632
- to,
1633
- preventScrollReset,
1634
- relative,
1635
- viewTransition
1636
- ]
1637
- );
1638
- }
1639
- var fetcherId = 0;
1640
- var getUniqueFetcherId = () => `__${String(++fetcherId)}__`;
1641
- function useSubmit() {
1642
- let { router } = useDataRouterContext3("useSubmit" /* UseSubmit */);
1643
- let { basename } = React.useContext(NavigationContext);
1644
- let currentRouteId = useRouteId();
1645
- return React.useCallback(
1646
- async (target, options = {}) => {
1647
- let { action, method, encType, formData, body } = getFormSubmissionInfo(
1648
- target,
1649
- basename
1650
- );
1651
- if (options.navigate === false) {
1652
- let key = options.fetcherKey || getUniqueFetcherId();
1653
- await router.fetch(key, currentRouteId, options.action || action, {
1654
- preventScrollReset: options.preventScrollReset,
1655
- formData,
1656
- body,
1657
- formMethod: options.method || method,
1658
- formEncType: options.encType || encType,
1659
- flushSync: options.flushSync
1660
- });
1661
- } else {
1662
- await router.navigate(options.action || action, {
1663
- preventScrollReset: options.preventScrollReset,
1664
- formData,
1665
- body,
1666
- formMethod: options.method || method,
1667
- formEncType: options.encType || encType,
1668
- replace: options.replace,
1669
- state: options.state,
1670
- fromRouteId: currentRouteId,
1671
- flushSync: options.flushSync,
1672
- viewTransition: options.viewTransition
1673
- });
1674
- }
1675
- },
1676
- [router, basename, currentRouteId]
1677
- );
1678
- }
1679
- function useFormAction(action, { relative } = {}) {
1680
- let { basename } = React.useContext(NavigationContext);
1681
- let routeContext = React.useContext(RouteContext);
1682
- invariant(routeContext, "useFormAction must be used inside a RouteContext");
1683
- let [match] = routeContext.matches.slice(-1);
1684
- let path = { ...useResolvedPath(action ? action : ".", { relative }) };
1685
- let location = useLocation();
1686
- if (action == null) {
1687
- path.search = location.search;
1688
- let params = new URLSearchParams(path.search);
1689
- let indexValues = params.getAll("index");
1690
- let hasNakedIndexParam = indexValues.some((v) => v === "");
1691
- if (hasNakedIndexParam) {
1692
- params.delete("index");
1693
- indexValues.filter((v) => v).forEach((v) => params.append("index", v));
1694
- let qs = params.toString();
1695
- path.search = qs ? `?${qs}` : "";
1696
- }
1697
- }
1698
- if ((!action || action === ".") && match.route.index) {
1699
- path.search = path.search ? path.search.replace(/^\?/, "?index&") : "?index";
1700
- }
1701
- if (basename !== "/") {
1702
- path.pathname = path.pathname === "/" ? basename : joinPaths([basename, path.pathname]);
1703
- }
1704
- return createPath(path);
1705
- }
1706
- function useViewTransitionState(to, opts = {}) {
1707
- let vtContext = React.useContext(ViewTransitionContext);
1708
- invariant(
1709
- vtContext != null,
1710
- "`useViewTransitionState` must be used within `react-router-dom`'s `RouterProvider`. Did you accidentally import `RouterProvider` from `react-router`?"
1711
- );
1712
- let { basename } = useDataRouterContext3(
1713
- "useViewTransitionState" /* useViewTransitionState */
1714
- );
1715
- let path = useResolvedPath(to, { relative: opts.relative });
1716
- if (!vtContext.isTransitioning) {
1717
- return false;
1718
- }
1719
- let currentPath = stripBasename(vtContext.currentLocation.pathname, basename) || vtContext.currentLocation.pathname;
1720
- let nextPath = stripBasename(vtContext.nextLocation.pathname, basename) || vtContext.nextLocation.pathname;
1721
- return matchPath(path.pathname, nextPath) != null || matchPath(path.pathname, currentPath) != null;
1722
- }
1723
-
1724
- // lib/server-runtime/single-fetch.ts
1725
- /* @__PURE__ */ new Set([
1726
- ...NO_BODY_STATUS_CODES,
1727
- 304
1728
- ]);
1729
-
1730
- export { DataRouterContext, DataRouterStateContext, FetchersContext, Form, FrameworkContext, Link, LocationContext, NavLink, NavigationContext, PrefetchPageLinks, RouteContext, ViewTransitionContext, createPath, invariant, isRouteErrorResponse, matchPath, matchRoutes, parsePath, resolvePath, useFormAction, useHref, useInRouterContext, useLinkClickHandler, useLocation, useNavigate, useParams, useResolvedPath, useRouteError, useSubmit, useViewTransitionState };
1731
- //# sourceMappingURL=chunk-NL6KNZEE.js.map