@tanstack/query-devtools 5.106.0 → 5.107.0

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.
Files changed (34) hide show
  1. package/build/Devtools-B2jiIqEJ.js +1292 -0
  2. package/build/Devtools-B2jiIqEJ.js.map +1 -0
  3. package/build/Devtools-C6D0zIvx.cjs +1291 -0
  4. package/build/{Devtools-DN7p-sdp.js → Devtools-CXcMqCPe.js} +3953 -3744
  5. package/build/{Devtools-DwGQtvng.cjs → Devtools-Dy8Npldt.cjs} +3956 -3741
  6. package/build/{DevtoolsComponent-CJQXyYNJ.js → DevtoolsComponent-C7hVCcUy.js} +9 -4
  7. package/build/{DevtoolsComponent-D8sLZqb7.cjs → DevtoolsComponent-CfBgdmsl.cjs} +9 -4
  8. package/build/{DevtoolsComponent-D4pZpbHT.cjs → DevtoolsComponent-D5toeyeh.cjs} +1 -1
  9. package/build/DevtoolsComponent-DGRxtIwZ.js +3 -0
  10. package/build/DevtoolsComponent-DGRxtIwZ.js.map +1 -0
  11. package/build/DevtoolsPanelComponent-CPGCRAPs.js +3 -0
  12. package/build/DevtoolsPanelComponent-CPGCRAPs.js.map +1 -0
  13. package/build/DevtoolsPanelComponent-D_S99j7E.cjs +2 -0
  14. package/build/{DevtoolsPanelComponent-Dpyndu31.cjs → DevtoolsPanelComponent-Dc49CXag.cjs} +16 -11
  15. package/build/{DevtoolsPanelComponent-CXpcIZT1.js → DevtoolsPanelComponent-XShN-s8X.js} +16 -11
  16. package/build/dev.cjs +2 -2
  17. package/build/dev.js +2 -2
  18. package/build/index.cjs +1 -1
  19. package/build/index.js +1 -1
  20. package/package.json +2 -2
  21. package/src/Devtools.tsx +242 -14
  22. package/src/DevtoolsComponent.tsx +7 -4
  23. package/src/DevtoolsPanelComponent.tsx +11 -8
  24. package/src/Explorer.tsx +12 -5
  25. package/src/constants.ts +4 -0
  26. package/src/explorerSearch.ts +40 -0
  27. package/build/Devtools-C6d4y1zP.js +0 -1270
  28. package/build/Devtools-C6d4y1zP.js.map +0 -1
  29. package/build/Devtools-he_mAvFk.cjs +0 -1269
  30. package/build/DevtoolsComponent-DQLY23gz.js +0 -3
  31. package/build/DevtoolsComponent-DQLY23gz.js.map +0 -1
  32. package/build/DevtoolsPanelComponent-BLDfq2ww.cjs +0 -2
  33. package/build/DevtoolsPanelComponent-CmWcNhgP.js +0 -3
  34. package/build/DevtoolsPanelComponent-CmWcNhgP.js.map +0 -1
package/src/Devtools.tsx CHANGED
@@ -53,21 +53,25 @@ import {
53
53
  XCircle,
54
54
  } from './icons'
55
55
  import Explorer, { SearchableExplorer } from './Explorer'
56
+ import { createSearchText } from './explorerSearch'
56
57
  import { VirtualList } from './VirtualList'
57
58
  import { usePiPWindow, useQueryDevtoolsContext, useTheme } from './contexts'
58
59
  import {
59
60
  BUTTON_POSITION,
61
+ DEFAULT_FILTER_SCOPE,
60
62
  DEFAULT_HEIGHT,
61
63
  DEFAULT_MUTATION_SORT_FN_NAME,
62
64
  DEFAULT_SORT_FN_NAME,
63
65
  DEFAULT_SORT_ORDER,
64
66
  DEFAULT_WIDTH,
67
+ FILTER_SCOPES,
65
68
  INITIAL_IS_OPEN,
66
69
  POSITION,
67
70
  firstBreakpoint,
68
71
  secondBreakpoint,
69
72
  thirdBreakpoint,
70
73
  } from './constants'
74
+ import type { FilterScope } from './constants'
71
75
  import type {
72
76
  DevtoolsErrorType,
73
77
  DevtoolsPosition,
@@ -76,6 +80,7 @@ import type {
76
80
  import type {
77
81
  Mutation,
78
82
  MutationCache,
83
+ MutationCacheNotifyEvent,
79
84
  Query,
80
85
  QueryCache,
81
86
  QueryCacheNotifyEvent,
@@ -83,6 +88,80 @@ import type {
83
88
  import type { StorageObject, StorageSetter } from '@solid-primitives/storage'
84
89
  import type { Accessor, Component, JSX } from 'solid-js'
85
90
 
91
+ const filterScopeLabels: Record<FilterScope, string> = {
92
+ key: 'Key',
93
+ data: 'Data',
94
+ all: 'All',
95
+ }
96
+
97
+ const filterScopeAriaLabels: Record<
98
+ 'queries' | 'mutations',
99
+ Record<FilterScope, string>
100
+ > = {
101
+ queries: {
102
+ key: 'Filter queries by query key',
103
+ data: 'Filter queries by query data',
104
+ all: 'Filter queries by query key or data',
105
+ },
106
+ mutations: {
107
+ key: 'Filter mutations by mutation key',
108
+ data: 'Filter mutations by variables or data',
109
+ all: 'Filter mutations by mutation key, variables or data',
110
+ },
111
+ }
112
+
113
+ // Query data is immutable. Cached mutation text is invalidated when mutation state changes.
114
+ const dataSearchTexts = new WeakMap<object, string>()
115
+
116
+ /**
117
+ * Gets the cached search text of query or mutation data, building it if there is time left.
118
+ * @param data - The query data, or mutation variables or data.
119
+ * @param deadline - When to stop building search texts, compared to `performance.now()`.
120
+ * @returns The search text, or undefined if it isn't built and the deadline has passed.
121
+ */
122
+ const getDataSearchText = (data: unknown, deadline = Infinity) => {
123
+ if (typeof data !== 'object' || data === null) return createSearchText(data)
124
+ let text = dataSearchTexts.get(data)
125
+ if (text === undefined && performance.now() < deadline) {
126
+ text = createSearchText(data)
127
+ dataSearchTexts.set(data, text)
128
+ }
129
+ return text
130
+ }
131
+
132
+ /**
133
+ * Checks whether data contains the term. Missing data never matches.
134
+ * @param data - The query data, or mutation variables or data.
135
+ * @param term - The lowercased search term.
136
+ * @returns Whether the data matches.
137
+ */
138
+ const matchesData = (data: unknown, term: string) =>
139
+ data !== undefined && getDataSearchText(data)!.includes(term)
140
+
141
+ /**
142
+ * Builds data search texts for a few milliseconds per task, so filtering by data doesn't block
143
+ * the page.
144
+ * @returns `version`, which changes when building continued in a later task, and `prepare`,
145
+ * which returns whether the search texts of all the data are built.
146
+ */
147
+ const createDataSearchTexts = () => {
148
+ const [version, setVersion] = createSignal(0)
149
+ let timeout: ReturnType<typeof setTimeout> | undefined
150
+ onCleanup(() => clearTimeout(timeout))
151
+
152
+ const prepare = (data: Array<unknown>) => {
153
+ clearTimeout(timeout)
154
+ const deadline = performance.now() + 8
155
+ if (data.every((item) => getDataSearchText(item, deadline) !== undefined)) {
156
+ return true
157
+ }
158
+ timeout = setTimeout(() => setVersion((current) => current + 1))
159
+ return false
160
+ }
161
+
162
+ return { version, prepare }
163
+ }
164
+
86
165
  interface DevtoolsPanelProps {
87
166
  localStore: StorageObject<string>
88
167
  setLocalStore: StorageSetter<string, unknown>
@@ -236,6 +315,7 @@ export const Devtools: Component<DevtoolsPanelProps> = (props) => {
236
315
  `,
237
316
  'tsqd-transitions-container',
238
317
  )}
318
+ dir="ltr"
239
319
  ref={transitionsContainerRef}
240
320
  >
241
321
  <TransitionGroup name="tsqd-panel-transition">
@@ -324,6 +404,7 @@ const PiPPanel: Component<{
324
404
 
325
405
  return (
326
406
  <div
407
+ dir="ltr"
327
408
  style={{
328
409
  '--tsqd-font-size': '16px',
329
410
  'max-height': '100vh',
@@ -393,6 +474,7 @@ export const ParentPanel: Component<{
393
474
 
394
475
  return (
395
476
  <div
477
+ dir="ltr"
396
478
  style={{
397
479
  '--tsqd-font-size': '16px',
398
480
  }}
@@ -752,22 +834,64 @@ export const ContentView: Component<ContentViewProps> = (props) => {
752
834
  : useQueryDevtoolsContext().hideDisabledQueries || false
753
835
  })
754
836
 
837
+ const filterScope = createMemo<FilterScope>(() => {
838
+ const scope = props.localStore.filterScope as FilterScope
839
+ return FILTER_SCOPES.includes(scope) ? scope : DEFAULT_FILTER_SCOPE
840
+ })
841
+
842
+ const cycleFilterScope = () => {
843
+ const index = FILTER_SCOPES.indexOf(filterScope())
844
+ props.setLocalStore(
845
+ 'filterScope',
846
+ FILTER_SCOPES[(index + 1) % FILTER_SCOPES.length]!,
847
+ )
848
+ }
849
+
850
+ // Data changes don't change the query count, so data searches need their own trigger
851
+ const queryDataVersion = createSubscribeToQueryCacheBatcher(
852
+ () => ({}),
853
+ false,
854
+ (event) =>
855
+ filterScope() !== 'key' &&
856
+ !!props.localStore.filter &&
857
+ event.type === 'updated' &&
858
+ (event.action.type === 'success' || event.action.type === 'setState'),
859
+ )
860
+
861
+ const queryDataSearchTexts = createDataSearchTexts()
862
+
755
863
  const queries = createMemo(
756
864
  on(
757
865
  () => [
758
866
  queryCount(),
759
867
  props.localStore.filter,
868
+ filterScope(),
869
+ queryDataVersion(),
870
+ queryDataSearchTexts.version(),
760
871
  sort(),
761
872
  sortOrder(),
762
873
  hideDisabledQueries(),
763
874
  ],
764
- () => {
875
+ (_input, _prevInput, prev: Array<Query> | undefined) => {
765
876
  const curr = query_cache().getAll()
877
+ const filter = props.localStore.filter || ''
878
+ const scope = filterScope()
879
+ const dataTerm = filter.toLowerCase()
880
+
881
+ if (
882
+ filter &&
883
+ scope !== 'key' &&
884
+ !queryDataSearchTexts.prepare(curr.map((item) => item.state.data))
885
+ ) {
886
+ // Keeps the previous results until all search texts are built
887
+ return prev ?? []
888
+ }
766
889
 
767
- let filtered = props.localStore.filter
890
+ let filtered = filter
768
891
  ? curr.filter(
769
892
  (item) =>
770
- rankItem(item.queryHash, props.localStore.filter || '').passed,
893
+ (scope !== 'data' && rankItem(item.queryHash, filter).passed) ||
894
+ (scope !== 'key' && matchesData(item.state.data, dataTerm)),
771
895
  )
772
896
  : [...curr]
773
897
 
@@ -791,26 +915,68 @@ export const ContentView: Component<ContentViewProps> = (props) => {
791
915
  false,
792
916
  )
793
917
 
918
+ // Variables and data changes don't change the mutation count, so data searches need their own trigger
919
+ const mutationDataVersion = createSubscribeToMutationCacheBatcher(
920
+ () => ({}),
921
+ false,
922
+ (event) => {
923
+ if (event.type !== 'updated') return false
924
+ // Mutation functions can change variables in place, including when no data filter is active.
925
+ for (const value of [
926
+ event.mutation.state.variables,
927
+ event.mutation.state.data,
928
+ ]) {
929
+ if (typeof value === 'object' && value !== null) {
930
+ dataSearchTexts.delete(value)
931
+ }
932
+ }
933
+ return filterScope() !== 'key' && !!props.localStore.mutationFilter
934
+ },
935
+ )
936
+
937
+ const mutationDataSearchTexts = createDataSearchTexts()
938
+
794
939
  const mutations = createMemo(
795
940
  on(
796
941
  () => [
797
942
  mutationCount(),
798
943
  props.localStore.mutationFilter,
944
+ filterScope(),
945
+ mutationDataVersion(),
946
+ mutationDataSearchTexts.version(),
799
947
  mutationSort(),
800
948
  mutationSortOrder(),
801
949
  ],
802
- () => {
950
+ (_input, _prevInput, prev: Array<Mutation> | undefined) => {
803
951
  const curr = mutation_cache().getAll()
952
+ const filter = props.localStore.mutationFilter || ''
953
+ const scope = filterScope()
954
+ const dataTerm = filter.toLowerCase()
955
+
956
+ if (
957
+ filter &&
958
+ scope !== 'key' &&
959
+ !mutationDataSearchTexts.prepare(
960
+ curr.flatMap((item) => [item.state.variables, item.state.data]),
961
+ )
962
+ ) {
963
+ // Keeps the previous results until all search texts are built
964
+ return prev ?? []
965
+ }
804
966
 
805
- const filtered = props.localStore.mutationFilter
967
+ const filtered = filter
806
968
  ? curr.filter((item) => {
807
969
  const value = `${
808
970
  item.options.mutationKey
809
971
  ? JSON.stringify(item.options.mutationKey) + ' - '
810
972
  : ''
811
973
  }${new Date(item.state.submittedAt).toLocaleString()}`
812
- return rankItem(value, props.localStore.mutationFilter || '')
813
- .passed
974
+ return (
975
+ (scope !== 'data' && rankItem(value, filter).passed) ||
976
+ (scope !== 'key' &&
977
+ (matchesData(item.state.variables, dataTerm) ||
978
+ matchesData(item.state.data, dataTerm)))
979
+ )
814
980
  })
815
981
  : [...curr]
816
982
 
@@ -936,7 +1102,9 @@ export const ContentView: Component<ContentViewProps> = (props) => {
936
1102
  >
937
1103
  <Search />
938
1104
  <input
939
- aria-label="Filter queries by query key"
1105
+ aria-label={
1106
+ filterScopeAriaLabels[selectedView()][filterScope()]
1107
+ }
940
1108
  type="text"
941
1109
  placeholder="Filter"
942
1110
  onInput={(e) => {
@@ -954,6 +1122,19 @@ export const ContentView: Component<ContentViewProps> = (props) => {
954
1122
  : props.localStore.mutationFilter || ''
955
1123
  }
956
1124
  />
1125
+ <button
1126
+ type="button"
1127
+ onClick={cycleFilterScope}
1128
+ class={cx(
1129
+ styles().filterScopeBtn,
1130
+ 'tsqd-query-filter-scope-btn',
1131
+ )}
1132
+ aria-label={`Filter scope: ${filterScopeLabels[filterScope()]}`}
1133
+ title={`${filterScopeAriaLabels[selectedView()][filterScope()]}. Click to switch between key, data, and both.`}
1134
+ data-scope={filterScope()}
1135
+ >
1136
+ {filterScopeLabels[filterScope()]}
1137
+ </button>
957
1138
  </div>
958
1139
  <div
959
1140
  class={cx(
@@ -1123,6 +1304,7 @@ export const ContentView: Component<ContentViewProps> = (props) => {
1123
1304
  }
1124
1305
  >
1125
1306
  <DropdownMenu.Content
1307
+ dir="ltr"
1126
1308
  class={cx(styles().settingsMenu, 'tsqd-settings-menu')}
1127
1309
  >
1128
1310
  <div
@@ -1154,6 +1336,7 @@ export const ContentView: Component<ContentViewProps> = (props) => {
1154
1336
  }
1155
1337
  >
1156
1338
  <DropdownMenu.SubContent
1339
+ dir="ltr"
1157
1340
  class={cx(
1158
1341
  styles().settingsMenu,
1159
1342
  'tsqd-settings-submenu',
@@ -1235,6 +1418,7 @@ export const ContentView: Component<ContentViewProps> = (props) => {
1235
1418
  }
1236
1419
  >
1237
1420
  <DropdownMenu.SubContent
1421
+ dir="ltr"
1238
1422
  class={cx(
1239
1423
  styles().settingsMenu,
1240
1424
  'tsqd-settings-submenu',
@@ -1304,6 +1488,7 @@ export const ContentView: Component<ContentViewProps> = (props) => {
1304
1488
  }
1305
1489
  >
1306
1490
  <DropdownMenu.SubContent
1491
+ dir="ltr"
1307
1492
  class={cx(
1308
1493
  styles().settingsMenu,
1309
1494
  'tsqd-settings-submenu',
@@ -1387,11 +1572,21 @@ export const ContentView: Component<ContentViewProps> = (props) => {
1387
1572
  </Show>
1388
1573
  </div>
1389
1574
  <Show when={selectedView() === 'queries' && selectedQueryHash()}>
1390
- <QueryDetails />
1575
+ <QueryDetails
1576
+ initialSearch={
1577
+ filterScope() !== 'key' ? props.localStore.filter : undefined
1578
+ }
1579
+ />
1391
1580
  </Show>
1392
1581
 
1393
1582
  <Show when={selectedView() === 'mutations' && selectedMutationId()}>
1394
- <MutationDetails />
1583
+ <MutationDetails
1584
+ initialSearch={
1585
+ filterScope() !== 'key'
1586
+ ? props.localStore.mutationFilter
1587
+ : undefined
1588
+ }
1589
+ />
1395
1590
  </Show>
1396
1591
  </>
1397
1592
  )
@@ -1781,7 +1976,7 @@ const QueryStatus: Component<QueryStatusProps> = (props) => {
1781
1976
  )
1782
1977
  }
1783
1978
 
1784
- const QueryDetails = () => {
1979
+ const QueryDetails = (props: { initialSearch?: string }) => {
1785
1980
  const { selectedQueryHash, setSelectedQueryHash } = useDevtoolsState()
1786
1981
 
1787
1982
  const theme = useTheme()
@@ -2220,6 +2415,7 @@ const QueryDetails = () => {
2220
2415
  >
2221
2416
  <SearchableExplorer
2222
2417
  searchKey={activeQuery()}
2418
+ initialSearch={props.initialSearch}
2223
2419
  label="Data"
2224
2420
  defaultExpanded={['Data']}
2225
2421
  value={activeQueryStateData()}
@@ -2314,7 +2510,7 @@ const QueryDetails = () => {
2314
2510
  )
2315
2511
  }
2316
2512
 
2317
- const MutationDetails = () => {
2513
+ const MutationDetails = (props: { initialSearch?: string }) => {
2318
2514
  const { selectedMutationId } = useDevtoolsState()
2319
2515
 
2320
2516
  const theme = useTheme()
@@ -2361,6 +2557,11 @@ const MutationDetails = () => {
2361
2557
  false,
2362
2558
  )
2363
2559
 
2560
+ const matchingSearch = (value: unknown) =>
2561
+ props.initialSearch && matchesData(value, props.initialSearch.toLowerCase())
2562
+ ? props.initialSearch
2563
+ : undefined
2564
+
2364
2565
  const getQueryStatusColors = () => {
2365
2566
  if (color() === 'gray') {
2366
2567
  return css`
@@ -2436,7 +2637,9 @@ const MutationDetails = () => {
2436
2637
  }}
2437
2638
  class="tsqd-query-details-explorer-container tsqd-query-details-query-explorer"
2438
2639
  >
2439
- <Explorer
2640
+ <SearchableExplorer
2641
+ searchKey={activeMutation()}
2642
+ initialSearch={matchingSearch(activeMutation()!.state.variables)}
2440
2643
  label="Variables"
2441
2644
  defaultExpanded={['Variables']}
2442
2645
  value={activeMutation()!.state.variables}
@@ -2476,6 +2679,7 @@ const MutationDetails = () => {
2476
2679
  >
2477
2680
  <SearchableExplorer
2478
2681
  searchKey={activeMutation()}
2682
+ initialSearch={matchingSearch(activeMutation()!.state.data)}
2479
2683
  label="Data"
2480
2684
  defaultExpanded={['Data']}
2481
2685
  value={activeMutation()!.state.data}
@@ -2579,6 +2783,7 @@ const setupMutationCacheSubscription = () => {
2579
2783
  const createSubscribeToMutationCacheBatcher = <T,>(
2580
2784
  callback: (queryCache: Accessor<MutationCache>) => Exclude<T, Function>,
2581
2785
  equalityCheck: boolean = true,
2786
+ shouldUpdate: (event: MutationCacheNotifyEvent) => boolean = () => true,
2582
2787
  ) => {
2583
2788
  const { mutationCacheSubscriptions } = useDevtoolsSubscriptions()
2584
2789
  const mutationCache = createMemo(() => {
@@ -2595,7 +2800,7 @@ const createSubscribeToMutationCacheBatcher = <T,>(
2595
2800
  setValue(callback(mutationCache))
2596
2801
  })
2597
2802
 
2598
- mutationCacheSubscriptions.register(callback, setValue)
2803
+ mutationCacheSubscriptions.register(callback, setValue, shouldUpdate)
2599
2804
 
2600
2805
  return value
2601
2806
  }
@@ -3149,6 +3354,8 @@ const stylesFactory = (
3149
3354
  & input {
3150
3355
  font-size: ${font.size.xs};
3151
3356
  width: 100%;
3357
+ min-width: 0;
3358
+ flex: 1;
3152
3359
  background-color: ${t(colors.gray[100], colors.darkGray[400])};
3153
3360
  border: none;
3154
3361
  padding: 0;
@@ -3168,6 +3375,27 @@ const stylesFactory = (
3168
3375
  outline: 2px solid ${colors.blue[800]};
3169
3376
  }
3170
3377
  `,
3378
+ filterScopeBtn: css`
3379
+ flex-shrink: 0;
3380
+ cursor: pointer;
3381
+ padding: 0 ${size[1]};
3382
+ border-radius: ${border.radius.xs};
3383
+ border: 1px solid ${t(colors.gray[300], colors.darkGray[200])};
3384
+ background-color: ${t(colors.gray[200], colors.darkGray[500])};
3385
+ color: ${t(colors.gray[700], colors.gray[300])};
3386
+ font-size: ${font.size.xs};
3387
+ line-height: ${font.lineHeight.xs};
3388
+ &[data-scope='data'],
3389
+ &[data-scope='all'] {
3390
+ border-color: ${t(colors.blue[300], colors.blue[700])};
3391
+ background-color: ${t(colors.blue[100], colors.blue[900])};
3392
+ color: ${t(colors.blue[700], colors.blue[300])};
3393
+ }
3394
+ &:focus-visible {
3395
+ outline-offset: 2px;
3396
+ outline: 2px solid ${colors.blue[800]};
3397
+ }
3398
+ `,
3171
3399
  filterSelect: css`
3172
3400
  padding: ${tokens.size[0.5]} ${tokens.size[2]};
3173
3401
  border-radius: ${tokens.border.radius.sm};
@@ -1,4 +1,5 @@
1
1
  import { createLocalStorage } from '@solid-primitives/storage'
2
+ import { I18nProvider } from '@kobalte/core'
2
3
  import { createMemo } from 'solid-js'
3
4
  import { DevtoolsOfflineProvider } from './providers/DevtoolsOfflineProvider'
4
5
  import { DevtoolsSubscriptionsProvider } from './providers/DevtoolsSubscriptionsProvider'
@@ -32,10 +33,12 @@ const DevtoolsComponent: DevtoolsComponentType = (props) => {
32
33
  <DevtoolsSubscriptionsProvider>
33
34
  <PiPProvider localStore={localStore} setLocalStore={setLocalStore}>
34
35
  <ThemeContext.Provider value={theme}>
35
- <Devtools
36
- localStore={localStore}
37
- setLocalStore={setLocalStore}
38
- />
36
+ <I18nProvider locale="en-US">
37
+ <Devtools
38
+ localStore={localStore}
39
+ setLocalStore={setLocalStore}
40
+ />
41
+ </I18nProvider>
39
42
  </ThemeContext.Provider>
40
43
  </PiPProvider>
41
44
  </DevtoolsSubscriptionsProvider>
@@ -1,4 +1,5 @@
1
1
  import { createLocalStorage } from '@solid-primitives/storage'
2
+ import { I18nProvider } from '@kobalte/core'
2
3
  import { createMemo } from 'solid-js'
3
4
  import { DevtoolsOfflineProvider } from './providers/DevtoolsOfflineProvider'
4
5
  import { DevtoolsSubscriptionsProvider } from './providers/DevtoolsSubscriptionsProvider'
@@ -36,14 +37,16 @@ const DevtoolsPanelComponent: DevtoolsComponentType = (props) => {
36
37
  setLocalStore={setLocalStore}
37
38
  >
38
39
  <ThemeContext.Provider value={theme}>
39
- <ParentPanel>
40
- <ContentView
41
- localStore={localStore}
42
- setLocalStore={setLocalStore}
43
- onClose={props.onClose}
44
- showPanelViewOnly
45
- />
46
- </ParentPanel>
40
+ <I18nProvider locale="en-US">
41
+ <ParentPanel>
42
+ <ContentView
43
+ localStore={localStore}
44
+ setLocalStore={setLocalStore}
45
+ onClose={props.onClose}
46
+ showPanelViewOnly
47
+ />
48
+ </ParentPanel>
49
+ </I18nProvider>
47
50
  </ThemeContext.Provider>
48
51
  </PiPProvider>
49
52
  </DevtoolsSubscriptionsProvider>
package/src/Explorer.tsx CHANGED
@@ -277,11 +277,12 @@ type ExplorerProps = {
277
277
 
278
278
  /**
279
279
  * Adds nested data search without changing the explorer's manual expansion.
280
- * @param props - Data explorer options and the selected query or mutation identity.
280
+ * @param props - Data explorer options, the selected query or mutation identity, and the search
281
+ * term to start with when another one is selected.
281
282
  * @returns The search controls and the original data tree.
282
283
  */
283
284
  export function SearchableExplorer(
284
- props: ExplorerProps & { searchKey?: unknown },
285
+ props: ExplorerProps & { searchKey?: unknown; initialSearch?: string },
285
286
  ) {
286
287
  const theme = useTheme()
287
288
  const css = useQueryDevtoolsContext().shadowDOMTarget
@@ -297,7 +298,13 @@ export function SearchableExplorer(
297
298
  setDebouncedTerm('')
298
299
  }
299
300
  const searchKey = createMemo(() => props.searchKey)
300
- createEffect(on(searchKey, clear))
301
+ createEffect(
302
+ on(searchKey, () => {
303
+ const initial = props.initialSearch ?? ''
304
+ setTerm(initial)
305
+ setDebouncedTerm(initial.toLowerCase())
306
+ }),
307
+ )
301
308
  createEffect(() => {
302
309
  const next = term().toLowerCase()
303
310
  if (!next) {
@@ -350,8 +357,8 @@ export function SearchableExplorer(
350
357
  <div class={styles().search}>
351
358
  <input
352
359
  type="search"
353
- aria-label="Search data"
354
- placeholder="Search data"
360
+ aria-label={`Search ${props.label.toLowerCase()}`}
361
+ placeholder={`Search ${props.label.toLowerCase()}`}
355
362
  class={styles().searchInput}
356
363
  value={term()}
357
364
  onInput={(event) => setTerm(event.currentTarget.value)}
package/src/constants.ts CHANGED
@@ -15,3 +15,7 @@ export const DEFAULT_WIDTH = 500
15
15
  export const DEFAULT_SORT_FN_NAME = Object.keys(sortFns)[0]
16
16
  export const DEFAULT_SORT_ORDER = 1
17
17
  export const DEFAULT_MUTATION_SORT_FN_NAME = Object.keys(mutationSortFns)[0]
18
+ export const FILTER_SCOPES = ['key', 'data', 'all'] as const
19
+ /** What the query and mutation list filters match: the key, the data, or either. */
20
+ export type FilterScope = (typeof FILTER_SCOPES)[number]
21
+ export const DEFAULT_FILTER_SCOPE: FilterScope = 'key'
@@ -104,6 +104,46 @@ export function searchEntries(value: unknown): Array<SearchEntry> | undefined {
104
104
  }
105
105
  }
106
106
 
107
+ // `toLowerCase` never outputs it, so a lowercased term can't match across two joined parts
108
+ const SEARCH_TEXT_SEPARATOR = 'A'
109
+
110
+ /**
111
+ * Builds the text that `searchExplorer` matches: every entry label and
112
+ * primitive value, lowercased. Visiting breadth-first reaches each object once
113
+ * at its shallowest depth, so shared data is searched once with the same depth
114
+ * bound.
115
+ * @param rootValue - The data to build the search text of.
116
+ * @returns Text that contains a lowercased term exactly when `searchExplorer` matches it.
117
+ */
118
+ export function createSearchText(rootValue: unknown): string {
119
+ const rootText = primitiveText(rootValue)
120
+ if (rootText !== undefined) return rootText.toLowerCase()
121
+ const parts: Array<string> = []
122
+ const seen = new Set<unknown>([rootValue])
123
+ const queue: Array<{ value: unknown; depth: number }> = [
124
+ { value: rootValue, depth: 0 },
125
+ ]
126
+ // Also visits the entries pushed while iterating
127
+ for (const { value, depth } of queue) {
128
+ for (const entry of searchEntries(value) ?? []) {
129
+ parts.push(entry.label.toLowerCase())
130
+ if (entry.accessor) continue
131
+ const text = primitiveText(entry.value)
132
+ if (text !== undefined) {
133
+ parts.push(text.toLowerCase())
134
+ } else if (
135
+ depth < 500 &&
136
+ typeof entry.value === 'object' &&
137
+ !seen.has(entry.value)
138
+ ) {
139
+ seen.add(entry.value)
140
+ queue.push({ value: entry.value, depth: depth + 1 })
141
+ }
142
+ }
143
+ }
144
+ return parts.join(SEARCH_TEXT_SEPARATOR)
145
+ }
146
+
107
147
  /**
108
148
  * Builds one search tree, stopping ancestor cycles while visiting shared siblings.
109
149
  * @param rootValue - The current root data.