@octanejs/tanstack-router 0.1.10 → 0.1.12
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/README.md +24 -11
- package/package.json +26 -11
- package/src/Asset.tsrx +122 -0
- package/src/Asset.tsrx.d.ts +9 -0
- package/src/Await.tsrx +2 -1
- package/src/Await.tsrx.d.ts +8 -6
- package/src/Body.ts +31 -0
- package/src/CatchBoundary.tsrx +1 -3
- package/src/ClientOnly.tsrx +4 -2
- package/src/Head.ts +22 -0
- package/src/HeadContent.tsrx +41 -0
- package/src/HeadContent.tsrx.d.ts +8 -0
- package/src/Html.ts +19 -0
- package/src/Link.tsrx +25 -7
- package/src/Link.tsrx.d.ts +3 -4
- package/src/Match.tsrx +40 -13
- package/src/Matches.tsrx +7 -7
- package/src/Outlet.tsrx +3 -3
- package/src/RouteNotFound.tsrx +1 -1
- package/src/RouterProvider.tsrx +2 -1
- package/src/ScriptOnce.tsrx +23 -0
- package/src/ScriptOnce.tsrx.d.ts +3 -0
- package/src/Scripts.tsrx +42 -0
- package/src/Scripts.tsrx.d.ts +3 -0
- package/src/Transitioner.tsrx +15 -13
- package/src/assetKeys.ts +11 -0
- package/src/context.ts +6 -3
- package/src/externalHydration.ts +77 -0
- package/src/fileRoute.ts +277 -0
- package/src/frameworkTypes.ts +42 -0
- package/src/generator-plugin.d.ts +20 -0
- package/src/generator-plugin.js +108 -0
- package/src/headContentUtils.ts +172 -0
- package/src/hooks.ts +151 -0
- package/src/index.ts +84 -4
- package/src/lazyRouteComponent.ts +2 -1
- package/src/link.ts +25 -4
- package/src/linkTypes.ts +95 -0
- package/src/not-found.tsrx +2 -2
- package/src/octane-compiler.d.ts +12 -0
- package/src/route.ts +438 -42
- package/src/routeHookTypes.ts +228 -0
- package/src/router.ts +31 -6
- package/src/scriptContentUtils.ts +64 -0
- package/src/scroll-restoration.tsrx +16 -0
- package/src/scroll-restoration.tsrx.d.ts +3 -0
- package/src/ssr/RouterClient.tsrx +36 -0
- package/src/ssr/RouterClient.tsrx.d.ts +4 -0
- package/src/ssr/RouterServer.tsrx +6 -0
- package/src/ssr/RouterServer.tsrx.d.ts +4 -0
- package/src/ssr/client.ts +4 -0
- package/src/ssr/defaultRenderHandler.ts +11 -0
- package/src/ssr/defaultStreamHandler.ts +12 -0
- package/src/ssr/renderRouterToStream.ts +195 -0
- package/src/ssr/renderRouterToString.ts +58 -0
- package/src/ssr/server.ts +8 -0
- package/src/structuralSharing.ts +41 -0
- package/src/typePrimitives.ts +77 -0
- package/src/useAwaited.ts +7 -2
- package/src/useBlocker.tsrx +2 -1
- package/src/useRouterState.ts +20 -0
package/src/link.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
// with replace/resetScroll/hashScrollIntoView/viewTransition/startTransition/
|
|
10
10
|
// ignoreBlocker forwarded), and data-status/data-transitioning reflection.
|
|
11
11
|
import { useRef, useState, useEffect, useCallback, flushSync, createElement } from 'octane';
|
|
12
|
+
import type { ComponentBody } from 'octane';
|
|
12
13
|
import {
|
|
13
14
|
deepEqual,
|
|
14
15
|
exactPathTest,
|
|
@@ -22,6 +23,9 @@ import { useRouter } from './context';
|
|
|
22
23
|
import { useStore } from './useStore';
|
|
23
24
|
import { splitSlot, subSlot } from './internal';
|
|
24
25
|
import { Link } from './Link.tsrx';
|
|
26
|
+
import type { AnyRouter, RegisteredRouter } from '@tanstack/router-core';
|
|
27
|
+
import type { LinkComponent, OctaneAnchorProps, UseLinkPropsOptions } from './linkTypes';
|
|
28
|
+
import type { ValidateLinkOptions, ValidateLinkOptionsArray } from './typePrimitives';
|
|
25
29
|
|
|
26
30
|
const STATIC_EMPTY_OBJECT = {};
|
|
27
31
|
const STATIC_ACTIVE_OBJECT = { class: 'active' };
|
|
@@ -82,6 +86,13 @@ function mergeStyles(base: any, active: any, inactive: any): any {
|
|
|
82
86
|
return Object.assign({}, ...parts);
|
|
83
87
|
}
|
|
84
88
|
|
|
89
|
+
export function useLinkProps<
|
|
90
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
91
|
+
const TFrom extends string = string,
|
|
92
|
+
const TTo extends string | undefined = undefined,
|
|
93
|
+
const TMaskFrom extends string = TFrom,
|
|
94
|
+
const TMaskTo extends string = '',
|
|
95
|
+
>(options: UseLinkPropsOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>): OctaneAnchorProps;
|
|
85
96
|
export function useLinkProps(...args: any[]): Record<string, any> {
|
|
86
97
|
const [user, slot] = splitSlot(args);
|
|
87
98
|
const options = (user[0] ?? {}) as Record<string, any>;
|
|
@@ -371,13 +382,23 @@ export function useLinkProps(...args: any[]): Record<string, any> {
|
|
|
371
382
|
|
|
372
383
|
// Wrap a design-system component so it navigates like <Link> — the component
|
|
373
384
|
// receives the fully-built link props (href, handlers, data-status, …).
|
|
385
|
+
export function createLink<const TComp extends ComponentBody<any>>(
|
|
386
|
+
Comp: TComp,
|
|
387
|
+
): LinkComponent<TComp>;
|
|
374
388
|
export function createLink(Comp: any): any {
|
|
375
389
|
return function CreatedLink(props: any) {
|
|
376
390
|
return createElement(Link as any, { ...props, _asChild: Comp });
|
|
377
391
|
};
|
|
378
392
|
}
|
|
379
393
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
394
|
+
export type LinkOptionsFnOptions<TOptions, TComp, TRouter extends AnyRouter = RegisteredRouter> =
|
|
395
|
+
TOptions extends ReadonlyArray<any>
|
|
396
|
+
? ValidateLinkOptionsArray<TRouter, TOptions, string, TComp>
|
|
397
|
+
: ValidateLinkOptions<TRouter, TOptions, string, TComp>;
|
|
398
|
+
|
|
399
|
+
export type LinkOptionsFn<TComp> = <const TOptions, TRouter extends AnyRouter = RegisteredRouter>(
|
|
400
|
+
options: LinkOptionsFnOptions<TOptions, TComp, TRouter>,
|
|
401
|
+
) => TOptions;
|
|
402
|
+
|
|
403
|
+
// Identity helper for pre-validating and reusing navigation options.
|
|
404
|
+
export const linkOptions: LinkOptionsFn<'a'> = (options) => options as any;
|
package/src/linkTypes.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { ComponentBody, ElementDescriptor } from 'octane';
|
|
2
|
+
import type { Octane } from 'octane/jsx-runtime';
|
|
3
|
+
import type { AnyRouter, LinkOptions, RegisteredRouter, RoutePaths } from '@tanstack/router-core';
|
|
4
|
+
export type OctaneAnchorProps = Octane.JSX.IntrinsicElements['a'];
|
|
5
|
+
|
|
6
|
+
export type OctaneRenderable =
|
|
7
|
+
| ElementDescriptor<unknown>
|
|
8
|
+
| string
|
|
9
|
+
| number
|
|
10
|
+
| bigint
|
|
11
|
+
| boolean
|
|
12
|
+
| null
|
|
13
|
+
| undefined
|
|
14
|
+
| ReadonlyArray<OctaneRenderable>;
|
|
15
|
+
|
|
16
|
+
type OctaneComponentProps<TComp> = TComp extends keyof Octane.JSX.IntrinsicElements
|
|
17
|
+
? Octane.JSX.IntrinsicElements[TComp]
|
|
18
|
+
: TComp extends ComponentBody<infer TProps, infer _TExtra>
|
|
19
|
+
? TProps
|
|
20
|
+
: never;
|
|
21
|
+
|
|
22
|
+
export type UseLinkPropsOptions<
|
|
23
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
24
|
+
TFrom extends RoutePaths<TRouter['routeTree']> | string = string,
|
|
25
|
+
TTo extends string | undefined = '.',
|
|
26
|
+
TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,
|
|
27
|
+
TMaskTo extends string = '.',
|
|
28
|
+
> = ActiveLinkOptions<'a', TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & OctaneAnchorProps;
|
|
29
|
+
|
|
30
|
+
export type ActiveLinkOptions<
|
|
31
|
+
TComp = 'a',
|
|
32
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
33
|
+
TFrom extends string = string,
|
|
34
|
+
TTo extends string | undefined = '.',
|
|
35
|
+
TMaskFrom extends string = TFrom,
|
|
36
|
+
TMaskTo extends string = '.',
|
|
37
|
+
> = LinkOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & ActiveLinkOptionProps<TComp>;
|
|
38
|
+
|
|
39
|
+
type ActiveLinkProps<TComp> = Partial<
|
|
40
|
+
OctaneComponentProps<TComp> & {
|
|
41
|
+
[key: `data-${string}`]: unknown;
|
|
42
|
+
}
|
|
43
|
+
>;
|
|
44
|
+
|
|
45
|
+
export interface ActiveLinkOptionProps<TComp = 'a'> {
|
|
46
|
+
activeProps?: ActiveLinkProps<TComp> | (() => ActiveLinkProps<TComp>);
|
|
47
|
+
inactiveProps?: ActiveLinkProps<TComp> | (() => ActiveLinkProps<TComp>);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type LinkProps<
|
|
51
|
+
TComp = 'a',
|
|
52
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
53
|
+
TFrom extends string = string,
|
|
54
|
+
TTo extends string | undefined = '.',
|
|
55
|
+
TMaskFrom extends string = TFrom,
|
|
56
|
+
TMaskTo extends string = '.',
|
|
57
|
+
> = ActiveLinkOptions<TComp, TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & LinkPropsChildren;
|
|
58
|
+
|
|
59
|
+
export interface LinkPropsChildren {
|
|
60
|
+
children?:
|
|
61
|
+
OctaneRenderable | ((state: { isActive: boolean; isTransitioning: boolean }) => unknown);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export type CreateLinkProps = LinkProps<any, any, string, string, string, string>;
|
|
65
|
+
|
|
66
|
+
export type LinkComponentProps<
|
|
67
|
+
TComp = 'a',
|
|
68
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
69
|
+
TFrom extends string = string,
|
|
70
|
+
TTo extends string | undefined = '.',
|
|
71
|
+
TMaskFrom extends string = TFrom,
|
|
72
|
+
TMaskTo extends string = '.',
|
|
73
|
+
> = Omit<OctaneComponentProps<TComp>, keyof CreateLinkProps> &
|
|
74
|
+
LinkProps<TComp, TRouter, TFrom, TTo, TMaskFrom, TMaskTo>;
|
|
75
|
+
|
|
76
|
+
export type LinkComponent<in out TComp, in out TDefaultFrom extends string = string> = <
|
|
77
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
78
|
+
const TFrom extends string = TDefaultFrom,
|
|
79
|
+
const TTo extends string | undefined = undefined,
|
|
80
|
+
const TMaskFrom extends string = TFrom,
|
|
81
|
+
const TMaskTo extends string = '',
|
|
82
|
+
>(
|
|
83
|
+
props: LinkComponentProps<TComp, TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,
|
|
84
|
+
) => void;
|
|
85
|
+
|
|
86
|
+
export interface LinkComponentRoute<in out TDefaultFrom extends string = string> {
|
|
87
|
+
defaultFrom: TDefaultFrom;
|
|
88
|
+
<
|
|
89
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
90
|
+
const TTo extends string | undefined = undefined,
|
|
91
|
+
const TMaskTo extends string = '',
|
|
92
|
+
>(
|
|
93
|
+
props: LinkComponentProps<'a', TRouter, this['defaultFrom'], TTo, this['defaultFrom'], TMaskTo>,
|
|
94
|
+
): void;
|
|
95
|
+
}
|
package/src/not-found.tsrx
CHANGED
|
@@ -27,8 +27,8 @@ export function CatchNotFound(props: {
|
|
|
27
27
|
children: OctaneNode;
|
|
28
28
|
}) @{
|
|
29
29
|
const router = useRouter();
|
|
30
|
-
const pathname = useStore(router.stores.location, (l) => l.pathname);
|
|
31
|
-
const status = useStore(router.stores.status, (s) => s);
|
|
30
|
+
const pathname = useStore(router.stores.location, (l: any) => l.pathname as string);
|
|
31
|
+
const status = useStore(router.stores.status, (s: any) => s as string);
|
|
32
32
|
const resetKey = `not-found-${pathname}-${status}`;
|
|
33
33
|
|
|
34
34
|
<CatchBoundary
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare module 'octane/compiler/volar' {
|
|
2
|
+
export interface VolarCompileResult {
|
|
3
|
+
code: string;
|
|
4
|
+
mappings: Array<unknown>;
|
|
5
|
+
cssMappings: Array<unknown>;
|
|
6
|
+
scriptMappings: Array<unknown>;
|
|
7
|
+
sourceAst: unknown;
|
|
8
|
+
errors: Array<unknown>;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function compileToVolarMappings(source: string, filename?: string): VolarCompileResult;
|
|
12
|
+
}
|