@terpjs/react-core 0.25.0 → 0.27.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 +4 -4
- package/src/styles.test.ts +76 -19
- package/src/styles.ts +122 -22
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@terpjs/react-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.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": {
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"test": "vitest run"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@tanstack/react-router": "^1.170.
|
|
17
|
-
"@terpjs/contract": "^0.
|
|
16
|
+
"@tanstack/react-router": "^1.170.38",
|
|
17
|
+
"@terpjs/contract": "^0.27.0"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
20
|
"react": "^19.0.0",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"@types/react": "^19.3.0",
|
|
27
27
|
"@types/react-dom": "^19.3.0",
|
|
28
28
|
"@vitejs/plugin-react": "^6.1.1",
|
|
29
|
-
"jsdom": "^30.0
|
|
29
|
+
"jsdom": "^30.1.0",
|
|
30
30
|
"react": "^19.3.0",
|
|
31
31
|
"react-dom": "^19.3.0",
|
|
32
32
|
"typescript": "^5.9.3",
|
package/src/styles.test.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @vitest-environment jsdom
|
|
2
2
|
import { afterEach, describe, expect, it } from "vitest";
|
|
3
3
|
|
|
4
|
-
import { ROOMY_VIEWPORT_QUERY } from "./breakpoints";
|
|
4
|
+
import { NARROW_VIEWPORT, ROOMY_VIEWPORT_QUERY, WIDE_VIEWPORT_QUERY } from "./breakpoints";
|
|
5
5
|
import { TERP_STYLES_ID, TERP_STYLES_CSS, injectTerpStyles } from "./styles";
|
|
6
6
|
|
|
7
7
|
/** The sheet with comments removed — prose must not satisfy a structural assertion. */
|
|
@@ -39,6 +39,40 @@ function layerBody(name: string): string {
|
|
|
39
39
|
throw new Error(`@layer ${name} is not brace-balanced`);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Every `@media <query>` block inside `body`, brace-balanced and joined.
|
|
44
|
+
*
|
|
45
|
+
* ALL of them, not the first: a cutover half is declared in more than one place — the stack's
|
|
46
|
+
* direction props and the page band's two-row form both sit above the same one — and reading
|
|
47
|
+
* only the first would assert against whichever block happens to be written earlier. Joining
|
|
48
|
+
* asserts what the sheet declares for that HALF of the cutover, which is the property worth
|
|
49
|
+
* holding; where a rule physically sits inside the half is not.
|
|
50
|
+
*
|
|
51
|
+
* Reaching inside the query at all is the point. A substring search across the flat layer
|
|
52
|
+
* passes just as happily when a rule has landed in the wrong half, which is the one mistake
|
|
53
|
+
* this pair of blocks can make.
|
|
54
|
+
*/
|
|
55
|
+
function mediaBodies(body: string, query: string): string {
|
|
56
|
+
const opener = `@media ${query} {`;
|
|
57
|
+
const found: string[] = [];
|
|
58
|
+
for (let at = body.indexOf(opener); at !== -1; at = body.indexOf(opener, at + 1)) {
|
|
59
|
+
const first = body.indexOf("{", at);
|
|
60
|
+
let depth = 0;
|
|
61
|
+
for (let i = first; i < body.length; i += 1) {
|
|
62
|
+
if (body[i] === "{") depth += 1;
|
|
63
|
+
else if (body[i] === "}") {
|
|
64
|
+
depth -= 1;
|
|
65
|
+
if (depth === 0) {
|
|
66
|
+
found.push(body.slice(first + 1, i));
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (found.length === 0) throw new Error(`the sheet declares no @media ${query} block`);
|
|
73
|
+
return found.join("\n");
|
|
74
|
+
}
|
|
75
|
+
|
|
42
76
|
/**
|
|
43
77
|
* Whether `body` declares a rule whose selector list contains EXACTLY `selector` — not
|
|
44
78
|
* merely a selector containing it as a substring.
|
|
@@ -1033,29 +1067,52 @@ describe("cascade structure", () => {
|
|
|
1033
1067
|
expect(header, "with nothing else to show, the band is one row").toContain(
|
|
1034
1068
|
'grid-template-areas: "trail actions"',
|
|
1035
1069
|
);
|
|
1036
|
-
// The second row
|
|
1037
|
-
//
|
|
1038
|
-
//
|
|
1039
|
-
//
|
|
1040
|
-
//
|
|
1070
|
+
// The second row. It used to carry the cluster as well -- "a page with badges already
|
|
1071
|
+
// spends a row, so the cluster joining them costs no height, and it buys the trail the
|
|
1072
|
+
// whole first row" -- and the second clause was false for as long as it was written. The
|
|
1073
|
+
// rule meant to hand the trail that row is a child selector against a display: contents
|
|
1074
|
+
// wrapper (pinned below), so it never matched; the trail was auto-placed into column one
|
|
1075
|
+
// and truncated exactly as early as before. The cluster paid and the trail never
|
|
1076
|
+
// collected. Measured at 1280px on two crumbs, one badge and one button: the button on
|
|
1077
|
+
// line two with 1028px of free room beside the trail on line one, unchanged at 1440.
|
|
1078
|
+
//
|
|
1079
|
+
// So the cluster stays beside the trail and the meta group takes the row under it, which
|
|
1080
|
+
// is the one-row band's arrangement with a row added rather than a second arrangement.
|
|
1041
1081
|
const metaAt = base.indexOf('[data-terp="page-header"][data-has-meta] {');
|
|
1042
1082
|
expect(metaAt, "the two-row band should have a rule of its own").toBeGreaterThan(-1);
|
|
1043
1083
|
const withMeta = base.slice(metaAt, base.indexOf("}", metaAt));
|
|
1044
|
-
|
|
1045
|
-
|
|
1084
|
+
// auto, not 1fr. Equal-height lines were the point of 1fr, and in an indefinite container
|
|
1085
|
+
// fr rows resolve to the LARGEST row's content -- so the taller line's item filled its
|
|
1086
|
+
// track exactly and, with the chrome row spending no block padding, sat flush on the
|
|
1087
|
+
// band's border. Measured 9px above the content and 0px below it on every two-row page.
|
|
1088
|
+
// Content-sized rows plus the multi-row band's own padding measure 4px and 4px.
|
|
1089
|
+
expect(withMeta, "rows sized to their content, so neither sits on the border").toContain(
|
|
1090
|
+
"grid-auto-rows: auto",
|
|
1091
|
+
);
|
|
1092
|
+
// The areas move per cutover, so they are pinned in their own queries rather than here.
|
|
1093
|
+
const wideMeta = mediaBodies(base, WIDE_VIEWPORT_QUERY);
|
|
1094
|
+
expect(wideMeta, "above the cutover the cluster keeps its place beside the trail").toContain(
|
|
1095
|
+
'"trail actions"',
|
|
1096
|
+
);
|
|
1097
|
+
expect(wideMeta, "meta takes the row under them, spanning both columns").toContain(
|
|
1098
|
+
'"meta meta"',
|
|
1099
|
+
);
|
|
1100
|
+
const narrowBand = mediaBodies(base, NARROW_VIEWPORT);
|
|
1101
|
+
expect(narrowBand, "below the cutover the band is a single column").toContain(
|
|
1102
|
+
"grid-template-columns: minmax(0, 1fr)",
|
|
1046
1103
|
);
|
|
1047
|
-
|
|
1048
|
-
|
|
1104
|
+
// The trail sheds its ancestors rather than its characters. Every crumb carries
|
|
1105
|
+
// min-width: 0 and an ellipsis while the separators are flex: 0 0 auto, so a trail with no
|
|
1106
|
+
// room degrades to bare chevrons -- measured at 360px on six crumbs: six labels under 8px
|
|
1107
|
+
// and no h1 on screen at all. Dropping the ancestors takes their separators with them.
|
|
1108
|
+
expect(narrowBand, "the narrow trail keeps the leaf and one ancestor").toContain(
|
|
1109
|
+
"li:not(:last-child):not(:nth-last-child(2))",
|
|
1049
1110
|
);
|
|
1050
|
-
//
|
|
1051
|
-
// is
|
|
1052
|
-
//
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
// resolved tracks rather than the box: a total carries the gap and the border too, so only
|
|
1056
|
-
// the tracks can say whether the two lines actually agree.
|
|
1057
|
-
expect(withMeta, "a band of two lines gives them the same height").toContain(
|
|
1058
|
-
"grid-auto-rows: 1fr",
|
|
1111
|
+
// The actions row is declared only where there is a cluster to put in it: a named row with
|
|
1112
|
+
// nothing in it is still a row, and the band's gap under it is 8px wedged beneath the
|
|
1113
|
+
// trail on every page with no actions.
|
|
1114
|
+
expect(narrowBand, "an actions row with no cluster is 8px of nothing").toContain(
|
|
1115
|
+
'[data-terp="page-header"]:has(> [data-terp="page-actions"])',
|
|
1059
1116
|
);
|
|
1060
1117
|
// The left group generates no box, which is what lets its two children be grid items of
|
|
1061
1118
|
// the BAND and therefore sit on different rows. The marker survives for the scanner.
|
package/src/styles.ts
CHANGED
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
* touched.
|
|
104
104
|
*/
|
|
105
105
|
|
|
106
|
-
import { ROOMY_VIEWPORT_QUERY, WIDE_VIEWPORT_QUERY } from "./breakpoints";
|
|
106
|
+
import { NARROW_VIEWPORT, ROOMY_VIEWPORT_QUERY, WIDE_VIEWPORT_QUERY } from "./breakpoints";
|
|
107
107
|
|
|
108
108
|
/** The `<style>` element id used to detect a prior injection. */
|
|
109
109
|
export const TERP_STYLES_ID = "terp-core-styles";
|
|
@@ -569,10 +569,11 @@ textarea[data-terp="input"] {
|
|
|
569
569
|
two halves of the cutover partition the viewport by construction. Written out here they
|
|
570
570
|
would be two literals that agree until someone edits one.
|
|
571
571
|
|
|
572
|
-
There are
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
572
|
+
There are FOUR \${…} in this sheet now: this one, the page band's ROOMY block, and the
|
|
573
|
+
two halves of the band's own cutover (its WIDE two-row form and its NARROW single
|
|
574
|
+
column). Every one of them comes from ./breakpoints and none spells a number, which is
|
|
575
|
+
the property worth grepping for: a further interpolation is fine if it names a constant
|
|
576
|
+
from that module, and a literal pixel width in a media query here is not. */
|
|
576
577
|
@media ${WIDE_VIEWPORT_QUERY} {
|
|
577
578
|
[data-terp="stack"][data-direction-wide="column"] { flex-direction: column; }
|
|
578
579
|
[data-terp="stack"][data-direction-wide="row"] { flex-direction: row; }
|
|
@@ -2015,12 +2016,22 @@ textarea[data-terp="input"] {
|
|
|
2015
2016
|
gap: var(--space-2) var(--space-4);
|
|
2016
2017
|
min-width: 0;
|
|
2017
2018
|
}
|
|
2018
|
-
/* The two-row band
|
|
2019
|
-
lead line ALREADY spends a second row
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2019
|
+
/* The two-row band. It used to move the action cluster onto the meta row at every width, on
|
|
2020
|
+
the reasoning that a page with badges or a lead line ALREADY spends a second row, so the
|
|
2021
|
+
cluster joining them costs no height and buys the trail the whole first row.
|
|
2022
|
+
|
|
2023
|
+
The second half of that was never true, because the rule that gave the trail the first row
|
|
2024
|
+
never matched (see the trail's own rule below). So the cluster was paying the whole price
|
|
2025
|
+
and the trail collected none of it: measured on a 1280px viewport, an ordinary detail page
|
|
2026
|
+
-- two crumbs, one badge, one button -- put the button on line two with 1028px of empty
|
|
2027
|
+
room beside the trail on line one. That is what "the button wraps before the breadcrumb is
|
|
2028
|
+
long" turns out to be, and it is width-independent: the same at 1440.
|
|
2029
|
+
|
|
2030
|
+
So the cluster keeps its place beside the trail and the meta group takes the row below it,
|
|
2031
|
+
which is also what the one-row band does and therefore one rule for where a page's actions
|
|
2032
|
+
live rather than two. Below the first cutover the band becomes a single column instead --
|
|
2033
|
+
there the cluster genuinely cannot share a line with the title, and the row it used to take
|
|
2034
|
+
from the trail was squeezing the h1 to nothing.
|
|
2024
2035
|
|
|
2025
2036
|
A grid rather than the flex-wrap this was: wrap order follows source order, so the meta
|
|
2026
2037
|
group and the cluster could not share a row while staying two groups, and the moment the
|
|
@@ -2029,15 +2040,67 @@ textarea[data-terp="input"] {
|
|
|
2029
2040
|
whose whole job was to right-align it. Areas say where things go and no free space is
|
|
2030
2041
|
distributed anywhere, so neither failure has anywhere to happen. */
|
|
2031
2042
|
[data-terp="page-header"][data-has-meta] {
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2043
|
+
/* auto, not 1fr. Equal-height lines read as one band of two lines, which is why they were
|
|
2044
|
+
here -- but fr rows in an indefinite container resolve to the LARGEST row's content, so
|
|
2045
|
+
the shorter line's item was centred in a track sized by the taller one and the taller
|
|
2046
|
+
line's item filled its track exactly. With no block padding under it (the chrome row
|
|
2047
|
+
spends none, by the invariant below) that put the bottom row flush against the band's
|
|
2048
|
+
border: measured 9px above the content and 0px below it on every two-row page. Rows sized
|
|
2049
|
+
to their content, plus the padding the multi-row band now spends, give 4px and 4px. */
|
|
2050
|
+
grid-auto-rows: auto;
|
|
2051
|
+
}
|
|
2052
|
+
@media ${WIDE_VIEWPORT_QUERY} {
|
|
2053
|
+
[data-terp="page-header"][data-has-meta] {
|
|
2054
|
+
grid-template-areas:
|
|
2055
|
+
"trail actions"
|
|
2056
|
+
"meta meta";
|
|
2057
|
+
}
|
|
2058
|
+
}
|
|
2059
|
+
/* Below the first cutover the band is one column and nothing competes for a line. The trail
|
|
2060
|
+
keeps the leaf and one ancestor: every crumb carries min-width: 0 and an ellipsis while the
|
|
2061
|
+
separators are flex: 0 0 auto, so a trail with no room does not degrade to short labels --
|
|
2062
|
+
it degrades to a row of bare chevrons with the h1 among the casualties. Measured at 360px
|
|
2063
|
+
on a six-crumb page: six labels under 8px, no page title on screen at all, and the cluster
|
|
2064
|
+
overlapping the badges by 24px. Dropping the ancestors takes their separators with them,
|
|
2065
|
+
which is the only degradation here that leaves something readable.
|
|
2066
|
+
|
|
2067
|
+
The actions row is declared only when there IS a cluster -- :has() for the same reason
|
|
2068
|
+
card-header and control-label use it, that the alternative is an attribute the component
|
|
2069
|
+
would have to stamp. A named row with nothing in it is still a row, and with the band's
|
|
2070
|
+
gap under it that is 8px of empty space wedged under the trail on every page that has no
|
|
2071
|
+
actions. */
|
|
2072
|
+
@media ${NARROW_VIEWPORT} {
|
|
2073
|
+
[data-terp="page-header"] {
|
|
2074
|
+
grid-template-columns: minmax(0, 1fr);
|
|
2075
|
+
grid-template-areas: "trail";
|
|
2076
|
+
}
|
|
2077
|
+
[data-terp="page-header"]:has(> [data-terp="page-actions"]) {
|
|
2078
|
+
grid-template-areas:
|
|
2079
|
+
"trail"
|
|
2080
|
+
"actions";
|
|
2081
|
+
}
|
|
2082
|
+
/* Written AFTER the :has() rule and not before it: the two selectors tie at (0,2,0), so
|
|
2083
|
+
source order is what decides a page that carries meta and no cluster, and it belongs to
|
|
2084
|
+
this one. The combined selector below outranks both at (0,3,0). */
|
|
2085
|
+
[data-terp="page-header"][data-has-meta] {
|
|
2086
|
+
grid-template-areas:
|
|
2087
|
+
"trail"
|
|
2088
|
+
"meta";
|
|
2089
|
+
}
|
|
2090
|
+
[data-terp="page-header"][data-has-meta]:has(> [data-terp="page-actions"]) {
|
|
2091
|
+
grid-template-areas:
|
|
2092
|
+
"trail"
|
|
2093
|
+
"meta"
|
|
2094
|
+
"actions";
|
|
2095
|
+
}
|
|
2096
|
+
[data-terp="breadcrumbs"] li:not(:last-child):not(:nth-last-child(2)) {
|
|
2097
|
+
display: none;
|
|
2098
|
+
}
|
|
2099
|
+
[data-terp="breadcrumbs"] li:nth-last-child(2):not(:first-child)::before {
|
|
2100
|
+
content: "…";
|
|
2101
|
+
margin-inline-end: var(--space-2);
|
|
2102
|
+
color: var(--color-neutral-600);
|
|
2103
|
+
}
|
|
2041
2104
|
}
|
|
2042
2105
|
/* The band's left group, and it generates NO box. The trail and the meta group have to be
|
|
2043
2106
|
grid items of the band itself -- they sit on different rows -- but the marker is published
|
|
@@ -2053,8 +2116,16 @@ textarea[data-terp="input"] {
|
|
|
2053
2116
|
[data-terp="page-heading"] {
|
|
2054
2117
|
display: contents;
|
|
2055
2118
|
}
|
|
2056
|
-
/* The trail
|
|
2057
|
-
|
|
2119
|
+
/* The trail's placement, and the combinator is the whole of it. This was a CHILD selector,
|
|
2120
|
+
and the trail is not a child of the band: Page renders it inside page-heading, which is
|
|
2121
|
+
display: contents. That removes the BOX and not the node, and selectors match the tree, so
|
|
2122
|
+
the rule matched nothing at all and the trail was auto-placed with its automatic minimum
|
|
2123
|
+
intact. Both halves below were therefore dead from the day the heading group arrived, and
|
|
2124
|
+
the two-row band above was justified by a benefit this rule was supposed to deliver.
|
|
2125
|
+
|
|
2126
|
+
Descendant, not child, and scoped to the band: page-header holds the heading group and the
|
|
2127
|
+
cluster and nothing else, so there is no second trail here to catch by accident. */
|
|
2128
|
+
[data-terp="page-header"] [data-terp="breadcrumbs"] {
|
|
2058
2129
|
grid-area: trail;
|
|
2059
2130
|
min-width: 0;
|
|
2060
2131
|
}
|
|
@@ -2171,6 +2242,26 @@ textarea[data-terp="input"] {
|
|
|
2171
2242
|
box-sizing: border-box;
|
|
2172
2243
|
border-block-end: 1px solid var(--color-neutral-200);
|
|
2173
2244
|
}
|
|
2245
|
+
/* The block padding the ONE-ROW band cannot have, spent on the bands that are already more
|
|
2246
|
+
than one row. The rule above stays at var(--space-0) and stays tied to the app header's
|
|
2247
|
+
own padding, because that row is the one making the claim: 48px, the same as the header
|
|
2248
|
+
above it, and the largest control this package ships (2.75rem) has to fit inside it. A band
|
|
2249
|
+
that carries meta has broken that height already and makes no such claim, so it can afford
|
|
2250
|
+
the 4px — and it is the only band where the missing padding was ever visible, since the
|
|
2251
|
+
one-row band centres its single line inside the floor and reads as padded either way.
|
|
2252
|
+
Below the cutover the same is true of a band whose cluster has taken a row of its own.
|
|
2253
|
+
|
|
2254
|
+
The narrow rule weighs (0,3,0) plus :has()'s argument, so (0,4,0) — the same as the meta
|
|
2255
|
+
rule, and they declare the same value, so the tie decides nothing. */
|
|
2256
|
+
[data-terp="page"]:not([data-measure="narrow"]) > [data-terp="page-header"][data-has-meta] {
|
|
2257
|
+
padding-block: var(--space-1);
|
|
2258
|
+
}
|
|
2259
|
+
@media ${NARROW_VIEWPORT} {
|
|
2260
|
+
[data-terp="page"]:not([data-measure="narrow"])
|
|
2261
|
+
> [data-terp="page-header"]:has(> [data-terp="page-actions"]) {
|
|
2262
|
+
padding-block: var(--space-1);
|
|
2263
|
+
}
|
|
2264
|
+
}
|
|
2174
2265
|
/* The BLEED, which does need a shell, because the negative-margin idiom is only correct when
|
|
2175
2266
|
the box being escaped is appshell-main and that box pads by exactly --shell-gutter. ADR
|
|
2176
2267
|
0097 §2 kept "it works with no shell above it at all" as a property of the mechanism, and
|
|
@@ -4080,6 +4171,14 @@ button[data-terp="input"][data-placeholder="true"] {
|
|
|
4080
4171
|
z-index: var(--z-index-toast);
|
|
4081
4172
|
max-width: min(22.5rem, calc(100vw - 2 * var(--space-4)));
|
|
4082
4173
|
}
|
|
4174
|
+
/* The font-family is declared here, and it is not decoration: this package sets the family
|
|
4175
|
+
per ROOT — on appshell and on login-view — and never on body, so a box outside both
|
|
4176
|
+
inherits the UA default and renders the platform's confirmations in a serif. The toast
|
|
4177
|
+
viewport is exactly that box. ToastProvider wraps the router rather than living inside a
|
|
4178
|
+
page, and a context provider emits no DOM, so the viewport is a SIBLING of appshell, not a
|
|
4179
|
+
descendant; position: fixed has nothing to do with it, since inheritance follows the tree
|
|
4180
|
+
and not the box. The portalled popover panel already carries this declaration for the same
|
|
4181
|
+
reason and says so; this is the one surface that escaped the shell without it. */
|
|
4083
4182
|
[data-terp="toast"] {
|
|
4084
4183
|
display: grid;
|
|
4085
4184
|
grid-template-columns: auto 1fr auto;
|
|
@@ -4091,6 +4190,7 @@ button[data-terp="input"][data-placeholder="true"] {
|
|
|
4091
4190
|
border-inline-start-width: 3px;
|
|
4092
4191
|
background: var(--color-neutral-0);
|
|
4093
4192
|
color: var(--color-neutral-900);
|
|
4193
|
+
font-family: var(--font-family-sans);
|
|
4094
4194
|
font-size: var(--font-size-sm);
|
|
4095
4195
|
box-shadow: var(--shadow-md);
|
|
4096
4196
|
}
|