1 | import {
|
---|
2 | require_react_dom
|
---|
3 | } from "./chunk-GKJBSOWT.js";
|
---|
4 | import {
|
---|
5 | require_react
|
---|
6 | } from "./chunk-QJTFJ6OV.js";
|
---|
7 | import {
|
---|
8 | __toESM
|
---|
9 | } from "./chunk-V4OQ3NZ2.js";
|
---|
10 |
|
---|
11 | // node_modules/react-router-dom/dist/index.js
|
---|
12 | var React2 = __toESM(require_react());
|
---|
13 | var ReactDOM = __toESM(require_react_dom());
|
---|
14 |
|
---|
15 | // node_modules/react-router/dist/index.js
|
---|
16 | var React = __toESM(require_react());
|
---|
17 |
|
---|
18 | // node_modules/@remix-run/router/dist/router.js
|
---|
19 | function _extends() {
|
---|
20 | _extends = Object.assign ? Object.assign.bind() : function(target) {
|
---|
21 | for (var i = 1; i < arguments.length; i++) {
|
---|
22 | var source = arguments[i];
|
---|
23 | for (var key in source) {
|
---|
24 | if (Object.prototype.hasOwnProperty.call(source, key)) {
|
---|
25 | target[key] = source[key];
|
---|
26 | }
|
---|
27 | }
|
---|
28 | }
|
---|
29 | return target;
|
---|
30 | };
|
---|
31 | return _extends.apply(this, arguments);
|
---|
32 | }
|
---|
33 | var Action;
|
---|
34 | (function(Action2) {
|
---|
35 | Action2["Pop"] = "POP";
|
---|
36 | Action2["Push"] = "PUSH";
|
---|
37 | Action2["Replace"] = "REPLACE";
|
---|
38 | })(Action || (Action = {}));
|
---|
39 | var PopStateEventType = "popstate";
|
---|
40 | function createMemoryHistory(options) {
|
---|
41 | if (options === void 0) {
|
---|
42 | options = {};
|
---|
43 | }
|
---|
44 | let {
|
---|
45 | initialEntries = ["/"],
|
---|
46 | initialIndex,
|
---|
47 | v5Compat = false
|
---|
48 | } = options;
|
---|
49 | let entries;
|
---|
50 | entries = initialEntries.map((entry, index2) => createMemoryLocation(entry, typeof entry === "string" ? null : entry.state, index2 === 0 ? "default" : void 0));
|
---|
51 | let index = clampIndex(initialIndex == null ? entries.length - 1 : initialIndex);
|
---|
52 | let action = Action.Pop;
|
---|
53 | let listener = null;
|
---|
54 | function clampIndex(n) {
|
---|
55 | return Math.min(Math.max(n, 0), entries.length - 1);
|
---|
56 | }
|
---|
57 | function getCurrentLocation() {
|
---|
58 | return entries[index];
|
---|
59 | }
|
---|
60 | function createMemoryLocation(to, state, key) {
|
---|
61 | if (state === void 0) {
|
---|
62 | state = null;
|
---|
63 | }
|
---|
64 | let location = createLocation(entries ? getCurrentLocation().pathname : "/", to, state, key);
|
---|
65 | warning(location.pathname.charAt(0) === "/", "relative pathnames are not supported in memory history: " + JSON.stringify(to));
|
---|
66 | return location;
|
---|
67 | }
|
---|
68 | function createHref(to) {
|
---|
69 | return typeof to === "string" ? to : createPath(to);
|
---|
70 | }
|
---|
71 | let history = {
|
---|
72 | get index() {
|
---|
73 | return index;
|
---|
74 | },
|
---|
75 | get action() {
|
---|
76 | return action;
|
---|
77 | },
|
---|
78 | get location() {
|
---|
79 | return getCurrentLocation();
|
---|
80 | },
|
---|
81 | createHref,
|
---|
82 | createURL(to) {
|
---|
83 | return new URL(createHref(to), "http://localhost");
|
---|
84 | },
|
---|
85 | encodeLocation(to) {
|
---|
86 | let path = typeof to === "string" ? parsePath(to) : to;
|
---|
87 | return {
|
---|
88 | pathname: path.pathname || "",
|
---|
89 | search: path.search || "",
|
---|
90 | hash: path.hash || ""
|
---|
91 | };
|
---|
92 | },
|
---|
93 | push(to, state) {
|
---|
94 | action = Action.Push;
|
---|
95 | let nextLocation = createMemoryLocation(to, state);
|
---|
96 | index += 1;
|
---|
97 | entries.splice(index, entries.length, nextLocation);
|
---|
98 | if (v5Compat && listener) {
|
---|
99 | listener({
|
---|
100 | action,
|
---|
101 | location: nextLocation,
|
---|
102 | delta: 1
|
---|
103 | });
|
---|
104 | }
|
---|
105 | },
|
---|
106 | replace(to, state) {
|
---|
107 | action = Action.Replace;
|
---|
108 | let nextLocation = createMemoryLocation(to, state);
|
---|
109 | entries[index] = nextLocation;
|
---|
110 | if (v5Compat && listener) {
|
---|
111 | listener({
|
---|
112 | action,
|
---|
113 | location: nextLocation,
|
---|
114 | delta: 0
|
---|
115 | });
|
---|
116 | }
|
---|
117 | },
|
---|
118 | go(delta) {
|
---|
119 | action = Action.Pop;
|
---|
120 | let nextIndex = clampIndex(index + delta);
|
---|
121 | let nextLocation = entries[nextIndex];
|
---|
122 | index = nextIndex;
|
---|
123 | if (listener) {
|
---|
124 | listener({
|
---|
125 | action,
|
---|
126 | location: nextLocation,
|
---|
127 | delta
|
---|
128 | });
|
---|
129 | }
|
---|
130 | },
|
---|
131 | listen(fn) {
|
---|
132 | listener = fn;
|
---|
133 | return () => {
|
---|
134 | listener = null;
|
---|
135 | };
|
---|
136 | }
|
---|
137 | };
|
---|
138 | return history;
|
---|
139 | }
|
---|
140 | function createBrowserHistory(options) {
|
---|
141 | if (options === void 0) {
|
---|
142 | options = {};
|
---|
143 | }
|
---|
144 | function createBrowserLocation(window2, globalHistory) {
|
---|
145 | let {
|
---|
146 | pathname,
|
---|
147 | search,
|
---|
148 | hash
|
---|
149 | } = window2.location;
|
---|
150 | return createLocation(
|
---|
151 | "",
|
---|
152 | {
|
---|
153 | pathname,
|
---|
154 | search,
|
---|
155 | hash
|
---|
156 | },
|
---|
157 | // state defaults to `null` because `window.history.state` does
|
---|
158 | globalHistory.state && globalHistory.state.usr || null,
|
---|
159 | globalHistory.state && globalHistory.state.key || "default"
|
---|
160 | );
|
---|
161 | }
|
---|
162 | function createBrowserHref(window2, to) {
|
---|
163 | return typeof to === "string" ? to : createPath(to);
|
---|
164 | }
|
---|
165 | return getUrlBasedHistory(createBrowserLocation, createBrowserHref, null, options);
|
---|
166 | }
|
---|
167 | function createHashHistory(options) {
|
---|
168 | if (options === void 0) {
|
---|
169 | options = {};
|
---|
170 | }
|
---|
171 | function createHashLocation(window2, globalHistory) {
|
---|
172 | let {
|
---|
173 | pathname = "/",
|
---|
174 | search = "",
|
---|
175 | hash = ""
|
---|
176 | } = parsePath(window2.location.hash.substr(1));
|
---|
177 | if (!pathname.startsWith("/") && !pathname.startsWith(".")) {
|
---|
178 | pathname = "/" + pathname;
|
---|
179 | }
|
---|
180 | return createLocation(
|
---|
181 | "",
|
---|
182 | {
|
---|
183 | pathname,
|
---|
184 | search,
|
---|
185 | hash
|
---|
186 | },
|
---|
187 | // state defaults to `null` because `window.history.state` does
|
---|
188 | globalHistory.state && globalHistory.state.usr || null,
|
---|
189 | globalHistory.state && globalHistory.state.key || "default"
|
---|
190 | );
|
---|
191 | }
|
---|
192 | function createHashHref(window2, to) {
|
---|
193 | let base = window2.document.querySelector("base");
|
---|
194 | let href = "";
|
---|
195 | if (base && base.getAttribute("href")) {
|
---|
196 | let url = window2.location.href;
|
---|
197 | let hashIndex = url.indexOf("#");
|
---|
198 | href = hashIndex === -1 ? url : url.slice(0, hashIndex);
|
---|
199 | }
|
---|
200 | return href + "#" + (typeof to === "string" ? to : createPath(to));
|
---|
201 | }
|
---|
202 | function validateHashLocation(location, to) {
|
---|
203 | warning(location.pathname.charAt(0) === "/", "relative pathnames are not supported in hash history.push(" + JSON.stringify(to) + ")");
|
---|
204 | }
|
---|
205 | return getUrlBasedHistory(createHashLocation, createHashHref, validateHashLocation, options);
|
---|
206 | }
|
---|
207 | function invariant(value, message) {
|
---|
208 | if (value === false || value === null || typeof value === "undefined") {
|
---|
209 | throw new Error(message);
|
---|
210 | }
|
---|
211 | }
|
---|
212 | function warning(cond, message) {
|
---|
213 | if (!cond) {
|
---|
214 | if (typeof console !== "undefined") console.warn(message);
|
---|
215 | try {
|
---|
216 | throw new Error(message);
|
---|
217 | } catch (e) {
|
---|
218 | }
|
---|
219 | }
|
---|
220 | }
|
---|
221 | function createKey() {
|
---|
222 | return Math.random().toString(36).substr(2, 8);
|
---|
223 | }
|
---|
224 | function getHistoryState(location, index) {
|
---|
225 | return {
|
---|
226 | usr: location.state,
|
---|
227 | key: location.key,
|
---|
228 | idx: index
|
---|
229 | };
|
---|
230 | }
|
---|
231 | function createLocation(current, to, state, key) {
|
---|
232 | if (state === void 0) {
|
---|
233 | state = null;
|
---|
234 | }
|
---|
235 | let location = _extends({
|
---|
236 | pathname: typeof current === "string" ? current : current.pathname,
|
---|
237 | search: "",
|
---|
238 | hash: ""
|
---|
239 | }, typeof to === "string" ? parsePath(to) : to, {
|
---|
240 | state,
|
---|
241 | // TODO: This could be cleaned up. push/replace should probably just take
|
---|
242 | // full Locations now and avoid the need to run through this flow at all
|
---|
243 | // But that's a pretty big refactor to the current test suite so going to
|
---|
244 | // keep as is for the time being and just let any incoming keys take precedence
|
---|
245 | key: to && to.key || key || createKey()
|
---|
246 | });
|
---|
247 | return location;
|
---|
248 | }
|
---|
249 | function createPath(_ref) {
|
---|
250 | let {
|
---|
251 | pathname = "/",
|
---|
252 | search = "",
|
---|
253 | hash = ""
|
---|
254 | } = _ref;
|
---|
255 | if (search && search !== "?") pathname += search.charAt(0) === "?" ? search : "?" + search;
|
---|
256 | if (hash && hash !== "#") pathname += hash.charAt(0) === "#" ? hash : "#" + hash;
|
---|
257 | return pathname;
|
---|
258 | }
|
---|
259 | function parsePath(path) {
|
---|
260 | let parsedPath = {};
|
---|
261 | if (path) {
|
---|
262 | let hashIndex = path.indexOf("#");
|
---|
263 | if (hashIndex >= 0) {
|
---|
264 | parsedPath.hash = path.substr(hashIndex);
|
---|
265 | path = path.substr(0, hashIndex);
|
---|
266 | }
|
---|
267 | let searchIndex = path.indexOf("?");
|
---|
268 | if (searchIndex >= 0) {
|
---|
269 | parsedPath.search = path.substr(searchIndex);
|
---|
270 | path = path.substr(0, searchIndex);
|
---|
271 | }
|
---|
272 | if (path) {
|
---|
273 | parsedPath.pathname = path;
|
---|
274 | }
|
---|
275 | }
|
---|
276 | return parsedPath;
|
---|
277 | }
|
---|
278 | function getUrlBasedHistory(getLocation, createHref, validateLocation, options) {
|
---|
279 | if (options === void 0) {
|
---|
280 | options = {};
|
---|
281 | }
|
---|
282 | let {
|
---|
283 | window: window2 = document.defaultView,
|
---|
284 | v5Compat = false
|
---|
285 | } = options;
|
---|
286 | let globalHistory = window2.history;
|
---|
287 | let action = Action.Pop;
|
---|
288 | let listener = null;
|
---|
289 | let index = getIndex();
|
---|
290 | if (index == null) {
|
---|
291 | index = 0;
|
---|
292 | globalHistory.replaceState(_extends({}, globalHistory.state, {
|
---|
293 | idx: index
|
---|
294 | }), "");
|
---|
295 | }
|
---|
296 | function getIndex() {
|
---|
297 | let state = globalHistory.state || {
|
---|
298 | idx: null
|
---|
299 | };
|
---|
300 | return state.idx;
|
---|
301 | }
|
---|
302 | function handlePop() {
|
---|
303 | action = Action.Pop;
|
---|
304 | let nextIndex = getIndex();
|
---|
305 | let delta = nextIndex == null ? null : nextIndex - index;
|
---|
306 | index = nextIndex;
|
---|
307 | if (listener) {
|
---|
308 | listener({
|
---|
309 | action,
|
---|
310 | location: history.location,
|
---|
311 | delta
|
---|
312 | });
|
---|
313 | }
|
---|
314 | }
|
---|
315 | function push(to, state) {
|
---|
316 | action = Action.Push;
|
---|
317 | let location = createLocation(history.location, to, state);
|
---|
318 | if (validateLocation) validateLocation(location, to);
|
---|
319 | index = getIndex() + 1;
|
---|
320 | let historyState = getHistoryState(location, index);
|
---|
321 | let url = history.createHref(location);
|
---|
322 | try {
|
---|
323 | globalHistory.pushState(historyState, "", url);
|
---|
324 | } catch (error) {
|
---|
325 | if (error instanceof DOMException && error.name === "DataCloneError") {
|
---|
326 | throw error;
|
---|
327 | }
|
---|
328 | window2.location.assign(url);
|
---|
329 | }
|
---|
330 | if (v5Compat && listener) {
|
---|
331 | listener({
|
---|
332 | action,
|
---|
333 | location: history.location,
|
---|
334 | delta: 1
|
---|
335 | });
|
---|
336 | }
|
---|
337 | }
|
---|
338 | function replace2(to, state) {
|
---|
339 | action = Action.Replace;
|
---|
340 | let location = createLocation(history.location, to, state);
|
---|
341 | if (validateLocation) validateLocation(location, to);
|
---|
342 | index = getIndex();
|
---|
343 | let historyState = getHistoryState(location, index);
|
---|
344 | let url = history.createHref(location);
|
---|
345 | globalHistory.replaceState(historyState, "", url);
|
---|
346 | if (v5Compat && listener) {
|
---|
347 | listener({
|
---|
348 | action,
|
---|
349 | location: history.location,
|
---|
350 | delta: 0
|
---|
351 | });
|
---|
352 | }
|
---|
353 | }
|
---|
354 | function createURL(to) {
|
---|
355 | let base = window2.location.origin !== "null" ? window2.location.origin : window2.location.href;
|
---|
356 | let href = typeof to === "string" ? to : createPath(to);
|
---|
357 | href = href.replace(/ $/, "%20");
|
---|
358 | invariant(base, "No window.location.(origin|href) available to create URL for href: " + href);
|
---|
359 | return new URL(href, base);
|
---|
360 | }
|
---|
361 | let history = {
|
---|
362 | get action() {
|
---|
363 | return action;
|
---|
364 | },
|
---|
365 | get location() {
|
---|
366 | return getLocation(window2, globalHistory);
|
---|
367 | },
|
---|
368 | listen(fn) {
|
---|
369 | if (listener) {
|
---|
370 | throw new Error("A history only accepts one active listener");
|
---|
371 | }
|
---|
372 | window2.addEventListener(PopStateEventType, handlePop);
|
---|
373 | listener = fn;
|
---|
374 | return () => {
|
---|
375 | window2.removeEventListener(PopStateEventType, handlePop);
|
---|
376 | listener = null;
|
---|
377 | };
|
---|
378 | },
|
---|
379 | createHref(to) {
|
---|
380 | return createHref(window2, to);
|
---|
381 | },
|
---|
382 | createURL,
|
---|
383 | encodeLocation(to) {
|
---|
384 | let url = createURL(to);
|
---|
385 | return {
|
---|
386 | pathname: url.pathname,
|
---|
387 | search: url.search,
|
---|
388 | hash: url.hash
|
---|
389 | };
|
---|
390 | },
|
---|
391 | push,
|
---|
392 | replace: replace2,
|
---|
393 | go(n) {
|
---|
394 | return globalHistory.go(n);
|
---|
395 | }
|
---|
396 | };
|
---|
397 | return history;
|
---|
398 | }
|
---|
399 | var ResultType;
|
---|
400 | (function(ResultType2) {
|
---|
401 | ResultType2["data"] = "data";
|
---|
402 | ResultType2["deferred"] = "deferred";
|
---|
403 | ResultType2["redirect"] = "redirect";
|
---|
404 | ResultType2["error"] = "error";
|
---|
405 | })(ResultType || (ResultType = {}));
|
---|
406 | var immutableRouteKeys = /* @__PURE__ */ new Set(["lazy", "caseSensitive", "path", "id", "index", "children"]);
|
---|
407 | function isIndexRoute(route) {
|
---|
408 | return route.index === true;
|
---|
409 | }
|
---|
410 | function convertRoutesToDataRoutes(routes, mapRouteProperties2, parentPath, manifest) {
|
---|
411 | if (parentPath === void 0) {
|
---|
412 | parentPath = [];
|
---|
413 | }
|
---|
414 | if (manifest === void 0) {
|
---|
415 | manifest = {};
|
---|
416 | }
|
---|
417 | return routes.map((route, index) => {
|
---|
418 | let treePath = [...parentPath, String(index)];
|
---|
419 | let id = typeof route.id === "string" ? route.id : treePath.join("-");
|
---|
420 | invariant(route.index !== true || !route.children, "Cannot specify children on an index route");
|
---|
421 | invariant(!manifest[id], 'Found a route id collision on id "' + id + `". Route id's must be globally unique within Data Router usages`);
|
---|
422 | if (isIndexRoute(route)) {
|
---|
423 | let indexRoute = _extends({}, route, mapRouteProperties2(route), {
|
---|
424 | id
|
---|
425 | });
|
---|
426 | manifest[id] = indexRoute;
|
---|
427 | return indexRoute;
|
---|
428 | } else {
|
---|
429 | let pathOrLayoutRoute = _extends({}, route, mapRouteProperties2(route), {
|
---|
430 | id,
|
---|
431 | children: void 0
|
---|
432 | });
|
---|
433 | manifest[id] = pathOrLayoutRoute;
|
---|
434 | if (route.children) {
|
---|
435 | pathOrLayoutRoute.children = convertRoutesToDataRoutes(route.children, mapRouteProperties2, treePath, manifest);
|
---|
436 | }
|
---|
437 | return pathOrLayoutRoute;
|
---|
438 | }
|
---|
439 | });
|
---|
440 | }
|
---|
441 | function matchRoutes(routes, locationArg, basename) {
|
---|
442 | if (basename === void 0) {
|
---|
443 | basename = "/";
|
---|
444 | }
|
---|
445 | return matchRoutesImpl(routes, locationArg, basename, false);
|
---|
446 | }
|
---|
447 | function matchRoutesImpl(routes, locationArg, basename, allowPartial) {
|
---|
448 | let location = typeof locationArg === "string" ? parsePath(locationArg) : locationArg;
|
---|
449 | let pathname = stripBasename(location.pathname || "/", basename);
|
---|
450 | if (pathname == null) {
|
---|
451 | return null;
|
---|
452 | }
|
---|
453 | let branches = flattenRoutes(routes);
|
---|
454 | rankRouteBranches(branches);
|
---|
455 | let matches = null;
|
---|
456 | for (let i = 0; matches == null && i < branches.length; ++i) {
|
---|
457 | let decoded = decodePath(pathname);
|
---|
458 | matches = matchRouteBranch(branches[i], decoded, allowPartial);
|
---|
459 | }
|
---|
460 | return matches;
|
---|
461 | }
|
---|
462 | function convertRouteMatchToUiMatch(match, loaderData) {
|
---|
463 | let {
|
---|
464 | route,
|
---|
465 | pathname,
|
---|
466 | params
|
---|
467 | } = match;
|
---|
468 | return {
|
---|
469 | id: route.id,
|
---|
470 | pathname,
|
---|
471 | params,
|
---|
472 | data: loaderData[route.id],
|
---|
473 | handle: route.handle
|
---|
474 | };
|
---|
475 | }
|
---|
476 | function flattenRoutes(routes, branches, parentsMeta, parentPath) {
|
---|
477 | if (branches === void 0) {
|
---|
478 | branches = [];
|
---|
479 | }
|
---|
480 | if (parentsMeta === void 0) {
|
---|
481 | parentsMeta = [];
|
---|
482 | }
|
---|
483 | if (parentPath === void 0) {
|
---|
484 | parentPath = "";
|
---|
485 | }
|
---|
486 | let flattenRoute = (route, index, relativePath) => {
|
---|
487 | let meta = {
|
---|
488 | relativePath: relativePath === void 0 ? route.path || "" : relativePath,
|
---|
489 | caseSensitive: route.caseSensitive === true,
|
---|
490 | childrenIndex: index,
|
---|
491 | route
|
---|
492 | };
|
---|
493 | if (meta.relativePath.startsWith("/")) {
|
---|
494 | invariant(meta.relativePath.startsWith(parentPath), '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.");
|
---|
495 | meta.relativePath = meta.relativePath.slice(parentPath.length);
|
---|
496 | }
|
---|
497 | let path = joinPaths([parentPath, meta.relativePath]);
|
---|
498 | let routesMeta = parentsMeta.concat(meta);
|
---|
499 | if (route.children && route.children.length > 0) {
|
---|
500 | invariant(
|
---|
501 | // Our types know better, but runtime JS may not!
|
---|
502 | // @ts-expect-error
|
---|
503 | route.index !== true,
|
---|
504 | "Index routes must not have child routes. Please remove " + ('all child routes from route path "' + path + '".')
|
---|
505 | );
|
---|
506 | flattenRoutes(route.children, branches, routesMeta, path);
|
---|
507 | }
|
---|
508 | if (route.path == null && !route.index) {
|
---|
509 | return;
|
---|
510 | }
|
---|
511 | branches.push({
|
---|
512 | path,
|
---|
513 | score: computeScore(path, route.index),
|
---|
514 | routesMeta
|
---|
515 | });
|
---|
516 | };
|
---|
517 | routes.forEach((route, index) => {
|
---|
518 | var _route$path;
|
---|
519 | if (route.path === "" || !((_route$path = route.path) != null && _route$path.includes("?"))) {
|
---|
520 | flattenRoute(route, index);
|
---|
521 | } else {
|
---|
522 | for (let exploded of explodeOptionalSegments(route.path)) {
|
---|
523 | flattenRoute(route, index, exploded);
|
---|
524 | }
|
---|
525 | }
|
---|
526 | });
|
---|
527 | return branches;
|
---|
528 | }
|
---|
529 | function explodeOptionalSegments(path) {
|
---|
530 | let segments = path.split("/");
|
---|
531 | if (segments.length === 0) return [];
|
---|
532 | let [first, ...rest] = segments;
|
---|
533 | let isOptional = first.endsWith("?");
|
---|
534 | let required = first.replace(/\?$/, "");
|
---|
535 | if (rest.length === 0) {
|
---|
536 | return isOptional ? [required, ""] : [required];
|
---|
537 | }
|
---|
538 | let restExploded = explodeOptionalSegments(rest.join("/"));
|
---|
539 | let result = [];
|
---|
540 | result.push(...restExploded.map((subpath) => subpath === "" ? required : [required, subpath].join("/")));
|
---|
541 | if (isOptional) {
|
---|
542 | result.push(...restExploded);
|
---|
543 | }
|
---|
544 | return result.map((exploded) => path.startsWith("/") && exploded === "" ? "/" : exploded);
|
---|
545 | }
|
---|
546 | function rankRouteBranches(branches) {
|
---|
547 | branches.sort((a, b) => a.score !== b.score ? b.score - a.score : compareIndexes(a.routesMeta.map((meta) => meta.childrenIndex), b.routesMeta.map((meta) => meta.childrenIndex)));
|
---|
548 | }
|
---|
549 | var paramRe = /^:[\w-]+$/;
|
---|
550 | var dynamicSegmentValue = 3;
|
---|
551 | var indexRouteValue = 2;
|
---|
552 | var emptySegmentValue = 1;
|
---|
553 | var staticSegmentValue = 10;
|
---|
554 | var splatPenalty = -2;
|
---|
555 | var isSplat = (s) => s === "*";
|
---|
556 | function computeScore(path, index) {
|
---|
557 | let segments = path.split("/");
|
---|
558 | let initialScore = segments.length;
|
---|
559 | if (segments.some(isSplat)) {
|
---|
560 | initialScore += splatPenalty;
|
---|
561 | }
|
---|
562 | if (index) {
|
---|
563 | initialScore += indexRouteValue;
|
---|
564 | }
|
---|
565 | return segments.filter((s) => !isSplat(s)).reduce((score, segment) => score + (paramRe.test(segment) ? dynamicSegmentValue : segment === "" ? emptySegmentValue : staticSegmentValue), initialScore);
|
---|
566 | }
|
---|
567 | function compareIndexes(a, b) {
|
---|
568 | let siblings = a.length === b.length && a.slice(0, -1).every((n, i) => n === b[i]);
|
---|
569 | return siblings ? (
|
---|
570 | // If two routes are siblings, we should try to match the earlier sibling
|
---|
571 | // first. This allows people to have fine-grained control over the matching
|
---|
572 | // behavior by simply putting routes with identical paths in the order they
|
---|
573 | // want them tried.
|
---|
574 | a[a.length - 1] - b[b.length - 1]
|
---|
575 | ) : (
|
---|
576 | // Otherwise, it doesn't really make sense to rank non-siblings by index,
|
---|
577 | // so they sort equally.
|
---|
578 | 0
|
---|
579 | );
|
---|
580 | }
|
---|
581 | function matchRouteBranch(branch, pathname, allowPartial) {
|
---|
582 | if (allowPartial === void 0) {
|
---|
583 | allowPartial = false;
|
---|
584 | }
|
---|
585 | let {
|
---|
586 | routesMeta
|
---|
587 | } = branch;
|
---|
588 | let matchedParams = {};
|
---|
589 | let matchedPathname = "/";
|
---|
590 | let matches = [];
|
---|
591 | for (let i = 0; i < routesMeta.length; ++i) {
|
---|
592 | let meta = routesMeta[i];
|
---|
593 | let end = i === routesMeta.length - 1;
|
---|
594 | let remainingPathname = matchedPathname === "/" ? pathname : pathname.slice(matchedPathname.length) || "/";
|
---|
595 | let match = matchPath({
|
---|
596 | path: meta.relativePath,
|
---|
597 | caseSensitive: meta.caseSensitive,
|
---|
598 | end
|
---|
599 | }, remainingPathname);
|
---|
600 | let route = meta.route;
|
---|
601 | if (!match && end && allowPartial && !routesMeta[routesMeta.length - 1].route.index) {
|
---|
602 | match = matchPath({
|
---|
603 | path: meta.relativePath,
|
---|
604 | caseSensitive: meta.caseSensitive,
|
---|
605 | end: false
|
---|
606 | }, remainingPathname);
|
---|
607 | }
|
---|
608 | if (!match) {
|
---|
609 | return null;
|
---|
610 | }
|
---|
611 | Object.assign(matchedParams, match.params);
|
---|
612 | matches.push({
|
---|
613 | // TODO: Can this as be avoided?
|
---|
614 | params: matchedParams,
|
---|
615 | pathname: joinPaths([matchedPathname, match.pathname]),
|
---|
616 | pathnameBase: normalizePathname(joinPaths([matchedPathname, match.pathnameBase])),
|
---|
617 | route
|
---|
618 | });
|
---|
619 | if (match.pathnameBase !== "/") {
|
---|
620 | matchedPathname = joinPaths([matchedPathname, match.pathnameBase]);
|
---|
621 | }
|
---|
622 | }
|
---|
623 | return matches;
|
---|
624 | }
|
---|
625 | function generatePath(originalPath, params) {
|
---|
626 | if (params === void 0) {
|
---|
627 | params = {};
|
---|
628 | }
|
---|
629 | let path = originalPath;
|
---|
630 | if (path.endsWith("*") && path !== "*" && !path.endsWith("/*")) {
|
---|
631 | warning(false, '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(/\*$/, "/*") + '".'));
|
---|
632 | path = path.replace(/\*$/, "/*");
|
---|
633 | }
|
---|
634 | const prefix = path.startsWith("/") ? "/" : "";
|
---|
635 | const stringify = (p) => p == null ? "" : typeof p === "string" ? p : String(p);
|
---|
636 | const segments = path.split(/\/+/).map((segment, index, array) => {
|
---|
637 | const isLastSegment = index === array.length - 1;
|
---|
638 | if (isLastSegment && segment === "*") {
|
---|
639 | const star = "*";
|
---|
640 | return stringify(params[star]);
|
---|
641 | }
|
---|
642 | const keyMatch = segment.match(/^:([\w-]+)(\??)$/);
|
---|
643 | if (keyMatch) {
|
---|
644 | const [, key, optional] = keyMatch;
|
---|
645 | let param = params[key];
|
---|
646 | invariant(optional === "?" || param != null, 'Missing ":' + key + '" param');
|
---|
647 | return stringify(param);
|
---|
648 | }
|
---|
649 | return segment.replace(/\?$/g, "");
|
---|
650 | }).filter((segment) => !!segment);
|
---|
651 | return prefix + segments.join("/");
|
---|
652 | }
|
---|
653 | function matchPath(pattern, pathname) {
|
---|
654 | if (typeof pattern === "string") {
|
---|
655 | pattern = {
|
---|
656 | path: pattern,
|
---|
657 | caseSensitive: false,
|
---|
658 | end: true
|
---|
659 | };
|
---|
660 | }
|
---|
661 | let [matcher, compiledParams] = compilePath(pattern.path, pattern.caseSensitive, pattern.end);
|
---|
662 | let match = pathname.match(matcher);
|
---|
663 | if (!match) return null;
|
---|
664 | let matchedPathname = match[0];
|
---|
665 | let pathnameBase = matchedPathname.replace(/(.)\/+$/, "$1");
|
---|
666 | let captureGroups = match.slice(1);
|
---|
667 | let params = compiledParams.reduce((memo2, _ref, index) => {
|
---|
668 | let {
|
---|
669 | paramName,
|
---|
670 | isOptional
|
---|
671 | } = _ref;
|
---|
672 | if (paramName === "*") {
|
---|
673 | let splatValue = captureGroups[index] || "";
|
---|
674 | pathnameBase = matchedPathname.slice(0, matchedPathname.length - splatValue.length).replace(/(.)\/+$/, "$1");
|
---|
675 | }
|
---|
676 | const value = captureGroups[index];
|
---|
677 | if (isOptional && !value) {
|
---|
678 | memo2[paramName] = void 0;
|
---|
679 | } else {
|
---|
680 | memo2[paramName] = (value || "").replace(/%2F/g, "/");
|
---|
681 | }
|
---|
682 | return memo2;
|
---|
683 | }, {});
|
---|
684 | return {
|
---|
685 | params,
|
---|
686 | pathname: matchedPathname,
|
---|
687 | pathnameBase,
|
---|
688 | pattern
|
---|
689 | };
|
---|
690 | }
|
---|
691 | function compilePath(path, caseSensitive, end) {
|
---|
692 | if (caseSensitive === void 0) {
|
---|
693 | caseSensitive = false;
|
---|
694 | }
|
---|
695 | if (end === void 0) {
|
---|
696 | end = true;
|
---|
697 | }
|
---|
698 | warning(path === "*" || !path.endsWith("*") || path.endsWith("/*"), '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(/\*$/, "/*") + '".'));
|
---|
699 | let params = [];
|
---|
700 | let regexpSource = "^" + path.replace(/\/*\*?$/, "").replace(/^\/*/, "/").replace(/[\\.*+^${}|()[\]]/g, "\\$&").replace(/\/:([\w-]+)(\?)?/g, (_, paramName, isOptional) => {
|
---|
701 | params.push({
|
---|
702 | paramName,
|
---|
703 | isOptional: isOptional != null
|
---|
704 | });
|
---|
705 | return isOptional ? "/?([^\\/]+)?" : "/([^\\/]+)";
|
---|
706 | });
|
---|
707 | if (path.endsWith("*")) {
|
---|
708 | params.push({
|
---|
709 | paramName: "*"
|
---|
710 | });
|
---|
711 | regexpSource += path === "*" || path === "/*" ? "(.*)$" : "(?:\\/(.+)|\\/*)$";
|
---|
712 | } else if (end) {
|
---|
713 | regexpSource += "\\/*$";
|
---|
714 | } else if (path !== "" && path !== "/") {
|
---|
715 | regexpSource += "(?:(?=\\/|$))";
|
---|
716 | } else ;
|
---|
717 | let matcher = new RegExp(regexpSource, caseSensitive ? void 0 : "i");
|
---|
718 | return [matcher, params];
|
---|
719 | }
|
---|
720 | function decodePath(value) {
|
---|
721 | try {
|
---|
722 | return value.split("/").map((v) => decodeURIComponent(v).replace(/\//g, "%2F")).join("/");
|
---|
723 | } catch (error) {
|
---|
724 | warning(false, 'The URL path "' + value + '" could not be decoded because it is is a malformed URL segment. This is probably due to a bad percent ' + ("encoding (" + error + ")."));
|
---|
725 | return value;
|
---|
726 | }
|
---|
727 | }
|
---|
728 | function stripBasename(pathname, basename) {
|
---|
729 | if (basename === "/") return pathname;
|
---|
730 | if (!pathname.toLowerCase().startsWith(basename.toLowerCase())) {
|
---|
731 | return null;
|
---|
732 | }
|
---|
733 | let startIndex = basename.endsWith("/") ? basename.length - 1 : basename.length;
|
---|
734 | let nextChar = pathname.charAt(startIndex);
|
---|
735 | if (nextChar && nextChar !== "/") {
|
---|
736 | return null;
|
---|
737 | }
|
---|
738 | return pathname.slice(startIndex) || "/";
|
---|
739 | }
|
---|
740 | function resolvePath(to, fromPathname) {
|
---|
741 | if (fromPathname === void 0) {
|
---|
742 | fromPathname = "/";
|
---|
743 | }
|
---|
744 | let {
|
---|
745 | pathname: toPathname,
|
---|
746 | search = "",
|
---|
747 | hash = ""
|
---|
748 | } = typeof to === "string" ? parsePath(to) : to;
|
---|
749 | let pathname = toPathname ? toPathname.startsWith("/") ? toPathname : resolvePathname(toPathname, fromPathname) : fromPathname;
|
---|
750 | return {
|
---|
751 | pathname,
|
---|
752 | search: normalizeSearch(search),
|
---|
753 | hash: normalizeHash(hash)
|
---|
754 | };
|
---|
755 | }
|
---|
756 | function resolvePathname(relativePath, fromPathname) {
|
---|
757 | let segments = fromPathname.replace(/\/+$/, "").split("/");
|
---|
758 | let relativeSegments = relativePath.split("/");
|
---|
759 | relativeSegments.forEach((segment) => {
|
---|
760 | if (segment === "..") {
|
---|
761 | if (segments.length > 1) segments.pop();
|
---|
762 | } else if (segment !== ".") {
|
---|
763 | segments.push(segment);
|
---|
764 | }
|
---|
765 | });
|
---|
766 | return segments.length > 1 ? segments.join("/") : "/";
|
---|
767 | }
|
---|
768 | function getInvalidPathError(char, field, dest, path) {
|
---|
769 | return "Cannot include a '" + char + "' character in a manually specified " + ("`to." + field + "` field [" + JSON.stringify(path) + "]. 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.';
|
---|
770 | }
|
---|
771 | function getPathContributingMatches(matches) {
|
---|
772 | return matches.filter((match, index) => index === 0 || match.route.path && match.route.path.length > 0);
|
---|
773 | }
|
---|
774 | function getResolveToMatches(matches, v7_relativeSplatPath) {
|
---|
775 | let pathMatches = getPathContributingMatches(matches);
|
---|
776 | if (v7_relativeSplatPath) {
|
---|
777 | return pathMatches.map((match, idx) => idx === pathMatches.length - 1 ? match.pathname : match.pathnameBase);
|
---|
778 | }
|
---|
779 | return pathMatches.map((match) => match.pathnameBase);
|
---|
780 | }
|
---|
781 | function resolveTo(toArg, routePathnames, locationPathname, isPathRelative) {
|
---|
782 | if (isPathRelative === void 0) {
|
---|
783 | isPathRelative = false;
|
---|
784 | }
|
---|
785 | let to;
|
---|
786 | if (typeof toArg === "string") {
|
---|
787 | to = parsePath(toArg);
|
---|
788 | } else {
|
---|
789 | to = _extends({}, toArg);
|
---|
790 | invariant(!to.pathname || !to.pathname.includes("?"), getInvalidPathError("?", "pathname", "search", to));
|
---|
791 | invariant(!to.pathname || !to.pathname.includes("#"), getInvalidPathError("#", "pathname", "hash", to));
|
---|
792 | invariant(!to.search || !to.search.includes("#"), getInvalidPathError("#", "search", "hash", to));
|
---|
793 | }
|
---|
794 | let isEmptyPath = toArg === "" || to.pathname === "";
|
---|
795 | let toPathname = isEmptyPath ? "/" : to.pathname;
|
---|
796 | let from;
|
---|
797 | if (toPathname == null) {
|
---|
798 | from = locationPathname;
|
---|
799 | } else {
|
---|
800 | let routePathnameIndex = routePathnames.length - 1;
|
---|
801 | if (!isPathRelative && toPathname.startsWith("..")) {
|
---|
802 | let toSegments = toPathname.split("/");
|
---|
803 | while (toSegments[0] === "..") {
|
---|
804 | toSegments.shift();
|
---|
805 | routePathnameIndex -= 1;
|
---|
806 | }
|
---|
807 | to.pathname = toSegments.join("/");
|
---|
808 | }
|
---|
809 | from = routePathnameIndex >= 0 ? routePathnames[routePathnameIndex] : "/";
|
---|
810 | }
|
---|
811 | let path = resolvePath(to, from);
|
---|
812 | let hasExplicitTrailingSlash = toPathname && toPathname !== "/" && toPathname.endsWith("/");
|
---|
813 | let hasCurrentTrailingSlash = (isEmptyPath || toPathname === ".") && locationPathname.endsWith("/");
|
---|
814 | if (!path.pathname.endsWith("/") && (hasExplicitTrailingSlash || hasCurrentTrailingSlash)) {
|
---|
815 | path.pathname += "/";
|
---|
816 | }
|
---|
817 | return path;
|
---|
818 | }
|
---|
819 | var joinPaths = (paths) => paths.join("/").replace(/\/\/+/g, "/");
|
---|
820 | var normalizePathname = (pathname) => pathname.replace(/\/+$/, "").replace(/^\/*/, "/");
|
---|
821 | var normalizeSearch = (search) => !search || search === "?" ? "" : search.startsWith("?") ? search : "?" + search;
|
---|
822 | var normalizeHash = (hash) => !hash || hash === "#" ? "" : hash.startsWith("#") ? hash : "#" + hash;
|
---|
823 | var json = function json2(data, init) {
|
---|
824 | if (init === void 0) {
|
---|
825 | init = {};
|
---|
826 | }
|
---|
827 | let responseInit = typeof init === "number" ? {
|
---|
828 | status: init
|
---|
829 | } : init;
|
---|
830 | let headers = new Headers(responseInit.headers);
|
---|
831 | if (!headers.has("Content-Type")) {
|
---|
832 | headers.set("Content-Type", "application/json; charset=utf-8");
|
---|
833 | }
|
---|
834 | return new Response(JSON.stringify(data), _extends({}, responseInit, {
|
---|
835 | headers
|
---|
836 | }));
|
---|
837 | };
|
---|
838 | var AbortedDeferredError = class extends Error {
|
---|
839 | };
|
---|
840 | var DeferredData = class {
|
---|
841 | constructor(data, responseInit) {
|
---|
842 | this.pendingKeysSet = /* @__PURE__ */ new Set();
|
---|
843 | this.subscribers = /* @__PURE__ */ new Set();
|
---|
844 | this.deferredKeys = [];
|
---|
845 | invariant(data && typeof data === "object" && !Array.isArray(data), "defer() only accepts plain objects");
|
---|
846 | let reject;
|
---|
847 | this.abortPromise = new Promise((_, r) => reject = r);
|
---|
848 | this.controller = new AbortController();
|
---|
849 | let onAbort = () => reject(new AbortedDeferredError("Deferred data aborted"));
|
---|
850 | this.unlistenAbortSignal = () => this.controller.signal.removeEventListener("abort", onAbort);
|
---|
851 | this.controller.signal.addEventListener("abort", onAbort);
|
---|
852 | this.data = Object.entries(data).reduce((acc, _ref2) => {
|
---|
853 | let [key, value] = _ref2;
|
---|
854 | return Object.assign(acc, {
|
---|
855 | [key]: this.trackPromise(key, value)
|
---|
856 | });
|
---|
857 | }, {});
|
---|
858 | if (this.done) {
|
---|
859 | this.unlistenAbortSignal();
|
---|
860 | }
|
---|
861 | this.init = responseInit;
|
---|
862 | }
|
---|
863 | trackPromise(key, value) {
|
---|
864 | if (!(value instanceof Promise)) {
|
---|
865 | return value;
|
---|
866 | }
|
---|
867 | this.deferredKeys.push(key);
|
---|
868 | this.pendingKeysSet.add(key);
|
---|
869 | let promise = Promise.race([value, this.abortPromise]).then((data) => this.onSettle(promise, key, void 0, data), (error) => this.onSettle(promise, key, error));
|
---|
870 | promise.catch(() => {
|
---|
871 | });
|
---|
872 | Object.defineProperty(promise, "_tracked", {
|
---|
873 | get: () => true
|
---|
874 | });
|
---|
875 | return promise;
|
---|
876 | }
|
---|
877 | onSettle(promise, key, error, data) {
|
---|
878 | if (this.controller.signal.aborted && error instanceof AbortedDeferredError) {
|
---|
879 | this.unlistenAbortSignal();
|
---|
880 | Object.defineProperty(promise, "_error", {
|
---|
881 | get: () => error
|
---|
882 | });
|
---|
883 | return Promise.reject(error);
|
---|
884 | }
|
---|
885 | this.pendingKeysSet.delete(key);
|
---|
886 | if (this.done) {
|
---|
887 | this.unlistenAbortSignal();
|
---|
888 | }
|
---|
889 | if (error === void 0 && data === void 0) {
|
---|
890 | let undefinedError = new Error('Deferred data for key "' + key + '" resolved/rejected with `undefined`, you must resolve/reject with a value or `null`.');
|
---|
891 | Object.defineProperty(promise, "_error", {
|
---|
892 | get: () => undefinedError
|
---|
893 | });
|
---|
894 | this.emit(false, key);
|
---|
895 | return Promise.reject(undefinedError);
|
---|
896 | }
|
---|
897 | if (data === void 0) {
|
---|
898 | Object.defineProperty(promise, "_error", {
|
---|
899 | get: () => error
|
---|
900 | });
|
---|
901 | this.emit(false, key);
|
---|
902 | return Promise.reject(error);
|
---|
903 | }
|
---|
904 | Object.defineProperty(promise, "_data", {
|
---|
905 | get: () => data
|
---|
906 | });
|
---|
907 | this.emit(false, key);
|
---|
908 | return data;
|
---|
909 | }
|
---|
910 | emit(aborted, settledKey) {
|
---|
911 | this.subscribers.forEach((subscriber) => subscriber(aborted, settledKey));
|
---|
912 | }
|
---|
913 | subscribe(fn) {
|
---|
914 | this.subscribers.add(fn);
|
---|
915 | return () => this.subscribers.delete(fn);
|
---|
916 | }
|
---|
917 | cancel() {
|
---|
918 | this.controller.abort();
|
---|
919 | this.pendingKeysSet.forEach((v, k) => this.pendingKeysSet.delete(k));
|
---|
920 | this.emit(true);
|
---|
921 | }
|
---|
922 | async resolveData(signal) {
|
---|
923 | let aborted = false;
|
---|
924 | if (!this.done) {
|
---|
925 | let onAbort = () => this.cancel();
|
---|
926 | signal.addEventListener("abort", onAbort);
|
---|
927 | aborted = await new Promise((resolve) => {
|
---|
928 | this.subscribe((aborted2) => {
|
---|
929 | signal.removeEventListener("abort", onAbort);
|
---|
930 | if (aborted2 || this.done) {
|
---|
931 | resolve(aborted2);
|
---|
932 | }
|
---|
933 | });
|
---|
934 | });
|
---|
935 | }
|
---|
936 | return aborted;
|
---|
937 | }
|
---|
938 | get done() {
|
---|
939 | return this.pendingKeysSet.size === 0;
|
---|
940 | }
|
---|
941 | get unwrappedData() {
|
---|
942 | invariant(this.data !== null && this.done, "Can only unwrap data on initialized and settled deferreds");
|
---|
943 | return Object.entries(this.data).reduce((acc, _ref3) => {
|
---|
944 | let [key, value] = _ref3;
|
---|
945 | return Object.assign(acc, {
|
---|
946 | [key]: unwrapTrackedPromise(value)
|
---|
947 | });
|
---|
948 | }, {});
|
---|
949 | }
|
---|
950 | get pendingKeys() {
|
---|
951 | return Array.from(this.pendingKeysSet);
|
---|
952 | }
|
---|
953 | };
|
---|
954 | function isTrackedPromise(value) {
|
---|
955 | return value instanceof Promise && value._tracked === true;
|
---|
956 | }
|
---|
957 | function unwrapTrackedPromise(value) {
|
---|
958 | if (!isTrackedPromise(value)) {
|
---|
959 | return value;
|
---|
960 | }
|
---|
961 | if (value._error) {
|
---|
962 | throw value._error;
|
---|
963 | }
|
---|
964 | return value._data;
|
---|
965 | }
|
---|
966 | var defer = function defer2(data, init) {
|
---|
967 | if (init === void 0) {
|
---|
968 | init = {};
|
---|
969 | }
|
---|
970 | let responseInit = typeof init === "number" ? {
|
---|
971 | status: init
|
---|
972 | } : init;
|
---|
973 | return new DeferredData(data, responseInit);
|
---|
974 | };
|
---|
975 | var redirect = function redirect2(url, init) {
|
---|
976 | if (init === void 0) {
|
---|
977 | init = 302;
|
---|
978 | }
|
---|
979 | let responseInit = init;
|
---|
980 | if (typeof responseInit === "number") {
|
---|
981 | responseInit = {
|
---|
982 | status: responseInit
|
---|
983 | };
|
---|
984 | } else if (typeof responseInit.status === "undefined") {
|
---|
985 | responseInit.status = 302;
|
---|
986 | }
|
---|
987 | let headers = new Headers(responseInit.headers);
|
---|
988 | headers.set("Location", url);
|
---|
989 | return new Response(null, _extends({}, responseInit, {
|
---|
990 | headers
|
---|
991 | }));
|
---|
992 | };
|
---|
993 | var redirectDocument = (url, init) => {
|
---|
994 | let response = redirect(url, init);
|
---|
995 | response.headers.set("X-Remix-Reload-Document", "true");
|
---|
996 | return response;
|
---|
997 | };
|
---|
998 | var replace = (url, init) => {
|
---|
999 | let response = redirect(url, init);
|
---|
1000 | response.headers.set("X-Remix-Replace", "true");
|
---|
1001 | return response;
|
---|
1002 | };
|
---|
1003 | var ErrorResponseImpl = class {
|
---|
1004 | constructor(status, statusText, data, internal) {
|
---|
1005 | if (internal === void 0) {
|
---|
1006 | internal = false;
|
---|
1007 | }
|
---|
1008 | this.status = status;
|
---|
1009 | this.statusText = statusText || "";
|
---|
1010 | this.internal = internal;
|
---|
1011 | if (data instanceof Error) {
|
---|
1012 | this.data = data.toString();
|
---|
1013 | this.error = data;
|
---|
1014 | } else {
|
---|
1015 | this.data = data;
|
---|
1016 | }
|
---|
1017 | }
|
---|
1018 | };
|
---|
1019 | function isRouteErrorResponse(error) {
|
---|
1020 | return error != null && typeof error.status === "number" && typeof error.statusText === "string" && typeof error.internal === "boolean" && "data" in error;
|
---|
1021 | }
|
---|
1022 | var validMutationMethodsArr = ["post", "put", "patch", "delete"];
|
---|
1023 | var validMutationMethods = new Set(validMutationMethodsArr);
|
---|
1024 | var validRequestMethodsArr = ["get", ...validMutationMethodsArr];
|
---|
1025 | var validRequestMethods = new Set(validRequestMethodsArr);
|
---|
1026 | var redirectStatusCodes = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
---|
1027 | var redirectPreserveMethodStatusCodes = /* @__PURE__ */ new Set([307, 308]);
|
---|
1028 | var IDLE_NAVIGATION = {
|
---|
1029 | state: "idle",
|
---|
1030 | location: void 0,
|
---|
1031 | formMethod: void 0,
|
---|
1032 | formAction: void 0,
|
---|
1033 | formEncType: void 0,
|
---|
1034 | formData: void 0,
|
---|
1035 | json: void 0,
|
---|
1036 | text: void 0
|
---|
1037 | };
|
---|
1038 | var IDLE_FETCHER = {
|
---|
1039 | state: "idle",
|
---|
1040 | data: void 0,
|
---|
1041 | formMethod: void 0,
|
---|
1042 | formAction: void 0,
|
---|
1043 | formEncType: void 0,
|
---|
1044 | formData: void 0,
|
---|
1045 | json: void 0,
|
---|
1046 | text: void 0
|
---|
1047 | };
|
---|
1048 | var IDLE_BLOCKER = {
|
---|
1049 | state: "unblocked",
|
---|
1050 | proceed: void 0,
|
---|
1051 | reset: void 0,
|
---|
1052 | location: void 0
|
---|
1053 | };
|
---|
1054 | var ABSOLUTE_URL_REGEX = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
|
---|
1055 | var defaultMapRouteProperties = (route) => ({
|
---|
1056 | hasErrorBoundary: Boolean(route.hasErrorBoundary)
|
---|
1057 | });
|
---|
1058 | var TRANSITIONS_STORAGE_KEY = "remix-router-transitions";
|
---|
1059 | function createRouter(init) {
|
---|
1060 | const routerWindow = init.window ? init.window : typeof window !== "undefined" ? window : void 0;
|
---|
1061 | const isBrowser2 = typeof routerWindow !== "undefined" && typeof routerWindow.document !== "undefined" && typeof routerWindow.document.createElement !== "undefined";
|
---|
1062 | const isServer = !isBrowser2;
|
---|
1063 | invariant(init.routes.length > 0, "You must provide a non-empty routes array to createRouter");
|
---|
1064 | let mapRouteProperties2;
|
---|
1065 | if (init.mapRouteProperties) {
|
---|
1066 | mapRouteProperties2 = init.mapRouteProperties;
|
---|
1067 | } else if (init.detectErrorBoundary) {
|
---|
1068 | let detectErrorBoundary = init.detectErrorBoundary;
|
---|
1069 | mapRouteProperties2 = (route) => ({
|
---|
1070 | hasErrorBoundary: detectErrorBoundary(route)
|
---|
1071 | });
|
---|
1072 | } else {
|
---|
1073 | mapRouteProperties2 = defaultMapRouteProperties;
|
---|
1074 | }
|
---|
1075 | let manifest = {};
|
---|
1076 | let dataRoutes = convertRoutesToDataRoutes(init.routes, mapRouteProperties2, void 0, manifest);
|
---|
1077 | let inFlightDataRoutes;
|
---|
1078 | let basename = init.basename || "/";
|
---|
1079 | let dataStrategyImpl = init.dataStrategy || defaultDataStrategy;
|
---|
1080 | let patchRoutesOnNavigationImpl = init.patchRoutesOnNavigation;
|
---|
1081 | let future = _extends({
|
---|
1082 | v7_fetcherPersist: false,
|
---|
1083 | v7_normalizeFormMethod: false,
|
---|
1084 | v7_partialHydration: false,
|
---|
1085 | v7_prependBasename: false,
|
---|
1086 | v7_relativeSplatPath: false,
|
---|
1087 | v7_skipActionErrorRevalidation: false
|
---|
1088 | }, init.future);
|
---|
1089 | let unlistenHistory = null;
|
---|
1090 | let subscribers = /* @__PURE__ */ new Set();
|
---|
1091 | let savedScrollPositions2 = null;
|
---|
1092 | let getScrollRestorationKey = null;
|
---|
1093 | let getScrollPosition = null;
|
---|
1094 | let initialScrollRestored = init.hydrationData != null;
|
---|
1095 | let initialMatches = matchRoutes(dataRoutes, init.history.location, basename);
|
---|
1096 | let initialErrors = null;
|
---|
1097 | if (initialMatches == null && !patchRoutesOnNavigationImpl) {
|
---|
1098 | let error = getInternalRouterError(404, {
|
---|
1099 | pathname: init.history.location.pathname
|
---|
1100 | });
|
---|
1101 | let {
|
---|
1102 | matches,
|
---|
1103 | route
|
---|
1104 | } = getShortCircuitMatches(dataRoutes);
|
---|
1105 | initialMatches = matches;
|
---|
1106 | initialErrors = {
|
---|
1107 | [route.id]: error
|
---|
1108 | };
|
---|
1109 | }
|
---|
1110 | if (initialMatches && !init.hydrationData) {
|
---|
1111 | let fogOfWar = checkFogOfWar(initialMatches, dataRoutes, init.history.location.pathname);
|
---|
1112 | if (fogOfWar.active) {
|
---|
1113 | initialMatches = null;
|
---|
1114 | }
|
---|
1115 | }
|
---|
1116 | let initialized;
|
---|
1117 | if (!initialMatches) {
|
---|
1118 | initialized = false;
|
---|
1119 | initialMatches = [];
|
---|
1120 | if (future.v7_partialHydration) {
|
---|
1121 | let fogOfWar = checkFogOfWar(null, dataRoutes, init.history.location.pathname);
|
---|
1122 | if (fogOfWar.active && fogOfWar.matches) {
|
---|
1123 | initialMatches = fogOfWar.matches;
|
---|
1124 | }
|
---|
1125 | }
|
---|
1126 | } else if (initialMatches.some((m) => m.route.lazy)) {
|
---|
1127 | initialized = false;
|
---|
1128 | } else if (!initialMatches.some((m) => m.route.loader)) {
|
---|
1129 | initialized = true;
|
---|
1130 | } else if (future.v7_partialHydration) {
|
---|
1131 | let loaderData = init.hydrationData ? init.hydrationData.loaderData : null;
|
---|
1132 | let errors = init.hydrationData ? init.hydrationData.errors : null;
|
---|
1133 | if (errors) {
|
---|
1134 | let idx = initialMatches.findIndex((m) => errors[m.route.id] !== void 0);
|
---|
1135 | initialized = initialMatches.slice(0, idx + 1).every((m) => !shouldLoadRouteOnHydration(m.route, loaderData, errors));
|
---|
1136 | } else {
|
---|
1137 | initialized = initialMatches.every((m) => !shouldLoadRouteOnHydration(m.route, loaderData, errors));
|
---|
1138 | }
|
---|
1139 | } else {
|
---|
1140 | initialized = init.hydrationData != null;
|
---|
1141 | }
|
---|
1142 | let router;
|
---|
1143 | let state = {
|
---|
1144 | historyAction: init.history.action,
|
---|
1145 | location: init.history.location,
|
---|
1146 | matches: initialMatches,
|
---|
1147 | initialized,
|
---|
1148 | navigation: IDLE_NAVIGATION,
|
---|
1149 | // Don't restore on initial updateState() if we were SSR'd
|
---|
1150 | restoreScrollPosition: init.hydrationData != null ? false : null,
|
---|
1151 | preventScrollReset: false,
|
---|
1152 | revalidation: "idle",
|
---|
1153 | loaderData: init.hydrationData && init.hydrationData.loaderData || {},
|
---|
1154 | actionData: init.hydrationData && init.hydrationData.actionData || null,
|
---|
1155 | errors: init.hydrationData && init.hydrationData.errors || initialErrors,
|
---|
1156 | fetchers: /* @__PURE__ */ new Map(),
|
---|
1157 | blockers: /* @__PURE__ */ new Map()
|
---|
1158 | };
|
---|
1159 | let pendingAction = Action.Pop;
|
---|
1160 | let pendingPreventScrollReset = false;
|
---|
1161 | let pendingNavigationController;
|
---|
1162 | let pendingViewTransitionEnabled = false;
|
---|
1163 | let appliedViewTransitions = /* @__PURE__ */ new Map();
|
---|
1164 | let removePageHideEventListener = null;
|
---|
1165 | let isUninterruptedRevalidation = false;
|
---|
1166 | let isRevalidationRequired = false;
|
---|
1167 | let cancelledDeferredRoutes = [];
|
---|
1168 | let cancelledFetcherLoads = /* @__PURE__ */ new Set();
|
---|
1169 | let fetchControllers = /* @__PURE__ */ new Map();
|
---|
1170 | let incrementingLoadId = 0;
|
---|
1171 | let pendingNavigationLoadId = -1;
|
---|
1172 | let fetchReloadIds = /* @__PURE__ */ new Map();
|
---|
1173 | let fetchRedirectIds = /* @__PURE__ */ new Set();
|
---|
1174 | let fetchLoadMatches = /* @__PURE__ */ new Map();
|
---|
1175 | let activeFetchers = /* @__PURE__ */ new Map();
|
---|
1176 | let deletedFetchers = /* @__PURE__ */ new Set();
|
---|
1177 | let activeDeferreds = /* @__PURE__ */ new Map();
|
---|
1178 | let blockerFunctions = /* @__PURE__ */ new Map();
|
---|
1179 | let unblockBlockerHistoryUpdate = void 0;
|
---|
1180 | function initialize() {
|
---|
1181 | unlistenHistory = init.history.listen((_ref) => {
|
---|
1182 | let {
|
---|
1183 | action: historyAction,
|
---|
1184 | location,
|
---|
1185 | delta
|
---|
1186 | } = _ref;
|
---|
1187 | if (unblockBlockerHistoryUpdate) {
|
---|
1188 | unblockBlockerHistoryUpdate();
|
---|
1189 | unblockBlockerHistoryUpdate = void 0;
|
---|
1190 | return;
|
---|
1191 | }
|
---|
1192 | warning(blockerFunctions.size === 0 || delta != null, "You are trying to use a blocker on a POP navigation to a location that was not created by @remix-run/router. This will fail silently in production. This can happen if you are navigating outside the router via `window.history.pushState`/`window.location.hash` instead of using router navigation APIs. This can also happen if you are using createHashRouter and the user manually changes the URL.");
|
---|
1193 | let blockerKey = shouldBlockNavigation({
|
---|
1194 | currentLocation: state.location,
|
---|
1195 | nextLocation: location,
|
---|
1196 | historyAction
|
---|
1197 | });
|
---|
1198 | if (blockerKey && delta != null) {
|
---|
1199 | let nextHistoryUpdatePromise = new Promise((resolve) => {
|
---|
1200 | unblockBlockerHistoryUpdate = resolve;
|
---|
1201 | });
|
---|
1202 | init.history.go(delta * -1);
|
---|
1203 | updateBlocker(blockerKey, {
|
---|
1204 | state: "blocked",
|
---|
1205 | location,
|
---|
1206 | proceed() {
|
---|
1207 | updateBlocker(blockerKey, {
|
---|
1208 | state: "proceeding",
|
---|
1209 | proceed: void 0,
|
---|
1210 | reset: void 0,
|
---|
1211 | location
|
---|
1212 | });
|
---|
1213 | nextHistoryUpdatePromise.then(() => init.history.go(delta));
|
---|
1214 | },
|
---|
1215 | reset() {
|
---|
1216 | let blockers = new Map(state.blockers);
|
---|
1217 | blockers.set(blockerKey, IDLE_BLOCKER);
|
---|
1218 | updateState({
|
---|
1219 | blockers
|
---|
1220 | });
|
---|
1221 | }
|
---|
1222 | });
|
---|
1223 | return;
|
---|
1224 | }
|
---|
1225 | return startNavigation(historyAction, location);
|
---|
1226 | });
|
---|
1227 | if (isBrowser2) {
|
---|
1228 | restoreAppliedTransitions(routerWindow, appliedViewTransitions);
|
---|
1229 | let _saveAppliedTransitions = () => persistAppliedTransitions(routerWindow, appliedViewTransitions);
|
---|
1230 | routerWindow.addEventListener("pagehide", _saveAppliedTransitions);
|
---|
1231 | removePageHideEventListener = () => routerWindow.removeEventListener("pagehide", _saveAppliedTransitions);
|
---|
1232 | }
|
---|
1233 | if (!state.initialized) {
|
---|
1234 | startNavigation(Action.Pop, state.location, {
|
---|
1235 | initialHydration: true
|
---|
1236 | });
|
---|
1237 | }
|
---|
1238 | return router;
|
---|
1239 | }
|
---|
1240 | function dispose() {
|
---|
1241 | if (unlistenHistory) {
|
---|
1242 | unlistenHistory();
|
---|
1243 | }
|
---|
1244 | if (removePageHideEventListener) {
|
---|
1245 | removePageHideEventListener();
|
---|
1246 | }
|
---|
1247 | subscribers.clear();
|
---|
1248 | pendingNavigationController && pendingNavigationController.abort();
|
---|
1249 | state.fetchers.forEach((_, key) => deleteFetcher(key));
|
---|
1250 | state.blockers.forEach((_, key) => deleteBlocker(key));
|
---|
1251 | }
|
---|
1252 | function subscribe(fn) {
|
---|
1253 | subscribers.add(fn);
|
---|
1254 | return () => subscribers.delete(fn);
|
---|
1255 | }
|
---|
1256 | function updateState(newState, opts) {
|
---|
1257 | if (opts === void 0) {
|
---|
1258 | opts = {};
|
---|
1259 | }
|
---|
1260 | state = _extends({}, state, newState);
|
---|
1261 | let completedFetchers = [];
|
---|
1262 | let deletedFetchersKeys = [];
|
---|
1263 | if (future.v7_fetcherPersist) {
|
---|
1264 | state.fetchers.forEach((fetcher, key) => {
|
---|
1265 | if (fetcher.state === "idle") {
|
---|
1266 | if (deletedFetchers.has(key)) {
|
---|
1267 | deletedFetchersKeys.push(key);
|
---|
1268 | } else {
|
---|
1269 | completedFetchers.push(key);
|
---|
1270 | }
|
---|
1271 | }
|
---|
1272 | });
|
---|
1273 | }
|
---|
1274 | [...subscribers].forEach((subscriber) => subscriber(state, {
|
---|
1275 | deletedFetchers: deletedFetchersKeys,
|
---|
1276 | viewTransitionOpts: opts.viewTransitionOpts,
|
---|
1277 | flushSync: opts.flushSync === true
|
---|
1278 | }));
|
---|
1279 | if (future.v7_fetcherPersist) {
|
---|
1280 | completedFetchers.forEach((key) => state.fetchers.delete(key));
|
---|
1281 | deletedFetchersKeys.forEach((key) => deleteFetcher(key));
|
---|
1282 | }
|
---|
1283 | }
|
---|
1284 | function completeNavigation(location, newState, _temp) {
|
---|
1285 | var _location$state, _location$state2;
|
---|
1286 | let {
|
---|
1287 | flushSync
|
---|
1288 | } = _temp === void 0 ? {} : _temp;
|
---|
1289 | let isActionReload = state.actionData != null && state.navigation.formMethod != null && isMutationMethod(state.navigation.formMethod) && state.navigation.state === "loading" && ((_location$state = location.state) == null ? void 0 : _location$state._isRedirect) !== true;
|
---|
1290 | let actionData;
|
---|
1291 | if (newState.actionData) {
|
---|
1292 | if (Object.keys(newState.actionData).length > 0) {
|
---|
1293 | actionData = newState.actionData;
|
---|
1294 | } else {
|
---|
1295 | actionData = null;
|
---|
1296 | }
|
---|
1297 | } else if (isActionReload) {
|
---|
1298 | actionData = state.actionData;
|
---|
1299 | } else {
|
---|
1300 | actionData = null;
|
---|
1301 | }
|
---|
1302 | let loaderData = newState.loaderData ? mergeLoaderData(state.loaderData, newState.loaderData, newState.matches || [], newState.errors) : state.loaderData;
|
---|
1303 | let blockers = state.blockers;
|
---|
1304 | if (blockers.size > 0) {
|
---|
1305 | blockers = new Map(blockers);
|
---|
1306 | blockers.forEach((_, k) => blockers.set(k, IDLE_BLOCKER));
|
---|
1307 | }
|
---|
1308 | let preventScrollReset = pendingPreventScrollReset === true || state.navigation.formMethod != null && isMutationMethod(state.navigation.formMethod) && ((_location$state2 = location.state) == null ? void 0 : _location$state2._isRedirect) !== true;
|
---|
1309 | if (inFlightDataRoutes) {
|
---|
1310 | dataRoutes = inFlightDataRoutes;
|
---|
1311 | inFlightDataRoutes = void 0;
|
---|
1312 | }
|
---|
1313 | if (isUninterruptedRevalidation) ;
|
---|
1314 | else if (pendingAction === Action.Pop) ;
|
---|
1315 | else if (pendingAction === Action.Push) {
|
---|
1316 | init.history.push(location, location.state);
|
---|
1317 | } else if (pendingAction === Action.Replace) {
|
---|
1318 | init.history.replace(location, location.state);
|
---|
1319 | }
|
---|
1320 | let viewTransitionOpts;
|
---|
1321 | if (pendingAction === Action.Pop) {
|
---|
1322 | let priorPaths = appliedViewTransitions.get(state.location.pathname);
|
---|
1323 | if (priorPaths && priorPaths.has(location.pathname)) {
|
---|
1324 | viewTransitionOpts = {
|
---|
1325 | currentLocation: state.location,
|
---|
1326 | nextLocation: location
|
---|
1327 | };
|
---|
1328 | } else if (appliedViewTransitions.has(location.pathname)) {
|
---|
1329 | viewTransitionOpts = {
|
---|
1330 | currentLocation: location,
|
---|
1331 | nextLocation: state.location
|
---|
1332 | };
|
---|
1333 | }
|
---|
1334 | } else if (pendingViewTransitionEnabled) {
|
---|
1335 | let toPaths = appliedViewTransitions.get(state.location.pathname);
|
---|
1336 | if (toPaths) {
|
---|
1337 | toPaths.add(location.pathname);
|
---|
1338 | } else {
|
---|
1339 | toPaths = /* @__PURE__ */ new Set([location.pathname]);
|
---|
1340 | appliedViewTransitions.set(state.location.pathname, toPaths);
|
---|
1341 | }
|
---|
1342 | viewTransitionOpts = {
|
---|
1343 | currentLocation: state.location,
|
---|
1344 | nextLocation: location
|
---|
1345 | };
|
---|
1346 | }
|
---|
1347 | updateState(_extends({}, newState, {
|
---|
1348 | actionData,
|
---|
1349 | loaderData,
|
---|
1350 | historyAction: pendingAction,
|
---|
1351 | location,
|
---|
1352 | initialized: true,
|
---|
1353 | navigation: IDLE_NAVIGATION,
|
---|
1354 | revalidation: "idle",
|
---|
1355 | restoreScrollPosition: getSavedScrollPosition(location, newState.matches || state.matches),
|
---|
1356 | preventScrollReset,
|
---|
1357 | blockers
|
---|
1358 | }), {
|
---|
1359 | viewTransitionOpts,
|
---|
1360 | flushSync: flushSync === true
|
---|
1361 | });
|
---|
1362 | pendingAction = Action.Pop;
|
---|
1363 | pendingPreventScrollReset = false;
|
---|
1364 | pendingViewTransitionEnabled = false;
|
---|
1365 | isUninterruptedRevalidation = false;
|
---|
1366 | isRevalidationRequired = false;
|
---|
1367 | cancelledDeferredRoutes = [];
|
---|
1368 | }
|
---|
1369 | async function navigate(to, opts) {
|
---|
1370 | if (typeof to === "number") {
|
---|
1371 | init.history.go(to);
|
---|
1372 | return;
|
---|
1373 | }
|
---|
1374 | let normalizedPath = normalizeTo(state.location, state.matches, basename, future.v7_prependBasename, to, future.v7_relativeSplatPath, opts == null ? void 0 : opts.fromRouteId, opts == null ? void 0 : opts.relative);
|
---|
1375 | let {
|
---|
1376 | path,
|
---|
1377 | submission,
|
---|
1378 | error
|
---|
1379 | } = normalizeNavigateOptions(future.v7_normalizeFormMethod, false, normalizedPath, opts);
|
---|
1380 | let currentLocation = state.location;
|
---|
1381 | let nextLocation = createLocation(state.location, path, opts && opts.state);
|
---|
1382 | nextLocation = _extends({}, nextLocation, init.history.encodeLocation(nextLocation));
|
---|
1383 | let userReplace = opts && opts.replace != null ? opts.replace : void 0;
|
---|
1384 | let historyAction = Action.Push;
|
---|
1385 | if (userReplace === true) {
|
---|
1386 | historyAction = Action.Replace;
|
---|
1387 | } else if (userReplace === false) ;
|
---|
1388 | else if (submission != null && isMutationMethod(submission.formMethod) && submission.formAction === state.location.pathname + state.location.search) {
|
---|
1389 | historyAction = Action.Replace;
|
---|
1390 | }
|
---|
1391 | let preventScrollReset = opts && "preventScrollReset" in opts ? opts.preventScrollReset === true : void 0;
|
---|
1392 | let flushSync = (opts && opts.flushSync) === true;
|
---|
1393 | let blockerKey = shouldBlockNavigation({
|
---|
1394 | currentLocation,
|
---|
1395 | nextLocation,
|
---|
1396 | historyAction
|
---|
1397 | });
|
---|
1398 | if (blockerKey) {
|
---|
1399 | updateBlocker(blockerKey, {
|
---|
1400 | state: "blocked",
|
---|
1401 | location: nextLocation,
|
---|
1402 | proceed() {
|
---|
1403 | updateBlocker(blockerKey, {
|
---|
1404 | state: "proceeding",
|
---|
1405 | proceed: void 0,
|
---|
1406 | reset: void 0,
|
---|
1407 | location: nextLocation
|
---|
1408 | });
|
---|
1409 | navigate(to, opts);
|
---|
1410 | },
|
---|
1411 | reset() {
|
---|
1412 | let blockers = new Map(state.blockers);
|
---|
1413 | blockers.set(blockerKey, IDLE_BLOCKER);
|
---|
1414 | updateState({
|
---|
1415 | blockers
|
---|
1416 | });
|
---|
1417 | }
|
---|
1418 | });
|
---|
1419 | return;
|
---|
1420 | }
|
---|
1421 | return await startNavigation(historyAction, nextLocation, {
|
---|
1422 | submission,
|
---|
1423 | // Send through the formData serialization error if we have one so we can
|
---|
1424 | // render at the right error boundary after we match routes
|
---|
1425 | pendingError: error,
|
---|
1426 | preventScrollReset,
|
---|
1427 | replace: opts && opts.replace,
|
---|
1428 | enableViewTransition: opts && opts.viewTransition,
|
---|
1429 | flushSync
|
---|
1430 | });
|
---|
1431 | }
|
---|
1432 | function revalidate() {
|
---|
1433 | interruptActiveLoads();
|
---|
1434 | updateState({
|
---|
1435 | revalidation: "loading"
|
---|
1436 | });
|
---|
1437 | if (state.navigation.state === "submitting") {
|
---|
1438 | return;
|
---|
1439 | }
|
---|
1440 | if (state.navigation.state === "idle") {
|
---|
1441 | startNavigation(state.historyAction, state.location, {
|
---|
1442 | startUninterruptedRevalidation: true
|
---|
1443 | });
|
---|
1444 | return;
|
---|
1445 | }
|
---|
1446 | startNavigation(pendingAction || state.historyAction, state.navigation.location, {
|
---|
1447 | overrideNavigation: state.navigation,
|
---|
1448 | // Proxy through any rending view transition
|
---|
1449 | enableViewTransition: pendingViewTransitionEnabled === true
|
---|
1450 | });
|
---|
1451 | }
|
---|
1452 | async function startNavigation(historyAction, location, opts) {
|
---|
1453 | pendingNavigationController && pendingNavigationController.abort();
|
---|
1454 | pendingNavigationController = null;
|
---|
1455 | pendingAction = historyAction;
|
---|
1456 | isUninterruptedRevalidation = (opts && opts.startUninterruptedRevalidation) === true;
|
---|
1457 | saveScrollPosition(state.location, state.matches);
|
---|
1458 | pendingPreventScrollReset = (opts && opts.preventScrollReset) === true;
|
---|
1459 | pendingViewTransitionEnabled = (opts && opts.enableViewTransition) === true;
|
---|
1460 | let routesToUse = inFlightDataRoutes || dataRoutes;
|
---|
1461 | let loadingNavigation = opts && opts.overrideNavigation;
|
---|
1462 | let matches = matchRoutes(routesToUse, location, basename);
|
---|
1463 | let flushSync = (opts && opts.flushSync) === true;
|
---|
1464 | let fogOfWar = checkFogOfWar(matches, routesToUse, location.pathname);
|
---|
1465 | if (fogOfWar.active && fogOfWar.matches) {
|
---|
1466 | matches = fogOfWar.matches;
|
---|
1467 | }
|
---|
1468 | if (!matches) {
|
---|
1469 | let {
|
---|
1470 | error,
|
---|
1471 | notFoundMatches,
|
---|
1472 | route
|
---|
1473 | } = handleNavigational404(location.pathname);
|
---|
1474 | completeNavigation(location, {
|
---|
1475 | matches: notFoundMatches,
|
---|
1476 | loaderData: {},
|
---|
1477 | errors: {
|
---|
1478 | [route.id]: error
|
---|
1479 | }
|
---|
1480 | }, {
|
---|
1481 | flushSync
|
---|
1482 | });
|
---|
1483 | return;
|
---|
1484 | }
|
---|
1485 | if (state.initialized && !isRevalidationRequired && isHashChangeOnly(state.location, location) && !(opts && opts.submission && isMutationMethod(opts.submission.formMethod))) {
|
---|
1486 | completeNavigation(location, {
|
---|
1487 | matches
|
---|
1488 | }, {
|
---|
1489 | flushSync
|
---|
1490 | });
|
---|
1491 | return;
|
---|
1492 | }
|
---|
1493 | pendingNavigationController = new AbortController();
|
---|
1494 | let request = createClientSideRequest(init.history, location, pendingNavigationController.signal, opts && opts.submission);
|
---|
1495 | let pendingActionResult;
|
---|
1496 | if (opts && opts.pendingError) {
|
---|
1497 | pendingActionResult = [findNearestBoundary(matches).route.id, {
|
---|
1498 | type: ResultType.error,
|
---|
1499 | error: opts.pendingError
|
---|
1500 | }];
|
---|
1501 | } else if (opts && opts.submission && isMutationMethod(opts.submission.formMethod)) {
|
---|
1502 | let actionResult = await handleAction(request, location, opts.submission, matches, fogOfWar.active, {
|
---|
1503 | replace: opts.replace,
|
---|
1504 | flushSync
|
---|
1505 | });
|
---|
1506 | if (actionResult.shortCircuited) {
|
---|
1507 | return;
|
---|
1508 | }
|
---|
1509 | if (actionResult.pendingActionResult) {
|
---|
1510 | let [routeId, result] = actionResult.pendingActionResult;
|
---|
1511 | if (isErrorResult(result) && isRouteErrorResponse(result.error) && result.error.status === 404) {
|
---|
1512 | pendingNavigationController = null;
|
---|
1513 | completeNavigation(location, {
|
---|
1514 | matches: actionResult.matches,
|
---|
1515 | loaderData: {},
|
---|
1516 | errors: {
|
---|
1517 | [routeId]: result.error
|
---|
1518 | }
|
---|
1519 | });
|
---|
1520 | return;
|
---|
1521 | }
|
---|
1522 | }
|
---|
1523 | matches = actionResult.matches || matches;
|
---|
1524 | pendingActionResult = actionResult.pendingActionResult;
|
---|
1525 | loadingNavigation = getLoadingNavigation(location, opts.submission);
|
---|
1526 | flushSync = false;
|
---|
1527 | fogOfWar.active = false;
|
---|
1528 | request = createClientSideRequest(init.history, request.url, request.signal);
|
---|
1529 | }
|
---|
1530 | let {
|
---|
1531 | shortCircuited,
|
---|
1532 | matches: updatedMatches,
|
---|
1533 | loaderData,
|
---|
1534 | errors
|
---|
1535 | } = await handleLoaders(request, location, matches, fogOfWar.active, loadingNavigation, opts && opts.submission, opts && opts.fetcherSubmission, opts && opts.replace, opts && opts.initialHydration === true, flushSync, pendingActionResult);
|
---|
1536 | if (shortCircuited) {
|
---|
1537 | return;
|
---|
1538 | }
|
---|
1539 | pendingNavigationController = null;
|
---|
1540 | completeNavigation(location, _extends({
|
---|
1541 | matches: updatedMatches || matches
|
---|
1542 | }, getActionDataForCommit(pendingActionResult), {
|
---|
1543 | loaderData,
|
---|
1544 | errors
|
---|
1545 | }));
|
---|
1546 | }
|
---|
1547 | async function handleAction(request, location, submission, matches, isFogOfWar, opts) {
|
---|
1548 | if (opts === void 0) {
|
---|
1549 | opts = {};
|
---|
1550 | }
|
---|
1551 | interruptActiveLoads();
|
---|
1552 | let navigation = getSubmittingNavigation(location, submission);
|
---|
1553 | updateState({
|
---|
1554 | navigation
|
---|
1555 | }, {
|
---|
1556 | flushSync: opts.flushSync === true
|
---|
1557 | });
|
---|
1558 | if (isFogOfWar) {
|
---|
1559 | let discoverResult = await discoverRoutes(matches, location.pathname, request.signal);
|
---|
1560 | if (discoverResult.type === "aborted") {
|
---|
1561 | return {
|
---|
1562 | shortCircuited: true
|
---|
1563 | };
|
---|
1564 | } else if (discoverResult.type === "error") {
|
---|
1565 | let boundaryId = findNearestBoundary(discoverResult.partialMatches).route.id;
|
---|
1566 | return {
|
---|
1567 | matches: discoverResult.partialMatches,
|
---|
1568 | pendingActionResult: [boundaryId, {
|
---|
1569 | type: ResultType.error,
|
---|
1570 | error: discoverResult.error
|
---|
1571 | }]
|
---|
1572 | };
|
---|
1573 | } else if (!discoverResult.matches) {
|
---|
1574 | let {
|
---|
1575 | notFoundMatches,
|
---|
1576 | error,
|
---|
1577 | route
|
---|
1578 | } = handleNavigational404(location.pathname);
|
---|
1579 | return {
|
---|
1580 | matches: notFoundMatches,
|
---|
1581 | pendingActionResult: [route.id, {
|
---|
1582 | type: ResultType.error,
|
---|
1583 | error
|
---|
1584 | }]
|
---|
1585 | };
|
---|
1586 | } else {
|
---|
1587 | matches = discoverResult.matches;
|
---|
1588 | }
|
---|
1589 | }
|
---|
1590 | let result;
|
---|
1591 | let actionMatch = getTargetMatch(matches, location);
|
---|
1592 | if (!actionMatch.route.action && !actionMatch.route.lazy) {
|
---|
1593 | result = {
|
---|
1594 | type: ResultType.error,
|
---|
1595 | error: getInternalRouterError(405, {
|
---|
1596 | method: request.method,
|
---|
1597 | pathname: location.pathname,
|
---|
1598 | routeId: actionMatch.route.id
|
---|
1599 | })
|
---|
1600 | };
|
---|
1601 | } else {
|
---|
1602 | let results = await callDataStrategy("action", state, request, [actionMatch], matches, null);
|
---|
1603 | result = results[actionMatch.route.id];
|
---|
1604 | if (request.signal.aborted) {
|
---|
1605 | return {
|
---|
1606 | shortCircuited: true
|
---|
1607 | };
|
---|
1608 | }
|
---|
1609 | }
|
---|
1610 | if (isRedirectResult(result)) {
|
---|
1611 | let replace2;
|
---|
1612 | if (opts && opts.replace != null) {
|
---|
1613 | replace2 = opts.replace;
|
---|
1614 | } else {
|
---|
1615 | let location2 = normalizeRedirectLocation(result.response.headers.get("Location"), new URL(request.url), basename);
|
---|
1616 | replace2 = location2 === state.location.pathname + state.location.search;
|
---|
1617 | }
|
---|
1618 | await startRedirectNavigation(request, result, true, {
|
---|
1619 | submission,
|
---|
1620 | replace: replace2
|
---|
1621 | });
|
---|
1622 | return {
|
---|
1623 | shortCircuited: true
|
---|
1624 | };
|
---|
1625 | }
|
---|
1626 | if (isDeferredResult(result)) {
|
---|
1627 | throw getInternalRouterError(400, {
|
---|
1628 | type: "defer-action"
|
---|
1629 | });
|
---|
1630 | }
|
---|
1631 | if (isErrorResult(result)) {
|
---|
1632 | let boundaryMatch = findNearestBoundary(matches, actionMatch.route.id);
|
---|
1633 | if ((opts && opts.replace) !== true) {
|
---|
1634 | pendingAction = Action.Push;
|
---|
1635 | }
|
---|
1636 | return {
|
---|
1637 | matches,
|
---|
1638 | pendingActionResult: [boundaryMatch.route.id, result]
|
---|
1639 | };
|
---|
1640 | }
|
---|
1641 | return {
|
---|
1642 | matches,
|
---|
1643 | pendingActionResult: [actionMatch.route.id, result]
|
---|
1644 | };
|
---|
1645 | }
|
---|
1646 | async function handleLoaders(request, location, matches, isFogOfWar, overrideNavigation, submission, fetcherSubmission, replace2, initialHydration, flushSync, pendingActionResult) {
|
---|
1647 | let loadingNavigation = overrideNavigation || getLoadingNavigation(location, submission);
|
---|
1648 | let activeSubmission = submission || fetcherSubmission || getSubmissionFromNavigation(loadingNavigation);
|
---|
1649 | let shouldUpdateNavigationState = !isUninterruptedRevalidation && (!future.v7_partialHydration || !initialHydration);
|
---|
1650 | if (isFogOfWar) {
|
---|
1651 | if (shouldUpdateNavigationState) {
|
---|
1652 | let actionData = getUpdatedActionData(pendingActionResult);
|
---|
1653 | updateState(_extends({
|
---|
1654 | navigation: loadingNavigation
|
---|
1655 | }, actionData !== void 0 ? {
|
---|
1656 | actionData
|
---|
1657 | } : {}), {
|
---|
1658 | flushSync
|
---|
1659 | });
|
---|
1660 | }
|
---|
1661 | let discoverResult = await discoverRoutes(matches, location.pathname, request.signal);
|
---|
1662 | if (discoverResult.type === "aborted") {
|
---|
1663 | return {
|
---|
1664 | shortCircuited: true
|
---|
1665 | };
|
---|
1666 | } else if (discoverResult.type === "error") {
|
---|
1667 | let boundaryId = findNearestBoundary(discoverResult.partialMatches).route.id;
|
---|
1668 | return {
|
---|
1669 | matches: discoverResult.partialMatches,
|
---|
1670 | loaderData: {},
|
---|
1671 | errors: {
|
---|
1672 | [boundaryId]: discoverResult.error
|
---|
1673 | }
|
---|
1674 | };
|
---|
1675 | } else if (!discoverResult.matches) {
|
---|
1676 | let {
|
---|
1677 | error,
|
---|
1678 | notFoundMatches,
|
---|
1679 | route
|
---|
1680 | } = handleNavigational404(location.pathname);
|
---|
1681 | return {
|
---|
1682 | matches: notFoundMatches,
|
---|
1683 | loaderData: {},
|
---|
1684 | errors: {
|
---|
1685 | [route.id]: error
|
---|
1686 | }
|
---|
1687 | };
|
---|
1688 | } else {
|
---|
1689 | matches = discoverResult.matches;
|
---|
1690 | }
|
---|
1691 | }
|
---|
1692 | let routesToUse = inFlightDataRoutes || dataRoutes;
|
---|
1693 | let [matchesToLoad, revalidatingFetchers] = getMatchesToLoad(init.history, state, matches, activeSubmission, location, future.v7_partialHydration && initialHydration === true, future.v7_skipActionErrorRevalidation, isRevalidationRequired, cancelledDeferredRoutes, cancelledFetcherLoads, deletedFetchers, fetchLoadMatches, fetchRedirectIds, routesToUse, basename, pendingActionResult);
|
---|
1694 | cancelActiveDeferreds((routeId) => !(matches && matches.some((m) => m.route.id === routeId)) || matchesToLoad && matchesToLoad.some((m) => m.route.id === routeId));
|
---|
1695 | pendingNavigationLoadId = ++incrementingLoadId;
|
---|
1696 | if (matchesToLoad.length === 0 && revalidatingFetchers.length === 0) {
|
---|
1697 | let updatedFetchers2 = markFetchRedirectsDone();
|
---|
1698 | completeNavigation(location, _extends({
|
---|
1699 | matches,
|
---|
1700 | loaderData: {},
|
---|
1701 | // Commit pending error if we're short circuiting
|
---|
1702 | errors: pendingActionResult && isErrorResult(pendingActionResult[1]) ? {
|
---|
1703 | [pendingActionResult[0]]: pendingActionResult[1].error
|
---|
1704 | } : null
|
---|
1705 | }, getActionDataForCommit(pendingActionResult), updatedFetchers2 ? {
|
---|
1706 | fetchers: new Map(state.fetchers)
|
---|
1707 | } : {}), {
|
---|
1708 | flushSync
|
---|
1709 | });
|
---|
1710 | return {
|
---|
1711 | shortCircuited: true
|
---|
1712 | };
|
---|
1713 | }
|
---|
1714 | if (shouldUpdateNavigationState) {
|
---|
1715 | let updates = {};
|
---|
1716 | if (!isFogOfWar) {
|
---|
1717 | updates.navigation = loadingNavigation;
|
---|
1718 | let actionData = getUpdatedActionData(pendingActionResult);
|
---|
1719 | if (actionData !== void 0) {
|
---|
1720 | updates.actionData = actionData;
|
---|
1721 | }
|
---|
1722 | }
|
---|
1723 | if (revalidatingFetchers.length > 0) {
|
---|
1724 | updates.fetchers = getUpdatedRevalidatingFetchers(revalidatingFetchers);
|
---|
1725 | }
|
---|
1726 | updateState(updates, {
|
---|
1727 | flushSync
|
---|
1728 | });
|
---|
1729 | }
|
---|
1730 | revalidatingFetchers.forEach((rf) => {
|
---|
1731 | abortFetcher(rf.key);
|
---|
1732 | if (rf.controller) {
|
---|
1733 | fetchControllers.set(rf.key, rf.controller);
|
---|
1734 | }
|
---|
1735 | });
|
---|
1736 | let abortPendingFetchRevalidations = () => revalidatingFetchers.forEach((f) => abortFetcher(f.key));
|
---|
1737 | if (pendingNavigationController) {
|
---|
1738 | pendingNavigationController.signal.addEventListener("abort", abortPendingFetchRevalidations);
|
---|
1739 | }
|
---|
1740 | let {
|
---|
1741 | loaderResults,
|
---|
1742 | fetcherResults
|
---|
1743 | } = await callLoadersAndMaybeResolveData(state, matches, matchesToLoad, revalidatingFetchers, request);
|
---|
1744 | if (request.signal.aborted) {
|
---|
1745 | return {
|
---|
1746 | shortCircuited: true
|
---|
1747 | };
|
---|
1748 | }
|
---|
1749 | if (pendingNavigationController) {
|
---|
1750 | pendingNavigationController.signal.removeEventListener("abort", abortPendingFetchRevalidations);
|
---|
1751 | }
|
---|
1752 | revalidatingFetchers.forEach((rf) => fetchControllers.delete(rf.key));
|
---|
1753 | let redirect3 = findRedirect(loaderResults);
|
---|
1754 | if (redirect3) {
|
---|
1755 | await startRedirectNavigation(request, redirect3.result, true, {
|
---|
1756 | replace: replace2
|
---|
1757 | });
|
---|
1758 | return {
|
---|
1759 | shortCircuited: true
|
---|
1760 | };
|
---|
1761 | }
|
---|
1762 | redirect3 = findRedirect(fetcherResults);
|
---|
1763 | if (redirect3) {
|
---|
1764 | fetchRedirectIds.add(redirect3.key);
|
---|
1765 | await startRedirectNavigation(request, redirect3.result, true, {
|
---|
1766 | replace: replace2
|
---|
1767 | });
|
---|
1768 | return {
|
---|
1769 | shortCircuited: true
|
---|
1770 | };
|
---|
1771 | }
|
---|
1772 | let {
|
---|
1773 | loaderData,
|
---|
1774 | errors
|
---|
1775 | } = processLoaderData(state, matches, loaderResults, pendingActionResult, revalidatingFetchers, fetcherResults, activeDeferreds);
|
---|
1776 | activeDeferreds.forEach((deferredData, routeId) => {
|
---|
1777 | deferredData.subscribe((aborted) => {
|
---|
1778 | if (aborted || deferredData.done) {
|
---|
1779 | activeDeferreds.delete(routeId);
|
---|
1780 | }
|
---|
1781 | });
|
---|
1782 | });
|
---|
1783 | if (future.v7_partialHydration && initialHydration && state.errors) {
|
---|
1784 | errors = _extends({}, state.errors, errors);
|
---|
1785 | }
|
---|
1786 | let updatedFetchers = markFetchRedirectsDone();
|
---|
1787 | let didAbortFetchLoads = abortStaleFetchLoads(pendingNavigationLoadId);
|
---|
1788 | let shouldUpdateFetchers = updatedFetchers || didAbortFetchLoads || revalidatingFetchers.length > 0;
|
---|
1789 | return _extends({
|
---|
1790 | matches,
|
---|
1791 | loaderData,
|
---|
1792 | errors
|
---|
1793 | }, shouldUpdateFetchers ? {
|
---|
1794 | fetchers: new Map(state.fetchers)
|
---|
1795 | } : {});
|
---|
1796 | }
|
---|
1797 | function getUpdatedActionData(pendingActionResult) {
|
---|
1798 | if (pendingActionResult && !isErrorResult(pendingActionResult[1])) {
|
---|
1799 | return {
|
---|
1800 | [pendingActionResult[0]]: pendingActionResult[1].data
|
---|
1801 | };
|
---|
1802 | } else if (state.actionData) {
|
---|
1803 | if (Object.keys(state.actionData).length === 0) {
|
---|
1804 | return null;
|
---|
1805 | } else {
|
---|
1806 | return state.actionData;
|
---|
1807 | }
|
---|
1808 | }
|
---|
1809 | }
|
---|
1810 | function getUpdatedRevalidatingFetchers(revalidatingFetchers) {
|
---|
1811 | revalidatingFetchers.forEach((rf) => {
|
---|
1812 | let fetcher = state.fetchers.get(rf.key);
|
---|
1813 | let revalidatingFetcher = getLoadingFetcher(void 0, fetcher ? fetcher.data : void 0);
|
---|
1814 | state.fetchers.set(rf.key, revalidatingFetcher);
|
---|
1815 | });
|
---|
1816 | return new Map(state.fetchers);
|
---|
1817 | }
|
---|
1818 | function fetch(key, routeId, href, opts) {
|
---|
1819 | if (isServer) {
|
---|
1820 | throw new Error("router.fetch() was called during the server render, but it shouldn't be. You are likely calling a useFetcher() method in the body of your component. Try moving it to a useEffect or a callback.");
|
---|
1821 | }
|
---|
1822 | abortFetcher(key);
|
---|
1823 | let flushSync = (opts && opts.flushSync) === true;
|
---|
1824 | let routesToUse = inFlightDataRoutes || dataRoutes;
|
---|
1825 | let normalizedPath = normalizeTo(state.location, state.matches, basename, future.v7_prependBasename, href, future.v7_relativeSplatPath, routeId, opts == null ? void 0 : opts.relative);
|
---|
1826 | let matches = matchRoutes(routesToUse, normalizedPath, basename);
|
---|
1827 | let fogOfWar = checkFogOfWar(matches, routesToUse, normalizedPath);
|
---|
1828 | if (fogOfWar.active && fogOfWar.matches) {
|
---|
1829 | matches = fogOfWar.matches;
|
---|
1830 | }
|
---|
1831 | if (!matches) {
|
---|
1832 | setFetcherError(key, routeId, getInternalRouterError(404, {
|
---|
1833 | pathname: normalizedPath
|
---|
1834 | }), {
|
---|
1835 | flushSync
|
---|
1836 | });
|
---|
1837 | return;
|
---|
1838 | }
|
---|
1839 | let {
|
---|
1840 | path,
|
---|
1841 | submission,
|
---|
1842 | error
|
---|
1843 | } = normalizeNavigateOptions(future.v7_normalizeFormMethod, true, normalizedPath, opts);
|
---|
1844 | if (error) {
|
---|
1845 | setFetcherError(key, routeId, error, {
|
---|
1846 | flushSync
|
---|
1847 | });
|
---|
1848 | return;
|
---|
1849 | }
|
---|
1850 | let match = getTargetMatch(matches, path);
|
---|
1851 | let preventScrollReset = (opts && opts.preventScrollReset) === true;
|
---|
1852 | if (submission && isMutationMethod(submission.formMethod)) {
|
---|
1853 | handleFetcherAction(key, routeId, path, match, matches, fogOfWar.active, flushSync, preventScrollReset, submission);
|
---|
1854 | return;
|
---|
1855 | }
|
---|
1856 | fetchLoadMatches.set(key, {
|
---|
1857 | routeId,
|
---|
1858 | path
|
---|
1859 | });
|
---|
1860 | handleFetcherLoader(key, routeId, path, match, matches, fogOfWar.active, flushSync, preventScrollReset, submission);
|
---|
1861 | }
|
---|
1862 | async function handleFetcherAction(key, routeId, path, match, requestMatches, isFogOfWar, flushSync, preventScrollReset, submission) {
|
---|
1863 | interruptActiveLoads();
|
---|
1864 | fetchLoadMatches.delete(key);
|
---|
1865 | function detectAndHandle405Error(m) {
|
---|
1866 | if (!m.route.action && !m.route.lazy) {
|
---|
1867 | let error = getInternalRouterError(405, {
|
---|
1868 | method: submission.formMethod,
|
---|
1869 | pathname: path,
|
---|
1870 | routeId
|
---|
1871 | });
|
---|
1872 | setFetcherError(key, routeId, error, {
|
---|
1873 | flushSync
|
---|
1874 | });
|
---|
1875 | return true;
|
---|
1876 | }
|
---|
1877 | return false;
|
---|
1878 | }
|
---|
1879 | if (!isFogOfWar && detectAndHandle405Error(match)) {
|
---|
1880 | return;
|
---|
1881 | }
|
---|
1882 | let existingFetcher = state.fetchers.get(key);
|
---|
1883 | updateFetcherState(key, getSubmittingFetcher(submission, existingFetcher), {
|
---|
1884 | flushSync
|
---|
1885 | });
|
---|
1886 | let abortController = new AbortController();
|
---|
1887 | let fetchRequest = createClientSideRequest(init.history, path, abortController.signal, submission);
|
---|
1888 | if (isFogOfWar) {
|
---|
1889 | let discoverResult = await discoverRoutes(requestMatches, path, fetchRequest.signal);
|
---|
1890 | if (discoverResult.type === "aborted") {
|
---|
1891 | return;
|
---|
1892 | } else if (discoverResult.type === "error") {
|
---|
1893 | setFetcherError(key, routeId, discoverResult.error, {
|
---|
1894 | flushSync
|
---|
1895 | });
|
---|
1896 | return;
|
---|
1897 | } else if (!discoverResult.matches) {
|
---|
1898 | setFetcherError(key, routeId, getInternalRouterError(404, {
|
---|
1899 | pathname: path
|
---|
1900 | }), {
|
---|
1901 | flushSync
|
---|
1902 | });
|
---|
1903 | return;
|
---|
1904 | } else {
|
---|
1905 | requestMatches = discoverResult.matches;
|
---|
1906 | match = getTargetMatch(requestMatches, path);
|
---|
1907 | if (detectAndHandle405Error(match)) {
|
---|
1908 | return;
|
---|
1909 | }
|
---|
1910 | }
|
---|
1911 | }
|
---|
1912 | fetchControllers.set(key, abortController);
|
---|
1913 | let originatingLoadId = incrementingLoadId;
|
---|
1914 | let actionResults = await callDataStrategy("action", state, fetchRequest, [match], requestMatches, key);
|
---|
1915 | let actionResult = actionResults[match.route.id];
|
---|
1916 | if (fetchRequest.signal.aborted) {
|
---|
1917 | if (fetchControllers.get(key) === abortController) {
|
---|
1918 | fetchControllers.delete(key);
|
---|
1919 | }
|
---|
1920 | return;
|
---|
1921 | }
|
---|
1922 | if (future.v7_fetcherPersist && deletedFetchers.has(key)) {
|
---|
1923 | if (isRedirectResult(actionResult) || isErrorResult(actionResult)) {
|
---|
1924 | updateFetcherState(key, getDoneFetcher(void 0));
|
---|
1925 | return;
|
---|
1926 | }
|
---|
1927 | } else {
|
---|
1928 | if (isRedirectResult(actionResult)) {
|
---|
1929 | fetchControllers.delete(key);
|
---|
1930 | if (pendingNavigationLoadId > originatingLoadId) {
|
---|
1931 | updateFetcherState(key, getDoneFetcher(void 0));
|
---|
1932 | return;
|
---|
1933 | } else {
|
---|
1934 | fetchRedirectIds.add(key);
|
---|
1935 | updateFetcherState(key, getLoadingFetcher(submission));
|
---|
1936 | return startRedirectNavigation(fetchRequest, actionResult, false, {
|
---|
1937 | fetcherSubmission: submission,
|
---|
1938 | preventScrollReset
|
---|
1939 | });
|
---|
1940 | }
|
---|
1941 | }
|
---|
1942 | if (isErrorResult(actionResult)) {
|
---|
1943 | setFetcherError(key, routeId, actionResult.error);
|
---|
1944 | return;
|
---|
1945 | }
|
---|
1946 | }
|
---|
1947 | if (isDeferredResult(actionResult)) {
|
---|
1948 | throw getInternalRouterError(400, {
|
---|
1949 | type: "defer-action"
|
---|
1950 | });
|
---|
1951 | }
|
---|
1952 | let nextLocation = state.navigation.location || state.location;
|
---|
1953 | let revalidationRequest = createClientSideRequest(init.history, nextLocation, abortController.signal);
|
---|
1954 | let routesToUse = inFlightDataRoutes || dataRoutes;
|
---|
1955 | let matches = state.navigation.state !== "idle" ? matchRoutes(routesToUse, state.navigation.location, basename) : state.matches;
|
---|
1956 | invariant(matches, "Didn't find any matches after fetcher action");
|
---|
1957 | let loadId = ++incrementingLoadId;
|
---|
1958 | fetchReloadIds.set(key, loadId);
|
---|
1959 | let loadFetcher = getLoadingFetcher(submission, actionResult.data);
|
---|
1960 | state.fetchers.set(key, loadFetcher);
|
---|
1961 | let [matchesToLoad, revalidatingFetchers] = getMatchesToLoad(init.history, state, matches, submission, nextLocation, false, future.v7_skipActionErrorRevalidation, isRevalidationRequired, cancelledDeferredRoutes, cancelledFetcherLoads, deletedFetchers, fetchLoadMatches, fetchRedirectIds, routesToUse, basename, [match.route.id, actionResult]);
|
---|
1962 | revalidatingFetchers.filter((rf) => rf.key !== key).forEach((rf) => {
|
---|
1963 | let staleKey = rf.key;
|
---|
1964 | let existingFetcher2 = state.fetchers.get(staleKey);
|
---|
1965 | let revalidatingFetcher = getLoadingFetcher(void 0, existingFetcher2 ? existingFetcher2.data : void 0);
|
---|
1966 | state.fetchers.set(staleKey, revalidatingFetcher);
|
---|
1967 | abortFetcher(staleKey);
|
---|
1968 | if (rf.controller) {
|
---|
1969 | fetchControllers.set(staleKey, rf.controller);
|
---|
1970 | }
|
---|
1971 | });
|
---|
1972 | updateState({
|
---|
1973 | fetchers: new Map(state.fetchers)
|
---|
1974 | });
|
---|
1975 | let abortPendingFetchRevalidations = () => revalidatingFetchers.forEach((rf) => abortFetcher(rf.key));
|
---|
1976 | abortController.signal.addEventListener("abort", abortPendingFetchRevalidations);
|
---|
1977 | let {
|
---|
1978 | loaderResults,
|
---|
1979 | fetcherResults
|
---|
1980 | } = await callLoadersAndMaybeResolveData(state, matches, matchesToLoad, revalidatingFetchers, revalidationRequest);
|
---|
1981 | if (abortController.signal.aborted) {
|
---|
1982 | return;
|
---|
1983 | }
|
---|
1984 | abortController.signal.removeEventListener("abort", abortPendingFetchRevalidations);
|
---|
1985 | fetchReloadIds.delete(key);
|
---|
1986 | fetchControllers.delete(key);
|
---|
1987 | revalidatingFetchers.forEach((r) => fetchControllers.delete(r.key));
|
---|
1988 | let redirect3 = findRedirect(loaderResults);
|
---|
1989 | if (redirect3) {
|
---|
1990 | return startRedirectNavigation(revalidationRequest, redirect3.result, false, {
|
---|
1991 | preventScrollReset
|
---|
1992 | });
|
---|
1993 | }
|
---|
1994 | redirect3 = findRedirect(fetcherResults);
|
---|
1995 | if (redirect3) {
|
---|
1996 | fetchRedirectIds.add(redirect3.key);
|
---|
1997 | return startRedirectNavigation(revalidationRequest, redirect3.result, false, {
|
---|
1998 | preventScrollReset
|
---|
1999 | });
|
---|
2000 | }
|
---|
2001 | let {
|
---|
2002 | loaderData,
|
---|
2003 | errors
|
---|
2004 | } = processLoaderData(state, matches, loaderResults, void 0, revalidatingFetchers, fetcherResults, activeDeferreds);
|
---|
2005 | if (state.fetchers.has(key)) {
|
---|
2006 | let doneFetcher = getDoneFetcher(actionResult.data);
|
---|
2007 | state.fetchers.set(key, doneFetcher);
|
---|
2008 | }
|
---|
2009 | abortStaleFetchLoads(loadId);
|
---|
2010 | if (state.navigation.state === "loading" && loadId > pendingNavigationLoadId) {
|
---|
2011 | invariant(pendingAction, "Expected pending action");
|
---|
2012 | pendingNavigationController && pendingNavigationController.abort();
|
---|
2013 | completeNavigation(state.navigation.location, {
|
---|
2014 | matches,
|
---|
2015 | loaderData,
|
---|
2016 | errors,
|
---|
2017 | fetchers: new Map(state.fetchers)
|
---|
2018 | });
|
---|
2019 | } else {
|
---|
2020 | updateState({
|
---|
2021 | errors,
|
---|
2022 | loaderData: mergeLoaderData(state.loaderData, loaderData, matches, errors),
|
---|
2023 | fetchers: new Map(state.fetchers)
|
---|
2024 | });
|
---|
2025 | isRevalidationRequired = false;
|
---|
2026 | }
|
---|
2027 | }
|
---|
2028 | async function handleFetcherLoader(key, routeId, path, match, matches, isFogOfWar, flushSync, preventScrollReset, submission) {
|
---|
2029 | let existingFetcher = state.fetchers.get(key);
|
---|
2030 | updateFetcherState(key, getLoadingFetcher(submission, existingFetcher ? existingFetcher.data : void 0), {
|
---|
2031 | flushSync
|
---|
2032 | });
|
---|
2033 | let abortController = new AbortController();
|
---|
2034 | let fetchRequest = createClientSideRequest(init.history, path, abortController.signal);
|
---|
2035 | if (isFogOfWar) {
|
---|
2036 | let discoverResult = await discoverRoutes(matches, path, fetchRequest.signal);
|
---|
2037 | if (discoverResult.type === "aborted") {
|
---|
2038 | return;
|
---|
2039 | } else if (discoverResult.type === "error") {
|
---|
2040 | setFetcherError(key, routeId, discoverResult.error, {
|
---|
2041 | flushSync
|
---|
2042 | });
|
---|
2043 | return;
|
---|
2044 | } else if (!discoverResult.matches) {
|
---|
2045 | setFetcherError(key, routeId, getInternalRouterError(404, {
|
---|
2046 | pathname: path
|
---|
2047 | }), {
|
---|
2048 | flushSync
|
---|
2049 | });
|
---|
2050 | return;
|
---|
2051 | } else {
|
---|
2052 | matches = discoverResult.matches;
|
---|
2053 | match = getTargetMatch(matches, path);
|
---|
2054 | }
|
---|
2055 | }
|
---|
2056 | fetchControllers.set(key, abortController);
|
---|
2057 | let originatingLoadId = incrementingLoadId;
|
---|
2058 | let results = await callDataStrategy("loader", state, fetchRequest, [match], matches, key);
|
---|
2059 | let result = results[match.route.id];
|
---|
2060 | if (isDeferredResult(result)) {
|
---|
2061 | result = await resolveDeferredData(result, fetchRequest.signal, true) || result;
|
---|
2062 | }
|
---|
2063 | if (fetchControllers.get(key) === abortController) {
|
---|
2064 | fetchControllers.delete(key);
|
---|
2065 | }
|
---|
2066 | if (fetchRequest.signal.aborted) {
|
---|
2067 | return;
|
---|
2068 | }
|
---|
2069 | if (deletedFetchers.has(key)) {
|
---|
2070 | updateFetcherState(key, getDoneFetcher(void 0));
|
---|
2071 | return;
|
---|
2072 | }
|
---|
2073 | if (isRedirectResult(result)) {
|
---|
2074 | if (pendingNavigationLoadId > originatingLoadId) {
|
---|
2075 | updateFetcherState(key, getDoneFetcher(void 0));
|
---|
2076 | return;
|
---|
2077 | } else {
|
---|
2078 | fetchRedirectIds.add(key);
|
---|
2079 | await startRedirectNavigation(fetchRequest, result, false, {
|
---|
2080 | preventScrollReset
|
---|
2081 | });
|
---|
2082 | return;
|
---|
2083 | }
|
---|
2084 | }
|
---|
2085 | if (isErrorResult(result)) {
|
---|
2086 | setFetcherError(key, routeId, result.error);
|
---|
2087 | return;
|
---|
2088 | }
|
---|
2089 | invariant(!isDeferredResult(result), "Unhandled fetcher deferred data");
|
---|
2090 | updateFetcherState(key, getDoneFetcher(result.data));
|
---|
2091 | }
|
---|
2092 | async function startRedirectNavigation(request, redirect3, isNavigation, _temp2) {
|
---|
2093 | let {
|
---|
2094 | submission,
|
---|
2095 | fetcherSubmission,
|
---|
2096 | preventScrollReset,
|
---|
2097 | replace: replace2
|
---|
2098 | } = _temp2 === void 0 ? {} : _temp2;
|
---|
2099 | if (redirect3.response.headers.has("X-Remix-Revalidate")) {
|
---|
2100 | isRevalidationRequired = true;
|
---|
2101 | }
|
---|
2102 | let location = redirect3.response.headers.get("Location");
|
---|
2103 | invariant(location, "Expected a Location header on the redirect Response");
|
---|
2104 | location = normalizeRedirectLocation(location, new URL(request.url), basename);
|
---|
2105 | let redirectLocation = createLocation(state.location, location, {
|
---|
2106 | _isRedirect: true
|
---|
2107 | });
|
---|
2108 | if (isBrowser2) {
|
---|
2109 | let isDocumentReload = false;
|
---|
2110 | if (redirect3.response.headers.has("X-Remix-Reload-Document")) {
|
---|
2111 | isDocumentReload = true;
|
---|
2112 | } else if (ABSOLUTE_URL_REGEX.test(location)) {
|
---|
2113 | const url = init.history.createURL(location);
|
---|
2114 | isDocumentReload = // Hard reload if it's an absolute URL to a new origin
|
---|
2115 | url.origin !== routerWindow.location.origin || // Hard reload if it's an absolute URL that does not match our basename
|
---|
2116 | stripBasename(url.pathname, basename) == null;
|
---|
2117 | }
|
---|
2118 | if (isDocumentReload) {
|
---|
2119 | if (replace2) {
|
---|
2120 | routerWindow.location.replace(location);
|
---|
2121 | } else {
|
---|
2122 | routerWindow.location.assign(location);
|
---|
2123 | }
|
---|
2124 | return;
|
---|
2125 | }
|
---|
2126 | }
|
---|
2127 | pendingNavigationController = null;
|
---|
2128 | let redirectHistoryAction = replace2 === true || redirect3.response.headers.has("X-Remix-Replace") ? Action.Replace : Action.Push;
|
---|
2129 | let {
|
---|
2130 | formMethod,
|
---|
2131 | formAction,
|
---|
2132 | formEncType
|
---|
2133 | } = state.navigation;
|
---|
2134 | if (!submission && !fetcherSubmission && formMethod && formAction && formEncType) {
|
---|
2135 | submission = getSubmissionFromNavigation(state.navigation);
|
---|
2136 | }
|
---|
2137 | let activeSubmission = submission || fetcherSubmission;
|
---|
2138 | if (redirectPreserveMethodStatusCodes.has(redirect3.response.status) && activeSubmission && isMutationMethod(activeSubmission.formMethod)) {
|
---|
2139 | await startNavigation(redirectHistoryAction, redirectLocation, {
|
---|
2140 | submission: _extends({}, activeSubmission, {
|
---|
2141 | formAction: location
|
---|
2142 | }),
|
---|
2143 | // Preserve these flags across redirects
|
---|
2144 | preventScrollReset: preventScrollReset || pendingPreventScrollReset,
|
---|
2145 | enableViewTransition: isNavigation ? pendingViewTransitionEnabled : void 0
|
---|
2146 | });
|
---|
2147 | } else {
|
---|
2148 | let overrideNavigation = getLoadingNavigation(redirectLocation, submission);
|
---|
2149 | await startNavigation(redirectHistoryAction, redirectLocation, {
|
---|
2150 | overrideNavigation,
|
---|
2151 | // Send fetcher submissions through for shouldRevalidate
|
---|
2152 | fetcherSubmission,
|
---|
2153 | // Preserve these flags across redirects
|
---|
2154 | preventScrollReset: preventScrollReset || pendingPreventScrollReset,
|
---|
2155 | enableViewTransition: isNavigation ? pendingViewTransitionEnabled : void 0
|
---|
2156 | });
|
---|
2157 | }
|
---|
2158 | }
|
---|
2159 | async function callDataStrategy(type, state2, request, matchesToLoad, matches, fetcherKey) {
|
---|
2160 | let results;
|
---|
2161 | let dataResults = {};
|
---|
2162 | try {
|
---|
2163 | results = await callDataStrategyImpl(dataStrategyImpl, type, state2, request, matchesToLoad, matches, fetcherKey, manifest, mapRouteProperties2);
|
---|
2164 | } catch (e) {
|
---|
2165 | matchesToLoad.forEach((m) => {
|
---|
2166 | dataResults[m.route.id] = {
|
---|
2167 | type: ResultType.error,
|
---|
2168 | error: e
|
---|
2169 | };
|
---|
2170 | });
|
---|
2171 | return dataResults;
|
---|
2172 | }
|
---|
2173 | for (let [routeId, result] of Object.entries(results)) {
|
---|
2174 | if (isRedirectDataStrategyResultResult(result)) {
|
---|
2175 | let response = result.result;
|
---|
2176 | dataResults[routeId] = {
|
---|
2177 | type: ResultType.redirect,
|
---|
2178 | response: normalizeRelativeRoutingRedirectResponse(response, request, routeId, matches, basename, future.v7_relativeSplatPath)
|
---|
2179 | };
|
---|
2180 | } else {
|
---|
2181 | dataResults[routeId] = await convertDataStrategyResultToDataResult(result);
|
---|
2182 | }
|
---|
2183 | }
|
---|
2184 | return dataResults;
|
---|
2185 | }
|
---|
2186 | async function callLoadersAndMaybeResolveData(state2, matches, matchesToLoad, fetchersToLoad, request) {
|
---|
2187 | let currentMatches = state2.matches;
|
---|
2188 | let loaderResultsPromise = callDataStrategy("loader", state2, request, matchesToLoad, matches, null);
|
---|
2189 | let fetcherResultsPromise = Promise.all(fetchersToLoad.map(async (f) => {
|
---|
2190 | if (f.matches && f.match && f.controller) {
|
---|
2191 | let results = await callDataStrategy("loader", state2, createClientSideRequest(init.history, f.path, f.controller.signal), [f.match], f.matches, f.key);
|
---|
2192 | let result = results[f.match.route.id];
|
---|
2193 | return {
|
---|
2194 | [f.key]: result
|
---|
2195 | };
|
---|
2196 | } else {
|
---|
2197 | return Promise.resolve({
|
---|
2198 | [f.key]: {
|
---|
2199 | type: ResultType.error,
|
---|
2200 | error: getInternalRouterError(404, {
|
---|
2201 | pathname: f.path
|
---|
2202 | })
|
---|
2203 | }
|
---|
2204 | });
|
---|
2205 | }
|
---|
2206 | }));
|
---|
2207 | let loaderResults = await loaderResultsPromise;
|
---|
2208 | let fetcherResults = (await fetcherResultsPromise).reduce((acc, r) => Object.assign(acc, r), {});
|
---|
2209 | await Promise.all([resolveNavigationDeferredResults(matches, loaderResults, request.signal, currentMatches, state2.loaderData), resolveFetcherDeferredResults(matches, fetcherResults, fetchersToLoad)]);
|
---|
2210 | return {
|
---|
2211 | loaderResults,
|
---|
2212 | fetcherResults
|
---|
2213 | };
|
---|
2214 | }
|
---|
2215 | function interruptActiveLoads() {
|
---|
2216 | isRevalidationRequired = true;
|
---|
2217 | cancelledDeferredRoutes.push(...cancelActiveDeferreds());
|
---|
2218 | fetchLoadMatches.forEach((_, key) => {
|
---|
2219 | if (fetchControllers.has(key)) {
|
---|
2220 | cancelledFetcherLoads.add(key);
|
---|
2221 | }
|
---|
2222 | abortFetcher(key);
|
---|
2223 | });
|
---|
2224 | }
|
---|
2225 | function updateFetcherState(key, fetcher, opts) {
|
---|
2226 | if (opts === void 0) {
|
---|
2227 | opts = {};
|
---|
2228 | }
|
---|
2229 | state.fetchers.set(key, fetcher);
|
---|
2230 | updateState({
|
---|
2231 | fetchers: new Map(state.fetchers)
|
---|
2232 | }, {
|
---|
2233 | flushSync: (opts && opts.flushSync) === true
|
---|
2234 | });
|
---|
2235 | }
|
---|
2236 | function setFetcherError(key, routeId, error, opts) {
|
---|
2237 | if (opts === void 0) {
|
---|
2238 | opts = {};
|
---|
2239 | }
|
---|
2240 | let boundaryMatch = findNearestBoundary(state.matches, routeId);
|
---|
2241 | deleteFetcher(key);
|
---|
2242 | updateState({
|
---|
2243 | errors: {
|
---|
2244 | [boundaryMatch.route.id]: error
|
---|
2245 | },
|
---|
2246 | fetchers: new Map(state.fetchers)
|
---|
2247 | }, {
|
---|
2248 | flushSync: (opts && opts.flushSync) === true
|
---|
2249 | });
|
---|
2250 | }
|
---|
2251 | function getFetcher(key) {
|
---|
2252 | if (future.v7_fetcherPersist) {
|
---|
2253 | activeFetchers.set(key, (activeFetchers.get(key) || 0) + 1);
|
---|
2254 | if (deletedFetchers.has(key)) {
|
---|
2255 | deletedFetchers.delete(key);
|
---|
2256 | }
|
---|
2257 | }
|
---|
2258 | return state.fetchers.get(key) || IDLE_FETCHER;
|
---|
2259 | }
|
---|
2260 | function deleteFetcher(key) {
|
---|
2261 | let fetcher = state.fetchers.get(key);
|
---|
2262 | if (fetchControllers.has(key) && !(fetcher && fetcher.state === "loading" && fetchReloadIds.has(key))) {
|
---|
2263 | abortFetcher(key);
|
---|
2264 | }
|
---|
2265 | fetchLoadMatches.delete(key);
|
---|
2266 | fetchReloadIds.delete(key);
|
---|
2267 | fetchRedirectIds.delete(key);
|
---|
2268 | deletedFetchers.delete(key);
|
---|
2269 | cancelledFetcherLoads.delete(key);
|
---|
2270 | state.fetchers.delete(key);
|
---|
2271 | }
|
---|
2272 | function deleteFetcherAndUpdateState(key) {
|
---|
2273 | if (future.v7_fetcherPersist) {
|
---|
2274 | let count = (activeFetchers.get(key) || 0) - 1;
|
---|
2275 | if (count <= 0) {
|
---|
2276 | activeFetchers.delete(key);
|
---|
2277 | deletedFetchers.add(key);
|
---|
2278 | } else {
|
---|
2279 | activeFetchers.set(key, count);
|
---|
2280 | }
|
---|
2281 | } else {
|
---|
2282 | deleteFetcher(key);
|
---|
2283 | }
|
---|
2284 | updateState({
|
---|
2285 | fetchers: new Map(state.fetchers)
|
---|
2286 | });
|
---|
2287 | }
|
---|
2288 | function abortFetcher(key) {
|
---|
2289 | let controller = fetchControllers.get(key);
|
---|
2290 | if (controller) {
|
---|
2291 | controller.abort();
|
---|
2292 | fetchControllers.delete(key);
|
---|
2293 | }
|
---|
2294 | }
|
---|
2295 | function markFetchersDone(keys) {
|
---|
2296 | for (let key of keys) {
|
---|
2297 | let fetcher = getFetcher(key);
|
---|
2298 | let doneFetcher = getDoneFetcher(fetcher.data);
|
---|
2299 | state.fetchers.set(key, doneFetcher);
|
---|
2300 | }
|
---|
2301 | }
|
---|
2302 | function markFetchRedirectsDone() {
|
---|
2303 | let doneKeys = [];
|
---|
2304 | let updatedFetchers = false;
|
---|
2305 | for (let key of fetchRedirectIds) {
|
---|
2306 | let fetcher = state.fetchers.get(key);
|
---|
2307 | invariant(fetcher, "Expected fetcher: " + key);
|
---|
2308 | if (fetcher.state === "loading") {
|
---|
2309 | fetchRedirectIds.delete(key);
|
---|
2310 | doneKeys.push(key);
|
---|
2311 | updatedFetchers = true;
|
---|
2312 | }
|
---|
2313 | }
|
---|
2314 | markFetchersDone(doneKeys);
|
---|
2315 | return updatedFetchers;
|
---|
2316 | }
|
---|
2317 | function abortStaleFetchLoads(landedId) {
|
---|
2318 | let yeetedKeys = [];
|
---|
2319 | for (let [key, id] of fetchReloadIds) {
|
---|
2320 | if (id < landedId) {
|
---|
2321 | let fetcher = state.fetchers.get(key);
|
---|
2322 | invariant(fetcher, "Expected fetcher: " + key);
|
---|
2323 | if (fetcher.state === "loading") {
|
---|
2324 | abortFetcher(key);
|
---|
2325 | fetchReloadIds.delete(key);
|
---|
2326 | yeetedKeys.push(key);
|
---|
2327 | }
|
---|
2328 | }
|
---|
2329 | }
|
---|
2330 | markFetchersDone(yeetedKeys);
|
---|
2331 | return yeetedKeys.length > 0;
|
---|
2332 | }
|
---|
2333 | function getBlocker(key, fn) {
|
---|
2334 | let blocker = state.blockers.get(key) || IDLE_BLOCKER;
|
---|
2335 | if (blockerFunctions.get(key) !== fn) {
|
---|
2336 | blockerFunctions.set(key, fn);
|
---|
2337 | }
|
---|
2338 | return blocker;
|
---|
2339 | }
|
---|
2340 | function deleteBlocker(key) {
|
---|
2341 | state.blockers.delete(key);
|
---|
2342 | blockerFunctions.delete(key);
|
---|
2343 | }
|
---|
2344 | function updateBlocker(key, newBlocker) {
|
---|
2345 | let blocker = state.blockers.get(key) || IDLE_BLOCKER;
|
---|
2346 | invariant(blocker.state === "unblocked" && newBlocker.state === "blocked" || blocker.state === "blocked" && newBlocker.state === "blocked" || blocker.state === "blocked" && newBlocker.state === "proceeding" || blocker.state === "blocked" && newBlocker.state === "unblocked" || blocker.state === "proceeding" && newBlocker.state === "unblocked", "Invalid blocker state transition: " + blocker.state + " -> " + newBlocker.state);
|
---|
2347 | let blockers = new Map(state.blockers);
|
---|
2348 | blockers.set(key, newBlocker);
|
---|
2349 | updateState({
|
---|
2350 | blockers
|
---|
2351 | });
|
---|
2352 | }
|
---|
2353 | function shouldBlockNavigation(_ref2) {
|
---|
2354 | let {
|
---|
2355 | currentLocation,
|
---|
2356 | nextLocation,
|
---|
2357 | historyAction
|
---|
2358 | } = _ref2;
|
---|
2359 | if (blockerFunctions.size === 0) {
|
---|
2360 | return;
|
---|
2361 | }
|
---|
2362 | if (blockerFunctions.size > 1) {
|
---|
2363 | warning(false, "A router only supports one blocker at a time");
|
---|
2364 | }
|
---|
2365 | let entries = Array.from(blockerFunctions.entries());
|
---|
2366 | let [blockerKey, blockerFunction] = entries[entries.length - 1];
|
---|
2367 | let blocker = state.blockers.get(blockerKey);
|
---|
2368 | if (blocker && blocker.state === "proceeding") {
|
---|
2369 | return;
|
---|
2370 | }
|
---|
2371 | if (blockerFunction({
|
---|
2372 | currentLocation,
|
---|
2373 | nextLocation,
|
---|
2374 | historyAction
|
---|
2375 | })) {
|
---|
2376 | return blockerKey;
|
---|
2377 | }
|
---|
2378 | }
|
---|
2379 | function handleNavigational404(pathname) {
|
---|
2380 | let error = getInternalRouterError(404, {
|
---|
2381 | pathname
|
---|
2382 | });
|
---|
2383 | let routesToUse = inFlightDataRoutes || dataRoutes;
|
---|
2384 | let {
|
---|
2385 | matches,
|
---|
2386 | route
|
---|
2387 | } = getShortCircuitMatches(routesToUse);
|
---|
2388 | cancelActiveDeferreds();
|
---|
2389 | return {
|
---|
2390 | notFoundMatches: matches,
|
---|
2391 | route,
|
---|
2392 | error
|
---|
2393 | };
|
---|
2394 | }
|
---|
2395 | function cancelActiveDeferreds(predicate) {
|
---|
2396 | let cancelledRouteIds = [];
|
---|
2397 | activeDeferreds.forEach((dfd, routeId) => {
|
---|
2398 | if (!predicate || predicate(routeId)) {
|
---|
2399 | dfd.cancel();
|
---|
2400 | cancelledRouteIds.push(routeId);
|
---|
2401 | activeDeferreds.delete(routeId);
|
---|
2402 | }
|
---|
2403 | });
|
---|
2404 | return cancelledRouteIds;
|
---|
2405 | }
|
---|
2406 | function enableScrollRestoration(positions, getPosition, getKey) {
|
---|
2407 | savedScrollPositions2 = positions;
|
---|
2408 | getScrollPosition = getPosition;
|
---|
2409 | getScrollRestorationKey = getKey || null;
|
---|
2410 | if (!initialScrollRestored && state.navigation === IDLE_NAVIGATION) {
|
---|
2411 | initialScrollRestored = true;
|
---|
2412 | let y = getSavedScrollPosition(state.location, state.matches);
|
---|
2413 | if (y != null) {
|
---|
2414 | updateState({
|
---|
2415 | restoreScrollPosition: y
|
---|
2416 | });
|
---|
2417 | }
|
---|
2418 | }
|
---|
2419 | return () => {
|
---|
2420 | savedScrollPositions2 = null;
|
---|
2421 | getScrollPosition = null;
|
---|
2422 | getScrollRestorationKey = null;
|
---|
2423 | };
|
---|
2424 | }
|
---|
2425 | function getScrollKey(location, matches) {
|
---|
2426 | if (getScrollRestorationKey) {
|
---|
2427 | let key = getScrollRestorationKey(location, matches.map((m) => convertRouteMatchToUiMatch(m, state.loaderData)));
|
---|
2428 | return key || location.key;
|
---|
2429 | }
|
---|
2430 | return location.key;
|
---|
2431 | }
|
---|
2432 | function saveScrollPosition(location, matches) {
|
---|
2433 | if (savedScrollPositions2 && getScrollPosition) {
|
---|
2434 | let key = getScrollKey(location, matches);
|
---|
2435 | savedScrollPositions2[key] = getScrollPosition();
|
---|
2436 | }
|
---|
2437 | }
|
---|
2438 | function getSavedScrollPosition(location, matches) {
|
---|
2439 | if (savedScrollPositions2) {
|
---|
2440 | let key = getScrollKey(location, matches);
|
---|
2441 | let y = savedScrollPositions2[key];
|
---|
2442 | if (typeof y === "number") {
|
---|
2443 | return y;
|
---|
2444 | }
|
---|
2445 | }
|
---|
2446 | return null;
|
---|
2447 | }
|
---|
2448 | function checkFogOfWar(matches, routesToUse, pathname) {
|
---|
2449 | if (patchRoutesOnNavigationImpl) {
|
---|
2450 | if (!matches) {
|
---|
2451 | let fogMatches = matchRoutesImpl(routesToUse, pathname, basename, true);
|
---|
2452 | return {
|
---|
2453 | active: true,
|
---|
2454 | matches: fogMatches || []
|
---|
2455 | };
|
---|
2456 | } else {
|
---|
2457 | if (Object.keys(matches[0].params).length > 0) {
|
---|
2458 | let partialMatches = matchRoutesImpl(routesToUse, pathname, basename, true);
|
---|
2459 | return {
|
---|
2460 | active: true,
|
---|
2461 | matches: partialMatches
|
---|
2462 | };
|
---|
2463 | }
|
---|
2464 | }
|
---|
2465 | }
|
---|
2466 | return {
|
---|
2467 | active: false,
|
---|
2468 | matches: null
|
---|
2469 | };
|
---|
2470 | }
|
---|
2471 | async function discoverRoutes(matches, pathname, signal) {
|
---|
2472 | if (!patchRoutesOnNavigationImpl) {
|
---|
2473 | return {
|
---|
2474 | type: "success",
|
---|
2475 | matches
|
---|
2476 | };
|
---|
2477 | }
|
---|
2478 | let partialMatches = matches;
|
---|
2479 | while (true) {
|
---|
2480 | let isNonHMR = inFlightDataRoutes == null;
|
---|
2481 | let routesToUse = inFlightDataRoutes || dataRoutes;
|
---|
2482 | let localManifest = manifest;
|
---|
2483 | try {
|
---|
2484 | await patchRoutesOnNavigationImpl({
|
---|
2485 | path: pathname,
|
---|
2486 | matches: partialMatches,
|
---|
2487 | patch: (routeId, children) => {
|
---|
2488 | if (signal.aborted) return;
|
---|
2489 | patchRoutesImpl(routeId, children, routesToUse, localManifest, mapRouteProperties2);
|
---|
2490 | }
|
---|
2491 | });
|
---|
2492 | } catch (e) {
|
---|
2493 | return {
|
---|
2494 | type: "error",
|
---|
2495 | error: e,
|
---|
2496 | partialMatches
|
---|
2497 | };
|
---|
2498 | } finally {
|
---|
2499 | if (isNonHMR && !signal.aborted) {
|
---|
2500 | dataRoutes = [...dataRoutes];
|
---|
2501 | }
|
---|
2502 | }
|
---|
2503 | if (signal.aborted) {
|
---|
2504 | return {
|
---|
2505 | type: "aborted"
|
---|
2506 | };
|
---|
2507 | }
|
---|
2508 | let newMatches = matchRoutes(routesToUse, pathname, basename);
|
---|
2509 | if (newMatches) {
|
---|
2510 | return {
|
---|
2511 | type: "success",
|
---|
2512 | matches: newMatches
|
---|
2513 | };
|
---|
2514 | }
|
---|
2515 | let newPartialMatches = matchRoutesImpl(routesToUse, pathname, basename, true);
|
---|
2516 | if (!newPartialMatches || partialMatches.length === newPartialMatches.length && partialMatches.every((m, i) => m.route.id === newPartialMatches[i].route.id)) {
|
---|
2517 | return {
|
---|
2518 | type: "success",
|
---|
2519 | matches: null
|
---|
2520 | };
|
---|
2521 | }
|
---|
2522 | partialMatches = newPartialMatches;
|
---|
2523 | }
|
---|
2524 | }
|
---|
2525 | function _internalSetRoutes(newRoutes) {
|
---|
2526 | manifest = {};
|
---|
2527 | inFlightDataRoutes = convertRoutesToDataRoutes(newRoutes, mapRouteProperties2, void 0, manifest);
|
---|
2528 | }
|
---|
2529 | function patchRoutes(routeId, children) {
|
---|
2530 | let isNonHMR = inFlightDataRoutes == null;
|
---|
2531 | let routesToUse = inFlightDataRoutes || dataRoutes;
|
---|
2532 | patchRoutesImpl(routeId, children, routesToUse, manifest, mapRouteProperties2);
|
---|
2533 | if (isNonHMR) {
|
---|
2534 | dataRoutes = [...dataRoutes];
|
---|
2535 | updateState({});
|
---|
2536 | }
|
---|
2537 | }
|
---|
2538 | router = {
|
---|
2539 | get basename() {
|
---|
2540 | return basename;
|
---|
2541 | },
|
---|
2542 | get future() {
|
---|
2543 | return future;
|
---|
2544 | },
|
---|
2545 | get state() {
|
---|
2546 | return state;
|
---|
2547 | },
|
---|
2548 | get routes() {
|
---|
2549 | return dataRoutes;
|
---|
2550 | },
|
---|
2551 | get window() {
|
---|
2552 | return routerWindow;
|
---|
2553 | },
|
---|
2554 | initialize,
|
---|
2555 | subscribe,
|
---|
2556 | enableScrollRestoration,
|
---|
2557 | navigate,
|
---|
2558 | fetch,
|
---|
2559 | revalidate,
|
---|
2560 | // Passthrough to history-aware createHref used by useHref so we get proper
|
---|
2561 | // hash-aware URLs in DOM paths
|
---|
2562 | createHref: (to) => init.history.createHref(to),
|
---|
2563 | encodeLocation: (to) => init.history.encodeLocation(to),
|
---|
2564 | getFetcher,
|
---|
2565 | deleteFetcher: deleteFetcherAndUpdateState,
|
---|
2566 | dispose,
|
---|
2567 | getBlocker,
|
---|
2568 | deleteBlocker,
|
---|
2569 | patchRoutes,
|
---|
2570 | _internalFetchControllers: fetchControllers,
|
---|
2571 | _internalActiveDeferreds: activeDeferreds,
|
---|
2572 | // TODO: Remove setRoutes, it's temporary to avoid dealing with
|
---|
2573 | // updating the tree while validating the update algorithm.
|
---|
2574 | _internalSetRoutes
|
---|
2575 | };
|
---|
2576 | return router;
|
---|
2577 | }
|
---|
2578 | var UNSAFE_DEFERRED_SYMBOL = Symbol("deferred");
|
---|
2579 | function isSubmissionNavigation(opts) {
|
---|
2580 | return opts != null && ("formData" in opts && opts.formData != null || "body" in opts && opts.body !== void 0);
|
---|
2581 | }
|
---|
2582 | function normalizeTo(location, matches, basename, prependBasename, to, v7_relativeSplatPath, fromRouteId, relative) {
|
---|
2583 | let contextualMatches;
|
---|
2584 | let activeRouteMatch;
|
---|
2585 | if (fromRouteId) {
|
---|
2586 | contextualMatches = [];
|
---|
2587 | for (let match of matches) {
|
---|
2588 | contextualMatches.push(match);
|
---|
2589 | if (match.route.id === fromRouteId) {
|
---|
2590 | activeRouteMatch = match;
|
---|
2591 | break;
|
---|
2592 | }
|
---|
2593 | }
|
---|
2594 | } else {
|
---|
2595 | contextualMatches = matches;
|
---|
2596 | activeRouteMatch = matches[matches.length - 1];
|
---|
2597 | }
|
---|
2598 | let path = resolveTo(to ? to : ".", getResolveToMatches(contextualMatches, v7_relativeSplatPath), stripBasename(location.pathname, basename) || location.pathname, relative === "path");
|
---|
2599 | if (to == null) {
|
---|
2600 | path.search = location.search;
|
---|
2601 | path.hash = location.hash;
|
---|
2602 | }
|
---|
2603 | if ((to == null || to === "" || to === ".") && activeRouteMatch) {
|
---|
2604 | let nakedIndex = hasNakedIndexQuery(path.search);
|
---|
2605 | if (activeRouteMatch.route.index && !nakedIndex) {
|
---|
2606 | path.search = path.search ? path.search.replace(/^\?/, "?index&") : "?index";
|
---|
2607 | } else if (!activeRouteMatch.route.index && nakedIndex) {
|
---|
2608 | let params = new URLSearchParams(path.search);
|
---|
2609 | let indexValues = params.getAll("index");
|
---|
2610 | params.delete("index");
|
---|
2611 | indexValues.filter((v) => v).forEach((v) => params.append("index", v));
|
---|
2612 | let qs = params.toString();
|
---|
2613 | path.search = qs ? "?" + qs : "";
|
---|
2614 | }
|
---|
2615 | }
|
---|
2616 | if (prependBasename && basename !== "/") {
|
---|
2617 | path.pathname = path.pathname === "/" ? basename : joinPaths([basename, path.pathname]);
|
---|
2618 | }
|
---|
2619 | return createPath(path);
|
---|
2620 | }
|
---|
2621 | function normalizeNavigateOptions(normalizeFormMethod, isFetcher, path, opts) {
|
---|
2622 | if (!opts || !isSubmissionNavigation(opts)) {
|
---|
2623 | return {
|
---|
2624 | path
|
---|
2625 | };
|
---|
2626 | }
|
---|
2627 | if (opts.formMethod && !isValidMethod(opts.formMethod)) {
|
---|
2628 | return {
|
---|
2629 | path,
|
---|
2630 | error: getInternalRouterError(405, {
|
---|
2631 | method: opts.formMethod
|
---|
2632 | })
|
---|
2633 | };
|
---|
2634 | }
|
---|
2635 | let getInvalidBodyError = () => ({
|
---|
2636 | path,
|
---|
2637 | error: getInternalRouterError(400, {
|
---|
2638 | type: "invalid-body"
|
---|
2639 | })
|
---|
2640 | });
|
---|
2641 | let rawFormMethod = opts.formMethod || "get";
|
---|
2642 | let formMethod = normalizeFormMethod ? rawFormMethod.toUpperCase() : rawFormMethod.toLowerCase();
|
---|
2643 | let formAction = stripHashFromPath(path);
|
---|
2644 | if (opts.body !== void 0) {
|
---|
2645 | if (opts.formEncType === "text/plain") {
|
---|
2646 | if (!isMutationMethod(formMethod)) {
|
---|
2647 | return getInvalidBodyError();
|
---|
2648 | }
|
---|
2649 | let text = typeof opts.body === "string" ? opts.body : opts.body instanceof FormData || opts.body instanceof URLSearchParams ? (
|
---|
2650 | // https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#plain-text-form-data
|
---|
2651 | Array.from(opts.body.entries()).reduce((acc, _ref3) => {
|
---|
2652 | let [name, value] = _ref3;
|
---|
2653 | return "" + acc + name + "=" + value + "\n";
|
---|
2654 | }, "")
|
---|
2655 | ) : String(opts.body);
|
---|
2656 | return {
|
---|
2657 | path,
|
---|
2658 | submission: {
|
---|
2659 | formMethod,
|
---|
2660 | formAction,
|
---|
2661 | formEncType: opts.formEncType,
|
---|
2662 | formData: void 0,
|
---|
2663 | json: void 0,
|
---|
2664 | text
|
---|
2665 | }
|
---|
2666 | };
|
---|
2667 | } else if (opts.formEncType === "application/json") {
|
---|
2668 | if (!isMutationMethod(formMethod)) {
|
---|
2669 | return getInvalidBodyError();
|
---|
2670 | }
|
---|
2671 | try {
|
---|
2672 | let json3 = typeof opts.body === "string" ? JSON.parse(opts.body) : opts.body;
|
---|
2673 | return {
|
---|
2674 | path,
|
---|
2675 | submission: {
|
---|
2676 | formMethod,
|
---|
2677 | formAction,
|
---|
2678 | formEncType: opts.formEncType,
|
---|
2679 | formData: void 0,
|
---|
2680 | json: json3,
|
---|
2681 | text: void 0
|
---|
2682 | }
|
---|
2683 | };
|
---|
2684 | } catch (e) {
|
---|
2685 | return getInvalidBodyError();
|
---|
2686 | }
|
---|
2687 | }
|
---|
2688 | }
|
---|
2689 | invariant(typeof FormData === "function", "FormData is not available in this environment");
|
---|
2690 | let searchParams;
|
---|
2691 | let formData;
|
---|
2692 | if (opts.formData) {
|
---|
2693 | searchParams = convertFormDataToSearchParams(opts.formData);
|
---|
2694 | formData = opts.formData;
|
---|
2695 | } else if (opts.body instanceof FormData) {
|
---|
2696 | searchParams = convertFormDataToSearchParams(opts.body);
|
---|
2697 | formData = opts.body;
|
---|
2698 | } else if (opts.body instanceof URLSearchParams) {
|
---|
2699 | searchParams = opts.body;
|
---|
2700 | formData = convertSearchParamsToFormData(searchParams);
|
---|
2701 | } else if (opts.body == null) {
|
---|
2702 | searchParams = new URLSearchParams();
|
---|
2703 | formData = new FormData();
|
---|
2704 | } else {
|
---|
2705 | try {
|
---|
2706 | searchParams = new URLSearchParams(opts.body);
|
---|
2707 | formData = convertSearchParamsToFormData(searchParams);
|
---|
2708 | } catch (e) {
|
---|
2709 | return getInvalidBodyError();
|
---|
2710 | }
|
---|
2711 | }
|
---|
2712 | let submission = {
|
---|
2713 | formMethod,
|
---|
2714 | formAction,
|
---|
2715 | formEncType: opts && opts.formEncType || "application/x-www-form-urlencoded",
|
---|
2716 | formData,
|
---|
2717 | json: void 0,
|
---|
2718 | text: void 0
|
---|
2719 | };
|
---|
2720 | if (isMutationMethod(submission.formMethod)) {
|
---|
2721 | return {
|
---|
2722 | path,
|
---|
2723 | submission
|
---|
2724 | };
|
---|
2725 | }
|
---|
2726 | let parsedPath = parsePath(path);
|
---|
2727 | if (isFetcher && parsedPath.search && hasNakedIndexQuery(parsedPath.search)) {
|
---|
2728 | searchParams.append("index", "");
|
---|
2729 | }
|
---|
2730 | parsedPath.search = "?" + searchParams;
|
---|
2731 | return {
|
---|
2732 | path: createPath(parsedPath),
|
---|
2733 | submission
|
---|
2734 | };
|
---|
2735 | }
|
---|
2736 | function getLoaderMatchesUntilBoundary(matches, boundaryId, includeBoundary) {
|
---|
2737 | if (includeBoundary === void 0) {
|
---|
2738 | includeBoundary = false;
|
---|
2739 | }
|
---|
2740 | let index = matches.findIndex((m) => m.route.id === boundaryId);
|
---|
2741 | if (index >= 0) {
|
---|
2742 | return matches.slice(0, includeBoundary ? index + 1 : index);
|
---|
2743 | }
|
---|
2744 | return matches;
|
---|
2745 | }
|
---|
2746 | function getMatchesToLoad(history, state, matches, submission, location, initialHydration, skipActionErrorRevalidation, isRevalidationRequired, cancelledDeferredRoutes, cancelledFetcherLoads, deletedFetchers, fetchLoadMatches, fetchRedirectIds, routesToUse, basename, pendingActionResult) {
|
---|
2747 | let actionResult = pendingActionResult ? isErrorResult(pendingActionResult[1]) ? pendingActionResult[1].error : pendingActionResult[1].data : void 0;
|
---|
2748 | let currentUrl = history.createURL(state.location);
|
---|
2749 | let nextUrl = history.createURL(location);
|
---|
2750 | let boundaryMatches = matches;
|
---|
2751 | if (initialHydration && state.errors) {
|
---|
2752 | boundaryMatches = getLoaderMatchesUntilBoundary(matches, Object.keys(state.errors)[0], true);
|
---|
2753 | } else if (pendingActionResult && isErrorResult(pendingActionResult[1])) {
|
---|
2754 | boundaryMatches = getLoaderMatchesUntilBoundary(matches, pendingActionResult[0]);
|
---|
2755 | }
|
---|
2756 | let actionStatus = pendingActionResult ? pendingActionResult[1].statusCode : void 0;
|
---|
2757 | let shouldSkipRevalidation = skipActionErrorRevalidation && actionStatus && actionStatus >= 400;
|
---|
2758 | let navigationMatches = boundaryMatches.filter((match, index) => {
|
---|
2759 | let {
|
---|
2760 | route
|
---|
2761 | } = match;
|
---|
2762 | if (route.lazy) {
|
---|
2763 | return true;
|
---|
2764 | }
|
---|
2765 | if (route.loader == null) {
|
---|
2766 | return false;
|
---|
2767 | }
|
---|
2768 | if (initialHydration) {
|
---|
2769 | return shouldLoadRouteOnHydration(route, state.loaderData, state.errors);
|
---|
2770 | }
|
---|
2771 | if (isNewLoader(state.loaderData, state.matches[index], match) || cancelledDeferredRoutes.some((id) => id === match.route.id)) {
|
---|
2772 | return true;
|
---|
2773 | }
|
---|
2774 | let currentRouteMatch = state.matches[index];
|
---|
2775 | let nextRouteMatch = match;
|
---|
2776 | return shouldRevalidateLoader(match, _extends({
|
---|
2777 | currentUrl,
|
---|
2778 | currentParams: currentRouteMatch.params,
|
---|
2779 | nextUrl,
|
---|
2780 | nextParams: nextRouteMatch.params
|
---|
2781 | }, submission, {
|
---|
2782 | actionResult,
|
---|
2783 | actionStatus,
|
---|
2784 | defaultShouldRevalidate: shouldSkipRevalidation ? false : (
|
---|
2785 | // Forced revalidation due to submission, useRevalidator, or X-Remix-Revalidate
|
---|
2786 | isRevalidationRequired || currentUrl.pathname + currentUrl.search === nextUrl.pathname + nextUrl.search || // Search params affect all loaders
|
---|
2787 | currentUrl.search !== nextUrl.search || isNewRouteInstance(currentRouteMatch, nextRouteMatch)
|
---|
2788 | )
|
---|
2789 | }));
|
---|
2790 | });
|
---|
2791 | let revalidatingFetchers = [];
|
---|
2792 | fetchLoadMatches.forEach((f, key) => {
|
---|
2793 | if (initialHydration || !matches.some((m) => m.route.id === f.routeId) || deletedFetchers.has(key)) {
|
---|
2794 | return;
|
---|
2795 | }
|
---|
2796 | let fetcherMatches = matchRoutes(routesToUse, f.path, basename);
|
---|
2797 | if (!fetcherMatches) {
|
---|
2798 | revalidatingFetchers.push({
|
---|
2799 | key,
|
---|
2800 | routeId: f.routeId,
|
---|
2801 | path: f.path,
|
---|
2802 | matches: null,
|
---|
2803 | match: null,
|
---|
2804 | controller: null
|
---|
2805 | });
|
---|
2806 | return;
|
---|
2807 | }
|
---|
2808 | let fetcher = state.fetchers.get(key);
|
---|
2809 | let fetcherMatch = getTargetMatch(fetcherMatches, f.path);
|
---|
2810 | let shouldRevalidate = false;
|
---|
2811 | if (fetchRedirectIds.has(key)) {
|
---|
2812 | shouldRevalidate = false;
|
---|
2813 | } else if (cancelledFetcherLoads.has(key)) {
|
---|
2814 | cancelledFetcherLoads.delete(key);
|
---|
2815 | shouldRevalidate = true;
|
---|
2816 | } else if (fetcher && fetcher.state !== "idle" && fetcher.data === void 0) {
|
---|
2817 | shouldRevalidate = isRevalidationRequired;
|
---|
2818 | } else {
|
---|
2819 | shouldRevalidate = shouldRevalidateLoader(fetcherMatch, _extends({
|
---|
2820 | currentUrl,
|
---|
2821 | currentParams: state.matches[state.matches.length - 1].params,
|
---|
2822 | nextUrl,
|
---|
2823 | nextParams: matches[matches.length - 1].params
|
---|
2824 | }, submission, {
|
---|
2825 | actionResult,
|
---|
2826 | actionStatus,
|
---|
2827 | defaultShouldRevalidate: shouldSkipRevalidation ? false : isRevalidationRequired
|
---|
2828 | }));
|
---|
2829 | }
|
---|
2830 | if (shouldRevalidate) {
|
---|
2831 | revalidatingFetchers.push({
|
---|
2832 | key,
|
---|
2833 | routeId: f.routeId,
|
---|
2834 | path: f.path,
|
---|
2835 | matches: fetcherMatches,
|
---|
2836 | match: fetcherMatch,
|
---|
2837 | controller: new AbortController()
|
---|
2838 | });
|
---|
2839 | }
|
---|
2840 | });
|
---|
2841 | return [navigationMatches, revalidatingFetchers];
|
---|
2842 | }
|
---|
2843 | function shouldLoadRouteOnHydration(route, loaderData, errors) {
|
---|
2844 | if (route.lazy) {
|
---|
2845 | return true;
|
---|
2846 | }
|
---|
2847 | if (!route.loader) {
|
---|
2848 | return false;
|
---|
2849 | }
|
---|
2850 | let hasData = loaderData != null && loaderData[route.id] !== void 0;
|
---|
2851 | let hasError = errors != null && errors[route.id] !== void 0;
|
---|
2852 | if (!hasData && hasError) {
|
---|
2853 | return false;
|
---|
2854 | }
|
---|
2855 | if (typeof route.loader === "function" && route.loader.hydrate === true) {
|
---|
2856 | return true;
|
---|
2857 | }
|
---|
2858 | return !hasData && !hasError;
|
---|
2859 | }
|
---|
2860 | function isNewLoader(currentLoaderData, currentMatch, match) {
|
---|
2861 | let isNew = (
|
---|
2862 | // [a] -> [a, b]
|
---|
2863 | !currentMatch || // [a, b] -> [a, c]
|
---|
2864 | match.route.id !== currentMatch.route.id
|
---|
2865 | );
|
---|
2866 | let isMissingData = currentLoaderData[match.route.id] === void 0;
|
---|
2867 | return isNew || isMissingData;
|
---|
2868 | }
|
---|
2869 | function isNewRouteInstance(currentMatch, match) {
|
---|
2870 | let currentPath = currentMatch.route.path;
|
---|
2871 | return (
|
---|
2872 | // param change for this match, /users/123 -> /users/456
|
---|
2873 | currentMatch.pathname !== match.pathname || // splat param changed, which is not present in match.path
|
---|
2874 | // e.g. /files/images/avatar.jpg -> files/finances.xls
|
---|
2875 | currentPath != null && currentPath.endsWith("*") && currentMatch.params["*"] !== match.params["*"]
|
---|
2876 | );
|
---|
2877 | }
|
---|
2878 | function shouldRevalidateLoader(loaderMatch, arg) {
|
---|
2879 | if (loaderMatch.route.shouldRevalidate) {
|
---|
2880 | let routeChoice = loaderMatch.route.shouldRevalidate(arg);
|
---|
2881 | if (typeof routeChoice === "boolean") {
|
---|
2882 | return routeChoice;
|
---|
2883 | }
|
---|
2884 | }
|
---|
2885 | return arg.defaultShouldRevalidate;
|
---|
2886 | }
|
---|
2887 | function patchRoutesImpl(routeId, children, routesToUse, manifest, mapRouteProperties2) {
|
---|
2888 | var _childrenToPatch;
|
---|
2889 | let childrenToPatch;
|
---|
2890 | if (routeId) {
|
---|
2891 | let route = manifest[routeId];
|
---|
2892 | invariant(route, "No route found to patch children into: routeId = " + routeId);
|
---|
2893 | if (!route.children) {
|
---|
2894 | route.children = [];
|
---|
2895 | }
|
---|
2896 | childrenToPatch = route.children;
|
---|
2897 | } else {
|
---|
2898 | childrenToPatch = routesToUse;
|
---|
2899 | }
|
---|
2900 | let uniqueChildren = children.filter((newRoute) => !childrenToPatch.some((existingRoute) => isSameRoute(newRoute, existingRoute)));
|
---|
2901 | let newRoutes = convertRoutesToDataRoutes(uniqueChildren, mapRouteProperties2, [routeId || "_", "patch", String(((_childrenToPatch = childrenToPatch) == null ? void 0 : _childrenToPatch.length) || "0")], manifest);
|
---|
2902 | childrenToPatch.push(...newRoutes);
|
---|
2903 | }
|
---|
2904 | function isSameRoute(newRoute, existingRoute) {
|
---|
2905 | if ("id" in newRoute && "id" in existingRoute && newRoute.id === existingRoute.id) {
|
---|
2906 | return true;
|
---|
2907 | }
|
---|
2908 | if (!(newRoute.index === existingRoute.index && newRoute.path === existingRoute.path && newRoute.caseSensitive === existingRoute.caseSensitive)) {
|
---|
2909 | return false;
|
---|
2910 | }
|
---|
2911 | if ((!newRoute.children || newRoute.children.length === 0) && (!existingRoute.children || existingRoute.children.length === 0)) {
|
---|
2912 | return true;
|
---|
2913 | }
|
---|
2914 | return newRoute.children.every((aChild, i) => {
|
---|
2915 | var _existingRoute$childr;
|
---|
2916 | return (_existingRoute$childr = existingRoute.children) == null ? void 0 : _existingRoute$childr.some((bChild) => isSameRoute(aChild, bChild));
|
---|
2917 | });
|
---|
2918 | }
|
---|
2919 | async function loadLazyRouteModule(route, mapRouteProperties2, manifest) {
|
---|
2920 | if (!route.lazy) {
|
---|
2921 | return;
|
---|
2922 | }
|
---|
2923 | let lazyRoute = await route.lazy();
|
---|
2924 | if (!route.lazy) {
|
---|
2925 | return;
|
---|
2926 | }
|
---|
2927 | let routeToUpdate = manifest[route.id];
|
---|
2928 | invariant(routeToUpdate, "No route found in manifest");
|
---|
2929 | let routeUpdates = {};
|
---|
2930 | for (let lazyRouteProperty in lazyRoute) {
|
---|
2931 | let staticRouteValue = routeToUpdate[lazyRouteProperty];
|
---|
2932 | let isPropertyStaticallyDefined = staticRouteValue !== void 0 && // This property isn't static since it should always be updated based
|
---|
2933 | // on the route updates
|
---|
2934 | lazyRouteProperty !== "hasErrorBoundary";
|
---|
2935 | warning(!isPropertyStaticallyDefined, 'Route "' + routeToUpdate.id + '" has a static property "' + lazyRouteProperty + '" defined but its lazy function is also returning a value for this property. ' + ('The lazy route property "' + lazyRouteProperty + '" will be ignored.'));
|
---|
2936 | if (!isPropertyStaticallyDefined && !immutableRouteKeys.has(lazyRouteProperty)) {
|
---|
2937 | routeUpdates[lazyRouteProperty] = lazyRoute[lazyRouteProperty];
|
---|
2938 | }
|
---|
2939 | }
|
---|
2940 | Object.assign(routeToUpdate, routeUpdates);
|
---|
2941 | Object.assign(routeToUpdate, _extends({}, mapRouteProperties2(routeToUpdate), {
|
---|
2942 | lazy: void 0
|
---|
2943 | }));
|
---|
2944 | }
|
---|
2945 | async function defaultDataStrategy(_ref4) {
|
---|
2946 | let {
|
---|
2947 | matches
|
---|
2948 | } = _ref4;
|
---|
2949 | let matchesToLoad = matches.filter((m) => m.shouldLoad);
|
---|
2950 | let results = await Promise.all(matchesToLoad.map((m) => m.resolve()));
|
---|
2951 | return results.reduce((acc, result, i) => Object.assign(acc, {
|
---|
2952 | [matchesToLoad[i].route.id]: result
|
---|
2953 | }), {});
|
---|
2954 | }
|
---|
2955 | async function callDataStrategyImpl(dataStrategyImpl, type, state, request, matchesToLoad, matches, fetcherKey, manifest, mapRouteProperties2, requestContext) {
|
---|
2956 | let loadRouteDefinitionsPromises = matches.map((m) => m.route.lazy ? loadLazyRouteModule(m.route, mapRouteProperties2, manifest) : void 0);
|
---|
2957 | let dsMatches = matches.map((match, i) => {
|
---|
2958 | let loadRoutePromise = loadRouteDefinitionsPromises[i];
|
---|
2959 | let shouldLoad = matchesToLoad.some((m) => m.route.id === match.route.id);
|
---|
2960 | let resolve = async (handlerOverride) => {
|
---|
2961 | if (handlerOverride && request.method === "GET" && (match.route.lazy || match.route.loader)) {
|
---|
2962 | shouldLoad = true;
|
---|
2963 | }
|
---|
2964 | return shouldLoad ? callLoaderOrAction(type, request, match, loadRoutePromise, handlerOverride, requestContext) : Promise.resolve({
|
---|
2965 | type: ResultType.data,
|
---|
2966 | result: void 0
|
---|
2967 | });
|
---|
2968 | };
|
---|
2969 | return _extends({}, match, {
|
---|
2970 | shouldLoad,
|
---|
2971 | resolve
|
---|
2972 | });
|
---|
2973 | });
|
---|
2974 | let results = await dataStrategyImpl({
|
---|
2975 | matches: dsMatches,
|
---|
2976 | request,
|
---|
2977 | params: matches[0].params,
|
---|
2978 | fetcherKey,
|
---|
2979 | context: requestContext
|
---|
2980 | });
|
---|
2981 | try {
|
---|
2982 | await Promise.all(loadRouteDefinitionsPromises);
|
---|
2983 | } catch (e) {
|
---|
2984 | }
|
---|
2985 | return results;
|
---|
2986 | }
|
---|
2987 | async function callLoaderOrAction(type, request, match, loadRoutePromise, handlerOverride, staticContext) {
|
---|
2988 | let result;
|
---|
2989 | let onReject;
|
---|
2990 | let runHandler = (handler) => {
|
---|
2991 | let reject;
|
---|
2992 | let abortPromise = new Promise((_, r) => reject = r);
|
---|
2993 | onReject = () => reject();
|
---|
2994 | request.signal.addEventListener("abort", onReject);
|
---|
2995 | let actualHandler = (ctx) => {
|
---|
2996 | if (typeof handler !== "function") {
|
---|
2997 | return Promise.reject(new Error("You cannot call the handler for a route which defines a boolean " + ('"' + type + '" [routeId: ' + match.route.id + "]")));
|
---|
2998 | }
|
---|
2999 | return handler({
|
---|
3000 | request,
|
---|
3001 | params: match.params,
|
---|
3002 | context: staticContext
|
---|
3003 | }, ...ctx !== void 0 ? [ctx] : []);
|
---|
3004 | };
|
---|
3005 | let handlerPromise = (async () => {
|
---|
3006 | try {
|
---|
3007 | let val = await (handlerOverride ? handlerOverride((ctx) => actualHandler(ctx)) : actualHandler());
|
---|
3008 | return {
|
---|
3009 | type: "data",
|
---|
3010 | result: val
|
---|
3011 | };
|
---|
3012 | } catch (e) {
|
---|
3013 | return {
|
---|
3014 | type: "error",
|
---|
3015 | result: e
|
---|
3016 | };
|
---|
3017 | }
|
---|
3018 | })();
|
---|
3019 | return Promise.race([handlerPromise, abortPromise]);
|
---|
3020 | };
|
---|
3021 | try {
|
---|
3022 | let handler = match.route[type];
|
---|
3023 | if (loadRoutePromise) {
|
---|
3024 | if (handler) {
|
---|
3025 | let handlerError;
|
---|
3026 | let [value] = await Promise.all([
|
---|
3027 | // If the handler throws, don't let it immediately bubble out,
|
---|
3028 | // since we need to let the lazy() execution finish so we know if this
|
---|
3029 | // route has a boundary that can handle the error
|
---|
3030 | runHandler(handler).catch((e) => {
|
---|
3031 | handlerError = e;
|
---|
3032 | }),
|
---|
3033 | loadRoutePromise
|
---|
3034 | ]);
|
---|
3035 | if (handlerError !== void 0) {
|
---|
3036 | throw handlerError;
|
---|
3037 | }
|
---|
3038 | result = value;
|
---|
3039 | } else {
|
---|
3040 | await loadRoutePromise;
|
---|
3041 | handler = match.route[type];
|
---|
3042 | if (handler) {
|
---|
3043 | result = await runHandler(handler);
|
---|
3044 | } else if (type === "action") {
|
---|
3045 | let url = new URL(request.url);
|
---|
3046 | let pathname = url.pathname + url.search;
|
---|
3047 | throw getInternalRouterError(405, {
|
---|
3048 | method: request.method,
|
---|
3049 | pathname,
|
---|
3050 | routeId: match.route.id
|
---|
3051 | });
|
---|
3052 | } else {
|
---|
3053 | return {
|
---|
3054 | type: ResultType.data,
|
---|
3055 | result: void 0
|
---|
3056 | };
|
---|
3057 | }
|
---|
3058 | }
|
---|
3059 | } else if (!handler) {
|
---|
3060 | let url = new URL(request.url);
|
---|
3061 | let pathname = url.pathname + url.search;
|
---|
3062 | throw getInternalRouterError(404, {
|
---|
3063 | pathname
|
---|
3064 | });
|
---|
3065 | } else {
|
---|
3066 | result = await runHandler(handler);
|
---|
3067 | }
|
---|
3068 | invariant(result.result !== void 0, "You defined " + (type === "action" ? "an action" : "a loader") + " for route " + ('"' + match.route.id + "\" but didn't return anything from your `" + type + "` ") + "function. Please return a value or `null`.");
|
---|
3069 | } catch (e) {
|
---|
3070 | return {
|
---|
3071 | type: ResultType.error,
|
---|
3072 | result: e
|
---|
3073 | };
|
---|
3074 | } finally {
|
---|
3075 | if (onReject) {
|
---|
3076 | request.signal.removeEventListener("abort", onReject);
|
---|
3077 | }
|
---|
3078 | }
|
---|
3079 | return result;
|
---|
3080 | }
|
---|
3081 | async function convertDataStrategyResultToDataResult(dataStrategyResult) {
|
---|
3082 | let {
|
---|
3083 | result,
|
---|
3084 | type
|
---|
3085 | } = dataStrategyResult;
|
---|
3086 | if (isResponse(result)) {
|
---|
3087 | let data;
|
---|
3088 | try {
|
---|
3089 | let contentType = result.headers.get("Content-Type");
|
---|
3090 | if (contentType && /\bapplication\/json\b/.test(contentType)) {
|
---|
3091 | if (result.body == null) {
|
---|
3092 | data = null;
|
---|
3093 | } else {
|
---|
3094 | data = await result.json();
|
---|
3095 | }
|
---|
3096 | } else {
|
---|
3097 | data = await result.text();
|
---|
3098 | }
|
---|
3099 | } catch (e) {
|
---|
3100 | return {
|
---|
3101 | type: ResultType.error,
|
---|
3102 | error: e
|
---|
3103 | };
|
---|
3104 | }
|
---|
3105 | if (type === ResultType.error) {
|
---|
3106 | return {
|
---|
3107 | type: ResultType.error,
|
---|
3108 | error: new ErrorResponseImpl(result.status, result.statusText, data),
|
---|
3109 | statusCode: result.status,
|
---|
3110 | headers: result.headers
|
---|
3111 | };
|
---|
3112 | }
|
---|
3113 | return {
|
---|
3114 | type: ResultType.data,
|
---|
3115 | data,
|
---|
3116 | statusCode: result.status,
|
---|
3117 | headers: result.headers
|
---|
3118 | };
|
---|
3119 | }
|
---|
3120 | if (type === ResultType.error) {
|
---|
3121 | if (isDataWithResponseInit(result)) {
|
---|
3122 | var _result$init2;
|
---|
3123 | if (result.data instanceof Error) {
|
---|
3124 | var _result$init;
|
---|
3125 | return {
|
---|
3126 | type: ResultType.error,
|
---|
3127 | error: result.data,
|
---|
3128 | statusCode: (_result$init = result.init) == null ? void 0 : _result$init.status
|
---|
3129 | };
|
---|
3130 | }
|
---|
3131 | result = new ErrorResponseImpl(((_result$init2 = result.init) == null ? void 0 : _result$init2.status) || 500, void 0, result.data);
|
---|
3132 | }
|
---|
3133 | return {
|
---|
3134 | type: ResultType.error,
|
---|
3135 | error: result,
|
---|
3136 | statusCode: isRouteErrorResponse(result) ? result.status : void 0
|
---|
3137 | };
|
---|
3138 | }
|
---|
3139 | if (isDeferredData(result)) {
|
---|
3140 | var _result$init3, _result$init4;
|
---|
3141 | return {
|
---|
3142 | type: ResultType.deferred,
|
---|
3143 | deferredData: result,
|
---|
3144 | statusCode: (_result$init3 = result.init) == null ? void 0 : _result$init3.status,
|
---|
3145 | headers: ((_result$init4 = result.init) == null ? void 0 : _result$init4.headers) && new Headers(result.init.headers)
|
---|
3146 | };
|
---|
3147 | }
|
---|
3148 | if (isDataWithResponseInit(result)) {
|
---|
3149 | var _result$init5, _result$init6;
|
---|
3150 | return {
|
---|
3151 | type: ResultType.data,
|
---|
3152 | data: result.data,
|
---|
3153 | statusCode: (_result$init5 = result.init) == null ? void 0 : _result$init5.status,
|
---|
3154 | headers: (_result$init6 = result.init) != null && _result$init6.headers ? new Headers(result.init.headers) : void 0
|
---|
3155 | };
|
---|
3156 | }
|
---|
3157 | return {
|
---|
3158 | type: ResultType.data,
|
---|
3159 | data: result
|
---|
3160 | };
|
---|
3161 | }
|
---|
3162 | function normalizeRelativeRoutingRedirectResponse(response, request, routeId, matches, basename, v7_relativeSplatPath) {
|
---|
3163 | let location = response.headers.get("Location");
|
---|
3164 | invariant(location, "Redirects returned/thrown from loaders/actions must have a Location header");
|
---|
3165 | if (!ABSOLUTE_URL_REGEX.test(location)) {
|
---|
3166 | let trimmedMatches = matches.slice(0, matches.findIndex((m) => m.route.id === routeId) + 1);
|
---|
3167 | location = normalizeTo(new URL(request.url), trimmedMatches, basename, true, location, v7_relativeSplatPath);
|
---|
3168 | response.headers.set("Location", location);
|
---|
3169 | }
|
---|
3170 | return response;
|
---|
3171 | }
|
---|
3172 | function normalizeRedirectLocation(location, currentUrl, basename) {
|
---|
3173 | if (ABSOLUTE_URL_REGEX.test(location)) {
|
---|
3174 | let normalizedLocation = location;
|
---|
3175 | let url = normalizedLocation.startsWith("//") ? new URL(currentUrl.protocol + normalizedLocation) : new URL(normalizedLocation);
|
---|
3176 | let isSameBasename = stripBasename(url.pathname, basename) != null;
|
---|
3177 | if (url.origin === currentUrl.origin && isSameBasename) {
|
---|
3178 | return url.pathname + url.search + url.hash;
|
---|
3179 | }
|
---|
3180 | }
|
---|
3181 | return location;
|
---|
3182 | }
|
---|
3183 | function createClientSideRequest(history, location, signal, submission) {
|
---|
3184 | let url = history.createURL(stripHashFromPath(location)).toString();
|
---|
3185 | let init = {
|
---|
3186 | signal
|
---|
3187 | };
|
---|
3188 | if (submission && isMutationMethod(submission.formMethod)) {
|
---|
3189 | let {
|
---|
3190 | formMethod,
|
---|
3191 | formEncType
|
---|
3192 | } = submission;
|
---|
3193 | init.method = formMethod.toUpperCase();
|
---|
3194 | if (formEncType === "application/json") {
|
---|
3195 | init.headers = new Headers({
|
---|
3196 | "Content-Type": formEncType
|
---|
3197 | });
|
---|
3198 | init.body = JSON.stringify(submission.json);
|
---|
3199 | } else if (formEncType === "text/plain") {
|
---|
3200 | init.body = submission.text;
|
---|
3201 | } else if (formEncType === "application/x-www-form-urlencoded" && submission.formData) {
|
---|
3202 | init.body = convertFormDataToSearchParams(submission.formData);
|
---|
3203 | } else {
|
---|
3204 | init.body = submission.formData;
|
---|
3205 | }
|
---|
3206 | }
|
---|
3207 | return new Request(url, init);
|
---|
3208 | }
|
---|
3209 | function convertFormDataToSearchParams(formData) {
|
---|
3210 | let searchParams = new URLSearchParams();
|
---|
3211 | for (let [key, value] of formData.entries()) {
|
---|
3212 | searchParams.append(key, typeof value === "string" ? value : value.name);
|
---|
3213 | }
|
---|
3214 | return searchParams;
|
---|
3215 | }
|
---|
3216 | function convertSearchParamsToFormData(searchParams) {
|
---|
3217 | let formData = new FormData();
|
---|
3218 | for (let [key, value] of searchParams.entries()) {
|
---|
3219 | formData.append(key, value);
|
---|
3220 | }
|
---|
3221 | return formData;
|
---|
3222 | }
|
---|
3223 | function processRouteLoaderData(matches, results, pendingActionResult, activeDeferreds, skipLoaderErrorBubbling) {
|
---|
3224 | let loaderData = {};
|
---|
3225 | let errors = null;
|
---|
3226 | let statusCode;
|
---|
3227 | let foundError = false;
|
---|
3228 | let loaderHeaders = {};
|
---|
3229 | let pendingError = pendingActionResult && isErrorResult(pendingActionResult[1]) ? pendingActionResult[1].error : void 0;
|
---|
3230 | matches.forEach((match) => {
|
---|
3231 | if (!(match.route.id in results)) {
|
---|
3232 | return;
|
---|
3233 | }
|
---|
3234 | let id = match.route.id;
|
---|
3235 | let result = results[id];
|
---|
3236 | invariant(!isRedirectResult(result), "Cannot handle redirect results in processLoaderData");
|
---|
3237 | if (isErrorResult(result)) {
|
---|
3238 | let error = result.error;
|
---|
3239 | if (pendingError !== void 0) {
|
---|
3240 | error = pendingError;
|
---|
3241 | pendingError = void 0;
|
---|
3242 | }
|
---|
3243 | errors = errors || {};
|
---|
3244 | if (skipLoaderErrorBubbling) {
|
---|
3245 | errors[id] = error;
|
---|
3246 | } else {
|
---|
3247 | let boundaryMatch = findNearestBoundary(matches, id);
|
---|
3248 | if (errors[boundaryMatch.route.id] == null) {
|
---|
3249 | errors[boundaryMatch.route.id] = error;
|
---|
3250 | }
|
---|
3251 | }
|
---|
3252 | loaderData[id] = void 0;
|
---|
3253 | if (!foundError) {
|
---|
3254 | foundError = true;
|
---|
3255 | statusCode = isRouteErrorResponse(result.error) ? result.error.status : 500;
|
---|
3256 | }
|
---|
3257 | if (result.headers) {
|
---|
3258 | loaderHeaders[id] = result.headers;
|
---|
3259 | }
|
---|
3260 | } else {
|
---|
3261 | if (isDeferredResult(result)) {
|
---|
3262 | activeDeferreds.set(id, result.deferredData);
|
---|
3263 | loaderData[id] = result.deferredData.data;
|
---|
3264 | if (result.statusCode != null && result.statusCode !== 200 && !foundError) {
|
---|
3265 | statusCode = result.statusCode;
|
---|
3266 | }
|
---|
3267 | if (result.headers) {
|
---|
3268 | loaderHeaders[id] = result.headers;
|
---|
3269 | }
|
---|
3270 | } else {
|
---|
3271 | loaderData[id] = result.data;
|
---|
3272 | if (result.statusCode && result.statusCode !== 200 && !foundError) {
|
---|
3273 | statusCode = result.statusCode;
|
---|
3274 | }
|
---|
3275 | if (result.headers) {
|
---|
3276 | loaderHeaders[id] = result.headers;
|
---|
3277 | }
|
---|
3278 | }
|
---|
3279 | }
|
---|
3280 | });
|
---|
3281 | if (pendingError !== void 0 && pendingActionResult) {
|
---|
3282 | errors = {
|
---|
3283 | [pendingActionResult[0]]: pendingError
|
---|
3284 | };
|
---|
3285 | loaderData[pendingActionResult[0]] = void 0;
|
---|
3286 | }
|
---|
3287 | return {
|
---|
3288 | loaderData,
|
---|
3289 | errors,
|
---|
3290 | statusCode: statusCode || 200,
|
---|
3291 | loaderHeaders
|
---|
3292 | };
|
---|
3293 | }
|
---|
3294 | function processLoaderData(state, matches, results, pendingActionResult, revalidatingFetchers, fetcherResults, activeDeferreds) {
|
---|
3295 | let {
|
---|
3296 | loaderData,
|
---|
3297 | errors
|
---|
3298 | } = processRouteLoaderData(
|
---|
3299 | matches,
|
---|
3300 | results,
|
---|
3301 | pendingActionResult,
|
---|
3302 | activeDeferreds,
|
---|
3303 | false
|
---|
3304 | // This method is only called client side so we always want to bubble
|
---|
3305 | );
|
---|
3306 | revalidatingFetchers.forEach((rf) => {
|
---|
3307 | let {
|
---|
3308 | key,
|
---|
3309 | match,
|
---|
3310 | controller
|
---|
3311 | } = rf;
|
---|
3312 | let result = fetcherResults[key];
|
---|
3313 | invariant(result, "Did not find corresponding fetcher result");
|
---|
3314 | if (controller && controller.signal.aborted) {
|
---|
3315 | return;
|
---|
3316 | } else if (isErrorResult(result)) {
|
---|
3317 | let boundaryMatch = findNearestBoundary(state.matches, match == null ? void 0 : match.route.id);
|
---|
3318 | if (!(errors && errors[boundaryMatch.route.id])) {
|
---|
3319 | errors = _extends({}, errors, {
|
---|
3320 | [boundaryMatch.route.id]: result.error
|
---|
3321 | });
|
---|
3322 | }
|
---|
3323 | state.fetchers.delete(key);
|
---|
3324 | } else if (isRedirectResult(result)) {
|
---|
3325 | invariant(false, "Unhandled fetcher revalidation redirect");
|
---|
3326 | } else if (isDeferredResult(result)) {
|
---|
3327 | invariant(false, "Unhandled fetcher deferred data");
|
---|
3328 | } else {
|
---|
3329 | let doneFetcher = getDoneFetcher(result.data);
|
---|
3330 | state.fetchers.set(key, doneFetcher);
|
---|
3331 | }
|
---|
3332 | });
|
---|
3333 | return {
|
---|
3334 | loaderData,
|
---|
3335 | errors
|
---|
3336 | };
|
---|
3337 | }
|
---|
3338 | function mergeLoaderData(loaderData, newLoaderData, matches, errors) {
|
---|
3339 | let mergedLoaderData = _extends({}, newLoaderData);
|
---|
3340 | for (let match of matches) {
|
---|
3341 | let id = match.route.id;
|
---|
3342 | if (newLoaderData.hasOwnProperty(id)) {
|
---|
3343 | if (newLoaderData[id] !== void 0) {
|
---|
3344 | mergedLoaderData[id] = newLoaderData[id];
|
---|
3345 | }
|
---|
3346 | } else if (loaderData[id] !== void 0 && match.route.loader) {
|
---|
3347 | mergedLoaderData[id] = loaderData[id];
|
---|
3348 | }
|
---|
3349 | if (errors && errors.hasOwnProperty(id)) {
|
---|
3350 | break;
|
---|
3351 | }
|
---|
3352 | }
|
---|
3353 | return mergedLoaderData;
|
---|
3354 | }
|
---|
3355 | function getActionDataForCommit(pendingActionResult) {
|
---|
3356 | if (!pendingActionResult) {
|
---|
3357 | return {};
|
---|
3358 | }
|
---|
3359 | return isErrorResult(pendingActionResult[1]) ? {
|
---|
3360 | // Clear out prior actionData on errors
|
---|
3361 | actionData: {}
|
---|
3362 | } : {
|
---|
3363 | actionData: {
|
---|
3364 | [pendingActionResult[0]]: pendingActionResult[1].data
|
---|
3365 | }
|
---|
3366 | };
|
---|
3367 | }
|
---|
3368 | function findNearestBoundary(matches, routeId) {
|
---|
3369 | let eligibleMatches = routeId ? matches.slice(0, matches.findIndex((m) => m.route.id === routeId) + 1) : [...matches];
|
---|
3370 | return eligibleMatches.reverse().find((m) => m.route.hasErrorBoundary === true) || matches[0];
|
---|
3371 | }
|
---|
3372 | function getShortCircuitMatches(routes) {
|
---|
3373 | let route = routes.length === 1 ? routes[0] : routes.find((r) => r.index || !r.path || r.path === "/") || {
|
---|
3374 | id: "__shim-error-route__"
|
---|
3375 | };
|
---|
3376 | return {
|
---|
3377 | matches: [{
|
---|
3378 | params: {},
|
---|
3379 | pathname: "",
|
---|
3380 | pathnameBase: "",
|
---|
3381 | route
|
---|
3382 | }],
|
---|
3383 | route
|
---|
3384 | };
|
---|
3385 | }
|
---|
3386 | function getInternalRouterError(status, _temp5) {
|
---|
3387 | let {
|
---|
3388 | pathname,
|
---|
3389 | routeId,
|
---|
3390 | method,
|
---|
3391 | type,
|
---|
3392 | message
|
---|
3393 | } = _temp5 === void 0 ? {} : _temp5;
|
---|
3394 | let statusText = "Unknown Server Error";
|
---|
3395 | let errorMessage = "Unknown @remix-run/router error";
|
---|
3396 | if (status === 400) {
|
---|
3397 | statusText = "Bad Request";
|
---|
3398 | if (method && pathname && routeId) {
|
---|
3399 | errorMessage = "You made a " + method + ' request to "' + pathname + '" but ' + ('did not provide a `loader` for route "' + routeId + '", ') + "so there is no way to handle the request.";
|
---|
3400 | } else if (type === "defer-action") {
|
---|
3401 | errorMessage = "defer() is not supported in actions";
|
---|
3402 | } else if (type === "invalid-body") {
|
---|
3403 | errorMessage = "Unable to encode submission body";
|
---|
3404 | }
|
---|
3405 | } else if (status === 403) {
|
---|
3406 | statusText = "Forbidden";
|
---|
3407 | errorMessage = 'Route "' + routeId + '" does not match URL "' + pathname + '"';
|
---|
3408 | } else if (status === 404) {
|
---|
3409 | statusText = "Not Found";
|
---|
3410 | errorMessage = 'No route matches URL "' + pathname + '"';
|
---|
3411 | } else if (status === 405) {
|
---|
3412 | statusText = "Method Not Allowed";
|
---|
3413 | if (method && pathname && routeId) {
|
---|
3414 | errorMessage = "You made a " + method.toUpperCase() + ' request to "' + pathname + '" but ' + ('did not provide an `action` for route "' + routeId + '", ') + "so there is no way to handle the request.";
|
---|
3415 | } else if (method) {
|
---|
3416 | errorMessage = 'Invalid request method "' + method.toUpperCase() + '"';
|
---|
3417 | }
|
---|
3418 | }
|
---|
3419 | return new ErrorResponseImpl(status || 500, statusText, new Error(errorMessage), true);
|
---|
3420 | }
|
---|
3421 | function findRedirect(results) {
|
---|
3422 | let entries = Object.entries(results);
|
---|
3423 | for (let i = entries.length - 1; i >= 0; i--) {
|
---|
3424 | let [key, result] = entries[i];
|
---|
3425 | if (isRedirectResult(result)) {
|
---|
3426 | return {
|
---|
3427 | key,
|
---|
3428 | result
|
---|
3429 | };
|
---|
3430 | }
|
---|
3431 | }
|
---|
3432 | }
|
---|
3433 | function stripHashFromPath(path) {
|
---|
3434 | let parsedPath = typeof path === "string" ? parsePath(path) : path;
|
---|
3435 | return createPath(_extends({}, parsedPath, {
|
---|
3436 | hash: ""
|
---|
3437 | }));
|
---|
3438 | }
|
---|
3439 | function isHashChangeOnly(a, b) {
|
---|
3440 | if (a.pathname !== b.pathname || a.search !== b.search) {
|
---|
3441 | return false;
|
---|
3442 | }
|
---|
3443 | if (a.hash === "") {
|
---|
3444 | return b.hash !== "";
|
---|
3445 | } else if (a.hash === b.hash) {
|
---|
3446 | return true;
|
---|
3447 | } else if (b.hash !== "") {
|
---|
3448 | return true;
|
---|
3449 | }
|
---|
3450 | return false;
|
---|
3451 | }
|
---|
3452 | function isRedirectDataStrategyResultResult(result) {
|
---|
3453 | return isResponse(result.result) && redirectStatusCodes.has(result.result.status);
|
---|
3454 | }
|
---|
3455 | function isDeferredResult(result) {
|
---|
3456 | return result.type === ResultType.deferred;
|
---|
3457 | }
|
---|
3458 | function isErrorResult(result) {
|
---|
3459 | return result.type === ResultType.error;
|
---|
3460 | }
|
---|
3461 | function isRedirectResult(result) {
|
---|
3462 | return (result && result.type) === ResultType.redirect;
|
---|
3463 | }
|
---|
3464 | function isDataWithResponseInit(value) {
|
---|
3465 | return typeof value === "object" && value != null && "type" in value && "data" in value && "init" in value && value.type === "DataWithResponseInit";
|
---|
3466 | }
|
---|
3467 | function isDeferredData(value) {
|
---|
3468 | let deferred = value;
|
---|
3469 | return deferred && typeof deferred === "object" && typeof deferred.data === "object" && typeof deferred.subscribe === "function" && typeof deferred.cancel === "function" && typeof deferred.resolveData === "function";
|
---|
3470 | }
|
---|
3471 | function isResponse(value) {
|
---|
3472 | return value != null && typeof value.status === "number" && typeof value.statusText === "string" && typeof value.headers === "object" && typeof value.body !== "undefined";
|
---|
3473 | }
|
---|
3474 | function isValidMethod(method) {
|
---|
3475 | return validRequestMethods.has(method.toLowerCase());
|
---|
3476 | }
|
---|
3477 | function isMutationMethod(method) {
|
---|
3478 | return validMutationMethods.has(method.toLowerCase());
|
---|
3479 | }
|
---|
3480 | async function resolveNavigationDeferredResults(matches, results, signal, currentMatches, currentLoaderData) {
|
---|
3481 | let entries = Object.entries(results);
|
---|
3482 | for (let index = 0; index < entries.length; index++) {
|
---|
3483 | let [routeId, result] = entries[index];
|
---|
3484 | let match = matches.find((m) => (m == null ? void 0 : m.route.id) === routeId);
|
---|
3485 | if (!match) {
|
---|
3486 | continue;
|
---|
3487 | }
|
---|
3488 | let currentMatch = currentMatches.find((m) => m.route.id === match.route.id);
|
---|
3489 | let isRevalidatingLoader = currentMatch != null && !isNewRouteInstance(currentMatch, match) && (currentLoaderData && currentLoaderData[match.route.id]) !== void 0;
|
---|
3490 | if (isDeferredResult(result) && isRevalidatingLoader) {
|
---|
3491 | await resolveDeferredData(result, signal, false).then((result2) => {
|
---|
3492 | if (result2) {
|
---|
3493 | results[routeId] = result2;
|
---|
3494 | }
|
---|
3495 | });
|
---|
3496 | }
|
---|
3497 | }
|
---|
3498 | }
|
---|
3499 | async function resolveFetcherDeferredResults(matches, results, revalidatingFetchers) {
|
---|
3500 | for (let index = 0; index < revalidatingFetchers.length; index++) {
|
---|
3501 | let {
|
---|
3502 | key,
|
---|
3503 | routeId,
|
---|
3504 | controller
|
---|
3505 | } = revalidatingFetchers[index];
|
---|
3506 | let result = results[key];
|
---|
3507 | let match = matches.find((m) => (m == null ? void 0 : m.route.id) === routeId);
|
---|
3508 | if (!match) {
|
---|
3509 | continue;
|
---|
3510 | }
|
---|
3511 | if (isDeferredResult(result)) {
|
---|
3512 | invariant(controller, "Expected an AbortController for revalidating fetcher deferred result");
|
---|
3513 | await resolveDeferredData(result, controller.signal, true).then((result2) => {
|
---|
3514 | if (result2) {
|
---|
3515 | results[key] = result2;
|
---|
3516 | }
|
---|
3517 | });
|
---|
3518 | }
|
---|
3519 | }
|
---|
3520 | }
|
---|
3521 | async function resolveDeferredData(result, signal, unwrap) {
|
---|
3522 | if (unwrap === void 0) {
|
---|
3523 | unwrap = false;
|
---|
3524 | }
|
---|
3525 | let aborted = await result.deferredData.resolveData(signal);
|
---|
3526 | if (aborted) {
|
---|
3527 | return;
|
---|
3528 | }
|
---|
3529 | if (unwrap) {
|
---|
3530 | try {
|
---|
3531 | return {
|
---|
3532 | type: ResultType.data,
|
---|
3533 | data: result.deferredData.unwrappedData
|
---|
3534 | };
|
---|
3535 | } catch (e) {
|
---|
3536 | return {
|
---|
3537 | type: ResultType.error,
|
---|
3538 | error: e
|
---|
3539 | };
|
---|
3540 | }
|
---|
3541 | }
|
---|
3542 | return {
|
---|
3543 | type: ResultType.data,
|
---|
3544 | data: result.deferredData.data
|
---|
3545 | };
|
---|
3546 | }
|
---|
3547 | function hasNakedIndexQuery(search) {
|
---|
3548 | return new URLSearchParams(search).getAll("index").some((v) => v === "");
|
---|
3549 | }
|
---|
3550 | function getTargetMatch(matches, location) {
|
---|
3551 | let search = typeof location === "string" ? parsePath(location).search : location.search;
|
---|
3552 | if (matches[matches.length - 1].route.index && hasNakedIndexQuery(search || "")) {
|
---|
3553 | return matches[matches.length - 1];
|
---|
3554 | }
|
---|
3555 | let pathMatches = getPathContributingMatches(matches);
|
---|
3556 | return pathMatches[pathMatches.length - 1];
|
---|
3557 | }
|
---|
3558 | function getSubmissionFromNavigation(navigation) {
|
---|
3559 | let {
|
---|
3560 | formMethod,
|
---|
3561 | formAction,
|
---|
3562 | formEncType,
|
---|
3563 | text,
|
---|
3564 | formData,
|
---|
3565 | json: json3
|
---|
3566 | } = navigation;
|
---|
3567 | if (!formMethod || !formAction || !formEncType) {
|
---|
3568 | return;
|
---|
3569 | }
|
---|
3570 | if (text != null) {
|
---|
3571 | return {
|
---|
3572 | formMethod,
|
---|
3573 | formAction,
|
---|
3574 | formEncType,
|
---|
3575 | formData: void 0,
|
---|
3576 | json: void 0,
|
---|
3577 | text
|
---|
3578 | };
|
---|
3579 | } else if (formData != null) {
|
---|
3580 | return {
|
---|
3581 | formMethod,
|
---|
3582 | formAction,
|
---|
3583 | formEncType,
|
---|
3584 | formData,
|
---|
3585 | json: void 0,
|
---|
3586 | text: void 0
|
---|
3587 | };
|
---|
3588 | } else if (json3 !== void 0) {
|
---|
3589 | return {
|
---|
3590 | formMethod,
|
---|
3591 | formAction,
|
---|
3592 | formEncType,
|
---|
3593 | formData: void 0,
|
---|
3594 | json: json3,
|
---|
3595 | text: void 0
|
---|
3596 | };
|
---|
3597 | }
|
---|
3598 | }
|
---|
3599 | function getLoadingNavigation(location, submission) {
|
---|
3600 | if (submission) {
|
---|
3601 | let navigation = {
|
---|
3602 | state: "loading",
|
---|
3603 | location,
|
---|
3604 | formMethod: submission.formMethod,
|
---|
3605 | formAction: submission.formAction,
|
---|
3606 | formEncType: submission.formEncType,
|
---|
3607 | formData: submission.formData,
|
---|
3608 | json: submission.json,
|
---|
3609 | text: submission.text
|
---|
3610 | };
|
---|
3611 | return navigation;
|
---|
3612 | } else {
|
---|
3613 | let navigation = {
|
---|
3614 | state: "loading",
|
---|
3615 | location,
|
---|
3616 | formMethod: void 0,
|
---|
3617 | formAction: void 0,
|
---|
3618 | formEncType: void 0,
|
---|
3619 | formData: void 0,
|
---|
3620 | json: void 0,
|
---|
3621 | text: void 0
|
---|
3622 | };
|
---|
3623 | return navigation;
|
---|
3624 | }
|
---|
3625 | }
|
---|
3626 | function getSubmittingNavigation(location, submission) {
|
---|
3627 | let navigation = {
|
---|
3628 | state: "submitting",
|
---|
3629 | location,
|
---|
3630 | formMethod: submission.formMethod,
|
---|
3631 | formAction: submission.formAction,
|
---|
3632 | formEncType: submission.formEncType,
|
---|
3633 | formData: submission.formData,
|
---|
3634 | json: submission.json,
|
---|
3635 | text: submission.text
|
---|
3636 | };
|
---|
3637 | return navigation;
|
---|
3638 | }
|
---|
3639 | function getLoadingFetcher(submission, data) {
|
---|
3640 | if (submission) {
|
---|
3641 | let fetcher = {
|
---|
3642 | state: "loading",
|
---|
3643 | formMethod: submission.formMethod,
|
---|
3644 | formAction: submission.formAction,
|
---|
3645 | formEncType: submission.formEncType,
|
---|
3646 | formData: submission.formData,
|
---|
3647 | json: submission.json,
|
---|
3648 | text: submission.text,
|
---|
3649 | data
|
---|
3650 | };
|
---|
3651 | return fetcher;
|
---|
3652 | } else {
|
---|
3653 | let fetcher = {
|
---|
3654 | state: "loading",
|
---|
3655 | formMethod: void 0,
|
---|
3656 | formAction: void 0,
|
---|
3657 | formEncType: void 0,
|
---|
3658 | formData: void 0,
|
---|
3659 | json: void 0,
|
---|
3660 | text: void 0,
|
---|
3661 | data
|
---|
3662 | };
|
---|
3663 | return fetcher;
|
---|
3664 | }
|
---|
3665 | }
|
---|
3666 | function getSubmittingFetcher(submission, existingFetcher) {
|
---|
3667 | let fetcher = {
|
---|
3668 | state: "submitting",
|
---|
3669 | formMethod: submission.formMethod,
|
---|
3670 | formAction: submission.formAction,
|
---|
3671 | formEncType: submission.formEncType,
|
---|
3672 | formData: submission.formData,
|
---|
3673 | json: submission.json,
|
---|
3674 | text: submission.text,
|
---|
3675 | data: existingFetcher ? existingFetcher.data : void 0
|
---|
3676 | };
|
---|
3677 | return fetcher;
|
---|
3678 | }
|
---|
3679 | function getDoneFetcher(data) {
|
---|
3680 | let fetcher = {
|
---|
3681 | state: "idle",
|
---|
3682 | formMethod: void 0,
|
---|
3683 | formAction: void 0,
|
---|
3684 | formEncType: void 0,
|
---|
3685 | formData: void 0,
|
---|
3686 | json: void 0,
|
---|
3687 | text: void 0,
|
---|
3688 | data
|
---|
3689 | };
|
---|
3690 | return fetcher;
|
---|
3691 | }
|
---|
3692 | function restoreAppliedTransitions(_window, transitions) {
|
---|
3693 | try {
|
---|
3694 | let sessionPositions = _window.sessionStorage.getItem(TRANSITIONS_STORAGE_KEY);
|
---|
3695 | if (sessionPositions) {
|
---|
3696 | let json3 = JSON.parse(sessionPositions);
|
---|
3697 | for (let [k, v] of Object.entries(json3 || {})) {
|
---|
3698 | if (v && Array.isArray(v)) {
|
---|
3699 | transitions.set(k, new Set(v || []));
|
---|
3700 | }
|
---|
3701 | }
|
---|
3702 | }
|
---|
3703 | } catch (e) {
|
---|
3704 | }
|
---|
3705 | }
|
---|
3706 | function persistAppliedTransitions(_window, transitions) {
|
---|
3707 | if (transitions.size > 0) {
|
---|
3708 | let json3 = {};
|
---|
3709 | for (let [k, v] of transitions) {
|
---|
3710 | json3[k] = [...v];
|
---|
3711 | }
|
---|
3712 | try {
|
---|
3713 | _window.sessionStorage.setItem(TRANSITIONS_STORAGE_KEY, JSON.stringify(json3));
|
---|
3714 | } catch (error) {
|
---|
3715 | warning(false, "Failed to save applied view transitions in sessionStorage (" + error + ").");
|
---|
3716 | }
|
---|
3717 | }
|
---|
3718 | }
|
---|
3719 |
|
---|
3720 | // node_modules/react-router/dist/index.js
|
---|
3721 | function _extends2() {
|
---|
3722 | _extends2 = Object.assign ? Object.assign.bind() : function(target) {
|
---|
3723 | for (var i = 1; i < arguments.length; i++) {
|
---|
3724 | var source = arguments[i];
|
---|
3725 | for (var key in source) {
|
---|
3726 | if (Object.prototype.hasOwnProperty.call(source, key)) {
|
---|
3727 | target[key] = source[key];
|
---|
3728 | }
|
---|
3729 | }
|
---|
3730 | }
|
---|
3731 | return target;
|
---|
3732 | };
|
---|
3733 | return _extends2.apply(this, arguments);
|
---|
3734 | }
|
---|
3735 | var DataRouterContext = React.createContext(null);
|
---|
3736 | if (true) {
|
---|
3737 | DataRouterContext.displayName = "DataRouter";
|
---|
3738 | }
|
---|
3739 | var DataRouterStateContext = React.createContext(null);
|
---|
3740 | if (true) {
|
---|
3741 | DataRouterStateContext.displayName = "DataRouterState";
|
---|
3742 | }
|
---|
3743 | var AwaitContext = React.createContext(null);
|
---|
3744 | if (true) {
|
---|
3745 | AwaitContext.displayName = "Await";
|
---|
3746 | }
|
---|
3747 | var NavigationContext = React.createContext(null);
|
---|
3748 | if (true) {
|
---|
3749 | NavigationContext.displayName = "Navigation";
|
---|
3750 | }
|
---|
3751 | var LocationContext = React.createContext(null);
|
---|
3752 | if (true) {
|
---|
3753 | LocationContext.displayName = "Location";
|
---|
3754 | }
|
---|
3755 | var RouteContext = React.createContext({
|
---|
3756 | outlet: null,
|
---|
3757 | matches: [],
|
---|
3758 | isDataRoute: false
|
---|
3759 | });
|
---|
3760 | if (true) {
|
---|
3761 | RouteContext.displayName = "Route";
|
---|
3762 | }
|
---|
3763 | var RouteErrorContext = React.createContext(null);
|
---|
3764 | if (true) {
|
---|
3765 | RouteErrorContext.displayName = "RouteError";
|
---|
3766 | }
|
---|
3767 | function useHref(to, _temp) {
|
---|
3768 | let {
|
---|
3769 | relative
|
---|
3770 | } = _temp === void 0 ? {} : _temp;
|
---|
3771 | !useInRouterContext() ? true ? invariant(
|
---|
3772 | false,
|
---|
3773 | // TODO: This error is probably because they somehow have 2 versions of the
|
---|
3774 | // router loaded. We can help them understand how to avoid that.
|
---|
3775 | "useHref() may be used only in the context of a <Router> component."
|
---|
3776 | ) : invariant(false) : void 0;
|
---|
3777 | let {
|
---|
3778 | basename,
|
---|
3779 | navigator
|
---|
3780 | } = React.useContext(NavigationContext);
|
---|
3781 | let {
|
---|
3782 | hash,
|
---|
3783 | pathname,
|
---|
3784 | search
|
---|
3785 | } = useResolvedPath(to, {
|
---|
3786 | relative
|
---|
3787 | });
|
---|
3788 | let joinedPathname = pathname;
|
---|
3789 | if (basename !== "/") {
|
---|
3790 | joinedPathname = pathname === "/" ? basename : joinPaths([basename, pathname]);
|
---|
3791 | }
|
---|
3792 | return navigator.createHref({
|
---|
3793 | pathname: joinedPathname,
|
---|
3794 | search,
|
---|
3795 | hash
|
---|
3796 | });
|
---|
3797 | }
|
---|
3798 | function useInRouterContext() {
|
---|
3799 | return React.useContext(LocationContext) != null;
|
---|
3800 | }
|
---|
3801 | function useLocation() {
|
---|
3802 | !useInRouterContext() ? true ? invariant(
|
---|
3803 | false,
|
---|
3804 | // TODO: This error is probably because they somehow have 2 versions of the
|
---|
3805 | // router loaded. We can help them understand how to avoid that.
|
---|
3806 | "useLocation() may be used only in the context of a <Router> component."
|
---|
3807 | ) : invariant(false) : void 0;
|
---|
3808 | return React.useContext(LocationContext).location;
|
---|
3809 | }
|
---|
3810 | function useNavigationType() {
|
---|
3811 | return React.useContext(LocationContext).navigationType;
|
---|
3812 | }
|
---|
3813 | function useMatch(pattern) {
|
---|
3814 | !useInRouterContext() ? true ? invariant(
|
---|
3815 | false,
|
---|
3816 | // TODO: This error is probably because they somehow have 2 versions of the
|
---|
3817 | // router loaded. We can help them understand how to avoid that.
|
---|
3818 | "useMatch() may be used only in the context of a <Router> component."
|
---|
3819 | ) : invariant(false) : void 0;
|
---|
3820 | let {
|
---|
3821 | pathname
|
---|
3822 | } = useLocation();
|
---|
3823 | return React.useMemo(() => matchPath(pattern, decodePath(pathname)), [pathname, pattern]);
|
---|
3824 | }
|
---|
3825 | var navigateEffectWarning = "You should call navigate() in a React.useEffect(), not when your component is first rendered.";
|
---|
3826 | function useIsomorphicLayoutEffect(cb) {
|
---|
3827 | let isStatic = React.useContext(NavigationContext).static;
|
---|
3828 | if (!isStatic) {
|
---|
3829 | React.useLayoutEffect(cb);
|
---|
3830 | }
|
---|
3831 | }
|
---|
3832 | function useNavigate() {
|
---|
3833 | let {
|
---|
3834 | isDataRoute
|
---|
3835 | } = React.useContext(RouteContext);
|
---|
3836 | return isDataRoute ? useNavigateStable() : useNavigateUnstable();
|
---|
3837 | }
|
---|
3838 | function useNavigateUnstable() {
|
---|
3839 | !useInRouterContext() ? true ? invariant(
|
---|
3840 | false,
|
---|
3841 | // TODO: This error is probably because they somehow have 2 versions of the
|
---|
3842 | // router loaded. We can help them understand how to avoid that.
|
---|
3843 | "useNavigate() may be used only in the context of a <Router> component."
|
---|
3844 | ) : invariant(false) : void 0;
|
---|
3845 | let dataRouterContext = React.useContext(DataRouterContext);
|
---|
3846 | let {
|
---|
3847 | basename,
|
---|
3848 | future,
|
---|
3849 | navigator
|
---|
3850 | } = React.useContext(NavigationContext);
|
---|
3851 | let {
|
---|
3852 | matches
|
---|
3853 | } = React.useContext(RouteContext);
|
---|
3854 | let {
|
---|
3855 | pathname: locationPathname
|
---|
3856 | } = useLocation();
|
---|
3857 | let routePathnamesJson = JSON.stringify(getResolveToMatches(matches, future.v7_relativeSplatPath));
|
---|
3858 | let activeRef = React.useRef(false);
|
---|
3859 | useIsomorphicLayoutEffect(() => {
|
---|
3860 | activeRef.current = true;
|
---|
3861 | });
|
---|
3862 | let navigate = React.useCallback(function(to, options) {
|
---|
3863 | if (options === void 0) {
|
---|
3864 | options = {};
|
---|
3865 | }
|
---|
3866 | true ? warning(activeRef.current, navigateEffectWarning) : void 0;
|
---|
3867 | if (!activeRef.current) return;
|
---|
3868 | if (typeof to === "number") {
|
---|
3869 | navigator.go(to);
|
---|
3870 | return;
|
---|
3871 | }
|
---|
3872 | let path = resolveTo(to, JSON.parse(routePathnamesJson), locationPathname, options.relative === "path");
|
---|
3873 | if (dataRouterContext == null && basename !== "/") {
|
---|
3874 | path.pathname = path.pathname === "/" ? basename : joinPaths([basename, path.pathname]);
|
---|
3875 | }
|
---|
3876 | (!!options.replace ? navigator.replace : navigator.push)(path, options.state, options);
|
---|
3877 | }, [basename, navigator, routePathnamesJson, locationPathname, dataRouterContext]);
|
---|
3878 | return navigate;
|
---|
3879 | }
|
---|
3880 | var OutletContext = React.createContext(null);
|
---|
3881 | function useOutletContext() {
|
---|
3882 | return React.useContext(OutletContext);
|
---|
3883 | }
|
---|
3884 | function useOutlet(context) {
|
---|
3885 | let outlet = React.useContext(RouteContext).outlet;
|
---|
3886 | if (outlet) {
|
---|
3887 | return React.createElement(OutletContext.Provider, {
|
---|
3888 | value: context
|
---|
3889 | }, outlet);
|
---|
3890 | }
|
---|
3891 | return outlet;
|
---|
3892 | }
|
---|
3893 | function useParams() {
|
---|
3894 | let {
|
---|
3895 | matches
|
---|
3896 | } = React.useContext(RouteContext);
|
---|
3897 | let routeMatch = matches[matches.length - 1];
|
---|
3898 | return routeMatch ? routeMatch.params : {};
|
---|
3899 | }
|
---|
3900 | function useResolvedPath(to, _temp2) {
|
---|
3901 | let {
|
---|
3902 | relative
|
---|
3903 | } = _temp2 === void 0 ? {} : _temp2;
|
---|
3904 | let {
|
---|
3905 | future
|
---|
3906 | } = React.useContext(NavigationContext);
|
---|
3907 | let {
|
---|
3908 | matches
|
---|
3909 | } = React.useContext(RouteContext);
|
---|
3910 | let {
|
---|
3911 | pathname: locationPathname
|
---|
3912 | } = useLocation();
|
---|
3913 | let routePathnamesJson = JSON.stringify(getResolveToMatches(matches, future.v7_relativeSplatPath));
|
---|
3914 | return React.useMemo(() => resolveTo(to, JSON.parse(routePathnamesJson), locationPathname, relative === "path"), [to, routePathnamesJson, locationPathname, relative]);
|
---|
3915 | }
|
---|
3916 | function useRoutes(routes, locationArg) {
|
---|
3917 | return useRoutesImpl(routes, locationArg);
|
---|
3918 | }
|
---|
3919 | function useRoutesImpl(routes, locationArg, dataRouterState, future) {
|
---|
3920 | !useInRouterContext() ? true ? invariant(
|
---|
3921 | false,
|
---|
3922 | // TODO: This error is probably because they somehow have 2 versions of the
|
---|
3923 | // router loaded. We can help them understand how to avoid that.
|
---|
3924 | "useRoutes() may be used only in the context of a <Router> component."
|
---|
3925 | ) : invariant(false) : void 0;
|
---|
3926 | let {
|
---|
3927 | navigator
|
---|
3928 | } = React.useContext(NavigationContext);
|
---|
3929 | let {
|
---|
3930 | matches: parentMatches
|
---|
3931 | } = React.useContext(RouteContext);
|
---|
3932 | let routeMatch = parentMatches[parentMatches.length - 1];
|
---|
3933 | let parentParams = routeMatch ? routeMatch.params : {};
|
---|
3934 | let parentPathname = routeMatch ? routeMatch.pathname : "/";
|
---|
3935 | let parentPathnameBase = routeMatch ? routeMatch.pathnameBase : "/";
|
---|
3936 | let parentRoute = routeMatch && routeMatch.route;
|
---|
3937 | if (true) {
|
---|
3938 | let parentPath = parentRoute && parentRoute.path || "";
|
---|
3939 | warningOnce(parentPathname, !parentRoute || parentPath.endsWith("*"), "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.
|
---|
3940 |
|
---|
3941 | ` + ('Please change the parent <Route path="' + parentPath + '"> to <Route ') + ('path="' + (parentPath === "/" ? "*" : parentPath + "/*") + '">.'));
|
---|
3942 | }
|
---|
3943 | let locationFromContext = useLocation();
|
---|
3944 | let location;
|
---|
3945 | if (locationArg) {
|
---|
3946 | var _parsedLocationArg$pa;
|
---|
3947 | let parsedLocationArg = typeof locationArg === "string" ? parsePath(locationArg) : locationArg;
|
---|
3948 | !(parentPathnameBase === "/" || ((_parsedLocationArg$pa = parsedLocationArg.pathname) == null ? void 0 : _parsedLocationArg$pa.startsWith(parentPathnameBase))) ? true ? invariant(false, "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.')) : invariant(false) : void 0;
|
---|
3949 | location = parsedLocationArg;
|
---|
3950 | } else {
|
---|
3951 | location = locationFromContext;
|
---|
3952 | }
|
---|
3953 | let pathname = location.pathname || "/";
|
---|
3954 | let remainingPathname = pathname;
|
---|
3955 | if (parentPathnameBase !== "/") {
|
---|
3956 | let parentSegments = parentPathnameBase.replace(/^\//, "").split("/");
|
---|
3957 | let segments = pathname.replace(/^\//, "").split("/");
|
---|
3958 | remainingPathname = "/" + segments.slice(parentSegments.length).join("/");
|
---|
3959 | }
|
---|
3960 | let matches = matchRoutes(routes, {
|
---|
3961 | pathname: remainingPathname
|
---|
3962 | });
|
---|
3963 | if (true) {
|
---|
3964 | true ? warning(parentRoute || matches != null, 'No routes matched location "' + location.pathname + location.search + location.hash + '" ') : void 0;
|
---|
3965 | true ? warning(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, '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.') : void 0;
|
---|
3966 | }
|
---|
3967 | let renderedMatches = _renderMatches(matches && matches.map((match) => Object.assign({}, match, {
|
---|
3968 | params: Object.assign({}, parentParams, match.params),
|
---|
3969 | pathname: joinPaths([
|
---|
3970 | parentPathnameBase,
|
---|
3971 | // Re-encode pathnames that were decoded inside matchRoutes
|
---|
3972 | navigator.encodeLocation ? navigator.encodeLocation(match.pathname).pathname : match.pathname
|
---|
3973 | ]),
|
---|
3974 | pathnameBase: match.pathnameBase === "/" ? parentPathnameBase : joinPaths([
|
---|
3975 | parentPathnameBase,
|
---|
3976 | // Re-encode pathnames that were decoded inside matchRoutes
|
---|
3977 | navigator.encodeLocation ? navigator.encodeLocation(match.pathnameBase).pathname : match.pathnameBase
|
---|
3978 | ])
|
---|
3979 | })), parentMatches, dataRouterState, future);
|
---|
3980 | if (locationArg && renderedMatches) {
|
---|
3981 | return React.createElement(LocationContext.Provider, {
|
---|
3982 | value: {
|
---|
3983 | location: _extends2({
|
---|
3984 | pathname: "/",
|
---|
3985 | search: "",
|
---|
3986 | hash: "",
|
---|
3987 | state: null,
|
---|
3988 | key: "default"
|
---|
3989 | }, location),
|
---|
3990 | navigationType: Action.Pop
|
---|
3991 | }
|
---|
3992 | }, renderedMatches);
|
---|
3993 | }
|
---|
3994 | return renderedMatches;
|
---|
3995 | }
|
---|
3996 | function DefaultErrorComponent() {
|
---|
3997 | let error = useRouteError();
|
---|
3998 | let message = isRouteErrorResponse(error) ? error.status + " " + error.statusText : error instanceof Error ? error.message : JSON.stringify(error);
|
---|
3999 | let stack = error instanceof Error ? error.stack : null;
|
---|
4000 | let lightgrey = "rgba(200,200,200, 0.5)";
|
---|
4001 | let preStyles = {
|
---|
4002 | padding: "0.5rem",
|
---|
4003 | backgroundColor: lightgrey
|
---|
4004 | };
|
---|
4005 | let codeStyles = {
|
---|
4006 | padding: "2px 4px",
|
---|
4007 | backgroundColor: lightgrey
|
---|
4008 | };
|
---|
4009 | let devInfo = null;
|
---|
4010 | if (true) {
|
---|
4011 | console.error("Error handled by React Router default ErrorBoundary:", error);
|
---|
4012 | devInfo = React.createElement(React.Fragment, null, React.createElement("p", null, "💿 Hey developer 👋"), React.createElement("p", null, "You can provide a way better UX than this when your app throws errors by providing your own ", React.createElement("code", {
|
---|
4013 | style: codeStyles
|
---|
4014 | }, "ErrorBoundary"), " or", " ", React.createElement("code", {
|
---|
4015 | style: codeStyles
|
---|
4016 | }, "errorElement"), " prop on your route."));
|
---|
4017 | }
|
---|
4018 | return React.createElement(React.Fragment, null, React.createElement("h2", null, "Unexpected Application Error!"), React.createElement("h3", {
|
---|
4019 | style: {
|
---|
4020 | fontStyle: "italic"
|
---|
4021 | }
|
---|
4022 | }, message), stack ? React.createElement("pre", {
|
---|
4023 | style: preStyles
|
---|
4024 | }, stack) : null, devInfo);
|
---|
4025 | }
|
---|
4026 | var defaultErrorElement = React.createElement(DefaultErrorComponent, null);
|
---|
4027 | var RenderErrorBoundary = class extends React.Component {
|
---|
4028 | constructor(props) {
|
---|
4029 | super(props);
|
---|
4030 | this.state = {
|
---|
4031 | location: props.location,
|
---|
4032 | revalidation: props.revalidation,
|
---|
4033 | error: props.error
|
---|
4034 | };
|
---|
4035 | }
|
---|
4036 | static getDerivedStateFromError(error) {
|
---|
4037 | return {
|
---|
4038 | error
|
---|
4039 | };
|
---|
4040 | }
|
---|
4041 | static getDerivedStateFromProps(props, state) {
|
---|
4042 | if (state.location !== props.location || state.revalidation !== "idle" && props.revalidation === "idle") {
|
---|
4043 | return {
|
---|
4044 | error: props.error,
|
---|
4045 | location: props.location,
|
---|
4046 | revalidation: props.revalidation
|
---|
4047 | };
|
---|
4048 | }
|
---|
4049 | return {
|
---|
4050 | error: props.error !== void 0 ? props.error : state.error,
|
---|
4051 | location: state.location,
|
---|
4052 | revalidation: props.revalidation || state.revalidation
|
---|
4053 | };
|
---|
4054 | }
|
---|
4055 | componentDidCatch(error, errorInfo) {
|
---|
4056 | console.error("React Router caught the following error during render", error, errorInfo);
|
---|
4057 | }
|
---|
4058 | render() {
|
---|
4059 | return this.state.error !== void 0 ? React.createElement(RouteContext.Provider, {
|
---|
4060 | value: this.props.routeContext
|
---|
4061 | }, React.createElement(RouteErrorContext.Provider, {
|
---|
4062 | value: this.state.error,
|
---|
4063 | children: this.props.component
|
---|
4064 | })) : this.props.children;
|
---|
4065 | }
|
---|
4066 | };
|
---|
4067 | function RenderedRoute(_ref) {
|
---|
4068 | let {
|
---|
4069 | routeContext,
|
---|
4070 | match,
|
---|
4071 | children
|
---|
4072 | } = _ref;
|
---|
4073 | let dataRouterContext = React.useContext(DataRouterContext);
|
---|
4074 | if (dataRouterContext && dataRouterContext.static && dataRouterContext.staticContext && (match.route.errorElement || match.route.ErrorBoundary)) {
|
---|
4075 | dataRouterContext.staticContext._deepestRenderedBoundaryId = match.route.id;
|
---|
4076 | }
|
---|
4077 | return React.createElement(RouteContext.Provider, {
|
---|
4078 | value: routeContext
|
---|
4079 | }, children);
|
---|
4080 | }
|
---|
4081 | function _renderMatches(matches, parentMatches, dataRouterState, future) {
|
---|
4082 | var _dataRouterState;
|
---|
4083 | if (parentMatches === void 0) {
|
---|
4084 | parentMatches = [];
|
---|
4085 | }
|
---|
4086 | if (dataRouterState === void 0) {
|
---|
4087 | dataRouterState = null;
|
---|
4088 | }
|
---|
4089 | if (future === void 0) {
|
---|
4090 | future = null;
|
---|
4091 | }
|
---|
4092 | if (matches == null) {
|
---|
4093 | var _future;
|
---|
4094 | if (!dataRouterState) {
|
---|
4095 | return null;
|
---|
4096 | }
|
---|
4097 | if (dataRouterState.errors) {
|
---|
4098 | matches = dataRouterState.matches;
|
---|
4099 | } else if ((_future = future) != null && _future.v7_partialHydration && parentMatches.length === 0 && !dataRouterState.initialized && dataRouterState.matches.length > 0) {
|
---|
4100 | matches = dataRouterState.matches;
|
---|
4101 | } else {
|
---|
4102 | return null;
|
---|
4103 | }
|
---|
4104 | }
|
---|
4105 | let renderedMatches = matches;
|
---|
4106 | let errors = (_dataRouterState = dataRouterState) == null ? void 0 : _dataRouterState.errors;
|
---|
4107 | if (errors != null) {
|
---|
4108 | let errorIndex = renderedMatches.findIndex((m) => m.route.id && (errors == null ? void 0 : errors[m.route.id]) !== void 0);
|
---|
4109 | !(errorIndex >= 0) ? true ? invariant(false, "Could not find a matching route for errors on route IDs: " + Object.keys(errors).join(",")) : invariant(false) : void 0;
|
---|
4110 | renderedMatches = renderedMatches.slice(0, Math.min(renderedMatches.length, errorIndex + 1));
|
---|
4111 | }
|
---|
4112 | let renderFallback = false;
|
---|
4113 | let fallbackIndex = -1;
|
---|
4114 | if (dataRouterState && future && future.v7_partialHydration) {
|
---|
4115 | for (let i = 0; i < renderedMatches.length; i++) {
|
---|
4116 | let match = renderedMatches[i];
|
---|
4117 | if (match.route.HydrateFallback || match.route.hydrateFallbackElement) {
|
---|
4118 | fallbackIndex = i;
|
---|
4119 | }
|
---|
4120 | if (match.route.id) {
|
---|
4121 | let {
|
---|
4122 | loaderData,
|
---|
4123 | errors: errors2
|
---|
4124 | } = dataRouterState;
|
---|
4125 | let needsToRunLoader = match.route.loader && loaderData[match.route.id] === void 0 && (!errors2 || errors2[match.route.id] === void 0);
|
---|
4126 | if (match.route.lazy || needsToRunLoader) {
|
---|
4127 | renderFallback = true;
|
---|
4128 | if (fallbackIndex >= 0) {
|
---|
4129 | renderedMatches = renderedMatches.slice(0, fallbackIndex + 1);
|
---|
4130 | } else {
|
---|
4131 | renderedMatches = [renderedMatches[0]];
|
---|
4132 | }
|
---|
4133 | break;
|
---|
4134 | }
|
---|
4135 | }
|
---|
4136 | }
|
---|
4137 | }
|
---|
4138 | return renderedMatches.reduceRight((outlet, match, index) => {
|
---|
4139 | let error;
|
---|
4140 | let shouldRenderHydrateFallback = false;
|
---|
4141 | let errorElement = null;
|
---|
4142 | let hydrateFallbackElement = null;
|
---|
4143 | if (dataRouterState) {
|
---|
4144 | error = errors && match.route.id ? errors[match.route.id] : void 0;
|
---|
4145 | errorElement = match.route.errorElement || defaultErrorElement;
|
---|
4146 | if (renderFallback) {
|
---|
4147 | if (fallbackIndex < 0 && index === 0) {
|
---|
4148 | warningOnce("route-fallback", false, "No `HydrateFallback` element provided to render during initial hydration");
|
---|
4149 | shouldRenderHydrateFallback = true;
|
---|
4150 | hydrateFallbackElement = null;
|
---|
4151 | } else if (fallbackIndex === index) {
|
---|
4152 | shouldRenderHydrateFallback = true;
|
---|
4153 | hydrateFallbackElement = match.route.hydrateFallbackElement || null;
|
---|
4154 | }
|
---|
4155 | }
|
---|
4156 | }
|
---|
4157 | let matches2 = parentMatches.concat(renderedMatches.slice(0, index + 1));
|
---|
4158 | let getChildren = () => {
|
---|
4159 | let children;
|
---|
4160 | if (error) {
|
---|
4161 | children = errorElement;
|
---|
4162 | } else if (shouldRenderHydrateFallback) {
|
---|
4163 | children = hydrateFallbackElement;
|
---|
4164 | } else if (match.route.Component) {
|
---|
4165 | children = React.createElement(match.route.Component, null);
|
---|
4166 | } else if (match.route.element) {
|
---|
4167 | children = match.route.element;
|
---|
4168 | } else {
|
---|
4169 | children = outlet;
|
---|
4170 | }
|
---|
4171 | return React.createElement(RenderedRoute, {
|
---|
4172 | match,
|
---|
4173 | routeContext: {
|
---|
4174 | outlet,
|
---|
4175 | matches: matches2,
|
---|
4176 | isDataRoute: dataRouterState != null
|
---|
4177 | },
|
---|
4178 | children
|
---|
4179 | });
|
---|
4180 | };
|
---|
4181 | return dataRouterState && (match.route.ErrorBoundary || match.route.errorElement || index === 0) ? React.createElement(RenderErrorBoundary, {
|
---|
4182 | location: dataRouterState.location,
|
---|
4183 | revalidation: dataRouterState.revalidation,
|
---|
4184 | component: errorElement,
|
---|
4185 | error,
|
---|
4186 | children: getChildren(),
|
---|
4187 | routeContext: {
|
---|
4188 | outlet: null,
|
---|
4189 | matches: matches2,
|
---|
4190 | isDataRoute: true
|
---|
4191 | }
|
---|
4192 | }) : getChildren();
|
---|
4193 | }, null);
|
---|
4194 | }
|
---|
4195 | var DataRouterHook = function(DataRouterHook3) {
|
---|
4196 | DataRouterHook3["UseBlocker"] = "useBlocker";
|
---|
4197 | DataRouterHook3["UseRevalidator"] = "useRevalidator";
|
---|
4198 | DataRouterHook3["UseNavigateStable"] = "useNavigate";
|
---|
4199 | return DataRouterHook3;
|
---|
4200 | }(DataRouterHook || {});
|
---|
4201 | var DataRouterStateHook = function(DataRouterStateHook3) {
|
---|
4202 | DataRouterStateHook3["UseBlocker"] = "useBlocker";
|
---|
4203 | DataRouterStateHook3["UseLoaderData"] = "useLoaderData";
|
---|
4204 | DataRouterStateHook3["UseActionData"] = "useActionData";
|
---|
4205 | DataRouterStateHook3["UseRouteError"] = "useRouteError";
|
---|
4206 | DataRouterStateHook3["UseNavigation"] = "useNavigation";
|
---|
4207 | DataRouterStateHook3["UseRouteLoaderData"] = "useRouteLoaderData";
|
---|
4208 | DataRouterStateHook3["UseMatches"] = "useMatches";
|
---|
4209 | DataRouterStateHook3["UseRevalidator"] = "useRevalidator";
|
---|
4210 | DataRouterStateHook3["UseNavigateStable"] = "useNavigate";
|
---|
4211 | DataRouterStateHook3["UseRouteId"] = "useRouteId";
|
---|
4212 | return DataRouterStateHook3;
|
---|
4213 | }(DataRouterStateHook || {});
|
---|
4214 | function getDataRouterConsoleError(hookName) {
|
---|
4215 | return hookName + " must be used within a data router. See https://reactrouter.com/v6/routers/picking-a-router.";
|
---|
4216 | }
|
---|
4217 | function useDataRouterContext(hookName) {
|
---|
4218 | let ctx = React.useContext(DataRouterContext);
|
---|
4219 | !ctx ? true ? invariant(false, getDataRouterConsoleError(hookName)) : invariant(false) : void 0;
|
---|
4220 | return ctx;
|
---|
4221 | }
|
---|
4222 | function useDataRouterState(hookName) {
|
---|
4223 | let state = React.useContext(DataRouterStateContext);
|
---|
4224 | !state ? true ? invariant(false, getDataRouterConsoleError(hookName)) : invariant(false) : void 0;
|
---|
4225 | return state;
|
---|
4226 | }
|
---|
4227 | function useRouteContext(hookName) {
|
---|
4228 | let route = React.useContext(RouteContext);
|
---|
4229 | !route ? true ? invariant(false, getDataRouterConsoleError(hookName)) : invariant(false) : void 0;
|
---|
4230 | return route;
|
---|
4231 | }
|
---|
4232 | function useCurrentRouteId(hookName) {
|
---|
4233 | let route = useRouteContext(hookName);
|
---|
4234 | let thisRoute = route.matches[route.matches.length - 1];
|
---|
4235 | !thisRoute.route.id ? true ? invariant(false, hookName + ' can only be used on routes that contain a unique "id"') : invariant(false) : void 0;
|
---|
4236 | return thisRoute.route.id;
|
---|
4237 | }
|
---|
4238 | function useRouteId() {
|
---|
4239 | return useCurrentRouteId(DataRouterStateHook.UseRouteId);
|
---|
4240 | }
|
---|
4241 | function useNavigation() {
|
---|
4242 | let state = useDataRouterState(DataRouterStateHook.UseNavigation);
|
---|
4243 | return state.navigation;
|
---|
4244 | }
|
---|
4245 | function useRevalidator() {
|
---|
4246 | let dataRouterContext = useDataRouterContext(DataRouterHook.UseRevalidator);
|
---|
4247 | let state = useDataRouterState(DataRouterStateHook.UseRevalidator);
|
---|
4248 | return React.useMemo(() => ({
|
---|
4249 | revalidate: dataRouterContext.router.revalidate,
|
---|
4250 | state: state.revalidation
|
---|
4251 | }), [dataRouterContext.router.revalidate, state.revalidation]);
|
---|
4252 | }
|
---|
4253 | function useMatches() {
|
---|
4254 | let {
|
---|
4255 | matches,
|
---|
4256 | loaderData
|
---|
4257 | } = useDataRouterState(DataRouterStateHook.UseMatches);
|
---|
4258 | return React.useMemo(() => matches.map((m) => convertRouteMatchToUiMatch(m, loaderData)), [matches, loaderData]);
|
---|
4259 | }
|
---|
4260 | function useLoaderData() {
|
---|
4261 | let state = useDataRouterState(DataRouterStateHook.UseLoaderData);
|
---|
4262 | let routeId = useCurrentRouteId(DataRouterStateHook.UseLoaderData);
|
---|
4263 | if (state.errors && state.errors[routeId] != null) {
|
---|
4264 | console.error("You cannot `useLoaderData` in an errorElement (routeId: " + routeId + ")");
|
---|
4265 | return void 0;
|
---|
4266 | }
|
---|
4267 | return state.loaderData[routeId];
|
---|
4268 | }
|
---|
4269 | function useRouteLoaderData(routeId) {
|
---|
4270 | let state = useDataRouterState(DataRouterStateHook.UseRouteLoaderData);
|
---|
4271 | return state.loaderData[routeId];
|
---|
4272 | }
|
---|
4273 | function useActionData() {
|
---|
4274 | let state = useDataRouterState(DataRouterStateHook.UseActionData);
|
---|
4275 | let routeId = useCurrentRouteId(DataRouterStateHook.UseLoaderData);
|
---|
4276 | return state.actionData ? state.actionData[routeId] : void 0;
|
---|
4277 | }
|
---|
4278 | function useRouteError() {
|
---|
4279 | var _state$errors;
|
---|
4280 | let error = React.useContext(RouteErrorContext);
|
---|
4281 | let state = useDataRouterState(DataRouterStateHook.UseRouteError);
|
---|
4282 | let routeId = useCurrentRouteId(DataRouterStateHook.UseRouteError);
|
---|
4283 | if (error !== void 0) {
|
---|
4284 | return error;
|
---|
4285 | }
|
---|
4286 | return (_state$errors = state.errors) == null ? void 0 : _state$errors[routeId];
|
---|
4287 | }
|
---|
4288 | function useAsyncValue() {
|
---|
4289 | let value = React.useContext(AwaitContext);
|
---|
4290 | return value == null ? void 0 : value._data;
|
---|
4291 | }
|
---|
4292 | function useAsyncError() {
|
---|
4293 | let value = React.useContext(AwaitContext);
|
---|
4294 | return value == null ? void 0 : value._error;
|
---|
4295 | }
|
---|
4296 | var blockerId = 0;
|
---|
4297 | function useBlocker(shouldBlock) {
|
---|
4298 | let {
|
---|
4299 | router,
|
---|
4300 | basename
|
---|
4301 | } = useDataRouterContext(DataRouterHook.UseBlocker);
|
---|
4302 | let state = useDataRouterState(DataRouterStateHook.UseBlocker);
|
---|
4303 | let [blockerKey, setBlockerKey] = React.useState("");
|
---|
4304 | let blockerFunction = React.useCallback((arg) => {
|
---|
4305 | if (typeof shouldBlock !== "function") {
|
---|
4306 | return !!shouldBlock;
|
---|
4307 | }
|
---|
4308 | if (basename === "/") {
|
---|
4309 | return shouldBlock(arg);
|
---|
4310 | }
|
---|
4311 | let {
|
---|
4312 | currentLocation,
|
---|
4313 | nextLocation,
|
---|
4314 | historyAction
|
---|
4315 | } = arg;
|
---|
4316 | return shouldBlock({
|
---|
4317 | currentLocation: _extends2({}, currentLocation, {
|
---|
4318 | pathname: stripBasename(currentLocation.pathname, basename) || currentLocation.pathname
|
---|
4319 | }),
|
---|
4320 | nextLocation: _extends2({}, nextLocation, {
|
---|
4321 | pathname: stripBasename(nextLocation.pathname, basename) || nextLocation.pathname
|
---|
4322 | }),
|
---|
4323 | historyAction
|
---|
4324 | });
|
---|
4325 | }, [basename, shouldBlock]);
|
---|
4326 | React.useEffect(() => {
|
---|
4327 | let key = String(++blockerId);
|
---|
4328 | setBlockerKey(key);
|
---|
4329 | return () => router.deleteBlocker(key);
|
---|
4330 | }, [router]);
|
---|
4331 | React.useEffect(() => {
|
---|
4332 | if (blockerKey !== "") {
|
---|
4333 | router.getBlocker(blockerKey, blockerFunction);
|
---|
4334 | }
|
---|
4335 | }, [router, blockerKey, blockerFunction]);
|
---|
4336 | return blockerKey && state.blockers.has(blockerKey) ? state.blockers.get(blockerKey) : IDLE_BLOCKER;
|
---|
4337 | }
|
---|
4338 | function useNavigateStable() {
|
---|
4339 | let {
|
---|
4340 | router
|
---|
4341 | } = useDataRouterContext(DataRouterHook.UseNavigateStable);
|
---|
4342 | let id = useCurrentRouteId(DataRouterStateHook.UseNavigateStable);
|
---|
4343 | let activeRef = React.useRef(false);
|
---|
4344 | useIsomorphicLayoutEffect(() => {
|
---|
4345 | activeRef.current = true;
|
---|
4346 | });
|
---|
4347 | let navigate = React.useCallback(function(to, options) {
|
---|
4348 | if (options === void 0) {
|
---|
4349 | options = {};
|
---|
4350 | }
|
---|
4351 | true ? warning(activeRef.current, navigateEffectWarning) : void 0;
|
---|
4352 | if (!activeRef.current) return;
|
---|
4353 | if (typeof to === "number") {
|
---|
4354 | router.navigate(to);
|
---|
4355 | } else {
|
---|
4356 | router.navigate(to, _extends2({
|
---|
4357 | fromRouteId: id
|
---|
4358 | }, options));
|
---|
4359 | }
|
---|
4360 | }, [router, id]);
|
---|
4361 | return navigate;
|
---|
4362 | }
|
---|
4363 | var alreadyWarned$1 = {};
|
---|
4364 | function warningOnce(key, cond, message) {
|
---|
4365 | if (!cond && !alreadyWarned$1[key]) {
|
---|
4366 | alreadyWarned$1[key] = true;
|
---|
4367 | true ? warning(false, message) : void 0;
|
---|
4368 | }
|
---|
4369 | }
|
---|
4370 | var alreadyWarned = {};
|
---|
4371 | function warnOnce(key, message) {
|
---|
4372 | if (!alreadyWarned[message]) {
|
---|
4373 | alreadyWarned[message] = true;
|
---|
4374 | console.warn(message);
|
---|
4375 | }
|
---|
4376 | }
|
---|
4377 | var logDeprecation = (flag, msg, link) => warnOnce(flag, "⚠️ React Router Future Flag Warning: " + msg + ". " + ("You can use the `" + flag + "` future flag to opt-in early. ") + ("For more information, see " + link + "."));
|
---|
4378 | function logV6DeprecationWarnings(renderFuture, routerFuture) {
|
---|
4379 | if (!(renderFuture != null && renderFuture.v7_startTransition)) {
|
---|
4380 | logDeprecation("v7_startTransition", "React Router will begin wrapping state updates in `React.startTransition` in v7", "https://reactrouter.com/v6/upgrading/future#v7_starttransition");
|
---|
4381 | }
|
---|
4382 | if (!(renderFuture != null && renderFuture.v7_relativeSplatPath) && (!routerFuture || !routerFuture.v7_relativeSplatPath)) {
|
---|
4383 | logDeprecation("v7_relativeSplatPath", "Relative route resolution within Splat routes is changing in v7", "https://reactrouter.com/v6/upgrading/future#v7_relativesplatpath");
|
---|
4384 | }
|
---|
4385 | if (routerFuture) {
|
---|
4386 | if (!routerFuture.v7_fetcherPersist) {
|
---|
4387 | logDeprecation("v7_fetcherPersist", "The persistence behavior of fetchers is changing in v7", "https://reactrouter.com/v6/upgrading/future#v7_fetcherpersist");
|
---|
4388 | }
|
---|
4389 | if (!routerFuture.v7_normalizeFormMethod) {
|
---|
4390 | logDeprecation("v7_normalizeFormMethod", "Casing of `formMethod` fields is being normalized to uppercase in v7", "https://reactrouter.com/v6/upgrading/future#v7_normalizeformmethod");
|
---|
4391 | }
|
---|
4392 | if (!routerFuture.v7_partialHydration) {
|
---|
4393 | logDeprecation("v7_partialHydration", "`RouterProvider` hydration behavior is changing in v7", "https://reactrouter.com/v6/upgrading/future#v7_partialhydration");
|
---|
4394 | }
|
---|
4395 | if (!routerFuture.v7_skipActionErrorRevalidation) {
|
---|
4396 | logDeprecation("v7_skipActionErrorRevalidation", "The revalidation behavior after 4xx/5xx `action` responses is changing in v7", "https://reactrouter.com/v6/upgrading/future#v7_skipactionerrorrevalidation");
|
---|
4397 | }
|
---|
4398 | }
|
---|
4399 | }
|
---|
4400 | var START_TRANSITION = "startTransition";
|
---|
4401 | var startTransitionImpl = React[START_TRANSITION];
|
---|
4402 | function MemoryRouter(_ref3) {
|
---|
4403 | let {
|
---|
4404 | basename,
|
---|
4405 | children,
|
---|
4406 | initialEntries,
|
---|
4407 | initialIndex,
|
---|
4408 | future
|
---|
4409 | } = _ref3;
|
---|
4410 | let historyRef = React.useRef();
|
---|
4411 | if (historyRef.current == null) {
|
---|
4412 | historyRef.current = createMemoryHistory({
|
---|
4413 | initialEntries,
|
---|
4414 | initialIndex,
|
---|
4415 | v5Compat: true
|
---|
4416 | });
|
---|
4417 | }
|
---|
4418 | let history = historyRef.current;
|
---|
4419 | let [state, setStateImpl] = React.useState({
|
---|
4420 | action: history.action,
|
---|
4421 | location: history.location
|
---|
4422 | });
|
---|
4423 | let {
|
---|
4424 | v7_startTransition
|
---|
4425 | } = future || {};
|
---|
4426 | let setState = React.useCallback((newState) => {
|
---|
4427 | v7_startTransition && startTransitionImpl ? startTransitionImpl(() => setStateImpl(newState)) : setStateImpl(newState);
|
---|
4428 | }, [setStateImpl, v7_startTransition]);
|
---|
4429 | React.useLayoutEffect(() => history.listen(setState), [history, setState]);
|
---|
4430 | React.useEffect(() => logV6DeprecationWarnings(future), [future]);
|
---|
4431 | return React.createElement(Router, {
|
---|
4432 | basename,
|
---|
4433 | children,
|
---|
4434 | location: state.location,
|
---|
4435 | navigationType: state.action,
|
---|
4436 | navigator: history,
|
---|
4437 | future
|
---|
4438 | });
|
---|
4439 | }
|
---|
4440 | function Navigate(_ref4) {
|
---|
4441 | let {
|
---|
4442 | to,
|
---|
4443 | replace: replace2,
|
---|
4444 | state,
|
---|
4445 | relative
|
---|
4446 | } = _ref4;
|
---|
4447 | !useInRouterContext() ? true ? invariant(
|
---|
4448 | false,
|
---|
4449 | // TODO: This error is probably because they somehow have 2 versions of
|
---|
4450 | // the router loaded. We can help them understand how to avoid that.
|
---|
4451 | "<Navigate> may be used only in the context of a <Router> component."
|
---|
4452 | ) : invariant(false) : void 0;
|
---|
4453 | let {
|
---|
4454 | future,
|
---|
4455 | static: isStatic
|
---|
4456 | } = React.useContext(NavigationContext);
|
---|
4457 | true ? warning(!isStatic, "<Navigate> must not be used on the initial render in a <StaticRouter>. This is a no-op, but you should modify your code so the <Navigate> is only ever rendered in response to some user interaction or state change.") : void 0;
|
---|
4458 | let {
|
---|
4459 | matches
|
---|
4460 | } = React.useContext(RouteContext);
|
---|
4461 | let {
|
---|
4462 | pathname: locationPathname
|
---|
4463 | } = useLocation();
|
---|
4464 | let navigate = useNavigate();
|
---|
4465 | let path = resolveTo(to, getResolveToMatches(matches, future.v7_relativeSplatPath), locationPathname, relative === "path");
|
---|
4466 | let jsonPath = JSON.stringify(path);
|
---|
4467 | React.useEffect(() => navigate(JSON.parse(jsonPath), {
|
---|
4468 | replace: replace2,
|
---|
4469 | state,
|
---|
4470 | relative
|
---|
4471 | }), [navigate, jsonPath, relative, replace2, state]);
|
---|
4472 | return null;
|
---|
4473 | }
|
---|
4474 | function Outlet(props) {
|
---|
4475 | return useOutlet(props.context);
|
---|
4476 | }
|
---|
4477 | function Route(_props) {
|
---|
4478 | true ? invariant(false, "A <Route> is only ever to be used as the child of <Routes> element, never rendered directly. Please wrap your <Route> in a <Routes>.") : invariant(false);
|
---|
4479 | }
|
---|
4480 | function Router(_ref5) {
|
---|
4481 | let {
|
---|
4482 | basename: basenameProp = "/",
|
---|
4483 | children = null,
|
---|
4484 | location: locationProp,
|
---|
4485 | navigationType = Action.Pop,
|
---|
4486 | navigator,
|
---|
4487 | static: staticProp = false,
|
---|
4488 | future
|
---|
4489 | } = _ref5;
|
---|
4490 | !!useInRouterContext() ? true ? invariant(false, "You cannot render a <Router> inside another <Router>. You should never have more than one in your app.") : invariant(false) : void 0;
|
---|
4491 | let basename = basenameProp.replace(/^\/*/, "/");
|
---|
4492 | let navigationContext = React.useMemo(() => ({
|
---|
4493 | basename,
|
---|
4494 | navigator,
|
---|
4495 | static: staticProp,
|
---|
4496 | future: _extends2({
|
---|
4497 | v7_relativeSplatPath: false
|
---|
4498 | }, future)
|
---|
4499 | }), [basename, future, navigator, staticProp]);
|
---|
4500 | if (typeof locationProp === "string") {
|
---|
4501 | locationProp = parsePath(locationProp);
|
---|
4502 | }
|
---|
4503 | let {
|
---|
4504 | pathname = "/",
|
---|
4505 | search = "",
|
---|
4506 | hash = "",
|
---|
4507 | state = null,
|
---|
4508 | key = "default"
|
---|
4509 | } = locationProp;
|
---|
4510 | let locationContext = React.useMemo(() => {
|
---|
4511 | let trailingPathname = stripBasename(pathname, basename);
|
---|
4512 | if (trailingPathname == null) {
|
---|
4513 | return null;
|
---|
4514 | }
|
---|
4515 | return {
|
---|
4516 | location: {
|
---|
4517 | pathname: trailingPathname,
|
---|
4518 | search,
|
---|
4519 | hash,
|
---|
4520 | state,
|
---|
4521 | key
|
---|
4522 | },
|
---|
4523 | navigationType
|
---|
4524 | };
|
---|
4525 | }, [basename, pathname, search, hash, state, key, navigationType]);
|
---|
4526 | true ? warning(locationContext != null, '<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.") : void 0;
|
---|
4527 | if (locationContext == null) {
|
---|
4528 | return null;
|
---|
4529 | }
|
---|
4530 | return React.createElement(NavigationContext.Provider, {
|
---|
4531 | value: navigationContext
|
---|
4532 | }, React.createElement(LocationContext.Provider, {
|
---|
4533 | children,
|
---|
4534 | value: locationContext
|
---|
4535 | }));
|
---|
4536 | }
|
---|
4537 | function Routes(_ref6) {
|
---|
4538 | let {
|
---|
4539 | children,
|
---|
4540 | location
|
---|
4541 | } = _ref6;
|
---|
4542 | return useRoutes(createRoutesFromChildren(children), location);
|
---|
4543 | }
|
---|
4544 | function Await(_ref7) {
|
---|
4545 | let {
|
---|
4546 | children,
|
---|
4547 | errorElement,
|
---|
4548 | resolve
|
---|
4549 | } = _ref7;
|
---|
4550 | return React.createElement(AwaitErrorBoundary, {
|
---|
4551 | resolve,
|
---|
4552 | errorElement
|
---|
4553 | }, React.createElement(ResolveAwait, null, children));
|
---|
4554 | }
|
---|
4555 | var AwaitRenderStatus = function(AwaitRenderStatus2) {
|
---|
4556 | AwaitRenderStatus2[AwaitRenderStatus2["pending"] = 0] = "pending";
|
---|
4557 | AwaitRenderStatus2[AwaitRenderStatus2["success"] = 1] = "success";
|
---|
4558 | AwaitRenderStatus2[AwaitRenderStatus2["error"] = 2] = "error";
|
---|
4559 | return AwaitRenderStatus2;
|
---|
4560 | }(AwaitRenderStatus || {});
|
---|
4561 | var neverSettledPromise = new Promise(() => {
|
---|
4562 | });
|
---|
4563 | var AwaitErrorBoundary = class extends React.Component {
|
---|
4564 | constructor(props) {
|
---|
4565 | super(props);
|
---|
4566 | this.state = {
|
---|
4567 | error: null
|
---|
4568 | };
|
---|
4569 | }
|
---|
4570 | static getDerivedStateFromError(error) {
|
---|
4571 | return {
|
---|
4572 | error
|
---|
4573 | };
|
---|
4574 | }
|
---|
4575 | componentDidCatch(error, errorInfo) {
|
---|
4576 | console.error("<Await> caught the following error during render", error, errorInfo);
|
---|
4577 | }
|
---|
4578 | render() {
|
---|
4579 | let {
|
---|
4580 | children,
|
---|
4581 | errorElement,
|
---|
4582 | resolve
|
---|
4583 | } = this.props;
|
---|
4584 | let promise = null;
|
---|
4585 | let status = AwaitRenderStatus.pending;
|
---|
4586 | if (!(resolve instanceof Promise)) {
|
---|
4587 | status = AwaitRenderStatus.success;
|
---|
4588 | promise = Promise.resolve();
|
---|
4589 | Object.defineProperty(promise, "_tracked", {
|
---|
4590 | get: () => true
|
---|
4591 | });
|
---|
4592 | Object.defineProperty(promise, "_data", {
|
---|
4593 | get: () => resolve
|
---|
4594 | });
|
---|
4595 | } else if (this.state.error) {
|
---|
4596 | status = AwaitRenderStatus.error;
|
---|
4597 | let renderError = this.state.error;
|
---|
4598 | promise = Promise.reject().catch(() => {
|
---|
4599 | });
|
---|
4600 | Object.defineProperty(promise, "_tracked", {
|
---|
4601 | get: () => true
|
---|
4602 | });
|
---|
4603 | Object.defineProperty(promise, "_error", {
|
---|
4604 | get: () => renderError
|
---|
4605 | });
|
---|
4606 | } else if (resolve._tracked) {
|
---|
4607 | promise = resolve;
|
---|
4608 | status = "_error" in promise ? AwaitRenderStatus.error : "_data" in promise ? AwaitRenderStatus.success : AwaitRenderStatus.pending;
|
---|
4609 | } else {
|
---|
4610 | status = AwaitRenderStatus.pending;
|
---|
4611 | Object.defineProperty(resolve, "_tracked", {
|
---|
4612 | get: () => true
|
---|
4613 | });
|
---|
4614 | promise = resolve.then((data) => Object.defineProperty(resolve, "_data", {
|
---|
4615 | get: () => data
|
---|
4616 | }), (error) => Object.defineProperty(resolve, "_error", {
|
---|
4617 | get: () => error
|
---|
4618 | }));
|
---|
4619 | }
|
---|
4620 | if (status === AwaitRenderStatus.error && promise._error instanceof AbortedDeferredError) {
|
---|
4621 | throw neverSettledPromise;
|
---|
4622 | }
|
---|
4623 | if (status === AwaitRenderStatus.error && !errorElement) {
|
---|
4624 | throw promise._error;
|
---|
4625 | }
|
---|
4626 | if (status === AwaitRenderStatus.error) {
|
---|
4627 | return React.createElement(AwaitContext.Provider, {
|
---|
4628 | value: promise,
|
---|
4629 | children: errorElement
|
---|
4630 | });
|
---|
4631 | }
|
---|
4632 | if (status === AwaitRenderStatus.success) {
|
---|
4633 | return React.createElement(AwaitContext.Provider, {
|
---|
4634 | value: promise,
|
---|
4635 | children
|
---|
4636 | });
|
---|
4637 | }
|
---|
4638 | throw promise;
|
---|
4639 | }
|
---|
4640 | };
|
---|
4641 | function ResolveAwait(_ref8) {
|
---|
4642 | let {
|
---|
4643 | children
|
---|
4644 | } = _ref8;
|
---|
4645 | let data = useAsyncValue();
|
---|
4646 | let toRender = typeof children === "function" ? children(data) : children;
|
---|
4647 | return React.createElement(React.Fragment, null, toRender);
|
---|
4648 | }
|
---|
4649 | function createRoutesFromChildren(children, parentPath) {
|
---|
4650 | if (parentPath === void 0) {
|
---|
4651 | parentPath = [];
|
---|
4652 | }
|
---|
4653 | let routes = [];
|
---|
4654 | React.Children.forEach(children, (element, index) => {
|
---|
4655 | if (!React.isValidElement(element)) {
|
---|
4656 | return;
|
---|
4657 | }
|
---|
4658 | let treePath = [...parentPath, index];
|
---|
4659 | if (element.type === React.Fragment) {
|
---|
4660 | routes.push.apply(routes, createRoutesFromChildren(element.props.children, treePath));
|
---|
4661 | return;
|
---|
4662 | }
|
---|
4663 | !(element.type === Route) ? true ? invariant(false, "[" + (typeof element.type === "string" ? element.type : element.type.name) + "] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>") : invariant(false) : void 0;
|
---|
4664 | !(!element.props.index || !element.props.children) ? true ? invariant(false, "An index route cannot have child routes.") : invariant(false) : void 0;
|
---|
4665 | let route = {
|
---|
4666 | id: element.props.id || treePath.join("-"),
|
---|
4667 | caseSensitive: element.props.caseSensitive,
|
---|
4668 | element: element.props.element,
|
---|
4669 | Component: element.props.Component,
|
---|
4670 | index: element.props.index,
|
---|
4671 | path: element.props.path,
|
---|
4672 | loader: element.props.loader,
|
---|
4673 | action: element.props.action,
|
---|
4674 | errorElement: element.props.errorElement,
|
---|
4675 | ErrorBoundary: element.props.ErrorBoundary,
|
---|
4676 | hasErrorBoundary: element.props.ErrorBoundary != null || element.props.errorElement != null,
|
---|
4677 | shouldRevalidate: element.props.shouldRevalidate,
|
---|
4678 | handle: element.props.handle,
|
---|
4679 | lazy: element.props.lazy
|
---|
4680 | };
|
---|
4681 | if (element.props.children) {
|
---|
4682 | route.children = createRoutesFromChildren(element.props.children, treePath);
|
---|
4683 | }
|
---|
4684 | routes.push(route);
|
---|
4685 | });
|
---|
4686 | return routes;
|
---|
4687 | }
|
---|
4688 | function renderMatches(matches) {
|
---|
4689 | return _renderMatches(matches);
|
---|
4690 | }
|
---|
4691 | function mapRouteProperties(route) {
|
---|
4692 | let updates = {
|
---|
4693 | // Note: this check also occurs in createRoutesFromChildren so update
|
---|
4694 | // there if you change this -- please and thank you!
|
---|
4695 | hasErrorBoundary: route.ErrorBoundary != null || route.errorElement != null
|
---|
4696 | };
|
---|
4697 | if (route.Component) {
|
---|
4698 | if (true) {
|
---|
4699 | if (route.element) {
|
---|
4700 | true ? warning(false, "You should not include both `Component` and `element` on your route - `Component` will be used.") : void 0;
|
---|
4701 | }
|
---|
4702 | }
|
---|
4703 | Object.assign(updates, {
|
---|
4704 | element: React.createElement(route.Component),
|
---|
4705 | Component: void 0
|
---|
4706 | });
|
---|
4707 | }
|
---|
4708 | if (route.HydrateFallback) {
|
---|
4709 | if (true) {
|
---|
4710 | if (route.hydrateFallbackElement) {
|
---|
4711 | true ? warning(false, "You should not include both `HydrateFallback` and `hydrateFallbackElement` on your route - `HydrateFallback` will be used.") : void 0;
|
---|
4712 | }
|
---|
4713 | }
|
---|
4714 | Object.assign(updates, {
|
---|
4715 | hydrateFallbackElement: React.createElement(route.HydrateFallback),
|
---|
4716 | HydrateFallback: void 0
|
---|
4717 | });
|
---|
4718 | }
|
---|
4719 | if (route.ErrorBoundary) {
|
---|
4720 | if (true) {
|
---|
4721 | if (route.errorElement) {
|
---|
4722 | true ? warning(false, "You should not include both `ErrorBoundary` and `errorElement` on your route - `ErrorBoundary` will be used.") : void 0;
|
---|
4723 | }
|
---|
4724 | }
|
---|
4725 | Object.assign(updates, {
|
---|
4726 | errorElement: React.createElement(route.ErrorBoundary),
|
---|
4727 | ErrorBoundary: void 0
|
---|
4728 | });
|
---|
4729 | }
|
---|
4730 | return updates;
|
---|
4731 | }
|
---|
4732 | function createMemoryRouter(routes, opts) {
|
---|
4733 | return createRouter({
|
---|
4734 | basename: opts == null ? void 0 : opts.basename,
|
---|
4735 | future: _extends2({}, opts == null ? void 0 : opts.future, {
|
---|
4736 | v7_prependBasename: true
|
---|
4737 | }),
|
---|
4738 | history: createMemoryHistory({
|
---|
4739 | initialEntries: opts == null ? void 0 : opts.initialEntries,
|
---|
4740 | initialIndex: opts == null ? void 0 : opts.initialIndex
|
---|
4741 | }),
|
---|
4742 | hydrationData: opts == null ? void 0 : opts.hydrationData,
|
---|
4743 | routes,
|
---|
4744 | mapRouteProperties,
|
---|
4745 | dataStrategy: opts == null ? void 0 : opts.dataStrategy,
|
---|
4746 | patchRoutesOnNavigation: opts == null ? void 0 : opts.patchRoutesOnNavigation
|
---|
4747 | }).initialize();
|
---|
4748 | }
|
---|
4749 |
|
---|
4750 | // node_modules/react-router-dom/dist/index.js
|
---|
4751 | function _extends3() {
|
---|
4752 | _extends3 = Object.assign ? Object.assign.bind() : function(target) {
|
---|
4753 | for (var i = 1; i < arguments.length; i++) {
|
---|
4754 | var source = arguments[i];
|
---|
4755 | for (var key in source) {
|
---|
4756 | if (Object.prototype.hasOwnProperty.call(source, key)) {
|
---|
4757 | target[key] = source[key];
|
---|
4758 | }
|
---|
4759 | }
|
---|
4760 | }
|
---|
4761 | return target;
|
---|
4762 | };
|
---|
4763 | return _extends3.apply(this, arguments);
|
---|
4764 | }
|
---|
4765 | function _objectWithoutPropertiesLoose(source, excluded) {
|
---|
4766 | if (source == null) return {};
|
---|
4767 | var target = {};
|
---|
4768 | var sourceKeys = Object.keys(source);
|
---|
4769 | var key, i;
|
---|
4770 | for (i = 0; i < sourceKeys.length; i++) {
|
---|
4771 | key = sourceKeys[i];
|
---|
4772 | if (excluded.indexOf(key) >= 0) continue;
|
---|
4773 | target[key] = source[key];
|
---|
4774 | }
|
---|
4775 | return target;
|
---|
4776 | }
|
---|
4777 | var defaultMethod = "get";
|
---|
4778 | var defaultEncType = "application/x-www-form-urlencoded";
|
---|
4779 | function isHtmlElement(object) {
|
---|
4780 | return object != null && typeof object.tagName === "string";
|
---|
4781 | }
|
---|
4782 | function isButtonElement(object) {
|
---|
4783 | return isHtmlElement(object) && object.tagName.toLowerCase() === "button";
|
---|
4784 | }
|
---|
4785 | function isFormElement(object) {
|
---|
4786 | return isHtmlElement(object) && object.tagName.toLowerCase() === "form";
|
---|
4787 | }
|
---|
4788 | function isInputElement(object) {
|
---|
4789 | return isHtmlElement(object) && object.tagName.toLowerCase() === "input";
|
---|
4790 | }
|
---|
4791 | function isModifiedEvent(event) {
|
---|
4792 | return !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey);
|
---|
4793 | }
|
---|
4794 | function shouldProcessLinkClick(event, target) {
|
---|
4795 | return event.button === 0 && // Ignore everything but left clicks
|
---|
4796 | (!target || target === "_self") && // Let browser handle "target=_blank" etc.
|
---|
4797 | !isModifiedEvent(event);
|
---|
4798 | }
|
---|
4799 | function createSearchParams(init) {
|
---|
4800 | if (init === void 0) {
|
---|
4801 | init = "";
|
---|
4802 | }
|
---|
4803 | return new URLSearchParams(typeof init === "string" || Array.isArray(init) || init instanceof URLSearchParams ? init : Object.keys(init).reduce((memo2, key) => {
|
---|
4804 | let value = init[key];
|
---|
4805 | return memo2.concat(Array.isArray(value) ? value.map((v) => [key, v]) : [[key, value]]);
|
---|
4806 | }, []));
|
---|
4807 | }
|
---|
4808 | function getSearchParamsForLocation(locationSearch, defaultSearchParams) {
|
---|
4809 | let searchParams = createSearchParams(locationSearch);
|
---|
4810 | if (defaultSearchParams) {
|
---|
4811 | defaultSearchParams.forEach((_, key) => {
|
---|
4812 | if (!searchParams.has(key)) {
|
---|
4813 | defaultSearchParams.getAll(key).forEach((value) => {
|
---|
4814 | searchParams.append(key, value);
|
---|
4815 | });
|
---|
4816 | }
|
---|
4817 | });
|
---|
4818 | }
|
---|
4819 | return searchParams;
|
---|
4820 | }
|
---|
4821 | var _formDataSupportsSubmitter = null;
|
---|
4822 | function isFormDataSubmitterSupported() {
|
---|
4823 | if (_formDataSupportsSubmitter === null) {
|
---|
4824 | try {
|
---|
4825 | new FormData(
|
---|
4826 | document.createElement("form"),
|
---|
4827 | // @ts-expect-error if FormData supports the submitter parameter, this will throw
|
---|
4828 | 0
|
---|
4829 | );
|
---|
4830 | _formDataSupportsSubmitter = false;
|
---|
4831 | } catch (e) {
|
---|
4832 | _formDataSupportsSubmitter = true;
|
---|
4833 | }
|
---|
4834 | }
|
---|
4835 | return _formDataSupportsSubmitter;
|
---|
4836 | }
|
---|
4837 | var supportedFormEncTypes = /* @__PURE__ */ new Set(["application/x-www-form-urlencoded", "multipart/form-data", "text/plain"]);
|
---|
4838 | function getFormEncType(encType) {
|
---|
4839 | if (encType != null && !supportedFormEncTypes.has(encType)) {
|
---|
4840 | true ? warning(false, '"' + encType + '" is not a valid `encType` for `<Form>`/`<fetcher.Form>` ' + ('and will default to "' + defaultEncType + '"')) : void 0;
|
---|
4841 | return null;
|
---|
4842 | }
|
---|
4843 | return encType;
|
---|
4844 | }
|
---|
4845 | function getFormSubmissionInfo(target, basename) {
|
---|
4846 | let method;
|
---|
4847 | let action;
|
---|
4848 | let encType;
|
---|
4849 | let formData;
|
---|
4850 | let body;
|
---|
4851 | if (isFormElement(target)) {
|
---|
4852 | let attr = target.getAttribute("action");
|
---|
4853 | action = attr ? stripBasename(attr, basename) : null;
|
---|
4854 | method = target.getAttribute("method") || defaultMethod;
|
---|
4855 | encType = getFormEncType(target.getAttribute("enctype")) || defaultEncType;
|
---|
4856 | formData = new FormData(target);
|
---|
4857 | } else if (isButtonElement(target) || isInputElement(target) && (target.type === "submit" || target.type === "image")) {
|
---|
4858 | let form = target.form;
|
---|
4859 | if (form == null) {
|
---|
4860 | throw new Error('Cannot submit a <button> or <input type="submit"> without a <form>');
|
---|
4861 | }
|
---|
4862 | let attr = target.getAttribute("formaction") || form.getAttribute("action");
|
---|
4863 | action = attr ? stripBasename(attr, basename) : null;
|
---|
4864 | method = target.getAttribute("formmethod") || form.getAttribute("method") || defaultMethod;
|
---|
4865 | encType = getFormEncType(target.getAttribute("formenctype")) || getFormEncType(form.getAttribute("enctype")) || defaultEncType;
|
---|
4866 | formData = new FormData(form, target);
|
---|
4867 | if (!isFormDataSubmitterSupported()) {
|
---|
4868 | let {
|
---|
4869 | name,
|
---|
4870 | type,
|
---|
4871 | value
|
---|
4872 | } = target;
|
---|
4873 | if (type === "image") {
|
---|
4874 | let prefix = name ? name + "." : "";
|
---|
4875 | formData.append(prefix + "x", "0");
|
---|
4876 | formData.append(prefix + "y", "0");
|
---|
4877 | } else if (name) {
|
---|
4878 | formData.append(name, value);
|
---|
4879 | }
|
---|
4880 | }
|
---|
4881 | } else if (isHtmlElement(target)) {
|
---|
4882 | throw new Error('Cannot submit element that is not <form>, <button>, or <input type="submit|image">');
|
---|
4883 | } else {
|
---|
4884 | method = defaultMethod;
|
---|
4885 | action = null;
|
---|
4886 | encType = defaultEncType;
|
---|
4887 | body = target;
|
---|
4888 | }
|
---|
4889 | if (formData && encType === "text/plain") {
|
---|
4890 | body = formData;
|
---|
4891 | formData = void 0;
|
---|
4892 | }
|
---|
4893 | return {
|
---|
4894 | action,
|
---|
4895 | method: method.toLowerCase(),
|
---|
4896 | encType,
|
---|
4897 | formData,
|
---|
4898 | body
|
---|
4899 | };
|
---|
4900 | }
|
---|
4901 | var _excluded = ["onClick", "relative", "reloadDocument", "replace", "state", "target", "to", "preventScrollReset", "viewTransition"];
|
---|
4902 | var _excluded2 = ["aria-current", "caseSensitive", "className", "end", "style", "to", "viewTransition", "children"];
|
---|
4903 | var _excluded3 = ["fetcherKey", "navigate", "reloadDocument", "replace", "state", "method", "action", "onSubmit", "relative", "preventScrollReset", "viewTransition"];
|
---|
4904 | var REACT_ROUTER_VERSION = "6";
|
---|
4905 | try {
|
---|
4906 | window.__reactRouterVersion = REACT_ROUTER_VERSION;
|
---|
4907 | } catch (e) {
|
---|
4908 | }
|
---|
4909 | function createBrowserRouter(routes, opts) {
|
---|
4910 | return createRouter({
|
---|
4911 | basename: opts == null ? void 0 : opts.basename,
|
---|
4912 | future: _extends3({}, opts == null ? void 0 : opts.future, {
|
---|
4913 | v7_prependBasename: true
|
---|
4914 | }),
|
---|
4915 | history: createBrowserHistory({
|
---|
4916 | window: opts == null ? void 0 : opts.window
|
---|
4917 | }),
|
---|
4918 | hydrationData: (opts == null ? void 0 : opts.hydrationData) || parseHydrationData(),
|
---|
4919 | routes,
|
---|
4920 | mapRouteProperties,
|
---|
4921 | dataStrategy: opts == null ? void 0 : opts.dataStrategy,
|
---|
4922 | patchRoutesOnNavigation: opts == null ? void 0 : opts.patchRoutesOnNavigation,
|
---|
4923 | window: opts == null ? void 0 : opts.window
|
---|
4924 | }).initialize();
|
---|
4925 | }
|
---|
4926 | function createHashRouter(routes, opts) {
|
---|
4927 | return createRouter({
|
---|
4928 | basename: opts == null ? void 0 : opts.basename,
|
---|
4929 | future: _extends3({}, opts == null ? void 0 : opts.future, {
|
---|
4930 | v7_prependBasename: true
|
---|
4931 | }),
|
---|
4932 | history: createHashHistory({
|
---|
4933 | window: opts == null ? void 0 : opts.window
|
---|
4934 | }),
|
---|
4935 | hydrationData: (opts == null ? void 0 : opts.hydrationData) || parseHydrationData(),
|
---|
4936 | routes,
|
---|
4937 | mapRouteProperties,
|
---|
4938 | dataStrategy: opts == null ? void 0 : opts.dataStrategy,
|
---|
4939 | patchRoutesOnNavigation: opts == null ? void 0 : opts.patchRoutesOnNavigation,
|
---|
4940 | window: opts == null ? void 0 : opts.window
|
---|
4941 | }).initialize();
|
---|
4942 | }
|
---|
4943 | function parseHydrationData() {
|
---|
4944 | var _window;
|
---|
4945 | let state = (_window = window) == null ? void 0 : _window.__staticRouterHydrationData;
|
---|
4946 | if (state && state.errors) {
|
---|
4947 | state = _extends3({}, state, {
|
---|
4948 | errors: deserializeErrors(state.errors)
|
---|
4949 | });
|
---|
4950 | }
|
---|
4951 | return state;
|
---|
4952 | }
|
---|
4953 | function deserializeErrors(errors) {
|
---|
4954 | if (!errors) return null;
|
---|
4955 | let entries = Object.entries(errors);
|
---|
4956 | let serialized = {};
|
---|
4957 | for (let [key, val] of entries) {
|
---|
4958 | if (val && val.__type === "RouteErrorResponse") {
|
---|
4959 | serialized[key] = new ErrorResponseImpl(val.status, val.statusText, val.data, val.internal === true);
|
---|
4960 | } else if (val && val.__type === "Error") {
|
---|
4961 | if (val.__subType) {
|
---|
4962 | let ErrorConstructor = window[val.__subType];
|
---|
4963 | if (typeof ErrorConstructor === "function") {
|
---|
4964 | try {
|
---|
4965 | let error = new ErrorConstructor(val.message);
|
---|
4966 | error.stack = "";
|
---|
4967 | serialized[key] = error;
|
---|
4968 | } catch (e) {
|
---|
4969 | }
|
---|
4970 | }
|
---|
4971 | }
|
---|
4972 | if (serialized[key] == null) {
|
---|
4973 | let error = new Error(val.message);
|
---|
4974 | error.stack = "";
|
---|
4975 | serialized[key] = error;
|
---|
4976 | }
|
---|
4977 | } else {
|
---|
4978 | serialized[key] = val;
|
---|
4979 | }
|
---|
4980 | }
|
---|
4981 | return serialized;
|
---|
4982 | }
|
---|
4983 | var ViewTransitionContext = React2.createContext({
|
---|
4984 | isTransitioning: false
|
---|
4985 | });
|
---|
4986 | if (true) {
|
---|
4987 | ViewTransitionContext.displayName = "ViewTransition";
|
---|
4988 | }
|
---|
4989 | var FetchersContext = React2.createContext(/* @__PURE__ */ new Map());
|
---|
4990 | if (true) {
|
---|
4991 | FetchersContext.displayName = "Fetchers";
|
---|
4992 | }
|
---|
4993 | var START_TRANSITION2 = "startTransition";
|
---|
4994 | var startTransitionImpl2 = React2[START_TRANSITION2];
|
---|
4995 | var FLUSH_SYNC = "flushSync";
|
---|
4996 | var flushSyncImpl = ReactDOM[FLUSH_SYNC];
|
---|
4997 | var USE_ID = "useId";
|
---|
4998 | var useIdImpl = React2[USE_ID];
|
---|
4999 | function startTransitionSafe(cb) {
|
---|
5000 | if (startTransitionImpl2) {
|
---|
5001 | startTransitionImpl2(cb);
|
---|
5002 | } else {
|
---|
5003 | cb();
|
---|
5004 | }
|
---|
5005 | }
|
---|
5006 | function flushSyncSafe(cb) {
|
---|
5007 | if (flushSyncImpl) {
|
---|
5008 | flushSyncImpl(cb);
|
---|
5009 | } else {
|
---|
5010 | cb();
|
---|
5011 | }
|
---|
5012 | }
|
---|
5013 | var Deferred = class {
|
---|
5014 | constructor() {
|
---|
5015 | this.status = "pending";
|
---|
5016 | this.promise = new Promise((resolve, reject) => {
|
---|
5017 | this.resolve = (value) => {
|
---|
5018 | if (this.status === "pending") {
|
---|
5019 | this.status = "resolved";
|
---|
5020 | resolve(value);
|
---|
5021 | }
|
---|
5022 | };
|
---|
5023 | this.reject = (reason) => {
|
---|
5024 | if (this.status === "pending") {
|
---|
5025 | this.status = "rejected";
|
---|
5026 | reject(reason);
|
---|
5027 | }
|
---|
5028 | };
|
---|
5029 | });
|
---|
5030 | }
|
---|
5031 | };
|
---|
5032 | function RouterProvider(_ref) {
|
---|
5033 | let {
|
---|
5034 | fallbackElement,
|
---|
5035 | router,
|
---|
5036 | future
|
---|
5037 | } = _ref;
|
---|
5038 | let [state, setStateImpl] = React2.useState(router.state);
|
---|
5039 | let [pendingState, setPendingState] = React2.useState();
|
---|
5040 | let [vtContext, setVtContext] = React2.useState({
|
---|
5041 | isTransitioning: false
|
---|
5042 | });
|
---|
5043 | let [renderDfd, setRenderDfd] = React2.useState();
|
---|
5044 | let [transition, setTransition] = React2.useState();
|
---|
5045 | let [interruption, setInterruption] = React2.useState();
|
---|
5046 | let fetcherData = React2.useRef(/* @__PURE__ */ new Map());
|
---|
5047 | let {
|
---|
5048 | v7_startTransition
|
---|
5049 | } = future || {};
|
---|
5050 | let optInStartTransition = React2.useCallback((cb) => {
|
---|
5051 | if (v7_startTransition) {
|
---|
5052 | startTransitionSafe(cb);
|
---|
5053 | } else {
|
---|
5054 | cb();
|
---|
5055 | }
|
---|
5056 | }, [v7_startTransition]);
|
---|
5057 | let setState = React2.useCallback((newState, _ref2) => {
|
---|
5058 | let {
|
---|
5059 | deletedFetchers,
|
---|
5060 | flushSync,
|
---|
5061 | viewTransitionOpts
|
---|
5062 | } = _ref2;
|
---|
5063 | deletedFetchers.forEach((key) => fetcherData.current.delete(key));
|
---|
5064 | newState.fetchers.forEach((fetcher, key) => {
|
---|
5065 | if (fetcher.data !== void 0) {
|
---|
5066 | fetcherData.current.set(key, fetcher.data);
|
---|
5067 | }
|
---|
5068 | });
|
---|
5069 | let isViewTransitionUnavailable = router.window == null || router.window.document == null || typeof router.window.document.startViewTransition !== "function";
|
---|
5070 | if (!viewTransitionOpts || isViewTransitionUnavailable) {
|
---|
5071 | if (flushSync) {
|
---|
5072 | flushSyncSafe(() => setStateImpl(newState));
|
---|
5073 | } else {
|
---|
5074 | optInStartTransition(() => setStateImpl(newState));
|
---|
5075 | }
|
---|
5076 | return;
|
---|
5077 | }
|
---|
5078 | if (flushSync) {
|
---|
5079 | flushSyncSafe(() => {
|
---|
5080 | if (transition) {
|
---|
5081 | renderDfd && renderDfd.resolve();
|
---|
5082 | transition.skipTransition();
|
---|
5083 | }
|
---|
5084 | setVtContext({
|
---|
5085 | isTransitioning: true,
|
---|
5086 | flushSync: true,
|
---|
5087 | currentLocation: viewTransitionOpts.currentLocation,
|
---|
5088 | nextLocation: viewTransitionOpts.nextLocation
|
---|
5089 | });
|
---|
5090 | });
|
---|
5091 | let t = router.window.document.startViewTransition(() => {
|
---|
5092 | flushSyncSafe(() => setStateImpl(newState));
|
---|
5093 | });
|
---|
5094 | t.finished.finally(() => {
|
---|
5095 | flushSyncSafe(() => {
|
---|
5096 | setRenderDfd(void 0);
|
---|
5097 | setTransition(void 0);
|
---|
5098 | setPendingState(void 0);
|
---|
5099 | setVtContext({
|
---|
5100 | isTransitioning: false
|
---|
5101 | });
|
---|
5102 | });
|
---|
5103 | });
|
---|
5104 | flushSyncSafe(() => setTransition(t));
|
---|
5105 | return;
|
---|
5106 | }
|
---|
5107 | if (transition) {
|
---|
5108 | renderDfd && renderDfd.resolve();
|
---|
5109 | transition.skipTransition();
|
---|
5110 | setInterruption({
|
---|
5111 | state: newState,
|
---|
5112 | currentLocation: viewTransitionOpts.currentLocation,
|
---|
5113 | nextLocation: viewTransitionOpts.nextLocation
|
---|
5114 | });
|
---|
5115 | } else {
|
---|
5116 | setPendingState(newState);
|
---|
5117 | setVtContext({
|
---|
5118 | isTransitioning: true,
|
---|
5119 | flushSync: false,
|
---|
5120 | currentLocation: viewTransitionOpts.currentLocation,
|
---|
5121 | nextLocation: viewTransitionOpts.nextLocation
|
---|
5122 | });
|
---|
5123 | }
|
---|
5124 | }, [router.window, transition, renderDfd, fetcherData, optInStartTransition]);
|
---|
5125 | React2.useLayoutEffect(() => router.subscribe(setState), [router, setState]);
|
---|
5126 | React2.useEffect(() => {
|
---|
5127 | if (vtContext.isTransitioning && !vtContext.flushSync) {
|
---|
5128 | setRenderDfd(new Deferred());
|
---|
5129 | }
|
---|
5130 | }, [vtContext]);
|
---|
5131 | React2.useEffect(() => {
|
---|
5132 | if (renderDfd && pendingState && router.window) {
|
---|
5133 | let newState = pendingState;
|
---|
5134 | let renderPromise = renderDfd.promise;
|
---|
5135 | let transition2 = router.window.document.startViewTransition(async () => {
|
---|
5136 | optInStartTransition(() => setStateImpl(newState));
|
---|
5137 | await renderPromise;
|
---|
5138 | });
|
---|
5139 | transition2.finished.finally(() => {
|
---|
5140 | setRenderDfd(void 0);
|
---|
5141 | setTransition(void 0);
|
---|
5142 | setPendingState(void 0);
|
---|
5143 | setVtContext({
|
---|
5144 | isTransitioning: false
|
---|
5145 | });
|
---|
5146 | });
|
---|
5147 | setTransition(transition2);
|
---|
5148 | }
|
---|
5149 | }, [optInStartTransition, pendingState, renderDfd, router.window]);
|
---|
5150 | React2.useEffect(() => {
|
---|
5151 | if (renderDfd && pendingState && state.location.key === pendingState.location.key) {
|
---|
5152 | renderDfd.resolve();
|
---|
5153 | }
|
---|
5154 | }, [renderDfd, transition, state.location, pendingState]);
|
---|
5155 | React2.useEffect(() => {
|
---|
5156 | if (!vtContext.isTransitioning && interruption) {
|
---|
5157 | setPendingState(interruption.state);
|
---|
5158 | setVtContext({
|
---|
5159 | isTransitioning: true,
|
---|
5160 | flushSync: false,
|
---|
5161 | currentLocation: interruption.currentLocation,
|
---|
5162 | nextLocation: interruption.nextLocation
|
---|
5163 | });
|
---|
5164 | setInterruption(void 0);
|
---|
5165 | }
|
---|
5166 | }, [vtContext.isTransitioning, interruption]);
|
---|
5167 | React2.useEffect(() => {
|
---|
5168 | true ? warning(fallbackElement == null || !router.future.v7_partialHydration, "`<RouterProvider fallbackElement>` is deprecated when using `v7_partialHydration`, use a `HydrateFallback` component instead") : void 0;
|
---|
5169 | }, []);
|
---|
5170 | let navigator = React2.useMemo(() => {
|
---|
5171 | return {
|
---|
5172 | createHref: router.createHref,
|
---|
5173 | encodeLocation: router.encodeLocation,
|
---|
5174 | go: (n) => router.navigate(n),
|
---|
5175 | push: (to, state2, opts) => router.navigate(to, {
|
---|
5176 | state: state2,
|
---|
5177 | preventScrollReset: opts == null ? void 0 : opts.preventScrollReset
|
---|
5178 | }),
|
---|
5179 | replace: (to, state2, opts) => router.navigate(to, {
|
---|
5180 | replace: true,
|
---|
5181 | state: state2,
|
---|
5182 | preventScrollReset: opts == null ? void 0 : opts.preventScrollReset
|
---|
5183 | })
|
---|
5184 | };
|
---|
5185 | }, [router]);
|
---|
5186 | let basename = router.basename || "/";
|
---|
5187 | let dataRouterContext = React2.useMemo(() => ({
|
---|
5188 | router,
|
---|
5189 | navigator,
|
---|
5190 | static: false,
|
---|
5191 | basename
|
---|
5192 | }), [router, navigator, basename]);
|
---|
5193 | let routerFuture = React2.useMemo(() => ({
|
---|
5194 | v7_relativeSplatPath: router.future.v7_relativeSplatPath
|
---|
5195 | }), [router.future.v7_relativeSplatPath]);
|
---|
5196 | React2.useEffect(() => logV6DeprecationWarnings(future, router.future), [future, router.future]);
|
---|
5197 | return React2.createElement(React2.Fragment, null, React2.createElement(DataRouterContext.Provider, {
|
---|
5198 | value: dataRouterContext
|
---|
5199 | }, React2.createElement(DataRouterStateContext.Provider, {
|
---|
5200 | value: state
|
---|
5201 | }, React2.createElement(FetchersContext.Provider, {
|
---|
5202 | value: fetcherData.current
|
---|
5203 | }, React2.createElement(ViewTransitionContext.Provider, {
|
---|
5204 | value: vtContext
|
---|
5205 | }, React2.createElement(Router, {
|
---|
5206 | basename,
|
---|
5207 | location: state.location,
|
---|
5208 | navigationType: state.historyAction,
|
---|
5209 | navigator,
|
---|
5210 | future: routerFuture
|
---|
5211 | }, state.initialized || router.future.v7_partialHydration ? React2.createElement(MemoizedDataRoutes, {
|
---|
5212 | routes: router.routes,
|
---|
5213 | future: router.future,
|
---|
5214 | state
|
---|
5215 | }) : fallbackElement))))), null);
|
---|
5216 | }
|
---|
5217 | var MemoizedDataRoutes = React2.memo(DataRoutes);
|
---|
5218 | function DataRoutes(_ref3) {
|
---|
5219 | let {
|
---|
5220 | routes,
|
---|
5221 | future,
|
---|
5222 | state
|
---|
5223 | } = _ref3;
|
---|
5224 | return useRoutesImpl(routes, void 0, state, future);
|
---|
5225 | }
|
---|
5226 | function BrowserRouter(_ref4) {
|
---|
5227 | let {
|
---|
5228 | basename,
|
---|
5229 | children,
|
---|
5230 | future,
|
---|
5231 | window: window2
|
---|
5232 | } = _ref4;
|
---|
5233 | let historyRef = React2.useRef();
|
---|
5234 | if (historyRef.current == null) {
|
---|
5235 | historyRef.current = createBrowserHistory({
|
---|
5236 | window: window2,
|
---|
5237 | v5Compat: true
|
---|
5238 | });
|
---|
5239 | }
|
---|
5240 | let history = historyRef.current;
|
---|
5241 | let [state, setStateImpl] = React2.useState({
|
---|
5242 | action: history.action,
|
---|
5243 | location: history.location
|
---|
5244 | });
|
---|
5245 | let {
|
---|
5246 | v7_startTransition
|
---|
5247 | } = future || {};
|
---|
5248 | let setState = React2.useCallback((newState) => {
|
---|
5249 | v7_startTransition && startTransitionImpl2 ? startTransitionImpl2(() => setStateImpl(newState)) : setStateImpl(newState);
|
---|
5250 | }, [setStateImpl, v7_startTransition]);
|
---|
5251 | React2.useLayoutEffect(() => history.listen(setState), [history, setState]);
|
---|
5252 | React2.useEffect(() => logV6DeprecationWarnings(future), [future]);
|
---|
5253 | return React2.createElement(Router, {
|
---|
5254 | basename,
|
---|
5255 | children,
|
---|
5256 | location: state.location,
|
---|
5257 | navigationType: state.action,
|
---|
5258 | navigator: history,
|
---|
5259 | future
|
---|
5260 | });
|
---|
5261 | }
|
---|
5262 | function HashRouter(_ref5) {
|
---|
5263 | let {
|
---|
5264 | basename,
|
---|
5265 | children,
|
---|
5266 | future,
|
---|
5267 | window: window2
|
---|
5268 | } = _ref5;
|
---|
5269 | let historyRef = React2.useRef();
|
---|
5270 | if (historyRef.current == null) {
|
---|
5271 | historyRef.current = createHashHistory({
|
---|
5272 | window: window2,
|
---|
5273 | v5Compat: true
|
---|
5274 | });
|
---|
5275 | }
|
---|
5276 | let history = historyRef.current;
|
---|
5277 | let [state, setStateImpl] = React2.useState({
|
---|
5278 | action: history.action,
|
---|
5279 | location: history.location
|
---|
5280 | });
|
---|
5281 | let {
|
---|
5282 | v7_startTransition
|
---|
5283 | } = future || {};
|
---|
5284 | let setState = React2.useCallback((newState) => {
|
---|
5285 | v7_startTransition && startTransitionImpl2 ? startTransitionImpl2(() => setStateImpl(newState)) : setStateImpl(newState);
|
---|
5286 | }, [setStateImpl, v7_startTransition]);
|
---|
5287 | React2.useLayoutEffect(() => history.listen(setState), [history, setState]);
|
---|
5288 | React2.useEffect(() => logV6DeprecationWarnings(future), [future]);
|
---|
5289 | return React2.createElement(Router, {
|
---|
5290 | basename,
|
---|
5291 | children,
|
---|
5292 | location: state.location,
|
---|
5293 | navigationType: state.action,
|
---|
5294 | navigator: history,
|
---|
5295 | future
|
---|
5296 | });
|
---|
5297 | }
|
---|
5298 | function HistoryRouter(_ref6) {
|
---|
5299 | let {
|
---|
5300 | basename,
|
---|
5301 | children,
|
---|
5302 | future,
|
---|
5303 | history
|
---|
5304 | } = _ref6;
|
---|
5305 | let [state, setStateImpl] = React2.useState({
|
---|
5306 | action: history.action,
|
---|
5307 | location: history.location
|
---|
5308 | });
|
---|
5309 | let {
|
---|
5310 | v7_startTransition
|
---|
5311 | } = future || {};
|
---|
5312 | let setState = React2.useCallback((newState) => {
|
---|
5313 | v7_startTransition && startTransitionImpl2 ? startTransitionImpl2(() => setStateImpl(newState)) : setStateImpl(newState);
|
---|
5314 | }, [setStateImpl, v7_startTransition]);
|
---|
5315 | React2.useLayoutEffect(() => history.listen(setState), [history, setState]);
|
---|
5316 | React2.useEffect(() => logV6DeprecationWarnings(future), [future]);
|
---|
5317 | return React2.createElement(Router, {
|
---|
5318 | basename,
|
---|
5319 | children,
|
---|
5320 | location: state.location,
|
---|
5321 | navigationType: state.action,
|
---|
5322 | navigator: history,
|
---|
5323 | future
|
---|
5324 | });
|
---|
5325 | }
|
---|
5326 | if (true) {
|
---|
5327 | HistoryRouter.displayName = "unstable_HistoryRouter";
|
---|
5328 | }
|
---|
5329 | var isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
|
---|
5330 | var ABSOLUTE_URL_REGEX2 = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
|
---|
5331 | var Link = React2.forwardRef(function LinkWithRef(_ref7, ref) {
|
---|
5332 | let {
|
---|
5333 | onClick,
|
---|
5334 | relative,
|
---|
5335 | reloadDocument,
|
---|
5336 | replace: replace2,
|
---|
5337 | state,
|
---|
5338 | target,
|
---|
5339 | to,
|
---|
5340 | preventScrollReset,
|
---|
5341 | viewTransition
|
---|
5342 | } = _ref7, rest = _objectWithoutPropertiesLoose(_ref7, _excluded);
|
---|
5343 | let {
|
---|
5344 | basename
|
---|
5345 | } = React2.useContext(NavigationContext);
|
---|
5346 | let absoluteHref;
|
---|
5347 | let isExternal = false;
|
---|
5348 | if (typeof to === "string" && ABSOLUTE_URL_REGEX2.test(to)) {
|
---|
5349 | absoluteHref = to;
|
---|
5350 | if (isBrowser) {
|
---|
5351 | try {
|
---|
5352 | let currentUrl = new URL(window.location.href);
|
---|
5353 | let targetUrl = to.startsWith("//") ? new URL(currentUrl.protocol + to) : new URL(to);
|
---|
5354 | let path = stripBasename(targetUrl.pathname, basename);
|
---|
5355 | if (targetUrl.origin === currentUrl.origin && path != null) {
|
---|
5356 | to = path + targetUrl.search + targetUrl.hash;
|
---|
5357 | } else {
|
---|
5358 | isExternal = true;
|
---|
5359 | }
|
---|
5360 | } catch (e) {
|
---|
5361 | true ? warning(false, '<Link to="' + to + '"> contains an invalid URL which will probably break when clicked - please update to a valid URL path.') : void 0;
|
---|
5362 | }
|
---|
5363 | }
|
---|
5364 | }
|
---|
5365 | let href = useHref(to, {
|
---|
5366 | relative
|
---|
5367 | });
|
---|
5368 | let internalOnClick = useLinkClickHandler(to, {
|
---|
5369 | replace: replace2,
|
---|
5370 | state,
|
---|
5371 | target,
|
---|
5372 | preventScrollReset,
|
---|
5373 | relative,
|
---|
5374 | viewTransition
|
---|
5375 | });
|
---|
5376 | function handleClick(event) {
|
---|
5377 | if (onClick) onClick(event);
|
---|
5378 | if (!event.defaultPrevented) {
|
---|
5379 | internalOnClick(event);
|
---|
5380 | }
|
---|
5381 | }
|
---|
5382 | return (
|
---|
5383 | // eslint-disable-next-line jsx-a11y/anchor-has-content
|
---|
5384 | React2.createElement("a", _extends3({}, rest, {
|
---|
5385 | href: absoluteHref || href,
|
---|
5386 | onClick: isExternal || reloadDocument ? onClick : handleClick,
|
---|
5387 | ref,
|
---|
5388 | target
|
---|
5389 | }))
|
---|
5390 | );
|
---|
5391 | });
|
---|
5392 | if (true) {
|
---|
5393 | Link.displayName = "Link";
|
---|
5394 | }
|
---|
5395 | var NavLink = React2.forwardRef(function NavLinkWithRef(_ref8, ref) {
|
---|
5396 | let {
|
---|
5397 | "aria-current": ariaCurrentProp = "page",
|
---|
5398 | caseSensitive = false,
|
---|
5399 | className: classNameProp = "",
|
---|
5400 | end = false,
|
---|
5401 | style: styleProp,
|
---|
5402 | to,
|
---|
5403 | viewTransition,
|
---|
5404 | children
|
---|
5405 | } = _ref8, rest = _objectWithoutPropertiesLoose(_ref8, _excluded2);
|
---|
5406 | let path = useResolvedPath(to, {
|
---|
5407 | relative: rest.relative
|
---|
5408 | });
|
---|
5409 | let location = useLocation();
|
---|
5410 | let routerState = React2.useContext(DataRouterStateContext);
|
---|
5411 | let {
|
---|
5412 | navigator,
|
---|
5413 | basename
|
---|
5414 | } = React2.useContext(NavigationContext);
|
---|
5415 | let isTransitioning = routerState != null && // Conditional usage is OK here because the usage of a data router is static
|
---|
5416 | // eslint-disable-next-line react-hooks/rules-of-hooks
|
---|
5417 | useViewTransitionState(path) && viewTransition === true;
|
---|
5418 | let toPathname = navigator.encodeLocation ? navigator.encodeLocation(path).pathname : path.pathname;
|
---|
5419 | let locationPathname = location.pathname;
|
---|
5420 | let nextLocationPathname = routerState && routerState.navigation && routerState.navigation.location ? routerState.navigation.location.pathname : null;
|
---|
5421 | if (!caseSensitive) {
|
---|
5422 | locationPathname = locationPathname.toLowerCase();
|
---|
5423 | nextLocationPathname = nextLocationPathname ? nextLocationPathname.toLowerCase() : null;
|
---|
5424 | toPathname = toPathname.toLowerCase();
|
---|
5425 | }
|
---|
5426 | if (nextLocationPathname && basename) {
|
---|
5427 | nextLocationPathname = stripBasename(nextLocationPathname, basename) || nextLocationPathname;
|
---|
5428 | }
|
---|
5429 | const endSlashPosition = toPathname !== "/" && toPathname.endsWith("/") ? toPathname.length - 1 : toPathname.length;
|
---|
5430 | let isActive = locationPathname === toPathname || !end && locationPathname.startsWith(toPathname) && locationPathname.charAt(endSlashPosition) === "/";
|
---|
5431 | let isPending = nextLocationPathname != null && (nextLocationPathname === toPathname || !end && nextLocationPathname.startsWith(toPathname) && nextLocationPathname.charAt(toPathname.length) === "/");
|
---|
5432 | let renderProps = {
|
---|
5433 | isActive,
|
---|
5434 | isPending,
|
---|
5435 | isTransitioning
|
---|
5436 | };
|
---|
5437 | let ariaCurrent = isActive ? ariaCurrentProp : void 0;
|
---|
5438 | let className;
|
---|
5439 | if (typeof classNameProp === "function") {
|
---|
5440 | className = classNameProp(renderProps);
|
---|
5441 | } else {
|
---|
5442 | className = [classNameProp, isActive ? "active" : null, isPending ? "pending" : null, isTransitioning ? "transitioning" : null].filter(Boolean).join(" ");
|
---|
5443 | }
|
---|
5444 | let style = typeof styleProp === "function" ? styleProp(renderProps) : styleProp;
|
---|
5445 | return React2.createElement(Link, _extends3({}, rest, {
|
---|
5446 | "aria-current": ariaCurrent,
|
---|
5447 | className,
|
---|
5448 | ref,
|
---|
5449 | style,
|
---|
5450 | to,
|
---|
5451 | viewTransition
|
---|
5452 | }), typeof children === "function" ? children(renderProps) : children);
|
---|
5453 | });
|
---|
5454 | if (true) {
|
---|
5455 | NavLink.displayName = "NavLink";
|
---|
5456 | }
|
---|
5457 | var Form = React2.forwardRef((_ref9, forwardedRef) => {
|
---|
5458 | let {
|
---|
5459 | fetcherKey,
|
---|
5460 | navigate,
|
---|
5461 | reloadDocument,
|
---|
5462 | replace: replace2,
|
---|
5463 | state,
|
---|
5464 | method = defaultMethod,
|
---|
5465 | action,
|
---|
5466 | onSubmit,
|
---|
5467 | relative,
|
---|
5468 | preventScrollReset,
|
---|
5469 | viewTransition
|
---|
5470 | } = _ref9, props = _objectWithoutPropertiesLoose(_ref9, _excluded3);
|
---|
5471 | let submit = useSubmit();
|
---|
5472 | let formAction = useFormAction(action, {
|
---|
5473 | relative
|
---|
5474 | });
|
---|
5475 | let formMethod = method.toLowerCase() === "get" ? "get" : "post";
|
---|
5476 | let submitHandler = (event) => {
|
---|
5477 | onSubmit && onSubmit(event);
|
---|
5478 | if (event.defaultPrevented) return;
|
---|
5479 | event.preventDefault();
|
---|
5480 | let submitter = event.nativeEvent.submitter;
|
---|
5481 | let submitMethod = (submitter == null ? void 0 : submitter.getAttribute("formmethod")) || method;
|
---|
5482 | submit(submitter || event.currentTarget, {
|
---|
5483 | fetcherKey,
|
---|
5484 | method: submitMethod,
|
---|
5485 | navigate,
|
---|
5486 | replace: replace2,
|
---|
5487 | state,
|
---|
5488 | relative,
|
---|
5489 | preventScrollReset,
|
---|
5490 | viewTransition
|
---|
5491 | });
|
---|
5492 | };
|
---|
5493 | return React2.createElement("form", _extends3({
|
---|
5494 | ref: forwardedRef,
|
---|
5495 | method: formMethod,
|
---|
5496 | action: formAction,
|
---|
5497 | onSubmit: reloadDocument ? onSubmit : submitHandler
|
---|
5498 | }, props));
|
---|
5499 | });
|
---|
5500 | if (true) {
|
---|
5501 | Form.displayName = "Form";
|
---|
5502 | }
|
---|
5503 | function ScrollRestoration(_ref10) {
|
---|
5504 | let {
|
---|
5505 | getKey,
|
---|
5506 | storageKey
|
---|
5507 | } = _ref10;
|
---|
5508 | useScrollRestoration({
|
---|
5509 | getKey,
|
---|
5510 | storageKey
|
---|
5511 | });
|
---|
5512 | return null;
|
---|
5513 | }
|
---|
5514 | if (true) {
|
---|
5515 | ScrollRestoration.displayName = "ScrollRestoration";
|
---|
5516 | }
|
---|
5517 | var DataRouterHook2;
|
---|
5518 | (function(DataRouterHook3) {
|
---|
5519 | DataRouterHook3["UseScrollRestoration"] = "useScrollRestoration";
|
---|
5520 | DataRouterHook3["UseSubmit"] = "useSubmit";
|
---|
5521 | DataRouterHook3["UseSubmitFetcher"] = "useSubmitFetcher";
|
---|
5522 | DataRouterHook3["UseFetcher"] = "useFetcher";
|
---|
5523 | DataRouterHook3["useViewTransitionState"] = "useViewTransitionState";
|
---|
5524 | })(DataRouterHook2 || (DataRouterHook2 = {}));
|
---|
5525 | var DataRouterStateHook2;
|
---|
5526 | (function(DataRouterStateHook3) {
|
---|
5527 | DataRouterStateHook3["UseFetcher"] = "useFetcher";
|
---|
5528 | DataRouterStateHook3["UseFetchers"] = "useFetchers";
|
---|
5529 | DataRouterStateHook3["UseScrollRestoration"] = "useScrollRestoration";
|
---|
5530 | })(DataRouterStateHook2 || (DataRouterStateHook2 = {}));
|
---|
5531 | function getDataRouterConsoleError2(hookName) {
|
---|
5532 | return hookName + " must be used within a data router. See https://reactrouter.com/v6/routers/picking-a-router.";
|
---|
5533 | }
|
---|
5534 | function useDataRouterContext2(hookName) {
|
---|
5535 | let ctx = React2.useContext(DataRouterContext);
|
---|
5536 | !ctx ? true ? invariant(false, getDataRouterConsoleError2(hookName)) : invariant(false) : void 0;
|
---|
5537 | return ctx;
|
---|
5538 | }
|
---|
5539 | function useDataRouterState2(hookName) {
|
---|
5540 | let state = React2.useContext(DataRouterStateContext);
|
---|
5541 | !state ? true ? invariant(false, getDataRouterConsoleError2(hookName)) : invariant(false) : void 0;
|
---|
5542 | return state;
|
---|
5543 | }
|
---|
5544 | function useLinkClickHandler(to, _temp) {
|
---|
5545 | let {
|
---|
5546 | target,
|
---|
5547 | replace: replaceProp,
|
---|
5548 | state,
|
---|
5549 | preventScrollReset,
|
---|
5550 | relative,
|
---|
5551 | viewTransition
|
---|
5552 | } = _temp === void 0 ? {} : _temp;
|
---|
5553 | let navigate = useNavigate();
|
---|
5554 | let location = useLocation();
|
---|
5555 | let path = useResolvedPath(to, {
|
---|
5556 | relative
|
---|
5557 | });
|
---|
5558 | return React2.useCallback((event) => {
|
---|
5559 | if (shouldProcessLinkClick(event, target)) {
|
---|
5560 | event.preventDefault();
|
---|
5561 | let replace2 = replaceProp !== void 0 ? replaceProp : createPath(location) === createPath(path);
|
---|
5562 | navigate(to, {
|
---|
5563 | replace: replace2,
|
---|
5564 | state,
|
---|
5565 | preventScrollReset,
|
---|
5566 | relative,
|
---|
5567 | viewTransition
|
---|
5568 | });
|
---|
5569 | }
|
---|
5570 | }, [location, navigate, path, replaceProp, state, target, to, preventScrollReset, relative, viewTransition]);
|
---|
5571 | }
|
---|
5572 | function useSearchParams(defaultInit) {
|
---|
5573 | true ? warning(typeof URLSearchParams !== "undefined", "You cannot use the `useSearchParams` hook in a browser that does not support the URLSearchParams API. If you need to support Internet Explorer 11, we recommend you load a polyfill such as https://github.com/ungap/url-search-params.") : void 0;
|
---|
5574 | let defaultSearchParamsRef = React2.useRef(createSearchParams(defaultInit));
|
---|
5575 | let hasSetSearchParamsRef = React2.useRef(false);
|
---|
5576 | let location = useLocation();
|
---|
5577 | let searchParams = React2.useMemo(() => (
|
---|
5578 | // Only merge in the defaults if we haven't yet called setSearchParams.
|
---|
5579 | // Once we call that we want those to take precedence, otherwise you can't
|
---|
5580 | // remove a param with setSearchParams({}) if it has an initial value
|
---|
5581 | getSearchParamsForLocation(location.search, hasSetSearchParamsRef.current ? null : defaultSearchParamsRef.current)
|
---|
5582 | ), [location.search]);
|
---|
5583 | let navigate = useNavigate();
|
---|
5584 | let setSearchParams = React2.useCallback((nextInit, navigateOptions) => {
|
---|
5585 | const newSearchParams = createSearchParams(typeof nextInit === "function" ? nextInit(searchParams) : nextInit);
|
---|
5586 | hasSetSearchParamsRef.current = true;
|
---|
5587 | navigate("?" + newSearchParams, navigateOptions);
|
---|
5588 | }, [navigate, searchParams]);
|
---|
5589 | return [searchParams, setSearchParams];
|
---|
5590 | }
|
---|
5591 | function validateClientSideSubmission() {
|
---|
5592 | if (typeof document === "undefined") {
|
---|
5593 | throw new Error("You are calling submit during the server render. Try calling submit within a `useEffect` or callback instead.");
|
---|
5594 | }
|
---|
5595 | }
|
---|
5596 | var fetcherId = 0;
|
---|
5597 | var getUniqueFetcherId = () => "__" + String(++fetcherId) + "__";
|
---|
5598 | function useSubmit() {
|
---|
5599 | let {
|
---|
5600 | router
|
---|
5601 | } = useDataRouterContext2(DataRouterHook2.UseSubmit);
|
---|
5602 | let {
|
---|
5603 | basename
|
---|
5604 | } = React2.useContext(NavigationContext);
|
---|
5605 | let currentRouteId = useRouteId();
|
---|
5606 | return React2.useCallback(function(target, options) {
|
---|
5607 | if (options === void 0) {
|
---|
5608 | options = {};
|
---|
5609 | }
|
---|
5610 | validateClientSideSubmission();
|
---|
5611 | let {
|
---|
5612 | action,
|
---|
5613 | method,
|
---|
5614 | encType,
|
---|
5615 | formData,
|
---|
5616 | body
|
---|
5617 | } = getFormSubmissionInfo(target, basename);
|
---|
5618 | if (options.navigate === false) {
|
---|
5619 | let key = options.fetcherKey || getUniqueFetcherId();
|
---|
5620 | router.fetch(key, currentRouteId, options.action || action, {
|
---|
5621 | preventScrollReset: options.preventScrollReset,
|
---|
5622 | formData,
|
---|
5623 | body,
|
---|
5624 | formMethod: options.method || method,
|
---|
5625 | formEncType: options.encType || encType,
|
---|
5626 | flushSync: options.flushSync
|
---|
5627 | });
|
---|
5628 | } else {
|
---|
5629 | router.navigate(options.action || action, {
|
---|
5630 | preventScrollReset: options.preventScrollReset,
|
---|
5631 | formData,
|
---|
5632 | body,
|
---|
5633 | formMethod: options.method || method,
|
---|
5634 | formEncType: options.encType || encType,
|
---|
5635 | replace: options.replace,
|
---|
5636 | state: options.state,
|
---|
5637 | fromRouteId: currentRouteId,
|
---|
5638 | flushSync: options.flushSync,
|
---|
5639 | viewTransition: options.viewTransition
|
---|
5640 | });
|
---|
5641 | }
|
---|
5642 | }, [router, basename, currentRouteId]);
|
---|
5643 | }
|
---|
5644 | function useFormAction(action, _temp2) {
|
---|
5645 | let {
|
---|
5646 | relative
|
---|
5647 | } = _temp2 === void 0 ? {} : _temp2;
|
---|
5648 | let {
|
---|
5649 | basename
|
---|
5650 | } = React2.useContext(NavigationContext);
|
---|
5651 | let routeContext = React2.useContext(RouteContext);
|
---|
5652 | !routeContext ? true ? invariant(false, "useFormAction must be used inside a RouteContext") : invariant(false) : void 0;
|
---|
5653 | let [match] = routeContext.matches.slice(-1);
|
---|
5654 | let path = _extends3({}, useResolvedPath(action ? action : ".", {
|
---|
5655 | relative
|
---|
5656 | }));
|
---|
5657 | let location = useLocation();
|
---|
5658 | if (action == null) {
|
---|
5659 | path.search = location.search;
|
---|
5660 | let params = new URLSearchParams(path.search);
|
---|
5661 | let indexValues = params.getAll("index");
|
---|
5662 | let hasNakedIndexParam = indexValues.some((v) => v === "");
|
---|
5663 | if (hasNakedIndexParam) {
|
---|
5664 | params.delete("index");
|
---|
5665 | indexValues.filter((v) => v).forEach((v) => params.append("index", v));
|
---|
5666 | let qs = params.toString();
|
---|
5667 | path.search = qs ? "?" + qs : "";
|
---|
5668 | }
|
---|
5669 | }
|
---|
5670 | if ((!action || action === ".") && match.route.index) {
|
---|
5671 | path.search = path.search ? path.search.replace(/^\?/, "?index&") : "?index";
|
---|
5672 | }
|
---|
5673 | if (basename !== "/") {
|
---|
5674 | path.pathname = path.pathname === "/" ? basename : joinPaths([basename, path.pathname]);
|
---|
5675 | }
|
---|
5676 | return createPath(path);
|
---|
5677 | }
|
---|
5678 | function useFetcher(_temp3) {
|
---|
5679 | var _route$matches;
|
---|
5680 | let {
|
---|
5681 | key
|
---|
5682 | } = _temp3 === void 0 ? {} : _temp3;
|
---|
5683 | let {
|
---|
5684 | router
|
---|
5685 | } = useDataRouterContext2(DataRouterHook2.UseFetcher);
|
---|
5686 | let state = useDataRouterState2(DataRouterStateHook2.UseFetcher);
|
---|
5687 | let fetcherData = React2.useContext(FetchersContext);
|
---|
5688 | let route = React2.useContext(RouteContext);
|
---|
5689 | let routeId = (_route$matches = route.matches[route.matches.length - 1]) == null ? void 0 : _route$matches.route.id;
|
---|
5690 | !fetcherData ? true ? invariant(false, "useFetcher must be used inside a FetchersContext") : invariant(false) : void 0;
|
---|
5691 | !route ? true ? invariant(false, "useFetcher must be used inside a RouteContext") : invariant(false) : void 0;
|
---|
5692 | !(routeId != null) ? true ? invariant(false, 'useFetcher can only be used on routes that contain a unique "id"') : invariant(false) : void 0;
|
---|
5693 | let defaultKey = useIdImpl ? useIdImpl() : "";
|
---|
5694 | let [fetcherKey, setFetcherKey] = React2.useState(key || defaultKey);
|
---|
5695 | if (key && key !== fetcherKey) {
|
---|
5696 | setFetcherKey(key);
|
---|
5697 | } else if (!fetcherKey) {
|
---|
5698 | setFetcherKey(getUniqueFetcherId());
|
---|
5699 | }
|
---|
5700 | React2.useEffect(() => {
|
---|
5701 | router.getFetcher(fetcherKey);
|
---|
5702 | return () => {
|
---|
5703 | router.deleteFetcher(fetcherKey);
|
---|
5704 | };
|
---|
5705 | }, [router, fetcherKey]);
|
---|
5706 | let load = React2.useCallback((href, opts) => {
|
---|
5707 | !routeId ? true ? invariant(false, "No routeId available for fetcher.load()") : invariant(false) : void 0;
|
---|
5708 | router.fetch(fetcherKey, routeId, href, opts);
|
---|
5709 | }, [fetcherKey, routeId, router]);
|
---|
5710 | let submitImpl = useSubmit();
|
---|
5711 | let submit = React2.useCallback((target, opts) => {
|
---|
5712 | submitImpl(target, _extends3({}, opts, {
|
---|
5713 | navigate: false,
|
---|
5714 | fetcherKey
|
---|
5715 | }));
|
---|
5716 | }, [fetcherKey, submitImpl]);
|
---|
5717 | let FetcherForm = React2.useMemo(() => {
|
---|
5718 | let FetcherForm2 = React2.forwardRef((props, ref) => {
|
---|
5719 | return React2.createElement(Form, _extends3({}, props, {
|
---|
5720 | navigate: false,
|
---|
5721 | fetcherKey,
|
---|
5722 | ref
|
---|
5723 | }));
|
---|
5724 | });
|
---|
5725 | if (true) {
|
---|
5726 | FetcherForm2.displayName = "fetcher.Form";
|
---|
5727 | }
|
---|
5728 | return FetcherForm2;
|
---|
5729 | }, [fetcherKey]);
|
---|
5730 | let fetcher = state.fetchers.get(fetcherKey) || IDLE_FETCHER;
|
---|
5731 | let data = fetcherData.get(fetcherKey);
|
---|
5732 | let fetcherWithComponents = React2.useMemo(() => _extends3({
|
---|
5733 | Form: FetcherForm,
|
---|
5734 | submit,
|
---|
5735 | load
|
---|
5736 | }, fetcher, {
|
---|
5737 | data
|
---|
5738 | }), [FetcherForm, submit, load, fetcher, data]);
|
---|
5739 | return fetcherWithComponents;
|
---|
5740 | }
|
---|
5741 | function useFetchers() {
|
---|
5742 | let state = useDataRouterState2(DataRouterStateHook2.UseFetchers);
|
---|
5743 | return Array.from(state.fetchers.entries()).map((_ref11) => {
|
---|
5744 | let [key, fetcher] = _ref11;
|
---|
5745 | return _extends3({}, fetcher, {
|
---|
5746 | key
|
---|
5747 | });
|
---|
5748 | });
|
---|
5749 | }
|
---|
5750 | var SCROLL_RESTORATION_STORAGE_KEY = "react-router-scroll-positions";
|
---|
5751 | var savedScrollPositions = {};
|
---|
5752 | function useScrollRestoration(_temp4) {
|
---|
5753 | let {
|
---|
5754 | getKey,
|
---|
5755 | storageKey
|
---|
5756 | } = _temp4 === void 0 ? {} : _temp4;
|
---|
5757 | let {
|
---|
5758 | router
|
---|
5759 | } = useDataRouterContext2(DataRouterHook2.UseScrollRestoration);
|
---|
5760 | let {
|
---|
5761 | restoreScrollPosition,
|
---|
5762 | preventScrollReset
|
---|
5763 | } = useDataRouterState2(DataRouterStateHook2.UseScrollRestoration);
|
---|
5764 | let {
|
---|
5765 | basename
|
---|
5766 | } = React2.useContext(NavigationContext);
|
---|
5767 | let location = useLocation();
|
---|
5768 | let matches = useMatches();
|
---|
5769 | let navigation = useNavigation();
|
---|
5770 | React2.useEffect(() => {
|
---|
5771 | window.history.scrollRestoration = "manual";
|
---|
5772 | return () => {
|
---|
5773 | window.history.scrollRestoration = "auto";
|
---|
5774 | };
|
---|
5775 | }, []);
|
---|
5776 | usePageHide(React2.useCallback(() => {
|
---|
5777 | if (navigation.state === "idle") {
|
---|
5778 | let key = (getKey ? getKey(location, matches) : null) || location.key;
|
---|
5779 | savedScrollPositions[key] = window.scrollY;
|
---|
5780 | }
|
---|
5781 | try {
|
---|
5782 | sessionStorage.setItem(storageKey || SCROLL_RESTORATION_STORAGE_KEY, JSON.stringify(savedScrollPositions));
|
---|
5783 | } catch (error) {
|
---|
5784 | true ? warning(false, "Failed to save scroll positions in sessionStorage, <ScrollRestoration /> will not work properly (" + error + ").") : void 0;
|
---|
5785 | }
|
---|
5786 | window.history.scrollRestoration = "auto";
|
---|
5787 | }, [storageKey, getKey, navigation.state, location, matches]));
|
---|
5788 | if (typeof document !== "undefined") {
|
---|
5789 | React2.useLayoutEffect(() => {
|
---|
5790 | try {
|
---|
5791 | let sessionPositions = sessionStorage.getItem(storageKey || SCROLL_RESTORATION_STORAGE_KEY);
|
---|
5792 | if (sessionPositions) {
|
---|
5793 | savedScrollPositions = JSON.parse(sessionPositions);
|
---|
5794 | }
|
---|
5795 | } catch (e) {
|
---|
5796 | }
|
---|
5797 | }, [storageKey]);
|
---|
5798 | React2.useLayoutEffect(() => {
|
---|
5799 | let getKeyWithoutBasename = getKey && basename !== "/" ? (location2, matches2) => getKey(
|
---|
5800 | // Strip the basename to match useLocation()
|
---|
5801 | _extends3({}, location2, {
|
---|
5802 | pathname: stripBasename(location2.pathname, basename) || location2.pathname
|
---|
5803 | }),
|
---|
5804 | matches2
|
---|
5805 | ) : getKey;
|
---|
5806 | let disableScrollRestoration = router == null ? void 0 : router.enableScrollRestoration(savedScrollPositions, () => window.scrollY, getKeyWithoutBasename);
|
---|
5807 | return () => disableScrollRestoration && disableScrollRestoration();
|
---|
5808 | }, [router, basename, getKey]);
|
---|
5809 | React2.useLayoutEffect(() => {
|
---|
5810 | if (restoreScrollPosition === false) {
|
---|
5811 | return;
|
---|
5812 | }
|
---|
5813 | if (typeof restoreScrollPosition === "number") {
|
---|
5814 | window.scrollTo(0, restoreScrollPosition);
|
---|
5815 | return;
|
---|
5816 | }
|
---|
5817 | if (location.hash) {
|
---|
5818 | let el = document.getElementById(decodeURIComponent(location.hash.slice(1)));
|
---|
5819 | if (el) {
|
---|
5820 | el.scrollIntoView();
|
---|
5821 | return;
|
---|
5822 | }
|
---|
5823 | }
|
---|
5824 | if (preventScrollReset === true) {
|
---|
5825 | return;
|
---|
5826 | }
|
---|
5827 | window.scrollTo(0, 0);
|
---|
5828 | }, [location, restoreScrollPosition, preventScrollReset]);
|
---|
5829 | }
|
---|
5830 | }
|
---|
5831 | function useBeforeUnload(callback, options) {
|
---|
5832 | let {
|
---|
5833 | capture
|
---|
5834 | } = options || {};
|
---|
5835 | React2.useEffect(() => {
|
---|
5836 | let opts = capture != null ? {
|
---|
5837 | capture
|
---|
5838 | } : void 0;
|
---|
5839 | window.addEventListener("beforeunload", callback, opts);
|
---|
5840 | return () => {
|
---|
5841 | window.removeEventListener("beforeunload", callback, opts);
|
---|
5842 | };
|
---|
5843 | }, [callback, capture]);
|
---|
5844 | }
|
---|
5845 | function usePageHide(callback, options) {
|
---|
5846 | let {
|
---|
5847 | capture
|
---|
5848 | } = options || {};
|
---|
5849 | React2.useEffect(() => {
|
---|
5850 | let opts = capture != null ? {
|
---|
5851 | capture
|
---|
5852 | } : void 0;
|
---|
5853 | window.addEventListener("pagehide", callback, opts);
|
---|
5854 | return () => {
|
---|
5855 | window.removeEventListener("pagehide", callback, opts);
|
---|
5856 | };
|
---|
5857 | }, [callback, capture]);
|
---|
5858 | }
|
---|
5859 | function usePrompt(_ref12) {
|
---|
5860 | let {
|
---|
5861 | when,
|
---|
5862 | message
|
---|
5863 | } = _ref12;
|
---|
5864 | let blocker = useBlocker(when);
|
---|
5865 | React2.useEffect(() => {
|
---|
5866 | if (blocker.state === "blocked") {
|
---|
5867 | let proceed = window.confirm(message);
|
---|
5868 | if (proceed) {
|
---|
5869 | setTimeout(blocker.proceed, 0);
|
---|
5870 | } else {
|
---|
5871 | blocker.reset();
|
---|
5872 | }
|
---|
5873 | }
|
---|
5874 | }, [blocker, message]);
|
---|
5875 | React2.useEffect(() => {
|
---|
5876 | if (blocker.state === "blocked" && !when) {
|
---|
5877 | blocker.reset();
|
---|
5878 | }
|
---|
5879 | }, [blocker, when]);
|
---|
5880 | }
|
---|
5881 | function useViewTransitionState(to, opts) {
|
---|
5882 | if (opts === void 0) {
|
---|
5883 | opts = {};
|
---|
5884 | }
|
---|
5885 | let vtContext = React2.useContext(ViewTransitionContext);
|
---|
5886 | !(vtContext != null) ? true ? invariant(false, "`useViewTransitionState` must be used within `react-router-dom`'s `RouterProvider`. Did you accidentally import `RouterProvider` from `react-router`?") : invariant(false) : void 0;
|
---|
5887 | let {
|
---|
5888 | basename
|
---|
5889 | } = useDataRouterContext2(DataRouterHook2.useViewTransitionState);
|
---|
5890 | let path = useResolvedPath(to, {
|
---|
5891 | relative: opts.relative
|
---|
5892 | });
|
---|
5893 | if (!vtContext.isTransitioning) {
|
---|
5894 | return false;
|
---|
5895 | }
|
---|
5896 | let currentPath = stripBasename(vtContext.currentLocation.pathname, basename) || vtContext.currentLocation.pathname;
|
---|
5897 | let nextPath = stripBasename(vtContext.nextLocation.pathname, basename) || vtContext.nextLocation.pathname;
|
---|
5898 | return matchPath(path.pathname, nextPath) != null || matchPath(path.pathname, currentPath) != null;
|
---|
5899 | }
|
---|
5900 | export {
|
---|
5901 | AbortedDeferredError,
|
---|
5902 | Await,
|
---|
5903 | BrowserRouter,
|
---|
5904 | Form,
|
---|
5905 | HashRouter,
|
---|
5906 | Link,
|
---|
5907 | MemoryRouter,
|
---|
5908 | NavLink,
|
---|
5909 | Navigate,
|
---|
5910 | Action as NavigationType,
|
---|
5911 | Outlet,
|
---|
5912 | Route,
|
---|
5913 | Router,
|
---|
5914 | RouterProvider,
|
---|
5915 | Routes,
|
---|
5916 | ScrollRestoration,
|
---|
5917 | DataRouterContext as UNSAFE_DataRouterContext,
|
---|
5918 | DataRouterStateContext as UNSAFE_DataRouterStateContext,
|
---|
5919 | ErrorResponseImpl as UNSAFE_ErrorResponseImpl,
|
---|
5920 | FetchersContext as UNSAFE_FetchersContext,
|
---|
5921 | LocationContext as UNSAFE_LocationContext,
|
---|
5922 | NavigationContext as UNSAFE_NavigationContext,
|
---|
5923 | RouteContext as UNSAFE_RouteContext,
|
---|
5924 | ViewTransitionContext as UNSAFE_ViewTransitionContext,
|
---|
5925 | useRouteId as UNSAFE_useRouteId,
|
---|
5926 | useScrollRestoration as UNSAFE_useScrollRestoration,
|
---|
5927 | createBrowserRouter,
|
---|
5928 | createHashRouter,
|
---|
5929 | createMemoryRouter,
|
---|
5930 | createPath,
|
---|
5931 | createRoutesFromChildren,
|
---|
5932 | createRoutesFromChildren as createRoutesFromElements,
|
---|
5933 | createSearchParams,
|
---|
5934 | defer,
|
---|
5935 | generatePath,
|
---|
5936 | isRouteErrorResponse,
|
---|
5937 | json,
|
---|
5938 | matchPath,
|
---|
5939 | matchRoutes,
|
---|
5940 | parsePath,
|
---|
5941 | redirect,
|
---|
5942 | redirectDocument,
|
---|
5943 | renderMatches,
|
---|
5944 | replace,
|
---|
5945 | resolvePath,
|
---|
5946 | HistoryRouter as unstable_HistoryRouter,
|
---|
5947 | usePrompt as unstable_usePrompt,
|
---|
5948 | useActionData,
|
---|
5949 | useAsyncError,
|
---|
5950 | useAsyncValue,
|
---|
5951 | useBeforeUnload,
|
---|
5952 | useBlocker,
|
---|
5953 | useFetcher,
|
---|
5954 | useFetchers,
|
---|
5955 | useFormAction,
|
---|
5956 | useHref,
|
---|
5957 | useInRouterContext,
|
---|
5958 | useLinkClickHandler,
|
---|
5959 | useLoaderData,
|
---|
5960 | useLocation,
|
---|
5961 | useMatch,
|
---|
5962 | useMatches,
|
---|
5963 | useNavigate,
|
---|
5964 | useNavigation,
|
---|
5965 | useNavigationType,
|
---|
5966 | useOutlet,
|
---|
5967 | useOutletContext,
|
---|
5968 | useParams,
|
---|
5969 | useResolvedPath,
|
---|
5970 | useRevalidator,
|
---|
5971 | useRouteError,
|
---|
5972 | useRouteLoaderData,
|
---|
5973 | useRoutes,
|
---|
5974 | useSearchParams,
|
---|
5975 | useSubmit,
|
---|
5976 | useViewTransitionState
|
---|
5977 | };
|
---|
5978 | /*! Bundled license information:
|
---|
5979 |
|
---|
5980 | @remix-run/router/dist/router.js:
|
---|
5981 | (**
|
---|
5982 | * @remix-run/router v1.21.0
|
---|
5983 | *
|
---|
5984 | * Copyright (c) Remix Software Inc.
|
---|
5985 | *
|
---|
5986 | * This source code is licensed under the MIT license found in the
|
---|
5987 | * LICENSE.md file in the root directory of this source tree.
|
---|
5988 | *
|
---|
5989 | * @license MIT
|
---|
5990 | *)
|
---|
5991 |
|
---|
5992 | react-router/dist/index.js:
|
---|
5993 | (**
|
---|
5994 | * React Router v6.28.0
|
---|
5995 | *
|
---|
5996 | * Copyright (c) Remix Software Inc.
|
---|
5997 | *
|
---|
5998 | * This source code is licensed under the MIT license found in the
|
---|
5999 | * LICENSE.md file in the root directory of this source tree.
|
---|
6000 | *
|
---|
6001 | * @license MIT
|
---|
6002 | *)
|
---|
6003 |
|
---|
6004 | react-router-dom/dist/index.js:
|
---|
6005 | (**
|
---|
6006 | * React Router DOM v6.28.0
|
---|
6007 | *
|
---|
6008 | * Copyright (c) Remix Software Inc.
|
---|
6009 | *
|
---|
6010 | * This source code is licensed under the MIT license found in the
|
---|
6011 | * LICENSE.md file in the root directory of this source tree.
|
---|
6012 | *
|
---|
6013 | * @license MIT
|
---|
6014 | *)
|
---|
6015 | */
|
---|
6016 | //# sourceMappingURL=react-router-dom.js.map
|
---|