| 1 | import { useLayoutEffect, useState, useSyncExternalStore } from "react"; |
| 2 | import { DockNavigation, type DockRequests } from "./dockNavigation"; |
| 3 | |
| 4 | export function useDockViewRequests(scope: string, view: string | null, incoming: DockRequests, owner?: DockNavigation, openViews?: readonly string[]): DockRequests { |
| 5 | const [local] = useState(() => new DockNavigation()); |
| 6 | const navigation = owner ?? local; |
| 7 | const snapshot = useSyncExternalStore(navigation.subscribe, navigation.getSnapshot, navigation.getSnapshot); |
| 8 | useLayoutEffect(() => { navigation.commit(scope, view, incoming, openViews); }); |
| 9 | useLayoutEffect(() => owner ? undefined : local.attach(), [local, owner]); |
| 10 | return view && navigation.matches(scope, view) ? snapshot : navigation.restoredView(scope, view); |
| 11 | } |
| 12 |