@tanstack/react-router-devtools 0.0.1-alpha.5 → 0.0.1-alpha.7

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.
@@ -10,7 +10,7 @@
10
10
  */
11
11
  import * as React from 'react';
12
12
  import React__default from 'react';
13
- import { last, useRouter } from '@tanstack/react-router';
13
+ import { last } from '@tanstack/react-router';
14
14
 
15
15
  function _extends() {
16
16
  _extends = Object.assign ? Object.assign.bind() : function (target) {
@@ -1076,6 +1076,41 @@ function scheduleMicrotask(callback) {
1076
1076
  }));
1077
1077
  }
1078
1078
 
1079
+ function multiSortBy(arr, accessors) {
1080
+ if (accessors === void 0) {
1081
+ accessors = [d => d];
1082
+ }
1083
+
1084
+ return arr.map((d, i) => [d, i]).sort((_ref3, _ref4) => {
1085
+ let [a, ai] = _ref3;
1086
+ let [b, bi] = _ref4;
1087
+
1088
+ for (const accessor of accessors) {
1089
+ const ao = accessor(a);
1090
+ const bo = accessor(b);
1091
+
1092
+ if (typeof ao === 'undefined') {
1093
+ if (typeof bo === 'undefined') {
1094
+ continue;
1095
+ }
1096
+
1097
+ return 1;
1098
+ }
1099
+
1100
+ if (ao === bo) {
1101
+ continue;
1102
+ }
1103
+
1104
+ return ao > bo ? 1 : -1;
1105
+ }
1106
+
1107
+ return ai - bi;
1108
+ }).map(_ref5 => {
1109
+ let [d] = _ref5;
1110
+ return d;
1111
+ });
1112
+ }
1113
+
1079
1114
  const Panel = styled('div', (_props, theme) => ({
1080
1115
  fontSize: 'clamp(12px, 1.5vw, 14px)',
1081
1116
  fontFamily: "sans-serif",
@@ -1382,9 +1417,7 @@ function Logo(props) {
1382
1417
  const _excluded = ["style"],
1383
1418
  _excluded2 = ["style", "onClick"],
1384
1419
  _excluded3 = ["style", "onClick"],
1385
- _excluded4 = ["isOpen", "setIsOpen", "handleDragStart", "useRouter"],
1386
- _excluded5 = ["listeners", "buildLocation", "mount", "update", "buildNext", "navigate", "cancelMatches", "loadLocation", "cleanPreloadCache", "loadRoute", "matchRoutes", "loadMatches", "invalidateRoute", "resolvePath", "matchRoute", "buildLink", "__experimental__createSnapshot", "destroy"],
1387
- _excluded6 = ["cancel", "load", "router", "Link", "MatchRoute", "buildLink", "linkProps", "matchRoute", "navigate"];
1420
+ _excluded4 = ["isOpen", "setIsOpen", "handleDragStart", "router"];
1388
1421
  const isServer = typeof window === 'undefined';
1389
1422
  function TanStackRouterDevtools(_ref) {
1390
1423
  let {
@@ -1394,7 +1427,7 @@ function TanStackRouterDevtools(_ref) {
1394
1427
  toggleButtonProps = {},
1395
1428
  position = 'bottom-left',
1396
1429
  containerElement: Container = 'footer',
1397
- useRouter: useRouterImpl = useRouter
1430
+ router
1398
1431
  } = _ref;
1399
1432
  const rootRef = React__default.useRef(null);
1400
1433
  const panelRef = React__default.useRef(null);
@@ -1530,7 +1563,7 @@ function TanStackRouterDevtools(_ref) {
1530
1563
  }, /*#__PURE__*/React__default.createElement(TanStackRouterDevtoolsPanel, _extends({
1531
1564
  ref: panelRef
1532
1565
  }, otherPanelProps, {
1533
- useRouter: useRouterImpl,
1566
+ router: router,
1534
1567
  style: _extends({
1535
1568
  position: 'fixed',
1536
1569
  bottom: '0',
@@ -1620,25 +1653,19 @@ function TanStackRouterDevtools(_ref) {
1620
1653
  })) : null);
1621
1654
  }
1622
1655
  const TanStackRouterDevtoolsPanel = /*#__PURE__*/React__default.forwardRef(function TanStackRouterDevtoolsPanel(props, ref) {
1623
- var _router$state$matches, _router$state$pending, _last, _last2, _last3, _last4, _last5, _last6;
1656
+ var _Object$values$find$m, _Object$values, _Object$values$find, _router$state$matches, _router$state$pending, _router$state$pending2, _last, _last2, _last3, _last4, _last5, _last6;
1624
1657
 
1625
1658
  const {
1626
1659
  isOpen = true,
1627
1660
  handleDragStart,
1628
- useRouter
1661
+ router
1629
1662
  } = props,
1630
1663
  panelProps = _objectWithoutPropertiesLoose(props, _excluded4);
1631
1664
 
1632
- const router = useRouter();
1633
- const routerExplorerValue = React__default.useMemo(() => {
1634
- const rest = _objectWithoutPropertiesLoose(router, _excluded5);
1635
-
1636
- return rest;
1637
- }, [router.state]);
1638
1665
  const rerender = React__default.useReducer(() => ({}), {})[1];
1639
1666
  React__default.useEffect(() => {
1640
1667
  let interval = setInterval(() => {
1641
- router.cleanPreloadCache(); // router.notify()
1668
+ router.cleanMatchCache(); // router.notify()
1642
1669
 
1643
1670
  rerender();
1644
1671
  }, 250);
@@ -1647,16 +1674,15 @@ const TanStackRouterDevtoolsPanel = /*#__PURE__*/React__default.forwardRef(funct
1647
1674
  };
1648
1675
  }, []);
1649
1676
  const [activeRouteId, setActiveRouteId] = useLocalStorage('tanstackRouterDevtoolsActiveRouteId', '');
1650
- const activeMatch = (_router$state$matches = router.state.matches) == null ? void 0 : _router$state$matches.find(d => d.routeId === activeRouteId);
1651
- const activeMatchExplorerValue = React__default.useMemo(() => {
1652
- if (!activeMatch) {
1653
- return {};
1654
- }
1655
-
1656
- const rest = _objectWithoutPropertiesLoose(activeMatch, _excluded6);
1657
-
1658
- return rest;
1659
- }, [activeMatch]);
1677
+ const [activeMatchId, setActiveMatchId] = useLocalStorage('tanstackRouterDevtoolsActiveMatchId', '');
1678
+ React__default.useEffect(() => {
1679
+ setActiveMatchId('');
1680
+ }, [activeRouteId]);
1681
+ const activeMatch = (_Object$values$find$m = (_Object$values = Object.values(router.matchCache)) == null ? void 0 : (_Object$values$find = _Object$values.find(d => d.match.matchId === activeMatchId)) == null ? void 0 : _Object$values$find.match) != null ? _Object$values$find$m : (_router$state$matches = router.state.matches) == null ? void 0 : _router$state$matches.find(d => d.routeId === activeRouteId);
1682
+ const matchCacheValues = multiSortBy(Object.keys(router.matchCache).filter(key => {
1683
+ const cacheEntry = router.matchCache[key];
1684
+ return cacheEntry.gc > Date.now();
1685
+ }).map(key => router.matchCache[key]), [d => d.match.isFetching ? -1 : 1, d => -d.match.updatedAt]);
1660
1686
  return /*#__PURE__*/React__default.createElement(ThemeProvider, {
1661
1687
  theme: defaultTheme
1662
1688
  }, /*#__PURE__*/React__default.createElement(Panel, _extends({
@@ -1722,7 +1748,7 @@ const TanStackRouterDevtoolsPanel = /*#__PURE__*/React__default.forwardRef(funct
1722
1748
  }
1723
1749
  }, /*#__PURE__*/React__default.createElement(Explorer, {
1724
1750
  label: "Router",
1725
- value: routerExplorerValue,
1751
+ value: router,
1726
1752
  defaultExpanded: {}
1727
1753
  })))), /*#__PURE__*/React__default.createElement("div", {
1728
1754
  style: {
@@ -1742,7 +1768,7 @@ const TanStackRouterDevtoolsPanel = /*#__PURE__*/React__default.forwardRef(funct
1742
1768
  top: 0,
1743
1769
  zIndex: 1
1744
1770
  }
1745
- }, "Current Matches"), router.state.matches.map((match, i) => {
1771
+ }, "Active Matches"), router.state.matches.map((match, i) => {
1746
1772
  return /*#__PURE__*/React__default.createElement("div", {
1747
1773
  key: match.routeId || i,
1748
1774
  role: "button",
@@ -1773,7 +1799,7 @@ const TanStackRouterDevtoolsPanel = /*#__PURE__*/React__default.forwardRef(funct
1773
1799
  padding: '.5em'
1774
1800
  }
1775
1801
  }, "" + match.matchId));
1776
- }), /*#__PURE__*/React__default.createElement("div", {
1802
+ }), (_router$state$pending = router.state.pending) != null && _router$state$pending.matches.length ? /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("div", {
1777
1803
  style: {
1778
1804
  marginTop: '2rem',
1779
1805
  padding: '.5em',
@@ -1782,7 +1808,7 @@ const TanStackRouterDevtoolsPanel = /*#__PURE__*/React__default.forwardRef(funct
1782
1808
  top: 0,
1783
1809
  zIndex: 1
1784
1810
  }
1785
- }, "Pending Matches"), (_router$state$pending = router.state.pending) == null ? void 0 : _router$state$pending.matches.map((match, i) => {
1811
+ }, "Pending Matches"), (_router$state$pending2 = router.state.pending) == null ? void 0 : _router$state$pending2.matches.map((match, i) => {
1786
1812
  return /*#__PURE__*/React__default.createElement("div", {
1787
1813
  key: match.routeId || i,
1788
1814
  role: "button",
@@ -1812,32 +1838,33 @@ const TanStackRouterDevtoolsPanel = /*#__PURE__*/React__default.forwardRef(funct
1812
1838
  padding: '.5em'
1813
1839
  }
1814
1840
  }, "" + match.matchId));
1815
- }), /*#__PURE__*/React__default.createElement("div", {
1841
+ })) : null, matchCacheValues.length ? /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("div", {
1816
1842
  style: {
1817
1843
  marginTop: '2rem',
1818
1844
  padding: '.5em',
1819
1845
  background: defaultTheme.backgroundAlt,
1820
1846
  position: 'sticky',
1821
1847
  top: 0,
1822
- zIndex: 1
1848
+ zIndex: 1,
1849
+ display: 'flex',
1850
+ alignItems: 'center',
1851
+ justifyContent: 'space-between'
1823
1852
  }
1824
- }, "Preloading Matches"), Object.keys(router.preloadCache).filter(key => {
1825
- var _cacheEntry$match$upd;
1826
-
1827
- const cacheEntry = router.preloadCache[key];
1828
- return ((_cacheEntry$match$upd = cacheEntry.match.updatedAt) != null ? _cacheEntry$match$upd : Date.now()) + cacheEntry.maxAge > Date.now();
1829
- }).map((key, i) => {
1830
- var _match$updatedAt;
1831
-
1853
+ }, /*#__PURE__*/React__default.createElement("div", null, "Match Cache"), /*#__PURE__*/React__default.createElement(Button, {
1854
+ onClick: () => {
1855
+ router.matchCache = {};
1856
+ router.notify();
1857
+ }
1858
+ }, "Clear")), matchCacheValues.map((d, i) => {
1832
1859
  const {
1833
1860
  match,
1834
- maxAge
1835
- } = router.preloadCache[key];
1861
+ gc
1862
+ } = d;
1836
1863
  return /*#__PURE__*/React__default.createElement("div", {
1837
1864
  key: match.matchId || i,
1838
1865
  role: "button",
1839
1866
  "aria-label": "Open match details for " + match.matchId,
1840
- onClick: () => setActiveRouteId(activeRouteId === match.routeId ? '' : match.routeId),
1867
+ onClick: () => setActiveMatchId(activeMatchId === match.matchId ? '' : match.matchId),
1841
1868
  style: {
1842
1869
  display: 'flex',
1843
1870
  borderBottom: "solid 1px " + defaultTheme.grayAlt,
@@ -1873,10 +1900,10 @@ const TanStackRouterDevtoolsPanel = /*#__PURE__*/React__default.forwardRef(funct
1873
1900
  style: {
1874
1901
  opacity: '.5'
1875
1902
  }
1876
- }, "Expires", ' ', formatDistanceStrict(new Date(), new Date(((_match$updatedAt = match.updatedAt) != null ? _match$updatedAt : Date.now()) + maxAge), {
1903
+ }, "Expires", ' ', formatDistanceStrict(new Date(), new Date(gc), {
1877
1904
  addSuffix: true
1878
1905
  }))));
1879
- })), activeMatch ? /*#__PURE__*/React__default.createElement(ActivePanel, null, /*#__PURE__*/React__default.createElement("div", {
1906
+ })) : null), activeMatch ? /*#__PURE__*/React__default.createElement(ActivePanel, null, /*#__PURE__*/React__default.createElement("div", {
1880
1907
  style: {
1881
1908
  padding: '.5em',
1882
1909
  background: defaultTheme.backgroundAlt,
@@ -1923,7 +1950,7 @@ const TanStackRouterDevtoolsPanel = /*#__PURE__*/React__default.forwardRef(funct
1923
1950
  }, /*#__PURE__*/React__default.createElement(Button, {
1924
1951
  type: "button",
1925
1952
  onClick: () => {
1926
- router.invalidateRoute(activeMatch);
1953
+ activeMatch.invalidate();
1927
1954
  router.notify();
1928
1955
  },
1929
1956
  style: {
@@ -1932,7 +1959,7 @@ const TanStackRouterDevtoolsPanel = /*#__PURE__*/React__default.forwardRef(funct
1932
1959
  }
1933
1960
  }, "Invalidate"), ' ', /*#__PURE__*/React__default.createElement(Button, {
1934
1961
  type: "button",
1935
- onClick: () => router.reload(),
1962
+ onClick: () => activeMatch.load(),
1936
1963
  style: {
1937
1964
  background: defaultTheme.gray
1938
1965
  }
@@ -1950,7 +1977,7 @@ const TanStackRouterDevtoolsPanel = /*#__PURE__*/React__default.forwardRef(funct
1950
1977
  }
1951
1978
  }, /*#__PURE__*/React__default.createElement(Explorer, {
1952
1979
  label: "Match",
1953
- value: activeMatchExplorerValue,
1980
+ value: activeMatch,
1954
1981
  defaultExpanded: {}
1955
1982
  }))) : null, /*#__PURE__*/React__default.createElement("div", {
1956
1983
  style: {