@tristan2828/ui-foundation 4.94.0 → 4.96.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.
@@ -219,7 +219,11 @@ function checkContract(specPath) {
219
219
  for (const [name, entry] of Object.entries(entries)) {
220
220
  const appEntry = app.components?.[section]?.[name]
221
221
  if (appEntry === undefined) {
222
- if (!optionalOnly.has(`${section}/${name}`)) problems.push(`missing components.${section}.${name}`)
222
+ // A component marked x-optional (Recurrence) is one an app's own
223
+ // schemas may reference; no path here needs it.
224
+ if (!entry['x-optional'] && !optionalOnly.has(`${section}/${name}`)) {
225
+ problems.push(`missing components.${section}.${name}`)
226
+ }
223
227
  } else if (!same(appEntry, entry)) {
224
228
  problems.push(`components.${section}.${name} differs`)
225
229
  }
@@ -4,28 +4,28 @@
4
4
  ## Index
5
5
 
6
6
  - [The reference files](#the-reference-files) · lines 44–66
7
- - [Before anything: the entity plan](#before-anything-the-entity-plan) · lines 68–832
7
+ - [Before anything: the entity plan](#before-anything-the-entity-plan) · lines 68–848
8
8
  - Step 1: Add `<Entity>` to `openapi.yaml` · lines 110–117
9
9
  - Step 2: `npm run gen:api` · lines 118–119
10
10
  - Step 3: Add gateway tests in `tests/gateway/<entity>.test.ts`, derived from the spec · lines 120–131
11
11
  - Step 4: Add MSW handlers in `src/mocks/<entity>.ts` · lines 132–141
12
12
  - Step 5: Add a gateway module in `src/api/gateway/<entity>.ts` · lines 142–146
13
- - Step 6: Copy the reference files, one for one, not just the two screens · lines 147–719
14
- - Step 7: Register routes · lines 720–735
15
- - Step 8: Add Playwright specs for all three screens · lines 736–814
16
- - Step 9: Register the nav entry and route names · lines 815–829
17
- - Step 10: `npm run verify`. · lines 830–832
18
- - [How a list opens a record](#how-a-list-opens-a-record) · lines 834–1153
19
- - [The record view](#the-record-view) · lines 983–1031
20
- - [Forms](#forms) · lines 1033–1085
21
- - [Dialogs](#dialogs) · lines 1087–1112
22
- - [Toasts and feedback](#toasts-and-feedback) · lines 1114–1153
23
- - [What not to copy](#what-not-to-copy) · lines 1155–1181
24
- - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 1183–1200
25
- - [Deleting](#deleting) · lines 1202–1233
26
- - [Fields only a script writes](#fields-only-a-script-writes) · lines 1235–1256
27
- - [Searching one part of the app](#searching-one-part-of-the-app) · lines 1258–1267
28
- - [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1270–1312
13
+ - Step 6: Copy the reference files, one for one, not just the two screens · lines 147–735
14
+ - Step 7: Register routes · lines 736–751
15
+ - Step 8: Add Playwright specs for all three screens · lines 752–830
16
+ - Step 9: Register the nav entry and route names · lines 831–845
17
+ - Step 10: `npm run verify`. · lines 846–848
18
+ - [How a list opens a record](#how-a-list-opens-a-record) · lines 850–1178
19
+ - [The record view](#the-record-view) · lines 999–1047
20
+ - [Forms](#forms) · lines 1049–1101
21
+ - [Dialogs](#dialogs) · lines 1103–1128
22
+ - [Toasts and feedback](#toasts-and-feedback) · lines 1130–1178
23
+ - [What not to copy](#what-not-to-copy) · lines 1180–1206
24
+ - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 1208–1225
25
+ - [Deleting](#deleting) · lines 1227–1258
26
+ - [Fields only a script writes](#fields-only-a-script-writes) · lines 1260–1281
27
+ - [Searching one part of the app](#searching-one-part-of-the-app) · lines 1283–1292
28
+ - [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1295–1337
29
29
 
30
30
  <!-- /index -->
31
31
 
@@ -252,6 +252,22 @@ is a filled-in example while the Widgets demo is still here).
252
252
  written, and the field shows it as written with nothing picked, refused
253
253
  until a day is picked.
254
254
 
255
+ **A `recurrence`** (how something repeats: a chore, a reminder, a
256
+ task) is the foundation's `Recurrence` schema: copy it from the
257
+ package's `openapi/foundation.yaml` into `components.schemas` (it's
258
+ `x-optional`, so `check-contract` holds it to the foundation's shape
259
+ once it's there) and reference it, nullable when it may not repeat.
260
+ On the form it's the foundation's `RecurrenceField` in a `Controller`
261
+ (presets, a phrase read as it's typed, and a preview of the next five);
262
+ the schema checks it with `recurrenceProblem(value)`, and a phrase the
263
+ field can't read gives `null`, so a required one is refused. The table
264
+ shows `formatRecurrence(value)` and a Next column (cell pattern 27);
265
+ editing in place is `inPlace.recurrence({ value, save })`. The backend
266
+ column is JSON, read and checked with
267
+ `foundation_backend.recurrence.Recurrence` (a 422 on the field for a
268
+ rule it refuses); `next_after` and `occurrences` say when it falls
269
+ (reminders.md "Repeating reminders").
270
+
255
271
  **An image on a record** (a photo of it) is the stored file's id on the
256
272
  wire (`string`, nullable), and on the form the foundation's
257
273
  `ImageField` in a `Controller` (`z.string().nullable()`): `value` and
@@ -1138,6 +1154,15 @@ sight.** What happened where the person is looking says so there.
1138
1154
  `open`/`onOpenChange`, opened by a `DataTable` `rowActions` entry's
1139
1155
  `onSelect` (a row's ⋯ menu). `verb="Retire"` for a retire.
1140
1156
  Never a delete without a confirm, never a hand-written dialog.
1157
+ - **A delete that asks a reason: `DeleteAction reason`** (4.96). One
1158
+ optional field between the sentence and the buttons, a "Why" box:
1159
+ `reason={{ label: 'Why remove it?', hint: 'Kept with its history.' }}`
1160
+ and `onDelete={(why) => remove({ id, reason: why })}`, `why` trimmed
1161
+ and `''` when nothing's typed. The rest is the same confirm: 420px, a
1162
+ bottom sheet on a phone, Cancel then the filled destructive button, a
1163
+ refusal in the dialog with Try again (sending the same words), and
1164
+ closing with something typed asks "Discard your changes?" first. One
1165
+ field only: a confirm that needs more is a `FormDialog`.
1141
1166
  - **A toast's words come from `notify.done(verb, name, { undo })`**: the
1142
1167
  verb first, "Deleted The Long Walk", "Added Paper Atlas"; Undo, when
1143
1168
  given, then says "Restored The Long Walk". Never "X deleted", never
@@ -3,45 +3,46 @@
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 73–92
7
- - [1. Plain text](#1-plain-text) · lines 94–147
8
- - [2. Icon + label](#2-icon--label) · lines 149–172
9
- - [3. Icon in a badge](#3-icon-in-a-badge) · lines 174–187
10
- - [4. Icon only, label in a tooltip](#4-icon-only-label-in-a-tooltip) · lines 189–266
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 214–266
12
- - [5. Enum → tone-mapped badge](#5-enum--tone-mapped-badge) · lines 268–281
13
- - [6. Multi-value enum, clustered](#6-multi-value-enum-clustered) · lines 283–295
14
- - [7. Link as an outline button](#7-link-as-an-outline-button) · lines 297–318
15
- - [8. Date, relative](#8-date-relative) · lines 320–357
16
- - [9. Ordinal scale (bounded integer)](#9-ordinal-scale-bounded-integer) · lines 359–407
17
- - [Two variants the package draws: a step bar and a star](#two-variants-the-package-draws-a-step-bar-and-a-star) · lines 377–407
18
- - [10. Summary in the cell, detail in a popover](#10-summary-in-the-cell-detail-in-a-popover) · lines 409–459
19
- - [A second example: what a row depends on](#a-second-example-what-a-row-depends-on) · lines 427–459
20
- - [11. Number or currency — Unproven](#11-number-or-currency--unproven) · lines 461–501
21
- - [12. Boolean](#12-boolean) · lines 503–533
22
- - [13. Progress bar — Unproven](#13-progress-bar--unproven) · lines 535–571
23
- - [The compact form: `ProgressRing`](#the-compact-form-progressring) · lines 555–571
24
- - [14. Avatar and name — Unproven](#14-avatar-and-name--unproven) · lines 573–590
25
- - [15. Yes/no you flip in the row](#15-yesno-you-flip-in-the-row) · lines 592–701
26
- - [A variant: a pressed icon inside another value's cell](#a-variant-a-pressed-icon-inside-another-values-cell) · lines 618–701
27
- - [16. Title linking to the record's view](#16-title-linking-to-the-records-view) · lines 703–738
28
- - [17. Quick action on the view](#17-quick-action-on-the-view) · lines 740–813
29
- - [18. Editable value](#18-editable-value) · lines 815–1493
30
- - [Presets: one line per field](#presets-one-line-per-field) · lines 1125–1193
31
- - [Several fields edited as one](#several-fields-edited-as-one) · lines 1195–1231
32
- - [A link and its label](#a-link-and-its-label) · lines 1233–1257
33
- - [A list of sub-items](#a-list-of-sub-items) · lines 1259–1392
34
- - [In a table's rows](#in-a-tables-rows) · lines 1394–1479
35
- - [A table of a few short columns: `width="content"`](#a-table-of-a-few-short-columns-widthcontent) · lines 1481–1493
36
- - [19. Stage circle for an ordered status](#19-stage-circle-for-an-ordered-status) · lines 1495–1561
37
- - [20. Count linking to the related records](#20-count-linking-to-the-related-records) · lines 1563–1627
38
- - [21. Rows grouped under headings, and a pill filter](#21-rows-grouped-under-headings-and-a-pill-filter) · lines 1629–1727
39
- - [22. A highlighted row, and rows that are done](#22-a-highlighted-row-and-rows-that-are-done) · lines 1729–1758
40
- - [24. A list's rows: hover, lines, rows per page](#24-a-lists-rows-hover-lines-rows-per-page) · lines 1760–1798
41
- - [23. A Group menu, and a record read beside the list](#23-a-group-menu-and-a-record-read-beside-the-list) · lines 1800–1876
42
- - [24. A stored colour beside its name](#24-a-stored-colour-beside-its-name) · lines 1878–1901
43
- - [25. A list's tools: views, filters, columns, row actions, a phone's rows](#25-a-lists-tools-views-filters-columns-row-actions-a-phones-rows) · lines 1903–1989
44
- - [26. A record's related list, capped](#26-a-records-related-list-capped) · lines 1991–2027
6
+ - [The rules that apply to every cell](#the-rules-that-apply-to-every-cell) · lines 74–94
7
+ - [1. Plain text](#1-plain-text) · lines 96–149
8
+ - [2. Icon + label](#2-icon--label) · lines 151–174
9
+ - [3. Icon in a badge](#3-icon-in-a-badge) · lines 176–189
10
+ - [4. Icon only, label in a tooltip](#4-icon-only-label-in-a-tooltip) · lines 191–268
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 216–268
12
+ - [5. Enum → tone-mapped badge](#5-enum--tone-mapped-badge) · lines 270–283
13
+ - [6. Multi-value enum, clustered](#6-multi-value-enum-clustered) · lines 285–297
14
+ - [7. Link as an outline button](#7-link-as-an-outline-button) · lines 299–320
15
+ - [8. Date, relative](#8-date-relative) · lines 322–359
16
+ - [9. Ordinal scale (bounded integer)](#9-ordinal-scale-bounded-integer) · lines 361–409
17
+ - [Two variants the package draws: a step bar and a star](#two-variants-the-package-draws-a-step-bar-and-a-star) · lines 379–409
18
+ - [10. Summary in the cell, detail in a popover](#10-summary-in-the-cell-detail-in-a-popover) · lines 411–461
19
+ - [A second example: what a row depends on](#a-second-example-what-a-row-depends-on) · lines 429–461
20
+ - [11. Number or currency — Unproven](#11-number-or-currency--unproven) · lines 463–503
21
+ - [12. Boolean](#12-boolean) · lines 505–535
22
+ - [13. Progress bar — Unproven](#13-progress-bar--unproven) · lines 537–573
23
+ - [The compact form: `ProgressRing`](#the-compact-form-progressring) · lines 557–573
24
+ - [14. Avatar and name — Unproven](#14-avatar-and-name--unproven) · lines 575–592
25
+ - [15. Yes/no you flip in the row](#15-yesno-you-flip-in-the-row) · lines 594–703
26
+ - [A variant: a pressed icon inside another value's cell](#a-variant-a-pressed-icon-inside-another-values-cell) · lines 620–703
27
+ - [16. Title linking to the record's view](#16-title-linking-to-the-records-view) · lines 705–740
28
+ - [17. Quick action on the view](#17-quick-action-on-the-view) · lines 742–815
29
+ - [18. Editable value](#18-editable-value) · lines 817–1495
30
+ - [Presets: one line per field](#presets-one-line-per-field) · lines 1127–1195
31
+ - [Several fields edited as one](#several-fields-edited-as-one) · lines 1197–1233
32
+ - [A link and its label](#a-link-and-its-label) · lines 1235–1259
33
+ - [A list of sub-items](#a-list-of-sub-items) · lines 1261–1394
34
+ - [In a table's rows](#in-a-tables-rows) · lines 1396–1481
35
+ - [A table of a few short columns: `width="content"`](#a-table-of-a-few-short-columns-widthcontent) · lines 1483–1495
36
+ - [19. Stage circle for an ordered status](#19-stage-circle-for-an-ordered-status) · lines 1497–1563
37
+ - [20. Count linking to the related records](#20-count-linking-to-the-related-records) · lines 1565–1629
38
+ - [21. Rows grouped under headings, and a pill filter](#21-rows-grouped-under-headings-and-a-pill-filter) · lines 1631–1729
39
+ - [22. A highlighted row, and rows that are done](#22-a-highlighted-row-and-rows-that-are-done) · lines 1731–1760
40
+ - [24. A list's rows: hover, lines, rows per page](#24-a-lists-rows-hover-lines-rows-per-page) · lines 1762–1800
41
+ - [23. A Group menu, and a record read beside the list](#23-a-group-menu-and-a-record-read-beside-the-list) · lines 1802–1878
42
+ - [24. A stored colour beside its name](#24-a-stored-colour-beside-its-name) · lines 1880–1903
43
+ - [25. A list's tools: views, filters, columns, row actions, a phone's rows](#25-a-lists-tools-views-filters-columns-row-actions-a-phones-rows) · lines 1905–1991
44
+ - [26. A record's related list, capped](#26-a-records-related-list-capped) · lines 1993–2029
45
+ - [27. A repeat and its next time](#27-a-repeat-and-its-next-time) · lines 2031–2076
45
46
 
46
47
  <!-- /index -->
47
48
 
@@ -73,9 +74,10 @@ too, so it ships here for every app.
73
74
  ## The rules that apply to every cell
74
75
 
75
76
  - **An empty value renders an em dash**, never a blank cell: a blank reads
76
- as a rendering bug. Define it once per columns file —
77
- `const emptyCell = <span className="text-muted-foreground">—</span>` —
78
- and use it everywhere. The one exception is a value whose "nothing" state
77
+ as a rendering bug. Draw it with the package's `EmptyText` (4.96), the
78
+ record's own dash, read by a screen reader as "Not set" (`label` for
79
+ other words): `const emptyCell = <EmptyText />` once per columns file,
80
+ used everywhere. Never a hand-written dash. The one exception is a value whose "nothing" state
79
81
  has its own meaning (an unrated 0-of-5 scale, a missing image), where the
80
82
  shape itself should say so.
81
83
  - **Colour is never the only signal.** Greyscale, colourblindness and print
@@ -2025,3 +2027,50 @@ const visits = useVisits({ provider: provider.id, sort: 'date:desc', page: 1, pa
2025
2027
  - On a DataTable of your own, `limit` and `viewAll` do the same.
2026
2028
  - The fixture `app/DataTable tools` Related draws a capped list and a
2027
2029
  short one with no link; the spec follows View all.
2030
+
2031
+ ## 27. A repeat and its next time
2032
+
2033
+ A record that repeats (a chore, a reminder) shows two columns: **Repeats**,
2034
+ the rule in words, and **Next**, when it falls next. The value is the
2035
+ contract's `Recurrence` (reminders.md "Repeating reminders"); both cells
2036
+ read it in the rule's own zone, so a reminder set in Chicago says 9:00 AM
2037
+ wherever it's looked at.
2038
+
2039
+ ```tsx
2040
+ import { formatOccurrence, formatRecurrence, nextOccurrence, EmptyText } from '@tristan2828/ui-foundation'
2041
+
2042
+ {
2043
+ id: 'repeats',
2044
+ header: 'Repeats',
2045
+ cell: ({ row }) => (row.original.repeats ? formatRecurrence(row.original.repeats) : <EmptyText />),
2046
+ },
2047
+ {
2048
+ id: 'next',
2049
+ header: 'Next',
2050
+ cell: ({ row }) => {
2051
+ const repeats = row.original.repeats
2052
+ if (!repeats) return <EmptyText />
2053
+ const next = nextOccurrence(repeats, new Date())
2054
+ if (!next) return <span className="text-muted-foreground">Ended</span>
2055
+ return (
2056
+ <time dateTime={next.toISOString()} className="tabular-nums">
2057
+ {formatOccurrence(next, repeats.timeZone)}
2058
+ </time>
2059
+ )
2060
+ },
2061
+ },
2062
+ ```
2063
+
2064
+ - **The label** reads "Every 2nd Tue at 9:00 AM", "Every Mon and Thu at
2065
+ 7:00 AM and 7:30 PM", "Every 30 days after done, at 9:00 AM" (from
2066
+ completion), "…, until Mar 1, 2027", "…, 10 times". `times: false`
2067
+ leaves the times out, for a table with its own time column. A rule it
2068
+ can't read shows as stored, never blank.
2069
+ - **Next** is "Tue, Dec 8, 9:00 AM", the year only when it isn't this
2070
+ one; a rule that has ended (UNTIL passed, COUNT used up) says Ended, in
2071
+ muted text. For a `fromCompletion` repeat whose next depends on being
2072
+ done, use the server's `next_at` if it sends one; `nextOccurrence`
2073
+ counts from the schedule's start.
2074
+ - **Sorting by Next** is the server's (`next_at`), not the cell's text.
2075
+ - The fixture `app/RecurrenceField` List cells draws both on six chores;
2076
+ its spec reads each cell.
@@ -30,12 +30,12 @@
30
30
  - [Parts of the page standards](#parts-of-the-page-standards) · lines 1278–1321
31
31
  - [A few equal things](#a-few-equal-things) · lines 1323–1407
32
32
  - [An overview page](#an-overview-page) · lines 1409–1472
33
- - [A record's header and empty values](#a-records-header-and-empty-values) · lines 1473–1511
34
- - [A record's tabs, mark and rail](#a-records-tabs-mark-and-rail) · lines 1513–1558
35
- - [Picking at random](#picking-at-random) · lines 1560–1591
36
- - [Filling in what's missing](#filling-in-whats-missing) · lines 1593–1660
37
- - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1662–1687
38
- - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 1689–1762
33
+ - [A record's header and empty values](#a-records-header-and-empty-values) · lines 1473–1524
34
+ - [A record's tabs, mark and rail](#a-records-tabs-mark-and-rail) · lines 1526–1571
35
+ - [Picking at random](#picking-at-random) · lines 1573–1604
36
+ - [Filling in what's missing](#filling-in-whats-missing) · lines 1606–1673
37
+ - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1675–1700
38
+ - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 1702–1775
39
39
 
40
40
  <!-- /index -->
41
41
 
@@ -1502,6 +1502,19 @@ data on each its own.
1502
1502
  muted text tone, read by a screen reader as "Not set": the same on
1503
1503
  every field, the presets' included. A field's own `emptyLabel` still
1504
1504
  wins where words say more than a dash ("No budget yet").
1505
+ - **The same dash off the record: `EmptyText`** (4.96). An app's own
1506
+ strip, summary line or cell with nothing in it draws
1507
+ `isEmptyValue(value) ? <EmptyText /> : value`, never a dash and an
1508
+ `sr-only` of its own. `label` is what a screen reader says for the
1509
+ dash ("Not set" unless set: `label="No reason given"`), `text` shows
1510
+ words instead of it, and `className` replaces the muted tone's class
1511
+ (keep a muted tone: `className="type-label text-muted-foreground"` on a
1512
+ label-sized line). EntityView, KeyStats, EqualItems, ValueList and the
1513
+ hub cards' "Couldn't load" all draw through it.
1514
+
1515
+ ```tsx
1516
+ <p className="type-body">{shelf} · {isEmptyValue(reason) ? <EmptyText label="No reason given" /> : reason}</p>
1517
+ ```
1505
1518
  - **Folded empties** (`emptyFields="fold"`): each fields card lists its
1506
1519
  filled fields, then a muted, underlined "N empty" with a down chevron
1507
1520
  under them opens the rest in their places, each still edited in place,
@@ -55,7 +55,9 @@ One or two sentences: what one record is, and who uses the screens.
55
55
  time: OpenAPI `format: date`; the foundation's `DateField`; say
56
56
  whether it's optional), `month-day` (a day that comes round every
57
57
  year, no year: `'MM-DD'`; the foundation's `MonthDayField`; say
58
- whether it's optional).
58
+ whether it's optional), `recurrence` (how it repeats: the
59
+ foundation's `Recurrence` schema and `RecurrenceField`; say whether
60
+ it's optional).
59
61
  - *Not supported yet:* a yes/no that can also be unset (three states),
60
62
  file, and anything else.
61
63
  Write it anyway with a note; the playbook will stop and raise it
@@ -111,6 +111,59 @@ Scope it to the signed-in user, as Widgets are.
111
111
  that's the `tzdata` package, which the backend doesn't install: a
112
112
  Windows dev machine reads only `UTC` until it's added.
113
113
 
114
+ ## Repeating reminders (4.95)
115
+
116
+ A weekday set and one time is the simple schedule. For anything more
117
+ (every 2nd Tuesday, the last day of the month, several times a day, an
118
+ end, "every! 3 days" counted from when it's done), a reminder carries a
119
+ **recurrence**: the contract's `Recurrence` schema (in the package's
120
+ `openapi/foundation.yaml`, marked `x-optional`: copy it into
121
+ `components.schemas` and reference it from the reminder's schema), the
122
+ package's `RecurrenceField` on the form and `inPlace.recurrence` on the
123
+ view, and `foundation_backend.recurrence` on the server. Both sides read
124
+ the same rules and agree on every next occurrence.
125
+
126
+ - **The value**: `{ rule, start, times, timeZone, fromCompletion }`.
127
+ `rule` is RFC 5545's RRULE without DTSTART (`FREQ=MONTHLY;BYDAY=2TU`):
128
+ FREQ daily to yearly, INTERVAL, BYDAY with an nth (`2TU`, `-1FR`),
129
+ BYMONTHDAY (`-1` the last day), BYMONTH, UNTIL (a date) or COUNT.
130
+ `start` is the first day it can fall on; each of `times` is an
131
+ occurrence on every day the rule falls on, read in `timeZone`. A day a
132
+ month lacks is skipped (the 31st, Feb 29), as in RFC 5545.
133
+ - **The columns**: the app's reminders model inherits
134
+ `foundation_backend.recurrence_models.RecurringReminderFields` and its
135
+ migration adds them: `recurrence` (JSON), `next_at`, `sent_at`,
136
+ `last_sent_at`, `done_occurrence`, `done_at` (timestamps with time
137
+ zone), `nag_count` (integer, default 0), `nag_every_minutes` and
138
+ `nag_limit` (integers, null for no nagging). `days` and `time_of_day`
139
+ become nullable. Hand the model to the job as before
140
+ (`reminders.register(model=MyReminder)`).
141
+ - **What the job does with a row whose `recurrence` is set**: each
142
+ occurrence is due from its time until 15 minutes have passed, so
143
+ several a day go out; one missed past that is skipped, not sent late
144
+ (the run's line says "1 missed"). Sent and not done, it's re-sent
145
+ every `nag_every_minutes`, at most `nag_limit` times (3 when only the
146
+ interval is set). The next occurrence coming round ends the wait; a
147
+ `fromCompletion` rule waits for done instead. A row with no
148
+ `recurrence` is the weekday set, as before.
149
+ - **Done**: the app's Done button (or a notification action that calls
150
+ the app) runs `reminders.mark_done(row)` and commits: the occurrence is
151
+ recorded (`done_occurrence`, `done_at`), nagging stops, and the next is
152
+ pending; for `fromCompletion` it counts from the done time. After the
153
+ rule itself changes, `reminders.schedule_changed(row)` forgets where it
154
+ was.
155
+ - **Moving a simple schedule over**: `recurrence.from_weekdays(days,
156
+ time_of_day, time_zone, start=today)` (and the package's
157
+ `recurrenceFromWeekdays`) is the same schedule exactly; store its
158
+ `model_dump(by_alias=True, mode="json")` in `recurrence`.
159
+ `recurrence.as_weekdays(rule)` goes back when a rule is still that
160
+ simple.
161
+ - **On screens**: `RecurrenceField` in the form (a `Controller`; check
162
+ with `recurrenceProblem`), `inPlace.recurrence` on the view, and in the
163
+ list `formatRecurrence` for a Repeats column and `nextOccurrence` with
164
+ `formatOccurrence` for a Next one (cell-patterns.md "A repeat and its
165
+ next time").
166
+
114
167
  ## Testing
115
168
 
116
169
  Under MSW the page is held by MSW's service worker, so `usePushPermission`
@@ -259,6 +259,25 @@ export interface components {
259
259
  PushSubscriptionCreated: {
260
260
  id: number;
261
261
  };
262
+ /** @description A repeating schedule (RecurrenceField, foundation_backend.recurrence). The rule's days, each at every one of its times, read in its zone. */
263
+ Recurrence: {
264
+ /** @description RFC 5545's RRULE value, without DTSTART: FREQ (daily, weekly, monthly, yearly), INTERVAL, BYMONTH, BYMONTHDAY (-1 is the last day), BYDAY (an nth for monthly and yearly: 2TU, -1FR), UNTIL (a date, YYYYMMDD, the last day it can fall on) or COUNT (occurrences, each time of each day). "FREQ=MONTHLY;BYDAY=2TU". */
265
+ rule: string;
266
+ /**
267
+ * Format: date
268
+ * @description The first day it can fall on (DTSTART's date).
269
+ */
270
+ start: string;
271
+ /** @description Its times of day, HH:MM, in order, each once. */
272
+ times: string[];
273
+ /** @description The IANA zone its days and times are read in. */
274
+ timeZone: string;
275
+ /**
276
+ * @description Repeat from when it was done ("every!"), not from the schedule: the next one is the rule's days counted from the day it was done.
277
+ * @default false
278
+ */
279
+ fromCompletion: boolean;
280
+ };
262
281
  /** @description FastAPI's default 422 shape (RequestValidationError). */
263
282
  ValidationErrorBody: {
264
283
  detail: {
@@ -1,12 +1,23 @@
1
1
  import { type ReactElement, type ReactNode } from 'react';
2
2
  export type DeleteKind = 'soft' | 'hard';
3
+ /** The one field a confirm can ask (4.96): an optional reason, in a textarea. */
4
+ export type DeleteReason = {
5
+ /** The field's label: "Why" unless set ("Why remove it?"). */
6
+ label?: string;
7
+ /** A line under the box, in muted type ("Kept with its history."). */
8
+ hint?: ReactNode;
9
+ placeholder?: string;
10
+ };
3
11
  export type DeleteActionProps = {
4
12
  /** What's deleted, as the page names it: "The Long Walk". */
5
13
  name: string;
6
14
  /** `soft`: it goes to Deleted and Restore brings it back. `hard`: it's gone. */
7
15
  kind: DeleteKind;
8
- /** Deletes it. A rejection keeps the dialog open with the reason. */
9
- onDelete: () => Promise<unknown>;
16
+ /**
17
+ * Deletes it. A rejection keeps the dialog open with the reason. With
18
+ * `reason`, it's given what was typed, trimmed ('' for nothing).
19
+ */
20
+ onDelete: (reason: string) => Promise<unknown>;
10
21
  /** A soft delete's Undo: restores it. Without it the toast has no Undo. */
11
22
  onRestore?: () => Promise<unknown>;
12
23
  /** After it's deleted and the toast is up: leave the record's page, say. */
@@ -17,6 +28,8 @@ export type DeleteActionProps = {
17
28
  verbDone?: string;
18
29
  /** Another sentence under the question than `kind`'s. */
19
30
  description?: ReactNode;
31
+ /** Ask a reason: one optional field between the sentence and the buttons, passed to `onDelete`. */
32
+ reason?: DeleteReason;
20
33
  /** `"icon"` (the default), `"button"` (the verb in words), an element to open it, or `null` for none. */
21
34
  trigger?: 'icon' | 'button' | ReactElement | null;
22
35
  /** The icon trigger's size: `default` (36px, a header) or `sm` (32px, a row). */
@@ -25,4 +38,4 @@ export type DeleteActionProps = {
25
38
  open?: boolean;
26
39
  onOpenChange?: (open: boolean) => void;
27
40
  };
28
- export declare function DeleteAction({ name, kind, onDelete, onRestore, onDeleted, verb, verbDone, description, trigger, size, open: openProp, onOpenChange, }: DeleteActionProps): import("react").JSX.Element;
41
+ export declare function DeleteAction({ name, kind, onDelete, onRestore, onDeleted, verb, verbDone, description, reason, trigger, size, open: openProp, onOpenChange, }: DeleteActionProps): import("react").JSX.Element;
@@ -14,16 +14,24 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
14
  // - `verb` covers the other ways something leaves a list: `verb="Retire"`
15
15
  // asks "Retire <name>?" on a "Retire" button and says "Retired <name>".
16
16
  //
17
+ // - `reason` (4.96) puts one field between the sentence and the buttons, a
18
+ // "Why" box, optional: what's typed (trimmed, '' for nothing) is
19
+ // `onDelete`'s argument, and Try again sends it again. While something's
20
+ // typed, closing asks "Discard your changes?" first (the dialog
21
+ // standard's `dirty`). Width, words and the buttons stay as they are.
22
+ //
17
23
  // The trigger is an icon (IconAction's Trash2) unless `trigger` says
18
24
  // otherwise: `"button"` for a "Delete" button in words, an element of the
19
25
  // caller's, or `null` for none, opened with `open`/`onOpenChange` (a row's
20
26
  // menu item).
21
- import { useState } from 'react';
27
+ import { useId, useState } from 'react';
22
28
  import { Trash2Icon } from 'lucide-react';
23
29
  import { useAction } from '../../hooks/use-action.js';
24
30
  import { Button } from '../ui/button.js';
25
31
  import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from '../ui/dialog.js';
32
+ import { Field, FieldDescription, FieldLabel } from '../ui/field.js';
26
33
  import { Spinner } from '../ui/spinner.js';
34
+ import { Textarea } from '../ui/textarea.js';
27
35
  import { ActionError } from './action-error.js';
28
36
  import { IconAction } from './icon-action.js';
29
37
  import { notify, pastTense } from './notify.js';
@@ -31,7 +39,7 @@ const SAYS = {
31
39
  soft: 'It goes to Deleted, and Restore brings it back.',
32
40
  hard: 'This can’t be undone.',
33
41
  };
34
- export function DeleteAction({ name, kind, onDelete, onRestore, onDeleted, verb = 'Delete', verbDone, description, trigger = 'icon', size = 'default', open: openProp, onOpenChange, }) {
42
+ export function DeleteAction({ name, kind, onDelete, onRestore, onDeleted, verb = 'Delete', verbDone, description, reason, trigger = 'icon', size = 'default', open: openProp, onOpenChange, }) {
35
43
  const [openState, setOpenState] = useState(false);
36
44
  const open = openProp ?? openState;
37
45
  const setOpen = (next) => {
@@ -41,8 +49,17 @@ export function DeleteAction({ name, kind, onDelete, onRestore, onDeleted, verb
41
49
  };
42
50
  const done = verbDone ?? pastTense(verb);
43
51
  const remove = useAction(onDelete, { failed: `Couldn't ${verb.toLowerCase()} ${name}` });
52
+ const reasonId = useId();
53
+ const [typed, setTyped] = useState('');
54
+ // A closed confirm starts empty next time, however it was closed.
55
+ const [wasOpen, setWasOpen] = useState(open);
56
+ if (wasOpen !== open) {
57
+ setWasOpen(open);
58
+ if (!open)
59
+ setTyped('');
60
+ }
44
61
  const confirm = async () => {
45
- const outcome = await remove.run();
62
+ const outcome = await remove.run(reason ? typed.trim() : '');
46
63
  if (!outcome.ok)
47
64
  return;
48
65
  // Whether or not this is still on screen: a row's delete is gone with
@@ -57,5 +74,5 @@ export function DeleteAction({ name, kind, onDelete, onRestore, onDeleted, verb
57
74
  if (!next)
58
75
  remove.reset();
59
76
  setOpen(next);
60
- }, children: [trigger === 'icon' && (_jsx(DialogTrigger, { render: _jsx(IconAction, { icon: Trash2Icon, label: verb, tone: "destructive", size: size }) })), trigger === 'button' && (_jsx(DialogTrigger, { render: _jsx(Button, { variant: "outline", size: size === 'sm' ? 'sm' : 'default' }), children: verb })), trigger && typeof trigger === 'object' && _jsx(DialogTrigger, { render: trigger }), _jsxs(DialogContent, { size: "confirm", "data-slot": "delete-action", "data-kind": kind, children: [_jsxs(DialogHeader, { children: [_jsxs(DialogTitle, { children: [verb, " ", name, "?"] }), _jsx(DialogDescription, { children: description ?? SAYS[kind] })] }), _jsx(ActionError, { action: { ...remove, retry: confirm } }), _jsxs(DialogFooter, { children: [_jsx(DialogClose, { render: _jsx(Button, { variant: "outline", disabled: remove.pending }), children: "Cancel" }), _jsxs(Button, { variant: "destructive", disabled: remove.pending, onClick: () => void confirm(), children: [remove.pending && _jsx(Spinner, { className: "size-4" }), verb] })] })] })] }));
77
+ }, children: [trigger === 'icon' && (_jsx(DialogTrigger, { render: _jsx(IconAction, { icon: Trash2Icon, label: verb, tone: "destructive", size: size }) })), trigger === 'button' && (_jsx(DialogTrigger, { render: _jsx(Button, { variant: "outline", size: size === 'sm' ? 'sm' : 'default' }), children: verb })), trigger && typeof trigger === 'object' && _jsx(DialogTrigger, { render: trigger }), _jsxs(DialogContent, { size: "confirm", dirty: reason !== undefined && typed.trim() !== '' && !remove.pending, "data-slot": "delete-action", "data-kind": kind, children: [_jsxs(DialogHeader, { children: [_jsxs(DialogTitle, { children: [verb, " ", name, "?"] }), _jsx(DialogDescription, { children: description ?? SAYS[kind] })] }), reason && (_jsxs(Field, { "data-slot": "delete-action-reason", children: [_jsx(FieldLabel, { htmlFor: reasonId, children: reason.label ?? 'Why' }), _jsx(Textarea, { id: reasonId, value: typed, placeholder: reason.placeholder, disabled: remove.pending, onChange: (event) => setTyped(event.target.value) }), reason.hint && _jsx(FieldDescription, { children: reason.hint })] })), _jsx(ActionError, { action: { ...remove, retry: confirm } }), _jsxs(DialogFooter, { children: [_jsx(DialogClose, { render: _jsx(Button, { variant: "outline", disabled: remove.pending }), children: "Cancel" }), _jsxs(Button, { variant: "destructive", disabled: remove.pending, onClick: () => void confirm(), children: [remove.pending && _jsx(Spinner, { className: "size-4" }), verb] })] })] })] }));
61
78
  }
@@ -1,6 +1,7 @@
1
1
  import type { ReactNode } from 'react';
2
2
  import { type MonthDay } from '../../lib/month-day.js';
3
3
  import { type PlainDate } from '../../lib/plain-date.js';
4
+ import { type Recurrence } from '../../lib/recurrence.js';
4
5
  import type { EditInPlace } from './edit-in-place.js';
5
6
  /** What the value saves as: with `required: true` never `null` (a blank is refused). */
6
7
  export type InPlaceSaved<TValue, TRequired extends boolean> = TRequired extends true ? TValue : TValue | null;
@@ -78,6 +79,23 @@ export type InPlaceMonthDayConfig<TRequired extends boolean = boolean> = {
78
79
  locale?: string;
79
80
  placeholder?: string;
80
81
  };
82
+ /**
83
+ * How something repeats (RecurrenceField): presets, a phrase read as it's
84
+ * typed, and a preview. Enter in the box or leaving the field saves; a
85
+ * phrase it can't read isn't saved. Not `required`: emptying the box saves
86
+ * `null` (doesn't repeat).
87
+ */
88
+ export type InPlaceRecurrenceConfig<TRequired extends boolean = boolean> = {
89
+ required?: TRequired;
90
+ /** The IANA zone a new repeat is read in. Defaults to the value's, else the browser's. */
91
+ timeZone?: string;
92
+ /** The times a new repeat starts with. Defaults to 09:00. */
93
+ defaultTimes?: string[];
94
+ /** Today, `'YYYY-MM-DD'`, and "now", for a fixed preview (tests). Default to the clock. */
95
+ today?: string;
96
+ now?: Date;
97
+ locale?: string;
98
+ };
81
99
  /** One option of a select: its value and its words. */
82
100
  export type InPlaceOption<T> = {
83
101
  value: T;
@@ -208,6 +226,13 @@ export declare const inPlace: {
208
226
  * Reads as "Mar 14"; February 29 is a day, February 30 is refused.
209
227
  */
210
228
  monthDay<R extends boolean = false>(options: Common<MonthDay | null | undefined, InPlaceSaved<MonthDay, R>> & InPlaceMonthDayConfig<R>): EditInPlace;
229
+ /**
230
+ * How something repeats (the contract's `Recurrence`) in RecurrenceField:
231
+ * presets, a phrase read as it's typed ("every 2nd tue at 9am") and a
232
+ * preview of the next five. Reads as its label ("Every 2nd Tue at 9:00
233
+ * AM"); Enter or leaving saves, and a phrase it can't read is refused.
234
+ */
235
+ recurrence<R extends boolean = false>(options: Common<Recurrence | null | undefined, InPlaceSaved<Recurrence, R>> & InPlaceRecurrenceConfig<R>): EditInPlace;
211
236
  /**
212
237
  * One of a fixed list; its list opens with the field and a pick saves.
213
238
  * `look: 'buttons'` draws it as ChoiceButtons (`inPlace.choice`).
@@ -4,10 +4,13 @@ import { InputGroup, InputGroupAddon, InputGroupInput, InputGroupText } from '..
4
4
  import { linkHost, linkRule } from '../../lib/link-href.js';
5
5
  import { formatMonthDay, monthDayProblem } from '../../lib/month-day.js';
6
6
  import { formatPlainDate, unreadableDateMessage } from '../../lib/plain-date.js';
7
+ import { normalizeRecurrence, recurrenceProblem } from '../../lib/recurrence.js';
8
+ import { formatRecurrence } from '../../lib/recurrence-format.js';
7
9
  import { ChoiceButtons } from './choice-buttons.js';
8
10
  import { DateField } from './date-field.js';
9
11
  import { MonthDayField } from './month-day-field.js';
10
12
  import { OptionSelect } from './option-select.js';
13
+ import { RecurrenceField } from './recurrence-field.js';
11
14
  import { Parts, ReferencePicker } from './edit-in-place-controls.js';
12
15
  import { LinkOut } from './row-edit-cells.js';
13
16
  const REQUIRED = 'Required';
@@ -177,6 +180,20 @@ function monthDayKind(config) {
177
180
  : undefined, "aria-label": props.label, "aria-describedby": props.describedBy })),
178
181
  };
179
182
  }
183
+ function recurrenceKind(config) {
184
+ return {
185
+ editKind: 'text',
186
+ toDraft: (value) => value ?? null,
187
+ check: (draft) => {
188
+ if (draft === null)
189
+ return config.required ? { ok: false, message: REQUIRED } : { ok: true, value: null };
190
+ const problem = recurrenceProblem(draft);
191
+ return problem ? { ok: false, message: problem } : { ok: true, value: normalizeRecurrence(draft) };
192
+ },
193
+ show: (value) => (value ? formatRecurrence(value, { locale: config.locale }) : null),
194
+ control: (props) => (_jsx(RecurrenceField, { id: props.id, value: props.value, onChange: props.onChange, onProblem: props.onProblem, timeZone: config.timeZone, defaultTimes: config.defaultTimes, today: config.today, now: config.now, locale: config.locale, invalid: props.invalid, readOnly: props.disabled, "aria-label": props.label, "aria-describedby": props.describedBy })),
195
+ };
196
+ }
180
197
  function selectKind(config) {
181
198
  const labelOf = (value) => config.options.find((option) => option.value === value)?.label ?? String(value);
182
199
  const shownOf = (value) => (config.render ? config.render(value, labelOf(value)) : labelOf(value));
@@ -421,6 +438,15 @@ export const inPlace = {
421
438
  monthDay(options) {
422
439
  return single(monthDayKind(options), { ...options, value: options.value || null });
423
440
  },
441
+ /**
442
+ * How something repeats (the contract's `Recurrence`) in RecurrenceField:
443
+ * presets, a phrase read as it's typed ("every 2nd tue at 9am") and a
444
+ * preview of the next five. Reads as its label ("Every 2nd Tue at 9:00
445
+ * AM"); Enter or leaving saves, and a phrase it can't read is refused.
446
+ */
447
+ recurrence(options) {
448
+ return single(recurrenceKind(options), { ...options, value: options.value ?? null });
449
+ },
424
450
  /**
425
451
  * One of a fixed list; its list opens with the field and a pick saves.
426
452
  * `look: 'buttons'` draws it as ChoiceButtons (`inPlace.choice`).
@@ -1,5 +1,12 @@
1
- /** The empty text in the muted tone; the dash is read as "Not set". */
2
- export declare function EmptyText({ text, className }: {
1
+ import type { ComponentProps } from 'react';
2
+ /** Any other span attribute (`data-state`, `id`) passes through to the span. */
3
+ export type EmptyTextProps = Omit<ComponentProps<'span'>, 'children'> & {
4
+ /** What shows: the dash unless set. Words ("No budget yet") read as they are. */
3
5
  text?: string;
6
+ /** What a screen reader says for the dash: "Not set" unless set ("No reason given"). */
7
+ label?: string;
8
+ /** Replaces the muted text tone's class (keep a muted tone: `type-body text-muted-foreground`). */
4
9
  className?: string;
5
- }): import("react").JSX.Element;
10
+ };
11
+ /** The empty text in the muted tone; the dash is read as `label`, "Not set" by default. */
12
+ export declare function EmptyText({ text, label, className, ...props }: EmptyTextProps): import("react").JSX.Element;