@tanstack/react-router 0.0.1-beta.266 → 0.0.1-beta.268
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.
- package/build/cjs/RouterProvider.js.map +1 -1
- package/build/cjs/link.js.map +1 -1
- package/build/cjs/router.js.map +1 -1
- package/build/cjs/useBlocker.js +4 -4
- package/build/cjs/useBlocker.js.map +1 -1
- package/build/esm/index.js +4 -4
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +355 -355
- package/build/types/RouterProvider.d.ts +1 -2
- package/build/types/link.d.ts +1 -15
- package/build/types/useBlocker.d.ts +4 -3
- package/build/umd/index.development.js +10 -13
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/RouterProvider.tsx +2 -15
- package/src/link.tsx +1 -19
- package/src/router.ts +0 -1
- package/src/useBlocker.tsx +6 -5
- package/build/types/injectHtml.d.ts +0 -0
- package/src/injectHtml.ts +0 -28
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { NavigateOptions, ResolveRelativePath, ToOptions } from './link';
|
|
3
3
|
import { ParsedLocation } from './location';
|
|
4
4
|
import { AnyRoute } from './route';
|
|
5
5
|
import { RouteById, RoutePaths } from './routeInfo';
|
|
@@ -18,7 +18,6 @@ export interface MatchLocation {
|
|
|
18
18
|
caseSensitive?: boolean;
|
|
19
19
|
from?: string;
|
|
20
20
|
}
|
|
21
|
-
export type BuildLinkFn<TRouteTree extends AnyRoute> = <TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = ''>(dest: LinkOptions<TRouteTree, TFrom, TTo>) => LinkInfo;
|
|
22
21
|
export type NavigateFn<TRouteTree extends AnyRoute> = <TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = TFrom, TMaskTo extends string = ''>(opts: NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>) => Promise<void>;
|
|
23
22
|
export type MatchRouteFn<TRouteTree extends AnyRoute> = <TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>>(location: ToOptions<TRouteTree, TFrom, TTo>, opts?: MatchRouteOptions) => false | RouteById<TRouteTree, TResolved>['types']['allParams'];
|
|
24
23
|
export type BuildLocationFn<TRouteTree extends AnyRoute> = (opts: BuildNextOptions) => ParsedLocation;
|
package/build/types/link.d.ts
CHANGED
|
@@ -1,25 +1,11 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { Trim } from './fileRoute';
|
|
3
|
-
import { LocationState
|
|
3
|
+
import { LocationState } from './location';
|
|
4
4
|
import { AnyRoute, ReactNode } from './route';
|
|
5
5
|
import { AllParams, FullSearchSchema, RouteByPath, RouteIds, RoutePaths } from './routeInfo';
|
|
6
6
|
import { RegisteredRouter } from './router';
|
|
7
7
|
import { MakeLinkOptions, MakeLinkPropsOptions } from './useNavigate';
|
|
8
8
|
import { Expand, NoInfer, NonNullableUpdater, PickRequired, UnionToIntersection, Updater } from './utils';
|
|
9
|
-
export type LinkInfo = {
|
|
10
|
-
type: 'external';
|
|
11
|
-
href: string;
|
|
12
|
-
} | {
|
|
13
|
-
type: 'internal';
|
|
14
|
-
next: ParsedLocation;
|
|
15
|
-
handleFocus: (e: any) => void;
|
|
16
|
-
handleClick: (e: any) => void;
|
|
17
|
-
handleEnter: (e: any) => void;
|
|
18
|
-
handleLeave: (e: any) => void;
|
|
19
|
-
handleTouchStart: (e: any) => void;
|
|
20
|
-
isActive: boolean;
|
|
21
|
-
disabled?: boolean;
|
|
22
|
-
};
|
|
23
9
|
export type CleanPath<T extends string> = T extends `${infer L}//${infer R}` ? CleanPath<`${CleanPath<L>}/${CleanPath<R>}`> : T extends `${infer L}//` ? `${CleanPath<L>}/` : T extends `//${infer L}` ? `/${CleanPath<L>}` : T;
|
|
24
10
|
export type Split<S, TIncludeTrailingSlash = true> = S extends unknown ? string extends S ? string[] : S extends string ? CleanPath<S> extends '' ? [] : TIncludeTrailingSlash extends true ? CleanPath<S> extends `${infer T}/` ? [...Split<T>, '/'] : CleanPath<S> extends `/${infer U}` ? Split<U> : CleanPath<S> extends `${infer T}/${infer U}` ? [...Split<T>, ...Split<U>] : [S] : CleanPath<S> extends `${infer T}/${infer U}` ? [...Split<T>, ...Split<U>] : S extends string ? [S] : never : never : never;
|
|
25
11
|
export type ParsePathParams<T extends string> = keyof {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ReactNode } from './route';
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
2
|
+
import { BlockerFn } from '@tanstack/history';
|
|
3
|
+
export declare function useBlocker(blockerFn: BlockerFn, condition?: boolean | any): void;
|
|
4
|
+
export declare function Block({ blocker, condition, children }: PromptProps): any;
|
|
4
5
|
export type PromptProps = {
|
|
5
|
-
|
|
6
|
+
blocker: BlockerFn;
|
|
6
7
|
condition?: boolean | any;
|
|
7
8
|
children?: ReactNode;
|
|
8
9
|
};
|
|
@@ -68,10 +68,11 @@
|
|
|
68
68
|
location = opts.getLocation();
|
|
69
69
|
subscribers.forEach(subscriber => subscriber());
|
|
70
70
|
};
|
|
71
|
-
const tryNavigation = task => {
|
|
71
|
+
const tryNavigation = async task => {
|
|
72
72
|
if (typeof document !== 'undefined' && blockers.length) {
|
|
73
73
|
for (let blocker of blockers) {
|
|
74
|
-
|
|
74
|
+
const allowed = await blocker();
|
|
75
|
+
if (!allowed) {
|
|
75
76
|
opts.onBlocked?.(onUpdate);
|
|
76
77
|
return;
|
|
77
78
|
}
|
|
@@ -117,18 +118,15 @@
|
|
|
117
118
|
});
|
|
118
119
|
},
|
|
119
120
|
createHref: str => opts.createHref(str),
|
|
120
|
-
block:
|
|
121
|
-
|
|
122
|
-
message
|
|
123
|
-
};
|
|
124
|
-
blockers.push(payload);
|
|
121
|
+
block: blocker => {
|
|
122
|
+
blockers.push(blocker);
|
|
125
123
|
if (blockers.length === 1) {
|
|
126
124
|
addEventListener(beforeUnloadEvent, beforeUnloadListener, {
|
|
127
125
|
capture: true
|
|
128
126
|
});
|
|
129
127
|
}
|
|
130
128
|
return () => {
|
|
131
|
-
blockers = blockers.filter(b => b !==
|
|
129
|
+
blockers = blockers.filter(b => b !== blocker);
|
|
132
130
|
if (!blockers.length) {
|
|
133
131
|
stopBlocking();
|
|
134
132
|
}
|
|
@@ -280,7 +278,6 @@
|
|
|
280
278
|
window: win,
|
|
281
279
|
parseLocation: () => {
|
|
282
280
|
const hashHref = win.location.hash.split('#').slice(1).join('#') ?? '/';
|
|
283
|
-
console.log(hashHref);
|
|
284
281
|
return parseHref(hashHref, win.history.state);
|
|
285
282
|
},
|
|
286
283
|
createHref: href => `${win.location.pathname}${win.location.search}#${href}`
|
|
@@ -3155,21 +3152,21 @@
|
|
|
3155
3152
|
return `${path.join(' > ')}`.toLowerCase();
|
|
3156
3153
|
}
|
|
3157
3154
|
|
|
3158
|
-
function useBlocker(
|
|
3155
|
+
function useBlocker(blockerFn, condition = true) {
|
|
3159
3156
|
const {
|
|
3160
3157
|
history
|
|
3161
3158
|
} = useRouter();
|
|
3162
3159
|
React__namespace.useEffect(() => {
|
|
3163
3160
|
if (!condition) return;
|
|
3164
|
-
return history.block(
|
|
3161
|
+
return history.block(blockerFn);
|
|
3165
3162
|
});
|
|
3166
3163
|
}
|
|
3167
3164
|
function Block({
|
|
3168
|
-
|
|
3165
|
+
blocker,
|
|
3169
3166
|
condition,
|
|
3170
3167
|
children
|
|
3171
3168
|
}) {
|
|
3172
|
-
useBlocker(
|
|
3169
|
+
useBlocker(blocker, condition);
|
|
3173
3170
|
return children ?? null;
|
|
3174
3171
|
}
|
|
3175
3172
|
|