@tanstack/react-devtools 0.9.13 → 0.10.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.
- package/dist/esm/devtools.d.ts +3 -3
- package/dist/esm/devtools.js +76 -103
- package/dist/esm/devtools.js.map +1 -1
- package/dist/esm/index.js +7 -5
- package/dist/esm/index.js.map +1 -1
- package/package.json +3 -3
- package/src/devtools.tsx +8 -6
package/dist/esm/devtools.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { JSX, ReactElement } from 'react';
|
|
2
|
-
import { ClientEventBusConfig, TanStackDevtoolsConfig, TanStackDevtoolsPlugin } from '@tanstack/devtools';
|
|
3
|
-
type PluginRender = JSX.Element | ((el: HTMLElement,
|
|
2
|
+
import { ClientEventBusConfig, TanStackDevtoolsConfig, TanStackDevtoolsPlugin, TanStackDevtoolsPluginProps, TanStackDevtoolsTheme } from '@tanstack/devtools';
|
|
3
|
+
type PluginRender = JSX.Element | ((el: HTMLElement, props: TanStackDevtoolsPluginProps) => JSX.Element);
|
|
4
4
|
type TriggerProps = {
|
|
5
|
-
theme:
|
|
5
|
+
theme: TanStackDevtoolsTheme;
|
|
6
6
|
};
|
|
7
7
|
type TriggerRender = JSX.Element | ((el: HTMLElement, props: TriggerProps) => JSX.Element);
|
|
8
8
|
export type TanStackDevtoolsReactPlugin = Omit<TanStackDevtoolsPlugin, 'render' | 'name'> & {
|
package/dist/esm/devtools.js
CHANGED
|
@@ -1,108 +1,81 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useRef, useState, useMemo, useEffect } from "react";
|
|
1
|
+
import { useEffect, useMemo, useRef, useState } from "react";
|
|
3
2
|
import { TanStackDevtoolsCore } from "@tanstack/devtools";
|
|
4
3
|
import { createPortal } from "react-dom";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
//#region src/devtools.tsx
|
|
6
|
+
var convertRender = (Component, setComponents, e, props) => {
|
|
7
|
+
const element = typeof Component === "function" ? Component(e, props) : Component;
|
|
8
|
+
setComponents((prev) => ({
|
|
9
|
+
...prev,
|
|
10
|
+
[e.getAttribute("id")]: element
|
|
11
|
+
}));
|
|
11
12
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
setComponent(element);
|
|
13
|
+
var convertTrigger = (Component, setComponent, e, props) => {
|
|
14
|
+
setComponent(typeof Component === "function" ? Component(e, props) : Component);
|
|
15
15
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
eventBusConfig,
|
|
78
|
-
plugins: pluginsMap
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
useEffect(() => {
|
|
82
|
-
devtools.setConfig({
|
|
83
|
-
plugins: pluginsMap
|
|
84
|
-
});
|
|
85
|
-
}, [devtools, pluginsMap]);
|
|
86
|
-
useEffect(() => {
|
|
87
|
-
if (devToolRef.current) {
|
|
88
|
-
devtools.mount(devToolRef.current);
|
|
89
|
-
}
|
|
90
|
-
return () => devtools.unmount();
|
|
91
|
-
}, [devtools]);
|
|
92
|
-
const hasPlugins = Object.values(pluginContainers).length > 0 && Object.values(PluginComponents).length > 0;
|
|
93
|
-
const hasTitles = Object.values(titleContainers).length > 0 && Object.values(TitleComponents).length > 0;
|
|
94
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
95
|
-
/* @__PURE__ */ jsx("div", { style: { position: "absolute" }, ref: devToolRef }),
|
|
96
|
-
hasPlugins ? Object.entries(pluginContainers).map(
|
|
97
|
-
([key, pluginContainer]) => createPortal(/* @__PURE__ */ jsx(Fragment, { children: PluginComponents[key] }), pluginContainer)
|
|
98
|
-
) : null,
|
|
99
|
-
hasTitles ? Object.entries(titleContainers).map(
|
|
100
|
-
([key, titleContainer]) => createPortal(/* @__PURE__ */ jsx(Fragment, { children: TitleComponents[key] }), titleContainer)
|
|
101
|
-
) : null,
|
|
102
|
-
triggerContainer && TriggerComponent ? createPortal(/* @__PURE__ */ jsx(Fragment, { children: TriggerComponent }), triggerContainer) : null
|
|
103
|
-
] });
|
|
16
|
+
var TanStackDevtools = ({ plugins, config, eventBusConfig }) => {
|
|
17
|
+
const devToolRef = useRef(null);
|
|
18
|
+
const [pluginContainers, setPluginContainers] = useState({});
|
|
19
|
+
const [titleContainers, setTitleContainers] = useState({});
|
|
20
|
+
const [triggerContainer, setTriggerContainer] = useState(null);
|
|
21
|
+
const [PluginComponents, setPluginComponents] = useState({});
|
|
22
|
+
const [TitleComponents, setTitleComponents] = useState({});
|
|
23
|
+
const [TriggerComponent, setTriggerComponent] = useState(null);
|
|
24
|
+
const pluginsMap = useMemo(() => plugins?.map((plugin) => {
|
|
25
|
+
return {
|
|
26
|
+
...plugin,
|
|
27
|
+
name: typeof plugin.name === "string" ? plugin.name : (e, props) => {
|
|
28
|
+
const id = e.getAttribute("id");
|
|
29
|
+
if (e.ownerDocument.getElementById(id)) setTitleContainers((prev) => ({
|
|
30
|
+
...prev,
|
|
31
|
+
[id]: e
|
|
32
|
+
}));
|
|
33
|
+
convertRender(plugin.name, setTitleComponents, e, props);
|
|
34
|
+
},
|
|
35
|
+
render: (e, theme) => {
|
|
36
|
+
const id = e.getAttribute("id");
|
|
37
|
+
if (e.ownerDocument.getElementById(id)) setPluginContainers((prev) => ({
|
|
38
|
+
...prev,
|
|
39
|
+
[id]: e
|
|
40
|
+
}));
|
|
41
|
+
convertRender(plugin.render, setPluginComponents, e, theme);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}) ?? [], [plugins]);
|
|
45
|
+
const [devtools] = useState(() => {
|
|
46
|
+
const { customTrigger, ...coreConfig } = config || {};
|
|
47
|
+
return new TanStackDevtoolsCore({
|
|
48
|
+
config: {
|
|
49
|
+
...coreConfig,
|
|
50
|
+
customTrigger: customTrigger ? (el, props) => {
|
|
51
|
+
setTriggerContainer(el);
|
|
52
|
+
convertTrigger(customTrigger, setTriggerComponent, el, props);
|
|
53
|
+
} : void 0
|
|
54
|
+
},
|
|
55
|
+
eventBusConfig,
|
|
56
|
+
plugins: pluginsMap
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
devtools.setConfig({ plugins: pluginsMap });
|
|
61
|
+
}, [devtools, pluginsMap]);
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
if (devToolRef.current) devtools.mount(devToolRef.current);
|
|
64
|
+
return () => devtools.unmount();
|
|
65
|
+
}, [devtools]);
|
|
66
|
+
const hasPlugins = Object.values(pluginContainers).length > 0 && Object.values(PluginComponents).length > 0;
|
|
67
|
+
const hasTitles = Object.values(titleContainers).length > 0 && Object.values(TitleComponents).length > 0;
|
|
68
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
69
|
+
/* @__PURE__ */ jsx("div", {
|
|
70
|
+
style: { position: "absolute" },
|
|
71
|
+
ref: devToolRef
|
|
72
|
+
}),
|
|
73
|
+
hasPlugins ? Object.entries(pluginContainers).map(([key, pluginContainer]) => createPortal(/* @__PURE__ */ jsx(Fragment, { children: PluginComponents[key] }), pluginContainer)) : null,
|
|
74
|
+
hasTitles ? Object.entries(titleContainers).map(([key, titleContainer]) => createPortal(/* @__PURE__ */ jsx(Fragment, { children: TitleComponents[key] }), titleContainer)) : null,
|
|
75
|
+
triggerContainer && TriggerComponent ? createPortal(/* @__PURE__ */ jsx(Fragment, { children: TriggerComponent }), triggerContainer) : null
|
|
76
|
+
] });
|
|
104
77
|
};
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
//# sourceMappingURL=devtools.js.map
|
|
78
|
+
//#endregion
|
|
79
|
+
export { TanStackDevtools };
|
|
80
|
+
|
|
81
|
+
//# sourceMappingURL=devtools.js.map
|
package/dist/esm/devtools.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devtools.js","sources":["../../src/devtools.tsx"],"sourcesContent":["import React, { useEffect, useMemo, useRef, useState } from 'react'\nimport { TanStackDevtoolsCore } from '@tanstack/devtools'\nimport { createPortal } from 'react-dom'\nimport type { JSX, ReactElement } from 'react'\nimport type {\n ClientEventBusConfig,\n TanStackDevtoolsConfig,\n TanStackDevtoolsPlugin,\n} from '@tanstack/devtools'\n\ntype PluginRender =\n | JSX.Element\n | ((el: HTMLElement, theme: 'dark' | 'light') => JSX.Element)\n\ntype TriggerProps = {\n theme: 'dark' | 'light'\n}\n\ntype TriggerRender =\n | JSX.Element\n | ((el: HTMLElement, props: TriggerProps) => JSX.Element)\n\nexport type TanStackDevtoolsReactPlugin = Omit<\n TanStackDevtoolsPlugin,\n 'render' | 'name'\n> & {\n /**\n * The render function can be a React element or a function that returns a React element.\n * If it's a function, it will be called to render the plugin, otherwise it will be rendered directly.\n *\n * Example:\n * ```jsx\n * {\n * render: () => <CustomPluginComponent />,\n * }\n * ```\n * or\n * ```jsx\n * {\n * render: <CustomPluginComponent />,\n * }\n * ```\n */\n render: PluginRender\n /**\n * Name to be displayed in the devtools UI.\n * If a string, it will be used as the plugin name.\n * If a function, it will be called with the mount element.\n *\n * Example:\n * ```jsx\n * {\n * name: \"Your Plugin\",\n * render: () => <CustomPluginComponent />,\n * }\n * ```\n * or\n * ```jsx\n * {\n * name: <h1>Your Plugin title</h1>,\n * render: () => <CustomPluginComponent />,\n * }\n * ```\n */\n name: string | PluginRender\n}\n\ntype TanStackDevtoolsReactConfig = Omit<\n Partial<TanStackDevtoolsConfig>,\n 'customTrigger'\n> & {\n /**\n * Optional custom trigger component for the devtools.\n * It can be a React element or a function that renders one.\n *\n * Example:\n * ```jsx\n * {\n * customTrigger: <CustomTriggerComponent />,\n * }\n * ```\n */\n customTrigger?: TriggerRender\n}\n\nexport interface TanStackDevtoolsReactInit {\n /**\n * Array of plugins to be used in the devtools.\n * Each plugin should have a `render` function that returns a React element or a function\n *\n * Example:\n * ```jsx\n * <TanStackDevtools\n * plugins={[\n * {\n * id: \"your-plugin-id\",\n * name: \"Your Plugin\",\n * render: <CustomPluginComponent />,\n * }\n * ]}\n * />\n * ```\n */\n plugins?: Array<TanStackDevtoolsReactPlugin>\n /**\n * Configuration for the devtools shell. These configuration options are used to set the\n * initial state of the devtools when it is started for the first time. Afterwards,\n * the settings are persisted in local storage and changed through the settings panel.\n */\n config?: TanStackDevtoolsReactConfig\n /**\n * Configuration for the TanStack Devtools client event bus.\n */\n eventBusConfig?: ClientEventBusConfig\n}\n\nconst convertRender = (\n Component: PluginRender,\n setComponents: React.Dispatch<\n React.SetStateAction<Record<string, JSX.Element>>\n >,\n e: HTMLElement,\n theme: 'dark' | 'light',\n) => {\n const element =\n typeof Component === 'function' ? Component(e, theme) : Component\n\n setComponents((prev) => ({\n ...prev,\n [e.getAttribute('id') as string]: element,\n }))\n}\n\nconst convertTrigger = (\n Component: TriggerRender,\n setComponent: React.Dispatch<React.SetStateAction<JSX.Element | null>>,\n e: HTMLElement,\n props: TriggerProps,\n) => {\n const element =\n typeof Component === 'function' ? Component(e, props) : Component\n setComponent(element)\n}\n\nexport const TanStackDevtools = ({\n plugins,\n config,\n eventBusConfig,\n}: TanStackDevtoolsReactInit): ReactElement | null => {\n const devToolRef = useRef<HTMLDivElement>(null)\n\n const [pluginContainers, setPluginContainers] = useState<\n Record<string, HTMLElement>\n >({})\n const [titleContainers, setTitleContainers] = useState<\n Record<string, HTMLElement>\n >({})\n const [triggerContainer, setTriggerContainer] = useState<HTMLElement | null>(\n null,\n )\n\n const [PluginComponents, setPluginComponents] = useState<\n Record<string, JSX.Element>\n >({})\n const [TitleComponents, setTitleComponents] = useState<\n Record<string, JSX.Element>\n >({})\n const [TriggerComponent, setTriggerComponent] = useState<JSX.Element | null>(\n null,\n )\n\n const pluginsMap: Array<TanStackDevtoolsPlugin> = useMemo(\n () =>\n plugins?.map((plugin) => {\n return {\n ...plugin,\n name:\n typeof plugin.name === 'string'\n ? plugin.name\n : (e, theme) => {\n const id = e.getAttribute('id')!\n const target = e.ownerDocument.getElementById(id)\n\n if (target) {\n setTitleContainers((prev) => ({\n ...prev,\n [id]: e,\n }))\n }\n\n convertRender(\n plugin.name as PluginRender,\n setTitleComponents,\n e,\n theme,\n )\n },\n render: (e, theme) => {\n const id = e.getAttribute('id')!\n const target = e.ownerDocument.getElementById(id)\n\n if (target) {\n setPluginContainers((prev) => ({\n ...prev,\n [id]: e,\n }))\n }\n\n convertRender(plugin.render, setPluginComponents, e, theme)\n },\n }\n }) ?? [],\n [plugins],\n )\n\n const [devtools] = useState(() => {\n const { customTrigger, ...coreConfig } = config || {}\n return new TanStackDevtoolsCore({\n config: {\n ...coreConfig,\n customTrigger: customTrigger\n ? (el, props) => {\n setTriggerContainer(el)\n convertTrigger(customTrigger, setTriggerComponent, el, props)\n }\n : undefined,\n },\n eventBusConfig,\n plugins: pluginsMap,\n })\n })\n\n useEffect(() => {\n devtools.setConfig({\n plugins: pluginsMap,\n })\n }, [devtools, pluginsMap])\n\n useEffect(() => {\n if (devToolRef.current) {\n devtools.mount(devToolRef.current)\n }\n\n return () => devtools.unmount()\n }, [devtools])\n\n const hasPlugins =\n Object.values(pluginContainers).length > 0 &&\n Object.values(PluginComponents).length > 0\n const hasTitles =\n Object.values(titleContainers).length > 0 &&\n Object.values(TitleComponents).length > 0\n\n return (\n <>\n <div style={{ position: 'absolute' }} ref={devToolRef} />\n\n {hasPlugins\n ? Object.entries(pluginContainers).map(([key, pluginContainer]) =>\n createPortal(<>{PluginComponents[key]}</>, pluginContainer),\n )\n : null}\n\n {hasTitles\n ? Object.entries(titleContainers).map(([key, titleContainer]) =>\n createPortal(<>{TitleComponents[key]}</>, titleContainer),\n )\n : null}\n\n {triggerContainer && TriggerComponent\n ? createPortal(<>{TriggerComponent}</>, triggerContainer)\n : null}\n </>\n )\n}\n"],"names":[],"mappings":";;;;AAoHA,MAAM,gBAAgB,CACpB,WACA,eAGA,GACA,UACG;AACH,QAAM,UACJ,OAAO,cAAc,aAAa,UAAU,GAAG,KAAK,IAAI;AAE1D,gBAAc,CAAC,UAAU;AAAA,IACvB,GAAG;AAAA,IACH,CAAC,EAAE,aAAa,IAAI,CAAW,GAAG;AAAA,EAAA,EAClC;AACJ;AAEA,MAAM,iBAAiB,CACrB,WACA,cACA,GACA,UACG;AACH,QAAM,UACJ,OAAO,cAAc,aAAa,UAAU,GAAG,KAAK,IAAI;AAC1D,eAAa,OAAO;AACtB;AAEO,MAAM,mBAAmB,CAAC;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AACF,MAAsD;AACpD,QAAM,aAAa,OAAuB,IAAI;AAE9C,QAAM,CAAC,kBAAkB,mBAAmB,IAAI,SAE9C,CAAA,CAAE;AACJ,QAAM,CAAC,iBAAiB,kBAAkB,IAAI,SAE5C,CAAA,CAAE;AACJ,QAAM,CAAC,kBAAkB,mBAAmB,IAAI;AAAA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ef, useState } from 'react'\nimport { TanStackDevtoolsCore } from '@tanstack/devtools'\nimport { createPortal } from 'react-dom'\nimport type { JSX, ReactElement } from 'react'\nimport type {\n ClientEventBusConfig,\n TanStackDevtoolsConfig,\n TanStackDevtoolsPlugin,\n TanStackDevtoolsPluginProps,\n TanStackDevtoolsTheme,\n} from '@tanstack/devtools'\n\ntype PluginRender =\n | JSX.Element\n | ((el: HTMLElement, props: TanStackDevtoolsPluginProps) => JSX.Element)\n\ntype TriggerProps = {\n theme: TanStackDevtoolsTheme\n}\n\ntype TriggerRender =\n | JSX.Element\n | ((el: HTMLElement, props: TriggerProps) => JSX.Element)\n\nexport type TanStackDevtoolsReactPlugin = Omit<\n TanStackDevtoolsPlugin,\n 'render' | 'name'\n> & {\n /**\n * The render function can be a React element or a function that returns a React element.\n * If it's a function, it will be called to render the plugin, otherwise it will be rendered directly.\n *\n * Example:\n * ```jsx\n * {\n * render: () => <CustomPluginComponent />,\n * }\n * ```\n * or\n * ```jsx\n * {\n * render: <CustomPluginComponent />,\n * }\n * ```\n */\n render: PluginRender\n /**\n * Name to be displayed in the devtools UI.\n * If a string, it will be used as the plugin name.\n * If a function, it will be called with the mount element.\n *\n * Example:\n * ```jsx\n * {\n * name: \"Your Plugin\",\n * render: () => <CustomPluginComponent />,\n * }\n * ```\n * or\n * ```jsx\n * {\n * name: <h1>Your Plugin title</h1>,\n * render: () => <CustomPluginComponent />,\n * }\n * ```\n */\n name: string | PluginRender\n}\n\ntype TanStackDevtoolsReactConfig = Omit<\n Partial<TanStackDevtoolsConfig>,\n 'customTrigger'\n> & {\n /**\n * Optional custom trigger component for the devtools.\n * It can be a React element or a function that renders one.\n *\n * Example:\n * ```jsx\n * {\n * customTrigger: <CustomTriggerComponent />,\n * }\n * ```\n */\n customTrigger?: TriggerRender\n}\n\nexport interface TanStackDevtoolsReactInit {\n /**\n * Array of plugins to be used in the devtools.\n * Each plugin should have a `render` function that returns a React element or a function\n *\n * Example:\n * ```jsx\n * <TanStackDevtools\n * plugins={[\n * {\n * id: \"your-plugin-id\",\n * name: \"Your Plugin\",\n * render: <CustomPluginComponent />,\n * }\n * ]}\n * />\n * ```\n */\n plugins?: Array<TanStackDevtoolsReactPlugin>\n /**\n * Configuration for the devtools shell. These configuration options are used to set the\n * initial state of the devtools when it is started for the first time. Afterwards,\n * the settings are persisted in local storage and changed through the settings panel.\n */\n config?: TanStackDevtoolsReactConfig\n /**\n * Configuration for the TanStack Devtools client event bus.\n */\n eventBusConfig?: ClientEventBusConfig\n}\n\nconst convertRender = (\n Component: PluginRender,\n setComponents: React.Dispatch<\n React.SetStateAction<Record<string, JSX.Element>>\n >,\n e: HTMLElement,\n props: TanStackDevtoolsPluginProps,\n) => {\n const element =\n typeof Component === 'function' ? Component(e, props) : Component\n\n setComponents((prev) => ({\n ...prev,\n [e.getAttribute('id') as string]: element,\n }))\n}\n\nconst convertTrigger = (\n Component: TriggerRender,\n setComponent: React.Dispatch<React.SetStateAction<JSX.Element | null>>,\n e: HTMLElement,\n props: TriggerProps,\n) => {\n const element =\n typeof Component === 'function' ? Component(e, props) : Component\n setComponent(element)\n}\n\nexport const TanStackDevtools = ({\n plugins,\n config,\n eventBusConfig,\n}: TanStackDevtoolsReactInit): ReactElement | null => {\n const devToolRef = useRef<HTMLDivElement>(null)\n\n const [pluginContainers, setPluginContainers] = useState<\n Record<string, HTMLElement>\n >({})\n const [titleContainers, setTitleContainers] = useState<\n Record<string, HTMLElement>\n >({})\n const [triggerContainer, setTriggerContainer] = useState<HTMLElement | null>(\n null,\n )\n\n const [PluginComponents, setPluginComponents] = useState<\n Record<string, JSX.Element>\n >({})\n const [TitleComponents, setTitleComponents] = useState<\n Record<string, JSX.Element>\n >({})\n const [TriggerComponent, setTriggerComponent] = useState<JSX.Element | null>(\n null,\n )\n\n const pluginsMap: Array<TanStackDevtoolsPlugin> = useMemo(\n () =>\n plugins?.map((plugin) => {\n return {\n ...plugin,\n name:\n typeof plugin.name === 'string'\n ? plugin.name\n : (e, props) => {\n const id = e.getAttribute('id')!\n const target = e.ownerDocument.getElementById(id)\n\n if (target) {\n setTitleContainers((prev) => ({\n ...prev,\n [id]: e,\n }))\n }\n\n convertRender(\n plugin.name as PluginRender,\n setTitleComponents,\n e,\n props,\n )\n },\n render: (e, theme) => {\n const id = e.getAttribute('id')!\n const target = e.ownerDocument.getElementById(id)\n\n if (target) {\n setPluginContainers((prev) => ({\n ...prev,\n [id]: e,\n }))\n }\n\n convertRender(plugin.render, setPluginComponents, e, theme)\n },\n }\n }) ?? [],\n [plugins],\n )\n\n const [devtools] = useState(() => {\n const { customTrigger, ...coreConfig } = config || {}\n return new TanStackDevtoolsCore({\n config: {\n ...coreConfig,\n customTrigger: customTrigger\n ? (el, props) => {\n setTriggerContainer(el)\n convertTrigger(customTrigger, setTriggerComponent, el, props)\n }\n : undefined,\n },\n eventBusConfig,\n plugins: pluginsMap,\n })\n })\n\n useEffect(() => {\n devtools.setConfig({\n plugins: pluginsMap,\n })\n }, [devtools, pluginsMap])\n\n useEffect(() => {\n if (devToolRef.current) {\n devtools.mount(devToolRef.current)\n }\n\n return () => devtools.unmount()\n }, [devtools])\n\n const hasPlugins =\n Object.values(pluginContainers).length > 0 &&\n Object.values(PluginComponents).length > 0\n const hasTitles =\n Object.values(titleContainers).length > 0 &&\n Object.values(TitleComponents).length > 0\n\n return (\n <>\n <div style={{ position: 'absolute' }} ref={devToolRef} />\n\n {hasPlugins\n ? Object.entries(pluginContainers).map(([key, pluginContainer]) =>\n createPortal(<>{PluginComponents[key]}</>, pluginContainer),\n )\n : null}\n\n {hasTitles\n ? Object.entries(titleContainers).map(([key, titleContainer]) =>\n createPortal(<>{TitleComponents[key]}</>, titleContainer),\n )\n : null}\n\n {triggerContainer && TriggerComponent\n ? createPortal(<>{TriggerComponent}</>, triggerContainer)\n : null}\n </>\n )\n}\n"],"mappings":";;;;;AAsHA,IAAM,iBACJ,WACA,eAGA,GACA,UACG;CACH,MAAM,UACJ,OAAO,cAAc,aAAa,UAAU,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
+
//#region src/index.ts
|
|
5
|
+
var TanStackDevtools = TanStackDevtools$1;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { TanStackDevtools };
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["'use client'\n\nimport * as Devtools from './devtools'\n\nexport const TanStackDevtools = Devtools.TanStackDevtools\n\nexport type {\n TanStackDevtoolsReactPlugin,\n TanStackDevtoolsReactInit,\n} from './devtools'\n"],"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["'use client'\n\nimport * as Devtools from './devtools'\n\nexport const TanStackDevtools = Devtools.TanStackDevtools\n\nexport type {\n TanStackDevtoolsReactPlugin,\n TanStackDevtoolsReactInit,\n} from './devtools'\n"],"mappings":";;;;AAIA,IAAA,mBAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-devtools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "TanStack Devtools is a set of tools for building advanced devtools for your React application.",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,12 +39,12 @@
|
|
|
39
39
|
"src"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@tanstack/devtools": "0.
|
|
42
|
+
"@tanstack/devtools": "0.11.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@eslint-react/eslint-plugin": "^1.53.1",
|
|
46
46
|
"@types/react": "^19.2.0",
|
|
47
|
-
"@vitejs/plugin-react": "^
|
|
47
|
+
"@vitejs/plugin-react": "^6.0.1",
|
|
48
48
|
"eslint-plugin-react-compiler": "19.1.0-rc.2",
|
|
49
49
|
"eslint-plugin-react-hooks": "^7.0.1",
|
|
50
50
|
"react": "^19.2.0"
|
package/src/devtools.tsx
CHANGED
|
@@ -6,14 +6,16 @@ import type {
|
|
|
6
6
|
ClientEventBusConfig,
|
|
7
7
|
TanStackDevtoolsConfig,
|
|
8
8
|
TanStackDevtoolsPlugin,
|
|
9
|
+
TanStackDevtoolsPluginProps,
|
|
10
|
+
TanStackDevtoolsTheme,
|
|
9
11
|
} from '@tanstack/devtools'
|
|
10
12
|
|
|
11
13
|
type PluginRender =
|
|
12
14
|
| JSX.Element
|
|
13
|
-
| ((el: HTMLElement,
|
|
15
|
+
| ((el: HTMLElement, props: TanStackDevtoolsPluginProps) => JSX.Element)
|
|
14
16
|
|
|
15
17
|
type TriggerProps = {
|
|
16
|
-
theme:
|
|
18
|
+
theme: TanStackDevtoolsTheme
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
type TriggerRender =
|
|
@@ -120,10 +122,10 @@ const convertRender = (
|
|
|
120
122
|
React.SetStateAction<Record<string, JSX.Element>>
|
|
121
123
|
>,
|
|
122
124
|
e: HTMLElement,
|
|
123
|
-
|
|
125
|
+
props: TanStackDevtoolsPluginProps,
|
|
124
126
|
) => {
|
|
125
127
|
const element =
|
|
126
|
-
typeof Component === 'function' ? Component(e,
|
|
128
|
+
typeof Component === 'function' ? Component(e, props) : Component
|
|
127
129
|
|
|
128
130
|
setComponents((prev) => ({
|
|
129
131
|
...prev,
|
|
@@ -177,7 +179,7 @@ export const TanStackDevtools = ({
|
|
|
177
179
|
name:
|
|
178
180
|
typeof plugin.name === 'string'
|
|
179
181
|
? plugin.name
|
|
180
|
-
: (e,
|
|
182
|
+
: (e, props) => {
|
|
181
183
|
const id = e.getAttribute('id')!
|
|
182
184
|
const target = e.ownerDocument.getElementById(id)
|
|
183
185
|
|
|
@@ -192,7 +194,7 @@ export const TanStackDevtools = ({
|
|
|
192
194
|
plugin.name as PluginRender,
|
|
193
195
|
setTitleComponents,
|
|
194
196
|
e,
|
|
195
|
-
|
|
197
|
+
props,
|
|
196
198
|
)
|
|
197
199
|
},
|
|
198
200
|
render: (e, theme) => {
|