react-router-dom
Advanced tools
Comparing version 0.0.0-experimental-48058118 to 0.0.0-experimental-5f6f59a6
128
CHANGELOG.md
# `react-router-dom` | ||
## 6.9.0-pre.0 | ||
### Minor Changes | ||
- React Router now supports an alternative way to define your route `element` and `errorElement` fields as React Components instead of React Elements. You can instead pass a React Component to the new `Component` and `ErrorBoundary` fields if you choose. There is no functional difference between the two, so use whichever approach you prefer 😀. You shouldn't be defining both, but if you do `Component`/`ErrorBoundary` will "win". ([#10045](https://github.com/remix-run/react-router/pull/10045)) | ||
**Example JSON Syntax** | ||
```jsx | ||
// Both of these work the same: | ||
const elementRoutes = [{ | ||
path: '/', | ||
element: <Home />, | ||
errorElement: <HomeError />, | ||
}] | ||
const componentRoutes = [{ | ||
path: '/', | ||
Component: Home, | ||
ErrorBoundary: HomeError, | ||
}] | ||
function Home() { ... } | ||
function HomeError() { ... } | ||
``` | ||
**Example JSX Syntax** | ||
```jsx | ||
// Both of these work the same: | ||
const elementRoutes = createRoutesFromElements( | ||
<Route path='/' element={<Home />} errorElement={<HomeError /> } /> | ||
); | ||
const componentRoutes = createRoutesFromElements( | ||
<Route path='/' Component={Home} ErrorBoundary={HomeError} /> | ||
); | ||
function Home() { ... } | ||
function HomeError() { ... } | ||
``` | ||
- **Introducing Lazy Route Modules!** ([#10045](https://github.com/remix-run/react-router/pull/10045)) | ||
In order to keep your application bundles small and support code-splitting of your routes, we've introduced a new `lazy()` route property. This is an async function that resolves the non-route-matching portions of your route definition (`loader`, `action`, `element`/`Component`, `errorElement`/`ErrorBoundary`, `shouldRevalidate`, `handle`). | ||
Lazy routes are resolved on initial load and during the `loading` or `submitting` phase of a navigation or fetcher call. You cannot lazily define route-matching properties (`path`, `index`, `children`) since we only execute your lazy route functions after we've matched known routes. | ||
Your `lazy` functions will typically return the result of a dynamic import. | ||
```jsx | ||
// In this example, we assume most folks land on the homepage so we include that | ||
// in our critical-path bundle, but then we lazily load modules for /a and /b so | ||
// they don't load until the user navigates to those routes | ||
let routes = createRoutesFromElements( | ||
<Route path="/" element={<Layout />}> | ||
<Route index element={<Home />} /> | ||
<Route path="a" lazy={() => import("./a")} /> | ||
<Route path="b" lazy={() => import("./b")} /> | ||
</Route> | ||
); | ||
``` | ||
Then in your lazy route modules, export the properties you want defined for the route: | ||
```jsx | ||
export async function loader({ request }) { | ||
let data = await fetchData(request); | ||
return json(data); | ||
} | ||
// Export a `Component` directly instead of needing to create a React Element from it | ||
export function Component() { | ||
let data = useLoaderData(); | ||
return ( | ||
<> | ||
<h1>You made it!</h1> | ||
<p>{data}</p> | ||
</> | ||
); | ||
} | ||
// Export an `ErrorBoundary` directly instead of needing to create a React Element from it | ||
export function ErrorBoundary() { | ||
let error = useRouteError(); | ||
return isRouteErrorResponse(error) ? ( | ||
<h1> | ||
{error.status} {error.statusText} | ||
</h1> | ||
) : ( | ||
<h1>{error.message || error}</h1> | ||
); | ||
} | ||
``` | ||
An example of this in action can be found in the [`examples/lazy-loading-router-provider`](https://github.com/remix-run/react-router/tree/main/examples/lazy-loading-router-provider) directory of the repository. | ||
🙌 Huge thanks to @rossipedia for the [Initial Proposal](https://github.com/remix-run/react-router/discussions/9826) and [POC Implementation](https://github.com/remix-run/react-router/pull/9830). | ||
### Patch Changes | ||
- Updated dependencies: | ||
- `react-router@6.9.0-pre.0` | ||
- `@remix-run/router@1.4.0-pre.0` | ||
## 6.8.2 | ||
### Patch Changes | ||
- Treat same-origin absolute URLs in `<Link to>` as external if they are outside of the router `basename` ([#10135](https://github.com/remix-run/react-router/pull/10135)) | ||
- Fix `useBlocker` to return `IDLE_BLOCKER` during SSR ([#10046](https://github.com/remix-run/react-router/pull/10046)) | ||
- Fix SSR of absolute `<Link to>` urls ([#10112](https://github.com/remix-run/react-router/pull/10112)) | ||
- Properly escape HTML characters in `StaticRouterProvider` serialized hydration data ([#10068](https://github.com/remix-run/react-router/pull/10068)) | ||
- Updated dependencies: | ||
- `@remix-run/router@1.3.3` | ||
- `react-router@6.8.2` | ||
## 6.8.1 | ||
### Patch Changes | ||
- Improved absolute url detection in `Link` component (now also supports `mailto:` urls) ([#9994](https://github.com/remix-run/react-router/pull/9994)) | ||
- Fix partial object (search or hash only) pathnames losing current path value ([#10029](https://github.com/remix-run/react-router/pull/10029)) | ||
- Updated dependencies: | ||
- `react-router@6.8.1` | ||
- `@remix-run/router@1.3.2` | ||
## 6.8.0 | ||
@@ -4,0 +132,0 @@ |
@@ -12,6 +12,6 @@ /** | ||
export { createSearchParams }; | ||
export type { ActionFunction, ActionFunctionArgs, ActionFunctionWithMiddleware, ActionFunctionArgsWithMiddleware, AwaitProps, unstable_Blocker, unstable_BlockerFunction, DataRouteMatch, DataRouteObject, Fetcher, FutureConfig, Hash, IndexRouteObject, IndexRouteProps, JsonFunction, LayoutRouteProps, LoaderFunction, LoaderFunctionArgs, LoaderFunctionWithMiddleware, LoaderFunctionArgsWithMiddleware, Location, MemoryRouterProps, MiddlewareContext, MiddlewareFunction, MiddlewareFunctionArgs, NavigateFunction, NavigateOptions, NavigateProps, Navigation, Navigator, NonIndexRouteObject, OutletProps, Params, ParamParseKey, Path, PathMatch, Pathname, PathPattern, PathRouteProps, RedirectFunction, RelativeRoutingType, RouteMatch, RouteObject, RouteProps, RouterProps, RouterProviderProps, RoutesProps, Search, ShouldRevalidateFunction, To, } from "react-router"; | ||
export { AbortedDeferredError, Await, MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, RouterProvider, Routes, createMemoryRouter, createMiddlewareContext, createPath, createRoutesFromChildren, createRoutesFromElements, defer, isRouteErrorResponse, generatePath, json, matchPath, matchRoutes, parsePath, redirect, renderMatches, resolvePath, useActionData, useAsyncError, useAsyncValue, unstable_useBlocker, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes, } from "react-router"; | ||
export type { ActionFunction, ActionFunctionArgs, AwaitProps, unstable_Blocker, unstable_BlockerFunction, DataRouteMatch, DataRouteObject, Fetcher, Hash, IndexRouteObject, IndexRouteProps, JsonFunction, LazyRouteFunction, LayoutRouteProps, LoaderFunction, LoaderFunctionArgs, Location, MemoryRouterProps, NavigateFunction, NavigateOptions, NavigateProps, Navigation, Navigator, NonIndexRouteObject, OutletProps, Params, ParamParseKey, Path, PathMatch, Pathname, PathPattern, PathRouteProps, RedirectFunction, RelativeRoutingType, RouteMatch, RouteObject, RouteProps, RouterProps, RouterProviderProps, RoutesProps, Search, ShouldRevalidateFunction, To, } from "react-router"; | ||
export { AbortedDeferredError, Await, MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, RouterProvider, Routes, createMemoryRouter, createPath, createRoutesFromChildren, createRoutesFromElements, defer, isRouteErrorResponse, generatePath, json, matchPath, matchRoutes, parsePath, redirect, renderMatches, resolvePath, useActionData, useAsyncError, useAsyncValue, unstable_useBlocker, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes, } from "react-router"; | ||
/** @internal */ | ||
export { UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, UNSAFE_NavigationContext, UNSAFE_LocationContext, UNSAFE_RouteContext, UNSAFE_enhanceManualRouteObjects, } from "react-router"; | ||
export { UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, UNSAFE_NavigationContext, UNSAFE_LocationContext, UNSAFE_RouteContext, } from "react-router"; | ||
declare global { | ||
@@ -225,2 +225,3 @@ var __staticRouterHydrationData: HydrationState | undefined; | ||
}): void; | ||
export { useScrollRestoration as UNSAFE_useScrollRestoration }; | ||
/** | ||
@@ -250,2 +251,1 @@ * Setup a callback to be fired on the window's `beforeunload` event. This is | ||
export { usePrompt as unstable_usePrompt }; | ||
export { useScrollRestoration as UNSAFE_useScrollRestoration }; |
/** | ||
* React Router DOM v0.0.0-experimental-48058118 | ||
* React Router DOM v0.0.0-experimental-5f6f59a6 | ||
* | ||
@@ -12,5 +12,5 @@ * Copyright (c) Remix Software Inc. | ||
import * as React from 'react'; | ||
import { UNSAFE_enhanceManualRouteObjects, Router, useHref, useResolvedPath, useLocation, UNSAFE_DataRouterStateContext, UNSAFE_NavigationContext, useNavigate, createPath, UNSAFE_RouteContext, useMatches, useNavigation, unstable_useBlocker, UNSAFE_DataRouterContext } from 'react-router'; | ||
export { AbortedDeferredError, Await, MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, RouterProvider, Routes, UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, UNSAFE_LocationContext, UNSAFE_NavigationContext, UNSAFE_RouteContext, UNSAFE_enhanceManualRouteObjects, createMemoryRouter, createMiddlewareContext, createPath, createRoutesFromChildren, createRoutesFromElements, defer, generatePath, isRouteErrorResponse, json, matchPath, matchRoutes, parsePath, redirect, renderMatches, resolvePath, unstable_useBlocker, useActionData, useAsyncError, useAsyncValue, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes } from 'react-router'; | ||
import { createRouter, createBrowserHistory, createHashHistory, ErrorResponse, invariant, joinPaths } from '@remix-run/router'; | ||
import { UNSAFE_detectErrorBoundary, Router, UNSAFE_NavigationContext, useHref, useResolvedPath, useLocation, UNSAFE_DataRouterStateContext, useNavigate, createPath, UNSAFE_RouteContext, useMatches, useNavigation, unstable_useBlocker, UNSAFE_DataRouterContext } from 'react-router'; | ||
export { AbortedDeferredError, Await, MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, RouterProvider, Routes, UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, UNSAFE_LocationContext, UNSAFE_NavigationContext, UNSAFE_RouteContext, createMemoryRouter, createPath, createRoutesFromChildren, createRoutesFromElements, defer, generatePath, isRouteErrorResponse, json, matchPath, matchRoutes, parsePath, redirect, renderMatches, resolvePath, unstable_useBlocker, useActionData, useAsyncError, useAsyncValue, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes } from 'react-router'; | ||
import { createRouter, createBrowserHistory, createHashHistory, ErrorResponse, stripBasename, UNSAFE_warning, UNSAFE_invariant, joinPaths } from '@remix-run/router'; | ||
@@ -204,3 +204,4 @@ function _extends() { | ||
hydrationData: (opts == null ? void 0 : opts.hydrationData) || parseHydrationData(), | ||
routes: UNSAFE_enhanceManualRouteObjects(routes) | ||
routes, | ||
detectErrorBoundary: UNSAFE_detectErrorBoundary | ||
}).initialize(); | ||
@@ -215,3 +216,4 @@ } | ||
hydrationData: (opts == null ? void 0 : opts.hydrationData) || parseHydrationData(), | ||
routes: UNSAFE_enhanceManualRouteObjects(routes) | ||
routes, | ||
detectErrorBoundary: UNSAFE_detectErrorBoundary | ||
}).initialize(); | ||
@@ -356,2 +358,3 @@ } | ||
const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined"; | ||
const ABSOLUTE_URL_REGEX = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i; | ||
/** | ||
@@ -374,16 +377,24 @@ * The public API for rendering a history-aware <a>. | ||
// Rendered into <a href> for absolute URLs | ||
let { | ||
basename | ||
} = React.useContext(UNSAFE_NavigationContext); // Rendered into <a href> for absolute URLs | ||
let absoluteHref; | ||
let isExternal = false; | ||
if (isBrowser && typeof to === "string" && /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i.test(to)) { | ||
absoluteHref = to; | ||
let currentUrl = new URL(window.location.href); | ||
let targetUrl = to.startsWith("//") ? new URL(currentUrl.protocol + to) : new URL(to); | ||
if (typeof to === "string" && ABSOLUTE_URL_REGEX.test(to)) { | ||
// Render the absolute href server- and client-side | ||
absoluteHref = to; // Only check for external origins client-side | ||
if (targetUrl.origin === currentUrl.origin) { | ||
// Strip the protocol/origin for same-origin absolute URLs | ||
to = targetUrl.pathname + targetUrl.search + targetUrl.hash; | ||
} else { | ||
isExternal = true; | ||
if (isBrowser) { | ||
let currentUrl = new URL(window.location.href); | ||
let targetUrl = to.startsWith("//") ? new URL(currentUrl.protocol + to) : new URL(to); | ||
let path = stripBasename(targetUrl.pathname, basename); | ||
if (targetUrl.origin === currentUrl.origin && path != null) { | ||
// Strip the protocol/origin/basename for same-origin absolute URLs | ||
to = path + targetUrl.search + targetUrl.hash; | ||
} else { | ||
isExternal = true; | ||
} | ||
} | ||
@@ -610,3 +621,3 @@ } // Rendered into <a href> for relative URLs | ||
let ctx = React.useContext(UNSAFE_DataRouterContext); | ||
!ctx ? process.env.NODE_ENV !== "production" ? invariant(false, getDataRouterConsoleError(hookName)) : invariant(false) : void 0; | ||
!ctx ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, getDataRouterConsoleError(hookName)) : UNSAFE_invariant(false) : void 0; | ||
return ctx; | ||
@@ -617,3 +628,3 @@ } | ||
let state = React.useContext(UNSAFE_DataRouterStateContext); | ||
!state ? process.env.NODE_ENV !== "production" ? invariant(false, getDataRouterConsoleError(hookName)) : invariant(false) : void 0; | ||
!state ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, getDataRouterConsoleError(hookName)) : UNSAFE_invariant(false) : void 0; | ||
return state; | ||
@@ -662,3 +673,3 @@ } | ||
function useSearchParams(defaultInit) { | ||
process.env.NODE_ENV !== "production" ? warning(typeof URLSearchParams !== "undefined", "You cannot use the `useSearchParams` hook in a browser that does not " + "support the URLSearchParams API. If you need to support Internet " + "Explorer 11, we recommend you load a polyfill such as " + "https://github.com/ungap/url-search-params\n\n" + "If you're unsure how to load polyfills, we recommend you check out " + "https://polyfill.io/v3/ which provides some recommendations about how " + "to load polyfills only for users that need them, instead of for every " + "user.") : void 0; | ||
process.env.NODE_ENV !== "production" ? UNSAFE_warning(typeof URLSearchParams !== "undefined", "You cannot use the `useSearchParams` hook in a browser that does not " + "support the URLSearchParams API. If you need to support Internet " + "Explorer 11, we recommend you load a polyfill such as " + "https://github.com/ungap/url-search-params\n\n" + "If you're unsure how to load polyfills, we recommend you check out " + "https://polyfill.io/v3/ which provides some recommendations about how " + "to load polyfills only for users that need them, instead of for every " + "user.") : void 0; | ||
let defaultSearchParamsRef = React.useRef(createSearchParams(defaultInit)); | ||
@@ -718,3 +729,3 @@ let hasSetSearchParamsRef = React.useRef(false); | ||
if (fetcherKey) { | ||
!(routeId != null) ? process.env.NODE_ENV !== "production" ? invariant(false, "No routeId available for useFetcher()") : invariant(false) : void 0; | ||
!(routeId != null) ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "No routeId available for useFetcher()") : UNSAFE_invariant(false) : void 0; | ||
router.fetch(fetcherKey, routeId, href, opts); | ||
@@ -735,3 +746,3 @@ } else { | ||
let routeContext = React.useContext(UNSAFE_RouteContext); | ||
!routeContext ? process.env.NODE_ENV !== "production" ? invariant(false, "useFormAction must be used inside a RouteContext") : invariant(false) : void 0; | ||
!routeContext ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "useFormAction must be used inside a RouteContext") : UNSAFE_invariant(false) : void 0; | ||
let [match] = routeContext.matches.slice(-1); // Shallow clone path so we can modify it below, otherwise we modify the | ||
@@ -811,13 +822,13 @@ // object referenced by useMemo inside useResolvedPath | ||
let route = React.useContext(UNSAFE_RouteContext); | ||
!route ? process.env.NODE_ENV !== "production" ? invariant(false, "useFetcher must be used inside a RouteContext") : invariant(false) : void 0; | ||
!route ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "useFetcher must be used inside a RouteContext") : UNSAFE_invariant(false) : void 0; | ||
let routeId = (_route$matches = route.matches[route.matches.length - 1]) == null ? void 0 : _route$matches.route.id; | ||
!(routeId != null) ? process.env.NODE_ENV !== "production" ? invariant(false, "useFetcher can only be used on routes that contain a unique \"id\"") : invariant(false) : void 0; | ||
!(routeId != null) ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "useFetcher can only be used on routes that contain a unique \"id\"") : UNSAFE_invariant(false) : void 0; | ||
let [fetcherKey] = React.useState(() => String(++fetcherId)); | ||
let [Form] = React.useState(() => { | ||
!routeId ? process.env.NODE_ENV !== "production" ? invariant(false, "No routeId available for fetcher.Form()") : invariant(false) : void 0; | ||
!routeId ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "No routeId available for fetcher.Form()") : UNSAFE_invariant(false) : void 0; | ||
return createFetcherForm(fetcherKey, routeId); | ||
}); | ||
let [load] = React.useState(() => href => { | ||
!router ? process.env.NODE_ENV !== "production" ? invariant(false, "No router available for fetcher.load()") : invariant(false) : void 0; | ||
!routeId ? process.env.NODE_ENV !== "production" ? invariant(false, "No routeId available for fetcher.load()") : invariant(false) : void 0; | ||
!router ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "No router available for fetcher.load()") : UNSAFE_invariant(false) : void 0; | ||
!routeId ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "No routeId available for fetcher.load()") : UNSAFE_invariant(false) : void 0; | ||
router.fetch(fetcherKey, routeId, href); | ||
@@ -956,3 +967,2 @@ }); | ||
function useBeforeUnload(callback, options) { | ||
@@ -1028,23 +1038,5 @@ let { | ||
} | ||
//////////////////////////////////////////////////////////////////////////////// | ||
//#region Utils | ||
//////////////////////////////////////////////////////////////////////////////// | ||
//#endregion | ||
function warning(cond, message) { | ||
if (!cond) { | ||
// eslint-disable-next-line no-console | ||
if (typeof console !== "undefined") console.warn(message); | ||
try { | ||
// Welcome to debugging React Router! | ||
// | ||
// This error is thrown as a convenience so you can more easily | ||
// find the source for a warning that appears in the console by | ||
// enabling "pause on exceptions" in your JavaScript debugger. | ||
throw new Error(message); // eslint-disable-next-line no-empty | ||
} catch (e) {} | ||
} | ||
} //#endregion | ||
export { BrowserRouter, Form, HashRouter, Link, NavLink, ScrollRestoration, useScrollRestoration as UNSAFE_useScrollRestoration, createBrowserRouter, createHashRouter, createSearchParams, HistoryRouter as unstable_HistoryRouter, usePrompt as unstable_usePrompt, useBeforeUnload, useFetcher, useFetchers, useFormAction, useLinkClickHandler, useSearchParams, useSubmit }; | ||
//# sourceMappingURL=index.js.map |
/** | ||
* React Router DOM v0.0.0-experimental-48058118 | ||
* React Router DOM v0.0.0-experimental-5f6f59a6 | ||
* | ||
@@ -4,0 +4,0 @@ * Copyright (c) Remix Software Inc. |
/** | ||
* React Router DOM v0.0.0-experimental-48058118 | ||
* React Router DOM v0.0.0-experimental-5f6f59a6 | ||
* | ||
@@ -12,5 +12,5 @@ * Copyright (c) Remix Software Inc. | ||
import * as React from 'react'; | ||
import { UNSAFE_enhanceManualRouteObjects, Router, useHref, useResolvedPath, useLocation, UNSAFE_DataRouterStateContext, UNSAFE_NavigationContext, useNavigate, createPath, UNSAFE_RouteContext, useMatches, useNavigation, unstable_useBlocker, UNSAFE_DataRouterContext } from 'react-router'; | ||
export { AbortedDeferredError, Await, MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, RouterProvider, Routes, UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, UNSAFE_LocationContext, UNSAFE_NavigationContext, UNSAFE_RouteContext, UNSAFE_enhanceManualRouteObjects, createMemoryRouter, createMiddlewareContext, createPath, createRoutesFromChildren, createRoutesFromElements, defer, generatePath, isRouteErrorResponse, json, matchPath, matchRoutes, parsePath, redirect, renderMatches, resolvePath, unstable_useBlocker, useActionData, useAsyncError, useAsyncValue, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes } from 'react-router'; | ||
import { createRouter, createBrowserHistory, createHashHistory, ErrorResponse, invariant, joinPaths } from '@remix-run/router'; | ||
import { UNSAFE_detectErrorBoundary, Router, UNSAFE_NavigationContext, useHref, useResolvedPath, useLocation, UNSAFE_DataRouterStateContext, useNavigate, createPath, UNSAFE_RouteContext, useMatches, useNavigation, unstable_useBlocker, UNSAFE_DataRouterContext } from 'react-router'; | ||
export { AbortedDeferredError, Await, MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, RouterProvider, Routes, UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, UNSAFE_LocationContext, UNSAFE_NavigationContext, UNSAFE_RouteContext, createMemoryRouter, createPath, createRoutesFromChildren, createRoutesFromElements, defer, generatePath, isRouteErrorResponse, json, matchPath, matchRoutes, parsePath, redirect, renderMatches, resolvePath, unstable_useBlocker, useActionData, useAsyncError, useAsyncValue, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes } from 'react-router'; | ||
import { createRouter, createBrowserHistory, createHashHistory, ErrorResponse, stripBasename, UNSAFE_warning, UNSAFE_invariant, joinPaths } from '@remix-run/router'; | ||
@@ -170,3 +170,4 @@ const defaultMethod = "get"; | ||
hydrationData: opts?.hydrationData || parseHydrationData(), | ||
routes: UNSAFE_enhanceManualRouteObjects(routes) | ||
routes, | ||
detectErrorBoundary: UNSAFE_detectErrorBoundary | ||
}).initialize(); | ||
@@ -181,3 +182,4 @@ } | ||
hydrationData: opts?.hydrationData || parseHydrationData(), | ||
routes: UNSAFE_enhanceManualRouteObjects(routes) | ||
routes, | ||
detectErrorBoundary: UNSAFE_detectErrorBoundary | ||
}).initialize(); | ||
@@ -320,2 +322,3 @@ } | ||
const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined"; | ||
const ABSOLUTE_URL_REGEX = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i; | ||
/** | ||
@@ -336,16 +339,24 @@ * The public API for rendering a history-aware <a>. | ||
}, ref) { | ||
// Rendered into <a href> for absolute URLs | ||
let { | ||
basename | ||
} = React.useContext(UNSAFE_NavigationContext); // Rendered into <a href> for absolute URLs | ||
let absoluteHref; | ||
let isExternal = false; | ||
if (isBrowser && typeof to === "string" && /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i.test(to)) { | ||
absoluteHref = to; | ||
let currentUrl = new URL(window.location.href); | ||
let targetUrl = to.startsWith("//") ? new URL(currentUrl.protocol + to) : new URL(to); | ||
if (typeof to === "string" && ABSOLUTE_URL_REGEX.test(to)) { | ||
// Render the absolute href server- and client-side | ||
absoluteHref = to; // Only check for external origins client-side | ||
if (targetUrl.origin === currentUrl.origin) { | ||
// Strip the protocol/origin for same-origin absolute URLs | ||
to = targetUrl.pathname + targetUrl.search + targetUrl.hash; | ||
} else { | ||
isExternal = true; | ||
if (isBrowser) { | ||
let currentUrl = new URL(window.location.href); | ||
let targetUrl = to.startsWith("//") ? new URL(currentUrl.protocol + to) : new URL(to); | ||
let path = stripBasename(targetUrl.pathname, basename); | ||
if (targetUrl.origin === currentUrl.origin && path != null) { | ||
// Strip the protocol/origin/basename for same-origin absolute URLs | ||
to = path + targetUrl.search + targetUrl.hash; | ||
} else { | ||
isExternal = true; | ||
} | ||
} | ||
@@ -566,3 +577,3 @@ } // Rendered into <a href> for relative URLs | ||
let ctx = React.useContext(UNSAFE_DataRouterContext); | ||
!ctx ? invariant(false, getDataRouterConsoleError(hookName)) : void 0; | ||
!ctx ? UNSAFE_invariant(false, getDataRouterConsoleError(hookName)) : void 0; | ||
return ctx; | ||
@@ -573,3 +584,3 @@ } | ||
let state = React.useContext(UNSAFE_DataRouterStateContext); | ||
!state ? invariant(false, getDataRouterConsoleError(hookName)) : void 0; | ||
!state ? UNSAFE_invariant(false, getDataRouterConsoleError(hookName)) : void 0; | ||
return state; | ||
@@ -617,3 +628,3 @@ } | ||
function useSearchParams(defaultInit) { | ||
warning(typeof URLSearchParams !== "undefined", `You cannot use the \`useSearchParams\` hook in a browser that does not ` + `support the URLSearchParams API. If you need to support Internet ` + `Explorer 11, we recommend you load a polyfill such as ` + `https://github.com/ungap/url-search-params\n\n` + `If you're unsure how to load polyfills, we recommend you check out ` + `https://polyfill.io/v3/ which provides some recommendations about how ` + `to load polyfills only for users that need them, instead of for every ` + `user.`) ; | ||
UNSAFE_warning(typeof URLSearchParams !== "undefined", `You cannot use the \`useSearchParams\` hook in a browser that does not ` + `support the URLSearchParams API. If you need to support Internet ` + `Explorer 11, we recommend you load a polyfill such as ` + `https://github.com/ungap/url-search-params\n\n` + `If you're unsure how to load polyfills, we recommend you check out ` + `https://polyfill.io/v3/ which provides some recommendations about how ` + `to load polyfills only for users that need them, instead of for every ` + `user.`) ; | ||
let defaultSearchParamsRef = React.useRef(createSearchParams(defaultInit)); | ||
@@ -669,3 +680,3 @@ let hasSetSearchParamsRef = React.useRef(false); | ||
if (fetcherKey) { | ||
!(routeId != null) ? invariant(false, "No routeId available for useFetcher()") : void 0; | ||
!(routeId != null) ? UNSAFE_invariant(false, "No routeId available for useFetcher()") : void 0; | ||
router.fetch(fetcherKey, routeId, href, opts); | ||
@@ -685,3 +696,3 @@ } else { | ||
let routeContext = React.useContext(UNSAFE_RouteContext); | ||
!routeContext ? invariant(false, "useFormAction must be used inside a RouteContext") : void 0; | ||
!routeContext ? UNSAFE_invariant(false, "useFormAction must be used inside a RouteContext") : void 0; | ||
let [match] = routeContext.matches.slice(-1); // Shallow clone path so we can modify it below, otherwise we modify the | ||
@@ -759,13 +770,13 @@ // object referenced by useMemo inside useResolvedPath | ||
let route = React.useContext(UNSAFE_RouteContext); | ||
!route ? invariant(false, `useFetcher must be used inside a RouteContext`) : void 0; | ||
!route ? UNSAFE_invariant(false, `useFetcher must be used inside a RouteContext`) : void 0; | ||
let routeId = route.matches[route.matches.length - 1]?.route.id; | ||
!(routeId != null) ? invariant(false, `useFetcher can only be used on routes that contain a unique "id"`) : void 0; | ||
!(routeId != null) ? UNSAFE_invariant(false, `useFetcher can only be used on routes that contain a unique "id"`) : void 0; | ||
let [fetcherKey] = React.useState(() => String(++fetcherId)); | ||
let [Form] = React.useState(() => { | ||
!routeId ? invariant(false, `No routeId available for fetcher.Form()`) : void 0; | ||
!routeId ? UNSAFE_invariant(false, `No routeId available for fetcher.Form()`) : void 0; | ||
return createFetcherForm(fetcherKey, routeId); | ||
}); | ||
let [load] = React.useState(() => href => { | ||
!router ? invariant(false, "No router available for fetcher.load()") : void 0; | ||
!routeId ? invariant(false, "No routeId available for fetcher.load()") : void 0; | ||
!router ? UNSAFE_invariant(false, "No router available for fetcher.load()") : void 0; | ||
!routeId ? UNSAFE_invariant(false, "No routeId available for fetcher.load()") : void 0; | ||
router.fetch(fetcherKey, routeId, href); | ||
@@ -904,3 +915,2 @@ }); | ||
function useBeforeUnload(callback, options) { | ||
@@ -975,23 +985,5 @@ let { | ||
} | ||
//////////////////////////////////////////////////////////////////////////////// | ||
//#region Utils | ||
//////////////////////////////////////////////////////////////////////////////// | ||
//#endregion | ||
function warning(cond, message) { | ||
if (!cond) { | ||
// eslint-disable-next-line no-console | ||
if (typeof console !== "undefined") console.warn(message); | ||
try { | ||
// Welcome to debugging React Router! | ||
// | ||
// This error is thrown as a convenience so you can more easily | ||
// find the source for a warning that appears in the console by | ||
// enabling "pause on exceptions" in your JavaScript debugger. | ||
throw new Error(message); // eslint-disable-next-line no-empty | ||
} catch (e) {} | ||
} | ||
} //#endregion | ||
export { BrowserRouter, Form, HashRouter, Link, NavLink, ScrollRestoration, useScrollRestoration as UNSAFE_useScrollRestoration, createBrowserRouter, createHashRouter, createSearchParams, HistoryRouter as unstable_HistoryRouter, usePrompt as unstable_usePrompt, useBeforeUnload, useFetcher, useFetchers, useFormAction, useLinkClickHandler, useSearchParams, useSubmit }; | ||
//# sourceMappingURL=react-router-dom.development.js.map |
/** | ||
* React Router DOM v0.0.0-experimental-48058118 | ||
* React Router DOM v0.0.0-experimental-5f6f59a6 | ||
* | ||
@@ -11,3 +11,3 @@ * Copyright (c) Remix Software Inc. | ||
*/ | ||
import*as e from"react";import{UNSAFE_enhanceManualRouteObjects as t,Router as r,useHref as n,useResolvedPath as o,useLocation as a,UNSAFE_DataRouterStateContext as i,UNSAFE_NavigationContext as s,useNavigate as l,createPath as u,UNSAFE_RouteContext as c,useMatches as f,useNavigation as m,unstable_useBlocker as d,UNSAFE_DataRouterContext as h}from"react-router";export{AbortedDeferredError,Await,MemoryRouter,Navigate,NavigationType,Outlet,Route,Router,RouterProvider,Routes,UNSAFE_DataRouterContext,UNSAFE_DataRouterStateContext,UNSAFE_LocationContext,UNSAFE_NavigationContext,UNSAFE_RouteContext,UNSAFE_enhanceManualRouteObjects,createMemoryRouter,createMiddlewareContext,createPath,createRoutesFromChildren,createRoutesFromElements,defer,generatePath,isRouteErrorResponse,json,matchPath,matchRoutes,parsePath,redirect,renderMatches,resolvePath,unstable_useBlocker,useActionData,useAsyncError,useAsyncValue,useHref,useInRouterContext,useLoaderData,useLocation,useMatch,useMatches,useNavigate,useNavigation,useNavigationType,useOutlet,useOutletContext,useParams,useResolvedPath,useRevalidator,useRouteError,useRouteLoaderData,useRoutes}from"react-router";import{createRouter as p,createBrowserHistory as w,createHashHistory as g,ErrorResponse as y,invariant as v,joinPaths as b}from"@remix-run/router";const R="application/x-www-form-urlencoded";function S(e){return null!=e&&"string"==typeof e.tagName}function E(e=""){return new URLSearchParams("string"==typeof e||Array.isArray(e)||e instanceof URLSearchParams?e:Object.keys(e).reduce(((t,r)=>{let n=e[r];return t.concat(Array.isArray(n)?n.map((e=>[r,e])):[[r,n]])}),[]))}function C(e,t,r){let n,o,a,i;if(S(s=e)&&"form"===s.tagName.toLowerCase()){let s=r.submissionTrigger;n=r.method||e.getAttribute("method")||"get",o=r.action||e.getAttribute("action")||t,a=r.encType||e.getAttribute("enctype")||R,i=new FormData(e),s&&s.name&&i.append(s.name,s.value)}else if(function(e){return S(e)&&"button"===e.tagName.toLowerCase()}(e)||function(e){return S(e)&&"input"===e.tagName.toLowerCase()}(e)&&("submit"===e.type||"image"===e.type)){let s=e.form;if(null==s)throw new Error('Cannot submit a <button> or <input type="submit"> without a <form>');n=r.method||e.getAttribute("formmethod")||s.getAttribute("method")||"get",o=r.action||e.getAttribute("formaction")||s.getAttribute("action")||t,a=r.encType||e.getAttribute("formenctype")||s.getAttribute("enctype")||R,i=new FormData(s),e.name&&i.append(e.name,e.value)}else{if(S(e))throw new Error('Cannot submit element that is not <form>, <button>, or <input type="submit|image">');if(n=r.method||"get",o=r.action||t,a=r.encType||R,e instanceof FormData)i=e;else if(i=new FormData,e instanceof URLSearchParams)for(let[t,r]of e)i.append(t,r);else if(null!=e)for(let t of Object.keys(e))i.append(t,e[t])}var s;let{protocol:l,host:u}=window.location;return{url:new URL(o,`${l}//${u}`),method:n.toLowerCase(),encType:a,formData:i}}function A(e,r){return p({basename:r?.basename,history:w({window:r?.window}),hydrationData:r?.hydrationData||x(),routes:t(e)}).initialize()}function L(e,r){return p({basename:r?.basename,history:g({window:r?.window}),hydrationData:r?.hydrationData||x(),routes:t(e)}).initialize()}function x(){let e=window?.__staticRouterHydrationData;return e&&e.errors&&(e={...e,errors:U(e.errors)}),e}function U(e){if(!e)return null;let t=Object.entries(e),r={};for(let[n,o]of t)if(o&&"RouteErrorResponse"===o.__type)r[n]=new y(o.status,o.statusText,o.data,!0===o.internal);else if(o&&"Error"===o.__type){let e=new Error(o.message);e.stack="",r[n]=e}else r[n]=o;return r}function F({basename:t,children:n,window:o}){let a=e.useRef();null==a.current&&(a.current=w({window:o,v5Compat:!0}));let i=a.current,[s,l]=e.useState({action:i.action,location:i.location});return e.useLayoutEffect((()=>i.listen(l)),[i]),e.createElement(r,{basename:t,children:n,location:s.location,navigationType:s.action,navigator:i})}function D({basename:t,children:n,window:o}){let a=e.useRef();null==a.current&&(a.current=g({window:o,v5Compat:!0}));let i=a.current,[s,l]=e.useState({action:i.action,location:i.location});return e.useLayoutEffect((()=>i.listen(l)),[i]),e.createElement(r,{basename:t,children:n,location:s.location,navigationType:s.action,navigator:i})}function N({basename:t,children:n,history:o}){const[a,i]=e.useState({action:o.action,location:o.location});return e.useLayoutEffect((()=>o.listen(i)),[o]),e.createElement(r,{basename:t,children:n,location:a.location,navigationType:a.action,navigator:o})}const P="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,T=e.forwardRef((function({onClick:t,relative:r,reloadDocument:o,replace:a,state:i,target:s,to:l,preventScrollReset:u,...c},f){let m,d=!1;if(P&&"string"==typeof l&&/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i.test(l)){m=l;let e=new URL(window.location.href),t=l.startsWith("//")?new URL(e.protocol+l):new URL(l);t.origin===e.origin?l=t.pathname+t.search+t.hash:d=!0}let h=n(l,{relative:r}),p=B(l,{replace:a,state:i,target:s,preventScrollReset:u,relative:r});return e.createElement("a",Object.assign({},c,{href:m||h,onClick:d||o?t:function(e){t&&t(e),e.defaultPrevented||p(e)},ref:f,target:s}))})),_=e.forwardRef((function({"aria-current":t="page",caseSensitive:r=!1,className:n="",end:l=!1,style:u,to:c,children:f,...m},d){let h=o(c,{relative:m.relative}),p=a(),w=e.useContext(i),{navigator:g}=e.useContext(s),y=g.encodeLocation?g.encodeLocation(h).pathname:h.pathname,v=p.pathname,b=w&&w.navigation&&w.navigation.location?w.navigation.location.pathname:null;r||(v=v.toLowerCase(),b=b?b.toLowerCase():null,y=y.toLowerCase());let R,S=v===y||!l&&v.startsWith(y)&&"/"===v.charAt(y.length),E=null!=b&&(b===y||!l&&b.startsWith(y)&&"/"===b.charAt(y.length)),C=S?t:void 0;R="function"==typeof n?n({isActive:S,isPending:E}):[n,S?"active":null,E?"pending":null].filter(Boolean).join(" ");let A="function"==typeof u?u({isActive:S,isPending:E}):u;return e.createElement(T,Object.assign({},m,{"aria-current":C,className:R,ref:d,style:A,to:c}),"function"==typeof f?f({isActive:S,isPending:E}):f)})),k=e.forwardRef(((t,r)=>e.createElement(O,Object.assign({},t,{ref:r})))),O=e.forwardRef((({reloadDocument:t,replace:r,method:n="get",action:o,onSubmit:a,fetcherKey:i,routeId:s,relative:l,preventScrollReset:u,...c},f)=>{let m=Y(i,s),d="get"===n.toLowerCase()?"get":"post",h=$(o,{relative:l});return e.createElement("form",Object.assign({ref:f,method:d,action:h,onSubmit:t?a:e=>{if(a&&a(e),e.defaultPrevented)return;e.preventDefault();let t=e.nativeEvent.submitter,o=t?.getAttribute("formmethod")||n;m(t||e.currentTarget,{method:o,replace:r,relative:l,preventScrollReset:u})}},c))}));function K({getKey:e,storageKey:t}){return Q({getKey:e,storageKey:t}),null}var j,I;function M(t){let r=e.useContext(h);return r||v(!1),r}function z(t){let r=e.useContext(i);return r||v(!1),r}function B(t,{target:r,replace:n,state:i,preventScrollReset:s,relative:c}={}){let f=l(),m=a(),d=o(t,{relative:c});return e.useCallback((e=>{if(function(e,t){return!(0!==e.button||t&&"_self"!==t||function(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}(e))}(e,r)){e.preventDefault();let r=void 0!==n?n:u(m)===u(d);f(t,{replace:r,state:i,preventScrollReset:s,relative:c})}}),[m,f,d,n,i,r,t,s,c])}function H(t){let r=e.useRef(E(t)),n=e.useRef(!1),o=a(),i=e.useMemo((()=>function(e,t){let r=E(e);if(t)for(let n of t.keys())r.has(n)||t.getAll(n).forEach((e=>{r.append(n,e)}));return r}(o.search,n.current?null:r.current)),[o.search]),s=l(),u=e.useCallback(((e,t)=>{const r=E("function"==typeof e?e(i):e);n.current=!0,s("?"+r,t)}),[s,i]);return[i,u]}function W(){return Y()}function Y(t,r){let{router:n}=M(j.UseSubmitImpl),o=$();return e.useCallback(((e,a={})=>{if("undefined"==typeof document)throw new Error("You are calling submit during the server render. Try calling submit within a `useEffect` or callback instead.");let{method:i,encType:s,formData:l,url:u}=C(e,o,a),c=u.pathname+u.search,f={replace:a.replace,preventScrollReset:a.preventScrollReset,formData:l,formMethod:i,formEncType:s};t?(null==r&&v(!1),n.fetch(t,r,c,f)):n.navigate(c,f)}),[o,n,t,r])}function $(t,{relative:r}={}){let{basename:n}=e.useContext(s),i=e.useContext(c);i||v(!1);let[l]=i.matches.slice(-1),f={...o(t||".",{relative:r})},m=a();if(null==t&&(f.search=m.search,f.hash=m.hash,l.route.index)){let e=new URLSearchParams(f.search);e.delete("index"),f.search=e.toString()?`?${e.toString()}`:""}return t&&"."!==t||!l.route.index||(f.search=f.search?f.search.replace(/^\?/,"?index&"):"?index"),"/"!==n&&(f.pathname="/"===f.pathname?n:b([n,f.pathname])),u(f)}!function(e){e.UseScrollRestoration="useScrollRestoration",e.UseSubmitImpl="useSubmitImpl",e.UseFetcher="useFetcher"}(j||(j={})),function(e){e.UseFetchers="useFetchers",e.UseScrollRestoration="useScrollRestoration"}(I||(I={}));let J=0;function V(){let{router:t}=M(j.UseFetcher),r=e.useContext(c);r||v(!1);let n=r.matches[r.matches.length-1]?.route.id;null==n&&v(!1);let[o]=e.useState((()=>String(++J))),[a]=e.useState((()=>(n||v(!1),function(t,r){return e.forwardRef(((n,o)=>e.createElement(O,Object.assign({},n,{ref:o,fetcherKey:t,routeId:r}))))}(o,n)))),[i]=e.useState((()=>e=>{t||v(!1),n||v(!1),t.fetch(o,n,e)})),s=Y(o,n),l=t.getFetcher(o),u=e.useMemo((()=>({Form:a,submit:s,load:i,...l})),[l,a,s,i]);return e.useEffect((()=>()=>{t?t.deleteFetcher(o):console.warn("No fetcher available to clean up from useFetcher()")}),[t,o]),u}function q(){return[...z(I.UseFetchers).fetchers.values()]}let G={};function Q({getKey:t,storageKey:r}={}){let{router:n}=M(j.UseScrollRestoration),{restoreScrollPosition:o,preventScrollReset:i}=z(I.UseScrollRestoration),s=a(),l=f(),u=m();e.useEffect((()=>(window.history.scrollRestoration="manual",()=>{window.history.scrollRestoration="auto"})),[]),function(t,r){let{capture:n}=r||{};e.useEffect((()=>{let e=null!=n?{capture:n}:void 0;return window.addEventListener("pagehide",t,e),()=>{window.removeEventListener("pagehide",t,e)}}),[t,n])}(e.useCallback((()=>{if("idle"===u.state){let e=(t?t(s,l):null)||s.key;G[e]=window.scrollY}sessionStorage.setItem(r||"react-router-scroll-positions",JSON.stringify(G)),window.history.scrollRestoration="auto"}),[r,t,u.state,s,l])),"undefined"!=typeof document&&(e.useLayoutEffect((()=>{try{let e=sessionStorage.getItem(r||"react-router-scroll-positions");e&&(G=JSON.parse(e))}catch(e){}}),[r]),e.useLayoutEffect((()=>{let e=n?.enableScrollRestoration(G,(()=>window.scrollY),t);return()=>e&&e()}),[n,t]),e.useLayoutEffect((()=>{if(!1!==o)if("number"!=typeof o){if(s.hash){let e=document.getElementById(s.hash.slice(1));if(e)return void e.scrollIntoView()}!0!==i&&window.scrollTo(0,0)}else window.scrollTo(0,o)}),[s,o,i]))}function X(t,r){let{capture:n}=r||{};e.useEffect((()=>{let e=null!=n?{capture:n}:void 0;return window.addEventListener("beforeunload",t,e),()=>{window.removeEventListener("beforeunload",t,e)}}),[t,n])}function Z({when:t,message:r}){let n=d(t);e.useEffect((()=>{"blocked"!==n.state||t||n.reset()}),[n,t]),e.useEffect((()=>{if("blocked"===n.state){window.confirm(r)?setTimeout(n.proceed,0):n.reset()}}),[n,r])}export{F as BrowserRouter,k as Form,D as HashRouter,T as Link,_ as NavLink,K as ScrollRestoration,Q as UNSAFE_useScrollRestoration,A as createBrowserRouter,L as createHashRouter,E as createSearchParams,N as unstable_HistoryRouter,Z as unstable_usePrompt,X as useBeforeUnload,V as useFetcher,q as useFetchers,$ as useFormAction,B as useLinkClickHandler,H as useSearchParams,W as useSubmit}; | ||
import*as e from"react";import{UNSAFE_detectErrorBoundary as t,Router as r,UNSAFE_NavigationContext as n,useHref as o,useResolvedPath as a,useLocation as i,UNSAFE_DataRouterStateContext as s,useNavigate as u,createPath as l,UNSAFE_RouteContext as c,useMatches as f,useNavigation as m,unstable_useBlocker as d,UNSAFE_DataRouterContext as h}from"react-router";export{AbortedDeferredError,Await,MemoryRouter,Navigate,NavigationType,Outlet,Route,Router,RouterProvider,Routes,UNSAFE_DataRouterContext,UNSAFE_DataRouterStateContext,UNSAFE_LocationContext,UNSAFE_NavigationContext,UNSAFE_RouteContext,createMemoryRouter,createPath,createRoutesFromChildren,createRoutesFromElements,defer,generatePath,isRouteErrorResponse,json,matchPath,matchRoutes,parsePath,redirect,renderMatches,resolvePath,unstable_useBlocker,useActionData,useAsyncError,useAsyncValue,useHref,useInRouterContext,useLoaderData,useLocation,useMatch,useMatches,useNavigate,useNavigation,useNavigationType,useOutlet,useOutletContext,useParams,useResolvedPath,useRevalidator,useRouteError,useRouteLoaderData,useRoutes}from"react-router";import{createRouter as p,createBrowserHistory as w,createHashHistory as g,ErrorResponse as y,stripBasename as v,UNSAFE_invariant as b,joinPaths as R}from"@remix-run/router";const E="application/x-www-form-urlencoded";function S(e){return null!=e&&"string"==typeof e.tagName}function C(e=""){return new URLSearchParams("string"==typeof e||Array.isArray(e)||e instanceof URLSearchParams?e:Object.keys(e).reduce(((t,r)=>{let n=e[r];return t.concat(Array.isArray(n)?n.map((e=>[r,e])):[[r,n]])}),[]))}function L(e,t,r){let n,o,a,i;if(S(s=e)&&"form"===s.tagName.toLowerCase()){let s=r.submissionTrigger;n=r.method||e.getAttribute("method")||"get",o=r.action||e.getAttribute("action")||t,a=r.encType||e.getAttribute("enctype")||E,i=new FormData(e),s&&s.name&&i.append(s.name,s.value)}else if(function(e){return S(e)&&"button"===e.tagName.toLowerCase()}(e)||function(e){return S(e)&&"input"===e.tagName.toLowerCase()}(e)&&("submit"===e.type||"image"===e.type)){let s=e.form;if(null==s)throw new Error('Cannot submit a <button> or <input type="submit"> without a <form>');n=r.method||e.getAttribute("formmethod")||s.getAttribute("method")||"get",o=r.action||e.getAttribute("formaction")||s.getAttribute("action")||t,a=r.encType||e.getAttribute("formenctype")||s.getAttribute("enctype")||E,i=new FormData(s),e.name&&i.append(e.name,e.value)}else{if(S(e))throw new Error('Cannot submit element that is not <form>, <button>, or <input type="submit|image">');if(n=r.method||"get",o=r.action||t,a=r.encType||E,e instanceof FormData)i=e;else if(i=new FormData,e instanceof URLSearchParams)for(let[t,r]of e)i.append(t,r);else if(null!=e)for(let t of Object.keys(e))i.append(t,e[t])}var s;let{protocol:u,host:l}=window.location;return{url:new URL(o,`${u}//${l}`),method:n.toLowerCase(),encType:a,formData:i}}function A(e,r){return p({basename:r?.basename,history:w({window:r?.window}),hydrationData:r?.hydrationData||U(),routes:e,detectErrorBoundary:t}).initialize()}function x(e,r){return p({basename:r?.basename,history:g({window:r?.window}),hydrationData:r?.hydrationData||U(),routes:e,detectErrorBoundary:t}).initialize()}function U(){let e=window?.__staticRouterHydrationData;return e&&e.errors&&(e={...e,errors:D(e.errors)}),e}function D(e){if(!e)return null;let t=Object.entries(e),r={};for(let[n,o]of t)if(o&&"RouteErrorResponse"===o.__type)r[n]=new y(o.status,o.statusText,o.data,!0===o.internal);else if(o&&"Error"===o.__type){let e=new Error(o.message);e.stack="",r[n]=e}else r[n]=o;return r}function F({basename:t,children:n,window:o}){let a=e.useRef();null==a.current&&(a.current=w({window:o,v5Compat:!0}));let i=a.current,[s,u]=e.useState({action:i.action,location:i.location});return e.useLayoutEffect((()=>i.listen(u)),[i]),e.createElement(r,{basename:t,children:n,location:s.location,navigationType:s.action,navigator:i})}function N({basename:t,children:n,window:o}){let a=e.useRef();null==a.current&&(a.current=g({window:o,v5Compat:!0}));let i=a.current,[s,u]=e.useState({action:i.action,location:i.location});return e.useLayoutEffect((()=>i.listen(u)),[i]),e.createElement(r,{basename:t,children:n,location:s.location,navigationType:s.action,navigator:i})}function P({basename:t,children:n,history:o}){const[a,i]=e.useState({action:o.action,location:o.location});return e.useLayoutEffect((()=>o.listen(i)),[o]),e.createElement(r,{basename:t,children:n,location:a.location,navigationType:a.action,navigator:o})}const T="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,_=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,k=e.forwardRef((function({onClick:t,relative:r,reloadDocument:a,replace:i,state:s,target:u,to:l,preventScrollReset:c,...f},m){let d,{basename:h}=e.useContext(n),p=!1;if("string"==typeof l&&_.test(l)&&(d=l,T)){let e=new URL(window.location.href),t=l.startsWith("//")?new URL(e.protocol+l):new URL(l),r=v(t.pathname,h);t.origin===e.origin&&null!=r?l=r+t.search+t.hash:p=!0}let w=o(l,{relative:r}),g=W(l,{replace:i,state:s,target:u,preventScrollReset:c,relative:r});return e.createElement("a",Object.assign({},f,{href:d||w,onClick:p||a?t:function(e){t&&t(e),e.defaultPrevented||g(e)},ref:m,target:u}))})),O=e.forwardRef((function({"aria-current":t="page",caseSensitive:r=!1,className:o="",end:u=!1,style:l,to:c,children:f,...m},d){let h=a(c,{relative:m.relative}),p=i(),w=e.useContext(s),{navigator:g}=e.useContext(n),y=g.encodeLocation?g.encodeLocation(h).pathname:h.pathname,v=p.pathname,b=w&&w.navigation&&w.navigation.location?w.navigation.location.pathname:null;r||(v=v.toLowerCase(),b=b?b.toLowerCase():null,y=y.toLowerCase());let R,E=v===y||!u&&v.startsWith(y)&&"/"===v.charAt(y.length),S=null!=b&&(b===y||!u&&b.startsWith(y)&&"/"===b.charAt(y.length)),C=E?t:void 0;R="function"==typeof o?o({isActive:E,isPending:S}):[o,E?"active":null,S?"pending":null].filter(Boolean).join(" ");let L="function"==typeof l?l({isActive:E,isPending:S}):l;return e.createElement(k,Object.assign({},m,{"aria-current":C,className:R,ref:d,style:L,to:c}),"function"==typeof f?f({isActive:E,isPending:S}):f)})),K=e.forwardRef(((t,r)=>e.createElement(j,Object.assign({},t,{ref:r})))),j=e.forwardRef((({reloadDocument:t,replace:r,method:n="get",action:o,onSubmit:a,fetcherKey:i,routeId:s,relative:u,preventScrollReset:l,...c},f)=>{let m=J(i,s),d="get"===n.toLowerCase()?"get":"post",h=V(o,{relative:u});return e.createElement("form",Object.assign({ref:f,method:d,action:h,onSubmit:t?a:e=>{if(a&&a(e),e.defaultPrevented)return;e.preventDefault();let t=e.nativeEvent.submitter,o=t?.getAttribute("formmethod")||n;m(t||e.currentTarget,{method:o,replace:r,relative:u,preventScrollReset:l})}},c))}));function I({getKey:e,storageKey:t}){return Z({getKey:e,storageKey:t}),null}var M,B;function z(t){let r=e.useContext(h);return r||b(!1),r}function H(t){let r=e.useContext(s);return r||b(!1),r}function W(t,{target:r,replace:n,state:o,preventScrollReset:s,relative:c}={}){let f=u(),m=i(),d=a(t,{relative:c});return e.useCallback((e=>{if(function(e,t){return!(0!==e.button||t&&"_self"!==t||function(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}(e))}(e,r)){e.preventDefault();let r=void 0!==n?n:l(m)===l(d);f(t,{replace:r,state:o,preventScrollReset:s,relative:c})}}),[m,f,d,n,o,r,t,s,c])}function Y(t){let r=e.useRef(C(t)),n=e.useRef(!1),o=i(),a=e.useMemo((()=>function(e,t){let r=C(e);if(t)for(let n of t.keys())r.has(n)||t.getAll(n).forEach((e=>{r.append(n,e)}));return r}(o.search,n.current?null:r.current)),[o.search]),s=u(),l=e.useCallback(((e,t)=>{const r=C("function"==typeof e?e(a):e);n.current=!0,s("?"+r,t)}),[s,a]);return[a,l]}function $(){return J()}function J(t,r){let{router:n}=z(M.UseSubmitImpl),o=V();return e.useCallback(((e,a={})=>{if("undefined"==typeof document)throw new Error("You are calling submit during the server render. Try calling submit within a `useEffect` or callback instead.");let{method:i,encType:s,formData:u,url:l}=L(e,o,a),c=l.pathname+l.search,f={replace:a.replace,preventScrollReset:a.preventScrollReset,formData:u,formMethod:i,formEncType:s};t?(null==r&&b(!1),n.fetch(t,r,c,f)):n.navigate(c,f)}),[o,n,t,r])}function V(t,{relative:r}={}){let{basename:o}=e.useContext(n),s=e.useContext(c);s||b(!1);let[u]=s.matches.slice(-1),f={...a(t||".",{relative:r})},m=i();if(null==t&&(f.search=m.search,f.hash=m.hash,u.route.index)){let e=new URLSearchParams(f.search);e.delete("index"),f.search=e.toString()?`?${e.toString()}`:""}return t&&"."!==t||!u.route.index||(f.search=f.search?f.search.replace(/^\?/,"?index&"):"?index"),"/"!==o&&(f.pathname="/"===f.pathname?o:R([o,f.pathname])),l(f)}!function(e){e.UseScrollRestoration="useScrollRestoration",e.UseSubmitImpl="useSubmitImpl",e.UseFetcher="useFetcher"}(M||(M={})),function(e){e.UseFetchers="useFetchers",e.UseScrollRestoration="useScrollRestoration"}(B||(B={}));let q=0;function G(){let{router:t}=z(M.UseFetcher),r=e.useContext(c);r||b(!1);let n=r.matches[r.matches.length-1]?.route.id;null==n&&b(!1);let[o]=e.useState((()=>String(++q))),[a]=e.useState((()=>(n||b(!1),function(t,r){return e.forwardRef(((n,o)=>e.createElement(j,Object.assign({},n,{ref:o,fetcherKey:t,routeId:r}))))}(o,n)))),[i]=e.useState((()=>e=>{t||b(!1),n||b(!1),t.fetch(o,n,e)})),s=J(o,n),u=t.getFetcher(o),l=e.useMemo((()=>({Form:a,submit:s,load:i,...u})),[u,a,s,i]);return e.useEffect((()=>()=>{t?t.deleteFetcher(o):console.warn("No fetcher available to clean up from useFetcher()")}),[t,o]),l}function Q(){return[...H(B.UseFetchers).fetchers.values()]}let X={};function Z({getKey:t,storageKey:r}={}){let{router:n}=z(M.UseScrollRestoration),{restoreScrollPosition:o,preventScrollReset:a}=H(B.UseScrollRestoration),s=i(),u=f(),l=m();e.useEffect((()=>(window.history.scrollRestoration="manual",()=>{window.history.scrollRestoration="auto"})),[]),function(t,r){let{capture:n}=r||{};e.useEffect((()=>{let e=null!=n?{capture:n}:void 0;return window.addEventListener("pagehide",t,e),()=>{window.removeEventListener("pagehide",t,e)}}),[t,n])}(e.useCallback((()=>{if("idle"===l.state){let e=(t?t(s,u):null)||s.key;X[e]=window.scrollY}sessionStorage.setItem(r||"react-router-scroll-positions",JSON.stringify(X)),window.history.scrollRestoration="auto"}),[r,t,l.state,s,u])),"undefined"!=typeof document&&(e.useLayoutEffect((()=>{try{let e=sessionStorage.getItem(r||"react-router-scroll-positions");e&&(X=JSON.parse(e))}catch(e){}}),[r]),e.useLayoutEffect((()=>{let e=n?.enableScrollRestoration(X,(()=>window.scrollY),t);return()=>e&&e()}),[n,t]),e.useLayoutEffect((()=>{if(!1!==o)if("number"!=typeof o){if(s.hash){let e=document.getElementById(s.hash.slice(1));if(e)return void e.scrollIntoView()}!0!==a&&window.scrollTo(0,0)}else window.scrollTo(0,o)}),[s,o,a]))}function ee(t,r){let{capture:n}=r||{};e.useEffect((()=>{let e=null!=n?{capture:n}:void 0;return window.addEventListener("beforeunload",t,e),()=>{window.removeEventListener("beforeunload",t,e)}}),[t,n])}function te({when:t,message:r}){let n=d(t);e.useEffect((()=>{"blocked"!==n.state||t||n.reset()}),[n,t]),e.useEffect((()=>{if("blocked"===n.state){window.confirm(r)?setTimeout(n.proceed,0):n.reset()}}),[n,r])}export{F as BrowserRouter,K as Form,N as HashRouter,k as Link,O as NavLink,I as ScrollRestoration,Z as UNSAFE_useScrollRestoration,A as createBrowserRouter,x as createHashRouter,C as createSearchParams,P as unstable_HistoryRouter,te as unstable_usePrompt,ee as useBeforeUnload,G as useFetcher,Q as useFetchers,V as useFormAction,W as useLinkClickHandler,Y as useSearchParams,$ as useSubmit}; | ||
//# sourceMappingURL=react-router-dom.production.min.js.map |
import * as React from "react"; | ||
import type { Router as RemixRouter, StaticHandlerContext } from "@remix-run/router"; | ||
import type { Router as RemixRouter, StaticHandlerContext, CreateStaticHandlerOptions as RouterCreateStaticHandlerOptions } from "@remix-run/router"; | ||
import type { Location, RouteObject } from "react-router-dom"; | ||
@@ -14,2 +14,3 @@ export interface StaticRouterProps { | ||
export declare function StaticRouter({ basename, children, location: locationProp, }: StaticRouterProps): JSX.Element; | ||
export { StaticHandlerContext }; | ||
export interface StaticRouterProviderProps { | ||
@@ -26,2 +27,4 @@ context: StaticHandlerContext; | ||
export declare function StaticRouterProvider({ context, router, hydrate, nonce, }: StaticRouterProviderProps): JSX.Element; | ||
declare type CreateStaticHandlerOptions = Omit<RouterCreateStaticHandlerOptions, "detectErrorBoundary">; | ||
export declare function createStaticHandler(routes: RouteObject[], opts?: CreateStaticHandlerOptions): import("@remix-run/router").StaticHandler; | ||
export declare function createStaticRouter(routes: RouteObject[], context: StaticHandlerContext): RemixRouter; |
@@ -72,3 +72,3 @@ 'use strict'; | ||
}) { | ||
!(router$1 && context) ? process.env.NODE_ENV !== "production" ? router.invariant(false, "You must provide `router` and `context` to <StaticRouterProvider>") : router.invariant(false) : void 0; | ||
!(router$1 && context) ? process.env.NODE_ENV !== "production" ? router.UNSAFE_invariant(false, "You must provide `router` and `context` to <StaticRouterProvider>") : router.UNSAFE_invariant(false) : void 0; | ||
let dataRouterContext = { | ||
@@ -93,3 +93,3 @@ router: router$1, | ||
let json = JSON.stringify(JSON.stringify(data)); | ||
let json = htmlEscape(JSON.stringify(JSON.stringify(data))); | ||
hydrateScript = `window.__staticRouterHydrationData = JSON.parse(${json});`; | ||
@@ -168,22 +168,14 @@ } | ||
}; | ||
} // Temporary manifest generation - we should optimize this by combining the | ||
// tree-walks between convertRoutesToDataRoutes, enhanceManualRouteObjects, | ||
// and generateManifest. | ||
// Also look into getting rid of `route as AgnosticDataRouteObject` down below? | ||
} | ||
let detectErrorBoundary = route => Boolean(route.errorElement); | ||
function generateManifest(routes, manifest = new Map()) { | ||
routes.forEach(route => { | ||
manifest.set(route.id, route); | ||
if (route.children) { | ||
generateManifest(route.children, manifest); | ||
} | ||
function createStaticHandler(routes, opts) { | ||
return router.createStaticHandler(routes, { ...opts, | ||
detectErrorBoundary | ||
}); | ||
return manifest; | ||
} | ||
function createStaticRouter(routes, context) { | ||
let dataRoutes = router.UNSAFE_convertRoutesToDataRoutes(reactRouterDom.UNSAFE_enhanceManualRouteObjects(routes)); | ||
let manifest = generateManifest(dataRoutes); // Because our context matches may be from a framework-agnostic set of | ||
let manifest = {}; | ||
let dataRoutes = router.UNSAFE_convertRoutesToDataRoutes(routes, detectErrorBoundary, undefined, manifest); // Because our context matches may be from a framework-agnostic set of | ||
// routes passed to createStaticHandler(), we update them here with our | ||
@@ -193,5 +185,5 @@ // newly created/enhanced data routes | ||
let matches = context.matches.map(match => { | ||
let route = manifest.get(match.route.id) || match.route; | ||
let route = manifest[match.route.id] || match.route; | ||
return { ...match, | ||
route: route | ||
route | ||
}; | ||
@@ -269,3 +261,3 @@ }); | ||
getBlocker() { | ||
throw msg("getBlocker"); | ||
return router.IDLE_BLOCKER; | ||
}, | ||
@@ -278,3 +270,8 @@ | ||
_internalFetchControllers: new Map(), | ||
_internalActiveDeferreds: new Map() | ||
_internalActiveDeferreds: new Map(), | ||
_internalSetRoutes() { | ||
throw msg("_internalSetRoutes"); | ||
} | ||
}; | ||
@@ -295,2 +292,17 @@ } | ||
}; | ||
} // This utility is based on https://github.com/zertosh/htmlescape | ||
// License: https://github.com/zertosh/htmlescape/blob/0527ca7156a524d256101bb310a9f970f63078ad/LICENSE | ||
const ESCAPE_LOOKUP = { | ||
"&": "\\u0026", | ||
">": "\\u003e", | ||
"<": "\\u003c", | ||
"\u2028": "\\u2028", | ||
"\u2029": "\\u2029" | ||
}; | ||
const ESCAPE_REGEX = /[&><\u2028\u2029]/g; | ||
function htmlEscape(str) { | ||
return str.replace(ESCAPE_REGEX, match => ESCAPE_LOOKUP[match]); | ||
} | ||
@@ -300,2 +312,3 @@ | ||
exports.StaticRouterProvider = StaticRouterProvider; | ||
exports.createStaticHandler = createStaticHandler; | ||
exports.createStaticRouter = createStaticRouter; |
/** | ||
* React Router DOM v0.0.0-experimental-48058118 | ||
* React Router DOM v0.0.0-experimental-5f6f59a6 | ||
* | ||
@@ -225,3 +225,4 @@ * Copyright (c) Remix Software Inc. | ||
hydrationData: (opts == null ? void 0 : opts.hydrationData) || parseHydrationData(), | ||
routes: reactRouter.UNSAFE_enhanceManualRouteObjects(routes) | ||
routes, | ||
detectErrorBoundary: reactRouter.UNSAFE_detectErrorBoundary | ||
}).initialize(); | ||
@@ -236,3 +237,4 @@ } | ||
hydrationData: (opts == null ? void 0 : opts.hydrationData) || parseHydrationData(), | ||
routes: reactRouter.UNSAFE_enhanceManualRouteObjects(routes) | ||
routes, | ||
detectErrorBoundary: reactRouter.UNSAFE_detectErrorBoundary | ||
}).initialize(); | ||
@@ -380,2 +382,3 @@ } | ||
const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined"; | ||
const ABSOLUTE_URL_REGEX = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i; | ||
/** | ||
@@ -398,16 +401,24 @@ * The public API for rendering a history-aware <a>. | ||
// Rendered into <a href> for absolute URLs | ||
let { | ||
basename | ||
} = React__namespace.useContext(reactRouter.UNSAFE_NavigationContext); // Rendered into <a href> for absolute URLs | ||
let absoluteHref; | ||
let isExternal = false; | ||
if (isBrowser && typeof to === "string" && /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i.test(to)) { | ||
absoluteHref = to; | ||
let currentUrl = new URL(window.location.href); | ||
let targetUrl = to.startsWith("//") ? new URL(currentUrl.protocol + to) : new URL(to); | ||
if (typeof to === "string" && ABSOLUTE_URL_REGEX.test(to)) { | ||
// Render the absolute href server- and client-side | ||
absoluteHref = to; // Only check for external origins client-side | ||
if (targetUrl.origin === currentUrl.origin) { | ||
// Strip the protocol/origin for same-origin absolute URLs | ||
to = targetUrl.pathname + targetUrl.search + targetUrl.hash; | ||
} else { | ||
isExternal = true; | ||
if (isBrowser) { | ||
let currentUrl = new URL(window.location.href); | ||
let targetUrl = to.startsWith("//") ? new URL(currentUrl.protocol + to) : new URL(to); | ||
let path = router.stripBasename(targetUrl.pathname, basename); | ||
if (targetUrl.origin === currentUrl.origin && path != null) { | ||
// Strip the protocol/origin/basename for same-origin absolute URLs | ||
to = path + targetUrl.search + targetUrl.hash; | ||
} else { | ||
isExternal = true; | ||
} | ||
} | ||
@@ -631,3 +642,3 @@ } // Rendered into <a href> for relative URLs | ||
let ctx = React__namespace.useContext(reactRouter.UNSAFE_DataRouterContext); | ||
!ctx ? router.invariant(false, getDataRouterConsoleError(hookName)) : void 0; | ||
!ctx ? router.UNSAFE_invariant(false, getDataRouterConsoleError(hookName)) : void 0; | ||
return ctx; | ||
@@ -638,3 +649,3 @@ } | ||
let state = React__namespace.useContext(reactRouter.UNSAFE_DataRouterStateContext); | ||
!state ? router.invariant(false, getDataRouterConsoleError(hookName)) : void 0; | ||
!state ? router.UNSAFE_invariant(false, getDataRouterConsoleError(hookName)) : void 0; | ||
return state; | ||
@@ -683,3 +694,3 @@ } | ||
function useSearchParams(defaultInit) { | ||
warning(typeof URLSearchParams !== "undefined", "You cannot use the `useSearchParams` hook in a browser that does not " + "support the URLSearchParams API. If you need to support Internet " + "Explorer 11, we recommend you load a polyfill such as " + "https://github.com/ungap/url-search-params\n\n" + "If you're unsure how to load polyfills, we recommend you check out " + "https://polyfill.io/v3/ which provides some recommendations about how " + "to load polyfills only for users that need them, instead of for every " + "user.") ; | ||
router.UNSAFE_warning(typeof URLSearchParams !== "undefined", "You cannot use the `useSearchParams` hook in a browser that does not " + "support the URLSearchParams API. If you need to support Internet " + "Explorer 11, we recommend you load a polyfill such as " + "https://github.com/ungap/url-search-params\n\n" + "If you're unsure how to load polyfills, we recommend you check out " + "https://polyfill.io/v3/ which provides some recommendations about how " + "to load polyfills only for users that need them, instead of for every " + "user.") ; | ||
let defaultSearchParamsRef = React__namespace.useRef(createSearchParams(defaultInit)); | ||
@@ -739,3 +750,3 @@ let hasSetSearchParamsRef = React__namespace.useRef(false); | ||
if (fetcherKey) { | ||
!(routeId != null) ? router.invariant(false, "No routeId available for useFetcher()") : void 0; | ||
!(routeId != null) ? router.UNSAFE_invariant(false, "No routeId available for useFetcher()") : void 0; | ||
router$1.fetch(fetcherKey, routeId, href, opts); | ||
@@ -756,3 +767,3 @@ } else { | ||
let routeContext = React__namespace.useContext(reactRouter.UNSAFE_RouteContext); | ||
!routeContext ? router.invariant(false, "useFormAction must be used inside a RouteContext") : void 0; | ||
!routeContext ? router.UNSAFE_invariant(false, "useFormAction must be used inside a RouteContext") : void 0; | ||
let [match] = routeContext.matches.slice(-1); // Shallow clone path so we can modify it below, otherwise we modify the | ||
@@ -832,13 +843,13 @@ // object referenced by useMemo inside useResolvedPath | ||
let route = React__namespace.useContext(reactRouter.UNSAFE_RouteContext); | ||
!route ? router.invariant(false, "useFetcher must be used inside a RouteContext") : void 0; | ||
!route ? router.UNSAFE_invariant(false, "useFetcher must be used inside a RouteContext") : void 0; | ||
let routeId = (_route$matches = route.matches[route.matches.length - 1]) == null ? void 0 : _route$matches.route.id; | ||
!(routeId != null) ? router.invariant(false, "useFetcher can only be used on routes that contain a unique \"id\"") : void 0; | ||
!(routeId != null) ? router.UNSAFE_invariant(false, "useFetcher can only be used on routes that contain a unique \"id\"") : void 0; | ||
let [fetcherKey] = React__namespace.useState(() => String(++fetcherId)); | ||
let [Form] = React__namespace.useState(() => { | ||
!routeId ? router.invariant(false, "No routeId available for fetcher.Form()") : void 0; | ||
!routeId ? router.UNSAFE_invariant(false, "No routeId available for fetcher.Form()") : void 0; | ||
return createFetcherForm(fetcherKey, routeId); | ||
}); | ||
let [load] = React__namespace.useState(() => href => { | ||
!router$1 ? router.invariant(false, "No router available for fetcher.load()") : void 0; | ||
!routeId ? router.invariant(false, "No routeId available for fetcher.load()") : void 0; | ||
!router$1 ? router.UNSAFE_invariant(false, "No router available for fetcher.load()") : void 0; | ||
!routeId ? router.UNSAFE_invariant(false, "No routeId available for fetcher.load()") : void 0; | ||
router$1.fetch(fetcherKey, routeId, href); | ||
@@ -977,3 +988,2 @@ }); | ||
function useBeforeUnload(callback, options) { | ||
@@ -1049,22 +1059,4 @@ let { | ||
} | ||
//////////////////////////////////////////////////////////////////////////////// | ||
//#region Utils | ||
//////////////////////////////////////////////////////////////////////////////// | ||
//#endregion | ||
function warning(cond, message) { | ||
if (!cond) { | ||
// eslint-disable-next-line no-console | ||
if (typeof console !== "undefined") console.warn(message); | ||
try { | ||
// Welcome to debugging React Router! | ||
// | ||
// This error is thrown as a convenience so you can more easily | ||
// find the source for a warning that appears in the console by | ||
// enabling "pause on exceptions" in your JavaScript debugger. | ||
throw new Error(message); // eslint-disable-next-line no-empty | ||
} catch (e) {} | ||
} | ||
} //#endregion | ||
Object.defineProperty(exports, 'AbortedDeferredError', { | ||
@@ -1130,6 +1122,2 @@ enumerable: true, | ||
}); | ||
Object.defineProperty(exports, 'UNSAFE_enhanceManualRouteObjects', { | ||
enumerable: true, | ||
get: function () { return reactRouter.UNSAFE_enhanceManualRouteObjects; } | ||
}); | ||
Object.defineProperty(exports, 'createMemoryRouter', { | ||
@@ -1139,6 +1127,2 @@ enumerable: true, | ||
}); | ||
Object.defineProperty(exports, 'createMiddlewareContext', { | ||
enumerable: true, | ||
get: function () { return reactRouter.createMiddlewareContext; } | ||
}); | ||
Object.defineProperty(exports, 'createPath', { | ||
@@ -1145,0 +1129,0 @@ enumerable: true, |
/** | ||
* React Router DOM v0.0.0-experimental-48058118 | ||
* React Router DOM v0.0.0-experimental-5f6f59a6 | ||
* | ||
@@ -11,3 +11,3 @@ * Copyright (c) Remix Software Inc. | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("react-router"),require("@remix-run/router")):"function"==typeof define&&define.amd?define(["exports","react","react-router","@remix-run/router"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactRouterDOM={},e.React,e.ReactRouter,e.RemixRouter)}(this,(function(e,t,r,n){"use strict";function o(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var a=o(t);function u(){return u=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},u.apply(this,arguments)}function i(e,t){if(null==e)return{};var r,n,o={},a=Object.keys(e);for(n=0;n<a.length;n++)r=a[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}const c="get",l="application/x-www-form-urlencoded";function s(e){return null!=e&&"string"==typeof e.tagName}function f(e){return void 0===e&&(e=""),new URLSearchParams("string"==typeof e||Array.isArray(e)||e instanceof URLSearchParams?e:Object.keys(e).reduce(((t,r)=>{let n=e[r];return t.concat(Array.isArray(n)?n.map((e=>[r,e])):[[r,n]])}),[]))}function d(e,t,r){let n,o,a,u;if(s(i=e)&&"form"===i.tagName.toLowerCase()){let i=r.submissionTrigger;n=r.method||e.getAttribute("method")||c,o=r.action||e.getAttribute("action")||t,a=r.encType||e.getAttribute("enctype")||l,u=new FormData(e),i&&i.name&&u.append(i.name,i.value)}else if(function(e){return s(e)&&"button"===e.tagName.toLowerCase()}(e)||function(e){return s(e)&&"input"===e.tagName.toLowerCase()}(e)&&("submit"===e.type||"image"===e.type)){let i=e.form;if(null==i)throw new Error('Cannot submit a <button> or <input type="submit"> without a <form>');n=r.method||e.getAttribute("formmethod")||i.getAttribute("method")||c,o=r.action||e.getAttribute("formaction")||i.getAttribute("action")||t,a=r.encType||e.getAttribute("formenctype")||i.getAttribute("enctype")||l,u=new FormData(i),e.name&&u.append(e.name,e.value)}else{if(s(e))throw new Error('Cannot submit element that is not <form>, <button>, or <input type="submit|image">');if(n=r.method||c,o=r.action||t,a=r.encType||l,e instanceof FormData)u=e;else if(u=new FormData,e instanceof URLSearchParams)for(let[t,r]of e)u.append(t,r);else if(null!=e)for(let t of Object.keys(e))u.append(t,e[t])}var i;let{protocol:f,host:d}=window.location;return{url:new URL(o,f+"//"+d),method:n.toLowerCase(),encType:a,formData:u}}const m=["onClick","relative","reloadDocument","replace","state","target","to","preventScrollReset"],b=["aria-current","caseSensitive","className","end","style","to","children"],p=["reloadDocument","replace","method","action","onSubmit","fetcherKey","routeId","relative","preventScrollReset"];function h(){var e;let t=null==(e=window)?void 0:e.__staticRouterHydrationData;return t&&t.errors&&(t=u({},t,{errors:y(t.errors)})),t}function y(e){if(!e)return null;let t=Object.entries(e),r={};for(let[e,o]of t)if(o&&"RouteErrorResponse"===o.__type)r[e]=new n.ErrorResponse(o.status,o.statusText,o.data,!0===o.internal);else if(o&&"Error"===o.__type){let t=new Error(o.message);t.stack="",r[e]=t}else r[e]=o;return r}const g="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,v=a.forwardRef((function(e,t){let n,{onClick:o,relative:c,reloadDocument:l,replace:s,state:f,target:d,to:b,preventScrollReset:p}=e,h=i(e,m),y=!1;if(g&&"string"==typeof b&&/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i.test(b)){n=b;let e=new URL(window.location.href),t=b.startsWith("//")?new URL(e.protocol+b):new URL(b);t.origin===e.origin?b=t.pathname+t.search+t.hash:y=!0}let v=r.useHref(b,{relative:c}),R=A(b,{replace:s,state:f,target:d,preventScrollReset:p,relative:c});return a.createElement("a",u({},h,{href:n||v,onClick:y||l?o:function(e){o&&o(e),e.defaultPrevented||R(e)},ref:t,target:d}))})),R=a.forwardRef((function(e,t){let{"aria-current":n="page",caseSensitive:o=!1,className:c="",end:l=!1,style:s,to:f,children:d}=e,m=i(e,b),p=r.useResolvedPath(f,{relative:m.relative}),h=r.useLocation(),y=a.useContext(r.UNSAFE_DataRouterStateContext),{navigator:g}=a.useContext(r.UNSAFE_NavigationContext),R=g.encodeLocation?g.encodeLocation(p).pathname:p.pathname,w=h.pathname,P=y&&y.navigation&&y.navigation.location?y.navigation.location.pathname:null;o||(w=w.toLowerCase(),P=P?P.toLowerCase():null,R=R.toLowerCase());let O,S=w===R||!l&&w.startsWith(R)&&"/"===w.charAt(R.length),j=null!=P&&(P===R||!l&&P.startsWith(R)&&"/"===P.charAt(R.length)),E=S?n:void 0;O="function"==typeof c?c({isActive:S,isPending:j}):[c,S?"active":null,j?"pending":null].filter(Boolean).join(" ");let A="function"==typeof s?s({isActive:S,isPending:j}):s;return a.createElement(v,u({},m,{"aria-current":E,className:O,ref:t,style:A,to:f}),"function"==typeof d?d({isActive:S,isPending:j}):d)})),w=a.forwardRef(((e,t)=>a.createElement(P,u({},e,{ref:t})))),P=a.forwardRef(((e,t)=>{let{reloadDocument:r,replace:n,method:o=c,action:l,onSubmit:s,fetcherKey:f,routeId:d,relative:m,preventScrollReset:b}=e,h=i(e,p),y=C(f,d),g="get"===o.toLowerCase()?"get":"post",v=N(l,{relative:m});return a.createElement("form",u({ref:t,method:g,action:v,onSubmit:r?s:e=>{if(s&&s(e),e.defaultPrevented)return;e.preventDefault();let t=e.nativeEvent.submitter,r=(null==t?void 0:t.getAttribute("formmethod"))||o;y(t||e.currentTarget,{method:r,replace:n,relative:m,preventScrollReset:b})}},h))}));var O,S;function j(e){let t=a.useContext(r.UNSAFE_DataRouterContext);return t||n.invariant(!1),t}function E(e){let t=a.useContext(r.UNSAFE_DataRouterStateContext);return t||n.invariant(!1),t}function A(e,t){let{target:n,replace:o,state:u,preventScrollReset:i,relative:c}=void 0===t?{}:t,l=r.useNavigate(),s=r.useLocation(),f=r.useResolvedPath(e,{relative:c});return a.useCallback((t=>{if(function(e,t){return!(0!==e.button||t&&"_self"!==t||function(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}(e))}(t,n)){t.preventDefault();let n=void 0!==o?o:r.createPath(s)===r.createPath(f);l(e,{replace:n,state:u,preventScrollReset:i,relative:c})}}),[s,l,f,o,u,n,e,i,c])}function C(e,t){let{router:r}=j(O.UseSubmitImpl),o=N();return a.useCallback((function(a,u){if(void 0===u&&(u={}),"undefined"==typeof document)throw new Error("You are calling submit during the server render. Try calling submit within a `useEffect` or callback instead.");let{method:i,encType:c,formData:l,url:s}=d(a,o,u),f=s.pathname+s.search,m={replace:u.replace,preventScrollReset:u.preventScrollReset,formData:l,formMethod:i,formEncType:c};e?(null==t&&n.invariant(!1),r.fetch(e,t,f,m)):r.navigate(f,m)}),[o,r,e,t])}function N(e,t){let{relative:o}=void 0===t?{}:t,{basename:i}=a.useContext(r.UNSAFE_NavigationContext),c=a.useContext(r.UNSAFE_RouteContext);c||n.invariant(!1);let[l]=c.matches.slice(-1),s=u({},r.useResolvedPath(e||".",{relative:o})),f=r.useLocation();if(null==e&&(s.search=f.search,s.hash=f.hash,l.route.index)){let e=new URLSearchParams(s.search);e.delete("index"),s.search=e.toString()?"?"+e.toString():""}return e&&"."!==e||!l.route.index||(s.search=s.search?s.search.replace(/^\?/,"?index&"):"?index"),"/"!==i&&(s.pathname="/"===s.pathname?i:n.joinPaths([i,s.pathname])),r.createPath(s)}!function(e){e.UseScrollRestoration="useScrollRestoration",e.UseSubmitImpl="useSubmitImpl",e.UseFetcher="useFetcher"}(O||(O={})),function(e){e.UseFetchers="useFetchers",e.UseScrollRestoration="useScrollRestoration"}(S||(S={}));let x=0;const F="react-router-scroll-positions";let L={};function U(e){let{getKey:t,storageKey:n}=void 0===e?{}:e,{router:o}=j(O.UseScrollRestoration),{restoreScrollPosition:u,preventScrollReset:i}=E(S.UseScrollRestoration),c=r.useLocation(),l=r.useMatches(),s=r.useNavigation();a.useEffect((()=>(window.history.scrollRestoration="manual",()=>{window.history.scrollRestoration="auto"})),[]),function(e,t){let{capture:r}=t||{};a.useEffect((()=>{let t=null!=r?{capture:r}:void 0;return window.addEventListener("pagehide",e,t),()=>{window.removeEventListener("pagehide",e,t)}}),[e,r])}(a.useCallback((()=>{if("idle"===s.state){let e=(t?t(c,l):null)||c.key;L[e]=window.scrollY}sessionStorage.setItem(n||F,JSON.stringify(L)),window.history.scrollRestoration="auto"}),[n,t,s.state,c,l])),"undefined"!=typeof document&&(a.useLayoutEffect((()=>{try{let e=sessionStorage.getItem(n||F);e&&(L=JSON.parse(e))}catch(e){}}),[n]),a.useLayoutEffect((()=>{let e=null==o?void 0:o.enableScrollRestoration(L,(()=>window.scrollY),t);return()=>e&&e()}),[o,t]),a.useLayoutEffect((()=>{if(!1!==u)if("number"!=typeof u){if(c.hash){let e=document.getElementById(c.hash.slice(1));if(e)return void e.scrollIntoView()}!0!==i&&window.scrollTo(0,0)}else window.scrollTo(0,u)}),[c,u,i]))}Object.defineProperty(e,"AbortedDeferredError",{enumerable:!0,get:function(){return r.AbortedDeferredError}}),Object.defineProperty(e,"Await",{enumerable:!0,get:function(){return r.Await}}),Object.defineProperty(e,"MemoryRouter",{enumerable:!0,get:function(){return r.MemoryRouter}}),Object.defineProperty(e,"Navigate",{enumerable:!0,get:function(){return r.Navigate}}),Object.defineProperty(e,"NavigationType",{enumerable:!0,get:function(){return r.NavigationType}}),Object.defineProperty(e,"Outlet",{enumerable:!0,get:function(){return r.Outlet}}),Object.defineProperty(e,"Route",{enumerable:!0,get:function(){return r.Route}}),Object.defineProperty(e,"Router",{enumerable:!0,get:function(){return r.Router}}),Object.defineProperty(e,"RouterProvider",{enumerable:!0,get:function(){return r.RouterProvider}}),Object.defineProperty(e,"Routes",{enumerable:!0,get:function(){return r.Routes}}),Object.defineProperty(e,"UNSAFE_DataRouterContext",{enumerable:!0,get:function(){return r.UNSAFE_DataRouterContext}}),Object.defineProperty(e,"UNSAFE_DataRouterStateContext",{enumerable:!0,get:function(){return r.UNSAFE_DataRouterStateContext}}),Object.defineProperty(e,"UNSAFE_LocationContext",{enumerable:!0,get:function(){return r.UNSAFE_LocationContext}}),Object.defineProperty(e,"UNSAFE_NavigationContext",{enumerable:!0,get:function(){return r.UNSAFE_NavigationContext}}),Object.defineProperty(e,"UNSAFE_RouteContext",{enumerable:!0,get:function(){return r.UNSAFE_RouteContext}}),Object.defineProperty(e,"UNSAFE_enhanceManualRouteObjects",{enumerable:!0,get:function(){return r.UNSAFE_enhanceManualRouteObjects}}),Object.defineProperty(e,"createMemoryRouter",{enumerable:!0,get:function(){return r.createMemoryRouter}}),Object.defineProperty(e,"createMiddlewareContext",{enumerable:!0,get:function(){return r.createMiddlewareContext}}),Object.defineProperty(e,"createPath",{enumerable:!0,get:function(){return r.createPath}}),Object.defineProperty(e,"createRoutesFromChildren",{enumerable:!0,get:function(){return r.createRoutesFromChildren}}),Object.defineProperty(e,"createRoutesFromElements",{enumerable:!0,get:function(){return r.createRoutesFromElements}}),Object.defineProperty(e,"defer",{enumerable:!0,get:function(){return r.defer}}),Object.defineProperty(e,"generatePath",{enumerable:!0,get:function(){return r.generatePath}}),Object.defineProperty(e,"isRouteErrorResponse",{enumerable:!0,get:function(){return r.isRouteErrorResponse}}),Object.defineProperty(e,"json",{enumerable:!0,get:function(){return r.json}}),Object.defineProperty(e,"matchPath",{enumerable:!0,get:function(){return r.matchPath}}),Object.defineProperty(e,"matchRoutes",{enumerable:!0,get:function(){return r.matchRoutes}}),Object.defineProperty(e,"parsePath",{enumerable:!0,get:function(){return r.parsePath}}),Object.defineProperty(e,"redirect",{enumerable:!0,get:function(){return r.redirect}}),Object.defineProperty(e,"renderMatches",{enumerable:!0,get:function(){return r.renderMatches}}),Object.defineProperty(e,"resolvePath",{enumerable:!0,get:function(){return r.resolvePath}}),Object.defineProperty(e,"unstable_useBlocker",{enumerable:!0,get:function(){return r.unstable_useBlocker}}),Object.defineProperty(e,"useActionData",{enumerable:!0,get:function(){return r.useActionData}}),Object.defineProperty(e,"useAsyncError",{enumerable:!0,get:function(){return r.useAsyncError}}),Object.defineProperty(e,"useAsyncValue",{enumerable:!0,get:function(){return r.useAsyncValue}}),Object.defineProperty(e,"useHref",{enumerable:!0,get:function(){return r.useHref}}),Object.defineProperty(e,"useInRouterContext",{enumerable:!0,get:function(){return r.useInRouterContext}}),Object.defineProperty(e,"useLoaderData",{enumerable:!0,get:function(){return r.useLoaderData}}),Object.defineProperty(e,"useLocation",{enumerable:!0,get:function(){return r.useLocation}}),Object.defineProperty(e,"useMatch",{enumerable:!0,get:function(){return r.useMatch}}),Object.defineProperty(e,"useMatches",{enumerable:!0,get:function(){return r.useMatches}}),Object.defineProperty(e,"useNavigate",{enumerable:!0,get:function(){return r.useNavigate}}),Object.defineProperty(e,"useNavigation",{enumerable:!0,get:function(){return r.useNavigation}}),Object.defineProperty(e,"useNavigationType",{enumerable:!0,get:function(){return r.useNavigationType}}),Object.defineProperty(e,"useOutlet",{enumerable:!0,get:function(){return r.useOutlet}}),Object.defineProperty(e,"useOutletContext",{enumerable:!0,get:function(){return r.useOutletContext}}),Object.defineProperty(e,"useParams",{enumerable:!0,get:function(){return r.useParams}}),Object.defineProperty(e,"useResolvedPath",{enumerable:!0,get:function(){return r.useResolvedPath}}),Object.defineProperty(e,"useRevalidator",{enumerable:!0,get:function(){return r.useRevalidator}}),Object.defineProperty(e,"useRouteError",{enumerable:!0,get:function(){return r.useRouteError}}),Object.defineProperty(e,"useRouteLoaderData",{enumerable:!0,get:function(){return r.useRouteLoaderData}}),Object.defineProperty(e,"useRoutes",{enumerable:!0,get:function(){return r.useRoutes}}),e.BrowserRouter=function(e){let{basename:t,children:o,window:u}=e,i=a.useRef();null==i.current&&(i.current=n.createBrowserHistory({window:u,v5Compat:!0}));let c=i.current,[l,s]=a.useState({action:c.action,location:c.location});return a.useLayoutEffect((()=>c.listen(s)),[c]),a.createElement(r.Router,{basename:t,children:o,location:l.location,navigationType:l.action,navigator:c})},e.Form=w,e.HashRouter=function(e){let{basename:t,children:o,window:u}=e,i=a.useRef();null==i.current&&(i.current=n.createHashHistory({window:u,v5Compat:!0}));let c=i.current,[l,s]=a.useState({action:c.action,location:c.location});return a.useLayoutEffect((()=>c.listen(s)),[c]),a.createElement(r.Router,{basename:t,children:o,location:l.location,navigationType:l.action,navigator:c})},e.Link=v,e.NavLink=R,e.ScrollRestoration=function(e){let{getKey:t,storageKey:r}=e;return U({getKey:t,storageKey:r}),null},e.UNSAFE_useScrollRestoration=U,e.createBrowserRouter=function(e,t){return n.createRouter({basename:null==t?void 0:t.basename,history:n.createBrowserHistory({window:null==t?void 0:t.window}),hydrationData:(null==t?void 0:t.hydrationData)||h(),routes:r.UNSAFE_enhanceManualRouteObjects(e)}).initialize()},e.createHashRouter=function(e,t){return n.createRouter({basename:null==t?void 0:t.basename,history:n.createHashHistory({window:null==t?void 0:t.window}),hydrationData:(null==t?void 0:t.hydrationData)||h(),routes:r.UNSAFE_enhanceManualRouteObjects(e)}).initialize()},e.createSearchParams=f,e.unstable_HistoryRouter=function(e){let{basename:t,children:n,history:o}=e;const[u,i]=a.useState({action:o.action,location:o.location});return a.useLayoutEffect((()=>o.listen(i)),[o]),a.createElement(r.Router,{basename:t,children:n,location:u.location,navigationType:u.action,navigator:o})},e.unstable_usePrompt=function(e){let{when:t,message:n}=e,o=r.unstable_useBlocker(t);a.useEffect((()=>{"blocked"!==o.state||t||o.reset()}),[o,t]),a.useEffect((()=>{if("blocked"===o.state){window.confirm(n)?setTimeout(o.proceed,0):o.reset()}}),[o,n])},e.useBeforeUnload=function(e,t){let{capture:r}=t||{};a.useEffect((()=>{let t=null!=r?{capture:r}:void 0;return window.addEventListener("beforeunload",e,t),()=>{window.removeEventListener("beforeunload",e,t)}}),[e,r])},e.useFetcher=function(){var e;let{router:t}=j(O.UseFetcher),o=a.useContext(r.UNSAFE_RouteContext);o||n.invariant(!1);let i=null==(e=o.matches[o.matches.length-1])?void 0:e.route.id;null==i&&n.invariant(!1);let[c]=a.useState((()=>String(++x))),[l]=a.useState((()=>(i||n.invariant(!1),function(e,t){return a.forwardRef(((r,n)=>a.createElement(P,u({},r,{ref:n,fetcherKey:e,routeId:t}))))}(c,i)))),[s]=a.useState((()=>e=>{t||n.invariant(!1),i||n.invariant(!1),t.fetch(c,i,e)})),f=C(c,i),d=t.getFetcher(c),m=a.useMemo((()=>u({Form:l,submit:f,load:s},d)),[d,l,f,s]);return a.useEffect((()=>()=>{t?t.deleteFetcher(c):console.warn("No fetcher available to clean up from useFetcher()")}),[t,c]),m},e.useFetchers=function(){return[...E(S.UseFetchers).fetchers.values()]},e.useFormAction=N,e.useLinkClickHandler=A,e.useSearchParams=function(e){let t=a.useRef(f(e)),n=a.useRef(!1),o=r.useLocation(),u=a.useMemo((()=>function(e,t){let r=f(e);if(t)for(let e of t.keys())r.has(e)||t.getAll(e).forEach((t=>{r.append(e,t)}));return r}(o.search,n.current?null:t.current)),[o.search]),i=r.useNavigate(),c=a.useCallback(((e,t)=>{const r=f("function"==typeof e?e(u):e);n.current=!0,i("?"+r,t)}),[i,u]);return[u,c]},e.useSubmit=function(){return C()},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("react-router"),require("@remix-run/router")):"function"==typeof define&&define.amd?define(["exports","react","react-router","@remix-run/router"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactRouterDOM={},e.React,e.ReactRouter,e.RemixRouter)}(this,(function(e,t,r,n){"use strict";function o(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var a=o(t);function u(){return u=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},u.apply(this,arguments)}function i(e,t){if(null==e)return{};var r,n,o={},a=Object.keys(e);for(n=0;n<a.length;n++)r=a[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}const c="get",l="application/x-www-form-urlencoded";function s(e){return null!=e&&"string"==typeof e.tagName}function f(e){return void 0===e&&(e=""),new URLSearchParams("string"==typeof e||Array.isArray(e)||e instanceof URLSearchParams?e:Object.keys(e).reduce(((t,r)=>{let n=e[r];return t.concat(Array.isArray(n)?n.map((e=>[r,e])):[[r,n]])}),[]))}function d(e,t,r){let n,o,a,u;if(s(i=e)&&"form"===i.tagName.toLowerCase()){let i=r.submissionTrigger;n=r.method||e.getAttribute("method")||c,o=r.action||e.getAttribute("action")||t,a=r.encType||e.getAttribute("enctype")||l,u=new FormData(e),i&&i.name&&u.append(i.name,i.value)}else if(function(e){return s(e)&&"button"===e.tagName.toLowerCase()}(e)||function(e){return s(e)&&"input"===e.tagName.toLowerCase()}(e)&&("submit"===e.type||"image"===e.type)){let i=e.form;if(null==i)throw new Error('Cannot submit a <button> or <input type="submit"> without a <form>');n=r.method||e.getAttribute("formmethod")||i.getAttribute("method")||c,o=r.action||e.getAttribute("formaction")||i.getAttribute("action")||t,a=r.encType||e.getAttribute("formenctype")||i.getAttribute("enctype")||l,u=new FormData(i),e.name&&u.append(e.name,e.value)}else{if(s(e))throw new Error('Cannot submit element that is not <form>, <button>, or <input type="submit|image">');if(n=r.method||c,o=r.action||t,a=r.encType||l,e instanceof FormData)u=e;else if(u=new FormData,e instanceof URLSearchParams)for(let[t,r]of e)u.append(t,r);else if(null!=e)for(let t of Object.keys(e))u.append(t,e[t])}var i;let{protocol:f,host:d}=window.location;return{url:new URL(o,f+"//"+d),method:n.toLowerCase(),encType:a,formData:u}}const m=["onClick","relative","reloadDocument","replace","state","target","to","preventScrollReset"],b=["aria-current","caseSensitive","className","end","style","to","children"],p=["reloadDocument","replace","method","action","onSubmit","fetcherKey","routeId","relative","preventScrollReset"];function h(){var e;let t=null==(e=window)?void 0:e.__staticRouterHydrationData;return t&&t.errors&&(t=u({},t,{errors:y(t.errors)})),t}function y(e){if(!e)return null;let t=Object.entries(e),r={};for(let[e,o]of t)if(o&&"RouteErrorResponse"===o.__type)r[e]=new n.ErrorResponse(o.status,o.statusText,o.data,!0===o.internal);else if(o&&"Error"===o.__type){let t=new Error(o.message);t.stack="",r[e]=t}else r[e]=o;return r}const g="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,v=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,R=a.forwardRef((function(e,t){let o,{onClick:c,relative:l,reloadDocument:s,replace:f,state:d,target:b,to:p,preventScrollReset:h}=e,y=i(e,m),{basename:R}=a.useContext(r.UNSAFE_NavigationContext),w=!1;if("string"==typeof p&&v.test(p)&&(o=p,g)){let e=new URL(window.location.href),t=p.startsWith("//")?new URL(e.protocol+p):new URL(p),r=n.stripBasename(t.pathname,R);t.origin===e.origin&&null!=r?p=r+t.search+t.hash:w=!0}let P=r.useHref(p,{relative:l}),S=N(p,{replace:f,state:d,target:b,preventScrollReset:h,relative:l});return a.createElement("a",u({},y,{href:o||P,onClick:w||s?c:function(e){c&&c(e),e.defaultPrevented||S(e)},ref:t,target:b}))})),w=a.forwardRef((function(e,t){let{"aria-current":n="page",caseSensitive:o=!1,className:c="",end:l=!1,style:s,to:f,children:d}=e,m=i(e,b),p=r.useResolvedPath(f,{relative:m.relative}),h=r.useLocation(),y=a.useContext(r.UNSAFE_DataRouterStateContext),{navigator:g}=a.useContext(r.UNSAFE_NavigationContext),v=g.encodeLocation?g.encodeLocation(p).pathname:p.pathname,w=h.pathname,P=y&&y.navigation&&y.navigation.location?y.navigation.location.pathname:null;o||(w=w.toLowerCase(),P=P?P.toLowerCase():null,v=v.toLowerCase());let S,E=w===v||!l&&w.startsWith(v)&&"/"===w.charAt(v.length),O=null!=P&&(P===v||!l&&P.startsWith(v)&&"/"===P.charAt(v.length)),j=E?n:void 0;S="function"==typeof c?c({isActive:E,isPending:O}):[c,E?"active":null,O?"pending":null].filter(Boolean).join(" ");let A="function"==typeof s?s({isActive:E,isPending:O}):s;return a.createElement(R,u({},m,{"aria-current":j,className:S,ref:t,style:A,to:f}),"function"==typeof d?d({isActive:E,isPending:O}):d)})),P=a.forwardRef(((e,t)=>a.createElement(S,u({},e,{ref:t})))),S=a.forwardRef(((e,t)=>{let{reloadDocument:r,replace:n,method:o=c,action:l,onSubmit:s,fetcherKey:f,routeId:d,relative:m,preventScrollReset:b}=e,h=i(e,p),y=C(f,d),g="get"===o.toLowerCase()?"get":"post",v=F(l,{relative:m});return a.createElement("form",u({ref:t,method:g,action:v,onSubmit:r?s:e=>{if(s&&s(e),e.defaultPrevented)return;e.preventDefault();let t=e.nativeEvent.submitter,r=(null==t?void 0:t.getAttribute("formmethod"))||o;y(t||e.currentTarget,{method:r,replace:n,relative:m,preventScrollReset:b})}},h))}));var E,O;function j(e){let t=a.useContext(r.UNSAFE_DataRouterContext);return t||n.UNSAFE_invariant(!1),t}function A(e){let t=a.useContext(r.UNSAFE_DataRouterStateContext);return t||n.UNSAFE_invariant(!1),t}function N(e,t){let{target:n,replace:o,state:u,preventScrollReset:i,relative:c}=void 0===t?{}:t,l=r.useNavigate(),s=r.useLocation(),f=r.useResolvedPath(e,{relative:c});return a.useCallback((t=>{if(function(e,t){return!(0!==e.button||t&&"_self"!==t||function(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}(e))}(t,n)){t.preventDefault();let n=void 0!==o?o:r.createPath(s)===r.createPath(f);l(e,{replace:n,state:u,preventScrollReset:i,relative:c})}}),[s,l,f,o,u,n,e,i,c])}function C(e,t){let{router:r}=j(E.UseSubmitImpl),o=F();return a.useCallback((function(a,u){if(void 0===u&&(u={}),"undefined"==typeof document)throw new Error("You are calling submit during the server render. Try calling submit within a `useEffect` or callback instead.");let{method:i,encType:c,formData:l,url:s}=d(a,o,u),f=s.pathname+s.search,m={replace:u.replace,preventScrollReset:u.preventScrollReset,formData:l,formMethod:i,formEncType:c};e?(null==t&&n.UNSAFE_invariant(!1),r.fetch(e,t,f,m)):r.navigate(f,m)}),[o,r,e,t])}function F(e,t){let{relative:o}=void 0===t?{}:t,{basename:i}=a.useContext(r.UNSAFE_NavigationContext),c=a.useContext(r.UNSAFE_RouteContext);c||n.UNSAFE_invariant(!1);let[l]=c.matches.slice(-1),s=u({},r.useResolvedPath(e||".",{relative:o})),f=r.useLocation();if(null==e&&(s.search=f.search,s.hash=f.hash,l.route.index)){let e=new URLSearchParams(s.search);e.delete("index"),s.search=e.toString()?"?"+e.toString():""}return e&&"."!==e||!l.route.index||(s.search=s.search?s.search.replace(/^\?/,"?index&"):"?index"),"/"!==i&&(s.pathname="/"===s.pathname?i:n.joinPaths([i,s.pathname])),r.createPath(s)}!function(e){e.UseScrollRestoration="useScrollRestoration",e.UseSubmitImpl="useSubmitImpl",e.UseFetcher="useFetcher"}(E||(E={})),function(e){e.UseFetchers="useFetchers",e.UseScrollRestoration="useScrollRestoration"}(O||(O={}));let U=0;const _="react-router-scroll-positions";let x={};function L(e){let{getKey:t,storageKey:n}=void 0===e?{}:e,{router:o}=j(E.UseScrollRestoration),{restoreScrollPosition:u,preventScrollReset:i}=A(O.UseScrollRestoration),c=r.useLocation(),l=r.useMatches(),s=r.useNavigation();a.useEffect((()=>(window.history.scrollRestoration="manual",()=>{window.history.scrollRestoration="auto"})),[]),function(e,t){let{capture:r}=t||{};a.useEffect((()=>{let t=null!=r?{capture:r}:void 0;return window.addEventListener("pagehide",e,t),()=>{window.removeEventListener("pagehide",e,t)}}),[e,r])}(a.useCallback((()=>{if("idle"===s.state){let e=(t?t(c,l):null)||c.key;x[e]=window.scrollY}sessionStorage.setItem(n||_,JSON.stringify(x)),window.history.scrollRestoration="auto"}),[n,t,s.state,c,l])),"undefined"!=typeof document&&(a.useLayoutEffect((()=>{try{let e=sessionStorage.getItem(n||_);e&&(x=JSON.parse(e))}catch(e){}}),[n]),a.useLayoutEffect((()=>{let e=null==o?void 0:o.enableScrollRestoration(x,(()=>window.scrollY),t);return()=>e&&e()}),[o,t]),a.useLayoutEffect((()=>{if(!1!==u)if("number"!=typeof u){if(c.hash){let e=document.getElementById(c.hash.slice(1));if(e)return void e.scrollIntoView()}!0!==i&&window.scrollTo(0,0)}else window.scrollTo(0,u)}),[c,u,i]))}Object.defineProperty(e,"AbortedDeferredError",{enumerable:!0,get:function(){return r.AbortedDeferredError}}),Object.defineProperty(e,"Await",{enumerable:!0,get:function(){return r.Await}}),Object.defineProperty(e,"MemoryRouter",{enumerable:!0,get:function(){return r.MemoryRouter}}),Object.defineProperty(e,"Navigate",{enumerable:!0,get:function(){return r.Navigate}}),Object.defineProperty(e,"NavigationType",{enumerable:!0,get:function(){return r.NavigationType}}),Object.defineProperty(e,"Outlet",{enumerable:!0,get:function(){return r.Outlet}}),Object.defineProperty(e,"Route",{enumerable:!0,get:function(){return r.Route}}),Object.defineProperty(e,"Router",{enumerable:!0,get:function(){return r.Router}}),Object.defineProperty(e,"RouterProvider",{enumerable:!0,get:function(){return r.RouterProvider}}),Object.defineProperty(e,"Routes",{enumerable:!0,get:function(){return r.Routes}}),Object.defineProperty(e,"UNSAFE_DataRouterContext",{enumerable:!0,get:function(){return r.UNSAFE_DataRouterContext}}),Object.defineProperty(e,"UNSAFE_DataRouterStateContext",{enumerable:!0,get:function(){return r.UNSAFE_DataRouterStateContext}}),Object.defineProperty(e,"UNSAFE_LocationContext",{enumerable:!0,get:function(){return r.UNSAFE_LocationContext}}),Object.defineProperty(e,"UNSAFE_NavigationContext",{enumerable:!0,get:function(){return r.UNSAFE_NavigationContext}}),Object.defineProperty(e,"UNSAFE_RouteContext",{enumerable:!0,get:function(){return r.UNSAFE_RouteContext}}),Object.defineProperty(e,"createMemoryRouter",{enumerable:!0,get:function(){return r.createMemoryRouter}}),Object.defineProperty(e,"createPath",{enumerable:!0,get:function(){return r.createPath}}),Object.defineProperty(e,"createRoutesFromChildren",{enumerable:!0,get:function(){return r.createRoutesFromChildren}}),Object.defineProperty(e,"createRoutesFromElements",{enumerable:!0,get:function(){return r.createRoutesFromElements}}),Object.defineProperty(e,"defer",{enumerable:!0,get:function(){return r.defer}}),Object.defineProperty(e,"generatePath",{enumerable:!0,get:function(){return r.generatePath}}),Object.defineProperty(e,"isRouteErrorResponse",{enumerable:!0,get:function(){return r.isRouteErrorResponse}}),Object.defineProperty(e,"json",{enumerable:!0,get:function(){return r.json}}),Object.defineProperty(e,"matchPath",{enumerable:!0,get:function(){return r.matchPath}}),Object.defineProperty(e,"matchRoutes",{enumerable:!0,get:function(){return r.matchRoutes}}),Object.defineProperty(e,"parsePath",{enumerable:!0,get:function(){return r.parsePath}}),Object.defineProperty(e,"redirect",{enumerable:!0,get:function(){return r.redirect}}),Object.defineProperty(e,"renderMatches",{enumerable:!0,get:function(){return r.renderMatches}}),Object.defineProperty(e,"resolvePath",{enumerable:!0,get:function(){return r.resolvePath}}),Object.defineProperty(e,"unstable_useBlocker",{enumerable:!0,get:function(){return r.unstable_useBlocker}}),Object.defineProperty(e,"useActionData",{enumerable:!0,get:function(){return r.useActionData}}),Object.defineProperty(e,"useAsyncError",{enumerable:!0,get:function(){return r.useAsyncError}}),Object.defineProperty(e,"useAsyncValue",{enumerable:!0,get:function(){return r.useAsyncValue}}),Object.defineProperty(e,"useHref",{enumerable:!0,get:function(){return r.useHref}}),Object.defineProperty(e,"useInRouterContext",{enumerable:!0,get:function(){return r.useInRouterContext}}),Object.defineProperty(e,"useLoaderData",{enumerable:!0,get:function(){return r.useLoaderData}}),Object.defineProperty(e,"useLocation",{enumerable:!0,get:function(){return r.useLocation}}),Object.defineProperty(e,"useMatch",{enumerable:!0,get:function(){return r.useMatch}}),Object.defineProperty(e,"useMatches",{enumerable:!0,get:function(){return r.useMatches}}),Object.defineProperty(e,"useNavigate",{enumerable:!0,get:function(){return r.useNavigate}}),Object.defineProperty(e,"useNavigation",{enumerable:!0,get:function(){return r.useNavigation}}),Object.defineProperty(e,"useNavigationType",{enumerable:!0,get:function(){return r.useNavigationType}}),Object.defineProperty(e,"useOutlet",{enumerable:!0,get:function(){return r.useOutlet}}),Object.defineProperty(e,"useOutletContext",{enumerable:!0,get:function(){return r.useOutletContext}}),Object.defineProperty(e,"useParams",{enumerable:!0,get:function(){return r.useParams}}),Object.defineProperty(e,"useResolvedPath",{enumerable:!0,get:function(){return r.useResolvedPath}}),Object.defineProperty(e,"useRevalidator",{enumerable:!0,get:function(){return r.useRevalidator}}),Object.defineProperty(e,"useRouteError",{enumerable:!0,get:function(){return r.useRouteError}}),Object.defineProperty(e,"useRouteLoaderData",{enumerable:!0,get:function(){return r.useRouteLoaderData}}),Object.defineProperty(e,"useRoutes",{enumerable:!0,get:function(){return r.useRoutes}}),e.BrowserRouter=function(e){let{basename:t,children:o,window:u}=e,i=a.useRef();null==i.current&&(i.current=n.createBrowserHistory({window:u,v5Compat:!0}));let c=i.current,[l,s]=a.useState({action:c.action,location:c.location});return a.useLayoutEffect((()=>c.listen(s)),[c]),a.createElement(r.Router,{basename:t,children:o,location:l.location,navigationType:l.action,navigator:c})},e.Form=P,e.HashRouter=function(e){let{basename:t,children:o,window:u}=e,i=a.useRef();null==i.current&&(i.current=n.createHashHistory({window:u,v5Compat:!0}));let c=i.current,[l,s]=a.useState({action:c.action,location:c.location});return a.useLayoutEffect((()=>c.listen(s)),[c]),a.createElement(r.Router,{basename:t,children:o,location:l.location,navigationType:l.action,navigator:c})},e.Link=R,e.NavLink=w,e.ScrollRestoration=function(e){let{getKey:t,storageKey:r}=e;return L({getKey:t,storageKey:r}),null},e.UNSAFE_useScrollRestoration=L,e.createBrowserRouter=function(e,t){return n.createRouter({basename:null==t?void 0:t.basename,history:n.createBrowserHistory({window:null==t?void 0:t.window}),hydrationData:(null==t?void 0:t.hydrationData)||h(),routes:e,detectErrorBoundary:r.UNSAFE_detectErrorBoundary}).initialize()},e.createHashRouter=function(e,t){return n.createRouter({basename:null==t?void 0:t.basename,history:n.createHashHistory({window:null==t?void 0:t.window}),hydrationData:(null==t?void 0:t.hydrationData)||h(),routes:e,detectErrorBoundary:r.UNSAFE_detectErrorBoundary}).initialize()},e.createSearchParams=f,e.unstable_HistoryRouter=function(e){let{basename:t,children:n,history:o}=e;const[u,i]=a.useState({action:o.action,location:o.location});return a.useLayoutEffect((()=>o.listen(i)),[o]),a.createElement(r.Router,{basename:t,children:n,location:u.location,navigationType:u.action,navigator:o})},e.unstable_usePrompt=function(e){let{when:t,message:n}=e,o=r.unstable_useBlocker(t);a.useEffect((()=>{"blocked"!==o.state||t||o.reset()}),[o,t]),a.useEffect((()=>{if("blocked"===o.state){window.confirm(n)?setTimeout(o.proceed,0):o.reset()}}),[o,n])},e.useBeforeUnload=function(e,t){let{capture:r}=t||{};a.useEffect((()=>{let t=null!=r?{capture:r}:void 0;return window.addEventListener("beforeunload",e,t),()=>{window.removeEventListener("beforeunload",e,t)}}),[e,r])},e.useFetcher=function(){var e;let{router:t}=j(E.UseFetcher),o=a.useContext(r.UNSAFE_RouteContext);o||n.UNSAFE_invariant(!1);let i=null==(e=o.matches[o.matches.length-1])?void 0:e.route.id;null==i&&n.UNSAFE_invariant(!1);let[c]=a.useState((()=>String(++U))),[l]=a.useState((()=>(i||n.UNSAFE_invariant(!1),function(e,t){return a.forwardRef(((r,n)=>a.createElement(S,u({},r,{ref:n,fetcherKey:e,routeId:t}))))}(c,i)))),[s]=a.useState((()=>e=>{t||n.UNSAFE_invariant(!1),i||n.UNSAFE_invariant(!1),t.fetch(c,i,e)})),f=C(c,i),d=t.getFetcher(c),m=a.useMemo((()=>u({Form:l,submit:f,load:s},d)),[d,l,f,s]);return a.useEffect((()=>()=>{t?t.deleteFetcher(c):console.warn("No fetcher available to clean up from useFetcher()")}),[t,c]),m},e.useFetchers=function(){return[...A(O.UseFetchers).fetchers.values()]},e.useFormAction=F,e.useLinkClickHandler=N,e.useSearchParams=function(e){let t=a.useRef(f(e)),n=a.useRef(!1),o=r.useLocation(),u=a.useMemo((()=>function(e,t){let r=f(e);if(t)for(let e of t.keys())r.has(e)||t.getAll(e).forEach((t=>{r.append(e,t)}));return r}(o.search,n.current?null:t.current)),[o.search]),i=r.useNavigate(),c=a.useCallback(((e,t)=>{const r=f("function"==typeof e?e(u):e);n.current=!0,i("?"+r,t)}),[i,u]);return[u,c]},e.useSubmit=function(){return C()},Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=react-router-dom.production.min.js.map |
{ | ||
"name": "react-router-dom", | ||
"version": "0.0.0-experimental-48058118", | ||
"version": "0.0.0-experimental-5f6f59a6", | ||
"description": "Declarative routing for React web applications", | ||
@@ -26,4 +26,4 @@ "keywords": [ | ||
"dependencies": { | ||
"@remix-run/router": "0.0.0-experimental-48058118", | ||
"react-router": "0.0.0-experimental-48058118" | ||
"@remix-run/router": "0.0.0-experimental-5f6f59a6", | ||
"react-router": "0.0.0-experimental-5f6f59a6" | ||
}, | ||
@@ -30,0 +30,0 @@ "devDependencies": { |
import * as React from "react"; | ||
import type { Router as RemixRouter, StaticHandlerContext } from "@remix-run/router"; | ||
import type { Router as RemixRouter, StaticHandlerContext, CreateStaticHandlerOptions as RouterCreateStaticHandlerOptions } from "@remix-run/router"; | ||
import type { Location, RouteObject } from "react-router-dom"; | ||
@@ -14,2 +14,3 @@ export interface StaticRouterProps { | ||
export declare function StaticRouter({ basename, children, location: locationProp, }: StaticRouterProps): JSX.Element; | ||
export { StaticHandlerContext }; | ||
export interface StaticRouterProviderProps { | ||
@@ -26,2 +27,4 @@ context: StaticHandlerContext; | ||
export declare function StaticRouterProvider({ context, router, hydrate, nonce, }: StaticRouterProviderProps): JSX.Element; | ||
declare type CreateStaticHandlerOptions = Omit<RouterCreateStaticHandlerOptions, "detectErrorBoundary">; | ||
export declare function createStaticHandler(routes: RouteObject[], opts?: CreateStaticHandlerOptions): import("@remix-run/router").StaticHandler; | ||
export declare function createStaticRouter(routes: RouteObject[], context: StaticHandlerContext): RemixRouter; |
@@ -72,3 +72,3 @@ 'use strict'; | ||
}) { | ||
!(router$1 && context) ? process.env.NODE_ENV !== "production" ? router.invariant(false, "You must provide `router` and `context` to <StaticRouterProvider>") : router.invariant(false) : void 0; | ||
!(router$1 && context) ? process.env.NODE_ENV !== "production" ? router.UNSAFE_invariant(false, "You must provide `router` and `context` to <StaticRouterProvider>") : router.UNSAFE_invariant(false) : void 0; | ||
let dataRouterContext = { | ||
@@ -93,3 +93,3 @@ router: router$1, | ||
let json = JSON.stringify(JSON.stringify(data)); | ||
let json = htmlEscape(JSON.stringify(JSON.stringify(data))); | ||
hydrateScript = `window.__staticRouterHydrationData = JSON.parse(${json});`; | ||
@@ -168,22 +168,14 @@ } | ||
}; | ||
} // Temporary manifest generation - we should optimize this by combining the | ||
// tree-walks between convertRoutesToDataRoutes, enhanceManualRouteObjects, | ||
// and generateManifest. | ||
// Also look into getting rid of `route as AgnosticDataRouteObject` down below? | ||
} | ||
let detectErrorBoundary = route => Boolean(route.errorElement); | ||
function generateManifest(routes, manifest = new Map()) { | ||
routes.forEach(route => { | ||
manifest.set(route.id, route); | ||
if (route.children) { | ||
generateManifest(route.children, manifest); | ||
} | ||
function createStaticHandler(routes, opts) { | ||
return router.createStaticHandler(routes, { ...opts, | ||
detectErrorBoundary | ||
}); | ||
return manifest; | ||
} | ||
function createStaticRouter(routes, context) { | ||
let dataRoutes = router.UNSAFE_convertRoutesToDataRoutes(reactRouterDom.UNSAFE_enhanceManualRouteObjects(routes)); | ||
let manifest = generateManifest(dataRoutes); // Because our context matches may be from a framework-agnostic set of | ||
let manifest = {}; | ||
let dataRoutes = router.UNSAFE_convertRoutesToDataRoutes(routes, detectErrorBoundary, undefined, manifest); // Because our context matches may be from a framework-agnostic set of | ||
// routes passed to createStaticHandler(), we update them here with our | ||
@@ -193,5 +185,5 @@ // newly created/enhanced data routes | ||
let matches = context.matches.map(match => { | ||
let route = manifest.get(match.route.id) || match.route; | ||
let route = manifest[match.route.id] || match.route; | ||
return { ...match, | ||
route: route | ||
route | ||
}; | ||
@@ -269,3 +261,3 @@ }); | ||
getBlocker() { | ||
throw msg("getBlocker"); | ||
return router.IDLE_BLOCKER; | ||
}, | ||
@@ -278,3 +270,8 @@ | ||
_internalFetchControllers: new Map(), | ||
_internalActiveDeferreds: new Map() | ||
_internalActiveDeferreds: new Map(), | ||
_internalSetRoutes() { | ||
throw msg("_internalSetRoutes"); | ||
} | ||
}; | ||
@@ -295,2 +292,17 @@ } | ||
}; | ||
} // This utility is based on https://github.com/zertosh/htmlescape | ||
// License: https://github.com/zertosh/htmlescape/blob/0527ca7156a524d256101bb310a9f970f63078ad/LICENSE | ||
const ESCAPE_LOOKUP = { | ||
"&": "\\u0026", | ||
">": "\\u003e", | ||
"<": "\\u003c", | ||
"\u2028": "\\u2028", | ||
"\u2029": "\\u2029" | ||
}; | ||
const ESCAPE_REGEX = /[&><\u2028\u2029]/g; | ||
function htmlEscape(str) { | ||
return str.replace(ESCAPE_REGEX, match => ESCAPE_LOOKUP[match]); | ||
} | ||
@@ -300,2 +312,3 @@ | ||
exports.StaticRouterProvider = StaticRouterProvider; | ||
exports.createStaticHandler = createStaticHandler; | ||
exports.createStaticRouter = createStaticRouter; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
567544
4433
0
+ Added@remix-run/router@0.0.0-experimental-5f6f59a6(transitive)
+ Addedreact-router@0.0.0-experimental-5f6f59a6(transitive)
- Removed@remix-run/router@0.0.0-experimental-48058118(transitive)
- Removedreact-router@0.0.0-experimental-48058118(transitive)