@tanstack/preact-devtools 0.9.17 → 0.10.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/dist/esm/devtools.d.ts +3 -3
- package/dist/esm/devtools.js +99 -116
- package/dist/esm/devtools.js.map +1 -1
- package/dist/esm/index.js +7 -5
- package/dist/esm/index.js.map +1 -1
- package/package.json +3 -3
- package/src/devtools.tsx +6 -4
package/dist/esm/devtools.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { JSX } from 'preact';
|
|
2
|
-
import { ClientEventBusConfig, TanStackDevtoolsConfig, TanStackDevtoolsPlugin } from '@tanstack/devtools';
|
|
3
|
-
type PluginRender = JSX.Element | ((el: HTMLElement,
|
|
2
|
+
import { ClientEventBusConfig, TanStackDevtoolsConfig, TanStackDevtoolsPlugin, TanStackDevtoolsPluginProps, TanStackDevtoolsTheme } from '@tanstack/devtools';
|
|
3
|
+
type PluginRender = JSX.Element | ((el: HTMLElement, props: TanStackDevtoolsPluginProps) => JSX.Element);
|
|
4
4
|
type TriggerProps = {
|
|
5
|
-
theme:
|
|
5
|
+
theme: TanStackDevtoolsTheme;
|
|
6
6
|
};
|
|
7
7
|
type TriggerRender = JSX.Element | ((el: HTMLElement, props: TriggerProps) => JSX.Element);
|
|
8
8
|
export type TanStackDevtoolsPreactPlugin = Omit<TanStackDevtoolsPlugin, 'render' | 'name'> & {
|
package/dist/esm/devtools.js
CHANGED
|
@@ -1,122 +1,105 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { useRef, useState, useMemo, useEffect } from "preact/hooks";
|
|
1
|
+
import { useEffect, useMemo, useRef, useState } from "preact/hooks";
|
|
3
2
|
import { render } from "preact";
|
|
4
3
|
import { TanStackDevtoolsCore } from "@tanstack/devtools";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return null;
|
|
4
|
+
import { Fragment, jsx, jsxs } from "preact/jsx-runtime";
|
|
5
|
+
//#region src/devtools.tsx
|
|
6
|
+
function Portal({ children, container }) {
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
render(children, container);
|
|
9
|
+
return () => {
|
|
10
|
+
render(null, container);
|
|
11
|
+
};
|
|
12
|
+
}, [children, container]);
|
|
13
|
+
return null;
|
|
16
14
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
var convertRender = (Component, setComponents, e, props) => {
|
|
16
|
+
const element = typeof Component === "function" ? Component(e, props) : Component;
|
|
17
|
+
setComponents((prev) => ({
|
|
18
|
+
...prev,
|
|
19
|
+
[e.getAttribute("id")]: element
|
|
20
|
+
}));
|
|
23
21
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
setComponent(element);
|
|
22
|
+
var convertTrigger = (Component, setComponent, e, props) => {
|
|
23
|
+
setComponent(typeof Component === "function" ? Component(e, props) : Component);
|
|
27
24
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const hasPlugins = Object.values(pluginContainers).length > 0 && Object.values(PluginComponents).length > 0;
|
|
105
|
-
const hasTitles = Object.values(titleContainers).length > 0 && Object.values(TitleComponents).length > 0;
|
|
106
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
107
|
-
/* @__PURE__ */ jsx("div", { style: { position: "absolute" }, ref: devToolRef }),
|
|
108
|
-
hasPlugins ? Object.entries(pluginContainers).map(([key, pluginContainer]) => {
|
|
109
|
-
const component = PluginComponents[key];
|
|
110
|
-
return component ? /* @__PURE__ */ jsx(Portal, { container: pluginContainer, children: component }, key) : null;
|
|
111
|
-
}) : null,
|
|
112
|
-
hasTitles ? Object.entries(titleContainers).map(([key, titleContainer]) => {
|
|
113
|
-
const component = TitleComponents[key];
|
|
114
|
-
return component ? /* @__PURE__ */ jsx(Portal, { container: titleContainer, children: component }, key) : null;
|
|
115
|
-
}) : null,
|
|
116
|
-
triggerContainer && TriggerComponent ? /* @__PURE__ */ jsx(Portal, { container: triggerContainer, children: TriggerComponent }) : null
|
|
117
|
-
] });
|
|
25
|
+
var TanStackDevtools = ({ plugins, config, eventBusConfig }) => {
|
|
26
|
+
const devToolRef = useRef(null);
|
|
27
|
+
const [pluginContainers, setPluginContainers] = useState({});
|
|
28
|
+
const [titleContainers, setTitleContainers] = useState({});
|
|
29
|
+
const [triggerContainer, setTriggerContainer] = useState(null);
|
|
30
|
+
const [PluginComponents, setPluginComponents] = useState({});
|
|
31
|
+
const [TitleComponents, setTitleComponents] = useState({});
|
|
32
|
+
const [TriggerComponent, setTriggerComponent] = useState(null);
|
|
33
|
+
const pluginsMap = useMemo(() => plugins?.map((plugin) => {
|
|
34
|
+
return {
|
|
35
|
+
...plugin,
|
|
36
|
+
name: typeof plugin.name === "string" ? plugin.name : (e, theme) => {
|
|
37
|
+
const id = e.getAttribute("id");
|
|
38
|
+
if (e.ownerDocument.getElementById(id)) setTitleContainers((prev) => ({
|
|
39
|
+
...prev,
|
|
40
|
+
[id]: e
|
|
41
|
+
}));
|
|
42
|
+
convertRender(plugin.name, setTitleComponents, e, theme);
|
|
43
|
+
},
|
|
44
|
+
render: (e, theme) => {
|
|
45
|
+
const id = e.getAttribute("id");
|
|
46
|
+
if (e.ownerDocument.getElementById(id)) setPluginContainers((prev) => ({
|
|
47
|
+
...prev,
|
|
48
|
+
[id]: e
|
|
49
|
+
}));
|
|
50
|
+
convertRender(plugin.render, setPluginComponents, e, theme);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}) ?? [], [plugins]);
|
|
54
|
+
const [devtools] = useState(() => {
|
|
55
|
+
const { customTrigger, ...coreConfig } = config || {};
|
|
56
|
+
return new TanStackDevtoolsCore({
|
|
57
|
+
config: {
|
|
58
|
+
...coreConfig,
|
|
59
|
+
customTrigger: customTrigger ? (el, props) => {
|
|
60
|
+
setTriggerContainer(el);
|
|
61
|
+
convertTrigger(customTrigger, setTriggerComponent, el, props);
|
|
62
|
+
} : void 0
|
|
63
|
+
},
|
|
64
|
+
eventBusConfig,
|
|
65
|
+
plugins: pluginsMap
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
devtools.setConfig({ plugins: pluginsMap });
|
|
70
|
+
}, [devtools, pluginsMap]);
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
if (devToolRef.current) devtools.mount(devToolRef.current);
|
|
73
|
+
return () => devtools.unmount();
|
|
74
|
+
}, [devtools]);
|
|
75
|
+
const hasPlugins = Object.values(pluginContainers).length > 0 && Object.values(PluginComponents).length > 0;
|
|
76
|
+
const hasTitles = Object.values(titleContainers).length > 0 && Object.values(TitleComponents).length > 0;
|
|
77
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
78
|
+
/* @__PURE__ */ jsx("div", {
|
|
79
|
+
style: { position: "absolute" },
|
|
80
|
+
ref: devToolRef
|
|
81
|
+
}),
|
|
82
|
+
hasPlugins ? Object.entries(pluginContainers).map(([key, pluginContainer]) => {
|
|
83
|
+
const component = PluginComponents[key];
|
|
84
|
+
return component ? /* @__PURE__ */ jsx(Portal, {
|
|
85
|
+
container: pluginContainer,
|
|
86
|
+
children: component
|
|
87
|
+
}, key) : null;
|
|
88
|
+
}) : null,
|
|
89
|
+
hasTitles ? Object.entries(titleContainers).map(([key, titleContainer]) => {
|
|
90
|
+
const component = TitleComponents[key];
|
|
91
|
+
return component ? /* @__PURE__ */ jsx(Portal, {
|
|
92
|
+
container: titleContainer,
|
|
93
|
+
children: component
|
|
94
|
+
}, key) : null;
|
|
95
|
+
}) : null,
|
|
96
|
+
triggerContainer && TriggerComponent ? /* @__PURE__ */ jsx(Portal, {
|
|
97
|
+
container: triggerContainer,
|
|
98
|
+
children: TriggerComponent
|
|
99
|
+
}) : null
|
|
100
|
+
] });
|
|
118
101
|
};
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
//# sourceMappingURL=devtools.js.map
|
|
102
|
+
//#endregion
|
|
103
|
+
export { TanStackDevtools };
|
|
104
|
+
|
|
105
|
+
//# 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 { useEffect, useMemo, useRef, useState } from 'preact/hooks'\nimport { render } from 'preact'\nimport { TanStackDevtoolsCore } from '@tanstack/devtools'\nimport type { JSX } from 'preact'\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\ntype TriggerProps = {\n theme: 'dark' | 'light'\n}\n\ntype TriggerRender =\n | JSX.Element\n | ((el: HTMLElement, props: TriggerProps) => JSX.Element)\n\nexport type TanStackDevtoolsPreactPlugin = Omit<\n TanStackDevtoolsPlugin,\n 'render' | 'name'\n> & {\n /**\n * The render function can be a Preact element or a function that returns a Preact 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\ntype TanStackDevtoolsPreactConfig = Omit<\n Partial<TanStackDevtoolsConfig>,\n 'customTrigger'\n> & {\n /**\n * Optional custom trigger component for the devtools.\n * It can be a Preact element or a function that renders one.\n *\n * Example:\n * ```jsx\n * {\n * customTrigger: <CustomTriggerComponent />,\n * }\n * ```\n */\n customTrigger?: TriggerRender\n}\n\nexport interface TanStackDevtoolsPreactInit {\n /**\n * Array of plugins to be used in the devtools.\n * Each plugin should have a `render` function that returns a Preact 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<TanStackDevtoolsPreactPlugin>\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?: TanStackDevtoolsPreactConfig\n /**\n * Configuration for the TanStack Devtools client event bus.\n */\n eventBusConfig?: ClientEventBusConfig\n}\n\n// Simple portal component for Preact\nfunction Portal({\n children,\n container,\n}: {\n children: JSX.Element\n container: HTMLElement\n}) {\n useEffect(() => {\n render(children, container)\n return () => {\n render(null, container)\n }\n }, [children, container])\n\n return null\n}\n\nconst convertRender = (\n Component: PluginRender,\n setComponents: (\n value:\n | Record<string, JSX.Element>\n | ((prev: Record<string, JSX.Element>) => Record<string, JSX.Element>),\n ) => void,\n e: HTMLElement,\n theme: 'dark' | 'light',\n) => {\n const element =\n typeof Component === 'function' ? Component(e, theme) : Component\n\n setComponents((prev) => ({\n ...prev,\n [e.getAttribute('id') as string]: element,\n }))\n}\n\nconst convertTrigger = (\n Component: TriggerRender,\n setComponent: (component: JSX.Element | null) => void,\n e: HTMLElement,\n props: TriggerProps,\n) => {\n const element =\n typeof Component === 'function' ? Component(e, props) : Component\n setComponent(element)\n}\n\nexport const TanStackDevtools = ({\n plugins,\n config,\n eventBusConfig,\n}: TanStackDevtoolsPreactInit): JSX.Element | null => {\n const devToolRef = useRef<HTMLDivElement>(null)\n\n const [pluginContainers, setPluginContainers] = useState<\n Record<string, HTMLElement>\n >({})\n const [titleContainers, setTitleContainers] = useState<\n Record<string, HTMLElement>\n >({})\n const [triggerContainer, setTriggerContainer] = useState<HTMLElement | null>(\n null,\n )\n\n const [PluginComponents, setPluginComponents] = useState<\n Record<string, JSX.Element>\n >({})\n const [TitleComponents, setTitleComponents] = useState<\n Record<string, JSX.Element>\n >({})\n const [TriggerComponent, setTriggerComponent] = useState<JSX.Element | null>(\n null,\n )\n\n const pluginsMap: Array<TanStackDevtoolsPlugin> = useMemo(\n () =>\n plugins?.map((plugin) => {\n return {\n ...plugin,\n name:\n typeof plugin.name === 'string'\n ? plugin.name\n : (e, theme) => {\n const id = e.getAttribute('id')!\n const target = e.ownerDocument.getElementById(id)\n\n if (target) {\n setTitleContainers((prev) => ({\n ...prev,\n [id]: e,\n }))\n }\n\n convertRender(\n plugin.name as PluginRender,\n setTitleComponents,\n e,\n theme,\n )\n },\n render: (e, theme) => {\n const id = e.getAttribute('id')!\n const target = e.ownerDocument.getElementById(id)\n\n if (target) {\n setPluginContainers((prev) => ({\n ...prev,\n [id]: e,\n }))\n }\n\n convertRender(plugin.render, setPluginComponents, e, theme)\n },\n }\n }) ?? [],\n [plugins],\n )\n\n const [devtools] = useState(() => {\n const { customTrigger, ...coreConfig } = config || {}\n return new TanStackDevtoolsCore({\n config: {\n ...coreConfig,\n customTrigger: customTrigger\n ? (el, props) => {\n setTriggerContainer(el)\n convertTrigger(customTrigger, setTriggerComponent, el, props)\n }\n : undefined,\n },\n eventBusConfig,\n plugins: pluginsMap,\n })\n })\n\n useEffect(() => {\n devtools.setConfig({\n plugins: pluginsMap,\n })\n }, [devtools, pluginsMap])\n\n useEffect(() => {\n if (devToolRef.current) {\n devtools.mount(devToolRef.current)\n }\n\n return () => devtools.unmount()\n }, [devtools])\n\n const hasPlugins =\n Object.values(pluginContainers).length > 0 &&\n Object.values(PluginComponents).length > 0\n const hasTitles =\n Object.values(titleContainers).length > 0 &&\n Object.values(TitleComponents).length > 0\n\n return (\n <>\n <div style={{ position: 'absolute' }} ref={devToolRef} />\n\n {hasPlugins\n ? Object.entries(pluginContainers).map(([key, pluginContainer]) => {\n const component = PluginComponents[key]\n return component ? (\n <Portal key={key} container={pluginContainer}>\n {component}\n </Portal>\n ) : null\n })\n : null}\n\n {hasTitles\n ? Object.entries(titleContainers).map(([key, titleContainer]) => {\n const component = TitleComponents[key]\n return component ? (\n <Portal key={key} container={titleContainer}>\n {component}\n </Portal>\n ) : null\n })\n : null}\n\n {triggerContainer && TriggerComponent ? (\n <Portal container={triggerContainer}>{TriggerComponent}</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M,SAAS,QAAA;AAAA,EACxB,GAAG,CAAC,QAAQ,CAAC;AAEb,QAAM,aACJ,OAAO,OAAO,gBAAgB,EAAE,SAAS,KACzC,OAAO,OAAO,gBAAgB,EAAE,SAAS;AAC3C,QAAM,YACJ,OAAO,OAAO,eAAe,EAAE,SAAS,KACxC,OAAO,OAAO,eAAe,EAAE,SAAS;AAE1C,SACE,qBAAA,UAAA,EACE,UAAA;AAAA,IAAA,oBAAC,SAAI,OAAO,EAAE,UAAU,WAAA,GAAc,KAAK,YAAY;AAAA,IAEtD,aACG,OAAO,QAAQ,gBAAgB,EAAE,IAAI,CAAC,CAAC,KAAK,eAAe,MAAM;AAC/D,YAAM,YAAY,iBAAiB,GAAG;AACtC,aAAO,YACL,oBAAC,QAAA,EAAiB,WAAW,iBAC1B,UAAA,UAAA,GADU,GAEb,IACE;AAAA,IACN,CAAC,IACD;AAAA,IAEH,YACG,OAAO,QAAQ,eAAe,EAAE,IAAI,CAAC,CAAC,KAAK,cAAc,MAAM;AAC7D,YAAM,YAAY,gBAAgB,GAAG;AACrC,aAAO,YACL,oBAAC,QAAA,EAAiB,WAAW,gBAC1B,UAAA,UAAA,GADU,GAEb,IACE;AAAA,IACN,CAAC,IACD;AAAA,IAEH,oBAAoB,mBACnB,oBAAC,UAAO,WAAW,kBAAmB,4BAAiB,IACrD;AAAA,EAAA,GACN;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"devtools.js","names":[],"sources":["../../src/devtools.tsx"],"sourcesContent":["import { useEffect, useMemo, useRef, useState } from 'preact/hooks'\nimport { render } from 'preact'\nimport { TanStackDevtoolsCore } from '@tanstack/devtools'\nimport type { JSX } from 'preact'\nimport type {\n ClientEventBusConfig,\n TanStackDevtoolsConfig,\n TanStackDevtoolsPlugin,\n TanStackDevtoolsPluginProps,\n TanStackDevtoolsTheme,\n} from '@tanstack/devtools'\n\ntype PluginRender =\n | JSX.Element\n | ((el: HTMLElement, props: TanStackDevtoolsPluginProps) => JSX.Element)\n\ntype TriggerProps = {\n theme: TanStackDevtoolsTheme\n}\n\ntype TriggerRender =\n | JSX.Element\n | ((el: HTMLElement, props: TriggerProps) => JSX.Element)\n\nexport type TanStackDevtoolsPreactPlugin = Omit<\n TanStackDevtoolsPlugin,\n 'render' | 'name'\n> & {\n /**\n * The render function can be a Preact element or a function that returns a Preact 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\ntype TanStackDevtoolsPreactConfig = Omit<\n Partial<TanStackDevtoolsConfig>,\n 'customTrigger'\n> & {\n /**\n * Optional custom trigger component for the devtools.\n * It can be a Preact element or a function that renders one.\n *\n * Example:\n * ```jsx\n * {\n * customTrigger: <CustomTriggerComponent />,\n * }\n * ```\n */\n customTrigger?: TriggerRender\n}\n\nexport interface TanStackDevtoolsPreactInit {\n /**\n * Array of plugins to be used in the devtools.\n * Each plugin should have a `render` function that returns a Preact 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<TanStackDevtoolsPreactPlugin>\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?: TanStackDevtoolsPreactConfig\n /**\n * Configuration for the TanStack Devtools client event bus.\n */\n eventBusConfig?: ClientEventBusConfig\n}\n\n// Simple portal component for Preact\nfunction Portal({\n children,\n container,\n}: {\n children: JSX.Element\n container: HTMLElement\n}) {\n useEffect(() => {\n render(children, container)\n return () => {\n render(null, container)\n }\n }, [children, container])\n\n return null\n}\n\nconst convertRender = (\n Component: PluginRender,\n setComponents: (\n value:\n | Record<string, JSX.Element>\n | ((prev: Record<string, JSX.Element>) => Record<string, JSX.Element>),\n ) => void,\n e: HTMLElement,\n props: TanStackDevtoolsPluginProps,\n) => {\n const element =\n typeof Component === 'function' ? Component(e, props) : Component\n\n setComponents((prev) => ({\n ...prev,\n [e.getAttribute('id') as string]: element,\n }))\n}\n\nconst convertTrigger = (\n Component: TriggerRender,\n setComponent: (component: JSX.Element | null) => void,\n e: HTMLElement,\n props: TriggerProps,\n) => {\n const element =\n typeof Component === 'function' ? Component(e, props) : Component\n setComponent(element)\n}\n\nexport const TanStackDevtools = ({\n plugins,\n config,\n eventBusConfig,\n}: TanStackDevtoolsPreactInit): JSX.Element | null => {\n const devToolRef = useRef<HTMLDivElement>(null)\n\n const [pluginContainers, setPluginContainers] = useState<\n Record<string, HTMLElement>\n >({})\n const [titleContainers, setTitleContainers] = useState<\n Record<string, HTMLElement>\n >({})\n const [triggerContainer, setTriggerContainer] = useState<HTMLElement | null>(\n null,\n )\n\n const [PluginComponents, setPluginComponents] = useState<\n Record<string, JSX.Element>\n >({})\n const [TitleComponents, setTitleComponents] = useState<\n Record<string, JSX.Element>\n >({})\n const [TriggerComponent, setTriggerComponent] = useState<JSX.Element | null>(\n null,\n )\n\n const pluginsMap: Array<TanStackDevtoolsPlugin> = useMemo(\n () =>\n plugins?.map((plugin) => {\n return {\n ...plugin,\n name:\n typeof plugin.name === 'string'\n ? plugin.name\n : (e, theme) => {\n const id = e.getAttribute('id')!\n const target = e.ownerDocument.getElementById(id)\n\n if (target) {\n setTitleContainers((prev) => ({\n ...prev,\n [id]: e,\n }))\n }\n\n convertRender(\n plugin.name as PluginRender,\n setTitleComponents,\n e,\n theme,\n )\n },\n render: (e, theme) => {\n const id = e.getAttribute('id')!\n const target = e.ownerDocument.getElementById(id)\n\n if (target) {\n setPluginContainers((prev) => ({\n ...prev,\n [id]: e,\n }))\n }\n\n convertRender(plugin.render, setPluginComponents, e, theme)\n },\n }\n }) ?? [],\n [plugins],\n )\n\n const [devtools] = useState(() => {\n const { customTrigger, ...coreConfig } = config || {}\n return new TanStackDevtoolsCore({\n config: {\n ...coreConfig,\n customTrigger: customTrigger\n ? (el, props) => {\n setTriggerContainer(el)\n convertTrigger(customTrigger, setTriggerComponent, el, props)\n }\n : undefined,\n },\n eventBusConfig,\n plugins: pluginsMap,\n })\n })\n\n useEffect(() => {\n devtools.setConfig({\n plugins: pluginsMap,\n })\n }, [devtools, pluginsMap])\n\n useEffect(() => {\n if (devToolRef.current) {\n devtools.mount(devToolRef.current)\n }\n\n return () => devtools.unmount()\n }, [devtools])\n\n const hasPlugins =\n Object.values(pluginContainers).length > 0 &&\n Object.values(PluginComponents).length > 0\n const hasTitles =\n Object.values(titleContainers).length > 0 &&\n Object.values(TitleComponents).length > 0\n\n return (\n <>\n <div style={{ position: 'absolute' }} ref={devToolRef} />\n\n {hasPlugins\n ? Object.entries(pluginContainers).map(([key, pluginContainer]) => {\n const component = PluginComponents[key]\n return component ? (\n <Portal key={key} container={pluginContainer}>\n {component}\n </Portal>\n ) : null\n })\n : null}\n\n {hasTitles\n ? Object.entries(titleContainers).map(([key, titleContainer]) => {\n const component = TitleComponents[key]\n return component ? (\n <Portal key={key} container={titleContainer}>\n {component}\n </Portal>\n ) : null\n })\n : null}\n\n {triggerContainer && TriggerComponent ? (\n <Portal container={triggerContainer}>{TriggerComponent}</Portal>\n ) : null}\n </>\n )\n}\n"],"mappings":";;;;;AAuHA,SAAS,OAAO,EACd,UACA,aAIC;AACD,iBAAgB;AACd,SAAO,UAAU,UAAU;AAC3B,eAAa;AACX,UAAO,MAAM,UAAU;;IAExB,CAAC,UAAU,U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
|
|
|
1
1
|
"use client";
|
|
2
|
+
"use client";
|
|
2
3
|
import { TanStackDevtools as TanStackDevtools$1 } from "./devtools.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
|
|
4
|
+
//#region src/index.ts
|
|
5
|
+
var TanStackDevtools = TanStackDevtools$1;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { TanStackDevtools };
|
|
8
|
+
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["'use client'\n\nimport * as Devtools from './devtools'\n\nexport const TanStackDevtools = Devtools.TanStackDevtools\n\nexport type {\n TanStackDevtoolsPreactPlugin,\n TanStackDevtoolsPreactInit,\n} from './devtools'\n"],"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/index.ts"],"sourcesContent":["'use client'\n\nimport * as Devtools from './devtools'\n\nexport const TanStackDevtools = Devtools.TanStackDevtools\n\nexport type {\n TanStackDevtoolsPreactPlugin,\n TanStackDevtoolsPreactInit,\n} from './devtools'\n"],"mappings":";;;;AAIA,IAAA,mBAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/preact-devtools",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "TanStack Devtools is a set of tools for building advanced devtools for your Preact application.",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,10 +39,10 @@
|
|
|
39
39
|
"src"
|
|
40
40
|
],
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@tanstack/devtools": "0.
|
|
42
|
+
"@tanstack/devtools": "0.11.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@preact/preset-vite": "^2.10.
|
|
45
|
+
"@preact/preset-vite": "^2.10.3",
|
|
46
46
|
"eslint-plugin-react-hooks": "^7.0.1",
|
|
47
47
|
"preact": "^10.28.0"
|
|
48
48
|
},
|
package/src/devtools.tsx
CHANGED
|
@@ -6,14 +6,16 @@ import type {
|
|
|
6
6
|
ClientEventBusConfig,
|
|
7
7
|
TanStackDevtoolsConfig,
|
|
8
8
|
TanStackDevtoolsPlugin,
|
|
9
|
+
TanStackDevtoolsPluginProps,
|
|
10
|
+
TanStackDevtoolsTheme,
|
|
9
11
|
} from '@tanstack/devtools'
|
|
10
12
|
|
|
11
13
|
type PluginRender =
|
|
12
14
|
| JSX.Element
|
|
13
|
-
| ((el: HTMLElement,
|
|
15
|
+
| ((el: HTMLElement, props: TanStackDevtoolsPluginProps) => JSX.Element)
|
|
14
16
|
|
|
15
17
|
type TriggerProps = {
|
|
16
|
-
theme:
|
|
18
|
+
theme: TanStackDevtoolsTheme
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
type TriggerRender =
|
|
@@ -140,10 +142,10 @@ const convertRender = (
|
|
|
140
142
|
| ((prev: Record<string, JSX.Element>) => Record<string, JSX.Element>),
|
|
141
143
|
) => void,
|
|
142
144
|
e: HTMLElement,
|
|
143
|
-
|
|
145
|
+
props: TanStackDevtoolsPluginProps,
|
|
144
146
|
) => {
|
|
145
147
|
const element =
|
|
146
|
-
typeof Component === 'function' ? Component(e,
|
|
148
|
+
typeof Component === 'function' ? Component(e, props) : Component
|
|
147
149
|
|
|
148
150
|
setComponents((prev) => ({
|
|
149
151
|
...prev,
|