strata-react 0.1.13 → 0.1.15

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 { _ as HttpError, a as useLoad, b as cn, c as ThemeProvider, d as useSystemColorScheme, f as ChoiceGroup, g as Textarea, h as NativeSelect, i as toLoad, l as colorSchemeScript, m as Input, n as createQueryClient, o as COLOR_SCHEME_STORAGE_KEY, p as Field, r as fetchJson, s as ColorSchemeChoice, t as StrataQueryProvider, u as useColorScheme, v as describeActionError, x as typeSteps, y as describeHttpError } from "./query-CkOrBm3w.js";
1
+ import { S 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, x as cn, y as describeActionError } from "./query-BlPgaCBG.js";
2
2
  import * as React from "react";
3
3
  import { Slot } from "@radix-ui/react-slot";
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, CircleAlert, LoaderCircle, RotateCcw, X } from "lucide-react";
6
+ import { ArrowDown, ArrowUp, ArrowUpDown, ArrowUpRight, Check, CircleAlert, History, ImageOff, LoaderCircle, RotateCcw, X } from "lucide-react";
7
7
  import { Link, NavLink, useSearchParams } from "react-router";
8
8
  import { flexRender, getCoreRowModel, getSortedRowModel, useReactTable } from "@tanstack/react-table";
9
9
  import { useVirtualizer } from "@tanstack/react-virtual";
@@ -180,10 +180,12 @@ function RowAction({ label, subject, icon: Icon, variant = "ghost", size = "sm",
180
180
  /** A native checkbox and its label as one target. `label` is required; `hideLabel` keeps it as the accessible name only. */
181
181
  function Checkbox({ label, hideLabel = false, detail, checked, onCheckedChange, className, disabled, ...props }) {
182
182
  const ref = React.useRef(null);
183
+ const shift = useShiftNote();
183
184
  React.useEffect(() => {
184
185
  if (ref.current) ref.current.indeterminate = checked === "mixed";
185
186
  }, [checked]);
186
187
  return /* @__PURE__ */ jsxs("label", {
188
+ ...shift.handlers,
187
189
  className: cn("inline-flex min-h-6 min-w-6 items-start gap-3", hideLabel && "items-center justify-center", disabled ? "cursor-not-allowed opacity-50" : "cursor-pointer", className),
188
190
  children: [/* @__PURE__ */ jsx("input", {
189
191
  ref,
@@ -192,7 +194,7 @@ function Checkbox({ label, hideLabel = false, detail, checked, onCheckedChange,
192
194
  "aria-checked": checked === "mixed" ? "mixed" : void 0,
193
195
  "aria-label": hideLabel ? label : void 0,
194
196
  disabled,
195
- onChange: (e) => onCheckedChange(e.target.checked),
197
+ onChange: (e) => onCheckedChange(e.target.checked, shift.take()),
196
198
  className: cn("size-4.5 shrink-0 accent-primary", !hideLabel && "mt-0.5", disabled ? "cursor-not-allowed" : "cursor-pointer"),
197
199
  ...props
198
200
  }), !hideLabel && /* @__PURE__ */ jsxs("span", {
@@ -207,6 +209,21 @@ function Checkbox({ label, hideLabel = false, detail, checked, onCheckedChange,
207
209
  })]
208
210
  });
209
211
  }
212
+ /** Notes Shift on the press that leads to a checkbox's change event, which has no modifier keys of its own. */
213
+ function useShiftNote() {
214
+ const held = React.useRef(false);
215
+ return React.useMemo(() => ({
216
+ handlers: {
217
+ onMouseDown: (e) => void (held.current = e.shiftKey),
218
+ onKeyDown: (e) => void (held.current = e.shiftKey)
219
+ },
220
+ take: () => {
221
+ const shiftKey = held.current;
222
+ held.current = false;
223
+ return { shiftKey };
224
+ }
225
+ }), []);
226
+ }
210
227
  // src/components/async-button.tsx
211
228
  /** One button through idle, pending, done and error, with the label changing in place and its width fixed by the longest label. The outcome is announced politely, with the error's own words when `error` is given. */
212
229
  function AsyncButton({ phase, labels, error, disabled, ...props }) {
@@ -610,8 +627,8 @@ function LinkCardList({ label, children, className }) {
610
627
  });
611
628
  }
612
629
  // src/components/data-view.tsx
613
- /** Every view of remote data: renders `skeleton` while loading, an alert with Try again on error, `empty` when `isEmpty`, else `children(data)`. The skeleton and empty state are required. */
614
- function DataView({ state, isEmpty, skeleton, empty, children, className }) {
630
+ /** Every view of remote data: renders `skeleton` while loading, an alert with Try again on error, `empty` when `isEmpty`, else `children(data)`, under a `StaleNotice` when a refresh failed. The skeleton and empty state are required. */
631
+ function DataView({ state, isEmpty, skeleton, empty, children, staleNotice = (stale) => /* @__PURE__ */ jsx(StaleNotice, { stale }), className }) {
615
632
  return /* @__PURE__ */ jsxs("div", {
616
633
  className: cn("min-w-0", className),
617
634
  "aria-busy": state.status === "loading" || void 0,
@@ -636,7 +653,38 @@ function DataView({ state, isEmpty, skeleton, empty, children, className }) {
636
653
  })
637
654
  ]
638
655
  }),
639
- state.status === "ready" && (isEmpty(state.data) ? empty : children(state.data))
656
+ state.status === "ready" && /* @__PURE__ */ jsxs(Fragment, { children: [state.stale && staleNotice(state.stale), isEmpty(state.data) ? empty : children(state.data)] })
657
+ ]
658
+ });
659
+ }
660
+ /** When `readAt` was, for a person: the clock time today, else the weekday and time. */
661
+ function readTime(readAt, now = /* @__PURE__ */ new Date()) {
662
+ return readAt.toDateString() === now.toDateString() ? format.clock.format(readAt) : format.shortDay.format(readAt);
663
+ }
664
+ /** The notice over data whose refresh failed: what happened, how old the data shown is, and Try again. A polite status, not an alert: nothing was lost. */
665
+ function StaleNotice({ stale, shown, className }) {
666
+ return /* @__PURE__ */ jsxs("div", {
667
+ role: "status",
668
+ className: cn("mb-4 flex flex-wrap items-start gap-3 rounded-surface bg-warning-subtle p-3 text-warning", className),
669
+ children: [
670
+ /* @__PURE__ */ jsx(History, {
671
+ "aria-hidden": true,
672
+ className: "mt-0.5 size-4 shrink-0"
673
+ }),
674
+ /* @__PURE__ */ jsxs("p", {
675
+ className: "min-w-0 flex-1 type-body-sm",
676
+ children: [
677
+ stale.message,
678
+ " ",
679
+ shown ? shown(readTime(stale.readAt)) : `Showing data from ${readTime(stale.readAt)}.`
680
+ ]
681
+ }),
682
+ /* @__PURE__ */ jsxs(Button, {
683
+ size: "sm",
684
+ onClick: stale.retry,
685
+ disabled: stale.retrying,
686
+ children: [/* @__PURE__ */ jsx(RotateCcw, { "aria-hidden": true }), stale.retrying ? "Trying again…" : "Try again"]
687
+ })
640
688
  ]
641
689
  });
642
690
  }
@@ -667,6 +715,247 @@ function Skeleton({ className }) {
667
715
  className: cn("rounded-control bg-muted motion-safe:animate-pulse", className)
668
716
  });
669
717
  }
718
+ // src/lib/in-view.ts
719
+ /**
720
+ * Whether an element is within `rootMargin` of its scroll region (the nearest
721
+ * `[data-strata-scroll]` ancestor, else the viewport). Returns a callback ref, so it follows the
722
+ * element as it mounts and unmounts.
723
+ */
724
+ function useInView({ active = true, rootMargin = "0px", once = false, unsupported = false } = {}) {
725
+ const [inView, setInView] = React.useState(false);
726
+ const [el, setEl] = React.useState(null);
727
+ const seen = once && inView;
728
+ React.useEffect(() => {
729
+ if (seen) return;
730
+ if (!active || !el) {
731
+ setInView(false);
732
+ return;
733
+ }
734
+ if (typeof IntersectionObserver === "undefined") {
735
+ setInView(unsupported);
736
+ return;
737
+ }
738
+ const root = el.parentElement?.closest("[data-strata-scroll]") ?? null;
739
+ const observer = new IntersectionObserver((entries) => setInView(entries[entries.length - 1].isIntersecting), {
740
+ root,
741
+ rootMargin
742
+ });
743
+ observer.observe(el);
744
+ return () => observer.disconnect();
745
+ }, [
746
+ active,
747
+ el,
748
+ rootMargin,
749
+ seen,
750
+ unsupported
751
+ ]);
752
+ return {
753
+ ref: setEl,
754
+ inView
755
+ };
756
+ }
757
+ // src/components/thumbnail.tsx
758
+ var ratio = (aspect) => typeof aspect === "number" ? String(aspect) : aspect.replace("/", " / ");
759
+ /** A box of fixed aspect ratio for a remote image: a skeleton until it loads, the `missing` words if it cannot, and a request only when it nears the screen. `alt` and `missing` are required. */
760
+ function Thumbnail({ src, alt, missing, aspect = 1, fit = "cover", srcSet, sizes, eager = false, rootMargin = "200px", className }) {
761
+ const request = src ? `${src} ${srcSet ?? ""}` : null;
762
+ const [result, setResult] = React.useState(null);
763
+ const phase = !request ? "missing" : result?.request === request ? result.ok ? "loaded" : "missing" : "loading";
764
+ const near = useInView({
765
+ active: !eager && !!src,
766
+ rootMargin,
767
+ once: true,
768
+ unsupported: true
769
+ });
770
+ const requested = eager || near.inView;
771
+ return /* @__PURE__ */ jsxs("div", {
772
+ ref: near.ref,
773
+ className: cn("relative overflow-hidden rounded-control bg-muted", className),
774
+ style: { aspectRatio: ratio(aspect) },
775
+ "aria-busy": phase === "loading" || void 0,
776
+ children: [
777
+ phase === "loading" && /* @__PURE__ */ jsx(Skeleton, { className: "absolute inset-0" }),
778
+ src && request && phase !== "missing" && requested && /* @__PURE__ */ jsx("img", {
779
+ src,
780
+ srcSet,
781
+ sizes,
782
+ alt,
783
+ decoding: "async",
784
+ onLoad: () => setResult({
785
+ request,
786
+ ok: true
787
+ }),
788
+ onError: () => setResult({
789
+ request,
790
+ ok: false
791
+ }),
792
+ className: cn("absolute inset-0 size-full", fit === "cover" ? "object-cover" : "object-contain", phase === "loading" && "opacity-0")
793
+ }, request),
794
+ phase === "missing" && /* @__PURE__ */ jsxs("div", {
795
+ role: "img",
796
+ "aria-label": alt ? `${alt}: ${missing}` : missing,
797
+ className: "absolute inset-0 grid content-center justify-items-center gap-0.5 p-1 text-center text-muted-foreground",
798
+ children: [/* @__PURE__ */ jsx(ImageOff, {
799
+ "aria-hidden": true,
800
+ className: "size-4 shrink-0"
801
+ }), /* @__PURE__ */ jsx("span", {
802
+ className: "type-caption text-balance",
803
+ children: missing
804
+ })]
805
+ })
806
+ ]
807
+ });
808
+ }
809
+ /** The loading shape of a `Thumbnail`, for a `DataView` skeleton: the same box and aspect ratio, so nothing moves when the list arrives. */
810
+ function ThumbnailSkeleton({ aspect = 1, className }) {
811
+ return /* @__PURE__ */ jsx("div", {
812
+ "aria-hidden": true,
813
+ className: cn("relative overflow-hidden rounded-control bg-muted", className),
814
+ style: { aspectRatio: ratio(aspect) },
815
+ children: /* @__PURE__ */ jsx(Skeleton, { className: "absolute inset-0" })
816
+ });
817
+ }
818
+ // src/components/selection.tsx
819
+ function reconcile(prev, rows, keys, initial) {
820
+ const present = new Set(keys);
821
+ const raw = new Set([...prev.raw].filter((k) => present.has(k)));
822
+ const seen = new Set(prev.seen);
823
+ rows.forEach((row, i) => {
824
+ const key = keys[i];
825
+ if (seen.has(key)) return;
826
+ seen.add(key);
827
+ if (initial(row, key)) raw.add(key);
828
+ });
829
+ return {
830
+ keys,
831
+ seen,
832
+ raw
833
+ };
834
+ }
835
+ var sameKeys = (a, b) => a.length === b.length && a.every((k, i) => k === b[i]);
836
+ /**
837
+ * Chosen row keys, pruned to the rows that exist, and the calls that change them. Spread into
838
+ * `DataTable`'s or `SelectableGrid`'s `selection` with a `rowLabel`. `initial` (keys, or a test on
839
+ * the row) chooses each row the first time it appears, so a selection seeded from data that loads
840
+ * later, or a next page, still starts right.
841
+ */
842
+ function useSelection(rows, rowKey, initial = []) {
843
+ const initialRef = React.useRef(initial);
844
+ initialRef.current = initial;
845
+ const initialKeys = React.useRef(void 0);
846
+ const test = (row, key) => {
847
+ const init = initialRef.current;
848
+ if (typeof init === "function") return init(row);
849
+ if (initialKeys.current?.source !== init) initialKeys.current = {
850
+ source: init,
851
+ keys: new Set(init)
852
+ };
853
+ return initialKeys.current.keys.has(key);
854
+ };
855
+ const keys = rows.map(rowKey);
856
+ const [state, setState] = React.useState(() => reconcile({
857
+ keys: [],
858
+ seen: /* @__PURE__ */ new Set(),
859
+ raw: /* @__PURE__ */ new Set()
860
+ }, rows, keys, test));
861
+ let current = state;
862
+ if (!sameKeys(state.keys, keys)) {
863
+ current = reconcile(state, rows, keys, test);
864
+ setState(current);
865
+ }
866
+ const selected = current.raw;
867
+ const selectedRows = React.useMemo(() => rows.filter((r) => selected.has(rowKey(r))), [rows, selected]);
868
+ const onChange = React.useCallback((next) => setState((s) => {
869
+ const present = new Set(s.keys);
870
+ return {
871
+ ...s,
872
+ raw: new Set([...next].filter((k) => present.has(k)))
873
+ };
874
+ }), []);
875
+ const clear = React.useCallback(() => setState((s) => ({
876
+ ...s,
877
+ raw: /* @__PURE__ */ new Set()
878
+ })), []);
879
+ return {
880
+ selected,
881
+ selectedRows,
882
+ count: selected.size,
883
+ onChange,
884
+ clear
885
+ };
886
+ }
887
+ /**
888
+ * Selecting rows of a surface in the order it shows them: one row, a range with Shift, and all
889
+ * shown. Shared by `DataTable` and `SelectableGrid`, so a range and select-all behave the same on
890
+ * both. `rows` are in display order (after sorting) and include rows a virtualised surface has not
891
+ * rendered.
892
+ *
893
+ * A range runs from the last row clicked (the anchor) to this one, over the selectable rows
894
+ * between, and sets them all to this row's new state, as Gmail and Finder do: Shift-clicking an
895
+ * unchosen row chooses the run, Shift-clicking a chosen one clears it. Every click moves the
896
+ * anchor. An anchor that has left the rows (filtered, removed) makes the next Shift-click a plain
897
+ * one.
898
+ * @internal
899
+ */
900
+ function useSelectRows(rows, rowKey, selection) {
901
+ const anchor = React.useRef(void 0);
902
+ const keys = selection ? rows.filter((r) => selection.isSelectable?.(r) ?? true).map(rowKey) : [];
903
+ const chosen = selection ? keys.filter((k) => selection.selected.has(k)).length : 0;
904
+ const allChecked = chosen === 0 ? false : chosen === keys.length ? true : "mixed";
905
+ const toggle = (key, on, { shiftKey }) => {
906
+ if (!selection) return;
907
+ const next = new Set(selection.selected);
908
+ const from = shiftKey && anchor.current !== void 0 ? keys.indexOf(anchor.current) : -1;
909
+ const to = keys.indexOf(key);
910
+ if (from >= 0 && to >= 0) {
911
+ const [a, b] = from < to ? [from, to] : [to, from];
912
+ for (const k of keys.slice(a, b + 1)) if (on) next.add(k);
913
+ else next.delete(k);
914
+ } else if (on) next.add(key);
915
+ else next.delete(key);
916
+ anchor.current = key;
917
+ selection.onChange(next);
918
+ };
919
+ const toggleAll = () => {
920
+ if (!selection) return;
921
+ const next = new Set(selection.selected);
922
+ if (allChecked === false) keys.forEach((k) => next.add(k));
923
+ else keys.forEach((k) => next.delete(k));
924
+ selection.onChange(next);
925
+ };
926
+ return {
927
+ toggle,
928
+ all: {
929
+ checked: allChecked,
930
+ toggle: toggleAll,
931
+ disabled: keys.length === 0
932
+ }
933
+ };
934
+ }
935
+ /** The bar for a selection: a polite live count ("2 bookings selected"), the bulk actions, and Clear selection. Renders only the live region while nothing is chosen. */
936
+ function BulkBar({ count, noun, onClear, children, format: format$1 = format, className }) {
937
+ const [one, many] = typeof noun === "string" ? [noun, `${noun}s`] : noun;
938
+ const label = `${format$1.count(count, one, many)} selected`;
939
+ return /* @__PURE__ */ jsxs("div", {
940
+ className: cn(count > 0 && "flex flex-wrap items-center gap-x-4 gap-y-2 rounded-surface bg-surface-sunken py-1.5 pr-1.5 pl-3", className),
941
+ children: [/* @__PURE__ */ jsx("p", {
942
+ "aria-live": "polite",
943
+ className: count > 0 ? "type-label tabular-nums" : "sr-only",
944
+ children: count > 0 ? label : `No ${many} selected`
945
+ }), count > 0 && /* @__PURE__ */ jsxs("div", {
946
+ role: "group",
947
+ "aria-label": `Actions for the selected ${many}`,
948
+ className: "flex flex-1 flex-wrap items-center gap-2",
949
+ children: [children, /* @__PURE__ */ jsxs(Button, {
950
+ size: "sm",
951
+ variant: "ghost",
952
+ className: "ml-auto",
953
+ onClick: onClear,
954
+ children: [/* @__PURE__ */ jsx(X, { "aria-hidden": true }), "Clear selection"]
955
+ })]
956
+ })]
957
+ });
958
+ }
670
959
  // src/components/data-table.tsx
671
960
  function useLocalSort(initial) {
672
961
  const [sort, setSort] = React.useState(initial);
@@ -713,31 +1002,7 @@ function UrlSortedTable(props) {
713
1002
  sortState: useUrlSort(props.sortParam, props.initialSort)
714
1003
  });
715
1004
  }
716
- function useSelectAll(rows, rowKey, selection) {
717
- return React.useMemo(() => {
718
- if (!selection) return void 0;
719
- const keys = rows.filter((r) => selection.isSelectable?.(r) ?? true).map(rowKey);
720
- const chosen = keys.filter((k) => selection.selected.has(k)).length;
721
- const checked = chosen === 0 ? false : chosen === keys.length ? true : "mixed";
722
- const toggle = () => {
723
- const next = new Set(selection.selected);
724
- if (checked === false) keys.forEach((k) => next.add(k));
725
- else keys.forEach((k) => next.delete(k));
726
- selection.onChange(next);
727
- };
728
- return {
729
- checked,
730
- toggle,
731
- disabled: keys.length === 0
732
- };
733
- }, [
734
- rows,
735
- rowKey,
736
- selection
737
- ]);
738
- }
739
1005
  function Table({ caption, columns, rows, rowKey, sortState: [sort, setSort], virtualizeFrom = 100, maxHeight = 480, selection, className }) {
740
- const selectAll = useSelectAll(rows, rowKey, selection);
741
1006
  const defs = React.useMemo(() => columns.map((c) => ({
742
1007
  id: c.key,
743
1008
  accessorFn: (row) => row,
@@ -770,6 +1035,8 @@ function Table({ caption, columns, rows, rowKey, sortState: [sort, setSort], vir
770
1035
  dir: sort?.key === key && sort.dir === "ascending" ? "descending" : "ascending"
771
1036
  });
772
1037
  const modelRows = table.getRowModel().rows;
1038
+ const select = useSelectRows(React.useMemo(() => modelRows.map((r) => r.original), [modelRows]), rowKey, selection);
1039
+ const selectAll = selection ? select.all : void 0;
773
1040
  const virtual = modelRows.length >= virtualizeFrom;
774
1041
  const scroller = React.useRef(null);
775
1042
  const virtualizer = useVirtualizer({
@@ -857,12 +1124,7 @@ function Table({ caption, columns, rows, rowKey, sortState: [sort, setSort], vir
857
1124
  hideLabel: true,
858
1125
  checked: chosen,
859
1126
  disabled: !(selection.isSelectable?.(row.original) ?? true),
860
- onCheckedChange: (on) => {
861
- const next = new Set(selection.selected);
862
- if (on) next.add(row.id);
863
- else next.delete(row.id);
864
- selection.onChange(next);
865
- }
1127
+ onCheckedChange: (on, gesture) => select.toggle(row.id, on, gesture)
866
1128
  })
867
1129
  }), row.getVisibleCells().map((cell) => {
868
1130
  const meta = cell.column.columnDef.meta;
@@ -896,52 +1158,155 @@ function TableSkeleton({ rows = 4, columns = 5 }) {
896
1158
  }, r))]
897
1159
  });
898
1160
  }
899
- // src/components/selection.tsx
900
- /** Chosen row keys, pruned to the rows that exist, and the calls that change them. Spread into `DataTable`'s `selection` with a `rowLabel`. */
901
- function useSelection(rows, rowKey, initial = []) {
902
- const [raw, setRaw] = React.useState(() => new Set(initial));
903
- const selected = React.useMemo(() => {
904
- const present = new Set(rows.map(rowKey));
905
- return new Set([...raw].filter((k) => present.has(k)));
906
- }, [raw, rows]);
907
- const selectedRows = React.useMemo(() => rows.filter((r) => selected.has(rowKey(r))), [rows, selected]);
908
- React.useEffect(() => {
909
- if (selected.size !== raw.size) setRaw(selected);
910
- }, [selected, raw]);
911
- const onChange = React.useCallback((next) => setRaw(next), []);
912
- const clear = React.useCallback(() => setRaw(/* @__PURE__ */ new Set()), []);
913
- return {
914
- selected,
915
- selectedRows,
916
- count: selected.size,
917
- onChange,
918
- clear
1161
+ // src/components/selectable-grid.tsx
1162
+ var minWidth = {
1163
+ sm: 96,
1164
+ md: 144,
1165
+ lg: 192
1166
+ };
1167
+ var aspectClass = {
1168
+ square: "aspect-square",
1169
+ portrait: "aspect-3/4",
1170
+ landscape: "aspect-4/3"
1171
+ };
1172
+ var aspectRatio = {
1173
+ square: 1,
1174
+ portrait: 4 / 3,
1175
+ landscape: 3 / 4
1176
+ };
1177
+ var GAP = 12;
1178
+ var TILE_CHROME = 40;
1179
+ /** A grid of pictures to choose from: each tile one labelled target, "Select all shown", Shift-click ranges, virtualised from `virtualizeFrom` tiles. Pair with `useSelection` and a `BulkBar`. */
1180
+ function SelectableGrid({ label, rows, rowKey, renderImage, detail, selection, aspect = "square", tileSize = "md", virtualizeFrom = 100, maxHeight = 480, className }) {
1181
+ const select = useSelectRows(rows, rowKey, selection);
1182
+ const virtual = rows.length >= virtualizeFrom;
1183
+ const tile = (row, index) => {
1184
+ const key = rowKey(row);
1185
+ return /* @__PURE__ */ jsx(Tile, {
1186
+ name: `Select ${selection.rowLabel(row)}`,
1187
+ chosen: selection.selected.has(key),
1188
+ disabled: !(selection.isSelectable?.(row) ?? true),
1189
+ onChange: (on, gesture) => select.toggle(key, on, gesture),
1190
+ aspect,
1191
+ image: renderImage(row),
1192
+ detail: detail?.(row),
1193
+ index
1194
+ });
919
1195
  };
920
- }
921
- /** The bar for a selection: a polite live count ("2 bookings selected"), the bulk actions, and Clear selection. Renders only the live region while nothing is chosen. */
922
- function BulkBar({ count, noun, onClear, children, format: format$1 = format, className }) {
923
- const [one, many] = typeof noun === "string" ? [noun, `${noun}s`] : noun;
924
- const label = `${format$1.count(count, one, many)} selected`;
925
1196
  return /* @__PURE__ */ jsxs("div", {
926
- className: cn(count > 0 && "flex flex-wrap items-center gap-x-4 gap-y-2 rounded-surface bg-surface-sunken py-1.5 pr-1.5 pl-3", className),
927
- children: [/* @__PURE__ */ jsx("p", {
928
- "aria-live": "polite",
929
- className: count > 0 ? "type-label tabular-nums" : "sr-only",
930
- children: count > 0 ? label : `No ${many} selected`
931
- }), count > 0 && /* @__PURE__ */ jsxs("div", {
932
- role: "group",
933
- "aria-label": `Actions for the selected ${many}`,
934
- className: "flex flex-1 flex-wrap items-center gap-2",
935
- children: [children, /* @__PURE__ */ jsxs(Button, {
936
- size: "sm",
937
- variant: "ghost",
938
- className: "ml-auto",
939
- onClick: onClear,
940
- children: [/* @__PURE__ */ jsx(X, { "aria-hidden": true }), "Clear selection"]
941
- })]
1197
+ className: cn("grid min-w-0 gap-3", className),
1198
+ children: [/* @__PURE__ */ jsx(Checkbox, {
1199
+ className: "justify-self-start",
1200
+ label: "Select all shown",
1201
+ checked: select.all.checked,
1202
+ disabled: select.all.disabled,
1203
+ onCheckedChange: select.all.toggle
1204
+ }), virtual ? /* @__PURE__ */ jsx(VirtualTiles, {
1205
+ label,
1206
+ rows,
1207
+ rowKey,
1208
+ tile,
1209
+ aspect,
1210
+ tileSize,
1211
+ maxHeight
1212
+ }) : /* @__PURE__ */ jsx("ul", {
1213
+ "aria-label": label,
1214
+ className: "grid gap-3",
1215
+ style: { gridTemplateColumns: `repeat(auto-fill, minmax(min(${minWidth[tileSize]}px, 100%), 1fr))` },
1216
+ children: rows.map((row, i) => /* @__PURE__ */ jsx("li", { children: tile(row, i) }, rowKey(row)))
942
1217
  })]
943
1218
  });
944
1219
  }
1220
+ function VirtualTiles({ label, rows, rowKey, tile, aspect, tileSize, maxHeight }) {
1221
+ const scroller = React.useRef(null);
1222
+ const [width, setWidth] = React.useState(0);
1223
+ React.useLayoutEffect(() => {
1224
+ const el = scroller.current;
1225
+ if (!el || typeof ResizeObserver === "undefined") return;
1226
+ const observer = new ResizeObserver(([entry]) => setWidth(entry.contentRect.width));
1227
+ observer.observe(el);
1228
+ return () => observer.disconnect();
1229
+ }, []);
1230
+ const min = minWidth[tileSize];
1231
+ const columns = Math.max(1, Math.floor((width + GAP) / (min + GAP)));
1232
+ const tileWidth = width > 0 ? (width - GAP * (columns - 1)) / columns : min;
1233
+ const lines = Math.ceil(rows.length / columns);
1234
+ const virtualizer = useVirtualizer({
1235
+ count: lines,
1236
+ getScrollElement: () => scroller.current,
1237
+ estimateSize: () => Math.round(tileWidth * aspectRatio[aspect]) + TILE_CHROME + GAP,
1238
+ overscan: 3,
1239
+ getItemKey: (i) => `${columns}:${i}`,
1240
+ initialRect: {
1241
+ width: 0,
1242
+ height: maxHeight
1243
+ }
1244
+ });
1245
+ const items = virtualizer.getVirtualItems();
1246
+ return /* @__PURE__ */ jsx("div", {
1247
+ ref: scroller,
1248
+ role: "region",
1249
+ "aria-label": label,
1250
+ tabIndex: 0,
1251
+ "data-strata-scroll": "",
1252
+ className: "min-w-0 overflow-y-auto",
1253
+ style: { height: maxHeight },
1254
+ children: /* @__PURE__ */ jsx("div", {
1255
+ role: "list",
1256
+ "aria-label": label,
1257
+ className: "relative w-full",
1258
+ style: { height: virtualizer.getTotalSize() },
1259
+ children: items.map((v) => {
1260
+ const start = v.index * columns;
1261
+ return /* @__PURE__ */ jsx("div", {
1262
+ ref: virtualizer.measureElement,
1263
+ "data-index": v.index,
1264
+ role: "none",
1265
+ className: "absolute inset-x-0 top-0 grid gap-3 pb-3",
1266
+ style: {
1267
+ translate: `0 ${v.start}px`,
1268
+ gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))`
1269
+ },
1270
+ children: rows.slice(start, start + columns).map((row, i) => /* @__PURE__ */ jsx("div", {
1271
+ role: "listitem",
1272
+ "aria-setsize": rows.length,
1273
+ "aria-posinset": start + i + 1,
1274
+ children: tile(row, start + i)
1275
+ }, rowKey(row)))
1276
+ }, v.key);
1277
+ })
1278
+ })
1279
+ });
1280
+ }
1281
+ function Tile({ name, chosen, disabled, onChange, aspect, image, detail, index }) {
1282
+ const shift = useShiftNote();
1283
+ return /* @__PURE__ */ jsxs("label", {
1284
+ ...shift.handlers,
1285
+ "data-index": index,
1286
+ className: cn("relative grid min-w-0 gap-1.5 rounded-surface border border-transparent p-1.5 select-none transition-state", chosen && "border-primary bg-surface-sunken", disabled ? "cursor-not-allowed opacity-50" : "cursor-pointer hover:bg-surface-sunken"),
1287
+ children: [
1288
+ /* @__PURE__ */ jsx("span", {
1289
+ className: cn("block overflow-hidden rounded-control bg-muted *:size-full *:object-cover", aspectClass[aspect]),
1290
+ children: image
1291
+ }),
1292
+ /* @__PURE__ */ jsx("span", {
1293
+ className: "absolute top-3 left-3 grid size-7 place-items-center rounded-control bg-background",
1294
+ children: /* @__PURE__ */ jsx("input", {
1295
+ type: "checkbox",
1296
+ "aria-label": name,
1297
+ checked: chosen,
1298
+ disabled,
1299
+ onChange: (e) => onChange(e.target.checked, shift.take()),
1300
+ className: cn("size-4.5 accent-primary", disabled ? "cursor-not-allowed" : "cursor-pointer")
1301
+ })
1302
+ }),
1303
+ detail != null && /* @__PURE__ */ jsx("span", {
1304
+ className: "truncate type-body-sm text-muted-foreground",
1305
+ children: detail
1306
+ })
1307
+ ]
1308
+ });
1309
+ }
945
1310
  // src/components/virtual-list.tsx
946
1311
  /** A list that renders only its visible rows (TanStack Virtual) from `virtualizeFrom` items, keeping list semantics for screen readers. */
947
1312
  function VirtualList({ label, items, itemKey, children, estimateSize = 48, height = 480, virtualizeFrom = 100, bounded = false, footer, className }) {
@@ -1003,7 +1368,10 @@ function InfiniteList({ state, label, children, skeleton, empty, moreLabel, more
1003
1368
  const { more, itemKey } = state;
1004
1369
  const held = state.status === "ready" ? state.data.length : 0;
1005
1370
  const box = React.useRef(null);
1006
- const near = useNearEnd(state.status === "ready" && more.hasMore, rootMargin);
1371
+ const near = useInView({
1372
+ active: state.status === "ready" && more.hasMore,
1373
+ rootMargin
1374
+ });
1007
1375
  const { hasMore, loadingMore, error, loadMore } = more;
1008
1376
  React.useEffect(() => {
1009
1377
  if (state.status !== "ready" || !hasMore || loadingMore || error) return;
@@ -1108,36 +1476,6 @@ function InfiniteList({ state, label, children, skeleton, empty, moreLabel, more
1108
1476
  })
1109
1477
  });
1110
1478
  }
1111
- /**
1112
- * Watches a sentinel element and reports whether it is within `rootMargin` of its scroll region
1113
- * (the nearest `[data-strata-scroll]` ancestor, else the viewport). A callback ref, so it follows
1114
- * the sentinel as it mounts and unmounts.
1115
- */
1116
- function useNearEnd(active, rootMargin) {
1117
- const [inView, setInView] = React.useState(false);
1118
- const [el, setEl] = React.useState(null);
1119
- React.useEffect(() => {
1120
- if (!active || !el || typeof IntersectionObserver === "undefined") {
1121
- setInView(false);
1122
- return;
1123
- }
1124
- const root = el.parentElement?.closest("[data-strata-scroll]") ?? null;
1125
- const observer = new IntersectionObserver((entries) => setInView(entries[entries.length - 1].isIntersecting), {
1126
- root,
1127
- rootMargin
1128
- });
1129
- observer.observe(el);
1130
- return () => observer.disconnect();
1131
- }, [
1132
- active,
1133
- el,
1134
- rootMargin
1135
- ]);
1136
- return {
1137
- ref: setEl,
1138
- inView
1139
- };
1140
- }
1141
1479
  // src/components/line-chart.tsx
1142
1480
  function useWidth() {
1143
1481
  const ref = React.useRef(null);
@@ -2075,11 +2413,15 @@ function useInfiniteLoad({ queryKey, queryFn, items, itemKey, hasMore, cursorAft
2075
2413
  dismiss,
2076
2414
  restore
2077
2415
  };
2078
- if (list) return {
2079
- status: "ready",
2080
- data: list,
2081
- ...extra
2082
- };
2416
+ if (list) {
2417
+ const stale = query.isRefetchError ? staleOf(query, describeError) : void 0;
2418
+ return {
2419
+ status: "ready",
2420
+ data: list,
2421
+ ...stale && { stale },
2422
+ ...extra
2423
+ };
2424
+ }
2083
2425
  if (query.status === "error") return {
2084
2426
  status: "error",
2085
2427
  message: describeError(query.error),
@@ -2120,6 +2462,6 @@ function nextAfter(pages, items, itemKey, hidden) {
2120
2462
  if (held.length === 0 || pages.length > 1 && !lastPageAddedAny) return last;
2121
2463
  return held[held.length - 1];
2122
2464
  }
2123
- export { ActiveList, AppShell, AsyncButton, Breadcrumb, BulkBar, Button, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGroup, ColorSchemeChoice, CompositionBar, DataTable, DataView, Done, EmptyState, Field, HttpError, IconButton, InfiniteList, Input, KeysLegend, LineChart, LinkCard, LinkCardList, Meter, Metric, MetricStrip, NBSP, NativeSelect, PageHeader, RowAction, SideNav, Skeleton, Status, StrataQueryProvider, TableSkeleton, Tabs, Textarea, ThemeProvider, UndoBar, VirtualList, buttonVariants, cn, colorSchemeScript, createFormat, createQueryClient, crossedThreshold, describeActionError, describeHttpError, fetchJson, format, isTypingTarget, parseSort, serialiseSort, toDate, toLoad, typeSteps, useActiveItem, useAsyncAction, useColorScheme, useHotkeys, useInfiniteLoad, useLoad, useSelection, useSystemColorScheme, useUndoable };
2465
+ export { ActiveList, AppShell, AsyncButton, Breadcrumb, BulkBar, Button, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGroup, ColorSchemeChoice, CompositionBar, DataTable, DataView, Done, EmptyState, Field, HttpError, IconButton, InfiniteList, Input, KeysLegend, LineChart, LinkCard, LinkCardList, Meter, Metric, MetricStrip, NBSP, NativeSelect, PageHeader, RowAction, SelectableGrid, SideNav, Skeleton, StaleNotice, Status, StrataQueryProvider, TableSkeleton, Tabs, Textarea, ThemeProvider, Thumbnail, ThumbnailSkeleton, UndoBar, VirtualList, buttonVariants, cn, colorSchemeScript, createFormat, createQueryClient, crossedThreshold, describeActionError, describeHttpError, fetchJson, format, isTypingTarget, parseSort, serialiseSort, staleOf, toDate, toLoad, typeSteps, useActiveItem, useAsyncAction, useColorScheme, useHotkeys, useInfiniteLoad, useLoad, useSelection, useSystemColorScheme, useUndoable };
2124
2466
 
2125
2467
  //# sourceMappingURL=index.js.map