UNPKG

@sudobility/email-components

Version:

Email marketing and management UI components for React

1,668 lines (1,667 loc) 56.4 kB
import { jsx as v, jsxs as R } from "react/jsx-runtime"; import { cn as k, ChainBadge as Te, Label as Ie } from "@sudobility/components"; import * as u from "react"; import { useRef as De, useState as Ue, useEffect as Me } from "react"; import { ChevronRightIcon as Be, ChevronUpIcon as Oe, ChevronDownIcon as We } from "@heroicons/react/24/outline"; import { textVariants as he } from "@sudobility/design"; const pr = ({ className: e, children: r, disabled: t }) => /* @__PURE__ */ v( "div", { className: k( "p-4 rounded-lg border transition-colors", "bg-white dark:bg-gray-900", "border-gray-200 dark:border-gray-700", "text-gray-900 dark:text-white", t && "opacity-50 cursor-not-allowed", e ), role: "region", "aria-label": "SubscriberList", children: r || "SubscriberList Component" } ), gr = ({ className: e, children: r, disabled: t }) => /* @__PURE__ */ v( "div", { className: k( "p-4 rounded-lg border transition-colors", "bg-white dark:bg-gray-900", "border-gray-200 dark:border-gray-700", "text-gray-900 dark:text-white", t && "opacity-50 cursor-not-allowed", e ), role: "region", "aria-label": "AbTestEmail", children: r || "AbTestEmail Component" } ), yr = ({ className: e, children: r, disabled: t }) => /* @__PURE__ */ v( "div", { className: k( "p-4 rounded-lg border transition-colors", "bg-white dark:bg-gray-900", "border-gray-200 dark:border-gray-700", "text-gray-900 dark:text-white", t && "opacity-50 cursor-not-allowed", e ), role: "region", "aria-label": "ContactCard", children: r || "ContactCard Component" } ), Ve = (e) => e ? e.length <= 10 ? e : `${e.slice(0, 6)}...${e.slice(-4)}` : "", pe = ({ type: e, addressType: r }) => { if (e === "primary") return /* @__PURE__ */ v( Te, { chainType: r === "solana" ? "solana" : "evm", size: "sm" } ); const t = () => e.toUpperCase(); return /* @__PURE__ */ v( "span", { className: k( "inline-flex items-center px-2.5 py-0.5 rounded-md text-xs font-medium border", (() => { switch (e) { case "ens": return "bg-green-50 text-green-700 border-green-200 dark:bg-green-900/10 dark:text-green-300 dark:border-green-800"; case "sns": return "bg-orange-50 text-orange-700 border-orange-200 dark:bg-orange-900/10 dark:text-orange-300 dark:border-orange-800"; default: return "bg-gray-50 text-gray-700 border-gray-200 dark:bg-gray-900/10 dark:text-gray-300 dark:border-gray-800"; } })() ), children: t() } ); }, _e = ({ domainEmails: e, isExpanded: r, selectedAccount: t, onAccountSelect: n, onAccountSettings: a }) => { const o = De(null), [l, s] = Ue(void 0); return Me(() => { if (o.current) { const i = o.current.scrollHeight; s(r ? i + 8 : 0); } }, [r, e]), /* @__PURE__ */ v( "div", { className: "overflow-hidden transition-all duration-300 ease-in-out", style: { height: l !== void 0 ? `${l}px` : "auto" }, children: /* @__PURE__ */ v("div", { ref: o, className: "ml-6 mt-2 space-y-1", children: e.map((i) => /* @__PURE__ */ R( "button", { onClick: () => n(i.address), className: k( "w-full flex items-center justify-between text-left px-3 py-2 rounded-lg transition-colors h-[44px]", he.body.sm(), t === i.address ? "bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300" : "hover:bg-gray-100 dark:hover:bg-gray-700" ), children: [ /* @__PURE__ */ v("span", { className: "truncate flex-1", children: i.name }), /* @__PURE__ */ v(pe, { type: i.type, addressType: i.addressType }) ] }, i.address )) }) } ); }, br = ({ walletGroups: e, selectedAccount: r, expandedWallets: t, onAccountSelect: n, onToggleWallet: a, onAccountSettings: o, className: l = "" }) => /* @__PURE__ */ v("nav", { className: k("space-y-1", l), children: e.map((s) => /* @__PURE__ */ R("div", { children: [ /* @__PURE__ */ R( "button", { onClick: () => n(s.primaryEmail.address), className: k( "w-full flex items-center justify-between text-left px-3 py-2 rounded-lg transition-colors h-[44px]", he.body.sm(), r === s.primaryEmail.address && s.domainEmails.length === 0 ? "bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300" : "hover:bg-gray-100 dark:hover:bg-gray-700" ), style: s.customColor ? { backgroundColor: s.customColor } : void 0, children: [ /* @__PURE__ */ R("div", { className: "flex items-center flex-1 min-w-0", children: [ /* @__PURE__ */ v("span", { className: "truncate flex-1", children: Ve(s.walletAddress) }), /* @__PURE__ */ v( pe, { type: s.primaryEmail.type, addressType: s.addressType } ) ] }), s.domainEmails.length > 0 && /* @__PURE__ */ v( "div", { onClick: (i) => { i.stopPropagation(), a(s.walletAddress); }, className: "p-1 rounded-lg hover:bg-gray-200 dark:hover:bg-gray-600 transition-colors cursor-pointer", role: "button", tabIndex: 0, onKeyDown: (i) => { (i.key === "Enter" || i.key === " ") && (i.preventDefault(), i.stopPropagation(), a(s.walletAddress)); }, children: /* @__PURE__ */ v( Be, { className: k( "h-4 w-4 text-gray-500 transition-transform duration-300 ease-in-out", t.includes(s.walletAddress) ? "rotate-90" : "rotate-0" ) } ) } ) ] } ), s.domainEmails.length > 0 && /* @__PURE__ */ v( _e, { domainEmails: s.domainEmails, isExpanded: t.includes(s.walletAddress), selectedAccount: r, onAccountSelect: n, onAccountSettings: o } ) ] }, s.walletAddress)) }), vr = ({ className: e, children: r, disabled: t }) => /* @__PURE__ */ v( "div", { className: k( "p-4 rounded-lg border transition-colors", "bg-white dark:bg-gray-900", "border-gray-200 dark:border-gray-700", "text-gray-900 dark:text-white", t && "opacity-50 cursor-not-allowed", e ), role: "region", "aria-label": "EmailAnalytics", children: r || "EmailAnalytics Component" } ), xr = ({ className: e, children: r, disabled: t }) => /* @__PURE__ */ v( "div", { className: k( "p-4 rounded-lg border transition-colors", "bg-white dark:bg-gray-900", "border-gray-200 dark:border-gray-700", "text-gray-900 dark:text-white", t && "opacity-50 cursor-not-allowed", e ), role: "region", "aria-label": "EmailCampaign", children: r || "EmailCampaign Component" } ), ge = ({ label: e, value: r, onChange: t, placeholder: n, required: a = !1, error: o, className: l = "" }) => /* @__PURE__ */ R("div", { className: l, children: [ /* @__PURE__ */ R( Ie, { htmlFor: e.toLowerCase(), className: "text-sm font-medium text-gray-700 dark:text-gray-300", children: [ e, " ", a && /* @__PURE__ */ v("span", { className: "text-red-500", children: "*" }) ] } ), /* @__PURE__ */ v( "input", { id: e.toLowerCase(), type: "email", value: r, onChange: (s) => t(s.target.value), placeholder: n, className: ` mt-1 block w-full px-3 py-2 border rounded-md shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-800 dark:border-gray-600 dark:text-white ${o ? "border-red-300 focus:ring-red-500 focus:border-red-500" : "border-gray-300 dark:border-gray-600"} ` } ), o && /* @__PURE__ */ v("p", { className: "mt-1 text-sm text-red-600 dark:text-red-400", children: o }) ] }), ie = ({ isVisible: e, onToggle: r, showLabel: t, hideLabel: n, ...a }) => /* @__PURE__ */ R("div", { children: [ /* @__PURE__ */ R( "button", { type: "button", onClick: r, className: "flex items-center text-sm text-blue-600 dark:text-blue-400 hover:text-blue-800 dark:hover:text-blue-300 mb-2", children: [ e ? /* @__PURE__ */ v(Oe, { className: "h-4 w-4 mr-1" }) : /* @__PURE__ */ v(We, { className: "h-4 w-4 mr-1" }), e ? n : t ] } ), e && /* @__PURE__ */ v(ge, { ...a }) ] }), wr = ({ to: e, onToChange: r, cc: t = "", onCcChange: n, bcc: a = "", onBccChange: o, showCc: l = !1, showBcc: s = !1, onToggleCc: i, onToggleBcc: c, errors: d = {}, className: f = "", labels: m = {}, placeholders: p = {} }) => { const g = { to: "To", cc: "CC", bcc: "BCC", addCc: "Add CC", removeCc: "Remove CC", addBcc: "Add BCC", removeBcc: "Remove BCC" }, x = { to: "recipient@example.com", cc: "cc@example.com", bcc: "bcc@example.com" }, h = { ...g, ...m }, y = { ...x, ...p }; return /* @__PURE__ */ R("div", { className: `space-y-4 ${f}`, children: [ /* @__PURE__ */ v( ge, { label: h.to, value: e, onChange: r, placeholder: y.to, required: !0, error: d.to } ), i && n && /* @__PURE__ */ v( ie, { label: h.cc, value: t, onChange: n, placeholder: y.cc, error: d.cc, isVisible: l, onToggle: i, showLabel: h.addCc, hideLabel: h.removeCc } ), c && o && /* @__PURE__ */ v( ie, { label: h.bcc, value: a, onChange: o, placeholder: y.bcc, error: d.bcc, isVisible: s, onToggle: c, showLabel: h.addBcc, hideLabel: h.removeBcc } ) ] }); }, Cr = ({ className: e, children: r, disabled: t = !1, onClick: n }) => /* @__PURE__ */ v( "div", { className: k( "p-4 rounded-lg border transition-colors", "bg-white dark:bg-gray-900", "border-gray-200 dark:border-gray-700", "text-gray-900 dark:text-white", t && "opacity-50 cursor-not-allowed", "hover:bg-gray-50 dark:hover:bg-gray-800", e ), onClick: t ? void 0 : n, role: "region", "aria-label": "UemailUtemplate", children: r || "UemailUtemplate Component" } ); function C(e, r) { if (e === !1 || e === null || typeof e > "u") throw new Error(r); } function L(e, r) { if (!e) { typeof console < "u" && console.warn(r); try { throw new Error(r); } catch { } } } function q({ pathname: e = "/", search: r = "", hash: t = "" }) { return r && r !== "?" && (e += r.charAt(0) === "?" ? r : "?" + r), t && t !== "#" && (e += t.charAt(0) === "#" ? t : "#" + t), e; } function X(e) { let r = {}; if (e) { let t = e.indexOf("#"); t >= 0 && (r.hash = e.substring(t), e = e.substring(0, t)); let n = e.indexOf("?"); n >= 0 && (r.search = e.substring(n), e = e.substring(0, n)), e && (r.pathname = e); } return r; } function ye(e, r, t = "/") { return je(e, r, t, !1); } function je(e, r, t, n) { let a = typeof r == "string" ? X(r) : r, o = $(a.pathname || "/", t); if (o == null) return null; let l = be(e); He(l); let s = null; for (let i = 0; s == null && i < l.length; ++i) { let c = tt(o); s = Ze( l[i], c, n ); } return s; } function be(e, r = [], t = [], n = "", a = !1) { let o = (l, s, i = a, c) => { let d = { relativePath: c === void 0 ? l.path || "" : c, caseSensitive: l.caseSensitive === !0, childrenIndex: s, route: l }; if (d.relativePath.startsWith("/")) { if (!d.relativePath.startsWith(n) && i) return; C( d.relativePath.startsWith(n), `Absolute route path "${d.relativePath}" nested under path "${n}" is not valid. An absolute child route path must start with the combined path of all its parent routes.` ), d.relativePath = d.relativePath.slice(n.length); } let f = P([n, d.relativePath]), m = t.concat(d); l.children && l.children.length > 0 && (C( // 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 "${f}".` ), be( l.children, r, m, f, i )), !(l.path == null && !l.index) && r.push({ path: f, score: Xe(f, l.index), routesMeta: m }); }; return e.forEach((l, s) => { if (l.path === "" || !l.path?.includes("?")) o(l, s); else for (let i of ve(l.path)) o(l, s, !0, i); }), r; } function ve(e) { let r = e.split("/"); if (r.length === 0) return []; let [t, ...n] = r, a = t.endsWith("?"), o = t.replace(/\?$/, ""); if (n.length === 0) return a ? [o, ""] : [o]; let l = ve(n.join("/")), s = []; return s.push( ...l.map( (i) => i === "" ? o : [o, i].join("/") ) ), a && s.push(...l), s.map( (i) => e.startsWith("/") && i === "" ? "/" : i ); } function He(e) { e.sort( (r, t) => r.score !== t.score ? t.score - r.score : Qe( r.routesMeta.map((n) => n.childrenIndex), t.routesMeta.map((n) => n.childrenIndex) ) ); } var ze = /^:[\w-]+$/, Ke = 3, Je = 2, Ge = 1, Ye = 10, qe = -2, se = (e) => e === "*"; function Xe(e, r) { let t = e.split("/"), n = t.length; return t.some(se) && (n += qe), r && (n += Je), t.filter((a) => !se(a)).reduce( (a, o) => a + (ze.test(o) ? Ke : o === "" ? Ge : Ye), n ); } function Qe(e, r) { return e.length === r.length && e.slice(0, -1).every((n, a) => n === r[a]) ? ( // 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] - r[r.length - 1] ) : ( // Otherwise, it doesn't really make sense to rank non-siblings by index, // so they sort equally. 0 ); } function Ze(e, r, t = !1) { let { routesMeta: n } = e, a = {}, o = "/", l = []; for (let s = 0; s < n.length; ++s) { let i = n[s], c = s === n.length - 1, d = o === "/" ? r : r.slice(o.length) || "/", f = H( { path: i.relativePath, caseSensitive: i.caseSensitive, end: c }, d ), m = i.route; if (!f && c && t && !n[n.length - 1].route.index && (f = H( { path: i.relativePath, caseSensitive: i.caseSensitive, end: !1 }, d )), !f) return null; Object.assign(a, f.params), l.push({ // TODO: Can this as be avoided? params: a, pathname: P([o, f.pathname]), pathnameBase: lt( P([o, f.pathnameBase]) ), route: m }), f.pathnameBase !== "/" && (o = P([o, f.pathnameBase])); } return l; } function H(e, r) { typeof e == "string" && (e = { path: e, caseSensitive: !1, end: !0 }); let [t, n] = et( e.path, e.caseSensitive, e.end ), a = r.match(t); if (!a) return null; let o = a[0], l = o.replace(/(.)\/+$/, "$1"), s = a.slice(1); return { params: n.reduce( (c, { paramName: d, isOptional: f }, m) => { if (d === "*") { let g = s[m] || ""; l = o.slice(0, o.length - g.length).replace(/(.)\/+$/, "$1"); } const p = s[m]; return f && !p ? c[d] = void 0 : c[d] = (p || "").replace(/%2F/g, "/"), c; }, {} ), pathname: o, pathnameBase: l, pattern: e }; } function et(e, r = !1, t = !0) { L( 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 n = [], a = "^" + e.replace(/\/*\*?$/, "").replace(/^\/*/, "/").replace(/[\\.*+^${}|()[\]]/g, "\\$&").replace( /\/:([\w-]+)(\?)?/g, (l, s, i) => (n.push({ paramName: s, isOptional: i != null }), i ? "/?([^\\/]+)?" : "/([^\\/]+)") ).replace(/\/([\w-]+)\?(\/|$)/g, "(/$1)?$2"); return e.endsWith("*") ? (n.push({ paramName: "*" }), a += e === "*" || e === "/*" ? "(.*)$" : "(?:\\/(.+)|\\/*)$") : t ? a += "\\/*$" : e !== "" && e !== "/" && (a += "(?:(?=\\/|$))"), [new RegExp(a, r ? void 0 : "i"), n]; } function tt(e) { try { return e.split("/").map((r) => decodeURIComponent(r).replace(/\//g, "%2F")).join("/"); } catch (r) { return L( !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 (${r}).` ), e; } } function $(e, r) { if (r === "/") return e; if (!e.toLowerCase().startsWith(r.toLowerCase())) return null; let t = r.endsWith("/") ? r.length - 1 : r.length, n = e.charAt(t); return n && n !== "/" ? null : e.slice(t) || "/"; } var rt = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i, nt = (e) => rt.test(e); function at(e, r = "/") { let { pathname: t, search: n = "", hash: a = "" } = typeof e == "string" ? X(e) : e, o; if (t) if (nt(t)) o = t; else { if (t.includes("//")) { let l = t; t = t.replace(/\/\/+/g, "/"), L( !1, `Pathnames cannot have embedded double slashes - normalizing ${l} -> ${t}` ); } t.startsWith("/") ? o = ue(t.substring(1), "/") : o = ue(t, r); } else o = r; return { pathname: o, search: it(n), hash: st(a) }; } function ue(e, r) { let t = r.replace(/\/+$/, "").split("/"); return e.split("/").forEach((a) => { a === ".." ? t.length > 1 && t.pop() : a !== "." && t.push(a); }), t.length > 1 ? t.join("/") : "/"; } function G(e, r, t, n) { return `Cannot include a '${e}' character in a manually specified \`to.${r}\` field [${JSON.stringify( n )}]. Please separate it out to the \`to.${t}\` field. Alternatively you may provide the full path as a string in <Link to="..."> and the router will parse it for you.`; } function ot(e) { return e.filter( (r, t) => t === 0 || r.route.path && r.route.path.length > 0 ); } function xe(e) { let r = ot(e); return r.map( (t, n) => n === r.length - 1 ? t.pathname : t.pathnameBase ); } function we(e, r, t, n = !1) { let a; typeof e == "string" ? a = X(e) : (a = { ...e }, C( !a.pathname || !a.pathname.includes("?"), G("?", "pathname", "search", a) ), C( !a.pathname || !a.pathname.includes("#"), G("#", "pathname", "hash", a) ), C( !a.search || !a.search.includes("#"), G("#", "search", "hash", a) )); let o = e === "" || a.pathname === "", l = o ? "/" : a.pathname, s; if (l == null) s = t; else { let f = r.length - 1; if (!n && l.startsWith("..")) { let m = l.split("/"); for (; m[0] === ".."; ) m.shift(), f -= 1; a.pathname = m.join("/"); } s = f >= 0 ? r[f] : "/"; } let i = at(a, s), c = l && l !== "/" && l.endsWith("/"), d = (o || l === ".") && t.endsWith("/"); return !i.pathname.endsWith("/") && (c || d) && (i.pathname += "/"), i; } var P = (e) => e.join("/").replace(/\/\/+/g, "/"), lt = (e) => e.replace(/\/+$/, "").replace(/^\/*/, "/"), it = (e) => !e || e === "?" ? "" : e.startsWith("?") ? e : "?" + e, st = (e) => !e || e === "#" ? "" : e.startsWith("#") ? e : "#" + e; function ut(e) { return e != null && typeof e.status == "number" && typeof e.statusText == "string" && typeof e.internal == "boolean" && "data" in e; } Object.getOwnPropertyNames(Object.prototype).sort().join("\0"); var Ce = [ "POST", "PUT", "PATCH", "DELETE" ]; new Set( Ce ); var ct = [ "GET", ...Ce ]; new Set(ct); var D = u.createContext(null); D.displayName = "DataRouter"; var z = u.createContext(null); z.displayName = "DataRouterState"; u.createContext(!1); var ke = u.createContext({ isTransitioning: !1 }); ke.displayName = "ViewTransition"; var dt = u.createContext( /* @__PURE__ */ new Map() ); dt.displayName = "Fetchers"; var ft = u.createContext(null); ft.displayName = "Await"; var N = u.createContext( null ); N.displayName = "Navigation"; var Q = u.createContext( null ); Q.displayName = "Location"; var S = u.createContext({ outlet: null, matches: [], isDataRoute: !1 }); S.displayName = "Route"; var Z = u.createContext(null); Z.displayName = "RouteError"; function mt(e, { relative: r } = {}) { C( K(), // 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: t, navigator: n } = u.useContext(N), { hash: a, pathname: o, search: l } = B(e, { relative: r }), s = o; return t !== "/" && (s = o === "/" ? t : P([t, o])), n.createHref({ pathname: s, search: l, hash: a }); } function K() { return u.useContext(Q) != null; } function F() { return C( K(), // 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 Ee = "You should call navigate() in a React.useEffect(), not when your component is first rendered."; function Re(e) { u.useContext(N).static || u.useLayoutEffect(e); } function ht() { let { isDataRoute: e } = u.useContext(S); return e ? Pt() : pt(); } function pt() { C( K(), // 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: r, navigator: t } = u.useContext(N), { matches: n } = u.useContext(S), { pathname: a } = F(), o = JSON.stringify(xe(n)), l = u.useRef(!1); return Re(() => { l.current = !0; }), u.useCallback( (i, c = {}) => { if (L(l.current, Ee), !l.current) return; if (typeof i == "number") { t.go(i); return; } let d = we( i, JSON.parse(o), a, c.relative === "path" ); e == null && r !== "/" && (d.pathname = d.pathname === "/" ? r : P([r, d.pathname])), (c.replace ? t.replace : t.push)( d, c.state, c ); }, [ r, t, o, a, e ] ); } u.createContext(null); function B(e, { relative: r } = {}) { let { matches: t } = u.useContext(S), { pathname: n } = F(), a = JSON.stringify(xe(t)); return u.useMemo( () => we( e, JSON.parse(a), n, r === "path" ), [e, a, n, r] ); } function gt(e, r, t, n, a) { C( K(), // 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: o } = u.useContext(N), { matches: l } = u.useContext(S), s = l[l.length - 1], i = s ? s.params : {}, c = s ? s.pathname : "/", d = s ? s.pathnameBase : "/", f = s && s.route; { let b = f && f.path || ""; Le( c, !f || b.endsWith("*") || b.endsWith("*?"), `You rendered descendant <Routes> (or called \`useRoutes()\`) at "${c}" (under <Route path="${b}">) 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="${b}"> to <Route path="${b === "/" ? "*" : `${b}/*`}">.` ); } let m = F(), p; p = m; let g = p.pathname || "/", x = g; if (d !== "/") { let b = d.replace(/^\//, "").split("/"); x = "/" + g.replace(/^\//, "").split("/").slice(b.length).join("/"); } let h = ye(e, { pathname: x }); return L( f || h != null, `No routes matched location "${p.pathname}${p.search}${p.hash}" ` ), L( h == null || h[h.length - 1].route.element !== void 0 || h[h.length - 1].route.Component !== void 0 || h[h.length - 1].route.lazy !== void 0, `Matched leaf route at location "${p.pathname}${p.search}${p.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.` ), wt( h && h.map( (b) => Object.assign({}, b, { params: Object.assign({}, i, b.params), pathname: P([ d, // Re-encode pathnames that were decoded inside matchRoutes. // Pre-encode `?` and `#` ahead of `encodeLocation` because it uses // `new URL()` internally and we need to prevent it from treating // them as separators o.encodeLocation ? o.encodeLocation( b.pathname.replace(/\?/g, "%3F").replace(/#/g, "%23") ).pathname : b.pathname ]), pathnameBase: b.pathnameBase === "/" ? d : P([ d, // Re-encode pathnames that were decoded inside matchRoutes // Pre-encode `?` and `#` ahead of `encodeLocation` because it uses // `new URL()` internally and we need to prevent it from treating // them as separators o.encodeLocation ? o.encodeLocation( b.pathnameBase.replace(/\?/g, "%3F").replace(/#/g, "%23") ).pathname : b.pathnameBase ]) }) ), l, t, n, a ); } function yt() { let e = Lt(), r = ut(e) ? `${e.status} ${e.statusText}` : e instanceof Error ? e.message : JSON.stringify(e), t = e instanceof Error ? e.stack : null, n = "rgba(200,200,200, 0.5)", a = { padding: "0.5rem", backgroundColor: n }, o = { padding: "2px 4px", backgroundColor: n }, l = null; return console.error( "Error handled by React Router default ErrorBoundary:", e ), l = /* @__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: o }, "ErrorBoundary"), " or", " ", /* @__PURE__ */ u.createElement("code", { style: o }, "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" } }, r), t ? /* @__PURE__ */ u.createElement("pre", { style: a }, t) : null, l); } var bt = /* @__PURE__ */ u.createElement(yt, null), vt = 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, r) { return r.location !== e.location || r.revalidation !== "idle" && e.revalidation === "idle" ? { error: e.error, location: e.location, revalidation: e.revalidation } : { error: e.error !== void 0 ? e.error : r.error, location: r.location, revalidation: e.revalidation || r.revalidation }; } componentDidCatch(e, r) { this.props.onError ? this.props.onError(e, r) : console.error( "React Router caught the following error during render", e ); } render() { return this.state.error !== void 0 ? /* @__PURE__ */ u.createElement(S.Provider, { value: this.props.routeContext }, /* @__PURE__ */ u.createElement( Z.Provider, { value: this.state.error, children: this.props.component } )) : this.props.children; } }; function xt({ routeContext: e, match: r, children: t }) { let n = u.useContext(D); return n && n.static && n.staticContext && (r.route.errorElement || r.route.ErrorBoundary) && (n.staticContext._deepestRenderedBoundaryId = r.route.id), /* @__PURE__ */ u.createElement(S.Provider, { value: e }, t); } function wt(e, r = [], t = null, n = null, a = null) { if (e == null) { if (!t) return null; if (t.errors) e = t.matches; else if (r.length === 0 && !t.initialized && t.matches.length > 0) e = t.matches; else return null; } let o = e, l = t?.errors; if (l != null) { let d = o.findIndex( (f) => f.route.id && l?.[f.route.id] !== void 0 ); C( d >= 0, `Could not find a matching route for errors on route IDs: ${Object.keys( l ).join(",")}` ), o = o.slice( 0, Math.min(o.length, d + 1) ); } let s = !1, i = -1; if (t) for (let d = 0; d < o.length; d++) { let f = o[d]; if ((f.route.HydrateFallback || f.route.hydrateFallbackElement) && (i = d), f.route.id) { let { loaderData: m, errors: p } = t, g = f.route.loader && !m.hasOwnProperty(f.route.id) && (!p || p[f.route.id] === void 0); if (f.route.lazy || g) { s = !0, i >= 0 ? o = o.slice(0, i + 1) : o = [o[0]]; break; } } } let c = t && n ? (d, f) => { n(d, { location: t.location, params: t.matches?.[0]?.params ?? {}, errorInfo: f }); } : void 0; return o.reduceRight( (d, f, m) => { let p, g = !1, x = null, h = null; t && (p = l && f.route.id ? l[f.route.id] : void 0, x = f.route.errorElement || bt, s && (i < 0 && m === 0 ? (Le( "route-fallback", !1, "No `HydrateFallback` element provided to render during initial hydration" ), g = !0, h = null) : i === m && (g = !0, h = f.route.hydrateFallbackElement || null))); let y = r.concat(o.slice(0, m + 1)), b = () => { let w; return p ? w = x : g ? w = h : f.route.Component ? w = /* @__PURE__ */ u.createElement(f.route.Component, null) : f.route.element ? w = f.route.element : w = d, /* @__PURE__ */ u.createElement( xt, { match: f, routeContext: { outlet: d, matches: y, isDataRoute: t != null }, children: w } ); }; return t && (f.route.ErrorBoundary || f.route.errorElement || m === 0) ? /* @__PURE__ */ u.createElement( vt, { location: t.location, revalidation: t.revalidation, component: x, error: p, children: b(), routeContext: { outlet: null, matches: y, isDataRoute: !0 }, onError: c } ) : b(); }, null ); } function ee(e) { return `${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`; } function Ct(e) { let r = u.useContext(D); return C(r, ee(e)), r; } function kt(e) { let r = u.useContext(z); return C(r, ee(e)), r; } function Et(e) { let r = u.useContext(S); return C(r, ee(e)), r; } function te(e) { let r = Et(e), t = r.matches[r.matches.length - 1]; return C( t.route.id, `${e} can only be used on routes that contain a unique "id"` ), t.route.id; } function Rt() { return te( "useRouteId" /* UseRouteId */ ); } function Lt() { let e = u.useContext(Z), r = kt( "useRouteError" /* UseRouteError */ ), t = te( "useRouteError" /* UseRouteError */ ); return e !== void 0 ? e : r.errors?.[t]; } function Pt() { let { router: e } = Ct( "useNavigate" /* UseNavigateStable */ ), r = te( "useNavigate" /* UseNavigateStable */ ), t = u.useRef(!1); return Re(() => { t.current = !0; }), u.useCallback( async (a, o = {}) => { L(t.current, Ee), t.current && (typeof a == "number" ? e.navigate(a) : await e.navigate(a, { fromRouteId: r, ...o })); }, [e, r] ); } var ce = {}; function Le(e, r, t) { !r && !ce[e] && (ce[e] = !0, L(!1, t)); } u.memo(Nt); function Nt({ routes: e, future: r, state: t, unstable_onError: n }) { return gt(e, void 0, t, n, r); } var _ = "get", j = "application/x-www-form-urlencoded"; function J(e) { return e != null && typeof e.tagName == "string"; } function St(e) { return J(e) && e.tagName.toLowerCase() === "button"; } function $t(e) { return J(e) && e.tagName.toLowerCase() === "form"; } function At(e) { return J(e) && e.tagName.toLowerCase() === "input"; } function Ft(e) { return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey); } function Tt(e, r) { return e.button === 0 && // Ignore everything but left clicks (!r || r === "_self") && // Let browser handle "target=_blank" etc. !Ft(e); } var V = null; function It() { if (V === null) try { new FormData( document.createElement("form"), // @ts-expect-error if FormData supports the submitter parameter, this will throw 0 ), V = !1; } catch { V = !0; } return V; } var Dt = /* @__PURE__ */ new Set([ "application/x-www-form-urlencoded", "multipart/form-data", "text/plain" ]); function Y(e) { return e != null && !Dt.has(e) ? (L( !1, `"${e}" is not a valid \`encType\` for \`<Form>\`/\`<fetcher.Form>\` and will default to "${j}"` ), null) : e; } function Ut(e, r) { let t, n, a, o, l; if ($t(e)) { let s = e.getAttribute("action"); n = s ? $(s, r) : null, t = e.getAttribute("method") || _, a = Y(e.getAttribute("enctype")) || j, o = new FormData(e); } else if (St(e) || At(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 i = e.getAttribute("formaction") || s.getAttribute("action"); if (n = i ? $(i, r) : null, t = e.getAttribute("formmethod") || s.getAttribute("method") || _, a = Y(e.getAttribute("formenctype")) || Y(s.getAttribute("enctype")) || j, o = new FormData(s, e), !It()) { let { name: c, type: d, value: f } = e; if (d === "image") { let m = c ? `${c}.` : ""; o.append(`${m}x`, "0"), o.append(`${m}y`, "0"); } else c && o.append(c, f); } } else { if (J(e)) throw new Error( 'Cannot submit element that is not <form>, <button>, or <input type="submit|image">' ); t = _, n = null, a = j, l = e; } return o && a === "text/plain" && (l = o, o = void 0), { action: n, method: t.toLowerCase(), encType: a, formData: o, body: l }; } Object.getOwnPropertyNames(Object.prototype).sort().join("\0"); function re(e, r) { if (e === !1 || e === null || typeof e > "u") throw new Error(r); } function Mt(e, r, 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.${t}` : r && $(n.pathname, r) === "/" ? n.pathname = `${r.replace(/\/$/, "")}/_root.${t}` : n.pathname = `${n.pathname.replace(/\/$/, "")}.${t}`, n; } async function Bt(e, r) { if (e.id in r) return r[e.id]; try { let t = await import( /* @vite-ignore */ /* webpackIgnore: true */ e.module ); return r[e.id] = t, t; } catch (t) { return console.error( `Error loading route module \`${e.module}\`, reloading page...` ), console.error(t), window.__reactRouterContext && window.__reactRouterContext.isSpaMode, window.location.reload(), new Promise(() => { }); } } function Ot(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 Wt(e, r, t) { let n = await Promise.all( e.map(async (a) => { let o = r.routes[a.route.id]; if (o) { let l = await Bt(o, t); return l.links ? l.links() : []; } return []; }) ); return Ht( n.flat(1).filter(Ot).filter((a) => a.rel === "stylesheet" || a.rel === "preload").map( (a) => a.rel === "stylesheet" ? { ...a, rel: "prefetch", as: "style" } : { ...a, rel: "prefetch" } ) ); } function de(e, r, t, n, a, o) { let l = (i, c) => t[c] ? i.route.id !== t[c].route.id : !0, s = (i, c) => ( // param change, /users/123 -> /users/456 t[c].pathname !== i.pathname || // splat param changed, which is not present in match.path // e.g. /files/images/avatar.jpg -> files/finances.xls t[c].route.path?.endsWith("*") && t[c].params["*"] !== i.params["*"] ); return o === "assets" ? r.filter( (i, c) => l(i, c) || s(i, c) ) : o === "data" ? r.filter((i, c) => { let d = n.routes[i.route.id]; if (!d || !d.hasLoader) return !1; if (l(i, c) || s(i, c)) return !0; if (i.route.shouldRevalidate) { let f = i.route.shouldRevalidate({ currentUrl: new URL( a.pathname + a.search + a.hash, window.origin ), currentParams: t[0]?.params || {}, nextUrl: new URL(e, window.origin), nextParams: i.params, defaultShouldRevalidate: !0 }); if (typeof f == "boolean") return f; } return !0; }) : []; } function Vt(e, r, { includeHydrateFallback: t } = {}) { return _t( e.map((n) => { let a = r.routes[n.route.id]; if (!a) return []; let o = [a.module]; return a.clientActionModule && (o = o.concat(a.clientActionModule)), a.clientLoaderModule && (o = o.concat(a.clientLoaderModule)), t && a.hydrateFallbackModule && (o = o.concat(a.hydrateFallbackModule)), a.imports && (o = o.concat(a.imports)), o; }).flat(1) ); } function _t(e) { return [...new Set(e)]; } function jt(e) { let r = {}, t = Object.keys(e).sort(); for (let n of t) r[n] = e[n]; return r; } function Ht(e, r) { let t = /* @__PURE__ */ new Set(); return new Set(r), e.reduce((n, a) => { let o = JSON.stringify(jt(a)); return t.has(o) || (t.add(o), n.push({ key: o, link: a })), n; }, []); } function Pe() { let e = u.useContext(D); return re( e, "You must render this element inside a <DataRouterContext.Provider> element" ), e; } function zt() { let e = u.useContext(z); return re( e, "You must render this element inside a <DataRouterStateContext.Provider> element" ), e; } var ne = u.createContext(void 0); ne.displayName = "FrameworkContext"; function Ne() { let e = u.useContext(ne); return re( e, "You must render this element inside a <HydratedRouter> element" ), e; } function Kt(e, r) { let t = u.useContext(ne), [n, a] = u.useState(!1), [o, l] = u.useState(!1), { onFocus: s, onBlur: i, onMouseEnter: c, onMouseLeave: d, onTouchStart: f } = r, m = u.useRef(null); u.useEffect(() => { if (e === "render" && l(!0), e === "viewport") { let x = (y) => { y.forEach((b) => { l(b.isIntersecting); }); }, h = new IntersectionObserver(x, { threshold: 0.5 }); return m.current && h.observe(m.current), () => { h.disconnect(); }; } }, [e]), u.useEffect(() => { if (n) { let x = setTimeout(() => { l(!0); }, 100); return () => { clearTimeout(x); }; } }, [n]); let p = () => { a(!0); }, g = () => { a(!1), l(!1); }; return t ? e !== "intent" ? [o, m, {}] : [ o, m, { onFocus: M(s, p), onBlur: M(i, g), onMouseEnter: M(c, p), onMouseLeave: M(d, g), onTouchStart: M(f, p) } ] : [!1, m, {}]; } function M(e, r) { return (t) => { e && e(t), t.defaultPrevented || r(t); }; } function Jt({ page: e, ...r }) { let { router: t } = Pe(), n = u.useMemo( () => ye(t.routes, e, t.basename), [t.routes, e, t.basename] ); return n ? /* @__PURE__ */ u.createElement(Yt, { page: e, matches: n, ...r }) : null; } function Gt(e) { let { manifest: r, routeModules: t } = Ne(), [n, a] = u.useState([]); return u.useEffect(() => { let o = !1; return Wt(e, r, t).then( (l) => { o || a(l); } ), () => { o = !0; }; }, [e, r, t]), n; } function Yt({ page: e, matches: r, ...t }) { let n = F(), { manifest: a, routeModules: o } = Ne(), { basename: l } = Pe(), { loaderData: s, matches: i } = zt(), c = u.useMemo( () => de( e, r, i, a, n, "data" ), [e, r, i, a, n] ), d = u.useMemo( () => de( e, r, i, a, n, "assets" ), [e, r, i, a, n] ), f = u.useMemo(() => { if (e === n.pathname + n.search + n.hash) return []; let g = /* @__PURE__ */ new Set(), x = !1; if (r.forEach((y) => { let b = a.routes[y.route.id]; !b || !b.hasLoader || (!c.some((w) => w.route.id === y.route.id) && y.route.id in s && o[y.route.id]?.shouldRevalidate || b.hasClientLoader ? x = !0 : g.add(y.route.id)); }), g.size === 0) return []; let h = Mt(e, l, "data"); return x && g.size > 0 && h.searchParams.set( "_routes", r.filter((y) => g.has(y.route.id)).map((y) => y.route.id).join(",") ), [h.pathname + h.search]; }, [ l, s, n, a, c, r, e, o ]), m = u.useMemo( () => Vt(d, a), [d, a] ), p = Gt(d); return /* @__PURE__ */ u.createElement(u.Fragment, null, f.map((g) => /* @__PURE__ */ u.createElement("link", { key: g, rel: "prefetch", as: "fetch", href: g, ...t })), m.map((g) => /* @__PURE__ */ u.createElement("link", { key: g, rel: "modulepreload", href: g, ...t })), p.map(({ key: g, link: x }) => ( // these don't spread `linkProps` because they are full link descriptors // already with their own props /* @__PURE__ */ u.createElement("link", { key: g, nonce: t.nonce, ...x }) ))); } function qt(...e) { return (r) => { e.forEach((t) => { typeof t == "function" ? t(r) : t != null && (t.current = r); }); }; } var Se = typeof window < "u" && typeof window.document < "u" && typeof window.document.createElement < "u"; try { Se && (window.__reactRouterVersion = // @ts-expect-error "7.9.6"); } catch { } var $e = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i, ae = u.forwardRef( function({ onClick: r, discover: t = "render", prefetch: n = "none", relative: a, reloadDocument: o, replace: l, state: s, target: i, to: c, preventScrollReset: d, viewTransition: f, ...m }, p) { let { basename: g } = u.useContext(N), x = typeof c == "string" && $e.test(c), h, y = !1; if (typeof c == "string" && x && (h = c, Se)) try { let E = new URL(window.location.href), I = c.startsWith("//") ? new URL(E.protocol + c) : new URL(c), le = $(I.pathname, g); I.origin === E.origin && le != null ? c = le + I.search + I.hash : y = !0; } catch { L( !1, `<Link to="${c}"> contains an invalid URL which will probably break when clicked - please update to a valid URL path.` ); } let b = mt(c, { relative: a }), [w, T, A] = Kt( n, m ), O = er(c, { replace: l, state: s, target: i, preventScrollReset: d, relative: a, viewTransition: f }); function U(E) { r && r(E), E.defaultPrevented || O(E); } let W = ( // eslint-disable-next-line jsx-a11y/anchor-has-content /* @__PURE__ */ u.createElement( "a", { ...m, ...A, href: h || b, onClick: y || o ? r : U, ref: qt(p, T), target: i, "data-discover": !x && t === "render" ? "true" : void 0 } ) ); return w && !x ? /* @__PURE__ */ u.createElement(u.Fragment, null, W, /* @__PURE__ */ u.createElement(Jt, { page: b })) : W; } ); ae.displayName = "Link"; var Xt = u.forwardRef( function({ "aria-current": r = "page", caseSensitive: t = !1, className: n = "", end: a = !1, style: o, to: l, viewTransition: s, children: i, ...c }, d) { let f = B(l, { relative: c.relative }), m = F(), p = u.useContext(z), { navigator: g, basename: x } = u.useContext(N), h = 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 or(f) && s === !0, y = g.encodeLocation ? g.encodeLocation(f).pathname : f.pathname, b = m.pathname, w = p && p.navigation && p.navigation.location ? p.navigation.location.pathname : null; t || (b = b.toLowerCase(), w = w ? w.toLowerCase() : null, y = y.toLowerCase()), w && x && (w = $(w, x) || w); const T = y !== "/" && y.endsWith("/") ? y.length - 1 : y.length; let A = b === y || !a && b.startsWith(y) && b.charAt(T) === "/", O = w != null && (w === y || !a && w.startsWith(y) && w.charAt(y.length) === "/"), U = { isActive: A, isPending: O, isTransitioning: h }, W = A ? r : void 0, E; typeof n == "function" ? E = n(U) : E = [ n, A ? "active" : null, O ? "pending" : null, h ? "transitioning" : null ].filter(Boolean).join(" "); let I = typeof o == "function" ? o(U) : o; return /* @__PURE__ */ u.createElement( ae, { ...c, "aria-current": W, className: E, ref: d, style: I, to: l, viewTransition: s }, typeof i == "function" ? i(U) : i ); } ); Xt.displayName = "NavLink"; var Qt = u.forwardRef( ({ discover: e = "render", fetcherKey: r, navigate: t, reloadDocument: n, replace: a, state: o, method: l = _, action: s, onSubmit: i, relative: c, preventScrollReset: d, viewTransition: f, ...m }, p) => { let g = nr(), x = ar(s, { relative: c }), h = l.toLowerCase() === "get" ? "get" : "post", y = typeof s == "string" && $e.test(s), b = (w) => { if (i && i(w), w.defaultPrevented) return; w.preventDefault(); let T = w.nativeEvent.submitter, A = T?.getAttribute("formmethod") || l; g(T || w.currentTarget, { fetcherKey: r, method: A, navigate: t, replace: a, state: o, relative: c, preventScrollReset: d, viewTransition: f }); }; return /* @__PURE__ */ u.createElement( "form", { ref: p, method: h, action: x, onSubmit: n ? i : b, ...m, "data-discover": !y && e === "render" ? "true" : void 0 } ); } ); Qt.displayName = "Form"; function Zt(e) { return `${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`; } function Ae(e) { let r = u.useContext(D); return C(r, Zt(e)), r; } function er(e, { target: r, replace: t, state: n, preventScrollReset: a, relative: o, viewTransition: l } = {}) { let s = ht(), i = F(), c = B(e, { relative: o }); return u.useCallback( (d) => { if (Tt(d, r)) { d.preventDefault(); let f = t !== void 0 ? t : q(i) === q(c); s(e, { replace: f, state: n, preventScrollReset: a, relative: o, viewTransition: l }); } }, [ i, s, c, t, n, r, e, a, o, l ] ); } var tr = 0, rr = () => `__${String(++tr)}__`; function nr() { let { router: e } = Ae( "useSubmit" /* UseSubmit */ ), { basename: r } = u.useContext(N), t = Rt(); return u.useCallback( async (n, a = {}) => { let { action: o, method: l, encType: s, formData: i, body: c } = Ut( n, r ); if (a.navigate === !1) { let d = a.fetcherKey || rr(); await e.fetch(d, t, a.action || o, { preventScrollReset: a.preventScrollReset, formData: i, body: c, formMethod: a.method || l, formEncType: a.encType || s, flushSync: a.flushSync }); } else await e.navigate(a.action || o, { preventScrollReset: a.preventScrollReset, formData: i, body: c, formMethod: a.method || l, formEncType: a.encType || s, replace: a.replace, state: a.state, fromRouteId: t, flushSync: a.flushSync, viewTransition: a.viewTransition }); }, [e, r, t] ); } function ar(e, { relative: r } = {}) { let { basename: t } = u.useContext(N), n = u.useContext(S); C(n, "useFormAction must be used inside a RouteContext"); let [a] = n.matches.slice(-1), o = { ...B(e || ".", { relative: r }) }, l = F(); if (e == null) { o.search = l.search; let s = new URLSearchParams(o.search), i = s.getAll("index"); if (i.some((d) => d === "")) { s.delete("index"), i.filter((f) => f).forEach((f) => s.append("index", f)); let d = s.toString(); o.search = d ? `?${d}` : ""; } } return (!e || e === ".") && a.route.index && (o.search = o.search ? o.search.replace(/^\?/, "?index&") : "?index"), t !== "/" && (o.pathname = o.pathname === "/" ? t : P([t, o.pathname])), q(o); } function or(e, { relative: r } = {}) { let t = u.useContext(ke); C( t != null, "`use