@tanstack/react-router 0.0.1-beta.197 → 0.0.1-beta.199
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,7 +38,7 @@
|
|
|
38
38
|
* LICENSE.md file in the root directory of this source tree.
|
|
39
39
|
*
|
|
40
40
|
* @license MIT
|
|
41
|
-
*/const c="pushstate",h="popstate",u="beforeunload",l=t=>(t.preventDefault(),t.returnValue=""),d=()=>{removeEventListener(u,l,{capture:!0})};function p(t){let e=t.getLocation(),r=new Set,o=[],s=[];const n=()=>{e=t.getLocation(),r.forEach((t=>t()))},a=()=>{if(o.length)o[0]?.(a,(()=>{o=[],d()}));else{for(;s.length;)s.shift()?.();n()}},i=t=>{s.push(t),a()};return{get location(){return e},subscribe:t=>(r.add(t),()=>{r.delete(t)}),push:(e,r)=>{r=f(r),i((()=>{t.pushState(e,r,n)}))},replace:(e,r)=>{r=f(r),i((()=>{t.replaceState(e,r,n)}))},go:e=>{i((()=>{t.go(e)}))},back:()=>{i((()=>{t.back()}))},forward:()=>{i((()=>{t.forward()}))},createHref:e=>t.createHref(e),block:t=>(o.push(t),1===o.length&&addEventListener(u,l,{capture:!0}),()=>{o=o.filter((e=>e!==t)),o.length||d()}),flush:()=>t.flush?.(),destroy:()=>t.destroy?.(),update:n}}function f(t){return t||(t={}),t.key=w(),t}function m(t){const e=t?.getHref??(()=>`${window.location.pathname}${window.location.search}${window.location.hash}`),r=t?.createHref??(t=>t);let o=g(e(),window.history.state);let s,n,a=!0;const i=()=>{a=!1,(()=>{s&&(window.history[s.isPush?"pushState":"replaceState"](s.state,"",s.href),s=void 0,n=void 0)})(),a=!0},u=(t,e,a,c)=>{const h=r(e);o=g(h,a),s={href:h,state:a,isPush:s?.isPush||"push"===t},c(),n||(n=Promise.resolve().then((()=>i())))},l=p({getLocation:()=>o,pushState:(t,e,r)=>u("push",t,e,r),replaceState:(t,e,r)=>u("replace",t,e,r),back:()=>window.history.back(),forward:()=>window.history.forward(),go:t=>window.history.go(t),createHref:t=>r(t),flush:i,destroy:()=>{window.history.pushState=d,window.history.replaceState=f,window.removeEventListener(c,l
|
|
41
|
+
*/const c="pushstate",h="popstate",u="beforeunload",l=t=>(t.preventDefault(),t.returnValue=""),d=()=>{removeEventListener(u,l,{capture:!0})};function p(t){let e=t.getLocation(),r=new Set,o=[],s=[];const n=()=>{e=t.getLocation(),r.forEach((t=>t()))},a=()=>{if(o.length)o[0]?.(a,(()=>{o=[],d()}));else{for(;s.length;)s.shift()?.();n()}},i=t=>{s.push(t),a()};return{get location(){return e},subscribe:t=>(r.add(t),()=>{r.delete(t)}),push:(e,r)=>{r=f(r),i((()=>{t.pushState(e,r,n)}))},replace:(e,r)=>{r=f(r),i((()=>{t.replaceState(e,r,n)}))},go:e=>{i((()=>{t.go(e)}))},back:()=>{i((()=>{t.back()}))},forward:()=>{i((()=>{t.forward()}))},createHref:e=>t.createHref(e),block:t=>(o.push(t),1===o.length&&addEventListener(u,l,{capture:!0}),()=>{o=o.filter((e=>e!==t)),o.length||d()}),flush:()=>t.flush?.(),destroy:()=>t.destroy?.(),update:n}}function f(t){return t||(t={}),t.key=w(),t}function m(t){const e=t?.getHref??(()=>`${window.location.pathname}${window.location.search}${window.location.hash}`),r=t?.createHref??(t=>t);let o=g(e(),window.history.state);let s,n,a=!0;const i=()=>{a=!1,(()=>{s&&(window.history[s.isPush?"pushState":"replaceState"](s.state,"",s.href),s=void 0,n=void 0)})(),a=!0},u=(t,e,a,c)=>{const h=r(e);o=g(h,a),s={href:h,state:a,isPush:s?.isPush||"push"===t},c(),n||(n=Promise.resolve().then((()=>i())))},l=()=>{o=g(e(),window.history.state),m.update()};var d=window.history.pushState,f=window.history.replaceState;const m=p({getLocation:()=>o,pushState:(t,e,r)=>u("push",t,e,r),replaceState:(t,e,r)=>u("replace",t,e,r),back:()=>window.history.back(),forward:()=>window.history.forward(),go:t=>window.history.go(t),createHref:t=>r(t),flush:i,destroy:()=>{window.history.pushState=d,window.history.replaceState=f,window.removeEventListener(c,l),window.removeEventListener(h,l)}});return window.addEventListener(c,l),window.addEventListener(h,l),window.history.pushState=function(){let t=d.apply(window.history,arguments);return a&&m.update(),t},window.history.replaceState=function(){let t=f.apply(window.history,arguments);return a&&m.update(),t},m}function y(t={initialEntries:["/"]}){const e=t.initialEntries;let r=t.initialIndex??e.length-1,o={key:w()};return p({getLocation:()=>g(e[r],o),pushState:(t,s)=>{o=s,e.push(t),r++},replaceState:(t,s)=>{o=s,e[r]=t},back:()=>{r--},forward:()=>{r=Math.min(r+1,e.length-1)},go:t=>window.history.go(t),createHref:t=>t})}function g(t,e){let r=t.indexOf("#"),o=t.indexOf("?");return{href:t,pathname:t.substring(0,r>0?o>0?Math.min(r,o):r:o>0?o:t.length),hash:r>-1?t.substring(r):"",search:o>-1?t.slice(o,-1===r?void 0:r):"",state:e||{}}}function w(){return(Math.random()+1).toString(36).substring(7)}function v(t,e){if(!t)throw new Error("Invariant failed")}
|
|
42
42
|
/**
|
|
43
43
|
* @tanstack/router-core/src/index.ts
|
|
44
44
|
*
|