@konstructio/ui
Version:
A set of reusable and customizable React components built for konstruct.io
1,264 lines (1,262 loc) • 38.4 kB
JavaScript
import * as i from "react";
function C(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 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 u = 0; s == null && u < c.length; ++u) {
let o = De(a);
s = Ie(
c[u],
o,
l
);
}
return s;
}
function oe(e, t = [], n = [], l = "") {
let r = (a, c, s) => {
let u = {
relativePath: s === void 0 ? a.path || "" : s,
caseSensitive: a.caseSensitive === !0,
childrenIndex: c,
route: a
};
u.relativePath.startsWith("/") && (C(
u.relativePath.startsWith(l),
`Absolute route path "${u.relativePath}" nested under path "${l}" is not valid. An absolute child route path must start with the combined path of all its parent routes.`
), u.relativePath = u.relativePath.slice(l.length));
let o = R([l, u.relativePath]), f = n.concat(u);
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 "${o}".`
), oe(a.children, t, f, o)), !(a.path == null && !a.index) && t.push({
path: o,
score: $e(o, a.index),
routesMeta: f
});
};
return e.forEach((a, c) => {
if (a.path === "" || !a.path?.includes("?"))
r(a, c);
else
for (let s of ie(a.path))
r(a, c, s);
}), 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(
(u) => u === "" ? a : [a, u].join("/")
)
), r && s.push(...c), s.map(
(u) => e.startsWith("/") && u === "" ? "/" : u
);
}
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, Se = 10, ke = -2, ne = (e) => e === "*";
function $e(e, t) {
let n = e.split("/"), l = n.length;
return n.some(ne) && (l += ke), t && (l += Pe), n.filter((r) => !ne(r)).reduce(
(r, a) => r + (Re.test(a) ? be : a === "" ? Le : Se),
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 u = l[s], o = s === l.length - 1, f = a === "/" ? t : t.slice(a.length) || "/", d = H(
{ path: u.relativePath, caseSensitive: u.caseSensitive, end: o },
f
), m = u.route;
if (!d && o && n && !l[l.length - 1].route.index && (d = H(
{
path: u.relativePath,
caseSensitive: u.caseSensitive,
end: !1
},
f
)), !d)
return null;
Object.assign(r, d.params), c.push({
// TODO: Can this as be avoided?
params: r,
pathname: R([a, d.pathname]),
pathnameBase: Be(
R([a, d.pathnameBase])
),
route: m
}), d.pathnameBase !== "/" && (a = R([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(
(o, { paramName: f, isOptional: d }, m) => {
if (f === "*") {
let y = s[m] || "";
c = a.slice(0, a.length - y.length).replace(/(.)\/+$/, "$1");
}
const g = s[m];
return d && !g ? o[f] = void 0 : o[f] = (g || "").replace(/%2F/g, "/"), o;
},
{}
),
pathname: a,
pathnameBase: c,
pattern: e
};
}
function Ne(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 l = [], r = "^" + e.replace(/\/*\*?$/, "").replace(/^\/*/, "/").replace(/[\\.*+^${}|()[\]]/g, "\\$&").replace(
/\/:([\w-]+)(\?)?/g,
(c, s, u) => (l.push({ paramName: s, isOptional: u != null }), u ? "/?([^\\/]+)?" : "/([^\\/]+)")
);
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 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 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 m = c.split("/");
for (; m[0] === ".."; )
m.shift(), d -= 1;
r.pathname = m.join("/");
}
s = d >= 0 ? t[d] : "/";
}
let u = Te(r, s), o = c && c !== "/" && c.endsWith("/"), f = (a || c === ".") && n.endsWith("/");
return !u.pathname.endsWith("/") && (o || f) && (u.pathname += "/"), u;
}
var R = (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 = i.createContext(null);
N.displayName = "DataRouter";
var _ = i.createContext(null);
_.displayName = "DataRouterState";
var fe = i.createContext({
isTransitioning: !1
});
fe.displayName = "ViewTransition";
var _e = i.createContext(
/* @__PURE__ */ new Map()
);
_e.displayName = "Fetchers";
var Ve = i.createContext(null);
Ve.displayName = "Await";
var P = i.createContext(
null
);
P.displayName = "Navigation";
var q = i.createContext(
null
);
q.displayName = "Location";
var L = i.createContext({
outlet: null,
matches: [],
isDataRoute: !1
});
L.displayName = "Route";
var G = i.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 } = i.useContext(P), { hash: r, pathname: a, search: c } = M(e, { relative: t }), s = a;
return n !== "/" && (s = a === "/" ? n : R([n, a])), l.createHref({ pathname: s, search: c, hash: r });
}
function V() {
return i.useContext(q) != null;
}
function k() {
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."
), i.useContext(q).location;
}
var de = "You should call navigate() in a React.useEffect(), not when your component is first rendered.";
function he(e) {
i.useContext(P).static || i.useLayoutEffect(e);
}
function je() {
let { isDataRoute: e } = i.useContext(L);
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 = i.useContext(N), { basename: t, navigator: n } = i.useContext(P), { matches: l } = i.useContext(L), { pathname: r } = k(), a = JSON.stringify(ue(l)), c = i.useRef(!1);
return he(() => {
c.current = !0;
}), i.useCallback(
(u, o = {}) => {
if (b(c.current, de), !c.current) return;
if (typeof u == "number") {
n.go(u);
return;
}
let f = se(
u,
JSON.parse(a),
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,
a,
r,
e
]
);
}
i.createContext(null);
function M(e, { relative: t } = {}) {
let { matches: n } = i.useContext(L), { pathname: l } = k(), r = JSON.stringify(ue(n));
return i.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 } = i.useContext(P), { matches: c } = i.useContext(L), s = c[c.length - 1], u = s ? s.params : {}, o = s ? s.pathname : "/", f = s ? s.pathnameBase : "/", d = s && s.route;
{
let p = d && d.path || "";
me(
o,
!d || p.endsWith("*") || p.endsWith("*?"),
`You rendered descendant <Routes> (or called \`useRoutes()\`) at "${o}" (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 m = k(), g;
g = m;
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 b(
d || v != null,
`No routes matched location "${g.pathname}${g.search}${g.hash}" `
), b(
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({}, u, p.params),
pathname: R([
f,
// Re-encode pathnames that were decoded inside matchRoutes
r.encodeLocation ? r.encodeLocation(p.pathname).pathname : p.pathname
]),
pathnameBase: p.pathnameBase === "/" ? f : R([
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__ */ i.createElement(i.Fragment, null, /* @__PURE__ */ i.createElement("p", null, "💿 Hey developer 👋"), /* @__PURE__ */ i.createElement("p", null, "You can provide a way better UX than this when your app throws errors by providing your own ", /* @__PURE__ */ i.createElement("code", { style: a }, "ErrorBoundary"), " or", " ", /* @__PURE__ */ i.createElement("code", { style: a }, "errorElement"), " prop on your route.")), /* @__PURE__ */ i.createElement(i.Fragment, null, /* @__PURE__ */ i.createElement("h2", null, "Unexpected Application Error!"), /* @__PURE__ */ i.createElement("h3", { style: { fontStyle: "italic" } }, t), n ? /* @__PURE__ */ i.createElement("pre", { style: r }, n) : null, c);
}
var qe = /* @__PURE__ */ i.createElement(Ye, null), Ge = class extends i.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__ */ i.createElement(L.Provider, { value: this.props.routeContext }, /* @__PURE__ */ i.createElement(
G.Provider,
{
value: this.state.error,
children: this.props.component
}
)) : this.props.children;
}
};
function Xe({ routeContext: e, match: t, children: n }) {
let l = i.useContext(N);
return l && l.static && l.staticContext && (t.route.errorElement || t.route.ErrorBoundary) && (l.staticContext._deepestRenderedBoundaryId = t.route.id), /* @__PURE__ */ i.createElement(L.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?.errors;
if (a != null) {
let u = r.findIndex(
(o) => o.route.id && a?.[o.route.id] !== void 0
);
C(
u >= 0,
`Could not find a matching route for errors on route IDs: ${Object.keys(
a
).join(",")}`
), r = r.slice(
0,
Math.min(r.length, u + 1)
);
}
let c = !1, s = -1;
if (n)
for (let u = 0; u < r.length; u++) {
let o = r[u];
if ((o.route.HydrateFallback || o.route.hydrateFallbackElement) && (s = u), 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) {
c = !0, s >= 0 ? r = r.slice(0, s + 1) : r = [r[0]];
break;
}
}
}
return r.reduceRight((u, o, f) => {
let d, m = !1, g = null, y = null;
n && (d = a && o.route.id ? a[o.route.id] : void 0, g = o.route.errorElement || qe, c && (s < 0 && f === 0 ? (me(
"route-fallback",
!1,
"No `HydrateFallback` element provided to render during initial hydration"
), m = !0, y = null) : s === f && (m = !0, y = o.route.hydrateFallbackElement || null)));
let w = t.concat(r.slice(0, f + 1)), v = () => {
let h;
return d ? h = g : m ? h = y : o.route.Component ? h = /* @__PURE__ */ i.createElement(o.route.Component, null) : o.route.element ? h = o.route.element : h = u, /* @__PURE__ */ i.createElement(
Xe,
{
match: o,
routeContext: {
outlet: u,
matches: w,
isDataRoute: n != null
},
children: h
}
);
};
return n && (o.route.ErrorBoundary || o.route.errorElement || f === 0) ? /* @__PURE__ */ i.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 = i.useContext(N);
return C(t, X(e)), t;
}
function et(e) {
let t = i.useContext(_);
return C(t, X(e)), t;
}
function tt(e) {
let t = i.useContext(L);
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() {
let e = i.useContext(G), t = et(
"useRouteError"
/* UseRouteError */
), n = Q(
"useRouteError"
/* UseRouteError */
);
return e !== void 0 ? e : t.errors?.[n];
}
function at() {
let { router: e } = Ze(
"useNavigate"
/* UseNavigateStable */
), t = Q(
"useNavigate"
/* UseNavigateStable */
), n = i.useRef(!1);
return he(() => {
n.current = !0;
}), i.useCallback(
async (r, a = {}) => {
b(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, b(!1, n));
}
i.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) ? (b(
!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 u = e.getAttribute("formaction") || s.getAttribute("action");
if (l = u ? S(u, 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: o, type: f, value: d } = e;
if (f === "image") {
let m = o ? `${o}.` : "";
a.append(`${m}x`, "0"), a.append(`${m}y`, "0");
} else o && a.append(o, 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 = (u, o) => n[o] ? u.route.id !== n[o].route.id : !0, s = (u, o) => (
// param change, /users/123 -> /users/456
n[o].pathname !== u.pathname || // splat param changed, which is not present in match.path
// e.g. /files/images/avatar.jpg -> files/finances.xls
n[o].route.path?.endsWith("*") && n[o].params["*"] !== u.params["*"]
);
return a === "assets" ? t.filter(
(u, o) => c(u, o) || s(u, o)
) : a === "data" ? t.filter((u, o) => {
let f = l.routes[u.route.id];
if (!f || !f.hasLoader)
return !1;
if (c(u, o) || s(u, o))
return !0;
if (u.route.shouldRevalidate) {
let d = u.route.shouldRevalidate({
currentUrl: new URL(
r.pathname + r.search + r.hash,
window.origin
),
currentParams: n[0]?.params || {},
nextUrl: new URL(e, window.origin),
nextParams: u.params,
defaultShouldRevalidate: !0
});
if (typeof d == "boolean")
return d;
}
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 = i.useContext(N);
return Z(
e,
"You must render this element inside a <DataRouterContext.Provider> element"
), e;
}
function Et() {
let e = i.useContext(_);
return Z(
e,
"You must render this element inside a <DataRouterStateContext.Provider> element"
), e;
}
var ee = i.createContext(void 0);
ee.displayName = "FrameworkContext";
function ge() {
let e = i.useContext(ee);
return Z(
e,
"You must render this element inside a <HydratedRouter> element"
), e;
}
function Rt(e, t) {
let n = i.useContext(ee), [l, r] = i.useState(!1), [a, c] = i.useState(!1), { onFocus: s, onBlur: u, onMouseEnter: o, onMouseLeave: f, onTouchStart: d } = t, m = i.useRef(null);
i.useEffect(() => {
if (e === "render" && c(!0), e === "viewport") {
let w = (h) => {
h.forEach((p) => {
c(p.isIntersecting);
});
}, v = new IntersectionObserver(w, { threshold: 0.5 });
return m.current && v.observe(m.current), () => {
v.disconnect();
};
}
}, [e]), i.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, m, {}] : [
a,
m,
{
onFocus: T(s, g),
onBlur: T(u, y),
onMouseEnter: T(o, g),
onMouseLeave: T(f, y),
onTouchStart: T(d, g)
}
] : [!1, m, {}];
}
function T(e, t) {
return (n) => {
e && e(n), n.defaultPrevented || t(n);
};
}
function bt({
page: e,
...t
}) {
let { router: n } = pe(), l = i.useMemo(
() => le(n.routes, e, n.basename),
[n.routes, e, n.basename]
);
return l ? /* @__PURE__ */ i.createElement(Lt, { page: e, matches: l, ...t }) : null;
}
function Pt(e) {
let { manifest: t, routeModules: n } = ge(), [l, r] = i.useState([]);
return i.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 = k(), { manifest: r, routeModules: a } = ge(), { basename: c } = pe(), { loaderData: s, matches: u } = Et(), o = i.useMemo(
() => ae(
e,
t,
u,
r,
l,
"data"
),
[e, t, u, r, l]
), f = i.useMemo(
() => ae(
e,
t,
u,
r,
l,
"assets"
),
[e, t, u, r, l]
), d = i.useMemo(() => {
if (e === l.pathname + l.search + l.hash)
return [];
let y = /* @__PURE__ */ new Set(), w = !1;
if (t.forEach((h) => {
let p = r.routes[h.route.id];
!p || !p.hasLoader || (!o.some((x) => x.route.id === h.route.id) && h.route.id in s && a[h.route.id]?.shouldRevalidate || p.hasClientLoader ? w = !0 : y.add(h.route.id));
}), y.size === 0)
return [];
let v = Ct(e, c);
return w && y.size > 0 && v.searchParams.set(
"_routes",
t.filter((h) => y.has(h.route.id)).map((h) => h.route.id).join(",")
), [v.pathname + v.search];
}, [
c,
s,
l,
r,
o,
t,
e,
a
]), m = i.useMemo(
() => yt(f, r),
[f, r]
), g = Pt(f);
return /* @__PURE__ */ i.createElement(i.Fragment, null, d.map((y) => /* @__PURE__ */ i.createElement("link", { key: y, rel: "prefetch", as: "fetch", href: y, ...n })), m.map((y) => /* @__PURE__ */ i.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__ */ i.createElement("link", { key: y, ...w })
)));
}
function St(...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 = i.forwardRef(
function({
onClick: t,
discover: n = "render",
prefetch: l = "none",
relative: r,
reloadDocument: a,
replace: c,
state: s,
target: u,
to: o,
preventScrollReset: f,
viewTransition: d,
...m
}, g) {
let { basename: y } = i.useContext(P), w = typeof o == "string" && ve.test(o), v, h = !1;
if (typeof o == "string" && w && (v = o, ye))
try {
let E = new URL(window.location.href), I = o.startsWith("//") ? new URL(E.protocol + o) : new URL(o), te = S(I.pathname, y);
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 p = ze(o, { relative: r }), [x, F, $] = Rt(
l,
m
), A = It(o, {
replace: c,
state: s,
target: u,
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__ */ i.createElement(
"a",
{
...m,
...$,
href: v || p,
onClick: h || a ? t : D,
ref: St(g, F),
target: u,
"data-discover": !w && n === "render" ? "true" : void 0
}
)
);
return x && !w ? /* @__PURE__ */ i.createElement(i.Fragment, null, B, /* @__PURE__ */ i.createElement(bt, { page: p })) : B;
}
);
we.displayName = "Link";
var kt = i.forwardRef(
function({
"aria-current": t = "page",
caseSensitive: n = !1,
className: l = "",
end: r = !1,
style: a,
to: c,
viewTransition: s,
children: u,
...o
}, f) {
let d = M(c, { relative: o.relative }), m = k(), g = i.useContext(_), { navigator: y, basename: w } = i.useContext(P), 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, h = y.encodeLocation ? y.encodeLocation(d).pathname : d.pathname, p = m.pathname, x = g && g.navigation && g.navigation.location ? g.navigation.location.pathname : null;
n || (p = p.toLowerCase(), x = x ? x.toLowerCase() : null, h = h.toLowerCase()), x && w && (x = S(x, w) || x);
const F = h !== "/" && h.endsWith("/") ? h.length - 1 : h.length;
let $ = p === h || !r && p.startsWith(h) && p.charAt(F) === "/", A = x != null && (x === h || !r && x.startsWith(h) && x.charAt(h.length) === "/"), D = {
isActive: $,
isPending: A,
isTransitioning: v
}, B = $ ? t : void 0, E;
typeof l == "function" ? E = l(D) : E = [
l,
$ ? "active" : null,
A ? "pending" : null,
v ? "transitioning" : null
].filter(Boolean).join(" ");
let I = typeof a == "function" ? a(D) : a;
return /* @__PURE__ */ i.createElement(
we,
{
...o,
"aria-current": B,
className: E,
ref: f,
style: I,
to: c,
viewTransition: s
},
typeof u == "function" ? u(D) : u
);
}
);
kt.displayName = "NavLink";
var $t = i.forwardRef(
({
discover: e = "render",
fetcherKey: t,
navigate: n,
reloadDocument: l,
replace: r,
state: a,
method: c = W,
action: s,
onSubmit: u,
relative: o,
preventScrollReset: f,
viewTransition: d,
...m
}, g) => {
let y = Tt(), w = Mt(s, { relative: o }), v = c.toLowerCase() === "get" ? "get" : "post", h = typeof s == "string" && ve.test(s), p = (x) => {
if (u && u(x), x.defaultPrevented) return;
x.preventDefault();
let F = x.nativeEvent.submitter, $ = F?.getAttribute("formmethod") || c;
y(F || x.currentTarget, {
fetcherKey: t,
method: $,
navigate: n,
replace: r,
state: a,
relative: o,
preventScrollReset: f,
viewTransition: d
});
};
return /* @__PURE__ */ i.createElement(
"form",
{
ref: g,
method: v,
action: w,
onSubmit: l ? u : p,
...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 xe(e) {
let t = i.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(), u = k(), o = M(e, { relative: a });
return i.useCallback(
(f) => {
if (ct(f, t)) {
f.preventDefault();
let d = n !== void 0 ? n : K(u) === K(o);
s(e, {
replace: d,
state: l,
preventScrollReset: r,
relative: a,
viewTransition: c
});
}
},
[
u,
s,
o,
n,
l,
t,
e,
r,
a,
c
]
);
}
var Nt = 0, Dt = () => `__${String(++Nt)}__`;
function Tt() {
let { router: e } = xe(
"useSubmit"
/* UseSubmit */
), { basename: t } = i.useContext(P), n = nt();
return i.useCallback(
async (l, r = {}) => {
let { action: a, method: c, encType: s, formData: u, body: o } = ht(
l,
t
);
if (r.navigate === !1) {
let f = r.fetcherKey || Dt();
await e.fetch(f, n, r.action || a, {
preventScrollReset: r.preventScrollReset,
formData: u,
body: o,
formMethod: r.method || c,
formEncType: r.encType || s,
flushSync: r.flushSync
});
} else
await e.navigate(r.action || a, {
preventScrollReset: r.preventScrollReset,
formData: u,
body: o,
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 } = i.useContext(P), l = i.useContext(L);
C(l, "useFormAction must be used inside a RouteContext");
let [r] = l.matches.slice(-1), a = { ...M(e || ".", { relative: t }) }, c = k();
if (e == null) {
a.search = c.search;
let s = new URLSearchParams(a.search), u = s.getAll("index");
if (u.some((f) => f === "")) {
s.delete("index"), u.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 : R([n, a.pathname])), K(a);
}
function At(e, t = {}) {
let n = i.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 k(), {
isInsideRouter: !0
};
} catch {
return {
isInsideRouter: !1
};
}
};
export {
we as L,
Bt as u
};