@tanstack/query-devtools 5.0.0-rc.1 → 5.0.0-rc.5

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.
@@ -9477,6 +9477,86 @@ var sortFns = {
9477
9477
  var convertRemToPixels = (rem) => {
9478
9478
  return rem * parseFloat(getComputedStyle(document.documentElement).fontSize);
9479
9479
  };
9480
+ var updateNestedDataByPath = (oldData, updatePath2, value) => {
9481
+ if (updatePath2.length === 0) {
9482
+ return value;
9483
+ }
9484
+ if (oldData instanceof Map) {
9485
+ const newData = new Map(oldData);
9486
+ if (updatePath2.length === 1) {
9487
+ newData.set(updatePath2[0], value);
9488
+ return newData;
9489
+ }
9490
+ const [head, ...tail] = updatePath2;
9491
+ newData.set(head, updateNestedDataByPath(newData.get(head), tail, value));
9492
+ return newData;
9493
+ }
9494
+ if (oldData instanceof Set) {
9495
+ const setAsArray = updateNestedDataByPath(
9496
+ Array.from(oldData),
9497
+ updatePath2,
9498
+ value
9499
+ );
9500
+ return new Set(setAsArray);
9501
+ }
9502
+ if (Array.isArray(oldData)) {
9503
+ const newData = [...oldData];
9504
+ if (updatePath2.length === 1) {
9505
+ newData[updatePath2[0]] = value;
9506
+ return newData;
9507
+ }
9508
+ const [head, ...tail] = updatePath2;
9509
+ newData[head] = updateNestedDataByPath(newData[head], tail, value);
9510
+ return newData;
9511
+ }
9512
+ if (oldData instanceof Object) {
9513
+ const newData = { ...oldData };
9514
+ if (updatePath2.length === 1) {
9515
+ newData[updatePath2[0]] = value;
9516
+ return newData;
9517
+ }
9518
+ const [head, ...tail] = updatePath2;
9519
+ newData[head] = updateNestedDataByPath(newData[head], tail, value);
9520
+ return newData;
9521
+ }
9522
+ return oldData;
9523
+ };
9524
+ var deleteNestedDataByPath = (oldData, deletePath) => {
9525
+ if (oldData instanceof Map) {
9526
+ const newData = new Map(oldData);
9527
+ if (deletePath.length === 1) {
9528
+ newData.delete(deletePath[0]);
9529
+ return newData;
9530
+ }
9531
+ const [head, ...tail] = deletePath;
9532
+ newData.set(head, deleteNestedDataByPath(newData.get(head), tail));
9533
+ return newData;
9534
+ }
9535
+ if (oldData instanceof Set) {
9536
+ const setAsArray = deleteNestedDataByPath(Array.from(oldData), deletePath);
9537
+ return new Set(setAsArray);
9538
+ }
9539
+ if (Array.isArray(oldData)) {
9540
+ const newData = [...oldData];
9541
+ if (deletePath.length === 1) {
9542
+ return newData.filter((_, idx) => idx.toString() !== deletePath[0]);
9543
+ }
9544
+ const [head, ...tail] = deletePath;
9545
+ newData[head] = deleteNestedDataByPath(newData[head], tail);
9546
+ return newData;
9547
+ }
9548
+ if (oldData instanceof Object) {
9549
+ const newData = { ...oldData };
9550
+ if (deletePath.length === 1) {
9551
+ delete newData[deletePath[0]];
9552
+ return newData;
9553
+ }
9554
+ const [head, ...tail] = deletePath;
9555
+ newData[head] = deleteNestedDataByPath(newData[head], tail);
9556
+ return newData;
9557
+ }
9558
+ return oldData;
9559
+ };
9480
9560
 
9481
9561
  // src/icons/index.tsx
9482
9562
  function Search() {
@@ -9691,6 +9771,22 @@ function ErrorCopier() {
9691
9771
  stroke-linejoin="round"
9692
9772
  /></svg>;
9693
9773
  }
9774
+ function List() {
9775
+ return <svg
9776
+ width="24"
9777
+ height="24"
9778
+ viewBox="0 0 24 24"
9779
+ fill="none"
9780
+ stroke="#98A2B3"
9781
+ stroke-width="2"
9782
+ xmlns="http://www.w3.org/2000/svg"
9783
+ >
9784
+ <rect class="list" width="20" height="20" y="2" x="2" rx="2" />
9785
+ <line class="list-item" y1="7" y2="7" x1="6" x2="18" />
9786
+ <line class="list-item" y2="12" y1="12" x1="6" x2="18" />
9787
+ <line class="list-item" y1="17" y2="17" x1="6" x2="18" />
9788
+ </svg>;
9789
+ }
9694
9790
  function TanstackLogo() {
9695
9791
  return <svg version="1.0" viewBox="0 0 633 633">
9696
9792
  <linearGradient
@@ -10407,6 +10503,17 @@ function TanstackLogo() {
10407
10503
  </svg>;
10408
10504
  }
10409
10505
 
10506
+ // src/Context.ts
10507
+ var QueryDevtoolsContext = createContext({
10508
+ client: void 0,
10509
+ onlineManager: void 0,
10510
+ queryFlavor: "",
10511
+ version: ""
10512
+ });
10513
+ function useQueryDevtoolsContext() {
10514
+ return useContext(QueryDevtoolsContext);
10515
+ }
10516
+
10410
10517
  // src/Explorer.tsx
10411
10518
  function chunkArray(array, size2) {
10412
10519
  if (size2 < 1)
@@ -10450,7 +10557,8 @@ var CopyButton = (props) => {
10450
10557
  const styles = getStyles();
10451
10558
  const [copyState, setCopyState] = createSignal("NoCopy");
10452
10559
  return <button
10453
- class={styles.copyButton}
10560
+ class={styles.actionButton}
10561
+ title="Copy object to clipboard"
10454
10562
  aria-label={`${copyState() === "NoCopy" ? "Copy object to clipboard" : copyState() === "SuccessCopy" ? "Object copied to clipboard" : "Error copying object to clipboard"}`}
10455
10563
  onClick={copyState() === "NoCopy" ? () => {
10456
10564
  navigator.clipboard.writeText(stringify(props.value)).then(
@@ -10474,11 +10582,40 @@ var CopyButton = (props) => {
10474
10582
  <Match when={copyState() === "ErrorCopy"}><ErrorCopier /></Match>
10475
10583
  </Switch></button>;
10476
10584
  };
10585
+ var ClearArrayButton = (props) => {
10586
+ const styles = getStyles();
10587
+ const queryClient = useQueryDevtoolsContext().client;
10588
+ return <button
10589
+ class={styles.actionButton}
10590
+ title="Remove all items"
10591
+ aria-label="Remove all items"
10592
+ onClick={() => {
10593
+ const oldData = props.activeQuery.state.data;
10594
+ const newData = updateNestedDataByPath(oldData, props.dataPath, []);
10595
+ queryClient.setQueryData(props.activeQuery.queryKey, newData);
10596
+ }}
10597
+ ><List /></button>;
10598
+ };
10599
+ var DeleteItemButton = (props) => {
10600
+ const styles = getStyles();
10601
+ const queryClient = useQueryDevtoolsContext().client;
10602
+ return <button
10603
+ class={clsx(styles.actionButton)}
10604
+ title="Delete item"
10605
+ aria-label="Delete item"
10606
+ onClick={() => {
10607
+ const oldData = props.activeQuery.state.data;
10608
+ const newData = deleteNestedDataByPath(oldData, props.dataPath);
10609
+ queryClient.setQueryData(props.activeQuery.queryKey, newData);
10610
+ }}
10611
+ ><Trash /></button>;
10612
+ };
10477
10613
  function isIterable(x) {
10478
10614
  return Symbol.iterator in x;
10479
10615
  }
10480
10616
  function Explorer(props) {
10481
10617
  const styles = getStyles();
10618
+ const queryClient = useQueryDevtoolsContext().client;
10482
10619
  const [expanded, setExpanded] = createSignal(
10483
10620
  (props.defaultExpanded || []).includes(props.label)
10484
10621
  );
@@ -10520,6 +10657,7 @@ function Explorer(props) {
10520
10657
  return typeof props.value;
10521
10658
  });
10522
10659
  const subEntryPages = createMemo(() => chunkArray(subEntries(), 100));
10660
+ const currentDataPath = props.dataPath ?? [];
10523
10661
  return <div class={styles.entry}>
10524
10662
  <Show when={subEntryPages().length}>
10525
10663
  <div class={styles.expanderButtonContainer}>
@@ -10538,7 +10676,21 @@ function Explorer(props) {
10538
10676
  {subEntries().length > 1 ? `items` : `item`}
10539
10677
  </span>
10540
10678
  </button>
10541
- <Show when={props.copyable}><CopyButton value={props.value} /></Show>
10679
+ <Show when={props.editable}><div class={styles.actions}>
10680
+ <CopyButton value={props.value} />
10681
+ <Show
10682
+ when={props.itemsDeletable && props.activeQuery !== void 0}
10683
+ ><DeleteItemButton
10684
+ activeQuery={props.activeQuery}
10685
+ dataPath={currentDataPath}
10686
+ /></Show>
10687
+ <Show
10688
+ when={type() === "array" && props.activeQuery !== void 0}
10689
+ ><ClearArrayButton
10690
+ activeQuery={props.activeQuery}
10691
+ dataPath={currentDataPath}
10692
+ /></Show>
10693
+ </div></Show>
10542
10694
  </div>
10543
10695
  <Show when={expanded()}>
10544
10696
  <Show when={subEntryPages().length === 1}><div class={styles.subEntry}><Key each={subEntries()} by={(item) => item.label}>{(entry) => {
@@ -10546,7 +10698,10 @@ function Explorer(props) {
10546
10698
  defaultExpanded={props.defaultExpanded}
10547
10699
  label={entry().label}
10548
10700
  value={entry().value}
10549
- copyable={props.copyable}
10701
+ editable={props.editable}
10702
+ dataPath={[...currentDataPath, entry().label]}
10703
+ activeQuery={props.activeQuery}
10704
+ itemsDeletable={type() === "array" || type() === "Iterable" || type() === "object"}
10550
10705
  />;
10551
10706
  }}</Key></div></Show>
10552
10707
  <Show when={subEntryPages().length > 1}><div class={styles.subEntry}><Index each={subEntryPages()}>{(entries3, index) => <div><div class={styles.entry}>
@@ -10568,22 +10723,41 @@ function Explorer(props) {
10568
10723
  defaultExpanded={props.defaultExpanded}
10569
10724
  label={entry().label}
10570
10725
  value={entry().value}
10571
- copyable={props.copyable}
10726
+ editable={props.editable}
10727
+ dataPath={[...currentDataPath, entry().label]}
10728
+ activeQuery={props.activeQuery}
10572
10729
  />}</Key></div></Show>
10573
10730
  </div></div>}</Index></div></Show>
10574
10731
  </Show>
10575
10732
  </Show>
10576
- <Show when={subEntryPages().length === 0}><div
10577
- style={{
10578
- "line-height": "1.125rem"
10579
- }}
10580
- >
10733
+ <Show when={subEntryPages().length === 0}><div class={styles.row}>
10581
10734
  <span class={styles.label}>
10582
10735
  {props.label}
10583
10736
  {":"}
10584
10737
  </span>
10585
- {" "}
10586
- <span class={styles.value}>{displayValue(props.value)}</span>
10738
+ <Show
10739
+ when={props.editable && props.activeQuery !== void 0 && (type() === "string" || type() === "number")}
10740
+ fallback={<span class={styles.value}>{displayValue(props.value)}</span>}
10741
+ ><input
10742
+ type={type() === "number" ? "number" : "text"}
10743
+ class={clsx(styles.value, styles.editableInput)}
10744
+ value={props.value}
10745
+ onChange={(changeEvent) => {
10746
+ const oldData = props.activeQuery.state.data;
10747
+ const newData = updateNestedDataByPath(
10748
+ oldData,
10749
+ currentDataPath,
10750
+ type() === "number" ? changeEvent.target.valueAsNumber : changeEvent.target.value
10751
+ );
10752
+ queryClient.setQueryData(props.activeQuery.queryKey, newData);
10753
+ }}
10754
+ /></Show>
10755
+ <Show
10756
+ when={props.editable && props.itemsDeletable && props.activeQuery !== void 0}
10757
+ ><DeleteItemButton
10758
+ activeQuery={props.activeQuery}
10759
+ dataPath={currentDataPath}
10760
+ /></Show>
10587
10761
  </div></Show>
10588
10762
  </div>;
10589
10763
  }
@@ -10623,6 +10797,7 @@ var getStyles = () => {
10623
10797
  align-items: center;
10624
10798
  line-height: 1.125rem;
10625
10799
  min-height: 1.125rem;
10800
+ gap: ${size2[2]};
10626
10801
  `,
10627
10802
  expanderButton: u`
10628
10803
  cursor: pointer;
@@ -10660,8 +10835,30 @@ var getStyles = () => {
10660
10835
  `,
10661
10836
  value: u`
10662
10837
  color: ${colors.purple[400]};
10838
+ flex-grow: 1;
10839
+ `,
10840
+ actions: u`
10841
+ display: inline-flex;
10842
+ gap: ${size2[2]};
10843
+ `,
10844
+ row: u`
10845
+ display: inline-flex;
10846
+ gap: ${size2[2]};
10847
+ width: 100%;
10848
+ margin-bottom: ${size2[0.5]};
10849
+ line-height: 1.125rem;
10663
10850
  `,
10664
- copyButton: u`
10851
+ editableInput: u`
10852
+ border: none;
10853
+ padding: 0px ${size2[1]};
10854
+ flex-grow: 1;
10855
+ background-color: ${colors.gray[900]};
10856
+
10857
+ &:hover {
10858
+ background-color: ${colors.gray[800]};
10859
+ }
10860
+ `,
10861
+ actionButton: u`
10665
10862
  background-color: transparent;
10666
10863
  border: none;
10667
10864
  display: inline-flex;
@@ -10672,11 +10869,17 @@ var getStyles = () => {
10672
10869
  width: ${size2[3]};
10673
10870
  height: ${size2[3]};
10674
10871
  position: relative;
10675
- left: ${size2[2]};
10676
10872
  z-index: 1;
10677
10873
 
10678
- &:hover svg .copier {
10679
- stroke: ${colors.gray[500]} !important;
10874
+ &:hover svg {
10875
+ .copier,
10876
+ .list {
10877
+ stroke: ${colors.gray[500]} !important;
10878
+ }
10879
+
10880
+ .list-item {
10881
+ stroke: ${colors.gray[700]};
10882
+ }
10680
10883
  }
10681
10884
 
10682
10885
  &:focus-visible {
@@ -10688,17 +10891,6 @@ var getStyles = () => {
10688
10891
  };
10689
10892
  };
10690
10893
 
10691
- // src/Context.ts
10692
- var QueryDevtoolsContext = createContext({
10693
- client: void 0,
10694
- onlineManager: void 0,
10695
- queryFlavor: "",
10696
- version: ""
10697
- });
10698
- function useQueryDevtoolsContext() {
10699
- return useContext(QueryDevtoolsContext);
10700
- }
10701
-
10702
10894
  // src/fonts.ts
10703
10895
  var loadFonts = () => {
10704
10896
  const link = document.createElement("link");
@@ -11626,7 +11818,8 @@ var QueryDetails = () => {
11626
11818
  label="Data"
11627
11819
  defaultExpanded={["Data"]}
11628
11820
  value={activeQueryStateData()}
11629
- copyable={true}
11821
+ editable={true}
11822
+ activeQuery={activeQuery()}
11630
11823
  /></div>
11631
11824
  <div class={clsx(styles.detailsHeader, "tsqd-query-details-header")}>Query Explorer</div>
11632
11825
  <div