strata-react 0.1.14 → 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, ImageOff, 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
  }
@@ -767,6 +815,147 @@ function ThumbnailSkeleton({ aspect = 1, className }) {
767
815
  children: /* @__PURE__ */ jsx(Skeleton, { className: "absolute inset-0" })
768
816
  });
769
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
+ }
770
959
  // src/components/data-table.tsx
771
960
  function useLocalSort(initial) {
772
961
  const [sort, setSort] = React.useState(initial);
@@ -813,31 +1002,7 @@ function UrlSortedTable(props) {
813
1002
  sortState: useUrlSort(props.sortParam, props.initialSort)
814
1003
  });
815
1004
  }
816
- function useSelectAll(rows, rowKey, selection) {
817
- return React.useMemo(() => {
818
- if (!selection) return void 0;
819
- const keys = rows.filter((r) => selection.isSelectable?.(r) ?? true).map(rowKey);
820
- const chosen = keys.filter((k) => selection.selected.has(k)).length;
821
- const checked = chosen === 0 ? false : chosen === keys.length ? true : "mixed";
822
- const toggle = () => {
823
- const next = new Set(selection.selected);
824
- if (checked === false) keys.forEach((k) => next.add(k));
825
- else keys.forEach((k) => next.delete(k));
826
- selection.onChange(next);
827
- };
828
- return {
829
- checked,
830
- toggle,
831
- disabled: keys.length === 0
832
- };
833
- }, [
834
- rows,
835
- rowKey,
836
- selection
837
- ]);
838
- }
839
1005
  function Table({ caption, columns, rows, rowKey, sortState: [sort, setSort], virtualizeFrom = 100, maxHeight = 480, selection, className }) {
840
- const selectAll = useSelectAll(rows, rowKey, selection);
841
1006
  const defs = React.useMemo(() => columns.map((c) => ({
842
1007
  id: c.key,
843
1008
  accessorFn: (row) => row,
@@ -870,6 +1035,8 @@ function Table({ caption, columns, rows, rowKey, sortState: [sort, setSort], vir
870
1035
  dir: sort?.key === key && sort.dir === "ascending" ? "descending" : "ascending"
871
1036
  });
872
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;
873
1040
  const virtual = modelRows.length >= virtualizeFrom;
874
1041
  const scroller = React.useRef(null);
875
1042
  const virtualizer = useVirtualizer({
@@ -957,12 +1124,7 @@ function Table({ caption, columns, rows, rowKey, sortState: [sort, setSort], vir
957
1124
  hideLabel: true,
958
1125
  checked: chosen,
959
1126
  disabled: !(selection.isSelectable?.(row.original) ?? true),
960
- onCheckedChange: (on) => {
961
- const next = new Set(selection.selected);
962
- if (on) next.add(row.id);
963
- else next.delete(row.id);
964
- selection.onChange(next);
965
- }
1127
+ onCheckedChange: (on, gesture) => select.toggle(row.id, on, gesture)
966
1128
  })
967
1129
  }), row.getVisibleCells().map((cell) => {
968
1130
  const meta = cell.column.columnDef.meta;
@@ -996,52 +1158,155 @@ function TableSkeleton({ rows = 4, columns = 5 }) {
996
1158
  }, r))]
997
1159
  });
998
1160
  }
999
- // src/components/selection.tsx
1000
- /** Chosen row keys, pruned to the rows that exist, and the calls that change them. Spread into `DataTable`'s `selection` with a `rowLabel`. */
1001
- function useSelection(rows, rowKey, initial = []) {
1002
- const [raw, setRaw] = React.useState(() => new Set(initial));
1003
- const selected = React.useMemo(() => {
1004
- const present = new Set(rows.map(rowKey));
1005
- return new Set([...raw].filter((k) => present.has(k)));
1006
- }, [raw, rows]);
1007
- const selectedRows = React.useMemo(() => rows.filter((r) => selected.has(rowKey(r))), [rows, selected]);
1008
- React.useEffect(() => {
1009
- if (selected.size !== raw.size) setRaw(selected);
1010
- }, [selected, raw]);
1011
- const onChange = React.useCallback((next) => setRaw(next), []);
1012
- const clear = React.useCallback(() => setRaw(/* @__PURE__ */ new Set()), []);
1013
- return {
1014
- selected,
1015
- selectedRows,
1016
- count: selected.size,
1017
- onChange,
1018
- 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
+ });
1019
1195
  };
1020
- }
1021
- /** 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. */
1022
- function BulkBar({ count, noun, onClear, children, format: format$1 = format, className }) {
1023
- const [one, many] = typeof noun === "string" ? [noun, `${noun}s`] : noun;
1024
- const label = `${format$1.count(count, one, many)} selected`;
1025
1196
  return /* @__PURE__ */ jsxs("div", {
1026
- 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),
1027
- children: [/* @__PURE__ */ jsx("p", {
1028
- "aria-live": "polite",
1029
- className: count > 0 ? "type-label tabular-nums" : "sr-only",
1030
- children: count > 0 ? label : `No ${many} selected`
1031
- }), count > 0 && /* @__PURE__ */ jsxs("div", {
1032
- role: "group",
1033
- "aria-label": `Actions for the selected ${many}`,
1034
- className: "flex flex-1 flex-wrap items-center gap-2",
1035
- children: [children, /* @__PURE__ */ jsxs(Button, {
1036
- size: "sm",
1037
- variant: "ghost",
1038
- className: "ml-auto",
1039
- onClick: onClear,
1040
- children: [/* @__PURE__ */ jsx(X, { "aria-hidden": true }), "Clear selection"]
1041
- })]
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)))
1042
1217
  })]
1043
1218
  });
1044
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
+ }
1045
1310
  // src/components/virtual-list.tsx
1046
1311
  /** A list that renders only its visible rows (TanStack Virtual) from `virtualizeFrom` items, keeping list semantics for screen readers. */
1047
1312
  function VirtualList({ label, items, itemKey, children, estimateSize = 48, height = 480, virtualizeFrom = 100, bounded = false, footer, className }) {
@@ -2148,11 +2413,15 @@ function useInfiniteLoad({ queryKey, queryFn, items, itemKey, hasMore, cursorAft
2148
2413
  dismiss,
2149
2414
  restore
2150
2415
  };
2151
- if (list) return {
2152
- status: "ready",
2153
- data: list,
2154
- ...extra
2155
- };
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
+ }
2156
2425
  if (query.status === "error") return {
2157
2426
  status: "error",
2158
2427
  message: describeError(query.error),
@@ -2193,6 +2462,6 @@ function nextAfter(pages, items, itemKey, hidden) {
2193
2462
  if (held.length === 0 || pages.length > 1 && !lastPageAddedAny) return last;
2194
2463
  return held[held.length - 1];
2195
2464
  }
2196
- 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, Thumbnail, ThumbnailSkeleton, 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 };
2197
2466
 
2198
2467
  //# sourceMappingURL=index.js.map