@ngrok/mantle 0.55.0 → 0.55.2
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.
|
@@ -1,43 +1,70 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { PropsWithChildren } from 'react';
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
|
-
* React component that auto-scrolls to the element matching the current URL hash
|
|
5
|
+
* React component that auto-scrolls to the element matching the current URL hash
|
|
6
|
+
* (e.g., `#subscription`). It also provides a context so consumers can
|
|
7
|
+
* programmatically re-run the scroll after asynchronous content mounts.
|
|
8
|
+
*
|
|
9
|
+
* Behavior
|
|
10
|
+
* - Runs on initial mount and whenever the `location.hash` changes.
|
|
11
|
+
* - Schedules the scroll in `requestAnimationFrame` to ensure the target exists
|
|
12
|
+
* after DOM updates/paint.
|
|
13
|
+
* - Respects the user's motion preference via {@link useScrollBehavior}
|
|
14
|
+
* (i.e., `"auto"` when reduced motion is enabled; `"smooth"` otherwise).
|
|
15
|
+
* - Cancels a pending animation frame on unmount or dependency change.
|
|
16
|
+
*
|
|
17
|
+
* Accessibility
|
|
18
|
+
* - Honors reduced-motion preferences; no sudden scrolling for motion-sensitive users.
|
|
3
19
|
*
|
|
4
|
-
*
|
|
5
|
-
* -
|
|
6
|
-
* - Schedules the scroll in `requestAnimationFrame` to ensure the target element
|
|
7
|
-
* exists after DOM updates/paint.
|
|
8
|
-
* - Respects the user's motion preference via `useScrollBehavior()` (i.e., `"auto"` when
|
|
9
|
-
* reduced motion is enabled; `"smooth"` otherwise).
|
|
10
|
-
* - Safe for SSR via `useIsomorphicLayoutEffect`.
|
|
20
|
+
* SSR
|
|
21
|
+
* - Uses {@link useIsomorphicLayoutEffect} so it is safe to include in code that may render on the server.
|
|
11
22
|
*
|
|
12
23
|
* @example
|
|
13
|
-
*
|
|
24
|
+
* ```tsx
|
|
25
|
+
* // App shell
|
|
26
|
+
* <Router>
|
|
27
|
+
* <AutoScrollToHash>
|
|
28
|
+
* <TheRestOfYourApp />
|
|
29
|
+
* </AutoScrollToHash>
|
|
30
|
+
* </Router>
|
|
31
|
+
* ```
|
|
14
32
|
*
|
|
15
33
|
* @remarks
|
|
16
34
|
* If your content is loaded asynchronously and may not exist by the next animation
|
|
17
|
-
* frame,
|
|
35
|
+
* frame, call the public hook {@link useAutoScrollToHash} to re-run the scroll once
|
|
36
|
+
* the content is in the DOM.
|
|
18
37
|
*/
|
|
19
|
-
declare function AutoScrollToHash():
|
|
20
|
-
type Props = {
|
|
21
|
-
/** Disable automatic scrolling to hash targets. */
|
|
22
|
-
disabled?: boolean;
|
|
23
|
-
};
|
|
38
|
+
declare function AutoScrollToHash({ children }: PropsWithChildren): react_jsx_runtime.JSX.Element;
|
|
24
39
|
/**
|
|
25
|
-
*
|
|
40
|
+
* Public hook that returns a stable callback for programmatically re-running the
|
|
41
|
+
* hash-based scroll performed by {@link AutoScrollToHash}.
|
|
26
42
|
*
|
|
27
|
-
*
|
|
28
|
-
* -
|
|
29
|
-
*
|
|
43
|
+
* Use this when the element for the current `location.hash` is rendered later
|
|
44
|
+
* (e.g., after lazy-loading a route, switching tabs, or finishing an async fetch)
|
|
45
|
+
* so you can bring it into view once it exists.
|
|
30
46
|
*
|
|
31
|
-
*
|
|
47
|
+
* The hook throws if it is used outside of an {@link AutoScrollToHash} provider.
|
|
48
|
+
*
|
|
49
|
+
* @returns A stable `() => void` function that, when called, scrolls the hash target into view if present.
|
|
32
50
|
*
|
|
33
51
|
* @example
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
52
|
+
* ```tsx
|
|
53
|
+
* function DetailsTab({ ready }: { ready: boolean }) {
|
|
54
|
+
* const reScroll = useAutoScrollToHash();
|
|
55
|
+
*
|
|
56
|
+
* useEffect(() => {
|
|
57
|
+
* if (ready) {
|
|
58
|
+
* reScroll();
|
|
59
|
+
* }
|
|
60
|
+
* }, [ready, reScroll]);
|
|
61
|
+
*
|
|
62
|
+
* return <div id="subscription">...</div>;
|
|
37
63
|
* }
|
|
64
|
+
* ```
|
|
38
65
|
*
|
|
39
|
-
* @see {@link
|
|
66
|
+
* @see {@link AutoScrollToHash}
|
|
40
67
|
*/
|
|
41
|
-
declare function useAutoScrollToHash(
|
|
68
|
+
declare function useAutoScrollToHash(): () => void;
|
|
42
69
|
|
|
43
70
|
export { AutoScrollToHash, useAutoScrollToHash };
|
|
@@ -1,19 +1,2 @@
|
|
|
1
|
-
import{a as
|
|
2
|
-
|
|
3
|
-
Please change the parent <Route path="${p}"> to <Route path="${p==="/"?"*":`${p}/*`}">.`)}let m=D(),y;if(t){let p=typeof t=="string"?$(t):t;b(c==="/"||p.pathname?.startsWith(c),`When overriding the location using \`<Routes location>\` or \`useRoutes(routes, location)\`, the location pathname must begin with the portion of the URL pathname that was matched by all parent routes. The current pathname base is "${c}" but pathname "${p.pathname}" was given in the \`location\` prop.`),y=p}else y=m;let R=y.pathname||"/",E=R;if(c!=="/"){let p=c.replace(/^\//,"").split("/");E="/"+R.replace(/^\//,"").split("/").slice(p.length).join("/")}let w=oe(e,{pathname:E});re&&(L(d||w!=null,`No routes matched location "${y.pathname}${y.search}${y.hash}" `),L(w==null||w[w.length-1].route.element!==void 0||w[w.length-1].route.Component!==void 0||w[w.length-1].route.lazy!==void 0,`Matched leaf route at location "${y.pathname}${y.search}${y.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.`));let v=Nt(w&&w.map(p=>Object.assign({},p,{params:Object.assign({},s,p.params),pathname:M([c,o.encodeLocation?o.encodeLocation(p.pathname.replace(/\?/g,"%3F").replace(/#/g,"%23")).pathname:p.pathname]),pathnameBase:p.pathnameBase==="/"?c:M([c,o.encodeLocation?o.encodeLocation(p.pathnameBase.replace(/\?/g,"%3F").replace(/#/g,"%23")).pathname:p.pathnameBase])})),i,r,n,a);return t&&v?f.createElement(H.Provider,{value:{location:{pathname:"/",search:"",hash:"",state:null,key:"default",...y},navigationType:"POP"}},v):v}function xt(){let e=_e(),t=Le(e)?`${e.status} ${e.statusText}`:e instanceof Error?e.message:JSON.stringify(e),r=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},i=null;return re&&(console.error("Error handled by React Router default ErrorBoundary:",e),i=f.createElement(f.Fragment,null,f.createElement("p",null,"\u{1F4BF} Hey developer \u{1F44B}"),f.createElement("p",null,"You can provide a way better UX than this when your app throws errors by providing your own ",f.createElement("code",{style:o},"ErrorBoundary")," or"," ",f.createElement("code",{style:o},"errorElement")," prop on your route."))),f.createElement(f.Fragment,null,f.createElement("h2",null,"Unexpected Application Error!"),f.createElement("h3",{style:{fontStyle:"italic"}},t),r?f.createElement("pre",{style:a},r):null,i)}var Lt=f.createElement(xt,null),Dt=class extends f.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,t){return t.location!==e.location||t.revalidation!=="idle"&&e.revalidation==="idle"?{error:e.error,location:e.location,revalidation:e.revalidation}:{error:e.error!==void 0?e.error:t.error,location:t.location,revalidation:e.revalidation||t.revalidation}}componentDidCatch(e,t){this.props.unstable_onError?this.props.unstable_onError(e,t):console.error("React Router caught the following error during render",e)}render(){return this.state.error!==void 0?f.createElement(T.Provider,{value:this.props.routeContext},f.createElement(le.Provider,{value:this.state.error,children:this.props.component})):this.props.children}};function Ft({routeContext:e,match:t,children:r}){let n=f.useContext(O);return n&&n.static&&n.staticContext&&(t.route.errorElement||t.route.ErrorBoundary)&&(n.staticContext._deepestRenderedBoundaryId=t.route.id),f.createElement(T.Provider,{value:e},r)}function Nt(e,t=[],r=null,n=null,a=null){if(e==null){if(!r)return null;if(r.errors)e=r.matches;else if(t.length===0&&!r.initialized&&r.matches.length>0)e=r.matches;else return null}let o=e,i=r?.errors;if(i!=null){let l=o.findIndex(c=>c.route.id&&i?.[c.route.id]!==void 0);b(l>=0,`Could not find a matching route for errors on route IDs: ${Object.keys(i).join(",")}`),o=o.slice(0,Math.min(o.length,l+1))}let u=!1,s=-1;if(r)for(let l=0;l<o.length;l++){let c=o[l];if((c.route.HydrateFallback||c.route.hydrateFallbackElement)&&(s=l),c.route.id){let{loaderData:d,errors:m}=r,y=c.route.loader&&!d.hasOwnProperty(c.route.id)&&(!m||m[c.route.id]===void 0);if(c.route.lazy||y){u=!0,s>=0?o=o.slice(0,s+1):o=[o[0]];break}}}return o.reduceRight((l,c,d)=>{let m,y=!1,R=null,E=null;r&&(m=i&&c.route.id?i[c.route.id]:void 0,R=c.route.errorElement||Lt,u&&(s<0&&d===0?(ke("route-fallback",!1,"No `HydrateFallback` element provided to render during initial hydration"),y=!0,E=null):s===d&&(y=!0,E=c.route.hydrateFallbackElement||null)));let w=t.concat(o.slice(0,d+1)),v=()=>{let p;return m?p=R:y?p=E:c.route.Component?p=f.createElement(c.route.Component,null):c.route.element?p=c.route.element:p=l,f.createElement(Ft,{match:c,routeContext:{outlet:l,matches:w,isDataRoute:r!=null},children:p})};return r&&(c.route.ErrorBoundary||c.route.errorElement||d===0)?f.createElement(Dt,{location:r.location,revalidation:r.revalidation,component:R,error:m,children:v(),routeContext:{outlet:null,matches:w,isDataRoute:!0},unstable_onError:n}):v()},null)}function se(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function Tt(e){let t=f.useContext(O);return b(t,se(e)),t}function ue(e){let t=f.useContext(I);return b(t,se(e)),t}function Mt(e){let t=f.useContext(T);return b(t,se(e)),t}function ce(e){let t=Mt(e),r=t.matches[t.matches.length-1];return b(r.route.id,`${e} can only be used on routes that contain a unique "id"`),r.route.id}function At(){return ce("useRouteId")}function Oe(){return ue("useNavigation").navigation}function de(){let{matches:e,loaderData:t}=ue("useMatches");return f.useMemo(()=>e.map(r=>nt(r,t)),[e,t])}function _e(){let e=f.useContext(le),t=ue("useRouteError"),r=ce("useRouteError");return e!==void 0?e:t.errors?.[r]}function Ot(){let{router:e}=Tt("useNavigate"),t=ce("useNavigate"),r=f.useRef(!1);return Me(()=>{r.current=!0}),f.useCallback(async(a,o={})=>{L(r.current,Te),r.current&&(typeof a=="number"?e.navigate(a):await e.navigate(a,{fromRouteId:t,...o}))},[e,t])}var we={};function ke(e,t,r){!t&&!we[e]&&(we[e]=!0,L(!1,r))}var Rr=C.memo(_t);function _t({routes:e,future:t,state:r,unstable_onError:n}){return Pt(e,void 0,r,n,t)}function $e({basename:e="/",children:t=null,location:r,navigationType:n="POP",navigator:a,static:o=!1}){b(!U(),"You cannot render a <Router> inside another <Router>. You should never have more than one in your app.");let i=e.replace(/^\/*/,"/"),u=C.useMemo(()=>({basename:i,navigator:a,static:o,future:{}}),[i,a,o]);typeof r=="string"&&(r=$(r));let{pathname:s="/",search:l="",hash:c="",state:d=null,key:m="default"}=r,y=C.useMemo(()=>{let R=N(s,i);return R==null?null:{location:{pathname:R,search:l,hash:c,state:d,key:m},navigationType:n}},[i,s,l,c,d,m,n]);return L(y!=null,`<Router basename="${i}"> is not able to match the URL "${s}${l}${c}" because it does not start with the basename, so the <Router> won't render anything.`),y==null?null:C.createElement(x.Provider,{value:u},C.createElement(H.Provider,{children:t,value:y}))}var X="get",Q="application/x-www-form-urlencoded";function q(e){return e!=null&&typeof e.tagName=="string"}function kt(e){return q(e)&&e.tagName.toLowerCase()==="button"}function $t(e){return q(e)&&e.tagName.toLowerCase()==="form"}function It(e){return q(e)&&e.tagName.toLowerCase()==="input"}function Ht(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function Ut(e,t){return e.button===0&&(!t||t==="_self")&&!Ht(e)}var K=null;function jt(){if(K===null)try{new FormData(document.createElement("form"),0),K=!1}catch{K=!0}return K}var Bt=new Set(["application/x-www-form-urlencoded","multipart/form-data","text/plain"]);function te(e){return e!=null&&!Bt.has(e)?(L(!1,`"${e}" is not a valid \`encType\` for \`<Form>\`/\`<fetcher.Form>\` and will default to "${Q}"`),null):e}function zt(e,t){let r,n,a,o,i;if($t(e)){let u=e.getAttribute("action");n=u?N(u,t):null,r=e.getAttribute("method")||X,a=te(e.getAttribute("enctype"))||Q,o=new FormData(e)}else if(kt(e)||It(e)&&(e.type==="submit"||e.type==="image")){let u=e.form;if(u==null)throw new Error('Cannot submit a <button> or <input type="submit"> without a <form>');let s=e.getAttribute("formaction")||u.getAttribute("action");if(n=s?N(s,t):null,r=e.getAttribute("formmethod")||u.getAttribute("method")||X,a=te(e.getAttribute("formenctype"))||te(u.getAttribute("enctype"))||Q,o=new FormData(u,e),!jt()){let{name:l,type:c,value:d}=e;if(c==="image"){let m=l?`${l}.`:"";o.append(`${m}x`,"0"),o.append(`${m}y`,"0")}else l&&o.append(l,d)}}else{if(q(e))throw new Error('Cannot submit element that is not <form>, <button>, or <input type="submit|image">');r=X,n=null,a=Q,i=e}return o&&a==="text/plain"&&(i=o,o=void 0),{action:n,method:r.toLowerCase(),encType:a,formData:o,body:i}}var gr=Object.getOwnPropertyNames(Object.prototype).sort().join("\0");function he(e,t){if(e===!1||e===null||typeof e>"u")throw new Error(t)}var Wt=Symbol("SingleFetchRedirect");function Vt(e,t,r){let n=typeof e=="string"?new URL(e,typeof window>"u"?"server://singlefetch/":window.location.origin):e;return n.pathname==="/"?n.pathname=`_root.${r}`:t&&N(n.pathname,t)==="/"?n.pathname=`${t.replace(/\/$/,"")}/_root.${r}`:n.pathname=`${n.pathname.replace(/\/$/,"")}.${r}`,n}async function Yt(e,t){if(e.id in t)return t[e.id];try{let r=await import(e.module);return t[e.id]=r,r}catch(r){if(console.error(`Error loading route module \`${e.module}\`, reloading page...`),console.error(r),window.__reactRouterContext&&window.__reactRouterContext.isSpaMode&&import.meta.hot)throw r;return window.location.reload(),new Promise(()=>{})}}function Jt(e){return e!=null&&typeof e.page=="string"}function Kt(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 Gt(e,t,r){let n=await Promise.all(e.map(async a=>{let o=t.routes[a.route.id];if(o){let i=await Yt(o,r);return i.links?i.links():[]}return[]}));return qt(n.flat(1).filter(Kt).filter(a=>a.rel==="stylesheet"||a.rel==="preload").map(a=>a.rel==="stylesheet"?{...a,rel:"prefetch",as:"style"}:{...a,rel:"prefetch"}))}function Ee(e,t,r,n,a,o){let i=(s,l)=>r[l]?s.route.id!==r[l].route.id:!0,u=(s,l)=>r[l].pathname!==s.pathname||r[l].route.path?.endsWith("*")&&r[l].params["*"]!==s.params["*"];return o==="assets"?t.filter((s,l)=>i(s,l)||u(s,l)):o==="data"?t.filter((s,l)=>{let c=n.routes[s.route.id];if(!c||!c.hasLoader)return!1;if(i(s,l)||u(s,l))return!0;if(s.route.shouldRevalidate){let d=s.route.shouldRevalidate({currentUrl:new URL(a.pathname+a.search+a.hash,window.origin),currentParams:r[0]?.params||{},nextUrl:new URL(e,window.origin),nextParams:s.params,defaultShouldRevalidate:!0});if(typeof d=="boolean")return d}return!0}):[]}function Xt(e,t,{includeHydrateFallback:r}={}){return Qt(e.map(n=>{let a=t.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)),r&&a.hydrateFallbackModule&&(o=o.concat(a.hydrateFallbackModule)),a.imports&&(o=o.concat(a.imports)),o}).flat(1))}function Qt(e){return[...new Set(e)]}function Zt(e){let t={},r=Object.keys(e).sort();for(let n of r)t[n]=e[n];return t}function qt(e,t){let r=new Set,n=new Set(t);return e.reduce((a,o)=>{if(t&&!Jt(o)&&o.as==="script"&&o.href&&n.has(o.href))return a;let u=JSON.stringify(Zt(o));return r.has(u)||(r.add(u),a.push({key:u,link:o})),a},[])}function He(){let e=g.useContext(O);return he(e,"You must render this element inside a <DataRouterContext.Provider> element"),e}function ar(){let e=g.useContext(I);return he(e,"You must render this element inside a <DataRouterStateContext.Provider> element"),e}var V=g.createContext(void 0);V.displayName="FrameworkContext";function Ue(){let e=g.useContext(V);return he(e,"You must render this element inside a <HydratedRouter> element"),e}function nr(e,t){let r=g.useContext(V),[n,a]=g.useState(!1),[o,i]=g.useState(!1),{onFocus:u,onBlur:s,onMouseEnter:l,onMouseLeave:c,onTouchStart:d}=t,m=g.useRef(null);g.useEffect(()=>{if(e==="render"&&i(!0),e==="viewport"){let E=v=>{v.forEach(p=>{i(p.isIntersecting)})},w=new IntersectionObserver(E,{threshold:.5});return m.current&&w.observe(m.current),()=>{w.disconnect()}}},[e]),g.useEffect(()=>{if(n){let E=setTimeout(()=>{i(!0)},100);return()=>{clearTimeout(E)}}},[n]);let y=()=>{a(!0)},R=()=>{a(!1),i(!1)};return r?e!=="intent"?[o,m,{}]:[o,m,{onFocus:z(u,y),onBlur:z(s,R),onMouseEnter:z(l,y),onMouseLeave:z(c,R),onTouchStart:z(d,y)}]:[!1,m,{}]}function z(e,t){return r=>{e&&e(r),r.defaultPrevented||t(r)}}function je({page:e,...t}){let{router:r}=He(),n=g.useMemo(()=>oe(r.routes,e,r.basename),[r.routes,e,r.basename]);return n?g.createElement(ir,{page:e,matches:n,...t}):null}function or(e){let{manifest:t,routeModules:r}=Ue(),[n,a]=g.useState([]);return g.useEffect(()=>{let o=!1;return Gt(e,t,r).then(i=>{o||a(i)}),()=>{o=!0}},[e,t,r]),n}function ir({page:e,matches:t,...r}){let n=D(),{manifest:a,routeModules:o}=Ue(),{basename:i}=He(),{loaderData:u,matches:s}=ar(),l=g.useMemo(()=>Ee(e,t,s,a,n,"data"),[e,t,s,a,n]),c=g.useMemo(()=>Ee(e,t,s,a,n,"assets"),[e,t,s,a,n]),d=g.useMemo(()=>{if(e===n.pathname+n.search+n.hash)return[];let R=new Set,E=!1;if(t.forEach(v=>{let p=a.routes[v.route.id];!p||!p.hasLoader||(!l.some(S=>S.route.id===v.route.id)&&v.route.id in u&&o[v.route.id]?.shouldRevalidate||p.hasClientLoader?E=!0:R.add(v.route.id))}),R.size===0)return[];let w=Vt(e,i,"data");return E&&R.size>0&&w.searchParams.set("_routes",t.filter(v=>R.has(v.route.id)).map(v=>v.route.id).join(",")),[w.pathname+w.search]},[i,u,n,a,l,t,e,o]),m=g.useMemo(()=>Xt(c,a),[c,a]),y=or(c);return g.createElement(g.Fragment,null,d.map(R=>g.createElement("link",{key:R,rel:"prefetch",as:"fetch",href:R,...r})),m.map(R=>g.createElement("link",{key:R,rel:"modulepreload",href:R,...r})),y.map(({key:R,link:E})=>g.createElement("link",{key:R,nonce:r.nonce,...E})))}function lr(...e){return t=>{e.forEach(r=>{typeof r=="function"?r(t):r!=null&&(r.current=t)})}}var Be=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";try{Be&&(window.__reactRouterVersion="7.9.3")}catch{}function ze({basename:e,children:t,history:r}){let[n,a]=h.useState({action:r.action,location:r.location}),o=h.useCallback(i=>{h.startTransition(()=>a(i))},[a]);return h.useLayoutEffect(()=>r.listen(o),[r,o]),h.createElement($e,{basename:e,children:t,location:n.location,navigationType:n.action,navigator:r})}ze.displayName="unstable_HistoryRouter";var We=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,me=h.forwardRef(function({onClick:t,discover:r="render",prefetch:n="none",relative:a,reloadDocument:o,replace:i,state:u,target:s,to:l,preventScrollReset:c,viewTransition:d,...m},y){let{basename:R}=h.useContext(x),E=typeof l=="string"&&We.test(l),w,v=!1;if(typeof l=="string"&&E&&(w=l,Be))try{let F=new URL(window.location.href),k=l.startsWith("//")?new URL(F.protocol+l):new URL(l),ye=N(k.pathname,R);k.origin===F.origin&&ye!=null?l=ye+k.search+k.hash:v=!0}catch{L(!1,`<Link to="${l}"> contains an invalid URL which will probably break when clicked - please update to a valid URL path.`)}let p=Ne(l,{relative:a}),[S,_,A]=nr(n,m),Y=Ge(l,{replace:i,state:u,target:s,preventScrollReset:c,relative:a,viewTransition:d});function B(F){t&&t(F),F.defaultPrevented||Y(F)}let J=h.createElement("a",{...m,...A,href:w||p,onClick:v||o?t:B,ref:lr(y,_),target:s,"data-discover":!E&&r==="render"?"true":void 0});return S&&!E?h.createElement(h.Fragment,null,J,h.createElement(je,{page:p})):J});me.displayName="Link";var Ve=h.forwardRef(function({"aria-current":t="page",caseSensitive:r=!1,className:n="",end:a=!1,style:o,to:i,viewTransition:u,children:s,...l},c){let d=j(i,{relative:l.relative}),m=D(),y=h.useContext(I),{navigator:R,basename:E}=h.useContext(x),w=y!=null&&qe(d)&&u===!0,v=R.encodeLocation?R.encodeLocation(d).pathname:d.pathname,p=m.pathname,S=y&&y.navigation&&y.navigation.location?y.navigation.location.pathname:null;r||(p=p.toLowerCase(),S=S?S.toLowerCase():null,v=v.toLowerCase()),S&&E&&(S=N(S,E)||S);let _=v!=="/"&&v.endsWith("/")?v.length-1:v.length,A=p===v||!a&&p.startsWith(v)&&p.charAt(_)==="/",Y=S!=null&&(S===v||!a&&S.startsWith(v)&&S.charAt(v.length)==="/"),B={isActive:A,isPending:Y,isTransitioning:w},J=A?t:void 0,F;typeof n=="function"?F=n(B):F=[n,A?"active":null,Y?"pending":null,w?"transitioning":null].filter(Boolean).join(" ");let k=typeof o=="function"?o(B):o;return h.createElement(me,{...l,"aria-current":J,className:F,ref:c,style:k,to:i,viewTransition:u},typeof s=="function"?s(B):s)});Ve.displayName="NavLink";var Ye=h.forwardRef(({discover:e="render",fetcherKey:t,navigate:r,reloadDocument:n,replace:a,state:o,method:i=X,action:u,onSubmit:s,relative:l,preventScrollReset:c,viewTransition:d,...m},y)=>{let R=Xe(),E=Qe(u,{relative:l}),w=i.toLowerCase()==="get"?"get":"post",v=typeof u=="string"&&We.test(u);return h.createElement("form",{ref:y,method:w,action:E,onSubmit:n?s:S=>{if(s&&s(S),S.defaultPrevented)return;S.preventDefault();let _=S.nativeEvent.submitter,A=_?.getAttribute("formmethod")||i;R(_||S.currentTarget,{fetcherKey:t,method:A,navigate:r,replace:a,state:o,relative:l,preventScrollReset:c,viewTransition:d})},...m,"data-discover":!v&&e==="render"?"true":void 0})});Ye.displayName="Form";function Je({getKey:e,storageKey:t,...r}){let n=h.useContext(V),{basename:a}=h.useContext(x),o=D(),i=de();Ze({getKey:e,storageKey:t});let u=h.useMemo(()=>{if(!n||!e)return null;let l=ne(o,i,a,e);return l!==o.key?l:null},[]);if(!n||n.isSpaMode)return null;let s=((l,c)=>{if(!window.history.state||!window.history.state.key){let d=Math.random().toString(32).slice(2);window.history.replaceState({key:d},"")}try{let m=JSON.parse(sessionStorage.getItem(l)||"{}")[c||window.history.state.key];typeof m=="number"&&window.scrollTo(0,m)}catch(d){console.error(d),sessionStorage.removeItem(l)}}).toString();return h.createElement("script",{...r,suppressHydrationWarning:!0,dangerouslySetInnerHTML:{__html:`(${s})(${JSON.stringify(t||ae)}, ${JSON.stringify(u)})`}})}Je.displayName="ScrollRestoration";function Ke(e){return`${e} must be used within a data router. See https://reactrouter.com/en/main/routers/picking-a-router.`}function pe(e){let t=h.useContext(O);return b(t,Ke(e)),t}function sr(e){let t=h.useContext(I);return b(t,Ke(e)),t}function Ge(e,{target:t,replace:r,state:n,preventScrollReset:a,relative:o,viewTransition:i}={}){let u=Ae(),s=D(),l=j(e,{relative:o});return h.useCallback(c=>{if(Ut(c,t)){c.preventDefault();let d=r!==void 0?r:Z(s)===Z(l);u(e,{replace:d,state:n,preventScrollReset:a,relative:o,viewTransition:i})}},[s,u,l,r,n,t,e,a,o,i])}var ur=0,cr=()=>`__${String(++ur)}__`;function Xe(){let{router:e}=pe("useSubmit"),{basename:t}=h.useContext(x),r=At();return h.useCallback(async(n,a={})=>{let{action:o,method:i,encType:u,formData:s,body:l}=zt(n,t);if(a.navigate===!1){let c=a.fetcherKey||cr();await e.fetch(c,r,a.action||o,{preventScrollReset:a.preventScrollReset,formData:s,body:l,formMethod:a.method||i,formEncType:a.encType||u,flushSync:a.flushSync})}else await e.navigate(a.action||o,{preventScrollReset:a.preventScrollReset,formData:s,body:l,formMethod:a.method||i,formEncType:a.encType||u,replace:a.replace,state:a.state,fromRouteId:r,flushSync:a.flushSync,viewTransition:a.viewTransition})},[e,t,r])}function Qe(e,{relative:t}={}){let{basename:r}=h.useContext(x),n=h.useContext(T);b(n,"useFormAction must be used inside a RouteContext");let[a]=n.matches.slice(-1),o={...j(e||".",{relative:t})},i=D();if(e==null){o.search=i.search;let u=new URLSearchParams(o.search),s=u.getAll("index");if(s.some(c=>c==="")){u.delete("index"),s.filter(d=>d).forEach(d=>u.append("index",d));let c=u.toString();o.search=c?`?${c}`:""}}return(!e||e===".")&&a.route.index&&(o.search=o.search?o.search.replace(/^\?/,"?index&"):"?index"),r!=="/"&&(o.pathname=o.pathname==="/"?r:M([r,o.pathname])),Z(o)}var ae="react-router-scroll-positions",G={};function ne(e,t,r,n){let a=null;return n&&(r!=="/"?a=n({...e,pathname:N(e.pathname,r)||e.pathname},t):a=n(e,t)),a==null&&(a=e.key),a}function Ze({getKey:e,storageKey:t}={}){let{router:r}=pe("useScrollRestoration"),{restoreScrollPosition:n,preventScrollReset:a}=sr("useScrollRestoration"),{basename:o}=h.useContext(x),i=D(),u=de(),s=Oe();h.useEffect(()=>(window.history.scrollRestoration="manual",()=>{window.history.scrollRestoration="auto"}),[]),dr(h.useCallback(()=>{if(s.state==="idle"){let l=ne(i,u,o,e);G[l]=window.scrollY}try{sessionStorage.setItem(t||ae,JSON.stringify(G))}catch(l){L(!1,`Failed to save scroll positions in sessionStorage, <ScrollRestoration /> will not work properly (${l}).`)}window.history.scrollRestoration="auto"},[s.state,e,o,i,u,t])),typeof document<"u"&&(h.useLayoutEffect(()=>{try{let l=sessionStorage.getItem(t||ae);l&&(G=JSON.parse(l))}catch{}},[t]),h.useLayoutEffect(()=>{let l=r?.enableScrollRestoration(G,()=>window.scrollY,e?(c,d)=>ne(c,d,o,e):void 0);return()=>l&&l()},[r,o,e]),h.useLayoutEffect(()=>{if(n!==!1){if(typeof n=="number"){window.scrollTo(0,n);return}try{if(i.hash){let l=document.getElementById(decodeURIComponent(i.hash.slice(1)));if(l){l.scrollIntoView();return}}}catch{L(!1,`"${i.hash.slice(1)}" is not a decodable element ID. The view will not scroll to it.`)}a!==!0&&window.scrollTo(0,0)}},[i,n,a]))}function dr(e,t){let{capture:r}=t||{};h.useEffect(()=>{let n=r!=null?{capture:r}:void 0;return window.addEventListener("pagehide",e,n),()=>{window.removeEventListener("pagehide",e,n)}},[e,r])}function qe(e,{relative:t}={}){let r=h.useContext(ie);b(r!=null,"`useViewTransitionState` must be used within `react-router-dom`'s `RouterProvider`. Did you accidentally import `RouterProvider` from `react-router`?");let{basename:n}=pe("useViewTransitionState"),a=j(e,{relative:t});if(!r.isTransitioning)return!1;let o=N(r.currentLocation.pathname,n)||r.currentLocation.pathname,i=N(r.nextLocation.pathname,n)||r.nextLocation.pathname;return W(a.pathname,i)!=null||W(a.pathname,o)!=null}function fr(){return tt(),null}function tt({disabled:e=!1}={}){let{hash:t}=D(),r=Re();ve(()=>{if(e||!t)return;let n=t.replace(/^#/,""),a=[n];try{let i=window.decodeURIComponent(n);i&&i!==n&&a.push(i)}catch{}let o=0;return o=window.requestAnimationFrame(()=>{(document.getElementById(a[0]??"")??document.getElementById(a[1]??""))?.scrollIntoView({behavior:r})}),()=>{window.cancelAnimationFrame(o)}},[t,e,r])}export{fr as AutoScrollToHash,tt as useAutoScrollToHash};
|
|
4
|
-
/*! Bundled license information:
|
|
5
|
-
|
|
6
|
-
react-router/dist/development/chunk-NISHYRIK.mjs:
|
|
7
|
-
react-router/dist/development/index.mjs:
|
|
8
|
-
(**
|
|
9
|
-
* react-router v7.9.3
|
|
10
|
-
*
|
|
11
|
-
* Copyright (c) Remix Software Inc.
|
|
12
|
-
*
|
|
13
|
-
* This source code is licensed under the MIT license found in the
|
|
14
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
15
|
-
*
|
|
16
|
-
* @license MIT
|
|
17
|
-
*)
|
|
18
|
-
*/
|
|
1
|
+
import{a as s,c as a}from"./chunk-V4TWM6RF.js";import{createContext as i,useCallback as m,useContext as d,useRef as h}from"react";import{useLocation as f}from"react-router";import p from"tiny-invariant";import{jsx as S}from"react/jsx-runtime";var u=i(()=>{});function T({children:o}){let t=H();return S(u.Provider,{value:t,children:o})}function A(){let o=d(u);return p(o,"useAutoScrollToHash must be used within an AutoScrollToHash provider"),o}function H(){let{hash:o}=f(),t=a(),c=h(0),l=m(()=>{if(!o)return;let r=o.replace(/^#/,""),n=[r];try{let e=window.decodeURIComponent(r);e&&e!==r&&n.push(e)}catch{}c.current=window.requestAnimationFrame(()=>{(document.getElementById(n[0]??"")??document.getElementById(n[1]??""))?.scrollIntoView({behavior:t})})},[o,t]);return s(()=>(l(),()=>{window.cancelAnimationFrame(c.current)}),[o,t]),l}export{T as AutoScrollToHash,A as useAutoScrollToHash};
|
|
19
2
|
//# sourceMappingURL=auto-scroll-to-hash.js.map
|