UNPKG

5.02 kBTypeScriptView Raw
1
2import { Action, History, Location, To } from "./router/history.js";
3import { RouteMatch, TrackedPromise } from "./router/utils.js";
4import { RelativeRoutingType, Router, StaticHandlerContext } from "./router/router.js";
5import { ClientOnErrorFunction } from "./components.js";
6import * as React$1 from "react";
7
8//#region lib/context.d.ts
9interface DataRouterContextObject extends Omit<NavigationContextObject, "future" | "useTransitions"> {
10 router: Router;
11 staticContext?: StaticHandlerContext;
12 onError?: ClientOnErrorFunction;
13}
14declare const DataRouterContext: React$1.Context<DataRouterContextObject | null>;
15type DataRouterDataContextObject = Pick<Router["state"], "loaderData" | "actionData" | "errors">;
16type DataRouterNavigationContextObject = Pick<Router["state"], "navigation" | "revalidation">;
17type DataRouterStateContextObject = Omit<Router["state"], keyof DataRouterDataContextObject | keyof DataRouterNavigationContextObject | "fetchers">;
18declare const DataRouterStateContext: React$1.Context<DataRouterStateContextObject | null>;
19declare const DataRouterDataContext: React$1.Context<DataRouterDataContextObject | null>;
20declare const DataRouterNavigationContext: React$1.Context<DataRouterNavigationContextObject | null>;
21type ViewTransitionContextObject = {
22 isTransitioning: false;
23} | {
24 isTransitioning: true;
25 flushSync: boolean;
26 currentLocation: Location;
27 nextLocation: Location;
28};
29declare const ViewTransitionContext: React$1.Context<ViewTransitionContextObject>;
30type FetchersContextObject = {
31 fetchers: Router["state"]["fetchers"];
32 fetcherData: Map<string, any>;
33};
34declare const FetchersContext: React$1.Context<FetchersContextObject | null>;
35declare const AwaitContext: React$1.Context<TrackedPromise | null>;
36declare const AwaitContextProvider: (props: React$1.ComponentProps<typeof AwaitContext.Provider>) => React$1.FunctionComponentElement<React$1.ProviderProps<TrackedPromise | null>>;
37interface NavigateOptions {
38 /** Replace the current entry in the history stack instead of pushing a new one */
39 replace?: boolean;
40 /** Masked URL */
41 mask?: To;
42 /** Adds persistent client side routing state to the next location */
43 state?: any;
44 /** If you are using {@link ScrollRestoration `<ScrollRestoration>`}, prevent the scroll position from being reset to the top of the window when navigating */
45 preventScrollReset?: boolean;
46 /** Defines the relative path behavior for the link. "route" will use the route hierarchy so ".." will remove all URL segments of the current route pattern while "path" will use the URL path so ".." will remove one URL segment. */
47 relative?: RelativeRoutingType;
48 /** Wraps the initial state update for this navigation in a {@link https://react.dev/reference/react-dom/flushSync ReactDOM.flushSync} call instead of the default {@link https://react.dev/reference/react/startTransition React.startTransition} */
49 flushSync?: boolean;
50 /** Enables a {@link https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API View Transition} for this navigation by wrapping the final state update in `document.startViewTransition()`. If you need to apply specific styles for this view transition, you will also need to leverage the {@link useViewTransitionState `useViewTransitionState()`} hook. */
51 viewTransition?: boolean;
52 /** Specifies the default revalidation behavior after this submission */
53 defaultShouldRevalidate?: boolean;
54}
55/**
56 * A Navigator is a "location changer"; it's how you get to different locations.
57 *
58 * Every history instance conforms to the Navigator interface, but the
59 * distinction is useful primarily when it comes to the low-level `<Router>` API
60 * where both the location and a navigator must be provided separately in order
61 * to avoid "tearing" that may occur in a suspense-enabled app if the action
62 * and/or location were to be read directly from the history instance.
63 */
64interface Navigator {
65 createHref: History["createHref"];
66 createURL?: History["createURL"];
67 encodeLocation?: History["encodeLocation"];
68 go: History["go"];
69 push(to: To, state?: any, opts?: NavigateOptions): void;
70 replace(to: To, state?: any, opts?: NavigateOptions): void;
71}
72interface NavigationContextObject {
73 basename: string;
74 navigator: Navigator;
75 static: boolean;
76 useTransitions: boolean | undefined;
77 future: {};
78}
79declare const NavigationContext: React$1.Context<NavigationContextObject>;
80interface LocationContextObject {
81 location: Location;
82 navigationType: Action;
83}
84declare const LocationContext: React$1.Context<LocationContextObject>;
85interface RouteContextObject {
86 outlet: React$1.ReactElement | null;
87 matches: RouteMatch[];
88 isDataRoute: boolean;
89}
90declare const RouteContext: React$1.Context<RouteContextObject>;
91//#endregion
92export { AwaitContextProvider, DataRouterContext, DataRouterDataContext, DataRouterNavigationContext, DataRouterStateContext, FetchersContext, LocationContext, NavigateOptions, NavigationContext, Navigator, RouteContext, ViewTransitionContext };
\No newline at end of file