@tanstack/react-router 0.0.1-beta.79 → 0.0.1-beta.80

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -38,5 +38,5 @@
38
38
  * LICENSE.md file in the root directory of this source tree.
39
39
  *
40
40
  * @license MIT
41
- */function Y(t,e=(t=>t),a){return r.useSyncExternalStoreWithSelector(t.subscribe,(()=>t.state),(()=>t.state),e,a?Z:void 0)}function Z(t,e){if(Object.is(t,e))return!0;if("object"!=typeof t||null===t||"object"!=typeof e||null===e)return!1;const r=Object.keys(t);if(r.length!==Object.keys(e).length)return!1;for(let a=0;a<r.length;a++)if(!Object.prototype.hasOwnProperty.call(e,r[a])||!Object.is(t[r[a]],e[r[a]]))return!1;return!0}function tt(t){const e=ot(),{type:r,children:a,target:s,activeProps:n=(()=>({className:"active"})),inactiveProps:i=(()=>({})),activeOptions:c,disabled:h,hash:u,search:l,params:p,to:d=".",preload:f,preloadDelay:m,replace:y,style:g,className:v,onClick:w,onFocus:S,onMouseEnter:_,onMouseLeave:L,onTouchStart:E,...P}=t,x=e.buildLink(t);if("external"===x.type){const{href:t}=x;return{href:t}}const{handleClick:R,handleFocus:C,handleEnter:M,handleLeave:k,handleTouchStart:O,isActive:j,next:I}=x,$=t=>e=>{e.persist&&e.persist(),t.filter(Boolean).forEach((t=>{e.defaultPrevented||t(e)}))},A=j?b(n,{})??{}:{},T=j?{}:b(i,{})??{};return{...A,...T,...P,href:h?void 0:I.href,onClick:$([w,t=>{o.startTransition?o.startTransition((()=>{R(t)})):R(t)}]),onFocus:$([S,C]),onMouseEnter:$([_,M]),onMouseLeave:$([L,k]),onTouchStart:$([E,O]),target:s,style:{...g,...A.style,...T.style},className:[v,A.className,T.className].filter(Boolean).join(" ")||void 0,...h?{role:"link","aria-disabled":!0}:void 0,"data-status":j?"active":void 0}}const et=o.forwardRef(((t,e)=>{const r=tt(t);return o.createElement("a",s({ref:e},r,{children:"function"==typeof t.children?t.children({isActive:"active"===r["data-status"]}):t.children}))}));const rt=o.createContext(null),at=o.createContext(null);function ot(){const t=o.useContext(at);return Y(t.router.__store),t.router}function st(t,e){const r=ot();return Y(r.__store,t,e),r}function nt(){return o.useContext(rt)}function it(t){const e=ot(),r=nt()[0],a=t?.from?e.state.currentMatches.find((e=>e.route.id===t?.from)):r;return n(a,t?.from&&t.from),(t?.strict??1)&&n(r.route.id==a?.route.id,(a?.route.id,r.route.id,a?.route.id,a?.route.id)),Y(a.__store,(e=>t?.track?.(a)??a),t?.shallow),a}function ct(){const t=ot();return o.useCallback((e=>{const{pending:r,caseSensitive:a,...o}=e;return t.matchRoute(o,{pending:r,caseSensitive:a})}),[])}function ht(){const t=nt().slice(1),e=t[0];return e?o.createElement(ut,{matches:t,match:e}):null}function ut({matches:t,match:e}){const r=ot();Y(e.__store,(t=>[t.status,t.error]),!0);const a=o.useCallback((()=>null),[]),s=o.useCallback((t=>{if("error"===t.match.state.status)throw t.match.state.error;if("success"===t.match.state.status)return o.createElement(t.match.component??r.options.defaultComponent??ht);if("pending"===t.match.state.status)throw t.match.__loadPromise;n(!1)}),[]),i=e.pendingComponent??r.options.defaultPendingComponent??a,c=e.errorComponent??r.options.defaultErrorComponent,h=e.route.options.wrapInSuspense??1?o.Suspense:lt,u=c?pt:lt;return o.createElement(rt.Provider,{value:t},o.createElement(h,{fallback:o.createElement(i,null)},o.createElement(u,{key:e.route.id,errorComponent:c,onCatch:()=>{e.id}},o.createElement(s,{match:e}))))}function lt(t){return o.createElement(o.Fragment,null,t.children)}class pt extends o.Component{state={error:!1,info:void 0};componentDidCatch(t,e){this.props.onCatch(t,e),console.error(t),this.setState({error:t,info:e})}render(){return o.createElement(dt,s({},this.props,{errorState:this.state,reset:()=>this.setState({})}))}}function dt(t){const[e,r]=o.useState(t.errorState),a=ot(),s=t.errorComponent??ft,n=o.useRef("");return o.useEffect((()=>{e&&a.state.currentLocation.key!==n.current&&r({}),n.current=a.state.currentLocation.key}),[e,a.state.currentLocation.key]),o.useEffect((()=>{t.errorState.error&&r(t.errorState)}),[t.errorState.error]),t.errorState.error&&e.error?o.createElement(s,e):t.children}function ft({error:t}){return o.createElement("div",{style:{padding:".5rem",maxWidth:"100%"}},o.createElement("strong",{style:{fontSize:"1.2rem"}},"Something went wrong!"),o.createElement("div",{style:{height:".5rem"}}),o.createElement("div",null,o.createElement("pre",{style:{fontSize:".7em",border:"1px solid red",borderRadius:".25rem",padding:".5rem",color:"red",overflow:"auto"}},t.message?o.createElement("code",null,t.message):null)))}function mt(t,e=!0){const r=st();o.useEffect((()=>{if(!e)return;let a=r.history.block(((e,r)=>{window.confirm(t)?(a(),e()):r()}));return a}))}t.Block=function({message:t,when:e,children:r}){return mt(t,e),r??null},t.ErrorComponent=ft,t.Link=et,t.MatchRoute=function(t){const e=ct()(t);return e?"function"==typeof t.children?t.children(e):e?t.children:null:null},t.Navigate=function(t){const e=ot();return o.useLayoutEffect((()=>{e.navigate(t)}),[]),null},t.Outlet=ht,t.ReactRouter=class extends K{constructor(t){super({...t,loadComponent:async t=>(t.preload&&await t.preload(),t)})}},t.RootRoute=B,t.Route=H,t.RouteMatch=X,t.Router=K,t.RouterProvider=function({router:t,...e}){t.update(e);const r=Y(t.__store,(t=>t.currentMatches));return o.useEffect(t.mount,[t]),o.createElement(at.Provider,{value:{router:t}},o.createElement(rt.Provider,{value:[void 0,...r]},o.createElement(pt,{errorComponent:ft,onCatch:()=>{}},o.createElement(ht,null))))},t.cleanPath=x,t.createBrowserHistory=f,t.createHashHistory=function(){return f({getHref:()=>window.location.hash.substring(1),createHref:t=>`#${t}`})},t.createMemoryHistory=m,t.decode=D,t.defaultFetchServerDataFn=W,t.defaultParseSearch=F,t.defaultStringifySearch=U,t.encode=A,t.functionalUpdate=b,t.interpolatePath=j,t.invariant=n,t.isPlainObject=_,t.isRedirect=G,t.joinPaths=P,t.last=v,t.lazy=function(t){const e=o.lazy(t);return e.preload=async()=>{await t()},e},t.matchByPath=$,t.matchPathname=I,t.matchesContext=rt,t.parsePathname=O,t.parseSearchWith=z,t.partialDeepEqual=E,t.pick=w,t.redirect=function(t){return t.isRedirect=!0,t},t.replaceEqualDeep=S,t.resolvePath=k,t.rootRouteId=N,t.routerContext=at,t.stringifySearchWith=q,t.trimPath=M,t.trimPathLeft=R,t.trimPathRight=C,t.useBlocker=mt,t.useLinkProps=tt,t.useMatch=it,t.useMatchRoute=ct,t.useMatches=nt,t.useNavigate=function(t){const e=ot();return o.useCallback((r=>e.navigate({...t,...r})),[])},t.useParams=function(t){const e=ot();return Y(e.__store,(e=>{const r=v(e.currentMatches)?.params;return t?.track?.(r)??r}),!0),v(e.state.currentMatches)?.params},t.useRoute=function(t){const e=ot().getRoute(t);return n(e),e},t.useRouter=st,t.useRouterContext=ot,t.useSearch=function(t){const{track:e,...r}=t,a=it(r);return Y(a.__store,(e=>t?.track?.(e.search)??e.search),!0),a.state.search},t.useStore=Y,t.warning=i,Object.defineProperty(t,"__esModule",{value:!0})}));
41
+ */function Y(t,e=(t=>t),a){return r.useSyncExternalStoreWithSelector(t.subscribe,(()=>t.state),(()=>t.state),e,a?Z:void 0)}function Z(t,e){if(Object.is(t,e))return!0;if("object"!=typeof t||null===t||"object"!=typeof e||null===e)return!1;const r=Object.keys(t);if(r.length!==Object.keys(e).length)return!1;for(let a=0;a<r.length;a++)if(!Object.prototype.hasOwnProperty.call(e,r[a])||!Object.is(t[r[a]],e[r[a]]))return!1;return!0}function tt(t){const e=ot(),{type:r,children:a,target:s,activeProps:n=(()=>({className:"active"})),inactiveProps:i=(()=>({})),activeOptions:c,disabled:h,hash:u,search:l,params:p,to:d=".",preload:f,preloadDelay:m,replace:y,style:g,className:v,onClick:w,onFocus:S,onMouseEnter:_,onMouseLeave:L,onTouchStart:E,...P}=t,x=e.buildLink(t);if("external"===x.type){const{href:t}=x;return{href:t}}const{handleClick:R,handleFocus:C,handleEnter:M,handleLeave:k,handleTouchStart:O,isActive:j,next:I}=x,$=t=>e=>{e.persist&&e.persist(),t.filter(Boolean).forEach((t=>{e.defaultPrevented||t(e)}))},A=j?b(n,{})??{}:{},T=j?{}:b(i,{})??{};return{...A,...T,...P,href:h?void 0:I.href,onClick:$([w,t=>{o.startTransition?o.startTransition((()=>{R(t)})):R(t)}]),onFocus:$([S,C]),onMouseEnter:$([_,M]),onMouseLeave:$([L,k]),onTouchStart:$([E,O]),target:s,style:{...g,...A.style,...T.style},className:[v,A.className,T.className].filter(Boolean).join(" ")||void 0,...h?{role:"link","aria-disabled":!0}:void 0,"data-status":j?"active":void 0}}const et=o.forwardRef(((t,e)=>{const r=tt(t);return o.createElement("a",s({ref:e},r,{children:"function"==typeof t.children?t.children({isActive:"active"===r["data-status"]}):t.children}))}));const rt=o.createContext(null),at=o.createContext(null);function ot(){const t=o.useContext(at);return Y(t.router.__store),t.router}function st(t,e){const r=ot();return Y(r.__store,t,e),r}function nt(){return o.useContext(rt)}function it(t){const e=ot(),r=nt()[0],a=t?.from?e.state.currentMatches.find((e=>e.route.id===t?.from)):r;return n(a,t?.from&&t.from),(t?.strict??1)&&n(r.route.id==a?.route.id,(a?.route.id,r.route.id,a?.route.id,a?.route.id)),Y(a.__store,(e=>t?.track?.(a)??a),t?.shallow),a}function ct(){const t=ot();return o.useCallback((e=>{const{pending:r,caseSensitive:a,...o}=e;return t.matchRoute(o,{pending:r,caseSensitive:a})}),[])}function ht(){const t=nt().slice(1),e=t[0];return e?o.createElement(ut,{matches:t,match:e}):null}function ut({matches:t,match:e}){const r=ot();Y(e.__store,(t=>[t.status,t.error]),!0);const a=o.useCallback((()=>null),[]),s=o.useCallback((t=>{if("error"===t.match.state.status)throw t.match.state.error;if("success"===t.match.state.status)return o.createElement(t.match.component??r.options.defaultComponent??ht);if("pending"===t.match.state.status)throw t.match.__loadPromise;n(!1)}),[]),i=e.pendingComponent??r.options.defaultPendingComponent??a,c=e.errorComponent??r.options.defaultErrorComponent,h=e.route.options.wrapInSuspense??1?o.Suspense:lt,u=c?pt:lt;return o.createElement(rt.Provider,{value:t},o.createElement(h,{fallback:o.createElement(i,null)},o.createElement(u,{key:e.route.id,errorComponent:c,onCatch:()=>{e.id}},o.createElement(s,{match:e}))))}function lt(t){return o.createElement(o.Fragment,null,t.children)}class pt extends o.Component{state={error:!1,info:void 0};componentDidCatch(t,e){this.props.onCatch(t,e),console.error(t),this.setState({error:t,info:e})}render(){return o.createElement(dt,s({},this.props,{errorState:this.state,reset:()=>this.setState({})}))}}function dt(t){const[e,r]=o.useState(t.errorState),a=ot(),s=t.errorComponent??ft,n=o.useRef("");return o.useEffect((()=>{e&&a.state.currentLocation.key!==n.current&&r({}),n.current=a.state.currentLocation.key}),[e,a.state.currentLocation.key]),o.useEffect((()=>{t.errorState.error&&r(t.errorState)}),[t.errorState.error]),t.errorState.error&&e.error?o.createElement(s,e):t.children}function ft({error:t}){return o.createElement("div",{style:{padding:".5rem",maxWidth:"100%"}},o.createElement("strong",{style:{fontSize:"1.2rem"}},"Something went wrong!"),o.createElement("div",{style:{height:".5rem"}}),o.createElement("div",null,o.createElement("pre",{style:{fontSize:".7em",border:"1px solid red",borderRadius:".25rem",padding:".5rem",color:"red",overflow:"auto"}},t.message?o.createElement("code",null,t.message):null)))}function mt(t,e=!0){const r=st();o.useEffect((()=>{if(!e)return;let a=r.history.block(((e,r)=>{window.confirm(t)?(a(),e()):r()}));return a}))}t.Block=function({message:t,condition:e,children:r}){return mt(t,e),r??null},t.ErrorComponent=ft,t.Link=et,t.MatchRoute=function(t){const e=ct()(t);return e?"function"==typeof t.children?t.children(e):e?t.children:null:null},t.Navigate=function(t){const e=ot();return o.useLayoutEffect((()=>{e.navigate(t)}),[]),null},t.Outlet=ht,t.ReactRouter=class extends K{constructor(t){super({...t,loadComponent:async t=>(t.preload&&await t.preload(),t)})}},t.RootRoute=B,t.Route=H,t.RouteMatch=X,t.Router=K,t.RouterProvider=function({router:t,...e}){t.update(e);const r=Y(t.__store,(t=>t.currentMatches));return o.useEffect(t.mount,[t]),o.createElement(at.Provider,{value:{router:t}},o.createElement(rt.Provider,{value:[void 0,...r]},o.createElement(pt,{errorComponent:ft,onCatch:()=>{}},o.createElement(ht,null))))},t.cleanPath=x,t.createBrowserHistory=f,t.createHashHistory=function(){return f({getHref:()=>window.location.hash.substring(1),createHref:t=>`#${t}`})},t.createMemoryHistory=m,t.decode=D,t.defaultFetchServerDataFn=W,t.defaultParseSearch=F,t.defaultStringifySearch=U,t.encode=A,t.functionalUpdate=b,t.interpolatePath=j,t.invariant=n,t.isPlainObject=_,t.isRedirect=G,t.joinPaths=P,t.last=v,t.lazy=function(t){const e=o.lazy(t);return e.preload=async()=>{await t()},e},t.matchByPath=$,t.matchPathname=I,t.matchesContext=rt,t.parsePathname=O,t.parseSearchWith=z,t.partialDeepEqual=E,t.pick=w,t.redirect=function(t){return t.isRedirect=!0,t},t.replaceEqualDeep=S,t.resolvePath=k,t.rootRouteId=N,t.routerContext=at,t.stringifySearchWith=q,t.trimPath=M,t.trimPathLeft=R,t.trimPathRight=C,t.useBlocker=mt,t.useLinkProps=tt,t.useMatch=it,t.useMatchRoute=ct,t.useMatches=nt,t.useNavigate=function(t){const e=ot();return o.useCallback((r=>e.navigate({...t,...r})),[])},t.useParams=function(t){const e=ot();return Y(e.__store,(e=>{const r=v(e.currentMatches)?.params;return t?.track?.(r)??r}),!0),v(e.state.currentMatches)?.params},t.useRoute=function(t){const e=ot().getRoute(t);return n(e),e},t.useRouter=st,t.useRouterContext=ot,t.useSearch=function(t){const{track:e,...r}=t,a=it(r);return Y(a.__store,(e=>t?.track?.(e.search)??e.search),!0),a.state.search},t.useStore=Y,t.warning=i,Object.defineProperty(t,"__esModule",{value:!0})}));
42
42
  //# sourceMappingURL=index.production.js.map