landvex: Fixar och tester klara för alla komponenter
- Datafabrik: Dockerfile fix, agentorkestrering fungerar - Vision: Identify-modell, FAISS, OCR alla testade - API: Alla 7 integrationstester passerade - Upplösare: Entitetsupplösning verifierad
This commit is contained in:
+117
@@ -0,0 +1,117 @@
|
||||
import type { FormEncType, HTMLFormMethod, RelativeRoutingType } from "@remix-run/router";
|
||||
export declare const defaultMethod: HTMLFormMethod;
|
||||
export declare function isHtmlElement(object: any): object is HTMLElement;
|
||||
export declare function isButtonElement(object: any): object is HTMLButtonElement;
|
||||
export declare function isFormElement(object: any): object is HTMLFormElement;
|
||||
export declare function isInputElement(object: any): object is HTMLInputElement;
|
||||
type LimitedMouseEvent = Pick<MouseEvent, "button" | "metaKey" | "altKey" | "ctrlKey" | "shiftKey">;
|
||||
export declare function shouldProcessLinkClick(event: LimitedMouseEvent, target?: string): boolean;
|
||||
export type ParamKeyValuePair = [string, string];
|
||||
export type URLSearchParamsInit = string | ParamKeyValuePair[] | Record<string, string | string[]> | URLSearchParams;
|
||||
/**
|
||||
* 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']
|
||||
* });
|
||||
*/
|
||||
export declare function createSearchParams(init?: URLSearchParamsInit): URLSearchParams;
|
||||
export declare function getSearchParamsForLocation(locationSearch: string, defaultSearchParams: URLSearchParams | null): URLSearchParams;
|
||||
type JsonObject = {
|
||||
[Key in string]: JsonValue;
|
||||
} & {
|
||||
[Key in string]?: JsonValue | undefined;
|
||||
};
|
||||
type JsonArray = JsonValue[] | readonly JsonValue[];
|
||||
type JsonPrimitive = string | number | boolean | null;
|
||||
type JsonValue = JsonPrimitive | JsonObject | JsonArray;
|
||||
export type SubmitTarget = HTMLFormElement | HTMLButtonElement | HTMLInputElement | FormData | URLSearchParams | JsonValue | null;
|
||||
/**
|
||||
* Submit options shared by both navigations and fetchers
|
||||
*/
|
||||
interface SharedSubmitOptions {
|
||||
/**
|
||||
* The HTTP method used to submit the form. Overrides `<form method>`.
|
||||
* Defaults to "GET".
|
||||
*/
|
||||
method?: HTMLFormMethod;
|
||||
/**
|
||||
* The action URL path used to submit the form. Overrides `<form action>`.
|
||||
* Defaults to the path of the current route.
|
||||
*/
|
||||
action?: string;
|
||||
/**
|
||||
* The encoding used to submit the form. Overrides `<form encType>`.
|
||||
* Defaults to "application/x-www-form-urlencoded".
|
||||
*/
|
||||
encType?: FormEncType;
|
||||
/**
|
||||
* 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;
|
||||
/**
|
||||
* In browser-based environments, prevent resetting scroll after this
|
||||
* navigation when using the <ScrollRestoration> component
|
||||
*/
|
||||
preventScrollReset?: boolean;
|
||||
/**
|
||||
* Enable flushSync for this submission's state updates
|
||||
*/
|
||||
flushSync?: boolean;
|
||||
}
|
||||
/**
|
||||
* Submit options available to fetchers
|
||||
*/
|
||||
export interface FetcherSubmitOptions extends SharedSubmitOptions {
|
||||
}
|
||||
/**
|
||||
* Submit options available to navigations
|
||||
*/
|
||||
export interface SubmitOptions extends FetcherSubmitOptions {
|
||||
/**
|
||||
* Set `true` to replace the current entry in the browser's history stack
|
||||
* instead of creating a new one (i.e. stay on "the same page"). Defaults
|
||||
* to `false`.
|
||||
*/
|
||||
replace?: boolean;
|
||||
/**
|
||||
* State object to add to the history stack entry for this navigation
|
||||
*/
|
||||
state?: any;
|
||||
/**
|
||||
* Indicate a specific fetcherKey to use when using navigate=false
|
||||
*/
|
||||
fetcherKey?: string;
|
||||
/**
|
||||
* navigate=false will use a fetcher instead of a navigation
|
||||
*/
|
||||
navigate?: boolean;
|
||||
/**
|
||||
* Enable view transitions on this submission navigation
|
||||
*/
|
||||
viewTransition?: boolean;
|
||||
}
|
||||
export declare function getFormSubmissionInfo(target: SubmitTarget, basename: string): {
|
||||
action: string | null;
|
||||
method: string;
|
||||
encType: string;
|
||||
formData: FormData | undefined;
|
||||
body: any;
|
||||
};
|
||||
export {};
|
||||
+331
@@ -0,0 +1,331 @@
|
||||
/**
|
||||
* 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, DataStrategyFunction, PatchRoutesOnNavigationFunction } from "react-router";
|
||||
import type { Fetcher, FormEncType, FormMethod, FutureConfig as RouterFutureConfig, GetScrollRestorationKeyFunction, History, HTMLFormMethod, HydrationState, Router as RemixRouter, V7_FormMethod, BlockerFunction } from "@remix-run/router";
|
||||
import { UNSAFE_ErrorResponseImpl as ErrorResponseImpl } from "@remix-run/router";
|
||||
import type { SubmitOptions, ParamKeyValuePair, URLSearchParamsInit, SubmitTarget, FetcherSubmitOptions } from "./dom";
|
||||
import { createSearchParams } from "./dom";
|
||||
export type { FormEncType, FormMethod, GetScrollRestorationKeyFunction, ParamKeyValuePair, SubmitOptions, URLSearchParamsInit, V7_FormMethod, };
|
||||
export { createSearchParams, ErrorResponseImpl as UNSAFE_ErrorResponseImpl };
|
||||
export type { ActionFunction, ActionFunctionArgs, AwaitProps, Blocker, BlockerFunction, DataRouteMatch, DataRouteObject, DataStrategyFunction, DataStrategyFunctionArgs, DataStrategyMatch, DataStrategyResult, ErrorResponse, Fetcher, FutureConfig, Hash, IndexRouteObject, IndexRouteProps, JsonFunction, LazyRouteFunction, LayoutRouteProps, LoaderFunction, LoaderFunctionArgs, Location, MemoryRouterProps, NavigateFunction, NavigateOptions, NavigateProps, Navigation, Navigator, NonIndexRouteObject, OutletProps, Params, ParamParseKey, PatchRoutesOnNavigationFunction, PatchRoutesOnNavigationFunctionArgs, Path, PathMatch, Pathname, PathParam, PathPattern, PathRouteProps, RedirectFunction, RelativeRoutingType, RouteMatch, RouteObject, RouteProps, RouterProps, RouterProviderProps, RoutesProps, Search, ShouldRevalidateFunction, ShouldRevalidateFunctionArgs, To, UIMatch, } 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, replace, 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;
|
||||
dataStrategy?: DataStrategyFunction;
|
||||
patchRoutesOnNavigation?: PatchRoutesOnNavigationFunction;
|
||||
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;
|
||||
viewTransition?: boolean;
|
||||
}
|
||||
/**
|
||||
* The public API for rendering a history-aware `<a>`.
|
||||
*/
|
||||
export declare const Link: React.ForwardRefExoticComponent<LinkProps & React.RefAttributes<HTMLAnchorElement>>;
|
||||
export 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>>;
|
||||
/**
|
||||
* Form props shared by navigations and fetchers
|
||||
*/
|
||||
interface SharedFormProps 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>;
|
||||
}
|
||||
/**
|
||||
* Form props available to fetchers
|
||||
*/
|
||||
export interface FetcherFormProps extends SharedFormProps {
|
||||
}
|
||||
/**
|
||||
* Form props available to navigations
|
||||
*/
|
||||
export interface FormProps extends SharedFormProps {
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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, viewTransition, }?: {
|
||||
target?: React.HTMLAttributeAnchorTarget;
|
||||
replace?: boolean;
|
||||
state?: any;
|
||||
preventScrollReset?: boolean;
|
||||
relative?: RelativeRoutingType;
|
||||
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?: FetcherSubmitOptions): 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?: {
|
||||
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 useViewTransitionState };
|
||||
+1450
@@ -0,0 +1,1450 @@
|
||||
/**
|
||||
* React Router DOM v6.30.4
|
||||
*
|
||||
* Copyright (c) Remix Software Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE.md file in the root directory of this source tree.
|
||||
*
|
||||
* @license MIT
|
||||
*/
|
||||
import * as React from 'react';
|
||||
import * as ReactDOM from 'react-dom';
|
||||
import { UNSAFE_mapRouteProperties, UNSAFE_logV6DeprecationWarnings, 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, replace, 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';
|
||||
|
||||
function _extends() {
|
||||
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
||||
for (var e = 1; e < arguments.length; e++) {
|
||||
var t = arguments[e];
|
||||
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
||||
}
|
||||
return n;
|
||||
}, _extends.apply(null, arguments);
|
||||
}
|
||||
function _objectWithoutPropertiesLoose(r, e) {
|
||||
if (null == r) return {};
|
||||
var t = {};
|
||||
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
||||
if (-1 !== e.indexOf(n)) continue;
|
||||
t[n] = r[n];
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
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) {
|
||||
if (init === void 0) {
|
||||
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;
|
||||
}
|
||||
// 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)) {
|
||||
process.env.NODE_ENV !== "production" ? UNSAFE_warning(false, "\"" + encType + "\" is not a valid `encType` for `<Form>`/`<fetcher.Form>` " + ("and will default to \"" + defaultEncType + "\"")) : void 0;
|
||||
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
|
||||
};
|
||||
}
|
||||
|
||||
const _excluded = ["onClick", "relative", "reloadDocument", "replace", "state", "target", "to", "preventScrollReset", "viewTransition"],
|
||||
_excluded2 = ["aria-current", "caseSensitive", "className", "end", "style", "to", "viewTransition", "children"],
|
||||
_excluded3 = ["fetcherKey", "navigate", "reloadDocument", "replace", "state", "method", "action", "onSubmit", "relative", "preventScrollReset", "viewTransition"];
|
||||
// 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 = "6";
|
||||
try {
|
||||
window.__reactRouterVersion = REACT_ROUTER_VERSION;
|
||||
} catch (e) {
|
||||
// no-op
|
||||
}
|
||||
function createBrowserRouter(routes, opts) {
|
||||
return createRouter({
|
||||
basename: opts == null ? void 0 : opts.basename,
|
||||
future: _extends({}, opts == null ? void 0 : opts.future, {
|
||||
v7_prependBasename: true
|
||||
}),
|
||||
history: createBrowserHistory({
|
||||
window: opts == null ? void 0 : opts.window
|
||||
}),
|
||||
hydrationData: (opts == null ? void 0 : opts.hydrationData) || parseHydrationData(),
|
||||
routes,
|
||||
mapRouteProperties: UNSAFE_mapRouteProperties,
|
||||
dataStrategy: opts == null ? void 0 : opts.dataStrategy,
|
||||
patchRoutesOnNavigation: opts == null ? void 0 : opts.patchRoutesOnNavigation,
|
||||
window: opts == null ? void 0 : opts.window
|
||||
}).initialize();
|
||||
}
|
||||
function createHashRouter(routes, opts) {
|
||||
return createRouter({
|
||||
basename: opts == null ? void 0 : opts.basename,
|
||||
future: _extends({}, opts == null ? void 0 : opts.future, {
|
||||
v7_prependBasename: true
|
||||
}),
|
||||
history: createHashHistory({
|
||||
window: opts == null ? void 0 : opts.window
|
||||
}),
|
||||
hydrationData: (opts == null ? void 0 : opts.hydrationData) || parseHydrationData(),
|
||||
routes,
|
||||
mapRouteProperties: UNSAFE_mapRouteProperties,
|
||||
dataStrategy: opts == null ? void 0 : opts.dataStrategy,
|
||||
patchRoutesOnNavigation: opts == null ? void 0 : opts.patchRoutesOnNavigation,
|
||||
window: opts == null ? void 0 : opts.window
|
||||
}).initialize();
|
||||
}
|
||||
function parseHydrationData() {
|
||||
var _window;
|
||||
let state = (_window = window) == null ? void 0 : _window.__staticRouterHydrationData;
|
||||
if (state && state.errors) {
|
||||
state = _extends({}, 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;
|
||||
}
|
||||
const ViewTransitionContext = /*#__PURE__*/React.createContext({
|
||||
isTransitioning: false
|
||||
});
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
ViewTransitionContext.displayName = "ViewTransition";
|
||||
}
|
||||
const FetchersContext = /*#__PURE__*/React.createContext(new Map());
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
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 {
|
||||
constructor() {
|
||||
this.status = "pending";
|
||||
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(_ref) {
|
||||
let {
|
||||
fallbackElement,
|
||||
router,
|
||||
future
|
||||
} = _ref;
|
||||
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, _ref2) => {
|
||||
let {
|
||||
deletedFetchers,
|
||||
flushSync: flushSync,
|
||||
viewTransitionOpts: viewTransitionOpts
|
||||
} = _ref2;
|
||||
newState.fetchers.forEach((fetcher, key) => {
|
||||
if (fetcher.data !== undefined) {
|
||||
fetcherData.current.set(key, fetcher.data);
|
||||
}
|
||||
});
|
||||
deletedFetchers.forEach(key => fetcherData.current.delete(key));
|
||||
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(() => {
|
||||
process.env.NODE_ENV !== "production" ? UNSAFE_warning(fallbackElement == null || !router.future.v7_partialHydration, "`<RouterProvider fallbackElement>` is deprecated when using " + "`v7_partialHydration`, use a `HydrateFallback` component instead") : void 0;
|
||||
// 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 == null ? void 0 : opts.preventScrollReset
|
||||
}),
|
||||
replace: (to, state, opts) => router.navigate(to, {
|
||||
replace: true,
|
||||
state,
|
||||
preventScrollReset: opts == null ? void 0 : opts.preventScrollReset
|
||||
})
|
||||
};
|
||||
}, [router]);
|
||||
let basename = router.basename || "/";
|
||||
let dataRouterContext = React.useMemo(() => ({
|
||||
router,
|
||||
navigator,
|
||||
static: false,
|
||||
basename
|
||||
}), [router, navigator, basename]);
|
||||
let routerFuture = React.useMemo(() => ({
|
||||
v7_relativeSplatPath: router.future.v7_relativeSplatPath
|
||||
}), [router.future.v7_relativeSplatPath]);
|
||||
React.useEffect(() => UNSAFE_logV6DeprecationWarnings(future, router.future), [future, router.future]);
|
||||
// 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: routerFuture
|
||||
}, state.initialized || router.future.v7_partialHydration ? (/*#__PURE__*/React.createElement(MemoizedDataRoutes, {
|
||||
routes: router.routes,
|
||||
future: router.future,
|
||||
state: state
|
||||
})) : fallbackElement))))), null);
|
||||
}
|
||||
// Memoize to avoid re-renders when updating `ViewTransitionContext`
|
||||
const MemoizedDataRoutes = /*#__PURE__*/React.memo(DataRoutes);
|
||||
function DataRoutes(_ref3) {
|
||||
let {
|
||||
routes,
|
||||
future,
|
||||
state
|
||||
} = _ref3;
|
||||
return UNSAFE_useRoutesImpl(routes, undefined, state, future);
|
||||
}
|
||||
/**
|
||||
* A `<Router>` for use in web browsers. Provides the cleanest URLs.
|
||||
*/
|
||||
function BrowserRouter(_ref4) {
|
||||
let {
|
||||
basename,
|
||||
children,
|
||||
future,
|
||||
window
|
||||
} = _ref4;
|
||||
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]);
|
||||
React.useEffect(() => UNSAFE_logV6DeprecationWarnings(future), [future]);
|
||||
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(_ref5) {
|
||||
let {
|
||||
basename,
|
||||
children,
|
||||
future,
|
||||
window
|
||||
} = _ref5;
|
||||
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]);
|
||||
React.useEffect(() => UNSAFE_logV6DeprecationWarnings(future), [future]);
|
||||
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(_ref6) {
|
||||
let {
|
||||
basename,
|
||||
children,
|
||||
future,
|
||||
history
|
||||
} = _ref6;
|
||||
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]);
|
||||
React.useEffect(() => UNSAFE_logV6DeprecationWarnings(future), [future]);
|
||||
return /*#__PURE__*/React.createElement(Router, {
|
||||
basename: basename,
|
||||
children: children,
|
||||
location: state.location,
|
||||
navigationType: state.action,
|
||||
navigator: history,
|
||||
future: future
|
||||
});
|
||||
}
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
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(_ref7, ref) {
|
||||
let {
|
||||
onClick,
|
||||
relative,
|
||||
reloadDocument,
|
||||
replace,
|
||||
state,
|
||||
target,
|
||||
to,
|
||||
preventScrollReset,
|
||||
viewTransition
|
||||
} = _ref7,
|
||||
rest = _objectWithoutPropertiesLoose(_ref7, _excluded);
|
||||
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
|
||||
process.env.NODE_ENV !== "production" ? UNSAFE_warning(false, "<Link to=\"" + to + "\"> contains an invalid URL which will probably break " + "when clicked - please update to a valid URL path.") : void 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Rendered into <a href> for relative URLs
|
||||
let href = useHref(to, {
|
||||
relative
|
||||
});
|
||||
let internalOnClick = useLinkClickHandler(to, {
|
||||
replace,
|
||||
state,
|
||||
target,
|
||||
preventScrollReset,
|
||||
relative,
|
||||
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", _extends({}, rest, {
|
||||
href: absoluteHref || href,
|
||||
onClick: isExternal || reloadDocument ? onClick : handleClick,
|
||||
ref: ref,
|
||||
target: target
|
||||
}))
|
||||
);
|
||||
});
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
Link.displayName = "Link";
|
||||
}
|
||||
/**
|
||||
* A `<Link>` wrapper that knows if it's "active" or not.
|
||||
*/
|
||||
const NavLink = /*#__PURE__*/React.forwardRef(function NavLinkWithRef(_ref8, ref) {
|
||||
let {
|
||||
"aria-current": ariaCurrentProp = "page",
|
||||
caseSensitive = false,
|
||||
className: classNameProp = "",
|
||||
end = false,
|
||||
style: styleProp,
|
||||
to,
|
||||
viewTransition,
|
||||
children
|
||||
} = _ref8,
|
||||
rest = _objectWithoutPropertiesLoose(_ref8, _excluded2);
|
||||
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) && 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, _extends({}, rest, {
|
||||
"aria-current": ariaCurrent,
|
||||
className: className,
|
||||
ref: ref,
|
||||
style: style,
|
||||
to: to,
|
||||
viewTransition: viewTransition
|
||||
}), typeof children === "function" ? children(renderProps) : children);
|
||||
});
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
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((_ref9, forwardedRef) => {
|
||||
let {
|
||||
fetcherKey,
|
||||
navigate,
|
||||
reloadDocument,
|
||||
replace,
|
||||
state,
|
||||
method = defaultMethod,
|
||||
action,
|
||||
onSubmit,
|
||||
relative,
|
||||
preventScrollReset,
|
||||
viewTransition
|
||||
} = _ref9,
|
||||
props = _objectWithoutPropertiesLoose(_ref9, _excluded3);
|
||||
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 == null ? void 0 : submitter.getAttribute("formmethod")) || method;
|
||||
submit(submitter || event.currentTarget, {
|
||||
fetcherKey,
|
||||
method: submitMethod,
|
||||
navigate,
|
||||
replace,
|
||||
state,
|
||||
relative,
|
||||
preventScrollReset,
|
||||
viewTransition
|
||||
});
|
||||
};
|
||||
return /*#__PURE__*/React.createElement("form", _extends({
|
||||
ref: forwardedRef,
|
||||
method: formMethod,
|
||||
action: formAction,
|
||||
onSubmit: reloadDocument ? onSubmit : submitHandler
|
||||
}, props));
|
||||
});
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
Form.displayName = "Form";
|
||||
}
|
||||
/**
|
||||
* This component will emulate the browser's scroll restoration on location
|
||||
* changes.
|
||||
*/
|
||||
function ScrollRestoration(_ref0) {
|
||||
let {
|
||||
getKey,
|
||||
storageKey
|
||||
} = _ref0;
|
||||
useScrollRestoration({
|
||||
getKey,
|
||||
storageKey
|
||||
});
|
||||
return null;
|
||||
}
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
ScrollRestoration.displayName = "ScrollRestoration";
|
||||
}
|
||||
//#endregion
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//#region Hooks
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
var DataRouterHook;
|
||||
(function (DataRouterHook) {
|
||||
DataRouterHook["UseScrollRestoration"] = "useScrollRestoration";
|
||||
DataRouterHook["UseSubmit"] = "useSubmit";
|
||||
DataRouterHook["UseSubmitFetcher"] = "useSubmitFetcher";
|
||||
DataRouterHook["UseFetcher"] = "useFetcher";
|
||||
DataRouterHook["useViewTransitionState"] = "useViewTransitionState";
|
||||
})(DataRouterHook || (DataRouterHook = {}));
|
||||
var DataRouterStateHook;
|
||||
(function (DataRouterStateHook) {
|
||||
DataRouterStateHook["UseFetcher"] = "useFetcher";
|
||||
DataRouterStateHook["UseFetchers"] = "useFetchers";
|
||||
DataRouterStateHook["UseScrollRestoration"] = "useScrollRestoration";
|
||||
})(DataRouterStateHook || (DataRouterStateHook = {}));
|
||||
// Internal hooks
|
||||
function getDataRouterConsoleError(hookName) {
|
||||
return hookName + " must be used within a data router. See https://reactrouter.com/v6/routers/picking-a-router.";
|
||||
}
|
||||
function useDataRouterContext(hookName) {
|
||||
let ctx = React.useContext(UNSAFE_DataRouterContext);
|
||||
!ctx ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, getDataRouterConsoleError(hookName)) : UNSAFE_invariant(false) : void 0;
|
||||
return ctx;
|
||||
}
|
||||
function useDataRouterState(hookName) {
|
||||
let state = React.useContext(UNSAFE_DataRouterStateContext);
|
||||
!state ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, getDataRouterConsoleError(hookName)) : UNSAFE_invariant(false) : 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, _temp) {
|
||||
let {
|
||||
target,
|
||||
replace: replaceProp,
|
||||
state,
|
||||
preventScrollReset,
|
||||
relative,
|
||||
viewTransition
|
||||
} = _temp === void 0 ? {} : _temp;
|
||||
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,
|
||||
viewTransition
|
||||
});
|
||||
}
|
||||
}, [location, navigate, path, replaceProp, state, target, to, preventScrollReset, relative, viewTransition]);
|
||||
}
|
||||
/**
|
||||
* A convenient wrapper for reading and writing search parameters via the
|
||||
* URLSearchParams interface.
|
||||
*/
|
||||
function useSearchParams(defaultInit) {
|
||||
process.env.NODE_ENV !== "production" ? UNSAFE_warning(typeof URLSearchParams !== "undefined", "You cannot use the `useSearchParams` hook in a browser that does not " + "support the URLSearchParams API. If you need to support Internet " + "Explorer 11, we recommend you load a polyfill such as " + "https://github.com/ungap/url-search-params.") : void 0;
|
||||
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];
|
||||
}
|
||||
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(function (target, options) {
|
||||
if (options === void 0) {
|
||||
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,
|
||||
flushSync: options.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,
|
||||
flushSync: options.flushSync,
|
||||
viewTransition: options.viewTransition
|
||||
});
|
||||
}
|
||||
}, [router, basename, currentRouteId]);
|
||||
}
|
||||
// v7: Eventually we should deprecate this entirely in favor of using the
|
||||
// router method directly?
|
||||
function useFormAction(action, _temp2) {
|
||||
let {
|
||||
relative
|
||||
} = _temp2 === void 0 ? {} : _temp2;
|
||||
let {
|
||||
basename
|
||||
} = React.useContext(UNSAFE_NavigationContext);
|
||||
let routeContext = React.useContext(UNSAFE_RouteContext);
|
||||
!routeContext ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "useFormAction must be used inside a RouteContext") : UNSAFE_invariant(false) : void 0;
|
||||
let [match] = routeContext.matches.slice(-1);
|
||||
// Shallow clone path so we can modify it below, otherwise we modify the
|
||||
// object referenced by useMemo inside useResolvedPath
|
||||
let path = _extends({}, 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);
|
||||
let indexValues = params.getAll("index");
|
||||
let hasNakedIndexParam = indexValues.some(v => v === "");
|
||||
if (hasNakedIndexParam) {
|
||||
params.delete("index");
|
||||
indexValues.filter(v => v).forEach(v => params.append("index", v));
|
||||
let qs = params.toString();
|
||||
path.search = qs ? "?" + qs : "";
|
||||
}
|
||||
}
|
||||
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(_temp3) {
|
||||
var _route$matches;
|
||||
let {
|
||||
key
|
||||
} = _temp3 === void 0 ? {} : _temp3;
|
||||
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[route.matches.length - 1]) == null ? void 0 : _route$matches.route.id;
|
||||
!fetcherData ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "useFetcher must be used inside a FetchersContext") : UNSAFE_invariant(false) : void 0;
|
||||
!route ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "useFetcher must be used inside a RouteContext") : UNSAFE_invariant(false) : void 0;
|
||||
!(routeId != null) ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "useFetcher can only be used on routes that contain a unique \"id\"") : UNSAFE_invariant(false) : void 0;
|
||||
// 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 ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "No routeId available for fetcher.load()") : UNSAFE_invariant(false) : void 0;
|
||||
router.fetch(fetcherKey, routeId, href, opts);
|
||||
}, [fetcherKey, routeId, router]);
|
||||
let submitImpl = useSubmit();
|
||||
let submit = React.useCallback((target, opts) => {
|
||||
submitImpl(target, _extends({}, opts, {
|
||||
navigate: false,
|
||||
fetcherKey
|
||||
}));
|
||||
}, [fetcherKey, submitImpl]);
|
||||
let FetcherForm = React.useMemo(() => {
|
||||
let FetcherForm = /*#__PURE__*/React.forwardRef((props, ref) => {
|
||||
return /*#__PURE__*/React.createElement(Form, _extends({}, props, {
|
||||
navigate: false,
|
||||
fetcherKey: fetcherKey,
|
||||
ref: ref
|
||||
}));
|
||||
});
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
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(() => _extends({
|
||||
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(_ref1 => {
|
||||
let [key, fetcher] = _ref1;
|
||||
return _extends({}, 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(_temp4) {
|
||||
let {
|
||||
getKey,
|
||||
storageKey
|
||||
} = _temp4 === void 0 ? {} : _temp4;
|
||||
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) {
|
||||
process.env.NODE_ENV !== "production" ? UNSAFE_warning(false, "Failed to save scroll positions in sessionStorage, <ScrollRestoration /> will not work properly (" + error + ").") : void 0;
|
||||
}
|
||||
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()
|
||||
_extends({}, location, {
|
||||
pathname: stripBasename(location.pathname, basename) || location.pathname
|
||||
}), matches) : getKey;
|
||||
let disableScrollRestoration = router == null ? void 0 : 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(_ref10) {
|
||||
let {
|
||||
when,
|
||||
message
|
||||
} = _ref10;
|
||||
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) {
|
||||
if (opts === void 0) {
|
||||
opts = {};
|
||||
}
|
||||
let vtContext = React.useContext(ViewTransitionContext);
|
||||
!(vtContext != null) ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "`useViewTransitionState` must be used within `react-router-dom`'s `RouterProvider`. " + "Did you accidentally import `RouterProvider` from `react-router`?") : UNSAFE_invariant(false) : 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" viewTransition>
|
||||
//
|
||||
// If you click the breadcrumb back to the list view:
|
||||
//
|
||||
// <NavLink to="/list" 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, useBeforeUnload, useFetcher, useFetchers, useFormAction, useLinkClickHandler, useSearchParams, useSubmit, useViewTransitionState };
|
||||
//# sourceMappingURL=index.js.map
|
||||
+1
File diff suppressed because one or more lines are too long
+19
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* React Router DOM v6.30.4
|
||||
*
|
||||
* Copyright (c) Remix Software Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE.md file in the root directory of this source tree.
|
||||
*
|
||||
* @license MIT
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
/* eslint-env node */
|
||||
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
module.exports = require("./umd/react-router-dom.production.min.js");
|
||||
} else {
|
||||
module.exports = require("./umd/react-router-dom.development.js");
|
||||
}
|
||||
+1528
@@ -0,0 +1,1528 @@
|
||||
/**
|
||||
* React Router DOM v6.30.4
|
||||
*
|
||||
* Copyright (c) Remix Software Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE.md file in the root directory of this source tree.
|
||||
*
|
||||
* @license MIT
|
||||
*/
|
||||
import * as React from 'react';
|
||||
import * as ReactDOM from 'react-dom';
|
||||
import { UNSAFE_mapRouteProperties, UNSAFE_logV6DeprecationWarnings, 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, replace, 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit options shared by both navigations and fetchers
|
||||
*/
|
||||
|
||||
/**
|
||||
* Submit options available to fetchers
|
||||
*/
|
||||
|
||||
/**
|
||||
* Submit options available to navigations
|
||||
*/
|
||||
|
||||
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 = "6";
|
||||
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,
|
||||
dataStrategy: opts?.dataStrategy,
|
||||
patchRoutesOnNavigation: opts?.patchRoutesOnNavigation,
|
||||
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,
|
||||
dataStrategy: opts?.dataStrategy,
|
||||
patchRoutesOnNavigation: opts?.patchRoutesOnNavigation,
|
||||
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,
|
||||
flushSync: flushSync,
|
||||
viewTransitionOpts: viewTransitionOpts
|
||||
}) => {
|
||||
newState.fetchers.forEach((fetcher, key) => {
|
||||
if (fetcher.data !== undefined) {
|
||||
fetcherData.current.set(key, fetcher.data);
|
||||
}
|
||||
});
|
||||
deletedFetchers.forEach(key => fetcherData.current.delete(key));
|
||||
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]);
|
||||
let routerFuture = React.useMemo(() => ({
|
||||
v7_relativeSplatPath: router.future.v7_relativeSplatPath
|
||||
}), [router.future.v7_relativeSplatPath]);
|
||||
React.useEffect(() => UNSAFE_logV6DeprecationWarnings(future, router.future), [future, router.future]);
|
||||
|
||||
// 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: routerFuture
|
||||
}, state.initialized || router.future.v7_partialHydration ? /*#__PURE__*/React.createElement(MemoizedDataRoutes, {
|
||||
routes: router.routes,
|
||||
future: router.future,
|
||||
state: state
|
||||
}) : fallbackElement))))), null);
|
||||
}
|
||||
|
||||
// Memoize to avoid re-renders when updating `ViewTransitionContext`
|
||||
const MemoizedDataRoutes = /*#__PURE__*/React.memo(DataRoutes);
|
||||
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]);
|
||||
React.useEffect(() => UNSAFE_logV6DeprecationWarnings(future), [future]);
|
||||
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]);
|
||||
React.useEffect(() => UNSAFE_logV6DeprecationWarnings(future), [future]);
|
||||
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]);
|
||||
React.useEffect(() => UNSAFE_logV6DeprecationWarnings(future), [future]);
|
||||
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,
|
||||
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,
|
||||
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,
|
||||
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) && 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,
|
||||
viewTransition: viewTransition
|
||||
}), typeof children === "function" ? children(renderProps) : children);
|
||||
});
|
||||
{
|
||||
NavLink.displayName = "NavLink";
|
||||
}
|
||||
|
||||
/**
|
||||
* Form props shared by navigations and fetchers
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form props available to fetchers
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form props available to navigations
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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,
|
||||
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,
|
||||
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/v6/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,
|
||||
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,
|
||||
viewTransition
|
||||
});
|
||||
}
|
||||
}, [location, navigate, path, replaceProp, state, target, to, preventScrollReset, relative, 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.`) ;
|
||||
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,
|
||||
flushSync: options.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,
|
||||
flushSync: options.flushSync,
|
||||
viewTransition: options.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);
|
||||
let indexValues = params.getAll("index");
|
||||
let hasNakedIndexParam = indexValues.some(v => v === "");
|
||||
if (hasNakedIndexParam) {
|
||||
params.delete("index");
|
||||
indexValues.filter(v => v).forEach(v => params.append("index", v));
|
||||
let qs = params.toString();
|
||||
path.search = qs ? `?${qs}` : "";
|
||||
}
|
||||
}
|
||||
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, "`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" viewTransition>
|
||||
//
|
||||
// If you click the breadcrumb back to the list view:
|
||||
//
|
||||
// <NavLink to="/list" 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, useBeforeUnload, useFetcher, useFetchers, useFormAction, useLinkClickHandler, useSearchParams, useSubmit, useViewTransitionState };
|
||||
//# sourceMappingURL=react-router-dom.development.js.map
|
||||
Generated
Vendored
+1
File diff suppressed because one or more lines are too long
Generated
Vendored
+12
File diff suppressed because one or more lines are too long
Generated
Vendored
+1
File diff suppressed because one or more lines are too long
+31
@@ -0,0 +1,31 @@
|
||||
import * as React from "react";
|
||||
import type { Router as RemixRouter, StaticHandlerContext, CreateStaticHandlerOptions as RouterCreateStaticHandlerOptions, FutureConfig as RouterFutureConfig } from "@remix-run/router";
|
||||
import type { FutureConfig, Location, RouteObject } from "react-router-dom";
|
||||
export interface StaticRouterProps {
|
||||
basename?: string;
|
||||
children?: React.ReactNode;
|
||||
location: Partial<Location> | string;
|
||||
future?: Partial<FutureConfig>;
|
||||
}
|
||||
/**
|
||||
* A `<Router>` that may not navigate to any other location. This is useful
|
||||
* on the server where there is no stateful UI.
|
||||
*/
|
||||
export declare function StaticRouter({ basename, children, location: locationProp, future, }: StaticRouterProps): React.JSX.Element;
|
||||
export { StaticHandlerContext };
|
||||
export interface StaticRouterProviderProps {
|
||||
context: StaticHandlerContext;
|
||||
router: RemixRouter;
|
||||
hydrate?: boolean;
|
||||
nonce?: string;
|
||||
}
|
||||
/**
|
||||
* A Data Router that may not navigate to any other location. This is useful
|
||||
* on the server where there is no stateful UI.
|
||||
*/
|
||||
export declare function StaticRouterProvider({ context, router, hydrate, nonce, }: StaticRouterProviderProps): React.JSX.Element;
|
||||
type CreateStaticHandlerOptions = Omit<RouterCreateStaticHandlerOptions, "detectErrorBoundary" | "mapRouteProperties">;
|
||||
export declare function createStaticHandler(routes: RouteObject[], opts?: CreateStaticHandlerOptions): import("@remix-run/router").StaticHandler;
|
||||
export declare function createStaticRouter(routes: RouteObject[], context: StaticHandlerContext, opts?: {
|
||||
future?: Partial<Pick<RouterFutureConfig, "v7_partialHydration" | "v7_relativeSplatPath">>;
|
||||
}): RemixRouter;
|
||||
+322
@@ -0,0 +1,322 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
var React = require('react');
|
||||
var router = require('@remix-run/router');
|
||||
var reactRouter = require('react-router');
|
||||
var reactRouterDom = require('react-router-dom');
|
||||
|
||||
function _interopNamespace(e) {
|
||||
if (e && e.__esModule) return e;
|
||||
var n = Object.create(null);
|
||||
if (e) {
|
||||
Object.keys(e).forEach(function (k) {
|
||||
if (k !== 'default') {
|
||||
var d = Object.getOwnPropertyDescriptor(e, k);
|
||||
Object.defineProperty(n, k, d.get ? d : {
|
||||
enumerable: true,
|
||||
get: function () { return e[k]; }
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
n["default"] = e;
|
||||
return Object.freeze(n);
|
||||
}
|
||||
|
||||
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
||||
|
||||
/**
|
||||
* A `<Router>` that may not navigate to any other location. This is useful
|
||||
* on the server where there is no stateful UI.
|
||||
*/
|
||||
function StaticRouter({
|
||||
basename,
|
||||
children,
|
||||
location: locationProp = "/",
|
||||
future
|
||||
}) {
|
||||
if (typeof locationProp === "string") {
|
||||
locationProp = reactRouterDom.parsePath(locationProp);
|
||||
}
|
||||
let action = router.Action.Pop;
|
||||
let location = {
|
||||
pathname: locationProp.pathname || "/",
|
||||
search: locationProp.search || "",
|
||||
hash: locationProp.hash || "",
|
||||
state: locationProp.state != null ? locationProp.state : null,
|
||||
key: locationProp.key || "default"
|
||||
};
|
||||
let staticNavigator = getStatelessNavigator();
|
||||
return /*#__PURE__*/React__namespace.createElement(reactRouterDom.Router, {
|
||||
basename: basename,
|
||||
children: children,
|
||||
location: location,
|
||||
navigationType: action,
|
||||
navigator: staticNavigator,
|
||||
future: future,
|
||||
static: true
|
||||
});
|
||||
}
|
||||
/**
|
||||
* A Data Router that may not navigate to any other location. This is useful
|
||||
* on the server where there is no stateful UI.
|
||||
*/
|
||||
function StaticRouterProvider({
|
||||
context,
|
||||
router: router$1,
|
||||
hydrate = true,
|
||||
nonce
|
||||
}) {
|
||||
!(router$1 && context) ? process.env.NODE_ENV !== "production" ? router.UNSAFE_invariant(false, "You must provide `router` and `context` to <StaticRouterProvider>") : router.UNSAFE_invariant(false) : void 0;
|
||||
let dataRouterContext = {
|
||||
router: router$1,
|
||||
navigator: getStatelessNavigator(),
|
||||
static: true,
|
||||
staticContext: context,
|
||||
basename: context.basename || "/"
|
||||
};
|
||||
let fetchersContext = new Map();
|
||||
let hydrateScript = "";
|
||||
if (hydrate !== false) {
|
||||
let data = {
|
||||
loaderData: context.loaderData,
|
||||
actionData: context.actionData,
|
||||
errors: serializeErrors(context.errors)
|
||||
};
|
||||
// Use JSON.parse here instead of embedding a raw JS object here to speed
|
||||
// up parsing on the client. Dual-stringify is needed to ensure all quotes
|
||||
// are properly escaped in the resulting string. See:
|
||||
// https://v8.dev/blog/cost-of-javascript-2019#json
|
||||
let json = htmlEscape(JSON.stringify(JSON.stringify(data)));
|
||||
hydrateScript = `window.__staticRouterHydrationData = JSON.parse(${json});`;
|
||||
}
|
||||
let {
|
||||
state
|
||||
} = dataRouterContext.router;
|
||||
return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, /*#__PURE__*/React__namespace.createElement(reactRouterDom.UNSAFE_DataRouterContext.Provider, {
|
||||
value: dataRouterContext
|
||||
}, /*#__PURE__*/React__namespace.createElement(reactRouterDom.UNSAFE_DataRouterStateContext.Provider, {
|
||||
value: state
|
||||
}, /*#__PURE__*/React__namespace.createElement(reactRouterDom.UNSAFE_FetchersContext.Provider, {
|
||||
value: fetchersContext
|
||||
}, /*#__PURE__*/React__namespace.createElement(reactRouterDom.UNSAFE_ViewTransitionContext.Provider, {
|
||||
value: {
|
||||
isTransitioning: false
|
||||
}
|
||||
}, /*#__PURE__*/React__namespace.createElement(reactRouterDom.Router, {
|
||||
basename: dataRouterContext.basename,
|
||||
location: state.location,
|
||||
navigationType: state.historyAction,
|
||||
navigator: dataRouterContext.navigator,
|
||||
static: dataRouterContext.static,
|
||||
future: {
|
||||
v7_relativeSplatPath: router$1.future.v7_relativeSplatPath
|
||||
}
|
||||
}, /*#__PURE__*/React__namespace.createElement(DataRoutes, {
|
||||
routes: router$1.routes,
|
||||
future: router$1.future,
|
||||
state: state
|
||||
})))))), hydrateScript ? (/*#__PURE__*/React__namespace.createElement("script", {
|
||||
suppressHydrationWarning: true,
|
||||
nonce: nonce,
|
||||
dangerouslySetInnerHTML: {
|
||||
__html: hydrateScript
|
||||
}
|
||||
})) : null);
|
||||
}
|
||||
function DataRoutes({
|
||||
routes,
|
||||
future,
|
||||
state
|
||||
}) {
|
||||
return reactRouter.UNSAFE_useRoutesImpl(routes, undefined, state, future);
|
||||
}
|
||||
function serializeErrors(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
|
||||
// deserializeErrors in react-router-dom/index.tsx :)
|
||||
if (router.isRouteErrorResponse(val)) {
|
||||
serialized[key] = {
|
||||
...val,
|
||||
__type: "RouteErrorResponse"
|
||||
};
|
||||
} else if (val instanceof Error) {
|
||||
// Do not serialize stack traces from SSR for security reasons
|
||||
serialized[key] = {
|
||||
message: val.message,
|
||||
__type: "Error",
|
||||
// If this is a subclass (i.e., ReferenceError), send up the type so we
|
||||
// can re-create the same type during hydration.
|
||||
...(val.name !== "Error" ? {
|
||||
__subType: val.name
|
||||
} : {})
|
||||
};
|
||||
} else {
|
||||
serialized[key] = val;
|
||||
}
|
||||
}
|
||||
return serialized;
|
||||
}
|
||||
function getStatelessNavigator() {
|
||||
return {
|
||||
createHref,
|
||||
encodeLocation,
|
||||
push(to) {
|
||||
throw new Error(`You cannot use navigator.push() on the server because it is a stateless ` + `environment. This error was probably triggered when you did a ` + `\`navigate(${JSON.stringify(to)})\` somewhere in your app.`);
|
||||
},
|
||||
replace(to) {
|
||||
throw new Error(`You cannot use navigator.replace() on the server because it is a stateless ` + `environment. This error was probably triggered when you did a ` + `\`navigate(${JSON.stringify(to)}, { replace: true })\` somewhere ` + `in your app.`);
|
||||
},
|
||||
go(delta) {
|
||||
throw new Error(`You cannot use navigator.go() on the server because it is a stateless ` + `environment. This error was probably triggered when you did a ` + `\`navigate(${delta})\` somewhere in your app.`);
|
||||
},
|
||||
back() {
|
||||
throw new Error(`You cannot use navigator.back() on the server because it is a stateless ` + `environment.`);
|
||||
},
|
||||
forward() {
|
||||
throw new Error(`You cannot use navigator.forward() on the server because it is a stateless ` + `environment.`);
|
||||
}
|
||||
};
|
||||
}
|
||||
function createStaticHandler(routes, opts) {
|
||||
return router.createStaticHandler(routes, {
|
||||
...opts,
|
||||
mapRouteProperties: reactRouter.UNSAFE_mapRouteProperties
|
||||
});
|
||||
}
|
||||
function createStaticRouter(routes, context, opts = {}) {
|
||||
let manifest = {};
|
||||
let dataRoutes = router.UNSAFE_convertRoutesToDataRoutes(routes, reactRouter.UNSAFE_mapRouteProperties, undefined, manifest);
|
||||
// Because our context matches may be from a framework-agnostic set of
|
||||
// routes passed to createStaticHandler(), we update them here with our
|
||||
// newly created/enhanced data routes
|
||||
let matches = context.matches.map(match => {
|
||||
let route = manifest[match.route.id] || match.route;
|
||||
return {
|
||||
...match,
|
||||
route
|
||||
};
|
||||
});
|
||||
let msg = method => `You cannot use router.${method}() on the server because it is a stateless environment`;
|
||||
return {
|
||||
get basename() {
|
||||
return context.basename;
|
||||
},
|
||||
get future() {
|
||||
return {
|
||||
v7_fetcherPersist: false,
|
||||
v7_normalizeFormMethod: false,
|
||||
v7_partialHydration: opts.future?.v7_partialHydration === true,
|
||||
v7_prependBasename: false,
|
||||
v7_relativeSplatPath: opts.future?.v7_relativeSplatPath === true,
|
||||
v7_skipActionErrorRevalidation: false
|
||||
};
|
||||
},
|
||||
get state() {
|
||||
return {
|
||||
historyAction: router.Action.Pop,
|
||||
location: context.location,
|
||||
matches,
|
||||
loaderData: context.loaderData,
|
||||
actionData: context.actionData,
|
||||
errors: context.errors,
|
||||
initialized: true,
|
||||
navigation: router.IDLE_NAVIGATION,
|
||||
restoreScrollPosition: null,
|
||||
preventScrollReset: false,
|
||||
revalidation: "idle",
|
||||
fetchers: new Map(),
|
||||
blockers: new Map()
|
||||
};
|
||||
},
|
||||
get routes() {
|
||||
return dataRoutes;
|
||||
},
|
||||
get window() {
|
||||
return undefined;
|
||||
},
|
||||
initialize() {
|
||||
throw msg("initialize");
|
||||
},
|
||||
subscribe() {
|
||||
throw msg("subscribe");
|
||||
},
|
||||
enableScrollRestoration() {
|
||||
throw msg("enableScrollRestoration");
|
||||
},
|
||||
navigate() {
|
||||
throw msg("navigate");
|
||||
},
|
||||
fetch() {
|
||||
throw msg("fetch");
|
||||
},
|
||||
revalidate() {
|
||||
throw msg("revalidate");
|
||||
},
|
||||
createHref,
|
||||
encodeLocation,
|
||||
getFetcher() {
|
||||
return router.IDLE_FETCHER;
|
||||
},
|
||||
deleteFetcher() {
|
||||
throw msg("deleteFetcher");
|
||||
},
|
||||
dispose() {
|
||||
throw msg("dispose");
|
||||
},
|
||||
getBlocker() {
|
||||
return router.IDLE_BLOCKER;
|
||||
},
|
||||
deleteBlocker() {
|
||||
throw msg("deleteBlocker");
|
||||
},
|
||||
patchRoutes() {
|
||||
throw msg("patchRoutes");
|
||||
},
|
||||
_internalFetchControllers: new Map(),
|
||||
_internalActiveDeferreds: new Map(),
|
||||
_internalSetRoutes() {
|
||||
throw msg("_internalSetRoutes");
|
||||
}
|
||||
};
|
||||
}
|
||||
function createHref(to) {
|
||||
return typeof to === "string" ? to : reactRouterDom.createPath(to);
|
||||
}
|
||||
function encodeLocation(to) {
|
||||
let href = typeof to === "string" ? to : reactRouterDom.createPath(to);
|
||||
// Treating this as a full URL will strip any trailing spaces so we need to
|
||||
// pre-encode them since they might be part of a matching splat param from
|
||||
// an ancestor route
|
||||
href = href.replace(/ $/, "%20");
|
||||
let encoded = ABSOLUTE_URL_REGEX.test(href) ? new URL(href) : new URL(href, "http://localhost");
|
||||
return {
|
||||
pathname: encoded.pathname,
|
||||
search: encoded.search,
|
||||
hash: encoded.hash
|
||||
};
|
||||
}
|
||||
const ABSOLUTE_URL_REGEX = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
|
||||
// This utility is based on https://github.com/zertosh/htmlescape
|
||||
// License: https://github.com/zertosh/htmlescape/blob/0527ca7156a524d256101bb310a9f970f63078ad/LICENSE
|
||||
const ESCAPE_LOOKUP = {
|
||||
"&": "\\u0026",
|
||||
">": "\\u003e",
|
||||
"<": "\\u003c",
|
||||
"\u2028": "\\u2028",
|
||||
"\u2029": "\\u2029"
|
||||
};
|
||||
const ESCAPE_REGEX = /[&><\u2028\u2029]/g;
|
||||
function htmlEscape(str) {
|
||||
return str.replace(ESCAPE_REGEX, match => ESCAPE_LOOKUP[match]);
|
||||
}
|
||||
|
||||
exports.StaticRouter = StaticRouter;
|
||||
exports.StaticRouterProvider = StaticRouterProvider;
|
||||
exports.createStaticHandler = createStaticHandler;
|
||||
exports.createStaticRouter = createStaticRouter;
|
||||
+297
@@ -0,0 +1,297 @@
|
||||
import * as React from 'react';
|
||||
import { Action, UNSAFE_invariant, isRouteErrorResponse, createStaticHandler as createStaticHandler$1, UNSAFE_convertRoutesToDataRoutes, IDLE_NAVIGATION, IDLE_FETCHER, IDLE_BLOCKER } from '@remix-run/router';
|
||||
import { UNSAFE_useRoutesImpl, UNSAFE_mapRouteProperties } from 'react-router';
|
||||
import { parsePath, Router, UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, UNSAFE_FetchersContext, UNSAFE_ViewTransitionContext, createPath } from 'react-router-dom';
|
||||
|
||||
/**
|
||||
* A `<Router>` that may not navigate to any other location. This is useful
|
||||
* on the server where there is no stateful UI.
|
||||
*/
|
||||
function StaticRouter({
|
||||
basename,
|
||||
children,
|
||||
location: locationProp = "/",
|
||||
future
|
||||
}) {
|
||||
if (typeof locationProp === "string") {
|
||||
locationProp = parsePath(locationProp);
|
||||
}
|
||||
let action = Action.Pop;
|
||||
let location = {
|
||||
pathname: locationProp.pathname || "/",
|
||||
search: locationProp.search || "",
|
||||
hash: locationProp.hash || "",
|
||||
state: locationProp.state != null ? locationProp.state : null,
|
||||
key: locationProp.key || "default"
|
||||
};
|
||||
let staticNavigator = getStatelessNavigator();
|
||||
return /*#__PURE__*/React.createElement(Router, {
|
||||
basename: basename,
|
||||
children: children,
|
||||
location: location,
|
||||
navigationType: action,
|
||||
navigator: staticNavigator,
|
||||
future: future,
|
||||
static: true
|
||||
});
|
||||
}
|
||||
/**
|
||||
* A Data Router that may not navigate to any other location. This is useful
|
||||
* on the server where there is no stateful UI.
|
||||
*/
|
||||
function StaticRouterProvider({
|
||||
context,
|
||||
router,
|
||||
hydrate = true,
|
||||
nonce
|
||||
}) {
|
||||
!(router && context) ? process.env.NODE_ENV !== "production" ? UNSAFE_invariant(false, "You must provide `router` and `context` to <StaticRouterProvider>") : UNSAFE_invariant(false) : void 0;
|
||||
let dataRouterContext = {
|
||||
router,
|
||||
navigator: getStatelessNavigator(),
|
||||
static: true,
|
||||
staticContext: context,
|
||||
basename: context.basename || "/"
|
||||
};
|
||||
let fetchersContext = new Map();
|
||||
let hydrateScript = "";
|
||||
if (hydrate !== false) {
|
||||
let data = {
|
||||
loaderData: context.loaderData,
|
||||
actionData: context.actionData,
|
||||
errors: serializeErrors(context.errors)
|
||||
};
|
||||
// Use JSON.parse here instead of embedding a raw JS object here to speed
|
||||
// up parsing on the client. Dual-stringify is needed to ensure all quotes
|
||||
// are properly escaped in the resulting string. See:
|
||||
// https://v8.dev/blog/cost-of-javascript-2019#json
|
||||
let json = htmlEscape(JSON.stringify(JSON.stringify(data)));
|
||||
hydrateScript = `window.__staticRouterHydrationData = JSON.parse(${json});`;
|
||||
}
|
||||
let {
|
||||
state
|
||||
} = dataRouterContext.router;
|
||||
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(UNSAFE_FetchersContext.Provider, {
|
||||
value: fetchersContext
|
||||
}, /*#__PURE__*/React.createElement(UNSAFE_ViewTransitionContext.Provider, {
|
||||
value: {
|
||||
isTransitioning: false
|
||||
}
|
||||
}, /*#__PURE__*/React.createElement(Router, {
|
||||
basename: dataRouterContext.basename,
|
||||
location: state.location,
|
||||
navigationType: state.historyAction,
|
||||
navigator: dataRouterContext.navigator,
|
||||
static: dataRouterContext.static,
|
||||
future: {
|
||||
v7_relativeSplatPath: router.future.v7_relativeSplatPath
|
||||
}
|
||||
}, /*#__PURE__*/React.createElement(DataRoutes, {
|
||||
routes: router.routes,
|
||||
future: router.future,
|
||||
state: state
|
||||
})))))), hydrateScript ? /*#__PURE__*/React.createElement("script", {
|
||||
suppressHydrationWarning: true,
|
||||
nonce: nonce,
|
||||
dangerouslySetInnerHTML: {
|
||||
__html: hydrateScript
|
||||
}
|
||||
}) : null);
|
||||
}
|
||||
function DataRoutes({
|
||||
routes,
|
||||
future,
|
||||
state
|
||||
}) {
|
||||
return UNSAFE_useRoutesImpl(routes, undefined, state, future);
|
||||
}
|
||||
function serializeErrors(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
|
||||
// deserializeErrors in react-router-dom/index.tsx :)
|
||||
if (isRouteErrorResponse(val)) {
|
||||
serialized[key] = {
|
||||
...val,
|
||||
__type: "RouteErrorResponse"
|
||||
};
|
||||
} else if (val instanceof Error) {
|
||||
// Do not serialize stack traces from SSR for security reasons
|
||||
serialized[key] = {
|
||||
message: val.message,
|
||||
__type: "Error",
|
||||
// If this is a subclass (i.e., ReferenceError), send up the type so we
|
||||
// can re-create the same type during hydration.
|
||||
...(val.name !== "Error" ? {
|
||||
__subType: val.name
|
||||
} : {})
|
||||
};
|
||||
} else {
|
||||
serialized[key] = val;
|
||||
}
|
||||
}
|
||||
return serialized;
|
||||
}
|
||||
function getStatelessNavigator() {
|
||||
return {
|
||||
createHref,
|
||||
encodeLocation,
|
||||
push(to) {
|
||||
throw new Error(`You cannot use navigator.push() on the server because it is a stateless ` + `environment. This error was probably triggered when you did a ` + `\`navigate(${JSON.stringify(to)})\` somewhere in your app.`);
|
||||
},
|
||||
replace(to) {
|
||||
throw new Error(`You cannot use navigator.replace() on the server because it is a stateless ` + `environment. This error was probably triggered when you did a ` + `\`navigate(${JSON.stringify(to)}, { replace: true })\` somewhere ` + `in your app.`);
|
||||
},
|
||||
go(delta) {
|
||||
throw new Error(`You cannot use navigator.go() on the server because it is a stateless ` + `environment. This error was probably triggered when you did a ` + `\`navigate(${delta})\` somewhere in your app.`);
|
||||
},
|
||||
back() {
|
||||
throw new Error(`You cannot use navigator.back() on the server because it is a stateless ` + `environment.`);
|
||||
},
|
||||
forward() {
|
||||
throw new Error(`You cannot use navigator.forward() on the server because it is a stateless ` + `environment.`);
|
||||
}
|
||||
};
|
||||
}
|
||||
function createStaticHandler(routes, opts) {
|
||||
return createStaticHandler$1(routes, {
|
||||
...opts,
|
||||
mapRouteProperties: UNSAFE_mapRouteProperties
|
||||
});
|
||||
}
|
||||
function createStaticRouter(routes, context, opts = {}) {
|
||||
let manifest = {};
|
||||
let dataRoutes = UNSAFE_convertRoutesToDataRoutes(routes, UNSAFE_mapRouteProperties, undefined, manifest);
|
||||
|
||||
// Because our context matches may be from a framework-agnostic set of
|
||||
// routes passed to createStaticHandler(), we update them here with our
|
||||
// newly created/enhanced data routes
|
||||
let matches = context.matches.map(match => {
|
||||
let route = manifest[match.route.id] || match.route;
|
||||
return {
|
||||
...match,
|
||||
route
|
||||
};
|
||||
});
|
||||
let msg = method => `You cannot use router.${method}() on the server because it is a stateless environment`;
|
||||
return {
|
||||
get basename() {
|
||||
return context.basename;
|
||||
},
|
||||
get future() {
|
||||
return {
|
||||
v7_fetcherPersist: false,
|
||||
v7_normalizeFormMethod: false,
|
||||
v7_partialHydration: opts.future?.v7_partialHydration === true,
|
||||
v7_prependBasename: false,
|
||||
v7_relativeSplatPath: opts.future?.v7_relativeSplatPath === true,
|
||||
v7_skipActionErrorRevalidation: false
|
||||
};
|
||||
},
|
||||
get state() {
|
||||
return {
|
||||
historyAction: Action.Pop,
|
||||
location: context.location,
|
||||
matches,
|
||||
loaderData: context.loaderData,
|
||||
actionData: context.actionData,
|
||||
errors: context.errors,
|
||||
initialized: true,
|
||||
navigation: IDLE_NAVIGATION,
|
||||
restoreScrollPosition: null,
|
||||
preventScrollReset: false,
|
||||
revalidation: "idle",
|
||||
fetchers: new Map(),
|
||||
blockers: new Map()
|
||||
};
|
||||
},
|
||||
get routes() {
|
||||
return dataRoutes;
|
||||
},
|
||||
get window() {
|
||||
return undefined;
|
||||
},
|
||||
initialize() {
|
||||
throw msg("initialize");
|
||||
},
|
||||
subscribe() {
|
||||
throw msg("subscribe");
|
||||
},
|
||||
enableScrollRestoration() {
|
||||
throw msg("enableScrollRestoration");
|
||||
},
|
||||
navigate() {
|
||||
throw msg("navigate");
|
||||
},
|
||||
fetch() {
|
||||
throw msg("fetch");
|
||||
},
|
||||
revalidate() {
|
||||
throw msg("revalidate");
|
||||
},
|
||||
createHref,
|
||||
encodeLocation,
|
||||
getFetcher() {
|
||||
return IDLE_FETCHER;
|
||||
},
|
||||
deleteFetcher() {
|
||||
throw msg("deleteFetcher");
|
||||
},
|
||||
dispose() {
|
||||
throw msg("dispose");
|
||||
},
|
||||
getBlocker() {
|
||||
return IDLE_BLOCKER;
|
||||
},
|
||||
deleteBlocker() {
|
||||
throw msg("deleteBlocker");
|
||||
},
|
||||
patchRoutes() {
|
||||
throw msg("patchRoutes");
|
||||
},
|
||||
_internalFetchControllers: new Map(),
|
||||
_internalActiveDeferreds: new Map(),
|
||||
_internalSetRoutes() {
|
||||
throw msg("_internalSetRoutes");
|
||||
}
|
||||
};
|
||||
}
|
||||
function createHref(to) {
|
||||
return typeof to === "string" ? to : createPath(to);
|
||||
}
|
||||
function encodeLocation(to) {
|
||||
let href = typeof to === "string" ? to : createPath(to);
|
||||
// Treating this as a full URL will strip any trailing spaces so we need to
|
||||
// pre-encode them since they might be part of a matching splat param from
|
||||
// an ancestor route
|
||||
href = href.replace(/ $/, "%20");
|
||||
let encoded = ABSOLUTE_URL_REGEX.test(href) ? new URL(href) : new URL(href, "http://localhost");
|
||||
return {
|
||||
pathname: encoded.pathname,
|
||||
search: encoded.search,
|
||||
hash: encoded.hash
|
||||
};
|
||||
}
|
||||
const ABSOLUTE_URL_REGEX = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
|
||||
|
||||
// This utility is based on https://github.com/zertosh/htmlescape
|
||||
// License: https://github.com/zertosh/htmlescape/blob/0527ca7156a524d256101bb310a9f970f63078ad/LICENSE
|
||||
const ESCAPE_LOOKUP = {
|
||||
"&": "\\u0026",
|
||||
">": "\\u003e",
|
||||
"<": "\\u003c",
|
||||
"\u2028": "\\u2028",
|
||||
"\u2029": "\\u2029"
|
||||
};
|
||||
const ESCAPE_REGEX = /[&><\u2028\u2029]/g;
|
||||
function htmlEscape(str) {
|
||||
return str.replace(ESCAPE_REGEX, match => ESCAPE_LOOKUP[match]);
|
||||
}
|
||||
|
||||
export { StaticRouter, StaticRouterProvider, createStaticHandler, createStaticRouter };
|
||||
Generated
Vendored
+1823
@@ -0,0 +1,1823 @@
|
||||
/**
|
||||
* React Router DOM v6.30.4
|
||||
*
|
||||
* Copyright (c) Remix Software Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE.md file in the root directory of this source tree.
|
||||
*
|
||||
* @license MIT
|
||||
*/
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('react-dom'), require('react-router'), require('@remix-run/router')) :
|
||||
typeof define === 'function' && define.amd ? define(['exports', 'react', 'react-dom', 'react-router', '@remix-run/router'], factory) :
|
||||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactRouterDOM = {}, global.React, global.ReactDOM, global.ReactRouter, global.RemixRouter));
|
||||
})(this, (function (exports, React, ReactDOM, reactRouter, router) { 'use strict';
|
||||
|
||||
function _interopNamespace(e) {
|
||||
if (e && e.__esModule) return e;
|
||||
var n = Object.create(null);
|
||||
if (e) {
|
||||
Object.keys(e).forEach(function (k) {
|
||||
if (k !== 'default') {
|
||||
var d = Object.getOwnPropertyDescriptor(e, k);
|
||||
Object.defineProperty(n, k, d.get ? d : {
|
||||
enumerable: true,
|
||||
get: function () { return e[k]; }
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
n["default"] = e;
|
||||
return Object.freeze(n);
|
||||
}
|
||||
|
||||
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
||||
var ReactDOM__namespace = /*#__PURE__*/_interopNamespace(ReactDOM);
|
||||
|
||||
function _extends() {
|
||||
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
||||
for (var e = 1; e < arguments.length; e++) {
|
||||
var t = arguments[e];
|
||||
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
||||
}
|
||||
return n;
|
||||
}, _extends.apply(null, arguments);
|
||||
}
|
||||
function _objectWithoutPropertiesLoose(r, e) {
|
||||
if (null == r) return {};
|
||||
var t = {};
|
||||
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
||||
if (-1 !== e.indexOf(n)) continue;
|
||||
t[n] = r[n];
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
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) {
|
||||
if (init === void 0) {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit options shared by both navigations and fetchers
|
||||
*/
|
||||
|
||||
/**
|
||||
* Submit options available to fetchers
|
||||
*/
|
||||
|
||||
/**
|
||||
* Submit options available to navigations
|
||||
*/
|
||||
|
||||
const supportedFormEncTypes = new Set(["application/x-www-form-urlencoded", "multipart/form-data", "text/plain"]);
|
||||
function getFormEncType(encType) {
|
||||
if (encType != null && !supportedFormEncTypes.has(encType)) {
|
||||
router.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 ? router.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 ? router.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
|
||||
};
|
||||
}
|
||||
|
||||
const _excluded = ["onClick", "relative", "reloadDocument", "replace", "state", "target", "to", "preventScrollReset", "viewTransition"],
|
||||
_excluded2 = ["aria-current", "caseSensitive", "className", "end", "style", "to", "viewTransition", "children"],
|
||||
_excluded3 = ["fetcherKey", "navigate", "reloadDocument", "replace", "state", "method", "action", "onSubmit", "relative", "preventScrollReset", "viewTransition"];
|
||||
//#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 = "6";
|
||||
try {
|
||||
window.__reactRouterVersion = REACT_ROUTER_VERSION;
|
||||
} catch (e) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//#region Routers
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function createBrowserRouter(routes, opts) {
|
||||
return router.createRouter({
|
||||
basename: opts == null ? void 0 : opts.basename,
|
||||
future: _extends({}, opts == null ? void 0 : opts.future, {
|
||||
v7_prependBasename: true
|
||||
}),
|
||||
history: router.createBrowserHistory({
|
||||
window: opts == null ? void 0 : opts.window
|
||||
}),
|
||||
hydrationData: (opts == null ? void 0 : opts.hydrationData) || parseHydrationData(),
|
||||
routes,
|
||||
mapRouteProperties: reactRouter.UNSAFE_mapRouteProperties,
|
||||
dataStrategy: opts == null ? void 0 : opts.dataStrategy,
|
||||
patchRoutesOnNavigation: opts == null ? void 0 : opts.patchRoutesOnNavigation,
|
||||
window: opts == null ? void 0 : opts.window
|
||||
}).initialize();
|
||||
}
|
||||
function createHashRouter(routes, opts) {
|
||||
return router.createRouter({
|
||||
basename: opts == null ? void 0 : opts.basename,
|
||||
future: _extends({}, opts == null ? void 0 : opts.future, {
|
||||
v7_prependBasename: true
|
||||
}),
|
||||
history: router.createHashHistory({
|
||||
window: opts == null ? void 0 : opts.window
|
||||
}),
|
||||
hydrationData: (opts == null ? void 0 : opts.hydrationData) || parseHydrationData(),
|
||||
routes,
|
||||
mapRouteProperties: reactRouter.UNSAFE_mapRouteProperties,
|
||||
dataStrategy: opts == null ? void 0 : opts.dataStrategy,
|
||||
patchRoutesOnNavigation: opts == null ? void 0 : opts.patchRoutesOnNavigation,
|
||||
window: opts == null ? void 0 : opts.window
|
||||
}).initialize();
|
||||
}
|
||||
function parseHydrationData() {
|
||||
var _window;
|
||||
let state = (_window = window) == null ? void 0 : _window.__staticRouterHydrationData;
|
||||
if (state && state.errors) {
|
||||
state = _extends({}, 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 router.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__namespace.createContext({
|
||||
isTransitioning: false
|
||||
});
|
||||
{
|
||||
ViewTransitionContext.displayName = "ViewTransition";
|
||||
}
|
||||
|
||||
// TODO: (v7) Change the useFetcher data from `any` to `unknown`
|
||||
|
||||
const FetchersContext = /*#__PURE__*/React__namespace.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__namespace[START_TRANSITION];
|
||||
const FLUSH_SYNC = "flushSync";
|
||||
const flushSyncImpl = ReactDOM__namespace[FLUSH_SYNC];
|
||||
const USE_ID = "useId";
|
||||
const useIdImpl = React__namespace[USE_ID];
|
||||
function startTransitionSafe(cb) {
|
||||
if (startTransitionImpl) {
|
||||
startTransitionImpl(cb);
|
||||
} else {
|
||||
cb();
|
||||
}
|
||||
}
|
||||
function flushSyncSafe(cb) {
|
||||
if (flushSyncImpl) {
|
||||
flushSyncImpl(cb);
|
||||
} else {
|
||||
cb();
|
||||
}
|
||||
}
|
||||
class Deferred {
|
||||
// @ts-expect-error - no initializer
|
||||
|
||||
// @ts-expect-error - no initializer
|
||||
|
||||
constructor() {
|
||||
this.status = "pending";
|
||||
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(_ref) {
|
||||
let {
|
||||
fallbackElement,
|
||||
router: router$1,
|
||||
future
|
||||
} = _ref;
|
||||
let [state, setStateImpl] = React__namespace.useState(router$1.state);
|
||||
let [pendingState, setPendingState] = React__namespace.useState();
|
||||
let [vtContext, setVtContext] = React__namespace.useState({
|
||||
isTransitioning: false
|
||||
});
|
||||
let [renderDfd, setRenderDfd] = React__namespace.useState();
|
||||
let [transition, setTransition] = React__namespace.useState();
|
||||
let [interruption, setInterruption] = React__namespace.useState();
|
||||
let fetcherData = React__namespace.useRef(new Map());
|
||||
let {
|
||||
v7_startTransition
|
||||
} = future || {};
|
||||
let optInStartTransition = React__namespace.useCallback(cb => {
|
||||
if (v7_startTransition) {
|
||||
startTransitionSafe(cb);
|
||||
} else {
|
||||
cb();
|
||||
}
|
||||
}, [v7_startTransition]);
|
||||
let setState = React__namespace.useCallback((newState, _ref2) => {
|
||||
let {
|
||||
deletedFetchers,
|
||||
flushSync: flushSync,
|
||||
viewTransitionOpts: viewTransitionOpts
|
||||
} = _ref2;
|
||||
newState.fetchers.forEach((fetcher, key) => {
|
||||
if (fetcher.data !== undefined) {
|
||||
fetcherData.current.set(key, fetcher.data);
|
||||
}
|
||||
});
|
||||
deletedFetchers.forEach(key => fetcherData.current.delete(key));
|
||||
let isViewTransitionUnavailable = router$1.window == null || router$1.window.document == null || typeof router$1.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$1.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$1.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__namespace.useLayoutEffect(() => router$1.subscribe(setState), [router$1, setState]);
|
||||
|
||||
// When we start a view transition, create a Deferred we can use for the
|
||||
// eventual "completed" render
|
||||
React__namespace.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__namespace.useEffect(() => {
|
||||
if (renderDfd && pendingState && router$1.window) {
|
||||
let newState = pendingState;
|
||||
let renderPromise = renderDfd.promise;
|
||||
let transition = router$1.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$1.window]);
|
||||
|
||||
// When the new location finally renders and is committed to the DOM, this
|
||||
// effect will run to resolve the transition
|
||||
React__namespace.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__namespace.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__namespace.useEffect(() => {
|
||||
router.UNSAFE_warning(fallbackElement == null || !router$1.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__namespace.useMemo(() => {
|
||||
return {
|
||||
createHref: router$1.createHref,
|
||||
encodeLocation: router$1.encodeLocation,
|
||||
go: n => router$1.navigate(n),
|
||||
push: (to, state, opts) => router$1.navigate(to, {
|
||||
state,
|
||||
preventScrollReset: opts == null ? void 0 : opts.preventScrollReset
|
||||
}),
|
||||
replace: (to, state, opts) => router$1.navigate(to, {
|
||||
replace: true,
|
||||
state,
|
||||
preventScrollReset: opts == null ? void 0 : opts.preventScrollReset
|
||||
})
|
||||
};
|
||||
}, [router$1]);
|
||||
let basename = router$1.basename || "/";
|
||||
let dataRouterContext = React__namespace.useMemo(() => ({
|
||||
router: router$1,
|
||||
navigator,
|
||||
static: false,
|
||||
basename
|
||||
}), [router$1, navigator, basename]);
|
||||
let routerFuture = React__namespace.useMemo(() => ({
|
||||
v7_relativeSplatPath: router$1.future.v7_relativeSplatPath
|
||||
}), [router$1.future.v7_relativeSplatPath]);
|
||||
React__namespace.useEffect(() => reactRouter.UNSAFE_logV6DeprecationWarnings(future, router$1.future), [future, router$1.future]);
|
||||
|
||||
// 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__namespace.createElement(React__namespace.Fragment, null, /*#__PURE__*/React__namespace.createElement(reactRouter.UNSAFE_DataRouterContext.Provider, {
|
||||
value: dataRouterContext
|
||||
}, /*#__PURE__*/React__namespace.createElement(reactRouter.UNSAFE_DataRouterStateContext.Provider, {
|
||||
value: state
|
||||
}, /*#__PURE__*/React__namespace.createElement(FetchersContext.Provider, {
|
||||
value: fetcherData.current
|
||||
}, /*#__PURE__*/React__namespace.createElement(ViewTransitionContext.Provider, {
|
||||
value: vtContext
|
||||
}, /*#__PURE__*/React__namespace.createElement(reactRouter.Router, {
|
||||
basename: basename,
|
||||
location: state.location,
|
||||
navigationType: state.historyAction,
|
||||
navigator: navigator,
|
||||
future: routerFuture
|
||||
}, state.initialized || router$1.future.v7_partialHydration ? /*#__PURE__*/React__namespace.createElement(MemoizedDataRoutes, {
|
||||
routes: router$1.routes,
|
||||
future: router$1.future,
|
||||
state: state
|
||||
}) : fallbackElement))))), null);
|
||||
}
|
||||
|
||||
// Memoize to avoid re-renders when updating `ViewTransitionContext`
|
||||
const MemoizedDataRoutes = /*#__PURE__*/React__namespace.memo(DataRoutes);
|
||||
function DataRoutes(_ref3) {
|
||||
let {
|
||||
routes,
|
||||
future,
|
||||
state
|
||||
} = _ref3;
|
||||
return reactRouter.UNSAFE_useRoutesImpl(routes, undefined, state, future);
|
||||
}
|
||||
/**
|
||||
* A `<Router>` for use in web browsers. Provides the cleanest URLs.
|
||||
*/
|
||||
function BrowserRouter(_ref4) {
|
||||
let {
|
||||
basename,
|
||||
children,
|
||||
future,
|
||||
window
|
||||
} = _ref4;
|
||||
let historyRef = React__namespace.useRef();
|
||||
if (historyRef.current == null) {
|
||||
historyRef.current = router.createBrowserHistory({
|
||||
window,
|
||||
v5Compat: true
|
||||
});
|
||||
}
|
||||
let history = historyRef.current;
|
||||
let [state, setStateImpl] = React__namespace.useState({
|
||||
action: history.action,
|
||||
location: history.location
|
||||
});
|
||||
let {
|
||||
v7_startTransition
|
||||
} = future || {};
|
||||
let setState = React__namespace.useCallback(newState => {
|
||||
v7_startTransition && startTransitionImpl ? startTransitionImpl(() => setStateImpl(newState)) : setStateImpl(newState);
|
||||
}, [setStateImpl, v7_startTransition]);
|
||||
React__namespace.useLayoutEffect(() => history.listen(setState), [history, setState]);
|
||||
React__namespace.useEffect(() => reactRouter.UNSAFE_logV6DeprecationWarnings(future), [future]);
|
||||
return /*#__PURE__*/React__namespace.createElement(reactRouter.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(_ref5) {
|
||||
let {
|
||||
basename,
|
||||
children,
|
||||
future,
|
||||
window
|
||||
} = _ref5;
|
||||
let historyRef = React__namespace.useRef();
|
||||
if (historyRef.current == null) {
|
||||
historyRef.current = router.createHashHistory({
|
||||
window,
|
||||
v5Compat: true
|
||||
});
|
||||
}
|
||||
let history = historyRef.current;
|
||||
let [state, setStateImpl] = React__namespace.useState({
|
||||
action: history.action,
|
||||
location: history.location
|
||||
});
|
||||
let {
|
||||
v7_startTransition
|
||||
} = future || {};
|
||||
let setState = React__namespace.useCallback(newState => {
|
||||
v7_startTransition && startTransitionImpl ? startTransitionImpl(() => setStateImpl(newState)) : setStateImpl(newState);
|
||||
}, [setStateImpl, v7_startTransition]);
|
||||
React__namespace.useLayoutEffect(() => history.listen(setState), [history, setState]);
|
||||
React__namespace.useEffect(() => reactRouter.UNSAFE_logV6DeprecationWarnings(future), [future]);
|
||||
return /*#__PURE__*/React__namespace.createElement(reactRouter.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(_ref6) {
|
||||
let {
|
||||
basename,
|
||||
children,
|
||||
future,
|
||||
history
|
||||
} = _ref6;
|
||||
let [state, setStateImpl] = React__namespace.useState({
|
||||
action: history.action,
|
||||
location: history.location
|
||||
});
|
||||
let {
|
||||
v7_startTransition
|
||||
} = future || {};
|
||||
let setState = React__namespace.useCallback(newState => {
|
||||
v7_startTransition && startTransitionImpl ? startTransitionImpl(() => setStateImpl(newState)) : setStateImpl(newState);
|
||||
}, [setStateImpl, v7_startTransition]);
|
||||
React__namespace.useLayoutEffect(() => history.listen(setState), [history, setState]);
|
||||
React__namespace.useEffect(() => reactRouter.UNSAFE_logV6DeprecationWarnings(future), [future]);
|
||||
return /*#__PURE__*/React__namespace.createElement(reactRouter.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__namespace.forwardRef(function LinkWithRef(_ref7, ref) {
|
||||
let {
|
||||
onClick,
|
||||
relative,
|
||||
reloadDocument,
|
||||
replace,
|
||||
state,
|
||||
target,
|
||||
to,
|
||||
preventScrollReset,
|
||||
viewTransition
|
||||
} = _ref7,
|
||||
rest = _objectWithoutPropertiesLoose(_ref7, _excluded);
|
||||
let {
|
||||
basename
|
||||
} = React__namespace.useContext(reactRouter.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 = router.stripBasename(targetUrl.pathname, basename);
|
||||
if (targetUrl.origin === currentUrl.origin && path != null) {
|
||||
// Strip the protocol/origin/basename for same-origin absolute URLs
|
||||
to = path + targetUrl.search + targetUrl.hash;
|
||||
} else {
|
||||
isExternal = true;
|
||||
}
|
||||
} catch (e) {
|
||||
// We can't do external URL detection without a valid URL
|
||||
router.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 = reactRouter.useHref(to, {
|
||||
relative
|
||||
});
|
||||
let internalOnClick = useLinkClickHandler(to, {
|
||||
replace,
|
||||
state,
|
||||
target,
|
||||
preventScrollReset,
|
||||
relative,
|
||||
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__namespace.createElement("a", _extends({}, 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__namespace.forwardRef(function NavLinkWithRef(_ref8, ref) {
|
||||
let {
|
||||
"aria-current": ariaCurrentProp = "page",
|
||||
caseSensitive = false,
|
||||
className: classNameProp = "",
|
||||
end = false,
|
||||
style: styleProp,
|
||||
to,
|
||||
viewTransition,
|
||||
children
|
||||
} = _ref8,
|
||||
rest = _objectWithoutPropertiesLoose(_ref8, _excluded2);
|
||||
let path = reactRouter.useResolvedPath(to, {
|
||||
relative: rest.relative
|
||||
});
|
||||
let location = reactRouter.useLocation();
|
||||
let routerState = React__namespace.useContext(reactRouter.UNSAFE_DataRouterStateContext);
|
||||
let {
|
||||
navigator,
|
||||
basename
|
||||
} = React__namespace.useContext(reactRouter.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) && 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 = router.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__namespace.createElement(Link, _extends({}, rest, {
|
||||
"aria-current": ariaCurrent,
|
||||
className: className,
|
||||
ref: ref,
|
||||
style: style,
|
||||
to: to,
|
||||
viewTransition: viewTransition
|
||||
}), typeof children === "function" ? children(renderProps) : children);
|
||||
});
|
||||
{
|
||||
NavLink.displayName = "NavLink";
|
||||
}
|
||||
|
||||
/**
|
||||
* Form props shared by navigations and fetchers
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form props available to fetchers
|
||||
*/
|
||||
|
||||
/**
|
||||
* Form props available to navigations
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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__namespace.forwardRef((_ref9, forwardedRef) => {
|
||||
let {
|
||||
fetcherKey,
|
||||
navigate,
|
||||
reloadDocument,
|
||||
replace,
|
||||
state,
|
||||
method = defaultMethod,
|
||||
action,
|
||||
onSubmit,
|
||||
relative,
|
||||
preventScrollReset,
|
||||
viewTransition
|
||||
} = _ref9,
|
||||
props = _objectWithoutPropertiesLoose(_ref9, _excluded3);
|
||||
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 == null ? void 0 : submitter.getAttribute("formmethod")) || method;
|
||||
submit(submitter || event.currentTarget, {
|
||||
fetcherKey,
|
||||
method: submitMethod,
|
||||
navigate,
|
||||
replace,
|
||||
state,
|
||||
relative,
|
||||
preventScrollReset,
|
||||
viewTransition
|
||||
});
|
||||
};
|
||||
return /*#__PURE__*/React__namespace.createElement("form", _extends({
|
||||
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(_ref0) {
|
||||
let {
|
||||
getKey,
|
||||
storageKey
|
||||
} = _ref0;
|
||||
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/v6/routers/picking-a-router.";
|
||||
}
|
||||
function useDataRouterContext(hookName) {
|
||||
let ctx = React__namespace.useContext(reactRouter.UNSAFE_DataRouterContext);
|
||||
!ctx ? router.UNSAFE_invariant(false, getDataRouterConsoleError(hookName)) : void 0;
|
||||
return ctx;
|
||||
}
|
||||
function useDataRouterState(hookName) {
|
||||
let state = React__namespace.useContext(reactRouter.UNSAFE_DataRouterStateContext);
|
||||
!state ? router.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, _temp) {
|
||||
let {
|
||||
target,
|
||||
replace: replaceProp,
|
||||
state,
|
||||
preventScrollReset,
|
||||
relative,
|
||||
viewTransition
|
||||
} = _temp === void 0 ? {} : _temp;
|
||||
let navigate = reactRouter.useNavigate();
|
||||
let location = reactRouter.useLocation();
|
||||
let path = reactRouter.useResolvedPath(to, {
|
||||
relative
|
||||
});
|
||||
return React__namespace.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 : reactRouter.createPath(location) === reactRouter.createPath(path);
|
||||
navigate(to, {
|
||||
replace,
|
||||
state,
|
||||
preventScrollReset,
|
||||
relative,
|
||||
viewTransition
|
||||
});
|
||||
}
|
||||
}, [location, navigate, path, replaceProp, state, target, to, preventScrollReset, relative, viewTransition]);
|
||||
}
|
||||
|
||||
/**
|
||||
* A convenient wrapper for reading and writing search parameters via the
|
||||
* URLSearchParams interface.
|
||||
*/
|
||||
function useSearchParams(defaultInit) {
|
||||
router.UNSAFE_warning(typeof URLSearchParams !== "undefined", "You cannot use the `useSearchParams` hook in a browser that does not " + "support the URLSearchParams API. If you need to support Internet " + "Explorer 11, we recommend you load a polyfill such as " + "https://github.com/ungap/url-search-params.") ;
|
||||
let defaultSearchParamsRef = React__namespace.useRef(createSearchParams(defaultInit));
|
||||
let hasSetSearchParamsRef = React__namespace.useRef(false);
|
||||
let location = reactRouter.useLocation();
|
||||
let searchParams = React__namespace.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 = reactRouter.useNavigate();
|
||||
let setSearchParams = React__namespace.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__namespace.useContext(reactRouter.UNSAFE_NavigationContext);
|
||||
let currentRouteId = reactRouter.UNSAFE_useRouteId();
|
||||
return React__namespace.useCallback(function (target, options) {
|
||||
if (options === void 0) {
|
||||
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,
|
||||
flushSync: options.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,
|
||||
flushSync: options.flushSync,
|
||||
viewTransition: options.viewTransition
|
||||
});
|
||||
}
|
||||
}, [router, basename, currentRouteId]);
|
||||
}
|
||||
|
||||
// v7: Eventually we should deprecate this entirely in favor of using the
|
||||
// router method directly?
|
||||
function useFormAction(action, _temp2) {
|
||||
let {
|
||||
relative
|
||||
} = _temp2 === void 0 ? {} : _temp2;
|
||||
let {
|
||||
basename
|
||||
} = React__namespace.useContext(reactRouter.UNSAFE_NavigationContext);
|
||||
let routeContext = React__namespace.useContext(reactRouter.UNSAFE_RouteContext);
|
||||
!routeContext ? router.UNSAFE_invariant(false, "useFormAction must be used inside a RouteContext") : void 0;
|
||||
let [match] = routeContext.matches.slice(-1);
|
||||
// Shallow clone path so we can modify it below, otherwise we modify the
|
||||
// object referenced by useMemo inside useResolvedPath
|
||||
let path = _extends({}, reactRouter.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 = reactRouter.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);
|
||||
let indexValues = params.getAll("index");
|
||||
let hasNakedIndexParam = indexValues.some(v => v === "");
|
||||
if (hasNakedIndexParam) {
|
||||
params.delete("index");
|
||||
indexValues.filter(v => v).forEach(v => params.append("index", v));
|
||||
let qs = params.toString();
|
||||
path.search = qs ? "?" + qs : "";
|
||||
}
|
||||
}
|
||||
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 : router.joinPaths([basename, path.pathname]);
|
||||
}
|
||||
return reactRouter.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(_temp3) {
|
||||
var _route$matches;
|
||||
let {
|
||||
key
|
||||
} = _temp3 === void 0 ? {} : _temp3;
|
||||
let {
|
||||
router: router$1
|
||||
} = useDataRouterContext(DataRouterHook.UseFetcher);
|
||||
let state = useDataRouterState(DataRouterStateHook.UseFetcher);
|
||||
let fetcherData = React__namespace.useContext(FetchersContext);
|
||||
let route = React__namespace.useContext(reactRouter.UNSAFE_RouteContext);
|
||||
let routeId = (_route$matches = route.matches[route.matches.length - 1]) == null ? void 0 : _route$matches.route.id;
|
||||
!fetcherData ? router.UNSAFE_invariant(false, "useFetcher must be used inside a FetchersContext") : void 0;
|
||||
!route ? router.UNSAFE_invariant(false, "useFetcher must be used inside a RouteContext") : void 0;
|
||||
!(routeId != null) ? router.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__namespace.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__namespace.useEffect(() => {
|
||||
router$1.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$1.deleteFetcher(fetcherKey);
|
||||
};
|
||||
}, [router$1, fetcherKey]);
|
||||
|
||||
// Fetcher additions
|
||||
let load = React__namespace.useCallback((href, opts) => {
|
||||
!routeId ? router.UNSAFE_invariant(false, "No routeId available for fetcher.load()") : void 0;
|
||||
router$1.fetch(fetcherKey, routeId, href, opts);
|
||||
}, [fetcherKey, routeId, router$1]);
|
||||
let submitImpl = useSubmit();
|
||||
let submit = React__namespace.useCallback((target, opts) => {
|
||||
submitImpl(target, _extends({}, opts, {
|
||||
navigate: false,
|
||||
fetcherKey
|
||||
}));
|
||||
}, [fetcherKey, submitImpl]);
|
||||
let FetcherForm = React__namespace.useMemo(() => {
|
||||
let FetcherForm = /*#__PURE__*/React__namespace.forwardRef((props, ref) => {
|
||||
return /*#__PURE__*/React__namespace.createElement(Form, _extends({}, props, {
|
||||
navigate: false,
|
||||
fetcherKey: fetcherKey,
|
||||
ref: ref
|
||||
}));
|
||||
});
|
||||
{
|
||||
FetcherForm.displayName = "fetcher.Form";
|
||||
}
|
||||
return FetcherForm;
|
||||
}, [fetcherKey]);
|
||||
|
||||
// Exposed FetcherWithComponents
|
||||
let fetcher = state.fetchers.get(fetcherKey) || router.IDLE_FETCHER;
|
||||
let data = fetcherData.get(fetcherKey);
|
||||
let fetcherWithComponents = React__namespace.useMemo(() => _extends({
|
||||
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(_ref1 => {
|
||||
let [key, fetcher] = _ref1;
|
||||
return _extends({}, 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(_temp4) {
|
||||
let {
|
||||
getKey,
|
||||
storageKey
|
||||
} = _temp4 === void 0 ? {} : _temp4;
|
||||
let {
|
||||
router: router$1
|
||||
} = useDataRouterContext(DataRouterHook.UseScrollRestoration);
|
||||
let {
|
||||
restoreScrollPosition,
|
||||
preventScrollReset
|
||||
} = useDataRouterState(DataRouterStateHook.UseScrollRestoration);
|
||||
let {
|
||||
basename
|
||||
} = React__namespace.useContext(reactRouter.UNSAFE_NavigationContext);
|
||||
let location = reactRouter.useLocation();
|
||||
let matches = reactRouter.useMatches();
|
||||
let navigation = reactRouter.useNavigation();
|
||||
|
||||
// Trigger manual scroll restoration while we're active
|
||||
React__namespace.useEffect(() => {
|
||||
window.history.scrollRestoration = "manual";
|
||||
return () => {
|
||||
window.history.scrollRestoration = "auto";
|
||||
};
|
||||
}, []);
|
||||
|
||||
// Save positions on pagehide
|
||||
usePageHide(React__namespace.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) {
|
||||
router.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__namespace.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__namespace.useLayoutEffect(() => {
|
||||
let getKeyWithoutBasename = getKey && basename !== "/" ? (location, matches) => getKey(// Strip the basename to match useLocation()
|
||||
_extends({}, location, {
|
||||
pathname: router.stripBasename(location.pathname, basename) || location.pathname
|
||||
}), matches) : getKey;
|
||||
let disableScrollRestoration = router$1 == null ? void 0 : router$1.enableScrollRestoration(savedScrollPositions, () => window.scrollY, getKeyWithoutBasename);
|
||||
return () => disableScrollRestoration && disableScrollRestoration();
|
||||
}, [router$1, basename, getKey]);
|
||||
|
||||
// Restore scrolling when state.restoreScrollPosition changes
|
||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||
React__namespace.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__namespace.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__namespace.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(_ref10) {
|
||||
let {
|
||||
when,
|
||||
message
|
||||
} = _ref10;
|
||||
let blocker = reactRouter.useBlocker(when);
|
||||
React__namespace.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__namespace.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) {
|
||||
if (opts === void 0) {
|
||||
opts = {};
|
||||
}
|
||||
let vtContext = React__namespace.useContext(ViewTransitionContext);
|
||||
!(vtContext != null) ? router.UNSAFE_invariant(false, "`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 = reactRouter.useResolvedPath(to, {
|
||||
relative: opts.relative
|
||||
});
|
||||
if (!vtContext.isTransitioning) {
|
||||
return false;
|
||||
}
|
||||
let currentPath = router.stripBasename(vtContext.currentLocation.pathname, basename) || vtContext.currentLocation.pathname;
|
||||
let nextPath = router.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" viewTransition>
|
||||
//
|
||||
// If you click the breadcrumb back to the list view:
|
||||
//
|
||||
// <NavLink to="/list" 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 router.matchPath(path.pathname, nextPath) != null || router.matchPath(path.pathname, currentPath) != null;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
Object.defineProperty(exports, 'AbortedDeferredError', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.AbortedDeferredError; }
|
||||
});
|
||||
Object.defineProperty(exports, 'Await', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.Await; }
|
||||
});
|
||||
Object.defineProperty(exports, 'MemoryRouter', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.MemoryRouter; }
|
||||
});
|
||||
Object.defineProperty(exports, 'Navigate', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.Navigate; }
|
||||
});
|
||||
Object.defineProperty(exports, 'NavigationType', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.NavigationType; }
|
||||
});
|
||||
Object.defineProperty(exports, 'Outlet', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.Outlet; }
|
||||
});
|
||||
Object.defineProperty(exports, 'Route', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.Route; }
|
||||
});
|
||||
Object.defineProperty(exports, 'Router', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.Router; }
|
||||
});
|
||||
Object.defineProperty(exports, 'Routes', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.Routes; }
|
||||
});
|
||||
Object.defineProperty(exports, 'UNSAFE_DataRouterContext', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.UNSAFE_DataRouterContext; }
|
||||
});
|
||||
Object.defineProperty(exports, 'UNSAFE_DataRouterStateContext', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.UNSAFE_DataRouterStateContext; }
|
||||
});
|
||||
Object.defineProperty(exports, 'UNSAFE_LocationContext', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.UNSAFE_LocationContext; }
|
||||
});
|
||||
Object.defineProperty(exports, 'UNSAFE_NavigationContext', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.UNSAFE_NavigationContext; }
|
||||
});
|
||||
Object.defineProperty(exports, 'UNSAFE_RouteContext', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.UNSAFE_RouteContext; }
|
||||
});
|
||||
Object.defineProperty(exports, 'UNSAFE_useRouteId', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.UNSAFE_useRouteId; }
|
||||
});
|
||||
Object.defineProperty(exports, 'createMemoryRouter', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.createMemoryRouter; }
|
||||
});
|
||||
Object.defineProperty(exports, 'createPath', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.createPath; }
|
||||
});
|
||||
Object.defineProperty(exports, 'createRoutesFromChildren', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.createRoutesFromChildren; }
|
||||
});
|
||||
Object.defineProperty(exports, 'createRoutesFromElements', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.createRoutesFromElements; }
|
||||
});
|
||||
Object.defineProperty(exports, 'defer', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.defer; }
|
||||
});
|
||||
Object.defineProperty(exports, 'generatePath', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.generatePath; }
|
||||
});
|
||||
Object.defineProperty(exports, 'isRouteErrorResponse', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.isRouteErrorResponse; }
|
||||
});
|
||||
Object.defineProperty(exports, 'json', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.json; }
|
||||
});
|
||||
Object.defineProperty(exports, 'matchPath', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.matchPath; }
|
||||
});
|
||||
Object.defineProperty(exports, 'matchRoutes', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.matchRoutes; }
|
||||
});
|
||||
Object.defineProperty(exports, 'parsePath', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.parsePath; }
|
||||
});
|
||||
Object.defineProperty(exports, 'redirect', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.redirect; }
|
||||
});
|
||||
Object.defineProperty(exports, 'redirectDocument', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.redirectDocument; }
|
||||
});
|
||||
Object.defineProperty(exports, 'renderMatches', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.renderMatches; }
|
||||
});
|
||||
Object.defineProperty(exports, 'replace', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.replace; }
|
||||
});
|
||||
Object.defineProperty(exports, 'resolvePath', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.resolvePath; }
|
||||
});
|
||||
Object.defineProperty(exports, 'useActionData', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.useActionData; }
|
||||
});
|
||||
Object.defineProperty(exports, 'useAsyncError', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.useAsyncError; }
|
||||
});
|
||||
Object.defineProperty(exports, 'useAsyncValue', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.useAsyncValue; }
|
||||
});
|
||||
Object.defineProperty(exports, 'useBlocker', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.useBlocker; }
|
||||
});
|
||||
Object.defineProperty(exports, 'useHref', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.useHref; }
|
||||
});
|
||||
Object.defineProperty(exports, 'useInRouterContext', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.useInRouterContext; }
|
||||
});
|
||||
Object.defineProperty(exports, 'useLoaderData', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.useLoaderData; }
|
||||
});
|
||||
Object.defineProperty(exports, 'useLocation', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.useLocation; }
|
||||
});
|
||||
Object.defineProperty(exports, 'useMatch', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.useMatch; }
|
||||
});
|
||||
Object.defineProperty(exports, 'useMatches', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.useMatches; }
|
||||
});
|
||||
Object.defineProperty(exports, 'useNavigate', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.useNavigate; }
|
||||
});
|
||||
Object.defineProperty(exports, 'useNavigation', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.useNavigation; }
|
||||
});
|
||||
Object.defineProperty(exports, 'useNavigationType', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.useNavigationType; }
|
||||
});
|
||||
Object.defineProperty(exports, 'useOutlet', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.useOutlet; }
|
||||
});
|
||||
Object.defineProperty(exports, 'useOutletContext', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.useOutletContext; }
|
||||
});
|
||||
Object.defineProperty(exports, 'useParams', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.useParams; }
|
||||
});
|
||||
Object.defineProperty(exports, 'useResolvedPath', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.useResolvedPath; }
|
||||
});
|
||||
Object.defineProperty(exports, 'useRevalidator', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.useRevalidator; }
|
||||
});
|
||||
Object.defineProperty(exports, 'useRouteError', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.useRouteError; }
|
||||
});
|
||||
Object.defineProperty(exports, 'useRouteLoaderData', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.useRouteLoaderData; }
|
||||
});
|
||||
Object.defineProperty(exports, 'useRoutes', {
|
||||
enumerable: true,
|
||||
get: function () { return reactRouter.useRoutes; }
|
||||
});
|
||||
Object.defineProperty(exports, 'UNSAFE_ErrorResponseImpl', {
|
||||
enumerable: true,
|
||||
get: function () { return router.UNSAFE_ErrorResponseImpl; }
|
||||
});
|
||||
exports.BrowserRouter = BrowserRouter;
|
||||
exports.Form = Form;
|
||||
exports.HashRouter = HashRouter;
|
||||
exports.Link = Link;
|
||||
exports.NavLink = NavLink;
|
||||
exports.RouterProvider = RouterProvider;
|
||||
exports.ScrollRestoration = ScrollRestoration;
|
||||
exports.UNSAFE_FetchersContext = FetchersContext;
|
||||
exports.UNSAFE_ViewTransitionContext = ViewTransitionContext;
|
||||
exports.UNSAFE_useScrollRestoration = useScrollRestoration;
|
||||
exports.createBrowserRouter = createBrowserRouter;
|
||||
exports.createHashRouter = createHashRouter;
|
||||
exports.createSearchParams = createSearchParams;
|
||||
exports.unstable_HistoryRouter = HistoryRouter;
|
||||
exports.unstable_usePrompt = usePrompt;
|
||||
exports.useBeforeUnload = useBeforeUnload;
|
||||
exports.useFetcher = useFetcher;
|
||||
exports.useFetchers = useFetchers;
|
||||
exports.useFormAction = useFormAction;
|
||||
exports.useLinkClickHandler = useLinkClickHandler;
|
||||
exports.useSearchParams = useSearchParams;
|
||||
exports.useSubmit = useSubmit;
|
||||
exports.useViewTransitionState = useViewTransitionState;
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
}));
|
||||
//# sourceMappingURL=react-router-dom.development.js.map
|
||||
Generated
Vendored
+1
File diff suppressed because one or more lines are too long
Generated
Vendored
+12
File diff suppressed because one or more lines are too long
Generated
Vendored
+1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user