@sincpro/web-ui 2.3.0 → 2.5.0

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 (70) hide show
  1. package/README.md +71 -6
  2. package/dist/components/activity/Activity.d.ts +20 -1
  3. package/dist/components/activity/Activity.js +44 -7
  4. package/dist/components/activity/index.d.ts +1 -1
  5. package/dist/components/board/Board.d.ts +74 -2
  6. package/dist/components/board/Board.js +65 -2
  7. package/dist/components/board/index.d.ts +1 -1
  8. package/dist/components/board/index.js +1 -1
  9. package/dist/components/canvas/canvas.css +6 -1
  10. package/dist/components/form/Form.js +11 -0
  11. package/dist/components/form/FormIndex.d.ts +11 -0
  12. package/dist/components/form/FormIndex.js +96 -0
  13. package/dist/components/form/Sheet.js +5 -0
  14. package/dist/components/guide/Guide.d.ts +33 -0
  15. package/dist/components/guide/Guide.js +288 -0
  16. package/dist/components/guide/GuideSpot.d.ts +14 -0
  17. package/dist/components/guide/GuideSpot.js +13 -0
  18. package/dist/components/guide/index.d.ts +4 -0
  19. package/dist/components/guide/index.js +6 -0
  20. package/dist/components/guide/place.d.ts +44 -0
  21. package/dist/components/guide/place.js +69 -0
  22. package/dist/components/guide/target.d.ts +41 -0
  23. package/dist/components/guide/target.js +55 -0
  24. package/dist/components/index.d.ts +1 -0
  25. package/dist/components/index.js +1 -0
  26. package/dist/components/listing/ChartExplorer.js +10 -5
  27. package/dist/components/listing/Listing.js +7 -5
  28. package/dist/components/listing/Row.js +8 -7
  29. package/dist/components/navigation/NavigationTree.js +1 -1
  30. package/dist/components/record/DirtyActions.d.ts +19 -8
  31. package/dist/components/record/DirtyActions.js +89 -13
  32. package/dist/components/record/RecordHeader.js +17 -11
  33. package/dist/components/record/ThumbBar.js +2 -1
  34. package/dist/components/shell/SearchEntry.d.ts +29 -0
  35. package/dist/components/shell/SearchEntry.js +34 -0
  36. package/dist/components/shell/Sidebar.d.ts +5 -1
  37. package/dist/components/shell/Sidebar.js +4 -3
  38. package/dist/components/shell/TopBar.d.ts +5 -1
  39. package/dist/components/shell/TopBar.js +3 -2
  40. package/dist/components/shell/index.d.ts +1 -0
  41. package/dist/components/shell/index.js +3 -0
  42. package/dist/foundations/calendar.d.ts +12 -0
  43. package/dist/foundations/calendar.js +50 -0
  44. package/dist/foundations/chart.d.ts +10 -1
  45. package/dist/foundations/chart.js +17 -1
  46. package/dist/foundations/copy.d.ts +39 -2
  47. package/dist/foundations/copy.es.js +19 -0
  48. package/dist/foundations/copy.js +19 -0
  49. package/dist/foundations/form.d.ts +6 -0
  50. package/dist/foundations/form.js +7 -0
  51. package/dist/foundations/index.d.ts +3 -2
  52. package/dist/foundations/index.js +4 -2
  53. package/dist/foundations/pivot.d.ts +6 -0
  54. package/dist/foundations/pivot.js +1 -0
  55. package/dist/foundations/shortcut.d.ts +18 -0
  56. package/dist/foundations/shortcut.js +20 -0
  57. package/dist/primitives/chart/BarList.d.ts +30 -0
  58. package/dist/primitives/chart/BarList.js +27 -0
  59. package/dist/primitives/chart/Chart.d.ts +13 -0
  60. package/dist/primitives/chart/Chart.js +71 -19
  61. package/dist/primitives/chart/Sparkline.d.ts +30 -0
  62. package/dist/primitives/chart/Sparkline.js +53 -0
  63. package/dist/primitives/chart/index.d.ts +2 -0
  64. package/dist/primitives/chart/index.js +2 -0
  65. package/dist/primitives/field/Field.d.ts +6 -2
  66. package/dist/primitives/field/Field.js +35 -6
  67. package/dist/primitives/value/Metric.d.ts +12 -1
  68. package/dist/primitives/value/Metric.js +9 -4
  69. package/dist/tokens.css +92 -22
  70. package/package.json +1 -1
package/README.md CHANGED
@@ -195,12 +195,14 @@ follows:
195
195
  | Menus, lists, popovers, the cuts panel | `--ui-popover-radius`, `--ui-popover-bg`, `--ui-popover-border`, `--ui-popover-shadow` |
196
196
  | A row inside them (menu item, option) | `--ui-option-radius`, `--ui-option-active-bg` |
197
197
  | `Dialog` | `--ui-dialog-radius`, `--ui-dialog-bg` |
198
- | `Block`, `RecordCard`, `BoardTile`, `Metric` | `--ui-card-radius`, `--ui-card-bg`, `--ui-card-border` |
198
+ | `Block`, `RecordCard`, `Metric` | `--ui-card-radius`, `--ui-card-bg`, `--ui-card-border` |
199
+ | A board's `BoardTile` and `BoardStat` | `--ui-tile-radius`, `--ui-tile-bg`, `--ui-tile-border` (fall back to the card's) |
199
200
  | `Tag`, `Tags`, the search bar's chips | `--ui-tag-radius` |
200
201
  | `SearchBar`'s field | `--ui-search-radius` (and the control's bg and border) |
201
202
  | The sidebar on the canvas | `--ui-sidebar-bg`, `--ui-sidebar-border` |
202
203
  | `NavigationTree` | `--ui-nav-radius`, `--ui-nav-current-bg` |
203
204
  | Table headers (`DataTable`, `EditableTable`, `ReportTable`) | `--ui-table-head-bg` |
205
+ | `Guide` (a guided tour): its card and its veil | `--ui-guide-radius`, `--ui-guide-bg`, `--ui-guide-scrim` |
204
206
 
205
207
  What a token does not cover, a **part** does. Every customizable piece names its root
206
208
  `data-ui="<component>"` and its parts `data-ui="<component>.<part>"`, with its variant beside
@@ -218,11 +220,74 @@ of classes that change with the next refactor:
218
220
 
219
221
  The parts: `button`, `icon-button`, `control`, `popover`, `menu`, `menu.trigger`,
220
222
  `menu.section`, `menu.item`, `menu.fold`, `dialog`, `block`, `record-card`, `board.tile`,
221
- `metric`, `tag`, `tags.item`, `search`, `search.field`, `search.chip`, `search.panel`,
222
- `search.suggestions`, `table`, `table.head`, `topbar`, `topbar.brand`, `topbar.menus`,
223
- `topbar.actions`, `topbar.user`, `frame`, `frame.bar`, `frame.sidebar`, `frame.main`, `sidebar`,
224
- `sidebar.brand`, `sidebar.user`, `sidebar.nav`, `sidebar.account`, `navigation`,
225
- `navigation.item`. Put your rules in a cascade layer above web-ui's, or outside any layer.
223
+ `board.stat`, `board.stat.value`, `activity.changes`, `metric`, `metric.detail`, `tag`, `tags.item`, `search`, `search.field`, `search.chip`,
224
+ `search.panel`, `search.suggestions`, `search-entry`, `search-entry.keys`, `table`,
225
+ `table.head`, `topbar`, `topbar.brand`, `topbar.menus`, `topbar.actions`, `topbar.user`,
226
+ `frame`, `frame.bar`, `frame.sidebar`, `frame.main`, `sidebar`, `sidebar.brand`,
227
+ `sidebar.user`, `sidebar.search`, `sidebar.nav`, `sidebar.account`, `navigation`,
228
+ `navigation.item`, `dirty.blocked`, `dirty.bar`, `field`, `field.label`, `form.section`,
229
+ `form.index`, `guide`, `guide.veil`, `guide.spot`, `guide.card`,
230
+ `guide.progress`, `guide.title`, `guide.body`, `guide.actions`. A part that is one of many
231
+ carries `data-key` too (`navigation.item`). Put your rules in a cascade layer above web-ui's, or
232
+ outside any layer.
233
+
234
+ #### A form that explains itself: the «settings» style
235
+
236
+ The default form is the dense sheet of an ERP — label | control, two columns, help behind a
237
+ `?`. An application whose forms are filled once in a while and read before they are typed into
238
+ (a back office's settings, an account) can choose the **settings** style, once, around the app:
239
+
240
+ ```tsx
241
+ <FormStyleProvider value="settings">
242
+ <App />
243
+ </FormStyleProvider>
244
+ ```
245
+
246
+ Then every `Field` is a row — the label with `*` or «(opcional)» (`optional`) and its `hint`
247
+ written out under it on the left, the control on the right —, every `FormSection` is a card
248
+ (`form.section`) with an index of the titled ones at the sheet's left (`form.index`), and a
249
+ `Record` with `dirty` floats Discard · Save at the bottom of the screen (`dirty.bar`) instead of
250
+ the rail. The layout (`stacked` / `horizontal`) is still the screen's: stacked, the help and the
251
+ control go under the label. Without the provider nothing changes.
252
+
253
+ #### A guided tour: the screen says what each thing is
254
+
255
+ `Guide` walks a person through a screen: the rest dims, the thing being explained is cut out,
256
+ and a card beside it names it. Its stops are the anchors above, so no component needs a prop to
257
+ be pointed at:
258
+
259
+ ```tsx
260
+ <Guide
261
+ open={open}
262
+ label="Recorrido del portal"
263
+ steps={[
264
+ { id: "hola", title: "Bienvenida", body: "Un minuto para ver dónde está cada cosa." },
265
+ { id: "buscar", target: { part: "sidebar.search" }, placement: "right", title: "Buscar", body: "…" },
266
+ { id: "cuotas", target: { part: "navigation.item", key: "socios.cuotas" }, title: "Cuotas", body: "…" },
267
+ { id: "cifras", target: { spot: "cifras" }, title: "Las cifras de hoy", body: "…" },
268
+ ]}
269
+ onClose={(reason, index) => {
270
+ setOpen(false);
271
+ markSeen(reason); // "finish" | "skip" | "dismiss" — remembering it is the application's
272
+ }}
273
+ />
274
+
275
+ <GuideSpot id="cifras">
276
+ <Metrics>…</Metrics>
277
+ </GuideSpot>
278
+ ```
279
+
280
+ - **A target** is a part (`{ part }`), one item of a collection (`{ part, key }`), anything wrapped
281
+ in `GuideSpot` or carrying `data-guide` (`{ spot }`), a selector, or a function returning an
282
+ element. A step without one is centred.
283
+ - **`before()`** runs first — navigate, open a tab — and the step waits for its target to appear.
284
+ A target that never appears is skipped; the tour does not break when the screen changes.
285
+ - **On a phone**, a stop inside the frame's sidebar opens its drawer, and the next stop outside
286
+ closes it. Render the `Guide` inside the `AppFrame`.
287
+ - It is a modal dialog: focus on «Siguiente» (Enter walks it), → and ←, Escape to leave, and
288
+ every step announced. `onStepChange` and `startAt` let an application save and resume it.
289
+ - `placeCard`, `findTarget`, `selectorOf` and `boxOf` are exported: a tour of your own follows the
290
+ same rules.
226
291
 
227
292
  #### Living beside a site's own CSS
228
293
 
@@ -11,6 +11,7 @@ import { type ReactNode } from "react";
11
11
  *
12
12
  * by WHO. Absent = the system did it, which is also an answer.
13
13
  * moved FROM WHAT TO WHAT. «borrador → confirmado» reads at a glance.
14
+ * changes WHICH FIELDS, each as it was → as it is: the edit an audit asks about.
14
15
  * error WHAT failed, whole and verbatim: whoever looks at this screen many
15
16
  * times has no access to the logs.
16
17
  */
@@ -31,8 +32,26 @@ export type ActivityEvent = {
31
32
  detail?: ReactNode;
32
33
  /** What failed, verbatim. The FIRST line is shown and the rest opens. */
33
34
  error?: string;
34
- /** The dot's icon, when the bolt does not say enough. */
35
+ /** The dot's icon, when the bolt does not say enough. An event with `changes` and no
36
+ * icon of its own gets the pencil: it is an edit. */
35
37
  icon?: LucideIcon;
38
+ /**
39
+ * The fields an edit changed, each as it WAS and as it IS — Odoo's tracked values. Drawn
40
+ * under the event, always in sight (the first three, the rest one press away): an audit
41
+ * reads «who changed what, from what to what, when» without opening anything. Prefer it to
42
+ * writing «Observación: — → test» into `detail`, which can only be read, not scanned.
43
+ */
44
+ changes?: readonly ActivityChange[];
45
+ };
46
+ /**
47
+ * One field an edit changed: what it is called, what it held, what it holds. `from` / `to`
48
+ * absent, `null` or `""` mean EMPTY — written «vacío», because «—» beside an arrow reads as
49
+ * a dash somebody typed.
50
+ */
51
+ export type ActivityChange = {
52
+ field: string;
53
+ from?: ReactNode;
54
+ to?: ReactNode;
36
55
  };
37
56
  /** A notice of the record, as the panel lists it: a `Callout` without its × label. */
38
57
  export type ActivityAlert = Omit<CalloutProps, "dismissLabel">;
@@ -3,6 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
3
3
  import { usePagination } from "../listing/pages.js";
4
4
  import { Pagination } from "../listing/Pagination.js";
5
5
  import { fillCopy, useUiCopy } from "../../foundations/copy.js";
6
+ import { useFormStyle } from "../../foundations/form.js";
6
7
  import { cn } from "../../foundations/variants.js";
7
8
  import { IconButton } from "../../primitives/button/Button.js";
8
9
  import { SegmentedControl } from "../../primitives/choice/SegmentedControl.js";
@@ -11,7 +12,7 @@ import { Callout } from "../../primitives/notice/Callout.js";
11
12
  import { Tag } from "../../primitives/tag/Tag.js";
12
13
  import { DateValue } from "../../primitives/value/DateValue.js";
13
14
  import { Avatar } from "../../primitives/value/Person.js";
14
- import { Activity as ActivityIcon, ArrowRight, CheckCircle2, ChevronDown, ChevronRight, ChevronUp, CornerDownRight, History, Info, Lock, MessageSquare, OctagonAlert, PanelRightClose, PanelRightOpen, TriangleAlert, Zap, } from "lucide-react";
15
+ import { Activity as ActivityIcon, ArrowRight, CheckCircle2, ChevronDown, ChevronRight, ChevronUp, CornerDownRight, History, Info, Lock, MessageSquare, OctagonAlert, PanelRightClose, PanelRightOpen, PencilLine, TriangleAlert, Zap, } from "lucide-react";
15
16
  import { Fragment, useId, useState } from "react";
16
17
  /** The day an instant falls on, here — a `YYYY-MM-DD` key in local time. */
17
18
  function dayKey(time) {
@@ -80,6 +81,39 @@ const STATE_CHIP = "inline-flex max-w-32 min-w-0 items-center truncate rounded-p
80
81
  function Moved({ from, to }) {
81
82
  return (_jsxs("span", { className: "inline-flex min-w-0 items-center gap-1", children: [from === undefined ? null : (_jsxs(_Fragment, { children: [_jsx("span", { className: `${STATE_CHIP} text-muted`, children: from }), _jsx(ArrowRight, { className: "size-3 shrink-0 text-muted", strokeWidth: 2.5, "aria-hidden": true })] })), _jsx("span", { className: `${STATE_CHIP} font-medium text-ink`, children: to })] }));
82
83
  }
84
+ /* ── A change you can audit ─────────────────────────────────────────
85
+ *
86
+ * It used to be one grey line in the event's folded detail — «Observación: — → test» — read
87
+ * only after a press, the old value and the new one in the same weight, the empty one a dash.
88
+ * An audit asks three things of an edit, and each gets its own channel:
89
+ *
90
+ * WHICH field — its name on its own line, small: the column an eye runs down;
91
+ * WAS — `<del>`, muted and struck through: it is gone;
92
+ * IS — `<ins>`, in ink: what holds now.
93
+ *
94
+ * Not red and green: before and after are not bad and good (PRINCIPLES §3), and the strike
95
+ * plus the weight already say which is which — to a screen reader too, through `del`/`ins`
96
+ * and a word before each. An empty value is the word «vacío», never a dash. */
97
+ const MANY_CHANGES = 3;
98
+ function isEmpty(value) {
99
+ return value === undefined || value === null || value === "" || value === false;
100
+ }
101
+ function ChangeValue({ value, was }) {
102
+ const copy = useUiCopy();
103
+ const lead = (_jsxs("span", { className: "sr-only", children: [was ? copy.activity.before : copy.activity.after, " "] }));
104
+ if (isEmpty(value)) {
105
+ return (_jsxs("span", { className: "text-muted italic", children: [lead, copy.activity.empty] }));
106
+ }
107
+ return was ? (_jsxs("del", { className: "min-w-0 break-words text-muted decoration-muted/70", children: [lead, value] })) : (_jsxs("ins", { className: "min-w-0 break-words font-medium text-ink no-underline", children: [lead, value] }));
108
+ }
109
+ function Changes({ changes }) {
110
+ const copy = useUiCopy();
111
+ const [all, setAll] = useState(false);
112
+ const shown = all ? changes : changes.slice(0, MANY_CHANGES);
113
+ return (_jsxs("div", { "data-ui": "activity.changes", className: "mb-1 ml-10.5 flex min-w-0 flex-col gap-1.5 rounded-control border border-line px-2.5 py-2", children: [_jsx("dl", { className: "flex min-w-0 flex-col divide-y divide-line", children: shown.map((change, at) => (_jsxs("div", { className: "flex min-w-0 flex-col gap-0.5 py-1.5 first:pt-0 last:pb-0", children: [_jsx("dt", { className: "truncate text-micro text-muted", children: change.field }), _jsxs("dd", { className: "flex min-w-0 flex-wrap items-baseline gap-x-1.5 gap-y-0.5 text-meta", children: [_jsx(ChangeValue, { value: change.from, was: true }), _jsx(ArrowRight, { className: "size-3 shrink-0 self-center text-muted", strokeWidth: 2.5, "aria-hidden": true }), _jsx(ChangeValue, { value: change.to, was: false })] })] }, `${change.field}\u0000${String(at)}`))) }), changes.length <= MANY_CHANGES ? null : (_jsx("button", { type: "button", onClick: () => setAll(!all), "aria-expanded": all, className: "self-start cursor-pointer text-micro text-muted underline-offset-2 hover:text-ink hover:underline focus-visible:outline-2 focus-visible:outline-primary", children: all
114
+ ? copy.activity.less
115
+ : fillCopy(copy.activity.allChanges, { count: changes.length }) }))] }));
116
+ }
83
117
  /** The error: the first line, and the rest one press away — kept, not dropped. */
84
118
  function ErrorLine({ error }) {
85
119
  const copy = useUiCopy();
@@ -101,12 +135,13 @@ function EventEntry({ event }) {
101
135
  const copy = useUiCopy();
102
136
  const failed = event.tone === "bad" || event.error !== undefined;
103
137
  const skin = failed ? "failed" : "ok";
104
- const Icon = event.icon ?? EVENT_ICON;
138
+ const edited = event.changes !== undefined && event.changes.length > 0;
139
+ const Icon = event.icon ?? (edited ? PencilLine : EVENT_ICON);
105
140
  const [open, setOpen] = useState(false);
106
141
  const more = event.moved !== undefined || event.detail !== undefined || event.error !== undefined;
107
- const row = (_jsxs(_Fragment, { children: [_jsx("span", { className: `relative z-10 flex size-6 shrink-0 items-center justify-center rounded-pill ring-2 ring-surface ${NODE_SKIN[skin]}`, children: _jsx(Icon, { className: "size-3", strokeWidth: 2.5, "aria-hidden": true }) }), _jsxs("span", { className: "flex min-w-0 flex-1 flex-col gap-0.5", children: [_jsx("span", { className: "line-clamp-2 text-meta text-ink", children: event.label }), _jsxs("span", { className: "flex min-w-0 flex-wrap items-baseline gap-x-1.5 text-micro text-muted", children: [_jsx("span", { className: "truncate", children: event.by ?? copy.activity.bySystem }), _jsx("span", { "aria-hidden": true, children: "\u00B7" }), _jsx(DateValue, { when: event.at, format: "relative" })] })] }), more ? (_jsx(ChevronRight, { className: `mt-1 size-3.5 shrink-0 text-muted transition-transform duration-(--duration-instant) ${open ? "rotate-90" : ""}`, strokeWidth: 2.5, "aria-hidden": true })) : null] }));
142
+ const row = (_jsxs(_Fragment, { children: [_jsx("span", { className: `relative z-10 flex size-6 shrink-0 items-center justify-center rounded-pill ring-2 ring-surface ${NODE_SKIN[skin]}`, children: _jsx(Icon, { className: "size-3", strokeWidth: 2.5, "aria-hidden": true }) }), _jsxs("span", { className: "flex min-w-0 flex-1 flex-col gap-0.5", children: [_jsx("span", { className: "line-clamp-2 text-meta text-ink", children: event.label }), _jsxs("span", { className: "flex min-w-0 flex-wrap items-baseline gap-x-1.5 text-micro text-muted", children: [_jsx("span", { className: "truncate font-medium text-ink", children: event.by ?? copy.activity.bySystem }), _jsx("span", { "aria-hidden": true, children: "\u00B7" }), _jsx(DateValue, { when: event.at, format: "relative" })] })] }), more ? (_jsx(ChevronRight, { className: `mt-1 size-3.5 shrink-0 text-muted transition-transform duration-(--duration-instant) ${open ? "rotate-90" : ""}`, strokeWidth: 2.5, "aria-hidden": true })) : null] }));
108
143
  const box = `flex w-full min-w-0 items-start gap-2.5 rounded-control px-2 py-2 text-left ${failed ? "bg-bad/6" : ""}`;
109
- return (_jsxs("li", { className: "group/event relative", children: [_jsx("span", { "aria-hidden": true, className: "absolute top-8 bottom-0 left-5 w-px bg-line group-last/event:hidden" }), more ? (_jsx("button", { type: "button", onClick: () => setOpen(!open), "aria-expanded": open, className: `${box} cursor-pointer transition-colors duration-(--duration-instant) focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-primary ${failed ? "hover:bg-bad/10" : "hover:bg-ink/4"}`, children: row })) : (_jsx("div", { className: box, children: row })), !open ? null : (_jsxs("div", { className: "mb-1 ml-10.5 flex min-w-0 flex-col gap-1.5 rounded-control bg-ground px-2.5 py-2", children: [event.moved === undefined ? null : (_jsx(Moved, { ...(event.moved.from === undefined ? {} : { from: event.moved.from }), to: event.moved.to })), event.detail === undefined ? null : (_jsx("div", { className: "min-w-0 text-micro text-muted", children: event.detail })), event.error === undefined ? null : _jsx(ErrorLine, { error: event.error })] }))] }));
144
+ return (_jsxs("li", { className: "group/event relative", children: [_jsx("span", { "aria-hidden": true, className: "absolute top-8 bottom-0 left-5 w-px bg-line group-last/event:hidden" }), more ? (_jsx("button", { type: "button", onClick: () => setOpen(!open), "aria-expanded": open, className: `${box} cursor-pointer transition-colors duration-(--duration-instant) focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-primary ${failed ? "hover:bg-bad/10" : "hover:bg-ink/4"}`, children: row })) : (_jsx("div", { className: box, children: row })), edited ? _jsx(Changes, { changes: event.changes ?? [] }) : null, !open ? null : (_jsxs("div", { className: "mb-1 ml-10.5 flex min-w-0 flex-col gap-1.5 rounded-control bg-ground px-2.5 py-2", children: [event.moved === undefined ? null : (_jsx(Moved, { ...(event.moved.from === undefined ? {} : { from: event.moved.from }), to: event.moved.to })), event.detail === undefined ? null : (_jsx("div", { className: "min-w-0 text-micro text-muted", children: event.detail })), event.error === undefined ? null : _jsx(ErrorLine, { error: event.error })] }))] }));
110
145
  }
111
146
  /** Takes you to the field or row a note belongs to, and lights it for a moment so the eye
112
147
  * lands on it. The light is the system's focus colour, faded out; with reduced motion it
@@ -149,6 +184,9 @@ export function Activity({ messages, events, alerts = [], alertsId: ownAlertsId,
149
184
  const autoAlertsId = useId();
150
185
  const alertsId = ownAlertsId ?? autoAlertsId;
151
186
  const auto = layout === "auto";
187
+ /* Beside the sheet it is joined to it — the sheet's right edge is the line between the two.
188
+ In the «settings» form style there is no sheet, only cards on the ground: it stands apart. */
189
+ const joined = useFormStyle() !== "settings";
152
190
  /* The notes of the fields and rows of the record around — `Record` keeps them. */
153
191
  const notes = useNoteEntries();
154
192
  const byTime = (items) => [...items].sort((x, y) => at(y.at) - at(x.at));
@@ -204,7 +242,7 @@ export function Activity({ messages, events, alerts = [], alertsId: ownAlertsId,
204
242
  where the eye starts, and under it the counts, stacked — nothing hidden
205
243
  silently. The sheet's own right edge is the hairline between the two. */
206
244
  auto &&
207
- "@beside/page:w-auto @beside/page:flex-col @beside/page:justify-start @beside/page:gap-3 @beside/page:rounded-l-none @beside/page:border-l-0 @beside/page:px-2 @beside/page:py-3"), children: [_jsx("span", { className: cn("hidden shrink-0 text-muted", auto && "@beside/page:block"), children: _jsx(PanelRightOpen, { className: "size-(--size-icon-md)", "aria-hidden": true }) }), _jsx(ActivityIcon, { className: cn("size-(--size-icon-md) shrink-0 text-muted", auto && "@beside/page:hidden"), "aria-hidden": true }), _jsx("span", { className: cn("min-w-0 truncate text-meta font-medium text-ink", auto && "@beside/page:sr-only"), children: label }), alertTone === undefined ? null : (_jsxs(Tag, { tone: alertTone, children: [_jsxs("span", { className: cn("hidden items-center gap-1", auto && "@beside/page:inline-flex"), children: [_jsx(AlertIcon, { className: "size-3", strokeWidth: 2.5, "aria-hidden": true }), notices] }), _jsx("span", { className: cn(auto && "@beside/page:sr-only"), children: fillCopy(notices === 1 ? copy.record.noticeOne : copy.record.noticeMany, {
245
+ "@beside/page:w-auto @beside/page:flex-col @beside/page:justify-start @beside/page:gap-3 @beside/page:px-2 @beside/page:py-3", auto && joined && "@beside/page:rounded-l-none @beside/page:border-l-0"), children: [_jsx("span", { className: cn("hidden shrink-0 text-muted", auto && "@beside/page:block"), children: _jsx(PanelRightOpen, { className: "size-(--size-icon-md)", "aria-hidden": true }) }), _jsx(ActivityIcon, { className: cn("size-(--size-icon-md) shrink-0 text-muted", auto && "@beside/page:hidden"), "aria-hidden": true }), _jsx("span", { className: cn("min-w-0 truncate text-meta font-medium text-ink", auto && "@beside/page:sr-only"), children: label }), alertTone === undefined ? null : (_jsxs(Tag, { tone: alertTone, children: [_jsxs("span", { className: cn("hidden items-center gap-1", auto && "@beside/page:inline-flex"), children: [_jsx(AlertIcon, { className: "size-3", strokeWidth: 2.5, "aria-hidden": true }), notices] }), _jsx("span", { className: cn(auto && "@beside/page:sr-only"), children: fillCopy(notices === 1 ? copy.record.noticeOne : copy.record.noticeMany, {
208
246
  count: notices,
209
247
  }) })] })), messages === undefined
210
248
  ? null
@@ -212,8 +250,7 @@ export function Activity({ messages, events, alerts = [], alertsId: ownAlertsId,
212
250
  }
213
251
  return (_jsxs("section", { "aria-labelledby": titleId, "data-activity": "open", className: cn("flex w-full min-w-0 flex-col rounded-box border border-line bg-surface",
214
252
  /* Beside the sheet: its column, joined to it — the sheet's right edge is the line. */
215
- auto &&
216
- "@beside/page:w-(--container-activity) @beside/page:rounded-l-none @beside/page:border-l-0"), children: [_jsxs("header", { className: "flex min-w-0 items-center gap-2 border-b border-line py-1.5 pr-1.5 pl-3", children: [_jsx(ActivityIcon, { className: "size-(--size-icon-md) shrink-0 text-muted", "aria-hidden": true }), _jsx("h2", { id: titleId, className: "min-w-0 truncate text-meta font-semibold text-ink", children: label }), _jsxs("span", { className: "ml-auto flex shrink-0", children: [_jsx("span", { className: cn("flex", auto && "@beside/page:hidden"), children: _jsx(IconButton, { icon: ChevronUp, label: fillCopy(copy.activity.fold, { label }), onClick: onToggle }) }), auto ? (_jsx("span", { className: "hidden @beside/page:flex", children: _jsx(IconButton, { icon: PanelRightClose, label: fillCopy(copy.activity.fold, { label }), onClick: onToggle }) })) : null] })] }), notices === 0 ? null : (
253
+ auto && "@beside/page:w-(--container-activity)", auto && joined && "@beside/page:rounded-l-none @beside/page:border-l-0"), children: [_jsxs("header", { className: "flex min-w-0 items-center gap-2 border-b border-line py-1.5 pr-1.5 pl-3", children: [_jsx(ActivityIcon, { className: "size-(--size-icon-md) shrink-0 text-muted", "aria-hidden": true }), _jsx("h2", { id: titleId, className: "min-w-0 truncate text-meta font-semibold text-ink", children: label }), _jsxs("span", { className: "ml-auto flex shrink-0", children: [_jsx("span", { className: cn("flex", auto && "@beside/page:hidden"), children: _jsx(IconButton, { icon: ChevronUp, label: fillCopy(copy.activity.fold, { label }), onClick: onToggle }) }), auto ? (_jsx("span", { className: "hidden @beside/page:flex", children: _jsx(IconButton, { icon: PanelRightClose, label: fillCopy(copy.activity.fold, { label }), onClick: onToggle }) })) : null] })] }), notices === 0 ? null : (
217
254
  /* NOW, before what happened. The rail's indicator sends the focus here, so it is
218
255
  focusable without being a tab stop. */
219
256
  _jsxs("section", { id: alertsId, tabIndex: -1, "aria-label": copy.activity.alerts, "data-activity-alerts": "", className: "flex min-w-0 scroll-mt-(--size-appbar) flex-col gap-2 border-b border-line px-3 py-3 outline-0 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-primary", children: [_jsxs("h3", { className: "flex items-center gap-2 px-1 text-micro font-medium text-muted", children: [copy.activity.alerts, _jsx(Tag, { tone: alertTone ?? "info", children: notices })] }), (() => {
@@ -1,4 +1,4 @@
1
- export { Activity, type ActivityAlert, type ActivityEvent, type ActivityLayout, type ActivityProps, useActivity, } from "./Activity.js";
1
+ export { Activity, type ActivityAlert, type ActivityChange, type ActivityEvent, type ActivityLayout, type ActivityProps, useActivity, } from "./Activity.js";
2
2
  export { ActivityBadge, type ActivityState, } from "./ActivityBadge.js";
3
3
  export { type Message, MessageComposer, type MessageComposerProps, type MessageKind, writeANote, } from "./Messages.js";
4
4
  export { Timeline, type TimelineItemProps, type TimelineProps, } from "./Timeline.js";
@@ -1,4 +1,7 @@
1
- import type { ReactNode } from "react";
1
+ import type { Tone } from "../../foundations/types.js";
2
+ import { type MetricProps } from "../../primitives/value/Metric.js";
3
+ import type { LucideIcon } from "lucide-react";
4
+ import { type ReactNode } from "react";
2
5
  /**
3
6
  * A BOARD: the tiles of a dashboard — Odoo's «Tableros», a BI page — over one slice of data.
4
7
  *
@@ -28,6 +31,18 @@ import type { ReactNode } from "react";
28
31
  * chart it will hold (`--size-tile-body`), so a neighbour landing never moves the grid. The
29
32
  * board's own `state` is the same for what the board reads as a whole: its headline numbers.
30
33
  * The application (or web-framework's boards) decides each state; web-ui only draws it.
34
+ *
35
+ * ── A tile is a panel of the page, and looks like one ──────────────────
36
+ *
37
+ * A tile used to be a box with a hard border (`line-strong`) and 16 px of air, the radius of
38
+ * a card inside a form: on the near-white ground the border did all the separating, and a
39
+ * page of them read as a wireframe. A tile is a PANEL — the panel's radius, the soft
40
+ * hairline every card has, more air — and its look is its own tokens (`--ui-tile-*`),
41
+ * falling back to the card's.
42
+ *
43
+ * The headline numbers are `BoardStat`s in a `BoardStats` row: tiles too, the same width as
44
+ * the columns under them, the figure in its own type step (`figure`, `hero`) and the trend
45
+ * beside it. `Metric` stays what it is — the chip that filters a list.
31
46
  */
32
47
  /** What a tile — or the board's own headline reading — is doing. */
33
48
  export type BoardState = {
@@ -63,19 +78,76 @@ declare const SPAN: {
63
78
  readonly 2: "@3xl:col-span-2";
64
79
  readonly full: "col-span-full";
65
80
  };
81
+ declare const ROWS: {
82
+ readonly 1: "";
83
+ readonly 2: "@3xl:row-span-2";
84
+ };
66
85
  export type BoardTileProps = {
67
86
  title: string;
87
+ /** What the tile is about, beside its title: a mailbox, a shield. */
88
+ icon?: LucideIcon;
89
+ /** What it counts and how, behind an ⓘ: the sentence that does not fit under the title. */
90
+ hint?: ReactNode;
68
91
  /** One line under the title: what it counts, or what a press on it does. */
69
92
  description?: ReactNode;
70
93
  /** The tile's own buttons, at its top right: open the list behind it, download. */
71
94
  actions?: ReactNode;
72
95
  /** How many columns it takes: a time series reads better wide. */
73
96
  span?: keyof typeof SPAN;
97
+ /** How many rows: a tall tile beside two short ones stacked. From two columns up. */
98
+ rows?: keyof typeof ROWS;
74
99
  /** Reading, ready or failed. Not ready, the body is the state, the height of a chart; the
75
100
  * title, its description and its actions stay. */
76
101
  state?: BoardState;
77
102
  children: ReactNode;
78
103
  };
79
104
  /** One tile of a `Board`: a titled surface around a chart, a list or a number. */
80
- export declare function BoardTile({ title, description, actions, span, state, children, }: BoardTileProps): import("react").JSX.Element;
105
+ export declare function BoardTile({ title, icon, hint, description, actions, span, rows, state, children, }: BoardTileProps): import("react").JSX.Element;
106
+ export type BoardStatProps = {
107
+ /** What the figure counts: «Mensajes recibidos». Sentence case, no colon. */
108
+ label: string;
109
+ /** The figure, already written or a number (written in the copy's locale). Absent — and not
110
+ * reading — it says «Sin datos»: nothing to compute it from, which is not zero. */
111
+ value?: number | string;
112
+ icon?: LucideIcon;
113
+ /** What it counts and how, behind an ⓘ beside the label. */
114
+ hint?: ReactNode;
115
+ /** A second reading under the figure, already formatted: «de 1.240 recibidos». */
116
+ detail?: string;
117
+ /** How it moved against a NAMED period — the same mark as `Metric.change`. */
118
+ change?: MetricProps["change"];
119
+ /** The last periods, oldest first: drawn as a sparkline beside the figure. */
120
+ trend?: readonly (number | null)[];
121
+ /** The ONE figure the board leads with: the hero step (≥ 48 px). At most one per board. */
122
+ hero?: boolean;
123
+ /**
124
+ * The STATE of the reading, never decoration: a share of clean mail under its floor is
125
+ * `bad`. It tints the tile and its icon; the label, the detail or the hint has to say why
126
+ * in words, because a colour alone is not read by everyone.
127
+ */
128
+ tone?: Tone;
129
+ /** Reading or failed: the figure's place keeps its size, the label stays. */
130
+ state?: BoardState;
131
+ /** Columns in the row of stats. */
132
+ span?: 1 | 2;
133
+ };
134
+ /**
135
+ * A board's headline figure as a tile: the label (with its icon and ⓘ), the figure big, and
136
+ * under it how it moved and the shape of the last periods.
137
+ *
138
+ * Context: it is NOT a `Metric`. A metric is a chip over a list that narrows it when pressed —
139
+ * small, the size of what it filters. A stat tile is read before anything else on a board
140
+ * and pressed for nothing; it has the width of the columns under it, so the page is one grid,
141
+ * and the figure is in the figure step, in proportional digits (tabular digits space a lone
142
+ * «121» like «000»; they are for columns).
143
+ */
144
+ export declare function BoardStat({ label, value, icon, hint, detail, change, trend, hero, tone, state, span, }: BoardStatProps): import("react").JSX.Element;
145
+ /**
146
+ * The row of a board's stat tiles: as wide as the grid under it, every tile the same width —
147
+ * two per row when the board is narrow, all in one row from a wide board up. A row of
148
+ * figures of different widths reads as figures of different kinds.
149
+ */
150
+ export declare function BoardStats({ children }: {
151
+ children: ReactNode;
152
+ }): import("react").JSX.Element;
81
153
  export {};
@@ -2,7 +2,11 @@
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { fillCopy, useUiCopy } from "../../foundations/copy.js";
4
4
  import { Button } from "../../primitives/button/Button.js";
5
+ import { Sparkline } from "../../primitives/chart/Sparkline.js";
6
+ import { Hint } from "../../primitives/hint/Hint.js";
5
7
  import { Failed } from "../../primitives/notice/Notice.js";
8
+ import { MetricChange } from "../../primitives/value/Metric.js";
9
+ import { useMemo } from "react";
6
10
  const READY = { status: "ready" };
7
11
  function Failure({ heading, state, }) {
8
12
  const copy = useUiCopy();
@@ -28,11 +32,70 @@ const SPAN = {
28
32
  2: "@3xl:col-span-2",
29
33
  full: "col-span-full",
30
34
  };
35
+ const ROWS = { 1: "", 2: "@3xl:row-span-2" };
36
+ /** The skin every tile shares, a stat tile included: a panel on the ground. */
37
+ const TILE = "rounded-ui-tile border border-ui-tile-border bg-ui-tile";
38
+ /** The mark of what a tile is about: its icon in a quiet square, never in a colour of its
39
+ * own — the colour of a tile is its state, not its subject. */
40
+ function TileIcon({ icon: Icon, tone }) {
41
+ return (_jsx("span", { "aria-hidden": true, className: `flex size-8 shrink-0 items-center justify-center rounded-control ${tone === undefined || tone === "neutral" ? "bg-ink/5 text-muted" : TONE[tone].icon}`, children: _jsx(Icon, { className: "size-(--size-icon-md)", strokeWidth: 2 }) }));
42
+ }
43
+ /** A tile's heading: the icon, the title and its ⓘ — what it counts, said on demand. */
44
+ function TileHeading({ title, icon, hint, tone, size = "title", }) {
45
+ return (_jsxs("div", { className: "flex min-w-0 items-center gap-2.5", children: [icon === undefined ? null : _jsx(TileIcon, { icon: icon, tone: tone }), _jsx("h2", { className: `min-w-0 truncate font-semibold text-ink ${size === "title" ? "text-lead" : "text-meta"}`, children: title }), hint === undefined ? null : _jsx(Hint, { children: hint })] }));
46
+ }
31
47
  /** One tile of a `Board`: a titled surface around a chart, a list or a number. */
32
- export function BoardTile({ title, description, actions, span = 1, state = READY, children, }) {
48
+ export function BoardTile({ title, icon, hint, description, actions, span = 1, rows = 1, state = READY, children, }) {
33
49
  const copy = useUiCopy();
34
- return (_jsxs("section", { "aria-label": title, ...(state.status === "loading" ? { "aria-busy": true } : {}), "data-ui": "board.tile", className: `flex min-w-0 flex-col gap-4 rounded-ui-card border border-line-strong bg-ui-card p-4 ${SPAN[span]}`, children: [_jsxs("header", { className: "flex min-w-0 items-start justify-between gap-3", children: [_jsxs("div", { className: "min-w-0", children: [_jsx("h2", { className: "text-lead font-semibold text-ink", children: title }), description === undefined ? null : (_jsx("p", { className: "mt-0.5 text-meta text-muted", children: description }))] }), actions === undefined ? null : (_jsx("div", { className: "flex shrink-0 items-center gap-1", children: actions }))] }), state.status === "loading" ? (
50
+ return (_jsxs("section", { "aria-label": title, ...(state.status === "loading" ? { "aria-busy": true } : {}), "data-ui": "board.tile", className: `flex min-w-0 flex-col gap-4 p-5 ${TILE} ${SPAN[span]} ${ROWS[rows]}`, children: [_jsxs("header", { className: "flex min-w-0 items-start justify-between gap-3", children: [_jsxs("div", { className: "min-w-0", children: [_jsx(TileHeading, { title: title, icon: icon, hint: hint }), description === undefined ? null : (_jsx("p", { className: "mt-0.5 text-meta text-muted", children: description }))] }), actions === undefined ? null : (_jsx("div", { className: "flex shrink-0 items-center gap-1", children: actions }))] }), state.status === "loading" ? (
35
51
  /* A quiet block where the chart goes. It appears late, like every skeleton: a fast
36
52
  read never shows it. */
37
53
  _jsx("div", { className: "min-h-(--size-tile-body) animate-reveal-late rounded-control bg-ink/4", children: _jsx("span", { className: "sr-only", children: copy.failed.loading }) })) : state.status === "failed" ? (_jsx("div", { className: "flex min-h-(--size-tile-body) flex-col justify-center", children: _jsx(Failure, { heading: fillCopy(copy.board.tileFailed, { title }), state: state }) })) : (children)] }));
38
54
  }
55
+ /* ==================================================================== *
56
+ * THE STAT TILE — the headline numbers of a board.
57
+ * ==================================================================== */
58
+ const TONE = {
59
+ neutral: { tile: "", icon: "bg-ink/5 text-muted" },
60
+ info: { tile: "bg-info/6 border-info/25", icon: "bg-info/12 text-info" },
61
+ good: { tile: "bg-good/6 border-good/25", icon: "bg-good/12 text-good" },
62
+ warn: { tile: "bg-warn/8 border-warn/30", icon: "bg-warn/14 text-warn" },
63
+ bad: { tile: "bg-bad/6 border-bad/25", icon: "bg-bad/12 text-bad" },
64
+ /* The gold never draws the border of a state (PRINCIPLES §3): only the wash. */
65
+ accent: { tile: "bg-accent/12", icon: "bg-accent/20 text-ink" },
66
+ };
67
+ /**
68
+ * A board's headline figure as a tile: the label (with its icon and ⓘ), the figure big, and
69
+ * under it how it moved and the shape of the last periods.
70
+ *
71
+ * Context: it is NOT a `Metric`. A metric is a chip over a list that narrows it when pressed —
72
+ * small, the size of what it filters. A stat tile is read before anything else on a board
73
+ * and pressed for nothing; it has the width of the columns under it, so the page is one grid,
74
+ * and the figure is in the figure step, in proportional digits (tabular digits space a lone
75
+ * «121» like «000»; they are for columns).
76
+ */
77
+ export function BoardStat({ label, value, icon, hint, detail, change, trend, hero = false, tone, state = READY, span = 1, }) {
78
+ const copy = useUiCopy();
79
+ const percent = useMemo(() => new Intl.NumberFormat(copy.locale, {
80
+ style: "percent",
81
+ maximumFractionDigits: 1,
82
+ signDisplay: "exceptZero",
83
+ }), [copy.locale]);
84
+ const loading = state.status === "loading";
85
+ const missing = value === undefined;
86
+ const figure = missing
87
+ ? copy.board.noData
88
+ : typeof value === "number"
89
+ ? value.toLocaleString(copy.locale)
90
+ : value;
91
+ const shade = tone === undefined ? "" : TONE[tone].tile;
92
+ return (_jsxs("section", { "aria-label": label, ...(loading ? { "aria-busy": true } : {}), "data-ui": "board.stat", ...(tone === undefined ? {} : { "data-tone": tone }), className: `flex min-w-0 flex-col gap-3 p-5 ${TILE} ${shade} ${span === 2 ? "@xl:col-span-2" : ""}`, children: [_jsx(TileHeading, { title: label, icon: icon, hint: hint, tone: tone, size: "label" }), state.status === "failed" ? (_jsx(Failure, { heading: fillCopy(copy.board.tileFailed, { title: label }), state: state })) : (_jsxs("div", { className: "flex min-w-0 items-end justify-between gap-4", children: [_jsxs("div", { className: "flex min-w-0 flex-col gap-1", children: [loading ? (_jsx("span", { "aria-hidden": true, className: `inline-block w-24 animate-reveal-late rounded-control bg-ink/8 ${hero ? "h-(--text-hero)" : "h-(--text-figure)"}` })) : (_jsx("span", { "data-ui": "board.stat.value", className: `min-w-0 truncate font-semibold text-ink ${hero ? "text-hero" : "text-figure"} ${missing ? "text-muted" : ""}`, children: figure })), loading ? _jsx("span", { className: "sr-only", children: copy.failed.loading }) : null, loading || (detail === undefined && change === undefined) ? null : (_jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-x-2 gap-y-0.5", children: [change === undefined ? null : (_jsx(MetricChange, { change: change, format: percent.format })), detail === undefined ? null : (_jsx("span", { className: "min-w-0 truncate text-micro text-muted", children: detail }))] }))] }), loading || trend === undefined ? null : (_jsx("div", { className: "w-2/5 max-w-40 shrink-0 pb-1", children: _jsx(Sparkline, { values: trend, label: label }) }))] }))] }));
93
+ }
94
+ /**
95
+ * The row of a board's stat tiles: as wide as the grid under it, every tile the same width —
96
+ * two per row when the board is narrow, all in one row from a wide board up. A row of
97
+ * figures of different widths reads as figures of different kinds.
98
+ */
99
+ export function BoardStats({ children }) {
100
+ return (_jsx("div", { className: "grid min-w-0 grid-cols-1 gap-4 @xl:grid-cols-2 @5xl:grid-flow-col @5xl:grid-cols-none @5xl:auto-cols-fr", children: children }));
101
+ }
@@ -1 +1 @@
1
- export { Board, type BoardProps, type BoardState, BoardTile, type BoardTileProps, } from "./Board.js";
1
+ export { Board, type BoardProps, BoardStat, type BoardState, type BoardStatProps, BoardStats, BoardTile, type BoardTileProps, } from "./Board.js";
@@ -1,3 +1,3 @@
1
1
  /* A dashboard: one filter row, the headline numbers, and tiles over the same slice — each
2
2
  tile reading on its own, with its loading and failed states. */
3
- export { Board, BoardTile, } from "./Board.js";
3
+ export { Board, BoardStat, BoardStats, BoardTile, } from "./Board.js";
@@ -14,6 +14,11 @@
14
14
  --xy-controls-button-border-color-default: var(--color-line);
15
15
  --xy-controls-button-color-default: var(--color-ink);
16
16
  --xy-minimap-background-color-default: var(--color-surface);
17
- --xy-minimap-mask-background-color-default: var(--color-scrim);
17
+ /* The mask covers what is off screen; opaque, it would hide those nodes instead of dimming. */
18
+ --xy-minimap-mask-background-color-default: color-mix(
19
+ in srgb,
20
+ var(--color-scrim) 40%,
21
+ transparent
22
+ );
18
23
  --xy-handle-background-color-default: var(--color-primary);
19
24
  }
@@ -1,6 +1,8 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useFormIndexEntry } from "./FormIndex.js";
3
4
  import { byDensity, useDensity } from "../../foundations/density.js";
5
+ import { useFormStyle } from "../../foundations/form.js";
4
6
  import { Hint } from "../../primitives/hint/Hint.js";
5
7
  import { Tag } from "../../primitives/tag/Tag.js";
6
8
  /* ==================================================================== *
@@ -20,12 +22,21 @@ import { Tag } from "../../primitives/tag/Tag.js";
20
22
  * go into every aspect to discover it was empty. */
21
23
  export function FormSection({ title, hint, status, actions, columns = 1, children, }) {
22
24
  const d = useDensity();
25
+ const settings = useFormStyle() === "settings";
26
+ const indexed = useFormIndexEntry(settings ? title : undefined);
23
27
  const asGrid = columns > 1 && d === "comfortable";
24
28
  const grid = columns === 3 ? "grid-cols-3" : "grid-cols-2";
25
29
  const withHeader = title !== undefined ||
26
30
  status !== undefined ||
27
31
  hint !== undefined ||
28
32
  actions !== undefined;
33
+ if (settings) {
34
+ /* «settings»: the section is a card of rows, one under the other, a hairline between
35
+ them — `columns` does not apply, a row already has its two. Its help is written under
36
+ the title, like a field's under its label. `@container`: each row measures the card
37
+ to decide whether its label still fits beside the control (`grid-setting`). */
38
+ return (_jsxs("section", { ...(indexed === undefined ? {} : { id: indexed }), "data-ui": "form.section", className: "@container flex min-w-0 scroll-mt-3 flex-col gap-1 rounded-ui-card border border-ui-card-border bg-ui-card px-5 py-4", children: [withHeader ? (_jsxs("header", { className: "flex min-w-0 flex-wrap items-start gap-x-2.5 gap-y-1 pb-2", children: [title === undefined && hint === undefined ? null : (_jsxs("div", { className: "flex min-w-0 flex-col gap-0.5", children: [title === undefined ? null : (_jsx("h2", { className: "min-w-0 text-title font-semibold text-ink", children: title })), hint === undefined ? null : (_jsx("p", { className: "max-w-prose text-micro text-muted", children: hint }))] })), status === undefined ? null : _jsx(Tag, { tone: status.tone, children: status.label }), actions === undefined ? null : (_jsx("span", { className: "ml-auto flex shrink-0 items-center gap-1.5", children: actions }))] })) : null, _jsx("div", { className: "flex min-w-0 flex-col divide-y divide-line *:py-3.5 *:first:pt-0 *:last:pb-0", children: children })] }));
39
+ }
29
40
  return (_jsxs("section", { className: `flex min-w-0 flex-col ${byDensity(d, "gap-3", "gap-2")}`, children: [withHeader ? (_jsxs("header", { className: "flex min-w-0 flex-wrap items-center gap-x-2.5 gap-y-1", children: [title === undefined && hint === undefined ? null : (_jsxs("h3", { className: "flex min-w-0 items-center gap-1 text-meta font-medium text-ink", children: [title === undefined ? null : _jsx("span", { className: "min-w-0 truncate", children: title }), hint === undefined ? null : _jsx(Hint, { children: hint })] })), status === undefined ? null : _jsx(Tag, { tone: status.tone, children: status.label }), actions === undefined ? null : (_jsx("span", { className: "ml-auto flex shrink-0 items-center gap-1.5", children: actions }))] })) : null, _jsx("div", { className: `min-w-0 ${asGrid
30
41
  ? `grid ${grid} gap-x-8 ${byDensity(d, "gap-y-3.5", "gap-y-2.5")}`
31
42
  : `flex flex-col ${byDensity(d, "gap-3.5", "gap-2.5")}`}`, children: children })] }));
@@ -0,0 +1,11 @@
1
+ import { type ReactNode } from "react";
2
+ /** Where a form's sections register: the sheet of a «settings» form. */
3
+ export declare function FormIndexScope({ children }: {
4
+ children: ReactNode;
5
+ }): import("react").JSX.Element;
6
+ /** A section's place in the index: the id to give its element, or `undefined` when it is not
7
+ * listed — no title, or no index around it. */
8
+ export declare function useFormIndexEntry(title: string | undefined): string | undefined;
9
+ /** The index itself: the sections' titles, the current one marked, each bringing its
10
+ * section into view. Drawn by `Sheet` in the «settings» style. */
11
+ export declare function FormIndex(): import("react").JSX.Element | null;
@@ -0,0 +1,96 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useUiCopy } from "../../foundations/copy.js";
4
+ import { createContext, useContext, useEffect, useId, useMemo, useState, useSyncExternalStore, } from "react";
5
+ function createRegistry() {
6
+ let entries = [];
7
+ const listeners = new Set();
8
+ const emit = () => {
9
+ for (const listener of listeners)
10
+ listener();
11
+ };
12
+ return {
13
+ register(entry) {
14
+ entries = [...entries.filter((one) => one.id !== entry.id), entry];
15
+ emit();
16
+ return () => {
17
+ entries = entries.filter((one) => one.id !== entry.id);
18
+ emit();
19
+ };
20
+ },
21
+ subscribe(listener) {
22
+ listeners.add(listener);
23
+ return () => listeners.delete(listener);
24
+ },
25
+ snapshot: () => entries,
26
+ };
27
+ }
28
+ const NONE = [];
29
+ const IndexContext = createContext(null);
30
+ /** Where a form's sections register: the sheet of a «settings» form. */
31
+ export function FormIndexScope({ children }) {
32
+ const [registry] = useState(createRegistry);
33
+ return _jsx(IndexContext, { value: registry, children: children });
34
+ }
35
+ /** A section's place in the index: the id to give its element, or `undefined` when it is not
36
+ * listed — no title, or no index around it. */
37
+ export function useFormIndexEntry(title) {
38
+ const registry = useContext(IndexContext);
39
+ const id = useId();
40
+ useEffect(() => {
41
+ if (registry === null || title === undefined)
42
+ return;
43
+ return registry.register({ id, title });
44
+ }, [registry, id, title]);
45
+ return registry === null || title === undefined ? undefined : id;
46
+ }
47
+ function inDocumentOrder(entries) {
48
+ return [...entries].sort((a, b) => {
49
+ const first = document.getElementById(a.id);
50
+ const second = document.getElementById(b.id);
51
+ if (first === null || second === null)
52
+ return 0;
53
+ return first.compareDocumentPosition(second) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1;
54
+ });
55
+ }
56
+ /** The index itself: the sections' titles, the current one marked, each bringing its
57
+ * section into view. Drawn by `Sheet` in the «settings» style. */
58
+ export function FormIndex() {
59
+ const copy = useUiCopy();
60
+ const registry = useContext(IndexContext);
61
+ const entries = useSyncExternalStore(registry?.subscribe ?? (() => () => undefined), registry?.snapshot ?? (() => NONE), () => NONE);
62
+ const ordered = useMemo(() => inDocumentOrder(entries), [entries]);
63
+ const [current, setCurrent] = useState(undefined);
64
+ /* The section being read is the first one crossing the top two fifths of the screen:
65
+ the one whose title just went by is still the one being read until the next arrives. */
66
+ useEffect(() => {
67
+ if (ordered.length < 2 || typeof IntersectionObserver === "undefined")
68
+ return;
69
+ const seen = new Set();
70
+ const observer = new IntersectionObserver((changes) => {
71
+ for (const change of changes) {
72
+ if (change.isIntersecting)
73
+ seen.add(change.target.id);
74
+ else
75
+ seen.delete(change.target.id);
76
+ }
77
+ const first = ordered.find((entry) => seen.has(entry.id));
78
+ if (first !== undefined)
79
+ setCurrent(first.id);
80
+ }, { rootMargin: "0px 0px -60% 0px" });
81
+ for (const entry of ordered) {
82
+ const element = document.getElementById(entry.id);
83
+ if (element !== null)
84
+ observer.observe(element);
85
+ }
86
+ return () => observer.disconnect();
87
+ }, [ordered]);
88
+ if (ordered.length < 2)
89
+ return null;
90
+ const marked = current ?? ordered[0]?.id;
91
+ return (_jsx("nav", { "aria-label": copy.field.sections, "data-ui": "form.index", className: "hidden w-(--container-form-index) shrink-0 @3xl/form:block", children: _jsx("ul", { className: "sticky top-3 flex flex-col gap-0.5", children: ordered.map((entry) => (_jsx("li", { children: _jsx("a", { href: `#${entry.id}`, ...(entry.id === marked ? { "aria-current": "location" } : {}), onClick: (event) => {
92
+ event.preventDefault();
93
+ document.getElementById(entry.id)?.scrollIntoView({ block: "start" });
94
+ setCurrent(entry.id);
95
+ }, className: "block truncate rounded-ui-nav px-2.5 py-1.5 text-meta text-muted transition-colors duration-(--duration-instant) outline-0 hover:bg-ink/5 hover:text-ink focus-visible:outline-2 focus-visible:outline-primary aria-[current]:bg-ui-nav-current aria-[current]:font-medium aria-[current]:text-ink", children: entry.title }) }, entry.id))) }) }));
96
+ }