@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.
@@ -1101,6 +1101,41 @@
1101
1101
  }));
1102
1102
  }
1103
1103
 
1104
+ function multiSortBy(arr, accessors) {
1105
+ if (accessors === void 0) {
1106
+ accessors = [d => d];
1107
+ }
1108
+
1109
+ return arr.map((d, i) => [d, i]).sort((_ref3, _ref4) => {
1110
+ let [a, ai] = _ref3;
1111
+ let [b, bi] = _ref4;
1112
+
1113
+ for (const accessor of accessors) {
1114
+ const ao = accessor(a);
1115
+ const bo = accessor(b);
1116
+
1117
+ if (typeof ao === 'undefined') {
1118
+ if (typeof bo === 'undefined') {
1119
+ continue;
1120
+ }
1121
+
1122
+ return 1;
1123
+ }
1124
+
1125
+ if (ao === bo) {
1126
+ continue;
1127
+ }
1128
+
1129
+ return ao > bo ? 1 : -1;
1130
+ }
1131
+
1132
+ return ai - bi;
1133
+ }).map(_ref5 => {
1134
+ let [d] = _ref5;
1135
+ return d;
1136
+ });
1137
+ }
1138
+
1104
1139
  const Panel = styled('div', (_props, theme) => ({
1105
1140
  fontSize: 'clamp(12px, 1.5vw, 14px)',
1106
1141
  fontFamily: "sans-serif",
@@ -1407,9 +1442,7 @@
1407
1442
  const _excluded = ["style"],
1408
1443
  _excluded2 = ["style", "onClick"],
1409
1444
  _excluded3 = ["style", "onClick"],
1410
- _excluded4 = ["isOpen", "setIsOpen", "handleDragStart", "router"],
1411
- _excluded5 = ["listeners", "buildLocation", "mount", "update", "buildNext", "navigate", "cancelMatches", "loadLocation", "cleanPreloadCache", "loadRoute", "matchRoutes", "loadMatches", "invalidateRoute", "resolvePath", "matchRoute", "buildLink", "__experimental__createSnapshot", "destroy"],
1412
- _excluded6 = ["cancel", "load", "router", "Link", "MatchRoute", "buildLink", "linkProps", "matchRoute", "navigate"];
1445
+ _excluded4 = ["isOpen", "setIsOpen", "handleDragStart", "router"];
1413
1446
  const isServer = typeof window === 'undefined';
1414
1447
  function TanStackRouterDevtools(_ref) {
1415
1448
  let {
@@ -1645,7 +1678,7 @@
1645
1678
  })) : null);
1646
1679
  }
1647
1680
  const TanStackRouterDevtoolsPanel = /*#__PURE__*/React__default["default"].forwardRef(function TanStackRouterDevtoolsPanel(props, ref) {
1648
- var _router$state$matches, _router$state$pending, _last, _last2, _last3, _last4, _last5, _last6;
1681
+ 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;
1649
1682
 
1650
1683
  const {
1651
1684
  isOpen = true,
@@ -1654,15 +1687,10 @@
1654
1687
  } = props,
1655
1688
  panelProps = _objectWithoutPropertiesLoose(props, _excluded4);
1656
1689
 
1657
- const routerExplorerValue = React__default["default"].useMemo(() => {
1658
- const rest = _objectWithoutPropertiesLoose(router, _excluded5);
1659
-
1660
- return rest;
1661
- }, [router.state]);
1662
1690
  const rerender = React__default["default"].useReducer(() => ({}), {})[1];
1663
1691
  React__default["default"].useEffect(() => {
1664
1692
  let interval = setInterval(() => {
1665
- router.cleanPreloadCache(); // router.notify()
1693
+ router.cleanMatchCache(); // router.notify()
1666
1694
 
1667
1695
  rerender();
1668
1696
  }, 250);
@@ -1671,16 +1699,15 @@
1671
1699
  };
1672
1700
  }, []);
1673
1701
  const [activeRouteId, setActiveRouteId] = useLocalStorage('tanstackRouterDevtoolsActiveRouteId', '');
1674
- const activeMatch = (_router$state$matches = router.state.matches) == null ? void 0 : _router$state$matches.find(d => d.routeId === activeRouteId);
1675
- const activeMatchExplorerValue = React__default["default"].useMemo(() => {
1676
- if (!activeMatch) {
1677
- return {};
1678
- }
1679
-
1680
- const rest = _objectWithoutPropertiesLoose(activeMatch, _excluded6);
1681
-
1682
- return rest;
1683
- }, [activeMatch]);
1702
+ const [activeMatchId, setActiveMatchId] = useLocalStorage('tanstackRouterDevtoolsActiveMatchId', '');
1703
+ React__default["default"].useEffect(() => {
1704
+ setActiveMatchId('');
1705
+ }, [activeRouteId]);
1706
+ 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);
1707
+ const matchCacheValues = multiSortBy(Object.keys(router.matchCache).filter(key => {
1708
+ const cacheEntry = router.matchCache[key];
1709
+ return cacheEntry.gc > Date.now();
1710
+ }).map(key => router.matchCache[key]), [d => d.match.isFetching ? -1 : 1, d => -d.match.updatedAt]);
1684
1711
  return /*#__PURE__*/React__default["default"].createElement(ThemeProvider, {
1685
1712
  theme: defaultTheme
1686
1713
  }, /*#__PURE__*/React__default["default"].createElement(Panel, _extends({
@@ -1746,7 +1773,7 @@
1746
1773
  }
1747
1774
  }, /*#__PURE__*/React__default["default"].createElement(Explorer, {
1748
1775
  label: "Router",
1749
- value: routerExplorerValue,
1776
+ value: router,
1750
1777
  defaultExpanded: {}
1751
1778
  })))), /*#__PURE__*/React__default["default"].createElement("div", {
1752
1779
  style: {
@@ -1766,7 +1793,7 @@
1766
1793
  top: 0,
1767
1794
  zIndex: 1
1768
1795
  }
1769
- }, "Current Matches"), router.state.matches.map((match, i) => {
1796
+ }, "Active Matches"), router.state.matches.map((match, i) => {
1770
1797
  return /*#__PURE__*/React__default["default"].createElement("div", {
1771
1798
  key: match.routeId || i,
1772
1799
  role: "button",
@@ -1797,7 +1824,7 @@
1797
1824
  padding: '.5em'
1798
1825
  }
1799
1826
  }, "" + match.matchId));
1800
- }), /*#__PURE__*/React__default["default"].createElement("div", {
1827
+ }), (_router$state$pending = router.state.pending) != null && _router$state$pending.matches.length ? /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement("div", {
1801
1828
  style: {
1802
1829
  marginTop: '2rem',
1803
1830
  padding: '.5em',
@@ -1806,7 +1833,7 @@
1806
1833
  top: 0,
1807
1834
  zIndex: 1
1808
1835
  }
1809
- }, "Pending Matches"), (_router$state$pending = router.state.pending) == null ? void 0 : _router$state$pending.matches.map((match, i) => {
1836
+ }, "Pending Matches"), (_router$state$pending2 = router.state.pending) == null ? void 0 : _router$state$pending2.matches.map((match, i) => {
1810
1837
  return /*#__PURE__*/React__default["default"].createElement("div", {
1811
1838
  key: match.routeId || i,
1812
1839
  role: "button",
@@ -1836,32 +1863,33 @@
1836
1863
  padding: '.5em'
1837
1864
  }
1838
1865
  }, "" + match.matchId));
1839
- }), /*#__PURE__*/React__default["default"].createElement("div", {
1866
+ })) : null, matchCacheValues.length ? /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement("div", {
1840
1867
  style: {
1841
1868
  marginTop: '2rem',
1842
1869
  padding: '.5em',
1843
1870
  background: defaultTheme.backgroundAlt,
1844
1871
  position: 'sticky',
1845
1872
  top: 0,
1846
- zIndex: 1
1873
+ zIndex: 1,
1874
+ display: 'flex',
1875
+ alignItems: 'center',
1876
+ justifyContent: 'space-between'
1847
1877
  }
1848
- }, "Preloading Matches"), Object.keys(router.preloadCache).filter(key => {
1849
- var _cacheEntry$match$upd;
1850
-
1851
- const cacheEntry = router.preloadCache[key];
1852
- return ((_cacheEntry$match$upd = cacheEntry.match.updatedAt) != null ? _cacheEntry$match$upd : Date.now()) + cacheEntry.maxAge > Date.now();
1853
- }).map((key, i) => {
1854
- var _match$updatedAt;
1855
-
1878
+ }, /*#__PURE__*/React__default["default"].createElement("div", null, "Match Cache"), /*#__PURE__*/React__default["default"].createElement(Button, {
1879
+ onClick: () => {
1880
+ router.matchCache = {};
1881
+ router.notify();
1882
+ }
1883
+ }, "Clear")), matchCacheValues.map((d, i) => {
1856
1884
  const {
1857
1885
  match,
1858
- maxAge
1859
- } = router.preloadCache[key];
1886
+ gc
1887
+ } = d;
1860
1888
  return /*#__PURE__*/React__default["default"].createElement("div", {
1861
1889
  key: match.matchId || i,
1862
1890
  role: "button",
1863
1891
  "aria-label": "Open match details for " + match.matchId,
1864
- onClick: () => setActiveRouteId(activeRouteId === match.routeId ? '' : match.routeId),
1892
+ onClick: () => setActiveMatchId(activeMatchId === match.matchId ? '' : match.matchId),
1865
1893
  style: {
1866
1894
  display: 'flex',
1867
1895
  borderBottom: "solid 1px " + defaultTheme.grayAlt,
@@ -1897,10 +1925,10 @@
1897
1925
  style: {
1898
1926
  opacity: '.5'
1899
1927
  }
1900
- }, "Expires", ' ', formatDistanceStrict(new Date(), new Date(((_match$updatedAt = match.updatedAt) != null ? _match$updatedAt : Date.now()) + maxAge), {
1928
+ }, "Expires", ' ', formatDistanceStrict(new Date(), new Date(gc), {
1901
1929
  addSuffix: true
1902
1930
  }))));
1903
- })), activeMatch ? /*#__PURE__*/React__default["default"].createElement(ActivePanel, null, /*#__PURE__*/React__default["default"].createElement("div", {
1931
+ })) : null), activeMatch ? /*#__PURE__*/React__default["default"].createElement(ActivePanel, null, /*#__PURE__*/React__default["default"].createElement("div", {
1904
1932
  style: {
1905
1933
  padding: '.5em',
1906
1934
  background: defaultTheme.backgroundAlt,
@@ -1974,7 +2002,7 @@
1974
2002
  }
1975
2003
  }, /*#__PURE__*/React__default["default"].createElement(Explorer, {
1976
2004
  label: "Match",
1977
- value: activeMatchExplorerValue,
2005
+ value: activeMatch,
1978
2006
  defaultExpanded: {}
1979
2007
  }))) : null, /*#__PURE__*/React__default["default"].createElement("div", {
1980
2008
  style: {