@tanstack/react-devtools 0.5.5 → 0.6.2
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 +1 -1
- package/dist/esm/devtools.js +10 -6
- package/dist/esm/devtools.js.map +1 -1
- package/package.json +3 -3
- package/src/devtools.tsx +13 -5
package/dist/esm/devtools.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { JSX, ReactElement } from 'react';
|
|
2
2
|
import { ClientEventBusConfig, TanStackDevtoolsConfig, TanStackDevtoolsPlugin } from '@tanstack/devtools';
|
|
3
|
-
type PluginRender = JSX.Element | (() => JSX.Element);
|
|
3
|
+
type PluginRender = JSX.Element | ((el: HTMLElement, theme: 'dark' | 'light') => JSX.Element);
|
|
4
4
|
export type TanStackDevtoolsReactPlugin = Omit<TanStackDevtoolsPlugin, 'render' | 'name'> & {
|
|
5
5
|
/**
|
|
6
6
|
* The render function can be a React element or a function that returns a React element.
|
package/dist/esm/devtools.js
CHANGED
|
@@ -2,8 +2,10 @@ import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { useRef, useState, useEffect } from "react";
|
|
3
3
|
import { TanStackDevtoolsCore, PLUGIN_CONTAINER_ID, PLUGIN_TITLE_CONTAINER_ID } from "@tanstack/devtools";
|
|
4
4
|
import { createPortal } from "react-dom";
|
|
5
|
-
const convertRender = (Component, setComponent) => {
|
|
6
|
-
setComponent(
|
|
5
|
+
const convertRender = (Component, setComponent, e, theme) => {
|
|
6
|
+
setComponent(
|
|
7
|
+
typeof Component === "function" ? Component(e, theme) : Component
|
|
8
|
+
);
|
|
7
9
|
};
|
|
8
10
|
const TanStackDevtools = ({
|
|
9
11
|
plugins,
|
|
@@ -28,7 +30,7 @@ const TanStackDevtools = ({
|
|
|
28
30
|
...plugin,
|
|
29
31
|
name: typeof plugin.name === "string" ? plugin.name : (
|
|
30
32
|
// The check above confirms that `plugin.name` is of Render type
|
|
31
|
-
(e) => {
|
|
33
|
+
(e, theme) => {
|
|
32
34
|
setTitleContainer(
|
|
33
35
|
e.ownerDocument.getElementById(
|
|
34
36
|
PLUGIN_TITLE_CONTAINER_ID
|
|
@@ -36,15 +38,17 @@ const TanStackDevtools = ({
|
|
|
36
38
|
);
|
|
37
39
|
convertRender(
|
|
38
40
|
plugin.name,
|
|
39
|
-
setTitleComponent
|
|
41
|
+
setTitleComponent,
|
|
42
|
+
e,
|
|
43
|
+
theme
|
|
40
44
|
);
|
|
41
45
|
}
|
|
42
46
|
),
|
|
43
|
-
render: (e) => {
|
|
47
|
+
render: (e, theme) => {
|
|
44
48
|
setPluginContainer(
|
|
45
49
|
e.ownerDocument.getElementById(PLUGIN_CONTAINER_ID) || null
|
|
46
50
|
);
|
|
47
|
-
convertRender(plugin.render, setPluginComponent);
|
|
51
|
+
convertRender(plugin.render, setPluginComponent, e, theme);
|
|
48
52
|
}
|
|
49
53
|
};
|
|
50
54
|
})
|
package/dist/esm/devtools.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devtools.js","sources":["../../src/devtools.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react'\nimport {\n PLUGIN_CONTAINER_ID,\n PLUGIN_TITLE_CONTAINER_ID,\n TanStackDevtoolsCore,\n} 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
|
|
1
|
+
{"version":3,"file":"devtools.js","sources":["../../src/devtools.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState } from 'react'\nimport {\n PLUGIN_CONTAINER_ID,\n PLUGIN_TITLE_CONTAINER_ID,\n TanStackDevtoolsCore,\n} 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\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\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?: Partial<TanStackDevtoolsConfig>\n /**\n * Configuration for the TanStack Devtools client event bus.\n */\n eventBusConfig?: ClientEventBusConfig\n}\n\nconst convertRender = (\n Component: PluginRender,\n setComponent: React.Dispatch<React.SetStateAction<JSX.Element | null>>,\n e: HTMLElement,\n theme: 'dark' | 'light',\n) => {\n setComponent(\n typeof Component === 'function' ? Component(e, theme) : Component,\n )\n}\n\nexport const TanStackDevtools = ({\n plugins,\n config,\n eventBusConfig,\n}: TanStackDevtoolsReactInit): ReactElement | null => {\n const devToolRef = useRef<HTMLDivElement>(null)\n const [pluginContainer, setPluginContainer] = useState<HTMLElement | null>(\n null,\n )\n const [titleContainer, setTitleContainer] = useState<HTMLElement | null>(null)\n const [PluginComponent, setPluginComponent] = useState<JSX.Element | null>(\n null,\n )\n const [TitleComponent, setTitleComponent] = useState<JSX.Element | null>(null)\n const [devtools] = useState(\n () =>\n new TanStackDevtoolsCore({\n config,\n eventBusConfig,\n plugins: plugins?.map((plugin) => {\n return {\n ...plugin,\n name:\n typeof plugin.name === 'string'\n ? plugin.name\n : // The check above confirms that `plugin.name` is of Render type\n (e, theme) => {\n setTitleContainer(\n e.ownerDocument.getElementById(\n PLUGIN_TITLE_CONTAINER_ID,\n ) || null,\n )\n convertRender(\n plugin.name as PluginRender,\n setTitleComponent,\n e,\n theme,\n )\n },\n render: (e, theme) => {\n setPluginContainer(\n e.ownerDocument.getElementById(PLUGIN_CONTAINER_ID) || null,\n )\n convertRender(plugin.render, setPluginComponent, e, theme)\n },\n }\n }),\n }),\n )\n useEffect(() => {\n if (devToolRef.current) {\n devtools.mount(devToolRef.current)\n }\n\n return () => devtools.unmount()\n }, [devtools])\n\n return (\n <>\n <div style={{ position: 'absolute' }} ref={devToolRef} />\n {pluginContainer && PluginComponent\n ? createPortal(<>{PluginComponent}</>, pluginContainer)\n : null}\n {titleContainer && TitleComponent\n ? createPortal(<>{TitleComponent}</>, titleContainer)\n : null}\n </>\n )\n}\n"],"names":[],"mappings":";;;;AA8FA,MAAM,gBAAgB,CACpB,WACA,cACA,GACA,UACG;AACH;AAAA,IACE,OAAO,cAAc,aAAa,UAAU,GAAG,KAAK,IAAI;AAAA,EAAA;AAE5D;AAEO,MAAM,mBAAmB,CAAC;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AACF,MAAsD;AACpD,QAAM,aAAa,OAAuB,IAAI;AAC9C,QAAM,CA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,cAAc,IAClD;AAAA,EAAA,GACN;AAEJ;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-devtools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.2",
|
|
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",
|
|
@@ -45,11 +45,11 @@
|
|
|
45
45
|
"src"
|
|
46
46
|
],
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@tanstack/devtools": "0.6.
|
|
48
|
+
"@tanstack/devtools": "0.6.6"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@eslint-react/eslint-plugin": "^1.48.5",
|
|
52
|
-
"@types/react": "^19.1.
|
|
52
|
+
"@types/react": "^19.1.12",
|
|
53
53
|
"@vitejs/plugin-react": "^4.5.2",
|
|
54
54
|
"eslint-plugin-react-compiler": "19.1.0-rc.1",
|
|
55
55
|
"eslint-plugin-react-hooks": "^5.2.0",
|
package/src/devtools.tsx
CHANGED
|
@@ -12,7 +12,9 @@ import type {
|
|
|
12
12
|
TanStackDevtoolsPlugin,
|
|
13
13
|
} from '@tanstack/devtools'
|
|
14
14
|
|
|
15
|
-
type PluginRender =
|
|
15
|
+
type PluginRender =
|
|
16
|
+
| JSX.Element
|
|
17
|
+
| ((el: HTMLElement, theme: 'dark' | 'light') => JSX.Element)
|
|
16
18
|
|
|
17
19
|
export type TanStackDevtoolsReactPlugin = Omit<
|
|
18
20
|
TanStackDevtoolsPlugin,
|
|
@@ -93,8 +95,12 @@ export interface TanStackDevtoolsReactInit {
|
|
|
93
95
|
const convertRender = (
|
|
94
96
|
Component: PluginRender,
|
|
95
97
|
setComponent: React.Dispatch<React.SetStateAction<JSX.Element | null>>,
|
|
98
|
+
e: HTMLElement,
|
|
99
|
+
theme: 'dark' | 'light',
|
|
96
100
|
) => {
|
|
97
|
-
setComponent(
|
|
101
|
+
setComponent(
|
|
102
|
+
typeof Component === 'function' ? Component(e, theme) : Component,
|
|
103
|
+
)
|
|
98
104
|
}
|
|
99
105
|
|
|
100
106
|
export const TanStackDevtools = ({
|
|
@@ -123,7 +129,7 @@ export const TanStackDevtools = ({
|
|
|
123
129
|
typeof plugin.name === 'string'
|
|
124
130
|
? plugin.name
|
|
125
131
|
: // The check above confirms that `plugin.name` is of Render type
|
|
126
|
-
(e) => {
|
|
132
|
+
(e, theme) => {
|
|
127
133
|
setTitleContainer(
|
|
128
134
|
e.ownerDocument.getElementById(
|
|
129
135
|
PLUGIN_TITLE_CONTAINER_ID,
|
|
@@ -132,13 +138,15 @@ export const TanStackDevtools = ({
|
|
|
132
138
|
convertRender(
|
|
133
139
|
plugin.name as PluginRender,
|
|
134
140
|
setTitleComponent,
|
|
141
|
+
e,
|
|
142
|
+
theme,
|
|
135
143
|
)
|
|
136
144
|
},
|
|
137
|
-
render: (e) => {
|
|
145
|
+
render: (e, theme) => {
|
|
138
146
|
setPluginContainer(
|
|
139
147
|
e.ownerDocument.getElementById(PLUGIN_CONTAINER_ID) || null,
|
|
140
148
|
)
|
|
141
|
-
convertRender(plugin.render, setPluginComponent)
|
|
149
|
+
convertRender(plugin.render, setPluginComponent, e, theme)
|
|
142
150
|
},
|
|
143
151
|
}
|
|
144
152
|
}),
|