@tristan2828/ui-foundation 4.126.0 → 4.127.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/conventions/docs/add-an-entity.md +118 -34
  2. package/conventions/docs/cell-patterns.md +88 -41
  3. package/conventions/docs/design-language.md +45 -13
  4. package/dist/api/contracts.d.ts +8 -1
  5. package/dist/api/gateway/errors.js +4 -0
  6. package/dist/api/schema.d.ts +9 -0
  7. package/dist/components/app/data-table-tools.d.ts +12 -0
  8. package/dist/components/app/data-table-tools.js +2 -2
  9. package/dist/components/app/data-table.d.ts +2 -1
  10. package/dist/components/app/data-table.js +1 -1
  11. package/dist/components/app/edit-in-place-presets.d.ts +51 -1
  12. package/dist/components/app/edit-in-place-presets.js +30 -0
  13. package/dist/components/app/edit-in-place-store.d.ts +31 -4
  14. package/dist/components/app/edit-in-place-store.js +59 -11
  15. package/dist/components/app/edit-in-place.d.ts +11 -0
  16. package/dist/components/app/editable-value.js +43 -8
  17. package/dist/components/app/entity-view.js +5 -1
  18. package/dist/components/app/equal-items.d.ts +32 -6
  19. package/dist/components/app/equal-items.js +59 -8
  20. package/dist/components/app/error-state.js +1 -0
  21. package/dist/components/app/milkdown-editor.js +3 -2
  22. package/dist/components/app/pill-filter.d.ts +16 -0
  23. package/dist/components/app/pill-filter.js +22 -1
  24. package/dist/components/app/rating-input.d.ts +22 -0
  25. package/dist/components/app/rating-input.js +65 -0
  26. package/dist/components/app/rating-score.d.ts +2 -1
  27. package/dist/components/app/rating-score.js +2 -6
  28. package/dist/components/app/rich-text-editor.d.ts +4 -2
  29. package/dist/components/app/rich-text-editor.js +3 -2
  30. package/dist/components/app/rich-text-keyboard-bar.js +3 -2
  31. package/dist/components/app/rich-text-toolbar.js +1 -1
  32. package/dist/components/app/rich-text-tools-bar.d.ts +3 -1
  33. package/dist/components/app/rich-text-tools-bar.js +2 -2
  34. package/dist/hooks/use-record-update.d.ts +13 -1
  35. package/dist/hooks/use-record-update.js +17 -3
  36. package/dist/index.d.ts +4 -2
  37. package/dist/index.js +5 -0
  38. package/dist/lib/markdown-merge.d.ts +12 -0
  39. package/dist/lib/markdown-merge.js +90 -0
  40. package/dist/lib/rating-glyphs.d.ts +3 -0
  41. package/dist/lib/rating-glyphs.js +7 -0
  42. package/openapi/foundation.yaml +12 -0
  43. package/package.json +1 -1
@@ -3,30 +3,31 @@
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 45–67
7
- - [Before anything: the entity plan](#before-anything-the-entity-plan) · lines 69–880
8
- - Step 1: Add `<Entity>` to `openapi.yaml` · lines 111–118
9
- - Step 2: `npm run gen:api` · lines 119–120
10
- - Step 3: Add gateway tests in `tests/gateway/<entity>.test.ts`, derived from the spec · lines 121–132
11
- - Step 4: Add MSW handlers in `src/mocks/<entity>.ts` · lines 133–142
12
- - Step 5: Add a gateway module in `src/api/gateway/<entity>.ts` · lines 143–149
13
- - Step 6: Copy the reference files, one for one, not just the two screens · lines 150–758
14
- - Step 7: Register routes · lines 759–774
15
- - Step 8: Add Playwright specs for all three screens · lines 775–862
16
- - Step 9: Register the nav entry and route names · lines 863–877
17
- - Step 10: `npm run verify`. · lines 878–880
18
- - [How a list opens a record](#how-a-list-opens-a-record) · lines 882–1351
19
- - [The record view](#the-record-view) · lines 1035–1192
20
- - [Forms](#forms) · lines 1194–1265
21
- - [Dialogs](#dialogs) · lines 1267–1298
22
- - [Toasts and feedback](#toasts-and-feedback) · lines 1300–1351
23
- - [What not to copy](#what-not-to-copy) · lines 1353–1386
24
- - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 1388–1405
25
- - [Deleting](#deleting) · lines 1407–1438
26
- - [Fields only a script writes](#fields-only-a-script-writes) · lines 1440–1461
27
- - [Searching one part of the app](#searching-one-part-of-the-app) · lines 1463–1472
28
- - [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1475–1517
29
- - [Behind a sign-in proxy](#behind-a-sign-in-proxy) · lines 1519–1555
6
+ - [The reference files](#the-reference-files) · lines 46–68
7
+ - [Before anything: the entity plan](#before-anything-the-entity-plan) · lines 70–881
8
+ - Step 1: Add `<Entity>` to `openapi.yaml` · lines 112–119
9
+ - Step 2: `npm run gen:api` · lines 120–121
10
+ - Step 3: Add gateway tests in `tests/gateway/<entity>.test.ts`, derived from the spec · lines 122–133
11
+ - Step 4: Add MSW handlers in `src/mocks/<entity>.ts` · lines 134–143
12
+ - Step 5: Add a gateway module in `src/api/gateway/<entity>.ts` · lines 144–150
13
+ - Step 6: Copy the reference files, one for one, not just the two screens · lines 151–759
14
+ - Step 7: Register routes · lines 760–775
15
+ - Step 8: Add Playwright specs for all three screens · lines 776–863
16
+ - Step 9: Register the nav entry and route names · lines 864–878
17
+ - Step 10: `npm run verify`. · lines 879–881
18
+ - [How a list opens a record](#how-a-list-opens-a-record) · lines 883–1385
19
+ - [The record view](#the-record-view) · lines 1036–1215
20
+ - [Forms](#forms) · lines 1217–1299
21
+ - [Dialogs](#dialogs) · lines 1301–1332
22
+ - [Toasts and feedback](#toasts-and-feedback) · lines 1334–1385
23
+ - [What not to copy](#what-not-to-copy) · lines 1387–1422
24
+ - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 1424–1441
25
+ - [Saves that don't overwrite](#saves-that-dont-overwrite) · lines 1443–1489
26
+ - [Deleting](#deleting) · lines 1491–1522
27
+ - [Fields only a script writes](#fields-only-a-script-writes) · lines 1524–1545
28
+ - [Searching one part of the app](#searching-one-part-of-the-app) · lines 1547–1556
29
+ - [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1559–1601
30
+ - [Behind a sign-in proxy](#behind-a-sign-in-proxy) · lines 1603–1639
30
31
 
31
32
  <!-- /index -->
32
33
 
@@ -650,8 +651,8 @@ is a filled-in example while the Widgets demo is still here).
650
651
  a number or integer too), `long-text` (Markdown, `RichTextEditor`
651
652
  with `onProblem={props.onProblem}`; notes are `inline: true` by
652
653
  default, the control passing `inline={props.inline}` and
653
- `toolbar={props.inline ? 'floating' : true}` with no `autoFocus`,
654
- as Widget's Description does; a short one opened by a click is
654
+ `toolbar="floating"` (on the form too: "Forms" below) with no
655
+ `autoFocus`, as Widget's Description does; a short one opened by a click is
655
656
  `autosave: true` with `autoFocus`), `choice` (a
656
657
  select or a single reference: its list opens with the field,
657
658
  `defaultOpen`, non-modal, `onChange={(v) => props.commit(v)}`,
@@ -1141,18 +1142,38 @@ A record uses the parts it has, in this order:
1141
1142
  component or a node) before the label, in the muted tone. With
1142
1143
  `tone` (4.123: `success`, `warning`, `info`, `destructive`) a label
1143
1144
  that is a state ("Pinned", "Overdue") is the outline badge in that
1144
- tone, its icon too; the word still says it.
1145
+ tone, its icon too; the word still says it. A flag that's set reads
1146
+ at a glance this way, edited in place as any badges fact (its `edit`
1147
+ picks the flags; at rest each is drawn in its tone), and the tone
1148
+ comes along where the rail folds into Details on a phone. Untoned
1149
+ items are the plain outline. Give each state its tone from the design
1150
+ language's badge tones, never a colour of the app's own:
1151
+
1152
+ ```tsx
1153
+ const FLAG_BADGE = { blocked: { label: 'Blocked', tone: 'destructive' }, needsYou: { label: 'Needs you', tone: 'warning' } } as const
1154
+ { label: 'Flags', kind: 'badges', items: record.flags.map((flag) => FLAG_BADGE[flag]), emptyLabel: 'None',
1155
+ edit: editInPlace({ kind: 'multi', value: record.flags, save: (flags) => save({ flags }), control: (props) => <MultiPick options={FLAGS} value={props.value} onValueChange={props.onChange} aria-label={props.label} aria-describedby={props.describedBy} /> }) },
1156
+ ```
1145
1157
  - **A rating** (4.117) is `kind: 'rating'`, drawn as the list's cells
1146
1158
  draw it, never as "4 of 5" text: stars (the default) or hearts for a
1147
1159
  score out of `max` (5), the step bar for a quality level. `null` is
1148
- empty (its `emptyLabel`). Edited in place with `inPlace.select`:
1160
+ empty (its `emptyLabel`). A score the person gives (my rating) is
1161
+ edited in place with **`inPlace.rating`** (4.127): the stars are then
1162
+ the value, a click on one saves it, a second press on the set one
1163
+ saves `null`, and an empty one shows five empty stars to click rather
1164
+ than its `emptyLabel`. A score that isn't the person's to set (a
1165
+ critics' average) stays read-only:
1149
1166
 
1150
1167
  ```tsx
1151
- { label: 'My Rating', kind: 'rating', look: 'hearts', value: record.rating, emptyLabel: 'Not rated',
1152
- edit: inPlace.select({ value: record.rating, options: [1, 2, 3, 4, 5].map((n) => ({ value: n, label: `${n} of 5` })),
1153
- emptyLabel: 'Not rated', save: (rating) => save({ rating }) }) },
1168
+ { label: 'My Rating', kind: 'rating', value: record.rating,
1169
+ edit: inPlace.rating({ value: record.rating, save: (rating) => save({ rating }) }) },
1170
+ { label: 'Loved', kind: 'rating', look: 'hearts', value: record.loved,
1171
+ edit: inPlace.rating({ value: record.loved, glyph: 'heart', save: (loved) => save({ loved }) }) },
1154
1172
  { label: 'Quality', kind: 'rating', look: 'bar', value: QUALITY[record.quality].value, word: QUALITY[record.quality].word },
1155
1173
  ```
1174
+
1175
+ A quality level drawn as the step bar is an enum, not a score: edit
1176
+ it with `inPlace.select` over its levels.
1156
1177
  - **A yes/no** (4.120) is `kind: 'switch'`, a switch toggled where it
1157
1178
  is, named by the label, never a two-choice select. Return the save's
1158
1179
  promise: the switch shows the new state while it runs and goes back
@@ -1180,8 +1201,10 @@ A record uses the parts it has, in this order:
1180
1201
  handful of options) are one `EqualItems` (4.93) in a section, one look
1181
1202
  per set: `cards` for little to say about each, `table` for things
1182
1203
  compared on the same values, `featured` when one is current or best,
1183
- `panels` when each has several details (design-language.md "A few
1184
- equal things"). Never hand-made cards or a grid of their own. An item
1204
+ `panels` when each has several details, `stepper` (4.127) for a
1205
+ sequence with a current step whose items are looked at one at a time
1206
+ (numbered steps picking the one panel shown; design-language.md "A few
1207
+ equal things"). Never hand-made cards, a grid or a stepper of their own. An item
1185
1208
  edited or removed on its own carries its editor as `content` and its
1186
1209
  Edit and Remove as `actions` (4.94), `wide` while the editor is open;
1187
1210
  never an editor put in a field's value.
@@ -1215,6 +1238,17 @@ shape (4.85):
1215
1238
  a status choice gives each option its `kind`, so its icons are
1216
1239
  `StatusMark`'s in their colours (below).
1217
1240
  - **Order:** required first, the status next, long text last.
1241
+ - **Notes** (a Markdown long text: notes, a description, a body) are a
1242
+ `RichTextEditor` with `toolbar="floating"` on the form as in place
1243
+ (4.127): no bar above the text, the formats over selected words, every
1244
+ block in the slash menu ("/"), and Image, Full Screen and (on a narrow
1245
+ or touch screen) Indent and Outdent on the small "Editor tools" strip
1246
+ while it has focus. On a phone the row pinned to the keyboard carries
1247
+ them, Image included, at 40px. Give it the app's `upload` (the one
1248
+ `ImageField` takes) for the Image button and for pasted and dropped
1249
+ pictures, which go in as `![](url)`; a refused or failed picture says
1250
+ why in a toast. Without `upload` there's no Image button, and a picture
1251
+ can't go in at all.
1218
1252
  - **Required:** `<FieldLabel required>` (an asterisk, and `aria-required`
1219
1253
  on the control it names). Nothing on an optional field: never
1220
1254
  "(optional)".
@@ -1375,7 +1409,9 @@ sight.** What happened where the person is looking says so there.
1375
1409
  opens on with `defaultView`, and put what no control can show (a
1376
1410
  computed "overdue") in the view's `rule` (cell-patterns.md "Saved views
1377
1411
  are pills"). The default view's `sort` is its plain address's too
1378
- (4.123): pressing it writes no `?sort=`, and the rows keep that order.
1412
+ (4.123): pressing it writes no `?sort=`, and the rows keep that order. A view the plan says
1413
+ shows a count gets `count` from the app's own query, passed to
1414
+ `DataTable`'s `views` (cell-patterns.md "A view can carry a count").
1379
1415
  - `src/api/gateway/widgets.ts`, `src/mocks/data.ts`, `src/mocks/handlers.ts`
1380
1416
  are demo-domain content — write the entity's own versions rather than
1381
1417
  adapting these by find-and-replace.
@@ -1404,6 +1440,54 @@ asyncio is a `MissingGreenlet` and a 500.
1404
1440
  a `User(...)` in for `get_current_user` in an override: a detached user
1405
1441
  never expires, so the test passes and the route fails live.
1406
1442
 
1443
+ ## Saves that don't overwrite
1444
+
1445
+ A record edited in more than one place (a laptop tab, a phone, an AI chat
1446
+ through MCP) needs a version, or the last save wins: a phone left open on
1447
+ a note, typed into after the laptop changed it, replaces the laptop's
1448
+ work. The fix is optimistic concurrency, the same for every entity:
1449
+
1450
+ - **The record carries its version: `updatedAt`** (`updated_at`, a
1451
+ `timestamptz` every write sets with `foundation_backend.versions.touch()`,
1452
+ never null, commented in its migration). Not a counter or an ETag: most
1453
+ tables already have one, a person or an AI reading the row knows what it
1454
+ means, and it rides in the JSON body, where an MCP tool call can send it
1455
+ back too (an `If-Match` header can't reach a chat). It's compared for
1456
+ equality, never ordered, so clocks don't matter.
1457
+ - **An update may send the version it was built on: `baseUpdatedAt`**, an
1458
+ optional field of `<Entity>Update` that isn't a column. The router locks
1459
+ the row, calls `check_version(record.updated_at, base)` before changing
1460
+ anything, and sets `updated_at = touch()`. A version that's no longer the
1461
+ record's is a **409** (`ConflictError`, `VersionConflict`): nothing is
1462
+ written. No version sent: no check, so older clients and scripts keep
1463
+ working. `responses=VERSIONED_UPDATE_RESPONSES` documents it, and the
1464
+ PATCH in `openapi.yaml` lists `"409": ConflictError`.
1465
+ - **The client sends it with every single-field save:** `useRecordUpdate`'s
1466
+ `withVersion: (update, record) => ({ ...update, baseUpdatedAt:
1467
+ record.updatedAt })`. The record it gets is the latest the server
1468
+ returned (a burst of saves chains through each answer's version), so a
1469
+ save never conflicts with the tab's own. The gateway needs no change:
1470
+ `toAppError` makes the 409 an `AppError` of kind `conflict`, and
1471
+ `useRecordUpdate` refetches the record.
1472
+ - **What the person sees.** A quick action's toast gives the 409's reason,
1473
+ and the refetch shows what the other writer saved. A field edited in
1474
+ place asks: "This changed elsewhere", with **Keep Mine** and **Show
1475
+ Saved**, and nothing saves until a pick. Long text's Keep Mine keeps
1476
+ both, block by block (`rebaseMarkdown`); when both changed the same
1477
+ paragraph it says so, and only a second Keep Mine replaces theirs. Any
1478
+ other field's Keep Mine saves what's typed over theirs. An `editInPlace`
1479
+ takes its own `rebase`, or `rebase: false`.
1480
+ - **A chat** gets the same check through the entity's `McpEntity.update`:
1481
+ the `update` tool tells it to send the `updatedAt` it read as
1482
+ `baseUpdatedAt`, and a 409 comes back as a refusal that says to fetch
1483
+ the record again. `edit_text` is safe without it (its `old` text must
1484
+ still be there).
1485
+ - **Copy:** `template/backend/app/routers/widgets.py` (`update_widget`),
1486
+ migration `0017_widget_updated_at.py`, `WidgetOut.updated_at` and
1487
+ `WidgetUpdate.base_updated_at` in `app/schemas.py`, the PATCH mock in
1488
+ `src/mocks/handlers.ts`, `withVersion` in `use-widgets.ts`, and the
1489
+ "two writers" specs in `e2e/widget-edit-in-place.spec.ts`.
1490
+
1407
1491
  ## Deleting
1408
1492
 
1409
1493
  The plan's "Deleting" line says which of three. The Widget reference is the
@@ -13,38 +13,38 @@
13
13
  - [6. Multi-value enum, clustered](#6-multi-value-enum-clustered) · lines 299–311
14
14
  - [7. Link as an outline button](#7-link-as-an-outline-button) · lines 313–334
15
15
  - [8. Date, relative](#8-date-relative) · lines 336–373
16
- - [9. Ordinal scale (bounded integer)](#9-ordinal-scale-bounded-integer) · lines 375–434
17
- - [Three variants the package draws: a step bar, a star and a score](#three-variants-the-package-draws-a-step-bar-a-star-and-a-score) · lines 393–434
18
- - [10. Summary in the cell, detail in a popover](#10-summary-in-the-cell-detail-in-a-popover) · lines 436–486
19
- - [A second example: what a row depends on](#a-second-example-what-a-row-depends-on) · lines 454–486
20
- - [11. Number or currency — Unproven](#11-number-or-currency--unproven) · lines 488–528
21
- - [12. Boolean](#12-boolean) · lines 530–560
22
- - [13. Progress bar — Unproven](#13-progress-bar--unproven) · lines 562–598
23
- - [The compact form: `ProgressRing`](#the-compact-form-progressring) · lines 582–598
24
- - [14. Avatar and name — Unproven](#14-avatar-and-name--unproven) · lines 600–617
25
- - [15. Yes/no you flip in the row](#15-yesno-you-flip-in-the-row) · lines 619–728
26
- - [A variant: a pressed icon inside another value's cell](#a-variant-a-pressed-icon-inside-another-values-cell) · lines 645–728
27
- - [16. Title linking to the record's view](#16-title-linking-to-the-records-view) · lines 730–776
28
- - [17. Quick action on the view](#17-quick-action-on-the-view) · lines 778–851
29
- - [18. Editable value](#18-editable-value) · lines 853–1597
30
- - [Presets: one line per field](#presets-one-line-per-field) · lines 1229–1297
31
- - [Several fields edited as one](#several-fields-edited-as-one) · lines 1299–1335
32
- - [A link and its label](#a-link-and-its-label) · lines 1337–1361
33
- - [A list of sub-items](#a-list-of-sub-items) · lines 1363–1496
34
- - [In a table's rows](#in-a-tables-rows) · lines 1498–1583
35
- - [A table of a few short columns: `width="content"`](#a-table-of-a-few-short-columns-widthcontent) · lines 1585–1597
36
- - [19. Stage circle for an ordered status](#19-stage-circle-for-an-ordered-status) · lines 1599–1665
37
- - [20. Count linking to the related records](#20-count-linking-to-the-related-records) · lines 1667–1731
38
- - [21. Rows grouped under headings, and a pill filter](#21-rows-grouped-under-headings-and-a-pill-filter) · lines 1733–1831
39
- - [22. A highlighted row, and rows that are done](#22-a-highlighted-row-and-rows-that-are-done) · lines 1833–1862
40
- - [24. A list's rows: hover, lines, rows per page](#24-a-lists-rows-hover-lines-rows-per-page) · lines 1864–1902
41
- - [23. A Group menu, and a record read beside the list](#23-a-group-menu-and-a-record-read-beside-the-list) · lines 1904–1980
42
- - [24. A stored colour beside its name](#24-a-stored-colour-beside-its-name) · lines 1982–2068
43
- - [Picking one on a form: `ColorField`](#picking-one-on-a-form-colorfield) · lines 2007–2068
44
- - [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 2070–2295
45
- - [The framed look, and sibling lists beside the title](#the-framed-look-and-sibling-lists-beside-the-title) · lines 2224–2295
46
- - [26. A record's related list, capped](#26-a-records-related-list-capped) · lines 2297–2333
47
- - [27. A repeat and its next time](#27-a-repeat-and-its-next-time) · lines 2335–2384
16
+ - [9. Ordinal scale (bounded integer)](#9-ordinal-scale-bounded-integer) · lines 375–453
17
+ - [Three variants the package draws: a step bar, a star and a score](#three-variants-the-package-draws-a-step-bar-a-star-and-a-score) · lines 393–453
18
+ - [10. Summary in the cell, detail in a popover](#10-summary-in-the-cell-detail-in-a-popover) · lines 455–505
19
+ - [A second example: what a row depends on](#a-second-example-what-a-row-depends-on) · lines 473–505
20
+ - [11. Number or currency — Unproven](#11-number-or-currency--unproven) · lines 507–547
21
+ - [12. Boolean](#12-boolean) · lines 549–579
22
+ - [13. Progress bar — Unproven](#13-progress-bar--unproven) · lines 581–617
23
+ - [The compact form: `ProgressRing`](#the-compact-form-progressring) · lines 601–617
24
+ - [14. Avatar and name — Unproven](#14-avatar-and-name--unproven) · lines 619–636
25
+ - [15. Yes/no you flip in the row](#15-yesno-you-flip-in-the-row) · lines 638–747
26
+ - [A variant: a pressed icon inside another value's cell](#a-variant-a-pressed-icon-inside-another-values-cell) · lines 664–747
27
+ - [16. Title linking to the record's view](#16-title-linking-to-the-records-view) · lines 749–795
28
+ - [17. Quick action on the view](#17-quick-action-on-the-view) · lines 797–870
29
+ - [18. Editable value](#18-editable-value) · lines 872–1628
30
+ - [Presets: one line per field](#presets-one-line-per-field) · lines 1257–1328
31
+ - [Several fields edited as one](#several-fields-edited-as-one) · lines 1330–1366
32
+ - [A link and its label](#a-link-and-its-label) · lines 1368–1392
33
+ - [A list of sub-items](#a-list-of-sub-items) · lines 1394–1527
34
+ - [In a table's rows](#in-a-tables-rows) · lines 1529–1614
35
+ - [A table of a few short columns: `width="content"`](#a-table-of-a-few-short-columns-widthcontent) · lines 1616–1628
36
+ - [19. Stage circle for an ordered status](#19-stage-circle-for-an-ordered-status) · lines 1630–1696
37
+ - [20. Count linking to the related records](#20-count-linking-to-the-related-records) · lines 1698–1762
38
+ - [21. Rows grouped under headings, and a pill filter](#21-rows-grouped-under-headings-and-a-pill-filter) · lines 1764–1862
39
+ - [22. A highlighted row, and rows that are done](#22-a-highlighted-row-and-rows-that-are-done) · lines 1864–1893
40
+ - [24. A list's rows: hover, lines, rows per page](#24-a-lists-rows-hover-lines-rows-per-page) · lines 1895–1933
41
+ - [23. A Group menu, and a record read beside the list](#23-a-group-menu-and-a-record-read-beside-the-list) · lines 1935–2011
42
+ - [24. A stored colour beside its name](#24-a-stored-colour-beside-its-name) · lines 2013–2099
43
+ - [Picking one on a form: `ColorField`](#picking-one-on-a-form-colorfield) · lines 2038–2099
44
+ - [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 2101–2342
45
+ - [The framed look, and sibling lists beside the title](#the-framed-look-and-sibling-lists-beside-the-title) · lines 2271–2342
46
+ - [26. A record's related list, capped](#26-a-records-related-list-capped) · lines 2344–2380
47
+ - [27. A repeat and its next time](#27-a-repeat-and-its-next-time) · lines 2382–2431
48
48
 
49
49
  <!-- /index -->
50
50
 
@@ -430,6 +430,25 @@ themes. Each is one image to a screen reader, named in words.
430
430
  {row.rating === null ? <Muted>Not rated</Muted> : <RatingScore value={row.rating} glyph="heart" />}
431
431
  ```
432
432
 
433
+ - **`RatingInput`, the same score set by a click** (4.127): RatingScore's
434
+ glyphs and tokens as a radio group named by `label`, one radio per
435
+ star ("2 of 5"). A click (or Space) sets a star, a click on the set one
436
+ clears it to `null`, the arrow keys move and set it, a mouse's hover
437
+ previews it. 24px targets on a laptop, 44px on a touch screen.
438
+ `onChange(value, source)`: `source` is `'pointer'` or `'keyboard'`.
439
+ On a form it's the field's control; on a record or in a row it's
440
+ `inPlace.rating` ("Presets" below), so a cell sets its row's score where
441
+ it's drawn:
442
+
443
+ ```tsx
444
+ <RatingInput label="Taste" value={value} onChange={(next) => setValue(next)} />
445
+ // A table's cell: inside DataTable, which runs editing in place.
446
+ cell: ({ row }) => (
447
+ <EditableValue layout="inline" label={`Rating of ${row.original.name}`}
448
+ edit={inPlace.rating({ value: row.original.rating, save: (rating) => save(row.original.id, { rating }) })} />
449
+ ),
450
+ ```
451
+
433
452
  - All three draw in `foreground`. Tone one only as pattern 5 would (a `*-text`
434
453
  class in `className`), never by band alone.
435
454
 
@@ -1050,9 +1069,15 @@ nobody has to click away to save notes. Opt in per field:
1050
1069
  query refetches): with nothing typed waiting, the note shows the new
1051
1070
  text at once, even with the caret in it, which keeps its paragraph.
1052
1071
  Under unsaved typing nothing saves over it: the line says it "changed
1053
- elsewhere", with **Keep Mine** (save what's typed over it) and **Show
1054
- Saved** (drop what's typed). The server sending back what it was sent,
1055
- even trimmed, is not a change: the editor keeps its undo.
1072
+ elsewhere", with **Keep Mine** and **Show Saved** (drop what's typed).
1073
+ Keep Mine keeps both, block by block: what's typed is laid onto the
1074
+ other writer's text and the editor shows the result as it saves; when
1075
+ both changed the same paragraph it says so, and a second Keep Mine
1076
+ replaces theirs. A save the server refuses because another writer saved
1077
+ first (a 409, the record's version check: add-an-entity.md "Saves that
1078
+ don't overwrite") asks the same way, never a plain failure to retry.
1079
+ The server sending back what it was sent, even trimmed, is not a
1080
+ change: the editor keeps its undo.
1056
1081
  - **Leaving mid-save:** a field that leaves the view while a save is in
1057
1082
  flight (a session ending, a parent that stops showing it) still sends
1058
1083
  what was typed after that save started.
@@ -1100,7 +1125,8 @@ but drops the bar above the text. An empty one shows the editor's
1100
1125
  `placeholder` (say "or type / for blocks" in it), not the view's "Not
1101
1126
  set". It saves like any always-editable value (a pause after typing,
1102
1127
  leaving the page saves first) and is otherwise the same: on the form the
1103
- control is the boxed editor with its fixed toolbar.
1128
+ control is the boxed editor, with the floating toolbar too (4.127,
1129
+ [add-an-entity.md "Forms"](add-an-entity.md#forms)).
1104
1130
 
1105
1131
  ```tsx
1106
1132
  notes: editInPlace({
@@ -1198,11 +1224,12 @@ const price = editInPlace({
1198
1224
  button fills the window with the field (Esc leaves; nothing is lost or
1199
1225
  saved by it), and on a touch screen or under 768px it carries Indent
1200
1226
  and Outdent for list items, where there is no Tab. A field with only the
1201
- floating toolbar (`inline` notes) gets the same two in a small "Editor
1202
- tools" strip over its corner while it has focus. On a touch screen the
1227
+ floating toolbar (`inline` notes, and notes on a form) gets the same
1228
+ two in a small "Editor tools" strip over its corner while it has focus,
1229
+ with the Image button too when the editor has `upload` (4.127). On a touch screen the
1203
1230
  toolbar is instead one row pinned to the top of the keyboard while the
1204
1231
  field has focus (Aa for every format, in the keyboard's place; the list
1205
- buttons, Insert and Undo; with words selected, their formats first, and
1232
+ buttons, Insert, Image (with `upload`) and Undo; with words selected, their formats first, and
1206
1233
  no floating bar under the system's Copy bar), and the checkbox, the
1207
1234
  table grips, the fold button and the callout icon take a 40px tap. A new checklist item
1208
1235
  shows a "To-do" placeholder and the caret until you type. `[] ` (or
@@ -1214,7 +1241,8 @@ const price = editInPlace({
1214
1241
  the floating one and the slash menu without the bar above (an `inline`
1215
1242
  field's look). Images in the text (`![alt](url)`) show; give it the
1216
1243
  app's `upload` (the same one `ImageField` takes) and an image pasted,
1217
- dropped or picked with the toolbar's Image button is uploaded and goes
1244
+ dropped or picked with an Image button (the fixed toolbar's, the tools
1245
+ strip's, the phone's row) is uploaded and goes
1218
1246
  in as `![](url)`, a placeholder showing meanwhile (never saved), a
1219
1247
  refusal or failure in a toast. No `upload`, no file handling at all.
1220
1248
  - **The save is the single-field save** (`useRecordUpdate` with
@@ -1248,6 +1276,7 @@ fields: [
1248
1276
  { label: 'Priority', edit: inPlace.select({ value: project.priority, options: PRIORITY_OPTIONS,
1249
1277
  render: (priority, label) => <Badge variant={PRIORITY_BADGE[priority]}>{label}</Badge>,
1250
1278
  save: (priority) => save({ priority }) }) },
1279
+ { label: 'My Rating', edit: inPlace.rating({ value: project.rating, save: (rating) => save({ rating }) }) },
1251
1280
  { label: 'Category', edit: inPlace.reference({ value: project.categoryId, label: categoryName,
1252
1281
  search: (text) => searchCategories(text), onCreate: (name) => openNewCategory(name),
1253
1282
  save: (categoryId) => save({ categoryId }) }) },
@@ -1271,12 +1300,14 @@ fields: [
1271
1300
  | `monthDay` | `Mar 14` (`format`, `locale`); a stored value that isn't a day, as written | `'MM-DD'`, no year; February 29 is a day; Clear is `null` | Clear when `required`, a day the month can't have ("February has 29 days") |
1272
1301
  | `select` | the option's label, or its `render` (a badge) | the option's value; "Not set" is `null` | "Not set" isn't offered when `required` |
1273
1302
  | `choice` | as `select` | as `select`, drawn as ChoiceButtons (two to four short options); pressing the picked one again is `null` | as `select` |
1303
+ | `rating` | `RatingScore` (`max`, `glyph`); always the stars (`RatingInput`), with no click to open | the star's number, at once on a click; an arrow's a pause after the last; pressing the set star again is `null` | clearing when `required` (the press does nothing) |
1274
1304
  | `reference` | the record's `label` (the view's lookup by id) | the picked record's id | "Not set" isn't offered when `required` |
1275
1305
 
1276
1306
  - **They save the way their kind does** (the table above): `text`,
1277
1307
  `number`, `money` and a typed `date` on Enter or leaving them, a day
1278
1308
  picked in the date's calendar, `monthDay`, `select`, `choice` and
1279
- `reference` on the pick (a list opens with the field).
1309
+ `reference` on the pick (a list opens with the field), `rating` on a
1310
+ click of a star (it's always open: the stars are the value).
1280
1311
  `required: true` types the save without `null`.
1281
1312
  - **`reference` searches through the app.** The package knows no
1282
1313
  endpoint: `search(text)` is the app's (its gateway's search by name,
@@ -2120,6 +2151,22 @@ const { filters, multiFilters, setFilter, setFilters, setMultiFilter, activeView
2120
2151
  once the filters move off every view. Under 48rem they stay on one line
2121
2152
  that scrolls sideways. Replaces a hand-written row of view buttons; a
2122
2153
  Deleted view goes in ListHeader's ⋯ menu as Show Deleted instead.
2154
+ - **A view can carry a count** (4.127): `count` on the view you pass
2155
+ `DataTable`, shown after its label as "Needs a Look · 3" and read as
2156
+ "Needs a Look, 3". The app counts with its own query (the list's
2157
+ `total` under that view's filters, or a count endpoint); the table
2158
+ computes nothing. null, undefined and 0 show no count, as the
2159
+ sidebar's counts and a record's tab counts don't, and past 99 it reads
2160
+ "99+". Count only views that ask you to act (Needs a Look, To Fill
2161
+ In), not All. Give the view the key from the first render, `undefined`
2162
+ while the query loads: a view with the key keeps room for a two-digit
2163
+ count, so no pill moves when it arrives, on a phone's scrolling row
2164
+ too.
2165
+
2166
+ ```tsx
2167
+ const { data: needsLook } = useNewsSourcesQuery({ ...VIEWS.look.filters, pageSize: 1 })
2168
+ <DataTable views={{ ...VIEWS, look: { ...VIEWS.look, count: needsLook?.total } }} … />
2169
+ ```
2123
2170
  - **Views fill the filters** (4.105), so the bar always says why rows are
2124
2171
  hidden:
2125
2172
  - A view's `filters` and `multiFilters` are what the bar's controls
@@ -30,14 +30,14 @@
30
30
  - [A list as cards](#a-list-as-cards) · lines 1308–1354
31
31
  - [Key numbers on a record](#key-numbers-on-a-record) · lines 1356–1392
32
32
  - [Parts of the page standards](#parts-of-the-page-standards) · lines 1394–1464
33
- - [A few equal things](#a-few-equal-things) · lines 1466–1550
34
- - [An overview page](#an-overview-page) · lines 1552–1623
35
- - [A record's header and empty values](#a-records-header-and-empty-values) · lines 1624–1690
36
- - [A record's tabs, mark and facts](#a-records-tabs-mark-and-facts) · lines 1692–1816
37
- - [Picking at random](#picking-at-random) · lines 1818–1849
38
- - [Filling in what's missing](#filling-in-whats-missing) · lines 1851–1918
39
- - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1920–1945
40
- - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 1947–2043
33
+ - [A few equal things](#a-few-equal-things) · lines 1466–1569
34
+ - [An overview page](#an-overview-page) · lines 1571–1642
35
+ - [A record's header and empty values](#a-records-header-and-empty-values) · lines 1643–1709
36
+ - [A record's tabs, mark and facts](#a-records-tabs-mark-and-facts) · lines 1711–1848
37
+ - [Picking at random](#picking-at-random) · lines 1850–1881
38
+ - [Filling in what's missing](#filling-in-whats-missing) · lines 1883–1950
39
+ - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1952–1977
40
+ - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 1979–2075
41
41
 
42
42
  <!-- /index -->
43
43
 
@@ -1467,8 +1467,8 @@ Every one is measured with axe and the glyph check in both themes
1467
1467
 
1468
1468
  `EqualItems` (4.93, record standard R10): a small set of equal, related
1469
1469
  things inside a record (a plan's phases, the stores a price is compared
1470
- at, a handful of options), one data shape in four looks. A record picks
1471
- one look per set; a fifth is asked for first.
1470
+ at, a handful of options), one data shape in five looks. A record picks
1471
+ one look per set; a sixth is asked for first.
1472
1472
 
1473
1473
  ```tsx
1474
1474
  <EqualItems
@@ -1490,6 +1490,7 @@ one look per set; a fifth is asked for first.
1490
1490
  | `table` | one compact row per item, the title as its row header, a column per field label (first-seen order), a dash where an item has none; scrolls sideways in its own box on a phone | things compared on the same values (a price at each store) |
1491
1491
  | `featured` | the item `featuredId` names in full, in a card with the accent border, then the rest as toggles that open in place | one is current or best (a program's phases) |
1492
1492
  | `panels` | a panel per item side by side, its title and state in a muted band, every detail labelled above its value; stacked on a phone | each has several details and must read as separate |
1493
+ | `stepper` (4.127) | a row of numbered steps joined by a line, each done, current or upcoming, picking the one item whose panel shows under it; opens on the current step; the row scrolls sideways in its own box on a phone | a sequence with one running and the others looked at in turn (a program's phases), where `featured`'s toggles would stack every phase's long content |
1493
1494
 
1494
1495
  - **A state is a badge**, the outline style in its tone (`state: 'Planned'`
1495
1496
  is the neutral one; `{ label, tone }` with `info`, `success`, `warning`
@@ -1501,6 +1502,24 @@ one look per set; a fifth is asked for first.
1501
1502
  Enter or Space opens one, Tab moves to the next, several can be open,
1502
1503
  `aria-expanded` says which. Never a link; `defaultOpenIds` opens some at
1503
1504
  first.
1505
+ - **The stepper** (4.127): each item's `step` is `done` (filled with
1506
+ the primary, a check), `current` (ringed, "Current" under its name, its
1507
+ panel's border the accent) or `upcoming` (outlined, the default); the
1508
+ line into a step is the primary up to the current one. It opens on
1509
+ `featuredId`, else the `current` step, else the first; the shown step
1510
+ has a ring round its mark and its name semibold. The steps are a
1511
+ tablist named `label`: arrow keys, Home and End move and pick, Tab goes
1512
+ on into the panel, and the current step is `aria-current="step"`. A
1513
+ step's name is what it shows plus hidden words ("Step 2: Phase 2:
1514
+ Build, done"), never an `aria-label`. An app that keeps the shown step
1515
+ (in the URL as `?phase=`) passes `selectedId` and `onSelectedChange`.
1516
+ `attention` ("needs an answer") puts a small warning dot on a step and
1517
+ those words in its name, for something in a panel not shown (an
1518
+ unsaved change waiting on an answer). **On a phone** the row stays a
1519
+ row: each step at least 4.5rem wide and 44px tall, scrolling sideways
1520
+ in its own box (never the page) as the record's tab bar does, the
1521
+ shown step kept in view; it never folds into a select, which would
1522
+ hide the done and current marks the stepper is for.
1504
1523
  - **Empty**: no items reads `emptyText` ("Nothing yet"), an item with no
1505
1524
  fields `noFieldsText` ("No details"). `label` names the set for a screen
1506
1525
  reader (the list's name, the table's caption); titles are `h3` under a
@@ -1546,7 +1565,7 @@ items={stores.map((store) => ({
1546
1565
 
1547
1566
  Measured with axe, the token check and the glyph check in both themes and
1548
1567
  every palette (fixtures `app/EqualItems`, "Content and actions" among
1549
- them), and from the keyboard and at a phone's width in
1568
+ them, and "Stepper"), and from the keyboard and at a phone's width in
1550
1569
  `e2e/equal-items.spec.ts`.
1551
1570
 
1552
1571
  ## An overview page
@@ -1776,8 +1795,21 @@ its short facts the last tab, Details. A mark goes left of the title.
1776
1795
  that's what a screen reader hears, one image named in words. The
1777
1796
  glyphs are a fixed size, so the value never moves on hover, and it's
1778
1797
  drawn the same in Details on a phone. An empty one reads its
1779
- `emptyLabel` ("Not rated"), not a row of empty stars. Edited in place
1780
- like any fact (`edit`), usually `inPlace.select` over the scores.
1798
+ `emptyLabel` ("Not rated"), not a row of empty stars. A score the
1799
+ person sets is edited with `inPlace.rating` (4.127): the stars become
1800
+ `RatingInput`, set by a click where they're drawn (no select to open),
1801
+ and an empty one is then five empty stars to click. "Saving…" and
1802
+ "Saved" are an icon beside the stars, words for a screen reader, so the
1803
+ row never grows. On a touch screen each star is a 44px target and the
1804
+ row puts its label above them, which a narrow value column can't hold.
1805
+ - **`RatingInput`** (4.127): RatingScore's glyphs and tokens as a radio
1806
+ group named by the field's label, each star a radio ("2 of 5"). The
1807
+ arrow keys move and set it, a click or Space sets the star it's on,
1808
+ pressing the set star again clears it. A mouse's hover previews the
1809
+ score in the same ink (the filled count is the preview; leaving puts it
1810
+ back); a finger gets no preview. 24px targets on a laptop, 44px on a
1811
+ touch screen, fixed-size either way. Disabled, it's the score at half
1812
+ opacity and ignores the pointer.
1781
1813
  - **A yes/no** (`kind: 'switch'`, 4.120) is a switch on the value's
1782
1814
  line, never a two-choice select: `checked`, `onCheckedChange` (return
1783
1815
  the save's promise and the switch shows the new state, busy, until it
@@ -11,8 +11,15 @@ export type AppError = {
11
11
  * lapsed, not from the app: a page or a redirect where JSON was
12
12
  * expected. Only a full page load signs in again. Not the app's own
13
13
  * session, which is `auth`.
14
+ *
15
+ * `conflict` (a 409): the save was refused because the record changed
16
+ * since the version it was built on (another tab, a phone, an AI chat
17
+ * saved in between). Nothing was written: fetch the record again and
18
+ * let the person choose. `useRecordUpdate` refetches it, and editing in
19
+ * place asks "This changed elsewhere" (docs/foundation/add-an-entity.md
20
+ * "Saves that don't overwrite").
14
21
  */
15
- kind: "validation" | "notfound" | "auth" | "rate_limited" | "server" | "network" | "proxy_auth";
22
+ kind: "validation" | "notfound" | "auth" | "rate_limited" | "conflict" | "server" | "network" | "proxy_auth";
16
23
  message: string;
17
24
  fieldErrors?: Record<string, string[]>;
18
25
  /**
@@ -89,6 +89,10 @@ function translate(status, body, headers) {
89
89
  return { kind: "notfound", message };
90
90
  if (status === 401)
91
91
  return { kind: "auth", message };
92
+ // The record changed since the version the save was built on: nothing
93
+ // was written (ConflictError in openapi/foundation.yaml).
94
+ if (status === 409)
95
+ return { kind: "conflict", message };
92
96
  if (status === 429) {
93
97
  const retryAfterSeconds = parseRetryAfter(headers?.get("retry-after") ?? null);
94
98
  return retryAfterSeconds === undefined
@@ -330,6 +330,15 @@ export interface components {
330
330
  "application/json": components["schemas"]["HTTPErrorBody"];
331
331
  };
332
332
  };
333
+ /** @description The record changed since the version the request was built on (another tab, device or AI chat saved in between). Nothing was written. The client fetches the record again and lets the person choose; the gateway's toAppError makes it AppError kind "conflict". */
334
+ ConflictError: {
335
+ headers: {
336
+ [name: string]: unknown;
337
+ };
338
+ content: {
339
+ "application/json": components["schemas"]["HTTPErrorBody"];
340
+ };
341
+ };
333
342
  /** @description The pending sign-in is missing, expired or out of tries. Start again with POST /auth/login. */
334
343
  SignInExpiredError: {
335
344
  headers: {
@@ -11,11 +11,23 @@ export type DataTableView = {
11
11
  label?: string;
12
12
  /** The columns this view shows; while it's on they win over the Columns menu. */
13
13
  columns?: readonly string[];
14
+ /**
15
+ * How many records the view holds, after its label: "Needs a Look · 3"
16
+ * (4.127). The app counts them with its own query; the table doesn't.
17
+ * null, undefined and 0 show no count, as the sidebar's counts and
18
+ * EntityView's tab counts don't, and past 99 it reads "99+". It's part
19
+ * of the pill's name ("Needs a Look, 3"). A view that has the key at all,
20
+ * even undefined while the count loads, keeps room for a two-digit count
21
+ * from the first render, so the pills don't move when it arrives.
22
+ */
23
+ count?: number | null;
14
24
  };
15
25
  export declare function ViewPills({ views, value, onValueChange, label, }: {
16
26
  views: readonly {
17
27
  id: string;
18
28
  label: string;
29
+ count?: number | null;
30
+ counted?: boolean;
19
31
  }[];
20
32
  value: string | null;
21
33
  onValueChange: (id: string) => void;
@@ -5,12 +5,12 @@ import { Button } from '../ui/button.js';
5
5
  import { DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from '../ui/dropdown-menu.js';
6
6
  import { Skeleton } from '../ui/skeleton.js';
7
7
  import { IconAction } from './icon-action.js';
8
- import { PillFilter } from './pill-filter.js';
8
+ import { PillGroup } from './pill-filter.js';
9
9
  import { togglePick } from './table-columns.js';
10
10
  // The pills on one line that scrolls sideways under 48rem, wrapping wider.
11
11
  // The padding keeps the focus ring inside the scroll box.
12
12
  export function ViewPills({ views, value, onValueChange, label, }) {
13
- return (_jsx("div", { "data-slot": "data-table-views", className: "max-md:-mx-1 max-md:overflow-x-auto max-md:p-1", children: _jsx(PillFilter, { label: label, allLabel: null, options: views.map((view) => ({ value: view.id, label: view.label })),
13
+ return (_jsx("div", { "data-slot": "data-table-views", className: "max-md:-mx-1 max-md:overflow-x-auto max-md:p-1", children: _jsx(PillGroup, { label: label, allLabel: null, options: views.map((view) => ({ value: view.id, label: view.label, count: view.count, counted: view.counted })),
14
14
  // No view's id matches '' (filters set by hand), so none is pressed.
15
15
  value: value ?? '', onValueChange: onValueChange, className: "max-md:w-max max-md:flex-nowrap" }) }));
16
16
  }
@@ -269,7 +269,8 @@ export type DataTableProps<TData extends Record<string, unknown>, TView extends
269
269
  * their order. One is pressed while it's `activeView`; none once the
270
270
  * filters move off every view. Under 48rem they stay on one line that
271
271
  * scrolls sideways. A view with `columns` shows those while it's on, over
272
- * the Columns menu's pick.
272
+ * the Columns menu's pick. A view with `count` shows it after its label
273
+ * ("Needs a Look · 3", 4.127).
273
274
  */
274
275
  views?: Readonly<Record<string, TView>>;
275
276
  /** The view on: useTableUrlState's `activeView`, or null. */
@@ -761,7 +761,7 @@ export function DataTable({ columns, data, total, page, pageSize, onPageChange,
761
761
  const showColumnsMenu = Boolean(columnsMenu) && !showPhoneRows;
762
762
  // The pieces, placed as `look` says: plain, or a framed card.
763
763
  const framed = look === 'framed';
764
- const viewPills = (_jsx(_Fragment, { children: viewEntries.length > 0 ? (_jsx(ViewPills, { label: viewsLabel, views: viewEntries.map(([id, view]) => ({ id, label: view.label ?? id })), value: activeView, onValueChange: (id) => {
764
+ const viewPills = (_jsx(_Fragment, { children: viewEntries.length > 0 ? (_jsx(ViewPills, { label: viewsLabel, views: viewEntries.map(([id, view]) => ({ id, label: view.label ?? id, count: view.count, counted: 'count' in view })), value: activeView, onValueChange: (id) => {
765
765
  const view = views?.[id];
766
766
  if (view)
767
767
  onViewChange?.(view, id);