what-core 0.14.0 → 0.15.0
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/LICENSE +21 -0
- package/README.md +64 -38
- package/a11y.d.ts +128 -0
- package/data.d.ts +294 -0
- package/dist/a11y.js +510 -0
- package/dist/a11y.min.js +413 -0
- package/dist/actions.js +158 -0
- package/dist/actions.min.js +112 -0
- package/dist/animation.js +481 -0
- package/dist/animation.min.js +295 -0
- package/dist/async.js +180 -0
- package/dist/async.min.js +134 -0
- package/dist/components.js +577 -0
- package/dist/components.min.js +413 -0
- package/dist/data.js +1212 -0
- package/dist/data.min.js +918 -0
- package/dist/diagnostics.js +187 -0
- package/dist/diagnostics.min.js +134 -0
- package/dist/dom.js +796 -0
- package/dist/dom.min.js +603 -0
- package/dist/entries/a11y.js +43 -0
- package/dist/entries/a11y.min.js +43 -0
- package/dist/entries/data.js +29 -0
- package/dist/entries/data.min.js +29 -0
- package/dist/entries/dom.js +45 -0
- package/dist/entries/dom.min.js +45 -0
- package/dist/entries/form.js +31 -0
- package/dist/entries/form.min.js +31 -0
- package/dist/entries/internal.js +123 -0
- package/dist/entries/internal.min.js +123 -0
- package/dist/entries/motion.js +23 -0
- package/dist/entries/motion.min.js +23 -0
- package/dist/entries/ui.js +25 -0
- package/dist/entries/ui.min.js +25 -0
- package/dist/env.js +5 -0
- package/dist/env.min.js +5 -0
- package/dist/errors.js +1518 -0
- package/dist/errors.min.js +548 -0
- package/dist/form.js +936 -0
- package/dist/form.min.js +703 -0
- package/dist/guardrails.js +84 -0
- package/dist/guardrails.min.js +55 -0
- package/dist/h.js +232 -0
- package/dist/h.min.js +171 -0
- package/dist/head.js +241 -0
- package/dist/head.min.js +207 -0
- package/dist/helpers.js +126 -0
- package/dist/helpers.min.js +98 -0
- package/dist/hooks.js +255 -0
- package/dist/hooks.min.js +153 -0
- package/dist/hot.js +215 -0
- package/dist/hot.min.js +24 -0
- package/dist/hydration-data.js +495 -0
- package/dist/hydration-data.min.js +371 -0
- package/dist/import-changes.js +273 -0
- package/dist/import-changes.min.js +272 -0
- package/dist/index.js +95 -0
- package/dist/index.min.js +95 -227
- package/dist/jsx-dev-runtime.js +10 -0
- package/dist/jsx-dev-runtime.min.js +10 -1
- package/dist/jsx-runtime.js +27 -0
- package/dist/jsx-runtime.min.js +15 -1
- package/dist/live.js +54 -0
- package/dist/live.min.js +49 -0
- package/dist/markup-rules.js +250 -0
- package/dist/markup-rules.min.js +213 -0
- package/dist/reactive.js +3334 -0
- package/dist/reactive.min.js +2033 -0
- package/dist/render.js +4746 -0
- package/dist/render.min.js +2797 -1
- package/dist/scheduler.js +225 -0
- package/dist/scheduler.min.js +162 -0
- package/dist/selector.js +11 -0
- package/dist/selector.min.js +10 -0
- package/dist/server-context.js +148 -0
- package/dist/server-context.min.js +121 -0
- package/dist/skeleton.js +342 -0
- package/dist/skeleton.min.js +310 -0
- package/dist/store.js +72 -0
- package/dist/store.min.js +50 -0
- package/dist/testing.js +720 -0
- package/dist/testing.min.js +458 -1
- package/dist/vnode-adoption.js +19 -0
- package/dist/vnode-adoption.min.js +19 -0
- package/dist/vnode-renderer.js +61 -0
- package/dist/vnode-renderer.min.js +47 -0
- package/dom.d.ts +44 -0
- package/form.d.ts +218 -0
- package/hot.d.ts +35 -0
- package/index.d.ts +421 -736
- package/internal.d.ts +284 -0
- package/jsx-runtime.d.ts +160 -137
- package/markup-rules.d.ts +83 -0
- package/motion.d.ts +156 -0
- package/package.json +117 -3
- package/render.d.ts +278 -29
- package/src/a11y.js +64 -59
- package/src/actions.js +226 -0
- package/src/animation.js +105 -57
- package/src/async.js +259 -0
- package/src/components.js +495 -144
- package/src/data.js +1410 -1159
- package/src/diagnostics.js +263 -0
- package/src/dom.js +1159 -872
- package/src/entries/a11y.js +24 -0
- package/src/entries/data.js +17 -0
- package/src/entries/dom.js +29 -0
- package/src/entries/form.js +16 -0
- package/src/entries/internal.js +63 -0
- package/src/entries/motion.js +13 -0
- package/src/entries/ui.js +13 -0
- package/src/env-development.js +12 -0
- package/src/env.js +33 -0
- package/src/errors.js +1144 -168
- package/src/form.js +723 -225
- package/src/guardrails.js +38 -126
- package/src/h.js +227 -152
- package/src/head.js +189 -19
- package/src/helpers.js +47 -75
- package/src/hooks.js +233 -248
- package/src/hot.js +316 -0
- package/src/hydration-data.js +859 -16
- package/src/import-changes.js +156 -0
- package/src/index.js +38 -188
- package/src/jsx-dev-runtime.js +7 -14
- package/src/jsx-runtime.js +25 -9
- package/src/live.js +80 -0
- package/src/markup-rules.js +387 -0
- package/src/reactive.js +4400 -862
- package/src/render.js +6502 -2570
- package/src/scheduler.js +56 -21
- package/src/selector.js +31 -0
- package/src/server-context.js +252 -22
- package/src/skeleton.js +22 -12
- package/src/store.js +17 -31
- package/src/testing.js +389 -63
- package/src/vnode-adoption.js +48 -0
- package/src/vnode-renderer.js +114 -0
- package/testing.d.ts +81 -1
- package/ui.d.ts +20 -0
- package/dist/chunk-6YOUZ6T4.min.js +0 -1
- package/dist/chunk-FN6HXME3.min.js +0 -11
- package/dist/chunk-VKZY7JPN.min.js +0 -1
- package/src/agent-context.js +0 -127
- package/src/warnings.js +0 -193
package/index.d.ts
CHANGED
|
@@ -1,20 +1,37 @@
|
|
|
1
1
|
// What Framework - TypeScript Definitions
|
|
2
|
+
//
|
|
3
|
+
// The root entry. Domain kits are declared beside it (a11y.d.ts, ui.d.ts,
|
|
4
|
+
// motion.d.ts, dom.d.ts, form.d.ts, data.d.ts), the compiled-JSX runtime in
|
|
5
|
+
// render.d.ts, and what sibling packages share in internal.d.ts.
|
|
2
6
|
|
|
3
7
|
export type Updater<T> = T | ((prev: T) => T);
|
|
4
8
|
|
|
5
9
|
// --- Reactive Primitives ---
|
|
6
10
|
|
|
7
11
|
export interface Signal<T> {
|
|
8
|
-
/** Read current value */
|
|
9
|
-
(): T;
|
|
10
12
|
/** Callable setter compatibility: sig(next) */
|
|
11
13
|
(value: Updater<T>): void;
|
|
14
|
+
/**
|
|
15
|
+
* Read current value. Declared after the write: TypeScript takes a function
|
|
16
|
+
* type's return from the last call signature, so a signal handed where an
|
|
17
|
+
* accessor is taken (`<For each={todos}>`, `untrack(count)`) gives `T`.
|
|
18
|
+
*/
|
|
19
|
+
(): T;
|
|
12
20
|
/** Setter method compatibility: sig.set(next) */
|
|
13
21
|
set(value: Updater<T>): void;
|
|
14
22
|
/** Read without dependency tracking */
|
|
15
23
|
peek(): T;
|
|
16
24
|
/** Subscribe to value changes */
|
|
17
25
|
subscribe(fn: (value: T) => void): () => void;
|
|
26
|
+
/**
|
|
27
|
+
* Change the value in place: `fn` receives the current value (an array or
|
|
28
|
+
* object to modify), then every reader is notified as a write would notify
|
|
29
|
+
* them, batched the same way, although the reference did not change. A
|
|
30
|
+
* computed that returns the value itself, or anything else equal to its last
|
|
31
|
+
* result, recomputes but does not notify its own readers: derive a new value
|
|
32
|
+
* (a copy, a length, a field) where a computed must see the change.
|
|
33
|
+
*/
|
|
34
|
+
mutate(fn: (value: T) => void): void;
|
|
18
35
|
_signal: true;
|
|
19
36
|
}
|
|
20
37
|
|
|
@@ -24,30 +41,187 @@ export interface Computed<T> {
|
|
|
24
41
|
_signal: true;
|
|
25
42
|
}
|
|
26
43
|
|
|
44
|
+
/**
|
|
45
|
+
* What computed() returns: a computed that may be async (its function returned
|
|
46
|
+
* a promise or an async iterable).
|
|
47
|
+
*/
|
|
48
|
+
export interface AsyncComputed<T> extends Computed<T> {
|
|
49
|
+
/**
|
|
50
|
+
* Read the value. For an async computed: in a binding, an effect or a
|
|
51
|
+
* computed, a value that has not landed, or is being fetched again, holds
|
|
52
|
+
* the reader, which keeps what it shows and runs again when the value lands;
|
|
53
|
+
* elsewhere (a handler, a component body) it is the last value that landed,
|
|
54
|
+
* and a read before the first one suspends the component.
|
|
55
|
+
*/
|
|
56
|
+
(): T;
|
|
57
|
+
/**
|
|
58
|
+
* The value without subscribing. For an async computed: the last value that
|
|
59
|
+
* landed, or undefined before the first; it never throws or suspends.
|
|
60
|
+
*/
|
|
61
|
+
peek(): T;
|
|
62
|
+
/**
|
|
63
|
+
* True while this value, or an async value it is computed from, has a value
|
|
64
|
+
* and is fetching a new one (a changed input, or refresh()). False on first
|
|
65
|
+
* load. Reactive: read it in JSX, `{users.pending() && <Spinner />}`.
|
|
66
|
+
*/
|
|
67
|
+
pending(): boolean;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** What a computed's function receives when it takes an argument. */
|
|
71
|
+
export interface ComputedRun {
|
|
72
|
+
/** Aborted when a newer run supersedes this one, or the computed is disposed. */
|
|
73
|
+
signal: AbortSignal;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** A value an async computed's function may return. */
|
|
77
|
+
export type AsyncResult<T> = PromiseLike<T> | AsyncIterable<T>;
|
|
78
|
+
|
|
27
79
|
export function signal<T>(initial: T, debugName?: string): Signal<T>;
|
|
28
|
-
export function computed<T>(fn: () => T): Computed<T>;
|
|
29
|
-
export function effect(fn: () => void | (() => void), opts?: { stable?: boolean }): () => void;
|
|
30
|
-
export function signalMemo<T>(fn: () => T): Computed<T>;
|
|
31
80
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
81
|
+
* A derived value, recomputed when read after what it reads changed. Its
|
|
82
|
+
* function may return a promise, a thenable or an async iterable: the
|
|
83
|
+
* computed is then an async value. It starts when created (an async function,
|
|
84
|
+
* or one that takes `{ signal }`) or when first read, keeps its last value
|
|
85
|
+
* while a newer run is in flight, supersedes and aborts older runs, and its
|
|
86
|
+
* readers hold until it lands. See docs/ASYNC.md.
|
|
87
|
+
*/
|
|
88
|
+
export function computed<T>(fn: (run: ComputedRun) => AsyncResult<T>): AsyncComputed<T>;
|
|
89
|
+
export function computed<T>(fn: (run: ComputedRun) => T): AsyncComputed<T>;
|
|
90
|
+
/**
|
|
91
|
+
* Run an async computed again now, superseding a run in flight. Its readers
|
|
92
|
+
* see it as pending (once it has a value) until the new value lands. Resolves
|
|
93
|
+
* with the value when it lands, rejects with its error.
|
|
94
|
+
*/
|
|
95
|
+
export function refresh<T>(computed: AsyncComputed<T>): Promise<T>;
|
|
96
|
+
/**
|
|
97
|
+
* True while an async value `fn` reads (directly or through computeds) has a
|
|
98
|
+
* value and is fetching a new one; false on first load. Tracked like a read.
|
|
99
|
+
*/
|
|
100
|
+
export function isPending(fn: () => unknown): boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Hold everything the writes inside `fn` reach until the async work they
|
|
103
|
+
* started has landed, then commit it in one flush. Writes outside `fn` commit
|
|
104
|
+
* as usual; writes after an `await` in `fn` are ordinary writes, as in React.
|
|
105
|
+
* Resolves when the transition commits; rejects with an async `fn`'s error.
|
|
106
|
+
* Inside an async action it commits with, it resolves once only the action
|
|
107
|
+
* keeps the commit waiting, so the action can await it.
|
|
36
108
|
*/
|
|
37
|
-
export function
|
|
109
|
+
export function startTransition(fn: () => void | Promise<unknown>): Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* React's useTransition. `isPending` is an ACCESSOR, not a boolean: call it,
|
|
112
|
+
* `isPending()`, true from the call to `startTransition` until that
|
|
113
|
+
* transition commits. `{isPending() && <Spinner />}` in JSX updates;
|
|
114
|
+
* `{isPending && ...}` is always truthy. A rejected action shows in the
|
|
115
|
+
* <ErrorBoundary> above the component, as in React 19; the returned promise
|
|
116
|
+
* rejects too.
|
|
117
|
+
*/
|
|
118
|
+
export function useTransition(): [isPending: () => boolean, startTransition: (fn: () => void | Promise<unknown>) => Promise<void>];
|
|
119
|
+
/**
|
|
120
|
+
* React 19's useOptimistic. `state` is an accessor (a signal, a computed) or a
|
|
121
|
+
* plain value: pass `likes`, not `likes()`, which is read once. `optimistic` is
|
|
122
|
+
* an ACCESSOR: `optimistic()` is `state` with the overlays added by
|
|
123
|
+
* `addOptimistic(value)` applied through `update` (or replacing it, without
|
|
124
|
+
* `update`). Each overlay lasts as long as the transition it was added in and
|
|
125
|
+
* drops when that commits, in the same flush as the real result. Call
|
|
126
|
+
* `addOptimistic` synchronously inside startTransition.
|
|
127
|
+
*/
|
|
128
|
+
export function useOptimistic<S>(state: Signal<S> | Computed<S> | (() => S)): [optimistic: () => S, addOptimistic: (value: S) => void];
|
|
129
|
+
export function useOptimistic<S, A>(state: Signal<S> | Computed<S> | (() => S), update: (current: S, value: A) => S): [optimistic: () => S, addOptimistic: (value: A) => void];
|
|
130
|
+
export function useOptimistic<S>(state: S): [optimistic: () => S, addOptimistic: (value: S) => void];
|
|
131
|
+
export function useOptimistic<S, A>(state: S, update: (current: S, value: A) => S): [optimistic: () => S, addOptimistic: (value: A) => void];
|
|
132
|
+
/**
|
|
133
|
+
* React 19's useActionState: `[state, dispatch, isPending]`, where `state` and
|
|
134
|
+
* `isPending` are ACCESSORS. `dispatch(payload)` runs
|
|
135
|
+
* `action(previousState, payload)` inside a transition; dispatches queue,
|
|
136
|
+
* each receiving the state the previous one returned. The new state commits
|
|
137
|
+
* with the transition, in the same flush as the data its action revalidated.
|
|
138
|
+
* An action that throws reaches the nearest <ErrorBoundary> and drops the
|
|
139
|
+
* dispatches queued behind it. `permalink` is where a <Form> posts before
|
|
140
|
+
* JavaScript has loaded; by default the page it is on (the form has no
|
|
141
|
+
* `action` attribute).
|
|
142
|
+
*/
|
|
143
|
+
export function useActionState<S, P = FormData>(
|
|
144
|
+
action: (previousState: S, payload: P) => S | Promise<S>,
|
|
145
|
+
initialState: S,
|
|
146
|
+
permalink?: string,
|
|
147
|
+
): [state: () => S, dispatch: ((payload: P) => void) & { permalink?: string }, isPending: () => boolean];
|
|
148
|
+
/** What useFormStatus() returns: the submission of the <Form> around the component. */
|
|
149
|
+
export interface FormStatus {
|
|
150
|
+
/** True from a submit until its transition commits, while any submission is pending. */
|
|
151
|
+
pending: () => boolean;
|
|
152
|
+
/** The FormData of the latest submission still pending, or null. */
|
|
153
|
+
data: () => FormData | null;
|
|
154
|
+
/** The form's method, or null outside a <Form>. */
|
|
155
|
+
method: string | null;
|
|
156
|
+
/** The form's action function, or null: for an action id (as React's is for a URL), and outside a <Form>. */
|
|
157
|
+
action: ((...args: any[]) => any) | null;
|
|
158
|
+
}
|
|
159
|
+
/** React 19's useFormStatus: the submission of the <Form> (what-server) this component renders in. */
|
|
160
|
+
export function useFormStatus(): FormStatus;
|
|
161
|
+
/**
|
|
162
|
+
* React 19's use(). A context reads like useContext. A promise returns its
|
|
163
|
+
* value once settled, or suspends the component until it settles: it must be
|
|
164
|
+
* made outside the component. An accessor (an async computed) is read like
|
|
165
|
+
* an untracked read, suspending the component while it has no value.
|
|
166
|
+
*/
|
|
167
|
+
export function use<T>(value: Context<T> | PromiseLike<T> | (() => T)): T;
|
|
168
|
+
/**
|
|
169
|
+
* Resolves once nothing is queued to run, no async computed is fetching, no
|
|
170
|
+
* transition is open and no <Suspense> waits on a promise. For tests and
|
|
171
|
+
* agents: act, `await settled()`, then read the DOM.
|
|
172
|
+
*/
|
|
173
|
+
export function settled(): Promise<void>;
|
|
174
|
+
export interface EffectOptions {
|
|
175
|
+
/** Re-runs skip dependency tracking and keep the first run's dependencies. */
|
|
176
|
+
stable?: boolean;
|
|
177
|
+
/**
|
|
178
|
+
* `'render'` (default) or `'user'`. In a flush, user-phase effects re-run
|
|
179
|
+
* only once no render-phase effect is queued, so they observe settled
|
|
180
|
+
* bindings. The first run is synchronous either way.
|
|
181
|
+
*/
|
|
182
|
+
phase?: 'render' | 'user';
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
export function effect(fn: () => void | (() => void), opts?: EffectOptions): () => void;
|
|
186
|
+
/**
|
|
187
|
+
* O(1) keyed selection. `isSelected(key)` is `key === source()`, but a reader
|
|
188
|
+
* depends on its key rather than on `source`: when the source moves from a to b,
|
|
189
|
+
* only the readers that asked about a or b re-run. The compiler rewrites
|
|
190
|
+
* `sel() === row.id` inside keyed `.map()` rows to use one automatically.
|
|
191
|
+
*/
|
|
192
|
+
export function createSelector<T>(source: () => T): (key: T) => boolean;
|
|
193
|
+
/**
|
|
194
|
+
* A live view of the object `source` returns: `view.name` reads the current
|
|
195
|
+
* value's `name`, so JSX built once from the view (a table cell's render
|
|
196
|
+
* function handed a row) follows a value replaced under `source` instead of
|
|
197
|
+
* being built again. In a keyed row, reading `view.id` while the row is built
|
|
198
|
+
* records only `id`: a replaced item with the same `id` keeps the row and its
|
|
199
|
+
* state. Read-only; reads `undefined` while `source` returns null or undefined.
|
|
200
|
+
*/
|
|
201
|
+
export function live<T extends object>(source: () => T | null | undefined): T;
|
|
202
|
+
/**
|
|
203
|
+
* Group signal writes so effects run once, when the outermost batch ends.
|
|
204
|
+
* Returns the callback's value.
|
|
205
|
+
*/
|
|
206
|
+
export function batch<T>(fn: () => T): T;
|
|
38
207
|
export function untrack<T>(fn: () => T): T;
|
|
39
208
|
export function flushSync(): void;
|
|
40
209
|
export function createRoot<T>(fn: (dispose: () => void) => T): T;
|
|
41
210
|
|
|
42
|
-
|
|
211
|
+
declare const ownerBrand: unique symbol;
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Opaque ownership scope handle: getOwner() is the only way to obtain one.
|
|
215
|
+
* Pair with runWithOwner() for async work. `disposals` holds what the scope
|
|
216
|
+
* disposes: cleanup functions and internal effect and computed nodes.
|
|
217
|
+
*/
|
|
43
218
|
export interface Owner {
|
|
44
|
-
|
|
219
|
+
readonly [ownerBrand]: true;
|
|
220
|
+
disposals: unknown[];
|
|
45
221
|
}
|
|
46
222
|
|
|
47
223
|
export function getOwner(): Owner | null;
|
|
48
224
|
export function runWithOwner<T>(owner: Owner | null, fn: () => T): T;
|
|
49
|
-
/** Register a cleanup with the current owner/root (root-level onCleanup). */
|
|
50
|
-
export function onRootCleanup(fn: () => void): void;
|
|
51
225
|
|
|
52
226
|
// --- Virtual DOM ---
|
|
53
227
|
|
|
@@ -56,9 +230,8 @@ export type PrimitiveChild = string | number | boolean | null | undefined;
|
|
|
56
230
|
// `VNode<any>`, not `VNode`. VNode is invariant in P (its `tag` holds a
|
|
57
231
|
// `Component<P>`, whose parameter position is contravariant under
|
|
58
232
|
// strictFunctionTypes), so `VNode` — which means `VNode<Record<string, any>>` —
|
|
59
|
-
// rejects every specifically-typed node
|
|
60
|
-
//
|
|
61
|
-
// passing that tree to mount().
|
|
233
|
+
// rejects every specifically-typed node: `h('div', {}, h('h1', { style: '' }))`
|
|
234
|
+
// would not compile, and neither would passing that tree to mount().
|
|
62
235
|
export type VNodeChild = PrimitiveChild | VNode<any> | (() => VNodeChild) | VNodeChild[];
|
|
63
236
|
|
|
64
237
|
/** Components may return renderable children, including reactive thunks and arrays. */
|
|
@@ -70,19 +243,27 @@ export type Component<P = {}> = ((props: P & { children?: VNodeChild }) => VNode
|
|
|
70
243
|
* provider, an error or suspense boundary) receives `props.children` as a
|
|
71
244
|
* zero-argument factory instead of built nodes, and the runtime realizes it
|
|
72
245
|
* once that scope exists. `ErrorBoundary`, `Suspense` and `Context.Provider`
|
|
73
|
-
* set this themselves, and the compiler
|
|
74
|
-
*
|
|
75
|
-
* inspects its children and forwards them into a
|
|
246
|
+
* set this themselves, and the compiler builds the children of a component
|
|
247
|
+
* that only places them where they render, so this is needed by a compiled
|
|
248
|
+
* component that both inspects its children and forwards them into a
|
|
249
|
+
* boundary or a provider, and by a component written with `h()` that places
|
|
250
|
+
* children given in compiled JSX (while hydrating, children it built while
|
|
251
|
+
* it ran would claim the server's nodes before its own element does).
|
|
76
252
|
*/
|
|
77
253
|
_deferChildren?: boolean;
|
|
78
254
|
};
|
|
79
255
|
|
|
256
|
+
/**
|
|
257
|
+
* An element or component description made by h(), the JSX runtime or a
|
|
258
|
+
* boundary. Renderers recognise one by a private brand only those producers
|
|
259
|
+
* give, so an object of this shape built any other way (from JSON, say)
|
|
260
|
+
* renders as text.
|
|
261
|
+
*/
|
|
80
262
|
export interface VNode<P = Record<string, any>> {
|
|
81
263
|
tag: string | Component<P>;
|
|
82
264
|
props: P;
|
|
83
265
|
children: VNodeChild[];
|
|
84
266
|
key: string | number | null;
|
|
85
|
-
_vnode: true;
|
|
86
267
|
}
|
|
87
268
|
|
|
88
269
|
export function h<P extends Record<string, any>>(
|
|
@@ -98,24 +279,17 @@ export function html(strings: TemplateStringsArray, ...values: any[]): VNode | V
|
|
|
98
279
|
|
|
99
280
|
export function mount(vnode: VNodeChild, container: string | Element | DocumentFragment): () => void;
|
|
100
281
|
|
|
101
|
-
/**
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
export function
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
options?: { key?: (item: T) => string | number; raw?: boolean },
|
|
113
|
-
): (parent: Node, marker?: Node | null) => Node;
|
|
114
|
-
export function spread(el: Element, props: Record<string, any>): void;
|
|
115
|
-
export function setProp(el: Element, key: string, value: any): void;
|
|
116
|
-
export function delegateEvents(eventNames: string[]): void;
|
|
117
|
-
export function on(el: Element, event: string, handler: (e: Event) => void): () => void;
|
|
118
|
-
export function classList(el: Element, classes: Record<string, boolean | (() => boolean)>): void;
|
|
282
|
+
/**
|
|
283
|
+
* Adopt server-rendered DOM as the DOM of `vnode`: bindings, events and
|
|
284
|
+
* components attach to the nodes the server wrote. Returns the unmount
|
|
285
|
+
* function, as mount() does. `options.onHydrationError` is called for every
|
|
286
|
+
* mismatch, in production too.
|
|
287
|
+
*/
|
|
288
|
+
export function hydrate(
|
|
289
|
+
vnode: VNodeChild,
|
|
290
|
+
container: string | Element,
|
|
291
|
+
options?: { onHydrationError?: (mismatch: { kind: string; component: string; ownerPath: string | null; path: string; expected: string; found: string; recovery: string }) => void },
|
|
292
|
+
): () => void;
|
|
119
293
|
|
|
120
294
|
// --- Hooks ---
|
|
121
295
|
|
|
@@ -130,7 +304,9 @@ export function classList(el: Element, classes: Record<string, boolean | (() =>
|
|
|
130
304
|
*/
|
|
131
305
|
export function useState<T>(initial: T | (() => T)): [Signal<T>, (value: Updater<T>) => void];
|
|
132
306
|
export function useSignal<T>(initial: T | (() => T)): Signal<T>;
|
|
133
|
-
|
|
307
|
+
/** computed() as a hook: it may be async, like computed(). */
|
|
308
|
+
export function useComputed<T>(fn: (run: ComputedRun) => AsyncResult<T>): AsyncComputed<T>;
|
|
309
|
+
export function useComputed<T>(fn: (run: ComputedRun) => T): AsyncComputed<T>;
|
|
134
310
|
export function useEffect(fn: () => void | (() => void), deps?: unknown[]): void;
|
|
135
311
|
/**
|
|
136
312
|
* Returns a COMPUTED ACCESSOR, not the value. Same reason as useState: the
|
|
@@ -141,6 +317,9 @@ export function useEffect(fn: () => void | (() => void), deps?: unknown[]): void
|
|
|
141
317
|
* `deps` is accepted for React familiarity and ignored at runtime: computed()
|
|
142
318
|
* tracks whatever signals the callback actually reads.
|
|
143
319
|
*
|
|
320
|
+
* A promise the callback returns stays a promise, as in React: read it with
|
|
321
|
+
* use(), or make the value an async computed with computed().
|
|
322
|
+
*
|
|
144
323
|
* It was declared as `T`, which inverted both halves: `useMemo(...) * 2`
|
|
145
324
|
* type-checked and produced NaN, while the correct `useMemo(...)()` was the
|
|
146
325
|
* type error.
|
|
@@ -148,13 +327,28 @@ export function useEffect(fn: () => void | (() => void), deps?: unknown[]): void
|
|
|
148
327
|
export function useMemo<T>(fn: () => T, deps?: unknown[]): Computed<T>;
|
|
149
328
|
export function useCallback<T extends (...args: any[]) => any>(fn: T, deps?: unknown[]): T;
|
|
150
329
|
export function useRef<T>(initial: T): { current: T };
|
|
330
|
+
/** A ref to an element, null until it is attached: `useRef<HTMLInputElement>(null)`. */
|
|
331
|
+
export function useRef<T>(initial: T | null): { current: T | null };
|
|
332
|
+
export function useRef<T = undefined>(): { current: T | undefined };
|
|
151
333
|
|
|
152
|
-
|
|
334
|
+
/**
|
|
335
|
+
* A context is its own provider, as in React 19: `<Ctx value={v}>` and
|
|
336
|
+
* `<Ctx.Provider value={v}>` render the same component. `displayName` names it
|
|
337
|
+
* in diagnostics.
|
|
338
|
+
*/
|
|
339
|
+
export interface Context<T> extends Component<{ value: T; children?: VNodeChild }> {
|
|
153
340
|
_defaultValue: T;
|
|
154
|
-
Provider:
|
|
341
|
+
Provider: Context<T>;
|
|
342
|
+
Consumer: Component<{ children: (value: T) => VNodeChild }>;
|
|
343
|
+
displayName?: string;
|
|
155
344
|
}
|
|
156
345
|
|
|
346
|
+
/**
|
|
347
|
+
* Called with no argument, the value must come from a provider: in development,
|
|
348
|
+
* reading it with none above reports ERR_CONTEXT_NOT_PROVIDED.
|
|
349
|
+
*/
|
|
157
350
|
export function createContext<T>(defaultValue: T): Context<T>;
|
|
351
|
+
export function createContext<T>(): Context<T | undefined>;
|
|
158
352
|
export function useContext<T>(context: Context<T>): T;
|
|
159
353
|
/**
|
|
160
354
|
* Returns [signal, dispatch]. The first element is the SIGNAL ITSELF, exactly
|
|
@@ -170,46 +364,106 @@ export function useReducer<S, A>(
|
|
|
170
364
|
init?: (initial: S) => S,
|
|
171
365
|
): [Signal<S>, (action: A) => void];
|
|
172
366
|
export function onMount(fn: () => void): void;
|
|
367
|
+
/**
|
|
368
|
+
* Run `fn` when the current scope goes away: the component being rendered, on
|
|
369
|
+
* unmount, or else the reactive owner around the call (createRoot, a list row,
|
|
370
|
+
* a mount root). With neither, development reports ERR_CLEANUP_WITHOUT_OWNER;
|
|
371
|
+
* an effect's per-run cleanup is the function the effect returns.
|
|
372
|
+
*/
|
|
173
373
|
export function onCleanup(fn: () => void): void;
|
|
374
|
+
/** A string, stable for the component's life: the component runs once. */
|
|
375
|
+
export function useId(prefix?: string): string;
|
|
174
376
|
|
|
377
|
+
/**
|
|
378
|
+
* `data` is an async computed: reading it before its first value lands holds
|
|
379
|
+
* the reader (a <Suspense> above shows its fallback), and in a server render
|
|
380
|
+
* the component suspends until it settles. `loading()` is true while it has
|
|
381
|
+
* no value or is fetching; `error()` is the last run's error or null;
|
|
382
|
+
* `refetch(source)` fetches again (it never rejects); `mutate(value)` sets the
|
|
383
|
+
* value now, superseding a fetch in flight.
|
|
384
|
+
*/
|
|
175
385
|
export function createResource<T = any, S = any>(
|
|
176
|
-
fetcher: (source
|
|
177
|
-
options?: { initialValue?: T; source?: S },
|
|
178
|
-
): [
|
|
179
|
-
loading:
|
|
180
|
-
error:
|
|
181
|
-
refetch: (source?: S) => Promise<
|
|
182
|
-
mutate: (value:
|
|
386
|
+
fetcher: (source: S, ctx: { signal: AbortSignal }) => Promise<T> | T,
|
|
387
|
+
options?: { initialValue?: T; source?: S; key?: string },
|
|
388
|
+
): [AsyncComputed<T>, {
|
|
389
|
+
loading: () => boolean;
|
|
390
|
+
error: () => any;
|
|
391
|
+
refetch: (source?: S) => Promise<void>;
|
|
392
|
+
mutate: (value: T | ((current: T | undefined) => T)) => void;
|
|
183
393
|
}];
|
|
184
394
|
|
|
185
395
|
// --- Components ---
|
|
186
396
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
397
|
+
/**
|
|
398
|
+
* A component loaded on first render, and kept once loaded. A download that
|
|
399
|
+
* fails goes to the error boundary of each render that waited on it; the
|
|
400
|
+
* next render (the boundary's `reset`, the component rendered again) and the
|
|
401
|
+
* next navigation to its route call `loader` again. Typed by the component
|
|
402
|
+
* the loader resolves to, so its props are inferred through
|
|
403
|
+
* `import('./Chart').then((m) => ({ default: m.Chart }))` as well.
|
|
404
|
+
*/
|
|
405
|
+
export function lazy<C extends (props: never) => VNodeChild>(loader: () => Promise<{ default: C }>): C;
|
|
406
|
+
export function lazy<C extends (props: never) => VNodeChild>(loader: () => Promise<C>): C;
|
|
190
407
|
export function memo<P>(component: Component<P>, areEqual?: (prev: P, next: P) => boolean): Component<P>;
|
|
191
408
|
|
|
409
|
+
/**
|
|
410
|
+
* Shows `fallback` until its children have first shown: while a binding under
|
|
411
|
+
* it waits for an async value that has not landed (one computed from another
|
|
412
|
+
* async value included), or a component under it has suspended (lazy(),
|
|
413
|
+
* use()). After that an async value never brings the fallback back: a refresh
|
|
414
|
+
* keeps the children mounted, their bindings holding what they show until the
|
|
415
|
+
* new value lands. A component that suspends again (a lazy() chunk,
|
|
416
|
+
* use(promise)) does, and the children stay mounted behind it; a transition
|
|
417
|
+
* does not hold that. onMount and useEffect under it first run when its
|
|
418
|
+
* children first show. A server-rendered one is adopted by hydrate() as it is.
|
|
419
|
+
*/
|
|
192
420
|
export function Suspense(props: {
|
|
193
421
|
fallback: VNodeChild;
|
|
194
422
|
children?: VNodeChild;
|
|
195
423
|
}): VNode;
|
|
196
424
|
|
|
425
|
+
/**
|
|
426
|
+
* Shows `fallback` when its children throw, while they are built or later
|
|
427
|
+
* (an effect, a binding, an async value that rejected, a useTransition action
|
|
428
|
+
* of a component under it that rejected). `reset()` fetches again the async
|
|
429
|
+
* value runs whose errors it caught and builds the children again.
|
|
430
|
+
*/
|
|
197
431
|
export function ErrorBoundary(props: {
|
|
198
432
|
fallback: VNodeChild | ((args: { error: Error; reset: () => void }) => VNodeChild);
|
|
199
433
|
onError?: (error: Error) => void;
|
|
200
434
|
children?: VNodeChild;
|
|
201
435
|
}): VNode;
|
|
202
436
|
|
|
437
|
+
/**
|
|
438
|
+
* Its children while `when` is truthy, else `fallback`. `when` is any value
|
|
439
|
+
* (`when={user()}`), or an accessor of one; the children are built once
|
|
440
|
+
* while it stays truthy.
|
|
441
|
+
*/
|
|
203
442
|
export function Show(props: {
|
|
204
|
-
when:
|
|
443
|
+
when: unknown;
|
|
205
444
|
fallback?: VNodeChild;
|
|
206
445
|
children?: VNodeChild;
|
|
207
446
|
}): VNode;
|
|
208
447
|
|
|
448
|
+
/**
|
|
449
|
+
* A list: `each` is an accessor (a signal, a computed) or an array. With
|
|
450
|
+
* `key`, each row is built once per key and gets its item as an accessor,
|
|
451
|
+
* `item()`, which follows an item replaced under the same key; without it, a
|
|
452
|
+
* row gets the item itself and a new item is a new row. `.map()` with a `key`
|
|
453
|
+
* prop is the usual form in compiled JSX.
|
|
454
|
+
*/
|
|
455
|
+
export function For<T>(props: {
|
|
456
|
+
each: readonly T[] | (() => readonly T[] | null | undefined);
|
|
457
|
+
/** The row's key; it is handed the item's index too, for a key of item and position. */
|
|
458
|
+
key: (item: T, index: number) => unknown;
|
|
459
|
+
fallback?: VNodeChild;
|
|
460
|
+
children: (item: () => T, index: number) => VNodeChild;
|
|
461
|
+
}): VNode;
|
|
209
462
|
export function For<T>(props: {
|
|
210
|
-
each: T[] | (() => T[]);
|
|
463
|
+
each: readonly T[] | (() => readonly T[] | null | undefined);
|
|
464
|
+
key?: undefined;
|
|
211
465
|
fallback?: VNodeChild;
|
|
212
|
-
children: (
|
|
466
|
+
children: (item: T, index: number) => VNodeChild;
|
|
213
467
|
}): VNode;
|
|
214
468
|
|
|
215
469
|
export function Switch(props: {
|
|
@@ -218,26 +472,22 @@ export function Switch(props: {
|
|
|
218
472
|
}): VNode;
|
|
219
473
|
|
|
220
474
|
export function Match(props: {
|
|
221
|
-
when:
|
|
475
|
+
when: unknown;
|
|
222
476
|
children?: VNodeChild;
|
|
223
477
|
}): VNode;
|
|
224
478
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
export function Island(props: IslandProps): VNode;
|
|
479
|
+
/**
|
|
480
|
+
* Renders its children into `target`, an element or a CSS selector, or into
|
|
481
|
+
* `document.body` when there is none, and removes them when the portal goes.
|
|
482
|
+
* The server renders nothing for it.
|
|
483
|
+
*/
|
|
484
|
+
export function Portal(props: { target?: string | Element | null; children?: VNodeChild }): VNode | null;
|
|
233
485
|
|
|
234
486
|
// --- State ---
|
|
235
487
|
|
|
236
488
|
/** `_storeComputed` is the marker createStore() actually reads to tell a derived value from an action. */
|
|
237
489
|
export type DerivedFn<T> = ((state: any) => T) & { _storeComputed: true };
|
|
238
490
|
export function derived<T>(fn: (state: any) => T): DerivedFn<T>;
|
|
239
|
-
/** @deprecated Use derived(). Warns once at runtime. */
|
|
240
|
-
export function storeComputed<T>(fn: (state: any) => T): DerivedFn<T>;
|
|
241
491
|
export type StoreDefinition = Record<string, any>;
|
|
242
492
|
/**
|
|
243
493
|
* The store hook resolves every derived key to its VALUE. State and derived
|
|
@@ -250,641 +500,121 @@ export type Store<T extends StoreDefinition> = {
|
|
|
250
500
|
[K in keyof T]: T[K] extends DerivedFn<infer U> ? U : T[K];
|
|
251
501
|
};
|
|
252
502
|
export function createStore<T extends StoreDefinition>(definition: T): () => Store<T>;
|
|
253
|
-
export function atom<T>(initial: T): Signal<T>;
|
|
254
|
-
|
|
255
|
-
// --- Helpers / Utilities ---
|
|
256
|
-
|
|
257
|
-
export function each<T>(
|
|
258
|
-
list: T[],
|
|
259
|
-
fn: (item: T, index: number) => VNodeChild,
|
|
260
|
-
keyFn?: (item: T, index: number) => string | number,
|
|
261
|
-
): VNodeChild[];
|
|
262
|
-
|
|
263
|
-
export function cls(...args: Array<string | false | null | undefined | Record<string, boolean>>): string;
|
|
264
|
-
export function style(obj: string | Record<string, string | number | null | undefined>): string;
|
|
265
|
-
export function debounce<T extends (...args: any[]) => any>(fn: T, ms: number): T;
|
|
266
|
-
export function throttle<T extends (...args: any[]) => any>(fn: T, ms: number): T;
|
|
267
|
-
export function useMediaQuery(query: string): Signal<boolean>;
|
|
268
|
-
export function useLocalStorage<T>(key: string, initial: T): Signal<T>;
|
|
269
|
-
export function useClickOutside(ref: { current?: Element | null } | Element, handler: (e: Event) => void): void;
|
|
270
|
-
export function Portal(props: { target: string | Element; children?: VNodeChild }): VNode | null;
|
|
271
|
-
export function transition(name: string, active: boolean): { class: string };
|
|
272
503
|
|
|
273
504
|
// --- Head ---
|
|
274
505
|
|
|
506
|
+
/**
|
|
507
|
+
* Set document head tags from any component, on the client and in a server
|
|
508
|
+
* render. `<title>`, `<meta>` and `<link>` children set the same tags as the
|
|
509
|
+
* props: `<Head><title>Docs</title></Head>` is `<Head title="Docs" />`. A meta
|
|
510
|
+
* is keyed by `name`, `property` or `httpEquiv`, a link by `rel` + `href`; the
|
|
511
|
+
* later of two with one key wins, and within one Head a child wins over a prop.
|
|
512
|
+
* Any other child renders in place.
|
|
513
|
+
*/
|
|
275
514
|
export function Head(props: {
|
|
276
515
|
title?: string;
|
|
277
|
-
meta?: Array<Record<string, string>>;
|
|
278
|
-
link?: Array<Record<string, string>>;
|
|
279
|
-
script?: Array<Record<string, string>>;
|
|
516
|
+
meta?: Record<string, string> | Array<Record<string, string>>;
|
|
517
|
+
link?: Record<string, string> | Array<Record<string, string>>;
|
|
280
518
|
children?: VNodeChild;
|
|
281
519
|
}): null;
|
|
282
|
-
export function clearHead(): void;
|
|
283
|
-
|
|
284
|
-
/** Per-render head accumulator used by the SSR renderer. */
|
|
285
|
-
export interface HeadSink {
|
|
286
|
-
title: string | null;
|
|
287
|
-
metas: Map<string, Record<string, string>>;
|
|
288
|
-
links: Map<string, Record<string, string>>;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
export function beginHeadCollection(): HeadSink;
|
|
292
|
-
export function endHeadCollection(sink: HeadSink | null): string;
|
|
293
520
|
|
|
294
521
|
// --- Loader Data ---
|
|
295
522
|
|
|
296
523
|
export function useLoaderData<T = any>(): T | undefined;
|
|
297
|
-
export function getLoaderData<T = any>(): T | undefined;
|
|
298
|
-
export function getResource<T = any>(key: string): T | undefined;
|
|
299
|
-
|
|
300
|
-
// --- Server Context ---
|
|
301
|
-
|
|
302
|
-
export interface ServerContext {
|
|
303
|
-
loaderData?: any;
|
|
304
|
-
head?: HeadSink;
|
|
305
|
-
resources?: Record<string, any>;
|
|
306
|
-
[key: string]: any;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
/** The active render context, or null on the client / outside a render. */
|
|
310
|
-
export function getServerContext(): ServerContext | null;
|
|
311
|
-
/** Set the active context and return the previous one so callers can restore it. */
|
|
312
|
-
export function setServerContext(ctx: ServerContext | null): ServerContext | null;
|
|
313
|
-
export function runWithServerContext<T>(ctx: ServerContext, fn: () => T): T;
|
|
314
|
-
|
|
315
|
-
// --- Scheduler ---
|
|
316
|
-
|
|
317
|
-
export function scheduleRead(fn: () => void): () => void;
|
|
318
|
-
export function scheduleWrite(fn: () => void): () => void;
|
|
319
|
-
export function flushScheduler(): void;
|
|
320
|
-
export function measure<T>(fn: () => T): Promise<T>;
|
|
321
|
-
export function mutate(fn: () => void): Promise<void>;
|
|
322
|
-
export function useScheduledEffect(readFn: () => any, writeFn?: (data: any) => void): () => void;
|
|
323
|
-
export function nextFrame(): Promise<void> & { cancel: () => void };
|
|
324
|
-
export function raf(key: string, fn: () => void): void;
|
|
325
|
-
export function onResize(element: Element, callback: (rect: DOMRectReadOnly) => void): () => void;
|
|
326
|
-
export function onIntersect(
|
|
327
|
-
element: Element,
|
|
328
|
-
callback: (entry: IntersectionObserverEntry) => void,
|
|
329
|
-
options?: IntersectionObserverInit,
|
|
330
|
-
): () => void;
|
|
331
|
-
export function smoothScrollTo(
|
|
332
|
-
element: Element,
|
|
333
|
-
options?: { duration?: number; easing?: (t: number) => number },
|
|
334
|
-
): Promise<void>;
|
|
335
|
-
|
|
336
|
-
// --- Animation ---
|
|
337
|
-
//
|
|
338
|
-
// Every accessor below is a plain getter function, NOT a Signal: the objects
|
|
339
|
-
// these factories return expose reads through closures and offer writes as
|
|
340
|
-
// named methods (set/snap/setValue), so nothing here carries .set/.peek. The
|
|
341
|
-
// declarations used to promise Signal<number> and a single shared SpringValue
|
|
342
|
-
// shape for both spring() and tween(), which are two different objects.
|
|
343
|
-
|
|
344
|
-
export interface SpringConfig {
|
|
345
|
-
stiffness?: number;
|
|
346
|
-
damping?: number;
|
|
347
|
-
mass?: number;
|
|
348
|
-
precision?: number;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
/** Physics-based value. `set()` retargets and animates; `snap()` jumps without animating. */
|
|
352
|
-
export interface SpringValue {
|
|
353
|
-
current(): number;
|
|
354
|
-
target(): number;
|
|
355
|
-
velocity(): number;
|
|
356
|
-
isAnimating(): boolean;
|
|
357
|
-
set(target: number): void;
|
|
358
|
-
stop(): void;
|
|
359
|
-
snap(value: number): void;
|
|
360
|
-
subscribe(fn: (value: number) => void): () => void;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
export interface TweenConfig {
|
|
364
|
-
duration?: number;
|
|
365
|
-
easing?: (t: number) => number;
|
|
366
|
-
onUpdate?: (value: number, progress: number) => void;
|
|
367
|
-
onComplete?: () => void;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
/**
|
|
371
|
-
* Easing-based interpolation from `from` to `to`. Starts immediately on
|
|
372
|
-
* creation and runs to completion, so it exposes `cancel()` rather than the
|
|
373
|
-
* spring's retargeting `set()`/`stop()`.
|
|
374
|
-
*/
|
|
375
|
-
export interface TweenValue {
|
|
376
|
-
progress(): number;
|
|
377
|
-
value(): number;
|
|
378
|
-
isAnimating(): boolean;
|
|
379
|
-
cancel(): void;
|
|
380
|
-
subscribe(fn: (value: number) => void): () => void;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
export function spring(initialValue: number, config?: SpringConfig): SpringValue;
|
|
384
|
-
/**
|
|
385
|
-
* Both endpoints are required and positional. This was declared as
|
|
386
|
-
* `tween(initialValue?, config?)` returning a SpringValue, so the documented
|
|
387
|
-
* call `tween(0, 100, { duration: 300 })` was a type error, while
|
|
388
|
-
* `tween(0).current()` type-checked and threw (`current` does not exist, and a
|
|
389
|
-
* missing `to` interpolates toward undefined).
|
|
390
|
-
*/
|
|
391
|
-
export function tween(from: number, to: number, config?: TweenConfig): TweenValue;
|
|
392
|
-
export const easings: Record<string, (t: number) => number>;
|
|
393
524
|
/**
|
|
394
|
-
*
|
|
395
|
-
*
|
|
396
|
-
*
|
|
525
|
+
* Swap streamed boundaries whose content has arrived into place. Call it from
|
|
526
|
+
* the client entry, before hydrating, on a page streamed with `noScripts`.
|
|
527
|
+
* Returns the number of boundaries swapped.
|
|
397
528
|
*/
|
|
398
|
-
export function
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
export interface GestureVelocity {
|
|
417
|
-
x: number;
|
|
418
|
-
y: number;
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
/**
|
|
422
|
-
* `preventDefault` is why this cannot be a `Record<string, (payload) => void>`:
|
|
423
|
-
* it sits in the same object as the callbacks and is a boolean.
|
|
424
|
-
*/
|
|
425
|
-
export interface GestureHandlers {
|
|
426
|
-
onDragStart?: (payload: { x: number; y: number }) => void;
|
|
427
|
-
onDrag?: (payload: {
|
|
428
|
-
x: number; y: number; deltaX: number; deltaY: number; velocity: GestureVelocity;
|
|
429
|
-
}) => void;
|
|
430
|
-
onDragEnd?: (payload: { deltaX: number; deltaY: number; velocity: GestureVelocity }) => void;
|
|
431
|
-
onPinch?: (payload: { scale: number; centerX: number; centerY: number }) => void;
|
|
432
|
-
onSwipe?: (payload: { direction: 'up' | 'down' | 'left' | 'right'; velocity: GestureVelocity }) => void;
|
|
433
|
-
onTap?: (payload: { x: number; y: number }) => void;
|
|
434
|
-
onLongPress?: (payload: { x: number; y: number }) => void;
|
|
435
|
-
/** Opt in to e.preventDefault() in the touch handlers (listeners become non-passive). */
|
|
436
|
-
preventDefault?: boolean;
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
/** Returns the gesture state. It was declared `void`, so the state was unreachable from TypeScript. */
|
|
440
|
-
export function useGesture(
|
|
441
|
-
ref: { current?: Element | null } | Element | (() => Element | null),
|
|
442
|
-
handlers?: GestureHandlers,
|
|
443
|
-
): GestureState;
|
|
444
|
-
|
|
445
|
-
/** Handle for one running animation started by useAnimatedValue. */
|
|
446
|
-
export interface AnimationHandle {
|
|
447
|
-
stop: () => void;
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
/**
|
|
451
|
-
* `animateTo` and `stop` were declared here and have never existed. Animations
|
|
452
|
-
* are started with spring()/timing(), each returning its own handle to stop.
|
|
453
|
-
*/
|
|
454
|
-
export function useAnimatedValue(initialValue: number): {
|
|
455
|
-
value: () => number;
|
|
456
|
-
setValue: (value: number) => void;
|
|
457
|
-
spring: (toValue: number, config?: SpringConfig) => AnimationHandle;
|
|
458
|
-
timing: (toValue: number, config?: TweenConfig) => AnimationHandle;
|
|
459
|
-
interpolate: (inputRange: number[], outputRange: number[]) => () => number;
|
|
460
|
-
subscribe: (fn: (value: number) => void) => () => void;
|
|
461
|
-
};
|
|
462
|
-
|
|
463
|
-
export interface TransitionClasses {
|
|
464
|
-
enter: string;
|
|
465
|
-
enterActive: string;
|
|
466
|
-
enterDone: string;
|
|
467
|
-
exit: string;
|
|
468
|
-
exitActive: string;
|
|
469
|
-
exitDone: string;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
/** Returns the six class NAMES for `name`, not a single string. */
|
|
473
|
-
export function createTransitionClasses(name: string): TransitionClasses;
|
|
474
|
-
/**
|
|
475
|
-
* Applies the enter/exit class sequence to an element and resolves when the
|
|
476
|
-
* transition is done. It was declared as a synchronous `(config) => object`.
|
|
477
|
-
*/
|
|
478
|
-
export function cssTransition(
|
|
479
|
-
element: Element,
|
|
480
|
-
name: string,
|
|
481
|
-
type?: 'enter' | 'exit',
|
|
482
|
-
duration?: number,
|
|
483
|
-
): Promise<void>;
|
|
484
|
-
|
|
485
|
-
// --- Accessibility ---
|
|
486
|
-
|
|
487
|
-
export function useFocus(): {
|
|
488
|
-
current: () => Element | null;
|
|
489
|
-
focus: (element?: Element | null) => void;
|
|
490
|
-
blur: () => void;
|
|
491
|
-
};
|
|
492
|
-
|
|
493
|
-
export function useFocusRestore(): {
|
|
494
|
-
capture: (target?: Element | null) => void;
|
|
495
|
-
restore: (fallbackTarget?: Element | null) => void;
|
|
496
|
-
previous: () => Element | null;
|
|
497
|
-
};
|
|
498
|
-
|
|
499
|
-
export function useFocusTrap(containerRef: { current?: Element | null } | Element): {
|
|
500
|
-
activate: () => void | (() => void);
|
|
501
|
-
deactivate: () => void;
|
|
502
|
-
};
|
|
503
|
-
|
|
504
|
-
export function FocusTrap(props: { children?: VNodeChild; active?: boolean }): VNode;
|
|
505
|
-
export function announce(message: string, options?: { priority?: 'polite' | 'assertive'; timeout?: number }): void;
|
|
506
|
-
export function announceAssertive(message: string): void;
|
|
507
|
-
export function SkipLink(props: { href?: string; children?: VNodeChild }): VNode;
|
|
508
|
-
|
|
509
|
-
export function useAriaExpanded(initialExpanded?: boolean): {
|
|
510
|
-
expanded: () => boolean;
|
|
511
|
-
toggle: () => void;
|
|
512
|
-
open: () => void;
|
|
513
|
-
close: () => void;
|
|
514
|
-
buttonProps: () => Record<string, any>;
|
|
515
|
-
panelProps: () => Record<string, any>;
|
|
516
|
-
};
|
|
517
|
-
|
|
518
|
-
export function useAriaSelected<T = any>(initialSelected?: T): {
|
|
519
|
-
selected: () => T;
|
|
520
|
-
select: (value: T) => void;
|
|
521
|
-
isSelected: (value: T) => boolean;
|
|
522
|
-
itemProps: (value: T) => Record<string, any>;
|
|
523
|
-
};
|
|
524
|
-
|
|
525
|
-
export function useAriaChecked(initialChecked?: boolean): {
|
|
526
|
-
checked: () => boolean;
|
|
527
|
-
toggle: () => void;
|
|
528
|
-
set: (value: boolean) => void;
|
|
529
|
-
checkboxProps: () => Record<string, any>;
|
|
530
|
-
};
|
|
531
|
-
|
|
532
|
-
export interface RovingTabIndexOptions {
|
|
529
|
+
export function applyStreamedBoundaries(): number;
|
|
530
|
+
|
|
531
|
+
// --- Server response ---
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
/** The HTTP response of a server render, as components see it. */
|
|
535
|
+
export interface ServerResponse {
|
|
536
|
+
/** The status the response will be sent with. */
|
|
537
|
+
readonly status: number;
|
|
538
|
+
/** Where the browser is sent (a path below the base the app is served at), or null. */
|
|
539
|
+
readonly location: string | null;
|
|
540
|
+
/** True once the shell has been sent: status and headers are final. */
|
|
541
|
+
readonly committed: boolean;
|
|
542
|
+
/** Set the status code. No effect once committed. */
|
|
543
|
+
setStatus(code: number): void;
|
|
544
|
+
/** Set (or with `append`, add) a header. Set-Cookie always appends. No effect once committed. */
|
|
545
|
+
setHeader(name: string, value: string, options?: { append?: boolean }): void;
|
|
533
546
|
/**
|
|
534
|
-
*
|
|
535
|
-
*
|
|
536
|
-
*
|
|
537
|
-
*
|
|
547
|
+
* Redirect to a path of the app such as "/login" (302 by default). The path
|
|
548
|
+
* is the app's, below the base it is served at: under the request handler's
|
|
549
|
+
* `basePath: '/app'` (else what-router's base), "/login" is sent as
|
|
550
|
+
* "/app/login", as a server action's and what-router's redirect() are.
|
|
551
|
+
* Before the shell is sent this is a real 3xx; after it, the browser is sent
|
|
552
|
+
* a script that replaces the location. Any other target (an absolute URL,
|
|
553
|
+
* "//host", "/\\host", javascript:) is refused: the response redirects to
|
|
554
|
+
* the app's root instead, and development logs ERR_SSR_UNSAFE_REDIRECT.
|
|
555
|
+
* Throws a RangeError for a status that is not a redirect status.
|
|
538
556
|
*/
|
|
539
|
-
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
/**
|
|
543
|
-
* Props for one roving item. `ref` is the item's REGISTRATION (the hook holds
|
|
544
|
-
* the node through it and cannot move focus without it), so a `ref` passed via
|
|
545
|
-
* `overrides` is chained rather than replaced. `tabIndex` is an accessor, not a
|
|
546
|
-
* number: exactly one item is tabbable at a time and which one changes as focus
|
|
547
|
-
* roves, so a resolved value could not survive the spread.
|
|
548
|
-
*/
|
|
549
|
-
export interface RovingItemProps {
|
|
550
|
-
ref: { current: Element | null };
|
|
551
|
-
tabIndex: () => number;
|
|
552
|
-
onKeyDown: (e: KeyboardEvent) => void;
|
|
553
|
-
onFocus: (e: Event) => void;
|
|
554
|
-
[prop: string]: any;
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
export function useRovingTabIndex(
|
|
558
|
-
itemCountOrSignal: number | (() => number),
|
|
559
|
-
options?: RovingTabIndexOptions,
|
|
560
|
-
): {
|
|
561
|
-
/** Active index, clamped to the current count so the group is never untabbable. */
|
|
562
|
-
focusIndex: () => number;
|
|
557
|
+
redirect(location: string, status?: 301 | 302 | 303 | 307 | 308): void;
|
|
563
558
|
/**
|
|
564
|
-
*
|
|
565
|
-
*
|
|
566
|
-
*
|
|
559
|
+
* Redirect off the site, to an absolute http: or https: URL with no
|
|
560
|
+
* credentials, or a mailto: or tel: URL: what what-router's redirect()
|
|
561
|
+
* leaves the site for in the browser. A target that is not one is refused
|
|
562
|
+
* like redirect()'s.
|
|
567
563
|
*/
|
|
568
|
-
|
|
564
|
+
redirectExternal(url: string, status?: 301 | 302 | 303 | 307 | 308): void;
|
|
569
565
|
/**
|
|
570
|
-
*
|
|
571
|
-
*
|
|
572
|
-
*
|
|
566
|
+
* @internal what-router's navigate() on a server: redirect to a URL of this
|
|
567
|
+
* origin as the browser resolves it (below the base already, or outside
|
|
568
|
+
* it); `to` is what the app wrote, named when it is refused. Absent where
|
|
569
|
+
* there is no server render.
|
|
573
570
|
*/
|
|
574
|
-
|
|
575
|
-
getItemProps: (index: number, overrides?: Record<string, any>) => RovingItemProps;
|
|
576
|
-
containerProps: (overrides?: Record<string, any>) => Record<string, any>;
|
|
577
|
-
};
|
|
578
|
-
|
|
579
|
-
export function VisuallyHidden(props: { children?: VNodeChild; as?: string }): VNode;
|
|
580
|
-
export function LiveRegion(props: { children?: VNodeChild; priority?: 'polite' | 'assertive'; atomic?: boolean }): VNode;
|
|
581
|
-
export function useId(prefix?: string): () => string;
|
|
582
|
-
export function useIds(count: number, prefix?: string): string[];
|
|
583
|
-
export function useDescribedBy(description: VNodeChild): {
|
|
584
|
-
descriptionId: () => string;
|
|
585
|
-
descriptionProps: () => Record<string, any>;
|
|
586
|
-
describedByProps: () => Record<string, any>;
|
|
587
|
-
Description: () => VNode;
|
|
588
|
-
};
|
|
589
|
-
export function useLabelledBy(label: VNodeChild): {
|
|
590
|
-
labelId: () => string;
|
|
591
|
-
labelProps: () => Record<string, any>;
|
|
592
|
-
labelledByProps: () => Record<string, any>;
|
|
593
|
-
};
|
|
594
|
-
|
|
595
|
-
export const Keys: {
|
|
596
|
-
Enter: 'Enter';
|
|
597
|
-
Space: ' ';
|
|
598
|
-
Escape: 'Escape';
|
|
599
|
-
ArrowUp: 'ArrowUp';
|
|
600
|
-
ArrowDown: 'ArrowDown';
|
|
601
|
-
ArrowLeft: 'ArrowLeft';
|
|
602
|
-
ArrowRight: 'ArrowRight';
|
|
603
|
-
Home: 'Home';
|
|
604
|
-
End: 'End';
|
|
605
|
-
Tab: 'Tab';
|
|
606
|
-
};
|
|
607
|
-
|
|
608
|
-
export function onKey(key: string, handler: (e: KeyboardEvent) => void): (e: KeyboardEvent) => void;
|
|
609
|
-
export function onKeys(keys: string[], handler: (e: KeyboardEvent) => void): (e: KeyboardEvent) => void;
|
|
610
|
-
|
|
611
|
-
// --- Skeleton ---
|
|
612
|
-
|
|
613
|
-
export function Skeleton(props?: Record<string, any>): VNode;
|
|
614
|
-
export function SkeletonText(props?: Record<string, any>): VNode;
|
|
615
|
-
export function SkeletonAvatar(props?: Record<string, any>): VNode;
|
|
616
|
-
export function SkeletonCard(props?: Record<string, any>): VNode;
|
|
617
|
-
export function SkeletonTable(props?: Record<string, any>): VNode;
|
|
618
|
-
export function IslandSkeleton(props?: Record<string, any>): VNode;
|
|
619
|
-
export function useSkeleton<T>(asyncFn: () => Promise<T> | T, deps?: unknown[]): {
|
|
620
|
-
isLoading: () => boolean;
|
|
621
|
-
data: () => T | null;
|
|
622
|
-
error: () => any;
|
|
623
|
-
Skeleton: (props?: Record<string, any>) => VNode;
|
|
624
|
-
};
|
|
625
|
-
export function Placeholder(props?: Record<string, any>): VNode;
|
|
626
|
-
export function LoadingDots(props?: Record<string, any>): VNode;
|
|
627
|
-
export function Spinner(props?: Record<string, any>): VNode;
|
|
628
|
-
|
|
629
|
-
// --- Data Fetching ---
|
|
630
|
-
|
|
631
|
-
export function useFetch<T = any>(url: string, options?: Record<string, any>): {
|
|
632
|
-
/** null until the first response lands. It was declared as bare `T`, so strict-mode callers skipped the check they need. */
|
|
633
|
-
data: () => T | null;
|
|
634
|
-
error: () => any;
|
|
635
|
-
isLoading: () => boolean;
|
|
636
|
-
refetch: () => Promise<void>;
|
|
637
|
-
mutate: (newData: T) => void;
|
|
638
|
-
};
|
|
639
|
-
|
|
640
|
-
export function useSWR<T = any>(key: string | null | false, fetcher: (key: string, ctx?: { signal: AbortSignal }) => Promise<T>, options?: Record<string, any>): {
|
|
641
|
-
data: () => T | null;
|
|
642
|
-
error: () => any;
|
|
643
|
-
isLoading: () => boolean;
|
|
644
|
-
isValidating: () => boolean;
|
|
645
|
-
mutate: (newData: T | ((prev: T | null) => T), shouldRevalidate?: boolean) => void;
|
|
646
|
-
revalidate: () => Promise<T | void>;
|
|
647
|
-
};
|
|
648
|
-
|
|
649
|
-
/**
|
|
650
|
-
* 'idle' is a real state, not a placeholder: a query with `enabled: false` and
|
|
651
|
-
* nothing cached is idle, and reporting it as loading is what renders a spinner
|
|
652
|
-
* that never comes down.
|
|
653
|
-
*/
|
|
654
|
-
export type QueryStatus = 'idle' | 'loading' | 'success' | 'error';
|
|
655
|
-
/** Whether a request is on the wire, independent of whether data exists. */
|
|
656
|
-
export type FetchStatus = 'idle' | 'fetching';
|
|
657
|
-
|
|
658
|
-
/**
|
|
659
|
-
* Any array key is joined into a single normalized string, so an array and its
|
|
660
|
-
* normalization address the same cache entry everywhere a key is accepted.
|
|
661
|
-
*/
|
|
662
|
-
export type QueryKey = string | readonly unknown[];
|
|
663
|
-
|
|
664
|
-
export function useQuery<T = any>(options: Record<string, any>): {
|
|
665
|
-
data: () => T | null;
|
|
666
|
-
error: () => any;
|
|
667
|
-
status: () => QueryStatus;
|
|
668
|
-
fetchStatus: () => FetchStatus;
|
|
669
|
-
isLoading: () => boolean;
|
|
670
|
-
isFetching: () => boolean;
|
|
671
|
-
isError: () => boolean;
|
|
672
|
-
isSuccess: () => boolean;
|
|
673
|
-
isIdle: () => boolean;
|
|
674
|
-
/** Whether the `enabled` gate is currently open. */
|
|
675
|
-
isEnabled: () => boolean;
|
|
676
|
-
refetch: () => Promise<T | void>;
|
|
677
|
-
};
|
|
678
|
-
|
|
679
|
-
/**
|
|
680
|
-
* Pages, plus the param each was fetched with. `pageParams[i]` names `pages[i]`.
|
|
681
|
-
*/
|
|
682
|
-
export interface InfiniteData<T> {
|
|
683
|
-
pages: T[];
|
|
684
|
-
pageParams: unknown[];
|
|
571
|
+
_redirectAt?(location: string | null, to: unknown): void;
|
|
685
572
|
}
|
|
686
573
|
|
|
687
574
|
/**
|
|
688
|
-
*
|
|
689
|
-
*
|
|
690
|
-
* `data().pages`. A `select` option replaces the container wholesale, and that
|
|
691
|
-
* transformation is not expressible here.
|
|
575
|
+
* The response of the server render in progress. On the client, or outside a
|
|
576
|
+
* render, an inert object whose methods do nothing.
|
|
692
577
|
*/
|
|
693
|
-
export function
|
|
694
|
-
data: () => InfiniteData<T>;
|
|
695
|
-
error: () => any;
|
|
696
|
-
status: () => QueryStatus;
|
|
697
|
-
isLoading: () => boolean;
|
|
698
|
-
isError: () => boolean;
|
|
699
|
-
isSuccess: () => boolean;
|
|
700
|
-
isIdle: () => boolean;
|
|
701
|
-
isFetching: () => boolean;
|
|
702
|
-
isEnabled: () => boolean;
|
|
703
|
-
hasNextPage: () => boolean;
|
|
704
|
-
hasPreviousPage: () => boolean;
|
|
705
|
-
isFetchingNextPage: () => boolean;
|
|
706
|
-
isFetchingPreviousPage: () => boolean;
|
|
707
|
-
fetchNextPage: () => Promise<void>;
|
|
708
|
-
fetchPreviousPage: () => Promise<void>;
|
|
709
|
-
refetch: () => Promise<void>;
|
|
710
|
-
};
|
|
711
|
-
|
|
712
|
-
/**
|
|
713
|
-
* Synchronous. It was declared as returning Promise<void>, so `await
|
|
714
|
-
* invalidateQueries(...)` awaited undefined and read as "the refetches are
|
|
715
|
-
* done" when they had only been kicked off. The subscribers it wakes fetch on
|
|
716
|
-
* their own.
|
|
717
|
-
*
|
|
718
|
-
* An array key is a PREFIX unless `exact` is set: invalidateQueries(['todos'])
|
|
719
|
-
* also invalidates ['todos', 1]. `hard` clears the cached value immediately
|
|
720
|
-
* (loading state); the default keeps stale data on screen while it refetches.
|
|
721
|
-
*/
|
|
722
|
-
export function invalidateQueries(
|
|
723
|
-
keyOrPredicate: QueryKey | ((key: string) => boolean),
|
|
724
|
-
options?: { exact?: boolean; hard?: boolean },
|
|
725
|
-
): void;
|
|
726
|
-
|
|
727
|
-
export function prefetchQuery<T = any>(key: QueryKey, fetcher: (key: string) => Promise<T>): Promise<T>;
|
|
728
|
-
export function setQueryData<T = any>(key: QueryKey, updater: T | ((prev: T | null) => T)): void;
|
|
729
|
-
/** `undefined` for a key the cache has never held; `null` for one that was emptied. */
|
|
730
|
-
export function getQueryData<T = any>(key: QueryKey): T | null | undefined;
|
|
731
|
-
export function clearCache(): void;
|
|
732
|
-
|
|
733
|
-
// --- Forms ---
|
|
734
|
-
|
|
735
|
-
export interface FieldError {
|
|
736
|
-
type?: string;
|
|
737
|
-
message?: string;
|
|
738
|
-
[key: string]: any;
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
/**
|
|
742
|
-
* What register() actually hands back, which varies by control type. The event
|
|
743
|
-
* handlers are LOWERCASE (`oninput`, `onchange`), because that is the key the
|
|
744
|
-
* DOM binding and the merge in <Input>/<Radio> look for; `onInput` was declared
|
|
745
|
-
* here and register() has never defined it, so `register('email').onInput(e)`
|
|
746
|
-
* type-checked and threw at the first keystroke.
|
|
747
|
-
*
|
|
748
|
-
* `value` and `checked` are reactive rather than snapshots: `value` and the
|
|
749
|
-
* checkbox `checked` are getters, and the radio `checked` is a thunk, so that a
|
|
750
|
-
* spread (`{...register('email')}`) binds instead of freezing the value at
|
|
751
|
-
* mount.
|
|
752
|
-
*
|
|
753
|
-
* A closed type alias rather than an interface: the key set really is closed
|
|
754
|
-
* (this is the whole object register() builds), and closing it is what makes
|
|
755
|
-
* the phantom `onInput` an error again instead of an `any` off an index
|
|
756
|
-
* signature. It must stay a `type`, not an `interface`, because only a type
|
|
757
|
-
* alias gets the implicit index signature that `h('input', register(name))`
|
|
758
|
-
* needs to be assignable to Record<string, any>.
|
|
759
|
-
*/
|
|
760
|
-
export type RegisterProps = {
|
|
761
|
-
name: string;
|
|
762
|
-
onBlur: () => void;
|
|
763
|
-
onFocus: () => void;
|
|
764
|
-
ref?: any;
|
|
765
|
-
/** text/select/textarea, and the option's own value on a radio. */
|
|
766
|
-
value?: any;
|
|
767
|
-
/** checkbox/radio only. */
|
|
768
|
-
checked?: boolean | (() => boolean);
|
|
769
|
-
/** text/select/textarea only. */
|
|
770
|
-
oninput?: (e: any) => void;
|
|
771
|
-
/** checkbox/radio only. */
|
|
772
|
-
onchange?: (e: any) => void;
|
|
773
|
-
};
|
|
774
|
-
|
|
775
|
-
export interface FormState {
|
|
776
|
-
readonly values: Record<string, any>;
|
|
777
|
-
readonly errors: Record<string, FieldError>;
|
|
778
|
-
error: (name: string) => FieldError | null;
|
|
779
|
-
readonly touched: Record<string, boolean>;
|
|
780
|
-
isDirty: () => boolean;
|
|
781
|
-
isValid: Computed<boolean>;
|
|
782
|
-
/** True while the resolver is running. Present since resolvers went async; never declared. */
|
|
783
|
-
isValidating: () => boolean;
|
|
784
|
-
isSubmitting: () => boolean;
|
|
785
|
-
isSubmitted: () => boolean;
|
|
786
|
-
submitCount: () => number;
|
|
787
|
-
dirtyFields: Computed<Record<string, boolean>>;
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
export interface UseFormReturn {
|
|
791
|
-
register: (name: string, options?: Record<string, any>) => RegisterProps;
|
|
792
|
-
handleSubmit: (
|
|
793
|
-
onValid: (values: Record<string, any>) => void | Promise<void>,
|
|
794
|
-
onInvalid?: (errors: Record<string, FieldError>) => void,
|
|
795
|
-
) => (e?: Event) => Promise<void>;
|
|
796
|
-
setValue: (name: string, value: any, options?: Record<string, any>) => void;
|
|
797
|
-
getValue: (name: string) => any;
|
|
798
|
-
setError: (name: string, error: FieldError | null) => void;
|
|
799
|
-
clearError: (name: string) => void;
|
|
800
|
-
clearErrors: () => void;
|
|
801
|
-
reset: (newValues?: Record<string, any>) => void;
|
|
802
|
-
watch: (name?: string) => Computed<any>;
|
|
803
|
-
validate: (fieldName?: string) => Promise<boolean>;
|
|
804
|
-
formState: FormState;
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
export function useForm(options?: {
|
|
808
|
-
defaultValues?: Record<string, any>;
|
|
809
|
-
mode?: 'onSubmit' | 'onChange' | 'onBlur';
|
|
810
|
-
reValidateMode?: 'onChange' | 'onBlur';
|
|
811
|
-
resolver?: (values: Record<string, any>) => Promise<{ values: Record<string, any>; errors: Record<string, FieldError> }>;
|
|
812
|
-
}): UseFormReturn;
|
|
813
|
-
|
|
814
|
-
export function useField(name: string, options?: {
|
|
815
|
-
validate?: (value: any) => string | null | Promise<string | null>;
|
|
816
|
-
defaultValue?: any;
|
|
817
|
-
}): {
|
|
818
|
-
name: string;
|
|
819
|
-
value: () => any;
|
|
820
|
-
error: () => string | null;
|
|
821
|
-
isTouched: () => boolean;
|
|
822
|
-
isDirty: () => boolean;
|
|
823
|
-
setValue: (value: any) => void;
|
|
824
|
-
setError: (error: string | null) => void;
|
|
825
|
-
validate: () => Promise<boolean>;
|
|
826
|
-
reset: () => void;
|
|
827
|
-
inputProps: () => Record<string, any>;
|
|
828
|
-
};
|
|
829
|
-
|
|
830
|
-
export const rules: {
|
|
831
|
-
required: (message?: string) => (value: any) => string | void;
|
|
832
|
-
minLength: (min: number, message?: string) => (value: any) => string | void;
|
|
833
|
-
maxLength: (max: number, message?: string) => (value: any) => string | void;
|
|
834
|
-
min: (min: number, message?: string) => (value: any) => string | void;
|
|
835
|
-
max: (max: number, message?: string) => (value: any) => string | void;
|
|
836
|
-
pattern: (regex: RegExp, message?: string) => (value: any) => string | void;
|
|
837
|
-
email: (message?: string) => (value: any) => string | void;
|
|
838
|
-
url: (message?: string) => (value: any) => string | void;
|
|
839
|
-
match: (field: string, message?: string) => (value: any, values: Record<string, any>) => string | void;
|
|
840
|
-
custom: <T extends (...args: any[]) => any>(validator: T) => T;
|
|
841
|
-
};
|
|
578
|
+
export function getResponse(): ServerResponse;
|
|
842
579
|
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
export function yupResolver(schema: { validate: (values: any, options?: any) => Promise<any> }):
|
|
850
|
-
(values: Record<string, any>) => Promise<{ values: Record<string, any>; errors: Record<string, FieldError> }>;
|
|
851
|
-
|
|
852
|
-
export function Input(props: Record<string, any>): VNode;
|
|
853
|
-
export function Textarea(props: Record<string, any>): VNode;
|
|
854
|
-
export function Select(props: Record<string, any>): VNode;
|
|
855
|
-
export function Checkbox(props: Record<string, any>): VNode;
|
|
856
|
-
export function Radio(props: Record<string, any>): VNode;
|
|
857
|
-
|
|
858
|
-
export function ErrorMessage(props: {
|
|
859
|
-
name: string;
|
|
860
|
-
formState?: FormState;
|
|
861
|
-
errors?: Record<string, FieldError> | (() => Record<string, FieldError>);
|
|
862
|
-
render?: (args: { message?: string; type?: string }) => VNodeChild;
|
|
863
|
-
}): VNode;
|
|
580
|
+
// The context of one server render (loader data, head sink, resources, the
|
|
581
|
+
// response), which what-server's renderToStringAsync takes and returns. It is
|
|
582
|
+
// public from here; what-core/internal declares it beside the functions that
|
|
583
|
+
// read and set it.
|
|
584
|
+
export type { ServerContext } from './internal.js';
|
|
864
585
|
|
|
865
586
|
// --- Structured Errors ---
|
|
866
587
|
|
|
588
|
+
/**
|
|
589
|
+
* A catalogue entry. The development build carries all of it; the production
|
|
590
|
+
* build carries `code`, `severity` and `template` only, and the fix and the
|
|
591
|
+
* worked example are in `what_fix` (the MCP tool) and docs/ERRORS.md.
|
|
592
|
+
*/
|
|
867
593
|
export interface ErrorCodeDefinition {
|
|
868
594
|
code: string;
|
|
869
595
|
severity: 'error' | 'warning';
|
|
870
596
|
template: string;
|
|
871
|
-
|
|
597
|
+
/** The fix. Absent in the production build. */
|
|
598
|
+
suggestion?: string;
|
|
599
|
+
/** A worked bad/good example. Absent in the production build, and on a few entries. */
|
|
872
600
|
codeExample?: string;
|
|
873
601
|
}
|
|
874
602
|
|
|
875
|
-
export const ERROR_CODES: Record<string, ErrorCodeDefinition>;
|
|
876
603
|
|
|
877
604
|
/**
|
|
878
605
|
* Look up a catalogue entry by its `ERR_*` code.
|
|
879
606
|
*
|
|
880
607
|
* Errors thrown outside what-core carry only their code — the suggestion and
|
|
881
608
|
* the worked example live once, in the catalogue, so that the client bundle
|
|
882
|
-
* does not have to ship the prose. This is how they are recovered
|
|
609
|
+
* does not have to ship the prose. This is how they are recovered, in
|
|
610
|
+
* development; the production build's entry has the code, severity and
|
|
611
|
+
* template only.
|
|
883
612
|
*/
|
|
884
613
|
export function getErrorDefinition(code: string): ErrorCodeDefinition | undefined;
|
|
885
614
|
|
|
886
615
|
export interface WhatErrorJSON {
|
|
887
616
|
code: string;
|
|
617
|
+
severity: 'error' | 'warning';
|
|
888
618
|
message: string;
|
|
889
619
|
suggestion?: string;
|
|
890
620
|
file?: string;
|
|
@@ -897,6 +627,8 @@ export interface WhatErrorJSON {
|
|
|
897
627
|
export class WhatError extends Error {
|
|
898
628
|
constructor(init: {
|
|
899
629
|
code: string;
|
|
630
|
+
/** Defaults to `'error'`: the class does not read the catalogue (see getErrorDefinition). */
|
|
631
|
+
severity?: 'error' | 'warning';
|
|
900
632
|
message: string;
|
|
901
633
|
suggestion?: string;
|
|
902
634
|
file?: string;
|
|
@@ -906,6 +638,7 @@ export class WhatError extends Error {
|
|
|
906
638
|
effect?: string;
|
|
907
639
|
});
|
|
908
640
|
code: string;
|
|
641
|
+
severity: 'error' | 'warning';
|
|
909
642
|
suggestion?: string;
|
|
910
643
|
file?: string;
|
|
911
644
|
line?: number;
|
|
@@ -915,90 +648,42 @@ export class WhatError extends Error {
|
|
|
915
648
|
toJSON(): WhatErrorJSON;
|
|
916
649
|
}
|
|
917
650
|
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
context?: Record<string, any>,
|
|
921
|
-
): WhatError;
|
|
922
|
-
export function classifyError(err: unknown, context?: Record<string, any>): WhatError;
|
|
923
|
-
export function collectError(error: WhatError): void;
|
|
924
|
-
export function getCollectedErrors(since?: number): Array<WhatErrorJSON & { timestamp: number }>;
|
|
925
|
-
export function clearCollectedErrors(): void;
|
|
926
|
-
|
|
927
|
-
// --- Guardrails ---
|
|
928
|
-
|
|
929
|
-
export interface GuardrailConfig {
|
|
930
|
-
signalReadDetection: boolean;
|
|
931
|
-
componentNaming: boolean;
|
|
932
|
-
importValidation: boolean;
|
|
933
|
-
}
|
|
651
|
+
// --- Diagnostics channel ---
|
|
652
|
+
// Development checks report coded events here; this is the read side.
|
|
934
653
|
|
|
935
|
-
export
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
// --- Agent Context ---
|
|
940
|
-
|
|
941
|
-
export interface HealthReport {
|
|
942
|
-
effectCycleRisk: boolean;
|
|
943
|
-
orphanEffects: number;
|
|
944
|
-
signalLeaks: number;
|
|
945
|
-
memoryPressure: 'low' | 'medium' | 'high';
|
|
946
|
-
recentErrorCount: number;
|
|
947
|
-
totalSignals: number;
|
|
948
|
-
totalComponents: number;
|
|
654
|
+
export interface DiagnosticSubject {
|
|
655
|
+
kind: string;
|
|
656
|
+
id?: string | number;
|
|
657
|
+
name?: string;
|
|
949
658
|
}
|
|
950
659
|
|
|
951
|
-
export
|
|
952
|
-
/**
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
/** Warn when a component function is not PascalCase. Dev-mode only; returns null in production. */
|
|
956
|
-
export function checkComponentName(name: string): GuardrailWarning | null;
|
|
957
|
-
|
|
958
|
-
export interface GuardrailWarning {
|
|
660
|
+
export interface DiagnosticEvent {
|
|
661
|
+
/** Monotonic sequence number; a repeat moves the event to a newer seq. */
|
|
662
|
+
seq: number;
|
|
959
663
|
code: string;
|
|
960
|
-
|
|
961
|
-
suggestion: string;
|
|
962
|
-
}
|
|
963
|
-
|
|
964
|
-
export interface InvalidImport {
|
|
965
|
-
name: string;
|
|
664
|
+
severity: 'error' | 'warning';
|
|
966
665
|
message: string;
|
|
967
|
-
suggestion
|
|
666
|
+
/** The catalogue suggestion for this code. */
|
|
667
|
+
fix: string;
|
|
668
|
+
/** Owner path, root first, e.g. ['<App>', '<TodoRow>', 'effect "sync"']. Empty when unknown. */
|
|
669
|
+
owner: string[];
|
|
670
|
+
/** Source location 'file:line:col' when the compiler supplied one. */
|
|
671
|
+
loc: string | null;
|
|
672
|
+
subject: DiagnosticSubject | null;
|
|
673
|
+
data: Record<string, any>;
|
|
674
|
+
/** Repeats of this code on this subject, folded into one event. */
|
|
675
|
+
count: number;
|
|
968
676
|
}
|
|
969
677
|
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
export
|
|
982
|
-
export function unregisterSignal(sig: unknown): void;
|
|
983
|
-
export function getActiveSignals(): unknown[];
|
|
984
|
-
|
|
985
|
-
// --- Internal cross-package exports ---
|
|
986
|
-
// Underscore-prefixed names are not public API and carry no compatibility
|
|
987
|
-
// promise. They are declared here because sibling packages in this repo import
|
|
988
|
-
// them across the package boundary (what-server, what-text), and an
|
|
989
|
-
// undeclared cross-package import is exactly the rename that ships broken:
|
|
990
|
-
// `hygiene:types` skips `_`-prefixed names in its reverse direction, so
|
|
991
|
-
// nothing else would have caught it. Application code should not use these.
|
|
992
|
-
|
|
993
|
-
/** @internal Used by what-server. True for `aria-*` and `data-*` attribute names. */
|
|
994
|
-
export function _isAriaAttr(name: string): boolean;
|
|
995
|
-
/** @internal Used by what-server. Opens an SSR component scope. */
|
|
996
|
-
export function _beginComponentSSR(...args: unknown[]): unknown;
|
|
997
|
-
/** @internal Used by what-server. Closes the scope opened by `_beginComponentSSR`. */
|
|
998
|
-
export function _endComponentSSR(...args: unknown[]): unknown;
|
|
999
|
-
/** @internal Used by what-server. The keyed-array mapping `<For>` compiles down to. */
|
|
1000
|
-
export function _mapArrayToArray(...args: unknown[]): unknown;
|
|
1001
|
-
/** @internal Used by what-server/node. Installs the Node AsyncLocalStorage backend. */
|
|
1002
|
-
export function __installServerContextStorage(storage: unknown): void;
|
|
1003
|
-
/** @internal Used by what-text. Lets the text engine intercept text-node insertion. */
|
|
1004
|
-
export function _setTextInsertHook(hook: unknown): void;
|
|
678
|
+
|
|
679
|
+
/** Listen to every report, repeats included. Returns an unsubscribe function. */
|
|
680
|
+
export function subscribeDiagnostics(listener: (event: DiagnosticEvent) => void): () => void;
|
|
681
|
+
/** Events with seq greater than `since`, oldest first; pass the returned seq back as the next `since`. */
|
|
682
|
+
export function getDiagnostics(options?: { since?: number }): { events: DiagnosticEvent[]; seq: number; dropped: number };
|
|
683
|
+
/** Forget buffered events and console pointers. */
|
|
684
|
+
export function clearDiagnostics(): void;
|
|
685
|
+
|
|
686
|
+
// Only what is exported above is public. Without this, a declaration file
|
|
687
|
+
// exports every top-level declaration, `ownerBrand` included, and an Owner
|
|
688
|
+
// could be forged.
|
|
689
|
+
export {};
|