clear-react-router 2.1.4 → 2.1.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 +0 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +75 -76
- package/dist/runtime/invalidate.d.ts +1 -1
- package/dist/types.d.ts +11 -10
- package/dist/utils/commitNavigation.d.ts +1 -1
- package/dist/utils/commitState.d.ts +1 -1
- 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
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
[](https://www.npmjs.com/package/clear-react-router)
|
|
2
|
-
|
|
3
1
|
# Clear Router
|
|
4
2
|
|
|
5
3
|
A lightweight, type-safe routing library for client side React applications with nested routes, data loading, navigation blocking, prefetching, and route actions.
|
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
|
@@ -30,12 +30,13 @@ var useGlobalState = ({ subscribe, getState, setState }) => {
|
|
|
30
30
|
};
|
|
31
31
|
//#endregion
|
|
32
32
|
//#region utils/commitState.ts
|
|
33
|
-
var createCommitState = ({
|
|
34
|
-
routeItemDataState.setState({
|
|
33
|
+
var createCommitState = ({ statusState, loaderStateRef, loaderState, routeItemDataState }) => (nextLocation, routeItem) => {
|
|
34
|
+
if (!routeItem?.loader) routeItemDataState.setState({
|
|
35
35
|
routeItem,
|
|
36
36
|
location: nextLocation
|
|
37
37
|
});
|
|
38
|
-
|
|
38
|
+
const isError = loaderStateRef.value.loaderError || loaderStateRef.value.beforeLoadError;
|
|
39
|
+
statusState.setState(isError ? "error" : "active");
|
|
39
40
|
loaderState.setState(loaderStateRef.value);
|
|
40
41
|
if ((nextLocation.search ? `${nextLocation.pathname}${nextLocation.search}` : nextLocation.pathname) === window.location.pathname + window.location.search) return;
|
|
41
42
|
history.pushState(null, "", `${nextLocation.pathname}${nextLocation.search}`);
|
|
@@ -105,8 +106,8 @@ var RouterConfig = class {
|
|
|
105
106
|
var routerConfig = new RouterConfig();
|
|
106
107
|
//#endregion
|
|
107
108
|
//#region utils/commitNavigation.ts
|
|
108
|
-
var commitNavigation = (callback) => {
|
|
109
|
-
if (!routerConfig.isAnimated) return callback();
|
|
109
|
+
var commitNavigation = (callback, isCommited) => {
|
|
110
|
+
if (!routerConfig.isAnimated || isCommited) return callback();
|
|
110
111
|
try {
|
|
111
112
|
const transition = document.startViewTransition(callback);
|
|
112
113
|
transition.ready.catch(() => {});
|
|
@@ -126,12 +127,9 @@ var createIsCacheItemFresh = (loaderMap) => (path) => {
|
|
|
126
127
|
};
|
|
127
128
|
//#endregion
|
|
128
129
|
//#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;
|
|
130
|
+
var getParams = (location, routeItem) => {
|
|
133
131
|
if (!routeItem) return {};
|
|
134
|
-
const pathnameSegments = pathname.split("/");
|
|
132
|
+
const pathnameSegments = location.pathname.split("/");
|
|
135
133
|
return routeItem.pattern.split("/").reduce((acc, segment, index) => {
|
|
136
134
|
if (segment.startsWith(":")) acc[segment.slice(1)] = pathnameSegments[index];
|
|
137
135
|
return acc;
|
|
@@ -152,11 +150,9 @@ var isMobile = () => {
|
|
|
152
150
|
return hasCoarsePointer && isSmallScreen;
|
|
153
151
|
};
|
|
154
152
|
var sleep = async (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
155
|
-
var getPartialLoaderArgs = (location) => {
|
|
156
|
-
const params = getParamsObject();
|
|
157
|
-
const { contextState } = router.state;
|
|
153
|
+
var getPartialLoaderArgs = (contextState, location, routeItem) => {
|
|
158
154
|
return {
|
|
159
|
-
params,
|
|
155
|
+
params: getParams(location, routeItem),
|
|
160
156
|
context: contextState.getState(),
|
|
161
157
|
setContext: contextState.setState,
|
|
162
158
|
searchParams: Object.fromEntries(new URLSearchParams(location.search).entries()),
|
|
@@ -164,8 +160,7 @@ var getPartialLoaderArgs = (location) => {
|
|
|
164
160
|
};
|
|
165
161
|
};
|
|
166
162
|
var isVerticalScroll = (el) => !!el && el.scrollHeight > el.clientHeight;
|
|
167
|
-
var updateScrollMap = () => {
|
|
168
|
-
const { routeItemDataState, scrollMapState } = router.state;
|
|
163
|
+
var updateScrollMap = (routeItemDataState, scrollMapState) => {
|
|
169
164
|
const { routeItem, location: { pathname } } = routeItemDataState.getState();
|
|
170
165
|
scrollMapState.setState((prevState) => {
|
|
171
166
|
if (Array.isArray(routeItem?.scrollRestoration)) return {
|
|
@@ -190,6 +185,28 @@ var updateScrollMap = () => {
|
|
|
190
185
|
};
|
|
191
186
|
});
|
|
192
187
|
};
|
|
188
|
+
var restoreScroll = (scrollMap, pathname, behavior) => {
|
|
189
|
+
scrollMap[pathname].forEach(([key, scrollPosition]) => {
|
|
190
|
+
if (key === "__window_top__" || key === "__window_left__") {
|
|
191
|
+
requestAnimationFrame(() => {
|
|
192
|
+
window.scrollTo({
|
|
193
|
+
[key === "__window_top__" ? "top" : "left"]: scrollPosition,
|
|
194
|
+
behavior
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
const element = document.getElementById(key);
|
|
200
|
+
if (!element) return;
|
|
201
|
+
const axis = isVerticalScroll(element) ? "top" : "left";
|
|
202
|
+
requestAnimationFrame(() => {
|
|
203
|
+
element.scrollTo({
|
|
204
|
+
[axis]: scrollPosition,
|
|
205
|
+
behavior
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
};
|
|
193
210
|
var findRoute = (pathname, includeAll) => {
|
|
194
211
|
if (includeAll) return routerConfig.routes.find((el) => el.path === "*" || comparePaths(el, pathname));
|
|
195
212
|
return routerConfig.routes.find((el) => comparePaths(el, pathname));
|
|
@@ -200,8 +217,8 @@ var createNavigate = (routerState, revalidateCache) => {
|
|
|
200
217
|
let navigationSeq = 0;
|
|
201
218
|
let interval = 0;
|
|
202
219
|
let abortController = null;
|
|
203
|
-
const { loaderState, loaderStateRef, statusState, contextState, loaderMap, routeItemDataState } = routerState;
|
|
204
|
-
const
|
|
220
|
+
const { loaderState, loaderStateRef, statusState, contextState, loaderMap, routeItemDataState, scrollMapState } = routerState;
|
|
221
|
+
const commitState = createCommitState(routerState);
|
|
205
222
|
const isCacheItemFresh = createIsCacheItemFresh(loaderMap);
|
|
206
223
|
const createSignal = () => {
|
|
207
224
|
abortController?.abort();
|
|
@@ -218,7 +235,7 @@ var createNavigate = (routerState, revalidateCache) => {
|
|
|
218
235
|
const nextItem = findRoute(location.pathname, true);
|
|
219
236
|
return {
|
|
220
237
|
nextItem,
|
|
221
|
-
params:
|
|
238
|
+
params: getParams(location, nextItem)
|
|
222
239
|
};
|
|
223
240
|
};
|
|
224
241
|
const beforeLoad = async (routeItem, nextLocation) => {
|
|
@@ -228,7 +245,7 @@ var createNavigate = (routerState, revalidateCache) => {
|
|
|
228
245
|
try {
|
|
229
246
|
await loaderFn({
|
|
230
247
|
redirect,
|
|
231
|
-
...getPartialLoaderArgs(nextLocation)
|
|
248
|
+
...getPartialLoaderArgs(contextState, nextLocation, routeItem)
|
|
232
249
|
});
|
|
233
250
|
loaderStateRef.set((prev) => ({
|
|
234
251
|
...prev,
|
|
@@ -245,20 +262,19 @@ var createNavigate = (routerState, revalidateCache) => {
|
|
|
245
262
|
if (routeItem?.beforeLoad) await runBeforeLoad(routeItem?.beforeLoad);
|
|
246
263
|
};
|
|
247
264
|
const prepareNavigation = (routeItem, location) => {
|
|
248
|
-
updateScrollMap();
|
|
265
|
+
updateScrollMap(routeItemDataState, scrollMapState);
|
|
266
|
+
if (routeItem?.loader) routeItemDataState.setState({
|
|
267
|
+
routeItem,
|
|
268
|
+
location
|
|
269
|
+
});
|
|
249
270
|
const path = getPath(location);
|
|
250
271
|
if (routeItem?.optimistic && loaderMap.has(path)) {
|
|
251
|
-
routeItemDataState.setState({
|
|
252
|
-
routeItem,
|
|
253
|
-
location
|
|
254
|
-
});
|
|
255
272
|
statusState.setState("optimistic");
|
|
256
273
|
const currentLoaderState = loaderMap.get(path)?.state;
|
|
257
274
|
if (currentLoaderState) loaderState.setState(currentLoaderState);
|
|
258
|
-
|
|
259
|
-
const pendingShouldExist = routeItem?.loader && !isCacheItemFresh(path);
|
|
260
|
-
commitNavigation(() => statusState.setState(pendingShouldExist ? "pending" : "active"));
|
|
275
|
+
return;
|
|
261
276
|
}
|
|
277
|
+
if (routeItem?.loader && !isCacheItemFresh(path)) statusState.setState("pending");
|
|
262
278
|
};
|
|
263
279
|
const polling = (routeItem, nextLocation) => {
|
|
264
280
|
if (!routeItem?.pollingInterval) return;
|
|
@@ -314,7 +330,7 @@ var createNavigate = (routerState, revalidateCache) => {
|
|
|
314
330
|
prepareNavigation(nextItem, nextLocation);
|
|
315
331
|
await loader(nextItem, nextLocation, seq);
|
|
316
332
|
if (seq !== navigationSeq) return;
|
|
317
|
-
commitNavigation(() =>
|
|
333
|
+
commitNavigation(() => commitState(nextLocation, nextItem));
|
|
318
334
|
await afterLoad(nextItem, params);
|
|
319
335
|
};
|
|
320
336
|
return navigate;
|
|
@@ -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,13 +552,13 @@ 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
|
|
555
|
+
const getCurrentAction = (actionKey) => {
|
|
540
556
|
const { routeItem, location } = routerState.routeItemDataState.getState();
|
|
541
557
|
if (!routeItem) throw new Error("Route not found");
|
|
542
558
|
if (!routeItem.actions) throw new Error("Route action creator not found");
|
|
543
559
|
const context = routerState.contextState.getState();
|
|
544
560
|
const setContext = routerState.contextState.setState;
|
|
545
|
-
const params =
|
|
561
|
+
const params = getParams(location, routeItem);
|
|
546
562
|
const searchParams = Object.fromEntries(new URLSearchParams(location.search).entries());
|
|
547
563
|
const action = routeItem.actions({
|
|
548
564
|
context,
|
|
@@ -568,7 +584,10 @@ var createRouterInstance = () => {
|
|
|
568
584
|
useStatus: () => useGlobalState(routerState.statusState),
|
|
569
585
|
useContextState: () => useGlobalState(routerState.contextState),
|
|
570
586
|
useLoaderState: () => useGlobalState(routerState.loaderState)[0],
|
|
571
|
-
useParams: () =>
|
|
587
|
+
useParams: () => {
|
|
588
|
+
const { routeItem, location } = routerState.routeItemDataState.getState();
|
|
589
|
+
return getParams(location, routeItem);
|
|
590
|
+
},
|
|
572
591
|
useNavigate: () => {
|
|
573
592
|
const { blockedRouteState } = routerState;
|
|
574
593
|
const { location } = routerState.routeItemDataState.getState();
|
|
@@ -588,7 +607,7 @@ var createRouterInstance = () => {
|
|
|
588
607
|
};
|
|
589
608
|
},
|
|
590
609
|
useAction: (action, options = {}) => {
|
|
591
|
-
const currentAction =
|
|
610
|
+
const currentAction = getCurrentAction(action);
|
|
592
611
|
return async (formData) => {
|
|
593
612
|
try {
|
|
594
613
|
const data = await currentAction(formData);
|
|
@@ -606,6 +625,12 @@ var createRouterInstance = () => {
|
|
|
606
625
|
};
|
|
607
626
|
}
|
|
608
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);
|
|
609
634
|
}
|
|
610
635
|
}
|
|
611
636
|
};
|
|
@@ -640,9 +665,6 @@ var useNavigation = () => {
|
|
|
640
665
|
}, [navigate]);
|
|
641
666
|
};
|
|
642
667
|
//#endregion
|
|
643
|
-
//#region hooks/useLoaderState.ts
|
|
644
|
-
var useLoaderState = router.hooks.useLoaderState;
|
|
645
|
-
//#endregion
|
|
646
668
|
//#region hooks/useApplyCustomAnimation.ts
|
|
647
669
|
var useApplyCustomAnimation = (animationDuration) => {
|
|
648
670
|
useEffect(() => {
|
|
@@ -682,36 +704,11 @@ var useApplyCustomAnimation = (animationDuration) => {
|
|
|
682
704
|
//#endregion
|
|
683
705
|
//#region hooks/usePreserveScroll.ts
|
|
684
706
|
var usePreserveScroll = (restorationBehavior) => {
|
|
685
|
-
const {
|
|
686
|
-
const
|
|
707
|
+
const { useRestoreScroll } = router.hooks;
|
|
708
|
+
const restoreScroll = useRestoreScroll(restorationBehavior);
|
|
687
709
|
useEffect(() => {
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
scrollMap[pathname].forEach(([key, scrollPosition]) => {
|
|
691
|
-
if (key === "__window_top__" || key === "__window_left__") {
|
|
692
|
-
requestAnimationFrame(() => {
|
|
693
|
-
window.scrollTo({
|
|
694
|
-
[key === "__window_top__" ? "top" : "left"]: scrollPosition,
|
|
695
|
-
behavior
|
|
696
|
-
});
|
|
697
|
-
});
|
|
698
|
-
return;
|
|
699
|
-
}
|
|
700
|
-
const element = document.getElementById(key);
|
|
701
|
-
if (!element) return;
|
|
702
|
-
const axis = isVerticalScroll(element) ? "top" : "left";
|
|
703
|
-
requestAnimationFrame(() => {
|
|
704
|
-
element.scrollTo({
|
|
705
|
-
[axis]: scrollPosition,
|
|
706
|
-
behavior
|
|
707
|
-
});
|
|
708
|
-
});
|
|
709
|
-
});
|
|
710
|
-
}, [
|
|
711
|
-
pathname,
|
|
712
|
-
routeItem?.scrollRestoration,
|
|
713
|
-
scrollMap
|
|
714
|
-
]);
|
|
710
|
+
restoreScroll?.();
|
|
711
|
+
}, [restoreScroll]);
|
|
715
712
|
};
|
|
716
713
|
//#endregion
|
|
717
714
|
//#region hooks/useSetRouterConfig.ts
|
|
@@ -781,7 +778,7 @@ var Router = ({ routes, defaultBeforeLoad, defaultAfterLoad, animationDuration,
|
|
|
781
778
|
const { useRouteItemData, useStatus } = router.hooks;
|
|
782
779
|
const [routeItemData] = useRouteItemData();
|
|
783
780
|
const [status] = useStatus();
|
|
784
|
-
const
|
|
781
|
+
const isError = status === "error";
|
|
785
782
|
const isLoading = status === "pending";
|
|
786
783
|
const isOptimistic = status === "optimistic";
|
|
787
784
|
useNavigation();
|
|
@@ -801,10 +798,9 @@ var Router = ({ routes, defaultBeforeLoad, defaultAfterLoad, animationDuration,
|
|
|
801
798
|
useSetInitialContext(initialContext);
|
|
802
799
|
usePreserveScroll(defaultScrollRestorationBehavior);
|
|
803
800
|
const { routeItem, location } = routeItemData;
|
|
804
|
-
|
|
805
|
-
if (!showErrorElement && isLoading) return renderElement(routeItemData?.routeItem?.loaderFallback || defaultLoaderFallback);
|
|
801
|
+
if (isLoading && !isError) return renderElement(routeItemData?.routeItem?.loaderFallback || defaultLoaderFallback);
|
|
806
802
|
if (!routeItem) return null;
|
|
807
|
-
if (
|
|
803
|
+
if (isError) return renderElement(routeItem.errorElement || defaultErrorElement);
|
|
808
804
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
|
|
809
805
|
style: { viewTransitionName: "page" },
|
|
810
806
|
children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorBoundary, { children: renderElement(routeItem.element) }, location.pathname), optimisticSpinner && isOptimistic && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Spinner, {})]
|
|
@@ -923,6 +919,9 @@ var Link = ({ children, to, search = "", state, as = defaultAs, prefetch: linkPr
|
|
|
923
919
|
//#region hooks/useParams.ts
|
|
924
920
|
var useParams = router.hooks.useParams;
|
|
925
921
|
//#endregion
|
|
922
|
+
//#region hooks/useLoaderState.ts
|
|
923
|
+
var useLoaderState = router.hooks.useLoaderState;
|
|
924
|
+
//#endregion
|
|
926
925
|
//#region hooks/useInvalidate.ts
|
|
927
926
|
var useInvalidate = () => router.runtime.invalidate;
|
|
928
927
|
//#endregion
|
|
@@ -1093,7 +1092,7 @@ var createLazyComponent = (importFn, fallback) => {
|
|
|
1093
1092
|
//#region types.ts
|
|
1094
1093
|
var LAZY_MARKER = Symbol("clear-router-lazy");
|
|
1095
1094
|
//#endregion
|
|
1096
|
-
//#region
|
|
1095
|
+
//#region creators/createRouter.ts
|
|
1097
1096
|
var isLazy = (el) => typeof el.element === "object" && el.element !== null && LAZY_MARKER in el.element;
|
|
1098
1097
|
var parseClientRouteItem = (el, parentPattern = "") => {
|
|
1099
1098
|
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
|
@@ -111,7 +111,7 @@ export type LoadingPromise = Promise<{
|
|
|
111
111
|
data: null;
|
|
112
112
|
error: unknown;
|
|
113
113
|
} | undefined>;
|
|
114
|
-
export type Status = 'idle' | 'pending' | 'active' | 'optimistic';
|
|
114
|
+
export type Status = 'idle' | 'pending' | 'active' | 'optimistic' | 'error';
|
|
115
115
|
export type ScrollMap = Record<string, [string, number][]>;
|
|
116
116
|
export type RouterState = {
|
|
117
117
|
routeItemDataState: Store<RouteItemData>;
|
|
@@ -135,21 +135,22 @@ export type RouterType = {
|
|
|
135
135
|
prefetch(location: Location): Promise<void>;
|
|
136
136
|
};
|
|
137
137
|
hooks: {
|
|
138
|
-
useBlockedRoute
|
|
138
|
+
useBlockedRoute(): ReturnType<typeof useGlobalState<{
|
|
139
139
|
from: string;
|
|
140
140
|
to: string;
|
|
141
141
|
}>>;
|
|
142
|
-
useRouteItemData
|
|
143
|
-
useScrollMap
|
|
144
|
-
useStatus
|
|
145
|
-
useContextState
|
|
146
|
-
useLoaderState
|
|
147
|
-
useParams
|
|
148
|
-
useNavigate
|
|
149
|
-
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<{
|
|
150
150
|
data: unknown;
|
|
151
151
|
error: Error | null;
|
|
152
152
|
}>;
|
|
153
|
+
useRestoreScroll(restorationBehavior: ScrollRestorationBehavior): (() => void) | undefined;
|
|
153
154
|
};
|
|
154
155
|
};
|
|
155
156
|
export type InvalidateOptions = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const commitNavigation: (callback: () => void) => void;
|
|
1
|
+
export declare const commitNavigation: (callback: () => void, isCommited?: boolean) => void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Location, RouteItem, RouterState } from '../types';
|
|
2
|
-
export declare const createCommitState: ({
|
|
2
|
+
export declare const createCommitState: ({ statusState, loaderStateRef, loaderState, routeItemDataState }: RouterState) => (nextLocation: Location, routeItem?: RouteItem) => void;
|
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.6",
|
|
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
|