@terpjs/react-core 0.27.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 +4 -3
- 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 +265 -14
- package/src/styles.ts +424 -49
- 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/index.ts
CHANGED
|
@@ -108,7 +108,7 @@ export { EmptyState } from "./EmptyState";
|
|
|
108
108
|
export type { EmptyStateProps } from "./EmptyState";
|
|
109
109
|
export { ErrorState, describeError } from "./ErrorState";
|
|
110
110
|
export type { ErrorStateProps } from "./ErrorState";
|
|
111
|
-
export { ErrorMessagesProvider, useErrorMessage
|
|
111
|
+
export { ErrorMessagesProvider, useErrorMessage } from "./errorMessages";
|
|
112
112
|
export type { ErrorMessages, ErrorMessagesProviderProps } from "./errorMessages";
|
|
113
113
|
export { ConfirmDialog } from "./ConfirmDialog";
|
|
114
114
|
export { Disclosure } from "./Disclosure";
|
|
@@ -175,8 +175,12 @@ export type {
|
|
|
175
175
|
CodeProps,
|
|
176
176
|
LinkProps,
|
|
177
177
|
} from "./typography";
|
|
178
|
-
export { Field } from "./Field";
|
|
179
|
-
export
|
|
178
|
+
export { Field, FieldRow } from "./Field";
|
|
179
|
+
export { QuietActions } from "./QuietActions";
|
|
180
|
+
export { Meter } from "./Meter";
|
|
181
|
+
export type { FieldProps, FieldRowProps } from "./Field";
|
|
182
|
+
export type { QuietActionsProps } from "./QuietActions";
|
|
183
|
+
export type { MeterProps } from "./Meter";
|
|
180
184
|
export { Stack, Grid, Divider, DetailList, DetailListGroup } from "./layout";
|
|
181
185
|
export type {
|
|
182
186
|
StackProps,
|
package/src/locale.test.tsx
CHANGED
|
@@ -15,6 +15,7 @@ import { DEFAULT_STRINGS, Trans, useStrings } from "./uiText";
|
|
|
15
15
|
afterEach(() => {
|
|
16
16
|
cleanup();
|
|
17
17
|
window.localStorage.clear();
|
|
18
|
+
document.documentElement.removeAttribute("lang");
|
|
18
19
|
});
|
|
19
20
|
|
|
20
21
|
function SignOutLabel() {
|
|
@@ -265,6 +266,40 @@ describe("LocaleProvider + LanguageSwitcher", () => {
|
|
|
265
266
|
).toEqual({ greeting: "Hallo" });
|
|
266
267
|
});
|
|
267
268
|
|
|
269
|
+
it("keeps <html lang> on the active locale, from mount and across a switch", () => {
|
|
270
|
+
// A value neither locale has, so the assertion can only pass if the provider wrote it:
|
|
271
|
+
// starting from "en" would let an effect that never ran pass the English half.
|
|
272
|
+
document.documentElement.lang = "x-stale";
|
|
273
|
+
render(
|
|
274
|
+
<LocaleProvider locales={{ en: LOCALE_EN, nl: NL }} defaultLocale="nl">
|
|
275
|
+
<LanguageSwitcher />
|
|
276
|
+
</LocaleProvider>,
|
|
277
|
+
);
|
|
278
|
+
expect(document.documentElement.lang).toBe("nl");
|
|
279
|
+
|
|
280
|
+
fireEvent.click(screen.getByRole("button", { name: "Taal" }));
|
|
281
|
+
fireEvent.click(screen.getByRole("menuitemradio", { name: "English" }));
|
|
282
|
+
expect(document.documentElement.lang).toBe("en");
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it("refuses a catalog that translates the shell but not DataView", () => {
|
|
286
|
+
// The upgrade path, pinned: a catalog complete against the key set before DataView's
|
|
287
|
+
// strings joined it. Refused, and by name, because the alternative is the defect itself —
|
|
288
|
+
// every table in the app back in English under a locale that claims to be complete.
|
|
289
|
+
const shellOnly = Object.fromEntries(
|
|
290
|
+
Object.keys(DEFAULT_STRINGS)
|
|
291
|
+
.filter((key) => !key.startsWith("dataView"))
|
|
292
|
+
.map((key) => [key, `de:${key}`]),
|
|
293
|
+
);
|
|
294
|
+
expect(() =>
|
|
295
|
+
render(
|
|
296
|
+
<LocaleProvider locales={{ en: LOCALE_EN, de: { strings: shellOnly } }}>
|
|
297
|
+
<span />
|
|
298
|
+
</LocaleProvider>,
|
|
299
|
+
),
|
|
300
|
+
).toThrow(/missing .* framework string translation.*dataViewSearchPlaceholder/);
|
|
301
|
+
});
|
|
302
|
+
|
|
268
303
|
it("always renders the descriptor fallback in the source locale", () => {
|
|
269
304
|
render(
|
|
270
305
|
<LocaleProvider
|
package/src/locale.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createContext, useCallback, useContext, useMemo, useState } from "react";
|
|
1
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react";
|
|
2
2
|
import type { ReactNode } from "react";
|
|
3
3
|
import type { UiText } from "@terpjs/contract";
|
|
4
4
|
|
|
@@ -154,9 +154,12 @@ export function defineAppLocales(
|
|
|
154
154
|
export const LOCALE_EN: LocaleCatalog = { label: "English" };
|
|
155
155
|
|
|
156
156
|
/**
|
|
157
|
-
* The built-in Dutch catalog: a
|
|
158
|
-
*
|
|
159
|
-
*
|
|
157
|
+
* The built-in Dutch catalog: a translation of every `TerpStrings` key, so
|
|
158
|
+
* `locales: { en: LOCALE_EN, nl: LOCALE_NL }` translates every string react-core
|
|
159
|
+
* reads from that table — the shell, the packaged admin area and its sidebar
|
|
160
|
+
* entry, every `DataView`'s toolbar and footer, and the wording for the platform's
|
|
161
|
+
* own error codes — with no catalog work in the app (a completeness test pins it to
|
|
162
|
+
* the `TerpStrings` key set).
|
|
160
163
|
*/
|
|
161
164
|
export const LOCALE_NL: LocaleCatalog = {
|
|
162
165
|
label: "Nederlands",
|
|
@@ -294,8 +297,51 @@ export const LOCALE_NL: LocaleCatalog = {
|
|
|
294
297
|
targetColumn: "Doel",
|
|
295
298
|
whenColumn: "Wanneer",
|
|
296
299
|
details: "Details",
|
|
300
|
+
requestLabel: "Verzoek",
|
|
297
301
|
saved: "Opgeslagen",
|
|
298
302
|
requestFailed: "Het verzoek is mislukt. Probeer opnieuw.",
|
|
303
|
+
dataViewSearchPlaceholder: "Zoeken…",
|
|
304
|
+
dataViewClearSearch: "Zoekopdracht wissen",
|
|
305
|
+
dataViewClearFilters: "Filters wissen",
|
|
306
|
+
dataViewViewOptions: "Weergaveopties",
|
|
307
|
+
dataViewColumns: "Kolommen",
|
|
308
|
+
dataViewMoveUp: "Omhoog verplaatsen",
|
|
309
|
+
dataViewMoveDown: "Omlaag verplaatsen",
|
|
310
|
+
dataViewTableView: "Tabelweergave",
|
|
311
|
+
dataViewCardView: "Kaartweergave",
|
|
312
|
+
dataViewPageSize: "Rijen per pagina",
|
|
313
|
+
dataViewResultsRange: "{from}–{to} van {total} resultaten",
|
|
314
|
+
dataViewPageOf: "Pagina {page} van {pages}",
|
|
315
|
+
dataViewFirstPage: "Eerste pagina",
|
|
316
|
+
dataViewPreviousPage: "Vorige pagina",
|
|
317
|
+
dataViewNextPage: "Volgende pagina",
|
|
318
|
+
dataViewLastPage: "Laatste pagina",
|
|
319
|
+
dataViewSelectAllPage: "Alle rijen op deze pagina selecteren",
|
|
320
|
+
dataViewSelectRow: "Rij selecteren",
|
|
321
|
+
dataViewSelected: "{count} geselecteerd",
|
|
322
|
+
dataViewSelectAllResults: "Alle {total} resultaten selecteren",
|
|
323
|
+
dataViewClearSelection: "Selectie wissen",
|
|
324
|
+
dataViewMoreActions: "Meer acties",
|
|
325
|
+
dataViewActions: "Acties",
|
|
326
|
+
dataViewOpenRow: "Details openen: {label}",
|
|
327
|
+
dataViewExpandRow: "Rij uitklappen",
|
|
328
|
+
dataViewCollapseRow: "Rij inklappen",
|
|
329
|
+
dataViewEmpty: "Niets om te tonen.",
|
|
330
|
+
dataViewLoading: "Laden…",
|
|
331
|
+
dataViewRefreshing: "Bijwerken…",
|
|
332
|
+
dataViewErrorTitle: "De gegevens konden niet worden geladen.",
|
|
333
|
+
dataViewResizeColumn: "Kolombreedte aanpassen",
|
|
334
|
+
errorCodeBadRequest: "Het verzoek kon niet worden verwerkt.",
|
|
335
|
+
errorCodeValidationFailed:
|
|
336
|
+
"Sommige velden zijn ongeldig. Controleer het formulier en probeer het opnieuw.",
|
|
337
|
+
errorCodeInvalidToken: "Je sessie is ongeldig. Log opnieuw in.",
|
|
338
|
+
errorCodeAuthenticationRequired: "Log in om verder te gaan.",
|
|
339
|
+
errorCodePermissionDenied: "Je hebt geen toestemming om dit te doen.",
|
|
340
|
+
errorCodeNotFound: "Dit item kon niet worden gevonden.",
|
|
341
|
+
errorCodeConflict:
|
|
342
|
+
"Dit botst met de huidige stand van zaken. Vernieuw de pagina en probeer het opnieuw.",
|
|
343
|
+
errorCodeStaleData:
|
|
344
|
+
"Iemand anders heeft dit item intussen gewijzigd. Vernieuw de pagina en probeer het opnieuw.",
|
|
299
345
|
},
|
|
300
346
|
};
|
|
301
347
|
|
|
@@ -326,6 +372,7 @@ export interface LocaleProviderProps {
|
|
|
326
372
|
* the choice in `localStorage`, and feeds the active catalog's string overrides to the
|
|
327
373
|
* `UiText` context — so every react-core component (and every `UiText` prop) follows the
|
|
328
374
|
* switch with no per-component wiring. Adding a language to an app is one catalog entry.
|
|
375
|
+
* It also keeps `<html lang>` on the active locale, from mount and across every switch.
|
|
329
376
|
*/
|
|
330
377
|
export function LocaleProvider({
|
|
331
378
|
locales,
|
|
@@ -351,6 +398,17 @@ export function LocaleProvider({
|
|
|
351
398
|
});
|
|
352
399
|
const activeLocale = codes.includes(locale) ? locale : fallback;
|
|
353
400
|
|
|
401
|
+
// The document says which language it is in, and it has to be the language on screen.
|
|
402
|
+
// `index.html` can only declare the default; a reader who picked another one, or a stored
|
|
403
|
+
// choice from an earlier visit, would otherwise have a Dutch interface announced to a screen
|
|
404
|
+
// reader as English and read aloud with English pronunciation throughout (WCAG 3.1.1). An
|
|
405
|
+
// effect rather than a write during render, because an effect never runs on the server:
|
|
406
|
+
// there is no `document` there, and `ssr.test.tsx` renders this provider without one to hold
|
|
407
|
+
// that.
|
|
408
|
+
useEffect(() => {
|
|
409
|
+
document.documentElement.lang = activeLocale;
|
|
410
|
+
}, [activeLocale]);
|
|
411
|
+
|
|
354
412
|
const setLocale = useCallback(
|
|
355
413
|
(next: string) => {
|
|
356
414
|
if (!codes.includes(next)) {
|
package/src/markers.test.ts
CHANGED
|
@@ -161,6 +161,8 @@ const MARKERS = [
|
|
|
161
161
|
"field-hint",
|
|
162
162
|
"field-label",
|
|
163
163
|
"field-label-text",
|
|
164
|
+
"field-messages",
|
|
165
|
+
"field-row",
|
|
164
166
|
"grid",
|
|
165
167
|
"heading",
|
|
166
168
|
"hubcard",
|
|
@@ -183,11 +185,14 @@ const MARKERS = [
|
|
|
183
185
|
"loading-state-spinner",
|
|
184
186
|
"login-brand",
|
|
185
187
|
"login-card",
|
|
188
|
+
"login-email",
|
|
186
189
|
"login-error",
|
|
187
190
|
"login-form",
|
|
191
|
+
"login-password",
|
|
188
192
|
"login-separator",
|
|
189
193
|
"login-separator-rule",
|
|
190
194
|
"login-sso",
|
|
195
|
+
"login-submit",
|
|
191
196
|
"login-title",
|
|
192
197
|
"login-view",
|
|
193
198
|
"markdown",
|
|
@@ -196,6 +201,9 @@ const MARKERS = [
|
|
|
196
201
|
"menu-item-check",
|
|
197
202
|
"menu-item-icon",
|
|
198
203
|
"menu-trigger",
|
|
204
|
+
"meter",
|
|
205
|
+
"meter-bar",
|
|
206
|
+
"meter-value",
|
|
199
207
|
"module-nav",
|
|
200
208
|
"module-nav-link",
|
|
201
209
|
"module-nav-list",
|
|
@@ -214,6 +222,8 @@ const MARKERS = [
|
|
|
214
222
|
"profile-card",
|
|
215
223
|
"profile-email",
|
|
216
224
|
"profile-role",
|
|
225
|
+
"quiet-actions",
|
|
226
|
+
"quiet-actions-slot",
|
|
217
227
|
"radio",
|
|
218
228
|
"radio-group",
|
|
219
229
|
"radio-group-legend",
|
|
@@ -254,6 +264,7 @@ const MARKERS = [
|
|
|
254
264
|
"user-menu-header",
|
|
255
265
|
"user-menu-identity",
|
|
256
266
|
"user-menu-role",
|
|
267
|
+
"user-menu-sign-out",
|
|
257
268
|
];
|
|
258
269
|
|
|
259
270
|
/**
|
|
@@ -572,20 +583,31 @@ describe("data-terp markers", () => {
|
|
|
572
583
|
|
|
573
584
|
it("injects the sheet from every module that owns a rule, or is reachable from one that does", () => {
|
|
574
585
|
// Twelve marker-rendering modules never call injectTerpStyles and do not need to: the
|
|
575
|
-
// package publishes ONE entry point and declares no `sideEffects`, so
|
|
576
|
-
// from it loads every module and two dozen of them inject. That
|
|
577
|
-
// property, and nothing asserted it — a `sideEffects: false`
|
|
578
|
-
// tree-shaking, would remove it silently and the first
|
|
579
|
-
// collapsing into one grid item. So the property
|
|
580
|
-
//
|
|
581
|
-
//
|
|
582
|
-
//
|
|
583
|
-
//
|
|
584
|
-
//
|
|
586
|
+
// package publishes ONE entry point into its modules and declares no `sideEffects`, so
|
|
587
|
+
// importing anything from it loads every module and two dozen of them inject. That
|
|
588
|
+
// guarantee is a packaging property, and nothing asserted it — a `sideEffects: false`
|
|
589
|
+
// added for bundle size, plus tree-shaking, would remove it silently and the first
|
|
590
|
+
// symptom would be Markdown's blocks collapsing into one grid item. So the property
|
|
591
|
+
// itself is what this pins.
|
|
592
|
+
// One way into this package's MODULES, which is the property. Two kinds of subpath do not
|
|
593
|
+
// weaken it. Data: `./layout.manifest.json` is JSON a tool reads out of node_modules, no
|
|
594
|
+
// module imports it, and importing JSON loads no JavaScript at all. And a code subpath that
|
|
595
|
+
// imports nothing from this package — `./testing`, the test-setup polyfill (ADR 0155) —
|
|
596
|
+
// loads no component and no rule, so it cannot render anything without the sheet. Asserted
|
|
597
|
+
// by what each further code entry imports rather than by key count, so that publishing a
|
|
598
|
+
// second way into the components is what fails, and a self-contained module is not.
|
|
585
599
|
const codeEntries = Object.entries(manifest.exports).filter(([, target]) =>
|
|
586
600
|
/\.(ts|tsx|js|mjs|cjs)$/.test(target),
|
|
587
601
|
);
|
|
588
|
-
expect(codeEntries)
|
|
602
|
+
expect(Object.fromEntries(codeEntries)["."]).toBe("./src/index.ts");
|
|
603
|
+
for (const [subpath, target] of codeEntries.filter(([key]) => key !== ".")) {
|
|
604
|
+
const text = sources[target.replace(/^\.\/src\//, "./")];
|
|
605
|
+
expect(text, `${subpath} points at ${target}, not a module in src/`).toBeDefined();
|
|
606
|
+
expect(
|
|
607
|
+
stripComments(text ?? ""),
|
|
608
|
+
`${subpath} imports from this package, which makes it a second way into its modules`,
|
|
609
|
+
).not.toMatch(/(?:from|import)\s*\(?\s*["']\.{1,2}\//);
|
|
610
|
+
}
|
|
589
611
|
expect(
|
|
590
612
|
"sideEffects" in manifest,
|
|
591
613
|
"declaring sideEffects would let a bundler drop the modules that inject the stylesheet",
|
package/src/ssr.test.tsx
CHANGED
|
@@ -4,6 +4,7 @@ import { describe, expect, it } from "vitest";
|
|
|
4
4
|
import { AppShell } from "./AppShell";
|
|
5
5
|
import { DataView } from "./dataview/DataView";
|
|
6
6
|
import type { DataViewRepository } from "./dataview/types";
|
|
7
|
+
import { LOCALE_EN, LOCALE_NL, LocaleProvider } from "./locale";
|
|
7
8
|
|
|
8
9
|
interface Row {
|
|
9
10
|
id: string;
|
|
@@ -40,4 +41,21 @@ describe("server rendering", () => {
|
|
|
40
41
|
expect(shell).toContain("Home");
|
|
41
42
|
expect(view).toContain('data-terp="dataview"');
|
|
42
43
|
});
|
|
44
|
+
|
|
45
|
+
it("renders a localised DataView without writing to a document that is not there", () => {
|
|
46
|
+
// LocaleProvider keeps <html lang> on the active locale, and there is no `document` on the
|
|
47
|
+
// server. The write lives in an effect, which server rendering never runs; moved into the
|
|
48
|
+
// render body it throws here. And the DataView's own copy is already Dutch in the markup,
|
|
49
|
+
// because its strings come from the same table the locale translates.
|
|
50
|
+
const view = renderToString(
|
|
51
|
+
<LocaleProvider locales={{ en: LOCALE_EN, nl: LOCALE_NL }} defaultLocale="nl">
|
|
52
|
+
<DataView
|
|
53
|
+
repository={repository}
|
|
54
|
+
columns={[{ id: "name", header: "Name", accessor: (row) => row.name }]}
|
|
55
|
+
/>
|
|
56
|
+
</LocaleProvider>,
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
expect(view).toContain('aria-label="Laden…"');
|
|
60
|
+
});
|
|
43
61
|
});
|
package/src/styles.test.ts
CHANGED
|
@@ -52,6 +52,40 @@ function layerBody(name: string): string {
|
|
|
52
52
|
* passes just as happily when a rule has landed in the wrong half, which is the one mistake
|
|
53
53
|
* this pair of blocks can make.
|
|
54
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
|
+
|
|
55
89
|
function mediaBodies(body: string, query: string): string {
|
|
56
90
|
const opener = `@media ${query} {`;
|
|
57
91
|
const found: string[] = [];
|
|
@@ -981,6 +1015,187 @@ describe("cascade structure", () => {
|
|
|
981
1015
|
expect(base.slice(termAt, base.indexOf("}", termAt))).not.toContain("color:");
|
|
982
1016
|
});
|
|
983
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
|
+
|
|
984
1199
|
it("gives body copy an emphasis step without re-weighting the copy that asks for none", () => {
|
|
985
1200
|
const base = layerBody("terp.base");
|
|
986
1201
|
// Both steps read the published weight tokens rather than a literal.
|
|
@@ -1143,30 +1358,37 @@ describe("cascade structure", () => {
|
|
|
1143
1358
|
expect(full).toContain("text-overflow: ellipsis");
|
|
1144
1359
|
});
|
|
1145
1360
|
|
|
1146
|
-
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", () => {
|
|
1147
1362
|
// The trail is a row of items that get CENTRED, so two line heights in it are two
|
|
1148
1363
|
// baselines. The leaf declared 1.3 while its ancestors inherited `normal`: measured at
|
|
1149
1364
|
// font-size-sm, a 19.00px ancestor line box against an 18.19px leaf, which left the
|
|
1150
1365
|
// page's own title 0.59px above the crumb it hangs off with the chevron centred on a
|
|
1151
|
-
// third line. One declaration on the trail, inherited by every crumb
|
|
1152
|
-
//
|
|
1366
|
+
// third line. One declaration on the trail, inherited by every crumb, is what makes the
|
|
1367
|
+
// ancestors share a baseline.
|
|
1153
1368
|
//
|
|
1154
1369
|
// The published step rather than a bare literal, and that is the second half of the fix
|
|
1155
1370
|
// rather than house style: `normal` is the FONT's metric, so the mismatch was as big as
|
|
1156
1371
|
// the app's typeface said it was, and an app on a webfont with taller natural leading got
|
|
1157
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.
|
|
1158
1380
|
const base = layerBody("terp.base");
|
|
1159
1381
|
const trail = base.slice(base.indexOf('[data-terp="breadcrumbs"] {'));
|
|
1160
1382
|
expect(
|
|
1161
1383
|
trail.slice(0, trail.indexOf("}")),
|
|
1162
|
-
"the trail declares the line box every crumb shares",
|
|
1384
|
+
"the trail declares the line box every ancestor crumb shares",
|
|
1163
1385
|
).toContain("line-height: var(--font-line-height-snug)");
|
|
1164
1386
|
const leafAt = base.indexOf('[data-terp="page-title"] {');
|
|
1165
1387
|
expect(leafAt, "the trail's leaf should have a rule").toBeGreaterThan(-1);
|
|
1166
1388
|
expect(
|
|
1167
1389
|
base.slice(leafAt, base.indexOf("}", leafAt)),
|
|
1168
|
-
"the leaf
|
|
1169
|
-
).
|
|
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)");
|
|
1170
1392
|
});
|
|
1171
1393
|
|
|
1172
1394
|
it("spans a full row across every track, and makes it a box that can", () => {
|
|
@@ -1322,14 +1544,16 @@ describe("cascade structure", () => {
|
|
|
1322
1544
|
// one published scale rather than four sizes that happen to differ.
|
|
1323
1545
|
const base = layerBody("terp.base");
|
|
1324
1546
|
for (const [selector, step] of [
|
|
1325
|
-
// page-title
|
|
1326
|
-
//
|
|
1327
|
-
//
|
|
1328
|
-
//
|
|
1329
|
-
//
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
//
|
|
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.
|
|
1333
1557
|
['[data-terp="heading"][data-size="xl"]', "xl"],
|
|
1334
1558
|
['[data-terp="card-title"]', "lg"],
|
|
1335
1559
|
['[data-terp="card-description"]', "sm"],
|
|
@@ -1820,6 +2044,26 @@ describe("cascade structure", () => {
|
|
|
1820
2044
|
expect(rule![2]!.trim()).toBe("display: contents;");
|
|
1821
2045
|
});
|
|
1822
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
|
+
|
|
1823
2067
|
it("pins the values of five declarations no lane can reach", () => {
|
|
1824
2068
|
// Presence is not enough for these five, and that is the distinction the roll-calls above
|
|
1825
2069
|
// already draw for Button sizes and gap steps: a rule can be present and WRONG, and nothing
|
|
@@ -1867,6 +2111,9 @@ describe("cascade structure", () => {
|
|
|
1867
2111
|
"badge",
|
|
1868
2112
|
"alert",
|
|
1869
2113
|
"tooltip",
|
|
2114
|
+
"meter",
|
|
2115
|
+
"meter-bar",
|
|
2116
|
+
"meter-value",
|
|
1870
2117
|
"input",
|
|
1871
2118
|
"input-password",
|
|
1872
2119
|
"field",
|
|
@@ -2015,6 +2262,10 @@ describe("cascade structure", () => {
|
|
|
2015
2262
|
"login-separator",
|
|
2016
2263
|
"login-separator-rule",
|
|
2017
2264
|
"login-error",
|
|
2265
|
+
"login-email",
|
|
2266
|
+
"login-password",
|
|
2267
|
+
"login-submit",
|
|
2268
|
+
"user-menu-sign-out",
|
|
2018
2269
|
"admin-form",
|
|
2019
2270
|
"admin-section-title",
|
|
2020
2271
|
"grid",
|