@tanstack/devtools-utils 0.3.4 → 0.4.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.
Files changed (52) hide show
  1. package/dist/preact/esm/index.js +1 -5
  2. package/dist/preact/esm/panel.d.ts +4 -5
  3. package/dist/preact/esm/panel.js +48 -28
  4. package/dist/preact/esm/panel.js.map +1 -1
  5. package/dist/preact/esm/plugin.d.ts +3 -2
  6. package/dist/preact/esm/plugin.js +20 -22
  7. package/dist/preact/esm/plugin.js.map +1 -1
  8. package/dist/react/esm/index.js +1 -5
  9. package/dist/react/esm/panel.d.ts +4 -4
  10. package/dist/react/esm/panel.js +47 -28
  11. package/dist/react/esm/panel.js.map +1 -1
  12. package/dist/react/esm/plugin.d.ts +3 -2
  13. package/dist/react/esm/plugin.js +20 -22
  14. package/dist/react/esm/plugin.js.map +1 -1
  15. package/dist/solid/esm/chunk/{ZXPCWXRH.js → 7TSS377A.js} +2 -10
  16. package/dist/solid/esm/chunk/{UX5ZZ4MG.js → WUD4VD3N.js} +2 -10
  17. package/dist/solid/esm/class-mount-impl/5TF6RAHJ.js +1 -0
  18. package/dist/solid/esm/class-mount-impl/VN5QTPB3.js +1 -0
  19. package/dist/solid/esm/dev.js +9 -11
  20. package/dist/solid/esm/index.d.ts +10 -10
  21. package/dist/solid/esm/index.js +9 -11
  22. package/dist/solid/esm/server.js +8 -10
  23. package/dist/solid-class/esm/class-mount-impl.d.ts +3 -2
  24. package/dist/solid-class/esm/class-mount-impl.js +17 -23
  25. package/dist/solid-class/esm/class-mount-impl.js.map +1 -1
  26. package/dist/solid-class/esm/class.d.ts +4 -3
  27. package/dist/solid-class/esm/class.js +57 -54
  28. package/dist/solid-class/esm/class.js.map +1 -1
  29. package/dist/solid-class/esm/panel.d.ts +3 -3
  30. package/dist/solid-class/esm/plugin.d.ts +3 -2
  31. package/dist/vue/esm/index.js +1 -5
  32. package/dist/vue/esm/panel.d.ts +3 -3
  33. package/dist/vue/esm/panel.js +36 -45
  34. package/dist/vue/esm/panel.js.map +1 -1
  35. package/dist/vue/esm/plugin.js +20 -19
  36. package/dist/vue/esm/plugin.js.map +1 -1
  37. package/package.json +6 -8
  38. package/src/preact/panel.tsx +6 -7
  39. package/src/preact/plugin.tsx +4 -3
  40. package/src/react/panel.tsx +6 -7
  41. package/src/react/plugin.tsx +4 -3
  42. package/src/solid/class-mount-impl.tsx +7 -10
  43. package/src/solid/class.test.tsx +43 -12
  44. package/src/solid/class.ts +15 -4
  45. package/src/solid/panel.tsx +6 -7
  46. package/src/solid/plugin.tsx +4 -3
  47. package/src/vue/panel.ts +6 -7
  48. package/dist/preact/esm/index.js.map +0 -1
  49. package/dist/react/esm/index.js.map +0 -1
  50. package/dist/solid/esm/class-mount-impl/LK7V47IP.js +0 -1
  51. package/dist/solid/esm/class-mount-impl/ZAIAXV4M.js +0 -1
  52. package/dist/vue/esm/index.js.map +0 -1
@@ -2,6 +2,7 @@
2
2
 
3
3
  import type { JSX } from 'preact'
4
4
  import type { DevtoolsPanelProps } from './panel'
5
+ import type { TanStackDevtoolsPluginProps } from '@tanstack/devtools'
5
6
 
6
7
  export function createPreactPlugin({
7
8
  Component,
@@ -15,15 +16,15 @@ export function createPreactPlugin({
15
16
  function Plugin() {
16
17
  return {
17
18
  ...config,
18
- render: (_el: HTMLElement, theme: 'light' | 'dark') => (
19
- <Component theme={theme} />
19
+ render: (_el: HTMLElement, props: TanStackDevtoolsPluginProps) => (
20
+ <Component {...props} />
20
21
  ),
21
22
  }
22
23
  }
23
24
  function NoOpPlugin() {
24
25
  return {
25
26
  ...config,
26
- render: (_el: HTMLElement, _theme: 'light' | 'dark') => <></>,
27
+ render: (_el: HTMLElement, _props: TanStackDevtoolsPluginProps) => <></>,
27
28
  }
28
29
  }
29
30
  return [Plugin, NoOpPlugin] as const
@@ -1,8 +1,7 @@
1
1
  import { useEffect, useRef } from 'react'
2
+ import type { TanStackDevtoolsPluginProps } from '@tanstack/devtools'
2
3
 
3
- export interface DevtoolsPanelProps {
4
- theme?: 'light' | 'dark'
5
- }
4
+ export interface DevtoolsPanelProps extends TanStackDevtoolsPluginProps {}
6
5
 
7
6
  /**
8
7
  * Creates a React component that dynamically imports and mounts a devtools panel. SSR friendly.
@@ -22,9 +21,9 @@ export interface DevtoolsPanelProps {
22
21
  * ```
23
22
  */
24
23
  export function createReactPanel<
25
- TComponentProps extends DevtoolsPanelProps | undefined,
24
+ TComponentProps extends TanStackDevtoolsPluginProps,
26
25
  TCoreDevtoolsClass extends {
27
- mount: (el: HTMLElement, theme: 'light' | 'dark') => void
26
+ mount: (el: HTMLElement, props: TanStackDevtoolsPluginProps) => void
28
27
  unmount: () => void
29
28
  },
30
29
  >(CoreClass: new () => TCoreDevtoolsClass) {
@@ -36,7 +35,7 @@ export function createReactPanel<
36
35
  devtools.current = new CoreClass()
37
36
 
38
37
  if (devToolRef.current) {
39
- devtools.current.mount(devToolRef.current, props?.theme ?? 'dark')
38
+ devtools.current.mount(devToolRef.current, props)
40
39
  }
41
40
 
42
41
  return () => {
@@ -45,7 +44,7 @@ export function createReactPanel<
45
44
  devtools.current = null
46
45
  }
47
46
  }
48
- }, [props?.theme])
47
+ }, [props])
49
48
 
50
49
  return <div style={{ height: '100%' }} ref={devToolRef} />
51
50
  }
@@ -1,5 +1,6 @@
1
1
  import type { JSX } from 'react'
2
2
  import type { DevtoolsPanelProps } from './panel'
3
+ import type { TanStackDevtoolsPluginProps } from '@tanstack/devtools'
3
4
 
4
5
  export function createReactPlugin({
5
6
  Component,
@@ -13,15 +14,15 @@ export function createReactPlugin({
13
14
  function Plugin() {
14
15
  return {
15
16
  ...config,
16
- render: (_el: HTMLElement, theme: 'light' | 'dark') => (
17
- <Component theme={theme} />
17
+ render: (_el: HTMLElement, props: TanStackDevtoolsPluginProps) => (
18
+ <Component {...props} />
18
19
  ),
19
20
  }
20
21
  }
21
22
  function NoOpPlugin() {
22
23
  return {
23
24
  ...config,
24
- render: (_el: HTMLElement, _theme: 'light' | 'dark') => <></>,
25
+ render: (_el: HTMLElement, _props: TanStackDevtoolsPluginProps) => <></>,
25
26
  }
26
27
  }
27
28
  return [Plugin, NoOpPlugin] as const
@@ -2,27 +2,24 @@
2
2
 
3
3
  import { lazy } from 'solid-js'
4
4
  import { Portal, render } from 'solid-js/web'
5
+
5
6
  import type { JSX } from 'solid-js'
7
+ import type { TanStackDevtoolsPluginProps } from '@tanstack/devtools'
6
8
 
7
9
  export function __mountComponent(
8
10
  el: HTMLElement,
9
- theme: 'light' | 'dark',
10
- importFn: () => Promise<{ default: () => JSX.Element }>,
11
+ props: TanStackDevtoolsPluginProps,
12
+ importFn: () => Promise<{
13
+ default: (props: TanStackDevtoolsPluginProps) => JSX.Element
14
+ }>,
11
15
  ): () => void {
12
16
  const Component = lazy(importFn)
13
- const ThemeProvider = lazy(() =>
14
- import('@tanstack/devtools-ui').then((m) => ({
15
- default: m.ThemeContextProvider,
16
- })),
17
- )
18
17
 
19
18
  return render(
20
19
  () => (
21
20
  <Portal mount={el}>
22
21
  <div style={{ height: '100%' }}>
23
- <ThemeProvider theme={theme}>
24
- <Component />
25
- </ThemeProvider>
22
+ <Component {...props} />
26
23
  </div>
27
24
  </Portal>
28
25
  ),
@@ -28,16 +28,23 @@ describe('constructCoreClass', () => {
28
28
  const [DevtoolsCore] = constructCoreClass(importFn)
29
29
  const instance = new DevtoolsCore()
30
30
  const el = document.createElement('div')
31
- await instance.mount(el, 'dark')
32
- expect(mountComponentMock).toHaveBeenCalledWith(el, 'dark', importFn)
31
+ const props = { theme: 'dark' as const, devtoolsOpen: true }
32
+ await instance.mount(el, props)
33
+ expect(mountComponentMock).toHaveBeenCalledWith(el, props, importFn)
33
34
  })
34
35
 
35
36
  it('DevtoolsCore should throw if mount is called twice without unmounting', async () => {
36
37
  const [DevtoolsCore] = constructCoreClass(importFn)
37
38
  const instance = new DevtoolsCore()
38
- await instance.mount(document.createElement('div'), 'dark')
39
+ await instance.mount(document.createElement('div'), {
40
+ theme: 'dark',
41
+ devtoolsOpen: true,
42
+ })
39
43
  await expect(
40
- instance.mount(document.createElement('div'), 'dark'),
44
+ instance.mount(document.createElement('div'), {
45
+ theme: 'dark',
46
+ devtoolsOpen: true,
47
+ }),
41
48
  ).rejects.toThrow('Devtools is already mounted')
42
49
  })
43
50
 
@@ -50,17 +57,26 @@ describe('constructCoreClass', () => {
50
57
  it('DevtoolsCore should allow mount after unmount', async () => {
51
58
  const [DevtoolsCore] = constructCoreClass(importFn)
52
59
  const instance = new DevtoolsCore()
53
- await instance.mount(document.createElement('div'), 'dark')
60
+ await instance.mount(document.createElement('div'), {
61
+ theme: 'dark',
62
+ devtoolsOpen: true,
63
+ })
54
64
  instance.unmount()
55
65
  await expect(
56
- instance.mount(document.createElement('div'), 'dark'),
66
+ instance.mount(document.createElement('div'), {
67
+ theme: 'dark',
68
+ devtoolsOpen: true,
69
+ }),
57
70
  ).resolves.not.toThrow()
58
71
  })
59
72
 
60
73
  it('DevtoolsCore should call dispose on unmount', async () => {
61
74
  const [DevtoolsCore] = constructCoreClass(importFn)
62
75
  const instance = new DevtoolsCore()
63
- await instance.mount(document.createElement('div'), 'dark')
76
+ await instance.mount(document.createElement('div'), {
77
+ theme: 'dark',
78
+ devtoolsOpen: true,
79
+ })
64
80
  instance.unmount()
65
81
  expect(disposeMock).toHaveBeenCalled()
66
82
  })
@@ -68,7 +84,10 @@ describe('constructCoreClass', () => {
68
84
  it('DevtoolsCore should abort mount if unmount is called during mounting', async () => {
69
85
  const [DevtoolsCore] = constructCoreClass(importFn)
70
86
  const instance = new DevtoolsCore()
71
- const mountPromise = instance.mount(document.createElement('div'), 'dark')
87
+ const mountPromise = instance.mount(document.createElement('div'), {
88
+ theme: 'dark',
89
+ devtoolsOpen: true,
90
+ })
72
91
  // Unmount while mount is in progress — triggers abort path
73
92
  // Note: since the mock resolves immediately, this tests the #abortMount flag
74
93
  await mountPromise
@@ -80,16 +99,25 @@ describe('constructCoreClass', () => {
80
99
  it('NoOpDevtoolsCore should not call __mountComponent when mount is called', async () => {
81
100
  const [, NoOpDevtoolsCore] = constructCoreClass(importFn)
82
101
  const noOpInstance = new NoOpDevtoolsCore()
83
- await noOpInstance.mount(document.createElement('div'), 'dark')
102
+ await noOpInstance.mount(document.createElement('div'), {
103
+ theme: 'dark',
104
+ devtoolsOpen: true,
105
+ })
84
106
  expect(mountComponentMock).not.toHaveBeenCalled()
85
107
  })
86
108
 
87
109
  it('NoOpDevtoolsCore should not throw if mount is called multiple times', async () => {
88
110
  const [, NoOpDevtoolsCore] = constructCoreClass(importFn)
89
111
  const noOpInstance = new NoOpDevtoolsCore()
90
- await noOpInstance.mount(document.createElement('div'), 'dark')
112
+ await noOpInstance.mount(document.createElement('div'), {
113
+ theme: 'dark',
114
+ devtoolsOpen: true,
115
+ })
91
116
  await expect(
92
- noOpInstance.mount(document.createElement('div'), 'dark'),
117
+ noOpInstance.mount(document.createElement('div'), {
118
+ theme: 'dark',
119
+ devtoolsOpen: true,
120
+ }),
93
121
  ).resolves.not.toThrow()
94
122
  })
95
123
 
@@ -102,7 +130,10 @@ describe('constructCoreClass', () => {
102
130
  it('NoOpDevtoolsCore should not throw if unmount is called after mount', async () => {
103
131
  const [, NoOpDevtoolsCore] = constructCoreClass(importFn)
104
132
  const noOpInstance = new NoOpDevtoolsCore()
105
- await noOpInstance.mount(document.createElement('div'), 'dark')
133
+ await noOpInstance.mount(document.createElement('div'), {
134
+ theme: 'dark',
135
+ devtoolsOpen: true,
136
+ })
106
137
  expect(() => noOpInstance.unmount()).not.toThrow()
107
138
  })
108
139
  })
@@ -1,3 +1,4 @@
1
+ import type { TanStackDevtoolsPluginProps } from '@tanstack/devtools'
1
2
  import type { JSX } from 'solid-js'
2
3
 
3
4
  /**
@@ -10,7 +11,9 @@ import type { JSX } from 'solid-js'
10
11
  * @returns Tuple containing the DevtoolsCore class and a NoOpDevtoolsCore class
11
12
  */
12
13
  export function constructCoreClass(
13
- importFn: () => Promise<{ default: () => JSX.Element }>,
14
+ importFn: () => Promise<{
15
+ default: (props: TanStackDevtoolsPluginProps) => JSX.Element
16
+ }>,
14
17
  ) {
15
18
  class DevtoolsCore {
16
19
  #isMounted = false
@@ -20,7 +23,10 @@ export function constructCoreClass(
20
23
 
21
24
  constructor() {}
22
25
 
23
- async mount<T extends HTMLElement>(el: T, theme: 'light' | 'dark') {
26
+ async mount<T extends HTMLElement>(
27
+ el: T,
28
+ props: TanStackDevtoolsPluginProps,
29
+ ) {
24
30
  if (this.#isMounted || this.#isMounting) {
25
31
  throw new Error('Devtools is already mounted')
26
32
  }
@@ -35,7 +41,7 @@ export function constructCoreClass(
35
41
  return
36
42
  }
37
43
 
38
- this.#dispose = __mountComponent(el, theme, importFn)
44
+ this.#dispose = __mountComponent(el, props, importFn)
39
45
  this.#isMounted = true
40
46
  this.#isMounting = false
41
47
  } catch (err) {
@@ -48,11 +54,13 @@ export function constructCoreClass(
48
54
  if (!this.#isMounted && !this.#isMounting) {
49
55
  throw new Error('Devtools is not mounted')
50
56
  }
57
+
51
58
  if (this.#isMounting) {
52
59
  this.#abortMount = true
53
60
  this.#isMounting = false
54
61
  return
55
62
  }
63
+
56
64
  this.#dispose?.()
57
65
  this.#isMounted = false
58
66
  }
@@ -62,7 +70,10 @@ export function constructCoreClass(
62
70
  constructor() {
63
71
  super()
64
72
  }
65
- async mount<T extends HTMLElement>(_el: T, _theme: 'light' | 'dark') {}
73
+ async mount<T extends HTMLElement>(
74
+ _el: T,
75
+ _props: TanStackDevtoolsPluginProps,
76
+ ) {}
66
77
  unmount() {}
67
78
  }
68
79
 
@@ -2,20 +2,19 @@
2
2
 
3
3
  import { createSignal, onCleanup, onMount } from 'solid-js'
4
4
  import type { ClassType } from './class'
5
+ import type { TanStackDevtoolsPluginProps } from '@tanstack/devtools'
5
6
 
6
- export interface DevtoolsPanelProps {
7
- theme?: 'light' | 'dark'
8
- }
7
+ export interface DevtoolsPanelProps extends TanStackDevtoolsPluginProps {}
9
8
 
10
- export function createSolidPanel<
11
- TComponentProps extends DevtoolsPanelProps | undefined,
12
- >(CoreClass: ClassType) {
9
+ export function createSolidPanel<TComponentProps extends DevtoolsPanelProps>(
10
+ CoreClass: ClassType,
11
+ ) {
13
12
  function Panel(props: TComponentProps) {
14
13
  let devToolRef: HTMLDivElement | undefined
15
14
  const [devtools] = createSignal(new CoreClass())
16
15
  onMount(() => {
17
16
  if (devToolRef) {
18
- devtools().mount(devToolRef, props?.theme ?? 'dark')
17
+ devtools().mount(devToolRef, props)
19
18
  }
20
19
  onCleanup(() => {
21
20
  devtools().unmount()
@@ -2,6 +2,7 @@
2
2
 
3
3
  import type { JSX } from 'solid-js'
4
4
  import type { DevtoolsPanelProps } from './panel'
5
+ import type { TanStackDevtoolsPluginProps } from '@tanstack/devtools'
5
6
 
6
7
  export function createSolidPlugin({
7
8
  Component,
@@ -15,15 +16,15 @@ export function createSolidPlugin({
15
16
  function Plugin() {
16
17
  return {
17
18
  ...config,
18
- render: (_el: HTMLElement, theme: 'light' | 'dark') => {
19
- return <Component theme={theme} />
19
+ render: (_el: HTMLElement, props: TanStackDevtoolsPluginProps) => {
20
+ return <Component {...props} />
20
21
  },
21
22
  }
22
23
  }
23
24
  function NoOpPlugin() {
24
25
  return {
25
26
  ...config,
26
- render: (_el: HTMLElement, _theme: 'light' | 'dark') => <></>,
27
+ render: (_el: HTMLElement, _props: TanStackDevtoolsPluginProps) => <></>,
27
28
  }
28
29
  }
29
30
  return [Plugin, NoOpPlugin] as const
package/src/vue/panel.ts CHANGED
@@ -1,20 +1,19 @@
1
1
  import { defineComponent, h, onMounted, onUnmounted, ref } from 'vue'
2
+ import type { TanStackDevtoolsPluginProps } from '@tanstack/devtools'
2
3
  import type { DefineComponent } from 'vue'
3
4
 
4
- export interface DevtoolsPanelProps {
5
- theme?: 'dark' | 'light' | 'system'
6
- }
5
+ export interface DevtoolsPanelProps extends TanStackDevtoolsPluginProps {}
7
6
 
8
7
  export function createVuePanel<
9
8
  TComponentProps extends DevtoolsPanelProps,
10
9
  TCoreDevtoolsClass extends {
11
- mount: (el: HTMLElement, theme?: DevtoolsPanelProps['theme']) => void
10
+ mount: (el: HTMLElement, props?: TanStackDevtoolsPluginProps) => void
12
11
  unmount: () => void
13
12
  },
14
13
  >(CoreClass: new (props: TComponentProps) => TCoreDevtoolsClass) {
15
14
  const props = {
16
- theme: {
17
- type: String as () => DevtoolsPanelProps['theme'],
15
+ props: {
16
+ type: Object as () => DevtoolsPanelProps,
18
17
  },
19
18
  devtoolsProps: {
20
19
  type: Object as () => TComponentProps,
@@ -32,7 +31,7 @@ export function createVuePanel<
32
31
  devtools.value = instance
33
32
 
34
33
  if (devToolRef.value) {
35
- instance.mount(devToolRef.value, config.theme)
34
+ instance.mount(devToolRef.value, config.props)
36
35
  }
37
36
  })
38
37
 
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -1 +0,0 @@
1
- export { __mountComponent } from '../chunk/UX5ZZ4MG.js';
@@ -1 +0,0 @@
1
- export { __mountComponent } from '../chunk/ZXPCWXRH.js';
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}