@tanstack/query-devtools 5.21.5 → 5.24.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.
@@ -11,6 +11,7 @@ import {
11
11
  Switch,
12
12
  batch,
13
13
  children,
14
+ clearDelegatedEvents,
14
15
  convertRemToPixels,
15
16
  createComponent,
16
17
  createComputed,
@@ -49,7 +50,7 @@ import {
49
50
  use,
50
51
  useContext,
51
52
  useTransition
52
- } from "../chunk/PQZZ5Z2E.jsx";
53
+ } from "../chunk/IQDKCOXE.jsx";
53
54
 
54
55
  // ../../node_modules/.pnpm/@tanstack+match-sorter-utils@8.11.8/node_modules/@tanstack/match-sorter-utils/build/lib/index.mjs
55
56
  var characterMap = {
@@ -9073,6 +9074,21 @@ function Settings() {
9073
9074
  />
9074
9075
  </svg>;
9075
9076
  }
9077
+ function PiPIcon() {
9078
+ return <svg
9079
+ width="24"
9080
+ height="24"
9081
+ viewBox="0 0 24 24"
9082
+ fill="none"
9083
+ xmlns="http://www.w3.org/2000/svg"
9084
+ ><path
9085
+ 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"
9086
+ stroke="currentColor"
9087
+ stroke-width="2"
9088
+ stroke-linecap="round"
9089
+ stroke-linejoin="round"
9090
+ /></svg>;
9091
+ }
9076
9092
  function Copier() {
9077
9093
  return <svg
9078
9094
  width="24"
@@ -10436,6 +10452,133 @@ var [selectedMutationId, setSelectedMutationId] = createSignal(
10436
10452
  null
10437
10453
  );
10438
10454
  var [panelWidth, setPanelWidth] = createSignal(0);
10455
+ var PiPContext = createContext(
10456
+ void 0
10457
+ );
10458
+ var PiPProvider = (props) => {
10459
+ const [pipWindow, setPipWindow] = createSignal(null);
10460
+ const closePipWindow = () => {
10461
+ const w = pipWindow();
10462
+ if (w != null) {
10463
+ w.close();
10464
+ setPipWindow(null);
10465
+ }
10466
+ };
10467
+ const requestPipWindow = async (width, height) => {
10468
+ if (pipWindow() != null) {
10469
+ return;
10470
+ }
10471
+ const pip = window.open(
10472
+ "",
10473
+ "TSQD-Devtools-Panel",
10474
+ `width=${width},height=${height},popup`
10475
+ );
10476
+ if (!pip) {
10477
+ throw new Error(
10478
+ "Failed to open popup. Please allow popups for this site to view the devtools in picture-in-picture mode."
10479
+ );
10480
+ }
10481
+ pip.document.head.innerHTML = "";
10482
+ pip.document.body.innerHTML = "";
10483
+ clearDelegatedEvents(pip.document);
10484
+ pip.document.title = "TanStack Query Devtools";
10485
+ pip.document.body.style.margin = "0";
10486
+ pip.addEventListener("pagehide", () => {
10487
+ props.setLocalStore("pip_open", "false");
10488
+ setPipWindow(null);
10489
+ });
10490
+ [...document.styleSheets].forEach((styleSheet) => {
10491
+ try {
10492
+ const cssRules = [...styleSheet.cssRules].map((rule) => rule.cssText).join("");
10493
+ const style2 = document.createElement("style");
10494
+ const style_node = styleSheet.ownerNode;
10495
+ let style_id = "";
10496
+ if (style_node && "id" in style_node) {
10497
+ style_id = style_node.id;
10498
+ }
10499
+ if (style_id) {
10500
+ style2.setAttribute("id", style_id);
10501
+ }
10502
+ style2.textContent = cssRules;
10503
+ pip.document.head.appendChild(style2);
10504
+ } catch (e2) {
10505
+ const link = document.createElement("link");
10506
+ if (styleSheet.href == null) {
10507
+ return;
10508
+ }
10509
+ link.rel = "stylesheet";
10510
+ link.type = styleSheet.type;
10511
+ link.media = styleSheet.media.toString();
10512
+ link.href = styleSheet.href;
10513
+ pip.document.head.appendChild(link);
10514
+ }
10515
+ });
10516
+ delegateEvents(
10517
+ [
10518
+ "focusin",
10519
+ "focusout",
10520
+ "pointermove",
10521
+ "keydown",
10522
+ "pointerdown",
10523
+ "pointerup",
10524
+ "click",
10525
+ "mousedown",
10526
+ "input"
10527
+ ],
10528
+ pip.document
10529
+ );
10530
+ props.setLocalStore("pip_open", "true");
10531
+ setPipWindow(pip);
10532
+ };
10533
+ createEffect(() => {
10534
+ const pip_open = props.localStore.pip_open ?? "false";
10535
+ if (pip_open === "true") {
10536
+ requestPipWindow(
10537
+ Number(window.innerWidth),
10538
+ Number(props.localStore.height || DEFAULT_HEIGHT)
10539
+ );
10540
+ }
10541
+ });
10542
+ createEffect(() => {
10543
+ const gooberStyles = document.getElementById("_goober");
10544
+ const w = pipWindow();
10545
+ if (gooberStyles && w) {
10546
+ const observer = new MutationObserver(() => {
10547
+ const pip_style = w.document.getElementById("_goober");
10548
+ if (pip_style) {
10549
+ pip_style.textContent = gooberStyles.textContent;
10550
+ }
10551
+ });
10552
+ observer.observe(gooberStyles, {
10553
+ childList: true,
10554
+ // observe direct children
10555
+ subtree: true,
10556
+ // and lower descendants too
10557
+ characterDataOldValue: true
10558
+ // pass old data to callback
10559
+ });
10560
+ onCleanup(() => {
10561
+ observer.disconnect();
10562
+ });
10563
+ }
10564
+ });
10565
+ const value = createMemo(() => ({
10566
+ pipWindow: pipWindow(),
10567
+ requestPipWindow,
10568
+ closePipWindow
10569
+ }));
10570
+ return <PiPContext.Provider value={value}>{props.children}</PiPContext.Provider>;
10571
+ };
10572
+ var usePiPWindow = () => {
10573
+ const context = createMemo(() => {
10574
+ const ctx = useContext(PiPContext);
10575
+ if (!ctx) {
10576
+ throw new Error("usePiPWindow must be used within a PiPProvider");
10577
+ }
10578
+ return ctx();
10579
+ });
10580
+ return context;
10581
+ };
10439
10582
  var DevtoolsComponent = (props) => {
10440
10583
  const [localStore, setLocalStore] = createLocalStorage({
10441
10584
  prefix: "TanstackQueryDevtools"
@@ -10447,7 +10590,7 @@ var DevtoolsComponent = (props) => {
10447
10590
  return preference;
10448
10591
  return colorScheme();
10449
10592
  });
10450
- return <QueryDevtoolsContext.Provider value={props}><ThemeContext.Provider value={theme}><Devtools localStore={localStore} setLocalStore={setLocalStore} /></ThemeContext.Provider></QueryDevtoolsContext.Provider>;
10593
+ return <QueryDevtoolsContext.Provider value={props}><PiPProvider localStore={localStore} setLocalStore={setLocalStore}><ThemeContext.Provider value={theme}><Devtools localStore={localStore} setLocalStore={setLocalStore} /></ThemeContext.Provider></PiPProvider></QueryDevtoolsContext.Provider>;
10451
10594
  };
10452
10595
  var Devtools_default = DevtoolsComponent;
10453
10596
  var Devtools = (props) => {
@@ -10455,6 +10598,7 @@ var Devtools = (props) => {
10455
10598
  const styles = createMemo(() => {
10456
10599
  return theme() === "dark" ? darkStyles2 : lightStyles2;
10457
10600
  });
10601
+ const pip = usePiPWindow();
10458
10602
  const buttonPosition = createMemo(() => {
10459
10603
  return useQueryDevtoolsContext().buttonPosition || BUTTON_POSITION;
10460
10604
  });
@@ -10491,58 +10635,123 @@ var Devtools = (props) => {
10491
10635
  window.removeEventListener("focus", onFocus);
10492
10636
  });
10493
10637
  });
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
10638
+ const pip_open = createMemo(
10639
+ () => props.localStore.pip_open ?? "false"
10640
+ );
10641
+ return <>
10642
+ <Show when={pip().pipWindow && pip_open() == "true"}><Portal mount={pip().pipWindow?.document.body}><PiPPanel><ContentView
10528
10643
  localStore={props.localStore}
10529
10644
  setLocalStore={props.setLocalStore}
10530
- /></Show></TransitionGroup>
10531
- <TransitionGroup name="tsqd-button-transition"><Show when={!isOpen()}><div
10645
+ /></PiPPanel></Portal></Show>
10646
+ <div
10532
10647
  class={clsx(
10533
- styles().devtoolsBtn,
10534
- styles()[`devtoolsBtn-position-${buttonPosition()}`],
10535
- "tsqd-open-btn-container"
10648
+ u`
10649
+ & .tsqd-panel-transition-exit-active,
10650
+ & .tsqd-panel-transition-enter-active {
10651
+ transition:
10652
+ opacity 0.3s,
10653
+ transform 0.3s;
10654
+ }
10655
+
10656
+ & .tsqd-panel-transition-exit-to,
10657
+ & .tsqd-panel-transition-enter {
10658
+ ${position() === "top" || position() === "bottom" ? `transform: translateY(var(--tsqd-panel-height));` : `transform: translateX(var(--tsqd-panel-width));`}
10659
+ }
10660
+
10661
+ & .tsqd-button-transition-exit-active,
10662
+ & .tsqd-button-transition-enter-active {
10663
+ transition:
10664
+ opacity 0.3s,
10665
+ transform 0.3s;
10666
+ opacity: 1;
10667
+ }
10668
+
10669
+ & .tsqd-button-transition-exit-to,
10670
+ & .tsqd-button-transition-enter {
10671
+ transform: ${buttonPosition() === "relative" ? `none;` : buttonPosition() === "top-left" ? `translateX(-72px);` : buttonPosition() === "top-right" ? `translateX(72px);` : `translateY(72px);`};
10672
+ opacity: 0;
10673
+ }
10674
+ `,
10675
+ "tsqd-transitions-container"
10536
10676
  )}
10677
+ ref={transitionsContainerRef}
10537
10678
  >
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>;
10679
+ <TransitionGroup name="tsqd-panel-transition"><Show when={isOpen() && !pip().pipWindow && pip_open() == "false"}><DevtoolsPanel
10680
+ localStore={props.localStore}
10681
+ setLocalStore={props.setLocalStore}
10682
+ /></Show></TransitionGroup>
10683
+ <TransitionGroup name="tsqd-button-transition"><Show when={!isOpen()}><div
10684
+ class={clsx(
10685
+ styles().devtoolsBtn,
10686
+ styles()[`devtoolsBtn-position-${buttonPosition()}`],
10687
+ "tsqd-open-btn-container"
10688
+ )}
10689
+ >
10690
+ <div aria-hidden="true"><TanstackLogo /></div>
10691
+ <button
10692
+ aria-label="Open Tanstack query devtools"
10693
+ onClick={() => props.setLocalStore("open", "true")}
10694
+ class="tsqd-open-btn"
10695
+ ><TanstackLogo /></button>
10696
+ </div></Show></TransitionGroup>
10697
+ </div>
10698
+ </>;
10699
+ };
10700
+ var PiPPanel = (props) => {
10701
+ const pip = usePiPWindow();
10702
+ const theme = useTheme();
10703
+ const styles = createMemo(() => {
10704
+ return theme() === "dark" ? darkStyles2 : lightStyles2;
10705
+ });
10706
+ const getPanelDynamicStyles = () => {
10707
+ const { colors } = tokens;
10708
+ const t2 = (light, dark) => theme() === "dark" ? dark : light;
10709
+ if (panelWidth() < secondBreakpoint) {
10710
+ return u`
10711
+ flex-direction: column;
10712
+ background-color: ${t2(colors.gray[300], colors.gray[600])};
10713
+ `;
10714
+ }
10715
+ return u`
10716
+ flex-direction: row;
10717
+ background-color: ${t2(colors.gray[200], colors.darkGray[900])};
10718
+ `;
10719
+ };
10720
+ createEffect(() => {
10721
+ const win = pip().pipWindow;
10722
+ const resizeCB = () => {
10723
+ if (!win)
10724
+ return;
10725
+ setPanelWidth(win.innerWidth);
10726
+ };
10727
+ if (win) {
10728
+ win.addEventListener("resize", resizeCB);
10729
+ resizeCB();
10730
+ }
10731
+ onCleanup(() => {
10732
+ if (win) {
10733
+ win.removeEventListener("resize", resizeCB);
10734
+ }
10735
+ });
10736
+ });
10737
+ return <div
10738
+ style={{
10739
+ "--tsqd-font-size": "16px",
10740
+ "max-height": "100vh",
10741
+ height: "100vh",
10742
+ width: "100vw"
10743
+ }}
10744
+ class={clsx(
10745
+ styles().panel,
10746
+ getPanelDynamicStyles(),
10747
+ {
10748
+ [u`
10749
+ min-width: min-content;
10750
+ `]: panelWidth() < thirdBreakpoint
10751
+ },
10752
+ "tsqd-main-panel"
10753
+ )}
10754
+ >{props.children}</div>;
10546
10755
  };
10547
10756
  var DevtoolsPanel = (props) => {
10548
10757
  const theme = useTheme();
@@ -10696,6 +10905,7 @@ var ContentView = (props) => {
10696
10905
  const styles = createMemo(() => {
10697
10906
  return theme() === "dark" ? darkStyles2 : lightStyles2;
10698
10907
  });
10908
+ const pip = usePiPWindow();
10699
10909
  const [selectedView, setSelectedView] = createSignal(
10700
10910
  "queries"
10701
10911
  );
@@ -10794,7 +11004,11 @@ var ContentView = (props) => {
10794
11004
  <div class={styles().logoAndToggleContainer}>
10795
11005
  <button
10796
11006
  class={clsx(styles().logo, "tsqd-text-logo-container")}
10797
- onClick={() => props.setLocalStore("open", "false")}
11007
+ onClick={() => {
11008
+ if (!pip().pipWindow) {
11009
+ props.setLocalStore("open", "false");
11010
+ }
11011
+ }}
10798
11012
  aria-label="Close Tanstack query devtools"
10799
11013
  >
10800
11014
  <span
@@ -10855,7 +11069,7 @@ var ContentView = (props) => {
10855
11069
  props.setLocalStore("mutationFilter", e2.currentTarget.value);
10856
11070
  }
10857
11071
  }}
10858
- class="tsqd-query-filter-textfield"
11072
+ class={clsx("tsqd-query-filter-textfield")}
10859
11073
  name="tsqd-query-filter-input"
10860
11074
  value={selectedView() === "queries" ? props.localStore.filter || "" : props.localStore.mutationFilter || ""}
10861
11075
  />
@@ -10954,6 +11168,21 @@ var ContentView = (props) => {
10954
11168
  aria-pressed={offline()}
10955
11169
  title={`${offline() ? "Unset offline mocking behavior" : "Mock offline behavior"}`}
10956
11170
  >{offline() ? <Offline /> : <Wifi />}</button>
11171
+ <Show when={!pip().pipWindow}><button
11172
+ onClick={() => {
11173
+ pip().requestPipWindow(
11174
+ Number(window.innerWidth),
11175
+ Number(props.localStore.height ?? 500)
11176
+ );
11177
+ }}
11178
+ class={clsx(
11179
+ styles().actionsBtn,
11180
+ "tsqd-actions-btn",
11181
+ "tsqd-action-open-pip"
11182
+ )}
11183
+ aria-label="Open in picture-in-picture mode"
11184
+ title="Open in picture-in-picture mode"
11185
+ ><PiPIcon /></button></Show>
10957
11186
  <index$f.Root gutter={4}>
10958
11187
  <index$f.Trigger
10959
11188
  class={clsx(
@@ -10964,6 +11193,7 @@ var ContentView = (props) => {
10964
11193
  ><Settings /></index$f.Trigger>
10965
11194
  <index$f.Portal
10966
11195
  ref={(el) => setComputedVariables(el)}
11196
+ mount={pip().pipWindow ? pip().pipWindow.document.body : document.body}
10967
11197
  ><index$f.Content
10968
11198
  class={clsx(styles().settingsMenu, "tsqd-settings-menu")}
10969
11199
  >
@@ -10986,6 +11216,7 @@ var ContentView = (props) => {
10986
11216
  </index$f.SubTrigger>
10987
11217
  <index$f.Portal
10988
11218
  ref={(el) => setComputedVariables(el)}
11219
+ mount={pip().pipWindow ? pip().pipWindow.document.body : document.body}
10989
11220
  ><index$f.SubContent
10990
11221
  class={clsx(
10991
11222
  styles().settingsMenu,
@@ -11063,6 +11294,7 @@ var ContentView = (props) => {
11063
11294
  </index$f.SubTrigger>
11064
11295
  <index$f.Portal
11065
11296
  ref={(el) => setComputedVariables(el)}
11297
+ mount={pip().pipWindow ? pip().pipWindow.document.body : document.body}
11066
11298
  ><index$f.SubContent
11067
11299
  class={clsx(
11068
11300
  styles().settingsMenu,
@@ -12415,8 +12647,8 @@ var stylesFactory2 = (theme) => {
12415
12647
  gap: ${tokens.size[2]};
12416
12648
  & > button {
12417
12649
  cursor: pointer;
12418
- padding: ${tokens.size[0.5]} ${tokens.size[2]};
12419
- padding-right: ${tokens.size[1.5]};
12650
+ padding: ${tokens.size[0.5]} ${tokens.size[1.5]} ${tokens.size[0.5]}
12651
+ ${tokens.size[2]};
12420
12652
  border-radius: ${tokens.border.radius.sm};
12421
12653
  background-color: ${t2(colors.gray[100], colors.darkGray[400])};
12422
12654
  border: 1px solid ${t2(colors.gray[300], colors.darkGray[200])};