@tristan2828/ui-foundation 4.103.0 → 4.105.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.
@@ -15,17 +15,17 @@
15
15
  - Step 8: Add Playwright specs for all three screens · lines 752–829
16
16
  - Step 9: Register the nav entry and route names · lines 830–844
17
17
  - Step 10: `npm run verify`. · lines 845–847
18
- - [How a list opens a record](#how-a-list-opens-a-record) · lines 849–1208
19
- - [The record view](#the-record-view) · lines 1002–1065
20
- - [Forms](#forms) · lines 1067–1125
21
- - [Dialogs](#dialogs) · lines 1127–1158
22
- - [Toasts and feedback](#toasts-and-feedback) · lines 1160–1208
23
- - [What not to copy](#what-not-to-copy) · lines 1210–1236
24
- - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 1238–1255
25
- - [Deleting](#deleting) · lines 1257–1288
26
- - [Fields only a script writes](#fields-only-a-script-writes) · lines 1290–1311
27
- - [Searching one part of the app](#searching-one-part-of-the-app) · lines 1313–1322
28
- - [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1325–1367
18
+ - [How a list opens a record](#how-a-list-opens-a-record) · lines 849–1216
19
+ - [The record view](#the-record-view) · lines 1002–1066
20
+ - [Forms](#forms) · lines 1068–1133
21
+ - [Dialogs](#dialogs) · lines 1135–1166
22
+ - [Toasts and feedback](#toasts-and-feedback) · lines 1168–1216
23
+ - [What not to copy](#what-not-to-copy) · lines 1218–1250
24
+ - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 1252–1269
25
+ - [Deleting](#deleting) · lines 1271–1302
26
+ - [Fields only a script writes](#fields-only-a-script-writes) · lines 1304–1325
27
+ - [Searching one part of the app](#searching-one-part-of-the-app) · lines 1327–1336
28
+ - [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1339–1381
29
29
 
30
30
  <!-- /index -->
31
31
 
@@ -1046,7 +1046,8 @@ A record uses the parts it has, in this order:
1046
1046
  row) opens as a small card: `RecordDialogRoute look="card"`, usually
1047
1047
  with `fullPage={false}`. A 420px dialog (a sheet on a phone), its
1048
1048
  title, Delete, Open full page and Close on one line, its facts as
1049
- plain rows.
1049
+ plain rows. The view's `strip` (KeyStats) is left out in the card
1050
+ (4.105); `cardStrip` keeps it, and the record's own page still shows it.
1050
1051
  - **Empty fields folded** (`emptyFields="fold"`, 4.81): each card shows
1051
1052
  what's known, then "N empty" opens the rest, still edited in place.
1052
1053
  - **A few equal things** (a plan's phases, a price at each store, a
@@ -1083,7 +1084,9 @@ shape (4.85):
1083
1084
  (`ChoiceButtons`, found by itself, 4.98) shares a row only with another
1084
1085
  choice, two to a row; on a phone two stay side by side while both
1085
1086
  groups fit, and go one per row when they don't. Never a hand-made
1086
- `sm:grid-cols-2` row.
1087
+ `sm:grid-cols-2` row. The picked option is in the theme colour (4.105);
1088
+ a status choice gives each option its `kind`, so its icons are
1089
+ `StatusMark`'s in their colours (below).
1087
1090
  - **Order:** required first, the status next, long text last.
1088
1091
  - **Required:** `<FieldLabel required>` (an asterisk, and `aria-required`
1089
1092
  on the control it names). Nothing on an optional field: never
@@ -1098,7 +1101,12 @@ shape (4.85):
1098
1101
  "Enter a full address, starting https://", never "Title is required".
1099
1102
  - **A status** is an `OptionSelect` with the same `render` (its
1100
1103
  `StatusMark`, 4.98) as its cell and the record: `inPlace.select`'s
1101
- `{ value, label }` options.
1104
+ `{ value, label }` options. A status of two to four is `ChoiceButtons`
1105
+ (4.105) with each option's `kind`, its status kind:
1106
+ `{ value: 'done', label: 'Done', kind: 'done' }` draws the kind's icon
1107
+ in its colour before the word, the same as the record's `StatusMark`
1108
+ (`icon` overrides the kind's icon; an `icon` with no `kind` stays
1109
+ uncoloured). Map the enum to kinds once and use that map for both.
1102
1110
  - **The controls** (4.88): a choice of two to four short options is
1103
1111
  `ChoiceButtons` (`inPlace.choice` in place), five or more an
1104
1112
  `OptionSelect`. A date is `DateField`, typed ("3/14", "Mar 14",
@@ -1226,6 +1234,12 @@ sight.** What happened where the person is looking says so there.
1226
1234
  takes the views, `activeView` says which one the filters are, and that
1227
1235
  view's `columns` go to `DataTable`'s `visibleColumns` (the table's own
1228
1236
  default list when no view is active, or `undefined` for every column).
1237
+ Views fill the filters (4.105): write each view's whole meaning in its
1238
+ `filters` and `multiFilters` (a "Current" view names its statuses, never
1239
+ `{}` with the server's default doing the rest), name the one the list
1240
+ opens on with `defaultView`, and put what no control can show (a
1241
+ computed "overdue") in the view's `rule` (cell-patterns.md "Saved views
1242
+ are pills").
1229
1243
  - `src/api/gateway/widgets.ts`, `src/mocks/data.ts`, `src/mocks/handlers.ts`
1230
1244
  are demo-domain content — write the entity's own versions rather than
1231
1245
  adapting these by find-and-replace.
@@ -40,10 +40,10 @@
40
40
  - [24. A list's rows: hover, lines, rows per page](#24-a-lists-rows-hover-lines-rows-per-page) · lines 1811–1849
41
41
  - [23. A Group menu, and a record read beside the list](#23-a-group-menu-and-a-record-read-beside-the-list) · lines 1851–1927
42
42
  - [24. A stored colour beside its name](#24-a-stored-colour-beside-its-name) · lines 1929–1952
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 1954–2080
44
- - [The framed look, and sibling lists beside the title](#the-framed-look-and-sibling-lists-beside-the-title) · lines 2042–2080
45
- - [26. A record's related list, capped](#26-a-records-related-list-capped) · lines 2082–2118
46
- - [27. A repeat and its next time](#27-a-repeat-and-its-next-time) · lines 2120–2165
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 1954–2112
44
+ - [The framed look, and sibling lists beside the title](#the-framed-look-and-sibling-lists-beside-the-title) · lines 2074–2112
45
+ - [26. A record's related list, capped](#26-a-records-related-list-capped) · lines 2114–2150
46
+ - [27. A repeat and its next time](#27-a-repeat-and-its-next-time) · lines 2152–2197
47
47
 
48
48
  <!-- /index -->
49
49
 
@@ -2004,6 +2004,38 @@ const { filters, multiFilters, setFilter, setFilters, setMultiFilter, activeView
2004
2004
  once the filters move off every view. Under 48rem they stay on one line
2005
2005
  that scrolls sideways. Replaces a hand-written row of view buttons; a
2006
2006
  Deleted view goes in ListHeader's ⋯ menu as Show Deleted instead.
2007
+ - **Views fill the filters** (4.105), so the bar always says why rows are
2008
+ hidden:
2009
+ - A view's `filters` and `multiFilters` are what the bar's controls
2010
+ show while it's on: write its whole meaning there. A "Current" view
2011
+ names its statuses (`multiFilters: { status: ['active', 'paused'] }`),
2012
+ never `{}` with the server's default hiding the rest.
2013
+ - `defaultView` (useTableUrlState's options) is the view the list opens
2014
+ on: at the list's plain address (no filter in the URL) its filters
2015
+ fill the bar and its pill is pressed; pressing it goes back to the
2016
+ plain address.
2017
+ - A part no control can show (a computed "overdue") is the view's
2018
+ `rule`: `{ label: 'Overdue', rule: { overdue: 'true' }, multiFilters: {
2019
+ status: OPEN } }`. It's in the URL and applies while the view is on;
2020
+ the bar shows the filters it can.
2021
+ - Changing a filter by hand keeps every other filter the bar shows (the
2022
+ default view's too), clears any `rule`, and the pills follow: the view
2023
+ the result equals is pressed (ticking every status is All), usually
2024
+ none. Clearing every filter by hand on a list with a `defaultView`
2025
+ writes `?view=none`, so it stays unfiltered; `applyView({})` (Back to
2026
+ the List, a "Clear filters" link) is the plain address again.
2027
+
2028
+ ```tsx
2029
+ const VIEWS = {
2030
+ current: { label: 'Current', multiFilters: { status: ['open', 'waiting'] } },
2031
+ overdue: { label: 'Overdue', rule: { overdue: 'true' }, multiFilters: { status: ['open', 'waiting'] } },
2032
+ all: { label: 'All', multiFilters: { status: ['open', 'waiting', 'closed'] } },
2033
+ }
2034
+ const table = useTableUrlState(['search', 'overdue'], ['status'], VIEWS, { defaultView: 'current' })
2035
+ ```
2036
+ - **The column header row** (4.105) wears the muted fill on every cell,
2037
+ pinned and stuck ones too, in the plain and framed looks, so the names
2038
+ read apart from the rows; its words stay `--foreground`.
2007
2039
  - **The filters** (L4): `FilterBar` holds search, the two filters used
2008
2040
  most (`primary`), and the rest behind Filters (`secondary`, with their
2009
2041
  chips, as `SecondaryFilters` draws them). No captions over controls:
@@ -3,41 +3,41 @@
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 50–157
7
- - [Glow](#glow) · lines 159–178
8
- - [Semantic tones](#semantic-tones) · lines 180–208
9
- - [The three badge styles](#the-three-badge-styles) · lines 210–227
10
- - [Status marks](#status-marks) · lines 229–268
11
- - [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines 270–299
12
- - [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines 301–314
13
- - [Logos and brand marks](#logos-and-brand-marks) · lines 316–360
14
- - [Categorical colour](#categorical-colour) · lines 362–432
15
- - [Heat scale](#heat-scale) · lines 434–495
16
- - [Depth ramps](#depth-ramps) · lines 497–582
17
- - [A stored colour](#a-stored-colour) · lines 584–632
18
- - [Shapes and sizes](#shapes-and-sizes) · lines 634–655
19
- - [Typography](#typography) · lines 657–814
20
- - [Words on screen: Title Case and sentence case](#words-on-screen-title-case-and-sentence-case) · lines 691–724
21
- - [Written text (notes)](#written-text-notes) · lines 726–814
22
- - [Density](#density) · lines 816–909
23
- - [Rows on this device](#rows-on-this-device) · lines 882–909
24
- - [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 911–1025
25
- - [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 1027–1104
26
- - [Notices](#notices) · lines 1106–1134
27
- - [A value over time](#a-value-over-time) · lines 1136–1222
28
- - [Several values over time](#several-values-over-time) · lines 1185–1222
29
- - [A list as a board](#a-list-as-a-board) · lines 1224–1275
30
- - [A list as cards](#a-list-as-cards) · lines 1277–1323
31
- - [Key numbers on a record](#key-numbers-on-a-record) · lines 1325–1354
32
- - [Parts of the page standards](#parts-of-the-page-standards) · lines 1356–1399
33
- - [A few equal things](#a-few-equal-things) · lines 1401–1485
34
- - [An overview page](#an-overview-page) · lines 1487–1550
35
- - [A record's header and empty values](#a-records-header-and-empty-values) · lines 1551–1602
36
- - [A record's tabs, mark and facts](#a-records-tabs-mark-and-facts) · lines 1604–1671
37
- - [Picking at random](#picking-at-random) · lines 1673–1704
38
- - [Filling in what's missing](#filling-in-whats-missing) · lines 1706–1773
39
- - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1775–1800
40
- - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 1802–1891
6
+ - [Palettes](#palettes) · lines 50–159
7
+ - [Glow](#glow) · lines 161–180
8
+ - [Semantic tones](#semantic-tones) · lines 182–210
9
+ - [The three badge styles](#the-three-badge-styles) · lines 212–229
10
+ - [Status marks](#status-marks) · lines 231–270
11
+ - [Mapping an enum to tones](#mapping-an-enum-to-tones) · lines 272–301
12
+ - [Glyphs and icons: 3:1](#glyphs-and-icons-31) · lines 303–316
13
+ - [Logos and brand marks](#logos-and-brand-marks) · lines 318–362
14
+ - [Categorical colour](#categorical-colour) · lines 364–434
15
+ - [Heat scale](#heat-scale) · lines 436–497
16
+ - [Depth ramps](#depth-ramps) · lines 499–584
17
+ - [A stored colour](#a-stored-colour) · lines 586–634
18
+ - [Shapes and sizes](#shapes-and-sizes) · lines 636–657
19
+ - [Typography](#typography) · lines 659–826
20
+ - [Words on screen: Title Case and sentence case](#words-on-screen-title-case-and-sentence-case) · lines 693–726
21
+ - [Written text (notes)](#written-text-notes) · lines 728–826
22
+ - [Density](#density) · lines 828–921
23
+ - [Rows on this device](#rows-on-this-device) · lines 894–921
24
+ - [Widget cards (hub pages)](#widget-cards-hub-pages) · lines 923–1037
25
+ - [Module cards (a hub's places)](#module-cards-a-hubs-places) · lines 1039–1116
26
+ - [Notices](#notices) · lines 1118–1146
27
+ - [A value over time](#a-value-over-time) · lines 1148–1234
28
+ - [Several values over time](#several-values-over-time) · lines 1197–1234
29
+ - [A list as a board](#a-list-as-a-board) · lines 1236–1287
30
+ - [A list as cards](#a-list-as-cards) · lines 1289–1335
31
+ - [Key numbers on a record](#key-numbers-on-a-record) · lines 1337–1366
32
+ - [Parts of the page standards](#parts-of-the-page-standards) · lines 1368–1413
33
+ - [A few equal things](#a-few-equal-things) · lines 1415–1499
34
+ - [An overview page](#an-overview-page) · lines 1501–1564
35
+ - [A record's header and empty values](#a-records-header-and-empty-values) · lines 1565–1616
36
+ - [A record's tabs, mark and facts](#a-records-tabs-mark-and-facts) · lines 1618–1686
37
+ - [Picking at random](#picking-at-random) · lines 1688–1719
38
+ - [Filling in what's missing](#filling-in-whats-missing) · lines 1721–1788
39
+ - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1790–1815
40
+ - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 1817–1906
41
41
 
42
42
  <!-- /index -->
43
43
 
@@ -124,7 +124,9 @@ portaled to `<body>` wear it too. An installed app's colours follow it with
124
124
  4.5:1 as small text on Indigo and Rose and on Violet, and on every
125
125
  palette's cards but Indigo and Cyan, so it is never small text: it is
126
126
  the ring, the primary fill and the active item's tint. The `link`
127
- Button variant is `text-link` for the same reason.
127
+ Button variant is `text-link` for the same reason, and the theme
128
+ colour as text (`--primary-text`, 4.105: the open tab's name, a picked
129
+ choice's word) is accent light too.
128
130
  - **The status colours are text shades.** The guide's success, warning
129
131
  and danger are `--success-text`, `--warning-text` and
130
132
  `--destructive-text` (soft badges, icons, coloured words). Solid fills
@@ -776,6 +778,16 @@ columns ("Item, Size, Colour, …"), so two such tables keep distinct
776
778
  names; the arrow keys scroll it (in the editor Home and End too), with
777
779
  the `ring` focus ring. A table that fits gets no tab stop and no region.
778
780
 
781
+ **The theme colour as text** (4.105) is `--primary-text`
782
+ (`text-primary-text`): what's picked or open, in the primary's own colour
783
+ where that reads as small text. The open record tab's name and a picked
784
+ `ChoiceButtons` option wear it (the tab with a 3px `bg-primary` line, the
785
+ choice with a `border-primary` and a `bg-primary/12` fill). It's the
786
+ primary itself in the light and dark themes (near-black, near-white),
787
+ each dark palette's accent light (the accent fails 4.5:1 as small text on
788
+ some surfaces), and Palm LCD's ink. Never for a link (`--link`) or a
789
+ heading.
790
+
779
791
  The same text has four colour tokens of its own: `--link` (`text-link`), a
780
792
  link's colour, blue as well as underlined (5.59:1 on white, 8.90:1 on the
781
793
  dark page); `--heading-band` (`bg-heading-band`), the `#` band, one step
@@ -1371,7 +1383,9 @@ into a table, a record or an overview.
1371
1383
  `more` (the page's own actions). `deleted={{ shown, onShownChange }}` adds
1372
1384
  "Show Deleted" as the menu's last item and, while it's on, an info
1373
1385
  `Notice` with "Back to the List" in a `role="status"` region that is
1374
- always there. It holds no state: the app keeps `shown`.
1386
+ always there. It holds no state: the app keeps `shown`. The menu is as
1387
+ wide as its longest item and never wraps one (4.105), as is a row's ⋯
1388
+ menu.
1375
1389
  - **`Timeline`: a record's dated history.** `items` newest first
1376
1390
  (`{ id, date, dateTime?, kind?, body, edit? }`): dates in a tabular
1377
1391
  column on the left, a dot and a thin line, the entry on the right with
@@ -1623,8 +1637,9 @@ its short facts the last tab, Details. A mark goes left of the title.
1623
1637
  - **Tabs** (`tab` on a section): a line tab list under the strip and any
1624
1638
  sections with no tab, one tab per name in the order the sections first
1625
1639
  give it. The look is the record standard's 3B (4.101): 44px tabs in
1626
- 16px semibold (14px under 48rem), the selected one in foreground text
1627
- with a 3px primary line under it, the others muted; the list's own
1640
+ 16px semibold (14px under 48rem), the selected one's name in the theme
1641
+ colour (`--primary-text`, 4.105) with a 3px primary line under it, the
1642
+ others muted; the list's own
1628
1643
  bottom border runs the column's width. A tab's count (`tabCounts`, by
1629
1644
  name: the records it holds) sits beside its name in a small muted
1630
1645
  pill; a tab with none shows no count. A list wider than the column
@@ -13,7 +13,7 @@ to the device, where the app's service worker shows it.
13
13
  | `usePushPermission()` | the package | Whether this device gets reminders, and `enable`/`disable` |
14
14
  | `AllowReminders` | the package | The control: says what reminders are, then asks, on a click |
15
15
  | `/push/public-key`, `/push/subscriptions` | `openapi.yaml`, the foundation's part (optional) | The VAPID key to subscribe with; this device's subscription saved or dropped |
16
- | `foundation_backend.push` | `ui-foundation-backend` | `send_push(session, user_id, title, body, url)`: encrypted (RFC 8291), signed (VAPID), to every device the user allowed |
16
+ | `foundation_backend.push` | `ui-foundation-backend` | `send_push(session, user_id, title, body, url)`: encrypted (RFC 8291), signed (VAPID), to every device the user allowed; optionally a `PushAction` button and `renotify` |
17
17
  | `foundation_backend.reminders`, `reminders` | `ui-foundation-backend` | A reminder row (when, which days, the text, the path), and the `send-reminders` job that sends each one when it's due |
18
18
 
19
19
  Off until the backend turns it on (`PUSH_ENABLED`, `docs/deploy.md`
@@ -149,8 +149,9 @@ the same rules and agree on every next occurrence.
149
149
  - **Done**: the app's Done button (or a notification action that calls
150
150
  the app) runs `reminders.mark_done(row)` and commits: the occurrence is
151
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
152
+ pending; for `fromCompletion` it counts from the done time (and from
153
+ the notification itself: "A Done button on the notification" below).
154
+ After the rule itself changes, `reminders.schedule_changed(row)` forgets where it
154
155
  was.
155
156
  - **Moving a simple schedule over**: `recurrence.from_weekdays(days,
156
157
  time_of_day, time_zone, start=today)` (and the package's
@@ -164,6 +165,52 @@ the same rules and agree on every next occurrence.
164
165
  `formatOccurrence` for a Next one (cell-patterns.md "A repeat and its
165
166
  next time").
166
167
 
168
+ ## A Done button on the notification (4.104)
169
+
170
+ A repeating reminder's push can carry a **Done** button that marks the
171
+ occurrence done without opening the app. The app names its own endpoint;
172
+ the job puts it on each occurrence's push:
173
+
174
+ ```python
175
+ from foundation_backend import push, reminders
176
+
177
+ reminders.register(
178
+ model=MyReminder,
179
+ done_action=lambda row, occurrence: push.PushAction(
180
+ f"/api/reminders/{row.id}/done", {"occurrence": occurrence.isoformat()}
181
+ ),
182
+ )
183
+ ```
184
+
185
+ - **The endpoint is the app's**: an ordinary signed-in route
186
+ (`POST /reminders/{id}/done`, body `{ occurrence }`) that loads the
187
+ user's own row, checks the occurrence is still the pending one (a tap
188
+ on an old notification marks nothing), runs `reminders.mark_done(row)`
189
+ and commits. Answer 2xx when done or already done; anything else counts
190
+ as a failure. Return nothing the worker needs to read.
191
+ - **What the service worker does** (`/push-sw.js`, from `pwa()`): shows
192
+ the button where the browser has notification buttons (Chrome, Edge,
193
+ Firefox on desktop, Chrome on Android). Tapped, it POSTs the action's
194
+ body as JSON to its path on the app's own origin with the session
195
+ cookie (`credentials: 'same-origin'`), and opens no window. Done, the
196
+ notification closes. Refused (signed out, a 4xx or 5xx) or offline, it
197
+ opens the reminder's `url` instead, so the person can do it in the app.
198
+ - **iOS Safari and any browser without buttons** shows the notification
199
+ without one; a tap opens the `url` as always. Keep a Done button on the
200
+ reminder's own page.
201
+ - **Only the app's own paths.** `PushAction`'s `path` (like `url`) must
202
+ start with one `/`: `send_push` refuses `https://...`, `//host`, a
203
+ backslash or a control character, and the worker checks again and
204
+ drops a button whose path resolves to any other origin.
205
+ - **Nags sound again.** A nag is re-sent under the same tag
206
+ (`reminder-{id}`), which a browser otherwise replaces silently; the job
207
+ sends it with `renotify`, so it rings again. `send_push(..., tag=...,
208
+ renotify=True, action=PushAction(...))` does the same for an app's own
209
+ pushes.
210
+ - **A weekday-set reminder** (no `recurrence`) has no occurrence to mark,
211
+ so it gets no button. Left out, `done_action` adds none: pushes look as
212
+ before.
213
+
167
214
  ## Testing
168
215
 
169
216
  Under MSW the page is held by MSW's service worker, so `usePushPermission`
@@ -1,7 +1,13 @@
1
1
  import type { ReactNode } from 'react';
2
+ import { type StatusKind } from '../../lib/status-kinds.js';
3
+ import type { IconComponent } from './icon-component.js';
2
4
  export type ChoiceButtonsOption<T> = {
3
5
  value: T;
4
6
  label: string;
7
+ /** A status kind (4.105): its icon, in its colour, before the word, as StatusMark draws it. */
8
+ kind?: StatusKind;
9
+ /** An icon before the word; with `kind`, in place of the kind's. Uncoloured without a `kind`. */
10
+ icon?: IconComponent;
5
11
  };
6
12
  export type ChoiceButtonsProps<T extends string | number> = {
7
13
  /** The group's id. Name it with `aria-labelledby` (the FieldLabel's id) or `aria-label`. */
@@ -1,6 +1,7 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { cn } from 'cn';
3
3
  import { ToggleGroup, ToggleGroupItem } from '../ui/toggle-group.js';
4
+ import { STATUS_KIND_ICONS, STATUS_KIND_TONES } from '../../lib/status-kinds.js';
4
5
  export function ChoiceButtons({ id, options, value, onValueChange, render, clearable = false, invalid = false, disabled = false, className, ...aria }) {
5
6
  const at = value == null ? -1 : options.findIndex((option) => option.value === value);
6
7
  return (_jsx(ToggleGroup, { id: id, "data-slot": "choice-buttons", variant: "outline", spacing: 0, value: at === -1 ? [] : [String(at)], onValueChange: (next) => {
@@ -13,10 +14,19 @@ export function ChoiceButtons({ id, options, value, onValueChange, render, clear
13
14
  const option = options[Number(key)];
14
15
  if (option && option.value !== value)
15
16
  onValueChange(option.value);
16
- }, disabled: disabled, "aria-invalid": invalid || undefined, className: cn('max-w-full min-w-0 flex-wrap gap-y-1 rounded-md pl-px aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40', className), ...aria, children: options.map((option, index) => (_jsx(ToggleGroupItem, { value: String(index), className: cn(
17
+ }, disabled: disabled, "aria-invalid": invalid || undefined, className: cn('max-w-full min-w-0 flex-wrap gap-y-1 rounded-md pl-px aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40', className), ...aria, children: options.map((option, index) => (_jsxs(ToggleGroupItem, { value: String(index), className: cn(
17
18
  // Every button has its left border (`!`: the joined group drops it
18
19
  // after the first) and overlaps the one before by it, so a button
19
20
  // that wraps to a new line starts with an edge; `pl-px` on the
20
21
  // group keeps that edge inside the box.
21
- '-ml-px border-l! h-(--control-height,--spacing(8)) max-w-full px-3 font-normal text-muted-foreground aria-pressed:font-medium aria-pressed:text-foreground', invalid && 'border-destructive'), children: render ? render(option.value, option.label) : option.label }, String(option.value)))) }));
22
+ '-ml-px border-l! h-(--control-height,--spacing(8)) max-w-full px-3 font-normal text-muted-foreground',
23
+ // Picked: the theme colour. On top of the ones before and
24
+ // after it (`z-1`), so its whole border shows where they overlap.
25
+ 'aria-pressed:z-1 aria-pressed:border-primary aria-pressed:bg-primary/12 aria-pressed:font-medium aria-pressed:text-primary-text hover:aria-pressed:bg-primary/16 hover:aria-pressed:text-primary-text', invalid && 'border-destructive'), children: [_jsx(OptionIcon, { option: option }), render ? render(option.value, option.label) : option.label] }, String(option.value)))) }));
26
+ }
27
+ function OptionIcon({ option }) {
28
+ const Icon = option.icon ?? (option.kind ? STATUS_KIND_ICONS[option.kind] : undefined);
29
+ if (!Icon)
30
+ return null;
31
+ return (_jsx(Icon, { "aria-hidden": "true", "data-slot": "choice-buttons-icon", "data-kind": option.kind, className: cn('size-3.5 shrink-0', option.kind && STATUS_KIND_TONES[option.kind]) }));
22
32
  }
@@ -30,7 +30,7 @@ export function RowActions({ actions, rowLabel }) {
30
30
  if (only) {
31
31
  return only.icon ? (_jsx(IconAction, { icon: only.icon, label: only.label, tone: only.tone, size: "sm", variant: "ghost", disabled: only.disabled, onClick: only.onSelect, "data-slot": "data-table-row-action" })) : (_jsx(Button, { variant: "ghost", size: "sm", disabled: only.disabled, onClick: only.onSelect, "data-slot": "data-table-row-action", className: cn(only.tone === 'destructive' && 'text-destructive-text'), children: only.label }));
32
32
  }
33
- return (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsx(IconAction, { icon: EllipsisIcon, label: rowLabel ? `Actions for ${rowLabel}` : 'Actions', size: "sm", variant: "ghost", "data-slot": "data-table-row-actions" }) }), _jsx(DropdownMenuContent, { align: "end", className: "w-44", children: actions.map((action) => {
33
+ return (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsx(IconAction, { icon: EllipsisIcon, label: rowLabel ? `Actions for ${rowLabel}` : 'Actions', size: "sm", variant: "ghost", "data-slot": "data-table-row-actions" }) }), _jsx(DropdownMenuContent, { align: "end", className: "w-max min-w-44 max-w-(--available-width) whitespace-nowrap", children: actions.map((action) => {
34
34
  const Icon = action.icon;
35
35
  return (_jsxs(DropdownMenuItem, { variant: action.tone === 'destructive' ? 'destructive' : 'default', disabled: action.disabled, onClick: action.onSelect, children: [Icon ? _jsx(Icon, { "aria-hidden": "true" }) : null, action.label] }, action.label));
36
36
  }) })] }));
@@ -257,6 +257,13 @@ const TOTALS_LABEL_CLASS = 'h-auto py-(--table-cell-py)';
257
257
  // its column header for a screen reader, but takes no room: each header
258
258
  // is its name in an sr-only span, in a cell with no height or padding.
259
259
  const HIDDEN_HEAD_CLASS = 'h-0 p-0';
260
+ // The column header row (4.105): the muted fill on every header cell, so
261
+ // the row of names reads apart from the rows of data, in the plain and
262
+ // framed looks alike. On the cells, not the row, so a pinned or stuck
263
+ // header cell (opaque, bg-background above) wears it too: listed after
264
+ // those, it wins. Its words keep --foreground, clear on --muted in every
265
+ // theme and palette.
266
+ const HEAD_CELL_CLASS = 'bg-muted';
260
267
  // A group's heading row (`groupBy`): a little air above, so the groups
261
268
  // read apart, and the page's background, never the zebra stripe.
262
269
  // A column's `meta.align` as the class its header, cells and totals take.
@@ -825,7 +832,7 @@ export function DataTable({ columns, data, total, page, pageSize, onPageChange,
825
832
  header.column.columnDef.meta?.align === 'right' && 'ml-auto flex-row-reverse'), onClick: header.column.getToggleSortingHandler(), children: [flexRender(header.column.columnDef.header, header.getContext()), sortDirection === 'asc' ? (_jsx(ArrowUpIcon, { className: "size-3.5 text-muted-foreground" })) : sortDirection === 'desc' ? (_jsx(ArrowDownIcon, { className: "size-3.5 text-muted-foreground" })) : (_jsx(ArrowUpDownIcon, { className: "size-3.5 text-muted-foreground/50" }))] })) : (flexRender(header.column.columnDef.header, header.getContext()));
826
833
  return (_jsx(TableHead, { className: cn(!showHeader && HIDDEN_HEAD_CLASS, pinFirstColumn && index === 0 && PINNED_COLUMN_CLASS, pinLast &&
827
834
  index === headerGroup.headers.length - 1 &&
828
- PINNED_LAST_COLUMN_CLASS, stickyGroups && showHeader && STICKY_HEAD_CELL_CLASS, alignClass(header.column.columnDef.meta?.align)), "aria-sort": !canSort
835
+ PINNED_LAST_COLUMN_CLASS, stickyGroups && showHeader && STICKY_HEAD_CELL_CLASS, showHeader && HEAD_CELL_CLASS, alignClass(header.column.columnDef.meta?.align)), "aria-sort": !canSort
829
836
  ? undefined
830
837
  : sortDirection === 'asc'
831
838
  ? 'ascending'
@@ -2,6 +2,7 @@ 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
4
  import { type Recurrence } from '../../lib/recurrence.js';
5
+ import { type ChoiceButtonsOption } from './choice-buttons.js';
5
6
  import type { EditInPlace } from './edit-in-place.js';
6
7
  /** What the value saves as: with `required: true` never `null` (a blank is refused). */
7
8
  export type InPlaceSaved<TValue, TRequired extends boolean> = TRequired extends true ? TValue : TValue | null;
@@ -96,11 +97,11 @@ export type InPlaceRecurrenceConfig<TRequired extends boolean = boolean> = {
96
97
  now?: Date;
97
98
  locale?: string;
98
99
  };
99
- /** One option of a select: its value and its words. */
100
- export type InPlaceOption<T> = {
101
- value: T;
102
- label: string;
103
- };
100
+ /**
101
+ * One option of a select: its value and its words. `kind` and `icon`
102
+ * (4.105) are ChoiceButtons': drawn by `look: 'buttons'` only.
103
+ */
104
+ export type InPlaceOption<T> = ChoiceButtonsOption<T>;
104
105
  /**
105
106
  * One of a fixed list. Not `required`: the list starts with "Not set",
106
107
  * which saves `null` (as buttons, pressing the picked one again does).
@@ -151,9 +151,13 @@ export type EntityViewProps = {
151
151
  * A row of the record's key numbers (`<KeyStats>`) under the header and
152
152
  * its notice, across the page at every width: in the rail layout above
153
153
  * both columns, so on a phone it comes before the rail and the main
154
- * column.
154
+ * column. Left out in a small card dialog (RecordDialogRoute
155
+ * `look="card"`, 4.105): a tiny record's facts are its few rows, so
156
+ * `cardStrip` keeps it there.
155
157
  */
156
158
  strip?: ReactNode;
159
+ /** Show `strip` in a small card dialog too (4.105); off by default. */
160
+ cardStrip?: boolean;
157
161
  sections: EntityViewSection[];
158
162
  /**
159
163
  * Below every section (both columns in the rail layout), in small muted
@@ -245,4 +249,4 @@ export type EntityViewProps = {
245
249
  trail?: readonly PageCrumb[];
246
250
  };
247
251
  };
248
- export declare function EntityView({ title, documentTitle, titleEdit, leading, subtitle, badges, actions, notice, strip, sections, footer, layout, detailsTab, tabCounts, tabsStickyTop, mobileOrder, railLabel, railFields, emptyFields, emptyText, printLabel, printLook, isLoading, error, onRetry, back, }: EntityViewProps): import("react").JSX.Element;
252
+ export declare function EntityView({ title, documentTitle, titleEdit, leading, subtitle, badges, actions, notice, strip, cardStrip, sections, footer, layout, detailsTab, tabCounts, tabsStickyTop, mobileOrder, railLabel, railFields, emptyFields, emptyText, printLabel, printLook, isLoading, error, onRetry, back, }: EntityViewProps): import("react").JSX.Element;
@@ -74,7 +74,8 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
74
74
  // switch. With no `tab` on any section, nothing changes.
75
75
  //
76
76
  // The tab bar (4.101, record standard 3B): bigger underline tabs (16px
77
- // semibold, 14px on a phone), a 3px primary line under the open one, each
77
+ // semibold, 14px on a phone), a 3px primary line under the open one and
78
+ // its name in the theme colour (`text-primary-text`, 4.105), each
78
79
  // tab's count beside its name (`tabCounts`; none for zero). The bar sticks
79
80
  // to the top of whatever scrolls (the page, or a record dialog's body) as
80
81
  // the record scrolls under it, `tabsStickyTop` below the top, and once
@@ -314,7 +315,7 @@ function MainTabs({ tabs, label, railFields = 'beside', title, counts, stickyTop
314
315
  // padding, so the bar sits at the body's own top edge there.
315
316
  style: { top: stickyTop ?? 'var(--entity-view-sticky-top, 0px)' }, className: "sticky z-10 -mx-1 flex min-w-0 flex-col gap-1 bg-background px-1 pt-0 data-[stuck]:pt-2 data-[stuck]:shadow-[0_8px_12px_-10px_var(--color-foreground)]", children: [stuck && title && (_jsx("p", { "data-slot": "entity-view-tab-bar-title", "aria-hidden": "true", className: "truncate type-label font-semibold text-foreground", children: title })), _jsx(TabsList, { variant: "line", activateOnFocus: true, "aria-label": label, className: "h-auto w-full max-w-full justify-start gap-0 overflow-x-auto overflow-y-hidden border-b border-border p-0 md:gap-1 [scrollbar-width:thin]", children: tabs.map((tab) => {
316
317
  const count = countOf(tab);
317
- return (_jsxs(TabsTrigger, { value: tab.slug, className: "h-11 flex-none gap-1.5 px-2.5 text-sm font-semibold text-muted-foreground group-data-horizontal/tabs:after:bottom-0 group-data-horizontal/tabs:after:h-[3px] after:bg-primary data-active:text-foreground md:px-4 md:text-base dark:text-muted-foreground dark:data-active:text-foreground", children: [tab.name, count > 0 && (_jsx("span", { "data-slot": "entity-view-tab-count", className: "rounded-full bg-muted px-1.5 text-xs leading-[1.0625rem] font-medium tabular-nums text-foreground", children: count }))] }, tab.slug));
318
+ return (_jsxs(TabsTrigger, { value: tab.slug, className: "h-11 flex-none gap-1.5 px-2.5 text-sm font-semibold text-muted-foreground group-data-horizontal/tabs:after:bottom-0 group-data-horizontal/tabs:after:h-[3px] after:bg-primary data-active:text-primary-text md:px-4 md:text-base dark:text-muted-foreground dark:data-active:text-primary-text", children: [tab.name, count > 0 && (_jsx("span", { "data-slot": "entity-view-tab-count", className: "rounded-full bg-muted px-1.5 text-xs leading-[1.0625rem] font-medium tabular-nums text-foreground", children: count }))] }, tab.slug));
318
319
  }) })] }), tabs.map((tab) => (_jsx(TabsContent, { value: tab.slug, keepMounted: true, className: "@container/tab flex min-w-0 flex-col gap-6 [font-size:inherit]", children: _jsx(TabBody, { tab: tab, railFields: railFields }) }, tab.slug)))] }));
319
320
  }
320
321
  // The `tabs` layout's sections (1A): the main column's untabbed sections,
@@ -341,7 +342,7 @@ function tabsLayout(sections, detailsTab) {
341
342
  tabs.push({ slug, name: detailsTab, sections: facts, side: [], details: true });
342
343
  return { above: main.filter((section) => section.tab === undefined), tabs, factsInColumn: false };
343
344
  }
344
- export function EntityView({ title, documentTitle, titleEdit, leading, subtitle, badges, actions, notice, strip, sections, footer, layout = 'tabs', detailsTab = 'Details', tabCounts, tabsStickyTop, mobileOrder = 'rail-first', railLabel, railFields = 'beside', emptyFields = 'show', emptyText = EMPTY_DASH, printLabel = 'Print Notes', printLook = 'icon', isLoading, error, onRetry, back, }) {
345
+ export function EntityView({ title, documentTitle, titleEdit, leading, subtitle, badges, actions, notice, strip, cardStrip = false, sections, footer, layout = 'tabs', detailsTab = 'Details', tabCounts, tabsStickyTop, mobileOrder = 'rail-first', railLabel, railFields = 'beside', emptyFields = 'show', emptyText = EMPTY_DASH, printLabel = 'Print Notes', printLook = 'icon', isLoading, error, onRetry, back, }) {
345
346
  // Editing in place: one store per view, and the leave-page prompt only
346
347
  // while a field is open (or one is always editable).
347
348
  const [store] = useState(() => new EditInPlaceStore());
@@ -408,5 +409,5 @@ export function EntityView({ title, documentTitle, titleEdit, leading, subtitle,
408
409
  .filter((section) => !tabbed(section))
409
410
  .map((section) => (_jsx(ViewSection, { section: section }, section.title))), tabList] }));
410
411
  }
411
- return (_jsx(EditInPlaceContext.Provider, { value: store, children: _jsx(EmptyContext.Provider, { value: { text: emptyText, fold: emptyFields === 'fold' }, children: _jsxs("div", { className: layout === 'rail' && !card ? RAIL_LAYOUT.page : cn('flex max-w-4xl flex-col', card ? 'gap-4' : 'gap-6'), "data-state": "success", "data-layout": layout, "data-look": card ? 'card' : undefined, children: [editing && _jsx(LeaveGuard, { store: store }), !dialog && !trail && _jsx(BackLink, { back: back }), !dialog && trail && !inShell && _jsx(PageTrail, { crumbs: trail }), _jsxs("header", { className: card ? 'flex items-start justify-between gap-3' : 'flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between', children: [_jsxs("div", { className: cn('flex min-w-0 flex-1 items-start gap-3', !card && 'sm:min-w-64 sm:gap-4'), children: [leading && (_jsx("div", { "data-slot": "entity-view-leading", className: "flex shrink-0 items-center", children: leading })), _jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-2", children: [_jsxs("div", { "data-slot": "entity-view-title-line", className: "flex min-w-0 flex-wrap items-center gap-x-3 gap-y-2", children: [_jsx("h1", { id: dialog?.titleId, className: cn('min-w-0 max-w-full break-words text-foreground', card ? 'type-section-title' : 'type-page-title'), children: titleEdit ? (_jsx(EditableField, { label: titleEdit.label, edit: titleEdit, layout: "inline", keepPencilRoom: true, children: title })) : (title) }), badges && (_jsx("div", { "data-slot": "entity-view-badges", className: "flex flex-wrap items-center gap-1.5", children: badges }))] }), subtitle && (_jsx("div", { "data-slot": "entity-view-subtitle", className: "type-body break-words text-muted-foreground", children: subtitle }))] })] }), card ? (_jsxs("div", { "data-slot": "entity-view-card-controls", className: "flex shrink-0 items-center gap-1", children: [printButton, actions, dialog?.controls] })) : ((actions || printButton) && (_jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-2 sm:justify-end", children: [printButton, actions] })))] }), _jsx("div", { role: "status", "data-slot": "entity-view-notice", className: "empty:hidden", children: notice }), strip && _jsx("div", { "data-slot": "entity-view-strip", children: strip }), body, footer && (_jsx("footer", { "data-slot": "entity-view-footer", className: "type-caption text-muted-foreground", children: footer }))] }) }) }));
412
+ return (_jsx(EditInPlaceContext.Provider, { value: store, children: _jsx(EmptyContext.Provider, { value: { text: emptyText, fold: emptyFields === 'fold' }, children: _jsxs("div", { className: layout === 'rail' && !card ? RAIL_LAYOUT.page : cn('flex max-w-4xl flex-col', card ? 'gap-4' : 'gap-6'), "data-state": "success", "data-layout": layout, "data-look": card ? 'card' : undefined, children: [editing && _jsx(LeaveGuard, { store: store }), !dialog && !trail && _jsx(BackLink, { back: back }), !dialog && trail && !inShell && _jsx(PageTrail, { crumbs: trail }), _jsxs("header", { className: card ? 'flex items-start justify-between gap-3' : 'flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between', children: [_jsxs("div", { className: cn('flex min-w-0 flex-1 items-start gap-3', !card && 'sm:min-w-64 sm:gap-4'), children: [leading && (_jsx("div", { "data-slot": "entity-view-leading", className: "flex shrink-0 items-center", children: leading })), _jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-2", children: [_jsxs("div", { "data-slot": "entity-view-title-line", className: "flex min-w-0 flex-wrap items-center gap-x-3 gap-y-2", children: [_jsx("h1", { id: dialog?.titleId, className: cn('min-w-0 max-w-full break-words text-foreground', card ? 'type-section-title' : 'type-page-title'), children: titleEdit ? (_jsx(EditableField, { label: titleEdit.label, edit: titleEdit, layout: "inline", keepPencilRoom: true, children: title })) : (title) }), badges && (_jsx("div", { "data-slot": "entity-view-badges", className: "flex flex-wrap items-center gap-1.5", children: badges }))] }), subtitle && (_jsx("div", { "data-slot": "entity-view-subtitle", className: "type-body break-words text-muted-foreground", children: subtitle }))] })] }), card ? (_jsxs("div", { "data-slot": "entity-view-card-controls", className: "flex shrink-0 items-center gap-1", children: [printButton, actions, dialog?.controls] })) : ((actions || printButton) && (_jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-2 sm:justify-end", children: [printButton, actions] })))] }), _jsx("div", { role: "status", "data-slot": "entity-view-notice", className: "empty:hidden", children: notice }), strip && (!card || cardStrip) && _jsx("div", { "data-slot": "entity-view-strip", children: strip }), body, footer && (_jsx("footer", { "data-slot": "entity-view-footer", className: "type-caption text-muted-foreground", children: footer }))] }) }) }));
412
413
  }
@@ -41,6 +41,6 @@ export function ListHeader({ title, count, links = [], newAction, more = [], del
41
41
  const outLink = links.length === 1 ? links[0] : undefined;
42
42
  const menuLinks = links.length > 1 ? links : [];
43
43
  const hasMenu = menuLinks.length > 0 || more.length > 0 || deleted !== undefined;
44
- return (_jsxs("div", { "data-slot": "list-header", className: cn('flex flex-col', className), children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-x-4 gap-y-2", children: [_jsxs("h1", { className: "flex items-baseline gap-2 type-page-title text-foreground", children: [title, count !== undefined && (_jsxs("span", { className: "type-body font-normal tabular-nums text-muted-foreground", children: [_jsx("span", { className: "sr-only", children: ", " }), count] }))] }), siblings.length > 1 && _jsx(SiblingSwitch, { siblings: siblings, label: siblingsLabel ?? `${title} Lists` }), _jsxs("div", { className: "ml-auto flex flex-wrap items-center gap-2", children: [outLink && (_jsxs(Button, { size: "sm", variant: "outline", nativeButton: false, render: _jsx(Link, { to: outLink.to }), children: [outLink.icon && _jsx(outLink.icon, { "aria-hidden": "true" }), outLink.label] })), hasMenu && (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsx(Button, { size: "icon-sm", variant: "outline", "aria-label": `More for ${title}`, "data-slot": "list-header-more" }), children: _jsx(EllipsisIcon, { "aria-hidden": "true" }) }), _jsxs(DropdownMenuContent, { align: "end", children: [menuLinks.map((link) => (_jsxs(DropdownMenuItem, { render: _jsx(Link, { to: link.to }), children: [link.icon && _jsx(link.icon, { "aria-hidden": "true" }), link.label] }, link.label))), more.map((action) => (_jsxs(DropdownMenuItem, { onClick: action.onSelect, children: [action.icon && _jsx(action.icon, { "aria-hidden": "true" }), action.label] }, action.label))), deleted && (menuLinks.length > 0 || more.length > 0) && _jsx(DropdownMenuSeparator, {}), deleted && (_jsxs(DropdownMenuCheckboxItem, { closeOnClick: true, checked: deleted.shown, onCheckedChange: deleted.onShownChange, children: [_jsx(Trash2Icon, { "aria-hidden": "true" }), "Show Deleted"] }))] })] })), newAction &&
44
+ return (_jsxs("div", { "data-slot": "list-header", className: cn('flex flex-col', className), children: [_jsxs("div", { className: "flex flex-wrap items-center justify-between gap-x-4 gap-y-2", children: [_jsxs("h1", { className: "flex items-baseline gap-2 type-page-title text-foreground", children: [title, count !== undefined && (_jsxs("span", { className: "type-body font-normal tabular-nums text-muted-foreground", children: [_jsx("span", { className: "sr-only", children: ", " }), count] }))] }), siblings.length > 1 && _jsx(SiblingSwitch, { siblings: siblings, label: siblingsLabel ?? `${title} Lists` }), _jsxs("div", { className: "ml-auto flex flex-wrap items-center gap-2", children: [outLink && (_jsxs(Button, { size: "sm", variant: "outline", nativeButton: false, render: _jsx(Link, { to: outLink.to }), children: [outLink.icon && _jsx(outLink.icon, { "aria-hidden": "true" }), outLink.label] })), hasMenu && (_jsxs(DropdownMenu, { children: [_jsx(DropdownMenuTrigger, { render: _jsx(Button, { size: "icon-sm", variant: "outline", "aria-label": `More for ${title}`, "data-slot": "list-header-more" }), children: _jsx(EllipsisIcon, { "aria-hidden": "true" }) }), _jsxs(DropdownMenuContent, { align: "end", className: "w-max max-w-(--available-width) whitespace-nowrap", children: [menuLinks.map((link) => (_jsxs(DropdownMenuItem, { render: _jsx(Link, { to: link.to }), children: [link.icon && _jsx(link.icon, { "aria-hidden": "true" }), link.label] }, link.label))), more.map((action) => (_jsxs(DropdownMenuItem, { onClick: action.onSelect, children: [action.icon && _jsx(action.icon, { "aria-hidden": "true" }), action.label] }, action.label))), deleted && (menuLinks.length > 0 || more.length > 0) && _jsx(DropdownMenuSeparator, {}), deleted && (_jsxs(DropdownMenuCheckboxItem, { closeOnClick: true, checked: deleted.shown, onCheckedChange: deleted.onShownChange, children: [_jsx(Trash2Icon, { "aria-hidden": "true" }), "Show Deleted"] }))] })] })), newAction &&
45
45
  (newAction.to !== undefined ? (_jsxs(Button, { size: "sm", nativeButton: false, render: _jsx(Link, { to: newAction.to }), children: [_jsx(PlusIcon, { "aria-hidden": "true" }), newAction.label] })) : (_jsxs(Button, { size: "sm", onClick: newAction.onClick, children: [_jsx(PlusIcon, { "aria-hidden": "true" }), newAction.label] })))] })] }), _jsx("div", { role: "status", "data-slot": "list-header-notice", className: "not-empty:mt-3", children: deleted?.shown && (_jsxs(Notice, { tone: "info", icon: Trash2Icon, action: _jsx(Button, { size: "sm", variant: "outline", onClick: () => deleted.onShownChange(false), children: "Back to the List" }), children: ["Showing deleted ", deleted.noun ?? 'records', "."] })) })] }));
46
46
  }
@@ -8,6 +8,17 @@ export type TableView<F extends string, M extends string> = {
8
8
  label?: string;
9
9
  filters?: Partial<Record<F, string>>;
10
10
  multiFilters?: Partial<Record<M, string[]>>;
11
+ /**
12
+ * The part of the view the filter bar has no control for (4.105): a
13
+ * computed rule the server applies, such as `{ overdue: 'true' }`. It's
14
+ * in the URL like a filter and counts toward the view being on, but the
15
+ * reader can't see or change it, so it lasts only while the view does:
16
+ * the first filter the reader changes clears it (filterChanges), and
17
+ * the rows are then what the bar shows. Put everything a control can
18
+ * show in `filters` and `multiFilters`, so the bar says why rows are
19
+ * hidden.
20
+ */
21
+ rule?: Partial<Record<F, string>>;
11
22
  sort?: Sort;
12
23
  /**
13
24
  * The ids of the columns this view shows, for DataTable's
@@ -25,6 +36,23 @@ export type TableView<F extends string, M extends string> = {
25
36
  };
26
37
  export declare function serializeSort(next: Sort): string | null;
27
38
  export declare function applyUrlChanges(previous: URLSearchParams, changes: UrlChanges): URLSearchParams;
28
- export declare function viewToUrlChanges<F extends string, M extends string>(filterNames: readonly F[], multiFilterNames: readonly M[], view: TableView<F, M>): UrlChanges;
39
+ export declare function viewToUrlChanges<F extends string, M extends string>(filterNames: readonly F[], multiFilterNames: readonly M[], view: TableView<F, M>, asDefault?: boolean): UrlChanges;
40
+ /**
41
+ * The query parameter that says "no view, no filters" on a list with a
42
+ * `defaultView` (4.105): `?view=none`. Without it a list's plain address
43
+ * is its default view, so clearing the last filter by hand writes it, or
44
+ * the default view's filters would come straight back.
45
+ */
46
+ export declare const NO_VIEW_PARAM = "view";
47
+ /** Every filter that some view's `rule` sets: the ones no control shows. */
48
+ export declare function ruleFilterNames<F extends string, M extends string>(views: Readonly<Record<string, TableView<F, M>>>): F[];
49
+ export type FilterState<F extends string, M extends string> = {
50
+ filters: Record<F, string>;
51
+ multiFilters: Record<M, string[]>;
52
+ /** The URL names no filter, so these are the default view's (useTableUrlState's `defaultView`). */
53
+ atDefault: boolean;
54
+ };
55
+ export declare function readFilterState<F extends string, M extends string>(params: URLSearchParams, filterNames: readonly F[], multiFilterNames: readonly M[], defaultView?: TableView<F, M>): FilterState<F, M>;
56
+ export declare function filterChanges<F extends string, M extends string>(state: FilterState<F, M>, changes: Readonly<Record<string, string | string[] | undefined>>, ruleNames: readonly F[], hasDefault: boolean): UrlChanges;
29
57
  export declare function activeViewOf<F extends string, M extends string, V extends string>(views: Readonly<Record<V, TableView<F, M>>>, filters: Readonly<Record<F, string>>, multiFilters: Readonly<Record<M, readonly string[]>>): V | null;
30
58
  export {};
@@ -22,17 +22,86 @@ export function applyUrlChanges(previous, changes) {
22
22
  // are set, and any the view doesn't name are cleared. Merging over the
23
23
  // current state instead would let a leftover filter silently show something
24
24
  // other than the view. Decided with the developer on 2026-09-28.
25
- export function viewToUrlChanges(filterNames, multiFilterNames, view) {
25
+ //
26
+ // The view the list opens on (`asDefault`, useTableUrlState's
27
+ // `defaultView`) is written as no filters at all, so the list's plain
28
+ // address is that view (readFilterState fills its filters back in).
29
+ export function viewToUrlChanges(filterNames, multiFilterNames, view, asDefault = false) {
30
+ const own = asDefault ? {} : viewFilters(view);
26
31
  return {
27
- ...Object.fromEntries(filterNames.map((name) => [name, view.filters?.[name] ?? ''])),
28
- ...Object.fromEntries(multiFilterNames.map((name) => [name, view.multiFilters?.[name] ?? []])),
32
+ // First, so a list's own filter of that name (one with no default view) wins.
33
+ [NO_VIEW_PARAM]: null,
34
+ ...Object.fromEntries(filterNames.map((name) => [name, own[name] ?? ''])),
35
+ ...Object.fromEntries(multiFilterNames.map((name) => [name, asDefault ? [] : (view.multiFilters?.[name] ?? [])])),
29
36
  sort: view.sort ? serializeSort(view.sort) : null,
30
37
  ...(view.group === undefined ? {} : { group: view.group || null }),
31
38
  page: null,
32
39
  };
33
40
  }
34
- // Which of `views` the current filters are: the first whose filters and
35
- // multi filters equal the URL's exactly (multi filters in any order), or
41
+ // A view's single-value filters with its rule: everything it sets.
42
+ function viewFilters(view) {
43
+ return { ...view.filters, ...view.rule };
44
+ }
45
+ /**
46
+ * The query parameter that says "no view, no filters" on a list with a
47
+ * `defaultView` (4.105): `?view=none`. Without it a list's plain address
48
+ * is its default view, so clearing the last filter by hand writes it, or
49
+ * the default view's filters would come straight back.
50
+ */
51
+ export const NO_VIEW_PARAM = 'view';
52
+ /** Every filter that some view's `rule` sets: the ones no control shows. */
53
+ export function ruleFilterNames(views) {
54
+ const names = new Set();
55
+ for (const view of Object.values(views))
56
+ for (const name of Object.keys(view.rule ?? {}))
57
+ names.add(name);
58
+ return [...names];
59
+ }
60
+ // The filters the bar shows and the query uses: the URL's, or, at a
61
+ // list's plain address (no filter and no `?view=none`), its default
62
+ // view's. So the default view's controls show what it means, the same as
63
+ // any other view's.
64
+ export function readFilterState(params, filterNames, multiFilterNames, defaultView) {
65
+ const named = filterNames.some((name) => Boolean(params.get(name))) || multiFilterNames.some((name) => params.getAll(name).length > 0);
66
+ const atDefault = defaultView !== undefined && !named && params.get(NO_VIEW_PARAM) !== 'none';
67
+ const own = atDefault ? viewFilters(defaultView) : {};
68
+ return {
69
+ filters: Object.fromEntries(filterNames.map((name) => [name, atDefault ? (own[name] ?? '') : (params.get(name) ?? '')])),
70
+ multiFilters: Object.fromEntries(multiFilterNames.map((name) => [
71
+ name,
72
+ atDefault ? [...(defaultView.multiFilters?.[name] ?? [])] : params.getAll(name),
73
+ ])),
74
+ atDefault,
75
+ };
76
+ }
77
+ // The URL changes for the reader changing filters by hand (setFilter,
78
+ // setFilters, setMultiFilter), 4.105:
79
+ // - every filter they didn't touch keeps the value the bar shows, even at
80
+ // the plain address where those come from the default view, so their
81
+ // change is the only change;
82
+ // - a view's `rule` is cleared, since no control shows it and the view it
83
+ // belonged to is no longer what's on;
84
+ // - with a `defaultView`, a result with no filter at all is written
85
+ // `?view=none`, so it stays empty instead of turning back into the
86
+ // default view.
87
+ // The page returns to 1. Which view is on follows from the result
88
+ // (activeViewOf): one whose filters it equals, often none.
89
+ export function filterChanges(state, changes, ruleNames, hasDefault) {
90
+ const next = {
91
+ ...(state.atDefault ? { ...state.filters, ...state.multiFilters } : {}),
92
+ ...Object.fromEntries(ruleNames.map((name) => [name, ''])),
93
+ };
94
+ for (const [name, value] of Object.entries(changes))
95
+ if (value !== undefined)
96
+ next[name] = value;
97
+ const result = { ...state.filters, ...state.multiFilters, ...next };
98
+ const empty = Object.values(result).every((value) => (Array.isArray(value) ? value.length === 0 : !value));
99
+ // The marker only on a list with a default view: without one, `view`
100
+ // may be a filter of the list's own, and is left alone.
101
+ return { ...next, ...(hasDefault ? { [NO_VIEW_PARAM]: empty ? 'none' : null } : {}), page: null };
102
+ }
103
+ // Which of `views` the current filters are: the first whose filters (with
104
+ // its `rule`) and multi filters equal the URL's exactly (multi filters in any order), or
36
105
  // null. A view is active only while it is still "this combination and
37
106
  // nothing else", so adding or changing any filter returns the table to its
38
107
  // default columns: a view's columns are chosen for the records its filters
@@ -41,7 +110,7 @@ export function viewToUrlChanges(filterNames, multiFilterNames, view) {
41
110
  // the developer on 2026-10-05.
42
111
  export function activeViewOf(views, filters, multiFilters) {
43
112
  const sameItems = (a, b) => a.length === b.length && [...a].sort().every((item, index) => item === [...b].sort()[index]);
44
- const matches = (view) => Object.keys(filters).every((name) => filters[name] === (view.filters?.[name] ?? '')) &&
113
+ const matches = (view) => Object.keys(filters).every((name) => filters[name] === (viewFilters(view)[name] ?? '')) &&
45
114
  Object.keys(multiFilters).every((name) => sameItems(multiFilters[name], view.multiFilters?.[name] ?? []));
46
115
  return Object.keys(views).find((id) => matches(views[id])) ?? null;
47
116
  }
@@ -21,7 +21,17 @@ export type TableUrlStateOptions = {
21
21
  */
22
22
  pageSizeStorageKey?: string;
23
23
  };
24
- export declare function useTableUrlState<F extends string, M extends string = never, V extends string = never>(filterNames: readonly F[], multiFilterNames?: readonly M[], views?: Readonly<Record<V, TableView<NoInfer<F>, NoInfer<M>>>>, { groupStorageKey, pageSizes, defaultPageSize, pageSizeStorageKey, }?: TableUrlStateOptions): {
24
+ /** useTableUrlState's options, with the view the list opens on. */
25
+ export type TableUrlStateViewOptions<V extends string> = TableUrlStateOptions & {
26
+ /**
27
+ * The view the list opens on (4.105): at the list's plain address its
28
+ * filters fill the bar and its pill is pressed. Write that view's whole
29
+ * meaning in its filters (`{ status: ['active', 'paused'] }`, not `{}`
30
+ * with the server's default doing the rest), so the bar shows it.
31
+ */
32
+ defaultView?: V;
33
+ };
34
+ export declare function useTableUrlState<F extends string, M extends string = never, V extends string = never>(filterNames: readonly F[], multiFilterNames?: readonly M[], views?: Readonly<Record<V, TableView<NoInfer<F>, NoInfer<M>>>>, { groupStorageKey, pageSizes, defaultPageSize, pageSizeStorageKey, defaultView, }?: TableUrlStateViewOptions<NoInfer<V>>): {
25
35
  page: number;
26
36
  sorting: SortingState;
27
37
  filters: Record<F, string>;
@@ -37,7 +47,7 @@ export declare function useTableUrlState<F extends string, M extends string = ne
37
47
  setFilter: (name: F, value: string) => void;
38
48
  setFilters: (changes: Partial<Record<F, string>> & Partial<Record<M, string[]>>) => void;
39
49
  setMultiFilter: (name: M, values: string[]) => void;
40
- applyView: (view: TableView<F, M>) => void;
50
+ applyView: (view: TableView<F, M>, id?: string) => void;
41
51
  };
42
52
  /** The rows per page: the URL's if it's one of the choices, then the remembered one, then the default. */
43
53
  export declare function resolvePageSize(pageSizes: readonly number[], fromUrl: string | null, remembered: string | null, defaultPageSize: number): number;
@@ -1,6 +1,6 @@
1
1
  import { useCallback, useSyncExternalStore } from 'react';
2
2
  import { useSearchParams } from 'react-router';
3
- import { activeViewOf, applyUrlChanges, serializeSort, viewToUrlChanges, } from './table-url-changes.js';
3
+ import { activeViewOf, applyUrlChanges, filterChanges, readFilterState, ruleFilterNames, serializeSort, viewToUrlChanges, } from './table-url-changes.js';
4
4
  import { browserStore } from './use-table-layout.js';
5
5
  const DEFAULT_PAGE_SIZES = [25, 50, 100];
6
6
  // A table's page, sort and filters, kept in the URL query string
@@ -18,6 +18,18 @@ const DEFAULT_PAGE_SIZES = [25, 50, 100];
18
18
  // counts as active); pass that view's `columns` to DataTable. A view is
19
19
  // pressed with applyView().
20
20
  //
21
+ // Views fill the filters (4.105). A view's `filters` and `multiFilters` are
22
+ // what the bar's controls show while it's on, so the bar says why rows are
23
+ // hidden; write each view's whole meaning there. `defaultView` names the
24
+ // view the list opens on: at the list's plain address (no filter in the
25
+ // URL) `filters` and `multiFilters` are that view's and it's the active
26
+ // one, and pressing it goes back to the plain address. Changing a filter
27
+ // by hand keeps every other filter the bar shows (the default view's
28
+ // too), clears any view's `rule` (what no control shows), and the pills
29
+ // follow: the view the result equals, usually none. Clearing every
30
+ // filter by hand on a list with a default view writes `?view=none`, so
31
+ // the list stays unfiltered.
32
+ //
21
33
  // `pageSize` is the rows per page, for the query and DataTable: `?size=` in
22
34
  // the URL, then the one remembered under `pageSizeStorageKey`, then
23
35
  // `defaultPageSize`; `setPageSize` (DataTable's `onPageSizeChange`) picks
@@ -30,7 +42,7 @@ const DEFAULT_PAGE_SIZES = [25, 50, 100];
30
42
  // names a `group` sets it when pressed.
31
43
  //
32
44
  // Every setter is one update(), and must stay one: see setFilters.
33
- export function useTableUrlState(filterNames, multiFilterNames = [], views = {}, { groupStorageKey, pageSizes = DEFAULT_PAGE_SIZES, defaultPageSize = 50, pageSizeStorageKey, } = {}) {
45
+ export function useTableUrlState(filterNames, multiFilterNames = [], views = {}, { groupStorageKey, pageSizes = DEFAULT_PAGE_SIZES, defaultPageSize = 50, pageSizeStorageKey, defaultView, } = {}) {
34
46
  const [params, setParams] = useSearchParams();
35
47
  const rememberedPageSize = useRemembered(pageSizeStorageKey);
36
48
  const pageSize = resolvePageSize(pageSizes, params.get('size'), rememberedPageSize, defaultPageSize);
@@ -43,9 +55,13 @@ export function useTableUrlState(filterNames, multiFilterNames = [], views = {},
43
55
  const page = Math.max(1, Math.floor(Number(params.get('page'))) || 1);
44
56
  const [sortField, sortDir] = (params.get('sort') ?? '').split(':');
45
57
  const sorting = sortField ? [{ id: sortField, desc: sortDir === 'desc' }] : [];
46
- const filters = Object.fromEntries(filterNames.map((name) => [name, params.get(name) ?? '']));
47
- const multiFilters = Object.fromEntries(multiFilterNames.map((name) => [name, params.getAll(name)]));
58
+ const fallback = defaultView === undefined ? undefined : views[defaultView];
59
+ const state = readFilterState(params, filterNames, multiFilterNames, fallback);
60
+ const { filters, multiFilters } = state;
48
61
  const activeView = activeViewOf(views, filters, multiFilters);
62
+ const ruleNames = ruleFilterNames(views);
63
+ // The reader changing filters by hand: see filterChanges.
64
+ const changeFilters = (changes) => update(filterChanges(state, changes, ruleNames, fallback !== undefined));
49
65
  function update(changes) {
50
66
  setParams((previous) => applyUrlChanges(previous, changes), { replace: true });
51
67
  }
@@ -69,21 +85,26 @@ export function useTableUrlState(filterNames, multiFilterNames = [], views = {},
69
85
  },
70
86
  setPage: (next) => update({ page: next > 1 ? String(next) : null }),
71
87
  setSorting: (next) => update({ sort: serializeSort(next), page: null }),
72
- setFilter: (name, value) => update({ [name]: value, page: null }),
88
+ setFilter: (name, value) => changeFilters({ [name]: value }),
73
89
  // Several filters in one call — for any user action that changes more
74
90
  // than one (both ends of a date range, "clear filters"). Two setters in
75
91
  // the same tick lose all but the last: react-router hands each
76
92
  // setSearchParams updater the params from the last render, not the
77
93
  // ones the previous updater produced. Single-value filters take a
78
94
  // string ('' clears), multi-value ones a list ([] clears).
79
- setFilters: (changes) => update({ ...changes, page: null }),
80
- setMultiFilter: (name, values) => update({ [name]: values, page: null }),
95
+ setFilters: (changes) => changeFilters(changes),
96
+ setMultiFilter: (name, values) => changeFilters({ [name]: values }),
81
97
  // Replaces the whole filter + sort state at once — a saved view. See
82
98
  // viewToUrlChanges() for why anything the view doesn't set is cleared.
83
- applyView: (view) => {
99
+ // The default view (by `id`, as DataTable's onViewChange passes it, or
100
+ // the same object) goes back to the list's plain address. `{}` is
101
+ // "no filters": the plain address too, so the default view on a list
102
+ // that has one.
103
+ applyView: (view, id) => {
84
104
  if (view.group !== undefined)
85
105
  rememberGrouping(view.group);
86
- update(viewToUrlChanges(filterNames, multiFilterNames, view));
106
+ const asDefault = fallback !== undefined && (id === defaultView || view === fallback);
107
+ update(viewToUrlChanges(filterNames, multiFilterNames, view, asDefault));
87
108
  },
88
109
  };
89
110
  }
package/dist/index.d.ts CHANGED
@@ -112,7 +112,7 @@ export type { AuthContextValue, AuthStatus, AuthUser, SignInResult } from './aut
112
112
  export type { AppError, Page, QuerySpec } from './api/contracts.js';
113
113
  export type { ErrorReportingOptions } from './error-reporting/reporter.js';
114
114
  export { createQueryClient } from './api/query-client.js';
115
- export { useTableUrlState, type TableUrlStateOptions } from './hooks/use-table-url-state.js';
115
+ export { useTableUrlState, type TableUrlStateOptions, type TableUrlStateViewOptions } from './hooks/use-table-url-state.js';
116
116
  export { useTableLayout, type TableLayoutOptions } from './hooks/use-table-layout.js';
117
117
  export { useWidgetLayout, createWidgetLayoutStore, mergeWidgetLayout, type SavedWidgetLayout, type WidgetLayout, type WidgetLayoutOptions, type WidgetLayoutStore, } from './hooks/use-widget-layout.js';
118
118
  export type { TableView, UrlChanges } from './hooks/table-url-changes.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tristan2828/ui-foundation",
3
- "version": "4.103.0",
3
+ "version": "4.105.0",
4
4
  "description": "Shared UI foundation for contract-first, database-backed React apps: shadcn primitives, DataTable/EntityForm composites, auth, the gateway error seam, design tokens, lint rules and the AI playbook.",
5
5
  "license": "MIT",
6
6
  "repository": {
package/styles/index.css CHANGED
@@ -60,6 +60,7 @@
60
60
  --color-info-foreground: var(--info-foreground);
61
61
  --color-info-text: var(--info-text);
62
62
  --color-link: var(--link);
63
+ --color-primary-text: var(--primary-text);
63
64
  --color-card-header: var(--card-header);
64
65
  --color-highlight-amber: var(--highlight-amber);
65
66
  --color-highlight-yellow: var(--highlight-yellow);
@@ -492,6 +493,7 @@
492
493
  --warning-text: var(--amber-800);
493
494
  --info-text: var(--blue-800);
494
495
  --link: var(--blue-700);
496
+ --primary-text: var(--gray-950);
495
497
  --highlight-amber: oklch(0.9 0.1 75);
496
498
  --highlight-yellow: oklch(0.94 0.13 100);
497
499
  --highlight-green: oklch(0.9 0.1 150);
package/styles/theme.css CHANGED
@@ -645,6 +645,10 @@
645
645
  /* A link in written text: coloured as well as underlined, so it reads
646
646
  as a link at a glance (on white: 5.59). */
647
647
  --link: var(--blue-700);
648
+ /* The theme colour as text (4.105): what's picked or open, such as the
649
+ open tab's name and a picked choice, in the primary's own colour where
650
+ it reads as text. Here it's the primary (near-black, 17.7 on white). */
651
+ --primary-text: var(--primary);
648
652
  /* Highlighted words in written text (the notes editor's highlight, four
649
653
  colours): a wash behind words that keep --foreground. Light washes,
650
654
  text on each measures 11 or more. */
@@ -957,6 +961,7 @@
957
961
  --warning-text: var(--amber-400);
958
962
  --info-text: var(--blue-400);
959
963
  --link: var(--blue-400); /* on near-black: 8.90 */
964
+ --primary-text: var(--primary); /* near-white on near-black */
960
965
  /* Highlighted words: deep washes, --foreground on each measures 7 or more. */
961
966
  --highlight-amber: oklch(0.42 0.09 75);
962
967
  --highlight-yellow: oklch(0.44 0.09 100);
@@ -1182,6 +1187,7 @@
1182
1187
  --success-text: var(--palette-success);
1183
1188
  --warning-text: var(--palette-warning);
1184
1189
  --link: var(--palette-indigo-cyan-accent-light);
1190
+ --primary-text: var(--palette-indigo-cyan-accent-light);
1185
1191
  --heading-bar: var(--palette-indigo-cyan-accent-light);
1186
1192
  --rule: var(--palette-indigo-cyan-strong-border);
1187
1193
  --table-highlight-muted-foreground: var(--palette-indigo-cyan-dim);
@@ -1223,6 +1229,7 @@
1223
1229
  --success-text: var(--palette-success);
1224
1230
  --warning-text: var(--palette-warning);
1225
1231
  --link: var(--palette-indigo-rose-accent-light);
1232
+ --primary-text: var(--palette-indigo-rose-accent-light);
1226
1233
  --heading-bar: var(--palette-indigo-rose-accent-light);
1227
1234
  --rule: var(--palette-indigo-rose-strong-border);
1228
1235
  --table-highlight-muted-foreground: var(--palette-indigo-rose-dim);
@@ -1264,6 +1271,7 @@
1264
1271
  --success-text: var(--palette-success);
1265
1272
  --warning-text: var(--palette-warning);
1266
1273
  --link: var(--palette-graphite-periwinkle-accent-light);
1274
+ --primary-text: var(--palette-graphite-periwinkle-accent-light);
1267
1275
  --heading-bar: var(--palette-graphite-periwinkle-accent-light);
1268
1276
  --rule: var(--palette-graphite-periwinkle-strong-border);
1269
1277
  --table-highlight-muted-foreground: var(--palette-graphite-periwinkle-dim);
@@ -1305,6 +1313,7 @@
1305
1313
  --success-text: var(--palette-success);
1306
1314
  --warning-text: var(--palette-warning);
1307
1315
  --link: var(--palette-violet-accent-light);
1316
+ --primary-text: var(--palette-violet-accent-light);
1308
1317
  --heading-bar: var(--palette-violet-accent-light);
1309
1318
  --rule: var(--palette-violet-strong-border);
1310
1319
  --table-highlight-muted-foreground: var(--palette-violet-dim);
@@ -1359,6 +1368,7 @@
1359
1368
  --warning-text: var(--palette-palm-lcd-warning);
1360
1369
  --info-text: var(--palette-palm-lcd-info);
1361
1370
  --link: var(--palette-palm-lcd-link);
1371
+ --primary-text: var(--palette-palm-lcd-accent);
1362
1372
  --heading-bar: var(--palette-palm-lcd-link);
1363
1373
  --rule: var(--palette-palm-lcd-border);
1364
1374
  --heading-band: var(--palette-palm-lcd-band);
package/vite/push-sw.js CHANGED
@@ -4,11 +4,46 @@
4
4
  // usePushPermission's enable(), not on load. ICON is set by pwa().
5
5
  /* global self, clients */
6
6
  const ICON = '__ICON__'
7
+ const ACTION = 'action'
7
8
 
8
9
  self.addEventListener('install', () => self.skipWaiting())
9
10
  self.addEventListener('activate', (event) => event.waitUntil(self.clients.claim()))
10
11
 
11
- // app/push.py sends {title, body, url, tag}. Anything else still shows.
12
+ // The app's own address for `path`, or null: a path with one leading /,
13
+ // no backslash or control character, that resolves to this origin. A
14
+ // payload naming anywhere else (https://..., //host, /\host) gets null, so
15
+ // the worker never opens or posts to another site.
16
+ function appUrl(path) {
17
+ if (typeof path !== 'string' || !path.startsWith('/') || path.startsWith('//')) return null
18
+ if (/[\\\u0000-\u001f]/.test(path)) return null
19
+ let url
20
+ try {
21
+ url = new URL(path, self.location.origin)
22
+ } catch {
23
+ return null
24
+ }
25
+ return url.origin === self.location.origin ? url : null
26
+ }
27
+
28
+ // The payload's button (PushAction in foundation_backend.push), checked:
29
+ // a title, an app path and a JSON object body. Anything else is no button.
30
+ function readAction(action) {
31
+ if (!action || typeof action !== 'object') return null
32
+ const title = typeof action.title === 'string' ? action.title.trim().slice(0, 40) : ''
33
+ const url = appUrl(action.path)
34
+ if (!title || !url) return null
35
+ const body = action.body && typeof action.body === 'object' && !Array.isArray(action.body) ? action.body : {}
36
+ return { title, path: url.pathname + url.search, body }
37
+ }
38
+
39
+ // Whether this browser shows notification buttons. iOS Safari doesn't
40
+ // (no Notification.maxActions): it gets the notification without one.
41
+ function showsActions() {
42
+ return typeof Notification !== 'undefined' && Number(Notification.maxActions) > 0
43
+ }
44
+
45
+ // foundation_backend.push sends {title, body, url, tag, renotify, action}.
46
+ // Anything else still shows.
12
47
  self.addEventListener('push', (event) => {
13
48
  let data = {}
14
49
  try {
@@ -16,31 +51,69 @@ self.addEventListener('push', (event) => {
16
51
  } catch {
17
52
  data = { body: event.data ? event.data.text() : '' }
18
53
  }
19
- const options = { body: data.body || '', icon: ICON, data: { url: data.url || '/' } }
20
- if (data.tag) options.tag = data.tag
54
+ if (!data || typeof data !== 'object') data = {}
55
+ const action = readAction(data.action)
56
+ const options = { body: data.body || '', icon: ICON, data: { url: data.url || '/', action } }
57
+ if (data.tag) {
58
+ options.tag = data.tag
59
+ // A nag re-sent under the same tag sounds again instead of replacing quietly.
60
+ if (data.renotify === true) options.renotify = true
61
+ }
62
+ if (action && showsActions()) options.actions = [{ action: ACTION, title: action.title }]
21
63
  event.waitUntil(self.registration.showNotification(data.title || 'Reminder', options))
22
64
  })
23
65
 
24
- // Opens the message's path in the app: in a window already open on the
25
- // app if there is one, else a new one. Never another site.
66
+ // Opens `target` in the app: in a window already open on the app if there
67
+ // is one, else a new one.
68
+ async function openApp(target) {
69
+ const windows = await clients.matchAll({ type: 'window', includeUncontrolled: true })
70
+ const open = windows.find((client) => new URL(client.url).origin === target.origin)
71
+ if (open) {
72
+ await open.focus()
73
+ try {
74
+ await open.navigate(target.href)
75
+ return
76
+ } catch {
77
+ // An uncontrolled window can't be navigated from here.
78
+ }
79
+ }
80
+ await clients.openWindow(target.href)
81
+ }
82
+
83
+ // The button: POSTs its body to the app's path with the session cookie,
84
+ // opening nothing. Done, the notification goes; refused or offline, it
85
+ // opens the message's path so the person can do it in the app.
86
+ async function runAction(notification, action, target) {
87
+ const url = appUrl(action.path)
88
+ let ok = false
89
+ if (url) {
90
+ try {
91
+ const response = await fetch(url.href, {
92
+ method: 'POST',
93
+ credentials: 'same-origin',
94
+ headers: { 'Content-Type': 'application/json' },
95
+ body: JSON.stringify(action.body || {}),
96
+ })
97
+ ok = response.ok
98
+ } catch {
99
+ ok = false
100
+ }
101
+ }
102
+ notification.close()
103
+ if (!ok && target) await openApp(target)
104
+ }
105
+
106
+ // A tap opens the message's path; the button runs its action. Never
107
+ // another site.
26
108
  self.addEventListener('notificationclick', (event) => {
109
+ const data = event.notification.data || {}
110
+ const target = appUrl(data.url || '/')
111
+ const action = event.action === ACTION ? readAction(data.action) : null
112
+ if (action) {
113
+ event.waitUntil(runAction(event.notification, action, target))
114
+ return
115
+ }
27
116
  event.notification.close()
28
- const target = new URL((event.notification.data && event.notification.data.url) || '/', self.location.origin)
29
- if (target.origin !== self.location.origin) return
30
- event.waitUntil(
31
- (async () => {
32
- const windows = await clients.matchAll({ type: 'window', includeUncontrolled: true })
33
- const open = windows.find((client) => new URL(client.url).origin === target.origin)
34
- if (open) {
35
- await open.focus()
36
- try {
37
- await open.navigate(target.href)
38
- return
39
- } catch {
40
- // An uncontrolled window can't be navigated from here.
41
- }
42
- }
43
- await clients.openWindow(target.href)
44
- })(),
45
- )
117
+ if (!target) return
118
+ event.waitUntil(openApp(target))
46
119
  })
package/vite/pwa.js CHANGED
@@ -12,7 +12,8 @@
12
12
  // plain PNGs in the theme colour (iOS's Home Screen icon must be a PNG,
13
13
  // and drawing a letter into one needs a font rasteriser the package
14
14
  // doesn't carry). `icon` replaces them all with the app's own PNG.
15
- // - /push-sw.js: ./push-sw.js, showing pushes and opening their path.
15
+ // - /push-sw.js: ./push-sw.js, showing pushes, opening their path, and
16
+ // posting a message's action (a Done button) to the app's own path.
16
17
  // And adds the manifest, theme-color and apple-touch-icon tags to
17
18
  // index.html. Registering the worker is usePushPermission's, on a click.
18
19
  //