@sincpro/web-ui 2.17.0 → 2.18.1

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/README.md CHANGED
@@ -359,8 +359,8 @@ The parts: `button`, `icon-button`, `control`, `popover`, `menu`, `menu.trigger`
359
359
  `kiosk.content`, `kiosk.reach`, `board.tile`,
360
360
  `board.stat`, `board.stat.value`, `activity.changes`, `file-list`, `file-list.file`, `file-value`, `metric`, `metric.detail`, `tag`, `tags.item`, `search`, `search.field`, `search.chip`, `search.facet-mark`,
361
361
  `search.panel`, `search.suggestions`, `search.suggestion`, `search.record`, `search.recent`,
362
- `search.advanced`, `search.keys`, `search.completion`, `search.undo`, `search.slash`, `search-entry`, `search-entry.keys`, `table`, `table.pile`, `yes-no`,
363
- `table.head`, `row.ways`, `topbar`, `topbar.brand`, `topbar.menus`, `topbar.actions`, `topbar.user`,
362
+ `search.advanced`, `search.keys`, `search.completion`, `search.undo`, `search.slash`, `search-entry`, `search-entry.keys`, `table`, `table.pile`, `list.pile`, `yes-no`,
363
+ `table.head`, `table.grip`, `row.ways`, `topbar`, `topbar.brand`, `topbar.menus`, `topbar.actions`, `topbar.user`,
364
364
  `frame`, `frame.banner`, `frame.bar`, `frame.sidebar`, `frame.main`, `banner`, `banner.action`,
365
365
  `inbox`, `inbox.item` (with `data-unread`), `kbd`, `plans`, `plan` (with `data-highlight`, `data-current`), `plan.highlight`, `plan.price`,
366
366
  `plan.features`, `plan.action`, `qr`, `price`, `price.before`, `range-slider`, `rating`, `gallery`,
@@ -66,7 +66,7 @@ export function RecordCalendar({ items, keyOf, titleOf, startOf, endOf, allDayOf
66
66
  return renderEvent(item, info.timeText);
67
67
  const person = avatarOf?.(item);
68
68
  const meta = metaOf?.(item);
69
- return (_jsxs("span", { className: "flex min-w-0 items-start gap-1.5 px-0.5 py-px", children: [person === undefined ? null : (_jsx(Avatar, { name: person.name, size: "sm", ...(person.src === undefined ? {} : { src: person.src }) })), _jsxs("span", { className: "flex min-w-0 flex-col", children: [_jsxs("span", { className: "min-w-0 truncate", children: [info.timeText === "" ? null : (_jsxs("b", { className: "font-semibold tabular-nums", children: [info.timeText, " "] })), titleOf(item)] }), meta === undefined ? null : (_jsx("span", { className: "min-w-0 truncate opacity-80", children: meta }))] })] }));
69
+ return (_jsxs("span", { className: "flex min-w-0 items-start gap-1.5 px-0.5 py-px", children: [person === undefined ? null : (_jsx(Avatar, { name: person.name, size: "xs", ...(person.src === undefined ? {} : { src: person.src }) })), _jsxs("span", { className: "flex min-w-0 flex-col", children: [_jsxs("span", { className: "min-w-0 truncate", children: [info.timeText === "" ? null : (_jsxs("b", { className: "font-semibold tabular-nums", children: [info.timeText, " "] })), titleOf(item)] }), meta === undefined ? null : (_jsx("span", { className: "min-w-0 truncate opacity-80", children: meta }))] })] }));
70
70
  };
71
71
  const moved = (info) => {
72
72
  const item = byId.get(info.event.id);
@@ -6,7 +6,7 @@ import { byDensity, useDensity } from "../../foundations/density.js";
6
6
  import { bySurface, useSurface } from "../../foundations/surface.js";
7
7
  import { useViewStyle } from "../../foundations/viewStyle.js";
8
8
  import { ChevronLeft, ChevronRight } from "lucide-react";
9
- import { useId, useState } from "react";
9
+ import { useEffect, useId, useRef, useState } from "react";
10
10
  /* ---------------------------------------------------------------- *
11
11
  * THE FOOTER AND ITS PAGINATION
12
12
  * ---------------------------------------------------------------- */
@@ -40,6 +40,15 @@ export function Pagination({ from, to, total, pageSize, pageSizes = PAGE_SIZES,
40
40
  const [editing, setEditing] = useState(false);
41
41
  const [draft, setDraft] = useState("");
42
42
  const listId = useId();
43
+ const range = useRef(null);
44
+ /* Back to the range once the size is set or dropped: the field goes away under the focus,
45
+ and a focus left on the page's body sends the next Tab to its first control. */
46
+ const wasEditing = useRef(false);
47
+ useEffect(() => {
48
+ if (wasEditing.current && !editing)
49
+ range.current?.focus();
50
+ wasEditing.current = editing;
51
+ }, [editing]);
43
52
  /* The modern style's position is the record's pager's: one translucent primary pill, so a
44
53
  list and a record say «where I am in the set» the same way. */
45
54
  const style = useViewStyle();
@@ -58,6 +67,9 @@ export function Pagination({ from, to, total, pageSize, pageSizes = PAGE_SIZES,
58
67
  ? [...pageSizes, pageSize]
59
68
  : pageSizes;
60
69
  function commitSize(raw) {
70
+ /* Enter commits and the field leaves; its blur on the way out must not commit twice. */
71
+ if (!editing)
72
+ return;
61
73
  const next = Number(raw);
62
74
  if (!Number.isFinite(next) || next < 1) {
63
75
  setEditing(false);
@@ -75,8 +87,21 @@ export function Pagination({ from, to, total, pageSize, pageSizes = PAGE_SIZES,
75
87
  }
76
88
  if (e.key === "Escape")
77
89
  setEditing(false);
78
- }, "aria-label": copy.pager.size, className: `h-(--size-control-sm) w-24 rounded-control border px-1.5 text-micro tabular-nums focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary ${bySurface(activeSurface, "border-line-strong bg-surface text-ink", "border-chrome-ink/45 bg-chrome-ink/8 text-chrome-ink")}` }), _jsx("datalist", { id: listId, children: sizes.map((n) => (_jsx("option", { value: n }, n))) })] })) : (_jsxs("span", { className: `tabular-nums whitespace-nowrap ${pill ? "text-meta font-semibold" : "text-micro"} ${faint}`, children: [canEdit ? (_jsxs("button", { type: "button", onClick: () => {
90
+ }, "aria-label": copy.pager.size,
91
+ /* Inside the pill it is a pill: a square box there broke the one shape the
92
+ position has. */
93
+ className: `h-(--size-control-sm) w-24 border px-1.5 tabular-nums focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary ${pill
94
+ ? "rounded-pill px-2.5 text-meta font-semibold"
95
+ : "rounded-control text-micro"} ${bySurface(activeSurface, pill
96
+ ? "border-primary/30 bg-surface text-primary"
97
+ : "border-line-strong bg-surface text-ink", "border-chrome-ink/45 bg-chrome-ink/8 text-chrome-ink")}` }), _jsx("datalist", { id: listId, children: sizes.map((n) => (_jsx("option", { value: n }, n))) })] })) : (_jsxs("span", { className: `tabular-nums whitespace-nowrap ${pill ? "text-meta font-semibold" : "text-micro"} ${faint}`, children: [canEdit ? (_jsxs("button", { ref: range, type: "button", onClick: () => {
79
98
  setDraft(String(pageSize));
80
99
  setEditing(true);
81
- }, title: fillCopy(copy.pager.sizeHint, { size: pageSize ?? 0 }), className: `rounded-control underline decoration-dotted underline-offset-4 transition-colors duration-(--duration-instant) ${strong} ${bySurface(activeSurface, "decoration-line-strong hover:decoration-primary", "decoration-chrome-ink/40 hover:decoration-chrome-link")} focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary`, children: [from.toLocaleString(copy.locale), "\u2013", to.toLocaleString(copy.locale)] })) : (_jsxs("span", { className: strong, children: [from.toLocaleString(copy.locale), "\u2013", to.toLocaleString(copy.locale)] })), _jsx("span", { className: "mx-1", children: "/" }), total.toLocaleString(copy.locale)] })), _jsxs("span", { className: "flex items-center", children: [_jsx("button", { type: "button", onClick: onPrev, disabled: from <= 1, "aria-label": copy.pager.prev, title: copy.pager.prev, className: arrow, children: _jsx(ChevronLeft, { className: "size-(--size-icon-md)", strokeWidth: 2 }) }), _jsx("button", { type: "button", onClick: onNext, disabled: to >= total, "aria-label": copy.pager.next, title: copy.pager.next, className: arrow, children: _jsx(ChevronRight, { className: "size-(--size-icon-md)", strokeWidth: 2 }) })] })] }));
100
+ }, title: fillCopy(copy.pager.sizeHint, { size: pageSize ?? 0 }),
101
+ /* Plain, the range says it is touchable with a dotted underline. In the pill an
102
+ underline read as a typo under a label: there it lights up like the arrows
103
+ beside it, which are the pill's other buttons. */
104
+ className: `transition-colors duration-(--duration-instant) ${strong} ${pill
105
+ ? `-mx-1.5 -my-1 rounded-pill px-1.5 py-1 ${bySurface(activeSurface, "hover:bg-primary/15", "hover:bg-chrome-link/20")}`
106
+ : `rounded-control underline decoration-dotted underline-offset-4 ${bySurface(activeSurface, "decoration-line-strong hover:decoration-primary", "decoration-chrome-ink/40 hover:decoration-chrome-link")}`} focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary`, children: [from.toLocaleString(copy.locale), "\u2013", to.toLocaleString(copy.locale)] })) : (_jsxs("span", { className: strong, children: [from.toLocaleString(copy.locale), "\u2013", to.toLocaleString(copy.locale)] })), _jsx("span", { className: "mx-1", children: "/" }), total.toLocaleString(copy.locale)] })), _jsxs("span", { className: "flex items-center", children: [_jsx("button", { type: "button", onClick: onPrev, disabled: from <= 1, "aria-label": copy.pager.prev, title: copy.pager.prev, className: arrow, children: _jsx(ChevronLeft, { className: "size-(--size-icon-md)", strokeWidth: 2 }) }), _jsx("button", { type: "button", onClick: onNext, disabled: to >= total, "aria-label": copy.pager.next, title: copy.pager.next, className: arrow, children: _jsx(ChevronRight, { className: "size-(--size-icon-md)", strokeWidth: 2 }) })] })] }));
82
107
  }
@@ -132,7 +132,7 @@ export function RowHeader({ name, meta, tags, withSelection = false, withIcon =
132
132
  export function GroupHeader({ field, label, count, detail, depth = 0, open = true, onToggle, }) {
133
133
  const d = useDensity();
134
134
  const copy = useUiCopy();
135
- const content = (_jsxs(_Fragment, { children: [onToggle === undefined ? null : (_jsx(ChevronRight, { className: `size-(--size-icon-sm) shrink-0 text-muted transition-transform duration-(--duration-instant) ${open ? "rotate-90" : ""}`, strokeWidth: 2, "aria-hidden": true })), field === undefined ? null : (_jsx("span", { className: "shrink-0 text-micro text-muted", children: field })), _jsx("span", { className: "truncate text-micro font-medium text-ink", children: label }), count === undefined ? null : (_jsx("span", { className: "inline-flex shrink-0 items-center rounded-pill border border-line-strong bg-ink/5 px-2 py-0.5 text-micro tabular-nums text-muted", children: count.toLocaleString(copy.locale) })), detail === undefined ? null : (_jsx("span", { className: "shrink-0 text-micro tabular-nums text-muted", children: detail }))] }));
135
+ const content = (_jsxs(_Fragment, { children: [onToggle === undefined ? null : (_jsx(ChevronRight, { className: `size-(--size-icon-sm) shrink-0 text-muted transition-transform duration-(--duration-instant) ${open ? "rotate-90" : ""}`, strokeWidth: 2, "aria-hidden": true })), field === undefined ? null : (_jsx("span", { className: "shrink-0 text-micro text-muted", children: field })), _jsx("span", { className: "truncate text-meta font-medium text-ink", children: label }), count === undefined ? null : (_jsx("span", { className: "inline-flex shrink-0 items-center rounded-pill border border-line-strong bg-ink/5 px-2 py-0.5 text-micro tabular-nums text-muted", children: count.toLocaleString(copy.locale) })), detail === undefined ? null : (_jsx("span", { className: "shrink-0 text-micro tabular-nums text-muted", children: detail }))] }));
136
136
  /* The indentation goes in the left padding and not in a margin: the
137
137
  header has a background and a bottom border, and a margin would cut them before the
138
138
  list's edge — the band would stop reading as a stripe. The hover
@@ -140,7 +140,7 @@ export function GroupHeader({ field, label, count, detail, depth = 0, open = tru
140
140
  const box = `flex min-w-0 items-center gap-2 border-b border-line bg-ground ${byDensity(d, "px-3 py-1.5", "px-2.5 py-1")}`;
141
141
  const indent = depth === 0 ? undefined : { paddingLeft: `calc(var(--spacing-indent) * ${depth})` };
142
142
  const mark = (_jsx("span", { "aria-hidden": true, className: "pointer-events-none absolute inset-x-1 inset-y-0.5 rounded-control group-hover/head:bg-ink/4" }));
143
- return onToggle === undefined ? (_jsx("div", { className: box, style: indent, children: content })) : (_jsxs("button", { type: "button", onClick: onToggle, "aria-expanded": open, style: indent, className: `group/head relative ${box} w-full text-left focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-primary`, children: [mark, content] }));
143
+ return onToggle === undefined ? (_jsx("div", { "data-ui": "list.pile", className: box, style: indent, children: content })) : (_jsxs("button", { type: "button", "data-ui": "list.pile", onClick: onToggle, "aria-expanded": open, style: indent, className: `group/head relative ${box} w-full text-left focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-primary`, children: [mark, content] }));
144
144
  }
145
145
  /** Under a short pile: «Ver 50 más de 49.950», or «Se muestran 500 de 49.950» when there is
146
146
  * no next page. Indented like the pile's rows. */
@@ -36,7 +36,7 @@ export function ModelCell({ kind, value, }) {
36
36
  case "duration":
37
37
  return typeof value === "number" ? (
38
38
  /* Right aligned like `Numeric`: a column of hours lines up by the colon. */
39
- _jsx("span", { className: "block text-right text-body tabular-nums whitespace-nowrap text-ink", children: formatDuration(value) })) : (_jsx(Plain, { text: text }));
39
+ _jsx("span", { className: "block text-right tabular-nums whitespace-nowrap text-ink", children: formatDuration(value) })) : (_jsx(Plain, { text: text }));
40
40
  case "boolean":
41
41
  return typeof value === "boolean" ? _jsx(YesNo, { value: value }) : _jsx(Plain, { text: text });
42
42
  case "date":
@@ -1,3 +1,4 @@
1
+ import { type UiCopy } from "../../foundations/copy.js";
1
2
  import { type Pile } from "../../foundations/grouping.js";
2
3
  import type { Tone } from "../../foundations/types.js";
3
4
  import { type RowAction } from "./RowActions.js";
@@ -33,6 +34,9 @@ export declare function columnFormat<T>(column: DataColumn<T>, locale?: string):
33
34
  export declare function pileAggregate<T extends object>(column: DataColumn<T>, pile: Pile<T>): number | null;
34
35
  /** An aggregate of a column, written — or the bare number when nothing says how. */
35
36
  export declare function aggregateText<T>(column: DataColumn<T>, value: number): string | number;
37
+ /** A pile's or the footer's number as the table writes it: «Bs. 185.200,50», «máx 5». Exported
38
+ * for the presentations without columns, so a pile says the same thing in rows and tiles. */
39
+ export declare function aggregateLabel<T>(copy: UiCopy, column: DataColumn<T>, v: number): string;
36
40
  export interface DataColumn<T> {
37
41
  id: string;
38
42
  header: string;
@@ -178,7 +182,7 @@ export type GroupColumn<T> = {
178
182
  /** How that key is read. */
179
183
  labelOf: (key: string) => string;
180
184
  };
181
- export declare function DataTable<T extends object>({ data, columns, getRowId, sort, onSortChange, levels, selected, onSelectedChange, height, onRowClick, rowActions, totals, collapsed, onGroupToggle, piles, onMore, create, copyable, }: {
185
+ export declare function DataTable<T extends object>({ data, columns, getRowId, sort, onSortChange, levels, selected, onSelectedChange, height, onRowClick, rowActions, totals, collapsed, onGroupToggle, piles, onMore, create, copyable, onReorder, }: {
182
186
  data: readonly T[];
183
187
  columns: readonly DataColumn<T>[];
184
188
  getRowId: (row: T) => string;
@@ -227,4 +231,14 @@ export declare function DataTable<T extends object>({ data, columns, getRowId, s
227
231
  /** The cells' copy buttons, on by default. `false` takes them off the whole table; a
228
232
  * column turns its own off with `copy: false`. */
229
233
  copyable?: boolean;
234
+ /**
235
+ * The records are in an order a person sets by hand (a `sequence`): a grip at the start of
236
+ * each row drags it, Alt + ↑ / ↓ moves it — `EditableTable`'s, the same `useRowReorder`.
237
+ * `before` is the row it lands in front of, `null` the end: one move, true on a page too.
238
+ *
239
+ * Off while grouped (the piles decide the order) and while sorted by a column (a row
240
+ * dropped would jump back to where the sort puts it): the order shown has to be the one
241
+ * being changed.
242
+ */
243
+ onReorder?: (id: string, before: string | null) => void;
230
244
  }): import("react").JSX.Element;
@@ -10,6 +10,7 @@ import { EditRow, firstControl } from "./EditableTable.js";
10
10
  import { levelNameOf } from "./levels.js";
11
11
  import { PileFootLine } from "./PileFootLine.js";
12
12
  import { RowActions } from "./RowActions.js";
13
+ import { useRowReorder } from "./rowReorder.js";
13
14
  import { useRowWindow } from "./rowWindow.js";
14
15
  import { SelectBox, Table, Td, Th, THead, Tr } from "./Table.js";
15
16
  import { YesNo } from "../value/YesNo.js";
@@ -69,7 +70,9 @@ export function aggregateText(column, value) {
69
70
  const format = aggregateFormat(column);
70
71
  return format === undefined ? value : format(value);
71
72
  }
72
- function aggregateLabel(copy, column, v) {
73
+ /** A pile's or the footer's number as the table writes it: «Bs. 185.200,50», «máx 5». Exported
74
+ * for the presentations without columns, so a pile says the same thing in rows and tiles. */
75
+ export function aggregateLabel(copy, column, v) {
73
76
  const n = v.toLocaleString(copy.locale);
74
77
  /* Raw, a sum of amounts read «78.752,9»: one decimal lost and no currency, under a
75
78
  column whose every cell says «Bs. 12.300,00». */
@@ -222,7 +225,7 @@ function entriesOfPiles(piles, columns, keyOf, collapsed, onToggle, onMore) {
222
225
  ];
223
226
  });
224
227
  }
225
- export function DataTable({ data, columns, getRowId, sort, onSortChange, levels, selected, onSelectedChange, height, onRowClick, rowActions, totals = false, collapsed, onGroupToggle, piles, onMore, create, copyable = true, }) {
228
+ export function DataTable({ data, columns, getRowId, sort, onSortChange, levels, selected, onSelectedChange, height, onRowClick, rowActions, totals = false, collapsed, onGroupToggle, piles, onMore, create, copyable = true, onReorder, }) {
226
229
  const copy = useUiCopy();
227
230
  const draft = create?.draft ?? null;
228
231
  const draftRow = useRef(null);
@@ -397,7 +400,15 @@ export function DataTable({ data, columns, getRowId, sort, onSortChange, levels,
397
400
  };
398
401
  });
399
402
  const selecting = onSelectedChange !== undefined;
400
- const width = columns.length + (selecting ? 1 : 0) + (rowActions === undefined ? 0 : 1);
403
+ const reorder = useRowReorder({
404
+ order: entries.flatMap((entry) => (entry.kind === "row" ? [entry.id] : [])),
405
+ onReorder,
406
+ enabled: (levels ?? []).length === 0 && piles === undefined && (sort ?? []).length === 0,
407
+ });
408
+ const width = columns.length +
409
+ (selecting ? 1 : 0) +
410
+ (reorder.on ? 1 : 0) +
411
+ (rowActions === undefined ? 0 : 1);
401
412
  /* Past a few hundred rows only the ones in view are drawn — see `rowWindow.tsx`. It
402
413
  windows what is DRAWN, pile headers included and folded rows left out: that is the
403
414
  sequence a person scrolls through. */
@@ -418,7 +429,7 @@ export function DataTable({ data, columns, getRowId, sort, onSortChange, levels,
418
429
  first one that sums, and from there each column says what the pile adds up to UNDER
419
430
  itself — Odoo's grouped list. With no column that sums, the name spans the row. */
420
431
  const firstSum = columns.findIndex((c) => c.aggregate !== undefined && c.numeric === true);
421
- const lead = selecting ? 1 : 0;
432
+ const lead = (selecting ? 1 : 0) + (reorder.on ? 1 : 0);
422
433
  const labelSpan = firstSum < 0 ? width : Math.max(1, lead + firstSum);
423
434
  const sumsFrom = firstSum < 0 ? columns.length : labelSpan - lead;
424
435
  const all = leaves.length > 0 && leaves.every((id) => selected?.has(id) === true);
@@ -435,7 +446,7 @@ export function DataTable({ data, columns, getRowId, sort, onSortChange, levels,
435
446
  ? {
436
447
  rowCount: 1 + entries.length + (draft === null ? 0 : 1) + (totals ? 1 : 0),
437
448
  }
438
- : {}), children: [_jsxs(THead, { ...(view.on ? { rowIndex: 1 } : {}), children: [selecting ? (_jsx(Th, { width: 36, children: _jsx(SelectBox, { label: copy.selection.all, checked: all, indeterminate: some, onChange: (v) => onSelectedChange?.(v ? new Set(leaves) : new Set()) }) })) : null, columns.map((c) => (_jsx(Th, { sortKey: c.sortable === false ? undefined : c.id, sort: sort, onSort: onSortChange, numeric: c.numeric, width: c.width, children: c.header }, c.id))), rowActions === undefined ? null : (_jsx("td", { className: "w-px border-b border-line-strong" }))] }), _jsxs("tbody", { ref: view.body.ref, children: [view.rows.flatMap((slot, at) => {
449
+ : {}), children: [_jsxs(THead, { ...(view.on ? { rowIndex: 1 } : {}), children: [reorder.on ? _jsx("td", { className: "w-0 border-b border-line-strong" }) : null, selecting ? (_jsx(Th, { width: 36, children: _jsx(SelectBox, { label: copy.selection.all, checked: all, indeterminate: some, onChange: (v) => onSelectedChange?.(v ? new Set(leaves) : new Set()) }) })) : null, columns.map((c) => (_jsx(Th, { sortKey: c.sortable === false ? undefined : c.id, sort: sort, onSort: onSortChange, numeric: c.numeric, width: c.width, children: c.header }, c.id))), rowActions === undefined ? null : (_jsx("td", { className: "w-px border-b border-line-strong" }))] }), _jsxs("tbody", { ref: view.body.ref, ...reorder.body, children: [view.rows.flatMap((slot, at) => {
439
450
  const entry = entries[slot.index];
440
451
  if (entry === undefined)
441
452
  return [];
@@ -453,23 +464,28 @@ export function DataTable({ data, columns, getRowId, sort, onSortChange, levels,
453
464
  gap,
454
465
  /* The pile's row: it spans the whole width, says which value it groups by
455
466
  and how many are inside — what makes it useful without opening it. */
456
- _jsxs("tr", { ...windowed, "data-ui": "table.pile", className: "border-b border-line bg-ground", children: [_jsx("td", { colSpan: labelSpan, className: "px-3 py-1.5 whitespace-nowrap", style: indent, children: entry.toggle === undefined ? (_jsx("span", { className: "inline-flex items-center gap-1.5 text-meta font-medium text-ink", children: head })) : (_jsx("button", { type: "button", onClick: entry.toggle, "aria-expanded": entry.open, className: "inline-flex items-center gap-1.5 rounded-control text-meta font-medium text-ink transition-colors duration-(--duration-instant) hover:text-primary focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary", children: head })) }), columns.slice(sumsFrom).map((c, i) => {
467
+ _jsxs("tr", { ...windowed, "data-ui": "table.pile", ...(entry.toggle === undefined
468
+ ? {}
469
+ : { onClick: entry.toggle, className: "group/pile cursor-pointer" }), children: [_jsx("td", { colSpan: labelSpan, className: `px-3 py-1.5 whitespace-nowrap ${PILE_CELL}`, style: indent, children: entry.toggle === undefined ? (_jsx("span", { className: "inline-flex items-center gap-1.5 text-meta font-medium text-ink", children: head })) : (_jsx("button", { type: "button", onClick: (e) => {
470
+ e.stopPropagation();
471
+ entry.toggle?.();
472
+ }, "aria-expanded": entry.open, className: "inline-flex items-center gap-1.5 rounded-control text-meta font-medium text-ink transition-colors duration-(--duration-instant) group-hover/pile:text-primary focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-primary", children: head })) }), columns.slice(sumsFrom).map((c, i) => {
457
473
  const value = entry.totals[sumsFrom + i] ?? null;
458
- return (_jsx("td", { className: `px-3 py-1.5 text-meta font-semibold tabular-nums whitespace-nowrap text-ink ${c.numeric === true ? "text-right" : ""}`, children: value === null ? null : aggregateLabel(copy, c, value) }, c.id));
459
- }), firstSum < 0 || rowActions === undefined ? null : _jsx("td", {})] }, entry.id),
474
+ return (_jsx("td", { className: `px-3 py-1.5 text-meta font-semibold tabular-nums whitespace-nowrap text-ink ${PILE_CELL} ${c.numeric === true ? "text-right" : ""}`, children: value === null ? null : aggregateLabel(copy, c, value) }, c.id));
475
+ }), firstSum < 0 || rowActions === undefined ? null : (_jsx("td", { className: PILE_CELL }))] }, entry.id),
460
476
  ];
461
477
  }
462
478
  if (entry.kind === "more") {
463
479
  return [
464
480
  gap,
465
- _jsx("tr", { ...windowed, className: "border-b border-line", children: _jsx("td", { colSpan: width, className: "px-3 py-1", style: indent, children: _jsx(PileFootLine, { foot: entry.foot, onMore: entry.more }) }) }, entry.id),
481
+ _jsx("tr", { ...windowed, children: _jsx("td", { colSpan: width, className: "border-b border-line px-3 py-1", style: indent, children: _jsx(PileFootLine, { foot: entry.foot, onMore: entry.more }) }) }, entry.id),
466
482
  ];
467
483
  }
468
484
  const original = entry.item;
469
485
  const id = entry.id;
470
486
  return [
471
487
  gap,
472
- _jsxs(Tr, { ...(windowed === undefined ? {} : { windowed }), selected: selected?.has(id) === true, onClick: onRowClick === undefined ? undefined : () => onRowClick(original), children: [selecting ? (_jsx(Td, { children: _jsx(SelectBox, { label: copy.selection.row, checked: selected?.has(id) === true, onChange: (v) => toggle(id, v) }) })) : null, columns.map((c) => {
488
+ _jsxs(Tr, { ...(windowed === undefined ? {} : { windowed }), selected: selected?.has(id) === true, onClick: onRowClick === undefined ? undefined : () => onRowClick(original), ...(reorder.on ? { rowId: id, line: reorder.line(id) } : {}), children: [reorder.on ? _jsx(Td, { fit: true, children: reorder.grip(id) }) : null, selecting ? (_jsx(Td, { children: _jsx(SelectBox, { label: copy.selection.row, checked: selected?.has(id) === true, onChange: (v) => toggle(id, v) }) })) : null, columns.map((c) => {
473
489
  const t = c.tone?.(original);
474
490
  const n = c.note?.(original);
475
491
  const edit = c.edit?.when?.(original) === false ? undefined : c.edit;
@@ -489,16 +505,21 @@ export function DataTable({ data, columns, getRowId, sort, onSortChange, levels,
489
505
  create.onCommit(draft);
490
506
  start();
491
507
  return true;
492
- }, children: [selecting ? _jsx("td", { className: DRAFT_CELL }) : null, columns.map((c) => (_jsx("td", { ...(c.input === undefined ? {} : { "data-edit": "" }), className: `${DRAFT_CELL} ${c.numeric === true ? "text-right tabular-nums" : ""}`, children: c.input?.(draft, (next) => {
508
+ }, children: [reorder.on ? _jsx("td", { className: DRAFT_CELL }) : null, selecting ? _jsx("td", { className: DRAFT_CELL }) : null, columns.map((c) => (_jsx("td", { ...(c.input === undefined ? {} : { "data-edit": "" }), className: `${DRAFT_CELL} ${c.numeric === true ? "text-right tabular-nums" : ""}`, children: c.input?.(draft, (next) => {
493
509
  touched.current = true;
494
510
  create.onChange(next);
495
- }) ?? null }, c.id))), rowActions === undefined ? null : _jsx("td", { className: DRAFT_CELL })] }))] }), footer === null ? null : (_jsx("tfoot", { className: "sticky bottom-0 z-10 bg-ground", children: _jsxs("tr", { className: "border-t border-line-strong", "aria-rowindex": view.on ? 2 + entries.length + (draft === null ? 0 : 1) : undefined, children: [selecting ? _jsx("td", {}) : null, columns.map((c, i) => {
511
+ }) ?? null }, c.id))), rowActions === undefined ? null : _jsx("td", { className: DRAFT_CELL })] }))] }), footer === null ? null : (_jsx("tfoot", { className: "sticky bottom-0 z-10 bg-ground", children: _jsxs("tr", { "aria-rowindex": view.on ? 2 + entries.length + (draft === null ? 0 : 1) : undefined, children: [reorder.on ? _jsx("td", { className: FOOT_CELL }) : null, selecting ? _jsx("td", { className: FOOT_CELL }) : null, columns.map((c, i) => {
496
512
  const value = footer[i] ?? null;
497
- return (_jsx("td", { className: `px-3 py-1.5 text-meta font-semibold text-ink ${c.numeric === true ? "text-right tabular-nums" : ""}`, children: i === 0 && value === null ? (_jsxs("span", { className: "text-muted", children: [data.length.toLocaleString(copy.locale), " ", data.length === 1 ? copy.table.row : copy.table.rows] })) : value === null ? null : (aggregateLabel(copy, c, value)) }, c.id));
498
- }), rowActions === undefined ? null : _jsx("td", {})] }) }))] }));
513
+ return (_jsx("td", { className: `px-3 py-1.5 text-meta font-semibold text-ink ${FOOT_CELL} ${c.numeric === true ? "text-right tabular-nums" : ""}`, children: i === 0 && value === null ? (_jsxs("span", { className: "text-muted", children: [data.length.toLocaleString(copy.locale), " ", data.length === 1 ? copy.table.row : copy.table.rows] })) : value === null ? null : (aggregateLabel(copy, c, value)) }, c.id));
514
+ }), rowActions === undefined ? null : _jsx("td", { className: FOOT_CELL })] }) }))] }));
499
515
  if (create === undefined)
500
516
  return _jsx(FieldBoundary, { children: grid });
501
517
  return (_jsx(FieldBoundary, { children: _jsxs("div", { className: "flex min-w-0 flex-col", children: [grid, writing ? null : (_jsx("div", { className: "px-1 py-0.5", children: _jsxs("button", { ref: addButton, type: "button", onClick: start, className: "flex w-full items-center gap-1.5 rounded-control px-3 py-1 text-left text-meta text-primary transition-colors duration-(--duration-instant) hover:bg-primary/5 focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-primary", children: [_jsx(Plus, { className: "size-(--size-icon-sm)", strokeWidth: 2.5, "aria-hidden": true }), create.label ?? copy.table.add] }) }))] }) }));
502
518
  }
503
519
  /* A cell of the row being written: the table's cell, washed like an edited row. */
504
- const DRAFT_CELL = "border-b border-line bg-primary/5 px-3 py-1 align-middle text-meta text-ink first:rounded-l-control last:rounded-r-control";
520
+ const DRAFT_CELL = "border-b border-line bg-primary/5 px-3 py-1 align-middle text-meta text-ink";
521
+ /* The rows that are not records draw their hairline and their band on the CELLS. The table is
522
+ `border-separate` (a sticky header needs it), and in that model the browser ignores a
523
+ border set on a `<tr>`: the piles' bands had no line under them and the footer none over it. */
524
+ const PILE_CELL = "border-b border-line bg-ground group-hover/pile:bg-ink/5";
525
+ const FOOT_CELL = "border-t border-line-strong";
@@ -10,9 +10,10 @@ import { IconButton } from "../button/Button.js";
10
10
  import { NoteCard, NoteRegistryContext, } from "../field/note.js";
11
11
  import { Flag } from "../notice/Flag.js";
12
12
  import { sectionLines, stackPlaces, tabTarget, } from "./editRules.js";
13
+ import { useRowReorder } from "./rowReorder.js";
13
14
  import { useRowWindow } from "./rowWindow.js";
14
15
  import { HEADER_TEXT } from "./Table.js";
15
- import { AlertCircle, GripVertical, Plus, Trash2 } from "lucide-react";
16
+ import { AlertCircle, Plus, Trash2 } from "lucide-react";
16
17
  import { Fragment, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState, } from "react";
17
18
  import { useKeyboard } from "react-aria";
18
19
  export { sectionLines, stackPlaces, tabTarget };
@@ -393,8 +394,6 @@ groupTotal, height, layout = "auto", onOpen, onDiscard, bands, adds, flag, onReo
393
394
  /* The rows in the order they are drawn: what the arrows walk. */
394
395
  const order = drawn.flatMap((entry) => entry.row === undefined ? [] : [getRowId(entry.row)]);
395
396
  const stop = active !== null && order.includes(active) ? active : (order[0] ?? null);
396
- /* REORDER — a grip at the start of each row. Dragged, the row shows where it would land (a
397
- line over the row it goes in front of); Alt + ↑ / ↓ on the grip does the same by keyboard. */
398
397
  /* The notes of the rows the window does not draw. A drawn row's mark registers its note
399
398
  with the record (`NoteCard`); one scrolled out of the window would vanish from the
400
399
  record's activity — «2 avisos» for a document that has nine. The table registers those
@@ -454,51 +453,20 @@ groupTotal, height, layout = "auto", onOpen, onDiscard, bands, adds, flag, onReo
454
453
  for (const noteId of ownNotes.current)
455
454
  registry?.drop(noteId);
456
455
  }, [registry]);
457
- const reorderable = onReorder !== undefined && grouping === undefined && !stacked;
456
+ /* The row's move — `useRowReorder`, shared with `DataTable`. Off while grouped (the piles
457
+ decide the order) and on a phone's cards. */
458
+ const reorder = useRowReorder({
459
+ order,
460
+ onReorder,
461
+ enabled: grouping === undefined && !stacked,
462
+ });
463
+ const reorderable = reorder.on;
458
464
  /* Every cell of a row, the grip and the trash: what a spacer row spans. */
459
465
  const width = columns.length + (onRemove === undefined ? 0 : 1) + (reorderable ? 1 : 0);
460
- /* A ref and not state: `dragover` can arrive before React re-renders after `dragstart`. */
461
- const dragged = useRef(null);
462
- const [landing, setLanding] = useState(undefined);
463
- const after = (id) => order[order.indexOf(id) + 1] ?? null;
464
- const land = (id, before) => {
465
- if (before === id || before === after(id))
466
- return;
467
- onReorder?.(id, before);
468
- };
469
- const overRow = (event) => {
470
- if (dragged.current === null)
471
- return;
472
- const tr = event.target.closest("tr[data-row-id]");
473
- if (tr === null)
474
- return;
475
- event.preventDefault();
476
- const id = tr.dataset["rowId"] ?? "";
477
- const box = tr.getBoundingClientRect();
478
- setLanding(event.clientY < box.top + box.height / 2 ? id : after(id));
479
- };
480
- const lineOver = (id) => (landing === id ? "border-t-2 border-t-primary" : "");
481
- const grip = (id, mark) => (_jsx("td", { className: `w-0 py-1 pr-0 pl-1 align-middle ${mark} ${lineOver(id)}`, children: _jsx("button", { type: "button", draggable: true, "aria-label": copy.editable.reorder, title: copy.editable.reorderHint, "aria-keyshortcuts": "Alt+ArrowUp Alt+ArrowDown", ...(editable && stop !== id ? { tabIndex: -1 } : {}), onClick: (event) => event.stopPropagation(), onKeyDown: (event) => {
482
- if (!event.altKey || (event.key !== "ArrowUp" && event.key !== "ArrowDown"))
483
- return;
484
- event.preventDefault();
485
- event.stopPropagation();
486
- const at = order.indexOf(id);
487
- if (event.key === "ArrowUp" && at > 0)
488
- land(id, order[at - 1] ?? null);
489
- if (event.key === "ArrowDown" && at < order.length - 1)
490
- land(id, order[at + 2] ?? null);
491
- }, onDragStart: (event) => {
492
- event.dataTransfer.setData("text/plain", id);
493
- event.dataTransfer.effectAllowed = "move";
494
- const tr = event.currentTarget.closest("tr");
495
- if (tr !== null)
496
- event.dataTransfer.setDragImage(tr, 16, 16);
497
- dragged.current = id;
498
- }, onDragEnd: () => {
499
- dragged.current = null;
500
- setLanding(undefined);
501
- }, className: "flex cursor-grab items-center rounded-control p-0.5 text-muted opacity-40 transition-opacity duration-(--duration-instant) group-hover/row:opacity-100 hover:text-ink focus-visible:opacity-100 focus-visible:outline-2 focus-visible:outline-primary active:cursor-grabbing", children: _jsx(GripVertical, { "aria-hidden": true, className: "size-(--size-icon-sm)", strokeWidth: 2 }) }) }));
466
+ const lineOver = reorder.line;
467
+ /* Only the row holding the tab stop offers its grip to `Tab`; the others are reached with
468
+ the arrows first. */
469
+ const grip = (id, mark) => (_jsx("td", { className: `w-0 py-1 pr-0 pl-1 align-middle ${mark} ${lineOver(id)}`, children: reorder.grip(id, { tabbable: !(editable && stop !== id) }) }));
502
470
  /* The focus a row is waiting for, once it is drawn: opened by the keyboard (its first or
503
471
  last control), or reached by a jump (`Home`, `End`) past what the window draws. Every
504
472
  render and not on `editing` alone: a row outside the window shows up a render or two
@@ -719,7 +687,7 @@ groupTotal, height, layout = "auto", onOpen, onDiscard, bands, adds, flag, onReo
719
687
  /* The errors of the cells that are not a control right now: under the card. A control
720
688
  carries its own, under it. */
721
689
  const loose = columns.filter((c) => !controls.includes(c) && (states.get(c.id)?.error ?? null) !== null);
722
- return (_jsxs(EditRow, { as: "li", ...rowWiring(id, row), className: `group/row flex min-w-0 flex-col gap-1 rounded-control border-b border-line ${pad} ${isEditing ? "bg-primary/5" : "hover:bg-ink/4"} ${operable ? RING : ""} ${operable && !isEditing
690
+ return (_jsxs(EditRow, { as: "li", ...rowWiring(id, row), className: `group/row flex min-w-0 flex-col gap-1 border-b border-line ${pad} ${isEditing ? "bg-primary/5" : "hover:bg-ink/4"} ${operable ? RING : ""} ${operable && !isEditing
723
691
  ? opens
724
692
  ? "cursor-pointer"
725
693
  : locked(row)
@@ -743,7 +711,7 @@ groupTotal, height, layout = "auto", onOpen, onDiscard, bands, adds, flag, onReo
743
711
  const band = bandOf(row);
744
712
  const isEditing = editing === id;
745
713
  const lines = underSection?.get(id) ?? null;
746
- return (_jsxs(EditRow, { as: "li", ...rowWiring(id, row), className: `flex min-w-0 flex-col gap-1.5 rounded-control border-b border-line ${pad} ${isEditing ? "bg-primary/5" : band === "section" ? "bg-ground" : ""} ${operable ? RING : ""}`, children: [_jsxs("div", { className: "flex min-w-0 items-baseline gap-3 text-meta", children: [_jsx("span", { className: `min-w-0 flex-1 ${band === "section" ? "font-semibold text-ink" : "text-muted italic"}`, children: bands?.render(row) }), lines === null
714
+ return (_jsxs(EditRow, { as: "li", ...rowWiring(id, row), className: `flex min-w-0 flex-col gap-1.5 border-b border-line ${pad} ${isEditing ? "bg-primary/5" : band === "section" ? "bg-ground" : ""} ${operable ? RING : ""}`, children: [_jsxs("div", { className: "flex min-w-0 items-baseline gap-3 text-meta", children: [_jsx("span", { className: `min-w-0 flex-1 ${band === "section" ? "font-semibold text-ink" : "text-muted italic"}`, children: bands?.render(row) }), lines === null
747
715
  ? null
748
716
  : amounts.map((c) => (_jsx("span", { className: "shrink-0 font-semibold text-ink tabular-nums", children: bands?.total?.(c, lines) ?? null }, c.id))), isEditing && onRemove !== undefined ? (_jsx(IconButton, { icon: Trash2, label: copy.editable.remove, size: "sm", tone: "danger", onClick: () => onRemove(id) })) : null] }), isEditing && editable && bands?.edit !== undefined ? (_jsx("div", { "data-edit": "", children: bands.edit(row, setter(id)) })) : null] }, id));
749
717
  };
@@ -774,7 +742,7 @@ groupTotal, height, layout = "auto", onOpen, onDiscard, bands, adds, flag, onReo
774
742
  return (
775
743
  /* A collection is many controls, each named by its column: no enclosing `Field`
776
744
  reaches inside (see `FieldBoundary`). */
777
- _jsx(FieldBoundary, { children: _jsxs("div", { ref: frame, className: "min-w-0", children: [_jsx("div", { ref: box.ref, tabIndex: box.tabIndex, className: `min-w-0 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-primary ${box.className}`, style: box.style, children: stacked ? (list) : (_jsxs("table", { "data-ui": "table", className: "w-full border-separate border-spacing-0 px-1 text-left", ...(view.on
745
+ _jsx(FieldBoundary, { children: _jsxs("div", { ref: frame, className: "min-w-0", children: [_jsx("div", { ref: box.ref, tabIndex: box.tabIndex, className: `min-w-0 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-primary ${box.className}`, style: box.style, children: stacked ? (list) : (_jsxs("table", { "data-ui": "table", className: "w-full border-separate border-spacing-0 text-left", ...(view.on
778
746
  ? { "aria-rowcount": 1 + drawn.length + (totals === undefined ? 0 : 1) }
779
747
  : {}), children: [_jsx("thead", { className: "sticky z-10 bg-ui-table-head", style: stickyTop, "data-ui": "table.head", children: _jsxs("tr", { ...(view.on ? { "aria-rowindex": 1 } : {}), children: [reorderable ? _jsx("td", { className: "w-0 border-b border-line-strong" }) : null, columns.map((c, ci) => c.header === "" ? (_jsx("td", { className: "w-0 border-b border-line-strong" }, c.id)) : (_jsx("th", { scope: "col", style: c.width === undefined ? undefined : { width: c.width },
780
748
  /* A column of figures takes its figures' width (`w-0` in an auto
@@ -785,18 +753,7 @@ groupTotal, height, layout = "auto", onOpen, onDiscard, bands, adds, flag, onReo
785
753
  least: a name cut with «…» asks for no width of its own. */
786
754
  places[ci] === "title" && c.width === undefined
787
755
  ? "min-w-(--size-cell-title)"
788
- : ""}`, children: c.header }, c.id))), onRemove === undefined ? null : (_jsx("td", { className: "w-0 border-b border-line-strong" }))] }) }), _jsxs("tbody", { ref: view.body.ref, ...(reorderable
789
- ? {
790
- onDragOver: overRow,
791
- onDrop: (event) => {
792
- event.preventDefault();
793
- if (dragged.current !== null && landing !== undefined)
794
- land(dragged.current, landing);
795
- dragged.current = null;
796
- setLanding(undefined);
797
- },
798
- }
799
- : {}), children: [rows.length === 0 ? (_jsx("tr", { children: _jsx("td", { colSpan: columns.length +
756
+ : ""}`, children: c.header }, c.id))), onRemove === undefined ? null : (_jsx("td", { className: "w-0 border-b border-line-strong" }))] }) }), _jsxs("tbody", { ref: view.body.ref, ...reorder.body, children: [rows.length === 0 ? (_jsx("tr", { children: _jsx("td", { colSpan: columns.length +
800
757
  (onRemove === undefined ? 0 : 1) +
801
758
  (reorderable ? 1 : 0), className: `text-meta text-muted italic ${cell}`, children: emptyText }) })) : (view.rows.flatMap((slot, at) => {
802
759
  const entry = drawn[slot.index];
@@ -836,7 +793,7 @@ groupTotal, height, layout = "auto", onOpen, onDiscard, bands, adds, flag, onReo
836
793
  : band === "section"
837
794
  ? "bg-ground group-hover/row:bg-ink/6"
838
795
  : "group-hover/row:bg-ink/4";
839
- const bandMark = `border-b border-line first:rounded-l-control last:rounded-r-control ${bandWash}`;
796
+ const bandMark = `border-b border-line ${bandWash}`;
840
797
  const control = isEditing && editable && bands?.edit !== undefined;
841
798
  return [
842
799
  gap,
@@ -847,10 +804,9 @@ groupTotal, height, layout = "auto", onOpen, onDiscard, bands, adds, flag, onReo
847
804
  : ""}`, children: figures[span + i] ?? null }, c.id))), onRemove === undefined ? null : (_jsx("td", { className: `w-0 py-1 pr-2 pl-1 align-middle ${bandMark}`, children: _jsx("span", { className: "flex opacity-0 transition-opacity duration-(--duration-instant) group-hover/row:opacity-100 group-focus-visible/row:opacity-100 focus-within:opacity-100", onClick: (e) => e.stopPropagation(), children: _jsx(IconButton, { icon: Trash2, label: copy.editable.remove, size: "sm", tone: "danger", ...(editable && stop !== id ? { tabIndex: -1 } : {}), onClick: () => onRemove(id) }) }) }))] }, id),
848
805
  ];
849
806
  }
850
- /* The wash lives on the cells. A background on the row paints
851
- edge to edge, and `border-collapse` would ignore a radius. */
807
+ /* The wash lives on the cells, like `Td`'s: the table is `border-separate`. */
852
808
  const wash = isEditing ? "bg-primary/5" : "group-hover/row:bg-ink/4";
853
- const mark = `border-b border-line first:rounded-l-control last:rounded-r-control ${wash}`;
809
+ const mark = `border-b border-line ${wash}`;
854
810
  const set = setter(id);
855
811
  return [
856
812
  gap,
@@ -63,7 +63,7 @@ function ReportLine({ row, columns, open, onToggle, compact, }) {
63
63
  /* `sticky left-0` so that the account name does not go away when you
64
64
  scroll twelve comparison columns to the right. An amount without its
65
65
  line is a loose number. */
66
- className: `sticky left-0 z-10 text-left font-normal ${skin.cell} ${compact ? "py-1 pr-4 pl-2" : "py-1.5 pr-6 pl-3"}`, style: { paddingLeft: `${(compact ? 0.5 : 0.75) + level * INDENT}rem` }, children: [clickable ? (_jsx("span", { "aria-hidden": true, className: "pointer-events-none absolute inset-0 rounded-l-control group-hover/row:bg-primary/5" })) : null, _jsxs("span", { className: `relative flex min-w-0 items-center gap-1.5 text-meta ${skin.text}`, children: [collapsible ? (_jsx("button", { type: "button", onClick: (e) => {
66
+ className: `sticky left-0 z-10 text-left font-normal ${skin.cell} ${compact ? "py-1 pr-4 pl-2" : "py-1.5 pr-6 pl-3"}`, style: { paddingLeft: `${(compact ? 0.5 : 0.75) + level * INDENT}rem` }, children: [clickable ? (_jsx("span", { "aria-hidden": true, className: "pointer-events-none absolute inset-0 group-hover/row:bg-primary/5" })) : null, _jsxs("span", { className: `relative flex min-w-0 items-center gap-1.5 text-meta ${skin.text}`, children: [collapsible ? (_jsx("button", { type: "button", onClick: (e) => {
67
67
  e.stopPropagation();
68
68
  onToggle(row.id);
69
69
  }, "aria-expanded": isOpen, "aria-label": fillCopy(isOpen ? copy.report.close : copy.report.open, {
@@ -72,7 +72,7 @@ function ReportLine({ row, columns, open, onToggle, compact, }) {
72
72
  /* The slot for the chevron is reserved anyway: without it, a leaf
73
73
  account and a collapsible one would start on different
74
74
  verticals and the hierarchy would stop reading. */
75
- _jsx("span", { className: "-ml-1 size-4 shrink-0", "aria-hidden": true })), _jsx("span", { className: "truncate", children: row.label })] })] }), columns.map((c, i) => (_jsxs("td", { className: `text-right text-meta whitespace-nowrap ${clickable ? "relative" : ""} ${skin.cell} ${compact ? "px-2 py-1" : "px-3 py-1.5"}`, children: [clickable ? (_jsx("span", { "aria-hidden": true, className: "pointer-events-none absolute inset-0 group-hover/row:bg-primary/5" })) : null, kind === "section" ? null : (_jsx("span", { className: "relative", children: _jsx(Amount, { value: row.values[i] ?? null, ...(c.format === undefined ? {} : { format: c.format }) }) }))] }, c.id))), _jsxs("td", { className: `w-0 ${clickable ? "relative" : ""} ${skin.cell} ${compact ? "pr-2" : "pr-3"}`, children: [clickable ? (_jsx("span", { "aria-hidden": true, className: "pointer-events-none absolute inset-0 rounded-r-control group-hover/row:bg-primary/5" })) : null, row.note === undefined ? null : (_jsx("span", { title: row.note, className: "relative inline-flex text-muted transition-colors duration-(--duration-instant) hover:text-ink", children: _jsx(Info, { className: "size-(--size-icon-sm)", strokeWidth: 2, "aria-label": row.note }) }))] })] }), !collapsible || !isOpen
75
+ _jsx("span", { className: "-ml-1 size-4 shrink-0", "aria-hidden": true })), _jsx("span", { className: "truncate", children: row.label })] })] }), columns.map((c, i) => (_jsxs("td", { className: `text-right text-meta whitespace-nowrap ${clickable ? "relative" : ""} ${skin.cell} ${compact ? "px-2 py-1" : "px-3 py-1.5"}`, children: [clickable ? (_jsx("span", { "aria-hidden": true, className: "pointer-events-none absolute inset-0 group-hover/row:bg-primary/5" })) : null, kind === "section" ? null : (_jsx("span", { className: "relative", children: _jsx(Amount, { value: row.values[i] ?? null, ...(c.format === undefined ? {} : { format: c.format }) }) }))] }, c.id))), _jsxs("td", { className: `w-0 ${clickable ? "relative" : ""} ${skin.cell} ${compact ? "pr-2" : "pr-3"}`, children: [clickable ? (_jsx("span", { "aria-hidden": true, className: "pointer-events-none absolute inset-0 group-hover/row:bg-primary/5" })) : null, row.note === undefined ? null : (_jsx("span", { title: row.note, className: "relative inline-flex text-muted transition-colors duration-(--duration-instant) hover:text-ink", children: _jsx(Info, { className: "size-(--size-icon-sm)", strokeWidth: 2, "aria-label": row.note }) }))] })] }), !collapsible || !isOpen
76
76
  ? null
77
77
  : row.children?.map((child) => (_jsx(ReportLine, { row: child, columns: columns, open: open, onToggle: onToggle, compact: compact }, child.id)))] }));
78
78
  }
@@ -44,7 +44,7 @@ inline = 2, }) {
44
44
  return (
45
45
  /* The row's hairline runs under its actions too: without it the separators stopped one
46
46
  column short and the actions read as outside the table. */
47
- _jsx("td", { className: `w-0 border-b border-line py-1 pr-2 pl-1 align-middle whitespace-nowrap last:rounded-r-control ${wash}`, children: _jsxs("div", { onClick: (e) => e.stopPropagation(), className: "flex items-center justify-end gap-0.5 opacity-0 transition-opacity duration-(--duration-instant) group-hover/row:opacity-100 focus-within:opacity-100 touch:opacity-100", children: [ways.length === 0 ? null : (_jsx("span", { "data-ui": "row.ways", "data-look": pill ? "pill" : "plain", className: `flex items-center gap-0.5 ${pill ? "rounded-pill border border-primary/20 bg-primary/8 p-0.5" : ""}`, children: ways.map((way) => (_jsx(WayButton, { way: way, pill: pill }, way.id))) })), inlineActions.map((a) => (_jsx(IconButton, { icon: a.icon, label: a.label, size: "sm", ...(a.tone === undefined ? {} : { tone: a.tone }), ...(a.disabled === undefined ? {} : { disabled: a.disabled }), onClick: a.onSelect }, a.id))), overflow.length === 0 ? null : (_jsx(Menu, { label: copy.selection.more, icon: MoreHorizontal, iconOnly: true, chevron: false, align: "end", groups: [
47
+ _jsx("td", { className: `w-0 border-b border-line py-1 pr-2 pl-1 align-middle whitespace-nowrap ${wash}`, children: _jsxs("div", { onClick: (e) => e.stopPropagation(), className: "flex items-center justify-end gap-0.5 opacity-0 transition-opacity duration-(--duration-instant) group-hover/row:opacity-100 focus-within:opacity-100 touch:opacity-100", children: [ways.length === 0 ? null : (_jsx("span", { "data-ui": "row.ways", "data-look": pill ? "pill" : "plain", className: `flex items-center gap-0.5 ${pill ? "rounded-pill border border-primary/20 bg-primary/8 p-0.5" : ""}`, children: ways.map((way) => (_jsx(WayButton, { way: way, pill: pill }, way.id))) })), inlineActions.map((a) => (_jsx(IconButton, { icon: a.icon, label: a.label, size: "sm", ...(a.tone === undefined ? {} : { tone: a.tone }), ...(a.disabled === undefined ? {} : { disabled: a.disabled }), onClick: a.onSelect }, a.id))), overflow.length === 0 ? null : (_jsx(Menu, { label: copy.selection.more, icon: MoreHorizontal, iconOnly: true, chevron: false, align: "end", groups: [
48
48
  {
49
49
  options: overflow.map((a) => ({
50
50
  id: a.id,
@@ -47,12 +47,18 @@ export declare function Th({ children, sortKey, sort, onSort, numeric, align, wi
47
47
  * system scale instead of pinning a size in pixels. */
48
48
  width?: number | string;
49
49
  }): import("react").JSX.Element;
50
- export declare function Tr({ children, onClick, selected, windowed, }: {
50
+ export declare function Tr({ children, onClick, selected, windowed, rowId, line, }: {
51
51
  children: ReactNode;
52
52
  onClick?: () => void;
53
53
  selected?: boolean;
54
54
  /** Set by a table that draws only the rows in view (`useRowWindow`). */
55
55
  windowed?: WindowedRow;
56
+ /** The row's id as `data-row-id`: what a drag reads to know which row it is over
57
+ * (`useRowReorder`). */
58
+ rowId?: string;
59
+ /** A class every cell of the row carries — the line where a dragged row would land
60
+ * (`useRowReorder`'s `line`). On the cells: a separated table draws no border on a row. */
61
+ line?: string;
56
62
  }): import("react").JSX.Element;
57
63
  /**
58
64
  * A row that opens its own detail underneath.
@@ -92,8 +98,11 @@ mono,
92
98
  * number is of another kind»; tinting the cell says «look here», which is
93
99
  * something else — and in a table of forty rows by six columns, colored text
94
100
  * gets lost. */
95
- tone, title, }: {
101
+ tone, title, fit, }: {
96
102
  children: ReactNode;
103
+ /** As narrow as what it holds, without the side padding: a cell for a control — the grip
104
+ * that moves the row — and not for a value. */
105
+ fit?: boolean;
97
106
  numeric?: boolean;
98
107
  /** Pushes without saying it is a number. See the note on `Th`. */
99
108
  align?: "left" | "right";
@@ -52,7 +52,7 @@ height, rowCount, }) {
52
52
  `useScrollBox`: the whole dilemma lives there, and so does its explanation. The
53
53
  three tables of the system solved it with three copies of the same
54
54
  measurement. */
55
- _jsx("div", { ref: caja.ref, tabIndex: caja.tabIndex, className: `min-w-0 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-primary ${caja.className}`, style: caja.style, children: _jsx("table", { "data-ui": "table", "aria-rowcount": rowCount, className: "w-full border-separate border-spacing-0 px-1 text-left", children: children }) }));
55
+ _jsx("div", { ref: caja.ref, tabIndex: caja.tabIndex, className: `min-w-0 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-primary ${caja.className}`, style: caja.style, children: _jsx("table", { "data-ui": "table", "aria-rowcount": rowCount, className: "w-full border-separate border-spacing-0 text-left", children: children }) }));
56
56
  }
57
57
  /** The text of a column header, shared by every table of the family. Ink and semibold, not
58
58
  * muted: in grey at the cells' weight the names of the columns read as one more row. */
@@ -97,10 +97,16 @@ export function Th({ children, sortKey, sort, onSort, numeric = false, align, wi
97
97
  direction: dir === "asc" ? copy.sorting.asc : copy.sorting.desc,
98
98
  }) })) : null] })) }));
99
99
  }
100
- /** The wash of a row lives on the cells, not on the `<tr>`. A background on the
101
- * row paints edge to edge; on the cells the ends can round and the table's
102
- * padding keeps the mark off the card. */
103
- const RowMark = createContext({ selected: false, interactive: false });
100
+ /** The wash of a row lives on the cells, not on the `<tr>`: the table is `border-separate`.
101
+ * Edge to edge, like the head and the hairlines — the table had a 4 px side padding to keep a
102
+ * rounded wash off the card, and with square stripes it only cut every line short of it. */
103
+ const RowMark = createContext({
104
+ selected: false,
105
+ interactive: false,
106
+ });
107
+ /* Square, edge to edge: a table row is a stripe. Its cells used to round their outer corners
108
+ so the wash read as a pill, and the hairline under a rounded corner follows the curve — every
109
+ separator of every table hooked up at both ends, read-only rows included. */
104
110
  const ROW_WASH = "group-hover/row:bg-ink/4";
105
111
  const ROW_ON = "bg-primary/8";
106
112
  /* The hover wash only where a click does something: on a read-only row it promised a click
@@ -108,8 +114,12 @@ const ROW_ON = "bg-primary/8";
108
114
  function rowWash({ selected, interactive }) {
109
115
  return selected ? ROW_ON : interactive ? ROW_WASH : "";
110
116
  }
111
- export function Tr({ children, onClick, selected = false, windowed, }) {
112
- return (_jsx(RowMark.Provider, { value: { selected, interactive: onClick !== undefined }, children: _jsx("tr", { ...windowed, onClick: onClick, className: `group/row ${onClick === undefined ? "" : "cursor-pointer"}`, children: children }) }));
117
+ export function Tr({ children, onClick, selected = false, windowed, rowId, line, }) {
118
+ return (_jsx(RowMark.Provider, { value: {
119
+ selected,
120
+ interactive: onClick !== undefined,
121
+ ...(line === undefined ? {} : { line }),
122
+ }, children: _jsx("tr", { ...windowed, ...(rowId === undefined ? {} : { "data-row-id": rowId }), onClick: onClick, className: `group/row ${onClick === undefined ? "" : "cursor-pointer"}`, children: children }) }));
113
123
  }
114
124
  /**
115
125
  * A row that opens its own detail underneath.
@@ -125,7 +135,7 @@ export function Tr({ children, onClick, selected = false, windowed, }) {
125
135
  */
126
136
  export function TrDetail({ children, detail, open, onToggle, columns, label, selected = false, }) {
127
137
  const id = useId();
128
- return (_jsx(RowMark.Provider, { value: { selected, interactive: true }, children: _jsxs(_Fragment, { children: [_jsxs("tr", { onClick: onToggle, className: "group/row cursor-pointer", children: [_jsx("td", { className: `border-b border-line py-1.5 pr-0 pl-2.5 align-middle first:rounded-l-control ${rowWash({ selected, interactive: true })}`, children: _jsx("button", { type: "button", onClick: (e) => {
138
+ return (_jsx(RowMark.Provider, { value: { selected, interactive: true }, children: _jsxs(_Fragment, { children: [_jsxs("tr", { onClick: onToggle, className: "group/row cursor-pointer", children: [_jsx("td", { className: `border-b border-line py-1.5 pr-0 pl-2.5 align-middle ${rowWash({ selected, interactive: true })}`, children: _jsx("button", { type: "button", onClick: (e) => {
129
139
  e.stopPropagation();
130
140
  onToggle();
131
141
  }, "aria-expanded": open, "aria-controls": id, "aria-label": label, className: "hit-target inline-flex size-5 items-center justify-center rounded-pill text-muted transition-colors duration-(--duration-instant) hover:bg-ink/6 hover:text-ink focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary", children: _jsx(ChevronRight, { className: `size-(--size-icon-sm) transition-transform duration-(--duration-instant) ${open ? "rotate-90" : ""}`, strokeWidth: 2 }) }) }), children] }), _jsx("tr", { id: id, hidden: !open, children: _jsx("td", { colSpan: columns + 1, className: "border-b border-line bg-ground px-3 py-3", children: detail }) })] }) }));
@@ -149,9 +159,9 @@ mono = false,
149
159
  * number is of another kind»; tinting the cell says «look here», which is
150
160
  * something else — and in a table of forty rows by six columns, colored text
151
161
  * gets lost. */
152
- tone, title, }) {
162
+ tone, title, fit = false, }) {
153
163
  const mark = useContext(RowMark);
154
- return (_jsx("td", { title: title, className: `border-b border-line px-3 py-1.5 text-meta text-ink first:rounded-l-control last:rounded-r-control ${(align ?? (numeric ? "right" : "left")) === "right" ? "text-right" : "text-left"} ${mono ? "font-mono tabular-nums" : numeric ? "tabular-nums whitespace-nowrap" : ""} ${tone === undefined ? rowWash(mark) : CELL_TONE[tone]}`, children: children }));
164
+ return (_jsx("td", { title: title, className: `border-b border-line py-1.5 text-meta text-ink ${fit ? "w-0 pr-0 pl-1 align-middle" : "px-3"} ${(align ?? (numeric ? "right" : "left")) === "right" ? "text-right" : "text-left"} ${mono ? "font-mono tabular-nums" : numeric ? "tabular-nums whitespace-nowrap" : ""} ${tone === undefined ? rowWash(mark) : CELL_TONE[tone]} ${mark.line ?? ""}`, children: children }));
155
165
  }
156
166
  /** The selection checkbox, with its third state.
157
167
  *
@@ -0,0 +1,25 @@
1
+ import { type HTMLAttributes, type ReactNode } from "react";
2
+ /** What a table wires to let its rows be moved. */
3
+ export interface RowReorder {
4
+ /** Whether rows move: `onReorder` given and the table allows it (not grouped, not sorted). */
5
+ readonly on: boolean;
6
+ /** For the `tbody`: where a dragged row would land, and the drop. Empty when off. */
7
+ readonly body: Pick<HTMLAttributes<HTMLElement>, "onDragOver" | "onDrop">;
8
+ /** The landing line, for EVERY cell of row `id`: over it when the row lands in front of
9
+ * it, under it when it is the last one and the row goes to the end. */
10
+ line: (id: string) => string;
11
+ /** The grip of row `id`: the button, without its cell — each table draws its own. With
12
+ * `tabbable: false` it leaves the tab order (a grid that walks its rows with arrows). */
13
+ grip: (id: string, options?: {
14
+ tabbable?: boolean;
15
+ }) => ReactNode;
16
+ }
17
+ /** A grip at the start of each row that drags it, and Alt + ↑ / ↓ that moves it. `order` is
18
+ * the ids in the order they are drawn — every one, drawn by the row window or not. */
19
+ export declare function useRowReorder({ order, onReorder, enabled, }: {
20
+ order: readonly string[];
21
+ onReorder: ((id: string, before: string | null) => void) | undefined;
22
+ /** The table's own conditions: off while grouped (the piles decide the order) or sorted
23
+ * by a column (a row dropped would jump back to where the sort puts it). */
24
+ enabled?: boolean;
25
+ }): RowReorder;
@@ -0,0 +1,99 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useUiCopy } from "../../foundations/copy.js";
4
+ import { GripVertical } from "lucide-react";
5
+ import { useLayoutEffect, useRef, useState, } from "react";
6
+ /* Over the row it goes in front of; under the last one for the end. Cells only: a border on
7
+ a `tr` is not drawn in a separated table. */
8
+ const OVER = "border-t-2 border-t-primary";
9
+ const UNDER = "border-b-2 border-b-primary";
10
+ /** A grip at the start of each row that drags it, and Alt + ↑ / ↓ that moves it. `order` is
11
+ * the ids in the order they are drawn — every one, drawn by the row window or not. */
12
+ export function useRowReorder({ order, onReorder, enabled = true, }) {
13
+ const copy = useUiCopy();
14
+ const on = onReorder !== undefined && enabled;
15
+ /* A ref and not state: `dragover` can arrive before React re-renders after `dragstart`. */
16
+ const dragged = useRef(null);
17
+ /* `undefined` while nothing is dragged; `null` is «to the end». */
18
+ const [landing, setLanding] = useState(undefined);
19
+ /* The row moved by keyboard, to give its grip the focus back: React moves the row's node
20
+ and a focused node that is moved loses the focus. */
21
+ const moved = useRef(null);
22
+ const signature = order.join("\u0000");
23
+ useLayoutEffect(() => {
24
+ const want = moved.current;
25
+ /* Only once the order came back changed: `onReorder` may answer after a round trip. */
26
+ if (want === null || want.was === signature)
27
+ return;
28
+ moved.current = null;
29
+ const grip = want.body.querySelector(`tr[data-row-id="${CSS.escape(want.id)}"] [data-ui="table.grip"]`);
30
+ if (grip !== null && document.activeElement !== grip)
31
+ grip.focus();
32
+ }, [signature]);
33
+ const after = (id) => order[order.indexOf(id) + 1] ?? null;
34
+ const land = (id, before) => {
35
+ if (before === id || before === after(id))
36
+ return;
37
+ onReorder?.(id, before);
38
+ };
39
+ const end = () => {
40
+ dragged.current = null;
41
+ setLanding(undefined);
42
+ };
43
+ if (!on)
44
+ return { on, body: {}, line: () => "", grip: () => null };
45
+ const last = order[order.length - 1];
46
+ return {
47
+ on,
48
+ body: {
49
+ onDragOver: (event) => {
50
+ if (dragged.current === null)
51
+ return;
52
+ const tr = event.target.closest("tr[data-row-id]");
53
+ const id = tr?.dataset["rowId"];
54
+ /* Only the rows of `order`: a row being written, a pile, a spacer are not places. */
55
+ if (tr === null || id === undefined || !order.includes(id))
56
+ return;
57
+ event.preventDefault();
58
+ const box = tr.getBoundingClientRect();
59
+ setLanding(event.clientY < box.top + box.height / 2 ? id : after(id));
60
+ },
61
+ onDrop: (event) => {
62
+ event.preventDefault();
63
+ if (dragged.current !== null && landing !== undefined)
64
+ land(dragged.current, landing);
65
+ end();
66
+ },
67
+ },
68
+ line: (id) => (landing === id ? OVER : landing === null && id === last ? UNDER : ""),
69
+ grip: (id, options) => (_jsx("button", { type: "button", draggable: true, "data-ui": "table.grip", "aria-label": copy.editable.reorder, title: copy.editable.reorderHint, "aria-keyshortcuts": "Alt+ArrowUp Alt+ArrowDown", ...(options?.tabbable === false ? { tabIndex: -1 } : {}),
70
+ /* The row may open on a click; the grip is not the row. */
71
+ onClick: (event) => event.stopPropagation(), onKeyDown: (event) => {
72
+ if (!event.altKey || (event.key !== "ArrowUp" && event.key !== "ArrowDown"))
73
+ return;
74
+ event.preventDefault();
75
+ event.stopPropagation();
76
+ const at = order.indexOf(id);
77
+ const to = event.key === "ArrowUp"
78
+ ? at > 0
79
+ ? (order[at - 1] ?? null)
80
+ : undefined
81
+ : at < order.length - 1
82
+ ? (order[at + 2] ?? null)
83
+ : undefined;
84
+ if (to === undefined)
85
+ return;
86
+ const body = event.currentTarget.closest("tbody");
87
+ if (body !== null)
88
+ moved.current = { id, was: signature, body };
89
+ land(id, to);
90
+ }, onDragStart: (event) => {
91
+ event.dataTransfer.setData("text/plain", id);
92
+ event.dataTransfer.effectAllowed = "move";
93
+ const tr = event.currentTarget.closest("tr");
94
+ if (tr !== null)
95
+ event.dataTransfer.setDragImage(tr, 16, 16);
96
+ dragged.current = id;
97
+ }, onDragEnd: end, className: "flex cursor-grab items-center rounded-control p-0.5 text-muted opacity-40 transition-opacity duration-(--duration-instant) group-hover/row:opacity-100 hover:text-ink focus-visible:opacity-100 focus-visible:outline-2 focus-visible:outline-primary active:cursor-grabbing", children: _jsx(GripVertical, { "aria-hidden": true, className: "size-(--size-icon-sm)", strokeWidth: 2 }) })),
98
+ };
99
+ }
@@ -136,7 +136,7 @@ function shell({ item, surface, stack, size, removable, pressable, }) {
136
136
  }
137
137
  function Inside({ item }) {
138
138
  const Icon = item.icon;
139
- return (_jsxs(_Fragment, { children: [Icon === undefined ? null : (_jsx(Icon, { className: "size-3 shrink-0 opacity-70", strokeWidth: 2, "aria-hidden": true })), item.avatar === undefined ? null : (_jsx("span", { "aria-hidden": true, className: "-my-0.5 -ml-1.5 flex shrink-0", children: _jsx(Avatar, { name: item.label, size: "sm", ...(typeof item.avatar === "string" ? { src: item.avatar } : {}) }) })), _jsx("span", { className: "min-w-0 truncate", children: item.label }), item.note === undefined ? null : (
139
+ return (_jsxs(_Fragment, { children: [Icon === undefined ? null : (_jsx(Icon, { className: "size-3 shrink-0 opacity-70", strokeWidth: 2, "aria-hidden": true })), item.avatar === undefined ? null : (_jsx("span", { "aria-hidden": true, className: "-my-0.5 -ml-1.5 flex shrink-0", children: _jsx(Avatar, { name: item.label, size: "xs", ...(typeof item.avatar === "string" ? { src: item.avatar } : {}) }) })), _jsx("span", { className: "min-w-0 truncate", children: item.label }), item.note === undefined ? null : (
140
140
  /* Secondary by its separator and weight, not by fading: at 60 % the note fell
141
141
  under 4.5:1 on a tinted chip. */
142
142
  _jsxs("span", { className: "shrink-0 font-normal", children: ["\u00B7 ", item.note] })), item.count === undefined ? null : (
@@ -1,6 +1,7 @@
1
1
  export declare const SIZE: {
2
- readonly sm: "size-5 text-micro";
3
- readonly md: "size-6 text-micro";
2
+ readonly xs: "size-5 text-micro";
3
+ readonly sm: "size-6 text-micro";
4
+ readonly md: "size-7 text-micro";
4
5
  readonly lg: "size-8 text-meta";
5
6
  readonly xl: "size-12 text-body";
6
7
  };
@@ -57,21 +57,27 @@ function toneOf(name, surface = "canvas") {
57
57
  }
58
58
  /* The text doesn't go below `micro`: two initials at 10 px can't be read, and an
59
59
  unreadable initial is a colored circle — which is exactly what we don't want.
60
- What changes between sizes is the circle. */
60
+ What changes between sizes is the circle — and it leaves the initials room: two 12 px
61
+ letters filled a 20 px disc edge to edge («NF» in a table cell read as a stamp, not a face),
62
+ so the small one is 24 and the default 28. `xs` keeps the 20 px disc for where height is
63
+ fixed by something else — inside a tag, on a calendar event. */
61
64
  export const SIZE = {
62
- sm: "size-5 text-micro",
63
- md: "size-6 text-micro",
65
+ xs: "size-5 text-micro",
66
+ sm: "size-6 text-micro",
67
+ md: "size-7 text-micro",
64
68
  lg: "size-8 text-meta",
65
69
  /* The head of a contact card: the face is what the card is about. */
66
70
  xl: "size-12 text-body",
67
71
  };
68
- /* Two initials, so the overlap stays short of the second letter. The ring is
69
- 1px: a 2px ring of the surface color reads as a gap between people, which
70
- is the thing a stack is not. */
72
+ /* Two initials, so the overlap stays short of the second letter: it covers only the room
73
+ between the disc's edge and its letters (two 12 px initials are ~16 px wide), never a stroke.
74
+ Deeper, «AG JM CR» read «AC JN CR». The ring is 1px: a 2px ring of the surface color reads
75
+ as a gap between people, which is the thing a stack is not. */
71
76
  export const OVERLAP = {
72
- sm: "-ml-1.5",
73
- md: "-ml-2",
74
- lg: "-ml-2.5",
77
+ xs: "-ml-0.5",
78
+ sm: "-ml-1",
79
+ md: "-ml-1.5",
80
+ lg: "-ml-2",
75
81
  xl: "-ml-3.5",
76
82
  };
77
83
  export function Avatar({ name, size = "md",
@@ -17,8 +17,11 @@ function ChipButton({ expanded, haspopup, children, ref, ...native }) {
17
17
  return (_jsx("button", { ...native, ref: ref, type: "button", ...(haspopup === undefined ? {} : { "aria-haspopup": haspopup }), ...(expanded === undefined ? {} : { "aria-expanded": expanded }),
18
18
  /* The hover tint is a pseudo-element that spills past the box, not padding: padding
19
19
  moved the chip off the column of values, and negative margins to undo it made the
20
- chip wider than the room its parent measured — and it truncated itself. */
21
- className: "relative isolate inline-flex max-w-full min-w-0 cursor-pointer items-center gap-2 rounded-control text-left outline-primary outline-offset-4 before:absolute before:-inset-x-1 before:-inset-y-0.5 before:-z-10 before:rounded-control before:transition-colors before:duration-(--duration-instant) hover:before:bg-ink/6 focus-visible:outline-2 aria-expanded:before:bg-ink/6 forced-colors:outline-[Highlight]", children: children }));
20
+ chip wider than the room its parent measured — and it truncated itself.
21
+ It is a CAPSULE around the face: the same 2 px all around the disc, so its left end
22
+ is concentric with it. A rounded rectangle there let the disc's curve poke out of
23
+ the tint's corners. */
24
+ className: "relative isolate inline-flex max-w-full min-w-0 cursor-pointer items-center gap-2 rounded-pill text-left outline-primary outline-offset-2 before:absolute before:-inset-y-0.5 before:-right-2 before:-left-0.5 before:-z-10 before:rounded-pill before:transition-colors before:duration-(--duration-instant) hover:before:bg-ink/6 focus-visible:outline-2 aria-expanded:before:bg-ink/6 forced-colors:outline-[Highlight]", children: children }));
22
25
  }
23
26
  /**
24
27
  * The person with their name next to them. For a cell, a list row, a field in read mode or
@@ -65,5 +68,8 @@ export function UserStack({ names, max = 4, size = "md", }) {
65
68
  }
66
69
  const visible = names.length <= max ? names : names.slice(0, max - 1);
67
70
  const rest = names.length - visible.length;
68
- return (_jsxs("span", { className: "inline-flex items-center", title: names.join(", "), children: [visible.map((n, i) => (_jsx("span", { className: i === 0 ? "" : OVERLAP[size], children: _jsx("span", { className: "block rounded-pill ring-1 ring-surface", children: _jsx(Avatar, { name: n, size: size }) }) }, n))), rest <= 0 ? null : (_jsxs("span", { className: `${OVERLAP[size]} inline-flex items-center justify-center rounded-pill bg-ink/10 font-medium tabular-nums text-muted ring-1 ring-surface ${SIZE[size]}`, children: ["+", rest] }))] }));
71
+ return (_jsxs("span", { className: "inline-flex items-center", title: names.join(", "), children: [visible.map((n, i) => (_jsx("span", { className: i === 0 ? "" : OVERLAP[size], children: _jsx("span", { className: "block rounded-pill ring-1 ring-surface", children: _jsx(Avatar, { name: n, size: size }) }) }, n))), rest <= 0 ? null : (
72
+ /* Opaque, like every disc of the stack: a translucent «+3» let the face under it
73
+ show through and its «+» read as a smudge. */
74
+ _jsxs("span", { className: `${OVERLAP[size]} relative inline-flex items-center justify-center overflow-hidden rounded-pill bg-surface font-medium tabular-nums text-muted ring-1 ring-surface ${SIZE[size]}`, children: [_jsx("span", { "aria-hidden": true, className: "absolute inset-0 bg-ink/10" }), _jsxs("span", { className: "relative", children: ["+", rest] })] }))] }));
69
75
  }
@@ -47,7 +47,10 @@ export function Numeric({ value, unit, format = "integer", align = "right", roun
47
47
  const options = typeof format === "object" ? format : PRESET[format];
48
48
  const text = formatWith(shown, signed ? { ...options, signDisplay: "exceptZero" } : options, locale);
49
49
  const negative = signed && shown < 0;
50
- return (_jsxs("span", { className: `${align === "left" ? "inline-block text-left" : "block text-right"} text-body tabular-nums whitespace-nowrap ${negative ? "text-danger" : "text-ink"}`, children: [_jsx("span", { className: "tabular-nums", children: text }), unit === undefined ? null : _jsx("span", { className: "ml-1 text-muted", children: unit })] }));
50
+ return (
51
+ /* No size of its own: it takes its container's, like a date or a yes/no beside it. At
52
+ `text-body` a quantity in a 13 px row stood a size above its row and off its baseline. */
53
+ _jsxs("span", { className: `${align === "left" ? "inline-block text-left" : "block text-right"} tabular-nums whitespace-nowrap ${negative ? "text-danger" : "text-ink"}`, children: [_jsx("span", { className: "tabular-nums", children: text }), unit === undefined ? null : _jsx("span", { className: "ml-1 text-muted", children: unit })] }));
51
54
  }
52
55
  /**
53
56
  * The content of a data cell, with what the system decides and the view does not.
@@ -47,6 +47,11 @@ type TableProps<T extends object> = {
47
47
  /** Write a new record as one more row of the table (Odoo's editable
48
48
  * list). See `DataTable`'s header. */
49
49
  create?: DataTableCreate<T>;
50
+ /** The records are in an order a person sets by hand (a `sequence`): a grip at the start of
51
+ * each row of the table drags it, Alt + ↑ / ↓ moves it. `before` is the row it lands in
52
+ * front of, `null` the end. Off while grouped or sorted by a column, and in the phone's
53
+ * rows — see `DataTable`'s `onReorder`. */
54
+ onReorder?: (id: string, before: string | null) => void;
50
55
  };
51
56
  /** The board. Without `card`, the card comes from what `List.Rows` already says: the
52
57
  * name, the `meta` and the chips. Writing it anyway is declaring that THIS list
@@ -151,6 +151,10 @@ export function List({ items, keyOf, embedded, surface, group, selection: select
151
151
  ? {}
152
152
  : { rowActions: table.rowActions }),
153
153
  ...(table.create === undefined || readOnly ? {} : { create: table.create }),
154
+ /* Read-only: moving a record is writing its position. */
155
+ ...(table.onReorder === undefined || readOnly
156
+ ? {}
157
+ : { onReorder: table.onReorder }),
154
158
  ...(table.visibleColumnIds === undefined
155
159
  ? {}
156
160
  : { visibleColumnIds: table.visibleColumnIds }),
@@ -1,5 +1,5 @@
1
1
  import type { ListViewProps } from "./types.js";
2
- export declare function ListView<T extends object>({ items, keyOf, identity, crumbs, embedded, surface: requestedSurface, metrics, filters, search, pagination, views, actions: written, dock, row, rowHeader, columns, visibleColumnIds, onVisibleColumnIdsChange, card, tiles, boardStages, calendar, gantt, timeline, sheet, report, pivot, chart, faces, present: requested, presents, onPresentChange, sort, onSortChange, sortable, totals, rowActions, create, group, selection, onOpen, onPeek, openTargets, onOpenIn, rowClick, onChoose, state, filtered, empty, children, }: ListViewProps<T>): import("react").JSX.Element;
2
+ export declare function ListView<T extends object>({ items, keyOf, identity, crumbs, embedded, surface: requestedSurface, metrics, filters, search, pagination, views, actions: written, dock, row, rowHeader, columns, visibleColumnIds, onVisibleColumnIdsChange, card, tiles, boardStages, calendar, gantt, timeline, sheet, report, pivot, chart, faces, present: requested, presents, onPresentChange, sort, onSortChange, sortable, totals, rowActions, onReorder, create, group, selection, onOpen, onPeek, openTargets, onOpenIn, rowClick, onChoose, state, filtered, empty, children, }: ListViewProps<T>): import("react").JSX.Element;
3
3
  /** What a list offers when it fails and can be retried. */
4
4
  export declare function RetryAction({ onRetry }: {
5
5
  onRetry: () => void;
@@ -27,7 +27,7 @@ import { ReportTable } from "../../primitives/table/ReportTable.js";
27
27
  import { Metric, Metrics } from "../../primitives/value/Metric.js";
28
28
  import { ProgressBar } from "../../primitives/value/ProgressBar.js";
29
29
  import { groupedColumnIds, WIDE_PRESENTS } from "./columns.js";
30
- import { groupLevelsOf, reportColumnsOf, reportRowsOf, sheetFromColumns, sheetRowsOf, } from "./derive.js";
30
+ import { groupLevelsOf, pileSummaryOf, reportColumnsOf, reportRowsOf, sheetFromColumns, sheetRowsOf, } from "./derive.js";
31
31
  import { SheetPresentation, TablePresentation, } from "./presentations.js";
32
32
  import { useNarrowList } from "./useNarrowList.js";
33
33
  import { useReachBottom } from "./useReachBottom.js";
@@ -90,7 +90,7 @@ const PRESENT_ICONS = [
90
90
  { id: "gantt", icon: ChartGantt },
91
91
  { id: "timeline", icon: CalendarRange },
92
92
  ];
93
- export function ListView({ items, keyOf, identity, crumbs, embedded = false, surface: requestedSurface, metrics, filters, search, pagination, views, actions: written, dock, row, rowHeader, columns, visibleColumnIds, onVisibleColumnIdsChange, card, tiles, boardStages, calendar, gantt, timeline, sheet, report, pivot, chart, faces, present: requested = "rows", presents, onPresentChange, sort, onSortChange, sortable, totals = false, rowActions, create, group, selection, onOpen, onPeek, openTargets, onOpenIn, rowClick = "peek", onChoose, state, filtered = false, empty, children, }) {
93
+ export function ListView({ items, keyOf, identity, crumbs, embedded = false, surface: requestedSurface, metrics, filters, search, pagination, views, actions: written, dock, row, rowHeader, columns, visibleColumnIds, onVisibleColumnIdsChange, card, tiles, boardStages, calendar, gantt, timeline, sheet, report, pivot, chart, faces, present: requested = "rows", presents, onPresentChange, sort, onSortChange, sortable, totals = false, rowActions, onReorder, create, group, selection, onOpen, onPeek, openTargets, onOpenIn, rowClick = "peek", onChoose, state, filtered = false, empty, children, }) {
94
94
  const wide = useMemo(() => [
95
95
  ...WIDE_PRESENTS,
96
96
  ...(faces ?? []).filter((f) => f.wide === true).map((f) => f.id),
@@ -361,11 +361,13 @@ export function ListView({ items, keyOf, identity, crumbs, embedded = false, sur
361
361
  /** The buckets, with their rows inside. It calls itself because the tree
362
362
  * has N levels: a bucket draws its header and, inside, either the buckets
363
363
  * below or the rows — never both. */
364
+ /* What the server summed and wrote, else what the columns add up to — the table's numbers. */
365
+ const withDetail = (detail) => (detail === undefined ? {} : { detail });
364
366
  function renderPiles(list, nodes) {
365
367
  return list.map((pile) => {
366
368
  const key = pathKey(pile.path);
367
369
  const open = isOpen(pile);
368
- return (_jsxs(Fragment, { children: [_jsx(GroupHeader, { field: levelNameOf(pile.field, columns), label: pile.label, count: pile.count, ...(pile.detail === undefined ? {} : { detail: pile.detail }), depth: pile.depth, open: open, ...(group?.onToggle === undefined
370
+ return (_jsxs(Fragment, { children: [_jsx(GroupHeader, { field: levelNameOf(pile.field, columns), label: pile.label, count: pile.count, ...withDetail(pile.detail ?? pileSummaryOf(pile, columns, copy)), depth: pile.depth, open: open, ...(group?.onToggle === undefined
369
371
  ? {}
370
372
  : { onToggle: () => group.onToggle?.(key) }) }), !open
371
373
  ? null
@@ -423,7 +425,7 @@ export function ListView({ items, keyOf, identity, crumbs, embedded = false, sur
423
425
  ...(onOpen === undefined || choosing ? {} : { open: onOpen }),
424
426
  })) : present === "table" && shownColumns !== undefined ? (
425
427
  /* The table receives EVERYTHING that belongs to the set: see `TablePresentation`. */
426
- _jsx(TablePresentation, { items: items, columns: shownColumns, keyOf: keyOf, levels: groupLevels, ...(sort === undefined ? {} : { sort }), ...(onSortChange === undefined ? {} : { onSortChange }), ...(group === undefined ? {} : { group }), ...(selection === undefined ? {} : { selection }), totals: totals, ...(rowActions === undefined ? {} : { rowActions }), ...(create === undefined ? {} : { create }), ...(onPeek === undefined || choosing ? {} : { onPeek }), ...(onOpen === undefined || choosing ? {} : { onOpen }), ...(openTargets === undefined || onOpenIn === undefined || choosing
428
+ _jsx(TablePresentation, { items: items, columns: shownColumns, keyOf: keyOf, levels: groupLevels, ...(sort === undefined ? {} : { sort }), ...(onSortChange === undefined ? {} : { onSortChange }), ...(group === undefined ? {} : { group }), ...(selection === undefined ? {} : { selection }), totals: totals, ...(rowActions === undefined ? {} : { rowActions }), ...(onReorder === undefined || choosing ? {} : { onReorder }), ...(create === undefined ? {} : { create }), ...(onPeek === undefined || choosing ? {} : { onPeek }), ...(onOpen === undefined || choosing ? {} : { onOpen }), ...(openTargets === undefined || onOpenIn === undefined || choosing
427
429
  ? {}
428
430
  : { openTargets, onOpenIn }), ...(choosing ? { onChoose } : {}), rowClick: rowClick })) : present === "sheet" && sheetSpec !== undefined ? (
429
431
  /* The sheet receives the set by INDEX and not an already built matrix: see `SheetPresentation`. */
@@ -1,4 +1,5 @@
1
1
  import { type Pile } from "../../foundations/grouping.js";
2
+ import type { UiCopy } from "../../foundations/uiCopy.js";
2
3
  import { type DataColumn } from "../../primitives/table/DataTable.js";
3
4
  import type { ReportColumn, ReportRow } from "../../primitives/table/ReportTable.js";
4
5
  import type { SheetColumn } from "../../primitives/table/SheetTable.js";
@@ -85,3 +86,12 @@ export declare function reportRowsOf<T extends object>(piles: readonly Pile<T>[]
85
86
  * number format — a count of rows is not an amount.
86
87
  */
87
88
  export declare function reportColumnsOf<T extends object>(reportColumns: readonly ReportColumn[], columns: readonly DataColumn<T>[] | undefined): readonly ReportColumn[];
89
+ /**
90
+ * What a pile adds up to, in one line — for the presentations without columns (rows, tiles,
91
+ * cards), where there is no column to write each total under.
92
+ *
93
+ * Context: the table's pile said «185.200,50 · máx 5» under its columns, and the same pile in
94
+ * rows said only «5». Switching presentation lost the answer the grouping was asked for. The
95
+ * numbers are the table's (`pileAggregate`, `aggregateLabel`), so the two never disagree.
96
+ */
97
+ export declare function pileSummaryOf<T extends object>(pile: Pile<T>, columns: readonly DataColumn<T>[] | undefined, copy: UiCopy): string | undefined;
@@ -1,5 +1,5 @@
1
1
  import { levelKey, pathKey, pileCount, pileItems, pileLabel, } from "../../foundations/grouping.js";
2
- import { aggregateFormat, aggregateOf, aggregateText, pileAggregate, } from "../../primitives/table/DataTable.js";
2
+ import { aggregateFormat, aggregateLabel, aggregateOf, aggregateText, pileAggregate, } from "../../primitives/table/DataTable.js";
3
3
  import { levelNameOf } from "../../primitives/table/levels.js";
4
4
  /**
5
5
  * Context: what a list DERIVES from its set, as pure functions — the table's group levels,
@@ -242,3 +242,20 @@ export function reportColumnsOf(reportColumns, columns) {
242
242
  : { ...column, format };
243
243
  });
244
244
  }
245
+ /**
246
+ * What a pile adds up to, in one line — for the presentations without columns (rows, tiles,
247
+ * cards), where there is no column to write each total under.
248
+ *
249
+ * Context: the table's pile said «185.200,50 · máx 5» under its columns, and the same pile in
250
+ * rows said only «5». Switching presentation lost the answer the grouping was asked for. The
251
+ * numbers are the table's (`pileAggregate`, `aggregateLabel`), so the two never disagree.
252
+ */
253
+ export function pileSummaryOf(pile, columns, copy) {
254
+ if (columns === undefined)
255
+ return undefined;
256
+ const parts = columns.flatMap((column) => {
257
+ const value = pileAggregate(column, pile);
258
+ return value === null ? [] : [`${column.header} ${aggregateLabel(copy, column, value)}`];
259
+ });
260
+ return parts.length === 0 ? undefined : parts.join(" · ");
261
+ }
@@ -15,14 +15,14 @@ type TableProps<T extends object> = {
15
15
  levels: NonNullable<Parameters<typeof DataTable<T>>[0]["levels"]>;
16
16
  group?: ListGroup<T>;
17
17
  totals: boolean;
18
- } & Pick<ListViewProps<T>, "sort" | "onSortChange" | "selection" | "rowActions" | "create" | "onPeek" | "onOpen" | "openTargets" | "onOpenIn"> & {
18
+ } & Pick<ListViewProps<T>, "sort" | "onSortChange" | "selection" | "rowActions" | "create" | "onReorder" | "onPeek" | "onOpen" | "openTargets" | "onOpenIn"> & {
19
19
  rowClick?: "peek" | "open";
20
20
  onChoose?: (item: T) => void;
21
21
  };
22
22
  /** The table receives EVERYTHING that belongs to the set —sorting, selection, grouping,
23
23
  * which columns are on screen— and not a trimmed down version: that was exactly the trap
24
24
  * this archetype exists to avoid, that switching presentation loses capabilities. */
25
- export declare function TablePresentation<T extends object>({ items, columns, keyOf, levels, group, totals, sort, onSortChange, selection, rowActions, create, onPeek, onOpen, openTargets, onOpenIn, rowClick, onChoose, }: TableProps<T>): import("react").JSX.Element;
25
+ export declare function TablePresentation<T extends object>({ items, columns, keyOf, levels, group, totals, sort, onSortChange, selection, rowActions, create, onReorder, onPeek, onOpen, openTargets, onOpenIn, rowClick, onChoose, }: TableProps<T>): import("react").JSX.Element;
26
26
  type SheetProps<T extends object> = {
27
27
  spec: ListSheet<T>;
28
28
  /** The flattened bands and rows when the set is grouped; `null` when it is not. */
@@ -15,7 +15,7 @@ const OPEN_ICON = {
15
15
  /** The table receives EVERYTHING that belongs to the set —sorting, selection, grouping,
16
16
  * which columns are on screen— and not a trimmed down version: that was exactly the trap
17
17
  * this archetype exists to avoid, that switching presentation loses capabilities. */
18
- export function TablePresentation({ items, columns, keyOf, levels, group, totals, sort, onSortChange, selection, rowActions, create, onPeek, onOpen, openTargets, onOpenIn, rowClick = "peek", onChoose, }) {
18
+ export function TablePresentation({ items, columns, keyOf, levels, group, totals, sort, onSortChange, selection, rowActions, create, onReorder, onPeek, onOpen, openTargets, onOpenIn, rowClick = "peek", onChoose, }) {
19
19
  const copy = useUiCopy();
20
20
  const press = onChoose ?? (rowClick === "open" ? (onOpen ?? onPeek) : (onPeek ?? onOpen));
21
21
  /* The row's ways in go FIRST among its actions, so they are always the inline ones and
@@ -86,7 +86,7 @@ export function TablePresentation({ items, columns, keyOf, levels, group, totals
86
86
  selection.toggle(id);
87
87
  }
88
88
  },
89
- }), ...(totals ? { totals: true } : {}), ...(withOpeners === undefined ? {} : { rowActions: withOpeners }), ...(create === undefined ? {} : { create }), ...(press === undefined ? {} : { onRowClick: press }) }));
89
+ }), ...(totals ? { totals: true } : {}), ...(withOpeners === undefined ? {} : { rowActions: withOpeners }), ...(create === undefined ? {} : { create }), ...(onReorder === undefined ? {} : { onReorder }), ...(press === undefined ? {} : { onRowClick: press }) }));
90
90
  }
91
91
  /** The sheet receives the set by INDEX and not a ready-made matrix: `SheetTable` is
92
92
  * virtualized precisely so as not to materialize a million rows, and handing it copies
@@ -380,6 +380,11 @@ export type ListViewProps<T extends object> = {
380
380
  * columns that declare `input` get a control in that row. See `DataTable`'s header.
381
381
  * While a record is being written the table shows even if the set is empty. */
382
382
  create?: DataTableCreate<T>;
383
+ /** The records are in an order a person sets by hand (a `sequence`): a grip at the start of
384
+ * each row of the table drags it, Alt + ↑ / ↓ moves it. `before` is the row it lands in
385
+ * front of, `null` the end. Off while grouped or sorted by a column, and in the phone's
386
+ * rows — see `DataTable`'s `onReorder`. */
387
+ onReorder?: (id: string, before: string | null) => void;
383
388
  /** The board presentation: the card of one record, with what a press on it does. */
384
389
  card?: (item: T, ways: CardWays) => ReactNode;
385
390
  /** The board by stages: one column each, cards moved between them. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sincpro/web-ui",
3
- "version": "2.17.0",
3
+ "version": "2.18.1",
4
4
  "description": "An enterprise web design system for business software — ERPs, back offices, management tools — in React and Tailwind: tokens, primitives, components and the two views every management screen is made of.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",