@tristan2828/ui-foundation 4.88.0 → 4.90.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 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
@@ -3,37 +3,38 @@
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 46–113
7
- - [Glow](#glow) · lines 115–133
8
- - [Semantic tones](#semantic-tones) · lines 135–163
9
- - [The three badge styles](#the-three-badge-styles) · lines 165–182
10
- - [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines 184–213
11
- - [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines 215–228
12
- - [Logos and brand marks](#logos-and-brand-marks) · lines 230–274
13
- - [Categorical colour](#categorical-colour) · lines 276–346
14
- - [Heat scale](#heat-scale) · lines 348–409
15
- - [Depth ramps](#depth-ramps) · lines 411–489
16
- - [A stored colour](#a-stored-colour) · lines 491–539
17
- - [Shapes and sizes](#shapes-and-sizes) · lines 541–562
18
- - [Typography](#typography) · lines 564–684
19
- - [Written text (notes)](#written-text-notes) · lines 598–684
20
- - [Density](#density) · lines 686–779
21
- - [Rows on this device](#rows-on-this-device) · lines 752–779
22
- - [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 781–895
23
- - [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 897–974
24
- - [Notices](#notices) · lines 976–1004
25
- - [A value over time](#a-value-over-time) · lines 1006–1092
26
- - [Several values over time](#several-values-over-time) · lines 1055–1092
27
- - [A list as a board](#a-list-as-a-board) · lines 1094–1145
28
- - [A list as cards](#a-list-as-cards) · lines 1147–1193
29
- - [Key numbers on a record](#key-numbers-on-a-record) · lines 1195–1224
30
- - [Parts of the page standards](#parts-of-the-page-standards) · lines 1226–1269
31
- - [A record's header and empty values](#a-records-header-and-empty-values) · lines 1270–1308
32
- - [A record's tabs, mark and rail](#a-records-tabs-mark-and-rail) · lines 1310–1355
33
- - [Picking at random](#picking-at-random) · lines 1357–1388
34
- - [Filling in what's missing](#filling-in-whats-missing) · lines 1390–1457
35
- - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1459–1484
36
- - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 1486–1559
6
+ - [Palettes](#palettes) · lines 47–114
7
+ - [Glow](#glow) · lines 116–134
8
+ - [Semantic tones](#semantic-tones) · lines 136–164
9
+ - [The three badge styles](#the-three-badge-styles) · lines 166–183
10
+ - [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines 185–214
11
+ - [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines 216–229
12
+ - [Logos and brand marks](#logos-and-brand-marks) · lines 231–275
13
+ - [Categorical colour](#categorical-colour) · lines 277–347
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
37
38
 
38
39
  <!-- /index -->
39
40
 
@@ -1267,6 +1268,71 @@ into a table, a record or an overview.
1267
1268
  Every one is measured with axe and the glyph check in both themes
1268
1269
  (fixtures `app/ValueList`, `ListHeader`, `Timeline`, `NeedsYou`,
1269
1270
  `Freshness`, `PartEmpty`).
1271
+
1272
+ ## An overview page
1273
+
1274
+ The overview standard (4.89): a module's first page when it has three
1275
+ or more lists, saying how things stand and what waits on the user, each
1276
+ part one click from its list. `OverviewPage` draws the whole page; the
1277
+ hub's `WidgetCard`s take the same card anatomy, so a hub and an overview
1278
+ read alike.
1279
+
1280
+ ```tsx
1281
+ <OverviewPage
1282
+ title="Household"
1283
+ stats={<KeyStats stats={[{ label: 'Savings', value: '$24,800', icon: LandmarkIcon }]} />}
1284
+ needs={[{ text: 'Balances are three months old', to: '/accounts' }]}
1285
+ parts={[
1286
+ {
1287
+ id: 'savings',
1288
+ title: 'Savings',
1289
+ icon: LandmarkIcon,
1290
+ to: '/accounts',
1291
+ value: '$24,800',
1292
+ line: '+$1,120 since August',
1293
+ freshness: { label: 'Balances entered', at: entered, staleAfter: addDays(entered, 90) },
1294
+ detail: <WidgetList>…</WidgetList>,
1295
+ isLoading,
1296
+ error,
1297
+ onRetry: refetch,
1298
+ },
1299
+ { id: 'budget', title: 'Budget', icon: WalletIcon, to: '/budget',
1300
+ empty: { action: { label: 'Add the first line', to: '/budget/new' } } },
1301
+ ]}
1302
+ />
1303
+ ```
1304
+
1305
+ - **The top:** the title (the page's h1, `actions` at its end), then
1306
+ `stats` (a `KeyStats` strip of three to five numbers), then `NeedsYou`
1307
+ from `needs`, which draws nothing when nothing waits. Collect `needs`
1308
+ from what each part says about itself.
1309
+ - **From 48rem up, tiles.** One per part, at least 170px, as many as fit:
1310
+ the icon and title, `value` in the numeric type, and `freshness`. A
1311
+ tile is a button (`aria-expanded`, `aria-controls` the detail); a click
1312
+ opens its part's detail below the grid, one at a time, and a second
1313
+ click or Escape inside the detail closes it, focus back on the tile.
1314
+ `defaultOpen` names a part open at first.
1315
+ - **The detail is a `WidgetCard`:** the title as a link to `to` with a
1316
+ chevron, `value`, `line`, the app's `detail` (a few `WidgetList` rows,
1317
+ a small `LineChart`) and `freshness`.
1318
+ - **Under 48rem, an accordion.** The same cards in a `WidgetCardGroup`,
1319
+ each folded to one line with its value; opening one folds the others.
1320
+ - **Each part owns its states:** `isLoading` (a skeleton in the tile and
1321
+ the card), `error` with `onRetry` (a dash in the tile, the compact
1322
+ `ErrorState` in the card), and `empty` (a part with nothing yet: "Nothing
1323
+ yet" in the tile, `PartEmpty` and its one way to start in the card). An
1324
+ empty part stays on the page: hiding it makes the part forgotten.
1325
+ - **One card anatomy on a hub** (`WidgetCard`): `to` makes the title the
1326
+ link with a chevron (in place of the header's `link`), `value` the
1327
+ headline in the numeric type, `line` one muted line under it, and
1328
+ `freshness` the `Freshness` line at the body's end, after the
1329
+ children. A folded card shows `value` when it has no `summary`. All
1330
+ optional: a card without them is drawn as before, and its folding on a
1331
+ phone is unchanged.
1332
+
1333
+ Measured with axe and the glyph check in both themes and every palette
1334
+ (fixture `app/OverviewPage`); `e2e/overview-page.spec.ts` clicks the
1335
+ tiles, Escape and the accordion.
1270
1336
  ## A record's header and empty values
1271
1337
 
1272
1338
  The record page standard (4.81): the same header on every record, the
@@ -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;
@@ -0,0 +1,19 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // "You're offline" across the top of the app (4.90, the dialogs and
3
+ // feedback standard D9), while the server can't be reached: the browser
4
+ // says it's offline, or a request got no answer at all. Gone as soon as
5
+ // the browser is back online or any request gets an answer. AppShell
6
+ // draws it above every page; an app without the shell can render it
7
+ // itself. One bar instead of each save failing on its own: a save made
8
+ // meanwhile still shows its own error beside it.
9
+ //
10
+ // A warning-tone band (the Notice's wash, edge to edge), in a live region
11
+ // that's always there, so the bar is announced when it appears.
12
+ import { WifiOffIcon } from 'lucide-react';
13
+ import { cn } from 'cn';
14
+ import { useOffline } from '../../lib/connection.js';
15
+ export function OfflineNotice({ offline: forced, className }) {
16
+ const detected = useOffline();
17
+ const offline = forced ?? detected;
18
+ return (_jsx("div", { role: "status", "data-slot": "offline-notice", className: "empty:hidden", children: offline && (_jsxs("div", { "data-state": "offline", className: cn('flex items-center justify-center gap-2 border-b border-warning-text/30 bg-warning/10 px-4 py-1.5 text-center type-body text-foreground dark:bg-warning/20', className), children: [_jsx(WifiOffIcon, { "aria-hidden": "true", className: "size-4 shrink-0 text-warning-text" }), _jsx("span", { children: "You\u2019re offline. Changes won\u2019t save until you\u2019re back." })] })) }));
19
+ }
@@ -0,0 +1,44 @@
1
+ import { type ReactNode } from 'react';
2
+ import type { To } from 'react-router';
3
+ import type { AppError } from '../../api/contracts.js';
4
+ import { type FreshnessProps } from './freshness.js';
5
+ import type { IconComponent } from './icon-component.js';
6
+ import { type NeedsYouItem } from './needs-you.js';
7
+ import type { PartEmptyState } from './part-empty.js';
8
+ export type OverviewPart = {
9
+ /** Unique on the page: the tile's and the card's id. */
10
+ id: string;
11
+ title: string;
12
+ /** Decorative: the title names the part. */
13
+ icon?: IconComponent;
14
+ /** Where the part's full list or page is: its detail's title links there. */
15
+ to: To;
16
+ /** The headline: a number or a word or two ("$412,300", "3 of 7"). */
17
+ value?: ReactNode;
18
+ /** One muted line under the value, in the detail: what it means. */
19
+ line?: ReactNode;
20
+ /** How old the value is, in the tile and the detail. */
21
+ freshness?: FreshnessProps;
22
+ /** What the detail shows under the value: a few rows (WidgetList), a small chart. */
23
+ detail?: ReactNode;
24
+ /** A part with nothing yet: given, the part is empty, and its detail offers this one way to start. */
25
+ empty?: PartEmptyState;
26
+ isLoading?: boolean;
27
+ error?: AppError | null;
28
+ onRetry?: () => void;
29
+ };
30
+ export type OverviewPageProps = {
31
+ /** The page's h1: the module's name. */
32
+ title: string;
33
+ parts: readonly OverviewPart[];
34
+ /** What waits on the user, collected from the parts: NeedsYou under the title. */
35
+ needs?: readonly NeedsYouItem[];
36
+ /** A strip of key numbers under the title (a KeyStats), before Needs you. */
37
+ stats?: ReactNode;
38
+ /** Controls at the title's end. */
39
+ actions?: ReactNode;
40
+ /** The part open at first; none when left out. */
41
+ defaultOpen?: string | null;
42
+ className?: string;
43
+ };
44
+ export declare function OverviewPage({ title, parts, needs, stats, actions, defaultOpen, className, }: OverviewPageProps): import("react").JSX.Element;
@@ -0,0 +1,63 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ // A module's overview page (overview standard O1): what sums a module up
3
+ // rather than lists it. The title (the page's h1), an optional strip of
4
+ // key numbers (`stats`, a KeyStats), NeedsYou from `needs` (nothing when
5
+ // it's empty), then the module's parts:
6
+ //
7
+ // - from 48rem up, a grid of tiles, each at least 170px, as many as fit.
8
+ // A tile is a button: the part's icon and title, its `value` in the
9
+ // numeric type, and its `freshness`. A click opens the part's detail
10
+ // below the grid, one at a time (`aria-expanded`, `aria-controls` the
11
+ // detail); a second click, or Escape inside the detail, closes it.
12
+ // The detail is the part's WidgetCard: the title as a link to `to`
13
+ // with a chevron, `value`, `line`, the app's own `detail`, `freshness`.
14
+ // - under 48rem, the same WidgetCards as an accordion (WidgetCardGroup):
15
+ // each folded to one line with its value, opening one folds the others.
16
+ //
17
+ // A part owns its states as a WidgetCard does: `isLoading` (a skeleton in
18
+ // the tile and the card), `error` (a dash in the tile, ErrorState with
19
+ // `onRetry` in the card), and `empty` (a part with nothing yet: "Nothing
20
+ // yet" in the tile, PartEmpty with its one way to start in the card).
21
+ //
22
+ // The breakpoint is read with matchMedia; on the server, or where it's
23
+ // missing (a test's DOM), the page is drawn wide.
24
+ import { useId, useState, useSyncExternalStore } from 'react';
25
+ import { cn } from 'cn';
26
+ import { Freshness } from './freshness.js';
27
+ import { NeedsYou } from './needs-you.js';
28
+ import { WidgetCard, WidgetCardGroup } from './widget-card.js';
29
+ import { Skeleton } from '../ui/skeleton.js';
30
+ const WIDE_QUERY = '(min-width: 48rem)';
31
+ const canMatchMedia = () => typeof window !== 'undefined' && typeof window.matchMedia === 'function';
32
+ function subscribeWide(listener) {
33
+ if (!canMatchMedia())
34
+ return () => { };
35
+ const query = window.matchMedia(WIDE_QUERY);
36
+ query.addEventListener('change', listener);
37
+ return () => query.removeEventListener('change', listener);
38
+ }
39
+ const useIsWide = () => useSyncExternalStore(subscribeWide, () => !canMatchMedia() || window.matchMedia(WIDE_QUERY).matches, () => true);
40
+ export function OverviewPage({ title, parts, needs = [], stats, actions, defaultOpen = null, className, }) {
41
+ const wide = useIsWide();
42
+ const detailId = useId();
43
+ const [openId, setOpenId] = useState(defaultOpen);
44
+ const open = parts.find((part) => part.id === openId);
45
+ const tileId = (id) => `${detailId}-tile-${id}`;
46
+ // Escape in the detail closes it and puts focus back on its tile.
47
+ const onDetailKeyDown = (event) => {
48
+ if (event.key !== 'Escape' || openId === null)
49
+ return;
50
+ const tile = document.getElementById(tileId(openId));
51
+ setOpenId(null);
52
+ tile?.focus();
53
+ };
54
+ return (_jsxs("div", { "data-slot": "overview-page", className: cn('flex flex-col gap-4', className), children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-2", children: [_jsx("h1", { className: "type-page-title text-foreground", children: title }), actions && _jsx("div", { className: "flex shrink-0 items-center gap-2", children: actions })] }), stats, _jsx(NeedsYou, { items: needs }), wide ? (_jsxs(_Fragment, { children: [_jsx("ul", { "data-slot": "overview-tiles", className: "grid grid-cols-[repeat(auto-fill,minmax(170px,1fr))] gap-2.5", children: parts.map((part) => (_jsx("li", { className: "flex min-w-0", children: _jsx(OverviewTile, { id: tileId(part.id), part: part, open: part.id === openId, controls: detailId, onToggle: () => setOpenId(part.id === openId ? null : part.id) }) }, part.id))) }), _jsx("div", { id: detailId, "data-slot": "overview-detail", onKeyDown: onDetailKeyDown, children: open && _jsx(PartCard, { part: open }) })] })) : (_jsx(WidgetCardGroup, { accordion: true, defaultOpen: openId, className: "flex flex-col gap-2.5", children: parts.map((part) => (_jsx(PartCard, { part: part }, part.id))) }))] }));
55
+ }
56
+ function PartCard({ part }) {
57
+ return (_jsx(WidgetCard, { id: part.id, title: part.title, icon: part.icon, to: part.to, value: part.value, line: part.line, freshness: part.freshness, isLoading: part.isLoading ?? false, error: part.error, onRetry: part.onRetry, isEmpty: part.empty !== undefined, emptyMessage: part.empty?.text ?? 'Nothing here yet', empty: part.empty, emptySummary: "Nothing yet", className: "w-full", children: part.detail }));
58
+ }
59
+ function OverviewTile({ id, part, open, controls, onToggle, }) {
60
+ const { icon: Icon } = part;
61
+ const state = part.error ? 'error' : part.isLoading ? 'loading' : part.empty ? 'empty' : 'success';
62
+ return (_jsxs("button", { type: "button", id: id, "data-slot": "overview-tile", "data-state": state, "aria-expanded": open, "aria-controls": controls, onClick: onToggle, className: cn('glow-edge flex w-full min-w-0 flex-col items-start gap-0.5 rounded-lg bg-card px-3 py-2.5 text-left text-card-foreground', 'shadow-(--card-shadow) ring-1 ring-border outline-none hover:bg-muted', 'focus-visible:ring-3 focus-visible:ring-ring/50 aria-expanded:ring-2 aria-expanded:ring-primary'), children: [_jsxs("span", { className: "flex min-w-0 max-w-full items-center gap-1.5 type-label text-muted-foreground", children: [Icon && _jsx(Icon, { "aria-hidden": "true", className: "size-4 shrink-0 text-link" }), _jsx("span", { className: "truncate", children: part.title })] }), state === 'loading' ? (_jsxs(_Fragment, { children: [_jsx(Skeleton, { "data-state": "loading", className: "my-1 h-6 w-16" }), _jsx("span", { className: "sr-only", children: "Loading" })] })) : state === 'error' ? (_jsxs("span", { "data-state": "error", className: "type-numeric text-muted-foreground", children: [_jsx("span", { "aria-hidden": "true", children: "\u2014" }), _jsx("span", { className: "sr-only", children: "Couldn't load" })] })) : state === 'empty' ? (_jsx("span", { "data-state": "empty", className: "py-0.5 type-body text-muted-foreground", children: "Nothing yet" })) : (part.value !== undefined && (_jsx("span", { "data-slot": "overview-tile-value", className: "max-w-full truncate type-numeric text-foreground", children: part.value }))), state === 'success' && part.freshness && _jsx(Freshness, { ...part.freshness })] }));
63
+ }
@@ -1,6 +1,7 @@
1
1
  import { type ReactNode } from 'react';
2
2
  import { type To } from 'react-router';
3
3
  import type { AppError } from '../../api/contracts.js';
4
+ import { type FreshnessProps } from './freshness.js';
4
5
  import type { IconComponent } from './icon-component.js';
5
6
  import { type PartEmptyState } from './part-empty.js';
6
7
  export interface WidgetCardProps {
@@ -16,6 +17,18 @@ export interface WidgetCardProps {
16
17
  * title names the card.
17
18
  */
18
19
  icon?: IconComponent;
20
+ /**
21
+ * Makes the title the link to everything the card sums up, with a
22
+ * chevron after it ("Net worth ›"): the overview standard's one way a
23
+ * card links its list (O4). Use it in place of `link`, not beside it.
24
+ */
25
+ to?: To;
26
+ /** The card's headline: a number or a word or two ("$412,300", "On track"), in the numeric type. */
27
+ value?: ReactNode;
28
+ /** One muted line under `value`: what it means ("+$6,240 since Aug"). */
29
+ line?: ReactNode;
30
+ /** How old the number is: Freshness's props, drawn at the body's end. */
31
+ freshness?: FreshnessProps;
19
32
  /** The title's heading level: 2 under the page's h1 (the default), deeper under a section. */
20
33
  headingLevel?: 2 | 3 | 4 | 5 | 6;
21
34
  /**
@@ -55,7 +68,7 @@ export interface WidgetCardProps {
55
68
  /**
56
69
  * One short value shown in the header while the card is folded: a count
57
70
  * (`3`), or a word or two (`"Due today"`). A skeleton while loading, a
58
- * muted dash on an error. Ignored while open.
71
+ * muted dash on an error. Ignored while open. Defaults to `value`.
59
72
  */
60
73
  summary?: ReactNode;
61
74
  /** What a folded card's summary says when it's empty (`"None"`); nothing when left out. */
@@ -72,7 +85,7 @@ export type WidgetCardLink = {
72
85
  label: string;
73
86
  to?: never;
74
87
  };
75
- export declare function WidgetCard({ id, title, icon: Icon, headingLevel, link, isLoading, error, onRetry, isEmpty, emptyMessage, empty, skeletonRows, collapsible, defaultCollapsed, storageKey, summary, emptySummary, children, className, }: WidgetCardProps): import("react").JSX.Element;
88
+ export declare function WidgetCard({ id, title, icon: Icon, to, value, line, freshness, headingLevel, link, isLoading, error, onRetry, isEmpty, emptyMessage, empty, skeletonRows, collapsible, defaultCollapsed, storageKey, summary: ownSummary, emptySummary, children, className, }: WidgetCardProps): import("react").JSX.Element;
76
89
  export interface WidgetCardGroupProps {
77
90
  /**
78
91
  * One card open at a time: `true` always, `"mobile"` only below the
@@ -50,15 +50,25 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
50
50
  // switch). A trailing control is labelled by the row's text: pass a
51
51
  // function and it gets the id to put in `aria-labelledby`.
52
52
  //
53
+ // One card anatomy (overview standard O4), shared with OverviewPage's
54
+ // parts so the hub's widgets and an overview's parts read alike: `to`
55
+ // makes the title the link to everything the card sums up, with a
56
+ // chevron after it; `value` is its headline in the numeric type, `line`
57
+ // one muted line under it, and `freshness` how old the number is
58
+ // (Freshness) at the body's end. A folded card shows `value` as its
59
+ // summary when no `summary` is given. All optional: a card without them
60
+ // is drawn as before, and its folding on a phone is unchanged.
61
+ //
53
62
  // Under data-density="compact" (#224) the card's padding drops to 12px and
54
63
  // a row's to 4px, for a dense hub; text stays at type-body. On a phone a
55
64
  // compact row is 44px tall and its link fills that height, so it stays a
56
65
  // finger's target.
57
66
  import { createContext, useContext, useId, useState } from 'react';
58
67
  import { Link } from 'react-router';
59
- import { ChevronDownIcon, ExternalLinkIcon } from 'lucide-react';
68
+ import { ChevronDownIcon, ChevronRightIcon, ExternalLinkIcon } from 'lucide-react';
60
69
  import { cn } from 'cn';
61
70
  import { ErrorState } from './error-state.js';
71
+ import { Freshness } from './freshness.js';
62
72
  import { PartEmpty } from './part-empty.js';
63
73
  import { Button } from '../ui/button.js';
64
74
  import { Card, CardContent, CardHeader } from '../ui/card.js';
@@ -67,7 +77,8 @@ import { useIsMobile } from '../../hooks/use-mobile.js';
67
77
  import { useRememberedFlag } from '../../hooks/use-remembered-flag.js';
68
78
  const HEADER_LINK_CLASS = 'shrink-0 rounded-sm type-label text-foreground underline underline-offset-4 outline-none ' +
69
79
  'hover:decoration-2 focus-visible:ring-3 focus-visible:ring-ring/50';
70
- export function WidgetCard({ id, title, icon: Icon, headingLevel = 2, link, isLoading, error, onRetry, isEmpty, emptyMessage, empty, skeletonRows = 3, collapsible = false, defaultCollapsed = false, storageKey, summary, emptySummary, children, className, }) {
80
+ export function WidgetCard({ id, title, icon: Icon, to, value, line, freshness, headingLevel = 2, link, isLoading, error, onRetry, isEmpty, emptyMessage, empty, skeletonRows = 3, collapsible = false, defaultCollapsed = false, storageKey, summary: ownSummary, emptySummary, children, className, }) {
81
+ const summary = ownSummary ?? value;
71
82
  const headingId = useId();
72
83
  const contentId = useId();
73
84
  const summaryId = useId();
@@ -91,10 +102,10 @@ export function WidgetCard({ id, title, icon: Icon, headingLevel = 2, link, isLo
91
102
  return;
92
103
  toggle();
93
104
  };
94
- return (_jsx("section", { id: id, "aria-labelledby": headingId, "data-slot": "widget-card", "data-state": state, "data-collapsed": collapsed || undefined, className: cn('min-w-0 self-start', className), children: _jsxs(Card, { className: cn('glow-edge density-compact:[--card-spacing:--spacing(3)]', collapsed && 'pb-0'), children: [_jsxs(CardHeader, { onClick: onHeaderClick, className: cn('flex items-center justify-between gap-3', inAccordion && 'cursor-pointer select-none', collapsed && 'border-b-0'), children: [_jsxs(Heading, { id: headingId, className: "flex min-w-0 items-center gap-2 type-section-title text-foreground", children: [Icon && _jsx(Icon, { "aria-hidden": "true", className: "size-4 shrink-0 text-muted-foreground" }), _jsx("span", { className: "truncate", children: title })] }), (link || foldable || summaryShown) && (_jsxs("div", { className: "flex shrink-0 items-center gap-1", children: [summaryShown && (_jsx("span", { id: summaryId, "data-slot": "widget-card-summary", className: "mr-2 flex items-center", children: _jsx(WidgetCardSummary, { state: state, summary: summary, emptySummary: emptySummary }) })), link?.href !== undefined ? (_jsxs("a", { href: link.href, target: "_blank", rel: "noreferrer", "aria-describedby": headingId, className: cn(HEADER_LINK_CLASS, 'inline-flex items-center gap-1'), children: [link.label, _jsx(ExternalLinkIcon, { "aria-hidden": "true", className: "size-3 shrink-0 text-muted-foreground" }), _jsx("span", { className: "sr-only", children: " (opens in a new tab)" })] })) : (link && (_jsx(Link, { to: link.to, "aria-describedby": headingId, className: HEADER_LINK_CLASS, children: link.label }))), foldable && (_jsx(Button, { variant: "ghost", size: "icon-sm", "aria-labelledby": headingId, "aria-describedby": summaryShown ? summaryId : undefined, "aria-expanded": !collapsed, "aria-controls": contentId, onClick: toggle,
105
+ return (_jsx("section", { id: id, "aria-labelledby": headingId, "data-slot": "widget-card", "data-state": state, "data-collapsed": collapsed || undefined, className: cn('min-w-0 self-start', className), children: _jsxs(Card, { className: cn('glow-edge density-compact:[--card-spacing:--spacing(3)]', collapsed && 'pb-0'), children: [_jsxs(CardHeader, { onClick: onHeaderClick, className: cn('flex items-center justify-between gap-3', inAccordion && 'cursor-pointer select-none', collapsed && 'border-b-0'), children: [_jsxs(Heading, { id: headingId, className: "flex min-w-0 items-center gap-2 type-section-title text-foreground", children: [Icon && _jsx(Icon, { "aria-hidden": "true", className: "size-4 shrink-0 text-muted-foreground" }), to !== undefined ? (_jsxs(Link, { to: to, "data-slot": "widget-card-title-link", className: "group/title -mx-1 flex min-w-0 items-center gap-0.5 rounded-sm px-1 outline-none hover:text-link focus-visible:ring-3 focus-visible:ring-ring/50", children: [_jsx("span", { className: "truncate underline-offset-4 group-hover/title:underline", children: title }), _jsx(ChevronRightIcon, { "aria-hidden": "true", className: "size-4 shrink-0 text-muted-foreground group-hover/title:text-link" })] })) : (_jsx("span", { className: "truncate", children: title }))] }), (link || foldable || summaryShown) && (_jsxs("div", { className: "flex shrink-0 items-center gap-1", children: [summaryShown && (_jsx("span", { id: summaryId, "data-slot": "widget-card-summary", className: "mr-2 flex items-center", children: _jsx(WidgetCardSummary, { state: state, summary: summary, emptySummary: emptySummary }) })), link?.href !== undefined ? (_jsxs("a", { href: link.href, target: "_blank", rel: "noreferrer", "aria-describedby": headingId, className: cn(HEADER_LINK_CLASS, 'inline-flex items-center gap-1'), children: [link.label, _jsx(ExternalLinkIcon, { "aria-hidden": "true", className: "size-3 shrink-0 text-muted-foreground" }), _jsx("span", { className: "sr-only", children: " (opens in a new tab)" })] })) : (link && (_jsx(Link, { to: link.to, "aria-describedby": headingId, className: HEADER_LINK_CLASS, children: link.label }))), foldable && (_jsx(Button, { variant: "ghost", size: "icon-sm", "aria-labelledby": headingId, "aria-describedby": summaryShown ? summaryId : undefined, "aria-expanded": !collapsed, "aria-controls": contentId, onClick: toggle,
95
106
  // The button's own open look (a filled background) would
96
107
  // read as pressed: the chevron says it.
97
- className: "-my-1 -mr-1.5 aria-expanded:not-hover:bg-transparent", children: _jsx(ChevronDownIcon, { "aria-hidden": "true", className: cn('transition-transform', collapsed && '-rotate-90') }) }))] }))] }), _jsx(CardContent, { id: contentId, hidden: collapsed, "aria-busy": state === 'loading' || undefined, children: error ? (_jsx(ErrorState, { error: error, onRetry: onRetry, size: "compact" })) : state === 'loading' ? (_jsx(WidgetListSkeleton, { rows: skeletonRows })) : state === 'empty' ? (empty ? (_jsx(PartEmpty, { ...empty })) : (_jsx("p", { "data-state": "empty", className: "py-2 type-body text-muted-foreground", children: emptyMessage }))) : (children) })] }) }));
108
+ className: "-my-1 -mr-1.5 aria-expanded:not-hover:bg-transparent", children: _jsx(ChevronDownIcon, { "aria-hidden": "true", className: cn('transition-transform', collapsed && '-rotate-90') }) }))] }))] }), _jsx(CardContent, { id: contentId, hidden: collapsed, "aria-busy": state === 'loading' || undefined, children: error ? (_jsx(ErrorState, { error: error, onRetry: onRetry, size: "compact" })) : state === 'loading' ? (_jsx(WidgetListSkeleton, { rows: skeletonRows })) : state === 'empty' ? (empty ? (_jsx(PartEmpty, { ...empty })) : (_jsx("p", { "data-state": "empty", className: "py-2 type-body text-muted-foreground", children: emptyMessage }))) : value !== undefined || line !== undefined || freshness !== undefined ? (_jsxs("div", { "data-slot": "widget-card-anatomy", className: "flex flex-col gap-1.5", children: [(value !== undefined || line !== undefined) && (_jsxs("div", { className: "flex flex-col gap-0.5", children: [value !== undefined && (_jsx("p", { "data-slot": "widget-card-value", className: "type-numeric text-foreground", children: value })), line !== undefined && _jsx("p", { className: "type-body text-muted-foreground", children: line })] })), children, freshness && _jsx(Freshness, { ...freshness, className: cn('self-start', freshness.className) })] })) : (children) })] }) }));
98
109
  }
99
110
  // A folded card's one value, by state. Loading's skeleton is about one
100
111
  // number wide; an error's dash says "Couldn't load" to a screen reader,
@@ -1,2 +1,6 @@
1
- declare function Skeleton({ className, ...props }: React.ComponentProps<"div">): import("react").JSX.Element;
1
+ import * as React from "react";
2
+ declare function Skeleton({ className, delay, ...props }: React.ComponentProps<"div"> & {
3
+ /** Milliseconds before it shows. 300 unless set; 0 shows it at once. */
4
+ delay?: number;
5
+ }): React.JSX.Element;
2
6
  export { Skeleton };
@@ -1,6 +1,21 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
+ import * as React from "react";
2
3
  import { cn } from "cn";
3
- function Skeleton({ className, ...props }) {
4
- return (_jsx("div", { "data-slot": "skeleton", className: cn("animate-pulse rounded-md bg-muted", className), ...props }));
4
+ // `delay` (4.90, the dialogs and feedback standard D7): nothing shows for
5
+ // the first 300ms, so a fast load just appears instead of flashing grey
6
+ // shapes; a slow one shows its shape after that. It keeps its room while
7
+ // it waits (invisible, not absent), so nothing moves when it shows.
8
+ // `delay={0}` shows it at once. DataTable's loading state, made of these,
9
+ // waits the same way.
10
+ function Skeleton({ className, delay = 300, ...props }) {
11
+ const [shown, setShown] = React.useState(delay <= 0);
12
+ React.useEffect(() => {
13
+ if (delay <= 0)
14
+ return;
15
+ const timer = window.setTimeout(() => setShown(true), delay);
16
+ return () => window.clearTimeout(timer);
17
+ }, [delay]);
18
+ const visible = shown || delay <= 0;
19
+ return (_jsx("div", { "data-slot": "skeleton", "data-shown": visible || undefined, className: cn("animate-pulse rounded-md bg-muted", !visible && "invisible", className), ...props }));
5
20
  }
6
21
  export { Skeleton };
@@ -1,14 +1,37 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
+ // The app's toaster (4.90, the dialogs and feedback standard D5).
3
+ //
4
+ // - Each icon in its tone's `*-text` shade (a green check, a red octagon,
5
+ // an amber triangle, a blue i), through `--toast-icon-*` (styles/
6
+ // index.css: sonner shadows the tokens' own names inside the toaster),
7
+ // which clears 3:1 on the popover surface
8
+ // in every theme and palette, so a success and an error are told apart
9
+ // at a glance. The words stay in the popover's foreground.
10
+ // - Top centre from 48rem up, where the eye already is and clear of the
11
+ // bars at the bottom; at the bottom on a phone, in thumb reach, above
12
+ // whatever is pinned there: `--toast-bottom-offset` (EntityForm's stuck
13
+ // bar sets it on <html>) or else AppShell's bottom bar
14
+ // (`--toast-bottom-base`, styles/index.css).
15
+ // - Toasts last 4 seconds, Undo too. An error from `notify.failed` stays
16
+ // until it's closed.
17
+ //
18
+ // What a toast says and when one shows: `notify` (components/app/notify.ts).
2
19
  import { useTheme } from "next-themes";
3
20
  import { Toaster as Sonner } from "sonner";
4
21
  import { CircleCheckIcon, InfoIcon, TriangleAlertIcon, OctagonXIcon, Loader2Icon } from "lucide-react";
22
+ import { useIsMobile } from "../../hooks/use-mobile.js";
23
+ // sonner's own gap from the window's edge is 24px (16px on its narrow
24
+ // layout); 16px here, plus whatever is pinned to the bottom.
25
+ const EDGE = "16px";
26
+ const BOTTOM = `calc(var(--toast-bottom-offset, var(--toast-bottom-base, 0px)) + ${EDGE})`;
5
27
  const Toaster = ({ ...props }) => {
6
28
  const { theme = "system" } = useTheme();
7
- return (_jsx(Sonner, { theme: theme, className: "toaster group", icons: {
8
- success: (_jsx(CircleCheckIcon, { className: "size-4" })),
9
- info: (_jsx(InfoIcon, { className: "size-4" })),
10
- warning: (_jsx(TriangleAlertIcon, { className: "size-4" })),
11
- error: (_jsx(OctagonXIcon, { className: "size-4" })),
29
+ const phone = useIsMobile();
30
+ return (_jsx(Sonner, { theme: theme, className: "toaster group", position: phone ? "bottom-center" : "top-center", offset: { top: EDGE, bottom: BOTTOM, left: EDGE, right: EDGE }, mobileOffset: { top: EDGE, bottom: BOTTOM, left: EDGE, right: EDGE }, duration: 4000, icons: {
31
+ success: (_jsx(CircleCheckIcon, { className: "size-4 text-(--toast-icon-success)" })),
32
+ info: (_jsx(InfoIcon, { className: "size-4 text-(--toast-icon-info)" })),
33
+ warning: (_jsx(TriangleAlertIcon, { className: "size-4 text-(--toast-icon-warning)" })),
34
+ error: (_jsx(OctagonXIcon, { className: "size-4 text-(--toast-icon-error)" })),
12
35
  loading: (_jsx(Loader2Icon, { className: "size-4 animate-spin" })),
13
36
  }, style: {
14
37
  "--normal-bg": "var(--popover)",
@@ -0,0 +1,29 @@
1
+ type AsyncAction<TArgs extends unknown[], TResult> = (...args: TArgs) => Promise<TResult>;
2
+ export type UseActionOptions<TResult> = {
3
+ /** The lead of the toast when it fails off screen: "Couldn't mark The Long Walk as read". */
4
+ failed?: string;
5
+ /** A toast's words when it finishes after the component was left. No toast when it's on screen. */
6
+ doneAway?: (result: TResult) => string;
7
+ };
8
+ export type ActionOutcome<TResult> = {
9
+ ok: true;
10
+ value: TResult;
11
+ } | {
12
+ ok: false;
13
+ error: string;
14
+ };
15
+ export type ActionState<TArgs extends unknown[] = unknown[], TResult = unknown> = {
16
+ /** Runs it. Never rejects: resolves `{ ok: true, value }`, or `{ ok: false, error }` (also in `error`). */
17
+ run: (...args: TArgs) => Promise<ActionOutcome<TResult>>;
18
+ /** The last run again, with the same arguments. */
19
+ retry: () => Promise<ActionOutcome<TResult>>;
20
+ /** Clears the error. */
21
+ reset: () => void;
22
+ pending: boolean;
23
+ /** Why the last run failed, in the gateway's words; null when it didn't. */
24
+ error: string | null;
25
+ };
26
+ export declare function useAction<TArgs extends unknown[], TResult>(action: AsyncAction<TArgs, TResult> | {
27
+ mutateAsync: AsyncAction<TArgs, TResult>;
28
+ }, { failed, doneAway }?: UseActionOptions<TResult>): ActionState<TArgs, TResult>;
29
+ export {};
@@ -0,0 +1,68 @@
1
+ // One action's run, its pending state and its error, kept beside the
2
+ // button that started it (4.90, the dialogs and feedback standard D6).
3
+ //
4
+ // const markRead = useAction(markReadMutation, { failed: "Couldn't mark The Long Walk as read" })
5
+ // <Button onClick={() => markRead.run(book.id)} disabled={markRead.pending}>…</Button>
6
+ // <ActionError action={markRead} />
7
+ //
8
+ // - `error` is the reason in the gateway's words, for ActionError to draw
9
+ // as a destructive Notice with Try again (`retry`, the last run again).
10
+ // - If the component is gone when it fails (its page was left), the error
11
+ // becomes a toast that stays: "<failed>: <reason>".
12
+ // - `doneAway`: what a toast says when it finishes after the component was
13
+ // left (a job's "Checked 12 · 2 deals"). On screen, the component shows
14
+ // its own result and no toast.
15
+ //
16
+ // Takes a TanStack mutation (its `mutateAsync`) or any async function.
17
+ import { useCallback, useEffect, useRef, useState } from 'react';
18
+ import { toast } from 'sonner';
19
+ import { messageOf } from '../components/app/edit-in-place-store.js';
20
+ import { notify } from '../components/app/notify.js';
21
+ export function useAction(action, { failed, doneAway } = {}) {
22
+ const [pending, setPending] = useState(false);
23
+ const [error, setError] = useState(null);
24
+ const latest = useRef({ action, failed, doneAway });
25
+ const lastArgs = useRef(null);
26
+ const mounted = useRef(true);
27
+ useEffect(() => {
28
+ latest.current = { action, failed, doneAway };
29
+ });
30
+ useEffect(() => {
31
+ mounted.current = true;
32
+ return () => {
33
+ mounted.current = false;
34
+ };
35
+ }, []);
36
+ const run = useCallback(async (...args) => {
37
+ const { action: current } = latest.current;
38
+ const call = typeof current === 'function' ? current : current.mutateAsync;
39
+ lastArgs.current = args;
40
+ setPending(true);
41
+ setError(null);
42
+ try {
43
+ const result = await call(...args);
44
+ if (mounted.current)
45
+ setPending(false);
46
+ else {
47
+ const words = latest.current.doneAway?.(result);
48
+ if (words)
49
+ toast.success(words);
50
+ }
51
+ return { ok: true, value: result };
52
+ }
53
+ catch (thrown) {
54
+ const reason = messageOf(thrown);
55
+ if (mounted.current) {
56
+ setPending(false);
57
+ setError(reason);
58
+ }
59
+ else {
60
+ notify.failed(`${latest.current.failed ?? "Couldn't finish"}: ${reason}`);
61
+ }
62
+ return { ok: false, error: reason };
63
+ }
64
+ }, []);
65
+ const retry = useCallback(() => run(...(lastArgs.current ?? [])), [run]);
66
+ const reset = useCallback(() => setError(null), []);
67
+ return { run, retry, reset, pending, error };
68
+ }
package/dist/index.d.ts CHANGED
@@ -29,6 +29,13 @@ export { usePrinting } from './components/app/print-context.js';
29
29
  export { RecordDialogRoute, RecordLink, type RecordDialogRouteProps, type RecordLinkProps, } from './components/app/record-dialog.js';
30
30
  export { recordDialogState, useNewRecordDialog, useOpenRecord, useRecordDialog, type NewRecordDialogContextValue, type RecordDialogBackground, type RecordDialogContextValue, type RecordDialogState, } from './components/app/record-dialog-context.js';
31
31
  export { FormDialog, type FormDialogProps } from './components/app/form-dialog.js';
32
+ export { DeleteAction, type DeleteActionProps, type DeleteKind } from './components/app/delete-action.js';
33
+ export { notify, doneMessage, pastTense, type NotifyDoneOptions } from './components/app/notify.js';
34
+ export { useAction, type ActionOutcome, type ActionState, type UseActionOptions } from './hooks/use-action.js';
35
+ export { ActionError, type ActionErrorProps } from './components/app/action-error.js';
36
+ export { JobStatus, type JobProgress, type JobStatusProps } from './components/app/job-status.js';
37
+ export { OfflineNotice, type OfflineNoticeProps } from './components/app/offline-notice.js';
38
+ export { useOffline } from './lib/connection.js';
32
39
  export { editInPlace, type EditControlProps, type EditInPlace, type EditInPlaceList, type EditInPlaceListOptions, type EditInPlaceOptions, type EditKind, type EditListAddProps, type EditListItemProps, } from './components/app/edit-in-place.js';
33
40
  export { inPlace, type InPlaceDateConfig, type InPlaceFieldsOptions, type InPlaceLinkConfig, type InPlaceLinkValue, type InPlaceMoneyConfig, type InPlaceMonthDayConfig, type InPlaceNumberConfig, type InPlaceOption, type InPlacePart, type InPlaceRecord, type InPlaceReferenceConfig, type InPlaceSaved, type InPlaceSelectConfig, type InPlaceTextConfig, } from './components/app/edit-in-place-presets.js';
34
41
  export { linkHost, linkHref, linkRule } from './lib/link-href.js';
@@ -84,6 +91,7 @@ export { formatMonthDay, isMonthDay, monthDayProblem, type MonthDay } from './li
84
91
  export { ChoiceCell, LinkCell, LinkOut, NameCell, type ChoiceCellProps, type LinkCellProps, type NameCellProps, } from './components/app/row-edit-cells.js';
85
92
  export { ModuleCard, ModuleStrip, type CategorySlot, type ModuleCardLink, type ModuleCardPlace, type ModuleCardProps, type ModuleStripMobile, type ModuleStripProps, } from './components/app/module-card.js';
86
93
  export { WidgetCard, WidgetCardGroup, WidgetList, WidgetListItem, type WidgetCardGroupProps, type WidgetCardLink, type WidgetCardProps, type WidgetListItemProps, } from './components/app/widget-card.js';
94
+ export { OverviewPage, type OverviewPageProps, type OverviewPart } from './components/app/overview-page.js';
87
95
  export { WidgetLayoutSheet, type WidgetLayoutSheetProps } from './components/app/widget-layout-sheet.js';
88
96
  export { ThemeProvider } from './components/theme-provider.js';
89
97
  export { LoginRoute, type LoginRouteProps } from './routes/login.js';
package/dist/index.js CHANGED
@@ -33,6 +33,15 @@ export { usePrinting } from './components/app/print-context.js';
33
33
  export { RecordDialogRoute, RecordLink, } from './components/app/record-dialog.js';
34
34
  export { recordDialogState, useNewRecordDialog, useOpenRecord, useRecordDialog, } from './components/app/record-dialog-context.js';
35
35
  export { FormDialog } from './components/app/form-dialog.js';
36
+ // The dialogs and feedback standard (4.90): one delete, toasts' words, an
37
+ // action's error beside it, a job's progress, and the offline bar.
38
+ export { DeleteAction } from './components/app/delete-action.js';
39
+ export { notify, doneMessage, pastTense } from './components/app/notify.js';
40
+ export { useAction } from './hooks/use-action.js';
41
+ export { ActionError } from './components/app/action-error.js';
42
+ export { JobStatus } from './components/app/job-status.js';
43
+ export { OfflineNotice } from './components/app/offline-notice.js';
44
+ export { useOffline } from './lib/connection.js';
36
45
  export { editInPlace, } from './components/app/edit-in-place.js';
37
46
  export { inPlace, } from './components/app/edit-in-place-presets.js';
38
47
  export { linkHost, linkHref, linkRule } from './lib/link-href.js';
@@ -86,6 +95,7 @@ export { formatMonthDay, isMonthDay, monthDayProblem } from './lib/month-day.js'
86
95
  export { ChoiceCell, LinkCell, LinkOut, NameCell, } from './components/app/row-edit-cells.js';
87
96
  export { ModuleCard, ModuleStrip, } from './components/app/module-card.js';
88
97
  export { WidgetCard, WidgetCardGroup, WidgetList, WidgetListItem, } from './components/app/widget-card.js';
98
+ export { OverviewPage } from './components/app/overview-page.js';
89
99
  export { WidgetLayoutSheet } from './components/app/widget-layout-sheet.js';
90
100
  export { ThemeProvider } from './components/theme-provider.js';
91
101
  // Screens outside the app shell
@@ -0,0 +1,8 @@
1
+ /** A request got an answer (any status): the server can be reached. */
2
+ export declare function reportAnswered(): void;
3
+ /** A request got no answer at all (fetch rejected): the server can't be reached. */
4
+ export declare function reportUnreachable(): void;
5
+ /** Whether the server can't be reached right now. */
6
+ export declare function isOffline(): boolean;
7
+ /** Whether the server can't be reached right now, re-rendering when that changes. */
8
+ export declare function useOffline(): boolean;
@@ -0,0 +1,49 @@
1
+ // Whether the app can reach its server (4.90, the dialogs and feedback
2
+ // standard D9): what OfflineNotice reads. Offline when the browser says so
3
+ // (`navigator.onLine`, its `offline` event) or when a request couldn't get
4
+ // an answer at all (safeFetch's network failure); online again when the
5
+ // browser says so or when any request gets an answer. One store for the
6
+ // whole app, so the notice shows once however many saves fail.
7
+ import { useSyncExternalStore } from 'react';
8
+ let offline = false;
9
+ const listeners = new Set();
10
+ function set(next) {
11
+ if (next === offline)
12
+ return;
13
+ offline = next;
14
+ for (const listener of listeners)
15
+ listener();
16
+ }
17
+ /** A request got an answer (any status): the server can be reached. */
18
+ export function reportAnswered() {
19
+ set(false);
20
+ }
21
+ /** A request got no answer at all (fetch rejected): the server can't be reached. */
22
+ export function reportUnreachable() {
23
+ set(true);
24
+ }
25
+ let watching = false;
26
+ function watchBrowser() {
27
+ if (watching || typeof window === 'undefined')
28
+ return;
29
+ watching = true;
30
+ if (typeof navigator !== 'undefined' && navigator.onLine === false)
31
+ offline = true;
32
+ window.addEventListener('offline', () => set(true));
33
+ window.addEventListener('online', () => set(false));
34
+ }
35
+ function subscribe(listener) {
36
+ watchBrowser();
37
+ listeners.add(listener);
38
+ return () => {
39
+ listeners.delete(listener);
40
+ };
41
+ }
42
+ /** Whether the server can't be reached right now. */
43
+ export function isOffline() {
44
+ return offline;
45
+ }
46
+ /** Whether the server can't be reached right now, re-rendering when that changes. */
47
+ export function useOffline() {
48
+ return useSyncExternalStore(subscribe, isOffline, () => false);
49
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tristan2828/ui-foundation",
3
- "version": "4.88.0",
3
+ "version": "4.90.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": {
package/styles/index.css CHANGED
@@ -675,3 +675,24 @@
675
675
  --form-bar-safe-area: 0px;
676
676
  }
677
677
  }
678
+
679
+ /* Toasts on a phone sit at the bottom (4.90, ui/sonner.tsx), above
680
+ whatever is pinned there: EntityForm's stuck bar sets
681
+ --toast-bottom-offset itself; failing that, the shell's bottom bar is
682
+ the room to clear, or the phone's safe area. */
683
+ :root {
684
+ --toast-bottom-base: env(safe-area-inset-bottom, 0px);
685
+ /* The tones' text shades, resolved here: sonner's toaster declares its
686
+ own --success-text, --info-text and --warning-text, which would win
687
+ inside it. A custom property's var() resolves where it's declared,
688
+ so these carry the theme's and the palette's values in. */
689
+ --toast-icon-success: var(--success-text);
690
+ --toast-icon-info: var(--info-text);
691
+ --toast-icon-warning: var(--warning-text);
692
+ --toast-icon-error: var(--destructive-text);
693
+ }
694
+ @media (width < 48rem) {
695
+ :root:has([data-slot="app-shell-bottom-bar"]) {
696
+ --toast-bottom-base: calc(var(--spacing) * 16 + 1px + env(safe-area-inset-bottom));
697
+ }
698
+ }