strata-react 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/UPGRADING.md +60 -0
- package/dist/components/alert.d.ts +17 -0
- package/dist/components/job-status.d.ts +11 -2
- package/dist/components/toast.d.ts +33 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +224 -15
- package/dist/index.js.map +1 -1
- package/dist/lib/client-work.d.ts +24 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -46,6 +46,8 @@ The last three are optional peers: an app that never imports those entries never
|
|
|
46
46
|
dev dependency and builds the package, so it is slow and also needs Node 26.
|
|
47
47
|
Use it to try a fix before it is released, then move back to the npm version.
|
|
48
48
|
|
|
49
|
+
**Updating:** [`UPGRADING.md`](./UPGRADING.md) lists what an app has to change between versions (breaking and test-visible changes only); [`CHANGELOG.md`](./CHANGELOG.md) is the development log.
|
|
50
|
+
|
|
49
51
|
## Set up an app
|
|
50
52
|
|
|
51
53
|
```css
|
|
@@ -129,6 +131,7 @@ function KilnRoom() {
|
|
|
129
131
|
| Toolbar and toggles | `Toolbar`, `ToolbarSeparator`, `Toggle`, `ToggleGroup`, `Switch` | A toolbar is one tab stop with arrows, Home and End inside; needs a `label`. `Toggle` (`aria-pressed`) and `ToggleGroup` (one of 2 to 7, always one chosen) show chosen as an ink border on a tint, never the filled primary, so they do not break the one-filled-button rule; an icon-only toggle still needs its `label` (shown as a tooltip). `Switch` is only for a setting that applies at once, label and control one target |
|
|
130
132
|
| Commands | `Command`, `useCommands`, `Menu`, `ContextMenu`, `CommandMenu`, `CommandLegend`, `formatChord`, `matchesChord` | A command is declared once (label or label function, chords, `disabled` with a reason, `destructive`, `checked`) and drives the key handler, dropdown and menu-bar menus, the context menu, the searchable command menu (Mod+K) and the legend, so they cannot disagree. Chords are written once ("Mod+Shift+Z") and shown per platform (⇧⌘Z, Ctrl+Shift+Z); they never fire while typing or during IME composition, and a chord the browser keeps (Ctrl+S) needs `claim: true`. `useHotkeys` is unchanged for single keys |
|
|
131
133
|
| Overlays | `Dialog`, `DialogProps`, `AlertDialog`, `Popover`, `Tooltip` | React Aria underneath. A dialog always has a title and, via `actions`'s close render prop, a way out; `closable={false}` while work cannot stop; `placement="end"` is a sheet. `AlertDialog` is the only confirm: required verb on the confirm button, Cancel focused first, no outside dismiss, stays open with the reason when an async confirm fails. `Popover` needs a `label`. `Tooltip` opens on hover and focus and `IconButton` uses it. All portal onto the `layer-*` stacking utilities |
|
|
134
|
+
| Feedback | `Alert`, `toast`, `StrataToastRegion`, `useClientWork`, `JobStatus` | Three weights. A `toast` confirms finished work and goes by itself (5 s plus 40 ms a character, 8 s minimum with an action, paused under the pointer or focus, always dismissable); it has no danger tone, because an error a person must act on is an inline `Alert` with its recovery as `action` (`announce` makes it `role="alert"` only when it answers something the person just did). `StrataToastRegion` goes once at the app root. `useClientWork` runs browser work with progress, cancel (aborts its `signal`, ends `cancelled`, never `failed`) and a double-start guard; `JobStatus` shows it exactly as it shows a server job, with `onCancel`, `cancelled` and `onDismiss` |
|
|
132
135
|
| Feedback | `UndoBar`, `useUndoable`, `Done` | Undo before confirm; the hook owns which rows are out of view (`isRemoved`), a failed commit brings the row back with Try again in the same bar, and `flush()` commits before a dependent action; `Done` is the one celebration, and it must say what happens next |
|
|
133
136
|
| Helpers | `cn`, `format`, `createFormat`, `NBSP` | `cn` knows `type-*`; all numbers and dates through `Intl`; `format.integer(n)`, `.decimal(n)`, `.percent(n)` are callable and keep Intl's methods; `format.bytes(n, unit?)` writes sizes in decimal units (`byteUnit` shares one unit across figures); `format.date(at)` ("8 Nov 2026") and `format.dateTime(at)` ("8 Nov 2026, 06:05"), like `clock`, `day` and `shortDay`, take a Date, ISO string or epoch ms; `format.ago(at, now?)` ("3 weeks ago"), `format.compact(n)` ("1.2k", and `count(n, one, many, { compact: true })`), `format.runningTime(seconds)` ("1:02:09") and `format.share(n)` ("<1%" for a part that rounds to 0); every number and date formatter prints the placeholder (`format.missing`, an en dash) for `null` or `undefined`; `createFormat(locale, { timeZone, missing })` fixes the zone and the placeholder; units and counts join with a non-breaking space |
|
|
134
137
|
| Testing | `strata-react/testing`: `renderWithStrata`, `renderRoutes`, `createTestQueryClient`, `installLayoutShims`, `installFakeIntersectionObserver`, `filledButtons`, `expectOneFilledButton`, `asyncButtonPhase` | Router + query client around Testing Library's `render`; `renderRoutes(routes, { route, basename })` renders the app's own `RouteObject[]` in a memory data router, so layout routes, redirects, loaders and error elements run, and returns the `router` (where a redirect landed is `router.state.location`) and an act-wrapped `navigate`; a fixed box and ResizeObserver so measuring components render in jsdom; an IntersectionObserver the test fires with `scrollToEnd()` or `intersect(el)`; `filledButtons()` and `expectOneFilledButton()` check "one filled button per view" from `data-variant`, and `asyncButtonPhase(el)` reads an `AsyncButton`'s phase. Role names keep the non-breaking space from `format.count`, so match them with the same call or a `\s` regex |
|
package/UPGRADING.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# Upgrading strata-react
|
|
2
|
+
|
|
3
|
+
What an app has to change when it updates, newest first. Only things that break, change
|
|
4
|
+
behaviour an app or its tests can see, or need an action. New components and props are not
|
|
5
|
+
listed; the [API reference](https://jburnhams.github.io/strata-react/api/) has them, and the
|
|
6
|
+
full development log, with reasons, is [`CHANGELOG.md`](./CHANGELOG.md).
|
|
7
|
+
|
|
8
|
+
Releases are cut on every merge to `main` (`v0.1.x`), so a day can span several versions.
|
|
9
|
+
Sections are by date; `v0.1.17` was published 2026-11-09 and the Release page gives each tag's
|
|
10
|
+
time. While the version is 0.x, any release may break.
|
|
11
|
+
|
|
12
|
+
Every PR that changes what an app sees adds a line here (see `CLAUDE.md`, "Changelog").
|
|
13
|
+
|
|
14
|
+
## After v0.1.17 (2026-11-11 to 2026-11-12)
|
|
15
|
+
|
|
16
|
+
React Aria Components is now the primitives layer (`react-aria-components`, installed with the
|
|
17
|
+
package). `@radix-ui/react-slot` is gone.
|
|
18
|
+
|
|
19
|
+
- **`Button` has no `asChild`.** A button that navigates is a link: use a router `Link`.
|
|
20
|
+
Do not rely on `@radix-ui/react-slot` arriving through Strata.
|
|
21
|
+
- **`IconButton` shows `label` as a tooltip**, not a `title` attribute. New optional `hint`
|
|
22
|
+
for a shortcut. `Button` still takes `onClick` and `disabled`; `onPress` also works.
|
|
23
|
+
- **Tests that query roles:** `ChoiceGroup` and `ColorSchemeChoice` are `radiogroup`, not
|
|
24
|
+
`group`. A mixed `Checkbox` is the DOM `indeterminate` state, no longer `aria-checked="mixed"`.
|
|
25
|
+
- **Checkbox, radio and selection tables are drawn from tokens**, not native controls. Expect
|
|
26
|
+
visual baselines to change (selection tables 4px shorter, choice groups 8px taller).
|
|
27
|
+
- **Tooltips and other portalled overlays are now in `strata-visual` shots** (the clip walks
|
|
28
|
+
the other children of `<body>`). Rewrite baselines that included a tooltip trigger.
|
|
29
|
+
- **Visual baselines:** lucide-react 1.72 redrew icons (moon, sort arrows, shell and status
|
|
30
|
+
icons), and the reference Chromium moved to 158 (Playwright 1.65). Re-record, after looking.
|
|
31
|
+
- No app change: TypeScript 7 for the repo's own typecheck, TanStack Table 9 inside `DataTable`
|
|
32
|
+
(its column API is unchanged), new `layer-bar`/`layer-overlay`/`layer-tip` utilities (use them
|
|
33
|
+
instead of writing a z-index).
|
|
34
|
+
|
|
35
|
+
## v0.1.17 and the days before (2026-11-07 to 2026-11-09)
|
|
36
|
+
|
|
37
|
+
- **`useUndoable`** (2026-11-07): returns `{ pending, failed, isRemoved, schedule, undo, flush,
|
|
38
|
+
retry, dismiss }`. `PendingRemoval` requires a `failure` sentence. `UndoBar` takes
|
|
39
|
+
`undoable={...}` instead of `pending` and `onUndo`. Filter rows with `isRemoved(id)` and drop
|
|
40
|
+
any hand-kept hidden set; `commit` may return a promise, and a rejection restores the item.
|
|
41
|
+
- **Errors read from the response** (2026-11-09): `HttpError` carries `body`, `reason` and
|
|
42
|
+
`fieldErrors`; `describeActionError`/`describeHttpError` now say "The request was refused:
|
|
43
|
+
<reason>." for a 4xx with a reason. Tests asserting the old error sentences need updating.
|
|
44
|
+
`fetchJson` treats a 204 or empty body as success.
|
|
45
|
+
- **`useAsyncAction`** (2026-11-07, 2026-11-09): returns `thrown`, `fieldErrors`,
|
|
46
|
+
`clearFieldError`; takes `onError` and `validate`. Failures no longer disappear silently.
|
|
47
|
+
- **Dark mode:** wrap the app in `ThemeProvider` and delete any `matchMedia` listener; it owns
|
|
48
|
+
the `.dark` class. `colorSchemeScript()` goes in `<head>`.
|
|
49
|
+
- **`strata-react/visual` and `strata-visual`** (2026-11-07): replaces any local Playwright
|
|
50
|
+
script. Every font a screen uses must be bundled (fontsource); text in a system font fails
|
|
51
|
+
the shot. Playwright must be pinned to an exact version. Both images are blurred before
|
|
52
|
+
comparing, so baselines recorded with plain pixelmatch settings may be re-recorded once.
|
|
53
|
+
- **One filled button per view** (2026-11-09): while a `BulkBar` is up, the screen's own
|
|
54
|
+
primary becomes `variant="outline"`. `expectOneFilledButton()` checks it.
|
|
55
|
+
- **`format`** (2026-11-08, 2026-11-09): number formatters are callable
|
|
56
|
+
(`format.integer(n)`; `.format(n)` still works). Missing values print `format.missing` and
|
|
57
|
+
dates accept a `Date` or ISO string. `format.share` prints `<1%` and `>99%` where it used to
|
|
58
|
+
print `0%` and `100%`; `CompositionBar` and `Meter` use it.
|
|
59
|
+
- **Install:** `dist/strata.css` scans the built components, so an app needs no `@source`
|
|
60
|
+
line. Node 26 is the floor (`engines`).
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Tone } from './status';
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
/** Props for `Alert`. */
|
|
4
|
+
export type AlertProps = {
|
|
5
|
+
tone: Exclude<Tone, "neutral">;
|
|
6
|
+
/** A short first line, when the sentence needs one: "Export failed". */
|
|
7
|
+
title?: string;
|
|
8
|
+
/** The sentence, in the product's words: what happened and what to do. */
|
|
9
|
+
children: React.ReactNode;
|
|
10
|
+
/** One recovery, a `Button` ("Try again"). */
|
|
11
|
+
action?: React.ReactNode;
|
|
12
|
+
/** It appeared because of something the person just did (a failed submit): announce it at once (`role="alert"`). */
|
|
13
|
+
announce?: boolean;
|
|
14
|
+
className?: string;
|
|
15
|
+
};
|
|
16
|
+
/** An inline sentence about a problem or a fact, in a tone with an icon, with one optional action. `announce` makes it `role="alert"` for a result of the person's own action. */
|
|
17
|
+
export declare function Alert({ tone, title, children, action, announce, className }: AlertProps): React.JSX.Element;
|
|
@@ -9,7 +9,8 @@ export type JobFailure = {
|
|
|
9
9
|
export type JobWords = {
|
|
10
10
|
running: string;
|
|
11
11
|
finished: string;
|
|
12
|
-
failed: string;
|
|
12
|
+
failed: string; /** Shown when `cancelled`. Default "Cancelled". */
|
|
13
|
+
cancelled?: string;
|
|
13
14
|
};
|
|
14
15
|
/** The job status's props. */
|
|
15
16
|
export type JobStatusProps = {
|
|
@@ -30,7 +31,15 @@ export type JobStatusProps = {
|
|
|
30
31
|
failed?: boolean;
|
|
31
32
|
/** Names the list of failures for screen readers. Default "Failures". */
|
|
32
33
|
failuresLabel?: string;
|
|
34
|
+
/** The person stopped it. A neutral ending, not a failure. */
|
|
35
|
+
cancelled?: boolean;
|
|
36
|
+
/** Stops the job. Shows a Cancel button while it runs. */
|
|
37
|
+
onCancel?: () => void;
|
|
38
|
+
/** Label of the cancel button. Default "Cancel". */
|
|
39
|
+
cancelLabel?: string;
|
|
40
|
+
/** Clears the result. Shows a Dismiss button once the job has ended. */
|
|
41
|
+
onDismiss?: () => void;
|
|
33
42
|
className?: string;
|
|
34
43
|
};
|
|
35
44
|
/** A long-running server job: its state as a required word beside the app's sentence, a progress bar when the total is known, each failure named with its reason, and a polite announcement only when the item changes or the job ends. */
|
|
36
|
-
export declare function JobStatus({ label, running, words, summary, current, total, failures, failed, failuresLabel, className, }: JobStatusProps): React.JSX.Element;
|
|
45
|
+
export declare function JobStatus({ label, running, words, summary, current, total, failures, failed, failuresLabel, cancelled, onCancel, cancelLabel, onDismiss, className, }: JobStatusProps): React.JSX.Element;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** What a toast says. */
|
|
2
|
+
export type ToastContentProps = {
|
|
3
|
+
/** What finished, past tense, in the product's words: "Export finished". */
|
|
4
|
+
title: string;
|
|
5
|
+
/** One more sentence: what and where ("run.mp4, 2:31 at 1080p, in your Downloads folder."). */
|
|
6
|
+
description?: string;
|
|
7
|
+
/** `info` by default. There is no danger tone: an error the person must act on is an `Alert`. */
|
|
8
|
+
tone?: "info" | "success" | "warning";
|
|
9
|
+
/** One action beside the words. */
|
|
10
|
+
action?: {
|
|
11
|
+
label: string;
|
|
12
|
+
onPress: () => void;
|
|
13
|
+
};
|
|
14
|
+
/** Milliseconds before it goes. Defaults to enough to read the words. */
|
|
15
|
+
timeout?: number;
|
|
16
|
+
};
|
|
17
|
+
/** Milliseconds a toast stays: 5 s plus 40 ms a character, to at most 15 s, and at least 8 s with an action. */
|
|
18
|
+
export declare function toastTimeout(content: Pick<ToastContentProps, "title" | "description" | "action" | "timeout">): number;
|
|
19
|
+
/** The toast queue: `toast.show({ title })` from anywhere; `toast.close(key)`; `toast.clear()`. */
|
|
20
|
+
export declare const toast: {
|
|
21
|
+
/** Shows a toast and returns its key. */
|
|
22
|
+
show(content: ToastContentProps): string;
|
|
23
|
+
close(key: string): void;
|
|
24
|
+
clear(): void;
|
|
25
|
+
};
|
|
26
|
+
/** Props for `ToastRegion`. */
|
|
27
|
+
export type StrataToastRegionProps = {
|
|
28
|
+
/** Names the landmark. Default "Notifications". */
|
|
29
|
+
label?: string;
|
|
30
|
+
className?: string;
|
|
31
|
+
};
|
|
32
|
+
/** The one place toasts appear. Render it once at the app root. A labelled landmark (F6), polite, above panes and the undo bar. */
|
|
33
|
+
export declare function StrataToastRegion({ label, className }: StrataToastRegionProps): import('react').JSX.Element;
|
package/dist/index.d.ts
CHANGED
|
@@ -27,6 +27,9 @@ export { Meter, crossedThreshold, type MeterProps, type MeterThreshold } from '.
|
|
|
27
27
|
export { CompositionBar, type CompositionBarProps, type CompositionPart } from './components/composition';
|
|
28
28
|
export { LinkCard, LinkCardList, type LinkCardProps } from './components/link-card';
|
|
29
29
|
export { DataView, EmptyState, LoadError, Skeleton, StaleNotice, type Load, type LoadFailure, type Stale } from './components/data-view';
|
|
30
|
+
export { Alert, type AlertProps } from './components/alert';
|
|
31
|
+
export { toast, toastTimeout, StrataToastRegion, type ToastContentProps, type StrataToastRegionProps } from './components/toast';
|
|
32
|
+
export { useClientWork, type ClientWork, type WorkContext, type WorkPhase } from './lib/client-work';
|
|
30
33
|
export { JobStatus, type JobStatusProps, type JobFailure, type JobWords } from './components/job-status';
|
|
31
34
|
export { Thumbnail, ThumbnailSkeleton, type ThumbnailProps, type AspectRatio } from './components/thumbnail';
|
|
32
35
|
export { DataTable, TableSkeleton, parseSort, serialiseSort, type CellValue, type Column, type Sort, type DataTableProps, type RowSelection, type RowExpansion, } from './components/data-table';
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { C as Tooltip, S as readErrorBody, T as typeSteps, _ as Textarea, a as toLoad, b as describeHttpError, c as ColorSchemeChoice, d as useColorScheme, f as useSystemColorScheme, g as NativeSelect, h as Input, i as staleOf, l as ThemeProvider, m as Field, n as createQueryClient, o as useLoad, p as ChoiceGroup, r as fetchJson, s as COLOR_SCHEME_STORAGE_KEY, t as StrataQueryProvider, u as colorSchemeScript, v as HttpError, w as cn, x as fieldErrorsOf, y as describeActionError } from "./query-BVh4zv7Y.js";
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
import { Autocomplete, Button as Button$1, Checkbox as Checkbox$1, Dialog as Dialog$1, DialogTrigger, Header, Heading, Input as Input$1, Keyboard, Menu as Menu$1, MenuItem, MenuSection, MenuTrigger, Modal, ModalOverlay, Popover as Popover$1, SearchField, Separator, SubmenuTrigger, Switch as Switch$1, Tab, TabList, TabPanel, Tabs as Tabs$1, Text, ToggleButton, ToggleButtonGroup, Toolbar as Toolbar$1, useFilter } from "react-aria-components";
|
|
3
|
+
import { Autocomplete, Button as Button$1, Checkbox as Checkbox$1, Dialog as Dialog$1, DialogTrigger, Header, Heading, Input as Input$1, Keyboard, Menu as Menu$1, MenuItem, MenuSection, MenuTrigger, Modal, ModalOverlay, Popover as Popover$1, SearchField, Separator, SubmenuTrigger, Switch as Switch$1, Tab, TabList, TabPanel, Tabs as Tabs$1, Text, ToggleButton, ToggleButtonGroup, Toolbar as Toolbar$1, UNSTABLE_Toast, UNSTABLE_ToastContent, UNSTABLE_ToastQueue, UNSTABLE_ToastRegion, useFilter } from "react-aria-components";
|
|
4
4
|
import { cva } from "class-variance-authority";
|
|
5
5
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
-
import { ArrowDown, ArrowUp, ArrowUpDown, ArrowUpRight, Check, ChevronRight, CircleAlert, History, ImageOff, LoaderCircle, Minus, RotateCcw, Search, Trash2, TriangleAlert, X } from "lucide-react";
|
|
6
|
+
import { ArrowDown, ArrowUp, ArrowUpDown, ArrowUpRight, Ban, Check, ChevronRight, CircleAlert, CircleCheck, History, ImageOff, Info, LoaderCircle, Minus, RotateCcw, Search, Trash2, TriangleAlert, X } from "lucide-react";
|
|
7
7
|
import { Link, NavLink, useSearchParams } from "react-router";
|
|
8
8
|
import { createSortedRowModel, flexRender, rowSortingFeature, tableFeatures, useTable } from "@tanstack/react-table";
|
|
9
9
|
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
@@ -1260,7 +1260,7 @@ function messages(found) {
|
|
|
1260
1260
|
return Object.keys(kept).length ? kept : void 0;
|
|
1261
1261
|
}
|
|
1262
1262
|
// src/components/status.tsx
|
|
1263
|
-
var tones = {
|
|
1263
|
+
var tones$1 = {
|
|
1264
1264
|
neutral: "bg-muted text-muted-foreground",
|
|
1265
1265
|
info: "bg-info-subtle text-info",
|
|
1266
1266
|
success: "bg-success-subtle text-success",
|
|
@@ -1270,7 +1270,7 @@ var tones = {
|
|
|
1270
1270
|
/** A status as a word on a pale tint of its tone, with an optional icon. Never colour alone. */
|
|
1271
1271
|
function Status({ tone, icon: Icon, children, className }) {
|
|
1272
1272
|
return /* @__PURE__ */ jsxs("span", {
|
|
1273
|
-
className: cn("inline-flex items-center gap-1.5 whitespace-nowrap rounded-pill py-0.5 pr-2.5 pl-2 type-caption font-medium", tones[tone], className),
|
|
1273
|
+
className: cn("inline-flex items-center gap-1.5 whitespace-nowrap rounded-pill py-0.5 pr-2.5 pl-2 type-caption font-medium", tones$1[tone], className),
|
|
1274
1274
|
children: [Icon && /* @__PURE__ */ jsx(Icon, {
|
|
1275
1275
|
"aria-hidden": true,
|
|
1276
1276
|
className: "size-3.5 shrink-0"
|
|
@@ -1658,14 +1658,209 @@ function Skeleton({ className }) {
|
|
|
1658
1658
|
className: cn("rounded-control bg-muted motion-safe:animate-pulse", className)
|
|
1659
1659
|
});
|
|
1660
1660
|
}
|
|
1661
|
+
// src/components/alert.tsx
|
|
1662
|
+
var tones = {
|
|
1663
|
+
info: {
|
|
1664
|
+
box: "bg-info-subtle text-info",
|
|
1665
|
+
icon: Info
|
|
1666
|
+
},
|
|
1667
|
+
success: {
|
|
1668
|
+
box: "bg-success-subtle text-success",
|
|
1669
|
+
icon: CircleCheck
|
|
1670
|
+
},
|
|
1671
|
+
warning: {
|
|
1672
|
+
box: "bg-warning-subtle text-warning",
|
|
1673
|
+
icon: TriangleAlert
|
|
1674
|
+
},
|
|
1675
|
+
danger: {
|
|
1676
|
+
box: "bg-danger-subtle text-danger",
|
|
1677
|
+
icon: CircleAlert
|
|
1678
|
+
}
|
|
1679
|
+
};
|
|
1680
|
+
/** An inline sentence about a problem or a fact, in a tone with an icon, with one optional action. `announce` makes it `role="alert"` for a result of the person's own action. */
|
|
1681
|
+
function Alert({ tone, title, children, action, announce = false, className }) {
|
|
1682
|
+
const { box, icon: Icon } = tones[tone];
|
|
1683
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
1684
|
+
role: announce ? "alert" : "region",
|
|
1685
|
+
"aria-label": announce ? void 0 : title ?? "Notice",
|
|
1686
|
+
className: cn("flex items-start gap-3 rounded-surface px-3 py-2.5", box, className),
|
|
1687
|
+
children: [
|
|
1688
|
+
/* @__PURE__ */ jsx(Icon, {
|
|
1689
|
+
"aria-hidden": true,
|
|
1690
|
+
className: "mt-0.5 size-4 shrink-0"
|
|
1691
|
+
}),
|
|
1692
|
+
/* @__PURE__ */ jsxs("div", {
|
|
1693
|
+
className: "grid min-w-0 flex-1 gap-0.5",
|
|
1694
|
+
children: [title && /* @__PURE__ */ jsx("p", {
|
|
1695
|
+
className: "type-label",
|
|
1696
|
+
children: title
|
|
1697
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
1698
|
+
className: "type-body-sm",
|
|
1699
|
+
children
|
|
1700
|
+
})]
|
|
1701
|
+
}),
|
|
1702
|
+
action && /* @__PURE__ */ jsx("div", {
|
|
1703
|
+
className: "shrink-0 self-center",
|
|
1704
|
+
children: action
|
|
1705
|
+
})
|
|
1706
|
+
]
|
|
1707
|
+
});
|
|
1708
|
+
}
|
|
1709
|
+
// src/components/toast.tsx
|
|
1710
|
+
var queue = new UNSTABLE_ToastQueue({ maxVisibleToasts: 3 });
|
|
1711
|
+
/** Milliseconds a toast stays: 5 s plus 40 ms a character, to at most 15 s, and at least 8 s with an action. */
|
|
1712
|
+
function toastTimeout(content) {
|
|
1713
|
+
if (content.timeout !== void 0) return content.timeout;
|
|
1714
|
+
const chars = content.title.length + (content.description?.length ?? 0) + (content.action?.label.length ?? 0);
|
|
1715
|
+
return Math.max(content.action ? 8e3 : 0, Math.min(15e3, 5e3 + 40 * chars));
|
|
1716
|
+
}
|
|
1717
|
+
/** The toast queue: `toast.show({ title })` from anywhere; `toast.close(key)`; `toast.clear()`. */
|
|
1718
|
+
var toast = {
|
|
1719
|
+
/** Shows a toast and returns its key. */
|
|
1720
|
+
show(content) {
|
|
1721
|
+
return queue.add(content, { timeout: toastTimeout(content) });
|
|
1722
|
+
},
|
|
1723
|
+
close(key) {
|
|
1724
|
+
queue.close(key);
|
|
1725
|
+
},
|
|
1726
|
+
clear() {
|
|
1727
|
+
queue.clear();
|
|
1728
|
+
}
|
|
1729
|
+
};
|
|
1730
|
+
var marks = {
|
|
1731
|
+
info: {
|
|
1732
|
+
icon: Info,
|
|
1733
|
+
color: "text-info"
|
|
1734
|
+
},
|
|
1735
|
+
success: {
|
|
1736
|
+
icon: CircleCheck,
|
|
1737
|
+
color: "text-success"
|
|
1738
|
+
},
|
|
1739
|
+
warning: {
|
|
1740
|
+
icon: TriangleAlert,
|
|
1741
|
+
color: "text-warning"
|
|
1742
|
+
}
|
|
1743
|
+
};
|
|
1744
|
+
/** The one place toasts appear. Render it once at the app root. A labelled landmark (F6), polite, above panes and the undo bar. */
|
|
1745
|
+
function StrataToastRegion({ label = "Notifications", className }) {
|
|
1746
|
+
return /* @__PURE__ */ jsx(UNSTABLE_ToastRegion, {
|
|
1747
|
+
queue,
|
|
1748
|
+
"aria-label": label,
|
|
1749
|
+
className: cn("layer-bar fixed inset-x-4 top-4 grid justify-items-end gap-2 outline-none sm:inset-x-auto sm:top-auto sm:right-4 sm:bottom-4", className),
|
|
1750
|
+
children: ({ toast: t }) => /* @__PURE__ */ jsxs(UNSTABLE_Toast, {
|
|
1751
|
+
toast: t,
|
|
1752
|
+
className: cn("flex w-full max-w-sm items-start gap-3 p-3 outline-none data-[focus-visible]:outline-2 data-[focus-visible]:outline-ring", overlaySurface),
|
|
1753
|
+
children: [
|
|
1754
|
+
(() => {
|
|
1755
|
+
const { icon: Icon, color } = marks[t.content.tone ?? "info"];
|
|
1756
|
+
return /* @__PURE__ */ jsx(Icon, {
|
|
1757
|
+
"aria-hidden": true,
|
|
1758
|
+
className: cn("mt-0.5 size-4 shrink-0", color)
|
|
1759
|
+
});
|
|
1760
|
+
})(),
|
|
1761
|
+
/* @__PURE__ */ jsxs(UNSTABLE_ToastContent, {
|
|
1762
|
+
className: "grid min-w-0 flex-1 gap-0.5",
|
|
1763
|
+
children: [/* @__PURE__ */ jsx(Text, {
|
|
1764
|
+
slot: "title",
|
|
1765
|
+
className: "type-label",
|
|
1766
|
+
children: t.content.title
|
|
1767
|
+
}), t.content.description && /* @__PURE__ */ jsx(Text, {
|
|
1768
|
+
slot: "description",
|
|
1769
|
+
className: "type-body-sm text-muted-foreground",
|
|
1770
|
+
children: t.content.description
|
|
1771
|
+
})]
|
|
1772
|
+
}),
|
|
1773
|
+
t.content.action && /* @__PURE__ */ jsx(Button, {
|
|
1774
|
+
size: "sm",
|
|
1775
|
+
onPress: () => {
|
|
1776
|
+
t.content.action?.onPress();
|
|
1777
|
+
queue.close(t.key);
|
|
1778
|
+
},
|
|
1779
|
+
children: t.content.action.label
|
|
1780
|
+
}),
|
|
1781
|
+
/* @__PURE__ */ jsx(Button$1, {
|
|
1782
|
+
slot: "close",
|
|
1783
|
+
"aria-label": "Dismiss",
|
|
1784
|
+
className: "grid size-6 shrink-0 cursor-pointer place-items-center rounded-control text-muted-foreground transition-state data-[hovered]:bg-muted data-[hovered]:text-foreground",
|
|
1785
|
+
children: /* @__PURE__ */ jsx(X, {
|
|
1786
|
+
"aria-hidden": true,
|
|
1787
|
+
className: "size-4"
|
|
1788
|
+
})
|
|
1789
|
+
})
|
|
1790
|
+
]
|
|
1791
|
+
})
|
|
1792
|
+
});
|
|
1793
|
+
}
|
|
1794
|
+
// src/lib/client-work.ts
|
|
1795
|
+
/** Runs browser-side work with progress, cancel and a clear end state, ready for `JobStatus`. */
|
|
1796
|
+
function useClientWork(run) {
|
|
1797
|
+
const [state, setState] = React.useState({ phase: "idle" });
|
|
1798
|
+
const controller = React.useRef(null);
|
|
1799
|
+
const runRef = React.useRef(run);
|
|
1800
|
+
runRef.current = run;
|
|
1801
|
+
const start = React.useCallback(async () => {
|
|
1802
|
+
if (controller.current) return;
|
|
1803
|
+
const mine = new AbortController();
|
|
1804
|
+
controller.current = mine;
|
|
1805
|
+
const live = () => controller.current === mine;
|
|
1806
|
+
setState({ phase: "running" });
|
|
1807
|
+
try {
|
|
1808
|
+
const result = await runRef.current({
|
|
1809
|
+
signal: mine.signal,
|
|
1810
|
+
progress: (current, total) => live() && setState((s) => ({
|
|
1811
|
+
...s,
|
|
1812
|
+
current,
|
|
1813
|
+
total: total ?? s.total
|
|
1814
|
+
}))
|
|
1815
|
+
});
|
|
1816
|
+
if (!live()) return;
|
|
1817
|
+
setState(mine.signal.aborted ? { phase: "cancelled" } : {
|
|
1818
|
+
phase: "finished",
|
|
1819
|
+
result
|
|
1820
|
+
});
|
|
1821
|
+
} catch (error) {
|
|
1822
|
+
if (!live()) return;
|
|
1823
|
+
setState(mine.signal.aborted ? { phase: "cancelled" } : {
|
|
1824
|
+
phase: "failed",
|
|
1825
|
+
error
|
|
1826
|
+
});
|
|
1827
|
+
} finally {
|
|
1828
|
+
if (live()) controller.current = null;
|
|
1829
|
+
}
|
|
1830
|
+
}, []);
|
|
1831
|
+
const cancel = React.useCallback(() => {
|
|
1832
|
+
const c = controller.current;
|
|
1833
|
+
if (!c) return;
|
|
1834
|
+
c.abort();
|
|
1835
|
+
controller.current = null;
|
|
1836
|
+
setState({ phase: "cancelled" });
|
|
1837
|
+
}, []);
|
|
1838
|
+
const dismiss = React.useCallback(() => {
|
|
1839
|
+
if (!controller.current) setState({ phase: "idle" });
|
|
1840
|
+
}, []);
|
|
1841
|
+
React.useEffect(() => () => {
|
|
1842
|
+
controller.current?.abort();
|
|
1843
|
+
controller.current = null;
|
|
1844
|
+
}, []);
|
|
1845
|
+
return {
|
|
1846
|
+
...state,
|
|
1847
|
+
start,
|
|
1848
|
+
cancel,
|
|
1849
|
+
dismiss
|
|
1850
|
+
};
|
|
1851
|
+
}
|
|
1661
1852
|
// src/components/job-status.tsx
|
|
1662
1853
|
var Spinner = ({ className, ...props }) => /* @__PURE__ */ jsx(LoaderCircle, {
|
|
1663
1854
|
...props,
|
|
1664
1855
|
className: cn(className, "motion-safe:animate-spin")
|
|
1665
1856
|
});
|
|
1666
1857
|
/** A long-running server job: its state as a required word beside the app's sentence, a progress bar when the total is known, each failure named with its reason, and a polite announcement only when the item changes or the job ends. */
|
|
1667
|
-
function JobStatus({ label, running, words, summary, current, total, failures = [], failed = false, failuresLabel = "Failures", className }) {
|
|
1668
|
-
const ended =
|
|
1858
|
+
function JobStatus({ label, running, words, summary, current, total, failures = [], failed = false, failuresLabel = "Failures", cancelled = false, onCancel, cancelLabel = "Cancel", onDismiss, className }) {
|
|
1859
|
+
const ended = cancelled ? {
|
|
1860
|
+
tone: "neutral",
|
|
1861
|
+
icon: Ban,
|
|
1862
|
+
word: words.cancelled ?? "Cancelled"
|
|
1863
|
+
} : failed ? {
|
|
1669
1864
|
tone: "danger",
|
|
1670
1865
|
icon: CircleAlert,
|
|
1671
1866
|
word: words.failed
|
|
@@ -1700,14 +1895,28 @@ function JobStatus({ label, running, words, summary, current, total, failures =
|
|
|
1700
1895
|
children: [
|
|
1701
1896
|
/* @__PURE__ */ jsxs("div", {
|
|
1702
1897
|
className: "flex flex-wrap items-center gap-x-3 gap-y-1",
|
|
1703
|
-
children: [
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1898
|
+
children: [
|
|
1899
|
+
/* @__PURE__ */ jsx(Status, {
|
|
1900
|
+
tone,
|
|
1901
|
+
icon,
|
|
1902
|
+
children: word
|
|
1903
|
+
}),
|
|
1904
|
+
/* @__PURE__ */ jsx("p", {
|
|
1905
|
+
className: "min-w-0 flex-1 type-body-sm text-foreground",
|
|
1906
|
+
children: summary
|
|
1907
|
+
}),
|
|
1908
|
+
running && onCancel && /* @__PURE__ */ jsx(Button, {
|
|
1909
|
+
size: "sm",
|
|
1910
|
+
onPress: onCancel,
|
|
1911
|
+
children: cancelLabel
|
|
1912
|
+
}),
|
|
1913
|
+
!running && onDismiss && /* @__PURE__ */ jsx(Button, {
|
|
1914
|
+
size: "sm",
|
|
1915
|
+
variant: "ghost",
|
|
1916
|
+
onPress: onDismiss,
|
|
1917
|
+
children: "Dismiss"
|
|
1918
|
+
})
|
|
1919
|
+
]
|
|
1711
1920
|
}),
|
|
1712
1921
|
bar && /* @__PURE__ */ jsx("div", {
|
|
1713
1922
|
role: "progressbar",
|
|
@@ -3640,6 +3849,6 @@ function useJob({ isRunning, every = 2e3, invalidates = [], describeError, ...op
|
|
|
3640
3849
|
poll
|
|
3641
3850
|
};
|
|
3642
3851
|
}
|
|
3643
|
-
export { ActiveList, AlertDialog, AppShell, AsyncButton, Breadcrumb, BulkBar, Button, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGroup, ColorSchemeChoice, CommandLegend, CommandMenu, CompositionBar, ContextMenu, DataTable, DataView, Dialog, Disclosure, Done, EmptyState, Field, HttpError, IconButton, InfiniteList, Input, JobStatus, KeysLegend, LineChart, LinkCard, LinkCardList, LoadError, LoadMore, MISSING, Menu, Meter, Metric, MetricStrip, NBSP, NativeSelect, PageHeader, Popover, RowAction, SelectableGrid, SideNav, Skeleton, StaleNotice, Status, StrataQueryProvider, Switch, TableSkeleton, Tabs, Textarea, ThemeProvider, Thumbnail, ThumbnailSkeleton, Toggle, ToggleGroup, Toolbar, ToolbarSeparator, Tooltip, UndoBar, VirtualList, buttonVariants, cn, colorSchemeScript, commandShortcut, createFormat, createQueryClient, crossedThreshold, describeActionError, describeHttpError, detectPlatform, fetchJson, fieldErrorsOf, format, formatChord, isReservedChord, isTypingTarget, labelOf, matchesChord, parseChord, parseSort, readErrorBody, serialiseSort, staleOf, toDate, toLoad, typeSteps, useActiveItem, useAsyncAction, useColorScheme, useCommands, useExpanded, useHotkeys, useInView, useInfiniteLoad, useJob, useLoad, useSelection, useSystemColorScheme, useUndoable };
|
|
3852
|
+
export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, Breadcrumb, BulkBar, Button, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGroup, ColorSchemeChoice, CommandLegend, CommandMenu, CompositionBar, ContextMenu, DataTable, DataView, Dialog, Disclosure, Done, EmptyState, Field, HttpError, IconButton, InfiniteList, Input, JobStatus, KeysLegend, LineChart, LinkCard, LinkCardList, LoadError, LoadMore, MISSING, Menu, Meter, Metric, MetricStrip, NBSP, NativeSelect, PageHeader, Popover, RowAction, SelectableGrid, SideNav, Skeleton, StaleNotice, Status, StrataQueryProvider, StrataToastRegion, Switch, TableSkeleton, Tabs, Textarea, ThemeProvider, Thumbnail, ThumbnailSkeleton, Toggle, ToggleGroup, Toolbar, ToolbarSeparator, Tooltip, UndoBar, VirtualList, buttonVariants, cn, colorSchemeScript, commandShortcut, createFormat, createQueryClient, crossedThreshold, describeActionError, describeHttpError, detectPlatform, fetchJson, fieldErrorsOf, format, formatChord, isReservedChord, isTypingTarget, labelOf, matchesChord, parseChord, parseSort, readErrorBody, serialiseSort, staleOf, toDate, toLoad, toast, toastTimeout, typeSteps, useActiveItem, useAsyncAction, useClientWork, useColorScheme, useCommands, useExpanded, useHotkeys, useInView, useInfiniteLoad, useJob, useLoad, useSelection, useSystemColorScheme, useUndoable };
|
|
3644
3853
|
|
|
3645
3854
|
//# sourceMappingURL=index.js.map
|