@tanstack/query-devtools 5.21.5 → 5.23.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.
@@ -9073,6 +9073,21 @@ function Settings() {
9073
9073
  />
9074
9074
  </svg>;
9075
9075
  }
9076
+ function PiPIcon() {
9077
+ return <svg
9078
+ width="24"
9079
+ height="24"
9080
+ viewBox="0 0 24 24"
9081
+ fill="none"
9082
+ xmlns="http://www.w3.org/2000/svg"
9083
+ ><path
9084
+ d="M16 21H16.2C17.8802 21 18.7202 21 19.362 20.673C19.9265 20.3854 20.3854 19.9265 20.673 19.362C21 18.7202 21 17.8802 21 16.2V7.8C21 6.11984 21 5.27976 20.673 4.63803C20.3854 4.07354 19.9265 3.6146 19.362 3.32698C18.7202 3 17.8802 3 16.2 3H7.8C6.11984 3 5.27976 3 4.63803 3.32698C4.07354 3.6146 3.6146 4.07354 3.32698 4.63803C3 5.27976 3 6.11984 3 7.8V8M11.5 12.5L17 7M17 7H12M17 7V12M6.2 21H8.8C9.9201 21 10.4802 21 10.908 20.782C11.2843 20.5903 11.5903 20.2843 11.782 19.908C12 19.4802 12 18.9201 12 17.8V15.2C12 14.0799 12 13.5198 11.782 13.092C11.5903 12.7157 11.2843 12.4097 10.908 12.218C10.4802 12 9.92011 12 8.8 12H6.2C5.0799 12 4.51984 12 4.09202 12.218C3.71569 12.4097 3.40973 12.7157 3.21799 13.092C3 13.5198 3 14.0799 3 15.2V17.8C3 18.9201 3 19.4802 3.21799 19.908C3.40973 20.2843 3.71569 20.5903 4.09202 20.782C4.51984 21 5.07989 21 6.2 21Z"
9085
+ stroke="currentColor"
9086
+ stroke-width="2"
9087
+ stroke-linecap="round"
9088
+ stroke-linejoin="round"
9089
+ /></svg>;
9090
+ }
9076
9091
  function Copier() {
9077
9092
  return <svg
9078
9093
  width="24"
@@ -10436,6 +10451,124 @@ var [selectedMutationId, setSelectedMutationId] = createSignal(
10436
10451
  null
10437
10452
  );
10438
10453
  var [panelWidth, setPanelWidth] = createSignal(0);
10454
+ var PiPContext = createContext(
10455
+ void 0
10456
+ );
10457
+ var PiPProvider = (props) => {
10458
+ const [pipWindow, setPipWindow] = createSignal(null);
10459
+ const closePipWindow = () => {
10460
+ const w = pipWindow();
10461
+ if (w != null) {
10462
+ w.close();
10463
+ setPipWindow(null);
10464
+ }
10465
+ };
10466
+ const requestPipWindow = async (width, height) => {
10467
+ if (pipWindow() != null) {
10468
+ return;
10469
+ }
10470
+ const pip = window.open("", "", `width=${width},height=${height},popup`);
10471
+ if (!pip) {
10472
+ throw new Error(
10473
+ "Failed to open popup. Please allow popups for this site to view the devtools in picture-in-picture mode."
10474
+ );
10475
+ }
10476
+ pip.document.title = "TanStack Query Devtools";
10477
+ pip.document.body.style.margin = "0";
10478
+ pip.addEventListener("pagehide", () => {
10479
+ setPipWindow(null);
10480
+ });
10481
+ [...document.styleSheets].forEach((styleSheet) => {
10482
+ try {
10483
+ const cssRules = [...styleSheet.cssRules].map((rule) => rule.cssText).join("");
10484
+ const style2 = document.createElement("style");
10485
+ const style_node = styleSheet.ownerNode;
10486
+ let style_id = "";
10487
+ if (style_node && "id" in style_node) {
10488
+ style_id = style_node.id;
10489
+ }
10490
+ if (style_id) {
10491
+ style2.setAttribute("id", style_id);
10492
+ }
10493
+ style2.textContent = cssRules;
10494
+ pip.document.head.appendChild(style2);
10495
+ } catch (e2) {
10496
+ const link = document.createElement("link");
10497
+ if (styleSheet.href == null) {
10498
+ return;
10499
+ }
10500
+ link.rel = "stylesheet";
10501
+ link.type = styleSheet.type;
10502
+ link.media = styleSheet.media.toString();
10503
+ link.href = styleSheet.href;
10504
+ pip.document.head.appendChild(link);
10505
+ }
10506
+ });
10507
+ delegateEvents(
10508
+ [
10509
+ "focusin",
10510
+ "focusout",
10511
+ "pointermove",
10512
+ "keydown",
10513
+ "pointerdown",
10514
+ "pointerup",
10515
+ "click",
10516
+ "mousedown",
10517
+ "input"
10518
+ ],
10519
+ pip.document
10520
+ );
10521
+ setPipWindow(pip);
10522
+ };
10523
+ createEffect(() => {
10524
+ const closePipWindowOnUnload = () => {
10525
+ closePipWindow();
10526
+ };
10527
+ window.addEventListener("beforeunload", closePipWindowOnUnload);
10528
+ onCleanup(() => {
10529
+ window.removeEventListener("beforeunload", closePipWindowOnUnload);
10530
+ });
10531
+ });
10532
+ createEffect(() => {
10533
+ const gooberStyles = document.getElementById("_goober");
10534
+ const w = pipWindow();
10535
+ if (gooberStyles && w) {
10536
+ const observer = new MutationObserver(() => {
10537
+ const pip_style = w.document.getElementById("_goober");
10538
+ if (pip_style) {
10539
+ pip_style.textContent = gooberStyles.textContent;
10540
+ }
10541
+ });
10542
+ observer.observe(gooberStyles, {
10543
+ childList: true,
10544
+ // observe direct children
10545
+ subtree: true,
10546
+ // and lower descendants too
10547
+ characterDataOldValue: true
10548
+ // pass old data to callback
10549
+ });
10550
+ onCleanup(() => {
10551
+ observer.disconnect();
10552
+ });
10553
+ }
10554
+ });
10555
+ const value = createMemo(() => ({
10556
+ pipWindow: pipWindow(),
10557
+ requestPipWindow,
10558
+ closePipWindow
10559
+ }));
10560
+ return <PiPContext.Provider value={value}>{props.children}</PiPContext.Provider>;
10561
+ };
10562
+ var usePiPWindow = () => {
10563
+ const context = createMemo(() => {
10564
+ const ctx = useContext(PiPContext);
10565
+ if (!ctx) {
10566
+ throw new Error("usePiPWindow must be used within a PiPProvider");
10567
+ }
10568
+ return ctx();
10569
+ });
10570
+ return context;
10571
+ };
10439
10572
  var DevtoolsComponent = (props) => {
10440
10573
  const [localStore, setLocalStore] = createLocalStorage({
10441
10574
  prefix: "TanstackQueryDevtools"
@@ -10447,7 +10580,7 @@ var DevtoolsComponent = (props) => {
10447
10580
  return preference;
10448
10581
  return colorScheme();
10449
10582
  });
10450
- return <QueryDevtoolsContext.Provider value={props}><ThemeContext.Provider value={theme}><Devtools localStore={localStore} setLocalStore={setLocalStore} /></ThemeContext.Provider></QueryDevtoolsContext.Provider>;
10583
+ return <QueryDevtoolsContext.Provider value={props}><PiPProvider><ThemeContext.Provider value={theme}><Devtools localStore={localStore} setLocalStore={setLocalStore} /></ThemeContext.Provider></PiPProvider></QueryDevtoolsContext.Provider>;
10451
10584
  };
10452
10585
  var Devtools_default = DevtoolsComponent;
10453
10586
  var Devtools = (props) => {
@@ -10455,6 +10588,7 @@ var Devtools = (props) => {
10455
10588
  const styles = createMemo(() => {
10456
10589
  return theme() === "dark" ? darkStyles2 : lightStyles2;
10457
10590
  });
10591
+ const pip = usePiPWindow();
10458
10592
  const buttonPosition = createMemo(() => {
10459
10593
  return useQueryDevtoolsContext().buttonPosition || BUTTON_POSITION;
10460
10594
  });
@@ -10491,58 +10625,119 @@ var Devtools = (props) => {
10491
10625
  window.removeEventListener("focus", onFocus);
10492
10626
  });
10493
10627
  });
10494
- return <div
10495
- class={clsx(
10496
- u`
10497
- & .tsqd-panel-transition-exit-active,
10498
- & .tsqd-panel-transition-enter-active {
10499
- transition:
10500
- opacity 0.3s,
10501
- transform 0.3s;
10502
- }
10503
-
10504
- & .tsqd-panel-transition-exit-to,
10505
- & .tsqd-panel-transition-enter {
10506
- ${position() === "top" || position() === "bottom" ? `transform: translateY(var(--tsqd-panel-height));` : `transform: translateX(var(--tsqd-panel-width));`}
10507
- }
10508
-
10509
- & .tsqd-button-transition-exit-active,
10510
- & .tsqd-button-transition-enter-active {
10511
- transition:
10512
- opacity 0.3s,
10513
- transform 0.3s;
10514
- opacity: 1;
10515
- }
10516
-
10517
- & .tsqd-button-transition-exit-to,
10518
- & .tsqd-button-transition-enter {
10519
- transform: ${buttonPosition() === "relative" ? `none;` : buttonPosition() === "top-left" ? `translateX(-72px);` : buttonPosition() === "top-right" ? `translateX(72px);` : `translateY(72px);`};
10520
- opacity: 0;
10521
- }
10522
- `,
10523
- "tsqd-transitions-container"
10524
- )}
10525
- ref={transitionsContainerRef}
10526
- >
10527
- <TransitionGroup name="tsqd-panel-transition"><Show when={isOpen()}><DevtoolsPanel
10628
+ return <>
10629
+ <Show when={pip().pipWindow}><Portal mount={pip().pipWindow?.document.body}><PiPPanel><ContentView
10528
10630
  localStore={props.localStore}
10529
10631
  setLocalStore={props.setLocalStore}
10530
- /></Show></TransitionGroup>
10531
- <TransitionGroup name="tsqd-button-transition"><Show when={!isOpen()}><div
10632
+ /></PiPPanel></Portal></Show>
10633
+ <div
10532
10634
  class={clsx(
10533
- styles().devtoolsBtn,
10534
- styles()[`devtoolsBtn-position-${buttonPosition()}`],
10535
- "tsqd-open-btn-container"
10635
+ u`
10636
+ & .tsqd-panel-transition-exit-active,
10637
+ & .tsqd-panel-transition-enter-active {
10638
+ transition:
10639
+ opacity 0.3s,
10640
+ transform 0.3s;
10641
+ }
10642
+
10643
+ & .tsqd-panel-transition-exit-to,
10644
+ & .tsqd-panel-transition-enter {
10645
+ ${position() === "top" || position() === "bottom" ? `transform: translateY(var(--tsqd-panel-height));` : `transform: translateX(var(--tsqd-panel-width));`}
10646
+ }
10647
+
10648
+ & .tsqd-button-transition-exit-active,
10649
+ & .tsqd-button-transition-enter-active {
10650
+ transition:
10651
+ opacity 0.3s,
10652
+ transform 0.3s;
10653
+ opacity: 1;
10654
+ }
10655
+
10656
+ & .tsqd-button-transition-exit-to,
10657
+ & .tsqd-button-transition-enter {
10658
+ transform: ${buttonPosition() === "relative" ? `none;` : buttonPosition() === "top-left" ? `translateX(-72px);` : buttonPosition() === "top-right" ? `translateX(72px);` : `translateY(72px);`};
10659
+ opacity: 0;
10660
+ }
10661
+ `,
10662
+ "tsqd-transitions-container"
10536
10663
  )}
10664
+ ref={transitionsContainerRef}
10537
10665
  >
10538
- <div aria-hidden="true"><TanstackLogo /></div>
10539
- <button
10540
- aria-label="Open Tanstack query devtools"
10541
- onClick={() => props.setLocalStore("open", "true")}
10542
- class="tsqd-open-btn"
10543
- ><TanstackLogo /></button>
10544
- </div></Show></TransitionGroup>
10545
- </div>;
10666
+ <TransitionGroup name="tsqd-panel-transition"><Show when={isOpen() && !pip().pipWindow}><DevtoolsPanel
10667
+ localStore={props.localStore}
10668
+ setLocalStore={props.setLocalStore}
10669
+ /></Show></TransitionGroup>
10670
+ <TransitionGroup name="tsqd-button-transition"><Show when={!isOpen()}><div
10671
+ class={clsx(
10672
+ styles().devtoolsBtn,
10673
+ styles()[`devtoolsBtn-position-${buttonPosition()}`],
10674
+ "tsqd-open-btn-container"
10675
+ )}
10676
+ >
10677
+ <div aria-hidden="true"><TanstackLogo /></div>
10678
+ <button
10679
+ aria-label="Open Tanstack query devtools"
10680
+ onClick={() => props.setLocalStore("open", "true")}
10681
+ class="tsqd-open-btn"
10682
+ ><TanstackLogo /></button>
10683
+ </div></Show></TransitionGroup>
10684
+ </div>
10685
+ </>;
10686
+ };
10687
+ var PiPPanel = (props) => {
10688
+ const pip = usePiPWindow();
10689
+ const theme = useTheme();
10690
+ const styles = createMemo(() => {
10691
+ return theme() === "dark" ? darkStyles2 : lightStyles2;
10692
+ });
10693
+ const getPanelDynamicStyles = () => {
10694
+ const { colors } = tokens;
10695
+ const t2 = (light, dark) => theme() === "dark" ? dark : light;
10696
+ if (panelWidth() < secondBreakpoint) {
10697
+ return u`
10698
+ flex-direction: column;
10699
+ background-color: ${t2(colors.gray[300], colors.gray[600])};
10700
+ `;
10701
+ }
10702
+ return u`
10703
+ flex-direction: row;
10704
+ background-color: ${t2(colors.gray[200], colors.darkGray[900])};
10705
+ `;
10706
+ };
10707
+ createEffect(() => {
10708
+ const win = pip().pipWindow;
10709
+ const resizeCB = () => {
10710
+ if (!win)
10711
+ return;
10712
+ setPanelWidth(win.innerWidth);
10713
+ };
10714
+ if (win) {
10715
+ win.addEventListener("resize", resizeCB);
10716
+ }
10717
+ onCleanup(() => {
10718
+ if (win) {
10719
+ win.removeEventListener("resize", resizeCB);
10720
+ }
10721
+ });
10722
+ });
10723
+ return <div
10724
+ style={{
10725
+ "--tsqd-font-size": "16px",
10726
+ "max-height": "100vh",
10727
+ height: "100vh",
10728
+ width: "100vw"
10729
+ }}
10730
+ class={clsx(
10731
+ styles().panel,
10732
+ getPanelDynamicStyles(),
10733
+ {
10734
+ [u`
10735
+ min-width: min-content;
10736
+ `]: panelWidth() < thirdBreakpoint
10737
+ },
10738
+ "tsqd-main-panel"
10739
+ )}
10740
+ >{props.children}</div>;
10546
10741
  };
10547
10742
  var DevtoolsPanel = (props) => {
10548
10743
  const theme = useTheme();
@@ -10696,6 +10891,7 @@ var ContentView = (props) => {
10696
10891
  const styles = createMemo(() => {
10697
10892
  return theme() === "dark" ? darkStyles2 : lightStyles2;
10698
10893
  });
10894
+ const pip = usePiPWindow();
10699
10895
  const [selectedView, setSelectedView] = createSignal(
10700
10896
  "queries"
10701
10897
  );
@@ -10794,7 +10990,11 @@ var ContentView = (props) => {
10794
10990
  <div class={styles().logoAndToggleContainer}>
10795
10991
  <button
10796
10992
  class={clsx(styles().logo, "tsqd-text-logo-container")}
10797
- onClick={() => props.setLocalStore("open", "false")}
10993
+ onClick={() => {
10994
+ if (!pip().pipWindow) {
10995
+ props.setLocalStore("open", "false");
10996
+ }
10997
+ }}
10798
10998
  aria-label="Close Tanstack query devtools"
10799
10999
  >
10800
11000
  <span
@@ -10855,7 +11055,7 @@ var ContentView = (props) => {
10855
11055
  props.setLocalStore("mutationFilter", e2.currentTarget.value);
10856
11056
  }
10857
11057
  }}
10858
- class="tsqd-query-filter-textfield"
11058
+ class={clsx("tsqd-query-filter-textfield")}
10859
11059
  name="tsqd-query-filter-input"
10860
11060
  value={selectedView() === "queries" ? props.localStore.filter || "" : props.localStore.mutationFilter || ""}
10861
11061
  />
@@ -10954,6 +11154,21 @@ var ContentView = (props) => {
10954
11154
  aria-pressed={offline()}
10955
11155
  title={`${offline() ? "Unset offline mocking behavior" : "Mock offline behavior"}`}
10956
11156
  >{offline() ? <Offline /> : <Wifi />}</button>
11157
+ <Show when={!pip().pipWindow}><button
11158
+ onClick={() => {
11159
+ pip().requestPipWindow(
11160
+ Number(window.innerWidth),
11161
+ Number(props.localStore.height ?? 500)
11162
+ );
11163
+ }}
11164
+ class={clsx(
11165
+ styles().actionsBtn,
11166
+ "tsqd-actions-btn",
11167
+ "tsqd-action-open-pip"
11168
+ )}
11169
+ aria-label="Open in picture-in-picture mode"
11170
+ title="Open in picture-in-picture mode"
11171
+ ><PiPIcon /></button></Show>
10957
11172
  <index$f.Root gutter={4}>
10958
11173
  <index$f.Trigger
10959
11174
  class={clsx(
@@ -10964,6 +11179,7 @@ var ContentView = (props) => {
10964
11179
  ><Settings /></index$f.Trigger>
10965
11180
  <index$f.Portal
10966
11181
  ref={(el) => setComputedVariables(el)}
11182
+ mount={pip().pipWindow ? pip().pipWindow.document.body : document.body}
10967
11183
  ><index$f.Content
10968
11184
  class={clsx(styles().settingsMenu, "tsqd-settings-menu")}
10969
11185
  >
@@ -10986,6 +11202,7 @@ var ContentView = (props) => {
10986
11202
  </index$f.SubTrigger>
10987
11203
  <index$f.Portal
10988
11204
  ref={(el) => setComputedVariables(el)}
11205
+ mount={pip().pipWindow ? pip().pipWindow.document.body : document.body}
10989
11206
  ><index$f.SubContent
10990
11207
  class={clsx(
10991
11208
  styles().settingsMenu,
@@ -11063,6 +11280,7 @@ var ContentView = (props) => {
11063
11280
  </index$f.SubTrigger>
11064
11281
  <index$f.Portal
11065
11282
  ref={(el) => setComputedVariables(el)}
11283
+ mount={pip().pipWindow ? pip().pipWindow.document.body : document.body}
11066
11284
  ><index$f.SubContent
11067
11285
  class={clsx(
11068
11286
  styles().settingsMenu,
@@ -12415,8 +12633,8 @@ var stylesFactory2 = (theme) => {
12415
12633
  gap: ${tokens.size[2]};
12416
12634
  & > button {
12417
12635
  cursor: pointer;
12418
- padding: ${tokens.size[0.5]} ${tokens.size[2]};
12419
- padding-right: ${tokens.size[1.5]};
12636
+ padding: ${tokens.size[0.5]} ${tokens.size[1.5]} ${tokens.size[0.5]}
12637
+ ${tokens.size[2]};
12420
12638
  border-radius: ${tokens.border.radius.sm};
12421
12639
  background-color: ${t2(colors.gray[100], colors.darkGray[400])};
12422
12640
  border: 1px solid ${t2(colors.gray[300], colors.darkGray[200])};