@terpjs/react-core 0.30.0 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/README.md +35 -14
  2. package/package.json +5 -5
  3. package/src/DashboardPage.tsx +34 -0
  4. package/src/Field.test.tsx +26 -1
  5. package/src/Field.tsx +15 -5
  6. package/src/HubPage.tsx +7 -2
  7. package/src/Page.test.tsx +192 -0
  8. package/src/Page.tsx +141 -55
  9. package/src/PageActions.test.tsx +64 -3
  10. package/src/PageActions.tsx +40 -15
  11. package/src/PageSequence.tsx +114 -0
  12. package/src/Stat.test.tsx +341 -0
  13. package/src/Stat.tsx +314 -0
  14. package/src/Timeline.test.tsx +74 -0
  15. package/src/Timeline.tsx +71 -0
  16. package/src/admin/AdminHub.tsx +11 -3
  17. package/src/admin/AuditLogAdmin.tsx +3 -1
  18. package/src/admin/GroupCreate.tsx +3 -1
  19. package/src/admin/GroupDetail.tsx +72 -67
  20. package/src/admin/GroupsAdmin.tsx +3 -1
  21. package/src/admin/ModuleAccessPanel.tsx +13 -12
  22. package/src/admin/RecordHistory.tsx +83 -0
  23. package/src/admin/UserCreate.tsx +3 -1
  24. package/src/admin/UserDetail.tsx +8 -1
  25. package/src/admin/UsersAdmin.tsx +3 -0
  26. package/src/admin/admin.test.tsx +208 -5
  27. package/src/bootstrap.test.tsx +31 -7
  28. package/src/bootstrap.tsx +30 -4
  29. package/src/charts/BarChart.tsx +74 -0
  30. package/src/charts/ProportionBar.tsx +118 -0
  31. package/src/charts/StatusHistory.tsx +75 -0
  32. package/src/charts/TrendChart.tsx +232 -0
  33. package/src/charts/charts.test.tsx +409 -0
  34. package/src/charts/scale.ts +103 -0
  35. package/src/dataview/DataView.test.tsx +255 -0
  36. package/src/dataview/DataView.tsx +35 -0
  37. package/src/dataview/DataViewCardList.tsx +21 -13
  38. package/src/dataview/DataViewTable.tsx +5 -6
  39. package/src/dataview/README.md +18 -0
  40. package/src/dataview/index.ts +1 -0
  41. package/src/dataview/internal.tsx +112 -5
  42. package/src/dataview/types.ts +39 -10
  43. package/src/errorMessages.test.tsx +17 -0
  44. package/src/errorMessages.tsx +18 -0
  45. package/src/format.ts +15 -0
  46. package/src/index.ts +24 -1
  47. package/src/layout.manifest.json +2 -9
  48. package/src/layout.manifest.test.ts +4 -2
  49. package/src/layout.test.tsx +74 -6
  50. package/src/layout.tsx +85 -25
  51. package/src/layoutContract.test.tsx +239 -1
  52. package/src/layoutContract.ts +131 -5
  53. package/src/layoutDeclaration.test.ts +31 -10
  54. package/src/layoutDeclaration.ts +9 -4
  55. package/src/locale.tsx +20 -3
  56. package/src/markers.test.ts +70 -2
  57. package/src/router.test.tsx +15 -3
  58. package/src/router.tsx +11 -2
  59. package/src/ssr.test.tsx +18 -0
  60. package/src/styles.test.ts +222 -190
  61. package/src/styles.ts +1268 -328
  62. package/src/theme.test.tsx +44 -18
  63. package/src/theme.themes.test.ts +22 -2
  64. package/src/theme.tsx +22 -14
  65. package/src/themes.ts +39 -4
  66. package/src/tokens.guard.test.ts +13 -15
  67. package/src/typography.tsx +5 -1
  68. package/src/ui/Alert.test.tsx +24 -1
  69. package/src/ui/Alert.tsx +10 -1
  70. package/src/ui/Card.tsx +5 -4
  71. package/src/ui/Tooltip.test.tsx +171 -2
  72. package/src/ui/Tooltip.tsx +144 -8
  73. package/src/ui/controlMessages.tsx +20 -7
  74. package/src/uiText.test.tsx +16 -0
  75. package/src/uiText.tsx +76 -7
@@ -371,15 +371,15 @@ describe("cascade structure", () => {
371
371
  }
372
372
  // And the content measure, which no structural check can reach through a marker: it is the
373
373
  // one shell rule keyed on a descendant of an attribute rather than on a marker of its own,
374
- // because the mechanism is deliberately NOT a new element (ADR 0097 §2). The `:not(header)`
375
- // is the whole band: the header keeps the page grid's full track while its siblings take
376
- // the measure.
374
+ // because the mechanism is deliberately NOT a new element (ADR 0097 §2). The `:not()` is the
375
+ // whole band: the frame's two bands -- the title band and the summary band (ADR 0169 §4) --
376
+ // keep the page grid's full track while their siblings take the measure.
377
377
  // Selector AND declaration read out of ONE rule body, not as two independent substrings
378
378
  // of the layer. Asserted separately, an empty measure rule plus the declaration moved onto
379
379
  // some other rule during a consolidation would satisfy both — and the only baseline that
380
380
  // moved would read as an intentional layout change.
381
381
  const measureRule =
382
- /\[data-terp="appshell"\]\[data-content-width="measured"\]\s*\n?\s*\[data-terp="page"\] > \*:not\(\[data-terp="page-header"\]\) \{([^}]*)\}/.exec(
382
+ /\[data-terp="appshell"\]\[data-content-width="measured"\]\s*\n?\s*\[data-terp="page"\] > \*:not\(\[data-terp="page-header"\], \[data-terp="page-summary"\]\) \{([^}]*)\}/.exec(
383
383
  base,
384
384
  );
385
385
  expect(measureRule, "the content measure must be one rule keyed on the shell's attribute").not
@@ -533,30 +533,43 @@ describe("cascade structure", () => {
533
533
  expect(chrome, "the band is what separates chrome from content").toContain(
534
534
  "border-block-end: 1px solid var(--color-neutral-200)",
535
535
  );
536
- // The block padding, and it has to be the same VALUE in both chrome rows rather than the
537
- // same intention. A min-height is only a height while nothing legal can beat it, and
538
- // var(--space-2) did not clear that bar: a 2.25rem control plus 8px of padding plus the
539
- // 1px border is 53px against a floor of 48, so the app header (which always carries its
540
- // toggle) was 53px, a band with an action button was 53px, and a band with only a title
541
- // was 48px — the one row whose whole promise is that it matches the header above it,
542
- // changing height per page.
536
+ // The block padding is ONE INSET, and the row gap is the same inset: every control's line
537
+ // of the band at least a control tall (pinned below), with the inset at the edges and
538
+ // between lines alike. The inset is what the header height leaves around one control, halved, so
539
+ // a one-line band is inset + control + inset + rule = the header's height, which is what
540
+ // the computed lane reads back. Two earlier shapes each got half of it wrong: zero padding
541
+ // with content-sized lines crammed a wrapped band against its border, and full 47px lines
542
+ // doubled the space between them.
543
543
  //
544
- // Zero, not a step: var(--space-1) leaves 39px of content box, which clears the 2.25rem
545
- // control and not the 2.75rem one this package also ships, so a band with a large action
546
- // button measured 53px again. Both rows spend the same value, and the resolved heights are
547
- // pinned in the computed lane against the largest control there is; what belongs here is
548
- // that neither row can move its padding without the other.
549
- expect(chrome, "the band's block padding is the app header's").toContain(
550
- "padding-block: var(--space-0)",
544
+ // On EVERY chrome band, not only the kinds known to wrap: the band is a flex line now, and
545
+ // whether its cluster wraps depends on content no selector can see.
546
+ const inset = "calc((var(--shell-header-height) - 1px - var(--density-control-min-height)) / 2)";
547
+ expect(chrome, "the inset above the first line and below the last").toContain(
548
+ `padding-block: ${inset}`,
551
549
  );
552
- expect(
553
- bodyFor('[data-terp="appshell-header"]'),
554
- "both chrome rows spend the same block padding under the floor they share",
555
- ).toContain("padding: var(--space-0) var(--shell-gutter)");
550
+ expect(chrome, "and once between lines, not twice").toContain(`row-gap: ${inset}`);
556
551
  expect(
557
552
  /padding-inline|padding:/.test(chrome),
558
553
  "an inline pad with no bleed would inset the band from the body beneath it",
559
554
  ).toBe(false);
555
+ const line = "min-height: var(--density-control-min-height)";
556
+ for (const item of [
557
+ '[data-terp="page"]:not([data-measure="narrow"]) > [data-terp="page-header"] [data-terp="breadcrumbs"]',
558
+ '[data-terp="page"]:not([data-measure="narrow"]) > [data-terp="page-header"] > [data-terp="page-actions"]',
559
+ ]) {
560
+ expect(bodyFor(item), `${item}: a control's line at least a control tall`).toContain(line);
561
+ }
562
+ // The meta line is not a control's line (ADR 0135, amended 2026-10-04): it takes its own
563
+ // height, meets the line above it by cancelling the band's gap, and keeps --space-2 under
564
+ // its ink, so a lead sentence reads as the title's subtitle rather than as a line of its own.
565
+ const meta = bodyFor(
566
+ '[data-terp="page"]:not([data-measure="narrow"]) > [data-terp="page-header"] [data-terp="page-meta"]',
567
+ );
568
+ expect(meta, "the meta line takes its own height").not.toContain(line);
569
+ expect(meta, "and meets the line above it").toContain(
570
+ `margin-block-start: calc((var(--shell-header-height) - 1px - var(--density-control-min-height)) / -2)`,
571
+ );
572
+ expect(meta, "with room under its ink").toContain("padding-block-end: var(--space-2)");
560
573
 
561
574
  // THE BLEED is gated, because the negative-margin idiom is only correct against a box
562
575
  // that pads by exactly this token. ADR 0097 section 2 kept "it works with no shell above
@@ -643,6 +656,49 @@ describe("cascade structure", () => {
643
656
  ).toContain("height: 100%");
644
657
  });
645
658
 
659
+ it("places a tooltip against the window and a card list against the view's own edge", () => {
660
+ const base = layerBody("terp.base");
661
+ const bodyFor = (selector: string): string => {
662
+ for (const match of base.matchAll(/([^{}]+)\{([^{}]*)\}/g)) {
663
+ const selectors = match[1].split(",").map((part) => part.trim().replace(/\s+/g, " "));
664
+ if (selectors.includes(selector)) return match[2];
665
+ }
666
+ throw new Error(`the sheet declares no rule for exactly ${selector}`);
667
+ };
668
+ // The bubble is portalled and placed from measured coordinates, so the sheet fixes it to
669
+ // the window and names no offset of its own. As an absolute child of its anchor it was
670
+ // clipped by any scroll container above it -- a DataView cell's tooltip ended at the
671
+ // table's edge -- and its available width was the trigger's, so a message on a button
672
+ // wrapped one button wide and grew off the top of the window.
673
+ const bubble = bodyFor('[data-terp="tooltip"]');
674
+ expect(bubble, "fixed to the window, where no scroll container can clip it").toContain(
675
+ "position: fixed",
676
+ );
677
+ expect(bubble, "the message's width, not the room a containing block leaves").toContain(
678
+ "inline-size: max-content",
679
+ );
680
+ // Portalled, its parent is the body, which no rule gives a typeface: without its own
681
+ // family the bubble rendered in the browser's default serif.
682
+ expect(bubble, "the bubble declares its typeface rather than inheriting the body's").toContain(
683
+ "font-family: var(--font-family-sans)",
684
+ );
685
+ expect(
686
+ /inset-|(^|[^-])(top|left|right|bottom):/.test(bubble),
687
+ "the coordinates are measured by the component; an offset here would fight them",
688
+ ).toBe(false);
689
+ expect(
690
+ bodyFor('[data-terp="tooltip-anchor"]'),
691
+ "the anchor is no longer anything's containing block",
692
+ ).not.toContain("position:");
693
+ // The card list sits beside the toolbar and the pagination, not inside the table's
694
+ // frame, so padding of its own inset every card from the edge they share. Measured at a
695
+ // phone width before: toolbar 16-394px, cards 24-386px.
696
+ expect(
697
+ bodyFor('[data-terp="dataview-card-list"]'),
698
+ "the cards line up with the toolbar and the pagination",
699
+ ).toContain("padding: 0");
700
+ });
701
+
646
702
  it("puts the DataView's surface on the full variant's TABLE, not on the root or the marker", () => {
647
703
  // Both values of data-variant are stamped and only one has a rule, which is what keeps
648
704
  // the embedded variant a bare grid. The alternative — surface on the marker, un-declared
@@ -787,6 +843,20 @@ describe("cascade structure", () => {
787
843
  ).not.toContain("box-shadow");
788
844
  });
789
845
 
846
+ it("draws a control's outline in the boundary token, never in the raw ramp step", () => {
847
+ // ADR 0170 §4. --color-border-strong is the outline of every control, and the contrast
848
+ // gate's control-boundary pairings hold it at 3:1 against the surfaces controls sit on. The
849
+ // gate measures tokens, not rules, so it cannot see a rule that draws an edge in
850
+ // --color-neutral-300 instead — the step every control used before, at 1.4 to 2.4:1, which
851
+ // still paints the scrollbar and disabled ink. Any border drawn in the step is refused here,
852
+ // with one exception: the empty state's dashed outline frames no control, and WCAG sets no
853
+ // ratio for a decorative edge.
854
+ const offenders = [...css.matchAll(/([^{}]+)\{([^{}]*)\}/g)]
855
+ .filter((rule) => /(?:^|;)\s*border[\w-]*\s*:[^;]*var\(--color-neutral-300\)/.test(rule[2]!))
856
+ .map((rule) => rule[1]!.trim().replace(/\s+/g, " "));
857
+ expect(offenders).toEqual(['[data-terp="empty-state"]']);
858
+ });
859
+
790
860
  it("keeps the focus-within tint scoped to rows something will actually open", () => {
791
861
  // The row marker is unconditional, so this selector reaches every row unless it says
792
862
  // otherwise. Unguarded it paints a brand wash on any row holding focus — a selection
@@ -985,6 +1055,9 @@ describe("cascade structure", () => {
985
1055
  // 500, near-black — and a card of five labelled values read as a wall of bold text with
986
1056
  // nothing saying which half of a pair to read first.
987
1057
  //
1058
+ // The ruled grid (ADR 0169 §5) joins the rule rather than taking a treatment of its own: a
1059
+ // grid cell is a stacked pair with rules around it.
1060
+ //
988
1061
  // `inline` is deliberately excluded, and that is the half worth pinning: there the term is
989
1062
  // part of a sentence (the colon comes from a ::after) and muting half a sentence is a
990
1063
  // different defect. So this asserts the selector list exactly, in both directions.
@@ -1006,6 +1079,7 @@ describe("cascade structure", () => {
1006
1079
  expect(muting[0]!.selectors).toEqual([
1007
1080
  '[data-terp="detail-list"][data-layout="aligned"] [data-terp="detail-list-term"]',
1008
1081
  '[data-terp="detail-list"][data-layout="stacked"] [data-terp="detail-list-term"]',
1082
+ '[data-terp="detail-list"][data-layout="grid"] [data-terp="detail-list-term"]',
1009
1083
  ]);
1010
1084
  expect(muting[0]!.body).toContain("var(--font-size-xs)");
1011
1085
  expect(muting[0]!.body).toContain("var(--font-weight-normal)");
@@ -1105,6 +1179,7 @@ describe("cascade structure", () => {
1105
1179
  expect(value[0]!.selectors).toEqual([
1106
1180
  '[data-terp="detail-list"][data-layout="aligned"] [data-terp="detail-list-value"]',
1107
1181
  '[data-terp="detail-list"][data-layout="stacked"] [data-terp="detail-list-value"]',
1182
+ '[data-terp="detail-list"][data-layout="grid"] [data-terp="detail-list-value"]',
1108
1183
  ]);
1109
1184
  expect(value[0]!.body, "the value takes the table body cell's step").toContain(cellStep!);
1110
1185
 
@@ -1113,20 +1188,24 @@ describe("cascade structure", () => {
1113
1188
  expect(term[0]!.selectors).toEqual([
1114
1189
  '[data-terp="detail-list"][data-layout="aligned"] [data-terp="detail-list-term"]',
1115
1190
  '[data-terp="detail-list"][data-layout="stacked"] [data-terp="detail-list-term"]',
1191
+ '[data-terp="detail-list"][data-layout="grid"] [data-terp="detail-list-term"]',
1116
1192
  ]);
1117
1193
  expect(term[0]!.body, "at the table header cell's step").toContain(headerStep!);
1118
1194
  });
1119
1195
 
1120
- it("gives a field row three shared lines, and the narrow shape none of them", () => {
1121
- // The whole of FieldRow is that a field's three parts land on the ROW's tracks rather
1122
- // than on its own, so these four declarations are one mechanism and a missing one
1123
- // breaks it silently -- a field that is not a subgrid simply measures itself again and
1124
- // the row looks like an ordinary Stack.
1196
+ it("gives a field row two shared lines, and the narrow shape none of them", () => {
1197
+ // The whole of FieldRow is that a field's two parts -- its label, and its body (the
1198
+ // control with whatever the field says under it) -- land on the ROW's tracks rather than
1199
+ // on its own, so these declarations are one mechanism and a missing one breaks it
1200
+ // silently: a field that is not a subgrid simply measures itself again and the row looks
1201
+ // like an ordinary Stack.
1202
+ //
1203
+ // Two lines, not the three this used to be (label, control, messages): the messages moved
1204
+ // into the body, so a row where no field has a hint carries no empty line.
1125
1205
  //
1126
- // The pairing that is easiest to get wrong is the last one: display: contents on the
1127
- // label is what lifts the label TEXT and the control out of the <label> box so they can
1128
- // sit on separate lines. Without it a field spans three tracks and puts everything on
1129
- // the first.
1206
+ // The pairing that is easiest to get wrong is display: contents on the label, which is
1207
+ // what lifts the label TEXT and the body out of the <label> box so they can sit on
1208
+ // separate lines. Without it a field spans both tracks and puts everything on the first.
1130
1209
  const wide = mediaBodies(layerBody("terp.base"), WIDE_VIEWPORT_QUERY);
1131
1210
  const subgrid = /\[data-terp="field-row"\] > \[data-terp="field"\] \{([^}]*)\}/.exec(wide);
1132
1211
  expect(subgrid, "each field subgrids the row").not.toBeNull();
@@ -1134,7 +1213,10 @@ describe("cascade structure", () => {
1134
1213
  expect(subgrid![1], "and spans every line, or it subgrids one of them").toContain(
1135
1214
  "grid-row: 1 / -1",
1136
1215
  );
1137
- expect(wide, "the row owns three lines for them to share").toContain(
1216
+ expect(wide, "the row owns two lines for them to share").toContain(
1217
+ "grid-template-rows: auto auto",
1218
+ );
1219
+ expect(wide, "not the three it had before the messages moved into the body").not.toContain(
1138
1220
  "grid-template-rows: auto auto auto",
1139
1221
  );
1140
1222
  expect(
@@ -1212,198 +1294,148 @@ describe("cascade structure", () => {
1212
1294
  expect(base.slice(textAt, base.indexOf("}", textAt))).not.toContain("font-weight");
1213
1295
  });
1214
1296
 
1215
- it("keeps a Card's actions slot on the title's line, description or not", () => {
1216
- // The measured inconsistency: `actions` is documented as a header-row slot and delivered
1217
- // one only while `description` was unset. The heading declared min-width: 0 alone, so it
1218
- // computed flex: 0 1 auto and its hypothetical main size was the max-content width of a
1219
- // block holding a title AND a sentence — and flex breaks lines on hypothetical main sizes
1220
- // BEFORE it shrinks anything, so with the header's flex-wrap the heading took the line and
1221
- // the control wrapped underneath. 103px against 48px for the same component, one prop apart.
1222
- //
1223
- // A base size of 0 is what makes both fit by construction. min-width: 0 stays for the other
1224
- // half: a flex item's automatic minimum is its content's, so a long unbreakable title would
1225
- // otherwise refuse to shrink past it. Both are asserted, because dropping either brings a
1226
- // different half of the bug back.
1227
- const base = layerBody("terp.base");
1228
- const headingAt = base.indexOf('[data-terp="card-heading"] {');
1229
- expect(headingAt, "card-heading should have a base rule").toBeGreaterThan(-1);
1230
- const heading = base.slice(headingAt, base.indexOf("}", headingAt));
1231
- expect(heading, "a content-sized heading wraps the actions slot onto its own line").toContain(
1232
- "flex: 1 1 0",
1233
- );
1234
- expect(heading, "min-width: 0 is what lets an unbreakable title shrink").toContain(
1235
- "min-width: 0",
1297
+ it("gives a Card a header line of title and actions, and its description a line of its own", () => {
1298
+ // The page band's shape at a card's size. The card put its title and description in ONE
1299
+ // column and the actions in a second beside the pair, so the actions took their width out
1300
+ // of the description: a sentence wrapped in a narrow column next to one button, three
1301
+ // lines deep. Now the title and the actions share the header's line (the actions wrapping
1302
+ // under it only when they do not fit), and the description takes the next line, full width.
1303
+ const base = baseOnly(layerBody("terp.base")).replace(/\/\*[\s\S]*?\*\//g, "");
1304
+ const ruleFor = (selector: string) => {
1305
+ for (const match of base.matchAll(/([^{}]+)\{([^{}]*)\}/g)) {
1306
+ if (match[1].trim().replace(/\s+/g, " ") === selector) return match[2];
1307
+ }
1308
+ return null;
1309
+ };
1310
+ const header = ruleFor('[data-terp="card-header"]');
1311
+ expect(header, "a line that wraps on its content").toContain("flex-wrap: wrap");
1312
+ expect(header, "the title in the middle of the line it shares with a control").toContain(
1313
+ "align-items: center",
1236
1314
  );
1237
- // The conditional half. `center` is right for a title alone — the slot is a control, so its
1238
- // box is taller than one line box — and wrong the moment a description makes the heading a
1239
- // block, where it floats the control in the middle instead of beside the title.
1240
- expect(
1241
- declaresRuleFor(base, '[data-terp="card-header"]:has([data-terp="card-description"])'),
1242
- "the header's alignment must depend on whether there is a description",
1243
- ).toBe(true);
1244
- const conditionalAt = base.indexOf(
1245
- '[data-terp="card-header"]:has([data-terp="card-description"])',
1315
+ expect(ruleFor('[data-terp="card-heading"]'), "title and description are items of the header").toContain(
1316
+ "display: contents",
1246
1317
  );
1247
- expect(base.slice(conditionalAt, base.indexOf("}", conditionalAt))).toContain(
1248
- "align-items: start",
1318
+ expect(ruleFor('[data-terp="card-header"] [data-terp="card-title"]'), "the title first").toContain(
1319
+ "order: 1",
1249
1320
  );
1250
- // And the base rule still centres, or the title rides above the control in the common case.
1251
- const headerAt = base.indexOf('[data-terp="card-header"] {');
1252
- expect(base.slice(headerAt, base.indexOf("}", headerAt))).toContain("align-items: center");
1321
+ const actions = ruleFor('[data-terp="card-actions"]');
1322
+ expect(actions, "the actions straight after it, so they can share its line").toContain("order: 2");
1323
+ expect(actions, "pushed to the end as one item").toContain("margin-inline-start: auto");
1324
+ expect(actions, "allowed to shrink to the line they are on").toContain("min-width: 0");
1325
+ expect(actions, "and wrapping their own buttons when they do").toContain("flex-wrap: wrap");
1326
+ const description = ruleFor('[data-terp="card-header"] [data-terp="card-description"]');
1327
+ expect(description, "the description last").toContain("order: 3");
1328
+ expect(description, "on a line of its own, never beside the actions").toContain("flex: 1 1 100%");
1329
+ expect(
1330
+ declaresRuleFor(layerBody("terp.base"), '[data-terp="card-header"]:has([data-terp="card-description"])'),
1331
+ "no alignment that depends on the description: it no longer shares the actions' line",
1332
+ ).toBe(false);
1253
1333
  });
1254
1334
 
1255
- it("lays the page band out in areas, and spends a second row only when one is earned", () => {
1256
- // What this replaced, and why the argument had to change shape. The band was a wrapping
1257
- // flex row, and the bug it kept producing was always the same one: flex collects items
1258
- // into lines using HYPOTHETICAL main sizes and only shrinks what is already on a line, so
1259
- // any item whose max-content was wide -- a deep trail, an unwrapped sentence -- took the
1260
- // line and pushed the action cluster onto the next one. A zero basis bought the single
1261
- // row back, and measured 48px against 76px, which is why it was pinned here.
1335
+ it("lays the page band out as one wrapping line: trail, cluster when it fits, then meta", () => {
1336
+ // The third shape, and why. ADR 0135 made the band a grid of named areas, because a
1337
+ // source-ordered wrapping row could not keep the meta group and the cluster as two groups
1338
+ // and justify-content: space-between spread a wrapped cluster across the width. But areas
1339
+ // answer "where does the cluster go" per VIEWPORT, and the question is about CONTENT: above
1340
+ // the first cutover the cluster stayed beside the trail however wide it was, squeezing the
1341
+ // trail and running past the window with enough actions; below it, it took a row of its own
1342
+ // even when one button fitted beside a short title. Reported on the pages with one action
1343
+ // and one crumb.
1262
1344
  //
1263
- // Two things that basis could never fix, both of which arrive the moment the band DOES
1264
- // wrap. Wrap order follows source order, so the meta group and the cluster cannot share a
1265
- // row while staying two groups. And justify-content: space-between then has free space to
1266
- // distribute, which scatters a page's buttons across the full width -- or left-aligns a
1267
- // single cluster on the row whose whole job was to right-align it.
1268
- //
1269
- // Areas answer both by construction: nothing is placed by flow and no free space is
1270
- // distributed anywhere, so neither failure has a place to happen.
1345
+ // A flex line wraps on what the items need, and the two old objections are answered
1346
+ // without areas: `order` puts the cluster straight after the trail and the meta group last,
1347
+ // and the cluster is one item pushed to the end by margin-inline-start: auto, so no free
1348
+ // space is distributed among buttons.
1271
1349
  const base = layerBody("terp.base");
1272
- const headerAt = base.indexOf('[data-terp="page-header"] {');
1273
- expect(headerAt, "page-header should have a base rule").toBeGreaterThan(-1);
1274
- const header = base.slice(headerAt, base.indexOf("}", headerAt));
1275
- expect(header, "the band places by area, never by flow").toContain("display: grid");
1276
- // minmax(0, 1fr) rather than 1fr: a grid track's automatic minimum is its content's, so a
1277
- // long unbreakable title would refuse to shrink past it and push the cluster out of the
1278
- // band. This is the same job the old zero flex basis did, done by the track instead.
1279
- expect(header, "the trail column must be allowed to shrink below its content").toContain(
1280
- "grid-template-columns: minmax(0, 1fr) auto",
1350
+ const flat = (body: string) => body.replace(/\s+/g, " ");
1351
+ // A rule whose WHOLE selector is this one -- not one that merely ends with it, which is
1352
+ // what a bare indexOf found first for page-actions inside the band's longer selector.
1353
+ const ruleFor = (selector: string) => {
1354
+ const all = flat(baseOnly(base).replace(/\/\*[\s\S]*?\*\//g, ""));
1355
+ for (const match of all.matchAll(/([^{}]+)\{([^{}]*)\}/g)) {
1356
+ if (match[1].trim() === selector) return `${selector} {${match[2]}`;
1357
+ }
1358
+ return null;
1359
+ };
1360
+ const header = ruleFor('[data-terp="page-header"]');
1361
+ expect(header, "page-header should have a base rule").not.toBeNull();
1362
+ expect(header, "a line that wraps on its content").toContain("display: flex");
1363
+ expect(header).toContain("flex-wrap: wrap");
1364
+ expect(header, "no areas left to place by viewport").not.toContain("grid-template-areas");
1365
+
1366
+ const trail = ruleFor('[data-terp="page-header"] [data-terp="breadcrumbs"]');
1367
+ expect(trail, "the trail comes first").toContain("order: 1");
1368
+ // What decides "fits": the trail's basis is its own full width, so the cluster joins its line
1369
+ // only when the whole trail fits beside it, and the trail grows into whatever is left.
1370
+ expect(trail, "the cluster shares the line only when the whole trail fits").toContain(
1371
+ "flex: 1 1 auto",
1281
1372
  );
1282
- expect(header, "with nothing else to show, the band is one row").toContain(
1283
- 'grid-template-areas: "trail actions"',
1373
+ expect(trail, "and it ellipsises inside its share rather than widening the line").toContain(
1374
+ "min-width: 0",
1284
1375
  );
1285
- // The second row. It used to carry the cluster as well -- "a page with badges already
1286
- // spends a row, so the cluster joining them costs no height, and it buys the trail the
1287
- // whole first row" -- and the second clause was false for as long as it was written. The
1288
- // rule meant to hand the trail that row is a child selector against a display: contents
1289
- // wrapper (pinned below), so it never matched; the trail was auto-placed into column one
1290
- // and truncated exactly as early as before. The cluster paid and the trail never
1291
- // collected. Measured at 1280px on two crumbs, one badge and one button: the button on
1292
- // line two with 1028px of free room beside the trail on line one, unchanged at 1440.
1293
- //
1294
- // So the cluster stays beside the trail and the meta group takes the row under it, which
1295
- // is the one-row band's arrangement with a row added rather than a second arrangement.
1296
- const metaAt = base.indexOf('[data-terp="page-header"][data-has-meta] {');
1297
- expect(metaAt, "the two-row band should have a rule of its own").toBeGreaterThan(-1);
1298
- const withMeta = base.slice(metaAt, base.indexOf("}", metaAt));
1299
- // auto, not 1fr. Equal-height lines were the point of 1fr, and in an indefinite container
1300
- // fr rows resolve to the LARGEST row's content -- so the taller line's item filled its
1301
- // track exactly and, with the chrome row spending no block padding, sat flush on the
1302
- // band's border. Measured 9px above the content and 0px below it on every two-row page.
1303
- // Content-sized rows plus the multi-row band's own padding measure 4px and 4px.
1304
- expect(withMeta, "rows sized to their content, so neither sits on the border").toContain(
1305
- "grid-auto-rows: auto",
1376
+
1377
+ const cluster = ruleFor('[data-terp="page-header"] > [data-terp="page-actions"]');
1378
+ expect(cluster, "the cluster straight after the trail, so it can share its line").toContain(
1379
+ "order: 2",
1306
1380
  );
1307
- // The areas move per cutover, so they are pinned in their own queries rather than here --
1308
- // and per meta KIND, which "spends the meta row only at the widths where its meta is
1309
- // visible" below pins.
1310
- const wideMeta = mediaBodies(base, WIDE_VIEWPORT_QUERY);
1311
- expect(wideMeta, "above the cutover the cluster keeps its place beside the trail").toContain(
1312
- '"trail actions"',
1381
+ expect(cluster, "pushed to the end as ONE item -- nothing spreads its buttons").toContain(
1382
+ "margin-inline-start: auto",
1313
1383
  );
1314
- expect(wideMeta, "meta takes the row under them, spanning both columns").toContain(
1315
- '"meta meta"',
1384
+ // A flex item's automatic minimum is its content's: without these the cluster refuses to
1385
+ // shrink past its buttons and runs off the edge instead of wrapping them.
1386
+ expect(cluster, "it may shrink to its line").toContain("flex: 0 1 auto");
1387
+ expect(cluster).toContain("min-width: 0");
1388
+ expect(ruleFor('[data-terp="page-actions"]'), "and its own buttons wrap when it does").toContain(
1389
+ "flex-wrap: wrap",
1316
1390
  );
1317
- const narrowBand = mediaBodies(base, NARROW_VIEWPORT);
1318
- expect(narrowBand, "below the cutover the band is a single column").toContain(
1319
- "grid-template-columns: minmax(0, 1fr)",
1391
+
1392
+ const meta = ruleFor('[data-terp="page-meta"]');
1393
+ expect(meta, "badges and the lead line last").toContain("order: 3");
1394
+ expect(meta, "on a line of their own, never beside the cluster").toContain("flex: 1 1 100%");
1395
+
1396
+ // The left group generates no box, which is what makes the trail and the meta group items
1397
+ // of the BAND, so they can sit on different lines. The marker survives for the scanner.
1398
+ expect(ruleFor('[data-terp="page-heading"]'), "a boxed wrapper would make them one item").toContain(
1399
+ "display: contents",
1320
1400
  );
1321
- // The trail sheds its ancestors rather than its characters. Every crumb carries
1322
- // min-width: 0 and an ellipsis while the separators are flex: 0 0 auto, so a trail with no
1323
- // room degrades to bare chevrons -- measured at 360px on six crumbs: six labels under 8px
1324
- // and no h1 on screen at all. Dropping the ancestors takes their separators with them.
1401
+
1402
+ // The trail sheds its ancestors rather than its characters below the first cutover.
1403
+ const narrowBand = mediaBodies(base, NARROW_VIEWPORT);
1325
1404
  expect(narrowBand, "the narrow trail keeps the leaf and one ancestor").toContain(
1326
1405
  "li:not(:last-child):not(:nth-last-child(2))",
1327
1406
  );
1328
- // The actions row is declared only where there is a cluster to put in it: a named row with
1329
- // nothing in it is still a row, and the band's gap under it is 8px wedged beneath the
1330
- // trail on every page with no actions.
1331
- expect(narrowBand, "an actions row with no cluster is 8px of nothing").toContain(
1332
- '[data-terp="page-header"]:has(> [data-terp="page-actions"])',
1333
- );
1334
- // The left group generates no box, which is what lets its two children be grid items of
1335
- // the BAND and therefore sit on different rows. The marker survives for the scanner.
1336
- const headingAt = base.indexOf('[data-terp="page-heading"] {');
1337
- expect(headingAt, "page-heading should have a base rule").toBeGreaterThan(-1);
1338
- const heading = base.slice(headingAt, base.indexOf("}", headingAt));
1339
- expect(heading, "a boxed wrapper would put the trail and the meta in one cell").toContain(
1340
- "display: contents",
1341
- );
1342
- // The lead line is written as a correction, not a rule: hidden everywhere, shown again
1343
- // above the SECOND cutover. That is what makes three regions out of two queries -- the
1344
- // middle one is the width at which this correction has not applied yet.
1345
- const descAt = base.indexOf('[data-terp="page-description"] {');
1346
- expect(descAt, "page-description should have a base rule").toBeGreaterThan(-1);
1347
- const description = base.slice(descAt, base.indexOf("}", descAt));
1407
+
1408
+ // The lead line is a correction, not a rule: hidden everywhere, shown again above the
1409
+ // SECOND cutover, which makes three regions out of two queries.
1410
+ const description = ruleFor('[data-terp="page-description"]');
1348
1411
  expect(description, "the lead line is the first thing to go when room is short").toContain(
1349
1412
  "display: none",
1350
1413
  );
1351
- // Searched FROM the hiding rule: the meta-kind correction earlier in the band is also a
1352
- // roomy block, and "the first roomy block in the sheet" stopped meaning this one with it.
1353
- const roomy = base.indexOf(`@media ${ROOMY_VIEWPORT_QUERY}`, descAt);
1354
- expect(roomy, "the lead line comes back above the second cutover").toBeGreaterThan(descAt);
1355
- // And the truncation, which still matters on the row it does get: the sentence shares
1356
- // that row with the badges, so its max-content must not decide the row's width.
1357
- const shown = base.slice(base.indexOf('[data-terp="page-description"] {', roomy));
1358
- expect(shown).toContain("display: block");
1359
- const full = base.slice(base.lastIndexOf('[data-terp="page-description"] {'));
1414
+ const roomy = mediaBodies(base, ROOMY_VIEWPORT_QUERY);
1415
+ expect(flat(roomy)).toContain('[data-terp="page-description"] { display: block; }');
1416
+ const full = flat(base.slice(base.lastIndexOf('[data-terp="page-description"] {')));
1360
1417
  expect(full).toContain("min-width: 0");
1361
1418
  expect(full).toContain("white-space: nowrap");
1362
1419
  expect(full).toContain("text-overflow: ellipsis");
1363
1420
  });
1364
1421
 
1365
- it("spends the meta row only at the widths where its meta is visible", () => {
1422
+ it("shows the meta line only where its meta is visible", () => {
1366
1423
  // A lead line is hidden below the second cutover, so a band whose ONLY meta is a lead line
1367
- // has nothing to show on a second row there. It had the row anyway: the empty meta group
1368
- // took a track, the row gap and the multi-row padding came with it, and the band stretched
1369
- // all of that to its floor -- measured below the first cutover, the lone title sat 6.8px
1370
- // above the centre of a band that showed one line. Badges are visible everywhere and keep
1371
- // their row everywhere; the lead-line kind earns it only where the lead line is shown.
1424
+ // has nothing to show on a meta line there. An empty flex item with a full-line basis is
1425
+ // still a line, with the band's gap above it -- the same defect the grid version had as an
1426
+ // empty row: measured below the first cutover, a lone title 6.8px off the band's centre.
1427
+ // Badges are visible everywhere; the lead-line kind's group leaves flow until it is shown.
1372
1428
  const base = layerBody("terp.base");
1373
1429
  const always = baseOnly(base);
1374
- const wide = mediaBodies(base, WIDE_VIEWPORT_QUERY);
1375
- const narrow = mediaBodies(base, NARROW_VIEWPORT);
1376
1430
  const roomy = mediaBodies(base, ROOMY_VIEWPORT_QUERY);
1377
- const badges = '[data-terp="page-header"][data-has-meta="badges"]';
1378
- const lead = '[data-terp="page-header"][data-has-meta="description"]';
1379
-
1380
- expect(wide, "badges keep their row above the first cutover").toContain(`${badges} {`);
1381
- expect(narrow, "and below it").toContain(`${badges} {`);
1382
- expect(wide, "a lead line alone earns no row where it is hidden").not.toContain(lead);
1383
- expect(narrow, "including below the first cutover").not.toContain(lead);
1384
- expect(roomy, "the lead line's row comes back with the lead line").toContain(`${lead} {`);
1385
-
1386
- // The empty group has to leave flow, not just sit empty: its grid-area names an area the
1387
- // one-row template lacks, and an item placed into a missing named area gets implicit lines.
1388
- expect(
1389
- declaresRuleFor(always, `${lead} [data-terp="page-meta"]`),
1390
- "the lead-line group is out of flow wherever the lead line is",
1391
- ).toBe(true);
1392
1431
  expect(always).toMatch(
1393
1432
  /\[data-has-meta="description"\] \[data-terp="page-meta"\] \{\s*display: none;/,
1394
1433
  );
1395
1434
  expect(roomy).toMatch(
1396
1435
  /\[data-has-meta="description"\] \[data-terp="page-meta"\] \{\s*display: flex;/,
1397
1436
  );
1398
-
1399
- // And the padding a multi-row band spends follows the same split: always for badges, only
1400
- // above the second cutover for a lead line alone.
1401
- expect(always.replace(/\s+/g, " ")).toContain(
1402
- `[data-terp="page"]:not([data-measure="narrow"]) > ${badges} { padding-block: var(--space-1);`,
1403
- );
1404
- expect(always).not.toContain(`> ${lead} {`);
1405
- expect(roomy.replace(/\s+/g, " ")).toContain(
1406
- `[data-terp="page"]:not([data-measure="narrow"]) > ${lead} { padding-block: var(--space-1);`,
1437
+ expect(always, "badges need no rule: their group is always shown").not.toMatch(
1438
+ /\[data-has-meta="badges"\] \[data-terp="page-meta"\] \{\s*display: none;/,
1407
1439
  );
1408
1440
  });
1409
1441