import { useSyncExternalStore } from 'react'; // Which character the floating character panel is showing, if it is open. // Kept outside React so that any page — an encounter card, say — can open the // panel for a particular character without being wired to the layout. let openId: string | null = null; const listeners = new Set<() => void>(); function set(id: string | null) { openId = id; listeners.forEach((listener) => listener()); } function subscribe(listener: () => void) { listeners.add(listener); return () => listeners.delete(listener); } export function openCharacterPanel(characterId: string) { set(characterId); } export function closeCharacterPanel() { set(null); } export function useCharacterPanelId(): string | null { return useSyncExternalStore(subscribe, () => openId); }