react-router-dom
Advanced tools
Comparing version 0.0.0-experimental-edf416237 to 0.0.0-experimental-f042b8c1e
@@ -1,320 +0,2 @@ | ||
/** | ||
* NOTE: If you refactor this to split up the modules into separate files, | ||
* you'll need to update the rollup config for react-router-dom-v5-compat. | ||
*/ | ||
import * as React from "react"; | ||
import type { FutureConfig, Location, NavigateOptions, RelativeRoutingType, RouteObject, RouterProviderProps, To } from "react-router"; | ||
import type { unstable_DataStrategyFunction, unstable_DataStrategyFunctionArgs, unstable_DataStrategyMatch, Fetcher, FormEncType, FormMethod, FutureConfig as RouterFutureConfig, GetScrollRestorationKeyFunction, History, HTMLFormMethod, HydrationState, Router as RemixRouter, V7_FormMethod, BlockerFunction, unstable_PatchRoutesOnMissFunction } from "@remix-run/router"; | ||
import { UNSAFE_ErrorResponseImpl as ErrorResponseImpl } from "@remix-run/router"; | ||
import type { SubmitOptions, ParamKeyValuePair, URLSearchParamsInit, SubmitTarget } from "./dom"; | ||
import { createSearchParams } from "./dom"; | ||
export type { unstable_DataStrategyFunction, unstable_DataStrategyFunctionArgs, unstable_DataStrategyMatch, FormEncType, FormMethod, GetScrollRestorationKeyFunction, ParamKeyValuePair, SubmitOptions, URLSearchParamsInit, V7_FormMethod, }; | ||
export { createSearchParams, ErrorResponseImpl as UNSAFE_ErrorResponseImpl }; | ||
export type { ActionFunction, ActionFunctionArgs, AwaitProps, Blocker, BlockerFunction, DataRouteMatch, DataRouteObject, ErrorResponse, Fetcher, FutureConfig, Hash, IndexRouteObject, IndexRouteProps, JsonFunction, LazyRouteFunction, LayoutRouteProps, LoaderFunction, LoaderFunctionArgs, Location, MemoryRouterProps, NavigateFunction, NavigateOptions, NavigateProps, Navigation, Navigator, NonIndexRouteObject, OutletProps, Params, ParamParseKey, Path, PathMatch, Pathname, PathParam, PathPattern, PathRouteProps, RedirectFunction, RelativeRoutingType, RouteMatch, RouteObject, RouteProps, RouterProps, RouterProviderProps, RoutesProps, Search, ShouldRevalidateFunction, ShouldRevalidateFunctionArgs, To, UIMatch, unstable_HandlerResult, } from "react-router"; | ||
export { AbortedDeferredError, Await, MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, Routes, createMemoryRouter, createPath, createRoutesFromChildren, createRoutesFromElements, defer, isRouteErrorResponse, generatePath, json, matchPath, matchRoutes, parsePath, redirect, redirectDocument, renderMatches, resolvePath, useActionData, useAsyncError, useAsyncValue, 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_useRouteId, } from "react-router"; | ||
declare global { | ||
var __staticRouterHydrationData: HydrationState | undefined; | ||
var __reactRouterVersion: string; | ||
interface Document { | ||
startViewTransition(cb: () => Promise<void> | void): ViewTransition; | ||
} | ||
} | ||
interface DOMRouterOpts { | ||
basename?: string; | ||
future?: Partial<Omit<RouterFutureConfig, "v7_prependBasename">>; | ||
hydrationData?: HydrationState; | ||
unstable_dataStrategy?: unstable_DataStrategyFunction; | ||
unstable_patchRoutesOnMiss?: unstable_PatchRoutesOnMissFunction; | ||
window?: Window; | ||
} | ||
export declare function createBrowserRouter(routes: RouteObject[], opts?: DOMRouterOpts): RemixRouter; | ||
export declare function createHashRouter(routes: RouteObject[], opts?: DOMRouterOpts): RemixRouter; | ||
type ViewTransitionContextObject = { | ||
isTransitioning: false; | ||
} | { | ||
isTransitioning: true; | ||
flushSync: boolean; | ||
currentLocation: Location; | ||
nextLocation: Location; | ||
}; | ||
declare const ViewTransitionContext: React.Context<ViewTransitionContextObject>; | ||
export { ViewTransitionContext as UNSAFE_ViewTransitionContext }; | ||
type FetchersContextObject = Map<string, any>; | ||
declare const FetchersContext: React.Context<FetchersContextObject>; | ||
export { FetchersContext as UNSAFE_FetchersContext }; | ||
interface ViewTransition { | ||
finished: Promise<void>; | ||
ready: Promise<void>; | ||
updateCallbackDone: Promise<void>; | ||
skipTransition(): void; | ||
} | ||
/** | ||
* Given a Remix Router instance, render the appropriate UI | ||
*/ | ||
export declare function RouterProvider({ fallbackElement, router, future, }: RouterProviderProps): React.ReactElement; | ||
export interface BrowserRouterProps { | ||
basename?: string; | ||
children?: React.ReactNode; | ||
future?: Partial<FutureConfig>; | ||
window?: Window; | ||
} | ||
/** | ||
* A `<Router>` for use in web browsers. Provides the cleanest URLs. | ||
*/ | ||
export declare function BrowserRouter({ basename, children, future, window, }: BrowserRouterProps): React.JSX.Element; | ||
export interface HashRouterProps { | ||
basename?: string; | ||
children?: React.ReactNode; | ||
future?: Partial<FutureConfig>; | ||
window?: Window; | ||
} | ||
/** | ||
* A `<Router>` for use in web browsers. Stores the location in the hash | ||
* portion of the URL so it is not sent to the server. | ||
*/ | ||
export declare function HashRouter({ basename, children, future, window, }: HashRouterProps): React.JSX.Element; | ||
export interface HistoryRouterProps { | ||
basename?: string; | ||
children?: React.ReactNode; | ||
future?: FutureConfig; | ||
history: History; | ||
} | ||
/** | ||
* A `<Router>` that accepts a pre-instantiated history object. It's important | ||
* to note that using your own history object is highly discouraged and may add | ||
* two versions of the history library to your bundles unless you use the same | ||
* version of the history library that React Router uses internally. | ||
*/ | ||
declare function HistoryRouter({ basename, children, future, history, }: HistoryRouterProps): React.JSX.Element; | ||
declare namespace HistoryRouter { | ||
var displayName: string; | ||
} | ||
export { HistoryRouter as unstable_HistoryRouter }; | ||
export interface LinkProps extends Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, "href"> { | ||
reloadDocument?: boolean; | ||
replace?: boolean; | ||
state?: any; | ||
preventScrollReset?: boolean; | ||
relative?: RelativeRoutingType; | ||
to: To; | ||
unstable_viewTransition?: boolean; | ||
} | ||
/** | ||
* The public API for rendering a history-aware `<a>`. | ||
*/ | ||
export declare const Link: React.ForwardRefExoticComponent<LinkProps & React.RefAttributes<HTMLAnchorElement>>; | ||
type NavLinkRenderProps = { | ||
isActive: boolean; | ||
isPending: boolean; | ||
isTransitioning: boolean; | ||
}; | ||
export interface NavLinkProps extends Omit<LinkProps, "className" | "style" | "children"> { | ||
children?: React.ReactNode | ((props: NavLinkRenderProps) => React.ReactNode); | ||
caseSensitive?: boolean; | ||
className?: string | ((props: NavLinkRenderProps) => string | undefined); | ||
end?: boolean; | ||
style?: React.CSSProperties | ((props: NavLinkRenderProps) => React.CSSProperties | undefined); | ||
} | ||
/** | ||
* A `<Link>` wrapper that knows if it's "active" or not. | ||
*/ | ||
export declare const NavLink: React.ForwardRefExoticComponent<NavLinkProps & React.RefAttributes<HTMLAnchorElement>>; | ||
export interface FetcherFormProps extends React.FormHTMLAttributes<HTMLFormElement> { | ||
/** | ||
* The HTTP verb to use when the form is submit. Supports "get", "post", | ||
* "put", "delete", "patch". | ||
*/ | ||
method?: HTMLFormMethod; | ||
/** | ||
* `<form encType>` - enhancing beyond the normal string type and limiting | ||
* to the built-in browser supported values | ||
*/ | ||
encType?: "application/x-www-form-urlencoded" | "multipart/form-data" | "text/plain"; | ||
/** | ||
* Normal `<form action>` but supports React Router's relative paths. | ||
*/ | ||
action?: string; | ||
/** | ||
* Determines whether the form action is relative to the route hierarchy or | ||
* the pathname. Use this if you want to opt out of navigating the route | ||
* hierarchy and want to instead route based on /-delimited URL segments | ||
*/ | ||
relative?: RelativeRoutingType; | ||
/** | ||
* Prevent the scroll position from resetting to the top of the viewport on | ||
* completion of the navigation when using the <ScrollRestoration> component | ||
*/ | ||
preventScrollReset?: boolean; | ||
/** | ||
* A function to call when the form is submitted. If you call | ||
* `event.preventDefault()` then this form will not do anything. | ||
*/ | ||
onSubmit?: React.FormEventHandler<HTMLFormElement>; | ||
} | ||
export interface FormProps extends FetcherFormProps { | ||
/** | ||
* Indicate a specific fetcherKey to use when using navigate=false | ||
*/ | ||
fetcherKey?: string; | ||
/** | ||
* navigate=false will use a fetcher instead of a navigation | ||
*/ | ||
navigate?: boolean; | ||
/** | ||
* Forces a full document navigation instead of a fetch. | ||
*/ | ||
reloadDocument?: boolean; | ||
/** | ||
* Replaces the current entry in the browser history stack when the form | ||
* navigates. Use this if you don't want the user to be able to click "back" | ||
* to the page with the form on it. | ||
*/ | ||
replace?: boolean; | ||
/** | ||
* State object to add to the history stack entry for this navigation | ||
*/ | ||
state?: any; | ||
/** | ||
* Enable view transitions on this Form navigation | ||
*/ | ||
unstable_viewTransition?: boolean; | ||
} | ||
/** | ||
* A `@remix-run/router`-aware `<form>`. It behaves like a normal form except | ||
* that the interaction with the server is with `fetch` instead of new document | ||
* requests, allowing components to add nicer UX to the page as the form is | ||
* submitted and returns with data. | ||
*/ | ||
export declare const Form: React.ForwardRefExoticComponent<FormProps & React.RefAttributes<HTMLFormElement>>; | ||
export interface ScrollRestorationProps { | ||
getKey?: GetScrollRestorationKeyFunction; | ||
storageKey?: string; | ||
} | ||
/** | ||
* This component will emulate the browser's scroll restoration on location | ||
* changes. | ||
*/ | ||
export declare function ScrollRestoration({ getKey, storageKey, }: ScrollRestorationProps): null; | ||
export declare namespace ScrollRestoration { | ||
var displayName: string; | ||
} | ||
/** | ||
* Handles the click behavior for router `<Link>` components. This is useful if | ||
* you need to create custom `<Link>` components with the same click behavior we | ||
* use in our exported `<Link>`. | ||
*/ | ||
export declare function useLinkClickHandler<E extends Element = HTMLAnchorElement>(to: To, { target, replace: replaceProp, state, preventScrollReset, relative, unstable_viewTransition, }?: { | ||
target?: React.HTMLAttributeAnchorTarget; | ||
replace?: boolean; | ||
state?: any; | ||
preventScrollReset?: boolean; | ||
relative?: RelativeRoutingType; | ||
unstable_viewTransition?: boolean; | ||
}): (event: React.MouseEvent<E, MouseEvent>) => void; | ||
/** | ||
* A convenient wrapper for reading and writing search parameters via the | ||
* URLSearchParams interface. | ||
*/ | ||
export declare function useSearchParams(defaultInit?: URLSearchParamsInit): [URLSearchParams, SetURLSearchParams]; | ||
export type SetURLSearchParams = (nextInit?: URLSearchParamsInit | ((prev: URLSearchParams) => URLSearchParamsInit), navigateOpts?: NavigateOptions) => void; | ||
/** | ||
* Submits a HTML `<form>` to the server without reloading the page. | ||
*/ | ||
export interface SubmitFunction { | ||
( | ||
/** | ||
* Specifies the `<form>` to be submitted to the server, a specific | ||
* `<button>` or `<input type="submit">` to use to submit the form, or some | ||
* arbitrary data to submit. | ||
* | ||
* Note: When using a `<button>` its `name` and `value` will also be | ||
* included in the form data that is submitted. | ||
*/ | ||
target: SubmitTarget, | ||
/** | ||
* Options that override the `<form>`'s own attributes. Required when | ||
* submitting arbitrary data without a backing `<form>`. | ||
*/ | ||
options?: SubmitOptions): void; | ||
} | ||
/** | ||
* Submits a fetcher `<form>` to the server without reloading the page. | ||
*/ | ||
export interface FetcherSubmitFunction { | ||
(target: SubmitTarget, options?: Omit<SubmitOptions, "replace" | "state">): void; | ||
} | ||
/** | ||
* Returns a function that may be used to programmatically submit a form (or | ||
* some arbitrary data) to the server. | ||
*/ | ||
export declare function useSubmit(): SubmitFunction; | ||
export declare function useFormAction(action?: string, { relative }?: { | ||
relative?: RelativeRoutingType; | ||
}): string; | ||
export type FetcherWithComponents<TData> = Fetcher<TData> & { | ||
Form: React.ForwardRefExoticComponent<FetcherFormProps & React.RefAttributes<HTMLFormElement>>; | ||
submit: FetcherSubmitFunction; | ||
load: (href: string, opts?: { | ||
unstable_flushSync?: boolean; | ||
}) => void; | ||
}; | ||
/** | ||
* Interacts with route loaders and actions without causing a navigation. Great | ||
* for any interaction that stays on the same page. | ||
*/ | ||
export declare function useFetcher<TData = any>({ key, }?: { | ||
key?: string; | ||
}): FetcherWithComponents<TData>; | ||
/** | ||
* Provides all fetchers currently on the page. Useful for layouts and parent | ||
* routes that need to provide pending/optimistic UI regarding the fetch. | ||
*/ | ||
export declare function useFetchers(): (Fetcher & { | ||
key: string; | ||
})[]; | ||
/** | ||
* When rendered inside a RouterProvider, will restore scroll positions on navigations | ||
*/ | ||
declare function useScrollRestoration({ getKey, storageKey, }?: { | ||
getKey?: GetScrollRestorationKeyFunction; | ||
storageKey?: string; | ||
}): void; | ||
export { useScrollRestoration as UNSAFE_useScrollRestoration }; | ||
/** | ||
* Setup a callback to be fired on the window's `beforeunload` event. This is | ||
* useful for saving some data to `window.localStorage` just before the page | ||
* refreshes. | ||
* | ||
* Note: The `callback` argument should be a function created with | ||
* `React.useCallback()`. | ||
*/ | ||
export declare function useBeforeUnload(callback: (event: BeforeUnloadEvent) => any, options?: { | ||
capture?: boolean; | ||
}): void; | ||
/** | ||
* Wrapper around useBlocker to show a window.confirm prompt to users instead | ||
* of building a custom UI with useBlocker. | ||
* | ||
* Warning: This has *a lot of rough edges* and behaves very differently (and | ||
* very incorrectly in some cases) across browsers if user click addition | ||
* back/forward navigations while the confirm is open. Use at your own risk. | ||
*/ | ||
declare function usePrompt({ when, message, }: { | ||
when: boolean | BlockerFunction; | ||
message: string; | ||
}): void; | ||
export { usePrompt as unstable_usePrompt }; | ||
/** | ||
* Return a boolean indicating if there is an active view transition to the | ||
* given href. You can use this value to render CSS classes or viewTransitionName | ||
* styles onto your elements | ||
* | ||
* @param href The destination href | ||
* @param [opts.relative] Relative routing type ("route" | "path") | ||
*/ | ||
declare function useViewTransitionState(to: To, opts?: { | ||
relative?: RelativeRoutingType; | ||
}): boolean; | ||
export { useViewTransitionState as unstable_useViewTransitionState }; | ||
export type * from "react-router"; | ||
export * from "react-router"; |
/** | ||
* React Router DOM v0.0.0-experimental-edf416237 | ||
* React Router DOM v0.0.0-experimental-f042b8c1e | ||
* | ||
@@ -4,0 +4,0 @@ * Copyright (c) Remix Software Inc. |
/** | ||
* React Router DOM v0.0.0-experimental-edf416237 | ||
* React Router DOM v0.0.0-experimental-f042b8c1e | ||
* | ||
@@ -11,1480 +11,3 @@ * Copyright (c) Remix Software Inc. | ||
*/ | ||
import * as React from 'react'; | ||
import * as ReactDOM from 'react-dom'; | ||
import { UNSAFE_mapRouteProperties, UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, Router, UNSAFE_useRoutesImpl, UNSAFE_NavigationContext, useHref, useResolvedPath, useLocation, useNavigate, createPath, UNSAFE_useRouteId, UNSAFE_RouteContext, useMatches, useNavigation, useBlocker } from 'react-router'; | ||
export { AbortedDeferredError, Await, MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, Routes, UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, UNSAFE_LocationContext, UNSAFE_NavigationContext, UNSAFE_RouteContext, UNSAFE_useRouteId, createMemoryRouter, createPath, createRoutesFromChildren, createRoutesFromElements, defer, generatePath, isRouteErrorResponse, json, matchPath, matchRoutes, parsePath, redirect, redirectDocument, renderMatches, resolvePath, useActionData, useAsyncError, useAsyncValue, useBlocker, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes } from 'react-router'; | ||
import { stripBasename, UNSAFE_warning, createRouter, createBrowserHistory, createHashHistory, UNSAFE_ErrorResponseImpl, UNSAFE_invariant, joinPaths, IDLE_FETCHER, matchPath } from '@remix-run/router'; | ||
export { UNSAFE_ErrorResponseImpl } from '@remix-run/router'; | ||
const defaultMethod = "get"; | ||
const defaultEncType = "application/x-www-form-urlencoded"; | ||
function isHtmlElement(object) { | ||
return object != null && typeof object.tagName === "string"; | ||
} | ||
function isButtonElement(object) { | ||
return isHtmlElement(object) && object.tagName.toLowerCase() === "button"; | ||
} | ||
function isFormElement(object) { | ||
return isHtmlElement(object) && object.tagName.toLowerCase() === "form"; | ||
} | ||
function isInputElement(object) { | ||
return isHtmlElement(object) && object.tagName.toLowerCase() === "input"; | ||
} | ||
function isModifiedEvent(event) { | ||
return !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey); | ||
} | ||
function shouldProcessLinkClick(event, target) { | ||
return event.button === 0 && ( | ||
// Ignore everything but left clicks | ||
!target || target === "_self") && | ||
// Let browser handle "target=_blank" etc. | ||
!isModifiedEvent(event) // Ignore clicks with modifier keys | ||
; | ||
} | ||
/** | ||
* Creates a URLSearchParams object using the given initializer. | ||
* | ||
* This is identical to `new URLSearchParams(init)` except it also | ||
* supports arrays as values in the object form of the initializer | ||
* instead of just strings. This is convenient when you need multiple | ||
* values for a given key, but don't want to use an array initializer. | ||
* | ||
* For example, instead of: | ||
* | ||
* let searchParams = new URLSearchParams([ | ||
* ['sort', 'name'], | ||
* ['sort', 'price'] | ||
* ]); | ||
* | ||
* you can do: | ||
* | ||
* let searchParams = createSearchParams({ | ||
* sort: ['name', 'price'] | ||
* }); | ||
*/ | ||
function createSearchParams(init = "") { | ||
return new URLSearchParams(typeof init === "string" || Array.isArray(init) || init instanceof URLSearchParams ? init : Object.keys(init).reduce((memo, key) => { | ||
let value = init[key]; | ||
return memo.concat(Array.isArray(value) ? value.map(v => [key, v]) : [[key, value]]); | ||
}, [])); | ||
} | ||
function getSearchParamsForLocation(locationSearch, defaultSearchParams) { | ||
let searchParams = createSearchParams(locationSearch); | ||
if (defaultSearchParams) { | ||
// Use `defaultSearchParams.forEach(...)` here instead of iterating of | ||
// `defaultSearchParams.keys()` to work-around a bug in Firefox related to | ||
// web extensions. Relevant Bugzilla tickets: | ||
// https://bugzilla.mozilla.org/show_bug.cgi?id=1414602 | ||
// https://bugzilla.mozilla.org/show_bug.cgi?id=1023984 | ||
defaultSearchParams.forEach((_, key) => { | ||
if (!searchParams.has(key)) { | ||
defaultSearchParams.getAll(key).forEach(value => { | ||
searchParams.append(key, value); | ||
}); | ||
} | ||
}); | ||
} | ||
return searchParams; | ||
} | ||
// Thanks https://github.com/sindresorhus/type-fest! | ||
// One-time check for submitter support | ||
let _formDataSupportsSubmitter = null; | ||
function isFormDataSubmitterSupported() { | ||
if (_formDataSupportsSubmitter === null) { | ||
try { | ||
new FormData(document.createElement("form"), | ||
// @ts-expect-error if FormData supports the submitter parameter, this will throw | ||
0); | ||
_formDataSupportsSubmitter = false; | ||
} catch (e) { | ||
_formDataSupportsSubmitter = true; | ||
} | ||
} | ||
return _formDataSupportsSubmitter; | ||
} | ||
const supportedFormEncTypes = new Set(["application/x-www-form-urlencoded", "multipart/form-data", "text/plain"]); | ||
function getFormEncType(encType) { | ||
if (encType != null && !supportedFormEncTypes.has(encType)) { | ||
UNSAFE_warning(false, `"${encType}" is not a valid \`encType\` for \`<Form>\`/\`<fetcher.Form>\` ` + `and will default to "${defaultEncType}"`) ; | ||
return null; | ||
} | ||
return encType; | ||
} | ||
function getFormSubmissionInfo(target, basename) { | ||
let method; | ||
let action; | ||
let encType; | ||
let formData; | ||
let body; | ||
if (isFormElement(target)) { | ||
// When grabbing the action from the element, it will have had the basename | ||
// prefixed to ensure non-JS scenarios work, so strip it since we'll | ||
// re-prefix in the router | ||
let attr = target.getAttribute("action"); | ||
action = attr ? stripBasename(attr, basename) : null; | ||
method = target.getAttribute("method") || defaultMethod; | ||
encType = getFormEncType(target.getAttribute("enctype")) || defaultEncType; | ||
formData = new FormData(target); | ||
} else if (isButtonElement(target) || isInputElement(target) && (target.type === "submit" || target.type === "image")) { | ||
let form = target.form; | ||
if (form == null) { | ||
throw new Error(`Cannot submit a <button> or <input type="submit"> without a <form>`); | ||
} | ||
// <button>/<input type="submit"> may override attributes of <form> | ||
// When grabbing the action from the element, it will have had the basename | ||
// prefixed to ensure non-JS scenarios work, so strip it since we'll | ||
// re-prefix in the router | ||
let attr = target.getAttribute("formaction") || form.getAttribute("action"); | ||
action = attr ? stripBasename(attr, basename) : null; | ||
method = target.getAttribute("formmethod") || form.getAttribute("method") || defaultMethod; | ||
encType = getFormEncType(target.getAttribute("formenctype")) || getFormEncType(form.getAttribute("enctype")) || defaultEncType; | ||
// Build a FormData object populated from a form and submitter | ||
formData = new FormData(form, target); | ||
// If this browser doesn't support the `FormData(el, submitter)` format, | ||
// then tack on the submitter value at the end. This is a lightweight | ||
// solution that is not 100% spec compliant. For complete support in older | ||
// browsers, consider using the `formdata-submitter-polyfill` package | ||
if (!isFormDataSubmitterSupported()) { | ||
let { | ||
name, | ||
type, | ||
value | ||
} = target; | ||
if (type === "image") { | ||
let prefix = name ? `${name}.` : ""; | ||
formData.append(`${prefix}x`, "0"); | ||
formData.append(`${prefix}y`, "0"); | ||
} else if (name) { | ||
formData.append(name, value); | ||
} | ||
} | ||
} else if (isHtmlElement(target)) { | ||
throw new Error(`Cannot submit element that is not <form>, <button>, or ` + `<input type="submit|image">`); | ||
} else { | ||
method = defaultMethod; | ||
action = null; | ||
encType = defaultEncType; | ||
body = target; | ||
} | ||
// Send body for <Form encType="text/plain" so we encode it into text | ||
if (formData && encType === "text/plain") { | ||
body = formData; | ||
formData = undefined; | ||
} | ||
return { | ||
action, | ||
method: method.toLowerCase(), | ||
encType, | ||
formData, | ||
body | ||
}; | ||
} | ||
/** | ||
* NOTE: If you refactor this to split up the modules into separate files, | ||
* you'll need to update the rollup config for react-router-dom-v5-compat. | ||
*/ | ||
//#endregion | ||
// HEY YOU! DON'T TOUCH THIS VARIABLE! | ||
// | ||
// It is replaced with the proper version at build time via a babel plugin in | ||
// the rollup config. | ||
// | ||
// Export a global property onto the window for React Router detection by the | ||
// Core Web Vitals Technology Report. This way they can configure the `wappalyzer` | ||
// to detect and properly classify live websites as being built with React Router: | ||
// https://github.com/HTTPArchive/wappalyzer/blob/main/src/technologies/r.json | ||
const REACT_ROUTER_VERSION = "0"; | ||
try { | ||
window.__reactRouterVersion = REACT_ROUTER_VERSION; | ||
} catch (e) { | ||
// no-op | ||
} | ||
//////////////////////////////////////////////////////////////////////////////// | ||
//#region Routers | ||
//////////////////////////////////////////////////////////////////////////////// | ||
function createBrowserRouter(routes, opts) { | ||
return createRouter({ | ||
basename: opts?.basename, | ||
future: { | ||
...opts?.future, | ||
v7_prependBasename: true | ||
}, | ||
history: createBrowserHistory({ | ||
window: opts?.window | ||
}), | ||
hydrationData: opts?.hydrationData || parseHydrationData(), | ||
routes, | ||
mapRouteProperties: UNSAFE_mapRouteProperties, | ||
unstable_dataStrategy: opts?.unstable_dataStrategy, | ||
unstable_patchRoutesOnMiss: opts?.unstable_patchRoutesOnMiss, | ||
window: opts?.window | ||
}).initialize(); | ||
} | ||
function createHashRouter(routes, opts) { | ||
return createRouter({ | ||
basename: opts?.basename, | ||
future: { | ||
...opts?.future, | ||
v7_prependBasename: true | ||
}, | ||
history: createHashHistory({ | ||
window: opts?.window | ||
}), | ||
hydrationData: opts?.hydrationData || parseHydrationData(), | ||
routes, | ||
mapRouteProperties: UNSAFE_mapRouteProperties, | ||
unstable_dataStrategy: opts?.unstable_dataStrategy, | ||
unstable_patchRoutesOnMiss: opts?.unstable_patchRoutesOnMiss, | ||
window: opts?.window | ||
}).initialize(); | ||
} | ||
function parseHydrationData() { | ||
let state = window?.__staticRouterHydrationData; | ||
if (state && state.errors) { | ||
state = { | ||
...state, | ||
errors: deserializeErrors(state.errors) | ||
}; | ||
} | ||
return state; | ||
} | ||
function deserializeErrors(errors) { | ||
if (!errors) return null; | ||
let entries = Object.entries(errors); | ||
let serialized = {}; | ||
for (let [key, val] of entries) { | ||
// Hey you! If you change this, please change the corresponding logic in | ||
// serializeErrors in react-router-dom/server.tsx :) | ||
if (val && val.__type === "RouteErrorResponse") { | ||
serialized[key] = new UNSAFE_ErrorResponseImpl(val.status, val.statusText, val.data, val.internal === true); | ||
} else if (val && val.__type === "Error") { | ||
// Attempt to reconstruct the right type of Error (i.e., ReferenceError) | ||
if (val.__subType) { | ||
let ErrorConstructor = window[val.__subType]; | ||
if (typeof ErrorConstructor === "function") { | ||
try { | ||
// @ts-expect-error | ||
let error = new ErrorConstructor(val.message); | ||
// Wipe away the client-side stack trace. Nothing to fill it in with | ||
// because we don't serialize SSR stack traces for security reasons | ||
error.stack = ""; | ||
serialized[key] = error; | ||
} catch (e) { | ||
// no-op - fall through and create a normal Error | ||
} | ||
} | ||
} | ||
if (serialized[key] == null) { | ||
let error = new Error(val.message); | ||
// Wipe away the client-side stack trace. Nothing to fill it in with | ||
// because we don't serialize SSR stack traces for security reasons | ||
error.stack = ""; | ||
serialized[key] = error; | ||
} | ||
} else { | ||
serialized[key] = val; | ||
} | ||
} | ||
return serialized; | ||
} | ||
//#endregion | ||
//////////////////////////////////////////////////////////////////////////////// | ||
//#region Contexts | ||
//////////////////////////////////////////////////////////////////////////////// | ||
const ViewTransitionContext = /*#__PURE__*/React.createContext({ | ||
isTransitioning: false | ||
}); | ||
{ | ||
ViewTransitionContext.displayName = "ViewTransition"; | ||
} | ||
// TODO: (v7) Change the useFetcher data from `any` to `unknown` | ||
const FetchersContext = /*#__PURE__*/React.createContext(new Map()); | ||
{ | ||
FetchersContext.displayName = "Fetchers"; | ||
} | ||
//#endregion | ||
//////////////////////////////////////////////////////////////////////////////// | ||
//#region Components | ||
//////////////////////////////////////////////////////////////////////////////// | ||
/** | ||
Webpack + React 17 fails to compile on any of the following because webpack | ||
complains that `startTransition` doesn't exist in `React`: | ||
* import { startTransition } from "react" | ||
* import * as React from from "react"; | ||
"startTransition" in React ? React.startTransition(() => setState()) : setState() | ||
* import * as React from from "react"; | ||
"startTransition" in React ? React["startTransition"](() => setState()) : setState() | ||
Moving it to a constant such as the following solves the Webpack/React 17 issue: | ||
* import * as React from from "react"; | ||
const START_TRANSITION = "startTransition"; | ||
START_TRANSITION in React ? React[START_TRANSITION](() => setState()) : setState() | ||
However, that introduces webpack/terser minification issues in production builds | ||
in React 18 where minification/obfuscation ends up removing the call of | ||
React.startTransition entirely from the first half of the ternary. Grabbing | ||
this exported reference once up front resolves that issue. | ||
See https://github.com/remix-run/react-router/issues/10579 | ||
*/ | ||
const START_TRANSITION = "startTransition"; | ||
const startTransitionImpl = React[START_TRANSITION]; | ||
const FLUSH_SYNC = "flushSync"; | ||
const flushSyncImpl = ReactDOM[FLUSH_SYNC]; | ||
const USE_ID = "useId"; | ||
const useIdImpl = React[USE_ID]; | ||
function startTransitionSafe(cb) { | ||
if (startTransitionImpl) { | ||
startTransitionImpl(cb); | ||
} else { | ||
cb(); | ||
} | ||
} | ||
function flushSyncSafe(cb) { | ||
if (flushSyncImpl) { | ||
flushSyncImpl(cb); | ||
} else { | ||
cb(); | ||
} | ||
} | ||
class Deferred { | ||
status = "pending"; | ||
// @ts-expect-error - no initializer | ||
// @ts-expect-error - no initializer | ||
constructor() { | ||
this.promise = new Promise((resolve, reject) => { | ||
this.resolve = value => { | ||
if (this.status === "pending") { | ||
this.status = "resolved"; | ||
resolve(value); | ||
} | ||
}; | ||
this.reject = reason => { | ||
if (this.status === "pending") { | ||
this.status = "rejected"; | ||
reject(reason); | ||
} | ||
}; | ||
}); | ||
} | ||
} | ||
/** | ||
* Given a Remix Router instance, render the appropriate UI | ||
*/ | ||
function RouterProvider({ | ||
fallbackElement, | ||
router, | ||
future | ||
}) { | ||
let [state, setStateImpl] = React.useState(router.state); | ||
let [pendingState, setPendingState] = React.useState(); | ||
let [vtContext, setVtContext] = React.useState({ | ||
isTransitioning: false | ||
}); | ||
let [renderDfd, setRenderDfd] = React.useState(); | ||
let [transition, setTransition] = React.useState(); | ||
let [interruption, setInterruption] = React.useState(); | ||
let fetcherData = React.useRef(new Map()); | ||
let { | ||
v7_startTransition | ||
} = future || {}; | ||
let optInStartTransition = React.useCallback(cb => { | ||
if (v7_startTransition) { | ||
startTransitionSafe(cb); | ||
} else { | ||
cb(); | ||
} | ||
}, [v7_startTransition]); | ||
let setState = React.useCallback((newState, { | ||
deletedFetchers, | ||
unstable_flushSync: flushSync, | ||
unstable_viewTransitionOpts: viewTransitionOpts | ||
}) => { | ||
deletedFetchers.forEach(key => fetcherData.current.delete(key)); | ||
newState.fetchers.forEach((fetcher, key) => { | ||
if (fetcher.data !== undefined) { | ||
fetcherData.current.set(key, fetcher.data); | ||
} | ||
}); | ||
let isViewTransitionUnavailable = router.window == null || router.window.document == null || typeof router.window.document.startViewTransition !== "function"; | ||
// If this isn't a view transition or it's not available in this browser, | ||
// just update and be done with it | ||
if (!viewTransitionOpts || isViewTransitionUnavailable) { | ||
if (flushSync) { | ||
flushSyncSafe(() => setStateImpl(newState)); | ||
} else { | ||
optInStartTransition(() => setStateImpl(newState)); | ||
} | ||
return; | ||
} | ||
// flushSync + startViewTransition | ||
if (flushSync) { | ||
// Flush through the context to mark DOM elements as transition=ing | ||
flushSyncSafe(() => { | ||
// Cancel any pending transitions | ||
if (transition) { | ||
renderDfd && renderDfd.resolve(); | ||
transition.skipTransition(); | ||
} | ||
setVtContext({ | ||
isTransitioning: true, | ||
flushSync: true, | ||
currentLocation: viewTransitionOpts.currentLocation, | ||
nextLocation: viewTransitionOpts.nextLocation | ||
}); | ||
}); | ||
// Update the DOM | ||
let t = router.window.document.startViewTransition(() => { | ||
flushSyncSafe(() => setStateImpl(newState)); | ||
}); | ||
// Clean up after the animation completes | ||
t.finished.finally(() => { | ||
flushSyncSafe(() => { | ||
setRenderDfd(undefined); | ||
setTransition(undefined); | ||
setPendingState(undefined); | ||
setVtContext({ | ||
isTransitioning: false | ||
}); | ||
}); | ||
}); | ||
flushSyncSafe(() => setTransition(t)); | ||
return; | ||
} | ||
// startTransition + startViewTransition | ||
if (transition) { | ||
// Interrupting an in-progress transition, cancel and let everything flush | ||
// out, and then kick off a new transition from the interruption state | ||
renderDfd && renderDfd.resolve(); | ||
transition.skipTransition(); | ||
setInterruption({ | ||
state: newState, | ||
currentLocation: viewTransitionOpts.currentLocation, | ||
nextLocation: viewTransitionOpts.nextLocation | ||
}); | ||
} else { | ||
// Completed navigation update with opted-in view transitions, let 'er rip | ||
setPendingState(newState); | ||
setVtContext({ | ||
isTransitioning: true, | ||
flushSync: false, | ||
currentLocation: viewTransitionOpts.currentLocation, | ||
nextLocation: viewTransitionOpts.nextLocation | ||
}); | ||
} | ||
}, [router.window, transition, renderDfd, fetcherData, optInStartTransition]); | ||
// Need to use a layout effect here so we are subscribed early enough to | ||
// pick up on any render-driven redirects/navigations (useEffect/<Navigate>) | ||
React.useLayoutEffect(() => router.subscribe(setState), [router, setState]); | ||
// When we start a view transition, create a Deferred we can use for the | ||
// eventual "completed" render | ||
React.useEffect(() => { | ||
if (vtContext.isTransitioning && !vtContext.flushSync) { | ||
setRenderDfd(new Deferred()); | ||
} | ||
}, [vtContext]); | ||
// Once the deferred is created, kick off startViewTransition() to update the | ||
// DOM and then wait on the Deferred to resolve (indicating the DOM update has | ||
// happened) | ||
React.useEffect(() => { | ||
if (renderDfd && pendingState && router.window) { | ||
let newState = pendingState; | ||
let renderPromise = renderDfd.promise; | ||
let transition = router.window.document.startViewTransition(async () => { | ||
optInStartTransition(() => setStateImpl(newState)); | ||
await renderPromise; | ||
}); | ||
transition.finished.finally(() => { | ||
setRenderDfd(undefined); | ||
setTransition(undefined); | ||
setPendingState(undefined); | ||
setVtContext({ | ||
isTransitioning: false | ||
}); | ||
}); | ||
setTransition(transition); | ||
} | ||
}, [optInStartTransition, pendingState, renderDfd, router.window]); | ||
// When the new location finally renders and is committed to the DOM, this | ||
// effect will run to resolve the transition | ||
React.useEffect(() => { | ||
if (renderDfd && pendingState && state.location.key === pendingState.location.key) { | ||
renderDfd.resolve(); | ||
} | ||
}, [renderDfd, transition, state.location, pendingState]); | ||
// If we get interrupted with a new navigation during a transition, we skip | ||
// the active transition, let it cleanup, then kick it off again here | ||
React.useEffect(() => { | ||
if (!vtContext.isTransitioning && interruption) { | ||
setPendingState(interruption.state); | ||
setVtContext({ | ||
isTransitioning: true, | ||
flushSync: false, | ||
currentLocation: interruption.currentLocation, | ||
nextLocation: interruption.nextLocation | ||
}); | ||
setInterruption(undefined); | ||
} | ||
}, [vtContext.isTransitioning, interruption]); | ||
React.useEffect(() => { | ||
UNSAFE_warning(fallbackElement == null || !router.future.v7_partialHydration, "`<RouterProvider fallbackElement>` is deprecated when using " + "`v7_partialHydration`, use a `HydrateFallback` component instead") ; | ||
// Only log this once on initial mount | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []); | ||
let navigator = React.useMemo(() => { | ||
return { | ||
createHref: router.createHref, | ||
encodeLocation: router.encodeLocation, | ||
go: n => router.navigate(n), | ||
push: (to, state, opts) => router.navigate(to, { | ||
state, | ||
preventScrollReset: opts?.preventScrollReset | ||
}), | ||
replace: (to, state, opts) => router.navigate(to, { | ||
replace: true, | ||
state, | ||
preventScrollReset: opts?.preventScrollReset | ||
}) | ||
}; | ||
}, [router]); | ||
let basename = router.basename || "/"; | ||
let dataRouterContext = React.useMemo(() => ({ | ||
router, | ||
navigator, | ||
static: false, | ||
basename | ||
}), [router, navigator, basename]); | ||
// The fragment and {null} here are important! We need them to keep React 18's | ||
// useId happy when we are server-rendering since we may have a <script> here | ||
// containing the hydrated server-side staticContext (from StaticRouterProvider). | ||
// useId relies on the component tree structure to generate deterministic id's | ||
// so we need to ensure it remains the same on the client even though | ||
// we don't need the <script> tag | ||
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(UNSAFE_DataRouterContext.Provider, { | ||
value: dataRouterContext | ||
}, /*#__PURE__*/React.createElement(UNSAFE_DataRouterStateContext.Provider, { | ||
value: state | ||
}, /*#__PURE__*/React.createElement(FetchersContext.Provider, { | ||
value: fetcherData.current | ||
}, /*#__PURE__*/React.createElement(ViewTransitionContext.Provider, { | ||
value: vtContext | ||
}, /*#__PURE__*/React.createElement(Router, { | ||
basename: basename, | ||
location: state.location, | ||
navigationType: state.historyAction, | ||
navigator: navigator, | ||
future: { | ||
v7_relativeSplatPath: router.future.v7_relativeSplatPath | ||
} | ||
}, state.initialized || router.future.v7_partialHydration ? /*#__PURE__*/React.createElement(DataRoutes, { | ||
routes: router.routes, | ||
future: router.future, | ||
state: state | ||
}) : fallbackElement))))), null); | ||
} | ||
function DataRoutes({ | ||
routes, | ||
future, | ||
state | ||
}) { | ||
return UNSAFE_useRoutesImpl(routes, undefined, state, future); | ||
} | ||
/** | ||
* A `<Router>` for use in web browsers. Provides the cleanest URLs. | ||
*/ | ||
function BrowserRouter({ | ||
basename, | ||
children, | ||
future, | ||
window | ||
}) { | ||
let historyRef = React.useRef(); | ||
if (historyRef.current == null) { | ||
historyRef.current = createBrowserHistory({ | ||
window, | ||
v5Compat: true | ||
}); | ||
} | ||
let history = historyRef.current; | ||
let [state, setStateImpl] = React.useState({ | ||
action: history.action, | ||
location: history.location | ||
}); | ||
let { | ||
v7_startTransition | ||
} = future || {}; | ||
let setState = React.useCallback(newState => { | ||
v7_startTransition && startTransitionImpl ? startTransitionImpl(() => setStateImpl(newState)) : setStateImpl(newState); | ||
}, [setStateImpl, v7_startTransition]); | ||
React.useLayoutEffect(() => history.listen(setState), [history, setState]); | ||
return /*#__PURE__*/React.createElement(Router, { | ||
basename: basename, | ||
children: children, | ||
location: state.location, | ||
navigationType: state.action, | ||
navigator: history, | ||
future: future | ||
}); | ||
} | ||
/** | ||
* A `<Router>` for use in web browsers. Stores the location in the hash | ||
* portion of the URL so it is not sent to the server. | ||
*/ | ||
function HashRouter({ | ||
basename, | ||
children, | ||
future, | ||
window | ||
}) { | ||
let historyRef = React.useRef(); | ||
if (historyRef.current == null) { | ||
historyRef.current = createHashHistory({ | ||
window, | ||
v5Compat: true | ||
}); | ||
} | ||
let history = historyRef.current; | ||
let [state, setStateImpl] = React.useState({ | ||
action: history.action, | ||
location: history.location | ||
}); | ||
let { | ||
v7_startTransition | ||
} = future || {}; | ||
let setState = React.useCallback(newState => { | ||
v7_startTransition && startTransitionImpl ? startTransitionImpl(() => setStateImpl(newState)) : setStateImpl(newState); | ||
}, [setStateImpl, v7_startTransition]); | ||
React.useLayoutEffect(() => history.listen(setState), [history, setState]); | ||
return /*#__PURE__*/React.createElement(Router, { | ||
basename: basename, | ||
children: children, | ||
location: state.location, | ||
navigationType: state.action, | ||
navigator: history, | ||
future: future | ||
}); | ||
} | ||
/** | ||
* A `<Router>` that accepts a pre-instantiated history object. It's important | ||
* to note that using your own history object is highly discouraged and may add | ||
* two versions of the history library to your bundles unless you use the same | ||
* version of the history library that React Router uses internally. | ||
*/ | ||
function HistoryRouter({ | ||
basename, | ||
children, | ||
future, | ||
history | ||
}) { | ||
let [state, setStateImpl] = React.useState({ | ||
action: history.action, | ||
location: history.location | ||
}); | ||
let { | ||
v7_startTransition | ||
} = future || {}; | ||
let setState = React.useCallback(newState => { | ||
v7_startTransition && startTransitionImpl ? startTransitionImpl(() => setStateImpl(newState)) : setStateImpl(newState); | ||
}, [setStateImpl, v7_startTransition]); | ||
React.useLayoutEffect(() => history.listen(setState), [history, setState]); | ||
return /*#__PURE__*/React.createElement(Router, { | ||
basename: basename, | ||
children: children, | ||
location: state.location, | ||
navigationType: state.action, | ||
navigator: history, | ||
future: future | ||
}); | ||
} | ||
{ | ||
HistoryRouter.displayName = "unstable_HistoryRouter"; | ||
} | ||
const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined"; | ||
const ABSOLUTE_URL_REGEX = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i; | ||
/** | ||
* The public API for rendering a history-aware `<a>`. | ||
*/ | ||
const Link = /*#__PURE__*/React.forwardRef(function LinkWithRef({ | ||
onClick, | ||
relative, | ||
reloadDocument, | ||
replace, | ||
state, | ||
target, | ||
to, | ||
preventScrollReset, | ||
unstable_viewTransition, | ||
...rest | ||
}, ref) { | ||
let { | ||
basename | ||
} = React.useContext(UNSAFE_NavigationContext); | ||
// Rendered into <a href> for absolute URLs | ||
let absoluteHref; | ||
let isExternal = false; | ||
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 (isBrowser) { | ||
try { | ||
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; | ||
} | ||
} catch (e) { | ||
// We can't do external URL detection without a valid URL | ||
UNSAFE_warning(false, `<Link to="${to}"> contains an invalid URL which will probably break ` + `when clicked - please update to a valid URL path.`) ; | ||
} | ||
} | ||
} | ||
// Rendered into <a href> for relative URLs | ||
let href = useHref(to, { | ||
relative | ||
}); | ||
let internalOnClick = useLinkClickHandler(to, { | ||
replace, | ||
state, | ||
target, | ||
preventScrollReset, | ||
relative, | ||
unstable_viewTransition | ||
}); | ||
function handleClick(event) { | ||
if (onClick) onClick(event); | ||
if (!event.defaultPrevented) { | ||
internalOnClick(event); | ||
} | ||
} | ||
return ( | ||
/*#__PURE__*/ | ||
// eslint-disable-next-line jsx-a11y/anchor-has-content | ||
React.createElement("a", Object.assign({}, rest, { | ||
href: absoluteHref || href, | ||
onClick: isExternal || reloadDocument ? onClick : handleClick, | ||
ref: ref, | ||
target: target | ||
})) | ||
); | ||
}); | ||
{ | ||
Link.displayName = "Link"; | ||
} | ||
/** | ||
* A `<Link>` wrapper that knows if it's "active" or not. | ||
*/ | ||
const NavLink = /*#__PURE__*/React.forwardRef(function NavLinkWithRef({ | ||
"aria-current": ariaCurrentProp = "page", | ||
caseSensitive = false, | ||
className: classNameProp = "", | ||
end = false, | ||
style: styleProp, | ||
to, | ||
unstable_viewTransition, | ||
children, | ||
...rest | ||
}, ref) { | ||
let path = useResolvedPath(to, { | ||
relative: rest.relative | ||
}); | ||
let location = useLocation(); | ||
let routerState = React.useContext(UNSAFE_DataRouterStateContext); | ||
let { | ||
navigator, | ||
basename | ||
} = React.useContext(UNSAFE_NavigationContext); | ||
let isTransitioning = routerState != null && | ||
// Conditional usage is OK here because the usage of a data router is static | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
useViewTransitionState(path) && unstable_viewTransition === true; | ||
let toPathname = navigator.encodeLocation ? navigator.encodeLocation(path).pathname : path.pathname; | ||
let locationPathname = location.pathname; | ||
let nextLocationPathname = routerState && routerState.navigation && routerState.navigation.location ? routerState.navigation.location.pathname : null; | ||
if (!caseSensitive) { | ||
locationPathname = locationPathname.toLowerCase(); | ||
nextLocationPathname = nextLocationPathname ? nextLocationPathname.toLowerCase() : null; | ||
toPathname = toPathname.toLowerCase(); | ||
} | ||
if (nextLocationPathname && basename) { | ||
nextLocationPathname = stripBasename(nextLocationPathname, basename) || nextLocationPathname; | ||
} | ||
// If the `to` has a trailing slash, look at that exact spot. Otherwise, | ||
// we're looking for a slash _after_ what's in `to`. For example: | ||
// | ||
// <NavLink to="/users"> and <NavLink to="/users/"> | ||
// both want to look for a / at index 6 to match URL `/users/matt` | ||
const endSlashPosition = toPathname !== "/" && toPathname.endsWith("/") ? toPathname.length - 1 : toPathname.length; | ||
let isActive = locationPathname === toPathname || !end && locationPathname.startsWith(toPathname) && locationPathname.charAt(endSlashPosition) === "/"; | ||
let isPending = nextLocationPathname != null && (nextLocationPathname === toPathname || !end && nextLocationPathname.startsWith(toPathname) && nextLocationPathname.charAt(toPathname.length) === "/"); | ||
let renderProps = { | ||
isActive, | ||
isPending, | ||
isTransitioning | ||
}; | ||
let ariaCurrent = isActive ? ariaCurrentProp : undefined; | ||
let className; | ||
if (typeof classNameProp === "function") { | ||
className = classNameProp(renderProps); | ||
} else { | ||
// If the className prop is not a function, we use a default `active` | ||
// class for <NavLink />s that are active. In v5 `active` was the default | ||
// value for `activeClassName`, but we are removing that API and can still | ||
// use the old default behavior for a cleaner upgrade path and keep the | ||
// simple styling rules working as they currently do. | ||
className = [classNameProp, isActive ? "active" : null, isPending ? "pending" : null, isTransitioning ? "transitioning" : null].filter(Boolean).join(" "); | ||
} | ||
let style = typeof styleProp === "function" ? styleProp(renderProps) : styleProp; | ||
return /*#__PURE__*/React.createElement(Link, Object.assign({}, rest, { | ||
"aria-current": ariaCurrent, | ||
className: className, | ||
ref: ref, | ||
style: style, | ||
to: to, | ||
unstable_viewTransition: unstable_viewTransition | ||
}), typeof children === "function" ? children(renderProps) : children); | ||
}); | ||
{ | ||
NavLink.displayName = "NavLink"; | ||
} | ||
/** | ||
* A `@remix-run/router`-aware `<form>`. It behaves like a normal form except | ||
* that the interaction with the server is with `fetch` instead of new document | ||
* requests, allowing components to add nicer UX to the page as the form is | ||
* submitted and returns with data. | ||
*/ | ||
const Form = /*#__PURE__*/React.forwardRef(({ | ||
fetcherKey, | ||
navigate, | ||
reloadDocument, | ||
replace, | ||
state, | ||
method: _method = defaultMethod, | ||
action, | ||
onSubmit, | ||
relative, | ||
preventScrollReset, | ||
unstable_viewTransition, | ||
...props | ||
}, forwardedRef) => { | ||
let submit = useSubmit(); | ||
let formAction = useFormAction(action, { | ||
relative | ||
}); | ||
let formMethod = _method.toLowerCase() === "get" ? "get" : "post"; | ||
let submitHandler = event => { | ||
onSubmit && onSubmit(event); | ||
if (event.defaultPrevented) return; | ||
event.preventDefault(); | ||
let submitter = event.nativeEvent.submitter; | ||
let submitMethod = submitter?.getAttribute("formmethod") || _method; | ||
submit(submitter || event.currentTarget, { | ||
fetcherKey, | ||
method: submitMethod, | ||
navigate, | ||
replace, | ||
state, | ||
relative, | ||
preventScrollReset, | ||
unstable_viewTransition | ||
}); | ||
}; | ||
return /*#__PURE__*/React.createElement("form", Object.assign({ | ||
ref: forwardedRef, | ||
method: formMethod, | ||
action: formAction, | ||
onSubmit: reloadDocument ? onSubmit : submitHandler | ||
}, props)); | ||
}); | ||
{ | ||
Form.displayName = "Form"; | ||
} | ||
/** | ||
* This component will emulate the browser's scroll restoration on location | ||
* changes. | ||
*/ | ||
function ScrollRestoration({ | ||
getKey, | ||
storageKey | ||
}) { | ||
useScrollRestoration({ | ||
getKey, | ||
storageKey | ||
}); | ||
return null; | ||
} | ||
{ | ||
ScrollRestoration.displayName = "ScrollRestoration"; | ||
} | ||
//#endregion | ||
//////////////////////////////////////////////////////////////////////////////// | ||
//#region Hooks | ||
//////////////////////////////////////////////////////////////////////////////// | ||
var DataRouterHook = /*#__PURE__*/function (DataRouterHook) { | ||
DataRouterHook["UseScrollRestoration"] = "useScrollRestoration"; | ||
DataRouterHook["UseSubmit"] = "useSubmit"; | ||
DataRouterHook["UseSubmitFetcher"] = "useSubmitFetcher"; | ||
DataRouterHook["UseFetcher"] = "useFetcher"; | ||
DataRouterHook["useViewTransitionState"] = "useViewTransitionState"; | ||
return DataRouterHook; | ||
}(DataRouterHook || {}); | ||
var DataRouterStateHook = /*#__PURE__*/function (DataRouterStateHook) { | ||
DataRouterStateHook["UseFetcher"] = "useFetcher"; | ||
DataRouterStateHook["UseFetchers"] = "useFetchers"; | ||
DataRouterStateHook["UseScrollRestoration"] = "useScrollRestoration"; | ||
return DataRouterStateHook; | ||
}(DataRouterStateHook || {}); // Internal hooks | ||
function getDataRouterConsoleError(hookName) { | ||
return `${hookName} must be used within a data router. See https://reactrouter.com/routers/picking-a-router.`; | ||
} | ||
function useDataRouterContext(hookName) { | ||
let ctx = React.useContext(UNSAFE_DataRouterContext); | ||
!ctx ? UNSAFE_invariant(false, getDataRouterConsoleError(hookName)) : void 0; | ||
return ctx; | ||
} | ||
function useDataRouterState(hookName) { | ||
let state = React.useContext(UNSAFE_DataRouterStateContext); | ||
!state ? UNSAFE_invariant(false, getDataRouterConsoleError(hookName)) : void 0; | ||
return state; | ||
} | ||
// External hooks | ||
/** | ||
* Handles the click behavior for router `<Link>` components. This is useful if | ||
* you need to create custom `<Link>` components with the same click behavior we | ||
* use in our exported `<Link>`. | ||
*/ | ||
function useLinkClickHandler(to, { | ||
target, | ||
replace: replaceProp, | ||
state, | ||
preventScrollReset, | ||
relative, | ||
unstable_viewTransition | ||
} = {}) { | ||
let navigate = useNavigate(); | ||
let location = useLocation(); | ||
let path = useResolvedPath(to, { | ||
relative | ||
}); | ||
return React.useCallback(event => { | ||
if (shouldProcessLinkClick(event, target)) { | ||
event.preventDefault(); | ||
// If the URL hasn't changed, a regular <a> will do a replace instead of | ||
// a push, so do the same here unless the replace prop is explicitly set | ||
let replace = replaceProp !== undefined ? replaceProp : createPath(location) === createPath(path); | ||
navigate(to, { | ||
replace, | ||
state, | ||
preventScrollReset, | ||
relative, | ||
unstable_viewTransition | ||
}); | ||
} | ||
}, [location, navigate, path, replaceProp, state, target, to, preventScrollReset, relative, unstable_viewTransition]); | ||
} | ||
/** | ||
* A convenient wrapper for reading and writing search parameters via the | ||
* URLSearchParams interface. | ||
*/ | ||
function useSearchParams(defaultInit) { | ||
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)); | ||
let hasSetSearchParamsRef = React.useRef(false); | ||
let location = useLocation(); | ||
let searchParams = React.useMemo(() => | ||
// Only merge in the defaults if we haven't yet called setSearchParams. | ||
// Once we call that we want those to take precedence, otherwise you can't | ||
// remove a param with setSearchParams({}) if it has an initial value | ||
getSearchParamsForLocation(location.search, hasSetSearchParamsRef.current ? null : defaultSearchParamsRef.current), [location.search]); | ||
let navigate = useNavigate(); | ||
let setSearchParams = React.useCallback((nextInit, navigateOptions) => { | ||
const newSearchParams = createSearchParams(typeof nextInit === "function" ? nextInit(searchParams) : nextInit); | ||
hasSetSearchParamsRef.current = true; | ||
navigate("?" + newSearchParams, navigateOptions); | ||
}, [navigate, searchParams]); | ||
return [searchParams, setSearchParams]; | ||
} | ||
/** | ||
* Submits a HTML `<form>` to the server without reloading the page. | ||
*/ | ||
/** | ||
* Submits a fetcher `<form>` to the server without reloading the page. | ||
*/ | ||
function validateClientSideSubmission() { | ||
if (typeof document === "undefined") { | ||
throw new Error("You are calling submit during the server render. " + "Try calling submit within a `useEffect` or callback instead."); | ||
} | ||
} | ||
let fetcherId = 0; | ||
let getUniqueFetcherId = () => `__${String(++fetcherId)}__`; | ||
/** | ||
* Returns a function that may be used to programmatically submit a form (or | ||
* some arbitrary data) to the server. | ||
*/ | ||
function useSubmit() { | ||
let { | ||
router | ||
} = useDataRouterContext(DataRouterHook.UseSubmit); | ||
let { | ||
basename | ||
} = React.useContext(UNSAFE_NavigationContext); | ||
let currentRouteId = UNSAFE_useRouteId(); | ||
return React.useCallback((target, options = {}) => { | ||
validateClientSideSubmission(); | ||
let { | ||
action, | ||
method, | ||
encType, | ||
formData, | ||
body | ||
} = getFormSubmissionInfo(target, basename); | ||
if (options.navigate === false) { | ||
let key = options.fetcherKey || getUniqueFetcherId(); | ||
router.fetch(key, currentRouteId, options.action || action, { | ||
preventScrollReset: options.preventScrollReset, | ||
formData, | ||
body, | ||
formMethod: options.method || method, | ||
formEncType: options.encType || encType, | ||
unstable_flushSync: options.unstable_flushSync | ||
}); | ||
} else { | ||
router.navigate(options.action || action, { | ||
preventScrollReset: options.preventScrollReset, | ||
formData, | ||
body, | ||
formMethod: options.method || method, | ||
formEncType: options.encType || encType, | ||
replace: options.replace, | ||
state: options.state, | ||
fromRouteId: currentRouteId, | ||
unstable_flushSync: options.unstable_flushSync, | ||
unstable_viewTransition: options.unstable_viewTransition | ||
}); | ||
} | ||
}, [router, basename, currentRouteId]); | ||
} | ||
// v7: Eventually we should deprecate this entirely in favor of using the | ||
// router method directly? | ||
function useFormAction(action, { | ||
relative | ||
} = {}) { | ||
let { | ||
basename | ||
} = React.useContext(UNSAFE_NavigationContext); | ||
let routeContext = React.useContext(UNSAFE_RouteContext); | ||
!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 | ||
// object referenced by useMemo inside useResolvedPath | ||
let path = { | ||
...useResolvedPath(action ? action : ".", { | ||
relative | ||
}) | ||
}; | ||
// If no action was specified, browsers will persist current search params | ||
// when determining the path, so match that behavior | ||
// https://github.com/remix-run/remix/issues/927 | ||
let location = useLocation(); | ||
if (action == null) { | ||
// Safe to write to this directly here since if action was undefined, we | ||
// would have called useResolvedPath(".") which will never include a search | ||
path.search = location.search; | ||
// When grabbing search params from the URL, remove any included ?index param | ||
// since it might not apply to our contextual route. We add it back based | ||
// on match.route.index below | ||
let params = new URLSearchParams(path.search); | ||
if (params.has("index") && params.get("index") === "") { | ||
params.delete("index"); | ||
path.search = params.toString() ? `?${params.toString()}` : ""; | ||
} | ||
} | ||
if ((!action || action === ".") && match.route.index) { | ||
path.search = path.search ? path.search.replace(/^\?/, "?index&") : "?index"; | ||
} | ||
// If we're operating within a basename, prepend it to the pathname prior | ||
// to creating the form action. If this is a root navigation, then just use | ||
// the raw basename which allows the basename to have full control over the | ||
// presence of a trailing slash on root actions | ||
if (basename !== "/") { | ||
path.pathname = path.pathname === "/" ? basename : joinPaths([basename, path.pathname]); | ||
} | ||
return createPath(path); | ||
} | ||
// TODO: (v7) Change the useFetcher generic default from `any` to `unknown` | ||
/** | ||
* Interacts with route loaders and actions without causing a navigation. Great | ||
* for any interaction that stays on the same page. | ||
*/ | ||
function useFetcher({ | ||
key | ||
} = {}) { | ||
let { | ||
router | ||
} = useDataRouterContext(DataRouterHook.UseFetcher); | ||
let state = useDataRouterState(DataRouterStateHook.UseFetcher); | ||
let fetcherData = React.useContext(FetchersContext); | ||
let route = React.useContext(UNSAFE_RouteContext); | ||
let routeId = route.matches[route.matches.length - 1]?.route.id; | ||
!fetcherData ? UNSAFE_invariant(false, `useFetcher must be used inside a FetchersContext`) : void 0; | ||
!route ? UNSAFE_invariant(false, `useFetcher must be used inside a RouteContext`) : void 0; | ||
!(routeId != null) ? UNSAFE_invariant(false, `useFetcher can only be used on routes that contain a unique "id"`) : void 0; | ||
// Fetcher key handling | ||
// OK to call conditionally to feature detect `useId` | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
let defaultKey = useIdImpl ? useIdImpl() : ""; | ||
let [fetcherKey, setFetcherKey] = React.useState(key || defaultKey); | ||
if (key && key !== fetcherKey) { | ||
setFetcherKey(key); | ||
} else if (!fetcherKey) { | ||
// We will only fall through here when `useId` is not available | ||
setFetcherKey(getUniqueFetcherId()); | ||
} | ||
// Registration/cleanup | ||
React.useEffect(() => { | ||
router.getFetcher(fetcherKey); | ||
return () => { | ||
// Tell the router we've unmounted - if v7_fetcherPersist is enabled this | ||
// will not delete immediately but instead queue up a delete after the | ||
// fetcher returns to an `idle` state | ||
router.deleteFetcher(fetcherKey); | ||
}; | ||
}, [router, fetcherKey]); | ||
// Fetcher additions | ||
let load = React.useCallback((href, opts) => { | ||
!routeId ? UNSAFE_invariant(false, "No routeId available for fetcher.load()") : void 0; | ||
router.fetch(fetcherKey, routeId, href, opts); | ||
}, [fetcherKey, routeId, router]); | ||
let submitImpl = useSubmit(); | ||
let submit = React.useCallback((target, opts) => { | ||
submitImpl(target, { | ||
...opts, | ||
navigate: false, | ||
fetcherKey | ||
}); | ||
}, [fetcherKey, submitImpl]); | ||
let FetcherForm = React.useMemo(() => { | ||
let FetcherForm = /*#__PURE__*/React.forwardRef((props, ref) => { | ||
return /*#__PURE__*/React.createElement(Form, Object.assign({}, props, { | ||
navigate: false, | ||
fetcherKey: fetcherKey, | ||
ref: ref | ||
})); | ||
}); | ||
{ | ||
FetcherForm.displayName = "fetcher.Form"; | ||
} | ||
return FetcherForm; | ||
}, [fetcherKey]); | ||
// Exposed FetcherWithComponents | ||
let fetcher = state.fetchers.get(fetcherKey) || IDLE_FETCHER; | ||
let data = fetcherData.get(fetcherKey); | ||
let fetcherWithComponents = React.useMemo(() => ({ | ||
Form: FetcherForm, | ||
submit, | ||
load, | ||
...fetcher, | ||
data | ||
}), [FetcherForm, submit, load, fetcher, data]); | ||
return fetcherWithComponents; | ||
} | ||
/** | ||
* Provides all fetchers currently on the page. Useful for layouts and parent | ||
* routes that need to provide pending/optimistic UI regarding the fetch. | ||
*/ | ||
function useFetchers() { | ||
let state = useDataRouterState(DataRouterStateHook.UseFetchers); | ||
return Array.from(state.fetchers.entries()).map(([key, fetcher]) => ({ | ||
...fetcher, | ||
key | ||
})); | ||
} | ||
const SCROLL_RESTORATION_STORAGE_KEY = "react-router-scroll-positions"; | ||
let savedScrollPositions = {}; | ||
/** | ||
* When rendered inside a RouterProvider, will restore scroll positions on navigations | ||
*/ | ||
function useScrollRestoration({ | ||
getKey, | ||
storageKey | ||
} = {}) { | ||
let { | ||
router | ||
} = useDataRouterContext(DataRouterHook.UseScrollRestoration); | ||
let { | ||
restoreScrollPosition, | ||
preventScrollReset | ||
} = useDataRouterState(DataRouterStateHook.UseScrollRestoration); | ||
let { | ||
basename | ||
} = React.useContext(UNSAFE_NavigationContext); | ||
let location = useLocation(); | ||
let matches = useMatches(); | ||
let navigation = useNavigation(); | ||
// Trigger manual scroll restoration while we're active | ||
React.useEffect(() => { | ||
window.history.scrollRestoration = "manual"; | ||
return () => { | ||
window.history.scrollRestoration = "auto"; | ||
}; | ||
}, []); | ||
// Save positions on pagehide | ||
usePageHide(React.useCallback(() => { | ||
if (navigation.state === "idle") { | ||
let key = (getKey ? getKey(location, matches) : null) || location.key; | ||
savedScrollPositions[key] = window.scrollY; | ||
} | ||
try { | ||
sessionStorage.setItem(storageKey || SCROLL_RESTORATION_STORAGE_KEY, JSON.stringify(savedScrollPositions)); | ||
} catch (error) { | ||
UNSAFE_warning(false, `Failed to save scroll positions in sessionStorage, <ScrollRestoration /> will not work properly (${error}).`) ; | ||
} | ||
window.history.scrollRestoration = "auto"; | ||
}, [storageKey, getKey, navigation.state, location, matches])); | ||
// Read in any saved scroll locations | ||
if (typeof document !== "undefined") { | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
React.useLayoutEffect(() => { | ||
try { | ||
let sessionPositions = sessionStorage.getItem(storageKey || SCROLL_RESTORATION_STORAGE_KEY); | ||
if (sessionPositions) { | ||
savedScrollPositions = JSON.parse(sessionPositions); | ||
} | ||
} catch (e) { | ||
// no-op, use default empty object | ||
} | ||
}, [storageKey]); | ||
// Enable scroll restoration in the router | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
React.useLayoutEffect(() => { | ||
let getKeyWithoutBasename = getKey && basename !== "/" ? (location, matches) => getKey( | ||
// Strip the basename to match useLocation() | ||
{ | ||
...location, | ||
pathname: stripBasename(location.pathname, basename) || location.pathname | ||
}, matches) : getKey; | ||
let disableScrollRestoration = router?.enableScrollRestoration(savedScrollPositions, () => window.scrollY, getKeyWithoutBasename); | ||
return () => disableScrollRestoration && disableScrollRestoration(); | ||
}, [router, basename, getKey]); | ||
// Restore scrolling when state.restoreScrollPosition changes | ||
// eslint-disable-next-line react-hooks/rules-of-hooks | ||
React.useLayoutEffect(() => { | ||
// Explicit false means don't do anything (used for submissions) | ||
if (restoreScrollPosition === false) { | ||
return; | ||
} | ||
// been here before, scroll to it | ||
if (typeof restoreScrollPosition === "number") { | ||
window.scrollTo(0, restoreScrollPosition); | ||
return; | ||
} | ||
// try to scroll to the hash | ||
if (location.hash) { | ||
let el = document.getElementById(decodeURIComponent(location.hash.slice(1))); | ||
if (el) { | ||
el.scrollIntoView(); | ||
return; | ||
} | ||
} | ||
// Don't reset if this navigation opted out | ||
if (preventScrollReset === true) { | ||
return; | ||
} | ||
// otherwise go to the top on new locations | ||
window.scrollTo(0, 0); | ||
}, [location, restoreScrollPosition, preventScrollReset]); | ||
} | ||
} | ||
/** | ||
* Setup a callback to be fired on the window's `beforeunload` event. This is | ||
* useful for saving some data to `window.localStorage` just before the page | ||
* refreshes. | ||
* | ||
* Note: The `callback` argument should be a function created with | ||
* `React.useCallback()`. | ||
*/ | ||
function useBeforeUnload(callback, options) { | ||
let { | ||
capture | ||
} = options || {}; | ||
React.useEffect(() => { | ||
let opts = capture != null ? { | ||
capture | ||
} : undefined; | ||
window.addEventListener("beforeunload", callback, opts); | ||
return () => { | ||
window.removeEventListener("beforeunload", callback, opts); | ||
}; | ||
}, [callback, capture]); | ||
} | ||
/** | ||
* Setup a callback to be fired on the window's `pagehide` event. This is | ||
* useful for saving some data to `window.localStorage` just before the page | ||
* refreshes. This event is better supported than beforeunload across browsers. | ||
* | ||
* Note: The `callback` argument should be a function created with | ||
* `React.useCallback()`. | ||
*/ | ||
function usePageHide(callback, options) { | ||
let { | ||
capture | ||
} = options || {}; | ||
React.useEffect(() => { | ||
let opts = capture != null ? { | ||
capture | ||
} : undefined; | ||
window.addEventListener("pagehide", callback, opts); | ||
return () => { | ||
window.removeEventListener("pagehide", callback, opts); | ||
}; | ||
}, [callback, capture]); | ||
} | ||
/** | ||
* Wrapper around useBlocker to show a window.confirm prompt to users instead | ||
* of building a custom UI with useBlocker. | ||
* | ||
* Warning: This has *a lot of rough edges* and behaves very differently (and | ||
* very incorrectly in some cases) across browsers if user click addition | ||
* back/forward navigations while the confirm is open. Use at your own risk. | ||
*/ | ||
function usePrompt({ | ||
when, | ||
message | ||
}) { | ||
let blocker = useBlocker(when); | ||
React.useEffect(() => { | ||
if (blocker.state === "blocked") { | ||
let proceed = window.confirm(message); | ||
if (proceed) { | ||
// This timeout is needed to avoid a weird "race" on POP navigations | ||
// between the `window.history` revert navigation and the result of | ||
// `window.confirm` | ||
setTimeout(blocker.proceed, 0); | ||
} else { | ||
blocker.reset(); | ||
} | ||
} | ||
}, [blocker, message]); | ||
React.useEffect(() => { | ||
if (blocker.state === "blocked" && !when) { | ||
blocker.reset(); | ||
} | ||
}, [blocker, when]); | ||
} | ||
/** | ||
* Return a boolean indicating if there is an active view transition to the | ||
* given href. You can use this value to render CSS classes or viewTransitionName | ||
* styles onto your elements | ||
* | ||
* @param href The destination href | ||
* @param [opts.relative] Relative routing type ("route" | "path") | ||
*/ | ||
function useViewTransitionState(to, opts = {}) { | ||
let vtContext = React.useContext(ViewTransitionContext); | ||
!(vtContext != null) ? UNSAFE_invariant(false, "`unstable_useViewTransitionState` must be used within `react-router-dom`'s `RouterProvider`. " + "Did you accidentally import `RouterProvider` from `react-router`?") : void 0; | ||
let { | ||
basename | ||
} = useDataRouterContext(DataRouterHook.useViewTransitionState); | ||
let path = useResolvedPath(to, { | ||
relative: opts.relative | ||
}); | ||
if (!vtContext.isTransitioning) { | ||
return false; | ||
} | ||
let currentPath = stripBasename(vtContext.currentLocation.pathname, basename) || vtContext.currentLocation.pathname; | ||
let nextPath = stripBasename(vtContext.nextLocation.pathname, basename) || vtContext.nextLocation.pathname; | ||
// Transition is active if we're going to or coming from the indicated | ||
// destination. This ensures that other PUSH navigations that reverse | ||
// an indicated transition apply. I.e., on the list view you have: | ||
// | ||
// <NavLink to="/details/1" unstable_viewTransition> | ||
// | ||
// If you click the breadcrumb back to the list view: | ||
// | ||
// <NavLink to="/list" unstable_viewTransition> | ||
// | ||
// We should apply the transition because it's indicated as active going | ||
// from /list -> /details/1 and therefore should be active on the reverse | ||
// (even though this isn't strictly a POP reverse) | ||
return matchPath(path.pathname, nextPath) != null || matchPath(path.pathname, currentPath) != null; | ||
} | ||
//#endregion | ||
export { BrowserRouter, Form, HashRouter, Link, NavLink, RouterProvider, ScrollRestoration, FetchersContext as UNSAFE_FetchersContext, ViewTransitionContext as UNSAFE_ViewTransitionContext, useScrollRestoration as UNSAFE_useScrollRestoration, createBrowserRouter, createHashRouter, createSearchParams, HistoryRouter as unstable_HistoryRouter, usePrompt as unstable_usePrompt, useViewTransitionState as unstable_useViewTransitionState, useBeforeUnload, useFetcher, useFetchers, useFormAction, useLinkClickHandler, useSearchParams, useSubmit }; | ||
export * from 'react-router'; | ||
//# sourceMappingURL=react-router-dom.development.js.map |
/** | ||
* React Router DOM v0.0.0-experimental-edf416237 | ||
* React Router DOM v0.0.0-experimental-f042b8c1e | ||
* | ||
@@ -11,3 +11,3 @@ * Copyright (c) Remix Software Inc. | ||
*/ | ||
import*as e from"react";import*as t from"react-dom";import{UNSAFE_mapRouteProperties as n,UNSAFE_DataRouterContext as r,UNSAFE_DataRouterStateContext as a,Router as o,UNSAFE_useRoutesImpl as i,UNSAFE_NavigationContext as s,useHref as u,useResolvedPath as l,useLocation as c,useNavigate as f,createPath as d,UNSAFE_useRouteId as m,UNSAFE_RouteContext as h,useMatches as p,useNavigation as w,useBlocker as v}from"react-router";export{AbortedDeferredError,Await,MemoryRouter,Navigate,NavigationType,Outlet,Route,Router,Routes,UNSAFE_DataRouterContext,UNSAFE_DataRouterStateContext,UNSAFE_LocationContext,UNSAFE_NavigationContext,UNSAFE_RouteContext,UNSAFE_useRouteId,createMemoryRouter,createPath,createRoutesFromChildren,createRoutesFromElements,defer,generatePath,isRouteErrorResponse,json,matchPath,matchRoutes,parsePath,redirect,redirectDocument,renderMatches,resolvePath,useActionData,useAsyncError,useAsyncValue,useBlocker,useHref,useInRouterContext,useLoaderData,useLocation,useMatch,useMatches,useNavigate,useNavigation,useNavigationType,useOutlet,useOutletContext,useParams,useResolvedPath,useRevalidator,useRouteError,useRouteLoaderData,useRoutes}from"react-router";import{stripBasename as g,createRouter as y,createBrowserHistory as b,createHashHistory as S,UNSAFE_ErrorResponseImpl as R,UNSAFE_invariant as E,joinPaths as _,IDLE_FETCHER as T,matchPath as L}from"@remix-run/router";export{UNSAFE_ErrorResponseImpl}from"@remix-run/router";const x="application/x-www-form-urlencoded";function C(e){return null!=e&&"string"==typeof e.tagName}function A(e=""){return new URLSearchParams("string"==typeof e||Array.isArray(e)||e instanceof URLSearchParams?e:Object.keys(e).reduce(((t,n)=>{let r=e[n];return t.concat(Array.isArray(r)?r.map((e=>[n,e])):[[n,r]])}),[]))}let F=null;const U=new Set(["application/x-www-form-urlencoded","multipart/form-data","text/plain"]);function k(e){return null==e||U.has(e)?e:null}function N(e,t){let n,r,a,o,i;if(C(s=e)&&"form"===s.tagName.toLowerCase()){let i=e.getAttribute("action");r=i?g(i,t):null,n=e.getAttribute("method")||"get",a=k(e.getAttribute("enctype"))||x,o=new FormData(e)}else if(function(e){return C(e)&&"button"===e.tagName.toLowerCase()}(e)||function(e){return C(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>');let s=e.getAttribute("formaction")||i.getAttribute("action");if(r=s?g(s,t):null,n=e.getAttribute("formmethod")||i.getAttribute("method")||"get",a=k(e.getAttribute("formenctype"))||k(i.getAttribute("enctype"))||x,o=new FormData(i,e),!function(){if(null===F)try{new FormData(document.createElement("form"),0),F=!1}catch(e){F=!0}return F}()){let{name:t,type:n,value:r}=e;if("image"===n){let e=t?`${t}.`:"";o.append(`${e}x`,"0"),o.append(`${e}y`,"0")}else t&&o.append(t,r)}}else{if(C(e))throw new Error('Cannot submit element that is not <form>, <button>, or <input type="submit|image">');n="get",r=null,a=x,i=e}var s;return o&&"text/plain"===a&&(i=o,o=void 0),{action:r,method:n.toLowerCase(),encType:a,formData:o,body:i}}try{window.__reactRouterVersion="0"}catch(ye){}function P(e,t){return y({basename:t?.basename,future:{...t?.future,v7_prependBasename:!0},history:b({window:t?.window}),hydrationData:t?.hydrationData||M(),routes:e,mapRouteProperties:n,unstable_dataStrategy:t?.unstable_dataStrategy,unstable_patchRoutesOnMiss:t?.unstable_patchRoutesOnMiss,window:t?.window}).initialize()}function D(e,t){return y({basename:t?.basename,future:{...t?.future,v7_prependBasename:!0},history:S({window:t?.window}),hydrationData:t?.hydrationData||M(),routes:e,mapRouteProperties:n,unstable_dataStrategy:t?.unstable_dataStrategy,unstable_patchRoutesOnMiss:t?.unstable_patchRoutesOnMiss,window:t?.window}).initialize()}function M(){let e=window?.__staticRouterHydrationData;return e&&e.errors&&(e={...e,errors:O(e.errors)}),e}function O(e){if(!e)return null;let t=Object.entries(e),n={};for(let[r,a]of t)if(a&&"RouteErrorResponse"===a.__type)n[r]=new R(a.status,a.statusText,a.data,!0===a.internal);else if(a&&"Error"===a.__type){if(a.__subType){let e=window[a.__subType];if("function"==typeof e)try{let t=new e(a.message);t.stack="",n[r]=t}catch(ye){}}if(null==n[r]){let e=new Error(a.message);e.stack="",n[r]=e}}else n[r]=a;return n}const K=e.createContext({isTransitioning:!1}),V=e.createContext(new Map),j=e.startTransition,I=t.flushSync,H=e.useId;function z(e){I?I(e):e()}class B{status="pending";constructor(){this.promise=new Promise(((e,t)=>{this.resolve=t=>{"pending"===this.status&&(this.status="resolved",e(t))},this.reject=e=>{"pending"===this.status&&(this.status="rejected",t(e))}}))}}function $({fallbackElement:t,router:n,future:i}){let[s,u]=e.useState(n.state),[l,c]=e.useState(),[f,d]=e.useState({isTransitioning:!1}),[m,h]=e.useState(),[p,w]=e.useState(),[v,g]=e.useState(),y=e.useRef(new Map),{v7_startTransition:b}=i||{},S=e.useCallback((e=>{b?function(e){j?j(e):e()}(e):e()}),[b]),R=e.useCallback(((e,{deletedFetchers:t,unstable_flushSync:r,unstable_viewTransitionOpts:a})=>{t.forEach((e=>y.current.delete(e))),e.fetchers.forEach(((e,t)=>{void 0!==e.data&&y.current.set(t,e.data)}));let o=null==n.window||null==n.window.document||"function"!=typeof n.window.document.startViewTransition;if(a&&!o){if(r){z((()=>{p&&(m&&m.resolve(),p.skipTransition()),d({isTransitioning:!0,flushSync:!0,currentLocation:a.currentLocation,nextLocation:a.nextLocation})}));let t=n.window.document.startViewTransition((()=>{z((()=>u(e)))}));return t.finished.finally((()=>{z((()=>{h(void 0),w(void 0),c(void 0),d({isTransitioning:!1})}))})),void z((()=>w(t)))}p?(m&&m.resolve(),p.skipTransition(),g({state:e,currentLocation:a.currentLocation,nextLocation:a.nextLocation})):(c(e),d({isTransitioning:!0,flushSync:!1,currentLocation:a.currentLocation,nextLocation:a.nextLocation}))}else r?z((()=>u(e))):S((()=>u(e)))}),[n.window,p,m,y,S]);e.useLayoutEffect((()=>n.subscribe(R)),[n,R]),e.useEffect((()=>{f.isTransitioning&&!f.flushSync&&h(new B)}),[f]),e.useEffect((()=>{if(m&&l&&n.window){let e=l,t=m.promise,r=n.window.document.startViewTransition((async()=>{S((()=>u(e))),await t}));r.finished.finally((()=>{h(void 0),w(void 0),c(void 0),d({isTransitioning:!1})})),w(r)}}),[S,l,m,n.window]),e.useEffect((()=>{m&&l&&s.location.key===l.location.key&&m.resolve()}),[m,p,s.location,l]),e.useEffect((()=>{!f.isTransitioning&&v&&(c(v.state),d({isTransitioning:!0,flushSync:!1,currentLocation:v.currentLocation,nextLocation:v.nextLocation}),g(void 0))}),[f.isTransitioning,v]),e.useEffect((()=>{}),[]);let E=e.useMemo((()=>({createHref:n.createHref,encodeLocation:n.encodeLocation,go:e=>n.navigate(e),push:(e,t,r)=>n.navigate(e,{state:t,preventScrollReset:r?.preventScrollReset}),replace:(e,t,r)=>n.navigate(e,{replace:!0,state:t,preventScrollReset:r?.preventScrollReset})})),[n]),_=n.basename||"/",T=e.useMemo((()=>({router:n,navigator:E,static:!1,basename:_})),[n,E,_]);return e.createElement(e.Fragment,null,e.createElement(r.Provider,{value:T},e.createElement(a.Provider,{value:s},e.createElement(V.Provider,{value:y.current},e.createElement(K.Provider,{value:f},e.createElement(o,{basename:_,location:s.location,navigationType:s.historyAction,navigator:E,future:{v7_relativeSplatPath:n.future.v7_relativeSplatPath}},s.initialized||n.future.v7_partialHydration?e.createElement(W,{routes:n.routes,future:n.future,state:s}):t))))),null)}function W({routes:e,future:t,state:n}){return i(e,void 0,n,t)}function Y({basename:t,children:n,future:r,window:a}){let i=e.useRef();null==i.current&&(i.current=b({window:a,v5Compat:!0}));let s=i.current,[u,l]=e.useState({action:s.action,location:s.location}),{v7_startTransition:c}=r||{},f=e.useCallback((e=>{c&&j?j((()=>l(e))):l(e)}),[l,c]);return e.useLayoutEffect((()=>s.listen(f)),[s,f]),e.createElement(o,{basename:t,children:n,location:u.location,navigationType:u.action,navigator:s,future:r})}function J({basename:t,children:n,future:r,window:a}){let i=e.useRef();null==i.current&&(i.current=S({window:a,v5Compat:!0}));let s=i.current,[u,l]=e.useState({action:s.action,location:s.location}),{v7_startTransition:c}=r||{},f=e.useCallback((e=>{c&&j?j((()=>l(e))):l(e)}),[l,c]);return e.useLayoutEffect((()=>s.listen(f)),[s,f]),e.createElement(o,{basename:t,children:n,location:u.location,navigationType:u.action,navigator:s,future:r})}function q({basename:t,children:n,future:r,history:a}){let[i,s]=e.useState({action:a.action,location:a.location}),{v7_startTransition:u}=r||{},l=e.useCallback((e=>{u&&j?j((()=>s(e))):s(e)}),[s,u]);return e.useLayoutEffect((()=>a.listen(l)),[a,l]),e.createElement(o,{basename:t,children:n,location:i.location,navigationType:i.action,navigator:a,future:r})}const G="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,Q=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,X=e.forwardRef((function({onClick:t,relative:n,reloadDocument:r,replace:a,state:o,target:i,to:l,preventScrollReset:c,unstable_viewTransition:f,...d},m){let h,{basename:p}=e.useContext(s),w=!1;if("string"==typeof l&&Q.test(l)&&(h=l,G))try{let e=new URL(window.location.href),t=l.startsWith("//")?new URL(e.protocol+l):new URL(l),n=g(t.pathname,p);t.origin===e.origin&&null!=n?l=n+t.search+t.hash:w=!0}catch(ye){}let v=u(l,{relative:n}),y=ie(l,{replace:a,state:o,target:i,preventScrollReset:c,relative:n,unstable_viewTransition:f});return e.createElement("a",Object.assign({},d,{href:h||v,onClick:w||r?t:function(e){t&&t(e),e.defaultPrevented||y(e)},ref:m,target:i}))})),Z=e.forwardRef((function({"aria-current":t="page",caseSensitive:n=!1,className:r="",end:o=!1,style:i,to:u,unstable_viewTransition:f,children:d,...m},h){let p=l(u,{relative:m.relative}),w=c(),v=e.useContext(a),{navigator:y,basename:b}=e.useContext(s),S=null!=v&&ge(p)&&!0===f,R=y.encodeLocation?y.encodeLocation(p).pathname:p.pathname,E=w.pathname,_=v&&v.navigation&&v.navigation.location?v.navigation.location.pathname:null;n||(E=E.toLowerCase(),_=_?_.toLowerCase():null,R=R.toLowerCase()),_&&b&&(_=g(_,b)||_);const T="/"!==R&&R.endsWith("/")?R.length-1:R.length;let L,x=E===R||!o&&E.startsWith(R)&&"/"===E.charAt(T),C=null!=_&&(_===R||!o&&_.startsWith(R)&&"/"===_.charAt(R.length)),A={isActive:x,isPending:C,isTransitioning:S},F=x?t:void 0;L="function"==typeof r?r(A):[r,x?"active":null,C?"pending":null,S?"transitioning":null].filter(Boolean).join(" ");let U="function"==typeof i?i(A):i;return e.createElement(X,Object.assign({},m,{"aria-current":F,className:L,ref:h,style:U,to:u,unstable_viewTransition:f}),"function"==typeof d?d(A):d)})),ee=e.forwardRef((({fetcherKey:t,navigate:n,reloadDocument:r,replace:a,state:o,method:i="get",action:s,onSubmit:u,relative:l,preventScrollReset:c,unstable_viewTransition:f,...d},m)=>{let h=ce(),p=fe(s,{relative:l}),w="get"===i.toLowerCase()?"get":"post";return e.createElement("form",Object.assign({ref:m,method:w,action:p,onSubmit:r?u:e=>{if(u&&u(e),e.defaultPrevented)return;e.preventDefault();let r=e.nativeEvent.submitter,s=r?.getAttribute("formmethod")||i;h(r||e.currentTarget,{fetcherKey:t,method:s,navigate:n,replace:a,state:o,relative:l,preventScrollReset:c,unstable_viewTransition:f})}},d))}));function te({getKey:e,storageKey:t}){return pe({getKey:e,storageKey:t}),null}var ne=function(e){return e.UseScrollRestoration="useScrollRestoration",e.UseSubmit="useSubmit",e.UseSubmitFetcher="useSubmitFetcher",e.UseFetcher="useFetcher",e.useViewTransitionState="useViewTransitionState",e}(ne||{}),re=function(e){return e.UseFetcher="useFetcher",e.UseFetchers="useFetchers",e.UseScrollRestoration="useScrollRestoration",e}(re||{});function ae(t){let n=e.useContext(r);return n||E(!1),n}function oe(t){let n=e.useContext(a);return n||E(!1),n}function ie(t,{target:n,replace:r,state:a,preventScrollReset:o,relative:i,unstable_viewTransition:s}={}){let u=f(),m=c(),h=l(t,{relative:i});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,n)){e.preventDefault();let n=void 0!==r?r:d(m)===d(h);u(t,{replace:n,state:a,preventScrollReset:o,relative:i,unstable_viewTransition:s})}}),[m,u,h,r,a,n,t,o,i,s])}function se(t){let n=e.useRef(A(t)),r=e.useRef(!1),a=c(),o=e.useMemo((()=>function(e,t){let n=A(e);return t&&t.forEach(((e,r)=>{n.has(r)||t.getAll(r).forEach((e=>{n.append(r,e)}))})),n}(a.search,r.current?null:n.current)),[a.search]),i=f(),s=e.useCallback(((e,t)=>{const n=A("function"==typeof e?e(o):e);r.current=!0,i("?"+n,t)}),[i,o]);return[o,s]}let ue=0,le=()=>`__${String(++ue)}__`;function ce(){let{router:t}=ae(ne.UseSubmit),{basename:n}=e.useContext(s),r=m();return e.useCallback(((e,a={})=>{!function(){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{action:o,method:i,encType:s,formData:u,body:l}=N(e,n);if(!1===a.navigate){let e=a.fetcherKey||le();t.fetch(e,r,a.action||o,{preventScrollReset:a.preventScrollReset,formData:u,body:l,formMethod:a.method||i,formEncType:a.encType||s,unstable_flushSync:a.unstable_flushSync})}else t.navigate(a.action||o,{preventScrollReset:a.preventScrollReset,formData:u,body:l,formMethod:a.method||i,formEncType:a.encType||s,replace:a.replace,state:a.state,fromRouteId:r,unstable_flushSync:a.unstable_flushSync,unstable_viewTransition:a.unstable_viewTransition})}),[t,n,r])}function fe(t,{relative:n}={}){let{basename:r}=e.useContext(s),a=e.useContext(h);a||E(!1);let[o]=a.matches.slice(-1),i={...l(t||".",{relative:n})},u=c();if(null==t){i.search=u.search;let e=new URLSearchParams(i.search);e.has("index")&&""===e.get("index")&&(e.delete("index"),i.search=e.toString()?`?${e.toString()}`:"")}return t&&"."!==t||!o.route.index||(i.search=i.search?i.search.replace(/^\?/,"?index&"):"?index"),"/"!==r&&(i.pathname="/"===i.pathname?r:_([r,i.pathname])),d(i)}function de({key:t}={}){let{router:n}=ae(ne.UseFetcher),r=oe(re.UseFetcher),a=e.useContext(V),o=e.useContext(h),i=o.matches[o.matches.length-1]?.route.id;a||E(!1),o||E(!1),null==i&&E(!1);let s=H?H():"",[u,l]=e.useState(t||s);t&&t!==u?l(t):u||l(le()),e.useEffect((()=>(n.getFetcher(u),()=>{n.deleteFetcher(u)})),[n,u]);let c=e.useCallback(((e,t)=>{i||E(!1),n.fetch(u,i,e,t)}),[u,i,n]),f=ce(),d=e.useCallback(((e,t)=>{f(e,{...t,navigate:!1,fetcherKey:u})}),[u,f]),m=e.useMemo((()=>e.forwardRef(((t,n)=>e.createElement(ee,Object.assign({},t,{navigate:!1,fetcherKey:u,ref:n}))))),[u]),p=r.fetchers.get(u)||T,w=a.get(u);return e.useMemo((()=>({Form:m,submit:d,load:c,...p,data:w})),[m,d,c,p,w])}function me(){let e=oe(re.UseFetchers);return Array.from(e.fetchers.entries()).map((([e,t])=>({...t,key:e})))}let he={};function pe({getKey:t,storageKey:n}={}){let{router:r}=ae(ne.UseScrollRestoration),{restoreScrollPosition:a,preventScrollReset:o}=oe(re.UseScrollRestoration),{basename:i}=e.useContext(s),u=c(),l=p(),f=w();e.useEffect((()=>(window.history.scrollRestoration="manual",()=>{window.history.scrollRestoration="auto"})),[]),function(t,n){let{capture:r}=n||{};e.useEffect((()=>{let e=null!=r?{capture:r}:void 0;return window.addEventListener("pagehide",t,e),()=>{window.removeEventListener("pagehide",t,e)}}),[t,r])}(e.useCallback((()=>{if("idle"===f.state){let e=(t?t(u,l):null)||u.key;he[e]=window.scrollY}try{sessionStorage.setItem(n||"react-router-scroll-positions",JSON.stringify(he))}catch(e){}window.history.scrollRestoration="auto"}),[n,t,f.state,u,l])),"undefined"!=typeof document&&(e.useLayoutEffect((()=>{try{let e=sessionStorage.getItem(n||"react-router-scroll-positions");e&&(he=JSON.parse(e))}catch(ye){}}),[n]),e.useLayoutEffect((()=>{let e=t&&"/"!==i?(e,n)=>t({...e,pathname:g(e.pathname,i)||e.pathname},n):t,n=r?.enableScrollRestoration(he,(()=>window.scrollY),e);return()=>n&&n()}),[r,i,t]),e.useLayoutEffect((()=>{if(!1!==a)if("number"!=typeof a){if(u.hash){let e=document.getElementById(decodeURIComponent(u.hash.slice(1)));if(e)return void e.scrollIntoView()}!0!==o&&window.scrollTo(0,0)}else window.scrollTo(0,a)}),[u,a,o]))}function we(t,n){let{capture:r}=n||{};e.useEffect((()=>{let e=null!=r?{capture:r}:void 0;return window.addEventListener("beforeunload",t,e),()=>{window.removeEventListener("beforeunload",t,e)}}),[t,r])}function ve({when:t,message:n}){let r=v(t);e.useEffect((()=>{if("blocked"===r.state){window.confirm(n)?setTimeout(r.proceed,0):r.reset()}}),[r,n]),e.useEffect((()=>{"blocked"!==r.state||t||r.reset()}),[r,t])}function ge(t,n={}){let r=e.useContext(K);null==r&&E(!1);let{basename:a}=ae(ne.useViewTransitionState),o=l(t,{relative:n.relative});if(!r.isTransitioning)return!1;let i=g(r.currentLocation.pathname,a)||r.currentLocation.pathname,s=g(r.nextLocation.pathname,a)||r.nextLocation.pathname;return null!=L(o.pathname,s)||null!=L(o.pathname,i)}export{Y as BrowserRouter,ee as Form,J as HashRouter,X as Link,Z as NavLink,$ as RouterProvider,te as ScrollRestoration,V as UNSAFE_FetchersContext,K as UNSAFE_ViewTransitionContext,pe as UNSAFE_useScrollRestoration,P as createBrowserRouter,D as createHashRouter,A as createSearchParams,q as unstable_HistoryRouter,ve as unstable_usePrompt,ge as unstable_useViewTransitionState,we as useBeforeUnload,de as useFetcher,me as useFetchers,fe as useFormAction,ie as useLinkClickHandler,se as useSearchParams,ce as useSubmit}; | ||
export*from"react-router"; | ||
//# sourceMappingURL=react-router-dom.production.min.js.map |
/** | ||
* React Router DOM v0.0.0-experimental-edf416237 | ||
* React Router v0.0.0-experimental-f042b8c1e | ||
* | ||
@@ -11,3 +11,3 @@ * Copyright (c) Remix Software Inc. | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("react-dom"),require("react-router"),require("@remix-run/router")):"function"==typeof define&&define.amd?define(["exports","react","react-dom","react-router","@remix-run/router"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactRouterDOM={},e.React,e.ReactDOM,e.ReactRouter,e.RemixRouter)}(this,(function(e,t,n,r,o){"use strict";function a(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var i=a(t),u=a(n);function s(){return s=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},s.apply(this,arguments)}function c(e,t){if(null==e)return{};var n,r,o={},a=Object.keys(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)>=0||(o[n]=e[n]);return o}const l="get",f="application/x-www-form-urlencoded";function d(e){return null!=e&&"string"==typeof e.tagName}function m(e){return void 0===e&&(e=""),new URLSearchParams("string"==typeof e||Array.isArray(e)||e instanceof URLSearchParams?e:Object.keys(e).reduce(((t,n)=>{let r=e[n];return t.concat(Array.isArray(r)?r.map((e=>[n,e])):[[n,r]])}),[]))}let p=null;const b=new Set(["application/x-www-form-urlencoded","multipart/form-data","text/plain"]);function h(e){return null==e||b.has(e)?e:null}function v(e,t){let n,r,a,i,u;if(d(s=e)&&"form"===s.tagName.toLowerCase()){let u=e.getAttribute("action");r=u?o.stripBasename(u,t):null,n=e.getAttribute("method")||l,a=h(e.getAttribute("enctype"))||f,i=new FormData(e)}else if(function(e){return d(e)&&"button"===e.tagName.toLowerCase()}(e)||function(e){return d(e)&&"input"===e.tagName.toLowerCase()}(e)&&("submit"===e.type||"image"===e.type)){let u=e.form;if(null==u)throw new Error('Cannot submit a <button> or <input type="submit"> without a <form>');let s=e.getAttribute("formaction")||u.getAttribute("action");if(r=s?o.stripBasename(s,t):null,n=e.getAttribute("formmethod")||u.getAttribute("method")||l,a=h(e.getAttribute("formenctype"))||h(u.getAttribute("enctype"))||f,i=new FormData(u,e),!function(){if(null===p)try{new FormData(document.createElement("form"),0),p=!1}catch(e){p=!0}return p}()){let{name:t,type:n,value:r}=e;if("image"===n){let e=t?t+".":"";i.append(e+"x","0"),i.append(e+"y","0")}else t&&i.append(t,r)}}else{if(d(e))throw new Error('Cannot submit element that is not <form>, <button>, or <input type="submit|image">');n=l,r=null,a=f,u=e}var s;return i&&"text/plain"===a&&(u=i,i=void 0),{action:r,method:n.toLowerCase(),encType:a,formData:i,body:u}}const y=["onClick","relative","reloadDocument","replace","state","target","to","preventScrollReset","unstable_viewTransition"],g=["aria-current","caseSensitive","className","end","style","to","unstable_viewTransition","children"],w=["fetcherKey","navigate","reloadDocument","replace","state","method","action","onSubmit","relative","preventScrollReset","unstable_viewTransition"];try{window.__reactRouterVersion="0"}catch(e){}function R(){var e;let t=null==(e=window)?void 0:e.__staticRouterHydrationData;return t&&t.errors&&(t=s({},t,{errors:S(t.errors)})),t}function S(e){if(!e)return null;let t=Object.entries(e),n={};for(let[e,r]of t)if(r&&"RouteErrorResponse"===r.__type)n[e]=new o.UNSAFE_ErrorResponseImpl(r.status,r.statusText,r.data,!0===r.internal);else if(r&&"Error"===r.__type){if(r.__subType){let t=window[r.__subType];if("function"==typeof t)try{let o=new t(r.message);o.stack="",n[e]=o}catch(e){}}if(null==n[e]){let t=new Error(r.message);t.stack="",n[e]=t}}else n[e]=r;return n}const E=i.createContext({isTransitioning:!1}),_=i.createContext(new Map),P=i.startTransition,O=u.flushSync,A=i.useId;function C(e){O?O(e):e()}class N{constructor(){this.status="pending",this.promise=new Promise(((e,t)=>{this.resolve=t=>{"pending"===this.status&&(this.status="resolved",e(t))},this.reject=e=>{"pending"===this.status&&(this.status="rejected",t(e))}}))}}function j(e){let{routes:t,future:n,state:o}=e;return r.UNSAFE_useRoutesImpl(t,void 0,o,n)}const x="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement,F=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,L=i.forwardRef((function(e,t){let n,{onClick:a,relative:u,reloadDocument:l,replace:f,state:d,target:m,to:p,preventScrollReset:b,unstable_viewTransition:h}=e,v=c(e,y),{basename:g}=i.useContext(r.UNSAFE_NavigationContext),w=!1;if("string"==typeof p&&F.test(p)&&(n=p,x))try{let e=new URL(window.location.href),t=p.startsWith("//")?new URL(e.protocol+p):new URL(p),n=o.stripBasename(t.pathname,g);t.origin===e.origin&&null!=n?p=n+t.search+t.hash:w=!0}catch(e){}let R=r.useHref(p,{relative:u}),S=H(p,{replace:f,state:d,target:m,preventScrollReset:b,relative:u,unstable_viewTransition:h});return i.createElement("a",s({},v,{href:n||R,onClick:w||l?a:function(e){a&&a(e),e.defaultPrevented||S(e)},ref:t,target:m}))})),T=i.forwardRef((function(e,t){let{"aria-current":n="page",caseSensitive:a=!1,className:u="",end:l=!1,style:f,to:d,unstable_viewTransition:m,children:p}=e,b=c(e,g),h=r.useResolvedPath(d,{relative:b.relative}),v=r.useLocation(),y=i.useContext(r.UNSAFE_DataRouterStateContext),{navigator:w,basename:R}=i.useContext(r.UNSAFE_NavigationContext),S=null!=y&&J(h)&&!0===m,E=w.encodeLocation?w.encodeLocation(h).pathname:h.pathname,_=v.pathname,P=y&&y.navigation&&y.navigation.location?y.navigation.location.pathname:null;a||(_=_.toLowerCase(),P=P?P.toLowerCase():null,E=E.toLowerCase()),P&&R&&(P=o.stripBasename(P,R)||P);const O="/"!==E&&E.endsWith("/")?E.length-1:E.length;let A,C=_===E||!l&&_.startsWith(E)&&"/"===_.charAt(O),N=null!=P&&(P===E||!l&&P.startsWith(E)&&"/"===P.charAt(E.length)),j={isActive:C,isPending:N,isTransitioning:S},x=C?n:void 0;A="function"==typeof u?u(j):[u,C?"active":null,N?"pending":null,S?"transitioning":null].filter(Boolean).join(" ");let F="function"==typeof f?f(j):f;return i.createElement(L,s({},b,{"aria-current":x,className:A,ref:t,style:F,to:d,unstable_viewTransition:m}),"function"==typeof p?p(j):p)})),U=i.forwardRef(((e,t)=>{let{fetcherKey:n,navigate:r,reloadDocument:o,replace:a,state:u,method:f=l,action:d,onSubmit:m,relative:p,preventScrollReset:b,unstable_viewTransition:h}=e,v=c(e,w),y=V(),g=z(d,{relative:p}),R="get"===f.toLowerCase()?"get":"post";return i.createElement("form",s({ref:t,method:R,action:g,onSubmit:o?m:e=>{if(m&&m(e),e.defaultPrevented)return;e.preventDefault();let t=e.nativeEvent.submitter,o=(null==t?void 0:t.getAttribute("formmethod"))||f;y(t||e.currentTarget,{fetcherKey:n,method:o,navigate:r,replace:a,state:u,relative:p,preventScrollReset:b,unstable_viewTransition:h})}},v))}));var D=function(e){return e.UseScrollRestoration="useScrollRestoration",e.UseSubmit="useSubmit",e.UseSubmitFetcher="useSubmitFetcher",e.UseFetcher="useFetcher",e.useViewTransitionState="useViewTransitionState",e}(D||{}),k=function(e){return e.UseFetcher="useFetcher",e.UseFetchers="useFetchers",e.UseScrollRestoration="useScrollRestoration",e}(k||{});function M(e){let t=i.useContext(r.UNSAFE_DataRouterContext);return t||o.UNSAFE_invariant(!1),t}function B(e){let t=i.useContext(r.UNSAFE_DataRouterStateContext);return t||o.UNSAFE_invariant(!1),t}function H(e,t){let{target:n,replace:o,state:a,preventScrollReset:u,relative:s,unstable_viewTransition:c}=void 0===t?{}:t,l=r.useNavigate(),f=r.useLocation(),d=r.useResolvedPath(e,{relative:s});return i.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(f)===r.createPath(d);l(e,{replace:n,state:a,preventScrollReset:u,relative:s,unstable_viewTransition:c})}}),[f,l,d,o,a,n,e,u,s,c])}let I=0,K=()=>"__"+String(++I)+"__";function V(){let{router:e}=M(D.UseSubmit),{basename:t}=i.useContext(r.UNSAFE_NavigationContext),n=r.UNSAFE_useRouteId();return i.useCallback((function(r,o){void 0===o&&(o={}),function(){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{action:a,method:i,encType:u,formData:s,body:c}=v(r,t);if(!1===o.navigate){let t=o.fetcherKey||K();e.fetch(t,n,o.action||a,{preventScrollReset:o.preventScrollReset,formData:s,body:c,formMethod:o.method||i,formEncType:o.encType||u,unstable_flushSync:o.unstable_flushSync})}else e.navigate(o.action||a,{preventScrollReset:o.preventScrollReset,formData:s,body:c,formMethod:o.method||i,formEncType:o.encType||u,replace:o.replace,state:o.state,fromRouteId:n,unstable_flushSync:o.unstable_flushSync,unstable_viewTransition:o.unstable_viewTransition})}),[e,t,n])}function z(e,t){let{relative:n}=void 0===t?{}:t,{basename:a}=i.useContext(r.UNSAFE_NavigationContext),u=i.useContext(r.UNSAFE_RouteContext);u||o.UNSAFE_invariant(!1);let[c]=u.matches.slice(-1),l=s({},r.useResolvedPath(e||".",{relative:n})),f=r.useLocation();if(null==e){l.search=f.search;let e=new URLSearchParams(l.search);e.has("index")&&""===e.get("index")&&(e.delete("index"),l.search=e.toString()?"?"+e.toString():"")}return e&&"."!==e||!c.route.index||(l.search=l.search?l.search.replace(/^\?/,"?index&"):"?index"),"/"!==a&&(l.pathname="/"===l.pathname?a:o.joinPaths([a,l.pathname])),r.createPath(l)}const q="react-router-scroll-positions";let W={};function Y(e){let{getKey:t,storageKey:n}=void 0===e?{}:e,{router:a}=M(D.UseScrollRestoration),{restoreScrollPosition:u,preventScrollReset:c}=B(k.UseScrollRestoration),{basename:l}=i.useContext(r.UNSAFE_NavigationContext),f=r.useLocation(),d=r.useMatches(),m=r.useNavigation();i.useEffect((()=>(window.history.scrollRestoration="manual",()=>{window.history.scrollRestoration="auto"})),[]),function(e,t){let{capture:n}=t||{};i.useEffect((()=>{let t=null!=n?{capture:n}:void 0;return window.addEventListener("pagehide",e,t),()=>{window.removeEventListener("pagehide",e,t)}}),[e,n])}(i.useCallback((()=>{if("idle"===m.state){let e=(t?t(f,d):null)||f.key;W[e]=window.scrollY}try{sessionStorage.setItem(n||q,JSON.stringify(W))}catch(e){}window.history.scrollRestoration="auto"}),[n,t,m.state,f,d])),"undefined"!=typeof document&&(i.useLayoutEffect((()=>{try{let e=sessionStorage.getItem(n||q);e&&(W=JSON.parse(e))}catch(e){}}),[n]),i.useLayoutEffect((()=>{let e=t&&"/"!==l?(e,n)=>t(s({},e,{pathname:o.stripBasename(e.pathname,l)||e.pathname}),n):t,n=null==a?void 0:a.enableScrollRestoration(W,(()=>window.scrollY),e);return()=>n&&n()}),[a,l,t]),i.useLayoutEffect((()=>{if(!1!==u)if("number"!=typeof u){if(f.hash){let e=document.getElementById(decodeURIComponent(f.hash.slice(1)));if(e)return void e.scrollIntoView()}!0!==c&&window.scrollTo(0,0)}else window.scrollTo(0,u)}),[f,u,c]))}function J(e,t){void 0===t&&(t={});let n=i.useContext(E);null==n&&o.UNSAFE_invariant(!1);let{basename:a}=M(D.useViewTransitionState),u=r.useResolvedPath(e,{relative:t.relative});if(!n.isTransitioning)return!1;let s=o.stripBasename(n.currentLocation.pathname,a)||n.currentLocation.pathname,c=o.stripBasename(n.nextLocation.pathname,a)||n.nextLocation.pathname;return null!=o.matchPath(u.pathname,c)||null!=o.matchPath(u.pathname,s)}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,"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_useRouteId",{enumerable:!0,get:function(){return r.UNSAFE_useRouteId}}),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,"redirectDocument",{enumerable:!0,get:function(){return r.redirectDocument}}),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,"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,"useBlocker",{enumerable:!0,get:function(){return r.useBlocker}}),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}}),Object.defineProperty(e,"UNSAFE_ErrorResponseImpl",{enumerable:!0,get:function(){return o.UNSAFE_ErrorResponseImpl}}),e.BrowserRouter=function(e){let{basename:t,children:n,future:a,window:u}=e,s=i.useRef();null==s.current&&(s.current=o.createBrowserHistory({window:u,v5Compat:!0}));let c=s.current,[l,f]=i.useState({action:c.action,location:c.location}),{v7_startTransition:d}=a||{},m=i.useCallback((e=>{d&&P?P((()=>f(e))):f(e)}),[f,d]);return i.useLayoutEffect((()=>c.listen(m)),[c,m]),i.createElement(r.Router,{basename:t,children:n,location:l.location,navigationType:l.action,navigator:c,future:a})},e.Form=U,e.HashRouter=function(e){let{basename:t,children:n,future:a,window:u}=e,s=i.useRef();null==s.current&&(s.current=o.createHashHistory({window:u,v5Compat:!0}));let c=s.current,[l,f]=i.useState({action:c.action,location:c.location}),{v7_startTransition:d}=a||{},m=i.useCallback((e=>{d&&P?P((()=>f(e))):f(e)}),[f,d]);return i.useLayoutEffect((()=>c.listen(m)),[c,m]),i.createElement(r.Router,{basename:t,children:n,location:l.location,navigationType:l.action,navigator:c,future:a})},e.Link=L,e.NavLink=T,e.RouterProvider=function(e){let{fallbackElement:t,router:n,future:o}=e,[a,u]=i.useState(n.state),[s,c]=i.useState(),[l,f]=i.useState({isTransitioning:!1}),[d,m]=i.useState(),[p,b]=i.useState(),[h,v]=i.useState(),y=i.useRef(new Map),{v7_startTransition:g}=o||{},w=i.useCallback((e=>{g?function(e){P?P(e):e()}(e):e()}),[g]),R=i.useCallback(((e,t)=>{let{deletedFetchers:r,unstable_flushSync:o,unstable_viewTransitionOpts:a}=t;r.forEach((e=>y.current.delete(e))),e.fetchers.forEach(((e,t)=>{void 0!==e.data&&y.current.set(t,e.data)}));let i=null==n.window||null==n.window.document||"function"!=typeof n.window.document.startViewTransition;if(a&&!i){if(o){C((()=>{p&&(d&&d.resolve(),p.skipTransition()),f({isTransitioning:!0,flushSync:!0,currentLocation:a.currentLocation,nextLocation:a.nextLocation})}));let t=n.window.document.startViewTransition((()=>{C((()=>u(e)))}));return t.finished.finally((()=>{C((()=>{m(void 0),b(void 0),c(void 0),f({isTransitioning:!1})}))})),void C((()=>b(t)))}p?(d&&d.resolve(),p.skipTransition(),v({state:e,currentLocation:a.currentLocation,nextLocation:a.nextLocation})):(c(e),f({isTransitioning:!0,flushSync:!1,currentLocation:a.currentLocation,nextLocation:a.nextLocation}))}else o?C((()=>u(e))):w((()=>u(e)))}),[n.window,p,d,y,w]);i.useLayoutEffect((()=>n.subscribe(R)),[n,R]),i.useEffect((()=>{l.isTransitioning&&!l.flushSync&&m(new N)}),[l]),i.useEffect((()=>{if(d&&s&&n.window){let e=s,t=d.promise,r=n.window.document.startViewTransition((async()=>{w((()=>u(e))),await t}));r.finished.finally((()=>{m(void 0),b(void 0),c(void 0),f({isTransitioning:!1})})),b(r)}}),[w,s,d,n.window]),i.useEffect((()=>{d&&s&&a.location.key===s.location.key&&d.resolve()}),[d,p,a.location,s]),i.useEffect((()=>{!l.isTransitioning&&h&&(c(h.state),f({isTransitioning:!0,flushSync:!1,currentLocation:h.currentLocation,nextLocation:h.nextLocation}),v(void 0))}),[l.isTransitioning,h]),i.useEffect((()=>{}),[]);let S=i.useMemo((()=>({createHref:n.createHref,encodeLocation:n.encodeLocation,go:e=>n.navigate(e),push:(e,t,r)=>n.navigate(e,{state:t,preventScrollReset:null==r?void 0:r.preventScrollReset}),replace:(e,t,r)=>n.navigate(e,{replace:!0,state:t,preventScrollReset:null==r?void 0:r.preventScrollReset})})),[n]),O=n.basename||"/",A=i.useMemo((()=>({router:n,navigator:S,static:!1,basename:O})),[n,S,O]);return i.createElement(i.Fragment,null,i.createElement(r.UNSAFE_DataRouterContext.Provider,{value:A},i.createElement(r.UNSAFE_DataRouterStateContext.Provider,{value:a},i.createElement(_.Provider,{value:y.current},i.createElement(E.Provider,{value:l},i.createElement(r.Router,{basename:O,location:a.location,navigationType:a.historyAction,navigator:S,future:{v7_relativeSplatPath:n.future.v7_relativeSplatPath}},a.initialized||n.future.v7_partialHydration?i.createElement(j,{routes:n.routes,future:n.future,state:a}):t))))),null)},e.ScrollRestoration=function(e){let{getKey:t,storageKey:n}=e;return Y({getKey:t,storageKey:n}),null},e.UNSAFE_FetchersContext=_,e.UNSAFE_ViewTransitionContext=E,e.UNSAFE_useScrollRestoration=Y,e.createBrowserRouter=function(e,t){return o.createRouter({basename:null==t?void 0:t.basename,future:s({},null==t?void 0:t.future,{v7_prependBasename:!0}),history:o.createBrowserHistory({window:null==t?void 0:t.window}),hydrationData:(null==t?void 0:t.hydrationData)||R(),routes:e,mapRouteProperties:r.UNSAFE_mapRouteProperties,unstable_dataStrategy:null==t?void 0:t.unstable_dataStrategy,unstable_patchRoutesOnMiss:null==t?void 0:t.unstable_patchRoutesOnMiss,window:null==t?void 0:t.window}).initialize()},e.createHashRouter=function(e,t){return o.createRouter({basename:null==t?void 0:t.basename,future:s({},null==t?void 0:t.future,{v7_prependBasename:!0}),history:o.createHashHistory({window:null==t?void 0:t.window}),hydrationData:(null==t?void 0:t.hydrationData)||R(),routes:e,mapRouteProperties:r.UNSAFE_mapRouteProperties,unstable_dataStrategy:null==t?void 0:t.unstable_dataStrategy,unstable_patchRoutesOnMiss:null==t?void 0:t.unstable_patchRoutesOnMiss,window:null==t?void 0:t.window}).initialize()},e.createSearchParams=m,e.unstable_HistoryRouter=function(e){let{basename:t,children:n,future:o,history:a}=e,[u,s]=i.useState({action:a.action,location:a.location}),{v7_startTransition:c}=o||{},l=i.useCallback((e=>{c&&P?P((()=>s(e))):s(e)}),[s,c]);return i.useLayoutEffect((()=>a.listen(l)),[a,l]),i.createElement(r.Router,{basename:t,children:n,location:u.location,navigationType:u.action,navigator:a,future:o})},e.unstable_usePrompt=function(e){let{when:t,message:n}=e,o=r.useBlocker(t);i.useEffect((()=>{if("blocked"===o.state){window.confirm(n)?setTimeout(o.proceed,0):o.reset()}}),[o,n]),i.useEffect((()=>{"blocked"!==o.state||t||o.reset()}),[o,t])},e.unstable_useViewTransitionState=J,e.useBeforeUnload=function(e,t){let{capture:n}=t||{};i.useEffect((()=>{let t=null!=n?{capture:n}:void 0;return window.addEventListener("beforeunload",e,t),()=>{window.removeEventListener("beforeunload",e,t)}}),[e,n])},e.useFetcher=function(e){var t;let{key:n}=void 0===e?{}:e,{router:a}=M(D.UseFetcher),u=B(k.UseFetcher),c=i.useContext(_),l=i.useContext(r.UNSAFE_RouteContext),f=null==(t=l.matches[l.matches.length-1])?void 0:t.route.id;c||o.UNSAFE_invariant(!1),l||o.UNSAFE_invariant(!1),null==f&&o.UNSAFE_invariant(!1);let d=A?A():"",[m,p]=i.useState(n||d);n&&n!==m?p(n):m||p(K()),i.useEffect((()=>(a.getFetcher(m),()=>{a.deleteFetcher(m)})),[a,m]);let b=i.useCallback(((e,t)=>{f||o.UNSAFE_invariant(!1),a.fetch(m,f,e,t)}),[m,f,a]),h=V(),v=i.useCallback(((e,t)=>{h(e,s({},t,{navigate:!1,fetcherKey:m}))}),[m,h]),y=i.useMemo((()=>i.forwardRef(((e,t)=>i.createElement(U,s({},e,{navigate:!1,fetcherKey:m,ref:t}))))),[m]),g=u.fetchers.get(m)||o.IDLE_FETCHER,w=c.get(m);return i.useMemo((()=>s({Form:y,submit:v,load:b},g,{data:w})),[y,v,b,g,w])},e.useFetchers=function(){let e=B(k.UseFetchers);return Array.from(e.fetchers.entries()).map((e=>{let[t,n]=e;return s({},n,{key:t})}))},e.useFormAction=z,e.useLinkClickHandler=H,e.useSearchParams=function(e){let t=i.useRef(m(e)),n=i.useRef(!1),o=r.useLocation(),a=i.useMemo((()=>function(e,t){let n=m(e);return t&&t.forEach(((e,r)=>{n.has(r)||t.getAll(r).forEach((e=>{n.append(r,e)}))})),n}(o.search,n.current?null:t.current)),[o.search]),u=r.useNavigate(),s=i.useCallback(((e,t)=>{const r=m("function"==typeof e?e(a):e);n.current=!0,u("?"+r,t)}),[u,a]);return[a,s]},e.useSubmit=V,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react-router")):"function"==typeof define&&define.amd?define(["exports","react-router"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactRouterDOM={},e.ReactRouter)}(this,(function(e,t){"use strict";Object.keys(t).forEach((function(o){"default"===o||e.hasOwnProperty(o)||Object.defineProperty(e,o,{enumerable:!0,get:function(){return t[o]}})})),Object.defineProperty(e,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=react-router-dom.production.min.js.map |
{ | ||
"name": "react-router-dom", | ||
"version": "0.0.0-experimental-edf416237", | ||
"version": "0.0.0-experimental-f042b8c1e", | ||
"description": "Declarative routing for React web applications", | ||
@@ -23,7 +23,14 @@ "keywords": [ | ||
"unpkg": "./dist/umd/react-router-dom.production.min.js", | ||
"module": "./dist/index.js", | ||
"module": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/index.mjs", | ||
"require": "./dist/main.js" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"dependencies": { | ||
"@remix-run/router": "0.0.0-experimental-edf416237", | ||
"react-router": "0.0.0-experimental-edf416237" | ||
"react-router": "0.0.0-experimental-f042b8c1e" | ||
}, | ||
@@ -35,17 +42,13 @@ "devDependencies": { | ||
"peerDependencies": { | ||
"react": ">=16.8", | ||
"react-dom": ">=16.8" | ||
"react": ">=18", | ||
"react-dom": ">=18" | ||
}, | ||
"files": [ | ||
"dist/", | ||
"CHANGELOG.md", | ||
"LICENSE.md", | ||
"README.md", | ||
"server.d.ts", | ||
"server.js", | ||
"server.mjs" | ||
"README.md" | ||
], | ||
"engines": { | ||
"node": ">=14.0.0" | ||
"node": ">=18.0.0" | ||
} | ||
} |
# React Router DOM | ||
The `react-router-dom` package contains bindings for using [React | ||
Router](https://github.com/remix-run/react-router) in web applications. | ||
Please see [the Getting Started guide](https://reactrouter.com/en/main/start/tutorial) for more information on how to get started with React Router. | ||
The `react-router-dom` package is deprecated and only kept around for backwards-compatibility. It re-exports everything from the `react-router` package - you should convert your applications to import everything from `react-router` in v7 and beyond. |
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 too big to display
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
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
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
3
2
1
6553
15
92
4
1
+ Added@types/cookie@0.6.0(transitive)
+ Added@web3-storage/multipart-parser@1.0.0(transitive)
+ Addedcookie@0.6.0(transitive)
+ Addedreact-router@0.0.0-experimental-f042b8c1e(transitive)
+ Addedset-cookie-parser@2.7.1(transitive)
+ Addedsource-map@0.7.4(transitive)
+ Addedturbo-stream@2.4.0(transitive)
- Removed@remix-run/router@0.0.0-experimental-edf416237(transitive)
- Removedreact-router@0.0.0-experimental-edf416237(transitive)