react-router-dom 6.4.0-pre.0 → 6.4.0-pre.4
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 +14 -0
- package/{dom.d.ts → dist/dom.d.ts} +0 -0
- package/{index.d.ts → dist/index.d.ts} +5 -5
- package/{index.js → dist/index.js} +67 -90
- package/dist/index.js.map +1 -0
- package/{main.js → dist/main.js} +3 -3
- package/{react-router-dom.development.js → dist/react-router-dom.development.js} +59 -77
- 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 +125 -210
- 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.d.ts +1 -1
- 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,14 @@
|
|
|
1
|
+
# react-router-dom
|
|
2
|
+
|
|
3
|
+
## 6.4.0-pre.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fix missing `dist` files
|
|
8
|
+
|
|
9
|
+
## 6.4.0-pre.3
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Make `fallbackElement` optional and change type to `ReactNode` (type changes only) (#8896)
|
|
14
|
+
- Properly trigger error boundaries on 404 routes
|
|
File without changes
|
|
@@ -16,7 +16,7 @@ export { UNSAFE_NavigationContext, UNSAFE_LocationContext, UNSAFE_RouteContext,
|
|
|
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.
|
|
@@ -152,9 +152,9 @@ export declare function useLinkClickHandler<E extends Element = HTMLAnchorElemen
|
|
|
152
152
|
* URLSearchParams interface.
|
|
153
153
|
*/
|
|
154
154
|
export declare function useSearchParams(defaultInit?: URLSearchParamsInit): readonly [URLSearchParams, (nextInit: URLSearchParamsInit, navigateOptions?: {
|
|
155
|
-
replace?: boolean
|
|
155
|
+
replace?: boolean;
|
|
156
156
|
state?: any;
|
|
157
|
-
}
|
|
157
|
+
}) => void];
|
|
158
158
|
/**
|
|
159
159
|
* Submits a HTML `<form>` to the server without reloading the page.
|
|
160
160
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* React Router DOM v6.4.0-pre.
|
|
2
|
+
* React Router DOM v6.4.0-pre.4
|
|
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
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';
|
|
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,28 @@ 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) => {
|
|
562
|
+
let setSearchParams = React.useCallback((nextInit, navigateOptions) => {
|
|
583
563
|
navigate("?" + createSearchParams(nextInit), navigateOptions);
|
|
584
564
|
}, [navigate]);
|
|
585
565
|
return [searchParams, setSearchParams];
|
|
586
566
|
}
|
|
587
|
-
/**
|
|
588
|
-
* Submits a HTML `<form>` to the server without reloading the page.
|
|
589
|
-
*/
|
|
590
|
-
|
|
591
567
|
/**
|
|
592
568
|
* Returns a function that may be used to programmatically submit a form (or
|
|
593
569
|
* some arbitrary data) to the server.
|
|
594
570
|
*/
|
|
571
|
+
|
|
595
572
|
function useSubmit() {
|
|
596
573
|
return useSubmitImpl();
|
|
597
574
|
}
|
|
598
575
|
|
|
599
576
|
function useSubmitImpl(fetcherKey) {
|
|
600
|
-
let router = useContext(UNSAFE_DataRouterContext);
|
|
577
|
+
let router = React.useContext(UNSAFE_DataRouterContext);
|
|
601
578
|
let defaultAction = useFormAction();
|
|
602
|
-
return useCallback(function (target, options) {
|
|
579
|
+
return React.useCallback(function (target, options) {
|
|
603
580
|
if (options === void 0) {
|
|
604
581
|
options = {};
|
|
605
582
|
}
|
|
@@ -639,8 +616,8 @@ function useFormAction(action) {
|
|
|
639
616
|
action = ".";
|
|
640
617
|
}
|
|
641
618
|
|
|
642
|
-
let routeContext = useContext(UNSAFE_RouteContext);
|
|
643
|
-
!routeContext ? process.env.NODE_ENV !== "production" ? invariant(false, "
|
|
619
|
+
let routeContext = React.useContext(UNSAFE_RouteContext);
|
|
620
|
+
!routeContext ? process.env.NODE_ENV !== "production" ? invariant(false, "useFormAction must be used inside a RouteContext") : invariant(false) : void 0;
|
|
644
621
|
let [match] = routeContext.matches.slice(-1);
|
|
645
622
|
let {
|
|
646
623
|
pathname,
|
|
@@ -655,8 +632,8 @@ function useFormAction(action) {
|
|
|
655
632
|
}
|
|
656
633
|
|
|
657
634
|
function createFetcherForm(fetcherKey) {
|
|
658
|
-
let FetcherForm = /*#__PURE__*/forwardRef((props, ref) => {
|
|
659
|
-
return /*#__PURE__*/createElement(FormImpl, _extends({}, props, {
|
|
635
|
+
let FetcherForm = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
636
|
+
return /*#__PURE__*/React.createElement(FormImpl, _extends({}, props, {
|
|
660
637
|
ref: ref,
|
|
661
638
|
fetcherKey: fetcherKey
|
|
662
639
|
}));
|
|
@@ -670,28 +647,28 @@ function createFetcherForm(fetcherKey) {
|
|
|
670
647
|
}
|
|
671
648
|
|
|
672
649
|
let fetcherId = 0;
|
|
673
|
-
|
|
674
650
|
/**
|
|
675
651
|
* Interacts with route loaders and actions without causing a navigation. Great
|
|
676
652
|
* for any interaction that stays on the same page.
|
|
677
653
|
*/
|
|
654
|
+
|
|
678
655
|
function useFetcher() {
|
|
679
|
-
let router = useContext(UNSAFE_DataRouterContext);
|
|
656
|
+
let router = React.useContext(UNSAFE_DataRouterContext);
|
|
680
657
|
!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 => {
|
|
658
|
+
let [fetcherKey] = React.useState(() => String(++fetcherId));
|
|
659
|
+
let [Form] = React.useState(() => createFetcherForm(fetcherKey));
|
|
660
|
+
let [load] = React.useState(() => href => {
|
|
684
661
|
!router ? process.env.NODE_ENV !== "production" ? invariant(false, "No router available for fetcher.load()") : invariant(false) : void 0;
|
|
685
662
|
router.fetch(fetcherKey, href);
|
|
686
663
|
});
|
|
687
664
|
let submit = useSubmitImpl(fetcherKey);
|
|
688
665
|
let fetcher = router.getFetcher(fetcherKey);
|
|
689
|
-
let fetcherWithComponents = useMemo(() => _extends({
|
|
666
|
+
let fetcherWithComponents = React.useMemo(() => _extends({
|
|
690
667
|
Form,
|
|
691
668
|
submit,
|
|
692
669
|
load
|
|
693
670
|
}, fetcher), [fetcher, Form, submit, load]);
|
|
694
|
-
useEffect(() => {
|
|
671
|
+
React.useEffect(() => {
|
|
695
672
|
// Is this busted when the React team gets real weird and calls effects
|
|
696
673
|
// twice on mount? We really just need to garbage collect here when this
|
|
697
674
|
// fetcher is no longer around.
|
|
@@ -712,7 +689,7 @@ function useFetcher() {
|
|
|
712
689
|
*/
|
|
713
690
|
|
|
714
691
|
function useFetchers() {
|
|
715
|
-
let state = useContext(UNSAFE_DataRouterStateContext);
|
|
692
|
+
let state = React.useContext(UNSAFE_DataRouterStateContext);
|
|
716
693
|
!state ? process.env.NODE_ENV !== "production" ? invariant(false, "useFetchers must be used within a DataRouter") : invariant(false) : void 0;
|
|
717
694
|
return [...state.fetchers.values()];
|
|
718
695
|
}
|
|
@@ -728,22 +705,22 @@ function useScrollRestoration(_temp2) {
|
|
|
728
705
|
storageKey
|
|
729
706
|
} = _temp2 === void 0 ? {} : _temp2;
|
|
730
707
|
let location = useLocation();
|
|
731
|
-
let router = useContext(UNSAFE_DataRouterContext);
|
|
732
|
-
let state = useContext(UNSAFE_DataRouterStateContext);
|
|
708
|
+
let router = React.useContext(UNSAFE_DataRouterContext);
|
|
709
|
+
let state = React.useContext(UNSAFE_DataRouterStateContext);
|
|
733
710
|
!(router != null && state != null) ? process.env.NODE_ENV !== "production" ? invariant(false, "useScrollRestoration must be used within a DataRouter") : invariant(false) : void 0;
|
|
734
711
|
let {
|
|
735
712
|
restoreScrollPosition,
|
|
736
713
|
resetScrollPosition
|
|
737
714
|
} = state; // Trigger manual scroll restoration while we're active
|
|
738
715
|
|
|
739
|
-
useEffect(() => {
|
|
716
|
+
React.useEffect(() => {
|
|
740
717
|
window.history.scrollRestoration = "manual";
|
|
741
718
|
return () => {
|
|
742
719
|
window.history.scrollRestoration = "auto";
|
|
743
720
|
};
|
|
744
721
|
}, []); // Save positions on unload
|
|
745
722
|
|
|
746
|
-
useBeforeUnload(useCallback(() => {
|
|
723
|
+
useBeforeUnload(React.useCallback(() => {
|
|
747
724
|
if ((state == null ? void 0 : state.navigation.state) === "idle") {
|
|
748
725
|
let key = (getKey ? getKey(state.location, state.matches) : null) || state.location.key;
|
|
749
726
|
savedScrollPositions[key] = window.scrollY;
|
|
@@ -753,7 +730,7 @@ function useScrollRestoration(_temp2) {
|
|
|
753
730
|
window.history.scrollRestoration = "auto";
|
|
754
731
|
}, [storageKey, getKey, state.navigation.state, state.location, state.matches])); // Read in any saved scroll locations
|
|
755
732
|
|
|
756
|
-
useLayoutEffect(() => {
|
|
733
|
+
React.useLayoutEffect(() => {
|
|
757
734
|
try {
|
|
758
735
|
let sessionPositions = sessionStorage.getItem(storageKey || SCROLL_RESTORATION_STORAGE_KEY);
|
|
759
736
|
|
|
@@ -764,12 +741,12 @@ function useScrollRestoration(_temp2) {
|
|
|
764
741
|
}
|
|
765
742
|
}, [storageKey]); // Enable scroll restoration in the router
|
|
766
743
|
|
|
767
|
-
useLayoutEffect(() => {
|
|
744
|
+
React.useLayoutEffect(() => {
|
|
768
745
|
let disableScrollRestoration = router == null ? void 0 : router.enableScrollRestoration(savedScrollPositions, () => window.scrollY, getKey);
|
|
769
746
|
return () => disableScrollRestoration && disableScrollRestoration();
|
|
770
747
|
}, [router, getKey]); // Restore scrolling when state.restoreScrollPosition changes
|
|
771
748
|
|
|
772
|
-
useLayoutEffect(() => {
|
|
749
|
+
React.useLayoutEffect(() => {
|
|
773
750
|
// Explicit false means don't do anything (used for submissions)
|
|
774
751
|
if (restoreScrollPosition === false) {
|
|
775
752
|
return;
|
|
@@ -802,7 +779,7 @@ function useScrollRestoration(_temp2) {
|
|
|
802
779
|
}
|
|
803
780
|
|
|
804
781
|
function useBeforeUnload(callback) {
|
|
805
|
-
useEffect(() => {
|
|
782
|
+
React.useEffect(() => {
|
|
806
783
|
window.addEventListener("beforeunload", callback);
|
|
807
784
|
return () => {
|
|
808
785
|
window.removeEventListener("beforeunload", callback);
|