strata-react 0.1.6 → 0.1.10

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.
Files changed (40) hide show
  1. package/README.md +121 -13
  2. package/bin/strata-visual.js +6 -0
  3. package/dist/components/active-list.d.ts +46 -0
  4. package/dist/components/button.d.ts +9 -0
  5. package/dist/components/checkbox.d.ts +14 -0
  6. package/dist/components/composition.d.ts +35 -0
  7. package/dist/components/data-table.d.ts +14 -0
  8. package/dist/components/hotkeys.d.ts +29 -0
  9. package/dist/components/infinite-list.d.ts +29 -0
  10. package/dist/components/line-chart.d.ts +24 -3
  11. package/dist/components/link-card.d.ts +30 -0
  12. package/dist/components/meter.d.ts +32 -0
  13. package/dist/components/selection.d.ts +22 -0
  14. package/dist/components/theme.d.ts +7 -3
  15. package/dist/components/undo.d.ts +51 -8
  16. package/dist/components/virtual-list.d.ts +5 -1
  17. package/dist/index.d.ts +13 -5
  18. package/dist/index.js +1130 -81
  19. package/dist/index.js.map +1 -1
  20. package/dist/lib/format.d.ts +19 -1
  21. package/dist/query/index.d.ts +2 -1
  22. package/dist/query/infinite.d.ts +47 -0
  23. package/dist/{query-CmdlXVW_.js → query-CkOrBm3w.js} +37 -7
  24. package/dist/query-CkOrBm3w.js.map +1 -0
  25. package/dist/run-CLQi924v.js +605 -0
  26. package/dist/run-CLQi924v.js.map +1 -0
  27. package/dist/testing.js +1 -1
  28. package/dist/visual/capture.d.ts +22 -0
  29. package/dist/visual/cli.d.ts +5 -0
  30. package/dist/visual/compare.d.ts +31 -0
  31. package/dist/visual/index.d.ts +17 -0
  32. package/dist/visual/run.d.ts +22 -0
  33. package/dist/visual/serve.d.ts +11 -0
  34. package/dist/visual/targets.d.ts +17 -0
  35. package/dist/visual/types.d.ts +158 -0
  36. package/dist/visual-cli.js +118 -0
  37. package/dist/visual-cli.js.map +1 -0
  38. package/dist/visual.js +1 -0
  39. package/package.json +32 -8
  40. package/dist/query-CmdlXVW_.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,14 +1,24 @@
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-CmdlXVW_.js";
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";
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, Check, CircleAlert, LoaderCircle, RotateCcw } from "lucide-react";
6
+ import { ArrowDown, ArrowUp, ArrowUpDown, ArrowUpRight, Check, CircleAlert, LoaderCircle, RotateCcw, X } from "lucide-react";
7
+ import { Link, NavLink, useSearchParams } from "react-router";
7
8
  import { flexRender, getCoreRowModel, getSortedRowModel, useReactTable } from "@tanstack/react-table";
8
9
  import { useVirtualizer } from "@tanstack/react-virtual";
9
- import { Link, NavLink, useSearchParams } from "react-router";
10
+ import { hashKey, useInfiniteQuery } from "@tanstack/react-query";
10
11
  // src/lib/format.ts
11
12
  var NBSP = "\xA0";
13
+ var BYTE_UNITS = [
14
+ "B",
15
+ "kB",
16
+ "MB",
17
+ "GB",
18
+ "TB",
19
+ "PB"
20
+ ];
21
+ var BYTE_SIZE = Object.fromEntries(BYTE_UNITS.map((u, i) => [u, 1e3 ** i]));
12
22
  function callable(nf) {
13
23
  const format = (value) => nf.format(value);
14
24
  return Object.assign(format, {
@@ -17,7 +27,7 @@ function callable(nf) {
17
27
  resolvedOptions: () => nf.resolvedOptions()
18
28
  });
19
29
  }
20
- /** Intl formatters for one locale: integers, decimals, percent, times, days, units with a non-breaking space, and counted nouns. */
30
+ /** Intl formatters for one locale: integers, decimals, percent, times, days, units with a non-breaking space, byte sizes, and counted nouns. */
21
31
  function createFormat(locale) {
22
32
  const integer = callable(new Intl.NumberFormat(locale, { maximumFractionDigits: 0 }));
23
33
  const decimal = callable(new Intl.NumberFormat(locale, { maximumFractionDigits: 1 }));
@@ -56,6 +66,18 @@ function createFormat(locale) {
56
66
  /** A temperature in °C, joined by a non-breaking space. */
57
67
  celsius: (value) => withUnit(value, "°C"),
58
68
  /**
69
+ * A size in bytes in the largest decimal unit it reaches (kB, MB, GB, TB, as disks and
70
+ * networks are sold): one decimal below 10 ("5.2 GB"), whole above ("431 GB"). Pass `unit`
71
+ * to fix the unit, so figures compared side by side ("431 of 466 GB") share one.
72
+ */
73
+ bytes: (value, unit) => {
74
+ const chosen = unit ?? [...BYTE_UNITS].reverse().find((u) => Math.abs(value) >= BYTE_SIZE[u]) ?? "B";
75
+ const scaled = value / BYTE_SIZE[chosen];
76
+ return withUnit(scaled, chosen, Math.abs(scaled) < 10 && chosen !== "B" ? decimal : integer);
77
+ },
78
+ /** The unit `bytes` would choose for a value, to share it across a set of figures. */
79
+ byteUnit: (value) => [...BYTE_UNITS].reverse().find((u) => Math.abs(value) >= BYTE_SIZE[u]) ?? "B",
80
+ /**
59
81
  * "1 piece", "6 pieces": the count and its noun, so copy never reads "1 pieces". They are
60
82
  * joined by a non-breaking space (`NBSP`), not a plain one: in a test, match with the same
61
83
  * call or a `\s` regex, not a typed "6 pieces" string in a role's `name`.
@@ -109,6 +131,48 @@ function IconButton({ icon: Icon, label, variant = "ghost", ...props }) {
109
131
  children: /* @__PURE__ */ jsx(Icon, { "aria-hidden": true })
110
132
  });
111
133
  }
134
+ /** A small ghost action for one table row: shows `label`, and is named "`label` `subject`" so every row's action has its own name. */
135
+ function RowAction({ label, subject, icon: Icon, variant = "ghost", size = "sm", className, ...props }) {
136
+ return /* @__PURE__ */ jsxs(Button, {
137
+ variant,
138
+ size,
139
+ "aria-label": `${label} ${subject}`,
140
+ className: cn("-my-1.5", className),
141
+ ...props,
142
+ children: [Icon && /* @__PURE__ */ jsx(Icon, { "aria-hidden": true }), label]
143
+ });
144
+ }
145
+ // src/components/checkbox.tsx
146
+ /** A native checkbox and its label as one target. `label` is required; `hideLabel` keeps it as the accessible name only. */
147
+ function Checkbox({ label, hideLabel = false, detail, checked, onCheckedChange, className, disabled, ...props }) {
148
+ const ref = React.useRef(null);
149
+ React.useEffect(() => {
150
+ if (ref.current) ref.current.indeterminate = checked === "mixed";
151
+ }, [checked]);
152
+ return /* @__PURE__ */ jsxs("label", {
153
+ 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),
154
+ children: [/* @__PURE__ */ jsx("input", {
155
+ ref,
156
+ type: "checkbox",
157
+ checked: checked === true,
158
+ "aria-checked": checked === "mixed" ? "mixed" : void 0,
159
+ "aria-label": hideLabel ? label : void 0,
160
+ disabled,
161
+ onChange: (e) => onCheckedChange(e.target.checked),
162
+ className: cn("size-4.5 shrink-0 accent-primary", !hideLabel && "mt-0.5", disabled ? "cursor-not-allowed" : "cursor-pointer"),
163
+ ...props
164
+ }), !hideLabel && /* @__PURE__ */ jsxs("span", {
165
+ className: "grid",
166
+ children: [/* @__PURE__ */ jsx("span", {
167
+ className: "type-body",
168
+ children: label
169
+ }), detail && /* @__PURE__ */ jsx("span", {
170
+ className: "type-body-sm text-muted-foreground",
171
+ children: detail
172
+ })]
173
+ })]
174
+ });
175
+ }
112
176
  // src/components/async-button.tsx
113
177
  /** 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. */
114
178
  function AsyncButton({ phase, labels, error, disabled, ...props }) {
@@ -261,6 +325,256 @@ function Metric({ label, value, unit, note }) {
261
325
  ]
262
326
  });
263
327
  }
328
+ // src/components/meter.tsx
329
+ /** The threshold a share has crossed, if any: the most severe one reached in the worse direction. */
330
+ function crossedThreshold(share, thresholds = [], worseWhen = "higher") {
331
+ return thresholds.filter((t) => worseWhen === "higher" ? share >= t.at : share <= t.at).sort((a, b) => worseWhen === "higher" ? b.at - a.at : a.at - b.at)[0];
332
+ }
333
+ var fills = {
334
+ warning: "var(--warning)",
335
+ danger: "var(--danger)"
336
+ };
337
+ /** How full one thing is: a labelled `meter` with its reading in words, threshold notches, and a status word once a threshold is crossed. */
338
+ function Meter({ label, value, max = 1, valueText, detail, thresholds, worseWhen = "higher", hideLabel = false, colour = "var(--chart-1)", className }) {
339
+ const labelId = React.useId();
340
+ const statusId = React.useId();
341
+ const detailId = React.useId();
342
+ const share = max > 0 ? Math.min(1, Math.max(0, value / max)) : 0;
343
+ const crossed = crossedThreshold(share, thresholds, worseWhen);
344
+ const text = valueText ?? `${format.percent(share)} used`;
345
+ const hasNote = Boolean(crossed || detail);
346
+ const describedBy = [crossed && statusId, detail && detailId].filter(Boolean).join(" ") || void 0;
347
+ const bar = /* @__PURE__ */ jsxs("div", {
348
+ role: "meter",
349
+ "aria-labelledby": hideLabel ? void 0 : labelId,
350
+ "aria-label": hideLabel ? label : void 0,
351
+ "aria-valuemin": 0,
352
+ "aria-valuemax": max,
353
+ "aria-valuenow": Math.min(max, Math.max(0, value)),
354
+ "aria-valuetext": text,
355
+ "aria-describedby": describedBy,
356
+ className: "relative h-2 min-w-16 flex-1 overflow-hidden rounded-pill bg-muted",
357
+ children: [/* @__PURE__ */ jsx("div", {
358
+ className: "absolute inset-y-0 left-0",
359
+ style: {
360
+ width: `${share * 100}%`,
361
+ background: crossed ? fills[crossed.tone] : colour
362
+ }
363
+ }), thresholds?.map((t) => /* @__PURE__ */ jsx("div", {
364
+ className: "absolute inset-y-0 w-0.5 -translate-x-1/2 bg-background",
365
+ style: { left: `${Math.min(1, Math.max(0, t.at)) * 100}%` }
366
+ }, t.at))]
367
+ });
368
+ const figure = /* @__PURE__ */ jsx("span", {
369
+ "aria-hidden": true,
370
+ className: "shrink-0 type-body-sm tabular-nums text-foreground",
371
+ children: text
372
+ });
373
+ const note = hasNote && /* @__PURE__ */ jsxs("div", {
374
+ className: "flex flex-wrap items-center gap-x-3 gap-y-1",
375
+ children: [crossed && /* @__PURE__ */ jsx("span", {
376
+ id: statusId,
377
+ className: "contents",
378
+ children: /* @__PURE__ */ jsx(Status, {
379
+ tone: crossed.tone,
380
+ children: crossed.label
381
+ })
382
+ }), detail && /* @__PURE__ */ jsx("span", {
383
+ id: detailId,
384
+ className: "type-body-sm text-muted-foreground tabular-nums",
385
+ children: detail
386
+ })]
387
+ });
388
+ if (hideLabel) return /* @__PURE__ */ jsxs("div", {
389
+ className: cn("grid min-w-0 gap-1.5", className),
390
+ children: [/* @__PURE__ */ jsxs("div", {
391
+ className: "flex items-center gap-3",
392
+ children: [bar, figure]
393
+ }), note]
394
+ });
395
+ return /* @__PURE__ */ jsxs("div", {
396
+ className: cn("grid min-w-0 gap-1.5", className),
397
+ children: [
398
+ /* @__PURE__ */ jsxs("div", {
399
+ className: "flex items-baseline justify-between gap-3",
400
+ children: [/* @__PURE__ */ jsx("span", {
401
+ id: labelId,
402
+ className: "min-w-0 truncate type-label text-foreground",
403
+ children: label
404
+ }), figure]
405
+ }),
406
+ /* @__PURE__ */ jsx("div", {
407
+ className: "flex",
408
+ children: bar
409
+ }),
410
+ note
411
+ ]
412
+ });
413
+ }
414
+ // src/components/composition.tsx
415
+ var MAX_TOKENS = 5;
416
+ /** A part's colour: its own, or the chart token for its position. Throws past the fifth token. */
417
+ function colourFor(part, index) {
418
+ if (part.colour) return part.colour;
419
+ if (index >= MAX_TOKENS) throw new Error(`CompositionBar: part "${part.label}" is number ${index + 1}, and there are only ${MAX_TOKENS} chart colours. Combine the smallest parts into one "Other" part, or give this part a colour.`);
420
+ return `var(--chart-${index + 1})`;
421
+ }
422
+ /** What a whole is made of: a stacked bar for proportion and a table that names every part, its amount and its share, so colour is never the only cue. */
423
+ function CompositionBar({ label, parts, formatValue, formatShare = format.percent, partHeader = "Part", valueHeader = "Amount", shareHeader = "Share", className, ...whole }) {
424
+ const captionId = React.useId();
425
+ const sum = parts.reduce((n, p) => n + Math.max(0, p.value), 0);
426
+ const total = Math.max(whole.total ?? sum, sum);
427
+ const rest = whole.total !== void 0 ? total - sum : 0;
428
+ const shareOf = (value) => total > 0 ? Math.max(0, value) / total : 0;
429
+ const rows = parts.map((p, i) => ({
430
+ ...p,
431
+ colour: colourFor(p, i),
432
+ share: shareOf(p.value)
433
+ }));
434
+ return /* @__PURE__ */ jsxs("figure", {
435
+ className: cn("grid min-w-0 gap-3", className),
436
+ children: [
437
+ /* @__PURE__ */ jsx("figcaption", {
438
+ id: captionId,
439
+ className: "type-label text-foreground",
440
+ children: label
441
+ }),
442
+ /* @__PURE__ */ jsxs("div", {
443
+ "aria-hidden": true,
444
+ className: "flex h-3 gap-0.5 overflow-hidden rounded-pill bg-muted",
445
+ children: [rows.filter((r) => r.value > 0).map((r) => /* @__PURE__ */ jsx("div", {
446
+ className: "h-full min-w-0",
447
+ style: {
448
+ flex: `${r.share} 1 0`,
449
+ background: r.colour
450
+ }
451
+ }, r.key)), rest > 0 && /* @__PURE__ */ jsx("div", {
452
+ className: "h-full min-w-0",
453
+ style: { flex: `${shareOf(rest)} 1 0` }
454
+ })]
455
+ }),
456
+ /* @__PURE__ */ jsxs("table", {
457
+ "aria-labelledby": captionId,
458
+ className: "w-full border-collapse type-body-sm",
459
+ children: [/* @__PURE__ */ jsx("thead", {
460
+ className: "sr-only",
461
+ children: /* @__PURE__ */ jsxs("tr", { children: [
462
+ /* @__PURE__ */ jsx("th", {
463
+ scope: "col",
464
+ children: partHeader
465
+ }),
466
+ /* @__PURE__ */ jsx("th", {
467
+ scope: "col",
468
+ children: valueHeader
469
+ }),
470
+ /* @__PURE__ */ jsx("th", {
471
+ scope: "col",
472
+ children: shareHeader
473
+ })
474
+ ] })
475
+ }), /* @__PURE__ */ jsxs("tbody", { children: [rows.map((r) => /* @__PURE__ */ jsxs("tr", {
476
+ className: "border-t border-border first:border-t-0",
477
+ children: [
478
+ /* @__PURE__ */ jsx("th", {
479
+ scope: "row",
480
+ className: "py-1.5 pr-4 text-left font-normal",
481
+ children: /* @__PURE__ */ jsxs("span", {
482
+ className: "inline-flex items-center gap-2",
483
+ children: [/* @__PURE__ */ jsx("span", {
484
+ "aria-hidden": true,
485
+ className: "size-3 shrink-0 rounded-control",
486
+ style: { background: r.colour }
487
+ }), r.label]
488
+ })
489
+ }),
490
+ /* @__PURE__ */ jsx("td", {
491
+ className: "py-1.5 pr-4 text-right tabular-nums",
492
+ children: formatValue(r.value)
493
+ }),
494
+ /* @__PURE__ */ jsx("td", {
495
+ className: "w-px py-1.5 text-right whitespace-nowrap text-muted-foreground tabular-nums",
496
+ children: formatShare(r.share)
497
+ })
498
+ ]
499
+ }, r.key)), whole.total !== void 0 && /* @__PURE__ */ jsxs("tr", {
500
+ className: "border-t border-border",
501
+ children: [
502
+ /* @__PURE__ */ jsx("th", {
503
+ scope: "row",
504
+ className: "py-1.5 pr-4 text-left font-normal",
505
+ children: /* @__PURE__ */ jsxs("span", {
506
+ className: "inline-flex items-center gap-2",
507
+ children: [/* @__PURE__ */ jsx("span", {
508
+ "aria-hidden": true,
509
+ className: "size-3 shrink-0 rounded-control border border-border bg-muted"
510
+ }), whole.restLabel]
511
+ })
512
+ }),
513
+ /* @__PURE__ */ jsx("td", {
514
+ className: "py-1.5 pr-4 text-right tabular-nums",
515
+ children: formatValue(rest)
516
+ }),
517
+ /* @__PURE__ */ jsx("td", {
518
+ className: "w-px py-1.5 text-right whitespace-nowrap text-muted-foreground tabular-nums",
519
+ children: formatShare(shareOf(rest))
520
+ })
521
+ ]
522
+ })] })]
523
+ })
524
+ ]
525
+ });
526
+ }
527
+ // src/components/link-card.tsx
528
+ /** A destination as a card that is one link: its title is the link's name, the description and status marks are its description, and the whole card is the target. */
529
+ function LinkCard({ title, description, marks, as: Heading = "h3", className, ...destination }) {
530
+ const descriptionId = React.useId();
531
+ const marksId = React.useId();
532
+ const describedBy = [description && descriptionId, marks && marksId].filter(Boolean).join(" ") || void 0;
533
+ const linkClass = "rounded-control outline-none after:absolute after:inset-0 after:rounded-surface";
534
+ return /* @__PURE__ */ jsxs("div", {
535
+ className: cn("relative grid content-start gap-1.5 rounded-surface border border-border bg-background p-4 transition-state", "hover:border-muted-foreground has-focus-visible:outline-2 has-focus-visible:outline-offset-2 has-focus-visible:outline-ring", className),
536
+ children: [
537
+ /* @__PURE__ */ jsx(Heading, {
538
+ className: "flex items-start justify-between gap-3 type-heading text-foreground",
539
+ children: destination.href !== void 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("a", {
540
+ href: destination.href,
541
+ "aria-describedby": describedBy,
542
+ className: linkClass,
543
+ children: title
544
+ }), /* @__PURE__ */ jsx(ArrowUpRight, {
545
+ "aria-hidden": true,
546
+ className: "mt-0.5 size-4 shrink-0 text-muted-foreground"
547
+ })] }) : /* @__PURE__ */ jsx(Link, {
548
+ to: destination.to,
549
+ "aria-describedby": describedBy,
550
+ className: linkClass,
551
+ children: title
552
+ })
553
+ }),
554
+ description && /* @__PURE__ */ jsx("p", {
555
+ id: descriptionId,
556
+ className: "type-body-sm text-pretty text-muted-foreground",
557
+ children: description
558
+ }),
559
+ marks && /* @__PURE__ */ jsx("div", {
560
+ id: marksId,
561
+ className: "mt-1.5 flex flex-wrap gap-2",
562
+ children: marks
563
+ })
564
+ ]
565
+ });
566
+ }
567
+ /** A labelled list of `LinkCard`s in a grid: one column on a phone, up to three on a wide screen. */
568
+ function LinkCardList({ label, children, className }) {
569
+ return /* @__PURE__ */ jsx("ul", {
570
+ "aria-label": label,
571
+ className: cn("grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3", className),
572
+ children: React.Children.toArray(children).map((child, i) => /* @__PURE__ */ jsx("li", {
573
+ className: "grid",
574
+ children: child
575
+ }, React.isValidElement(child) && child.key != null ? child.key : i))
576
+ });
577
+ }
264
578
  // src/components/data-view.tsx
265
579
  /** 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. */
266
580
  function DataView({ state, isEmpty, skeleton, empty, children, className }) {
@@ -365,7 +679,31 @@ function UrlSortedTable(props) {
365
679
  sortState: useUrlSort(props.sortParam, props.initialSort)
366
680
  });
367
681
  }
368
- function Table({ caption, columns, rows, rowKey, sortState: [sort, setSort], virtualizeFrom = 100, maxHeight = 480, className }) {
682
+ function useSelectAll(rows, rowKey, selection) {
683
+ return React.useMemo(() => {
684
+ if (!selection) return void 0;
685
+ const keys = rows.filter((r) => selection.isSelectable?.(r) ?? true).map(rowKey);
686
+ const chosen = keys.filter((k) => selection.selected.has(k)).length;
687
+ const checked = chosen === 0 ? false : chosen === keys.length ? true : "mixed";
688
+ const toggle = () => {
689
+ const next = new Set(selection.selected);
690
+ if (checked === false) keys.forEach((k) => next.add(k));
691
+ else keys.forEach((k) => next.delete(k));
692
+ selection.onChange(next);
693
+ };
694
+ return {
695
+ checked,
696
+ toggle,
697
+ disabled: keys.length === 0
698
+ };
699
+ }, [
700
+ rows,
701
+ rowKey,
702
+ selection
703
+ ]);
704
+ }
705
+ function Table({ caption, columns, rows, rowKey, sortState: [sort, setSort], virtualizeFrom = 100, maxHeight = 480, selection, className }) {
706
+ const selectAll = useSelectAll(rows, rowKey, selection);
369
707
  const defs = React.useMemo(() => columns.map((c) => ({
370
708
  id: c.key,
371
709
  accessorFn: (row) => row,
@@ -376,6 +714,7 @@ function Table({ caption, columns, rows, rowKey, sortState: [sort, setSort], vir
376
714
  meta: {
377
715
  numeric: c.numeric,
378
716
  truncate: c.truncate,
717
+ hideHeader: c.hideHeader,
379
718
  className: c.className
380
719
  }
381
720
  })), [columns]);
@@ -389,7 +728,8 @@ function Table({ caption, columns, rows, rowKey, sortState: [sort, setSort], vir
389
728
  state: { sorting },
390
729
  getRowId: (row) => rowKey(row),
391
730
  getCoreRowModel: getCoreRowModel(),
392
- getSortedRowModel: getSortedRowModel()
731
+ getSortedRowModel: getSortedRowModel(),
732
+ autoResetAll: false
393
733
  });
394
734
  const toggle = (key) => setSort({
395
735
  key,
@@ -417,7 +757,7 @@ function Table({ caption, columns, rows, rowKey, sortState: [sort, setSort], vir
417
757
  role: "region",
418
758
  "aria-label": caption,
419
759
  tabIndex: 0,
420
- className: cn("min-w-0 overflow-x-auto", virtual && "overflow-y-auto", className),
760
+ className: cn("relative min-w-0 overflow-x-auto", virtual && "overflow-y-auto", className),
421
761
  style: virtual ? { maxHeight } : void 0,
422
762
  children: /* @__PURE__ */ jsxs("table", {
423
763
  className: "w-full border-collapse type-body-sm",
@@ -429,11 +769,26 @@ function Table({ caption, columns, rows, rowKey, sortState: [sort, setSort], vir
429
769
  }),
430
770
  /* @__PURE__ */ jsx("thead", {
431
771
  className: cn(virtual && "sticky top-0 z-10 bg-background"),
432
- children: table.getHeaderGroups().map((group) => /* @__PURE__ */ jsx("tr", { children: group.headers.map((header) => {
772
+ children: table.getHeaderGroups().map((group) => /* @__PURE__ */ jsxs("tr", { children: [selectAll && /* @__PURE__ */ jsx("th", {
773
+ scope: "col",
774
+ className: "w-8 py-2 pr-2 text-left align-bottom",
775
+ children: /* @__PURE__ */ jsx(Checkbox, {
776
+ className: "-my-1",
777
+ label: "Select all shown",
778
+ hideLabel: true,
779
+ checked: selectAll.checked,
780
+ disabled: selectAll.disabled,
781
+ onCheckedChange: selectAll.toggle
782
+ })
783
+ }), group.headers.map((header) => {
433
784
  const meta = header.column.columnDef.meta;
434
785
  const active = sort?.key === header.id && header.column.getCanSort() ? sort.dir : void 0;
435
786
  const Icon = active === "ascending" ? ArrowUp : active === "descending" ? ArrowDown : ArrowUpDown;
436
- const label = flexRender(header.column.columnDef.header, header.getContext());
787
+ const rendered = flexRender(header.column.columnDef.header, header.getContext());
788
+ const label = meta?.hideHeader ? /* @__PURE__ */ jsx("span", {
789
+ className: "sr-only",
790
+ children: rendered
791
+ }) : rendered;
437
792
  return /* @__PURE__ */ jsx("th", {
438
793
  scope: "col",
439
794
  "aria-sort": active,
@@ -448,24 +803,42 @@ function Table({ caption, columns, rows, rowKey, sortState: [sort, setSort], vir
448
803
  })]
449
804
  }) : label
450
805
  }, header.id);
451
- }) }, group.id))
806
+ })] }, group.id))
452
807
  }),
453
808
  /* @__PURE__ */ jsxs("tbody", { children: [
454
809
  padTop > 0 && /* @__PURE__ */ jsx("tr", {
455
810
  "aria-hidden": true,
456
811
  style: { height: padTop }
457
812
  }),
458
- visible.map((row, i) => /* @__PURE__ */ jsx("tr", {
459
- className: "border-t border-border",
460
- "aria-rowindex": virtual ? (items[i]?.index ?? 0) + 2 : void 0,
461
- children: row.getVisibleCells().map((cell) => {
462
- const meta = cell.column.columnDef.meta;
463
- return /* @__PURE__ */ jsx("td", {
464
- 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),
465
- children: flexRender(cell.column.columnDef.cell, cell.getContext())
466
- }, cell.id);
467
- })
468
- }, row.id)),
813
+ visible.map((row, i) => {
814
+ const chosen = selection?.selected.has(row.id) ?? false;
815
+ return /* @__PURE__ */ jsxs("tr", {
816
+ className: cn("border-t border-border", chosen && "bg-surface-sunken"),
817
+ "aria-rowindex": virtual ? (items[i]?.index ?? 0) + 2 : void 0,
818
+ children: [selection && /* @__PURE__ */ jsx("td", {
819
+ className: "w-8 py-2.5 pr-2 align-middle",
820
+ children: /* @__PURE__ */ jsx(Checkbox, {
821
+ className: "-my-0.5",
822
+ label: `Select ${selection.rowLabel(row.original)}`,
823
+ hideLabel: true,
824
+ checked: chosen,
825
+ disabled: !(selection.isSelectable?.(row.original) ?? true),
826
+ onCheckedChange: (on) => {
827
+ const next = new Set(selection.selected);
828
+ if (on) next.add(row.id);
829
+ else next.delete(row.id);
830
+ selection.onChange(next);
831
+ }
832
+ })
833
+ }), row.getVisibleCells().map((cell) => {
834
+ const meta = cell.column.columnDef.meta;
835
+ return /* @__PURE__ */ jsx("td", {
836
+ 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),
837
+ children: flexRender(cell.column.columnDef.cell, cell.getContext())
838
+ }, cell.id);
839
+ })]
840
+ }, row.id);
841
+ }),
469
842
  padBottom > 0 && /* @__PURE__ */ jsx("tr", {
470
843
  "aria-hidden": true,
471
844
  style: { height: padBottom }
@@ -489,9 +862,55 @@ function TableSkeleton({ rows = 4, columns = 5 }) {
489
862
  }, r))]
490
863
  });
491
864
  }
865
+ // src/components/selection.tsx
866
+ /** Chosen row keys, pruned to the rows that exist, and the calls that change them. Spread into `DataTable`'s `selection` with a `rowLabel`. */
867
+ function useSelection(rows, rowKey, initial = []) {
868
+ const [raw, setRaw] = React.useState(() => new Set(initial));
869
+ const selected = React.useMemo(() => {
870
+ const present = new Set(rows.map(rowKey));
871
+ return new Set([...raw].filter((k) => present.has(k)));
872
+ }, [raw, rows]);
873
+ const selectedRows = React.useMemo(() => rows.filter((r) => selected.has(rowKey(r))), [rows, selected]);
874
+ React.useEffect(() => {
875
+ if (selected.size !== raw.size) setRaw(selected);
876
+ }, [selected, raw]);
877
+ const onChange = React.useCallback((next) => setRaw(next), []);
878
+ const clear = React.useCallback(() => setRaw(/* @__PURE__ */ new Set()), []);
879
+ return {
880
+ selected,
881
+ selectedRows,
882
+ count: selected.size,
883
+ onChange,
884
+ clear
885
+ };
886
+ }
887
+ /** 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. */
888
+ function BulkBar({ count, noun, onClear, children, format: format$1 = format, className }) {
889
+ const [one, many] = typeof noun === "string" ? [noun, `${noun}s`] : noun;
890
+ const label = `${format$1.count(count, one, many)} selected`;
891
+ return /* @__PURE__ */ jsxs("div", {
892
+ 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),
893
+ children: [/* @__PURE__ */ jsx("p", {
894
+ "aria-live": "polite",
895
+ className: count > 0 ? "type-label tabular-nums" : "sr-only",
896
+ children: count > 0 ? label : `No ${many} selected`
897
+ }), count > 0 && /* @__PURE__ */ jsxs("div", {
898
+ role: "group",
899
+ "aria-label": `Actions for the selected ${many}`,
900
+ className: "flex flex-1 flex-wrap items-center gap-2",
901
+ children: [children, /* @__PURE__ */ jsxs(Button, {
902
+ size: "sm",
903
+ variant: "ghost",
904
+ className: "ml-auto",
905
+ onClick: onClear,
906
+ children: [/* @__PURE__ */ jsx(X, { "aria-hidden": true }), "Clear selection"]
907
+ })]
908
+ })]
909
+ });
910
+ }
492
911
  // src/components/virtual-list.tsx
493
912
  /** A list that renders only its visible rows (TanStack Virtual) from `virtualizeFrom` items, keeping list semantics for screen readers. */
494
- function VirtualList({ label, items, itemKey, children, estimateSize = 48, height = 480, virtualizeFrom = 100, className }) {
913
+ function VirtualList({ label, items, itemKey, children, estimateSize = 48, height = 480, virtualizeFrom = 100, bounded = false, footer, className }) {
495
914
  const scroller = React.useRef(null);
496
915
  const virtual = items.length >= virtualizeFrom;
497
916
  const virtualizer = useVirtualizer({
@@ -504,22 +923,28 @@ function VirtualList({ label, items, itemKey, children, estimateSize = 48, heigh
504
923
  height
505
924
  }
506
925
  });
507
- if (!virtual) return /* @__PURE__ */ jsx("ul", {
926
+ const plain = () => /* @__PURE__ */ jsx("ul", {
508
927
  "aria-label": label,
509
- className: cn("grid min-w-0", className),
928
+ className: cn("grid min-w-0", !bounded && !footer && className),
510
929
  children: items.map((item, i) => /* @__PURE__ */ jsx("li", {
930
+ "data-index": i,
511
931
  className: "border-t border-border first:border-t-0",
512
932
  children: children(item, i)
513
933
  }, itemKey(item)))
514
934
  });
515
- return /* @__PURE__ */ jsx("div", {
935
+ if (!virtual && !bounded) return footer ? /* @__PURE__ */ jsxs("div", {
936
+ className: cn("min-w-0", className),
937
+ children: [plain(), footer]
938
+ }) : plain();
939
+ return /* @__PURE__ */ jsxs("div", {
516
940
  ref: scroller,
517
941
  role: "region",
518
942
  "aria-label": label,
519
943
  tabIndex: 0,
944
+ "data-strata-scroll": "",
520
945
  className: cn("min-w-0 overflow-y-auto", className),
521
- style: { height },
522
- children: /* @__PURE__ */ jsx("ul", {
946
+ style: virtual ? { height } : { maxHeight: height },
947
+ children: [virtual ? /* @__PURE__ */ jsx("ul", {
523
948
  "aria-label": label,
524
949
  className: "relative w-full",
525
950
  style: { height: virtualizer.getTotalSize() },
@@ -535,9 +960,150 @@ function VirtualList({ label, items, itemKey, children, estimateSize = 48, heigh
535
960
  children: children(item, v.index)
536
961
  }, itemKey(item));
537
962
  })
963
+ }) : plain(), footer]
964
+ });
965
+ }
966
+ // src/components/infinite-list.tsx
967
+ /** A cursor-paged list for `useInfiniteLoad`: DataView's first-page states, virtual rows, and a next-page row that loads on approach, shows a skeleton, or says why it failed with Try again. */
968
+ function InfiniteList({ state, label, children, skeleton, empty, moreLabel, moreSkeleton = skeleton, end, rootMargin = "400px", keepAtLeast = 0, estimateSize, height = 480, virtualizeFrom, className }) {
969
+ const { more, itemKey } = state;
970
+ const held = state.status === "ready" ? state.data.length : 0;
971
+ const box = React.useRef(null);
972
+ const near = useNearEnd(state.status === "ready" && more.hasMore, rootMargin);
973
+ const { hasMore, loadingMore, error, loadMore } = more;
974
+ React.useEffect(() => {
975
+ if (state.status !== "ready" || !hasMore || loadingMore || error) return;
976
+ if (near.inView || held < keepAtLeast) loadMore();
977
+ }, [
978
+ state.status,
979
+ hasMore,
980
+ loadingMore,
981
+ error,
982
+ near.inView,
983
+ held,
984
+ keepAtLeast,
985
+ loadMore
986
+ ]);
987
+ const focusFrom = React.useRef(null);
988
+ const loadByHand = () => {
989
+ focusFrom.current = held;
990
+ loadMore();
991
+ };
992
+ React.useEffect(() => {
993
+ const from = focusFrom.current;
994
+ if (from === null || loadingMore) return;
995
+ if (held > from) {
996
+ const row = box.current?.querySelector(`li[data-index="${from}"]`);
997
+ if (row) {
998
+ row.tabIndex = -1;
999
+ row.focus();
1000
+ }
1001
+ focusFrom.current = null;
1002
+ } else if (error || !hasMore) focusFrom.current = null;
1003
+ }, [
1004
+ held,
1005
+ loadingMore,
1006
+ error,
1007
+ hasMore
1008
+ ]);
1009
+ const footer = /* @__PURE__ */ jsxs("div", { children: [
1010
+ hasMore && !error && /* @__PURE__ */ jsx("div", {
1011
+ ref: near.ref,
1012
+ "aria-hidden": true,
1013
+ className: "h-px"
1014
+ }),
1015
+ loadingMore ? /* @__PURE__ */ jsx("div", {
1016
+ "aria-hidden": true,
1017
+ className: "border-t border-border",
1018
+ children: moreSkeleton
1019
+ }) : error ? /* @__PURE__ */ jsxs("div", {
1020
+ role: "alert",
1021
+ className: "flex flex-wrap items-start gap-3 border-t border-border bg-danger-subtle px-3 py-2 text-danger",
1022
+ children: [
1023
+ /* @__PURE__ */ jsx(CircleAlert, {
1024
+ "aria-hidden": true,
1025
+ className: "mt-0.5 size-4 shrink-0"
1026
+ }),
1027
+ /* @__PURE__ */ jsx("p", {
1028
+ className: "min-w-0 flex-1 type-body-sm",
1029
+ children: error
1030
+ }),
1031
+ /* @__PURE__ */ jsxs(Button, {
1032
+ size: "sm",
1033
+ onClick: loadByHand,
1034
+ children: [/* @__PURE__ */ jsx(RotateCcw, { "aria-hidden": true }), "Try again"]
1035
+ })
1036
+ ]
1037
+ }) : hasMore ? /* @__PURE__ */ jsx("div", {
1038
+ className: "border-t border-border py-3",
1039
+ children: /* @__PURE__ */ jsx(Button, {
1040
+ size: "sm",
1041
+ onClick: loadByHand,
1042
+ children: moreLabel
1043
+ })
1044
+ }) : end && /* @__PURE__ */ jsx("div", {
1045
+ className: "border-t border-border py-3 type-body-sm text-muted-foreground",
1046
+ children: end
1047
+ }),
1048
+ /* @__PURE__ */ jsx("p", {
1049
+ role: "status",
1050
+ className: "sr-only",
1051
+ children: loadingMore ? "Loading more" : ""
1052
+ })
1053
+ ] });
1054
+ return /* @__PURE__ */ jsx(DataView, {
1055
+ state,
1056
+ isEmpty: (items) => items.length === 0 && !hasMore,
1057
+ skeleton,
1058
+ empty,
1059
+ className,
1060
+ children: (items) => /* @__PURE__ */ jsx("div", {
1061
+ ref: box,
1062
+ "aria-busy": loadingMore || void 0,
1063
+ children: /* @__PURE__ */ jsx(VirtualList, {
1064
+ label,
1065
+ items,
1066
+ itemKey,
1067
+ estimateSize,
1068
+ height,
1069
+ virtualizeFrom,
1070
+ bounded: true,
1071
+ footer,
1072
+ children
1073
+ })
538
1074
  })
539
1075
  });
540
1076
  }
1077
+ /**
1078
+ * Watches a sentinel element and reports whether it is within `rootMargin` of its scroll region
1079
+ * (the nearest `[data-strata-scroll]` ancestor, else the viewport). A callback ref, so it follows
1080
+ * the sentinel as it mounts and unmounts.
1081
+ */
1082
+ function useNearEnd(active, rootMargin) {
1083
+ const [inView, setInView] = React.useState(false);
1084
+ const [el, setEl] = React.useState(null);
1085
+ React.useEffect(() => {
1086
+ if (!active || !el || typeof IntersectionObserver === "undefined") {
1087
+ setInView(false);
1088
+ return;
1089
+ }
1090
+ const root = el.parentElement?.closest("[data-strata-scroll]") ?? null;
1091
+ const observer = new IntersectionObserver((entries) => setInView(entries[entries.length - 1].isIntersecting), {
1092
+ root,
1093
+ rootMargin
1094
+ });
1095
+ observer.observe(el);
1096
+ return () => observer.disconnect();
1097
+ }, [
1098
+ active,
1099
+ el,
1100
+ rootMargin
1101
+ ]);
1102
+ return {
1103
+ ref: setEl,
1104
+ inView
1105
+ };
1106
+ }
541
1107
  // src/components/line-chart.tsx
542
1108
  function useWidth() {
543
1109
  const ref = React.useRef(null);
@@ -552,35 +1118,86 @@ function useWidth() {
552
1118
  }, []);
553
1119
  return [ref, width];
554
1120
  }
555
- /** Four gridline steps of a size people write on a scale (1, 2, 2.5, 4 or 5 × 10ⁿ), ending above the max. */
556
- function niceMax(max) {
557
- if (!(max > 0)) return 4;
558
- const raw = max / 4;
1121
+ /** The smallest step of a size people write on a scale (1, 2, 2.5, 4 or 5 × 10ⁿ) at least `raw`. */
1122
+ function niceStep(raw) {
559
1123
  const mag = 10 ** Math.floor(Math.log10(raw));
560
- return ([
1124
+ return [
561
1125
  1,
562
1126
  2,
563
1127
  2.5,
564
1128
  4,
565
1129
  5,
566
1130
  10
567
- ].map((m) => m * mag).find((s) => s >= raw) ?? 10 * mag) * 4;
1131
+ ].map((m) => m * mag).find((s) => s >= raw * (1 - 1e-9)) ?? 10 * mag;
1132
+ }
1133
+ /**
1134
+ * The y-axis: four equal gridline steps covering every value. With no pins the steps are a size
1135
+ * people write on a scale (1, 2, 2.5, 4 or 5 × 10ⁿ), from zero or a round number below the lowest
1136
+ * reading. A pinned end is used as given unless a value lies beyond it.
1137
+ */
1138
+ function yScale(values, pin = {}) {
1139
+ const finite = values.filter(Number.isFinite);
1140
+ const dMin = finite.length ? Math.min(...finite) : 0;
1141
+ const dMax = finite.length ? Math.max(...finite) : 0;
1142
+ const pinMin = pin.min !== void 0 && dMin >= pin.min ? pin.min : void 0;
1143
+ const pinMax = pin.max !== void 0 && dMax <= pin.max ? pin.max : void 0;
1144
+ let lo = pinMin ?? Math.min(0, dMin);
1145
+ if (pinMax !== void 0 && pinMin === void 0 && !(pinMax > lo)) lo = pinMax - (Math.abs(pinMax) || 4);
1146
+ let min;
1147
+ let max;
1148
+ if (pinMax !== void 0) {
1149
+ max = pinMax;
1150
+ min = pinMin ?? (lo < 0 ? Math.floor(lo / niceStep((max - lo) / 4)) * niceStep((max - lo) / 4) : 0);
1151
+ } else {
1152
+ const hi = Math.max(dMax, pin.max ?? -Infinity);
1153
+ let step = hi > lo ? niceStep((hi - lo) / 4) : 1;
1154
+ let base = pinMin ?? Math.floor(lo / step) * step;
1155
+ while (base + 4 * step < hi) {
1156
+ step = niceStep(step * 1.01);
1157
+ base = pinMin ?? Math.floor(lo / step) * step;
1158
+ }
1159
+ min = base;
1160
+ max = base + 4 * step;
1161
+ }
1162
+ if (!(max > min)) max = min + 4;
1163
+ return {
1164
+ min,
1165
+ max,
1166
+ ticks: [
1167
+ 0,
1168
+ 1,
1169
+ 2,
1170
+ 3,
1171
+ 4
1172
+ ].map((i) => min + (max - min) * i / 4)
1173
+ };
1174
+ }
1175
+ /** Roughly how wide a 12px caption label is, in px. jsdom cannot measure text, so the chart estimates. */
1176
+ var labelWidth = (text) => text.length * 7;
1177
+ /**
1178
+ * The x ticks that fit at this width: every k-th tick, the smallest k for which neighbouring labels
1179
+ * leave a gap, so the spacing stays even. `scale` maps an x value to a pixel.
1180
+ */
1181
+ function fitTicks(ticks, scale, widthOf, gap = 12) {
1182
+ if (ticks.length < 3) return ticks;
1183
+ const sorted = [...ticks].sort((a, b) => a - b);
1184
+ for (let k = 1; k < sorted.length; k++) {
1185
+ const kept = sorted.filter((_, i) => i % k === 0);
1186
+ if (kept.every((t, i) => i === 0 || scale(t) - scale(kept[i - 1]) >= (widthOf(t) + widthOf(kept[i - 1])) / 2 + gap)) return kept;
1187
+ }
1188
+ return sorted.slice(0, 1);
568
1189
  }
569
1190
  /** One measured series, drawn in real pixels, with the peak and current readings labelled on the chart and every reading in a screen-reader table. Optional plan, threshold band and `colourScale`. */
570
- function LineChart({ label, series, seriesLabel, planned, plannedLabel, band, formatX, formatY, xTicks, colour = "var(--chart-1)", colourScale, colourScaleLabel, height = 280, className }) {
1191
+ function LineChart({ label, series, seriesLabel, planned, plannedLabel, band, formatX, formatY, xTicks, yMin, yMax, colour = "var(--chart-1)", colourScale, colourScaleLabel, height = 280, className }) {
571
1192
  const [ref, width] = useWidth();
572
1193
  const gradientId = `heat-${React.useId().replace(/[^\w-]/g, "")}`;
573
1194
  const all = [...series, ...planned ?? []];
574
1195
  const xMin = Math.min(...all.map((p) => p.x));
575
1196
  const xMax = Math.max(...all.map((p) => p.x));
576
- const yMax = niceMax(Math.max(...all.map((p) => p.y)));
577
- const yTicks = [
578
- 0,
579
- .25,
580
- .5,
581
- .75,
582
- 1
583
- ].map((f) => f * yMax);
1197
+ const y = yScale(all.map((p) => p.y), {
1198
+ min: yMin,
1199
+ max: yMax
1200
+ });
584
1201
  const pad = {
585
1202
  top: 16,
586
1203
  right: 16,
@@ -590,7 +1207,13 @@ function LineChart({ label, series, seriesLabel, planned, plannedLabel, band, fo
590
1207
  const w = Math.max(0, width - pad.left - pad.right);
591
1208
  const h = height - pad.top - pad.bottom;
592
1209
  const sx = (x) => pad.left + (x - xMin) / (xMax - xMin || 1) * w;
593
- const sy = (y) => pad.top + h - y / yMax * h;
1210
+ const sy = (v) => pad.top + h - (v - y.min) / (y.max - y.min) * h;
1211
+ const xLabelWidth = (t) => labelWidth(formatX(t));
1212
+ const xLabelAt = (t) => {
1213
+ const half = xLabelWidth(t) / 2;
1214
+ return Math.min(Math.max(sx(t), half), Math.max(half, width - half));
1215
+ };
1216
+ const shownXTicks = fitTicks(xTicks, xLabelAt, xLabelWidth);
594
1217
  const path = (pts) => pts.map((p, i) => `${i ? "L" : "M"}${sx(p.x).toFixed(1)},${sy(p.y).toFixed(1)}`).join("");
595
1218
  const last = series[series.length - 1];
596
1219
  const peak = series.reduce((a, b) => b.y > a.y ? b : a, series[0]);
@@ -616,26 +1239,26 @@ function LineChart({ label, series, seriesLabel, planned, plannedLabel, band, fo
616
1239
  gradientUnits: "userSpaceOnUse",
617
1240
  x1: 0,
618
1241
  x2: 0,
619
- y1: sy(0),
620
- y2: sy(yMax),
1242
+ y1: sy(y.min),
1243
+ y2: sy(y.max),
621
1244
  children: stops.map((s) => /* @__PURE__ */ jsx("stop", {
622
- offset: Math.min(1, Math.max(0, s.at / yMax)),
1245
+ offset: Math.min(1, Math.max(0, (s.at - y.min) / (y.max - y.min))),
623
1246
  stopColor: s.colour
624
1247
  }, s.at))
625
1248
  }) }),
626
- band && /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("rect", {
1249
+ band && band.below > y.min && /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("rect", {
627
1250
  x: pad.left,
628
- y: sy(band.below),
1251
+ y: sy(Math.min(band.below, y.max)),
629
1252
  width: w,
630
- height: sy(0) - sy(band.below),
1253
+ height: sy(y.min) - sy(Math.min(band.below, y.max)),
631
1254
  fill: "var(--success-subtle)"
632
1255
  }), /* @__PURE__ */ jsx("text", {
633
1256
  x: pad.left + 8,
634
- y: sy(band.below) + 16,
1257
+ y: sy(Math.min(band.below, y.max)) + 16,
635
1258
  className: "fill-success type-caption",
636
1259
  children: band.label
637
1260
  })] }),
638
- yTicks.map((t) => /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("line", {
1261
+ y.ticks.map((t) => /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("line", {
639
1262
  x1: pad.left,
640
1263
  x2: pad.left + w,
641
1264
  y1: sy(t),
@@ -650,8 +1273,8 @@ function LineChart({ label, series, seriesLabel, planned, plannedLabel, band, fo
650
1273
  className: "fill-muted-foreground type-caption tabular-nums",
651
1274
  children: formatY(t)
652
1275
  })] }, t)),
653
- xTicks.map((t) => /* @__PURE__ */ jsx("text", {
654
- x: sx(t),
1276
+ shownXTicks.map((t) => /* @__PURE__ */ jsx("text", {
1277
+ x: xLabelAt(t),
655
1278
  y: height - 8,
656
1279
  textAnchor: "middle",
657
1280
  className: "fill-muted-foreground type-caption tabular-nums",
@@ -810,56 +1433,167 @@ function PageHeader({ title, scope, actions, finding, as: Heading = "h1" }) {
810
1433
  });
811
1434
  }
812
1435
  // src/components/undo.tsx
813
- /** Schedules a reversible removal to commit after `windowMs` unless undone. A second removal, or unmounting, commits the pending one. */
814
- function useUndoable(windowMs = 8e3) {
1436
+ /**
1437
+ * Schedules a reversible removal to commit after a window unless undone, and owns which items
1438
+ * are out of view meanwhile.
1439
+ *
1440
+ * Only one removal is pending at a time: scheduling a second commits the first immediately.
1441
+ * Unmounting inside the window commits the pending removal (leaving is not Undo), so a navigation
1442
+ * or a test that unmounts still sends the commit's request: await `flush()` before a dependent
1443
+ * action, and in tests let MSW answer the request or flush before unmounting.
1444
+ */
1445
+ function useUndoable(options = {}) {
1446
+ const { windowMs = 8e3, describeError = describeActionError } = typeof options === "number" ? { windowMs: options } : options;
815
1447
  const [pending, setPending] = React.useState(null);
1448
+ const [failed, setFailed] = React.useState(null);
1449
+ const [removed, setRemoved] = React.useState(() => /* @__PURE__ */ new Set());
816
1450
  const current = React.useRef(null);
817
1451
  const timer = React.useRef(void 0);
818
- const set = React.useCallback((p) => {
819
- current.current = p;
820
- setPending(p);
1452
+ const mounted = React.useRef(true);
1453
+ const inFlight = React.useRef(/* @__PURE__ */ new Set());
1454
+ const describe = React.useRef(describeError);
1455
+ describe.current = describeError;
1456
+ const hide = React.useCallback((p, out) => {
1457
+ const ids = p.ids ?? [p.id];
1458
+ setRemoved((s) => {
1459
+ if (ids.every((id) => s.has(id) === out)) return s;
1460
+ const n = new Set(s);
1461
+ for (const id of ids) if (out) n.add(id);
1462
+ else n.delete(id);
1463
+ return n;
1464
+ });
821
1465
  }, []);
822
- const schedule = React.useCallback((next) => {
1466
+ const attempt = React.useCallback((p) => {
1467
+ let result;
1468
+ try {
1469
+ result = p.commit();
1470
+ } catch (error) {
1471
+ result = Promise.reject(error);
1472
+ }
1473
+ const done = Promise.resolve(result).then(() => void 0, (error) => {
1474
+ if (mounted.current) {
1475
+ hide(p, false);
1476
+ setFailed({
1477
+ removal: p,
1478
+ message: describe.current(error)
1479
+ });
1480
+ }
1481
+ p.onError?.(error);
1482
+ throw error;
1483
+ });
1484
+ inFlight.current.add(done);
1485
+ const settle = () => void inFlight.current.delete(done);
1486
+ done.then(settle, settle);
1487
+ return done;
1488
+ }, [hide]);
1489
+ const take = React.useCallback(() => {
823
1490
  window.clearTimeout(timer.current);
824
- current.current?.commit();
825
- set(next);
826
- timer.current = window.setTimeout(() => {
827
- current.current?.commit();
828
- set(null);
829
- }, windowMs);
830
- }, [set, windowMs]);
1491
+ const p = current.current;
1492
+ if (!p) return null;
1493
+ current.current = null;
1494
+ if (mounted.current) setPending(null);
1495
+ return {
1496
+ removal: p,
1497
+ done: attempt(p)
1498
+ };
1499
+ }, [attempt]);
1500
+ const commitDetached = React.useCallback(() => {
1501
+ const t = take();
1502
+ t?.done.catch((error) => {
1503
+ if (!mounted.current && !t.removal.onError) throw error;
1504
+ });
1505
+ }, [take]);
1506
+ const schedule = React.useCallback((next) => {
1507
+ commitDetached();
1508
+ setFailed(null);
1509
+ hide(next, true);
1510
+ current.current = next;
1511
+ setPending(next);
1512
+ timer.current = window.setTimeout(commitDetached, windowMs);
1513
+ }, [
1514
+ commitDetached,
1515
+ hide,
1516
+ windowMs
1517
+ ]);
831
1518
  const undo = React.useCallback(() => {
832
1519
  window.clearTimeout(timer.current);
833
- set(null);
834
- }, [set]);
835
- React.useEffect(() => () => {
836
- window.clearTimeout(timer.current);
837
- current.current?.commit();
1520
+ const p = current.current;
838
1521
  current.current = null;
839
- }, []);
1522
+ setPending(null);
1523
+ if (p) hide(p, false);
1524
+ }, [hide]);
1525
+ const flush = React.useCallback(async () => {
1526
+ take();
1527
+ const failure = (await Promise.allSettled([...inFlight.current])).find((r) => r.status === "rejected");
1528
+ if (failure) throw failure.reason;
1529
+ }, [take]);
1530
+ const retry = React.useCallback(() => {
1531
+ if (!failed) return Promise.resolve();
1532
+ setFailed(null);
1533
+ hide(failed.removal, true);
1534
+ return attempt(failed.removal);
1535
+ }, [
1536
+ attempt,
1537
+ failed,
1538
+ hide
1539
+ ]);
1540
+ const dismiss = React.useCallback(() => setFailed(null), []);
1541
+ const isRemoved = React.useCallback((id) => removed.has(id), [removed]);
1542
+ React.useEffect(() => {
1543
+ mounted.current = true;
1544
+ return () => {
1545
+ mounted.current = false;
1546
+ commitDetached();
1547
+ };
1548
+ }, [commitDetached]);
840
1549
  return {
841
1550
  pending,
1551
+ failed,
1552
+ isRemoved,
842
1553
  schedule,
843
- undo
1554
+ undo,
1555
+ flush,
1556
+ retry,
1557
+ dismiss
844
1558
  };
845
1559
  }
846
- /** The polite live region that shows a pending removal with an Undo button. */
847
- function UndoBar({ pending, onUndo, inline = false }) {
1560
+ /** The polite live region that shows a pending removal with Undo, or a failed one with Try again. Pass it the whole `useUndoable()` result. */
1561
+ function UndoBar({ undoable, inline = false }) {
1562
+ const { pending, failed, undo, retry, dismiss } = undoable;
1563
+ const ghost = "text-background hover:bg-neutral-11";
848
1564
  return /* @__PURE__ */ jsx("div", {
849
1565
  "aria-live": "polite",
850
1566
  className: inline ? "flex" : "pointer-events-none fixed inset-x-0 bottom-4 z-50 flex justify-center px-4",
851
- children: pending && /* @__PURE__ */ jsxs("div", {
1567
+ children: (pending || failed) && /* @__PURE__ */ jsx("div", {
852
1568
  className: "pointer-events-auto flex max-w-lg items-center gap-4 rounded-overlay bg-foreground py-2 pr-2 pl-4 text-background shadow-overlay",
853
- children: [/* @__PURE__ */ jsx("p", {
1569
+ children: pending ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("p", {
854
1570
  className: "min-w-0 type-body-sm",
855
1571
  children: pending.message
856
1572
  }), /* @__PURE__ */ jsx(Button, {
857
1573
  size: "sm",
858
1574
  variant: "ghost",
859
- className: "text-background hover:bg-neutral-11",
860
- onClick: onUndo,
1575
+ className: ghost,
1576
+ onClick: undo,
861
1577
  children: "Undo"
862
- })]
1578
+ })] }) : failed && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("p", {
1579
+ className: "min-w-0 type-body-sm",
1580
+ children: failed.message ? `${failed.removal.failure} ${failed.message}` : failed.removal.failure
1581
+ }), /* @__PURE__ */ jsxs("div", {
1582
+ className: "flex shrink-0 gap-1",
1583
+ children: [/* @__PURE__ */ jsx(Button, {
1584
+ size: "sm",
1585
+ variant: "ghost",
1586
+ className: ghost,
1587
+ onClick: () => void retry().catch(() => void 0),
1588
+ children: "Try again"
1589
+ }), /* @__PURE__ */ jsx(Button, {
1590
+ size: "sm",
1591
+ variant: "ghost",
1592
+ className: ghost,
1593
+ onClick: dismiss,
1594
+ children: "Dismiss"
1595
+ })]
1596
+ })] })
863
1597
  })
864
1598
  });
865
1599
  }
@@ -1037,6 +1771,321 @@ function Tabs({ param, items, label, children, className }) {
1037
1771
  })]
1038
1772
  });
1039
1773
  }
1040
- export { AppShell, AsyncButton, Breadcrumb, Button, COLOR_SCHEME_STORAGE_KEY, ChoiceGroup, ColorSchemeChoice, DataTable, DataView, Done, EmptyState, Field, HttpError, IconButton, Input, LineChart, Metric, MetricStrip, NBSP, NativeSelect, PageHeader, SideNav, Skeleton, Status, StrataQueryProvider, TableSkeleton, Tabs, Textarea, ThemeProvider, UndoBar, VirtualList, buttonVariants, cn, colorSchemeScript, createFormat, createQueryClient, describeActionError, describeHttpError, fetchJson, format, parseSort, serialiseSort, toLoad, typeSteps, useAsyncAction, useColorScheme, useLoad, useSystemColorScheme, useUndoable };
1774
+ // src/components/hotkeys.tsx
1775
+ var TEXT_INPUTS_EXEMPT = /* @__PURE__ */ new Set([
1776
+ "checkbox",
1777
+ "radio",
1778
+ "button",
1779
+ "submit",
1780
+ "reset",
1781
+ "range",
1782
+ "color",
1783
+ "file"
1784
+ ]);
1785
+ /** True when a key pressed on this element is the person typing, so single-key shortcuts must leave it alone. */
1786
+ function isTypingTarget(target) {
1787
+ if (!(target instanceof HTMLElement)) return false;
1788
+ if (target.isContentEditable || target.closest("[contenteditable=''],[contenteditable='true']")) return true;
1789
+ if (target instanceof HTMLTextAreaElement || target instanceof HTMLSelectElement) return true;
1790
+ if (target instanceof HTMLInputElement) return !TEXT_INPUTS_EXEMPT.has(target.type);
1791
+ return false;
1792
+ }
1793
+ function toShortcuts(input) {
1794
+ return Array.isArray(input) ? input : Object.entries(input).map(([key, run]) => ({
1795
+ keys: [key],
1796
+ label: key,
1797
+ run
1798
+ }));
1799
+ }
1800
+ /**
1801
+ * Binds single-key shortcuts on the window, ignoring keys typed into fields, chords with Ctrl, Meta
1802
+ * or Alt, IME composition and (unless `repeat`) held keys. Pass the same list to `KeysLegend`.
1803
+ */
1804
+ function useHotkeys(shortcuts, { enabled = true } = {}) {
1805
+ const latest = React.useRef([]);
1806
+ latest.current = toShortcuts(shortcuts);
1807
+ React.useEffect(() => {
1808
+ if (!enabled) return;
1809
+ const onKeyDown = (e) => {
1810
+ if (e.defaultPrevented || e.isComposing || e.ctrlKey || e.metaKey || e.altKey) return;
1811
+ if (isTypingTarget(e.target)) return;
1812
+ const hit = latest.current.find((s) => !s.disabled && s.keys.includes(e.key));
1813
+ if (!hit || e.repeat && !hit.repeat) return;
1814
+ e.preventDefault();
1815
+ hit.run();
1816
+ };
1817
+ window.addEventListener("keydown", onKeyDown);
1818
+ return () => window.removeEventListener("keydown", onKeyDown);
1819
+ }, [enabled]);
1820
+ }
1821
+ var KEY_NAMES = {
1822
+ ArrowDown: "↓",
1823
+ ArrowUp: "↑",
1824
+ ArrowLeft: "←",
1825
+ ArrowRight: "→",
1826
+ Escape: "Esc",
1827
+ Enter: "Enter",
1828
+ Backspace: "Backspace",
1829
+ Delete: "Delete",
1830
+ " ": "Space"
1831
+ };
1832
+ /** A quiet legend of the screen's shortcuts, from the same list `useHotkeys` binds. Hidden on touch screens. */
1833
+ function KeysLegend({ shortcuts, label = "Keyboard shortcuts", className }) {
1834
+ return /* @__PURE__ */ jsx("dl", {
1835
+ "aria-label": label,
1836
+ className: cn("flex flex-wrap gap-x-4 gap-y-1 type-caption text-muted-foreground pointer-coarse:hidden", className),
1837
+ children: shortcuts.map((s) => /* @__PURE__ */ jsxs("div", {
1838
+ className: cn("flex items-center gap-1.5", s.disabled && "opacity-50"),
1839
+ children: [/* @__PURE__ */ jsx("dt", {
1840
+ className: "flex items-center gap-1",
1841
+ children: s.keys.map((k, i) => /* @__PURE__ */ jsxs(React.Fragment, { children: [i > 0 && /* @__PURE__ */ jsx("span", {
1842
+ className: "sr-only",
1843
+ children: " or "
1844
+ }), /* @__PURE__ */ jsx("kbd", {
1845
+ className: "min-w-5 rounded-control border border-border bg-surface-sunken px-1 text-center font-mono text-foreground",
1846
+ children: KEY_NAMES[k] ?? k
1847
+ })] }, k))
1848
+ }), /* @__PURE__ */ jsx("dd", { children: s.label })]
1849
+ }, s.keys.join(" ")))
1850
+ });
1851
+ }
1852
+ // src/components/active-list.tsx
1853
+ /** Tracks the active item in a list worked through from the keyboard: moving, roving focus, and moving on when the active item is removed. */
1854
+ function useActiveItem(items, getKey, { initial, noun } = {}) {
1855
+ const [chosen, setChosen] = React.useState(initial ?? null);
1856
+ const lastIndex = React.useRef(0);
1857
+ const elements = React.useRef(/* @__PURE__ */ new Map());
1858
+ const navigated = React.useRef(false);
1859
+ const focusWithin = React.useRef(false);
1860
+ const keys = items.map(getKey);
1861
+ let index = chosen === null ? -1 : keys.indexOf(chosen);
1862
+ if (index === -1 && keys.length > 0) index = Math.min(lastIndex.current, keys.length - 1);
1863
+ const activeKey = index >= 0 ? keys[index] : null;
1864
+ const prevActive = React.useRef(activeKey);
1865
+ React.useLayoutEffect(() => {
1866
+ if (index >= 0) lastIndex.current = index;
1867
+ const gone = prevActive.current;
1868
+ prevActive.current = activeKey;
1869
+ if (gone !== null && gone !== chosen && !keys.includes(gone)) setChosen(gone);
1870
+ });
1871
+ React.useLayoutEffect(() => {
1872
+ const el = activeKey === null ? void 0 : elements.current.get(activeKey);
1873
+ const focused = document.activeElement;
1874
+ const lost = focusWithin.current && (focused === null || focused === document.body);
1875
+ const elsewhereInList = focused !== null && !el?.contains(focused) && [...elements.current.values()].some((item) => item.contains(focused));
1876
+ if (el && (navigated.current || lost || elsewhereInList)) {
1877
+ el.focus({ preventScroll: true });
1878
+ el.scrollIntoView?.({ block: "nearest" });
1879
+ }
1880
+ navigated.current = false;
1881
+ }, [activeKey]);
1882
+ const moveTo = (i) => {
1883
+ if (keys.length === 0) return;
1884
+ const to = Math.max(0, Math.min(keys.length - 1, i));
1885
+ navigated.current = true;
1886
+ if (to === index) {
1887
+ const el = elements.current.get(keys[to]);
1888
+ el?.focus({ preventScroll: true });
1889
+ el?.scrollIntoView?.({ block: "nearest" });
1890
+ navigated.current = false;
1891
+ }
1892
+ setChosen(keys[to]);
1893
+ };
1894
+ const next = () => moveTo(index + 1);
1895
+ const prev = () => moveTo(index - 1);
1896
+ const first = () => moveTo(0);
1897
+ const last = () => moveTo(keys.length - 1);
1898
+ const setActive = (key) => {
1899
+ const i = keys.indexOf(key);
1900
+ if (i >= 0) moveTo(i);
1901
+ };
1902
+ const name = noun ? ` ${noun}` : "";
1903
+ const shortcuts = [{
1904
+ keys: ["j"],
1905
+ label: `Next${name}`,
1906
+ run: next,
1907
+ repeat: true,
1908
+ disabled: keys.length === 0
1909
+ }, {
1910
+ keys: ["k"],
1911
+ label: `Previous${name}`,
1912
+ run: prev,
1913
+ repeat: true,
1914
+ disabled: keys.length === 0
1915
+ }];
1916
+ const itemProps = (key) => ({
1917
+ ref: (el) => {
1918
+ if (el) elements.current.set(key, el);
1919
+ else elements.current.delete(key);
1920
+ },
1921
+ tabIndex: key === activeKey ? 0 : -1,
1922
+ "aria-current": key === activeKey ? "true" : void 0,
1923
+ "data-active": key === activeKey ? "" : void 0,
1924
+ onFocus: () => {
1925
+ focusWithin.current = true;
1926
+ if (key !== activeKey) setChosen(key);
1927
+ },
1928
+ onBlur: (e) => {
1929
+ const to = e.relatedTarget;
1930
+ if (to instanceof Node && ![...elements.current.values()].some((el) => el.contains(to))) focusWithin.current = false;
1931
+ }
1932
+ });
1933
+ return {
1934
+ items,
1935
+ getKey,
1936
+ activeKey,
1937
+ activeItem: index >= 0 ? items[index] : null,
1938
+ index,
1939
+ next,
1940
+ prev,
1941
+ first,
1942
+ last,
1943
+ setActive,
1944
+ shortcuts,
1945
+ itemProps
1946
+ };
1947
+ }
1948
+ /** A keyboard-worked queue: the active item is a roving tab stop with aria-current, and the arrow keys, Home and End move it. */
1949
+ function ActiveList({ label, active, empty, children, className }) {
1950
+ if (active.items.length === 0) return /* @__PURE__ */ jsx(Fragment, { children: empty });
1951
+ const onKeyDown = (e) => {
1952
+ if (e.ctrlKey || e.metaKey || e.altKey || isTypingTarget(e.target)) return;
1953
+ const move = e.key === "ArrowDown" ? active.next : e.key === "ArrowUp" ? active.prev : e.key === "Home" ? active.first : e.key === "End" ? active.last : void 0;
1954
+ if (!move) return;
1955
+ e.preventDefault();
1956
+ move();
1957
+ };
1958
+ return /* @__PURE__ */ jsx("ul", {
1959
+ "aria-label": label,
1960
+ onKeyDown,
1961
+ className: cn("grid gap-px", className),
1962
+ children: active.items.map((item) => {
1963
+ const key = active.getKey(item);
1964
+ const isActive = key === active.activeKey;
1965
+ return /* @__PURE__ */ jsx("li", {
1966
+ ...active.itemProps(key),
1967
+ className: cn("rounded-control border-l-2 px-3 py-2 -outline-offset-2", isActive ? "border-foreground bg-accent text-accent-foreground" : "border-transparent"),
1968
+ children: children(item, { active: isActive })
1969
+ }, key);
1970
+ })
1971
+ });
1972
+ }
1973
+ // src/query/infinite.ts
1974
+ /** `useInfiniteQuery` for cursor-paged data, returned as an `InfiniteLoad<T>` for `InfiniteList` (or `DataView`). */
1975
+ function useInfiniteLoad({ queryKey, queryFn, items, itemKey, hasMore, cursorAfter = itemKey, isRemoved, describeError = describeHttpError, enabled, staleTime }) {
1976
+ const queryHash = hashKey(queryKey);
1977
+ const [stored, setStored] = React.useState(() => ({
1978
+ query: queryHash,
1979
+ keys: /* @__PURE__ */ new Set()
1980
+ }));
1981
+ const dismissed = stored.query === queryHash ? stored.keys : none;
1982
+ const hidden = React.useCallback((key) => dismissed.has(key) || (isRemoved?.(key) ?? false), [dismissed, isRemoved]);
1983
+ const latest = React.useRef({
1984
+ hidden,
1985
+ items,
1986
+ itemKey,
1987
+ hasMore,
1988
+ cursorAfter
1989
+ });
1990
+ latest.current = {
1991
+ hidden,
1992
+ items,
1993
+ itemKey,
1994
+ hasMore,
1995
+ cursorAfter
1996
+ };
1997
+ const query = useInfiniteQuery({
1998
+ queryKey,
1999
+ queryFn: ({ pageParam, signal }) => queryFn({
2000
+ cursor: pageParam.cursor,
2001
+ signal
2002
+ }),
2003
+ initialPageParam: { cursor: void 0 },
2004
+ getNextPageParam: (lastPage, pages) => {
2005
+ const l = latest.current;
2006
+ if (!l.hasMore(lastPage)) return null;
2007
+ const after = nextAfter(pages, l.items, l.itemKey, l.hidden);
2008
+ return { cursor: after === void 0 ? void 0 : l.cursorAfter(after) };
2009
+ },
2010
+ enabled,
2011
+ staleTime
2012
+ });
2013
+ const pages = query.data?.pages;
2014
+ const list = React.useMemo(() => pages ? merge(pages, latest.current.items, latest.current.itemKey, hidden).held : void 0, [pages, hidden]);
2015
+ const { hasNextPage, isFetchingNextPage, fetchNextPage, refetch } = query;
2016
+ const loadMore = React.useCallback(() => {
2017
+ if (hasNextPage && !isFetchingNextPage) fetchNextPage();
2018
+ }, [
2019
+ hasNextPage,
2020
+ isFetchingNextPage,
2021
+ fetchNextPage
2022
+ ]);
2023
+ const change = React.useCallback((edit) => setStored((s) => {
2024
+ const keys = new Set(s.query === queryHash ? s.keys : none);
2025
+ edit(keys);
2026
+ return {
2027
+ query: queryHash,
2028
+ keys
2029
+ };
2030
+ }), [queryHash]);
2031
+ const dismiss = React.useCallback((key) => change((keys) => keys.add(key)), [change]);
2032
+ const restore = React.useCallback((key) => change((keys) => keys.delete(key)), [change]);
2033
+ const extra = {
2034
+ more: {
2035
+ hasMore: Boolean(hasNextPage),
2036
+ loadingMore: isFetchingNextPage,
2037
+ error: query.isFetchNextPageError ? describeError(query.error) : void 0,
2038
+ loadMore
2039
+ },
2040
+ itemKey,
2041
+ dismiss,
2042
+ restore
2043
+ };
2044
+ if (list) return {
2045
+ status: "ready",
2046
+ data: list,
2047
+ ...extra
2048
+ };
2049
+ if (query.status === "error") return {
2050
+ status: "error",
2051
+ message: describeError(query.error),
2052
+ retry: () => void refetch(),
2053
+ ...extra
2054
+ };
2055
+ return {
2056
+ status: "loading",
2057
+ ...extra
2058
+ };
2059
+ }
2060
+ var none = /* @__PURE__ */ new Set();
2061
+ /** Every page's items, in order, once each by key: the ones held (not dismissed) and the last one seen. */
2062
+ function merge(pages, items, itemKey, hidden) {
2063
+ const seen = /* @__PURE__ */ new Set();
2064
+ const held = [];
2065
+ let last;
2066
+ let lastPageAddedAny = false;
2067
+ pages.forEach((page, p) => {
2068
+ for (const item of items(page)) {
2069
+ const key = itemKey(item);
2070
+ if (seen.has(key)) continue;
2071
+ seen.add(key);
2072
+ last = item;
2073
+ if (p === pages.length - 1) lastPageAddedAny = true;
2074
+ if (!hidden(key)) held.push(item);
2075
+ }
2076
+ });
2077
+ return {
2078
+ held,
2079
+ last,
2080
+ lastPageAddedAny
2081
+ };
2082
+ }
2083
+ /** The item the next page goes after: the last held, or the last seen when nothing is held or the last page brought nothing new. */
2084
+ function nextAfter(pages, items, itemKey, hidden) {
2085
+ const { held, last, lastPageAddedAny } = merge(pages, items, itemKey, hidden);
2086
+ if (held.length === 0 || pages.length > 1 && !lastPageAddedAny) return last;
2087
+ return held[held.length - 1];
2088
+ }
2089
+ export { ActiveList, AppShell, AsyncButton, Breadcrumb, BulkBar, Button, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGroup, ColorSchemeChoice, CompositionBar, DataTable, DataView, Done, EmptyState, Field, HttpError, IconButton, InfiniteList, Input, KeysLegend, LineChart, LinkCard, LinkCardList, Meter, Metric, MetricStrip, NBSP, NativeSelect, PageHeader, RowAction, SideNav, Skeleton, Status, StrataQueryProvider, TableSkeleton, Tabs, Textarea, ThemeProvider, UndoBar, VirtualList, buttonVariants, cn, colorSchemeScript, createFormat, createQueryClient, crossedThreshold, describeActionError, describeHttpError, fetchJson, format, isTypingTarget, parseSort, serialiseSort, toLoad, typeSteps, useActiveItem, useAsyncAction, useColorScheme, useHotkeys, useInfiniteLoad, useLoad, useSelection, useSystemColorScheme, useUndoable };
1041
2090
 
1042
2091
  //# sourceMappingURL=index.js.map