react-router-dom 6.4.0-pre.2 → 6.4.0-pre.5
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/CHANGELOG.md +22 -0
- package/{dom.d.ts → dist/dom.d.ts} +0 -0
- package/{index.d.ts → dist/index.d.ts} +9 -11
- package/{index.js → dist/index.js} +71 -93
- package/dist/index.js.map +1 -0
- package/{main.js → dist/main.js} +1 -1
- package/{react-router-dom.development.js → dist/react-router-dom.development.js} +63 -83
- package/dist/react-router-dom.development.js.map +1 -0
- package/dist/react-router-dom.production.min.js +12 -0
- package/dist/react-router-dom.production.min.js.map +1 -0
- package/dist/server.d.ts +23 -0
- package/dist/server.js +125 -0
- package/dist/server.mjs +101 -0
- package/{umd → dist/umd}/react-router-dom.development.js +132 -215
- package/dist/umd/react-router-dom.development.js.map +1 -0
- package/dist/umd/react-router-dom.production.min.js +12 -0
- package/dist/umd/react-router-dom.production.min.js.map +1 -0
- package/package.json +29 -16
- package/server.js +25 -5
- package/server.mjs +8 -7
- package/index.js.map +0 -1
- package/react-router-dom.development.js.map +0 -1
- package/react-router-dom.production.min.js +0 -12
- package/react-router-dom.production.min.js.map +0 -1
- package/umd/react-router-dom.development.js.map +0 -1
- package/umd/react-router-dom.production.min.js +0 -12
- package/umd/react-router-dom.production.min.js.map +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# react-router-dom
|
|
2
|
+
|
|
3
|
+
## 6.4.0-pre.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fix broken require for CJS builds
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- react-router@6.4.0-pre.5
|
|
10
|
+
|
|
11
|
+
## 6.4.0-pre.4
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Fix missing `dist` files
|
|
16
|
+
|
|
17
|
+
## 6.4.0-pre.3
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Make `fallbackElement` optional and change type to `ReactNode` (type changes only) (#8896)
|
|
22
|
+
- Properly trigger error boundaries on 404 routes
|
|
File without changes
|
|
@@ -3,20 +3,20 @@
|
|
|
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 { To } from "react-router";
|
|
7
|
-
import type { Fetcher, FormMethod, History, HydrationState,
|
|
6
|
+
import type { NavigateOptions, To } from "react-router";
|
|
7
|
+
import type { Fetcher, FormMethod, GetScrollRestorationKeyFunction, History, HydrationState, RouteObject } from "@remix-run/router";
|
|
8
8
|
import type { SubmitOptions, ParamKeyValuePair, URLSearchParamsInit } from "./dom";
|
|
9
9
|
import { createSearchParams } from "./dom";
|
|
10
10
|
export type { ParamKeyValuePair, URLSearchParamsInit };
|
|
11
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";
|
|
12
|
+
export type { ActionFunction, DataMemoryRouterProps, DataRouteMatch, Fetcher, Hash, IndexRouteProps, JsonFunction, LayoutRouteProps, LoaderFunction, Location, MemoryRouterProps, NavigateFunction, NavigateOptions, NavigateProps, Navigation, Navigator, OutletProps, Params, ParamParseKey, Path, PathMatch, Pathname, PathPattern, PathRouteProps, RedirectFunction, RouteMatch, RouteObject, RouteProps, RouterProps, RoutesProps, Search, ShouldRevalidateFunction, To, } from "react-router";
|
|
13
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";
|
|
14
14
|
/** @internal */
|
|
15
|
-
export { UNSAFE_NavigationContext, UNSAFE_LocationContext, UNSAFE_RouteContext, UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, useRenderDataRouter, } from "react-router";
|
|
15
|
+
export { UNSAFE_NavigationContext, UNSAFE_LocationContext, UNSAFE_RouteContext, UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, UNSAFE_resetModuleScope, useRenderDataRouter, } from "react-router";
|
|
16
16
|
export interface DataBrowserRouterProps {
|
|
17
17
|
children?: React.ReactNode;
|
|
18
18
|
hydrationData?: HydrationState;
|
|
19
|
-
fallbackElement
|
|
19
|
+
fallbackElement?: React.ReactNode;
|
|
20
20
|
routes?: RouteObject[];
|
|
21
21
|
window?: Window;
|
|
22
22
|
}
|
|
@@ -24,7 +24,7 @@ export declare function DataBrowserRouter({ children, fallbackElement, hydration
|
|
|
24
24
|
export interface DataHashRouterProps {
|
|
25
25
|
children?: React.ReactNode;
|
|
26
26
|
hydrationData?: HydrationState;
|
|
27
|
-
fallbackElement
|
|
27
|
+
fallbackElement?: React.ReactNode;
|
|
28
28
|
routes?: RouteObject[];
|
|
29
29
|
window?: Window;
|
|
30
30
|
}
|
|
@@ -89,7 +89,7 @@ export interface NavLinkProps extends Omit<LinkProps, "className" | "style" | "c
|
|
|
89
89
|
style?: React.CSSProperties | ((props: {
|
|
90
90
|
isActive: boolean;
|
|
91
91
|
isPending: boolean;
|
|
92
|
-
}) => React.CSSProperties);
|
|
92
|
+
}) => React.CSSProperties | undefined);
|
|
93
93
|
}
|
|
94
94
|
/**
|
|
95
95
|
* A <Link> wrapper that knows if it's "active" or not.
|
|
@@ -151,10 +151,8 @@ export declare function useLinkClickHandler<E extends Element = HTMLAnchorElemen
|
|
|
151
151
|
* A convenient wrapper for reading and writing search parameters via the
|
|
152
152
|
* URLSearchParams interface.
|
|
153
153
|
*/
|
|
154
|
-
export declare function useSearchParams(defaultInit?: URLSearchParamsInit):
|
|
155
|
-
|
|
156
|
-
state?: any;
|
|
157
|
-
} | undefined) => void];
|
|
154
|
+
export declare function useSearchParams(defaultInit?: URLSearchParamsInit): [URLSearchParams, SetURLSearchParams];
|
|
155
|
+
declare type SetURLSearchParams = (nextInit?: URLSearchParamsInit | ((prev: URLSearchParams) => URLSearchParamsInit), navigateOpts?: NavigateOptions) => void;
|
|
158
156
|
/**
|
|
159
157
|
* Submits a HTML `<form>` to the server without reloading the page.
|
|
160
158
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* React Router DOM v6.4.0-pre.
|
|
2
|
+
* React Router DOM v6.4.0-pre.5
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
import
|
|
11
|
+
import * as React from 'react';
|
|
12
12
|
import { useRenderDataRouter, Router, useHref, createPath, useResolvedPath, useMatch, UNSAFE_DataRouterStateContext, useNavigate, useLocation, UNSAFE_DataRouterContext, UNSAFE_RouteContext } from 'react-router';
|
|
13
|
-
export { DataMemoryRouter, MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, Routes, UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, UNSAFE_LocationContext, UNSAFE_NavigationContext, UNSAFE_RouteContext, createPath, createRoutesFromChildren, generatePath, isRouteErrorResponse, json, matchPath, matchRoutes, parsePath, redirect, renderMatches, resolvePath, useActionData, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useRenderDataRouter, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes } from 'react-router';
|
|
13
|
+
export { DataMemoryRouter, MemoryRouter, Navigate, NavigationType, Outlet, Route, Router, Routes, UNSAFE_DataRouterContext, UNSAFE_DataRouterStateContext, UNSAFE_LocationContext, UNSAFE_NavigationContext, UNSAFE_RouteContext, UNSAFE_resetModuleScope, createPath, createRoutesFromChildren, generatePath, isRouteErrorResponse, json, matchPath, matchRoutes, parsePath, redirect, renderMatches, resolvePath, useActionData, useHref, useInRouterContext, useLoaderData, useLocation, useMatch, useMatches, useNavigate, useNavigation, useNavigationType, useOutlet, useOutletContext, useParams, useRenderDataRouter, useResolvedPath, useRevalidator, useRouteError, useRouteLoaderData, useRoutes } from 'react-router';
|
|
14
14
|
import { createBrowserRouter, createHashRouter, createBrowserHistory, createHashHistory, matchPath, invariant } from '@remix-run/router';
|
|
15
15
|
|
|
16
16
|
function _extends() {
|
|
17
|
-
_extends = Object.assign
|
|
17
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
18
18
|
for (var i = 1; i < arguments.length; i++) {
|
|
19
19
|
var source = arguments[i];
|
|
20
20
|
|
|
@@ -27,7 +27,6 @@ function _extends() {
|
|
|
27
27
|
|
|
28
28
|
return target;
|
|
29
29
|
};
|
|
30
|
-
|
|
31
30
|
return _extends.apply(this, arguments);
|
|
32
31
|
}
|
|
33
32
|
|
|
@@ -71,7 +70,6 @@ function shouldProcessLinkClick(event, target) {
|
|
|
71
70
|
!isModifiedEvent(event) // Ignore clicks with modifier keys
|
|
72
71
|
;
|
|
73
72
|
}
|
|
74
|
-
|
|
75
73
|
/**
|
|
76
74
|
* Creates a URLSearchParams object using the given initializer.
|
|
77
75
|
*
|
|
@@ -93,6 +91,7 @@ function shouldProcessLinkClick(event, target) {
|
|
|
93
91
|
* sort: ['name', 'price']
|
|
94
92
|
* });
|
|
95
93
|
*/
|
|
94
|
+
|
|
96
95
|
function createSearchParams(init) {
|
|
97
96
|
if (init === void 0) {
|
|
98
97
|
init = "";
|
|
@@ -177,17 +176,6 @@ function getFormSubmissionInfo(target, defaultAction, options) {
|
|
|
177
176
|
host
|
|
178
177
|
} = window.location;
|
|
179
178
|
let url = new URL(action, protocol + "//" + host);
|
|
180
|
-
|
|
181
|
-
if (method.toLowerCase() === "get") {
|
|
182
|
-
for (let [name, value] of formData) {
|
|
183
|
-
if (typeof value === "string") {
|
|
184
|
-
url.searchParams.append(name, value);
|
|
185
|
-
} else {
|
|
186
|
-
throw new Error("Cannot submit binary form data using GET");
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
179
|
return {
|
|
192
180
|
url,
|
|
193
181
|
method,
|
|
@@ -199,10 +187,6 @@ function getFormSubmissionInfo(target, defaultAction, options) {
|
|
|
199
187
|
const _excluded = ["onClick", "reloadDocument", "replace", "state", "target", "to", "resetScroll"],
|
|
200
188
|
_excluded2 = ["aria-current", "caseSensitive", "className", "end", "style", "to", "children"],
|
|
201
189
|
_excluded3 = ["replace", "method", "action", "onSubmit", "fetcherKey"];
|
|
202
|
-
////////////////////////////////////////////////////////////////////////////////
|
|
203
|
-
//#region Components
|
|
204
|
-
////////////////////////////////////////////////////////////////////////////////
|
|
205
|
-
|
|
206
190
|
function DataBrowserRouter(_ref) {
|
|
207
191
|
let {
|
|
208
192
|
children,
|
|
@@ -241,17 +225,17 @@ function DataHashRouter(_ref2) {
|
|
|
241
225
|
})
|
|
242
226
|
});
|
|
243
227
|
}
|
|
244
|
-
|
|
245
228
|
/**
|
|
246
229
|
* A `<Router>` for use in web browsers. Provides the cleanest URLs.
|
|
247
230
|
*/
|
|
231
|
+
|
|
248
232
|
function BrowserRouter(_ref3) {
|
|
249
233
|
let {
|
|
250
234
|
basename,
|
|
251
235
|
children,
|
|
252
236
|
window
|
|
253
237
|
} = _ref3;
|
|
254
|
-
let historyRef = useRef();
|
|
238
|
+
let historyRef = React.useRef();
|
|
255
239
|
|
|
256
240
|
if (historyRef.current == null) {
|
|
257
241
|
historyRef.current = createBrowserHistory({
|
|
@@ -261,12 +245,12 @@ function BrowserRouter(_ref3) {
|
|
|
261
245
|
}
|
|
262
246
|
|
|
263
247
|
let history = historyRef.current;
|
|
264
|
-
let [state, setState] = useState({
|
|
248
|
+
let [state, setState] = React.useState({
|
|
265
249
|
action: history.action,
|
|
266
250
|
location: history.location
|
|
267
251
|
});
|
|
268
|
-
useLayoutEffect(() => history.listen(setState), [history]);
|
|
269
|
-
return /*#__PURE__*/createElement(Router, {
|
|
252
|
+
React.useLayoutEffect(() => history.listen(setState), [history]);
|
|
253
|
+
return /*#__PURE__*/React.createElement(Router, {
|
|
270
254
|
basename: basename,
|
|
271
255
|
children: children,
|
|
272
256
|
location: state.location,
|
|
@@ -274,18 +258,18 @@ function BrowserRouter(_ref3) {
|
|
|
274
258
|
navigator: history
|
|
275
259
|
});
|
|
276
260
|
}
|
|
277
|
-
|
|
278
261
|
/**
|
|
279
262
|
* A `<Router>` for use in web browsers. Stores the location in the hash
|
|
280
263
|
* portion of the URL so it is not sent to the server.
|
|
281
264
|
*/
|
|
265
|
+
|
|
282
266
|
function HashRouter(_ref4) {
|
|
283
267
|
let {
|
|
284
268
|
basename,
|
|
285
269
|
children,
|
|
286
270
|
window
|
|
287
271
|
} = _ref4;
|
|
288
|
-
let historyRef = useRef();
|
|
272
|
+
let historyRef = React.useRef();
|
|
289
273
|
|
|
290
274
|
if (historyRef.current == null) {
|
|
291
275
|
historyRef.current = createHashHistory({
|
|
@@ -295,12 +279,12 @@ function HashRouter(_ref4) {
|
|
|
295
279
|
}
|
|
296
280
|
|
|
297
281
|
let history = historyRef.current;
|
|
298
|
-
let [state, setState] = useState({
|
|
282
|
+
let [state, setState] = React.useState({
|
|
299
283
|
action: history.action,
|
|
300
284
|
location: history.location
|
|
301
285
|
});
|
|
302
|
-
useLayoutEffect(() => history.listen(setState), [history]);
|
|
303
|
-
return /*#__PURE__*/createElement(Router, {
|
|
286
|
+
React.useLayoutEffect(() => history.listen(setState), [history]);
|
|
287
|
+
return /*#__PURE__*/React.createElement(Router, {
|
|
304
288
|
basename: basename,
|
|
305
289
|
children: children,
|
|
306
290
|
location: state.location,
|
|
@@ -308,25 +292,25 @@ function HashRouter(_ref4) {
|
|
|
308
292
|
navigator: history
|
|
309
293
|
});
|
|
310
294
|
}
|
|
311
|
-
|
|
312
295
|
/**
|
|
313
296
|
* A `<Router>` that accepts a pre-instantiated history object. It's important
|
|
314
297
|
* to note that using your own history object is highly discouraged and may add
|
|
315
298
|
* two versions of the history library to your bundles unless you use the same
|
|
316
299
|
* version of the history library that React Router uses internally.
|
|
317
300
|
*/
|
|
301
|
+
|
|
318
302
|
function HistoryRouter(_ref5) {
|
|
319
303
|
let {
|
|
320
304
|
basename,
|
|
321
305
|
children,
|
|
322
306
|
history
|
|
323
307
|
} = _ref5;
|
|
324
|
-
const [state, setState] = useState({
|
|
308
|
+
const [state, setState] = React.useState({
|
|
325
309
|
action: history.action,
|
|
326
310
|
location: history.location
|
|
327
311
|
});
|
|
328
|
-
useLayoutEffect(() => history.listen(setState), [history]);
|
|
329
|
-
return /*#__PURE__*/createElement(Router, {
|
|
312
|
+
React.useLayoutEffect(() => history.listen(setState), [history]);
|
|
313
|
+
return /*#__PURE__*/React.createElement(Router, {
|
|
330
314
|
basename: basename,
|
|
331
315
|
children: children,
|
|
332
316
|
location: state.location,
|
|
@@ -338,15 +322,15 @@ function HistoryRouter(_ref5) {
|
|
|
338
322
|
if (process.env.NODE_ENV !== "production") {
|
|
339
323
|
HistoryRouter.displayName = "unstable_HistoryRouter";
|
|
340
324
|
}
|
|
341
|
-
|
|
342
325
|
/**
|
|
343
326
|
* The public API for rendering a history-aware <a>.
|
|
344
327
|
*/
|
|
345
|
-
|
|
328
|
+
|
|
329
|
+
const Link = /*#__PURE__*/React.forwardRef(function LinkWithRef(_ref6, ref) {
|
|
346
330
|
let {
|
|
347
331
|
onClick,
|
|
348
332
|
reloadDocument,
|
|
349
|
-
replace
|
|
333
|
+
replace,
|
|
350
334
|
state,
|
|
351
335
|
target,
|
|
352
336
|
to,
|
|
@@ -373,7 +357,7 @@ const Link = /*#__PURE__*/forwardRef(function LinkWithRef(_ref6, ref) {
|
|
|
373
357
|
return (
|
|
374
358
|
/*#__PURE__*/
|
|
375
359
|
// eslint-disable-next-line jsx-a11y/anchor-has-content
|
|
376
|
-
createElement("a", _extends({}, rest, {
|
|
360
|
+
React.createElement("a", _extends({}, rest, {
|
|
377
361
|
href: href,
|
|
378
362
|
onClick: handleClick,
|
|
379
363
|
ref: ref,
|
|
@@ -385,11 +369,12 @@ const Link = /*#__PURE__*/forwardRef(function LinkWithRef(_ref6, ref) {
|
|
|
385
369
|
if (process.env.NODE_ENV !== "production") {
|
|
386
370
|
Link.displayName = "Link";
|
|
387
371
|
}
|
|
388
|
-
|
|
389
372
|
/**
|
|
390
373
|
* A <Link> wrapper that knows if it's "active" or not.
|
|
391
374
|
*/
|
|
392
|
-
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
const NavLink = /*#__PURE__*/React.forwardRef(function NavLinkWithRef(_ref7, ref) {
|
|
393
378
|
let {
|
|
394
379
|
"aria-current": ariaCurrentProp = "page",
|
|
395
380
|
caseSensitive = false,
|
|
@@ -407,10 +392,10 @@ const NavLink = /*#__PURE__*/forwardRef(function NavLinkWithRef(_ref7, ref) {
|
|
|
407
392
|
end,
|
|
408
393
|
caseSensitive
|
|
409
394
|
});
|
|
410
|
-
let routerState = useContext(UNSAFE_DataRouterStateContext);
|
|
395
|
+
let routerState = React.useContext(UNSAFE_DataRouterStateContext);
|
|
411
396
|
let nextLocation = routerState == null ? void 0 : routerState.navigation.location;
|
|
412
397
|
let nextPath = useResolvedPath(nextLocation || "");
|
|
413
|
-
let nextMatch = useMemo(() => nextLocation ? matchPath({
|
|
398
|
+
let nextMatch = React.useMemo(() => nextLocation ? matchPath({
|
|
414
399
|
path: path.pathname,
|
|
415
400
|
end,
|
|
416
401
|
caseSensitive
|
|
@@ -438,7 +423,7 @@ const NavLink = /*#__PURE__*/forwardRef(function NavLinkWithRef(_ref7, ref) {
|
|
|
438
423
|
isActive,
|
|
439
424
|
isPending
|
|
440
425
|
}) : styleProp;
|
|
441
|
-
return /*#__PURE__*/createElement(Link, _extends({}, rest, {
|
|
426
|
+
return /*#__PURE__*/React.createElement(Link, _extends({}, rest, {
|
|
442
427
|
"aria-current": ariaCurrent,
|
|
443
428
|
className: className,
|
|
444
429
|
ref: ref,
|
|
@@ -453,15 +438,16 @@ const NavLink = /*#__PURE__*/forwardRef(function NavLinkWithRef(_ref7, ref) {
|
|
|
453
438
|
if (process.env.NODE_ENV !== "production") {
|
|
454
439
|
NavLink.displayName = "NavLink";
|
|
455
440
|
}
|
|
456
|
-
|
|
457
441
|
/**
|
|
458
442
|
* A `@remix-run/router`-aware `<form>`. It behaves like a normal form except
|
|
459
443
|
* that the interaction with the server is with `fetch` instead of new document
|
|
460
444
|
* requests, allowing components to add nicer UX to the page as the form is
|
|
461
445
|
* submitted and returns with data.
|
|
462
446
|
*/
|
|
463
|
-
|
|
464
|
-
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
const Form = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
450
|
+
return /*#__PURE__*/React.createElement(FormImpl, _extends({}, props, {
|
|
465
451
|
ref: ref
|
|
466
452
|
}));
|
|
467
453
|
});
|
|
@@ -470,7 +456,7 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
470
456
|
Form.displayName = "Form";
|
|
471
457
|
}
|
|
472
458
|
|
|
473
|
-
const FormImpl = /*#__PURE__*/forwardRef((_ref8, forwardedRef) => {
|
|
459
|
+
const FormImpl = /*#__PURE__*/React.forwardRef((_ref8, forwardedRef) => {
|
|
474
460
|
let {
|
|
475
461
|
replace,
|
|
476
462
|
method = defaultMethod,
|
|
@@ -495,7 +481,7 @@ const FormImpl = /*#__PURE__*/forwardRef((_ref8, forwardedRef) => {
|
|
|
495
481
|
});
|
|
496
482
|
};
|
|
497
483
|
|
|
498
|
-
return /*#__PURE__*/createElement("form", _extends({
|
|
484
|
+
return /*#__PURE__*/React.createElement("form", _extends({
|
|
499
485
|
ref: forwardedRef,
|
|
500
486
|
method: formMethod,
|
|
501
487
|
action: formAction,
|
|
@@ -506,11 +492,12 @@ const FormImpl = /*#__PURE__*/forwardRef((_ref8, forwardedRef) => {
|
|
|
506
492
|
if (process.env.NODE_ENV !== "production") {
|
|
507
493
|
Form.displayName = "Form";
|
|
508
494
|
}
|
|
509
|
-
|
|
510
495
|
/**
|
|
511
496
|
* This component will emulate the browser's scroll restoration on location
|
|
512
497
|
* changes.
|
|
513
498
|
*/
|
|
499
|
+
|
|
500
|
+
|
|
514
501
|
function ScrollRestoration(_ref9) {
|
|
515
502
|
let {
|
|
516
503
|
getKey,
|
|
@@ -547,23 +534,16 @@ function useLinkClickHandler(to, _temp) {
|
|
|
547
534
|
let navigate = useNavigate();
|
|
548
535
|
let location = useLocation();
|
|
549
536
|
let path = useResolvedPath(to);
|
|
550
|
-
return useCallback(event => {
|
|
537
|
+
return React.useCallback(event => {
|
|
551
538
|
if (shouldProcessLinkClick(event, target)) {
|
|
552
539
|
event.preventDefault(); // If the URL hasn't changed, a regular <a> will do a replace instead of
|
|
553
|
-
// a push, so do the same here
|
|
554
|
-
|
|
555
|
-
let replace = !!replaceProp || createPath(location) === createPath(path);
|
|
556
|
-
let newState = state;
|
|
557
|
-
|
|
558
|
-
if (resetScroll === false) {
|
|
559
|
-
newState = _extends({}, state, {
|
|
560
|
-
__resetScrollPosition: false
|
|
561
|
-
});
|
|
562
|
-
}
|
|
540
|
+
// a push, so do the same here unless the replace prop is explcitly set
|
|
563
541
|
|
|
542
|
+
let replace = replaceProp !== undefined ? replaceProp : createPath(location) === createPath(path);
|
|
564
543
|
navigate(to, {
|
|
565
544
|
replace,
|
|
566
|
-
state
|
|
545
|
+
state,
|
|
546
|
+
resetScroll
|
|
567
547
|
});
|
|
568
548
|
}
|
|
569
549
|
}, [location, navigate, path, replaceProp, state, target, to, resetScroll]);
|
|
@@ -575,31 +555,29 @@ function useLinkClickHandler(to, _temp) {
|
|
|
575
555
|
|
|
576
556
|
function useSearchParams(defaultInit) {
|
|
577
557
|
process.env.NODE_ENV !== "production" ? warning(typeof URLSearchParams !== "undefined", "You cannot use the `useSearchParams` hook in a browser that does not " + "support the URLSearchParams API. If you need to support Internet " + "Explorer 11, we recommend you load a polyfill such as " + "https://github.com/ungap/url-search-params\n\n" + "If you're unsure how to load polyfills, we recommend you check out " + "https://polyfill.io/v3/ which provides some recommendations about how " + "to load polyfills only for users that need them, instead of for every " + "user.") : void 0;
|
|
578
|
-
let defaultSearchParamsRef = useRef(createSearchParams(defaultInit));
|
|
558
|
+
let defaultSearchParamsRef = React.useRef(createSearchParams(defaultInit));
|
|
579
559
|
let location = useLocation();
|
|
580
|
-
let searchParams = useMemo(() => getSearchParamsForLocation(location.search, defaultSearchParamsRef.current), [location.search]);
|
|
560
|
+
let searchParams = React.useMemo(() => getSearchParamsForLocation(location.search, defaultSearchParamsRef.current), [location.search]);
|
|
581
561
|
let navigate = useNavigate();
|
|
582
|
-
let setSearchParams = useCallback((nextInit, navigateOptions) => {
|
|
583
|
-
|
|
584
|
-
|
|
562
|
+
let setSearchParams = React.useCallback((nextInit, navigateOptions) => {
|
|
563
|
+
const newSearchParams = createSearchParams(typeof nextInit === "function" ? nextInit(searchParams) : nextInit);
|
|
564
|
+
navigate("?" + newSearchParams, navigateOptions);
|
|
565
|
+
}, [navigate, searchParams]);
|
|
585
566
|
return [searchParams, setSearchParams];
|
|
586
567
|
}
|
|
587
|
-
/**
|
|
588
|
-
* Submits a HTML `<form>` to the server without reloading the page.
|
|
589
|
-
*/
|
|
590
|
-
|
|
591
568
|
/**
|
|
592
569
|
* Returns a function that may be used to programmatically submit a form (or
|
|
593
570
|
* some arbitrary data) to the server.
|
|
594
571
|
*/
|
|
572
|
+
|
|
595
573
|
function useSubmit() {
|
|
596
574
|
return useSubmitImpl();
|
|
597
575
|
}
|
|
598
576
|
|
|
599
577
|
function useSubmitImpl(fetcherKey) {
|
|
600
|
-
let router = useContext(UNSAFE_DataRouterContext);
|
|
578
|
+
let router = React.useContext(UNSAFE_DataRouterContext);
|
|
601
579
|
let defaultAction = useFormAction();
|
|
602
|
-
return useCallback(function (target, options) {
|
|
580
|
+
return React.useCallback(function (target, options) {
|
|
603
581
|
if (options === void 0) {
|
|
604
582
|
options = {};
|
|
605
583
|
}
|
|
@@ -639,8 +617,8 @@ function useFormAction(action) {
|
|
|
639
617
|
action = ".";
|
|
640
618
|
}
|
|
641
619
|
|
|
642
|
-
let routeContext = useContext(UNSAFE_RouteContext);
|
|
643
|
-
!routeContext ? process.env.NODE_ENV !== "production" ? invariant(false, "
|
|
620
|
+
let routeContext = React.useContext(UNSAFE_RouteContext);
|
|
621
|
+
!routeContext ? process.env.NODE_ENV !== "production" ? invariant(false, "useFormAction must be used inside a RouteContext") : invariant(false) : void 0;
|
|
644
622
|
let [match] = routeContext.matches.slice(-1);
|
|
645
623
|
let {
|
|
646
624
|
pathname,
|
|
@@ -655,8 +633,8 @@ function useFormAction(action) {
|
|
|
655
633
|
}
|
|
656
634
|
|
|
657
635
|
function createFetcherForm(fetcherKey) {
|
|
658
|
-
let FetcherForm = /*#__PURE__*/forwardRef((props, ref) => {
|
|
659
|
-
return /*#__PURE__*/createElement(FormImpl, _extends({}, props, {
|
|
636
|
+
let FetcherForm = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
637
|
+
return /*#__PURE__*/React.createElement(FormImpl, _extends({}, props, {
|
|
660
638
|
ref: ref,
|
|
661
639
|
fetcherKey: fetcherKey
|
|
662
640
|
}));
|
|
@@ -670,28 +648,28 @@ function createFetcherForm(fetcherKey) {
|
|
|
670
648
|
}
|
|
671
649
|
|
|
672
650
|
let fetcherId = 0;
|
|
673
|
-
|
|
674
651
|
/**
|
|
675
652
|
* Interacts with route loaders and actions without causing a navigation. Great
|
|
676
653
|
* for any interaction that stays on the same page.
|
|
677
654
|
*/
|
|
655
|
+
|
|
678
656
|
function useFetcher() {
|
|
679
|
-
let router = useContext(UNSAFE_DataRouterContext);
|
|
657
|
+
let router = React.useContext(UNSAFE_DataRouterContext);
|
|
680
658
|
!router ? process.env.NODE_ENV !== "production" ? invariant(false, "useFetcher must be used within a DataRouter") : invariant(false) : void 0;
|
|
681
|
-
let [fetcherKey] = useState(() => String(++fetcherId));
|
|
682
|
-
let [Form] = useState(() => createFetcherForm(fetcherKey));
|
|
683
|
-
let [load] = useState(() => href => {
|
|
659
|
+
let [fetcherKey] = React.useState(() => String(++fetcherId));
|
|
660
|
+
let [Form] = React.useState(() => createFetcherForm(fetcherKey));
|
|
661
|
+
let [load] = React.useState(() => href => {
|
|
684
662
|
!router ? process.env.NODE_ENV !== "production" ? invariant(false, "No router available for fetcher.load()") : invariant(false) : void 0;
|
|
685
663
|
router.fetch(fetcherKey, href);
|
|
686
664
|
});
|
|
687
665
|
let submit = useSubmitImpl(fetcherKey);
|
|
688
666
|
let fetcher = router.getFetcher(fetcherKey);
|
|
689
|
-
let fetcherWithComponents = useMemo(() => _extends({
|
|
667
|
+
let fetcherWithComponents = React.useMemo(() => _extends({
|
|
690
668
|
Form,
|
|
691
669
|
submit,
|
|
692
670
|
load
|
|
693
671
|
}, fetcher), [fetcher, Form, submit, load]);
|
|
694
|
-
useEffect(() => {
|
|
672
|
+
React.useEffect(() => {
|
|
695
673
|
// Is this busted when the React team gets real weird and calls effects
|
|
696
674
|
// twice on mount? We really just need to garbage collect here when this
|
|
697
675
|
// fetcher is no longer around.
|
|
@@ -712,7 +690,7 @@ function useFetcher() {
|
|
|
712
690
|
*/
|
|
713
691
|
|
|
714
692
|
function useFetchers() {
|
|
715
|
-
let state = useContext(UNSAFE_DataRouterStateContext);
|
|
693
|
+
let state = React.useContext(UNSAFE_DataRouterStateContext);
|
|
716
694
|
!state ? process.env.NODE_ENV !== "production" ? invariant(false, "useFetchers must be used within a DataRouter") : invariant(false) : void 0;
|
|
717
695
|
return [...state.fetchers.values()];
|
|
718
696
|
}
|
|
@@ -728,22 +706,22 @@ function useScrollRestoration(_temp2) {
|
|
|
728
706
|
storageKey
|
|
729
707
|
} = _temp2 === void 0 ? {} : _temp2;
|
|
730
708
|
let location = useLocation();
|
|
731
|
-
let router = useContext(UNSAFE_DataRouterContext);
|
|
732
|
-
let state = useContext(UNSAFE_DataRouterStateContext);
|
|
709
|
+
let router = React.useContext(UNSAFE_DataRouterContext);
|
|
710
|
+
let state = React.useContext(UNSAFE_DataRouterStateContext);
|
|
733
711
|
!(router != null && state != null) ? process.env.NODE_ENV !== "production" ? invariant(false, "useScrollRestoration must be used within a DataRouter") : invariant(false) : void 0;
|
|
734
712
|
let {
|
|
735
713
|
restoreScrollPosition,
|
|
736
714
|
resetScrollPosition
|
|
737
715
|
} = state; // Trigger manual scroll restoration while we're active
|
|
738
716
|
|
|
739
|
-
useEffect(() => {
|
|
717
|
+
React.useEffect(() => {
|
|
740
718
|
window.history.scrollRestoration = "manual";
|
|
741
719
|
return () => {
|
|
742
720
|
window.history.scrollRestoration = "auto";
|
|
743
721
|
};
|
|
744
722
|
}, []); // Save positions on unload
|
|
745
723
|
|
|
746
|
-
useBeforeUnload(useCallback(() => {
|
|
724
|
+
useBeforeUnload(React.useCallback(() => {
|
|
747
725
|
if ((state == null ? void 0 : state.navigation.state) === "idle") {
|
|
748
726
|
let key = (getKey ? getKey(state.location, state.matches) : null) || state.location.key;
|
|
749
727
|
savedScrollPositions[key] = window.scrollY;
|
|
@@ -753,7 +731,7 @@ function useScrollRestoration(_temp2) {
|
|
|
753
731
|
window.history.scrollRestoration = "auto";
|
|
754
732
|
}, [storageKey, getKey, state.navigation.state, state.location, state.matches])); // Read in any saved scroll locations
|
|
755
733
|
|
|
756
|
-
useLayoutEffect(() => {
|
|
734
|
+
React.useLayoutEffect(() => {
|
|
757
735
|
try {
|
|
758
736
|
let sessionPositions = sessionStorage.getItem(storageKey || SCROLL_RESTORATION_STORAGE_KEY);
|
|
759
737
|
|
|
@@ -764,12 +742,12 @@ function useScrollRestoration(_temp2) {
|
|
|
764
742
|
}
|
|
765
743
|
}, [storageKey]); // Enable scroll restoration in the router
|
|
766
744
|
|
|
767
|
-
useLayoutEffect(() => {
|
|
745
|
+
React.useLayoutEffect(() => {
|
|
768
746
|
let disableScrollRestoration = router == null ? void 0 : router.enableScrollRestoration(savedScrollPositions, () => window.scrollY, getKey);
|
|
769
747
|
return () => disableScrollRestoration && disableScrollRestoration();
|
|
770
748
|
}, [router, getKey]); // Restore scrolling when state.restoreScrollPosition changes
|
|
771
749
|
|
|
772
|
-
useLayoutEffect(() => {
|
|
750
|
+
React.useLayoutEffect(() => {
|
|
773
751
|
// Explicit false means don't do anything (used for submissions)
|
|
774
752
|
if (restoreScrollPosition === false) {
|
|
775
753
|
return;
|
|
@@ -802,7 +780,7 @@ function useScrollRestoration(_temp2) {
|
|
|
802
780
|
}
|
|
803
781
|
|
|
804
782
|
function useBeforeUnload(callback) {
|
|
805
|
-
useEffect(() => {
|
|
783
|
+
React.useEffect(() => {
|
|
806
784
|
window.addEventListener("beforeunload", callback);
|
|
807
785
|
return () => {
|
|
808
786
|
window.removeEventListener("beforeunload", callback);
|