@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/README.md
CHANGED
|
@@ -72,8 +72,8 @@ also carries JSDoc, so your editor shows the same guidance inline. **Never deep-
|
|
|
72
72
|
## Page archetypes (the three-level screen pattern)
|
|
73
73
|
|
|
74
74
|
Every routed view **must** render one of the archetypes (`Page`, or `OverviewPage` /
|
|
75
|
-
`DetailPage` / `HubPage` / `DashboardPage` / `FormPage` / `SettingsPage` / `SplitPage
|
|
76
|
-
compose it) — `buildAppRouter` refuses an unframed view at
|
|
75
|
+
`DetailPage` / `HubPage` / `DashboardPage` / `FormPage` / `SettingsPage` / `SplitPage` /
|
|
76
|
+
`WorkspacePage`, which compose it) — `buildAppRouter` refuses an unframed view at
|
|
77
77
|
runtime, fail closed (ADR 0059), so every screen keeps the breadcrumb/title/error frame.
|
|
78
78
|
|
|
79
79
|
| Export | Use |
|
|
@@ -99,6 +99,7 @@ runtime, fail closed (ADR 0059), so every screen keeps the breadcrumb/title/erro
|
|
|
99
99
|
| `FormPage` | A create-or-edit screen. `measure="narrow"` by default, so the whole frame — header, actions and all — caps at 32rem over a single column of controls. Its body slot takes the form container (`Stack as="form"`), plus `Grid` / `Card` / `Divider` / `Text`; a bare `Field` at the top level is refused, because a run of fields has no `<form>` and cannot be submitted. |
|
|
100
100
|
| `SettingsPage` | Preferences and account screens: `Card` sections, also `measure="narrow"`. No `DataView`, `DetailList` or `Tabs` — a settings screen whose body is a collection is an overview with the wrong chrome. `parents` is optional, unlike `FormPage`'s. |
|
|
101
101
|
| `SplitPage`, `SplitPane` | A list beside the record it selects. The archetype owns the pane row and admits **only** `SplitPane` in it (`HubPage`'s shape, not `DetailPage`'s), so the panes are the governed thing. `listWidth` is a step — `sm` / `md` / `lg` — not a length; a draggable divider waits for the preference seam. Each pane is a named `<section>`, and below the mobile breakpoint they stack list-first, so the reading order and the tab order agree at both widths. |
|
|
102
|
+
| `WorkspacePage`, `CanvasHost` | One canvas that fills the screen, for work done on a surface: a diagram of nodes and connections, a plan, a board (ADR 0179). The page keeps its band, with its trail as `parents`; below it the body takes every pixel the shell leaves, and its slot admits **one** `CanvasHost`, a framework state while it loads or fails (which fills the same box, so the frame does not jump), and a `ConfirmDialog`. The host is a named `<section>` painted from tokens, clipped, with a 24rem floor outside a shell, and it takes the full track in a measured shell. It takes **one** canvas child, drawn in an inner layer of a definite size at 100% of it, so an `<svg>` scales by its `viewBox` and a canvas library's root that sizes itself to its container gets all of it; a second child would land below the first and be clipped. A canvas that takes keyboard focus shows the framework's focus ring on the host, where the clip cannot cut it. Nothing on the page needs a style to be sized. |
|
|
102
103
|
| `Breadcrumbs` | The trail itself (used by the archetypes; rarely composed directly). Ancestor crumbs use the router's `Link` by default — `renderLink` is only for rendering outside a Terp router. |
|
|
103
104
|
| `NavLinkContext`, `useNavLink` | The ambient link renderer `buildAppRouter` publishes (and the layout components default to); provide it yourself in a standalone story/test tree or a bespoke shell. |
|
|
104
105
|
| `useRouteParam` | Read one route param, fail closed: the declared param comes back as a string, an undeclared name throws a directive error instead of silently yielding `undefined`. Replaces the unchecked `useParams({ strict: false }) as {…}` cast (ADR 0092). Checked against the generated route table when the app has one. |
|
|
@@ -217,7 +218,7 @@ marker, counted by the escape-hatch budget.
|
|
|
217
218
|
| Export | Use |
|
|
218
219
|
|---|---|
|
|
219
220
|
| `Button` | Token-styled command: `variant` (primary / secondary / danger / ghost), `size` (sm / md / lg, composing with density), `loading` (spinner in the icon slot, `aria-busy`, and disabled so a second click cannot start the request twice), `fullWidth` to fill the container instead of the label, and an optional leading `icon`. Content-sized by default. |
|
|
220
|
-
| `Input`, `Select`, `Textarea` | Token-styled controls with stable framework typography, independent of surrounding display text (raw elements are lint-refused). Numeric inputs suppress unthemeable browser steppers. `Input type="password"` grows a reveal toggle — the type decides, so there is no second export and no prop; an app could not add one itself, because the toggle needs a positioned wrapper and
|
|
221
|
+
| `Input`, `Select`, `Textarea` | Token-styled controls with stable framework typography, independent of surrounding display text (raw elements are lint-refused). Numeric inputs suppress unthemeable browser steppers. `Input type="password"` grows a reveal toggle — the type decides, so there is no second export and no prop; an app could not add one itself, because the toggle needs a positioned wrapper and app source may use neither `style` nor `className`. |
|
|
221
222
|
| `Select` options (`SelectOption<T>`) | Two forms. Pass `options={[{ value, label, disabled? }]}` with `onValueChange` when the choices are data — `T` is inferred from the list, so a closed enum is checked at both ends and the `event.target.value as Status` cast goes away; `placeholder` renders the disabled empty-valued leading row. Or pass `<option>` children as before. The two are mutually exclusive at the type level, so neither can silently ignore the other. |
|
|
222
223
|
| `Combobox` | Accessible autocomplete/typeahead single-select: filterable options, controlled or uncontrolled value, loading state, disabled state, and ARIA combobox/listbox keyboard navigation. |
|
|
223
224
|
| `DatePicker`, `DateRangePicker` | Locale-aware calendar popover controls with keyboard-navigable month grids, min/max bounds, and range selection for ERP date filters. |
|
|
@@ -245,8 +246,8 @@ marker, counted by the escape-hatch budget.
|
|
|
245
246
|
|
|
246
247
|
## Layout
|
|
247
248
|
|
|
248
|
-
|
|
249
|
-
attribute in `src
|
|
249
|
+
App code never writes `style={}` or CSS — the boundary lint refuses the `style`
|
|
250
|
+
attribute anywhere in `src/**` (ADR 0175). Layout comes from these primitives (gaps index the
|
|
250
251
|
token spacing scale, so spacing is themed centrally):
|
|
251
252
|
|
|
252
253
|
| Export | Use |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@terpjs/react-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.33.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": {
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"test": "vitest run"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@tanstack/react-router": "^1.170.
|
|
18
|
-
"@terpjs/contract": "^0.
|
|
17
|
+
"@tanstack/react-router": "^1.170.41",
|
|
18
|
+
"@terpjs/contract": "^0.33.0"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"react": "^19.0.0",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"react": "^19.3.0",
|
|
32
32
|
"react-dom": "^19.3.0",
|
|
33
33
|
"typescript": "^5.9.3",
|
|
34
|
-
"vite": "^8.3.
|
|
35
|
-
"vitest": "^5.0.
|
|
34
|
+
"vite": "^8.3.2",
|
|
35
|
+
"vitest": "^5.0.3"
|
|
36
36
|
},
|
|
37
37
|
"license": "Apache-2.0",
|
|
38
38
|
"repository": {
|
package/src/Breadcrumbs.test.tsx
CHANGED
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
import { cleanup, render, screen } from "@testing-library/react";
|
|
3
3
|
import { afterEach, describe, expect, it } from "vitest";
|
|
4
4
|
|
|
5
|
+
import type { ReactNode } from "react";
|
|
6
|
+
|
|
5
7
|
import { Breadcrumbs } from "./Breadcrumbs";
|
|
8
|
+
import { TrailMemoryContext, trailMemory } from "./trailMemory";
|
|
6
9
|
|
|
7
10
|
afterEach(cleanup);
|
|
8
11
|
|
|
@@ -97,3 +100,78 @@ describe("Breadcrumbs", () => {
|
|
|
97
100
|
expect(container.querySelectorAll('[aria-current="page"]')).toHaveLength(3);
|
|
98
101
|
});
|
|
99
102
|
});
|
|
103
|
+
|
|
104
|
+
// A trail that keeps what it knows (ADR 0173): a label not known yet is never a stand-in, the
|
|
105
|
+
// trail recalls what it said at a path before, and a crumb is updated in place rather than
|
|
106
|
+
// replaced, so going deeper only adds a crumb.
|
|
107
|
+
describe("a trail that keeps what it knows", () => {
|
|
108
|
+
function within(pathname: string, labels: Map<string, string>, node: ReactNode) {
|
|
109
|
+
return (
|
|
110
|
+
<TrailMemoryContext.Provider value={trailMemory(labels, pathname)}>{node}</TrailMemoryContext.Provider>
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
it("shows a placeholder, read as loading, for a leaf never seen before", () => {
|
|
115
|
+
render(<Breadcrumbs items={[{ label: "Users", to: "/users" }, { label: null }]} currentAs="h1" />);
|
|
116
|
+
const heading = screen.getByRole("heading", { level: 1 });
|
|
117
|
+
// Mutation: the parent's name as the stand-in, which is a wrong title for as long as it shows.
|
|
118
|
+
expect(heading).toHaveTextContent("Loading...");
|
|
119
|
+
expect(heading).not.toHaveTextContent("Users");
|
|
120
|
+
expect(heading).toHaveAttribute("aria-busy", "true");
|
|
121
|
+
expect(heading.querySelector('[data-terp="breadcrumbs-pending"]')).not.toBeNull();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("recalls the leaf's last label at its path while the page reloads it", () => {
|
|
125
|
+
const labels = new Map<string, string>();
|
|
126
|
+
const { rerender } = render(within("/users/u1", labels, <Breadcrumbs items={[{ label: "Jane" }]} />));
|
|
127
|
+
// The same place, mounted again (a tab of the detail, or coming back): its record loads again.
|
|
128
|
+
rerender(within("/users/u1/", labels, <Breadcrumbs items={[{ label: "" }]} />));
|
|
129
|
+
expect(screen.getByText("Jane")).toHaveAttribute("aria-current", "page");
|
|
130
|
+
expect(document.querySelector('[data-terp="breadcrumbs-pending"]')).toBeNull();
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("recalls a parent one level down, where only the child page has loaded", () => {
|
|
134
|
+
const labels = new Map([["/users/u1", "Jane"]]);
|
|
135
|
+
render(
|
|
136
|
+
within(
|
|
137
|
+
"/users/u1/history",
|
|
138
|
+
labels,
|
|
139
|
+
<Breadcrumbs
|
|
140
|
+
items={[{ label: "Users", to: "/users" }, { label: null, to: "/users/u1?tab=a" }, { label: "History" }]}
|
|
141
|
+
/>,
|
|
142
|
+
),
|
|
143
|
+
);
|
|
144
|
+
// Mutation: a pending ancestor looked up by its raw `to`, query and all.
|
|
145
|
+
expect(screen.getByRole("link", { name: "Jane" })).toHaveAttribute("href", "/users/u1?tab=a");
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it("does not remember one place's label for another", () => {
|
|
149
|
+
const labels = new Map<string, string>();
|
|
150
|
+
const { rerender } = render(within("/users/u1", labels, <Breadcrumbs items={[{ label: "Jane" }]} />));
|
|
151
|
+
rerender(within("/users/u2", labels, <Breadcrumbs items={[{ label: null }]} />));
|
|
152
|
+
expect(screen.queryByText("Jane")).toBeNull();
|
|
153
|
+
expect(screen.getByText("Loading...")).toBeInTheDocument();
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("updates a crumb in place when its label arrives", () => {
|
|
157
|
+
const { rerender } = render(<Breadcrumbs items={[{ label: "Users", to: "/users" }, { label: null }]} />);
|
|
158
|
+
const [, leaf] = screen.getAllByRole("listitem");
|
|
159
|
+
rerender(<Breadcrumbs items={[{ label: "Users", to: "/users" }, { label: "Jane" }]} />);
|
|
160
|
+
// Mutation: keyed by its text, which replaced the crumb when the words arrived.
|
|
161
|
+
expect(screen.getAllByRole("listitem")[1]).toBe(leaf);
|
|
162
|
+
expect(leaf).toHaveTextContent("Jane");
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("only adds a crumb when the trail goes one level deeper", () => {
|
|
166
|
+
const { rerender } = render(<Breadcrumbs items={[{ label: "Users", to: "/users" }, { label: "Jane" }]} />);
|
|
167
|
+
const [root, jane] = screen.getAllByRole("listitem");
|
|
168
|
+
rerender(
|
|
169
|
+
<Breadcrumbs items={[{ label: "Users", to: "/users" }, { label: "Jane", to: "/users/u1" }, { label: "History" }]} />,
|
|
170
|
+
);
|
|
171
|
+
const after = screen.getAllByRole("listitem");
|
|
172
|
+
expect(after).toHaveLength(3);
|
|
173
|
+
expect(after[0]).toBe(root);
|
|
174
|
+
expect(after[1]).toBe(jane);
|
|
175
|
+
expect(screen.getByRole("link", { name: "Jane" })).toHaveAttribute("href", "/users/u1");
|
|
176
|
+
});
|
|
177
|
+
});
|
package/src/Breadcrumbs.tsx
CHANGED
|
@@ -2,6 +2,7 @@ import type { ReactNode } from "react";
|
|
|
2
2
|
|
|
3
3
|
import { injectTerpStyles } from "./styles";
|
|
4
4
|
import { useNavLink } from "./navLink";
|
|
5
|
+
import { useTrailMemory } from "./trailMemory";
|
|
5
6
|
import { useStrings, useUiText } from "./uiText";
|
|
6
7
|
import type { UiText } from "./uiText";
|
|
7
8
|
|
|
@@ -9,8 +10,13 @@ injectTerpStyles();
|
|
|
9
10
|
|
|
10
11
|
/** One breadcrumb: a label plus, for ancestor levels, the path it links back to. */
|
|
11
12
|
export interface BreadcrumbItem {
|
|
12
|
-
/**
|
|
13
|
-
|
|
13
|
+
/**
|
|
14
|
+
* The crumb text (e.g. the module title, or the record's display name). `null` (or `""`)
|
|
15
|
+
* while it is not known yet, such as a record still loading: the crumb then shows the last
|
|
16
|
+
* label it had at its path (ADR 0173), or a placeholder where it never had one. Never a
|
|
17
|
+
* stand-in such as the parent's name, which is a wrong name for as long as it shows.
|
|
18
|
+
*/
|
|
19
|
+
label: UiText | null;
|
|
14
20
|
/** Destination path for ancestor crumbs; the current page's crumb omits it. */
|
|
15
21
|
to?: string;
|
|
16
22
|
}
|
|
@@ -80,15 +86,42 @@ export function Breadcrumbs({ items, renderLink, currentAs = "span" }: Breadcrum
|
|
|
80
86
|
: (item: { label: string; to: string }) => navLink({ to: item.to, children: item.label }));
|
|
81
87
|
const strings = useStrings();
|
|
82
88
|
const resolve = useUiText();
|
|
89
|
+
const memory = useTrailMemory();
|
|
90
|
+
// Not known yet: a quiet bar of fixed width, read as "Loading" by assistive technology.
|
|
91
|
+
const pending = (
|
|
92
|
+
<span data-terp="breadcrumbs-pending">
|
|
93
|
+
<span data-terp="breadcrumbs-pending-text">{strings.loading}</span>
|
|
94
|
+
</span>
|
|
95
|
+
);
|
|
83
96
|
return (
|
|
84
97
|
<nav aria-label={strings.breadcrumbsLabel} data-terp="breadcrumbs">
|
|
85
98
|
<ol>
|
|
86
99
|
{items.map((item, index) => {
|
|
87
100
|
const isLast = index === items.length - 1;
|
|
88
|
-
|
|
101
|
+
// The place a crumb names: its link, or for the leaf the page the reader is on.
|
|
102
|
+
const path = item.to ?? (isLast ? memory?.pathname : undefined);
|
|
103
|
+
const given = item.label === null ? "" : resolve(item.label);
|
|
104
|
+
if (given !== "" && path !== undefined) memory?.remember(path, given);
|
|
105
|
+
const label = given !== "" ? given : path === undefined ? "" : (memory?.recall(path) ?? "");
|
|
89
106
|
return (
|
|
90
|
-
|
|
91
|
-
|
|
107
|
+
// Keyed by position, never by text: a label that arrives, or changes, is the same
|
|
108
|
+
// crumb with new words, so React updates it in place rather than replacing it.
|
|
109
|
+
<li key={index}>
|
|
110
|
+
{label === "" ? (
|
|
111
|
+
isLast && currentAs === "h1" ? (
|
|
112
|
+
<h1 aria-current="page" aria-busy="true" data-terp="page-title">
|
|
113
|
+
{pending}
|
|
114
|
+
</h1>
|
|
115
|
+
) : isLast ? (
|
|
116
|
+
<span aria-current="page" aria-busy="true" data-terp="breadcrumbs-current">
|
|
117
|
+
{pending}
|
|
118
|
+
</span>
|
|
119
|
+
) : (
|
|
120
|
+
// An ancestor not known yet is not a link either: a link with no words is
|
|
121
|
+
// one a screen reader announces as nothing.
|
|
122
|
+
<span>{pending}</span>
|
|
123
|
+
)
|
|
124
|
+
) : !isLast && item.to !== undefined ? (
|
|
92
125
|
renderCrumbLink({ label, to: item.to })
|
|
93
126
|
) : isLast && currentAs === "h1" ? (
|
|
94
127
|
// Two spelled-out branches rather than one element with a computed tag and a
|
package/src/ModuleNav.test.tsx
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
createRouter,
|
|
9
9
|
} from "@tanstack/react-router";
|
|
10
10
|
import { cleanup, render, screen, waitFor } from "@testing-library/react";
|
|
11
|
-
import { afterEach, describe, expect, it } from "vitest";
|
|
11
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
12
12
|
|
|
13
13
|
import { ModuleNav } from "./ModuleNav";
|
|
14
14
|
import { UiTextProvider } from "./uiText";
|
|
@@ -120,3 +120,31 @@ describe("ModuleNav", () => {
|
|
|
120
120
|
);
|
|
121
121
|
});
|
|
122
122
|
});
|
|
123
|
+
|
|
124
|
+
describe("ModuleNav on a strip too narrow for its tabs", () => {
|
|
125
|
+
it("scrolls the strip, not the page, until the current tab is in view", async () => {
|
|
126
|
+
// jsdom lays nothing out, so the boxes are given: a strip 200px wide, and the current tab
|
|
127
|
+
// past its right edge, at 250 to 320.
|
|
128
|
+
const boxes = vi
|
|
129
|
+
.spyOn(HTMLElement.prototype, "getBoundingClientRect")
|
|
130
|
+
.mockImplementation(function (this: HTMLElement) {
|
|
131
|
+
const at = (left: number, right: number) =>
|
|
132
|
+
({ left, right, top: 0, bottom: 20, width: right - left, height: 20, x: left, y: 0 }) as DOMRect;
|
|
133
|
+
if (this.dataset.terp === "module-nav-list") return at(0, 200);
|
|
134
|
+
if (this.dataset.active === "true") return at(250, 320);
|
|
135
|
+
return at(0, 0);
|
|
136
|
+
});
|
|
137
|
+
try {
|
|
138
|
+
renderWithRouter("/tickets/projects");
|
|
139
|
+
const list = await waitFor(() => {
|
|
140
|
+
const found = document.querySelector<HTMLElement>('[data-terp="module-nav-list"]');
|
|
141
|
+
expect(found?.scrollLeft).toBe(120);
|
|
142
|
+
return found;
|
|
143
|
+
});
|
|
144
|
+
// Mutation: no scroll at all, or the item's own offset scrolled to rather than the overrun.
|
|
145
|
+
expect(list?.scrollLeft).toBe(120);
|
|
146
|
+
} finally {
|
|
147
|
+
boxes.mockRestore();
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
});
|
package/src/ModuleNav.tsx
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Link, useRouterState } from "@tanstack/react-router";
|
|
2
|
+
import { useRef } from "react";
|
|
2
3
|
|
|
4
|
+
import { useCurrentInView } from "./currentInView";
|
|
3
5
|
import { activeNavPath } from "./navActive";
|
|
4
6
|
import { useStrings, useUiText } from "./uiText";
|
|
5
7
|
import type { UiText } from "./uiText";
|
|
@@ -49,6 +51,8 @@ export function ModuleNav({ items, ariaLabel }: ModuleNavProps) {
|
|
|
49
51
|
// diverged from its own Link in both directions, as the sheet's comment on the active rule
|
|
50
52
|
// says. Longest match wins, so `/records` does not steal from `/records/mapping`.
|
|
51
53
|
const activeTo = activeNavPath(pathname, items);
|
|
54
|
+
const list = useRef<HTMLUListElement>(null);
|
|
55
|
+
useCurrentInView(list, activeTo, '[data-active="true"]');
|
|
52
56
|
|
|
53
57
|
if (items.length === 0) {
|
|
54
58
|
return null;
|
|
@@ -56,7 +60,7 @@ export function ModuleNav({ items, ariaLabel }: ModuleNavProps) {
|
|
|
56
60
|
|
|
57
61
|
return (
|
|
58
62
|
<nav aria-label={resolve(ariaLabel ?? strings.moduleNavigationLabel)} data-terp="module-nav">
|
|
59
|
-
<ul data-terp="module-nav-list">
|
|
63
|
+
<ul ref={list} data-terp="module-nav-list">
|
|
60
64
|
{items.map((item) => {
|
|
61
65
|
const label = resolve(item.label);
|
|
62
66
|
const isActive = item.to === activeTo;
|
package/src/Page.tsx
CHANGED
|
@@ -21,8 +21,13 @@ import { resolveUiTextNode, useUiText } from "./uiText";
|
|
|
21
21
|
import type { UiText, UiTextNode } from "./uiText";
|
|
22
22
|
|
|
23
23
|
export interface PageProps {
|
|
24
|
-
/**
|
|
25
|
-
|
|
24
|
+
/**
|
|
25
|
+
* The page heading (rendered as the single `h1`). `null` while it is not known yet — a
|
|
26
|
+
* detail page's record still loading: the heading then keeps the name it had at this path,
|
|
27
|
+
* or a placeholder on a first visit (ADR 0173). Pass `record?.name ?? null`, never the
|
|
28
|
+
* parent's name as a stand-in, which is a wrong heading for as long as it shows.
|
|
29
|
+
*/
|
|
30
|
+
title: UiText | null;
|
|
26
31
|
/** Ancestor breadcrumb trail, outermost first; the current page's crumb is appended automatically. */
|
|
27
32
|
breadcrumbs?: readonly BreadcrumbItem[];
|
|
28
33
|
/** Link renderer for ancestor crumbs; defaults to the surrounding router's `Link` (see {@link Breadcrumbs}). */
|
|
@@ -271,13 +276,21 @@ export function Page({
|
|
|
271
276
|
// branch, and a conditional written at the attribute is the form the marker scanner reads
|
|
272
277
|
// every string literal out of.
|
|
273
278
|
const measureAttribute = measure === "narrow" ? "narrow" : undefined;
|
|
279
|
+
// A workspace fills the height the shell leaves it (ADR 0179). Read from the slot owner the
|
|
280
|
+
// archetype already provides, so there is no prop for any other page to set.
|
|
281
|
+
const fillAttribute = slotOwner === "WorkspacePage" ? "workspace" : undefined;
|
|
274
282
|
// The same renderability test as the band's meta: `summary={figures && <StatGroup/>}` hands
|
|
275
283
|
// this `false` before the figures arrive, and an empty band would still take its padding.
|
|
276
284
|
const hasSummary =
|
|
277
285
|
showsBody && summary !== undefined && summary !== null && summary !== false && summary !== "";
|
|
278
286
|
return (
|
|
279
287
|
<HeadlineContext.Provider value={headlineRegistry}>
|
|
280
|
-
<article
|
|
288
|
+
<article
|
|
289
|
+
ref={articleRef}
|
|
290
|
+
data-terp="page"
|
|
291
|
+
data-measure={measureAttribute}
|
|
292
|
+
data-fill={fillAttribute}
|
|
293
|
+
>
|
|
281
294
|
{/* A <header> ELEMENT, and it has to stay one. The slot check above drops the header
|
|
282
295
|
from the body set by tagName, so re-rendering this as a marked <div> would put it
|
|
283
296
|
back in and fail every governed OverviewPage / DetailPage closed. The marker is
|
package/src/Stat.test.tsx
CHANGED
|
@@ -339,3 +339,38 @@ describe("Stat's colours are declared pairings", () => {
|
|
|
339
339
|
}
|
|
340
340
|
});
|
|
341
341
|
});
|
|
342
|
+
|
|
343
|
+
describe("a figure with no value", () => {
|
|
344
|
+
it("marks its dash as empty, and a zero as a value", () => {
|
|
345
|
+
const { container } = renderIn(
|
|
346
|
+
"en",
|
|
347
|
+
<>
|
|
348
|
+
<Stat label="Nothing" value={null} />
|
|
349
|
+
<Stat label="Blank" value="" />
|
|
350
|
+
<Stat label="Zero" value={0} />
|
|
351
|
+
</>,
|
|
352
|
+
);
|
|
353
|
+
const values = [...container.querySelectorAll('[data-terp="stat-value"]')].map((value) => [
|
|
354
|
+
value.textContent,
|
|
355
|
+
value.getAttribute("data-empty"),
|
|
356
|
+
]);
|
|
357
|
+
// Mutations: no mark, so the dash keeps the value's ink; or a zero taken for nothing.
|
|
358
|
+
expect(values).toEqual([
|
|
359
|
+
["—", "true"],
|
|
360
|
+
["—", "true"],
|
|
361
|
+
["0", null],
|
|
362
|
+
]);
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
it("draws the dash in the quiet ink, and leaves a headline's ink alone", () => {
|
|
366
|
+
const rule =
|
|
367
|
+
/\[data-terp="stat"\]:not\(\[data-headline\]\) \[data-terp="stat-value"\]\[data-empty\] \{([^}]*)\}/.exec(
|
|
368
|
+
TERP_STYLES_CSS,
|
|
369
|
+
);
|
|
370
|
+
// Mutation: the rule without :not([data-headline]), which would put the subtle ink on the
|
|
371
|
+
// headline's brand fill, the one surface it was never measured against.
|
|
372
|
+
expect(rule, "an empty value has a rule of its own, outside a headline").not.toBeNull();
|
|
373
|
+
expect(rule![1]).toContain("color: var(--color-fg-subtle)");
|
|
374
|
+
expect(rule![1]).toContain("font-weight: var(--font-weight-normal)");
|
|
375
|
+
});
|
|
376
|
+
});
|
package/src/Stat.tsx
CHANGED
|
@@ -244,7 +244,9 @@ export function Stat({
|
|
|
244
244
|
return (
|
|
245
245
|
<span data-terp="stat" data-headline={headline ? "true" : undefined}>
|
|
246
246
|
<span data-terp="stat-label">{resolve(label)}</span>
|
|
247
|
-
<span data-terp="stat-value"
|
|
247
|
+
<span data-terp="stat-value" data-empty={printed === DASH ? "true" : undefined}>
|
|
248
|
+
{printed}
|
|
249
|
+
</span>
|
|
248
250
|
{delta !== undefined && direction !== undefined && (
|
|
249
251
|
<span data-terp="stat-delta">
|
|
250
252
|
<span data-terp="stat-change" data-sentiment={sentiment}>
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { cleanup, render, screen } from "@testing-library/react";
|
|
3
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
4
|
+
|
|
5
|
+
import { DashboardPage } from "./DashboardPage";
|
|
6
|
+
import { Page } from "./Page";
|
|
7
|
+
import { CanvasHost, WorkspacePage } from "./WorkspacePage";
|
|
8
|
+
|
|
9
|
+
afterEach(cleanup);
|
|
10
|
+
|
|
11
|
+
describe("WorkspacePage (ADR 0179)", () => {
|
|
12
|
+
it("marks its page as the one that fills the shell", () => {
|
|
13
|
+
const { container } = render(
|
|
14
|
+
<WorkspacePage title="Network">
|
|
15
|
+
<CanvasHost label="Network diagram">
|
|
16
|
+
<svg viewBox="0 0 10 10" />
|
|
17
|
+
</CanvasHost>
|
|
18
|
+
</WorkspacePage>,
|
|
19
|
+
);
|
|
20
|
+
const page = container.querySelector('[data-terp="page"]');
|
|
21
|
+
expect(page?.getAttribute("data-fill")).toBe("workspace");
|
|
22
|
+
expect(screen.getByRole("heading", { level: 1 }).textContent).toBe("Network");
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("leaves every other page as it was", () => {
|
|
26
|
+
// Mutation: stamp data-fill on every page, and every main becomes a flex column.
|
|
27
|
+
for (const page of [
|
|
28
|
+
<Page key="page" title="Plain">body</Page>,
|
|
29
|
+
<DashboardPage key="dashboard" title="Overview">body</DashboardPage>,
|
|
30
|
+
]) {
|
|
31
|
+
const { container, unmount } = render(page);
|
|
32
|
+
expect(container.querySelector('[data-terp="page"]')?.hasAttribute("data-fill")).toBe(false);
|
|
33
|
+
unmount();
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("takes its parent trail as parents, as DashboardPage does", () => {
|
|
38
|
+
render(
|
|
39
|
+
<WorkspacePage title="Network" parents={[{ label: "Sites", to: "/sites" }]}>
|
|
40
|
+
<CanvasHost label="Network diagram">
|
|
41
|
+
<svg viewBox="0 0 10 10" />
|
|
42
|
+
</CanvasHost>
|
|
43
|
+
</WorkspacePage>,
|
|
44
|
+
);
|
|
45
|
+
expect(screen.getByRole("link", { name: "Sites" }).getAttribute("href")).toBe("/sites");
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe("CanvasHost", () => {
|
|
50
|
+
it("is a named region carrying the canvas", () => {
|
|
51
|
+
render(
|
|
52
|
+
<CanvasHost label={{ id: "network.canvas", message: "Network diagram" }}>
|
|
53
|
+
<svg data-testid="drawing" viewBox="0 0 10 10" />
|
|
54
|
+
</CanvasHost>,
|
|
55
|
+
);
|
|
56
|
+
const region = screen.getByRole("region", { name: "Network diagram" });
|
|
57
|
+
expect(region.getAttribute("data-terp")).toBe("canvas-host");
|
|
58
|
+
// The canvas sits in the host's one layer, which is what gives it a definite box.
|
|
59
|
+
// Mutation: render the children straight into the section, and a canvas root that sizes
|
|
60
|
+
// to its container resolves its percentage height against a flex-grown box.
|
|
61
|
+
const layer = region.firstElementChild;
|
|
62
|
+
expect(region.children).toHaveLength(1);
|
|
63
|
+
expect(layer?.getAttribute("data-terp")).toBe("canvas-host-layer");
|
|
64
|
+
expect(layer?.firstElementChild).toBe(screen.getByTestId("drawing"));
|
|
65
|
+
// It renders no inline style: its geometry is the stylesheet's.
|
|
66
|
+
expect(region.hasAttribute("style")).toBe(false);
|
|
67
|
+
expect(layer?.hasAttribute("style")).toBe(false);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
|
|
3
|
+
import type { BreadcrumbItem } from "./Breadcrumbs";
|
|
4
|
+
import { LayoutSlotContext } from "./layoutContract";
|
|
5
|
+
import { Page } from "./Page";
|
|
6
|
+
import type { PageProps } from "./Page";
|
|
7
|
+
import { injectTerpStyles } from "./styles";
|
|
8
|
+
import { useUiText } from "./uiText";
|
|
9
|
+
import type { UiText } from "./uiText";
|
|
10
|
+
|
|
11
|
+
injectTerpStyles();
|
|
12
|
+
|
|
13
|
+
export type WorkspacePageProps = Omit<PageProps, "breadcrumbs" | "measure"> & {
|
|
14
|
+
/** Optional parent layers for a workspace nested below a hub or an area. */
|
|
15
|
+
parents?: readonly (BreadcrumbItem & { to: string })[];
|
|
16
|
+
/**
|
|
17
|
+
* The workspace: one {@link CanvasHost}, or a framework state while it loads or fails, and a
|
|
18
|
+
* `ConfirmDialog` for an action taken on it.
|
|
19
|
+
*
|
|
20
|
+
* The body takes every pixel the shell leaves below the band, and the canvas takes the
|
|
21
|
+
* body. Under a layout contract nothing else is admitted, because a second block beside the
|
|
22
|
+
* canvas would have to share a height nobody declared. One host, too: two would split the
|
|
23
|
+
* height between them.
|
|
24
|
+
*/
|
|
25
|
+
children: ReactNode;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The workspace archetype: one canvas that fills the screen (ADR 0179).
|
|
30
|
+
*
|
|
31
|
+
* For the screen whose work IS a surface rather than a list or a record: a diagram of nodes
|
|
32
|
+
* and the connections between them, a floor plan, a planning board. Every other archetype
|
|
33
|
+
* lays its body out as blocks that take the height of their content, and a canvas has no
|
|
34
|
+
* content height of its own — it takes the box it is given — so before this a canvas could
|
|
35
|
+
* only be sized with an inline style, which app code may not write.
|
|
36
|
+
*
|
|
37
|
+
* The frame is the ordinary page band, trail, actions and summary included. Below it the body
|
|
38
|
+
* fills the rest of the shell's content column: the shell's main area becomes a flex column
|
|
39
|
+
* when it holds a workspace (the same `:has()` scoping the page-sequence bar uses, so no other
|
|
40
|
+
* page changes), the page grows into it, and the {@link CanvasHost} grows into the page. A
|
|
41
|
+
* loading, error or empty state in the canvas's place grows the same way, so the frame does
|
|
42
|
+
* not jump when the canvas arrives. Standalone, outside a shell, the canvas keeps a floor of
|
|
43
|
+
* 24rem.
|
|
44
|
+
*
|
|
45
|
+
* It takes its trail as `parents` and provides `LayoutSlotContext`, as `DashboardPage` does:
|
|
46
|
+
* `Page` verifies the body's children against the contract's `WorkspacePage` slot and stamps
|
|
47
|
+
* `data-fill` on the article when it is the workspace's.
|
|
48
|
+
*/
|
|
49
|
+
export function WorkspacePage({ parents, ...page }: WorkspacePageProps): ReactNode {
|
|
50
|
+
return (
|
|
51
|
+
<LayoutSlotContext.Provider value="WorkspacePage">
|
|
52
|
+
<Page {...page} breadcrumbs={parents} />
|
|
53
|
+
</LayoutSlotContext.Provider>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface CanvasHostProps {
|
|
58
|
+
/**
|
|
59
|
+
* The canvas's accessible name.
|
|
60
|
+
*
|
|
61
|
+
* Required: the host is a `<section>`, so a landmark, and an unnamed one is an entry in a
|
|
62
|
+
* screen reader's landmark list that says nothing about what is on it.
|
|
63
|
+
*/
|
|
64
|
+
label: UiText;
|
|
65
|
+
/**
|
|
66
|
+
* The canvas itself: ONE `<svg>` the app draws, or the root of ONE canvas component.
|
|
67
|
+
*
|
|
68
|
+
* The host lays an inner layer over its whole box, absolutely at inset 0, so the layer has a
|
|
69
|
+
* definite size whatever the page around it does, and the child is sized to 100% of that
|
|
70
|
+
* layer. So an `<svg>` fills the box and scales its drawing by its `viewBox`, and a canvas
|
|
71
|
+
* component whose root sizes itself to its container gets all of it. Every child takes the
|
|
72
|
+
* whole layer, which is why the host takes one: a second sibling does not share the box, it
|
|
73
|
+
* lands below the first, outside the visible area, and is clipped. A `ConfirmDialog` is the
|
|
74
|
+
* exception and is left at its own size.
|
|
75
|
+
*
|
|
76
|
+
* The host's subtree is the app's to compose, as a `Card`'s body is: the contract governs the
|
|
77
|
+
* workspace's direct children, not what is drawn on the canvas.
|
|
78
|
+
*/
|
|
79
|
+
children: ReactNode;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The surface a {@link WorkspacePage} fills: a named, bounded region that takes the page's
|
|
84
|
+
* remaining height and lays its one canvas over the whole of it. A workspace holds one host.
|
|
85
|
+
*
|
|
86
|
+
* It paints from tokens only — the surface fill, the hairline and the radius a `Card` uses —
|
|
87
|
+
* so it reads as a block of the page in every theme, and it clips what is drawn on it, so a
|
|
88
|
+
* canvas panned past its edge does not paint over the band. Because it clips, a focus ring
|
|
89
|
+
* drawn around the canvas would be clipped with it, so the host draws the framework's focus
|
|
90
|
+
* ring on itself while the canvas has keyboard focus. It renders no inline style.
|
|
91
|
+
*/
|
|
92
|
+
export function CanvasHost({ label, children }: CanvasHostProps) {
|
|
93
|
+
const resolve = useUiText();
|
|
94
|
+
return (
|
|
95
|
+
<section data-terp="canvas-host" aria-label={resolve(label)}>
|
|
96
|
+
{/* The layer is what gives the canvas a definite box. The host's own height comes from
|
|
97
|
+
flex growth, which a child's percentage height cannot resolve against, and a canvas
|
|
98
|
+
library's root is positioned by the library's own sheet rather than by ours. The
|
|
99
|
+
layer is ours alone, absolutely positioned at inset 0, so its size is definite. */}
|
|
100
|
+
<div data-terp="canvas-host-layer">{children}</div>
|
|
101
|
+
</section>
|
|
102
|
+
);
|
|
103
|
+
}
|