@tanstack/history 0.0.1-beta.211 → 0.0.1-beta.213

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.
@@ -115,8 +115,10 @@ function assignKey(state) {
115
115
  if (!state) {
116
116
  state = {};
117
117
  }
118
- state.key = createRandomKey();
119
- return state;
118
+ return {
119
+ ...state,
120
+ key: createRandomKey()
121
+ };
120
122
  }
121
123
 
122
124
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["// While the public API was clearly inspired by the \"history\" npm package,\n// This implementation attempts to be more lightweight by\n// making assumptions about the way TanStack Router works\n\nexport interface RouterHistory {\n location: HistoryLocation\n subscribe: (cb: () => void) => () => void\n push: (path: string, state?: any) => void\n replace: (path: string, state?: any) => void\n go: (index: number) => void\n back: () => void\n forward: () => void\n createHref: (href: string) => string\n block: (blockerFn: BlockerFn) => () => void\n flush: () => void\n destroy: () => void\n notify: () => void\n}\n\nexport interface HistoryLocation extends ParsedPath {\n state: HistoryState\n}\n\nexport interface ParsedPath {\n href: string\n pathname: string\n search: string\n hash: string\n}\n\nexport interface HistoryState {\n key: string\n}\n\ntype BlockerFn = (retry: () => void, cancel: () => void) => void\n\nconst pushStateEvent = 'pushstate'\nconst popStateEvent = 'popstate'\nconst beforeUnloadEvent = 'beforeunload'\n\nconst beforeUnloadListener = (event: Event) => {\n event.preventDefault()\n // @ts-ignore\n return (event.returnValue = '')\n}\n\nconst stopBlocking = () => {\n removeEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n}\n\nfunction createHistory(opts: {\n getLocation: () => HistoryLocation\n pushState: (path: string, state: any, onUpdate: () => void) => void\n replaceState: (path: string, state: any, onUpdate: () => void) => void\n go: (n: number) => void\n back: () => void\n forward: () => void\n createHref: (path: string) => string\n flush?: () => void\n destroy?: () => void\n}): RouterHistory {\n let location = opts.getLocation()\n let subscribers = new Set<() => void>()\n let blockers: BlockerFn[] = []\n let queue: (() => void)[] = []\n\n const onUpdate = () => {\n location = opts.getLocation()\n subscribers.forEach((subscriber) => subscriber())\n }\n\n const tryUnblock = () => {\n if (blockers.length) {\n blockers[0]?.(tryUnblock, () => {\n blockers = []\n stopBlocking()\n })\n return\n }\n\n while (queue.length) {\n queue.shift()?.()\n }\n }\n\n const queueTask = (task: () => void) => {\n queue.push(task)\n tryUnblock()\n }\n\n return {\n get location() {\n return location\n },\n subscribe: (cb: () => void) => {\n subscribers.add(cb)\n\n return () => {\n subscribers.delete(cb)\n }\n },\n push: (path: string, state: any) => {\n state = assignKey(state)\n queueTask(() => {\n opts.pushState(path, state, onUpdate)\n })\n },\n replace: (path: string, state: any) => {\n state = assignKey(state)\n queueTask(() => {\n opts.replaceState(path, state, onUpdate)\n })\n },\n go: (index) => {\n queueTask(() => {\n opts.go(index)\n })\n },\n back: () => {\n queueTask(() => {\n opts.back()\n })\n },\n forward: () => {\n queueTask(() => {\n opts.forward()\n })\n },\n createHref: (str) => opts.createHref(str),\n block: (cb) => {\n blockers.push(cb)\n\n if (blockers.length === 1) {\n addEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n }\n\n return () => {\n blockers = blockers.filter((b) => b !== cb)\n\n if (!blockers.length) {\n stopBlocking()\n }\n }\n },\n flush: () => opts.flush?.(),\n destroy: () => opts.destroy?.(),\n notify: onUpdate,\n }\n}\n\nfunction assignKey(state: HistoryState) {\n if (!state) {\n state = {} as HistoryState\n }\n state.key = createRandomKey()\n return state\n}\n\n/**\n * Creates a history object that can be used to interact with the browser's\n * navigation. This is a lightweight API wrapping the browser's native methods.\n * It is designed to work with TanStack Router, but could be used as a standalone API as well.\n * IMPORTANT: This API implements history throttling via a microtask to prevent\n * excessive calls to the history API. In some browsers, calling history.pushState or\n * history.replaceState in quick succession can cause the browser to ignore subsequent\n * calls. This API smooths out those differences and ensures that your application\n * state will *eventually* match the browser state. In most cases, this is not a problem,\n * but if you need to ensure that the browser state is up to date, you can use the\n * `history.flush` method to immediately flush all pending state changes to the browser URL.\n * @param opts\n * @param opts.getHref A function that returns the current href (path + search + hash)\n * @param opts.createHref A function that takes a path and returns a href (path + search + hash)\n * @returns A history instance\n */\nexport function createBrowserHistory(opts?: {\n getHref?: () => string\n createHref?: (path: string) => string\n}): RouterHistory {\n const getHref =\n opts?.getHref ??\n (() =>\n `${window.location.pathname}${window.location.search}${window.location.hash}`)\n\n const createHref = opts?.createHref ?? ((path) => path)\n\n let currentLocation = parseLocation(getHref(), window.history.state)\n\n const getLocation = () => currentLocation\n\n let next:\n | undefined\n | {\n // This is the latest location that we were attempting to push/replace\n href: string\n // This is the latest state that we were attempting to push/replace\n state: any\n // This is the latest type that we were attempting to push/replace\n isPush: boolean\n }\n\n // Because we are proactively updating the location\n // in memory before actually updating the browser history,\n // we need to track when we are doing this so we don't\n // notify subscribers twice on the last update.\n let tracking = true\n\n // We need to track the current scheduled update to prevent\n // multiple updates from being scheduled at the same time.\n let scheduled: Promise<void> | undefined\n\n // This function is a wrapper to prevent any of the callback's\n // side effects from causing a subscriber notification\n const untrack = (fn: () => void) => {\n tracking = false\n fn()\n tracking = true\n }\n\n // This function flushes the next update to the browser history\n const flush = () => {\n // Do not notify subscribers about this push/replace call\n untrack(() => {\n if (!next) return\n window.history[next.isPush ? 'pushState' : 'replaceState'](\n next.state,\n '',\n next.href,\n )\n // Reset the nextIsPush flag and clear the scheduled update\n next = undefined\n scheduled = undefined\n })\n }\n\n // This function queues up a call to update the browser history\n const queueHistoryAction = (\n type: 'push' | 'replace',\n path: string,\n state: any,\n onUpdate: () => void,\n ) => {\n const href = createHref(path)\n\n // Update the location in memory\n currentLocation = parseLocation(href, state)\n\n // Keep track of the next location we need to flush to the URL\n next = {\n href,\n state,\n isPush: next?.isPush || type === 'push',\n }\n // Notify subscribers\n onUpdate()\n\n if (!scheduled) {\n // Schedule an update to the browser history\n scheduled = Promise.resolve().then(() => flush())\n }\n }\n\n const onPushPop = () => {\n currentLocation = parseLocation(getHref(), window.history.state)\n history.notify()\n }\n\n var originalPushState = window.history.pushState\n var originalReplaceState = window.history.replaceState\n\n const history = createHistory({\n getLocation,\n pushState: (path, state, onUpdate) =>\n queueHistoryAction('push', path, state, onUpdate),\n replaceState: (path, state, onUpdate) =>\n queueHistoryAction('replace', path, state, onUpdate),\n back: () => window.history.back(),\n forward: () => window.history.forward(),\n go: (n) => window.history.go(n),\n createHref: (path) => createHref(path),\n flush,\n destroy: () => {\n window.history.pushState = originalPushState\n window.history.replaceState = originalReplaceState\n window.removeEventListener(pushStateEvent, onPushPop)\n window.removeEventListener(popStateEvent, onPushPop)\n },\n })\n\n window.addEventListener(pushStateEvent, onPushPop)\n window.addEventListener(popStateEvent, onPushPop)\n\n window.history.pushState = function () {\n let res = originalPushState.apply(window.history, arguments as any)\n if (tracking) history.notify()\n return res\n }\n\n window.history.replaceState = function () {\n let res = originalReplaceState.apply(window.history, arguments as any)\n if (tracking) history.notify()\n return res\n }\n\n return history\n}\n\nexport function createHashHistory(): RouterHistory {\n return createBrowserHistory({\n getHref: () => window.location.hash.substring(1),\n createHref: (path) => `#${path}`,\n })\n}\n\nexport function createMemoryHistory(\n opts: {\n initialEntries: string[]\n initialIndex?: number\n } = {\n initialEntries: ['/'],\n },\n): RouterHistory {\n const entries = opts.initialEntries\n let index = opts.initialIndex ?? entries.length - 1\n let currentState = {\n key: createRandomKey(),\n } as HistoryState\n\n const getLocation = () => parseLocation(entries[index]!, currentState)\n\n return createHistory({\n getLocation,\n pushState: (path, state) => {\n currentState = state\n entries.push(path)\n index++\n },\n replaceState: (path, state) => {\n currentState = state\n entries[index] = path\n },\n back: () => {\n index--\n },\n forward: () => {\n index = Math.min(index + 1, entries.length - 1)\n },\n go: (n) => window.history.go(n),\n createHref: (path) => path,\n })\n}\n\nfunction parseLocation(href: string, state: HistoryState): HistoryLocation {\n let hashIndex = href.indexOf('#')\n let searchIndex = href.indexOf('?')\n\n return {\n href,\n pathname: href.substring(\n 0,\n hashIndex > 0\n ? searchIndex > 0\n ? Math.min(hashIndex, searchIndex)\n : hashIndex\n : searchIndex > 0\n ? searchIndex\n : href.length,\n ),\n hash: hashIndex > -1 ? href.substring(hashIndex) : '',\n search:\n searchIndex > -1\n ? href.slice(searchIndex, hashIndex === -1 ? undefined : hashIndex)\n : '',\n state: state || {},\n }\n}\n\n// Thanks co-pilot!\nfunction createRandomKey() {\n return (Math.random() + 1).toString(36).substring(7)\n}\n"],"names":["pushStateEvent","popStateEvent","beforeUnloadEvent","beforeUnloadListener","event","preventDefault","returnValue","stopBlocking","removeEventListener","capture","createHistory","opts","location","getLocation","subscribers","Set","blockers","queue","onUpdate","forEach","subscriber","tryUnblock","length","shift","queueTask","task","push","subscribe","cb","add","delete","path","state","assignKey","pushState","replace","replaceState","go","index","back","forward","createHref","str","block","addEventListener","filter","b","flush","destroy","notify","key","createRandomKey","createBrowserHistory","getHref","window","pathname","search","hash","currentLocation","parseLocation","history","next","tracking","scheduled","untrack","fn","isPush","href","undefined","queueHistoryAction","type","Promise","resolve","then","onPushPop","originalPushState","originalReplaceState","n","res","apply","arguments","createHashHistory","substring","createMemoryHistory","initialEntries","entries","initialIndex","currentState","Math","min","hashIndex","indexOf","searchIndex","slice","random","toString"],"mappings":";;;;;;;;;;;;;;AAAA;AACA;AACA;;AAkCA,MAAMA,cAAc,GAAG,WAAW,CAAA;AAClC,MAAMC,aAAa,GAAG,UAAU,CAAA;AAChC,MAAMC,iBAAiB,GAAG,cAAc,CAAA;AAExC,MAAMC,oBAAoB,GAAIC,KAAY,IAAK;EAC7CA,KAAK,CAACC,cAAc,EAAE,CAAA;AACtB;AACA,EAAA,OAAQD,KAAK,CAACE,WAAW,GAAG,EAAE,CAAA;AAChC,CAAC,CAAA;AAED,MAAMC,YAAY,GAAGA,MAAM;AACzBC,EAAAA,mBAAmB,CAACN,iBAAiB,EAAEC,oBAAoB,EAAE;AAC3DM,IAAAA,OAAO,EAAE,IAAA;AACX,GAAC,CAAC,CAAA;AACJ,CAAC,CAA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AS,GAAGvB,IAAI,CAACwB,OAAO,CAAC,GAAG,CAAC,CAAA;AACjC,EAAA,IAAIC,WAAW,GAAGzB,IAAI,CAACwB,OAAO,CAAC,GAAG,CAAC,CAAA;EAEnC,OAAO;IACLxB,IAAI;AACJZ,IAAAA,QAAQ,EAAEY,IAAI,CAACe,SAAS,CACtB,CAAC,EACDQ,SAAS,GAAG,CAAC,GACTE,WAAW,GAAG,CAAC,GACbJ,IAAI,CAACC,GAAG,CAACC,SAAS,EAAEE,WAAW,CAAC,GAChCF,SAAS,GACXE,WAAW,GAAG,CAAC,GACfA,WAAW,GACXzB,IAAI,CAAC7C,MACX,CAAC;AACDmC,IAAAA,IAAI,EAAEiC,SAAS,GAAG,CAAC,CAAC,GAAGvB,IAAI,CAACe,SAAS,CAACQ,SAAS,CAAC,GAAG,EAAE;IACrDlC,MAAM,EACJoC,WAAW,GAAG,CAAC,CAAC,GACZzB,IAAI,CAAC0B,KAAK,CAACD,WAAW,EAAEF,SAAS,KAAK,CAAC,CAAC,GAAGtB,SAAS,GAAGsB,SAAS,CAAC,GACjE,EAAE;IACR1D,KAAK,EAAEA,KAAK,IAAI,EAAC;GAClB,CAAA;AACH,CAAA;;AAEA;AACA,SAASmB,eAAeA,GAAG;AACzB,EAAA,OAAO,CAACqC,IAAI,CAACM,MAAM,EAAE,GAAG,CAAC,EAAEC,QAAQ,CAAC,EAAE,CAAC,CAACb,SAAS,CAAC,CAAC,CAAC,CAAA;AACtD;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["// While the public API was clearly inspired by the \"history\" npm package,\n// This implementation attempts to be more lightweight by\n// making assumptions about the way TanStack Router works\n\nexport interface RouterHistory {\n location: HistoryLocation\n subscribe: (cb: () => void) => () => void\n push: (path: string, state?: any) => void\n replace: (path: string, state?: any) => void\n go: (index: number) => void\n back: () => void\n forward: () => void\n createHref: (href: string) => string\n block: (blockerFn: BlockerFn) => () => void\n flush: () => void\n destroy: () => void\n notify: () => void\n}\n\nexport interface HistoryLocation extends ParsedPath {\n state: HistoryState\n}\n\nexport interface ParsedPath {\n href: string\n pathname: string\n search: string\n hash: string\n}\n\nexport interface HistoryState {\n key: string\n}\n\ntype BlockerFn = (retry: () => void, cancel: () => void) => void\n\nconst pushStateEvent = 'pushstate'\nconst popStateEvent = 'popstate'\nconst beforeUnloadEvent = 'beforeunload'\n\nconst beforeUnloadListener = (event: Event) => {\n event.preventDefault()\n // @ts-ignore\n return (event.returnValue = '')\n}\n\nconst stopBlocking = () => {\n removeEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n}\n\nfunction createHistory(opts: {\n getLocation: () => HistoryLocation\n pushState: (path: string, state: any, onUpdate: () => void) => void\n replaceState: (path: string, state: any, onUpdate: () => void) => void\n go: (n: number) => void\n back: () => void\n forward: () => void\n createHref: (path: string) => string\n flush?: () => void\n destroy?: () => void\n}): RouterHistory {\n let location = opts.getLocation()\n let subscribers = new Set<() => void>()\n let blockers: BlockerFn[] = []\n let queue: (() => void)[] = []\n\n const onUpdate = () => {\n location = opts.getLocation()\n subscribers.forEach((subscriber) => subscriber())\n }\n\n const tryUnblock = () => {\n if (blockers.length) {\n blockers[0]?.(tryUnblock, () => {\n blockers = []\n stopBlocking()\n })\n return\n }\n\n while (queue.length) {\n queue.shift()?.()\n }\n }\n\n const queueTask = (task: () => void) => {\n queue.push(task)\n tryUnblock()\n }\n\n return {\n get location() {\n return location\n },\n subscribe: (cb: () => void) => {\n subscribers.add(cb)\n\n return () => {\n subscribers.delete(cb)\n }\n },\n push: (path: string, state: any) => {\n state = assignKey(state)\n queueTask(() => {\n opts.pushState(path, state, onUpdate)\n })\n },\n replace: (path: string, state: any) => {\n state = assignKey(state)\n queueTask(() => {\n opts.replaceState(path, state, onUpdate)\n })\n },\n go: (index) => {\n queueTask(() => {\n opts.go(index)\n })\n },\n back: () => {\n queueTask(() => {\n opts.back()\n })\n },\n forward: () => {\n queueTask(() => {\n opts.forward()\n })\n },\n createHref: (str) => opts.createHref(str),\n block: (cb) => {\n blockers.push(cb)\n\n if (blockers.length === 1) {\n addEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n }\n\n return () => {\n blockers = blockers.filter((b) => b !== cb)\n\n if (!blockers.length) {\n stopBlocking()\n }\n }\n },\n flush: () => opts.flush?.(),\n destroy: () => opts.destroy?.(),\n notify: onUpdate,\n }\n}\n\nfunction assignKey(state: HistoryState) {\n if (!state) {\n state = {} as HistoryState\n }\n return {\n ...state,\n key: createRandomKey(),\n }\n}\n\n/**\n * Creates a history object that can be used to interact with the browser's\n * navigation. This is a lightweight API wrapping the browser's native methods.\n * It is designed to work with TanStack Router, but could be used as a standalone API as well.\n * IMPORTANT: This API implements history throttling via a microtask to prevent\n * excessive calls to the history API. In some browsers, calling history.pushState or\n * history.replaceState in quick succession can cause the browser to ignore subsequent\n * calls. This API smooths out those differences and ensures that your application\n * state will *eventually* match the browser state. In most cases, this is not a problem,\n * but if you need to ensure that the browser state is up to date, you can use the\n * `history.flush` method to immediately flush all pending state changes to the browser URL.\n * @param opts\n * @param opts.getHref A function that returns the current href (path + search + hash)\n * @param opts.createHref A function that takes a path and returns a href (path + search + hash)\n * @returns A history instance\n */\nexport function createBrowserHistory(opts?: {\n getHref?: () => string\n createHref?: (path: string) => string\n}): RouterHistory {\n const getHref =\n opts?.getHref ??\n (() =>\n `${window.location.pathname}${window.location.search}${window.location.hash}`)\n\n const createHref = opts?.createHref ?? ((path) => path)\n\n let currentLocation = parseLocation(getHref(), window.history.state)\n\n const getLocation = () => currentLocation\n\n let next:\n | undefined\n | {\n // This is the latest location that we were attempting to push/replace\n href: string\n // This is the latest state that we were attempting to push/replace\n state: any\n // This is the latest type that we were attempting to push/replace\n isPush: boolean\n }\n\n // Because we are proactively updating the location\n // in memory before actually updating the browser history,\n // we need to track when we are doing this so we don't\n // notify subscribers twice on the last update.\n let tracking = true\n\n // We need to track the current scheduled update to prevent\n // multiple updates from being scheduled at the same time.\n let scheduled: Promise<void> | undefined\n\n // This function is a wrapper to prevent any of the callback's\n // side effects from causing a subscriber notification\n const untrack = (fn: () => void) => {\n tracking = false\n fn()\n tracking = true\n }\n\n // This function flushes the next update to the browser history\n const flush = () => {\n // Do not notify subscribers about this push/replace call\n untrack(() => {\n if (!next) return\n window.history[next.isPush ? 'pushState' : 'replaceState'](\n next.state,\n '',\n next.href,\n )\n // Reset the nextIsPush flag and clear the scheduled update\n next = undefined\n scheduled = undefined\n })\n }\n\n // This function queues up a call to update the browser history\n const queueHistoryAction = (\n type: 'push' | 'replace',\n path: string,\n state: any,\n onUpdate: () => void,\n ) => {\n const href = createHref(path)\n\n // Update the location in memory\n currentLocation = parseLocation(href, state)\n\n // Keep track of the next location we need to flush to the URL\n next = {\n href,\n state,\n isPush: next?.isPush || type === 'push',\n }\n // Notify subscribers\n onUpdate()\n\n if (!scheduled) {\n // Schedule an update to the browser history\n scheduled = Promise.resolve().then(() => flush())\n }\n }\n\n const onPushPop = () => {\n currentLocation = parseLocation(getHref(), window.history.state)\n history.notify()\n }\n\n var originalPushState = window.history.pushState\n var originalReplaceState = window.history.replaceState\n\n const history = createHistory({\n getLocation,\n pushState: (path, state, onUpdate) =>\n queueHistoryAction('push', path, state, onUpdate),\n replaceState: (path, state, onUpdate) =>\n queueHistoryAction('replace', path, state, onUpdate),\n back: () => window.history.back(),\n forward: () => window.history.forward(),\n go: (n) => window.history.go(n),\n createHref: (path) => createHref(path),\n flush,\n destroy: () => {\n window.history.pushState = originalPushState\n window.history.replaceState = originalReplaceState\n window.removeEventListener(pushStateEvent, onPushPop)\n window.removeEventListener(popStateEvent, onPushPop)\n },\n })\n\n window.addEventListener(pushStateEvent, onPushPop)\n window.addEventListener(popStateEvent, onPushPop)\n\n window.history.pushState = function () {\n let res = originalPushState.apply(window.history, arguments as any)\n if (tracking) history.notify()\n return res\n }\n\n window.history.replaceState = function () {\n let res = originalReplaceState.apply(window.history, arguments as any)\n if (tracking) history.notify()\n return res\n }\n\n return history\n}\n\nexport function createHashHistory(): RouterHistory {\n return createBrowserHistory({\n getHref: () => window.location.hash.substring(1),\n createHref: (path) => `#${path}`,\n })\n}\n\nexport function createMemoryHistory(\n opts: {\n initialEntries: string[]\n initialIndex?: number\n } = {\n initialEntries: ['/'],\n },\n): RouterHistory {\n const entries = opts.initialEntries\n let index = opts.initialIndex ?? entries.length - 1\n let currentState = {\n key: createRandomKey(),\n } as HistoryState\n\n const getLocation = () => parseLocation(entries[index]!, currentState)\n\n return createHistory({\n getLocation,\n pushState: (path, state) => {\n currentState = state\n entries.push(path)\n index++\n },\n replaceState: (path, state) => {\n currentState = state\n entries[index] = path\n },\n back: () => {\n index--\n },\n forward: () => {\n index = Math.min(index + 1, entries.length - 1)\n },\n go: (n) => window.history.go(n),\n createHref: (path) => path,\n })\n}\n\nfunction parseLocation(href: string, state: HistoryState): HistoryLocation {\n let hashIndex = href.indexOf('#')\n let searchIndex = href.indexOf('?')\n\n return {\n href,\n pathname: href.substring(\n 0,\n hashIndex > 0\n ? searchIndex > 0\n ? Math.min(hashIndex, searchIndex)\n : hashIndex\n : searchIndex > 0\n ? searchIndex\n : href.length,\n ),\n hash: hashIndex > -1 ? href.substring(hashIndex) : '',\n search:\n searchIndex > -1\n ? href.slice(searchIndex, hashIndex === -1 ? undefined : hashIndex)\n : '',\n state: state || {},\n }\n}\n\n// Thanks co-pilot!\nfunction createRandomKey() {\n return (Math.random() + 1).toString(36).substring(7)\n}\n"],"names":["pushStateEvent","popStateEvent","beforeUnloadEvent","beforeUnloadListener","event","preventDefault","returnValue","stopBlocking","removeEventListener","capture","createHistory","opts","location","getLocation","subscribers","Set","blockers","queue","onUpdate","forEach","subscriber","tryUnblock","length","shift","queueTask","task","push","subscribe","cb","add","delete","path","state","assignKey","pushState","replace","replaceState","go","index","back","forward","createHref","str","block","addEventListener","filter","b","flush","destroy","notify","key","createRandomKey","createBrowserHistory","getHref","window","pathname","search","hash","currentLocation","parseLocation","history","next","tracking","scheduled","untrack","fn","isPush","href","undefined","queueHistoryAction","type","Promise","resolve","then","onPushPop","originalPushState","originalReplaceState","n","res","apply","arguments","createHashHistory","substring","createMemoryHistory","initialEntries","entries","initialIndex","currentState","Math","min","hashIndex","indexOf","searchIndex","slice","random","toString"],"mappings":";;;;;;;;;;;;;;AAAA;AACA;AACA;;AAkCA,MAAMA,cAAc,GAAG,WAAW,CAAA;AAClC,MAAMC,aAAa,GAAG,UAAU,CAAA;AAChC,MAAMC,iBAAiB,GAAG,cAAc,CAAA;AAExC,MAAMC,oBAAoB,GAAIC,KAAY,IAAK;EAC7CA,KAAK,CAACC,cAAc,EAAE,CAAA;AACtB;AACA,EAAA,OAAQD,KAAK,CAACE,WAAW,GAAG,EAAE,CAAA;AAChC,CAAC,CAAA;AAED,MAAMC,YAAY,GAAGA,MAAM;AACzBC,EAAAA,mBAAmB,CAACN,iBAAiB,EAAEC,oBAAoB,EAAE;AAC3DM,IAAAA,OAAO,EAAE,IAAA;AACX,GAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,SAASC,aAAaA,CAACC,IAUtB,EAAiB;AAChB,EAAA,IAAIC,QAAQ,GAAGD,IAAI,CAACE,WAAW,EAAE,CAAA;AACjC,EAAA,IAAIC,WAAW,GAAG,IAAIC,GAAG,EAAc,CAAA;EACvC,IAAIC,QAAqB,GAAG,EAAE,CAAA;EAC9B,IAAIC,KAAqB,GAAG,EAAE,CAAA;EAE9B,MAAMC,QAAQ,GAAGA,MAAM;AACrBN,IAAAA,QAAQ,GAAGD,IAAI,CAACE,WAAW,EAAE,CAAA;IAC7BC,WAAW,CAACK,OAAO,CAAEC,UAAU,IAAKA,UAAU,EAAE,CAAC,CAAA;GAClD,CAAA;EAED,MAAMC,UAAU,GAAGA,MAAM;IACvB,IAAIL,QAAQ,CAACM,MAAM,EAAE;AACnBN,MAAAA,QAAQ,CAAC,CAAC,CAAC,GAAGK,UAAU,EAAE,MAAM;AAC9BL,QAAAA,QAAQ,GAAG,EAAE,CAAA;AACbT,Q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S,KAAK,CAAC,CAAC,GAAGtB,SAAS,GAAGsB,SAAS,CAAC,GACjE,EAAE;IACR1D,KAAK,EAAEA,KAAK,IAAI,EAAC;GAClB,CAAA;AACH,CAAA;;AAEA;AACA,SAASmB,eAAeA,GAAG;AACzB,EAAA,OAAO,CAACqC,IAAI,CAACM,MAAM,EAAE,GAAG,CAAC,EAAEC,QAAQ,CAAC,EAAE,CAAC,CAACb,SAAS,CAAC,CAAC,CAAC,CAAA;AACtD;;;;;;"}
@@ -111,8 +111,10 @@ function assignKey(state) {
111
111
  if (!state) {
112
112
  state = {};
113
113
  }
114
- state.key = createRandomKey();
115
- return state;
114
+ return {
115
+ ...state,
116
+ key: createRandomKey()
117
+ };
116
118
  }
117
119
 
118
120
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["// While the public API was clearly inspired by the \"history\" npm package,\n// This implementation attempts to be more lightweight by\n// making assumptions about the way TanStack Router works\n\nexport interface RouterHistory {\n location: HistoryLocation\n subscribe: (cb: () => void) => () => void\n push: (path: string, state?: any) => void\n replace: (path: string, state?: any) => void\n go: (index: number) => void\n back: () => void\n forward: () => void\n createHref: (href: string) => string\n block: (blockerFn: BlockerFn) => () => void\n flush: () => void\n destroy: () => void\n notify: () => void\n}\n\nexport interface HistoryLocation extends ParsedPath {\n state: HistoryState\n}\n\nexport interface ParsedPath {\n href: string\n pathname: string\n search: string\n hash: string\n}\n\nexport interface HistoryState {\n key: string\n}\n\ntype BlockerFn = (retry: () => void, cancel: () => void) => void\n\nconst pushStateEvent = 'pushstate'\nconst popStateEvent = 'popstate'\nconst beforeUnloadEvent = 'beforeunload'\n\nconst beforeUnloadListener = (event: Event) => {\n event.preventDefault()\n // @ts-ignore\n return (event.returnValue = '')\n}\n\nconst stopBlocking = () => {\n removeEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n}\n\nfunction createHistory(opts: {\n getLocation: () => HistoryLocation\n pushState: (path: string, state: any, onUpdate: () => void) => void\n replaceState: (path: string, state: any, onUpdate: () => void) => void\n go: (n: number) => void\n back: () => void\n forward: () => void\n createHref: (path: string) => string\n flush?: () => void\n destroy?: () => void\n}): RouterHistory {\n let location = opts.getLocation()\n let subscribers = new Set<() => void>()\n let blockers: BlockerFn[] = []\n let queue: (() => void)[] = []\n\n const onUpdate = () => {\n location = opts.getLocation()\n subscribers.forEach((subscriber) => subscriber())\n }\n\n const tryUnblock = () => {\n if (blockers.length) {\n blockers[0]?.(tryUnblock, () => {\n blockers = []\n stopBlocking()\n })\n return\n }\n\n while (queue.length) {\n queue.shift()?.()\n }\n }\n\n const queueTask = (task: () => void) => {\n queue.push(task)\n tryUnblock()\n }\n\n return {\n get location() {\n return location\n },\n subscribe: (cb: () => void) => {\n subscribers.add(cb)\n\n return () => {\n subscribers.delete(cb)\n }\n },\n push: (path: string, state: any) => {\n state = assignKey(state)\n queueTask(() => {\n opts.pushState(path, state, onUpdate)\n })\n },\n replace: (path: string, state: any) => {\n state = assignKey(state)\n queueTask(() => {\n opts.replaceState(path, state, onUpdate)\n })\n },\n go: (index) => {\n queueTask(() => {\n opts.go(index)\n })\n },\n back: () => {\n queueTask(() => {\n opts.back()\n })\n },\n forward: () => {\n queueTask(() => {\n opts.forward()\n })\n },\n createHref: (str) => opts.createHref(str),\n block: (cb) => {\n blockers.push(cb)\n\n if (blockers.length === 1) {\n addEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n }\n\n return () => {\n blockers = blockers.filter((b) => b !== cb)\n\n if (!blockers.length) {\n stopBlocking()\n }\n }\n },\n flush: () => opts.flush?.(),\n destroy: () => opts.destroy?.(),\n notify: onUpdate,\n }\n}\n\nfunction assignKey(state: HistoryState) {\n if (!state) {\n state = {} as HistoryState\n }\n state.key = createRandomKey()\n return state\n}\n\n/**\n * Creates a history object that can be used to interact with the browser's\n * navigation. This is a lightweight API wrapping the browser's native methods.\n * It is designed to work with TanStack Router, but could be used as a standalone API as well.\n * IMPORTANT: This API implements history throttling via a microtask to prevent\n * excessive calls to the history API. In some browsers, calling history.pushState or\n * history.replaceState in quick succession can cause the browser to ignore subsequent\n * calls. This API smooths out those differences and ensures that your application\n * state will *eventually* match the browser state. In most cases, this is not a problem,\n * but if you need to ensure that the browser state is up to date, you can use the\n * `history.flush` method to immediately flush all pending state changes to the browser URL.\n * @param opts\n * @param opts.getHref A function that returns the current href (path + search + hash)\n * @param opts.createHref A function that takes a path and returns a href (path + search + hash)\n * @returns A history instance\n */\nexport function createBrowserHistory(opts?: {\n getHref?: () => string\n createHref?: (path: string) => string\n}): RouterHistory {\n const getHref =\n opts?.getHref ??\n (() =>\n `${window.location.pathname}${window.location.search}${window.location.hash}`)\n\n const createHref = opts?.createHref ?? ((path) => path)\n\n let currentLocation = parseLocation(getHref(), window.history.state)\n\n const getLocation = () => currentLocation\n\n let next:\n | undefined\n | {\n // This is the latest location that we were attempting to push/replace\n href: string\n // This is the latest state that we were attempting to push/replace\n state: any\n // This is the latest type that we were attempting to push/replace\n isPush: boolean\n }\n\n // Because we are proactively updating the location\n // in memory before actually updating the browser history,\n // we need to track when we are doing this so we don't\n // notify subscribers twice on the last update.\n let tracking = true\n\n // We need to track the current scheduled update to prevent\n // multiple updates from being scheduled at the same time.\n let scheduled: Promise<void> | undefined\n\n // This function is a wrapper to prevent any of the callback's\n // side effects from causing a subscriber notification\n const untrack = (fn: () => void) => {\n tracking = false\n fn()\n tracking = true\n }\n\n // This function flushes the next update to the browser history\n const flush = () => {\n // Do not notify subscribers about this push/replace call\n untrack(() => {\n if (!next) return\n window.history[next.isPush ? 'pushState' : 'replaceState'](\n next.state,\n '',\n next.href,\n )\n // Reset the nextIsPush flag and clear the scheduled update\n next = undefined\n scheduled = undefined\n })\n }\n\n // This function queues up a call to update the browser history\n const queueHistoryAction = (\n type: 'push' | 'replace',\n path: string,\n state: any,\n onUpdate: () => void,\n ) => {\n const href = createHref(path)\n\n // Update the location in memory\n currentLocation = parseLocation(href, state)\n\n // Keep track of the next location we need to flush to the URL\n next = {\n href,\n state,\n isPush: next?.isPush || type === 'push',\n }\n // Notify subscribers\n onUpdate()\n\n if (!scheduled) {\n // Schedule an update to the browser history\n scheduled = Promise.resolve().then(() => flush())\n }\n }\n\n const onPushPop = () => {\n currentLocation = parseLocation(getHref(), window.history.state)\n history.notify()\n }\n\n var originalPushState = window.history.pushState\n var originalReplaceState = window.history.replaceState\n\n const history = createHistory({\n getLocation,\n pushState: (path, state, onUpdate) =>\n queueHistoryAction('push', path, state, onUpdate),\n replaceState: (path, state, onUpdate) =>\n queueHistoryAction('replace', path, state, onUpdate),\n back: () => window.history.back(),\n forward: () => window.history.forward(),\n go: (n) => window.history.go(n),\n createHref: (path) => createHref(path),\n flush,\n destroy: () => {\n window.history.pushState = originalPushState\n window.history.replaceState = originalReplaceState\n window.removeEventListener(pushStateEvent, onPushPop)\n window.removeEventListener(popStateEvent, onPushPop)\n },\n })\n\n window.addEventListener(pushStateEvent, onPushPop)\n window.addEventListener(popStateEvent, onPushPop)\n\n window.history.pushState = function () {\n let res = originalPushState.apply(window.history, arguments as any)\n if (tracking) history.notify()\n return res\n }\n\n window.history.replaceState = function () {\n let res = originalReplaceState.apply(window.history, arguments as any)\n if (tracking) history.notify()\n return res\n }\n\n return history\n}\n\nexport function createHashHistory(): RouterHistory {\n return createBrowserHistory({\n getHref: () => window.location.hash.substring(1),\n createHref: (path) => `#${path}`,\n })\n}\n\nexport function createMemoryHistory(\n opts: {\n initialEntries: string[]\n initialIndex?: number\n } = {\n initialEntries: ['/'],\n },\n): RouterHistory {\n const entries = opts.initialEntries\n let index = opts.initialIndex ?? entries.length - 1\n let currentState = {\n key: createRandomKey(),\n } as HistoryState\n\n const getLocation = () => parseLocation(entries[index]!, currentState)\n\n return createHistory({\n getLocation,\n pushState: (path, state) => {\n currentState = state\n entries.push(path)\n index++\n },\n replaceState: (path, state) => {\n currentState = state\n entries[index] = path\n },\n back: () => {\n index--\n },\n forward: () => {\n index = Math.min(index + 1, entries.length - 1)\n },\n go: (n) => window.history.go(n),\n createHref: (path) => path,\n })\n}\n\nfunction parseLocation(href: string, state: HistoryState): HistoryLocation {\n let hashIndex = href.indexOf('#')\n let searchIndex = href.indexOf('?')\n\n return {\n href,\n pathname: href.substring(\n 0,\n hashIndex > 0\n ? searchIndex > 0\n ? Math.min(hashIndex, searchIndex)\n : hashIndex\n : searchIndex > 0\n ? searchIndex\n : href.length,\n ),\n hash: hashIndex > -1 ? href.substring(hashIndex) : '',\n search:\n searchIndex > -1\n ? href.slice(searchIndex, hashIndex === -1 ? undefined : hashIndex)\n : '',\n state: state || {},\n }\n}\n\n// Thanks co-pilot!\nfunction createRandomKey() {\n return (Math.random() + 1).toString(36).substring(7)\n}\n"],"names":["pushStateEvent","popStateEvent","beforeUnloadEvent","beforeUnloadListener","event","preventDefault","returnValue","stopBlocking","removeEventListener","capture","createHistory","opts","location","getLocation","subscribers","Set","blockers","queue","onUpdate","forEach","subscriber","tryUnblock","length","shift","queueTask","task","push","subscribe","cb","add","delete","path","state","assignKey","pushState","replace","replaceState","go","index","back","forward","createHref","str","block","addEventListener","filter","b","flush","destroy","notify","key","createRandomKey","createBrowserHistory","getHref","window","pathname","search","hash","currentLocation","parseLocation","history","next","tracking","scheduled","untrack","fn","isPush","href","undefined","queueHistoryAction","type","Promise","resolve","then","onPushPop","originalPushState","originalReplaceState","n","res","apply","arguments","createHashHistory","substring","createMemoryHistory","initialEntries","entries","initialIndex","currentState","Math","min","hashIndex","indexOf","searchIndex","slice","random","toString"],"mappings":";;;;;;;;;;AAAA;AACA;AACA;;AAkCA,MAAMA,cAAc,GAAG,WAAW,CAAA;AAClC,MAAMC,aAAa,GAAG,UAAU,CAAA;AAChC,MAAMC,iBAAiB,GAAG,cAAc,CAAA;AAExC,MAAMC,oBAAoB,GAAIC,KAAY,IAAK;EAC7CA,KAAK,CAACC,cAAc,EAAE,CAAA;AACtB;AACA,EAAA,OAAQD,KAAK,CAACE,WAAW,GAAG,EAAE,CAAA;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,CAACwC,CAAC,CAAC;IAC/BpC,UAAU,EAAGV,IAAI,IAAKA,IAAAA;AACxB,GAAC,CAAC,CAAA;AACJ,CAAA;AAEA,SAAS4B,aAAaA,CAACQ,IAAY,EAAEnC,KAAmB,EAAmB;AACzE,EAAA,IAAI0D,SAAS,GAAGvB,IAAI,CAACwB,OAAO,CAAC,GAAG,CAAC,CAAA;AACjC,EAAA,IAAIC,WAAW,GAAGzB,IAAI,CAACwB,OAAO,CAAC,GAAG,CAAC,CAAA;EAEnC,OAAO;IACLxB,IAAI;AACJZ,IAAAA,QAAQ,EAAEY,IAAI,CAACe,SAAS,CACtB,CAAC,EACDQ,SAAS,GAAG,CAAC,GACTE,WAAW,GAAG,CAAC,GACbJ,IAAI,CAACC,GAAG,CAACC,SAAS,EAAEE,WAAW,CAAC,GAChCF,SAAS,GACXE,WAAW,GAAG,CAAC,GACfA,WAAW,GACXzB,IAAI,CAAC7C,MACX,CAAC;AACDmC,IAAAA,IAAI,EAAEiC,SAAS,GAAG,CAAC,CAAC,GAAGvB,IAAI,CAACe,SAAS,CAACQ,SAAS,CAAC,GAAG,EAAE;IACrDlC,MAAM,EACJoC,WAAW,GAAG,CAAC,CAAC,GACZzB,IAAI,CAAC0B,KAAK,CAACD,WAAW,EAAEF,SAAS,KAAK,CAAC,CAAC,GAAGtB,SAAS,GAAGsB,SAAS,CAAC,GACjE,EAAE;IACR1D,KAAK,EAAEA,KAAK,IAAI,EAAC;GAClB,CAAA;AACH,CAAA;;AAEA;AACA,SAASmB,eAAeA,GAAG;AACzB,EAAA,OAAO,CAACqC,IAAI,CAACM,MAAM,EAAE,GAAG,CAAC,EAAEC,QAAQ,CAAC,EAAE,CAAC,CAACb,SAAS,CAAC,CAAC,CAAC,CAAA;AACtD;;;;"}
1
+ {"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["// While the public API was clearly inspired by the \"history\" npm package,\n// This implementation attempts to be more lightweight by\n// making assumptions about the way TanStack Router works\n\nexport interface RouterHistory {\n location: HistoryLocation\n subscribe: (cb: () => void) => () => void\n push: (path: string, state?: any) => void\n replace: (path: string, state?: any) => void\n go: (index: number) => void\n back: () => void\n forward: () => void\n createHref: (href: string) => string\n block: (blockerFn: BlockerFn) => () => void\n flush: () => void\n destroy: () => void\n notify: () => void\n}\n\nexport interface HistoryLocation extends ParsedPath {\n state: HistoryState\n}\n\nexport interface ParsedPath {\n href: string\n pathname: string\n search: string\n hash: string\n}\n\nexport interface HistoryState {\n key: string\n}\n\ntype BlockerFn = (retry: () => void, cancel: () => void) => void\n\nconst pushStateEvent = 'pushstate'\nconst popStateEvent = 'popstate'\nconst beforeUnloadEvent = 'beforeunload'\n\nconst beforeUnloadListener = (event: Event) => {\n event.preventDefault()\n // @ts-ignore\n return (event.returnValue = '')\n}\n\nconst stopBlocking = () => {\n removeEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n}\n\nfunction createHistory(opts: {\n getLocation: () => HistoryLocation\n pushState: (path: string, state: any, onUpdate: () => void) => void\n replaceState: (path: string, state: any, onUpdate: () => void) => void\n go: (n: number) => void\n back: () => void\n forward: () => void\n createHref: (path: string) => string\n flush?: () => void\n destroy?: () => void\n}): RouterHistory {\n let location = opts.getLocation()\n let subscribers = new Set<() => void>()\n let blockers: BlockerFn[] = []\n let queue: (() => void)[] = []\n\n const onUpdate = () => {\n location = opts.getLocation()\n subscribers.forEach((subscriber) => subscriber())\n }\n\n const tryUnblock = () => {\n if (blockers.length) {\n blockers[0]?.(tryUnblock, () => {\n blockers = []\n stopBlocking()\n })\n return\n }\n\n while (queue.length) {\n queue.shift()?.()\n }\n }\n\n const queueTask = (task: () => void) => {\n queue.push(task)\n tryUnblock()\n }\n\n return {\n get location() {\n return location\n },\n subscribe: (cb: () => void) => {\n subscribers.add(cb)\n\n return () => {\n subscribers.delete(cb)\n }\n },\n push: (path: string, state: any) => {\n state = assignKey(state)\n queueTask(() => {\n opts.pushState(path, state, onUpdate)\n })\n },\n replace: (path: string, state: any) => {\n state = assignKey(state)\n queueTask(() => {\n opts.replaceState(path, state, onUpdate)\n })\n },\n go: (index) => {\n queueTask(() => {\n opts.go(index)\n })\n },\n back: () => {\n queueTask(() => {\n opts.back()\n })\n },\n forward: () => {\n queueTask(() => {\n opts.forward()\n })\n },\n createHref: (str) => opts.createHref(str),\n block: (cb) => {\n blockers.push(cb)\n\n if (blockers.length === 1) {\n addEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n }\n\n return () => {\n blockers = blockers.filter((b) => b !== cb)\n\n if (!blockers.length) {\n stopBlocking()\n }\n }\n },\n flush: () => opts.flush?.(),\n destroy: () => opts.destroy?.(),\n notify: onUpdate,\n }\n}\n\nfunction assignKey(state: HistoryState) {\n if (!state) {\n state = {} as HistoryState\n }\n return {\n ...state,\n key: createRandomKey(),\n }\n}\n\n/**\n * Creates a history object that can be used to interact with the browser's\n * navigation. This is a lightweight API wrapping the browser's native methods.\n * It is designed to work with TanStack Router, but could be used as a standalone API as well.\n * IMPORTANT: This API implements history throttling via a microtask to prevent\n * excessive calls to the history API. In some browsers, calling history.pushState or\n * history.replaceState in quick succession can cause the browser to ignore subsequent\n * calls. This API smooths out those differences and ensures that your application\n * state will *eventually* match the browser state. In most cases, this is not a problem,\n * but if you need to ensure that the browser state is up to date, you can use the\n * `history.flush` method to immediately flush all pending state changes to the browser URL.\n * @param opts\n * @param opts.getHref A function that returns the current href (path + search + hash)\n * @param opts.createHref A function that takes a path and returns a href (path + search + hash)\n * @returns A history instance\n */\nexport function createBrowserHistory(opts?: {\n getHref?: () => string\n createHref?: (path: string) => string\n}): RouterHistory {\n const getHref =\n opts?.getHref ??\n (() =>\n `${window.location.pathname}${window.location.search}${window.location.hash}`)\n\n const createHref = opts?.createHref ?? ((path) => path)\n\n let currentLocation = parseLocation(getHref(), window.history.state)\n\n const getLocation = () => currentLocation\n\n let next:\n | undefined\n | {\n // This is the latest location that we were attempting to push/replace\n href: string\n // This is the latest state that we were attempting to push/replace\n state: any\n // This is the latest type that we were attempting to push/replace\n isPush: boolean\n }\n\n // Because we are proactively updating the location\n // in memory before actually updating the browser history,\n // we need to track when we are doing this so we don't\n // notify subscribers twice on the last update.\n let tracking = true\n\n // We need to track the current scheduled update to prevent\n // multiple updates from being scheduled at the same time.\n let scheduled: Promise<void> | undefined\n\n // This function is a wrapper to prevent any of the callback's\n // side effects from causing a subscriber notification\n const untrack = (fn: () => void) => {\n tracking = false\n fn()\n tracking = true\n }\n\n // This function flushes the next update to the browser history\n const flush = () => {\n // Do not notify subscribers about this push/replace call\n untrack(() => {\n if (!next) return\n window.history[next.isPush ? 'pushState' : 'replaceState'](\n next.state,\n '',\n next.href,\n )\n // Reset the nextIsPush flag and clear the scheduled update\n next = undefined\n scheduled = undefined\n })\n }\n\n // This function queues up a call to update the browser history\n const queueHistoryAction = (\n type: 'push' | 'replace',\n path: string,\n state: any,\n onUpdate: () => void,\n ) => {\n const href = createHref(path)\n\n // Update the location in memory\n currentLocation = parseLocation(href, state)\n\n // Keep track of the next location we need to flush to the URL\n next = {\n href,\n state,\n isPush: next?.isPush || type === 'push',\n }\n // Notify subscribers\n onUpdate()\n\n if (!scheduled) {\n // Schedule an update to the browser history\n scheduled = Promise.resolve().then(() => flush())\n }\n }\n\n const onPushPop = () => {\n currentLocation = parseLocation(getHref(), window.history.state)\n history.notify()\n }\n\n var originalPushState = window.history.pushState\n var originalReplaceState = window.history.replaceState\n\n const history = createHistory({\n getLocation,\n pushState: (path, state, onUpdate) =>\n queueHistoryAction('push', path, state, onUpdate),\n replaceState: (path, state, onUpdate) =>\n queueHistoryAction('replace', path, state, onUpdate),\n back: () => window.history.back(),\n forward: () => window.history.forward(),\n go: (n) => window.history.go(n),\n createHref: (path) => createHref(path),\n flush,\n destroy: () => {\n window.history.pushState = originalPushState\n window.history.replaceState = originalReplaceState\n window.removeEventListener(pushStateEvent, onPushPop)\n window.removeEventListener(popStateEvent, onPushPop)\n },\n })\n\n window.addEventListener(pushStateEvent, onPushPop)\n window.addEventListener(popStateEvent, onPushPop)\n\n window.history.pushState = function () {\n let res = originalPushState.apply(window.history, arguments as any)\n if (tracking) history.notify()\n return res\n }\n\n window.history.replaceState = function () {\n let res = originalReplaceState.apply(window.history, arguments as any)\n if (tracking) history.notify()\n return res\n }\n\n return history\n}\n\nexport function createHashHistory(): RouterHistory {\n return createBrowserHistory({\n getHref: () => window.location.hash.substring(1),\n createHref: (path) => `#${path}`,\n })\n}\n\nexport function createMemoryHistory(\n opts: {\n initialEntries: string[]\n initialIndex?: number\n } = {\n initialEntries: ['/'],\n },\n): RouterHistory {\n const entries = opts.initialEntries\n let index = opts.initialIndex ?? entries.length - 1\n let currentState = {\n key: createRandomKey(),\n } as HistoryState\n\n const getLocation = () => parseLocation(entries[index]!, currentState)\n\n return createHistory({\n getLocation,\n pushState: (path, state) => {\n currentState = state\n entries.push(path)\n index++\n },\n replaceState: (path, state) => {\n currentState = state\n entries[index] = path\n },\n back: () => {\n index--\n },\n forward: () => {\n index = Math.min(index + 1, entries.length - 1)\n },\n go: (n) => window.history.go(n),\n createHref: (path) => path,\n })\n}\n\nfunction parseLocation(href: string, state: HistoryState): HistoryLocation {\n let hashIndex = href.indexOf('#')\n let searchIndex = href.indexOf('?')\n\n return {\n href,\n pathname: href.substring(\n 0,\n hashIndex > 0\n ? searchIndex > 0\n ? Math.min(hashIndex, searchIndex)\n : hashIndex\n : searchIndex > 0\n ? searchIndex\n : href.length,\n ),\n hash: hashIndex > -1 ? href.substring(hashIndex) : '',\n search:\n searchIndex > -1\n ? href.slice(searchIndex, hashIndex === -1 ? undefined : hashIndex)\n : '',\n state: state || {},\n }\n}\n\n// Thanks co-pilot!\nfunction createRandomKey() {\n return (Math.random() + 1).toString(36).substring(7)\n}\n"],"names":["pushStateEvent","popStateEvent","beforeUnloadEvent","beforeUnloadListener","event","preventDefault","returnValue","stopBlocking","removeEventListener","capture","createHistory","opts","location","getLocation","subscribers","Set","blockers","queue","onUpdate","forEach","subscriber","tryUnblock","length","shift","queueTask","task","push","subscribe","cb","add","delete","path","state","assignKey","pushState","replace","replaceState","go","index","back","forward","createHref","str","block","addEventListener","filter","b","flush","destroy","notify","key","createRandomKey","createBrowserHistory","getHref","window","pathname","search","hash","currentLocation","parseLocation","history","next","tracking","scheduled","untrack","fn","isPush","href","undefined","queueHistoryAction","type","Promise","resolve","then","onPushPop","originalPushState","originalReplaceState","n","res","apply","arguments","createHashHistory","substring","createMemoryHistory","initialEntries","entries","initialIndex","currentState","Math","min","hashIndex","indexOf","searchIndex","slice","random","toString"],"mappings":";;;;;;;;;;AAAA;AACA;AACA;;AAkCA,MAAMA,cAAc,GAAG,WAAW,CAAA;AAClC,MAAMC,aAAa,GAAG,UAAU,CAAA;AAChC,MAAMC,iBAAiB,GAAG,cAAc,CAAA;AAExC,MAAMC,oBAAoB,GAAIC,KAAY,IAAK;EAC7CA,KAAK,CAACC,cAAc,EAAE,CAAA;AACtB;AACA,EAAA,OAAQD,KAAK,CAACE,WAAW,GAAG,EAAE,CAAA;AAChC,CAAC,CAAA;AAED,MAAMC,YAAY,GAAGA,MAAM;AACzBC,EAAAA,mBAAmB,CAACN,iBAAiB,EAAEC,oBAAoB,EAAE;AAC3DM,IAAAA,OAAO,EAAE,IAAA;AACX,GAAC,CAAC,CAAA;AACJ,CAAC,CAAA;AAED,SAASC,aAAaA,CAACC,IAUtB,EAAiB;AAChB,EAAA,IAAIC,QAAQ,GAAGD,IAAI,CAACE,WAAW,EAAE,CAAA;AACjC,EAAA,IAAIC,WAAW,GAAG,IAAIC,GAAG,EAAc,CAAA;EACvC,IAAIC,QAAqB,GAAG,EAAE,CAAA;EAC9B,IAAIC,KAAqB,GAAG,EAAE,CAAA;EAE9B,MAAMC,QAAQ,GAAGA,MAAM;AACrBN,IAAAA,QAAQ,GAAGD,IAAI,CAACE,WAAW,EAAE,CAAA;IAC7BC,WAAW,CAACK,OAAO,CAAEC,UAAU,IAAKA,UAAU,EAAE,CAAC,CAAA;GAClD,CAAA;EAED,MAAM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,GAAG,CAAC,CAAC,GAAGvB,IAAI,CAACe,SAAS,CAACQ,SAAS,CAAC,GAAG,EAAE;IACrDlC,MAAM,EACJoC,WAAW,GAAG,CAAC,CAAC,GACZzB,IAAI,CAAC0B,KAAK,CAACD,WAAW,EAAEF,SAAS,KAAK,CAAC,CAAC,GAAGtB,SAAS,GAAGsB,SAAS,CAAC,GACjE,EAAE;IACR1D,KAAK,EAAEA,KAAK,IAAI,EAAC;GAClB,CAAA;AACH,CAAA;;AAEA;AACA,SAASmB,eAAeA,GAAG;AACzB,EAAA,OAAO,CAACqC,IAAI,CAACM,MAAM,EAAE,GAAG,CAAC,EAAEC,QAAQ,CAAC,EAAE,CAAC,CAACb,SAAS,CAAC,CAAC,CAAC,CAAA;AACtD;;;;"}
@@ -4024,7 +4024,7 @@ var drawChart = (function (exports) {
4024
4024
  </script>
4025
4025
  <script>
4026
4026
  /*<!--*/
4027
- const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.production.js","children":[{"name":"packages/history/src/index.ts","uid":"4ab1-1"}]}],"isRoot":true},"nodeParts":{"4ab1-1":{"renderedLength":8888,"gzipLength":2610,"brotliLength":0,"mainUid":"4ab1-0"}},"nodeMetas":{"4ab1-0":{"id":"/packages/history/src/index.ts","moduleParts":{"index.production.js":"4ab1-1"},"imported":[],"importedBy":[],"isEntry":true}},"env":{"rollup":"2.79.1"},"options":{"gzip":true,"brotli":false,"sourcemap":false}};
4027
+ const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.production.js","children":[{"name":"packages/history/src/index.ts","uid":"d37e-1"}]}],"isRoot":true},"nodeParts":{"d37e-1":{"renderedLength":8900,"gzipLength":2605,"brotliLength":0,"mainUid":"d37e-0"}},"nodeMetas":{"d37e-0":{"id":"/packages/history/src/index.ts","moduleParts":{"index.production.js":"d37e-1"},"imported":[],"importedBy":[],"isEntry":true}},"env":{"rollup":"2.79.1"},"options":{"gzip":true,"brotli":false,"sourcemap":false}};
4028
4028
 
4029
4029
  const run = () => {
4030
4030
  const width = window.innerWidth;
@@ -8,7 +8,7 @@
8
8
  "children": [
9
9
  {
10
10
  "name": "packages/history/src/index.ts",
11
- "uid": "4ab1-3"
11
+ "uid": "d37e-3"
12
12
  }
13
13
  ]
14
14
  }
@@ -16,18 +16,18 @@
16
16
  "isRoot": true
17
17
  },
18
18
  "nodeParts": {
19
- "4ab1-3": {
20
- "renderedLength": 8888,
21
- "gzipLength": 2610,
19
+ "d37e-3": {
20
+ "renderedLength": 8900,
21
+ "gzipLength": 2605,
22
22
  "brotliLength": 0,
23
- "mainUid": "4ab1-2"
23
+ "mainUid": "d37e-2"
24
24
  }
25
25
  },
26
26
  "nodeMetas": {
27
- "4ab1-2": {
27
+ "d37e-2": {
28
28
  "id": "/packages/history/src/index.ts",
29
29
  "moduleParts": {
30
- "index.production.js": "4ab1-3"
30
+ "index.production.js": "d37e-3"
31
31
  },
32
32
  "imported": [],
33
33
  "importedBy": [],
@@ -117,8 +117,10 @@
117
117
  if (!state) {
118
118
  state = {};
119
119
  }
120
- state.key = createRandomKey();
121
- return state;
120
+ return {
121
+ ...state,
122
+ key: createRandomKey()
123
+ };
122
124
  }
123
125
 
124
126
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.development.js","sources":["../../src/index.ts"],"sourcesContent":["// While the public API was clearly inspired by the \"history\" npm package,\n// This implementation attempts to be more lightweight by\n// making assumptions about the way TanStack Router works\n\nexport interface RouterHistory {\n location: HistoryLocation\n subscribe: (cb: () => void) => () => void\n push: (path: string, state?: any) => void\n replace: (path: string, state?: any) => void\n go: (index: number) => void\n back: () => void\n forward: () => void\n createHref: (href: string) => string\n block: (blockerFn: BlockerFn) => () => void\n flush: () => void\n destroy: () => void\n notify: () => void\n}\n\nexport interface HistoryLocation extends ParsedPath {\n state: HistoryState\n}\n\nexport interface ParsedPath {\n href: string\n pathname: string\n search: string\n hash: string\n}\n\nexport interface HistoryState {\n key: string\n}\n\ntype BlockerFn = (retry: () => void, cancel: () => void) => void\n\nconst pushStateEvent = 'pushstate'\nconst popStateEvent = 'popstate'\nconst beforeUnloadEvent = 'beforeunload'\n\nconst beforeUnloadListener = (event: Event) => {\n event.preventDefault()\n // @ts-ignore\n return (event.returnValue = '')\n}\n\nconst stopBlocking = () => {\n removeEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n}\n\nfunction createHistory(opts: {\n getLocation: () => HistoryLocation\n pushState: (path: string, state: any, onUpdate: () => void) => void\n replaceState: (path: string, state: any, onUpdate: () => void) => void\n go: (n: number) => void\n back: () => void\n forward: () => void\n createHref: (path: string) => string\n flush?: () => void\n destroy?: () => void\n}): RouterHistory {\n let location = opts.getLocation()\n let subscribers = new Set<() => void>()\n let blockers: BlockerFn[] = []\n let queue: (() => void)[] = []\n\n const onUpdate = () => {\n location = opts.getLocation()\n subscribers.forEach((subscriber) => subscriber())\n }\n\n const tryUnblock = () => {\n if (blockers.length) {\n blockers[0]?.(tryUnblock, () => {\n blockers = []\n stopBlocking()\n })\n return\n }\n\n while (queue.length) {\n queue.shift()?.()\n }\n }\n\n const queueTask = (task: () => void) => {\n queue.push(task)\n tryUnblock()\n }\n\n return {\n get location() {\n return location\n },\n subscribe: (cb: () => void) => {\n subscribers.add(cb)\n\n return () => {\n subscribers.delete(cb)\n }\n },\n push: (path: string, state: any) => {\n state = assignKey(state)\n queueTask(() => {\n opts.pushState(path, state, onUpdate)\n })\n },\n replace: (path: string, state: any) => {\n state = assignKey(state)\n queueTask(() => {\n opts.replaceState(path, state, onUpdate)\n })\n },\n go: (index) => {\n queueTask(() => {\n opts.go(index)\n })\n },\n back: () => {\n queueTask(() => {\n opts.back()\n })\n },\n forward: () => {\n queueTask(() => {\n opts.forward()\n })\n },\n createHref: (str) => opts.createHref(str),\n block: (cb) => {\n blockers.push(cb)\n\n if (blockers.length === 1) {\n addEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n }\n\n return () => {\n blockers = blockers.filter((b) => b !== cb)\n\n if (!blockers.length) {\n stopBlocking()\n }\n }\n },\n flush: () => opts.flush?.(),\n destroy: () => opts.destroy?.(),\n notify: onUpdate,\n }\n}\n\nfunction assignKey(state: HistoryState) {\n if (!state) {\n state = {} as HistoryState\n }\n state.key = createRandomKey()\n return state\n}\n\n/**\n * Creates a history object that can be used to interact with the browser's\n * navigation. This is a lightweight API wrapping the browser's native methods.\n * It is designed to work with TanStack Router, but could be used as a standalone API as well.\n * IMPORTANT: This API implements history throttling via a microtask to prevent\n * excessive calls to the history API. In some browsers, calling history.pushState or\n * history.replaceState in quick succession can cause the browser to ignore subsequent\n * calls. This API smooths out those differences and ensures that your application\n * state will *eventually* match the browser state. In most cases, this is not a problem,\n * but if you need to ensure that the browser state is up to date, you can use the\n * `history.flush` method to immediately flush all pending state changes to the browser URL.\n * @param opts\n * @param opts.getHref A function that returns the current href (path + search + hash)\n * @param opts.createHref A function that takes a path and returns a href (path + search + hash)\n * @returns A history instance\n */\nexport function createBrowserHistory(opts?: {\n getHref?: () => string\n createHref?: (path: string) => string\n}): RouterHistory {\n const getHref =\n opts?.getHref ??\n (() =>\n `${window.location.pathname}${window.location.search}${window.location.hash}`)\n\n const createHref = opts?.createHref ?? ((path) => path)\n\n let currentLocation = parseLocation(getHref(), window.history.state)\n\n const getLocation = () => currentLocation\n\n let next:\n | undefined\n | {\n // This is the latest location that we were attempting to push/replace\n href: string\n // This is the latest state that we were attempting to push/replace\n state: any\n // This is the latest type that we were attempting to push/replace\n isPush: boolean\n }\n\n // Because we are proactively updating the location\n // in memory before actually updating the browser history,\n // we need to track when we are doing this so we don't\n // notify subscribers twice on the last update.\n let tracking = true\n\n // We need to track the current scheduled update to prevent\n // multiple updates from being scheduled at the same time.\n let scheduled: Promise<void> | undefined\n\n // This function is a wrapper to prevent any of the callback's\n // side effects from causing a subscriber notification\n const untrack = (fn: () => void) => {\n tracking = false\n fn()\n tracking = true\n }\n\n // This function flushes the next update to the browser history\n const flush = () => {\n // Do not notify subscribers about this push/replace call\n untrack(() => {\n if (!next) return\n window.history[next.isPush ? 'pushState' : 'replaceState'](\n next.state,\n '',\n next.href,\n )\n // Reset the nextIsPush flag and clear the scheduled update\n next = undefined\n scheduled = undefined\n })\n }\n\n // This function queues up a call to update the browser history\n const queueHistoryAction = (\n type: 'push' | 'replace',\n path: string,\n state: any,\n onUpdate: () => void,\n ) => {\n const href = createHref(path)\n\n // Update the location in memory\n currentLocation = parseLocation(href, state)\n\n // Keep track of the next location we need to flush to the URL\n next = {\n href,\n state,\n isPush: next?.isPush || type === 'push',\n }\n // Notify subscribers\n onUpdate()\n\n if (!scheduled) {\n // Schedule an update to the browser history\n scheduled = Promise.resolve().then(() => flush())\n }\n }\n\n const onPushPop = () => {\n currentLocation = parseLocation(getHref(), window.history.state)\n history.notify()\n }\n\n var originalPushState = window.history.pushState\n var originalReplaceState = window.history.replaceState\n\n const history = createHistory({\n getLocation,\n pushState: (path, state, onUpdate) =>\n queueHistoryAction('push', path, state, onUpdate),\n replaceState: (path, state, onUpdate) =>\n queueHistoryAction('replace', path, state, onUpdate),\n back: () => window.history.back(),\n forward: () => window.history.forward(),\n go: (n) => window.history.go(n),\n createHref: (path) => createHref(path),\n flush,\n destroy: () => {\n window.history.pushState = originalPushState\n window.history.replaceState = originalReplaceState\n window.removeEventListener(pushStateEvent, onPushPop)\n window.removeEventListener(popStateEvent, onPushPop)\n },\n })\n\n window.addEventListener(pushStateEvent, onPushPop)\n window.addEventListener(popStateEvent, onPushPop)\n\n window.history.pushState = function () {\n let res = originalPushState.apply(window.history, arguments as any)\n if (tracking) history.notify()\n return res\n }\n\n window.history.replaceState = function () {\n let res = originalReplaceState.apply(window.history, arguments as any)\n if (tracking) history.notify()\n return res\n }\n\n return history\n}\n\nexport function createHashHistory(): RouterHistory {\n return createBrowserHistory({\n getHref: () => window.location.hash.substring(1),\n createHref: (path) => `#${path}`,\n })\n}\n\nexport function createMemoryHistory(\n opts: {\n initialEntries: string[]\n initialIndex?: number\n } = {\n initialEntries: ['/'],\n },\n): RouterHistory {\n const entries = opts.initialEntries\n let index = opts.initialIndex ?? entries.length - 1\n let currentState = {\n key: createRandomKey(),\n } as HistoryState\n\n const getLocation = () => parseLocation(entries[index]!, currentState)\n\n return createHistory({\n getLocation,\n pushState: (path, state) => {\n currentState = state\n entries.push(path)\n index++\n },\n replaceState: (path, state) => {\n currentState = state\n entries[index] = path\n },\n back: () => {\n index--\n },\n forward: () => {\n index = Math.min(index + 1, entries.length - 1)\n },\n go: (n) => window.history.go(n),\n createHref: (path) => path,\n })\n}\n\nfunction parseLocation(href: string, state: HistoryState): HistoryLocation {\n let hashIndex = href.indexOf('#')\n let searchIndex = href.indexOf('?')\n\n return {\n href,\n pathname: href.substring(\n 0,\n hashIndex > 0\n ? searchIndex > 0\n ? Math.min(hashIndex, searchIndex)\n : hashIndex\n : searchIndex > 0\n ? searchIndex\n : href.length,\n ),\n hash: hashIndex > -1 ? href.substring(hashIndex) : '',\n search:\n searchIndex > -1\n ? href.slice(searchIndex, hashIndex === -1 ? undefined : hashIndex)\n : '',\n state: state || {},\n }\n}\n\n// Thanks co-pilot!\nfunction createRandomKey() {\n return (Math.random() + 1).toString(36).substring(7)\n}\n"],"names":["pushStateEvent","popStateEvent","beforeUnloadEvent","beforeUnloadListener","event","preventDefault","returnValue","stopBlocking","removeEventListener","capture","createHistory","opts","location","getLocation","subscribers","Set","blockers","queue","onUpdate","forEach","subscriber","tryUnblock","length","shift","queueTask","task","push","subscribe","cb","add","delete","path","state","assignKey","pushState","replace","replaceState","go","index","back","forward","createHref","str","block","addEventListener","filter","b","flush","destroy","notify","key","createRandomKey","createBrowserHistory","getHref","window","pathname","search","hash","currentLocation","parseLocation","history","next","tracking","scheduled","untrack","fn","isPush","href","undefined","queueHistoryAction","type","Promise","resolve","then","onPushPop","originalPushState","originalReplaceState","n","res","apply","arguments","createHashHistory","substring","createMemoryHistory","initialEntries","entries","initialIndex","currentState","Math","min","hashIndex","indexOf","searchIndex","slice","random","toString"],"mappings":";;;;;;;;;;;;;;;;EA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AA,OAAO,CAACqC,IAAI,CAACM,MAAM,EAAE,GAAG,CAAC,EAAEC,QAAQ,CAAC,EAAE,CAAC,CAACb,SAAS,CAAC,CAAC,CAAC,CAAA;EACtD;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.development.js","sources":["../../src/index.ts"],"sourcesContent":["// While the public API was clearly inspired by the \"history\" npm package,\n// This implementation attempts to be more lightweight by\n// making assumptions about the way TanStack Router works\n\nexport interface RouterHistory {\n location: HistoryLocation\n subscribe: (cb: () => void) => () => void\n push: (path: string, state?: any) => void\n replace: (path: string, state?: any) => void\n go: (index: number) => void\n back: () => void\n forward: () => void\n createHref: (href: string) => string\n block: (blockerFn: BlockerFn) => () => void\n flush: () => void\n destroy: () => void\n notify: () => void\n}\n\nexport interface HistoryLocation extends ParsedPath {\n state: HistoryState\n}\n\nexport interface ParsedPath {\n href: string\n pathname: string\n search: string\n hash: string\n}\n\nexport interface HistoryState {\n key: string\n}\n\ntype BlockerFn = (retry: () => void, cancel: () => void) => void\n\nconst pushStateEvent = 'pushstate'\nconst popStateEvent = 'popstate'\nconst beforeUnloadEvent = 'beforeunload'\n\nconst beforeUnloadListener = (event: Event) => {\n event.preventDefault()\n // @ts-ignore\n return (event.returnValue = '')\n}\n\nconst stopBlocking = () => {\n removeEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n}\n\nfunction createHistory(opts: {\n getLocation: () => HistoryLocation\n pushState: (path: string, state: any, onUpdate: () => void) => void\n replaceState: (path: string, state: any, onUpdate: () => void) => void\n go: (n: number) => void\n back: () => void\n forward: () => void\n createHref: (path: string) => string\n flush?: () => void\n destroy?: () => void\n}): RouterHistory {\n let location = opts.getLocation()\n let subscribers = new Set<() => void>()\n let blockers: BlockerFn[] = []\n let queue: (() => void)[] = []\n\n const onUpdate = () => {\n location = opts.getLocation()\n subscribers.forEach((subscriber) => subscriber())\n }\n\n const tryUnblock = () => {\n if (blockers.length) {\n blockers[0]?.(tryUnblock, () => {\n blockers = []\n stopBlocking()\n })\n return\n }\n\n while (queue.length) {\n queue.shift()?.()\n }\n }\n\n const queueTask = (task: () => void) => {\n queue.push(task)\n tryUnblock()\n }\n\n return {\n get location() {\n return location\n },\n subscribe: (cb: () => void) => {\n subscribers.add(cb)\n\n return () => {\n subscribers.delete(cb)\n }\n },\n push: (path: string, state: any) => {\n state = assignKey(state)\n queueTask(() => {\n opts.pushState(path, state, onUpdate)\n })\n },\n replace: (path: string, state: any) => {\n state = assignKey(state)\n queueTask(() => {\n opts.replaceState(path, state, onUpdate)\n })\n },\n go: (index) => {\n queueTask(() => {\n opts.go(index)\n })\n },\n back: () => {\n queueTask(() => {\n opts.back()\n })\n },\n forward: () => {\n queueTask(() => {\n opts.forward()\n })\n },\n createHref: (str) => opts.createHref(str),\n block: (cb) => {\n blockers.push(cb)\n\n if (blockers.length === 1) {\n addEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n }\n\n return () => {\n blockers = blockers.filter((b) => b !== cb)\n\n if (!blockers.length) {\n stopBlocking()\n }\n }\n },\n flush: () => opts.flush?.(),\n destroy: () => opts.destroy?.(),\n notify: onUpdate,\n }\n}\n\nfunction assignKey(state: HistoryState) {\n if (!state) {\n state = {} as HistoryState\n }\n return {\n ...state,\n key: createRandomKey(),\n }\n}\n\n/**\n * Creates a history object that can be used to interact with the browser's\n * navigation. This is a lightweight API wrapping the browser's native methods.\n * It is designed to work with TanStack Router, but could be used as a standalone API as well.\n * IMPORTANT: This API implements history throttling via a microtask to prevent\n * excessive calls to the history API. In some browsers, calling history.pushState or\n * history.replaceState in quick succession can cause the browser to ignore subsequent\n * calls. This API smooths out those differences and ensures that your application\n * state will *eventually* match the browser state. In most cases, this is not a problem,\n * but if you need to ensure that the browser state is up to date, you can use the\n * `history.flush` method to immediately flush all pending state changes to the browser URL.\n * @param opts\n * @param opts.getHref A function that returns the current href (path + search + hash)\n * @param opts.createHref A function that takes a path and returns a href (path + search + hash)\n * @returns A history instance\n */\nexport function createBrowserHistory(opts?: {\n getHref?: () => string\n createHref?: (path: string) => string\n}): RouterHistory {\n const getHref =\n opts?.getHref ??\n (() =>\n `${window.location.pathname}${window.location.search}${window.location.hash}`)\n\n const createHref = opts?.createHref ?? ((path) => path)\n\n let currentLocation = parseLocation(getHref(), window.history.state)\n\n const getLocation = () => currentLocation\n\n let next:\n | undefined\n | {\n // This is the latest location that we were attempting to push/replace\n href: string\n // This is the latest state that we were attempting to push/replace\n state: any\n // This is the latest type that we were attempting to push/replace\n isPush: boolean\n }\n\n // Because we are proactively updating the location\n // in memory before actually updating the browser history,\n // we need to track when we are doing this so we don't\n // notify subscribers twice on the last update.\n let tracking = true\n\n // We need to track the current scheduled update to prevent\n // multiple updates from being scheduled at the same time.\n let scheduled: Promise<void> | undefined\n\n // This function is a wrapper to prevent any of the callback's\n // side effects from causing a subscriber notification\n const untrack = (fn: () => void) => {\n tracking = false\n fn()\n tracking = true\n }\n\n // This function flushes the next update to the browser history\n const flush = () => {\n // Do not notify subscribers about this push/replace call\n untrack(() => {\n if (!next) return\n window.history[next.isPush ? 'pushState' : 'replaceState'](\n next.state,\n '',\n next.href,\n )\n // Reset the nextIsPush flag and clear the scheduled update\n next = undefined\n scheduled = undefined\n })\n }\n\n // This function queues up a call to update the browser history\n const queueHistoryAction = (\n type: 'push' | 'replace',\n path: string,\n state: any,\n onUpdate: () => void,\n ) => {\n const href = createHref(path)\n\n // Update the location in memory\n currentLocation = parseLocation(href, state)\n\n // Keep track of the next location we need to flush to the URL\n next = {\n href,\n state,\n isPush: next?.isPush || type === 'push',\n }\n // Notify subscribers\n onUpdate()\n\n if (!scheduled) {\n // Schedule an update to the browser history\n scheduled = Promise.resolve().then(() => flush())\n }\n }\n\n const onPushPop = () => {\n currentLocation = parseLocation(getHref(), window.history.state)\n history.notify()\n }\n\n var originalPushState = window.history.pushState\n var originalReplaceState = window.history.replaceState\n\n const history = createHistory({\n getLocation,\n pushState: (path, state, onUpdate) =>\n queueHistoryAction('push', path, state, onUpdate),\n replaceState: (path, state, onUpdate) =>\n queueHistoryAction('replace', path, state, onUpdate),\n back: () => window.history.back(),\n forward: () => window.history.forward(),\n go: (n) => window.history.go(n),\n createHref: (path) => createHref(path),\n flush,\n destroy: () => {\n window.history.pushState = originalPushState\n window.history.replaceState = originalReplaceState\n window.removeEventListener(pushStateEvent, onPushPop)\n window.removeEventListener(popStateEvent, onPushPop)\n },\n })\n\n window.addEventListener(pushStateEvent, onPushPop)\n window.addEventListener(popStateEvent, onPushPop)\n\n window.history.pushState = function () {\n let res = originalPushState.apply(window.history, arguments as any)\n if (tracking) history.notify()\n return res\n }\n\n window.history.replaceState = function () {\n let res = originalReplaceState.apply(window.history, arguments as any)\n if (tracking) history.notify()\n return res\n }\n\n return history\n}\n\nexport function createHashHistory(): RouterHistory {\n return createBrowserHistory({\n getHref: () => window.location.hash.substring(1),\n createHref: (path) => `#${path}`,\n })\n}\n\nexport function createMemoryHistory(\n opts: {\n initialEntries: string[]\n initialIndex?: number\n } = {\n initialEntries: ['/'],\n },\n): RouterHistory {\n const entries = opts.initialEntries\n let index = opts.initialIndex ?? entries.length - 1\n let currentState = {\n key: createRandomKey(),\n } as HistoryState\n\n const getLocation = () => parseLocation(entries[index]!, currentState)\n\n return createHistory({\n getLocation,\n pushState: (path, state) => {\n currentState = state\n entries.push(path)\n index++\n },\n replaceState: (path, state) => {\n currentState = state\n entries[index] = path\n },\n back: () => {\n index--\n },\n forward: () => {\n index = Math.min(index + 1, entries.length - 1)\n },\n go: (n) => window.history.go(n),\n createHref: (path) => path,\n })\n}\n\nfunction parseLocation(href: string, state: HistoryState): HistoryLocation {\n let hashIndex = href.indexOf('#')\n let searchIndex = href.indexOf('?')\n\n return {\n href,\n pathname: href.substring(\n 0,\n hashIndex > 0\n ? searchIndex > 0\n ? Math.min(hashIndex, searchIndex)\n : hashIndex\n : searchIndex > 0\n ? searchIndex\n : href.length,\n ),\n hash: hashIndex > -1 ? href.substring(hashIndex) : '',\n search:\n searchIndex > -1\n ? href.slice(searchIndex, hashIndex === -1 ? undefined : hashIndex)\n : '',\n state: state || {},\n }\n}\n\n// Thanks co-pilot!\nfunction createRandomKey() {\n return (Math.random() + 1).toString(36).substring(7)\n}\n"],"names":["pushStateEvent","popStateEvent","beforeUnloadEvent","beforeUnloadListener","event","preventDefault","returnValue","stopBlocking","removeEventListener","capture","createHistory","opts","location","getLocation","subscribers","Set","blockers","queue","onUpdate","forEach","subscriber","tryUnblock","length","shift","queueTask","task","push","subscribe","cb","add","delete","path","state","assignKey","pushState","replace","replaceState","go","index","back","forward","createHref","str","block","addEventListener","filter","b","flush","destroy","notify","key","createRandomKey","createBrowserHistory","getHref","window","pathname","search","hash","currentLocation","parseLocation","history","next","tracking","scheduled","untrack","fn","isPush","href","undefined","queueHistoryAction","type","Promise","resolve","then","onPushPop","originalPushState","originalReplaceState","n","res","apply","arguments","createHashHistory","substring","createMemoryHistory","initialEntries","entries","initialIndex","currentState","Math","min","hashIndex","indexOf","searchIndex","slice","random","toString"],"mappings":";;;;;;;;;;;;;;;;EAAA;EACA;EACA;;EAkCA,MAAMA,cAAc,GAAG,WAAW,CAAA;EAClC,MAAMC,aAAa,GAAG,UAAU,CAAA;EAChC,MAAMC,iBAAiB,GAAG,cAAc,CAAA;EAExC,MAAMC,oBAAoB,GAAIC,KAAY,IAAK;IAC7CA,KAAK,CAACC,cAAc,EAAE,CAAA;EACtB;EACA,EAAA,OAAQD,KAAK,CAACE,WAAW,GAAG,EAAE,CAAA;EAChC,CAAC,CAAA;EAED,MAAMC,YAAY,GAAGA,MAAM;EACzBC,EAAAA,mBAAmB,CAACN,iBAAiB,EAAEC,oBAAoB,EAAE;EAC3DM,IAAAA,OAAO,EAAE,IAAA;EACX,GAAC,CAAC,CAAA;EACJ,CAAC,CAAA;EAED,SAASC,aAAaA,CAACC,IAUtB,EAAiB;EAChB,EAAA,IAAIC,QAAQ,GAAGD,IAAI,CAACE,WAAW,EAAE,CAAA;EACjC,EAAA,IAAIC,WAAW,GAAG,I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B,IAAI;EACJZ,IAAAA,QAAQ,EAAEY,IAAI,CAACe,SAAS,CACtB,CAAC,EACDQ,SAAS,GAAG,CAAC,GACTE,WAAW,GAAG,CAAC,GACbJ,IAAI,CAACC,GAAG,CAACC,SAAS,EAAEE,WAAW,CAAC,GAChCF,SAAS,GACXE,WAAW,GAAG,CAAC,GACfA,WAAW,GACXzB,IAAI,CAAC7C,MACX,CAAC;EACDmC,IAAAA,IAAI,EAAEiC,SAAS,GAAG,CAAC,CAAC,GAAGvB,IAAI,CAACe,SAAS,CAACQ,SAAS,CAAC,GAAG,EAAE;MACrDlC,MAAM,EACJoC,WAAW,GAAG,CAAC,CAAC,GACZzB,IAAI,CAAC0B,KAAK,CAACD,WAAW,EAAEF,SAAS,KAAK,CAAC,CAAC,GAAGtB,SAAS,GAAGsB,SAAS,CAAC,GACjE,EAAE;MACR1D,KAAK,EAAEA,KAAK,IAAI,EAAC;KAClB,CAAA;EACH,CAAA;;EAEA;EACA,SAASmB,eAAeA,GAAG;EACzB,EAAA,OAAO,CAACqC,IAAI,CAACM,MAAM,EAAE,GAAG,CAAC,EAAEC,QAAQ,CAAC,EAAE,CAAC,CAACb,SAAS,CAAC,CAAC,CAAC,CAAA;EACtD;;;;;;;;;;;;"}
@@ -8,5 +8,5 @@
8
8
  *
9
9
  * @license MIT
10
10
  */
11
- !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=[],h=[];const c=()=>{t=e.getLocation(),n.forEach((e=>e()))},d=()=>{if(s.length)s[0]?.(d,(()=>{s=[],i()}));else for(;h.length;)h.shift()?.()},u=e=>{h.push(e),d()};return{get location(){return t},subscribe:e=>(n.add(e),()=>{n.delete(e)}),push:(t,n)=>{n=a(n),u((()=>{e.pushState(t,n,c)}))},replace:(t,n)=>{n=a(n),u((()=>{e.replaceState(t,n,c)}))},go:t=>{u((()=>{e.go(t)}))},back:()=>{u((()=>{e.back()}))},forward:()=>{u((()=>{e.forward()}))},createHref:t=>e.createHref(t),block:e=>(s.push(e),1===s.length&&addEventListener(o,r,{capture:!0}),()=>{s=s.filter((t=>t!==e)),s.length||i()}),flush:()=>e.flush?.(),destroy:()=>e.destroy?.(),notify:c}}function a(e){return e||(e={}),e.key=d(),e}function h(e){const o=e?.getHref??(()=>`${window.location.pathname}${window.location.search}${window.location.hash}`),r=e?.createHref??(e=>e);let i=c(o(),window.history.state);let a,h,d=!0;const u=()=>{d=!1,(()=>{a&&(window.history[a.isPush?"pushState":"replaceState"](a.state,"",a.href),a=void 0,h=void 0)})(),d=!0},f=(e,t,n,o)=>{const s=r(t);i=c(s,n),a={href:s,state:n,isPush:a?.isPush||"push"===e},o(),h||(h=Promise.resolve().then((()=>u())))},l=()=>{i=c(o(),window.history.state),y.notify()};var w=window.history.pushState,p=window.history.replaceState;const y=s({getLocation:()=>i,pushState:(e,t,n)=>f("push",e,t,n),replaceState:(e,t,n)=>f("replace",e,t,n),back:()=>window.history.back(),forward:()=>window.history.forward(),go:e=>window.history.go(e),createHref:e=>r(e),flush:u,destroy:()=>{window.history.pushState=w,window.history.replaceState=p,window.removeEventListener(t,l),window.removeEventListener(n,l)}});return window.addEventListener(t,l),window.addEventListener(n,l),window.history.pushState=function(){let e=w.apply(window.history,arguments);return d&&y.notify(),e},window.history.replaceState=function(){let e=p.apply(window.history,arguments);return d&&y.notify(),e},y}function c(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 d(){return(Math.random()+1).toString(36).substring(7)}e.createBrowserHistory=h,e.createHashHistory=function(){return h({getHref:()=>window.location.hash.substring(1),createHref:e=>`#${e}`})},e.createMemoryHistory=function(e={initialEntries:["/"]}){const t=e.initialEntries;let n=e.initialIndex??t.length-1,o={key:d()};return s({getLocation:()=>c(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=>window.history.go(e),createHref:e=>e})},Object.defineProperty(e,"__esModule",{value:!0})}));
11
+ !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=[],h=[];const c=()=>{t=e.getLocation(),n.forEach((e=>e()))},d=()=>{if(s.length)s[0]?.(d,(()=>{s=[],i()}));else for(;h.length;)h.shift()?.()},u=e=>{h.push(e),d()};return{get location(){return t},subscribe:e=>(n.add(e),()=>{n.delete(e)}),push:(t,n)=>{n=a(n),u((()=>{e.pushState(t,n,c)}))},replace:(t,n)=>{n=a(n),u((()=>{e.replaceState(t,n,c)}))},go:t=>{u((()=>{e.go(t)}))},back:()=>{u((()=>{e.back()}))},forward:()=>{u((()=>{e.forward()}))},createHref:t=>e.createHref(t),block:e=>(s.push(e),1===s.length&&addEventListener(o,r,{capture:!0}),()=>{s=s.filter((t=>t!==e)),s.length||i()}),flush:()=>e.flush?.(),destroy:()=>e.destroy?.(),notify:c}}function a(e){return e||(e={}),{...e,key:d()}}function h(e){const o=e?.getHref??(()=>`${window.location.pathname}${window.location.search}${window.location.hash}`),r=e?.createHref??(e=>e);let i=c(o(),window.history.state);let a,h,d=!0;const u=()=>{d=!1,(()=>{a&&(window.history[a.isPush?"pushState":"replaceState"](a.state,"",a.href),a=void 0,h=void 0)})(),d=!0},f=(e,t,n,o)=>{const s=r(t);i=c(s,n),a={href:s,state:n,isPush:a?.isPush||"push"===e},o(),h||(h=Promise.resolve().then((()=>u())))},l=()=>{i=c(o(),window.history.state),y.notify()};var w=window.history.pushState,p=window.history.replaceState;const y=s({getLocation:()=>i,pushState:(e,t,n)=>f("push",e,t,n),replaceState:(e,t,n)=>f("replace",e,t,n),back:()=>window.history.back(),forward:()=>window.history.forward(),go:e=>window.history.go(e),createHref:e=>r(e),flush:u,destroy:()=>{window.history.pushState=w,window.history.replaceState=p,window.removeEventListener(t,l),window.removeEventListener(n,l)}});return window.addEventListener(t,l),window.addEventListener(n,l),window.history.pushState=function(){let e=w.apply(window.history,arguments);return d&&y.notify(),e},window.history.replaceState=function(){let e=p.apply(window.history,arguments);return d&&y.notify(),e},y}function c(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 d(){return(Math.random()+1).toString(36).substring(7)}e.createBrowserHistory=h,e.createHashHistory=function(){return h({getHref:()=>window.location.hash.substring(1),createHref:e=>`#${e}`})},e.createMemoryHistory=function(e={initialEntries:["/"]}){const t=e.initialEntries;let n=e.initialIndex??t.length-1,o={key:d()};return s({getLocation:()=>c(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=>window.history.go(e),createHref:e=>e})},Object.defineProperty(e,"__esModule",{value:!0})}));
12
12
  //# sourceMappingURL=index.production.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.production.js","sources":["../../src/index.ts"],"sourcesContent":["// While the public API was clearly inspired by the \"history\" npm package,\n// This implementation attempts to be more lightweight by\n// making assumptions about the way TanStack Router works\n\nexport interface RouterHistory {\n location: HistoryLocation\n subscribe: (cb: () => void) => () => void\n push: (path: string, state?: any) => void\n replace: (path: string, state?: any) => void\n go: (index: number) => void\n back: () => void\n forward: () => void\n createHref: (href: string) => string\n block: (blockerFn: BlockerFn) => () => void\n flush: () => void\n destroy: () => void\n notify: () => void\n}\n\nexport interface HistoryLocation extends ParsedPath {\n state: HistoryState\n}\n\nexport interface ParsedPath {\n href: string\n pathname: string\n search: string\n hash: string\n}\n\nexport interface HistoryState {\n key: string\n}\n\ntype BlockerFn = (retry: () => void, cancel: () => void) => void\n\nconst pushStateEvent = 'pushstate'\nconst popStateEvent = 'popstate'\nconst beforeUnloadEvent = 'beforeunload'\n\nconst beforeUnloadListener = (event: Event) => {\n event.preventDefault()\n // @ts-ignore\n return (event.returnValue = '')\n}\n\nconst stopBlocking = () => {\n removeEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n}\n\nfunction createHistory(opts: {\n getLocation: () => HistoryLocation\n pushState: (path: string, state: any, onUpdate: () => void) => void\n replaceState: (path: string, state: any, onUpdate: () => void) => void\n go: (n: number) => void\n back: () => void\n forward: () => void\n createHref: (path: string) => string\n flush?: () => void\n destroy?: () => void\n}): RouterHistory {\n let location = opts.getLocation()\n let subscribers = new Set<() => void>()\n let blockers: BlockerFn[] = []\n let queue: (() => void)[] = []\n\n const onUpdate = () => {\n location = opts.getLocation()\n subscribers.forEach((subscriber) => subscriber())\n }\n\n const tryUnblock = () => {\n if (blockers.length) {\n blockers[0]?.(tryUnblock, () => {\n blockers = []\n stopBlocking()\n })\n return\n }\n\n while (queue.length) {\n queue.shift()?.()\n }\n }\n\n const queueTask = (task: () => void) => {\n queue.push(task)\n tryUnblock()\n }\n\n return {\n get location() {\n return location\n },\n subscribe: (cb: () => void) => {\n subscribers.add(cb)\n\n return () => {\n subscribers.delete(cb)\n }\n },\n push: (path: string, state: any) => {\n state = assignKey(state)\n queueTask(() => {\n opts.pushState(path, state, onUpdate)\n })\n },\n replace: (path: string, state: any) => {\n state = assignKey(state)\n queueTask(() => {\n opts.replaceState(path, state, onUpdate)\n })\n },\n go: (index) => {\n queueTask(() => {\n opts.go(index)\n })\n },\n back: () => {\n queueTask(() => {\n opts.back()\n })\n },\n forward: () => {\n queueTask(() => {\n opts.forward()\n })\n },\n createHref: (str) => opts.createHref(str),\n block: (cb) => {\n blockers.push(cb)\n\n if (blockers.length === 1) {\n addEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n }\n\n return () => {\n blockers = blockers.filter((b) => b !== cb)\n\n if (!blockers.length) {\n stopBlocking()\n }\n }\n },\n flush: () => opts.flush?.(),\n destroy: () => opts.destroy?.(),\n notify: onUpdate,\n }\n}\n\nfunction assignKey(state: HistoryState) {\n if (!state) {\n state = {} as HistoryState\n }\n state.key = createRandomKey()\n return state\n}\n\n/**\n * Creates a history object that can be used to interact with the browser's\n * navigation. This is a lightweight API wrapping the browser's native methods.\n * It is designed to work with TanStack Router, but could be used as a standalone API as well.\n * IMPORTANT: This API implements history throttling via a microtask to prevent\n * excessive calls to the history API. In some browsers, calling history.pushState or\n * history.replaceState in quick succession can cause the browser to ignore subsequent\n * calls. This API smooths out those differences and ensures that your application\n * state will *eventually* match the browser state. In most cases, this is not a problem,\n * but if you need to ensure that the browser state is up to date, you can use the\n * `history.flush` method to immediately flush all pending state changes to the browser URL.\n * @param opts\n * @param opts.getHref A function that returns the current href (path + search + hash)\n * @param opts.createHref A function that takes a path and returns a href (path + search + hash)\n * @returns A history instance\n */\nexport function createBrowserHistory(opts?: {\n getHref?: () => string\n createHref?: (path: string) => string\n}): RouterHistory {\n const getHref =\n opts?.getHref ??\n (() =>\n `${window.location.pathname}${window.location.search}${window.location.hash}`)\n\n const createHref = opts?.createHref ?? ((path) => path)\n\n let currentLocation = parseLocation(getHref(), window.history.state)\n\n const getLocation = () => currentLocation\n\n let next:\n | undefined\n | {\n // This is the latest location that we were attempting to push/replace\n href: string\n // This is the latest state that we were attempting to push/replace\n state: any\n // This is the latest type that we were attempting to push/replace\n isPush: boolean\n }\n\n // Because we are proactively updating the location\n // in memory before actually updating the browser history,\n // we need to track when we are doing this so we don't\n // notify subscribers twice on the last update.\n let tracking = true\n\n // We need to track the current scheduled update to prevent\n // multiple updates from being scheduled at the same time.\n let scheduled: Promise<void> | undefined\n\n // This function is a wrapper to prevent any of the callback's\n // side effects from causing a subscriber notification\n const untrack = (fn: () => void) => {\n tracking = false\n fn()\n tracking = true\n }\n\n // This function flushes the next update to the browser history\n const flush = () => {\n // Do not notify subscribers about this push/replace call\n untrack(() => {\n if (!next) return\n window.history[next.isPush ? 'pushState' : 'replaceState'](\n next.state,\n '',\n next.href,\n )\n // Reset the nextIsPush flag and clear the scheduled update\n next = undefined\n scheduled = undefined\n })\n }\n\n // This function queues up a call to update the browser history\n const queueHistoryAction = (\n type: 'push' | 'replace',\n path: string,\n state: any,\n onUpdate: () => void,\n ) => {\n const href = createHref(path)\n\n // Update the location in memory\n currentLocation = parseLocation(href, state)\n\n // Keep track of the next location we need to flush to the URL\n next = {\n href,\n state,\n isPush: next?.isPush || type === 'push',\n }\n // Notify subscribers\n onUpdate()\n\n if (!scheduled) {\n // Schedule an update to the browser history\n scheduled = Promise.resolve().then(() => flush())\n }\n }\n\n const onPushPop = () => {\n currentLocation = parseLocation(getHref(), window.history.state)\n history.notify()\n }\n\n var originalPushState = window.history.pushState\n var originalReplaceState = window.history.replaceState\n\n const history = createHistory({\n getLocation,\n pushState: (path, state, onUpdate) =>\n queueHistoryAction('push', path, state, onUpdate),\n replaceState: (path, state, onUpdate) =>\n queueHistoryAction('replace', path, state, onUpdate),\n back: () => window.history.back(),\n forward: () => window.history.forward(),\n go: (n) => window.history.go(n),\n createHref: (path) => createHref(path),\n flush,\n destroy: () => {\n window.history.pushState = originalPushState\n window.history.replaceState = originalReplaceState\n window.removeEventListener(pushStateEvent, onPushPop)\n window.removeEventListener(popStateEvent, onPushPop)\n },\n })\n\n window.addEventListener(pushStateEvent, onPushPop)\n window.addEventListener(popStateEvent, onPushPop)\n\n window.history.pushState = function () {\n let res = originalPushState.apply(window.history, arguments as any)\n if (tracking) history.notify()\n return res\n }\n\n window.history.replaceState = function () {\n let res = originalReplaceState.apply(window.history, arguments as any)\n if (tracking) history.notify()\n return res\n }\n\n return history\n}\n\nexport function createHashHistory(): RouterHistory {\n return createBrowserHistory({\n getHref: () => window.location.hash.substring(1),\n createHref: (path) => `#${path}`,\n })\n}\n\nexport function createMemoryHistory(\n opts: {\n initialEntries: string[]\n initialIndex?: number\n } = {\n initialEntries: ['/'],\n },\n): RouterHistory {\n const entries = opts.initialEntries\n let index = opts.initialIndex ?? entries.length - 1\n let currentState = {\n key: createRandomKey(),\n } as HistoryState\n\n const getLocation = () => parseLocation(entries[index]!, currentState)\n\n return createHistory({\n getLocation,\n pushState: (path, state) => {\n currentState = state\n entries.push(path)\n index++\n },\n replaceState: (path, state) => {\n currentState = state\n entries[index] = path\n },\n back: () => {\n index--\n },\n forward: () => {\n index = Math.min(index + 1, entries.length - 1)\n },\n go: (n) => window.history.go(n),\n createHref: (path) => path,\n })\n}\n\nfunction parseLocation(href: string, state: HistoryState): HistoryLocation {\n let hashIndex = href.indexOf('#')\n let searchIndex = href.indexOf('?')\n\n return {\n href,\n pathname: href.substring(\n 0,\n hashIndex > 0\n ? searchIndex > 0\n ? Math.min(hashIndex, searchIndex)\n : hashIndex\n : searchIndex > 0\n ? searchIndex\n : href.length,\n ),\n hash: hashIndex > -1 ? href.substring(hashIndex) : '',\n search:\n searchIndex > -1\n ? href.slice(searchIndex, hashIndex === -1 ? undefined : hashIndex)\n : '',\n state: state || {},\n }\n}\n\n// Thanks co-pilot!\nfunction createRandomKey() {\n return (Math.random() + 1).toString(36).substring(7)\n}\n"],"names":["pushStateEvent","popStateEvent","beforeUnloadEvent","beforeUnloadListener","event","preventDefault","returnValue","stopBlocking","removeEventListener","capture","createHistory","opts","location","getLocation","subscribers","Set","blockers","queue","onUpdate","forEach","subscriber","tryUnblock","length","shift","queueTask","task","push","subscribe","cb","add","delete","path","state","assignKey","pushState","replace","replaceState","go","index","back","forward","createHref","str","block","addEventListener","filter","b","flush","destroy","notify","key","createRandomKey","createBrowserHistory","getHref","window","pathname","search","hash","currentLocation","parseLocation","history","next","scheduled","tracking","isPush","href","undefined","fn","queueHistoryAction","type","Promise","resolve","then","onPushPop","originalPushState","originalReplaceState","n","res","apply","arguments","hashIndex","indexOf","searchIndex","substring","Math","min","slice","random","toString","initialEntries","entries","initialIndex","currentState"],"mappings":";;;;;;;;;;uPAoCA,MAAMA,EAAiB,YACjBC,EAAgB,WAChBC,EAAoB,eAEpBC,EAAwBC,IAC5BA,EAAMC,iBAEED,EAAME,YAAc,IAGxBC,EAAeA,KACnBC,oBAAoBN,EAAmBC,EAAsB,CAC3DM,SAAS,GACT,EAGJ,SAASC,EAAcC,GAWrB,IAAIC,EAAWD,EAAKE,cAChBC,EAAc,IAAIC,IAClBC,EAAwB,GACxBC,EAAwB,GAE5B,MAAMC,EAAWA,KACfN,EAAWD,EAAKE,cAChBC,EAAYK,SAASC,GAAeA,KAAa,EAG7CC,EAAaA,KACjB,GAAIL,EAASM,OACXN,EAAS,KAAKK,GAAY,KACxBL,EAAW,GACXT,GAAc,SAKlB,KAAOU,EAAMK,QACXL,EAAMM,OAANN,IACF,EAGIO,EAAaC,IACjBR,EAAMS,KAAKD,GACXJ,GAAY,EAGd,MAAO,CACDT,eACF,OAAOA,CACR,EACDe,UAAYC,IACVd,EAAYe,IAAID,GAET,KACLd,EAAYgB,OAAOF,EAAG,GAG1BF,KAAMA,CAACK,EAAcC,KACnBA,EAAQC,EAAUD,GAClBR,GAAU,KACRb,EAAKuB,UAAUH,EAAMC,EAAOd,EAAS,GACrC,EAEJiB,QAASA,CAACJ,EAAcC,KACtBA,EAAQC,EAAUD,GAClBR,GAAU,KACRb,EAAKyB,aAAaL,EAAMC,EAAOd,EAAS,GACxC,EAEJmB,GAAKC,IACHd,GAAU,KACRb,EAAK0B,GAAGC,EAAM,GACd,EAEJC,KAAMA,KACJf,GAAU,KAC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kB,UAAUH,GAAa,GACnDxB,OACE0B,GAAe,EACXjB,EAAKqB,MAAMJ,GAA4B,IAAfF,OAAmBd,EAAYc,GACvD,GACNhD,MAAOA,GAAS,CAAC,EAErB,CAGA,SAASmB,IACP,OAAQiC,KAAKG,SAAW,GAAGC,SAAS,IAAIL,UAAU,EACpD,8CAzEO,WACL,OAAO/B,EAAqB,CAC1BC,QAASA,IAAMC,OAAO1C,SAAS6C,KAAK0B,UAAU,GAC9C1C,WAAaV,GAAU,IAAGA,KAE9B,wBAEO,SACLpB,EAGI,CACF8E,eAAgB,CAAC,OAGnB,MAAMC,EAAU/E,EAAK8E,eACrB,IAAInD,EAAQ3B,EAAKgF,cAAgBD,EAAQpE,OAAS,EAC9CsE,EAAe,CACjB1C,IAAKC,KAKP,OAAOzC,EAAc,CACnBG,YAHkBA,IAAM8C,EAAc+B,EAAQpD,GAASsD,GAIvD1D,UAAWA,CAACH,EAAMC,KAChB4D,EAAe5D,EACf0D,EAAQhE,KAAKK,GACbO,GAAO,EAETF,aAAcA,CAACL,EAAMC,KACnB4D,EAAe5D,EACf0D,EAAQpD,GAASP,CAAI,EAEvBQ,KAAMA,KACJD,GAAO,EAETE,QAASA,KACPF,EAAQ8C,KAAKC,IAAI/C,EAAQ,EAAGoD,EAAQpE,OAAS,EAAE,EAEjDe,GAAKuC,GAAMtB,OAAOM,QAAQvB,GAAGuC,GAC7BnC,WAAaV,GAASA,GAE1B"}
1
+ {"version":3,"file":"index.production.js","sources":["../../src/index.ts"],"sourcesContent":["// While the public API was clearly inspired by the \"history\" npm package,\n// This implementation attempts to be more lightweight by\n// making assumptions about the way TanStack Router works\n\nexport interface RouterHistory {\n location: HistoryLocation\n subscribe: (cb: () => void) => () => void\n push: (path: string, state?: any) => void\n replace: (path: string, state?: any) => void\n go: (index: number) => void\n back: () => void\n forward: () => void\n createHref: (href: string) => string\n block: (blockerFn: BlockerFn) => () => void\n flush: () => void\n destroy: () => void\n notify: () => void\n}\n\nexport interface HistoryLocation extends ParsedPath {\n state: HistoryState\n}\n\nexport interface ParsedPath {\n href: string\n pathname: string\n search: string\n hash: string\n}\n\nexport interface HistoryState {\n key: string\n}\n\ntype BlockerFn = (retry: () => void, cancel: () => void) => void\n\nconst pushStateEvent = 'pushstate'\nconst popStateEvent = 'popstate'\nconst beforeUnloadEvent = 'beforeunload'\n\nconst beforeUnloadListener = (event: Event) => {\n event.preventDefault()\n // @ts-ignore\n return (event.returnValue = '')\n}\n\nconst stopBlocking = () => {\n removeEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n}\n\nfunction createHistory(opts: {\n getLocation: () => HistoryLocation\n pushState: (path: string, state: any, onUpdate: () => void) => void\n replaceState: (path: string, state: any, onUpdate: () => void) => void\n go: (n: number) => void\n back: () => void\n forward: () => void\n createHref: (path: string) => string\n flush?: () => void\n destroy?: () => void\n}): RouterHistory {\n let location = opts.getLocation()\n let subscribers = new Set<() => void>()\n let blockers: BlockerFn[] = []\n let queue: (() => void)[] = []\n\n const onUpdate = () => {\n location = opts.getLocation()\n subscribers.forEach((subscriber) => subscriber())\n }\n\n const tryUnblock = () => {\n if (blockers.length) {\n blockers[0]?.(tryUnblock, () => {\n blockers = []\n stopBlocking()\n })\n return\n }\n\n while (queue.length) {\n queue.shift()?.()\n }\n }\n\n const queueTask = (task: () => void) => {\n queue.push(task)\n tryUnblock()\n }\n\n return {\n get location() {\n return location\n },\n subscribe: (cb: () => void) => {\n subscribers.add(cb)\n\n return () => {\n subscribers.delete(cb)\n }\n },\n push: (path: string, state: any) => {\n state = assignKey(state)\n queueTask(() => {\n opts.pushState(path, state, onUpdate)\n })\n },\n replace: (path: string, state: any) => {\n state = assignKey(state)\n queueTask(() => {\n opts.replaceState(path, state, onUpdate)\n })\n },\n go: (index) => {\n queueTask(() => {\n opts.go(index)\n })\n },\n back: () => {\n queueTask(() => {\n opts.back()\n })\n },\n forward: () => {\n queueTask(() => {\n opts.forward()\n })\n },\n createHref: (str) => opts.createHref(str),\n block: (cb) => {\n blockers.push(cb)\n\n if (blockers.length === 1) {\n addEventListener(beforeUnloadEvent, beforeUnloadListener, {\n capture: true,\n })\n }\n\n return () => {\n blockers = blockers.filter((b) => b !== cb)\n\n if (!blockers.length) {\n stopBlocking()\n }\n }\n },\n flush: () => opts.flush?.(),\n destroy: () => opts.destroy?.(),\n notify: onUpdate,\n }\n}\n\nfunction assignKey(state: HistoryState) {\n if (!state) {\n state = {} as HistoryState\n }\n return {\n ...state,\n key: createRandomKey(),\n }\n}\n\n/**\n * Creates a history object that can be used to interact with the browser's\n * navigation. This is a lightweight API wrapping the browser's native methods.\n * It is designed to work with TanStack Router, but could be used as a standalone API as well.\n * IMPORTANT: This API implements history throttling via a microtask to prevent\n * excessive calls to the history API. In some browsers, calling history.pushState or\n * history.replaceState in quick succession can cause the browser to ignore subsequent\n * calls. This API smooths out those differences and ensures that your application\n * state will *eventually* match the browser state. In most cases, this is not a problem,\n * but if you need to ensure that the browser state is up to date, you can use the\n * `history.flush` method to immediately flush all pending state changes to the browser URL.\n * @param opts\n * @param opts.getHref A function that returns the current href (path + search + hash)\n * @param opts.createHref A function that takes a path and returns a href (path + search + hash)\n * @returns A history instance\n */\nexport function createBrowserHistory(opts?: {\n getHref?: () => string\n createHref?: (path: string) => string\n}): RouterHistory {\n const getHref =\n opts?.getHref ??\n (() =>\n `${window.location.pathname}${window.location.search}${window.location.hash}`)\n\n const createHref = opts?.createHref ?? ((path) => path)\n\n let currentLocation = parseLocation(getHref(), window.history.state)\n\n const getLocation = () => currentLocation\n\n let next:\n | undefined\n | {\n // This is the latest location that we were attempting to push/replace\n href: string\n // This is the latest state that we were attempting to push/replace\n state: any\n // This is the latest type that we were attempting to push/replace\n isPush: boolean\n }\n\n // Because we are proactively updating the location\n // in memory before actually updating the browser history,\n // we need to track when we are doing this so we don't\n // notify subscribers twice on the last update.\n let tracking = true\n\n // We need to track the current scheduled update to prevent\n // multiple updates from being scheduled at the same time.\n let scheduled: Promise<void> | undefined\n\n // This function is a wrapper to prevent any of the callback's\n // side effects from causing a subscriber notification\n const untrack = (fn: () => void) => {\n tracking = false\n fn()\n tracking = true\n }\n\n // This function flushes the next update to the browser history\n const flush = () => {\n // Do not notify subscribers about this push/replace call\n untrack(() => {\n if (!next) return\n window.history[next.isPush ? 'pushState' : 'replaceState'](\n next.state,\n '',\n next.href,\n )\n // Reset the nextIsPush flag and clear the scheduled update\n next = undefined\n scheduled = undefined\n })\n }\n\n // This function queues up a call to update the browser history\n const queueHistoryAction = (\n type: 'push' | 'replace',\n path: string,\n state: any,\n onUpdate: () => void,\n ) => {\n const href = createHref(path)\n\n // Update the location in memory\n currentLocation = parseLocation(href, state)\n\n // Keep track of the next location we need to flush to the URL\n next = {\n href,\n state,\n isPush: next?.isPush || type === 'push',\n }\n // Notify subscribers\n onUpdate()\n\n if (!scheduled) {\n // Schedule an update to the browser history\n scheduled = Promise.resolve().then(() => flush())\n }\n }\n\n const onPushPop = () => {\n currentLocation = parseLocation(getHref(), window.history.state)\n history.notify()\n }\n\n var originalPushState = window.history.pushState\n var originalReplaceState = window.history.replaceState\n\n const history = createHistory({\n getLocation,\n pushState: (path, state, onUpdate) =>\n queueHistoryAction('push', path, state, onUpdate),\n replaceState: (path, state, onUpdate) =>\n queueHistoryAction('replace', path, state, onUpdate),\n back: () => window.history.back(),\n forward: () => window.history.forward(),\n go: (n) => window.history.go(n),\n createHref: (path) => createHref(path),\n flush,\n destroy: () => {\n window.history.pushState = originalPushState\n window.history.replaceState = originalReplaceState\n window.removeEventListener(pushStateEvent, onPushPop)\n window.removeEventListener(popStateEvent, onPushPop)\n },\n })\n\n window.addEventListener(pushStateEvent, onPushPop)\n window.addEventListener(popStateEvent, onPushPop)\n\n window.history.pushState = function () {\n let res = originalPushState.apply(window.history, arguments as any)\n if (tracking) history.notify()\n return res\n }\n\n window.history.replaceState = function () {\n let res = originalReplaceState.apply(window.history, arguments as any)\n if (tracking) history.notify()\n return res\n }\n\n return history\n}\n\nexport function createHashHistory(): RouterHistory {\n return createBrowserHistory({\n getHref: () => window.location.hash.substring(1),\n createHref: (path) => `#${path}`,\n })\n}\n\nexport function createMemoryHistory(\n opts: {\n initialEntries: string[]\n initialIndex?: number\n } = {\n initialEntries: ['/'],\n },\n): RouterHistory {\n const entries = opts.initialEntries\n let index = opts.initialIndex ?? entries.length - 1\n let currentState = {\n key: createRandomKey(),\n } as HistoryState\n\n const getLocation = () => parseLocation(entries[index]!, currentState)\n\n return createHistory({\n getLocation,\n pushState: (path, state) => {\n currentState = state\n entries.push(path)\n index++\n },\n replaceState: (path, state) => {\n currentState = state\n entries[index] = path\n },\n back: () => {\n index--\n },\n forward: () => {\n index = Math.min(index + 1, entries.length - 1)\n },\n go: (n) => window.history.go(n),\n createHref: (path) => path,\n })\n}\n\nfunction parseLocation(href: string, state: HistoryState): HistoryLocation {\n let hashIndex = href.indexOf('#')\n let searchIndex = href.indexOf('?')\n\n return {\n href,\n pathname: href.substring(\n 0,\n hashIndex > 0\n ? searchIndex > 0\n ? Math.min(hashIndex, searchIndex)\n : hashIndex\n : searchIndex > 0\n ? searchIndex\n : href.length,\n ),\n hash: hashIndex > -1 ? href.substring(hashIndex) : '',\n search:\n searchIndex > -1\n ? href.slice(searchIndex, hashIndex === -1 ? undefined : hashIndex)\n : '',\n state: state || {},\n }\n}\n\n// Thanks co-pilot!\nfunction createRandomKey() {\n return (Math.random() + 1).toString(36).substring(7)\n}\n"],"names":["pushStateEvent","popStateEvent","beforeUnloadEvent","beforeUnloadListener","event","preventDefault","returnValue","stopBlocking","removeEventListener","capture","createHistory","opts","location","getLocation","subscribers","Set","blockers","queue","onUpdate","forEach","subscriber","tryUnblock","length","shift","queueTask","task","push","subscribe","cb","add","delete","path","state","assignKey","pushState","replace","replaceState","go","index","back","forward","createHref","str","block","addEventListener","filter","b","flush","destroy","notify","key","createRandomKey","createBrowserHistory","getHref","window","pathname","search","hash","currentLocation","parseLocation","history","next","scheduled","tracking","isPush","href","undefined","fn","queueHistoryAction","type","Promise","resolve","then","onPushPop","originalPushState","originalReplaceState","n","res","apply","arguments","hashIndex","indexOf","searchIndex","substring","Math","min","slice","random","toString","initialEntries","entries","initialIndex","currentState"],"mappings":";;;;;;;;;;uPAoCA,MAAMA,EAAiB,YACjBC,EAAgB,WAChBC,EAAoB,eAEpBC,EAAwBC,IAC5BA,EAAMC,iBAEED,EAAME,YAAc,IAGxBC,EAAeA,KACnBC,oBAAoBN,EAAmBC,EAAsB,CAC3DM,SAAS,GACT,EAGJ,SAASC,EAAcC,GAWrB,IAAIC,EAAWD,EAAKE,cAChBC,EAAc,IAAIC,IAClBC,EAAwB,GACxBC,EAAwB,GAE5B,MAAMC,EAAWA,KACfN,EAAWD,EAAKE,cAChBC,EAAYK,SAASC,GAAeA,KAAa,EAG7CC,EAAaA,KACjB,GAAIL,EAASM,OACXN,EAAS,KAAKK,GAAY,KACxBL,EAAW,GACXT,GAAc,SAKlB,KAAOU,EAAMK,QACXL,EAAMM,OAANN,IACF,EAGIO,EAAaC,IACjBR,EAAMS,KAAKD,GACXJ,GAAY,EAGd,MAAO,CACDT,eACF,OAAOA,CACR,EACDe,UAAYC,IACVd,EAAYe,IAAID,GAET,KACLd,EAAYgB,OAAOF,EAAG,GAG1BF,KAAMA,CAACK,EAAcC,KACnBA,EAAQC,EAAUD,GAClBR,GAAU,KACRb,EAAKuB,UAAUH,EAAMC,EAAOd,EAAS,GACrC,EAEJiB,QAASA,CAACJ,EAAcC,KACtBA,EAAQC,EAAUD,GAClBR,GAAU,KACRb,EAAKyB,aAAaL,EAAMC,EAAOd,EAAS,GACxC,EAEJmB,GAAKC,IACHd,GAAU,KACRb,EAAK0B,GAAGC,EAAM,GACd,EAEJC,KAAMA,KACJf,GAAU,KACRb,EAAK4B,MAAM,GACX,EAEJC,QAASA,KACPhB,GAAU,KACRb,EAAK6B,SAAS,GACd,EAEJC,WAAaC,GAAQ/B,EAAK8B,WAAWC,GACrCC,MAAQf,IACNZ,EAASU,KAAKE,GAEU,IAApBZ,EAAS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AAGC,SAAS,IAAIL,UAAU,EACpD,8CAzEO,WACL,OAAO/B,EAAqB,CAC1BC,QAASA,IAAMC,OAAO1C,SAAS6C,KAAK0B,UAAU,GAC9C1C,WAAaV,GAAU,IAAGA,KAE9B,wBAEO,SACLpB,EAGI,CACF8E,eAAgB,CAAC,OAGnB,MAAMC,EAAU/E,EAAK8E,eACrB,IAAInD,EAAQ3B,EAAKgF,cAAgBD,EAAQpE,OAAS,EAC9CsE,EAAe,CACjB1C,IAAKC,KAKP,OAAOzC,EAAc,CACnBG,YAHkBA,IAAM8C,EAAc+B,EAAQpD,GAASsD,GAIvD1D,UAAWA,CAACH,EAAMC,KAChB4D,EAAe5D,EACf0D,EAAQhE,KAAKK,GACbO,GAAO,EAETF,aAAcA,CAACL,EAAMC,KACnB4D,EAAe5D,EACf0D,EAAQpD,GAASP,CAAI,EAEvBQ,KAAMA,KACJD,GAAO,EAETE,QAASA,KACPF,EAAQ8C,KAAKC,IAAI/C,EAAQ,EAAGoD,EAAQpE,OAAS,EAAE,EAEjDe,GAAKuC,GAAMtB,OAAOM,QAAQvB,GAAGuC,GAC7BnC,WAAaV,GAASA,GAE1B"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tanstack/history",
3
3
  "author": "Tanner Linsley",
4
- "version": "0.0.1-beta.211",
4
+ "version": "0.0.1-beta.213",
5
5
  "license": "MIT",
6
6
  "repository": "tanstack/history",
7
7
  "homepage": "https://tanstack.com",
package/src/index.ts CHANGED
@@ -156,8 +156,10 @@ function assignKey(state: HistoryState) {
156
156
  if (!state) {
157
157
  state = {} as HistoryState
158
158
  }
159
- state.key = createRandomKey()
160
- return state
159
+ return {
160
+ ...state,
161
+ key: createRandomKey(),
162
+ }
161
163
  }
162
164
 
163
165
  /**