import React, { useSyncExternalStore } from 'react'; import type { ReactNode } from 'react'; import type { ToolkitHost, ToolkitHostSnapshot } from './DebugToolkit'; import { FloatPanelView } from '../ui/panel/FloatPanelView'; import { CopyActionContext } from '../ui/shared/CopyButton'; import { copyToComputer } from '../utils/copyToComputer'; const empty: ToolkitHostSnapshot = { features: [], panelOpen: false, quickActions: [] }; const emptySnapshot = () => empty; const noSubscription = () => () => {}; const disabledCopy = (text: string) => copyToComputer(text, { enabled: false, channels: {} }); /** Internal view binding. Only withDebugToolkit owns the host lifecycle. */ export function DebugToolkitProvider({ host, children }: { host: ToolkitHost | null; children: ReactNode }) { const state = useSyncExternalStore(host?.subscribe ?? noSubscription, host?.getSnapshot ?? emptySnapshot, emptySnapshot); return ( {children} {!!host && (state.features.length > 0 || state.quickActions.length > 0) && ( host.actions.clear()} /> )} ); }