@tristan2828/ui-foundation 4.89.0 → 4.91.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`, `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 the page standards (`docs/foundation/design-language.md` "Parts of the page standards"): `ValueList`, `ListHeader`, `Timeline`, `NeedsYou`, `Freshness`, `PartEmpty`. For a module's overview ("An overview page" there): `OverviewPage`, and `WidgetCard`'s `to`, `value`, `line` and `freshness`. For a list's tools (`docs/foundation/cell-patterns.md` 25 and 26): `FilterBar`, `FilterSelect`, `RelatedTable`, and DataTable's `views`, `columnsMenu`, `rowActions`, `phoneRow`, `limit` and `viewAll`. 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`, and for a new record over it `useNewRecordDialog`. A small form in a dialog: `FormDialog`. For the trail and search in `AppShell`'s bar (`docs/foundation/design-language.md` "The sidebar and the phone's bar"): `usePageTrail`, `useRecentRecord`, `PageTrail`; types `AppShellSearch`, `SearchRecord`, `RecentRecord`. For the form standard (`docs/foundation/add-an-entity.md` "Forms"): `FormSection`, `OptionSelect`, `ChoiceButtons`, `ReferenceCombobox`, `countFormErrors`, `fieldRows`, `parsePlainDate`, and for a record's rows edited in place `editRowClass`, `onEditRowClick` and `inPlace.choice`; from `/ui/field`, `Field` takes `size`, `solo` and `kind`, and `FieldLabel` takes `required`. From `/ui/dialog`, `DialogContent` takes `size` and `dirty`, and `DiscardChangesDialog` is the "Discard your changes?" prompt |
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 the page standards (`docs/foundation/design-language.md` "Parts of the page standards"): `ValueList`, `ListHeader`, `Timeline`, `NeedsYou`, `Freshness`, `PartEmpty`. For a module's overview ("An overview page" there): `OverviewPage`, and `WidgetCard`'s `to`, `value`, `line` and `freshness`. For a list's tools (`docs/foundation/cell-patterns.md` 25 and 26): `FilterBar`, `FilterSelect`, `RelatedTable`, and DataTable's `views`, `columnsMenu`, `rowActions`, `phoneRow`, `limit` and `viewAll`. 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`, and for a new record over it `useNewRecordDialog`. A small form in a dialog: `FormDialog`. For the dialogs and feedback standard (`docs/foundation/add-an-entity.md` "Toasts and feedback"): `DeleteAction`, `notify`, `useAction`, `ActionError`, `JobStatus`, `OfflineNotice`, `useOffline`; from `/ui/skeleton`, `Skeleton` takes `delay`. For the trail and search in `AppShell`'s bar (`docs/foundation/design-language.md` "The sidebar and the phone's bar"): `usePageTrail`, `useRecentRecord`, `PageTrail`; types `AppShellSearch`, `SearchRecord`, `RecentRecord`. For the form standard (`docs/foundation/add-an-entity.md` "Forms"): `FormSection`, `OptionSelect`, `ChoiceButtons`, `ReferenceCombobox`, `countFormErrors`, `fieldRows`, `parsePlainDate`, and for a record's rows edited in place `editRowClass`, `onEditRowClick` and `inPlace.choice`; from `/ui/field`, `Field` takes `size`, `solo` and `kind`, and `FieldLabel` takes `required`. From `/ui/dialog`, `DialogContent` takes `size` and `dirty`, and `DiscardChangesDialog` is the "Discard your changes?" prompt |
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` |
@@ -3,28 +3,29 @@
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
- - [The reference files](#the-reference-files) · lines 43–65
7
- - [Before anything: the entity plan](#before-anything-the-entity-plan) · lines 67–830
8
- - Step 1: Add `<Entity>` to `openapi.yaml` · lines 109–116
9
- - Step 2: `npm run gen:api` · lines 117–118
10
- - Step 3: Add gateway tests in `tests/gateway/<entity>.test.ts`, derived from the spec · lines 119–130
11
- - Step 4: Add MSW handlers in `src/mocks/<entity>.ts` · lines 131–140
12
- - Step 5: Add a gateway module in `src/api/gateway/<entity>.ts` · lines 141–145
13
- - Step 6: Copy the reference files, one for one, not just the two screens · lines 146–717
14
- - Step 7: Register routes · lines 718–733
15
- - Step 8: Add Playwright specs for all three screens · lines 734–812
16
- - Step 9: Register the nav entry and route names · lines 813–827
17
- - Step 10: `npm run verify`. · lines 828–830
18
- - [How a list opens a record](#how-a-list-opens-a-record) · lines 832–1101
19
- - [The record view](#the-record-view) · lines 981–1020
20
- - [Forms](#forms) · lines 1022–1074
21
- - [Dialogs](#dialogs) · lines 1076–1101
22
- - [What not to copy](#what-not-to-copy) · lines 1103–1129
23
- - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 1131–1148
24
- - [Deleting](#deleting) · lines 1150–1179
25
- - [Fields only a script writes](#fields-only-a-script-writes) · lines 1181–1202
26
- - [Searching one part of the app](#searching-one-part-of-the-app) · lines 1204–1213
27
- - [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1216–1255
6
+ - [The reference files](#the-reference-files) · lines 44–66
7
+ - [Before anything: the entity plan](#before-anything-the-entity-plan) · lines 68–832
8
+ - Step 1: Add `<Entity>` to `openapi.yaml` · lines 110–117
9
+ - Step 2: `npm run gen:api` · lines 118–119
10
+ - Step 3: Add gateway tests in `tests/gateway/<entity>.test.ts`, derived from the spec · lines 120–131
11
+ - Step 4: Add MSW handlers in `src/mocks/<entity>.ts` · lines 132–141
12
+ - Step 5: Add a gateway module in `src/api/gateway/<entity>.ts` · lines 142–146
13
+ - Step 6: Copy the reference files, one for one, not just the two screens · lines 147–719
14
+ - Step 7: Register routes · lines 720–735
15
+ - Step 8: Add Playwright specs for all three screens · lines 736–814
16
+ - Step 9: Register the nav entry and route names · lines 815–829
17
+ - Step 10: `npm run verify`. · lines 830–832
18
+ - [How a list opens a record](#how-a-list-opens-a-record) · lines 834–1144
19
+ - [The record view](#the-record-view) · lines 983–1022
20
+ - [Forms](#forms) · lines 1024–1076
21
+ - [Dialogs](#dialogs) · lines 1078–1103
22
+ - [Toasts and feedback](#toasts-and-feedback) · lines 1105–1144
23
+ - [What not to copy](#what-not-to-copy) · lines 1146–1172
24
+ - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 1174–1191
25
+ - [Deleting](#deleting) · lines 1193–1224
26
+ - [Fields only a script writes](#fields-only-a-script-writes) · lines 1226–1247
27
+ - [Searching one part of the app](#searching-one-part-of-the-app) · lines 1249–1258
28
+ - [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1261–1300
28
29
 
29
30
  <!-- /index -->
30
31
 
@@ -406,8 +407,9 @@ is a filled-in example while the Widgets demo is still here).
406
407
  file.
407
408
  - `src/routes/widgets/delete-widget-action.tsx` →
408
409
  `src/routes/<entity>/delete-<entity>-action.tsx` (Delete in the
409
- view's header: the confirm dialog, then `onDeleted` leaves for the
410
- list; its own file, a fast-refresh hazard otherwise)
410
+ view's header: the foundation's `DeleteAction` with the entity's
411
+ delete and restore mutations, then `onDeleted` leaves for the list;
412
+ its own file, a fast-refresh hazard otherwise)
411
413
  - `src/routes/widgets/widget-form.tsx` →
412
414
  `src/routes/<entity>/<entity>-form.tsx` — thin consumer of the
413
415
  foundation's `<EntityForm>` (its `danger` slot takes an edit-only
@@ -1100,6 +1102,47 @@ Every dialog is one of three widths, `DialogContent`'s `size` (4.82):
1100
1102
  - **Always a dialog, never a side panel**, except a phone's filters
1101
1103
  (a bottom sheet of controls for the list behind it).
1102
1104
 
1105
+ ### Toasts and feedback
1106
+
1107
+ What the app says after something happens (the dialogs and feedback
1108
+ standard, 4.90). The rule: **a toast is for what happened out of
1109
+ sight.** What happened where the person is looking says so there.
1110
+
1111
+ | What happened | What says so |
1112
+ | --- | --- |
1113
+ | A delete (soft: with Undo) | `DeleteAction`'s toast, "Deleted The Long Walk" |
1114
+ | A record made, landing on its own page | a toast, "Added The Long Walk" |
1115
+ | An edit in place, a quick action, a toggle | the value itself and its "Saved" (cell pattern 18). **Never a toast** |
1116
+ | An action that failed, its button still there | `ActionError` beside the button: the reason and Try again |
1117
+ | An action that failed after its page was left | a toast that stays until it's closed (`useAction` does this) |
1118
+ | A job that takes a while | `JobStatus` beside its button: "Checking 3 of 12…", then the result stays |
1119
+ | A job that finished after its page was left | a toast (`useAction`'s `doneAway`) |
1120
+ | A list or record still loading | skeletons, after 300ms (`Skeleton`'s `delay`; `DataTable`'s are) |
1121
+ | The server can't be reached | `OfflineNotice` across the top (`AppShell` has it) |
1122
+
1123
+ - **One delete: `DeleteAction`.** `name`, `kind` (`soft` or `hard`),
1124
+ `onDelete`, and for a soft one `onRestore`. Its confirm asks "Delete
1125
+ <name>?" and says "It goes to Deleted, and Restore brings it back." or
1126
+ "This can't be undone."; the button is the filled destructive one; a
1127
+ failed delete keeps the dialog open with the reason. A row's delete is
1128
+ the same component (`size="sm"`), or `trigger={null}` with
1129
+ `open`/`onOpenChange`, opened by a `DataTable` `rowActions` entry's
1130
+ `onSelect` (a row's ⋯ menu). `verb="Retire"` for a retire.
1131
+ Never a delete without a confirm, never a hand-written dialog.
1132
+ - **A toast's words come from `notify.done(verb, name, { undo })`**: the
1133
+ verb first, "Deleted The Long Walk", "Added Paper Atlas"; Undo, when
1134
+ given, then says "Restored The Long Walk". Never "X deleted", never
1135
+ "Book deleted". Toasts last 4 seconds, Undo's too.
1136
+ - **An error stays beside what failed**: `const save = useAction(mutation)`,
1137
+ `save.run(…)` on the button (`disabled={save.pending}`, a `Spinner` in
1138
+ it), `<ActionError action={save} />` next to it. Never
1139
+ `toast.error` from a screen: `notify.failed` is the fallback
1140
+ `useAction` uses when the component is gone.
1141
+ - **Where a toast shows**: top centre on a laptop; at the bottom on a
1142
+ phone, above the shell's bottom bar and a form's stuck bar
1143
+ (`--toast-bottom-offset`). The shell's `Toaster` does this; never a
1144
+ `<Toaster>` of the app's own.
1145
+
1103
1146
  ## What not to copy
1104
1147
 
1105
1148
  - `widget-quick-actions.tsx`, its `quick action: …` specs and
@@ -1168,13 +1211,15 @@ soft one; copy it.
1168
1211
  - *Contract, gateway, mocks:* `restore<Entity>` in `openapi.yaml`, the
1169
1212
  gateway's `restore<Entity>`, a `useRestore<Entity>Mutation`, and mocks
1170
1213
  that move the record aside (`deletedWidgets` in `src/mocks/data.ts`).
1171
- - *Screens:* the delete dialog says it can be undone, and the success
1172
- toast carries an Undo that restores (`delete-widget-action.tsx`).
1214
+ - *Screens:* `DeleteAction kind="soft"`: the dialog says it can be
1215
+ undone, and the toast "Deleted <name>" carries an Undo that restores
1216
+ (`onRestore`; `delete-widget-action.tsx`).
1173
1217
  - *MCP:* give the entity's `McpEntity` `delete` and `restore` (and add
1174
1218
  `deleted` to its filters). Chats then get `delete(url)`, marked
1175
1219
  destructive so the chat asks before each call, and `restore(url)`.
1176
1220
  Both are logged with the whole record.
1177
- - **Hard-deleted:** `DELETE` removes the row. Give the entity no `delete`
1221
+ - **Hard-deleted:** `DELETE` removes the row. The screens use
1222
+ `DeleteAction kind="hard"`: "This can't be undone.", and no Undo. Give the entity no `delete`
1178
1223
  in `mcp_entities.py`: a chat that read planted instructions would
1179
1224
  destroy data that only a backup returns.
1180
1225
 
@@ -26,22 +26,22 @@
26
26
  - [A variant: a pressed icon inside another value's cell](#a-variant-a-pressed-icon-inside-another-values-cell) · lines 618–701
27
27
  - [16. Title linking to the record's view](#16-title-linking-to-the-records-view) · lines 703–738
28
28
  - [17. Quick action on the view](#17-quick-action-on-the-view) · lines 740–813
29
- - [18. Editable value](#18-editable-value) · lines 815–1483
30
- - [Presets: one line per field](#presets-one-line-per-field) · lines 1115–1183
31
- - [Several fields edited as one](#several-fields-edited-as-one) · lines 1185–1221
32
- - [A link and its label](#a-link-and-its-label) · lines 1223–1247
33
- - [A list of sub-items](#a-list-of-sub-items) · lines 1249–1382
34
- - [In a table's rows](#in-a-tables-rows) · lines 1384–1469
35
- - [A table of a few short columns: `width="content"`](#a-table-of-a-few-short-columns-widthcontent) · lines 1471–1483
36
- - [19. Stage circle for an ordered status](#19-stage-circle-for-an-ordered-status) · lines 1485–1551
37
- - [20. Count linking to the related records](#20-count-linking-to-the-related-records) · lines 1553–1617
38
- - [21. Rows grouped under headings, and a pill filter](#21-rows-grouped-under-headings-and-a-pill-filter) · lines 1619–1717
39
- - [22. A highlighted row, and rows that are done](#22-a-highlighted-row-and-rows-that-are-done) · lines 1719–1748
40
- - [24. A list's rows: hover, lines, rows per page](#24-a-lists-rows-hover-lines-rows-per-page) · lines 1750–1788
41
- - [23. A Group menu, and a record read beside the list](#23-a-group-menu-and-a-record-read-beside-the-list) · lines 1790–1866
42
- - [24. A stored colour beside its name](#24-a-stored-colour-beside-its-name) · lines 1868–1891
43
- - [25. A list's tools: views, filters, columns, row actions, a phone's rows](#25-a-lists-tools-views-filters-columns-row-actions-a-phones-rows) · lines 1893–1979
44
- - [26. A record's related list, capped](#26-a-records-related-list-capped) · lines 1981–2017
29
+ - [18. Editable value](#18-editable-value) · lines 815–1489
30
+ - [Presets: one line per field](#presets-one-line-per-field) · lines 1121–1189
31
+ - [Several fields edited as one](#several-fields-edited-as-one) · lines 1191–1227
32
+ - [A link and its label](#a-link-and-its-label) · lines 1229–1253
33
+ - [A list of sub-items](#a-list-of-sub-items) · lines 1255–1388
34
+ - [In a table's rows](#in-a-tables-rows) · lines 1390–1475
35
+ - [A table of a few short columns: `width="content"`](#a-table-of-a-few-short-columns-widthcontent) · lines 1477–1489
36
+ - [19. Stage circle for an ordered status](#19-stage-circle-for-an-ordered-status) · lines 1491–1557
37
+ - [20. Count linking to the related records](#20-count-linking-to-the-related-records) · lines 1559–1623
38
+ - [21. Rows grouped under headings, and a pill filter](#21-rows-grouped-under-headings-and-a-pill-filter) · lines 1625–1723
39
+ - [22. A highlighted row, and rows that are done](#22-a-highlighted-row-and-rows-that-are-done) · lines 1725–1754
40
+ - [24. A list's rows: hover, lines, rows per page](#24-a-lists-rows-hover-lines-rows-per-page) · lines 1756–1794
41
+ - [23. A Group menu, and a record read beside the list](#23-a-group-menu-and-a-record-read-beside-the-list) · lines 1796–1872
42
+ - [24. A stored colour beside its name](#24-a-stored-colour-beside-its-name) · lines 1874–1897
43
+ - [25. A list's tools: views, filters, columns, row actions, a phone's rows](#25-a-lists-tools-views-filters-columns-row-actions-a-phones-rows) · lines 1899–1985
44
+ - [26. A record's related list, capped](#26-a-records-related-list-capped) · lines 1987–2023
45
45
 
46
46
  <!-- /index -->
47
47
 
@@ -824,6 +824,12 @@ form uses.
824
824
 
825
825
  The rule behind every part of it: **nothing typed is ever lost.**
826
826
 
827
+ **No toast, ever.** An edit in place says what happened where it
828
+ happened: "Saving…" and "Saved" beside the value, a refusal's reason
829
+ under it. A toast after one would repeat what the person just watched
830
+ (add-an-entity.md "Toasts and feedback": a toast is for what happened
831
+ out of sight).
832
+
827
833
  **Which values.** Only those the plan's "View screen" names under `Edit
828
834
  in place`; read-only is the default, and a value not named renders
829
835
  exactly as it did. Text, long text, a single choice (optional ones with
@@ -12,29 +12,29 @@
12
12
  - [Logos and brand marks](#logos-and-brand-marks) · lines 231–275
13
13
  - [Categorical colour](#categorical-colour) · lines 277–347
14
14
  - [Heat scale](#heat-scale) · lines 349–410
15
- - [Depth ramps](#depth-ramps) · lines 412–490
16
- - [A stored colour](#a-stored-colour) · lines 492–540
17
- - [Shapes and sizes](#shapes-and-sizes) · lines 542–563
18
- - [Typography](#typography) · lines 565–685
19
- - [Written text (notes)](#written-text-notes) · lines 599–685
20
- - [Density](#density) · lines 687–780
21
- - [Rows on this device](#rows-on-this-device) · lines 753–780
22
- - [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 782–896
23
- - [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 898–975
24
- - [Notices](#notices) · lines 977–1005
25
- - [A value over time](#a-value-over-time) · lines 1007–1093
26
- - [Several values over time](#several-values-over-time) · lines 1056–1093
27
- - [A list as a board](#a-list-as-a-board) · lines 1095–1146
28
- - [A list as cards](#a-list-as-cards) · lines 1148–1194
29
- - [Key numbers on a record](#key-numbers-on-a-record) · lines 1196–1225
30
- - [Parts of the page standards](#parts-of-the-page-standards) · lines 1227–1270
31
- - [An overview page](#an-overview-page) · lines 1272–1335
32
- - [A record's header and empty values](#a-records-header-and-empty-values) · lines 1336–1374
33
- - [A record's tabs, mark and rail](#a-records-tabs-mark-and-rail) · lines 1376–1421
34
- - [Picking at random](#picking-at-random) · lines 1423–1454
35
- - [Filling in what's missing](#filling-in-whats-missing) · lines 1456–1523
36
- - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1525–1550
37
- - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 1552–1625
15
+ - [Depth ramps](#depth-ramps) · lines 412–495
16
+ - [A stored colour](#a-stored-colour) · lines 497–545
17
+ - [Shapes and sizes](#shapes-and-sizes) · lines 547–568
18
+ - [Typography](#typography) · lines 570–690
19
+ - [Written text (notes)](#written-text-notes) · lines 604–690
20
+ - [Density](#density) · lines 692–785
21
+ - [Rows on this device](#rows-on-this-device) · lines 758–785
22
+ - [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 787–901
23
+ - [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 903–980
24
+ - [Notices](#notices) · lines 982–1010
25
+ - [A value over time](#a-value-over-time) · lines 1012–1098
26
+ - [Several values over time](#several-values-over-time) · lines 1061–1098
27
+ - [A list as a board](#a-list-as-a-board) · lines 1100–1151
28
+ - [A list as cards](#a-list-as-cards) · lines 1153–1199
29
+ - [Key numbers on a record](#key-numbers-on-a-record) · lines 1201–1230
30
+ - [Parts of the page standards](#parts-of-the-page-standards) · lines 1232–1275
31
+ - [An overview page](#an-overview-page) · lines 1277–1340
32
+ - [A record's header and empty values](#a-records-header-and-empty-values) · lines 1341–1379
33
+ - [A record's tabs, mark and rail](#a-records-tabs-mark-and-rail) · lines 1381–1426
34
+ - [Picking at random](#picking-at-random) · lines 1428–1459
35
+ - [Filling in what's missing](#filling-in-whats-missing) · lines 1461–1528
36
+ - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1530–1555
37
+ - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 1557–1630
38
38
 
39
39
  <!-- /index -->
40
40
 
@@ -432,10 +432,10 @@ and `text-category-N-depth-M-foreground` (text on that cell).
432
432
  - **One ramp per category, its slot's.** A record whose category is slot 3
433
433
  draws its levels from slot 3's ramp, so the depth reads as "more of the
434
434
  same thing". Two categories side by side each keep their own ramp. A
435
- ramp's hue stays within about 20° of its slot's, so a step never reads
436
- as another slot, but steps of two neighbouring slots' ramps can come
437
- close (orange and brown, blue and navy): tell categories apart by their
438
- slot's own glyph and name, not by a ramp step alone.
435
+ ramp has one hue, its slot's, in all five steps and in both themes: only
436
+ lightness and chroma change. Steps of two neighbouring slots' ramps can
437
+ still come close (orange and brown, blue and navy): tell categories apart
438
+ by their slot's own glyph and name, not by a ramp step alone.
439
439
  - **Depth, not amount.** A ramp says "a level of this", never "more of
440
440
  this is worse". A count or a total over many categories is the heat
441
441
  scale; a status is a tone.
@@ -447,16 +447,18 @@ and `text-category-N-depth-M-foreground` (text on that cell).
447
447
  depends on the step and the theme: pair the two as below. It measures
448
448
  4.55:1 at the least.
449
449
  - **Neighbours are closer than the heat scale's, so keep a boundary.**
450
- Neighbouring steps are at least ΔE 17.7 apart in light and 13.9 in
451
- dark (blue's; every slot but blue and navy 17.4 or more), and 10.3
452
- under simulated deuteranopia and protanopia. Five steps of one hue that
453
- each clear 3:1 on the card only have so much lightness to share, dark's
454
- band most of all. A `stroke-card` or a 1px gap between shapes, as a
455
- stacked bar's segments have, makes each boundary easy to see.
456
- - **The order holds without hue.** Each step is darker than the one before
457
- it in both themes, so a ramp also reads in greyscale. In the dark
458
- themes step 1 is near white and step 5 the slot's deepest, still 3:1
459
- on the card.
450
+ Neighbouring steps are at least ΔE 9.6 apart in light and 8.7 in dark,
451
+ and 6.9 under simulated deuteranopia and protanopia. Five steps of one
452
+ hue that each clear 3:1 on the card only have so much lightness to
453
+ share. A `stroke-card` or a 1px gap between shapes, as a stacked bar's
454
+ segments have, makes each boundary easy to see.
455
+ - **Deeper is more contrast with the page.** In light each step is darker
456
+ than the one before it, in the dark themes brighter, so a ramp also
457
+ reads in greyscale. Step 1 is the shallowest, a tint of the hue (lightest
458
+ step still 3:1 on the card), and step 5 the deepest: nearly black in
459
+ light, nearly white in dark, never a grey. No step comes within ΔE 6 of
460
+ the neutral greys (`--muted`, `--muted-foreground`, `--rule`, `--border`,
461
+ `--input`, the charts' greys), so a step never reads as "no value".
460
462
  - **Never colour alone.** Name the level too, in the cell, a tooltip or
461
463
  a legend, and give a shape holding one a name for screen readers.
462
464
  - **Five steps, not more.** Deeper nesting than five shares step 5, or
@@ -483,11 +485,14 @@ The package's fixtures render every ramp (`patterns/DepthRamps`). Its
483
485
  Default story runs through axe and the token check in light and dark, axe
484
486
  in every palette too, and a check that measures every step of every
485
487
  slot, as a fill and as a cell, against the page and a card in each.
486
- `tests/depth-ramps.test.ts` holds the distance between neighbours (17 in
487
- light, 13.5 in dark, 10 with deuteranopia and protanopia), the order of
488
- lightness, text on every fill and every step against every palette's card
489
- and raised surface. `SideBySide` shows both themes at once, under normal
490
- vision and simulated deuteranopia and protanopia.
488
+ `tests/depth-ramps.test.ts` computes from the token values one hue per
489
+ slot, the order of lightness, the distance between neighbours (ΔE 8, and
490
+ 6 with deuteranopia and protanopia), the distance from the neutral greys
491
+ (6), text on every fill and every step against every palette's card and
492
+ raised surface, and fails if a change to `theme.css` breaks one.
493
+ `SideBySide` shows both themes at once, each ramp beside its theme's
494
+ muted greys, under normal vision and simulated deuteranopia and
495
+ protanopia.
491
496
 
492
497
  ## A stored colour
493
498
 
@@ -3,13 +3,22 @@
3
3
  // AppError{kind:'network'} instead of letting a raw fetch error escape. This
4
4
  // is the anti-corruption layer's error seam (docs/ARCHITECTURE.md).
5
5
  import { apiFetch } from "../transport/index.js";
6
+ import { reportAnswered, reportUnreachable } from "../../lib/connection.js";
7
+ // Each request also tells the connection store (lib/connection.ts) whether
8
+ // it got an answer, for OfflineNotice. A request cancelled on purpose (an
9
+ // AbortSignal: a query superseded or unmounted) says nothing either way.
6
10
  export async function safeFetch(path, init) {
11
+ let response;
7
12
  try {
8
- return await apiFetch(path, init);
13
+ response = await apiFetch(path, init);
9
14
  }
10
- catch {
15
+ catch (error) {
16
+ if (!(error instanceof DOMException && error.name === "AbortError"))
17
+ reportUnreachable();
11
18
  throw networkError();
12
19
  }
20
+ reportAnswered();
21
+ return response;
13
22
  }
14
23
  /**
15
24
  * Pass the response's `headers` so a 429 carries its Retry-After
@@ -0,0 +1,11 @@
1
+ import type { ActionState } from '../../hooks/use-action.js';
2
+ export type ActionErrorProps = {
3
+ /** The action, from useAction: its error, pending state and retry. */
4
+ action: Pick<ActionState, 'error' | 'pending'> & {
5
+ retry: () => unknown;
6
+ };
7
+ /** A lead before the reason: "Couldn't mark it as read". */
8
+ title?: string;
9
+ className?: string;
10
+ };
11
+ export declare function ActionError({ action, title, className }: ActionErrorProps): import("react").JSX.Element;
@@ -0,0 +1,15 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // An action's error beside its button (4.90, the dialogs and feedback
3
+ // standard D6): a destructive Notice with the reason and Try again, which
4
+ // runs the action again. Not a toast: the error stays next to what failed
5
+ // until it's tried again or the action works. Give it a useAction.
6
+ //
7
+ // The live region is always there (empty, it takes no room), so an error
8
+ // that appears is announced.
9
+ import { cn } from 'cn';
10
+ import { Button } from '../ui/button.js';
11
+ import { Spinner } from '../ui/spinner.js';
12
+ import { Notice } from './notice.js';
13
+ export function ActionError({ action, title, className }) {
14
+ return (_jsx("div", { role: "status", "data-slot": "action-error", className: cn('empty:hidden', className), children: action.error && (_jsx(Notice, { tone: "destructive", title: title, action: _jsxs(Button, { type: "button", size: "sm", variant: "outline", disabled: action.pending, onClick: () => void action.retry(), children: [action.pending && _jsx(Spinner, { className: "size-4" }), "Try again"] }), children: action.error })) }));
15
+ }
@@ -25,6 +25,7 @@ import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuLabel
25
25
  import { Skeleton } from '../ui/skeleton.js';
26
26
  import { Sidebar, SidebarContent, SidebarFooter, SidebarGroup, SidebarGroupContent, SidebarGroupLabel, SidebarHeader, SidebarInset, SidebarMenu, SidebarMenuButton, SidebarMenuItem, SidebarMenuSub, SidebarMenuSubButton, SidebarMenuSubItem, SidebarProvider, SidebarTrigger, useSidebar, } from '../ui/sidebar.js';
27
27
  import { Toaster } from '../ui/sonner.js';
28
+ import { OfflineNotice } from './offline-notice.js';
28
29
  import { TooltipProvider } from '../ui/tooltip.js';
29
30
  // Must match SIDEBAR_COOKIE_NAME in ../ui/sidebar.tsx, which writes the
30
31
  // cookie on every toggle but never reads it back — that half is here.
@@ -238,5 +239,5 @@ export function AppShell({ title, logo: Logo, nav, sidebarExtra, defaultSidebarO
238
239
  // (AuthProvider), so this stays a deliberate logout: a
239
240
  // clean /login, never the previous user's page as `from`.
240
241
  logout().catch(() => { });
241
- }, children: _jsx(LogOutIcon, {}) })] })] })] }) }), _jsx(PageTrailContext.Provider, { value: trailSlot, children: _jsxs("div", { "data-slot": "app-shell-column", className: "flex w-full min-w-0 flex-1 flex-col bg-background", 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", { "data-slot": "app-shell-trail", className: "min-w-0 flex-1", children: trail.length > 0 && _jsx(PageTrail, { crumbs: trail, "aria-label": "You are here", className: "max-md:hidden" }) }), search && _jsx(SearchPalette, { search: search, nav: nav }), _jsx(LookControl, {})] }), _jsx(SidebarInset, { className: "min-w-0", children: _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" })] }));
242
+ }, children: _jsx(LogOutIcon, {}) })] })] })] }) }), _jsx(PageTrailContext.Provider, { value: trailSlot, children: _jsxs("div", { "data-slot": "app-shell-column", className: "flex w-full min-w-0 flex-1 flex-col bg-background", 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", { "data-slot": "app-shell-trail", className: "min-w-0 flex-1", children: trail.length > 0 && _jsx(PageTrail, { crumbs: trail, "aria-label": "You are here", className: "max-md:hidden" }) }), search && _jsx(SearchPalette, { search: search, nav: nav }), _jsx(LookControl, {})] }), _jsx(OfflineNotice, {}), _jsx(SidebarInset, { className: "min-w-0", children: _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, {})] }));
242
243
  }
@@ -0,0 +1,28 @@
1
+ import { type ReactElement, type ReactNode } from 'react';
2
+ export type DeleteKind = 'soft' | 'hard';
3
+ export type DeleteActionProps = {
4
+ /** What's deleted, as the page names it: "The Long Walk". */
5
+ name: string;
6
+ /** `soft`: it goes to Deleted and Restore brings it back. `hard`: it's gone. */
7
+ kind: DeleteKind;
8
+ /** Deletes it. A rejection keeps the dialog open with the reason. */
9
+ onDelete: () => Promise<unknown>;
10
+ /** A soft delete's Undo: restores it. Without it the toast has no Undo. */
11
+ onRestore?: () => Promise<unknown>;
12
+ /** After it's deleted and the toast is up: leave the record's page, say. */
13
+ onDeleted?: () => void;
14
+ /** The action's word, "Delete" unless set ("Retire"). */
15
+ verb?: string;
16
+ /** The word once it's done, "Deleted" unless set. Defaults to `verb` + "d" ("Retired"), or + "ed". */
17
+ verbDone?: string;
18
+ /** Another sentence under the question than `kind`'s. */
19
+ description?: ReactNode;
20
+ /** `"icon"` (the default), `"button"` (the verb in words), an element to open it, or `null` for none. */
21
+ trigger?: 'icon' | 'button' | ReactElement | null;
22
+ /** The icon trigger's size: `default` (36px, a header) or `sm` (32px, a row). */
23
+ size?: 'default' | 'sm';
24
+ /** Open it from outside, with `trigger={null}`. */
25
+ open?: boolean;
26
+ onOpenChange?: (open: boolean) => void;
27
+ };
28
+ export declare function DeleteAction({ name, kind, onDelete, onRestore, onDeleted, verb, verbDone, description, trigger, size, open: openProp, onOpenChange, }: DeleteActionProps): import("react").JSX.Element;
@@ -0,0 +1,61 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // The one delete (4.90, the dialogs and feedback standard D1): a record's
3
+ // Delete in its header and a row's delete in a table both use it.
4
+ //
5
+ // - The confirm asks "Delete <name>?" and says what happens, by `kind`:
6
+ // `soft` "It goes to Deleted, and Restore brings it back.", `hard` "This
7
+ // can't be undone." A confirm dialog (420px; a bottom sheet on a phone,
8
+ // the action above Cancel), Cancel first, then the filled red button.
9
+ // - A failed delete keeps the dialog open with the reason in a Notice and
10
+ // Try again (useAction, ActionError). A slow one spins in the button.
11
+ // - Done: the dialog closes, `onDeleted` runs (leave the record's page),
12
+ // and the toast says "Deleted <name>". A soft delete's toast has Undo
13
+ // (`onRestore`), then "Restored <name>".
14
+ // - `verb` covers the other ways something leaves a list: `verb="Retire"`
15
+ // asks "Retire <name>?" on a "Retire" button and says "Retired <name>".
16
+ //
17
+ // The trigger is an icon (IconAction's Trash2) unless `trigger` says
18
+ // otherwise: `"button"` for a "Delete" button in words, an element of the
19
+ // caller's, or `null` for none, opened with `open`/`onOpenChange` (a row's
20
+ // menu item).
21
+ import { useState } from 'react';
22
+ import { Trash2Icon } from 'lucide-react';
23
+ import { useAction } from '../../hooks/use-action.js';
24
+ import { Button } from '../ui/button.js';
25
+ import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from '../ui/dialog.js';
26
+ import { Spinner } from '../ui/spinner.js';
27
+ import { ActionError } from './action-error.js';
28
+ import { IconAction } from './icon-action.js';
29
+ import { notify, pastTense } from './notify.js';
30
+ const SAYS = {
31
+ soft: 'It goes to Deleted, and Restore brings it back.',
32
+ hard: 'This can’t be undone.',
33
+ };
34
+ export function DeleteAction({ name, kind, onDelete, onRestore, onDeleted, verb = 'Delete', verbDone, description, trigger = 'icon', size = 'default', open: openProp, onOpenChange, }) {
35
+ const [openState, setOpenState] = useState(false);
36
+ const open = openProp ?? openState;
37
+ const setOpen = (next) => {
38
+ if (openProp === undefined)
39
+ setOpenState(next);
40
+ onOpenChange?.(next);
41
+ };
42
+ const done = verbDone ?? pastTense(verb);
43
+ const remove = useAction(onDelete, { failed: `Couldn't ${verb.toLowerCase()} ${name}` });
44
+ const confirm = async () => {
45
+ const outcome = await remove.run();
46
+ if (!outcome.ok)
47
+ return;
48
+ // Whether or not this is still on screen: a row's delete is gone with
49
+ // its row once the list refetches, and the toast must still show.
50
+ notify.done(done, name, kind === 'soft' && onRestore ? { undo: onRestore } : {});
51
+ setOpen(false);
52
+ onDeleted?.();
53
+ };
54
+ return (_jsxs(Dialog, { open: open, onOpenChange: (next) => {
55
+ if (remove.pending)
56
+ return;
57
+ if (!next)
58
+ remove.reset();
59
+ setOpen(next);
60
+ }, children: [trigger === 'icon' && (_jsx(DialogTrigger, { render: _jsx(IconAction, { icon: Trash2Icon, label: verb, tone: "destructive", size: size }) })), trigger === 'button' && (_jsx(DialogTrigger, { render: _jsx(Button, { variant: "outline", size: size === 'sm' ? 'sm' : 'default' }), children: verb })), trigger && typeof trigger === 'object' && _jsx(DialogTrigger, { render: trigger }), _jsxs(DialogContent, { size: "confirm", "data-slot": "delete-action", "data-kind": kind, children: [_jsxs(DialogHeader, { children: [_jsxs(DialogTitle, { children: [verb, " ", name, "?"] }), _jsx(DialogDescription, { children: description ?? SAYS[kind] })] }), _jsx(ActionError, { action: { ...remove, retry: confirm } }), _jsxs(DialogFooter, { children: [_jsx(DialogClose, { render: _jsx(Button, { variant: "outline", disabled: remove.pending }), children: "Cancel" }), _jsxs(Button, { variant: "destructive", disabled: remove.pending, onClick: () => void confirm(), children: [remove.pending && _jsx(Spinner, { className: "size-4" }), verb] })] })] })] }));
61
+ }
@@ -0,0 +1,17 @@
1
+ import type { ReactNode } from 'react';
2
+ export type JobProgress = {
3
+ /** How far it is: the 3 in "Checking 3 of 12…". */
4
+ done: number;
5
+ /** How many there are, when it's known; without it the line is just "Checking…". */
6
+ total?: number;
7
+ };
8
+ export type JobStatusProps = {
9
+ /** While it runs: how far along it is. Leave it out (or null) once it's finished. */
10
+ state?: JobProgress | null;
11
+ /** The word for the work, as it goes: "Checking", "Fetching". */
12
+ verb: string;
13
+ /** Once it's finished: what it found, "Checked 12 · 2 deals". Stays until the next run. */
14
+ result?: ReactNode;
15
+ className?: string;
16
+ };
17
+ export declare function JobStatus({ state, verb, result, className }: JobStatusProps): import("react").JSX.Element;
@@ -0,0 +1,7 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { CheckIcon } from 'lucide-react';
3
+ import { cn } from 'cn';
4
+ import { Spinner } from '../ui/spinner.js';
5
+ export function JobStatus({ state, verb, result, className }) {
6
+ return (_jsx("div", { role: "status", "data-slot": "job-status", "data-state": state ? 'running' : result ? 'done' : 'idle', className: cn('flex min-h-5 items-center gap-1.5 type-caption text-muted-foreground empty:hidden', className), children: state ? (_jsxs(_Fragment, { children: [_jsx(Spinner, { className: "size-3.5" }), _jsx("span", { className: "tabular-nums", children: state.total === undefined ? `${verb}…` : `${verb} ${state.done} of ${state.total}…` })] })) : result ? (_jsxs(_Fragment, { children: [_jsx(CheckIcon, { "aria-hidden": "true", className: "size-3.5 text-success-text" }), _jsx("span", { children: result })] })) : null }));
7
+ }
@@ -0,0 +1,17 @@
1
+ export type NotifyDoneOptions = {
2
+ /** Undo's action: restores what was done. Undo shows only when it's given. */
3
+ undo?: () => unknown;
4
+ /** The verb once Undo has worked: "Restored" unless set ("Unarchived"). */
5
+ undone?: string;
6
+ };
7
+ /** "Deleted The Long Walk": the verb, then the name. */
8
+ export declare function doneMessage(verb: string, name: string): string;
9
+ /** "Retire" → "Retired", "Archive" → "Archived", "Remove" → "Removed". */
10
+ export declare function pastTense(verb: string): string;
11
+ declare function failed(message: string): string | number;
12
+ declare function done(verb: string, name: string, { undo, undone }?: NotifyDoneOptions): string | number;
13
+ export declare const notify: {
14
+ done: typeof done;
15
+ failed: typeof failed;
16
+ };
17
+ export {};
@@ -0,0 +1,46 @@
1
+ // The words and the lifetimes of the app's toasts (4.90, the dialogs and
2
+ // feedback standard D5, D6). A toast is for what happened out of sight: a
3
+ // delete (with Undo), a record made somewhere else, a job that finished
4
+ // after the page was left. Never after an edit in place, which shows its
5
+ // own "Saved" (cell-patterns.md, add-an-entity.md "When a toast shows").
6
+ //
7
+ // - `notify.done("Deleted", "The Long Walk", { undo })`: "Deleted The Long
8
+ // Walk", the verb first, the same way everywhere, for 4 seconds. With
9
+ // `undo`, an Undo button that runs it, then "Restored The Long Walk"; an
10
+ // Undo that fails is a toast that stays.
11
+ // - `notify.failed("Couldn't save The Long Walk: the server didn't
12
+ // answer.")`: an error toast that stays until it's closed. Only as the
13
+ // fallback, when what failed is no longer on screen (useAction does
14
+ // this); an action whose button is still there shows its error beside
15
+ // it (ActionError).
16
+ import { toast } from 'sonner';
17
+ import { messageOf } from './edit-in-place-store.js';
18
+ /** "Deleted The Long Walk": the verb, then the name. */
19
+ export function doneMessage(verb, name) {
20
+ return `${verb} ${name}`;
21
+ }
22
+ /** "Retire" → "Retired", "Archive" → "Archived", "Remove" → "Removed". */
23
+ export function pastTense(verb) {
24
+ return verb.endsWith('e') ? `${verb}d` : `${verb}ed`;
25
+ }
26
+ function failed(message) {
27
+ return toast.error(message, { duration: Number.POSITIVE_INFINITY, closeButton: true });
28
+ }
29
+ function done(verb, name, { undo, undone = 'Restored' } = {}) {
30
+ return toast.success(doneMessage(verb, name), {
31
+ action: undo
32
+ ? {
33
+ label: 'Undo',
34
+ onClick: () => {
35
+ // A promise from here, not a mutation's callbacks: whatever
36
+ // asked for the toast may be gone (a record's page, left after
37
+ // its delete) by the time Undo is pressed.
38
+ Promise.resolve()
39
+ .then(undo)
40
+ .then(() => toast.success(doneMessage(undone, name)), (error) => failed(`Couldn't undo: ${messageOf(error)}`));
41
+ },
42
+ }
43
+ : undefined,
44
+ });
45
+ }
46
+ export const notify = { done, failed };
@@ -0,0 +1,6 @@
1
+ export type OfflineNoticeProps = {
2
+ /** Show it whatever the connection: for a fixture or a test. */
3
+ offline?: boolean;
4
+ className?: string;
5
+ };
6
+ export declare function OfflineNotice({ offline: forced, className }: OfflineNoticeProps): import("react").JSX.Element;