clear-react-router 2.2.7 → 2.2.9
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 +51 -0
- package/dist/components/Link.d.ts +14 -2
- package/dist/config/routerConfig.d.ts +1 -0
- package/dist/create.d.ts +3 -3
- package/dist/creators/createRouterInstance.d.ts +2 -2
- package/dist/hooks/usePreserveScroll.d.ts +1 -1
- package/dist/hooks/useRestoreScroll.d.ts +2 -0
- package/dist/hooks/useRouterContext.d.ts +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +69 -61
- package/dist/types.d.ts +10 -22
- package/dist/utils/createLazyComponent.d.ts +3 -3
- package/dist/utils/renderElement.d.ts +3 -2
- package/dist/utils/utils.d.ts +2 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -837,6 +837,57 @@ const Blocker = ({ callback, children }: BlockerProps) => {
|
|
|
837
837
|
</Blocker>
|
|
838
838
|
```
|
|
839
839
|
|
|
840
|
+
### `useRestoreScroll()`
|
|
841
|
+
|
|
842
|
+
Returns a callback that restores the saved scroll position for the current route — the same restoration the router performs automatically after every navigation, but triggered manually whenever you need it.
|
|
843
|
+
|
|
844
|
+
The automatic restore covers content that is ready when navigation finishes (including route `loader` data). Call the callback yourself for content that arrives later:
|
|
845
|
+
|
|
846
|
+
* deferred data streamed via React 19 `use()`,
|
|
847
|
+
* lazily loaded route chunks,
|
|
848
|
+
* any container that mounts after the initial render.
|
|
849
|
+
|
|
850
|
+
```tsx
|
|
851
|
+
import { useRestoreScroll, useLoaderState } from 'clear-react-router';
|
|
852
|
+
|
|
853
|
+
const SlowTable = () => {
|
|
854
|
+
const restoreScroll = useRestoreScroll();
|
|
855
|
+
const { data } = useLoaderState<{ rows: Promise<Row[]> }>();
|
|
856
|
+
|
|
857
|
+
return (
|
|
858
|
+
<Suspense fallback={<Skeleton />}>
|
|
859
|
+
<Table rows={data.rows} onReady={restoreScroll} />
|
|
860
|
+
</Suspense>
|
|
861
|
+
);
|
|
862
|
+
};
|
|
863
|
+
```
|
|
864
|
+
|
|
865
|
+
Data fetched outside the route `loader` (e.g. a `useEffect` fetch inside the component) is invisible to the router, so the automatic restore can't account for it either. The rule of thumb is simple: whenever *your* data arrives and the scrollable content is in place, call the callback:
|
|
866
|
+
|
|
867
|
+
```tsx
|
|
868
|
+
const Dashboard = () => {
|
|
869
|
+
const restoreScroll = useRestoreScroll();
|
|
870
|
+
const [rows, setRows] = useState<Row[] | null>(null);
|
|
871
|
+
|
|
872
|
+
useEffect(() => {
|
|
873
|
+
fetchRows().then(data => {
|
|
874
|
+
setRows(data);
|
|
875
|
+
// DOM updates after setState — wait a frame so the container exists
|
|
876
|
+
requestAnimationFrame(() => restoreScroll());
|
|
877
|
+
});
|
|
878
|
+
}, [restoreScroll]);
|
|
879
|
+
|
|
880
|
+
return rows ? <Table rows={rows} /> : <Skeleton />;
|
|
881
|
+
};
|
|
882
|
+
```
|
|
883
|
+
|
|
884
|
+
Details worth knowing:
|
|
885
|
+
|
|
886
|
+
* The callback reads the latest saved positions at call time, not at render time — so it stays correct even if called long after mount, and repeated calls pick up the newest data. It also works from components outside `<Router>` (e.g. a static navbar), since it doesn't depend on the render tree.
|
|
887
|
+
* Calling it is always safe: it silently does nothing when there is nothing saved for the current route, or when the route opted out with `scrollRestoration: false`.
|
|
888
|
+
* An optional behavior argument on the hook overrides the scroll behavior for these calls (`useRestoreScroll('smooth')`); by default the route's `scrollRestorationBehavior`, then the router's `defaultScrollRestorationBehavior`, applies.
|
|
889
|
+
* For element-level restoration (`scrollRestoration: ['panel']`), container `id`s must be unique and stable across visits — a typo or a remounted `id` logs a warning and skips that container.
|
|
890
|
+
|
|
840
891
|
### `useIsDataLoading()`
|
|
841
892
|
|
|
842
893
|
Returns a boolean indicating whether any route loader is currently fetching data. Useful for global loading indicators (progress bar, spinner in the layout, etc.).
|
|
@@ -1,9 +1,21 @@
|
|
|
1
|
-
import { type CSSProperties, ReactNode, ReactElement } from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import { type CSSProperties, ReactNode, MouseEvent, ReactElement, Ref } from 'react';
|
|
2
|
+
import { RouterProps, SearchObject } from '../types';
|
|
3
3
|
type ElementState = {
|
|
4
4
|
isActive: boolean;
|
|
5
5
|
isPending: boolean;
|
|
6
6
|
};
|
|
7
|
+
export type ElementProps<T extends HTMLElement = HTMLElement> = {
|
|
8
|
+
'ref': Ref<T>;
|
|
9
|
+
'href': string;
|
|
10
|
+
'className'?: string;
|
|
11
|
+
'style'?: CSSProperties;
|
|
12
|
+
onClick(event: MouseEvent): void;
|
|
13
|
+
onMouseEnter(event: MouseEvent): void;
|
|
14
|
+
onMouseLeave(event: MouseEvent): void;
|
|
15
|
+
'children'?: ReactNode;
|
|
16
|
+
'aria-current'?: 'page';
|
|
17
|
+
'aria-busy'?: boolean;
|
|
18
|
+
} & Record<`data-${string}` | `aria-${string}`, unknown>;
|
|
7
19
|
type LinkProps<T extends HTMLElement = HTMLAnchorElement> = {
|
|
8
20
|
to: string;
|
|
9
21
|
search?: string | SearchObject;
|
|
@@ -12,6 +12,7 @@ declare class RouterConfig {
|
|
|
12
12
|
defaultRetry?: RouterProps['defaultRetry'];
|
|
13
13
|
defaultStaleTime?: RouterProps['defaultStaleTime'];
|
|
14
14
|
defaultMinLoaderDuration?: RouterProps['defaultMinLoaderDuration'];
|
|
15
|
+
defaultScrollRestorationBehavior: RouterProps['defaultScrollRestorationBehavior'];
|
|
15
16
|
configure(config: Partial<RouterConfig>): void;
|
|
16
17
|
}
|
|
17
18
|
export declare const routerConfig: RouterConfig;
|
package/dist/create.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
type
|
|
1
|
+
import type { SetStateFn, Synchronizer } from './types';
|
|
2
2
|
type Listener<T> = (state: T, prevState: T) => void;
|
|
3
3
|
export type Store<T> = {
|
|
4
4
|
subscribe: (listener: Listener<T>) => () => void;
|
|
5
5
|
getState: () => T;
|
|
6
|
-
setState:
|
|
6
|
+
setState: SetStateFn<T>;
|
|
7
7
|
};
|
|
8
8
|
export declare const create: <T>(initialState: T) => Store<T>;
|
|
9
|
-
export declare const useGlobalState: <T>({ subscribe, getState, setState }: Store<T
|
|
9
|
+
export declare const useGlobalState: <T>({ subscribe, getState, setState }: Store<T>, synchronizer: Synchronizer) => readonly [T, SetStateFn<T>];
|
|
10
10
|
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { RouterType } from '../types';
|
|
2
|
-
export declare const createRouterInstance: () => RouterType;
|
|
1
|
+
import { RouterType, Synchronizer } from '../types';
|
|
2
|
+
export declare const createRouterInstance: (synchronizer: Synchronizer) => RouterType;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ScrollRestorationBehavior } from '../types';
|
|
2
|
-
export declare const usePreserveScroll: (
|
|
2
|
+
export declare const usePreserveScroll: (behavior?: ScrollRestorationBehavior) => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare const useRouterContext: () => {
|
|
2
2
|
context: Record<string, unknown>;
|
|
3
|
-
setContext: (
|
|
3
|
+
setContext: import("../types").SetStateFn<Record<string, unknown>>;
|
|
4
4
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ export { useIsDataLoading } from './hooks/useIsDataLoading';
|
|
|
11
11
|
export { useRouterContext } from './hooks/useRouterContext';
|
|
12
12
|
export { useSearchParams } from './hooks/useSearchParams';
|
|
13
13
|
export { useSubmitAction } from './hooks/useSubmitAction';
|
|
14
|
+
export { useRestoreScroll } from './hooks/useRestoreScroll';
|
|
14
15
|
export { createRouter } from './creators/createRouter';
|
|
15
16
|
export { lazy } from './utils/lazy';
|
|
16
|
-
export type { RouteItem, BlockerState, Location, RouterProps,
|
|
17
|
+
export type { RouteItem, BlockerState, Location, RouterProps, NavigationLocation } from './types';
|
|
18
|
+
export type { ElementProps } from './components/Link';
|
package/dist/index.js
CHANGED
|
@@ -23,8 +23,8 @@ var create = (initialState) => {
|
|
|
23
23
|
setState
|
|
24
24
|
};
|
|
25
25
|
};
|
|
26
|
-
var useGlobalState = ({ subscribe, getState, setState }) => {
|
|
27
|
-
return [
|
|
26
|
+
var useGlobalState = ({ subscribe, getState, setState }, synchronizer) => {
|
|
27
|
+
return [synchronizer(subscribe, getState), setState];
|
|
28
28
|
};
|
|
29
29
|
//#endregion
|
|
30
30
|
//#region utils/commitState.ts
|
|
@@ -99,6 +99,7 @@ var RouterConfig = class {
|
|
|
99
99
|
_defineProperty(this, "defaultRetry", void 0);
|
|
100
100
|
_defineProperty(this, "defaultStaleTime", void 0);
|
|
101
101
|
_defineProperty(this, "defaultMinLoaderDuration", void 0);
|
|
102
|
+
_defineProperty(this, "defaultScrollRestorationBehavior", void 0);
|
|
102
103
|
}
|
|
103
104
|
configure(config) {
|
|
104
105
|
Object.assign(this, config);
|
|
@@ -187,28 +188,6 @@ var updateScrollMap = (routeItemDataState, scrollMapState) => {
|
|
|
187
188
|
};
|
|
188
189
|
});
|
|
189
190
|
};
|
|
190
|
-
var restoreScroll = (scrollMap, pathname, behavior) => {
|
|
191
|
-
scrollMap[pathname].forEach(([key, scrollPosition]) => {
|
|
192
|
-
if (key === "__window_top__" || key === "__window_left__") {
|
|
193
|
-
requestAnimationFrame(() => {
|
|
194
|
-
window.scrollTo({
|
|
195
|
-
[key === "__window_top__" ? "top" : "left"]: scrollPosition,
|
|
196
|
-
behavior
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
const element = document.getElementById(key);
|
|
202
|
-
if (!element) return;
|
|
203
|
-
const axis = isVerticalScroll(element) ? "top" : "left";
|
|
204
|
-
requestAnimationFrame(() => {
|
|
205
|
-
element.scrollTo({
|
|
206
|
-
[axis]: scrollPosition,
|
|
207
|
-
behavior
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
});
|
|
211
|
-
};
|
|
212
191
|
var formatSearchObject = (searchObject) => {
|
|
213
192
|
const params = new URLSearchParams();
|
|
214
193
|
Object.entries(searchObject).forEach(([key, value]) => {
|
|
@@ -588,7 +567,7 @@ var createRevalidateCache = (routerState) => {
|
|
|
588
567
|
};
|
|
589
568
|
//#endregion
|
|
590
569
|
//#region creators/createRouterInstance.ts
|
|
591
|
-
var createRouterInstance = () => {
|
|
570
|
+
var createRouterInstance = (synchronizer) => {
|
|
592
571
|
const routerState = {
|
|
593
572
|
routeItemDataState: create({
|
|
594
573
|
routeItem: void 0,
|
|
@@ -632,12 +611,12 @@ var createRouterInstance = () => {
|
|
|
632
611
|
prefetch
|
|
633
612
|
},
|
|
634
613
|
hooks: {
|
|
635
|
-
useBlockerState: () => useGlobalState(routerState.blockerState),
|
|
636
|
-
useRouteItemData: () => useGlobalState(routerState.routeItemDataState),
|
|
637
|
-
useScrollMap: () => useGlobalState(routerState.scrollMapState),
|
|
638
|
-
useContextState: () => useGlobalState(routerState.contextState),
|
|
639
|
-
useBlockedTargetState: () => useGlobalState(routerState.blockedTargetState),
|
|
640
|
-
useLoaderState: () => useGlobalState(routerState.loaderState)[0],
|
|
614
|
+
useBlockerState: () => useGlobalState(routerState.blockerState, synchronizer),
|
|
615
|
+
useRouteItemData: () => useGlobalState(routerState.routeItemDataState, synchronizer),
|
|
616
|
+
useScrollMap: () => useGlobalState(routerState.scrollMapState, synchronizer),
|
|
617
|
+
useContextState: () => useGlobalState(routerState.contextState, synchronizer),
|
|
618
|
+
useBlockedTargetState: () => useGlobalState(routerState.blockedTargetState, synchronizer),
|
|
619
|
+
useLoaderState: () => useGlobalState(routerState.loaderState, synchronizer)[0],
|
|
641
620
|
useParams: () => {
|
|
642
621
|
const { routeItem, location } = routerState.routeItemDataState.getState();
|
|
643
622
|
return getParams(location, routeItem);
|
|
@@ -684,18 +663,42 @@ var createRouterInstance = () => {
|
|
|
684
663
|
}
|
|
685
664
|
};
|
|
686
665
|
},
|
|
687
|
-
|
|
666
|
+
useScrollRestoration: (restorationBehavior) => () => {
|
|
688
667
|
const { routeItem, location: { pathname } } = routerState.routeItemDataState.getState();
|
|
689
668
|
const scrollMap = routerState.scrollMapState.getState();
|
|
690
669
|
if (!routeItem || routeItem.scrollRestoration === false || !scrollMap[pathname]) return;
|
|
691
|
-
|
|
670
|
+
const behavior = routeItem.scrollRestorationBehavior ?? restorationBehavior;
|
|
671
|
+
scrollMap[pathname].forEach(([key, scrollPosition]) => {
|
|
672
|
+
if (key === "__window_top__" || key === "__window_left__") {
|
|
673
|
+
requestAnimationFrame(() => {
|
|
674
|
+
window.scrollTo({
|
|
675
|
+
[key === "__window_top__" ? "top" : "left"]: scrollPosition,
|
|
676
|
+
behavior
|
|
677
|
+
});
|
|
678
|
+
});
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
const element = document.getElementById(key);
|
|
682
|
+
if (!element) return;
|
|
683
|
+
const axis = isVerticalScroll(element) ? "top" : "left";
|
|
684
|
+
requestAnimationFrame(() => {
|
|
685
|
+
element.scrollTo({
|
|
686
|
+
[axis]: scrollPosition,
|
|
687
|
+
behavior
|
|
688
|
+
});
|
|
689
|
+
});
|
|
690
|
+
});
|
|
691
|
+
},
|
|
692
|
+
useRouteItemDataSelector: (callback) => {
|
|
693
|
+
const state = routerState.routeItemDataState;
|
|
694
|
+
return synchronizer(state.subscribe, () => callback(state.getState()));
|
|
692
695
|
}
|
|
693
696
|
}
|
|
694
697
|
};
|
|
695
698
|
};
|
|
696
699
|
//#endregion
|
|
697
700
|
//#region instance.ts
|
|
698
|
-
var router = createRouterInstance();
|
|
701
|
+
var router = createRouterInstance(useSyncExternalStore);
|
|
699
702
|
//#endregion
|
|
700
703
|
//#region hooks/useNavigation.ts
|
|
701
704
|
var useNavigation = () => {
|
|
@@ -767,13 +770,17 @@ var useApplyCustomAnimation = (animationDuration) => {
|
|
|
767
770
|
}, [animationDuration]);
|
|
768
771
|
};
|
|
769
772
|
//#endregion
|
|
773
|
+
//#region hooks/useRestoreScroll.ts
|
|
774
|
+
var useRestoreScroll = (behavior) => {
|
|
775
|
+
const { useScrollRestoration } = router.hooks;
|
|
776
|
+
const { defaultScrollRestorationBehavior = "auto" } = routerConfig;
|
|
777
|
+
return useScrollRestoration(behavior ?? defaultScrollRestorationBehavior);
|
|
778
|
+
};
|
|
779
|
+
//#endregion
|
|
770
780
|
//#region hooks/usePreserveScroll.ts
|
|
771
|
-
var usePreserveScroll = (
|
|
772
|
-
const
|
|
773
|
-
|
|
774
|
-
useEffect(() => {
|
|
775
|
-
restoreScroll?.();
|
|
776
|
-
}, [restoreScroll]);
|
|
781
|
+
var usePreserveScroll = (behavior) => {
|
|
782
|
+
const restoreScroll = useRestoreScroll(behavior);
|
|
783
|
+
useEffect(() => restoreScroll?.(), [restoreScroll]);
|
|
777
784
|
};
|
|
778
785
|
//#endregion
|
|
779
786
|
//#region hooks/useSetRouterConfig.ts
|
|
@@ -818,7 +825,8 @@ var Spinner = () => /* @__PURE__ */ jsx("span", {
|
|
|
818
825
|
//#region utils/renderElement.tsx
|
|
819
826
|
var renderElement = (Component) => {
|
|
820
827
|
if (!Component) return null;
|
|
821
|
-
|
|
828
|
+
if (typeof Component !== "function") return Component;
|
|
829
|
+
return /* @__PURE__ */ jsx(Component, {});
|
|
822
830
|
};
|
|
823
831
|
//#endregion
|
|
824
832
|
//#region components/Router.tsx
|
|
@@ -845,7 +853,8 @@ var Router = ({ routes, defaultBeforeLoad, defaultAfterLoad, animationDuration,
|
|
|
845
853
|
defaultMinLoaderDuration,
|
|
846
854
|
maxCacheSize,
|
|
847
855
|
revalidateOnFocus,
|
|
848
|
-
revalidateOnReconnect
|
|
856
|
+
revalidateOnReconnect,
|
|
857
|
+
defaultScrollRestorationBehavior
|
|
849
858
|
});
|
|
850
859
|
useApplyCustomAnimation(animationDuration);
|
|
851
860
|
useSetInitialContext(initialContext);
|
|
@@ -862,26 +871,21 @@ var Router = ({ routes, defaultBeforeLoad, defaultAfterLoad, animationDuration,
|
|
|
862
871
|
//#endregion
|
|
863
872
|
//#region hooks/useIsRoutePending.ts
|
|
864
873
|
var useIsRoutePending = (routePath) => {
|
|
865
|
-
const {
|
|
866
|
-
|
|
867
|
-
return routeItemData.status === "pending" && routeItemData?.location.pathname === routePath;
|
|
874
|
+
const { useRouteItemDataSelector } = router.hooks;
|
|
875
|
+
return useRouteItemDataSelector(({ location: { pathname }, status }) => pathname === routePath && status === "pending");
|
|
868
876
|
};
|
|
869
877
|
//#endregion
|
|
870
878
|
//#region hooks/useNavigate.ts
|
|
871
879
|
var useNavigate = router.hooks.useNavigate;
|
|
872
880
|
//#endregion
|
|
873
|
-
//#region hooks/useLocation.ts
|
|
874
|
-
var useLocation = () => {
|
|
875
|
-
const [routeItemData] = router.hooks.useRouteItemData();
|
|
876
|
-
return routeItemData.location;
|
|
877
|
-
};
|
|
878
|
-
//#endregion
|
|
879
881
|
//#region components/Link.tsx
|
|
880
882
|
var defaultAs = (props) => /* @__PURE__ */ jsx("a", { ...props });
|
|
883
|
+
var comparator = (to, pathname, exact) => to === "/" ? pathname === "/" : exact ? pathname === to : pathname === to || pathname?.startsWith(`${to}/`);
|
|
881
884
|
var Link = ({ children, to, search = "", state, as = defaultAs, prefetch: linkPrefetch, hoverPrefetchDelay, className, style, beforeNavigate, exact = false, activeClassName = "active-link", pendingClassName = "pending-link", ...rest }) => {
|
|
885
|
+
const { useRouteItemDataSelector } = router.hooks;
|
|
882
886
|
const isPending = useIsRoutePending(to);
|
|
883
|
-
const { pathname } = useLocation();
|
|
884
887
|
const navigate = useNavigate();
|
|
888
|
+
const isActive = useRouteItemDataSelector(({ location: { pathname } }) => comparator(to, pathname, exact));
|
|
885
889
|
const timeout = useRef(0);
|
|
886
890
|
const elementRef = useRef(null);
|
|
887
891
|
const { defaultPrefetch: configPrefetch, defaultHoverPrefetchDelay: configPrefetchDelay } = routerConfig;
|
|
@@ -934,7 +938,6 @@ var Link = ({ children, to, search = "", state, as = defaultAs, prefetch: linkPr
|
|
|
934
938
|
useEffect(() => () => {
|
|
935
939
|
if (timeout.current) clearTimeout(timeout.current);
|
|
936
940
|
}, []);
|
|
937
|
-
const isActive = to === "/" ? pathname === "/" : exact ? pathname === to : pathname === to || pathname?.startsWith(`${to}/`);
|
|
938
941
|
const normalizedClassName = typeof className === "function" ? className({
|
|
939
942
|
isActive,
|
|
940
943
|
isPending
|
|
@@ -955,10 +958,10 @@ var Link = ({ children, to, search = "", state, as = defaultAs, prefetch: linkPr
|
|
|
955
958
|
await navigate(location);
|
|
956
959
|
};
|
|
957
960
|
return as({
|
|
958
|
-
ref: elementRef,
|
|
959
|
-
style: normalizedStyle,
|
|
960
|
-
className: resultClassName,
|
|
961
|
-
onClick: clickHandler,
|
|
961
|
+
"ref": elementRef,
|
|
962
|
+
"style": normalizedStyle,
|
|
963
|
+
"className": resultClassName,
|
|
964
|
+
"onClick": clickHandler,
|
|
962
965
|
href: `${to}${searchString}`,
|
|
963
966
|
onMouseEnter,
|
|
964
967
|
onMouseLeave,
|
|
@@ -975,6 +978,12 @@ var Link = ({ children, to, search = "", state, as = defaultAs, prefetch: linkPr
|
|
|
975
978
|
//#region hooks/useParams.ts
|
|
976
979
|
var useParams = router.hooks.useParams;
|
|
977
980
|
//#endregion
|
|
981
|
+
//#region hooks/useLocation.ts
|
|
982
|
+
var useLocation = () => {
|
|
983
|
+
const [routeItemData] = router.hooks.useRouteItemData();
|
|
984
|
+
return routeItemData.location;
|
|
985
|
+
};
|
|
986
|
+
//#endregion
|
|
978
987
|
//#region hooks/useLoaderState.ts
|
|
979
988
|
var useLoaderState = router.hooks.useLoaderState;
|
|
980
989
|
//#endregion
|
|
@@ -1020,9 +1029,8 @@ var useAction = router.hooks.useAction;
|
|
|
1020
1029
|
//#endregion
|
|
1021
1030
|
//#region hooks/useIsDataLoading.ts
|
|
1022
1031
|
var useIsDataLoading = () => {
|
|
1023
|
-
const {
|
|
1024
|
-
|
|
1025
|
-
return routeData.status === "pending";
|
|
1032
|
+
const { useRouteItemDataSelector } = router.hooks;
|
|
1033
|
+
return useRouteItemDataSelector(({ status }) => status) === "pending";
|
|
1026
1034
|
};
|
|
1027
1035
|
//#endregion
|
|
1028
1036
|
//#region hooks/useRouterContext.ts
|
|
@@ -1144,4 +1152,4 @@ var lazy = (importFn) => ({
|
|
|
1144
1152
|
importFn
|
|
1145
1153
|
});
|
|
1146
1154
|
//#endregion
|
|
1147
|
-
export { Link, Router, createRouter, lazy, useAction, useBlocker, useInvalidate, useIsDataLoading, useLoaderState, useLocation, useNavigate, useParams, useRouterContext, useSearchParams, useSubmitAction };
|
|
1155
|
+
export { Link, Router, createRouter, lazy, useAction, useBlocker, useInvalidate, useIsDataLoading, useLoaderState, useLocation, useNavigate, useParams, useRestoreScroll, useRouterContext, useSearchParams, useSubmitAction };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Store, useGlobalState } from './create';
|
|
1
|
+
import type { Store, useGlobalState } from './create';
|
|
3
2
|
export declare const LAZY_MARKER: unique symbol;
|
|
3
|
+
export type SetStateFn<T> = (action: T | ((prevState: T) => T)) => void;
|
|
4
4
|
export type LazyComponent = {
|
|
5
5
|
readonly [LAZY_MARKER]: true;
|
|
6
6
|
importFn: () => Promise<{
|
|
7
|
-
default:
|
|
7
|
+
default: unknown;
|
|
8
8
|
}>;
|
|
9
9
|
};
|
|
10
|
-
export type RenderElement =
|
|
10
|
+
export type RenderElement = unknown;
|
|
11
11
|
type LoaderArgs = {
|
|
12
12
|
context: Record<string, unknown>;
|
|
13
13
|
params: Record<string, string>;
|
|
14
|
-
setContext:
|
|
14
|
+
setContext: SetStateFn<Record<string, unknown>>;
|
|
15
15
|
searchParams: Record<string, string>;
|
|
16
16
|
location: Location;
|
|
17
17
|
};
|
|
@@ -50,7 +50,7 @@ export type RouteItem = ClientRouteItem & {
|
|
|
50
50
|
pattern: string;
|
|
51
51
|
cacheTimestamp?: number;
|
|
52
52
|
preloadElement?(): Promise<{
|
|
53
|
-
default:
|
|
53
|
+
default: unknown;
|
|
54
54
|
}>;
|
|
55
55
|
};
|
|
56
56
|
export type Location = {
|
|
@@ -93,9 +93,7 @@ export type RouterProps = {
|
|
|
93
93
|
defaultHoverPrefetchDelay?: number;
|
|
94
94
|
defaultMinLoaderDuration?: number;
|
|
95
95
|
maxCacheSize?: number;
|
|
96
|
-
errorBoundary?:
|
|
97
|
-
children: ReactNode;
|
|
98
|
-
}>;
|
|
96
|
+
errorBoundary?: unknown;
|
|
99
97
|
defaultBeforeLoad?: ClientRouteItem['beforeLoad'];
|
|
100
98
|
defaultAfterLoad?: ClientRouteItem['afterLoad'];
|
|
101
99
|
defaultScrollRestorationBehavior?: ScrollRestorationBehavior;
|
|
@@ -146,7 +144,8 @@ export type RouterType = {
|
|
|
146
144
|
data: unknown;
|
|
147
145
|
error: Error | null;
|
|
148
146
|
}>;
|
|
149
|
-
|
|
147
|
+
useScrollRestoration(restorationBehavior: ScrollRestorationBehavior): () => void;
|
|
148
|
+
useRouteItemDataSelector<T>(callback: (arg: RouteItemData) => T): T;
|
|
150
149
|
};
|
|
151
150
|
};
|
|
152
151
|
export type InvalidateOptions = {
|
|
@@ -164,20 +163,9 @@ export type InvalidateResult = {
|
|
|
164
163
|
data: unknown;
|
|
165
164
|
error: Error | null;
|
|
166
165
|
};
|
|
167
|
-
export type ElementProps<T extends HTMLElement = HTMLElement> = {
|
|
168
|
-
'ref': Ref<T>;
|
|
169
|
-
'href': string;
|
|
170
|
-
'className'?: string;
|
|
171
|
-
'style'?: CSSProperties;
|
|
172
|
-
onClick(event: MouseEvent): void;
|
|
173
|
-
onMouseEnter(event: MouseEvent): void;
|
|
174
|
-
onMouseLeave(event: MouseEvent): void;
|
|
175
|
-
'children'?: ReactNode;
|
|
176
|
-
'aria-current'?: 'page';
|
|
177
|
-
'aria-busy'?: boolean;
|
|
178
|
-
} & Record<`data-${string}` | `aria-${string}`, unknown>;
|
|
179
166
|
export type SearchObject = Record<string, string | number | boolean | null | undefined>;
|
|
180
167
|
export type NavigationLocation = Omit<Location, 'search'> & {
|
|
181
168
|
search?: string | SearchObject;
|
|
182
169
|
};
|
|
170
|
+
export type Synchronizer = <T>(subscribe: (updater: () => void) => () => void, getSnapshot: () => T, getServerSnapshot?: () => T) => T;
|
|
183
171
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { type ComponentType
|
|
1
|
+
import { type ComponentType } from 'react';
|
|
2
2
|
export declare const createLazyComponent: (importFn: () => Promise<{
|
|
3
|
-
default:
|
|
4
|
-
}>, fallback?:
|
|
3
|
+
default: unknown;
|
|
4
|
+
}>, fallback?: unknown) => {
|
|
5
5
|
Component: () => import("react/jsx-runtime").JSX.Element;
|
|
6
6
|
preloadElement: () => Promise<{
|
|
7
7
|
default: ComponentType<unknown>;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import type { ReactElement } from 'react';
|
|
2
|
+
import type { RenderElement } from '../types';
|
|
3
|
+
export declare const renderElement: (Component?: RenderElement) => ReactElement | null;
|
package/dist/utils/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Store } from '../create';
|
|
2
|
-
import { Location, RouteItem, RouteItemData, RouterState, ScrollMap,
|
|
2
|
+
import { Location, RouteItem, RouteItemData, RouterState, ScrollMap, SearchObject } from '../types';
|
|
3
3
|
export declare const getParams: (location: Location, routeItem?: RouteItem) => Record<string, string>;
|
|
4
4
|
export declare const parseWindowLocation: (location: typeof window.location) => Location;
|
|
5
5
|
export declare const comparePaths: (route: RouteItem, pathname: string) => boolean;
|
|
@@ -8,11 +8,10 @@ export declare const sleep: (ms: number) => Promise<unknown>;
|
|
|
8
8
|
export declare const getPartialLoaderArgs: (contextState: RouterState["contextState"], location: Location, routeItem?: RouteItem) => {
|
|
9
9
|
params: Record<string, string>;
|
|
10
10
|
context: Record<string, unknown>;
|
|
11
|
-
setContext: (
|
|
11
|
+
setContext: import("../types").SetStateFn<Record<string, unknown>>;
|
|
12
12
|
searchParams: Record<string, string>;
|
|
13
13
|
location: Location;
|
|
14
14
|
};
|
|
15
15
|
export declare const isVerticalScroll: (el: Element | null) => boolean;
|
|
16
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
17
|
export declare const formatSearchObject: (searchObject: SearchObject) => string;
|