clear-react-router 1.5.4 → 1.5.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/dist/config/routerConfig.d.ts +7 -0
- package/dist/context/RouterProviderContext.d.ts +1 -0
- package/dist/hooks/useHandleNavigation.d.ts +2 -1
- package/dist/hooks/useLoader.d.ts +2 -0
- package/dist/hooks/useSetIsAnimated.d.ts +1 -1
- package/dist/index.js +80 -47
- package/dist/provider/Provider.d.ts +1 -1
- package/package.json +1 -1
- package/dist/store/createStore.d.ts +0 -13
- package/dist/store/isAnimatedStore.d.ts +0 -13
|
@@ -9,8 +9,9 @@ type UseHandleNavigation = {
|
|
|
9
9
|
routeItem?: RouteItem;
|
|
10
10
|
pathname: string;
|
|
11
11
|
}): boolean;
|
|
12
|
+
setIsLoading(arg: boolean): void;
|
|
12
13
|
};
|
|
13
|
-
export declare const useHandleNavigation: ({ routeList, context, revalidateCache, setContext, isCacheItemFresh, }: UseHandleNavigation) => {
|
|
14
|
+
export declare const useHandleNavigation: ({ routeList, context, revalidateCache, setContext, isCacheItemFresh, setIsLoading, }: UseHandleNavigation) => {
|
|
14
15
|
blockerState: BlockerState;
|
|
15
16
|
updateLocation: (nextLocation: Location) => Promise<void>;
|
|
16
17
|
updateBlockedRoute: ({ type, payload }: UpdateBlockedRouteProps) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useSetIsAnimated: (isAnimated
|
|
1
|
+
export declare const useSetIsAnimated: (isAnimated: boolean | undefined, showFallbackIfAnimated: boolean) => void;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Suspense, createContext, lazy, useCallback, useContext, useEffect, useMemo, useRef, useState
|
|
1
|
+
import { Suspense, createContext, lazy, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
2
2
|
//#region \0rolldown/runtime.js
|
|
3
3
|
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
4
4
|
//#endregion
|
|
@@ -45,7 +45,7 @@ var require_react_jsx_runtime_production = /* @__PURE__ */ __commonJSMin(((expor
|
|
|
45
45
|
var import_jsx_runtime = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
46
46
|
module.exports = require_react_jsx_runtime_production();
|
|
47
47
|
})))();
|
|
48
|
-
var Provider = ({ children, setContext, context, updateBlockedRoute, updateLocation, setSearch, prefetchLoader, blockerState, routeItemData, restoreScroll, currentLoaderFallback }) => {
|
|
48
|
+
var Provider = ({ children, setContext, context, updateBlockedRoute, updateLocation, setSearch, prefetchLoader, blockerState, routeItemData, restoreScroll, currentLoaderFallback, isLoading }) => {
|
|
49
49
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ActionsContext.Provider, {
|
|
50
50
|
value: {
|
|
51
51
|
setSearch,
|
|
@@ -61,7 +61,8 @@ var Provider = ({ children, setContext, context, updateBlockedRoute, updateLocat
|
|
|
61
61
|
value: {
|
|
62
62
|
blockerState,
|
|
63
63
|
routeItemData,
|
|
64
|
-
currentLoaderFallback
|
|
64
|
+
currentLoaderFallback,
|
|
65
|
+
isLoading
|
|
65
66
|
},
|
|
66
67
|
children
|
|
67
68
|
})
|
|
@@ -78,41 +79,55 @@ var useLatest = (value) => {
|
|
|
78
79
|
return ref;
|
|
79
80
|
};
|
|
80
81
|
//#endregion
|
|
81
|
-
//#region
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
};
|
|
100
|
-
function use(selector) {
|
|
101
|
-
return useSyncExternalStore(subscribe, () => selector ? selector(get()) : get());
|
|
82
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
|
|
83
|
+
function _typeof(o) {
|
|
84
|
+
"@babel/helpers - typeof";
|
|
85
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
86
|
+
return typeof o;
|
|
87
|
+
} : function(o) {
|
|
88
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
89
|
+
}, _typeof(o);
|
|
90
|
+
}
|
|
91
|
+
//#endregion
|
|
92
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
|
|
93
|
+
function toPrimitive(t, r) {
|
|
94
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
95
|
+
var e = t[Symbol.toPrimitive];
|
|
96
|
+
if (void 0 !== e) {
|
|
97
|
+
var i = e.call(t, r || "default");
|
|
98
|
+
if ("object" != _typeof(i)) return i;
|
|
99
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
102
100
|
}
|
|
103
|
-
return
|
|
104
|
-
|
|
105
|
-
set,
|
|
106
|
-
subscribe,
|
|
107
|
-
use
|
|
108
|
-
};
|
|
109
|
-
};
|
|
101
|
+
return ("string" === r ? String : Number)(t);
|
|
102
|
+
}
|
|
110
103
|
//#endregion
|
|
111
|
-
//#region
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
104
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
|
|
105
|
+
function toPropertyKey(t) {
|
|
106
|
+
var i = toPrimitive(t, "string");
|
|
107
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
108
|
+
}
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
|
|
111
|
+
function _defineProperty(e, r, t) {
|
|
112
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
113
|
+
value: t,
|
|
114
|
+
enumerable: !0,
|
|
115
|
+
configurable: !0,
|
|
116
|
+
writable: !0
|
|
117
|
+
}) : e[r] = t, e;
|
|
118
|
+
}
|
|
119
|
+
//#endregion
|
|
120
|
+
//#region config/routerConfig.ts
|
|
121
|
+
var RouterConfig = class {
|
|
122
|
+
constructor() {
|
|
123
|
+
_defineProperty(this, "isAnimated", false);
|
|
124
|
+
_defineProperty(this, "showFallbackIfAnimated", false);
|
|
125
|
+
}
|
|
126
|
+
configure(config) {
|
|
127
|
+
Object.assign(this, config);
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
var routerConfig = new RouterConfig();
|
|
116
131
|
//#endregion
|
|
117
132
|
//#region utils/createLazyComponent.tsx
|
|
118
133
|
var createLazyComponent = (importFn, fallback) => {
|
|
@@ -167,8 +182,8 @@ var comparePaths = (el, pathname) => {
|
|
|
167
182
|
//#endregion
|
|
168
183
|
//#region hooks/useHandleNavigation.ts
|
|
169
184
|
var ALL_LOCATIONS = "*";
|
|
170
|
-
var useHandleNavigation = ({ routeList, context, revalidateCache, setContext, isCacheItemFresh }) => {
|
|
171
|
-
const isAnimated
|
|
185
|
+
var useHandleNavigation = ({ routeList, context, revalidateCache, setContext, isCacheItemFresh, setIsLoading }) => {
|
|
186
|
+
const { isAnimated, showFallbackIfAnimated: showFallback } = routerConfig;
|
|
172
187
|
const [blockedRoute, setBlockedRoute] = useState({
|
|
173
188
|
from: "",
|
|
174
189
|
to: ""
|
|
@@ -206,6 +221,7 @@ var useHandleNavigation = ({ routeList, context, revalidateCache, setContext, is
|
|
|
206
221
|
routeItem,
|
|
207
222
|
loaderState: loaderState.current
|
|
208
223
|
});
|
|
224
|
+
setIsLoading(false);
|
|
209
225
|
setCurrentLoaderFallback(void 0);
|
|
210
226
|
prevPathname.current = nextLocation.pathname;
|
|
211
227
|
const fullPath = nextLocation.search ? `${nextLocation.pathname}${nextLocation.search}` : nextLocation.pathname;
|
|
@@ -263,7 +279,7 @@ var useHandleNavigation = ({ routeList, context, revalidateCache, setContext, is
|
|
|
263
279
|
setCurrentLoaderFallback(isCacheItemFresh({
|
|
264
280
|
routeItem: nextItem,
|
|
265
281
|
pathname: nextLocation.pathname
|
|
266
|
-
}) ? void 0 : nextItem?.loaderFallback);
|
|
282
|
+
}) || isAnimated && !showFallback ? void 0 : nextItem?.loaderFallback);
|
|
267
283
|
await revalidateCache({
|
|
268
284
|
routeItem: nextItem,
|
|
269
285
|
loaderState,
|
|
@@ -282,7 +298,9 @@ var useHandleNavigation = ({ routeList, context, revalidateCache, setContext, is
|
|
|
282
298
|
routeList,
|
|
283
299
|
transitionedNavigation,
|
|
284
300
|
setContext,
|
|
285
|
-
isCacheItemFresh
|
|
301
|
+
isCacheItemFresh,
|
|
302
|
+
isAnimated,
|
|
303
|
+
showFallback
|
|
286
304
|
]);
|
|
287
305
|
const setNextLocationRef = useLatest(navigationHandler);
|
|
288
306
|
const updateBlockedRoute = useCallback(({ type, payload = "" }) => setBlockedRoute((prevState) => {
|
|
@@ -345,6 +363,7 @@ var useHandleNavigation = ({ routeList, context, revalidateCache, setContext, is
|
|
|
345
363
|
//#endregion
|
|
346
364
|
//#region hooks/useLoader.ts
|
|
347
365
|
var useLoader = ({ routeList, context, setContext }) => {
|
|
366
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
348
367
|
const cacheTimestampsRef = useRef({});
|
|
349
368
|
const loaderCacheRef = useRef({});
|
|
350
369
|
const isCacheItemFresh = useCallback(({ routeItem, pathname }) => {
|
|
@@ -367,6 +386,7 @@ var useLoader = ({ routeList, context, setContext }) => {
|
|
|
367
386
|
if (loaderState) loaderState.current = loaderCacheRef.current[pathname];
|
|
368
387
|
return;
|
|
369
388
|
}
|
|
389
|
+
if (loaderState) setIsLoading(true);
|
|
370
390
|
try {
|
|
371
391
|
const params = getParamsObject({
|
|
372
392
|
params: routeItem.params,
|
|
@@ -412,14 +432,16 @@ var useLoader = ({ routeList, context, setContext }) => {
|
|
|
412
432
|
});
|
|
413
433
|
}, [revalidateCache, routeList]),
|
|
414
434
|
revalidateCache,
|
|
415
|
-
isCacheItemFresh
|
|
435
|
+
isCacheItemFresh,
|
|
436
|
+
isLoading,
|
|
437
|
+
setIsLoading
|
|
416
438
|
};
|
|
417
439
|
};
|
|
418
440
|
//#endregion
|
|
419
441
|
//#region components/RouterProvider.tsx
|
|
420
442
|
var RouterProvider = ({ children, routeList, context: initialContext = {} }) => {
|
|
421
443
|
const [context, setContext] = useState(initialContext);
|
|
422
|
-
const { prefetchLoader, revalidateCache, isCacheItemFresh } = useLoader({
|
|
444
|
+
const { prefetchLoader, revalidateCache, isCacheItemFresh, setIsLoading, isLoading } = useLoader({
|
|
423
445
|
routeList,
|
|
424
446
|
context,
|
|
425
447
|
setContext
|
|
@@ -429,7 +451,8 @@ var RouterProvider = ({ children, routeList, context: initialContext = {} }) =>
|
|
|
429
451
|
context,
|
|
430
452
|
setContext,
|
|
431
453
|
revalidateCache,
|
|
432
|
-
isCacheItemFresh
|
|
454
|
+
isCacheItemFresh,
|
|
455
|
+
setIsLoading
|
|
433
456
|
});
|
|
434
457
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Provider, {
|
|
435
458
|
...useMemo(() => ({
|
|
@@ -442,7 +465,8 @@ var RouterProvider = ({ children, routeList, context: initialContext = {} }) =>
|
|
|
442
465
|
setContext,
|
|
443
466
|
routeItemData,
|
|
444
467
|
restoreScroll,
|
|
445
|
-
currentLoaderFallback
|
|
468
|
+
currentLoaderFallback,
|
|
469
|
+
isLoading
|
|
446
470
|
}), [
|
|
447
471
|
blockerState,
|
|
448
472
|
context,
|
|
@@ -452,7 +476,8 @@ var RouterProvider = ({ children, routeList, context: initialContext = {} }) =>
|
|
|
452
476
|
updateBlockedRoute,
|
|
453
477
|
updateLocation,
|
|
454
478
|
currentLoaderFallback,
|
|
455
|
-
restoreScroll
|
|
479
|
+
restoreScroll,
|
|
480
|
+
isLoading
|
|
456
481
|
]),
|
|
457
482
|
children
|
|
458
483
|
});
|
|
@@ -518,6 +543,14 @@ var usePreserveScroll = (preserveScroll) => {
|
|
|
518
543
|
]);
|
|
519
544
|
};
|
|
520
545
|
//#endregion
|
|
546
|
+
//#region hooks/useSetIsAnimated.ts
|
|
547
|
+
var useSetIsAnimated = (isAnimated = false, showFallbackIfAnimated) => {
|
|
548
|
+
useEffect(() => routerConfig.configure({
|
|
549
|
+
isAnimated,
|
|
550
|
+
showFallbackIfAnimated
|
|
551
|
+
}), [isAnimated]);
|
|
552
|
+
};
|
|
553
|
+
//#endregion
|
|
521
554
|
//#region components/Spinner.tsx
|
|
522
555
|
var Spinner = () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "cr-spinner" });
|
|
523
556
|
//#endregion
|
|
@@ -529,10 +562,10 @@ var renderElement = (Component) => {
|
|
|
529
562
|
//#endregion
|
|
530
563
|
//#region components/Router.tsx
|
|
531
564
|
var Router = ({ isAnimated, animationDuration, spinner = true, preserveScroll = true, showFallbackIfAnimated = false }) => {
|
|
532
|
-
const { routeItemData: { routeItem, loaderState }, currentLoaderFallback } = useNavigationState();
|
|
565
|
+
const { routeItemData: { routeItem, loaderState }, currentLoaderFallback, isLoading } = useNavigationState();
|
|
533
566
|
usePreserveScroll(preserveScroll);
|
|
534
567
|
useApplyCustomAnimation(animationDuration);
|
|
535
|
-
|
|
568
|
+
useSetIsAnimated(isAnimated, showFallbackIfAnimated);
|
|
536
569
|
const showErrorElement = !isLoading && Boolean(loaderState.loaderError || loaderState.beforeLoadError);
|
|
537
570
|
const showSpinner = spinner && isAnimated && isLoading;
|
|
538
571
|
const loadingContent = !showErrorElement && isLoading;
|
|
@@ -3,5 +3,5 @@ import { type ActionsContextValue, type DataContextValue, type NavigationContext
|
|
|
3
3
|
type ProviderProps = NavigationContextValue & ActionsContextValue & DataContextValue & {
|
|
4
4
|
children: ReactNode;
|
|
5
5
|
};
|
|
6
|
-
export declare const Provider: ({ children, setContext, context, updateBlockedRoute, updateLocation, setSearch, prefetchLoader, blockerState, routeItemData, restoreScroll, currentLoaderFallback, }: ProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
export declare const Provider: ({ children, setContext, context, updateBlockedRoute, updateLocation, setSearch, prefetchLoader, blockerState, routeItemData, restoreScroll, currentLoaderFallback, isLoading, }: ProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
7
|
export {};
|
package/package.json
CHANGED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
type SetStateAction<T> = ((prevState: T) => Partial<T>) | Partial<T>;
|
|
2
|
-
type Listener<T> = (state: T, prevState: T) => void;
|
|
3
|
-
type Store<T> = {
|
|
4
|
-
get: () => T;
|
|
5
|
-
set: (action: SetStateAction<T>) => void;
|
|
6
|
-
subscribe: (listener: Listener<T>) => () => void;
|
|
7
|
-
use(): T;
|
|
8
|
-
use<S>(selector: (state: T) => S): S;
|
|
9
|
-
use<S>(selector?: (state: T) => S): T | S;
|
|
10
|
-
};
|
|
11
|
-
type StoreCreator<T> = (set: (action: SetStateAction<T>) => void, get: () => T) => T;
|
|
12
|
-
export declare const createStore: <T>(storeCreator: StoreCreator<T>) => Store<T>;
|
|
13
|
-
export {};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
type IsAnimatedStore = {
|
|
2
|
-
isAnimated: boolean;
|
|
3
|
-
setIsAnimated(arg: boolean): void;
|
|
4
|
-
};
|
|
5
|
-
export declare const isAnimatedStore: {
|
|
6
|
-
get: () => IsAnimatedStore;
|
|
7
|
-
set: (action: Partial<IsAnimatedStore> | ((prevState: IsAnimatedStore) => Partial<IsAnimatedStore>)) => void;
|
|
8
|
-
subscribe: (listener: (state: IsAnimatedStore, prevState: IsAnimatedStore) => void) => () => void;
|
|
9
|
-
use(): IsAnimatedStore;
|
|
10
|
-
use<S>(selector: (state: IsAnimatedStore) => S): S;
|
|
11
|
-
use<S>(selector?: ((state: IsAnimatedStore) => S) | undefined): IsAnimatedStore | S;
|
|
12
|
-
};
|
|
13
|
-
export {};
|