clear-react-router 1.7.9 → 1.8.0

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 CHANGED
@@ -456,10 +456,11 @@ await invalidate('/post/[id]/comment/[id]');
456
456
 
457
457
  #### Including child routes
458
458
 
459
- To revalidate a single route together with its cached child routes, pass the `withChildren` option:
459
+ To revalidate routes together with their cached child routes, pass the `withChildren` option:
460
460
 
461
461
  ```tsx
462
- await invalidate('/posts', { withChildren: true }); // a route, not a route list
462
+ await invalidate('/posts', { withChildren: true });
463
+ await invalidate(['/posts', '/users'], { withChildren: true });
463
464
  ```
464
465
 
465
466
  This will recursively revalidate cached routes inside the route tree.
package/dist/cell.d.ts CHANGED
@@ -1,10 +1,9 @@
1
- declare class Cell<T> {
1
+ export declare class Cell<T> {
2
2
  private _value;
3
3
  constructor(_value: T);
4
4
  get value(): T;
5
5
  set(action: T | ((prev: T) => T)): void;
6
6
  }
7
- export declare const loaderStateRef: Cell<import("./types/global").LoaderState>;
7
+ export declare const loaderStateRef: Cell<import("./types").LoaderState>;
8
8
  export declare const prevPathnameRef: Cell<string>;
9
9
  export declare const timestampMap: Map<string, number>;
10
- export {};
@@ -1,5 +1,5 @@
1
1
  import { type ReactElement, type MouseEvent, type CSSProperties } from 'react';
2
- import { RouterProps } from '../types/global';
2
+ import { RouterProps } from '../types';
3
3
  type LinkProps = {
4
4
  to: string;
5
5
  children: ReactElement<{
@@ -1,2 +1,2 @@
1
- import { RouterProps } from '../types/global';
1
+ import { RouterProps } from '../types';
2
2
  export declare const Router: ({ routes, beforeLoad, afterLoad, animationDuration, isAnimated, spinner, preserveScroll, showFallbackOnAnimation, prefetch, hoverPrefetchDelay, errorBoundary: ErrorBoundary, context: initialContext, defaultLoaderFallback, defaultErrorElement, }: RouterProps) => import("react/jsx-runtime").JSX.Element | null;
@@ -1,4 +1,4 @@
1
- import { ClientRouteItem, RouterProps } from '../types/global';
1
+ import { ClientRouteItem, RouterProps } from '../types';
2
2
  declare class RouterConfig {
3
3
  routes: RouterProps['routes'];
4
4
  prefetch: RouterProps['prefetch'];
@@ -1,3 +1,3 @@
1
- import type { LoaderState } from './types/global.ts';
1
+ import type { LoaderState } from './types';
2
2
  export declare const emptyLoaderState: LoaderState;
3
3
  export declare const STANDARD_PREFETCH_DELAY = 150;
@@ -1,11 +1,10 @@
1
1
  type SetStateAction<T> = ((prevState: T) => T) | T;
2
2
  type Listener<T> = (state: T, prevState: T) => void;
3
- type Store<T> = {
3
+ export type Store<T> = {
4
4
  subscribe: (listener: Listener<T>) => () => void;
5
5
  getState: () => T;
6
6
  setState: (action: SetStateAction<T>) => void;
7
7
  };
8
8
  export declare const create: <T>(initialState: T) => Store<T>;
9
9
  export declare const useGlobalState: <T>({ subscribe, getState, setState }: Store<T>) => readonly [T, (action: SetStateAction<T>) => void];
10
- export declare const createState: <T>(initialState: T) => () => readonly [T, (action: SetStateAction<T>) => void];
11
10
  export {};
@@ -1,4 +1,4 @@
1
- import { BlockerState } from '../types/global';
1
+ import { BlockerState } from '../types';
2
2
  type UseBlockerReturnValue = {
3
3
  state: BlockerState;
4
4
  process(): void;
@@ -1,4 +1,4 @@
1
1
  export declare const useGetAction: (actionKey: string) => {
2
2
  currentAction: (arg: FormData) => Promise<unknown> | Promise<void> | void | unknown;
3
- invalidate: typeof import("../runtime/invalidate").invalidate;
3
+ invalidate: (pathList?: string | string[], options?: import("../types").InvalidateOptions) => Promise<void>;
4
4
  };
@@ -1,2 +1 @@
1
- import { invalidate } from '../runtime/invalidate';
2
- export declare const useInvalidate: () => typeof invalidate;
1
+ export declare const useInvalidate: () => (pathList?: string | string[], options?: import("../types").InvalidateOptions) => Promise<void>;
@@ -1,2 +1,2 @@
1
- import { LoaderState } from '../types/global';
1
+ import { LoaderState } from '../types';
2
2
  export declare const useLoaderState: <T>() => LoaderState<T>;
@@ -1,2 +1,2 @@
1
- import type { Location } from '../types/global';
1
+ import type { Location } from '../types';
2
2
  export declare const useNavigate: () => (arg: Location | string | -1) => Promise<void>;
@@ -1,2 +1,2 @@
1
- import { AdapterType } from '../types/global';
2
- export declare function useQueryParam<T>(field: string, adapter: AdapterType<T>, defaultValue?: T): [T, (arg: T | null) => void];
1
+ import { Adapter } from '../types';
2
+ export declare function useQueryParam<T>(field: string, adapter: Adapter<T>, defaultValue?: T): [T, (arg: T | null) => void];
@@ -1 +1,2 @@
1
- export declare const useSetInitialContext: (initialContext?: Record<string, unknown>) => void;
1
+ import { RouterProps } from '../types';
2
+ export declare const useSetInitialContext: (initialContext?: RouterProps["context"]) => void;
@@ -1,2 +1,2 @@
1
- import { RouterProps } from '../types/global';
1
+ import { RouterProps } from '../types';
2
2
  export declare const useSetRouterConfig: (routerProps: RouterProps) => void;
package/dist/index.d.ts CHANGED
@@ -14,4 +14,4 @@ export { useSearchParams } from './hooks/useSearchParams';
14
14
  export { useFormContext } from './hooks/useFormContext';
15
15
  export { adapter } from './utils/adapter';
16
16
  export { createRouter } from './utils/utils';
17
- export type { RouteItem, BlockerState, Location, AdapterType, RouterProps } from './types/global';
17
+ export type { RouteItem, BlockerState, Location, Adapter, RouterProps } from './types';
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import { Suspense, createContext, lazy, useCallback, useContext, useEffect, useM
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
5
- //#region state/createState.ts
5
+ //#region create.ts
6
6
  var create = (initialState) => {
7
7
  let state = initialState;
8
8
  const subscribers = /* @__PURE__ */ new Set();
@@ -28,35 +28,25 @@ var create = (initialState) => {
28
28
  var useGlobalState = ({ subscribe, getState, setState }) => {
29
29
  return [useSyncExternalStore(subscribe, getState), setState];
30
30
  };
31
- var createState = (initialState) => {
32
- const store = create(initialState);
33
- return () => useGlobalState(store);
31
+ //#endregion
32
+ //#region utils/commitState.ts
33
+ var createCommitState = ({ isLoadingState, routeItemDataState, loaderFallbackState, currentLoaderState, prevPathnameRef, loaderStateRef }) => (nextLocation, routeItem) => {
34
+ routeItemDataState.setState({
35
+ routeItem,
36
+ location: nextLocation
37
+ });
38
+ currentLoaderState.setState(loaderStateRef.value);
39
+ isLoadingState.setState(false);
40
+ loaderFallbackState.setState(void 0);
41
+ prevPathnameRef.set(nextLocation.pathname);
42
+ const fullPath = nextLocation.search ? `${nextLocation.pathname}${nextLocation.search}` : nextLocation.pathname;
43
+ if (fullPath === window.location.pathname + window.location.search) return;
44
+ history.pushState(null, "", fullPath);
34
45
  };
35
46
  //#endregion
36
47
  //#region constants.ts
37
48
  var emptyLoaderState = {};
38
49
  //#endregion
39
- //#region state/state.ts
40
- var isLoadingState = create(false);
41
- var useIsLoading = () => useGlobalState(isLoadingState);
42
- var useBlockedRoute = createState({
43
- from: "",
44
- to: ""
45
- });
46
- var loaderFallbackState = create(void 0);
47
- var useLoaderFallback = () => useGlobalState(loaderFallbackState);
48
- var routeItemDataState = create({
49
- routeItem: void 0,
50
- location: {}
51
- });
52
- var useRouteItemData = () => useGlobalState(routeItemDataState);
53
- var currentLoaderState = create(emptyLoaderState);
54
- var useCurrentLoaderState = () => useGlobalState(currentLoaderState);
55
- var scrollMapState = create({});
56
- var useScrollMap = () => useGlobalState(scrollMapState);
57
- var contextState = create({});
58
- var useContextState = () => useGlobalState(contextState);
59
- //#endregion
60
50
  //#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
61
51
  function _typeof(o) {
62
52
  "@babel/helpers - typeof";
@@ -95,25 +85,39 @@ function _defineProperty(e, r, t) {
95
85
  }) : e[r] = t, e;
96
86
  }
97
87
  //#endregion
98
- //#region cell.ts
99
- var Cell = class {
100
- constructor(_value) {
101
- _defineProperty(this, "_value", void 0);
102
- this._value = _value;
88
+ //#region config/routerConfig.ts
89
+ var RouterConfig = class {
90
+ constructor() {
91
+ _defineProperty(this, "routes", []);
92
+ _defineProperty(this, "prefetch", "hover");
93
+ _defineProperty(this, "isAnimated", false);
94
+ _defineProperty(this, "showFallbackOnAnimation", false);
95
+ _defineProperty(this, "hoverPrefetchDelay", 150);
96
+ _defineProperty(this, "beforeLoad", void 0);
97
+ _defineProperty(this, "afterLoad", void 0);
103
98
  }
104
- get value() {
105
- return this._value;
99
+ configure(config) {
100
+ Object.assign(this, config);
106
101
  }
107
- set(action) {
108
- this._value = typeof action === "function" ? action(this._value) : action;
102
+ };
103
+ var routerConfig = new RouterConfig();
104
+ //#endregion
105
+ //#region utils/commitNavigation.ts
106
+ var createCommitNavigation = (navigationExecutor, prevPathnameRef) => (nextLocation, routeItem) => {
107
+ const { isAnimated } = routerConfig;
108
+ if (!isAnimated || !prevPathnameRef.value) {
109
+ navigationExecutor(nextLocation, routeItem);
110
+ return;
111
+ }
112
+ try {
113
+ document.startViewTransition(() => navigationExecutor(nextLocation, routeItem));
114
+ } catch {
115
+ navigationExecutor(nextLocation, routeItem);
109
116
  }
110
117
  };
111
- var loaderStateRef = new Cell(emptyLoaderState);
112
- var prevPathnameRef = new Cell("");
113
- var timestampMap = /* @__PURE__ */ new Map();
114
118
  //#endregion
115
119
  //#region utils/isCacheItemFresh.ts
116
- var isCacheItemFresh = ({ routeItem, pathname }) => {
120
+ var createIsCacheItemFresh = (timestampMap) => ({ routeItem, pathname }) => {
117
121
  if (!routeItem) return true;
118
122
  const currentCacheTimestamp = timestampMap.get(pathname);
119
123
  if (!currentCacheTimestamp) return false;
@@ -216,20 +220,177 @@ var comparePaths = (el, pathname) => {
216
220
  const splitPathname = pathname.split("/").filter(Boolean);
217
221
  return splitElementPath.every((item, index) => item === splitPathname[2 * index]) && splitPathname.length === splitElementPath.length + paramsLength;
218
222
  };
223
+ var findRoute = (pathname, includeAll) => {
224
+ if (includeAll) return routerConfig.routes.find((el) => el.path === "/*" || comparePaths(el, pathname));
225
+ return routerConfig.routes.find((el) => comparePaths(el, pathname));
226
+ };
219
227
  //#endregion
220
- //#region utils/getContext.ts
221
- var getContext = () => {
222
- return {
228
+ //#region runtime/navigate.ts
229
+ var navigationSeq = 0;
230
+ var createNavigate = (routerSta, revalidateCache) => {
231
+ const { loaderStateRef, scrollMapState, prevPathnameRef, loaderFallbackState, isLoadingState, contextState, timestampMap } = routerSta;
232
+ const commitNavigation = createCommitNavigation(createCommitState(routerSta), prevPathnameRef);
233
+ const isCacheItemFresh = createIsCacheItemFresh(timestampMap);
234
+ const getContext = () => ({
223
235
  context: contextState.getState(),
224
236
  setContext: contextState.setState
237
+ });
238
+ const routeResolve = (location) => {
239
+ loaderStateRef.set(emptyLoaderState);
240
+ const nextItem = findRoute(location.pathname, true);
241
+ return {
242
+ nextItem,
243
+ params: getParamsObject({
244
+ params: nextItem?.params,
245
+ pathname: location.pathname
246
+ })
247
+ };
225
248
  };
249
+ const beforeLoad = async (routeItem, params) => {
250
+ const { beforeLoad } = routerConfig;
251
+ const runBeforeLoad = async (loaderFn) => {
252
+ const redirect = async (redirected) => await navigate(typeof redirected === "string" ? { pathname: redirected } : redirected);
253
+ try {
254
+ await loaderFn({
255
+ ...getContext(),
256
+ redirect,
257
+ params
258
+ });
259
+ loaderStateRef.set((prev) => ({
260
+ ...prev,
261
+ beforeLoadError: null
262
+ }));
263
+ } catch (error) {
264
+ loaderStateRef.set((prev) => ({
265
+ ...prev,
266
+ beforeLoadError: error
267
+ }));
268
+ }
269
+ };
270
+ if (beforeLoad) await runBeforeLoad(beforeLoad);
271
+ if (routeItem?.beforeLoad) await runBeforeLoad(routeItem?.beforeLoad);
272
+ };
273
+ const prepareNavigation = (routeItem, location) => {
274
+ const { isAnimated, showFallbackOnAnimation: showFallback } = routerConfig;
275
+ scrollMapState.setState((prevState) => {
276
+ const scrollPosition = document.scrollingElement?.scrollTop ?? 0;
277
+ if (!scrollPosition || prevState[prevPathnameRef.value] === scrollPosition) return prevState;
278
+ return {
279
+ ...prevState,
280
+ [prevPathnameRef.value]: scrollPosition
281
+ };
282
+ });
283
+ loaderFallbackState.setState(isCacheItemFresh({
284
+ routeItem,
285
+ pathname: location.pathname
286
+ }) || isAnimated && !showFallback ? void 0 : routeItem?.loaderFallback);
287
+ };
288
+ const loader = async (routeItem, location) => {
289
+ if (!routeItem?.loader) return;
290
+ isLoadingState.setState(true);
291
+ await revalidateCache({
292
+ routeItem,
293
+ pathname: location.pathname
294
+ });
295
+ };
296
+ const afterLoad = async (routeItem, params) => {
297
+ const { afterLoad } = routerConfig;
298
+ if (routeItem?.afterLoad) await routeItem.afterLoad({
299
+ ...getContext(),
300
+ params
301
+ });
302
+ if (afterLoad) await afterLoad({
303
+ ...getContext(),
304
+ params
305
+ });
306
+ };
307
+ const navigate = async (nextLocation) => {
308
+ navigationSeq = navigationSeq + 1;
309
+ const seq = navigationSeq;
310
+ const { nextItem, params } = routeResolve(nextLocation);
311
+ await beforeLoad(nextItem, params);
312
+ if (seq !== navigationSeq) return;
313
+ prepareNavigation(nextItem, nextLocation);
314
+ await loader(nextItem, nextLocation);
315
+ if (seq !== navigationSeq) return;
316
+ commitNavigation(nextLocation, nextItem);
317
+ await afterLoad(nextItem, params);
318
+ };
319
+ return navigate;
320
+ };
321
+ //#endregion
322
+ //#region runtime/invalidate.ts
323
+ var redirect = () => Promise.resolve();
324
+ var createInvalidate = ({ routeItemDataState, loaderStateRef, timestampMap, currentLoaderState, contextState }, revalidateCache) => {
325
+ const invalidatePath = async (routeItem, pathname) => {
326
+ const routePathname = routeItemDataState.getState().location.pathname;
327
+ timestampMap.delete(pathname);
328
+ const params = getParamsObject({
329
+ params: routeItem?.params,
330
+ pathname
331
+ });
332
+ try {
333
+ if (routeItem?.beforeLoad) {
334
+ const context = contextState.getState();
335
+ const setContext = contextState.setState;
336
+ await routeItem.beforeLoad({
337
+ context,
338
+ redirect,
339
+ params,
340
+ setContext
341
+ });
342
+ }
343
+ loaderStateRef.set((prev) => ({
344
+ ...prev,
345
+ beforeLoadError: null
346
+ }));
347
+ } catch (error) {
348
+ loaderStateRef.set((prev) => ({
349
+ ...prev,
350
+ beforeLoadError: error
351
+ }));
352
+ }
353
+ await revalidateCache({
354
+ routeItem,
355
+ pathname
356
+ });
357
+ if (pathname === routePathname) currentLoaderState.setState(loaderStateRef.value);
358
+ };
359
+ const invalidateItem = async (pathname, withChildren) => {
360
+ const routeItem = findRoute(pathname);
361
+ if (!routeItem) return;
362
+ const pathnameArray = [];
363
+ for (const [key] of timestampMap) if (comparePaths(routeItem, key)) pathnameArray.push(key);
364
+ await Promise.all(pathnameArray.map((pathname) => invalidatePath(routeItem, pathname)));
365
+ if (withChildren && routeItem.children?.length) {
366
+ const childPathList = routeItem.children.map((el) => el.path);
367
+ await Promise.all(childPathList.map((el) => invalidateItem(`${pathname}${el}`, true)));
368
+ }
369
+ };
370
+ async function invalidate(pathList, options) {
371
+ const routePathname = routeItemDataState.getState().location.pathname;
372
+ const pathnameList = Array.isArray(pathList) ? pathList : pathList ? [pathList] : [routePathname];
373
+ await Promise.all(pathnameList.map((pathname) => invalidateItem(pathname, options?.withChildren)));
374
+ }
375
+ return invalidate;
376
+ };
377
+ //#endregion
378
+ //#region runtime/prefetch.ts
379
+ var createPrefetch = (revalidateCache) => async (pathname) => {
380
+ const item = findRoute(pathname);
381
+ if (item) await revalidateCache({
382
+ routeItem: item,
383
+ pathname
384
+ });
226
385
  };
227
386
  //#endregion
228
387
  //#region utils/revalidateCache.ts
229
388
  var loaderMapRef = {};
230
389
  var loadingPromises = /* @__PURE__ */ new Map();
231
- var revalidateCache = ({ routeItem, pathname }) => {
390
+ var createRevalidateCache = (routerState) => ({ routeItem, pathname }) => {
232
391
  if (!routeItem?.loader) return;
392
+ const isCacheItemFresh = createIsCacheItemFresh(routerState.timestampMap);
393
+ const { loaderStateRef, timestampMap, contextState } = routerState;
233
394
  if (loadingPromises.has(pathname)) return loadingPromises.get(pathname);
234
395
  if (isCacheItemFresh({
235
396
  routeItem,
@@ -241,7 +402,8 @@ var revalidateCache = ({ routeItem, pathname }) => {
241
402
  const promise = (async () => {
242
403
  if (!routeItem?.loader) return;
243
404
  try {
244
- const { context, setContext } = getContext();
405
+ const context = contextState.getState();
406
+ const setContext = contextState.setState;
245
407
  const params = getParamsObject({
246
408
  params: routeItem.params,
247
409
  pathname
@@ -272,148 +434,82 @@ var revalidateCache = ({ routeItem, pathname }) => {
272
434
  return promise;
273
435
  };
274
436
  //#endregion
275
- //#region utils/commitState.ts
276
- var commitState = (nextLocation, routeItem) => {
277
- routeItemDataState.setState({
278
- routeItem,
279
- location: nextLocation
280
- });
281
- currentLoaderState.setState(loaderStateRef.value);
282
- isLoadingState.setState(false);
283
- loaderFallbackState.setState(void 0);
284
- prevPathnameRef.set(nextLocation.pathname);
285
- const fullPath = nextLocation.search ? `${nextLocation.pathname}${nextLocation.search}` : nextLocation.pathname;
286
- if (fullPath === window.location.pathname + window.location.search) return;
287
- history.pushState(null, "", fullPath);
288
- };
289
- //#endregion
290
- //#region config/routerConfig.ts
291
- var RouterConfig = class {
292
- constructor() {
293
- _defineProperty(this, "routes", []);
294
- _defineProperty(this, "prefetch", "hover");
295
- _defineProperty(this, "isAnimated", false);
296
- _defineProperty(this, "showFallbackOnAnimation", false);
297
- _defineProperty(this, "hoverPrefetchDelay", 150);
298
- _defineProperty(this, "beforeLoad", void 0);
299
- _defineProperty(this, "afterLoad", void 0);
300
- }
301
- configure(config) {
302
- Object.assign(this, config);
437
+ //#region cell.ts
438
+ var Cell = class {
439
+ constructor(_value) {
440
+ _defineProperty(this, "_value", void 0);
441
+ this._value = _value;
303
442
  }
304
- };
305
- var routerConfig = new RouterConfig();
306
- //#endregion
307
- //#region utils/commitNavigation.ts
308
- var commitNavigation = (nextLocation, routeItem) => {
309
- const { isAnimated } = routerConfig;
310
- if (!isAnimated || !prevPathnameRef.value) {
311
- commitState(nextLocation, routeItem);
312
- return;
443
+ get value() {
444
+ return this._value;
313
445
  }
314
- try {
315
- document.startViewTransition(() => commitState(nextLocation, routeItem));
316
- } catch {
317
- commitState(nextLocation, routeItem);
446
+ set(action) {
447
+ this._value = typeof action === "function" ? action(this._value) : action;
318
448
  }
319
449
  };
320
- var findRoute = (pathname, includeAll) => {
321
- if (includeAll) return routerConfig.routes.find((el) => el.path === "*" || comparePaths(el, pathname));
322
- return routerConfig.routes.find((el) => el.path === "*" || comparePaths(el, pathname));
323
- };
450
+ new Cell(emptyLoaderState);
451
+ new Cell("");
324
452
  //#endregion
325
- //#region runtime/navigate.ts
326
- var navigationSeq = 0;
327
- var routeResolve = (location) => {
328
- loaderStateRef.set(emptyLoaderState);
329
- const nextItem = findRoute(location.pathname, true);
330
- return {
331
- nextItem,
332
- params: getParamsObject({
333
- params: nextItem?.params,
334
- pathname: location.pathname
335
- })
453
+ //#region utils/createRouterInstance.ts
454
+ var createRouterInstance = () => {
455
+ const routerState = {
456
+ isLoadingState: create(false),
457
+ loaderFallbackState: create(void 0),
458
+ routeItemDataState: create({
459
+ routeItem: void 0,
460
+ location: {}
461
+ }),
462
+ currentLoaderState: create(emptyLoaderState),
463
+ scrollMapState: create({}),
464
+ contextState: create({}),
465
+ blockedRouteState: create({
466
+ from: "",
467
+ to: ""
468
+ }),
469
+ loaderStateRef: new Cell(emptyLoaderState),
470
+ prevPathnameRef: new Cell(""),
471
+ timestampMap: /* @__PURE__ */ new Map()
336
472
  };
337
- };
338
- var beforeLoad = async (routeItem, params) => {
339
- const { beforeLoad } = routerConfig;
340
- const runBeforeLoad = async (loaderFn) => {
341
- const redirect = async (redirected) => await navigate(typeof redirected === "string" ? { pathname: redirected } : redirected);
342
- try {
343
- await loaderFn({
344
- ...getContext(),
345
- redirect,
346
- params
347
- });
348
- loaderStateRef.set((prev) => ({
349
- ...prev,
350
- beforeLoadError: null
351
- }));
352
- } catch (error) {
353
- loaderStateRef.set((prev) => ({
354
- ...prev,
355
- beforeLoadError: error
356
- }));
473
+ const revalidateCache = createRevalidateCache(routerState);
474
+ return {
475
+ state: {
476
+ isLoadingState: routerState.isLoadingState,
477
+ loaderFallbackState: routerState.loaderFallbackState,
478
+ routeItemDataState: routerState.routeItemDataState,
479
+ currentLoaderState: routerState.currentLoaderState,
480
+ scrollMapState: routerState.scrollMapState,
481
+ contextState: routerState.contextState,
482
+ blockedRouteState: routerState.blockedRouteState,
483
+ prevPathnameRef: routerState.prevPathnameRef
484
+ },
485
+ runtime: {
486
+ navigate: createNavigate(routerState, revalidateCache),
487
+ invalidate: createInvalidate(routerState, revalidateCache),
488
+ prefetch: createPrefetch(revalidateCache)
489
+ },
490
+ hooks: {
491
+ useIsLoading: () => useGlobalState(routerState.isLoadingState),
492
+ useBlockedRoute: () => useGlobalState(routerState.blockedRouteState),
493
+ useLoaderFallback: () => useGlobalState(routerState.loaderFallbackState),
494
+ useRouteItemData: () => useGlobalState(routerState.routeItemDataState),
495
+ useCurrentLoaderState: () => useGlobalState(routerState.currentLoaderState),
496
+ useScrollMap: () => useGlobalState(routerState.scrollMapState),
497
+ useContextState: () => useGlobalState(routerState.contextState)
357
498
  }
358
499
  };
359
- if (beforeLoad) await runBeforeLoad(beforeLoad);
360
- if (routeItem?.beforeLoad) await runBeforeLoad(routeItem?.beforeLoad);
361
- };
362
- var prepareNavigation = (routeItem, location) => {
363
- const { isAnimated, showFallbackOnAnimation: showFallback } = routerConfig;
364
- scrollMapState.setState((prevState) => {
365
- const scrollPosition = document.scrollingElement?.scrollTop ?? 0;
366
- if (!scrollPosition || prevState[prevPathnameRef.value] === scrollPosition) return prevState;
367
- return {
368
- ...prevState,
369
- [prevPathnameRef.value]: scrollPosition
370
- };
371
- });
372
- loaderFallbackState.setState(isCacheItemFresh({
373
- routeItem,
374
- pathname: location.pathname
375
- }) || isAnimated && !showFallback ? void 0 : routeItem?.loaderFallback);
376
- };
377
- var loader = async (routeItem, location) => {
378
- if (!routeItem?.loader) return;
379
- isLoadingState.setState(true);
380
- await revalidateCache({
381
- routeItem,
382
- pathname: location.pathname
383
- });
384
- };
385
- var afterLoad = async (routeItem, params) => {
386
- const { afterLoad } = routerConfig;
387
- if (routeItem?.afterLoad) await routeItem.afterLoad({
388
- ...getContext(),
389
- params
390
- });
391
- if (afterLoad) await afterLoad({
392
- ...getContext(),
393
- params
394
- });
395
- };
396
- var navigate = async (nextLocation) => {
397
- navigationSeq = navigationSeq + 1;
398
- const seq = navigationSeq;
399
- const { nextItem, params } = routeResolve(nextLocation);
400
- await beforeLoad(nextItem, params);
401
- if (seq !== navigationSeq) return;
402
- prepareNavigation(nextItem, nextLocation);
403
- await loader(nextItem, nextLocation);
404
- if (seq !== navigationSeq) return;
405
- commitNavigation(nextLocation, nextItem);
406
- await afterLoad(nextItem, params);
407
500
  };
408
501
  //#endregion
502
+ //#region instance.ts
503
+ var router = createRouterInstance();
504
+ //#endregion
409
505
  //#region hooks/useNavigation.ts
410
506
  var useNavigation = () => {
411
- const [blockedRoute, setBlockedRoute] = useBlockedRoute();
507
+ const { state: { prevPathnameRef, blockedRouteState }, runtime: { navigate } } = router;
412
508
  useEffect(() => {
413
509
  const handler = async (event) => {
414
510
  const newLocation = parseWindowLocation(event.target.location);
415
- if (prevPathnameRef.value === blockedRoute.from) {
416
- setBlockedRoute({
511
+ if (prevPathnameRef.value === blockedRouteState.getState().from) {
512
+ blockedRouteState.setState({
417
513
  from: prevPathnameRef.value,
418
514
  to: newLocation.pathname
419
515
  });
@@ -422,12 +518,16 @@ var useNavigation = () => {
422
518
  };
423
519
  window.addEventListener("popstate", handler);
424
520
  return () => window.removeEventListener("popstate", handler);
425
- }, [blockedRoute.from, setBlockedRoute]);
521
+ }, [
522
+ blockedRouteState,
523
+ navigate,
524
+ prevPathnameRef.value
525
+ ]);
426
526
  useEffect(() => {
427
527
  const currentLocation = parseWindowLocation(window.location);
428
528
  navigate(currentLocation);
429
529
  prevPathnameRef.set(currentLocation.pathname);
430
- }, []);
530
+ }, [navigate, prevPathnameRef]);
431
531
  };
432
532
  //#endregion
433
533
  //#region hooks/useApplyCustomAnimation.ts
@@ -469,6 +569,7 @@ var useApplyCustomAnimation = (animationDuration) => {
469
569
  //#endregion
470
570
  //#region hooks/usePreserveScroll.ts
471
571
  var usePreserveScroll = (preserveScroll) => {
572
+ const { useRouteItemData, useScrollMap } = router.hooks;
472
573
  const [routeItemData] = useRouteItemData();
473
574
  const [scrollMap] = useScrollMap();
474
575
  const { pathname } = routeItemData.location;
@@ -497,7 +598,7 @@ var useSetRouterConfig = (routerProps) => {
497
598
  //#endregion
498
599
  //#region hooks/useSetInitialContext.ts
499
600
  var useSetInitialContext = (initialContext) => {
500
- const [, setContext] = useContextState();
601
+ const [, setContext] = router.hooks.useContextState();
501
602
  useEffect(() => {
502
603
  if (initialContext) setContext(initialContext);
503
604
  }, [initialContext, setContext]);
@@ -515,6 +616,7 @@ var renderElement = (Component) => {
515
616
  //#region components/Router.tsx
516
617
  var EmptyBoundary = ({ children }) => children;
517
618
  var Router = ({ routes, beforeLoad, afterLoad, animationDuration, isAnimated = false, spinner = true, preserveScroll = true, showFallbackOnAnimation = false, prefetch = "hover", hoverPrefetchDelay = 150, errorBoundary: ErrorBoundary = EmptyBoundary, context: initialContext, defaultLoaderFallback, defaultErrorElement }) => {
619
+ const { useIsLoading, useLoaderFallback, useRouteItemData, useCurrentLoaderState } = router.hooks;
518
620
  const [isLoading] = useIsLoading();
519
621
  const [currentLoaderFallback] = useLoaderFallback();
520
622
  const [routeItemData] = useRouteItemData();
@@ -546,18 +648,9 @@ var Router = ({ routes, beforeLoad, afterLoad, animationDuration, isAnimated = f
546
648
  });
547
649
  };
548
650
  //#endregion
549
- //#region runtime/prefetch.ts
550
- var prefetch = async (pathname) => {
551
- const item = findRoute(pathname);
552
- if (item) await revalidateCache({
553
- routeItem: item,
554
- pathname
555
- });
556
- };
557
- //#endregion
558
651
  //#region hooks/useLocation.ts
559
652
  var useLocation = () => {
560
- const [routeItemData] = useRouteItemData();
653
+ const [routeItemData] = router.hooks.useRouteItemData();
561
654
  return routeItemData.location;
562
655
  };
563
656
  //#endregion
@@ -572,11 +665,10 @@ var useLatest = (value) => {
572
665
  //#endregion
573
666
  //#region hooks/useNavigate.ts
574
667
  var useNavigate = () => {
575
- const [blockedRoute, setBlockedRoute] = useBlockedRoute();
668
+ const [blockedRoute, setBlockedRoute] = router.hooks.useBlockedRoute();
576
669
  const locationRef = useLatest(useLocation());
577
670
  const blockedRouteRef = useLatest(blockedRoute);
578
671
  return useCallback(async (arg) => {
579
- if (!navigate) throw new Error("Router has not been initialized. Did you forget to render <Router />?");
580
672
  if (arg !== -1 && blockedRouteRef.current.from) {
581
673
  const to = typeof arg === "object" ? arg.pathname : arg;
582
674
  setBlockedRoute((prevState) => ({
@@ -587,8 +679,8 @@ var useNavigate = () => {
587
679
  }
588
680
  if (arg === -1) return history.go(arg);
589
681
  if (typeof arg === "string") {
590
- if (arg !== locationRef.current.pathname) await navigate({ pathname: arg });
591
- } else if (JSON.stringify(arg) !== JSON.stringify(locationRef.current)) await navigate(arg);
682
+ if (arg !== locationRef.current.pathname) await router.runtime.navigate({ pathname: arg });
683
+ } else if (JSON.stringify(arg) !== JSON.stringify(locationRef.current)) await router.runtime.navigate(arg);
592
684
  }, [
593
685
  blockedRouteRef,
594
686
  locationRef,
@@ -599,45 +691,45 @@ var useNavigate = () => {
599
691
  //#region components/Link.tsx
600
692
  var Link = ({ children, to, prefetch: prefetchLink, hoverPrefetchDelay }) => {
601
693
  const { prefetch: configPrefetch, hoverPrefetchDelay: configPrefetchDelay } = routerConfig;
602
- const prefetch$1 = prefetchLink || configPrefetch;
694
+ const prefetch = prefetchLink || configPrefetch;
603
695
  const prefetchDelay = hoverPrefetchDelay ?? configPrefetchDelay;
604
696
  const navigate = useNavigate();
605
697
  const timeout = useRef(0);
606
698
  const ref = useRef(null);
607
699
  const onMouseEnter = useCallback(() => {
608
- if (prefetch$1 !== "hover" || !prefetchDelay) return;
700
+ if (prefetch !== "hover" || !prefetchDelay) return;
609
701
  if (timeout.current) clearTimeout(timeout.current);
610
- timeout.current = window.setTimeout(() => prefetch(to), prefetchDelay);
702
+ timeout.current = window.setTimeout(() => router.runtime.prefetch(to), prefetchDelay);
611
703
  }, [
612
- prefetch$1,
704
+ prefetch,
613
705
  prefetchDelay,
614
706
  to
615
707
  ]);
616
708
  const onMouseLeave = useCallback(() => {
617
- if (prefetch$1 !== "hover" || !prefetchDelay) return;
709
+ if (prefetch !== "hover" || !prefetchDelay) return;
618
710
  if (timeout.current) {
619
711
  clearTimeout(timeout.current);
620
712
  timeout.current = 0;
621
713
  }
622
- }, [prefetch$1, prefetchDelay]);
714
+ }, [prefetch, prefetchDelay]);
623
715
  useEffect(() => {
624
- if (prefetch$1 !== "render") return;
716
+ if (prefetch !== "render") return;
625
717
  (async () => {
626
- await prefetch(to);
718
+ await router.runtime.prefetch(to);
627
719
  })();
628
- }, [prefetch$1, to]);
720
+ }, [prefetch, to]);
629
721
  useEffect(() => {
630
- if (prefetch$1 !== "viewport") return;
722
+ if (prefetch !== "viewport") return;
631
723
  const element = ref.current;
632
724
  const observer = new IntersectionObserver(async () => {
633
- await prefetch(to);
725
+ await router.runtime.prefetch(to);
634
726
  observer.disconnect();
635
727
  });
636
728
  if (element) observer.observe(element);
637
729
  return () => {
638
730
  if (element) observer.disconnect();
639
731
  };
640
- }, [prefetch$1, to]);
732
+ }, [prefetch, to]);
641
733
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", {
642
734
  ref,
643
735
  style: { cursor: "pointer" },
@@ -657,64 +749,12 @@ var FormProvider = ({ children, isSubmitting }) => /* @__PURE__ */ (0, import_js
657
749
  children
658
750
  });
659
751
  //#endregion
660
- //#region runtime/invalidate.ts
661
- var redirect = () => Promise.resolve();
662
- var invalidatePath = async (routeItem, pathname) => {
663
- const routePathname = routeItemDataState.getState().location.pathname;
664
- timestampMap.delete(pathname);
665
- const params = getParamsObject({
666
- params: routeItem?.params,
667
- pathname
668
- });
669
- try {
670
- if (routeItem?.beforeLoad) {
671
- const { context, setContext } = getContext();
672
- await routeItem.beforeLoad({
673
- context,
674
- redirect,
675
- params,
676
- setContext
677
- });
678
- }
679
- loaderStateRef.set((prev) => ({
680
- ...prev,
681
- beforeLoadError: null
682
- }));
683
- } catch (error) {
684
- loaderStateRef.set((prev) => ({
685
- ...prev,
686
- beforeLoadError: error
687
- }));
688
- }
689
- await revalidateCache({
690
- routeItem,
691
- pathname
692
- });
693
- if (pathname === routePathname) currentLoaderState.setState(loaderStateRef.value);
694
- };
695
- var invalidateItem = async (pathname, withChildren) => {
696
- const routeItem = findRoute(pathname);
697
- if (!routeItem) return;
698
- const pathnameArray = [];
699
- for (const [key] of timestampMap) if (comparePaths(routeItem, key)) pathnameArray.push(key);
700
- await Promise.all(pathnameArray.map((pathname) => invalidatePath(routeItem, pathname)));
701
- if (withChildren && routeItem.children?.length) {
702
- const childPathList = routeItem.children.map((el) => el.path);
703
- await Promise.all(childPathList.map((el) => invalidateItem(`${pathname}${el}`, withChildren)));
704
- }
705
- };
706
- async function invalidate(pathList, options) {
707
- const routePathname = routeItemDataState.getState().location.pathname;
708
- const pathnameList = Array.isArray(pathList) ? pathList : pathList ? [pathList] : [routePathname];
709
- await Promise.all(pathnameList.map((pathname) => invalidateItem(pathname, options?.withChildren)));
710
- }
711
- //#endregion
712
752
  //#region hooks/useInvalidate.ts
713
- var useInvalidate = () => invalidate;
753
+ var useInvalidate = () => router.runtime.invalidate;
714
754
  //#endregion
715
755
  //#region hooks/useParams.ts
716
756
  var useParams = () => {
717
- const [routeItemData] = useRouteItemData();
757
+ const [routeItemData] = router.hooks.useRouteItemData();
718
758
  const { routeItem, location: { pathname } } = routeItemData;
719
759
  return useMemo(() => routeItem ? getParamsObject({
720
760
  params: routeItem?.params,
@@ -724,6 +764,7 @@ var useParams = () => {
724
764
  //#endregion
725
765
  //#region hooks/useGetAction.ts
726
766
  var useGetAction = (actionKey) => {
767
+ const { useRouteItemData, useContextState } = router.hooks;
727
768
  const invalidate = useInvalidate();
728
769
  const [routeItemData] = useRouteItemData();
729
770
  const [context, setContext] = useContextState();
@@ -774,12 +815,13 @@ var Form = ({ children, action, onSuccess, onError, autoReset = true }) => {
774
815
  //#endregion
775
816
  //#region hooks/useLoaderState.ts
776
817
  var useLoaderState = () => {
777
- const [loaderState] = useCurrentLoaderState();
818
+ const [loaderState] = router.hooks.useCurrentLoaderState();
778
819
  return loaderState;
779
820
  };
780
821
  //#endregion
781
822
  //#region hooks/useBlocker.ts
782
823
  var useBlocker = (blockerFn) => {
824
+ const { hooks: { useBlockedRoute, useRouteItemData }, runtime: { navigate } } = router;
783
825
  const [blockedRoute, setBlockedRoute] = useBlockedRoute();
784
826
  const [routeItemData] = useRouteItemData();
785
827
  const { location: { pathname } } = routeItemData;
@@ -799,7 +841,7 @@ var useBlocker = (blockerFn) => {
799
841
  from: "",
800
842
  to: ""
801
843
  };
802
- }), [setBlockedRoute]);
844
+ }), [navigate, setBlockedRoute]);
803
845
  const blockerState = useMemo(() => {
804
846
  if (blockedRoute.from && blockedRoute.to) return "blocked";
805
847
  if (blockedRoute.from) return "charged";
@@ -844,7 +886,7 @@ var useAction = (action, options = {}) => {
844
886
  //#endregion
845
887
  //#region hooks/useRouterContext.ts
846
888
  var useRouterContext = () => {
847
- const [context, setContext] = useContextState();
889
+ const [context, setContext] = router.hooks.useContextState();
848
890
  return {
849
891
  context,
850
892
  setContext
@@ -0,0 +1 @@
1
+ export declare const router: import("./types").RouterType;
@@ -1,6 +1,5 @@
1
- type Options = {
2
- withChildren?: boolean;
1
+ import { type InvalidateOptions, RevalidateCache, RouterState } from '../types';
2
+ export declare const createInvalidate: ({ routeItemDataState, loaderStateRef, timestampMap, currentLoaderState, contextState }: RouterState, revalidateCache: RevalidateCache) => {
3
+ (pathList?: string[]): Promise<void>;
4
+ (path?: string, options?: InvalidateOptions): Promise<void>;
3
5
  };
4
- export declare function invalidate(path?: string[]): Promise<void>;
5
- export declare function invalidate(path?: string, options?: Options): Promise<void>;
6
- export {};
@@ -1,2 +1,2 @@
1
- import { Location } from '../types/global';
2
- export declare const navigate: (nextLocation: Location) => Promise<void>;
1
+ import { Location, RevalidateCache, RouterState } from '../types';
2
+ export declare const createNavigate: (routerSta: RouterState, revalidateCache: RevalidateCache) => (nextLocation: Location) => Promise<void>;
@@ -1 +1,2 @@
1
- export declare const prefetch: (pathname: string) => Promise<void>;
1
+ import { RevalidateCache } from '../types';
2
+ export declare const createPrefetch: (revalidateCache: RevalidateCache) => (pathname: string) => Promise<void>;
@@ -1,4 +1,6 @@
1
1
  import type { ComponentType, Dispatch, ReactElement, ReactNode, SetStateAction } from 'react';
2
+ import { Store, useGlobalState } from './create';
3
+ import { Cell } from './cell';
2
4
  export type LazyComponent = () => Promise<{
3
5
  default: ComponentType<unknown>;
4
6
  }>;
@@ -9,11 +11,6 @@ export type BeforeLoad = (arg: {
9
11
  params: Record<string, string>;
10
12
  setContext: Dispatch<SetStateAction<Record<string, unknown>>>;
11
13
  }) => Promise<unknown> | undefined | void;
12
- export type AfterLoad = (arg: {
13
- context: Record<string, unknown>;
14
- params: Record<string, string>;
15
- setContext: Dispatch<SetStateAction<Record<string, unknown>>>;
16
- }) => Promise<void>;
17
14
  export type ClientRouteItem = {
18
15
  path: string;
19
16
  element: RenderElement | LazyComponent;
@@ -63,7 +60,7 @@ export type LoaderState<T = unknown> = {
63
60
  loaderError: Error | null;
64
61
  beforeLoadError: Error | null;
65
62
  };
66
- export type AdapterType<T> = {
63
+ export type Adapter<T> = {
67
64
  parse: (params: string[]) => T;
68
65
  serialize?: (params: T) => string | string[];
69
66
  };
@@ -89,3 +86,42 @@ export type RouterProps = {
89
86
  afterLoad?: ClientRouteItem['afterLoad'];
90
87
  context?: Record<string, unknown>;
91
88
  };
89
+ export type RouterState = {
90
+ isLoadingState: Store<boolean>;
91
+ loaderFallbackState: Store<RouteItem['loaderFallback']>;
92
+ routeItemDataState: Store<RouteItemData>;
93
+ currentLoaderState: Store<LoaderState>;
94
+ scrollMapState: Store<Record<string, number>>;
95
+ contextState: Store<Record<string, unknown>>;
96
+ blockedRouteState: Store<{
97
+ from: string;
98
+ to: string;
99
+ }>;
100
+ loaderStateRef: Cell<LoaderState>;
101
+ prevPathnameRef: Cell<string>;
102
+ timestampMap: Map<string, number>;
103
+ };
104
+ export type RouterType = {
105
+ state: Omit<RouterState, 'loaderStateRef' | 'timestampMap'>;
106
+ runtime: {
107
+ navigate(arg: Location): Promise<void>;
108
+ invalidate(pathList?: string | string[], options?: InvalidateOptions): Promise<void>;
109
+ prefetch(pathname: string): Promise<void>;
110
+ };
111
+ hooks: {
112
+ useIsLoading: () => ReturnType<typeof useGlobalState<boolean>>;
113
+ useBlockedRoute: () => ReturnType<typeof useGlobalState<{
114
+ from: string;
115
+ to: string;
116
+ }>>;
117
+ useLoaderFallback: () => ReturnType<typeof useGlobalState<RenderElement | undefined>>;
118
+ useRouteItemData: () => ReturnType<typeof useGlobalState<RouteItemData>>;
119
+ useCurrentLoaderState: () => ReturnType<typeof useGlobalState<LoaderState<unknown>>>;
120
+ useScrollMap: () => ReturnType<typeof useGlobalState<Record<string, number>>>;
121
+ useContextState: () => ReturnType<typeof useGlobalState<Record<string, unknown>>>;
122
+ };
123
+ };
124
+ export type InvalidateOptions = {
125
+ withChildren?: boolean;
126
+ };
127
+ export type RevalidateCache = ({ routeItem, pathname }: RevalidateCacheArgs) => Promise<unknown> | undefined;
@@ -1,4 +1,4 @@
1
- import { AdapterType } from '../types/global';
1
+ import { Adapter } from '../types';
2
2
  type ZodInterface<T> = {
3
3
  safeParse(input: unknown): {
4
4
  success: true;
@@ -46,6 +46,6 @@ export declare const adapter: {
46
46
  parse: (params: string[]) => Date[];
47
47
  serialize: (args: Date[]) => string[];
48
48
  };
49
- zodSchema: <T>(schema: ZodInterface<T>) => AdapterType<T>;
49
+ zodSchema: <T>(schema: ZodInterface<T>) => Adapter<T>;
50
50
  };
51
51
  export {};
@@ -1,2 +1,3 @@
1
- import { Location, RouteItem } from '../types/global';
2
- export declare const commitNavigation: (nextLocation: Location, routeItem: RouteItem | undefined) => void;
1
+ import { Cell } from '../cell';
2
+ import { Location, RouteItem } from '../types';
3
+ export declare const createCommitNavigation: (navigationExecutor: (arg: Location, routeItem: RouteItem | undefined) => void, prevPathnameRef: Cell<string>) => (nextLocation: Location, routeItem: RouteItem | undefined) => void;
@@ -1,2 +1,2 @@
1
- import { Location, RouteItem } from '../types/global';
2
- export declare const commitState: (nextLocation: Location, routeItem: RouteItem | undefined) => void;
1
+ import { Location, RouteItem, RouterState } from '../types';
2
+ export declare const createCommitState: ({ isLoadingState, routeItemDataState, loaderFallbackState, currentLoaderState, prevPathnameRef, loaderStateRef, }: RouterState) => (nextLocation: Location, routeItem: RouteItem | undefined) => void;
@@ -0,0 +1,2 @@
1
+ import { RouterType } from '../types';
2
+ export declare const createRouterInstance: () => RouterType;
@@ -1,2 +1,2 @@
1
- export declare const ALL_LOCATIONS = "*";
1
+ export declare const ALL_LOCATIONS = "/*";
2
2
  export declare const findRoute: (pathname: string, includeAll?: boolean) => import("..").RouteItem | undefined;
@@ -1,5 +1,5 @@
1
- import type { RouteItem } from '../types/global';
2
- export declare const isCacheItemFresh: ({ routeItem, pathname }: {
1
+ import type { RouteItem } from '../types';
2
+ export declare const createIsCacheItemFresh: (timestampMap: Map<string, number>) => ({ routeItem, pathname }: {
3
3
  routeItem?: RouteItem;
4
4
  pathname: string;
5
5
  }) => boolean;
@@ -1,2 +1,2 @@
1
- import { RenderElement } from '../types/global';
1
+ import { RenderElement } from '../types';
2
2
  export declare const renderElement: (Component?: RenderElement) => import("react/jsx-runtime").JSX.Element | null;
@@ -1,3 +1,2 @@
1
- import type { RevalidateCacheArgs } from '../types/global';
2
- declare const revalidateCache: ({ routeItem, pathname }: RevalidateCacheArgs) => Promise<unknown> | undefined;
3
- export { revalidateCache };
1
+ import { RevalidateCacheArgs, RouterState } from '../types';
2
+ export declare const createRevalidateCache: (routerState: RouterState) => ({ routeItem, pathname }: RevalidateCacheArgs) => any;
@@ -1,4 +1,4 @@
1
- import type { ClientRouteItem, Location, RouteItem } from '../types/global';
1
+ import { ClientRouteItem, Location, RouteItem } from '../types';
2
2
  export declare const createRouter: (clientList: ClientRouteItem[]) => RouteItem[];
3
3
  export declare const getParamsObject: ({ params, pathname }: {
4
4
  params?: RouteItem["params"];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clear-react-router",
3
- "version": "1.7.9",
3
+ "version": "1.8.0",
4
4
  "description": "A lightweight, type-safe routing library for React applications",
5
5
  "author": "Andrew Bubnov",
6
6
  "scripts": {
@@ -1,50 +0,0 @@
1
- import { LoaderState, RouteItemData } from '../types/global';
2
- export declare const isLoadingState: {
3
- subscribe: (listener: (state: boolean, prevState: boolean) => void) => () => void;
4
- getState: () => boolean;
5
- setState: (action: boolean | ((prevState: boolean) => boolean)) => void;
6
- };
7
- export declare const useIsLoading: () => readonly [boolean, (action: boolean | ((prevState: boolean) => boolean)) => void];
8
- export declare const useBlockedRoute: () => readonly [{
9
- from: string;
10
- to: string;
11
- }, (action: {
12
- from: string;
13
- to: string;
14
- } | ((prevState: {
15
- from: string;
16
- to: string;
17
- }) => {
18
- from: string;
19
- to: string;
20
- })) => void];
21
- export declare const loaderFallbackState: {
22
- subscribe: (listener: (state: import("../types/global").RenderElement | undefined, prevState: import("../types/global").RenderElement | undefined) => void) => () => void;
23
- getState: () => import("../types/global").RenderElement | undefined;
24
- setState: (action: import("../types/global").RenderElement | ((prevState: import("../types/global").RenderElement | undefined) => import("../types/global").RenderElement | undefined) | undefined) => void;
25
- };
26
- export declare const useLoaderFallback: () => readonly [import("../types/global").RenderElement | undefined, (action: import("../types/global").RenderElement | ((prevState: import("../types/global").RenderElement | undefined) => import("../types/global").RenderElement | undefined) | undefined) => void];
27
- export declare const routeItemDataState: {
28
- subscribe: (listener: (state: RouteItemData, prevState: RouteItemData) => void) => () => void;
29
- getState: () => RouteItemData;
30
- setState: (action: RouteItemData | ((prevState: RouteItemData) => RouteItemData)) => void;
31
- };
32
- export declare const useRouteItemData: () => readonly [RouteItemData, (action: RouteItemData | ((prevState: RouteItemData) => RouteItemData)) => void];
33
- export declare const currentLoaderState: {
34
- subscribe: (listener: (state: LoaderState, prevState: LoaderState) => void) => () => void;
35
- getState: () => LoaderState;
36
- setState: (action: LoaderState | ((prevState: LoaderState) => LoaderState)) => void;
37
- };
38
- export declare const useCurrentLoaderState: () => readonly [LoaderState, (action: LoaderState | ((prevState: LoaderState) => LoaderState)) => void];
39
- export declare const scrollMapState: {
40
- subscribe: (listener: (state: Record<string, number>, prevState: Record<string, number>) => void) => () => void;
41
- getState: () => Record<string, number>;
42
- setState: (action: Record<string, number> | ((prevState: Record<string, number>) => Record<string, number>)) => void;
43
- };
44
- export declare const useScrollMap: () => readonly [Record<string, number>, (action: Record<string, number> | ((prevState: Record<string, number>) => Record<string, number>)) => void];
45
- export declare const contextState: {
46
- subscribe: (listener: (state: Record<string, unknown>, prevState: Record<string, unknown>) => void) => () => void;
47
- getState: () => Record<string, unknown>;
48
- setState: (action: Record<string, unknown> | ((prevState: Record<string, unknown>) => Record<string, unknown>)) => void;
49
- };
50
- export declare const useContextState: () => readonly [Record<string, unknown>, (action: Record<string, unknown> | ((prevState: Record<string, unknown>) => Record<string, unknown>)) => void];
@@ -1,4 +0,0 @@
1
- export declare const getContext: () => {
2
- context: Record<string, unknown>;
3
- setContext: (action: Record<string, unknown> | ((prevState: Record<string, unknown>) => Record<string, unknown>)) => void;
4
- };