@vertz/ui 0.2.0 → 0.2.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 +339 -857
- package/dist/css/public.d.ts +24 -27
- package/dist/css/public.js +5 -1
- package/dist/form/public.d.ts +94 -38
- package/dist/form/public.js +5 -3
- package/dist/index.d.ts +696 -167
- package/dist/index.js +461 -84
- package/dist/internals.d.ts +192 -23
- package/dist/internals.js +151 -102
- package/dist/jsx-runtime/index.d.ts +44 -17
- package/dist/jsx-runtime/index.js +26 -7
- package/dist/query/public.d.ts +62 -7
- package/dist/query/public.js +12 -4
- package/dist/router/public.d.ts +186 -26
- package/dist/router/public.js +22 -7
- package/dist/shared/{chunk-f1ynwam4.js → chunk-0p5f7gmg.js} +155 -32
- package/dist/shared/{chunk-j8vzvne3.js → chunk-9e92w0wt.js} +4 -1
- package/dist/shared/{chunk-xd9d7q5p.js → chunk-cq7xg4xe.js} +59 -10
- package/dist/shared/chunk-g4rch80a.js +33 -0
- package/dist/shared/{chunk-pgymxpn1.js → chunk-hrd0mft1.js} +136 -34
- package/dist/shared/chunk-nmjyj8p9.js +290 -0
- package/dist/shared/chunk-pp3a6xbn.js +483 -0
- package/dist/shared/chunk-prj7nm08.js +67 -0
- package/dist/shared/chunk-q6cpe5k7.js +230 -0
- package/dist/shared/chunk-ryb49346.js +374 -0
- package/dist/shared/chunk-v3yyf79g.js +48 -0
- package/dist/shared/chunk-vx0kzack.js +103 -0
- package/dist/shared/chunk-wv6kkj1w.js +464 -0
- package/dist/test/index.d.ts +67 -6
- package/dist/test/index.js +4 -3
- package/package.json +13 -8
- package/dist/shared/chunk-bp3v6s9j.js +0 -62
- package/dist/shared/chunk-d8h2eh8d.js +0 -141
- package/dist/shared/chunk-tsdpgmks.js +0 -98
- package/dist/shared/chunk-zbbvx05f.js +0 -202
|
@@ -1,31 +1,50 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* JSX
|
|
3
|
-
*
|
|
4
|
-
* At build time, the @vertz/ui-compiler transforms JSX into optimized
|
|
5
|
-
* __element() / __on() / __text() / __attr() calls with compile-time
|
|
6
|
-
* reactivity analysis. This runtime provides a simpler DOM-based
|
|
7
|
-
* implementation for tests and development.
|
|
8
|
-
*
|
|
9
|
-
* Implements the "react-jsx" automatic runtime interface:
|
|
10
|
-
* - jsx(type, props) — single child
|
|
11
|
-
* - jsxs(type, props) — multiple children
|
|
12
|
-
* - Fragment — document fragment
|
|
2
|
+
* JSX namespace - required for TypeScript's react-jsx mode
|
|
3
|
+
* to understand intrinsic element types and component types.
|
|
13
4
|
*/
|
|
14
|
-
|
|
15
|
-
type
|
|
5
|
+
declare namespace JSX {
|
|
6
|
+
type Element = HTMLElement | SVGElement;
|
|
7
|
+
type JSXComponent = (props: Record<string, unknown>) => Element;
|
|
8
|
+
interface HTMLAttributes {
|
|
9
|
+
[key: string]: unknown;
|
|
10
|
+
children?: unknown;
|
|
11
|
+
}
|
|
12
|
+
interface IntrinsicAttributes {
|
|
13
|
+
key?: string | number;
|
|
14
|
+
}
|
|
15
|
+
interface IntrinsicElements {
|
|
16
|
+
[key: string]: HTMLAttributes | undefined;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
16
19
|
/**
|
|
17
20
|
* JSX factory function for client-side rendering.
|
|
18
21
|
*
|
|
19
22
|
* When tag is a function (component), calls it with props.
|
|
20
23
|
* When tag is a string (HTML element), creates a DOM element.
|
|
21
24
|
*/
|
|
22
|
-
declare function jsx(tag:
|
|
25
|
+
declare function jsx<K extends keyof HTMLElementTagNameMap>(tag: K, props: Record<string, unknown> | null | undefined): HTMLElementTagNameMap[K];
|
|
26
|
+
declare function jsx(tag: string, props: Record<string, unknown> | null | undefined): HTMLElement;
|
|
27
|
+
declare function jsx<
|
|
28
|
+
P extends Record<string, unknown>,
|
|
29
|
+
R extends JSX.Element
|
|
30
|
+
>(tag: (props: P) => R, props: P): R;
|
|
31
|
+
declare function jsx(tag: typeof Fragment, props: {
|
|
32
|
+
children?: unknown;
|
|
33
|
+
}): DocumentFragment;
|
|
23
34
|
/**
|
|
24
35
|
* JSX factory for elements with multiple children.
|
|
25
36
|
* In the automatic runtime, this is used when there are multiple children.
|
|
26
37
|
* For our implementation, it's the same as jsx().
|
|
27
38
|
*/
|
|
28
|
-
declare
|
|
39
|
+
declare function jsxs<K extends keyof HTMLElementTagNameMap>(tag: K, props: Record<string, unknown> | null | undefined): HTMLElementTagNameMap[K];
|
|
40
|
+
declare function jsxs(tag: string, props: Record<string, unknown> | null | undefined): HTMLElement;
|
|
41
|
+
declare function jsxs<
|
|
42
|
+
P extends Record<string, unknown>,
|
|
43
|
+
R extends JSX.Element
|
|
44
|
+
>(tag: (props: P) => R, props: P): R;
|
|
45
|
+
declare function jsxs(tag: typeof Fragment, props: {
|
|
46
|
+
children?: unknown;
|
|
47
|
+
}): DocumentFragment;
|
|
29
48
|
/**
|
|
30
49
|
* Fragment component — a DocumentFragment container for multiple children.
|
|
31
50
|
*/
|
|
@@ -36,5 +55,13 @@ declare function Fragment(props: {
|
|
|
36
55
|
* JSX development mode factory (used with @jsxImportSource in tsconfig).
|
|
37
56
|
* Same as jsx() for our implementation.
|
|
38
57
|
*/
|
|
39
|
-
declare
|
|
40
|
-
|
|
58
|
+
declare function jsxDEV<K extends keyof HTMLElementTagNameMap>(tag: K, props: Record<string, unknown> | null | undefined): HTMLElementTagNameMap[K];
|
|
59
|
+
declare function jsxDEV(tag: string, props: Record<string, unknown> | null | undefined): HTMLElement;
|
|
60
|
+
declare function jsxDEV<
|
|
61
|
+
P extends Record<string, unknown>,
|
|
62
|
+
R extends JSX.Element
|
|
63
|
+
>(tag: (props: P) => R, props: P): R;
|
|
64
|
+
declare function jsxDEV(tag: typeof Fragment, props: {
|
|
65
|
+
children?: unknown;
|
|
66
|
+
}): DocumentFragment;
|
|
67
|
+
export { jsxs, jsxDEV, jsx, JSX, Fragment };
|
|
@@ -1,7 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SVG_NS,
|
|
3
|
+
isSVGTag,
|
|
4
|
+
normalizeSVGAttr
|
|
5
|
+
} from "../shared/chunk-prj7nm08.js";
|
|
6
|
+
|
|
1
7
|
// src/jsx-runtime/index.ts
|
|
2
8
|
function applyChildren(parent, children) {
|
|
3
9
|
if (children == null || children === false || children === true)
|
|
4
10
|
return;
|
|
11
|
+
if (typeof children === "function") {
|
|
12
|
+
applyChildren(parent, children());
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
5
15
|
if (Array.isArray(children)) {
|
|
6
16
|
for (const child of children) {
|
|
7
17
|
applyChildren(parent, child);
|
|
@@ -12,36 +22,45 @@ function applyChildren(parent, children) {
|
|
|
12
22
|
parent.appendChild(document.createTextNode(String(children)));
|
|
13
23
|
}
|
|
14
24
|
}
|
|
15
|
-
function
|
|
25
|
+
function jsxImpl(tag, props) {
|
|
16
26
|
if (typeof tag === "function") {
|
|
17
|
-
return tag(props);
|
|
27
|
+
return tag(props || {});
|
|
18
28
|
}
|
|
19
29
|
const { children, ...attrs } = props || {};
|
|
20
|
-
const
|
|
30
|
+
const svg = isSVGTag(tag);
|
|
31
|
+
const element = svg ? document.createElementNS(SVG_NS, tag) : document.createElement(tag);
|
|
21
32
|
for (const [key, value] of Object.entries(attrs)) {
|
|
22
33
|
if (key.startsWith("on") && typeof value === "function") {
|
|
23
34
|
const eventName = key.slice(2).toLowerCase();
|
|
24
35
|
element.addEventListener(eventName, value);
|
|
25
36
|
} else if (key === "class" && value != null) {
|
|
26
|
-
element.
|
|
37
|
+
element.setAttribute("class", String(value));
|
|
27
38
|
} else if (key === "style" && value != null) {
|
|
28
39
|
element.setAttribute("style", String(value));
|
|
29
40
|
} else if (value === true) {
|
|
30
41
|
element.setAttribute(key, "");
|
|
31
42
|
} else if (value != null && value !== false) {
|
|
32
|
-
|
|
43
|
+
const attrName = svg ? normalizeSVGAttr(key) : key;
|
|
44
|
+
element.setAttribute(attrName, String(value));
|
|
33
45
|
}
|
|
34
46
|
}
|
|
35
47
|
applyChildren(element, children);
|
|
36
48
|
return element;
|
|
37
49
|
}
|
|
38
|
-
|
|
50
|
+
function jsx(tag, props) {
|
|
51
|
+
return jsxImpl(tag, props);
|
|
52
|
+
}
|
|
53
|
+
function jsxs(tag, props) {
|
|
54
|
+
return jsxImpl(tag, props);
|
|
55
|
+
}
|
|
39
56
|
function Fragment(props) {
|
|
40
57
|
const frag = document.createDocumentFragment();
|
|
41
58
|
applyChildren(frag, props?.children);
|
|
42
59
|
return frag;
|
|
43
60
|
}
|
|
44
|
-
|
|
61
|
+
function jsxDEV(tag, props) {
|
|
62
|
+
return jsxImpl(tag, props);
|
|
63
|
+
}
|
|
45
64
|
export {
|
|
46
65
|
jsxs,
|
|
47
66
|
jsxDEV,
|
package/dist/query/public.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { QueryDescriptor as QueryDescriptor2 } from "@vertz/fetch";
|
|
2
|
+
import { isQueryDescriptor } from "@vertz/fetch";
|
|
1
3
|
/**
|
|
2
4
|
* Interface for cache stores used by query().
|
|
3
5
|
* Consumers can provide custom implementations (e.g. LRU, persistent storage).
|
|
@@ -6,7 +8,9 @@ interface CacheStore<T = unknown> {
|
|
|
6
8
|
get(key: string): T | undefined;
|
|
7
9
|
set(key: string, value: T): void;
|
|
8
10
|
delete(key: string): void;
|
|
11
|
+
clear?(): void;
|
|
9
12
|
}
|
|
13
|
+
import { QueryDescriptor } from "@vertz/fetch";
|
|
10
14
|
/**
|
|
11
15
|
* A read-only reactive value derived from other signals.
|
|
12
16
|
*/
|
|
@@ -16,6 +20,17 @@ interface ReadonlySignal<T> {
|
|
|
16
20
|
/** Read the current value without subscribing. */
|
|
17
21
|
peek(): T;
|
|
18
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Unwraps a ReadonlySignal to its value type.
|
|
25
|
+
* Used by signal APIs (like query()) to expose plain values in TypeScript
|
|
26
|
+
* while the compiler auto-unwraps them at runtime.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* type UnwrappedData = Unwrapped<ReadonlySignal<Task | undefined>>; // → Task | undefined
|
|
30
|
+
*/
|
|
31
|
+
type Unwrapped<T> = T extends ReadonlySignal<infer U> ? U : T;
|
|
32
|
+
/** Dispose function returned by effect(). */
|
|
33
|
+
type DisposeFn = () => void;
|
|
19
34
|
/** Options for query(). */
|
|
20
35
|
interface QueryOptions<T> {
|
|
21
36
|
/** Pre-populated data — skips the initial fetch when provided. */
|
|
@@ -28,15 +43,22 @@ interface QueryOptions<T> {
|
|
|
28
43
|
key?: string;
|
|
29
44
|
/** Custom cache store. Defaults to a shared in-memory Map. */
|
|
30
45
|
cache?: CacheStore<T>;
|
|
46
|
+
/** Timeout in ms for SSR data loading. Default: 300. Set to 0 to disable. */
|
|
47
|
+
ssrTimeout?: number;
|
|
31
48
|
}
|
|
32
49
|
/** The reactive object returned by query(). */
|
|
33
|
-
interface QueryResult<
|
|
50
|
+
interface QueryResult<
|
|
51
|
+
T,
|
|
52
|
+
E = unknown
|
|
53
|
+
> {
|
|
34
54
|
/** The fetched data, or undefined while loading. */
|
|
35
|
-
readonly data: ReadonlySignal<T | undefined
|
|
36
|
-
/** True
|
|
37
|
-
readonly loading: ReadonlySignal<boolean
|
|
55
|
+
readonly data: Unwrapped<ReadonlySignal<T | undefined>>;
|
|
56
|
+
/** True only on the initial load (no data yet). False during revalidation. */
|
|
57
|
+
readonly loading: Unwrapped<ReadonlySignal<boolean>>;
|
|
58
|
+
/** True when refetching while stale data is already available. */
|
|
59
|
+
readonly revalidating: Unwrapped<ReadonlySignal<boolean>>;
|
|
38
60
|
/** The error from the latest failed fetch, or undefined. */
|
|
39
|
-
readonly error: ReadonlySignal<
|
|
61
|
+
readonly error: Unwrapped<ReadonlySignal<E | undefined>>;
|
|
40
62
|
/** Manually trigger a refetch (clears cache for this key). */
|
|
41
63
|
refetch: () => void;
|
|
42
64
|
/** Alias for refetch — revalidate the cached data. */
|
|
@@ -50,9 +72,42 @@ interface QueryResult<T> {
|
|
|
50
72
|
* The thunk is wrapped in an effect so that when reactive dependencies
|
|
51
73
|
* used *before* the async call change, the query automatically re-fetches.
|
|
52
74
|
*
|
|
53
|
-
* @param
|
|
75
|
+
* @param source - A QueryDescriptor or an async function that returns the data.
|
|
54
76
|
* @param options - Optional configuration.
|
|
55
77
|
* @returns A QueryResult with reactive signals for data, loading, and error.
|
|
56
78
|
*/
|
|
79
|
+
declare function query<
|
|
80
|
+
T,
|
|
81
|
+
E
|
|
82
|
+
>(descriptor: QueryDescriptor<T, E>, options?: Omit<QueryOptions<T>, "key">): QueryResult<T, E>;
|
|
57
83
|
declare function query<T>(thunk: () => Promise<T>, options?: QueryOptions<T>): QueryResult<T>;
|
|
58
|
-
|
|
84
|
+
interface QueryMatchHandlers<
|
|
85
|
+
T,
|
|
86
|
+
E
|
|
87
|
+
> {
|
|
88
|
+
loading: () => Node | null;
|
|
89
|
+
error: (error: E) => Node | null;
|
|
90
|
+
data: (data: T) => Node | null;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Pattern-match on a QueryResult's exclusive state.
|
|
94
|
+
*
|
|
95
|
+
* Returns a stable `<span style="display:contents">` wrapper that internally
|
|
96
|
+
* manages branch switching (loading/error/data) via a reactive effect.
|
|
97
|
+
* The same wrapper is returned for repeated calls with the same queryResult
|
|
98
|
+
* (cached via WeakMap), enabling __child's stable-node optimization.
|
|
99
|
+
*
|
|
100
|
+
* Priority: loading → error → data.
|
|
101
|
+
*
|
|
102
|
+
* `loading` only fires on the initial load (no data yet).
|
|
103
|
+
* When revalidating with existing data, the `data` handler receives the
|
|
104
|
+
* current data. Access `query.revalidating` from the component scope for
|
|
105
|
+
* revalidation state.
|
|
106
|
+
*/
|
|
107
|
+
declare function queryMatch<
|
|
108
|
+
T,
|
|
109
|
+
E
|
|
110
|
+
>(queryResult: QueryResult<T, E>, handlers: QueryMatchHandlers<T, E>): HTMLElement & {
|
|
111
|
+
dispose: DisposeFn;
|
|
112
|
+
};
|
|
113
|
+
export { queryMatch, query, isQueryDescriptor, QueryResult, QueryOptions, QueryMatchHandlers, QueryDescriptor2 as QueryDescriptor, CacheStore };
|
package/dist/query/public.js
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
|
-
query
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
query,
|
|
3
|
+
queryMatch
|
|
4
|
+
} from "../shared/chunk-wv6kkj1w.js";
|
|
5
|
+
import"../shared/chunk-vx0kzack.js";
|
|
6
|
+
import"../shared/chunk-g4rch80a.js";
|
|
7
|
+
import"../shared/chunk-hrd0mft1.js";
|
|
8
|
+
|
|
9
|
+
// src/query/public.ts
|
|
10
|
+
import { isQueryDescriptor } from "@vertz/fetch";
|
|
5
11
|
export {
|
|
6
|
-
|
|
12
|
+
queryMatch,
|
|
13
|
+
query,
|
|
14
|
+
isQueryDescriptor
|
|
7
15
|
};
|
package/dist/router/public.d.ts
CHANGED
|
@@ -25,9 +25,34 @@ type ExtractParams<T extends string> = [ExtractParamsFromSegments<WithoutWildcar
|
|
|
25
25
|
} : Record<string, never> : HasWildcard<T> extends true ? { [K in ExtractParamsFromSegments<WithoutWildcard<T>>] : string } & {
|
|
26
26
|
"*": string;
|
|
27
27
|
} : { [K in ExtractParamsFromSegments<WithoutWildcard<T>>] : string };
|
|
28
|
+
/**
|
|
29
|
+
* Convert a route pattern to the union of URL shapes it accepts.
|
|
30
|
+
* - Static: `'/'` → `'/'`
|
|
31
|
+
* - Param: `'/tasks/:id'` → `` `/tasks/${string}` ``
|
|
32
|
+
* - Wildcard: `'/files/*'` → `` `/files/${string}` ``
|
|
33
|
+
* - Multi: `'/users/:id/posts/:postId'` → `` `/users/${string}/posts/${string}` ``
|
|
34
|
+
* - Fallback: `string` → `string` (backward compat)
|
|
35
|
+
*/
|
|
36
|
+
type PathWithParams<T extends string> = T extends `${infer Before}*` ? `${PathWithParams<Before>}${string}` : T extends `${infer Before}:${string}/${infer After}` ? `${Before}${string}/${PathWithParams<`${After}`>}` : T extends `${infer Before}:${string}` ? `${Before}${string}` : T;
|
|
37
|
+
/**
|
|
38
|
+
* Union of all valid URL shapes for a route map.
|
|
39
|
+
* Maps each route pattern key through `PathWithParams` to produce the accepted URL shapes.
|
|
40
|
+
*
|
|
41
|
+
* Example:
|
|
42
|
+
* ```
|
|
43
|
+
* RoutePaths<{ '/': ..., '/tasks/:id': ... }> = '/' | `/tasks/${string}`
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
type RoutePaths<TRouteMap extends Record<string, unknown>> = { [K in keyof TRouteMap & string] : PathWithParams<K> }[keyof TRouteMap & string];
|
|
28
47
|
/** Simple schema interface for search param parsing. */
|
|
29
48
|
interface SearchParamSchema<T> {
|
|
30
|
-
parse(data: unknown):
|
|
49
|
+
parse(data: unknown): {
|
|
50
|
+
ok: true;
|
|
51
|
+
data: T;
|
|
52
|
+
} | {
|
|
53
|
+
ok: false;
|
|
54
|
+
error: unknown;
|
|
55
|
+
};
|
|
31
56
|
}
|
|
32
57
|
/** A route configuration for a single path. */
|
|
33
58
|
interface RouteConfig<
|
|
@@ -55,6 +80,46 @@ interface RouteConfig<
|
|
|
55
80
|
interface RouteDefinitionMap {
|
|
56
81
|
[pattern: string]: RouteConfig;
|
|
57
82
|
}
|
|
83
|
+
/**
|
|
84
|
+
* Loose route config used as the generic constraint for `defineRoutes`.
|
|
85
|
+
* Uses `Record<string, string>` for loader params so any concrete loader
|
|
86
|
+
* that accesses string params (e.g., `params.id`) satisfies the constraint.
|
|
87
|
+
*/
|
|
88
|
+
interface RouteConfigLike {
|
|
89
|
+
component: () => Node | Promise<{
|
|
90
|
+
default: () => Node;
|
|
91
|
+
}>;
|
|
92
|
+
/**
|
|
93
|
+
* Method syntax (`loader?(ctx): R`) is intentional — it enables **bivariant**
|
|
94
|
+
* parameter checking under `strictFunctionTypes`. Property syntax
|
|
95
|
+
* (`loader?: (ctx) => R`) would be contravariant, causing `RouteConfig<string>`
|
|
96
|
+
* (whose loader has `params: Record<string, never>`) to fail assignability
|
|
97
|
+
* against this constraint's `params: Record<string, string>`.
|
|
98
|
+
*/
|
|
99
|
+
loader?(ctx: {
|
|
100
|
+
params: Record<string, string>;
|
|
101
|
+
signal: AbortSignal;
|
|
102
|
+
}): unknown;
|
|
103
|
+
errorComponent?: (error: Error) => Node;
|
|
104
|
+
searchParams?: SearchParamSchema<unknown>;
|
|
105
|
+
children?: Record<string, RouteConfigLike>;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Phantom branded array that carries the route map type `T`.
|
|
109
|
+
* The `__routes` property never exists at runtime — it is a type-level
|
|
110
|
+
* marker used to thread the developer's literal route keys through
|
|
111
|
+
* `createRouter`, `useRouter`, etc.
|
|
112
|
+
*/
|
|
113
|
+
type TypedRoutes<T extends Record<string, RouteConfigLike> = RouteDefinitionMap> = CompiledRoute[] & {
|
|
114
|
+
readonly __routes: T;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Extract the route map type from `TypedRoutes<T>`.
|
|
118
|
+
* If `T` is not a `TypedRoutes`, returns `T` as-is (passthrough).
|
|
119
|
+
*
|
|
120
|
+
* Usage: `useRouter<InferRouteMap<typeof routes>>()`
|
|
121
|
+
*/
|
|
122
|
+
type InferRouteMap<T> = T extends TypedRoutes<infer R> ? R : T;
|
|
58
123
|
/** Internal compiled route. */
|
|
59
124
|
interface CompiledRoute {
|
|
60
125
|
/** The original path pattern. */
|
|
@@ -100,7 +165,7 @@ type LoaderData<T> = T extends {
|
|
|
100
165
|
* Define routes from a configuration map.
|
|
101
166
|
* Returns an array of compiled routes preserving definition order.
|
|
102
167
|
*/
|
|
103
|
-
declare function defineRoutes(map:
|
|
168
|
+
declare function defineRoutes<const T extends Record<string, RouteConfigLike>>(map: T): TypedRoutes<T>;
|
|
104
169
|
/**
|
|
105
170
|
* A reactive signal that holds a value and notifies subscribers on change.
|
|
106
171
|
*/
|
|
@@ -123,16 +188,50 @@ interface ReadonlySignal<T> {
|
|
|
123
188
|
/** Read the current value without subscribing. */
|
|
124
189
|
peek(): T;
|
|
125
190
|
}
|
|
126
|
-
/**
|
|
127
|
-
|
|
191
|
+
/**
|
|
192
|
+
* Unwraps a ReadonlySignal to its value type.
|
|
193
|
+
* Used by signal APIs (like query()) to expose plain values in TypeScript
|
|
194
|
+
* while the compiler auto-unwraps them at runtime.
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* type UnwrappedData = Unwrapped<ReadonlySignal<Task | undefined>>; // → Task | undefined
|
|
198
|
+
*/
|
|
199
|
+
type Unwrapped<T> = T extends ReadonlySignal<infer U> ? U : T;
|
|
200
|
+
/**
|
|
201
|
+
* Unwraps all signal properties of an object type.
|
|
202
|
+
* Properties that are signals become their inner value type.
|
|
203
|
+
* Non-signal properties and primitive types pass through unchanged.
|
|
204
|
+
*
|
|
205
|
+
* Used by `useContext` to present context values without the Signal wrapper.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* type Settings = { theme: Signal<string>; setTheme: (t: string) => void };
|
|
209
|
+
* type Unwrapped = UnwrapSignals<Settings>; // { theme: string; setTheme: (t: string) => void }
|
|
210
|
+
*/
|
|
211
|
+
type UnwrapSignals<T> = T extends object ? { [K in keyof T] : Unwrapped<T[K]> } : T;
|
|
212
|
+
/**
|
|
213
|
+
* Props for the Link component.
|
|
214
|
+
*
|
|
215
|
+
* Generic over the route map `T`. Defaults to `RouteDefinitionMap` (string
|
|
216
|
+
* index signature) for backward compatibility — unparameterized `LinkProps`
|
|
217
|
+
* accepts any string href.
|
|
218
|
+
*/
|
|
219
|
+
interface LinkProps<T extends Record<string, RouteConfigLike> = RouteDefinitionMap> {
|
|
128
220
|
/** The target URL path. */
|
|
129
|
-
href:
|
|
130
|
-
/** Text or content for the link. */
|
|
131
|
-
children: string;
|
|
221
|
+
href: RoutePaths<T>;
|
|
222
|
+
/** Text or content for the link. Thunk may return string or Text node. */
|
|
223
|
+
children: string | (() => string | Node);
|
|
132
224
|
/** Class applied when the link's href matches the current path. */
|
|
133
225
|
activeClass?: string;
|
|
134
226
|
/** Static class name for the anchor element. */
|
|
135
227
|
className?: string;
|
|
228
|
+
/** Prefetch strategy. 'hover' triggers server pre-fetch on mouseenter/focus. */
|
|
229
|
+
prefetch?: "hover";
|
|
230
|
+
}
|
|
231
|
+
/** Options for createLink(). */
|
|
232
|
+
interface LinkFactoryOptions {
|
|
233
|
+
/** Callback fired when a link wants to prefetch its target URL. */
|
|
234
|
+
onPrefetch?: (url: string) => void;
|
|
136
235
|
}
|
|
137
236
|
/**
|
|
138
237
|
* Create a Link component factory bound to the router's state.
|
|
@@ -141,14 +240,43 @@ interface LinkProps {
|
|
|
141
240
|
* @param navigate - Navigation function from the router
|
|
142
241
|
* @returns A Link component function
|
|
143
242
|
*/
|
|
144
|
-
declare function createLink(currentPath: ReadonlySignal<string>, navigate: (url: string) => void): (props: LinkProps) => HTMLAnchorElement;
|
|
243
|
+
declare function createLink(currentPath: ReadonlySignal<string>, navigate: (url: string) => void, factoryOptions?: LinkFactoryOptions): (props: LinkProps) => HTMLAnchorElement;
|
|
145
244
|
/** Options for router.navigate(). */
|
|
146
245
|
interface NavigateOptions {
|
|
147
246
|
/** Use history.replaceState instead of pushState. */
|
|
148
247
|
replace?: boolean;
|
|
149
248
|
}
|
|
150
|
-
/**
|
|
151
|
-
interface
|
|
249
|
+
/** Handle returned by prefetchNavData for cancellation. */
|
|
250
|
+
interface PrefetchHandle {
|
|
251
|
+
abort: () => void;
|
|
252
|
+
/** Resolves when SSE stream completes (data or done event). */
|
|
253
|
+
done?: Promise<void>;
|
|
254
|
+
}
|
|
255
|
+
/** Options for createRouter(). */
|
|
256
|
+
interface RouterOptions {
|
|
257
|
+
/** Enable server-side navigation pre-fetch. When true, uses default timeout. */
|
|
258
|
+
serverNav?: boolean | {
|
|
259
|
+
timeout?: number;
|
|
260
|
+
};
|
|
261
|
+
/** @internal — injected for testing. Production uses the real module. */
|
|
262
|
+
_prefetchNavData?: (url: string, options?: {
|
|
263
|
+
timeout?: number;
|
|
264
|
+
}) => PrefetchHandle;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* The router instance returned by createRouter.
|
|
268
|
+
*
|
|
269
|
+
* Generic over the route map `T`. Defaults to `RouteDefinitionMap` (string
|
|
270
|
+
* index signature) for backward compatibility — unparameterized `Router`
|
|
271
|
+
* accepts any string in `navigate()`.
|
|
272
|
+
*
|
|
273
|
+
* Method syntax on `navigate`, `revalidate`, and `dispose` enables bivariant
|
|
274
|
+
* parameter checking under `strictFunctionTypes`. This means `Router<T>` is
|
|
275
|
+
* assignable to `Router` (the unparameterized default), which is required for
|
|
276
|
+
* storing typed routers in the `RouterContext` without contravariance errors.
|
|
277
|
+
* At call sites, TypeScript still enforces the `RoutePaths<T>` constraint.
|
|
278
|
+
*/
|
|
279
|
+
interface Router<T extends Record<string, RouteConfigLike> = RouteDefinitionMap> {
|
|
152
280
|
/** Current matched route (reactive signal). */
|
|
153
281
|
current: Signal<RouteMatch | null>;
|
|
154
282
|
/** Loader data from the current route's loaders (reactive signal). */
|
|
@@ -158,43 +286,75 @@ interface Router {
|
|
|
158
286
|
/** Parsed search params from the current route (reactive signal). */
|
|
159
287
|
searchParams: Signal<Record<string, unknown>>;
|
|
160
288
|
/** Navigate to a new URL path. */
|
|
161
|
-
navigate
|
|
289
|
+
navigate(url: RoutePaths<T>, options?: NavigateOptions): Promise<void>;
|
|
162
290
|
/** Re-run all loaders for the current route. */
|
|
163
|
-
revalidate
|
|
291
|
+
revalidate(): Promise<void>;
|
|
164
292
|
/** Remove popstate listener and clean up the router. */
|
|
165
|
-
dispose
|
|
293
|
+
dispose(): void;
|
|
166
294
|
}
|
|
167
295
|
/**
|
|
296
|
+
* Convenience alias for a typed router.
|
|
297
|
+
* `TypedRouter<T>` is identical to `Router<T>` — it exists for readability
|
|
298
|
+
* when the generic parameter makes the intent clearer.
|
|
299
|
+
*/
|
|
300
|
+
type TypedRouter<T extends Record<string, RouteConfigLike> = RouteDefinitionMap> = Router<T>;
|
|
301
|
+
/**
|
|
168
302
|
* Create a router instance.
|
|
169
303
|
*
|
|
170
304
|
* @param routes - Compiled route list from defineRoutes()
|
|
171
305
|
* @param initialUrl - The initial URL to match (optional; auto-detects from window.location or __SSR_URL__)
|
|
172
306
|
* @returns Router instance with reactive state and navigation methods
|
|
173
307
|
*/
|
|
174
|
-
declare function createRouter(routes:
|
|
308
|
+
declare function createRouter<T extends Record<string, RouteConfigLike> = RouteDefinitionMap>(routes: TypedRoutes<T>, initialUrl?: string, options?: RouterOptions): Router<T>;
|
|
309
|
+
/**
|
|
310
|
+
* Props for the JSX pattern of Context.Provider.
|
|
311
|
+
*
|
|
312
|
+
* `children` accepts both raw values (what TypeScript sees in JSX) and
|
|
313
|
+
* thunks (what the compiler produces). At compile time the compiler wraps
|
|
314
|
+
* JSX children in `() => ...`, but TypeScript checks the pre-compilation
|
|
315
|
+
* source where children are plain elements.
|
|
316
|
+
*/
|
|
317
|
+
interface ProviderJsxProps<T> {
|
|
318
|
+
value: T;
|
|
319
|
+
children: (() => unknown) | unknown;
|
|
320
|
+
}
|
|
175
321
|
/** A context object created by `createContext`. */
|
|
176
322
|
interface Context<T> {
|
|
177
|
-
/** Provide a value
|
|
178
|
-
Provider
|
|
323
|
+
/** Provide a value via callback pattern. */
|
|
324
|
+
Provider(value: T, fn: () => void): void;
|
|
325
|
+
/** Provide a value via JSX pattern (single-arg object with children thunk). */
|
|
326
|
+
Provider(props: ProviderJsxProps<T>): HTMLElement;
|
|
179
327
|
/** @internal — current value stack */
|
|
180
328
|
_stack: T[];
|
|
181
329
|
/** @internal — default value */
|
|
182
330
|
_default: T | undefined;
|
|
183
331
|
}
|
|
184
332
|
/** Context value for the Outlet. */
|
|
185
|
-
interface
|
|
186
|
-
/**
|
|
187
|
-
childComponent: (() => Node
|
|
188
|
-
|
|
189
|
-
|
|
333
|
+
interface OutletContextValue {
|
|
334
|
+
/** Reactive child component factory (may return async module). */
|
|
335
|
+
childComponent: Signal<(() => Node | Promise<{
|
|
336
|
+
default: () => Node;
|
|
337
|
+
}>) | undefined>;
|
|
338
|
+
/** Router instance for restoring context in async resolution. */
|
|
339
|
+
router: Router;
|
|
190
340
|
}
|
|
341
|
+
/** Shared context used by RouterView and Outlet. */
|
|
342
|
+
declare const OutletContext: Context<OutletContextValue>;
|
|
191
343
|
/**
|
|
192
|
-
*
|
|
344
|
+
* Outlet component — renders the nested child route.
|
|
193
345
|
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
346
|
+
* Must be called inside a layout component rendered by RouterView.
|
|
347
|
+
* Reads from OutletContext to determine which child to render.
|
|
196
348
|
*/
|
|
197
|
-
declare function
|
|
349
|
+
declare function Outlet(): Node;
|
|
350
|
+
declare const RouterContext: Context<Router>;
|
|
351
|
+
declare function useRouter<T extends Record<string, RouteConfigLike> = RouteDefinitionMap>(): UnwrapSignals<Router<T>>;
|
|
352
|
+
declare function useParams<TPath extends string = string>(): ExtractParams<TPath>;
|
|
353
|
+
interface RouterViewProps {
|
|
354
|
+
router: Router;
|
|
355
|
+
fallback?: () => Node;
|
|
356
|
+
}
|
|
357
|
+
declare function RouterView({ router, fallback }: RouterViewProps): HTMLElement;
|
|
198
358
|
/**
|
|
199
359
|
* Parse URLSearchParams into a typed object, optionally through a schema.
|
|
200
360
|
*
|
|
@@ -211,4 +371,4 @@ declare function parseSearchParams<T = Record<string, string>>(urlParams: URLSea
|
|
|
211
371
|
* @returns The current search params value
|
|
212
372
|
*/
|
|
213
373
|
declare function useSearchParams<T>(searchSignal: ReadonlySignal<T>): T;
|
|
214
|
-
export { useSearchParams, parseSearchParams, defineRoutes, createRouter,
|
|
374
|
+
export { useSearchParams, useRouter, useParams, parseSearchParams, defineRoutes, createRouter, createLink, TypedRoutes, TypedRouter, SearchParamSchema, RouterViewProps, RouterView, RouterContext, Router, RoutePaths, RouteMatch, RouteDefinitionMap, RouteConfig, PathWithParams, OutletContextValue, OutletContext, Outlet, NavigateOptions, MatchedRoute, LoaderData, LinkProps, InferRouteMap, ExtractParams, CompiledRoute };
|
package/dist/router/public.js
CHANGED
|
@@ -1,21 +1,36 @@
|
|
|
1
1
|
import {
|
|
2
|
+
Outlet,
|
|
3
|
+
OutletContext,
|
|
4
|
+
RouterContext,
|
|
5
|
+
RouterView,
|
|
2
6
|
createLink,
|
|
3
|
-
createOutlet,
|
|
4
7
|
parseSearchParams,
|
|
8
|
+
useParams,
|
|
9
|
+
useRouter,
|
|
5
10
|
useSearchParams
|
|
6
|
-
} from "../shared/chunk-
|
|
11
|
+
} from "../shared/chunk-nmjyj8p9.js";
|
|
12
|
+
import"../shared/chunk-v3yyf79g.js";
|
|
7
13
|
import {
|
|
8
14
|
createRouter
|
|
9
|
-
} from "../shared/chunk-
|
|
15
|
+
} from "../shared/chunk-cq7xg4xe.js";
|
|
10
16
|
import {
|
|
11
17
|
defineRoutes
|
|
12
|
-
} from "../shared/chunk-
|
|
13
|
-
import"../shared/chunk-
|
|
18
|
+
} from "../shared/chunk-9e92w0wt.js";
|
|
19
|
+
import"../shared/chunk-vx0kzack.js";
|
|
20
|
+
import"../shared/chunk-ryb49346.js";
|
|
21
|
+
import"../shared/chunk-g4rch80a.js";
|
|
22
|
+
import"../shared/chunk-hrd0mft1.js";
|
|
23
|
+
import"../shared/chunk-prj7nm08.js";
|
|
14
24
|
export {
|
|
15
25
|
useSearchParams,
|
|
26
|
+
useRouter,
|
|
27
|
+
useParams,
|
|
16
28
|
parseSearchParams,
|
|
17
29
|
defineRoutes,
|
|
18
30
|
createRouter,
|
|
19
|
-
|
|
20
|
-
|
|
31
|
+
createLink,
|
|
32
|
+
RouterView,
|
|
33
|
+
RouterContext,
|
|
34
|
+
OutletContext,
|
|
35
|
+
Outlet
|
|
21
36
|
};
|