clear-react-router 1.9.6 → 1.9.8
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 +14 -11
- package/dist/components/Link.d.ts +2 -2
- package/dist/components/Router.d.ts +1 -1
- package/dist/config/routerConfig.d.ts +4 -4
- package/dist/index.d.ts +1 -0
- package/dist/index.js +48 -35
- package/dist/types.d.ts +11 -7
- package/dist/utils/lazy.d.ts +5 -0
- package/dist/utils/utils.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -45,21 +45,22 @@ It provides first-class support for:
|
|
|
45
45
|
| `routes` | `RouteItem[]` | required | Array of route configurations |
|
|
46
46
|
| `isAnimated` | `boolean \| undefined` | `false` | Enable smooth page fade transitions |
|
|
47
47
|
| `animationDuration` | `number` | `optional` | Animation duration in milliseconds (browser default is used if not set) |
|
|
48
|
+
| `spinner` | `boolean \| undefined` | `true` | Show a small spinner in the corner while loading data (only when `isAnimated` is enabled) |
|
|
49
|
+
| `context` | `object` | `{}` | Initial context (user, theme, etc.) |
|
|
50
|
+
| `errorBoundary` | `ComponentType<{ children: ReactNode }>` | `undefined` | Custom error boundary component for catching render errors in route components |
|
|
51
|
+
| `showFallbackOnAnimation` | `boolean \| undefined` | `false` | Show `loaderFallback` even when `isAnimated` is `true` (instead of spinner) |
|
|
48
52
|
| `defaultLoaderFallback` | `ReactElement \| () => ReactElement` | `optional` | Default loading fallback for every route loader |
|
|
49
53
|
| `defaultErrorElement` | `ReactElement \| () => ReactElement` | `optional` | Default error fallback for every route |
|
|
50
54
|
| `defaultRetry` | `number \| { count: number; delay: number }` | `optional` | Default cache revalidation retry policy for all routes |
|
|
51
55
|
| `defaultStaleTime` | `number` | `optional` | Default time in milliseconds before cached loader data is considered stale |
|
|
52
|
-
| `
|
|
53
|
-
| `
|
|
54
|
-
| `spinner` | `boolean \| undefined` | `true` | Show a small spinner in the corner while loading data (only when `isAnimated` is enabled) |
|
|
56
|
+
| `defaultBeforeLoad` | `({ params, context, redirect, setContext }) => Promise<unknown> \| undefined \| void` | `undefined` | Runs before every navigation. Useful for authentication, analytics, or updating shared context. |
|
|
57
|
+
| `defaultAfterLoad` | `({ params, context, setContext }) => Promise<void>` | `undefined` | Runs after every successful navigation. Useful for analytics, page tracking, or other global side effects. |
|
|
55
58
|
| `defaultPreserveScroll` | `boolean \| undefined` | `true` | Default value for save and restore scroll position when navigating between pages |
|
|
56
|
-
| `
|
|
57
|
-
| `
|
|
58
|
-
| `hoverPrefetchDelay` | `number` | `150` | Delay in milliseconds before prefetching on hover (only for `'hover'` strategy) |
|
|
59
|
-
| `context` | `object` | `{}` | Initial context (user, theme, etc.) |
|
|
60
|
-
| `errorBoundary` | `ComponentType<{ children: ReactNode }>` | `undefined` | Custom error boundary component for catching render errors in route components |
|
|
59
|
+
| `defaultPrefetch` | `'hover' \| 'render' \| 'viewport' \| 'none'` | `'hover'` for desktop, `'viewport'` for mobile | Default prefetch strategy for all `<Link>` components |
|
|
60
|
+
| `defaultHoverPrefetchDelay` | `number` | `150` | Default delay in milliseconds before prefetching on hover (only for `'hover'` strategy) |
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
|
|
63
|
+
> **Note:** Global lifecycle hooks wrap every route navigation. The global `defaultBeforeLoad` runs **before** the route-specific beforeLoad, while the global `defaultAfterLoad` runs **after** the route-specific afterLoad.
|
|
63
64
|
|
|
64
65
|
```tsx
|
|
65
66
|
<div>
|
|
@@ -772,11 +773,13 @@ function ProductFilter() {
|
|
|
772
773
|
|
|
773
774
|
## Lazy Loading
|
|
774
775
|
|
|
775
|
-
Clear Router supports code-splitting out of the box. Simply
|
|
776
|
+
Clear Router supports code-splitting out of the box. Simply wrap dynamic import into a library's `lazy` function:
|
|
776
777
|
```tsx
|
|
778
|
+
import { lazy } from 'clear-react-router';
|
|
779
|
+
|
|
777
780
|
{
|
|
778
781
|
path: '/heavy-page',
|
|
779
|
-
element: () => import('./pages/HeavyComponent'),
|
|
782
|
+
element: lazy(() => import('./pages/HeavyComponent')),
|
|
780
783
|
fallback: () => <div>Loading...</div>,
|
|
781
784
|
}
|
|
782
785
|
```
|
|
@@ -8,7 +8,7 @@ type LinkProps<T extends HTMLElement = HTMLAnchorElement> = {
|
|
|
8
8
|
to: string;
|
|
9
9
|
children?: ReactNode;
|
|
10
10
|
as?: (props: ElementProps<T>, state: ElementState) => ReactElement;
|
|
11
|
-
prefetch?: RouterProps['
|
|
11
|
+
prefetch?: RouterProps['defaultPrefetch'];
|
|
12
12
|
hoverPrefetchDelay?: number;
|
|
13
13
|
className?: string | ((arg: ElementState) => string);
|
|
14
14
|
activeClassName?: string;
|
|
@@ -17,5 +17,5 @@ type LinkProps<T extends HTMLElement = HTMLAnchorElement> = {
|
|
|
17
17
|
style?: CSSProperties | ((arg: ElementState) => CSSProperties);
|
|
18
18
|
exact?: boolean;
|
|
19
19
|
};
|
|
20
|
-
export declare const Link: <T extends HTMLElement = HTMLAnchorElement>({ children, to, as, prefetch:
|
|
20
|
+
export declare const Link: <T extends HTMLElement = HTMLAnchorElement>({ children, to, as, prefetch: linkPrefetch, hoverPrefetchDelay, className, style, beforeNavigate, exact, activeClassName, pendingClassName, }: LinkProps<T>) => ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
21
21
|
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { RouterProps } from '../types';
|
|
2
|
-
export declare const Router: ({ routes,
|
|
2
|
+
export declare const Router: ({ routes, defaultBeforeLoad, defaultAfterLoad, animationDuration, defaultLoaderFallback, defaultErrorElement, defaultRetry, defaultStaleTime, context: initialContext, isAnimated, spinner, defaultPreserveScroll, showFallbackOnAnimation, defaultPrefetch, defaultHoverPrefetchDelay, errorBoundary: ErrorBoundary, }: RouterProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { ClientRouteItem, RouterProps } from '../types';
|
|
2
2
|
declare class RouterConfig {
|
|
3
3
|
routes: RouterProps['routes'];
|
|
4
|
-
|
|
4
|
+
defaultPrefetch: RouterProps['defaultPrefetch'];
|
|
5
5
|
isAnimated: RouterProps['isAnimated'];
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
defaultHoverPrefetchDelay: number;
|
|
7
|
+
defaultBeforeLoad?: ClientRouteItem['beforeLoad'];
|
|
8
|
+
defaultAfterLoad?: ClientRouteItem['afterLoad'];
|
|
9
9
|
defaultRetry?: RouterProps['defaultRetry'];
|
|
10
10
|
defaultStaleTime?: RouterProps['defaultStaleTime'];
|
|
11
11
|
defaultPreserveScroll?: RouterProps['defaultPreserveScroll'];
|
package/dist/index.d.ts
CHANGED
|
@@ -11,5 +11,6 @@ export { useAction } from './hooks/useAction';
|
|
|
11
11
|
export { useRouterContext } from './hooks/useRouterContext';
|
|
12
12
|
export { useSearchParams } from './hooks/useSearchParams';
|
|
13
13
|
export { useFormContext } from './hooks/useFormContext';
|
|
14
|
+
export { lazy } from './utils/lazy';
|
|
14
15
|
export { createRouter } from './utils/utils';
|
|
15
16
|
export type { RouteItem, BlockerState, Location, RouterProps, ElementProps } from './types';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Suspense, createContext, lazy, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
1
|
+
import { Suspense, createContext, lazy as lazy$1, useCallback, useContext, useEffect, useLayoutEffect, 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
|
|
@@ -44,7 +44,7 @@ var createCommitState = ({ routeItemDataState, pendingState }) => (nextLocation,
|
|
|
44
44
|
//#region constants.ts
|
|
45
45
|
var emptyLoaderState = {};
|
|
46
46
|
//#endregion
|
|
47
|
-
//#region \0@oxc-project+runtime@0.
|
|
47
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
|
|
48
48
|
function _typeof(o) {
|
|
49
49
|
"@babel/helpers - typeof";
|
|
50
50
|
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
@@ -54,7 +54,7 @@ function _typeof(o) {
|
|
|
54
54
|
}, _typeof(o);
|
|
55
55
|
}
|
|
56
56
|
//#endregion
|
|
57
|
-
//#region \0@oxc-project+runtime@0.
|
|
57
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
|
|
58
58
|
function toPrimitive(t, r) {
|
|
59
59
|
if ("object" != _typeof(t) || !t) return t;
|
|
60
60
|
var e = t[Symbol.toPrimitive];
|
|
@@ -66,13 +66,13 @@ function toPrimitive(t, r) {
|
|
|
66
66
|
return ("string" === r ? String : Number)(t);
|
|
67
67
|
}
|
|
68
68
|
//#endregion
|
|
69
|
-
//#region \0@oxc-project+runtime@0.
|
|
69
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
|
|
70
70
|
function toPropertyKey(t) {
|
|
71
71
|
var i = toPrimitive(t, "string");
|
|
72
72
|
return "symbol" == _typeof(i) ? i : i + "";
|
|
73
73
|
}
|
|
74
74
|
//#endregion
|
|
75
|
-
//#region \0@oxc-project+runtime@0.
|
|
75
|
+
//#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
|
|
76
76
|
function _defineProperty(e, r, t) {
|
|
77
77
|
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
78
78
|
value: t,
|
|
@@ -86,11 +86,11 @@ function _defineProperty(e, r, t) {
|
|
|
86
86
|
var RouterConfig = class {
|
|
87
87
|
constructor() {
|
|
88
88
|
_defineProperty(this, "routes", []);
|
|
89
|
-
_defineProperty(this, "
|
|
89
|
+
_defineProperty(this, "defaultPrefetch", "hover");
|
|
90
90
|
_defineProperty(this, "isAnimated", false);
|
|
91
|
-
_defineProperty(this, "
|
|
92
|
-
_defineProperty(this, "
|
|
93
|
-
_defineProperty(this, "
|
|
91
|
+
_defineProperty(this, "defaultHoverPrefetchDelay", 150);
|
|
92
|
+
_defineProperty(this, "defaultBeforeLoad", void 0);
|
|
93
|
+
_defineProperty(this, "defaultAfterLoad", void 0);
|
|
94
94
|
_defineProperty(this, "defaultRetry", void 0);
|
|
95
95
|
_defineProperty(this, "defaultStaleTime", void 0);
|
|
96
96
|
_defineProperty(this, "defaultPreserveScroll", void 0);
|
|
@@ -133,8 +133,7 @@ var createIsCacheItemFresh = (loaderMap) => ({ routeItem, pathname }) => {
|
|
|
133
133
|
* LICENSE file in the root directory of this source tree.
|
|
134
134
|
*/
|
|
135
135
|
var require_react_jsx_runtime_production = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
136
|
-
var REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element");
|
|
137
|
-
var REACT_FRAGMENT_TYPE = Symbol.for("react.fragment");
|
|
136
|
+
var REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"), REACT_FRAGMENT_TYPE = Symbol.for("react.fragment");
|
|
138
137
|
function jsxProd(type, config, maybeKey) {
|
|
139
138
|
var key = null;
|
|
140
139
|
void 0 !== maybeKey && (key = "" + maybeKey);
|
|
@@ -163,7 +162,7 @@ var import_jsx_runtime = (/* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
|
163
162
|
})))();
|
|
164
163
|
var createLazyComponent = (importFn, fallback) => {
|
|
165
164
|
const load = () => importFn().then((module) => ({ default: module.default || module }));
|
|
166
|
-
const LazyComp = lazy(load);
|
|
165
|
+
const LazyComp = lazy$1(load);
|
|
167
166
|
const Component = () => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Suspense, {
|
|
168
167
|
fallback: typeof fallback === "function" ? fallback() : fallback || null,
|
|
169
168
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LazyComp, {})
|
|
@@ -174,12 +173,15 @@ var createLazyComponent = (importFn, fallback) => {
|
|
|
174
173
|
};
|
|
175
174
|
};
|
|
176
175
|
//#endregion
|
|
176
|
+
//#region types.ts
|
|
177
|
+
var LAZY_MARKER = Symbol("clear-router-lazy");
|
|
178
|
+
//#endregion
|
|
177
179
|
//#region utils/utils.ts
|
|
178
|
-
var isLazy = (el) => typeof el.element === "
|
|
180
|
+
var isLazy = (el) => typeof el.element === "object" && el.element !== null && LAZY_MARKER in el.element;
|
|
179
181
|
var parseClientRouteItem = (el, parentPattern = "") => {
|
|
180
182
|
const pattern = `${parentPattern}/${el.path}`.replace(/\/+/g, "/");
|
|
181
|
-
const preloadElement = isLazy(el) ? createLazyComponent(el.element, el.fallback).preloadElement : void 0;
|
|
182
|
-
const resolvedElement = isLazy(el) ? createLazyComponent(el.element, el.fallback).Component : el.element;
|
|
183
|
+
const preloadElement = isLazy(el) ? createLazyComponent(el.element.importFn, el.fallback).preloadElement : void 0;
|
|
184
|
+
const resolvedElement = isLazy(el) ? createLazyComponent(el.element.importFn, el.fallback).Component : el.element;
|
|
183
185
|
return [{
|
|
184
186
|
...el,
|
|
185
187
|
pattern,
|
|
@@ -208,6 +210,11 @@ var comparePaths = (route, pathname) => {
|
|
|
208
210
|
const current = pathname.split("/").filter(Boolean);
|
|
209
211
|
return pattern.length === current.length ? pattern.every((segment, index) => segment.startsWith(":") || segment === current[index]) : false;
|
|
210
212
|
};
|
|
213
|
+
var isMobile = () => {
|
|
214
|
+
const hasCoarsePointer = window.matchMedia("(pointer: coarse)").matches;
|
|
215
|
+
const isSmallScreen = window.matchMedia("(max-width: 768px)").matches;
|
|
216
|
+
return hasCoarsePointer && isSmallScreen;
|
|
217
|
+
};
|
|
211
218
|
var findRoute = (pathname, includeAll) => {
|
|
212
219
|
if (includeAll) return routerConfig.routes.find((el) => el.path === "*" || comparePaths(el, pathname));
|
|
213
220
|
return routerConfig.routes.find((el) => comparePaths(el, pathname));
|
|
@@ -233,7 +240,7 @@ var createNavigate = (routerState, revalidateCache) => {
|
|
|
233
240
|
};
|
|
234
241
|
};
|
|
235
242
|
const beforeLoad = async (routeItem, params) => {
|
|
236
|
-
const {
|
|
243
|
+
const { defaultBeforeLoad } = routerConfig;
|
|
237
244
|
const runBeforeLoad = async (loaderFn) => {
|
|
238
245
|
const redirect = async (redirected) => await navigate(typeof redirected === "string" ? { pathname: redirected } : redirected);
|
|
239
246
|
try {
|
|
@@ -253,7 +260,7 @@ var createNavigate = (routerState, revalidateCache) => {
|
|
|
253
260
|
}));
|
|
254
261
|
}
|
|
255
262
|
};
|
|
256
|
-
if (
|
|
263
|
+
if (defaultBeforeLoad) await runBeforeLoad(defaultBeforeLoad);
|
|
257
264
|
if (routeItem?.beforeLoad) await runBeforeLoad(routeItem?.beforeLoad);
|
|
258
265
|
};
|
|
259
266
|
const prepareNavigation = (routeItem, location) => {
|
|
@@ -284,7 +291,7 @@ var createNavigate = (routerState, revalidateCache) => {
|
|
|
284
291
|
} : void 0);
|
|
285
292
|
}
|
|
286
293
|
};
|
|
287
|
-
const afterEachLoad = (routeItem) => {
|
|
294
|
+
const afterEachLoad = (routeItem, location) => {
|
|
288
295
|
if (!routeItem?.pollingInterval) return;
|
|
289
296
|
interval = window.setInterval(() => revalidateCache({
|
|
290
297
|
routeItem,
|
|
@@ -299,15 +306,15 @@ var createNavigate = (routerState, revalidateCache) => {
|
|
|
299
306
|
pathname: location.pathname,
|
|
300
307
|
search: location.search
|
|
301
308
|
});
|
|
302
|
-
afterEachLoad(routeItem);
|
|
309
|
+
afterEachLoad(routeItem, location);
|
|
303
310
|
};
|
|
304
311
|
const afterLoad = async (routeItem, params) => {
|
|
305
|
-
const {
|
|
312
|
+
const { defaultAfterLoad } = routerConfig;
|
|
306
313
|
if (routeItem?.afterLoad) await routeItem.afterLoad({
|
|
307
314
|
...getContext(),
|
|
308
315
|
params
|
|
309
316
|
});
|
|
310
|
-
if (
|
|
317
|
+
if (defaultAfterLoad) await defaultAfterLoad({
|
|
311
318
|
...getContext(),
|
|
312
319
|
params
|
|
313
320
|
});
|
|
@@ -461,7 +468,8 @@ var createRevalidateCache = (routerState) => {
|
|
|
461
468
|
if (retry.delay) await sleep(retry.delay);
|
|
462
469
|
await revalidateCache({
|
|
463
470
|
routeItem,
|
|
464
|
-
pathname
|
|
471
|
+
pathname,
|
|
472
|
+
search
|
|
465
473
|
}, retried + 1);
|
|
466
474
|
return {
|
|
467
475
|
data: null,
|
|
@@ -705,7 +713,8 @@ var renderElement = (Component) => {
|
|
|
705
713
|
//#endregion
|
|
706
714
|
//#region components/Router.tsx
|
|
707
715
|
var EmptyBoundary = ({ children }) => children;
|
|
708
|
-
var
|
|
716
|
+
var IS_MOBILE = isMobile();
|
|
717
|
+
var Router = ({ routes, defaultBeforeLoad, defaultAfterLoad, animationDuration, defaultLoaderFallback, defaultErrorElement, defaultRetry, defaultStaleTime, context: initialContext, isAnimated = false, spinner = true, defaultPreserveScroll = true, showFallbackOnAnimation = false, defaultPrefetch = IS_MOBILE ? "viewport" : "hover", defaultHoverPrefetchDelay = 150, errorBoundary: ErrorBoundary = EmptyBoundary }) => {
|
|
709
718
|
const { useRouteItemData, usePendingState } = router.hooks;
|
|
710
719
|
const [routeItemData] = useRouteItemData();
|
|
711
720
|
const [pendingState] = usePendingState();
|
|
@@ -715,10 +724,10 @@ var Router = ({ routes, beforeLoad, afterLoad, animationDuration, isAnimated = f
|
|
|
715
724
|
useSetRouterConfig({
|
|
716
725
|
routes,
|
|
717
726
|
isAnimated,
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
727
|
+
defaultPrefetch,
|
|
728
|
+
defaultHoverPrefetchDelay,
|
|
729
|
+
defaultBeforeLoad,
|
|
730
|
+
defaultAfterLoad,
|
|
722
731
|
defaultRetry,
|
|
723
732
|
defaultStaleTime,
|
|
724
733
|
defaultPreserveScroll
|
|
@@ -758,14 +767,14 @@ var useLocation = () => {
|
|
|
758
767
|
//#endregion
|
|
759
768
|
//#region components/Link.tsx
|
|
760
769
|
var defaultAs = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { ...props });
|
|
761
|
-
var Link = ({ children, to, as = defaultAs, prefetch:
|
|
770
|
+
var Link = ({ children, to, as = defaultAs, prefetch: linkPrefetch, hoverPrefetchDelay, className, style, beforeNavigate, exact = false, activeClassName = "active-link", pendingClassName = "pending-link" }) => {
|
|
762
771
|
const isPending = useIsRoutePending(to);
|
|
763
772
|
const { pathname } = useLocation();
|
|
764
773
|
const navigate = useNavigate();
|
|
765
774
|
const timeout = useRef(0);
|
|
766
775
|
const elementRef = useRef(null);
|
|
767
|
-
const {
|
|
768
|
-
const prefetch =
|
|
776
|
+
const { defaultPrefetch: configPrefetch, defaultHoverPrefetchDelay: configPrefetchDelay } = routerConfig;
|
|
777
|
+
const prefetch = linkPrefetch || configPrefetch;
|
|
769
778
|
const prefetchDelay = hoverPrefetchDelay ?? configPrefetchDelay;
|
|
770
779
|
const onMouseEnter = useCallback(() => {
|
|
771
780
|
if (prefetch !== "hover" || !prefetchDelay) return;
|
|
@@ -993,10 +1002,8 @@ var useSearchParams = () => {
|
|
|
993
1002
|
currentParams.delete(param);
|
|
994
1003
|
(Array.isArray(value) ? value : [value]).forEach((v) => currentParams.append(param, v));
|
|
995
1004
|
navigateWithSearchParams(currentParams);
|
|
996
|
-
} else if (typeof param === "function")
|
|
997
|
-
|
|
998
|
-
navigateWithSearchParams(newParams);
|
|
999
|
-
} else throw new Error("useSearchParams first argument must be either function or string");
|
|
1005
|
+
} else if (typeof param === "function") navigateWithSearchParams(param(currentParams));
|
|
1006
|
+
else throw new Error("useSearchParams first argument must be either function or string");
|
|
1000
1007
|
}, [navigateWithSearchParams, search])
|
|
1001
1008
|
};
|
|
1002
1009
|
};
|
|
@@ -1004,4 +1011,10 @@ var useSearchParams = () => {
|
|
|
1004
1011
|
//#region hooks/useFormContext.ts
|
|
1005
1012
|
var useFormContext = () => useContext(FormContext);
|
|
1006
1013
|
//#endregion
|
|
1007
|
-
|
|
1014
|
+
//#region utils/lazy.ts
|
|
1015
|
+
var lazy = (importFn) => ({
|
|
1016
|
+
[LAZY_MARKER]: true,
|
|
1017
|
+
importFn
|
|
1018
|
+
});
|
|
1019
|
+
//#endregion
|
|
1020
|
+
export { Form, Link, Router, createRouter, lazy, useAction, useBlocker, useFormContext, useInvalidate, useLoaderState, useLocation, useNavigate, useParams, useRouterContext, useSearchParams };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { ComponentType, type CSSProperties, Dispatch, MouseEvent, ReactElement, ReactNode, Ref, SetStateAction } from 'react';
|
|
2
2
|
import { Store, useGlobalState } from './create';
|
|
3
3
|
import { Cell } from './cell';
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
export declare const LAZY_MARKER: unique symbol;
|
|
5
|
+
export type LazyComponent = {
|
|
6
|
+
readonly [LAZY_MARKER]: true;
|
|
7
|
+
importFn: () => Promise<{
|
|
8
|
+
default: ComponentType<unknown>;
|
|
9
|
+
}>;
|
|
10
|
+
};
|
|
7
11
|
export type RenderElement = (() => ReactElement) | ReactElement;
|
|
8
12
|
export type BeforeLoad = (arg: {
|
|
9
13
|
context: Record<string, unknown>;
|
|
@@ -86,13 +90,13 @@ export type RouterProps = {
|
|
|
86
90
|
defaultLoaderFallback?: RenderElement;
|
|
87
91
|
defaultErrorElement?: RenderElement;
|
|
88
92
|
showFallbackOnAnimation?: boolean;
|
|
89
|
-
|
|
90
|
-
|
|
93
|
+
defaultPrefetch?: 'hover' | 'render' | 'viewport' | 'none';
|
|
94
|
+
defaultHoverPrefetchDelay?: number;
|
|
91
95
|
errorBoundary?: ComponentType<{
|
|
92
96
|
children: ReactNode;
|
|
93
97
|
}>;
|
|
94
|
-
|
|
95
|
-
|
|
98
|
+
defaultBeforeLoad?: ClientRouteItem['beforeLoad'];
|
|
99
|
+
defaultAfterLoad?: ClientRouteItem['afterLoad'];
|
|
96
100
|
context?: Record<string, unknown>;
|
|
97
101
|
};
|
|
98
102
|
export type LoaderStateItem = {
|
package/dist/utils/utils.d.ts
CHANGED
|
@@ -3,3 +3,4 @@ export declare const createRouter: (clientList: ClientRouteItem[]) => RouteItem[
|
|
|
3
3
|
export declare const getParamsObject: (nextItem?: RouteItem, nextPathname?: string) => Record<string, string>;
|
|
4
4
|
export declare const parseWindowLocation: (location: typeof window.location) => Location;
|
|
5
5
|
export declare const comparePaths: (route: RouteItem, pathname: string) => boolean;
|
|
6
|
+
export declare const isMobile: () => boolean;
|