clear-react-router 1.0.6 → 1.0.10
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.
|
@@ -7,5 +7,5 @@ type LinkProps = {
|
|
|
7
7
|
}>;
|
|
8
8
|
prefetch?: boolean;
|
|
9
9
|
};
|
|
10
|
-
export declare const Link: ({ children, to, prefetch }: LinkProps) => import("react").JSX.Element;
|
|
10
|
+
export declare const Link: ({ children, to, prefetch }: LinkProps) => import("react/jsx-runtime").JSX.Element;
|
|
11
11
|
export {};
|
|
@@ -3,5 +3,5 @@ type RouterProps = {
|
|
|
3
3
|
routeList: RouteItem[];
|
|
4
4
|
context?: Record<string, unknown>;
|
|
5
5
|
};
|
|
6
|
-
export declare const Router: ({ routeList, context: initialContext }: RouterProps) => import("react").JSX.Element;
|
|
6
|
+
export declare const Router: ({ routeList, context: initialContext }: RouterProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
7
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BlockerState, Location, RouteItem, UpdateBlockedRouteProps } from '../types/global
|
|
1
|
+
import type { BlockerState, Location, RouteItem, UpdateBlockedRouteProps } from '../types/global';
|
|
2
2
|
type UseHandleNavigation = {
|
|
3
3
|
routeList: RouteItem[];
|
|
4
4
|
setLocation: (arg: Location) => void;
|
package/dist/index.js
CHANGED
|
@@ -199,24 +199,29 @@ var l = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
|
|
|
199
199
|
children: e
|
|
200
200
|
})
|
|
201
201
|
})
|
|
202
|
-
}), v = (
|
|
202
|
+
}), v = (e) => {
|
|
203
|
+
let t = s(e);
|
|
204
|
+
return a(() => {
|
|
205
|
+
t.current = e;
|
|
206
|
+
}, [e]), t;
|
|
207
|
+
}, y = (t, r) => {
|
|
203
208
|
let i = n(() => t().then((e) => ({ default: e.default || e })));
|
|
204
209
|
return () => /* @__PURE__ */ (0, g.jsx)(e, {
|
|
205
210
|
fallback: typeof r == "function" ? r() : r || null,
|
|
206
211
|
children: /* @__PURE__ */ (0, g.jsx)(i, {})
|
|
207
212
|
});
|
|
208
|
-
},
|
|
213
|
+
}, b = (e) => typeof e.element == "function" && e.element.toString().includes("import("), x = (e, t = [], n = "") => {
|
|
209
214
|
let r = e.path.match(/:[^/]+/g), i = e.path.replaceAll(/:[^/]+(\/|$)/g, "").split("/").filter(Boolean), a = e.path.split("/"), o = r ? [...t, ...r.map((e, t) => ({
|
|
210
215
|
key: i[t],
|
|
211
216
|
value: e.slice(1)
|
|
212
|
-
}))] : t, s = o.length ? `${n}${a.slice(0, a.length - 1).join("/")}` : e.path, c =
|
|
217
|
+
}))] : t, s = o.length ? `${n}${a.slice(0, a.length - 1).join("/")}` : e.path, c = b(e) ? y(e.element, e.fallback) : e.element;
|
|
213
218
|
return [{
|
|
214
219
|
...e,
|
|
215
220
|
path: s,
|
|
216
221
|
params: o,
|
|
217
222
|
element: c
|
|
218
|
-
}, ...e.children?.flatMap((e) =>
|
|
219
|
-
},
|
|
223
|
+
}, ...e.children?.flatMap((e) => x(e, o, s)) || []];
|
|
224
|
+
}, S = (e) => e.flatMap((e) => x(e, [])), C = (e) => {
|
|
220
225
|
let { pathname: t } = window.location, n = t.split("/");
|
|
221
226
|
return (e || []).map((e) => ({
|
|
222
227
|
index: n.findIndex((t) => t === e.key),
|
|
@@ -225,34 +230,29 @@ var l = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
|
|
|
225
230
|
...e,
|
|
226
231
|
[t.value]: n[t.index + 1]
|
|
227
232
|
}), {});
|
|
228
|
-
},
|
|
233
|
+
}, w = (e) => ({
|
|
229
234
|
pathname: e.pathname,
|
|
230
235
|
search: e.search
|
|
231
|
-
}),
|
|
236
|
+
}), T = (e, t) => {
|
|
232
237
|
let n = e.path.split("/").filter(Boolean), r = e.params ? Object.keys(e.params).length : 0, i = t.split("/").filter(Boolean);
|
|
233
238
|
return n.every((e, t) => e === i[t + +!!t]) && i.length === n.length + r;
|
|
234
|
-
},
|
|
239
|
+
}, E = class {
|
|
235
240
|
url;
|
|
236
241
|
search;
|
|
237
242
|
cause;
|
|
238
243
|
constructor(e, t) {
|
|
239
244
|
this.url = e, this.search = t, this.cause = "redirect";
|
|
240
245
|
}
|
|
241
|
-
},
|
|
242
|
-
let t = s(e);
|
|
243
|
-
return a(() => {
|
|
244
|
-
t.current = e;
|
|
245
|
-
}, [e]), t;
|
|
246
|
-
}, O = ({ setLocation: e, routeList: t, context: n, revalidateCache: i }) => {
|
|
246
|
+
}, D = (e, t) => Promise.reject(new E(e, t)), O = ({ setLocation: e, routeList: t, context: n, revalidateCache: i }) => {
|
|
247
247
|
let [l, u] = c({
|
|
248
248
|
from: "",
|
|
249
249
|
to: ""
|
|
250
|
-
}), d = s(""), f =
|
|
250
|
+
}), d = s(""), f = v(r(async (r) => {
|
|
251
251
|
try {
|
|
252
|
-
let a = t.find((e) =>
|
|
252
|
+
let a = t.find((e) => T(e, r.pathname));
|
|
253
253
|
a?.beforeLoad && await a?.beforeLoad(n), e(r), r.pathname !== window.location.pathname && (history.pushState(null, "", r.pathname), d.current = r.pathname), await i(a), a?.afterLoad && await a?.afterLoad(n);
|
|
254
254
|
} catch (t) {
|
|
255
|
-
if (!(t instanceof
|
|
255
|
+
if (!(t instanceof E)) return t;
|
|
256
256
|
history.replaceState(null, "", `${t.url}${t.search || ""}`), e({
|
|
257
257
|
pathname: t.url,
|
|
258
258
|
search: t.search
|
|
@@ -280,7 +280,7 @@ var l = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
|
|
|
280
280
|
}, [l.from, f]);
|
|
281
281
|
return a(() => {
|
|
282
282
|
let e = async (e) => {
|
|
283
|
-
let t =
|
|
283
|
+
let t = w(e.target.location);
|
|
284
284
|
d.current === l.from ? (u({
|
|
285
285
|
from: d.current,
|
|
286
286
|
to: t.pathname
|
|
@@ -288,7 +288,7 @@ var l = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
|
|
|
288
288
|
};
|
|
289
289
|
return window.addEventListener("popstate", e), () => window.removeEventListener("popstate", e);
|
|
290
290
|
}, [l.from, f]), a(() => {
|
|
291
|
-
let e =
|
|
291
|
+
let e = w(window.location);
|
|
292
292
|
f.current(e), d.current = e.pathname;
|
|
293
293
|
}, [f]), {
|
|
294
294
|
blockerState: o(() => l.from && l.to ? "blocked" : l.from ? "charged" : "unblocked", [l]),
|
|
@@ -332,7 +332,7 @@ var l = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
|
|
|
332
332
|
}
|
|
333
333
|
}
|
|
334
334
|
}, [f, d]), m = r(async (t) => {
|
|
335
|
-
let n = e.find((e) =>
|
|
335
|
+
let n = e.find((e) => T(e, t));
|
|
336
336
|
n && await p(n);
|
|
337
337
|
}, [p, e]);
|
|
338
338
|
return {
|
|
@@ -343,12 +343,12 @@ var l = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
|
|
|
343
343
|
isLoading: o[window.location.pathname]
|
|
344
344
|
};
|
|
345
345
|
}, A = (e) => e ? typeof e == "function" ? /* @__PURE__ */ (0, g.jsx)(e, {}) : e : null, j = "error 404. Page not found", M = "*", N = ({ routeList: e, context: t = {} }) => {
|
|
346
|
-
let [n, r] = c(
|
|
346
|
+
let [n, r] = c(w(window.location)), [i, a] = c(t), s = o(() => e.find((e) => e.path === M || T(e, n.pathname)), [n.pathname, e]), { loaderError: l, loaderCache: u, prefetchLoader: d, revalidateCache: f, isLoading: p } = k(e), { blockerState: m, updateLocation: h, updateBlockedRoute: v } = O({
|
|
347
347
|
setLocation: r,
|
|
348
348
|
routeList: e,
|
|
349
349
|
context: i,
|
|
350
350
|
revalidateCache: f
|
|
351
|
-
}), y = o(() => s?.params ?
|
|
351
|
+
}), y = o(() => s?.params ? C(s.params) : {}, [s]), b = o(() => ({
|
|
352
352
|
location: n,
|
|
353
353
|
updateLocation: h,
|
|
354
354
|
params: y,
|
|
@@ -436,4 +436,4 @@ var l = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t
|
|
|
436
436
|
};
|
|
437
437
|
};
|
|
438
438
|
//#endregion
|
|
439
|
-
export { R as Link, N as Router,
|
|
439
|
+
export { R as Link, N as Router, S as createRouter, D as redirect, U as useBeforeUnload, H as useBlocker, V as useLoaderState, B as useLocation, L as useNavigate, z as useParams, W as useRouterContext };
|
|
@@ -3,5 +3,5 @@ import { type ActionsContextValue, type DataContextValue, type NavigationContext
|
|
|
3
3
|
type RouterProviderProps = NavigationContextValue & ActionsContextValue & DataContextValue & {
|
|
4
4
|
children: ReactNode;
|
|
5
5
|
};
|
|
6
|
-
export declare const RouterProvider: ({ children, setContext, context, updateBlockedRoute, updateLocation, location, params, prefetchLoader, loaderCache, blockerState, }: RouterProviderProps) => import("react").JSX.Element;
|
|
6
|
+
export declare const RouterProvider: ({ children, setContext, context, updateBlockedRoute, updateLocation, location, params, prefetchLoader, loaderCache, blockerState, }: RouterProviderProps) => import("react/jsx-runtime").JSX.Element;
|
|
7
7
|
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { type ReactElement } from 'react';
|
|
2
|
-
export declare const renderElement: (Component?: (() => ReactElement) | ReactElement) => import("react").JSX.Element | null;
|
|
2
|
+
export declare const renderElement: (Component?: (() => ReactElement) | ReactElement) => import("react/jsx-runtime").JSX.Element | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clear-react-router",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"description": "A lightweight, type-safe routing library for React applications",
|
|
5
5
|
"author": "Andrew Bubnov",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -34,8 +34,7 @@
|
|
|
34
34
|
"exports": {
|
|
35
35
|
".": {
|
|
36
36
|
"types": "./dist/index.d.ts",
|
|
37
|
-
"import": "./dist/index.js"
|
|
38
|
-
"require": "./dist/index.js"
|
|
37
|
+
"import": "./dist/index.js"
|
|
39
38
|
}
|
|
40
39
|
},
|
|
41
40
|
"devDependencies": {
|