@terpjs/react-core 0.25.0 → 0.28.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/README.md +31 -7
- package/package.json +6 -5
- package/src/Field.test.tsx +95 -1
- package/src/Field.tsx +70 -1
- package/src/LoginView.test.tsx +33 -0
- package/src/LoginView.tsx +36 -23
- package/src/Meter.test.tsx +304 -0
- package/src/Meter.tsx +159 -0
- package/src/QuietActions.test.tsx +118 -0
- package/src/QuietActions.tsx +75 -0
- package/src/UserMenu.test.tsx +23 -0
- package/src/UserMenu.tsx +9 -1
- package/src/admin/AuditLogAdmin.tsx +1 -1
- package/src/admin/admin.test.tsx +57 -5
- package/src/admin/module.tsx +9 -6
- package/src/bootstrap.test.tsx +1 -1
- package/src/bootstrap.tsx +2 -1
- package/src/dataview/DataView.test.tsx +70 -0
- package/src/dataview/README.md +5 -3
- package/src/dataview/index.ts +1 -1
- package/src/dataview/internal.tsx +76 -19
- package/src/dataview/types.ts +9 -35
- package/src/errorMessages.test.tsx +21 -0
- package/src/errorMessages.tsx +33 -19
- package/src/index.ts +7 -3
- package/src/locale.test.tsx +35 -0
- package/src/locale.tsx +62 -4
- package/src/markers.test.ts +33 -11
- package/src/ssr.test.tsx +18 -0
- package/src/styles.test.ts +341 -33
- package/src/styles.ts +546 -71
- package/src/testing.test.tsx +162 -0
- package/src/testing.ts +84 -0
- package/src/tokens.guard.test.ts +11 -6
- package/src/ui/controlMessages.tsx +27 -14
- package/src/uiText.literals.test.ts +19 -6
- package/src/uiText.test.tsx +54 -2
- package/src/uiText.tsx +166 -6
- package/vitest.setup.ts +7 -20
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,74 @@ 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
|
+
/**
|
|
56
|
+
* A layer body with every `@media` block removed -- the rules that apply at EVERY width.
|
|
57
|
+
*
|
|
58
|
+
* The complement of {@link mediaBodies}, and it exists for the mistake that helper cannot
|
|
59
|
+
* catch: a plain `indexOf` over the layer finds whichever copy of a selector comes first in
|
|
60
|
+
* the SOURCE, and this sheet declares its one wide-viewport block roughly three thousand
|
|
61
|
+
* lines above the base rules it overrides. So a component with a rule in both halves -- which
|
|
62
|
+
* is every responsive one -- has its base rule silently shadowed by its wide one in any
|
|
63
|
+
* assertion written that way, and the test then reads the wrong body and passes or fails for
|
|
64
|
+
* the wrong reason.
|
|
65
|
+
*/
|
|
66
|
+
function baseOnly(body: string): string {
|
|
67
|
+
let out = "";
|
|
68
|
+
for (let i = 0; i < body.length; i += 1) {
|
|
69
|
+
if (!body.startsWith("@media", i)) {
|
|
70
|
+
out += body[i];
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const first = body.indexOf("{", i);
|
|
74
|
+
let depth = 0;
|
|
75
|
+
for (let j = first; j < body.length; j += 1) {
|
|
76
|
+
if (body[j] === "{") depth += 1;
|
|
77
|
+
else if (body[j] === "}") {
|
|
78
|
+
depth -= 1;
|
|
79
|
+
if (depth === 0) {
|
|
80
|
+
i = j;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function mediaBodies(body: string, query: string): string {
|
|
90
|
+
const opener = `@media ${query} {`;
|
|
91
|
+
const found: string[] = [];
|
|
92
|
+
for (let at = body.indexOf(opener); at !== -1; at = body.indexOf(opener, at + 1)) {
|
|
93
|
+
const first = body.indexOf("{", at);
|
|
94
|
+
let depth = 0;
|
|
95
|
+
for (let i = first; i < body.length; i += 1) {
|
|
96
|
+
if (body[i] === "{") depth += 1;
|
|
97
|
+
else if (body[i] === "}") {
|
|
98
|
+
depth -= 1;
|
|
99
|
+
if (depth === 0) {
|
|
100
|
+
found.push(body.slice(first + 1, i));
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (found.length === 0) throw new Error(`the sheet declares no @media ${query} block`);
|
|
107
|
+
return found.join("\n");
|
|
108
|
+
}
|
|
109
|
+
|
|
42
110
|
/**
|
|
43
111
|
* Whether `body` declares a rule whose selector list contains EXACTLY `selector` — not
|
|
44
112
|
* merely a selector containing it as a substring.
|
|
@@ -947,6 +1015,187 @@ describe("cascade structure", () => {
|
|
|
947
1015
|
expect(base.slice(termAt, base.indexOf("}", termAt))).not.toContain("color:");
|
|
948
1016
|
});
|
|
949
1017
|
|
|
1018
|
+
it("puts an aligned pair on one baseline, in every shape that shares a column", () => {
|
|
1019
|
+
// Reported as the label's text not lining up with the value beside it, and it is a
|
|
1020
|
+
// consequence of the shared column rather than an oversight in it. An aligned row is a
|
|
1021
|
+
// display: contents box, so the dt and the dd are separate grid items -- and grid's
|
|
1022
|
+
// default is stretch, which starts both boxes at the row's top and leaves each text at
|
|
1023
|
+
// the top of its own line box. The two line boxes are not the same height, because the
|
|
1024
|
+
// term is a type step smaller, so the label rides ABOVE the value it labels: measured at
|
|
1025
|
+
// 4px on every row. The one axis a shared label column was not sharing.
|
|
1026
|
+
//
|
|
1027
|
+
// Asserted as an INVARIANT over the contents rules rather than as two literal selectors,
|
|
1028
|
+
// and that is the whole value of the test. A row becomes a grid item in two places -- the
|
|
1029
|
+
// closed counts in the wide block, and columns="auto" in the base, which has no cutover --
|
|
1030
|
+
// and a third would be added the same way. Naming the two would pass a sheet that grew a
|
|
1031
|
+
// third and left its labels riding high in exactly one configuration; this cannot.
|
|
1032
|
+
const base = layerBody("terp.base");
|
|
1033
|
+
const rules = [...base.matchAll(/([^{}]+)\{([^{}]*)\}/g)].map((match) => ({
|
|
1034
|
+
selector: match[1]!.trim().replace(/\s+/g, " "),
|
|
1035
|
+
body: match[2]!,
|
|
1036
|
+
}));
|
|
1037
|
+
const row = ' [data-terp="detail-list-row"]';
|
|
1038
|
+
const contents = rules.filter(
|
|
1039
|
+
(rule) => rule.selector.includes(row) && rule.body.includes("display: contents"),
|
|
1040
|
+
);
|
|
1041
|
+
expect(
|
|
1042
|
+
contents.length,
|
|
1043
|
+
"the shared column exists where a row is a contents box; find those rules",
|
|
1044
|
+
).toBe(2);
|
|
1045
|
+
for (const rule of contents) {
|
|
1046
|
+
// The list the rule belongs to, which is the grid whose items those dt and dd become,
|
|
1047
|
+
// and therefore the only box an align-items can be declared on.
|
|
1048
|
+
const list = rule.selector.slice(0, rule.selector.indexOf(row));
|
|
1049
|
+
const owner = rules.filter((candidate) => candidate.selector === list);
|
|
1050
|
+
expect(owner.length, `${list} should have a rule of its own`).toBeGreaterThan(0);
|
|
1051
|
+
expect(
|
|
1052
|
+
owner.some((candidate) => candidate.body.includes("align-items: baseline")),
|
|
1053
|
+
`${list} makes its rows contents boxes, so it owes its pairs a baseline`,
|
|
1054
|
+
).toBe(true);
|
|
1055
|
+
}
|
|
1056
|
+
});
|
|
1057
|
+
|
|
1058
|
+
it("keeps a DetailList pair one type step apart, on the table's own two steps", () => {
|
|
1059
|
+
// The other half of the same report: the value read too big for its label. Muting the term
|
|
1060
|
+
// moved one half of the pair to xs and left the other at the inherited base -- 12px against
|
|
1061
|
+
// 16px, two steps, far enough apart that a reader sees two kinds of text rather than a
|
|
1062
|
+
// label and the thing it labels.
|
|
1063
|
+
//
|
|
1064
|
+
// The steps are asserted against DataView's, not against literals, because that is the
|
|
1065
|
+
// actual claim: a header cell and a body cell ARE this pair in a table, so a detail list
|
|
1066
|
+
// beside a table on the same page must not render a step larger than the record it
|
|
1067
|
+
// describes. Written as a comparison, the two surfaces cannot drift apart silently -- and
|
|
1068
|
+
// a literal pair of tokens here would have let either side move alone.
|
|
1069
|
+
const base = layerBody("terp.base");
|
|
1070
|
+
const sizeOf = (selector: string) => {
|
|
1071
|
+
const at = base.indexOf(selector);
|
|
1072
|
+
expect(at, `${selector} should exist`).toBeGreaterThan(-1);
|
|
1073
|
+
return /font-size:\s*([^;]+);/.exec(base.slice(at, base.indexOf("}", at)))?.[1]?.trim();
|
|
1074
|
+
};
|
|
1075
|
+
const headerStep = sizeOf('[data-terp="dataview-table"] > thead > tr > th {');
|
|
1076
|
+
const cellStep = sizeOf('[data-terp="dataview-row"] > td {');
|
|
1077
|
+
expect(headerStep, "a table labels its columns at one step").toBeTruthy();
|
|
1078
|
+
expect(cellStep, "and holds the values at another").toBeTruthy();
|
|
1079
|
+
expect(headerStep, "and the two are not the same step, or there is no pair").not.toBe(
|
|
1080
|
+
cellStep,
|
|
1081
|
+
);
|
|
1082
|
+
|
|
1083
|
+
// One rule per half, over both non-inline layouts and neither sentence. inline is excluded
|
|
1084
|
+
// for the reason the muting rule above is: there the value is the second half of a sentence
|
|
1085
|
+
// whose first half is the term, so stepping one half down breaks the line rather than
|
|
1086
|
+
// grouping it.
|
|
1087
|
+
//
|
|
1088
|
+
// Found by parsing rather than by index, and the difference is not cosmetic: the term
|
|
1089
|
+
// selector opens TWO rules in this sheet -- this one and the display: block rule above it
|
|
1090
|
+
// -- so an indexOf lands on whichever comes first and reads a body with no font-size in it
|
|
1091
|
+
// at all, which is an undefined that compares unequal to everything and passes nothing.
|
|
1092
|
+
const rules = [...base.matchAll(/([^{}]+)\{([^{}]*)\}/g)].map((match) => ({
|
|
1093
|
+
selectors: match[1]!.split(",").map((part) => part.trim().replace(/\s+/g, " ")),
|
|
1094
|
+
body: match[2]!,
|
|
1095
|
+
}));
|
|
1096
|
+
const half = (marker: string) =>
|
|
1097
|
+
rules.filter(
|
|
1098
|
+
(rule) =>
|
|
1099
|
+
rule.selectors.some((selector) => selector.includes(marker)) &&
|
|
1100
|
+
rule.body.includes("font-size"),
|
|
1101
|
+
);
|
|
1102
|
+
|
|
1103
|
+
const value = half('[data-terp="detail-list-value"]');
|
|
1104
|
+
expect(value, "one shared rule sizes the value, not one per layout").toHaveLength(1);
|
|
1105
|
+
expect(value[0]!.selectors).toEqual([
|
|
1106
|
+
'[data-terp="detail-list"][data-layout="aligned"] [data-terp="detail-list-value"]',
|
|
1107
|
+
'[data-terp="detail-list"][data-layout="stacked"] [data-terp="detail-list-value"]',
|
|
1108
|
+
]);
|
|
1109
|
+
expect(value[0]!.body, "the value takes the table body cell's step").toContain(cellStep!);
|
|
1110
|
+
|
|
1111
|
+
const term = half('[data-terp="detail-list-term"]');
|
|
1112
|
+
expect(term, "and one sizes the label").toHaveLength(1);
|
|
1113
|
+
expect(term[0]!.selectors).toEqual([
|
|
1114
|
+
'[data-terp="detail-list"][data-layout="aligned"] [data-terp="detail-list-term"]',
|
|
1115
|
+
'[data-terp="detail-list"][data-layout="stacked"] [data-terp="detail-list-term"]',
|
|
1116
|
+
]);
|
|
1117
|
+
expect(term[0]!.body, "at the table header cell's step").toContain(headerStep!);
|
|
1118
|
+
});
|
|
1119
|
+
|
|
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.
|
|
1125
|
+
//
|
|
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.
|
|
1130
|
+
const wide = mediaBodies(layerBody("terp.base"), WIDE_VIEWPORT_QUERY);
|
|
1131
|
+
const subgrid = /\[data-terp="field-row"\] > \[data-terp="field"\] \{([^}]*)\}/.exec(wide);
|
|
1132
|
+
expect(subgrid, "each field subgrids the row").not.toBeNull();
|
|
1133
|
+
expect(subgrid![1]).toContain("grid-template-rows: subgrid");
|
|
1134
|
+
expect(subgrid![1], "and spans every line, or it subgrids one of them").toContain(
|
|
1135
|
+
"grid-row: 1 / -1",
|
|
1136
|
+
);
|
|
1137
|
+
expect(wide, "the row owns three lines for them to share").toContain(
|
|
1138
|
+
"grid-template-rows: auto auto auto",
|
|
1139
|
+
);
|
|
1140
|
+
expect(
|
|
1141
|
+
wide.replace(/\s+/g, " "),
|
|
1142
|
+
"the label generates no box, or the text and the control share one line",
|
|
1143
|
+
).toContain(
|
|
1144
|
+
'[data-terp="field-row"] > [data-terp="field"] > [data-terp="field-label"] { display: contents; }',
|
|
1145
|
+
);
|
|
1146
|
+
expect(
|
|
1147
|
+
wide.replace(/\s+/g, " "),
|
|
1148
|
+
"and a child that is not a field lands on the control line",
|
|
1149
|
+
).toContain('[data-terp="field-row"] > :not([data-terp="field"]) { grid-row: 2; }');
|
|
1150
|
+
|
|
1151
|
+
// The narrow shape is the BASE rule, mobile-first: one column, no subgrid, nothing to
|
|
1152
|
+
// align. Declared this way round because three controls and an action do not fit a
|
|
1153
|
+
// phone at any gap -- so the base must not carry the wide block's tracks, or a phone
|
|
1154
|
+
// gets them with no query to take them away again.
|
|
1155
|
+
const base = baseOnly(layerBody("terp.base"));
|
|
1156
|
+
const rowAt = base.indexOf('[data-terp="field-row"] {');
|
|
1157
|
+
expect(rowAt, "the row should have a base rule").toBeGreaterThan(-1);
|
|
1158
|
+
const narrow = base.slice(rowAt, base.indexOf("}", rowAt));
|
|
1159
|
+
expect(narrow, "the narrow shape lays out no columns").not.toContain("grid-auto-flow");
|
|
1160
|
+
expect(narrow, "and shares no lines").not.toContain("subgrid");
|
|
1161
|
+
});
|
|
1162
|
+
|
|
1163
|
+
it("keeps a field row's row-gap on the row and off its fields", () => {
|
|
1164
|
+
// A subgrid takes its parent's gutters unless it declares its own. A field that
|
|
1165
|
+
// declared one would space its OWN three lines while the row's other tracks kept the
|
|
1166
|
+
// parent's -- so a bare button, which is not a subgrid, sat 2px above every control on
|
|
1167
|
+
// the row. Measured; it reads as a button that is almost aligned, which is harder to
|
|
1168
|
+
// see than one that obviously is not.
|
|
1169
|
+
//
|
|
1170
|
+
// The gap prop is column-only for the matching reason: the row gap IS each field's
|
|
1171
|
+
// internal label-to-control measure, shared by every field on the row, so a caller
|
|
1172
|
+
// moving it from outside would be reaching into all of them at once.
|
|
1173
|
+
const full = layerBody("terp.base");
|
|
1174
|
+
const base = baseOnly(full);
|
|
1175
|
+
const rowAt = base.indexOf('[data-terp="field-row"] {');
|
|
1176
|
+
expect(rowAt, "the row should have a base rule").toBeGreaterThan(-1);
|
|
1177
|
+
expect(base.slice(rowAt, base.indexOf("}", rowAt))).toContain("row-gap:");
|
|
1178
|
+
|
|
1179
|
+
const wide = mediaBodies(full, WIDE_VIEWPORT_QUERY);
|
|
1180
|
+
const subgrid = /\[data-terp="field-row"\] > \[data-terp="field"\] \{([^}]*)\}/.exec(wide);
|
|
1181
|
+
expect(
|
|
1182
|
+
subgrid![1],
|
|
1183
|
+
"a field must inherit the row's gutters, not declare its own",
|
|
1184
|
+
).not.toContain("row-gap");
|
|
1185
|
+
|
|
1186
|
+
for (const token of [0, 1, 2, 3, 4, 6, 8]) {
|
|
1187
|
+
const rule = `[data-terp="field-row"][data-gap="${token}"]`;
|
|
1188
|
+
const at = base.indexOf(rule);
|
|
1189
|
+
expect(at, `field-row has no rule for gap ${token}`).toBeGreaterThan(-1);
|
|
1190
|
+
const body = base.slice(at, base.indexOf("}", at));
|
|
1191
|
+
expect(body, `gap ${token} sets the column gap`).toContain("column-gap:");
|
|
1192
|
+
expect(body, `gap ${token} must not touch the shared row gap`).not.toContain("row-gap:");
|
|
1193
|
+
expect(at, `gap ${token} must be declared after the base rule it overrides`).toBeGreaterThan(
|
|
1194
|
+
rowAt,
|
|
1195
|
+
);
|
|
1196
|
+
}
|
|
1197
|
+
});
|
|
1198
|
+
|
|
950
1199
|
it("gives body copy an emphasis step without re-weighting the copy that asks for none", () => {
|
|
951
1200
|
const base = layerBody("terp.base");
|
|
952
1201
|
// Both steps read the published weight tokens rather than a literal.
|
|
@@ -1033,29 +1282,52 @@ describe("cascade structure", () => {
|
|
|
1033
1282
|
expect(header, "with nothing else to show, the band is one row").toContain(
|
|
1034
1283
|
'grid-template-areas: "trail actions"',
|
|
1035
1284
|
);
|
|
1036
|
-
// The second row
|
|
1037
|
-
//
|
|
1038
|
-
//
|
|
1039
|
-
//
|
|
1040
|
-
//
|
|
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.
|
|
1041
1296
|
const metaAt = base.indexOf('[data-terp="page-header"][data-has-meta] {');
|
|
1042
1297
|
expect(metaAt, "the two-row band should have a rule of its own").toBeGreaterThan(-1);
|
|
1043
1298
|
const withMeta = base.slice(metaAt, base.indexOf("}", metaAt));
|
|
1044
|
-
|
|
1045
|
-
|
|
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",
|
|
1306
|
+
);
|
|
1307
|
+
// The areas move per cutover, so they are pinned in their own queries rather than here.
|
|
1308
|
+
const wideMeta = mediaBodies(base, WIDE_VIEWPORT_QUERY);
|
|
1309
|
+
expect(wideMeta, "above the cutover the cluster keeps its place beside the trail").toContain(
|
|
1310
|
+
'"trail actions"',
|
|
1311
|
+
);
|
|
1312
|
+
expect(wideMeta, "meta takes the row under them, spanning both columns").toContain(
|
|
1313
|
+
'"meta meta"',
|
|
1046
1314
|
);
|
|
1047
|
-
|
|
1048
|
-
|
|
1315
|
+
const narrowBand = mediaBodies(base, NARROW_VIEWPORT);
|
|
1316
|
+
expect(narrowBand, "below the cutover the band is a single column").toContain(
|
|
1317
|
+
"grid-template-columns: minmax(0, 1fr)",
|
|
1049
1318
|
);
|
|
1050
|
-
//
|
|
1051
|
-
//
|
|
1052
|
-
//
|
|
1053
|
-
//
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1319
|
+
// The trail sheds its ancestors rather than its characters. Every crumb carries
|
|
1320
|
+
// min-width: 0 and an ellipsis while the separators are flex: 0 0 auto, so a trail with no
|
|
1321
|
+
// room degrades to bare chevrons -- measured at 360px on six crumbs: six labels under 8px
|
|
1322
|
+
// and no h1 on screen at all. Dropping the ancestors takes their separators with them.
|
|
1323
|
+
expect(narrowBand, "the narrow trail keeps the leaf and one ancestor").toContain(
|
|
1324
|
+
"li:not(:last-child):not(:nth-last-child(2))",
|
|
1325
|
+
);
|
|
1326
|
+
// The actions row is declared only where there is a cluster to put in it: a named row with
|
|
1327
|
+
// nothing in it is still a row, and the band's gap under it is 8px wedged beneath the
|
|
1328
|
+
// trail on every page with no actions.
|
|
1329
|
+
expect(narrowBand, "an actions row with no cluster is 8px of nothing").toContain(
|
|
1330
|
+
'[data-terp="page-header"]:has(> [data-terp="page-actions"])',
|
|
1059
1331
|
);
|
|
1060
1332
|
// The left group generates no box, which is what lets its two children be grid items of
|
|
1061
1333
|
// the BAND and therefore sit on different rows. The marker survives for the scanner.
|
|
@@ -1086,30 +1358,37 @@ describe("cascade structure", () => {
|
|
|
1086
1358
|
expect(full).toContain("text-overflow: ellipsis");
|
|
1087
1359
|
});
|
|
1088
1360
|
|
|
1089
|
-
it("gives the breadcrumb trail one line box, leaf
|
|
1361
|
+
it("gives the breadcrumb trail one line box, and the leaf the step its own size needs", () => {
|
|
1090
1362
|
// The trail is a row of items that get CENTRED, so two line heights in it are two
|
|
1091
1363
|
// baselines. The leaf declared 1.3 while its ancestors inherited `normal`: measured at
|
|
1092
1364
|
// font-size-sm, a 19.00px ancestor line box against an 18.19px leaf, which left the
|
|
1093
1365
|
// page's own title 0.59px above the crumb it hangs off with the chevron centred on a
|
|
1094
|
-
// third line. One declaration on the trail, inherited by every crumb
|
|
1095
|
-
//
|
|
1366
|
+
// third line. One declaration on the trail, inherited by every crumb, is what makes the
|
|
1367
|
+
// ancestors share a baseline.
|
|
1096
1368
|
//
|
|
1097
1369
|
// The published step rather than a bare literal, and that is the second half of the fix
|
|
1098
1370
|
// rather than house style: `normal` is the FONT's metric, so the mismatch was as big as
|
|
1099
1371
|
// the app's typeface said it was, and an app on a webfont with taller natural leading got
|
|
1100
1372
|
// a worse one than the system stack this was measured in.
|
|
1373
|
+
//
|
|
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.
|
|
1101
1380
|
const base = layerBody("terp.base");
|
|
1102
1381
|
const trail = base.slice(base.indexOf('[data-terp="breadcrumbs"] {'));
|
|
1103
1382
|
expect(
|
|
1104
1383
|
trail.slice(0, trail.indexOf("}")),
|
|
1105
|
-
"the trail declares the line box every crumb shares",
|
|
1384
|
+
"the trail declares the line box every ancestor crumb shares",
|
|
1106
1385
|
).toContain("line-height: var(--font-line-height-snug)");
|
|
1107
1386
|
const leafAt = base.indexOf('[data-terp="page-title"] {');
|
|
1108
1387
|
expect(leafAt, "the trail's leaf should have a rule").toBeGreaterThan(-1);
|
|
1109
1388
|
expect(
|
|
1110
1389
|
base.slice(leafAt, base.indexOf("}", leafAt)),
|
|
1111
|
-
"the leaf
|
|
1112
|
-
).
|
|
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)");
|
|
1113
1392
|
});
|
|
1114
1393
|
|
|
1115
1394
|
it("spans a full row across every track, and makes it a box that can", () => {
|
|
@@ -1265,14 +1544,16 @@ describe("cascade structure", () => {
|
|
|
1265
1544
|
// one published scale rather than four sizes that happen to differ.
|
|
1266
1545
|
const base = layerBody("terp.base");
|
|
1267
1546
|
for (const [selector, step] of [
|
|
1268
|
-
// page-title
|
|
1269
|
-
//
|
|
1270
|
-
//
|
|
1271
|
-
//
|
|
1272
|
-
//
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
//
|
|
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.
|
|
1276
1557
|
['[data-terp="heading"][data-size="xl"]', "xl"],
|
|
1277
1558
|
['[data-terp="card-title"]', "lg"],
|
|
1278
1559
|
['[data-terp="card-description"]', "sm"],
|
|
@@ -1763,6 +2044,26 @@ describe("cascade structure", () => {
|
|
|
1763
2044
|
expect(rule![2]!.trim()).toBe("display: contents;");
|
|
1764
2045
|
});
|
|
1765
2046
|
|
|
2047
|
+
it("keeps the parts the conformance helpers find by name boxless", () => {
|
|
2048
|
+
// Four wrappers exist only so a locale-agnostic caller can find the login controls and
|
|
2049
|
+
// sign-out by marker. They must not become layout: login-form and the menu are grids that
|
|
2050
|
+
// space their children with `gap`, and a boxed wrapper would make itself the grid item
|
|
2051
|
+
// instead of the field or the item it names. So each rule is display: contents and nothing
|
|
2052
|
+
// else — a second declaration would be silently dropped on a contents box anyway.
|
|
2053
|
+
const base = layerBody("terp.base");
|
|
2054
|
+
for (const marker of ["login-email", "login-password", "login-submit", "user-menu-sign-out"]) {
|
|
2055
|
+
const selector = `[data-terp="${marker}"]`;
|
|
2056
|
+
const rule = [...base.matchAll(/([^{}]+)\{([^{}]*)\}/g)].find((match) =>
|
|
2057
|
+
match[1]!
|
|
2058
|
+
.split(",")
|
|
2059
|
+
.map((part) => part.trim())
|
|
2060
|
+
.includes(selector),
|
|
2061
|
+
);
|
|
2062
|
+
expect(rule, `no rule names ${selector} in terp.base`).toBeDefined();
|
|
2063
|
+
expect(rule![2]!.trim(), `${selector} must stay a boxless name`).toBe("display: contents;");
|
|
2064
|
+
}
|
|
2065
|
+
});
|
|
2066
|
+
|
|
1766
2067
|
it("pins the values of five declarations no lane can reach", () => {
|
|
1767
2068
|
// Presence is not enough for these five, and that is the distinction the roll-calls above
|
|
1768
2069
|
// already draw for Button sizes and gap steps: a rule can be present and WRONG, and nothing
|
|
@@ -1810,6 +2111,9 @@ describe("cascade structure", () => {
|
|
|
1810
2111
|
"badge",
|
|
1811
2112
|
"alert",
|
|
1812
2113
|
"tooltip",
|
|
2114
|
+
"meter",
|
|
2115
|
+
"meter-bar",
|
|
2116
|
+
"meter-value",
|
|
1813
2117
|
"input",
|
|
1814
2118
|
"input-password",
|
|
1815
2119
|
"field",
|
|
@@ -1958,6 +2262,10 @@ describe("cascade structure", () => {
|
|
|
1958
2262
|
"login-separator",
|
|
1959
2263
|
"login-separator-rule",
|
|
1960
2264
|
"login-error",
|
|
2265
|
+
"login-email",
|
|
2266
|
+
"login-password",
|
|
2267
|
+
"login-submit",
|
|
2268
|
+
"user-menu-sign-out",
|
|
1961
2269
|
"admin-form",
|
|
1962
2270
|
"admin-section-title",
|
|
1963
2271
|
"grid",
|