clear-react-router 2.2.4 → 2.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/components/Link.d.ts +23 -0
- package/dist/components/Router.d.ts +2 -0
- package/dist/components/Spinner.d.ts +1 -0
- package/dist/config/routerConfig.d.ts +18 -0
- package/dist/constants.d.ts +5 -0
- package/dist/create.d.ts +10 -0
- package/dist/creators/createRouter.d.ts +2 -0
- package/dist/creators/createRouterInstance.d.ts +2 -0
- package/dist/hooks/useAction.d.ts +4 -0
- package/dist/hooks/useApplyCustomAnimation.d.ts +1 -0
- package/dist/hooks/useBlocker.d.ts +13 -0
- package/dist/hooks/useInvalidate.d.ts +1 -0
- package/dist/hooks/useIsDataLoading.d.ts +1 -0
- package/dist/hooks/useIsRoutePending.d.ts +1 -0
- package/dist/hooks/useLoaderState.d.ts +1 -0
- package/dist/hooks/useLocation.d.ts +1 -0
- package/dist/hooks/useNavigate.d.ts +1 -0
- package/dist/hooks/useNavigation.d.ts +1 -0
- package/dist/hooks/useParams.d.ts +1 -0
- package/dist/hooks/usePreserveScroll.d.ts +2 -0
- package/dist/hooks/useReload.d.ts +1 -0
- package/dist/hooks/useRouterContext.d.ts +4 -0
- package/dist/hooks/useSearch.d.ts +1 -0
- package/dist/hooks/useSearchParams.d.ts +10 -0
- package/dist/hooks/useSetInitialContext.d.ts +2 -0
- package/dist/hooks/useSetRouterConfig.d.ts +2 -0
- package/dist/hooks/useSubmitAction.d.ts +17 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +1168 -0
- package/dist/instance.d.ts +1 -0
- package/dist/runtime/invalidate.d.ts +2 -0
- package/dist/runtime/navigate.d.ts +2 -0
- package/dist/runtime/prefetch.d.ts +2 -0
- package/dist/runtime/revalidateCache.d.ts +2 -0
- package/dist/types.d.ts +180 -0
- package/dist/utils/commitNavigation.d.ts +1 -0
- package/dist/utils/commitState.d.ts +8 -0
- package/dist/utils/createLazyComponent.d.ts +9 -0
- package/dist/utils/findRoute.d.ts +2 -0
- package/dist/utils/isCacheItemFresh.d.ts +2 -0
- package/dist/utils/lazy.d.ts +5 -0
- package/dist/utils/renderElement.d.ts +2 -0
- package/dist/utils/utils.d.ts +18 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const router: import("./types").RouterType;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { type InvalidateOptions, InvalidateResult, RevalidateCache, RouterState } from '../types';
|
|
2
|
+
export declare const createInvalidate: ({ routeItemDataState, loaderState, loaderMap }: RouterState, revalidateCache: RevalidateCache) => (pathList?: string | string[], options?: InvalidateOptions) => Promise<InvalidateResult[]>;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { ComponentType, type CSSProperties, Dispatch, MouseEvent, ReactElement, ReactNode, Ref, SetStateAction } from 'react';
|
|
2
|
+
import { Store, useGlobalState } from './create';
|
|
3
|
+
export declare const LAZY_MARKER: unique symbol;
|
|
4
|
+
export type LazyComponent = {
|
|
5
|
+
readonly [LAZY_MARKER]: true;
|
|
6
|
+
importFn: () => Promise<{
|
|
7
|
+
default: ComponentType<unknown>;
|
|
8
|
+
}>;
|
|
9
|
+
};
|
|
10
|
+
export type RenderElement = (() => ReactElement) | ReactElement;
|
|
11
|
+
type LoaderArgs = {
|
|
12
|
+
context: Record<string, unknown>;
|
|
13
|
+
params: Record<string, string>;
|
|
14
|
+
setContext: Dispatch<SetStateAction<Record<string, unknown>>>;
|
|
15
|
+
searchParams: Record<string, string>;
|
|
16
|
+
location: Location;
|
|
17
|
+
};
|
|
18
|
+
export type BeforeLoad = (arg: LoaderArgs & {
|
|
19
|
+
redirect: (arg: Location | string) => Promise<void>;
|
|
20
|
+
}) => Promise<unknown> | undefined | void;
|
|
21
|
+
export type ScrollRestorationBehavior = 'auto' | 'smooth' | 'instant';
|
|
22
|
+
export type ClientRouteItem = {
|
|
23
|
+
path: string;
|
|
24
|
+
element: RenderElement | LazyComponent;
|
|
25
|
+
loader?(arg: LoaderArgs & {
|
|
26
|
+
signal: AbortSignal;
|
|
27
|
+
}): Promise<unknown>;
|
|
28
|
+
loaderFallback?: RenderElement;
|
|
29
|
+
errorElement?: RenderElement;
|
|
30
|
+
fallback?: RenderElement;
|
|
31
|
+
children?: ClientRouteItem[];
|
|
32
|
+
staleTime?: number;
|
|
33
|
+
gcTime?: number;
|
|
34
|
+
optimistic?: boolean;
|
|
35
|
+
pollingInterval?: number;
|
|
36
|
+
retry?: Retry;
|
|
37
|
+
minLoaderDuration?: number;
|
|
38
|
+
scrollRestoration?: boolean | string[];
|
|
39
|
+
scrollRestorationBehavior?: ScrollRestorationBehavior;
|
|
40
|
+
beforeLoad?: BeforeLoad;
|
|
41
|
+
afterLoad?: (arg: {
|
|
42
|
+
context: Record<string, unknown>;
|
|
43
|
+
params: Record<string, string>;
|
|
44
|
+
searchParams: Record<string, string>;
|
|
45
|
+
}) => Promise<void> | void;
|
|
46
|
+
actions?: (arg: LoaderArgs) => Record<string, (arg: Record<string, unknown>) => Promise<unknown> | Promise<void> | void | unknown>;
|
|
47
|
+
};
|
|
48
|
+
export type RouteItem = ClientRouteItem & {
|
|
49
|
+
element: RenderElement;
|
|
50
|
+
pattern: string;
|
|
51
|
+
cacheTimestamp?: number;
|
|
52
|
+
preloadElement?(): Promise<{
|
|
53
|
+
default: ComponentType<unknown>;
|
|
54
|
+
}>;
|
|
55
|
+
};
|
|
56
|
+
export type Location = {
|
|
57
|
+
pathname: string;
|
|
58
|
+
search?: string;
|
|
59
|
+
state?: unknown;
|
|
60
|
+
prevLocation?: Omit<Location, 'state' | 'prevLocation'>;
|
|
61
|
+
};
|
|
62
|
+
export type BlockerState = 'blocked' | 'unblocked' | 'charged';
|
|
63
|
+
export type RevalidateCacheArgs = {
|
|
64
|
+
location: Location;
|
|
65
|
+
routeItem?: RouteItem;
|
|
66
|
+
signal?: AbortSignal;
|
|
67
|
+
};
|
|
68
|
+
export type LoaderState<T = unknown> = {
|
|
69
|
+
data: T;
|
|
70
|
+
loaderError: Error | null;
|
|
71
|
+
beforeLoadError: Error | null;
|
|
72
|
+
};
|
|
73
|
+
export type RouteItemData = {
|
|
74
|
+
location: Location;
|
|
75
|
+
routeItem: RouteItem | undefined;
|
|
76
|
+
status: 'idle' | 'pending' | 'active' | 'optimistic' | 'error';
|
|
77
|
+
};
|
|
78
|
+
type ObjectRetry = {
|
|
79
|
+
count: number;
|
|
80
|
+
delay: number;
|
|
81
|
+
};
|
|
82
|
+
export type Retry = number | ObjectRetry | undefined;
|
|
83
|
+
export type RouterProps = {
|
|
84
|
+
routes: RouteItem[];
|
|
85
|
+
isAnimated?: boolean;
|
|
86
|
+
animationDuration?: number;
|
|
87
|
+
optimisticSpinner?: boolean;
|
|
88
|
+
defaultRetry?: Retry;
|
|
89
|
+
defaultStaleTime?: number;
|
|
90
|
+
defaultLoaderFallback?: RenderElement;
|
|
91
|
+
defaultErrorElement?: RenderElement;
|
|
92
|
+
defaultPrefetch?: 'hover' | 'render' | 'viewport' | 'none';
|
|
93
|
+
defaultHoverPrefetchDelay?: number;
|
|
94
|
+
defaultMinLoaderDuration?: number;
|
|
95
|
+
maxCacheSize?: number;
|
|
96
|
+
errorBoundary?: ComponentType<{
|
|
97
|
+
children: ReactNode;
|
|
98
|
+
}>;
|
|
99
|
+
defaultBeforeLoad?: ClientRouteItem['beforeLoad'];
|
|
100
|
+
defaultAfterLoad?: ClientRouteItem['afterLoad'];
|
|
101
|
+
defaultScrollRestorationBehavior?: ScrollRestorationBehavior;
|
|
102
|
+
revalidateOnFocus?: boolean;
|
|
103
|
+
revalidateOnReconnect?: boolean;
|
|
104
|
+
context?: Record<string, unknown>;
|
|
105
|
+
};
|
|
106
|
+
export type LoaderStateItem = {
|
|
107
|
+
state: LoaderState;
|
|
108
|
+
timestamp: number;
|
|
109
|
+
staleTime: number | undefined;
|
|
110
|
+
gcTimeout?: number;
|
|
111
|
+
};
|
|
112
|
+
export type LoadingPromise = Promise<{
|
|
113
|
+
data: unknown;
|
|
114
|
+
error: null;
|
|
115
|
+
} | {
|
|
116
|
+
data: null;
|
|
117
|
+
error: unknown;
|
|
118
|
+
} | undefined>;
|
|
119
|
+
export type ScrollMap = Record<string, [string, number][]>;
|
|
120
|
+
export type RouterState = {
|
|
121
|
+
routeItemDataState: Store<RouteItemData>;
|
|
122
|
+
scrollMapState: Store<ScrollMap>;
|
|
123
|
+
contextState: Store<Record<string, unknown>>;
|
|
124
|
+
blockerState: Store<BlockerState>;
|
|
125
|
+
loaderState: Store<LoaderState>;
|
|
126
|
+
blockedTargetState: Store<Location | null>;
|
|
127
|
+
loaderMap: Map<string, LoaderStateItem>;
|
|
128
|
+
loadingPromises: Map<string, LoadingPromise>;
|
|
129
|
+
};
|
|
130
|
+
export type RouterType = {
|
|
131
|
+
runtime: {
|
|
132
|
+
navigate(arg: Location): Promise<void>;
|
|
133
|
+
invalidate(pathList?: string | string[], options?: InvalidateOptions): Promise<InvalidateResult[]>;
|
|
134
|
+
prefetch(location: Location): Promise<void>;
|
|
135
|
+
};
|
|
136
|
+
hooks: {
|
|
137
|
+
useBlockerState(): ReturnType<typeof useGlobalState<BlockerState>>;
|
|
138
|
+
useRouteItemData(): ReturnType<typeof useGlobalState<RouteItemData>>;
|
|
139
|
+
useScrollMap(): ReturnType<typeof useGlobalState<ScrollMap>>;
|
|
140
|
+
useContextState(): ReturnType<typeof useGlobalState<Record<string, unknown>>>;
|
|
141
|
+
useBlockedTargetState(): ReturnType<typeof useGlobalState<Location | null>>;
|
|
142
|
+
useLoaderState<T>(): LoaderState<T>;
|
|
143
|
+
useParams<T>(): T;
|
|
144
|
+
useNavigate(): (arg: NavigationLocation | string | -1) => Promise<void>;
|
|
145
|
+
useAction(action: string, options?: Options): (arg: Record<string, unknown>) => Promise<{
|
|
146
|
+
data: unknown;
|
|
147
|
+
error: Error | null;
|
|
148
|
+
}>;
|
|
149
|
+
useRestoreScroll(restorationBehavior: ScrollRestorationBehavior): (() => void) | undefined;
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
export type InvalidateOptions = {
|
|
153
|
+
withChildren?: boolean;
|
|
154
|
+
force?: boolean;
|
|
155
|
+
staleOnly?: boolean;
|
|
156
|
+
};
|
|
157
|
+
export type RevalidateCache = (args: RevalidateCacheArgs) => LoadingPromise;
|
|
158
|
+
export type Options = Partial<{
|
|
159
|
+
onSuccess: (args: unknown) => void;
|
|
160
|
+
onError: (args: unknown) => void;
|
|
161
|
+
}> | undefined;
|
|
162
|
+
export type InvalidateResult = {
|
|
163
|
+
path: string;
|
|
164
|
+
data: unknown;
|
|
165
|
+
};
|
|
166
|
+
export type ElementProps<T extends HTMLElement = HTMLElement> = {
|
|
167
|
+
ref: Ref<T>;
|
|
168
|
+
href: string;
|
|
169
|
+
className?: string;
|
|
170
|
+
style?: CSSProperties;
|
|
171
|
+
onClick(event: MouseEvent): void;
|
|
172
|
+
onMouseEnter(event: MouseEvent): void;
|
|
173
|
+
onMouseLeave(event: MouseEvent): void;
|
|
174
|
+
children?: ReactNode;
|
|
175
|
+
};
|
|
176
|
+
export type SearchObject = Record<string, string | number | boolean | null | undefined>;
|
|
177
|
+
export type NavigationLocation = Omit<Location, 'search'> & {
|
|
178
|
+
search?: string | SearchObject;
|
|
179
|
+
};
|
|
180
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const commitNavigation: (callback: () => void, isCommited?: boolean) => void;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { LoaderState, Location, RouteItem, RouterState } from '../types';
|
|
2
|
+
type CommitState = {
|
|
3
|
+
location: Location;
|
|
4
|
+
loaderStateValue: LoaderState;
|
|
5
|
+
routeItem?: RouteItem;
|
|
6
|
+
};
|
|
7
|
+
export declare const createCommitState: ({ loaderState, routeItemDataState, blockerState }: RouterState) => ({ routeItem, loaderStateValue, location }: CommitState) => void;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ComponentType, type ReactElement } from 'react';
|
|
2
|
+
export declare const createLazyComponent: (importFn: () => Promise<{
|
|
3
|
+
default: ComponentType<unknown>;
|
|
4
|
+
}>, fallback?: ReactElement | (() => ReactElement)) => {
|
|
5
|
+
Component: () => import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
preloadElement: () => Promise<{
|
|
7
|
+
default: ComponentType<unknown>;
|
|
8
|
+
}>;
|
|
9
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Store } from '../create';
|
|
2
|
+
import { Location, RouteItem, RouteItemData, RouterState, ScrollMap, ScrollRestorationBehavior, SearchObject } from '../types';
|
|
3
|
+
export declare const getParams: (location: Location, routeItem?: RouteItem) => Record<string, string>;
|
|
4
|
+
export declare const parseWindowLocation: (location: typeof window.location) => Location;
|
|
5
|
+
export declare const comparePaths: (route: RouteItem, pathname: string) => boolean;
|
|
6
|
+
export declare const isMobile: () => boolean;
|
|
7
|
+
export declare const sleep: (ms: number) => Promise<unknown>;
|
|
8
|
+
export declare const getPartialLoaderArgs: (contextState: RouterState["contextState"], location: Location, routeItem?: RouteItem) => {
|
|
9
|
+
params: Record<string, string>;
|
|
10
|
+
context: Record<string, unknown>;
|
|
11
|
+
setContext: (action: Record<string, unknown> | ((prevState: Record<string, unknown>) => Record<string, unknown>)) => void;
|
|
12
|
+
searchParams: Record<string, string>;
|
|
13
|
+
location: Location;
|
|
14
|
+
};
|
|
15
|
+
export declare const isVerticalScroll: (el: Element | null) => boolean;
|
|
16
|
+
export declare const updateScrollMap: (routeItemDataState: Store<RouteItemData>, scrollMapState: Store<ScrollMap>) => void;
|
|
17
|
+
export declare const restoreScroll: (scrollMap: ScrollMap, pathname: string, behavior: ScrollRestorationBehavior) => void;
|
|
18
|
+
export declare const formatSearchObject: (searchObject: SearchObject) => string;
|