React context that bridges `useDocumentTree` viewer instances to `GlobalAskAI` components, enabling programmatic document navigation without global events or URL parsing. ## Key Components ### `DocNavigator` (interface) Represents a mounted document viewer with three members: - `baseRoute` — the URL prefix this navigator owns (e.g., `'/knowledge-base'`) - `findNodeByPath(path)` — looks up a `DocNode` by storage path - `selectNode(node)` — triggers navigation as if the user clicked a sidebar item ### `DocNavigationProvider` Context provider that maintains a `Map`. Supports multiple concurrent navigators (dual-pane, nested viewers) with longest-prefix matching to route navigation calls to the correct owner. ### `useDocNavigation()` (hook) Returns the context value with three methods: - `register(nav)` — registers a navigator; returns a StrictMode-safe cleanup function - `navigate(path)` — resolves the owning navigator and selects the node; returns `true` if handled - `isAvailable()` — returns `true` if at least one navigator is mounted ## Usage Example ```typescript // In a document viewer component import { useDocNavigation } from './doc-navigation-context' function DocViewer({ baseRoute }: { baseRoute: string }) { const { register } = useDocNavigation() useEffect(() => { const cleanup = register({ baseRoute, findNodeByPath: (path) => tree.find(path) ?? null, selectNode: (node) => setActiveNode(node), }) return cleanup }, [baseRoute, register]) } // In GlobalAskAI — navigate to a cited document function AskAI() { const { navigate, isAvailable } = useDocNavigation() const handleCitationClick = (storagePath: string) => { const handled = navigate(storagePath) if (!handled) window.open(storagePath, '_blank') } } ```