@tanstack/react-router 1.34.6 → 1.34.9
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/dist/cjs/Matches.cjs.map +1 -1
- package/dist/cjs/Matches.d.cts +1 -1
- package/dist/cjs/fileRoute.cjs.map +1 -1
- package/dist/cjs/fileRoute.d.cts +2 -2
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +6 -6
- package/dist/cjs/useBlocker.cjs +15 -14
- package/dist/cjs/useBlocker.cjs.map +1 -1
- package/dist/esm/Matches.d.ts +1 -1
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/fileRoute.d.ts +2 -2
- package/dist/esm/fileRoute.js.map +1 -1
- package/dist/esm/route.d.ts +6 -6
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/useBlocker.js +15 -14
- package/dist/esm/useBlocker.js.map +1 -1
- package/package.json +1 -1
- package/src/Matches.tsx +1 -1
- package/src/fileRoute.ts +1 -1
- package/src/route.ts +6 -6
- package/src/useBlocker.tsx +14 -17
package/dist/esm/useBlocker.js
CHANGED
|
@@ -13,29 +13,30 @@ function useBlocker(blockerFnOrOpts, condition) {
|
|
|
13
13
|
reset: () => {
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
|
-
const createPromise = () => new Promise((resolve) => {
|
|
17
|
-
setResolver({
|
|
18
|
-
status: "idle",
|
|
19
|
-
proceed: () => resolve(true),
|
|
20
|
-
reset: () => resolve(false)
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
const [promise, setPromise] = React.useState(createPromise);
|
|
24
16
|
React.useEffect(() => {
|
|
25
17
|
const blockerFnComposed = async () => {
|
|
26
18
|
if (blockerFn) {
|
|
27
19
|
return await blockerFn();
|
|
28
20
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
21
|
+
const promise = new Promise((resolve) => {
|
|
22
|
+
setResolver({
|
|
23
|
+
status: "blocked",
|
|
24
|
+
proceed: () => resolve(true),
|
|
25
|
+
reset: () => resolve(false)
|
|
26
|
+
});
|
|
27
|
+
});
|
|
33
28
|
const canNavigateAsync = await promise;
|
|
34
|
-
|
|
29
|
+
setResolver({
|
|
30
|
+
status: "idle",
|
|
31
|
+
proceed: () => {
|
|
32
|
+
},
|
|
33
|
+
reset: () => {
|
|
34
|
+
}
|
|
35
|
+
});
|
|
35
36
|
return canNavigateAsync;
|
|
36
37
|
};
|
|
37
38
|
return !blockerCondition ? void 0 : history.block(blockerFnComposed);
|
|
38
|
-
}, [blockerFn, blockerCondition, history
|
|
39
|
+
}, [blockerFn, blockerCondition, history]);
|
|
39
40
|
return resolver;
|
|
40
41
|
}
|
|
41
42
|
function Block({ blockerFn, condition, children }) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBlocker.js","sources":["../../src/useBlocker.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useRouter } from './useRouter'\nimport type { BlockerFn } from '@tanstack/history'\nimport type { ReactNode } from './route'\n\ntype BlockerResolver = {\n status: 'idle' | 'blocked'\n proceed: () => void\n reset: () => void\n}\n\ntype BlockerOpts = {\n blockerFn?: BlockerFn\n condition?: boolean | any\n}\n\nexport function useBlocker(blockerFnOrOpts?: BlockerOpts): BlockerResolver\n\n/**\n * @deprecated Use the BlockerOpts object syntax instead\n */\nexport function useBlocker(\n blockerFn?: BlockerFn,\n condition?: boolean | any,\n): BlockerResolver\n\nexport function useBlocker(\n blockerFnOrOpts?: BlockerFn | BlockerOpts,\n condition?: boolean | any,\n): BlockerResolver {\n const { blockerFn, blockerCondition } = blockerFnOrOpts\n ? typeof blockerFnOrOpts === 'function'\n ? { blockerFn: blockerFnOrOpts, blockerCondition: condition ?? true }\n : {\n blockerFn: blockerFnOrOpts.blockerFn,\n blockerCondition: blockerFnOrOpts.condition ?? true,\n }\n : { blockerFn: undefined, blockerCondition: condition ?? true }\n const { history } = useRouter()\n\n const [resolver, setResolver] = React.useState<BlockerResolver>({\n status: 'idle',\n proceed: () => {},\n reset: () => {},\n })\n\n
|
|
1
|
+
{"version":3,"file":"useBlocker.js","sources":["../../src/useBlocker.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useRouter } from './useRouter'\nimport type { BlockerFn } from '@tanstack/history'\nimport type { ReactNode } from './route'\n\ntype BlockerResolver = {\n status: 'idle' | 'blocked'\n proceed: () => void\n reset: () => void\n}\n\ntype BlockerOpts = {\n blockerFn?: BlockerFn\n condition?: boolean | any\n}\n\nexport function useBlocker(blockerFnOrOpts?: BlockerOpts): BlockerResolver\n\n/**\n * @deprecated Use the BlockerOpts object syntax instead\n */\nexport function useBlocker(\n blockerFn?: BlockerFn,\n condition?: boolean | any,\n): BlockerResolver\n\nexport function useBlocker(\n blockerFnOrOpts?: BlockerFn | BlockerOpts,\n condition?: boolean | any,\n): BlockerResolver {\n const { blockerFn, blockerCondition } = blockerFnOrOpts\n ? typeof blockerFnOrOpts === 'function'\n ? { blockerFn: blockerFnOrOpts, blockerCondition: condition ?? true }\n : {\n blockerFn: blockerFnOrOpts.blockerFn,\n blockerCondition: blockerFnOrOpts.condition ?? true,\n }\n : { blockerFn: undefined, blockerCondition: condition ?? true }\n const { history } = useRouter()\n\n const [resolver, setResolver] = React.useState<BlockerResolver>({\n status: 'idle',\n proceed: () => {},\n reset: () => {},\n })\n\n React.useEffect(() => {\n const blockerFnComposed = async () => {\n // If a function is provided, it takes precedence over the promise blocker\n if (blockerFn) {\n return await blockerFn()\n }\n\n const promise = new Promise<boolean>((resolve) => {\n setResolver({\n status: 'blocked',\n proceed: () => resolve(true),\n reset: () => resolve(false),\n })\n })\n\n const canNavigateAsync = await promise\n\n setResolver({\n status: 'idle',\n proceed: () => {},\n reset: () => {},\n })\n\n return canNavigateAsync\n }\n\n return !blockerCondition ? undefined : history.block(blockerFnComposed)\n }, [blockerFn, blockerCondition, history])\n\n return resolver\n}\n\nexport function Block({ blockerFn, condition, children }: PromptProps) {\n const resolver = useBlocker({ blockerFn, condition })\n return children\n ? typeof children === 'function'\n ? children(resolver)\n : children\n : null\n}\n\nexport type PromptProps = {\n blockerFn?: BlockerFn\n condition?: boolean | any\n children?: ReactNode | (({ proceed, reset }: BlockerResolver) => ReactNode)\n}\n"],"names":[],"mappings":";;AA0BgB,SAAA,WACd,iBACA,WACiB;AACjB,QAAM,EAAE,WAAW,qBAAqB,kBACpC,OAAO,oBAAoB,aACzB,EAAE,WAAW,iBAAiB,kBAAkB,aAAa,SAC7D;AAAA,IACE,WAAW,gBAAgB;AAAA,IAC3B,kBAAkB,gBAAgB,aAAa;AAAA,EAAA,IAEnD,EAAE,WAAW,QAAW,kBAAkB,aAAa;AACrD,QAAA,EAAE,YAAY;AAEpB,QAAM,CAAC,UAAU,WAAW,IAAI,MAAM,SAA0B;AAAA,IAC9D,QAAQ;AAAA,IACR,SAAS,MAAM;AAAA,IAAC;AAAA,IAChB,OAAO,MAAM;AAAA,IAAC;AAAA,EAAA,CACf;AAED,QAAM,UAAU,MAAM;AACpB,UAAM,oBAAoB,YAAY;AAEpC,UAAI,WAAW;AACb,eAAO,MAAM,UAAU;AAAA,MACzB;AAEA,YAAM,UAAU,IAAI,QAAiB,CAAC,YAAY;AACpC,oBAAA;AAAA,UACV,QAAQ;AAAA,UACR,SAAS,MAAM,QAAQ,IAAI;AAAA,UAC3B,OAAO,MAAM,QAAQ,KAAK;AAAA,QAAA,CAC3B;AAAA,MAAA,CACF;AAED,YAAM,mBAAmB,MAAM;AAEnB,kBAAA;AAAA,QACV,QAAQ;AAAA,QACR,SAAS,MAAM;AAAA,QAAC;AAAA,QAChB,OAAO,MAAM;AAAA,QAAC;AAAA,MAAA,CACf;AAEM,aAAA;AAAA,IAAA;AAGT,WAAO,CAAC,mBAAmB,SAAY,QAAQ,MAAM,iBAAiB;AAAA,EACrE,GAAA,CAAC,WAAW,kBAAkB,OAAO,CAAC;AAElC,SAAA;AACT;AAEO,SAAS,MAAM,EAAE,WAAW,WAAW,YAAyB;AACrE,QAAM,WAAW,WAAW,EAAE,WAAW,UAAW,CAAA;AACpD,SAAO,WACH,OAAO,aAAa,aAClB,SAAS,QAAQ,IACjB,WACF;AACN;"}
|
package/package.json
CHANGED
package/src/Matches.tsx
CHANGED
|
@@ -499,7 +499,7 @@ export function useMatchRoute<TRouter extends AnyRouter = RegisteredRouter>() {
|
|
|
499
499
|
opts: UseMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,
|
|
500
500
|
):
|
|
501
501
|
| false
|
|
502
|
-
|
|
|
502
|
+
| RouteByPath<TRouter['routeTree'], TResolved>['types']['allParams'] => {
|
|
503
503
|
const { pending, caseSensitive, fuzzy, includeSearch, ...rest } = opts
|
|
504
504
|
|
|
505
505
|
return router.matchRoute(rest as any, {
|
package/src/fileRoute.ts
CHANGED
package/src/route.ts
CHANGED
|
@@ -59,7 +59,7 @@ export type RouteOptions<
|
|
|
59
59
|
TParentRoute extends AnyRoute = AnyRoute,
|
|
60
60
|
TCustomId extends string = string,
|
|
61
61
|
TPath extends string = string,
|
|
62
|
-
TSearchSchemaInput =
|
|
62
|
+
TSearchSchemaInput = Record<string, unknown>,
|
|
63
63
|
TSearchSchema = {},
|
|
64
64
|
TSearchSchemaUsed = {},
|
|
65
65
|
TFullSearchSchemaInput = TSearchSchemaUsed,
|
|
@@ -109,7 +109,7 @@ export type ParamsFallback<
|
|
|
109
109
|
export type FileBaseRouteOptions<
|
|
110
110
|
TParentRoute extends AnyRoute = AnyRoute,
|
|
111
111
|
TPath extends string = string,
|
|
112
|
-
TSearchSchemaInput =
|
|
112
|
+
TSearchSchemaInput = Record<string, unknown>,
|
|
113
113
|
TSearchSchema = {},
|
|
114
114
|
TFullSearchSchema = TSearchSchema,
|
|
115
115
|
TParams = {},
|
|
@@ -173,7 +173,7 @@ export type BaseRouteOptions<
|
|
|
173
173
|
TParentRoute extends AnyRoute = AnyRoute,
|
|
174
174
|
TCustomId extends string = string,
|
|
175
175
|
TPath extends string = string,
|
|
176
|
-
TSearchSchemaInput =
|
|
176
|
+
TSearchSchemaInput = Record<string, unknown>,
|
|
177
177
|
TSearchSchema = {},
|
|
178
178
|
TSearchSchemaUsed = {},
|
|
179
179
|
TFullSearchSchemaInput = TSearchSchemaUsed,
|
|
@@ -603,7 +603,7 @@ export class Route<
|
|
|
603
603
|
TCustomId,
|
|
604
604
|
TPath
|
|
605
605
|
>,
|
|
606
|
-
in out TSearchSchemaInput =
|
|
606
|
+
in out TSearchSchemaInput = Record<string, unknown>,
|
|
607
607
|
in out TSearchSchema = {},
|
|
608
608
|
in out TSearchSchemaUsed = ResolveSearchSchemaUsed<
|
|
609
609
|
TSearchSchemaInput,
|
|
@@ -948,7 +948,7 @@ export function createRoute<
|
|
|
948
948
|
TCustomId,
|
|
949
949
|
TPath
|
|
950
950
|
>,
|
|
951
|
-
TSearchSchemaInput =
|
|
951
|
+
TSearchSchemaInput = Record<string, unknown>,
|
|
952
952
|
TSearchSchema = {},
|
|
953
953
|
TSearchSchemaUsed = ResolveSearchSchemaUsed<
|
|
954
954
|
TSearchSchemaInput,
|
|
@@ -1306,7 +1306,7 @@ export type NotFoundRouteComponent = SyncRouteComponent<NotFoundRouteProps>
|
|
|
1306
1306
|
|
|
1307
1307
|
export class NotFoundRoute<
|
|
1308
1308
|
TParentRoute extends AnyRootRoute,
|
|
1309
|
-
TSearchSchemaInput
|
|
1309
|
+
TSearchSchemaInput = Record<string, unknown>,
|
|
1310
1310
|
TSearchSchema = {},
|
|
1311
1311
|
TSearchSchemaUsed = {},
|
|
1312
1312
|
TFullSearchSchemaInput = ResolveFullSearchSchemaInput<
|
package/src/useBlocker.tsx
CHANGED
|
@@ -44,17 +44,6 @@ export function useBlocker(
|
|
|
44
44
|
reset: () => {},
|
|
45
45
|
})
|
|
46
46
|
|
|
47
|
-
const createPromise = () =>
|
|
48
|
-
new Promise<boolean>((resolve) => {
|
|
49
|
-
setResolver({
|
|
50
|
-
status: 'idle',
|
|
51
|
-
proceed: () => resolve(true),
|
|
52
|
-
reset: () => resolve(false),
|
|
53
|
-
})
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
const [promise, setPromise] = React.useState(createPromise)
|
|
57
|
-
|
|
58
47
|
React.useEffect(() => {
|
|
59
48
|
const blockerFnComposed = async () => {
|
|
60
49
|
// If a function is provided, it takes precedence over the promise blocker
|
|
@@ -62,19 +51,27 @@ export function useBlocker(
|
|
|
62
51
|
return await blockerFn()
|
|
63
52
|
}
|
|
64
53
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
54
|
+
const promise = new Promise<boolean>((resolve) => {
|
|
55
|
+
setResolver({
|
|
56
|
+
status: 'blocked',
|
|
57
|
+
proceed: () => resolve(true),
|
|
58
|
+
reset: () => resolve(false),
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
|
|
69
62
|
const canNavigateAsync = await promise
|
|
70
63
|
|
|
71
|
-
|
|
64
|
+
setResolver({
|
|
65
|
+
status: 'idle',
|
|
66
|
+
proceed: () => {},
|
|
67
|
+
reset: () => {},
|
|
68
|
+
})
|
|
72
69
|
|
|
73
70
|
return canNavigateAsync
|
|
74
71
|
}
|
|
75
72
|
|
|
76
73
|
return !blockerCondition ? undefined : history.block(blockerFnComposed)
|
|
77
|
-
}, [blockerFn, blockerCondition, history
|
|
74
|
+
}, [blockerFn, blockerCondition, history])
|
|
78
75
|
|
|
79
76
|
return resolver
|
|
80
77
|
}
|