brumate 0.5.2 → 0.6.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/dist/{boot-Difa0qdg.d.ts → boot-DkbcqdUz.d.ts} +2 -2
- package/dist/cli.js +2 -2
- package/dist/{client-De-7aGlO.js → client-C3vRNuLi.js} +353 -103
- package/dist/client-C3vRNuLi.js.map +1 -0
- package/dist/{client-DvsU9qxG.d.ts → client-CqGDbWd_.d.ts} +45 -8
- package/dist/{defer-DlFYiAuK.js → defer-M18UKyfG.js} +2 -2
- package/dist/{defer-DlFYiAuK.js.map → defer-M18UKyfG.js.map} +1 -1
- package/dist/{devtools-Di_dI9tS.js → devtools-YnvrZ6D8.js} +4 -4
- package/dist/{devtools-Di_dI9tS.js.map → devtools-YnvrZ6D8.js.map} +1 -1
- package/dist/{devtools-panel-BvIKX1LY.js → devtools-panel-DRcKclEG.js} +2 -2
- package/dist/{devtools-panel-BvIKX1LY.js.map → devtools-panel-DRcKclEG.js.map} +1 -1
- package/dist/{features-D5kLyihb.js → features-CbgII-o7.js} +4 -2
- package/dist/features-CbgII-o7.js.map +1 -0
- package/dist/{files-s4wmjcZV.js → files-HzPDUyTY.js} +2 -2
- package/dist/{files-s4wmjcZV.js.map → files-HzPDUyTY.js.map} +1 -1
- package/dist/index.d.ts +8 -4
- package/dist/index.js +2 -7
- package/dist/index.js.map +1 -1
- package/dist/{inspect-BLPt-dZZ.js → inspect-Q5W0A66e.js} +476 -122
- package/dist/inspect-Q5W0A66e.js.map +1 -0
- package/dist/{loader-krRrJuIv.js → loader-C-S3yzep.js} +13 -5
- package/dist/loader-C-S3yzep.js.map +1 -0
- package/dist/{navigate-BcV1qkkx.js → navigate-r23FFR6e.js} +5 -2
- package/dist/{navigate-BcV1qkkx.js.map → navigate-r23FFR6e.js.map} +1 -1
- package/dist/routes-D21FQyGF.js +51 -0
- package/dist/routes-D21FQyGF.js.map +1 -0
- package/dist/{rpc-BYYAj1vV.js → rpc-C_znDZ_w.js} +3 -3
- package/dist/{rpc-BYYAj1vV.js.map → rpc-C_znDZ_w.js.map} +1 -1
- package/dist/runtime/bundles.d.ts +1 -1
- package/dist/runtime/client.d.ts +2 -2
- package/dist/runtime/client.js +3 -3
- package/dist/runtime/devtools.d.ts +1 -1
- package/dist/runtime/devtools.js +1 -1
- package/dist/runtime/hot.d.ts +1 -1
- package/dist/runtime/loader.d.ts +2 -2
- package/dist/runtime/loader.js +2 -2
- package/dist/runtime/routes.js +1 -51
- package/dist/runtime/server.d.ts +2 -2
- package/dist/runtime/server.js +3 -3
- package/dist/runtime/signals.d.ts +2 -140
- package/dist/runtime/signals.js +4 -1
- package/dist/runtime/signals.js.map +1 -1
- package/dist/runtime/static-loader.d.ts +2 -2
- package/dist/runtime/static-loader.js +1 -1
- package/dist/runtime/testing.d.ts +24 -4
- package/dist/runtime/testing.js +66 -2
- package/dist/runtime/testing.js.map +1 -1
- package/dist/{produce-Cq6KKi7b.js → search-params-CM1RWR2P.js} +25 -3
- package/dist/search-params-CM1RWR2P.js.map +1 -0
- package/dist/{server-Doy5HR7r.js → server-BcT9icQ4.js} +107 -40
- package/dist/server-BcT9icQ4.js.map +1 -0
- package/dist/{server-CAwIqrXl.d.ts → server-dP_ucRiJ.d.ts} +42 -3
- package/dist/signals-BwD4u22K.d.ts +165 -0
- package/dist/{static-loader-DoHWsf9t.js → static-loader-Bt2WDkY1.js} +3 -3
- package/dist/{static-loader-DoHWsf9t.js.map → static-loader-Bt2WDkY1.js.map} +1 -1
- package/dist/{static-loader-9Nc1GvF0.d.ts → static-loader-DysAET-w.d.ts} +2 -2
- package/dist/{stream-BdhzvPQO.js → stream-DRjx0keF.js} +2 -2
- package/dist/{stream-BdhzvPQO.js.map → stream-DRjx0keF.js.map} +1 -1
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +18 -13
- package/dist/vite.js.map +1 -1
- package/elements.d.ts +239 -37
- package/package.json +6 -1
- package/skills/brumate/references/errors.md +46 -12
- package/skills/brumate/references/signals.md +27 -25
- package/skills/brumate/references/syntax.md +1 -1
- package/dist/client-De-7aGlO.js.map +0 -1
- package/dist/features-D5kLyihb.js.map +0 -1
- package/dist/inspect-BLPt-dZZ.js.map +0 -1
- package/dist/loader-krRrJuIv.js.map +0 -1
- package/dist/produce-Cq6KKi7b.js.map +0 -1
- package/dist/runtime/routes.js.map +0 -1
- package/dist/server-Doy5HR7r.js.map +0 -1
package/dist/runtime/routes.js
CHANGED
|
@@ -1,51 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* The URL of a route, with its params in place:
|
|
4
|
-
* `href('/todos/[id]', { id: '3' })` is `/todos/3`. A rest param, such as
|
|
5
|
-
* `[...path]`, keeps its slashes.
|
|
6
|
-
*/
|
|
7
|
-
function href(path, ...[params]) {
|
|
8
|
-
const values = params ?? {};
|
|
9
|
-
return path.replace(/\[(\.\.\.)?([^\]]+)\]/g, (_, rest, name) => {
|
|
10
|
-
const value = values[name];
|
|
11
|
-
if (value === void 0 || value === "") throw new Error(`The param ${name} of ${path} is missing`);
|
|
12
|
-
if (!rest) return encodeURIComponent(String(value));
|
|
13
|
-
const parts = [];
|
|
14
|
-
for (const part of String(value).split("/")) parts.push(encodeURIComponent(part));
|
|
15
|
-
return parts.join("/");
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Loads a page as a link does: the layouts that stay keep their state. It
|
|
20
|
-
* returns when the page shows. A URL of another origin, or a page without
|
|
21
|
-
* the loader, loads in full.
|
|
22
|
-
*
|
|
23
|
-
* ```ts
|
|
24
|
-
* await navigate(href('/issues/[id]', { id: issue.id }));
|
|
25
|
-
* navigate(`?q=${query}`, { replace: true });
|
|
26
|
-
* ```
|
|
27
|
-
*/
|
|
28
|
-
function navigate(to, options = {}) {
|
|
29
|
-
const url = new URL(to, location.href);
|
|
30
|
-
if (url.protocol !== "http:" && url.protocol !== "https:") return Promise.reject(/* @__PURE__ */ new TypeError(`navigate loads http and https URLs, not ${url.protocol}`));
|
|
31
|
-
if (url.origin !== location.origin) {
|
|
32
|
-
location.assign(url.href);
|
|
33
|
-
return new Promise(() => {});
|
|
34
|
-
}
|
|
35
|
-
return new Promise((resolve) => {
|
|
36
|
-
const event = new CustomEvent("brumate:navigate", {
|
|
37
|
-
cancelable: true,
|
|
38
|
-
detail: {
|
|
39
|
-
url: url.href,
|
|
40
|
-
replace: options.replace === true,
|
|
41
|
-
scroll: options.scroll !== false,
|
|
42
|
-
done: resolve
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
if (document.dispatchEvent(event)) location.assign(url.href);
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
//#endregion
|
|
49
|
-
export { href, navigate };
|
|
50
|
-
|
|
51
|
-
//# sourceMappingURL=routes.js.map
|
|
1
|
+
export { t as href, n as navigate } from "../routes-D21FQyGF.js";
|
package/dist/runtime/server.d.ts
CHANGED
|
@@ -3,5 +3,5 @@ import { A as onAttribute, C as escapeAttribute, E as internal, N as raw, R as v
|
|
|
3
3
|
import { t as produce } from "../produce-CLABZ8k2.js";
|
|
4
4
|
import { t as StandardSchemaV1 } from "../standard-schema-BNY82yX3.js";
|
|
5
5
|
import { f as Intent, v as SubmissionResult } from "../forms-j1xPAR14.js";
|
|
6
|
-
import { $ as idempotent, $t as
|
|
7
|
-
export { type CacheStore, type CachedOptions, ClientBundles, Component, Context, type CookieOptions, DeferTarget, DocumentOptions, ElementReference, type EndpointLoader, type EntryMiddleware, type FailedSubmission, FunctionReference, type Handler, type IdempotentOptions, type Intent, type IntentSubmission, ItemSource, Lazy, type Loader, type Locals, Mark, Memo, type Middleware, type MiddlewareLoader, type NavigationState, NotReady, PageCache, type PageState, type ParseResult, type RateLimit, type RateLimitConfig, RateLimitError, type RateLimitMiddleware, type RateLimitOptions, type RateLimitStore, type Raw, type Redirect, RenderOptions, RenderResult, type ReplyOptions, type RequestCall, RequestEvent, type RequestEventOptions, type RequestKind, RequestOptions, RevealOrder, type Route, type RouteMatch, type RouteNode, RouteOptions, type RouteView, ScopeEntry, type ScopeId, type ScopeState, ServerError, type Session, type SessionOptions, type StandardSchemaV1, StateAttributes, StateMap, StreamOptions, type Submission, type SubmissionOptions, type SubmissionResult, type SuccessfulSubmission, ValidationError, type ValidationIssue, type Window, action, actionResult, affix, attribute, binding, cached, caught, children, classAttribute, clientAddress, component, configureRateLimit, createContext, createSession, dedupe, defineMiddleware, dynamic, escape, escapeAttribute, fieldErrors, getEvent, handleRequest, handleRoute, idempotent, inlineBodies, insert, internal, isCrossSite, isRedirect, lazy, matchRoute, memo, memoryStore, mergeAttributes, navigationContext, onAttribute, packState, parse, parseCookies, parseForm, parseSubmission, produce, rateLimit, raw, read, ready, redirect, render, renderToStream, revalidate, routeContext, safeParse, serializeCookie, setCacheStore, setClientBundles, settled, spacerTag, spread, start, stateScript, stateValue, storageStore, streamParts, streamState, toNodeHeaders, unbind, useSerialEntry, vars, wait, waitAll, withEvent };
|
|
6
|
+
import { $ as idempotent, $t as defineMiddleware, A as handleRoute, At as safeParse, B as renderToStream, Bt as searchParam, C as attribute, Ct as parseSubmission, D as component, Dt as fieldErrors, E as children, Et as ValidationIssue, F as memo, Ft as MiddlewareLoader, G as start, Gt as RequestEvent, H as settled, Ht as Locals, I as packState, It as RouteMatch, J as streamParts, Jt as ServerError, K as stateScript, Kt as RequestEventOptions, L as read, Lt as RouteNode, M as insert, Mt as Handler, N as isCrossSite, Nt as Loader, O as dynamic, Ot as parse, P as lazy, Pt as Middleware, Q as IdempotentOptions, Qt as dedupe, R as ready, Rt as RouteView, S as actionResult, St as SuccessfulSubmission, T as caught, Tt as ValidationError, U as spacerTag, Ut as Redirect, V as setClientBundles, Vt as EntryMiddleware, W as spread, Wt as RequestCall, X as wait, Xt as ServerErrorInfo, Y as streamState, Yt as ServerErrorHandler, Z as waitAll, Zt as ServerErrorKind, _ as ScopeEntry, _t as FailedSubmission, a as DocumentOptions, an as Session, at as setCacheStore, b as StreamOptions, bt as Submission, c as Mark, cn as parseCookies, ct as RateLimitConfig, d as PageCache, dt as RateLimitOptions, en as getEvent, et as CacheStore, f as RenderOptions, ft as RateLimitStore, g as RouteOptions, gt as rateLimit, h as RevealOrder, ht as configureRateLimit, i as DeferTarget, in as CookieOptions, it as revalidate, j as inlineBodies, jt as EndpointLoader, k as handleRequest, kt as parseForm, l as Memo, ln as serializeCookie, lt as RateLimitError, m as RequestOptions, mt as clientAddress, n as Component, nn as redirect, nt as cached, o as ItemSource, on as SessionOptions, ot as storageStore, p as RenderResult, pt as Window, q as stateValue, qt as RequestKind, r as Context, rn as withEvent, rt as memoryStore, s as Lazy, sn as createSession, st as RateLimit, t as ClientBundles, tn as isRedirect, tt as CachedOptions, u as NotReady, un as toNodeHeaders, ut as RateLimitMiddleware, v as StateAttributes, vt as IntentSubmission, w as binding, wt as ParseResult, x as action, xt as SubmissionOptions, y as StateMap, yt as ReplyOptions, z as render, zt as matchRoute } from "../server-dP_ucRiJ.js";
|
|
7
|
+
export { type CacheStore, type CachedOptions, ClientBundles, Component, Context, type CookieOptions, DeferTarget, DocumentOptions, ElementReference, type EndpointLoader, type EntryMiddleware, type FailedSubmission, FunctionReference, type Handler, type IdempotentOptions, type Intent, type IntentSubmission, ItemSource, Lazy, type Loader, type Locals, Mark, Memo, type Middleware, type MiddlewareLoader, type NavigationState, NotReady, PageCache, type PageState, type ParseResult, type RateLimit, type RateLimitConfig, RateLimitError, type RateLimitMiddleware, type RateLimitOptions, type RateLimitStore, type Raw, type Redirect, RenderOptions, RenderResult, type ReplyOptions, type RequestCall, RequestEvent, type RequestEventOptions, type RequestKind, RequestOptions, RevealOrder, type Route, type RouteMatch, type RouteNode, RouteOptions, type RouteView, ScopeEntry, type ScopeId, type ScopeState, ServerError, type ServerErrorHandler, type ServerErrorInfo, type ServerErrorKind, type Session, type SessionOptions, type StandardSchemaV1, StateAttributes, StateMap, StreamOptions, type Submission, type SubmissionOptions, type SubmissionResult, type SuccessfulSubmission, ValidationError, type ValidationIssue, type Window, action, actionResult, affix, attribute, binding, cached, caught, children, classAttribute, clientAddress, component, configureRateLimit, createContext, createSession, dedupe, defineMiddleware, dynamic, escape, escapeAttribute, fieldErrors, getEvent, handleRequest, handleRoute, idempotent, inlineBodies, insert, internal, isCrossSite, isRedirect, lazy, matchRoute, memo, memoryStore, mergeAttributes, navigationContext, onAttribute, packState, parse, parseCookies, parseForm, parseSubmission, produce, rateLimit, raw, read, ready, redirect, render, renderToStream, revalidate, routeContext, safeParse, searchParam, serializeCookie, setCacheStore, setClientBundles, settled, spacerTag, spread, start, stateScript, stateValue, storageStore, streamParts, streamState, toNodeHeaders, unbind, useSerialEntry, vars, wait, waitAll, withEvent };
|
package/dist/runtime/server.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { E as vars, _ as mergeAttributes, c as classAttribute, d as escapeAttribute, i as affix, m as internal, u as escape, v as onAttribute, x as raw } from "../html-t1JpkODI.js";
|
|
2
2
|
import { a as serializeCookie, i as parseCookies, s as toNodeHeaders, t as createSession } from "../cookies-Cnbf4w-S.js";
|
|
3
|
-
import {
|
|
4
|
-
import { $ as dedupe, A as streamParts, B as ValidationError, C as setClientBundles, D as start, E as spread, F as RateLimitError, G as matchRoute, H as parse, I as clientAddress, J as revalidate, K as cached, L as configureRateLimit, M as wait, N as waitAll, O as stateScript, P as idempotent, Q as ServerError, R as rateLimit, S as renderToStream, T as spacerTag, U as parseForm, V as fieldErrors, W as safeParse, X as storageStore, Y as setCacheStore, Z as RequestEvent, _ as memo, a as attribute, b as ready, c as children, d as handleRequest, et as defineMiddleware, f as handleRoute, g as lazy, h as isCrossSite, i as actionResult, it as withEvent, j as streamState, k as stateValue, l as component, m as insert, n as NotReady, nt as isRedirect, o as binding, p as inlineBodies, q as memoryStore, r as action, rt as redirect, s as caught, t as Context, tt as getEvent, u as dynamic, v as packState, w as settled, x as render, y as read, z as parseSubmission } from "../server-
|
|
3
|
+
import { E as useSerialEntry, T as unbind, c as ElementReference, i as produce, l as FunctionReference, n as searchParam } from "../search-params-CM1RWR2P.js";
|
|
4
|
+
import { $ as dedupe, A as streamParts, B as ValidationError, C as setClientBundles, D as start, E as spread, F as RateLimitError, G as matchRoute, H as parse, I as clientAddress, J as revalidate, K as cached, L as configureRateLimit, M as wait, N as waitAll, O as stateScript, P as idempotent, Q as ServerError, R as rateLimit, S as renderToStream, T as spacerTag, U as parseForm, V as fieldErrors, W as safeParse, X as storageStore, Y as setCacheStore, Z as RequestEvent, _ as memo, a as attribute, b as ready, c as children, d as handleRequest, et as defineMiddleware, f as handleRoute, g as lazy, h as isCrossSite, i as actionResult, it as withEvent, j as streamState, k as stateValue, l as component, m as insert, n as NotReady, nt as isRedirect, o as binding, p as inlineBodies, q as memoryStore, r as action, rt as redirect, s as caught, t as Context, tt as getEvent, u as dynamic, v as packState, w as settled, x as render, y as read, z as parseSubmission } from "../server-BcT9icQ4.js";
|
|
5
5
|
import { a as routeContext, i as navigationContext, r as createContext } from "../context-CTiSzQRc.js";
|
|
6
|
-
export { Context, ElementReference, FunctionReference, NotReady, RateLimitError, RequestEvent, ServerError, ValidationError, action, actionResult, affix, attribute, binding, cached, caught, children, classAttribute, clientAddress, component, configureRateLimit, createContext, createSession, dedupe, defineMiddleware, dynamic, escape, escapeAttribute, fieldErrors, getEvent, handleRequest, handleRoute, idempotent, inlineBodies, insert, internal, isCrossSite, isRedirect, lazy, matchRoute, memo, memoryStore, mergeAttributes, navigationContext, onAttribute, packState, parse, parseCookies, parseForm, parseSubmission, produce, rateLimit, raw, read, ready, redirect, render, renderToStream, revalidate, routeContext, safeParse, serializeCookie, setCacheStore, setClientBundles, settled, spacerTag, spread, start, stateScript, stateValue, storageStore, streamParts, streamState, toNodeHeaders, unbind, useSerialEntry, vars, wait, waitAll, withEvent };
|
|
6
|
+
export { Context, ElementReference, FunctionReference, NotReady, RateLimitError, RequestEvent, ServerError, ValidationError, action, actionResult, affix, attribute, binding, cached, caught, children, classAttribute, clientAddress, component, configureRateLimit, createContext, createSession, dedupe, defineMiddleware, dynamic, escape, escapeAttribute, fieldErrors, getEvent, handleRequest, handleRoute, idempotent, inlineBodies, insert, internal, isCrossSite, isRedirect, lazy, matchRoute, memo, memoryStore, mergeAttributes, navigationContext, onAttribute, packState, parse, parseCookies, parseForm, parseSubmission, produce, rateLimit, raw, read, ready, redirect, render, renderToStream, revalidate, routeContext, safeParse, searchParam, serializeCookie, setCacheStore, setClientBundles, settled, spacerTag, spread, start, stateScript, stateValue, storageStore, streamParts, streamState, toNodeHeaders, unbind, useSerialEntry, vars, wait, waitAll, withEvent };
|
|
@@ -1,140 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
|
|
3
|
-
//#region src/runtime/signals.d.ts
|
|
4
|
-
declare const BINDABLE: unique symbol;
|
|
5
|
-
declare const WRITES: unique symbol;
|
|
6
|
-
/** The mark of a prop that a parent can bind. It has no value at runtime. */
|
|
7
|
-
export interface BindableMark<T> {
|
|
8
|
-
readonly [BINDABLE]: T;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* What a binding writes. A binding of a signal of `T` takes a prop that writes `W` when `W` is
|
|
12
|
-
* assignable to `T`, as a signal of `HTMLElement | undefined` takes the ref of a `div`.
|
|
13
|
-
*/
|
|
14
|
-
export interface WritableMark<W> {
|
|
15
|
-
readonly [WRITES]: (value: W) => void;
|
|
16
|
-
}
|
|
17
|
-
/** What `$bind` returns: the mark of a prop, and the write side that checks the type of a ref. */
|
|
18
|
-
export interface BoundSignal<T> extends BindableMark<T>, WritableMark<T> {}
|
|
19
|
-
/**
|
|
20
|
-
* Marks a prop that a parent can bind with `$bind`, such as
|
|
21
|
-
* `open?: Bindable<boolean>`. The parent passes `T` or `$bind(name)`.
|
|
22
|
-
* Inside the component, `$props<T>()` gives `T`.
|
|
23
|
-
*/
|
|
24
|
-
export type Bindable<T> = T | BindableMark<T>;
|
|
25
|
-
/** The props as the component reads them, with `Bindable<T>` as `T`. */
|
|
26
|
-
export type Unbound<T> = { [K in keyof T]: Exclude<T[K], BindableMark<unknown>>; };
|
|
27
|
-
/**
|
|
28
|
-
* Returns the props of the component. Destructure the call to keep each prop
|
|
29
|
-
* reactive. Destructure it with `let` to write props, such as
|
|
30
|
-
* `let { open = false } = $props()`.
|
|
31
|
-
*/
|
|
32
|
-
export declare function $props<T = Record<string, any>>(): Unbound<T>;
|
|
33
|
-
/** Declares writable state. The variable reads and writes the signal. */
|
|
34
|
-
export declare function $signal<T>(value: T): T;
|
|
35
|
-
export declare function $signal<T>(): T | undefined;
|
|
36
|
-
/** The value of a memo: what a promise settles to, or the latest value of an async iterable. */
|
|
37
|
-
export type MemoValue<T> = Awaited<T> extends AsyncIterable<infer U> ? U : Awaited<T>;
|
|
38
|
-
/**
|
|
39
|
-
* Declares a value computed from other values. A promise is awaited where it
|
|
40
|
-
* is read. An async iterable gives each of its values in turn.
|
|
41
|
-
*/
|
|
42
|
-
export declare function $memo<T>(_value: T): MemoValue<T>;
|
|
43
|
-
/**
|
|
44
|
-
* Declares a memo that takes the value once it stops changing for `ms`
|
|
45
|
-
* milliseconds, such as a search query while the user types. On the server,
|
|
46
|
-
* and until the value first changes, it is the value.
|
|
47
|
-
*/
|
|
48
|
-
export declare function $debounced<T>(_value: T, _ms: number): MemoValue<T>;
|
|
49
|
-
/**
|
|
50
|
-
* Declares a memo that takes the value at most once every `ms`
|
|
51
|
-
* milliseconds, and the last value after the wait, such as a position while
|
|
52
|
-
* the pointer moves. On the server, and until the value first changes, it is the value.
|
|
53
|
-
*/
|
|
54
|
-
export declare function $throttled<T>(_value: T, _ms: number): MemoValue<T>;
|
|
55
|
-
/**
|
|
56
|
-
* Declares a value that follows a memo, and that handlers can write. A write
|
|
57
|
-
* shows a guess, such as a new item while the form that adds it posts. The
|
|
58
|
-
* value goes back to the memo when the memo changes, or when the server
|
|
59
|
-
* calls of the page finish, such as after a failed post.
|
|
60
|
-
*/
|
|
61
|
-
export declare function $optimistic<T>(_source: T): T;
|
|
62
|
-
/** Runs a callback when the values it reads change, after the page resumes. Never on load. */
|
|
63
|
-
export declare function $effect(_callback: () => void | (() => void)): void;
|
|
64
|
-
/** Runs a callback in the browser when a trigger fires. */
|
|
65
|
-
export declare function $client(_callback: () => void | (() => void), _trigger?: "visible" | "idle" | "load"): void;
|
|
66
|
-
/** Reads a value without depending on it. */
|
|
67
|
-
export declare function $untrack<T>(_value: T): T;
|
|
68
|
-
/** True while a new value of a memo, or of a memo it reads, loads on the client. Always false on the server. */
|
|
69
|
-
export declare function $isPending(_memo: unknown): boolean;
|
|
70
|
-
/**
|
|
71
|
-
* Waits for a memo to have its value, and gives it. It resolves at once when the memo is settled,
|
|
72
|
-
* and after the load when the memo loads its first value or loads again. When the inputs of the
|
|
73
|
-
* memo change while it waits, it waits for the load of the current inputs. It rejects with the
|
|
74
|
-
* error of the memo, when `timeout` milliseconds pass, or when `signal` aborts. Use it in a handler,
|
|
75
|
-
* an effect or a `$client` callback, never where a memo computes or markup renders.
|
|
76
|
-
*/
|
|
77
|
-
export declare function $resolve<T>(_memo: T, _options?: {
|
|
78
|
-
timeout?: number;
|
|
79
|
-
signal?: AbortSignal;
|
|
80
|
-
}): Promise<Awaited<T>>;
|
|
81
|
-
/**
|
|
82
|
-
* True when the parent passed a prop with `$bind`, so a write of it reaches the parent. The prop is
|
|
83
|
-
* one that the component destructures with `let`. Always false on the server, where nothing writes.
|
|
84
|
-
*/
|
|
85
|
-
export declare function $isBound(_prop: unknown): boolean;
|
|
86
|
-
/**
|
|
87
|
-
* True when the caller passed the prop, even as `undefined`. A part uses it to tell a controlled
|
|
88
|
-
* value, such as `value=(null)`, from no value. Declare it with `const` in the component script.
|
|
89
|
-
*/
|
|
90
|
-
export declare function $isPassed(_prop: unknown): boolean;
|
|
91
|
-
/** Returns an ID that is unique in the page and the same on the server and the client. */
|
|
92
|
-
export declare function $id(): string;
|
|
93
|
-
/** Provides a value of a context to the components inside this one. */
|
|
94
|
-
export declare function $setContext<T>(_context: Context<T>, _value: T): void;
|
|
95
|
-
/** Reads a context from the nearest component above that provides it, or its default value. */
|
|
96
|
-
export declare function $getContext<T>(_context: Context<T>): T;
|
|
97
|
-
/**
|
|
98
|
-
* The route of the page: its URL, its query string and its params, typed
|
|
99
|
-
* from the route files as `href` is. The server reads the request, and the
|
|
100
|
-
* browser reads `location`. It changes when navigation changes the URL.
|
|
101
|
-
*/
|
|
102
|
-
export declare function $route<P extends RoutePath = RoutePath>(_path?: P): Route<RouteParams<P>>;
|
|
103
|
-
/** The navigation that loads, with `pending` false when none does. Always `{ pending: false }` on the server. */
|
|
104
|
-
export declare function $navigation(): NavigationState;
|
|
105
|
-
/** Changes an object or an array in a signal through a draft, and writes the signal with the result. */
|
|
106
|
-
export declare function $produce<T>(_signal: T, _recipe: (draft: T) => T | void): void;
|
|
107
|
-
/** Sets the title of the page. The last component that sets it wins. */
|
|
108
|
-
export declare function $title(_value: unknown): void;
|
|
109
|
-
/**
|
|
110
|
-
* The latest result of a server function that a form of this component posts
|
|
111
|
-
* to, or undefined before the first post. Pending while the form sends.
|
|
112
|
-
*/
|
|
113
|
-
export declare function $action<F extends (...args: never[]) => unknown>(_fn: F): Awaited<ReturnType<F>> | undefined;
|
|
114
|
-
/**
|
|
115
|
-
* Passes a child a signal, or a prop that the component writes, so a write
|
|
116
|
-
* of the prop in the child writes it. The child destructures the prop with
|
|
117
|
-
* `let`. Pass it as the value of a prop: `<Dialog open=$bind(open) />`.
|
|
118
|
-
*
|
|
119
|
-
* - Only a prop of type `Bindable<T>` takes it.
|
|
120
|
-
* - With `set`, a write calls `set(next)` in place of writing the signal.
|
|
121
|
-
*/
|
|
122
|
-
export declare function $bind<T>(signal: T, set?: (next: T) => unknown): BoundSignal<T>;
|
|
123
|
-
/**
|
|
124
|
-
* Marks a function that a script makes as an event handler, so a spread can
|
|
125
|
-
* pass it on, as it passes on a handler that a caller writes in markup.
|
|
126
|
-
* `args` are JSON values that go with the handler, and it runs as
|
|
127
|
-
* `fn(...args, event)`.
|
|
128
|
-
*/
|
|
129
|
-
export declare function $handler<A extends unknown[], E = Event>(fn: (...args: [...A, E]) => unknown, ...args: A): (event: E) => unknown;
|
|
130
|
-
/** A function that does not read the event. */
|
|
131
|
-
export declare function $handler<A extends unknown[]>(fn: (...args: A) => unknown, ...args: A): (event: Event) => unknown;
|
|
132
|
-
/**
|
|
133
|
-
* Writes what the writes of the handler so far changed to the page, so the code after it can read
|
|
134
|
-
* the DOM, such as to focus or measure what a write rendered. A handler is one pass, and the page
|
|
135
|
-
* changes when it returns. Does nothing outside a handler, and on the server.
|
|
136
|
-
*/
|
|
137
|
-
export declare function flush(): void;
|
|
138
|
-
//#endregion
|
|
139
|
-
export {};
|
|
140
|
-
//# sourceMappingURL=signals.d.ts.map
|
|
1
|
+
import { A as Unbound, C as $title, D as BoundSignal, E as BindableMark, M as flush, O as MemoValue, S as $throttled, T as Bindable, _ as $resolve, a as $effect, b as $setContext, c as $id, d as $isPending, f as $memo, g as $props, h as $produce, i as $debounced, j as WritableMark, k as SearchParamOptions, l as $isBound, m as $optimistic, n as $bind, o as $getContext, p as $navigation, r as $client, s as $handler, t as $action, u as $isPassed, v as $route, w as $untrack, x as $signal, y as $searchParam } from "../signals-BwD4u22K.js";
|
|
2
|
+
export { $action, $bind, $client, $debounced, $effect, $getContext, $handler, $id, $isBound, $isPassed, $isPending, $memo, $navigation, $optimistic, $produce, $props, $resolve, $route, $searchParam, $setContext, $signal, $throttled, $title, $untrack, Bindable, BindableMark, BoundSignal, MemoValue, SearchParamOptions, Unbound, WritableMark, flush };
|
package/dist/runtime/signals.js
CHANGED
|
@@ -105,6 +105,9 @@ function $getContext(_context) {
|
|
|
105
105
|
function $route(_path) {
|
|
106
106
|
return compileTimeOnly("$route");
|
|
107
107
|
}
|
|
108
|
+
function $searchParam() {
|
|
109
|
+
return compileTimeOnly("$searchParam");
|
|
110
|
+
}
|
|
108
111
|
/** The navigation that loads, with `pending` false when none does. Always `{ pending: false }` on the server. */
|
|
109
112
|
function $navigation() {
|
|
110
113
|
return compileTimeOnly("$navigation");
|
|
@@ -139,6 +142,6 @@ function flush() {
|
|
|
139
142
|
globalThis[Symbol.for("brumate.flush")]?.();
|
|
140
143
|
}
|
|
141
144
|
//#endregion
|
|
142
|
-
export { $action, $bind, $client, $debounced, $effect, $getContext, $handler, $id, $isBound, $isPassed, $isPending, $memo, $navigation, $optimistic, $produce, $props, $resolve, $route, $setContext, $signal, $throttled, $title, $untrack, flush };
|
|
145
|
+
export { $action, $bind, $client, $debounced, $effect, $getContext, $handler, $id, $isBound, $isPassed, $isPending, $memo, $navigation, $optimistic, $produce, $props, $resolve, $route, $searchParam, $setContext, $signal, $throttled, $title, $untrack, flush };
|
|
143
146
|
|
|
144
147
|
//# sourceMappingURL=signals.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signals.js","names":[],"sources":["../../src/runtime/signals.ts"],"sourcesContent":["// The compile-time functions of `.brm` files. The compiler replaces every\n// call and removes the import, so this module only gives them their types.\n// A call outside a `.brm` file throws.\n\nimport type { Context, NavigationState, Route } from './context.ts';\nimport type { RoutePath, RouteParams } from './routes.ts';\n\nfunction compileTimeOnly(name: string): never {\n throw new Error(`${name} works only in .brm files, which the brumate compiler compiles`);\n}\n\ndeclare const BINDABLE: unique symbol;\ndeclare const WRITES: unique symbol;\n\n/** The mark of a prop that a parent can bind. It has no value at runtime. */\nexport interface BindableMark<T> {\n readonly [BINDABLE]: T;\n}\n\n/**\n * What a binding writes. A binding of a signal of `T` takes a prop that writes `W` when `W` is\n * assignable to `T`, as a signal of `HTMLElement | undefined` takes the ref of a `div`.\n */\nexport interface WritableMark<W> {\n readonly [WRITES]: (value: W) => void;\n}\n\n/** What `$bind` returns: the mark of a prop, and the write side that checks the type of a ref. */\n// oxlint-disable-next-line typescript/no-empty-object-type, typescript/no-empty-interface -- An interface keeps its name in messages.\nexport interface BoundSignal<T> extends BindableMark<T>, WritableMark<T> {}\n\n/**\n * Marks a prop that a parent can bind with `$bind`, such as\n * `open?: Bindable<boolean>`. The parent passes `T` or `$bind(name)`.\n * Inside the component, `$props<T>()` gives `T`.\n */\nexport type Bindable<T> = T | BindableMark<T>;\n\n/** The props as the component reads them, with `Bindable<T>` as `T`. */\nexport type Unbound<T> = { [K in keyof T]: Exclude<T[K], BindableMark<unknown>> };\n\n/**\n * Returns the props of the component. Destructure the call to keep each prop\n * reactive. Destructure it with `let` to write props, such as\n * `let { open = false } = $props()`.\n */\n// oxlint-disable-next-line typescript/no-explicit-any -- Props are any object unless typed.\nexport function $props<T = Record<string, any>>(): Unbound<T> {\n return compileTimeOnly('$props');\n}\n\n/** Declares writable state. The variable reads and writes the signal. */\nexport function $signal<T>(value: T): T;\nexport function $signal<T>(): T | undefined;\nexport function $signal(): never {\n return compileTimeOnly('$signal');\n}\n\n/** The value of a memo: what a promise settles to, or the latest value of an async iterable. */\nexport type MemoValue<T> = Awaited<T> extends AsyncIterable<infer U> ? U : Awaited<T>;\n\n/**\n * Declares a value computed from other values. A promise is awaited where it\n * is read. An async iterable gives each of its values in turn.\n */\nexport function $memo<T>(_value: T): MemoValue<T> {\n return compileTimeOnly('$memo');\n}\n\n/**\n * Declares a memo that takes the value once it stops changing for `ms`\n * milliseconds, such as a search query while the user types. On the server,\n * and until the value first changes, it is the value.\n */\nexport function $debounced<T>(_value: T, _ms: number): MemoValue<T> {\n return compileTimeOnly('$debounced');\n}\n\n/**\n * Declares a memo that takes the value at most once every `ms`\n * milliseconds, and the last value after the wait, such as a position while\n * the pointer moves. On the server, and until the value first changes, it is the value.\n */\nexport function $throttled<T>(_value: T, _ms: number): MemoValue<T> {\n return compileTimeOnly('$throttled');\n}\n\n/**\n * Declares a value that follows a memo, and that handlers can write. A write\n * shows a guess, such as a new item while the form that adds it posts. The\n * value goes back to the memo when the memo changes, or when the server\n * calls of the page finish, such as after a failed post.\n */\nexport function $optimistic<T>(_source: T): T {\n return compileTimeOnly('$optimistic');\n}\n\n/** Runs a callback when the values it reads change, after the page resumes. Never on load. */\nexport function $effect(_callback: () => void | (() => void)): void {\n compileTimeOnly('$effect');\n}\n\n/** Runs a callback in the browser when a trigger fires. */\nexport function $client(\n _callback: () => void | (() => void),\n _trigger?: 'visible' | 'idle' | 'load',\n): void {\n compileTimeOnly('$client');\n}\n\n/** Reads a value without depending on it. */\nexport function $untrack<T>(_value: T): T {\n return compileTimeOnly('$untrack');\n}\n\n/** True while a new value of a memo, or of a memo it reads, loads on the client. Always false on the server. */\nexport function $isPending(_memo: unknown): boolean {\n return compileTimeOnly('$isPending');\n}\n\n/**\n * Waits for a memo to have its value, and gives it. It resolves at once when the memo is settled,\n * and after the load when the memo loads its first value or loads again. When the inputs of the\n * memo change while it waits, it waits for the load of the current inputs. It rejects with the\n * error of the memo, when `timeout` milliseconds pass, or when `signal` aborts. Use it in a handler,\n * an effect or a `$client` callback, never where a memo computes or markup renders.\n */\nexport function $resolve<T>(\n _memo: T,\n _options?: { timeout?: number; signal?: AbortSignal },\n): Promise<Awaited<T>> {\n return compileTimeOnly('$resolve');\n}\n\n/**\n * True when the parent passed a prop with `$bind`, so a write of it reaches the parent. The prop is\n * one that the component destructures with `let`. Always false on the server, where nothing writes.\n */\nexport function $isBound(_prop: unknown): boolean {\n return compileTimeOnly('$isBound');\n}\n\n/**\n * True when the caller passed the prop, even as `undefined`. A part uses it to tell a controlled\n * value, such as `value=(null)`, from no value. Declare it with `const` in the component script.\n */\nexport function $isPassed(_prop: unknown): boolean {\n return compileTimeOnly('$isPassed');\n}\n\n/** Returns an ID that is unique in the page and the same on the server and the client. */\nexport function $id(): string {\n return compileTimeOnly('$id');\n}\n\n/** Provides a value of a context to the components inside this one. */\nexport function $setContext<T>(_context: Context<T>, _value: T): void {\n compileTimeOnly('$setContext');\n}\n\n/** Reads a context from the nearest component above that provides it, or its default value. */\nexport function $getContext<T>(_context: Context<T>): T {\n return compileTimeOnly('$getContext');\n}\n\n/**\n * The route of the page: its URL, its query string and its params, typed\n * from the route files as `href` is. The server reads the request, and the\n * browser reads `location`. It changes when navigation changes the URL.\n */\nexport function $route<P extends RoutePath = RoutePath>(_path?: P): Route<RouteParams<P>> {\n return compileTimeOnly('$route');\n}\n\n/** The navigation that loads, with `pending` false when none does. Always `{ pending: false }` on the server. */\nexport function $navigation(): NavigationState {\n return compileTimeOnly('$navigation');\n}\n\n/** Changes an object or an array in a signal through a draft, and writes the signal with the result. */\nexport function $produce<T>(_signal: T, _recipe: (draft: T) => T | void): void {\n compileTimeOnly('$produce');\n}\n\n/** Sets the title of the page. The last component that sets it wins. */\nexport function $title(_value: unknown): void {\n compileTimeOnly('$title');\n}\n\n/**\n * The latest result of a server function that a form of this component posts\n * to, or undefined before the first post. Pending while the form sends.\n */\nexport function $action<F extends (...args: never[]) => unknown>(\n _fn: F,\n): Awaited<ReturnType<F>> | undefined {\n return compileTimeOnly('$action');\n}\n\n/**\n * Passes a child a signal, or a prop that the component writes, so a write\n * of the prop in the child writes it. The child destructures the prop with\n * `let`. Pass it as the value of a prop: `<Dialog open=$bind(open) />`.\n *\n * - Only a prop of type `Bindable<T>` takes it.\n * - With `set`, a write calls `set(next)` in place of writing the signal.\n */\nexport function $bind<T>(signal: T, set?: (next: T) => unknown): BoundSignal<T>;\nexport function $bind(): never {\n return compileTimeOnly('$bind');\n}\n\n/**\n * Marks a function that a script makes as an event handler, so a spread can\n * pass it on, as it passes on a handler that a caller writes in markup.\n * `args` are JSON values that go with the handler, and it runs as\n * `fn(...args, event)`.\n */\nexport function $handler<A extends unknown[], E = Event>(\n fn: (...args: [...A, E]) => unknown,\n ...args: A\n): (event: E) => unknown;\n/** A function that does not read the event. */\nexport function $handler<A extends unknown[]>(\n fn: (...args: A) => unknown,\n ...args: A\n): (event: Event) => unknown;\nexport function $handler(): never {\n return compileTimeOnly('$handler');\n}\n\n/**\n * Writes what the writes of the handler so far changed to the page, so the code after it can read\n * the DOM, such as to focus or measure what a write rendered. A handler is one pass, and the page\n * changes when it returns. Does nothing outside a handler, and on the server.\n */\nexport function flush(): void {\n (globalThis as { [key: symbol]: (() => void) | undefined })[Symbol.for('brumate.flush')]?.();\n}\n"],"mappings":";AAOA,SAAS,gBAAgB,MAAqB;CAC5C,MAAM,IAAI,MAAM,GAAG,KAAK,+DAA+D;AACzF;;;;;;AAsCA,SAAgB,SAA8C;CAC5D,OAAO,gBAAgB,QAAQ;AACjC;AAKA,SAAgB,UAAiB;CAC/B,OAAO,gBAAgB,SAAS;AAClC;;;;;AASA,SAAgB,MAAS,QAAyB;CAChD,OAAO,gBAAgB,OAAO;AAChC;;;;;;AAOA,SAAgB,WAAc,QAAW,KAA2B;CAClE,OAAO,gBAAgB,YAAY;AACrC;;;;;;AAOA,SAAgB,WAAc,QAAW,KAA2B;CAClE,OAAO,gBAAgB,YAAY;AACrC;;;;;;;AAQA,SAAgB,YAAe,SAAe;CAC5C,OAAO,gBAAgB,aAAa;AACtC;;AAGA,SAAgB,QAAQ,WAA4C;CAClE,gBAAgB,SAAS;AAC3B;;AAGA,SAAgB,QACd,WACA,UACM;CACN,gBAAgB,SAAS;AAC3B;;AAGA,SAAgB,SAAY,QAAc;CACxC,OAAO,gBAAgB,UAAU;AACnC;;AAGA,SAAgB,WAAW,OAAyB;CAClD,OAAO,gBAAgB,YAAY;AACrC;;;;;;;;AASA,SAAgB,SACd,OACA,UACqB;CACrB,OAAO,gBAAgB,UAAU;AACnC;;;;;AAMA,SAAgB,SAAS,OAAyB;CAChD,OAAO,gBAAgB,UAAU;AACnC;;;;;AAMA,SAAgB,UAAU,OAAyB;CACjD,OAAO,gBAAgB,WAAW;AACpC;;AAGA,SAAgB,MAAc;CAC5B,OAAO,gBAAgB,KAAK;AAC9B;;AAGA,SAAgB,YAAe,UAAsB,QAAiB;CACpE,gBAAgB,aAAa;AAC/B;;AAGA,SAAgB,YAAe,UAAyB;CACtD,OAAO,gBAAgB,aAAa;AACtC;;;;;;AAOA,SAAgB,OAAwC,OAAkC;CACxF,OAAO,gBAAgB,QAAQ;AACjC;;AAGA,SAAgB,cAA+B;CAC7C,OAAO,gBAAgB,aAAa;AACtC;;AAGA,SAAgB,SAAY,SAAY,SAAuC;CAC7E,gBAAgB,UAAU;AAC5B;;AAGA,SAAgB,OAAO,QAAuB;CAC5C,gBAAgB,QAAQ;AAC1B;;;;;AAMA,SAAgB,QACd,KACoC;CACpC,OAAO,gBAAgB,SAAS;AAClC;AAWA,SAAgB,QAAe;CAC7B,OAAO,gBAAgB,OAAO;AAChC;AAiBA,SAAgB,WAAkB;CAChC,OAAO,gBAAgB,UAAU;AACnC;;;;;;AAOA,SAAgB,QAAc;CAC5B,WAA4D,OAAO,IAAI,eAAe,EAAE,GAAG;AAC7F"}
|
|
1
|
+
{"version":3,"file":"signals.js","names":[],"sources":["../../src/runtime/signals.ts"],"sourcesContent":["// The compile-time functions of `.brm` files. The compiler replaces every\n// call and removes the import, so this module only gives them their types.\n// A call outside a `.brm` file throws.\n\nimport type { Context, NavigationState, Route } from './context.ts';\nimport type { RoutePath, RouteParams } from './routes.ts';\n\nfunction compileTimeOnly(name: string): never {\n throw new Error(`${name} works only in .brm files, which the brumate compiler compiles`);\n}\n\ndeclare const BINDABLE: unique symbol;\ndeclare const WRITES: unique symbol;\n\n/** The mark of a prop that a parent can bind. It has no value at runtime. */\nexport interface BindableMark<T> {\n readonly [BINDABLE]: T;\n}\n\n/**\n * What a binding writes. A binding of a signal of `T` takes a prop that writes `W` when `W` is\n * assignable to `T`, as a signal of `HTMLElement | undefined` takes the ref of a `div`.\n */\nexport interface WritableMark<W> {\n readonly [WRITES]: (value: W) => void;\n}\n\n/** What `$bind` returns: the mark of a prop, and the write side that checks the type of a ref. */\n// oxlint-disable-next-line typescript/no-empty-object-type, typescript/no-empty-interface -- An interface keeps its name in messages.\nexport interface BoundSignal<T> extends BindableMark<T>, WritableMark<T> {}\n\n/**\n * Marks a prop that a parent can bind with `$bind`, such as\n * `open?: Bindable<boolean>`. The parent passes `T` or `$bind(name)`.\n * Inside the component, `$props<T>()` gives `T`.\n */\nexport type Bindable<T> = T | BindableMark<T>;\n\n/** The props as the component reads them, with `Bindable<T>` as `T`. */\nexport type Unbound<T> = { [K in keyof T]: Exclude<T[K], BindableMark<unknown>> };\n\n/**\n * Returns the props of the component. Destructure the call to keep each prop\n * reactive. Destructure it with `let` to write props, such as\n * `let { open = false } = $props()`.\n */\n// oxlint-disable-next-line typescript/no-explicit-any -- Props are any object unless typed.\nexport function $props<T = Record<string, any>>(): Unbound<T> {\n return compileTimeOnly('$props');\n}\n\n/** Declares writable state. The variable reads and writes the signal. */\nexport function $signal<T>(value: T): T;\nexport function $signal<T>(): T | undefined;\nexport function $signal(): never {\n return compileTimeOnly('$signal');\n}\n\n/** The value of a memo: what a promise settles to, or the latest value of an async iterable. */\nexport type MemoValue<T> = Awaited<T> extends AsyncIterable<infer U> ? U : Awaited<T>;\n\n/**\n * Declares a value computed from other values. A promise is awaited where it\n * is read. An async iterable gives each of its values in turn.\n */\nexport function $memo<T>(_value: T): MemoValue<T> {\n return compileTimeOnly('$memo');\n}\n\n/**\n * Declares a memo that takes the value once it stops changing for `ms`\n * milliseconds, such as a search query while the user types. On the server,\n * and until the value first changes, it is the value.\n */\nexport function $debounced<T>(_value: T, _ms: number): MemoValue<T> {\n return compileTimeOnly('$debounced');\n}\n\n/**\n * Declares a memo that takes the value at most once every `ms`\n * milliseconds, and the last value after the wait, such as a position while\n * the pointer moves. On the server, and until the value first changes, it is the value.\n */\nexport function $throttled<T>(_value: T, _ms: number): MemoValue<T> {\n return compileTimeOnly('$throttled');\n}\n\n/**\n * Declares a value that follows a memo, and that handlers can write. A write\n * shows a guess, such as a new item while the form that adds it posts. The\n * value goes back to the memo when the memo changes, or when the server\n * calls of the page finish, such as after a failed post.\n */\nexport function $optimistic<T>(_source: T): T {\n return compileTimeOnly('$optimistic');\n}\n\n/** Runs a callback when the values it reads change, after the page resumes. Never on load. */\nexport function $effect(_callback: () => void | (() => void)): void {\n compileTimeOnly('$effect');\n}\n\n/** Runs a callback in the browser when a trigger fires. */\nexport function $client(\n _callback: () => void | (() => void),\n _trigger?: 'visible' | 'idle' | 'load',\n): void {\n compileTimeOnly('$client');\n}\n\n/** Reads a value without depending on it. */\nexport function $untrack<T>(_value: T): T {\n return compileTimeOnly('$untrack');\n}\n\n/** True while a new value of a memo, or of a memo it reads, loads on the client. Always false on the server. */\nexport function $isPending(_memo: unknown): boolean {\n return compileTimeOnly('$isPending');\n}\n\n/**\n * Waits for a memo to have its value, and gives it. It resolves at once when the memo is settled,\n * and after the load when the memo loads its first value or loads again. When the inputs of the\n * memo change while it waits, it waits for the load of the current inputs. It rejects with the\n * error of the memo, when `timeout` milliseconds pass, or when `signal` aborts. Use it in a handler,\n * an effect or a `$client` callback, never where a memo computes or markup renders.\n */\nexport function $resolve<T>(\n _memo: T,\n _options?: { timeout?: number; signal?: AbortSignal },\n): Promise<Awaited<T>> {\n return compileTimeOnly('$resolve');\n}\n\n/**\n * True when the parent passed a prop with `$bind`, so a write of it reaches the parent. The prop is\n * one that the component destructures with `let`. Always false on the server, where nothing writes.\n */\nexport function $isBound(_prop: unknown): boolean {\n return compileTimeOnly('$isBound');\n}\n\n/**\n * True when the caller passed the prop, even as `undefined`. A part uses it to tell a controlled\n * value, such as `value=(null)`, from no value. Declare it with `const` in the component script.\n */\nexport function $isPassed(_prop: unknown): boolean {\n return compileTimeOnly('$isPassed');\n}\n\n/** Returns an ID that is unique in the page and the same on the server and the client. */\nexport function $id(): string {\n return compileTimeOnly('$id');\n}\n\n/** Provides a value of a context to the components inside this one. */\nexport function $setContext<T>(_context: Context<T>, _value: T): void {\n compileTimeOnly('$setContext');\n}\n\n/** Reads a context from the nearest component above that provides it, or its default value. */\nexport function $getContext<T>(_context: Context<T>): T {\n return compileTimeOnly('$getContext');\n}\n\n/**\n * The route of the page: its URL, its query string and its params, typed\n * from the route files as `href` is. The server reads the request, and the\n * browser reads `location`. It changes when navigation changes the URL.\n */\nexport function $route<P extends RoutePath = RoutePath>(_path?: P): Route<RouteParams<P>> {\n return compileTimeOnly('$route');\n}\n\n/** The options of `$searchParam`. */\nexport interface SearchParamOptions<T> {\n /** The value while the parameter is not in the URL. A write of this value leaves the parameter out. */\n default?: T;\n /** Converts the text of the parameter to a value. Defaults to the text. */\n parse?: (text: string) => T;\n /** Converts a value to the text of the parameter. Defaults to `String`. */\n serialize?: (value: T) => string;\n /** `'push'` adds an entry to the history for each change, and `'replace'` (the default) changes the entry. */\n history?: 'push' | 'replace';\n /** True asks the server for the page again when the parameter changes, as a link to the new URL does. */\n server?: boolean;\n}\n\n/**\n * A signal bound to one parameter of the query string. The server reads the URL of the request.\n * A write in the browser changes the URL with `history.replaceState`, or `pushState` with\n * `{ history: 'push' }`, and asks the server nothing. Back and forward write the signal.\n */\nexport function $searchParam(name: string, options?: SearchParamOptions<string>): string | null;\nexport function $searchParam<T>(name: string, options: SearchParamOptions<T> & { default: T }): T;\nexport function $searchParam<T>(\n name: string,\n options: SearchParamOptions<T> & { parse: (text: string) => T },\n): T | null;\nexport function $searchParam(): never {\n return compileTimeOnly('$searchParam');\n}\n\n/** The navigation that loads, with `pending` false when none does. Always `{ pending: false }` on the server. */\nexport function $navigation(): NavigationState {\n return compileTimeOnly('$navigation');\n}\n\n/** Changes an object or an array in a signal through a draft, and writes the signal with the result. */\nexport function $produce<T>(_signal: T, _recipe: (draft: T) => T | void): void {\n compileTimeOnly('$produce');\n}\n\n/** Sets the title of the page. The last component that sets it wins. */\nexport function $title(_value: unknown): void {\n compileTimeOnly('$title');\n}\n\n/**\n * The latest result of a server function that a form of this component posts\n * to, or undefined before the first post. Pending while the form sends.\n */\nexport function $action<F extends (...args: never[]) => unknown>(\n _fn: F,\n): Awaited<ReturnType<F>> | undefined {\n return compileTimeOnly('$action');\n}\n\n/**\n * Passes a child a signal, or a prop that the component writes, so a write\n * of the prop in the child writes it. The child destructures the prop with\n * `let`. Pass it as the value of a prop: `<Dialog open=$bind(open) />`.\n *\n * - Only a prop of type `Bindable<T>` takes it.\n * - With `set`, a write calls `set(next)` in place of writing the signal.\n */\nexport function $bind<T>(signal: T, set?: (next: T) => unknown): BoundSignal<T>;\nexport function $bind(): never {\n return compileTimeOnly('$bind');\n}\n\n/**\n * Marks a function that a script makes as an event handler, so a spread can\n * pass it on, as it passes on a handler that a caller writes in markup.\n * `args` are JSON values that go with the handler, and it runs as\n * `fn(...args, event)`.\n */\nexport function $handler<A extends unknown[], E = Event>(\n fn: (...args: [...A, E]) => unknown,\n ...args: A\n): (event: E) => unknown;\n/** A function that does not read the event. */\nexport function $handler<A extends unknown[]>(\n fn: (...args: A) => unknown,\n ...args: A\n): (event: Event) => unknown;\nexport function $handler(): never {\n return compileTimeOnly('$handler');\n}\n\n/**\n * Writes what the writes of the handler so far changed to the page, so the code after it can read\n * the DOM, such as to focus or measure what a write rendered. A handler is one pass, and the page\n * changes when it returns. Does nothing outside a handler, and on the server.\n */\nexport function flush(): void {\n (globalThis as { [key: symbol]: (() => void) | undefined })[Symbol.for('brumate.flush')]?.();\n}\n"],"mappings":";AAOA,SAAS,gBAAgB,MAAqB;CAC5C,MAAM,IAAI,MAAM,GAAG,KAAK,+DAA+D;AACzF;;;;;;AAsCA,SAAgB,SAA8C;CAC5D,OAAO,gBAAgB,QAAQ;AACjC;AAKA,SAAgB,UAAiB;CAC/B,OAAO,gBAAgB,SAAS;AAClC;;;;;AASA,SAAgB,MAAS,QAAyB;CAChD,OAAO,gBAAgB,OAAO;AAChC;;;;;;AAOA,SAAgB,WAAc,QAAW,KAA2B;CAClE,OAAO,gBAAgB,YAAY;AACrC;;;;;;AAOA,SAAgB,WAAc,QAAW,KAA2B;CAClE,OAAO,gBAAgB,YAAY;AACrC;;;;;;;AAQA,SAAgB,YAAe,SAAe;CAC5C,OAAO,gBAAgB,aAAa;AACtC;;AAGA,SAAgB,QAAQ,WAA4C;CAClE,gBAAgB,SAAS;AAC3B;;AAGA,SAAgB,QACd,WACA,UACM;CACN,gBAAgB,SAAS;AAC3B;;AAGA,SAAgB,SAAY,QAAc;CACxC,OAAO,gBAAgB,UAAU;AACnC;;AAGA,SAAgB,WAAW,OAAyB;CAClD,OAAO,gBAAgB,YAAY;AACrC;;;;;;;;AASA,SAAgB,SACd,OACA,UACqB;CACrB,OAAO,gBAAgB,UAAU;AACnC;;;;;AAMA,SAAgB,SAAS,OAAyB;CAChD,OAAO,gBAAgB,UAAU;AACnC;;;;;AAMA,SAAgB,UAAU,OAAyB;CACjD,OAAO,gBAAgB,WAAW;AACpC;;AAGA,SAAgB,MAAc;CAC5B,OAAO,gBAAgB,KAAK;AAC9B;;AAGA,SAAgB,YAAe,UAAsB,QAAiB;CACpE,gBAAgB,aAAa;AAC/B;;AAGA,SAAgB,YAAe,UAAyB;CACtD,OAAO,gBAAgB,aAAa;AACtC;;;;;;AAOA,SAAgB,OAAwC,OAAkC;CACxF,OAAO,gBAAgB,QAAQ;AACjC;AA2BA,SAAgB,eAAsB;CACpC,OAAO,gBAAgB,cAAc;AACvC;;AAGA,SAAgB,cAA+B;CAC7C,OAAO,gBAAgB,aAAa;AACtC;;AAGA,SAAgB,SAAY,SAAY,SAAuC;CAC7E,gBAAgB,UAAU;AAC5B;;AAGA,SAAgB,OAAO,QAAuB;CAC5C,gBAAgB,QAAQ;AAC1B;;;;;AAMA,SAAgB,QACd,KACoC;CACpC,OAAO,gBAAgB,SAAS;AAClC;AAWA,SAAgB,QAAe;CAC7B,OAAO,gBAAgB,OAAO;AAChC;AAiBA,SAAgB,WAAkB;CAChC,OAAO,gBAAgB,UAAU;AACnC;;;;;;AAOA,SAAgB,QAAc;CAC5B,WAA4D,OAAO,IAAI,eAAe,EAAE,GAAG;AAC7F"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { t as LoaderOptions } from "../boot-
|
|
2
|
-
import { t as startWithoutNavigation } from "../static-loader-
|
|
1
|
+
import { t as LoaderOptions } from "../boot-DkbcqdUz.js";
|
|
2
|
+
import { t as startWithoutNavigation } from "../static-loader-DysAET-w.js";
|
|
3
3
|
export { type LoaderOptions, startWithoutNavigation };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as startWithoutNavigation } from "../static-loader-
|
|
1
|
+
export { t as startWithoutNavigation } from "../static-loader-Bt2WDkY1.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Wt as ClientModule } from "../client-CqGDbWd_.js";
|
|
2
|
+
import { Vt as EntryMiddleware, Yt as ServerErrorHandler, f as RenderOptions, n as Component } from "../server-dP_ucRiJ.js";
|
|
3
3
|
//#region src/runtime/testing.d.ts
|
|
4
4
|
/** The middleware of files of server functions, by function ID. */
|
|
5
5
|
type FileMiddleware = Record<string, EntryMiddleware>;
|
|
@@ -32,7 +32,25 @@ export interface Actions {
|
|
|
32
32
|
*/
|
|
33
33
|
waitFor: (assertion: () => void, timeout?: number) => Promise<void>;
|
|
34
34
|
}
|
|
35
|
-
|
|
35
|
+
/** The options of `checkAccessibility`. */
|
|
36
|
+
export interface AccessibilityOptions {
|
|
37
|
+
/** Turns axe-core rules on or off by ID, over the defaults of the test. */
|
|
38
|
+
rules?: Record<string, {
|
|
39
|
+
enabled: boolean;
|
|
40
|
+
}>;
|
|
41
|
+
}
|
|
42
|
+
export interface Checks {
|
|
43
|
+
/**
|
|
44
|
+
* Runs axe-core on what the test rendered, and throws with each violation,
|
|
45
|
+
* its element and its fix. Needs `axe-core` installed. Rules about a whole
|
|
46
|
+
* page are off for `mount`. The landmark rules, such as `landmark-one-main`,
|
|
47
|
+
* are off for `visit` while an element with `inert` or `aria-modal="true"`
|
|
48
|
+
* is in the page. Rules that need layout, such as `color-contrast`,
|
|
49
|
+
* are off, since the DOM of a test has none.
|
|
50
|
+
*/
|
|
51
|
+
checkAccessibility: (options?: AccessibilityOptions) => Promise<void>;
|
|
52
|
+
}
|
|
53
|
+
export interface Mounted extends Actions, Checks {
|
|
36
54
|
/** The element that holds the component. */
|
|
37
55
|
container: HTMLElement;
|
|
38
56
|
/** Stops the loader and removes the component. */
|
|
@@ -59,6 +77,8 @@ export interface AnswerOptions {
|
|
|
59
77
|
onCall?: (id: string) => void;
|
|
60
78
|
/** The middleware of the entry, which runs before each call. `virtual:brumate/testing` passes the app's. */
|
|
61
79
|
middleware?: EntryMiddleware;
|
|
80
|
+
/** The `onError` of the entry middleware, which gets the errors of calls. `virtual:brumate/testing` passes the app's. */
|
|
81
|
+
onError?: ServerErrorHandler;
|
|
62
82
|
/**
|
|
63
83
|
* The middleware of each `'use server'` file, by function ID, or a
|
|
64
84
|
* function that imports them. `virtual:brumate/testing` passes them.
|
|
@@ -92,7 +112,7 @@ export interface VisitOptions {
|
|
|
92
112
|
/** A selector of elements that stay out of view until `reveal` brings them in. */
|
|
93
113
|
offscreen?: string;
|
|
94
114
|
}
|
|
95
|
-
export interface Visited extends Actions {
|
|
115
|
+
export interface Visited extends Actions, Checks {
|
|
96
116
|
/** The path and the query of the page, such as `/issues?q=bug`. It changes with client navigation. */
|
|
97
117
|
readonly url: string;
|
|
98
118
|
/** The status of the first page. */
|
package/dist/runtime/testing.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { d as handleRequest, x as render } from "../server-
|
|
2
|
-
import { t as start } from "../loader-
|
|
1
|
+
import { d as handleRequest, x as render } from "../server-BcT9icQ4.js";
|
|
2
|
+
import { t as start } from "../loader-C-S3yzep.js";
|
|
3
3
|
//#region src/runtime/nodes.ts
|
|
4
4
|
const VOID = /* @__PURE__ */ new Set([
|
|
5
5
|
"area",
|
|
@@ -42,6 +42,67 @@ function wholeNodes(markup) {
|
|
|
42
42
|
}
|
|
43
43
|
//#endregion
|
|
44
44
|
//#region src/runtime/testing.ts
|
|
45
|
+
/** The rules about the document itself, which stay on for a page that an inert background covers. */
|
|
46
|
+
const DOCUMENT_RULES = [
|
|
47
|
+
"bypass",
|
|
48
|
+
"document-title",
|
|
49
|
+
"html-has-lang",
|
|
50
|
+
"html-lang-valid"
|
|
51
|
+
];
|
|
52
|
+
/** The rules about the landmarks of a page, which an inert background breaks. */
|
|
53
|
+
const LANDMARK_RULES = [
|
|
54
|
+
"landmark-one-main",
|
|
55
|
+
"page-has-heading-one",
|
|
56
|
+
"region",
|
|
57
|
+
"landmark-unique",
|
|
58
|
+
"landmark-no-duplicate-banner",
|
|
59
|
+
"landmark-no-duplicate-contentinfo",
|
|
60
|
+
"landmark-no-duplicate-main",
|
|
61
|
+
"landmark-banner-is-top-level",
|
|
62
|
+
"landmark-contentinfo-is-top-level",
|
|
63
|
+
"landmark-main-is-top-level",
|
|
64
|
+
"landmark-complementary-is-top-level"
|
|
65
|
+
];
|
|
66
|
+
/** The rules that need layout, which happy-dom has none of. */
|
|
67
|
+
const LAYOUT_RULES = [
|
|
68
|
+
"color-contrast",
|
|
69
|
+
"color-contrast-enhanced",
|
|
70
|
+
"scrollable-region-focusable"
|
|
71
|
+
];
|
|
72
|
+
/** Loads axe-core, or says how to install it. */
|
|
73
|
+
async function loadAxe() {
|
|
74
|
+
try {
|
|
75
|
+
const module = await import("axe-core");
|
|
76
|
+
return module.default ?? module;
|
|
77
|
+
} catch (cause) {
|
|
78
|
+
throw new Error("checkAccessibility needs axe-core. Install it with: npm install --save-dev axe-core", { cause });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** The accessibility check for the elements inside `root`. */
|
|
82
|
+
function checks(root, wholePage) {
|
|
83
|
+
return { checkAccessibility: async (options = {}) => {
|
|
84
|
+
const axe = await loadAxe();
|
|
85
|
+
const rules = {};
|
|
86
|
+
for (const id of LAYOUT_RULES) rules[id] = { enabled: false };
|
|
87
|
+
const inert = wholePage && document.querySelector("[inert], [aria-modal=\"true\"]") !== null;
|
|
88
|
+
if (!wholePage || inert) for (const id of LANDMARK_RULES) rules[id] = { enabled: false };
|
|
89
|
+
if (!wholePage) for (const id of DOCUMENT_RULES) rules[id] = { enabled: false };
|
|
90
|
+
const { violations } = await axe.run(root, { rules: {
|
|
91
|
+
...rules,
|
|
92
|
+
...options.rules
|
|
93
|
+
} });
|
|
94
|
+
if (violations.length === 0) return;
|
|
95
|
+
const lines = [];
|
|
96
|
+
for (const violation of violations) {
|
|
97
|
+
lines.push(`${violation.id}: ${violation.help} (${violation.helpUrl})`);
|
|
98
|
+
for (const node of violation.nodes) {
|
|
99
|
+
lines.push(` ${node.html}`);
|
|
100
|
+
if (node.failureSummary) lines.push(` ${node.failureSummary.replaceAll("\n", "\n ")}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
throw new Error(`${violations.length} accessibility violation(s):\n${lines.join("\n")}`);
|
|
104
|
+
} };
|
|
105
|
+
}
|
|
45
106
|
let view;
|
|
46
107
|
/** Reports an element that waits out of view, as visible. */
|
|
47
108
|
function reveal(element) {
|
|
@@ -251,6 +312,7 @@ function createMount(options) {
|
|
|
251
312
|
return {
|
|
252
313
|
container,
|
|
253
314
|
...actions(container),
|
|
315
|
+
...checks(container, false),
|
|
254
316
|
unmount: () => {
|
|
255
317
|
stop();
|
|
256
318
|
container.remove();
|
|
@@ -305,6 +367,7 @@ function answerCalls(functions, options = {}) {
|
|
|
305
367
|
function handle() {
|
|
306
368
|
return handleRequest(registry, request, prefix, {
|
|
307
369
|
middleware: options.middleware,
|
|
370
|
+
onError: options.onError,
|
|
308
371
|
fileMiddleware
|
|
309
372
|
});
|
|
310
373
|
}
|
|
@@ -465,6 +528,7 @@ function createVisit(options) {
|
|
|
465
528
|
})();
|
|
466
529
|
const current = {
|
|
467
530
|
...actions(document),
|
|
531
|
+
...checks(document, true),
|
|
468
532
|
get url() {
|
|
469
533
|
return location.pathname + location.search;
|
|
470
534
|
},
|