@konstructio/ui
Version:
A set of reusable and customizable React components built for konstruct.io
1,280 lines (1,278 loc) • 38.4 kB
JavaScript
import * as u from "react";
/**
* react-router v7.1.3
*
* Copyright (c) Remix Software Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/
function x(e, t) {
if (e === !1 || e === null || typeof e > "u")
throw new Error(t);
}
function b(e, t) {
if (!e) {
typeof console < "u" && console.warn(t);
try {
throw new Error(t);
} catch {
}
}
}
function j({
pathname: e = "/",
search: t = "",
hash: n = ""
}) {
return t && t !== "?" && (e += t.charAt(0) === "?" ? t : "?" + t), n && n !== "#" && (e += n.charAt(0) === "#" ? n : "#" + n), e;
}
function Y(e) {
let t = {};
if (e) {
let n = e.indexOf("#");
n >= 0 && (t.hash = e.substring(n), e = e.substring(0, n));
let a = e.indexOf("?");
a >= 0 && (t.search = e.substring(a), e = e.substring(0, a)), e && (t.pathname = e);
}
return t;
}
function le(e, t, n = "/") {
return xe(e, t, n, !1);
}
function xe(e, t, n, a) {
let r = typeof t == "string" ? Y(t) : t, l = F(r.pathname || "/", n);
if (l == null)
return null;
let s = oe(e);
Ce(s);
let c = null;
for (let i = 0; c == null && i < s.length; ++i) {
let o = De(l);
c = Fe(
s[i],
o,
a
);
}
return c;
}
function oe(e, t = [], n = [], a = "") {
let r = (l, s, c) => {
let i = {
relativePath: c === void 0 ? l.path || "" : c,
caseSensitive: l.caseSensitive === !0,
childrenIndex: s,
route: l
};
i.relativePath.startsWith("/") && (x(
i.relativePath.startsWith(a),
`Absolute route path "${i.relativePath}" nested under path "${a}" is not valid. An absolute child route path must start with the combined path of all its parent routes.`
), i.relativePath = i.relativePath.slice(a.length));
let o = R([a, i.relativePath]), f = n.concat(i);
l.children && l.children.length > 0 && (x(
// Our types know better, but runtime JS may not!
// @ts-expect-error
l.index !== !0,
`Index routes must not have child routes. Please remove all child routes from route path "${o}".`
), oe(l.children, t, f, o)), !(l.path == null && !l.index) && t.push({
path: o,
score: ke(o, l.index),
routesMeta: f
});
};
return e.forEach((l, s) => {
var c;
if (l.path === "" || !((c = l.path) != null && c.includes("?")))
r(l, s);
else
for (let i of ie(l.path))
r(l, s, i);
}), t;
}
function ie(e) {
let t = e.split("/");
if (t.length === 0) return [];
let [n, ...a] = t, r = n.endsWith("?"), l = n.replace(/\?$/, "");
if (a.length === 0)
return r ? [l, ""] : [l];
let s = ie(a.join("/")), c = [];
return c.push(
...s.map(
(i) => i === "" ? l : [l, i].join("/")
)
), r && c.push(...s), c.map(
(i) => e.startsWith("/") && i === "" ? "/" : i
);
}
function Ce(e) {
e.sort(
(t, n) => t.score !== n.score ? n.score - t.score : $e(
t.routesMeta.map((a) => a.childrenIndex),
n.routesMeta.map((a) => a.childrenIndex)
)
);
}
var Ee = /^:[\w-]+$/, Re = 3, be = 2, Pe = 1, Le = 10, Se = -2, ne = (e) => e === "*";
function ke(e, t) {
let n = e.split("/"), a = n.length;
return n.some(ne) && (a += Se), t && (a += be), n.filter((r) => !ne(r)).reduce(
(r, l) => r + (Ee.test(l) ? Re : l === "" ? Pe : Le),
a
);
}
function $e(e, t) {
return e.length === t.length && e.slice(0, -1).every((a, r) => a === t[r]) ? (
// If two routes are siblings, we should try to match the earlier sibling
// first. This allows people to have fine-grained control over the matching
// behavior by simply putting routes with identical paths in the order they
// want them tried.
e[e.length - 1] - t[t.length - 1]
) : (
// Otherwise, it doesn't really make sense to rank non-siblings by index,
// so they sort equally.
0
);
}
function Fe(e, t, n = !1) {
let { routesMeta: a } = e, r = {}, l = "/", s = [];
for (let c = 0; c < a.length; ++c) {
let i = a[c], o = c === a.length - 1, f = l === "/" ? t : t.slice(l.length) || "/", d = H(
{ path: i.relativePath, caseSensitive: i.caseSensitive, end: o },
f
), m = i.route;
if (!d && o && n && !a[a.length - 1].route.index && (d = H(
{
path: i.relativePath,
caseSensitive: i.caseSensitive,
end: !1
},
f
)), !d)
return null;
Object.assign(r, d.params), s.push({
// TODO: Can this as be avoided?
params: r,
pathname: R([l, d.pathname]),
pathnameBase: Be(
R([l, d.pathnameBase])
),
route: m
}), d.pathnameBase !== "/" && (l = R([l, d.pathnameBase]));
}
return s;
}
function H(e, t) {
typeof e == "string" && (e = { path: e, caseSensitive: !1, end: !0 });
let [n, a] = Ie(
e.path,
e.caseSensitive,
e.end
), r = t.match(n);
if (!r) return null;
let l = r[0], s = l.replace(/(.)\/+$/, "$1"), c = r.slice(1);
return {
params: a.reduce(
(o, { paramName: f, isOptional: d }, m) => {
if (f === "*") {
let v = c[m] || "";
s = l.slice(0, l.length - v.length).replace(/(.)\/+$/, "$1");
}
const p = c[m];
return d && !p ? o[f] = void 0 : o[f] = (p || "").replace(/%2F/g, "/"), o;
},
{}
),
pathname: l,
pathnameBase: s,
pattern: e
};
}
function Ie(e, t = !1, n = !0) {
b(
e === "*" || !e.endsWith("*") || e.endsWith("/*"),
`Route path "${e}" will be treated as if it were "${e.replace(/\*$/, "/*")}" because the \`*\` character must always follow a \`/\` in the pattern. To get rid of this warning, please change the route path to "${e.replace(/\*$/, "/*")}".`
);
let a = [], r = "^" + e.replace(/\/*\*?$/, "").replace(/^\/*/, "/").replace(/[\\.*+^${}|()[\]]/g, "\\$&").replace(
/\/:([\w-]+)(\?)?/g,
(s, c, i) => (a.push({ paramName: c, isOptional: i != null }), i ? "/?([^\\/]+)?" : "/([^\\/]+)")
);
return e.endsWith("*") ? (a.push({ paramName: "*" }), r += e === "*" || e === "/*" ? "(.*)$" : "(?:\\/(.+)|\\/*)$") : n ? r += "\\/*$" : e !== "" && e !== "/" && (r += "(?:(?=\\/|$))"), [new RegExp(r, t ? void 0 : "i"), a];
}
function De(e) {
try {
return e.split("/").map((t) => decodeURIComponent(t).replace(/\//g, "%2F")).join("/");
} catch (t) {
return b(
!1,
`The URL path "${e}" could not be decoded because it is a malformed URL segment. This is probably due to a bad percent encoding (${t}).`
), e;
}
}
function F(e, t) {
if (t === "/") return e;
if (!e.toLowerCase().startsWith(t.toLowerCase()))
return null;
let n = t.endsWith("/") ? t.length - 1 : t.length, a = e.charAt(n);
return a && a !== "/" ? null : e.slice(n) || "/";
}
function Ne(e, t = "/") {
let {
pathname: n,
search: a = "",
hash: r = ""
} = typeof e == "string" ? Y(e) : e;
return {
pathname: n ? n.startsWith("/") ? n : Te(n, t) : t,
search: Me(a),
hash: We(r)
};
}
function Te(e, t) {
let n = t.replace(/\/+$/, "").split("/");
return e.split("/").forEach((r) => {
r === ".." ? n.length > 1 && n.pop() : r !== "." && n.push(r);
}), n.length > 1 ? n.join("/") : "/";
}
function J(e, t, n, a) {
return `Cannot include a '${e}' character in a manually specified \`to.${t}\` field [${JSON.stringify(
a
)}]. Please separate it out to the \`to.${n}\` field. Alternatively you may provide the full path as a string in <Link to="..."> and the router will parse it for you.`;
}
function Ae(e) {
return e.filter(
(t, n) => n === 0 || t.route.path && t.route.path.length > 0
);
}
function ue(e) {
let t = Ae(e);
return t.map(
(n, a) => a === t.length - 1 ? n.pathname : n.pathnameBase
);
}
function se(e, t, n, a = !1) {
let r;
typeof e == "string" ? r = Y(e) : (r = { ...e }, x(
!r.pathname || !r.pathname.includes("?"),
J("?", "pathname", "search", r)
), x(
!r.pathname || !r.pathname.includes("#"),
J("#", "pathname", "hash", r)
), x(
!r.search || !r.search.includes("#"),
J("#", "search", "hash", r)
));
let l = e === "" || r.pathname === "", s = l ? "/" : r.pathname, c;
if (s == null)
c = n;
else {
let d = t.length - 1;
if (!a && s.startsWith("..")) {
let m = s.split("/");
for (; m[0] === ".."; )
m.shift(), d -= 1;
r.pathname = m.join("/");
}
c = d >= 0 ? t[d] : "/";
}
let i = Ne(r, c), o = s && s !== "/" && s.endsWith("/"), f = (l || s === ".") && n.endsWith("/");
return !i.pathname.endsWith("/") && (o || f) && (i.pathname += "/"), i;
}
var R = (e) => e.join("/").replace(/\/\/+/g, "/"), Be = (e) => e.replace(/\/+$/, "").replace(/^\/*/, "/"), Me = (e) => !e || e === "?" ? "" : e.startsWith("?") ? e : "?" + e, We = (e) => !e || e === "#" ? "" : e.startsWith("#") ? e : "#" + e;
function Oe(e) {
return e != null && typeof e.status == "number" && typeof e.statusText == "string" && typeof e.internal == "boolean" && "data" in e;
}
var ce = [
"POST",
"PUT",
"PATCH",
"DELETE"
];
new Set(
ce
);
var Ue = [
"GET",
...ce
];
new Set(Ue);
var D = u.createContext(null);
D.displayName = "DataRouter";
var _ = u.createContext(null);
_.displayName = "DataRouterState";
var fe = u.createContext({
isTransitioning: !1
});
fe.displayName = "ViewTransition";
var He = u.createContext(
/* @__PURE__ */ new Map()
);
He.displayName = "Fetchers";
var _e = u.createContext(null);
_e.displayName = "Await";
var P = u.createContext(
null
);
P.displayName = "Navigation";
var q = u.createContext(
null
);
q.displayName = "Location";
var L = u.createContext({
outlet: null,
matches: [],
isDataRoute: !1
});
L.displayName = "Route";
var G = u.createContext(null);
G.displayName = "RouteError";
function Ve(e, { relative: t } = {}) {
x(
V(),
// TODO: This error is probably because they somehow have 2 versions of the
// router loaded. We can help them understand how to avoid that.
"useHref() may be used only in the context of a <Router> component."
);
let { basename: n, navigator: a } = u.useContext(P), { hash: r, pathname: l, search: s } = A(e, { relative: t }), c = l;
return n !== "/" && (c = l === "/" ? n : R([n, l])), a.createHref({ pathname: c, search: s, hash: r });
}
function V() {
return u.useContext(q) != null;
}
function k() {
return x(
V(),
// TODO: This error is probably because they somehow have 2 versions of the
// router loaded. We can help them understand how to avoid that.
"useLocation() may be used only in the context of a <Router> component."
), u.useContext(q).location;
}
var de = "You should call navigate() in a React.useEffect(), not when your component is first rendered.";
function he(e) {
u.useContext(P).static || u.useLayoutEffect(e);
}
function ze() {
let { isDataRoute: e } = u.useContext(L);
return e ? rt() : Je();
}
function Je() {
x(
V(),
// TODO: This error is probably because they somehow have 2 versions of the
// router loaded. We can help them understand how to avoid that.
"useNavigate() may be used only in the context of a <Router> component."
);
let e = u.useContext(D), { basename: t, navigator: n } = u.useContext(P), { matches: a } = u.useContext(L), { pathname: r } = k(), l = JSON.stringify(ue(a)), s = u.useRef(!1);
return he(() => {
s.current = !0;
}), u.useCallback(
(i, o = {}) => {
if (b(s.current, de), !s.current) return;
if (typeof i == "number") {
n.go(i);
return;
}
let f = se(
i,
JSON.parse(l),
r,
o.relative === "path"
);
e == null && t !== "/" && (f.pathname = f.pathname === "/" ? t : R([t, f.pathname])), (o.replace ? n.replace : n.push)(
f,
o.state,
o
);
},
[
t,
n,
l,
r,
e
]
);
}
u.createContext(null);
function A(e, { relative: t } = {}) {
let { matches: n } = u.useContext(L), { pathname: a } = k(), r = JSON.stringify(ue(n));
return u.useMemo(
() => se(
e,
JSON.parse(r),
a,
t === "path"
),
[e, r, a, t]
);
}
function Ke(e, t, n, a) {
x(
V(),
// TODO: This error is probably because they somehow have 2 versions of the
// router loaded. We can help them understand how to avoid that.
"useRoutes() may be used only in the context of a <Router> component."
);
let { navigator: r } = u.useContext(P), { matches: l } = u.useContext(L), s = l[l.length - 1], c = s ? s.params : {}, i = s ? s.pathname : "/", o = s ? s.pathnameBase : "/", f = s && s.route;
{
let h = f && f.path || "";
me(
i,
!f || h.endsWith("*") || h.endsWith("*?"),
`You rendered descendant <Routes> (or called \`useRoutes()\`) at "${i}" (under <Route path="${h}">) but the parent route path has no trailing "*". This means if you navigate deeper, the parent won't match anymore and therefore the child routes will never render.
Please change the parent <Route path="${h}"> to <Route path="${h === "/" ? "*" : `${h}/*`}">.`
);
}
let d = k(), m;
m = d;
let p = m.pathname || "/", v = p;
if (o !== "/") {
let h = o.replace(/^\//, "").split("/");
v = "/" + p.replace(/^\//, "").split("/").slice(h.length).join("/");
}
let g = le(e, { pathname: v });
return b(
f || g != null,
`No routes matched location "${m.pathname}${m.search}${m.hash}" `
), b(
g == null || g[g.length - 1].route.element !== void 0 || g[g.length - 1].route.Component !== void 0 || g[g.length - 1].route.lazy !== void 0,
`Matched leaf route at location "${m.pathname}${m.search}${m.hash}" does not have an element or Component. This means it will render an <Outlet /> with a null value by default resulting in an "empty" page.`
), Xe(
g && g.map(
(h) => Object.assign({}, h, {
params: Object.assign({}, c, h.params),
pathname: R([
o,
// Re-encode pathnames that were decoded inside matchRoutes
r.encodeLocation ? r.encodeLocation(h.pathname).pathname : h.pathname
]),
pathnameBase: h.pathnameBase === "/" ? o : R([
o,
// Re-encode pathnames that were decoded inside matchRoutes
r.encodeLocation ? r.encodeLocation(h.pathnameBase).pathname : h.pathnameBase
])
})
),
l,
n,
a
);
}
function je() {
let e = nt(), t = Oe(e) ? `${e.status} ${e.statusText}` : e instanceof Error ? e.message : JSON.stringify(e), n = e instanceof Error ? e.stack : null, a = "rgba(200,200,200, 0.5)", r = { padding: "0.5rem", backgroundColor: a }, l = { padding: "2px 4px", backgroundColor: a }, s = null;
return console.error(
"Error handled by React Router default ErrorBoundary:",
e
), s = /* @__PURE__ */ u.createElement(u.Fragment, null, /* @__PURE__ */ u.createElement("p", null, "💿 Hey developer 👋"), /* @__PURE__ */ u.createElement("p", null, "You can provide a way better UX than this when your app throws errors by providing your own ", /* @__PURE__ */ u.createElement("code", { style: l }, "ErrorBoundary"), " or", " ", /* @__PURE__ */ u.createElement("code", { style: l }, "errorElement"), " prop on your route.")), /* @__PURE__ */ u.createElement(u.Fragment, null, /* @__PURE__ */ u.createElement("h2", null, "Unexpected Application Error!"), /* @__PURE__ */ u.createElement("h3", { style: { fontStyle: "italic" } }, t), n ? /* @__PURE__ */ u.createElement("pre", { style: r }, n) : null, s);
}
var Ye = /* @__PURE__ */ u.createElement(je, null), qe = class extends u.Component {
constructor(e) {
super(e), this.state = {
location: e.location,
revalidation: e.revalidation,
error: e.error
};
}
static getDerivedStateFromError(e) {
return { error: e };
}
static getDerivedStateFromProps(e, t) {
return t.location !== e.location || t.revalidation !== "idle" && e.revalidation === "idle" ? {
error: e.error,
location: e.location,
revalidation: e.revalidation
} : {
error: e.error !== void 0 ? e.error : t.error,
location: t.location,
revalidation: e.revalidation || t.revalidation
};
}
componentDidCatch(e, t) {
console.error(
"React Router caught the following error during render",
e,
t
);
}
render() {
return this.state.error !== void 0 ? /* @__PURE__ */ u.createElement(L.Provider, { value: this.props.routeContext }, /* @__PURE__ */ u.createElement(
G.Provider,
{
value: this.state.error,
children: this.props.component
}
)) : this.props.children;
}
};
function Ge({ routeContext: e, match: t, children: n }) {
let a = u.useContext(D);
return a && a.static && a.staticContext && (t.route.errorElement || t.route.ErrorBoundary) && (a.staticContext._deepestRenderedBoundaryId = t.route.id), /* @__PURE__ */ u.createElement(L.Provider, { value: e }, n);
}
function Xe(e, t = [], n = null, a = null) {
if (e == null) {
if (!n)
return null;
if (n.errors)
e = n.matches;
else if (t.length === 0 && !n.initialized && n.matches.length > 0)
e = n.matches;
else
return null;
}
let r = e, l = n == null ? void 0 : n.errors;
if (l != null) {
let i = r.findIndex(
(o) => o.route.id && (l == null ? void 0 : l[o.route.id]) !== void 0
);
x(
i >= 0,
`Could not find a matching route for errors on route IDs: ${Object.keys(
l
).join(",")}`
), r = r.slice(
0,
Math.min(r.length, i + 1)
);
}
let s = !1, c = -1;
if (n)
for (let i = 0; i < r.length; i++) {
let o = r[i];
if ((o.route.HydrateFallback || o.route.hydrateFallbackElement) && (c = i), o.route.id) {
let { loaderData: f, errors: d } = n, m = o.route.loader && !f.hasOwnProperty(o.route.id) && (!d || d[o.route.id] === void 0);
if (o.route.lazy || m) {
s = !0, c >= 0 ? r = r.slice(0, c + 1) : r = [r[0]];
break;
}
}
}
return r.reduceRight((i, o, f) => {
let d, m = !1, p = null, v = null;
n && (d = l && o.route.id ? l[o.route.id] : void 0, p = o.route.errorElement || Ye, s && (c < 0 && f === 0 ? (me(
"route-fallback",
!1,
"No `HydrateFallback` element provided to render during initial hydration"
), m = !0, v = null) : c === f && (m = !0, v = o.route.hydrateFallbackElement || null)));
let g = t.concat(r.slice(0, f + 1)), y = () => {
let h;
return d ? h = p : m ? h = v : o.route.Component ? h = /* @__PURE__ */ u.createElement(o.route.Component, null) : o.route.element ? h = o.route.element : h = i, /* @__PURE__ */ u.createElement(
Ge,
{
match: o,
routeContext: {
outlet: i,
matches: g,
isDataRoute: n != null
},
children: h
}
);
};
return n && (o.route.ErrorBoundary || o.route.errorElement || f === 0) ? /* @__PURE__ */ u.createElement(
qe,
{
location: n.location,
revalidation: n.revalidation,
component: p,
error: d,
children: y(),
routeContext: { outlet: null, matches: g, isDataRoute: !0 }
}
) : y();
}, null);
}
function X(e) {
return `${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`;
}
function Qe(e) {
let t = u.useContext(D);
return x(t, X(e)), t;
}
function Ze(e) {
let t = u.useContext(_);
return x(t, X(e)), t;
}
function et(e) {
let t = u.useContext(L);
return x(t, X(e)), t;
}
function Q(e) {
let t = et(e), n = t.matches[t.matches.length - 1];
return x(
n.route.id,
`${e} can only be used on routes that contain a unique "id"`
), n.route.id;
}
function tt() {
return Q(
"useRouteId"
/* UseRouteId */
);
}
function nt() {
var a;
let e = u.useContext(G), t = Ze(
"useRouteError"
/* UseRouteError */
), n = Q(
"useRouteError"
/* UseRouteError */
);
return e !== void 0 ? e : (a = t.errors) == null ? void 0 : a[n];
}
function rt() {
let { router: e } = Qe(
"useNavigate"
/* UseNavigateStable */
), t = Q(
"useNavigate"
/* UseNavigateStable */
), n = u.useRef(!1);
return he(() => {
n.current = !0;
}), u.useCallback(
async (r, l = {}) => {
b(n.current, de), n.current && (typeof r == "number" ? e.navigate(r) : await e.navigate(r, { fromRouteId: t, ...l }));
},
[e, t]
);
}
var re = {};
function me(e, t, n) {
!t && !re[e] && (re[e] = !0, b(!1, n));
}
u.memo(at);
function at({
routes: e,
future: t,
state: n
}) {
return Ke(e, void 0, n, t);
}
var O = "get", U = "application/x-www-form-urlencoded";
function z(e) {
return e != null && typeof e.tagName == "string";
}
function lt(e) {
return z(e) && e.tagName.toLowerCase() === "button";
}
function ot(e) {
return z(e) && e.tagName.toLowerCase() === "form";
}
function it(e) {
return z(e) && e.tagName.toLowerCase() === "input";
}
function ut(e) {
return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
}
function st(e, t) {
return e.button === 0 && // Ignore everything but left clicks
(!t || t === "_self") && // Let browser handle "target=_blank" etc.
!ut(e);
}
var W = null;
function ct() {
if (W === null)
try {
new FormData(
document.createElement("form"),
// @ts-expect-error if FormData supports the submitter parameter, this will throw
0
), W = !1;
} catch {
W = !0;
}
return W;
}
var ft = /* @__PURE__ */ new Set([
"application/x-www-form-urlencoded",
"multipart/form-data",
"text/plain"
]);
function K(e) {
return e != null && !ft.has(e) ? (b(
!1,
`"${e}" is not a valid \`encType\` for \`<Form>\`/\`<fetcher.Form>\` and will default to "${U}"`
), null) : e;
}
function dt(e, t) {
let n, a, r, l, s;
if (ot(e)) {
let c = e.getAttribute("action");
a = c ? F(c, t) : null, n = e.getAttribute("method") || O, r = K(e.getAttribute("enctype")) || U, l = new FormData(e);
} else if (lt(e) || it(e) && (e.type === "submit" || e.type === "image")) {
let c = e.form;
if (c == null)
throw new Error(
'Cannot submit a <button> or <input type="submit"> without a <form>'
);
let i = e.getAttribute("formaction") || c.getAttribute("action");
if (a = i ? F(i, t) : null, n = e.getAttribute("formmethod") || c.getAttribute("method") || O, r = K(e.getAttribute("formenctype")) || K(c.getAttribute("enctype")) || U, l = new FormData(c, e), !ct()) {
let { name: o, type: f, value: d } = e;
if (f === "image") {
let m = o ? `${o}.` : "";
l.append(`${m}x`, "0"), l.append(`${m}y`, "0");
} else o && l.append(o, d);
}
} else {
if (z(e))
throw new Error(
'Cannot submit element that is not <form>, <button>, or <input type="submit|image">'
);
n = O, a = null, r = U, s = e;
}
return l && r === "text/plain" && (s = l, l = void 0), { action: a, method: n.toLowerCase(), encType: r, formData: l, body: s };
}
function Z(e, t) {
if (e === !1 || e === null || typeof e > "u")
throw new Error(t);
}
async function ht(e, t) {
if (e.id in t)
return t[e.id];
try {
let n = await import(
/* @vite-ignore */
/* webpackIgnore: true */
e.module
);
return t[e.id] = n, n;
} catch (n) {
return console.error(
`Error loading route module \`${e.module}\`, reloading page...`
), console.error(n), window.location.reload(), new Promise(() => {
});
}
}
function mt(e) {
return e == null ? !1 : e.href == null ? e.rel === "preload" && typeof e.imageSrcSet == "string" && typeof e.imageSizes == "string" : typeof e.rel == "string" && typeof e.href == "string";
}
async function pt(e, t, n) {
let a = await Promise.all(
e.map(async (r) => {
let l = t.routes[r.route.id];
if (l) {
let s = await ht(l, n);
return s.links ? s.links() : [];
}
return [];
})
);
return wt(
a.flat(1).filter(mt).filter((r) => r.rel === "stylesheet" || r.rel === "preload").map(
(r) => r.rel === "stylesheet" ? { ...r, rel: "prefetch", as: "style" } : { ...r, rel: "prefetch" }
)
);
}
function ae(e, t, n, a, r, l) {
let s = (i, o) => n[o] ? i.route.id !== n[o].route.id : !0, c = (i, o) => {
var f;
return (
// param change, /users/123 -> /users/456
n[o].pathname !== i.pathname || // splat param changed, which is not present in match.path
// e.g. /files/images/avatar.jpg -> files/finances.xls
((f = n[o].route.path) == null ? void 0 : f.endsWith("*")) && n[o].params["*"] !== i.params["*"]
);
};
return l === "assets" ? t.filter(
(i, o) => s(i, o) || c(i, o)
) : l === "data" ? t.filter((i, o) => {
var d;
let f = a.routes[i.route.id];
if (!f || !f.hasLoader)
return !1;
if (s(i, o) || c(i, o))
return !0;
if (i.route.shouldRevalidate) {
let m = i.route.shouldRevalidate({
currentUrl: new URL(
r.pathname + r.search + r.hash,
window.origin
),
currentParams: ((d = n[0]) == null ? void 0 : d.params) || {},
nextUrl: new URL(e, window.origin),
nextParams: i.params,
defaultShouldRevalidate: !0
});
if (typeof m == "boolean")
return m;
}
return !0;
}) : [];
}
function gt(e, t) {
return vt(
e.map((n) => {
let a = t.routes[n.route.id];
if (!a) return [];
let r = [a.module];
return a.imports && (r = r.concat(a.imports)), r;
}).flat(1)
);
}
function vt(e) {
return [...new Set(e)];
}
function yt(e) {
let t = {}, n = Object.keys(e).sort();
for (let a of n)
t[a] = e[a];
return t;
}
function wt(e, t) {
let n = /* @__PURE__ */ new Set();
return new Set(t), e.reduce((a, r) => {
let l = JSON.stringify(yt(r));
return n.has(l) || (n.add(l), a.push({ key: l, link: r })), a;
}, []);
}
function xt(e) {
let t = typeof e == "string" ? new URL(
e,
// This can be called during the SSR flow via PrefetchPageLinksImpl so
// don't assume window is available
typeof window > "u" ? "server://singlefetch/" : window.location.origin
) : e;
return t.pathname === "/" ? t.pathname = "_root.data" : t.pathname = `${t.pathname.replace(/\/$/, "")}.data`, t;
}
function Ct() {
let e = u.useContext(D);
return Z(
e,
"You must render this element inside a <DataRouterContext.Provider> element"
), e;
}
function Et() {
let e = u.useContext(_);
return Z(
e,
"You must render this element inside a <DataRouterStateContext.Provider> element"
), e;
}
var ee = u.createContext(void 0);
ee.displayName = "FrameworkContext";
function pe() {
let e = u.useContext(ee);
return Z(
e,
"You must render this element inside a <HydratedRouter> element"
), e;
}
function Rt(e, t) {
let n = u.useContext(ee), [a, r] = u.useState(!1), [l, s] = u.useState(!1), { onFocus: c, onBlur: i, onMouseEnter: o, onMouseLeave: f, onTouchStart: d } = t, m = u.useRef(null);
u.useEffect(() => {
if (e === "render" && s(!0), e === "viewport") {
let g = (h) => {
h.forEach((C) => {
s(C.isIntersecting);
});
}, y = new IntersectionObserver(g, { threshold: 0.5 });
return m.current && y.observe(m.current), () => {
y.disconnect();
};
}
}, [e]), u.useEffect(() => {
if (a) {
let g = setTimeout(() => {
s(!0);
}, 100);
return () => {
clearTimeout(g);
};
}
}, [a]);
let p = () => {
r(!0);
}, v = () => {
r(!1), s(!1);
};
return n ? e !== "intent" ? [l, m, {}] : [
l,
m,
{
onFocus: T(c, p),
onBlur: T(i, v),
onMouseEnter: T(o, p),
onMouseLeave: T(f, v),
onTouchStart: T(d, p)
}
] : [!1, m, {}];
}
function T(e, t) {
return (n) => {
e && e(n), n.defaultPrevented || t(n);
};
}
function bt({
page: e,
...t
}) {
let { router: n } = Ct(), a = u.useMemo(
() => le(n.routes, e, n.basename),
[n.routes, e, n.basename]
);
return a ? /* @__PURE__ */ u.createElement(Lt, { page: e, matches: a, ...t }) : null;
}
function Pt(e) {
let { manifest: t, routeModules: n } = pe(), [a, r] = u.useState([]);
return u.useEffect(() => {
let l = !1;
return pt(e, t, n).then(
(s) => {
l || r(s);
}
), () => {
l = !0;
};
}, [e, t, n]), a;
}
function Lt({
page: e,
matches: t,
...n
}) {
let a = k(), { manifest: r, routeModules: l } = pe(), { loaderData: s, matches: c } = Et(), i = u.useMemo(
() => ae(
e,
t,
c,
r,
a,
"data"
),
[e, t, c, r, a]
), o = u.useMemo(
() => ae(
e,
t,
c,
r,
a,
"assets"
),
[e, t, c, r, a]
), f = u.useMemo(() => {
if (e === a.pathname + a.search + a.hash)
return [];
let p = /* @__PURE__ */ new Set(), v = !1;
if (t.forEach((y) => {
var C;
let h = r.routes[y.route.id];
!h || !h.hasLoader || (!i.some((w) => w.route.id === y.route.id) && y.route.id in s && ((C = l[y.route.id]) != null && C.shouldRevalidate) || h.hasClientLoader ? v = !0 : p.add(y.route.id));
}), p.size === 0)
return [];
let g = xt(e);
return v && p.size > 0 && g.searchParams.set(
"_routes",
t.filter((y) => p.has(y.route.id)).map((y) => y.route.id).join(",")
), [g.pathname + g.search];
}, [
s,
a,
r,
i,
t,
e,
l
]), d = u.useMemo(
() => gt(o, r),
[o, r]
), m = Pt(o);
return /* @__PURE__ */ u.createElement(u.Fragment, null, f.map((p) => /* @__PURE__ */ u.createElement("link", { key: p, rel: "prefetch", as: "fetch", href: p, ...n })), d.map((p) => /* @__PURE__ */ u.createElement("link", { key: p, rel: "modulepreload", href: p, ...n })), m.map(({ key: p, link: v }) => (
// these don't spread `linkProps` because they are full link descriptors
// already with their own props
/* @__PURE__ */ u.createElement("link", { key: p, ...v })
)));
}
function St(...e) {
return (t) => {
e.forEach((n) => {
typeof n == "function" ? n(t) : n != null && (n.current = t);
});
};
}
var ge = typeof window < "u" && typeof window.document < "u" && typeof window.document.createElement < "u";
try {
ge && (window.__reactRouterVersion = "7.1.3");
} catch {
}
var ve = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i, ye = u.forwardRef(
function({
onClick: t,
discover: n = "render",
prefetch: a = "none",
relative: r,
reloadDocument: l,
replace: s,
state: c,
target: i,
to: o,
preventScrollReset: f,
viewTransition: d,
...m
}, p) {
let { basename: v } = u.useContext(P), g = typeof o == "string" && ve.test(o), y, h = !1;
if (typeof o == "string" && g && (y = o, ge))
try {
let E = new URL(window.location.href), I = o.startsWith("//") ? new URL(E.protocol + o) : new URL(o), te = F(I.pathname, v);
I.origin === E.origin && te != null ? o = te + I.search + I.hash : h = !0;
} catch {
b(
!1,
`<Link to="${o}"> contains an invalid URL which will probably break when clicked - please update to a valid URL path.`
);
}
let C = Ve(o, { relative: r }), [w, S, $] = Rt(
a,
m
), B = It(o, {
replace: s,
state: c,
target: i,
preventScrollReset: f,
relative: r,
viewTransition: d
});
function N(E) {
t && t(E), E.defaultPrevented || B(E);
}
let M = (
// eslint-disable-next-line jsx-a11y/anchor-has-content
/* @__PURE__ */ u.createElement(
"a",
{
...m,
...$,
href: y || C,
onClick: h || l ? t : N,
ref: St(p, S),
target: i,
"data-discover": !g && n === "render" ? "true" : void 0
}
)
);
return w && !g ? /* @__PURE__ */ u.createElement(u.Fragment, null, M, /* @__PURE__ */ u.createElement(bt, { page: C })) : M;
}
);
ye.displayName = "Link";
var kt = u.forwardRef(
function({
"aria-current": t = "page",
caseSensitive: n = !1,
className: a = "",
end: r = !1,
style: l,
to: s,
viewTransition: c,
children: i,
...o
}, f) {
let d = A(s, { relative: o.relative }), m = k(), p = u.useContext(_), { navigator: v, basename: g } = u.useContext(P), y = p != null && // Conditional usage is OK here because the usage of a data router is static
// eslint-disable-next-line react-hooks/rules-of-hooks
Bt(d) && c === !0, h = v.encodeLocation ? v.encodeLocation(d).pathname : d.pathname, C = m.pathname, w = p && p.navigation && p.navigation.location ? p.navigation.location.pathname : null;
n || (C = C.toLowerCase(), w = w ? w.toLowerCase() : null, h = h.toLowerCase()), w && g && (w = F(w, g) || w);
const S = h !== "/" && h.endsWith("/") ? h.length - 1 : h.length;
let $ = C === h || !r && C.startsWith(h) && C.charAt(S) === "/", B = w != null && (w === h || !r && w.startsWith(h) && w.charAt(h.length) === "/"), N = {
isActive: $,
isPending: B,
isTransitioning: y
}, M = $ ? t : void 0, E;
typeof a == "function" ? E = a(N) : E = [
a,
$ ? "active" : null,
B ? "pending" : null,
y ? "transitioning" : null
].filter(Boolean).join(" ");
let I = typeof l == "function" ? l(N) : l;
return /* @__PURE__ */ u.createElement(
ye,
{
...o,
"aria-current": M,
className: E,
ref: f,
style: I,
to: s,
viewTransition: c
},
typeof i == "function" ? i(N) : i
);
}
);
kt.displayName = "NavLink";
var $t = u.forwardRef(
({
discover: e = "render",
fetcherKey: t,
navigate: n,
reloadDocument: a,
replace: r,
state: l,
method: s = O,
action: c,
onSubmit: i,
relative: o,
preventScrollReset: f,
viewTransition: d,
...m
}, p) => {
let v = Tt(), g = At(c, { relative: o }), y = s.toLowerCase() === "get" ? "get" : "post", h = typeof c == "string" && ve.test(c), C = (w) => {
if (i && i(w), w.defaultPrevented) return;
w.preventDefault();
let S = w.nativeEvent.submitter, $ = (S == null ? void 0 : S.getAttribute("formmethod")) || s;
v(S || w.currentTarget, {
fetcherKey: t,
method: $,
navigate: n,
replace: r,
state: l,
relative: o,
preventScrollReset: f,
viewTransition: d
});
};
return /* @__PURE__ */ u.createElement(
"form",
{
ref: p,
method: y,
action: g,
onSubmit: a ? i : C,
...m,
"data-discover": !h && e === "render" ? "true" : void 0
}
);
}
);
$t.displayName = "Form";
function Ft(e) {
return `${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`;
}
function we(e) {
let t = u.useContext(D);
return x(t, Ft(e)), t;
}
function It(e, {
target: t,
replace: n,
state: a,
preventScrollReset: r,
relative: l,
viewTransition: s
} = {}) {
let c = ze(), i = k(), o = A(e, { relative: l });
return u.useCallback(
(f) => {
if (st(f, t)) {
f.preventDefault();
let d = n !== void 0 ? n : j(i) === j(o);
c(e, {
replace: d,
state: a,
preventScrollReset: r,
relative: l,
viewTransition: s
});
}
},
[
i,
c,
o,
n,
a,
t,
e,
r,
l,
s
]
);
}
var Dt = 0, Nt = () => `__${String(++Dt)}__`;
function Tt() {
let { router: e } = we(
"useSubmit"
/* UseSubmit */
), { basename: t } = u.useContext(P), n = tt();
return u.useCallback(
async (a, r = {}) => {
let { action: l, method: s, encType: c, formData: i, body: o } = dt(
a,
t
);
if (r.navigate === !1) {
let f = r.fetcherKey || Nt();
await e.fetch(f, n, r.action || l, {
preventScrollReset: r.preventScrollReset,
formData: i,
body: o,
formMethod: r.method || s,
formEncType: r.encType || c,
flushSync: r.flushSync
});
} else
await e.navigate(r.action || l, {
preventScrollReset: r.preventScrollReset,
formData: i,
body: o,
formMethod: r.method || s,
formEncType: r.encType || c,
replace: r.replace,
state: r.state,
fromRouteId: n,
flushSync: r.flushSync,
viewTransition: r.viewTransition
});
},
[e, t, n]
);
}
function At(e, { relative: t } = {}) {
let { basename: n } = u.useContext(P), a = u.useContext(L);
x(a, "useFormAction must be used inside a RouteContext");
let [r] = a.matches.slice(-1), l = { ...A(e || ".", { relative: t }) }, s = k();
if (e == null) {
l.search = s.search;
let c = new URLSearchParams(l.search), i = c.getAll("index");
if (i.some((f) => f === "")) {
c.delete("index"), i.filter((d) => d).forEach((d) => c.append("index", d));
let f = c.toString();
l.search = f ? `?${f}` : "";
}
}
return (!e || e === ".") && r.route.index && (l.search = l.search ? l.search.replace(/^\?/, "?index&") : "?index"), n !== "/" && (l.pathname = l.pathname === "/" ? n : R([n, l.pathname])), j(l);
}
function Bt(e, t = {}) {
let n = u.useContext(fe);
x(
n != null,
"`useViewTransitionState` must be used within `react-router-dom`'s `RouterProvider`. Did you accidentally import `RouterProvider` from `react-router`?"
);
let { basename: a } = we(
"useViewTransitionState"
/* useViewTransitionState */
), r = A(e, { relative: t.relative });
if (!n.isTransitioning)
return !1;
let l = F(n.currentLocation.pathname, a) || n.currentLocation.pathname, s = F(n.nextLocation.pathname, a) || n.nextLocation.pathname;
return H(r.pathname, s) != null || H(r.pathname, l) != null;
}
new TextEncoder();
const Mt = () => {
try {
return k(), {
isInsideRouter: !0
};
} catch {
return {
isInsideRouter: !1
};
}
};
export {
ye as L,
Mt as u
};