react-router-dom 6.3.0 → 6.4.0-pre.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md CHANGED
@@ -1,7 +1,7 @@
1
1
  MIT License
2
2
 
3
3
  Copyright (c) React Training 2015-2019
4
- Copyright (c) Remix Software 2020-2021
4
+ Copyright (c) Remix Software 2020-2022
5
5
 
6
6
  Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  of this software and associated documentation files (the "Software"), to deal
package/dom.d.ts ADDED
@@ -0,0 +1,68 @@
1
+ import type { FormEncType, FormMethod } from "@remix-run/router";
2
+ export declare const defaultMethod = "get";
3
+ export declare function isHtmlElement(object: any): object is HTMLElement;
4
+ export declare function isButtonElement(object: any): object is HTMLButtonElement;
5
+ export declare function isFormElement(object: any): object is HTMLFormElement;
6
+ export declare function isInputElement(object: any): object is HTMLInputElement;
7
+ declare type LimitedMouseEvent = Pick<MouseEvent, "button" | "metaKey" | "altKey" | "ctrlKey" | "shiftKey">;
8
+ export declare function shouldProcessLinkClick(event: LimitedMouseEvent, target?: string): boolean;
9
+ export declare type ParamKeyValuePair = [string, string];
10
+ export declare type URLSearchParamsInit = string | ParamKeyValuePair[] | Record<string, string | string[]> | URLSearchParams;
11
+ /**
12
+ * Creates a URLSearchParams object using the given initializer.
13
+ *
14
+ * This is identical to `new URLSearchParams(init)` except it also
15
+ * supports arrays as values in the object form of the initializer
16
+ * instead of just strings. This is convenient when you need multiple
17
+ * values for a given key, but don't want to use an array initializer.
18
+ *
19
+ * For example, instead of:
20
+ *
21
+ * let searchParams = new URLSearchParams([
22
+ * ['sort', 'name'],
23
+ * ['sort', 'price']
24
+ * ]);
25
+ *
26
+ * you can do:
27
+ *
28
+ * let searchParams = createSearchParams({
29
+ * sort: ['name', 'price']
30
+ * });
31
+ */
32
+ export declare function createSearchParams(init?: URLSearchParamsInit): URLSearchParams;
33
+ export declare function getSearchParamsForLocation(locationSearch: string, defaultSearchParams: URLSearchParams): URLSearchParams;
34
+ export interface SubmitOptions {
35
+ /**
36
+ * The HTTP method used to submit the form. Overrides `<form method>`.
37
+ * Defaults to "GET".
38
+ */
39
+ method?: FormMethod;
40
+ /**
41
+ * The action URL path used to submit the form. Overrides `<form action>`.
42
+ * Defaults to the path of the current route.
43
+ *
44
+ * Note: It is assumed the path is already resolved. If you need to resolve a
45
+ * relative path, use `useFormAction`.
46
+ */
47
+ action?: string;
48
+ /**
49
+ * The action URL used to submit the form. Overrides `<form encType>`.
50
+ * Defaults to "application/x-www-form-urlencoded".
51
+ */
52
+ encType?: FormEncType;
53
+ /**
54
+ * Set `true` to replace the current entry in the browser's history stack
55
+ * instead of creating a new one (i.e. stay on "the same page"). Defaults
56
+ * to `false`.
57
+ */
58
+ replace?: boolean;
59
+ }
60
+ export declare function getFormSubmissionInfo(target: HTMLFormElement | HTMLButtonElement | HTMLInputElement | FormData | URLSearchParams | {
61
+ [name: string]: string;
62
+ } | null, defaultAction: string, options: SubmitOptions): {
63
+ url: URL;
64
+ method: string;
65
+ encType: string;
66
+ formData: FormData;
67
+ };
68
+ export {};
package/index.d.ts CHANGED
@@ -3,14 +3,32 @@
3
3
  * you'll need to update the rollup config for react-router-dom-v5-compat.
4
4
  */
5
5
  import * as React from "react";
6
- import type { History } from "history";
7
- import { MemoryRouter, Navigate, Outlet, Route, Router, Routes, createRoutesFromChildren, generatePath, matchRoutes, matchPath, createPath, parsePath, resolvePath, renderMatches, useHref, useInRouterContext, useLocation, useMatch, useNavigate, useNavigationType, useOutlet, useParams, useResolvedPath, useRoutes, useOutletContext } from "react-router";
8
6
  import type { To } from "react-router";
9
- export { MemoryRouter, Navigate, Outlet, Route, Router, Routes, createRoutesFromChildren, generatePath, matchRoutes, matchPath, createPath, parsePath, renderMatches, resolvePath, useHref, useInRouterContext, useLocation, useMatch, useNavigate, useNavigationType, useOutlet, useParams, useResolvedPath, useRoutes, useOutletContext, };
10
- export { NavigationType } from "react-router";
11
- export type { Hash, Location, Path, To, MemoryRouterProps, NavigateFunction, NavigateOptions, NavigateProps, Navigator, OutletProps, Params, PathMatch, RouteMatch, RouteObject, RouteProps, PathRouteProps, LayoutRouteProps, IndexRouteProps, RouterProps, Pathname, Search, RoutesProps, } from "react-router";
7
+ import type { Fetcher, FormMethod, History, HydrationState, GetScrollRestorationKeyFunction, RouteObject } from "@remix-run/router";
8
+ import type { SubmitOptions, ParamKeyValuePair, URLSearchParamsInit } from "./dom";
9
+ import { createSearchParams } from "./dom";
10
+ export type { ParamKeyValuePair, URLSearchParamsInit };
11
+ export { createSearchParams };
12
+ export type { ActionFunction, DataMemoryRouterProps, DataRouteMatch, Fetcher, Hash, IndexRouteProps, JsonFunction, LayoutRouteProps, LoaderFunction, Location, MemoryRouterProps, NavigateFunction, NavigateOptions, NavigateProps, Navigation, Navigator, OutletProps, Params, Path, PathMatch, Pathname, PathPattern, PathRouteProps, RedirectFunction, RouteMatch, RouteObject, RouteProps, RouterProps, RoutesProps, Search, ShouldRevalidateFunction, To, } from "react-router";
13
+ export { DataMemoryRouter, MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, Routes, createPath, createRoutesFromChildren, isRouteErrorResponse, generatePath, json, matchPath, matchRoutes, parsePath, redirect, renderMatches, resolvePath, useActionData, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes, } from "react-router";
12
14
  /** @internal */
13
- export { UNSAFE_NavigationContext, UNSAFE_LocationContext, UNSAFE_RouteContext, } from "react-router";
15
+ export { UNSAFE_NavigationContext, UNSAFE_LocationContext, UNSAFE_RouteContext, UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, useRenderDataRouter, } from "react-router";
16
+ export interface DataBrowserRouterProps {
17
+ children?: React.ReactNode;
18
+ hydrationData?: HydrationState;
19
+ fallbackElement: React.ReactElement;
20
+ routes?: RouteObject[];
21
+ window?: Window;
22
+ }
23
+ export declare function DataBrowserRouter({ children, fallbackElement, hydrationData, routes, window, }: DataBrowserRouterProps): React.ReactElement;
24
+ export interface DataHashRouterProps {
25
+ children?: React.ReactNode;
26
+ hydrationData?: HydrationState;
27
+ fallbackElement: React.ReactElement;
28
+ routes?: RouteObject[];
29
+ window?: Window;
30
+ }
31
+ export declare function DataHashRouter({ children, hydrationData, fallbackElement, routes, window, }: DataBrowserRouterProps): React.ReactElement;
14
32
  export interface BrowserRouterProps {
15
33
  basename?: string;
16
34
  children?: React.ReactNode;
@@ -50,6 +68,7 @@ export interface LinkProps extends Omit<React.AnchorHTMLAttributes<HTMLAnchorEle
50
68
  reloadDocument?: boolean;
51
69
  replace?: boolean;
52
70
  state?: any;
71
+ resetScroll?: boolean;
53
72
  to: To;
54
73
  }
55
74
  /**
@@ -59,29 +78,74 @@ export declare const Link: React.ForwardRefExoticComponent<LinkProps & React.Ref
59
78
  export interface NavLinkProps extends Omit<LinkProps, "className" | "style" | "children"> {
60
79
  children?: React.ReactNode | ((props: {
61
80
  isActive: boolean;
81
+ isPending: boolean;
62
82
  }) => React.ReactNode);
63
83
  caseSensitive?: boolean;
64
84
  className?: string | ((props: {
65
85
  isActive: boolean;
86
+ isPending: boolean;
66
87
  }) => string | undefined);
67
88
  end?: boolean;
68
89
  style?: React.CSSProperties | ((props: {
69
90
  isActive: boolean;
91
+ isPending: boolean;
70
92
  }) => React.CSSProperties);
71
93
  }
72
94
  /**
73
95
  * A <Link> wrapper that knows if it's "active" or not.
74
96
  */
75
97
  export declare const NavLink: React.ForwardRefExoticComponent<NavLinkProps & React.RefAttributes<HTMLAnchorElement>>;
98
+ export interface FormProps extends React.FormHTMLAttributes<HTMLFormElement> {
99
+ /**
100
+ * The HTTP verb to use when the form is submit. Supports "get", "post",
101
+ * "put", "delete", "patch".
102
+ */
103
+ method?: FormMethod;
104
+ /**
105
+ * Normal `<form action>` but supports React Router's relative paths.
106
+ */
107
+ action?: string;
108
+ /**
109
+ * Replaces the current entry in the browser history stack when the form
110
+ * navigates. Use this if you don't want the user to be able to click "back"
111
+ * to the page with the form on it.
112
+ */
113
+ replace?: boolean;
114
+ /**
115
+ * A function to call when the form is submitted. If you call
116
+ * `event.preventDefault()` then this form will not do anything.
117
+ */
118
+ onSubmit?: React.FormEventHandler<HTMLFormElement>;
119
+ }
120
+ /**
121
+ * A `@remix-run/router`-aware `<form>`. It behaves like a normal form except
122
+ * that the interaction with the server is with `fetch` instead of new document
123
+ * requests, allowing components to add nicer UX to the page as the form is
124
+ * submitted and returns with data.
125
+ */
126
+ export declare const Form: React.ForwardRefExoticComponent<FormProps & React.RefAttributes<HTMLFormElement>>;
127
+ interface ScrollRestorationProps {
128
+ getKey?: GetScrollRestorationKeyFunction;
129
+ storageKey?: string;
130
+ }
131
+ /**
132
+ * This component will emulate the browser's scroll restoration on location
133
+ * changes.
134
+ */
135
+ export declare function ScrollRestoration({ getKey, storageKey, }: ScrollRestorationProps): null;
136
+ export declare namespace ScrollRestoration {
137
+ var displayName: string;
138
+ }
76
139
  /**
77
140
  * Handles the click behavior for router `<Link>` components. This is useful if
78
141
  * you need to create custom `<Link>` components with the same click behavior we
79
142
  * use in our exported `<Link>`.
80
143
  */
81
- export declare function useLinkClickHandler<E extends Element = HTMLAnchorElement>(to: To, { target, replace: replaceProp, state, }?: {
144
+ export declare function useLinkClickHandler<E extends Element = HTMLAnchorElement>(to: To, { target, replace: replaceProp, state, resetScroll, }?: {
82
145
  target?: React.HTMLAttributeAnchorTarget;
83
146
  replace?: boolean;
84
147
  state?: any;
148
+ resetScroll?: boolean;
85
149
  }): (event: React.MouseEvent<E, MouseEvent>) => void;
86
150
  /**
87
151
  * A convenient wrapper for reading and writing search parameters via the
@@ -91,27 +155,48 @@ export declare function useSearchParams(defaultInit?: URLSearchParamsInit): read
91
155
  replace?: boolean | undefined;
92
156
  state?: any;
93
157
  } | undefined) => void];
94
- export declare type ParamKeyValuePair = [string, string];
95
- export declare type URLSearchParamsInit = string | ParamKeyValuePair[] | Record<string, string | string[]> | URLSearchParams;
96
158
  /**
97
- * Creates a URLSearchParams object using the given initializer.
98
- *
99
- * This is identical to `new URLSearchParams(init)` except it also
100
- * supports arrays as values in the object form of the initializer
101
- * instead of just strings. This is convenient when you need multiple
102
- * values for a given key, but don't want to use an array initializer.
103
- *
104
- * For example, instead of:
105
- *
106
- * let searchParams = new URLSearchParams([
107
- * ['sort', 'name'],
108
- * ['sort', 'price']
109
- * ]);
110
- *
111
- * you can do:
112
- *
113
- * let searchParams = createSearchParams({
114
- * sort: ['name', 'price']
115
- * });
159
+ * Submits a HTML `<form>` to the server without reloading the page.
160
+ */
161
+ export interface SubmitFunction {
162
+ (
163
+ /**
164
+ * Specifies the `<form>` to be submitted to the server, a specific
165
+ * `<button>` or `<input type="submit">` to use to submit the form, or some
166
+ * arbitrary data to submit.
167
+ *
168
+ * Note: When using a `<button>` its `name` and `value` will also be
169
+ * included in the form data that is submitted.
170
+ */
171
+ target: HTMLFormElement | HTMLButtonElement | HTMLInputElement | FormData | URLSearchParams | {
172
+ [name: string]: string;
173
+ } | null,
174
+ /**
175
+ * Options that override the `<form>`'s own attributes. Required when
176
+ * submitting arbitrary data without a backing `<form>`.
177
+ */
178
+ options?: SubmitOptions): void;
179
+ }
180
+ /**
181
+ * Returns a function that may be used to programmatically submit a form (or
182
+ * some arbitrary data) to the server.
183
+ */
184
+ export declare function useSubmit(): SubmitFunction;
185
+ declare function useSubmitImpl(fetcherKey?: string): SubmitFunction;
186
+ export declare function useFormAction(action?: string): string;
187
+ declare function createFetcherForm(fetcherKey: string): React.ForwardRefExoticComponent<FormProps & React.RefAttributes<HTMLFormElement>>;
188
+ declare type FetcherWithComponents<TData> = Fetcher<TData> & {
189
+ Form: ReturnType<typeof createFetcherForm>;
190
+ submit: ReturnType<typeof useSubmitImpl>;
191
+ load: (href: string) => void;
192
+ };
193
+ /**
194
+ * Interacts with route loaders and actions without causing a navigation. Great
195
+ * for any interaction that stays on the same page.
196
+ */
197
+ export declare function useFetcher<TData = any>(): FetcherWithComponents<TData>;
198
+ /**
199
+ * Provides all fetchers currently on the page. Useful for layouts and parent
200
+ * routes that need to provide pending/optimistic UI regarding the fetch.
116
201
  */
117
- export declare function createSearchParams(init?: URLSearchParamsInit): URLSearchParams;
202
+ export declare function useFetchers(): Fetcher[];