@tanstack/router-devtools 0.0.1-beta.204 → 0.0.1-beta.205

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.
@@ -9,10 +9,10 @@
9
9
  * @license MIT
10
10
  */
11
11
  (function (global, factory) {
12
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('use-sync-external-store/shim/with-selector')) :
13
- typeof define === 'function' && define.amd ? define(['exports', 'react', 'use-sync-external-store/shim/with-selector'], factory) :
14
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TanStackRouterDevtools = {}, global.React, global.withSelector));
15
- })(this, (function (exports, React, withSelector) { 'use strict';
12
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
13
+ typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
14
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.TanStackRouterDevtools = {}, global.React));
15
+ })(this, (function (exports, React) { 'use strict';
16
16
 
17
17
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
18
18
 
@@ -52,40 +52,6 @@
52
52
  return _extends.apply(this, arguments);
53
53
  }
54
54
 
55
- /**
56
- * @tanstack/react-store/src/index.tsx
57
- *
58
- * Copyright (c) TanStack
59
- *
60
- * This source code is licensed under the MIT license found in the
61
- * LICENSE.md file in the root directory of this source tree.
62
- *
63
- * @license MIT
64
- */
65
-
66
- function useStore(store, selector = d => d) {
67
- const slice = withSelector.useSyncExternalStoreWithSelector(store.subscribe, () => store.state, () => store.state, selector, shallow);
68
- return slice;
69
- }
70
- function shallow(objA, objB) {
71
- if (Object.is(objA, objB)) {
72
- return true;
73
- }
74
- if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
75
- return false;
76
- }
77
- const keysA = Object.keys(objA);
78
- if (keysA.length !== Object.keys(objB).length) {
79
- return false;
80
- }
81
- for (let i = 0; i < keysA.length; i++) {
82
- if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !Object.is(objA[keysA[i]], objB[keysA[i]])) {
83
- return false;
84
- }
85
- }
86
- return true;
87
- }
88
-
89
55
  var prefix = 'Invariant failed';
90
56
  function invariant(condition, message) {
91
57
  if (condition) {
@@ -96,8 +62,26 @@
96
62
  throw new Error(value);
97
63
  }
98
64
 
65
+ function warning(condition, message) {
66
+ {
67
+ if (condition) {
68
+ return;
69
+ }
70
+
71
+ var text = "Warning: " + message;
72
+
73
+ if (typeof console !== 'undefined') {
74
+ console.warn(text);
75
+ }
76
+
77
+ try {
78
+ throw Error(text);
79
+ } catch (x) {}
80
+ }
81
+ }
82
+
99
83
  /**
100
- * @tanstack/router-core/src/index.ts
84
+ * @tanstack/react-router/src/index.tsx
101
85
  *
102
86
  * Copyright (c) TanStack
103
87
  *
@@ -115,28 +99,12 @@
115
99
  function trimPath(path) {
116
100
  return trimPathRight(trimPathLeft(path));
117
101
  }
118
- function isMatchInvalid(match, opts) {
119
- const now = Date.now();
120
- if (match.invalid) {
121
- return true;
122
- }
123
- if (opts?.preload) {
124
- return match.preloadMaxAge < 0 ? false : match.updatedAt + match.preloadMaxAge < now;
125
- }
126
- return match.maxAge < 0 ? false : match.updatedAt + match.maxAge < now;
127
- }
128
-
129
- /**
130
- * @tanstack/react-router/src/index.tsx
131
- *
132
- * Copyright (c) TanStack
133
- *
134
- * This source code is licensed under the MIT license found in the
135
- * LICENSE.md file in the root directory of this source tree.
136
- *
137
- * @license MIT
138
- */
139
102
  const routerContext = /*#__PURE__*/React__namespace.createContext(null);
103
+ function useRouter() {
104
+ const value = React__namespace.useContext(routerContext);
105
+ warning(value, 'useRouter must be used inside a <RouterProvider> component!');
106
+ return value;
107
+ }
140
108
 
141
109
  const getItem = key => {
142
110
  try {
@@ -238,7 +206,7 @@
238
206
 
239
207
  const isServer$1 = typeof window === 'undefined';
240
208
  function getStatusColor(match, theme) {
241
- return match.status === 'pending' || match.isFetching ? theme.active : isMatchInvalid(match) ? theme.warning : match.status === 'error' ? theme.danger : match.status === 'success' ? theme.success : theme.gray;
209
+ return match.status === 'pending' || match.isFetching ? theme.active : match.status === 'error' ? theme.danger : match.status === 'success' ? theme.success : theme.gray;
242
210
  }
243
211
  function getRouteStatusColor(matches, route, theme) {
244
212
  const found = matches.find(d => d.routeId === route.id);
@@ -792,13 +760,13 @@
792
760
  function RouteComp({
793
761
  route,
794
762
  isRoot,
795
- router,
796
763
  activeRouteId,
797
764
  activeMatchId,
798
765
  setActiveRouteId,
799
766
  setActiveMatchId
800
767
  }) {
801
- const matches = Object.values(router.state.matchesById);
768
+ const router = useRouter();
769
+ const matches = [...router.state.pendingMatches, ...router.state.matches];
802
770
  const match = router.state.matches.find(d => d.routeId === route.id);
803
771
  return /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement("div", {
804
772
  role: "button",
@@ -854,7 +822,6 @@
854
822
  }).map(r => /*#__PURE__*/React__default["default"].createElement(RouteComp, {
855
823
  key: r.id,
856
824
  route: r,
857
- router: router,
858
825
  activeRouteId: activeRouteId,
859
826
  activeMatchId: activeMatchId,
860
827
  setActiveRouteId: setActiveRouteId,
@@ -869,18 +836,24 @@
869
836
  router: userRouter,
870
837
  ...panelProps
871
838
  } = props;
872
- const routerContextValue = React__default["default"].useContext(routerContext);
873
- const router = userRouter ?? routerContextValue;
839
+ const router = useRouter();
840
+ const matches = [...router.state.pendingMatches, ...router.state.matches];
874
841
  invariant(router, 'No router was found for the TanStack Router Devtools. Please place the devtools in the <RouterProvider> component tree or pass the router instance to the devtools manually.');
875
- useStore(router.__store);
842
+
843
+ // useStore(router.__store)
844
+
876
845
  const [showMatches, setShowMatches] = useLocalStorage('tanstackRouterDevtoolsShowMatches', true);
877
846
  const [activeRouteId, setActiveRouteId] = useLocalStorage('tanstackRouterDevtoolsActiveRouteId', '');
878
847
  const [activeMatchId, setActiveMatchId] = useLocalStorage('tanstackRouterDevtoolsActiveMatchId', '');
879
- const activeMatch = React__default["default"].useMemo(() => router.state.matchesById[activeRouteId] || router.state.matchesById[activeMatchId], [activeRouteId, activeMatchId]);
848
+ const activeMatch = React__default["default"].useMemo(() => matches.find(d => d.id === activeRouteId) || matches.find(d => d.id === activeMatchId), [activeRouteId, activeMatchId]);
880
849
  const hasSearch = Object.keys(router.state.location.search || {}).length;
881
- const preloadMatches = Object.values(router.state.matchesById).filter(match => {
882
- return !router.state.matchIds.includes(match.id) && !router.state.pendingMatchIds.includes(match.id);
883
- });
850
+
851
+ // const preloadMatches = matches.filter((match) => {
852
+ // return (
853
+ // !state.matchIds.includes(match.id) &&
854
+ // !state.pendingMatchIds.includes(match.id)
855
+ // )
856
+ // })
884
857
 
885
858
  // React.useEffect(() => {
886
859
  // const interval = setInterval(() => {
@@ -1094,7 +1067,6 @@
1094
1067
  }
1095
1068
  }, "Matches")), !showMatches ? /*#__PURE__*/React__default["default"].createElement(RouteComp, {
1096
1069
  route: router.routeTree,
1097
- router: router,
1098
1070
  isRoot: true,
1099
1071
  activeRouteId: activeRouteId,
1100
1072
  activeMatchId: activeMatchId,
@@ -1132,57 +1104,7 @@
1132
1104
  fontSize: '0.7rem'
1133
1105
  }
1134
1106
  }, `${match.id}`));
1135
- }))), preloadMatches?.length ? /*#__PURE__*/React__default["default"].createElement("div", {
1136
- style: {
1137
- flex: '1 1 auto',
1138
- overflowY: 'auto',
1139
- maxHeight: '50%'
1140
- }
1141
- }, /*#__PURE__*/React__default["default"].createElement("div", {
1142
- style: {
1143
- padding: '.5em',
1144
- background: defaultTheme.backgroundAlt,
1145
- position: 'sticky',
1146
- top: 0,
1147
- zIndex: 1,
1148
- display: 'flex',
1149
- alignItems: 'center',
1150
- gap: '.5rem',
1151
- fontWeight: 'bold'
1152
- }
1153
- }, "Preloaded Matches"), preloadMatches.map(match => {
1154
- return /*#__PURE__*/React__default["default"].createElement("div", {
1155
- key: match.id,
1156
- role: "button",
1157
- "aria-label": `Open match details for ${match.routeId}`,
1158
- onClick: () => setActiveMatchId(activeMatchId === match.id ? '' : match.id),
1159
- style: {
1160
- display: 'flex',
1161
- borderBottom: `solid 1px ${defaultTheme.grayAlt}`,
1162
- cursor: 'pointer',
1163
- alignItems: 'center',
1164
- background: match === activeMatch ? 'rgba(255,255,255,.1)' : undefined
1165
- }
1166
- }, /*#__PURE__*/React__default["default"].createElement("div", {
1167
- style: {
1168
- flex: '0 0 auto',
1169
- width: '1.3rem',
1170
- height: '1.3rem',
1171
- marginLeft: '.25rem',
1172
- background: getStatusColor(match, defaultTheme),
1173
- alignItems: 'center',
1174
- justifyContent: 'center',
1175
- fontWeight: 'bold',
1176
- borderRadius: '.25rem',
1177
- transition: 'all .2s ease-out'
1178
- }
1179
- }), /*#__PURE__*/React__default["default"].createElement(Code, {
1180
- style: {
1181
- padding: '.5em',
1182
- fontSize: '0.7rem'
1183
- }
1184
- }, `${match.id}`));
1185
- })) : null), activeMatch ? /*#__PURE__*/React__default["default"].createElement(ActivePanel, null, /*#__PURE__*/React__default["default"].createElement("div", {
1107
+ })))), activeMatch ? /*#__PURE__*/React__default["default"].createElement(ActivePanel, null, /*#__PURE__*/React__default["default"].createElement("div", {
1186
1108
  style: {
1187
1109
  padding: '.5em',
1188
1110
  background: defaultTheme.backgroundAlt,