clear-react-router 1.5.3 → 1.5.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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useSetIsAnimated: (isAnimated?: boolean) => void;
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Suspense, createContext, lazy, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
1
|
+
import { Suspense, createContext, lazy, useCallback, useContext, useEffect, useMemo, useRef, useState, useSyncExternalStore } 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,6 +78,41 @@ 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
|
+
subscribers.forEach((listener) => listener(store, prevState));
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
store = storeCreator(set, get);
|
|
95
|
+
const subscribe = (listener) => {
|
|
96
|
+
subscribers.add(listener);
|
|
97
|
+
return () => subscribers.delete(listener);
|
|
98
|
+
};
|
|
99
|
+
function use(selector) {
|
|
100
|
+
return useSyncExternalStore(subscribe, () => selector ? selector(get()) : get());
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
get,
|
|
104
|
+
set,
|
|
105
|
+
subscribe,
|
|
106
|
+
use
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region store/isAnimatedStore.ts
|
|
111
|
+
var isAnimatedStore = createStore((set) => ({
|
|
112
|
+
isAnimated: false,
|
|
113
|
+
setIsAnimated: (isAnimated) => set({ isAnimated })
|
|
114
|
+
}));
|
|
115
|
+
//#endregion
|
|
81
116
|
//#region utils/createLazyComponent.tsx
|
|
82
117
|
var createLazyComponent = (importFn, fallback) => {
|
|
83
118
|
const LazyComp = lazy(() => importFn().then((module) => ({ default: module.default || module })));
|
|
@@ -132,6 +167,7 @@ var comparePaths = (el, pathname) => {
|
|
|
132
167
|
//#region hooks/useHandleNavigation.ts
|
|
133
168
|
var ALL_LOCATIONS = "*";
|
|
134
169
|
var useHandleNavigation = ({ routeList, context, revalidateCache, setContext, isCacheItemFresh }) => {
|
|
170
|
+
const isAnimated = isAnimatedStore.use((state) => state.isAnimated);
|
|
135
171
|
const [blockedRoute, setBlockedRoute] = useState({
|
|
136
172
|
from: "",
|
|
137
173
|
to: ""
|
|
@@ -184,12 +220,16 @@ var useHandleNavigation = ({ routeList, context, revalidateCache, setContext, is
|
|
|
184
220
|
[prevPathname.current]: scrollPosition
|
|
185
221
|
};
|
|
186
222
|
});
|
|
223
|
+
if (!isAnimated) {
|
|
224
|
+
navigation(nextLocation, routeItem);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
187
227
|
try {
|
|
188
228
|
document.startViewTransition(() => navigation(nextLocation, routeItem));
|
|
189
229
|
} catch {
|
|
190
230
|
navigation(nextLocation, routeItem);
|
|
191
231
|
}
|
|
192
|
-
}, [navigation]);
|
|
232
|
+
}, [navigation, isAnimated]);
|
|
193
233
|
const navigationHandler = useCallback(async (nextLocation) => {
|
|
194
234
|
navigationSeq.current = navigationSeq.current + 1;
|
|
195
235
|
const seq = navigationSeq.current;
|
|
@@ -0,0 +1,13 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,13 @@
|
|
|
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 {};
|