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.
Files changed (45) hide show
  1. package/README.md +1 -1
  2. package/dist/components/Link.d.ts +23 -0
  3. package/dist/components/Router.d.ts +2 -0
  4. package/dist/components/Spinner.d.ts +1 -0
  5. package/dist/config/routerConfig.d.ts +18 -0
  6. package/dist/constants.d.ts +5 -0
  7. package/dist/create.d.ts +10 -0
  8. package/dist/creators/createRouter.d.ts +2 -0
  9. package/dist/creators/createRouterInstance.d.ts +2 -0
  10. package/dist/hooks/useAction.d.ts +4 -0
  11. package/dist/hooks/useApplyCustomAnimation.d.ts +1 -0
  12. package/dist/hooks/useBlocker.d.ts +13 -0
  13. package/dist/hooks/useInvalidate.d.ts +1 -0
  14. package/dist/hooks/useIsDataLoading.d.ts +1 -0
  15. package/dist/hooks/useIsRoutePending.d.ts +1 -0
  16. package/dist/hooks/useLoaderState.d.ts +1 -0
  17. package/dist/hooks/useLocation.d.ts +1 -0
  18. package/dist/hooks/useNavigate.d.ts +1 -0
  19. package/dist/hooks/useNavigation.d.ts +1 -0
  20. package/dist/hooks/useParams.d.ts +1 -0
  21. package/dist/hooks/usePreserveScroll.d.ts +2 -0
  22. package/dist/hooks/useReload.d.ts +1 -0
  23. package/dist/hooks/useRouterContext.d.ts +4 -0
  24. package/dist/hooks/useSearch.d.ts +1 -0
  25. package/dist/hooks/useSearchParams.d.ts +10 -0
  26. package/dist/hooks/useSetInitialContext.d.ts +2 -0
  27. package/dist/hooks/useSetRouterConfig.d.ts +2 -0
  28. package/dist/hooks/useSubmitAction.d.ts +17 -0
  29. package/dist/index.d.ts +16 -0
  30. package/dist/index.js +1168 -0
  31. package/dist/instance.d.ts +1 -0
  32. package/dist/runtime/invalidate.d.ts +2 -0
  33. package/dist/runtime/navigate.d.ts +2 -0
  34. package/dist/runtime/prefetch.d.ts +2 -0
  35. package/dist/runtime/revalidateCache.d.ts +2 -0
  36. package/dist/types.d.ts +180 -0
  37. package/dist/utils/commitNavigation.d.ts +1 -0
  38. package/dist/utils/commitState.d.ts +8 -0
  39. package/dist/utils/createLazyComponent.d.ts +9 -0
  40. package/dist/utils/findRoute.d.ts +2 -0
  41. package/dist/utils/isCacheItemFresh.d.ts +2 -0
  42. package/dist/utils/lazy.d.ts +5 -0
  43. package/dist/utils/renderElement.d.ts +2 -0
  44. package/dist/utils/utils.d.ts +18 -0
  45. package/package.json +1 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Clear Router
2
2
 
3
- A lightweight, type-safe routing library for client side React applications with nested routes, data loading, navigation blocking, prefetching, and route actions.
3
+ A lightweight routing library for client side React applications with nested routes, data loading, navigation blocking, prefetching, and route actions.
4
4
 
5
5
  ## Why Clear Router?
6
6
 
@@ -0,0 +1,23 @@
1
+ import { type CSSProperties, ReactNode, ReactElement } from 'react';
2
+ import { ElementProps, RouterProps, SearchObject } from '../types';
3
+ type ElementState = {
4
+ isActive: boolean;
5
+ isPending: boolean;
6
+ };
7
+ type LinkProps<T extends HTMLElement = HTMLAnchorElement> = {
8
+ to: string;
9
+ search?: string | SearchObject;
10
+ state?: unknown;
11
+ children?: ReactNode;
12
+ as?: (props: ElementProps<T>, state: ElementState) => ReactElement;
13
+ prefetch?: RouterProps['defaultPrefetch'];
14
+ hoverPrefetchDelay?: number;
15
+ className?: string | ((arg: ElementState) => string);
16
+ activeClassName?: string;
17
+ pendingClassName?: string;
18
+ beforeNavigate?(): Promise<void>;
19
+ style?: CSSProperties | ((arg: ElementState) => CSSProperties);
20
+ exact?: boolean;
21
+ };
22
+ export declare const Link: <T extends HTMLElement = HTMLAnchorElement>({ children, to, search, state, as, prefetch: linkPrefetch, hoverPrefetchDelay, className, style, beforeNavigate, exact, activeClassName, pendingClassName, }: LinkProps<T>) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
23
+ export {};
@@ -0,0 +1,2 @@
1
+ import { RouterProps } from '../types';
2
+ export declare const Router: ({ routes, defaultBeforeLoad, defaultAfterLoad, animationDuration, defaultLoaderFallback, defaultErrorElement, defaultRetry, defaultStaleTime, context: initialContext, isAnimated, optimisticSpinner, defaultMinLoaderDuration, revalidateOnFocus, revalidateOnReconnect, maxCacheSize, defaultPrefetch, defaultHoverPrefetchDelay, defaultScrollRestorationBehavior, errorBoundary: ErrorBoundary, }: RouterProps) => import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1 @@
1
+ export declare const Spinner: () => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,18 @@
1
+ import { ClientRouteItem, RouterProps } from '../types';
2
+ declare class RouterConfig {
3
+ routes: RouterProps['routes'];
4
+ maxCacheSize: number;
5
+ defaultPrefetch: RouterProps['defaultPrefetch'];
6
+ isAnimated: RouterProps['isAnimated'];
7
+ revalidateOnFocus: boolean;
8
+ revalidateOnReconnect: boolean;
9
+ defaultHoverPrefetchDelay: number;
10
+ defaultBeforeLoad?: ClientRouteItem['beforeLoad'];
11
+ defaultAfterLoad?: ClientRouteItem['afterLoad'];
12
+ defaultRetry?: RouterProps['defaultRetry'];
13
+ defaultStaleTime?: RouterProps['defaultStaleTime'];
14
+ defaultMinLoaderDuration?: RouterProps['defaultMinLoaderDuration'];
15
+ configure(config: Partial<RouterConfig>): void;
16
+ }
17
+ export declare const routerConfig: RouterConfig;
18
+ export {};
@@ -0,0 +1,5 @@
1
+ import type { LoaderState } from './types';
2
+ export declare const EMPTY_LOADER_STATE: LoaderState;
3
+ export declare const STANDARD_PREFETCH_DELAY = 150;
4
+ export declare const WINDOW_TOP = "__window_top__";
5
+ export declare const WINDOW_LEFT = "__window_left__";
@@ -0,0 +1,10 @@
1
+ type SetStateAction<T> = ((prevState: T) => T) | T;
2
+ type Listener<T> = (state: T, prevState: T) => void;
3
+ export type Store<T> = {
4
+ subscribe: (listener: Listener<T>) => () => void;
5
+ getState: () => T;
6
+ setState: (action: SetStateAction<T>) => void;
7
+ };
8
+ export declare const create: <T>(initialState: T) => Store<T>;
9
+ export declare const useGlobalState: <T>({ subscribe, getState, setState }: Store<T>) => readonly [T, (action: SetStateAction<T>) => void];
10
+ export {};
@@ -0,0 +1,2 @@
1
+ import { ClientRouteItem, RouteItem } from '../types';
2
+ export declare const createRouter: (clientList: ClientRouteItem[]) => RouteItem[];
@@ -0,0 +1,2 @@
1
+ import { RouterType } from '../types';
2
+ export declare const createRouterInstance: () => RouterType;
@@ -0,0 +1,4 @@
1
+ export declare const useAction: (action: string, options?: import("../types").Options) => (arg: Record<string, unknown>) => Promise<{
2
+ data: unknown;
3
+ error: Error | null;
4
+ }>;
@@ -0,0 +1 @@
1
+ export declare const useApplyCustomAnimation: (animationDuration?: number) => void;
@@ -0,0 +1,13 @@
1
+ import { BlockerState, Location } from '../types';
2
+ type UseBlockerReturnValue = {
3
+ state: BlockerState;
4
+ process(): void;
5
+ reset(): void;
6
+ };
7
+ type BlockerCallback = {
8
+ location: Location;
9
+ nextLocation: Location | null;
10
+ context: Record<string, unknown>;
11
+ };
12
+ export declare const useBlocker: (blockerFn: (args: BlockerCallback) => boolean) => UseBlockerReturnValue;
13
+ export {};
@@ -0,0 +1 @@
1
+ export declare const useInvalidate: () => (pathList?: string | string[], options?: import("../types").InvalidateOptions) => Promise<import("../types").InvalidateResult[]>;
@@ -0,0 +1 @@
1
+ export declare const useIsDataLoading: () => boolean;
@@ -0,0 +1 @@
1
+ export declare const useIsRoutePending: (routePath: string) => boolean;
@@ -0,0 +1 @@
1
+ export declare const useLoaderState: <T>() => import("../types").LoaderState<T>;
@@ -0,0 +1 @@
1
+ export declare const useLocation: () => import("..").Location;
@@ -0,0 +1 @@
1
+ export declare const useNavigate: () => (arg: import("..").NavigationLocation | string | -1) => Promise<void>;
@@ -0,0 +1 @@
1
+ export declare const useNavigation: () => void;
@@ -0,0 +1 @@
1
+ export declare const useParams: <T>() => T;
@@ -0,0 +1,2 @@
1
+ import { ScrollRestorationBehavior } from '../types';
2
+ export declare const usePreserveScroll: (restorationBehavior: ScrollRestorationBehavior) => void;
@@ -0,0 +1 @@
1
+ export declare const useReload: () => void;
@@ -0,0 +1,4 @@
1
+ export declare const useRouterContext: () => {
2
+ context: Record<string, unknown>;
3
+ setContext: (action: Record<string, unknown> | ((prevState: Record<string, unknown>) => Record<string, unknown>)) => void;
4
+ };
@@ -0,0 +1 @@
1
+ export declare const useSearch: () => string;
@@ -0,0 +1,10 @@
1
+ type UseSearchParamsReturn = {
2
+ searchParams: URLSearchParams;
3
+ getSearchParams(arg: string): string | string[];
4
+ setSearchParams: {
5
+ (param: string, value: string | string[]): void;
6
+ (param: (prevState: URLSearchParams) => URLSearchParams): void;
7
+ };
8
+ };
9
+ export declare const useSearchParams: () => UseSearchParamsReturn;
10
+ export {};
@@ -0,0 +1,2 @@
1
+ import { RouterProps } from '../types';
2
+ export declare const useSetInitialContext: (initialContext?: RouterProps["context"]) => void;
@@ -0,0 +1,2 @@
1
+ import { RouterProps } from '../types';
2
+ export declare const useSetRouterConfig: (routerProps: RouterProps) => void;
@@ -0,0 +1,17 @@
1
+ import { SubmitEvent } from 'react';
2
+ type Options = {
3
+ onSuccess?(arg: unknown): void;
4
+ onError?(arg: unknown): void;
5
+ autoReset?: boolean;
6
+ };
7
+ export declare const useSubmitAction: (action: string, options?: Options) => {
8
+ submit: (data: Record<string, unknown>) => Promise<{
9
+ data: unknown;
10
+ error: Error | null;
11
+ }>;
12
+ onSubmit: (evt: SubmitEvent<HTMLFormElement>) => Promise<void>;
13
+ data: unknown;
14
+ error: Error | null;
15
+ isSubmitting: boolean;
16
+ };
17
+ export {};
@@ -0,0 +1,16 @@
1
+ export { Router } from './components/Router';
2
+ export { Link } from './components/Link';
3
+ export { useNavigate } from './hooks/useNavigate';
4
+ export { useParams } from './hooks/useParams';
5
+ export { useLocation } from './hooks/useLocation';
6
+ export { useLoaderState } from './hooks/useLoaderState';
7
+ export { useInvalidate } from './hooks/useInvalidate';
8
+ export { useBlocker } from './hooks/useBlocker';
9
+ export { useAction } from './hooks/useAction';
10
+ export { useIsDataLoading } from './hooks/useIsDataLoading';
11
+ export { useRouterContext } from './hooks/useRouterContext';
12
+ export { useSearchParams } from './hooks/useSearchParams';
13
+ export { useSubmitAction } from './hooks/useSubmitAction';
14
+ export { createRouter } from './creators/createRouter';
15
+ export { lazy } from './utils/lazy';
16
+ export type { RouteItem, BlockerState, Location, RouterProps, ElementProps, NavigationLocation } from './types';