@terpjs/react-core 0.31.0 → 0.33.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 +6 -5
- package/package.json +5 -5
- package/src/Breadcrumbs.test.tsx +78 -0
- package/src/Breadcrumbs.tsx +38 -5
- package/src/ModuleNav.test.tsx +29 -1
- package/src/ModuleNav.tsx +5 -1
- package/src/Page.tsx +16 -3
- package/src/Stat.test.tsx +35 -0
- package/src/Stat.tsx +3 -1
- package/src/WorkspacePage.test.tsx +69 -0
- package/src/WorkspacePage.tsx +103 -0
- package/src/admin/AdminHub.tsx +233 -86
- package/src/admin/GroupDetail.tsx +1 -1
- package/src/admin/RecordHistory.tsx +5 -0
- package/src/admin/UserDetail.tsx +1 -1
- package/src/admin/admin.test.tsx +233 -14
- package/src/charts/TrendChart.tsx +24 -18
- package/src/charts/charts.test.tsx +11 -0
- package/src/currentInView.ts +28 -0
- package/src/dataview/DataView.test.tsx +48 -1
- package/src/dataview/DataView.tsx +18 -3
- package/src/dataview/DataViewToolbar.tsx +4 -1
- package/src/index.ts +2 -0
- package/src/layoutContract.test.tsx +62 -1
- package/src/layoutContract.ts +12 -0
- package/src/locale.tsx +8 -0
- package/src/markers.test.ts +4 -0
- package/src/router.test.tsx +1 -1
- package/src/router.tsx +19 -1
- package/src/styles.test.ts +241 -2
- package/src/styles.ts +234 -39
- package/src/trailMemory.ts +56 -0
- package/src/ui/Tabs.test.tsx +44 -0
- package/src/ui/Tabs.tsx +5 -2
- package/src/uiText.tsx +30 -1
- package/src/viewerTimeZone.ts +15 -0
package/src/locale.tsx
CHANGED
|
@@ -225,6 +225,14 @@ export const LOCALE_NL: LocaleCatalog = {
|
|
|
225
225
|
statUnfavourable: "ongunstig",
|
|
226
226
|
statTrend: "Verloop: {points}",
|
|
227
227
|
adminHubTotal: "Totaal",
|
|
228
|
+
adminHubActiveAccounts: "Actieve accounts",
|
|
229
|
+
adminHubDeactivated: "{count} gedeactiveerd",
|
|
230
|
+
adminHubChangesWeek: "Wijzigingen, afgelopen {count} dagen",
|
|
231
|
+
adminHubVsWeekBefore: "t.o.v. de week ervoor",
|
|
232
|
+
adminHubChangesPerDay: "Wijzigingen per dag",
|
|
233
|
+
adminHubLastDays: "Afgelopen {count} dagen",
|
|
234
|
+
adminHubDaysBefore: "De {count} dagen ervoor",
|
|
235
|
+
adminHubChangesByKind: "Wijzigingen per soort, afgelopen {count} dagen",
|
|
228
236
|
statusHistoryRuns: "{label}, oudste eerst: {runs}",
|
|
229
237
|
recordHistory: "Geschiedenis",
|
|
230
238
|
auditActionCreated: "Aangemaakt",
|
package/src/markers.test.ts
CHANGED
|
@@ -75,6 +75,8 @@ const MARKERS = [
|
|
|
75
75
|
"bar-chart-value",
|
|
76
76
|
"breadcrumbs",
|
|
77
77
|
"breadcrumbs-current",
|
|
78
|
+
"breadcrumbs-pending",
|
|
79
|
+
"breadcrumbs-pending-text",
|
|
78
80
|
"breadcrumbs-separator",
|
|
79
81
|
"button",
|
|
80
82
|
"button-icon",
|
|
@@ -85,6 +87,8 @@ const MARKERS = [
|
|
|
85
87
|
"calendar-title",
|
|
86
88
|
"calendar-week",
|
|
87
89
|
"calendar-weekday",
|
|
90
|
+
"canvas-host",
|
|
91
|
+
"canvas-host-layer",
|
|
88
92
|
"card",
|
|
89
93
|
"card-actions",
|
|
90
94
|
"card-description",
|
package/src/router.test.tsx
CHANGED
|
@@ -674,7 +674,7 @@ describe("buildAppRouter", () => {
|
|
|
674
674
|
.map((argument) => (argument instanceof Error ? argument.message : String(argument)))
|
|
675
675
|
.join(" ");
|
|
676
676
|
expect(`${logged} ${document.body.textContent ?? ""}`).toContain(
|
|
677
|
-
"(Page, HubPage, OverviewPage, FormPage, SettingsPage, SplitPage, DashboardPage or DetailPage)",
|
|
677
|
+
"(Page, HubPage, OverviewPage, FormPage, SettingsPage, SplitPage, DashboardPage, WorkspacePage or DetailPage)",
|
|
678
678
|
);
|
|
679
679
|
});
|
|
680
680
|
|
package/src/router.tsx
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
Outlet,
|
|
7
7
|
useNavigate,
|
|
8
8
|
useParams,
|
|
9
|
+
useMatch,
|
|
9
10
|
useRouter,
|
|
10
11
|
useRouterState,
|
|
11
12
|
useSearch,
|
|
@@ -13,7 +14,7 @@ import {
|
|
|
13
14
|
type RouterHistory,
|
|
14
15
|
} from "@tanstack/react-router";
|
|
15
16
|
import type { ComponentType, ReactNode } from "react";
|
|
16
|
-
import { useCallback, useEffect, useRef, useState } from "react";
|
|
17
|
+
import { useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
17
18
|
import type { ModuleManifest, NavGroup, UiText } from "@terpjs/contract";
|
|
18
19
|
|
|
19
20
|
import { AppShell } from "./AppShell";
|
|
@@ -35,6 +36,7 @@ import { isDeclarationVisible, visibleNav } from "./nav";
|
|
|
35
36
|
import { NavLinkContext } from "./navLink";
|
|
36
37
|
import type { NavLinkRenderer } from "./navLink";
|
|
37
38
|
import { PageMarkerContext } from "./pageMarker";
|
|
39
|
+
import { TrailLabelsContext, TrailMemoryContext, trailMemory } from "./trailMemory";
|
|
38
40
|
import {
|
|
39
41
|
RouteSearchContext,
|
|
40
42
|
declaredSearchKeys,
|
|
@@ -514,11 +516,16 @@ export function buildAppRouter(
|
|
|
514
516
|
),
|
|
515
517
|
[],
|
|
516
518
|
);
|
|
519
|
+
// What the trail has said about each place, for as long as the app runs (ADR 0173): one map
|
|
520
|
+
// for the shell's lifetime, so a page mounted by the next navigation still finds it. Each
|
|
521
|
+
// routed view binds it to its own path (RouteComponent), never to this location.
|
|
522
|
+
const trailLabels = useRef(new Map<string, string>()).current;
|
|
517
523
|
return (
|
|
518
524
|
// Publish the router's Link so every layout component that renders an in-app link
|
|
519
525
|
// (Breadcrumbs, HubCard) navigates client-side by default. Forgetting `renderLink`
|
|
520
526
|
// used to degrade the app silently: a raw anchor, a full page reload, no error.
|
|
521
527
|
<NavLinkContext.Provider value={renderNavLink}>
|
|
528
|
+
<TrailLabelsContext.Provider value={trailLabels}>
|
|
522
529
|
<AppShell
|
|
523
530
|
title={options.title}
|
|
524
531
|
logo={brandMark(layout.brand?.logo) ?? options.logo}
|
|
@@ -570,6 +577,7 @@ export function buildAppRouter(
|
|
|
570
577
|
>
|
|
571
578
|
<Outlet />
|
|
572
579
|
</AppShell>
|
|
580
|
+
</TrailLabelsContext.Provider>
|
|
573
581
|
</NavLinkContext.Provider>
|
|
574
582
|
);
|
|
575
583
|
}
|
|
@@ -584,6 +592,14 @@ export function buildAppRouter(
|
|
|
584
592
|
): AnyRoute {
|
|
585
593
|
function RouteComponent() {
|
|
586
594
|
const user = useAuth().currentUser();
|
|
595
|
+
// The trail's memory, bound to the path THIS view's match is at (ADR 0173): the leaf is
|
|
596
|
+
// remembered as this page's name, never as the name of a location the router has moved on to.
|
|
597
|
+
const trailLabels = useContext(TrailLabelsContext);
|
|
598
|
+
const ownPath = useMatch({ strict: false }).pathname;
|
|
599
|
+
const memory = useMemo(
|
|
600
|
+
() => (trailLabels === null ? null : trailMemory(trailLabels, ownPath)),
|
|
601
|
+
[trailLabels, ownPath],
|
|
602
|
+
);
|
|
587
603
|
const rank = user?.role_rank ?? null;
|
|
588
604
|
// The same resolution the sidebar uses, and using it here is what stops `permission` from
|
|
589
605
|
// becoming a cosmetic gate: hiding a link while leaving its route reachable by URL is not
|
|
@@ -624,6 +640,7 @@ export function buildAppRouter(
|
|
|
624
640
|
}
|
|
625
641
|
return (
|
|
626
642
|
<RouteSearchContext.Provider value={searchKeys}>
|
|
643
|
+
<TrailMemoryContext.Provider value={memory}>
|
|
627
644
|
<LayoutContractContext.Provider value={layoutContract}>
|
|
628
645
|
<PageMarkerContext.Provider
|
|
629
646
|
value={() => {
|
|
@@ -633,6 +650,7 @@ export function buildAppRouter(
|
|
|
633
650
|
<View />
|
|
634
651
|
</PageMarkerContext.Provider>
|
|
635
652
|
</LayoutContractContext.Provider>
|
|
653
|
+
</TrailMemoryContext.Provider>
|
|
636
654
|
</RouteSearchContext.Provider>
|
|
637
655
|
);
|
|
638
656
|
}
|
package/src/styles.test.ts
CHANGED
|
@@ -373,13 +373,14 @@ describe("cascade structure", () => {
|
|
|
373
373
|
// one shell rule keyed on a descendant of an attribute rather than on a marker of its own,
|
|
374
374
|
// because the mechanism is deliberately NOT a new element (ADR 0097 §2). The `:not()` is the
|
|
375
375
|
// whole band: the frame's two bands -- the title band and the summary band (ADR 0169 §4) --
|
|
376
|
-
// keep the page grid's full track while their siblings take the measure
|
|
376
|
+
// keep the page grid's full track while their siblings take the measure, and so does a
|
|
377
|
+
// workspace's canvas host (ADR 0179), which is not read along a line.
|
|
377
378
|
// Selector AND declaration read out of ONE rule body, not as two independent substrings
|
|
378
379
|
// of the layer. Asserted separately, an empty measure rule plus the declaration moved onto
|
|
379
380
|
// some other rule during a consolidation would satisfy both — and the only baseline that
|
|
380
381
|
// moved would read as an intentional layout change.
|
|
381
382
|
const measureRule =
|
|
382
|
-
/\[data-terp="appshell"\]\[data-content-width="measured"\]\s*\n?\s*\[data-terp="page"\] > \*:not\(\[data-terp="page-header"\], \[data-terp="page-summary"\]\) \{([^}]*)\}/.exec(
|
|
383
|
+
/\[data-terp="appshell"\]\[data-content-width="measured"\]\s*\n?\s*\[data-terp="page"\] > \*:not\(\[data-terp="page-header"\], \[data-terp="page-summary"\], \[data-terp="canvas-host"\]\) \{([^}]*)\}/.exec(
|
|
383
384
|
base,
|
|
384
385
|
);
|
|
385
386
|
expect(measureRule, "the content measure must be one rule keyed on the shell's attribute").not
|
|
@@ -2416,3 +2417,241 @@ describe("cascade structure", () => {
|
|
|
2416
2417
|
}
|
|
2417
2418
|
});
|
|
2418
2419
|
});
|
|
2420
|
+
|
|
2421
|
+
describe("what a review of the screens in use changed", () => {
|
|
2422
|
+
const base = layerBody("terp.base");
|
|
2423
|
+
const always = baseOnly(base);
|
|
2424
|
+
const ruleBody = (body: string, selector: string) => {
|
|
2425
|
+
const match = [...body.matchAll(/([^{}]+)\{([^{}]*)\}/g)].find(
|
|
2426
|
+
(rule) => rule[1]!.trim().replace(/\s+/g, " ") === selector,
|
|
2427
|
+
);
|
|
2428
|
+
expect(match, `${selector} has no rule of its own`).toBeDefined();
|
|
2429
|
+
return match![2]!;
|
|
2430
|
+
};
|
|
2431
|
+
|
|
2432
|
+
it("lays a tab strip out as one line that scrolls, never a wrap", () => {
|
|
2433
|
+
for (const selector of ['[data-terp="tab-list"]', '[data-terp="module-nav-list"]']) {
|
|
2434
|
+
const rule = ruleBody(always, selector);
|
|
2435
|
+
// Mutation: flex-wrap back to wrap, which splits the strip and its rule apart on a phone.
|
|
2436
|
+
expect(rule, selector).toContain("flex-wrap: nowrap");
|
|
2437
|
+
expect(rule, selector).toContain("overflow-x: auto");
|
|
2438
|
+
// The focus ring's room inside the scroll container, given back outside it.
|
|
2439
|
+
expect(rule, selector).toContain("padding: var(--space-1)");
|
|
2440
|
+
expect(rule, selector).toContain("margin: calc(-1 * var(--space-1))");
|
|
2441
|
+
}
|
|
2442
|
+
// The tab strip's rule is drawn inside its content box: a border would be clipped by the
|
|
2443
|
+
// scroll container, and the selected tab's edge with it.
|
|
2444
|
+
const tabList = ruleBody(always, '[data-terp="tab-list"]');
|
|
2445
|
+
expect(tabList).not.toContain("border-block-end");
|
|
2446
|
+
expect(tabList).toContain("linear-gradient(var(--color-neutral-200), var(--color-neutral-200))");
|
|
2447
|
+
expect(ruleBody(always, '[data-terp="tab"]')).not.toContain("margin-block-end: -1px");
|
|
2448
|
+
expect(ruleBody(always, '[data-terp="module-nav-link"]')).toContain("white-space: nowrap");
|
|
2449
|
+
});
|
|
2450
|
+
|
|
2451
|
+
it("lets a badge wrap inside its container, and keeps one line a pill", () => {
|
|
2452
|
+
const badge = ruleBody(always, '[data-terp="badge"]');
|
|
2453
|
+
// Mutation: nowrap back, or no cap, which let a long label run out of a phone's column.
|
|
2454
|
+
expect(badge).not.toContain("white-space: nowrap");
|
|
2455
|
+
expect(badge).toContain("max-inline-size: 100%");
|
|
2456
|
+
// A radius above half a one-line badge's height clamps to a full round; a full radius
|
|
2457
|
+
// would make a two-line badge a lozenge.
|
|
2458
|
+
expect(badge).toContain("border-radius: var(--radius-lg)");
|
|
2459
|
+
});
|
|
2460
|
+
|
|
2461
|
+
it("breaks a badge inside a word only when the word alone does not fit", () => {
|
|
2462
|
+
const badge = ruleBody(always, '[data-terp="badge"]');
|
|
2463
|
+
// Measured in Chromium: with `anywhere` a badge's narrowest width is one glyph, so a
|
|
2464
|
+
// squeezed auto-layout table split "Cancelled" mid-word into a 43x56 box; with
|
|
2465
|
+
// break-word on an inline block it stays the 75x23 pill. An inline flex keeps the
|
|
2466
|
+
// longest word too, but no longer breaks a single word wider than its column.
|
|
2467
|
+
expect(badge).toContain("overflow-wrap: break-word");
|
|
2468
|
+
expect(badge).toContain("display: inline-block");
|
|
2469
|
+
expect(badge).not.toContain("anywhere");
|
|
2470
|
+
});
|
|
2471
|
+
|
|
2472
|
+
it("closes up a band's rows of figures on a narrow screen, two to a line still", () => {
|
|
2473
|
+
const narrow = mediaBodies(base, NARROW_VIEWPORT);
|
|
2474
|
+
const group = ruleBody(narrow, '[data-terp="stat-group"]');
|
|
2475
|
+
// Mutations: the full gap kept between rows on a phone, or the band's full padding.
|
|
2476
|
+
expect(group).toContain("row-gap: var(--space-2)");
|
|
2477
|
+
expect(ruleBody(narrow, '[data-terp="page-summary"]')).toContain("padding-block: var(--space-3)");
|
|
2478
|
+
// Two to a line stays: a third column broke a figure like "4 m 12 s" over two lines.
|
|
2479
|
+
// Mutation: a narrower floor for the phone.
|
|
2480
|
+
expect(group).not.toContain("grid-template-columns");
|
|
2481
|
+
expect(ruleBody(always, '[data-terp="stat-group"]')).toContain(
|
|
2482
|
+
"grid-template-columns: repeat(auto-fit, minmax(min(9.5rem, 100%), 1fr))",
|
|
2483
|
+
);
|
|
2484
|
+
});
|
|
2485
|
+
});
|
|
2486
|
+
|
|
2487
|
+
describe("flat at rest (ADR 0172)", () => {
|
|
2488
|
+
/** Every rule whose body reads a shadow token, by its selector. */
|
|
2489
|
+
function shadowReaders(): string[] {
|
|
2490
|
+
const readers: string[] = [];
|
|
2491
|
+
for (const match of css.matchAll(/([^{}]+)\{([^{}]*)\}/g)) {
|
|
2492
|
+
if (/var\(--shadow-/.test(match[2]!)) readers.push(match[1]!.trim().replace(/\s+/g, " "));
|
|
2493
|
+
}
|
|
2494
|
+
return readers.sort();
|
|
2495
|
+
}
|
|
2496
|
+
|
|
2497
|
+
it("lets only a layer cast a shadow, and never a block on the page", () => {
|
|
2498
|
+
// A shadow means something over the page: the six layers below. A card, a hub card, a
|
|
2499
|
+
// figure, a chart, a button and the table frame are told apart by fill and hairline.
|
|
2500
|
+
// Mutation: any resting block given a shadow again, or a layer that loses its own.
|
|
2501
|
+
expect(shadowReaders()).toEqual(
|
|
2502
|
+
[
|
|
2503
|
+
'[data-terp="appshell"][data-variant="mobile"] [data-terp="appshell-sidebar"]',
|
|
2504
|
+
'[data-terp="combobox-list"]',
|
|
2505
|
+
'[data-terp="dialog"]',
|
|
2506
|
+
'[data-terp="popover-panel"]',
|
|
2507
|
+
'[data-terp="toast"]',
|
|
2508
|
+
'[data-terp="tooltip"]',
|
|
2509
|
+
].sort(),
|
|
2510
|
+
);
|
|
2511
|
+
});
|
|
2512
|
+
});
|
|
2513
|
+
|
|
2514
|
+
describe("a page's sections stand further apart than a section's blocks (ADR 0174)", () => {
|
|
2515
|
+
const always = baseOnly(layerBody("terp.base"));
|
|
2516
|
+
const ruleBody = (selector: string) => {
|
|
2517
|
+
const match = [...always.matchAll(/([^{}]+)\{([^{}]*)\}/g)].find(
|
|
2518
|
+
(rule) => rule[1]!.trim().replace(/\s+/g, " ") === selector,
|
|
2519
|
+
);
|
|
2520
|
+
expect(match, `${selector} has no rule of its own`).toBeDefined();
|
|
2521
|
+
return match![2]!;
|
|
2522
|
+
};
|
|
2523
|
+
const sectionGap = () => /(?:^|[;\s])gap: (var\(--space-\d+\))/.exec(ruleBody('[data-terp="page"]'))?.[1];
|
|
2524
|
+
|
|
2525
|
+
it("spaces the page's sections a step wider than a hub spaces its cards", () => {
|
|
2526
|
+
// Mutation: the page's gap back to --space-4, the hub grid's own, so a row of cards is as
|
|
2527
|
+
// far from the chart under it as from its neighbour again. Grid's side of the same promise
|
|
2528
|
+
// is its default `gap = 4`, a prop it always stamps, so it is measured in the workbench's
|
|
2529
|
+
// computed lane rather than read from a rule here.
|
|
2530
|
+
expect(sectionGap()).toBe("var(--space-6)");
|
|
2531
|
+
expect(ruleBody('[data-terp="hubpage-grid"]')).toContain("gap: var(--space-4)");
|
|
2532
|
+
});
|
|
2533
|
+
|
|
2534
|
+
it("cancels and repeats the section gap with the page's own token", () => {
|
|
2535
|
+
// Read from the page rule rather than written out, so moving the gap again moves these
|
|
2536
|
+
// with it or fails here. Mutation: either one left at --space-4 while the page moves,
|
|
2537
|
+
// which drops the summary band 8px under the title band, or sets the body nearer the
|
|
2538
|
+
// sequence bar than the band.
|
|
2539
|
+
const gap = sectionGap();
|
|
2540
|
+
expect(gap).toBeDefined();
|
|
2541
|
+
expect(
|
|
2542
|
+
ruleBody(
|
|
2543
|
+
'[data-terp="appshell-main"] > [data-terp="page"]:not([data-measure="narrow"]) > [data-terp="page-summary"]',
|
|
2544
|
+
),
|
|
2545
|
+
).toContain(`margin: calc(-1 * ${gap})`);
|
|
2546
|
+
expect(ruleBody('[data-terp="page-sequence"]')).toContain(`margin-block-start: ${gap}`);
|
|
2547
|
+
});
|
|
2548
|
+
});
|
|
2549
|
+
|
|
2550
|
+
describe("a workspace fills the height the shell leaves it (ADR 0179)", () => {
|
|
2551
|
+
const always = baseOnly(layerBody("terp.base"));
|
|
2552
|
+
const ruleIn = (body: string, selector: string) => {
|
|
2553
|
+
const match = [...body.matchAll(/([^{}]+)\{([^{}]*)\}/g)].find(
|
|
2554
|
+
(rule) => rule[1]!.trim().replace(/\s+/g, " ") === selector,
|
|
2555
|
+
);
|
|
2556
|
+
expect(match, `${selector} has no rule of its own`).toBeDefined();
|
|
2557
|
+
return match![2]!;
|
|
2558
|
+
};
|
|
2559
|
+
const ruleBody = (selector: string) => ruleIn(always, selector);
|
|
2560
|
+
const workspace = '[data-terp="page"][data-fill="workspace"]';
|
|
2561
|
+
|
|
2562
|
+
it("turns the shell's main into a column only when it holds a workspace", () => {
|
|
2563
|
+
// Mutation: drop the :has() scope, and every page's main becomes a flex column.
|
|
2564
|
+
const main = ruleBody(`[data-terp="appshell-main"]:has(> ${workspace})`);
|
|
2565
|
+
expect(main).toContain("display: flex");
|
|
2566
|
+
expect(main).toContain("flex-direction: column");
|
|
2567
|
+
expect(ruleBody(`[data-terp="appshell-main"] > ${workspace}`)).toContain("flex-grow: 1");
|
|
2568
|
+
// Every other page keeps the grid it always had.
|
|
2569
|
+
expect(ruleBody('[data-terp="page"]')).toContain("display: grid");
|
|
2570
|
+
});
|
|
2571
|
+
|
|
2572
|
+
it("gives the canvas what the band and the summary leave, and a floor where nothing does", () => {
|
|
2573
|
+
expect(ruleBody(workspace)).toContain("flex-direction: column");
|
|
2574
|
+
expect(ruleBody(`${workspace} > [data-terp="canvas-host"]`)).toContain("flex: 1 1 auto");
|
|
2575
|
+
const host = ruleBody('[data-terp="canvas-host"]');
|
|
2576
|
+
// Mutation: drop the floor, and a standalone canvas collapses to nothing.
|
|
2577
|
+
expect(host).toContain("min-height: 24rem");
|
|
2578
|
+
// Mutation: drop the clip, and a canvas panned past its edge paints over the band.
|
|
2579
|
+
// clip, not hidden: hidden makes the host a scroll container that focus can scroll.
|
|
2580
|
+
expect(host).toContain("overflow: clip");
|
|
2581
|
+
expect(host).not.toContain("overflow: hidden");
|
|
2582
|
+
expect(host).toContain("position: relative");
|
|
2583
|
+
});
|
|
2584
|
+
|
|
2585
|
+
it("lets a state in the canvas's place take the canvas's box, so the frame does not jump", () => {
|
|
2586
|
+
// Mutation: drop this rule, and a loading workspace is a short block that jumps to the full
|
|
2587
|
+
// height when the canvas arrives.
|
|
2588
|
+
const states = ruleBody(
|
|
2589
|
+
["loading-state", "error-state", "empty-state"]
|
|
2590
|
+
.map((marker) => `${workspace} > [data-terp="${marker}"]`)
|
|
2591
|
+
.join(", "),
|
|
2592
|
+
);
|
|
2593
|
+
expect(states).toContain("flex: 1 1 auto");
|
|
2594
|
+
expect(states).toContain("min-height: 24rem");
|
|
2595
|
+
// Centred in the taller box, rather than the grid states' rows spreading down it.
|
|
2596
|
+
expect(states).toContain("align-content: center");
|
|
2597
|
+
});
|
|
2598
|
+
|
|
2599
|
+
it("leaves the host out of a measured shell's measure, as it does the bands", () => {
|
|
2600
|
+
// Mutation: drop canvas-host from the :not(), and in a measured shell the canvas stops at
|
|
2601
|
+
// the measure and sits against the start of the track.
|
|
2602
|
+
const measure = [...always.matchAll(/([^{}]+)\{([^{}]*)\}/g)].find((rule) =>
|
|
2603
|
+
rule[1]!
|
|
2604
|
+
.replace(/\s+/g, " ")
|
|
2605
|
+
.includes('[data-content-width="measured"] [data-terp="page"] > *:not('),
|
|
2606
|
+
);
|
|
2607
|
+
expect(measure, "the content measure has no rule").toBeDefined();
|
|
2608
|
+
expect(measure![1]).toContain('[data-terp="canvas-host"]');
|
|
2609
|
+
expect(measure![2]).toContain("width: min(100%, var(--shell-content-max-width))");
|
|
2610
|
+
});
|
|
2611
|
+
|
|
2612
|
+
it("paints the host from tokens only, as a block of the page", () => {
|
|
2613
|
+
const host = ruleBody('[data-terp="canvas-host"]');
|
|
2614
|
+
expect(host).toContain("background: var(--color-bg-surface)");
|
|
2615
|
+
expect(host).toContain("border: 1px solid var(--color-neutral-200)");
|
|
2616
|
+
expect(host).toContain("border-radius: var(--radius-lg)");
|
|
2617
|
+
expect(host).not.toMatch(/#[0-9a-f]{3,8}\b|rgb\(/i);
|
|
2618
|
+
});
|
|
2619
|
+
|
|
2620
|
+
it("lays its canvas over the whole host, through a layer of its own with a definite size", () => {
|
|
2621
|
+
// The layer, not the canvas, is what is positioned: a canvas library's root is positioned
|
|
2622
|
+
// by the library's own sheet, which beats a layered rule.
|
|
2623
|
+
const layer = ruleBody('[data-terp="canvas-host-layer"]');
|
|
2624
|
+
expect(layer).toContain("position: absolute");
|
|
2625
|
+
expect(layer).toContain("inset: 0");
|
|
2626
|
+
expect(declaresRuleFor(always, '[data-terp="canvas-host"] > *')).toBe(false);
|
|
2627
|
+
// Mutation: drop the explicit size, and an svg takes its height from its viewBox's ratio
|
|
2628
|
+
// and sits at the top of a tall canvas instead of filling it.
|
|
2629
|
+
const child = ruleBody('[data-terp="canvas-host-layer"] > :not([data-terp="dialog"])');
|
|
2630
|
+
expect(child).toContain("width: 100%");
|
|
2631
|
+
expect(child).toContain("height: 100%");
|
|
2632
|
+
expect(child).not.toContain("position");
|
|
2633
|
+
});
|
|
2634
|
+
|
|
2635
|
+
it("draws the shared focus ring on the host while its canvas has keyboard focus", () => {
|
|
2636
|
+
// The canvas fills the host edge to edge, so a ring around it lies wholly in what the host
|
|
2637
|
+
// clips. Mutation: drop this rule, and a keyboard user on the canvas sees no indicator.
|
|
2638
|
+
// In terp.state with the shared ring, and its declarations copied rather than restated:
|
|
2639
|
+
// the ring is one indicator wherever it is drawn.
|
|
2640
|
+
const state = baseOnly(layerBody("terp.state"));
|
|
2641
|
+
const declarations = (body: string) =>
|
|
2642
|
+
body
|
|
2643
|
+
.split(";")
|
|
2644
|
+
.map((part) => part.trim())
|
|
2645
|
+
.filter((part) => part.length > 0);
|
|
2646
|
+
const ring = declarations(ruleIn(state, "[data-terp]:focus-visible"));
|
|
2647
|
+
expect(ring).toContain("outline: 2px solid var(--color-fg-accent)");
|
|
2648
|
+
expect(
|
|
2649
|
+
declarations(
|
|
2650
|
+
ruleIn(
|
|
2651
|
+
state,
|
|
2652
|
+
'[data-terp="canvas-host"]:has(> [data-terp="canvas-host-layer"] > :focus-visible)',
|
|
2653
|
+
),
|
|
2654
|
+
),
|
|
2655
|
+
).toEqual(ring);
|
|
2656
|
+
});
|
|
2657
|
+
});
|