clear-react-router 2.1.3 → 2.1.5
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 +10 -9
- package/dist/index.d.ts +1 -1
- package/dist/index.js +61 -59
- package/dist/runtime/invalidate.d.ts +1 -1
- package/dist/types.d.ts +16 -23
- package/dist/utils/utils.d.ts +6 -4
- package/package.json +2 -2
- /package/dist/{utils → creators}/createRouter.d.ts +0 -0
- /package/dist/{utils → creators}/createRouterInstance.d.ts +0 -0
- /package/dist/{utils → runtime}/revalidateCache.d.ts +0 -0
package/README.md
CHANGED
|
@@ -414,12 +414,15 @@ actions?: ({ context, params, invalidate, setContext }) => ({
|
|
|
414
414
|
|
|
415
415
|
#### Arguments
|
|
416
416
|
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
417
|
+
```ts
|
|
418
|
+
{
|
|
419
|
+
params: Record<string, string>; // Route parameters
|
|
420
|
+
context: Record<string, unknown>; // Router context
|
|
421
|
+
setContext: Dispatch<SetStateAction<Record<string, unknown>>>; // Updates the router context
|
|
422
|
+
searchParams: Record<string, string>; // URL search parameters
|
|
423
|
+
location: Location; // Route location
|
|
424
|
+
}
|
|
425
|
+
```
|
|
423
426
|
|
|
424
427
|
#### Returns
|
|
425
428
|
|
|
@@ -427,9 +430,7 @@ A record where each key is an action name and each value is a function accepting
|
|
|
427
430
|
|
|
428
431
|
## useSubmitAction()
|
|
429
432
|
|
|
430
|
-
`useSubmitAction` wraps a route's `action` with submission state (`isSubmitting`, `data`, `error`) and
|
|
431
|
-
gives you two ways to trigger it — a ready-made `onSubmit` for native forms, or a raw `submit(formData)`
|
|
432
|
-
you can call from any form library.
|
|
433
|
+
`useSubmitAction` wraps a route's `action` with submission state (`isSubmitting`, `data`, `error`) and gives you two ways to trigger it — a ready-made `onSubmit` for native forms, or a raw `submit(formData)` you can call from any form library.
|
|
433
434
|
|
|
434
435
|
```tsx
|
|
435
436
|
import { useSubmitAction } from 'clear-react-router';
|
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,6 @@ 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 { createRouter } from './
|
|
14
|
+
export { createRouter } from './creators/createRouter';
|
|
15
15
|
export { lazy } from './utils/lazy';
|
|
16
16
|
export type { RouteItem, BlockerState, Location, RouterProps, ElementProps } from './types';
|
package/dist/index.js
CHANGED
|
@@ -126,12 +126,9 @@ var createIsCacheItemFresh = (loaderMap) => (path) => {
|
|
|
126
126
|
};
|
|
127
127
|
//#endregion
|
|
128
128
|
//#region utils/utils.ts
|
|
129
|
-
var
|
|
130
|
-
const { routeItem: stateItem, location: { pathname: statePathname } } = router.state.routeItemDataState.getState();
|
|
131
|
-
const routeItem = nextItem || stateItem;
|
|
132
|
-
const pathname = nextPathname || statePathname;
|
|
129
|
+
var getParams = (location, routeItem) => {
|
|
133
130
|
if (!routeItem) return {};
|
|
134
|
-
const pathnameSegments = pathname.split("/");
|
|
131
|
+
const pathnameSegments = location.pathname.split("/");
|
|
135
132
|
return routeItem.pattern.split("/").reduce((acc, segment, index) => {
|
|
136
133
|
if (segment.startsWith(":")) acc[segment.slice(1)] = pathnameSegments[index];
|
|
137
134
|
return acc;
|
|
@@ -152,11 +149,9 @@ var isMobile = () => {
|
|
|
152
149
|
return hasCoarsePointer && isSmallScreen;
|
|
153
150
|
};
|
|
154
151
|
var sleep = async (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
155
|
-
var getPartialLoaderArgs = (location) => {
|
|
156
|
-
const params = getParamsObject();
|
|
157
|
-
const { contextState } = router.state;
|
|
152
|
+
var getPartialLoaderArgs = (contextState, location, routeItem) => {
|
|
158
153
|
return {
|
|
159
|
-
params,
|
|
154
|
+
params: getParams(location, routeItem),
|
|
160
155
|
context: contextState.getState(),
|
|
161
156
|
setContext: contextState.setState,
|
|
162
157
|
searchParams: Object.fromEntries(new URLSearchParams(location.search).entries()),
|
|
@@ -164,8 +159,7 @@ var getPartialLoaderArgs = (location) => {
|
|
|
164
159
|
};
|
|
165
160
|
};
|
|
166
161
|
var isVerticalScroll = (el) => !!el && el.scrollHeight > el.clientHeight;
|
|
167
|
-
var updateScrollMap = () => {
|
|
168
|
-
const { routeItemDataState, scrollMapState } = router.state;
|
|
162
|
+
var updateScrollMap = (routeItemDataState, scrollMapState) => {
|
|
169
163
|
const { routeItem, location: { pathname } } = routeItemDataState.getState();
|
|
170
164
|
scrollMapState.setState((prevState) => {
|
|
171
165
|
if (Array.isArray(routeItem?.scrollRestoration)) return {
|
|
@@ -190,6 +184,28 @@ var updateScrollMap = () => {
|
|
|
190
184
|
};
|
|
191
185
|
});
|
|
192
186
|
};
|
|
187
|
+
var restoreScroll = (scrollMap, pathname, behavior) => {
|
|
188
|
+
scrollMap[pathname].forEach(([key, scrollPosition]) => {
|
|
189
|
+
if (key === "__window_top__" || key === "__window_left__") {
|
|
190
|
+
requestAnimationFrame(() => {
|
|
191
|
+
window.scrollTo({
|
|
192
|
+
[key === "__window_top__" ? "top" : "left"]: scrollPosition,
|
|
193
|
+
behavior
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const element = document.getElementById(key);
|
|
199
|
+
if (!element) return;
|
|
200
|
+
const axis = isVerticalScroll(element) ? "top" : "left";
|
|
201
|
+
requestAnimationFrame(() => {
|
|
202
|
+
element.scrollTo({
|
|
203
|
+
[axis]: scrollPosition,
|
|
204
|
+
behavior
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
};
|
|
193
209
|
var findRoute = (pathname, includeAll) => {
|
|
194
210
|
if (includeAll) return routerConfig.routes.find((el) => el.path === "*" || comparePaths(el, pathname));
|
|
195
211
|
return routerConfig.routes.find((el) => comparePaths(el, pathname));
|
|
@@ -200,7 +216,7 @@ var createNavigate = (routerState, revalidateCache) => {
|
|
|
200
216
|
let navigationSeq = 0;
|
|
201
217
|
let interval = 0;
|
|
202
218
|
let abortController = null;
|
|
203
|
-
const { loaderState, loaderStateRef, statusState, contextState, loaderMap, routeItemDataState } = routerState;
|
|
219
|
+
const { loaderState, loaderStateRef, statusState, contextState, loaderMap, routeItemDataState, scrollMapState } = routerState;
|
|
204
220
|
const navigationExecutor = createCommitState(routerState);
|
|
205
221
|
const isCacheItemFresh = createIsCacheItemFresh(loaderMap);
|
|
206
222
|
const createSignal = () => {
|
|
@@ -218,7 +234,7 @@ var createNavigate = (routerState, revalidateCache) => {
|
|
|
218
234
|
const nextItem = findRoute(location.pathname, true);
|
|
219
235
|
return {
|
|
220
236
|
nextItem,
|
|
221
|
-
params:
|
|
237
|
+
params: getParams(location, nextItem)
|
|
222
238
|
};
|
|
223
239
|
};
|
|
224
240
|
const beforeLoad = async (routeItem, nextLocation) => {
|
|
@@ -228,7 +244,7 @@ var createNavigate = (routerState, revalidateCache) => {
|
|
|
228
244
|
try {
|
|
229
245
|
await loaderFn({
|
|
230
246
|
redirect,
|
|
231
|
-
...getPartialLoaderArgs(nextLocation)
|
|
247
|
+
...getPartialLoaderArgs(contextState, nextLocation, routeItem)
|
|
232
248
|
});
|
|
233
249
|
loaderStateRef.set((prev) => ({
|
|
234
250
|
...prev,
|
|
@@ -245,7 +261,7 @@ var createNavigate = (routerState, revalidateCache) => {
|
|
|
245
261
|
if (routeItem?.beforeLoad) await runBeforeLoad(routeItem?.beforeLoad);
|
|
246
262
|
};
|
|
247
263
|
const prepareNavigation = (routeItem, location) => {
|
|
248
|
-
updateScrollMap();
|
|
264
|
+
updateScrollMap(routeItemDataState, scrollMapState);
|
|
249
265
|
const path = getPath(location);
|
|
250
266
|
if (routeItem?.optimistic && loaderMap.has(path)) {
|
|
251
267
|
routeItemDataState.setState({
|
|
@@ -322,7 +338,7 @@ var createNavigate = (routerState, revalidateCache) => {
|
|
|
322
338
|
//#endregion
|
|
323
339
|
//#region runtime/invalidate.ts
|
|
324
340
|
var redirect = Promise.resolve;
|
|
325
|
-
var createInvalidate = ({ routeItemDataState, loaderState, loaderMap }, revalidateCache) => {
|
|
341
|
+
var createInvalidate = ({ routeItemDataState, loaderState, loaderMap, contextState }, revalidateCache) => {
|
|
326
342
|
const invalidatePath = async (routeItem, pathname, options) => {
|
|
327
343
|
const routePathname = routeItemDataState.getState().location.pathname;
|
|
328
344
|
loaderMap.delete(pathname);
|
|
@@ -334,7 +350,7 @@ var createInvalidate = ({ routeItemDataState, loaderState, loaderMap }, revalida
|
|
|
334
350
|
if (routeItem?.beforeLoad && options?.withBeforeLoad) try {
|
|
335
351
|
await routeItem.beforeLoad({
|
|
336
352
|
redirect,
|
|
337
|
-
...getPartialLoaderArgs(location)
|
|
353
|
+
...getPartialLoaderArgs(contextState, location, routeItem)
|
|
338
354
|
});
|
|
339
355
|
loaderState.setState((prev) => ({
|
|
340
356
|
...prev,
|
|
@@ -392,7 +408,7 @@ var createPrefetch = ({ routeItemDataState }, revalidateCache) => async (locatio
|
|
|
392
408
|
}
|
|
393
409
|
};
|
|
394
410
|
//#endregion
|
|
395
|
-
//#region
|
|
411
|
+
//#region runtime/revalidateCache.ts
|
|
396
412
|
var isObjectRetry = (arg) => typeof arg === "object";
|
|
397
413
|
var createRetry = (arg) => {
|
|
398
414
|
if (arg === void 0) return null;
|
|
@@ -411,7 +427,7 @@ var getRetry = (routeItem) => {
|
|
|
411
427
|
};
|
|
412
428
|
};
|
|
413
429
|
var createRevalidateCache = (routerState) => {
|
|
414
|
-
const { loaderMap, loadingPromises } = routerState;
|
|
430
|
+
const { loaderMap, loadingPromises, contextState } = routerState;
|
|
415
431
|
const evict = () => {
|
|
416
432
|
if (loaderMap.size <= routerConfig.maxCacheSize) return;
|
|
417
433
|
const oldestKey = loaderMap.keys().next().value;
|
|
@@ -450,7 +466,7 @@ var createRevalidateCache = (routerState) => {
|
|
|
450
466
|
const effectiveSignal = signal ?? new AbortController().signal;
|
|
451
467
|
try {
|
|
452
468
|
const result = await routeItem?.loader({
|
|
453
|
-
...getPartialLoaderArgs(location),
|
|
469
|
+
...getPartialLoaderArgs(contextState, location, routeItem),
|
|
454
470
|
signal: effectiveSignal
|
|
455
471
|
});
|
|
456
472
|
loaderMap.set(path, {
|
|
@@ -513,7 +529,7 @@ var Cell = class {
|
|
|
513
529
|
}
|
|
514
530
|
};
|
|
515
531
|
//#endregion
|
|
516
|
-
//#region
|
|
532
|
+
//#region creators/createRouterInstance.ts
|
|
517
533
|
var createRouterInstance = () => {
|
|
518
534
|
const routerState = {
|
|
519
535
|
routeItemDataState: create({
|
|
@@ -536,18 +552,20 @@ var createRouterInstance = () => {
|
|
|
536
552
|
const invalidate = createInvalidate(routerState, revalidateCache);
|
|
537
553
|
const navigate = createNavigate(routerState, revalidateCache);
|
|
538
554
|
const prefetch = createPrefetch(routerState, revalidateCache);
|
|
539
|
-
const
|
|
540
|
-
const { routeItem } = routerState.routeItemDataState.getState();
|
|
541
|
-
const context = routerState.contextState.getState();
|
|
542
|
-
const setContext = routerState.contextState.setState;
|
|
543
|
-
const params = getParamsObject();
|
|
555
|
+
const getCurrentAction = (actionKey) => {
|
|
556
|
+
const { routeItem, location } = routerState.routeItemDataState.getState();
|
|
544
557
|
if (!routeItem) throw new Error("Route not found");
|
|
545
558
|
if (!routeItem.actions) throw new Error("Route action creator not found");
|
|
559
|
+
const context = routerState.contextState.getState();
|
|
560
|
+
const setContext = routerState.contextState.setState;
|
|
561
|
+
const params = getParams(location, routeItem);
|
|
562
|
+
const searchParams = Object.fromEntries(new URLSearchParams(location.search).entries());
|
|
546
563
|
const action = routeItem.actions({
|
|
547
564
|
context,
|
|
548
565
|
setContext,
|
|
549
566
|
params,
|
|
550
|
-
|
|
567
|
+
location,
|
|
568
|
+
searchParams
|
|
551
569
|
})[actionKey];
|
|
552
570
|
if (!action) throw new Error(`Action "${actionKey}" not found`);
|
|
553
571
|
return action;
|
|
@@ -566,7 +584,10 @@ var createRouterInstance = () => {
|
|
|
566
584
|
useStatus: () => useGlobalState(routerState.statusState),
|
|
567
585
|
useContextState: () => useGlobalState(routerState.contextState),
|
|
568
586
|
useLoaderState: () => useGlobalState(routerState.loaderState)[0],
|
|
569
|
-
useParams: () =>
|
|
587
|
+
useParams: () => {
|
|
588
|
+
const { routeItem, location } = routerState.routeItemDataState.getState();
|
|
589
|
+
return getParams(location, routeItem);
|
|
590
|
+
},
|
|
570
591
|
useNavigate: () => {
|
|
571
592
|
const { blockedRouteState } = routerState;
|
|
572
593
|
const { location } = routerState.routeItemDataState.getState();
|
|
@@ -586,7 +607,7 @@ var createRouterInstance = () => {
|
|
|
586
607
|
};
|
|
587
608
|
},
|
|
588
609
|
useAction: (action, options = {}) => {
|
|
589
|
-
const currentAction =
|
|
610
|
+
const currentAction = getCurrentAction(action);
|
|
590
611
|
return async (formData) => {
|
|
591
612
|
try {
|
|
592
613
|
const data = await currentAction(formData);
|
|
@@ -604,6 +625,12 @@ var createRouterInstance = () => {
|
|
|
604
625
|
};
|
|
605
626
|
}
|
|
606
627
|
};
|
|
628
|
+
},
|
|
629
|
+
useRestoreScroll: (restorationBehavior) => {
|
|
630
|
+
const { routeItem, location: { pathname } } = routerState.routeItemDataState.getState();
|
|
631
|
+
const scrollMap = routerState.scrollMapState.getState();
|
|
632
|
+
if (!routeItem || routeItem.scrollRestoration === false || !scrollMap[pathname]) return;
|
|
633
|
+
return () => restoreScroll(scrollMap, pathname, routeItem.scrollRestorationBehavior ?? restorationBehavior);
|
|
607
634
|
}
|
|
608
635
|
}
|
|
609
636
|
};
|
|
@@ -680,36 +707,11 @@ var useApplyCustomAnimation = (animationDuration) => {
|
|
|
680
707
|
//#endregion
|
|
681
708
|
//#region hooks/usePreserveScroll.ts
|
|
682
709
|
var usePreserveScroll = (restorationBehavior) => {
|
|
683
|
-
const {
|
|
684
|
-
const
|
|
710
|
+
const { useRestoreScroll } = router.hooks;
|
|
711
|
+
const restoreScroll = useRestoreScroll(restorationBehavior);
|
|
685
712
|
useEffect(() => {
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
scrollMap[pathname].forEach(([key, scrollPosition]) => {
|
|
689
|
-
if (key === "__window_top__" || key === "__window_left__") {
|
|
690
|
-
requestAnimationFrame(() => {
|
|
691
|
-
window.scrollTo({
|
|
692
|
-
[key === "__window_top__" ? "top" : "left"]: scrollPosition,
|
|
693
|
-
behavior
|
|
694
|
-
});
|
|
695
|
-
});
|
|
696
|
-
return;
|
|
697
|
-
}
|
|
698
|
-
const element = document.getElementById(key);
|
|
699
|
-
if (!element) return;
|
|
700
|
-
const axis = isVerticalScroll(element) ? "top" : "left";
|
|
701
|
-
requestAnimationFrame(() => {
|
|
702
|
-
element.scrollTo({
|
|
703
|
-
[axis]: scrollPosition,
|
|
704
|
-
behavior
|
|
705
|
-
});
|
|
706
|
-
});
|
|
707
|
-
});
|
|
708
|
-
}, [
|
|
709
|
-
pathname,
|
|
710
|
-
routeItem?.scrollRestoration,
|
|
711
|
-
scrollMap
|
|
712
|
-
]);
|
|
713
|
+
restoreScroll?.();
|
|
714
|
+
}, [restoreScroll]);
|
|
713
715
|
};
|
|
714
716
|
//#endregion
|
|
715
717
|
//#region hooks/useSetRouterConfig.ts
|
|
@@ -1091,7 +1093,7 @@ var createLazyComponent = (importFn, fallback) => {
|
|
|
1091
1093
|
//#region types.ts
|
|
1092
1094
|
var LAZY_MARKER = Symbol("clear-router-lazy");
|
|
1093
1095
|
//#endregion
|
|
1094
|
-
//#region
|
|
1096
|
+
//#region creators/createRouter.ts
|
|
1095
1097
|
var isLazy = (el) => typeof el.element === "object" && el.element !== null && LAZY_MARKER in el.element;
|
|
1096
1098
|
var parseClientRouteItem = (el, parentPattern = "") => {
|
|
1097
1099
|
const pattern = `${parentPattern}/${el.path}`.replace(/\/+/g, "/");
|
|
@@ -1,2 +1,2 @@
|
|
|
1
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[]>;
|
|
2
|
+
export declare const createInvalidate: ({ routeItemDataState, loaderState, loaderMap, contextState }: RouterState, revalidateCache: RevalidateCache) => (pathList?: string | string[], options?: InvalidateOptions) => Promise<InvalidateResult[]>;
|
package/dist/types.d.ts
CHANGED
|
@@ -9,25 +9,22 @@ export type LazyComponent = {
|
|
|
9
9
|
}>;
|
|
10
10
|
};
|
|
11
11
|
export type RenderElement = (() => ReactElement) | ReactElement;
|
|
12
|
-
|
|
12
|
+
type LoaderArgs = {
|
|
13
13
|
context: Record<string, unknown>;
|
|
14
|
-
redirect: (arg: Location | string) => Promise<void>;
|
|
15
14
|
params: Record<string, string>;
|
|
16
15
|
setContext: Dispatch<SetStateAction<Record<string, unknown>>>;
|
|
17
16
|
searchParams: Record<string, string>;
|
|
18
17
|
location: Location;
|
|
18
|
+
};
|
|
19
|
+
export type BeforeLoad = (arg: LoaderArgs & {
|
|
20
|
+
redirect: (arg: Location | string) => Promise<void>;
|
|
19
21
|
}) => Promise<unknown> | undefined | void;
|
|
20
22
|
export type ScrollRestorationBehavior = 'auto' | 'smooth' | 'instant';
|
|
21
23
|
export type ClientRouteItem = {
|
|
22
24
|
path: string;
|
|
23
25
|
element: RenderElement | LazyComponent;
|
|
24
|
-
loader?(arg: {
|
|
25
|
-
params: Record<string, string>;
|
|
26
|
-
context: Record<string, unknown>;
|
|
27
|
-
setContext: Dispatch<SetStateAction<Record<string, unknown>>>;
|
|
28
|
-
searchParams: Record<string, string>;
|
|
26
|
+
loader?(arg: LoaderArgs & {
|
|
29
27
|
signal: AbortSignal;
|
|
30
|
-
location: Location;
|
|
31
28
|
}): Promise<unknown>;
|
|
32
29
|
loaderFallback?: RenderElement;
|
|
33
30
|
errorElement?: RenderElement;
|
|
@@ -46,12 +43,7 @@ export type ClientRouteItem = {
|
|
|
46
43
|
params: Record<string, string>;
|
|
47
44
|
setContext: Dispatch<SetStateAction<Record<string, unknown>>>;
|
|
48
45
|
}) => Promise<void>;
|
|
49
|
-
actions?: (arg:
|
|
50
|
-
context: Record<string, unknown>;
|
|
51
|
-
params: Record<string, string>;
|
|
52
|
-
invalidate: (path?: string) => Promise<InvalidateResult[]>;
|
|
53
|
-
setContext: Dispatch<SetStateAction<Record<string, unknown>>>;
|
|
54
|
-
}) => Record<string, (arg: FormData) => Promise<unknown> | Promise<void> | void | unknown>;
|
|
46
|
+
actions?: (arg: LoaderArgs) => Record<string, (arg: FormData) => Promise<unknown> | Promise<void> | void | unknown>;
|
|
55
47
|
};
|
|
56
48
|
export type RouteItem = ClientRouteItem & {
|
|
57
49
|
element: RenderElement;
|
|
@@ -143,21 +135,22 @@ export type RouterType = {
|
|
|
143
135
|
prefetch(location: Location): Promise<void>;
|
|
144
136
|
};
|
|
145
137
|
hooks: {
|
|
146
|
-
useBlockedRoute
|
|
138
|
+
useBlockedRoute(): ReturnType<typeof useGlobalState<{
|
|
147
139
|
from: string;
|
|
148
140
|
to: string;
|
|
149
141
|
}>>;
|
|
150
|
-
useRouteItemData
|
|
151
|
-
useScrollMap
|
|
152
|
-
useStatus
|
|
153
|
-
useContextState
|
|
154
|
-
useLoaderState
|
|
155
|
-
useParams
|
|
156
|
-
useNavigate
|
|
157
|
-
useAction
|
|
142
|
+
useRouteItemData(): ReturnType<typeof useGlobalState<RouteItemData>>;
|
|
143
|
+
useScrollMap(): ReturnType<typeof useGlobalState<ScrollMap>>;
|
|
144
|
+
useStatus(): ReturnType<typeof useGlobalState<Status>>;
|
|
145
|
+
useContextState(): ReturnType<typeof useGlobalState<Record<string, unknown>>>;
|
|
146
|
+
useLoaderState<T>(): LoaderState<T>;
|
|
147
|
+
useParams<T>(): T;
|
|
148
|
+
useNavigate(): (arg: Location | string | -1) => Promise<void>;
|
|
149
|
+
useAction(action: string, options?: Options): (arg: FormData) => Promise<{
|
|
158
150
|
data: unknown;
|
|
159
151
|
error: Error | null;
|
|
160
152
|
}>;
|
|
153
|
+
useRestoreScroll(restorationBehavior: ScrollRestorationBehavior): (() => void) | undefined;
|
|
161
154
|
};
|
|
162
155
|
};
|
|
163
156
|
export type InvalidateOptions = {
|
package/dist/utils/utils.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { Location, RouteItem } from '../types';
|
|
2
|
-
|
|
1
|
+
import { Location, RouteItem, RouteItemData, RouterState, ScrollMap, ScrollRestorationBehavior } from '../types';
|
|
2
|
+
import { Store } from '../create';
|
|
3
|
+
export declare const getParams: (location: Location, routeItem?: RouteItem) => Record<string, string>;
|
|
3
4
|
export declare const parseWindowLocation: (location: typeof window.location) => Location;
|
|
4
5
|
export declare const comparePaths: (route: RouteItem, pathname: string) => boolean;
|
|
5
6
|
export declare const isMobile: () => boolean;
|
|
6
7
|
export declare const sleep: (ms: number) => Promise<unknown>;
|
|
7
|
-
export declare const getPartialLoaderArgs: (location: Location) => {
|
|
8
|
+
export declare const getPartialLoaderArgs: (contextState: RouterState["contextState"], location: Location, routeItem?: RouteItem) => {
|
|
8
9
|
params: Record<string, string>;
|
|
9
10
|
context: Record<string, unknown>;
|
|
10
11
|
setContext: (action: Record<string, unknown> | ((prevState: Record<string, unknown>) => Record<string, unknown>)) => void;
|
|
@@ -12,4 +13,5 @@ export declare const getPartialLoaderArgs: (location: Location) => {
|
|
|
12
13
|
location: Location;
|
|
13
14
|
};
|
|
14
15
|
export declare const isVerticalScroll: (el: Element | null) => boolean;
|
|
15
|
-
export declare const updateScrollMap: () => void;
|
|
16
|
+
export declare const updateScrollMap: (routeItemDataState: Store<RouteItemData>, scrollMapState: Store<ScrollMap>) => void;
|
|
17
|
+
export declare const restoreScroll: (scrollMap: ScrollMap, pathname: string, behavior: ScrollRestorationBehavior) => void;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clear-react-router",
|
|
3
|
-
"version": "2.1.
|
|
4
|
-
"description": "A lightweight
|
|
3
|
+
"version": "2.1.5",
|
|
4
|
+
"description": "A lightweight routing library for React applications",
|
|
5
5
|
"author": "Andrew Bubnov",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"build": "vite build && tsc --emitDeclarationOnly"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|