import { createEffect, onCleanup, onMount } from "solid-js";
import type { Catalog, Spec, StateStore } from "@json-render/core";
import { markDevtoolsActive, registerActionObserver } from "@json-render/core";
import { useStateStore } from "@json-render/solid";
import {
actionsTab,
catalogTab,
createEventStore,
createPanel,
createSelectionBus,
highlightElement,
isProduction,
scanMessageParts,
specTab,
startPicker,
stateTab,
streamTab,
type DevtoolsEvent,
type PanelHandle,
type PanelPosition,
} from "@json-render/devtools";
interface ChatLikeMessage {
parts?: Array<{ type: string; text?: string; data?: unknown }>;
}
/**
* Props for ``.
*/
export interface JsonRenderDevtoolsProps {
spec?: Spec | null;
catalog?: Catalog | null;
messages?: ChatLikeMessage[];
initialOpen?: boolean;
/**
* Where the panel docks and where the floating toggle lives.
* - `"bottom-right"` (default), `"bottom-left"` — bottom-docked drawer.
* - `"right"` — right-docked panel spanning full height; best for
* app-shell layouts that already use `100vh` / fixed bottom elements.
*/
position?: PanelPosition;
hotkey?: string | false;
bufferSize?: number;
/**
* Reserve space for the panel via body padding while open. Default `true`.
* Set `false` to keep the panel as a pure overlay; the
* `--jr-devtools-offset-bottom` / `--jr-devtools-offset-right` CSS
* custom properties are still published for apps to consume manually.
*/
reserveSpace?: boolean;
/**
* Show a toolbar button to flip the panel between bottom-dock and
* right-dock. Default `true`. The user's choice persists to
* localStorage. Set `false` to lock the dock to `position`.
*/
allowDockToggle?: boolean;
onEvent?: (evt: DevtoolsEvent) => void;
}
/**
* Drop this component anywhere inside a Solid `` to get a
* floating devtools panel. Production builds render nothing.
*/
export function JsonRenderDevtools(props: JsonRenderDevtoolsProps) {
if (isProduction()) return null;
const stateCtx = useStateStore();
const store: StateStore = {
get: stateCtx.get,
set: stateCtx.set,
update: stateCtx.update,
getSnapshot: stateCtx.getSnapshot,
subscribe: () => () => {},
};
const events = createEventStore({ bufferSize: props.bufferSize });
const seenParts = new WeakSet