import { PageDefinition, DialogSize } from '@judo/model-api'; import { ReactNode } from 'react'; /** * Page stack entry. */ export interface PageStackEntry { pageDefinition: PageDefinition; params?: Record; scrollPosition?: number; } /** * Dialog close result types. */ export type DialogCloseResultType = "cancelled" | "created" | "updated" | "deleted" | "selected" | "submitted"; /** * Result returned when dialog closes. * Uses discriminated union for type-safe handling of different outcomes. */ export type DialogCloseResult = { type: "cancelled"; } | { type: "created"; isEager: boolean; data?: unknown; } | { type: "updated"; data?: unknown; } | { type: "deleted"; data?: unknown; } | { type: "selected"; data?: unknown; } | { type: "submitted"; data?: unknown; }; /** * Dialog state. */ export interface DialogState { pageDefinition: PageDefinition; size: DialogSize; params?: Record; } /** * Navigation state. */ export interface NavigationState { /** Current page stack (for back navigation) */ pageStack: PageStackEntry[]; /** Current page definition */ currentPage: PageDefinition | null; /** Dialog stack — supports nested dialogs. Top of stack is the active dialog. */ dialogStack: DialogState[]; } /** * Callback invoked when dialog closes. */ export type DialogCloseCallback = (result?: DialogCloseResult) => void; /** * Navigation context type. */ export interface NavigationContextType extends NavigationState { /** Top dialog (convenience — same as dialogStack[dialogStack.length - 1] or null) */ dialog: DialogState | null; /** Navigate to page */ navigateTo: (page: PageDefinition, params?: Record) => void; /** Navigate back */ goBack: () => void; /** Open page in dialog with optional onClose callback */ openDialog: (page: PageDefinition, params?: Record, onClose?: DialogCloseCallback) => void; /** Close current dialog with optional result */ closeDialog: (result?: DialogCloseResult) => void; /** Replace current page (no stack) */ replacePage: (page: PageDefinition, params?: Record) => void; /** Clear navigation stack */ clearStack: () => void; /** Sync navigation state with current route pathname (for browser back/forward) */ syncLocation: (pathname: string) => void; /** Check if can go back */ canGoBack: boolean; } /** * Hook to access navigation context. * * @returns NavigationContextType * @throws Error if used outside NavigationProvider */ export declare function useNavigation(): NavigationContextType; /** * Hook to access navigation context (optional). * * @returns NavigationContextType | null */ export declare function useNavigationOptional(): NavigationContextType | null; /** * Props for NavigationProvider. */ export interface NavigationProviderProps { children: ReactNode; /** Initial page (optional) */ initialPage?: PageDefinition; /** Optional navigate function for React Router integration */ navigate?: (path: string, options?: { state?: unknown; replace?: boolean; }) => void; /** Optional function to get route path for a page */ getRouteForPage?: (page: PageDefinition) => string; /** * Optional resolver for the fallback route used by `goBack()` when both the * dialog stack and the page stack are empty. When provided, the returned route * is used with `{ replace: true }` so the in-app Back action always lands on * a known, app-scoped URL instead of a potentially stale browser history entry. * Defaults to `"/"` when not provided. */ getFallbackRoute?: () => string; } /** * Provider for navigation context. */ export declare function NavigationProvider({ children, initialPage, navigate, getRouteForPage, getFallbackRoute, }: NavigationProviderProps): import("react/jsx-runtime").JSX.Element; //# sourceMappingURL=navigation-context.d.ts.map