@tanstack/react-router-devtools 0.0.1-alpha.6 → 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.
@@ -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", "router"],
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 {
@@ -1620,7 +1653,7 @@ 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,
@@ -1629,15 +1662,10 @@ const TanStackRouterDevtoolsPanel = /*#__PURE__*/React__default.forwardRef(funct
1629
1662
  } = props,
1630
1663
  panelProps = _objectWithoutPropertiesLoose(props, _excluded4);
1631
1664
 
1632
- const routerExplorerValue = React__default.useMemo(() => {
1633
- const rest = _objectWithoutPropertiesLoose(router, _excluded5);
1634
-
1635
- return rest;
1636
- }, [router.state]);
1637
1665
  const rerender = React__default.useReducer(() => ({}), {})[1];
1638
1666
  React__default.useEffect(() => {
1639
1667
  let interval = setInterval(() => {
1640
- router.cleanPreloadCache(); // router.notify()
1668
+ router.cleanMatchCache(); // router.notify()
1641
1669
 
1642
1670
  rerender();
1643
1671
  }, 250);
@@ -1646,16 +1674,15 @@ const TanStackRouterDevtoolsPanel = /*#__PURE__*/React__default.forwardRef(funct
1646
1674
  };
1647
1675
  }, []);
1648
1676
  const [activeRouteId, setActiveRouteId] = useLocalStorage('tanstackRouterDevtoolsActiveRouteId', '');
1649
- const activeMatch = (_router$state$matches = router.state.matches) == null ? void 0 : _router$state$matches.find(d => d.routeId === activeRouteId);
1650
- const activeMatchExplorerValue = React__default.useMemo(() => {
1651
- if (!activeMatch) {
1652
- return {};
1653
- }
1654
-
1655
- const rest = _objectWithoutPropertiesLoose(activeMatch, _excluded6);
1656
-
1657
- return rest;
1658
- }, [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]);
1659
1686
  return /*#__PURE__*/React__default.createElement(ThemeProvider, {
1660
1687
  theme: defaultTheme
1661
1688
  }, /*#__PURE__*/React__default.createElement(Panel, _extends({
@@ -1721,7 +1748,7 @@ const TanStackRouterDevtoolsPanel = /*#__PURE__*/React__default.forwardRef(funct
1721
1748
  }
1722
1749
  }, /*#__PURE__*/React__default.createElement(Explorer, {
1723
1750
  label: "Router",
1724
- value: routerExplorerValue,
1751
+ value: router,
1725
1752
  defaultExpanded: {}
1726
1753
  })))), /*#__PURE__*/React__default.createElement("div", {
1727
1754
  style: {
@@ -1741,7 +1768,7 @@ const TanStackRouterDevtoolsPanel = /*#__PURE__*/React__default.forwardRef(funct
1741
1768
  top: 0,
1742
1769
  zIndex: 1
1743
1770
  }
1744
- }, "Current Matches"), router.state.matches.map((match, i) => {
1771
+ }, "Active Matches"), router.state.matches.map((match, i) => {
1745
1772
  return /*#__PURE__*/React__default.createElement("div", {
1746
1773
  key: match.routeId || i,
1747
1774
  role: "button",
@@ -1772,7 +1799,7 @@ const TanStackRouterDevtoolsPanel = /*#__PURE__*/React__default.forwardRef(funct
1772
1799
  padding: '.5em'
1773
1800
  }
1774
1801
  }, "" + match.matchId));
1775
- }), /*#__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", {
1776
1803
  style: {
1777
1804
  marginTop: '2rem',
1778
1805
  padding: '.5em',
@@ -1781,7 +1808,7 @@ const TanStackRouterDevtoolsPanel = /*#__PURE__*/React__default.forwardRef(funct
1781
1808
  top: 0,
1782
1809
  zIndex: 1
1783
1810
  }
1784
- }, "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) => {
1785
1812
  return /*#__PURE__*/React__default.createElement("div", {
1786
1813
  key: match.routeId || i,
1787
1814
  role: "button",
@@ -1811,32 +1838,33 @@ const TanStackRouterDevtoolsPanel = /*#__PURE__*/React__default.forwardRef(funct
1811
1838
  padding: '.5em'
1812
1839
  }
1813
1840
  }, "" + match.matchId));
1814
- }), /*#__PURE__*/React__default.createElement("div", {
1841
+ })) : null, matchCacheValues.length ? /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement("div", {
1815
1842
  style: {
1816
1843
  marginTop: '2rem',
1817
1844
  padding: '.5em',
1818
1845
  background: defaultTheme.backgroundAlt,
1819
1846
  position: 'sticky',
1820
1847
  top: 0,
1821
- zIndex: 1
1848
+ zIndex: 1,
1849
+ display: 'flex',
1850
+ alignItems: 'center',
1851
+ justifyContent: 'space-between'
1822
1852
  }
1823
- }, "Preloading Matches"), Object.keys(router.preloadCache).filter(key => {
1824
- var _cacheEntry$match$upd;
1825
-
1826
- const cacheEntry = router.preloadCache[key];
1827
- return ((_cacheEntry$match$upd = cacheEntry.match.updatedAt) != null ? _cacheEntry$match$upd : Date.now()) + cacheEntry.maxAge > Date.now();
1828
- }).map((key, i) => {
1829
- var _match$updatedAt;
1830
-
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) => {
1831
1859
  const {
1832
1860
  match,
1833
- maxAge
1834
- } = router.preloadCache[key];
1861
+ gc
1862
+ } = d;
1835
1863
  return /*#__PURE__*/React__default.createElement("div", {
1836
1864
  key: match.matchId || i,
1837
1865
  role: "button",
1838
1866
  "aria-label": "Open match details for " + match.matchId,
1839
- onClick: () => setActiveRouteId(activeRouteId === match.routeId ? '' : match.routeId),
1867
+ onClick: () => setActiveMatchId(activeMatchId === match.matchId ? '' : match.matchId),
1840
1868
  style: {
1841
1869
  display: 'flex',
1842
1870
  borderBottom: "solid 1px " + defaultTheme.grayAlt,
@@ -1872,10 +1900,10 @@ const TanStackRouterDevtoolsPanel = /*#__PURE__*/React__default.forwardRef(funct
1872
1900
  style: {
1873
1901
  opacity: '.5'
1874
1902
  }
1875
- }, "Expires", ' ', formatDistanceStrict(new Date(), new Date(((_match$updatedAt = match.updatedAt) != null ? _match$updatedAt : Date.now()) + maxAge), {
1903
+ }, "Expires", ' ', formatDistanceStrict(new Date(), new Date(gc), {
1876
1904
  addSuffix: true
1877
1905
  }))));
1878
- })), 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", {
1879
1907
  style: {
1880
1908
  padding: '.5em',
1881
1909
  background: defaultTheme.backgroundAlt,
@@ -1949,7 +1977,7 @@ const TanStackRouterDevtoolsPanel = /*#__PURE__*/React__default.forwardRef(funct
1949
1977
  }
1950
1978
  }, /*#__PURE__*/React__default.createElement(Explorer, {
1951
1979
  label: "Match",
1952
- value: activeMatchExplorerValue,
1980
+ value: activeMatch,
1953
1981
  defaultExpanded: {}
1954
1982
  }))) : null, /*#__PURE__*/React__default.createElement("div", {
1955
1983
  style: {