@tanstack/history
Advanced tools
+11
-8
@@ -9,5 +9,7 @@ "use strict"; | ||
| const subscribers = /* @__PURE__ */ new Set(); | ||
| const notify = (action) => { | ||
| const notify = (action, navigateOpts) => { | ||
| location = opts.getLocation(); | ||
| subscribers.forEach((subscriber) => subscriber({ location, action })); | ||
| subscribers.forEach( | ||
| (subscriber) => subscriber({ location, action, navigateOpts }) | ||
| ); | ||
| }; | ||
@@ -26,3 +28,3 @@ const handleIndexChange = (action) => { | ||
| task(); | ||
| return; | ||
| return { type: "SUCCESS" }; | ||
| } | ||
@@ -41,3 +43,3 @@ const blockers = opts.getBlockers?.() ?? []; | ||
| opts.onBlocked?.(); | ||
| return; | ||
| return { type: "BLOCKED" }; | ||
| } | ||
@@ -47,2 +49,3 @@ } | ||
| task(); | ||
| return { type: "SUCCESS" }; | ||
| }; | ||
@@ -66,6 +69,6 @@ return { | ||
| state = assignKeyAndIndex(currentIndex + 1, state); | ||
| tryNavigation({ | ||
| return tryNavigation({ | ||
| task: () => { | ||
| opts.pushState(path, state); | ||
| notify({ type: "PUSH" }); | ||
| notify({ type: "PUSH" }, navigateOpts); | ||
| }, | ||
@@ -81,6 +84,6 @@ navigateOpts, | ||
| state = assignKeyAndIndex(currentIndex, state); | ||
| tryNavigation({ | ||
| return tryNavigation({ | ||
| task: () => { | ||
| opts.replaceState(path, state); | ||
| notify({ type: "REPLACE" }); | ||
| notify({ type: "REPLACE" }, navigateOpts); | ||
| }, | ||
@@ -87,0 +90,0 @@ navigateOpts, |
+27
-3
| export interface NavigateOptions { | ||
| ignoreBlocker?: boolean; | ||
| /** When true, Transitioner should skip calling load() - commitLocation handles it */ | ||
| skipTransitionerLoad?: boolean; | ||
| } | ||
| /** Result of a navigation attempt (push/replace) */ | ||
| export type NavigationResult = { | ||
| type: 'SUCCESS'; | ||
| } | { | ||
| type: 'BLOCKED'; | ||
| }; | ||
| type SubscriberHistoryAction = { | ||
@@ -10,5 +18,6 @@ type: Exclude<HistoryAction, 'GO'>; | ||
| }; | ||
| type SubscriberArgs = { | ||
| export type SubscriberArgs = { | ||
| location: HistoryLocation; | ||
| action: SubscriberHistoryAction; | ||
| navigateOpts?: NavigateOptions; | ||
| }; | ||
@@ -20,4 +29,4 @@ export interface RouterHistory { | ||
| subscribe: (cb: (opts: SubscriberArgs) => void) => () => void; | ||
| push: (path: string, state?: any, navigateOpts?: NavigateOptions) => void; | ||
| replace: (path: string, state?: any, navigateOpts?: NavigateOptions) => void; | ||
| push: (path: string, state?: any, navigateOpts?: NavigateOptions) => Promise<NavigationResult>; | ||
| replace: (path: string, state?: any, navigateOpts?: NavigateOptions) => Promise<NavigationResult>; | ||
| go: (index: number, navigateOpts?: NavigateOptions) => void; | ||
@@ -49,2 +58,17 @@ back: (navigateOpts?: NavigateOptions) => void; | ||
| __TSR_index: number; | ||
| /** Whether to reset scroll position on this navigation (default: true) */ | ||
| __TSR_resetScroll?: boolean; | ||
| /** Session id for cached TSR internals */ | ||
| __TSR_sessionId?: string; | ||
| /** Match snapshot for fast-path on back/forward navigation */ | ||
| __TSR_matches?: { | ||
| routeIds: Array<string>; | ||
| params: Record<string, string>; | ||
| globalNotFoundRouteId?: string; | ||
| searchStr?: string; | ||
| validatedSearches?: Array<{ | ||
| search: Record<string, unknown>; | ||
| strictSearch: Record<string, unknown>; | ||
| }>; | ||
| }; | ||
| }; | ||
@@ -51,0 +75,0 @@ type ShouldAllowNavigation = any; |
+27
-3
| export interface NavigateOptions { | ||
| ignoreBlocker?: boolean; | ||
| /** When true, Transitioner should skip calling load() - commitLocation handles it */ | ||
| skipTransitionerLoad?: boolean; | ||
| } | ||
| /** Result of a navigation attempt (push/replace) */ | ||
| export type NavigationResult = { | ||
| type: 'SUCCESS'; | ||
| } | { | ||
| type: 'BLOCKED'; | ||
| }; | ||
| type SubscriberHistoryAction = { | ||
@@ -10,5 +18,6 @@ type: Exclude<HistoryAction, 'GO'>; | ||
| }; | ||
| type SubscriberArgs = { | ||
| export type SubscriberArgs = { | ||
| location: HistoryLocation; | ||
| action: SubscriberHistoryAction; | ||
| navigateOpts?: NavigateOptions; | ||
| }; | ||
@@ -20,4 +29,4 @@ export interface RouterHistory { | ||
| subscribe: (cb: (opts: SubscriberArgs) => void) => () => void; | ||
| push: (path: string, state?: any, navigateOpts?: NavigateOptions) => void; | ||
| replace: (path: string, state?: any, navigateOpts?: NavigateOptions) => void; | ||
| push: (path: string, state?: any, navigateOpts?: NavigateOptions) => Promise<NavigationResult>; | ||
| replace: (path: string, state?: any, navigateOpts?: NavigateOptions) => Promise<NavigationResult>; | ||
| go: (index: number, navigateOpts?: NavigateOptions) => void; | ||
@@ -49,2 +58,17 @@ back: (navigateOpts?: NavigateOptions) => void; | ||
| __TSR_index: number; | ||
| /** Whether to reset scroll position on this navigation (default: true) */ | ||
| __TSR_resetScroll?: boolean; | ||
| /** Session id for cached TSR internals */ | ||
| __TSR_sessionId?: string; | ||
| /** Match snapshot for fast-path on back/forward navigation */ | ||
| __TSR_matches?: { | ||
| routeIds: Array<string>; | ||
| params: Record<string, string>; | ||
| globalNotFoundRouteId?: string; | ||
| searchStr?: string; | ||
| validatedSearches?: Array<{ | ||
| search: Record<string, unknown>; | ||
| strictSearch: Record<string, unknown>; | ||
| }>; | ||
| }; | ||
| }; | ||
@@ -51,0 +75,0 @@ type ShouldAllowNavigation = any; |
+11
-8
@@ -7,5 +7,7 @@ const stateIndexKey = "__TSR_index"; | ||
| const subscribers = /* @__PURE__ */ new Set(); | ||
| const notify = (action) => { | ||
| const notify = (action, navigateOpts) => { | ||
| location = opts.getLocation(); | ||
| subscribers.forEach((subscriber) => subscriber({ location, action })); | ||
| subscribers.forEach( | ||
| (subscriber) => subscriber({ location, action, navigateOpts }) | ||
| ); | ||
| }; | ||
@@ -24,3 +26,3 @@ const handleIndexChange = (action) => { | ||
| task(); | ||
| return; | ||
| return { type: "SUCCESS" }; | ||
| } | ||
@@ -39,3 +41,3 @@ const blockers = opts.getBlockers?.() ?? []; | ||
| opts.onBlocked?.(); | ||
| return; | ||
| return { type: "BLOCKED" }; | ||
| } | ||
@@ -45,2 +47,3 @@ } | ||
| task(); | ||
| return { type: "SUCCESS" }; | ||
| }; | ||
@@ -64,6 +67,6 @@ return { | ||
| state = assignKeyAndIndex(currentIndex + 1, state); | ||
| tryNavigation({ | ||
| return tryNavigation({ | ||
| task: () => { | ||
| opts.pushState(path, state); | ||
| notify({ type: "PUSH" }); | ||
| notify({ type: "PUSH" }, navigateOpts); | ||
| }, | ||
@@ -79,6 +82,6 @@ navigateOpts, | ||
| state = assignKeyAndIndex(currentIndex, state); | ||
| tryNavigation({ | ||
| return tryNavigation({ | ||
| task: () => { | ||
| opts.replaceState(path, state); | ||
| notify({ type: "REPLACE" }); | ||
| notify({ type: "REPLACE" }, navigateOpts); | ||
| }, | ||
@@ -85,0 +88,0 @@ navigateOpts, |
+1
-1
| { | ||
| "name": "@tanstack/history", | ||
| "version": "1.151.1", | ||
| "version": "1.153.2", | ||
| "description": "Modern and scalable routing for React applications", | ||
@@ -5,0 +5,0 @@ "author": "Tanner Linsley", |
+47
-12
@@ -7,4 +7,9 @@ // While the public API was clearly inspired by the "history" npm package, | ||
| ignoreBlocker?: boolean | ||
| /** When true, Transitioner should skip calling load() - commitLocation handles it */ | ||
| skipTransitionerLoad?: boolean | ||
| } | ||
| /** Result of a navigation attempt (push/replace) */ | ||
| export type NavigationResult = { type: 'SUCCESS' } | { type: 'BLOCKED' } | ||
| type SubscriberHistoryAction = | ||
@@ -19,5 +24,6 @@ | { | ||
| type SubscriberArgs = { | ||
| export type SubscriberArgs = { | ||
| location: HistoryLocation | ||
| action: SubscriberHistoryAction | ||
| navigateOpts?: NavigateOptions | ||
| } | ||
@@ -30,4 +36,12 @@ | ||
| subscribe: (cb: (opts: SubscriberArgs) => void) => () => void | ||
| push: (path: string, state?: any, navigateOpts?: NavigateOptions) => void | ||
| replace: (path: string, state?: any, navigateOpts?: NavigateOptions) => void | ||
| push: ( | ||
| path: string, | ||
| state?: any, | ||
| navigateOpts?: NavigateOptions, | ||
| ) => Promise<NavigationResult> | ||
| replace: ( | ||
| path: string, | ||
| state?: any, | ||
| navigateOpts?: NavigateOptions, | ||
| ) => Promise<NavigationResult> | ||
| go: (index: number, navigateOpts?: NavigateOptions) => void | ||
@@ -62,2 +76,17 @@ back: (navigateOpts?: NavigateOptions) => void | ||
| __TSR_index: number | ||
| /** Whether to reset scroll position on this navigation (default: true) */ | ||
| __TSR_resetScroll?: boolean | ||
| /** Session id for cached TSR internals */ | ||
| __TSR_sessionId?: string | ||
| /** Match snapshot for fast-path on back/forward navigation */ | ||
| __TSR_matches?: { | ||
| routeIds: Array<string> | ||
| params: Record<string, string> | ||
| globalNotFoundRouteId?: string | ||
| searchStr?: string | ||
| validatedSearches?: Array<{ | ||
| search: Record<string, unknown> | ||
| strictSearch: Record<string, unknown> | ||
| }> | ||
| } | ||
| } | ||
@@ -123,5 +152,10 @@ | ||
| const notify = (action: SubscriberHistoryAction) => { | ||
| const notify = ( | ||
| action: SubscriberHistoryAction, | ||
| navigateOpts?: NavigateOptions, | ||
| ) => { | ||
| location = opts.getLocation() | ||
| subscribers.forEach((subscriber) => subscriber({ location, action })) | ||
| subscribers.forEach((subscriber) => | ||
| subscriber({ location, action, navigateOpts }), | ||
| ) | ||
| } | ||
@@ -138,7 +172,7 @@ | ||
| ...actionInfo | ||
| }: TryNavigateArgs) => { | ||
| }: TryNavigateArgs): Promise<NavigationResult> => { | ||
| const ignoreBlocker = navigateOpts?.ignoreBlocker ?? false | ||
| if (ignoreBlocker) { | ||
| task() | ||
| return | ||
| return { type: 'SUCCESS' } | ||
| } | ||
@@ -159,3 +193,3 @@ | ||
| opts.onBlocked?.() | ||
| return | ||
| return { type: 'BLOCKED' } | ||
| } | ||
@@ -166,2 +200,3 @@ } | ||
| task() | ||
| return { type: 'SUCCESS' } | ||
| } | ||
@@ -187,6 +222,6 @@ | ||
| state = assignKeyAndIndex(currentIndex + 1, state) | ||
| tryNavigation({ | ||
| return tryNavigation({ | ||
| task: () => { | ||
| opts.pushState(path, state) | ||
| notify({ type: 'PUSH' }) | ||
| notify({ type: 'PUSH' }, navigateOpts) | ||
| }, | ||
@@ -202,6 +237,6 @@ navigateOpts, | ||
| state = assignKeyAndIndex(currentIndex, state) | ||
| tryNavigation({ | ||
| return tryNavigation({ | ||
| task: () => { | ||
| opts.replaceState(path, state) | ||
| notify({ type: 'REPLACE' }) | ||
| notify({ type: 'REPLACE' }, navigateOpts) | ||
| }, | ||
@@ -208,0 +243,0 @@ navigateOpts, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
122160
4.89%1645
4.05%