| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 |
|
| 11 | (function (global, factory) {
|
| 12 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@remix-run/router'), require('react')) :
|
| 13 | typeof define === 'function' && define.amd ? define(['exports', '@remix-run/router', 'react'], factory) :
|
| 14 | (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactRouter = {}, global.RemixRouter, global.React));
|
| 15 | })(this, (function (exports, router, React) { 'use strict';
|
| 16 |
|
| 17 | function _interopNamespace(e) {
|
| 18 | if (e && e.__esModule) return e;
|
| 19 | var n = Object.create(null);
|
| 20 | if (e) {
|
| 21 | Object.keys(e).forEach(function (k) {
|
| 22 | if (k !== 'default') {
|
| 23 | var d = Object.getOwnPropertyDescriptor(e, k);
|
| 24 | Object.defineProperty(n, k, d.get ? d : {
|
| 25 | enumerable: true,
|
| 26 | get: function () { return e[k]; }
|
| 27 | });
|
| 28 | }
|
| 29 | });
|
| 30 | }
|
| 31 | n["default"] = e;
|
| 32 | return Object.freeze(n);
|
| 33 | }
|
| 34 |
|
| 35 | var React__namespace = _interopNamespace(React);
|
| 36 |
|
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 |
|
| 43 | |
| 44 | |
| 45 | |
| 46 |
|
| 47 |
|
| 48 | function isPolyfill(x, y) {
|
| 49 | return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y
|
| 50 | ;
|
| 51 | }
|
| 52 |
|
| 53 | const is = typeof Object.is === "function" ? Object.is : isPolyfill;
|
| 54 |
|
| 55 |
|
| 56 | const {
|
| 57 | useState,
|
| 58 | useEffect,
|
| 59 | useLayoutEffect,
|
| 60 | useDebugValue
|
| 61 | } = React__namespace;
|
| 62 | let didWarnOld18Alpha = false;
|
| 63 | let didWarnUncachedGetSnapshot = false;
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 | function useSyncExternalStore$2(subscribe, getSnapshot, // Note: The shim does not use getServerSnapshot, because pre-18 versions of
|
| 75 | // React do not expose a way to check if we're hydrating. So users of the shim
|
| 76 |
|
| 77 |
|
| 78 | getServerSnapshot) {
|
| 79 | {
|
| 80 | if (!didWarnOld18Alpha) {
|
| 81 | if ("startTransition" in React__namespace) {
|
| 82 | didWarnOld18Alpha = true;
|
| 83 | console.error("You are using an outdated, pre-release alpha of React 18 that " + "does not support useSyncExternalStore. The " + "use-sync-external-store shim will not work correctly. Upgrade " + "to a newer pre-release.");
|
| 84 | }
|
| 85 | }
|
| 86 | }
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 | const value = getSnapshot();
|
| 93 |
|
| 94 | {
|
| 95 | if (!didWarnUncachedGetSnapshot) {
|
| 96 | const cachedValue = getSnapshot();
|
| 97 |
|
| 98 | if (!is(value, cachedValue)) {
|
| 99 | console.error("The result of getSnapshot should be cached to avoid an infinite loop");
|
| 100 | didWarnUncachedGetSnapshot = true;
|
| 101 | }
|
| 102 | }
|
| 103 | }
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 | const [{
|
| 120 | inst
|
| 121 | }, forceUpdate] = useState({
|
| 122 | inst: {
|
| 123 | value,
|
| 124 | getSnapshot
|
| 125 | }
|
| 126 | });
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 | useLayoutEffect(() => {
|
| 131 | inst.value = value;
|
| 132 | inst.getSnapshot = getSnapshot;
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 | if (checkIfSnapshotChanged(inst)) {
|
| 138 |
|
| 139 | forceUpdate({
|
| 140 | inst
|
| 141 | });
|
| 142 | }
|
| 143 |
|
| 144 | }, [subscribe, value, getSnapshot]);
|
| 145 | useEffect(() => {
|
| 146 |
|
| 147 |
|
| 148 | if (checkIfSnapshotChanged(inst)) {
|
| 149 |
|
| 150 | forceUpdate({
|
| 151 | inst
|
| 152 | });
|
| 153 | }
|
| 154 |
|
| 155 | const handleStoreChange = () => {
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 | if (checkIfSnapshotChanged(inst)) {
|
| 163 |
|
| 164 | forceUpdate({
|
| 165 | inst
|
| 166 | });
|
| 167 | }
|
| 168 | };
|
| 169 |
|
| 170 |
|
| 171 | return subscribe(handleStoreChange);
|
| 172 | }, [subscribe]);
|
| 173 | useDebugValue(value);
|
| 174 | return value;
|
| 175 | }
|
| 176 |
|
| 177 | function checkIfSnapshotChanged(inst) {
|
| 178 | const latestGetSnapshot = inst.getSnapshot;
|
| 179 | const prevValue = inst.value;
|
| 180 |
|
| 181 | try {
|
| 182 | const nextValue = latestGetSnapshot();
|
| 183 | return !is(prevValue, nextValue);
|
| 184 | } catch (error) {
|
| 185 | return true;
|
| 186 | }
|
| 187 | }
|
| 188 |
|
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 |
|
| 197 | function useSyncExternalStore$1(subscribe, getSnapshot, getServerSnapshot) {
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 | return getSnapshot();
|
| 203 | }
|
| 204 |
|
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 |
|
| 210 | const canUseDOM = !!(typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined");
|
| 211 | const isServerEnvironment = !canUseDOM;
|
| 212 | const shim = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore$2;
|
| 213 | const useSyncExternalStore = "useSyncExternalStore" in React__namespace ? (module => module.useSyncExternalStore)(React__namespace) : shim;
|
| 214 |
|
| 215 | const DataRouterContext = React__namespace.createContext(null);
|
| 216 |
|
| 217 | {
|
| 218 | DataRouterContext.displayName = "DataRouter";
|
| 219 | }
|
| 220 |
|
| 221 | const DataRouterStateContext = React__namespace.createContext(null);
|
| 222 |
|
| 223 | {
|
| 224 | DataRouterStateContext.displayName = "DataRouterState";
|
| 225 | }
|
| 226 |
|
| 227 | const AwaitContext = React__namespace.createContext(null);
|
| 228 |
|
| 229 | {
|
| 230 | AwaitContext.displayName = "Await";
|
| 231 | }
|
| 232 |
|
| 233 | const NavigationContext = React__namespace.createContext(null);
|
| 234 |
|
| 235 | {
|
| 236 | NavigationContext.displayName = "Navigation";
|
| 237 | }
|
| 238 |
|
| 239 | const LocationContext = React__namespace.createContext(null);
|
| 240 |
|
| 241 | {
|
| 242 | LocationContext.displayName = "Location";
|
| 243 | }
|
| 244 |
|
| 245 | const RouteContext = React__namespace.createContext({
|
| 246 | outlet: null,
|
| 247 | matches: []
|
| 248 | });
|
| 249 |
|
| 250 | {
|
| 251 | RouteContext.displayName = "Route";
|
| 252 | }
|
| 253 |
|
| 254 | const RouteErrorContext = React__namespace.createContext(null);
|
| 255 |
|
| 256 | {
|
| 257 | RouteErrorContext.displayName = "RouteError";
|
| 258 | }
|
| 259 |
|
| 260 | function _extends() {
|
| 261 | _extends = Object.assign ? Object.assign.bind() : function (target) {
|
| 262 | for (var i = 1; i < arguments.length; i++) {
|
| 263 | var source = arguments[i];
|
| 264 |
|
| 265 | for (var key in source) {
|
| 266 | if (Object.prototype.hasOwnProperty.call(source, key)) {
|
| 267 | target[key] = source[key];
|
| 268 | }
|
| 269 | }
|
| 270 | }
|
| 271 |
|
| 272 | return target;
|
| 273 | };
|
| 274 | return _extends.apply(this, arguments);
|
| 275 | }
|
| 276 |
|
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 |
|
| 283 |
|
| 284 | function useHref(to, _temp) {
|
| 285 | let {
|
| 286 | relative
|
| 287 | } = _temp === void 0 ? {} : _temp;
|
| 288 | !useInRouterContext() ? router.UNSAFE_invariant(false,
|
| 289 |
|
| 290 | "useHref() may be used only in the context of a <Router> component.") : void 0;
|
| 291 | let {
|
| 292 | basename,
|
| 293 | navigator
|
| 294 | } = React__namespace.useContext(NavigationContext);
|
| 295 | let {
|
| 296 | hash,
|
| 297 | pathname,
|
| 298 | search
|
| 299 | } = useResolvedPath(to, {
|
| 300 | relative
|
| 301 | });
|
| 302 | let joinedPathname = pathname;
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 | if (basename !== "/") {
|
| 308 | joinedPathname = pathname === "/" ? basename : router.joinPaths([basename, pathname]);
|
| 309 | }
|
| 310 |
|
| 311 | return navigator.createHref({
|
| 312 | pathname: joinedPathname,
|
| 313 | search,
|
| 314 | hash
|
| 315 | });
|
| 316 | }
|
| 317 | |
| 318 | |
| 319 | |
| 320 | |
| 321 |
|
| 322 |
|
| 323 | function useInRouterContext() {
|
| 324 | return React__namespace.useContext(LocationContext) != null;
|
| 325 | }
|
| 326 | |
| 327 | |
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | |
| 333 | |
| 334 | |
| 335 |
|
| 336 |
|
| 337 | function useLocation() {
|
| 338 | !useInRouterContext() ? router.UNSAFE_invariant(false,
|
| 339 |
|
| 340 | "useLocation() may be used only in the context of a <Router> component.") : void 0;
|
| 341 | return React__namespace.useContext(LocationContext).location;
|
| 342 | }
|
| 343 | |
| 344 | |
| 345 | |
| 346 | |
| 347 | |
| 348 |
|
| 349 |
|
| 350 | function useNavigationType() {
|
| 351 | return React__namespace.useContext(LocationContext).navigationType;
|
| 352 | }
|
| 353 | |
| 354 | |
| 355 | |
| 356 | |
| 357 | |
| 358 | |
| 359 |
|
| 360 |
|
| 361 | function useMatch(pattern) {
|
| 362 | !useInRouterContext() ? router.UNSAFE_invariant(false,
|
| 363 |
|
| 364 | "useMatch() may be used only in the context of a <Router> component.") : void 0;
|
| 365 | let {
|
| 366 | pathname
|
| 367 | } = useLocation();
|
| 368 | return React__namespace.useMemo(() => router.matchPath(pattern, pathname), [pathname, pattern]);
|
| 369 | }
|
| 370 | |
| 371 | |
| 372 |
|
| 373 |
|
| 374 | |
| 375 | |
| 376 | |
| 377 | |
| 378 | |
| 379 |
|
| 380 | function useNavigate() {
|
| 381 | !useInRouterContext() ? router.UNSAFE_invariant(false,
|
| 382 |
|
| 383 | "useNavigate() may be used only in the context of a <Router> component.") : void 0;
|
| 384 | let {
|
| 385 | basename,
|
| 386 | navigator
|
| 387 | } = React__namespace.useContext(NavigationContext);
|
| 388 | let {
|
| 389 | matches
|
| 390 | } = React__namespace.useContext(RouteContext);
|
| 391 | let {
|
| 392 | pathname: locationPathname
|
| 393 | } = useLocation();
|
| 394 | let routePathnamesJson = JSON.stringify(router.UNSAFE_getPathContributingMatches(matches).map(match => match.pathnameBase));
|
| 395 | let activeRef = React__namespace.useRef(false);
|
| 396 | React__namespace.useEffect(() => {
|
| 397 | activeRef.current = true;
|
| 398 | });
|
| 399 | let navigate = React__namespace.useCallback(function (to, options) {
|
| 400 | if (options === void 0) {
|
| 401 | options = {};
|
| 402 | }
|
| 403 |
|
| 404 | router.UNSAFE_warning(activeRef.current, "You should call navigate() in a React.useEffect(), not when " + "your component is first rendered.") ;
|
| 405 | if (!activeRef.current) return;
|
| 406 |
|
| 407 | if (typeof to === "number") {
|
| 408 | navigator.go(to);
|
| 409 | return;
|
| 410 | }
|
| 411 |
|
| 412 | let path = router.resolveTo(to, JSON.parse(routePathnamesJson), locationPathname, options.relative === "path");
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 | if (basename !== "/") {
|
| 418 | path.pathname = path.pathname === "/" ? basename : router.joinPaths([basename, path.pathname]);
|
| 419 | }
|
| 420 |
|
| 421 | (!!options.replace ? navigator.replace : navigator.push)(path, options.state, options);
|
| 422 | }, [basename, navigator, routePathnamesJson, locationPathname]);
|
| 423 | return navigate;
|
| 424 | }
|
| 425 | const OutletContext = React__namespace.createContext(null);
|
| 426 | |
| 427 | |
| 428 | |
| 429 | |
| 430 |
|
| 431 |
|
| 432 | function useOutletContext() {
|
| 433 | return React__namespace.useContext(OutletContext);
|
| 434 | }
|
| 435 | |
| 436 | |
| 437 | |
| 438 | |
| 439 | |
| 440 |
|
| 441 |
|
| 442 | function useOutlet(context) {
|
| 443 | let outlet = React__namespace.useContext(RouteContext).outlet;
|
| 444 |
|
| 445 | if (outlet) {
|
| 446 | return React__namespace.createElement(OutletContext.Provider, {
|
| 447 | value: context
|
| 448 | }, outlet);
|
| 449 | }
|
| 450 |
|
| 451 | return outlet;
|
| 452 | }
|
| 453 | |
| 454 | |
| 455 | |
| 456 | |
| 457 | |
| 458 |
|
| 459 |
|
| 460 | function useParams() {
|
| 461 | let {
|
| 462 | matches
|
| 463 | } = React__namespace.useContext(RouteContext);
|
| 464 | let routeMatch = matches[matches.length - 1];
|
| 465 | return routeMatch ? routeMatch.params : {};
|
| 466 | }
|
| 467 | |
| 468 | |
| 469 | |
| 470 | |
| 471 |
|
| 472 |
|
| 473 | function useResolvedPath(to, _temp2) {
|
| 474 | let {
|
| 475 | relative
|
| 476 | } = _temp2 === void 0 ? {} : _temp2;
|
| 477 | let {
|
| 478 | matches
|
| 479 | } = React__namespace.useContext(RouteContext);
|
| 480 | let {
|
| 481 | pathname: locationPathname
|
| 482 | } = useLocation();
|
| 483 | let routePathnamesJson = JSON.stringify(router.UNSAFE_getPathContributingMatches(matches).map(match => match.pathnameBase));
|
| 484 | return React__namespace.useMemo(() => router.resolveTo(to, JSON.parse(routePathnamesJson), locationPathname, relative === "path"), [to, routePathnamesJson, locationPathname, relative]);
|
| 485 | }
|
| 486 | |
| 487 | |
| 488 | |
| 489 | |
| 490 | |
| 491 | |
| 492 | |
| 493 |
|
| 494 |
|
| 495 | function useRoutes(routes, locationArg) {
|
| 496 | !useInRouterContext() ? router.UNSAFE_invariant(false,
|
| 497 |
|
| 498 | "useRoutes() may be used only in the context of a <Router> component.") : void 0;
|
| 499 | let {
|
| 500 | navigator
|
| 501 | } = React__namespace.useContext(NavigationContext);
|
| 502 | let dataRouterStateContext = React__namespace.useContext(DataRouterStateContext);
|
| 503 | let {
|
| 504 | matches: parentMatches
|
| 505 | } = React__namespace.useContext(RouteContext);
|
| 506 | let routeMatch = parentMatches[parentMatches.length - 1];
|
| 507 | let parentParams = routeMatch ? routeMatch.params : {};
|
| 508 | let parentPathname = routeMatch ? routeMatch.pathname : "/";
|
| 509 | let parentPathnameBase = routeMatch ? routeMatch.pathnameBase : "/";
|
| 510 | let parentRoute = routeMatch && routeMatch.route;
|
| 511 |
|
| 512 | {
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 | let parentPath = parentRoute && parentRoute.path || "";
|
| 534 | 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.\n\n" + ("Please change the parent <Route path=\"" + parentPath + "\"> to <Route ") + ("path=\"" + (parentPath === "/" ? "*" : parentPath + "/*") + "\">."));
|
| 535 | }
|
| 536 |
|
| 537 | let locationFromContext = useLocation();
|
| 538 | let location;
|
| 539 |
|
| 540 | if (locationArg) {
|
| 541 | var _parsedLocationArg$pa;
|
| 542 |
|
| 543 | let parsedLocationArg = typeof locationArg === "string" ? router.parsePath(locationArg) : locationArg;
|
| 544 | !(parentPathnameBase === "/" || ((_parsedLocationArg$pa = parsedLocationArg.pathname) == null ? void 0 : _parsedLocationArg$pa.startsWith(parentPathnameBase))) ? router.UNSAFE_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.")) : void 0;
|
| 545 | location = parsedLocationArg;
|
| 546 | } else {
|
| 547 | location = locationFromContext;
|
| 548 | }
|
| 549 |
|
| 550 | let pathname = location.pathname || "/";
|
| 551 | let remainingPathname = parentPathnameBase === "/" ? pathname : pathname.slice(parentPathnameBase.length) || "/";
|
| 552 | let matches = router.matchRoutes(routes, {
|
| 553 | pathname: remainingPathname
|
| 554 | });
|
| 555 |
|
| 556 | {
|
| 557 | router.UNSAFE_warning(parentRoute || matches != null, "No routes matched location \"" + location.pathname + location.search + location.hash + "\" ") ;
|
| 558 | router.UNSAFE_warning(matches == null || matches[matches.length - 1].route.element !== undefined || matches[matches.length - 1].route.Component !== undefined, "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.") ;
|
| 559 | }
|
| 560 |
|
| 561 | let renderedMatches = _renderMatches(matches && matches.map(match => Object.assign({}, match, {
|
| 562 | params: Object.assign({}, parentParams, match.params),
|
| 563 | pathname: router.joinPaths([parentPathnameBase,
|
| 564 | navigator.encodeLocation ? navigator.encodeLocation(match.pathname).pathname : match.pathname]),
|
| 565 | pathnameBase: match.pathnameBase === "/" ? parentPathnameBase : router.joinPaths([parentPathnameBase,
|
| 566 | navigator.encodeLocation ? navigator.encodeLocation(match.pathnameBase).pathname : match.pathnameBase])
|
| 567 | })), parentMatches, dataRouterStateContext || undefined);
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 | if (locationArg && renderedMatches) {
|
| 573 | return React__namespace.createElement(LocationContext.Provider, {
|
| 574 | value: {
|
| 575 | location: _extends({
|
| 576 | pathname: "/",
|
| 577 | search: "",
|
| 578 | hash: "",
|
| 579 | state: null,
|
| 580 | key: "default"
|
| 581 | }, location),
|
| 582 | navigationType: router.Action.Pop
|
| 583 | }
|
| 584 | }, renderedMatches);
|
| 585 | }
|
| 586 |
|
| 587 | return renderedMatches;
|
| 588 | }
|
| 589 |
|
| 590 | function DefaultErrorComponent() {
|
| 591 | let error = useRouteError();
|
| 592 | let message = router.isRouteErrorResponse(error) ? error.status + " " + error.statusText : error instanceof Error ? error.message : JSON.stringify(error);
|
| 593 | let stack = error instanceof Error ? error.stack : null;
|
| 594 | let lightgrey = "rgba(200,200,200, 0.5)";
|
| 595 | let preStyles = {
|
| 596 | padding: "0.5rem",
|
| 597 | backgroundColor: lightgrey
|
| 598 | };
|
| 599 | let codeStyles = {
|
| 600 | padding: "2px 4px",
|
| 601 | backgroundColor: lightgrey
|
| 602 | };
|
| 603 | let devInfo = null;
|
| 604 |
|
| 605 | {
|
| 606 | devInfo = React__namespace.createElement(React__namespace.Fragment, null, React__namespace.createElement("p", null, "\uD83D\uDCBF Hey developer \uD83D\uDC4B"), React__namespace.createElement("p", null, "You can provide a way better UX than this when your app throws errors by providing your own\xA0", React__namespace.createElement("code", {
|
| 607 | style: codeStyles
|
| 608 | }, "ErrorBoundary"), " prop on\xA0", React__namespace.createElement("code", {
|
| 609 | style: codeStyles
|
| 610 | }, "<Route>")));
|
| 611 | }
|
| 612 |
|
| 613 | return React__namespace.createElement(React__namespace.Fragment, null, React__namespace.createElement("h2", null, "Unexpected Application Error!"), React__namespace.createElement("h3", {
|
| 614 | style: {
|
| 615 | fontStyle: "italic"
|
| 616 | }
|
| 617 | }, message), stack ? React__namespace.createElement("pre", {
|
| 618 | style: preStyles
|
| 619 | }, stack) : null, devInfo);
|
| 620 | }
|
| 621 |
|
| 622 | class RenderErrorBoundary extends React__namespace.Component {
|
| 623 | constructor(props) {
|
| 624 | super(props);
|
| 625 | this.state = {
|
| 626 | location: props.location,
|
| 627 | error: props.error
|
| 628 | };
|
| 629 | }
|
| 630 |
|
| 631 | static getDerivedStateFromError(error) {
|
| 632 | return {
|
| 633 | error: error
|
| 634 | };
|
| 635 | }
|
| 636 |
|
| 637 | static getDerivedStateFromProps(props, state) {
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 | if (state.location !== props.location) {
|
| 647 | return {
|
| 648 | error: props.error,
|
| 649 | location: props.location
|
| 650 | };
|
| 651 | }
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 | return {
|
| 658 | error: props.error || state.error,
|
| 659 | location: state.location
|
| 660 | };
|
| 661 | }
|
| 662 |
|
| 663 | componentDidCatch(error, errorInfo) {
|
| 664 | console.error("React Router caught the following error during render", error, errorInfo);
|
| 665 | }
|
| 666 |
|
| 667 | render() {
|
| 668 | return this.state.error ? React__namespace.createElement(RouteContext.Provider, {
|
| 669 | value: this.props.routeContext
|
| 670 | }, React__namespace.createElement(RouteErrorContext.Provider, {
|
| 671 | value: this.state.error,
|
| 672 | children: this.props.component
|
| 673 | })) : this.props.children;
|
| 674 | }
|
| 675 |
|
| 676 | }
|
| 677 |
|
| 678 | function RenderedRoute(_ref) {
|
| 679 | let {
|
| 680 | routeContext,
|
| 681 | match,
|
| 682 | children
|
| 683 | } = _ref;
|
| 684 | let dataRouterContext = React__namespace.useContext(DataRouterContext);
|
| 685 |
|
| 686 |
|
| 687 | if (dataRouterContext && dataRouterContext.static && dataRouterContext.staticContext && (match.route.errorElement || match.route.ErrorBoundary)) {
|
| 688 | dataRouterContext.staticContext._deepestRenderedBoundaryId = match.route.id;
|
| 689 | }
|
| 690 |
|
| 691 | return React__namespace.createElement(RouteContext.Provider, {
|
| 692 | value: routeContext
|
| 693 | }, children);
|
| 694 | }
|
| 695 |
|
| 696 | function _renderMatches(matches, parentMatches, dataRouterState) {
|
| 697 | if (parentMatches === void 0) {
|
| 698 | parentMatches = [];
|
| 699 | }
|
| 700 |
|
| 701 | if (matches == null) {
|
| 702 | if (dataRouterState != null && dataRouterState.errors) {
|
| 703 |
|
| 704 |
|
| 705 | matches = dataRouterState.matches;
|
| 706 | } else {
|
| 707 | return null;
|
| 708 | }
|
| 709 | }
|
| 710 |
|
| 711 | let renderedMatches = matches;
|
| 712 |
|
| 713 | let errors = dataRouterState == null ? void 0 : dataRouterState.errors;
|
| 714 |
|
| 715 | if (errors != null) {
|
| 716 | let errorIndex = renderedMatches.findIndex(m => m.route.id && (errors == null ? void 0 : errors[m.route.id]));
|
| 717 | !(errorIndex >= 0) ? router.UNSAFE_invariant(false, "Could not find a matching route for the current errors: " + errors) : void 0;
|
| 718 | renderedMatches = renderedMatches.slice(0, Math.min(renderedMatches.length, errorIndex + 1));
|
| 719 | }
|
| 720 |
|
| 721 | return renderedMatches.reduceRight((outlet, match, index) => {
|
| 722 | let error = match.route.id ? errors == null ? void 0 : errors[match.route.id] : null;
|
| 723 |
|
| 724 | let errorElement = null;
|
| 725 |
|
| 726 | if (dataRouterState) {
|
| 727 | if (match.route.ErrorBoundary) {
|
| 728 | errorElement = React__namespace.createElement(match.route.ErrorBoundary, null);
|
| 729 | } else if (match.route.errorElement) {
|
| 730 | errorElement = match.route.errorElement;
|
| 731 | } else {
|
| 732 | errorElement = React__namespace.createElement(DefaultErrorComponent, null);
|
| 733 | }
|
| 734 | }
|
| 735 |
|
| 736 | let matches = parentMatches.concat(renderedMatches.slice(0, index + 1));
|
| 737 |
|
| 738 | let getChildren = () => {
|
| 739 | let children = outlet;
|
| 740 |
|
| 741 | if (error) {
|
| 742 | children = errorElement;
|
| 743 | } else if (match.route.Component) {
|
| 744 | children = React__namespace.createElement(match.route.Component, null);
|
| 745 | } else if (match.route.element) {
|
| 746 | children = match.route.element;
|
| 747 | }
|
| 748 |
|
| 749 | return React__namespace.createElement(RenderedRoute, {
|
| 750 | match: match,
|
| 751 | routeContext: {
|
| 752 | outlet,
|
| 753 | matches
|
| 754 | },
|
| 755 | children: children
|
| 756 | });
|
| 757 | };
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 | return dataRouterState && (match.route.ErrorBoundary || match.route.errorElement || index === 0) ? React__namespace.createElement(RenderErrorBoundary, {
|
| 763 | location: dataRouterState.location,
|
| 764 | component: errorElement,
|
| 765 | error: error,
|
| 766 | children: getChildren(),
|
| 767 | routeContext: {
|
| 768 | outlet: null,
|
| 769 | matches
|
| 770 | }
|
| 771 | }) : getChildren();
|
| 772 | }, null);
|
| 773 | }
|
| 774 | var DataRouterHook;
|
| 775 |
|
| 776 | (function (DataRouterHook) {
|
| 777 | DataRouterHook["UseBlocker"] = "useBlocker";
|
| 778 | DataRouterHook["UseRevalidator"] = "useRevalidator";
|
| 779 | })(DataRouterHook || (DataRouterHook = {}));
|
| 780 |
|
| 781 | var DataRouterStateHook;
|
| 782 |
|
| 783 | (function (DataRouterStateHook) {
|
| 784 | DataRouterStateHook["UseBlocker"] = "useBlocker";
|
| 785 | DataRouterStateHook["UseLoaderData"] = "useLoaderData";
|
| 786 | DataRouterStateHook["UseActionData"] = "useActionData";
|
| 787 | DataRouterStateHook["UseRouteError"] = "useRouteError";
|
| 788 | DataRouterStateHook["UseNavigation"] = "useNavigation";
|
| 789 | DataRouterStateHook["UseRouteLoaderData"] = "useRouteLoaderData";
|
| 790 | DataRouterStateHook["UseMatches"] = "useMatches";
|
| 791 | DataRouterStateHook["UseRevalidator"] = "useRevalidator";
|
| 792 | })(DataRouterStateHook || (DataRouterStateHook = {}));
|
| 793 |
|
| 794 | function getDataRouterConsoleError(hookName) {
|
| 795 | return hookName + " must be used within a data router. See https://reactrouter.com/routers/picking-a-router.";
|
| 796 | }
|
| 797 |
|
| 798 | function useDataRouterContext(hookName) {
|
| 799 | let ctx = React__namespace.useContext(DataRouterContext);
|
| 800 | !ctx ? router.UNSAFE_invariant(false, getDataRouterConsoleError(hookName)) : void 0;
|
| 801 | return ctx;
|
| 802 | }
|
| 803 |
|
| 804 | function useDataRouterState(hookName) {
|
| 805 | let state = React__namespace.useContext(DataRouterStateContext);
|
| 806 | !state ? router.UNSAFE_invariant(false, getDataRouterConsoleError(hookName)) : void 0;
|
| 807 | return state;
|
| 808 | }
|
| 809 |
|
| 810 | function useRouteContext(hookName) {
|
| 811 | let route = React__namespace.useContext(RouteContext);
|
| 812 | !route ? router.UNSAFE_invariant(false, getDataRouterConsoleError(hookName)) : void 0;
|
| 813 | return route;
|
| 814 | }
|
| 815 |
|
| 816 | function useCurrentRouteId(hookName) {
|
| 817 | let route = useRouteContext(hookName);
|
| 818 | let thisRoute = route.matches[route.matches.length - 1];
|
| 819 | !thisRoute.route.id ? router.UNSAFE_invariant(false, hookName + " can only be used on routes that contain a unique \"id\"") : void 0;
|
| 820 | return thisRoute.route.id;
|
| 821 | }
|
| 822 | |
| 823 | |
| 824 | |
| 825 |
|
| 826 |
|
| 827 |
|
| 828 | function useNavigation() {
|
| 829 | let state = useDataRouterState(DataRouterStateHook.UseNavigation);
|
| 830 | return state.navigation;
|
| 831 | }
|
| 832 | |
| 833 | |
| 834 | |
| 835 |
|
| 836 |
|
| 837 | function useRevalidator() {
|
| 838 | let dataRouterContext = useDataRouterContext(DataRouterHook.UseRevalidator);
|
| 839 | let state = useDataRouterState(DataRouterStateHook.UseRevalidator);
|
| 840 | return {
|
| 841 | revalidate: dataRouterContext.router.revalidate,
|
| 842 | state: state.revalidation
|
| 843 | };
|
| 844 | }
|
| 845 | |
| 846 | |
| 847 | |
| 848 |
|
| 849 |
|
| 850 | function useMatches() {
|
| 851 | let {
|
| 852 | matches,
|
| 853 | loaderData
|
| 854 | } = useDataRouterState(DataRouterStateHook.UseMatches);
|
| 855 | return React__namespace.useMemo(() => matches.map(match => {
|
| 856 | let {
|
| 857 | pathname,
|
| 858 | params
|
| 859 | } = match;
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 | return {
|
| 864 | id: match.route.id,
|
| 865 | pathname,
|
| 866 | params,
|
| 867 | data: loaderData[match.route.id],
|
| 868 | handle: match.route.handle
|
| 869 | };
|
| 870 | }), [matches, loaderData]);
|
| 871 | }
|
| 872 | |
| 873 | |
| 874 |
|
| 875 |
|
| 876 | function useLoaderData() {
|
| 877 | let state = useDataRouterState(DataRouterStateHook.UseLoaderData);
|
| 878 | let routeId = useCurrentRouteId(DataRouterStateHook.UseLoaderData);
|
| 879 |
|
| 880 | if (state.errors && state.errors[routeId] != null) {
|
| 881 | console.error("You cannot `useLoaderData` in an errorElement (routeId: " + routeId + ")");
|
| 882 | return undefined;
|
| 883 | }
|
| 884 |
|
| 885 | return state.loaderData[routeId];
|
| 886 | }
|
| 887 | |
| 888 | |
| 889 |
|
| 890 |
|
| 891 | function useRouteLoaderData(routeId) {
|
| 892 | let state = useDataRouterState(DataRouterStateHook.UseRouteLoaderData);
|
| 893 | return state.loaderData[routeId];
|
| 894 | }
|
| 895 | |
| 896 | |
| 897 |
|
| 898 |
|
| 899 | function useActionData() {
|
| 900 | let state = useDataRouterState(DataRouterStateHook.UseActionData);
|
| 901 | let route = React__namespace.useContext(RouteContext);
|
| 902 | !route ? router.UNSAFE_invariant(false, "useActionData must be used inside a RouteContext") : void 0;
|
| 903 | return Object.values((state == null ? void 0 : state.actionData) || {})[0];
|
| 904 | }
|
| 905 | |
| 906 | |
| 907 | |
| 908 | |
| 909 |
|
| 910 |
|
| 911 | function useRouteError() {
|
| 912 | var _state$errors;
|
| 913 |
|
| 914 | let error = React__namespace.useContext(RouteErrorContext);
|
| 915 | let state = useDataRouterState(DataRouterStateHook.UseRouteError);
|
| 916 | let routeId = useCurrentRouteId(DataRouterStateHook.UseRouteError);
|
| 917 |
|
| 918 |
|
| 919 | if (error) {
|
| 920 | return error;
|
| 921 | }
|
| 922 |
|
| 923 |
|
| 924 | return (_state$errors = state.errors) == null ? void 0 : _state$errors[routeId];
|
| 925 | }
|
| 926 | |
| 927 | |
| 928 |
|
| 929 |
|
| 930 | function useAsyncValue() {
|
| 931 | let value = React__namespace.useContext(AwaitContext);
|
| 932 | return value == null ? void 0 : value._data;
|
| 933 | }
|
| 934 | |
| 935 | |
| 936 |
|
| 937 |
|
| 938 | function useAsyncError() {
|
| 939 | let value = React__namespace.useContext(AwaitContext);
|
| 940 | return value == null ? void 0 : value._error;
|
| 941 | }
|
| 942 | let blockerId = 0;
|
| 943 | |
| 944 | |
| 945 | |
| 946 | |
| 947 | |
| 948 |
|
| 949 |
|
| 950 | function useBlocker(shouldBlock) {
|
| 951 | let {
|
| 952 | router
|
| 953 | } = useDataRouterContext(DataRouterHook.UseBlocker);
|
| 954 | let state = useDataRouterState(DataRouterStateHook.UseBlocker);
|
| 955 | let [blockerKey] = React__namespace.useState(() => String(++blockerId));
|
| 956 | let blockerFunction = React__namespace.useCallback(args => {
|
| 957 | return typeof shouldBlock === "function" ? !!shouldBlock(args) : !!shouldBlock;
|
| 958 | }, [shouldBlock]);
|
| 959 | let blocker = router.getBlocker(blockerKey, blockerFunction);
|
| 960 |
|
| 961 | React__namespace.useEffect(() => () => router.deleteBlocker(blockerKey), [router, blockerKey]);
|
| 962 |
|
| 963 |
|
| 964 | return state.blockers.get(blockerKey) || blocker;
|
| 965 | }
|
| 966 | const alreadyWarned = {};
|
| 967 |
|
| 968 | function warningOnce(key, cond, message) {
|
| 969 | if (!cond && !alreadyWarned[key]) {
|
| 970 | alreadyWarned[key] = true;
|
| 971 | router.UNSAFE_warning(false, message) ;
|
| 972 | }
|
| 973 | }
|
| 974 |
|
| 975 | |
| 976 | |
| 977 |
|
| 978 | function RouterProvider(_ref) {
|
| 979 | let {
|
| 980 | fallbackElement,
|
| 981 | router
|
| 982 | } = _ref;
|
| 983 | let getState = React__namespace.useCallback(() => router.state, [router]);
|
| 984 |
|
| 985 | let state = useSyncExternalStore(router.subscribe, getState,
|
| 986 |
|
| 987 |
|
| 988 | getState);
|
| 989 | let navigator = React__namespace.useMemo(() => {
|
| 990 | return {
|
| 991 | createHref: router.createHref,
|
| 992 | encodeLocation: router.encodeLocation,
|
| 993 | go: n => router.navigate(n),
|
| 994 | push: (to, state, opts) => router.navigate(to, {
|
| 995 | state,
|
| 996 | preventScrollReset: opts == null ? void 0 : opts.preventScrollReset
|
| 997 | }),
|
| 998 | replace: (to, state, opts) => router.navigate(to, {
|
| 999 | replace: true,
|
| 1000 | state,
|
| 1001 | preventScrollReset: opts == null ? void 0 : opts.preventScrollReset
|
| 1002 | })
|
| 1003 | };
|
| 1004 | }, [router]);
|
| 1005 | let basename = router.basename || "/";
|
| 1006 | let dataRouterContext = React__namespace.useMemo(() => ({
|
| 1007 | router,
|
| 1008 | navigator,
|
| 1009 | static: false,
|
| 1010 | basename
|
| 1011 | }), [router, navigator, basename]);
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 | return React__namespace.createElement(React__namespace.Fragment, null, React__namespace.createElement(DataRouterContext.Provider, {
|
| 1019 | value: dataRouterContext
|
| 1020 | }, React__namespace.createElement(DataRouterStateContext.Provider, {
|
| 1021 | value: state
|
| 1022 | }, React__namespace.createElement(Router, {
|
| 1023 | basename: router.basename,
|
| 1024 | location: router.state.location,
|
| 1025 | navigationType: router.state.historyAction,
|
| 1026 | navigator: navigator
|
| 1027 | }, router.state.initialized ? React__namespace.createElement(Routes, null) : fallbackElement))), null);
|
| 1028 | }
|
| 1029 |
|
| 1030 | |
| 1031 | |
| 1032 | |
| 1033 | |
| 1034 |
|
| 1035 | function MemoryRouter(_ref2) {
|
| 1036 | let {
|
| 1037 | basename,
|
| 1038 | children,
|
| 1039 | initialEntries,
|
| 1040 | initialIndex
|
| 1041 | } = _ref2;
|
| 1042 | let historyRef = React__namespace.useRef();
|
| 1043 |
|
| 1044 | if (historyRef.current == null) {
|
| 1045 | historyRef.current = router.createMemoryHistory({
|
| 1046 | initialEntries,
|
| 1047 | initialIndex,
|
| 1048 | v5Compat: true
|
| 1049 | });
|
| 1050 | }
|
| 1051 |
|
| 1052 | let history = historyRef.current;
|
| 1053 | let [state, setState] = React__namespace.useState({
|
| 1054 | action: history.action,
|
| 1055 | location: history.location
|
| 1056 | });
|
| 1057 | React__namespace.useLayoutEffect(() => history.listen(setState), [history]);
|
| 1058 | return React__namespace.createElement(Router, {
|
| 1059 | basename: basename,
|
| 1060 | children: children,
|
| 1061 | location: state.location,
|
| 1062 | navigationType: state.action,
|
| 1063 | navigator: history
|
| 1064 | });
|
| 1065 | }
|
| 1066 |
|
| 1067 | |
| 1068 | |
| 1069 | |
| 1070 | |
| 1071 | |
| 1072 | |
| 1073 | |
| 1074 | |
| 1075 |
|
| 1076 | function Navigate(_ref3) {
|
| 1077 | let {
|
| 1078 | to,
|
| 1079 | replace,
|
| 1080 | state,
|
| 1081 | relative
|
| 1082 | } = _ref3;
|
| 1083 | !useInRouterContext() ? router.UNSAFE_invariant(false,
|
| 1084 |
|
| 1085 | "<Navigate> may be used only in the context of a <Router> component.") : void 0;
|
| 1086 | router.UNSAFE_warning(!React__namespace.useContext(NavigationContext).static, "<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.") ;
|
| 1087 | let dataRouterState = React__namespace.useContext(DataRouterStateContext);
|
| 1088 | let navigate = useNavigate();
|
| 1089 | React__namespace.useEffect(() => {
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 | if (dataRouterState && dataRouterState.navigation.state !== "idle") {
|
| 1094 | return;
|
| 1095 | }
|
| 1096 |
|
| 1097 | navigate(to, {
|
| 1098 | replace,
|
| 1099 | state,
|
| 1100 | relative
|
| 1101 | });
|
| 1102 | });
|
| 1103 | return null;
|
| 1104 | }
|
| 1105 |
|
| 1106 | |
| 1107 | |
| 1108 | |
| 1109 | |
| 1110 |
|
| 1111 | function Outlet(props) {
|
| 1112 | return useOutlet(props.context);
|
| 1113 | }
|
| 1114 |
|
| 1115 | |
| 1116 | |
| 1117 | |
| 1118 | |
| 1119 |
|
| 1120 | function Route(_props) {
|
| 1121 | router.UNSAFE_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>.") ;
|
| 1122 | }
|
| 1123 |
|
| 1124 | |
| 1125 | |
| 1126 | |
| 1127 | |
| 1128 | |
| 1129 | |
| 1130 | |
| 1131 | |
| 1132 |
|
| 1133 | function Router(_ref4) {
|
| 1134 | let {
|
| 1135 | basename: basenameProp = "/",
|
| 1136 | children = null,
|
| 1137 | location: locationProp,
|
| 1138 | navigationType = router.Action.Pop,
|
| 1139 | navigator,
|
| 1140 | static: staticProp = false
|
| 1141 | } = _ref4;
|
| 1142 | !!useInRouterContext() ? router.UNSAFE_invariant(false, "You cannot render a <Router> inside another <Router>." + " You should never have more than one in your app.") : void 0;
|
| 1143 |
|
| 1144 |
|
| 1145 | let basename = basenameProp.replace(/^\/*/, "/");
|
| 1146 | let navigationContext = React__namespace.useMemo(() => ({
|
| 1147 | basename,
|
| 1148 | navigator,
|
| 1149 | static: staticProp
|
| 1150 | }), [basename, navigator, staticProp]);
|
| 1151 |
|
| 1152 | if (typeof locationProp === "string") {
|
| 1153 | locationProp = router.parsePath(locationProp);
|
| 1154 | }
|
| 1155 |
|
| 1156 | let {
|
| 1157 | pathname = "/",
|
| 1158 | search = "",
|
| 1159 | hash = "",
|
| 1160 | state = null,
|
| 1161 | key = "default"
|
| 1162 | } = locationProp;
|
| 1163 | let locationContext = React__namespace.useMemo(() => {
|
| 1164 | let trailingPathname = router.stripBasename(pathname, basename);
|
| 1165 |
|
| 1166 | if (trailingPathname == null) {
|
| 1167 | return null;
|
| 1168 | }
|
| 1169 |
|
| 1170 | return {
|
| 1171 | location: {
|
| 1172 | pathname: trailingPathname,
|
| 1173 | search,
|
| 1174 | hash,
|
| 1175 | state,
|
| 1176 | key
|
| 1177 | },
|
| 1178 | navigationType
|
| 1179 | };
|
| 1180 | }, [basename, pathname, search, hash, state, key, navigationType]);
|
| 1181 | router.UNSAFE_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.") ;
|
| 1182 |
|
| 1183 | if (locationContext == null) {
|
| 1184 | return null;
|
| 1185 | }
|
| 1186 |
|
| 1187 | return React__namespace.createElement(NavigationContext.Provider, {
|
| 1188 | value: navigationContext
|
| 1189 | }, React__namespace.createElement(LocationContext.Provider, {
|
| 1190 | children: children,
|
| 1191 | value: locationContext
|
| 1192 | }));
|
| 1193 | }
|
| 1194 |
|
| 1195 | |
| 1196 | |
| 1197 | |
| 1198 | |
| 1199 | |
| 1200 |
|
| 1201 | function Routes(_ref5) {
|
| 1202 | let {
|
| 1203 | children,
|
| 1204 | location
|
| 1205 | } = _ref5;
|
| 1206 | let dataRouterContext = React__namespace.useContext(DataRouterContext);
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 | let routes = dataRouterContext && !children ? dataRouterContext.router.routes : createRoutesFromChildren(children);
|
| 1211 | return useRoutes(routes, location);
|
| 1212 | }
|
| 1213 |
|
| 1214 | |
| 1215 | |
| 1216 | |
| 1217 |
|
| 1218 | function Await(_ref6) {
|
| 1219 | let {
|
| 1220 | children,
|
| 1221 | errorElement,
|
| 1222 | resolve
|
| 1223 | } = _ref6;
|
| 1224 | return React__namespace.createElement(AwaitErrorBoundary, {
|
| 1225 | resolve: resolve,
|
| 1226 | errorElement: errorElement
|
| 1227 | }, React__namespace.createElement(ResolveAwait, null, children));
|
| 1228 | }
|
| 1229 | var AwaitRenderStatus;
|
| 1230 |
|
| 1231 | (function (AwaitRenderStatus) {
|
| 1232 | AwaitRenderStatus[AwaitRenderStatus["pending"] = 0] = "pending";
|
| 1233 | AwaitRenderStatus[AwaitRenderStatus["success"] = 1] = "success";
|
| 1234 | AwaitRenderStatus[AwaitRenderStatus["error"] = 2] = "error";
|
| 1235 | })(AwaitRenderStatus || (AwaitRenderStatus = {}));
|
| 1236 |
|
| 1237 | const neverSettledPromise = new Promise(() => {});
|
| 1238 |
|
| 1239 | class AwaitErrorBoundary extends React__namespace.Component {
|
| 1240 | constructor(props) {
|
| 1241 | super(props);
|
| 1242 | this.state = {
|
| 1243 | error: null
|
| 1244 | };
|
| 1245 | }
|
| 1246 |
|
| 1247 | static getDerivedStateFromError(error) {
|
| 1248 | return {
|
| 1249 | error
|
| 1250 | };
|
| 1251 | }
|
| 1252 |
|
| 1253 | componentDidCatch(error, errorInfo) {
|
| 1254 | console.error("<Await> caught the following error during render", error, errorInfo);
|
| 1255 | }
|
| 1256 |
|
| 1257 | render() {
|
| 1258 | let {
|
| 1259 | children,
|
| 1260 | errorElement,
|
| 1261 | resolve
|
| 1262 | } = this.props;
|
| 1263 | let promise = null;
|
| 1264 | let status = AwaitRenderStatus.pending;
|
| 1265 |
|
| 1266 | if (!(resolve instanceof Promise)) {
|
| 1267 |
|
| 1268 | status = AwaitRenderStatus.success;
|
| 1269 | promise = Promise.resolve();
|
| 1270 | Object.defineProperty(promise, "_tracked", {
|
| 1271 | get: () => true
|
| 1272 | });
|
| 1273 | Object.defineProperty(promise, "_data", {
|
| 1274 | get: () => resolve
|
| 1275 | });
|
| 1276 | } else if (this.state.error) {
|
| 1277 |
|
| 1278 | status = AwaitRenderStatus.error;
|
| 1279 | let renderError = this.state.error;
|
| 1280 | promise = Promise.reject().catch(() => {});
|
| 1281 |
|
| 1282 | Object.defineProperty(promise, "_tracked", {
|
| 1283 | get: () => true
|
| 1284 | });
|
| 1285 | Object.defineProperty(promise, "_error", {
|
| 1286 | get: () => renderError
|
| 1287 | });
|
| 1288 | } else if (resolve._tracked) {
|
| 1289 |
|
| 1290 | promise = resolve;
|
| 1291 | status = promise._error !== undefined ? AwaitRenderStatus.error : promise._data !== undefined ? AwaitRenderStatus.success : AwaitRenderStatus.pending;
|
| 1292 | } else {
|
| 1293 |
|
| 1294 | status = AwaitRenderStatus.pending;
|
| 1295 | Object.defineProperty(resolve, "_tracked", {
|
| 1296 | get: () => true
|
| 1297 | });
|
| 1298 | promise = resolve.then(data => Object.defineProperty(resolve, "_data", {
|
| 1299 | get: () => data
|
| 1300 | }), error => Object.defineProperty(resolve, "_error", {
|
| 1301 | get: () => error
|
| 1302 | }));
|
| 1303 | }
|
| 1304 |
|
| 1305 | if (status === AwaitRenderStatus.error && promise._error instanceof router.AbortedDeferredError) {
|
| 1306 |
|
| 1307 | throw neverSettledPromise;
|
| 1308 | }
|
| 1309 |
|
| 1310 | if (status === AwaitRenderStatus.error && !errorElement) {
|
| 1311 |
|
| 1312 | throw promise._error;
|
| 1313 | }
|
| 1314 |
|
| 1315 | if (status === AwaitRenderStatus.error) {
|
| 1316 |
|
| 1317 | return React__namespace.createElement(AwaitContext.Provider, {
|
| 1318 | value: promise,
|
| 1319 | children: errorElement
|
| 1320 | });
|
| 1321 | }
|
| 1322 |
|
| 1323 | if (status === AwaitRenderStatus.success) {
|
| 1324 |
|
| 1325 | return React__namespace.createElement(AwaitContext.Provider, {
|
| 1326 | value: promise,
|
| 1327 | children: children
|
| 1328 | });
|
| 1329 | }
|
| 1330 |
|
| 1331 |
|
| 1332 | throw promise;
|
| 1333 | }
|
| 1334 |
|
| 1335 | }
|
| 1336 | |
| 1337 | |
| 1338 | |
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 | function ResolveAwait(_ref7) {
|
| 1343 | let {
|
| 1344 | children
|
| 1345 | } = _ref7;
|
| 1346 | let data = useAsyncValue();
|
| 1347 | let toRender = typeof children === "function" ? children(data) : children;
|
| 1348 | return React__namespace.createElement(React__namespace.Fragment, null, toRender);
|
| 1349 | }
|
| 1350 |
|
| 1351 |
|
| 1352 |
|
| 1353 | |
| 1354 | |
| 1355 | |
| 1356 | |
| 1357 | |
| 1358 | |
| 1359 |
|
| 1360 |
|
| 1361 |
|
| 1362 | function createRoutesFromChildren(children, parentPath) {
|
| 1363 | if (parentPath === void 0) {
|
| 1364 | parentPath = [];
|
| 1365 | }
|
| 1366 |
|
| 1367 | let routes = [];
|
| 1368 | React__namespace.Children.forEach(children, (element, index) => {
|
| 1369 | if (! React__namespace.isValidElement(element)) {
|
| 1370 |
|
| 1371 |
|
| 1372 | return;
|
| 1373 | }
|
| 1374 |
|
| 1375 | let treePath = [...parentPath, index];
|
| 1376 |
|
| 1377 | if (element.type === React__namespace.Fragment) {
|
| 1378 |
|
| 1379 | routes.push.apply(routes, createRoutesFromChildren(element.props.children, treePath));
|
| 1380 | return;
|
| 1381 | }
|
| 1382 |
|
| 1383 | !(element.type === Route) ? router.UNSAFE_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>") : void 0;
|
| 1384 | !(!element.props.index || !element.props.children) ? router.UNSAFE_invariant(false, "An index route cannot have child routes.") : void 0;
|
| 1385 | let route = {
|
| 1386 | id: element.props.id || treePath.join("-"),
|
| 1387 | caseSensitive: element.props.caseSensitive,
|
| 1388 | element: element.props.element,
|
| 1389 | Component: element.props.Component,
|
| 1390 | index: element.props.index,
|
| 1391 | path: element.props.path,
|
| 1392 | loader: element.props.loader,
|
| 1393 | action: element.props.action,
|
| 1394 | errorElement: element.props.errorElement,
|
| 1395 | ErrorBoundary: element.props.ErrorBoundary,
|
| 1396 | hasErrorBoundary: element.props.ErrorBoundary != null || element.props.errorElement != null,
|
| 1397 | shouldRevalidate: element.props.shouldRevalidate,
|
| 1398 | handle: element.props.handle,
|
| 1399 | lazy: element.props.lazy
|
| 1400 | };
|
| 1401 |
|
| 1402 | if (element.props.children) {
|
| 1403 | route.children = createRoutesFromChildren(element.props.children, treePath);
|
| 1404 | }
|
| 1405 |
|
| 1406 | routes.push(route);
|
| 1407 | });
|
| 1408 | return routes;
|
| 1409 | }
|
| 1410 | |
| 1411 | |
| 1412 |
|
| 1413 |
|
| 1414 | function renderMatches(matches) {
|
| 1415 | return _renderMatches(matches);
|
| 1416 | }
|
| 1417 |
|
| 1418 | function detectErrorBoundary(route) {
|
| 1419 | {
|
| 1420 | if (route.Component && route.element) {
|
| 1421 | router.UNSAFE_warning(false, "You should not include both `Component` and `element` on your route - " + "`element` will be ignored.") ;
|
| 1422 | }
|
| 1423 |
|
| 1424 | if (route.ErrorBoundary && route.errorElement) {
|
| 1425 | router.UNSAFE_warning(false, "You should not include both `ErrorBoundary` and `errorElement` on your route - " + "`errorElement` will be ignored.") ;
|
| 1426 | }
|
| 1427 | }
|
| 1428 |
|
| 1429 |
|
| 1430 |
|
| 1431 | return Boolean(route.ErrorBoundary) || Boolean(route.errorElement);
|
| 1432 | }
|
| 1433 |
|
| 1434 | function createMemoryRouter(routes, opts) {
|
| 1435 | return router.createRouter({
|
| 1436 | basename: opts == null ? void 0 : opts.basename,
|
| 1437 | future: opts == null ? void 0 : opts.future,
|
| 1438 | history: router.createMemoryHistory({
|
| 1439 | initialEntries: opts == null ? void 0 : opts.initialEntries,
|
| 1440 | initialIndex: opts == null ? void 0 : opts.initialIndex
|
| 1441 | }),
|
| 1442 | hydrationData: opts == null ? void 0 : opts.hydrationData,
|
| 1443 | routes,
|
| 1444 | detectErrorBoundary
|
| 1445 | }).initialize();
|
| 1446 | }
|
| 1447 |
|
| 1448 | Object.defineProperty(exports, 'AbortedDeferredError', {
|
| 1449 | enumerable: true,
|
| 1450 | get: function () { return router.AbortedDeferredError; }
|
| 1451 | });
|
| 1452 | Object.defineProperty(exports, 'NavigationType', {
|
| 1453 | enumerable: true,
|
| 1454 | get: function () { return router.Action; }
|
| 1455 | });
|
| 1456 | Object.defineProperty(exports, 'createPath', {
|
| 1457 | enumerable: true,
|
| 1458 | get: function () { return router.createPath; }
|
| 1459 | });
|
| 1460 | Object.defineProperty(exports, 'defer', {
|
| 1461 | enumerable: true,
|
| 1462 | get: function () { return router.defer; }
|
| 1463 | });
|
| 1464 | Object.defineProperty(exports, 'generatePath', {
|
| 1465 | enumerable: true,
|
| 1466 | get: function () { return router.generatePath; }
|
| 1467 | });
|
| 1468 | Object.defineProperty(exports, 'isRouteErrorResponse', {
|
| 1469 | enumerable: true,
|
| 1470 | get: function () { return router.isRouteErrorResponse; }
|
| 1471 | });
|
| 1472 | Object.defineProperty(exports, 'json', {
|
| 1473 | enumerable: true,
|
| 1474 | get: function () { return router.json; }
|
| 1475 | });
|
| 1476 | Object.defineProperty(exports, 'matchPath', {
|
| 1477 | enumerable: true,
|
| 1478 | get: function () { return router.matchPath; }
|
| 1479 | });
|
| 1480 | Object.defineProperty(exports, 'matchRoutes', {
|
| 1481 | enumerable: true,
|
| 1482 | get: function () { return router.matchRoutes; }
|
| 1483 | });
|
| 1484 | Object.defineProperty(exports, 'parsePath', {
|
| 1485 | enumerable: true,
|
| 1486 | get: function () { return router.parsePath; }
|
| 1487 | });
|
| 1488 | Object.defineProperty(exports, 'redirect', {
|
| 1489 | enumerable: true,
|
| 1490 | get: function () { return router.redirect; }
|
| 1491 | });
|
| 1492 | Object.defineProperty(exports, 'resolvePath', {
|
| 1493 | enumerable: true,
|
| 1494 | get: function () { return router.resolvePath; }
|
| 1495 | });
|
| 1496 | exports.Await = Await;
|
| 1497 | exports.MemoryRouter = MemoryRouter;
|
| 1498 | exports.Navigate = Navigate;
|
| 1499 | exports.Outlet = Outlet;
|
| 1500 | exports.Route = Route;
|
| 1501 | exports.Router = Router;
|
| 1502 | exports.RouterProvider = RouterProvider;
|
| 1503 | exports.Routes = Routes;
|
| 1504 | exports.UNSAFE_DataRouterContext = DataRouterContext;
|
| 1505 | exports.UNSAFE_DataRouterStateContext = DataRouterStateContext;
|
| 1506 | exports.UNSAFE_LocationContext = LocationContext;
|
| 1507 | exports.UNSAFE_NavigationContext = NavigationContext;
|
| 1508 | exports.UNSAFE_RouteContext = RouteContext;
|
| 1509 | exports.UNSAFE_detectErrorBoundary = detectErrorBoundary;
|
| 1510 | exports.createMemoryRouter = createMemoryRouter;
|
| 1511 | exports.createRoutesFromChildren = createRoutesFromChildren;
|
| 1512 | exports.createRoutesFromElements = createRoutesFromChildren;
|
| 1513 | exports.renderMatches = renderMatches;
|
| 1514 | exports.unstable_useBlocker = useBlocker;
|
| 1515 | exports.useActionData = useActionData;
|
| 1516 | exports.useAsyncError = useAsyncError;
|
| 1517 | exports.useAsyncValue = useAsyncValue;
|
| 1518 | exports.useHref = useHref;
|
| 1519 | exports.useInRouterContext = useInRouterContext;
|
| 1520 | exports.useLoaderData = useLoaderData;
|
| 1521 | exports.useLocation = useLocation;
|
| 1522 | exports.useMatch = useMatch;
|
| 1523 | exports.useMatches = useMatches;
|
| 1524 | exports.useNavigate = useNavigate;
|
| 1525 | exports.useNavigation = useNavigation;
|
| 1526 | exports.useNavigationType = useNavigationType;
|
| 1527 | exports.useOutlet = useOutlet;
|
| 1528 | exports.useOutletContext = useOutletContext;
|
| 1529 | exports.useParams = useParams;
|
| 1530 | exports.useResolvedPath = useResolvedPath;
|
| 1531 | exports.useRevalidator = useRevalidator;
|
| 1532 | exports.useRouteError = useRouteError;
|
| 1533 | exports.useRouteLoaderData = useRouteLoaderData;
|
| 1534 | exports.useRoutes = useRoutes;
|
| 1535 |
|
| 1536 | Object.defineProperty(exports, '__esModule', { value: true });
|
| 1537 |
|
| 1538 | }));
|
| 1539 |
|