@tristan2828/ui-foundation 4.71.0 → 4.73.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 (50) hide show
  1. package/conventions/docs/add-an-entity.md +45 -15
  2. package/conventions/docs/cell-patterns.md +210 -37
  3. package/conventions/docs/design-language.md +64 -24
  4. package/dist/components/app/edit-in-place-controls.d.ts +34 -0
  5. package/dist/components/app/edit-in-place-controls.js +92 -0
  6. package/dist/components/app/edit-in-place-presets.d.ts +187 -0
  7. package/dist/components/app/edit-in-place-presets.js +409 -0
  8. package/dist/components/app/edit-in-place-store.d.ts +9 -0
  9. package/dist/components/app/edit-in-place-store.js +14 -7
  10. package/dist/components/app/edit-in-place.d.ts +101 -4
  11. package/dist/components/app/editable-list.js +158 -23
  12. package/dist/components/app/editable-value.d.ts +2 -2
  13. package/dist/components/app/editable-value.js +7 -3
  14. package/dist/components/app/entity-view.d.ts +6 -2
  15. package/dist/components/app/entity-view.js +11 -2
  16. package/dist/components/app/markdown.d.ts +13 -1
  17. package/dist/components/app/markdown.js +43 -8
  18. package/dist/components/app/milkdown-editor.d.ts +1 -1
  19. package/dist/components/app/milkdown-editor.js +184 -19
  20. package/dist/components/app/page-link.d.ts +13 -0
  21. package/dist/components/app/page-link.js +44 -0
  22. package/dist/components/app/page-restore.d.ts +3 -0
  23. package/dist/components/app/page-restore.js +14 -0
  24. package/dist/components/app/page-trail.d.ts +17 -0
  25. package/dist/components/app/page-trail.js +71 -0
  26. package/dist/components/app/rich-text-editor.d.ts +22 -0
  27. package/dist/components/app/rich-text-editor.js +8 -0
  28. package/dist/components/app/rich-text-floating-toolbar.d.ts +3 -1
  29. package/dist/components/app/rich-text-floating-toolbar.js +2 -2
  30. package/dist/components/app/rich-text-page-links.d.ts +44 -0
  31. package/dist/components/app/rich-text-page-links.js +201 -0
  32. package/dist/components/app/rich-text-slash-menu.d.ts +3 -4
  33. package/dist/components/app/rich-text-slash.d.ts +12 -3
  34. package/dist/components/app/rich-text-slash.js +16 -5
  35. package/dist/components/app/rich-text-toolbar.d.ts +3 -1
  36. package/dist/components/app/rich-text-toolbar.js +10 -7
  37. package/dist/components/app/row-edit-cells.d.ts +9 -0
  38. package/dist/components/app/row-edit-cells.js +12 -16
  39. package/dist/components/ui/breadcrumb.d.ts +10 -0
  40. package/dist/components/ui/breadcrumb.js +37 -0
  41. package/dist/index.d.ts +5 -1
  42. package/dist/index.js +4 -1
  43. package/dist/lib/link-href.d.ts +28 -0
  44. package/dist/lib/link-href.js +40 -0
  45. package/dist/lib/page-link.d.ts +40 -0
  46. package/dist/lib/page-link.js +32 -0
  47. package/dist/lib/page-trail.d.ts +7 -0
  48. package/dist/lib/page-trail.js +24 -0
  49. package/package.json +1 -1
  50. package/styles/index.css +63 -0
@@ -4,25 +4,25 @@
4
4
  ## Index
5
5
 
6
6
  - [The reference files](#the-reference-files) · lines 41–63
7
- - [Before anything: the entity plan](#before-anything-the-entity-plan) · lines 65–752
7
+ - [Before anything: the entity plan](#before-anything-the-entity-plan) · lines 65–782
8
8
  - Step 1: Add `<Entity>` to `openapi.yaml` · lines 107–114
9
9
  - Step 2: `npm run gen:api` · lines 115–116
10
10
  - Step 3: Add gateway tests in `tests/gateway/<entity>.test.ts`, derived from the spec · lines 117–128
11
11
  - Step 4: Add MSW handlers in `src/mocks/<entity>.ts` · lines 129–138
12
12
  - Step 5: Add a gateway module in `src/api/gateway/<entity>.ts` · lines 139–143
13
- - Step 6: Copy the reference files, one for one, not just the two screens · lines 144–639
14
- - Step 7: Register routes · lines 640–655
15
- - Step 8: Add Playwright specs for all three screens · lines 656–734
16
- - Step 9: Register the nav entry and route names · lines 735–749
17
- - Step 10: `npm run verify`. · lines 750–752
18
- - [How a list opens a record](#how-a-list-opens-a-record) · lines 754–892
19
- - [The record view](#the-record-view) · lines 867–892
20
- - [What not to copy](#what-not-to-copy) · lines 894–920
21
- - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 922–939
22
- - [Deleting](#deleting) · lines 941–970
23
- - [Fields only a script writes](#fields-only-a-script-writes) · lines 972–993
24
- - [Searching one part of the app](#searching-one-part-of-the-app) · lines 995–1004
25
- - [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1007–1046
13
+ - Step 6: Copy the reference files, one for one, not just the two screens · lines 144–669
14
+ - Step 7: Register routes · lines 670–685
15
+ - Step 8: Add Playwright specs for all three screens · lines 686–764
16
+ - Step 9: Register the nav entry and route names · lines 765–779
17
+ - Step 10: `npm run verify`. · lines 780–782
18
+ - [How a list opens a record](#how-a-list-opens-a-record) · lines 784–922
19
+ - [The record view](#the-record-view) · lines 897–922
20
+ - [What not to copy](#what-not-to-copy) · lines 924–950
21
+ - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 952–969
22
+ - [Deleting](#deleting) · lines 971–1000
23
+ - [Fields only a script writes](#fields-only-a-script-writes) · lines 1002–1023
24
+ - [Searching one part of the app](#searching-one-part-of-the-app) · lines 1025–1034
25
+ - [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1037–1076
26
26
 
27
27
  <!-- /index -->
28
28
 
@@ -502,6 +502,30 @@ is a filled-in example while the Widgets demo is still here).
502
502
  (`useEdit<Entity>Field`). Without the prop the boxes are pictures
503
503
  and the text stays read-only. A list's "2/5" column counts them
504
504
  with `countTasks(text)` (`{ done, total }`; `total` 0 for none).
505
+ - **Pages in the notes** (a record's notes linking to pages of their
506
+ own, each a title and its own Markdown at its own URL, and a page's
507
+ notes linking to pages under it, to any depth): the app keeps the
508
+ pages (a table, an API, a screen per page); the foundation only
509
+ draws and makes the links. A page is linked by an ordinary Markdown
510
+ link, `[Getting Started](/notes/12/pages/3)`, so the notes stay
511
+ Markdown and nothing about how they're stored changes. Give
512
+ `<Markdown>` and `RichTextEditor` the same `pageLink={(href) => …}`:
513
+ return `{ title, removed, onRestore }` for an address that is one of
514
+ the app's pages (look it up in the record's pages, already loaded),
515
+ `null` for any other link. A page link shows the page icon and the
516
+ page's title and opens it in this tab; alone on its line it's a row
517
+ of its own; a removed page (soft-deleted) shows "Page removed" and,
518
+ with `onRestore` (the app's undelete, returning its promise),
519
+ Restore. Give the editor `onCreatePage={(title) => createPage(title).then((page) => pagePath(page))}`
520
+ too: "/page" (and Turn into page on selected words) asks for a
521
+ title, awaits the new page's address and puts in the link; a
522
+ rejection shows in the title box in the gateway's words and leaves
523
+ the text as it was. The page's own screen puts `PageTrail` above its
524
+ title (`crumbs`: the list, the record, every page above this one,
525
+ then this one, last, with no `href`): it folds the middle into a "…"
526
+ menu when it doesn't fit. A page's notes take the same two props, so
527
+ nothing assumes one level: the app decides where a new page lives
528
+ (under the record, or under the page whose note it's in).
505
529
  - **Notes worth taking on paper** (a visit's prep and questions, a
506
530
  guide, a checklist to tick by hand): mark each of those sections
507
531
  `print: true`. The header gets a Print notes button (`printLabel`
@@ -547,7 +571,13 @@ is a filled-in example while the Widgets demo is still here).
547
571
  ids as a set; a field the plan marks `small` is `MultiPick`, on the
548
572
  form too, every option loaded once, and saves each click itself:
549
573
  `value` is the record's, `onPick` the single-field save as a
550
- function of the record, cell pattern 18 "A small set"). A field gets `edit`, a `content` section gets `edit`,
574
+ function of the record, cell pattern 18 "A small set"). A plain
575
+ text, number, money, date, single choice or single reference whose
576
+ form control is a plain box (no control of the entity's own) can be
577
+ the package's preset instead, one line with no control to wrap:
578
+ `{ label, edit: inPlace.money({ value, save }) }` (cell pattern 18,
579
+ "Presets"); a link with a label is `inPlace.link`, and two fields
580
+ that must agree are `inPlace.fields` with its `rule`. A field gets `edit`, a `content` section gets `edit`,
551
581
  the title gets `titleEdit={{ label, ...edit }}`, and a header badge
552
582
  wraps itself in `<EditableValue label edit layout="inline">`. The
553
583
  shown value stays exactly as before. A sub-record list the line
@@ -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–520
17
+ - [Written text (notes)](#written-text-notes) · lines 448–520
18
+ - [Density](#density) · lines 522–608
19
+ - [Rows on this device](#rows-on-this-device) · lines 581–608
20
+ - [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 610–724
21
+ - [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 726–795
22
+ - [Notices](#notices) · lines 797–825
23
+ - [A value over time](#a-value-over-time) · lines 827–913
24
+ - [Several values over time](#several-values-over-time) · lines 876–913
25
+ - [A list as a board](#a-list-as-a-board) · lines 915–966
26
+ - [A list as cards](#a-list-as-cards) · lines 968–1014
27
+ - [Key numbers on a record](#key-numbers-on-a-record) · lines 1016–1038
28
+ - [Picking at random](#picking-at-random) · lines 1040–1071
29
+ - [Filling in what's missing](#filling-in-whats-missing) · lines 1073–1140
30
+ - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1142–1167
30
31
 
31
32
  <!-- /index -->
32
33
 
@@ -493,6 +494,18 @@ shade: note `info`, tip `success`, important category slot 2, warning
493
494
  `warning`, caution `destructive`. The package draws all of it; an app
494
495
  only renders `<Markdown>` or the editor.
495
496
 
497
+ A page link (a link the app marks as one of its pages, `pageLink`) is the
498
+ page icon in `--muted-foreground`, then the title in the text's own
499
+ colour at medium weight, underlined in `--muted-foreground` (the colour
500
+ of the words around it, so the underline is what tells it apart). Alone
501
+ on its line it's a page line, a row that tints `--muted` on hover. A
502
+ removed page is muted and struck through, "Page removed" beside it in
503
+ the caption size, with an outline `xs` Restore button. Both renderers
504
+ draw it from the same CSS (styles/index.css "Page links in written
505
+ text"). The trail back from a page, `PageTrail`, is shadcn's Breadcrumb:
506
+ crumbs in `--muted-foreground`, the page itself in `--foreground`, on
507
+ one line, the middle folded into a "…" menu when it doesn't fit.
508
+
496
509
  Highlighted words (`==words==` in the Markdown) have four colour tokens:
497
510
  `--highlight-amber` (the default), `--highlight-yellow`,
498
511
  `--highlight-green` and `--highlight-red` (`bg-highlight-amber`, …). Each
@@ -1125,3 +1138,30 @@ size"); the list stays where a record is edited one field at a time.
1125
1138
  progress }`) and `getGroup` name a record's source above its heading,
1126
1139
  with that group's own count; with more than one group counted, each
1127
1140
  one's count is listed under the bar.
1141
+
1142
+ ## Values edited in place: the presets' looks
1143
+
1144
+ The `inPlace` presets (cell pattern 18, "Presets") draw a value the same
1145
+ way everywhere it's edited in place, so a record's view reads alike
1146
+ across apps. Their fixture is `app/EditInPlacePresets`, axe-checked in
1147
+ both themes and every palette.
1148
+
1149
+ - **Money** reads as the currency formats it, `$1,234.56`, two decimals
1150
+ always; its box has the symbol before it (an `InputGroup` addon in the
1151
+ muted text tone), as `FillInInput`'s money does.
1152
+ - **A number with a unit** reads `12 h`, the unit after a space; its box
1153
+ has the unit after it, in the same addon tone.
1154
+ - **A date** reads `Sep 2, 2026` (`dateStyle: 'medium'`), never shifted
1155
+ by the time zone.
1156
+ - **A select** reads as its option's label, or as the app's `render`
1157
+ (a badge in its tone), the same on the trigger and in the list.
1158
+ - **A link** reads as its label, else the address's host, in `--link`,
1159
+ underlined, with the external-link mark: `LinkOut`, LinkCell's look.
1160
+ - **Several fields edited as one** read at rest as their values joined
1161
+ by " · " (`Small · Low`). Open, each part has its label over it in
1162
+ `type-caption text-muted-foreground`, and a part's refusal under it in
1163
+ the destructive text tone, as a form field's; the pair's own refusal is
1164
+ under them all.
1165
+ - **A list in place under group headings** heads each group in
1166
+ `type-label text-muted-foreground` (an `<h3>` under the section's
1167
+ 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 {};
@@ -0,0 +1,92 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // The controls behind the `inPlace` presets that hold state or lay out
3
+ // several parts (edit-in-place-presets.tsx), kept in a file of their own
4
+ // so the presets' file exports no components.
5
+ import { useEffect, useRef, useState } from 'react';
6
+ import { Combobox, ComboboxContent, ComboboxEmpty, ComboboxInput, ComboboxItem, ComboboxList } from '../ui/combobox.js';
7
+ import { FieldError } from '../ui/field.js';
8
+ /** A select's and a combobox's items are strings: the option's position, or this for "Not set". */
9
+ export const NONE = 'none';
10
+ function controlAria(props) {
11
+ return {
12
+ 'aria-label': props.label,
13
+ 'aria-describedby': props.describedBy,
14
+ 'aria-invalid': props.invalid || undefined,
15
+ };
16
+ }
17
+ // How long typing pauses before the search runs.
18
+ const SEARCH_DELAY_MS = 200;
19
+ // The reference's combobox: what's typed searches (through the app's
20
+ // `search`), a pick is the record's id. Names come from the searches and
21
+ // from the saved record's `label`, so a pick the current search no longer
22
+ // returns still shows its name.
23
+ export function ReferencePicker({ props, alone, config }) {
24
+ const [text, setText] = useState('');
25
+ const [found, setFound] = useState([]);
26
+ const [names] = useState(() => new Map());
27
+ if (props.value != null && config.label !== undefined && !names.has(String(props.value)))
28
+ names.set(String(props.value), { id: props.value, label: config.label });
29
+ for (const record of found)
30
+ names.set(String(record.id), record);
31
+ // The search is the app's, often a new function each render: the
32
+ // latest is called, and only what's typed starts a search.
33
+ const search = useRef(config.search);
34
+ useEffect(() => {
35
+ search.current = config.search;
36
+ });
37
+ useEffect(() => {
38
+ let live = true;
39
+ const timer = setTimeout(() => {
40
+ search.current(text).then((records) => {
41
+ if (live)
42
+ setFound(records);
43
+ }, () => {
44
+ if (live)
45
+ setFound([]);
46
+ });
47
+ }, text === '' ? 0 : SEARCH_DELAY_MS);
48
+ return () => {
49
+ live = false;
50
+ clearTimeout(timer);
51
+ };
52
+ }, [text]);
53
+ const picked = props.value == null ? null : String(props.value);
54
+ const items = [...(config.required ? [] : [NONE]), ...found.map((record) => String(record.id))];
55
+ const emptyLabel = config.emptyLabel ?? 'Not set';
56
+ const nameOf = (key) => (key === NONE ? '' : (names.get(key)?.label ?? ''));
57
+ return (_jsxs(Combobox, { items: items, value: picked, onValueChange: (key) => {
58
+ if (key == null)
59
+ return;
60
+ const id = key === NONE ? null : (names.get(key)?.id ?? null);
61
+ if (alone)
62
+ props.commit(id);
63
+ else
64
+ props.onChange(id);
65
+ },
66
+ // The box showing the pick's own name is no search: the list then
67
+ // offers everything, not only the one already picked.
68
+ onInputValueChange: (typed) => setText(picked !== null && typed === nameOf(picked) ? '' : typed), itemToStringLabel: nameOf, filter: null, readOnly: props.disabled, defaultOpen: alone, children: [_jsx(ComboboxInput, { id: props.id, placeholder: config.placeholder ?? 'Search', ...controlAria(props) }), _jsxs(ComboboxContent, { children: [_jsx(ComboboxEmpty, { children: config.emptyText ?? 'No matches.' }), _jsx(ComboboxList, { children: items.map((key) => (_jsx(ComboboxItem, { value: key, children: key === NONE ? emptyLabel : nameOf(key) }, key))) })] })] }));
69
+ }
70
+ // The parts side by side (stacked when the field is narrow), each with its
71
+ // own label over its control and its own refusal under it. A refusal
72
+ // about none of them (the rule across them) is the field's, under them all.
73
+ export function Parts({ props, keys, parts, kinds }) {
74
+ const errors = props.errors;
75
+ return (_jsx("span", { className: "flex flex-wrap items-start gap-3", children: keys.map((key) => {
76
+ const part = parts[key];
77
+ const partId = `${props.id}-${key}`;
78
+ const errorId = `${partId}-error`;
79
+ const error = errors?.[key];
80
+ return (_jsxs("span", { "data-part": key, className: "flex min-w-40 flex-1 flex-col gap-1", children: [_jsx("span", { "aria-hidden": "true", className: "type-caption text-muted-foreground", children: part.label }), kinds[key].control({
81
+ ...props,
82
+ // The first part takes the field's id, so its label points at it.
83
+ id: key === keys[0] ? props.id : partId,
84
+ label: part.label,
85
+ value: props.value[key],
86
+ onChange: (next) => props.onChange({ ...props.value, [key]: next }),
87
+ invalid: Boolean(error) || (props.invalid && !errors),
88
+ describedBy: error ? `${errorId} ${props.describedBy}` : props.describedBy,
89
+ errors: undefined,
90
+ }, false), error && (_jsx(FieldError, { id: errorId, className: "type-caption", children: error }))] }, key));
91
+ }) }));
92
+ }