UNPKG

alinea

Version:
79 lines (78 loc) 2.52 kB
import { type Atom, type PrimitiveAtom } from 'jotai'; import { type FunctionComponent, type PropsWithChildren, type ReactNode } from 'react'; export interface RouteData<T> { path: string; loader?: (params: Record<string, string>) => Atom<Promise<T>>; component: FunctionComponent<T>; } export declare class Route<T = any> { data: RouteData<T>; constructor(data: RouteData<T>); get component(): FunctionComponent<T>; } export interface RouterData { routes: Array<Route>; } export declare class Router { data: RouterData; matchers: Array<{ route: Route; matcher: Atom<Record<string, string> | undefined>; }>; constructor(data: RouterData); matchingRoute: Atom<{ route: Route<any>; params: Record<string, string>; } | undefined>; matchingRouteWithData: Atom<Promise<Match>>; currentRoute: PrimitiveAtom<Match> & { init: Match; }; prevLocation: PrimitiveAtom<URL | undefined> & { init: URL | undefined; }; blockers: PrimitiveAtom<Set<PrimitiveAtom<BlockingResponse>>> & { init: Set<PrimitiveAtom<BlockingResponse>>; }; expected: Promise<Match> | undefined; cancelled: PrimitiveAtom<boolean> & { init: boolean; }; match: import("jotai").WritableAtom<Match | Promise<Match>, [Promise<Match>, Match], void>; } export interface RouterProviderProps { router: Router; } export declare function RouterProvider({ children, router }: PropsWithChildren<RouterProviderProps>): import("react/jsx-runtime").JSX.Element; export declare function useRouter(): Router; export interface RouteMatch<T = any> { route: Route<T>; data: T; params: Record<string, string>; } type Match = RouteMatch | undefined; type BlockingResponse = { nextRoute: Match; confirm(): void; cancel(): void; } | undefined; export type UseBlockerData = { isBlocking: true; nextRoute?: Match; confirm(): void; cancel(): void; } | { isBlocking: false; nextRoute: undefined; confirm: undefined; cancel: undefined; }; export declare function useRouteBlocker(message: string, when: boolean): UseBlockerData; export declare function useRouteMatch(): Match; export declare function useRouteParams(): Record<string, string>; export declare function useRouteRender(): ReactNode; export interface RouteViewProps { fallback?: ReactNode; } export declare function RouteView({ fallback }: RouteViewProps): import("react/jsx-runtime").JSX.Element; export {};