@tristan2828/ui-foundation 4.79.0 → 4.81.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.
package/README.md CHANGED
@@ -18,7 +18,7 @@ than installing this by hand:
18
18
 
19
19
  | Import | What |
20
20
  |---|---|
21
- | `@tristan2828/ui-foundation` | `AppShell`, `DataTable`, `EntityView` (with `EditableValue`, `editInPlace`, printing its notes and `usePrinting`), `EntityForm`, `Markdown` (with `countTasks`, `toggleTaskAt`), `RichTextEditor`, `ErrorState`, `MultiChoice`, `MultiReference`, `ListEditor`, `PasswordInput`, `RouteErrorBoundary`, `FoundationProviders`, `DataEnvironmentBanner`, `LoginRoute`, `RegisterRoute`, `useAuth`, `useTableUrlState`, `useRecordUpdate`, `useDebouncedValue`, `createQueryClient`, `cn`; types `Page`, `AppError`, `QuerySpec`. For timed screens (`docs/foundation/timed-screens.md`): `SessionView`, `useSessionClock`, `useWakeLock`, `useMuted`, `usePrefersReducedMotion`, and the audio cues `unlockAudio`, `chime`, `sequence`, `cancelCues`, `onCuesRecovered`, `cuesInSync`, `keepAudioAlive`, `say`, `hush`, `vibrate`, `canVibrate`. For reminders (`docs/foundation/reminders.md`): `AllowReminders`, `usePushPermission`. For a record opened in a dialog over its list (`docs/foundation/add-an-entity.md`): `RecordDialogRoute`, `RecordLink`, `useOpenRecord`, `useRecordDialog`, `recordDialogState` |
21
+ | `@tristan2828/ui-foundation` | `AppShell`, `DataTable`, `EntityView` (with `EditableValue`, `editInPlace`, printing its notes and `usePrinting`, `KeyStats`, `IconAction`), `EntityForm`, `Markdown` (with `countTasks`, `toggleTaskAt`), `RichTextEditor`, `ErrorState`, `MultiChoice`, `MultiReference`, `ListEditor`, `PasswordInput`, `RouteErrorBoundary`, `FoundationProviders`, `DataEnvironmentBanner`, `LoginRoute`, `RegisterRoute`, `useAuth`, `useTableUrlState`, `useRecordUpdate`, `useDebouncedValue`, `createQueryClient`, `cn`; types `Page`, `AppError`, `QuerySpec`. For timed screens (`docs/foundation/timed-screens.md`): `SessionView`, `useSessionClock`, `useWakeLock`, `useMuted`, `usePrefersReducedMotion`, and the audio cues `unlockAudio`, `chime`, `sequence`, `cancelCues`, `onCuesRecovered`, `cuesInSync`, `keepAudioAlive`, `say`, `hush`, `vibrate`, `canVibrate`. For reminders (`docs/foundation/reminders.md`): `AllowReminders`, `usePushPermission`. For a record opened in a dialog over its list (`docs/foundation/add-an-entity.md`): `RecordDialogRoute`, `RecordLink`, `useOpenRecord`, `useRecordDialog`, `recordDialogState` |
22
22
  | `@tristan2828/ui-foundation/ui/<name>` | shadcn primitives: badge, button, calendar, card, checkbox, combobox, dialog, empty, field, input, input-group, label, popover, select, separator, sheet, sidebar, skeleton, sonner, spinner, switch, table, textarea, tooltip |
23
23
  | `@tristan2828/ui-foundation/gateway` | `safeFetch`, `toAppError`, `networkError` — for an app's `src/api/gateway/` only |
24
24
  | `@tristan2828/ui-foundation/mocks` | MSW: `authHandlers`, `environmentHandlers`, `resetMockAuth`, `getMockCurrentUser`, `MOCK_USER`, `exposeMswForE2E` |
@@ -4,25 +4,25 @@
4
4
  ## Index
5
5
 
6
6
  - [The reference files](#the-reference-files) · lines 41–63
7
- - [Before anything: the entity plan](#before-anything-the-entity-plan) · lines 65–802
7
+ - [Before anything: the entity plan](#before-anything-the-entity-plan) · lines 65–806
8
8
  - Step 1: Add `<Entity>` to `openapi.yaml` · lines 107–114
9
9
  - Step 2: `npm run gen:api` · lines 115–116
10
10
  - Step 3: Add gateway tests in `tests/gateway/<entity>.test.ts`, derived from the spec · lines 117–128
11
11
  - Step 4: Add MSW handlers in `src/mocks/<entity>.ts` · lines 129–138
12
12
  - Step 5: Add a gateway module in `src/api/gateway/<entity>.ts` · lines 139–143
13
- - Step 6: Copy the reference files, one for one, not just the two screens · lines 144–689
14
- - Step 7: Register routes · lines 690–705
15
- - Step 8: Add Playwright specs for all three screens · lines 706–784
16
- - Step 9: Register the nav entry and route names · lines 785–799
17
- - Step 10: `npm run verify`. · lines 800–802
18
- - [How a list opens a record](#how-a-list-opens-a-record) · lines 804–953
19
- - [The record view](#the-record-view) · lines 917–953
20
- - [What not to copy](#what-not-to-copy) · lines 955–981
21
- - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 983–1000
22
- - [Deleting](#deleting) · lines 1002–1031
23
- - [Fields only a script writes](#fields-only-a-script-writes) · lines 1033–1054
24
- - [Searching one part of the app](#searching-one-part-of-the-app) · lines 1056–1065
25
- - [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1068–1107
13
+ - Step 6: Copy the reference files, one for one, not just the two screens · lines 144–693
14
+ - Step 7: Register routes · lines 694–709
15
+ - Step 8: Add Playwright specs for all three screens · lines 710–788
16
+ - Step 9: Register the nav entry and route names · lines 789–803
17
+ - Step 10: `npm run verify`. · lines 804–806
18
+ - [How a list opens a record](#how-a-list-opens-a-record) · lines 808–960
19
+ - [The record view](#the-record-view) · lines 921–960
20
+ - [What not to copy](#what-not-to-copy) · lines 962–988
21
+ - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 990–1007
22
+ - [Deleting](#deleting) · lines 1009–1038
23
+ - [Fields only a script writes](#fields-only-a-script-writes) · lines 1040–1061
24
+ - [Searching one part of the app](#searching-one-part-of-the-app) · lines 1063–1072
25
+ - [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1075–1114
26
26
 
27
27
  <!-- /index -->
28
28
 
@@ -414,9 +414,12 @@ is a filled-in example while the Widgets demo is still here).
414
414
  plan's "View screen" section lists:
415
415
 
416
416
  - **Title and badges.** The plan's title field is the page's `<h1>`.
417
- Its badge fields sit beside it, each the same `Badge` and variant map
418
- as its table cell. Edit (a `Button` rendering a `Link` to
419
- `/<entity>/:id/edit`) and the delete action go in `actions`.
417
+ Its badge fields sit on its line, after it (`badges`), each the same
418
+ `Badge` and variant map as its table cell. Edit (a `Button`
419
+ rendering a `Link` to `/<entity>/:id/edit`) and the delete action go
420
+ in `actions`, Delete as an `IconAction` (`icon={Trash2Icon}
421
+ label="Delete" tone="destructive"`, the dialog's trigger through
422
+ `render`).
420
423
  - **The browser tab** reads the record's title once it loads
421
424
  ("Wireless Mouse · <app>"): `EntityView` sets it from `title`, and
422
425
  puts the nav's ("Widgets · <app>") back while loading, on an error
@@ -471,9 +474,10 @@ is a filled-in example while the Widgets demo is still here).
471
474
  of linked records, a done-count, from the shared lookups in
472
475
  `<entity>-format.ts`. Never re-derive one for the view.
473
476
  - **An empty value is passed through as it is** (`null`, `''`, or
474
- `list.length > 0 && …`), and `EntityView` shows the field's
475
- `emptyLabel`, the plan's "not set" label, never a blank. A yes/no is
476
- never empty: it reads Yes or No (cell pattern 12).
477
+ `list.length > 0 && …`), and `EntityView` shows a dash (read as "Not
478
+ set"), never a blank. A field's `emptyLabel` replaces it only where
479
+ words say more ("No budget yet"). A yes/no is never empty: it reads
480
+ Yes or No (cell pattern 12).
477
481
  - **A reference links to the referenced record's view** when that
478
482
  entity has one: the name, from the same lookup by id the table uses,
479
483
  inside `<Link to={`/<other>/${id}`}>`. Without a view, the plain name
@@ -548,8 +552,8 @@ is a filled-in example while the Widgets demo is still here).
548
552
  (under the record, or under the page whose note it's in).
549
553
  - **Notes worth taking on paper** (a visit's prep and questions, a
550
554
  guide, a checklist to tick by hand): mark each of those sections
551
- `print: true`. The header gets a Print notes button (`printLabel`
552
- renames it) that prints the marked sections alone, under the title
555
+ `print: true`. The header gets a Print notes icon (`printLabel`
556
+ renames its tooltip and name) that prints the marked sections alone, under the title
553
557
  and subtitle: no rail, no shell, no buttons, light paper in either
554
558
  theme, headings and bullets as written, nothing folded, tables
555
559
  ruled with room in their empty cells. `print: { answerSpace: true }`
@@ -926,8 +930,9 @@ view reaches them all. A record uses the parts it has, in this order:
926
930
  at once) and other status-like fields as badges, edited in place. A
927
931
  record with a face or a mark of its own (a person's avatar, a
928
932
  service's logo, a cover) puts it left of all that (`leading`, 4.76).
929
- `actions` holds Delete (soft, with Undo) and the record's own commands
930
- (Run, Print), never Edit.
933
+ `actions` holds the record's own commands in words (Run, New visit),
934
+ then Delete (soft, with Undo) as an `IconAction`, never Edit. Print
935
+ notes is an icon of EntityView's own.
931
936
  - **Strip**: the record's key numbers and ratings (`strip`, a
932
937
  `KeyStats`), each edited in place where it's shown.
933
938
  - **Sections**: with long text (notes, a body) `layout="rail"` and
@@ -943,9 +948,11 @@ view reaches them all. A record uses the parts it has, in this order:
943
948
  `?tab=`. Fewer groups stay one scroll, folded by headings. A record's
944
949
  Notes stay outside the tabs, above them, unless they are one tab's
945
950
  content; the rail and the strip never go in a tab.
946
- - **Rail fields beside their labels** (`railFields="beside"`, 4.76) for
947
- a rail of many short facts, so it reads as a list of pairs rather than
948
- a column of labels; keep labels to a word or two.
951
+ - **Rail fields beside their labels** (`railFields`, `beside` by
952
+ default since 4.81), so a rail of short facts reads as a list of pairs
953
+ rather than a column of labels; keep labels to a word or two.
954
+ - **Empty fields folded** (`emptyFields="fold"`, 4.81): each card shows
955
+ what's known, then "N empty" opens the rest, still edited in place.
949
956
  - **A big record's own parts** (a drawing, a player, a checklist of
950
957
  documents) are sections in the view, not a screen of their own.
951
958
 
@@ -3,34 +3,36 @@
3
3
  <!-- index: written by `npm run docs:index` in the package from the headings below; never edit it by hand -->
4
4
  ## Index
5
5
 
6
- - [Palettes](#palettes) · lines 43–110
7
- - [Glow](#glow) · lines 112–130
8
- - [Semantic tones](#semantic-tones) · lines 132–160
9
- - [The three badge styles](#the-three-badge-styles) · lines 162–179
10
- - [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines 181–210
11
- - [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines 212–225
12
- - [Logos and brand marks](#logos-and-brand-marks) · lines 227–271
13
- - [Categorical colour](#categorical-colour) · lines 273–343
14
- - [Heat scale](#heat-scale) · lines 345–406
15
- - [Depth ramps](#depth-ramps) · lines 408–486
16
- - [A stored colour](#a-stored-colour) · lines 488–536
17
- - [Shapes and sizes](#shapes-and-sizes) · lines 538–559
18
- - [Typography](#typography) · lines 561–681
19
- - [Written text (notes)](#written-text-notes) · lines 595–681
20
- - [Density](#density) · lines 683–769
21
- - [Rows on this device](#rows-on-this-device) · lines 742–769
22
- - [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 771–885
23
- - [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 887–964
24
- - [Notices](#notices) · lines 966–994
25
- - [A value over time](#a-value-over-time) · lines 996–1082
26
- - [Several values over time](#several-values-over-time) · lines 1045–1082
27
- - [A list as a board](#a-list-as-a-board) · lines 1084–1135
28
- - [A list as cards](#a-list-as-cards) · lines 1137–1183
29
- - [Key numbers on a record](#key-numbers-on-a-record) · lines 1185–1207
30
- - [A record's tabs, mark and rail](#a-records-tabs-mark-and-rail) · lines 1209–1253
31
- - [Picking at random](#picking-at-random) · lines 1255–1286
32
- - [Filling in what's missing](#filling-in-whats-missing) · lines 1288–1355
33
- - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1357–1382
6
+ - [Palettes](#palettes) · lines 45–112
7
+ - [Glow](#glow) · lines 114–132
8
+ - [Semantic tones](#semantic-tones) · lines 134–162
9
+ - [The three badge styles](#the-three-badge-styles) · lines 164–181
10
+ - [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines 183–212
11
+ - [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines 214–227
12
+ - [Logos and brand marks](#logos-and-brand-marks) · lines 229–273
13
+ - [Categorical colour](#categorical-colour) · lines 275–345
14
+ - [Heat scale](#heat-scale) · lines 347–408
15
+ - [Depth ramps](#depth-ramps) · lines 410–488
16
+ - [A stored colour](#a-stored-colour) · lines 490–538
17
+ - [Shapes and sizes](#shapes-and-sizes) · lines 540–561
18
+ - [Typography](#typography) · lines 563–683
19
+ - [Written text (notes)](#written-text-notes) · lines 597–683
20
+ - [Density](#density) · lines 685–771
21
+ - [Rows on this device](#rows-on-this-device) · lines 744–771
22
+ - [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 773–887
23
+ - [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 889–966
24
+ - [Notices](#notices) · lines 968–996
25
+ - [A value over time](#a-value-over-time) · lines 998–1084
26
+ - [Several values over time](#several-values-over-time) · lines 1047–1084
27
+ - [A list as a board](#a-list-as-a-board) · lines 1086–1137
28
+ - [A list as cards](#a-list-as-cards) · lines 1139–1185
29
+ - [Key numbers on a record](#key-numbers-on-a-record) · lines 1187–1216
30
+ - [A record's header and empty values](#a-records-header-and-empty-values) · lines 1218–1256
31
+ - [A record's tabs, mark and rail](#a-records-tabs-mark-and-rail) · lines 1258–1303
32
+ - [Picking at random](#picking-at-random) · lines 1305–1336
33
+ - [Filling in what's missing](#filling-in-whats-missing) · lines 1338–1405
34
+ - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1407–1432
35
+ - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 1434–1480
34
36
 
35
37
  <!-- /index -->
36
38
 
@@ -1191,7 +1193,7 @@ row under the header, across the page at every width.
1191
1193
  ```tsx
1192
1194
  <EntityView
1193
1195
  subtitle={<EditableValue label="Goal" edit={goals} layout="inline">{goal}</EditableValue>}
1194
- strip={<KeyStats stats={[{ label: 'Done', value: '7', hint: 'of 12' }, { label: 'Next step', value: formatPlainDate(next) }]} />}
1196
+ strip={<KeyStats stats={[{ label: 'Done', icon: HashIcon, value: '7', hint: 'of 12' }, { label: 'Next step', icon: CalendarClockIcon, value: formatPlainDate(next) }]} />}
1195
1197
  … />
1196
1198
  ```
1197
1199
 
@@ -1199,24 +1201,71 @@ row under the header, across the page at every width.
1199
1201
  value in the section title's size and tabular figures, a `hint`
1200
1202
  under it in caption type. One bordered card, the figures side by side,
1201
1203
  wrapping on a phone. A `<dl>`, so each label is read with its value.
1202
- - **An empty value reads as `emptyLabel`** ("Not set"), in body type and
1203
- muted, never a blank or a dash.
1204
+ - **An icon with the word** (`icon`, 4.81): the concept's icon at 13px
1205
+ before the label, in the label's muted tone, one icon per meaning
1206
+ across the app (Lucide: a date `CalendarIcon`, next and review on
1207
+ `CalendarClockIcon`, when and length `ClockIcon`, a count `HashIcon`,
1208
+ status `CircleDotIcon`, price `DollarSignIcon`). The word stays; the
1209
+ icon is decorative. Never an icon alone in the strip.
1210
+ - **An empty value reads as a dash** (`emptyLabel`, 4.81; "Not set"
1211
+ before), in body type and muted, read by a screen reader as "Not set".
1212
+ Never a blank.
1204
1213
  - **Three to five.** It's what the page is for at a glance; anything
1205
1214
  more is a section's label/value rows.
1206
1215
  - **`subtitle`** is the line under the title: what the record is for,
1207
1216
  in muted body type, editable in place like any value.
1208
1217
 
1218
+ ## A record's header and empty values
1219
+
1220
+ The record page standard (4.81): the same header on every record, the
1221
+ data on each its own.
1222
+
1223
+ ```tsx
1224
+ <EntityView
1225
+ title={name}
1226
+ badges={<><StatusSelect … /><Badge variant="outline">Wholesale</Badge></>}
1227
+ subtitle={summary}
1228
+ actions={<><Button variant="outline"><PlusIcon />New order</Button><DeleteSupplier … /></>}
1229
+ emptyFields="fold"
1230
+ … />
1231
+ // Delete: <DialogTrigger render={<IconAction icon={Trash2Icon} label="Delete" tone="destructive" />} />
1232
+ ```
1233
+
1234
+ - **The title's line**: the title, then the status and badges after it
1235
+ (12px apart, 6px between badges), centred on the title's line; a title
1236
+ too long for both pushes them to the next line, starting under it.
1237
+ `subtitle` is the line below, in muted body type.
1238
+ - **Actions**: the record's own commands in words (New visit, Mark
1239
+ done), then the universal ones as `IconAction`s: Print notes
1240
+ (`printer`, EntityView's own) and Delete (`trash-2`, the destructive
1241
+ tone). Each is a square outline button at the header's 36px with its
1242
+ words as both its tooltip and its accessible name. Icon alone is for
1243
+ the universal actions only (Delete, Print notes, Copy link, Pin, Open
1244
+ site, Restore, Open full page, Close, More); everything else keeps its
1245
+ word. `printLook="words"` keeps Print notes as a button with its words.
1246
+ - **An empty value** reads as a dash (`emptyText`, default `'—'`), in the
1247
+ muted text tone, read by a screen reader as "Not set": the same on
1248
+ every field, the presets' included. A field's own `emptyLabel` still
1249
+ wins where words say more than a dash ("No budget yet").
1250
+ - **Folded empties** (`emptyFields="fold"`): each fields card lists its
1251
+ filled fields, then a muted, underlined "N empty" with a down chevron
1252
+ under them opens the rest in their places, each still edited in place,
1253
+ and reads "Hide empty" (the chevron up) while open. A card with
1254
+ nothing empty has no toggle; one with nothing filled has the toggle
1255
+ alone. A value set elsewhere moves its field into the card at once.
1256
+ The fold is per card and isn't remembered.
1257
+
1209
1258
  ## A record's tabs, mark and rail
1210
1259
 
1211
- Three opt-ins on `EntityView` (4.76), each for a record that needs it;
1212
- a record without them is as it was.
1260
+ Three settings on `EntityView` (4.76): tabs and a mark, each for a
1261
+ record that needs it, and rail fields beside their labels, the default
1262
+ since 4.81.
1213
1263
 
1214
1264
  ```tsx
1215
1265
  <EntityView
1216
1266
  layout="rail"
1217
1267
  mobileOrder="main-first"
1218
1268
  leading={<img src={photo} alt="" className="size-12 rounded-full object-cover" />}
1219
- railFields="beside"
1220
1269
  sections={[
1221
1270
  { title: 'Summary', placement: 'rail', fields },
1222
1271
  { title: 'Notes', content: <Markdown>{notes}</Markdown> },
@@ -1246,7 +1295,8 @@ a record without them is as it was.
1246
1295
  the title names the record (`alt=""`, `aria-hidden`); initials in
1247
1296
  foreground on `bg-muted`, an icon in muted foreground on the card
1248
1297
  with its border. "Logos and brand marks" above holds for a logo here.
1249
- - **Rail fields beside** (`railFields="beside"`): the label in a 6 to
1298
+ - **Rail fields beside** (`railFields`, `beside` by default since 4.81;
1299
+ `stacked` puts each label above its value): the label in a 6 to
1250
1300
  7rem column left of its value, baseline-aligned, rows a little tighter
1251
1301
  than stacked. Where the rail's list is under 18rem (a phone narrower
1252
1302
  than ~350px) it stacks as before, and once the rail stacks full width
@@ -1380,3 +1430,51 @@ both themes and every palette.
1380
1430
  - **A list in place under group headings** heads each group in
1381
1431
  `type-label text-muted-foreground` (an `<h3>` under the section's
1382
1432
  title), with `gap-4` between groups and the list's own `gap-2` inside.
1433
+
1434
+ ## The sidebar and the phone's bar
1435
+
1436
+ `AppShell`'s navigation (4.80), all set in the app's `nav` and
1437
+ `bottomBar`; an app that sets none of it looks as it did, except the
1438
+ current entry's bar and the phone's back arrow, which every app gets.
1439
+
1440
+ ```tsx
1441
+ const nav: NavEntry[] = [
1442
+ { to: '/', label: 'Home', icon: HomeIcon, end: true },
1443
+ { label: 'Every day', items: [{ to: '/news', label: 'News', icon: NewspaperIcon, count: unread, countLabel: 'unread' }] },
1444
+ { label: 'Home and money', items: [{ to: '/finance', label: 'Finance', icon: WalletIcon, children: [
1445
+ { label: 'Money', items: [accounts, savings] },
1446
+ { label: 'Spending', items: [budget] },
1447
+ ] }] },
1448
+ { label: 'Tools', placement: 'bottom', items: [fillIn, roadmap] },
1449
+ ]
1450
+ const bottomBar: BottomBarItem[] = [
1451
+ { to: '/', label: 'Home', icon: HouseIcon },
1452
+ { group: 'Every day', icon: SunIcon, sheet: 'tiles' },
1453
+ ]
1454
+ ```
1455
+
1456
+ - **The current entry:** the sidebar's tint and a 3px `--primary` bar
1457
+ at its start, the same mark as a selected or hovered table row, in the
1458
+ sidebar and on the icon rail.
1459
+ - **Headings among a module's pages** (a group `{ label, items }` in an
1460
+ entry's `children`): small caption headings in the sidebar's muted
1461
+ text, each heading's pages a list named by it. Use them for a module
1462
+ with more than about six pages, a few words each; the rail's tooltip
1463
+ names the headings ("Finance: Money, Spending").
1464
+ - **Counts** (`count`, `countLabel`): a plain number at the entry's end
1465
+ in the muted text tone, never a coloured badge; on the icon rail a dot
1466
+ in `--primary` on the icon. Only on entries that ask you to act
1467
+ (unread, to fill in, new); 0 shows nothing. `countLabel` is what the
1468
+ number counts, read after the entry's name ("News 24 unread").
1469
+ - **A section at the foot** (`placement: 'bottom'`): under every other
1470
+ section and `sidebarExtra`, pushed to the sidebar's foot when there's
1471
+ room; for tools rather than modules.
1472
+ - **A phone's back arrow:** below 48rem, a page below a nav entry (a
1473
+ record under Accounts) shows "‹ Accounts" in `--link` at the header's
1474
+ start, linking to the entry. With a `bottomBar` it takes the menu
1475
+ button's place; without one the menu button stays beside it. An
1476
+ entry's own page keeps the menu button.
1477
+ - **An area's sheet as tiles** (`sheet: 'tiles'`): a three-column grid,
1478
+ one tile per entry, the icon in `--link` over the label, bordered,
1479
+ 44px tall at least; the tile holding the page has a `--primary`
1480
+ border. The entries' own pages are left to the module.
@@ -3,14 +3,16 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
3
3
  // sections in thumb reach, where the sidebar is a sheet behind the
4
4
  // header's menu button. An item is a link, or a nav section by its label,
5
5
  // which opens a sheet from the bottom listing that section's entries (and
6
- // their children, under them). The sheet closes on navigation, as the
6
+ // their children, under them, by heading where they have them), or with
7
+ // `sheet: 'tiles'` a grid of the entries as tiles, icon over label, like
8
+ // a phone's home screen. The sheet closes on navigation, as the
7
9
  // sidebar's does. The item holding the current page is marked
8
10
  // (`aria-current`). Shown below the md breakpoint only (the sidebar's own
9
11
  // mobile breakpoint); the shell pads its content by the bar's height and
10
12
  // the phone's safe area, so a page's last row clears it.
11
- import { useState } from 'react';
13
+ import { useId, useState } from 'react';
12
14
  import { Link, useLocation } from 'react-router';
13
- import { bottomBarCurrent, bottomBarSection } from './app-shell-nav.js';
15
+ import { bottomBarCurrent, bottomBarSection, childItems, isNavItemGroup, } from './app-shell-nav.js';
14
16
  import { Sheet, SheetContent, SheetHeader, SheetTitle } from '../ui/sheet.js';
15
17
  const ITEM_CLASS = 'flex min-w-0 flex-1 flex-col items-center justify-center gap-0.5 rounded-md px-1 type-caption text-muted-foreground ' +
16
18
  'outline-none focus-visible:ring-3 focus-visible:ring-ring/50 aria-[current]:text-foreground aria-[current]:font-medium ' +
@@ -23,8 +25,30 @@ const SHEET_LINK_CLASS = 'flex min-h-11 items-center gap-3 rounded-md px-3 type-
23
25
  * plus the bar (4rem and its 1px border) and the phone's safe area.
24
26
  */
25
27
  export const BOTTOM_BAR_PADDING = 'max-md:pb-[calc(--spacing(22)+1px+env(safe-area-inset-bottom))]';
26
- function SheetLinks({ items, activeTo }) {
27
- return (_jsx("ul", { className: "flex flex-col gap-0.5", children: items.map(({ to, label, icon: Icon, children }) => (_jsxs("li", { children: [_jsxs(Link, { to: to, "aria-current": to === activeTo ? 'page' : undefined, className: SHEET_LINK_CLASS, children: [_jsx(Icon, {}), _jsx("span", { className: "truncate", children: label })] }), children && children.length > 0 && (_jsx("div", { className: "ml-5 border-l border-border pl-2", children: _jsx(SheetLinks, { items: children, activeTo: activeTo }) }))] }, to))) }));
28
+ // A tile: the entry's icon over its label, a finger's target at least.
29
+ const TILE_CLASS = 'flex min-h-11 min-w-0 flex-col items-center justify-center gap-1 rounded-lg border border-border bg-background px-1.5 py-2.5 ' +
30
+ 'text-center type-caption text-foreground outline-none hover:bg-accent focus-visible:ring-3 focus-visible:ring-ring/50 ' +
31
+ 'aria-[current]:border-primary aria-[current]:font-medium [&>svg]:size-5 [&>svg]:shrink-0 [&>svg]:text-link';
32
+ function SheetLink({ item, activeTo }) {
33
+ const { to, label, icon: Icon, children } = item;
34
+ return (_jsxs("li", { children: [_jsxs(Link, { to: to, "aria-current": to === activeTo ? 'page' : undefined, className: SHEET_LINK_CLASS, children: [_jsx(Icon, {}), _jsx("span", { className: "truncate", children: label })] }), children && children.length > 0 && (_jsx("div", { className: "ml-5 border-l border-border pl-2", children: _jsx(SheetChildren, { items: children, activeTo: activeTo }) }))] }));
35
+ }
36
+ function SheetGroup({ label, items, activeTo }) {
37
+ const headingId = useId();
38
+ return (_jsxs("li", { children: [_jsx("span", { id: headingId, className: "block px-3 pt-2 pb-0.5 type-caption text-muted-foreground", children: label }), _jsx("ul", { "aria-labelledby": headingId, className: "flex flex-col gap-0.5", children: items.map((item) => (_jsx(SheetLink, { item: item, activeTo: activeTo }, item.to))) })] }));
39
+ }
40
+ function SheetChildren({ items, activeTo }) {
41
+ return (_jsx("ul", { className: "flex flex-col gap-0.5", children: items.map((child) => isNavItemGroup(child) ? (_jsx(SheetGroup, { label: child.label, items: child.items, activeTo: activeTo }, `group:${child.label}`)) : (_jsx(SheetLink, { item: child, activeTo: activeTo }, child.to))) }));
42
+ }
43
+ // The tiles (#N8): one per entry, its pages left to the module itself. The
44
+ // tile holding the current page, its own or one of its pages, is marked.
45
+ function SheetTiles({ items, activeTo }) {
46
+ return (_jsx("ul", { "data-slot": "app-shell-sheet-tiles", className: "grid grid-cols-3 gap-2", children: items.map((item) => {
47
+ const { to, label, icon: Icon } = item;
48
+ // "page" on the module's own page, "true" on one of its pages.
49
+ const current = to === activeTo ? 'page' : childItems(item).some((child) => child.to === activeTo) ? 'true' : undefined;
50
+ return (_jsx("li", { className: "flex min-w-0", children: _jsxs(Link, { to: to, "aria-current": current, className: `${TILE_CLASS} flex-1`, children: [_jsx(Icon, { "aria-hidden": "true" }), _jsx("span", { className: "max-w-full break-words", children: label })] }) }, to));
51
+ }) }));
28
52
  }
29
53
  export function BottomBar({ items, nav, activeTo, }) {
30
54
  // The section open, and the location it was opened at: following a link
@@ -37,6 +61,7 @@ export function BottomBar({ items, nav, activeTo, }) {
37
61
  const shown = items.slice(0, 5);
38
62
  const current = bottomBarCurrent(shown, nav, activeTo);
39
63
  const section = openGroup === null ? undefined : bottomBarSection(nav, openGroup);
64
+ const tiles = shown.some((item) => 'group' in item && item.group === openGroup && item.sheet === 'tiles');
40
65
  return (_jsxs(_Fragment, { children: [_jsx("nav", { "aria-label": "Bottom bar", "data-slot": "app-shell-bottom-bar", className: "fixed inset-x-0 bottom-0 z-20 border-t border-border bg-background pb-[env(safe-area-inset-bottom)] md:hidden", children: _jsx("ul", { className: "flex h-16 items-stretch gap-1 px-2 py-1.5", children: shown.map((item, index) => {
41
66
  const Icon = item.icon;
42
67
  const isCurrent = index === current;
@@ -45,5 +70,5 @@ export function BottomBar({ items, nav, activeTo, }) {
45
70
  }
46
71
  const label = item.label ?? item.group;
47
72
  return (_jsx("li", { className: "flex min-w-0 flex-1", children: _jsxs("button", { type: "button", "aria-haspopup": "dialog", "aria-expanded": openGroup === item.group, "aria-current": isCurrent ? 'true' : undefined, onClick: () => setOpenGroup(item.group), className: ITEM_CLASS, children: [_jsx(Icon, { "aria-hidden": "true" }), _jsx("span", { className: "max-w-full truncate", children: label })] }) }, `group:${item.group}`));
48
- }) }) }), _jsx(Sheet, { open: section !== undefined, onOpenChange: (open) => !open && setOpenGroup(null), children: _jsx(SheetContent, { side: "bottom", className: "max-h-[80dvh] gap-2 pb-[calc(--spacing(4)+env(safe-area-inset-bottom))] md:hidden", children: section && (_jsxs(_Fragment, { children: [_jsx(SheetHeader, { className: "pb-0", children: _jsx(SheetTitle, { children: section.label }) }), _jsx("nav", { "aria-label": section.label, className: "overflow-y-auto px-2", children: _jsx(SheetLinks, { items: section.items, activeTo: activeTo }) })] })) }) })] }));
73
+ }) }) }), _jsx(Sheet, { open: section !== undefined, onOpenChange: (open) => !open && setOpenGroup(null), children: _jsx(SheetContent, { side: "bottom", className: "max-h-[80dvh] gap-2 pb-[calc(--spacing(4)+env(safe-area-inset-bottom))] md:hidden", children: section && (_jsxs(_Fragment, { children: [_jsx(SheetHeader, { className: "pb-0", children: _jsx(SheetTitle, { children: section.label }) }), _jsx("nav", { "aria-label": section.label, className: "overflow-y-auto px-2", children: tiles ? (_jsx(SheetTiles, { items: section.items, activeTo: activeTo })) : (_jsx(SheetChildren, { items: section.items, activeTo: activeTo })) })] })) }) })] }));
49
74
  }
@@ -16,11 +16,43 @@ export type NavItem = {
16
16
  * channels under YouTube, its series under Comics. They show while the
17
17
  * page is this entry or one of them (`open: 'current'`), or always
18
18
  * (`'always'`). On the icon rail they're named in this entry's tooltip.
19
+ * A long module's pages can sit under small headings: a child can be a
20
+ * group (`{ label: 'Money', items }`), and the tooltip then names the
21
+ * headings.
19
22
  */
20
- children?: readonly NavItem[];
23
+ children?: readonly NavChild[];
21
24
  /** When `children` show: while you're in them (`'current'`, the default) or `'always'`. */
22
25
  open?: 'current' | 'always';
26
+ /**
27
+ * A number on the entry that asks you to act (unread articles, records
28
+ * to fill in), drawn at its end in the muted tone; a dot on the icon
29
+ * rail. None, or 0, shows nothing. The app passes it from a query.
30
+ */
31
+ count?: number;
32
+ /**
33
+ * What the count counts, for screen readers: 'unread' reads "24
34
+ * unread". Without it the number is read alone.
35
+ */
36
+ countLabel?: string;
37
+ };
38
+ /**
39
+ * A small heading over some of a module's pages, in its entry's
40
+ * `children`: Finance's Money, Spending and Taxes.
41
+ */
42
+ export type NavItemGroup = {
43
+ label: string;
44
+ items: readonly NavItem[];
23
45
  };
46
+ /** One of an entry's `children`: a page, or a heading over pages. */
47
+ export type NavChild = NavItem | NavItemGroup;
48
+ export declare function isNavItemGroup(child: NavChild): child is NavItemGroup;
49
+ /** An entry's pages, its groups' included, in order. */
50
+ export declare function childItems(item: NavItem): NavItem[];
51
+ /**
52
+ * The rail's tooltip for an entry: its label, then what's under it, by
53
+ * heading where it has them ("Finance: Money, Spending, Taxes").
54
+ */
55
+ export declare function navTooltip(item: NavItem): string;
24
56
  /** A labelled group of sidebar entries: one module's pages, say. */
25
57
  export type NavSection = {
26
58
  label: string;
@@ -34,6 +66,12 @@ export type NavSection = {
34
66
  collapsible?: boolean;
35
67
  /** Whether a collapsible section starts open for someone who has never folded it. Defaults to true. */
36
68
  defaultOpen?: boolean;
69
+ /**
70
+ * Where the section sits: in order with the rest (`'top'`, the
71
+ * default), or at the sidebar's foot, under every other section
72
+ * (`'bottom'`: a Tools group, say).
73
+ */
74
+ placement?: 'top' | 'bottom';
37
75
  };
38
76
  /** One entry of `AppShell`'s `nav`: a page, or a labelled section of pages. */
39
77
  export type NavEntry = NavItem | NavSection;
@@ -45,11 +83,14 @@ export type NavGroup = {
45
83
  /** From its section: the label folds it (NavSection's `collapsible`). */
46
84
  collapsible?: boolean;
47
85
  defaultOpen?: boolean;
86
+ /** From its section: at the sidebar's foot (NavSection's `placement`). */
87
+ placement?: 'bottom';
48
88
  };
49
89
  /**
50
90
  * The sidebar groups for a nav, in order. A flat nav (no sections) is the
51
91
  * one "Navigation" group it always was. Otherwise each section is its own
52
92
  * labelled group, and each run of plain items between them an unlabelled one.
93
+ * Sections placed at the bottom come last, in their own order.
53
94
  */
54
95
  export declare function navGroups(nav: readonly NavEntry[]): NavGroup[];
55
96
  /** Each item and, after it, its children: every page a list of items links. */
@@ -84,6 +125,16 @@ export declare function activeNavTo(nav: readonly NavEntry[], pathname: string):
84
125
  * itself, or on a page no entry covers.
85
126
  */
86
127
  export declare function navPageLabel(nav: readonly NavEntry[], pathname: string): string | undefined;
128
+ /**
129
+ * Where a phone's back arrow goes: the current entry, when the page is
130
+ * below it (a record under Accounts reads "‹ Accounts"). None on an
131
+ * entry's own page, or a page no entry covers: the header keeps its menu
132
+ * button there.
133
+ */
134
+ export declare function navBackTarget(nav: readonly NavEntry[], pathname: string): {
135
+ label: string;
136
+ to: string;
137
+ } | undefined;
87
138
  /**
88
139
  * One item of `AppShell`'s `bottomBar`, the phone's bar of shortcuts: a
89
140
  * page, or one of the nav's sections by its label, which opens a sheet of
@@ -98,6 +149,12 @@ export type BottomBarItem = {
98
149
  group: string;
99
150
  label?: string;
100
151
  icon: IconComponent;
152
+ /**
153
+ * How its sheet shows the section: a list of its entries with their
154
+ * pages (`'list'`, the default), or a grid of tiles, one per entry,
155
+ * icon over label, like a phone's home screen (`'tiles'`).
156
+ */
157
+ sheet?: 'list' | 'tiles';
101
158
  };
102
159
  /** The nav's section with this label, if there is one. */
103
160
  export declare function bottomBarSection(nav: readonly NavEntry[], label: string): NavSection | undefined;
@@ -1,3 +1,20 @@
1
+ export function isNavItemGroup(child) {
2
+ return 'items' in child;
3
+ }
4
+ /** An entry's pages, its groups' included, in order. */
5
+ export function childItems(item) {
6
+ return (item.children ?? []).flatMap((child) => (isNavItemGroup(child) ? child.items : [child]));
7
+ }
8
+ /**
9
+ * The rail's tooltip for an entry: its label, then what's under it, by
10
+ * heading where it has them ("Finance: Money, Spending, Taxes").
11
+ */
12
+ export function navTooltip(item) {
13
+ const children = item.children ?? [];
14
+ if (!children.length)
15
+ return item.label;
16
+ return `${item.label}: ${children.map((child) => child.label).join(', ')}`;
17
+ }
1
18
  export function isNavSection(entry) {
2
19
  return 'items' in entry;
3
20
  }
@@ -5,6 +22,7 @@ export function isNavSection(entry) {
5
22
  * The sidebar groups for a nav, in order. A flat nav (no sections) is the
6
23
  * one "Navigation" group it always was. Otherwise each section is its own
7
24
  * labelled group, and each run of plain items between them an unlabelled one.
25
+ * Sections placed at the bottom come last, in their own order.
8
26
  */
9
27
  export function navGroups(nav) {
10
28
  if (!nav.some(isNavSection))
@@ -20,6 +38,7 @@ export function navGroups(nav) {
20
38
  label: entry.label,
21
39
  items: entry.items,
22
40
  ...(entry.collapsible && { collapsible: true, defaultOpen: entry.defaultOpen ?? true }),
41
+ ...(entry.placement === 'bottom' && { placement: 'bottom' }),
23
42
  });
24
43
  }
25
44
  else {
@@ -28,11 +47,11 @@ export function navGroups(nav) {
28
47
  }
29
48
  if (run.length)
30
49
  groups.push({ items: run });
31
- return groups;
50
+ return [...groups.filter((group) => !group.placement), ...groups.filter((group) => group.placement)];
32
51
  }
33
52
  /** Each item and, after it, its children: every page a list of items links. */
34
53
  export function withChildren(items) {
35
- return items.flatMap((item) => [item, ...(item.children ?? [])]);
54
+ return items.flatMap((item) => [item, ...childItems(item)]);
36
55
  }
37
56
  /** Every page in a nav, sections' items and children included, in order. */
38
57
  export function navItems(nav) {
@@ -45,7 +64,7 @@ export function navItems(nav) {
45
64
  export function childrenOpen(item, activeTo) {
46
65
  if (!item.children?.length)
47
66
  return false;
48
- return item.open === 'always' || item.to === activeTo || item.children.some((child) => child.to === activeTo);
67
+ return item.open === 'always' || item.to === activeTo || childItems(item).some((child) => child.to === activeTo);
49
68
  }
50
69
  /**
51
70
  * The path a `to` names, without its query string or hash: what an entry is
@@ -100,6 +119,20 @@ export function navPageLabel(nav, pathname) {
100
119
  const item = activeNavItem(nav, pathname);
101
120
  return item && navPathname(item.to) !== '/' ? item.label : undefined;
102
121
  }
122
+ /**
123
+ * Where a phone's back arrow goes: the current entry, when the page is
124
+ * below it (a record under Accounts reads "‹ Accounts"). None on an
125
+ * entry's own page, or a page no entry covers: the header keeps its menu
126
+ * button there.
127
+ */
128
+ export function navBackTarget(nav, pathname) {
129
+ const item = activeNavItem(nav, pathname);
130
+ if (!item)
131
+ return undefined;
132
+ const path = navPathname(item.to);
133
+ const trimmed = pathname.length > 1 ? pathname.replace(/\/+$/, '') : pathname;
134
+ return trimmed === path ? undefined : { label: item.label, to: item.to };
135
+ }
103
136
  /** The nav's section with this label, if there is one. */
104
137
  export function bottomBarSection(nav, label) {
105
138
  return nav.find((entry) => isNavSection(entry) && entry.label === label);
@@ -2,7 +2,7 @@ import { type ReactNode } from 'react';
2
2
  import { type BottomBarItem, type NavEntry } from './app-shell-nav.js';
3
3
  import { type AppShellVersion } from './app-shell-version.js';
4
4
  import type { IconComponent } from './icon-component.js';
5
- export type { BottomBarItem, NavEntry, NavItem, NavSection } from './app-shell-nav.js';
5
+ export type { BottomBarItem, NavChild, NavEntry, NavItem, NavItemGroup, NavSection } from './app-shell-nav.js';
6
6
  export type { AppShellVersion } from './app-shell-version.js';
7
7
  export type AppShellProps = {
8
8
  /**
@@ -31,7 +31,12 @@ export type AppShellProps = {
31
31
  * remembered per browser (`defaultOpen` for the first visit); the one
32
32
  * holding the current page stays open, and the icon rail shows every
33
33
  * section's items. An entry's `children` (a module's own pages) show
34
- * under it while you're on one of them.
34
+ * under it while you're on one of them, under small headings where they
35
+ * are groups (`{ label, items }`). The current entry has the tint and a
36
+ * bar at its start; an entry's `count` shows at its end (a dot on the
37
+ * rail); a section with `placement: 'bottom'` sits at the sidebar's foot.
38
+ * On a phone, a page below an entry shows a back arrow to it in the
39
+ * header (design-language.md "The sidebar and the phone's bar").
35
40
  */
36
41
  nav: readonly NavEntry[];
37
42
  /**
@@ -58,9 +63,11 @@ export type AppShellProps = {
58
63
  * breakpoint), in thumb reach: at most five, each a page
59
64
  * (`{ to, label, icon }`) or a nav section by its label
60
65
  * (`{ group: 'Every day', icon }`, with an optional shorter `label`),
61
- * which opens a sheet of that section's entries. The item holding the
66
+ * which opens a sheet of that section's entries (as tiles with
67
+ * `sheet: 'tiles'`). The item holding the
62
68
  * current page is marked. The header's menu button stays, for
63
- * everything. The shell pads its content so nothing sits under the bar.
69
+ * everything, except on a page below a nav entry, where the back arrow
70
+ * takes its place. The shell pads its content so nothing sits under the bar.
64
71
  */
65
72
  bottomBar?: readonly BottomBarItem[];
66
73
  };
@@ -1,11 +1,11 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { ChevronRightIcon, LogOutIcon, MoonIcon, PaletteIcon, Rows3Icon, SunIcon } from 'lucide-react';
2
+ import { ChevronLeftIcon, ChevronRightIcon, LogOutIcon, MoonIcon, PaletteIcon, Rows3Icon, SunIcon } from 'lucide-react';
3
3
  import { useTheme } from 'next-themes';
4
4
  import { useEffect, useId, useState } from 'react';
5
5
  import { Link, Navigate, Outlet, useLocation } from 'react-router';
6
6
  import { useAuth } from '../../auth/use-auth.js';
7
7
  import { BottomBar, BOTTOM_BAR_PADDING } from './app-shell-bottom-bar.js';
8
- import { activeNavTo, childrenOpen, navGroups, navPageLabel, withChildren, } from './app-shell-nav.js';
8
+ import { activeNavTo, childItems, childrenOpen, isNavItemGroup, navBackTarget, navGroups, navPageLabel, navTooltip, withChildren, } from './app-shell-nav.js';
9
9
  import { versionHref, versionLabel } from './app-shell-version.js';
10
10
  import { ErrorState } from './error-state.js';
11
11
  import { useErrorReporter } from '../../error-reporting/error-reporting-context.js';
@@ -16,7 +16,7 @@ import { useRows } from '../../hooks/use-rows.js';
16
16
  import { isPaletteName, PALETTE_LABELS, PALETTES } from '../../lib/palettes.js';
17
17
  import { isRowsName, ROWS, ROWS_LABELS } from '../../lib/rows.js';
18
18
  import { cn } from 'cn';
19
- import { Button } from '../ui/button.js';
19
+ import { Button, buttonVariants } from '../ui/button.js';
20
20
  import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuLabel, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuTrigger, } from '../ui/dropdown-menu.js';
21
21
  import { Skeleton } from '../ui/skeleton.js';
22
22
  import { Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarInset, SidebarMenu, SidebarMenuButton, SidebarMenuItem, SidebarMenuSub, SidebarMenuSubButton, SidebarMenuSubItem, SidebarProvider, SidebarTrigger, useSidebar, } from '../ui/sidebar.js';
@@ -86,6 +86,28 @@ function VersionEntry({ version }) {
86
86
  const className = 'block truncate px-2 type-caption text-sidebar-foreground/70 group-data-[collapsible=icon]:hidden';
87
87
  return href ? (_jsx("a", { href: href, target: "_blank", rel: "noreferrer", className: `${className} hover:underline`, children: label })) : (_jsx("span", { className: className, children: label }));
88
88
  }
89
+ // The current entry's mark (#N2): the sidebar's tint and a 3px bar in
90
+ // the accent at its start, the same mark as a selected or hovered table
91
+ // row, in the sidebar and on the rail.
92
+ const ACTIVE_MARK = 'data-active:shadow-[inset_3px_0_0_0_var(--primary)]';
93
+ // An entry's count (#N3): a plain number at its end in the muted tone,
94
+ // read with what it counts; on the icon rail, a dot on the icon.
95
+ function NavCount({ count, countLabel }) {
96
+ if (!count)
97
+ return null;
98
+ return (_jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": "true", "data-slot": "nav-count", className: "ml-auto shrink-0 type-caption text-muted-foreground tabular-nums group-data-[collapsible=icon]:hidden", children: count }), _jsx("span", { className: "sr-only", children: countLabel ? `${count} ${countLabel}` : count }), _jsx("span", { "aria-hidden": "true", "data-slot": "nav-count-dot", className: "pointer-events-none absolute top-1 right-1 hidden size-1.5 rounded-full bg-primary group-data-[collapsible=icon]:block" })] }));
99
+ }
100
+ function NavSubLink({ item, activeTo }) {
101
+ const { to, label, icon: Icon, count, countLabel } = item;
102
+ const isActive = to === activeTo;
103
+ return (_jsx(SidebarMenuSubItem, { children: _jsxs(SidebarMenuSubButton, { isActive: isActive, className: ACTIVE_MARK, render: _jsx(Link, { to: to, "aria-current": isActive ? 'page' : undefined }), children: [_jsx(Icon, {}), _jsx("span", { className: "min-w-0 flex-1 truncate", children: label }), _jsx(NavCount, { count: count, countLabel: countLabel })] }) }));
104
+ }
105
+ // A heading among a module's pages (#N1): a small label over its pages,
106
+ // a list named by it, so a screen reader hears "Money, list".
107
+ function NavSubGroup({ group, activeTo }) {
108
+ const headingId = useId();
109
+ return (_jsxs("li", { "data-slot": "nav-sub-group", className: "flex flex-col gap-1", children: [_jsx("span", { id: headingId, className: "px-2 pt-1.5 type-caption text-sidebar-foreground/70", children: group.label }), _jsx("ul", { "aria-labelledby": headingId, className: "flex flex-col gap-1", children: group.items.map((item) => (_jsx(NavSubLink, { item: item, activeTo: activeTo }, item.to))) })] }));
110
+ }
89
111
  // One group's entries. A plain Link, not NavLink: NavLink marks every
90
112
  // matching entry current, and only the most specific one should be
91
113
  // (activeNavTo).
@@ -94,18 +116,15 @@ function VersionEntry({ version }) {
94
116
  // as its pages, shown while you're in them (childrenOpen) and otherwise
95
117
  // in the page but hidden, as a folded section's are. The icon rail has no
96
118
  // room for them: there the entry looks current while one of them is, and
97
- // its tooltip names them.
119
+ // its tooltip names them (or their headings).
98
120
  function NavMenu({ items, activeTo }) {
99
121
  const { state, isMobile } = useSidebar();
100
122
  const rail = state === 'collapsed' && !isMobile;
101
123
  return (_jsx(SidebarMenu, { children: items.map((item) => {
102
- const { to, label, icon: Icon, children } = item;
124
+ const { to, label, icon: Icon, children, count, countLabel } = item;
103
125
  const isActive = to === activeTo;
104
- const childActive = children?.some((child) => child.to === activeTo) ?? false;
105
- return (_jsxs(SidebarMenuItem, { children: [_jsxs(SidebarMenuButton, { isActive: isActive || (rail && childActive), tooltip: children?.length ? `${label}: ${children.map((child) => child.label).join(', ')}` : label, render: _jsx(Link, { to: to, "aria-current": isActive ? 'page' : undefined }), children: [_jsx(Icon, {}), _jsx("span", { children: label })] }), children && children.length > 0 && (_jsx(SidebarMenuSub, { hidden: !childrenOpen(item, activeTo), children: children.map(({ to: childTo, label: childLabel, icon: ChildIcon }) => {
106
- const isChildActive = childTo === activeTo;
107
- return (_jsx(SidebarMenuSubItem, { children: _jsxs(SidebarMenuSubButton, { isActive: isChildActive, render: _jsx(Link, { to: childTo, "aria-current": isChildActive ? 'page' : undefined }), children: [_jsx(ChildIcon, {}), _jsx("span", { children: childLabel })] }) }, childTo));
108
- }) }))] }, to));
126
+ const childActive = childItems(item).some((child) => child.to === activeTo);
127
+ return (_jsxs(SidebarMenuItem, { children: [_jsxs(SidebarMenuButton, { isActive: isActive || (rail && childActive), tooltip: navTooltip(item), className: cn('relative', ACTIVE_MARK), render: _jsx(Link, { to: to, "aria-current": isActive ? 'page' : undefined }), children: [_jsx(Icon, {}), _jsx("span", { className: "min-w-0 flex-1 truncate", children: label }), _jsx(NavCount, { count: count, countLabel: countLabel })] }), children && children.length > 0 && (_jsx(SidebarMenuSub, { hidden: !childrenOpen(item, activeTo), children: children.map((child) => isNavItemGroup(child) ? (_jsx(NavSubGroup, { group: child, activeTo: activeTo }, `group:${child.label}`)) : (_jsx(NavSubLink, { item: child, activeTo: activeTo }, child.to))) }))] }, to));
109
128
  }) }));
110
129
  }
111
130
  // Whether a collapsible section is open, remembered per browser by its
@@ -157,6 +176,12 @@ function CollapsibleNavGroup({ group, activeTo }) {
157
176
  storeSectionOpen(group.label, !open);
158
177
  } }), className: "w-full justify-between text-left hover:bg-sidebar-accent hover:text-sidebar-accent-foreground aria-disabled:hover:bg-transparent aria-disabled:hover:text-sidebar-foreground/70", children: [group.label, _jsx(ChevronRightIcon, { "aria-hidden": "true", className: cn('transition-transform', open && 'rotate-90') })] }), _jsx(SidebarGroupContent, { id: contentId, hidden: !open, children: _jsx(NavMenu, { items: group.items, activeTo: activeTo }) })] }));
159
178
  }
179
+ // The phone's back arrow (#N7), below the md breakpoint only: the
180
+ // shell's own way up from a page below a nav entry. Its label is the
181
+ // place it goes, so it reads "Back to Accounts".
182
+ function PhoneBack({ back }) {
183
+ return (_jsxs(Link, { to: back.to, "data-slot": "app-shell-back", "aria-label": `Back to ${back.label}`, className: cn(buttonVariants({ variant: 'ghost', size: 'sm' }), '-ml-2 max-w-[60vw] gap-0.5 px-1.5 text-link hover:text-link md:hidden'), children: [_jsx(ChevronLeftIcon, { "aria-hidden": "true" }), _jsx("span", { className: "truncate", children: back.label })] }));
184
+ }
160
185
  function AppShellSkeleton() {
161
186
  return (_jsxs("div", { className: "flex h-screen w-full gap-4 p-4", "data-state": "loading", children: [_jsx(Skeleton, { className: "h-full w-56 shrink-0" }), _jsxs("div", { className: "flex-1 space-y-4 pt-2", children: [_jsx(Skeleton, { className: "h-8 w-64" }), _jsx(Skeleton, { className: "h-40 w-full" })] })] }));
162
187
  }
@@ -190,11 +215,14 @@ export function AppShell({ title, logo: Logo, nav, sidebarExtra, defaultSidebarO
190
215
  return _jsx(Navigate, { to: "/login", replace: true, state: isLoggingOut ? undefined : { from } });
191
216
  }
192
217
  const activeTo = activeNavTo(nav, location.pathname);
193
- return (_jsxs(TooltipProvider, { children: [reporter && _jsx(ReportRoutePattern, { reporter: reporter }), _jsxs(SidebarProvider, { defaultOpen: storedSidebarOpen(defaultSidebarOpen), children: [_jsx(CloseMobileSidebarOnNavigate, {}), _jsx("nav", { "aria-label": "Primary", children: _jsxs(Sidebar, { collapsible: "icon", children: [_jsx(SidebarHeader, { children: _jsxs("div", { className: "flex items-center gap-2 px-2 group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:px-0", children: [Logo && (_jsx(Logo, { "aria-hidden": "true", className: "size-5 shrink-0 text-sidebar-foreground group-data-[collapsible=icon]:size-4" })), _jsx("span", { className: "truncate text-sm font-semibold text-sidebar-foreground group-data-[collapsible=icon]:hidden", children: title })] }) }), _jsxs(SidebarContent, { children: [navGroups(nav).map((group, groupIndex) => group.collapsible && group.label !== undefined ? (_jsx(CollapsibleNavGroup, { group: { ...group, label: group.label }, activeTo: activeTo }, `${groupIndex}:${group.label}`)) : (_jsxs(SidebarGroup, { children: [group.label !== undefined && _jsx(SidebarGroupLabel, { children: group.label }), _jsx(SidebarGroupContent, { children: _jsx(NavMenu, { items: group.items, activeTo: activeTo }) })] }, `${groupIndex}:${group.label ?? ''}`))), sidebarExtra] }), _jsxs(SidebarFooter, { children: [version && _jsx(VersionEntry, { version: version }), _jsxs("div", { className: "flex items-center justify-between gap-2 px-2 group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:px-0", children: [_jsx("span", { className: "truncate type-caption text-sidebar-foreground/70 group-data-[collapsible=icon]:hidden", children: user.name }), _jsx(Button, { variant: "ghost", size: "icon-sm", "aria-label": "Log out", onClick: () => {
218
+ const back = navBackTarget(nav, location.pathname);
219
+ const groups = navGroups(nav);
220
+ const renderGroup = (group, groupIndex) => group.collapsible && group.label !== undefined ? (_jsx(CollapsibleNavGroup, { group: { ...group, label: group.label }, activeTo: activeTo }, `${group.placement ?? 'top'}:${groupIndex}:${group.label}`)) : (_jsxs(SidebarGroup, { children: [group.label !== undefined && _jsx(SidebarGroupLabel, { children: group.label }), _jsx(SidebarGroupContent, { children: _jsx(NavMenu, { items: group.items, activeTo: activeTo }) })] }, `${group.placement ?? 'top'}:${groupIndex}:${group.label ?? ''}`));
221
+ return (_jsxs(TooltipProvider, { children: [reporter && _jsx(ReportRoutePattern, { reporter: reporter }), _jsxs(SidebarProvider, { defaultOpen: storedSidebarOpen(defaultSidebarOpen), children: [_jsx(CloseMobileSidebarOnNavigate, {}), _jsx("nav", { "aria-label": "Primary", children: _jsxs(Sidebar, { collapsible: "icon", children: [_jsx(SidebarHeader, { children: _jsxs("div", { className: "flex items-center gap-2 px-2 group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:px-0", children: [Logo && (_jsx(Logo, { "aria-hidden": "true", className: "size-5 shrink-0 text-sidebar-foreground group-data-[collapsible=icon]:size-4" })), _jsx("span", { className: "truncate text-sm font-semibold text-sidebar-foreground group-data-[collapsible=icon]:hidden", children: title })] }) }), _jsxs(SidebarContent, { children: [groups.filter((group) => !group.placement).map(renderGroup), sidebarExtra, groups.some((group) => group.placement) && (_jsx("div", { "data-slot": "nav-foot", className: "mt-auto flex flex-col", children: groups.filter((group) => group.placement).map(renderGroup) }))] }), _jsxs(SidebarFooter, { children: [version && _jsx(VersionEntry, { version: version }), _jsxs("div", { className: "flex items-center justify-between gap-2 px-2 group-data-[collapsible=icon]:justify-center group-data-[collapsible=icon]:px-0", children: [_jsx("span", { className: "truncate type-caption text-sidebar-foreground/70 group-data-[collapsible=icon]:hidden", children: user.name }), _jsx(Button, { variant: "ghost", size: "icon-sm", "aria-label": "Log out", onClick: () => {
194
222
  setIsLoggingOut(true);
195
223
  // A failed request still ends the session on screen
196
224
  // (AuthProvider), so this stays a deliberate logout: a
197
225
  // clean /login, never the previous user's page as `from`.
198
226
  logout().catch(() => { });
199
- }, children: _jsx(LogOutIcon, {}) })] })] })] }) }), _jsxs(SidebarInset, { className: "min-w-0", children: [_jsxs("header", { className: "flex h-14 shrink-0 items-center gap-2 border-b border-border px-4", children: [_jsx(SidebarTrigger, {}), _jsx("div", { className: "flex-1" }), _jsx(LookControl, {})] }), _jsx("div", { className: cn('flex-1 p-6', bottomBar?.length && BOTTOM_BAR_PADDING), children: _jsx(Outlet, {}) })] }), bottomBar && bottomBar.length > 0 && _jsx(BottomBar, { items: bottomBar, nav: nav, activeTo: activeTo })] }), _jsx(Toaster, { position: "top-center" })] }));
227
+ }, children: _jsx(LogOutIcon, {}) })] })] })] }) }), _jsxs(SidebarInset, { className: "min-w-0", children: [_jsxs("header", { className: "flex h-14 shrink-0 items-center gap-2 border-b border-border px-4", children: [back && _jsx(PhoneBack, { back: back }), _jsx(SidebarTrigger, { className: cn(back && bottomBar?.length && 'max-md:hidden') }), _jsx("div", { className: "flex-1" }), _jsx(LookControl, {})] }), _jsx("div", { className: cn('flex-1 p-6', bottomBar?.length && BOTTOM_BAR_PADDING), children: _jsx(Outlet, {}) })] }), bottomBar && bottomBar.length > 0 && _jsx(BottomBar, { items: bottomBar, nav: nav, activeTo: activeTo })] }), _jsx(Toaster, { position: "top-center" })] }));
200
228
  }
@@ -0,0 +1,5 @@
1
+ /** The empty text in the muted tone; the dash is read as "Not set". */
2
+ export declare function EmptyText({ text, className }: {
3
+ text?: string;
4
+ className?: string;
5
+ }): import("react").JSX.Element;
@@ -0,0 +1,11 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // What an empty value reads as on a record (form standard 22.2, #F17): a
3
+ // dash in the muted text tone, everywhere, with "Not set" as what a screen
4
+ // reader says for it. Words given instead ("No budget yet") read as they
5
+ // are. EntityView, its strip (KeyStats) and the inPlace presets' fields all
6
+ // show it.
7
+ import { EMPTY_DASH } from '../../lib/empty-value.js';
8
+ /** The empty text in the muted tone; the dash is read as "Not set". */
9
+ export function EmptyText({ text = EMPTY_DASH, className }) {
10
+ return (_jsx("span", { "data-slot": "empty-value", className: className ?? 'text-muted-foreground', children: text === EMPTY_DASH ? (_jsxs(_Fragment, { children: [_jsx("span", { "aria-hidden": "true", children: EMPTY_DASH }), _jsx("span", { className: "sr-only", children: "Not set" })] })) : (text) }));
11
+ }
@@ -16,8 +16,10 @@ export type EntityViewPrintSection = {
16
16
  * The copy mounts, then the browser's print dialog opens on it; it goes
17
17
  * when the dialog closes (`afterprint`).
18
18
  */
19
- export declare function PrintNotes({ label, title, subtitle, sections, }: {
19
+ export declare function PrintNotes({ label, look, title, subtitle, sections, }: {
20
20
  label: string;
21
+ /** An icon with `label` as its tooltip and name (the default), or a button with its words. */
22
+ look?: 'icon' | 'words';
21
23
  title?: string;
22
24
  subtitle?: ReactNode;
23
25
  sections: EntityViewPrintSection[];
@@ -19,6 +19,7 @@ import { useEffect, useState } from 'react';
19
19
  import { createPortal } from 'react-dom';
20
20
  import { PrinterIcon } from 'lucide-react';
21
21
  import { Button } from '../ui/button.js';
22
+ import { IconAction } from './icon-action.js';
22
23
  import { PrintingContext } from './print-context.js';
23
24
  function isEmpty(value) {
24
25
  return value === null || value === undefined || value === false || value === '' || (Array.isArray(value) && value.length === 0);
@@ -34,7 +35,7 @@ function PrintedNotes({ title, subtitle, sections }) {
34
35
  * The copy mounts, then the browser's print dialog opens on it; it goes
35
36
  * when the dialog closes (`afterprint`).
36
37
  */
37
- export function PrintNotes({ label, title, subtitle, sections, }) {
38
+ export function PrintNotes({ label, look = 'icon', title, subtitle, sections, }) {
38
39
  // How many times it's been pressed since the copy last went: a press
39
40
  // while one is up (a browser that never said the dialog closed) prints
40
41
  // it again rather than doing nothing.
@@ -47,5 +48,5 @@ export function PrintNotes({ label, title, subtitle, sections, }) {
47
48
  window.print();
48
49
  return () => window.removeEventListener('afterprint', done);
49
50
  }, [printing]);
50
- return (_jsxs(_Fragment, { children: [_jsxs(Button, { variant: "outline", onClick: () => setPrinting((count) => count + 1), children: [_jsx(PrinterIcon, {}), label] }), printing > 0 && _jsx(PrintedNotes, { title: title, subtitle: subtitle, sections: sections })] }));
51
+ return (_jsxs(_Fragment, { children: [look === 'icon' ? (_jsx(IconAction, { icon: PrinterIcon, label: label, onClick: () => setPrinting((count) => count + 1) })) : (_jsxs(Button, { variant: "outline", onClick: () => setPrinting((count) => count + 1), children: [_jsx(PrinterIcon, {}), label] })), printing > 0 && _jsx(PrintedNotes, { title: title, subtitle: subtitle, sections: sections })] }));
51
52
  }
@@ -9,7 +9,7 @@ export type EntityViewField = {
9
9
  * so `{tags.map(...)}` or `{email}` can be passed as they are.
10
10
  */
11
11
  value?: ReactNode;
12
- /** What an empty value reads as: the plan's "not set" label. Defaults to "Not set". */
12
+ /** What an empty value reads as, for this field. Defaults to the view's `emptyText` (a dash). */
13
13
  emptyLabel?: string;
14
14
  /**
15
15
  * Editable in place: `editInPlace({...})`, or a ready-made `inPlace`
@@ -86,6 +86,12 @@ export type EntityViewMobileOrder = 'rail-first' | 'main-first';
86
86
  * where the rail's list is narrower than 18rem (a small phone).
87
87
  */
88
88
  export type EntityViewRailFields = 'stacked' | 'beside';
89
+ /**
90
+ * What a fields card does with its empty fields: `show` (the default),
91
+ * each with the empty text; `fold`, the filled ones first and an
92
+ * "N empty" toggle that opens the rest, still edited in place.
93
+ */
94
+ export type EntityViewEmptyFields = 'show' | 'fold';
89
95
  export type EntityViewProps = {
90
96
  /** The record's name or title, the page's <h1>, and the browser tab's once it loads (`documentTitle`). */
91
97
  title?: string;
@@ -115,12 +121,17 @@ export type EntityViewProps = {
115
121
  */
116
122
  subtitle?: ReactNode;
117
123
  /**
118
- * A few status-like values beside the title, as `<Badge>`s, or as the
119
- * control that changes one when the plan makes it a quick action (a
120
- * status `Select`, a yes/no `Switch`).
124
+ * A few status-like values on the title's line, after it, as `<Badge>`s,
125
+ * or as the control that changes one when the plan makes it a quick
126
+ * action (a status `Select`, a yes/no `Switch`). A title too long for
127
+ * them on its line pushes them to the next; `subtitle` stays below.
121
128
  */
122
129
  badges?: ReactNode;
123
- /** The header's actions: an Edit button, a Delete with its confirm dialog. */
130
+ /**
131
+ * The header's actions: the record's own commands in words (New visit,
132
+ * Mark done), then the universal ones as an `<IconAction>` (Delete, with
133
+ * its confirm dialog, `tone="destructive"`). They follow Print notes.
134
+ */
124
135
  actions?: ReactNode;
125
136
  /**
126
137
  * A state that decides what you do with the record, said before
@@ -152,18 +163,38 @@ export type EntityViewProps = {
152
163
  * ignores it.
153
164
  */
154
165
  mobileOrder?: EntityViewMobileOrder;
155
- /** The Print notes button's words, when a section is marked `print`. Defaults to "Print notes". */
166
+ /**
167
+ * The Print notes action's words, when a section is marked `print`: its
168
+ * tooltip and accessible name as an icon, its text as `words`. Defaults
169
+ * to "Print notes".
170
+ */
156
171
  printLabel?: string;
172
+ /** Print notes as an icon (`icon`, the default since 4.81) or a button with its words (`words`). */
173
+ printLook?: 'icon' | 'words';
157
174
  /** The rail's landmark name (its `<aside>`). Defaults to the title + " details". */
158
175
  railLabel?: string;
159
176
  /**
160
- * In the `rail` layout, a rail section's fields: each label above its
161
- * value (`stacked`, the default), or to its left (`beside`), falling back
162
- * to stacked where the rail is too narrow for both. Once the rail's
163
- * sections stack full width on a narrower screen, labels sit beside
164
- * values either way.
177
+ * In the `rail` layout, a rail section's fields: each label to the left
178
+ * of its value (`beside`, the default since 4.81), falling back to
179
+ * stacked where the rail is too narrow for both, or above it
180
+ * (`stacked`). Once the rail's sections stack full width on a narrower
181
+ * screen, labels sit beside values either way.
165
182
  */
166
183
  railFields?: EntityViewRailFields;
184
+ /**
185
+ * Empty fields in a fields card (the rail's and the main column's):
186
+ * shown with the empty text (`show`, the default), or folded (`fold`):
187
+ * the card lists its filled fields, then "N empty" opens the rest in
188
+ * their places, each still edited in place. A value set elsewhere moves
189
+ * its field into the card.
190
+ */
191
+ emptyFields?: EntityViewEmptyFields;
192
+ /**
193
+ * What an empty value reads as across the view (a field's or a block's
194
+ * own `emptyLabel` wins): a dash by default, in the muted tone, read
195
+ * by a screen reader as "Not set".
196
+ */
197
+ emptyText?: string;
167
198
  isLoading: boolean;
168
199
  /** A `notfound` error (including another user's record) shows "Not found" and a way back, never a retry. */
169
200
  error?: AppError | null;
@@ -174,4 +205,4 @@ export type EntityViewProps = {
174
205
  label: string;
175
206
  };
176
207
  };
177
- export declare function EntityView({ title, documentTitle, titleEdit, leading, subtitle, badges, actions, notice, strip, sections, footer, layout, mobileOrder, railLabel, railFields, printLabel, isLoading, error, onRetry, back, }: EntityViewProps): import("react").JSX.Element;
208
+ export declare function EntityView({ title, documentTitle, titleEdit, leading, subtitle, badges, actions, notice, strip, sections, footer, layout, mobileOrder, railLabel, railFields, emptyFields, emptyText, printLabel, printLook, isLoading, error, onRetry, back, }: EntityViewProps): import("react").JSX.Element;
@@ -67,13 +67,19 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
67
67
  // switch. With no `tab` on any section, nothing changes.
68
68
  //
69
69
  // `leading`, left of the title: the record's mark or avatar, with the
70
- // title, subtitle and badges beside it at every width. `railFields`
71
- // `beside` puts a rail field's label to the left of its value, as in an
72
- // issue tracker's sidebar, stacked again where the rail's list is too
73
- // narrow for both.
74
- import { useEffect, useId, useState, useSyncExternalStore } from 'react';
70
+ // title, subtitle and badges beside it at every width. A rail field's
71
+ // label sits to the left of its value (`railFields`, `beside` by default
72
+ // since 4.81), as in an issue tracker's sidebar, stacked again where the
73
+ // rail's list is too narrow for both.
74
+ //
75
+ // The record page standard (4.81): `badges` sit on the title's line,
76
+ // wrapping under a long title; Print notes is an icon (`IconAction`, its
77
+ // words the tooltip and name); an empty value reads as a dash
78
+ // (`emptyText`), and `emptyFields="fold"` folds each fields card's empty
79
+ // ones behind an "N empty" toggle, still edited in place once opened.
80
+ import { createContext, useContext, useEffect, useId, useState, useSyncExternalStore } from 'react';
75
81
  import { Link, useLocation, useNavigate } from 'react-router';
76
- import { ArrowLeftIcon, SearchXIcon } from 'lucide-react';
82
+ import { ArrowLeftIcon, ChevronDownIcon, SearchXIcon } from 'lucide-react';
77
83
  import { cn } from 'cn';
78
84
  import { ErrorState } from './error-state.js';
79
85
  import { Button } from '../ui/button.js';
@@ -87,22 +93,22 @@ import { EditInPlaceContext } from './edit-in-place.js';
87
93
  import { EditInPlaceStore } from './edit-in-place-store.js';
88
94
  import { EditableList } from './editable-list.js';
89
95
  import { EditableValue, LeaveGuard } from './editable-value.js';
96
+ import { EmptyText } from './empty-value.js';
97
+ import { EMPTY_DASH, isEmptyValue } from '../../lib/empty-value.js';
90
98
  import { useRecordDialog } from './record-dialog-context.js';
91
99
  import { entityViewTabSlug } from '../../lib/entity-view-tab.js';
92
- const DEFAULT_EMPTY_LABEL = 'Not set';
93
- function isEmptyValue(value) {
94
- return (value === null ||
95
- value === undefined ||
96
- value === false ||
97
- value === '' ||
98
- (Array.isArray(value) && value.length === 0));
99
- }
100
+ // The view's empty text and whether fields cards fold their empty ones,
101
+ // for every section without threading them through each layout.
102
+ const EmptyContext = createContext({ text: EMPTY_DASH, fold: false });
100
103
  function BackLink({ back }) {
101
104
  return (_jsxs(Link, { to: back.to, className: "inline-flex w-fit items-center gap-1 rounded-sm type-label text-muted-foreground outline-none hover:text-foreground focus-visible:ring-3 focus-visible:ring-ring/50", children: [_jsx(ArrowLeftIcon, { "aria-hidden": "true", className: "size-4" }), back.label] }));
102
105
  }
103
- function orEmptyLabel(value, emptyLabel) {
104
- return isEmptyValue(value) ? (_jsx("span", { className: "text-muted-foreground", children: emptyLabel ?? DEFAULT_EMPTY_LABEL })) : (value);
106
+ function OrEmpty({ value, emptyLabel }) {
107
+ const empty = useContext(EmptyContext);
108
+ return isEmptyValue(value) ? _jsx(EmptyText, { text: emptyLabel ?? empty.text }) : value;
105
109
  }
110
+ // A preset shows its own value unless the screen gives one.
111
+ const fieldValue = (field) => (field.value !== undefined ? field.value : field.edit?.shown);
106
112
  // Label beside value from `sm` up; below it (a phone) the label sits
107
113
  // above its value, so nothing is squeezed into a narrow second column. In
108
114
  // the rail the list's own width decides instead (a container query on the
@@ -117,13 +123,26 @@ const FIELD_ROW = {
117
123
  railBeside: '@2xs/fields:grid @2xs/fields:grid-cols-[minmax(--spacing(24),--spacing(28))_minmax(0,1fr)] @2xs/fields:items-baseline @2xs/fields:gap-4 @2xs/fields:py-2.5 @lg/fields:grid-cols-[minmax(--spacing(32),--spacing(48))_1fr] @lg/fields:gap-6',
118
124
  };
119
125
  function FieldRow({ field, place }) {
120
- // A preset shows its own value unless the screen gives one.
121
- const value = field.value !== undefined ? field.value : field.edit?.shown;
122
- return (_jsxs("div", { className: cn('flex flex-col gap-1 py-3 first:pt-0 last:pb-0', FIELD_ROW[place]), children: [_jsx("dt", { className: "type-label text-muted-foreground", children: field.label }), _jsx("dd", { className: "min-w-0 type-body break-words text-foreground", children: field.edit ? (_jsx(EditableValue, { label: field.label, edit: field.edit, children: orEmptyLabel(value, field.emptyLabel) })) : (orEmptyLabel(value, field.emptyLabel)) })] }));
126
+ const value = fieldValue(field);
127
+ return (_jsxs("div", { className: cn('flex flex-col gap-1 py-3 first:pt-0 last:pb-0', FIELD_ROW[place]), children: [_jsx("dt", { className: "type-label text-muted-foreground", children: field.label }), _jsx("dd", { className: "min-w-0 type-body break-words text-foreground", children: field.edit ? (_jsx(EditableValue, { label: field.label, edit: field.edit, children: _jsx(OrEmpty, { value: value, emptyLabel: field.emptyLabel }) })) : (_jsx(OrEmpty, { value: value, emptyLabel: field.emptyLabel })) })] }));
128
+ }
129
+ // A fields card's rows. Folded (`emptyFields="fold"`), the filled fields
130
+ // show and the empty ones wait behind "N empty", which opens them in their
131
+ // places (the card's order kept) and then reads "Hide empty". Whether a
132
+ // field is empty is read on every render, so one filled elsewhere joins
133
+ // the card at once.
134
+ function FieldList({ fields, inRail, place }) {
135
+ const empty = useContext(EmptyContext);
136
+ const [open, setOpen] = useState(false);
137
+ const listId = useId();
138
+ const emptyCount = empty.fold ? fields.filter((field) => isEmptyValue(fieldValue(field))).length : 0;
139
+ const shown = emptyCount === 0 || open ? fields : fields.filter((field) => !isEmptyValue(fieldValue(field)));
140
+ return (_jsxs("div", { className: "flex flex-col gap-3", children: [shown.length > 0 && (_jsx("dl", { id: listId, className: cn('flex flex-col divide-y divide-border', inRail && '@container/fields'), children: shown.map((field) => (_jsx(FieldRow, { field: field, place: place }, field.label))) })), emptyCount > 0 && (_jsxs("button", { type: "button", "data-slot": "entity-view-empty-toggle", "aria-expanded": open, "aria-controls": shown.length > 0 ? listId : undefined, onClick: () => setOpen((was) => !was), className: "inline-flex w-fit items-center gap-1 rounded-sm type-label text-muted-foreground underline underline-offset-3 outline-none hover:text-foreground focus-visible:ring-3 focus-visible:ring-ring/50 pointer-coarse:min-h-11", children: [open ? 'Hide empty' : `${emptyCount} empty`, _jsx(ChevronDownIcon, { "aria-hidden": "true", className: cn('size-3.5 transition-transform', open && 'rotate-180') })] }))] }));
123
141
  }
124
- function ViewSection({ section, inRail = false, railFields = 'stacked', }) {
142
+ function ViewSection({ section, inRail = false, railFields = 'beside', }) {
125
143
  const headingId = useId();
126
- return (_jsx("section", { "aria-labelledby": headingId, children: _jsxs(Card, { children: [_jsx(CardHeader, { children: _jsx("h2", { id: headingId, className: "type-section-title text-foreground", children: section.title }) }), _jsx(CardContent, { children: 'fields' in section ? (_jsx("dl", { className: cn('flex flex-col divide-y divide-border', inRail && '@container/fields'), children: section.fields.map((field) => (_jsx(FieldRow, { field: field, place: !inRail ? 'page' : railFields === 'beside' ? 'railBeside' : 'rail' }, field.label))) })) : section.edit?.kind === 'list' ? (_jsxs("div", { className: "flex min-w-0 flex-col gap-2 type-body break-words text-foreground", children: [!isEmptyValue(section.content) && section.content, _jsx(EditableList, { label: section.title, edit: section.edit, emptyLabel: section.emptyLabel ?? DEFAULT_EMPTY_LABEL })] })) : (_jsx("div", { className: "min-w-0 type-body break-words text-foreground", children: section.edit ? (_jsx(EditableValue, { label: section.title, edit: section.edit, children: orEmptyLabel(section.content, section.emptyLabel) })) : (orEmptyLabel(section.content, section.emptyLabel)) })) })] }) }));
144
+ const empty = useContext(EmptyContext);
145
+ return (_jsx("section", { "aria-labelledby": headingId, children: _jsxs(Card, { children: [_jsx(CardHeader, { children: _jsx("h2", { id: headingId, className: "type-section-title text-foreground", children: section.title }) }), _jsx(CardContent, { children: 'fields' in section ? (_jsx(FieldList, { fields: section.fields, inRail: inRail, place: !inRail ? 'page' : railFields === 'beside' ? 'railBeside' : 'rail' })) : section.edit?.kind === 'list' ? (_jsxs("div", { className: "flex min-w-0 flex-col gap-2 type-body break-words text-foreground", children: [!isEmptyValue(section.content) && section.content, _jsx(EditableList, { label: section.title, edit: section.edit, emptyLabel: section.emptyLabel ?? empty.text })] })) : (_jsx("div", { className: "min-w-0 type-body break-words text-foreground", children: section.edit ? (_jsx(EditableValue, { label: section.title, edit: section.edit, children: _jsx(OrEmpty, { value: section.content, emptyLabel: section.emptyLabel }) })) : (_jsx(OrEmpty, { value: section.content, emptyLabel: section.emptyLabel })) })) })] }) }));
127
146
  }
128
147
  // The rail layout's columns. The view is a container, so the switch to
129
148
  // two columns follows the width the page actually has (the sidebar open
@@ -220,7 +239,7 @@ function MainTabs({ tabs, label }) {
220
239
  };
221
240
  return (_jsxs(Tabs, { value: selected, onValueChange: (value) => select(String(value)), "data-slot": "entity-view-tabs", className: "min-w-0 gap-6", children: [_jsx(TabsList, { variant: "line", activateOnFocus: true, "aria-label": label, className: "h-auto w-full max-w-full justify-start gap-1 overflow-x-auto overflow-y-hidden border-b border-border p-0 [scrollbar-width:thin]", children: tabs.map((tab) => (_jsx(TabsTrigger, { value: tab.slug, className: "h-9 flex-none px-3 text-muted-foreground group-data-horizontal/tabs:after:bottom-0 pointer-coarse:h-11 dark:text-muted-foreground", children: tab.name }, tab.slug))) }), tabs.map((tab) => (_jsx(TabsContent, { value: tab.slug, keepMounted: true, className: "flex min-w-0 flex-col gap-6 [font-size:inherit]", children: tab.sections.map((section) => (_jsx(ViewSection, { section: section }, section.title))) }, tab.slug)))] }));
222
241
  }
223
- export function EntityView({ title, documentTitle, titleEdit, leading, subtitle, badges, actions, notice, strip, sections, footer, layout = 'column', mobileOrder = 'rail-first', railLabel, railFields = 'stacked', printLabel = 'Print notes', isLoading, error, onRetry, back, }) {
242
+ export function EntityView({ title, documentTitle, titleEdit, leading, subtitle, badges, actions, notice, strip, sections, footer, layout = 'column', mobileOrder = 'rail-first', railLabel, railFields = 'beside', emptyFields = 'show', emptyText = EMPTY_DASH, printLabel = 'Print notes', printLook = 'icon', isLoading, error, onRetry, back, }) {
224
243
  // Editing in place: one store per view, and the leave-page prompt only
225
244
  // while a field is open (or one is always editable).
226
245
  const [store] = useState(() => new EditInPlaceStore());
@@ -252,7 +271,7 @@ export function EntityView({ title, documentTitle, titleEdit, leading, subtitle,
252
271
  : { content: section.content, emptyLabel: section.emptyLabel }),
253
272
  answerSpace: typeof section.print === 'object' && section.print.answerSpace === true,
254
273
  }));
255
- const printButton = printSections.length > 0 && (_jsx(PrintNotes, { label: printLabel, title: title, subtitle: subtitle, sections: printSections }));
274
+ const printButton = printSections.length > 0 && (_jsx(PrintNotes, { label: printLabel, look: printLook, title: title, subtitle: subtitle, sections: printSections }));
256
275
  const railSections = sections.filter((section) => section.placement === 'rail');
257
276
  const mainSections = sections.filter((section) => section.placement !== 'rail');
258
277
  // Tabs: a main section's `tab` (a rail one's is ignored, in either layout).
@@ -262,7 +281,7 @@ export function EntityView({ title, documentTitle, titleEdit, leading, subtitle,
262
281
  const main = (_jsxs("div", { className: cn(RAIL_LAYOUT.main, railSections.length === 0 && RAIL_LAYOUT.mainAlone), children: [mainSections
263
282
  .filter((section) => !tabbed(section))
264
283
  .map((section) => (_jsx(ViewSection, { section: section }, section.title))), tabList] }));
265
- return (_jsx(EditInPlaceContext.Provider, { value: store, children: _jsxs("div", { className: layout === 'rail' ? RAIL_LAYOUT.page : 'flex max-w-4xl flex-col gap-6', "data-state": "success", "data-layout": layout, children: [editing && _jsx(LeaveGuard, { store: store }), !dialog && _jsx(BackLink, { back: back }), _jsxs("header", { className: "flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between", children: [_jsxs("div", { className: "flex min-w-0 flex-1 items-start gap-3 sm:min-w-64 sm:gap-4", children: [leading && (_jsx("div", { "data-slot": "entity-view-leading", className: "flex shrink-0 items-center", children: leading })), _jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-2", children: [_jsx("h1", { id: dialog?.titleId, className: "type-page-title break-words text-foreground", children: titleEdit ? (_jsx(EditableValue, { label: titleEdit.label, edit: titleEdit, layout: "inline", className: "w-full", children: title })) : (title) }), subtitle && (_jsx("div", { "data-slot": "entity-view-subtitle", className: "type-body break-words text-muted-foreground", children: subtitle })), badges && _jsx("div", { className: "flex flex-wrap items-center gap-1.5", children: badges })] })] }), (actions || printButton) && (_jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-2 sm:justify-end", children: [printButton, actions] }))] }), _jsx("div", { role: "status", "data-slot": "entity-view-notice", className: "empty:hidden", children: notice }), strip && _jsx("div", { "data-slot": "entity-view-strip", children: strip }), layout === 'rail' ? (_jsxs("div", { className: RAIL_LAYOUT.columns, children: [mobileOrder === 'main-first' && main, railSections.length > 0 && (_jsx(Rail, { label: railLabel ?? `${title ?? 'Record'} details`, sections: railSections, fields: railFields })), mobileOrder === 'rail-first' && main] })) : (_jsxs(_Fragment, { children: [sections
266
- .filter((section) => !tabbed(section))
267
- .map((section) => (_jsx(ViewSection, { section: section }, section.title))), tabList] })), footer && (_jsx("footer", { "data-slot": "entity-view-footer", className: "type-caption text-muted-foreground", children: footer }))] }) }));
284
+ return (_jsx(EditInPlaceContext.Provider, { value: store, children: _jsx(EmptyContext.Provider, { value: { text: emptyText, fold: emptyFields === 'fold' }, children: _jsxs("div", { className: layout === 'rail' ? RAIL_LAYOUT.page : 'flex max-w-4xl flex-col gap-6', "data-state": "success", "data-layout": layout, children: [editing && _jsx(LeaveGuard, { store: store }), !dialog && _jsx(BackLink, { back: back }), _jsxs("header", { className: "flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between", children: [_jsxs("div", { className: "flex min-w-0 flex-1 items-start gap-3 sm:min-w-64 sm:gap-4", children: [leading && (_jsx("div", { "data-slot": "entity-view-leading", className: "flex shrink-0 items-center", children: leading })), _jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-2", children: [_jsxs("div", { "data-slot": "entity-view-title-line", className: "flex min-w-0 flex-wrap items-center gap-x-3 gap-y-2", children: [_jsx("h1", { id: dialog?.titleId, className: "min-w-0 max-w-full type-page-title break-words text-foreground", children: titleEdit ? (_jsx(EditableValue, { label: titleEdit.label, edit: titleEdit, layout: "inline", className: "w-full", children: title })) : (title) }), badges && (_jsx("div", { "data-slot": "entity-view-badges", className: "flex flex-wrap items-center gap-1.5", children: badges }))] }), subtitle && (_jsx("div", { "data-slot": "entity-view-subtitle", className: "type-body break-words text-muted-foreground", children: subtitle }))] })] }), (actions || printButton) && (_jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-2 sm:justify-end", children: [printButton, actions] }))] }), _jsx("div", { role: "status", "data-slot": "entity-view-notice", className: "empty:hidden", children: notice }), strip && _jsx("div", { "data-slot": "entity-view-strip", children: strip }), layout === 'rail' ? (_jsxs("div", { className: RAIL_LAYOUT.columns, children: [mobileOrder === 'main-first' && main, railSections.length > 0 && (_jsx(Rail, { label: railLabel ?? `${title ?? 'Record'} details`, sections: railSections, fields: railFields })), mobileOrder === 'rail-first' && main] })) : (_jsxs(_Fragment, { children: [sections
285
+ .filter((section) => !tabbed(section))
286
+ .map((section) => (_jsx(ViewSection, { section: section }, section.title))), tabList] })), footer && (_jsx("footer", { "data-slot": "entity-view-footer", className: "type-caption text-muted-foreground", children: footer }))] }) }) }));
268
287
  }
@@ -0,0 +1,14 @@
1
+ import type { ComponentProps } from 'react';
2
+ import { Button } from '../ui/button.js';
3
+ import type { IconComponent } from './icon-component.js';
4
+ export type IconActionProps = Omit<ComponentProps<typeof Button>, 'children' | 'size' | 'aria-label'> & {
5
+ /** The action's icon, from the app's icon vocabulary (Lucide `Trash2Icon` for Delete). */
6
+ icon: IconComponent;
7
+ /** What the action does ("Delete", "Print notes"): its tooltip and accessible name. */
8
+ label: string;
9
+ /** `destructive` draws the icon in the destructive tone (Delete). Defaults to `default`. */
10
+ tone?: 'default' | 'destructive';
11
+ /** The button's size: `default` (36px, beside the header's other buttons) or `sm` (32px). */
12
+ size?: 'default' | 'sm';
13
+ };
14
+ export declare function IconAction({ icon: Icon, label, tone, size, variant, className, ...props }: IconActionProps): import("react").JSX.Element;
@@ -0,0 +1,7 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { cn } from 'cn';
3
+ import { Button } from '../ui/button.js';
4
+ import { Tooltip, TooltipContent, TooltipTrigger } from '../ui/tooltip.js';
5
+ export function IconAction({ icon: Icon, label, tone = 'default', size = 'default', variant = 'outline', className, ...props }) {
6
+ return (_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { render: _jsx(Button, { ...props, "data-slot": "icon-action", variant: variant, size: size === 'sm' ? 'icon-sm' : 'icon', "aria-label": label, className: className }), children: _jsx(Icon, { "aria-hidden": "true", className: cn('size-4', tone === 'destructive' && 'text-destructive-text') }) }), _jsx(TooltipContent, { children: label })] }));
7
+ }
@@ -1,13 +1,16 @@
1
1
  import type { ReactNode } from 'react';
2
+ import type { IconComponent } from './icon-component.js';
2
3
  export type KeyStat = {
3
4
  label: string;
4
5
  value: ReactNode;
5
6
  /** A few words under the value ("of 12", "since May"), in caption type. */
6
7
  hint?: ReactNode;
8
+ /** The concept's icon, drawn at 13px before the label (decorative: the label still says it). */
9
+ icon?: IconComponent;
7
10
  };
8
11
  export type KeyStatsProps = {
9
12
  stats: readonly KeyStat[];
10
- /** What an empty value reads as. Defaults to "Not set". */
13
+ /** What an empty value reads as. Defaults to a dash, read as "Not set". */
11
14
  emptyLabel?: string;
12
15
  className?: string;
13
16
  };
@@ -1,6 +1,11 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { cn } from 'cn';
3
+ import { EmptyText } from './empty-value.js';
4
+ import { EMPTY_DASH } from '../../lib/empty-value.js';
3
5
  const isEmpty = (value) => value === null || value === undefined || value === false || value === '';
4
- export function KeyStats({ stats, emptyLabel = 'Not set', className }) {
5
- return (_jsx("dl", { "data-slot": "key-stats", className: cn('flex flex-wrap gap-x-8 gap-y-3 rounded-lg border border-border bg-card px-4 py-3 text-card-foreground', className), children: stats.map((stat) => (_jsxs("div", { className: "flex min-w-0 flex-col gap-0.5", children: [_jsx("dt", { className: "type-caption text-muted-foreground", children: stat.label }), _jsx("dd", { className: "type-section-title tabular-nums break-words text-foreground", children: isEmpty(stat.value) ? _jsx("span", { className: "type-body text-muted-foreground", children: emptyLabel }) : stat.value }), stat.hint && _jsx("dd", { className: "type-caption text-muted-foreground", children: stat.hint })] }, stat.label))) }));
6
+ export function KeyStats({ stats, emptyLabel = EMPTY_DASH, className }) {
7
+ return (_jsx("dl", { "data-slot": "key-stats", className: cn('flex flex-wrap gap-x-8 gap-y-3 rounded-lg border border-border bg-card px-4 py-3 text-card-foreground', className), children: stats.map((stat) => {
8
+ const Icon = stat.icon;
9
+ return (_jsxs("div", { className: "flex min-w-0 flex-col gap-0.5", children: [_jsxs("dt", { className: cn('type-caption text-muted-foreground', Icon && 'inline-flex items-center gap-1'), children: [Icon && _jsx(Icon, { "aria-hidden": "true", className: "size-3.25 shrink-0" }), stat.label] }), _jsx("dd", { className: "type-section-title tabular-nums break-words text-foreground", children: isEmpty(stat.value) ? _jsx(EmptyText, { text: emptyLabel, className: "type-body text-muted-foreground" }) : stat.value }), stat.hint && _jsx("dd", { className: "type-caption text-muted-foreground", children: stat.hint })] }, stat.label));
10
+ }) }));
6
11
  }
package/dist/index.d.ts CHANGED
@@ -14,7 +14,8 @@ export { type RowGroup } from './components/app/table-groups.js';
14
14
  export { byDay, type ByDayOptions } from './lib/group-by-day.js';
15
15
  export { EntityForm, type EntityFormProps } from './components/app/entity-form.js';
16
16
  export { KeyStats, type KeyStat, type KeyStatsProps } from './components/app/key-stats.js';
17
- export { EntityView, type EntityViewField, type EntityViewLayout, type EntityViewMobileOrder, type EntityViewPlacement, type EntityViewProps, type EntityViewRailFields, type EntityViewSection, } from './components/app/entity-view.js';
17
+ export { IconAction, type IconActionProps } from './components/app/icon-action.js';
18
+ export { EntityView, type EntityViewEmptyFields, type EntityViewField, type EntityViewLayout, type EntityViewMobileOrder, type EntityViewPlacement, type EntityViewProps, type EntityViewRailFields, type EntityViewSection, } from './components/app/entity-view.js';
18
19
  export { entityViewTabSlug } from './lib/entity-view-tab.js';
19
20
  export { usePrinting } from './components/app/print-context.js';
20
21
  export { RecordDialogRoute, RecordLink, type RecordDialogRouteProps, type RecordLinkProps, } from './components/app/record-dialog.js';
package/dist/index.js CHANGED
@@ -18,6 +18,7 @@ export {} from './components/app/table-groups.js';
18
18
  export { byDay } from './lib/group-by-day.js';
19
19
  export { EntityForm } from './components/app/entity-form.js';
20
20
  export { KeyStats } from './components/app/key-stats.js';
21
+ export { IconAction } from './components/app/icon-action.js';
21
22
  export { EntityView, } from './components/app/entity-view.js';
22
23
  export { entityViewTabSlug } from './lib/entity-view-tab.js';
23
24
  export { usePrinting } from './components/app/print-context.js';
@@ -0,0 +1,8 @@
1
+ import type { ReactNode } from 'react';
2
+ /** The default empty text: an em dash, spoken as "Not set". */
3
+ export declare const EMPTY_DASH = "\u2014";
4
+ /**
5
+ * Whether a value counts as empty: `null`, `undefined`, `false`, `''` and
6
+ * an empty array, so `{tags.map(...)}` or `{email}` can be passed as is.
7
+ */
8
+ export declare function isEmptyValue(value: ReactNode): boolean;
@@ -0,0 +1,13 @@
1
+ /** The default empty text: an em dash, spoken as "Not set". */
2
+ export const EMPTY_DASH = '—';
3
+ /**
4
+ * Whether a value counts as empty: `null`, `undefined`, `false`, `''` and
5
+ * an empty array, so `{tags.map(...)}` or `{email}` can be passed as is.
6
+ */
7
+ export function isEmptyValue(value) {
8
+ return (value === null ||
9
+ value === undefined ||
10
+ value === false ||
11
+ value === '' ||
12
+ (Array.isArray(value) && value.length === 0));
13
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tristan2828/ui-foundation",
3
- "version": "4.79.0",
3
+ "version": "4.81.0",
4
4
  "description": "Shared UI foundation for contract-first, database-backed React apps: shadcn primitives, DataTable/EntityForm composites, auth, the gateway error seam, design tokens, lint rules and the AI playbook.",
5
5
  "license": "MIT",
6
6
  "repository": {