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