@tanstack/devtools 0.10.10 → 0.10.13

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.
@@ -0,0 +1,5 @@
1
+ // src/constants.ts
2
+ var PLUGIN_CONTAINER_ID = "plugin-container";
3
+ var PLUGIN_TITLE_CONTAINER_ID = "plugin-title-container";
4
+
5
+ export { PLUGIN_CONTAINER_ID, PLUGIN_TITLE_CONTAINER_ID };
@@ -1,11 +1,8 @@
1
+ import { initialState } from './BNGI36V3.js';
1
2
  import { createComponent, delegateEvents } from 'solid-js/web';
2
- import { createContext, createSignal, createEffect, onCleanup, createMemo, useContext } from 'solid-js';
3
+ import { createContext, createEffect, createSignal, onCleanup, createMemo, useContext } from 'solid-js';
3
4
  import { createStore } from 'solid-js/store';
4
5
 
5
- // src/constants.ts
6
- var PLUGIN_CONTAINER_ID = "plugin-container";
7
- var PLUGIN_TITLE_CONTAINER_ID = "plugin-title-container";
8
-
9
6
  // src/utils/storage.ts
10
7
  var getStorageItem = (key) => localStorage.getItem(key);
11
8
  var setStorageItem = (key, value) => {
@@ -18,121 +15,21 @@ var setStorageItem = (key, value) => {
18
15
  var TANSTACK_DEVTOOLS = "tanstack_devtools";
19
16
  var TANSTACK_DEVTOOLS_STATE = "tanstack_devtools_state";
20
17
  var TANSTACK_DEVTOOLS_SETTINGS = "tanstack_devtools_settings";
21
- var PiPContext = createContext(void 0);
22
- var PiPProvider = (props) => {
23
- const [pipWindow, setPipWindow] = createSignal(null);
24
- const closePipWindow = () => {
25
- const w = pipWindow();
26
- if (w != null) {
27
- w.close();
28
- setPipWindow(null);
29
- }
30
- };
31
- const requestPipWindow = (settings) => {
32
- if (pipWindow() != null) {
33
- return;
34
- }
35
- const pip = window.open("", "TSDT-Devtools-Panel", `${settings},popup`);
36
- if (!pip) {
37
- throw new Error("Failed to open popup. Please allow popups for this site to view the devtools in picture-in-picture mode.");
38
- }
39
- if (import.meta.hot && typeof import.meta.hot.on === "function") {
40
- import.meta.hot.on("vite:beforeUpdate", () => {
41
- localStorage.setItem("pip_open", "false");
42
- closePipWindow();
43
- });
44
- }
45
- window.addEventListener("beforeunload", () => {
46
- localStorage.setItem("pip_open", "false");
47
- closePipWindow();
48
- });
49
- pip.document.head.innerHTML = "";
50
- pip.document.body.innerHTML = "";
51
- pip.document.title = "TanStack Devtools";
52
- pip.document.body.style.margin = "0";
53
- pip.addEventListener("pagehide", () => {
54
- localStorage.setItem("pip_open", "false");
55
- closePipWindow();
56
- });
57
- [...document.styleSheets].forEach((styleSheet) => {
58
- try {
59
- const cssRules = [...styleSheet.cssRules].map((rule) => rule.cssText).join("");
60
- const style = document.createElement("style");
61
- const style_node = styleSheet.ownerNode;
62
- let style_id = "";
63
- if (style_node && "id" in style_node) {
64
- style_id = style_node.id;
65
- }
66
- if (style_id) {
67
- style.setAttribute("id", style_id);
68
- }
69
- style.textContent = cssRules;
70
- pip.document.head.appendChild(style);
71
- } catch (e) {
72
- const link = document.createElement("link");
73
- if (styleSheet.href == null) {
74
- return;
75
- }
76
- link.rel = "stylesheet";
77
- link.type = styleSheet.type;
78
- link.media = styleSheet.media.toString();
79
- link.href = styleSheet.href;
80
- pip.document.head.appendChild(link);
81
- }
82
- });
83
- delegateEvents(["focusin", "focusout", "pointermove", "keydown", "pointerdown", "pointerup", "click", "mousedown", "input"], pip.document);
84
- setPipWindow(pip);
85
- };
86
- createEffect(() => {
87
- const gooberStyles = document.querySelector("#_goober");
88
- const w = pipWindow();
89
- if (gooberStyles && w) {
90
- const observer = new MutationObserver(() => {
91
- const pip_style = w.document.querySelector("#_goober");
92
- if (pip_style) {
93
- pip_style.textContent = gooberStyles.textContent;
94
- }
95
- });
96
- observer.observe(gooberStyles, {
97
- childList: true,
98
- // observe direct children
99
- subtree: true,
100
- // and lower descendants too
101
- characterDataOldValue: true
102
- // pass old data to callback
103
- });
104
- onCleanup(() => {
105
- observer.disconnect();
106
- });
107
- }
108
- });
109
- const value = createMemo(() => ({
110
- pipWindow: pipWindow(),
111
- requestPipWindow,
112
- closePipWindow,
113
- disabled: props.disabled ?? false
114
- }));
115
- return createComponent(PiPContext.Provider, {
116
- value,
117
- get children() {
118
- return props.children;
119
- }
120
- });
121
- };
122
- var usePiPWindow = () => {
123
- const context = createMemo(() => {
124
- const ctx = useContext(PiPContext);
125
- if (!ctx) {
126
- throw new Error("usePiPWindow must be used within a PiPProvider");
127
- }
128
- return ctx();
129
- });
130
- return context;
131
- };
132
18
 
133
19
  // src/utils/constants.ts
134
20
  var MAX_ACTIVE_PLUGINS = 3;
135
21
 
22
+ // src/utils/get-default-active-plugins.ts
23
+ function getDefaultActivePlugins(plugins) {
24
+ if (plugins.length === 0) {
25
+ return [];
26
+ }
27
+ if (plugins.length === 1) {
28
+ return [plugins[0].id];
29
+ }
30
+ return plugins.filter((plugin) => plugin.defaultOpen === true).slice(0, MAX_ACTIVE_PLUGINS).map((plugin) => plugin.id);
31
+ }
32
+
136
33
  // src/utils/sanitize.ts
137
34
  var tryParseJson = (json) => {
138
35
  if (!json) return void 0;
@@ -160,47 +57,6 @@ var getAllPermutations = (arr) => {
160
57
  return res;
161
58
  };
162
59
 
163
- // src/context/devtools-store.ts
164
- var keyboardModifiers = [
165
- "Alt",
166
- "Control",
167
- "Meta",
168
- "Shift",
169
- "CtrlOrMeta"
170
- ];
171
- var initialState = {
172
- settings: {
173
- defaultOpen: false,
174
- hideUntilHover: false,
175
- position: "bottom-right",
176
- panelLocation: "bottom",
177
- openHotkey: ["Control", "~"],
178
- inspectHotkey: ["Shift", "Alt", "CtrlOrMeta"],
179
- requireUrlFlag: false,
180
- urlFlag: "tanstack-devtools",
181
- theme: typeof window !== "undefined" && typeof window.matchMedia !== "undefined" && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light",
182
- triggerHidden: false,
183
- customTrigger: void 0
184
- },
185
- state: {
186
- activeTab: "plugins",
187
- height: 400,
188
- activePlugins: [],
189
- persistOpen: false
190
- }
191
- };
192
-
193
- // src/utils/get-default-active-plugins.ts
194
- function getDefaultActivePlugins(plugins) {
195
- if (plugins.length === 0) {
196
- return [];
197
- }
198
- if (plugins.length === 1) {
199
- return [plugins[0].id];
200
- }
201
- return plugins.filter((plugin) => plugin.defaultOpen === true).slice(0, MAX_ACTIVE_PLUGINS).map((plugin) => plugin.id);
202
- }
203
-
204
60
  // src/context/devtools-context.tsx
205
61
  var DevtoolsContext = createContext();
206
62
  var getSettings = () => {
@@ -303,5 +159,116 @@ var DevtoolsProvider = (props) => {
303
159
  }
304
160
  });
305
161
  };
162
+ var PiPContext = createContext(void 0);
163
+ var PiPProvider = (props) => {
164
+ const [pipWindow, setPipWindow] = createSignal(null);
165
+ const closePipWindow = () => {
166
+ const w = pipWindow();
167
+ if (w != null) {
168
+ w.close();
169
+ setPipWindow(null);
170
+ }
171
+ };
172
+ const requestPipWindow = (settings) => {
173
+ if (pipWindow() != null) {
174
+ return;
175
+ }
176
+ const pip = window.open("", "TSDT-Devtools-Panel", `${settings},popup`);
177
+ if (!pip) {
178
+ throw new Error("Failed to open popup. Please allow popups for this site to view the devtools in picture-in-picture mode.");
179
+ }
180
+ if (import.meta.hot && typeof import.meta.hot.on === "function") {
181
+ import.meta.hot.on("vite:beforeUpdate", () => {
182
+ localStorage.setItem("pip_open", "false");
183
+ closePipWindow();
184
+ });
185
+ }
186
+ window.addEventListener("beforeunload", () => {
187
+ localStorage.setItem("pip_open", "false");
188
+ closePipWindow();
189
+ });
190
+ pip.document.head.innerHTML = "";
191
+ pip.document.body.innerHTML = "";
192
+ pip.document.title = "TanStack Devtools";
193
+ pip.document.body.style.margin = "0";
194
+ pip.addEventListener("pagehide", () => {
195
+ localStorage.setItem("pip_open", "false");
196
+ closePipWindow();
197
+ });
198
+ [...document.styleSheets].forEach((styleSheet) => {
199
+ try {
200
+ const cssRules = [...styleSheet.cssRules].map((rule) => rule.cssText).join("");
201
+ const style = document.createElement("style");
202
+ const style_node = styleSheet.ownerNode;
203
+ let style_id = "";
204
+ if (style_node && "id" in style_node) {
205
+ style_id = style_node.id;
206
+ }
207
+ if (style_id) {
208
+ style.setAttribute("id", style_id);
209
+ }
210
+ style.textContent = cssRules;
211
+ pip.document.head.appendChild(style);
212
+ } catch (e) {
213
+ const link = document.createElement("link");
214
+ if (styleSheet.href == null) {
215
+ return;
216
+ }
217
+ link.rel = "stylesheet";
218
+ link.type = styleSheet.type;
219
+ link.media = styleSheet.media.toString();
220
+ link.href = styleSheet.href;
221
+ pip.document.head.appendChild(link);
222
+ }
223
+ });
224
+ delegateEvents(["focusin", "focusout", "pointermove", "keydown", "pointerdown", "pointerup", "click", "mousedown", "input"], pip.document);
225
+ setPipWindow(pip);
226
+ };
227
+ createEffect(() => {
228
+ const gooberStyles = document.querySelector("#_goober");
229
+ const w = pipWindow();
230
+ if (gooberStyles && w) {
231
+ const observer = new MutationObserver(() => {
232
+ const pip_style = w.document.querySelector("#_goober");
233
+ if (pip_style) {
234
+ pip_style.textContent = gooberStyles.textContent;
235
+ }
236
+ });
237
+ observer.observe(gooberStyles, {
238
+ childList: true,
239
+ // observe direct children
240
+ subtree: true,
241
+ // and lower descendants too
242
+ characterDataOldValue: true
243
+ // pass old data to callback
244
+ });
245
+ onCleanup(() => {
246
+ observer.disconnect();
247
+ });
248
+ }
249
+ });
250
+ const value = createMemo(() => ({
251
+ pipWindow: pipWindow(),
252
+ requestPipWindow,
253
+ closePipWindow,
254
+ disabled: props.disabled ?? false
255
+ }));
256
+ return createComponent(PiPContext.Provider, {
257
+ value,
258
+ get children() {
259
+ return props.children;
260
+ }
261
+ });
262
+ };
263
+ var usePiPWindow = () => {
264
+ const context = createMemo(() => {
265
+ const ctx = useContext(PiPContext);
266
+ if (!ctx) {
267
+ throw new Error("usePiPWindow must be used within a PiPProvider");
268
+ }
269
+ return ctx();
270
+ });
271
+ return context;
272
+ };
306
273
 
307
- export { DevtoolsContext, DevtoolsProvider, MAX_ACTIVE_PLUGINS, PLUGIN_CONTAINER_ID, PLUGIN_TITLE_CONTAINER_ID, PiPProvider, TANSTACK_DEVTOOLS, getAllPermutations, initialState, keyboardModifiers, uppercaseFirstLetter, usePiPWindow };
274
+ export { DevtoolsContext, DevtoolsProvider, MAX_ACTIVE_PLUGINS, PiPProvider, TANSTACK_DEVTOOLS, getAllPermutations, uppercaseFirstLetter, usePiPWindow };
@@ -0,0 +1,31 @@
1
+ // src/context/devtools-store.ts
2
+ var keyboardModifiers = [
3
+ "Alt",
4
+ "Control",
5
+ "Meta",
6
+ "Shift",
7
+ "CtrlOrMeta"
8
+ ];
9
+ var initialState = {
10
+ settings: {
11
+ defaultOpen: false,
12
+ hideUntilHover: false,
13
+ position: "bottom-right",
14
+ panelLocation: "bottom",
15
+ openHotkey: ["Control", "~"],
16
+ inspectHotkey: ["Shift", "Alt", "CtrlOrMeta"],
17
+ requireUrlFlag: false,
18
+ urlFlag: "tanstack-devtools",
19
+ theme: typeof window !== "undefined" && typeof window.matchMedia !== "undefined" && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light",
20
+ triggerHidden: false,
21
+ customTrigger: void 0
22
+ },
23
+ state: {
24
+ activeTab: "plugins",
25
+ height: 400,
26
+ activePlugins: [],
27
+ persistOpen: false
28
+ }
29
+ };
30
+
31
+ export { initialState, keyboardModifiers };
package/dist/dev.js CHANGED
@@ -1,17 +1,16 @@
1
- import { initialState, DevtoolsProvider, PiPProvider } from './chunk/ULTYUGME.js';
2
- export { PLUGIN_CONTAINER_ID, PLUGIN_TITLE_CONTAINER_ID } from './chunk/ULTYUGME.js';
3
- import { render, createComponent, Portal } from 'solid-js/web';
4
- import { lazy } from 'solid-js';
5
- import { ClientEventBus } from '@tanstack/devtools-event-bus/client';
1
+ export { PLUGIN_CONTAINER_ID, PLUGIN_TITLE_CONTAINER_ID } from './chunk/A767CXXU.js';
2
+ import { initialState } from './chunk/BNGI36V3.js';
6
3
 
4
+ // src/core.ts
7
5
  var TanStackDevtoolsCore = class {
8
6
  #config = {
9
7
  ...initialState.settings
10
8
  };
11
9
  #plugins = [];
12
10
  #isMounted = false;
11
+ #isMounting = false;
12
+ #abortMount = false;
13
13
  #dispose;
14
- #Component;
15
14
  #eventBus;
16
15
  #eventBusConfig;
17
16
  #setPlugins;
@@ -24,47 +23,44 @@ var TanStackDevtoolsCore = class {
24
23
  };
25
24
  }
26
25
  mount(el) {
27
- if (this.#isMounted) {
26
+ if (typeof document === "undefined") return;
27
+ if (this.#isMounted || this.#isMounting) {
28
28
  throw new Error("Devtools is already mounted");
29
29
  }
30
- const mountTo = el;
31
- const dispose = render(() => {
32
- const _self$ = this;
33
- this.#Component = lazy(() => import('./devtools/LF5QLUHI.js'));
34
- const Devtools = this.#Component;
35
- this.#eventBus = new ClientEventBus(this.#eventBusConfig);
36
- this.#eventBus.start();
37
- return createComponent(DevtoolsProvider, {
38
- get plugins() {
39
- return _self$.#plugins;
40
- },
41
- get config() {
42
- return _self$.#config;
43
- },
30
+ this.#isMounting = true;
31
+ this.#abortMount = false;
32
+ import('./mount-impl/Z6LKUI5N.js').then(({ mountDevtools }) => {
33
+ if (this.#abortMount) {
34
+ this.#isMounting = false;
35
+ return;
36
+ }
37
+ const result = mountDevtools({
38
+ el,
39
+ plugins: this.#plugins,
40
+ config: this.#config,
41
+ eventBusConfig: this.#eventBusConfig,
44
42
  onSetPlugins: (setPlugins) => {
45
- _self$.#setPlugins = setPlugins;
46
- },
47
- get children() {
48
- return createComponent(PiPProvider, {
49
- get children() {
50
- return createComponent(Portal, {
51
- mount: mountTo,
52
- get children() {
53
- return createComponent(Devtools, {});
54
- }
55
- });
56
- }
57
- });
43
+ this.#setPlugins = setPlugins;
58
44
  }
59
45
  });
60
- }, mountTo);
61
- this.#isMounted = true;
62
- this.#dispose = dispose;
46
+ this.#dispose = result.dispose;
47
+ this.#eventBus = result.eventBus;
48
+ this.#isMounted = true;
49
+ this.#isMounting = false;
50
+ }).catch((err) => {
51
+ this.#isMounting = false;
52
+ console.error("[TanStack Devtools] Failed to load:", err);
53
+ });
63
54
  }
64
55
  unmount() {
65
- if (!this.#isMounted) {
56
+ if (!this.#isMounted && !this.#isMounting) {
66
57
  throw new Error("Devtools is not mounted");
67
58
  }
59
+ if (this.#isMounting) {
60
+ this.#abortMount = true;
61
+ this.#isMounting = false;
62
+ return;
63
+ }
68
64
  this.#eventBus?.stop();
69
65
  this.#dispose?.();
70
66
  this.#isMounted = false;
@@ -1,4 +1,6 @@
1
- import { usePiPWindow, TANSTACK_DEVTOOLS, keyboardModifiers, getAllPermutations, DevtoolsContext, PLUGIN_TITLE_CONTAINER_ID, PLUGIN_CONTAINER_ID, MAX_ACTIVE_PLUGINS, uppercaseFirstLetter } from '../chunk/ULTYUGME.js';
1
+ import { PLUGIN_TITLE_CONTAINER_ID, PLUGIN_CONTAINER_ID } from '../chunk/A767CXXU.js';
2
+ import { usePiPWindow, TANSTACK_DEVTOOLS, getAllPermutations, DevtoolsContext, MAX_ACTIVE_PLUGINS, uppercaseFirstLetter } from '../chunk/AP5L3KAF.js';
3
+ import { keyboardModifiers } from '../chunk/BNGI36V3.js';
2
4
  import { createComponent, Portal, ssr, ssrAttribute, escape, ssrStyleProperty, ssrStyle } from 'solid-js/web';
3
5
  import { createContext, createSignal, createEffect, onCleanup, Show, createMemo, For, useContext, onMount } from 'solid-js';
4
6
  import { createShortcut, useKeyDownList } from '@solid-primitives/keyboard';
@@ -3551,7 +3553,7 @@ var SourceInspector = () => {
3551
3553
  window.getSelection()?.removeAllRanges();
3552
3554
  e.preventDefault();
3553
3555
  e.stopPropagation();
3554
- const baseUrl = new URL(import.meta?.env?.BASE_URL ?? "/", location.origin);
3556
+ const baseUrl = new URL(import.meta.env?.BASE_URL ?? "/", location.origin);
3555
3557
  const url = new URL(`__tsd/open-source?source=${encodeURIComponent(highlightState.dataSource)}`, baseUrl);
3556
3558
  fetch(url).catch(() => {
3557
3559
  });
@@ -1,4 +1,6 @@
1
- import { usePiPWindow, TANSTACK_DEVTOOLS, keyboardModifiers, getAllPermutations, DevtoolsContext, PLUGIN_TITLE_CONTAINER_ID, PLUGIN_CONTAINER_ID, MAX_ACTIVE_PLUGINS, uppercaseFirstLetter } from '../chunk/ULTYUGME.js';
1
+ import { PLUGIN_TITLE_CONTAINER_ID, PLUGIN_CONTAINER_ID } from '../chunk/A767CXXU.js';
2
+ import { usePiPWindow, TANSTACK_DEVTOOLS, getAllPermutations, DevtoolsContext, MAX_ACTIVE_PLUGINS, uppercaseFirstLetter } from '../chunk/AP5L3KAF.js';
3
+ import { keyboardModifiers } from '../chunk/BNGI36V3.js';
2
4
  import { delegateEvents, createComponent, Portal, use, setAttribute, insert, memo, effect, className, setStyleProperty, addEventListener, style, template, classList } from 'solid-js/web';
3
5
  import { createContext, createSignal, createEffect, onCleanup, Show, createMemo, For, useContext, onMount } from 'solid-js';
4
6
  import { createShortcut, useKeyDownList } from '@solid-primitives/keyboard';
@@ -4089,7 +4091,7 @@ var SourceInspector = () => {
4089
4091
  window.getSelection()?.removeAllRanges();
4090
4092
  e.preventDefault();
4091
4093
  e.stopPropagation();
4092
- const baseUrl = new URL(import.meta?.env?.BASE_URL ?? "/", location.origin);
4094
+ const baseUrl = new URL(import.meta.env?.BASE_URL ?? "/", location.origin);
4093
4095
  const url = new URL(`__tsd/open-source?source=${encodeURIComponent(highlightState.dataSource)}`, baseUrl);
4094
4096
  fetch(url).catch(() => {
4095
4097
  });
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
+ import * as solid_js from 'solid-js';
1
2
  import { ClientEventBusConfig } from '@tanstack/devtools-event-bus/client';
2
3
  export { ClientEventBusConfig } from '@tanstack/devtools-event-bus/client';
3
- import * as solid_js from 'solid-js';
4
4
 
5
5
  declare const PLUGIN_CONTAINER_ID = "plugin-container";
6
6
  declare const PLUGIN_TITLE_CONTAINER_ID = "plugin-title-container";
package/dist/index.js CHANGED
@@ -1,17 +1,16 @@
1
- import { initialState, DevtoolsProvider, PiPProvider } from './chunk/ULTYUGME.js';
2
- export { PLUGIN_CONTAINER_ID, PLUGIN_TITLE_CONTAINER_ID } from './chunk/ULTYUGME.js';
3
- import { render, createComponent, Portal } from 'solid-js/web';
4
- import { lazy } from 'solid-js';
5
- import { ClientEventBus } from '@tanstack/devtools-event-bus/client';
1
+ export { PLUGIN_CONTAINER_ID, PLUGIN_TITLE_CONTAINER_ID } from './chunk/A767CXXU.js';
2
+ import { initialState } from './chunk/BNGI36V3.js';
6
3
 
4
+ // src/core.ts
7
5
  var TanStackDevtoolsCore = class {
8
6
  #config = {
9
7
  ...initialState.settings
10
8
  };
11
9
  #plugins = [];
12
10
  #isMounted = false;
11
+ #isMounting = false;
12
+ #abortMount = false;
13
13
  #dispose;
14
- #Component;
15
14
  #eventBus;
16
15
  #eventBusConfig;
17
16
  #setPlugins;
@@ -24,47 +23,43 @@ var TanStackDevtoolsCore = class {
24
23
  };
25
24
  }
26
25
  mount(el) {
27
- if (this.#isMounted) {
26
+ if (typeof document === "undefined") return;
27
+ if (this.#isMounted || this.#isMounting) {
28
28
  throw new Error("Devtools is already mounted");
29
29
  }
30
- const mountTo = el;
31
- const dispose = render(() => {
32
- const _self$ = this;
33
- this.#Component = lazy(() => import('./devtools/LF5QLUHI.js'));
34
- const Devtools = this.#Component;
35
- this.#eventBus = new ClientEventBus(this.#eventBusConfig);
36
- this.#eventBus.start();
37
- return createComponent(DevtoolsProvider, {
38
- get plugins() {
39
- return _self$.#plugins;
40
- },
41
- get config() {
42
- return _self$.#config;
43
- },
30
+ this.#isMounting = true;
31
+ this.#abortMount = false;
32
+ import('./mount-impl/Z6LKUI5N.js').then(({ mountDevtools }) => {
33
+ if (this.#abortMount) {
34
+ this.#isMounting = false;
35
+ return;
36
+ }
37
+ const result = mountDevtools({
38
+ el,
39
+ plugins: this.#plugins,
40
+ config: this.#config,
41
+ eventBusConfig: this.#eventBusConfig,
44
42
  onSetPlugins: (setPlugins) => {
45
- _self$.#setPlugins = setPlugins;
46
- },
47
- get children() {
48
- return createComponent(PiPProvider, {
49
- get children() {
50
- return createComponent(Portal, {
51
- mount: mountTo,
52
- get children() {
53
- return createComponent(Devtools, {});
54
- }
55
- });
56
- }
57
- });
43
+ this.#setPlugins = setPlugins;
58
44
  }
59
45
  });
60
- }, mountTo);
61
- this.#isMounted = true;
62
- this.#dispose = dispose;
46
+ this.#dispose = result.dispose;
47
+ this.#eventBus = result.eventBus;
48
+ this.#isMounted = true;
49
+ this.#isMounting = false;
50
+ }).catch((err) => {
51
+ this.#isMounting = false;
52
+ });
63
53
  }
64
54
  unmount() {
65
- if (!this.#isMounted) {
55
+ if (!this.#isMounted && !this.#isMounting) {
66
56
  throw new Error("Devtools is not mounted");
67
57
  }
58
+ if (this.#isMounting) {
59
+ this.#abortMount = true;
60
+ this.#isMounting = false;
61
+ return;
62
+ }
68
63
  this.#eventBus?.stop();
69
64
  this.#dispose?.();
70
65
  this.#isMounted = false;
@@ -0,0 +1,41 @@
1
+ import { DevtoolsProvider, PiPProvider } from '../chunk/AP5L3KAF.js';
2
+ import '../chunk/BNGI36V3.js';
3
+ import { render, createComponent, Portal } from 'solid-js/web';
4
+ import { lazy } from 'solid-js';
5
+ import { ClientEventBus } from '@tanstack/devtools-event-bus/client';
6
+
7
+ function mountDevtools(options) {
8
+ const {
9
+ el,
10
+ plugins,
11
+ config,
12
+ eventBusConfig,
13
+ onSetPlugins
14
+ } = options;
15
+ const eventBus = new ClientEventBus(eventBusConfig);
16
+ eventBus.start();
17
+ const Devtools = lazy(() => import('../devtools/7Z2ESJHO.js'));
18
+ const dispose = render(() => createComponent(DevtoolsProvider, {
19
+ plugins,
20
+ config,
21
+ onSetPlugins,
22
+ get children() {
23
+ return createComponent(PiPProvider, {
24
+ get children() {
25
+ return createComponent(Portal, {
26
+ mount: el,
27
+ get children() {
28
+ return createComponent(Devtools, {});
29
+ }
30
+ });
31
+ }
32
+ });
33
+ }
34
+ }), el);
35
+ return {
36
+ dispose,
37
+ eventBus
38
+ };
39
+ }
40
+
41
+ export { mountDevtools };
@@ -0,0 +1,41 @@
1
+ import { DevtoolsProvider, PiPProvider } from '../chunk/AP5L3KAF.js';
2
+ import '../chunk/BNGI36V3.js';
3
+ import { render, createComponent, Portal } from 'solid-js/web';
4
+ import { lazy } from 'solid-js';
5
+ import { ClientEventBus } from '@tanstack/devtools-event-bus/client';
6
+
7
+ function mountDevtools(options) {
8
+ const {
9
+ el,
10
+ plugins,
11
+ config,
12
+ eventBusConfig,
13
+ onSetPlugins
14
+ } = options;
15
+ const eventBus = new ClientEventBus(eventBusConfig);
16
+ eventBus.start();
17
+ const Devtools = lazy(() => import('../devtools/W6LG6674.js'));
18
+ const dispose = render(() => createComponent(DevtoolsProvider, {
19
+ plugins,
20
+ config,
21
+ onSetPlugins,
22
+ get children() {
23
+ return createComponent(PiPProvider, {
24
+ get children() {
25
+ return createComponent(Portal, {
26
+ mount: el,
27
+ get children() {
28
+ return createComponent(Devtools, {});
29
+ }
30
+ });
31
+ }
32
+ });
33
+ }
34
+ }), el);
35
+ return {
36
+ dispose,
37
+ eventBus
38
+ };
39
+ }
40
+
41
+ export { mountDevtools };
package/dist/server.js CHANGED
@@ -1,17 +1,16 @@
1
- import { initialState } from './chunk/ULTYUGME.js';
2
- export { PLUGIN_CONTAINER_ID, PLUGIN_TITLE_CONTAINER_ID } from './chunk/ULTYUGME.js';
3
- import 'solid-js/web';
4
- import 'solid-js';
5
- import '@tanstack/devtools-event-bus/client';
1
+ export { PLUGIN_CONTAINER_ID, PLUGIN_TITLE_CONTAINER_ID } from './chunk/A767CXXU.js';
2
+ import { initialState } from './chunk/BNGI36V3.js';
6
3
 
4
+ // src/core.ts
7
5
  var TanStackDevtoolsCore = class {
8
6
  #config = {
9
7
  ...initialState.settings
10
8
  };
11
9
  #plugins = [];
12
10
  #isMounted = false;
11
+ #isMounting = false;
12
+ #abortMount = false;
13
13
  #dispose;
14
- #Component;
15
14
  #eventBus;
16
15
  #eventBusConfig;
17
16
  #setPlugins;
@@ -24,12 +23,43 @@ var TanStackDevtoolsCore = class {
24
23
  };
25
24
  }
26
25
  mount(el) {
27
- return;
26
+ if (typeof document === "undefined") return;
27
+ if (this.#isMounted || this.#isMounting) {
28
+ throw new Error("Devtools is already mounted");
29
+ }
30
+ this.#isMounting = true;
31
+ this.#abortMount = false;
32
+ import('./mount-impl/EMNOPRXX.js').then(({ mountDevtools }) => {
33
+ if (this.#abortMount) {
34
+ this.#isMounting = false;
35
+ return;
36
+ }
37
+ const result = mountDevtools({
38
+ el,
39
+ plugins: this.#plugins,
40
+ config: this.#config,
41
+ eventBusConfig: this.#eventBusConfig,
42
+ onSetPlugins: (setPlugins) => {
43
+ this.#setPlugins = setPlugins;
44
+ }
45
+ });
46
+ this.#dispose = result.dispose;
47
+ this.#eventBus = result.eventBus;
48
+ this.#isMounted = true;
49
+ this.#isMounting = false;
50
+ }).catch((err) => {
51
+ this.#isMounting = false;
52
+ });
28
53
  }
29
54
  unmount() {
30
- if (!this.#isMounted) {
55
+ if (!this.#isMounted && !this.#isMounting) {
31
56
  throw new Error("Devtools is not mounted");
32
57
  }
58
+ if (this.#isMounting) {
59
+ this.#abortMount = true;
60
+ this.#isMounting = false;
61
+ return;
62
+ }
33
63
  this.#eventBus?.stop();
34
64
  this.#dispose?.();
35
65
  this.#isMounted = false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/devtools",
3
- "version": "0.10.10",
3
+ "version": "0.10.13",
4
4
  "description": "TanStack Devtools is a set of tools for building advanced devtools for your application.",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -80,7 +80,7 @@ export const SourceInspector = () => {
80
80
  e.stopPropagation()
81
81
 
82
82
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
83
- const baseUrl = new URL(import.meta?.env?.BASE_URL ?? '/', location.origin)
83
+ const baseUrl = new URL(import.meta.env?.BASE_URL ?? '/', location.origin)
84
84
  const url = new URL(
85
85
  `__tsd/open-source?source=${encodeURIComponent(
86
86
  highlightState.dataSource,
@@ -1,14 +1,9 @@
1
- import { lazy } from 'solid-js'
2
- import { Portal, render } from 'solid-js/web'
3
- import { ClientEventBus } from '@tanstack/devtools-event-bus/client'
4
- import { DevtoolsProvider } from './context/devtools-context'
5
1
  import { initialState } from './context/devtools-store'
6
- import { PiPProvider } from './context/pip-context'
7
- import type { ClientEventBusConfig } from '@tanstack/devtools-event-bus/client'
8
2
  import type {
9
3
  TanStackDevtoolsConfig,
10
4
  TanStackDevtoolsPlugin,
11
5
  } from './context/devtools-context'
6
+ import type { ClientEventBusConfig } from '@tanstack/devtools-event-bus/client'
12
7
 
13
8
  export interface TanStackDevtoolsInit {
14
9
  /**
@@ -46,9 +41,10 @@ export class TanStackDevtoolsCore {
46
41
  }
47
42
  #plugins: Array<TanStackDevtoolsPlugin> = []
48
43
  #isMounted = false
44
+ #isMounting = false
45
+ #abortMount = false
49
46
  #dispose?: () => void
50
- #Component: any
51
- #eventBus: ClientEventBus | undefined
47
+ #eventBus?: { stop: () => void }
52
48
  #eventBusConfig: ClientEventBusConfig | undefined
53
49
  #setPlugins?: (plugins: Array<TanStackDevtoolsPlugin>) => void
54
50
 
@@ -62,45 +58,51 @@ export class TanStackDevtoolsCore {
62
58
  }
63
59
 
64
60
  mount<T extends HTMLElement>(el: T) {
65
- // tsup-preset-solid statically replaces this variable during build, which eliminates this code from server bundle
66
- // can be run outside of vite so we ignore the rule
67
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
68
- if (import.meta?.env?.SSR) return
61
+ if (typeof document === 'undefined') return
69
62
 
70
- if (this.#isMounted) {
63
+ if (this.#isMounted || this.#isMounting) {
71
64
  throw new Error('Devtools is already mounted')
72
65
  }
73
- const mountTo = el
74
- const dispose = render(() => {
75
- this.#Component = lazy(() => import('./devtools'))
76
- const Devtools = this.#Component
77
- this.#eventBus = new ClientEventBus(this.#eventBusConfig)
78
- this.#eventBus.start()
79
- return (
80
- <DevtoolsProvider
81
- plugins={this.#plugins}
82
- config={this.#config}
83
- onSetPlugins={(setPlugins) => {
66
+ this.#isMounting = true
67
+ this.#abortMount = false
68
+
69
+ import('./mount-impl')
70
+ .then(({ mountDevtools }) => {
71
+ if (this.#abortMount) {
72
+ this.#isMounting = false
73
+ return
74
+ }
75
+
76
+ const result = mountDevtools({
77
+ el,
78
+ plugins: this.#plugins,
79
+ config: this.#config,
80
+ eventBusConfig: this.#eventBusConfig,
81
+ onSetPlugins: (setPlugins) => {
84
82
  this.#setPlugins = setPlugins
85
- }}
86
- >
87
- <PiPProvider>
88
- <Portal mount={mountTo}>
89
- <Devtools />
90
- </Portal>
91
- </PiPProvider>
92
- </DevtoolsProvider>
93
- )
94
- }, mountTo)
83
+ },
84
+ })
95
85
 
96
- this.#isMounted = true
97
- this.#dispose = dispose
86
+ this.#dispose = result.dispose
87
+ this.#eventBus = result.eventBus
88
+ this.#isMounted = true
89
+ this.#isMounting = false
90
+ })
91
+ .catch((err) => {
92
+ this.#isMounting = false
93
+ console.error('[TanStack Devtools] Failed to load:', err)
94
+ })
98
95
  }
99
96
 
100
97
  unmount() {
101
- if (!this.#isMounted) {
98
+ if (!this.#isMounted && !this.#isMounting) {
102
99
  throw new Error('Devtools is not mounted')
103
100
  }
101
+ if (this.#isMounting) {
102
+ this.#abortMount = true
103
+ this.#isMounting = false
104
+ return
105
+ }
104
106
  this.#eventBus?.stop()
105
107
  this.#dispose?.()
106
108
  this.#isMounted = false
@@ -0,0 +1,53 @@
1
+ import { lazy } from 'solid-js'
2
+ import { Portal, render } from 'solid-js/web'
3
+ import { ClientEventBus } from '@tanstack/devtools-event-bus/client'
4
+ import { DevtoolsProvider } from './context/devtools-context'
5
+ import { PiPProvider } from './context/pip-context'
6
+ import type {
7
+ TanStackDevtoolsConfig,
8
+ TanStackDevtoolsPlugin,
9
+ } from './context/devtools-context'
10
+ import type { ClientEventBusConfig } from '@tanstack/devtools-event-bus/client'
11
+
12
+ interface MountOptions {
13
+ el: HTMLElement
14
+ plugins: Array<TanStackDevtoolsPlugin>
15
+ config: TanStackDevtoolsConfig
16
+ eventBusConfig?: ClientEventBusConfig
17
+ onSetPlugins: (
18
+ setPlugins: (plugins: Array<TanStackDevtoolsPlugin>) => void,
19
+ ) => void
20
+ }
21
+
22
+ interface MountResult {
23
+ dispose: () => void
24
+ eventBus: { stop: () => void }
25
+ }
26
+
27
+ export function mountDevtools(options: MountOptions): MountResult {
28
+ const { el, plugins, config, eventBusConfig, onSetPlugins } = options
29
+
30
+ const eventBus = new ClientEventBus(eventBusConfig)
31
+ eventBus.start()
32
+
33
+ const Devtools = lazy(() => import('./devtools'))
34
+
35
+ const dispose = render(
36
+ () => (
37
+ <DevtoolsProvider
38
+ plugins={plugins}
39
+ config={config}
40
+ onSetPlugins={onSetPlugins}
41
+ >
42
+ <PiPProvider>
43
+ <Portal mount={el}>
44
+ <Devtools />
45
+ </Portal>
46
+ </PiPProvider>
47
+ </DevtoolsProvider>
48
+ ),
49
+ el,
50
+ )
51
+
52
+ return { dispose, eventBus }
53
+ }