@tanstack/devtools-utils 0.0.9 → 0.1.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.
@@ -0,0 +1,2 @@
1
+ export * from './panel.js';
2
+ export * from './plugin.js';
@@ -0,0 +1,7 @@
1
+ import { createPreactPanel } from "./panel.js";
2
+ import { createPreactPlugin } from "./plugin.js";
3
+ export {
4
+ createPreactPanel,
5
+ createPreactPlugin
6
+ };
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
@@ -0,0 +1,25 @@
1
+ /** @jsxImportSource preact */
2
+ export interface DevtoolsPanelProps {
3
+ theme?: 'light' | 'dark';
4
+ }
5
+ /**
6
+ * Creates a Preact component that dynamically imports and mounts a devtools panel. SSR friendly.
7
+ * @param devtoolsPackageName The name of the devtools package to be imported, e.g., '@tanstack/devtools-preact'
8
+ * @param importName The name of the export to be imported from the devtools package (e.g., 'default' or 'DevtoolsCore')
9
+ * @returns A Preact component that mounts the devtools
10
+ * @example
11
+ * ```tsx
12
+ * // if the export is default
13
+ * const [PreactDevtoolsPanel, NoOpPreactDevtoolsPanel] = createPreactPanel('@tanstack/devtools-preact')
14
+ * ```
15
+ *
16
+ * @example
17
+ * ```tsx
18
+ * // if the export is named differently
19
+ * const [PreactDevtoolsPanel, NoOpPreactDevtoolsPanel] = createPreactPanel('@tanstack/devtools-preact', 'DevtoolsCore')
20
+ * ```
21
+ */
22
+ export declare function createPreactPanel<TComponentProps extends DevtoolsPanelProps | undefined, TCoreDevtoolsClass extends {
23
+ mount: (el: HTMLElement, theme: 'light' | 'dark') => void;
24
+ unmount: () => void;
25
+ }>(CoreClass: new () => TCoreDevtoolsClass): readonly [(props: TComponentProps) => import("preact").JSX.Element, (_props: TComponentProps) => import("preact").JSX.Element];
@@ -0,0 +1,29 @@
1
+ import { jsx, Fragment } from "preact/jsx-runtime";
2
+ import { useRef, useEffect } from "preact/hooks";
3
+ function createPreactPanel(CoreClass) {
4
+ function Panel(props) {
5
+ const devToolRef = useRef(null);
6
+ const devtools = useRef(null);
7
+ useEffect(() => {
8
+ if (devtools.current) return;
9
+ devtools.current = new CoreClass();
10
+ if (devToolRef.current) {
11
+ devtools.current.mount(devToolRef.current, props?.theme ?? "dark");
12
+ }
13
+ return () => {
14
+ if (devToolRef.current) {
15
+ devtools.current?.unmount();
16
+ }
17
+ };
18
+ }, [props?.theme]);
19
+ return /* @__PURE__ */ jsx("div", { style: { height: "100%" }, ref: devToolRef });
20
+ }
21
+ function NoOpPanel(_props) {
22
+ return /* @__PURE__ */ jsx(Fragment, {});
23
+ }
24
+ return [Panel, NoOpPanel];
25
+ }
26
+ export {
27
+ createPreactPanel
28
+ };
29
+ //# sourceMappingURL=panel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"panel.js","sources":["../../../src/preact/panel.tsx"],"sourcesContent":["/** @jsxImportSource preact */\n\nimport { useEffect, useRef } from 'preact/hooks'\n\nexport interface DevtoolsPanelProps {\n theme?: 'light' | 'dark'\n}\n\n/**\n * Creates a Preact component that dynamically imports and mounts a devtools panel. SSR friendly.\n * @param devtoolsPackageName The name of the devtools package to be imported, e.g., '@tanstack/devtools-preact'\n * @param importName The name of the export to be imported from the devtools package (e.g., 'default' or 'DevtoolsCore')\n * @returns A Preact component that mounts the devtools\n * @example\n * ```tsx\n * // if the export is default\n * const [PreactDevtoolsPanel, NoOpPreactDevtoolsPanel] = createPreactPanel('@tanstack/devtools-preact')\n * ```\n *\n * @example\n * ```tsx\n * // if the export is named differently\n * const [PreactDevtoolsPanel, NoOpPreactDevtoolsPanel] = createPreactPanel('@tanstack/devtools-preact', 'DevtoolsCore')\n * ```\n */\nexport function createPreactPanel<\n TComponentProps extends DevtoolsPanelProps | undefined,\n TCoreDevtoolsClass extends {\n mount: (el: HTMLElement, theme: 'light' | 'dark') => void\n unmount: () => void\n },\n>(CoreClass: new () => TCoreDevtoolsClass) {\n function Panel(props: TComponentProps) {\n const devToolRef = useRef<HTMLDivElement>(null)\n const devtools = useRef<TCoreDevtoolsClass | null>(null)\n useEffect(() => {\n if (devtools.current) return\n\n devtools.current = new CoreClass()\n\n if (devToolRef.current) {\n devtools.current.mount(devToolRef.current, props?.theme ?? 'dark')\n }\n\n return () => {\n if (devToolRef.current) {\n devtools.current?.unmount()\n }\n }\n }, [props?.theme])\n\n return <div style={{ height: '100%' }} ref={devToolRef} />\n }\n\n function NoOpPanel(_props: TComponentProps) {\n return <></>\n }\n return [Panel, NoOpPanel] as const\n}\n"],"names":[],"mappings":";;AAyBO,SAAS,kBAMd,WAAyC;AACzC,WAAS,MAAM,OAAwB;AACrC,UAAM,aAAa,OAAuB,IAAI;AAC9C,UAAM,WAAW,OAAkC,IAAI;AACvD,cAAU,MAAM;AACd,UAAI,SAAS,QAAS;AAEtB,eAAS,UAAU,IAAI,UAAA;AAEvB,UAAI,WAAW,SAAS;AACtB,iBAAS,QAAQ,MAAM,WAAW,SAAS,OAAO,SAAS,MAAM;AAAA,MACnE;AAEA,aAAO,MAAM;AACX,YAAI,WAAW,SAAS;AACtB,mBAAS,SAAS,QAAA;AAAA,QACpB;AAAA,MACF;AAAA,IACF,GAAG,CAAC,OAAO,KAAK,CAAC;AAEjB,WAAO,oBAAC,SAAI,OAAO,EAAE,QAAQ,OAAA,GAAU,KAAK,YAAY;AAAA,EAC1D;AAEA,WAAS,UAAU,QAAyB;AAC1C,WAAO,oBAAA,UAAA,EAAE;AAAA,EACX;AACA,SAAO,CAAC,OAAO,SAAS;AAC1B;"}
@@ -0,0 +1,18 @@
1
+ import { JSX } from 'preact';
2
+ import { DevtoolsPanelProps } from './panel.js';
3
+ export declare function createPreactPlugin({ Component, ...config }: {
4
+ name: string;
5
+ id?: string;
6
+ defaultOpen?: boolean;
7
+ Component: (props: DevtoolsPanelProps) => JSX.Element;
8
+ }): readonly [() => {
9
+ render: (_el: HTMLElement, theme: "light" | "dark") => JSX.Element;
10
+ name: string;
11
+ id?: string;
12
+ defaultOpen?: boolean;
13
+ }, () => {
14
+ render: (_el: HTMLElement, _theme: "light" | "dark") => JSX.Element;
15
+ name: string;
16
+ id?: string;
17
+ defaultOpen?: boolean;
18
+ }];
@@ -0,0 +1,23 @@
1
+ import { jsx, Fragment } from "preact/jsx-runtime";
2
+ function createPreactPlugin({
3
+ Component,
4
+ ...config
5
+ }) {
6
+ function Plugin() {
7
+ return {
8
+ ...config,
9
+ render: (_el, theme) => /* @__PURE__ */ jsx(Component, { theme })
10
+ };
11
+ }
12
+ function NoOpPlugin() {
13
+ return {
14
+ ...config,
15
+ render: (_el, _theme) => /* @__PURE__ */ jsx(Fragment, {})
16
+ };
17
+ }
18
+ return [Plugin, NoOpPlugin];
19
+ }
20
+ export {
21
+ createPreactPlugin
22
+ };
23
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sources":["../../../src/preact/plugin.tsx"],"sourcesContent":["/** @jsxImportSource preact */\n\nimport type { JSX } from 'preact'\nimport type { DevtoolsPanelProps } from './panel'\n\nexport function createPreactPlugin({\n Component,\n ...config\n}: {\n name: string\n id?: string\n defaultOpen?: boolean\n Component: (props: DevtoolsPanelProps) => JSX.Element\n}) {\n function Plugin() {\n return {\n ...config,\n render: (_el: HTMLElement, theme: 'light' | 'dark') => (\n <Component theme={theme} />\n ),\n }\n }\n function NoOpPlugin() {\n return {\n ...config,\n render: (_el: HTMLElement, _theme: 'light' | 'dark') => <></>,\n }\n }\n return [Plugin, NoOpPlugin] as const\n}\n"],"names":[],"mappings":";AAKO,SAAS,mBAAmB;AAAA,EACjC;AAAA,EACA,GAAG;AACL,GAKG;AACD,WAAS,SAAS;AAChB,WAAO;AAAA,MACL,GAAG;AAAA,MACH,QAAQ,CAAC,KAAkB,UACzB,oBAAC,aAAU,MAAA,CAAc;AAAA,IAAA;AAAA,EAG/B;AACA,WAAS,aAAa;AACpB,WAAO;AAAA,MACL,GAAG;AAAA,MACH,QAAQ,CAAC,KAAkB,WAA6B,oBAAA,UAAA,CAAA,CAAE;AAAA,IAAA;AAAA,EAE9D;AACA,SAAO,CAAC,QAAQ,UAAU;AAC5B;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/devtools-utils",
3
- "version": "0.0.9",
3
+ "version": "0.1.0",
4
4
  "description": "TanStack Devtools utilities for creating your own devtools.",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -25,6 +25,12 @@
25
25
  "default": "./dist/react/esm/index.js"
26
26
  }
27
27
  },
28
+ "./preact": {
29
+ "import": {
30
+ "types": "./dist/preact/esm/index.d.ts",
31
+ "default": "./dist/preact/esm/index.js"
32
+ }
33
+ },
28
34
  "./solid": {
29
35
  "browser": {
30
36
  "development": {
@@ -52,15 +58,19 @@
52
58
  },
53
59
  "peerDependencies": {
54
60
  "@types/react": ">=17.0.0",
61
+ "preact": ">=10.0.0",
55
62
  "react": ">=17.0.0",
56
63
  "solid-js": ">=1.9.7",
57
64
  "vue": ">=3.2.0"
58
65
  },
59
66
  "peerDependenciesMeta": {
60
- "react": {
67
+ "@types/react": {
61
68
  "optional": true
62
69
  },
63
- "@types/react": {
70
+ "preact": {
71
+ "optional": true
72
+ },
73
+ "react": {
64
74
  "optional": true
65
75
  },
66
76
  "solid-js": {
@@ -87,6 +97,6 @@
87
97
  "test:lib:dev": "pnpm test:lib --watch",
88
98
  "test:types": "tsc",
89
99
  "test:build": "publint --strict",
90
- "build": "vite build && tsup "
100
+ "build": "vite build && vite build --config vite.config.preact.ts && tsup "
91
101
  }
92
102
  }
@@ -0,0 +1,2 @@
1
+ export * from './panel'
2
+ export * from './plugin'
@@ -0,0 +1,59 @@
1
+ /** @jsxImportSource preact */
2
+
3
+ import { useEffect, useRef } from 'preact/hooks'
4
+
5
+ export interface DevtoolsPanelProps {
6
+ theme?: 'light' | 'dark'
7
+ }
8
+
9
+ /**
10
+ * Creates a Preact component that dynamically imports and mounts a devtools panel. SSR friendly.
11
+ * @param devtoolsPackageName The name of the devtools package to be imported, e.g., '@tanstack/devtools-preact'
12
+ * @param importName The name of the export to be imported from the devtools package (e.g., 'default' or 'DevtoolsCore')
13
+ * @returns A Preact component that mounts the devtools
14
+ * @example
15
+ * ```tsx
16
+ * // if the export is default
17
+ * const [PreactDevtoolsPanel, NoOpPreactDevtoolsPanel] = createPreactPanel('@tanstack/devtools-preact')
18
+ * ```
19
+ *
20
+ * @example
21
+ * ```tsx
22
+ * // if the export is named differently
23
+ * const [PreactDevtoolsPanel, NoOpPreactDevtoolsPanel] = createPreactPanel('@tanstack/devtools-preact', 'DevtoolsCore')
24
+ * ```
25
+ */
26
+ export function createPreactPanel<
27
+ TComponentProps extends DevtoolsPanelProps | undefined,
28
+ TCoreDevtoolsClass extends {
29
+ mount: (el: HTMLElement, theme: 'light' | 'dark') => void
30
+ unmount: () => void
31
+ },
32
+ >(CoreClass: new () => TCoreDevtoolsClass) {
33
+ function Panel(props: TComponentProps) {
34
+ const devToolRef = useRef<HTMLDivElement>(null)
35
+ const devtools = useRef<TCoreDevtoolsClass | null>(null)
36
+ useEffect(() => {
37
+ if (devtools.current) return
38
+
39
+ devtools.current = new CoreClass()
40
+
41
+ if (devToolRef.current) {
42
+ devtools.current.mount(devToolRef.current, props?.theme ?? 'dark')
43
+ }
44
+
45
+ return () => {
46
+ if (devToolRef.current) {
47
+ devtools.current?.unmount()
48
+ }
49
+ }
50
+ }, [props?.theme])
51
+
52
+ return <div style={{ height: '100%' }} ref={devToolRef} />
53
+ }
54
+
55
+ function NoOpPanel(_props: TComponentProps) {
56
+ return <></>
57
+ }
58
+ return [Panel, NoOpPanel] as const
59
+ }
@@ -0,0 +1,30 @@
1
+ /** @jsxImportSource preact */
2
+
3
+ import type { JSX } from 'preact'
4
+ import type { DevtoolsPanelProps } from './panel'
5
+
6
+ export function createPreactPlugin({
7
+ Component,
8
+ ...config
9
+ }: {
10
+ name: string
11
+ id?: string
12
+ defaultOpen?: boolean
13
+ Component: (props: DevtoolsPanelProps) => JSX.Element
14
+ }) {
15
+ function Plugin() {
16
+ return {
17
+ ...config,
18
+ render: (_el: HTMLElement, theme: 'light' | 'dark') => (
19
+ <Component theme={theme} />
20
+ ),
21
+ }
22
+ }
23
+ function NoOpPlugin() {
24
+ return {
25
+ ...config,
26
+ render: (_el: HTMLElement, _theme: 'light' | 'dark') => <></>,
27
+ }
28
+ }
29
+ return [Plugin, NoOpPlugin] as const
30
+ }