@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.
- package/build/cjs/packages/react-router-devtools/src/devtools.js +38 -46
- package/build/cjs/packages/react-router-devtools/src/devtools.js.map +1 -1
- package/build/cjs/packages/react-router-devtools/src/utils.js +36 -0
- package/build/cjs/packages/react-router-devtools/src/utils.js.map +1 -1
- package/build/esm/index.js +74 -47
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +2677 -2677
- package/build/types/index.d.ts +4 -3
- package/build/umd/index.development.js +73 -46
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/devtools.tsx +171 -189
- package/src/utils.ts +30 -0
package/build/types/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
11
|
import React from 'react';
|
|
12
|
+
import { Router } from '@tanstack/react-router';
|
|
12
13
|
|
|
13
14
|
declare type PartialKeys<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
14
15
|
interface DevtoolsOptions {
|
|
@@ -42,7 +43,7 @@ interface DevtoolsOptions {
|
|
|
42
43
|
/**
|
|
43
44
|
* A boolean variable indicating if the "lite" version of the library is being used
|
|
44
45
|
*/
|
|
45
|
-
|
|
46
|
+
router: Router<any, any>;
|
|
46
47
|
}
|
|
47
48
|
interface DevtoolsPanelOptions {
|
|
48
49
|
/**
|
|
@@ -68,9 +69,9 @@ interface DevtoolsPanelOptions {
|
|
|
68
69
|
/**
|
|
69
70
|
* A boolean variable indicating if the "lite" version of the library is being used
|
|
70
71
|
*/
|
|
71
|
-
|
|
72
|
+
router: Router<any, any>;
|
|
72
73
|
}
|
|
73
|
-
declare function TanStackRouterDevtools({ initialIsOpen, panelProps, closeButtonProps, toggleButtonProps, position, containerElement: Container,
|
|
74
|
+
declare function TanStackRouterDevtools({ initialIsOpen, panelProps, closeButtonProps, toggleButtonProps, position, containerElement: Container, router, }: DevtoolsOptions): React.ReactElement | null;
|
|
74
75
|
declare const TanStackRouterDevtoolsPanel: React.ForwardRefExoticComponent<DevtoolsPanelOptions & React.RefAttributes<HTMLDivElement>>;
|
|
75
76
|
|
|
76
77
|
export { PartialKeys, TanStackRouterDevtools, TanStackRouterDevtoolsPanel };
|
|
@@ -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", "
|
|
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 {
|
|
@@ -1419,7 +1452,7 @@
|
|
|
1419
1452
|
toggleButtonProps = {},
|
|
1420
1453
|
position = 'bottom-left',
|
|
1421
1454
|
containerElement: Container = 'footer',
|
|
1422
|
-
|
|
1455
|
+
router
|
|
1423
1456
|
} = _ref;
|
|
1424
1457
|
const rootRef = React__default["default"].useRef(null);
|
|
1425
1458
|
const panelRef = React__default["default"].useRef(null);
|
|
@@ -1555,7 +1588,7 @@
|
|
|
1555
1588
|
}, /*#__PURE__*/React__default["default"].createElement(TanStackRouterDevtoolsPanel, _extends({
|
|
1556
1589
|
ref: panelRef
|
|
1557
1590
|
}, otherPanelProps, {
|
|
1558
|
-
|
|
1591
|
+
router: router,
|
|
1559
1592
|
style: _extends({
|
|
1560
1593
|
position: 'fixed',
|
|
1561
1594
|
bottom: '0',
|
|
@@ -1645,25 +1678,19 @@
|
|
|
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,
|
|
1652
1685
|
handleDragStart,
|
|
1653
|
-
|
|
1686
|
+
router
|
|
1654
1687
|
} = props,
|
|
1655
1688
|
panelProps = _objectWithoutPropertiesLoose(props, _excluded4);
|
|
1656
1689
|
|
|
1657
|
-
const router = useRouter();
|
|
1658
|
-
const routerExplorerValue = React__default["default"].useMemo(() => {
|
|
1659
|
-
const rest = _objectWithoutPropertiesLoose(router, _excluded5);
|
|
1660
|
-
|
|
1661
|
-
return rest;
|
|
1662
|
-
}, [router.state]);
|
|
1663
1690
|
const rerender = React__default["default"].useReducer(() => ({}), {})[1];
|
|
1664
1691
|
React__default["default"].useEffect(() => {
|
|
1665
1692
|
let interval = setInterval(() => {
|
|
1666
|
-
router.
|
|
1693
|
+
router.cleanMatchCache(); // router.notify()
|
|
1667
1694
|
|
|
1668
1695
|
rerender();
|
|
1669
1696
|
}, 250);
|
|
@@ -1672,16 +1699,15 @@
|
|
|
1672
1699
|
};
|
|
1673
1700
|
}, []);
|
|
1674
1701
|
const [activeRouteId, setActiveRouteId] = useLocalStorage('tanstackRouterDevtoolsActiveRouteId', '');
|
|
1675
|
-
const
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
const
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
}, [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]);
|
|
1685
1711
|
return /*#__PURE__*/React__default["default"].createElement(ThemeProvider, {
|
|
1686
1712
|
theme: defaultTheme
|
|
1687
1713
|
}, /*#__PURE__*/React__default["default"].createElement(Panel, _extends({
|
|
@@ -1747,7 +1773,7 @@
|
|
|
1747
1773
|
}
|
|
1748
1774
|
}, /*#__PURE__*/React__default["default"].createElement(Explorer, {
|
|
1749
1775
|
label: "Router",
|
|
1750
|
-
value:
|
|
1776
|
+
value: router,
|
|
1751
1777
|
defaultExpanded: {}
|
|
1752
1778
|
})))), /*#__PURE__*/React__default["default"].createElement("div", {
|
|
1753
1779
|
style: {
|
|
@@ -1767,7 +1793,7 @@
|
|
|
1767
1793
|
top: 0,
|
|
1768
1794
|
zIndex: 1
|
|
1769
1795
|
}
|
|
1770
|
-
}, "
|
|
1796
|
+
}, "Active Matches"), router.state.matches.map((match, i) => {
|
|
1771
1797
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
1772
1798
|
key: match.routeId || i,
|
|
1773
1799
|
role: "button",
|
|
@@ -1798,7 +1824,7 @@
|
|
|
1798
1824
|
padding: '.5em'
|
|
1799
1825
|
}
|
|
1800
1826
|
}, "" + match.matchId));
|
|
1801
|
-
}), /*#__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", {
|
|
1802
1828
|
style: {
|
|
1803
1829
|
marginTop: '2rem',
|
|
1804
1830
|
padding: '.5em',
|
|
@@ -1807,7 +1833,7 @@
|
|
|
1807
1833
|
top: 0,
|
|
1808
1834
|
zIndex: 1
|
|
1809
1835
|
}
|
|
1810
|
-
}, "Pending Matches"), (_router$state$
|
|
1836
|
+
}, "Pending Matches"), (_router$state$pending2 = router.state.pending) == null ? void 0 : _router$state$pending2.matches.map((match, i) => {
|
|
1811
1837
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
1812
1838
|
key: match.routeId || i,
|
|
1813
1839
|
role: "button",
|
|
@@ -1837,32 +1863,33 @@
|
|
|
1837
1863
|
padding: '.5em'
|
|
1838
1864
|
}
|
|
1839
1865
|
}, "" + match.matchId));
|
|
1840
|
-
}), /*#__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", {
|
|
1841
1867
|
style: {
|
|
1842
1868
|
marginTop: '2rem',
|
|
1843
1869
|
padding: '.5em',
|
|
1844
1870
|
background: defaultTheme.backgroundAlt,
|
|
1845
1871
|
position: 'sticky',
|
|
1846
1872
|
top: 0,
|
|
1847
|
-
zIndex: 1
|
|
1873
|
+
zIndex: 1,
|
|
1874
|
+
display: 'flex',
|
|
1875
|
+
alignItems: 'center',
|
|
1876
|
+
justifyContent: 'space-between'
|
|
1848
1877
|
}
|
|
1849
|
-
}, "
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
}).map((
|
|
1855
|
-
var _match$updatedAt;
|
|
1856
|
-
|
|
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) => {
|
|
1857
1884
|
const {
|
|
1858
1885
|
match,
|
|
1859
|
-
|
|
1860
|
-
} =
|
|
1886
|
+
gc
|
|
1887
|
+
} = d;
|
|
1861
1888
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
1862
1889
|
key: match.matchId || i,
|
|
1863
1890
|
role: "button",
|
|
1864
1891
|
"aria-label": "Open match details for " + match.matchId,
|
|
1865
|
-
onClick: () =>
|
|
1892
|
+
onClick: () => setActiveMatchId(activeMatchId === match.matchId ? '' : match.matchId),
|
|
1866
1893
|
style: {
|
|
1867
1894
|
display: 'flex',
|
|
1868
1895
|
borderBottom: "solid 1px " + defaultTheme.grayAlt,
|
|
@@ -1898,10 +1925,10 @@
|
|
|
1898
1925
|
style: {
|
|
1899
1926
|
opacity: '.5'
|
|
1900
1927
|
}
|
|
1901
|
-
}, "Expires", ' ', formatDistanceStrict(new Date(), new Date(
|
|
1928
|
+
}, "Expires", ' ', formatDistanceStrict(new Date(), new Date(gc), {
|
|
1902
1929
|
addSuffix: true
|
|
1903
1930
|
}))));
|
|
1904
|
-
})), 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", {
|
|
1905
1932
|
style: {
|
|
1906
1933
|
padding: '.5em',
|
|
1907
1934
|
background: defaultTheme.backgroundAlt,
|
|
@@ -1948,7 +1975,7 @@
|
|
|
1948
1975
|
}, /*#__PURE__*/React__default["default"].createElement(Button, {
|
|
1949
1976
|
type: "button",
|
|
1950
1977
|
onClick: () => {
|
|
1951
|
-
|
|
1978
|
+
activeMatch.invalidate();
|
|
1952
1979
|
router.notify();
|
|
1953
1980
|
},
|
|
1954
1981
|
style: {
|
|
@@ -1957,7 +1984,7 @@
|
|
|
1957
1984
|
}
|
|
1958
1985
|
}, "Invalidate"), ' ', /*#__PURE__*/React__default["default"].createElement(Button, {
|
|
1959
1986
|
type: "button",
|
|
1960
|
-
onClick: () =>
|
|
1987
|
+
onClick: () => activeMatch.load(),
|
|
1961
1988
|
style: {
|
|
1962
1989
|
background: defaultTheme.gray
|
|
1963
1990
|
}
|
|
@@ -1975,7 +2002,7 @@
|
|
|
1975
2002
|
}
|
|
1976
2003
|
}, /*#__PURE__*/React__default["default"].createElement(Explorer, {
|
|
1977
2004
|
label: "Match",
|
|
1978
|
-
value:
|
|
2005
|
+
value: activeMatch,
|
|
1979
2006
|
defaultExpanded: {}
|
|
1980
2007
|
}))) : null, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
1981
2008
|
style: {
|