@route-weaver/react
Version:
React hooks for @route-weaver/core
40 lines (36 loc) • 24 kB
JavaScript
;var Be=Object.create;var W=Object.defineProperty;var ze=Object.getOwnPropertyDescriptor;var We=Object.getOwnPropertyNames;var Ke=Object.getPrototypeOf,Ye=Object.prototype.hasOwnProperty;var $e=(e,t)=>{for(var r in t)W(e,r,{get:t[r],enumerable:!0})},Re=(e,t,r,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of We(t))!Ye.call(e,n)&&n!==r&&W(e,n,{get:()=>t[n],enumerable:!(a=ze(t,n))||a.enumerable});return e};var te=(e,t,r)=>(r=e!=null?Be(Ke(e)):{},Re(t||!e||!e.__esModule?W(r,"default",{value:e,enumerable:!0}):r,e)),Je=e=>Re(W({},"__esModule",{value:!0}),e);var Zt={};$e(Zt,{createRouteWeaverReactApi:()=>je});module.exports=Je(Zt);var Q=require("react");var d=te(require("react")),Rt=te(require("react-dom"));var c=te(require("react"));function ne(){return ne=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var a in r)Object.prototype.hasOwnProperty.call(r,a)&&(e[a]=r[a])}return e},ne.apply(this,arguments)}var L;(function(e){e.Pop="POP",e.Push="PUSH",e.Replace="REPLACE"})(L||(L={}));function m(e,t){if(e===!1||e===null||typeof e=="undefined")throw new Error(t)}function x(e,t){if(!e){typeof console!="undefined"&&console.warn(t);try{throw new Error(t)}catch(r){}}}function T(e){let{pathname:t="/",search:r="",hash:a=""}=e;return r&&r!=="?"&&(t+=r.charAt(0)==="?"?r:"?"+r),a&&a!=="#"&&(t+=a.charAt(0)==="#"?a:"#"+a),t}function F(e){let t={};if(e){let r=e.indexOf("#");r>=0&&(t.hash=e.substr(r),e=e.substr(0,r));let a=e.indexOf("?");a>=0&&(t.search=e.substr(a),e=e.substr(0,a)),e&&(t.pathname=e)}return t}var Ee;(function(e){e.data="data",e.deferred="deferred",e.redirect="redirect",e.error="error"})(Ee||(Ee={}));function be(e,t){let{route:r,pathname:a,params:n}=e;return{id:r.id,pathname:a,params:n,data:t[r.id],handle:r.handle}}function O(e,t){typeof e=="string"&&(e={path:e,caseSensitive:!1,end:!0});let[r,a]=Ge(e.path,e.caseSensitive,e.end),n=t.match(r);if(!n)return null;let o=n[0],i=o.replace(/(.)\/+$/,"$1"),s=n.slice(1);return{params:a.reduce((u,f,h)=>{let{paramName:p,isOptional:w}=f;if(p==="*"){let E=s[h]||"";i=o.slice(0,o.length-E.length).replace(/(.)\/+$/,"$1")}let R=s[h];return w&&!R?u[p]=void 0:u[p]=(R||"").replace(/%2F/g,"/"),u},{}),pathname:o,pathnameBase:i,pattern:e}}function Ge(e,t,r){t===void 0&&(t=!1),r===void 0&&(r=!0),x(e==="*"||!e.endsWith("*")||e.endsWith("/*"),'Route path "'+e+'" will be treated as if it were '+('"'+e.replace(/\*$/,"/*")+'" because the `*` character must ')+"always follow a `/` in the pattern. To get rid of this warning, "+('please change the route path to "'+e.replace(/\*$/,"/*")+'".'));let a=[],n="^"+e.replace(/\/*\*?$/,"").replace(/^\/*/,"/").replace(/[\\.*+^${}|()[\]]/g,"\\$&").replace(/\/:([\w-]+)(\?)?/g,(i,s,l)=>(a.push({paramName:s,isOptional:l!=null}),l?"/?([^\\/]+)?":"/([^\\/]+)"));return e.endsWith("*")?(a.push({paramName:"*"}),n+=e==="*"||e==="/*"?"(.*)$":"(?:\\/(.+)|\\/*)$"):r?n+="\\/*$":e!==""&&e!=="/"&&(n+="(?:(?=\\/|$))"),[new RegExp(n,t?void 0:"i"),a]}function D(e,t){if(t==="/")return e;if(!e.toLowerCase().startsWith(t.toLowerCase()))return null;let r=t.endsWith("/")?t.length-1:t.length,a=e.charAt(r);return a&&a!=="/"?null:e.slice(r)||"/"}function ae(e,t){t===void 0&&(t="/");let{pathname:r,search:a="",hash:n=""}=typeof e=="string"?F(e):e;return{pathname:r?r.startsWith("/")?r:Qe(r,t):t,search:qe(a),hash:et(n)}}function Qe(e,t){let r=t.replace(/\/+$/,"").split("/");return e.split("/").forEach(n=>{n===".."?r.length>1&&r.pop():n!=="."&&r.push(n)}),r.length>1?r.join("/"):"/"}function re(e,t,r,a){return"Cannot include a '"+e+"' character in a manually specified "+("`to."+t+"` field ["+JSON.stringify(a)+"]. Please separate it out to the ")+("`to."+r+"` field. Alternatively you may provide the full path as ")+'a string in <Link to="..."> and the router will parse it for you.'}function Ze(e){return e.filter((t,r)=>r===0||t.route.path&&t.route.path.length>0)}function oe(e,t){let r=Ze(e);return t?r.map((a,n)=>n===r.length-1?a.pathname:a.pathnameBase):r.map(a=>a.pathnameBase)}function ie(e,t,r,a){a===void 0&&(a=!1);let n;typeof e=="string"?n=F(e):(n=ne({},e),m(!n.pathname||!n.pathname.includes("?"),re("?","pathname","search",n)),m(!n.pathname||!n.pathname.includes("#"),re("#","pathname","hash",n)),m(!n.search||!n.search.includes("#"),re("#","search","hash",n)));let o=e===""||n.pathname==="",i=o?"/":n.pathname,s;if(i==null)s=r;else{let h=t.length-1;if(!a&&i.startsWith("..")){let p=i.split("/");for(;p[0]==="..";)p.shift(),h-=1;n.pathname=p.join("/")}s=h>=0?t[h]:"/"}let l=ae(n,s),u=i&&i!=="/"&&i.endsWith("/"),f=(o||i===".")&&r.endsWith("/");return!l.pathname.endsWith("/")&&(u||f)&&(l.pathname+="/"),l}var j=e=>e.join("/").replace(/\/\/+/g,"/");var qe=e=>!e||e==="?"?"":e.startsWith("?")?e:"?"+e,et=e=>!e||e==="#"?"":e.startsWith("#")?e:"#"+e;var we=["post","put","patch","delete"],er=new Set(we),tt=["get",...we],tr=new Set(tt);var rr=Symbol("deferred");function K(){return K=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var a in r)Object.prototype.hasOwnProperty.call(r,a)&&(e[a]=r[a])}return e},K.apply(this,arguments)}var M=c.createContext(null);process.env.NODE_ENV!=="production"&&(M.displayName="DataRouter");var A=c.createContext(null);process.env.NODE_ENV!=="production"&&(A.displayName="DataRouterState");var ut=c.createContext(null);process.env.NODE_ENV!=="production"&&(ut.displayName="Await");var b=c.createContext(null);process.env.NODE_ENV!=="production"&&(b.displayName="Navigation");var V=c.createContext(null);process.env.NODE_ENV!=="production"&&(V.displayName="Location");var P=c.createContext({outlet:null,matches:[],isDataRoute:!1});process.env.NODE_ENV!=="production"&&(P.displayName="Route");var ct=c.createContext(null);process.env.NODE_ENV!=="production"&&(ct.displayName="RouteError");function le(e,t){let{relative:r}=t===void 0?{}:t;k()||(process.env.NODE_ENV!=="production"?m(!1,"useHref() may be used only in the context of a <Router> component."):m(!1));let{basename:a,navigator:n}=c.useContext(b),{hash:o,pathname:i,search:s}=C(e,{relative:r}),l=i;return a!=="/"&&(l=i==="/"?a:j([a,i])),n.createHref({pathname:l,search:s,hash:o})}function k(){return c.useContext(V)!=null}function S(){return k()||(process.env.NODE_ENV!=="production"?m(!1,"useLocation() may be used only in the context of a <Router> component."):m(!1)),c.useContext(V).location}var Pe="You should call navigate() in a React.useEffect(), not when your component is first rendered.";function Ce(e){c.useContext(b).static||c.useLayoutEffect(e)}function se(){let{isDataRoute:e}=c.useContext(P);return e?pt():dt()}function dt(){k()||(process.env.NODE_ENV!=="production"?m(!1,"useNavigate() may be used only in the context of a <Router> component."):m(!1));let e=c.useContext(M),{basename:t,future:r,navigator:a}=c.useContext(b),{matches:n}=c.useContext(P),{pathname:o}=S(),i=JSON.stringify(oe(n,r.v7_relativeSplatPath)),s=c.useRef(!1);return Ce(()=>{s.current=!0}),c.useCallback(function(u,f){if(f===void 0&&(f={}),process.env.NODE_ENV!=="production"&&x(s.current,Pe),!s.current)return;if(typeof u=="number"){a.go(u);return}let h=ie(u,JSON.parse(i),o,f.relative==="path");e==null&&t!=="/"&&(h.pathname=h.pathname==="/"?t:j([t,h.pathname])),(f.replace?a.replace:a.push)(h,f.state,f)},[t,a,i,o,e])}function C(e,t){let{relative:r}=t===void 0?{}:t,{future:a}=c.useContext(b),{matches:n}=c.useContext(P),{pathname:o}=S(),i=JSON.stringify(oe(n,a.v7_relativeSplatPath));return c.useMemo(()=>ie(e,JSON.parse(i),o,r==="path"),[e,i,o,r])}var _e=function(e){return e.UseBlocker="useBlocker",e.UseRevalidator="useRevalidator",e.UseNavigateStable="useNavigate",e}(_e||{}),H=function(e){return e.UseBlocker="useBlocker",e.UseLoaderData="useLoaderData",e.UseActionData="useActionData",e.UseRouteError="useRouteError",e.UseNavigation="useNavigation",e.UseRouteLoaderData="useRouteLoaderData",e.UseMatches="useMatches",e.UseRevalidator="useRevalidator",e.UseNavigateStable="useNavigate",e.UseRouteId="useRouteId",e}(H||{});function ue(e){return e+" must be used within a data router. See https://reactrouter.com/v6/routers/picking-a-router."}function ft(e){let t=c.useContext(M);return t||(process.env.NODE_ENV!=="production"?m(!1,ue(e)):m(!1)),t}function Le(e){let t=c.useContext(A);return t||(process.env.NODE_ENV!=="production"?m(!1,ue(e)):m(!1)),t}function ht(e){let t=c.useContext(P);return t||(process.env.NODE_ENV!=="production"?m(!1,ue(e)):m(!1)),t}function Te(e){let t=ht(e),r=t.matches[t.matches.length-1];return r.route.id||(process.env.NODE_ENV!=="production"?m(!1,e+' can only be used on routes that contain a unique "id"'):m(!1)),r.route.id}function ce(){return Te(H.UseRouteId)}function de(){return Le(H.UseNavigation).navigation}function fe(){let{matches:e,loaderData:t}=Le(H.UseMatches);return c.useMemo(()=>e.map(r=>be(r,t)),[e,t])}function pt(){let{router:e}=ft(_e.UseNavigateStable),t=Te(H.UseNavigateStable),r=c.useRef(!1);return Ce(()=>{r.current=!0}),c.useCallback(function(n,o){o===void 0&&(o={}),process.env.NODE_ENV!=="production"&&x(r.current,Pe),r.current&&(typeof n=="number"?e.navigate(n):e.navigate(n,K({fromRouteId:t},o)))},[e,t])}var Se={};function mt(e,t){process.env.NODE_ENV!=="production"&&!Se[t]&&(Se[t]=!0,console.warn(t))}var U=(e,t,r)=>mt(e,"\u26A0\uFE0F React Router Future Flag Warning: "+t+". "+("You can use the `"+e+"` future flag to opt-in early. ")+("For more information, see "+r+"."));function Fe(e,t){(e==null?void 0:e.v7_startTransition)===void 0&&U("v7_startTransition","React Router will begin wrapping state updates in `React.startTransition` in v7","https://reactrouter.com/v6/upgrading/future#v7_starttransition"),(e==null?void 0:e.v7_relativeSplatPath)===void 0&&(!t||t.v7_relativeSplatPath===void 0)&&U("v7_relativeSplatPath","Relative route resolution within Splat routes is changing in v7","https://reactrouter.com/v6/upgrading/future#v7_relativesplatpath"),t&&(t.v7_fetcherPersist===void 0&&U("v7_fetcherPersist","The persistence behavior of fetchers is changing in v7","https://reactrouter.com/v6/upgrading/future#v7_fetcherpersist"),t.v7_normalizeFormMethod===void 0&&U("v7_normalizeFormMethod","Casing of `formMethod` fields is being normalized to uppercase in v7","https://reactrouter.com/v6/upgrading/future#v7_normalizeformmethod"),t.v7_partialHydration===void 0&&U("v7_partialHydration","`RouterProvider` hydration behavior is changing in v7","https://reactrouter.com/v6/upgrading/future#v7_partialhydration"),t.v7_skipActionErrorRevalidation===void 0&&U("v7_skipActionErrorRevalidation","The revalidation behavior after 4xx/5xx `action` responses is changing in v7","https://reactrouter.com/v6/upgrading/future#v7_skipactionerrorrevalidation"))}var vt="startTransition",ur=c[vt];function he(e){let{basename:t="/",children:r=null,location:a,navigationType:n=L.Pop,navigator:o,static:i=!1,future:s}=e;k()&&(process.env.NODE_ENV!=="production"?m(!1,"You cannot render a <Router> inside another <Router>. You should never have more than one in your app."):m(!1));let l=t.replace(/^\/*/,"/"),u=c.useMemo(()=>({basename:l,navigator:o,static:i,future:K({v7_relativeSplatPath:!1},s)}),[l,s,o,i]);typeof a=="string"&&(a=F(a));let{pathname:f="/",search:h="",hash:p="",state:w=null,key:R="default"}=a,E=c.useMemo(()=>{let N=D(f,l);return N==null?null:{location:{pathname:N,search:h,hash:p,state:w,key:R},navigationType:n}},[l,f,h,p,w,R,n]);return process.env.NODE_ENV!=="production"&&x(E!=null,'<Router basename="'+l+'"> is not able to match the URL '+('"'+f+h+p+'" because it does not start with the ')+"basename, so the <Router> won't render anything."),E==null?null:c.createElement(b.Provider,{value:u},c.createElement(V.Provider,{children:r,value:E}))}var cr=new Promise(()=>{});function _(){return _=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var a in r)Object.prototype.hasOwnProperty.call(r,a)&&(e[a]=r[a])}return e},_.apply(this,arguments)}function ve(e,t){if(e==null)return{};var r={},a=Object.keys(e),n,o;for(o=0;o<a.length;o++)n=a[o],!(t.indexOf(n)>=0)&&(r[n]=e[n]);return r}var J="get",X="application/x-www-form-urlencoded";function G(e){return e!=null&&typeof e.tagName=="string"}function Et(e){return G(e)&&e.tagName.toLowerCase()==="button"}function bt(e){return G(e)&&e.tagName.toLowerCase()==="form"}function wt(e){return G(e)&&e.tagName.toLowerCase()==="input"}function St(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function Dt(e,t){return e.button===0&&(!t||t==="_self")&&!St(e)}var Y=null;function Nt(){if(Y===null)try{new FormData(document.createElement("form"),0),Y=!1}catch(e){Y=!0}return Y}var xt=new Set(["application/x-www-form-urlencoded","multipart/form-data","text/plain"]);function pe(e){return e!=null&&!xt.has(e)?(process.env.NODE_ENV!=="production"&&x(!1,'"'+e+'" is not a valid `encType` for `<Form>`/`<fetcher.Form>` '+('and will default to "'+X+'"')),null):e}function Pt(e,t){let r,a,n,o,i;if(bt(e)){let s=e.getAttribute("action");a=s?D(s,t):null,r=e.getAttribute("method")||J,n=pe(e.getAttribute("enctype"))||X,o=new FormData(e)}else if(Et(e)||wt(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 l=e.getAttribute("formaction")||s.getAttribute("action");if(a=l?D(l,t):null,r=e.getAttribute("formmethod")||s.getAttribute("method")||J,n=pe(e.getAttribute("formenctype"))||pe(s.getAttribute("enctype"))||X,o=new FormData(s,e),!Nt()){let{name:u,type:f,value:h}=e;if(f==="image"){let p=u?u+".":"";o.append(p+"x","0"),o.append(p+"y","0")}else u&&o.append(u,h)}}else{if(G(e))throw new Error('Cannot submit element that is not <form>, <button>, or <input type="submit|image">');r=J,a=null,n=X,i=e}return o&&n==="text/plain"&&(i=o,o=void 0),{action:a,method:r.toLowerCase(),encType:n,formData:o,body:i}}var Ct=["onClick","relative","reloadDocument","replace","state","target","to","preventScrollReset","viewTransition"],_t=["aria-current","caseSensitive","className","end","style","to","viewTransition","children"],Lt=["fetcherKey","navigate","reloadDocument","replace","state","method","action","onSubmit","relative","preventScrollReset","viewTransition"],Tt="6";try{window.__reactRouterVersion=Tt}catch(e){}var Me=d.createContext({isTransitioning:!1});process.env.NODE_ENV!=="production"&&(Me.displayName="ViewTransition");var Ft=d.createContext(new Map);process.env.NODE_ENV!=="production"&&(Ft.displayName="Fetchers");var Ot="startTransition",Oe=d[Ot],Ut="flushSync",Br=Rt[Ut],Mt="useId",zr=d[Mt];function At(e){let{basename:t,children:r,future:a,history:n}=e,[o,i]=d.useState({action:n.action,location:n.location}),{v7_startTransition:s}=a||{},l=d.useCallback(u=>{s&&Oe?Oe(()=>i(u)):i(u)},[i,s]);return d.useLayoutEffect(()=>n.listen(l),[n,l]),d.useEffect(()=>Fe(a),[a]),d.createElement(he,{basename:t,children:r,location:o.location,navigationType:o.action,navigator:n,future:a})}process.env.NODE_ENV!=="production"&&(At.displayName="unstable_HistoryRouter");var It=typeof window!="undefined"&&typeof window.document!="undefined"&&typeof window.document.createElement!="undefined",jt=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,Ae=d.forwardRef(function(t,r){let{onClick:a,relative:n,reloadDocument:o,replace:i,state:s,target:l,to:u,preventScrollReset:f,viewTransition:h}=t,p=ve(t,Ct),{basename:w}=d.useContext(b),R,E=!1;if(typeof u=="string"&&jt.test(u)&&(R=u,It))try{let g=new URL(window.location.href),y=u.startsWith("//")?new URL(g.protocol+u):new URL(u),z=D(y.pathname,w);y.origin===g.origin&&z!=null?u=z+y.search+y.hash:E=!0}catch(g){process.env.NODE_ENV!=="production"&&x(!1,'<Link to="'+u+'"> contains an invalid URL which will probably break when clicked - please update to a valid URL path.')}let N=le(u,{relative:n}),I=zt(u,{replace:i,state:s,target:l,preventScrollReset:f,relative:n,viewTransition:h});function v(g){a&&a(g),g.defaultPrevented||I(g)}return d.createElement("a",_({},p,{href:R||N,onClick:E||o?a:v,ref:r,target:l}))});process.env.NODE_ENV!=="production"&&(Ae.displayName="Link");var Vt=d.forwardRef(function(t,r){let{"aria-current":a="page",caseSensitive:n=!1,className:o="",end:i=!1,style:s,to:l,viewTransition:u,children:f}=t,h=ve(t,_t),p=C(l,{relative:h.relative}),w=S(),R=d.useContext(A),{navigator:E,basename:N}=d.useContext(b),I=R!=null&&Qt(p)&&u===!0,v=E.encodeLocation?E.encodeLocation(p).pathname:p.pathname,g=w.pathname,y=R&&R.navigation&&R.navigation.location?R.navigation.location.pathname:null;n||(g=g.toLowerCase(),y=y?y.toLowerCase():null,v=v.toLowerCase()),y&&N&&(y=D(y,N)||y);let z=v!=="/"&&v.endsWith("/")?v.length-1:v.length,Z=g===v||!i&&g.startsWith(v)&&g.charAt(z)==="/",ge=y!=null&&(y===v||!i&&y.startsWith(v)&&y.charAt(v.length)==="/"),q={isActive:Z,isPending:ge,isTransitioning:I},ke=Z?a:void 0,ee;typeof o=="function"?ee=o(q):ee=[o,Z?"active":null,ge?"pending":null,I?"transitioning":null].filter(Boolean).join(" ");let He=typeof s=="function"?s(q):s;return d.createElement(Ae,_({},h,{"aria-current":ke,className:ee,ref:r,style:He,to:l,viewTransition:u}),typeof f=="function"?f(q):f)});process.env.NODE_ENV!=="production"&&(Vt.displayName="NavLink");var kt=d.forwardRef((e,t)=>{let{fetcherKey:r,navigate:a,reloadDocument:n,replace:o,state:i,method:s=J,action:l,onSubmit:u,relative:f,preventScrollReset:h,viewTransition:p}=e,w=ve(e,Lt),R=$t(),E=Jt(l,{relative:f}),N=s.toLowerCase()==="get"?"get":"post";return d.createElement("form",_({ref:t,method:N,action:E,onSubmit:n?u:v=>{if(u&&u(v),v.defaultPrevented)return;v.preventDefault();let g=v.nativeEvent.submitter,y=(g==null?void 0:g.getAttribute("formmethod"))||s;R(g||v.currentTarget,{fetcherKey:r,method:y,navigate:a,replace:o,state:i,relative:f,preventScrollReset:h,viewTransition:p})}},w))});process.env.NODE_ENV!=="production"&&(kt.displayName="Form");function Ht(e){let{getKey:t,storageKey:r}=e;return Xt({getKey:t,storageKey:r}),null}process.env.NODE_ENV!=="production"&&(Ht.displayName="ScrollRestoration");var B;(function(e){e.UseScrollRestoration="useScrollRestoration",e.UseSubmit="useSubmit",e.UseSubmitFetcher="useSubmitFetcher",e.UseFetcher="useFetcher",e.useViewTransitionState="useViewTransitionState"})(B||(B={}));var me;(function(e){e.UseFetcher="useFetcher",e.UseFetchers="useFetchers",e.UseScrollRestoration="useScrollRestoration"})(me||(me={}));function Ie(e){return e+" must be used within a data router. See https://reactrouter.com/v6/routers/picking-a-router."}function ye(e){let t=d.useContext(M);return t||(process.env.NODE_ENV!=="production"?m(!1,Ie(e)):m(!1)),t}function Bt(e){let t=d.useContext(A);return t||(process.env.NODE_ENV!=="production"?m(!1,Ie(e)):m(!1)),t}function zt(e,t){let{target:r,replace:a,state:n,preventScrollReset:o,relative:i,viewTransition:s}=t===void 0?{}:t,l=se(),u=S(),f=C(e,{relative:i});return d.useCallback(h=>{if(Dt(h,r)){h.preventDefault();let p=a!==void 0?a:T(u)===T(f);l(e,{replace:p,state:n,preventScrollReset:o,relative:i,viewTransition:s})}},[u,l,f,a,n,r,e,o,i,s])}function Wt(){if(typeof document=="undefined")throw new Error("You are calling submit during the server render. Try calling submit within a `useEffect` or callback instead.")}var Kt=0,Yt=()=>"__"+String(++Kt)+"__";function $t(){let{router:e}=ye(B.UseSubmit),{basename:t}=d.useContext(b),r=ce();return d.useCallback(function(a,n){n===void 0&&(n={}),Wt();let{action:o,method:i,encType:s,formData:l,body:u}=Pt(a,t);if(n.navigate===!1){let f=n.fetcherKey||Yt();e.fetch(f,r,n.action||o,{preventScrollReset:n.preventScrollReset,formData:l,body:u,formMethod:n.method||i,formEncType:n.encType||s,flushSync:n.flushSync})}else e.navigate(n.action||o,{preventScrollReset:n.preventScrollReset,formData:l,body:u,formMethod:n.method||i,formEncType:n.encType||s,replace:n.replace,state:n.state,fromRouteId:r,flushSync:n.flushSync,viewTransition:n.viewTransition})},[e,t,r])}function Jt(e,t){let{relative:r}=t===void 0?{}:t,{basename:a}=d.useContext(b),n=d.useContext(P);n||(process.env.NODE_ENV!=="production"?m(!1,"useFormAction must be used inside a RouteContext"):m(!1));let[o]=n.matches.slice(-1),i=_({},C(e||".",{relative:r})),s=S();if(e==null){i.search=s.search;let l=new URLSearchParams(i.search),u=l.getAll("index");if(u.some(h=>h==="")){l.delete("index"),u.filter(p=>p).forEach(p=>l.append("index",p));let h=l.toString();i.search=h?"?"+h:""}}return(!e||e===".")&&o.route.index&&(i.search=i.search?i.search.replace(/^\?/,"?index&"):"?index"),a!=="/"&&(i.pathname=i.pathname==="/"?a:j([a,i.pathname])),T(i)}var Ue="react-router-scroll-positions",$={};function Xt(e){let{getKey:t,storageKey:r}=e===void 0?{}:e,{router:a}=ye(B.UseScrollRestoration),{restoreScrollPosition:n,preventScrollReset:o}=Bt(me.UseScrollRestoration),{basename:i}=d.useContext(b),s=S(),l=fe(),u=de();d.useEffect(()=>(window.history.scrollRestoration="manual",()=>{window.history.scrollRestoration="auto"}),[]),Gt(d.useCallback(()=>{if(u.state==="idle"){let f=(t?t(s,l):null)||s.key;$[f]=window.scrollY}try{sessionStorage.setItem(r||Ue,JSON.stringify($))}catch(f){process.env.NODE_ENV!=="production"&&x(!1,"Failed to save scroll positions in sessionStorage, <ScrollRestoration /> will not work properly ("+f+").")}window.history.scrollRestoration="auto"},[r,t,u.state,s,l])),typeof document!="undefined"&&(d.useLayoutEffect(()=>{try{let f=sessionStorage.getItem(r||Ue);f&&($=JSON.parse(f))}catch(f){}},[r]),d.useLayoutEffect(()=>{let f=t&&i!=="/"?(p,w)=>t(_({},p,{pathname:D(p.pathname,i)||p.pathname}),w):t,h=a==null?void 0:a.enableScrollRestoration($,()=>window.scrollY,f);return()=>h&&h()},[a,i,t]),d.useLayoutEffect(()=>{if(n!==!1){if(typeof n=="number"){window.scrollTo(0,n);return}if(s.hash){let f=document.getElementById(decodeURIComponent(s.hash.slice(1)));if(f){f.scrollIntoView();return}}o!==!0&&window.scrollTo(0,0)}},[s,n,o]))}function Gt(e,t){let{capture:r}=t||{};d.useEffect(()=>{let a=r!=null?{capture:r}:void 0;return window.addEventListener("pagehide",e,a),()=>{window.removeEventListener("pagehide",e,a)}},[e,r])}function Qt(e,t){t===void 0&&(t={});let r=d.useContext(Me);r==null&&(process.env.NODE_ENV!=="production"?m(!1,"`useViewTransitionState` must be used within `react-router-dom`'s `RouterProvider`. Did you accidentally import `RouterProvider` from `react-router`?"):m(!1));let{basename:a}=ye(B.useViewTransitionState),n=C(e,{relative:t.relative});if(!r.isTransitioning)return!1;let o=D(r.currentLocation.pathname,a)||r.currentLocation.pathname,i=D(r.nextLocation.pathname,a)||r.nextLocation.pathname;return O(n.pathname,i)!=null||O(n.pathname,o)!=null}var Ve=require("react/jsx-runtime"),je=e=>{let t=(0,Q.createContext)(null),r=()=>{let l=(0,Q.useContext)(t);if(!l)throw new Error("useRouteWeaver must be used within a RouteWeaverProvider");return l};return{RouteWeaverProvider:({children:l})=>(0,Ve.jsx)(t.Provider,{value:e,children:l}),useNavigation:()=>r().navigation,useActiveRoute:()=>{let l=r(),{pathname:u}=S();return l.getActiveRoute(u)},useBreadcrumbs:()=>{let l=r(),{pathname:u}=S();return l.getBreadcrumbs(u)},useBuildPath:()=>r().buildPath}};0&&(module.exports={createRouteWeaverReactApi});
/*! Bundled license information:
@remix-run/router/dist/router.js:
(**
* @remix-run/router v1.23.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
*)
react-router/dist/index.js:
(**
* React Router v6.30.1
*
* 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
*)
react-router-dom/dist/index.js:
(**
* React Router DOM v6.30.1
*
* 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
*)
*/