LocalCDN-Firefox-Chrome-Brave/resources/react-router/6.10.0/react-router.min.jsm

13 lines
15 KiB
JavaScript

/**
* React Router v6.10.0
*
* Copyright (c) Remix Software Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@remix-run/router"),require("react")):"function"==typeof define&&define.amd?define(["exports","@remix-run/router","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactRouter={},e.RemixRouter,e.React)}(this,(function(e,t,r){"use strict";function n(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var o=n(r);const a="function"==typeof Object.is?Object.is:function(e,t){return e===t&&(0!==e||1/e==1/t)||e!=e&&t!=t},{useState:i,useEffect:u,useLayoutEffect:l,useDebugValue:s}=o;function c(e){const t=e.getSnapshot,r=e.value;try{const e=t();return!a(r,e)}catch(e){return!0}}const d=!!("undefined"==typeof window||void 0===window.document||void 0===window.document.createElement)?function(e,t,r){return t()}:function(e,t,r){const n=t(),[{inst:o},a]=i({inst:{value:n,getSnapshot:t}});return l((()=>{o.value=n,o.getSnapshot=t,c(o)&&a({inst:o})}),[e,n,t]),u((()=>{c(o)&&a({inst:o});return e((()=>{c(o)&&a({inst:o})}))}),[e]),s(n),n},p="useSyncExternalStore"in o?(e=>e.useSyncExternalStore)(o):d,m=o.createContext(null),h=o.createContext(null),f=o.createContext(null),v=o.createContext(null),E=o.createContext(null),g=o.createContext({outlet:null,matches:[]}),y=o.createContext(null);function b(){return b=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},b.apply(this,arguments)}function x(){return null!=o.useContext(E)}function P(){return x()||t.UNSAFE_invariant(!1),o.useContext(E).location}function C(){x()||t.UNSAFE_invariant(!1);let{basename:e,navigator:r}=o.useContext(v),{matches:n}=o.useContext(g),{pathname:a}=P(),i=JSON.stringify(t.UNSAFE_getPathContributingMatches(n).map((e=>e.pathnameBase))),u=o.useRef(!1);return o.useEffect((()=>{u.current=!0})),o.useCallback((function(n,o){if(void 0===o&&(o={}),!u.current)return;if("number"==typeof n)return void r.go(n);let l=t.resolveTo(n,JSON.parse(i),a,"path"===o.relative);"/"!==e&&(l.pathname="/"===l.pathname?e:t.joinPaths([e,l.pathname])),(o.replace?r.replace:r.push)(l,o.state,o)}),[e,r,i,a])}const R=o.createContext(null);function S(e){let t=o.useContext(g).outlet;return t?o.createElement(R.Provider,{value:e},t):t}function U(e,r){let{relative:n}=void 0===r?{}:r,{matches:a}=o.useContext(g),{pathname:i}=P(),u=JSON.stringify(t.UNSAFE_getPathContributingMatches(a).map((e=>e.pathnameBase)));return o.useMemo((()=>t.resolveTo(e,JSON.parse(u),i,"path"===n)),[e,u,i,n])}function _(e,r){x()||t.UNSAFE_invariant(!1);let{navigator:n}=o.useContext(v),a=o.useContext(h),{matches:i}=o.useContext(g),u=i[i.length-1],l=u?u.params:{};!u||u.pathname;let s=u?u.pathnameBase:"/";u&&u.route;let c,d=P();if(r){var p;let e="string"==typeof r?t.parsePath(r):r;"/"===s||(null==(p=e.pathname)?void 0:p.startsWith(s))||t.UNSAFE_invariant(!1),c=e}else c=d;let m=c.pathname||"/",f="/"===s?m:m.slice(s.length)||"/",y=t.matchRoutes(e,{pathname:f}),C=N(y&&y.map((e=>Object.assign({},e,{params:Object.assign({},l,e.params),pathname:t.joinPaths([s,n.encodeLocation?n.encodeLocation(e.pathname).pathname:e.pathname]),pathnameBase:"/"===e.pathnameBase?s:t.joinPaths([s,n.encodeLocation?n.encodeLocation(e.pathnameBase).pathname:e.pathnameBase])}))),i,a||void 0);return r&&C?o.createElement(E.Provider,{value:{location:b({pathname:"/",search:"",hash:"",state:null,key:"default"},c),navigationType:t.Action.Pop}},C):C}function O(){let e=L(),r=t.isRouteErrorResponse(e)?e.status+" "+e.statusText:e instanceof Error?e.message:JSON.stringify(e),n=e instanceof Error?e.stack:null,a={padding:"0.5rem",backgroundColor:"rgba(200,200,200, 0.5)"};return o.createElement(o.Fragment,null,o.createElement("h2",null,"Unexpected Application Error!"),o.createElement("h3",{style:{fontStyle:"italic"}},r),n?o.createElement("pre",{style:a},n):null,null)}class j extends o.Component{constructor(e){super(e),this.state={location:e.location,error:e.error}}static getDerivedStateFromError(e){return{error:e}}static getDerivedStateFromProps(e,t){return t.location!==e.location?{error:e.error,location:e.location}:{error:e.error||t.error,location:t.location}}componentDidCatch(e,t){console.error("React Router caught the following error during render",e,t)}render(){return this.state.error?o.createElement(g.Provider,{value:this.props.routeContext},o.createElement(y.Provider,{value:this.state.error,children:this.props.component})):this.props.children}}function A(e){let{routeContext:t,match:r,children:n}=e,a=o.useContext(m);return a&&a.static&&a.staticContext&&(r.route.errorElement||r.route.ErrorBoundary)&&(a.staticContext._deepestRenderedBoundaryId=r.route.id),o.createElement(g.Provider,{value:t},n)}function N(e,r,n){if(void 0===r&&(r=[]),null==e){if(null==n||!n.errors)return null;e=n.matches}let a=e,i=null==n?void 0:n.errors;if(null!=i){let e=a.findIndex((e=>e.route.id&&(null==i?void 0:i[e.route.id])));e>=0||t.UNSAFE_invariant(!1),a=a.slice(0,Math.min(a.length,e+1))}return a.reduceRight(((e,t,u)=>{let l=t.route.id?null==i?void 0:i[t.route.id]:null,s=null;n&&(s=t.route.ErrorBoundary?o.createElement(t.route.ErrorBoundary,null):t.route.errorElement?t.route.errorElement:o.createElement(O,null));let c=r.concat(a.slice(0,u+1)),d=()=>{let r=e;return l?r=s:t.route.Component?r=o.createElement(t.route.Component,null):t.route.element&&(r=t.route.element),o.createElement(A,{match:t,routeContext:{outlet:e,matches:c},children:r})};return n&&(t.route.ErrorBoundary||t.route.errorElement||0===u)?o.createElement(j,{location:n.location,component:s,error:l,children:d(),routeContext:{outlet:null,matches:c}}):d()}),null)}var F,D;function B(e){let r=o.useContext(m);return r||t.UNSAFE_invariant(!1),r}function k(e){let r=o.useContext(h);return r||t.UNSAFE_invariant(!1),r}function M(e){let r=function(e){let r=o.useContext(g);return r||t.UNSAFE_invariant(!1),r}(),n=r.matches[r.matches.length-1];return n.route.id||t.UNSAFE_invariant(!1),n.route.id}function L(){var e;let t=o.useContext(y),r=k(D.UseRouteError),n=M(D.UseRouteError);return t||(null==(e=r.errors)?void 0:e[n])}function w(){let e=o.useContext(f);return null==e?void 0:e._data}!function(e){e.UseBlocker="useBlocker",e.UseRevalidator="useRevalidator"}(F||(F={})),function(e){e.UseBlocker="useBlocker",e.UseLoaderData="useLoaderData",e.UseActionData="useActionData",e.UseRouteError="useRouteError",e.UseNavigation="useNavigation",e.UseRouteLoaderData="useRouteLoaderData",e.UseMatches="useMatches",e.UseRevalidator="useRevalidator"}(D||(D={}));let T=0;function I(e){t.UNSAFE_invariant(!1)}function H(e){let{basename:r="/",children:n=null,location:a,navigationType:i=t.Action.Pop,navigator:u,static:l=!1}=e;x()&&t.UNSAFE_invariant(!1);let s=r.replace(/^\/*/,"/"),c=o.useMemo((()=>({basename:s,navigator:u,static:l})),[s,u,l]);"string"==typeof a&&(a=t.parsePath(a));let{pathname:d="/",search:p="",hash:m="",state:h=null,key:f="default"}=a,g=o.useMemo((()=>{let e=t.stripBasename(d,s);return null==e?null:{location:{pathname:e,search:p,hash:m,state:h,key:f},navigationType:i}}),[s,d,p,m,h,f,i]);return null==g?null:o.createElement(v.Provider,{value:c},o.createElement(E.Provider,{children:n,value:g}))}function z(e){let{children:t,location:r}=e,n=o.useContext(m);return _(n&&!t?n.router.routes:Y(t),r)}var J;!function(e){e[e.pending=0]="pending",e[e.success=1]="success",e[e.error=2]="error"}(J||(J={}));const V=new Promise((()=>{}));class q extends o.Component{constructor(e){super(e),this.state={error:null}}static getDerivedStateFromError(e){return{error:e}}componentDidCatch(e,t){console.error("<Await> caught the following error during render",e,t)}render(){let{children:e,errorElement:r,resolve:n}=this.props,a=null,i=J.pending;if(n instanceof Promise)if(this.state.error){i=J.error;let e=this.state.error;a=Promise.reject().catch((()=>{})),Object.defineProperty(a,"_tracked",{get:()=>!0}),Object.defineProperty(a,"_error",{get:()=>e})}else n._tracked?(a=n,i=void 0!==a._error?J.error:void 0!==a._data?J.success:J.pending):(i=J.pending,Object.defineProperty(n,"_tracked",{get:()=>!0}),a=n.then((e=>Object.defineProperty(n,"_data",{get:()=>e})),(e=>Object.defineProperty(n,"_error",{get:()=>e}))));else i=J.success,a=Promise.resolve(),Object.defineProperty(a,"_tracked",{get:()=>!0}),Object.defineProperty(a,"_data",{get:()=>n});if(i===J.error&&a._error instanceof t.AbortedDeferredError)throw V;if(i===J.error&&!r)throw a._error;if(i===J.error)return o.createElement(f.Provider,{value:a,children:r});if(i===J.success)return o.createElement(f.Provider,{value:a,children:e});throw a}}function W(e){let{children:t}=e,r=w(),n="function"==typeof t?t(r):t;return o.createElement(o.Fragment,null,n)}function Y(e,r){void 0===r&&(r=[]);let n=[];return o.Children.forEach(e,((e,a)=>{if(!o.isValidElement(e))return;let i=[...r,a];if(e.type===o.Fragment)return void n.push.apply(n,Y(e.props.children,i));e.type!==I&&t.UNSAFE_invariant(!1),e.props.index&&e.props.children&&t.UNSAFE_invariant(!1);let u={id:e.props.id||i.join("-"),caseSensitive:e.props.caseSensitive,element:e.props.element,Component:e.props.Component,index:e.props.index,path:e.props.path,loader:e.props.loader,action:e.props.action,errorElement:e.props.errorElement,ErrorBoundary:e.props.ErrorBoundary,hasErrorBoundary:null!=e.props.ErrorBoundary||null!=e.props.errorElement,shouldRevalidate:e.props.shouldRevalidate,handle:e.props.handle,lazy:e.props.lazy};e.props.children&&(u.children=Y(e.props.children,i)),n.push(u)})),n}function G(e){return Boolean(e.ErrorBoundary)||Boolean(e.errorElement)}Object.defineProperty(e,"AbortedDeferredError",{enumerable:!0,get:function(){return t.AbortedDeferredError}}),Object.defineProperty(e,"NavigationType",{enumerable:!0,get:function(){return t.Action}}),Object.defineProperty(e,"createPath",{enumerable:!0,get:function(){return t.createPath}}),Object.defineProperty(e,"defer",{enumerable:!0,get:function(){return t.defer}}),Object.defineProperty(e,"generatePath",{enumerable:!0,get:function(){return t.generatePath}}),Object.defineProperty(e,"isRouteErrorResponse",{enumerable:!0,get:function(){return t.isRouteErrorResponse}}),Object.defineProperty(e,"json",{enumerable:!0,get:function(){return t.json}}),Object.defineProperty(e,"matchPath",{enumerable:!0,get:function(){return t.matchPath}}),Object.defineProperty(e,"matchRoutes",{enumerable:!0,get:function(){return t.matchRoutes}}),Object.defineProperty(e,"parsePath",{enumerable:!0,get:function(){return t.parsePath}}),Object.defineProperty(e,"redirect",{enumerable:!0,get:function(){return t.redirect}}),Object.defineProperty(e,"resolvePath",{enumerable:!0,get:function(){return t.resolvePath}}),e.Await=function(e){let{children:t,errorElement:r,resolve:n}=e;return o.createElement(q,{resolve:n,errorElement:r},o.createElement(W,null,t))},e.MemoryRouter=function(e){let{basename:r,children:n,initialEntries:a,initialIndex:i}=e,u=o.useRef();null==u.current&&(u.current=t.createMemoryHistory({initialEntries:a,initialIndex:i,v5Compat:!0}));let l=u.current,[s,c]=o.useState({action:l.action,location:l.location});return o.useLayoutEffect((()=>l.listen(c)),[l]),o.createElement(H,{basename:r,children:n,location:s.location,navigationType:s.action,navigator:l})},e.Navigate=function(e){let{to:r,replace:n,state:a,relative:i}=e;x()||t.UNSAFE_invariant(!1);let u=o.useContext(h),l=C();return o.useEffect((()=>{u&&"idle"!==u.navigation.state||l(r,{replace:n,state:a,relative:i})})),null},e.Outlet=function(e){return S(e.context)},e.Route=I,e.Router=H,e.RouterProvider=function(e){let{fallbackElement:t,router:r}=e,n=o.useCallback((()=>r.state),[r]),a=p(r.subscribe,n,n),i=o.useMemo((()=>({createHref:r.createHref,encodeLocation:r.encodeLocation,go:e=>r.navigate(e),push:(e,t,n)=>r.navigate(e,{state:t,preventScrollReset:null==n?void 0:n.preventScrollReset}),replace:(e,t,n)=>r.navigate(e,{replace:!0,state:t,preventScrollReset:null==n?void 0:n.preventScrollReset})})),[r]),u=r.basename||"/",l=o.useMemo((()=>({router:r,navigator:i,static:!1,basename:u})),[r,i,u]);return o.createElement(o.Fragment,null,o.createElement(m.Provider,{value:l},o.createElement(h.Provider,{value:a},o.createElement(H,{basename:r.basename,location:r.state.location,navigationType:r.state.historyAction,navigator:i},r.state.initialized?o.createElement(z,null):t))),null)},e.Routes=z,e.UNSAFE_DataRouterContext=m,e.UNSAFE_DataRouterStateContext=h,e.UNSAFE_LocationContext=E,e.UNSAFE_NavigationContext=v,e.UNSAFE_RouteContext=g,e.UNSAFE_detectErrorBoundary=G,e.createMemoryRouter=function(e,r){return t.createRouter({basename:null==r?void 0:r.basename,future:null==r?void 0:r.future,history:t.createMemoryHistory({initialEntries:null==r?void 0:r.initialEntries,initialIndex:null==r?void 0:r.initialIndex}),hydrationData:null==r?void 0:r.hydrationData,routes:e,detectErrorBoundary:G}).initialize()},e.createRoutesFromChildren=Y,e.createRoutesFromElements=Y,e.renderMatches=function(e){return N(e)},e.unstable_useBlocker=function(e){let{router:t}=B(F.UseBlocker),r=k(D.UseBlocker),[n]=o.useState((()=>String(++T))),a=o.useCallback((t=>"function"==typeof e?!!e(t):!!e),[e]),i=t.getBlocker(n,a);return o.useEffect((()=>()=>t.deleteBlocker(n)),[t,n]),r.blockers.get(n)||i},e.useActionData=function(){let e=k(D.UseActionData);return o.useContext(g)||t.UNSAFE_invariant(!1),Object.values((null==e?void 0:e.actionData)||{})[0]},e.useAsyncError=function(){let e=o.useContext(f);return null==e?void 0:e._error},e.useAsyncValue=w,e.useHref=function(e,r){let{relative:n}=void 0===r?{}:r;x()||t.UNSAFE_invariant(!1);let{basename:a,navigator:i}=o.useContext(v),{hash:u,pathname:l,search:s}=U(e,{relative:n}),c=l;return"/"!==a&&(c="/"===l?a:t.joinPaths([a,l])),i.createHref({pathname:c,search:s,hash:u})},e.useInRouterContext=x,e.useLoaderData=function(){let e=k(D.UseLoaderData),t=M(D.UseLoaderData);if(!e.errors||null==e.errors[t])return e.loaderData[t];console.error("You cannot `useLoaderData` in an errorElement (routeId: "+t+")")},e.useLocation=P,e.useMatch=function(e){x()||t.UNSAFE_invariant(!1);let{pathname:r}=P();return o.useMemo((()=>t.matchPath(e,r)),[r,e])},e.useMatches=function(){let{matches:e,loaderData:t}=k(D.UseMatches);return o.useMemo((()=>e.map((e=>{let{pathname:r,params:n}=e;return{id:e.route.id,pathname:r,params:n,data:t[e.route.id],handle:e.route.handle}}))),[e,t])},e.useNavigate=C,e.useNavigation=function(){return k(D.UseNavigation).navigation},e.useNavigationType=function(){return o.useContext(E).navigationType},e.useOutlet=S,e.useOutletContext=function(){return o.useContext(R)},e.useParams=function(){let{matches:e}=o.useContext(g),t=e[e.length-1];return t?t.params:{}},e.useResolvedPath=U,e.useRevalidator=function(){let e=B(F.UseRevalidator),t=k(D.UseRevalidator);return{revalidate:e.router.revalidate,state:t.revalidation}},e.useRouteError=L,e.useRouteLoaderData=function(e){return k(D.UseRouteLoaderData).loaderData[e]},e.useRoutes=_,Object.defineProperty(e,"__esModule",{value:!0})}));
//# sourceMappingURL=react-router.production.min.js.map