clear-react-router 1.5.2 → 1.5.3
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/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
|
|
@@ -78,42 +78,6 @@ var useLatest = (value) => {
|
|
|
78
78
|
return ref;
|
|
79
79
|
};
|
|
80
80
|
//#endregion
|
|
81
|
-
//#region store/createStore.ts
|
|
82
|
-
var createStore = (storeCreator) => {
|
|
83
|
-
let store;
|
|
84
|
-
const subscribers = /* @__PURE__ */ new Set();
|
|
85
|
-
const get = () => store;
|
|
86
|
-
const set = (action) => {
|
|
87
|
-
const nextState = typeof action === "function" ? action(store) : action;
|
|
88
|
-
if (!Object.is(store, nextState)) {
|
|
89
|
-
const prevState = store;
|
|
90
|
-
store = typeof nextState !== "object" || nextState === null ? nextState : Object.assign({}, store, nextState);
|
|
91
|
-
console.log({ store });
|
|
92
|
-
subscribers.forEach((listener) => listener(store, prevState));
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
store = storeCreator(set, get);
|
|
96
|
-
const subscribe = (listener) => {
|
|
97
|
-
subscribers.add(listener);
|
|
98
|
-
return () => subscribers.delete(listener);
|
|
99
|
-
};
|
|
100
|
-
function use(selector) {
|
|
101
|
-
return useSyncExternalStore(subscribe, () => selector ? selector(get()) : get());
|
|
102
|
-
}
|
|
103
|
-
return {
|
|
104
|
-
get,
|
|
105
|
-
set,
|
|
106
|
-
subscribe,
|
|
107
|
-
use
|
|
108
|
-
};
|
|
109
|
-
};
|
|
110
|
-
//#endregion
|
|
111
|
-
//#region store/isAnimatedStore.ts
|
|
112
|
-
var isAnimatedStore = createStore((set) => ({
|
|
113
|
-
isAnimated: false,
|
|
114
|
-
setIsAnimated: (isAnimated) => set({ isAnimated })
|
|
115
|
-
}));
|
|
116
|
-
//#endregion
|
|
117
81
|
//#region utils/createLazyComponent.tsx
|
|
118
82
|
var createLazyComponent = (importFn, fallback) => {
|
|
119
83
|
const LazyComp = lazy(() => importFn().then((module) => ({ default: module.default || module })));
|
|
@@ -168,7 +132,6 @@ var comparePaths = (el, pathname) => {
|
|
|
168
132
|
//#region hooks/useHandleNavigation.ts
|
|
169
133
|
var ALL_LOCATIONS = "*";
|
|
170
134
|
var useHandleNavigation = ({ routeList, context, revalidateCache, setContext, isCacheItemFresh }) => {
|
|
171
|
-
const isAnimated = isAnimatedStore.use((state) => state.isAnimated);
|
|
172
135
|
const [blockedRoute, setBlockedRoute] = useState({
|
|
173
136
|
from: "",
|
|
174
137
|
to: ""
|
|
@@ -221,10 +184,6 @@ var useHandleNavigation = ({ routeList, context, revalidateCache, setContext, is
|
|
|
221
184
|
[prevPathname.current]: scrollPosition
|
|
222
185
|
};
|
|
223
186
|
});
|
|
224
|
-
if (!isAnimated) {
|
|
225
|
-
navigation(nextLocation, routeItem);
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
187
|
try {
|
|
229
188
|
document.startViewTransition(() => navigation(nextLocation, routeItem));
|
|
230
189
|
} catch {
|
|
@@ -527,18 +486,11 @@ var renderElement = (Component) => {
|
|
|
527
486
|
return typeof Component === "function" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, {}) : Component;
|
|
528
487
|
};
|
|
529
488
|
//#endregion
|
|
530
|
-
//#region hooks/useSetIsAnimated.ts
|
|
531
|
-
var useSetIsAnimated = (isAnimated) => {
|
|
532
|
-
const setIsAnimated = isAnimatedStore.use((state) => state.setIsAnimated);
|
|
533
|
-
useEffect(() => setIsAnimated(!!isAnimated), [isAnimated]);
|
|
534
|
-
};
|
|
535
|
-
//#endregion
|
|
536
489
|
//#region components/Router.tsx
|
|
537
490
|
var Router = ({ isAnimated, animationDuration, spinner = true, preserveScroll = true, showFallbackIfAnimated = false }) => {
|
|
538
491
|
const { routeItemData: { routeItem, loaderState }, currentLoaderFallback } = useNavigationState();
|
|
539
492
|
usePreserveScroll(preserveScroll);
|
|
540
493
|
useApplyCustomAnimation(animationDuration);
|
|
541
|
-
useSetIsAnimated(isAnimated);
|
|
542
494
|
const isLoading = Boolean(currentLoaderFallback);
|
|
543
495
|
const showErrorElement = !isLoading && Boolean(loaderState.loaderError || loaderState.beforeLoadError);
|
|
544
496
|
const showSpinner = spinner && isAnimated && isLoading;
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const useSetIsAnimated: (isAnimated?: boolean) => void;
|
|
@@ -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 {};
|