@tanstack/react-devtools 0.1.0 → 0.2.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/README.md CHANGED
@@ -8,10 +8,11 @@ This package is still under active development and might have breaking changes i
8
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'
12
+ const queryClient = new QueryClient()
12
13
  function App() {
13
14
  return (
14
- <div>
15
+ <QueryClientProvider client={queryClient}>
15
16
  <h1>My App</h1>
16
17
  <TanstackDevtools
17
18
  plugins={[
@@ -25,6 +26,31 @@ function App() {
25
26
  },
26
27
  ]}
27
28
  />
29
+ </QueryClientProvider>
30
+ )
31
+ }
32
+ ```
33
+
34
+ ## Creating plugins
35
+
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
+
38
+ ```tsx
39
+ import { TanstackDevtools } from '@tanstack/react-devtools'
40
+
41
+ function App() {
42
+ return (
43
+ <div>
44
+ <h1>My App</h1>
45
+ <TanstackDevtools
46
+ plugins={[
47
+ {
48
+ id: 'your-plugin-id',
49
+ name: 'Your Plugin',
50
+ render: <CustomPluginComponent />,
51
+ },
52
+ ]}
53
+ />
28
54
  </div>
29
55
  )
30
56
  }
@@ -9,7 +9,8 @@ const convertRender = (Component, setComponent) => {
9
9
  };
10
10
  const TanstackDevtools = ({
11
11
  plugins,
12
- config
12
+ config,
13
+ eventBusConfig
13
14
  }) => {
14
15
  const devToolRef = react.useRef(null);
15
16
  const [pluginContainer, setPluginContainer] = react.useState(
@@ -23,6 +24,7 @@ const TanstackDevtools = ({
23
24
  const [devtools$1] = react.useState(
24
25
  () => new devtools.TanStackDevtoolsCore({
25
26
  config,
27
+ eventBusConfig,
26
28
  plugins: plugins?.map((plugin) => {
27
29
  return {
28
30
  ...plugin,
@@ -52,9 +54,7 @@ const TanstackDevtools = ({
52
54
  if (devToolRef.current) {
53
55
  devtools$1.mount(devToolRef.current);
54
56
  }
55
- return () => {
56
- devtools$1.unmount();
57
- };
57
+ return () => devtools$1.unmount();
58
58
  }, [devtools$1]);
59
59
  return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
60
60
  /* @__PURE__ */ jsxRuntime.jsx("div", { ref: devToolRef }),
@@ -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 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 render: PluginRender\n name: string | PluginRender\n}\n\nexport interface TanStackDevtoolsReactInit {\n plugins?: Array<TanStackDevtoolsReactPlugin>\n config?: TanStackDevtoolsConfig\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}: TanStackDevtoolsReactInit) => {\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 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 () => {\n devtools.unmount()\n }\n }, [devtools])\n\n return (\n <>\n <div 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":";;;;;;AA4BA,MAAM,gBAAgB,CACpB,WACA,iBACG;AACH,eAAa,OAAO,cAAc,aAAa,UAAA,IAAc,SAAS;AACxE;AAEO,MAAM,mBAAmB,CAAC;AAAA,EAC/B;AAAA,EACA;AACF,MAAiC;AAC/B,QAAM,aAAaA,MAAAA,OAAuB,IAAI;AAC9C,QAAM,CAAC,iBAAiB,kBAAkB,IAAIC,MAAAA;AAAAA,IAC5C;AAAA,EAAA;AAEF,QAAM,CAAC,gBAAgB,iBAAiB,IAAIA,MAAAA,SAA6B,IAAI;AAC7E,QAAM,CAAC,iBAAiB,kBAAkB,IAAIA,MAAAA;AAAAA,IAC5C;AAAA,EAAA;AAEF,QAAM,CAAC,gBAAgB,iBAAiB,IAAIA,MAAAA,SAA6B,IAAI;AAC7E,QAAM,CAACC,UAAQ,IAAID,MAAAA;AAAAA,IACjB,MACE,IAAIE,SAAAA,qBAAqB;AAAA,MACvB;AAAA,MACA,SAAS,SAAS,IAAI,CAAC,WAAW;AAChC,eAAO;AAAA,UACL,GAAG;AAAA,UACH,MACE,OAAO,OAAO,SAAS,WACnB,OAAO;AAAA;AAAA,YAEP,MAAM;AACJ;AAAA,gBACE,SAAS,eAAeC,SAAAA,yBAAyB,KAC/C;AAAA,cAAA;AAEJ;AAAA,gBACE,OAAO;AAAA,gBACP;AAAA,cAAA;AAAA,YAEJ;AAAA;AAAA,UACN,QAAQ,MAAM;AACZ;AAAA,cACE,SAAS,eAAeC,SAAAA,mBAAmB,KAAK;AAAA,YAAA;AAElD,0BAAc,OAAO,QAAQ,kBAAkB;AAAA,UACjD;AAAA,QAAA;AAAA,MAEJ,CAAC;AAAA,IAAA,CACF;AAAA,EAAA;AAELC,QAAAA,UAAU,MAAM;AACd,QAAI,WAAW,SAAS;AACtBJ,iBAAS,MAAM,WAAW,OAAO;AAAA,IACnC;AAEA,WAAO,MAAM;AACXA,iBAAS,QAAA;AAAA,IACX;AAAA,EACF,GAAG,CAACA,UAAQ,CAAC;AAEb,SACEK,2BAAAA,KAAAC,qBAAA,EACE,UAAA;AAAA,IAAAC,2BAAAA,IAAC,OAAA,EAAI,KAAK,WAAA,CAAY;AAAA,IACrB,mBAAmB,kBAChBC,4EAAgB,UAAA,gBAAA,CAAgB,GAAK,eAAe,IACpD;AAAA,IACH,kBAAkB,iBACfA,SAAAA,mEAAgB,UAAA,eAAA,CAAe,GAAK,cAAc,IAClD;AAAA,EAAA,GACN;AAEJ;;"}
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 * <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) => {\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 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,MAAiC;AAC/B,QAAM,aAAaA,MAAAA,OAAuB,IAAI;AAC9C,QAAM,CAAC,iBAAiB,kBAAkB,IAAIC,MAAAA;AAAAA,IAC5C;AAAA,EAAA;AAEF,QAAM,CAAC,gBAAgB,iBAAiB,IAAIA,MAAAA,SAA6B,IAAI;AAC7E,QAAM,CAAC,iBAAiB,kBAAkB,IAAIA,MAAAA;AAAAA,IAC5C;AAAA,EAAA;AAEF,QAAM,CAAC,gBAAgB,iBAAiB,IAAIA,MAAAA,SAA6B,IAAI;AAC7E,QAAM,CAACC,UAAQ,IAAID,MAAAA;AAAAA,IACjB,MACE,IAAIE,SAAAA,qBAAqB;AAAA,MACvB;AAAA,MACA;AAAA,MACA,SAAS,SAAS,IAAI,CAAC,WAAW;AAChC,eAAO;AAAA,UACL,GAAG;AAAA,UACH,MACE,OAAO,OAAO,SAAS,WACnB,OAAO;AAAA;AAAA,YAEP,MAAM;AACJ;AAAA,gBACE,SAAS,eAAeC,SAAAA,yBAAyB,KAC/C;AAAA,cAAA;AAEJ;AAAA,gBACE,OAAO;AAAA,gBACP;AAAA,cAAA;AAAA,YAEJ;AAAA;AAAA,UACN,QAAQ,MAAM;AACZ;AAAA,cACE,SAAS,eAAeC,SAAAA,mBAAmB,KAAK;AAAA,YAAA;AAElD,0BAAc,OAAO,QAAQ,kBAAkB;AAAA,UACjD;AAAA,QAAA;AAAA,MAEJ,CAAC;AAAA,IAAA,CACF;AAAA,EAAA;AAELC,QAAAA,UAAU,MAAM;AACd,QAAI,WAAW,SAAS;AACtBJ,iBAAS,MAAM,WAAW,OAAO;AAAA,IACnC;AAEA,WAAO,MAAMA,WAAS,QAAA;AAAA,EACxB,GAAG,CAACA,UAAQ,CAAC;AAEb,SACEK,2BAAAA,KAAAC,qBAAA,EACE,UAAA;AAAA,IAAAC,2BAAAA,IAAC,OAAA,EAAI,KAAK,WAAA,CAAY;AAAA,IACrB,mBAAmB,kBAChBC,4EAAgB,UAAA,gBAAA,CAAgB,GAAK,eAAe,IACpD;AAAA,IACH,kBAAkB,iBACfA,SAAAA,mEAAgB,UAAA,eAAA,CAAe,GAAK,cAAc,IAClD;AAAA,EAAA,GACN;AAEJ;;"}
@@ -1,13 +1,76 @@
1
1
  import { JSX } from 'react';
2
- import { TanStackDevtoolsConfig, TanStackDevtoolsPlugin } from '@tanstack/devtools';
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'> & {
5
+ /**
6
+ * The render function can be a React element or a function that returns a React element.
7
+ * If it's a function, it will be called to render the plugin, otherwise it will be rendered directly.
8
+ *
9
+ * Example:
10
+ * ```jsx
11
+ * {
12
+ * render: () => <CustomPluginComponent />,
13
+ * }
14
+ * ```
15
+ * or
16
+ * ```jsx
17
+ * {
18
+ * render: <CustomPluginComponent />,
19
+ * }
20
+ * ```
21
+ */
5
22
  render: PluginRender;
23
+ /**
24
+ * Name to be displayed in the devtools UI.
25
+ * If a string, it will be used as the plugin name.
26
+ * If a function, it will be called with the mount element.
27
+ *
28
+ * Example:
29
+ * ```jsx
30
+ * {
31
+ * name: "Your Plugin",
32
+ * render: () => <CustomPluginComponent />,
33
+ * }
34
+ * ```
35
+ * or
36
+ * ```jsx
37
+ * {
38
+ * name: <h1>Your Plugin title</h1>,
39
+ * render: () => <CustomPluginComponent />,
40
+ * }
41
+ * ```
42
+ */
6
43
  name: string | PluginRender;
7
44
  };
8
45
  export interface TanStackDevtoolsReactInit {
46
+ /**
47
+ * Array of plugins to be used in the devtools.
48
+ * Each plugin should have a `render` function that returns a React element or a function
49
+ *
50
+ * Example:
51
+ * ```jsx
52
+ * <TanstackDevtools
53
+ * plugins={[
54
+ * {
55
+ * id: "your-plugin-id",
56
+ * name: "Your Plugin",
57
+ * render: <CustomPluginComponent />,
58
+ * }
59
+ * ]}
60
+ * />
61
+ * ```
62
+ */
9
63
  plugins?: Array<TanStackDevtoolsReactPlugin>;
10
- config?: TanStackDevtoolsConfig;
64
+ /**
65
+ * Configuration for the devtools shell. These configuration options are used to set the
66
+ * initial state of the devtools when it is started for the first time. Afterwards,
67
+ * the settings are persisted in local storage and changed through the settings panel.
68
+ */
69
+ config?: Partial<TanStackDevtoolsConfig>;
70
+ /**
71
+ * Configuration for the TanStack Devtools client event bus.
72
+ */
73
+ eventBusConfig?: ClientEventBusConfig;
11
74
  }
12
- export declare const TanstackDevtools: ({ plugins, config, }: TanStackDevtoolsReactInit) => JSX.Element;
75
+ export declare const TanstackDevtools: ({ plugins, config, eventBusConfig, }: TanStackDevtoolsReactInit) => JSX.Element;
13
76
  export {};
@@ -1,13 +1,76 @@
1
1
  import { JSX } from 'react';
2
- import { TanStackDevtoolsConfig, TanStackDevtoolsPlugin } from '@tanstack/devtools';
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'> & {
5
+ /**
6
+ * The render function can be a React element or a function that returns a React element.
7
+ * If it's a function, it will be called to render the plugin, otherwise it will be rendered directly.
8
+ *
9
+ * Example:
10
+ * ```jsx
11
+ * {
12
+ * render: () => <CustomPluginComponent />,
13
+ * }
14
+ * ```
15
+ * or
16
+ * ```jsx
17
+ * {
18
+ * render: <CustomPluginComponent />,
19
+ * }
20
+ * ```
21
+ */
5
22
  render: PluginRender;
23
+ /**
24
+ * Name to be displayed in the devtools UI.
25
+ * If a string, it will be used as the plugin name.
26
+ * If a function, it will be called with the mount element.
27
+ *
28
+ * Example:
29
+ * ```jsx
30
+ * {
31
+ * name: "Your Plugin",
32
+ * render: () => <CustomPluginComponent />,
33
+ * }
34
+ * ```
35
+ * or
36
+ * ```jsx
37
+ * {
38
+ * name: <h1>Your Plugin title</h1>,
39
+ * render: () => <CustomPluginComponent />,
40
+ * }
41
+ * ```
42
+ */
6
43
  name: string | PluginRender;
7
44
  };
8
45
  export interface TanStackDevtoolsReactInit {
46
+ /**
47
+ * Array of plugins to be used in the devtools.
48
+ * Each plugin should have a `render` function that returns a React element or a function
49
+ *
50
+ * Example:
51
+ * ```jsx
52
+ * <TanstackDevtools
53
+ * plugins={[
54
+ * {
55
+ * id: "your-plugin-id",
56
+ * name: "Your Plugin",
57
+ * render: <CustomPluginComponent />,
58
+ * }
59
+ * ]}
60
+ * />
61
+ * ```
62
+ */
9
63
  plugins?: Array<TanStackDevtoolsReactPlugin>;
10
- config?: TanStackDevtoolsConfig;
64
+ /**
65
+ * Configuration for the devtools shell. These configuration options are used to set the
66
+ * initial state of the devtools when it is started for the first time. Afterwards,
67
+ * the settings are persisted in local storage and changed through the settings panel.
68
+ */
69
+ config?: Partial<TanStackDevtoolsConfig>;
70
+ /**
71
+ * Configuration for the TanStack Devtools client event bus.
72
+ */
73
+ eventBusConfig?: ClientEventBusConfig;
11
74
  }
12
- export declare const TanstackDevtools: ({ plugins, config, }: TanStackDevtoolsReactInit) => JSX.Element;
75
+ export declare const TanstackDevtools: ({ plugins, config, eventBusConfig, }: TanStackDevtoolsReactInit) => JSX.Element;
13
76
  export {};
@@ -7,7 +7,8 @@ const convertRender = (Component, setComponent) => {
7
7
  };
8
8
  const TanstackDevtools = ({
9
9
  plugins,
10
- config
10
+ config,
11
+ eventBusConfig
11
12
  }) => {
12
13
  const devToolRef = useRef(null);
13
14
  const [pluginContainer, setPluginContainer] = useState(
@@ -21,6 +22,7 @@ const TanstackDevtools = ({
21
22
  const [devtools] = useState(
22
23
  () => new TanStackDevtoolsCore({
23
24
  config,
25
+ eventBusConfig,
24
26
  plugins: plugins?.map((plugin) => {
25
27
  return {
26
28
  ...plugin,
@@ -50,9 +52,7 @@ const TanstackDevtools = ({
50
52
  if (devToolRef.current) {
51
53
  devtools.mount(devToolRef.current);
52
54
  }
53
- return () => {
54
- devtools.unmount();
55
- };
55
+ return () => devtools.unmount();
56
56
  }, [devtools]);
57
57
  return /* @__PURE__ */ jsxs(Fragment, { children: [
58
58
  /* @__PURE__ */ jsx("div", { ref: devToolRef }),
@@ -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 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 render: PluginRender\n name: string | PluginRender\n}\n\nexport interface TanStackDevtoolsReactInit {\n plugins?: Array<TanStackDevtoolsReactPlugin>\n config?: TanStackDevtoolsConfig\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}: TanStackDevtoolsReactInit) => {\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 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 () => {\n devtools.unmount()\n }\n }, [devtools])\n\n return (\n <>\n <div 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":";;;;AA4BA,MAAM,gBAAgB,CACpB,WACA,iBACG;AACH,eAAa,OAAO,cAAc,aAAa,UAAA,IAAc,SAAS;AACxE;AAEO,MAAM,mBAAmB,CAAC;AAAA,EAC/B;AAAA,EACA;AACF,MAAiC;AAC/B,QAAM,aAAa,OAAuB,IAAI;AAC9C,QAAM,CAAC,iBAAiB,kBAAkB,IAAI;AAAA,IAC5C;AAAA,EAAA;AAEF,QAAM,CAAC,gBAAgB,iBAAiB,IAAI,SAA6B,IAAI;AAC7E,QAAM,CAAC,iBAAiB,kBAAkB,IAAI;AAAA,IAC5C;AAAA,EAAA;AAEF,QAAM,CAAC,gBAAgB,iBAAiB,IAAI,SAA6B,IAAI;AAC7E,QAAM,CAAC,QAAQ,IAAI;AAAA,IACjB,MACE,IAAI,qBAAqB;AAAA,MACvB;AAAA,MACA,SAAS,SAAS,IAAI,CAAC,WAAW;AAChC,eAAO;AAAA,UACL,GAAG;AAAA,UACH,MACE,OAAO,OAAO,SAAS,WACnB,OAAO;AAAA;AAAA,YAEP,MAAM;AACJ;AAAA,gBACE,SAAS,eAAe,yBAAyB,KAC/C;AAAA,cAAA;AAEJ;AAAA,gBACE,OAAO;AAAA,gBACP;AAAA,cAAA;AAAA,YAEJ;AAAA;AAAA,UACN,QAAQ,MAAM;AACZ;AAAA,cACE,SAAS,eAAe,mBAAmB,KAAK;AAAA,YAAA;AAElD,0BAAc,OAAO,QAAQ,kBAAkB;AAAA,UACjD;AAAA,QAAA;AAAA,MAEJ,CAAC;AAAA,IAAA,CACF;AAAA,EAAA;AAEL,YAAU,MAAM;AACd,QAAI,WAAW,SAAS;AACtB,eAAS,MAAM,WAAW,OAAO;AAAA,IACnC;AAEA,WAAO,MAAM;AACX,eAAS,QAAA;AAAA,IACX;AAAA,EACF,GAAG,CAAC,QAAQ,CAAC;AAEb,SACE,qBAAA,UAAA,EACE,UAAA;AAAA,IAAA,oBAAC,OAAA,EAAI,KAAK,WAAA,CAAY;AAAA,IACrB,mBAAmB,kBAChB,6CAAgB,UAAA,gBAAA,CAAgB,GAAK,eAAe,IACpD;AAAA,IACH,kBAAkB,iBACf,6CAAgB,UAAA,eAAA,CAAe,GAAK,cAAc,IAClD;AAAA,EAAA,GACN;AAEJ;"}
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 * <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) => {\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 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,MAAiC;AAC/B,QAAM,aAAa,OAAuB,IAAI;AAC9C,QAAM,CAAC,iBAAiB,kBAAkB,IAAI;AAAA,IAC5C;AAAA,EAAA;AAEF,QAAM,CAAC,gBAAgB,iBAAiB,IAAI,SAA6B,IAAI;AAC7E,QAAM,CAAC,iBAAiB,kBAAkB,IAAI;AAAA,IAC5C;AAAA,EAAA;AAEF,QAAM,CAAC,gBAAgB,iBAAiB,IAAI,SAA6B,IAAI;AAC7E,QAAM,CAAC,QAAQ,IAAI;AAAA,IACjB,MACE,IAAI,qBAAqB;AAAA,MACvB;AAAA,MACA;AAAA,MACA,SAAS,SAAS,IAAI,CAAC,WAAW;AAChC,eAAO;AAAA,UACL,GAAG;AAAA,UACH,MACE,OAAO,OAAO,SAAS,WACnB,OAAO;AAAA;AAAA,YAEP,MAAM;AACJ;AAAA,gBACE,SAAS,eAAe,yBAAyB,KAC/C;AAAA,cAAA;AAEJ;AAAA,gBACE,OAAO;AAAA,gBACP;AAAA,cAAA;AAAA,YAEJ;AAAA;AAAA,UACN,QAAQ,MAAM;AACZ;AAAA,cACE,SAAS,eAAe,mBAAmB,KAAK;AAAA,YAAA;AAElD,0BAAc,OAAO,QAAQ,kBAAkB;AAAA,UACjD;AAAA,QAAA;AAAA,MAEJ,CAAC;AAAA,IAAA,CACF;AAAA,EAAA;AAEL,YAAU,MAAM;AACd,QAAI,WAAW,SAAS;AACtB,eAAS,MAAM,WAAW,OAAO;AAAA,IACnC;AAEA,WAAO,MAAM,SAAS,QAAA;AAAA,EACxB,GAAG,CAAC,QAAQ,CAAC;AAEb,SACE,qBAAA,UAAA,EACE,UAAA;AAAA,IAAA,oBAAC,OAAA,EAAI,KAAK,WAAA,CAAY;AAAA,IACrB,mBAAmB,kBAChB,6CAAgB,UAAA,gBAAA,CAAgB,GAAK,eAAe,IACpD;AAAA,IACH,kBAAkB,iBACf,6CAAgB,UAAA,eAAA,CAAe,GAAK,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.1.0",
3
+ "version": "0.2.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",
@@ -44,12 +44,12 @@
44
44
  "src"
45
45
  ],
46
46
  "dependencies": {
47
- "@tanstack/devtools": "0.1.0"
47
+ "@tanstack/devtools": "0.2.0"
48
48
  },
49
49
  "devDependencies": {
50
50
  "@eslint-react/eslint-plugin": "^1.48.5",
51
51
  "@types/react": "^19.1.2",
52
- "@vitejs/plugin-react": "^4.4.1",
52
+ "@vitejs/plugin-react": "^4.5.2",
53
53
  "eslint-plugin-react-compiler": "19.1.0-rc.1",
54
54
  "eslint-plugin-react-hooks": "^5.2.0",
55
55
  "react": "^19.1.0"
package/src/devtools.tsx CHANGED
@@ -7,6 +7,7 @@ import {
7
7
  import { createPortal } from 'react-dom'
8
8
  import type { JSX } from 'react'
9
9
  import type {
10
+ ClientEventBusConfig,
10
11
  TanStackDevtoolsConfig,
11
12
  TanStackDevtoolsPlugin,
12
13
  } from '@tanstack/devtools'
@@ -17,13 +18,76 @@ export type TanStackDevtoolsReactPlugin = Omit<
17
18
  TanStackDevtoolsPlugin,
18
19
  'render' | 'name'
19
20
  > & {
21
+ /**
22
+ * The render function can be a React element or a function that returns a React element.
23
+ * If it's a function, it will be called to render the plugin, otherwise it will be rendered directly.
24
+ *
25
+ * Example:
26
+ * ```jsx
27
+ * {
28
+ * render: () => <CustomPluginComponent />,
29
+ * }
30
+ * ```
31
+ * or
32
+ * ```jsx
33
+ * {
34
+ * render: <CustomPluginComponent />,
35
+ * }
36
+ * ```
37
+ */
20
38
  render: PluginRender
39
+ /**
40
+ * Name to be displayed in the devtools UI.
41
+ * If a string, it will be used as the plugin name.
42
+ * If a function, it will be called with the mount element.
43
+ *
44
+ * Example:
45
+ * ```jsx
46
+ * {
47
+ * name: "Your Plugin",
48
+ * render: () => <CustomPluginComponent />,
49
+ * }
50
+ * ```
51
+ * or
52
+ * ```jsx
53
+ * {
54
+ * name: <h1>Your Plugin title</h1>,
55
+ * render: () => <CustomPluginComponent />,
56
+ * }
57
+ * ```
58
+ */
21
59
  name: string | PluginRender
22
60
  }
23
61
 
24
62
  export interface TanStackDevtoolsReactInit {
63
+ /**
64
+ * Array of plugins to be used in the devtools.
65
+ * Each plugin should have a `render` function that returns a React element or a function
66
+ *
67
+ * Example:
68
+ * ```jsx
69
+ * <TanstackDevtools
70
+ * plugins={[
71
+ * {
72
+ * id: "your-plugin-id",
73
+ * name: "Your Plugin",
74
+ * render: <CustomPluginComponent />,
75
+ * }
76
+ * ]}
77
+ * />
78
+ * ```
79
+ */
25
80
  plugins?: Array<TanStackDevtoolsReactPlugin>
26
- config?: TanStackDevtoolsConfig
81
+ /**
82
+ * Configuration for the devtools shell. These configuration options are used to set the
83
+ * initial state of the devtools when it is started for the first time. Afterwards,
84
+ * the settings are persisted in local storage and changed through the settings panel.
85
+ */
86
+ config?: Partial<TanStackDevtoolsConfig>
87
+ /**
88
+ * Configuration for the TanStack Devtools client event bus.
89
+ */
90
+ eventBusConfig?: ClientEventBusConfig
27
91
  }
28
92
 
29
93
  const convertRender = (
@@ -36,6 +100,7 @@ const convertRender = (
36
100
  export const TanstackDevtools = ({
37
101
  plugins,
38
102
  config,
103
+ eventBusConfig,
39
104
  }: TanStackDevtoolsReactInit) => {
40
105
  const devToolRef = useRef<HTMLDivElement>(null)
41
106
  const [pluginContainer, setPluginContainer] = useState<HTMLElement | null>(
@@ -50,6 +115,7 @@ export const TanstackDevtools = ({
50
115
  () =>
51
116
  new TanStackDevtoolsCore({
52
117
  config,
118
+ eventBusConfig,
53
119
  plugins: plugins?.map((plugin) => {
54
120
  return {
55
121
  ...plugin,
@@ -82,9 +148,7 @@ export const TanstackDevtools = ({
82
148
  devtools.mount(devToolRef.current)
83
149
  }
84
150
 
85
- return () => {
86
- devtools.unmount()
87
- }
151
+ return () => devtools.unmount()
88
152
  }, [devtools])
89
153
 
90
154
  return (