clear-react-router 1.7.9 → 1.8.1

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.
@@ -0,0 +1 @@
1
+ export declare const router: import("./types").RouterType;
@@ -1,6 +1,2 @@
1
- type Options = {
2
- withChildren?: boolean;
3
- };
4
- export declare function invalidate(path?: string[]): Promise<void>;
5
- export declare function invalidate(path?: string, options?: Options): Promise<void>;
6
- export {};
1
+ import { type InvalidateOptions, RevalidateCache, RouterState } from '../types';
2
+ export declare const createInvalidate: ({ routeItemDataState, loaderStateRef, timestampMap, currentLoaderState, contextState }: RouterState, revalidateCache: RevalidateCache) => (pathList?: string | string[], options?: InvalidateOptions) => Promise<void>;
@@ -1,2 +1,2 @@
1
- import { Location } from '../types/global';
2
- export declare const navigate: (nextLocation: Location) => Promise<void>;
1
+ import { Location, RevalidateCache, RouterState } from '../types';
2
+ export declare const createNavigate: (routerState: RouterState, revalidateCache: RevalidateCache) => (nextLocation: Location) => Promise<void>;
@@ -1 +1,2 @@
1
- export declare const prefetch: (pathname: string) => Promise<void>;
1
+ import { RevalidateCache } from '../types';
2
+ export declare const createPrefetch: (revalidateCache: RevalidateCache) => (pathname: string) => Promise<void>;
@@ -1,4 +1,6 @@
1
1
  import type { ComponentType, Dispatch, ReactElement, ReactNode, SetStateAction } from 'react';
2
+ import { Store, useGlobalState } from './create';
3
+ import { Cell } from './cell';
2
4
  export type LazyComponent = () => Promise<{
3
5
  default: ComponentType<unknown>;
4
6
  }>;
@@ -9,11 +11,6 @@ export type BeforeLoad = (arg: {
9
11
  params: Record<string, string>;
10
12
  setContext: Dispatch<SetStateAction<Record<string, unknown>>>;
11
13
  }) => Promise<unknown> | undefined | void;
12
- export type AfterLoad = (arg: {
13
- context: Record<string, unknown>;
14
- params: Record<string, string>;
15
- setContext: Dispatch<SetStateAction<Record<string, unknown>>>;
16
- }) => Promise<void>;
17
14
  export type ClientRouteItem = {
18
15
  path: string;
19
16
  element: RenderElement | LazyComponent;
@@ -27,6 +24,7 @@ export type ClientRouteItem = {
27
24
  fallback?: RenderElement;
28
25
  children?: ClientRouteItem[];
29
26
  staleTime?: number;
27
+ retry?: Retry;
30
28
  beforeLoad?: BeforeLoad;
31
29
  afterLoad?: (arg: {
32
30
  context: Record<string, unknown>;
@@ -63,7 +61,7 @@ export type LoaderState<T = unknown> = {
63
61
  loaderError: Error | null;
64
62
  beforeLoadError: Error | null;
65
63
  };
66
- export type AdapterType<T> = {
64
+ export type Adapter<T> = {
67
65
  parse: (params: string[]) => T;
68
66
  serialize?: (params: T) => string | string[];
69
67
  };
@@ -71,12 +69,18 @@ export type RouteItemData = {
71
69
  location: Location;
72
70
  routeItem: RouteItem | undefined;
73
71
  };
72
+ type ObjectRetry = {
73
+ count: number;
74
+ delay: number;
75
+ };
76
+ export type Retry = number | ObjectRetry | undefined;
74
77
  export type RouterProps = {
75
78
  routes: RouteItem[];
76
79
  isAnimated?: boolean;
77
80
  animationDuration?: number;
78
81
  spinner?: boolean;
79
82
  preserveScroll?: boolean;
83
+ defaultRetry?: Retry;
80
84
  defaultLoaderFallback?: RenderElement;
81
85
  defaultErrorElement?: RenderElement;
82
86
  showFallbackOnAnimation?: boolean;
@@ -89,3 +93,55 @@ export type RouterProps = {
89
93
  afterLoad?: ClientRouteItem['afterLoad'];
90
94
  context?: Record<string, unknown>;
91
95
  };
96
+ export type RouterState = {
97
+ isLoadingState: Store<boolean>;
98
+ loaderFallbackState: Store<RouteItem['loaderFallback']>;
99
+ routeItemDataState: Store<RouteItemData>;
100
+ currentLoaderState: Store<LoaderState>;
101
+ scrollMapState: Store<Record<string, number>>;
102
+ contextState: Store<Record<string, unknown>>;
103
+ blockedRouteState: Store<{
104
+ from: string;
105
+ to: string;
106
+ }>;
107
+ loaderStateRef: Cell<LoaderState>;
108
+ prevPathnameRef: Cell<string>;
109
+ timestampMap: Map<string, number>;
110
+ };
111
+ export type RouterType = {
112
+ state: Omit<RouterState, 'loaderStateRef' | 'timestampMap'>;
113
+ runtime: {
114
+ navigate(arg: Location): Promise<void>;
115
+ invalidate(pathList?: string | string[], options?: InvalidateOptions): Promise<void>;
116
+ prefetch(pathname: string): Promise<void>;
117
+ };
118
+ hooks: {
119
+ useIsLoading: () => ReturnType<typeof useGlobalState<boolean>>;
120
+ useBlockedRoute: () => ReturnType<typeof useGlobalState<{
121
+ from: string;
122
+ to: string;
123
+ }>>;
124
+ useLoaderFallback: () => ReturnType<typeof useGlobalState<RenderElement | undefined>>;
125
+ useRouteItemData: () => ReturnType<typeof useGlobalState<RouteItemData>>;
126
+ useCurrentLoaderState: () => ReturnType<typeof useGlobalState<LoaderState>>;
127
+ useScrollMap: () => ReturnType<typeof useGlobalState<Record<string, number>>>;
128
+ useContextState: () => ReturnType<typeof useGlobalState<Record<string, unknown>>>;
129
+ useParams: <T>() => T;
130
+ useNavigate: () => (arg: Location | string | -1) => Promise<void>;
131
+ useGetAction: (actionKey: string) => {
132
+ currentAction: (arg: FormData) => Promise<unknown> | Promise<void> | void | unknown;
133
+ invalidate: (pathList?: string | string[], options?: InvalidateOptions) => Promise<void>;
134
+ };
135
+ useRestoreScroll: () => () => void;
136
+ useAction: (action: string, options?: Options) => (arg: FormData) => Promise<void>;
137
+ };
138
+ };
139
+ export type InvalidateOptions = {
140
+ withChildren?: boolean;
141
+ };
142
+ export type RevalidateCache = ({ routeItem, pathname }: RevalidateCacheArgs) => Promise<unknown> | undefined;
143
+ export type Options = Partial<{
144
+ onSuccess: (args: unknown) => void;
145
+ onError: (args: unknown) => void;
146
+ }> | undefined;
147
+ export {};
@@ -1,4 +1,4 @@
1
- import { AdapterType } from '../types/global';
1
+ import { Adapter } from '../types';
2
2
  type ZodInterface<T> = {
3
3
  safeParse(input: unknown): {
4
4
  success: true;
@@ -46,6 +46,6 @@ export declare const adapter: {
46
46
  parse: (params: string[]) => Date[];
47
47
  serialize: (args: Date[]) => string[];
48
48
  };
49
- zodSchema: <T>(schema: ZodInterface<T>) => AdapterType<T>;
49
+ zodSchema: <T>(schema: ZodInterface<T>) => Adapter<T>;
50
50
  };
51
51
  export {};
@@ -1,2 +1,3 @@
1
- import { Location, RouteItem } from '../types/global';
2
- export declare const commitNavigation: (nextLocation: Location, routeItem: RouteItem | undefined) => void;
1
+ import { Cell } from '../cell';
2
+ import { Location, RouteItem } from '../types';
3
+ export declare const createCommitNavigation: (navigationExecutor: (arg: Location, routeItem: RouteItem | undefined) => void, prevPathnameRef: Cell<string>) => (nextLocation: Location, routeItem: RouteItem | undefined) => void;
@@ -1,2 +1,2 @@
1
- import { Location, RouteItem } from '../types/global';
2
- export declare const commitState: (nextLocation: Location, routeItem: RouteItem | undefined) => void;
1
+ import { Location, RouteItem, RouterState } from '../types';
2
+ export declare const createCommitState: ({ isLoadingState, routeItemDataState, loaderFallbackState, currentLoaderState, prevPathnameRef, loaderStateRef, }: RouterState) => (nextLocation: Location, routeItem: RouteItem | undefined) => void;
@@ -0,0 +1,2 @@
1
+ import { RouterType } from '../types';
2
+ export declare const createRouterInstance: () => RouterType;
@@ -1,2 +1,2 @@
1
- export declare const ALL_LOCATIONS = "*";
1
+ export declare const ALL_LOCATIONS = "/*";
2
2
  export declare const findRoute: (pathname: string, includeAll?: boolean) => import("..").RouteItem | undefined;
@@ -1,5 +1,5 @@
1
- import type { RouteItem } from '../types/global';
2
- export declare const isCacheItemFresh: ({ routeItem, pathname }: {
1
+ import type { RouteItem } from '../types';
2
+ export declare const createIsCacheItemFresh: (timestampMap: Map<string, number>) => ({ routeItem, pathname }: {
3
3
  routeItem?: RouteItem;
4
4
  pathname: string;
5
5
  }) => boolean;
@@ -1,2 +1,2 @@
1
- import { RenderElement } from '../types/global';
1
+ import { RenderElement } from '../types';
2
2
  export declare const renderElement: (Component?: RenderElement) => import("react/jsx-runtime").JSX.Element | null;
@@ -1,3 +1,2 @@
1
- import type { RevalidateCacheArgs } from '../types/global';
2
- declare const revalidateCache: ({ routeItem, pathname }: RevalidateCacheArgs) => Promise<unknown> | undefined;
3
- export { revalidateCache };
1
+ import { RevalidateCacheArgs, RouterState } from '../types';
2
+ export declare const createRevalidateCache: (routerState: RouterState) => ({ routeItem, pathname }: RevalidateCacheArgs, retried?: number) => Promise<any>;
@@ -1,4 +1,4 @@
1
- import type { ClientRouteItem, Location, RouteItem } from '../types/global';
1
+ import { ClientRouteItem, Location, RouteItem } from '../types';
2
2
  export declare const createRouter: (clientList: ClientRouteItem[]) => RouteItem[];
3
3
  export declare const getParamsObject: ({ params, pathname }: {
4
4
  params?: RouteItem["params"];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clear-react-router",
3
- "version": "1.7.9",
3
+ "version": "1.8.1",
4
4
  "description": "A lightweight, type-safe routing library for React applications",
5
5
  "author": "Andrew Bubnov",
6
6
  "scripts": {
@@ -1,4 +0,0 @@
1
- export declare const useGetAction: (actionKey: string) => {
2
- currentAction: (arg: FormData) => Promise<unknown> | Promise<void> | void | unknown;
3
- invalidate: typeof import("../runtime/invalidate").invalidate;
4
- };
@@ -1,50 +0,0 @@
1
- import { LoaderState, RouteItemData } from '../types/global';
2
- export declare const isLoadingState: {
3
- subscribe: (listener: (state: boolean, prevState: boolean) => void) => () => void;
4
- getState: () => boolean;
5
- setState: (action: boolean | ((prevState: boolean) => boolean)) => void;
6
- };
7
- export declare const useIsLoading: () => readonly [boolean, (action: boolean | ((prevState: boolean) => boolean)) => void];
8
- export declare const useBlockedRoute: () => readonly [{
9
- from: string;
10
- to: string;
11
- }, (action: {
12
- from: string;
13
- to: string;
14
- } | ((prevState: {
15
- from: string;
16
- to: string;
17
- }) => {
18
- from: string;
19
- to: string;
20
- })) => void];
21
- export declare const loaderFallbackState: {
22
- subscribe: (listener: (state: import("../types/global").RenderElement | undefined, prevState: import("../types/global").RenderElement | undefined) => void) => () => void;
23
- getState: () => import("../types/global").RenderElement | undefined;
24
- setState: (action: import("../types/global").RenderElement | ((prevState: import("../types/global").RenderElement | undefined) => import("../types/global").RenderElement | undefined) | undefined) => void;
25
- };
26
- export declare const useLoaderFallback: () => readonly [import("../types/global").RenderElement | undefined, (action: import("../types/global").RenderElement | ((prevState: import("../types/global").RenderElement | undefined) => import("../types/global").RenderElement | undefined) | undefined) => void];
27
- export declare const routeItemDataState: {
28
- subscribe: (listener: (state: RouteItemData, prevState: RouteItemData) => void) => () => void;
29
- getState: () => RouteItemData;
30
- setState: (action: RouteItemData | ((prevState: RouteItemData) => RouteItemData)) => void;
31
- };
32
- export declare const useRouteItemData: () => readonly [RouteItemData, (action: RouteItemData | ((prevState: RouteItemData) => RouteItemData)) => void];
33
- export declare const currentLoaderState: {
34
- subscribe: (listener: (state: LoaderState, prevState: LoaderState) => void) => () => void;
35
- getState: () => LoaderState;
36
- setState: (action: LoaderState | ((prevState: LoaderState) => LoaderState)) => void;
37
- };
38
- export declare const useCurrentLoaderState: () => readonly [LoaderState, (action: LoaderState | ((prevState: LoaderState) => LoaderState)) => void];
39
- export declare const scrollMapState: {
40
- subscribe: (listener: (state: Record<string, number>, prevState: Record<string, number>) => void) => () => void;
41
- getState: () => Record<string, number>;
42
- setState: (action: Record<string, number> | ((prevState: Record<string, number>) => Record<string, number>)) => void;
43
- };
44
- export declare const useScrollMap: () => readonly [Record<string, number>, (action: Record<string, number> | ((prevState: Record<string, number>) => Record<string, number>)) => void];
45
- export declare const contextState: {
46
- subscribe: (listener: (state: Record<string, unknown>, prevState: Record<string, unknown>) => void) => () => void;
47
- getState: () => Record<string, unknown>;
48
- setState: (action: Record<string, unknown> | ((prevState: Record<string, unknown>) => Record<string, unknown>)) => void;
49
- };
50
- export declare const useContextState: () => readonly [Record<string, unknown>, (action: Record<string, unknown> | ((prevState: Record<string, unknown>) => Record<string, unknown>)) => void];
@@ -1,4 +0,0 @@
1
- export declare const getContext: () => {
2
- context: Record<string, unknown>;
3
- setContext: (action: Record<string, unknown> | ((prevState: Record<string, unknown>) => Record<string, unknown>)) => void;
4
- };