@tanstack/devtools-utils 0.0.1

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 TanStack
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @tanstack/devtools-utils
2
+
3
+ This package is still under active development and might have breaking changes in the future. Please use it with caution.
@@ -0,0 +1,2 @@
1
+ export * from './panel.js';
2
+ export * from './plugin.js';
@@ -0,0 +1,7 @@
1
+ import { createReactPanel } from "./panel.js";
2
+ import { createReactPlugin } from "./plugin.js";
3
+ export {
4
+ createReactPanel,
5
+ createReactPlugin
6
+ };
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -0,0 +1,24 @@
1
+ export interface DevtoolsPanelProps {
2
+ theme?: 'light' | 'dark';
3
+ }
4
+ /**
5
+ * Creates a React component that dynamically imports and mounts a devtools panel. SSR friendly.
6
+ * @param devtoolsPackageName The name of the devtools package to be imported, e.g., '@tanstack/devtools-react'
7
+ * @param importName The name of the export to be imported from the devtools package (e.g., 'default' or 'DevtoolsCore')
8
+ * @returns A React component that mounts the devtools
9
+ * @example
10
+ * ```tsx
11
+ * // if the export is default
12
+ * const [ReactDevtoolsPanel, NoOpReactDevtoolsPanel] = createReactPanel('@tanstack/devtools-react')
13
+ * ```
14
+ *
15
+ * @example
16
+ * ```tsx
17
+ * // if the export is named differently
18
+ * const [ReactDevtoolsPanel, NoOpReactDevtoolsPanel] = createReactPanel('@tanstack/devtools-react', 'DevtoolsCore')
19
+ * ```
20
+ */
21
+ export declare function createReactPanel<TComponentProps extends DevtoolsPanelProps | undefined, TCoreDevtoolsClass extends {
22
+ mount: (el: HTMLElement, theme: 'light' | 'dark') => void;
23
+ unmount: () => void;
24
+ }>(CoreClass: new () => TCoreDevtoolsClass): readonly [(props: TComponentProps) => import("react/jsx-runtime").JSX.Element, (_props: TComponentProps) => import("react/jsx-runtime").JSX.Element];
@@ -0,0 +1,27 @@
1
+ import { jsx, Fragment } from "react/jsx-runtime";
2
+ import { useRef, useEffect } from "react";
3
+ function createReactPanel(CoreClass) {
4
+ function Panel(props) {
5
+ const devToolRef = useRef(null);
6
+ const devtools = useRef(null);
7
+ useEffect(() => {
8
+ if (devtools.current) return;
9
+ devtools.current = new CoreClass();
10
+ if (devToolRef.current) {
11
+ devtools.current.mount(devToolRef.current, props?.theme ?? "dark");
12
+ }
13
+ return () => {
14
+ devtools.current?.unmount();
15
+ };
16
+ }, [props?.theme]);
17
+ return /* @__PURE__ */ jsx("div", { style: { height: "100%" }, ref: devToolRef });
18
+ }
19
+ function NoOpPanel(_props) {
20
+ return /* @__PURE__ */ jsx(Fragment, {});
21
+ }
22
+ return [Panel, NoOpPanel];
23
+ }
24
+ export {
25
+ createReactPanel
26
+ };
27
+ //# sourceMappingURL=panel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"panel.js","sources":["../../../src/react/panel.tsx"],"sourcesContent":["import { useEffect, useRef } from 'react'\n\nexport interface DevtoolsPanelProps {\n theme?: 'light' | 'dark'\n}\n\n/**\n * Creates a React component that dynamically imports and mounts a devtools panel. SSR friendly.\n * @param devtoolsPackageName The name of the devtools package to be imported, e.g., '@tanstack/devtools-react'\n * @param importName The name of the export to be imported from the devtools package (e.g., 'default' or 'DevtoolsCore')\n * @returns A React component that mounts the devtools\n * @example\n * ```tsx\n * // if the export is default\n * const [ReactDevtoolsPanel, NoOpReactDevtoolsPanel] = createReactPanel('@tanstack/devtools-react')\n * ```\n *\n * @example\n * ```tsx\n * // if the export is named differently\n * const [ReactDevtoolsPanel, NoOpReactDevtoolsPanel] = createReactPanel('@tanstack/devtools-react', 'DevtoolsCore')\n * ```\n */\nexport function createReactPanel<\n TComponentProps extends DevtoolsPanelProps | undefined,\n TCoreDevtoolsClass extends {\n mount: (el: HTMLElement, theme: 'light' | 'dark') => void\n unmount: () => void\n },\n>(CoreClass: new () => TCoreDevtoolsClass) {\n function Panel(props: TComponentProps) {\n const devToolRef = useRef<HTMLDivElement>(null)\n const devtools = useRef<TCoreDevtoolsClass | null>(null)\n useEffect(() => {\n if (devtools.current) return\n\n devtools.current = new CoreClass()\n\n if (devToolRef.current) {\n devtools.current.mount(devToolRef.current, props?.theme ?? 'dark')\n }\n\n return () => {\n devtools.current?.unmount()\n }\n }, [props?.theme])\n\n return <div style={{ height: '100%' }} ref={devToolRef} />\n }\n\n function NoOpPanel(_props: TComponentProps) {\n return <></>\n }\n return [Panel, NoOpPanel] as const\n}\n"],"names":[],"mappings":";;AAuBO,SAAS,iBAMd,WAAyC;AACzC,WAAS,MAAM,OAAwB;AACrC,UAAM,aAAa,OAAuB,IAAI;AAC9C,UAAM,WAAW,OAAkC,IAAI;AACvD,cAAU,MAAM;AACd,UAAI,SAAS,QAAS;AAEtB,eAAS,UAAU,IAAI,UAAA;AAEvB,UAAI,WAAW,SAAS;AACtB,iBAAS,QAAQ,MAAM,WAAW,SAAS,OAAO,SAAS,MAAM;AAAA,MACnE;AAEA,aAAO,MAAM;AACX,iBAAS,SAAS,QAAA;AAAA,MACpB;AAAA,IACF,GAAG,CAAC,OAAO,KAAK,CAAC;AAEjB,WAAO,oBAAC,SAAI,OAAO,EAAE,QAAQ,OAAA,GAAU,KAAK,YAAY;AAAA,EAC1D;AAEA,WAAS,UAAU,QAAyB;AAC1C,WAAO,oBAAA,UAAA,EAAE;AAAA,EACX;AACA,SAAO,CAAC,OAAO,SAAS;AAC1B;"}
@@ -0,0 +1,9 @@
1
+ import { JSX } from 'react';
2
+ import { DevtoolsPanelProps } from './panel.js';
3
+ export declare function createReactPlugin(name: string, Component: (props: DevtoolsPanelProps) => JSX.Element): readonly [() => {
4
+ name: string;
5
+ render: (_el: HTMLElement, theme: "light" | "dark") => import("react/jsx-runtime").JSX.Element;
6
+ }, () => {
7
+ name: string;
8
+ render: (_el: HTMLElement, _theme: "light" | "dark") => import("react/jsx-runtime").JSX.Element;
9
+ }];
@@ -0,0 +1,20 @@
1
+ import { jsx, Fragment } from "react/jsx-runtime";
2
+ function createReactPlugin(name, Component) {
3
+ function Plugin() {
4
+ return {
5
+ name,
6
+ render: (_el, theme) => /* @__PURE__ */ jsx(Component, { theme })
7
+ };
8
+ }
9
+ function NoOpPlugin() {
10
+ return {
11
+ name,
12
+ render: (_el, _theme) => /* @__PURE__ */ jsx(Fragment, {})
13
+ };
14
+ }
15
+ return [Plugin, NoOpPlugin];
16
+ }
17
+ export {
18
+ createReactPlugin
19
+ };
20
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sources":["../../../src/react/plugin.tsx"],"sourcesContent":["import type { JSX } from 'react'\nimport type { DevtoolsPanelProps } from './panel'\n\nexport function createReactPlugin(\n name: string,\n Component: (props: DevtoolsPanelProps) => JSX.Element,\n) {\n function Plugin() {\n return {\n name: name,\n render: (_el: HTMLElement, theme: 'light' | 'dark') => (\n <Component theme={theme} />\n ),\n }\n }\n function NoOpPlugin() {\n return {\n name: name,\n render: (_el: HTMLElement, _theme: 'light' | 'dark') => <></>,\n }\n }\n return [Plugin, NoOpPlugin] as const\n}\n"],"names":[],"mappings":";AAGO,SAAS,kBACd,MACA,WACA;AACA,WAAS,SAAS;AAChB,WAAO;AAAA,MACL;AAAA,MACA,QAAQ,CAAC,KAAkB,UACzB,oBAAC,aAAU,MAAA,CAAc;AAAA,IAAA;AAAA,EAG/B;AACA,WAAS,aAAa;AACpB,WAAO;AAAA,MACL;AAAA,MACA,QAAQ,CAAC,KAAkB,WAA6B,oBAAA,UAAA,CAAA,CAAE;AAAA,IAAA;AAAA,EAE9D;AACA,SAAO,CAAC,QAAQ,UAAU;AAC5B;"}
@@ -0,0 +1,30 @@
1
+ import { JSX } from 'solid-js';
2
+ /**
3
+ * Constructs the core class for the Devtools.
4
+ * This utility is used to construct a lazy loaded Solid component for the Devtools.
5
+ * It returns a tuple containing the main DevtoolsCore class and a NoOpDevtoolsCore class.
6
+ * The NoOpDevtoolsCore class is a no-op implementation that can be used for production if you want to explicitly exclude
7
+ * the Devtools from your application.
8
+ * @param importPath The path to the Solid component to be lazily imported
9
+ * @returns Tuple containing the DevtoolsCore class and a NoOpDevtoolsCore class
10
+ */
11
+ export declare function constructCoreClass(Component: () => JSX.Element): readonly [{
12
+ new (): {
13
+ #isMounted: boolean;
14
+ #dispose?: () => void;
15
+ #Component: any;
16
+ #ThemeProvider: any;
17
+ mount<T extends HTMLElement>(el: T, theme: "light" | "dark"): Promise<void>;
18
+ unmount(): void;
19
+ };
20
+ }, {
21
+ new (): {
22
+ mount<T extends HTMLElement>(_el: T, _theme: "light" | "dark"): Promise<void>;
23
+ unmount(): void;
24
+ #isMounted: boolean;
25
+ #dispose?: () => void;
26
+ #Component: any;
27
+ #ThemeProvider: any;
28
+ };
29
+ }];
30
+ export type ClassType = ReturnType<typeof constructCoreClass>[0];
@@ -0,0 +1,72 @@
1
+ import { createComponent, getNextElement, template, insert } from "solid-js/web";
2
+ var _tmpl$ = /* @__PURE__ */ template(`<div>`);
3
+ function constructCoreClass(Component) {
4
+ class DevtoolsCore {
5
+ #isMounted = false;
6
+ #dispose;
7
+ #Component;
8
+ #ThemeProvider;
9
+ constructor() {
10
+ }
11
+ async mount(el, theme) {
12
+ const {
13
+ lazy
14
+ } = await import("solid-js");
15
+ const {
16
+ render,
17
+ Portal
18
+ } = await import("solid-js/web");
19
+ if (this.#isMounted) {
20
+ throw new Error("Devtools is already mounted");
21
+ }
22
+ const mountTo = el;
23
+ const dispose = render(() => {
24
+ this.#Component = lazy(async () => ({
25
+ default: Component
26
+ }));
27
+ this.#ThemeProvider = lazy(() => import("@tanstack/devtools-ui").then((mod) => ({
28
+ default: mod.ThemeContextProvider
29
+ })));
30
+ const Devtools = this.#Component;
31
+ const ThemeProvider = this.#ThemeProvider;
32
+ return createComponent(Portal, {
33
+ mount: mountTo,
34
+ get children() {
35
+ var _el$ = getNextElement(_tmpl$);
36
+ _el$.style.setProperty("height", "100%");
37
+ insert(_el$, createComponent(ThemeProvider, {
38
+ theme,
39
+ get children() {
40
+ return createComponent(Devtools, {});
41
+ }
42
+ }));
43
+ return _el$;
44
+ }
45
+ });
46
+ }, mountTo);
47
+ this.#isMounted = true;
48
+ this.#dispose = dispose;
49
+ }
50
+ unmount() {
51
+ if (!this.#isMounted) {
52
+ throw new Error("Devtools is not mounted");
53
+ }
54
+ this.#dispose?.();
55
+ this.#isMounted = false;
56
+ }
57
+ }
58
+ class NoOpDevtoolsCore extends DevtoolsCore {
59
+ constructor() {
60
+ super();
61
+ }
62
+ async mount(_el, _theme) {
63
+ }
64
+ unmount() {
65
+ }
66
+ }
67
+ return [DevtoolsCore, NoOpDevtoolsCore];
68
+ }
69
+ export {
70
+ constructCoreClass
71
+ };
72
+ //# sourceMappingURL=class.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"class.js","sources":["../../../src/solid/class.tsx"],"sourcesContent":["/** @jsxImportSource solid-js - we use Solid.js as JSX here */\n\nimport type { JSX } from 'solid-js'\n\n/**\n * Constructs the core class for the Devtools.\n * This utility is used to construct a lazy loaded Solid component for the Devtools.\n * It returns a tuple containing the main DevtoolsCore class and a NoOpDevtoolsCore class.\n * The NoOpDevtoolsCore class is a no-op implementation that can be used for production if you want to explicitly exclude\n * the Devtools from your application.\n * @param importPath The path to the Solid component to be lazily imported\n * @returns Tuple containing the DevtoolsCore class and a NoOpDevtoolsCore class\n */\nexport function constructCoreClass(Component: () => JSX.Element) {\n class DevtoolsCore {\n #isMounted = false\n #dispose?: () => void\n #Component: any\n #ThemeProvider: any\n\n constructor() {}\n\n async mount<T extends HTMLElement>(el: T, theme: 'light' | 'dark') {\n const { lazy } = await import('solid-js')\n const { render, Portal } = await import('solid-js/web')\n if (this.#isMounted) {\n throw new Error('Devtools is already mounted')\n }\n const mountTo = el\n const dispose = render(() => {\n // eslint-disable-next-line @typescript-eslint/require-await\n this.#Component = lazy(async () => ({ default: Component }))\n\n this.#ThemeProvider = lazy(() =>\n import('@tanstack/devtools-ui').then((mod) => ({\n default: mod.ThemeContextProvider,\n })),\n )\n const Devtools = this.#Component\n const ThemeProvider = this.#ThemeProvider\n\n return (\n <Portal mount={mountTo}>\n <div style={{ height: '100%' }}>\n <ThemeProvider theme={theme}>\n <Devtools />\n </ThemeProvider>\n </div>\n </Portal>\n )\n }, mountTo)\n this.#isMounted = true\n this.#dispose = dispose\n }\n\n unmount() {\n if (!this.#isMounted) {\n throw new Error('Devtools is not mounted')\n }\n this.#dispose?.()\n this.#isMounted = false\n }\n }\n class NoOpDevtoolsCore extends DevtoolsCore {\n constructor() {\n super()\n }\n async mount<T extends HTMLElement>(_el: T, _theme: 'light' | 'dark') {}\n unmount() {}\n }\n return [DevtoolsCore, NoOpDevtoolsCore] as const\n}\n\nexport type ClassType = ReturnType<typeof constructCoreClass>[0]\n"],"names":["constructCoreClass","Component","DevtoolsCore","constructor","mount","el","theme","lazy","render","Portal","Error","mountTo","dispose","default","then","mod","ThemeContextProvider","Devtools","ThemeProvider","_$createComponent","children","_el$","_$getNextElement","_tmpl$","style","setProperty","_$insert","unmount","NoOpDevtoolsCore","_el","_theme"],"mappings":";;AAaO,SAASA,mBAAmBC,WAA8B;AAAA,EAC/D,MAAMC,aAAa;AAAA,IACjB,aAAa;AAAA,IACb;AAAA,IACA;AAAA,IACA;AAAA,IAEAC,cAAc;AAAA,IAAC;AAAA,IAEf,MAAMC,MAA6BC,IAAOC,OAAyB;AACjE,YAAM;AAAA,QAAEC;AAAAA,MAAAA,IAAS,MAAM,OAAO,UAAU;AACxC,YAAM;AAAA,QAAEC;AAAAA,QAAQC;AAAAA,MAAAA,IAAW,MAAM,OAAO,cAAc;AACtD,UAAI,KAAK,YAAY;AACnB,cAAM,IAAIC,MAAM,6BAA6B;AAAA,MAC/C;AACA,YAAMC,UAAUN;AAChB,YAAMO,UAAUJ,OAAO,MAAM;AAE3B,aAAK,aAAaD,KAAK,aAAa;AAAA,UAAEM,SAASZ;AAAAA,QAAAA,EAAY;AAE3D,aAAK,iBAAiBM,KAAK,MACzB,OAAO,uBAAuB,EAAEO,KAAMC,CAAAA,SAAS;AAAA,UAC7CF,SAASE,IAAIC;AAAAA,QAAAA,EACb,CACJ;AACA,cAAMC,WAAW,KAAK;AACtB,cAAMC,gBAAgB,KAAK;AAE3B,eAAAC,gBACGV,QAAM;AAAA,UAACL,OAAOO;AAAAA,UAAO,IAAAS,WAAA;AAAA,gBAAAC,OAAAC,eAAAC,MAAA;AAAAF,iBAAAG,MAAAC,YAAA,UAAA,MAAA;AAAAC,mBAAAL,MAAAF,gBAEjBD,eAAa;AAAA,cAACZ;AAAAA,cAAY,IAAAc,WAAA;AAAA,uBAAAD,gBACxBF,UAAQ,EAAA;AAAA,cAAA;AAAA,YAAA,CAAA,CAAA;AAAA,mBAAAI;AAAAA,UAAA;AAAA,QAAA,CAAA;AAAA,MAKnB,GAAGV,OAAO;AACV,WAAK,aAAa;AAClB,WAAK,WAAWC;AAAAA,IAClB;AAAA,IAEAe,UAAU;AACR,UAAI,CAAC,KAAK,YAAY;AACpB,cAAM,IAAIjB,MAAM,yBAAyB;AAAA,MAC3C;AACA,WAAK,WAAA;AACL,WAAK,aAAa;AAAA,IACpB;AAAA,EAAA;AAAA,EAEF,MAAMkB,yBAAyB1B,aAAa;AAAA,IAC1CC,cAAc;AACZ,YAAA;AAAA,IACF;AAAA,IACA,MAAMC,MAA6ByB,KAAQC,QAA0B;AAAA,IAAC;AAAA,IACtEH,UAAU;AAAA,IAAC;AAAA,EAAA;AAEb,SAAO,CAACzB,cAAc0B,gBAAgB;AACxC;"}
@@ -0,0 +1,3 @@
1
+ export * from './class.js';
2
+ export * from './panel.js';
3
+ export * from './plugin.js';
@@ -0,0 +1,9 @@
1
+ import { constructCoreClass } from "./class.js";
2
+ import { createSolidPanel } from "./panel.js";
3
+ import { createSolidPlugin } from "./plugin.js";
4
+ export {
5
+ constructCoreClass,
6
+ createSolidPanel,
7
+ createSolidPlugin
8
+ };
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
@@ -0,0 +1,5 @@
1
+ import { ClassType } from './class.js';
2
+ export interface DevtoolsPanelProps {
3
+ theme?: 'light' | 'dark';
4
+ }
5
+ export declare function createSolidPanel<TComponentProps extends DevtoolsPanelProps | undefined>(CoreClass: ClassType): readonly [(props: TComponentProps) => import("solid-js").JSX.Element, (_props: TComponentProps) => import("solid-js").JSX.Element];
@@ -0,0 +1,32 @@
1
+ import { getNextElement, template, use } from "solid-js/web";
2
+ import { onMount, onCleanup } from "solid-js";
3
+ var _tmpl$ = /* @__PURE__ */ template(`<div>`);
4
+ function createSolidPanel(CoreClass) {
5
+ function Panel(props) {
6
+ let devToolRef;
7
+ onMount(() => {
8
+ const devtools = new CoreClass();
9
+ if (devToolRef) {
10
+ devtools.mount(devToolRef, props?.theme ?? "dark");
11
+ onCleanup(() => {
12
+ devtools.unmount();
13
+ });
14
+ }
15
+ });
16
+ return (() => {
17
+ var _el$ = getNextElement(_tmpl$);
18
+ var _ref$ = devToolRef;
19
+ typeof _ref$ === "function" ? use(_ref$, _el$) : devToolRef = _el$;
20
+ _el$.style.setProperty("height", "100%");
21
+ return _el$;
22
+ })();
23
+ }
24
+ function NoOpPanel(_props) {
25
+ return [];
26
+ }
27
+ return [Panel, NoOpPanel];
28
+ }
29
+ export {
30
+ createSolidPanel
31
+ };
32
+ //# sourceMappingURL=panel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"panel.js","sources":["../../../src/solid/panel.tsx"],"sourcesContent":["/** @jsxImportSource solid-js - we use Solid.js as JSX here */\n\nimport { onCleanup, onMount } from 'solid-js'\nimport type { ClassType } from './class'\n\nexport interface DevtoolsPanelProps {\n theme?: 'light' | 'dark'\n}\n\nexport function createSolidPanel<\n TComponentProps extends DevtoolsPanelProps | undefined,\n>(CoreClass: ClassType) {\n function Panel(props: TComponentProps) {\n let devToolRef: HTMLDivElement | undefined\n\n onMount(() => {\n const devtools = new CoreClass()\n\n if (devToolRef) {\n devtools.mount(devToolRef, props?.theme ?? 'dark')\n\n onCleanup(() => {\n devtools.unmount()\n })\n }\n })\n\n return <div style={{ height: '100%' }} ref={devToolRef} />\n }\n\n function NoOpPanel(_props: TComponentProps) {\n return <></>\n }\n\n return [Panel, NoOpPanel] as const\n}\n"],"names":["createSolidPanel","CoreClass","Panel","props","devToolRef","onMount","devtools","mount","theme","onCleanup","unmount","_el$","_$getNextElement","_tmpl$","_ref$","_$use","style","setProperty","NoOpPanel","_props"],"mappings":";;;AASO,SAASA,iBAEdC,WAAsB;AACtB,WAASC,MAAMC,OAAwB;AACrC,QAAIC;AAEJC,YAAQ,MAAM;AACZ,YAAMC,WAAW,IAAIL,UAAAA;AAErB,UAAIG,YAAY;AACdE,iBAASC,MAAMH,YAAYD,OAAOK,SAAS,MAAM;AAEjDC,kBAAU,MAAM;AACdH,mBAASI,QAAAA;AAAAA,QACX,CAAC;AAAA,MACH;AAAA,IACF,CAAC;AAED,YAAA,MAAA;AAAA,UAAAC,OAAAC,eAAAC,MAAA;AAAA,UAAAC,QAA4CV;AAAU,aAAAU,UAAA,aAAAC,IAAAD,OAAAH,IAAA,IAAVP,aAAUO;AAAAA,WAAAK,MAAAC,YAAA,UAAA,MAAA;AAAA,aAAAN;AAAAA,IAAA,GAAA;AAAA,EACxD;AAEA,WAASO,UAAUC,QAAyB;AAC1C,WAAA,CAAA;AAAA,EACF;AAEA,SAAO,CAACjB,OAAOgB,SAAS;AAC1B;"}
@@ -0,0 +1,9 @@
1
+ import { JSX } from 'solid-js';
2
+ import { DevtoolsPanelProps } from './panel.js';
3
+ export declare function createSolidPlugin(name: string, Component: (props: DevtoolsPanelProps) => JSX.Element): readonly [() => {
4
+ name: string;
5
+ render: (_el: HTMLElement, theme: "light" | "dark") => JSX.Element;
6
+ }, () => {
7
+ name: string;
8
+ render: (_el: HTMLElement, _theme: "light" | "dark") => JSX.Element;
9
+ }];
@@ -0,0 +1,24 @@
1
+ import { createComponent } from "solid-js/web";
2
+ function createSolidPlugin(name, Component) {
3
+ function Plugin() {
4
+ return {
5
+ name,
6
+ render: (_el, theme) => {
7
+ return createComponent(Component, {
8
+ theme
9
+ });
10
+ }
11
+ };
12
+ }
13
+ function NoOpPlugin() {
14
+ return {
15
+ name,
16
+ render: (_el, _theme) => []
17
+ };
18
+ }
19
+ return [Plugin, NoOpPlugin];
20
+ }
21
+ export {
22
+ createSolidPlugin
23
+ };
24
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sources":["../../../src/solid/plugin.tsx"],"sourcesContent":["/** @jsxImportSource solid-js - we use Solid.js as JSX here */\n\nimport type { JSX } from 'solid-js'\nimport type { DevtoolsPanelProps } from './panel'\n\nexport function createSolidPlugin(\n name: string,\n Component: (props: DevtoolsPanelProps) => JSX.Element,\n) {\n function Plugin() {\n return {\n name: name,\n render: (_el: HTMLElement, theme: 'light' | 'dark') => {\n return <Component theme={theme} />\n },\n }\n }\n function NoOpPlugin() {\n return {\n name: name,\n render: (_el: HTMLElement, _theme: 'light' | 'dark') => <></>,\n }\n }\n return [Plugin, NoOpPlugin] as const\n}\n"],"names":["createSolidPlugin","name","Component","Plugin","render","_el","theme","_$createComponent","NoOpPlugin","_theme"],"mappings":";AAKO,SAASA,kBACdC,MACAC,WACA;AACA,WAASC,SAAS;AAChB,WAAO;AAAA,MACLF;AAAAA,MACAG,QAAQA,CAACC,KAAkBC,UAA4B;AACrD,eAAAC,gBAAQL,WAAS;AAAA,UAACI;AAAAA,QAAAA,CAAY;AAAA,MAChC;AAAA,IAAA;AAAA,EAEJ;AACA,WAASE,aAAa;AACpB,WAAO;AAAA,MACLP;AAAAA,MACAG,QAAQA,CAACC,KAAkBI,WAAwB,CAAA;AAAA,IAAA;AAAA,EAEvD;AACA,SAAO,CAACN,QAAQK,UAAU;AAC5B;"}
package/package.json ADDED
@@ -0,0 +1,76 @@
1
+ {
2
+ "name": "@tanstack/devtools-utils",
3
+ "version": "0.0.1",
4
+ "description": "TanStack Devtools utilities for creating your own devtools.",
5
+ "author": "Tanner Linsley",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/TanStack/devtools.git",
10
+ "directory": "packages/devtools"
11
+ },
12
+ "homepage": "https://tanstack.com/devtools",
13
+ "funding": {
14
+ "type": "github",
15
+ "url": "https://github.com/sponsors/tannerlinsley"
16
+ },
17
+ "keywords": [
18
+ "devtools"
19
+ ],
20
+ "type": "module",
21
+ "exports": {
22
+ "./react": {
23
+ "import": {
24
+ "types": "./dist/react/esm/index.d.ts",
25
+ "default": "./dist/react/esm/index.js"
26
+ }
27
+ },
28
+ "./solid": {
29
+ "import": {
30
+ "types": "./dist/solid/esm/index.d.ts",
31
+ "default": "./dist/solid/esm/index.js"
32
+ }
33
+ },
34
+ "./package.json": "./package.json"
35
+ },
36
+ "sideEffects": false,
37
+ "engines": {
38
+ "node": ">=18"
39
+ },
40
+ "dependencies": {
41
+ "@tanstack/devtools-ui": "^0.3.5"
42
+ },
43
+ "peerDependencies": {
44
+ "@types/react": ">=19.0.0",
45
+ "react": ">=19.0.0",
46
+ "solid-js": ">=1.9.7"
47
+ },
48
+ "peerDependenciesMeta": {
49
+ "react": {
50
+ "optional": true
51
+ },
52
+ "@types/react": {
53
+ "optional": true
54
+ },
55
+ "solid-js": {
56
+ "optional": true
57
+ }
58
+ },
59
+ "files": [
60
+ "dist/",
61
+ "src"
62
+ ],
63
+ "devDependencies": {
64
+ "vite-plugin-solid": "^2.11.8"
65
+ },
66
+ "scripts": {
67
+ "clean": "premove ./build ./dist",
68
+ "lint:fix": "eslint ./src --fix",
69
+ "test:eslint": "eslint ./src",
70
+ "test:lib": "vitest",
71
+ "test:lib:dev": "pnpm test:lib --watch",
72
+ "test:types": "tsc",
73
+ "test:build": "publint --strict",
74
+ "build": "vite build && vite build --config ./vite.config.solid.ts "
75
+ }
76
+ }
@@ -0,0 +1,2 @@
1
+ export * from './panel'
2
+ export * from './plugin'
@@ -0,0 +1,55 @@
1
+ import { useEffect, useRef } from 'react'
2
+
3
+ export interface DevtoolsPanelProps {
4
+ theme?: 'light' | 'dark'
5
+ }
6
+
7
+ /**
8
+ * Creates a React component that dynamically imports and mounts a devtools panel. SSR friendly.
9
+ * @param devtoolsPackageName The name of the devtools package to be imported, e.g., '@tanstack/devtools-react'
10
+ * @param importName The name of the export to be imported from the devtools package (e.g., 'default' or 'DevtoolsCore')
11
+ * @returns A React component that mounts the devtools
12
+ * @example
13
+ * ```tsx
14
+ * // if the export is default
15
+ * const [ReactDevtoolsPanel, NoOpReactDevtoolsPanel] = createReactPanel('@tanstack/devtools-react')
16
+ * ```
17
+ *
18
+ * @example
19
+ * ```tsx
20
+ * // if the export is named differently
21
+ * const [ReactDevtoolsPanel, NoOpReactDevtoolsPanel] = createReactPanel('@tanstack/devtools-react', 'DevtoolsCore')
22
+ * ```
23
+ */
24
+ export function createReactPanel<
25
+ TComponentProps extends DevtoolsPanelProps | undefined,
26
+ TCoreDevtoolsClass extends {
27
+ mount: (el: HTMLElement, theme: 'light' | 'dark') => void
28
+ unmount: () => void
29
+ },
30
+ >(CoreClass: new () => TCoreDevtoolsClass) {
31
+ function Panel(props: TComponentProps) {
32
+ const devToolRef = useRef<HTMLDivElement>(null)
33
+ const devtools = useRef<TCoreDevtoolsClass | null>(null)
34
+ useEffect(() => {
35
+ if (devtools.current) return
36
+
37
+ devtools.current = new CoreClass()
38
+
39
+ if (devToolRef.current) {
40
+ devtools.current.mount(devToolRef.current, props?.theme ?? 'dark')
41
+ }
42
+
43
+ return () => {
44
+ devtools.current?.unmount()
45
+ }
46
+ }, [props?.theme])
47
+
48
+ return <div style={{ height: '100%' }} ref={devToolRef} />
49
+ }
50
+
51
+ function NoOpPanel(_props: TComponentProps) {
52
+ return <></>
53
+ }
54
+ return [Panel, NoOpPanel] as const
55
+ }
@@ -0,0 +1,23 @@
1
+ import type { JSX } from 'react'
2
+ import type { DevtoolsPanelProps } from './panel'
3
+
4
+ export function createReactPlugin(
5
+ name: string,
6
+ Component: (props: DevtoolsPanelProps) => JSX.Element,
7
+ ) {
8
+ function Plugin() {
9
+ return {
10
+ name: name,
11
+ render: (_el: HTMLElement, theme: 'light' | 'dark') => (
12
+ <Component theme={theme} />
13
+ ),
14
+ }
15
+ }
16
+ function NoOpPlugin() {
17
+ return {
18
+ name: name,
19
+ render: (_el: HTMLElement, _theme: 'light' | 'dark') => <></>,
20
+ }
21
+ }
22
+ return [Plugin, NoOpPlugin] as const
23
+ }
@@ -0,0 +1,118 @@
1
+ /** @jsxImportSource solid-js - we use Solid.js as JSX here */
2
+ import { beforeEach, describe, expect, it, vi } from 'vitest'
3
+ import { constructCoreClass } from './class'
4
+
5
+ const lazyImportMock = vi.fn((fn) => fn())
6
+ const renderMock = vi.fn()
7
+ const portalMock = vi.fn((props: any) => <div>{props.children}</div>)
8
+
9
+ vi.mock('solid-js', async () => {
10
+ const actual = await vi.importActual<any>('solid-js')
11
+ return {
12
+ ...actual,
13
+ lazy: lazyImportMock,
14
+ }
15
+ })
16
+
17
+ vi.mock('solid-js/web', async () => {
18
+ const actual = await vi.importActual<any>('solid-js/web')
19
+ return {
20
+ ...actual,
21
+ render: renderMock,
22
+ Portal: portalMock,
23
+ }
24
+ })
25
+
26
+ describe('constructCoreClass', () => {
27
+ beforeEach(() => {
28
+ vi.clearAllMocks()
29
+ })
30
+ it('should export DevtoolsCore and NoOpDevtoolsCore classes and make no calls to Solid.js primitives', () => {
31
+ const [DevtoolsCore, NoOpDevtoolsCore] = constructCoreClass(() => (
32
+ <div>Test Component</div>
33
+ ))
34
+ expect(DevtoolsCore).toBeDefined()
35
+ expect(NoOpDevtoolsCore).toBeDefined()
36
+ expect(lazyImportMock).not.toHaveBeenCalled()
37
+ })
38
+
39
+ it('DevtoolsCore should call solid primitives when mount is called', async () => {
40
+ const [DevtoolsCore, _] = constructCoreClass(() => (
41
+ <div>Test Component</div>
42
+ ))
43
+ const instance = new DevtoolsCore()
44
+ await instance.mount(document.createElement('div'), 'dark')
45
+ expect(renderMock).toHaveBeenCalled()
46
+ })
47
+
48
+ it('DevtoolsCore should throw if mount is called twice without unmounting', async () => {
49
+ const [DevtoolsCore, _] = constructCoreClass(() => (
50
+ <div>Test Component</div>
51
+ ))
52
+ const instance = new DevtoolsCore()
53
+ await instance.mount(document.createElement('div'), 'dark')
54
+ await expect(
55
+ instance.mount(document.createElement('div'), 'dark'),
56
+ ).rejects.toThrow('Devtools is already mounted')
57
+ })
58
+
59
+ it('DevtoolsCore should throw if unmount is called before mount', () => {
60
+ const [DevtoolsCore, _] = constructCoreClass(() => (
61
+ <div>Test Component</div>
62
+ ))
63
+ const instance = new DevtoolsCore()
64
+ expect(() => instance.unmount()).toThrow('Devtools is not mounted')
65
+ })
66
+
67
+ it('DevtoolsCore should allow mount after unmount', async () => {
68
+ const [DevtoolsCore, _] = constructCoreClass(() => (
69
+ <div>Test Component</div>
70
+ ))
71
+ const instance = new DevtoolsCore()
72
+ await instance.mount(document.createElement('div'), 'dark')
73
+ instance.unmount()
74
+ await expect(
75
+ instance.mount(document.createElement('div'), 'dark'),
76
+ ).resolves.not.toThrow()
77
+ })
78
+
79
+ it('NoOpDevtoolsCore should not call any solid primitives when mount is called', async () => {
80
+ const [_, NoOpDevtoolsCore] = constructCoreClass(() => (
81
+ <div>Test Component</div>
82
+ ))
83
+ const noOpInstance = new NoOpDevtoolsCore()
84
+ await noOpInstance.mount(document.createElement('div'), 'dark')
85
+
86
+ expect(lazyImportMock).not.toHaveBeenCalled()
87
+ expect(renderMock).not.toHaveBeenCalled()
88
+ expect(portalMock).not.toHaveBeenCalled()
89
+ })
90
+
91
+ it('NoOpDevtoolsCore should not throw if mount is called multiple times', async () => {
92
+ const [_, NoOpDevtoolsCore] = constructCoreClass(() => (
93
+ <div>Test Component</div>
94
+ ))
95
+ const noOpInstance = new NoOpDevtoolsCore()
96
+ await noOpInstance.mount(document.createElement('div'), 'dark')
97
+ await expect(
98
+ noOpInstance.mount(document.createElement('div'), 'dark'),
99
+ ).resolves.not.toThrow()
100
+ })
101
+
102
+ it('NoOpDevtoolsCore should not throw if unmount is called before mount', () => {
103
+ const [_, NoOpDevtoolsCore] = constructCoreClass(() => (
104
+ <div>Test Component</div>
105
+ ))
106
+ const noOpInstance = new NoOpDevtoolsCore()
107
+ expect(() => noOpInstance.unmount()).not.toThrow()
108
+ })
109
+
110
+ it('NoOpDevtoolsCore should not throw if unmount is called after mount', async () => {
111
+ const [_, NoOpDevtoolsCore] = constructCoreClass(() => (
112
+ <div>Test Component</div>
113
+ ))
114
+ const noOpInstance = new NoOpDevtoolsCore()
115
+ await noOpInstance.mount(document.createElement('div'), 'dark')
116
+ expect(() => noOpInstance.unmount()).not.toThrow()
117
+ })
118
+ })
@@ -0,0 +1,74 @@
1
+ /** @jsxImportSource solid-js - we use Solid.js as JSX here */
2
+
3
+ import type { JSX } from 'solid-js'
4
+
5
+ /**
6
+ * Constructs the core class for the Devtools.
7
+ * This utility is used to construct a lazy loaded Solid component for the Devtools.
8
+ * It returns a tuple containing the main DevtoolsCore class and a NoOpDevtoolsCore class.
9
+ * The NoOpDevtoolsCore class is a no-op implementation that can be used for production if you want to explicitly exclude
10
+ * the Devtools from your application.
11
+ * @param importPath The path to the Solid component to be lazily imported
12
+ * @returns Tuple containing the DevtoolsCore class and a NoOpDevtoolsCore class
13
+ */
14
+ export function constructCoreClass(Component: () => JSX.Element) {
15
+ class DevtoolsCore {
16
+ #isMounted = false
17
+ #dispose?: () => void
18
+ #Component: any
19
+ #ThemeProvider: any
20
+
21
+ constructor() {}
22
+
23
+ async mount<T extends HTMLElement>(el: T, theme: 'light' | 'dark') {
24
+ const { lazy } = await import('solid-js')
25
+ const { render, Portal } = await import('solid-js/web')
26
+ if (this.#isMounted) {
27
+ throw new Error('Devtools is already mounted')
28
+ }
29
+ const mountTo = el
30
+ const dispose = render(() => {
31
+ // eslint-disable-next-line @typescript-eslint/require-await
32
+ this.#Component = lazy(async () => ({ default: Component }))
33
+
34
+ this.#ThemeProvider = lazy(() =>
35
+ import('@tanstack/devtools-ui').then((mod) => ({
36
+ default: mod.ThemeContextProvider,
37
+ })),
38
+ )
39
+ const Devtools = this.#Component
40
+ const ThemeProvider = this.#ThemeProvider
41
+
42
+ return (
43
+ <Portal mount={mountTo}>
44
+ <div style={{ height: '100%' }}>
45
+ <ThemeProvider theme={theme}>
46
+ <Devtools />
47
+ </ThemeProvider>
48
+ </div>
49
+ </Portal>
50
+ )
51
+ }, mountTo)
52
+ this.#isMounted = true
53
+ this.#dispose = dispose
54
+ }
55
+
56
+ unmount() {
57
+ if (!this.#isMounted) {
58
+ throw new Error('Devtools is not mounted')
59
+ }
60
+ this.#dispose?.()
61
+ this.#isMounted = false
62
+ }
63
+ }
64
+ class NoOpDevtoolsCore extends DevtoolsCore {
65
+ constructor() {
66
+ super()
67
+ }
68
+ async mount<T extends HTMLElement>(_el: T, _theme: 'light' | 'dark') {}
69
+ unmount() {}
70
+ }
71
+ return [DevtoolsCore, NoOpDevtoolsCore] as const
72
+ }
73
+
74
+ export type ClassType = ReturnType<typeof constructCoreClass>[0]
@@ -0,0 +1,3 @@
1
+ export * from './class'
2
+ export * from './panel'
3
+ export * from './plugin'
@@ -0,0 +1,36 @@
1
+ /** @jsxImportSource solid-js - we use Solid.js as JSX here */
2
+
3
+ import { onCleanup, onMount } from 'solid-js'
4
+ import type { ClassType } from './class'
5
+
6
+ export interface DevtoolsPanelProps {
7
+ theme?: 'light' | 'dark'
8
+ }
9
+
10
+ export function createSolidPanel<
11
+ TComponentProps extends DevtoolsPanelProps | undefined,
12
+ >(CoreClass: ClassType) {
13
+ function Panel(props: TComponentProps) {
14
+ let devToolRef: HTMLDivElement | undefined
15
+
16
+ onMount(() => {
17
+ const devtools = new CoreClass()
18
+
19
+ if (devToolRef) {
20
+ devtools.mount(devToolRef, props?.theme ?? 'dark')
21
+
22
+ onCleanup(() => {
23
+ devtools.unmount()
24
+ })
25
+ }
26
+ })
27
+
28
+ return <div style={{ height: '100%' }} ref={devToolRef} />
29
+ }
30
+
31
+ function NoOpPanel(_props: TComponentProps) {
32
+ return <></>
33
+ }
34
+
35
+ return [Panel, NoOpPanel] as const
36
+ }
@@ -0,0 +1,25 @@
1
+ /** @jsxImportSource solid-js - we use Solid.js as JSX here */
2
+
3
+ import type { JSX } from 'solid-js'
4
+ import type { DevtoolsPanelProps } from './panel'
5
+
6
+ export function createSolidPlugin(
7
+ name: string,
8
+ Component: (props: DevtoolsPanelProps) => JSX.Element,
9
+ ) {
10
+ function Plugin() {
11
+ return {
12
+ name: name,
13
+ render: (_el: HTMLElement, theme: 'light' | 'dark') => {
14
+ return <Component theme={theme} />
15
+ },
16
+ }
17
+ }
18
+ function NoOpPlugin() {
19
+ return {
20
+ name: name,
21
+ render: (_el: HTMLElement, _theme: 'light' | 'dark') => <></>,
22
+ }
23
+ }
24
+ return [Plugin, NoOpPlugin] as const
25
+ }