react-router-dom-v5-compat 6.2.2

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.
@@ -0,0 +1,642 @@
1
+ /**
2
+ * React Router DOM v5 Compat v6.2.2
3
+ *
4
+ * Copyright (c) Remix Software Inc.
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE.md file in the root directory of this source tree.
8
+ *
9
+ * @license MIT
10
+ */
11
+ (function (global, factory) {
12
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('history'), require('react-router'), require('react-router-dom')) :
13
+ typeof define === 'function' && define.amd ? define(['exports', 'react', 'history', 'react-router', 'react-router-dom'], factory) :
14
+ (global = global || self, factory(global.ReactRouterDOMv5Compat = {}, global.React, global.HistoryLibrary, global.ReactRouter, global.ReactRouterDOM));
15
+ }(this, (function (exports, React, history, reactRouter, reactRouterDom) { 'use strict';
16
+
17
+ function _extends() {
18
+ _extends = Object.assign || function (target) {
19
+ for (var i = 1; i < arguments.length; i++) {
20
+ var source = arguments[i];
21
+
22
+ for (var key in source) {
23
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
24
+ target[key] = source[key];
25
+ }
26
+ }
27
+ }
28
+
29
+ return target;
30
+ };
31
+
32
+ return _extends.apply(this, arguments);
33
+ }
34
+
35
+ function _objectWithoutPropertiesLoose(source, excluded) {
36
+ if (source == null) return {};
37
+ var target = {};
38
+ var sourceKeys = Object.keys(source);
39
+ var key, i;
40
+
41
+ for (i = 0; i < sourceKeys.length; i++) {
42
+ key = sourceKeys[i];
43
+ if (excluded.indexOf(key) >= 0) continue;
44
+ target[key] = source[key];
45
+ }
46
+
47
+ return target;
48
+ }
49
+
50
+ const _excluded = ["onClick", "reloadDocument", "replace", "state", "target", "to"],
51
+ _excluded2 = ["aria-current", "caseSensitive", "className", "end", "style", "to", "children"];
52
+
53
+ function warning(cond, message) {
54
+ if (!cond) {
55
+ // eslint-disable-next-line no-console
56
+ if (typeof console !== "undefined") console.warn(message);
57
+
58
+ try {
59
+ // Welcome to debugging React Router!
60
+ //
61
+ // This error is thrown as a convenience so you can more easily
62
+ // find the source for a warning that appears in the console by
63
+ // enabling "pause on exceptions" in your JavaScript debugger.
64
+ throw new Error(message); // eslint-disable-next-line no-empty
65
+ } catch (e) {}
66
+ }
67
+ } ////////////////////////////////////////////////////////////////////////////////
68
+ // COMPONENTS
69
+ ////////////////////////////////////////////////////////////////////////////////
70
+
71
+ /**
72
+ * A `<Router>` for use in web browsers. Provides the cleanest URLs.
73
+ */
74
+ function BrowserRouter(_ref) {
75
+ let {
76
+ basename,
77
+ children,
78
+ window
79
+ } = _ref;
80
+ let historyRef = React.useRef();
81
+
82
+ if (historyRef.current == null) {
83
+ historyRef.current = history.createBrowserHistory({
84
+ window
85
+ });
86
+ }
87
+
88
+ let history$1 = historyRef.current;
89
+ let [state, setState] = React.useState({
90
+ action: history$1.action,
91
+ location: history$1.location
92
+ });
93
+ React.useLayoutEffect(() => history$1.listen(setState), [history$1]);
94
+ return /*#__PURE__*/React.createElement(reactRouter.Router, {
95
+ basename: basename,
96
+ children: children,
97
+ location: state.location,
98
+ navigationType: state.action,
99
+ navigator: history$1
100
+ });
101
+ }
102
+
103
+ /**
104
+ * A `<Router>` for use in web browsers. Stores the location in the hash
105
+ * portion of the URL so it is not sent to the server.
106
+ */
107
+ function HashRouter(_ref2) {
108
+ let {
109
+ basename,
110
+ children,
111
+ window
112
+ } = _ref2;
113
+ let historyRef = React.useRef();
114
+
115
+ if (historyRef.current == null) {
116
+ historyRef.current = history.createHashHistory({
117
+ window
118
+ });
119
+ }
120
+
121
+ let history$1 = historyRef.current;
122
+ let [state, setState] = React.useState({
123
+ action: history$1.action,
124
+ location: history$1.location
125
+ });
126
+ React.useLayoutEffect(() => history$1.listen(setState), [history$1]);
127
+ return /*#__PURE__*/React.createElement(reactRouter.Router, {
128
+ basename: basename,
129
+ children: children,
130
+ location: state.location,
131
+ navigationType: state.action,
132
+ navigator: history$1
133
+ });
134
+ }
135
+
136
+ /**
137
+ * A `<Router>` that accepts a pre-instantiated history object. It's important
138
+ * to note that using your own history object is highly discouraged and may add
139
+ * two versions of the history library to your bundles unless you use the same
140
+ * version of the history library that React Router uses internally.
141
+ */
142
+ function HistoryRouter(_ref3) {
143
+ let {
144
+ basename,
145
+ children,
146
+ history
147
+ } = _ref3;
148
+ const [state, setState] = React.useState({
149
+ action: history.action,
150
+ location: history.location
151
+ });
152
+ React.useLayoutEffect(() => history.listen(setState), [history]);
153
+ return /*#__PURE__*/React.createElement(reactRouter.Router, {
154
+ basename: basename,
155
+ children: children,
156
+ location: state.location,
157
+ navigationType: state.action,
158
+ navigator: history
159
+ });
160
+ }
161
+
162
+ {
163
+ HistoryRouter.displayName = "unstable_HistoryRouter";
164
+ }
165
+
166
+ function isModifiedEvent(event) {
167
+ return !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey);
168
+ }
169
+
170
+ /**
171
+ * The public API for rendering a history-aware <a>.
172
+ */
173
+ const Link = /*#__PURE__*/React.forwardRef(function LinkWithRef(_ref4, ref) {
174
+ let {
175
+ onClick,
176
+ reloadDocument,
177
+ replace = false,
178
+ state,
179
+ target,
180
+ to
181
+ } = _ref4,
182
+ rest = _objectWithoutPropertiesLoose(_ref4, _excluded);
183
+
184
+ let href = reactRouter.useHref(to);
185
+ let internalOnClick = useLinkClickHandler(to, {
186
+ replace,
187
+ state,
188
+ target
189
+ });
190
+
191
+ function handleClick(event) {
192
+ if (onClick) onClick(event);
193
+
194
+ if (!event.defaultPrevented && !reloadDocument) {
195
+ internalOnClick(event);
196
+ }
197
+ }
198
+
199
+ return (
200
+ /*#__PURE__*/
201
+ // eslint-disable-next-line jsx-a11y/anchor-has-content
202
+ React.createElement("a", _extends({}, rest, {
203
+ href: href,
204
+ onClick: handleClick,
205
+ ref: ref,
206
+ target: target
207
+ }))
208
+ );
209
+ });
210
+
211
+ {
212
+ Link.displayName = "Link";
213
+ }
214
+
215
+ /**
216
+ * A <Link> wrapper that knows if it's "active" or not.
217
+ */
218
+ const NavLink = /*#__PURE__*/React.forwardRef(function NavLinkWithRef(_ref5, ref) {
219
+ let {
220
+ "aria-current": ariaCurrentProp = "page",
221
+ caseSensitive = false,
222
+ className: classNameProp = "",
223
+ end = false,
224
+ style: styleProp,
225
+ to,
226
+ children
227
+ } = _ref5,
228
+ rest = _objectWithoutPropertiesLoose(_ref5, _excluded2);
229
+
230
+ let location = reactRouter.useLocation();
231
+ let path = reactRouter.useResolvedPath(to);
232
+ let locationPathname = location.pathname;
233
+ let toPathname = path.pathname;
234
+
235
+ if (!caseSensitive) {
236
+ locationPathname = locationPathname.toLowerCase();
237
+ toPathname = toPathname.toLowerCase();
238
+ }
239
+
240
+ let isActive = locationPathname === toPathname || !end && locationPathname.startsWith(toPathname) && locationPathname.charAt(toPathname.length) === "/";
241
+ let ariaCurrent = isActive ? ariaCurrentProp : undefined;
242
+ let className;
243
+
244
+ if (typeof classNameProp === "function") {
245
+ className = classNameProp({
246
+ isActive
247
+ });
248
+ } else {
249
+ // If the className prop is not a function, we use a default `active`
250
+ // class for <NavLink />s that are active. In v5 `active` was the default
251
+ // value for `activeClassName`, but we are removing that API and can still
252
+ // use the old default behavior for a cleaner upgrade path and keep the
253
+ // simple styling rules working as they currently do.
254
+ className = [classNameProp, isActive ? "active" : null].filter(Boolean).join(" ");
255
+ }
256
+
257
+ let style = typeof styleProp === "function" ? styleProp({
258
+ isActive
259
+ }) : styleProp;
260
+ return /*#__PURE__*/React.createElement(Link, _extends({}, rest, {
261
+ "aria-current": ariaCurrent,
262
+ className: className,
263
+ ref: ref,
264
+ style: style,
265
+ to: to
266
+ }), typeof children === "function" ? children({
267
+ isActive
268
+ }) : children);
269
+ });
270
+
271
+ {
272
+ NavLink.displayName = "NavLink";
273
+ } ////////////////////////////////////////////////////////////////////////////////
274
+ // HOOKS
275
+ ////////////////////////////////////////////////////////////////////////////////
276
+
277
+ /**
278
+ * Handles the click behavior for router `<Link>` components. This is useful if
279
+ * you need to create custom `<Link>` components with the same click behavior we
280
+ * use in our exported `<Link>`.
281
+ */
282
+
283
+
284
+ function useLinkClickHandler(to, _temp) {
285
+ let {
286
+ target,
287
+ replace: replaceProp,
288
+ state
289
+ } = _temp === void 0 ? {} : _temp;
290
+ let navigate = reactRouter.useNavigate();
291
+ let location = reactRouter.useLocation();
292
+ let path = reactRouter.useResolvedPath(to);
293
+ return React.useCallback(event => {
294
+ if (event.button === 0 && ( // Ignore everything but left clicks
295
+ !target || target === "_self") && // Let browser handle "target=_blank" etc.
296
+ !isModifiedEvent(event) // Ignore clicks with modifier keys
297
+ ) {
298
+ event.preventDefault(); // If the URL hasn't changed, a regular <a> will do a replace instead of
299
+ // a push, so do the same here.
300
+
301
+ let replace = !!replaceProp || reactRouter.createPath(location) === reactRouter.createPath(path);
302
+ navigate(to, {
303
+ replace,
304
+ state
305
+ });
306
+ }
307
+ }, [location, navigate, path, replaceProp, state, target, to]);
308
+ }
309
+ /**
310
+ * A convenient wrapper for reading and writing search parameters via the
311
+ * URLSearchParams interface.
312
+ */
313
+
314
+ function useSearchParams(defaultInit) {
315
+ 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.") ;
316
+ let defaultSearchParamsRef = React.useRef(createSearchParams(defaultInit));
317
+ let location = reactRouter.useLocation();
318
+ let searchParams = React.useMemo(() => {
319
+ let searchParams = createSearchParams(location.search);
320
+
321
+ for (let key of defaultSearchParamsRef.current.keys()) {
322
+ if (!searchParams.has(key)) {
323
+ defaultSearchParamsRef.current.getAll(key).forEach(value => {
324
+ searchParams.append(key, value);
325
+ });
326
+ }
327
+ }
328
+
329
+ return searchParams;
330
+ }, [location.search]);
331
+ let navigate = reactRouter.useNavigate();
332
+ let setSearchParams = React.useCallback((nextInit, navigateOptions) => {
333
+ navigate("?" + createSearchParams(nextInit), navigateOptions);
334
+ }, [navigate]);
335
+ return [searchParams, setSearchParams];
336
+ }
337
+
338
+ /**
339
+ * Creates a URLSearchParams object using the given initializer.
340
+ *
341
+ * This is identical to `new URLSearchParams(init)` except it also
342
+ * supports arrays as values in the object form of the initializer
343
+ * instead of just strings. This is convenient when you need multiple
344
+ * values for a given key, but don't want to use an array initializer.
345
+ *
346
+ * For example, instead of:
347
+ *
348
+ * let searchParams = new URLSearchParams([
349
+ * ['sort', 'name'],
350
+ * ['sort', 'price']
351
+ * ]);
352
+ *
353
+ * you can do:
354
+ *
355
+ * let searchParams = createSearchParams({
356
+ * sort: ['name', 'price']
357
+ * });
358
+ */
359
+ function createSearchParams(init) {
360
+ if (init === void 0) {
361
+ init = "";
362
+ }
363
+
364
+ return new URLSearchParams(typeof init === "string" || Array.isArray(init) || init instanceof URLSearchParams ? init : Object.keys(init).reduce((memo, key) => {
365
+ let value = init[key];
366
+ return memo.concat(Array.isArray(value) ? value.map(v => [key, v]) : [[key, value]]);
367
+ }, []));
368
+ }
369
+
370
+ function CompatRouter(_ref) {
371
+ let {
372
+ children
373
+ } = _ref;
374
+ let history = reactRouterDom.useHistory();
375
+ let [state, setState] = React.useState(() => ({
376
+ location: history.location,
377
+ action: history.action
378
+ }));
379
+ React.useEffect(() => {
380
+ history.listen((location, action) => setState({
381
+ location,
382
+ action
383
+ }));
384
+ }, [history]);
385
+ return /*#__PURE__*/React.createElement(reactRouter.Router, {
386
+ navigationType: state.action,
387
+ location: state.location,
388
+ navigator: history
389
+ }, /*#__PURE__*/React.createElement(reactRouter.Routes, null, /*#__PURE__*/React.createElement(reactRouter.Route, {
390
+ path: "*",
391
+ element: children
392
+ })));
393
+ }
394
+
395
+ /**
396
+ * A <Router> that may not transition to any other location. This is useful
397
+ * on the server where there is no stateful UI.
398
+ */
399
+ function StaticRouter(_ref2) {
400
+ let {
401
+ basename,
402
+ children,
403
+ location: locationProp = "/"
404
+ } = _ref2;
405
+
406
+ if (typeof locationProp === "string") {
407
+ locationProp = history.parsePath(locationProp);
408
+ }
409
+
410
+ let action = history.Action.Pop;
411
+ let location = {
412
+ pathname: locationProp.pathname || "/",
413
+ search: locationProp.search || "",
414
+ hash: locationProp.hash || "",
415
+ state: locationProp.state || null,
416
+ key: locationProp.key || "default"
417
+ };
418
+ let staticNavigator = {
419
+ createHref(to) {
420
+ return typeof to === "string" ? to : history.createPath(to);
421
+ },
422
+
423
+ push(to) {
424
+ 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."));
425
+ },
426
+
427
+ replace(to) {
428
+ 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.");
429
+ },
430
+
431
+ go(delta) {
432
+ 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."));
433
+ },
434
+
435
+ back() {
436
+ throw new Error("You cannot use navigator.back() on the server because it is a stateless " + "environment.");
437
+ },
438
+
439
+ forward() {
440
+ throw new Error("You cannot use navigator.forward() on the server because it is a stateless " + "environment.");
441
+ }
442
+
443
+ };
444
+ return /*#__PURE__*/React.createElement(reactRouter.Router, {
445
+ basename: basename,
446
+ children: children,
447
+ location: location,
448
+ navigationType: action,
449
+ navigator: staticNavigator,
450
+ static: true
451
+ });
452
+ }
453
+
454
+ Object.defineProperty(exports, 'MemoryRouter', {
455
+ enumerable: true,
456
+ get: function () {
457
+ return reactRouter.MemoryRouter;
458
+ }
459
+ });
460
+ Object.defineProperty(exports, 'Navigate', {
461
+ enumerable: true,
462
+ get: function () {
463
+ return reactRouter.Navigate;
464
+ }
465
+ });
466
+ Object.defineProperty(exports, 'NavigationType', {
467
+ enumerable: true,
468
+ get: function () {
469
+ return reactRouter.NavigationType;
470
+ }
471
+ });
472
+ Object.defineProperty(exports, 'Outlet', {
473
+ enumerable: true,
474
+ get: function () {
475
+ return reactRouter.Outlet;
476
+ }
477
+ });
478
+ Object.defineProperty(exports, 'Route', {
479
+ enumerable: true,
480
+ get: function () {
481
+ return reactRouter.Route;
482
+ }
483
+ });
484
+ Object.defineProperty(exports, 'Router', {
485
+ enumerable: true,
486
+ get: function () {
487
+ return reactRouter.Router;
488
+ }
489
+ });
490
+ Object.defineProperty(exports, 'Routes', {
491
+ enumerable: true,
492
+ get: function () {
493
+ return reactRouter.Routes;
494
+ }
495
+ });
496
+ Object.defineProperty(exports, 'UNSAFE_LocationContext', {
497
+ enumerable: true,
498
+ get: function () {
499
+ return reactRouter.UNSAFE_LocationContext;
500
+ }
501
+ });
502
+ Object.defineProperty(exports, 'UNSAFE_NavigationContext', {
503
+ enumerable: true,
504
+ get: function () {
505
+ return reactRouter.UNSAFE_NavigationContext;
506
+ }
507
+ });
508
+ Object.defineProperty(exports, 'UNSAFE_RouteContext', {
509
+ enumerable: true,
510
+ get: function () {
511
+ return reactRouter.UNSAFE_RouteContext;
512
+ }
513
+ });
514
+ Object.defineProperty(exports, 'createPath', {
515
+ enumerable: true,
516
+ get: function () {
517
+ return reactRouter.createPath;
518
+ }
519
+ });
520
+ Object.defineProperty(exports, 'createRoutesFromChildren', {
521
+ enumerable: true,
522
+ get: function () {
523
+ return reactRouter.createRoutesFromChildren;
524
+ }
525
+ });
526
+ Object.defineProperty(exports, 'generatePath', {
527
+ enumerable: true,
528
+ get: function () {
529
+ return reactRouter.generatePath;
530
+ }
531
+ });
532
+ Object.defineProperty(exports, 'matchPath', {
533
+ enumerable: true,
534
+ get: function () {
535
+ return reactRouter.matchPath;
536
+ }
537
+ });
538
+ Object.defineProperty(exports, 'matchRoutes', {
539
+ enumerable: true,
540
+ get: function () {
541
+ return reactRouter.matchRoutes;
542
+ }
543
+ });
544
+ Object.defineProperty(exports, 'parsePath', {
545
+ enumerable: true,
546
+ get: function () {
547
+ return reactRouter.parsePath;
548
+ }
549
+ });
550
+ Object.defineProperty(exports, 'renderMatches', {
551
+ enumerable: true,
552
+ get: function () {
553
+ return reactRouter.renderMatches;
554
+ }
555
+ });
556
+ Object.defineProperty(exports, 'resolvePath', {
557
+ enumerable: true,
558
+ get: function () {
559
+ return reactRouter.resolvePath;
560
+ }
561
+ });
562
+ Object.defineProperty(exports, 'useHref', {
563
+ enumerable: true,
564
+ get: function () {
565
+ return reactRouter.useHref;
566
+ }
567
+ });
568
+ Object.defineProperty(exports, 'useInRouterContext', {
569
+ enumerable: true,
570
+ get: function () {
571
+ return reactRouter.useInRouterContext;
572
+ }
573
+ });
574
+ Object.defineProperty(exports, 'useLocation', {
575
+ enumerable: true,
576
+ get: function () {
577
+ return reactRouter.useLocation;
578
+ }
579
+ });
580
+ Object.defineProperty(exports, 'useMatch', {
581
+ enumerable: true,
582
+ get: function () {
583
+ return reactRouter.useMatch;
584
+ }
585
+ });
586
+ Object.defineProperty(exports, 'useNavigate', {
587
+ enumerable: true,
588
+ get: function () {
589
+ return reactRouter.useNavigate;
590
+ }
591
+ });
592
+ Object.defineProperty(exports, 'useNavigationType', {
593
+ enumerable: true,
594
+ get: function () {
595
+ return reactRouter.useNavigationType;
596
+ }
597
+ });
598
+ Object.defineProperty(exports, 'useOutlet', {
599
+ enumerable: true,
600
+ get: function () {
601
+ return reactRouter.useOutlet;
602
+ }
603
+ });
604
+ Object.defineProperty(exports, 'useOutletContext', {
605
+ enumerable: true,
606
+ get: function () {
607
+ return reactRouter.useOutletContext;
608
+ }
609
+ });
610
+ Object.defineProperty(exports, 'useParams', {
611
+ enumerable: true,
612
+ get: function () {
613
+ return reactRouter.useParams;
614
+ }
615
+ });
616
+ Object.defineProperty(exports, 'useResolvedPath', {
617
+ enumerable: true,
618
+ get: function () {
619
+ return reactRouter.useResolvedPath;
620
+ }
621
+ });
622
+ Object.defineProperty(exports, 'useRoutes', {
623
+ enumerable: true,
624
+ get: function () {
625
+ return reactRouter.useRoutes;
626
+ }
627
+ });
628
+ exports.BrowserRouter = BrowserRouter;
629
+ exports.CompatRouter = CompatRouter;
630
+ exports.HashRouter = HashRouter;
631
+ exports.Link = Link;
632
+ exports.NavLink = NavLink;
633
+ exports.StaticRouter = StaticRouter;
634
+ exports.createSearchParams = createSearchParams;
635
+ exports.unstable_HistoryRouter = HistoryRouter;
636
+ exports.useLinkClickHandler = useLinkClickHandler;
637
+ exports.useSearchParams = useSearchParams;
638
+
639
+ Object.defineProperty(exports, '__esModule', { value: true });
640
+
641
+ })));
642
+ //# sourceMappingURL=react-router-dom-v5-compat.development.js.map