@tanstack/react-devtools 0.3.1 → 0.4.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/README.md +7 -7
- package/dist/cjs/devtools.cjs +2 -2
- package/dist/cjs/devtools.cjs.map +1 -1
- package/dist/cjs/devtools.d.cts +3 -3
- package/dist/cjs/index.cjs +5 -8
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +3 -6
- package/dist/cjs/production.cjs +7 -0
- package/dist/cjs/production.cjs.map +1 -0
- package/dist/cjs/production.d.cts +3 -0
- package/dist/esm/devtools.d.ts +3 -3
- package/dist/esm/devtools.js +2 -2
- package/dist/esm/devtools.js.map +1 -1
- package/dist/esm/index.d.ts +3 -6
- package/dist/esm/index.js +6 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/production.d.ts +3 -0
- package/dist/esm/production.js +7 -0
- package/dist/esm/production.js.map +1 -0
- package/package.json +12 -2
- package/src/devtools.tsx +4 -4
- package/src/index.ts +14 -7
- package/src/production.ts +10 -0
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ This package is still under active development and might have breaking changes i
|
|
|
5
5
|
## Usage
|
|
6
6
|
|
|
7
7
|
```tsx
|
|
8
|
-
import {
|
|
8
|
+
import { TanStackDevtools } from '@tanstack/react-devtools'
|
|
9
9
|
import { ReactQueryDevtoolsPanel } from '@tanstack/react-query-devtools'
|
|
10
10
|
import { TanStackRouterDevtoolsPanel } from '@tanstack/react-router-devtools'
|
|
11
11
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
@@ -14,14 +14,14 @@ function App() {
|
|
|
14
14
|
return (
|
|
15
15
|
<QueryClientProvider client={queryClient}>
|
|
16
16
|
<h1>My App</h1>
|
|
17
|
-
<
|
|
17
|
+
<TanStackDevtools
|
|
18
18
|
plugins={[
|
|
19
19
|
{
|
|
20
|
-
name: '
|
|
20
|
+
name: 'TanStack Query',
|
|
21
21
|
render: <ReactQueryDevtoolsPanel />,
|
|
22
22
|
},
|
|
23
23
|
{
|
|
24
|
-
name: '
|
|
24
|
+
name: 'TanStack Router',
|
|
25
25
|
render: <TanStackRouterDevtoolsPanel router={router} />,
|
|
26
26
|
},
|
|
27
27
|
]}
|
|
@@ -33,16 +33,16 @@ function App() {
|
|
|
33
33
|
|
|
34
34
|
## Creating plugins
|
|
35
35
|
|
|
36
|
-
In order to create a plugin for TanStack Devtools, you can use the `plugins` prop of the `
|
|
36
|
+
In order to create a plugin for TanStack Devtools, you can use the `plugins` prop of the `TanStackDevtools` component. Here's an example of how to create a simple plugin:
|
|
37
37
|
|
|
38
38
|
```tsx
|
|
39
|
-
import {
|
|
39
|
+
import { TanStackDevtools } from '@tanstack/react-devtools'
|
|
40
40
|
|
|
41
41
|
function App() {
|
|
42
42
|
return (
|
|
43
43
|
<div>
|
|
44
44
|
<h1>My App</h1>
|
|
45
|
-
<
|
|
45
|
+
<TanStackDevtools
|
|
46
46
|
plugins={[
|
|
47
47
|
{
|
|
48
48
|
id: 'your-plugin-id',
|
package/dist/cjs/devtools.cjs
CHANGED
|
@@ -7,7 +7,7 @@ const reactDom = require("react-dom");
|
|
|
7
7
|
const convertRender = (Component, setComponent) => {
|
|
8
8
|
setComponent(typeof Component === "function" ? Component() : Component);
|
|
9
9
|
};
|
|
10
|
-
const
|
|
10
|
+
const TanStackDevtools = ({
|
|
11
11
|
plugins,
|
|
12
12
|
config,
|
|
13
13
|
eventBusConfig
|
|
@@ -62,5 +62,5 @@ const TanstackDevtools = ({
|
|
|
62
62
|
titleContainer && TitleComponent ? reactDom.createPortal(/* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: TitleComponent }), titleContainer) : null
|
|
63
63
|
] });
|
|
64
64
|
};
|
|
65
|
-
exports.
|
|
65
|
+
exports.TanStackDevtools = TanStackDevtools;
|
|
66
66
|
//# sourceMappingURL=devtools.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devtools.cjs","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 } from 'react'\nimport type {\n ClientEventBusConfig,\n TanStackDevtoolsConfig,\n TanStackDevtoolsPlugin,\n} from '@tanstack/devtools'\n\ntype PluginRender = JSX.Element | (() => 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 * <
|
|
1
|
+
{"version":3,"file":"devtools.cjs","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 = JSX.Element | (() => 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) => {\n setComponent(typeof Component === 'function' ? Component() : Component)\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 () => {\n setTitleContainer(\n document.getElementById(PLUGIN_TITLE_CONTAINER_ID) ||\n null,\n )\n convertRender(\n plugin.name as PluginRender,\n setTitleComponent,\n )\n },\n render: () => {\n setPluginContainer(\n document.getElementById(PLUGIN_CONTAINER_ID) || null,\n )\n convertRender(plugin.render, setPluginComponent)\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":["useRef","useState","devtools","TanStackDevtoolsCore","PLUGIN_TITLE_CONTAINER_ID","PLUGIN_CONTAINER_ID","useEffect","jsxs","Fragment","jsx","createPortal"],"mappings":";;;;;;AA4FA,MAAM,gBAAgB,CACpB,WACA,iBACG;AACH,eAAa,OAAO,cAAc,aAAa,UAAA,IAAc,SAAS;AACxE;AAEO,MAAM,mBAAmB,CAAC;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AACF,MAAsD;AACpD,QAAM,aAAaA,MAAAA,OAAuB,IAAI;AAC9C,QAAM,CAAC,iBAAiB,kBAAkB,IAAIC,MAAAA;AAAAA,IAC5C;AAAA,EAAA;AAEF,QAAM,CAAC,gBAAgB,i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HANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JSX } from 'react';
|
|
1
|
+
import { JSX, ReactElement } from 'react';
|
|
2
2
|
import { ClientEventBusConfig, TanStackDevtoolsConfig, TanStackDevtoolsPlugin } from '@tanstack/devtools';
|
|
3
3
|
type PluginRender = JSX.Element | (() => JSX.Element);
|
|
4
4
|
export type TanStackDevtoolsReactPlugin = Omit<TanStackDevtoolsPlugin, 'render' | 'name'> & {
|
|
@@ -49,7 +49,7 @@ export interface TanStackDevtoolsReactInit {
|
|
|
49
49
|
*
|
|
50
50
|
* Example:
|
|
51
51
|
* ```jsx
|
|
52
|
-
* <
|
|
52
|
+
* <TanStackDevtools
|
|
53
53
|
* plugins={[
|
|
54
54
|
* {
|
|
55
55
|
* id: "your-plugin-id",
|
|
@@ -72,5 +72,5 @@ export interface TanStackDevtoolsReactInit {
|
|
|
72
72
|
*/
|
|
73
73
|
eventBusConfig?: ClientEventBusConfig;
|
|
74
74
|
}
|
|
75
|
-
export declare const
|
|
75
|
+
export declare const TanStackDevtools: ({ plugins, config, eventBusConfig, }: TanStackDevtoolsReactInit) => ReactElement | null;
|
|
76
76
|
export {};
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
+
"use client";
|
|
1
2
|
"use strict";
|
|
2
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const devtools$1 = require("@tanstack/devtools");
|
|
4
4
|
const devtools = require("./devtools.cjs");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
get: () => devtools$1[k]
|
|
10
|
-
});
|
|
11
|
-
});
|
|
5
|
+
const TanStackDevtools = process.env.NODE_ENV !== "development" ? function() {
|
|
6
|
+
return null;
|
|
7
|
+
} : devtools.TanStackDevtools;
|
|
8
|
+
exports.TanStackDevtools = TanStackDevtools;
|
|
12
9
|
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/index.ts"],"sourcesContent":["'use client'\n\nimport * as Devtools from './devtools'\n\nexport const TanStackDevtools: (typeof Devtools)['TanStackDevtools'] =\n process.env.NODE_ENV !== 'development'\n ? function () {\n return null\n }\n : Devtools.TanStackDevtools\n\nexport type {\n TanStackDevtoolsReactPlugin,\n TanStackDevtoolsReactInit,\n} from './devtools'\n"],"names":[],"mappings":";;;;AAIO;AAGC;AACF;;"}
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*/
|
|
5
|
-
export * from './devtools.cjs';
|
|
6
|
-
export type { TanStackDevtoolsReactPlugin } from './devtools.cjs';
|
|
1
|
+
import * as Devtools from './devtools.cjs';
|
|
2
|
+
export declare const TanStackDevtools: (typeof Devtools)['TanStackDevtools'];
|
|
3
|
+
export type { TanStackDevtoolsReactPlugin, TanStackDevtoolsReactInit, } from './devtools.cjs';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4
|
+
const devtools = require("./devtools.cjs");
|
|
5
|
+
const TanStackDevtools = devtools.TanStackDevtools;
|
|
6
|
+
exports.TanStackDevtools = TanStackDevtools;
|
|
7
|
+
//# sourceMappingURL=production.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"production.cjs","sources":["../../src/production.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"],"names":[],"mappings":";;;;AAIO;;"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import * as Devtools from './devtools.cjs';
|
|
2
|
+
export declare const TanStackDevtools: ({ plugins, config, eventBusConfig, }: Devtools.TanStackDevtoolsReactInit) => import('react').ReactElement | null;
|
|
3
|
+
export type { TanStackDevtoolsReactPlugin, TanStackDevtoolsReactInit, } from './devtools.cjs';
|
package/dist/esm/devtools.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JSX } from 'react';
|
|
1
|
+
import { JSX, ReactElement } from 'react';
|
|
2
2
|
import { ClientEventBusConfig, TanStackDevtoolsConfig, TanStackDevtoolsPlugin } from '@tanstack/devtools';
|
|
3
3
|
type PluginRender = JSX.Element | (() => JSX.Element);
|
|
4
4
|
export type TanStackDevtoolsReactPlugin = Omit<TanStackDevtoolsPlugin, 'render' | 'name'> & {
|
|
@@ -49,7 +49,7 @@ export interface TanStackDevtoolsReactInit {
|
|
|
49
49
|
*
|
|
50
50
|
* Example:
|
|
51
51
|
* ```jsx
|
|
52
|
-
* <
|
|
52
|
+
* <TanStackDevtools
|
|
53
53
|
* plugins={[
|
|
54
54
|
* {
|
|
55
55
|
* id: "your-plugin-id",
|
|
@@ -72,5 +72,5 @@ export interface TanStackDevtoolsReactInit {
|
|
|
72
72
|
*/
|
|
73
73
|
eventBusConfig?: ClientEventBusConfig;
|
|
74
74
|
}
|
|
75
|
-
export declare const
|
|
75
|
+
export declare const TanStackDevtools: ({ plugins, config, eventBusConfig, }: TanStackDevtoolsReactInit) => ReactElement | null;
|
|
76
76
|
export {};
|
package/dist/esm/devtools.js
CHANGED
|
@@ -5,7 +5,7 @@ import { createPortal } from "react-dom";
|
|
|
5
5
|
const convertRender = (Component, setComponent) => {
|
|
6
6
|
setComponent(typeof Component === "function" ? Component() : Component);
|
|
7
7
|
};
|
|
8
|
-
const
|
|
8
|
+
const TanStackDevtools = ({
|
|
9
9
|
plugins,
|
|
10
10
|
config,
|
|
11
11
|
eventBusConfig
|
|
@@ -61,6 +61,6 @@ const TanstackDevtools = ({
|
|
|
61
61
|
] });
|
|
62
62
|
};
|
|
63
63
|
export {
|
|
64
|
-
|
|
64
|
+
TanStackDevtools
|
|
65
65
|
};
|
|
66
66
|
//# 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, 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 } from 'react'\nimport type {\n ClientEventBusConfig,\n TanStackDevtoolsConfig,\n TanStackDevtoolsPlugin,\n} from '@tanstack/devtools'\n\ntype PluginRender = JSX.Element | (() => 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 * <
|
|
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 = JSX.Element | (() => 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) => {\n setComponent(typeof Component === 'function' ? Component() : Component)\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 () => {\n setTitleContainer(\n document.getElementById(PLUGIN_TITLE_CONTAINER_ID) ||\n null,\n )\n convertRender(\n plugin.name as PluginRender,\n setTitleComponent,\n )\n },\n render: () => {\n setPluginContainer(\n document.getElementById(PLUGIN_CONTAINER_ID) || null,\n )\n convertRender(plugin.render, setPluginComponent)\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":";;;;AA4FA,MAAM,gBAAgB,CACpB,WACA,iBACG;AACH,eAAa,OAAO,cAAc,aAAa,UAAA,IAAc,SAAS;AACxE;AAEO,MAAM,mBAAmB,CAAC;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AACF,MAAsD;AACpD,QAAM,aAAa,OAAuB,IA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HANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
*/
|
|
5
|
-
export * from './devtools.js';
|
|
6
|
-
export type { TanStackDevtoolsReactPlugin } from './devtools.js';
|
|
1
|
+
import * as Devtools from './devtools.js';
|
|
2
|
+
export declare const TanStackDevtools: (typeof Devtools)['TanStackDevtools'];
|
|
3
|
+
export type { TanStackDevtoolsReactPlugin, TanStackDevtoolsReactInit, } from './devtools.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
"use client";
|
|
2
|
+
import { TanStackDevtools as TanStackDevtools$1 } from "./devtools.js";
|
|
3
|
+
const TanStackDevtools = process.env.NODE_ENV !== "development" ? function() {
|
|
4
|
+
return null;
|
|
5
|
+
} : TanStackDevtools$1;
|
|
3
6
|
export {
|
|
4
|
-
|
|
7
|
+
TanStackDevtools
|
|
5
8
|
};
|
|
6
9
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["'use client'\n\nimport * as Devtools from './devtools'\n\nexport const TanStackDevtools: (typeof Devtools)['TanStackDevtools'] =\n process.env.NODE_ENV !== 'development'\n ? function () {\n return null\n }\n : Devtools.TanStackDevtools\n\nexport type {\n TanStackDevtoolsReactPlugin,\n TanStackDevtoolsReactInit,\n} from './devtools'\n"],"names":[],"mappings":";;AAIO;AAGC;AACF;;;;"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import * as Devtools from './devtools.js';
|
|
2
|
+
export declare const TanStackDevtools: ({ plugins, config, eventBusConfig, }: Devtools.TanStackDevtoolsReactInit) => import('react').ReactElement | null;
|
|
3
|
+
export type { TanStackDevtoolsReactPlugin, TanStackDevtoolsReactInit, } from './devtools.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"production.js","sources":["../../src/production.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"],"names":[],"mappings":";;AAIO;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-devtools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
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",
|
|
@@ -33,6 +33,16 @@
|
|
|
33
33
|
"default": "./dist/cjs/index.cjs"
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
|
+
"./production": {
|
|
37
|
+
"import": {
|
|
38
|
+
"types": "./dist/esm/production.d.ts",
|
|
39
|
+
"default": "./dist/esm/production.js"
|
|
40
|
+
},
|
|
41
|
+
"require": {
|
|
42
|
+
"types": "./dist/cjs/production.d.cts",
|
|
43
|
+
"default": "./dist/cjs/production.cjs"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
36
46
|
"./package.json": "./package.json"
|
|
37
47
|
},
|
|
38
48
|
"sideEffects": false,
|
|
@@ -44,7 +54,7 @@
|
|
|
44
54
|
"src"
|
|
45
55
|
],
|
|
46
56
|
"dependencies": {
|
|
47
|
-
"@tanstack/devtools": "0.
|
|
57
|
+
"@tanstack/devtools": "0.4.0"
|
|
48
58
|
},
|
|
49
59
|
"devDependencies": {
|
|
50
60
|
"@eslint-react/eslint-plugin": "^1.48.5",
|
package/src/devtools.tsx
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
TanStackDevtoolsCore,
|
|
6
6
|
} from '@tanstack/devtools'
|
|
7
7
|
import { createPortal } from 'react-dom'
|
|
8
|
-
import type { JSX } from 'react'
|
|
8
|
+
import type { JSX, ReactElement } from 'react'
|
|
9
9
|
import type {
|
|
10
10
|
ClientEventBusConfig,
|
|
11
11
|
TanStackDevtoolsConfig,
|
|
@@ -66,7 +66,7 @@ export interface TanStackDevtoolsReactInit {
|
|
|
66
66
|
*
|
|
67
67
|
* Example:
|
|
68
68
|
* ```jsx
|
|
69
|
-
* <
|
|
69
|
+
* <TanStackDevtools
|
|
70
70
|
* plugins={[
|
|
71
71
|
* {
|
|
72
72
|
* id: "your-plugin-id",
|
|
@@ -97,11 +97,11 @@ const convertRender = (
|
|
|
97
97
|
setComponent(typeof Component === 'function' ? Component() : Component)
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
export const
|
|
100
|
+
export const TanStackDevtools = ({
|
|
101
101
|
plugins,
|
|
102
102
|
config,
|
|
103
103
|
eventBusConfig,
|
|
104
|
-
}: TanStackDevtoolsReactInit) => {
|
|
104
|
+
}: TanStackDevtoolsReactInit): ReactElement | null => {
|
|
105
105
|
const devToolRef = useRef<HTMLDivElement>(null)
|
|
106
106
|
const [pluginContainer, setPluginContainer] = useState<HTMLElement | null>(
|
|
107
107
|
null,
|
package/src/index.ts
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
export * from '@tanstack/devtools'
|
|
3
|
-
/**
|
|
4
|
-
* Export every hook individually - DON'T export from barrel files
|
|
5
|
-
*/
|
|
1
|
+
'use client'
|
|
6
2
|
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
import * as Devtools from './devtools'
|
|
4
|
+
|
|
5
|
+
export const TanStackDevtools: (typeof Devtools)['TanStackDevtools'] =
|
|
6
|
+
process.env.NODE_ENV !== 'development'
|
|
7
|
+
? function () {
|
|
8
|
+
return null
|
|
9
|
+
}
|
|
10
|
+
: Devtools.TanStackDevtools
|
|
11
|
+
|
|
12
|
+
export type {
|
|
13
|
+
TanStackDevtoolsReactPlugin,
|
|
14
|
+
TanStackDevtoolsReactInit,
|
|
15
|
+
} from './devtools'
|