@konstructio/ui
Version:
A set of reusable and customizable React components built for konstruct.io
1,281 lines (1,279 loc) • 38.8 kB
JavaScript
import * as u from "react";
/**
* react-router v7.6.0
*
* 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 C(e, t) {
if (e === !1 || e === null || typeof e > "u")
throw new Error(t);
}
function P(e, t) {
if (!e) {
typeof console < "u" && console.warn(t);
try {
throw new Error(t);
} catch {
}
}
}
function K({
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 l = e.indexOf("?");
l >= 0 && (t.search = e.substring(l), e = e.substring(0, l)), e && (t.pathname = e);
}
return t;
}
function le(e, t, n = "/") {
return Ce(e, t, n, !1);
}
function Ce(e, t, n, l) {
let r = typeof t == "string" ? Y(t) : t, a = S(r.pathname || "/", n);
if (a == null)
return null;
let c = oe(e);
Ee(c);
let s = null;
for (let o = 0; s == null && o < c.length; ++o) {
let i = De(a);
s = Ie(
c[o],
i,
l
);
}
return s;
}
function oe(e, t = [], n = [], l = "") {
let r = (a, c, s) => {
let o = {
relativePath: s === void 0 ? a.path || "" : s,
caseSensitive: a.caseSensitive === !0,
childrenIndex: c,
route: a
};
o.relativePath.startsWith("/") && (C(
o.relativePath.startsWith(l),
`Absolute route path "${o.relativePath}" nested under path "${l}" is not valid. An absolute child route path must start with the combined path of all its parent routes.`
), o.relativePath = o.relativePath.slice(l.length));
let i = b([l, o.relativePath]), f = n.concat(o);
a.children && a.children.length > 0 && (C(
// Our types know better, but runtime JS may not!
// @ts-expect-error
a.index !== !0,
`Index routes must not have child routes. Please remove all child routes from route path "${i}".`
), oe(a.children, t, f, i)), !(a.path == null && !a.index) && t.push({
path: i,
score: $e(i, a.index),
routesMeta: f
});
};
return e.forEach((a, c) => {
var s;
if (a.path === "" || !((s = a.path) != null && s.includes("?")))
r(a, c);
else
for (let o of ie(a.path))
r(a, c, o);
}), t;
}
function ie(e) {
let t = e.split("/");
if (t.length === 0) return [];
let [n, ...l] = t, r = n.endsWith("?"), a = n.replace(/\?$/, "");
if (l.length === 0)
return r ? [a, ""] : [a];
let c = ie(l.join("/")), s = [];
return s.push(
...c.map(
(o) => o === "" ? a : [a, o].join("/")
)
), r && s.push(...c), s.map(
(o) => e.startsWith("/") && o === "" ? "/" : o
);
}
function Ee(e) {
e.sort(
(t, n) => t.score !== n.score ? n.score - t.score : Fe(
t.routesMeta.map((l) => l.childrenIndex),
n.routesMeta.map((l) => l.childrenIndex)
)
);
}
var Re = /^:[\w-]+$/, be = 3, Pe = 2, Le = 1, ke = 10, Se = -2, ne = (e) => e === "*";
function $e(e, t) {
let n = e.split("/"), l = n.length;
return n.some(ne) && (l += Se), t && (l += Pe), n.filter((r) => !ne(r)).reduce(
(r, a) => r + (Re.test(a) ? be : a === "" ? Le : ke),
l
);
}
function Fe(e, t) {
return e.length === t.length && e.slice(0, -1).every((l, r) => l === 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 Ie(e, t, n = !1) {
let { routesMeta: l } = e, r = {}, a = "/", c = [];
for (let s = 0; s < l.length; ++s) {
let o = l[s], i = s === l.length - 1, f = a === "/" ? t : t.slice(a.length) || "/", d = H(
{ path: o.relativePath, caseSensitive: o.caseSensitive, end: i },
f
), h = o.route;
if (!d && i && n && !l[l.length - 1].route.index && (d = H(
{
path: o.relativePath,
caseSensitive: o.caseSensitive,
end: !1
},
f
)), !d)
return null;
Object.assign(r, d.params), c.push({
// TODO: Can this as be avoided?
params: r,
pathname: b([a, d.pathname]),
pathnameBase: Be(
b([a, d.pathnameBase])
),
route: h
}), d.pathnameBase !== "/" && (a = b([a, d.pathnameBase]));
}
return c;
}
function H(e, t) {
typeof e == "string" && (e = { path: e, caseSensitive: !1, end: !0 });
let [n, l] = Ne(
e.path,
e.caseSensitive,
e.end
), r = t.match(n);
if (!r) return null;
let a = r[0], c = a.replace(/(.)\/+$/, "$1"), s = r.slice(1);
return {
params: l.reduce(
(i, { paramName: f, isOptional: d }, h) => {
if (f === "*") {
let y = s[h] || "";
c = a.slice(0, a.length - y.length).replace(/(.)\/+$/, "$1");
}
const g = s[h];
return d && !g ? i[f] = void 0 : i[f] = (g || "").replace(/%2F/g, "/"), i;
},
{}
),
pathname: a,
pathnameBase: c,
pattern: e
};
}
function Ne(e, t = !1, n = !0) {
P(
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 l = [], r = "^" + e.replace(/\/*\*?$/, "").replace(/^\/*/, "/").replace(/[\\.*+^${}|()[\]]/g, "\\$&").replace(
/\/:([\w-]+)(\?)?/g,
(c, s, o) => (l.push({ paramName: s, isOptional: o != null }), o ? "/?([^\\/]+)?" : "/([^\\/]+)")
);
return e.endsWith("*") ? (l.push({ paramName: "*" }), r += e === "*" || e === "/*" ? "(.*)$" : "(?:\\/(.+)|\\/*)$") : n ? r += "\\/*$" : e !== "" && e !== "/" && (r += "(?:(?=\\/|$))"), [new RegExp(r, t ? void 0 : "i"), l];
}
function De(e) {
try {
return e.split("/").map((t) => decodeURIComponent(t).replace(/\//g, "%2F")).join("/");
} catch (t) {
return P(
!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 S(e, t) {
if (t === "/") return e;
if (!e.toLowerCase().startsWith(t.toLowerCase()))
return null;
let n = t.endsWith("/") ? t.length - 1 : t.length, l = e.charAt(n);
return l && l !== "/" ? null : e.slice(n) || "/";
}
function Te(e, t = "/") {
let {
pathname: n,
search: l = "",
hash: r = ""
} = typeof e == "string" ? Y(e) : e;
return {
pathname: n ? n.startsWith("/") ? n : Me(n, t) : t,
search: Oe(l),
hash: We(r)
};
}
function Me(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, l) {
return `Cannot include a '${e}' character in a manually specified \`to.${t}\` field [${JSON.stringify(
l
)}]. 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, l) => l === t.length - 1 ? n.pathname : n.pathnameBase
);
}
function se(e, t, n, l = !1) {
let r;
typeof e == "string" ? r = Y(e) : (r = { ...e }, C(
!r.pathname || !r.pathname.includes("?"),
j("?", "pathname", "search", r)
), C(
!r.pathname || !r.pathname.includes("#"),
j("#", "pathname", "hash", r)
), C(
!r.search || !r.search.includes("#"),
j("#", "search", "hash", r)
));
let a = e === "" || r.pathname === "", c = a ? "/" : r.pathname, s;
if (c == null)
s = n;
else {
let d = t.length - 1;
if (!l && c.startsWith("..")) {
let h = c.split("/");
for (; h[0] === ".."; )
h.shift(), d -= 1;
r.pathname = h.join("/");
}
s = d >= 0 ? t[d] : "/";
}
let o = Te(r, s), i = c && c !== "/" && c.endsWith("/"), f = (a || c === ".") && n.endsWith("/");
return !o.pathname.endsWith("/") && (i || f) && (o.pathname += "/"), o;
}
var b = (e) => e.join("/").replace(/\/\/+/g, "/"), Be = (e) => e.replace(/\/+$/, "").replace(/^\/*/, "/"), Oe = (e) => !e || e === "?" ? "" : e.startsWith("?") ? e : "?" + e, We = (e) => !e || e === "#" ? "" : e.startsWith("#") ? e : "#" + e;
function Ue(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 He = [
"GET",
...ce
];
new Set(He);
var N = u.createContext(null);
N.displayName = "DataRouter";
var _ = u.createContext(null);
_.displayName = "DataRouterState";
var fe = u.createContext({
isTransitioning: !1
});
fe.displayName = "ViewTransition";
var _e = u.createContext(
/* @__PURE__ */ new Map()
);
_e.displayName = "Fetchers";
var Ve = u.createContext(null);
Ve.displayName = "Await";
var L = u.createContext(
null
);
L.displayName = "Navigation";
var q = u.createContext(
null
);
q.displayName = "Location";
var k = u.createContext({
outlet: null,
matches: [],
isDataRoute: !1
});
k.displayName = "Route";
var G = u.createContext(null);
G.displayName = "RouteError";
function ze(e, { relative: t } = {}) {
C(
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: l } = u.useContext(L), { hash: r, pathname: a, search: c } = M(e, { relative: t }), s = a;
return n !== "/" && (s = a === "/" ? n : b([n, a])), l.createHref({ pathname: s, search: c, hash: r });
}
function V() {
return u.useContext(q) != null;
}
function $() {
return C(
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(L).static || u.useLayoutEffect(e);
}
function je() {
let { isDataRoute: e } = u.useContext(k);
return e ? at() : Je();
}
function Je() {
C(
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(N), { basename: t, navigator: n } = u.useContext(L), { matches: l } = u.useContext(k), { pathname: r } = $(), a = JSON.stringify(ue(l)), c = u.useRef(!1);
return he(() => {
c.current = !0;
}), u.useCallback(
(o, i = {}) => {
if (P(c.current, de), !c.current) return;
if (typeof o == "number") {
n.go(o);
return;
}
let f = se(
o,
JSON.parse(a),
r,
i.relative === "path"
);
e == null && t !== "/" && (f.pathname = f.pathname === "/" ? t : b([t, f.pathname])), (i.replace ? n.replace : n.push)(
f,
i.state,
i
);
},
[
t,
n,
a,
r,
e
]
);
}
u.createContext(null);
function M(e, { relative: t } = {}) {
let { matches: n } = u.useContext(k), { pathname: l } = $(), r = JSON.stringify(ue(n));
return u.useMemo(
() => se(
e,
JSON.parse(r),
l,
t === "path"
),
[e, r, l, t]
);
}
function Ke(e, t, n, l) {
C(
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, static: a } = u.useContext(L), { matches: c } = u.useContext(k), s = c[c.length - 1], o = s ? s.params : {}, i = s ? s.pathname : "/", f = s ? s.pathnameBase : "/", d = s && s.route;
{
let p = d && d.path || "";
me(
i,
!d || p.endsWith("*") || p.endsWith("*?"),
`You rendered descendant <Routes> (or called \`useRoutes()\`) at "${i}" (under <Route path="${p}">) 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="${p}"> to <Route path="${p === "/" ? "*" : `${p}/*`}">.`
);
}
let h = $(), g;
g = h;
let y = g.pathname || "/", w = y;
if (f !== "/") {
let p = f.replace(/^\//, "").split("/");
w = "/" + y.replace(/^\//, "").split("/").slice(p.length).join("/");
}
let v = !a && n && n.matches && n.matches.length > 0 ? n.matches : le(e, { pathname: w });
return P(
d || v != null,
`No routes matched location "${g.pathname}${g.search}${g.hash}" `
), P(
v == null || v[v.length - 1].route.element !== void 0 || v[v.length - 1].route.Component !== void 0 || v[v.length - 1].route.lazy !== void 0,
`Matched leaf route at location "${g.pathname}${g.search}${g.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.`
), Qe(
v && v.map(
(p) => Object.assign({}, p, {
params: Object.assign({}, o, p.params),
pathname: b([
f,
// Re-encode pathnames that were decoded inside matchRoutes
r.encodeLocation ? r.encodeLocation(p.pathname).pathname : p.pathname
]),
pathnameBase: p.pathnameBase === "/" ? f : b([
f,
// Re-encode pathnames that were decoded inside matchRoutes
r.encodeLocation ? r.encodeLocation(p.pathnameBase).pathname : p.pathnameBase
])
})
),
c,
n,
l
);
}
function Ye() {
let e = rt(), t = Ue(e) ? `${e.status} ${e.statusText}` : e instanceof Error ? e.message : JSON.stringify(e), n = e instanceof Error ? e.stack : null, l = "rgba(200,200,200, 0.5)", r = { padding: "0.5rem", backgroundColor: l }, a = { padding: "2px 4px", backgroundColor: l }, c = null;
return console.error(
"Error handled by React Router default ErrorBoundary:",
e
), c = /* @__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: a }, "ErrorBoundary"), " or", " ", /* @__PURE__ */ u.createElement("code", { style: a }, "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, c);
}
var qe = /* @__PURE__ */ u.createElement(Ye, null), Ge = 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(k.Provider, { value: this.props.routeContext }, /* @__PURE__ */ u.createElement(
G.Provider,
{
value: this.state.error,
children: this.props.component
}
)) : this.props.children;
}
};
function Xe({ routeContext: e, match: t, children: n }) {
let l = u.useContext(N);
return l && l.static && l.staticContext && (t.route.errorElement || t.route.ErrorBoundary) && (l.staticContext._deepestRenderedBoundaryId = t.route.id), /* @__PURE__ */ u.createElement(k.Provider, { value: e }, n);
}
function Qe(e, t = [], n = null, l = 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, a = n == null ? void 0 : n.errors;
if (a != null) {
let o = r.findIndex(
(i) => i.route.id && (a == null ? void 0 : a[i.route.id]) !== void 0
);
C(
o >= 0,
`Could not find a matching route for errors on route IDs: ${Object.keys(
a
).join(",")}`
), r = r.slice(
0,
Math.min(r.length, o + 1)
);
}
let c = !1, s = -1;
if (n)
for (let o = 0; o < r.length; o++) {
let i = r[o];
if ((i.route.HydrateFallback || i.route.hydrateFallbackElement) && (s = o), i.route.id) {
let { loaderData: f, errors: d } = n, h = i.route.loader && !f.hasOwnProperty(i.route.id) && (!d || d[i.route.id] === void 0);
if (i.route.lazy || h) {
c = !0, s >= 0 ? r = r.slice(0, s + 1) : r = [r[0]];
break;
}
}
}
return r.reduceRight((o, i, f) => {
let d, h = !1, g = null, y = null;
n && (d = a && i.route.id ? a[i.route.id] : void 0, g = i.route.errorElement || qe, c && (s < 0 && f === 0 ? (me(
"route-fallback",
!1,
"No `HydrateFallback` element provided to render during initial hydration"
), h = !0, y = null) : s === f && (h = !0, y = i.route.hydrateFallbackElement || null)));
let w = t.concat(r.slice(0, f + 1)), v = () => {
let m;
return d ? m = g : h ? m = y : i.route.Component ? m = /* @__PURE__ */ u.createElement(i.route.Component, null) : i.route.element ? m = i.route.element : m = o, /* @__PURE__ */ u.createElement(
Xe,
{
match: i,
routeContext: {
outlet: o,
matches: w,
isDataRoute: n != null
},
children: m
}
);
};
return n && (i.route.ErrorBoundary || i.route.errorElement || f === 0) ? /* @__PURE__ */ u.createElement(
Ge,
{
location: n.location,
revalidation: n.revalidation,
component: g,
error: d,
children: v(),
routeContext: { outlet: null, matches: w, isDataRoute: !0 }
}
) : v();
}, null);
}
function X(e) {
return `${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`;
}
function Ze(e) {
let t = u.useContext(N);
return C(t, X(e)), t;
}
function et(e) {
let t = u.useContext(_);
return C(t, X(e)), t;
}
function tt(e) {
let t = u.useContext(k);
return C(t, X(e)), t;
}
function Q(e) {
let t = tt(e), n = t.matches[t.matches.length - 1];
return C(
n.route.id,
`${e} can only be used on routes that contain a unique "id"`
), n.route.id;
}
function nt() {
return Q(
"useRouteId"
/* UseRouteId */
);
}
function rt() {
var l;
let e = u.useContext(G), t = et(
"useRouteError"
/* UseRouteError */
), n = Q(
"useRouteError"
/* UseRouteError */
);
return e !== void 0 ? e : (l = t.errors) == null ? void 0 : l[n];
}
function at() {
let { router: e } = Ze(
"useNavigate"
/* UseNavigateStable */
), t = Q(
"useNavigate"
/* UseNavigateStable */
), n = u.useRef(!1);
return he(() => {
n.current = !0;
}), u.useCallback(
async (r, a = {}) => {
P(n.current, de), n.current && (typeof r == "number" ? e.navigate(r) : await e.navigate(r, { fromRouteId: t, ...a }));
},
[e, t]
);
}
var re = {};
function me(e, t, n) {
!t && !re[e] && (re[e] = !0, P(!1, n));
}
u.memo(lt);
function lt({
routes: e,
future: t,
state: n
}) {
return Ke(e, void 0, n, t);
}
var W = "get", U = "application/x-www-form-urlencoded";
function z(e) {
return e != null && typeof e.tagName == "string";
}
function ot(e) {
return z(e) && e.tagName.toLowerCase() === "button";
}
function it(e) {
return z(e) && e.tagName.toLowerCase() === "form";
}
function ut(e) {
return z(e) && e.tagName.toLowerCase() === "input";
}
function st(e) {
return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
}
function ct(e, t) {
return e.button === 0 && // Ignore everything but left clicks
(!t || t === "_self") && // Let browser handle "target=_blank" etc.
!st(e);
}
var O = null;
function ft() {
if (O === null)
try {
new FormData(
document.createElement("form"),
// @ts-expect-error if FormData supports the submitter parameter, this will throw
0
), O = !1;
} catch {
O = !0;
}
return O;
}
var dt = /* @__PURE__ */ new Set([
"application/x-www-form-urlencoded",
"multipart/form-data",
"text/plain"
]);
function J(e) {
return e != null && !dt.has(e) ? (P(
!1,
`"${e}" is not a valid \`encType\` for \`<Form>\`/\`<fetcher.Form>\` and will default to "${U}"`
), null) : e;
}
function ht(e, t) {
let n, l, r, a, c;
if (it(e)) {
let s = e.getAttribute("action");
l = s ? S(s, t) : null, n = e.getAttribute("method") || W, r = J(e.getAttribute("enctype")) || U, a = new FormData(e);
} else if (ot(e) || ut(e) && (e.type === "submit" || e.type === "image")) {
let s = e.form;
if (s == null)
throw new Error(
'Cannot submit a <button> or <input type="submit"> without a <form>'
);
let o = e.getAttribute("formaction") || s.getAttribute("action");
if (l = o ? S(o, t) : null, n = e.getAttribute("formmethod") || s.getAttribute("method") || W, r = J(e.getAttribute("formenctype")) || J(s.getAttribute("enctype")) || U, a = new FormData(s, e), !ft()) {
let { name: i, type: f, value: d } = e;
if (f === "image") {
let h = i ? `${i}.` : "";
a.append(`${h}x`, "0"), a.append(`${h}y`, "0");
} else i && a.append(i, d);
}
} else {
if (z(e))
throw new Error(
'Cannot submit element that is not <form>, <button>, or <input type="submit|image">'
);
n = W, l = null, r = U, c = e;
}
return a && r === "text/plain" && (c = a, a = void 0), { action: l, method: n.toLowerCase(), encType: r, formData: a, body: c };
}
function Z(e, t) {
if (e === !1 || e === null || typeof e > "u")
throw new Error(t);
}
async function mt(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 pt(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 gt(e, t, n) {
let l = await Promise.all(
e.map(async (r) => {
let a = t.routes[r.route.id];
if (a) {
let c = await mt(a, n);
return c.links ? c.links() : [];
}
return [];
})
);
return xt(
l.flat(1).filter(pt).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, l, r, a) {
let c = (o, i) => n[i] ? o.route.id !== n[i].route.id : !0, s = (o, i) => {
var f;
return (
// param change, /users/123 -> /users/456
n[i].pathname !== o.pathname || // splat param changed, which is not present in match.path
// e.g. /files/images/avatar.jpg -> files/finances.xls
((f = n[i].route.path) == null ? void 0 : f.endsWith("*")) && n[i].params["*"] !== o.params["*"]
);
};
return a === "assets" ? t.filter(
(o, i) => c(o, i) || s(o, i)
) : a === "data" ? t.filter((o, i) => {
var d;
let f = l.routes[o.route.id];
if (!f || !f.hasLoader)
return !1;
if (c(o, i) || s(o, i))
return !0;
if (o.route.shouldRevalidate) {
let h = o.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: o.params,
defaultShouldRevalidate: !0
});
if (typeof h == "boolean")
return h;
}
return !0;
}) : [];
}
function yt(e, t, { includeHydrateFallback: n } = {}) {
return vt(
e.map((l) => {
let r = t.routes[l.route.id];
if (!r) return [];
let a = [r.module];
return r.clientActionModule && (a = a.concat(r.clientActionModule)), r.clientLoaderModule && (a = a.concat(r.clientLoaderModule)), n && r.hydrateFallbackModule && (a = a.concat(r.hydrateFallbackModule)), r.imports && (a = a.concat(r.imports)), a;
}).flat(1)
);
}
function vt(e) {
return [...new Set(e)];
}
function wt(e) {
let t = {}, n = Object.keys(e).sort();
for (let l of n)
t[l] = e[l];
return t;
}
function xt(e, t) {
let n = /* @__PURE__ */ new Set();
return new Set(t), e.reduce((l, r) => {
let a = JSON.stringify(wt(r));
return n.has(a) || (n.add(a), l.push({ key: a, link: r })), l;
}, []);
}
Object.getOwnPropertyNames(Object.prototype).sort().join("\0");
function Ct(e, t) {
let n = 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 n.pathname === "/" ? n.pathname = "_root.data" : t && S(n.pathname, t) === "/" ? n.pathname = `${t.replace(/\/$/, "")}/_root.data` : n.pathname = `${n.pathname.replace(/\/$/, "")}.data`, n;
}
function pe() {
let e = u.useContext(N);
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 ge() {
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), [l, r] = u.useState(!1), [a, c] = u.useState(!1), { onFocus: s, onBlur: o, onMouseEnter: i, onMouseLeave: f, onTouchStart: d } = t, h = u.useRef(null);
u.useEffect(() => {
if (e === "render" && c(!0), e === "viewport") {
let w = (m) => {
m.forEach((p) => {
c(p.isIntersecting);
});
}, v = new IntersectionObserver(w, { threshold: 0.5 });
return h.current && v.observe(h.current), () => {
v.disconnect();
};
}
}, [e]), u.useEffect(() => {
if (l) {
let w = setTimeout(() => {
c(!0);
}, 100);
return () => {
clearTimeout(w);
};
}
}, [l]);
let g = () => {
r(!0);
}, y = () => {
r(!1), c(!1);
};
return n ? e !== "intent" ? [a, h, {}] : [
a,
h,
{
onFocus: T(s, g),
onBlur: T(o, y),
onMouseEnter: T(i, g),
onMouseLeave: T(f, y),
onTouchStart: T(d, g)
}
] : [!1, h, {}];
}
function T(e, t) {
return (n) => {
e && e(n), n.defaultPrevented || t(n);
};
}
function bt({
page: e,
...t
}) {
let { router: n } = pe(), l = u.useMemo(
() => le(n.routes, e, n.basename),
[n.routes, e, n.basename]
);
return l ? /* @__PURE__ */ u.createElement(Lt, { page: e, matches: l, ...t }) : null;
}
function Pt(e) {
let { manifest: t, routeModules: n } = ge(), [l, r] = u.useState([]);
return u.useEffect(() => {
let a = !1;
return gt(e, t, n).then(
(c) => {
a || r(c);
}
), () => {
a = !0;
};
}, [e, t, n]), l;
}
function Lt({
page: e,
matches: t,
...n
}) {
let l = $(), { manifest: r, routeModules: a } = ge(), { basename: c } = pe(), { loaderData: s, matches: o } = Et(), i = u.useMemo(
() => ae(
e,
t,
o,
r,
l,
"data"
),
[e, t, o, r, l]
), f = u.useMemo(
() => ae(
e,
t,
o,
r,
l,
"assets"
),
[e, t, o, r, l]
), d = u.useMemo(() => {
if (e === l.pathname + l.search + l.hash)
return [];
let y = /* @__PURE__ */ new Set(), w = !1;
if (t.forEach((m) => {
var x;
let p = r.routes[m.route.id];
!p || !p.hasLoader || (!i.some((R) => R.route.id === m.route.id) && m.route.id in s && ((x = a[m.route.id]) != null && x.shouldRevalidate) || p.hasClientLoader ? w = !0 : y.add(m.route.id));
}), y.size === 0)
return [];
let v = Ct(e, c);
return w && y.size > 0 && v.searchParams.set(
"_routes",
t.filter((m) => y.has(m.route.id)).map((m) => m.route.id).join(",")
), [v.pathname + v.search];
}, [
c,
s,
l,
r,
i,
t,
e,
a
]), h = u.useMemo(
() => yt(f, r),
[f, r]
), g = Pt(f);
return /* @__PURE__ */ u.createElement(u.Fragment, null, d.map((y) => /* @__PURE__ */ u.createElement("link", { key: y, rel: "prefetch", as: "fetch", href: y, ...n })), h.map((y) => /* @__PURE__ */ u.createElement("link", { key: y, rel: "modulepreload", href: y, ...n })), g.map(({ key: y, link: w }) => (
// these don't spread `linkProps` because they are full link descriptors
// already with their own props
/* @__PURE__ */ u.createElement("link", { key: y, ...w })
)));
}
function kt(...e) {
return (t) => {
e.forEach((n) => {
typeof n == "function" ? n(t) : n != null && (n.current = t);
});
};
}
var ye = typeof window < "u" && typeof window.document < "u" && typeof window.document.createElement < "u";
try {
ye && (window.__reactRouterVersion = "7.6.0");
} catch {
}
var ve = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i, we = u.forwardRef(
function({
onClick: t,
discover: n = "render",
prefetch: l = "none",
relative: r,
reloadDocument: a,
replace: c,
state: s,
target: o,
to: i,
preventScrollReset: f,
viewTransition: d,
...h
}, g) {
let { basename: y } = u.useContext(L), w = typeof i == "string" && ve.test(i), v, m = !1;
if (typeof i == "string" && w && (v = i, ye))
try {
let E = new URL(window.location.href), I = i.startsWith("//") ? new URL(E.protocol + i) : new URL(i), te = S(I.pathname, y);
I.origin === E.origin && te != null ? i = te + I.search + I.hash : m = !0;
} catch {
P(
!1,
`<Link to="${i}"> contains an invalid URL which will probably break when clicked - please update to a valid URL path.`
);
}
let p = ze(i, { relative: r }), [x, R, F] = Rt(
l,
h
), A = It(i, {
replace: c,
state: s,
target: o,
preventScrollReset: f,
relative: r,
viewTransition: d
});
function D(E) {
t && t(E), E.defaultPrevented || A(E);
}
let B = (
// eslint-disable-next-line jsx-a11y/anchor-has-content
/* @__PURE__ */ u.createElement(
"a",
{
...h,
...F,
href: v || p,
onClick: m || a ? t : D,
ref: kt(g, R),
target: o,
"data-discover": !w && n === "render" ? "true" : void 0
}
)
);
return x && !w ? /* @__PURE__ */ u.createElement(u.Fragment, null, B, /* @__PURE__ */ u.createElement(bt, { page: p })) : B;
}
);
we.displayName = "Link";
var St = u.forwardRef(
function({
"aria-current": t = "page",
caseSensitive: n = !1,
className: l = "",
end: r = !1,
style: a,
to: c,
viewTransition: s,
children: o,
...i
}, f) {
let d = M(c, { relative: i.relative }), h = $(), g = u.useContext(_), { navigator: y, basename: w } = u.useContext(L), v = g != null && // Conditional usage is OK here because the usage of a data router is static
// eslint-disable-next-line react-hooks/rules-of-hooks
At(d) && s === !0, m = y.encodeLocation ? y.encodeLocation(d).pathname : d.pathname, p = h.pathname, x = g && g.navigation && g.navigation.location ? g.navigation.location.pathname : null;
n || (p = p.toLowerCase(), x = x ? x.toLowerCase() : null, m = m.toLowerCase()), x && w && (x = S(x, w) || x);
const R = m !== "/" && m.endsWith("/") ? m.length - 1 : m.length;
let F = p === m || !r && p.startsWith(m) && p.charAt(R) === "/", A = x != null && (x === m || !r && x.startsWith(m) && x.charAt(m.length) === "/"), D = {
isActive: F,
isPending: A,
isTransitioning: v
}, B = F ? t : void 0, E;
typeof l == "function" ? E = l(D) : E = [
l,
F ? "active" : null,
A ? "pending" : null,
v ? "transitioning" : null
].filter(Boolean).join(" ");
let I = typeof a == "function" ? a(D) : a;
return /* @__PURE__ */ u.createElement(
we,
{
...i,
"aria-current": B,
className: E,
ref: f,
style: I,
to: c,
viewTransition: s
},
typeof o == "function" ? o(D) : o
);
}
);
St.displayName = "NavLink";
var $t = u.forwardRef(
({
discover: e = "render",
fetcherKey: t,
navigate: n,
reloadDocument: l,
replace: r,
state: a,
method: c = W,
action: s,
onSubmit: o,
relative: i,
preventScrollReset: f,
viewTransition: d,
...h
}, g) => {
let y = Tt(), w = Mt(s, { relative: i }), v = c.toLowerCase() === "get" ? "get" : "post", m = typeof s == "string" && ve.test(s), p = (x) => {
if (o && o(x), x.defaultPrevented) return;
x.preventDefault();
let R = x.nativeEvent.submitter, F = (R == null ? void 0 : R.getAttribute("formmethod")) || c;
y(R || x.currentTarget, {
fetcherKey: t,
method: F,
navigate: n,
replace: r,
state: a,
relative: i,
preventScrollReset: f,
viewTransition: d
});
};
return /* @__PURE__ */ u.createElement(
"form",
{
ref: g,
method: v,
action: w,
onSubmit: l ? o : p,
...h,
"data-discover": !m && 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 xe(e) {
let t = u.useContext(N);
return C(t, Ft(e)), t;
}
function It(e, {
target: t,
replace: n,
state: l,
preventScrollReset: r,
relative: a,
viewTransition: c
} = {}) {
let s = je(), o = $(), i = M(e, { relative: a });
return u.useCallback(
(f) => {
if (ct(f, t)) {
f.preventDefault();
let d = n !== void 0 ? n : K(o) === K(i);
s(e, {
replace: d,
state: l,
preventScrollReset: r,
relative: a,
viewTransition: c
});
}
},
[
o,
s,
i,
n,
l,
t,
e,
r,
a,
c
]
);
}
var Nt = 0, Dt = () => `__${String(++Nt)}__`;
function Tt() {
let { router: e } = xe(
"useSubmit"
/* UseSubmit */
), { basename: t } = u.useContext(L), n = nt();
return u.useCallback(
async (l, r = {}) => {
let { action: a, method: c, encType: s, formData: o, body: i } = ht(
l,
t
);
if (r.navigate === !1) {
let f = r.fetcherKey || Dt();
await e.fetch(f, n, r.action || a, {
preventScrollReset: r.preventScrollReset,
formData: o,
body: i,
formMethod: r.method || c,
formEncType: r.encType || s,
flushSync: r.flushSync
});
} else
await e.navigate(r.action || a, {
preventScrollReset: r.preventScrollReset,
formData: o,
body: i,
formMethod: r.method || c,
formEncType: r.encType || s,
replace: r.replace,
state: r.state,
fromRouteId: n,
flushSync: r.flushSync,
viewTransition: r.viewTransition
});
},
[e, t, n]
);
}
function Mt(e, { relative: t } = {}) {
let { basename: n } = u.useContext(L), l = u.useContext(k);
C(l, "useFormAction must be used inside a RouteContext");
let [r] = l.matches.slice(-1), a = { ...M(e || ".", { relative: t }) }, c = $();
if (e == null) {
a.search = c.search;
let s = new URLSearchParams(a.search), o = s.getAll("index");
if (o.some((f) => f === "")) {
s.delete("index"), o.filter((d) => d).forEach((d) => s.append("index", d));
let f = s.toString();
a.search = f ? `?${f}` : "";
}
}
return (!e || e === ".") && r.route.index && (a.search = a.search ? a.search.replace(/^\?/, "?index&") : "?index"), n !== "/" && (a.pathname = a.pathname === "/" ? n : b([n, a.pathname])), K(a);
}
function At(e, t = {}) {
let n = u.useContext(fe);
C(
n != null,
"`useViewTransitionState` must be used within `react-router-dom`'s `RouterProvider`. Did you accidentally import `RouterProvider` from `react-router`?"
);
let { basename: l } = xe(
"useViewTransitionState"
/* useViewTransitionState */
), r = M(e, { relative: t.relative });
if (!n.isTransitioning)
return !1;
let a = S(n.currentLocation.pathname, l) || n.currentLocation.pathname, c = S(n.nextLocation.pathname, l) || n.nextLocation.pathname;
return H(r.pathname, c) != null || H(r.pathname, a) != null;
}
const Bt = () => {
try {
return $(), {
isInsideRouter: !0
};
} catch {
return {
isInsideRouter: !1
};
}
};
export {
we as L,
Bt as u
};