@tristan2828/ui-foundation 4.104.0 → 4.106.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–1246
19
+ - [The record view](#the-record-view) · lines 1002–1096
20
+ - [Forms](#forms) · lines 1098–1163
21
+ - [Dialogs](#dialogs) · lines 1165–1196
22
+ - [Toasts and feedback](#toasts-and-feedback) · lines 1198–1246
23
+ - [What not to copy](#what-not-to-copy) · lines 1248–1280
24
+ - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 1282–1299
25
+ - [Deleting](#deleting) · lines 1301–1332
26
+ - [Fields only a script writes](#fields-only-a-script-writes) · lines 1334–1355
27
+ - [Searching one part of the app](#searching-one-part-of-the-app) · lines 1357–1366
28
+ - [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1369–1411
29
29
 
30
30
  <!-- /index -->
31
31
 
@@ -1042,11 +1042,42 @@ A record uses the parts it has, in this order:
1042
1042
  - **Facts beside their labels** (`railFields`, `beside` by default since
1043
1043
  4.81), so the short facts read as a list of pairs rather than a column
1044
1044
  of labels; keep labels to a word or two.
1045
+ - **The facts rail** (4.106, record standard A1): `factsRail` on the
1046
+ view puts the record's short facts in a 300px column beside the strip
1047
+ and the tabs where the view has room (60rem: a laptop's page, a record
1048
+ dialog), so the page doesn't end 900px in. Only short values go in it,
1049
+ and the API holds to that: a rail section is `facts`, not `fields`,
1050
+ each fact one of a few kinds, never free markup:
1051
+
1052
+ ```tsx
1053
+ { title: 'Facts', placement: 'rail', facts: [
1054
+ { label: 'Status', kind: 'status', status: STATUS_KINDS[record.status], word: STATUS_LABELS[record.status] },
1055
+ { label: 'By', kind: 'text', text: formatDay(record.due) },
1056
+ { label: 'Areas', kind: 'badges', items: record.areas.map(areaLabel) },
1057
+ { label: 'From', kind: 'record', name: provider.name, to: `/providers/${provider.id}`, short: true },
1058
+ { label: 'Open Tasks', kind: 'count', count: record.openTasks, to: `/tasks?project=${record.id}` },
1059
+ { label: 'Task', kind: 'link', href: task.url, name: task.name },
1060
+ ] }
1061
+ ```
1062
+
1063
+ - `text` is a date, a number or a person's name: one line, cut with
1064
+ its whole text on hover. `badges` are a few short labels.
1065
+ - A link to another record is `record`, and must say `short: true`:
1066
+ the app vouches its names are short (a person, a place). Records
1067
+ with long titles (a list of discussions, a log's entries) never go in
1068
+ the rail: they're a tab of their own, with its count.
1069
+ - Anything else (a sentence, a closing condition, notes) is a
1070
+ `fields` or `content` section: in Details, never the rail.
1071
+ - What's in the rail isn't repeated in Details. A Details tab left with
1072
+ nothing isn't drawn. On a phone (or a view under 60rem) the rail's
1073
+ sections are back in Details, as rows.
1074
+ - `edit` works on a fact as on a field; at rest it's drawn by its kind.
1045
1075
  - **A tiny record** (4.98: a few fields and no notes, like a lookup's
1046
1076
  row) opens as a small card: `RecordDialogRoute look="card"`, usually
1047
1077
  with `fullPage={false}`. A 420px dialog (a sheet on a phone), its
1048
1078
  title, Delete, Open full page and Close on one line, its facts as
1049
- plain rows.
1079
+ plain rows. The view's `strip` (KeyStats) is left out in the card
1080
+ (4.105); `cardStrip` keeps it, and the record's own page still shows it.
1050
1081
  - **Empty fields folded** (`emptyFields="fold"`, 4.81): each card shows
1051
1082
  what's known, then "N empty" opens the rest, still edited in place.
1052
1083
  - **A few equal things** (a plan's phases, a price at each store, a
@@ -1083,7 +1114,9 @@ shape (4.85):
1083
1114
  (`ChoiceButtons`, found by itself, 4.98) shares a row only with another
1084
1115
  choice, two to a row; on a phone two stay side by side while both
1085
1116
  groups fit, and go one per row when they don't. Never a hand-made
1086
- `sm:grid-cols-2` row.
1117
+ `sm:grid-cols-2` row. The picked option is in the theme colour (4.105);
1118
+ a status choice gives each option its `kind`, so its icons are
1119
+ `StatusMark`'s in their colours (below).
1087
1120
  - **Order:** required first, the status next, long text last.
1088
1121
  - **Required:** `<FieldLabel required>` (an asterisk, and `aria-required`
1089
1122
  on the control it names). Nothing on an optional field: never
@@ -1098,7 +1131,12 @@ shape (4.85):
1098
1131
  "Enter a full address, starting https://", never "Title is required".
1099
1132
  - **A status** is an `OptionSelect` with the same `render` (its
1100
1133
  `StatusMark`, 4.98) as its cell and the record: `inPlace.select`'s
1101
- `{ value, label }` options.
1134
+ `{ value, label }` options. A status of two to four is `ChoiceButtons`
1135
+ (4.105) with each option's `kind`, its status kind:
1136
+ `{ value: 'done', label: 'Done', kind: 'done' }` draws the kind's icon
1137
+ in its colour before the word, the same as the record's `StatusMark`
1138
+ (`icon` overrides the kind's icon; an `icon` with no `kind` stays
1139
+ uncoloured). Map the enum to kinds once and use that map for both.
1102
1140
  - **The controls** (4.88): a choice of two to four short options is
1103
1141
  `ChoiceButtons` (`inPlace.choice` in place), five or more an
1104
1142
  `OptionSelect`. A date is `DateField`, typed ("3/14", "Mar 14",
@@ -1226,6 +1264,12 @@ sight.** What happened where the person is looking says so there.
1226
1264
  takes the views, `activeView` says which one the filters are, and that
1227
1265
  view's `columns` go to `DataTable`'s `visibleColumns` (the table's own
1228
1266
  default list when no view is active, or `undefined` for every column).
1267
+ Views fill the filters (4.105): write each view's whole meaning in its
1268
+ `filters` and `multiFilters` (a "Current" view names its statuses, never
1269
+ `{}` with the server's default doing the rest), name the one the list
1270
+ opens on with `defaultView`, and put what no control can show (a
1271
+ computed "overdue") in the view's `rule` (cell-patterns.md "Saved views
1272
+ are pills").
1229
1273
  - `src/api/gateway/widgets.ts`, `src/mocks/data.ts`, `src/mocks/handlers.ts`
1230
1274
  are demo-domain content — write the entity's own versions rather than
1231
1275
  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–2129
44
+ - [The framed look, and sibling lists beside the title](#the-framed-look-and-sibling-lists-beside-the-title) · lines 2074–2129
45
+ - [26. A record's related list, capped](#26-a-records-related-list-capped) · lines 2131–2167
46
+ - [27. A repeat and its next time](#27-a-repeat-and-its-next-time) · lines 2169–2214
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:
@@ -2058,6 +2090,13 @@ The toolbar a list-page review picked (4.100): `look="framed"` on
2058
2090
  <DataTable look="framed" views={VIEWS} columnsMenu={…} groupings={…} toolbar={<FilterBar … />} … />
2059
2091
  ```
2060
2092
 
2093
+ Since 4.106 (C3) the header goes in the table, as `pageHeader`, so the
2094
+ header row ends where the card does:
2095
+
2096
+ ```tsx
2097
+ <DataTable look="framed" pageHeader={<ListHeader title="Exercises" … />} views={VIEWS} toolbar={…} … />
2098
+ ```
2099
+
2061
2100
  - **The card**: the toolbar in its top bar (search and Filters keep their
2062
2101
  words), the rows, then the count and pager in its bottom bar. Saved
2063
2102
  views sit above it, outside the bar. Loading, empty and error show
@@ -2065,6 +2104,14 @@ The toolbar a list-page review picked (4.100): `look="framed"` on
2065
2104
  - **The tools end at the table's edge**: the card is as wide as `width`
2066
2105
  makes the table, tools and pager with it, so nothing sits off at the
2067
2106
  far right of a wide page. `width="full"` fills the area as before.
2107
+ - **So does the header** (4.106, C3), passed as `pageHeader`: the
2108
+ header (title, siblings, ⋯ and New), the views and the card are one
2109
+ box as wide as the table (CSS `fit-content` with the table's minimum
2110
+ and the page as its maximum; nothing is measured), so above a short
2111
+ table ⋯ and New sit over the card's right edge, and above a wide one
2112
+ where the page ends. A header wider than the table widens the card to
2113
+ match. `width="full"` and the phone's row list span the page as before.
2114
+ A ListHeader left outside the table spans the page, as before 4.106.
2068
2115
  - **One settings button** in place of Columns and Group: the Columns
2069
2116
  ticks, then Group By, in one menu. Its name says the grouping that's on
2070
2117
  ("Table Settings, Grouped by Status") and a dot marks it. Fold All
@@ -2077,7 +2124,9 @@ The toolbar a list-page review picked (4.100): `look="framed"` on
2077
2124
  - The fixtures' `app/DataTable tools` Framed and `app/ListHeader`
2078
2125
  Siblings stories hold it, under axe and the token check in both
2079
2126
  themes; `e2e/data-table-framed.spec.ts` checks the edges, the menu
2080
- from the mouse and the keyboard, the switch and the phone.
2127
+ from the mouse and the keyboard, the switch and the phone, and
2128
+ `e2e/list-header-width.spec.ts` the header's edge at 1440 and 1920
2129
+ (`Header at the table edge` stories).
2081
2130
 
2082
2131
  ## 26. A record's related list, capped
2083
2132
 
@@ -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–1415
33
+ - [A few equal things](#a-few-equal-things) · lines 1417–1501
34
+ - [An overview page](#an-overview-page) · lines 1503–1566
35
+ - [A record's header and empty values](#a-records-header-and-empty-values) · lines 1567–1618
36
+ - [A record's tabs, mark and facts](#a-records-tabs-mark-and-facts) · lines 1620–1688
37
+ - [Picking at random](#picking-at-random) · lines 1690–1721
38
+ - [Filling in what's missing](#filling-in-whats-missing) · lines 1723–1790
39
+ - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1792–1817
40
+ - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 1819–1908
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,11 @@ 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`. Passed as a
1387
+ framed DataTable's `pageHeader` (4.106, C3) it's as wide as the
1388
+ table, so ⋯ and New end on the card's right edge. The menu is as
1389
+ wide as its longest item and never wraps one (4.105), as is a row's ⋯
1390
+ menu.
1375
1391
  - **`Timeline`: a record's dated history.** `items` newest first
1376
1392
  (`{ id, date, dateTime?, kind?, body, edit? }`): dates in a tabular
1377
1393
  column on the left, a dot and a thin line, the entry on the right with
@@ -1623,8 +1639,9 @@ its short facts the last tab, Details. A mark goes left of the title.
1623
1639
  - **Tabs** (`tab` on a section): a line tab list under the strip and any
1624
1640
  sections with no tab, one tab per name in the order the sections first
1625
1641
  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
1642
+ 16px semibold (14px under 48rem), the selected one's name in the theme
1643
+ colour (`--primary-text`, 4.105) with a 3px primary line under it, the
1644
+ others muted; the list's own
1628
1645
  bottom border runs the column's width. A tab's count (`tabCounts`, by
1629
1646
  name: the records it holds) sits beside its name in a small muted
1630
1647
  pill; a tab with none shows no count. A list wider than the column
@@ -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
  }) })] }));
@@ -278,6 +278,16 @@ export type DataTableProps<TData extends Record<string, unknown>, TView extends
278
278
  onViewChange?: (view: TView, id: string) => void;
279
279
  /** The pills' group name: "Views" unless set. */
280
280
  viewsLabel?: string;
281
+ /**
282
+ * The list page's header (4.106, the list standard's C3): its
283
+ * `<ListHeader>`, drawn above the views. In the framed look with
284
+ * `width="content"` the header, the views and the card share one width,
285
+ * the table's, so the header's ⋯ and New end on the card's right edge
286
+ * above a short table instead of at the page's far edge. With
287
+ * `width="full"`, a table wider than the page, or the row list on a
288
+ * phone, it spans the page as before.
289
+ */
290
+ pageHeader?: ReactNode;
281
291
  /**
282
292
  * A Columns menu at the end of the toolbar (L5): a tick for every column
283
293
  * but the first (the name) and the row actions, remembered on this device
@@ -405,4 +415,4 @@ export type DataTableTotals = {
405
415
  */
406
416
  cells?: Partial<Record<string, ReactNode>>;
407
417
  };
408
- export declare function DataTable<TData extends Record<string, unknown>, TView extends DataTableView = DataTableView>({ columns, data, total, page, pageSize, onPageChange, pageSizes, onPageSizeChange, sorting, onSortingChange, isLoading, error, onRetry, emptyTitle, emptyDescription, emptyAction, toolbar, getRowId, pinFirstColumn, pinLastColumn, enableSortingRemoval, visibleColumns, width, striped, groupBy, groupSummary, stickyGroupHeadings, stickyTop, header: showHeader, highlightRow, totals, layouts, layout: layoutProp, onLayoutChange, tableLayout, groupings, grouping: groupingProp, onGroupingChange, opens, detailPanel, onRowClick: onRowClickProp, detailRow, onDetailRowChange, detailLabel, views, activeView, onViewChange, viewsLabel, columnsMenu, rowActions, phoneRow, limit, viewAll, look, }: DataTableProps<TData, TView>): import("react").JSX.Element;
418
+ export declare function DataTable<TData extends Record<string, unknown>, TView extends DataTableView = DataTableView>({ columns, data, total, page, pageSize, onPageChange, pageSizes, onPageSizeChange, sorting, onSortingChange, isLoading, error, onRetry, emptyTitle, emptyDescription, emptyAction, toolbar, getRowId, pinFirstColumn, pinLastColumn, enableSortingRemoval, visibleColumns, width, striped, groupBy, groupSummary, stickyGroupHeadings, stickyTop, header: showHeader, highlightRow, totals, layouts, layout: layoutProp, onLayoutChange, tableLayout, groupings, grouping: groupingProp, onGroupingChange, opens, detailPanel, onRowClick: onRowClickProp, detailRow, onDetailRowChange, detailLabel, views, activeView, onViewChange, viewsLabel, pageHeader, columnsMenu, rowActions, phoneRow, limit, viewAll, look, }: DataTableProps<TData, TView>): import("react").JSX.Element;
@@ -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.
@@ -421,7 +428,7 @@ const ROW_ACTIONS_COLUMN = {
421
428
  };
422
429
  // The cell under the actions' column: as narrow as its button.
423
430
  const ROW_ACTIONS_CELL_CLASS = 'w-px py-0';
424
- export function DataTable({ columns, data, total, page, pageSize, onPageChange, pageSizes, onPageSizeChange, sorting, onSortingChange, isLoading, error, onRetry, emptyTitle, emptyDescription, emptyAction, toolbar, getRowId, pinFirstColumn, pinLastColumn, enableSortingRemoval, visibleColumns, width = 'content', striped = false, groupBy, groupSummary, stickyGroupHeadings = false, stickyTop = '0px', header: showHeader = true, highlightRow, totals, layouts, layout: layoutProp, onLayoutChange, tableLayout, groupings, grouping: groupingProp, onGroupingChange, opens, detailPanel, onRowClick: onRowClickProp, detailRow, onDetailRowChange, detailLabel = 'Details', views, activeView = null, onViewChange, viewsLabel = 'Views', columnsMenu, rowActions, phoneRow, limit, viewAll, look = 'plain', }) {
431
+ export function DataTable({ columns, data, total, page, pageSize, onPageChange, pageSizes, onPageSizeChange, sorting, onSortingChange, isLoading, error, onRetry, emptyTitle, emptyDescription, emptyAction, toolbar, getRowId, pinFirstColumn, pinLastColumn, enableSortingRemoval, visibleColumns, width = 'content', striped = false, groupBy, groupSummary, stickyGroupHeadings = false, stickyTop = '0px', header: showHeader = true, highlightRow, totals, layouts, layout: layoutProp, onLayoutChange, tableLayout, groupings, grouping: groupingProp, onGroupingChange, opens, detailPanel, onRowClick: onRowClickProp, detailRow, onDetailRowChange, detailLabel = 'Details', views, activeView = null, onViewChange, viewsLabel = 'Views', pageHeader, columnsMenu, rowActions, phoneRow, limit, viewAll, look = 'plain', }) {
425
432
  // The switch's own state, for a table that doesn't pass `layout`.
426
433
  const [ownLayout, setOwnLayout] = useState('table');
427
434
  const requestedLayout = layoutProp ?? ownLayout;
@@ -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'
@@ -844,7 +851,11 @@ export function DataTable({ columns, data, total, page, pageSize, onPageChange,
844
851
  const lastWidthStyle = fitsColumns && !isSuccessView && lastWidth !== null
845
852
  ? { '--data-table-last-width': `${lastWidth}px` }
846
853
  : undefined;
847
- const content = framed ? (_jsxs("div", { ref: root, className: "flex flex-col gap-4", "data-width": width, "data-look": "framed", "data-layout": layouts?.length ? currentLayout : undefined, children: [viewPills, _jsx(DetailFrame, { enabled: Boolean(detailPanel) && !cardLayout, aside: detailAside, children: _jsxs("div", { ref: body, "data-slot": "data-table-frame", className: cn(FRAME_CLASS, fitsColumns && CONTENT_WIDTH_CLASS), style: lastWidthStyle, children: [framedToolbar, _jsx("div", { "data-slot": "data-table-body", className: cn('flex flex-col gap-4', (stateView || cardLayout) && 'p-3', showPhoneRows && !stateView && FRAMED_PHONE_ROWS_CLASS), children: stateView ?? rowsView }), stateView ? null : pagination] }) })] })) : (_jsxs("div", { ref: root, className: "flex flex-col gap-4", "data-width": width, "data-layout": layouts?.length ? currentLayout : undefined, children: [viewPills, plainToolbar, _jsx("div", { ref: body, "data-slot": "data-table-body", className: cn('flex flex-col gap-4', fitsColumns && CONTENT_WIDTH_CLASS), style: lastWidthStyle, children: stateView ?? (_jsxs(DetailFrame, { enabled: Boolean(detailPanel) && !cardLayout, aside: detailAside, children: [rowsView, pagination] })) })] }));
854
+ // C3: with a header, the header, views and card are one box as wide as
855
+ // the table (the box fits its content, the card fills the box), so the
856
+ // header ends where the card does. CSS only: nothing is measured.
857
+ const sharedWidth = Boolean(pageHeader) && fitsColumns;
858
+ const content = framed ? (_jsxs("div", { ref: root, className: cn('flex flex-col gap-4', sharedWidth && CONTENT_WIDTH_CLASS), "data-width": width, "data-look": "framed", "data-shared-width": sharedWidth ? '' : undefined, "data-layout": layouts?.length ? currentLayout : undefined, children: [pageHeader, viewPills, _jsx(DetailFrame, { enabled: Boolean(detailPanel) && !cardLayout, aside: detailAside, children: _jsxs("div", { ref: body, "data-slot": "data-table-frame", className: cn(FRAME_CLASS, fitsColumns && !sharedWidth && CONTENT_WIDTH_CLASS), style: lastWidthStyle, children: [framedToolbar, _jsx("div", { "data-slot": "data-table-body", className: cn('flex flex-col gap-4', (stateView || cardLayout) && 'p-3', showPhoneRows && !stateView && FRAMED_PHONE_ROWS_CLASS), children: stateView ?? rowsView }), stateView ? null : pagination] }) })] })) : (_jsxs("div", { ref: root, className: "flex flex-col gap-4", "data-width": width, "data-layout": layouts?.length ? currentLayout : undefined, children: [pageHeader, viewPills, plainToolbar, _jsx("div", { ref: body, "data-slot": "data-table-body", className: cn('flex flex-col gap-4', fitsColumns && CONTENT_WIDTH_CLASS), style: lastWidthStyle, children: stateView ?? (_jsxs(DetailFrame, { enabled: Boolean(detailPanel) && !cardLayout, aside: detailAside, children: [rowsView, pagination] })) })] }));
848
859
  return (_jsx(EditInPlaceContext.Provider, { value: store, children: _jsxs(RowActionsContext.Provider, { value: rowActions, children: [editing && _jsx(LeaveGuard, { store: store }), width === 'content' ? _jsx("div", { className: "@container/data-table", children: content }) : content, detailPanel && (_jsx(Sheet, { open: Boolean(selectedRow) && !isWide && isSuccessView && !cardLayout, onOpenChange: (open) => {
849
860
  if (!open)
850
861
  setSelection(null);
@@ -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).
@@ -0,0 +1,69 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { StatusKind } from '../../lib/status-kinds.js';
3
+ import type { EditInPlace } from './edit-in-place.js';
4
+ /** What a fact holds: one of the short kinds a rail can draw. */
5
+ export type EntityViewFactValue =
6
+ /** A status, drawn as its StatusMark; `word` is the status's own ("As needed"). */
7
+ {
8
+ kind: 'status';
9
+ status: StatusKind;
10
+ word?: string;
11
+ }
12
+ /** Short text: a date, a number, a person's name. One line, cut with its whole text on hover. `null` is empty. */
13
+ | {
14
+ kind: 'text';
15
+ text: string | number | null | undefined;
16
+ }
17
+ /** A few short labels (areas, tags) as badges. None is empty. */
18
+ | {
19
+ kind: 'badges';
20
+ items: readonly string[];
21
+ }
22
+ /** A count, and where it links to, if anywhere (`/discussions?provider=3`). */
23
+ | {
24
+ kind: 'count';
25
+ count: number;
26
+ to?: string;
27
+ }
28
+ /** A link out of the app, its words `name`, opening in a new tab. */
29
+ | {
30
+ kind: 'link';
31
+ href: string;
32
+ name: string;
33
+ }
34
+ /**
35
+ * Another record, by a short `name` (a person's, a place's). `short: true`
36
+ * says the app knows its titles are short: a record whose titles run
37
+ * long (a discussion, a log entry) is a section in a tab instead.
38
+ */
39
+ | {
40
+ kind: 'record';
41
+ name: string;
42
+ to: string;
43
+ short: true;
44
+ };
45
+ export type EntityViewFact = EntityViewFactValue & {
46
+ label: string;
47
+ /** What an empty value reads as, for this fact. Defaults to the view's `emptyText`. */
48
+ emptyLabel?: string;
49
+ /** Editable in place, as a field is (`inPlace.select`, `inPlace.date`); it's drawn by its kind at rest. */
50
+ edit?: EditInPlace;
51
+ };
52
+ /** A fact as the view draws it: `null` when empty. */
53
+ export declare function factValue(fact: EntityViewFactValue): ReactNode;
54
+ /** A facts section's facts as fields rows, for Details, the column and printing. */
55
+ export declare function factsAsFields(facts: readonly EntityViewFact[]): {
56
+ label: string;
57
+ value: ReactNode;
58
+ emptyLabel: string | undefined;
59
+ edit: EditInPlace | undefined;
60
+ }[];
61
+ /** The width the view needs for the facts rail beside its column: 60rem (the column ~40rem, a 300px rail, the gap). */
62
+ export declare const FACTS_RAIL_MIN_WIDTH = 960;
63
+ /**
64
+ * Whether the element's parent (the room the view has: the page's content
65
+ * area, or a dialog's body) is at least `min` px wide. A ResizeObserver
66
+ * measures it: its first report comes after layout and before paint, and
67
+ * then on every resize, so the rail and the Details tab never flash.
68
+ */
69
+ export declare function useWideParent<T extends HTMLElement>(enabled: boolean, min?: number): readonly [import("react").Dispatch<import("react").SetStateAction<T | null>>, boolean];
@@ -0,0 +1,56 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useLayoutEffect, useState } from 'react';
3
+ import { Link } from 'react-router';
4
+ import { ExternalLinkIcon } from 'lucide-react';
5
+ import { cn } from 'cn';
6
+ import { Badge } from '../ui/badge.js';
7
+ import { StatusMark } from './status-mark.js';
8
+ const LINK_CLASS = 'rounded-sm font-medium text-link underline-offset-4 outline-none hover:underline focus-visible:ring-3 focus-visible:ring-ring/50';
9
+ /** A fact as the view draws it: `null` when empty. */
10
+ export function factValue(fact) {
11
+ switch (fact.kind) {
12
+ case 'status':
13
+ return _jsx(StatusMark, { kind: fact.status, children: fact.word });
14
+ case 'text': {
15
+ if (fact.text === null || fact.text === undefined || fact.text === '')
16
+ return null;
17
+ const text = String(fact.text);
18
+ return (_jsx("span", { "data-slot": "entity-view-fact-text", title: text, className: "inline-block max-w-full truncate align-bottom tabular-nums", children: text }));
19
+ }
20
+ case 'badges':
21
+ if (fact.items.length === 0)
22
+ return null;
23
+ return (_jsx("span", { className: "inline-flex max-w-full flex-wrap gap-1", children: fact.items.map((item) => (_jsx(Badge, { variant: "outline", className: "max-w-full truncate", children: item }, item))) }));
24
+ case 'count':
25
+ return fact.to ? (_jsx(Link, { to: fact.to, className: cn(LINK_CLASS, 'tabular-nums'), children: fact.count })) : (_jsx("span", { className: "tabular-nums", children: fact.count }));
26
+ case 'link':
27
+ return (_jsxs("a", { href: fact.href, target: "_blank", rel: "noreferrer", className: cn(LINK_CLASS, 'inline-flex max-w-full items-center gap-1'), children: [_jsx("span", { className: "truncate", children: fact.name }), _jsx(ExternalLinkIcon, { "aria-hidden": "true", className: "size-3.5 shrink-0" }), _jsx("span", { className: "sr-only", children: "(opens in a new tab)" })] }));
28
+ case 'record':
29
+ return (_jsx(Link, { to: fact.to, title: fact.name, className: cn(LINK_CLASS, 'inline-block max-w-full truncate align-bottom'), children: fact.name }));
30
+ }
31
+ }
32
+ /** A facts section's facts as fields rows, for Details, the column and printing. */
33
+ export function factsAsFields(facts) {
34
+ return facts.map((fact) => ({ label: fact.label, value: factValue(fact), emptyLabel: fact.emptyLabel, edit: fact.edit }));
35
+ }
36
+ /** The width the view needs for the facts rail beside its column: 60rem (the column ~40rem, a 300px rail, the gap). */
37
+ export const FACTS_RAIL_MIN_WIDTH = 960;
38
+ /**
39
+ * Whether the element's parent (the room the view has: the page's content
40
+ * area, or a dialog's body) is at least `min` px wide. A ResizeObserver
41
+ * measures it: its first report comes after layout and before paint, and
42
+ * then on every resize, so the rail and the Details tab never flash.
43
+ */
44
+ export function useWideParent(enabled, min = FACTS_RAIL_MIN_WIDTH) {
45
+ const [node, setNode] = useState(null);
46
+ const [wide, setWide] = useState(false);
47
+ useLayoutEffect(() => {
48
+ const parent = node?.parentElement;
49
+ if (!enabled || !parent || typeof ResizeObserver === 'undefined')
50
+ return;
51
+ const observer = new ResizeObserver(() => setWide(parent.getBoundingClientRect().width >= min));
52
+ observer.observe(parent);
53
+ return () => observer.disconnect();
54
+ }, [node, enabled, min]);
55
+ return [setNode, enabled && wide];
56
+ }