@tanstack/react-router 0.0.1-beta.209 → 0.0.1-beta.210

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.
Files changed (72) hide show
  1. package/build/cjs/CatchBoundary.js +125 -0
  2. package/build/cjs/CatchBoundary.js.map +1 -0
  3. package/build/cjs/Matches.js +223 -0
  4. package/build/cjs/Matches.js.map +1 -0
  5. package/build/cjs/RouterProvider.js +99 -53
  6. package/build/cjs/RouterProvider.js.map +1 -1
  7. package/build/cjs/index.js +46 -37
  8. package/build/cjs/index.js.map +1 -1
  9. package/build/cjs/lazyRouteComponent.js +57 -0
  10. package/build/cjs/lazyRouteComponent.js.map +1 -0
  11. package/build/cjs/link.js +150 -0
  12. package/build/cjs/link.js.map +1 -0
  13. package/build/cjs/route.js +9 -5
  14. package/build/cjs/route.js.map +1 -1
  15. package/build/cjs/router.js.map +1 -1
  16. package/build/cjs/searchParams.js.map +1 -1
  17. package/build/cjs/useBlocker.js +64 -0
  18. package/build/cjs/useBlocker.js.map +1 -0
  19. package/build/cjs/useNavigate.js +78 -0
  20. package/build/cjs/useNavigate.js.map +1 -0
  21. package/build/cjs/useParams.js +28 -0
  22. package/build/cjs/useParams.js.map +1 -0
  23. package/build/cjs/useSearch.js +27 -0
  24. package/build/cjs/useSearch.js.map +1 -0
  25. package/build/cjs/utils.js +30 -1
  26. package/build/cjs/utils.js.map +1 -1
  27. package/build/esm/index.js +491 -514
  28. package/build/esm/index.js.map +1 -1
  29. package/build/stats-html.html +1 -1
  30. package/build/stats-react.json +484 -208
  31. package/build/types/CatchBoundary.d.ts +33 -0
  32. package/build/types/Matches.d.ts +31 -0
  33. package/build/types/RouterProvider.d.ts +42 -18
  34. package/build/types/fileRoute.d.ts +7 -7
  35. package/build/types/index.d.ts +13 -7
  36. package/build/types/injectHtml.d.ts +0 -0
  37. package/build/types/lazyRouteComponent.d.ts +2 -0
  38. package/build/types/link.d.ts +10 -3
  39. package/build/types/route.d.ts +39 -7
  40. package/build/types/router.d.ts +6 -7
  41. package/build/types/useBlocker.d.ts +8 -0
  42. package/build/types/useNavigate.d.ts +20 -0
  43. package/build/types/useParams.d.ts +7 -0
  44. package/build/types/useSearch.d.ts +7 -0
  45. package/build/types/utils.d.ts +17 -0
  46. package/build/umd/index.development.js +492 -513
  47. package/build/umd/index.development.js.map +1 -1
  48. package/build/umd/index.production.js +1 -1
  49. package/build/umd/index.production.js.map +1 -1
  50. package/package.json +2 -2
  51. package/src/CatchBoundary.tsx +97 -0
  52. package/src/Matches.tsx +315 -0
  53. package/src/RouterProvider.tsx +317 -251
  54. package/src/index.tsx +17 -8
  55. package/src/injectHtml.ts +28 -0
  56. package/src/lazyRouteComponent.tsx +33 -0
  57. package/src/{link.ts → link.tsx} +163 -3
  58. package/src/location.ts +1 -0
  59. package/src/route.ts +86 -16
  60. package/src/router.ts +6 -7
  61. package/src/searchParams.ts +1 -0
  62. package/src/useBlocker.tsx +34 -0
  63. package/src/useNavigate.tsx +109 -0
  64. package/src/useParams.tsx +25 -0
  65. package/src/useSearch.tsx +25 -0
  66. package/src/utils.ts +83 -3
  67. package/build/cjs/react.js +0 -620
  68. package/build/cjs/react.js.map +0 -1
  69. package/build/types/RouteMatch.d.ts +0 -23
  70. package/build/types/react.d.ts +0 -141
  71. package/src/RouteMatch.ts +0 -28
  72. package/src/react.tsx +0 -1013
@@ -16,6 +16,91 @@ import warning from 'tiny-warning';
16
16
  export { default as warning } from 'tiny-warning';
17
17
  import * as React from 'react';
18
18
 
19
+ function CatchBoundary(props) {
20
+ const errorComponent = props.errorComponent ?? ErrorComponent;
21
+ return /*#__PURE__*/React.createElement(CatchBoundaryImpl, {
22
+ resetKey: props.resetKey,
23
+ onCatch: props.onCatch,
24
+ children: ({
25
+ error
26
+ }) => {
27
+ if (error) {
28
+ return /*#__PURE__*/React.createElement(errorComponent, {
29
+ error
30
+ });
31
+ }
32
+ return props.children;
33
+ }
34
+ });
35
+ }
36
+ class CatchBoundaryImpl extends React.Component {
37
+ state = {
38
+ error: null
39
+ };
40
+ static getDerivedStateFromError(error) {
41
+ return {
42
+ error
43
+ };
44
+ }
45
+ componentDidUpdate(prevProps, prevState) {
46
+ if (prevState.error && prevProps.resetKey !== this.props.resetKey) {
47
+ this.setState({
48
+ error: null
49
+ });
50
+ }
51
+ }
52
+ componentDidCatch(error) {
53
+ this.props.onCatch?.(error);
54
+ }
55
+ render() {
56
+ return this.props.children(this.state);
57
+ }
58
+ }
59
+ function ErrorComponent({
60
+ error
61
+ }) {
62
+ const [show, setShow] = React.useState(process.env.NODE_ENV !== 'production');
63
+ return /*#__PURE__*/React.createElement("div", {
64
+ style: {
65
+ padding: '.5rem',
66
+ maxWidth: '100%'
67
+ }
68
+ }, /*#__PURE__*/React.createElement("div", {
69
+ style: {
70
+ display: 'flex',
71
+ alignItems: 'center',
72
+ gap: '.5rem'
73
+ }
74
+ }, /*#__PURE__*/React.createElement("strong", {
75
+ style: {
76
+ fontSize: '1rem'
77
+ }
78
+ }, "Something went wrong!"), /*#__PURE__*/React.createElement("button", {
79
+ style: {
80
+ appearance: 'none',
81
+ fontSize: '.6em',
82
+ border: '1px solid currentColor',
83
+ padding: '.1rem .2rem',
84
+ fontWeight: 'bold',
85
+ borderRadius: '.25rem'
86
+ },
87
+ onClick: () => setShow(d => !d)
88
+ }, show ? 'Hide Error' : 'Show Error')), /*#__PURE__*/React.createElement("div", {
89
+ style: {
90
+ height: '.25rem'
91
+ }
92
+ }), show ? /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("pre", {
93
+ style: {
94
+ fontSize: '.7em',
95
+ border: '1px solid red',
96
+ borderRadius: '.25rem',
97
+ padding: '.3rem',
98
+ color: 'red',
99
+ overflow: 'auto'
100
+ }
101
+ }, error.message ? /*#__PURE__*/React.createElement("code", null, error.message) : null)) : null);
102
+ }
103
+
19
104
  // export type Expand<T> = T
20
105
 
21
106
  // type Compute<T> = { [K in keyof T]: T[K] } | never
@@ -156,7 +241,7 @@ function partialDeepEqual(a, b) {
156
241
  return !Object.keys(b).some(key => !partialDeepEqual(a[key], b[key]));
157
242
  }
158
243
  if (Array.isArray(a) && Array.isArray(b)) {
159
- return a.length === b.length && a.every((item, index) => partialDeepEqual(item, b[index]));
244
+ return !(a.length !== b.length || a.some((item, index) => !partialDeepEqual(item, b[index])));
160
245
  }
161
246
  return false;
162
247
  }
@@ -166,6 +251,31 @@ function useStableCallback(fn) {
166
251
  const ref = React.useRef((...args) => fnRef.current(...args));
167
252
  return ref.current;
168
253
  }
254
+ function shallow(objA, objB) {
255
+ if (Object.is(objA, objB)) {
256
+ return true;
257
+ }
258
+ if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
259
+ return false;
260
+ }
261
+ const keysA = Object.keys(objA);
262
+ if (keysA.length !== Object.keys(objB).length) {
263
+ return false;
264
+ }
265
+ for (let i = 0; i < keysA.length; i++) {
266
+ if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !Object.is(objA[keysA[i]], objB[keysA[i]])) {
267
+ return false;
268
+ }
269
+ }
270
+ return true;
271
+ }
272
+ function useRouteContext(opts) {
273
+ return useMatch({
274
+ ...opts,
275
+ select: match => opts?.select ? opts.select(match.context) : match.context
276
+ });
277
+ }
278
+ const useLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
169
279
 
170
280
  function joinPaths(paths) {
171
281
  return cleanPath(paths.filter(Boolean).join('/'));
@@ -351,6 +461,16 @@ function matchByPath(basepath, from, matchLocation) {
351
461
  return isMatch ? params : undefined;
352
462
  }
353
463
 
464
+ // Detect if we're in the DOM
465
+
466
+ function redirect(opts) {
467
+ opts.isRedirect = true;
468
+ return opts;
469
+ }
470
+ function isRedirect(obj) {
471
+ return !!obj?.isRedirect;
472
+ }
473
+
354
474
  // @ts-nocheck
355
475
 
356
476
  // qss has been slightly modified and inlined here for our use cases (and compression's sake). We've included it as a hard dependency for MIT license attribution.
@@ -399,21 +519,6 @@ function decode(str) {
399
519
  return out;
400
520
  }
401
521
 
402
- function _extends() {
403
- _extends = Object.assign ? Object.assign.bind() : function (target) {
404
- for (var i = 1; i < arguments.length; i++) {
405
- var source = arguments[i];
406
- for (var key in source) {
407
- if (Object.prototype.hasOwnProperty.call(source, key)) {
408
- target[key] = source[key];
409
- }
410
- }
411
- }
412
- return target;
413
- };
414
- return _extends.apply(this, arguments);
415
- }
416
-
417
522
  const defaultParseSearch = parseSearchWith(JSON.parse);
418
523
  const defaultStringifySearch = stringifySearchWith(JSON.stringify, JSON.parse);
419
524
  function parseSearchWith(parser) {
@@ -659,26 +764,20 @@ function lazyFn(fn, key) {
659
764
  };
660
765
  }
661
766
 
662
- // Detect if we're in the DOM
663
-
664
- function redirect(opts) {
665
- opts.isRedirect = true;
666
- return opts;
667
- }
668
- function isRedirect(obj) {
669
- return !!obj?.isRedirect;
670
- }
671
-
672
- const preloadWarning = 'Error preloading route! ☝️';
673
767
  const routerContext = /*#__PURE__*/React.createContext(null);
674
768
  if (typeof document !== 'undefined') {
675
769
  window.__TSR_ROUTER_CONTEXT__ = routerContext;
676
770
  }
771
+ const preloadWarning = 'Error preloading route! ☝️';
772
+ function isCtrlEvent(e) {
773
+ return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
774
+ }
775
+ class SearchParamError extends Error {}
776
+ class PathParamError extends Error {}
677
777
  function getInitialRouterState(location) {
678
778
  return {
679
779
  status: 'idle',
680
- isFetching: false,
681
- resolvedLocation: location,
780
+ resolvedLocation: undefined,
682
781
  location: location,
683
782
  matches: [],
684
783
  pendingMatches: [],
@@ -739,7 +838,20 @@ function RouterProvider({
739
838
  }
740
839
  return location;
741
840
  });
742
- const [state, setState] = React.useState(() => getInitialRouterState(parseLocation()));
841
+ const [preState, setState] = React.useState(() => getInitialRouterState(parseLocation()));
842
+ const [isTransitioning, startReactTransition] = React.useTransition();
843
+ const state = React.useMemo(() => ({
844
+ ...preState,
845
+ status: isTransitioning ? 'pending' : 'idle'
846
+ }), [preState, isTransitioning]);
847
+ React.useLayoutEffect(() => {
848
+ if (!isTransitioning && state.resolvedLocation !== state.location) {
849
+ setState(s => ({
850
+ ...s,
851
+ resolvedLocation: s.location
852
+ }));
853
+ }
854
+ });
743
855
  const basepath = `/${trimPath(options.basepath ?? '') ?? ''}`;
744
856
  const resolvePathWithBase = useStableCallback((from, path) => {
745
857
  return resolvePath(basepath, from, cleanPath(path));
@@ -958,7 +1070,7 @@ function RouterProvider({
958
1070
  cancelMatch(match.id);
959
1071
  });
960
1072
  });
961
- const buildLocation = useStableCallback((opts = {}) => {
1073
+ const buildLocation = useStableCallback(opts => {
962
1074
  const build = (dest = {}, matches) => {
963
1075
  const from = latestLocationRef.current;
964
1076
  const fromPathname = dest.from ?? from.pathname;
@@ -1051,7 +1163,10 @@ function RouterProvider({
1051
1163
  }
1052
1164
  return buildWithMatches(opts);
1053
1165
  });
1054
- const commitLocation = useStableCallback(async next => {
1166
+ const commitLocation = useStableCallback(async ({
1167
+ startTransition,
1168
+ ...next
1169
+ }) => {
1055
1170
  if (navigateTimeoutRef.current) clearTimeout(navigateTimeoutRef.current);
1056
1171
  const isSameUrl = latestLocationRef.current.href === next.href;
1057
1172
 
@@ -1084,7 +1199,14 @@ function RouterProvider({
1084
1199
  nextHistory.state.__tempKey = tempLocationKeyRef.current;
1085
1200
  }
1086
1201
  }
1087
- history[next.replace ? 'replace' : 'push'](nextHistory.href, nextHistory.state);
1202
+ const apply = () => {
1203
+ history[next.replace ? 'replace' : 'push'](nextHistory.href, nextHistory.state);
1204
+ };
1205
+ if (startTransition ?? true) {
1206
+ startReactTransition(apply);
1207
+ } else {
1208
+ apply();
1209
+ }
1088
1210
  }
1089
1211
  resetNextScrollRef.current = next.resetScroll ?? true;
1090
1212
  return latestLoadPromiseRef.current;
@@ -1092,11 +1214,13 @@ function RouterProvider({
1092
1214
  const buildAndCommitLocation = useStableCallback(({
1093
1215
  replace,
1094
1216
  resetScroll,
1217
+ startTransition,
1095
1218
  ...rest
1096
1219
  } = {}) => {
1097
1220
  const location = buildLocation(rest);
1098
1221
  return commitLocation({
1099
1222
  ...location,
1223
+ startTransition,
1100
1224
  replace,
1101
1225
  resetScroll
1102
1226
  });
@@ -1178,7 +1302,8 @@ function RouterProvider({
1178
1302
  navigate: opts => navigate({
1179
1303
  ...opts,
1180
1304
  from: match.pathname
1181
- })
1305
+ }),
1306
+ buildLocation
1182
1307
  })) ?? {};
1183
1308
  const context = {
1184
1309
  ...parentContext,
@@ -1239,7 +1364,7 @@ function RouterProvider({
1239
1364
  from: match.pathname
1240
1365
  })
1241
1366
  });
1242
- await Promise.all([componentsPromise, loaderPromise]);
1367
+ const [_, loaderContext] = await Promise.all([componentsPromise, loaderPromise]);
1243
1368
  if (latestPromise = checkLatest()) return await latestPromise;
1244
1369
  matches[index] = match = {
1245
1370
  ...match,
@@ -1293,7 +1418,7 @@ function RouterProvider({
1293
1418
  const load = useStableCallback(async () => {
1294
1419
  const promise = new Promise(async (resolve, reject) => {
1295
1420
  const next = latestLocationRef.current;
1296
- const prevLocation = state.resolvedLocation;
1421
+ const prevLocation = state.resolvedLocation || state.location;
1297
1422
  const pathDidChange = !!(next && prevLocation.href !== next.href);
1298
1423
  let latestPromise;
1299
1424
 
@@ -1306,19 +1431,14 @@ function RouterProvider({
1306
1431
  pathChanged: pathDidChange
1307
1432
  });
1308
1433
 
1309
- // Ingest the new location
1310
- setState(s => ({
1311
- ...s,
1312
- location: next
1313
- }));
1314
-
1315
1434
  // Match the routes
1316
1435
  let matches = matchRoutes(next.pathname, next.search, {
1317
1436
  debug: true
1318
1437
  });
1438
+
1439
+ // Ingest the new matches
1319
1440
  setState(s => ({
1320
1441
  ...s,
1321
- status: 'pending',
1322
1442
  matches
1323
1443
  }));
1324
1444
  try {
@@ -1349,11 +1469,11 @@ function RouterProvider({
1349
1469
  // state.pendingMatches.includes(id),
1350
1470
  // )
1351
1471
 
1352
- setState(s => ({
1353
- ...s,
1354
- status: 'idle',
1355
- resolvedLocation: s.location
1356
- }));
1472
+ // setState((s) => ({
1473
+ // ...s,
1474
+ // status: 'idle',
1475
+ // resolvedLocation: s.location,
1476
+ // }))
1357
1477
 
1358
1478
  // TODO:
1359
1479
  // ;(
@@ -1398,7 +1518,7 @@ function RouterProvider({
1398
1518
  });
1399
1519
  return [last(matches), matches];
1400
1520
  });
1401
- const buildLink = useStableCallback((state, dest) => {
1521
+ const buildLink = useStableCallback(dest => {
1402
1522
  // If this link simply reloads the current route,
1403
1523
  // make sure it has a new key so it will trigger a data refresh
1404
1524
 
@@ -1413,7 +1533,8 @@ function RouterProvider({
1413
1533
  disabled,
1414
1534
  target,
1415
1535
  replace,
1416
- resetScroll
1536
+ resetScroll,
1537
+ startTransition
1417
1538
  } = dest;
1418
1539
  try {
1419
1540
  new URL(`${to}`);
@@ -1448,7 +1569,8 @@ function RouterProvider({
1448
1569
  commitLocation({
1449
1570
  ...next,
1450
1571
  replace,
1451
- resetScroll
1572
+ resetScroll,
1573
+ startTransition
1452
1574
  });
1453
1575
  }
1454
1576
  };
@@ -1506,15 +1628,17 @@ function RouterProvider({
1506
1628
  React.useLayoutEffect(() => {
1507
1629
  const unsub = history.subscribe(() => {
1508
1630
  latestLocationRef.current = parseLocation(latestLocationRef.current);
1509
- React.startTransition(() => {
1510
- if (state.location !== latestLocationRef.current) {
1511
- try {
1512
- load();
1513
- } catch (err) {
1514
- console.error(err);
1515
- }
1631
+ setState(s => ({
1632
+ ...s,
1633
+ status: 'pending'
1634
+ }));
1635
+ if (state.location !== latestLocationRef.current) {
1636
+ try {
1637
+ load();
1638
+ } catch (err) {
1639
+ console.error(err);
1516
1640
  }
1517
- });
1641
+ }
1518
1642
  });
1519
1643
  const nextLocation = buildLocation({
1520
1644
  search: true,
@@ -1535,14 +1659,15 @@ function RouterProvider({
1535
1659
  const initialLoad = React.useRef(true);
1536
1660
  if (initialLoad.current) {
1537
1661
  initialLoad.current = false;
1538
- try {
1539
- load();
1540
- } catch (err) {
1541
- console.error(err);
1542
- }
1662
+ startReactTransition(() => {
1663
+ try {
1664
+ load();
1665
+ } catch (err) {
1666
+ console.error(err);
1667
+ }
1668
+ });
1543
1669
  }
1544
- React.useMemo(() => [...state.matches, ...state.pendingMatches].some(d => d.isFetching), [state.matches, state.pendingMatches]);
1545
- const matchRoute = useStableCallback((state, location, opts) => {
1670
+ const matchRoute = useStableCallback((location, opts) => {
1546
1671
  location = {
1547
1672
  ...location,
1548
1673
  to: location.to ? resolvePathWithBase(location.from || '', location.to) : undefined
@@ -1552,6 +1677,9 @@ function RouterProvider({
1552
1677
  return false;
1553
1678
  }
1554
1679
  const baseLocation = opts?.pending ? latestLocationRef.current : state.resolvedLocation;
1680
+
1681
+ // const baseLocation = state.resolvedLocation
1682
+
1555
1683
  if (!baseLocation) {
1556
1684
  return false;
1557
1685
  }
@@ -1562,7 +1690,7 @@ function RouterProvider({
1562
1690
  if (!match) {
1563
1691
  return false;
1564
1692
  }
1565
- if (opts?.includeSearch ?? true) {
1693
+ if (match && (opts?.includeSearch ?? true)) {
1566
1694
  return partialDeepEqual(baseLocation.search, next.search) ? match : false;
1567
1695
  }
1568
1696
  return match;
@@ -1576,292 +1704,39 @@ function RouterProvider({
1576
1704
  routesById,
1577
1705
  options,
1578
1706
  history,
1579
- load
1707
+ load,
1708
+ buildLocation
1580
1709
  };
1581
1710
  return /*#__PURE__*/React.createElement(routerContext.Provider, {
1582
1711
  value: routerContextValue
1583
1712
  }, /*#__PURE__*/React.createElement(Matches, null));
1584
1713
  }
1585
- function isCtrlEvent(e) {
1586
- return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
1587
- }
1588
- class SearchParamError extends Error {}
1589
- class PathParamError extends Error {}
1590
1714
  function getRouteMatch(state, id) {
1591
1715
  return [...state.pendingMatches, ...state.matches].find(d => d.id === id);
1592
1716
  }
1593
-
1594
- const useLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
1595
-
1596
- //
1597
-
1598
- function lazyRouteComponent(importer, exportName) {
1599
- let loadPromise;
1600
- const load = () => {
1601
- if (!loadPromise) {
1602
- loadPromise = importer();
1603
- }
1604
- return loadPromise;
1605
- };
1606
- const lazyComp = /*#__PURE__*/React.lazy(async () => {
1607
- const moduleExports = await load();
1608
- const comp = moduleExports[exportName ?? 'default'];
1609
- return {
1610
- default: comp
1611
- };
1612
- });
1613
- lazyComp.preload = load;
1614
- return lazyComp;
1717
+ function useRouterState(opts) {
1718
+ const {
1719
+ state
1720
+ } = useRouter();
1721
+ // return useStore(router.__store, opts?.select as any)
1722
+ return opts?.select ? opts.select(state) : state;
1723
+ }
1724
+ function useRouter() {
1725
+ const resolvedContext = window.__TSR_ROUTER_CONTEXT__ || routerContext;
1726
+ const value = React.useContext(resolvedContext);
1727
+ warning(value, 'useRouter must be used inside a <RouterProvider> component!');
1728
+ return value;
1615
1729
  }
1616
- //
1617
1730
 
1618
- function useLinkProps(options) {
1731
+ function Matches() {
1619
1732
  const {
1620
- buildLink,
1621
- state: routerState
1733
+ routesById,
1734
+ state
1622
1735
  } = useRouter();
1623
- const match = useMatch({
1624
- strict: false
1625
- });
1626
- const {
1627
- // custom props
1628
- type,
1629
- children,
1630
- target,
1631
- activeProps = () => ({
1632
- className: 'active'
1633
- }),
1634
- inactiveProps = () => ({}),
1635
- activeOptions,
1636
- disabled,
1637
- hash,
1638
- search,
1639
- params,
1640
- to,
1641
- state,
1642
- mask,
1643
- preload,
1644
- preloadDelay,
1645
- replace,
1646
- // element props
1647
- style,
1648
- className,
1649
- onClick,
1650
- onFocus,
1651
- onMouseEnter,
1652
- onMouseLeave,
1653
- onTouchStart,
1654
- ...rest
1655
- } = options;
1656
- const linkInfo = buildLink(routerState, {
1657
- from: options.to ? match.pathname : undefined,
1658
- ...options
1659
- });
1660
- if (linkInfo.type === 'external') {
1661
- const {
1662
- href
1663
- } = linkInfo;
1664
- return {
1665
- href
1666
- };
1667
- }
1668
- const {
1669
- handleClick,
1670
- handleFocus,
1671
- handleEnter,
1672
- handleLeave,
1673
- handleTouchStart,
1674
- isActive,
1675
- next
1676
- } = linkInfo;
1677
- const handleReactClick = e => {
1678
- if (options.startTransition ?? true) {
1679
- (React.startTransition || (d => d))(() => {
1680
- handleClick(e);
1681
- });
1682
- }
1683
- };
1684
- const composeHandlers = handlers => e => {
1685
- if (e.persist) e.persist();
1686
- handlers.filter(Boolean).forEach(handler => {
1687
- if (e.defaultPrevented) return;
1688
- handler(e);
1689
- });
1690
- };
1691
-
1692
- // Get the active props
1693
- const resolvedActiveProps = isActive ? functionalUpdate(activeProps, {}) ?? {} : {};
1694
-
1695
- // Get the inactive props
1696
- const resolvedInactiveProps = isActive ? {} : functionalUpdate(inactiveProps, {}) ?? {};
1697
- return {
1698
- ...resolvedActiveProps,
1699
- ...resolvedInactiveProps,
1700
- ...rest,
1701
- href: disabled ? undefined : next.maskedLocation ? next.maskedLocation.href : next.href,
1702
- onClick: composeHandlers([onClick, handleReactClick]),
1703
- onFocus: composeHandlers([onFocus, handleFocus]),
1704
- onMouseEnter: composeHandlers([onMouseEnter, handleEnter]),
1705
- onMouseLeave: composeHandlers([onMouseLeave, handleLeave]),
1706
- onTouchStart: composeHandlers([onTouchStart, handleTouchStart]),
1707
- target,
1708
- style: {
1709
- ...style,
1710
- ...resolvedActiveProps.style,
1711
- ...resolvedInactiveProps.style
1712
- },
1713
- className: [className, resolvedActiveProps.className, resolvedInactiveProps.className].filter(Boolean).join(' ') || undefined,
1714
- ...(disabled ? {
1715
- role: 'link',
1716
- 'aria-disabled': true
1717
- } : undefined),
1718
- ['data-status']: isActive ? 'active' : undefined
1719
- };
1720
- }
1721
- const Link = /*#__PURE__*/React.forwardRef((props, ref) => {
1722
- const linkProps = useLinkProps(props);
1723
- return /*#__PURE__*/React.createElement("a", _extends({
1724
- ref: ref
1725
- }, linkProps, {
1726
- children: typeof props.children === 'function' ? props.children({
1727
- isActive: linkProps['data-status'] === 'active'
1728
- }) : props.children
1729
- }));
1730
- });
1731
- function Navigate(props) {
1732
- const {
1733
- navigate
1734
- } = useRouter();
1735
- const match = useMatch({
1736
- strict: false
1737
- });
1738
- useLayoutEffect(() => {
1739
- navigate({
1740
- from: props.to ? match.pathname : undefined,
1741
- ...props
1742
- });
1743
- }, []);
1744
- return null;
1745
- }
1746
- const matchesContext = /*#__PURE__*/React.createContext(null);
1747
- function useRouter() {
1748
- const resolvedContext = window.__TSR_ROUTER_CONTEXT__ || routerContext;
1749
- const value = React.useContext(resolvedContext);
1750
- warning(value, 'useRouter must be used inside a <RouterProvider> component!');
1751
- return value;
1752
- }
1753
- function useRouterState(opts) {
1754
- const {
1755
- state
1756
- } = useRouter();
1757
- // return useStore(router.__store, opts?.select as any)
1758
- return opts?.select ? opts.select(state) : state;
1759
- }
1760
- function useMatches(opts) {
1761
- const contextMatches = React.useContext(matchesContext);
1762
- return useRouterState({
1763
- select: state => {
1764
- const matches = state.matches.slice(state.matches.findIndex(d => d.id === contextMatches[0]?.id));
1765
- return opts?.select ? opts.select(matches) : matches;
1766
- }
1767
- });
1768
- }
1769
- function useMatch(opts) {
1770
- const nearestMatch = React.useContext(matchesContext)[0];
1771
- const nearestMatchRouteId = nearestMatch?.routeId;
1772
- const matchRouteId = useRouterState({
1773
- select: state => {
1774
- const match = opts?.from ? state.matches.find(d => d.routeId === opts?.from) : state.matches.find(d => d.id === nearestMatch.id);
1775
- return match.routeId;
1776
- }
1777
- });
1778
- if (opts?.strict ?? true) {
1779
- invariant(nearestMatchRouteId == matchRouteId, `useMatch("${matchRouteId}") is being called in a component that is meant to render the '${nearestMatchRouteId}' route. Did you mean to 'useMatch("${matchRouteId}", { strict: false })' or 'useRoute("${matchRouteId}")' instead?`);
1780
- }
1781
- const matchSelection = useRouterState({
1782
- select: state => {
1783
- const match = opts?.from ? state.matches.find(d => d.routeId === opts?.from) : state.matches.find(d => d.id === nearestMatch.id);
1784
- invariant(match, `Could not find ${opts?.from ? `an active match from "${opts.from}"` : 'a nearest match!'}`);
1785
- return opts?.select ? opts.select(match) : match;
1786
- }
1787
- });
1788
- return matchSelection;
1789
- }
1790
- function useRouteContext(opts) {
1791
- return useMatch({
1792
- ...opts,
1793
- select: match => opts?.select ? opts.select(match.context) : match.context
1794
- });
1795
- }
1796
- function useSearch(opts) {
1797
- return useMatch({
1798
- ...opts,
1799
- select: match => {
1800
- return opts?.select ? opts.select(match.search) : match.search;
1801
- }
1802
- });
1803
- }
1804
- function useParams(opts) {
1805
- return useRouterState({
1806
- select: state => {
1807
- const params = last(state.matches)?.params;
1808
- return opts?.select ? opts.select(params) : params;
1809
- }
1810
- });
1811
- }
1812
- function useNavigate(defaultOpts) {
1813
- const {
1814
- navigate
1815
- } = useRouter();
1816
- const match = useMatch({
1817
- strict: false
1818
- });
1819
- return React.useCallback(opts => {
1820
- return navigate({
1821
- from: opts?.to ? match.pathname : undefined,
1822
- ...defaultOpts,
1823
- ...opts
1824
- });
1825
- }, []);
1826
- }
1827
- function typedNavigate(navigate) {
1828
- return navigate;
1829
- }
1830
- function useMatchRoute() {
1831
- const {
1832
- state,
1833
- matchRoute
1834
- } = useRouter();
1835
- return React.useCallback(opts => {
1836
- const {
1837
- pending,
1838
- caseSensitive,
1839
- ...rest
1840
- } = opts;
1841
- return matchRoute(state, rest, {
1842
- pending,
1843
- caseSensitive
1844
- });
1845
- }, []);
1846
- }
1847
- function Matches() {
1848
- const {
1849
- routesById,
1850
- state
1851
- } = useRouter();
1852
-
1853
- // const matches = useRouterState({
1854
- // select: (state) => {
1855
- // return state.matches
1856
- // },
1857
- // })
1858
-
1859
1736
  const {
1860
1737
  matches
1861
1738
  } = state;
1862
- const locationKey = useRouterState({
1863
- select: d => d.resolvedLocation.state?.key
1864
- });
1739
+ const locationKey = useRouterState().location.state.key;
1865
1740
  const route = routesById[rootRouteId];
1866
1741
  const errorComponent = React.useCallback(props => {
1867
1742
  return /*#__PURE__*/React.createElement(ErrorComponent, {
@@ -1884,23 +1759,6 @@ function Matches() {
1884
1759
  matches: matches
1885
1760
  }) : null));
1886
1761
  }
1887
- function MatchRoute(props) {
1888
- const matchRoute = useMatchRoute();
1889
- const params = matchRoute(props);
1890
- if (typeof props.children === 'function') {
1891
- return props.children(params);
1892
- }
1893
- return !!params ? props.children : null;
1894
- }
1895
- function Outlet() {
1896
- const matches = React.useContext(matchesContext).slice(1);
1897
- if (!matches[0]) {
1898
- return null;
1899
- }
1900
- return /*#__PURE__*/React.createElement(Match, {
1901
- matches: matches
1902
- });
1903
- }
1904
1762
  const defaultPending = () => null;
1905
1763
  function Match({
1906
1764
  matches
@@ -1912,13 +1770,12 @@ function Match({
1912
1770
  const match = matches[0];
1913
1771
  const routeId = match?.routeId;
1914
1772
  const route = routesById[routeId];
1915
- const locationKey = useRouterState({
1916
- select: s => s.resolvedLocation.state?.key
1917
- });
1773
+ const locationKey = useRouterState().location.state?.key;
1918
1774
  const PendingComponent = route.options.pendingComponent ?? options.defaultPendingComponent ?? defaultPending;
1919
1775
  const routeErrorComponent = route.options.errorComponent ?? options.defaultErrorComponent ?? ErrorComponent;
1920
- const ResolvedSuspenseBoundary = route.options.wrapInSuspense ?? !route.isRoot ? React.Suspense : SafeFragment;
1921
- const ResolvedCatchBoundary = !!routeErrorComponent ? CatchBoundary : SafeFragment;
1776
+ const ResolvedSuspenseBoundary = route.options.wrapInSuspense ?? React.Suspense;
1777
+ // const ResolvedSuspenseBoundary = SafeFragment
1778
+
1922
1779
  const errorComponent = React.useCallback(props => {
1923
1780
  return /*#__PURE__*/React.createElement(routeErrorComponent, {
1924
1781
  ...props,
@@ -1937,7 +1794,7 @@ function Match({
1937
1794
  useSearch: route.useSearch,
1938
1795
  useParams: route.useParams
1939
1796
  })
1940
- }, /*#__PURE__*/React.createElement(ResolvedCatchBoundary, {
1797
+ }, /*#__PURE__*/React.createElement(CatchBoundary, {
1941
1798
  resetKey: locationKey,
1942
1799
  errorComponent: errorComponent,
1943
1800
  onCatch: () => {
@@ -1975,169 +1832,87 @@ function MatchInner({
1975
1832
  }
1976
1833
  invariant(false, 'Idle routeMatch status encountered during rendering! You should never see this. File an issue!');
1977
1834
  }
1978
- function SafeFragment(props) {
1979
- return /*#__PURE__*/React.createElement(React.Fragment, null, props.children);
1980
- }
1981
-
1982
- // export function useInjectHtml() {
1983
- // const { } = useRouter()
1984
-
1985
- // return React.useCallback(
1986
- // (html: string | (() => Promise<string> | string)) => {
1987
- // router.injectHtml(html)
1988
- // },
1989
- // [],
1990
- // )
1991
- // }
1992
-
1993
- // export function useDehydrate() {
1994
- // const { } = useRouter()
1995
-
1996
- // return React.useCallback(function dehydrate<T>(
1997
- // key: any,
1998
- // data: T | (() => Promise<T> | T),
1999
- // ) {
2000
- // return router.dehydrateData(key, data)
2001
- // },
2002
- // [])
2003
- // }
2004
-
2005
- // export function useHydrate() {
2006
- // const { } = useRouter()
2007
-
2008
- // return function hydrate<T = unknown>(key: any) {
2009
- // return router.hydrateData(key) as T
2010
- // }
2011
- // }
2012
-
2013
- // This is the messiest thing ever... I'm either seriously tired (likely) or
2014
- // there has to be a better way to reset error boundaries when the
2015
- // router's location key changes.
2016
-
2017
- function CatchBoundary(props) {
2018
- const errorComponent = props.errorComponent ?? ErrorComponent;
2019
- return /*#__PURE__*/React.createElement(CatchBoundaryImpl, {
2020
- resetKey: props.resetKey,
2021
- onCatch: props.onCatch,
2022
- children: ({
2023
- error
2024
- }) => {
2025
- if (error) {
2026
- return /*#__PURE__*/React.createElement(errorComponent, {
2027
- error
2028
- });
2029
- }
2030
- return props.children;
2031
- }
1835
+ function Outlet() {
1836
+ const matches = React.useContext(matchesContext).slice(1);
1837
+ if (!matches[0]) {
1838
+ return null;
1839
+ }
1840
+ return /*#__PURE__*/React.createElement(Match, {
1841
+ matches: matches
2032
1842
  });
2033
1843
  }
2034
- class CatchBoundaryImpl extends React.Component {
2035
- state = {
2036
- error: null
2037
- };
2038
- static getDerivedStateFromError(error) {
2039
- return {
2040
- error
2041
- };
2042
- }
2043
- componentDidUpdate(prevProps, prevState) {
2044
- if (prevState.error && prevProps.resetKey !== this.props.resetKey) {
2045
- this.setState({
2046
- error: null
2047
- });
2048
- }
2049
- }
2050
- componentDidCatch(error) {
2051
- this.props.onCatch?.(error);
2052
- }
2053
- render() {
2054
- return this.props.children(this.state);
1844
+ function useMatchRoute() {
1845
+ const {
1846
+ matchRoute
1847
+ } = useRouter();
1848
+ return React.useCallback(opts => {
1849
+ const {
1850
+ pending,
1851
+ caseSensitive,
1852
+ ...rest
1853
+ } = opts;
1854
+ return matchRoute(rest, {
1855
+ pending,
1856
+ caseSensitive
1857
+ });
1858
+ }, []);
1859
+ }
1860
+ function MatchRoute(props) {
1861
+ const matchRoute = useMatchRoute();
1862
+ const params = matchRoute(props);
1863
+ if (typeof props.children === 'function') {
1864
+ return props.children(params);
2055
1865
  }
1866
+ return !!params ? props.children : null;
2056
1867
  }
2057
- function ErrorComponent({
2058
- error
2059
- }) {
2060
- const [show, setShow] = React.useState(process.env.NODE_ENV !== 'production');
2061
- return /*#__PURE__*/React.createElement("div", {
2062
- style: {
2063
- padding: '.5rem',
2064
- maxWidth: '100%'
2065
- }
2066
- }, /*#__PURE__*/React.createElement("div", {
2067
- style: {
2068
- display: 'flex',
2069
- alignItems: 'center',
2070
- gap: '.5rem'
2071
- }
2072
- }, /*#__PURE__*/React.createElement("strong", {
2073
- style: {
2074
- fontSize: '1rem'
2075
- }
2076
- }, "Something went wrong!"), /*#__PURE__*/React.createElement("button", {
2077
- style: {
2078
- appearance: 'none',
2079
- fontSize: '.6em',
2080
- border: '1px solid currentColor',
2081
- padding: '.1rem .2rem',
2082
- fontWeight: 'bold',
2083
- borderRadius: '.25rem'
2084
- },
2085
- onClick: () => setShow(d => !d)
2086
- }, show ? 'Hide Error' : 'Show Error')), /*#__PURE__*/React.createElement("div", {
2087
- style: {
2088
- height: '.25rem'
1868
+ function useMatch(opts) {
1869
+ const nearestMatch = React.useContext(matchesContext)[0];
1870
+ const nearestMatchRouteId = nearestMatch?.routeId;
1871
+ const matchRouteId = useRouterState({
1872
+ select: state => {
1873
+ const match = opts?.from ? state.matches.find(d => d.routeId === opts?.from) : state.matches.find(d => d.id === nearestMatch.id);
1874
+ return match.routeId;
2089
1875
  }
2090
- }), show ? /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("pre", {
2091
- style: {
2092
- fontSize: '.7em',
2093
- border: '1px solid red',
2094
- borderRadius: '.25rem',
2095
- padding: '.3rem',
2096
- color: 'red',
2097
- overflow: 'auto'
1876
+ });
1877
+ if (opts?.strict ?? true) {
1878
+ invariant(nearestMatchRouteId == matchRouteId, `useMatch("${matchRouteId}") is being called in a component that is meant to render the '${nearestMatchRouteId}' route. Did you mean to 'useMatch("${matchRouteId}", { strict: false })' or 'useRoute("${matchRouteId}")' instead?`);
1879
+ }
1880
+ const matchSelection = useRouterState({
1881
+ select: state => {
1882
+ const match = opts?.from ? state.matches.find(d => d.routeId === opts?.from) : state.matches.find(d => d.id === nearestMatch.id);
1883
+ invariant(match, `Could not find ${opts?.from ? `an active match from "${opts.from}"` : 'a nearest match!'}`);
1884
+ return opts?.select ? opts.select(match) : match;
2098
1885
  }
2099
- }, error.message ? /*#__PURE__*/React.createElement("code", null, error.message) : null)) : null);
1886
+ });
1887
+ return matchSelection;
2100
1888
  }
2101
- function useBlocker(message, condition = true) {
2102
- const {
2103
- history
2104
- } = useRouter();
2105
- React.useEffect(() => {
2106
- if (!condition) return;
2107
- let unblock = history.block((retry, cancel) => {
2108
- if (window.confirm(message)) {
2109
- unblock();
2110
- retry();
2111
- }
2112
- });
2113
- return unblock;
1889
+ const matchesContext = /*#__PURE__*/React.createContext(null);
1890
+ function useMatches(opts) {
1891
+ const contextMatches = React.useContext(matchesContext);
1892
+ return useRouterState({
1893
+ select: state => {
1894
+ const matches = state.matches.slice(state.matches.findIndex(d => d.id === contextMatches[0]?.id));
1895
+ return opts?.select ? opts.select(matches) : matches;
1896
+ }
2114
1897
  });
2115
1898
  }
2116
- function Block({
2117
- message,
2118
- condition,
2119
- children
2120
- }) {
2121
- useBlocker(message, condition);
2122
- return children ?? null;
1899
+
1900
+ function useParams(opts) {
1901
+ return useRouterState({
1902
+ select: state => {
1903
+ const params = last(state.matches)?.params;
1904
+ return opts?.select ? opts.select(params) : params;
1905
+ }
1906
+ });
2123
1907
  }
2124
- function shallow(objA, objB) {
2125
- if (Object.is(objA, objB)) {
2126
- return true;
2127
- }
2128
- if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
2129
- return false;
2130
- }
2131
- const keysA = Object.keys(objA);
2132
- if (keysA.length !== Object.keys(objB).length) {
2133
- return false;
2134
- }
2135
- for (let i = 0; i < keysA.length; i++) {
2136
- if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !Object.is(objA[keysA[i]], objB[keysA[i]])) {
2137
- return false;
1908
+
1909
+ function useSearch(opts) {
1910
+ return useMatch({
1911
+ ...opts,
1912
+ select: match => {
1913
+ return opts?.select ? opts.select(match.search) : match.search;
2138
1914
  }
2139
- }
2140
- return true;
1915
+ });
2141
1916
  }
2142
1917
 
2143
1918
  const rootRouteId = '__root__';
@@ -2241,6 +2016,8 @@ function createRouteMask(opts) {
2241
2016
  return opts;
2242
2017
  }
2243
2018
 
2019
+ //
2020
+
2244
2021
  class FileRoute {
2245
2022
  constructor(path) {
2246
2023
  this.path = path;
@@ -2252,5 +2029,205 @@ class FileRoute {
2252
2029
  };
2253
2030
  }
2254
2031
 
2255
- export { Block, CatchBoundary, CatchBoundaryImpl, ErrorComponent, FileRoute, Link, MatchRoute, Matches, Navigate, Outlet, PathParamError, RootRoute, Route, Router, RouterProvider, SearchParamError, cleanPath, componentTypes, createRouteMask, decode, defaultParseSearch, defaultStringifySearch, encode, functionalUpdate, getInitialRouterState, getRouteMatch, interpolatePath, isPlainObject, isRedirect, isServer, joinPaths, last, lazyFn, lazyRouteComponent, matchByPath, matchPathname, matchesContext, parsePathname, parseSearchWith, partialDeepEqual, pick, redirect, replaceEqualDeep, resolvePath, rootRouteId, rootRouteWithContext, routerContext, shallow, stringifySearchWith, trimPath, trimPathLeft, trimPathRight, typedNavigate, useBlocker, useLinkProps, useMatch, useMatchRoute, useMatches, useNavigate, useParams, useRouteContext, useRouter, useRouterState, useSearch, useStableCallback };
2032
+ function lazyRouteComponent(importer, exportName) {
2033
+ let loadPromise;
2034
+ const load = () => {
2035
+ if (!loadPromise) {
2036
+ loadPromise = importer();
2037
+ }
2038
+ return loadPromise;
2039
+ };
2040
+ const lazyComp = /*#__PURE__*/React.lazy(async () => {
2041
+ const moduleExports = await load();
2042
+ const comp = moduleExports[exportName ?? 'default'];
2043
+ return {
2044
+ default: comp
2045
+ };
2046
+ });
2047
+ lazyComp.preload = load;
2048
+ return lazyComp;
2049
+ }
2050
+
2051
+ function _extends() {
2052
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
2053
+ for (var i = 1; i < arguments.length; i++) {
2054
+ var source = arguments[i];
2055
+ for (var key in source) {
2056
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
2057
+ target[key] = source[key];
2058
+ }
2059
+ }
2060
+ }
2061
+ return target;
2062
+ };
2063
+ return _extends.apply(this, arguments);
2064
+ }
2065
+
2066
+ function useLinkProps(options) {
2067
+ const {
2068
+ buildLink
2069
+ } = useRouter();
2070
+ const match = useMatch({
2071
+ strict: false
2072
+ });
2073
+ const {
2074
+ // custom props
2075
+ type,
2076
+ children,
2077
+ target,
2078
+ activeProps = () => ({
2079
+ className: 'active'
2080
+ }),
2081
+ inactiveProps = () => ({}),
2082
+ activeOptions,
2083
+ disabled,
2084
+ hash,
2085
+ search,
2086
+ params,
2087
+ to,
2088
+ state,
2089
+ mask,
2090
+ preload,
2091
+ preloadDelay,
2092
+ replace,
2093
+ startTransition,
2094
+ // element props
2095
+ style,
2096
+ className,
2097
+ onClick,
2098
+ onFocus,
2099
+ onMouseEnter,
2100
+ onMouseLeave,
2101
+ onTouchStart,
2102
+ ...rest
2103
+ } = options;
2104
+ const linkInfo = buildLink({
2105
+ from: options.to ? match.pathname : undefined,
2106
+ ...options
2107
+ });
2108
+ if (linkInfo.type === 'external') {
2109
+ const {
2110
+ href
2111
+ } = linkInfo;
2112
+ return {
2113
+ href
2114
+ };
2115
+ }
2116
+ const {
2117
+ handleClick,
2118
+ handleFocus,
2119
+ handleEnter,
2120
+ handleLeave,
2121
+ handleTouchStart,
2122
+ isActive,
2123
+ next
2124
+ } = linkInfo;
2125
+ const composeHandlers = handlers => e => {
2126
+ if (e.persist) e.persist();
2127
+ handlers.filter(Boolean).forEach(handler => {
2128
+ if (e.defaultPrevented) return;
2129
+ handler(e);
2130
+ });
2131
+ };
2132
+
2133
+ // Get the active props
2134
+ const resolvedActiveProps = isActive ? functionalUpdate(activeProps, {}) ?? {} : {};
2135
+
2136
+ // Get the inactive props
2137
+ const resolvedInactiveProps = isActive ? {} : functionalUpdate(inactiveProps, {}) ?? {};
2138
+ return {
2139
+ ...resolvedActiveProps,
2140
+ ...resolvedInactiveProps,
2141
+ ...rest,
2142
+ href: disabled ? undefined : next.maskedLocation ? next.maskedLocation.href : next.href,
2143
+ onClick: composeHandlers([onClick, handleClick]),
2144
+ onFocus: composeHandlers([onFocus, handleFocus]),
2145
+ onMouseEnter: composeHandlers([onMouseEnter, handleEnter]),
2146
+ onMouseLeave: composeHandlers([onMouseLeave, handleLeave]),
2147
+ onTouchStart: composeHandlers([onTouchStart, handleTouchStart]),
2148
+ target,
2149
+ style: {
2150
+ ...style,
2151
+ ...resolvedActiveProps.style,
2152
+ ...resolvedInactiveProps.style
2153
+ },
2154
+ className: [className, resolvedActiveProps.className, resolvedInactiveProps.className].filter(Boolean).join(' ') || undefined,
2155
+ ...(disabled ? {
2156
+ role: 'link',
2157
+ 'aria-disabled': true
2158
+ } : undefined),
2159
+ ['data-status']: isActive ? 'active' : undefined
2160
+ };
2161
+ }
2162
+ const Link = /*#__PURE__*/React.forwardRef((props, ref) => {
2163
+ const linkProps = useLinkProps(props);
2164
+ return /*#__PURE__*/React.createElement("a", _extends({
2165
+ ref: ref
2166
+ }, linkProps, {
2167
+ children: typeof props.children === 'function' ? props.children({
2168
+ isActive: linkProps['data-status'] === 'active'
2169
+ }) : props.children
2170
+ }));
2171
+ });
2172
+
2173
+ function useBlocker(message, condition = true) {
2174
+ const {
2175
+ history
2176
+ } = useRouter();
2177
+ React.useEffect(() => {
2178
+ if (!condition) return;
2179
+ let unblock = history.block((retry, cancel) => {
2180
+ if (window.confirm(message)) {
2181
+ unblock();
2182
+ retry();
2183
+ }
2184
+ });
2185
+ return unblock;
2186
+ });
2187
+ }
2188
+ function Block({
2189
+ message,
2190
+ condition,
2191
+ children
2192
+ }) {
2193
+ useBlocker(message, condition);
2194
+ return children ?? null;
2195
+ }
2196
+
2197
+ function useNavigate(defaultOpts) {
2198
+ const {
2199
+ navigate
2200
+ } = useRouter();
2201
+ const match = useMatch({
2202
+ strict: false
2203
+ });
2204
+ return React.useCallback(opts => {
2205
+ return navigate({
2206
+ from: opts?.to ? match.pathname : undefined,
2207
+ ...defaultOpts,
2208
+ ...opts
2209
+ });
2210
+ }, []);
2211
+ }
2212
+ function typedNavigate(navigate) {
2213
+ return navigate;
2214
+ } //
2215
+
2216
+ function Navigate(props) {
2217
+ const {
2218
+ navigate
2219
+ } = useRouter();
2220
+ const match = useMatch({
2221
+ strict: false
2222
+ });
2223
+ useLayoutEffect(() => {
2224
+ navigate({
2225
+ from: props.to ? match.pathname : undefined,
2226
+ ...props
2227
+ });
2228
+ }, []);
2229
+ return null;
2230
+ }
2231
+
2232
+ export { Block, CatchBoundary, CatchBoundaryImpl, ErrorComponent, FileRoute, Link, Match, MatchRoute, Matches, Navigate, Outlet, PathParamError, RootRoute, Route, Router, RouterProvider, SearchParamError, cleanPath, componentTypes, createRouteMask, decode, defaultParseSearch, defaultStringifySearch, encode, functionalUpdate, getInitialRouterState, getRouteMatch, interpolatePath, isPlainObject, isRedirect, isServer, joinPaths, last, lazyFn, lazyRouteComponent, matchByPath, matchPathname, matchesContext, parsePathname, parseSearchWith, partialDeepEqual, pick, redirect, replaceEqualDeep, resolvePath, rootRouteId, rootRouteWithContext, routerContext, shallow, stringifySearchWith, trimPath, trimPathLeft, trimPathRight, typedNavigate, useBlocker, useLayoutEffect, useLinkProps, useMatch, useMatchRoute, useMatches, useNavigate, useParams, useRouteContext, useRouter, useRouterState, useSearch, useStableCallback };
2256
2233
  //# sourceMappingURL=index.js.map