strata-react 1.0.2 → 1.0.4

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.
@@ -0,0 +1,4 @@
1
+ /** Reads `#rgb`, `#rrggbb` (with or without the #) as lower-case `#rrggbb`, or null. */
2
+ export declare function parseHex(text: string): string | null;
3
+ /** WCAG contrast ratio between two `#rrggbb` colours, 1 to 21. */
4
+ export declare function contrastRatio(a: string, b: string): number;
@@ -0,0 +1,29 @@
1
+ /** Zoom and pan of a picture inside its frame. `scale` 1 is the picture fitted; `x` and `y` are pixels from the centre. */
2
+ export type Viewport = {
3
+ scale: number;
4
+ x: number;
5
+ y: number;
6
+ };
7
+ /** The picture fitted in its frame, not panned. */
8
+ export declare const FIT: Viewport;
9
+ /** The least zoom: the whole picture fitted. */
10
+ export declare const MIN_SCALE = 1;
11
+ /** The most zoom, 32 times the fit. */
12
+ export declare const MAX_SCALE = 32;
13
+ /** Keeps the picture from being dragged out of its frame: at most half the extra width or height past each edge. */
14
+ export declare function clampViewport(v: Viewport, frame: {
15
+ width: number;
16
+ height: number;
17
+ }): Viewport;
18
+ /** A new scale with the point under `at` (pixels from the frame's centre) staying under it. */
19
+ export declare function zoomAt(v: Viewport, nextScale: number, at: {
20
+ x: number;
21
+ y: number;
22
+ }, frame: {
23
+ width: number;
24
+ height: number;
25
+ }): Viewport;
26
+ /** The scale at which the picture's own pixels are drawn one to one: its natural width over the width it is fitted at. */
27
+ export declare function actualPixelsScale(naturalWidth: number, fittedWidth: number): number;
28
+ /** The CSS transform for a viewport. */
29
+ export declare function viewportTransform(v: Viewport): string;
@@ -127,6 +127,14 @@ function fieldErrorsOf(error) {
127
127
  }
128
128
  // src/components/field.tsx
129
129
  var FieldContext = React.createContext(null);
130
+ /** @internal The surrounding Field, and where a control reports its own message. */
131
+ function useFieldControl() {
132
+ const field = React.useContext(FieldContext);
133
+ return {
134
+ field,
135
+ report: field?.report ?? noReport
136
+ };
137
+ }
130
138
  function useField(id) {
131
139
  const field = React.useContext(FieldContext);
132
140
  return {
@@ -135,18 +143,23 @@ function useField(id) {
135
143
  "aria-invalid": field?.invalid || void 0
136
144
  };
137
145
  }
146
+ var noReport = () => {};
138
147
  /** A labelled form field: wires the label, hint, error, `aria-describedby` and `aria-invalid` into the one control it wraps. */
139
148
  function Field({ label, id: idProp, hint, error, action, children, className }) {
140
149
  const generated = React.useId();
141
150
  const id = idProp ?? generated;
142
151
  const hintId = hint ? `${id}-hint` : void 0;
143
- const errorId = error ? `${id}-error` : void 0;
152
+ const [reported, report] = React.useState();
153
+ const shown = error ?? reported;
154
+ const errorId = shown ? `${id}-error` : void 0;
144
155
  const describedBy = [errorId, hintId].filter(Boolean).join(" ") || void 0;
145
156
  return /* @__PURE__ */ jsx(FieldContext.Provider, {
146
157
  value: {
147
158
  id,
159
+ label,
148
160
  describedBy,
149
- invalid: Boolean(error)
161
+ invalid: Boolean(shown),
162
+ report
150
163
  },
151
164
  children: /* @__PURE__ */ jsxs("div", {
152
165
  className: cn("grid min-w-0 content-start gap-1.5", className),
@@ -166,13 +179,13 @@ function Field({ label, id: idProp, hint, error, action, children, className })
166
179
  children: action
167
180
  })]
168
181
  }) : children,
169
- error && /* @__PURE__ */ jsxs("p", {
182
+ shown && /* @__PURE__ */ jsxs("p", {
170
183
  id: errorId,
171
184
  className: "flex items-start gap-1.5 type-body-sm text-danger",
172
185
  children: [/* @__PURE__ */ jsx(CircleAlert, {
173
186
  "aria-hidden": true,
174
187
  className: "mt-0.5 size-4 shrink-0"
175
- }), error]
188
+ }), shown]
176
189
  }),
177
190
  hint && /* @__PURE__ */ jsx("p", {
178
191
  id: hintId,
@@ -492,6 +505,6 @@ async function fetchJson(input, init, { readError = readErrorBody } = {}) {
492
505
  const text = res.status === 204 ? "" : await res.text();
493
506
  return text ? JSON.parse(text) : void 0;
494
507
  }
495
- export { Tooltip$1 as C, readErrorBody as S, typeSteps as T, Textarea as _, toLoad as a, describeHttpError as b, ColorSchemeChoice as c, useColorScheme as d, useSystemColorScheme as f, NativeSelect as g, Input$1 as h, staleOf as i, ThemeProvider as l, Field as m, createQueryClient as n, useLoad as o, ChoiceGroup as p, fetchJson as r, COLOR_SCHEME_STORAGE_KEY as s, StrataQueryProvider as t, colorSchemeScript as u, HttpError as v, cn as w, fieldErrorsOf as x, describeActionError as y };
508
+ export { readErrorBody as C, typeSteps as E, fieldErrorsOf as S, cn as T, Textarea as _, toLoad as a, describeActionError as b, ColorSchemeChoice as c, useColorScheme as d, useSystemColorScheme as f, NativeSelect as g, Input$1 as h, staleOf as i, ThemeProvider as l, Field as m, createQueryClient as n, useLoad as o, ChoiceGroup as p, fetchJson as r, COLOR_SCHEME_STORAGE_KEY as s, StrataQueryProvider as t, colorSchemeScript as u, useFieldControl as v, Tooltip$1 as w, describeHttpError as x, HttpError as y };
496
509
 
497
- //# sourceMappingURL=query-BVh4zv7Y.js.map
510
+ //# sourceMappingURL=query-gC6I6Cen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"query-gC6I6Cen.js","names":["Tooltip","AriaTooltip","Input","Tooltip"],"sources":["../src/lib/utils.ts","../src/components/tooltip.tsx","../src/lib/errors.ts","../src/components/field.tsx","../src/components/theme.tsx","../src/query/index.tsx"],"sourcesContent":["import { clsx, type ClassValue } from \"clsx\";\nimport { extendTailwindMerge } from \"tailwind-merge\";\n\n// Teach tailwind-merge that `type-*` utilities are font sizes. Without this, cn() cannot tell\n// `type-label` from a colour and may drop one of two classes that both survive in CSS; with stock\n// shadcn the same bug drops `text-muted-foreground` next to a custom `text-*` size.\nexport const typeSteps = [\"caption\", \"label\", \"body-sm\", \"body\", \"heading\", \"title\", \"figure\", \"display\"] as const;\n\n// The radius roles too, so `rounded-pill` at a call site (a round avatar Thumbnail) replaces a\n// component's `rounded-control` instead of both surviving and CSS order picking one.\nconst radiusRoles = [\"control\", \"surface\", \"overlay\", \"pill\"] as const;\n\nconst twMerge = extendTailwindMerge({\n extend: {\n theme: { radius: [...radiusRoles] },\n classGroups: {\n \"font-size\": [{ type: [...typeSteps] }],\n },\n },\n});\n\n/** clsx + tailwind-merge, taught that `type-*` utilities are font sizes and `rounded-control`, `-surface`, `-overlay`, `-pill` are radii. */\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n","import * as React from \"react\";\nimport { Tooltip as AriaTooltip, TooltipTrigger } from \"react-aria-components\";\nimport { cn } from \"../lib/utils\";\n\n// A tooltip names or explains a control; it is never the only place information lives. React Aria\n// opens it on keyboard focus as well as hover (strata-vid's old hover-only tooltip hid it from\n// keyboard users), after a short delay so a pointer crossing a toolbar does not flash every tip,\n// and shares the delay between neighbouring tips. It holds only words: anything interactive is a\n// Popover. It is portalled to the body, so a parent's overflow cannot clip it, and sits on the\n// `layer-tip` layer above dialogs, since it can name a control inside one.\n//\n// `IconButton` uses it for its required `label`, so the name and the visible hint come from one\n// string and cannot drift.\n\n/** Props for `Tooltip`. */\nexport type TooltipProps = {\n /** The words: a control's name or one sentence about it. Not interactive. */\n label: React.ReactNode;\n /** A shortcut or other aside shown after the label, muted (\"Ctrl+Z\"). */\n hint?: React.ReactNode;\n /** The element that gets the tip. It must be a React Aria pressable or focusable (a Strata `Button` is). */\n children: React.ReactElement;\n /** Which side of the trigger it prefers; it flips when there is no room. Default `top`. */\n side?: \"top\" | \"right\" | \"bottom\" | \"left\";\n /** Milliseconds before it opens on hover. Focus opens it at once. Default 500. */\n delay?: number;\n /** A controlled open state, for a story or test that needs it shown. */\n open?: boolean;\n className?: string;\n};\n\n/** A hover-and-focus tooltip for a control, portalled above everything. Words only; not the only home of information. */\nexport function Tooltip({ label, hint, children, side = \"top\", delay = 500, open, className }: TooltipProps) {\n return (\n <TooltipTrigger delay={delay} closeDelay={0} isOpen={open}>\n {children}\n <AriaTooltip\n placement={side}\n offset={6}\n className={cn(\"layer-tip enter-overlay max-w-xs rounded-control bg-foreground px-2 py-1 type-caption text-background\", className)}\n >\n {label}\n {hint != null && <span className=\"ml-2 opacity-70\">{hint}</span>}\n </AriaTooltip>\n </TooltipTrigger>\n );\n}\n","// Errors, described for a person. Anything that fails in front of someone (a load in DataView, an\n// action in AsyncButton) says what happened in a sentence, in the product's words, not the\n// developer's: `HttpError`'s own message (\"409 Conflict from /api/bookings\") is for logs. Loads\n// and actions share HttpError's status sentences, so the same failure reads the same everywhere,\n// and differ only in what is true afterwards: a failed load changed nothing, while a failed action\n// may have reached the server, so its sentence does not promise that.\n//\n// A server's own reason beats the status text (strata-react issue #42, from python-app-template).\n// FastAPI and most JSON APIs say why a 4xx happened in the body (`{\"detail\": \"the data folder must\n// be an absolute path\"}`), and a client that drops it has to repeat every server rule to show the\n// person anything better than \"Bad Request\", which drifts and cannot cover rules only the server\n// can check. So `fetchJson` reads an error response's body, `HttpError` keeps it with the reason\n// and any per-field messages found in it, and the sentences below use the reason for a 4xx.\n// Per-field messages (FastAPI's 422 `detail: [{loc, msg}]`) are keyed by field name, so\n// `useAsyncAction`'s `fieldErrors` can put each under its `Field`, never in a toast. A 5xx body is\n// not shown: it is usually a stack trace or a proxy's HTML page, and is kept on `body` for logs.\n\n/** What `readErrorBody` finds in an error response: the server's sentence, and messages per field. */\nexport type ErrorBody = {\n /** Why the server refused, in its own words. */\n reason?: string;\n /** Messages for individual fields, keyed by field name (`\"name\"`, `\"address.city\"`). */\n fields?: Record<string, string>;\n};\n\n/** Thrown by `fetchJson` on a non-2xx response; carries the status, the response body and the server's reason for `describeHttpError` and `describeActionError`. */\nexport class HttpError extends Error {\n /** The server's sentence for why it refused, from the body (`detail`, `message`, `error`), if it gave one. */\n readonly reason?: string;\n /** Messages for individual fields from the body (FastAPI's 422 `detail: [{loc, msg}]`), keyed by field name. Empty when there are none. */\n readonly fieldErrors: Readonly<Record<string, string>>;\n\n constructor(\n readonly status: number,\n readonly statusText: string,\n readonly url: string,\n /** The response body: parsed JSON when it was JSON, else its text; undefined when empty. */\n readonly body?: unknown,\n found: ErrorBody = readErrorBody(body),\n ) {\n super(`${status} ${statusText} from ${url}`);\n this.name = \"HttpError\";\n this.reason = found.reason;\n this.fieldErrors = found.fields ?? {};\n }\n}\n\nconst text = (value: unknown) => (typeof value === \"string\" && value.trim() ? value.trim() : undefined);\n\n/** A field name from a FastAPI/pydantic `loc`: the path after where it came from (`[\"body\", \"address\", \"city\"]` is `\"address.city\"`). */\nfunction fieldName(loc: unknown) {\n if (!Array.isArray(loc)) return undefined;\n const path = loc.map(String);\n if ([\"body\", \"query\", \"path\", \"header\", \"cookie\", \"form\"].includes(path[0]) && path.length > 1) path.shift();\n return path.join(\".\") || undefined;\n}\n\n/**\n * The default reading of an error body, for the shapes most JSON APIs use: `{ detail: \"…\" }`\n * (FastAPI), `{ message: \"…\" }`, `{ error: \"…\" }` or `{ error: { message: \"…\" } }` for the reason,\n * and FastAPI's validation list `{ detail: [{ loc, msg }] }` for per-field messages. A short\n * plain-text body (not HTML) is taken as the reason too. Pass your own to `fetchJson` for other APIs.\n */\nexport function readErrorBody(body: unknown): ErrorBody {\n if (typeof body === \"string\") {\n const t = text(body);\n return t && t.length <= 300 && !t.startsWith(\"<\") ? { reason: t } : {};\n }\n if (!body || typeof body !== \"object\") return {};\n const b = body as Record<string, unknown>;\n if (Array.isArray(b.detail)) {\n const fields: Record<string, string> = {};\n for (const item of b.detail as unknown[]) {\n const entry = item as { loc?: unknown; msg?: unknown } | null;\n const name = fieldName(entry?.loc);\n const msg = text(entry?.msg);\n if (name && msg && !fields[name]) fields[name] = msg;\n }\n return { fields };\n }\n const nested = b.error && typeof b.error === \"object\" ? text((b.error as Record<string, unknown>).message) : undefined;\n return { reason: text(b.detail) ?? text(b.message) ?? text(b.error) ?? nested };\n}\n\n/** Writes an error for a person: what happened, in a sentence. A product passes its own words. */\nexport type DescribeError = (error: unknown) => string;\n\n/** A sentence ends once: \"…absolute path\" and \"…absolute path.\" both end in one full stop. */\nconst sentence = (s: string) => (/[.!?…]$/.test(s) ? s : `${s}.`);\n\nfunction refused(error: HttpError) {\n if (error.reason) return `The request was refused: ${sentence(error.reason)}`;\n if (Object.keys(error.fieldErrors).length) return \"The request was refused: check the fields marked.\";\n return `The request was refused (${error.status}): ${error.statusText || \"no reason given\"}.`;\n}\n\n/** The default `DescribeError` for loads: the HTTP status in a sentence (with the server's reason for a 4xx), else the error's message, else a plain fallback. */\nexport const describeHttpError: DescribeError = (error) =>\n error instanceof HttpError\n ? error.status >= 500\n ? `The server could not answer (${error.status}). Nothing was changed.`\n : refused(error)\n : error instanceof Error && error.message\n ? error.message\n : \"The data could not be loaded. Nothing was changed.\";\n\n/** The default for `useAsyncAction`: the HTTP status in a sentence (with the server's reason for a 4xx), else the thrown Error's message, else undefined (the retry label alone). */\nexport const describeActionError = (error: unknown): string | undefined =>\n error instanceof HttpError\n ? error.status >= 500\n ? `The server could not answer (${error.status}).`\n : refused(error)\n : error instanceof Error && error.message\n ? error.message\n : undefined;\n\n/** Messages for individual fields carried by what was thrown: an `HttpError`'s `fieldErrors`, else none. */\nexport function fieldErrorsOf(error: unknown): Readonly<Record<string, string>> {\n return error instanceof HttpError ? error.fieldErrors : {};\n}\n","import * as React from \"react\";\nimport { CircleAlert } from \"lucide-react\";\nimport { Label, Radio, RadioGroup } from \"react-aria-components\";\nimport { cn } from \"../lib/utils\";\n\n// Field owns the wiring a generated form usually forgets: the label's htmlFor, aria-describedby\n// pointing at the hint and the error, and aria-invalid. Controls read it from context, so a control\n// inside a Field cannot end up unlabelled or silently invalid.\n//\n// A one-field form (\"paste a link, Add\", a search box, \"invite by email\") puts its button on the\n// control's row, not beside the whole field (strata-react issue #46, from the Tubes Library\n// screen): in a plain flex row the button lines up with label, hint and error together and drifts\n// off the input whenever one shows. `action` is drawn on the control's row, both at --control-h,\n// with the hint and the error under both across the full width. It wraps under the control only\n// when the row cannot keep the control 14rem wide beside it: on a phone a short \"Add\" stays on the\n// row, as a search box's button does, and a long label or a narrow column wraps. The error and hint stay the input's description; the\n// button is not described by them. Field messages for a form come from `useAsyncAction`'s\n// `fieldErrors` (its `validate`, or the server's 422), so no `problem` state is kept by hand.\n\ntype FieldState = { id: string; label: string; describedBy?: string; invalid: boolean; report: (message: string | undefined) => void };\nconst FieldContext = React.createContext<FieldState | null>(null);\n\n// A control that checks what was typed (a number field, a colour field) reports its own message to\n// the Field it sits in, which draws it as the field's error, so a value outside the limits is\n// explained in the same place and way as a server's 422, with nothing for the screen to wire.\n// `error` from the screen wins over the control's own. Outside a Field `report` does nothing and\n// the control marks itself invalid without a message.\n/** @internal The surrounding Field, and where a control reports its own message. */\nexport function useFieldControl() {\n const field = React.useContext(FieldContext);\n return { field, report: field?.report ?? noReport };\n}\n\nfunction useField(id?: string) {\n const field = React.useContext(FieldContext);\n return {\n // Inside a Field the Field's id wins, so the label always points at the control. To choose the\n // id yourself, pass it to Field.\n id: field?.id ?? id,\n \"aria-describedby\": field?.describedBy,\n \"aria-invalid\": field?.invalid || undefined,\n };\n}\n\nconst noReport = () => {};\n\nexport type FieldProps = {\n label: string;\n /** The control's id, when the page needs a known one (an anchor, a test). Generated otherwise. */\n id?: string;\n /** What the person needs to know before typing, such as limits or units. */\n hint?: React.ReactNode;\n /** What went wrong and how to fix it, in one sentence. Shown under the control, never in a toast. */\n error?: string;\n /** A button on the control's row, for a one-field form (an `AsyncButton` \"Add\"). The hint and error run under both; on a narrow screen it wraps under the control. */\n action?: React.ReactNode;\n children: React.ReactNode;\n className?: string;\n};\n\n/** A labelled form field: wires the label, hint, error, `aria-describedby` and `aria-invalid` into the one control it wraps. */\nexport function Field({ label, id: idProp, hint, error, action, children, className }: FieldProps) {\n const generated = React.useId();\n const id = idProp ?? generated;\n const hintId = hint ? `${id}-hint` : undefined;\n const [reported, report] = React.useState<string>();\n const shown = error ?? reported;\n const errorId = shown ? `${id}-error` : undefined;\n const describedBy = [errorId, hintId].filter(Boolean).join(\" \") || undefined;\n\n return (\n <FieldContext.Provider value={{ id, label, describedBy, invalid: Boolean(shown), report }}>\n <div className={cn(\"grid min-w-0 content-start gap-1.5\", className)}>\n <label htmlFor={id} className=\"type-label text-foreground\">\n {label}\n </label>\n {action ? (\n <div className=\"flex flex-wrap items-start gap-2\">\n <div className=\"min-w-56 flex-1\">{children}</div>\n <div className=\"flex shrink-0 items-center\">{action}</div>\n </div>\n ) : (\n children\n )}\n {shown && (\n <p id={errorId} className=\"flex items-start gap-1.5 type-body-sm text-danger\">\n <CircleAlert aria-hidden className=\"mt-0.5 size-4 shrink-0\" />\n {shown}\n </p>\n )}\n {hint && (\n <p id={hintId} className=\"type-body-sm text-muted-foreground\">\n {hint}\n </p>\n )}\n </div>\n </FieldContext.Provider>\n );\n}\n\nconst control =\n \"w-full min-w-0 rounded-control border border-input bg-background px-3 type-body text-foreground transition-state placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:bg-muted disabled:opacity-70 aria-invalid:border-danger\";\n\n/** A text input that picks up its id and descriptions from the surrounding `Field`. */\nexport function Input({ className, id, ...props }: React.ComponentProps<\"input\">) {\n return <input {...useField(id)} className={cn(control, \"h-(--control-h)\", className)} {...props} />;\n}\n\n/** A multi-line input that picks up its id and descriptions from the surrounding `Field`. */\nexport function Textarea({ className, id, ...props }: React.ComponentProps<\"textarea\">) {\n return <textarea {...useField(id)} className={cn(control, \"min-h-24 py-2\", className)} {...props} />;\n}\n\n// A native select, styled. For short option lists on a touch screen it beats a custom listbox:\n// the platform picker, typeahead and form autofill all work with no code.\n/** The platform select, styled. The default for short lists, especially on touch screens. */\nexport function NativeSelect({ className, id, ...props }: React.ComponentProps<\"select\">) {\n return <select {...useField(id)} className={cn(control, \"h-(--control-h) pr-8\", className)} {...props} />;\n}\n\n// Radio choices: React Aria's RadioGroup (a group named by its label, arrow-key movement, one tab\n// stop), and each row wraps its control so the whole row is one hit target. The dot is drawn from\n// tokens, not the platform's accent-color radio.\nexport type Choice = { value: string; label: string; detail?: string };\n\n/** Radio choices in a fieldset with a legend; each whole row is the hit target. For 2 to 5 options that each need a sentence. */\nexport function ChoiceGroup({\n legend,\n name,\n choices,\n value,\n onChange,\n error,\n}: {\n legend: string;\n name: string;\n choices: Choice[];\n value: string;\n onChange: (value: string) => void;\n error?: string;\n}) {\n const errorId = React.useId();\n return (\n <RadioGroup name={name} value={value} onChange={onChange} aria-describedby={error ? errorId : undefined} className=\"grid gap-2\">\n <Label className=\"mb-1.5 type-label text-foreground\">{legend}</Label>\n {choices.map((c) => (\n <Radio key={c.value} value={c.value} className=\"group flex min-h-(--control-h-sm) cursor-pointer items-start gap-3 py-1\">\n <span\n aria-hidden\n className=\"mt-1 grid size-4 shrink-0 place-items-center rounded-pill border border-input bg-background transition-state group-data-[selected]:border-primary group-data-[focus-visible]:outline-2 group-data-[focus-visible]:outline-offset-2 group-data-[focus-visible]:outline-ring\"\n >\n <span className=\"size-2 rounded-pill bg-primary opacity-0 group-data-[selected]:opacity-100\" />\n </span>\n <span className=\"grid\">\n <span className=\"type-body\">{c.label}</span>\n {c.detail && <span className=\"type-body-sm text-muted-foreground\">{c.detail}</span>}\n </span>\n </Radio>\n ))}\n {error && (\n <p id={errorId} className=\"flex items-start gap-1.5 type-body-sm text-danger\">\n <CircleAlert aria-hidden className=\"mt-0.5 size-4 shrink-0\" />\n {error}\n </p>\n )}\n </RadioGroup>\n );\n}\n","import * as React from \"react\";\nimport { Radio, RadioGroup } from \"react-aria-components\";\nimport { Tooltip } from \"./tooltip\";\nimport { Monitor, Moon, Sun } from \"lucide-react\";\nimport type { IconComponent } from \"../lib/icon\";\nimport { cn } from \"../lib/utils\";\nimport { ChoiceGroup } from \"./field\";\n\n// strata.css keys dark mode on a `.dark` ancestor (`@custom-variant dark (&:is(.dark *))`) and\n// gives `.dark` its `color-scheme`, but nothing in the library set the class, so every app wrote\n// the same matchMedia listener by hand (strata-listory did, in web/src/main.tsx). This is that\n// listener, once:\n// - Three choices, not two. \"system\" follows the operating system and keeps following it when it\n// changes at dusk; \"light\" and \"dark\" are a person's override. A toggle with only light and dark\n// loses the system setting the first time it is pressed.\n// - The choice persists in localStorage, read and written inside try/catch. Storage throws in\n// private windows, with blocked site data and in sandboxed frames; the theme then simply does\n// not persist, and the page still renders. A stored value that is not one of the three is\n// ignored.\n// - Another tab changing the choice changes this one too (the `storage` event).\n// - The first render uses the default preference, as a server render would, and the stored choice\n// is applied in a layout effect, so server-rendered markup hydrates cleanly and nothing paints\n// with the wrong scheme (found in review).\n// - The class is set in a layout effect, before paint. A page that must not flash light on first\n// load before React runs puts `colorSchemeScript()` in an inline script in its `<head>`.\n// - `ColorSchemeChoice` is the picker for a settings page: a `ChoiceGroup` of the three, with\n// \"Match this device\" first because it is the default and the one most people should keep. A\n// product that wants the choice elsewhere (a menu item, a header button) builds it from\n// `useColorScheme`. Changing theme is rare, so the picker has no motion and no icon flourish.\n// - `compact` is the same choice for an app with no settings page (a homepage, a single-page\n// tool), sized to sit in a header or footer: three segments with an icon each, named\n// \"Appearance\" (strata-react issue #25). They are still native radio buttons, so arrow keys move\n// the choice and a screen reader hears \"Match this device, radio button, 1 of 3, Appearance\".\n// Each segment is named by `aria-label` on its radio and shows the same words as a tooltip; the\n// icons are the familiar three (screen, sun, moon), and none of them is a toggle that loses the\n// system setting. The visible words are left out only because the icons are that well known.\n// - Storybook's decorator and `renderWithStrata({ colorScheme })` run through this provider, so\n// stories and tests see the same class, in the same place, as an app.\n\n/** What a person chose: follow the operating system, or a fixed light or dark theme. */\nexport type ColorSchemePreference = \"system\" | \"light\" | \"dark\";\n/** The scheme in effect after \"system\" is resolved. */\nexport type ColorScheme = \"light\" | \"dark\";\n\n/** The localStorage key `ThemeProvider` uses unless given another. */\nexport const COLOR_SCHEME_STORAGE_KEY = \"strata-color-scheme\";\n\nconst QUERY = \"(prefers-color-scheme: dark)\";\nconst PREFERENCES: readonly ColorSchemePreference[] = [\"system\", \"light\", \"dark\"];\n\nfunction isPreference(value: unknown): value is ColorSchemePreference {\n return typeof value === \"string\" && (PREFERENCES as readonly string[]).includes(value);\n}\n\nfunction readStored(key: string | null): ColorSchemePreference | null {\n if (key === null) return null;\n try {\n const value = window.localStorage.getItem(key);\n return isPreference(value) ? value : null;\n } catch {\n return null;\n }\n}\n\nfunction writeStored(key: string | null, value: ColorSchemePreference) {\n if (key === null) return;\n try {\n window.localStorage.setItem(key, value);\n } catch {\n // Storage unavailable (private window, blocked site data): the choice lasts this visit only.\n }\n}\n\nfunction media(): MediaQueryList | null {\n return typeof window !== \"undefined\" && typeof window.matchMedia === \"function\" ? window.matchMedia(QUERY) : null;\n}\n\nfunction subscribeSystem(onChange: () => void) {\n const list = media();\n if (!list) return () => undefined;\n list.addEventListener(\"change\", onChange);\n return () => list.removeEventListener(\"change\", onChange);\n}\n\nconst systemSnapshot = (): ColorScheme => (media()?.matches ? \"dark\" : \"light\");\nconst serverSnapshot = (): ColorScheme => \"light\";\n\n/** The operating system's colour scheme, kept current as it changes. Light where it cannot be read (the server, jsdom). */\nexport function useSystemColorScheme(): ColorScheme {\n return React.useSyncExternalStore(subscribeSystem, systemSnapshot, serverSnapshot);\n}\n\n/** What `useColorScheme` returns: the chosen preference, the scheme in effect, and a setter that persists the choice. */\nexport type ColorSchemeState = {\n preference: ColorSchemePreference;\n scheme: ColorScheme;\n setPreference: (preference: ColorSchemePreference) => void;\n};\n\nconst Context = React.createContext<ColorSchemeState | null>(null);\n\n/** Sets the `.dark` class strata.css keys on, from a system, light or dark preference that persists in localStorage when it can. */\nexport function ThemeProvider({\n children,\n defaultPreference = \"system\",\n storageKey = COLOR_SCHEME_STORAGE_KEY,\n target,\n}: {\n children: React.ReactNode;\n /** The preference before a person has chosen one. */\n defaultPreference?: ColorSchemePreference;\n /** Where the choice is kept in localStorage; `null` keeps it for this visit only. */\n storageKey?: string | null;\n /**\n * The element that gets the `.dark` class; the document's root element when left out. A nested\n * target can turn a light page's panel dark, not the reverse: strata.css keys dark on any\n * `.dark` ancestor. Pass the element itself (keep it in state with a callback ref, since a\n * wrapping element's ref is not attached yet when this provider's effect first runs); `null`\n * means it has not mounted yet, and nothing is set until it has.\n */\n target?: HTMLElement | null;\n}) {\n // The first render uses the default, as the server does, so a server-rendered tree hydrates\n // without a mismatch; the stored choice is read in a layout effect, which re-renders before the\n // browser paints, so a client-only app still never shows the default first.\n const [preference, setState] = React.useState<ColorSchemePreference>(defaultPreference);\n React.useLayoutEffect(() => {\n const stored = readStored(storageKey);\n if (stored) setState(stored);\n }, [storageKey]);\n const system = useSystemColorScheme();\n const scheme: ColorScheme = preference === \"system\" ? system : preference;\n\n const setPreference = React.useCallback(\n (next: ColorSchemePreference) => {\n setState(next);\n writeStored(storageKey, next);\n },\n [storageKey],\n );\n\n // Another tab changed the choice. A cleared key (`newValue` null) falls back to the default.\n React.useEffect(() => {\n if (storageKey === null) return;\n const onStorage = (event: StorageEvent) => {\n if (event.key !== storageKey && event.key !== null) return;\n const value = event.key === null ? null : event.newValue;\n setState(isPreference(value) ? value : defaultPreference);\n };\n window.addEventListener(\"storage\", onStorage);\n return () => window.removeEventListener(\"storage\", onStorage);\n }, [storageKey, defaultPreference]);\n\n React.useLayoutEffect(() => {\n const element = target === undefined ? document.documentElement : target;\n if (!element) return;\n element.classList.toggle(\"dark\", scheme === \"dark\");\n return () => element.classList.remove(\"dark\");\n }, [scheme, target]);\n\n const value = React.useMemo(() => ({ preference, scheme, setPreference }), [preference, scheme, setPreference]);\n return <Context.Provider value={value}>{children}</Context.Provider>;\n}\n\n/** The person's colour-scheme preference, the scheme in effect, and a setter that persists it. Must be inside `ThemeProvider`. */\nexport function useColorScheme(): ColorSchemeState {\n const value = React.useContext(Context);\n if (!value) throw new Error(\"useColorScheme must be used inside a ThemeProvider.\");\n return value;\n}\n\n/**\n * The body of an inline `<script>` for the page's `<head>` that sets `.dark` before the first\n * paint, from the stored choice or the operating system, so a dark page does not flash light while\n * the bundle loads. Pass the same key and default as the `ThemeProvider`.\n */\nexport function colorSchemeScript(\n storageKey: string = COLOR_SCHEME_STORAGE_KEY,\n defaultPreference: ColorSchemePreference = \"system\",\n): string {\n const key = JSON.stringify(storageKey);\n const fallback = JSON.stringify(defaultPreference);\n return (\n `(function(){var p=${fallback};try{var s=localStorage.getItem(${key});` +\n `if(s===\"system\"||s===\"light\"||s===\"dark\")p=s}catch(e){}` +\n `var d=p===\"dark\"||(p===\"system\"&&window.matchMedia&&matchMedia(${JSON.stringify(QUERY)}).matches);` +\n `document.documentElement.classList.toggle(\"dark\",!!d)})()`\n );\n}\n\n/** The words `ColorSchemeChoice` shows for each preference. */\nexport type ColorSchemeLabels = Record<ColorSchemePreference, { label: string; detail?: string }>;\n\nconst defaultLabels: ColorSchemeLabels = {\n system: { label: \"Match this device\", detail: \"Light or dark as your system setting changes\" },\n light: { label: \"Light\" },\n dark: { label: \"Dark\" },\n};\n\nconst icons: Record<ColorSchemePreference, IconComponent> = { system: Monitor, light: Sun, dark: Moon };\n\n/** The three colour-scheme preferences as radio buttons, bound to the nearest `ThemeProvider`. A list for a settings page, or `compact` icon segments named \"Appearance\" for a header. */\nexport function ColorSchemeChoice({\n legend,\n labels = defaultLabels,\n compact = false,\n className,\n}: {\n /** The group's name, as the page words it. Defaults to \"Theme\", or \"Appearance\" when `compact`. */\n legend?: string;\n /** Overrides the words for each choice, in the product's voice. */\n labels?: Partial<ColorSchemeLabels>;\n /** Three icon segments for a header or footer, for an app with no settings page. */\n compact?: boolean;\n /** Layout at the call site (compact only). */\n className?: string;\n}) {\n const { preference, setPreference } = useColorScheme();\n const name = React.useId();\n const words = { ...defaultLabels, ...labels };\n if (compact) {\n return (\n <RadioGroup\n aria-label={legend ?? \"Appearance\"}\n orientation=\"horizontal\"\n name={name}\n value={preference}\n onChange={(value) => {\n if (isPreference(value)) setPreference(value);\n }}\n className={cn(\"inline-flex gap-0.5 rounded-surface border border-border bg-background p-0.5\", className)}\n >\n {PREFERENCES.map((value) => {\n const Icon = icons[value];\n return (\n <Tooltip key={value} label={words[value].label}>\n <Radio\n value={value}\n aria-label={words[value].label}\n className={cn(\n // Outer 6px less 2px padding: the segments are 4px, as optical nesting asks.\n \"grid size-(--control-h-sm) cursor-pointer place-items-center rounded-control text-muted-foreground transition-state\",\n \"data-[hovered]:text-foreground data-[selected]:bg-muted data-[selected]:text-foreground\",\n \"data-[focus-visible]:outline-2 data-[focus-visible]:outline-offset-2 data-[focus-visible]:outline-ring\",\n )}\n >\n <Icon aria-hidden className=\"size-4\" />\n </Radio>\n </Tooltip>\n );\n })}\n </RadioGroup>\n );\n }\n return (\n <ChoiceGroup\n legend={legend ?? \"Theme\"}\n name={name}\n value={preference}\n onChange={(value) => {\n if (isPreference(value)) setPreference(value);\n }}\n choices={PREFERENCES.map((value) => ({ value, ...words[value] }))}\n />\n );\n}\n","import * as React from \"react\";\nimport {\n QueryClient,\n QueryClientProvider,\n useQuery,\n type QueryKey,\n type UseQueryOptions,\n type UseQueryResult,\n} from \"@tanstack/react-query\";\nimport type { Load, Stale } from \"../components/data-view\";\nimport { HttpError, describeHttpError, readErrorBody, type DescribeError, type ErrorBody } from \"../lib/errors\";\n\nexport { HttpError, describeHttpError, readErrorBody, type DescribeError, type ErrorBody };\n\n// Data loading, the Strata way: TanStack Query fetches and caches, and every view of the result\n// goes through DataView, which takes a Load<T>. `toLoad` is the one bridge between them, so a\n// screen never re-derives loading/error/ready from a query's flags and never forgets one.\n//\n// Opinions in createQueryClient: one retry (a second failure is real and the person should see\n// it with a \"Try again\"), 30 s stale time (dashboards are read many times a minute but change\n// over minutes), and no refetch on window focus (a table that reorders itself while someone reads\n// it is worse than one that is 30 s old). Override per query when the data says otherwise.\n\n/** A QueryClient with Strata's defaults: one retry, 30 s stale time, no refetch on window focus. */\nexport function createQueryClient(overrides?: ConstructorParameters<typeof QueryClient>[0]) {\n return new QueryClient({\n ...overrides,\n defaultOptions: {\n ...overrides?.defaultOptions,\n queries: { retry: 1, staleTime: 30_000, refetchOnWindowFocus: false, ...overrides?.defaultOptions?.queries },\n },\n });\n}\n\n/** Provides a query client (Strata's defaults unless one is passed) to the app. */\nexport function StrataQueryProvider({ client, children }: { client?: QueryClient; children: React.ReactNode }) {\n const [fallback] = React.useState(() => client ?? createQueryClient());\n return <QueryClientProvider client={client ?? fallback}>{children}</QueryClientProvider>;\n}\n\n/**\n * Turns a TanStack query result into the `Load<T>` that `DataView` takes; errors are described for a person by `describe`.\n * A refetch that fails after data arrived stays `ready`, with `stale` saying why and when the data was read.\n */\nexport function toLoad<T>(query: UseQueryResult<T>, describe: DescribeError = describeHttpError): Load<T> {\n if (query.status === \"success\") return { status: \"ready\", data: query.data };\n // TanStack keeps the last good data when a refetch fails and sets status \"error\" (isRefetchError).\n // That is old data, not no data: keep it on screen and say how old it is.\n if (query.status === \"error\" && query.data !== undefined) return { status: \"ready\", data: query.data, stale: staleOf(query, describe) };\n if (query.status === \"error\") return { status: \"error\", message: describe(query.error), retry: () => void query.refetch() };\n return { status: \"loading\" };\n}\n\n/** The `Stale` of a query whose refetch failed after a good read. Shared by `toLoad` and `useInfiniteLoad`. */\nexport function staleOf(\n query: { error: unknown; dataUpdatedAt: number; isFetching: boolean; refetch: () => unknown },\n describe: DescribeError = describeHttpError,\n): Stale {\n return { message: describe(query.error), readAt: new Date(query.dataUpdatedAt), retry: () => void query.refetch(), retrying: query.isFetching };\n}\n\n/** `useQuery`, returned as a `Load<T>` for `DataView`. */\nexport function useLoad<T, K extends QueryKey = QueryKey>(\n options: UseQueryOptions<T, Error, T, K> & { describeError?: DescribeError },\n): Load<T> {\n const { describeError, ...rest } = options;\n return toLoad(useQuery(rest), describeError);\n}\n\n/** Options for `fetchJson` beyond `fetch`'s own. */\nexport type FetchJsonOptions = {\n /** Finds the server's reason and per-field messages in an error body. Default `readErrorBody` (FastAPI's `detail`, `message`, `error`). */\n readError?: (body: unknown) => ErrorBody;\n};\n\n/**\n * fetch() that throws an HttpError on a non-2xx response and parses JSON: the queryFn default, and the usual commit for a write.\n * A 204 or empty body resolves to undefined. An error response's body is read onto the HttpError (`body`, `reason`, `fieldErrors`).\n */\nexport async function fetchJson<T>(input: string | URL, init?: RequestInit, { readError = readErrorBody }: FetchJsonOptions = {}): Promise<T> {\n // Headers, tuple arrays and plain objects are all valid HeadersInit; normalise before adding the\n // default so a caller's Authorization (or their own Accept) is never dropped.\n const headers = new Headers(init?.headers);\n if (!headers.has(\"Accept\")) headers.set(\"Accept\", \"application/json\");\n const res = await fetch(input, { ...init, headers });\n if (!res.ok) {\n // The body is read as text and parsed only when it parses: a proxy's HTML 502 page or an empty\n // body must still throw the HttpError, never a JSON SyntaxError in its place.\n const raw = await res.text().catch(() => \"\");\n let body: unknown = raw || undefined;\n try {\n if (raw) body = JSON.parse(raw);\n } catch {\n // Not JSON: keep the text.\n }\n throw new HttpError(res.status, res.statusText, String(input), body, readError(body));\n }\n // Writes (DELETE, a PUT that returns nothing) answer 204 or an empty body; that is success, not a\n // JSON parse error.\n const text = res.status === 204 ? \"\" : await res.text();\n return (text ? JSON.parse(text) : undefined) as T;\n}\n\nexport { useInfiniteLoad, type InfiniteLoad, type InfiniteLoadOptions, type More } from \"./infinite\";\nexport { useJob, type Job, type JobOptions } from \"./job\";\n"],"mappings":";;;;;;;;AAMA,IAAa,YAAY;CAAC;CAAW;CAAS;CAAW;CAAQ;CAAW;CAAS;CAAU;AAAS;AAMxG,IAAM,UAAU,oBAAoB,EAClC,QAAQ;CACN,OAAO,EAAE,QAAQ,CAAC,GAAG;EAJJ;EAAW;EAAW;EAAW;CAI7B,CAAW,EAAE;CAClC,aAAa,EACX,aAAa,CAAC,EAAE,MAAM,CAAC,GAAG,SAAS,EAAE,CAAC,EACxC;AACF,EACF,CAAC;;AAGD,SAAgB,GAAG,GAAG,QAAsB;CAC1C,OAAO,QAAQ,KAAK,MAAM,CAAC;AAC7B;;;ACQA,SAAgBA,UAAQ,EAAE,OAAO,MAAM,UAAU,OAAO,OAAO,QAAQ,KAAK,MAAM,aAA2B;CAC3G,OACE,qBAAC,gBAAD;EAAuB;EAAO,YAAY;EAAG,QAAQ;EAArD,UAAA,CACG,UACD,qBAACC,SAAD;GACE,WAAW;GACX,QAAQ;GACR,WAAW,GAAG,yGAAyG,SAAS;GAHlI,UAAA,CAKG,OACA,QAAQ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AO,KAAA;EAC3B,IAAI;GACF,IAAI,KAAK,OAAO,KAAK,MAAM,GAAG;EAChC,QAAQ,CAER;EACA,MAAM,IAAI,UAAU,IAAI,QAAQ,IAAI,YAAY,OAAO,KAAK,GAAG,MAAM,UAAU,IAAI,CAAC;CACtF;CAGA,MAAM,OAAO,IAAI,WAAW,MAAM,KAAK,MAAM,IAAI,KAAK;CACtD,OAAQ,OAAO,KAAK,MAAM,IAAI,IAAI,KAAA;AACpC"}
package/dist/testing.js CHANGED
@@ -1,4 +1,4 @@
1
- import { l as ThemeProvider, n as createQueryClient, t as StrataQueryProvider } from "./query-BVh4zv7Y.js";
1
+ import { l as ThemeProvider, n as createQueryClient, t as StrataQueryProvider } from "./query-gC6I6Cen.js";
2
2
  import "react";
3
3
  import { jsx } from "react/jsx-runtime";
4
4
  import { MemoryRouter, RouterProvider, createMemoryRouter } from "react-router";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strata-react",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "React + Tailwind v4 components that ship structure, behaviour, states and a token contract, and no look: each product brings a theme generated from its own subject.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1 +0,0 @@
1
- {"version":3,"file":"query-BVh4zv7Y.js","names":["Tooltip","AriaTooltip","Input","Tooltip"],"sources":["../src/lib/utils.ts","../src/components/tooltip.tsx","../src/lib/errors.ts","../src/components/field.tsx","../src/components/theme.tsx","../src/query/index.tsx"],"sourcesContent":["import { clsx, type ClassValue } from \"clsx\";\nimport { extendTailwindMerge } from \"tailwind-merge\";\n\n// Teach tailwind-merge that `type-*` utilities are font sizes. Without this, cn() cannot tell\n// `type-label` from a colour and may drop one of two classes that both survive in CSS; with stock\n// shadcn the same bug drops `text-muted-foreground` next to a custom `text-*` size.\nexport const typeSteps = [\"caption\", \"label\", \"body-sm\", \"body\", \"heading\", \"title\", \"figure\", \"display\"] as const;\n\n// The radius roles too, so `rounded-pill` at a call site (a round avatar Thumbnail) replaces a\n// component's `rounded-control` instead of both surviving and CSS order picking one.\nconst radiusRoles = [\"control\", \"surface\", \"overlay\", \"pill\"] as const;\n\nconst twMerge = extendTailwindMerge({\n extend: {\n theme: { radius: [...radiusRoles] },\n classGroups: {\n \"font-size\": [{ type: [...typeSteps] }],\n },\n },\n});\n\n/** clsx + tailwind-merge, taught that `type-*` utilities are font sizes and `rounded-control`, `-surface`, `-overlay`, `-pill` are radii. */\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n","import * as React from \"react\";\nimport { Tooltip as AriaTooltip, TooltipTrigger } from \"react-aria-components\";\nimport { cn } from \"../lib/utils\";\n\n// A tooltip names or explains a control; it is never the only place information lives. React Aria\n// opens it on keyboard focus as well as hover (strata-vid's old hover-only tooltip hid it from\n// keyboard users), after a short delay so a pointer crossing a toolbar does not flash every tip,\n// and shares the delay between neighbouring tips. It holds only words: anything interactive is a\n// Popover. It is portalled to the body, so a parent's overflow cannot clip it, and sits on the\n// `layer-tip` layer above dialogs, since it can name a control inside one.\n//\n// `IconButton` uses it for its required `label`, so the name and the visible hint come from one\n// string and cannot drift.\n\n/** Props for `Tooltip`. */\nexport type TooltipProps = {\n /** The words: a control's name or one sentence about it. Not interactive. */\n label: React.ReactNode;\n /** A shortcut or other aside shown after the label, muted (\"Ctrl+Z\"). */\n hint?: React.ReactNode;\n /** The element that gets the tip. It must be a React Aria pressable or focusable (a Strata `Button` is). */\n children: React.ReactElement;\n /** Which side of the trigger it prefers; it flips when there is no room. Default `top`. */\n side?: \"top\" | \"right\" | \"bottom\" | \"left\";\n /** Milliseconds before it opens on hover. Focus opens it at once. Default 500. */\n delay?: number;\n /** A controlled open state, for a story or test that needs it shown. */\n open?: boolean;\n className?: string;\n};\n\n/** A hover-and-focus tooltip for a control, portalled above everything. Words only; not the only home of information. */\nexport function Tooltip({ label, hint, children, side = \"top\", delay = 500, open, className }: TooltipProps) {\n return (\n <TooltipTrigger delay={delay} closeDelay={0} isOpen={open}>\n {children}\n <AriaTooltip\n placement={side}\n offset={6}\n className={cn(\"layer-tip enter-overlay max-w-xs rounded-control bg-foreground px-2 py-1 type-caption text-background\", className)}\n >\n {label}\n {hint != null && <span className=\"ml-2 opacity-70\">{hint}</span>}\n </AriaTooltip>\n </TooltipTrigger>\n );\n}\n","// Errors, described for a person. Anything that fails in front of someone (a load in DataView, an\n// action in AsyncButton) says what happened in a sentence, in the product's words, not the\n// developer's: `HttpError`'s own message (\"409 Conflict from /api/bookings\") is for logs. Loads\n// and actions share HttpError's status sentences, so the same failure reads the same everywhere,\n// and differ only in what is true afterwards: a failed load changed nothing, while a failed action\n// may have reached the server, so its sentence does not promise that.\n//\n// A server's own reason beats the status text (strata-react issue #42, from python-app-template).\n// FastAPI and most JSON APIs say why a 4xx happened in the body (`{\"detail\": \"the data folder must\n// be an absolute path\"}`), and a client that drops it has to repeat every server rule to show the\n// person anything better than \"Bad Request\", which drifts and cannot cover rules only the server\n// can check. So `fetchJson` reads an error response's body, `HttpError` keeps it with the reason\n// and any per-field messages found in it, and the sentences below use the reason for a 4xx.\n// Per-field messages (FastAPI's 422 `detail: [{loc, msg}]`) are keyed by field name, so\n// `useAsyncAction`'s `fieldErrors` can put each under its `Field`, never in a toast. A 5xx body is\n// not shown: it is usually a stack trace or a proxy's HTML page, and is kept on `body` for logs.\n\n/** What `readErrorBody` finds in an error response: the server's sentence, and messages per field. */\nexport type ErrorBody = {\n /** Why the server refused, in its own words. */\n reason?: string;\n /** Messages for individual fields, keyed by field name (`\"name\"`, `\"address.city\"`). */\n fields?: Record<string, string>;\n};\n\n/** Thrown by `fetchJson` on a non-2xx response; carries the status, the response body and the server's reason for `describeHttpError` and `describeActionError`. */\nexport class HttpError extends Error {\n /** The server's sentence for why it refused, from the body (`detail`, `message`, `error`), if it gave one. */\n readonly reason?: string;\n /** Messages for individual fields from the body (FastAPI's 422 `detail: [{loc, msg}]`), keyed by field name. Empty when there are none. */\n readonly fieldErrors: Readonly<Record<string, string>>;\n\n constructor(\n readonly status: number,\n readonly statusText: string,\n readonly url: string,\n /** The response body: parsed JSON when it was JSON, else its text; undefined when empty. */\n readonly body?: unknown,\n found: ErrorBody = readErrorBody(body),\n ) {\n super(`${status} ${statusText} from ${url}`);\n this.name = \"HttpError\";\n this.reason = found.reason;\n this.fieldErrors = found.fields ?? {};\n }\n}\n\nconst text = (value: unknown) => (typeof value === \"string\" && value.trim() ? value.trim() : undefined);\n\n/** A field name from a FastAPI/pydantic `loc`: the path after where it came from (`[\"body\", \"address\", \"city\"]` is `\"address.city\"`). */\nfunction fieldName(loc: unknown) {\n if (!Array.isArray(loc)) return undefined;\n const path = loc.map(String);\n if ([\"body\", \"query\", \"path\", \"header\", \"cookie\", \"form\"].includes(path[0]) && path.length > 1) path.shift();\n return path.join(\".\") || undefined;\n}\n\n/**\n * The default reading of an error body, for the shapes most JSON APIs use: `{ detail: \"…\" }`\n * (FastAPI), `{ message: \"…\" }`, `{ error: \"…\" }` or `{ error: { message: \"…\" } }` for the reason,\n * and FastAPI's validation list `{ detail: [{ loc, msg }] }` for per-field messages. A short\n * plain-text body (not HTML) is taken as the reason too. Pass your own to `fetchJson` for other APIs.\n */\nexport function readErrorBody(body: unknown): ErrorBody {\n if (typeof body === \"string\") {\n const t = text(body);\n return t && t.length <= 300 && !t.startsWith(\"<\") ? { reason: t } : {};\n }\n if (!body || typeof body !== \"object\") return {};\n const b = body as Record<string, unknown>;\n if (Array.isArray(b.detail)) {\n const fields: Record<string, string> = {};\n for (const item of b.detail as unknown[]) {\n const entry = item as { loc?: unknown; msg?: unknown } | null;\n const name = fieldName(entry?.loc);\n const msg = text(entry?.msg);\n if (name && msg && !fields[name]) fields[name] = msg;\n }\n return { fields };\n }\n const nested = b.error && typeof b.error === \"object\" ? text((b.error as Record<string, unknown>).message) : undefined;\n return { reason: text(b.detail) ?? text(b.message) ?? text(b.error) ?? nested };\n}\n\n/** Writes an error for a person: what happened, in a sentence. A product passes its own words. */\nexport type DescribeError = (error: unknown) => string;\n\n/** A sentence ends once: \"…absolute path\" and \"…absolute path.\" both end in one full stop. */\nconst sentence = (s: string) => (/[.!?…]$/.test(s) ? s : `${s}.`);\n\nfunction refused(error: HttpError) {\n if (error.reason) return `The request was refused: ${sentence(error.reason)}`;\n if (Object.keys(error.fieldErrors).length) return \"The request was refused: check the fields marked.\";\n return `The request was refused (${error.status}): ${error.statusText || \"no reason given\"}.`;\n}\n\n/** The default `DescribeError` for loads: the HTTP status in a sentence (with the server's reason for a 4xx), else the error's message, else a plain fallback. */\nexport const describeHttpError: DescribeError = (error) =>\n error instanceof HttpError\n ? error.status >= 500\n ? `The server could not answer (${error.status}). Nothing was changed.`\n : refused(error)\n : error instanceof Error && error.message\n ? error.message\n : \"The data could not be loaded. Nothing was changed.\";\n\n/** The default for `useAsyncAction`: the HTTP status in a sentence (with the server's reason for a 4xx), else the thrown Error's message, else undefined (the retry label alone). */\nexport const describeActionError = (error: unknown): string | undefined =>\n error instanceof HttpError\n ? error.status >= 500\n ? `The server could not answer (${error.status}).`\n : refused(error)\n : error instanceof Error && error.message\n ? error.message\n : undefined;\n\n/** Messages for individual fields carried by what was thrown: an `HttpError`'s `fieldErrors`, else none. */\nexport function fieldErrorsOf(error: unknown): Readonly<Record<string, string>> {\n return error instanceof HttpError ? error.fieldErrors : {};\n}\n","import * as React from \"react\";\nimport { CircleAlert } from \"lucide-react\";\nimport { Label, Radio, RadioGroup } from \"react-aria-components\";\nimport { cn } from \"../lib/utils\";\n\n// Field owns the wiring a generated form usually forgets: the label's htmlFor, aria-describedby\n// pointing at the hint and the error, and aria-invalid. Controls read it from context, so a control\n// inside a Field cannot end up unlabelled or silently invalid.\n//\n// A one-field form (\"paste a link, Add\", a search box, \"invite by email\") puts its button on the\n// control's row, not beside the whole field (strata-react issue #46, from the Tubes Library\n// screen): in a plain flex row the button lines up with label, hint and error together and drifts\n// off the input whenever one shows. `action` is drawn on the control's row, both at --control-h,\n// with the hint and the error under both across the full width. It wraps under the control only\n// when the row cannot keep the control 14rem wide beside it: on a phone a short \"Add\" stays on the\n// row, as a search box's button does, and a long label or a narrow column wraps. The error and hint stay the input's description; the\n// button is not described by them. Field messages for a form come from `useAsyncAction`'s\n// `fieldErrors` (its `validate`, or the server's 422), so no `problem` state is kept by hand.\n\ntype FieldState = { id: string; describedBy?: string; invalid: boolean };\nconst FieldContext = React.createContext<FieldState | null>(null);\n\nfunction useField(id?: string) {\n const field = React.useContext(FieldContext);\n return {\n // Inside a Field the Field's id wins, so the label always points at the control. To choose the\n // id yourself, pass it to Field.\n id: field?.id ?? id,\n \"aria-describedby\": field?.describedBy,\n \"aria-invalid\": field?.invalid || undefined,\n };\n}\n\nexport type FieldProps = {\n label: string;\n /** The control's id, when the page needs a known one (an anchor, a test). Generated otherwise. */\n id?: string;\n /** What the person needs to know before typing, such as limits or units. */\n hint?: React.ReactNode;\n /** What went wrong and how to fix it, in one sentence. Shown under the control, never in a toast. */\n error?: string;\n /** A button on the control's row, for a one-field form (an `AsyncButton` \"Add\"). The hint and error run under both; on a narrow screen it wraps under the control. */\n action?: React.ReactNode;\n children: React.ReactNode;\n className?: string;\n};\n\n/** A labelled form field: wires the label, hint, error, `aria-describedby` and `aria-invalid` into the one control it wraps. */\nexport function Field({ label, id: idProp, hint, error, action, children, className }: FieldProps) {\n const generated = React.useId();\n const id = idProp ?? generated;\n const hintId = hint ? `${id}-hint` : undefined;\n const errorId = error ? `${id}-error` : undefined;\n const describedBy = [errorId, hintId].filter(Boolean).join(\" \") || undefined;\n\n return (\n <FieldContext.Provider value={{ id, describedBy, invalid: Boolean(error) }}>\n <div className={cn(\"grid min-w-0 content-start gap-1.5\", className)}>\n <label htmlFor={id} className=\"type-label text-foreground\">\n {label}\n </label>\n {action ? (\n <div className=\"flex flex-wrap items-start gap-2\">\n <div className=\"min-w-56 flex-1\">{children}</div>\n <div className=\"flex shrink-0 items-center\">{action}</div>\n </div>\n ) : (\n children\n )}\n {error && (\n <p id={errorId} className=\"flex items-start gap-1.5 type-body-sm text-danger\">\n <CircleAlert aria-hidden className=\"mt-0.5 size-4 shrink-0\" />\n {error}\n </p>\n )}\n {hint && (\n <p id={hintId} className=\"type-body-sm text-muted-foreground\">\n {hint}\n </p>\n )}\n </div>\n </FieldContext.Provider>\n );\n}\n\nconst control =\n \"w-full min-w-0 rounded-control border border-input bg-background px-3 type-body text-foreground transition-state placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:bg-muted disabled:opacity-70 aria-invalid:border-danger\";\n\n/** A text input that picks up its id and descriptions from the surrounding `Field`. */\nexport function Input({ className, id, ...props }: React.ComponentProps<\"input\">) {\n return <input {...useField(id)} className={cn(control, \"h-(--control-h)\", className)} {...props} />;\n}\n\n/** A multi-line input that picks up its id and descriptions from the surrounding `Field`. */\nexport function Textarea({ className, id, ...props }: React.ComponentProps<\"textarea\">) {\n return <textarea {...useField(id)} className={cn(control, \"min-h-24 py-2\", className)} {...props} />;\n}\n\n// A native select, styled. For short option lists on a touch screen it beats a custom listbox:\n// the platform picker, typeahead and form autofill all work with no code.\n/** The platform select, styled. The default for short lists, especially on touch screens. */\nexport function NativeSelect({ className, id, ...props }: React.ComponentProps<\"select\">) {\n return <select {...useField(id)} className={cn(control, \"h-(--control-h) pr-8\", className)} {...props} />;\n}\n\n// Radio choices: React Aria's RadioGroup (a group named by its label, arrow-key movement, one tab\n// stop), and each row wraps its control so the whole row is one hit target. The dot is drawn from\n// tokens, not the platform's accent-color radio.\nexport type Choice = { value: string; label: string; detail?: string };\n\n/** Radio choices in a fieldset with a legend; each whole row is the hit target. For 2 to 5 options that each need a sentence. */\nexport function ChoiceGroup({\n legend,\n name,\n choices,\n value,\n onChange,\n error,\n}: {\n legend: string;\n name: string;\n choices: Choice[];\n value: string;\n onChange: (value: string) => void;\n error?: string;\n}) {\n const errorId = React.useId();\n return (\n <RadioGroup name={name} value={value} onChange={onChange} aria-describedby={error ? errorId : undefined} className=\"grid gap-2\">\n <Label className=\"mb-1.5 type-label text-foreground\">{legend}</Label>\n {choices.map((c) => (\n <Radio key={c.value} value={c.value} className=\"group flex min-h-(--control-h-sm) cursor-pointer items-start gap-3 py-1\">\n <span\n aria-hidden\n className=\"mt-1 grid size-4 shrink-0 place-items-center rounded-pill border border-input bg-background transition-state group-data-[selected]:border-primary group-data-[focus-visible]:outline-2 group-data-[focus-visible]:outline-offset-2 group-data-[focus-visible]:outline-ring\"\n >\n <span className=\"size-2 rounded-pill bg-primary opacity-0 group-data-[selected]:opacity-100\" />\n </span>\n <span className=\"grid\">\n <span className=\"type-body\">{c.label}</span>\n {c.detail && <span className=\"type-body-sm text-muted-foreground\">{c.detail}</span>}\n </span>\n </Radio>\n ))}\n {error && (\n <p id={errorId} className=\"flex items-start gap-1.5 type-body-sm text-danger\">\n <CircleAlert aria-hidden className=\"mt-0.5 size-4 shrink-0\" />\n {error}\n </p>\n )}\n </RadioGroup>\n );\n}\n","import * as React from \"react\";\nimport { Radio, RadioGroup } from \"react-aria-components\";\nimport { Tooltip } from \"./tooltip\";\nimport { Monitor, Moon, Sun } from \"lucide-react\";\nimport type { IconComponent } from \"../lib/icon\";\nimport { cn } from \"../lib/utils\";\nimport { ChoiceGroup } from \"./field\";\n\n// strata.css keys dark mode on a `.dark` ancestor (`@custom-variant dark (&:is(.dark *))`) and\n// gives `.dark` its `color-scheme`, but nothing in the library set the class, so every app wrote\n// the same matchMedia listener by hand (strata-listory did, in web/src/main.tsx). This is that\n// listener, once:\n// - Three choices, not two. \"system\" follows the operating system and keeps following it when it\n// changes at dusk; \"light\" and \"dark\" are a person's override. A toggle with only light and dark\n// loses the system setting the first time it is pressed.\n// - The choice persists in localStorage, read and written inside try/catch. Storage throws in\n// private windows, with blocked site data and in sandboxed frames; the theme then simply does\n// not persist, and the page still renders. A stored value that is not one of the three is\n// ignored.\n// - Another tab changing the choice changes this one too (the `storage` event).\n// - The first render uses the default preference, as a server render would, and the stored choice\n// is applied in a layout effect, so server-rendered markup hydrates cleanly and nothing paints\n// with the wrong scheme (found in review).\n// - The class is set in a layout effect, before paint. A page that must not flash light on first\n// load before React runs puts `colorSchemeScript()` in an inline script in its `<head>`.\n// - `ColorSchemeChoice` is the picker for a settings page: a `ChoiceGroup` of the three, with\n// \"Match this device\" first because it is the default and the one most people should keep. A\n// product that wants the choice elsewhere (a menu item, a header button) builds it from\n// `useColorScheme`. Changing theme is rare, so the picker has no motion and no icon flourish.\n// - `compact` is the same choice for an app with no settings page (a homepage, a single-page\n// tool), sized to sit in a header or footer: three segments with an icon each, named\n// \"Appearance\" (strata-react issue #25). They are still native radio buttons, so arrow keys move\n// the choice and a screen reader hears \"Match this device, radio button, 1 of 3, Appearance\".\n// Each segment is named by `aria-label` on its radio and shows the same words as a tooltip; the\n// icons are the familiar three (screen, sun, moon), and none of them is a toggle that loses the\n// system setting. The visible words are left out only because the icons are that well known.\n// - Storybook's decorator and `renderWithStrata({ colorScheme })` run through this provider, so\n// stories and tests see the same class, in the same place, as an app.\n\n/** What a person chose: follow the operating system, or a fixed light or dark theme. */\nexport type ColorSchemePreference = \"system\" | \"light\" | \"dark\";\n/** The scheme in effect after \"system\" is resolved. */\nexport type ColorScheme = \"light\" | \"dark\";\n\n/** The localStorage key `ThemeProvider` uses unless given another. */\nexport const COLOR_SCHEME_STORAGE_KEY = \"strata-color-scheme\";\n\nconst QUERY = \"(prefers-color-scheme: dark)\";\nconst PREFERENCES: readonly ColorSchemePreference[] = [\"system\", \"light\", \"dark\"];\n\nfunction isPreference(value: unknown): value is ColorSchemePreference {\n return typeof value === \"string\" && (PREFERENCES as readonly string[]).includes(value);\n}\n\nfunction readStored(key: string | null): ColorSchemePreference | null {\n if (key === null) return null;\n try {\n const value = window.localStorage.getItem(key);\n return isPreference(value) ? value : null;\n } catch {\n return null;\n }\n}\n\nfunction writeStored(key: string | null, value: ColorSchemePreference) {\n if (key === null) return;\n try {\n window.localStorage.setItem(key, value);\n } catch {\n // Storage unavailable (private window, blocked site data): the choice lasts this visit only.\n }\n}\n\nfunction media(): MediaQueryList | null {\n return typeof window !== \"undefined\" && typeof window.matchMedia === \"function\" ? window.matchMedia(QUERY) : null;\n}\n\nfunction subscribeSystem(onChange: () => void) {\n const list = media();\n if (!list) return () => undefined;\n list.addEventListener(\"change\", onChange);\n return () => list.removeEventListener(\"change\", onChange);\n}\n\nconst systemSnapshot = (): ColorScheme => (media()?.matches ? \"dark\" : \"light\");\nconst serverSnapshot = (): ColorScheme => \"light\";\n\n/** The operating system's colour scheme, kept current as it changes. Light where it cannot be read (the server, jsdom). */\nexport function useSystemColorScheme(): ColorScheme {\n return React.useSyncExternalStore(subscribeSystem, systemSnapshot, serverSnapshot);\n}\n\n/** What `useColorScheme` returns: the chosen preference, the scheme in effect, and a setter that persists the choice. */\nexport type ColorSchemeState = {\n preference: ColorSchemePreference;\n scheme: ColorScheme;\n setPreference: (preference: ColorSchemePreference) => void;\n};\n\nconst Context = React.createContext<ColorSchemeState | null>(null);\n\n/** Sets the `.dark` class strata.css keys on, from a system, light or dark preference that persists in localStorage when it can. */\nexport function ThemeProvider({\n children,\n defaultPreference = \"system\",\n storageKey = COLOR_SCHEME_STORAGE_KEY,\n target,\n}: {\n children: React.ReactNode;\n /** The preference before a person has chosen one. */\n defaultPreference?: ColorSchemePreference;\n /** Where the choice is kept in localStorage; `null` keeps it for this visit only. */\n storageKey?: string | null;\n /**\n * The element that gets the `.dark` class; the document's root element when left out. A nested\n * target can turn a light page's panel dark, not the reverse: strata.css keys dark on any\n * `.dark` ancestor. Pass the element itself (keep it in state with a callback ref, since a\n * wrapping element's ref is not attached yet when this provider's effect first runs); `null`\n * means it has not mounted yet, and nothing is set until it has.\n */\n target?: HTMLElement | null;\n}) {\n // The first render uses the default, as the server does, so a server-rendered tree hydrates\n // without a mismatch; the stored choice is read in a layout effect, which re-renders before the\n // browser paints, so a client-only app still never shows the default first.\n const [preference, setState] = React.useState<ColorSchemePreference>(defaultPreference);\n React.useLayoutEffect(() => {\n const stored = readStored(storageKey);\n if (stored) setState(stored);\n }, [storageKey]);\n const system = useSystemColorScheme();\n const scheme: ColorScheme = preference === \"system\" ? system : preference;\n\n const setPreference = React.useCallback(\n (next: ColorSchemePreference) => {\n setState(next);\n writeStored(storageKey, next);\n },\n [storageKey],\n );\n\n // Another tab changed the choice. A cleared key (`newValue` null) falls back to the default.\n React.useEffect(() => {\n if (storageKey === null) return;\n const onStorage = (event: StorageEvent) => {\n if (event.key !== storageKey && event.key !== null) return;\n const value = event.key === null ? null : event.newValue;\n setState(isPreference(value) ? value : defaultPreference);\n };\n window.addEventListener(\"storage\", onStorage);\n return () => window.removeEventListener(\"storage\", onStorage);\n }, [storageKey, defaultPreference]);\n\n React.useLayoutEffect(() => {\n const element = target === undefined ? document.documentElement : target;\n if (!element) return;\n element.classList.toggle(\"dark\", scheme === \"dark\");\n return () => element.classList.remove(\"dark\");\n }, [scheme, target]);\n\n const value = React.useMemo(() => ({ preference, scheme, setPreference }), [preference, scheme, setPreference]);\n return <Context.Provider value={value}>{children}</Context.Provider>;\n}\n\n/** The person's colour-scheme preference, the scheme in effect, and a setter that persists it. Must be inside `ThemeProvider`. */\nexport function useColorScheme(): ColorSchemeState {\n const value = React.useContext(Context);\n if (!value) throw new Error(\"useColorScheme must be used inside a ThemeProvider.\");\n return value;\n}\n\n/**\n * The body of an inline `<script>` for the page's `<head>` that sets `.dark` before the first\n * paint, from the stored choice or the operating system, so a dark page does not flash light while\n * the bundle loads. Pass the same key and default as the `ThemeProvider`.\n */\nexport function colorSchemeScript(\n storageKey: string = COLOR_SCHEME_STORAGE_KEY,\n defaultPreference: ColorSchemePreference = \"system\",\n): string {\n const key = JSON.stringify(storageKey);\n const fallback = JSON.stringify(defaultPreference);\n return (\n `(function(){var p=${fallback};try{var s=localStorage.getItem(${key});` +\n `if(s===\"system\"||s===\"light\"||s===\"dark\")p=s}catch(e){}` +\n `var d=p===\"dark\"||(p===\"system\"&&window.matchMedia&&matchMedia(${JSON.stringify(QUERY)}).matches);` +\n `document.documentElement.classList.toggle(\"dark\",!!d)})()`\n );\n}\n\n/** The words `ColorSchemeChoice` shows for each preference. */\nexport type ColorSchemeLabels = Record<ColorSchemePreference, { label: string; detail?: string }>;\n\nconst defaultLabels: ColorSchemeLabels = {\n system: { label: \"Match this device\", detail: \"Light or dark as your system setting changes\" },\n light: { label: \"Light\" },\n dark: { label: \"Dark\" },\n};\n\nconst icons: Record<ColorSchemePreference, IconComponent> = { system: Monitor, light: Sun, dark: Moon };\n\n/** The three colour-scheme preferences as radio buttons, bound to the nearest `ThemeProvider`. A list for a settings page, or `compact` icon segments named \"Appearance\" for a header. */\nexport function ColorSchemeChoice({\n legend,\n labels = defaultLabels,\n compact = false,\n className,\n}: {\n /** The group's name, as the page words it. Defaults to \"Theme\", or \"Appearance\" when `compact`. */\n legend?: string;\n /** Overrides the words for each choice, in the product's voice. */\n labels?: Partial<ColorSchemeLabels>;\n /** Three icon segments for a header or footer, for an app with no settings page. */\n compact?: boolean;\n /** Layout at the call site (compact only). */\n className?: string;\n}) {\n const { preference, setPreference } = useColorScheme();\n const name = React.useId();\n const words = { ...defaultLabels, ...labels };\n if (compact) {\n return (\n <RadioGroup\n aria-label={legend ?? \"Appearance\"}\n orientation=\"horizontal\"\n name={name}\n value={preference}\n onChange={(value) => {\n if (isPreference(value)) setPreference(value);\n }}\n className={cn(\"inline-flex gap-0.5 rounded-surface border border-border bg-background p-0.5\", className)}\n >\n {PREFERENCES.map((value) => {\n const Icon = icons[value];\n return (\n <Tooltip key={value} label={words[value].label}>\n <Radio\n value={value}\n aria-label={words[value].label}\n className={cn(\n // Outer 6px less 2px padding: the segments are 4px, as optical nesting asks.\n \"grid size-(--control-h-sm) cursor-pointer place-items-center rounded-control text-muted-foreground transition-state\",\n \"data-[hovered]:text-foreground data-[selected]:bg-muted data-[selected]:text-foreground\",\n \"data-[focus-visible]:outline-2 data-[focus-visible]:outline-offset-2 data-[focus-visible]:outline-ring\",\n )}\n >\n <Icon aria-hidden className=\"size-4\" />\n </Radio>\n </Tooltip>\n );\n })}\n </RadioGroup>\n );\n }\n return (\n <ChoiceGroup\n legend={legend ?? \"Theme\"}\n name={name}\n value={preference}\n onChange={(value) => {\n if (isPreference(value)) setPreference(value);\n }}\n choices={PREFERENCES.map((value) => ({ value, ...words[value] }))}\n />\n );\n}\n","import * as React from \"react\";\nimport {\n QueryClient,\n QueryClientProvider,\n useQuery,\n type QueryKey,\n type UseQueryOptions,\n type UseQueryResult,\n} from \"@tanstack/react-query\";\nimport type { Load, Stale } from \"../components/data-view\";\nimport { HttpError, describeHttpError, readErrorBody, type DescribeError, type ErrorBody } from \"../lib/errors\";\n\nexport { HttpError, describeHttpError, readErrorBody, type DescribeError, type ErrorBody };\n\n// Data loading, the Strata way: TanStack Query fetches and caches, and every view of the result\n// goes through DataView, which takes a Load<T>. `toLoad` is the one bridge between them, so a\n// screen never re-derives loading/error/ready from a query's flags and never forgets one.\n//\n// Opinions in createQueryClient: one retry (a second failure is real and the person should see\n// it with a \"Try again\"), 30 s stale time (dashboards are read many times a minute but change\n// over minutes), and no refetch on window focus (a table that reorders itself while someone reads\n// it is worse than one that is 30 s old). Override per query when the data says otherwise.\n\n/** A QueryClient with Strata's defaults: one retry, 30 s stale time, no refetch on window focus. */\nexport function createQueryClient(overrides?: ConstructorParameters<typeof QueryClient>[0]) {\n return new QueryClient({\n ...overrides,\n defaultOptions: {\n ...overrides?.defaultOptions,\n queries: { retry: 1, staleTime: 30_000, refetchOnWindowFocus: false, ...overrides?.defaultOptions?.queries },\n },\n });\n}\n\n/** Provides a query client (Strata's defaults unless one is passed) to the app. */\nexport function StrataQueryProvider({ client, children }: { client?: QueryClient; children: React.ReactNode }) {\n const [fallback] = React.useState(() => client ?? createQueryClient());\n return <QueryClientProvider client={client ?? fallback}>{children}</QueryClientProvider>;\n}\n\n/**\n * Turns a TanStack query result into the `Load<T>` that `DataView` takes; errors are described for a person by `describe`.\n * A refetch that fails after data arrived stays `ready`, with `stale` saying why and when the data was read.\n */\nexport function toLoad<T>(query: UseQueryResult<T>, describe: DescribeError = describeHttpError): Load<T> {\n if (query.status === \"success\") return { status: \"ready\", data: query.data };\n // TanStack keeps the last good data when a refetch fails and sets status \"error\" (isRefetchError).\n // That is old data, not no data: keep it on screen and say how old it is.\n if (query.status === \"error\" && query.data !== undefined) return { status: \"ready\", data: query.data, stale: staleOf(query, describe) };\n if (query.status === \"error\") return { status: \"error\", message: describe(query.error), retry: () => void query.refetch() };\n return { status: \"loading\" };\n}\n\n/** The `Stale` of a query whose refetch failed after a good read. Shared by `toLoad` and `useInfiniteLoad`. */\nexport function staleOf(\n query: { error: unknown; dataUpdatedAt: number; isFetching: boolean; refetch: () => unknown },\n describe: DescribeError = describeHttpError,\n): Stale {\n return { message: describe(query.error), readAt: new Date(query.dataUpdatedAt), retry: () => void query.refetch(), retrying: query.isFetching };\n}\n\n/** `useQuery`, returned as a `Load<T>` for `DataView`. */\nexport function useLoad<T, K extends QueryKey = QueryKey>(\n options: UseQueryOptions<T, Error, T, K> & { describeError?: DescribeError },\n): Load<T> {\n const { describeError, ...rest } = options;\n return toLoad(useQuery(rest), describeError);\n}\n\n/** Options for `fetchJson` beyond `fetch`'s own. */\nexport type FetchJsonOptions = {\n /** Finds the server's reason and per-field messages in an error body. Default `readErrorBody` (FastAPI's `detail`, `message`, `error`). */\n readError?: (body: unknown) => ErrorBody;\n};\n\n/**\n * fetch() that throws an HttpError on a non-2xx response and parses JSON: the queryFn default, and the usual commit for a write.\n * A 204 or empty body resolves to undefined. An error response's body is read onto the HttpError (`body`, `reason`, `fieldErrors`).\n */\nexport async function fetchJson<T>(input: string | URL, init?: RequestInit, { readError = readErrorBody }: FetchJsonOptions = {}): Promise<T> {\n // Headers, tuple arrays and plain objects are all valid HeadersInit; normalise before adding the\n // default so a caller's Authorization (or their own Accept) is never dropped.\n const headers = new Headers(init?.headers);\n if (!headers.has(\"Accept\")) headers.set(\"Accept\", \"application/json\");\n const res = await fetch(input, { ...init, headers });\n if (!res.ok) {\n // The body is read as text and parsed only when it parses: a proxy's HTML 502 page or an empty\n // body must still throw the HttpError, never a JSON SyntaxError in its place.\n const raw = await res.text().catch(() => \"\");\n let body: unknown = raw || undefined;\n try {\n if (raw) body = JSON.parse(raw);\n } catch {\n // Not JSON: keep the text.\n }\n throw new HttpError(res.status, res.statusText, String(input), body, readError(body));\n }\n // Writes (DELETE, a PUT that returns nothing) answer 204 or an empty body; that is success, not a\n // JSON parse error.\n const text = res.status === 204 ? \"\" : await res.text();\n return (text ? JSON.parse(text) : undefined) as T;\n}\n\nexport { useInfiniteLoad, type InfiniteLoad, type InfiniteLoadOptions, type More } from \"./infinite\";\nexport { useJob, type Job, type JobOptions } from \"./job\";\n"],"mappings":";;;;;;;;AAMA,IAAa,YAAY;CAAC;CAAW;CAAS;CAAW;CAAQ;CAAW;CAAS;CAAU;AAAS;AAMxG,IAAM,UAAU,oBAAoB,EAClC,QAAQ;CACN,OAAO,EAAE,QAAQ,CAAC,GAAG;EAJJ;EAAW;EAAW;EAAW;CAI7B,CAAW,EAAE;CAClC,aAAa,EACX,aAAa,CAAC,EAAE,MAAM,CAAC,GAAG,SAAS,EAAE,CAAC,EACxC;AACF,EACF,CAAC;;AAGD,SAAgB,GAAG,GAAG,QAAsB;CAC1C,OAAO,QAAQ,KAAK,MAAM,CAAC;AAC7B;;;ACQA,SAAgBA,UAAQ,EAAE,OAAO,MAAM,UAAU,OAAO,OAAO,QAAQ,KAAK,MAAM,aAA2B;CAC3G,OACE,qBAAC,gBAAD;EAAuB;EAAO,YAAY;EAAG,QAAQ;EAArD,UAAA,CACG,UACD,qBAACC,SAAD;GACE,WAAW;GACX,QAAQ;GACR,WAAW,GAAG,yGAAyG,SAAS;GAHlI,UAAA,CAKG,OACA,QAAQ,QAAQ,oBAAC,QAAD;IAAM,WAAU;IAAmB,UAAA;GAAW,CAAA,CACpD;EACC,CAAA,CAAA;;AAEpB;;;ACpBA,IAAa,YAAb,cAA+B,MAAM;CAOxB;CACA;CACA;CAEA;;CATX;;CAEA;CAEA,YACE,QACA,YACA,KAEA,MACA,QA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