@route-weaver/react
Version:
React hooks for @route-weaver/core
40 lines (36 loc) • 24.1 kB
JavaScript
;var ze=Object.create;var K=Object.defineProperty;var We=Object.getOwnPropertyDescriptor;var Ke=Object.getOwnPropertyNames;var Ye=Object.getPrototypeOf,$e=Object.prototype.hasOwnProperty;var Je=(e,t)=>{for(var r in t)K(e,r,{get:t[r],enumerable:!0})},Ee=(e,t,r,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Ke(t))!$e.call(e,n)&&n!==r&&K(e,n,{get:()=>t[n],enumerable:!(a=We(t,n))||a.enumerable});return e};var re=(e,t,r)=>(r=e!=null?ze(Ye(e)):{},Ee(t||!e||!e.__esModule?K(r,"default",{value:e,enumerable:!0}):r,e)),Xe=e=>Ee(K({},"__esModule",{value:!0}),e);var ar={};Je(ar,{RouteWeaverProvider:()=>qt,useActiveRoute:()=>tr,useBreadcrumbs:()=>rr,useBuildPath:()=>nr,useNavigation:()=>er,useRouteWeaver:()=>I});module.exports=Xe(ar);var d=re(require("react")),Et=re(require("react-dom"));var c=re(require("react"));function ae(){return ae=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},ae.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 N(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 U(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 we;(function(e){e.data="data",e.deferred="deferred",e.redirect="redirect",e.error="error"})(we||(we={}));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 F(e,t){typeof e=="string"&&(e={path:e,caseSensitive:!1,end:!0});let[r,a]=Qe(e.path,e.caseSensitive,e.end),n=t.match(r);if(!n)return null;let o=n[0],i=o.replace(/(.)\/+$/,"$1"),l=n.slice(1);return{params:a.reduce((s,f,h)=>{let{paramName:p,isOptional:b}=f;if(p==="*"){let E=l[h]||"";i=o.slice(0,o.length-E.length).replace(/(.)\/+$/,"$1")}let R=l[h];return b&&!R?s[p]=void 0:s[p]=(R||"").replace(/%2F/g,"/"),s},{}),pathname:o,pathnameBase:i,pattern:e}}function Qe(e,t,r){t===void 0&&(t=!1),r===void 0&&(r=!0),N(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,l,u)=>(a.push({paramName:l,isOptional:u!=null}),u?"/?([^\\/]+)?":"/([^\\/]+)"));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 oe(e,t){t===void 0&&(t="/");let{pathname:r,search:a="",hash:n=""}=typeof e=="string"?U(e):e;return{pathname:r?r.startsWith("/")?r:Ze(r,t):t,search:et(a),hash:tt(n)}}function Ze(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 ne(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 qe(e){return e.filter((t,r)=>r===0||t.route.path&&t.route.path.length>0)}function ie(e,t){let r=qe(e);return t?r.map((a,n)=>n===r.length-1?a.pathname:a.pathnameBase):r.map(a=>a.pathnameBase)}function le(e,t,r,a){a===void 0&&(a=!1);let n;typeof e=="string"?n=U(e):(n=ae({},e),m(!n.pathname||!n.pathname.includes("?"),ne("?","pathname","search",n)),m(!n.pathname||!n.pathname.includes("#"),ne("#","pathname","hash",n)),m(!n.search||!n.search.includes("#"),ne("#","search","hash",n)));let o=e===""||n.pathname==="",i=o?"/":n.pathname,l;if(i==null)l=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("/")}l=h>=0?t[h]:"/"}let u=oe(n,l),s=i&&i!=="/"&&i.endsWith("/"),f=(o||i===".")&&r.endsWith("/");return!u.pathname.endsWith("/")&&(s||f)&&(u.pathname+="/"),u}var j=e=>e.join("/").replace(/\/\/+/g,"/");var et=e=>!e||e==="?"?"":e.startsWith("?")?e:"?"+e,tt=e=>!e||e==="#"?"":e.startsWith("#")?e:"#"+e;var Se=["post","put","patch","delete"],ir=new Set(Se),rt=["get",...Se],lr=new Set(rt);var sr=Symbol("deferred");function Y(){return Y=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},Y.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 ct=c.createContext(null);process.env.NODE_ENV!=="production"&&(ct.displayName="Await");var w=c.createContext(null);process.env.NODE_ENV!=="production"&&(w.displayName="Navigation");var k=c.createContext(null);process.env.NODE_ENV!=="production"&&(k.displayName="Location");var P=c.createContext({outlet:null,matches:[],isDataRoute:!1});process.env.NODE_ENV!=="production"&&(P.displayName="Route");var dt=c.createContext(null);process.env.NODE_ENV!=="production"&&(dt.displayName="RouteError");function se(e,t){let{relative:r}=t===void 0?{}:t;H()||(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(w),{hash:o,pathname:i,search:l}=C(e,{relative:r}),u=i;return a!=="/"&&(u=i==="/"?a:j([a,i])),n.createHref({pathname:u,search:l,hash:o})}function H(){return c.useContext(k)!=null}function S(){return H()||(process.env.NODE_ENV!=="production"?m(!1,"useLocation() may be used only in the context of a <Router> component."):m(!1)),c.useContext(k).location}var Ce="You should call navigate() in a React.useEffect(), not when your component is first rendered.";function _e(e){c.useContext(w).static||c.useLayoutEffect(e)}function ue(){let{isDataRoute:e}=c.useContext(P);return e?mt():ft()}function ft(){H()||(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(w),{matches:n}=c.useContext(P),{pathname:o}=S(),i=JSON.stringify(ie(n,r.v7_relativeSplatPath)),l=c.useRef(!1);return _e(()=>{l.current=!0}),c.useCallback(function(s,f){if(f===void 0&&(f={}),process.env.NODE_ENV!=="production"&&N(l.current,Ce),!l.current)return;if(typeof s=="number"){a.go(s);return}let h=le(s,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(w),{matches:n}=c.useContext(P),{pathname:o}=S(),i=JSON.stringify(ie(n,a.v7_relativeSplatPath));return c.useMemo(()=>le(e,JSON.parse(i),o,r==="path"),[e,i,o,r])}var Le=function(e){return e.UseBlocker="useBlocker",e.UseRevalidator="useRevalidator",e.UseNavigateStable="useNavigate",e}(Le||{}),B=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}(B||{});function ce(e){return e+" must be used within a data router. See https://reactrouter.com/v6/routers/picking-a-router."}function ht(e){let t=c.useContext(M);return t||(process.env.NODE_ENV!=="production"?m(!1,ce(e)):m(!1)),t}function Te(e){let t=c.useContext(A);return t||(process.env.NODE_ENV!=="production"?m(!1,ce(e)):m(!1)),t}function pt(e){let t=c.useContext(P);return t||(process.env.NODE_ENV!=="production"?m(!1,ce(e)):m(!1)),t}function Ue(e){let t=pt(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 de(){return Ue(B.UseRouteId)}function fe(){return Te(B.UseNavigation).navigation}function he(){let{matches:e,loaderData:t}=Te(B.UseMatches);return c.useMemo(()=>e.map(r=>be(r,t)),[e,t])}function mt(){let{router:e}=ht(Le.UseNavigateStable),t=Ue(B.UseNavigateStable),r=c.useRef(!1);return _e(()=>{r.current=!0}),c.useCallback(function(n,o){o===void 0&&(o={}),process.env.NODE_ENV!=="production"&&N(r.current,Ce),r.current&&(typeof n=="number"?e.navigate(n):e.navigate(n,Y({fromRouteId:t},o)))},[e,t])}var De={};function vt(e,t){process.env.NODE_ENV!=="production"&&!De[t]&&(De[t]=!0,console.warn(t))}var O=(e,t,r)=>vt(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&&O("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)&&O("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&&O("v7_fetcherPersist","The persistence behavior of fetchers is changing in v7","https://reactrouter.com/v6/upgrading/future#v7_fetcherpersist"),t.v7_normalizeFormMethod===void 0&&O("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&&O("v7_partialHydration","`RouterProvider` hydration behavior is changing in v7","https://reactrouter.com/v6/upgrading/future#v7_partialhydration"),t.v7_skipActionErrorRevalidation===void 0&&O("v7_skipActionErrorRevalidation","The revalidation behavior after 4xx/5xx `action` responses is changing in v7","https://reactrouter.com/v6/upgrading/future#v7_skipactionerrorrevalidation"))}var yt="startTransition",mr=c[yt];function pe(e){let{basename:t="/",children:r=null,location:a,navigationType:n=L.Pop,navigator:o,static:i=!1,future:l}=e;H()&&(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 u=t.replace(/^\/*/,"/"),s=c.useMemo(()=>({basename:u,navigator:o,static:i,future:Y({v7_relativeSplatPath:!1},l)}),[u,l,o,i]);typeof a=="string"&&(a=U(a));let{pathname:f="/",search:h="",hash:p="",state:b=null,key:R="default"}=a,E=c.useMemo(()=>{let x=D(f,u);return x==null?null:{location:{pathname:x,search:h,hash:p,state:b,key:R},navigationType:n}},[u,f,h,p,b,R,n]);return process.env.NODE_ENV!=="production"&&N(E!=null,'<Router basename="'+u+'"> 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(w.Provider,{value:s},c.createElement(k.Provider,{children:r,value:E}))}var vr=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 ye(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 X="get",G="application/x-www-form-urlencoded";function Q(e){return e!=null&&typeof e.tagName=="string"}function wt(e){return Q(e)&&e.tagName.toLowerCase()==="button"}function bt(e){return Q(e)&&e.tagName.toLowerCase()==="form"}function St(e){return Q(e)&&e.tagName.toLowerCase()==="input"}function Dt(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function xt(e,t){return e.button===0&&(!t||t==="_self")&&!Dt(e)}var $=null;function Nt(){if($===null)try{new FormData(document.createElement("form"),0),$=!1}catch(e){$=!0}return $}var Pt=new Set(["application/x-www-form-urlencoded","multipart/form-data","text/plain"]);function me(e){return e!=null&&!Pt.has(e)?(process.env.NODE_ENV!=="production"&&N(!1,'"'+e+'" is not a valid `encType` for `<Form>`/`<fetcher.Form>` '+('and will default to "'+G+'"')),null):e}function Ct(e,t){let r,a,n,o,i;if(bt(e)){let l=e.getAttribute("action");a=l?D(l,t):null,r=e.getAttribute("method")||X,n=me(e.getAttribute("enctype"))||G,o=new FormData(e)}else if(wt(e)||St(e)&&(e.type==="submit"||e.type==="image")){let l=e.form;if(l==null)throw new Error('Cannot submit a <button> or <input type="submit"> without a <form>');let u=e.getAttribute("formaction")||l.getAttribute("action");if(a=u?D(u,t):null,r=e.getAttribute("formmethod")||l.getAttribute("method")||X,n=me(e.getAttribute("formenctype"))||me(l.getAttribute("enctype"))||G,o=new FormData(l,e),!Nt()){let{name:s,type:f,value:h}=e;if(f==="image"){let p=s?s+".":"";o.append(p+"x","0"),o.append(p+"y","0")}else s&&o.append(s,h)}}else{if(Q(e))throw new Error('Cannot submit element that is not <form>, <button>, or <input type="submit|image">');r=X,a=null,n=G,i=e}return o&&n==="text/plain"&&(i=o,o=void 0),{action:a,method:r.toLowerCase(),encType:n,formData:o,body:i}}var _t=["onClick","relative","reloadDocument","replace","state","target","to","preventScrollReset","viewTransition"],Lt=["aria-current","caseSensitive","className","end","style","to","viewTransition","children"],Tt=["fetcherKey","navigate","reloadDocument","replace","state","method","action","onSubmit","relative","preventScrollReset","viewTransition"],Ut="6";try{window.__reactRouterVersion=Ut}catch(e){}var Ae=d.createContext({isTransitioning:!1});process.env.NODE_ENV!=="production"&&(Ae.displayName="ViewTransition");var Ft=d.createContext(new Map);process.env.NODE_ENV!=="production"&&(Ft.displayName="Fetchers");var Ot="startTransition",Oe=d[Ot],Mt="flushSync",Jr=Et[Mt],At="useId",Xr=d[At];function It(e){let{basename:t,children:r,future:a,history:n}=e,[o,i]=d.useState({action:n.action,location:n.location}),{v7_startTransition:l}=a||{},u=d.useCallback(s=>{l&&Oe?Oe(()=>i(s)):i(s)},[i,l]);return d.useLayoutEffect(()=>n.listen(u),[n,u]),d.useEffect(()=>Fe(a),[a]),d.createElement(pe,{basename:t,children:r,location:o.location,navigationType:o.action,navigator:n,future:a})}process.env.NODE_ENV!=="production"&&(It.displayName="unstable_HistoryRouter");var Vt=typeof window!="undefined"&&typeof window.document!="undefined"&&typeof window.document.createElement!="undefined",jt=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,Ie=d.forwardRef(function(t,r){let{onClick:a,relative:n,reloadDocument:o,replace:i,state:l,target:u,to:s,preventScrollReset:f,viewTransition:h}=t,p=ye(t,_t),{basename:b}=d.useContext(w),R,E=!1;if(typeof s=="string"&&jt.test(s)&&(R=s,Vt))try{let g=new URL(window.location.href),y=s.startsWith("//")?new URL(g.protocol+s):new URL(s),W=D(y.pathname,b);y.origin===g.origin&&W!=null?s=W+y.search+y.hash:E=!0}catch(g){process.env.NODE_ENV!=="production"&&N(!1,'<Link to="'+s+'"> contains an invalid URL which will probably break when clicked - please update to a valid URL path.')}let x=se(s,{relative:n}),V=Wt(s,{replace:i,state:l,target:u,preventScrollReset:f,relative:n,viewTransition:h});function v(g){a&&a(g),g.defaultPrevented||V(g)}return d.createElement("a",_({},p,{href:R||x,onClick:E||o?a:v,ref:r,target:u}))});process.env.NODE_ENV!=="production"&&(Ie.displayName="Link");var kt=d.forwardRef(function(t,r){let{"aria-current":a="page",caseSensitive:n=!1,className:o="",end:i=!1,style:l,to:u,viewTransition:s,children:f}=t,h=ye(t,Lt),p=C(u,{relative:h.relative}),b=S(),R=d.useContext(A),{navigator:E,basename:x}=d.useContext(w),V=R!=null&&Zt(p)&&s===!0,v=E.encodeLocation?E.encodeLocation(p).pathname:p.pathname,g=b.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&&x&&(y=D(y,x)||y);let W=v!=="/"&&v.endsWith("/")?v.length-1:v.length,q=g===v||!i&&g.startsWith(v)&&g.charAt(W)==="/",Re=y!=null&&(y===v||!i&&y.startsWith(v)&&y.charAt(v.length)==="/"),ee={isActive:q,isPending:Re,isTransitioning:V},He=q?a:void 0,te;typeof o=="function"?te=o(ee):te=[o,q?"active":null,Re?"pending":null,V?"transitioning":null].filter(Boolean).join(" ");let Be=typeof l=="function"?l(ee):l;return d.createElement(Ie,_({},h,{"aria-current":He,className:te,ref:r,style:Be,to:u,viewTransition:s}),typeof f=="function"?f(ee):f)});process.env.NODE_ENV!=="production"&&(kt.displayName="NavLink");var Ht=d.forwardRef((e,t)=>{let{fetcherKey:r,navigate:a,reloadDocument:n,replace:o,state:i,method:l=X,action:u,onSubmit:s,relative:f,preventScrollReset:h,viewTransition:p}=e,b=ye(e,Tt),R=Jt(),E=Xt(u,{relative:f}),x=l.toLowerCase()==="get"?"get":"post";return d.createElement("form",_({ref:t,method:x,action:E,onSubmit:n?s:v=>{if(s&&s(v),v.defaultPrevented)return;v.preventDefault();let g=v.nativeEvent.submitter,y=(g==null?void 0:g.getAttribute("formmethod"))||l;R(g||v.currentTarget,{fetcherKey:r,method:y,navigate:a,replace:o,state:i,relative:f,preventScrollReset:h,viewTransition:p})}},b))});process.env.NODE_ENV!=="production"&&(Ht.displayName="Form");function Bt(e){let{getKey:t,storageKey:r}=e;return Gt({getKey:t,storageKey:r}),null}process.env.NODE_ENV!=="production"&&(Bt.displayName="ScrollRestoration");var z;(function(e){e.UseScrollRestoration="useScrollRestoration",e.UseSubmit="useSubmit",e.UseSubmitFetcher="useSubmitFetcher",e.UseFetcher="useFetcher",e.useViewTransitionState="useViewTransitionState"})(z||(z={}));var ve;(function(e){e.UseFetcher="useFetcher",e.UseFetchers="useFetchers",e.UseScrollRestoration="useScrollRestoration"})(ve||(ve={}));function Ve(e){return e+" must be used within a data router. See https://reactrouter.com/v6/routers/picking-a-router."}function ge(e){let t=d.useContext(M);return t||(process.env.NODE_ENV!=="production"?m(!1,Ve(e)):m(!1)),t}function zt(e){let t=d.useContext(A);return t||(process.env.NODE_ENV!=="production"?m(!1,Ve(e)):m(!1)),t}function Wt(e,t){let{target:r,replace:a,state:n,preventScrollReset:o,relative:i,viewTransition:l}=t===void 0?{}:t,u=ue(),s=S(),f=C(e,{relative:i});return d.useCallback(h=>{if(xt(h,r)){h.preventDefault();let p=a!==void 0?a:T(s)===T(f);u(e,{replace:p,state:n,preventScrollReset:o,relative:i,viewTransition:l})}},[s,u,f,a,n,r,e,o,i,l])}function Kt(){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 Yt=0,$t=()=>"__"+String(++Yt)+"__";function Jt(){let{router:e}=ge(z.UseSubmit),{basename:t}=d.useContext(w),r=de();return d.useCallback(function(a,n){n===void 0&&(n={}),Kt();let{action:o,method:i,encType:l,formData:u,body:s}=Ct(a,t);if(n.navigate===!1){let f=n.fetcherKey||$t();e.fetch(f,r,n.action||o,{preventScrollReset:n.preventScrollReset,formData:u,body:s,formMethod:n.method||i,formEncType:n.encType||l,flushSync:n.flushSync})}else e.navigate(n.action||o,{preventScrollReset:n.preventScrollReset,formData:u,body:s,formMethod:n.method||i,formEncType:n.encType||l,replace:n.replace,state:n.state,fromRouteId:r,flushSync:n.flushSync,viewTransition:n.viewTransition})},[e,t,r])}function Xt(e,t){let{relative:r}=t===void 0?{}:t,{basename:a}=d.useContext(w),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})),l=S();if(e==null){i.search=l.search;let u=new URLSearchParams(i.search),s=u.getAll("index");if(s.some(h=>h==="")){u.delete("index"),s.filter(p=>p).forEach(p=>u.append("index",p));let h=u.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 Me="react-router-scroll-positions",J={};function Gt(e){let{getKey:t,storageKey:r}=e===void 0?{}:e,{router:a}=ge(z.UseScrollRestoration),{restoreScrollPosition:n,preventScrollReset:o}=zt(ve.UseScrollRestoration),{basename:i}=d.useContext(w),l=S(),u=he(),s=fe();d.useEffect(()=>(window.history.scrollRestoration="manual",()=>{window.history.scrollRestoration="auto"}),[]),Qt(d.useCallback(()=>{if(s.state==="idle"){let f=(t?t(l,u):null)||l.key;J[f]=window.scrollY}try{sessionStorage.setItem(r||Me,JSON.stringify(J))}catch(f){process.env.NODE_ENV!=="production"&&N(!1,"Failed to save scroll positions in sessionStorage, <ScrollRestoration /> will not work properly ("+f+").")}window.history.scrollRestoration="auto"},[r,t,s.state,l,u])),typeof document!="undefined"&&(d.useLayoutEffect(()=>{try{let f=sessionStorage.getItem(r||Me);f&&(J=JSON.parse(f))}catch(f){}},[r]),d.useLayoutEffect(()=>{let f=t&&i!=="/"?(p,b)=>t(_({},p,{pathname:D(p.pathname,i)||p.pathname}),b):t,h=a==null?void 0:a.enableScrollRestoration(J,()=>window.scrollY,f);return()=>h&&h()},[a,i,t]),d.useLayoutEffect(()=>{if(n!==!1){if(typeof n=="number"){window.scrollTo(0,n);return}if(l.hash){let f=document.getElementById(decodeURIComponent(l.hash.slice(1)));if(f){f.scrollIntoView();return}}o!==!0&&window.scrollTo(0,0)}},[l,n,o]))}function Qt(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 Zt(e,t){t===void 0&&(t={});let r=d.useContext(Ae);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}=ge(z.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 F(n.pathname,i)!=null||F(n.pathname,o)!=null}var Z=require("react"),ke=require("react/jsx-runtime"),je=(0,Z.createContext)(void 0),qt=({navInstance:e,children:t})=>(0,ke.jsx)(je.Provider,{value:{navInstance:e},children:t}),I=()=>{let e=(0,Z.useContext)(je);if(e===void 0)throw new Error("useRouteWeaver must be used within a RouteWeaverProvider");return e.navInstance};var er=()=>I().navigation,tr=()=>{let e=I(),{pathname:t}=S();return e.getActiveRoute(t)},rr=()=>{let e=I(),{pathname:t}=S();return e.getBreadcrumbs(t)},nr=()=>I().buildPath;0&&(module.exports={RouteWeaverProvider,useActiveRoute,useBreadcrumbs,useBuildPath,useNavigation,useRouteWeaver});
/*! 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
*)
*/