@storesjs/stores 0.8.0 → 0.8.1
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 +147 -0
- package/dist/native/index.js +1 -1
- package/package.json +1 -1
- package/dist/middleware/createSubscriptionManager.d.ts +0 -10
- package/dist/plugins/chrome/utils.d.ts +0 -1
- package/dist/plugins/delta/deltaInstrumentation.d.ts +0 -42
- package/dist/plugins/delta/index.d.ts +0 -1
- package/dist/plugins/delta/recordDelta.d.ts +0 -14
- package/dist/plugins/network/index.d.ts +0 -2
- package/dist/plugins/router/RouteErrorBoundary.d.ts +0 -19
- package/dist/plugins/router/__tests__/router-types.test.d.ts +0 -0
- package/dist/plugins/router/constants.d.ts +0 -38
- package/dist/plugins/router/createRouter-old-version.d.ts +0 -183
- package/dist/plugins/router/createRouter.d.ts +0 -183
- package/dist/plugins/router/errorBoundary.d.ts +0 -23
- package/dist/plugins/router/index.d.ts +0 -6
- package/dist/plugins/router/lazy.d.ts +0 -14
- package/dist/plugins/router/locationStore.d.ts +0 -24
- package/dist/plugins/router/pathMatching.d.ts +0 -28
- package/dist/plugins/router/scrollRestoration.d.ts +0 -8
- package/dist/plugins/router/searchParams.d.ts +0 -53
- package/dist/plugins/router/test-link-params.d.ts +0 -1
- package/dist/plugins/router/test-prefetch.d.ts +0 -17
- package/dist/plugins/router/test-types.d.ts +0 -1
- package/dist/plugins/router/types.d.ts +0 -11
- package/dist/plugins/router/utils.d.ts +0 -14
- package/dist/plugins/router/vite.d.ts +0 -5
- package/dist/presence/heartbeat.d.ts +0 -23
- package/dist/presence/presenceChannel.d.ts +0 -19
- package/dist/presence/pruning.d.ts +0 -34
- package/dist/queryStore/createParamManager.d.ts +0 -27
- package/dist/sync/networkSyncEngine.d.ts +0 -137
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import { ComponentType, ReactNode } from "react";
|
|
2
|
-
import { DeriveGetter } from "../../createDerivedStore";
|
|
3
|
-
import { BaseStore, DerivedStore, EqualityFn, Selector } from "../../types";
|
|
4
|
-
import { ErrorFallback } from "./RouteErrorBoundary";
|
|
5
|
-
import { InferSearchParams, SearchParamsSchema } from "./searchParams";
|
|
6
|
-
import { Location, NavigateOptions, To } from "./types";
|
|
7
|
-
export type RouteBackground = string | {
|
|
8
|
-
dark: string;
|
|
9
|
-
light: string;
|
|
10
|
-
} | (($: DeriveGetter) => string);
|
|
11
|
-
type RouteBase = {
|
|
12
|
-
readonly background?: RouteBackground;
|
|
13
|
-
readonly path: string;
|
|
14
|
-
readonly title?: string;
|
|
15
|
-
};
|
|
16
|
-
type ContentRoute = RouteBase & ({
|
|
17
|
-
readonly element: LazyElement;
|
|
18
|
-
readonly pendingElement?: ReactNode;
|
|
19
|
-
} | {
|
|
20
|
-
readonly element: ReactNode;
|
|
21
|
-
readonly pendingElement?: never;
|
|
22
|
-
}) & {
|
|
23
|
-
readonly children?: Record<string, Route>;
|
|
24
|
-
readonly searchParams?: SearchParamsSchema;
|
|
25
|
-
readonly wrapper?: never;
|
|
26
|
-
};
|
|
27
|
-
type LayoutRoute = RouteBase & ({
|
|
28
|
-
readonly pendingElement?: ReactNode;
|
|
29
|
-
readonly wrapper: LazyWrapperComponent;
|
|
30
|
-
} | {
|
|
31
|
-
readonly pendingElement?: never;
|
|
32
|
-
readonly wrapper?: WrapperComponent;
|
|
33
|
-
}) & {
|
|
34
|
-
readonly children: Record<string, Route>;
|
|
35
|
-
readonly element?: never;
|
|
36
|
-
readonly searchParams?: never;
|
|
37
|
-
};
|
|
38
|
-
export type Route = ContentRoute | LayoutRoute;
|
|
39
|
-
export type RedirectFn = (route: string, params?: Record<string, string>) => void;
|
|
40
|
-
export type BeforeEnterCallback = (params: Record<string, string>, redirect: RedirectFn) => void;
|
|
41
|
-
type RouterOptions<T extends Record<string, Route>> = {
|
|
42
|
-
errorFallback?: ErrorFallback;
|
|
43
|
-
formatTitle?: (title: string | null) => string;
|
|
44
|
-
notFound?: ReactNode;
|
|
45
|
-
resolveTitle?: (routeName: ExtractRoutes<T>, params: Partial<Record<string, string>>) => string | null | Promise<string | null>;
|
|
46
|
-
scrollRestoration?: boolean;
|
|
47
|
-
};
|
|
48
|
-
type ComponentModule = Record<string, ComponentType<unknown>>;
|
|
49
|
-
type LazyLoader = () => Promise<ComponentModule>;
|
|
50
|
-
type LazyTuple = readonly [LazyLoader, string];
|
|
51
|
-
type LazyElement = LazyLoader | LazyTuple;
|
|
52
|
-
type WrapperComponent = ComponentType<{
|
|
53
|
-
children?: ReactNode;
|
|
54
|
-
}>;
|
|
55
|
-
type LazyWrapperComponent = readonly [LazyLoader, string?];
|
|
56
|
-
type PathParams<P extends string> = ExtractParams<P> & Record<string, string>;
|
|
57
|
-
type TypedCallbacks<P extends string> = {
|
|
58
|
-
afterLeave?: (params: PathParams<P>) => void;
|
|
59
|
-
beforeEnter?: (params: PathParams<P>, redirect: RedirectFn) => void;
|
|
60
|
-
prefetch?: (params: PathParams<P>) => void;
|
|
61
|
-
};
|
|
62
|
-
type RouteWithTypedCallbacks<T> = T extends {
|
|
63
|
-
path: infer P extends string;
|
|
64
|
-
} ? Route & TypedCallbacks<P> : Route;
|
|
65
|
-
export declare function defineRoutes<const T extends {
|
|
66
|
-
[K in keyof T]: RouteWithTypedCallbacks<T[K]>;
|
|
67
|
-
}>(routes: T): T;
|
|
68
|
-
export type ExtractRoutes<T extends Record<string, Route>, Prefix extends string = ""> = Extract<{
|
|
69
|
-
[K in keyof T & string]: `${Prefix}${K}` | (T[K] extends {
|
|
70
|
-
children: infer C extends Record<string, Route>;
|
|
71
|
-
} ? ExtractRoutes<C, `${Prefix}${K}.`> : never);
|
|
72
|
-
}[keyof T & string], string>;
|
|
73
|
-
type ExtractParams<T extends string | undefined> = T extends undefined ? Record<never, never> : T extends `${string}:${infer Param}/${infer Rest}` ? {
|
|
74
|
-
[K in Param | keyof ExtractParams<`/${Rest}`>]: string;
|
|
75
|
-
} : T extends `${string}:${infer Param}` ? {
|
|
76
|
-
[K in Param]: string;
|
|
77
|
-
} : Record<never, never>;
|
|
78
|
-
type HasParams<T> = T extends Record<string, unknown> ? (keyof T extends never ? false : true) : false;
|
|
79
|
-
type AccumulatedParams<T extends Record<string, Route>, K extends string> = K extends `${infer Head}.${infer Rest}` ? Head extends keyof T ? T[Head] extends {
|
|
80
|
-
children: infer C extends Record<string, Route>;
|
|
81
|
-
path: infer P extends string;
|
|
82
|
-
} ? ExtractParams<P> & AccumulatedParams<C, Rest> : Record<never, never> : Record<never, never> : K extends keyof T ? T[K] extends {
|
|
83
|
-
path: infer P extends string;
|
|
84
|
-
} ? ExtractParams<P> : Record<never, never> : Record<never, never>;
|
|
85
|
-
type FlatRoutesWithSearchParams<T, Prefix extends string = ""> = T extends Record<string, unknown> ? {
|
|
86
|
-
[K in keyof T & string]: (T[K] extends {
|
|
87
|
-
searchParams: SearchParamsSchema;
|
|
88
|
-
} ? `${Prefix}${K}` : never) | (T[K] extends {
|
|
89
|
-
children: infer C;
|
|
90
|
-
} ? FlatRoutesWithSearchParams<C, `${Prefix}${K}.`> : never);
|
|
91
|
-
}[keyof T & string] : never;
|
|
92
|
-
type RoutesWithSearchParams<T extends Record<string, Route>> = FlatRoutesWithSearchParams<T> & string;
|
|
93
|
-
type RouteSearchParamsSchema<T, K extends string> = K extends `${infer Head}.${infer Rest}` ? Head extends keyof T ? T[Head] extends {
|
|
94
|
-
children: infer C;
|
|
95
|
-
} ? RouteSearchParamsSchema<C, Rest> : never : never : K extends keyof T ? T[K] extends {
|
|
96
|
-
searchParams: infer S extends SearchParamsSchema;
|
|
97
|
-
} ? S : never : never;
|
|
98
|
-
type SearchParamsFor<T extends Record<string, Route>, K extends RoutesWithSearchParams<T>> = InferSearchParams<RouteSearchParamsSchema<T, K>>;
|
|
99
|
-
type SearchParamsResult<Params extends Record<string, unknown>, K extends string> = Params & {
|
|
100
|
-
route: K;
|
|
101
|
-
setParams: (params: Partial<Params>, options?: {
|
|
102
|
-
replace?: boolean;
|
|
103
|
-
}) => void;
|
|
104
|
-
};
|
|
105
|
-
type BackToProps<K extends string> = {
|
|
106
|
-
backTo: K;
|
|
107
|
-
};
|
|
108
|
-
type ToProps<K extends string> = {
|
|
109
|
-
replace?: boolean;
|
|
110
|
-
to: K;
|
|
111
|
-
state?: unknown;
|
|
112
|
-
};
|
|
113
|
-
type LinkPropsBase<K extends string> = {
|
|
114
|
-
prefetch?: boolean;
|
|
115
|
-
} & (BackToProps<K> | ToProps<K>);
|
|
116
|
-
type ParamsProps<T extends Record<string, Route>, K extends ExtractRoutes<T>> = HasParams<AccumulatedParams<T, K>> extends true ? {
|
|
117
|
-
params: AccumulatedParams<T, K>;
|
|
118
|
-
} : {
|
|
119
|
-
params?: Record<never, never>;
|
|
120
|
-
};
|
|
121
|
-
type LinkProps<T extends Record<string, Route>, K extends ExtractRoutes<T>> = Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, "href"> & LinkPropsBase<K> & ParamsProps<T, K>;
|
|
122
|
-
type NavLinkProps<T extends Record<string, Route>, K extends ExtractRoutes<T>> = Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, "href" | "className" | "style"> & LinkPropsBase<K> & ParamsProps<T, K> & {
|
|
123
|
-
className?: string | ((isActive: boolean) => string | undefined);
|
|
124
|
-
isActive?: (route: string | null) => boolean;
|
|
125
|
-
style?: React.CSSProperties | ((isActive: boolean) => React.CSSProperties | undefined);
|
|
126
|
-
};
|
|
127
|
-
type NavigateProps<T extends Record<string, Route>, K extends ExtractRoutes<T>> = ToProps<K> & ParamsProps<T, K>;
|
|
128
|
-
type RouterInstance<T extends Record<string, Route>, Routes extends ExtractRoutes<T> = ExtractRoutes<T>> = {
|
|
129
|
-
Link: <K extends Routes>(props: LinkProps<T, K>) => ReactNode;
|
|
130
|
-
Navigate: <K extends Routes>(props: NavigateProps<T, K>) => null;
|
|
131
|
-
NavLink: <K extends Routes>(props: NavLinkProps<T, K>) => ReactNode;
|
|
132
|
-
Router: () => ReactNode;
|
|
133
|
-
backTo: <K extends Routes>(route: K, ...args: HasParams<AccumulatedParams<T, K>> extends true ? [params: AccumulatedParams<T, K>] : [params?: Record<never, never>]) => void;
|
|
134
|
-
destroyRouter: () => void;
|
|
135
|
-
getPath: <K extends Routes>(route: K, ...args: HasParams<AccumulatedParams<T, K>> extends true ? [params: AccumulatedParams<T, K>] : [params?: Record<never, never>]) => string;
|
|
136
|
-
navigate: <K extends Routes>(route: K, ...args: HasParams<AccumulatedParams<T, K>> extends true ? [params: AccumulatedParams<T, K>, options?: NavigateOptions] : [params?: Record<never, never>, options?: NavigateOptions]) => void;
|
|
137
|
-
routes: T;
|
|
138
|
-
searchParamsStore: <K extends RoutesWithSearchParams<T>>(route: K) => DerivedStore<SearchParamsResult<SearchParamsFor<T, K>, K> | null>;
|
|
139
|
-
useCurrentRoute: DerivedStore<{
|
|
140
|
-
name: string;
|
|
141
|
-
params: Record<string, string>;
|
|
142
|
-
} | null>;
|
|
143
|
-
useIsActive: (route: Routes) => boolean;
|
|
144
|
-
useLocationStore: BaseStore<Location & {
|
|
145
|
-
back: () => void;
|
|
146
|
-
forward: () => void;
|
|
147
|
-
navigate: (to: To, options?: NavigateOptions) => void;
|
|
148
|
-
}, false>;
|
|
149
|
-
useParams: () => Record<string, string>;
|
|
150
|
-
useRoute: () => string | null;
|
|
151
|
-
useRouteBackground: DerivedStore<string | null>;
|
|
152
|
-
useSetTitle: (title: string | undefined) => void;
|
|
153
|
-
useSearchParams: {
|
|
154
|
-
<K extends RoutesWithSearchParams<T>>(route: K): SearchParamsResult<SearchParamsFor<T, K>, K> | null;
|
|
155
|
-
<K extends RoutesWithSearchParams<T>, Selected>(route: K, selector: Selector<SearchParamsResult<SearchParamsFor<T, K>, K> | null, Selected>, equalityFn?: EqualityFn<Selected>): Selected;
|
|
156
|
-
};
|
|
157
|
-
};
|
|
158
|
-
/**
|
|
159
|
-
* Create a type-safe router.
|
|
160
|
-
*
|
|
161
|
-
* @example
|
|
162
|
-
* ```tsx
|
|
163
|
-
* const Router = createRouter({
|
|
164
|
-
* home: { path: '/', element: <Home /> },
|
|
165
|
-
* search: { path: '/search', element: <Search />, searchParams: { q: s.string(''), page: s.number(1) } },
|
|
166
|
-
* });
|
|
167
|
-
*
|
|
168
|
-
* // Type-safe navigation
|
|
169
|
-
* Router.navigate('home');
|
|
170
|
-
*
|
|
171
|
-
* // Type-safe search params (specify route for type inference)
|
|
172
|
-
* const params = Router.useSearchParams('search');
|
|
173
|
-
* if (params) {
|
|
174
|
-
* params.q // string
|
|
175
|
-
* params.page // number
|
|
176
|
-
* params.setParams({ page: 2 });
|
|
177
|
-
* }
|
|
178
|
-
* ```
|
|
179
|
-
*/
|
|
180
|
-
export declare function createRouter<const T extends {
|
|
181
|
-
[K in keyof T]: RouteWithTypedCallbacks<T[K]>;
|
|
182
|
-
}>(routes: T, options?: RouterOptions<T>): RouterInstance<T>;
|
|
183
|
-
export {};
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import { ComponentType, ReactNode } from 'react';
|
|
2
|
-
import { DeriveGetter } from '../../createDerivedStore';
|
|
3
|
-
import { BaseStore, DerivedStore, EqualityFn, Selector } from '../../types';
|
|
4
|
-
import { ErrorFallback } from './RouteErrorBoundary';
|
|
5
|
-
import { InferSearchParams, SearchParamsSchema } from './searchParams';
|
|
6
|
-
import { Location, NavigateOptions, To } from './types';
|
|
7
|
-
export type RouteBackground = string | {
|
|
8
|
-
dark: string;
|
|
9
|
-
light: string;
|
|
10
|
-
} | (($: DeriveGetter) => string);
|
|
11
|
-
type RouteBase = {
|
|
12
|
-
readonly background?: RouteBackground;
|
|
13
|
-
readonly path: string;
|
|
14
|
-
readonly title?: string;
|
|
15
|
-
};
|
|
16
|
-
type ContentRoute = RouteBase & ({
|
|
17
|
-
readonly element: LazyElement;
|
|
18
|
-
readonly pendingElement?: ReactNode;
|
|
19
|
-
} | {
|
|
20
|
-
readonly element: ReactNode;
|
|
21
|
-
readonly pendingElement?: never;
|
|
22
|
-
}) & {
|
|
23
|
-
readonly children?: Record<string, Route>;
|
|
24
|
-
readonly searchParams?: SearchParamsSchema;
|
|
25
|
-
readonly wrapper?: never;
|
|
26
|
-
};
|
|
27
|
-
type LayoutRoute = RouteBase & ({
|
|
28
|
-
readonly pendingElement?: ReactNode;
|
|
29
|
-
readonly wrapper: LazyWrapperComponent;
|
|
30
|
-
} | {
|
|
31
|
-
readonly pendingElement?: never;
|
|
32
|
-
readonly wrapper?: WrapperComponent;
|
|
33
|
-
}) & {
|
|
34
|
-
readonly children: Record<string, Route>;
|
|
35
|
-
readonly element?: never;
|
|
36
|
-
readonly searchParams?: never;
|
|
37
|
-
};
|
|
38
|
-
export type Route = ContentRoute | LayoutRoute;
|
|
39
|
-
export type RedirectFn = (route: string, params?: Record<string, string>) => void;
|
|
40
|
-
export type BeforeEnterCallback = (params: Record<string, string>, redirect: RedirectFn) => void;
|
|
41
|
-
type RouterOptions<T extends Record<string, Route>> = {
|
|
42
|
-
errorFallback?: ErrorFallback;
|
|
43
|
-
formatTitle?: (title: string | null) => string;
|
|
44
|
-
notFound?: ReactNode;
|
|
45
|
-
resolveTitle?: (routeName: ExtractRoutes<T>, params: Partial<Record<string, string>>) => string | null | undefined | Promise<string | null | undefined>;
|
|
46
|
-
scrollRestoration?: boolean;
|
|
47
|
-
};
|
|
48
|
-
type ComponentModule = Record<string, ComponentType<unknown>>;
|
|
49
|
-
type LazyLoader = () => Promise<ComponentModule>;
|
|
50
|
-
type LazyTuple = readonly [LazyLoader, string];
|
|
51
|
-
type LazyElement = LazyLoader | LazyTuple;
|
|
52
|
-
type WrapperComponent = ComponentType<{
|
|
53
|
-
children?: ReactNode;
|
|
54
|
-
}>;
|
|
55
|
-
type LazyWrapperComponent = readonly [LazyLoader, string?];
|
|
56
|
-
type PathParams<P extends string> = ExtractParams<P> & Record<string, string>;
|
|
57
|
-
type TypedCallbacks<P extends string> = {
|
|
58
|
-
afterLeave?: (params: PathParams<P>) => void;
|
|
59
|
-
beforeEnter?: (params: PathParams<P>, redirect: RedirectFn) => void;
|
|
60
|
-
prefetch?: (params: PathParams<P>) => void;
|
|
61
|
-
};
|
|
62
|
-
type RouteWithTypedCallbacks<T> = T extends {
|
|
63
|
-
path: infer P extends string;
|
|
64
|
-
} ? Route & TypedCallbacks<P> : Route;
|
|
65
|
-
export declare function defineRoutes<const T extends {
|
|
66
|
-
[K in keyof T]: RouteWithTypedCallbacks<T[K]>;
|
|
67
|
-
}>(routes: T): T;
|
|
68
|
-
export type ExtractRoutes<T extends Record<string, Route>, Prefix extends string = ''> = Extract<{
|
|
69
|
-
[K in keyof T & string]: `${Prefix}${K}` | (T[K] extends {
|
|
70
|
-
children: infer C extends Record<string, Route>;
|
|
71
|
-
} ? ExtractRoutes<C, `${Prefix}${K}.`> : never);
|
|
72
|
-
}[keyof T & string], string>;
|
|
73
|
-
type ExtractParams<T extends string | undefined> = T extends undefined ? Record<never, never> : T extends `${string}:${infer Param}/${infer Rest}` ? {
|
|
74
|
-
[K in Param | keyof ExtractParams<`/${Rest}`>]: string;
|
|
75
|
-
} : T extends `${string}:${infer Param}` ? {
|
|
76
|
-
[K in Param]: string;
|
|
77
|
-
} : Record<never, never>;
|
|
78
|
-
type HasParams<T> = T extends Record<string, unknown> ? (keyof T extends never ? false : true) : false;
|
|
79
|
-
type AccumulatedParams<T extends Record<string, Route>, K extends string> = K extends `${infer Head}.${infer Rest}` ? Head extends keyof T ? T[Head] extends {
|
|
80
|
-
children: infer C extends Record<string, Route>;
|
|
81
|
-
path: infer P extends string;
|
|
82
|
-
} ? ExtractParams<P> & AccumulatedParams<C, Rest> : Record<never, never> : Record<never, never> : K extends keyof T ? T[K] extends {
|
|
83
|
-
path: infer P extends string;
|
|
84
|
-
} ? ExtractParams<P> : Record<never, never> : Record<never, never>;
|
|
85
|
-
type FlatRoutesWithSearchParams<T, Prefix extends string = ''> = T extends Record<string, unknown> ? {
|
|
86
|
-
[K in keyof T & string]: (T[K] extends {
|
|
87
|
-
searchParams: SearchParamsSchema;
|
|
88
|
-
} ? `${Prefix}${K}` : never) | (T[K] extends {
|
|
89
|
-
children: infer C;
|
|
90
|
-
} ? FlatRoutesWithSearchParams<C, `${Prefix}${K}.`> : never);
|
|
91
|
-
}[keyof T & string] : never;
|
|
92
|
-
type RoutesWithSearchParams<T extends Record<string, Route>> = FlatRoutesWithSearchParams<T> & string;
|
|
93
|
-
type RouteSearchParamsSchema<T, K extends string> = K extends `${infer Head}.${infer Rest}` ? Head extends keyof T ? T[Head] extends {
|
|
94
|
-
children: infer C;
|
|
95
|
-
} ? RouteSearchParamsSchema<C, Rest> : never : never : K extends keyof T ? T[K] extends {
|
|
96
|
-
searchParams: infer S extends SearchParamsSchema;
|
|
97
|
-
} ? S : never : never;
|
|
98
|
-
type SearchParamsFor<T extends Record<string, Route>, K extends RoutesWithSearchParams<T>> = InferSearchParams<RouteSearchParamsSchema<T, K>>;
|
|
99
|
-
type SearchParamsResult<Params extends Record<string, unknown>, K extends string> = Params & {
|
|
100
|
-
route: K;
|
|
101
|
-
setParams: (params: Partial<Params>, options?: {
|
|
102
|
-
replace?: boolean;
|
|
103
|
-
}) => void;
|
|
104
|
-
};
|
|
105
|
-
type BackToProps<K extends string> = {
|
|
106
|
-
backTo: K;
|
|
107
|
-
};
|
|
108
|
-
type ToProps<K extends string> = {
|
|
109
|
-
replace?: boolean;
|
|
110
|
-
to: K;
|
|
111
|
-
state?: unknown;
|
|
112
|
-
};
|
|
113
|
-
type LinkPropsBase<K extends string> = {
|
|
114
|
-
prefetch?: boolean;
|
|
115
|
-
} & (BackToProps<K> | ToProps<K>);
|
|
116
|
-
type ParamsProps<T extends Record<string, Route>, K extends ExtractRoutes<T>> = HasParams<AccumulatedParams<T, K>> extends true ? {
|
|
117
|
-
params: AccumulatedParams<T, K>;
|
|
118
|
-
} : {
|
|
119
|
-
params?: Record<never, never>;
|
|
120
|
-
};
|
|
121
|
-
type LinkProps<T extends Record<string, Route>, K extends ExtractRoutes<T>> = Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'href'> & LinkPropsBase<K> & ParamsProps<T, K>;
|
|
122
|
-
type NavLinkProps<T extends Record<string, Route>, K extends ExtractRoutes<T>> = Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'href' | 'className' | 'style'> & LinkPropsBase<K> & ParamsProps<T, K> & {
|
|
123
|
-
className?: string | ((isActive: boolean) => string | undefined);
|
|
124
|
-
isActive?: (route: string | null) => boolean;
|
|
125
|
-
style?: React.CSSProperties | ((isActive: boolean) => React.CSSProperties | undefined);
|
|
126
|
-
};
|
|
127
|
-
type NavigateProps<T extends Record<string, Route>, K extends ExtractRoutes<T>> = ToProps<K> & ParamsProps<T, K>;
|
|
128
|
-
type RouterInstance<T extends Record<string, Route>, Routes extends ExtractRoutes<T> = ExtractRoutes<T>> = {
|
|
129
|
-
Link: <K extends Routes>(props: LinkProps<T, K>) => ReactNode;
|
|
130
|
-
Navigate: <K extends Routes>(props: NavigateProps<T, K>) => null;
|
|
131
|
-
NavLink: <K extends Routes>(props: NavLinkProps<T, K>) => ReactNode;
|
|
132
|
-
Router: () => ReactNode;
|
|
133
|
-
backTo: <K extends Routes>(route: K, ...args: HasParams<AccumulatedParams<T, K>> extends true ? [params: AccumulatedParams<T, K>] : [params?: Record<never, never>]) => void;
|
|
134
|
-
destroyRouter: () => void;
|
|
135
|
-
getPath: <K extends Routes>(route: K, ...args: HasParams<AccumulatedParams<T, K>> extends true ? [params: AccumulatedParams<T, K>] : [params?: Record<never, never>]) => string;
|
|
136
|
-
navigate: <K extends Routes>(route: K, ...args: HasParams<AccumulatedParams<T, K>> extends true ? [params: AccumulatedParams<T, K>, options?: NavigateOptions] : [params?: Record<never, never>, options?: NavigateOptions]) => void;
|
|
137
|
-
routes: T;
|
|
138
|
-
searchParamsStore: <K extends RoutesWithSearchParams<T>>(route: K) => DerivedStore<SearchParamsResult<SearchParamsFor<T, K>, K> | null>;
|
|
139
|
-
useCurrentRoute: DerivedStore<{
|
|
140
|
-
name: string;
|
|
141
|
-
params: Record<string, string>;
|
|
142
|
-
} | null>;
|
|
143
|
-
useIsActive: (route: Routes) => boolean;
|
|
144
|
-
useLocationStore: BaseStore<Location & {
|
|
145
|
-
back: () => void;
|
|
146
|
-
forward: () => void;
|
|
147
|
-
navigate: (to: To, options?: NavigateOptions) => void;
|
|
148
|
-
}, false>;
|
|
149
|
-
useParams: () => Record<string, string>;
|
|
150
|
-
useRoute: () => string | null;
|
|
151
|
-
useRouteBackground: DerivedStore<string | null>;
|
|
152
|
-
useSetTitle: (title: string | undefined) => void;
|
|
153
|
-
useSearchParams: {
|
|
154
|
-
<K extends RoutesWithSearchParams<T>>(route: K): SearchParamsResult<SearchParamsFor<T, K>, K> | null;
|
|
155
|
-
<K extends RoutesWithSearchParams<T>, Selected>(route: K, selector: Selector<SearchParamsResult<SearchParamsFor<T, K>, K> | null, Selected>, equalityFn?: EqualityFn<Selected>): Selected;
|
|
156
|
-
};
|
|
157
|
-
};
|
|
158
|
-
/**
|
|
159
|
-
* Create a type-safe router.
|
|
160
|
-
*
|
|
161
|
-
* @example
|
|
162
|
-
* ```tsx
|
|
163
|
-
* const Router = createRouter({
|
|
164
|
-
* home: { path: '/', element: <Home /> },
|
|
165
|
-
* search: { path: '/search', element: <Search />, searchParams: { q: s.string(''), page: s.number(1) } },
|
|
166
|
-
* });
|
|
167
|
-
*
|
|
168
|
-
* // Type-safe navigation
|
|
169
|
-
* Router.navigate('home');
|
|
170
|
-
*
|
|
171
|
-
* // Type-safe search params (specify route for type inference)
|
|
172
|
-
* const params = Router.useSearchParams('search');
|
|
173
|
-
* if (params) {
|
|
174
|
-
* params.q // string
|
|
175
|
-
* params.page // number
|
|
176
|
-
* params.setParams({ page: 2 });
|
|
177
|
-
* }
|
|
178
|
-
* ```
|
|
179
|
-
*/
|
|
180
|
-
export declare function createRouter<const T extends {
|
|
181
|
-
[K in keyof T]: RouteWithTypedCallbacks<T[K]>;
|
|
182
|
-
}>(routes: T, options?: RouterOptions<T>): RouterInstance<T>;
|
|
183
|
-
export {};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Component, ReactNode } from 'react';
|
|
2
|
-
export type RouteErrorContextValue = {
|
|
3
|
-
error: unknown;
|
|
4
|
-
reset: () => void;
|
|
5
|
-
};
|
|
6
|
-
export type RouteErrorBoundaryProps = {
|
|
7
|
-
children: ReactNode;
|
|
8
|
-
fallback: ReactNode;
|
|
9
|
-
resetKey?: string;
|
|
10
|
-
};
|
|
11
|
-
type ErrorBoundaryState = {
|
|
12
|
-
error: unknown;
|
|
13
|
-
hasError: boolean;
|
|
14
|
-
};
|
|
15
|
-
export declare function useRouteError(): RouteErrorContextValue;
|
|
16
|
-
export declare class RouteErrorBoundary extends Component<RouteErrorBoundaryProps, ErrorBoundaryState> {
|
|
17
|
-
state: ErrorBoundaryState;
|
|
18
|
-
static getDerivedStateFromError(error: unknown): ErrorBoundaryState;
|
|
19
|
-
componentDidUpdate(prevProps: RouteErrorBoundaryProps): void;
|
|
20
|
-
private reset;
|
|
21
|
-
render(): ReactNode;
|
|
22
|
-
}
|
|
23
|
-
export {};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { initializeLocation, navigation, useLocationStore } from './locationStore';
|
|
2
|
-
export { InferSearchParams, ParamSchema, s, SearchParamsSchema } from './searchParams';
|
|
3
|
-
export { BeforeEnterCallback, ExtractRoutes, RedirectFn, Route, RouteBackground, createRouter, defineRoutes } from './createRouter';
|
|
4
|
-
export { scrollRestoration } from './scrollRestoration';
|
|
5
|
-
export { Location, NavigateOptions, To } from './types';
|
|
6
|
-
export { VitePlugin, router as vitePlugin } from './vite';
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { ComponentType, ReactNode } from 'react';
|
|
2
|
-
type ComponentModule = Record<string, ComponentType<unknown>>;
|
|
3
|
-
type UseLazy<T> = {
|
|
4
|
-
(): T | null;
|
|
5
|
-
preload: () => Promise<void>;
|
|
6
|
-
};
|
|
7
|
-
export type LazyComponent = ComponentType<{
|
|
8
|
-
children?: ReactNode;
|
|
9
|
-
}> & {
|
|
10
|
-
preload: () => Promise<void>;
|
|
11
|
-
};
|
|
12
|
-
export declare function createLazy<T>(load: () => Promise<T>): UseLazy<T>;
|
|
13
|
-
export declare function createLazyComponent(load: () => Promise<ComponentModule>, exportName: string | null, pendingElement?: ReactNode): LazyComponent;
|
|
14
|
-
export {};
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Location, NavigateOptions, To } from './types';
|
|
2
|
-
type BeforeNavigateCallback = (hash: string) => Record<string, unknown> | undefined;
|
|
3
|
-
type BeforePopStateCallback = () => void;
|
|
4
|
-
export declare const addBeforeNavigateCallback: (callback: BeforeNavigateCallback) => () => void;
|
|
5
|
-
export declare const addBeforePopStateCallback: (callback: BeforePopStateCallback) => () => void;
|
|
6
|
-
export declare function setCurrentRoute(routeName: string | null): void;
|
|
7
|
-
export declare function getPreviousRoute(): string | null;
|
|
8
|
-
type LocationStore = Location & {
|
|
9
|
-
awaitingLazyRoute: boolean;
|
|
10
|
-
back: () => void;
|
|
11
|
-
forward: () => void;
|
|
12
|
-
get<K extends keyof Location>(key: K): Location[K];
|
|
13
|
-
initialize: (isLazyRoute: () => boolean) => void;
|
|
14
|
-
isAwaitingLazyRoute: () => boolean;
|
|
15
|
-
navigate: (to: To, options?: NavigateOptions) => void;
|
|
16
|
-
setAwaitingLazyRoute: (value: boolean) => void;
|
|
17
|
-
};
|
|
18
|
-
export declare function setOnBeforeNavigate(callback: ((pathname: string) => void) | undefined): void;
|
|
19
|
-
export declare const useLocationStore: import("../..").BaseStore<LocationStore, false>;
|
|
20
|
-
export declare const navigation: import("../../utils/createStoreActions").StoreActions<import("../..").BaseStore<LocationStore, false>>;
|
|
21
|
-
type PopStateInterceptor = (pathname: string, historyState: unknown) => boolean;
|
|
22
|
-
export declare function setPopStateInterceptor(interceptor: PopStateInterceptor | null): void;
|
|
23
|
-
export declare function initializeLocation(url: string): void;
|
|
24
|
-
export {};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export type TrieMatch<T> = {
|
|
2
|
-
entry: T;
|
|
3
|
-
params: Record<string, string>;
|
|
4
|
-
};
|
|
5
|
-
export type RouteTrie<T> = {
|
|
6
|
-
insert(pattern: string, entry: T): void;
|
|
7
|
-
match(pathname: string): TrieMatch<T> | null;
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* Radix trie for O(k) route matching, where k is path depth.
|
|
11
|
-
*
|
|
12
|
-
* Traversal order (static → param → wildcard) with backtracking
|
|
13
|
-
* implements specificity: `/users/admin` matches before `/users/:id`.
|
|
14
|
-
*/
|
|
15
|
-
export declare function createRouteTrie<T>(): RouteTrie<T>;
|
|
16
|
-
/**
|
|
17
|
-
* Check if a route matches a target (exact match or descendant).
|
|
18
|
-
* Used for active state detection and route hierarchy checks.
|
|
19
|
-
*/
|
|
20
|
-
export declare function routeMatches(route: string, target: string): boolean;
|
|
21
|
-
/**
|
|
22
|
-
* Interpolate params into a path pattern.
|
|
23
|
-
*/
|
|
24
|
-
export declare function interpolatePath(pattern: string, params: Record<string, string>): string;
|
|
25
|
-
/**
|
|
26
|
-
* Join parent and child path segments with normalization.
|
|
27
|
-
*/
|
|
28
|
-
export declare function joinPaths(parent: string, child: string): string;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export declare function flushPendingScrollRestoration(): void;
|
|
2
|
-
export declare const scrollRestoration: {
|
|
3
|
-
disable: typeof disableScrollRestoration;
|
|
4
|
-
enable: typeof enableScrollRestoration;
|
|
5
|
-
};
|
|
6
|
-
export declare function enableScrollRestoration(): void;
|
|
7
|
-
declare function disableScrollRestoration(): void;
|
|
8
|
-
export {};
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
export type ParamSchema<T> = {
|
|
2
|
-
readonly cached: boolean;
|
|
3
|
-
readonly default: T;
|
|
4
|
-
readonly shouldReplace: boolean;
|
|
5
|
-
parse(value: string | null): T;
|
|
6
|
-
serialize(value: T): string;
|
|
7
|
-
};
|
|
8
|
-
type ParamSchemaBuilder<T> = ParamSchema<T> & {
|
|
9
|
-
/** Cache this param's value when navigating away, restore when returning. */
|
|
10
|
-
cache(): ParamSchemaBuilder<T>;
|
|
11
|
-
/** Use history.replaceState instead of pushState when updating this param. */
|
|
12
|
-
replace(): ParamSchemaBuilder<T>;
|
|
13
|
-
};
|
|
14
|
-
export type AnyParamSchema = ParamSchema<unknown>;
|
|
15
|
-
export type SearchParamsSchema = Record<string, AnyParamSchema>;
|
|
16
|
-
export type InferParamType<S> = S extends ParamSchema<infer T> ? T : never;
|
|
17
|
-
export type InferSearchParams<S extends SearchParamsSchema> = {
|
|
18
|
-
[K in keyof S]: InferParamType<S[K]>;
|
|
19
|
-
};
|
|
20
|
-
declare function createStringSchema(defaultValue: string): ParamSchemaBuilder<string>;
|
|
21
|
-
declare function createNumberSchema(defaultValue: number): ParamSchemaBuilder<number>;
|
|
22
|
-
declare function createBooleanSchema(defaultValue: boolean): ParamSchemaBuilder<boolean>;
|
|
23
|
-
declare function createEnumSchema<const T extends readonly string[]>(values: T, defaultValue?: T[number]): ParamSchemaBuilder<T[number]>;
|
|
24
|
-
/**
|
|
25
|
-
* Schema builder for typed search params.
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* ```ts
|
|
29
|
-
* const routes = createRouter({
|
|
30
|
-
* search: {
|
|
31
|
-
* path: '/search',
|
|
32
|
-
* element: <Search />,
|
|
33
|
-
* searchParams: {
|
|
34
|
-
* q: s.string(''),
|
|
35
|
-
* page: s.number(1),
|
|
36
|
-
* sort: s.enum(['date', 'relevance'], 'relevance'),
|
|
37
|
-
* },
|
|
38
|
-
* },
|
|
39
|
-
* });
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
export declare const s: {
|
|
43
|
-
boolean: typeof createBooleanSchema;
|
|
44
|
-
enum: typeof createEnumSchema;
|
|
45
|
-
number: typeof createNumberSchema;
|
|
46
|
-
string: typeof createStringSchema;
|
|
47
|
-
};
|
|
48
|
-
/**
|
|
49
|
-
* Parse search params from a URL search string using a schema.
|
|
50
|
-
*/
|
|
51
|
-
export declare function parseSearchParams<S extends SearchParamsSchema>(search: string, schema: S): InferSearchParams<S>;
|
|
52
|
-
export declare function serializeSearchParams<S extends SearchParamsSchema>(values: InferSearchParams<S>, schema: S): string;
|
|
53
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
declare const routes: {
|
|
2
|
-
readonly detail: {
|
|
3
|
-
readonly path: "film/:id";
|
|
4
|
-
readonly element: any;
|
|
5
|
-
readonly prefetch: (_params: {
|
|
6
|
-
id: string;
|
|
7
|
-
} & Record<string, string>) => void;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
declare const routes2: {
|
|
11
|
-
readonly detail: {
|
|
12
|
-
readonly path: "film/:id";
|
|
13
|
-
readonly element: any;
|
|
14
|
-
readonly prefetch: (params: Record<never, never> & Record<string, string>) => void;
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
export { routes, routes2 };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Location, To } from './types';
|
|
2
|
-
export declare function parsePath(path: string): Location;
|
|
3
|
-
export declare function formatHref(loc: Pick<Location, 'pathname' | 'search' | 'hash'>): string;
|
|
4
|
-
export declare function resolveTo(to: To, current: Pick<Location, 'pathname'>): Location;
|
|
5
|
-
type ClickEvent = {
|
|
6
|
-
altKey: boolean;
|
|
7
|
-
button: number;
|
|
8
|
-
ctrlKey: boolean;
|
|
9
|
-
defaultPrevented: boolean;
|
|
10
|
-
metaKey: boolean;
|
|
11
|
-
shiftKey: boolean;
|
|
12
|
-
};
|
|
13
|
-
export declare function shouldNavigate(e: ClickEvent): boolean;
|
|
14
|
-
export {};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export type HeartbeatConfig<T> = {
|
|
2
|
-
/** Interval in milliseconds between heartbeat broadcasts */
|
|
3
|
-
interval: number;
|
|
4
|
-
behavior: 'reuse';
|
|
5
|
-
} | {
|
|
6
|
-
interval: number;
|
|
7
|
-
behavior: 'refresh-activity';
|
|
8
|
-
activityField: string;
|
|
9
|
-
} | {
|
|
10
|
-
interval: number;
|
|
11
|
-
behavior: 'transform';
|
|
12
|
-
onHeartbeat: (currentData: T) => T | void;
|
|
13
|
-
};
|
|
14
|
-
export type HeartbeatManager = {
|
|
15
|
-
readonly start: () => void;
|
|
16
|
-
readonly stop: () => void;
|
|
17
|
-
readonly destroy: () => void;
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Creates a heartbeat manager that automatically broadcasts presence at intervals.
|
|
21
|
-
* Allows optional transformation of the payload before each broadcast.
|
|
22
|
-
*/
|
|
23
|
-
export declare function createHeartbeatManager<T>(config: HeartbeatConfig<T>, getCurrentData: () => T | null, broadcast: (data: T) => void): HeartbeatManager;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { SyncPresenceChannel, SyncPresenceRegistration } from '../sync/types';
|
|
2
|
-
import { SyncTransport } from '../sync/transport';
|
|
3
|
-
/**
|
|
4
|
-
* Internal interface for NetworkSyncEngine to dispatch remote presence events.
|
|
5
|
-
* Separated from public SyncPresenceChannel to maintain clean boundaries.
|
|
6
|
-
*/
|
|
7
|
-
export type PresenceChannelInternal<T> = {
|
|
8
|
-
readonly channel: SyncPresenceChannel<T>;
|
|
9
|
-
readonly handleRemoteJoin: (userId: string, data: T) => void;
|
|
10
|
-
readonly handleRemoteUpdate: (userId: string, data: T) => void;
|
|
11
|
-
readonly handleRemoteLeave: (userId: string) => void;
|
|
12
|
-
readonly handleConnectionLost: () => void;
|
|
13
|
-
readonly handleConnectionRestored: () => void;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Creates a presence channel with automatic heartbeat and pruning.
|
|
17
|
-
* Returns both public interface and internal handlers for the sync engine.
|
|
18
|
-
*/
|
|
19
|
-
export declare function createPresenceChannel<T>(key: string, transport: SyncTransport, registration: SyncPresenceRegistration<T>, isConnected: () => boolean): PresenceChannelInternal<T>;
|