@tanstack/router-devtools 0.0.1-beta.119 → 0.0.1-beta.121

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.
@@ -75,17 +75,36 @@
75
75
 
76
76
  function useStore(store, selector = d => d) {
77
77
  // const isMountedRef = React.useRef(false)
78
- // const [state, setState] = React.useState<{ ref: TSelected }>({
79
- // ref: undefined!,
80
- // })
78
+ // const [state, setState] = React.useState<{ ref: TSelected }>(() => ({
79
+ // ref: selector(store.state),
80
+ // }))
81
81
 
82
- const slice = withSelector.useSyncExternalStoreWithSelector(store.subscribe, () => store.state, () => store.state, selector, shallow);
82
+ // if (!shallow(selector(store.state), state.ref)) {
83
+ // setState(() => ({ ref: selector(store.state) }))
84
+ // }
85
+
86
+ // useLayoutEffect(() => {
87
+ // console.log('effect')
88
+
89
+ // const cb = () => {
90
+ // const next = selector(store.state)
91
+ // console.log('onsub')
92
+ // if (!shallow(next, state.ref)) {
93
+ // console.log('set')
94
+ // setState(() => ({ ref: selector(store.state) }))
95
+ // }
96
+ // }
97
+
98
+ // return store.subscribe(cb)
99
+ // }, [])
100
+
101
+ const slice = withSelector.useSyncExternalStoreWithSelector(store.subscribe, () => store.state, () => store.state, selector, shallow$1);
83
102
 
84
103
  // if (!isMountedRef.current) {
85
104
  // state.ref = slice
86
105
  // }
87
106
 
88
- // if (slice !== state.ref) {
107
+ // if (!shallow(slice, state.ref)) {
89
108
  // setState({ ref: slice })
90
109
  // }
91
110
 
@@ -100,7 +119,7 @@
100
119
 
101
120
  return slice;
102
121
  }
103
- function shallow(objA, objB) {
122
+ function shallow$1(objA, objB) {
104
123
  if (Object.is(objA, objB)) {
105
124
  return true;
106
125
  }
@@ -129,10 +148,6 @@
129
148
  *
130
149
  * @license MIT
131
150
  */
132
-
133
- function last(arr) {
134
- return arr[arr.length - 1];
135
- }
136
151
  function trimPathLeft(path) {
137
152
  return path === '/' ? path : path.replace(/^\/{1,}/, '');
138
153
  }
@@ -142,7 +157,35 @@
142
157
  function trimPath(path) {
143
158
  return trimPathRight(trimPathLeft(path));
144
159
  }
160
+ const routerStateContext = /*#__PURE__*/React__namespace.createContext(null);
145
161
  const routerContext = /*#__PURE__*/React__namespace.createContext(null);
162
+ function useRouterState(select) {
163
+ const state = React__namespace.useContext(routerStateContext);
164
+ const next = select?.(state) ?? state;
165
+ const valueRef = React__namespace.useRef(next);
166
+ if (!shallow(valueRef.current, next)) {
167
+ valueRef.current = next;
168
+ }
169
+ return valueRef.current;
170
+ }
171
+ function shallow(objA, objB) {
172
+ if (Object.is(objA, objB)) {
173
+ return true;
174
+ }
175
+ if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {
176
+ return false;
177
+ }
178
+ const keysA = Object.keys(objA);
179
+ if (keysA.length !== Object.keys(objB).length) {
180
+ return false;
181
+ }
182
+ for (let i = 0; i < keysA.length; i++) {
183
+ if (!Object.prototype.hasOwnProperty.call(objB, keysA[i]) || !Object.is(objA[keysA[i]], objB[keysA[i]])) {
184
+ return false;
185
+ }
186
+ }
187
+ return true;
188
+ }
146
189
 
147
190
  const getItem = key => {
148
191
  try {
@@ -244,11 +287,11 @@
244
287
 
245
288
  const isServer$1 = typeof window === 'undefined';
246
289
  function getStatusColor(match, theme) {
247
- return match.state.status === 'pending' ? theme.active : match.state.status === 'error' ? theme.danger : match.state.status === 'success' ? theme.success : theme.gray;
290
+ return match.status === 'pending' ? theme.active : match.status === 'error' ? theme.danger : match.status === 'success' ? theme.success : theme.gray;
248
291
  }
249
292
  function getRouteStatusColor(matches, route, theme) {
250
- const found = matches.find(d => d.route === route);
251
- return found ? found.route.status === 'pending' ? theme.active : found.state.status === 'error' ? theme.danger : found.state.status === 'success' ? theme.success : theme.gray : theme.gray;
293
+ const found = matches.find(d => d.routeId === route.id);
294
+ return found ? found.status === 'pending' ? theme.active : found.status === 'error' ? theme.danger : found.status === 'success' ? theme.success : theme.gray : theme.gray;
252
295
  }
253
296
  function styled(type, newStyles, queries = {}) {
254
297
  return /*#__PURE__*/React__default["default"].forwardRef(({
@@ -496,6 +539,7 @@
496
539
  defaultExpanded,
497
540
  renderer = DefaultRenderer,
498
541
  pageSize = 100,
542
+ filterSubEntries,
499
543
  ...rest
500
544
  }) {
501
545
  const [expanded, setExpanded] = React__namespace.useState(Boolean(defaultExpanded));
@@ -530,12 +574,14 @@
530
574
  value: val
531
575
  }));
532
576
  }
577
+ subEntries = filterSubEntries ? filterSubEntries(subEntries) : subEntries;
533
578
  const subEntryPages = chunkArray(subEntries, pageSize);
534
579
  return renderer({
535
580
  handleEntry: entry => /*#__PURE__*/React__namespace.createElement(Explorer, _extends({
536
581
  key: entry.label,
537
582
  value: value,
538
- renderer: renderer
583
+ renderer: renderer,
584
+ filterSubEntries: filterSubEntries
539
585
  }, rest, entry)),
540
586
  type,
541
587
  subEntries,
@@ -798,7 +844,7 @@
798
844
  activeRouteId,
799
845
  setActiveRouteId
800
846
  }) {
801
- const isActive = matches.find(d => d.route === route);
847
+ const isActive = matches.find(d => d.routeId === route.id);
802
848
  return /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement("div", {
803
849
  role: "button",
804
850
  "aria-label": `Open match details for ${route.id}`,
@@ -856,14 +902,15 @@
856
902
  ...panelProps
857
903
  } = props;
858
904
  const routerContextValue = React__default["default"].useContext(routerContext);
859
- const router = userRouter ?? routerContextValue?.router;
905
+ const router = userRouter ?? routerContextValue;
906
+ const routerState = useRouterState();
860
907
  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.');
861
908
  useStore(router.__store);
862
909
  const [showMatches, setShowMatches] = useLocalStorage('tanstackRouterDevtoolsShowMatches', true);
863
910
  const [activeRouteId, setActiveRouteId] = useLocalStorage('tanstackRouterDevtoolsActiveRouteId', '');
864
- const allMatches = React__default["default"].useMemo(() => [...Object.values(router.state.matches)], [router.state.matches]);
865
- const activeMatch = allMatches?.find(d => d.route.id === activeRouteId);
866
- const hasSearch = Object.keys(last(router.state.matches)?.state.search || {}).length;
911
+ const allMatches = React__default["default"].useMemo(() => [...Object.values(routerState.matches)], [routerState.matches]);
912
+ const activeMatch = allMatches?.find(d => d.routeId === activeRouteId);
913
+ const hasSearch = Object.keys(routerState.location.search || {}).length;
867
914
  return /*#__PURE__*/React__default["default"].createElement(ThemeProvider, {
868
915
  theme: defaultTheme
869
916
  }, /*#__PURE__*/React__default["default"].createElement(Panel, _extends({
@@ -969,7 +1016,13 @@
969
1016
  }, /*#__PURE__*/React__default["default"].createElement(Explorer, {
970
1017
  label: "Router",
971
1018
  value: router,
972
- defaultExpanded: {}
1019
+ defaultExpanded: {
1020
+ state: {},
1021
+ context: {}
1022
+ },
1023
+ filterSubEntries: subEntries => {
1024
+ return subEntries.filter(d => typeof d.value !== 'function');
1025
+ }
973
1026
  })))), /*#__PURE__*/React__default["default"].createElement("div", {
974
1027
  style: {
975
1028
  flex: '1 1 500px',
@@ -998,7 +1051,12 @@
998
1051
  },
999
1052
  disabled: !showMatches,
1000
1053
  style: {
1001
- opacity: showMatches ? 0.5 : 1
1054
+ appearance: 'none',
1055
+ opacity: showMatches ? 0.5 : 1,
1056
+ border: 0,
1057
+ background: 'transparent',
1058
+ color: 'inherit',
1059
+ cursor: 'pointer'
1002
1060
  }
1003
1061
  }, "Routes"), "/", /*#__PURE__*/React__default["default"].createElement("button", {
1004
1062
  type: "button",
@@ -1007,7 +1065,12 @@
1007
1065
  },
1008
1066
  disabled: showMatches,
1009
1067
  style: {
1010
- opacity: !showMatches ? 0.5 : 1
1068
+ appearance: 'none',
1069
+ opacity: !showMatches ? 0.5 : 1,
1070
+ border: 0,
1071
+ background: 'transparent',
1072
+ color: 'inherit',
1073
+ cursor: 'pointer'
1011
1074
  }
1012
1075
  }, "Matches")), !showMatches ? /*#__PURE__*/React__default["default"].createElement(RouteComp, {
1013
1076
  route: router.routeTree,
@@ -1015,12 +1078,12 @@
1015
1078
  matches: allMatches,
1016
1079
  activeRouteId: activeRouteId,
1017
1080
  setActiveRouteId: setActiveRouteId
1018
- }) : /*#__PURE__*/React__default["default"].createElement("div", null, router.state.matches.map((match, i) => {
1081
+ }) : /*#__PURE__*/React__default["default"].createElement("div", null, routerState.matches.map((match, i) => {
1019
1082
  return /*#__PURE__*/React__default["default"].createElement("div", {
1020
- key: match.route.id || i,
1083
+ key: match.routeId || i,
1021
1084
  role: "button",
1022
- "aria-label": `Open match details for ${match.route.id}`,
1023
- onClick: () => setActiveRouteId(activeRouteId === match.route.id ? '' : match.route.id),
1085
+ "aria-label": `Open match details for ${match.routeId}`,
1086
+ onClick: () => setActiveRouteId(activeRouteId === match.routeId ? '' : match.routeId),
1024
1087
  style: {
1025
1088
  display: 'flex',
1026
1089
  borderBottom: `solid 1px ${defaultTheme.grayAlt}`,
@@ -1067,11 +1130,11 @@
1067
1130
  style: {
1068
1131
  opacity: '.5'
1069
1132
  }
1070
- }, "Status"), /*#__PURE__*/React__default["default"].createElement("td", null, activeMatch.state.status)), /*#__PURE__*/React__default["default"].createElement("tr", null, /*#__PURE__*/React__default["default"].createElement("td", {
1133
+ }, "Status"), /*#__PURE__*/React__default["default"].createElement("td", null, activeMatch.status)), /*#__PURE__*/React__default["default"].createElement("tr", null, /*#__PURE__*/React__default["default"].createElement("td", {
1071
1134
  style: {
1072
1135
  opacity: '.5'
1073
1136
  }
1074
- }, "Last Updated"), /*#__PURE__*/React__default["default"].createElement("td", null, activeMatch.state.updatedAt ? new Date(activeMatch.state.updatedAt).toLocaleTimeString() : 'N/A'))))), /*#__PURE__*/React__default["default"].createElement("div", {
1137
+ }, "Last Updated"), /*#__PURE__*/React__default["default"].createElement("td", null, activeMatch.updatedAt ? new Date(activeMatch.updatedAt).toLocaleTimeString() : 'N/A'))))), /*#__PURE__*/React__default["default"].createElement("div", {
1075
1138
  style: {
1076
1139
  background: defaultTheme.backgroundAlt,
1077
1140
  padding: '.5em',
@@ -1112,8 +1175,8 @@
1112
1175
  padding: '.5em'
1113
1176
  }
1114
1177
  }, /*#__PURE__*/React__default["default"].createElement(Explorer, {
1115
- value: last(router.state.matches)?.state.search || {},
1116
- defaultExpanded: Object.keys(last(router.state.matches)?.state.search || {}).reduce((obj, next) => {
1178
+ value: routerState.location.search || {},
1179
+ defaultExpanded: Object.keys(routerState.location.search || {}).reduce((obj, next) => {
1117
1180
  obj[next] = {};
1118
1181
  return obj;
1119
1182
  }, {})