strata-react 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
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";
1
+ import { C as readErrorBody, E as typeSteps, S as fieldErrorsOf, T as cn, _ as Textarea, a as toLoad, b as describeActionError, 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 useFieldControl, w as Tooltip, x as describeHttpError, y as HttpError } from "./query-gC6I6Cen.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, I18nProvider, Input as Input$1, Keyboard, Menu as Menu$1, MenuItem, MenuSection, MenuTrigger, Modal, ModalOverlay, NumberField as NumberField$1, Popover as Popover$1, SearchField, Separator, Slider as Slider$1, SliderOutput, SliderThumb, SliderTrack, 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,516 @@ function Skeleton({ className }) {
1658
1658
  className: cn("rounded-control bg-muted motion-safe:animate-pulse", className)
1659
1659
  });
1660
1660
  }
1661
+ // src/lib/number-input.ts
1662
+ /** Reads `#rgb`, `#rrggbb` (with or without the #) as lower-case `#rrggbb`, or null. */
1663
+ function parseHex(text) {
1664
+ const m = /^#?([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(text.trim());
1665
+ if (!m) return null;
1666
+ const h = m[1].toLowerCase();
1667
+ return "#" + (h.length === 3 ? [...h].map((c) => c + c).join("") : h);
1668
+ }
1669
+ function luminance(hex) {
1670
+ const v = [
1671
+ 1,
1672
+ 3,
1673
+ 5
1674
+ ].map((i) => parseInt(hex.slice(i, i + 2), 16) / 255).map((c) => c <= .03928 ? c / 12.92 : ((c + .055) / 1.055) ** 2.4);
1675
+ return .2126 * v[0] + .7152 * v[1] + .0722 * v[2];
1676
+ }
1677
+ /** WCAG contrast ratio between two `#rrggbb` colours, 1 to 21. */
1678
+ function contrastRatio(a, b) {
1679
+ const [hi, lo] = [luminance(a), luminance(b)].sort((x, y) => y - x);
1680
+ return (hi + .05) / (lo + .05);
1681
+ }
1682
+ // src/components/value-controls.tsx
1683
+ var box = "flex h-(--control-h) w-full min-w-0 items-center rounded-control border border-input bg-background px-3 type-body text-foreground transition-state data-[disabled]:cursor-not-allowed data-[disabled]:bg-muted data-[disabled]:opacity-70 has-[input:disabled]:cursor-not-allowed has-[input:disabled]:bg-muted has-[input:disabled]:opacity-70 aria-invalid:border-danger has-[input:focus-visible]:outline-2 has-[input:focus-visible]:outline-offset-2 has-[input:focus-visible]:outline-ring";
1684
+ /** A number with its unit joined by a non-breaking space; `%` and `°` stay attached. */
1685
+ function withUnit(text, unit) {
1686
+ if (!unit) return text;
1687
+ return unit === "%" || unit === "°" ? text + unit : text + "\xA0" + unit;
1688
+ }
1689
+ var intlUnits = {
1690
+ "%": "percent",
1691
+ "°": "degree",
1692
+ ms: "millisecond",
1693
+ s: "second",
1694
+ kB: "kilobyte",
1695
+ MB: "megabyte",
1696
+ GB: "gigabyte",
1697
+ kbps: "kilobit-per-second",
1698
+ Mbps: "megabit-per-second"
1699
+ };
1700
+ function decimalsOf(n) {
1701
+ const s = String(n);
1702
+ if (s.includes("e-")) return Number(s.split("e-")[1]) + (s.split("e-")[0].split(".")[1]?.length ?? 0);
1703
+ return s.split(".")[1]?.length ?? 0;
1704
+ }
1705
+ function useNumberText(locale, places) {
1706
+ return React.useMemo(() => {
1707
+ const f = new Intl.NumberFormat(locale, {
1708
+ maximumFractionDigits: places,
1709
+ minimumFractionDigits: 0
1710
+ });
1711
+ return (n) => f.format(n);
1712
+ }, [locale, places]);
1713
+ }
1714
+ function formatOptionsFor(places, unit) {
1715
+ const base = {
1716
+ maximumFractionDigits: places,
1717
+ minimumFractionDigits: 0
1718
+ };
1719
+ const known = unit ? intlUnits[unit] : void 0;
1720
+ return known ? {
1721
+ ...base,
1722
+ style: "unit",
1723
+ unit: known,
1724
+ unitDisplay: "narrow"
1725
+ } : base;
1726
+ }
1727
+ function describeRange(min, max, show, unit) {
1728
+ const a = min === void 0 ? "" : withUnit(show(min), unit);
1729
+ const b = max === void 0 ? "" : withUnit(show(max), unit);
1730
+ if (min !== void 0 && max !== void 0) return `Enter a value from ${a} to ${b}.`;
1731
+ if (min !== void 0) return `Enter ${a} or more.`;
1732
+ if (max !== void 0) return `Enter ${b} or less.`;
1733
+ return "Enter a number.";
1734
+ }
1735
+ /** A number with a unit on React Aria's number field: typed input is validated, not clamped, so an out-of-range value is explained in the surrounding `Field` and never passed on; empty stays `null`. */
1736
+ function NumberField({ value, onChange, min, max, step = 1, places, unit, locale = format.locale, required = false, disabled, id: idProp, name, className, "aria-label": ariaLabel }) {
1737
+ const { field, report } = useFieldControl();
1738
+ const digits = places ?? Math.max(decimalsOf(step), min === void 0 ? 0 : decimalsOf(min));
1739
+ const show = useNumberText(locale, digits);
1740
+ const [own, setOwn] = React.useState(false);
1741
+ const unitId = React.useId();
1742
+ const [local, setLocal] = React.useState(value ?? NaN);
1743
+ const [seen, setSeen] = React.useState(value);
1744
+ if (seen !== value) {
1745
+ setSeen(value);
1746
+ setLocal(value ?? NaN);
1747
+ }
1748
+ const fail = (message) => {
1749
+ setOwn(true);
1750
+ report(message);
1751
+ };
1752
+ const ok = () => {
1753
+ setOwn(false);
1754
+ report(void 0);
1755
+ };
1756
+ const handle = (n) => {
1757
+ setLocal(n);
1758
+ if (Number.isNaN(n)) {
1759
+ if (required) return fail("Enter a value.");
1760
+ ok();
1761
+ if (value !== null) onChange(null);
1762
+ return;
1763
+ }
1764
+ if (min !== void 0 && n < min || max !== void 0 && n > max) return fail(describeRange(min, max, show, unit));
1765
+ ok();
1766
+ if (n !== value) onChange(n);
1767
+ };
1768
+ const invalid = field?.invalid || own;
1769
+ return /* @__PURE__ */ jsx(I18nProvider, {
1770
+ locale,
1771
+ children: /* @__PURE__ */ jsxs(NumberField$1, {
1772
+ value: local,
1773
+ onChange: handle,
1774
+ minValue: min,
1775
+ maxValue: max,
1776
+ step,
1777
+ formatOptions: {
1778
+ maximumFractionDigits: digits,
1779
+ minimumFractionDigits: 0
1780
+ },
1781
+ commitBehavior: "validate",
1782
+ isDisabled: disabled,
1783
+ isInvalid: invalid || void 0,
1784
+ name,
1785
+ "aria-label": ariaLabel ?? field?.label,
1786
+ className: cn(box, className),
1787
+ children: [/* @__PURE__ */ jsx(Input$1, {
1788
+ id: idProp ?? field?.id,
1789
+ placeholder: format.missing,
1790
+ "aria-describedby": [field?.describedBy, unit ? unitId : void 0].filter(Boolean).join(" ") || void 0,
1791
+ className: "min-w-0 flex-1 bg-transparent tabular-nums outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed"
1792
+ }), unit && /* @__PURE__ */ jsxs("span", {
1793
+ id: unitId,
1794
+ className: "ml-2 shrink-0 type-body-sm text-muted-foreground",
1795
+ children: [/* @__PURE__ */ jsx("span", {
1796
+ "aria-hidden": true,
1797
+ children: unit
1798
+ }), /* @__PURE__ */ jsx("span", {
1799
+ className: "sr-only",
1800
+ children: intlUnits[unit] ? intlUnits[unit].replace(/-/g, " ") : unit
1801
+ })]
1802
+ })]
1803
+ })
1804
+ });
1805
+ }
1806
+ /** A slider on React Aria with its current value always printed beside the track (and spoken with the unit when `Intl` knows it); `editable` adds a number field to type an exact value. */
1807
+ function Slider({ value, onChange, min, max, step = 1, unit, locale = format.locale, editable = false, hideValue = false, places, disabled, className, "aria-label": ariaLabel }) {
1808
+ const { field } = useFieldControl();
1809
+ const digits = places ?? Math.max(decimalsOf(step), decimalsOf(min));
1810
+ const show = useNumberText(locale, digits);
1811
+ const name = ariaLabel ?? field?.label ?? "Value";
1812
+ const text = withUnit(show(value), unit);
1813
+ return /* @__PURE__ */ jsx(I18nProvider, {
1814
+ locale,
1815
+ children: /* @__PURE__ */ jsxs(Slider$1, {
1816
+ value,
1817
+ onChange: (v) => onChange(v),
1818
+ minValue: min,
1819
+ maxValue: max,
1820
+ step,
1821
+ formatOptions: formatOptionsFor(digits, unit),
1822
+ isDisabled: disabled,
1823
+ "aria-label": name,
1824
+ "aria-describedby": field?.describedBy,
1825
+ className: cn("flex min-w-0 items-center gap-3", className),
1826
+ children: [/* @__PURE__ */ jsx(SliderTrack, {
1827
+ className: "relative flex h-(--control-h) min-w-0 flex-1 cursor-pointer items-center data-[disabled]:cursor-not-allowed data-[disabled]:opacity-50",
1828
+ children: ({ state }) => /* @__PURE__ */ jsxs(Fragment, { children: [
1829
+ /* @__PURE__ */ jsx("span", {
1830
+ "aria-hidden": true,
1831
+ className: "absolute inset-x-0 h-1.5 rounded-pill bg-muted"
1832
+ }),
1833
+ /* @__PURE__ */ jsx("span", {
1834
+ "aria-hidden": true,
1835
+ className: "absolute left-0 h-1.5 rounded-pill bg-primary",
1836
+ style: { width: `${state.getThumbPercent(0) * 100}%` }
1837
+ }),
1838
+ /* @__PURE__ */ jsx(SliderThumb, { className: "top-1/2 size-5 rounded-pill border-2 border-primary bg-background data-[focus-visible]:outline-2 data-[focus-visible]:outline-offset-2 data-[focus-visible]:outline-ring" })
1839
+ ] })
1840
+ }), editable ? /* @__PURE__ */ jsx(NumberField, {
1841
+ className: "w-28 shrink-0",
1842
+ "aria-label": `${name}, exact value`,
1843
+ value,
1844
+ onChange: (v) => v !== null && onChange(v),
1845
+ min,
1846
+ max,
1847
+ step,
1848
+ unit,
1849
+ locale,
1850
+ places: digits,
1851
+ required: true,
1852
+ disabled
1853
+ }) : !hideValue && /* @__PURE__ */ jsx(SliderOutput, {
1854
+ "aria-hidden": true,
1855
+ className: "w-16 shrink-0 text-right type-body-sm tabular-nums text-foreground",
1856
+ children: text
1857
+ })]
1858
+ })
1859
+ });
1860
+ }
1861
+ /** Choose a colour with the platform picker, see and type its hex value, pick from the app's suggestions, and get a note when it would be hard to see on `against`. A half-typed value is never passed on. */
1862
+ function ColorField({ value, onChange, suggestions, against, againstLabel = "the background", minContrast = 3, disabled, id: idProp, className, "aria-label": ariaLabel }) {
1863
+ const { field, report } = useFieldControl();
1864
+ const [draft, setDraft] = React.useState(null);
1865
+ const [own, setOwn] = React.useState(false);
1866
+ const text = draft ?? value ?? "";
1867
+ const ratio = value && against ? contrastRatio(value, against) : null;
1868
+ const commitText = (t) => {
1869
+ if (t.trim() === "") {
1870
+ setOwn(false);
1871
+ report(void 0);
1872
+ if (value !== null) onChange(null);
1873
+ return true;
1874
+ }
1875
+ const hex = parseHex(t);
1876
+ if (!hex) {
1877
+ setOwn(true);
1878
+ report("Enter a colour like #1a7f64.");
1879
+ return false;
1880
+ }
1881
+ setOwn(false);
1882
+ report(void 0);
1883
+ if (hex !== value) onChange(hex);
1884
+ return true;
1885
+ };
1886
+ const pick = (hex) => {
1887
+ setDraft(null);
1888
+ setOwn(false);
1889
+ report(void 0);
1890
+ if (hex !== value) onChange(hex);
1891
+ };
1892
+ const invalid = field?.invalid || own;
1893
+ return /* @__PURE__ */ jsxs("div", {
1894
+ className: cn("grid min-w-0 gap-2", className),
1895
+ children: [
1896
+ /* @__PURE__ */ jsxs("div", {
1897
+ className: cn(box, "gap-2 px-2"),
1898
+ "aria-invalid": invalid || void 0,
1899
+ children: [/* @__PURE__ */ jsxs("span", {
1900
+ className: "relative size-6 shrink-0 overflow-hidden rounded-control border border-input",
1901
+ children: [/* @__PURE__ */ jsx("span", {
1902
+ "aria-hidden": true,
1903
+ className: cn("absolute inset-0", value === null && "bg-muted"),
1904
+ style: value ? { background: value } : void 0
1905
+ }), /* @__PURE__ */ jsx("input", {
1906
+ type: "color",
1907
+ "aria-label": ariaLabel ? `${ariaLabel}, picker` : "Colour picker",
1908
+ value: value ?? "#000000",
1909
+ disabled,
1910
+ onChange: (e) => pick(e.target.value),
1911
+ className: "absolute inset-0 size-full cursor-pointer opacity-0 disabled:cursor-not-allowed"
1912
+ })]
1913
+ }), /* @__PURE__ */ jsx("input", {
1914
+ id: idProp ?? field?.id,
1915
+ type: "text",
1916
+ autoComplete: "off",
1917
+ spellCheck: false,
1918
+ disabled,
1919
+ "aria-label": ariaLabel,
1920
+ "aria-describedby": field?.describedBy,
1921
+ "aria-invalid": invalid || void 0,
1922
+ placeholder: format.missing,
1923
+ value: text,
1924
+ onChange: (e) => setDraft(e.target.value),
1925
+ onBlur: () => {
1926
+ if (draft !== null && commitText(draft)) setDraft(null);
1927
+ },
1928
+ onKeyDown: (e) => {
1929
+ if (e.key === "Enter" && draft !== null && commitText(draft)) setDraft(null);
1930
+ if (e.key === "Escape" && draft !== null) {
1931
+ setDraft(null);
1932
+ setOwn(false);
1933
+ report(void 0);
1934
+ }
1935
+ },
1936
+ className: "min-w-0 flex-1 bg-transparent tabular-nums outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed"
1937
+ })]
1938
+ }),
1939
+ suggestions && suggestions.length > 0 && /* @__PURE__ */ jsx("div", {
1940
+ role: "group",
1941
+ "aria-label": "Suggested colours",
1942
+ className: "flex flex-wrap gap-1.5",
1943
+ children: suggestions.map((hex) => /* @__PURE__ */ jsx("button", {
1944
+ type: "button",
1945
+ disabled,
1946
+ "aria-label": hex,
1947
+ "aria-pressed": value === hex,
1948
+ onClick: () => pick(hex),
1949
+ className: "size-6 cursor-pointer rounded-control border border-input transition-state aria-pressed:outline-2 aria-pressed:outline-offset-2 aria-pressed:outline-foreground disabled:cursor-not-allowed disabled:opacity-50",
1950
+ style: { background: hex }
1951
+ }, hex))
1952
+ }),
1953
+ ratio !== null && ratio < minContrast && /* @__PURE__ */ jsxs("p", {
1954
+ className: "type-body-sm text-warning",
1955
+ children: [
1956
+ "Hard to see on ",
1957
+ againstLabel,
1958
+ ": contrast ",
1959
+ format.decimal(ratio),
1960
+ ":1, aim for ",
1961
+ format.decimal(minContrast),
1962
+ ":1 or more."
1963
+ ]
1964
+ })
1965
+ ]
1966
+ });
1967
+ }
1968
+ // src/components/alert.tsx
1969
+ var tones = {
1970
+ info: {
1971
+ box: "bg-info-subtle text-info",
1972
+ icon: Info
1973
+ },
1974
+ success: {
1975
+ box: "bg-success-subtle text-success",
1976
+ icon: CircleCheck
1977
+ },
1978
+ warning: {
1979
+ box: "bg-warning-subtle text-warning",
1980
+ icon: TriangleAlert
1981
+ },
1982
+ danger: {
1983
+ box: "bg-danger-subtle text-danger",
1984
+ icon: CircleAlert
1985
+ }
1986
+ };
1987
+ /** 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. */
1988
+ function Alert({ tone, title, children, action, announce = false, className }) {
1989
+ const { box, icon: Icon } = tones[tone];
1990
+ return /* @__PURE__ */ jsxs("div", {
1991
+ role: announce ? "alert" : "region",
1992
+ "aria-label": announce ? void 0 : title ?? "Notice",
1993
+ className: cn("flex items-start gap-3 rounded-surface px-3 py-2.5", box, className),
1994
+ children: [
1995
+ /* @__PURE__ */ jsx(Icon, {
1996
+ "aria-hidden": true,
1997
+ className: "mt-0.5 size-4 shrink-0"
1998
+ }),
1999
+ /* @__PURE__ */ jsxs("div", {
2000
+ className: "grid min-w-0 flex-1 gap-0.5",
2001
+ children: [title && /* @__PURE__ */ jsx("p", {
2002
+ className: "type-label",
2003
+ children: title
2004
+ }), /* @__PURE__ */ jsx("div", {
2005
+ className: "type-body-sm",
2006
+ children
2007
+ })]
2008
+ }),
2009
+ action && /* @__PURE__ */ jsx("div", {
2010
+ className: "shrink-0 self-center",
2011
+ children: action
2012
+ })
2013
+ ]
2014
+ });
2015
+ }
2016
+ // src/components/toast.tsx
2017
+ var queue = new UNSTABLE_ToastQueue({ maxVisibleToasts: 3 });
2018
+ /** Milliseconds a toast stays: 5 s plus 40 ms a character, to at most 15 s, and at least 8 s with an action. */
2019
+ function toastTimeout(content) {
2020
+ if (content.timeout !== void 0) return content.timeout;
2021
+ const chars = content.title.length + (content.description?.length ?? 0) + (content.action?.label.length ?? 0);
2022
+ return Math.max(content.action ? 8e3 : 0, Math.min(15e3, 5e3 + 40 * chars));
2023
+ }
2024
+ /** The toast queue: `toast.show({ title })` from anywhere; `toast.close(key)`; `toast.clear()`. */
2025
+ var toast = {
2026
+ /** Shows a toast and returns its key. */
2027
+ show(content) {
2028
+ return queue.add(content, { timeout: toastTimeout(content) });
2029
+ },
2030
+ close(key) {
2031
+ queue.close(key);
2032
+ },
2033
+ clear() {
2034
+ queue.clear();
2035
+ }
2036
+ };
2037
+ var marks = {
2038
+ info: {
2039
+ icon: Info,
2040
+ color: "text-info"
2041
+ },
2042
+ success: {
2043
+ icon: CircleCheck,
2044
+ color: "text-success"
2045
+ },
2046
+ warning: {
2047
+ icon: TriangleAlert,
2048
+ color: "text-warning"
2049
+ }
2050
+ };
2051
+ /** The one place toasts appear. Render it once at the app root. A labelled landmark (F6), polite, above panes and the undo bar. */
2052
+ function StrataToastRegion({ label = "Notifications", className }) {
2053
+ return /* @__PURE__ */ jsx(UNSTABLE_ToastRegion, {
2054
+ queue,
2055
+ "aria-label": label,
2056
+ 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),
2057
+ children: ({ toast: t }) => /* @__PURE__ */ jsxs(UNSTABLE_Toast, {
2058
+ toast: t,
2059
+ 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),
2060
+ children: [
2061
+ (() => {
2062
+ const { icon: Icon, color } = marks[t.content.tone ?? "info"];
2063
+ return /* @__PURE__ */ jsx(Icon, {
2064
+ "aria-hidden": true,
2065
+ className: cn("mt-0.5 size-4 shrink-0", color)
2066
+ });
2067
+ })(),
2068
+ /* @__PURE__ */ jsxs(UNSTABLE_ToastContent, {
2069
+ className: "grid min-w-0 flex-1 gap-0.5",
2070
+ children: [/* @__PURE__ */ jsx(Text, {
2071
+ slot: "title",
2072
+ className: "type-label",
2073
+ children: t.content.title
2074
+ }), t.content.description && /* @__PURE__ */ jsx(Text, {
2075
+ slot: "description",
2076
+ className: "type-body-sm text-muted-foreground",
2077
+ children: t.content.description
2078
+ })]
2079
+ }),
2080
+ t.content.action && /* @__PURE__ */ jsx(Button, {
2081
+ size: "sm",
2082
+ onPress: () => {
2083
+ t.content.action?.onPress();
2084
+ queue.close(t.key);
2085
+ },
2086
+ children: t.content.action.label
2087
+ }),
2088
+ /* @__PURE__ */ jsx(Button$1, {
2089
+ slot: "close",
2090
+ "aria-label": "Dismiss",
2091
+ 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",
2092
+ children: /* @__PURE__ */ jsx(X, {
2093
+ "aria-hidden": true,
2094
+ className: "size-4"
2095
+ })
2096
+ })
2097
+ ]
2098
+ })
2099
+ });
2100
+ }
2101
+ // src/lib/client-work.ts
2102
+ /** Runs browser-side work with progress, cancel and a clear end state, ready for `JobStatus`. */
2103
+ function useClientWork(run) {
2104
+ const [state, setState] = React.useState({ phase: "idle" });
2105
+ const controller = React.useRef(null);
2106
+ const runRef = React.useRef(run);
2107
+ runRef.current = run;
2108
+ const start = React.useCallback(async () => {
2109
+ if (controller.current) return;
2110
+ const mine = new AbortController();
2111
+ controller.current = mine;
2112
+ const live = () => controller.current === mine;
2113
+ setState({ phase: "running" });
2114
+ try {
2115
+ const result = await runRef.current({
2116
+ signal: mine.signal,
2117
+ progress: (current, total) => live() && setState((s) => ({
2118
+ ...s,
2119
+ current,
2120
+ total: total ?? s.total
2121
+ }))
2122
+ });
2123
+ if (!live()) return;
2124
+ setState(mine.signal.aborted ? { phase: "cancelled" } : {
2125
+ phase: "finished",
2126
+ result
2127
+ });
2128
+ } catch (error) {
2129
+ if (!live()) return;
2130
+ setState(mine.signal.aborted ? { phase: "cancelled" } : {
2131
+ phase: "failed",
2132
+ error
2133
+ });
2134
+ } finally {
2135
+ if (live()) controller.current = null;
2136
+ }
2137
+ }, []);
2138
+ const cancel = React.useCallback(() => {
2139
+ const c = controller.current;
2140
+ if (!c) return;
2141
+ c.abort();
2142
+ controller.current = null;
2143
+ setState({ phase: "cancelled" });
2144
+ }, []);
2145
+ const dismiss = React.useCallback(() => {
2146
+ if (!controller.current) setState({ phase: "idle" });
2147
+ }, []);
2148
+ React.useEffect(() => () => {
2149
+ controller.current?.abort();
2150
+ controller.current = null;
2151
+ }, []);
2152
+ return {
2153
+ ...state,
2154
+ start,
2155
+ cancel,
2156
+ dismiss
2157
+ };
2158
+ }
1661
2159
  // src/components/job-status.tsx
1662
2160
  var Spinner = ({ className, ...props }) => /* @__PURE__ */ jsx(LoaderCircle, {
1663
2161
  ...props,
1664
2162
  className: cn(className, "motion-safe:animate-spin")
1665
2163
  });
1666
2164
  /** 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 = failed ? {
2165
+ function JobStatus({ label, running, words, summary, current, total, failures = [], failed = false, failuresLabel = "Failures", cancelled = false, onCancel, cancelLabel = "Cancel", onDismiss, className }) {
2166
+ const ended = cancelled ? {
2167
+ tone: "neutral",
2168
+ icon: Ban,
2169
+ word: words.cancelled ?? "Cancelled"
2170
+ } : failed ? {
1669
2171
  tone: "danger",
1670
2172
  icon: CircleAlert,
1671
2173
  word: words.failed
@@ -1700,14 +2202,28 @@ function JobStatus({ label, running, words, summary, current, total, failures =
1700
2202
  children: [
1701
2203
  /* @__PURE__ */ jsxs("div", {
1702
2204
  className: "flex flex-wrap items-center gap-x-3 gap-y-1",
1703
- children: [/* @__PURE__ */ jsx(Status, {
1704
- tone,
1705
- icon,
1706
- children: word
1707
- }), /* @__PURE__ */ jsx("p", {
1708
- className: "min-w-0 flex-1 type-body-sm text-foreground",
1709
- children: summary
1710
- })]
2205
+ children: [
2206
+ /* @__PURE__ */ jsx(Status, {
2207
+ tone,
2208
+ icon,
2209
+ children: word
2210
+ }),
2211
+ /* @__PURE__ */ jsx("p", {
2212
+ className: "min-w-0 flex-1 type-body-sm text-foreground",
2213
+ children: summary
2214
+ }),
2215
+ running && onCancel && /* @__PURE__ */ jsx(Button, {
2216
+ size: "sm",
2217
+ onPress: onCancel,
2218
+ children: cancelLabel
2219
+ }),
2220
+ !running && onDismiss && /* @__PURE__ */ jsx(Button, {
2221
+ size: "sm",
2222
+ variant: "ghost",
2223
+ onPress: onDismiss,
2224
+ children: "Dismiss"
2225
+ })
2226
+ ]
1711
2227
  }),
1712
2228
  bar && /* @__PURE__ */ jsx("div", {
1713
2229
  role: "progressbar",
@@ -3640,6 +4156,6 @@ function useJob({ isRunning, every = 2e3, invalidates = [], describeError, ...op
3640
4156
  poll
3641
4157
  };
3642
4158
  }
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 };
4159
+ export { ActiveList, Alert, AlertDialog, AppShell, AsyncButton, Breadcrumb, BulkBar, Button, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGroup, ColorField, 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, NumberField, PageHeader, Popover, RowAction, SelectableGrid, SideNav, Skeleton, Slider, 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
4160
 
3645
4161
  //# sourceMappingURL=index.js.map