@terpjs/react-core 0.29.0 → 0.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@terpjs/react-core",
3
- "version": "0.29.0",
3
+ "version": "0.30.0",
4
4
  "type": "module",
5
5
  "description": "Terp React stack core — typed @terpjs/contract client provider, auth session, capability gates, TanStack Router adapter, app shell, page archetypes, DataView and token-styled UI primitives. First frontend stack; see README.md for the component catalog.",
6
6
  "exports": {
@@ -15,7 +15,7 @@
15
15
  },
16
16
  "dependencies": {
17
17
  "@tanstack/react-router": "^1.170.38",
18
- "@terpjs/contract": "^0.29.0"
18
+ "@terpjs/contract": "^0.30.0"
19
19
  },
20
20
  "peerDependencies": {
21
21
  "react": "^19.0.0",
package/src/Page.test.tsx CHANGED
@@ -6,6 +6,7 @@ import { DetailPage } from "./DetailPage";
6
6
  import { OverviewPage } from "./OverviewPage";
7
7
  import { Page } from "./Page";
8
8
  import { ApiError } from "./unwrap";
9
+ import { Badge } from "./ui/Badge";
9
10
  import { Button } from "./ui/Button";
10
11
 
11
12
  afterEach(cleanup);
@@ -126,8 +127,29 @@ describe("Page", () => {
126
127
  </Page>,
127
128
  );
128
129
  const withMeta = container.querySelector('[data-terp="page-header"]');
129
- expect(withMeta?.getAttribute("data-has-meta"), "a lead line earns the row").toBe("true");
130
+ // "description" rather than a bare flag: a lead line earns the row only where it is shown,
131
+ // above the second cutover, and the sheet can only honour that if it can tell this band
132
+ // from one carrying a badge.
133
+ expect(withMeta?.getAttribute("data-has-meta"), "a lead line earns the row").toBe(
134
+ "description",
135
+ );
130
136
  expect(container.querySelector('[data-terp="page-meta"]')).not.toBeNull();
137
+
138
+ // A badge is visible at every width, so it names the kind even beside a lead line.
139
+ rerender(
140
+ <Page
141
+ title="Tasks"
142
+ badges={<Badge>Draft</Badge>}
143
+ description="A sentence."
144
+ actions={<Button>New</Button>}
145
+ >
146
+ <p>body</p>
147
+ </Page>,
148
+ );
149
+ expect(
150
+ container.querySelector('[data-terp="page-header"]')?.getAttribute("data-has-meta"),
151
+ "a badge earns the row at every width",
152
+ ).toBe("badges");
131
153
  });
132
154
 
133
155
  it("groups the action cluster even when the page passes loose nodes", () => {
package/src/Page.tsx CHANGED
@@ -185,9 +185,14 @@ export function Page({
185
185
  // shares it at no cost in height. A page with neither keeps the single row, and with it the
186
186
  // measurement the chrome is held to: the band matches the app header above it.
187
187
  const hasMeta = badgeList.length > 0 || hasDescription;
188
+ // WHICH meta, because the two are visible at different widths and the row must follow what
189
+ // is visible: badges show everywhere, a lead line only above the second cutover. A band whose
190
+ // only meta is a lead line therefore has an empty second row below that width unless the
191
+ // sheet can tell it apart, and it could not while this said "true" for both.
188
192
  // Hoisted, the density/collapsed idiom: the default stamps nothing, so the expression has a
189
193
  // branch rather than a boolean React would render as the string "false".
190
- const metaAttribute = hasMeta ? "true" : undefined;
194
+ const metaAttribute =
195
+ badgeList.length > 0 ? "badges" : hasDescription ? "description" : undefined;
191
196
  const body =
192
197
  error !== null && error !== undefined ? (
193
198
  (errorState ?? <ErrorState error={error} />)
@@ -1304,7 +1304,9 @@ describe("cascade structure", () => {
1304
1304
  expect(withMeta, "rows sized to their content, so neither sits on the border").toContain(
1305
1305
  "grid-auto-rows: auto",
1306
1306
  );
1307
- // The areas move per cutover, so they are pinned in their own queries rather than here.
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.
1308
1310
  const wideMeta = mediaBodies(base, WIDE_VIEWPORT_QUERY);
1309
1311
  expect(wideMeta, "above the cutover the cluster keeps its place beside the trail").toContain(
1310
1312
  '"trail actions"',
@@ -1346,7 +1348,9 @@ describe("cascade structure", () => {
1346
1348
  expect(description, "the lead line is the first thing to go when room is short").toContain(
1347
1349
  "display: none",
1348
1350
  );
1349
- const roomy = base.indexOf(`@media ${ROOMY_VIEWPORT_QUERY}`);
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);
1350
1354
  expect(roomy, "the lead line comes back above the second cutover").toBeGreaterThan(descAt);
1351
1355
  // And the truncation, which still matters on the row it does get: the sentence shares
1352
1356
  // that row with the badges, so its max-content must not decide the row's width.
@@ -1358,37 +1362,78 @@ describe("cascade structure", () => {
1358
1362
  expect(full).toContain("text-overflow: ellipsis");
1359
1363
  });
1360
1364
 
1361
- it("gives the breadcrumb trail one line box, and the leaf the step its own size needs", () => {
1365
+ it("spends the meta row only at the widths where its meta is visible", () => {
1366
+ // 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.
1372
+ const base = layerBody("terp.base");
1373
+ const always = baseOnly(base);
1374
+ const wide = mediaBodies(base, WIDE_VIEWPORT_QUERY);
1375
+ const narrow = mediaBodies(base, NARROW_VIEWPORT);
1376
+ 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
+ expect(always).toMatch(
1393
+ /\[data-has-meta="description"\] \[data-terp="page-meta"\] \{\s*display: none;/,
1394
+ );
1395
+ expect(roomy).toMatch(
1396
+ /\[data-has-meta="description"\] \[data-terp="page-meta"\] \{\s*display: flex;/,
1397
+ );
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);`,
1407
+ );
1408
+ });
1409
+
1410
+ it("gives the breadcrumb trail one line box, leaf included", () => {
1362
1411
  // The trail is a row of items that get CENTRED, so two line heights in it are two
1363
1412
  // baselines. The leaf declared 1.3 while its ancestors inherited `normal`: measured at
1364
1413
  // font-size-sm, a 19.00px ancestor line box against an 18.19px leaf, which left the
1365
1414
  // page's own title 0.59px above the crumb it hangs off with the chevron centred on a
1366
- // third line. One declaration on the trail, inherited by every crumb, is what makes the
1367
- // ancestors share a baseline.
1415
+ // third line. One declaration on the trail, inherited by every crumb and by the h1, is
1416
+ // what makes the row share a baseline.
1368
1417
  //
1369
1418
  // The published step rather than a bare literal, and that is the second half of the fix
1370
1419
  // rather than house style: `normal` is the FONT's metric, so the mismatch was as big as
1371
1420
  // the app's typeface said it was, and an app on a webfont with taller natural leading got
1372
1421
  // a worse one than the system stack this was measured in.
1373
1422
  //
1374
- // The LEAF is now the exception, and deliberately: at xl against sm ancestors it cannot
1375
- // share their baseline whatever it declares, and the li centres it instead. That frees the
1376
- // value to do the one job only it can do here — hold the band's floor, where snug would
1377
- // cost 3.6px on every page carrying a lead line (see the rule, where the measurement is).
1378
- // So this holds it at the published tight step rather than at "absent": absent means
1379
- // inheriting the trail's snug, which is the version that grows the band.
1423
+ // 0.28.0 made the leaf the exception (xl at the tight step) and this test followed it.
1424
+ // The leaf is back at the trail's own size, so it is back on the trail's line box too.
1380
1425
  const base = layerBody("terp.base");
1381
1426
  const trail = base.slice(base.indexOf('[data-terp="breadcrumbs"] {'));
1382
1427
  expect(
1383
1428
  trail.slice(0, trail.indexOf("}")),
1384
- "the trail declares the line box every ancestor crumb shares",
1429
+ "the trail declares the line box every crumb shares",
1385
1430
  ).toContain("line-height: var(--font-line-height-snug)");
1386
1431
  const leafAt = base.indexOf('[data-terp="page-title"] {');
1387
1432
  expect(leafAt, "the trail's leaf should have a rule").toBeGreaterThan(-1);
1388
1433
  expect(
1389
1434
  base.slice(leafAt, base.indexOf("}", leafAt)),
1390
- "the leaf declares the tight step; inheriting snug is what overruns the band's floor",
1391
- ).toContain("line-height: var(--font-line-height-tight)");
1435
+ "the leaf takes the trail's line box; a second value here is the misalignment",
1436
+ ).not.toContain("line-height");
1392
1437
  });
1393
1438
 
1394
1439
  it("spans a full row across every track, and makes it a box that can", () => {
@@ -1544,16 +1589,15 @@ describe("cascade structure", () => {
1544
1589
  // one published scale rather than four sizes that happen to differ.
1545
1590
  const base = layerBody("terp.base");
1546
1591
  for (const [selector, step] of [
1547
- // page-title is back on the top step, which is where this loop found it before the band
1548
- // change demoted it to sm. At sm it tied with card-title, so the page's own name measured
1549
- // exactly as much as the name of a section on it — the flat scale this test exists to
1550
- // stop, one row further up than the version it was written for. Pinned rather than
1551
- // dropped, for the reason the band change proved: removing this marker from the loop left
1552
- // the one size the change was about free to drift.
1553
- ['[data-terp="page-title"]', "xl"],
1554
- // The top step's OTHER reader. It stopped being the thing that keeps the token read when
1555
- // page-title came back to it, and is kept for the reason it was added: a standalone
1556
- // heading asking for the masthead step should get the same size the masthead renders.
1592
+ // page-title left the TOP step when the header became a band, but it still has a step
1593
+ // and this is it: sm, the trail's own size, because the title IS the trail's leaf and a
1594
+ // 24px leaf on 14px ancestors reads as small-small-BIG rather than as one trail. Pinned
1595
+ // rather than dropped — removing it from this loop, which is what the band change first
1596
+ // did, left the one marker whose size the change was about free to drift. 0.28.0 took it
1597
+ // back to xl, and the band paid 8px of header height for it; this is that reversal.
1598
+ ['[data-terp="page-title"]', "sm"],
1599
+ // The top step keeps two readers, which is what stops the token going unread;
1600
+ // tokens.guard.test.ts holds that end.
1557
1601
  ['[data-terp="heading"][data-size="xl"]', "xl"],
1558
1602
  ['[data-terp="card-title"]', "lg"],
1559
1603
  ['[data-terp="card-description"]', "sm"],
package/src/styles.ts CHANGED
@@ -2137,12 +2137,40 @@ textarea[data-terp="input"] {
2137
2137
  to their content, plus the padding the multi-row band now spends, give 4px and 4px. */
2138
2138
  grid-auto-rows: auto;
2139
2139
  }
2140
+ /* WHICH meta decides the row, not whether there is any. Badges show at every width, so a band
2141
+ carrying one has its second row at every width. A lead line shows only above the SECOND
2142
+ cutover (see page-description below), so a band whose only meta is a lead line has nothing
2143
+ to put on that row anywhere beneath it -- and a grid row with nothing visible in it is still
2144
+ a row. It was one: the empty meta group took a track, the band's row gap and the multi-row
2145
+ band's block padding came with it, and the whole was stretched to the header floor. Measured
2146
+ below the first cutover on a hub with a lead line, the title sat 6.8px above the centre of a
2147
+ one-line band whose other line showed nothing at all.
2148
+
2149
+ So Page stamps the kind (data-has-meta="badges" or "description"), and a description-only
2150
+ band is a one-row band until the correction at the second cutover gives it its meta row --
2151
+ the same mobile-first shape the lead line itself is written in. Its meta group is taken out
2152
+ of flow there too, and not merely left empty: its grid-area names an area the one-row
2153
+ template does not declare, and an item placed into a missing named area is not dropped but
2154
+ given IMPLICIT lines, which is a new row after all. */
2155
+ [data-terp="page-header"][data-has-meta="description"] [data-terp="page-meta"] {
2156
+ display: none;
2157
+ }
2140
2158
  @media ${WIDE_VIEWPORT_QUERY} {
2141
- [data-terp="page-header"][data-has-meta] {
2159
+ [data-terp="page-header"][data-has-meta="badges"] {
2160
+ grid-template-areas:
2161
+ "trail actions"
2162
+ "meta meta";
2163
+ }
2164
+ }
2165
+ @media ${ROOMY_VIEWPORT_QUERY} {
2166
+ [data-terp="page-header"][data-has-meta="description"] {
2142
2167
  grid-template-areas:
2143
2168
  "trail actions"
2144
2169
  "meta meta";
2145
2170
  }
2171
+ [data-terp="page-header"][data-has-meta="description"] [data-terp="page-meta"] {
2172
+ display: flex;
2173
+ }
2146
2174
  }
2147
2175
  /* Below the first cutover the band is one column and nothing competes for a line. The trail
2148
2176
  keeps the leaf and one ancestor: every crumb carries min-width: 0 and an ellipsis while the
@@ -2169,13 +2197,16 @@ textarea[data-terp="input"] {
2169
2197
  }
2170
2198
  /* Written AFTER the :has() rule and not before it: the two selectors tie at (0,2,0), so
2171
2199
  source order is what decides a page that carries meta and no cluster, and it belongs to
2172
- this one. The combined selector below outranks both at (0,3,0). */
2173
- [data-terp="page-header"][data-has-meta] {
2200
+ this one. The combined selector below outranks both at (0,3,0).
2201
+
2202
+ Badges only: this whole block sits below the first cutover, where a lead line never
2203
+ shows, so a description-only band keeps the rows it would have with no meta at all. */
2204
+ [data-terp="page-header"][data-has-meta="badges"] {
2174
2205
  grid-template-areas:
2175
2206
  "trail"
2176
2207
  "meta";
2177
2208
  }
2178
- [data-terp="page-header"][data-has-meta]:has(> [data-terp="page-actions"]) {
2209
+ [data-terp="page-header"][data-has-meta="badges"]:has(> [data-terp="page-actions"]) {
2179
2210
  grid-template-areas:
2180
2211
  "trail"
2181
2212
  "meta"
@@ -2253,35 +2284,25 @@ textarea[data-terp="input"] {
2253
2284
  2em } ON the element, and a declaration on the element beats an inherited value however
2254
2285
  specific the ancestor rule is: without this the leaf renders at twice the trail.
2255
2286
 
2256
- xl, not the trail's own sm. "Heavier than its ancestors, not larger" was the rule while the
2257
- band was 3rem and the leaf had no room to be anything else, and it cost the page its name:
2258
- at sm/semibold the title measured the same as a table header, less than the action button
2259
- beside it, and exactly as much as the card titles of the sections under it — so on a hub
2260
- every HubCard outranked the page it was on. A screen whose largest type belongs to its
2261
- content is a screen with no masthead, and that reads as unfinished before any one component
2262
- does. The scale is 24 / 18 / 16 / 14 again: page title, card title, body, description.
2263
-
2264
- The one-row band still holds its floor, which is the promise this row makes and the number
2265
- to re-measure if either half moves. --shell-header-height is 3.5rem now, and xl at the TIGHT
2266
- step is 28.8px, so the title's line box sits inside 56px with room to spare: measured, a hub's
2267
- band and the app header above it are both 56.0. At the trail's snug step it would be 32.4 and
2268
- still fit, but the band that carries meta — which has broken the floor by design, and does not
2269
- make the claim — would take the extra 3.6px on every page with a lead line, so the tight step
2270
- is what keeps the two bands one apart rather than two.
2271
-
2272
- That is also the answer to the line height the trail's own rule argues for. Sharing it keeps
2273
- the leaf's glyphs on the ancestors' baseline, which mattered when leaf and ancestors were the
2274
- same size; at 24 against 14 they cannot share a baseline anyway and the li centres them, so
2275
- the value is free to do the job only it can do here.
2276
-
2277
- Tracking is the scale's tight step, which only starts earning its keep at this size: -0.02em
2278
- is 0.48px here and nothing at all at 14px, which is why the trail below does not take it. */
2287
+ Semibold at the trail's own size, which is the whole "the trail is the title" idea in one
2288
+ declaration — heavier than its ancestors, not larger.
2289
+
2290
+ This is the second time the leaf has been sm, and the first reversal is the reason to keep
2291
+ it here. 0.28.0 took it to xl so the page's name would outrank its cards, and paid for that
2292
+ in the band itself: the leaf was 24px on 14px ancestors, the small-small-BIG trail the band
2293
+ comment above warns about, and it needed --shell-header-height raised from 3rem to 3.5rem to
2294
+ fit, so every app's header grew 8px to hold a title that is chrome. The page's name is
2295
+ carried by being the trail's heaviest item and its h1, not by being its largest.
2296
+
2297
+ And no line-height of its own, which is the other half of that idea: it takes the trail's
2298
+ (see breadcrumbs, where the value and the defect are recorded). A second value here — 1.3
2299
+ against the ancestors' inherited normal — is what left the leaf's glyphs sitting 0.59px
2300
+ above the crumb they hang off, in the same font at the same size. */
2279
2301
  [data-terp="page-title"] {
2280
2302
  margin: 0;
2281
- font-size: var(--font-size-xl);
2282
- line-height: var(--font-line-height-tight);
2303
+ font-size: var(--font-size-sm);
2283
2304
  font-weight: var(--font-weight-semibold);
2284
- letter-spacing: var(--font-letter-spacing-tight);
2305
+ letter-spacing: 0;
2285
2306
  color: var(--color-neutral-900);
2286
2307
  }
2287
2308
  /* Status pills next to the title. A row of its own so a page passing several keeps them
@@ -2357,10 +2378,21 @@ textarea[data-terp="input"] {
2357
2378
  Below the cutover the same is true of a band whose cluster has taken a row of its own.
2358
2379
 
2359
2380
  The narrow rule weighs (0,3,0) plus :has()'s argument, so (0,4,0) — the same as the meta
2360
- rule, and they declare the same value, so the tie decides nothing. */
2361
- [data-terp="page"]:not([data-measure="narrow"]) > [data-terp="page-header"][data-has-meta] {
2381
+ rule, and they declare the same value, so the tie decides nothing.
2382
+
2383
+ A description-only band is multi-row only above the second cutover (see the meta-kind rule
2384
+ near the top of the band), so that is the only width it spends this padding at. Below it
2385
+ the band is one row and holds the floor like any other: spending 4px + 4px there is exactly
2386
+ what pushed a lone title off the centre of a band with nothing else in it. */
2387
+ [data-terp="page"]:not([data-measure="narrow"]) > [data-terp="page-header"][data-has-meta="badges"] {
2362
2388
  padding-block: var(--space-1);
2363
2389
  }
2390
+ @media ${ROOMY_VIEWPORT_QUERY} {
2391
+ [data-terp="page"]:not([data-measure="narrow"])
2392
+ > [data-terp="page-header"][data-has-meta="description"] {
2393
+ padding-block: var(--space-1);
2394
+ }
2395
+ }
2364
2396
  @media ${NARROW_VIEWPORT} {
2365
2397
  [data-terp="page"]:not([data-measure="narrow"])
2366
2398
  > [data-terp="page-header"]:has(> [data-terp="page-actions"]) {
@@ -148,9 +148,9 @@ const BARE_TYPE_LITERALS: Record<string, Record<string, number>> = {
148
148
  // letter-spacing on form controls, so inheritance has to be asked for explicitly — the
149
149
  // header and its button were rendering two different treatments side by side until it was.
150
150
  //
151
- // One `0` retired when page-title took --font-letter-spacing-tight: the leaf is set at lg now,
152
- // and the tight step is worth a third of a pixel there where at sm it was worth nothing.
153
- "letter-spacing": { "0": 3, "0.04em": 1, "0.06em": 1, inherit: 1 },
151
+ // Four `0`s again: page-title is back at sm, where the tight step is worth nothing, and it
152
+ // takes the trail's plain tracking as it did before 0.28.0 set it at xl.
153
+ "letter-spacing": { "0": 4, "0.04em": 1, "0.06em": 1, inherit: 1 },
154
154
  };
155
155
 
156
156
  describe("design tokens", () => {