@tanstack/devtools-utils
Version:
TanStack Devtools utilities for creating your own devtools.
96 lines (93 loc) • 2.4 kB
JavaScript
export { __mountComponent } from './chunk/WUD4VD3N.js';
import { ssr, ssrStyleProperty, createComponent } from 'solid-js/web';
import { createSignal, onMount, onCleanup } from 'solid-js';
// src/solid/class.ts
function constructCoreClass(importFn) {
class DevtoolsCore {
#isMounted = false;
#isMounting = false;
#abortMount = false;
#dispose;
constructor() {
}
async mount(el, props) {
if (this.#isMounted || this.#isMounting) {
throw new Error("Devtools is already mounted");
}
this.#isMounting = true;
this.#abortMount = false;
try {
const { __mountComponent: __mountComponent2 } = await import('./class-mount-impl/5TF6RAHJ.js');
if (this.#abortMount) {
this.#isMounting = false;
return;
}
this.#dispose = __mountComponent2(el, props, importFn);
this.#isMounted = true;
this.#isMounting = false;
} catch (err) {
this.#isMounting = false;
console.error("[TanStack Devtools] Failed to load:", err);
}
}
unmount() {
if (!this.#isMounted && !this.#isMounting) {
throw new Error("Devtools is not mounted");
}
if (this.#isMounting) {
this.#abortMount = true;
this.#isMounting = false;
return;
}
this.#dispose?.();
this.#isMounted = false;
}
}
class NoOpDevtoolsCore extends DevtoolsCore {
constructor() {
super();
}
async mount(_el, _props) {
}
unmount() {
}
}
return [DevtoolsCore, NoOpDevtoolsCore];
}
var _tmpl$ = ['<div style="', '"></div>'];
function createSolidPanel(CoreClass) {
function Panel(props) {
const [devtools] = createSignal(new CoreClass());
onMount(() => {
onCleanup(() => {
devtools().unmount();
});
});
return ssr(_tmpl$, ssrStyleProperty("height:", "100%"));
}
function NoOpPanel(_props) {
return [];
}
return [Panel, NoOpPanel];
}
function createSolidPlugin({
Component,
...config
}) {
function Plugin() {
return {
...config,
render: (_el, props) => {
return createComponent(Component, props);
}
};
}
function NoOpPlugin() {
return {
...config,
render: (_el, _props) => []
};
}
return [Plugin, NoOpPlugin];
}
export { constructCoreClass, createSolidPanel, createSolidPlugin };