@tristan2828/ui-foundation 4.71.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.
- package/conventions/docs/add-an-entity.md +21 -15
- package/conventions/docs/cell-patterns.md +210 -37
- package/conventions/docs/design-language.md +52 -24
- package/dist/components/app/edit-in-place-controls.d.ts +34 -0
- package/dist/components/app/edit-in-place-controls.js +92 -0
- package/dist/components/app/edit-in-place-presets.d.ts +187 -0
- package/dist/components/app/edit-in-place-presets.js +409 -0
- package/dist/components/app/edit-in-place-store.d.ts +9 -0
- package/dist/components/app/edit-in-place-store.js +14 -7
- package/dist/components/app/edit-in-place.d.ts +101 -4
- package/dist/components/app/editable-list.js +158 -23
- package/dist/components/app/editable-value.d.ts +2 -2
- package/dist/components/app/editable-value.js +7 -3
- package/dist/components/app/entity-view.d.ts +6 -2
- package/dist/components/app/entity-view.js +11 -2
- package/dist/components/app/row-edit-cells.d.ts +9 -0
- package/dist/components/app/row-edit-cells.js +12 -16
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3 -1
- package/dist/lib/link-href.d.ts +28 -0
- package/dist/lib/link-href.js +40 -0
- package/package.json +1 -1
|
@@ -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–
|
|
7
|
+
- [Before anything: the entity plan](#before-anything-the-entity-plan) · lines 65–758
|
|
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–
|
|
14
|
-
- Step 7: Register routes · lines
|
|
15
|
-
- Step 8: Add Playwright specs for all three screens · lines
|
|
16
|
-
- Step 9: Register the nav entry and route names · lines
|
|
17
|
-
- Step 10: `npm run verify`. · lines
|
|
18
|
-
- [How a list opens a record](#how-a-list-opens-a-record) · lines
|
|
19
|
-
- [The record view](#the-record-view) · lines
|
|
20
|
-
- [What not to copy](#what-not-to-copy) · lines
|
|
21
|
-
- [After a commit, in the backend](#after-a-commit-in-the-backend) · lines
|
|
22
|
-
- [Deleting](#deleting) · lines
|
|
23
|
-
- [Fields only a script writes](#fields-only-a-script-writes) · lines
|
|
24
|
-
- [Searching one part of the app](#searching-one-part-of-the-app) · lines
|
|
25
|
-
- [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines
|
|
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
|
|
26
26
|
|
|
27
27
|
<!-- /index -->
|
|
28
28
|
|
|
@@ -547,7 +547,13 @@ is a filled-in example while the Widgets demo is still here).
|
|
|
547
547
|
ids as a set; a field the plan marks `small` is `MultiPick`, on the
|
|
548
548
|
form too, every option loaded once, and saves each click itself:
|
|
549
549
|
`value` is the record's, `onPick` the single-field save as a
|
|
550
|
-
function of the record, cell pattern 18 "A small set"). A
|
|
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`,
|
|
551
557
|
the title gets `titleEdit={{ label, ...edit }}`, and a header badge
|
|
552
558
|
wraps itself in `<EditableValue label edit layout="inline">`. The
|
|
553
559
|
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
|
|
7
|
-
- [1. Plain text](#1-plain-text) · lines
|
|
8
|
-
- [2. Icon + label](#2-icon--label) · lines
|
|
9
|
-
- [3. Icon in a badge](#3-icon-in-a-badge) · lines
|
|
10
|
-
- [4. Icon only, label in a tooltip](#4-icon-only-label-in-a-tooltip) · lines
|
|
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
|
|
12
|
-
- [5. Enum → tone-mapped badge](#5-enum--tone-mapped-badge) · lines
|
|
13
|
-
- [6. Multi-value enum, clustered](#6-multi-value-enum-clustered) · lines
|
|
14
|
-
- [7. Link as an outline button](#7-link-as-an-outline-button) · lines
|
|
15
|
-
- [8. Date, relative](#8-date-relative) · lines
|
|
16
|
-
- [9. Ordinal scale (bounded integer)](#9-ordinal-scale-bounded-integer) · lines
|
|
17
|
-
- [Two variants the package draws: a step bar and a star](#two-variants-the-package-draws-a-step-bar-and-a-star) · lines
|
|
18
|
-
- [10. Summary in the cell, detail in a popover](#10-summary-in-the-cell-detail-in-a-popover) · lines
|
|
19
|
-
- [A second example: what a row depends on](#a-second-example-what-a-row-depends-on) · lines
|
|
20
|
-
- [11. Number or currency — Unproven](#11-number-or-currency--unproven) · lines
|
|
21
|
-
- [12. Boolean](#12-boolean) · lines
|
|
22
|
-
- [13. Progress bar — Unproven](#13-progress-bar--unproven) · lines
|
|
23
|
-
- [The compact form: `ProgressRing`](#the-compact-form-progressring) · lines
|
|
24
|
-
- [14. Avatar and name — Unproven](#14-avatar-and-name--unproven) · lines
|
|
25
|
-
- [15. Yes/no you flip in the row](#15-yesno-you-flip-in-the-row) · lines
|
|
26
|
-
- [A variant: a pressed icon inside another value's cell](#a-variant-a-pressed-icon-inside-another-values-cell) · lines
|
|
27
|
-
- [16. Title linking to the record's view](#16-title-linking-to-the-records-view) · lines
|
|
28
|
-
- [17. Quick action on the view](#17-quick-action-on-the-view) · lines
|
|
29
|
-
- [18. Editable value](#18-editable-value) · lines
|
|
30
|
-
- [
|
|
31
|
-
- [
|
|
32
|
-
- [A
|
|
33
|
-
- [
|
|
34
|
-
- [
|
|
35
|
-
- [
|
|
36
|
-
- [
|
|
37
|
-
- [
|
|
38
|
-
- [
|
|
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
|
|
779
|
-
|
|
780
|
-
|
|
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
|
|
7
|
-
- [Glow](#glow) · lines
|
|
8
|
-
- [Semantic tones](#semantic-tones) · lines
|
|
9
|
-
- [The three badge styles](#the-three-badge-styles) · lines
|
|
10
|
-
- [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines
|
|
11
|
-
- [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines
|
|
12
|
-
- [Logos and brand marks](#logos-and-brand-marks) · lines
|
|
13
|
-
- [Categorical colour](#categorical-colour) · lines
|
|
14
|
-
- [A stored colour](#a-stored-colour) · lines
|
|
15
|
-
- [Shapes and sizes](#shapes-and-sizes) · lines
|
|
16
|
-
- [Typography](#typography) · lines
|
|
17
|
-
- [Written text (notes)](#written-text-notes) · lines
|
|
18
|
-
- [Density](#density) · lines
|
|
19
|
-
- [Rows on this device](#rows-on-this-device) · lines
|
|
20
|
-
- [Widget cards (hub pages)](#widget-cards-hub-pages) · lines
|
|
21
|
-
- [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines
|
|
22
|
-
- [Notices](#notices) · lines
|
|
23
|
-
- [A value over time](#a-value-over-time) · lines
|
|
24
|
-
- [Several values over time](#several-values-over-time) · lines
|
|
25
|
-
- [A list as a board](#a-list-as-a-board) · lines
|
|
26
|
-
- [A list as cards](#a-list-as-cards) · lines
|
|
27
|
-
- [Key numbers on a record](#key-numbers-on-a-record) · lines
|
|
28
|
-
- [Picking at random](#picking-at-random) · lines
|
|
29
|
-
- [Filling in what's missing](#filling-in-whats-missing) · lines
|
|
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 {};
|
|
@@ -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
|
+
}
|