@tristan2828/ui-foundation 4.70.0 → 4.72.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.
@@ -3,25 +3,26 @@
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 40–62
7
- - [Before anything: the entity plan](#before-anything-the-entity-plan) · lines 64–749
8
- - Step 1: Add `<Entity>` to `openapi.yaml` · lines 106–113
9
- - Step 2: `npm run gen:api` · lines 114–115
10
- - Step 3: Add gateway tests in `tests/gateway/<entity>.test.ts`, derived from the spec · lines 116–127
11
- - Step 4: Add MSW handlers in `src/mocks/<entity>.ts` · lines 128–137
12
- - Step 5: Add a gateway module in `src/api/gateway/<entity>.ts` · lines 138–142
13
- - Step 6: Copy the reference files, one for one, not just the two screens · lines 143–638
14
- - Step 7: Register routes · lines 639–652
15
- - Step 8: Add Playwright specs for all three screens · lines 653–731
16
- - Step 9: Register the nav entry and route names · lines 732–746
17
- - Step 10: `npm run verify`. · lines 747–749
18
- - [How a list opens a record](#how-a-list-opens-a-record) · lines 751–854
19
- - [The record view](#the-record-view) · lines 829–854
20
- - [What not to copy](#what-not-to-copy) · lines 856–882
21
- - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 884–901
22
- - [Deleting](#deleting) · lines 903–932
23
- - [Fields only a script writes](#fields-only-a-script-writes) · lines 934–955
24
- - [Searching one part of the app](#searching-one-part-of-the-app) · lines 957–966
6
+ - [The reference files](#the-reference-files) · lines 41–63
7
+ - [Before anything: the entity plan](#before-anything-the-entity-plan) · lines 65–758
8
+ - Step 1: Add `<Entity>` to `openapi.yaml` · lines 107–114
9
+ - Step 2: `npm run gen:api` · lines 115–116
10
+ - Step 3: Add gateway tests in `tests/gateway/<entity>.test.ts`, derived from the spec · lines 117–128
11
+ - Step 4: Add MSW handlers in `src/mocks/<entity>.ts` · lines 129–138
12
+ - Step 5: Add a gateway module in `src/api/gateway/<entity>.ts` · lines 139–143
13
+ - Step 6: Copy the reference files, one for one, not just the two screens · lines 144–645
14
+ - Step 7: Register routes · lines 646–661
15
+ - Step 8: Add Playwright specs for all three screens · lines 662–740
16
+ - Step 9: Register the nav entry and route names · lines 741–755
17
+ - Step 10: `npm run verify`. · lines 756–758
18
+ - [How a list opens a record](#how-a-list-opens-a-record) · lines 760–898
19
+ - [The record view](#the-record-view) · lines 873–898
20
+ - [What not to copy](#what-not-to-copy) · lines 900–926
21
+ - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 928–945
22
+ - [Deleting](#deleting) · lines 947–976
23
+ - [Fields only a script writes](#fields-only-a-script-writes) · lines 978–999
24
+ - [Searching one part of the app](#searching-one-part-of-the-app) · lines 1001–1010
25
+ - [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1013–1052
25
26
 
26
27
  <!-- /index -->
27
28
 
@@ -546,7 +547,13 @@ is a filled-in example while the Widgets demo is still here).
546
547
  ids as a set; a field the plan marks `small` is `MultiPick`, on the
547
548
  form too, every option loaded once, and saves each click itself:
548
549
  `value` is the record's, `onPick` the single-field save as a
549
- function of the record, cell pattern 18 "A small set"). A field gets `edit`, a `content` section gets `edit`,
550
+ function of the record, cell pattern 18 "A small set"). A plain
551
+ text, number, money, date, single choice or single reference whose
552
+ form control is a plain box (no control of the entity's own) can be
553
+ the package's preset instead, one line with no control to wrap:
554
+ `{ label, edit: inPlace.money({ value, save }) }` (cell pattern 18,
555
+ "Presets"); a link with a label is `inPlace.link`, and two fields
556
+ that must agree are `inPlace.fields` with its `rule`. A field gets `edit`, a `content` section gets `edit`,
550
557
  the title gets `titleEdit={{ label, ...edit }}`, and a header badge
551
558
  wraps itself in `<EditableValue label edit layout="inline">`. The
552
559
  shown value stays exactly as before. A sub-record list the line
@@ -649,7 +656,9 @@ is a filled-in example while the Widgets demo is still here).
649
656
  it shows under the module while you're in it.
650
657
  If the plan says records **open in a dialog** over the list (`opens`
651
658
  kind `dialog` or `dialog-only`), the view's route is the list route's
652
- child instead: see [How a list opens a record](#how-a-list-opens-a-record).
659
+ child instead (or, for a list at `/<entity>/list`, its sibling under
660
+ `listPath`; a sub-record opens over its parent's page the same way):
661
+ see [How a list opens a record](#how-a-list-opens-a-record).
653
662
  8. **Add Playwright specs for all three screens**, one test per state
654
663
  (`loading`, `empty`, `error`, `validation`, `success`), forced through
655
664
  MSW overrides — `forceMswOverride`, `waitForMswReady` and the
@@ -789,6 +798,41 @@ plan allows it.
789
798
  <Board renderCard={(item) => <RecordLink to={`/<entity>/${item.id}`}>{item.name}</RecordLink>} … />
790
799
  ```
791
800
 
801
+ **A list that isn't the record's parent route** (4.71: the list at
802
+ `/<entity>/list`, the record at `/<entity>/:id`): the route the two share
803
+ wraps them, with `listPath`. The list's own route has no element (the
804
+ `list` prop draws it), and every other child is a record. Opened from
805
+ the list, the record is the dialog over it; closing goes back to
806
+ `/<entity>/list`; a deep link is the full page, as above.
807
+
808
+ ```tsx
809
+ {
810
+ path: '<entity>',
811
+ element: <RecordDialogRoute list={<<Entity>sTableRoute />} listPath="list" label="<Entity>" />,
812
+ children: [{ path: 'list' }, { path: ':id', element: <<Entity>ViewRoute /> }],
813
+ },
814
+ ```
815
+
816
+ **A sub-record over its parent's page** (4.71: a parent's documents,
817
+ `/<parents>/7/<children>/31`): the same dialog one level down. The
818
+ parent's page is the `list`, the sub-record its child, and
819
+ `fullPage={false}`, so a reload of the sub-record's address is the dialog
820
+ over the parent again. The parent's table of sub-records says
821
+ `` opens={{ kind: 'dialog-only', to: (row) => `/<parents>/${row.parentId}/<children>/${row.id}` }} ``,
822
+ and the sub-record's view is its ordinary `EntityView` (`back` to the
823
+ parent). Keep the parent's other routes (its `edit`) siblings of
824
+ `<parents>/:id`, not its children: every child of the route is drawn in
825
+ the dialog.
826
+
827
+ ```tsx
828
+ {
829
+ path: '<parents>/:id',
830
+ element: <RecordDialogRoute list={<<Parent>ViewRoute />} label="<Child>" fullPage={false} />,
831
+ children: [{ path: '<children>/:childId', element: <<Child>ViewRoute /> }],
832
+ },
833
+ { path: '<parents>/:id/edit', element: <<Parent>FormRoute /> }, // a sibling, not a child
834
+ ```
835
+
792
836
  - **The row opens it**: a click on the row, Enter on it, ↑/↓ between
793
837
  rows. So does a click on a link in the row to the record's own address
794
838
  (the name cell can stay a plain `<Link>`), and in a card layout a click
@@ -964,3 +1008,45 @@ question isn't handed purchases and comics too. The tool's description
964
1008
  lists each group's entities, and `group` is offered only when some entity
965
1009
  has one; an unknown group is a refusal naming the ones there are. An
966
1010
  entity with no group is searched only when no group is given.
1011
+
1012
+
1013
+ ## What a chat is told about an entity
1014
+
1015
+ Four more things an app sets for AI chats (4.71), each in
1016
+ `backend/app/mcp_entities.py`:
1017
+
1018
+ - **`description`** on the `McpEntity`: what the entity is, in a sentence
1019
+ (`description="A purchase: what was bought, where and for how much"`).
1020
+ It's shown beside the entity's name in the `search`, `list` and
1021
+ `create` tools, so a chat picks the right one.
1022
+ - **`text_edits`**: the wire names of its long-text fields (notes, a body)
1023
+ that a chat changes in part with the `edit_text` tool
1024
+ (`text_edits=("notes",)`): `old` and `new` replace one passage, which
1025
+ must be found exactly once (missing, or found twice, is a refusal that
1026
+ says so and saves nothing), or `append` adds text on a new line at the
1027
+ end. It saves and logs as `update` does, so a long note isn't sent back
1028
+ whole to change a line. Each must be a text field of `update_schema`
1029
+ and not `script_only`; the backend refuses to start otherwise.
1030
+ - **The server's instructions** a chat gets when it connects:
1031
+ `register_entities(ENTITIES, instructions="…")` (or
1032
+ `register_instructions("…")`) adds the app's own words after the
1033
+ built-in ones; `register_instructions("…", replace=True)` sends only
1034
+ the app's. The built-in ones are written from the entities: which can
1035
+ be deleted (soft only, with restore; "Nothing can be deleted" only when
1036
+ none can) and which texts `edit_text` changes.
1037
+ - **An answer note**, `register_answer_note(note)`: a function given the
1038
+ caller, the tool's name, its arguments and the entities whose records
1039
+ the answer shows, which returns text appended to the answer after a
1040
+ blank line, or `None`. Plain or async. It runs after every answer (not
1041
+ a refusal); one that raises is reported and left out, and the answer
1042
+ stands.
1043
+
1044
+ ```python
1045
+ def note(caller, tool, arguments, entities):
1046
+ if any(e.group == "health" for e in entities):
1047
+ return "Health records are the person's own notes, not medical advice."
1048
+ return None
1049
+
1050
+ register_entities(ENTITIES, instructions="Amounts are in the account's currency.")
1051
+ register_answer_note(note)
1052
+ ```
@@ -3,39 +3,42 @@
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 rules that apply to every cell](#the-rules-that-apply-to-every-cell) · lines 67–86
7
- - [1. Plain text](#1-plain-text) · lines 88–95
8
- - [2. Icon + label](#2-icon--label) · lines 97–120
9
- - [3. Icon in a badge](#3-icon-in-a-badge) · lines 122–135
10
- - [4. Icon only, label in a tooltip](#4-icon-only-label-in-a-tooltip) · lines 137–214
11
- - [Several values: the icons side by side, every name in one tooltip](#several-values-the-icons-side-by-side-every-name-in-one-tooltip) · lines 162–214
12
- - [5. Enum → tone-mapped badge](#5-enum--tone-mapped-badge) · lines 216–229
13
- - [6. Multi-value enum, clustered](#6-multi-value-enum-clustered) · lines 231–243
14
- - [7. Link as an outline button](#7-link-as-an-outline-button) · lines 245–266
15
- - [8. Date, relative](#8-date-relative) · lines 268–305
16
- - [9. Ordinal scale (bounded integer)](#9-ordinal-scale-bounded-integer) · lines 307–355
17
- - [Two variants the package draws: a step bar and a star](#two-variants-the-package-draws-a-step-bar-and-a-star) · lines 325–355
18
- - [10. Summary in the cell, detail in a popover](#10-summary-in-the-cell-detail-in-a-popover) · lines 357–407
19
- - [A second example: what a row depends on](#a-second-example-what-a-row-depends-on) · lines 375–407
20
- - [11. Number or currency — Unproven](#11-number-or-currency--unproven) · lines 409–449
21
- - [12. Boolean](#12-boolean) · lines 451–481
22
- - [13. Progress bar — Unproven](#13-progress-bar--unproven) · lines 483–519
23
- - [The compact form: `ProgressRing`](#the-compact-form-progressring) · lines 503–519
24
- - [14. Avatar and name — Unproven](#14-avatar-and-name--unproven) · lines 521–538
25
- - [15. Yes/no you flip in the row](#15-yesno-you-flip-in-the-row) · lines 540–649
26
- - [A variant: a pressed icon inside another value's cell](#a-variant-a-pressed-icon-inside-another-values-cell) · lines 566–649
27
- - [16. Title linking to the record's view](#16-title-linking-to-the-records-view) · lines 651–686
28
- - [17. Quick action on the view](#17-quick-action-on-the-view) · lines 688–761
29
- - [18. Editable value](#18-editable-value) · lines 763–1228
30
- - [A list of sub-items](#a-list-of-sub-items) · lines 1044–1129
31
- - [In a table's rows](#in-a-tables-rows) · lines 1131–1216
32
- - [A table of a few short columns: `width="content"`](#a-table-of-a-few-short-columns-widthcontent) · lines 1218–1228
33
- - [19. Stage circle for an ordered status](#19-stage-circle-for-an-ordered-status) · lines 1230–1296
34
- - [20. Count linking to the related records](#20-count-linking-to-the-related-records) · lines 1298–1362
35
- - [21. Rows grouped under headings, and a pill filter](#21-rows-grouped-under-headings-and-a-pill-filter) · lines 1364–1432
36
- - [22. A highlighted row, and rows that are done](#22-a-highlighted-row-and-rows-that-are-done) · lines 1434–1462
37
- - [23. A Group menu, and a record read beside the list](#23-a-group-menu-and-a-record-read-beside-the-list) · lines 1464–1540
38
- - [24. A stored colour beside its name](#24-a-stored-colour-beside-its-name) · lines 1542–1565
6
+ - [The rules that apply to every cell](#the-rules-that-apply-to-every-cell) · lines 70–89
7
+ - [1. Plain text](#1-plain-text) · lines 91–98
8
+ - [2. Icon + label](#2-icon--label) · lines 100–123
9
+ - [3. Icon in a badge](#3-icon-in-a-badge) · lines 125–138
10
+ - [4. Icon only, label in a tooltip](#4-icon-only-label-in-a-tooltip) · lines 140–217
11
+ - [Several values: the icons side by side, every name in one tooltip](#several-values-the-icons-side-by-side-every-name-in-one-tooltip) · lines 165–217
12
+ - [5. Enum → tone-mapped badge](#5-enum--tone-mapped-badge) · lines 219–232
13
+ - [6. Multi-value enum, clustered](#6-multi-value-enum-clustered) · lines 234–246
14
+ - [7. Link as an outline button](#7-link-as-an-outline-button) · lines 248–269
15
+ - [8. Date, relative](#8-date-relative) · lines 271–308
16
+ - [9. Ordinal scale (bounded integer)](#9-ordinal-scale-bounded-integer) · lines 310–358
17
+ - [Two variants the package draws: a step bar and a star](#two-variants-the-package-draws-a-step-bar-and-a-star) · lines 328–358
18
+ - [10. Summary in the cell, detail in a popover](#10-summary-in-the-cell-detail-in-a-popover) · lines 360–410
19
+ - [A second example: what a row depends on](#a-second-example-what-a-row-depends-on) · lines 378–410
20
+ - [11. Number or currency — Unproven](#11-number-or-currency--unproven) · lines 412–452
21
+ - [12. Boolean](#12-boolean) · lines 454–484
22
+ - [13. Progress bar — Unproven](#13-progress-bar--unproven) · lines 486–522
23
+ - [The compact form: `ProgressRing`](#the-compact-form-progressring) · lines 506–522
24
+ - [14. Avatar and name — Unproven](#14-avatar-and-name--unproven) · lines 524–541
25
+ - [15. Yes/no you flip in the row](#15-yesno-you-flip-in-the-row) · lines 543–652
26
+ - [A variant: a pressed icon inside another value's cell](#a-variant-a-pressed-icon-inside-another-values-cell) · lines 569–652
27
+ - [16. Title linking to the record's view](#16-title-linking-to-the-records-view) · lines 654–689
28
+ - [17. Quick action on the view](#17-quick-action-on-the-view) · lines 691–764
29
+ - [18. Editable value](#18-editable-value) · lines 766–1401
30
+ - [Presets: one line per field](#presets-one-line-per-field) · lines 1051–1107
31
+ - [Several fields edited as one](#several-fields-edited-as-one) · lines 1109–1141
32
+ - [A link and its label](#a-link-and-its-label) · lines 1143–1167
33
+ - [A list of sub-items](#a-list-of-sub-items) · lines 1169–1302
34
+ - [In a table's rows](#in-a-tables-rows) · lines 1304–1389
35
+ - [A table of a few short columns: `width="content"`](#a-table-of-a-few-short-columns-widthcontent) · lines 1391–1401
36
+ - [19. Stage circle for an ordered status](#19-stage-circle-for-an-ordered-status) · lines 1403–1469
37
+ - [20. Count linking to the related records](#20-count-linking-to-the-related-records) · lines 1471–1535
38
+ - [21. Rows grouped under headings, and a pill filter](#21-rows-grouped-under-headings-and-a-pill-filter) · lines 1537–1605
39
+ - [22. A highlighted row, and rows that are done](#22-a-highlighted-row-and-rows-that-are-done) · lines 1607–1635
40
+ - [23. A Group menu, and a record read beside the list](#23-a-group-menu-and-a-record-read-beside-the-list) · lines 1637–1713
41
+ - [24. A stored colour beside its name](#24-a-stored-colour-beside-its-name) · lines 1715–1738
39
42
 
40
43
  <!-- /index -->
41
44
 
@@ -775,9 +778,11 @@ The rule behind every part of it: **nothing typed is ever lost.**
775
778
  **Which values.** Only those the plan's "View screen" names under `Edit
776
779
  in place`; read-only is the default, and a value not named renders
777
780
  exactly as it did. Text, long text, a single choice (optional ones with
778
- their "not set" option), an integer or a rating, a yes/no, a single or
779
- multi reference, and a sub-record list (its own rules, under "A list of
780
- sub-items" below). Never a computed field. The view's Edit button and
781
+ their "not set" option), an integer or a rating, money, a date, a link
782
+ and its label, a yes/no, a single or multi reference, two fields that
783
+ must agree (edited as one), and a sub-record list (its own rules, under
784
+ "A list of sub-items" below). The plain ones are one line each with the
785
+ `inPlace` presets ("Presets" below). Never a computed field. The view's Edit button and
781
786
  the form stay.
782
787
 
783
788
  **At rest: says it's editable without shouting.** The value reads as it
@@ -980,7 +985,9 @@ const price = editInPlace({
980
985
 
981
986
  - **One control per field, shared with the form** (`<entity>-fields.tsx`):
982
987
  each takes `value`/`onChange` and `readOnly`, and the form wraps it in a
983
- `Controller`. Never a second, in-place-only control.
988
+ `Controller`. Never a second, in-place-only control of the app's own: a
989
+ plain box, number, money, day, list or reference uses the package's
990
+ `inPlace` preset instead (below).
984
991
  - **Long text written as Markdown edits as rich text** (`RichTextEditor`):
985
992
  formatted where it's read, saved as Markdown with every block the person
986
993
  didn't touch kept exactly as written. On the form too, so it's one
@@ -1041,6 +1048,124 @@ const price = editInPlace({
1041
1048
  Keep it to the fields the plan names, and leave the form for everything
1042
1049
  else.
1043
1050
 
1051
+ ### Presets: one line per field
1052
+
1053
+ For a value whose control is a plain one (a text box, a number, money, a
1054
+ day, a fixed list, another record), the package's **`inPlace` presets**
1055
+ carry the control, its check and how the value reads at rest, so the
1056
+ field is one line and there is nothing to wrap:
1057
+
1058
+ ```tsx
1059
+ import { inPlace } from '@tristan2828/ui-foundation'
1060
+
1061
+ const editField = useEditProjectField(project.id) // optimistic: false, toastOnError: false
1062
+ const save = (change: Partial<ProjectUpdate>) => editField.mutateAsync(change)
1063
+ fields: [
1064
+ { label: 'Code', edit: inPlace.text({ value: project.code, maxLength: 8, save: (code) => save({ code }) }) },
1065
+ { label: 'Hours', edit: inPlace.number({ value: project.hours, min: 0, max: 200, unit: 'h', save: (hours) => save({ hours }) }) },
1066
+ { label: 'Budget', edit: inPlace.money({ value: project.budget, save: (budget) => save({ budget }) }) },
1067
+ { label: 'Due', edit: inPlace.date({ value: project.due, required: true, save: (due) => save({ due }) }) },
1068
+ { label: 'Priority', edit: inPlace.select({ value: project.priority, options: PRIORITY_OPTIONS,
1069
+ render: (priority, label) => <Badge variant={PRIORITY_BADGE[priority]}>{label}</Badge>,
1070
+ save: (priority) => save({ priority }) }) },
1071
+ { label: 'Category', edit: inPlace.reference({ value: project.categoryId, label: categoryName,
1072
+ search: (text) => searchCategories(text), save: (categoryId) => save({ categoryId }) }) },
1073
+ ]
1074
+ // The title: <EntityView titleEdit={{ label: 'Name', ...inPlace.text({ value: project.name, required: true, save: … }) }} />
1075
+ // A badge: <EditableValue label="Priority" edit={priority} layout="inline" /> (its children default to the preset's look)
1076
+ ```
1077
+
1078
+ - **The field gives no `value`**: the preset's `shown` is what the view
1079
+ shows (and prints), `null` reading as the field's "Not set". Pass
1080
+ `value` or `shown` only to draw it some other way (a link to the record).
1081
+ - **What each saves, and checks first** (its message under the field,
1082
+ nothing sent):
1083
+
1084
+ | Preset | At rest | Saves | Refuses |
1085
+ |---|---|---|---|
1086
+ | `text` | the text | it trimmed; blank is `null` | blank when `required`, past `maxLength` |
1087
+ | `number` | `1,234 h` (`unit`) | a number; blank is `null` | not a number, under `min`, over `max`, a fraction with `integer` |
1088
+ | `money` | `$1,234.56` (`currency`, `locale`) | the API's decimal string, two places (`"1234.50"`), built from the digits, never a float; `$` and commas typed are fine | a third decimal, words, under `min` (0 by default), over `max` |
1089
+ | `date` | `Sep 2, 2026` | `'YYYY-MM-DD'`; Clear is `null` | Clear when `required` |
1090
+ | `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` |
1091
+ | `reference` | the record's `label` (the view's lookup by id) | the picked record's id | "Not set" isn't offered when `required` |
1092
+
1093
+ - **They save the way their kind does** (the table above): `text`,
1094
+ `number` and `money` on Enter or leaving them, `date`, `select` and
1095
+ `reference` on the pick (the list opens with the field).
1096
+ `required: true` types the save without `null`.
1097
+ - **`reference` searches through the app.** The package knows no
1098
+ endpoint: `search(text)` is the app's (its gateway's search by name,
1099
+ `''` when the list opens), called a pause after typing stops; a
1100
+ rejection reads as nothing found. Names come from the searches and from
1101
+ `label`, so the saved record's name shows before any search answers.
1102
+ - **Keep the app's own control when it has one.** A field whose control
1103
+ is the form's own (a rich-text editor, a multi picker, an icon select,
1104
+ anything in `<entity>-fields.tsx` beyond a plain box) stays
1105
+ `editInPlace({ kind, control, ... })`; the rule "one control per field,
1106
+ shared with the form" is for those. A preset is the package's control,
1107
+ and the form can use the same plain box.
1108
+
1109
+ ### Several fields edited as one
1110
+
1111
+ Two (or more) of a record's fields that only make sense together (a
1112
+ model and an effort that must agree, a range's low and high) edit as one
1113
+ value and save in one PATCH: `inPlace.fields`.
1114
+
1115
+ ```tsx
1116
+ { label: 'Model and effort', edit: inPlace.fields({
1117
+ value: { model: run.model, effort: run.effort }, // keyed by the record's field names
1118
+ fields: {
1119
+ model: { kind: 'select', label: 'Model', required: true, options: MODEL_OPTIONS },
1120
+ effort: { kind: 'select', label: 'Effort', required: true, options: EFFORT_OPTIONS },
1121
+ },
1122
+ rule: ({ model, effort }) => (effort === 'max' && model !== 'large' ? 'Max effort needs the large model' : null),
1123
+ save: ({ model, effort }) => editField.mutateAsync({ model, effort }),
1124
+ }) }
1125
+ ```
1126
+
1127
+ - **Each part is a preset's control** (`kind` and its options, as in the
1128
+ table above, with its own `label`), side by side under a small caption
1129
+ of its label, and stacked when the row is narrow. At rest the parts
1130
+ read joined by " · " ("Small · Low"), or as `shown`.
1131
+ - **Nothing saves until they agree.** Picking a part doesn't save it:
1132
+ the pair saves on leaving it or Ctrl/Cmd+Enter (and on Enter too when
1133
+ every part is typed into: numbers, money, text). Esc gives up both.
1134
+ - **Where a refusal shows.** A part's own check ("Budget: Enter an
1135
+ amount") and a 422 naming its field (`fieldErrors.model`) show under
1136
+ that part, which is `aria-invalid`. The `rule`'s message, or a refusal
1137
+ naming none of them, shows under the pair, with every part invalid.
1138
+ - Built from `editInPlace` options any field can use: `fieldErrors`
1139
+ (which of the value's fields a refusal is about) and `errorsOnFields`
1140
+ (the control shows them, so they aren't repeated under it); the
1141
+ control gets them as `errors`.
1142
+
1143
+ ### A link and its label
1144
+
1145
+ A link stored as an address and an optional label (`docsUrl` and
1146
+ `docsLabel`): `inPlace.link`, its value `{ url, label }` mapped to and
1147
+ from the app's own fields.
1148
+
1149
+ ```tsx
1150
+ { label: 'Docs', edit: inPlace.link({
1151
+ value: { url: project.docsUrl, label: project.docsLabel },
1152
+ save: ({ url, label }) => editField.mutateAsync({ docsUrl: url, docsLabel: label }),
1153
+ }) }
1154
+ ```
1155
+
1156
+ - **At rest** it's `LinkCell`'s link (`LinkOut`): the label if it has
1157
+ one, else the address's host (`docs.example.com`), in the link tone,
1158
+ opening in a new tab with `noopener noreferrer` and saying so to a
1159
+ screen reader. No address reads as "Not set" (or `emptyLabel`). A
1160
+ stored address the box would refuse reads as text, never a link. A
1161
+ click on the link follows it; the pencil edits.
1162
+ - **Open**, two boxes, URL and Label (optional); Enter in either or
1163
+ leaving saves both. The address is checked by **`linkRule`**, the rule
1164
+ `LinkCell` uses (exported, over `linkHref`): `example.com` gains
1165
+ `https://`, another scheme (`javascript:`) or a space is refused on the
1166
+ URL box. A label with no address is refused ("Add the address, or
1167
+ clear the label"); both blank saves `{ url: null, label: null }`.
1168
+
1044
1169
  ### A list of sub-items
1045
1170
 
1046
1171
  A sub-record list (a checklist, a list of links) on a `content` section,
@@ -1088,6 +1213,54 @@ Checklist is the reference (`checklist` in `widgetEdits`). It's built on
1088
1213
  plus `items` (to stop at a limit), `disabled` (a change is saving) and
1089
1214
  `onProblem(message)` (an upload refused, under the list). Each item
1090
1215
  then reads, edits, moves and removes like a checklist's.
1216
+ - **Grouped by one of its items' fields** (`groupBy`, a checklist by
1217
+ room): each group under its own heading (`type-label`, muted), with its
1218
+ own rows, buttons and Add ("Add task to Kitchen", whose `newItem` is
1219
+ given the group's key). A move swaps the item with its group's next
1220
+ one, never into another group, and the first of a group can't go up.
1221
+ `order` names the groups in order and shows each even when empty (so
1222
+ its Add is there); others follow as their first item comes.
1223
+ - **Filtered** (`filter`, the view's "Hide done"): only the items it
1224
+ keeps show; the others stay in the list as they are, and a move swaps
1225
+ with the next item shown, over the hidden ones. A new item the filter
1226
+ drops goes out of sight once it's saved. Grouped or filtered, the list
1227
+ still saves as one, in its own order.
1228
+ - **Duplicate** (`duplicate: (item) => copy`), as on the form's
1229
+ `ListEditor`: a Duplicate button beside Remove ("Duplicate item 2")
1230
+ puts the copy right after the item, saved as a move is. Leave out
1231
+ what a copy mustn't share (a saved id).
1232
+ - **A refusal about an item's field shows on that field.** Give the
1233
+ list its field `name` (`checklist`): a 422 at `checklist.2.text`, like
1234
+ the list schema's issue at `[2, 'text']`, reaches item 2's row as
1235
+ `props.errors.text`. With `errorsOnFields`, the row shows them on its
1236
+ fields and the line under the row keeps only a message about no one
1237
+ field; without it they still show under the row, as before.
1238
+ - **The form's own react-hook-form row** (`itemForm: true`, with
1239
+ `name`): `renderItem` gets `form`, a form holding the list under
1240
+ `name` with the draft at the item's index, so the row the form's
1241
+ `ListEditor` renders (``form.register(`checklist.${index}.text`)``, a
1242
+ `Controller` on `form.control`, errors read from
1243
+ `form.formState.errors`) works here unchanged, and its every change is
1244
+ the item's draft. Refusals are set on that form (`setError`), so they
1245
+ show where the form shows them. No form of the app's own per item.
1246
+
1247
+ ```tsx
1248
+ const rooms = editInPlace<Task>({
1249
+ kind: 'list',
1250
+ name: 'tasks', // the record's field: 422s land on the item's fields
1251
+ value: house.tasks,
1252
+ save: (change) => editField.mutateAsync((current) => ({ tasks: change(current.tasks) })),
1253
+ groupBy: { key: (task) => task.room, label: (room) => ROOM_LABELS[room], order: ROOMS },
1254
+ filter: hideDone ? (task) => !task.done : undefined,
1255
+ duplicate: ({ id: _id, ...task }) => ({ ...task, done: false }),
1256
+ newItem: (room) => ({ text: '', room: room ?? ROOMS[0], done: false }),
1257
+ itemName: (index) => `task ${index + 1}`,
1258
+ addLabel: 'Add task',
1259
+ itemForm: true, // renderItem gets the form's own `form`
1260
+ renderShown: (task) => <TaskLine task={task} />,
1261
+ renderItem: ({ form, index }) => <TaskRowFields form={form!} index={index} />, // the form's row, as on the form
1262
+ })
1263
+ ```
1091
1264
 
1092
1265
  ```tsx
1093
1266
  const checklist = editInPlace<ChecklistItem>({
@@ -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
- - [Palettes](#palettes) · lines 39–105
7
- - [Glow](#glow) · lines 107–125
8
- - [Semantic tones](#semantic-tones) · lines 127–155
9
- - [The three badge styles](#the-three-badge-styles) · lines 157–174
10
- - [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines 176–205
11
- - [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines 207–220
12
- - [Logos and brand marks](#logos-and-brand-marks) · lines 222–266
13
- - [Categorical colour](#categorical-colour) · lines 268–338
14
- - [A stored colour](#a-stored-colour) · lines 340–388
15
- - [Shapes and sizes](#shapes-and-sizes) · lines 390–411
16
- - [Typography](#typography) · lines 413–507
17
- - [Written text (notes)](#written-text-notes) · lines 447–507
18
- - [Density](#density) · lines 509–595
19
- - [Rows on this device](#rows-on-this-device) · lines 568–595
20
- - [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 597–711
21
- - [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 713–782
22
- - [Notices](#notices) · lines 784–812
23
- - [A value over time](#a-value-over-time) · lines 814–900
24
- - [Several values over time](#several-values-over-time) · lines 863–900
25
- - [A list as a board](#a-list-as-a-board) · lines 902–953
26
- - [A list as cards](#a-list-as-cards) · lines 955–1001
27
- - [Key numbers on a record](#key-numbers-on-a-record) · lines 1003–1025
28
- - [Picking at random](#picking-at-random) · lines 1027–1058
29
- - [Filling in what's missing](#filling-in-whats-missing) · lines 1060–1127
6
+ - [Palettes](#palettes) · lines 40–106
7
+ - [Glow](#glow) · lines 108–126
8
+ - [Semantic tones](#semantic-tones) · lines 128–156
9
+ - [The three badge styles](#the-three-badge-styles) · lines 158–175
10
+ - [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines 177–206
11
+ - [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines 208–221
12
+ - [Logos and brand marks](#logos-and-brand-marks) · lines 223–267
13
+ - [Categorical colour](#categorical-colour) · lines 269–339
14
+ - [A stored colour](#a-stored-colour) · lines 341–389
15
+ - [Shapes and sizes](#shapes-and-sizes) · lines 391–412
16
+ - [Typography](#typography) · lines 414–508
17
+ - [Written text (notes)](#written-text-notes) · lines 448–508
18
+ - [Density](#density) · lines 510–596
19
+ - [Rows on this device](#rows-on-this-device) · lines 569–596
20
+ - [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 598–712
21
+ - [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 714–783
22
+ - [Notices](#notices) · lines 785–813
23
+ - [A value over time](#a-value-over-time) · lines 815–901
24
+ - [Several values over time](#several-values-over-time) · lines 864–901
25
+ - [A list as a board](#a-list-as-a-board) · lines 903–954
26
+ - [A list as cards](#a-list-as-cards) · lines 956–1002
27
+ - [Key numbers on a record](#key-numbers-on-a-record) · lines 1004–1026
28
+ - [Picking at random](#picking-at-random) · lines 1028–1059
29
+ - [Filling in what's missing](#filling-in-whats-missing) · lines 1061–1128
30
+ - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1130–1155
30
31
 
31
32
  <!-- /index -->
32
33
 
@@ -1125,3 +1126,30 @@ size"); the list stays where a record is edited one field at a time.
1125
1126
  progress }`) and `getGroup` name a record's source above its heading,
1126
1127
  with that group's own count; with more than one group counted, each
1127
1128
  one's count is listed under the bar.
1129
+
1130
+ ## Values edited in place: the presets' looks
1131
+
1132
+ The `inPlace` presets (cell pattern 18, "Presets") draw a value the same
1133
+ way everywhere it's edited in place, so a record's view reads alike
1134
+ across apps. Their fixture is `app/EditInPlacePresets`, axe-checked in
1135
+ both themes and every palette.
1136
+
1137
+ - **Money** reads as the currency formats it, `$1,234.56`, two decimals
1138
+ always; its box has the symbol before it (an `InputGroup` addon in the
1139
+ muted text tone), as `FillInInput`'s money does.
1140
+ - **A number with a unit** reads `12 h`, the unit after a space; its box
1141
+ has the unit after it, in the same addon tone.
1142
+ - **A date** reads `Sep 2, 2026` (`dateStyle: 'medium'`), never shifted
1143
+ by the time zone.
1144
+ - **A select** reads as its option's label, or as the app's `render`
1145
+ (a badge in its tone), the same on the trigger and in the list.
1146
+ - **A link** reads as its label, else the address's host, in `--link`,
1147
+ underlined, with the external-link mark: `LinkOut`, LinkCell's look.
1148
+ - **Several fields edited as one** read at rest as their values joined
1149
+ by " · " (`Small · Low`). Open, each part has its label over it in
1150
+ `type-caption text-muted-foreground`, and a part's refusal under it in
1151
+ the destructive text tone, as a form field's; the pair's own refusal is
1152
+ under them all.
1153
+ - **A list in place under group headings** heads each group in
1154
+ `type-label text-muted-foreground` (an `<h3>` under the section's
1155
+ title), with `gap-4` between groups and the list's own `gap-2` inside.
@@ -0,0 +1,34 @@
1
+ import { type ReactNode } from 'react';
2
+ import type { EditControlProps, EditKind } from './edit-in-place.js';
3
+ import type { InPlacePart, InPlaceReferenceConfig } from './edit-in-place-presets.js';
4
+ export type Checked<TValue> = {
5
+ ok: true;
6
+ value: TValue;
7
+ } | {
8
+ ok: false;
9
+ message: string;
10
+ };
11
+ export type Kind<TValue, TDraft> = {
12
+ editKind: EditKind;
13
+ toDraft: (value: TValue) => TDraft;
14
+ check: (draft: TDraft) => Checked<TValue>;
15
+ show: (value: TValue) => ReactNode;
16
+ control: (props: EditControlProps<TDraft>, alone: boolean) => ReactNode;
17
+ };
18
+ export type AnyKind = Kind<any, any>;
19
+ /** A select's and a combobox's items are strings: the option's position, or this for "Not set". */
20
+ export declare const NONE = "none";
21
+ type ReferencePickerProps<Id extends string | number> = {
22
+ props: EditControlProps<Id | null>;
23
+ alone: boolean;
24
+ config: InPlaceReferenceConfig<Id>;
25
+ };
26
+ export declare function ReferencePicker<Id extends string | number>({ props, alone, config }: ReferencePickerProps<Id>): import("react").JSX.Element;
27
+ type PartsProps = {
28
+ props: EditControlProps<Record<string, unknown>>;
29
+ keys: readonly string[];
30
+ parts: Record<string, InPlacePart>;
31
+ kinds: Record<string, AnyKind>;
32
+ };
33
+ export declare function Parts({ props, keys, parts, kinds }: PartsProps): import("react").JSX.Element;
34
+ export {};