@tristan2828/ui-foundation 4.106.0 → 4.108.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/conventions/docs/add-an-entity.md +71 -27
- package/dist/api/contracts.d.ts +8 -1
- package/dist/api/gateway/environment.js +9 -1
- package/dist/api/gateway/errors.d.ts +7 -0
- package/dist/api/gateway/errors.js +32 -0
- package/dist/api/transport/index.d.ts +10 -0
- package/dist/api/transport/index.js +45 -3
- package/dist/components/app/entity-view.d.ts +5 -3
- package/dist/components/app/entity-view.js +21 -8
- package/dist/components/app/error-state.js +12 -2
- package/dist/components/app/module-card.js +1 -1
- package/dist/components/ui/badge.d.ts +1 -1
- package/dist/components/ui/button.d.ts +1 -1
- package/dist/gateway.d.ts +1 -1
- package/dist/gateway.js +1 -1
- package/package.json +1 -1
|
@@ -3,29 +3,30 @@
|
|
|
3
3
|
<!-- index: written by `npm run docs:index` in the package from the headings below; never edit it by hand -->
|
|
4
4
|
## Index
|
|
5
5
|
|
|
6
|
-
- [The reference files](#the-reference-files) · lines
|
|
7
|
-
- [Before anything: the entity plan](#before-anything-the-entity-plan) · lines
|
|
8
|
-
- Step 1: Add `<Entity>` to `openapi.yaml` · lines
|
|
9
|
-
- Step 2: `npm run gen:api` · lines
|
|
10
|
-
- Step 3: Add gateway tests in `tests/gateway/<entity>.test.ts`, derived from the spec · lines
|
|
11
|
-
- Step 4: Add MSW handlers in `src/mocks/<entity>.ts` · lines
|
|
12
|
-
- Step 5: Add a gateway module in `src/api/gateway/<entity>.ts` · lines
|
|
13
|
-
- Step 6: Copy the reference files, one for one, not just the two screens · lines
|
|
14
|
-
- Step 7: Register routes · lines
|
|
15
|
-
- Step 8: Add Playwright specs for all three screens · lines
|
|
16
|
-
- Step 9: Register the nav entry and route names · lines
|
|
17
|
-
- Step 10: `npm run verify`. · lines
|
|
18
|
-
- [How a list opens a record](#how-a-list-opens-a-record) · lines
|
|
19
|
-
- [The record view](#the-record-view) · lines
|
|
20
|
-
- [Forms](#forms) · lines
|
|
21
|
-
- [Dialogs](#dialogs) · lines
|
|
22
|
-
- [Toasts and feedback](#toasts-and-feedback) · lines
|
|
23
|
-
- [What not to copy](#what-not-to-copy) · lines
|
|
24
|
-
- [After a commit, in the backend](#after-a-commit-in-the-backend) · lines
|
|
25
|
-
- [Deleting](#deleting) · lines
|
|
26
|
-
- [Fields only a script writes](#fields-only-a-script-writes) · lines
|
|
27
|
-
- [Searching one part of the app](#searching-one-part-of-the-app) · lines
|
|
28
|
-
- [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines
|
|
6
|
+
- [The reference files](#the-reference-files) · lines 45–67
|
|
7
|
+
- [Before anything: the entity plan](#before-anything-the-entity-plan) · lines 69–850
|
|
8
|
+
- Step 1: Add `<Entity>` to `openapi.yaml` · lines 111–118
|
|
9
|
+
- Step 2: `npm run gen:api` · lines 119–120
|
|
10
|
+
- Step 3: Add gateway tests in `tests/gateway/<entity>.test.ts`, derived from the spec · lines 121–132
|
|
11
|
+
- Step 4: Add MSW handlers in `src/mocks/<entity>.ts` · lines 133–142
|
|
12
|
+
- Step 5: Add a gateway module in `src/api/gateway/<entity>.ts` · lines 143–149
|
|
13
|
+
- Step 6: Copy the reference files, one for one, not just the two screens · lines 150–738
|
|
14
|
+
- Step 7: Register routes · lines 739–754
|
|
15
|
+
- Step 8: Add Playwright specs for all three screens · lines 755–832
|
|
16
|
+
- Step 9: Register the nav entry and route names · lines 833–847
|
|
17
|
+
- Step 10: `npm run verify`. · lines 848–850
|
|
18
|
+
- [How a list opens a record](#how-a-list-opens-a-record) · lines 852–1252
|
|
19
|
+
- [The record view](#the-record-view) · lines 1005–1102
|
|
20
|
+
- [Forms](#forms) · lines 1104–1169
|
|
21
|
+
- [Dialogs](#dialogs) · lines 1171–1202
|
|
22
|
+
- [Toasts and feedback](#toasts-and-feedback) · lines 1204–1252
|
|
23
|
+
- [What not to copy](#what-not-to-copy) · lines 1254–1286
|
|
24
|
+
- [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 1288–1305
|
|
25
|
+
- [Deleting](#deleting) · lines 1307–1338
|
|
26
|
+
- [Fields only a script writes](#fields-only-a-script-writes) · lines 1340–1361
|
|
27
|
+
- [Searching one part of the app](#searching-one-part-of-the-app) · lines 1363–1372
|
|
28
|
+
- [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1375–1417
|
|
29
|
+
- [Behind a sign-in proxy](#behind-a-sign-in-proxy) · lines 1419–1455
|
|
29
30
|
|
|
30
31
|
<!-- /index -->
|
|
31
32
|
|
|
@@ -143,7 +144,9 @@ is a filled-in example while the Widgets demo is still here).
|
|
|
143
144
|
tests pass, built on `safeFetch`/`toAppError` from
|
|
144
145
|
`@tristan2828/ui-foundation/gateway` (see `src/api/gateway/widgets.ts`).
|
|
145
146
|
Wire → `Page<T>` / `AppError` translation only; no hand-written types
|
|
146
|
-
(everything comes from `schema.d.ts`).
|
|
147
|
+
(everything comes from `schema.d.ts`). A proxy's sign-in page or redirect never
|
|
148
|
+
reaches it: `safeFetch` throws kind `proxy_auth` first
|
|
149
|
+
([Behind a sign-in proxy](#behind-a-sign-in-proxy)).
|
|
147
150
|
6. **Copy the reference files, one for one, not just the two screens**
|
|
148
151
|
(the Widgets demo's, or the ones the app's `### Reference files` names) — shaped by the plan: table columns and sortable columns from
|
|
149
152
|
its "List" column, toolbar filters from its "Filter" column, form fields
|
|
@@ -1043,9 +1046,12 @@ A record uses the parts it has, in this order:
|
|
|
1043
1046
|
4.81), so the short facts read as a list of pairs rather than a column
|
|
1044
1047
|
of labels; keep labels to a word or two.
|
|
1045
1048
|
- **The facts rail** (4.106, record standard A1): `factsRail` on the
|
|
1046
|
-
view puts the record's short facts in a 300px column beside the
|
|
1047
|
-
|
|
1048
|
-
dialog), so the page doesn't end 900px in.
|
|
1049
|
+
view puts the record's short facts in a 300px column beside the
|
|
1050
|
+
record's body where the view has room (60rem: a laptop's page, a record
|
|
1051
|
+
dialog), so the page doesn't end 900px in. The strip stays above it at
|
|
1052
|
+
full width, and the rail starts level with the first content under the
|
|
1053
|
+
strip: the open tab's first section (beside the tab's content, not its
|
|
1054
|
+
bar), or the first card when cards come before the tabs (4.108). Only short values go in it,
|
|
1049
1055
|
and the API holds to that: a rail section is `facts`, not `fields`,
|
|
1050
1056
|
each fact one of a few kinds, never free markup:
|
|
1051
1057
|
|
|
@@ -1409,3 +1415,41 @@ def note(caller, tool, arguments, entities):
|
|
|
1409
1415
|
register_entities(ENTITIES, instructions="Amounts are in the account's currency.")
|
|
1410
1416
|
register_answer_note(note)
|
|
1411
1417
|
```
|
|
1418
|
+
|
|
1419
|
+
## Behind a sign-in proxy
|
|
1420
|
+
|
|
1421
|
+
An app put behind an identity-aware proxy that has its own sign-in
|
|
1422
|
+
(Cloudflare Access is the usual one; an OAuth proxy or a VPN gateway's
|
|
1423
|
+
portal works the same way) can outlive that sign-in: the page stays open,
|
|
1424
|
+
the proxy's session lapses, and the next request gets the proxy's answer
|
|
1425
|
+
instead of the app's. The foundation handles it (4.107), with nothing for
|
|
1426
|
+
the app to write:
|
|
1427
|
+
|
|
1428
|
+
- **The request asks for JSON as a script.** `safeFetch` sends
|
|
1429
|
+
`Accept: application/json` and `X-Requested-With: XMLHttpRequest`
|
|
1430
|
+
(unless the gateway module set its own) and doesn't follow redirects
|
|
1431
|
+
(`redirect: "manual"`, unless the module passes `"follow"`), so a proxy
|
|
1432
|
+
that can answers a script with a 401, and one that can't answers with a
|
|
1433
|
+
redirect the browser doesn't chase to another origin.
|
|
1434
|
+
- **The proxy's answer becomes one `AppError`, kind `proxy_auth`.**
|
|
1435
|
+
`safeFetch` throws it, before your gateway module sees the response,
|
|
1436
|
+
for: a page (`text/html`) on a 2xx, 401 or 403; a 401 or 403 whose body
|
|
1437
|
+
isn't JSON; a redirect not followed (an opaque redirect); and a redirect
|
|
1438
|
+
followed to another origin. A step 5 gateway module needs no change.
|
|
1439
|
+
The app's own answers are untouched: a JSON 401 is still `auth` (the
|
|
1440
|
+
app's session, which sends the person to `/login`), and a 404, 422, 429
|
|
1441
|
+
or 5xx, JSON or not, is what `toAppError` always made it.
|
|
1442
|
+
- **The screens say "Sign In Again".** `ErrorState` (every `DataTable`,
|
|
1443
|
+
`EntityView`, `WidgetCard`, `Board`, the shell's own session check) and
|
|
1444
|
+
`ModuleCard` show "Sign-in expired" with a **Sign In Again** button in
|
|
1445
|
+
place of any retry. It reloads the whole page, so the proxy's sign-in
|
|
1446
|
+
runs and brings the person back. A screen with its own error UI checks
|
|
1447
|
+
`error.kind === 'proxy_auth'` and offers the same reload.
|
|
1448
|
+
- **Your contract tests don't change.** `openapi.yaml` and the step 3
|
|
1449
|
+
gateway tests describe the app's own responses, never the proxy's; the
|
|
1450
|
+
proxy isn't part of the contract. `proxyAuthError()` (from
|
|
1451
|
+
`@tristan2828/ui-foundation/gateway`) is the error itself, for a mock or
|
|
1452
|
+
a test of a screen's state.
|
|
1453
|
+
- **On the proxy's side**, nothing is required. Where it offers a 401 for
|
|
1454
|
+
scripts instead of a redirect (Cloudflare Access does for requests with
|
|
1455
|
+
`X-Requested-With`), either answer works.
|
package/dist/api/contracts.d.ts
CHANGED
|
@@ -5,7 +5,14 @@ export type Page<T> = {
|
|
|
5
5
|
pageSize: number;
|
|
6
6
|
};
|
|
7
7
|
export type AppError = {
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* `proxy_auth`: the answer came from something in front of the app (an
|
|
10
|
+
* identity-aware proxy such as Cloudflare Access) whose own sign-in has
|
|
11
|
+
* lapsed, not from the app: a page or a redirect where JSON was
|
|
12
|
+
* expected. Only a full page load signs in again. Not the app's own
|
|
13
|
+
* session, which is `auth`.
|
|
14
|
+
*/
|
|
15
|
+
kind: "validation" | "notfound" | "auth" | "rate_limited" | "server" | "network" | "proxy_auth";
|
|
9
16
|
message: string;
|
|
10
17
|
fieldErrors?: Record<string, string[]>;
|
|
11
18
|
/**
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { safeFetch, toAppError } from "./errors.js";
|
|
2
2
|
export async function getDataLabel() {
|
|
3
|
-
|
|
3
|
+
let res;
|
|
4
|
+
try {
|
|
5
|
+
res = await safeFetch("/environment");
|
|
6
|
+
}
|
|
7
|
+
catch (error) {
|
|
8
|
+
if (error.kind === "proxy_auth")
|
|
9
|
+
return null;
|
|
10
|
+
throw error;
|
|
11
|
+
}
|
|
4
12
|
if (res.status === 404)
|
|
5
13
|
return null;
|
|
6
14
|
if (res.status !== 200)
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { type ApiResponse } from "../transport/index.js";
|
|
2
2
|
import type { AppError } from "../contracts.js";
|
|
3
3
|
export declare function safeFetch(path: string, init?: RequestInit): Promise<ApiResponse>;
|
|
4
|
+
/**
|
|
5
|
+
* The AppError for a lapsed sign-in at a proxy in front of the app (kind
|
|
6
|
+
* `proxy_auth`): only a full page load can sign in again, which
|
|
7
|
+
* `ErrorState` offers ("Sign In Again"). `safeFetch` throws it itself, so
|
|
8
|
+
* an app's gateway modules need no change to get it.
|
|
9
|
+
*/
|
|
10
|
+
export declare function proxyAuthError(status?: number): AppError;
|
|
4
11
|
export declare function httpStatusOf(error: AppError): number | undefined;
|
|
5
12
|
export declare function toAppError(status: number, body: unknown, headers?: Headers): AppError;
|
|
6
13
|
export declare function networkError(): AppError;
|
|
@@ -18,8 +18,40 @@ export async function safeFetch(path, init) {
|
|
|
18
18
|
throw networkError();
|
|
19
19
|
}
|
|
20
20
|
reportAnswered();
|
|
21
|
+
if (isProxySignIn(response))
|
|
22
|
+
throw proxyAuthError(response.status);
|
|
21
23
|
return response;
|
|
22
24
|
}
|
|
25
|
+
// What a proxy in front of the app (an identity-aware proxy such as
|
|
26
|
+
// Cloudflare Access) sends once its own sign-in has lapsed, in place of
|
|
27
|
+
// the app's JSON: any redirect (never in an app's contract), or a page or
|
|
28
|
+
// unparseable body on a success, a 401 or a 403. The app's own 401 and
|
|
29
|
+
// 403 are always JSON (the foundation's error envelopes), so they still
|
|
30
|
+
// reach toAppError as before. Anything else not JSON (a load balancer's
|
|
31
|
+
// 502 page, say) is left to the caller's toAppError, as before.
|
|
32
|
+
function isProxySignIn(response) {
|
|
33
|
+
const { foreign, status } = response;
|
|
34
|
+
if (foreign === "opaque-redirect" || foreign === "cross-origin-redirect")
|
|
35
|
+
return true;
|
|
36
|
+
if (foreign === "html" && status >= 200 && status < 300)
|
|
37
|
+
return true;
|
|
38
|
+
return (foreign === "html" || foreign === "not-json") && (status === 401 || status === 403);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The AppError for a lapsed sign-in at a proxy in front of the app (kind
|
|
42
|
+
* `proxy_auth`): only a full page load can sign in again, which
|
|
43
|
+
* `ErrorState` offers ("Sign In Again"). `safeFetch` throws it itself, so
|
|
44
|
+
* an app's gateway modules need no change to get it.
|
|
45
|
+
*/
|
|
46
|
+
export function proxyAuthError(status) {
|
|
47
|
+
const error = {
|
|
48
|
+
kind: "proxy_auth",
|
|
49
|
+
message: "Your sign-in has expired. Reload the page to sign in again.",
|
|
50
|
+
};
|
|
51
|
+
if (status)
|
|
52
|
+
STATUS.set(error, status);
|
|
53
|
+
return error;
|
|
54
|
+
}
|
|
23
55
|
/**
|
|
24
56
|
* Pass the response's `headers` so a 429 carries its Retry-After
|
|
25
57
|
* (`retryAfterSeconds`); without them it's still `rate_limited`.
|
|
@@ -3,5 +3,15 @@ export type ApiResponse = {
|
|
|
3
3
|
body: unknown;
|
|
4
4
|
/** The response's headers (a 429's Retry-After, for one). */
|
|
5
5
|
headers: Headers;
|
|
6
|
+
/**
|
|
7
|
+
* Set when the answer can't be the app's own API speaking JSON, the way
|
|
8
|
+
* an identity-aware proxy in front of the app answers once its sign-in
|
|
9
|
+
* has lapsed: `html` (a page where JSON was expected), `not-json` (a
|
|
10
|
+
* body that doesn't parse as JSON), `cross-origin-redirect` (followed to
|
|
11
|
+
* another origin) or `opaque-redirect` (a redirect not followed). The
|
|
12
|
+
* gateway decides what it means (`safeFetch`). Absent on every ordinary
|
|
13
|
+
* response.
|
|
14
|
+
*/
|
|
15
|
+
foreign?: "html" | "not-json" | "cross-origin-redirect" | "opaque-redirect";
|
|
6
16
|
};
|
|
7
17
|
export declare function apiFetch(path: string, init?: RequestInit): Promise<ApiResponse>;
|
|
@@ -4,11 +4,53 @@
|
|
|
4
4
|
// Owns the base URL and the raw HTTP call; knows nothing about widgets,
|
|
5
5
|
// pagination, or error shapes — that translation is the gateway's job.
|
|
6
6
|
const BASE_URL = "/api";
|
|
7
|
+
// Sent unless the caller set them: they tell a proxy in front of the app
|
|
8
|
+
// that this is a script asking for JSON, not a page, so a proxy that can
|
|
9
|
+
// answers a lapsed sign-in with a 401 rather than a redirect to its login
|
|
10
|
+
// page (Cloudflare Access reads X-Requested-With; others read Accept).
|
|
11
|
+
const DEFAULT_HEADERS = [
|
|
12
|
+
["accept", "application/json"],
|
|
13
|
+
["x-requested-with", "XMLHttpRequest"],
|
|
14
|
+
];
|
|
7
15
|
export async function apiFetch(path, init) {
|
|
8
|
-
const
|
|
16
|
+
const headers = new Headers(init?.headers);
|
|
17
|
+
for (const [name, value] of DEFAULT_HEADERS)
|
|
18
|
+
if (!headers.has(name))
|
|
19
|
+
headers.set(name, value);
|
|
20
|
+
// A redirect is never part of the app's contract. A proxy's redirect to
|
|
21
|
+
// its login page on another origin, if followed, fails as a network
|
|
22
|
+
// error that can't be told from being offline; not followed, it comes
|
|
23
|
+
// back as an opaque redirect the gateway can name. A caller can still
|
|
24
|
+
// pass `redirect: "follow"`.
|
|
25
|
+
const response = await fetch(`${BASE_URL}${path}`, { ...init, headers, redirect: init?.redirect ?? "manual" });
|
|
26
|
+
if (response.type === "opaqueredirect") {
|
|
27
|
+
return { status: response.status, body: undefined, headers: response.headers, foreign: "opaque-redirect" };
|
|
28
|
+
}
|
|
29
|
+
if (response.redirected && isOtherOrigin(response.url)) {
|
|
30
|
+
return { status: response.status, body: undefined, headers: response.headers, foreign: "cross-origin-redirect" };
|
|
31
|
+
}
|
|
9
32
|
if (response.status === 204) {
|
|
10
33
|
return { status: response.status, body: undefined, headers: response.headers };
|
|
11
34
|
}
|
|
12
|
-
const
|
|
13
|
-
|
|
35
|
+
const html = (response.headers.get("content-type") ?? "").toLowerCase().includes("text/html");
|
|
36
|
+
let parsed = true;
|
|
37
|
+
const body = await response.json().catch(() => {
|
|
38
|
+
parsed = false;
|
|
39
|
+
return undefined;
|
|
40
|
+
});
|
|
41
|
+
const foreign = html ? "html" : parsed ? undefined : "not-json";
|
|
42
|
+
return foreign
|
|
43
|
+
? { status: response.status, body, headers: response.headers, foreign }
|
|
44
|
+
: { status: response.status, body, headers: response.headers };
|
|
45
|
+
}
|
|
46
|
+
function isOtherOrigin(url) {
|
|
47
|
+
const here = globalThis.location?.origin;
|
|
48
|
+
if (!here || !url)
|
|
49
|
+
return false;
|
|
50
|
+
try {
|
|
51
|
+
return new URL(url).origin !== here;
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
14
56
|
}
|
|
@@ -224,9 +224,11 @@ export type EntityViewProps = {
|
|
|
224
224
|
* The facts rail (4.106, record standard A1), in the `tabs` layout:
|
|
225
225
|
* where the view has room (60rem beside it: a laptop's page, a record
|
|
226
226
|
* dialog), the sections of short facts (`facts`, placed `rail`, no
|
|
227
|
-
* `tab`) go in a 300px column beside the
|
|
228
|
-
* Details
|
|
229
|
-
*
|
|
227
|
+
* `tab`) go in a 300px column beside the record's body, and leave
|
|
228
|
+
* Details. The strip stays above, full width; the rail starts level with
|
|
229
|
+
* the first content under it (the open tab's first section, or the first
|
|
230
|
+
* card when cards come before the tabs; 4.108). A Details tab left with
|
|
231
|
+
* nothing isn't drawn. Narrower (a phone), they're in Details as before. Sections with `fields` or
|
|
230
232
|
* `content` never go in it: a rail holds short values only.
|
|
231
233
|
*/
|
|
232
234
|
factsRail?: boolean;
|
|
@@ -186,12 +186,18 @@ const RAIL_LAYOUT = {
|
|
|
186
186
|
sticky: '@4xl/view:data-[fits]:sticky @4xl/view:data-[fits]:top-6',
|
|
187
187
|
};
|
|
188
188
|
// The facts rail (A1): the record's column at its usual reading width
|
|
189
|
-
// (max-w-4xl) and a 300px rail beside it
|
|
189
|
+
// (max-w-4xl) and a 300px rail beside it. The strip stays above both, at
|
|
190
|
+
// full width; the rail starts level with the first content under it: the
|
|
191
|
+
// first section of the open tab (beside the tab's content, never its bar),
|
|
192
|
+
// or the first card when the record's first content isn't the tabs (4.108).
|
|
190
193
|
const FACTS_RAIL = {
|
|
191
194
|
page: 'max-w-[calc(var(--container-4xl)+var(--spacing)*6+300px)]',
|
|
192
195
|
columns: 'grid grid-cols-[minmax(0,1fr)_300px] items-start gap-6',
|
|
193
196
|
main: 'flex min-w-0 flex-col gap-6',
|
|
194
|
-
rail: 'flex min-w-0 flex-col gap-6',
|
|
197
|
+
rail: 'col-start-2 row-start-1 flex min-w-0 flex-col gap-6',
|
|
198
|
+
// The tab bar over the column only: the rail's 300px and the gap (the
|
|
199
|
+
// bar's own -mx-1 bleed kept on its left).
|
|
200
|
+
barBeside: 'mr-[calc(300px+var(--spacing)*5)]',
|
|
195
201
|
};
|
|
196
202
|
/** A section of short facts placed `rail` with no tab: the facts rail's, where it's drawn. */
|
|
197
203
|
function isRailFacts(section) {
|
|
@@ -302,7 +308,7 @@ function useStuck() {
|
|
|
302
308
|
}, [marker, bar]);
|
|
303
309
|
return { setMarker, setBar, stuck };
|
|
304
310
|
}
|
|
305
|
-
function MainTabs({ tabs, label, railFields = 'beside', title, counts, stickyTop, }) {
|
|
311
|
+
function MainTabs({ tabs, label, railFields = 'beside', title, counts, stickyTop, aside, }) {
|
|
306
312
|
const { setMarker, setBar, stuck } = useStuck();
|
|
307
313
|
const countOf = (tab) => {
|
|
308
314
|
if (!counts)
|
|
@@ -323,13 +329,16 @@ function MainTabs({ tabs, label, railFields = 'beside', title, counts, stickyTop
|
|
|
323
329
|
const search = params.toString();
|
|
324
330
|
void navigate({ pathname: location.pathname, search: search ? `?${search}` : '', hash: location.hash }, { replace: true, state: location.state, preventScrollReset: true });
|
|
325
331
|
};
|
|
332
|
+
// Kept mounted, the closed tabs are hidden (no box), so beside the rail
|
|
333
|
+
// only the open one takes the first column.
|
|
334
|
+
const panels = tabs.map((tab) => (_jsx(TabsContent, { value: tab.slug, keepMounted: true, className: cn('@container/tab flex min-w-0 flex-col gap-6 [font-size:inherit]', aside !== undefined && 'col-start-1 row-start-1'), children: _jsx(TabBody, { tab: tab, railFields: railFields }) }, tab.slug)));
|
|
326
335
|
return (_jsxs(Tabs, { value: selected, onValueChange: (value) => select(String(value)), "data-slot": "entity-view-tabs", className: "min-w-0 gap-6", children: [_jsx("div", { ref: setMarker, "aria-hidden": "true", "data-slot": "entity-view-tabs-marker", className: "h-px -mb-6" }), _jsxs("div", { ref: setBar, "data-slot": "entity-view-tab-bar", "data-stuck": stuck ? '' : undefined,
|
|
327
336
|
// A record dialog's body sets --entity-view-sticky-top to minus its
|
|
328
337
|
// padding, so the bar sits at the body's own top edge there.
|
|
329
|
-
style: { top: stickyTop ?? 'var(--entity-view-sticky-top, 0px)' }, className:
|
|
338
|
+
style: { top: stickyTop ?? 'var(--entity-view-sticky-top, 0px)' }, className: cn('sticky z-10 -mx-1 flex min-w-0 flex-col gap-1 bg-background px-1 pt-0 data-[stuck]:pt-2 data-[stuck]:shadow-[0_8px_12px_-10px_var(--color-foreground)]', aside !== undefined && FACTS_RAIL.barBeside), children: [stuck && title && (_jsx("p", { "data-slot": "entity-view-tab-bar-title", "aria-hidden": "true", className: "truncate type-label font-semibold text-foreground", children: title })), _jsx(TabsList, { variant: "line", activateOnFocus: true, "aria-label": label, className: "h-auto w-full max-w-full justify-start gap-0 overflow-x-auto overflow-y-hidden border-b border-border p-0 md:gap-1 [scrollbar-width:thin]", children: tabs.map((tab) => {
|
|
330
339
|
const count = countOf(tab);
|
|
331
340
|
return (_jsxs(TabsTrigger, { value: tab.slug, className: "h-11 flex-none gap-1.5 px-2.5 text-sm font-semibold text-muted-foreground group-data-horizontal/tabs:after:bottom-0 group-data-horizontal/tabs:after:h-[3px] after:bg-primary data-active:text-primary-text md:px-4 md:text-base dark:text-muted-foreground dark:data-active:text-primary-text", children: [tab.name, count > 0 && (_jsx("span", { "data-slot": "entity-view-tab-count", className: "rounded-full bg-muted px-1.5 text-xs leading-[1.0625rem] font-medium tabular-nums text-foreground", children: count }))] }, tab.slug));
|
|
332
|
-
}) })] }),
|
|
341
|
+
}) })] }), aside === undefined ? (panels) : (_jsxs("div", { "data-slot": "entity-view-with-facts", className: FACTS_RAIL.columns, children: [panels, aside] }))] }));
|
|
333
342
|
}
|
|
334
343
|
// The `tabs` layout's sections (1A): the main column's untabbed sections,
|
|
335
344
|
// then the tab list, with the facts (placed `rail`, no tab) as the last
|
|
@@ -406,7 +415,11 @@ export function EntityView({ title, documentTitle, titleEdit, leading, subtitle,
|
|
|
406
415
|
const shaped = layout === 'tabs' ? tabsLayout(railFacts.length > 0 ? sections.filter((section) => !isRailFacts(section)) : sections, detailsTab) : null;
|
|
407
416
|
const tabs = shaped ? shaped.tabs : tabsOf(mainSections);
|
|
408
417
|
const tabbed = (section) => section.placement !== 'rail' && section.tab !== undefined;
|
|
409
|
-
const
|
|
418
|
+
const factsAside = railFacts.length > 0 && (_jsx("aside", { "aria-label": factsRailLabel ?? `${title ?? 'Record'} facts`, "data-slot": "entity-view-facts-rail", className: FACTS_RAIL.rail, children: railFacts.map((section) => (_jsx(ViewSection, { section: section, inRail: true, factsRail: true }, section.title))) }));
|
|
419
|
+
// The record's first content under the strip is the tab bar: the rail
|
|
420
|
+
// goes in the tabs, beside the open tab's content.
|
|
421
|
+
const factsInTabs = factsAside !== false && shaped !== null && shaped.above.length === 0 && tabs.length > 0;
|
|
422
|
+
const tabList = tabs.length > 0 && (_jsx(MainTabs, { tabs: tabs, label: tabsLabel, railFields: railFields, title: title, counts: tabCounts, stickyTop: tabsStickyTop, aside: factsInTabs ? factsAside : undefined }));
|
|
410
423
|
const main = (_jsxs("div", { className: cn(RAIL_LAYOUT.main, railSections.length === 0 && RAIL_LAYOUT.mainAlone), children: [mainSections
|
|
411
424
|
.filter((section) => !tabbed(section))
|
|
412
425
|
.map((section) => (_jsx(ViewSection, { section: section }, section.title))), tabList] }));
|
|
@@ -420,7 +433,7 @@ export function EntityView({ title, documentTitle, titleEdit, leading, subtitle,
|
|
|
420
433
|
else if (shaped) {
|
|
421
434
|
const column = (_jsxs(_Fragment, { children: [shaped.above.map((section) => section.placement === 'rail' ? (_jsx(ViewSection, { section: section, inRail: true, railFields: railFields }, section.title)) : (_jsx(ViewSection, { section: section }, section.title))), tabList] }));
|
|
422
435
|
body =
|
|
423
|
-
|
|
436
|
+
factsAside !== false && !factsInTabs ? (_jsxs("div", { "data-slot": "entity-view-with-facts", className: FACTS_RAIL.columns, children: [_jsx("div", { className: cn(FACTS_RAIL.main, 'col-start-1 row-start-1'), children: column }), factsAside] })) : (column);
|
|
424
437
|
}
|
|
425
438
|
else {
|
|
426
439
|
body = (_jsxs(_Fragment, { children: [sections
|
|
@@ -429,5 +442,5 @@ export function EntityView({ title, documentTitle, titleEdit, leading, subtitle,
|
|
|
429
442
|
}
|
|
430
443
|
return (_jsx(EditInPlaceContext.Provider, { value: store, children: _jsx(EmptyContext.Provider, { value: { text: emptyText, fold: emptyFields === 'fold' }, children: _jsxs("div", { ref: setRoot, className: layout === 'rail' && !card
|
|
431
444
|
? RAIL_LAYOUT.page
|
|
432
|
-
: cn('flex flex-col', railFacts.length > 0 ? FACTS_RAIL.page : 'max-w-4xl', card ? 'gap-4' : 'gap-6'), "data-facts-rail": railFacts.length > 0 ? '' : undefined, "data-state": "success", "data-layout": layout, "data-look": card ? 'card' : undefined, children: [editing && _jsx(LeaveGuard, { store: store }), !dialog && !trail && _jsx(BackLink, { back: back }), !dialog && trail && !inShell && _jsx(PageTrail, { crumbs: trail }), _jsxs("header", { className: card ? 'flex items-start justify-between gap-3' : 'flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between', children: [_jsxs("div", { className: cn('flex min-w-0 flex-1 items-start gap-3', !card && 'sm:min-w-64 sm:gap-4'), children: [leading && (_jsx("div", { "data-slot": "entity-view-leading", className: "flex shrink-0 items-center", children: leading })), _jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-2", children: [_jsxs("div", { "data-slot": "entity-view-title-line", className: "flex min-w-0 flex-wrap items-center gap-x-3 gap-y-2", children: [_jsx("h1", { id: dialog?.titleId, className: cn('min-w-0 max-w-full break-words text-foreground', card ? 'type-section-title' : 'type-page-title'), children: titleEdit ? (_jsx(EditableField, { label: titleEdit.label, edit: titleEdit, layout: "inline", keepPencilRoom: true, children: title })) : (title) }), badges && (_jsx("div", { "data-slot": "entity-view-badges", className: "flex flex-wrap items-center gap-1.5", children: badges }))] }), subtitle && (_jsx("div", { "data-slot": "entity-view-subtitle", className: "type-body break-words text-muted-foreground", children: subtitle }))] })] }), card ? (_jsxs("div", { "data-slot": "entity-view-card-controls", className: "flex shrink-0 items-center gap-1", children: [printButton, actions, dialog?.controls] })) : ((actions || printButton) && (_jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-2 sm:justify-end", children: [printButton, actions] })))] }), _jsx("div", { role: "status", "data-slot": "entity-view-notice", className: "empty:hidden", children: notice }), strip && (!card || cardStrip) &&
|
|
445
|
+
: cn('flex flex-col', railFacts.length > 0 ? FACTS_RAIL.page : 'max-w-4xl', card ? 'gap-4' : 'gap-6'), "data-facts-rail": railFacts.length > 0 ? '' : undefined, "data-state": "success", "data-layout": layout, "data-look": card ? 'card' : undefined, children: [editing && _jsx(LeaveGuard, { store: store }), !dialog && !trail && _jsx(BackLink, { back: back }), !dialog && trail && !inShell && _jsx(PageTrail, { crumbs: trail }), _jsxs("header", { className: card ? 'flex items-start justify-between gap-3' : 'flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between', children: [_jsxs("div", { className: cn('flex min-w-0 flex-1 items-start gap-3', !card && 'sm:min-w-64 sm:gap-4'), children: [leading && (_jsx("div", { "data-slot": "entity-view-leading", className: "flex shrink-0 items-center", children: leading })), _jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-2", children: [_jsxs("div", { "data-slot": "entity-view-title-line", className: "flex min-w-0 flex-wrap items-center gap-x-3 gap-y-2", children: [_jsx("h1", { id: dialog?.titleId, className: cn('min-w-0 max-w-full break-words text-foreground', card ? 'type-section-title' : 'type-page-title'), children: titleEdit ? (_jsx(EditableField, { label: titleEdit.label, edit: titleEdit, layout: "inline", keepPencilRoom: true, children: title })) : (title) }), badges && (_jsx("div", { "data-slot": "entity-view-badges", className: "flex flex-wrap items-center gap-1.5", children: badges }))] }), subtitle && (_jsx("div", { "data-slot": "entity-view-subtitle", className: "type-body break-words text-muted-foreground", children: subtitle }))] })] }), card ? (_jsxs("div", { "data-slot": "entity-view-card-controls", className: "flex shrink-0 items-center gap-1", children: [printButton, actions, dialog?.controls] })) : ((actions || printButton) && (_jsxs("div", { className: "flex min-w-0 flex-wrap items-center gap-2 sm:justify-end", children: [printButton, actions] })))] }), _jsx("div", { role: "status", "data-slot": "entity-view-notice", className: "empty:hidden", children: notice }), strip && (!card || cardStrip) && _jsx("div", { "data-slot": "entity-view-strip", children: strip }), body, footer && (_jsx("footer", { "data-slot": "entity-view-footer", className: "type-caption text-muted-foreground", children: footer }))] }) }) }));
|
|
433
446
|
}
|
|
@@ -9,7 +9,12 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
9
9
|
// `compact` is the same state for a small container (a WidgetCard): less
|
|
10
10
|
// padding and the icon beside the title instead of in a box above it, so
|
|
11
11
|
// one failing widget reads as that widget's problem, not the page's.
|
|
12
|
-
|
|
12
|
+
//
|
|
13
|
+
// Kind `proxy_auth` (a lapsed sign-in at a proxy in front of the app, such
|
|
14
|
+
// as Cloudflare Access) offers "Sign In Again" in place of any retry: a
|
|
15
|
+
// full page load, so the proxy's own sign-in runs. Retrying the request
|
|
16
|
+
// would only get the proxy's page again.
|
|
17
|
+
import { AlertCircleIcon, LogInIcon } from 'lucide-react';
|
|
13
18
|
import { cn } from 'cn';
|
|
14
19
|
import { Button } from '../ui/button.js';
|
|
15
20
|
import { Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle, } from '../ui/empty.js';
|
|
@@ -20,8 +25,13 @@ const TITLE_BY_KIND = {
|
|
|
20
25
|
auth: 'Not authorized',
|
|
21
26
|
rate_limited: 'Too many attempts',
|
|
22
27
|
validation: 'Check the form',
|
|
28
|
+
proxy_auth: 'Sign-in expired',
|
|
23
29
|
};
|
|
30
|
+
function reloadPage() {
|
|
31
|
+
window.location.reload();
|
|
32
|
+
}
|
|
24
33
|
export function ErrorState({ error, onRetry, size = 'default', className, }) {
|
|
25
34
|
const compact = size === 'compact';
|
|
26
|
-
|
|
35
|
+
const signInAgain = error.kind === 'proxy_auth';
|
|
36
|
+
return (_jsxs(Empty, { className: cn(compact && 'gap-3 p-4', className), "data-state": "error", "data-size": size, children: [_jsxs(EmptyHeader, { className: cn(compact && 'gap-1'), children: [compact ? (_jsxs(EmptyTitle, { className: "flex items-center gap-1.5", children: [_jsx(AlertCircleIcon, { "aria-hidden": "true", className: "size-4 shrink-0 text-destructive-text" }), TITLE_BY_KIND[error.kind]] })) : (_jsxs(_Fragment, { children: [_jsx(EmptyMedia, { variant: "icon", children: _jsx(AlertCircleIcon, { className: "text-destructive-text" }) }), _jsx(EmptyTitle, { children: TITLE_BY_KIND[error.kind] })] })), _jsx(EmptyDescription, { children: error.message })] }), signInAgain ? (_jsx(EmptyContent, { children: _jsxs(Button, { size: "sm", onClick: reloadPage, children: [_jsx(LogInIcon, { "aria-hidden": "true" }), "Sign In Again"] }) })) : (onRetry && (_jsx(EmptyContent, { children: _jsx(Button, { size: "sm", variant: "outline", onClick: onRetry, children: "Try Again" }) })))] }));
|
|
27
37
|
}
|
|
@@ -116,7 +116,7 @@ export function ModuleCard({ title, icon: Icon, category, to, href, value, note,
|
|
|
116
116
|
'data-slot': 'module-card-band',
|
|
117
117
|
className: cn(BAND_LINK_CLASS, category && BAND_CLASS[category]),
|
|
118
118
|
};
|
|
119
|
-
const card = (_jsxs(Card, { "data-slot": "module-card", "data-state": state, className: cn('glow-edge relative h-full min-w-0 gap-0 py-0', mobile === 'row' && 'max-md:hidden', className), children: [href !== undefined ? (_jsxs("a", { href: href, target: "_blank", rel: "noreferrer", ...bandProps, children: [band, _jsx(NewTabMark, {})] })) : (_jsx(Link, { to: to, ...bandProps, children: band })), _jsxs("div", { id: bodyId, "data-slot": "module-card-body", "aria-busy": state === 'loading' || undefined, className: "flex flex-1 flex-col gap-0.5 px-3 py-2 density-compact:py-1.5 max-sm:px-2", children: [state === 'error' ? (_jsxs(_Fragment, { children: [_jsxs("p", { className: "flex items-center gap-1.5 type-body text-foreground", children: [_jsx(AlertCircleIcon, { "aria-hidden": "true", className: "size-4 shrink-0 text-destructive-text" }), _jsxs("span", { className: "min-w-0", children: ["Couldn't load", error?.message && _jsxs("span", { className: "sr-only", children: [": ", error.message] })] })] }), onRetry && (_jsx(Button, { size: "sm", variant: "outline", onClick: onRetry, "aria-describedby": titleId, className: "relative z-10 mt-1 self-start", children: "Retry" }))] })) : state === 'loading' ? (_jsxs(_Fragment, { children: [_jsx("span", { className: "sr-only", children: "Loading" }), _jsx(Skeleton, { "data-state": "loading", className: "my-0.5 h-6 w-12" })] })) : (value !== undefined && (_jsx("span", { "data-slot": "module-card-value", className: "type-numeric text-foreground", children: value }))), note && state !== 'error' && (_jsx("span", { className: "truncate type-body text-muted-foreground", title: note, children: note }))] }), action &&
|
|
119
|
+
const card = (_jsxs(Card, { "data-slot": "module-card", "data-state": state, className: cn('glow-edge relative h-full min-w-0 gap-0 py-0', mobile === 'row' && 'max-md:hidden', className), children: [href !== undefined ? (_jsxs("a", { href: href, target: "_blank", rel: "noreferrer", ...bandProps, children: [band, _jsx(NewTabMark, {})] })) : (_jsx(Link, { to: to, ...bandProps, children: band })), _jsxs("div", { id: bodyId, "data-slot": "module-card-body", "aria-busy": state === 'loading' || undefined, className: "flex flex-1 flex-col gap-0.5 px-3 py-2 density-compact:py-1.5 max-sm:px-2", children: [state === 'error' ? (_jsxs(_Fragment, { children: [_jsxs("p", { className: "flex items-center gap-1.5 type-body text-foreground", children: [_jsx(AlertCircleIcon, { "aria-hidden": "true", className: "size-4 shrink-0 text-destructive-text" }), _jsxs("span", { className: "min-w-0", children: ["Couldn't load", error?.message && _jsxs("span", { className: "sr-only", children: [": ", error.message] })] })] }), error?.kind === 'proxy_auth' ? (_jsx(Button, { size: "sm", variant: "outline", onClick: () => window.location.reload(), "aria-describedby": titleId, className: "relative z-10 mt-1 self-start", children: "Sign In Again" })) : (onRetry && (_jsx(Button, { size: "sm", variant: "outline", onClick: onRetry, "aria-describedby": titleId, className: "relative z-10 mt-1 self-start", children: "Retry" })))] })) : state === 'loading' ? (_jsxs(_Fragment, { children: [_jsx("span", { className: "sr-only", children: "Loading" }), _jsx(Skeleton, { "data-state": "loading", className: "my-0.5 h-6 w-12" })] })) : (value !== undefined && (_jsx("span", { "data-slot": "module-card-value", className: "type-numeric text-foreground", children: value }))), note && state !== 'error' && (_jsx("span", { className: "truncate type-body text-muted-foreground", title: note, children: note }))] }), action &&
|
|
120
120
|
(action.href !== undefined ? (_jsxs("a", { href: action.href, target: "_blank", rel: "noreferrer", "aria-describedby": titleId, className: ACTION_CLASS, children: [_jsx("span", { className: "truncate", children: action.label }), _jsx(NewTabMark, {})] })) : (_jsx(Link, { to: action.to, "aria-describedby": titleId, className: ACTION_CLASS, children: _jsx("span", { className: "truncate", children: action.label }) })))] }));
|
|
121
121
|
if (mobile === 'tiles')
|
|
122
122
|
return card;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useRender } from "@base-ui/react/use-render";
|
|
2
2
|
import { type VariantProps } from "class-variance-authority";
|
|
3
3
|
declare const badgeVariants: (props?: ({
|
|
4
|
-
variant?: "
|
|
4
|
+
variant?: "default" | "link" | "success" | "outline" | "secondary" | "ghost" | "destructive" | "solid" | "info" | "warning" | "outline-success" | "outline-warning" | "outline-info" | "outline-destructive" | "tinted-success" | "tinted-warning" | "tinted-info" | "tinted-destructive" | null | undefined;
|
|
5
5
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
6
6
|
declare function Badge({ className, variant, render, ...props }: useRender.ComponentProps<"span"> & VariantProps<typeof badgeVariants>): import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>>;
|
|
7
7
|
export { Badge, badgeVariants };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Button as ButtonPrimitive } from "@base-ui/react/button";
|
|
2
2
|
import { type VariantProps } from "class-variance-authority";
|
|
3
3
|
declare const buttonVariants: (props?: ({
|
|
4
|
-
variant?: "
|
|
4
|
+
variant?: "default" | "link" | "outline" | "secondary" | "ghost" | "destructive" | null | undefined;
|
|
5
5
|
size?: "default" | "xs" | "sm" | "lg" | "icon" | "icon-xs" | "icon-sm" | "icon-lg" | null | undefined;
|
|
6
6
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
7
7
|
declare function Button({ className, variant, size, ...props }: ButtonPrimitive.Props & VariantProps<typeof buttonVariants>): import("react").JSX.Element;
|
package/dist/gateway.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { networkError, safeFetch, toAppError } from './api/gateway/errors.js';
|
|
1
|
+
export { networkError, proxyAuthError, safeFetch, toAppError } from './api/gateway/errors.js';
|
|
2
2
|
export type { ApiResponse } from './api/transport/index.js';
|
package/dist/gateway.js
CHANGED
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
// (src/api/gateway/<entity>.ts) build on: the single fetch path and the
|
|
3
3
|
// wire-error -> AppError translation. Lint allows importing this only from
|
|
4
4
|
// src/api/gateway/, which is what keeps every other layer off the network.
|
|
5
|
-
export { networkError, safeFetch, toAppError } from './api/gateway/errors.js';
|
|
5
|
+
export { networkError, proxyAuthError, safeFetch, toAppError } from './api/gateway/errors.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tristan2828/ui-foundation",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.108.0",
|
|
4
4
|
"description": "Shared UI foundation for contract-first, database-backed React apps: shadcn primitives, DataTable/EntityForm composites, auth, the gateway error seam, design tokens, lint rules and the AI playbook.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|