strata-react 1.0.10 → 1.0.12

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,14 +1,13 @@
1
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-CXlmWmrY.js";
2
2
  import * as React from "react";
3
- import { Autocomplete, Button as Button$1, Checkbox as Checkbox$1, Dialog as Dialog$1, DialogTrigger, Disclosure as Disclosure$1, DisclosurePanel, DropIndicator, DropZone, FileTrigger, GridList, GridListItem, 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, useDragAndDrop, useFilter } from "react-aria-components";
3
+ import { Autocomplete, Button as Button$1, Cell, Checkbox as Checkbox$1, Collection, Column, Dialog as Dialog$1, DialogTrigger, Disclosure as Disclosure$1, DisclosurePanel, DropIndicator, DropZone, FileTrigger, GridLayout, GridList, GridListItem, Header, Heading, I18nProvider, Input as Input$1, Keyboard, ListLayout, ListStateContext, Menu as Menu$1, MenuItem, MenuSection, MenuTrigger, Modal, ModalOverlay, NumberField as NumberField$1, Popover as Popover$1, Row, SearchField, Separator, Slider as Slider$1, SliderOutput, SliderThumb, SliderTrack, SubmenuTrigger, Switch as Switch$1, Tab, TabList, TabPanel, Table, TableBody, TableHeader, TableLayout, Tabs as Tabs$1, Text, ToggleButton, ToggleButtonGroup, Toolbar as Toolbar$1, UNSTABLE_Toast, UNSTABLE_ToastContent, UNSTABLE_ToastQueue, UNSTABLE_ToastRegion, Virtualizer, useDragAndDrop, useFilter } from "react-aria-components";
4
4
  import { cva } from "class-variance-authority";
5
5
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
6
  import { ArrowDown, ArrowUp, ArrowUpDown, ArrowUpRight, Ban, Check, ChevronRight, CircleAlert, CircleCheck, FileQuestion, GripVertical, History, ImageOff, Info, Loader, LoaderCircle, Maximize, Maximize2, Minimize, Minus, Pause, Play, RotateCcw, Scan, Search, SkipBack, SkipForward, Square, StepBack, StepForward, Trash2, TriangleAlert, Upload, Volume2, VolumeX, X, ZoomIn, ZoomOut } 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
- import { useVirtualizer } from "@tanstack/react-virtual";
10
9
  import { VisuallyHidden, mergeProps, useFocusRing, useSlider, useSliderThumb } from "react-aria";
11
- import { useSliderState } from "react-stately";
10
+ import { Size, useSliderState } from "react-stately";
12
11
  import { hashKey, useInfiniteQuery, useQuery, useQueryClient } from "@tanstack/react-query";
13
12
  import pixelmatch from "pixelmatch";
14
13
  // src/lib/format.ts
@@ -1099,16 +1098,10 @@ function Checkbox({ label, hideLabel = false, detail, checked, onCheckedChange,
1099
1098
  "aria-label": hideLabel ? label : void 0,
1100
1099
  ...props,
1101
1100
  className: cn("group 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),
1102
- children: ({ isSelected, isIndeterminate }) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
1103
- "aria-hidden": true,
1104
- className: cn("grid size-4.5 shrink-0 place-items-center rounded-control border border-input bg-background transition-state", "group-focus-visible:outline-2 group-focus-visible:outline-offset-2 group-focus-visible:outline-ring", (isSelected || isIndeterminate) && "border-primary bg-primary text-primary-foreground", !hideLabel && "mt-0.5"),
1105
- children: isIndeterminate ? /* @__PURE__ */ jsx(Minus, {
1106
- className: "size-3.5",
1107
- strokeWidth: 3
1108
- }) : isSelected ? /* @__PURE__ */ jsx(Check, {
1109
- className: "size-3.5",
1110
- strokeWidth: 3
1111
- }) : null
1101
+ children: ({ isSelected, isIndeterminate }) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(CheckboxBox, {
1102
+ selected: isSelected,
1103
+ indeterminate: isIndeterminate,
1104
+ hideLabel
1112
1105
  }), !hideLabel && /* @__PURE__ */ jsxs("span", {
1113
1106
  className: "grid",
1114
1107
  children: [/* @__PURE__ */ jsx("span", {
@@ -1137,6 +1130,41 @@ function useShiftNote() {
1137
1130
  }
1138
1131
  }), []);
1139
1132
  }
1133
+ function CheckboxBox({ selected, indeterminate, hideLabel }) {
1134
+ return /* @__PURE__ */ jsx("span", {
1135
+ "aria-hidden": true,
1136
+ className: cn("grid size-4.5 shrink-0 place-items-center rounded-control border border-input bg-background transition-state", "group-focus-visible:outline-2 group-focus-visible:outline-offset-2 group-focus-visible:outline-ring", (selected || indeterminate) && "border-primary bg-primary text-primary-foreground", !hideLabel && "mt-0.5"),
1137
+ children: indeterminate ? /* @__PURE__ */ jsx(Minus, {
1138
+ className: "size-3.5",
1139
+ strokeWidth: 3
1140
+ }) : selected ? /* @__PURE__ */ jsx(Check, {
1141
+ className: "size-3.5",
1142
+ strokeWidth: 3
1143
+ }) : null
1144
+ });
1145
+ }
1146
+ /**
1147
+ * The checkbox of a React Aria `Table` row or header (`slot="selection"`): its checked, mixed and
1148
+ * disabled state come from the table, so it takes only a name. A `Checkbox` is controlled and would
1149
+ * fight the table's own selection state. Not exported from the package: `DataTable` uses it.
1150
+ * @internal
1151
+ */
1152
+ function TableSelectionCheckbox({ label, className, disabled }) {
1153
+ const id = React.useId();
1154
+ return /* @__PURE__ */ jsx(Checkbox$1, {
1155
+ slot: "selection",
1156
+ isDisabled: disabled,
1157
+ id,
1158
+ "aria-labelledby": id,
1159
+ "aria-label": label,
1160
+ className: ({ isDisabled }) => cn("group inline-flex min-h-6 min-w-6 items-center justify-center", isDisabled ? "cursor-not-allowed opacity-50" : "cursor-pointer", className),
1161
+ children: ({ isSelected, isIndeterminate }) => /* @__PURE__ */ jsx(CheckboxBox, {
1162
+ selected: isSelected,
1163
+ indeterminate: isIndeterminate,
1164
+ hideLabel: true
1165
+ })
1166
+ });
1167
+ }
1140
1168
  // src/components/async-button.tsx
1141
1169
  /** 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. */
1142
1170
  function AsyncButton({ phase, labels, error, disabled, ...props }) {
@@ -2345,90 +2373,6 @@ function ThumbnailSkeleton({ aspect = 1, className }) {
2345
2373
  children: /* @__PURE__ */ jsx(Skeleton, { className: "absolute inset-0" })
2346
2374
  });
2347
2375
  }
2348
- // src/components/disclosure.tsx
2349
- /** Shows more of one thing in place: a button with `aria-expanded` around `summary`, and a body mounted only while open (so a request inside it runs on first open). Controlled with `open`/`onOpenChange` or `useExpanded`, or uncontrolled with `defaultOpen`. */
2350
- function Disclosure({ summary, children, actions, open, defaultOpen = false, onOpenChange, className }) {
2351
- const [own, setOwn] = React.useState(defaultOpen);
2352
- const isOpen = open ?? own;
2353
- const bodyId = React.useId();
2354
- const toggle = () => {
2355
- if (open === void 0) setOwn(!isOpen);
2356
- onOpenChange?.(!isOpen);
2357
- };
2358
- return /* @__PURE__ */ jsxs("div", {
2359
- className: cn("min-w-0", className),
2360
- children: [/* @__PURE__ */ jsxs("div", {
2361
- className: "flex items-center gap-3",
2362
- children: [/* @__PURE__ */ jsxs("button", {
2363
- type: "button",
2364
- "aria-expanded": isOpen,
2365
- "aria-controls": isOpen ? bodyId : void 0,
2366
- onClick: toggle,
2367
- className: "-mx-1 flex min-h-(--control-h-sm) min-w-0 flex-1 cursor-pointer items-center gap-2 rounded-control px-1 text-left hover:bg-muted",
2368
- children: [/* @__PURE__ */ jsx(Chevron, { open: isOpen }), /* @__PURE__ */ jsx("span", {
2369
- className: "min-w-0 flex-1",
2370
- children: summary
2371
- })]
2372
- }), actions && /* @__PURE__ */ jsx("div", {
2373
- className: "flex shrink-0 items-center gap-2",
2374
- children: actions
2375
- })]
2376
- }), isOpen && /* @__PURE__ */ jsx("div", {
2377
- id: bodyId,
2378
- className: "pt-2 pb-3 pl-6",
2379
- children
2380
- })]
2381
- });
2382
- }
2383
- /** The disclosure chevron: points right when closed, down when open. Shared with `DataTable`'s row toggle. */
2384
- function Chevron({ open, className }) {
2385
- return /* @__PURE__ */ jsx(ChevronRight, {
2386
- "aria-hidden": true,
2387
- className: cn("size-4 shrink-0 text-muted-foreground", open && "rotate-90", className)
2388
- });
2389
- }
2390
- /** Shared open state for the disclosures of one list or table, optionally kept in the URL (`param`). */
2391
- function useExpanded(options = {}) {
2392
- return options.param ? useUrlExpanded(options.param, options) : useLocalExpanded(options);
2393
- }
2394
- function api(expanded, set, single) {
2395
- return {
2396
- expanded,
2397
- onChange: (next) => {
2398
- const opened = single ? [...next].filter((k) => !expanded.has(k)) : [];
2399
- set(opened.length ? /* @__PURE__ */ new Set([opened[opened.length - 1]]) : next);
2400
- },
2401
- isOpen: (key) => expanded.has(key),
2402
- setOpen: (key, open) => {
2403
- const next = single ? /* @__PURE__ */ new Set() : new Set(expanded);
2404
- if (open) next.add(key);
2405
- else next.delete(key);
2406
- set(next);
2407
- },
2408
- collapseAll: () => set(/* @__PURE__ */ new Set())
2409
- };
2410
- }
2411
- function useLocalExpanded({ initial = [], single }) {
2412
- const [expanded, setExpanded] = React.useState(() => new Set(initial));
2413
- return React.useMemo(() => api(expanded, setExpanded, single), [expanded, single]);
2414
- }
2415
- function useUrlExpanded(param, { single }) {
2416
- const [params, setParams] = useSearchParams();
2417
- const fromUrl = params.getAll(param);
2418
- const joined = fromUrl.join("\0");
2419
- const expanded = React.useMemo(() => new Set(fromUrl), [joined]);
2420
- const set = React.useCallback((next) => setParams((p) => {
2421
- const out = new URLSearchParams(p);
2422
- out.delete(param);
2423
- for (const k of next) out.append(param, k);
2424
- return out;
2425
- }, { replace: true }), [param, setParams]);
2426
- return React.useMemo(() => api(expanded, set, single), [
2427
- expanded,
2428
- set,
2429
- single
2430
- ]);
2431
- }
2432
2376
  // src/components/selection.tsx
2433
2377
  function reconcile(prev, rows, keys, initial) {
2434
2378
  const present = new Set(keys);
@@ -2537,8 +2481,12 @@ function useSelectRows(rows, rowKey, selection) {
2537
2481
  else keys.forEach((k) => next.delete(k));
2538
2482
  selection.onChange(next);
2539
2483
  };
2484
+ const setAnchor = (key) => {
2485
+ if (key !== null) anchor.current = key;
2486
+ };
2540
2487
  return {
2541
2488
  toggle,
2489
+ setAnchor,
2542
2490
  all: {
2543
2491
  checked: allChecked,
2544
2492
  toggle: toggleAll,
@@ -2570,6 +2518,90 @@ function BulkBar({ count, noun, onClear, children, format: format$1 = format, cl
2570
2518
  })]
2571
2519
  });
2572
2520
  }
2521
+ // src/components/disclosure.tsx
2522
+ /** Shows more of one thing in place: a button with `aria-expanded` around `summary`, and a body mounted only while open (so a request inside it runs on first open). Controlled with `open`/`onOpenChange` or `useExpanded`, or uncontrolled with `defaultOpen`. */
2523
+ function Disclosure({ summary, children, actions, open, defaultOpen = false, onOpenChange, className }) {
2524
+ const [own, setOwn] = React.useState(defaultOpen);
2525
+ const isOpen = open ?? own;
2526
+ const bodyId = React.useId();
2527
+ const toggle = () => {
2528
+ if (open === void 0) setOwn(!isOpen);
2529
+ onOpenChange?.(!isOpen);
2530
+ };
2531
+ return /* @__PURE__ */ jsxs("div", {
2532
+ className: cn("min-w-0", className),
2533
+ children: [/* @__PURE__ */ jsxs("div", {
2534
+ className: "flex items-center gap-3",
2535
+ children: [/* @__PURE__ */ jsxs("button", {
2536
+ type: "button",
2537
+ "aria-expanded": isOpen,
2538
+ "aria-controls": isOpen ? bodyId : void 0,
2539
+ onClick: toggle,
2540
+ className: "-mx-1 flex min-h-(--control-h-sm) min-w-0 flex-1 cursor-pointer items-center gap-2 rounded-control px-1 text-left hover:bg-muted",
2541
+ children: [/* @__PURE__ */ jsx(Chevron, { open: isOpen }), /* @__PURE__ */ jsx("span", {
2542
+ className: "min-w-0 flex-1",
2543
+ children: summary
2544
+ })]
2545
+ }), actions && /* @__PURE__ */ jsx("div", {
2546
+ className: "flex shrink-0 items-center gap-2",
2547
+ children: actions
2548
+ })]
2549
+ }), isOpen && /* @__PURE__ */ jsx("div", {
2550
+ id: bodyId,
2551
+ className: "pt-2 pb-3 pl-6",
2552
+ children
2553
+ })]
2554
+ });
2555
+ }
2556
+ /** The disclosure chevron: points right when closed, down when open. Shared with `DataTable`'s row toggle. */
2557
+ function Chevron({ open, className }) {
2558
+ return /* @__PURE__ */ jsx(ChevronRight, {
2559
+ "aria-hidden": true,
2560
+ className: cn("size-4 shrink-0 text-muted-foreground", open && "rotate-90", className)
2561
+ });
2562
+ }
2563
+ /** Shared open state for the disclosures of one list or table, optionally kept in the URL (`param`). */
2564
+ function useExpanded(options = {}) {
2565
+ return options.param ? useUrlExpanded(options.param, options) : useLocalExpanded(options);
2566
+ }
2567
+ function api(expanded, set, single) {
2568
+ return {
2569
+ expanded,
2570
+ onChange: (next) => {
2571
+ const opened = single ? [...next].filter((k) => !expanded.has(k)) : [];
2572
+ set(opened.length ? /* @__PURE__ */ new Set([opened[opened.length - 1]]) : next);
2573
+ },
2574
+ isOpen: (key) => expanded.has(key),
2575
+ setOpen: (key, open) => {
2576
+ const next = single ? /* @__PURE__ */ new Set() : new Set(expanded);
2577
+ if (open) next.add(key);
2578
+ else next.delete(key);
2579
+ set(next);
2580
+ },
2581
+ collapseAll: () => set(/* @__PURE__ */ new Set())
2582
+ };
2583
+ }
2584
+ function useLocalExpanded({ initial = [], single }) {
2585
+ const [expanded, setExpanded] = React.useState(() => new Set(initial));
2586
+ return React.useMemo(() => api(expanded, setExpanded, single), [expanded, single]);
2587
+ }
2588
+ function useUrlExpanded(param, { single }) {
2589
+ const [params, setParams] = useSearchParams();
2590
+ const fromUrl = params.getAll(param);
2591
+ const joined = fromUrl.join("\0");
2592
+ const expanded = React.useMemo(() => new Set(fromUrl), [joined]);
2593
+ const set = React.useCallback((next) => setParams((p) => {
2594
+ const out = new URLSearchParams(p);
2595
+ out.delete(param);
2596
+ for (const k of next) out.append(param, k);
2597
+ return out;
2598
+ }, { replace: true }), [param, setParams]);
2599
+ return React.useMemo(() => api(expanded, set, single), [
2600
+ expanded,
2601
+ set,
2602
+ single
2603
+ ]);
2604
+ }
2573
2605
  // src/components/data-table.tsx
2574
2606
  var collator = new Intl.Collator(void 0, {
2575
2607
  numeric: true,
@@ -2627,7 +2659,7 @@ function useUrlSort(param, initial) {
2627
2659
  return out;
2628
2660
  }, { replace: true }), [param, setParams])];
2629
2661
  }
2630
- /** A table on TanStack Table: muted headers, row rules, right-aligned tabular numbers, sortable headers with `aria-sort`, virtualised from `virtualizeFrom` rows, sort optionally kept in the URL (`sortParam`). */
2662
+ /** A table on React Aria's Table with TanStack Table's data model: muted headers, row rules, right-aligned tabular numbers, sortable headers with `aria-sort`, virtualised from `virtualizeFrom` rows, sort optionally kept in the URL (`sortParam`). */
2631
2663
  function DataTable(props) {
2632
2664
  return props.sortParam ? /* @__PURE__ */ jsx(UrlSortedTable, {
2633
2665
  ...props,
@@ -2635,13 +2667,13 @@ function DataTable(props) {
2635
2667
  }) : /* @__PURE__ */ jsx(LocalSortedTable, { ...props });
2636
2668
  }
2637
2669
  function LocalSortedTable(props) {
2638
- return /* @__PURE__ */ jsx(Table, {
2670
+ return /* @__PURE__ */ jsx(Table$1, {
2639
2671
  ...props,
2640
2672
  sortState: useLocalSort(props.initialSort)
2641
2673
  });
2642
2674
  }
2643
2675
  function UrlSortedTable(props) {
2644
- return /* @__PURE__ */ jsx(Table, {
2676
+ return /* @__PURE__ */ jsx(Table$1, {
2645
2677
  ...props,
2646
2678
  sortState: useUrlSort(props.sortParam, props.initialSort)
2647
2679
  });
@@ -2650,15 +2682,8 @@ var features = tableFeatures({
2650
2682
  rowSortingFeature,
2651
2683
  sortedRowModel: createSortedRowModel()
2652
2684
  });
2653
- function Table({ caption, columns, rows, rowKey, sortState: [sort, setSort], virtualizeFrom = 100, maxHeight = 480, selection, expansion, className }) {
2654
- const baseId = React.useId();
2685
+ function Table$1({ caption, columns, rows, rowKey, sortState: [sort, setSort], virtualizeFrom = 100, maxHeight = 480, selection, expansion, className }) {
2655
2686
  const defs = React.useMemo(() => columns.map((c) => {
2656
- const meta = {
2657
- numeric: c.numeric,
2658
- truncate: c.truncate,
2659
- hideHeader: c.hideHeader,
2660
- className: c.className
2661
- };
2662
2687
  const { value, sort } = c;
2663
2688
  if (!value) return {
2664
2689
  id: c.key,
@@ -2666,8 +2691,7 @@ function Table({ caption, columns, rows, rowKey, sortState: [sort, setSort], vir
2666
2691
  header: c.header,
2667
2692
  cell: (info) => c.cell?.(info.row.original),
2668
2693
  enableSorting: Boolean(sort),
2669
- sortFn: sort ? (a, b) => sort(a.original, b.original) : void 0,
2670
- meta
2694
+ sortFn: sort ? (a, b) => sort(a.original, b.original) : void 0
2671
2695
  };
2672
2696
  return {
2673
2697
  id: c.key,
@@ -2680,204 +2704,204 @@ function Table({ caption, columns, rows, rowKey, sortState: [sort, setSort], vir
2680
2704
  },
2681
2705
  enableSorting: sort !== false,
2682
2706
  sortUndefined: "last",
2683
- sortFn: sort ? (a, b) => sort(a.original, b.original) : (a, b) => compareValues(a.getValue(c.key), b.getValue(c.key)),
2684
- meta
2707
+ sortFn: sort ? (a, b) => sort(a.original, b.original) : (a, b) => compareValues(a.getValue(c.key), b.getValue(c.key))
2685
2708
  };
2686
2709
  }), [columns]);
2687
- const sorting = sort && columns.some((c) => c.key === sort.key && (c.value ? c.sort !== false : c.sort)) ? [{
2710
+ const sortable = (c) => c.value ? c.sort !== false : Boolean(c.sort);
2711
+ const sorting = sort && columns.some((c) => c.key === sort.key && sortable(c)) ? [{
2688
2712
  id: sort.key,
2689
2713
  desc: sort.dir === "descending"
2690
2714
  }] : [];
2691
- const table = useTable({
2715
+ const modelRows = useTable({
2692
2716
  features,
2693
2717
  data: rows,
2694
2718
  columns: defs,
2695
2719
  state: { sorting },
2696
2720
  getRowId: (row) => rowKey(row),
2697
2721
  autoResetAll: false
2698
- });
2699
- const toggle = (key) => setSort({
2700
- key,
2701
- dir: sort?.key === key && sort.dir === "ascending" ? "descending" : "ascending"
2702
- });
2703
- const modelRows = table.getRowModel().rows;
2722
+ }).getRowModel().rows;
2704
2723
  const canExpand = (row) => expansion?.isExpandable?.(row) ?? true;
2705
- const lines = React.useMemo(() => expansion ? modelRows.flatMap((row) => expansion.expanded.has(row.id) && canExpand(row.original) ? [{
2706
- row,
2707
- detail: false
2708
- }, {
2709
- row,
2710
- detail: true
2711
- }] : [{
2712
- row,
2713
- detail: false
2714
- }]) : modelRows.map((row) => ({
2715
- row,
2716
- detail: false
2717
- })), [modelRows, expansion]);
2718
- const select = useSelectRows(React.useMemo(() => modelRows.map((r) => r.original), [modelRows]), rowKey, selection);
2719
- const selectAll = selection ? select.all : void 0;
2720
2724
  const virtual = modelRows.length >= virtualizeFrom;
2721
- const scroller = React.useRef(null);
2722
- const virtualizer = useVirtualizer({
2723
- count: virtual ? lines.length : 0,
2724
- getScrollElement: () => scroller.current,
2725
- estimateSize: (i) => lines[i]?.detail ? 160 : 41,
2726
- getItemKey: (i) => lines[i] ? `${lines[i].row.id}${lines[i].detail ? "\0detail" : ""}` : i,
2727
- overscan: 8,
2728
- initialRect: {
2729
- width: 0,
2730
- height: maxHeight
2731
- }
2732
- });
2733
- const items = virtual ? virtualizer.getVirtualItems() : [];
2734
- const padTop = items.length ? items[0].start : 0;
2735
- const padBottom = items.length ? virtualizer.getTotalSize() - items[items.length - 1].end : 0;
2736
- const visible = virtual ? items.map((i) => ({
2737
- ...lines[i.index],
2738
- index: i.index
2739
- })) : lines.map((l, index) => ({
2740
- ...l,
2741
- index
2742
- }));
2743
2725
  const lead = (selection ? 1 : 0) + (expansion ? 1 : 0);
2744
- return /* @__PURE__ */ jsx("div", {
2745
- ref: scroller,
2746
- role: "region",
2726
+ const shownKeys = React.useMemo(() => new Set(modelRows.map((r) => r.id)), [modelRows]);
2727
+ const selectableKeys = modelRows.filter((r) => selection?.isSelectable?.(r.original) ?? true).map((r) => r.id);
2728
+ const detailKey = (id) => `${id}\u0000detail`;
2729
+ const disabledKeys = React.useMemo(() => {
2730
+ const keys = [];
2731
+ for (const r of modelRows) {
2732
+ if (selection && !(selection.isSelectable?.(r.original) ?? true)) keys.push(r.id);
2733
+ if (expansion && canExpand(r.original)) keys.push(detailKey(r.id));
2734
+ }
2735
+ return keys;
2736
+ }, [
2737
+ modelRows,
2738
+ selection,
2739
+ expansion
2740
+ ]);
2741
+ const shift = useShiftNote();
2742
+ const pressed = React.useRef(null);
2743
+ const notePress = (e) => void (pressed.current = e.target.closest("[data-key]")?.getAttribute("data-key") ?? null);
2744
+ const select = useSelectRows(React.useMemo(() => modelRows.map((r) => r.original), [modelRows]), rowKey, selection);
2745
+ const changeSelection = (next) => {
2746
+ if (!selection) return;
2747
+ if (next !== "all") {
2748
+ const nextShown = new Set([...next].map(String).filter((k) => shownKeys.has(k)));
2749
+ const added = [...nextShown].filter((k) => !selection.selected.has(k));
2750
+ const removed = [...selection.selected].filter((k) => shownKeys.has(k) && !nextShown.has(k));
2751
+ if (added.length + removed.length === 1) {
2752
+ select.toggle(added[0] ?? removed[0], added.length === 1, shift.take());
2753
+ return;
2754
+ }
2755
+ select.setAnchor(pressed.current);
2756
+ }
2757
+ const outside = [...selection.selected].filter((k) => !shownKeys.has(k));
2758
+ const chosen = selectableKeys.filter((k) => selection.selected.has(k)).length;
2759
+ const picked = next === "all" ? chosen > 0 && chosen < selectableKeys.length ? [] : selectableKeys : [...next].map(String).filter((k) => shownKeys.has(k));
2760
+ selection.onChange(/* @__PURE__ */ new Set([...outside, ...picked]));
2761
+ };
2762
+ const grid = /* @__PURE__ */ jsxs(Table, {
2747
2763
  "aria-label": caption,
2748
- tabIndex: 0,
2749
- className: cn("relative min-w-0 overflow-x-auto", virtual && "overflow-y-auto", className),
2764
+ selectionMode: selection ? "multiple" : "none",
2765
+ selectionBehavior: "toggle",
2766
+ selectedKeys: selection ? new Set([...selection.selected].filter((k) => shownKeys.has(k))) : void 0,
2767
+ onSelectionChange: changeSelection,
2768
+ disabledKeys,
2769
+ sortDescriptor: sort && columns.some((c) => c.key === sort.key && sortable(c)) ? {
2770
+ column: sort.key,
2771
+ direction: sort.dir
2772
+ } : void 0,
2773
+ onSortChange: (d) => setSort({
2774
+ key: String(d.column),
2775
+ dir: d.direction
2776
+ }),
2777
+ className: cn("w-full border-collapse type-body-sm outline-none", virtual && "overflow-auto"),
2750
2778
  style: virtual ? { maxHeight } : void 0,
2751
- children: /* @__PURE__ */ jsxs("table", {
2752
- className: "w-full border-collapse type-body-sm",
2753
- "aria-rowcount": virtual ? lines.length + 1 : void 0,
2779
+ children: [/* @__PURE__ */ jsxs(TableHeader, {
2780
+ className: cn(virtual && "bg-background"),
2754
2781
  children: [
2755
- /* @__PURE__ */ jsx("caption", {
2756
- className: "sr-only",
2757
- children: caption
2782
+ selection && /* @__PURE__ */ jsx(Column, {
2783
+ id: SELECT,
2784
+ textValue: "Select all shown",
2785
+ width: 32,
2786
+ className: "w-8 py-2 pr-2 text-left align-bottom outline-offset-[-2px]",
2787
+ children: /* @__PURE__ */ jsx(TableSelectionCheckbox, {
2788
+ label: "Select all shown",
2789
+ className: "-my-1",
2790
+ disabled: selectableKeys.length === 0
2791
+ })
2758
2792
  }),
2759
- /* @__PURE__ */ jsx("thead", {
2760
- className: cn(virtual && "sticky top-0 z-10 bg-background"),
2761
- children: table.getHeaderGroups().map((group) => /* @__PURE__ */ jsxs("tr", { children: [
2762
- selectAll && /* @__PURE__ */ jsx("th", {
2763
- scope: "col",
2764
- className: "w-8 py-2 pr-2 text-left align-bottom",
2765
- children: /* @__PURE__ */ jsx(Checkbox, {
2766
- className: "-my-1",
2767
- label: "Select all shown",
2768
- hideLabel: true,
2769
- checked: selectAll.checked,
2770
- disabled: selectAll.disabled,
2771
- onCheckedChange: selectAll.toggle
2772
- })
2773
- }),
2774
- expansion && /* @__PURE__ */ jsx("th", {
2775
- scope: "col",
2776
- className: "w-10 py-2 pr-2",
2777
- children: /* @__PURE__ */ jsx("span", {
2778
- className: "sr-only",
2779
- children: "Details"
2780
- })
2781
- }),
2782
- group.headers.map((header) => {
2783
- const meta = header.column.columnDef.meta;
2784
- const active = sort?.key === header.id && header.column.getCanSort() ? sort.dir : void 0;
2785
- const Icon = active === "ascending" ? ArrowUp : active === "descending" ? ArrowDown : ArrowUpDown;
2786
- const rendered = flexRender(header.column.columnDef.header, header.getContext());
2787
- const label = meta?.hideHeader ? /* @__PURE__ */ jsx("span", {
2788
- className: "sr-only",
2789
- children: rendered
2790
- }) : rendered;
2791
- return /* @__PURE__ */ jsx("th", {
2792
- scope: "col",
2793
- "aria-sort": active,
2794
- className: cn("py-2 pr-4 text-left align-bottom type-caption text-muted-foreground last:pr-0", meta?.numeric && "text-right"),
2795
- children: header.column.getCanSort() ? /* @__PURE__ */ jsxs("button", {
2796
- type: "button",
2797
- onClick: () => toggle(header.id),
2798
- className: cn("-mx-1 inline-flex cursor-pointer items-center gap-1 rounded-control px-1 transition-state hover:text-foreground", meta?.numeric && "flex-row-reverse", active && "text-foreground"),
2799
- children: [label, /* @__PURE__ */ jsx(Icon, {
2800
- "aria-hidden": true,
2801
- className: cn("size-3.5", !active && "opacity-50")
2802
- })]
2803
- }) : label
2804
- }, header.id);
2805
- })
2806
- ] }, group.id))
2793
+ expansion && /* @__PURE__ */ jsx(Column, {
2794
+ id: EXPAND,
2795
+ textValue: "Details",
2796
+ width: 40,
2797
+ className: "w-10 py-2 pr-2 outline-offset-[-2px]",
2798
+ children: /* @__PURE__ */ jsx("span", {
2799
+ className: "sr-only",
2800
+ children: "Details"
2801
+ })
2807
2802
  }),
2808
- /* @__PURE__ */ jsxs("tbody", { children: [
2809
- padTop > 0 && /* @__PURE__ */ jsx("tr", {
2810
- "aria-hidden": true,
2811
- style: { height: padTop }
2812
- }),
2813
- visible.map(({ row, detail, index }) => {
2814
- const chosen = selection?.selected.has(row.id) ?? false;
2815
- const detailId = `${baseId}-detail-${row.id}`;
2816
- if (detail && expansion) return /* @__PURE__ */ jsxs("tr", {
2817
- ref: virtual ? virtualizer.measureElement : void 0,
2818
- "data-index": index,
2819
- className: cn(chosen && "bg-surface-sunken"),
2820
- "aria-rowindex": virtual ? index + 2 : void 0,
2821
- children: [lead > 0 && /* @__PURE__ */ jsx("td", { colSpan: lead }), /* @__PURE__ */ jsx("td", {
2822
- id: detailId,
2823
- colSpan: columns.length,
2824
- className: "pt-0.5 pb-4 align-top",
2825
- children: expansion.detail(row.original)
2803
+ columns.map((c, i) => /* @__PURE__ */ jsx(Column, {
2804
+ id: c.key,
2805
+ textValue: c.header,
2806
+ isRowHeader: i === 0,
2807
+ allowsSorting: sortable(c),
2808
+ width: c.numeric ? "0.6fr" : "1fr",
2809
+ className: cn("py-2 text-left align-bottom type-caption font-normal text-muted-foreground outline-offset-[-2px]", i < columns.length - 1 && "pr-4", c.numeric && "text-right"),
2810
+ children: ({ allowsSorting, sortDirection }) => {
2811
+ const Icon = sortDirection === "ascending" ? ArrowUp : sortDirection === "descending" ? ArrowDown : ArrowUpDown;
2812
+ const label = c.hideHeader ? /* @__PURE__ */ jsx("span", {
2813
+ className: "sr-only",
2814
+ children: c.header
2815
+ }) : c.header;
2816
+ return allowsSorting ? /* @__PURE__ */ jsxs("span", {
2817
+ className: cn("-mx-1 inline-flex cursor-pointer items-center gap-1 rounded-control px-1 transition-state hover:text-foreground", c.numeric && "flex-row-reverse", sortDirection && "text-foreground"),
2818
+ children: [label, /* @__PURE__ */ jsx(Icon, {
2819
+ "aria-hidden": true,
2820
+ className: cn("size-3.5", !sortDirection && "opacity-50")
2826
2821
  })]
2827
- }, `${row.id}-detail`);
2828
- const open = expansion?.expanded.has(row.id) ?? false;
2829
- return /* @__PURE__ */ jsxs("tr", {
2830
- className: cn("border-t border-border", chosen && "bg-surface-sunken"),
2831
- "aria-rowindex": virtual ? index + 2 : void 0,
2832
- children: [
2833
- selection && /* @__PURE__ */ jsx("td", {
2834
- className: "w-8 py-2.5 pr-2 align-middle",
2835
- children: /* @__PURE__ */ jsx(Checkbox, {
2836
- className: "-my-0.5",
2837
- label: `Select ${selection.rowLabel(row.original)}`,
2838
- hideLabel: true,
2839
- checked: chosen,
2840
- disabled: !(selection.isSelectable?.(row.original) ?? true),
2841
- onCheckedChange: (on, gesture) => select.toggle(row.id, on, gesture)
2842
- })
2843
- }),
2844
- expansion && /* @__PURE__ */ jsx("td", {
2845
- className: "w-10 py-2.5 pr-2 align-middle",
2846
- children: canExpand(row.original) && /* @__PURE__ */ jsx("button", {
2847
- type: "button",
2848
- "aria-expanded": open,
2849
- "aria-controls": open ? detailId : void 0,
2850
- "aria-label": expansion.rowLabel(row.original),
2851
- title: expansion.rowLabel(row.original),
2852
- onClick: () => {
2853
- const next = new Set(expansion.expanded);
2854
- if (open) next.delete(row.id);
2855
- else next.add(row.id);
2856
- expansion.onChange(next);
2857
- },
2858
- className: "-my-1.5 grid size-(--control-h-sm) cursor-pointer place-items-center rounded-control hover:bg-muted",
2859
- children: /* @__PURE__ */ jsx(Chevron, { open })
2860
- })
2861
- }),
2862
- row.getAllCells().map((cell) => {
2863
- const meta = cell.column.columnDef.meta;
2864
- return /* @__PURE__ */ jsx("td", {
2865
- className: cn("py-2.5 pr-4 align-middle last:pr-0", meta?.numeric && "text-right tabular-nums", meta?.truncate && "max-w-48 truncate", meta?.className),
2866
- children: flexRender(cell.column.columnDef.cell, cell.getContext())
2867
- }, cell.id);
2868
- })
2869
- ]
2870
- }, row.id);
2822
+ }) : label;
2823
+ }
2824
+ }, c.key))
2825
+ ]
2826
+ }), /* @__PURE__ */ jsx(TableBody, { children: modelRows.flatMap((row) => {
2827
+ const open = (expansion?.expanded.has(row.id) ?? false) && canExpand(row.original);
2828
+ const cells = new Map(row.getAllCells().map((cell) => [cell.column.id, cell]));
2829
+ const items = [/* @__PURE__ */ jsxs(Row, {
2830
+ id: row.id,
2831
+ textValue: selection?.rowLabel(row.original) ?? expansion?.rowLabel(row.original) ?? row.id,
2832
+ onAction: selection ? noop : void 0,
2833
+ className: cn("border-t border-border outline-offset-[-2px] selected:bg-surface-sunken", open && "selected:bg-surface-sunken"),
2834
+ children: [
2835
+ selection && /* @__PURE__ */ jsx(Cell, {
2836
+ className: "w-8 py-2.5 pr-2 align-middle",
2837
+ children: /* @__PURE__ */ jsx(TableSelectionCheckbox, {
2838
+ label: `Select ${selection.rowLabel(row.original)}`,
2839
+ className: "-my-0.5"
2840
+ })
2871
2841
  }),
2872
- padBottom > 0 && /* @__PURE__ */ jsx("tr", {
2873
- "aria-hidden": true,
2874
- style: { height: padBottom }
2842
+ expansion && /* @__PURE__ */ jsx(Cell, {
2843
+ className: "w-10 py-2.5 pr-2 align-middle",
2844
+ children: canExpand(row.original) && /* @__PURE__ */ jsx(Button$1, {
2845
+ "aria-expanded": open,
2846
+ "aria-label": expansion.rowLabel(row.original),
2847
+ onPress: () => {
2848
+ const next = new Set(expansion.expanded);
2849
+ if (open) next.delete(row.id);
2850
+ else next.add(row.id);
2851
+ expansion.onChange(next);
2852
+ },
2853
+ className: "-my-1.5 grid size-(--control-h-sm) cursor-pointer place-items-center rounded-control hover:bg-muted",
2854
+ children: /* @__PURE__ */ jsx(Chevron, { open })
2855
+ })
2856
+ }),
2857
+ columns.map((c, i) => {
2858
+ const cell = cells.get(c.key);
2859
+ return /* @__PURE__ */ jsx(Cell, {
2860
+ className: cn("py-2.5 align-middle", i < columns.length - 1 && "pr-4", c.numeric && "text-right tabular-nums", c.truncate && "max-w-48 truncate", c.className),
2861
+ children: flexRender(cell.column.columnDef.cell, cell.getContext())
2862
+ }, c.key);
2875
2863
  })
2876
- ] })
2877
- ]
2878
- })
2864
+ ]
2865
+ }, row.id)];
2866
+ if (open && expansion) items.push(/* @__PURE__ */ jsxs(Row, {
2867
+ id: detailKey(row.id),
2868
+ textValue: expansion.rowLabel(row.original),
2869
+ className: "outline-offset-[-2px]",
2870
+ children: [lead > 0 && /* @__PURE__ */ jsx(Cell, { colSpan: lead }), /* @__PURE__ */ jsx(Cell, {
2871
+ colSpan: columns.length,
2872
+ className: "pt-0.5 pb-4 align-top",
2873
+ children: expansion.detail(row.original)
2874
+ })]
2875
+ }, detailKey(row.id)));
2876
+ return items;
2877
+ }) })]
2878
+ });
2879
+ return /* @__PURE__ */ jsx("div", {
2880
+ className: cn("relative min-w-0", !virtual && "overflow-x-auto", className),
2881
+ onMouseDownCapture: (e) => {
2882
+ shift.handlers.onMouseDown(e);
2883
+ notePress(e);
2884
+ },
2885
+ onKeyDownCapture: (e) => {
2886
+ shift.handlers.onKeyDown(e);
2887
+ notePress(e);
2888
+ },
2889
+ children: virtual ? /* @__PURE__ */ jsx(Virtualizer, {
2890
+ layout: TableLayout,
2891
+ layoutOptions: expansion ? {
2892
+ estimatedRowHeight: 41,
2893
+ headingHeight: 36
2894
+ } : {
2895
+ rowHeight: 41,
2896
+ headingHeight: 36
2897
+ },
2898
+ children: grid
2899
+ }) : grid
2879
2900
  });
2880
2901
  }
2902
+ var SELECT = "\0select";
2903
+ var EXPAND = "\0expand";
2904
+ var noop = () => {};
2881
2905
  /** The loading placeholder for a `DataTable`, shaped like its rows. */
2882
2906
  function TableSkeleton({ rows = 4, columns = 5 }) {
2883
2907
  return /* @__PURE__ */ jsxs("div", {
@@ -4575,197 +4599,147 @@ var TILE_CHROME = 40;
4575
4599
  function SelectableGrid({ label, rows, rowKey, renderImage, detail, selection, aspect = "square", tileSize = "md", virtualizeFrom = 100, maxHeight = 480, className }) {
4576
4600
  const select = useSelectRows(rows, rowKey, selection);
4577
4601
  const virtual = rows.length >= virtualizeFrom;
4578
- const tile = (row, index) => {
4579
- const key = rowKey(row);
4580
- return /* @__PURE__ */ jsx(Tile, {
4581
- name: `Select ${selection.rowLabel(row)}`,
4582
- chosen: selection.selected.has(key),
4583
- disabled: !(selection.isSelectable?.(row) ?? true),
4584
- onChange: (on, gesture) => select.toggle(key, on, gesture),
4585
- aspect,
4586
- image: renderImage(row),
4587
- detail: detail?.(row),
4588
- index
4589
- });
4602
+ const shownKeys = React.useMemo(() => new Set(rows.map(rowKey)), [rows, rowKey]);
4603
+ const disabledKeys = rows.filter((r) => !(selection.isSelectable?.(r) ?? true)).map(rowKey);
4604
+ const shift = useShiftNote();
4605
+ const pressed = React.useRef(null);
4606
+ const notePress = (e) => void (pressed.current = e.target.closest("[data-key]")?.getAttribute("data-key") ?? null);
4607
+ const changeSelection = (next) => {
4608
+ if (next !== "all") {
4609
+ const nextShown = new Set([...next].map(String).filter((k) => shownKeys.has(k)));
4610
+ const added = [...nextShown].filter((k) => !selection.selected.has(k));
4611
+ const removed = [...selection.selected].filter((k) => shownKeys.has(k) && !nextShown.has(k));
4612
+ if (added.length + removed.length === 1) {
4613
+ select.toggle(added[0] ?? removed[0], added.length === 1, shift.take());
4614
+ return;
4615
+ }
4616
+ select.setAnchor(pressed.current);
4617
+ }
4618
+ const outside = [...selection.selected].filter((k) => !shownKeys.has(k));
4619
+ const picked = next === "all" ? rows.filter((r) => selection.isSelectable?.(r) ?? true).map(rowKey) : [...next].map(String).filter((k) => shownKeys.has(k));
4620
+ selection.onChange(/* @__PURE__ */ new Set([...outside, ...picked]));
4590
4621
  };
4622
+ const layoutOptions = React.useMemo(() => ({
4623
+ minItemSize: new Size(minWidth[tileSize], Math.round(minWidth[tileSize] * aspectRatio[aspect]) + TILE_CHROME),
4624
+ minSpace: new Size(GAP, GAP)
4625
+ }), [tileSize, aspect]);
4626
+ const grid = /* @__PURE__ */ jsx(GridList, {
4627
+ "aria-label": label,
4628
+ layout: "grid",
4629
+ selectionMode: "multiple",
4630
+ selectionBehavior: "toggle",
4631
+ selectedKeys: new Set([...selection.selected].filter((k) => shownKeys.has(k))),
4632
+ onSelectionChange: changeSelection,
4633
+ disabledKeys,
4634
+ "data-strata-scroll": "",
4635
+ className: cn("min-w-0 outline-none", virtual ? "overflow-y-auto" : "grid gap-3"),
4636
+ style: virtual ? { height: maxHeight } : { gridTemplateColumns: `repeat(auto-fill, minmax(min(${minWidth[tileSize]}px, 100%), 1fr))` },
4637
+ children: rows.map((row, index) => {
4638
+ const key = rowKey(row);
4639
+ const name = selection.rowLabel(row);
4640
+ return /* @__PURE__ */ jsxs(GridListItem, {
4641
+ id: key,
4642
+ textValue: name,
4643
+ "data-index": index,
4644
+ className: cn("group relative grid min-w-0 gap-1.5 rounded-surface border border-transparent p-1.5 select-none outline-offset-2 transition-state", "selected:border-primary selected:bg-surface-sunken disabled:cursor-not-allowed disabled:opacity-50", "cursor-pointer hover:bg-surface-sunken disabled:hover:bg-transparent"),
4645
+ children: [
4646
+ /* @__PURE__ */ jsx("span", {
4647
+ className: cn("block overflow-hidden rounded-control bg-muted *:size-full *:object-cover", aspectClass[aspect]),
4648
+ children: renderImage(row)
4649
+ }),
4650
+ /* @__PURE__ */ jsx(TileBox, { label: `Select ${name}` }),
4651
+ detail?.(row) != null && /* @__PURE__ */ jsx("span", {
4652
+ className: "truncate type-body-sm text-muted-foreground",
4653
+ children: detail(row)
4654
+ })
4655
+ ]
4656
+ }, key);
4657
+ })
4658
+ });
4591
4659
  return /* @__PURE__ */ jsxs("div", {
4592
4660
  className: cn("grid min-w-0 gap-3", className),
4661
+ onMouseDownCapture: (e) => {
4662
+ shift.handlers.onMouseDown(e);
4663
+ notePress(e);
4664
+ },
4665
+ onKeyDownCapture: (e) => {
4666
+ shift.handlers.onKeyDown(e);
4667
+ notePress(e);
4668
+ },
4593
4669
  children: [/* @__PURE__ */ jsx(Checkbox, {
4594
4670
  className: "justify-self-start",
4595
4671
  label: "Select all shown",
4596
4672
  checked: select.all.checked,
4597
4673
  disabled: select.all.disabled,
4598
4674
  onCheckedChange: select.all.toggle
4599
- }), virtual ? /* @__PURE__ */ jsx(VirtualTiles, {
4600
- label,
4601
- rows,
4602
- rowKey,
4603
- tile,
4604
- aspect,
4605
- tileSize,
4606
- maxHeight
4607
- }) : /* @__PURE__ */ jsx("ul", {
4608
- "aria-label": label,
4609
- className: "grid gap-3",
4610
- style: { gridTemplateColumns: `repeat(auto-fill, minmax(min(${minWidth[tileSize]}px, 100%), 1fr))` },
4611
- children: rows.map((row, i) => /* @__PURE__ */ jsx("li", { children: tile(row, i) }, rowKey(row)))
4612
- })]
4613
- });
4614
- }
4615
- function VirtualTiles({ label, rows, rowKey, tile, aspect, tileSize, maxHeight }) {
4616
- const scroller = React.useRef(null);
4617
- const [width, setWidth] = React.useState(0);
4618
- React.useLayoutEffect(() => {
4619
- const el = scroller.current;
4620
- if (!el || typeof ResizeObserver === "undefined") return;
4621
- const observer = new ResizeObserver(([entry]) => setWidth(entry.contentRect.width));
4622
- observer.observe(el);
4623
- return () => observer.disconnect();
4624
- }, []);
4625
- const min = minWidth[tileSize];
4626
- const columns = Math.max(1, Math.floor((width + GAP) / (min + GAP)));
4627
- const tileWidth = width > 0 ? (width - GAP * (columns - 1)) / columns : min;
4628
- const lines = Math.ceil(rows.length / columns);
4629
- const virtualizer = useVirtualizer({
4630
- count: lines,
4631
- getScrollElement: () => scroller.current,
4632
- estimateSize: () => Math.round(tileWidth * aspectRatio[aspect]) + TILE_CHROME + GAP,
4633
- overscan: 3,
4634
- getItemKey: (i) => `${columns}:${i}`,
4635
- initialRect: {
4636
- width: 0,
4637
- height: maxHeight
4638
- }
4639
- });
4640
- const items = virtualizer.getVirtualItems();
4641
- return /* @__PURE__ */ jsx("div", {
4642
- ref: scroller,
4643
- role: "region",
4675
+ }), virtual ? /* @__PURE__ */ jsx(Virtualizer, {
4676
+ layout: GridLayout,
4677
+ layoutOptions,
4678
+ children: grid
4679
+ }) : grid]
4680
+ });
4681
+ }
4682
+ function TileBox({ label }) {
4683
+ const id = React.useId();
4684
+ return /* @__PURE__ */ jsx(Checkbox$1, {
4685
+ slot: "selection",
4686
+ id,
4687
+ "aria-labelledby": id,
4644
4688
  "aria-label": label,
4645
- tabIndex: 0,
4646
- "data-strata-scroll": "",
4647
- className: "min-w-0 overflow-y-auto",
4648
- style: { height: maxHeight },
4649
- children: /* @__PURE__ */ jsx("div", {
4650
- role: "list",
4651
- "aria-label": label,
4652
- className: "relative w-full",
4653
- style: { height: virtualizer.getTotalSize() },
4654
- children: items.map((v) => {
4655
- const start = v.index * columns;
4656
- return /* @__PURE__ */ jsx("div", {
4657
- ref: virtualizer.measureElement,
4658
- "data-index": v.index,
4659
- role: "none",
4660
- className: "absolute inset-x-0 top-0 grid gap-3 pb-3",
4661
- style: {
4662
- translate: `0 ${v.start}px`,
4663
- gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))`
4664
- },
4665
- children: rows.slice(start, start + columns).map((row, i) => /* @__PURE__ */ jsx("div", {
4666
- role: "listitem",
4667
- "aria-setsize": rows.length,
4668
- "aria-posinset": start + i + 1,
4669
- children: tile(row, start + i)
4670
- }, rowKey(row)))
4671
- }, v.key);
4689
+ className: "absolute top-3 left-3 grid size-7 place-items-center rounded-control bg-background",
4690
+ children: ({ isSelected }) => /* @__PURE__ */ jsx("span", {
4691
+ "aria-hidden": true,
4692
+ className: cn("grid size-4.5 place-items-center rounded-control border border-input bg-background", isSelected && "border-primary bg-primary text-primary-foreground"),
4693
+ children: isSelected && /* @__PURE__ */ jsx(Check, {
4694
+ className: "size-3.5",
4695
+ strokeWidth: 3
4672
4696
  })
4673
4697
  })
4674
4698
  });
4675
4699
  }
4676
- function Tile({ name, chosen, disabled, onChange, aspect, image, detail, index }) {
4677
- const shift = useShiftNote();
4678
- return /* @__PURE__ */ jsx("span", {
4679
- className: "contents",
4680
- onMouseDownCapture: shift.handlers.onMouseDown,
4681
- onKeyDownCapture: shift.handlers.onKeyDown,
4682
- children: /* @__PURE__ */ jsxs(Checkbox$1, {
4683
- isSelected: chosen,
4684
- isDisabled: disabled,
4685
- "aria-label": name,
4686
- onChange: (on) => onChange(on, shift.take()),
4687
- "data-index": index,
4688
- className: cn("group relative grid min-w-0 gap-1.5 rounded-surface border border-transparent p-1.5 select-none transition-state", "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring", chosen && "border-primary bg-surface-sunken", disabled ? "cursor-not-allowed opacity-50" : "cursor-pointer hover:bg-surface-sunken"),
4689
- children: [
4690
- /* @__PURE__ */ jsx("span", {
4691
- className: cn("block overflow-hidden rounded-control bg-muted *:size-full *:object-cover", aspectClass[aspect]),
4692
- children: image
4693
- }),
4694
- /* @__PURE__ */ jsx("span", {
4695
- className: "absolute top-3 left-3 grid size-7 place-items-center rounded-control bg-background",
4696
- children: /* @__PURE__ */ jsx("span", {
4697
- "aria-hidden": true,
4698
- className: cn("grid size-4.5 place-items-center rounded-control border border-input bg-background", chosen && "border-primary bg-primary text-primary-foreground"),
4699
- children: chosen && /* @__PURE__ */ jsx(Check, {
4700
- className: "size-3.5",
4701
- strokeWidth: 3
4702
- })
4703
- })
4704
- }),
4705
- detail != null && /* @__PURE__ */ jsx("span", {
4706
- className: "truncate type-body-sm text-muted-foreground",
4707
- children: detail
4708
- })
4709
- ]
4710
- })
4711
- });
4712
- }
4713
4700
  // src/components/virtual-list.tsx
4714
- /** A list that renders only its visible rows (TanStack Virtual) from `virtualizeFrom` items, keeping list semantics for screen readers. */
4715
- function VirtualList({ label, items, itemKey, children, estimateSize = 48, height = 480, virtualizeFrom = 100, bounded = false, footer, className }) {
4716
- const scroller = React.useRef(null);
4701
+ var FOOTER = "\0footer";
4702
+ /** A list that renders only its visible rows (React Aria's GridList and Virtualizer) from `virtualizeFrom` items, with arrow-key navigation between rows. */
4703
+ function VirtualList({ label, items, itemKey, children, estimateSize = 48, rowHeight, height = 480, virtualizeFrom = 100, bounded = false, footer, className }) {
4717
4704
  const virtual = items.length >= virtualizeFrom;
4718
- const virtualizer = useVirtualizer({
4719
- count: virtual ? items.length : 0,
4720
- getScrollElement: () => scroller.current,
4721
- estimateSize: () => estimateSize,
4722
- overscan: 6,
4723
- initialRect: {
4724
- width: 0,
4725
- height
4726
- }
4727
- });
4728
- const plain = () => /* @__PURE__ */ jsx("ul", {
4729
- "aria-label": label,
4730
- className: cn("grid min-w-0", !bounded && !footer && className),
4731
- children: items.map((item, i) => /* @__PURE__ */ jsx("li", {
4732
- "data-index": i,
4733
- className: "border-t border-border first:border-t-0",
4734
- children: children(item, i)
4735
- }, itemKey(item)))
4736
- });
4737
- if (!virtual && !bounded) return footer ? /* @__PURE__ */ jsxs("div", {
4738
- className: cn("min-w-0", className),
4739
- children: [plain(), footer]
4740
- }) : plain();
4741
- return /* @__PURE__ */ jsxs("div", {
4742
- ref: scroller,
4743
- role: "region",
4705
+ const rows = React.useMemo(() => items.map((item, index) => ({
4706
+ id: itemKey(item),
4707
+ item,
4708
+ index
4709
+ })), [items, itemKey]);
4710
+ const layoutOptions = React.useMemo(() => rowHeight ? { rowHeight } : { estimatedRowHeight: estimateSize }, [rowHeight, estimateSize]);
4711
+ const virtualise = virtual || bounded;
4712
+ const scrolls = virtualise;
4713
+ const list = /* @__PURE__ */ jsxs(GridList, {
4744
4714
  "aria-label": label,
4745
- tabIndex: 0,
4715
+ selectionMode: "none",
4746
4716
  "data-strata-scroll": "",
4747
- className: cn("min-w-0 overflow-y-auto", className),
4748
- style: virtual ? { height } : { maxHeight: height },
4749
- children: [virtual ? /* @__PURE__ */ jsx("ul", {
4750
- "aria-label": label,
4751
- className: "relative w-full",
4752
- style: { height: virtualizer.getTotalSize() },
4753
- children: virtualizer.getVirtualItems().map((v) => {
4754
- const item = items[v.index];
4755
- return /* @__PURE__ */ jsx("li", {
4756
- ref: virtualizer.measureElement,
4757
- "data-index": v.index,
4758
- "aria-setsize": items.length,
4759
- "aria-posinset": v.index + 1,
4760
- className: cn("absolute inset-x-0 top-0", v.index > 0 && "border-t border-border"),
4761
- style: { translate: `0 ${v.start}px` },
4762
- children: children(item, v.index)
4763
- }, itemKey(item));
4717
+ className: cn("min-w-0 outline-none", scrolls && "overflow-y-auto", className),
4718
+ style: scrolls ? virtual ? { height } : { maxHeight: height } : void 0,
4719
+ children: [/* @__PURE__ */ jsx(Collection, {
4720
+ items: rows,
4721
+ children: (row) => /* @__PURE__ */ jsx(GridListItem, {
4722
+ id: row.id,
4723
+ textValue: row.id,
4724
+ "data-index": row.index,
4725
+ className: cn("min-w-0 outline-offset-[-2px]", row.index > 0 && "border-t border-border"),
4726
+ children: children(row.item, row.index)
4764
4727
  })
4765
- }) : plain(), footer]
4728
+ }), footer && /* @__PURE__ */ jsx(GridListItem, {
4729
+ id: FOOTER,
4730
+ textValue: "More",
4731
+ className: "min-w-0",
4732
+ children: footer
4733
+ })]
4766
4734
  });
4735
+ return virtualise ? /* @__PURE__ */ jsx(Virtualizer, {
4736
+ layout: ListLayout,
4737
+ layoutOptions,
4738
+ children: list
4739
+ }) : list;
4767
4740
  }
4768
4741
  // src/components/infinite-list.tsx
4742
+ var PendingFocus = React.createContext(null);
4769
4743
  function MoreFailed({ message, retry }) {
4770
4744
  return /* @__PURE__ */ jsxs("div", {
4771
4745
  className: "flex flex-wrap items-start gap-3 border-t border-border bg-danger-subtle px-3 py-2 text-danger",
@@ -4802,6 +4776,7 @@ function LoadMore({ state, moreLabel, moreSkeleton, end, rootMargin = "400px", k
4802
4776
  active: ready && more.hasMore,
4803
4777
  rootMargin
4804
4778
  });
4779
+ const grid = React.useContext(ListStateContext);
4805
4780
  const { hasMore, loadingMore, error, loadMore } = more;
4806
4781
  React.useEffect(() => {
4807
4782
  if (!ready || !hasMore || loadingMore || error) return;
@@ -4816,7 +4791,8 @@ function LoadMore({ state, moreLabel, moreSkeleton, end, rootMargin = "400px", k
4816
4791
  keepAtLeast,
4817
4792
  loadMore
4818
4793
  ]);
4819
- const focusFrom = React.useRef(null);
4794
+ const own = React.useRef(null);
4795
+ const focusFrom = React.useContext(PendingFocus) ?? own;
4820
4796
  const loadByHand = () => {
4821
4797
  focusFrom.current = held;
4822
4798
  loadMore();
@@ -4824,19 +4800,36 @@ function LoadMore({ state, moreLabel, moreSkeleton, end, rootMargin = "400px", k
4824
4800
  React.useEffect(() => {
4825
4801
  const from = focusFrom.current;
4826
4802
  if (from === null || loadingMore) return;
4827
- if (held > from) {
4828
- const item = box.current?.parentElement?.querySelector(`[data-index="${from}"]`);
4829
- if (item) {
4830
- item.tabIndex = -1;
4831
- item.focus();
4803
+ if (held <= from) {
4804
+ if (error || !hasMore) focusFrom.current = null;
4805
+ return;
4806
+ }
4807
+ let frames = 0;
4808
+ let frame = 0;
4809
+ const find = () => {
4810
+ const item = (box.current?.closest("[data-strata-scroll]") ?? box.current?.parentElement)?.querySelector(`[data-index="${from}"]`);
4811
+ if (!item) {
4812
+ if (frames++ < 30) frame = requestAnimationFrame(find);
4813
+ else focusFrom.current = null;
4814
+ return;
4815
+ }
4816
+ const key = item.getAttribute("data-key");
4817
+ if (grid && key !== null) {
4818
+ grid.selectionManager.setFocused(true);
4819
+ grid.selectionManager.setFocusedKey(key);
4832
4820
  }
4821
+ item.tabIndex = -1;
4822
+ item.focus();
4833
4823
  focusFrom.current = null;
4834
- } else if (error || !hasMore) focusFrom.current = null;
4824
+ };
4825
+ find();
4826
+ return () => cancelAnimationFrame(frame);
4835
4827
  }, [
4836
4828
  held,
4837
4829
  loadingMore,
4838
4830
  error,
4839
- hasMore
4831
+ hasMore,
4832
+ grid
4840
4833
  ]);
4841
4834
  if (!ready) return null;
4842
4835
  return /* @__PURE__ */ jsxs("div", {
@@ -4880,15 +4873,32 @@ function LoadMore({ state, moreLabel, moreSkeleton, end, rootMargin = "400px", k
4880
4873
  /** A cursor-paged list for `useInfiniteLoad`: DataView's first-page states, virtual rows (or a page-scrolled grid), and a `LoadMore` row that loads on approach, shows a skeleton, or says why it failed with Try again. */
4881
4874
  function InfiniteList({ state, label, children, skeleton, empty, moreLabel, moreSkeleton = skeleton, end, rootMargin = "400px", keepAtLeast = 0, scroll = "region", listClassName, error, moreError, estimateSize, height = 480, virtualizeFrom, className }) {
4882
4875
  const { more, itemKey } = state;
4883
- const footer = /* @__PURE__ */ jsx(LoadMore, {
4884
- className: scroll === "page" ? "mt-4" : void 0,
4885
- state,
4886
- moreLabel,
4887
- moreSkeleton,
4888
- end,
4889
- rootMargin,
4876
+ const pendingFocus = React.useRef(null);
4877
+ const ready = state.status === "ready";
4878
+ const held = ready ? state.data.length : 0;
4879
+ const { hasMore, loadingMore, error: moreFailure, loadMore } = more;
4880
+ React.useEffect(() => {
4881
+ if (ready && hasMore && !loadingMore && !moreFailure && held < keepAtLeast) loadMore();
4882
+ }, [
4883
+ ready,
4884
+ hasMore,
4885
+ loadingMore,
4886
+ moreFailure,
4887
+ held,
4890
4888
  keepAtLeast,
4891
- error: moreError
4889
+ loadMore
4890
+ ]);
4891
+ const footer = /* @__PURE__ */ jsx(PendingFocus.Provider, {
4892
+ value: pendingFocus,
4893
+ children: /* @__PURE__ */ jsx(LoadMore, {
4894
+ className: scroll === "page" ? "mt-4" : void 0,
4895
+ state,
4896
+ moreLabel,
4897
+ moreSkeleton,
4898
+ end,
4899
+ rootMargin,
4900
+ error: moreError
4901
+ })
4892
4902
  });
4893
4903
  return /* @__PURE__ */ jsx(DataView, {
4894
4904
  state,