strata-react 1.0.44 → 1.0.45

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/UPGRADING.md CHANGED
@@ -11,6 +11,10 @@ time. While the version is 0.x, any release may break.
11
11
 
12
12
  Every PR that changes what an app sees adds a line here (see `CLAUDE.md`, "Changelog").
13
13
 
14
+ ## After v1.0.44 (2026-11-14)
15
+
16
+ - `SelectableGrid` with `groupBy` is now one virtualised list: a group's heading is a row of the grid (not a `region` with its own list per group), so a test that looked for `getByRole("region", { name })` finds the heading row instead, and only the visible rows are in the DOM. Tiles `isSelectable` refuses are now focusable (not selectable) so the arrow keys land on them and their `unselectableReason` can be read; they were skipped before. The grouped baselines move.
17
+
14
18
  ## After v1.0.43 (2026-11-14)
15
19
 
16
20
  - `toast.show(...)` with no `StrataToastRegion` mounted warns once in development ("nothing will be drawn") and still queues the toast; an app that called it before its region mounted will see the warning, and `renderWithStrata` keeps its region on by default so a test is unchanged.
@@ -29,7 +29,7 @@ export type SelectableGridProps<T> = {
29
29
  onAction?: (row: T) => void;
30
30
  /** A corner badge on the picture (top right): a `Status`. */
31
31
  badge?: (row: T) => React.ReactNode;
32
- /** Puts tiles under sticky headings, in the order the rows first show them. The grid is not virtualised while grouped. */
32
+ /** Puts tiles under full-width headings, in the order the rows first show them. Virtualised like the ungrouped grid. */
33
33
  groupBy?: (row: T) => string;
34
34
  /** The words for a group's heading; default the group text. */
35
35
  groupHeading?: (group: string, rows: T[]) => string;
package/dist/index.js CHANGED
@@ -12,7 +12,7 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
12
12
  import { Link, NavLink, useHref, useNavigate, useSearchParams } from "react-router";
13
13
  import { createSortedRowModel, flexRender, rowSortingFeature, tableFeatures, useTable } from "@tanstack/react-table";
14
14
  import { VisuallyHidden, mergeProps, useDrop, useFocusRing, useMove, useSlider, useSliderThumb } from "react-aria";
15
- import { Size, useSliderState } from "react-stately";
15
+ import { LayoutInfo, Rect, Size, useSliderState } from "react-stately";
16
16
  import { hashKey, useInfiniteQuery, useQuery, useQueryClient } from "@tanstack/react-query";
17
17
  import pixelmatch from "pixelmatch";
18
18
  // src/lib/chords.ts
@@ -6471,6 +6471,77 @@ function PropertyList({ items, label, className }) {
6471
6471
  })
6472
6472
  });
6473
6473
  }
6474
+ // src/lib/grouped-grid-layout.ts
6475
+ /** Keys of group headings start with this, so a tile key that is a plain id can never be mistaken for one. */
6476
+ var GROUP_PREFIX = "⁣group⁣";
6477
+ var groupKey = (group) => `${GROUP_PREFIX}${group}`;
6478
+ var isGroupKey = (key) => typeof key === "string" && key.startsWith("⁣group⁣");
6479
+ /** `GridLayout` with full-width group headings (items keyed by `groupKey`) that stay at the top of the scroll box while their group is in view. */
6480
+ var GroupedGridLayout = class extends GridLayout {
6481
+ headers = [];
6482
+ update(context) {
6483
+ super.update(context);
6484
+ const space = (context.layoutOptions ?? {}).minSpace?.height ?? 18;
6485
+ const width = this.virtualizer.size.width;
6486
+ const collection = this.virtualizer.collection;
6487
+ const tiles = [...collection].filter((n) => !isGroupKey(n.key)).map((n) => super.getLayoutInfo(n.key)).filter((l) => l !== null);
6488
+ const first = tiles[0];
6489
+ const columns = Math.max(1, this.numColumns);
6490
+ const xs = [...collection].slice(0, columns).map((n) => super.getLayoutInfo(n.key)?.rect.x ?? 0);
6491
+ const tileHeight = tiles.reduce((h, t) => Math.max(h, t.rect.height), 0) || first?.rect.height || 0;
6492
+ const next = /* @__PURE__ */ new Map();
6493
+ this.headers = [];
6494
+ let y = space;
6495
+ let col = 0;
6496
+ let rowInfos = [];
6497
+ const endRow = () => {
6498
+ if (!rowInfos.length) return;
6499
+ const h = rowInfos.reduce((m, l) => Math.max(m, l.rect.height), 0);
6500
+ for (const l of rowInfos) l.rect.height = h;
6501
+ y += h + space;
6502
+ rowInfos = [];
6503
+ col = 0;
6504
+ };
6505
+ for (const node of collection) {
6506
+ const key = String(node.key);
6507
+ if (isGroupKey(key)) {
6508
+ endRow();
6509
+ const info = new LayoutInfo(node.type, key, new Rect(0, y, width, 40));
6510
+ info.estimatedSize = false;
6511
+ info.allowOverflow = true;
6512
+ info.content = node;
6513
+ next.set(key, info);
6514
+ this.headers.push(info);
6515
+ y += 40 + space;
6516
+ continue;
6517
+ }
6518
+ const base = super.getLayoutInfo(node.key);
6519
+ if (!base) continue;
6520
+ const info = base.copy();
6521
+ info.rect = new Rect(xs[col] ?? base.rect.x, y, base.rect.width, Math.max(tileHeight, base.rect.height));
6522
+ info.estimatedSize = base.estimatedSize;
6523
+ next.set(key, info);
6524
+ rowInfos.push(info);
6525
+ if (++col === columns) endRow();
6526
+ }
6527
+ endRow();
6528
+ this.layoutInfos = next;
6529
+ this.contentSize = {
6530
+ width,
6531
+ height: y
6532
+ };
6533
+ }
6534
+ getVisibleLayoutInfos(rect) {
6535
+ const visible = super.getVisibleLayoutInfos(rect);
6536
+ let current = null;
6537
+ for (const h of this.headers) if (h.rect.y <= rect.y) current = h;
6538
+ if (!current || current.rect.y === rect.y) return visible;
6539
+ const stuck = current.copy();
6540
+ stuck.rect = new Rect(0, rect.y, current.rect.width, current.rect.height);
6541
+ stuck.zIndex = 10;
6542
+ return [...visible.filter((l) => l.key !== current.key), stuck];
6543
+ }
6544
+ };
6474
6545
  // src/components/tile-grid.tsx
6475
6546
  var minWidth = {
6476
6547
  sm: 96,
@@ -6593,7 +6664,7 @@ function SelectableGrid({ label, rows, rowKey, renderImage, detail, selection, a
6593
6664
  }));
6594
6665
  }, [rows, groupBy]);
6595
6666
  const [folded, setFolded] = React.useState(/* @__PURE__ */ new Set());
6596
- const virtual = !groups && rows.length >= virtualizeFrom;
6667
+ const virtual = Boolean(groups) || rows.length >= virtualizeFrom;
6597
6668
  const px = tileWidth(tileSize);
6598
6669
  const outer = React.useRef(null);
6599
6670
  const hidden = [...selection.selected].filter((k) => !shownKeys.has(k)).length;
@@ -6652,52 +6723,111 @@ function SelectableGrid({ label, rows, rowKey, renderImage, detail, selection, a
6652
6723
  const picked = next === "all" ? [] : [...next].map(String).filter((k) => shownKeys.has(k));
6653
6724
  selection.onChange(/* @__PURE__ */ new Set([...outside, ...picked.slice(-1)]));
6654
6725
  };
6655
- const list = (listRows, scroll, groupKey) => /* @__PURE__ */ jsx(GridList, {
6656
- "aria-label": groupKey !== void 0 ? `${label}, ${groupHeading ? groupHeading(groupKey, listRows) : groupKey}` : label,
6726
+ const selectableIn = (list) => list.filter((r) => selection.isSelectable?.(r) ?? true).map(rowKey);
6727
+ const groupChecked = (list) => {
6728
+ const keys = selectableIn(list);
6729
+ const chosen = keys.filter((k) => selection.selected.has(k)).length;
6730
+ return chosen === 0 ? false : chosen === keys.length ? true : "mixed";
6731
+ };
6732
+ const toggleGroup = (list) => {
6733
+ const next = new Set(selection.selected);
6734
+ const on = groupChecked(list) === false;
6735
+ for (const k of selectableIn(list)) if (on) next.add(k);
6736
+ else next.delete(k);
6737
+ selection.onChange(next);
6738
+ };
6739
+ const foldGroup = (key) => setFolded((f) => {
6740
+ const n = new Set(f);
6741
+ if (n.has(key)) n.delete(key);
6742
+ else n.add(key);
6743
+ return n;
6744
+ });
6745
+ const tile = (row) => {
6746
+ const key = rowKey(row);
6747
+ const index = indexOf.get(key) ?? 0;
6748
+ const name = selection.rowLabel(row);
6749
+ const unselectable = !(selection.isSelectable?.(row) ?? true);
6750
+ const why = unselectableReason && unselectable ? unselectableReason(row) : void 0;
6751
+ const corner = badge?.(row);
6752
+ return /* @__PURE__ */ jsxs(GridListItem, {
6753
+ id: key,
6754
+ textValue: name,
6755
+ "data-index": index,
6756
+ 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", unselectable ? "cursor-not-allowed opacity-50" : "cursor-pointer hover:bg-surface-sunken"),
6757
+ children: [
6758
+ /* @__PURE__ */ jsx("span", {
6759
+ className: cn("block overflow-hidden rounded-control bg-muted *:size-full *:object-cover", aspectClass[aspect]),
6760
+ children: renderImage(row)
6761
+ }),
6762
+ selectionMode === "multiple" && /* @__PURE__ */ jsx(TileBox, { label: `Select ${name}` }),
6763
+ corner != null && /* @__PURE__ */ jsx("span", {
6764
+ className: "absolute top-3 right-3",
6765
+ children: corner
6766
+ }),
6767
+ detail?.(row) != null && /* @__PURE__ */ jsx("span", {
6768
+ className: "truncate type-body-sm text-muted-foreground",
6769
+ children: detail(row)
6770
+ }),
6771
+ why && /* @__PURE__ */ jsx("span", {
6772
+ className: "truncate type-caption text-muted-foreground",
6773
+ children: why
6774
+ })
6775
+ ]
6776
+ }, key);
6777
+ };
6778
+ const header = (g) => {
6779
+ const heading = groupHeading ? groupHeading(g.key, g.rows) : g.key;
6780
+ const isFolded = folded.has(g.key);
6781
+ return /* @__PURE__ */ jsxs(GridListItem, {
6782
+ id: groupKey(g.key),
6783
+ textValue: heading,
6784
+ onAction: () => foldGroup(g.key),
6785
+ className: "flex min-w-0 items-center gap-2 bg-background outline-offset-[-2px]",
6786
+ children: [
6787
+ /* @__PURE__ */ jsx(Button, {
6788
+ size: "sm",
6789
+ variant: "ghost",
6790
+ "aria-expanded": !isFolded,
6791
+ "aria-label": `${isFolded ? "Unfold" : "Fold"} ${heading}`,
6792
+ onPress: () => foldGroup(g.key),
6793
+ children: /* @__PURE__ */ jsx(ChevronDown, {
6794
+ "aria-hidden": true,
6795
+ className: cn("transition-state", isFolded && "-rotate-90")
6796
+ })
6797
+ }),
6798
+ selectionMode === "multiple" && /* @__PURE__ */ jsx(Checkbox, {
6799
+ label: `Select ${heading}`,
6800
+ hideLabel: true,
6801
+ checked: groupChecked(g.rows),
6802
+ disabled: selectableIn(g.rows).length === 0,
6803
+ onCheckedChange: () => toggleGroup(g.rows)
6804
+ }),
6805
+ /* @__PURE__ */ jsx("h3", {
6806
+ className: "type-label",
6807
+ children: heading
6808
+ }),
6809
+ /* @__PURE__ */ jsx("span", {
6810
+ className: "type-caption text-muted-foreground tabular-nums",
6811
+ children: g.rows.length
6812
+ })
6813
+ ]
6814
+ }, groupKey(g.key));
6815
+ };
6816
+ const grid = /* @__PURE__ */ jsx(GridList, {
6817
+ "aria-label": label,
6657
6818
  layout: "grid",
6658
6819
  selectionMode,
6659
6820
  selectionBehavior,
6821
+ disabledBehavior: "selection",
6660
6822
  selectedKeys: new Set([...selection.selected].filter((k) => shownKeys.has(k))),
6661
6823
  onSelectionChange: selectionMode === "single" ? changeOne : changeSelection,
6662
6824
  onAction: onAction ? (key) => void (byKey.has(String(key)) && onAction(byKey.get(String(key)))) : void 0,
6663
- disabledKeys,
6664
- "data-strata-scroll": scroll ? "" : void 0,
6665
- className: cn("min-w-0 outline-none", virtual && scroll ? "overflow-y-auto" : "grid gap-3"),
6666
- style: virtual && scroll ? { height: maxHeight } : { gridTemplateColumns: `repeat(auto-fill, minmax(min(${px}px, 100%), 1fr))` },
6667
- children: listRows.map((row) => {
6668
- const key = rowKey(row);
6669
- const index = indexOf.get(key) ?? 0;
6670
- const name = selection.rowLabel(row);
6671
- const why = unselectableReason && !(selection.isSelectable?.(row) ?? true) ? unselectableReason(row) : void 0;
6672
- const corner = badge?.(row);
6673
- return /* @__PURE__ */ jsxs(GridListItem, {
6674
- id: key,
6675
- textValue: name,
6676
- "data-index": index,
6677
- 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"),
6678
- children: [
6679
- /* @__PURE__ */ jsx("span", {
6680
- className: cn("block overflow-hidden rounded-control bg-muted *:size-full *:object-cover", aspectClass[aspect]),
6681
- children: renderImage(row)
6682
- }),
6683
- selectionMode === "multiple" && /* @__PURE__ */ jsx(TileBox, { label: `Select ${name}` }),
6684
- corner != null && /* @__PURE__ */ jsx("span", {
6685
- className: "absolute top-3 right-3",
6686
- children: corner
6687
- }),
6688
- detail?.(row) != null && /* @__PURE__ */ jsx("span", {
6689
- className: "truncate type-body-sm text-muted-foreground",
6690
- children: detail(row)
6691
- }),
6692
- why && /* @__PURE__ */ jsx("span", {
6693
- className: "truncate type-caption text-muted-foreground",
6694
- children: why
6695
- })
6696
- ]
6697
- }, key);
6698
- })
6825
+ disabledKeys: groups ? [...disabledKeys, ...groups.map((g) => groupKey(g.key))] : disabledKeys,
6826
+ "data-strata-scroll": "",
6827
+ className: cn("min-w-0 outline-none", virtual ? "overflow-y-auto" : "grid gap-3"),
6828
+ style: virtual ? { height: maxHeight } : { gridTemplateColumns: `repeat(auto-fill, minmax(min(${px}px, 100%), 1fr))` },
6829
+ children: groups ? groups.map((g) => [header(g), ...folded.has(g.key) ? [] : g.rows.map(tile)]) : rows.map(tile)
6699
6830
  });
6700
- const grid = groups ? null : list(rows, true);
6701
6831
  return /* @__PURE__ */ jsxs("div", {
6702
6832
  ref: outer,
6703
6833
  className: cn("grid min-w-0 gap-3", className),
@@ -6708,6 +6838,12 @@ function SelectableGrid({ label, rows, rowKey, renderImage, detail, selection, a
6708
6838
  onKeyDownCapture: (e) => {
6709
6839
  shift.handlers.onKeyDown(e);
6710
6840
  notePress(e);
6841
+ const onHeader = e.target.closest("[data-key]")?.getAttribute("data-key");
6842
+ if (e.key === " " && groups && isGroupKey(onHeader) && e.target.getAttribute("data-key") === onHeader && selectionMode === "multiple") {
6843
+ toggleGroup(groups.find((g) => groupKey(g.key) === onHeader)?.rows ?? []);
6844
+ e.preventDefault();
6845
+ e.stopPropagation();
6846
+ }
6711
6847
  },
6712
6848
  onKeyDown: (e) => {
6713
6849
  if (isTypingTarget(e.target) || e.ctrlKey || e.metaKey || e.altKey) return;
@@ -6734,27 +6870,8 @@ function SelectableGrid({ label, rows, rowKey, renderImage, detail, selection, a
6734
6870
  onPress: () => selection.onChange(new Set([...selection.selected].filter((k) => shownKeys.has(k)))),
6735
6871
  children: "Clear hidden"
6736
6872
  })] })]
6737
- }), groups ? /* @__PURE__ */ jsx("div", {
6738
- "data-strata-scroll": "",
6739
- className: "min-w-0 overflow-y-auto",
6740
- style: { maxHeight },
6741
- children: groups.map((g) => /* @__PURE__ */ jsx(GroupSection, {
6742
- heading: groupHeading ? groupHeading(g.key, g.rows) : g.key,
6743
- rows: g.rows,
6744
- rowKey,
6745
- selection,
6746
- folded: folded.has(g.key),
6747
- onFold: () => setFolded((f) => {
6748
- const n = new Set(f);
6749
- if (n.has(g.key)) n.delete(g.key);
6750
- else n.add(g.key);
6751
- return n;
6752
- }),
6753
- multiple: selectionMode === "multiple",
6754
- children: list(g.rows, false, g.key)
6755
- }, g.key))
6756
- }) : virtual ? /* @__PURE__ */ jsx(Virtualizer, {
6757
- layout: GridLayout,
6873
+ }), virtual ? /* @__PURE__ */ jsx(Virtualizer, {
6874
+ layout: groups ? GroupedGridLayout : GridLayout,
6758
6875
  layoutOptions,
6759
6876
  children: grid
6760
6877
  }) : grid]
@@ -6778,44 +6895,6 @@ function TileBox({ label }) {
6778
6895
  })
6779
6896
  });
6780
6897
  }
6781
- function GroupSection({ heading, rows, rowKey, selection, folded, onFold, multiple, children }) {
6782
- const group = useSelectRows(rows, rowKey, selection);
6783
- return /* @__PURE__ */ jsxs("section", {
6784
- "aria-label": heading,
6785
- className: "grid gap-2 pb-3",
6786
- children: [/* @__PURE__ */ jsxs("header", {
6787
- className: "sticky top-0 z-10 flex items-center gap-2 bg-background py-1",
6788
- children: [
6789
- /* @__PURE__ */ jsx(Button, {
6790
- size: "sm",
6791
- variant: "ghost",
6792
- "aria-expanded": !folded,
6793
- "aria-label": `${folded ? "Unfold" : "Fold"} ${heading}`,
6794
- onPress: onFold,
6795
- children: /* @__PURE__ */ jsx(ChevronDown, {
6796
- "aria-hidden": true,
6797
- className: cn("transition-state", folded && "-rotate-90")
6798
- })
6799
- }),
6800
- multiple && /* @__PURE__ */ jsx(Checkbox, {
6801
- label: `Select ${heading}`,
6802
- hideLabel: true,
6803
- checked: group.all.checked,
6804
- disabled: group.all.disabled,
6805
- onCheckedChange: group.all.toggle
6806
- }),
6807
- /* @__PURE__ */ jsx("h3", {
6808
- className: "type-label",
6809
- children: heading
6810
- }),
6811
- /* @__PURE__ */ jsx("span", {
6812
- className: "type-caption text-muted-foreground tabular-nums",
6813
- children: rows.length
6814
- })
6815
- ]
6816
- }), !folded && children]
6817
- });
6818
- }
6819
6898
  // src/lib/viewport.ts
6820
6899
  /** The picture fitted in its frame, not panned. */
6821
6900
  var FIT = {