@tanstack/history
Advanced tools
Comparing version 0.0.1-beta.250 to 0.0.1-beta.251
@@ -137,5 +137,5 @@ /** | ||
const win = opts?.window ?? (typeof document !== 'undefined' ? window : undefined); | ||
const getHref = opts?.getHref ?? (() => `${win.location.pathname}${win.location.search}${win.location.hash}`); | ||
const createHref = opts?.createHref ?? (path => path); | ||
let currentLocation = parseLocation(getHref(), win.history.state); | ||
const parseLocation = opts?.parseLocation ?? (() => parseHref(`${win.location.pathname}${win.location.search}${win.location.hash}`, win.history.state)); | ||
let currentLocation = parseLocation(); | ||
let rollbackLocation; | ||
@@ -177,4 +177,5 @@ const getLocation = () => currentLocation; | ||
// This function queues up a call to update the browser history | ||
const queueHistoryAction = (type, path, state, onUpdate) => { | ||
const href = createHref(path); | ||
const queueHistoryAction = (type, destHref, state, onUpdate) => { | ||
console.log(destHref); | ||
const href = createHref(destHref); | ||
if (!scheduled) { | ||
@@ -185,3 +186,3 @@ rollbackLocation = currentLocation; | ||
// Update the location in memory | ||
currentLocation = parseLocation(href, state); | ||
currentLocation = parseHref(destHref, state); | ||
@@ -203,3 +204,3 @@ // Keep track of the next location we need to flush to the URL | ||
const onPushPop = () => { | ||
currentLocation = parseLocation(getHref(), win.history.state); | ||
currentLocation = parseLocation(); | ||
history.notify(); | ||
@@ -211,8 +212,8 @@ }; | ||
getLocation, | ||
pushState: (path, state, onUpdate) => queueHistoryAction('push', path, state, onUpdate), | ||
replaceState: (path, state, onUpdate) => queueHistoryAction('replace', path, state, onUpdate), | ||
pushState: (href, state, onUpdate) => queueHistoryAction('push', href, state, onUpdate), | ||
replaceState: (href, state, onUpdate) => queueHistoryAction('replace', href, state, onUpdate), | ||
back: () => win.history.back(), | ||
forward: () => win.history.forward(), | ||
go: n => win.history.go(n), | ||
createHref: path => createHref(path), | ||
createHref: href => createHref(href), | ||
flush, | ||
@@ -252,5 +253,9 @@ destroy: () => { | ||
return createBrowserHistory({ | ||
getHref: () => win.location.hash.substring(1), | ||
createHref: path => `#${path}`, | ||
window: win | ||
window: win, | ||
parseLocation: () => { | ||
const hashHref = win.location.hash.split('#').slice(1).join('#') ?? '/'; | ||
console.log(hashHref); | ||
return parseHref(hashHref, win.history.state); | ||
}, | ||
createHref: href => `${win.location.pathname}${win.location.search}#${href}` | ||
}); | ||
@@ -266,3 +271,3 @@ } | ||
}; | ||
const getLocation = () => parseLocation(entries[index], currentState); | ||
const getLocation = () => parseHref(entries[index], currentState); | ||
return createHistory({ | ||
@@ -291,3 +296,3 @@ getLocation, | ||
} | ||
function parseLocation(href, state) { | ||
function parseHref(href, state) { | ||
let hashIndex = href.indexOf('#'); | ||
@@ -294,0 +299,0 @@ let searchIndex = href.indexOf('?'); |
@@ -135,5 +135,5 @@ /** | ||
const win = opts?.window ?? (typeof document !== 'undefined' ? window : undefined); | ||
const getHref = opts?.getHref ?? (() => `${win.location.pathname}${win.location.search}${win.location.hash}`); | ||
const createHref = opts?.createHref ?? (path => path); | ||
let currentLocation = parseLocation(getHref(), win.history.state); | ||
const parseLocation = opts?.parseLocation ?? (() => parseHref(`${win.location.pathname}${win.location.search}${win.location.hash}`, win.history.state)); | ||
let currentLocation = parseLocation(); | ||
let rollbackLocation; | ||
@@ -175,4 +175,5 @@ const getLocation = () => currentLocation; | ||
// This function queues up a call to update the browser history | ||
const queueHistoryAction = (type, path, state, onUpdate) => { | ||
const href = createHref(path); | ||
const queueHistoryAction = (type, destHref, state, onUpdate) => { | ||
console.log(destHref); | ||
const href = createHref(destHref); | ||
if (!scheduled) { | ||
@@ -183,3 +184,3 @@ rollbackLocation = currentLocation; | ||
// Update the location in memory | ||
currentLocation = parseLocation(href, state); | ||
currentLocation = parseHref(destHref, state); | ||
@@ -201,3 +202,3 @@ // Keep track of the next location we need to flush to the URL | ||
const onPushPop = () => { | ||
currentLocation = parseLocation(getHref(), win.history.state); | ||
currentLocation = parseLocation(); | ||
history.notify(); | ||
@@ -209,8 +210,8 @@ }; | ||
getLocation, | ||
pushState: (path, state, onUpdate) => queueHistoryAction('push', path, state, onUpdate), | ||
replaceState: (path, state, onUpdate) => queueHistoryAction('replace', path, state, onUpdate), | ||
pushState: (href, state, onUpdate) => queueHistoryAction('push', href, state, onUpdate), | ||
replaceState: (href, state, onUpdate) => queueHistoryAction('replace', href, state, onUpdate), | ||
back: () => win.history.back(), | ||
forward: () => win.history.forward(), | ||
go: n => win.history.go(n), | ||
createHref: path => createHref(path), | ||
createHref: href => createHref(href), | ||
flush, | ||
@@ -250,5 +251,9 @@ destroy: () => { | ||
return createBrowserHistory({ | ||
getHref: () => win.location.hash.substring(1), | ||
createHref: path => `#${path}`, | ||
window: win | ||
window: win, | ||
parseLocation: () => { | ||
const hashHref = win.location.hash.split('#').slice(1).join('#') ?? '/'; | ||
console.log(hashHref); | ||
return parseHref(hashHref, win.history.state); | ||
}, | ||
createHref: href => `${win.location.pathname}${win.location.search}#${href}` | ||
}); | ||
@@ -264,3 +269,3 @@ } | ||
}; | ||
const getLocation = () => parseLocation(entries[index], currentState); | ||
const getLocation = () => parseHref(entries[index], currentState); | ||
return createHistory({ | ||
@@ -289,3 +294,3 @@ getLocation, | ||
} | ||
function parseLocation(href, state) { | ||
function parseHref(href, state) { | ||
let hashIndex = href.indexOf('#'); | ||
@@ -292,0 +297,0 @@ let searchIndex = href.indexOf('?'); |
@@ -11,3 +11,3 @@ { | ||
"name": "packages/history/src/index.ts", | ||
"uid": "5ac9-3" | ||
"uid": "26ef-3" | ||
} | ||
@@ -20,14 +20,14 @@ ] | ||
"nodeParts": { | ||
"5ac9-3": { | ||
"renderedLength": 9608, | ||
"gzipLength": 2778, | ||
"26ef-3": { | ||
"renderedLength": 9821, | ||
"gzipLength": 2853, | ||
"brotliLength": 0, | ||
"metaUid": "5ac9-2" | ||
"metaUid": "26ef-2" | ||
} | ||
}, | ||
"nodeMetas": { | ||
"5ac9-2": { | ||
"26ef-2": { | ||
"id": "/packages/history/src/index.ts", | ||
"moduleParts": { | ||
"index.production.js": "5ac9-3" | ||
"index.production.js": "26ef-3" | ||
}, | ||
@@ -34,0 +34,0 @@ "imported": [], |
@@ -66,3 +66,3 @@ /** | ||
declare function createBrowserHistory(opts?: { | ||
getHref?: () => string; | ||
parseLocation?: () => HistoryLocation; | ||
createHref?: (path: string) => string; | ||
@@ -69,0 +69,0 @@ window?: any; |
@@ -141,5 +141,5 @@ /** | ||
const win = opts?.window ?? (typeof document !== 'undefined' ? window : undefined); | ||
const getHref = opts?.getHref ?? (() => `${win.location.pathname}${win.location.search}${win.location.hash}`); | ||
const createHref = opts?.createHref ?? (path => path); | ||
let currentLocation = parseLocation(getHref(), win.history.state); | ||
const parseLocation = opts?.parseLocation ?? (() => parseHref(`${win.location.pathname}${win.location.search}${win.location.hash}`, win.history.state)); | ||
let currentLocation = parseLocation(); | ||
let rollbackLocation; | ||
@@ -181,4 +181,5 @@ const getLocation = () => currentLocation; | ||
// This function queues up a call to update the browser history | ||
const queueHistoryAction = (type, path, state, onUpdate) => { | ||
const href = createHref(path); | ||
const queueHistoryAction = (type, destHref, state, onUpdate) => { | ||
console.log(destHref); | ||
const href = createHref(destHref); | ||
if (!scheduled) { | ||
@@ -189,3 +190,3 @@ rollbackLocation = currentLocation; | ||
// Update the location in memory | ||
currentLocation = parseLocation(href, state); | ||
currentLocation = parseHref(destHref, state); | ||
@@ -207,3 +208,3 @@ // Keep track of the next location we need to flush to the URL | ||
const onPushPop = () => { | ||
currentLocation = parseLocation(getHref(), win.history.state); | ||
currentLocation = parseLocation(); | ||
history.notify(); | ||
@@ -215,8 +216,8 @@ }; | ||
getLocation, | ||
pushState: (path, state, onUpdate) => queueHistoryAction('push', path, state, onUpdate), | ||
replaceState: (path, state, onUpdate) => queueHistoryAction('replace', path, state, onUpdate), | ||
pushState: (href, state, onUpdate) => queueHistoryAction('push', href, state, onUpdate), | ||
replaceState: (href, state, onUpdate) => queueHistoryAction('replace', href, state, onUpdate), | ||
back: () => win.history.back(), | ||
forward: () => win.history.forward(), | ||
go: n => win.history.go(n), | ||
createHref: path => createHref(path), | ||
createHref: href => createHref(href), | ||
flush, | ||
@@ -256,5 +257,9 @@ destroy: () => { | ||
return createBrowserHistory({ | ||
getHref: () => win.location.hash.substring(1), | ||
createHref: path => `#${path}`, | ||
window: win | ||
window: win, | ||
parseLocation: () => { | ||
const hashHref = win.location.hash.split('#').slice(1).join('#') ?? '/'; | ||
console.log(hashHref); | ||
return parseHref(hashHref, win.history.state); | ||
}, | ||
createHref: href => `${win.location.pathname}${win.location.search}#${href}` | ||
}); | ||
@@ -270,3 +275,3 @@ } | ||
}; | ||
const getLocation = () => parseLocation(entries[index], currentState); | ||
const getLocation = () => parseHref(entries[index], currentState); | ||
return createHistory({ | ||
@@ -295,3 +300,3 @@ getLocation, | ||
} | ||
function parseLocation(href, state) { | ||
function parseHref(href, state) { | ||
let hashIndex = href.indexOf('#'); | ||
@@ -298,0 +303,0 @@ let searchIndex = href.indexOf('?'); |
@@ -11,3 +11,3 @@ /** | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TanStackHistory={})}(this,(function(e){"use strict";const t="pushstate",n="popstate",o="beforeunload",r=e=>(e.preventDefault(),e.returnValue=""),i=()=>{removeEventListener(o,r,{capture:!0})};function s(e){let t=e.getLocation(),n=new Set,s=[];const c=()=>{t=e.getLocation(),n.forEach((e=>e()))},h=t=>{if("undefined"!=typeof document&&s.length)for(let t of s)if(!window.confirm(t.message))return void e.onBlocked?.(c);t()};return{get location(){return t},subscribe:e=>(n.add(e),()=>{n.delete(e)}),push:(t,n)=>{n=a(n),h((()=>{e.pushState(t,n,c)}))},replace:(t,n)=>{n=a(n),h((()=>{e.replaceState(t,n,c)}))},go:t=>{h((()=>{e.go(t)}))},back:()=>{h((()=>{e.back()}))},forward:()=>{h((()=>{e.forward()}))},createHref:t=>e.createHref(t),block:e=>{const t={message:e};return s.push(t),1===s.length&&addEventListener(o,r,{capture:!0}),()=>{s=s.filter((e=>e!==t)),s.length||i()}},flush:()=>e.flush?.(),destroy:()=>e.destroy?.(),notify:c}}function a(e){return e||(e={}),{...e,key:u()}}function c(e){const o=e?.window??("undefined"!=typeof document?window:void 0),r=e?.getHref??(()=>`${o.location.pathname}${o.location.search}${o.location.hash}`),i=e?.createHref??(e=>e);let a,c=h(r(),o.history.state);let u,f,d=!0;const l=()=>{d=!1,(()=>{u&&(o.history[u.isPush?"pushState":"replaceState"](u.state,"",u.href),u=void 0,f=void 0,a=void 0)})(),d=!0},p=(e,t,n,o)=>{const r=i(t);f||(a=c),c=h(r,n),u={href:r,state:n,isPush:u?.isPush||"push"===e},o(),f||(f=Promise.resolve().then((()=>l())))},y=()=>{c=h(r(),o.history.state),v.notify()};var g=o.history.pushState,m=o.history.replaceState;const v=s({getLocation:()=>c,pushState:(e,t,n)=>p("push",e,t,n),replaceState:(e,t,n)=>p("replace",e,t,n),back:()=>o.history.back(),forward:()=>o.history.forward(),go:e=>o.history.go(e),createHref:e=>i(e),flush:l,destroy:()=>{o.history.pushState=g,o.history.replaceState=m,o.removeEventListener(t,y),o.removeEventListener(n,y)},onBlocked:e=>{a&&c!==a&&(c=a,e())}});return o.addEventListener(t,y),o.addEventListener(n,y),o.history.pushState=function(){let e=g.apply(o.history,arguments);return d&&v.notify(),e},o.history.replaceState=function(){let e=m.apply(o.history,arguments);return d&&v.notify(),e},v}function h(e,t){let n=e.indexOf("#"),o=e.indexOf("?");return{href:e,pathname:e.substring(0,n>0?o>0?Math.min(n,o):n:o>0?o:e.length),hash:n>-1?e.substring(n):"",search:o>-1?e.slice(o,-1===n?void 0:n):"",state:t||{}}}function u(){return(Math.random()+1).toString(36).substring(7)}e.createBrowserHistory=c,e.createHashHistory=function(e){const t=e?.window??("undefined"!=typeof document?window:void 0);return c({getHref:()=>t.location.hash.substring(1),createHref:e=>`#${e}`,window:t})},e.createHistory=s,e.createMemoryHistory=function(e={initialEntries:["/"]}){const t=e.initialEntries;let n=e.initialIndex??t.length-1,o={key:u()};return s({getLocation:()=>h(t[n],o),pushState:(e,r)=>{o=r,t.push(e),n++},replaceState:(e,r)=>{o=r,t[n]=e},back:()=>{n--},forward:()=>{n=Math.min(n+1,t.length-1)},go:e=>{n=Math.min(Math.max(n+e,0),t.length-1)},createHref:e=>e})}})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).TanStackHistory={})}(this,(function(e){"use strict";const t="pushstate",o="popstate",n="beforeunload",r=e=>(e.preventDefault(),e.returnValue=""),i=()=>{removeEventListener(n,r,{capture:!0})};function a(e){let t=e.getLocation(),o=new Set,a=[];const c=()=>{t=e.getLocation(),o.forEach((e=>e()))},h=t=>{if("undefined"!=typeof document&&a.length)for(let t of a)if(!window.confirm(t.message))return void e.onBlocked?.(c);t()};return{get location(){return t},subscribe:e=>(o.add(e),()=>{o.delete(e)}),push:(t,o)=>{o=s(o),h((()=>{e.pushState(t,o,c)}))},replace:(t,o)=>{o=s(o),h((()=>{e.replaceState(t,o,c)}))},go:t=>{h((()=>{e.go(t)}))},back:()=>{h((()=>{e.back()}))},forward:()=>{h((()=>{e.forward()}))},createHref:t=>e.createHref(t),block:e=>{const t={message:e};return a.push(t),1===a.length&&addEventListener(n,r,{capture:!0}),()=>{a=a.filter((e=>e!==t)),a.length||i()}},flush:()=>e.flush?.(),destroy:()=>e.destroy?.(),notify:c}}function s(e){return e||(e={}),{...e,key:u()}}function c(e){const n=e?.window??("undefined"!=typeof document?window:void 0),r=e?.createHref??(e=>e),i=e?.parseLocation??(()=>h(`${n.location.pathname}${n.location.search}${n.location.hash}`,n.history.state));let s,c=i();let u,l,f=!0;const d=()=>{f=!1,(()=>{u&&(n.history[u.isPush?"pushState":"replaceState"](u.state,"",u.href),u=void 0,l=void 0,s=void 0)})(),f=!0},p=(e,t,o,n)=>{console.log(t);const i=r(t);l||(s=c),c=h(t,o),u={href:i,state:o,isPush:u?.isPush||"push"===e},n(),l||(l=Promise.resolve().then((()=>d())))},y=()=>{c=i(),v.notify()};var g=n.history.pushState,m=n.history.replaceState;const v=a({getLocation:()=>c,pushState:(e,t,o)=>p("push",e,t,o),replaceState:(e,t,o)=>p("replace",e,t,o),back:()=>n.history.back(),forward:()=>n.history.forward(),go:e=>n.history.go(e),createHref:e=>r(e),flush:d,destroy:()=>{n.history.pushState=g,n.history.replaceState=m,n.removeEventListener(t,y),n.removeEventListener(o,y)},onBlocked:e=>{s&&c!==s&&(c=s,e())}});return n.addEventListener(t,y),n.addEventListener(o,y),n.history.pushState=function(){let e=g.apply(n.history,arguments);return f&&v.notify(),e},n.history.replaceState=function(){let e=m.apply(n.history,arguments);return f&&v.notify(),e},v}function h(e,t){let o=e.indexOf("#"),n=e.indexOf("?");return{href:e,pathname:e.substring(0,o>0?n>0?Math.min(o,n):o:n>0?n:e.length),hash:o>-1?e.substring(o):"",search:n>-1?e.slice(n,-1===o?void 0:o):"",state:t||{}}}function u(){return(Math.random()+1).toString(36).substring(7)}e.createBrowserHistory=c,e.createHashHistory=function(e){const t=e?.window??("undefined"!=typeof document?window:void 0);return c({window:t,parseLocation:()=>{const e=t.location.hash.split("#").slice(1).join("#")??"/";return console.log(e),h(e,t.history.state)},createHref:e=>`${t.location.pathname}${t.location.search}#${e}`})},e.createHistory=a,e.createMemoryHistory=function(e={initialEntries:["/"]}){const t=e.initialEntries;let o=e.initialIndex??t.length-1,n={key:u()};return a({getLocation:()=>h(t[o],n),pushState:(e,r)=>{n=r,t.push(e),o++},replaceState:(e,r)=>{n=r,t[o]=e},back:()=>{o--},forward:()=>{o=Math.min(o+1,t.length-1)},go:e=>{o=Math.min(Math.max(o+e,0),t.length-1)},createHref:e=>e})}})); | ||
//# sourceMappingURL=index.production.js.map |
{ | ||
"name": "@tanstack/history", | ||
"author": "Tanner Linsley", | ||
"version": "0.0.1-beta.250", | ||
"version": "0.0.1-beta.251", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "repository": "tanstack/history", |
@@ -182,3 +182,3 @@ // While the public API was clearly inspired by the "history" npm package, | ||
export function createBrowserHistory(opts?: { | ||
getHref?: () => string | ||
parseLocation?: () => HistoryLocation | ||
createHref?: (path: string) => string | ||
@@ -191,9 +191,12 @@ window?: any | ||
const getHref = | ||
opts?.getHref ?? | ||
(() => `${win.location.pathname}${win.location.search}${win.location.hash}`) | ||
const createHref = opts?.createHref ?? ((path) => path) | ||
const parseLocation = | ||
opts?.parseLocation ?? | ||
(() => | ||
parseHref( | ||
`${win.location.pathname}${win.location.search}${win.location.hash}`, | ||
win.history.state, | ||
)) | ||
let currentLocation = parseLocation(getHref(), win.history.state) | ||
let currentLocation = parseLocation() | ||
let rollbackLocation: HistoryLocation | undefined | ||
@@ -252,7 +255,8 @@ | ||
type: 'push' | 'replace', | ||
path: string, | ||
destHref: string, | ||
state: any, | ||
onUpdate: () => void, | ||
) => { | ||
const href = createHref(path) | ||
console.log(destHref) | ||
const href = createHref(destHref) | ||
@@ -264,3 +268,3 @@ if (!scheduled) { | ||
// Update the location in memory | ||
currentLocation = parseLocation(href, state) | ||
currentLocation = parseHref(destHref, state) | ||
@@ -284,3 +288,3 @@ // Keep track of the next location we need to flush to the URL | ||
const onPushPop = () => { | ||
currentLocation = parseLocation(getHref(), win.history.state) | ||
currentLocation = parseLocation() | ||
history.notify() | ||
@@ -294,10 +298,10 @@ } | ||
getLocation, | ||
pushState: (path, state, onUpdate) => | ||
queueHistoryAction('push', path, state, onUpdate), | ||
replaceState: (path, state, onUpdate) => | ||
queueHistoryAction('replace', path, state, onUpdate), | ||
pushState: (href, state, onUpdate) => | ||
queueHistoryAction('push', href, state, onUpdate), | ||
replaceState: (href, state, onUpdate) => | ||
queueHistoryAction('replace', href, state, onUpdate), | ||
back: () => win.history.back(), | ||
forward: () => win.history.forward(), | ||
go: (n) => win.history.go(n), | ||
createHref: (path) => createHref(path), | ||
createHref: (href) => createHref(href), | ||
flush, | ||
@@ -344,5 +348,10 @@ destroy: () => { | ||
return createBrowserHistory({ | ||
getHref: () => win.location.hash.substring(1), | ||
createHref: (path) => `#${path}`, | ||
window: win, | ||
parseLocation: () => { | ||
const hashHref = win.location.hash.split('#').slice(1).join('#') ?? '/' | ||
console.log(hashHref) | ||
return parseHref(hashHref, win.history.state) | ||
}, | ||
createHref: (href) => | ||
`${win.location.pathname}${win.location.search}#${href}`, | ||
}) | ||
@@ -365,3 +374,3 @@ } | ||
const getLocation = () => parseLocation(entries[index]!, currentState) | ||
const getLocation = () => parseHref(entries[index]!, currentState) | ||
@@ -392,3 +401,3 @@ return createHistory({ | ||
function parseLocation(href: string, state: HistoryState): HistoryLocation { | ||
function parseHref(href: string, state: HistoryState): HistoryLocation { | ||
let hashIndex = href.indexOf('#') | ||
@@ -395,0 +404,0 @@ let searchIndex = href.indexOf('?') |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
291658
1410