@tristan2828/ui-foundation 4.114.0 → 4.115.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 +39 -13
- package/conventions/docs/design-language.md +31 -6
- package/dist/components/app/editable-value.d.ts +9 -7
- package/dist/components/app/editable-value.js +6 -1
- package/dist/components/app/entity-view-facts.d.ts +53 -4
- package/dist/components/app/entity-view-facts.js +48 -4
- package/dist/components/app/entity-view.d.ts +1 -1
- package/dist/components/app/entity-view.js +25 -4
- package/dist/components/app/keep-pencil-room.d.ts +1 -0
- package/dist/components/app/keep-pencil-room.js +7 -0
- package/dist/components/app/key-stats.js +5 -4
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -15,18 +15,18 @@
|
|
|
15
15
|
- Step 8: Add Playwright specs for all three screens · lines 755–832
|
|
16
16
|
- Step 9: Register the nav entry and route names · lines 833–847
|
|
17
17
|
- Step 10: `npm run verify`. · lines 848–850
|
|
18
|
-
- [How a list opens a record](#how-a-list-opens-a-record) · lines 852–
|
|
19
|
-
- [The record view](#the-record-view) · lines 1005–
|
|
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
|
|
29
|
-
- [Behind a sign-in proxy](#behind-a-sign-in-proxy) · lines
|
|
18
|
+
- [How a list opens a record](#how-a-list-opens-a-record) · lines 852–1287
|
|
19
|
+
- [The record view](#the-record-view) · lines 1005–1132
|
|
20
|
+
- [Forms](#forms) · lines 1134–1204
|
|
21
|
+
- [Dialogs](#dialogs) · lines 1206–1237
|
|
22
|
+
- [Toasts and feedback](#toasts-and-feedback) · lines 1239–1287
|
|
23
|
+
- [What not to copy](#what-not-to-copy) · lines 1289–1321
|
|
24
|
+
- [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 1323–1340
|
|
25
|
+
- [Deleting](#deleting) · lines 1342–1373
|
|
26
|
+
- [Fields only a script writes](#fields-only-a-script-writes) · lines 1375–1396
|
|
27
|
+
- [Searching one part of the app](#searching-one-part-of-the-app) · lines 1398–1407
|
|
28
|
+
- [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1410–1452
|
|
29
|
+
- [Behind a sign-in proxy](#behind-a-sign-in-proxy) · lines 1454–1490
|
|
30
30
|
|
|
31
31
|
<!-- /index -->
|
|
32
32
|
|
|
@@ -1023,7 +1023,9 @@ A record uses the parts it has, in this order:
|
|
|
1023
1023
|
notes is an icon of EntityView's own.
|
|
1024
1024
|
- **Strip**: the record's key numbers and ratings (`strip`, a
|
|
1025
1025
|
`KeyStats`, as wide as its numbers since 4.98), each edited in place
|
|
1026
|
-
where it's shown.
|
|
1026
|
+
where it's shown. An inline `EditableValue` there keeps its pencil's room
|
|
1027
|
+
at rest (4.115), so nothing moves on hover; an app's own wrapping row of
|
|
1028
|
+
inline values passes `keepPencilRoom` for the same.
|
|
1027
1029
|
- **Sections** (4.98, no right rail): one column. The label/value facts
|
|
1028
1030
|
are placed `rail`, which makes them the last tab, Details, on a record
|
|
1029
1031
|
with tabs, and keeps them in the column on one without; the long text
|
|
@@ -1082,6 +1084,30 @@ A record uses the parts it has, in this order:
|
|
|
1082
1084
|
nothing isn't drawn. On a phone (or a view under 60rem) the rail's
|
|
1083
1085
|
sections are back in Details, as rows.
|
|
1084
1086
|
- `edit` works on a fact as on a field; at rest it's drawn by its kind.
|
|
1087
|
+
- **The status first** (4.115): a record's status is the first fact at
|
|
1088
|
+
the top of the right rail, edited in place there; a status that
|
|
1089
|
+
changes only through an action stays read-only, with the action as a
|
|
1090
|
+
small button under it and a tooltip saying why. Mark it
|
|
1091
|
+
`recordStatus: true` and the view puts it first, wherever it is in
|
|
1092
|
+
`facts`:
|
|
1093
|
+
|
|
1094
|
+
```tsx
|
|
1095
|
+
{ label: 'Status', recordStatus: true, kind: 'status', status: STATUS_KINDS[record.status], word: STATUS_LABELS[record.status],
|
|
1096
|
+
// Editable in place:
|
|
1097
|
+
edit: inPlace.select({ ... }),
|
|
1098
|
+
// Or, changed only by an action (closing records a date and a reason):
|
|
1099
|
+
hint: 'Changes when the record is closed.',
|
|
1100
|
+
action: { label: 'Close…', render: (button) => <CloseRecord record={record} trigger={button} /> } }
|
|
1101
|
+
```
|
|
1102
|
+
|
|
1103
|
+
`action` is a small button under the value: `onClick`, or `render`,
|
|
1104
|
+
which is given the button so the app's own action (its dialog) opens
|
|
1105
|
+
from it with the same look (`<DialogTrigger render={button} />`).
|
|
1106
|
+
`hint` is an info button after the value, its words in a tooltip on
|
|
1107
|
+
hover and keyboard focus, and a line under the value on a touch
|
|
1108
|
+
screen. Both are drawn in Details too, where the rail folds.
|
|
1109
|
+
- A `badges` item may be `{ label, icon }` (4.115): the icon (a
|
|
1110
|
+
component or a node) before the label, in the muted tone.
|
|
1085
1111
|
- **A tiny record** (4.98: a few fields and no notes, like a lookup's
|
|
1086
1112
|
row) opens as a small card: `RecordDialogRoute look="card"`, usually
|
|
1087
1113
|
with `fullPage={false}`. A 420px dialog (a sheet on a phone), its
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
- [A few equal things](#a-few-equal-things) · lines 1427–1511
|
|
34
34
|
- [An overview page](#an-overview-page) · lines 1513–1576
|
|
35
35
|
- [A record's header and empty values](#a-records-header-and-empty-values) · lines 1577–1628
|
|
36
|
-
- [A record's tabs, mark and facts](#a-records-tabs-mark-and-facts) · lines 1630–
|
|
37
|
-
- [Picking at random](#picking-at-random) · lines
|
|
38
|
-
- [Filling in what's missing](#filling-in-whats-missing) · lines
|
|
39
|
-
- [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines
|
|
40
|
-
- [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines
|
|
36
|
+
- [A record's tabs, mark and facts](#a-records-tabs-mark-and-facts) · lines 1630–1736
|
|
37
|
+
- [Picking at random](#picking-at-random) · lines 1738–1769
|
|
38
|
+
- [Filling in what's missing](#filling-in-whats-missing) · lines 1771–1838
|
|
39
|
+
- [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1840–1865
|
|
40
|
+
- [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 1867–1963
|
|
41
41
|
|
|
42
42
|
<!-- /index -->
|
|
43
43
|
|
|
@@ -1689,8 +1689,33 @@ its short facts the last tab, Details. A mark goes left of the title.
|
|
|
1689
1689
|
bullet otherwise, in the muted colour; a wrapped line starts after the
|
|
1690
1690
|
mark (a hanging indent), and items have a little room between them.
|
|
1691
1691
|
Never a bare stack of links.
|
|
1692
|
+
- **The record's status** (4.115): a record's status is the first fact at
|
|
1693
|
+
the top of the right rail, edited in place there; a status that changes
|
|
1694
|
+
only through an action stays read-only, with the action as a small
|
|
1695
|
+
button under it and a tooltip saying why. Mark it `recordStatus: true`
|
|
1696
|
+
and EntityView draws it first, whatever its place in `facts` and its
|
|
1697
|
+
section's among the rail's, and first in Details where the rail folds.
|
|
1698
|
+
One per record.
|
|
1699
|
+
- **An action under a fact** (`action`, 4.115): a small outline button
|
|
1700
|
+
(`xs`, 44px tall on a touch screen) under the value, its words a verb
|
|
1701
|
+
("Close…", an ellipsis when it opens a dialog), an icon before them if
|
|
1702
|
+
the app's actions have one. For the status above, and for any read-only
|
|
1703
|
+
fact that one action changes. Never several: more belong in the
|
|
1704
|
+
header's actions.
|
|
1705
|
+
- **Why a fact can't be edited here** (`hint`, 4.115): a few words, in a
|
|
1706
|
+
tooltip on a small info button after the value, shown on hover and on
|
|
1707
|
+
keyboard focus, and read with the button by a screen reader. A touch
|
|
1708
|
+
screen has no hover, so there the words are a caption line under the
|
|
1709
|
+
value instead. Nothing that only hover shows.
|
|
1710
|
+
- **Icons on badges** (4.115): a `badges` fact's items may each carry an
|
|
1711
|
+
icon (a component or a node) before the label, at the badge's icon size
|
|
1712
|
+
in the muted tone a list's item icons have; items without one stay
|
|
1713
|
+
words alone. The label always stays.
|
|
1692
1714
|
- **The strip** (`KeyStats`) is as wide as its numbers (`width="content"`,
|
|
1693
|
-
the default since 4.98), not the page's width.
|
|
1715
|
+
the default since 4.98), not the page's width. **Nothing in it moves on
|
|
1716
|
+
hover or focus** (4.115): a value edited in place inline keeps its
|
|
1717
|
+
pencil's room at rest there, as in a table cell, so a click lands on the
|
|
1718
|
+
value under the mouse, wrapped onto two lines on a phone too.
|
|
1694
1719
|
- **A mark or avatar** (`leading`): left of the title, top-aligned,
|
|
1695
1720
|
with the title, subtitle and badges beside it at every width. 40 to
|
|
1696
1721
|
64px (`size-10` to `size-16`): an avatar round (`rounded-full`), a
|
|
@@ -16,6 +16,14 @@ export type EditableValueProps = {
|
|
|
16
16
|
* have); under 48rem or on a touch screen a chevron, not the pencil.
|
|
17
17
|
*/
|
|
18
18
|
look?: 'value' | 'row';
|
|
19
|
+
/**
|
|
20
|
+
* Inline, the pencil's room is kept at rest, as before 4.102, so nothing
|
|
21
|
+
* moves on hover or focus: a table cell (row-edit-cells.tsx), whose
|
|
22
|
+
* column would otherwise widen, EntityView's title, which ends its line
|
|
23
|
+
* and can fill it, and every value inside a <KeyStats> (4.115, which
|
|
24
|
+
* sets it for them: a wrapping row moved the values after it along).
|
|
25
|
+
*/
|
|
26
|
+
keepPencilRoom?: boolean;
|
|
19
27
|
className?: string;
|
|
20
28
|
};
|
|
21
29
|
/** EditableValue's own props, plus what a list's rows and its Add box need (editable-list.tsx). */
|
|
@@ -28,15 +36,9 @@ export type EditableFieldProps = EditableValueProps & {
|
|
|
28
36
|
trigger?: (start: () => void) => ReactNode;
|
|
29
37
|
/** Opens again, empty, once a save from the keyboard succeeds: adding one item after another. */
|
|
30
38
|
reopenAfterKeyboardSave?: boolean;
|
|
31
|
-
/**
|
|
32
|
-
* Inline, the pencil's room is kept at rest, as before 4.102: a table
|
|
33
|
-
* cell (row-edit-cells.tsx), whose column would otherwise widen on
|
|
34
|
-
* hover, and EntityView's title, which ends its line and can fill it.
|
|
35
|
-
*/
|
|
36
|
-
keepPencilRoom?: boolean;
|
|
37
39
|
};
|
|
38
40
|
export declare function EditableValue(props: EditableValueProps): import("react").JSX.Element;
|
|
39
|
-
export declare function EditableField({ label, edit, children, layout, look, className, trigger, reopenAfterKeyboardSave, keepPencilRoom, }: EditableFieldProps): import("react").JSX.Element;
|
|
41
|
+
export declare function EditableField({ label, edit, children, layout, look, className, trigger, reopenAfterKeyboardSave, keepPencilRoom: keepPencilRoomProp, }: EditableFieldProps): import("react").JSX.Element;
|
|
40
42
|
/**
|
|
41
43
|
* While a field holds something unsaved, leaving asks first: an in-app
|
|
42
44
|
* link or Back (React Router's blocker, so the app needs a data router),
|
|
@@ -22,6 +22,8 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
22
22
|
// for two seconds (`role="status"`).
|
|
23
23
|
// - `layout="inline"` (4.102): the pencil takes no room until hover or
|
|
24
24
|
// focus, so nothing gaps before what follows the value on its line.
|
|
25
|
+
// `keepPencilRoom` (and every value inside a KeyStats, 4.115) keeps it
|
|
26
|
+
// at rest instead, so nothing moves on hover or focus.
|
|
25
27
|
// - `look="row"` (4.88, F15 and F18): in a record's field list the row is
|
|
26
28
|
// the target (edit-row.ts): it wears the list's row hover and the pencil
|
|
27
29
|
// sits at its end; under 48rem or on a touch screen there's a chevron
|
|
@@ -37,6 +39,7 @@ import { Spinner } from '../ui/spinner.js';
|
|
|
37
39
|
import { EditInPlaceContext } from './edit-in-place.js';
|
|
38
40
|
import { SAVED_FOR_MS } from './edit-row.js';
|
|
39
41
|
import { escapePassedThrough } from './escape-passthrough.js';
|
|
42
|
+
import { KeepPencilRoomContext } from './keep-pencil-room.js';
|
|
40
43
|
// What a click on the shown value must leave alone: links navigate,
|
|
41
44
|
// buttons and boxes do their own thing (a list item's done box ticks it).
|
|
42
45
|
const INTERACTIVE = 'a[href], button, input, select, textarea, label, [role="button"], [role="link"], [role="checkbox"], [role="switch"]';
|
|
@@ -74,8 +77,10 @@ function useStore() {
|
|
|
74
77
|
export function EditableValue(props) {
|
|
75
78
|
return _jsx(EditableField, { ...props });
|
|
76
79
|
}
|
|
77
|
-
export function EditableField({ label, edit, children, layout = 'block', look = 'value', className, trigger, reopenAfterKeyboardSave = false, keepPencilRoom
|
|
80
|
+
export function EditableField({ label, edit, children, layout = 'block', look = 'value', className, trigger, reopenAfterKeyboardSave = false, keepPencilRoom: keepPencilRoomProp, }) {
|
|
78
81
|
const store = useStore();
|
|
82
|
+
const keepRoomHere = useContext(KeepPencilRoomContext);
|
|
83
|
+
const keepPencilRoom = keepPencilRoomProp ?? keepRoomHere;
|
|
79
84
|
const key = useId();
|
|
80
85
|
const controlId = `${key}-control`;
|
|
81
86
|
const describedBy = `${key}-status`;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ReactNode } from 'react';
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
2
|
import type { StatusKind } from '../../lib/status-kinds.js';
|
|
3
3
|
import type { EditInPlace } from './edit-in-place.js';
|
|
4
4
|
import type { IconComponent } from './icon-component.js';
|
|
@@ -15,10 +15,10 @@ export type EntityViewFactValue =
|
|
|
15
15
|
kind: 'text';
|
|
16
16
|
text: string | number | null | undefined;
|
|
17
17
|
}
|
|
18
|
-
/** A few short labels (areas, tags) as badges. None is empty. */
|
|
18
|
+
/** A few short labels (areas, tags) as badges, each with its icon if it has one (4.115). None is empty. */
|
|
19
19
|
| {
|
|
20
20
|
kind: 'badges';
|
|
21
|
-
items: readonly string[];
|
|
21
|
+
items: readonly (string | EntityViewFactBadge)[];
|
|
22
22
|
}
|
|
23
23
|
/** A count, and where it links to, if anywhere (`/discussions?provider=3`). */
|
|
24
24
|
| {
|
|
@@ -63,22 +63,71 @@ export type EntityViewFactListItem = {
|
|
|
63
63
|
/** Its kind's icon (the record standard's 4I); a bullet without one. */
|
|
64
64
|
icon?: IconComponent;
|
|
65
65
|
};
|
|
66
|
+
/** One item of a `badges` fact with an icon (4.115): the icon before its label, in the muted tone. */
|
|
67
|
+
export type EntityViewFactBadge = {
|
|
68
|
+
label: string;
|
|
69
|
+
/** An icon component (a `LucideIcon`, an app's own mark) or a node drawn as it is. Decorative: the label says it. */
|
|
70
|
+
icon?: IconComponent | ReactNode;
|
|
71
|
+
};
|
|
72
|
+
/** A small button under a fact's value (4.115): "Close…" under a status that changes only through it. */
|
|
73
|
+
export type EntityViewFactAction = {
|
|
74
|
+
/** The button's words ("Close…"; an ellipsis when it opens a dialog). */
|
|
75
|
+
label: string;
|
|
76
|
+
/** Drawn before the words. */
|
|
77
|
+
icon?: IconComponent;
|
|
78
|
+
/** What a click does, when `render` isn't given. */
|
|
79
|
+
onClick?: () => void;
|
|
80
|
+
/**
|
|
81
|
+
* The app's own action instead (one that opens its dialog), given the
|
|
82
|
+
* button the fact would draw, so it can be the dialog's trigger with the
|
|
83
|
+
* same look: `(button) => <CloseDialog trigger={button} />`, or
|
|
84
|
+
* `<DialogTrigger render={button} />`. What it returns is drawn as it is.
|
|
85
|
+
*/
|
|
86
|
+
render?: (button: ReactElement) => ReactNode;
|
|
87
|
+
};
|
|
66
88
|
export type EntityViewFact = EntityViewFactValue & {
|
|
67
89
|
label: string;
|
|
68
90
|
/** What an empty value reads as, for this fact. Defaults to the view's `emptyText`. */
|
|
69
91
|
emptyLabel?: string;
|
|
70
92
|
/** Editable in place, as a field is (`inPlace.select`, `inPlace.date`); it's drawn by its kind at rest. */
|
|
71
93
|
edit?: EditInPlace;
|
|
94
|
+
/**
|
|
95
|
+
* The record's status (4.115): drawn first, at the top of the rail (or
|
|
96
|
+
* of Details), whatever its place in `facts` or its section's among the
|
|
97
|
+
* rail's. One per record; usually a `kind: 'status'` fact.
|
|
98
|
+
*/
|
|
99
|
+
recordStatus?: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* A few words on the value (4.115), such as why it can't be edited here
|
|
102
|
+
* ("Changes when the record is closed"). An info button after the value
|
|
103
|
+
* shows it on hover and keyboard focus; a touch screen shows it as a
|
|
104
|
+
* line under the value instead. A screen reader reads it with the value.
|
|
105
|
+
*/
|
|
106
|
+
hint?: string;
|
|
107
|
+
/** A small button under the value (4.115), drawn in the rail and in Details alike. */
|
|
108
|
+
action?: EntityViewFactAction;
|
|
72
109
|
};
|
|
73
110
|
/** A fact as the view draws it: `null` when empty. */
|
|
74
111
|
export declare function factValue(fact: EntityViewFactValue): ReactNode;
|
|
75
|
-
/** A facts section's facts as fields rows, for Details, the column and printing. */
|
|
112
|
+
/** A facts section's facts as fields rows, for Details, the column and printing: the status first. */
|
|
76
113
|
export declare function factsAsFields(facts: readonly EntityViewFact[]): {
|
|
77
114
|
label: string;
|
|
78
115
|
value: ReactNode;
|
|
79
116
|
emptyLabel: string | undefined;
|
|
80
117
|
edit: EditInPlace | undefined;
|
|
118
|
+
hint: string | undefined;
|
|
119
|
+
action: EntityViewFactAction | undefined;
|
|
120
|
+
recordStatus: boolean | undefined;
|
|
81
121
|
}[];
|
|
122
|
+
/**
|
|
123
|
+
* The sections with the one holding the status fact (4.115) moved before
|
|
124
|
+
* the other sections that share its place (the rail, or a tab's
|
|
125
|
+
* side), so the status is the first fact there. Nothing else moves.
|
|
126
|
+
*/
|
|
127
|
+
export declare function statusSectionFirst<T extends {
|
|
128
|
+
placement?: string;
|
|
129
|
+
tab?: string;
|
|
130
|
+
}>(sections: readonly T[]): T[];
|
|
82
131
|
/** The width the view needs for the facts rail beside its column: 60rem (the column ~40rem, a 300px rail, the gap). */
|
|
83
132
|
export declare const FACTS_RAIL_MIN_WIDTH = 960;
|
|
84
133
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useLayoutEffect, useState } from 'react';
|
|
2
|
+
import { isValidElement, useLayoutEffect, useState } from 'react';
|
|
3
3
|
import { Link } from 'react-router';
|
|
4
4
|
import { ExternalLinkIcon } from 'lucide-react';
|
|
5
5
|
import { cn } from 'cn';
|
|
@@ -7,6 +7,15 @@ import { Badge } from '../ui/badge.js';
|
|
|
7
7
|
import { FactList, FactListItem } from './fact-list.js';
|
|
8
8
|
import { StatusMark } from './status-mark.js';
|
|
9
9
|
const LINK_CLASS = 'rounded-sm font-medium text-link underline-offset-4 outline-none hover:underline focus-visible:ring-3 focus-visible:ring-ring/50';
|
|
10
|
+
// A badge item's icon in the muted tone a list's item icons have
|
|
11
|
+
// (FactList's marks): a component drawn at the badge's icon size, or the
|
|
12
|
+
// app's own node as it is.
|
|
13
|
+
function badgeIcon(icon) {
|
|
14
|
+
// A component: a function, or a forwardRef or memo object (a LucideIcon); an element is a node.
|
|
15
|
+
const isComponent = typeof icon === 'function' || (typeof icon === 'object' && icon !== null && !isValidElement(icon) && '$$typeof' in icon);
|
|
16
|
+
const Icon = icon;
|
|
17
|
+
return (_jsx("span", { "data-slot": "entity-view-fact-badge-icon", "aria-hidden": "true", "data-icon": "inline-start", className: "inline-flex shrink-0 text-muted-foreground", children: isComponent ? _jsx(Icon, { "aria-hidden": "true", className: "size-3" }) : icon }));
|
|
18
|
+
}
|
|
10
19
|
/** A fact as the view draws it: `null` when empty. */
|
|
11
20
|
export function factValue(fact) {
|
|
12
21
|
switch (fact.kind) {
|
|
@@ -21,7 +30,10 @@ export function factValue(fact) {
|
|
|
21
30
|
case 'badges':
|
|
22
31
|
if (fact.items.length === 0)
|
|
23
32
|
return null;
|
|
24
|
-
return (_jsx("span", { className: "inline-flex max-w-full flex-wrap gap-1", children: fact.items.map((item) =>
|
|
33
|
+
return (_jsx("span", { className: "inline-flex max-w-full flex-wrap gap-1", children: fact.items.map((item, index) => {
|
|
34
|
+
const { label, icon } = typeof item === 'string' ? { label: item, icon: undefined } : item;
|
|
35
|
+
return (_jsxs(Badge, { variant: "outline", className: "max-w-full", children: [icon !== undefined && icon !== null && badgeIcon(icon), _jsx("span", { className: "min-w-0 truncate", children: label })] }, `${index}:${label}`));
|
|
36
|
+
}) }));
|
|
25
37
|
case 'count':
|
|
26
38
|
return fact.to ? (_jsx(Link, { to: fact.to, className: cn(LINK_CLASS, 'tabular-nums'), children: fact.count })) : (_jsx("span", { className: "tabular-nums", children: fact.count }));
|
|
27
39
|
case 'link':
|
|
@@ -34,9 +46,41 @@ export function factValue(fact) {
|
|
|
34
46
|
return (_jsx(Link, { to: fact.to, title: fact.name, className: cn(LINK_CLASS, 'inline-block max-w-full truncate align-bottom'), children: fact.name }));
|
|
35
47
|
}
|
|
36
48
|
}
|
|
37
|
-
/** A facts section's facts as fields rows, for Details, the column and printing. */
|
|
49
|
+
/** A facts section's facts as fields rows, for Details, the column and printing: the status first. */
|
|
38
50
|
export function factsAsFields(facts) {
|
|
39
|
-
return facts.map((fact) => ({
|
|
51
|
+
return statusFirst(facts).map((fact) => ({
|
|
52
|
+
label: fact.label,
|
|
53
|
+
value: factValue(fact),
|
|
54
|
+
emptyLabel: fact.emptyLabel,
|
|
55
|
+
edit: fact.edit,
|
|
56
|
+
hint: fact.hint,
|
|
57
|
+
action: fact.action,
|
|
58
|
+
recordStatus: fact.recordStatus,
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
// The status fact first, the rest in their order.
|
|
62
|
+
function statusFirst(facts) {
|
|
63
|
+
const at = facts.findIndex((fact) => fact.recordStatus);
|
|
64
|
+
return at <= 0 ? facts : [facts[at], ...facts.slice(0, at), ...facts.slice(at + 1)];
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The sections with the one holding the status fact (4.115) moved before
|
|
68
|
+
* the other sections that share its place (the rail, or a tab's
|
|
69
|
+
* side), so the status is the first fact there. Nothing else moves.
|
|
70
|
+
*/
|
|
71
|
+
export function statusSectionFirst(sections) {
|
|
72
|
+
const holds = (section) => 'facts' in section && section.facts.some((fact) => fact.recordStatus);
|
|
73
|
+
const at = sections.findIndex(holds);
|
|
74
|
+
if (at < 0)
|
|
75
|
+
return [...sections];
|
|
76
|
+
const status = sections[at];
|
|
77
|
+
const sameSpot = (section) => section.placement === status.placement && section.tab === status.tab;
|
|
78
|
+
const first = sections.findIndex(sameSpot);
|
|
79
|
+
if (first === at)
|
|
80
|
+
return [...sections];
|
|
81
|
+
const rest = sections.filter((_, index) => index !== at);
|
|
82
|
+
rest.splice(first, 0, status);
|
|
83
|
+
return rest;
|
|
40
84
|
}
|
|
41
85
|
/** The width the view needs for the facts rail beside its column: 60rem (the column ~40rem, a 300px rail, the gap). */
|
|
42
86
|
export const FACTS_RAIL_MIN_WIDTH = 960;
|
|
@@ -275,4 +275,4 @@ export type EntityViewProps = {
|
|
|
275
275
|
trail?: readonly PageCrumb[];
|
|
276
276
|
};
|
|
277
277
|
};
|
|
278
|
-
export declare function EntityView({ title, documentTitle, titleEdit, leading, subtitle, badges, actions, notice, strip, cardStrip, sections, footer, layout, detailsTab, tabCounts, tabsStickyTop, mobileOrder, railLabel, factsRail, factsRailLabel, railFields, emptyFields, emptyText, printLabel, printLook, isLoading, error, onRetry, back, }: EntityViewProps): import("react").JSX.Element;
|
|
278
|
+
export declare function EntityView({ title, documentTitle, titleEdit, leading, subtitle, badges, actions, notice, strip, cardStrip, sections: givenSections, footer, layout, detailsTab, tabCounts, tabsStickyTop, mobileOrder, railLabel, factsRail, factsRailLabel, railFields, emptyFields, emptyText, printLabel, printLook, isLoading, error, onRetry, back, }: EntityViewProps): import("react").JSX.Element;
|
|
@@ -97,7 +97,7 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
97
97
|
// ones behind an "N empty" toggle, still edited in place once opened.
|
|
98
98
|
import { createContext, useContext, useEffect, useId, useState, useSyncExternalStore } from 'react';
|
|
99
99
|
import { Link, useLocation, useNavigate } from 'react-router';
|
|
100
|
-
import { ArrowLeftIcon, ChevronDownIcon, SearchXIcon } from 'lucide-react';
|
|
100
|
+
import { ArrowLeftIcon, ChevronDownIcon, InfoIcon, SearchXIcon } from 'lucide-react';
|
|
101
101
|
import { cn } from 'cn';
|
|
102
102
|
import { ErrorState } from './error-state.js';
|
|
103
103
|
import { Button } from '../ui/button.js';
|
|
@@ -119,7 +119,8 @@ import { FIELD_LABEL, FIELD_ROW, FIELD_ROW_BASE, FIELD_VALUE } from './field-row
|
|
|
119
119
|
import { PageTrail } from './page-trail.js';
|
|
120
120
|
import { usePageTrail } from './page-trail-context.js';
|
|
121
121
|
import { entityViewTabSlug } from '../../lib/entity-view-tab.js';
|
|
122
|
-
import { factsAsFields, useWideParent } from './entity-view-facts.js';
|
|
122
|
+
import { factsAsFields, statusSectionFirst, useWideParent } from './entity-view-facts.js';
|
|
123
|
+
import { Tooltip, TooltipContent, TooltipTrigger } from '../ui/tooltip.js';
|
|
123
124
|
// The view's empty text and whether fields cards fold their empty ones,
|
|
124
125
|
// for every section without threading them through each layout.
|
|
125
126
|
const EmptyContext = createContext({ text: EMPTY_DASH, fold: false });
|
|
@@ -143,12 +144,30 @@ function OrEmpty({ value, emptyLabel }) {
|
|
|
143
144
|
}
|
|
144
145
|
// A preset shows its own value unless the screen gives one.
|
|
145
146
|
const fieldValue = (field) => (field.value !== undefined ? field.value : field.edit?.shown);
|
|
147
|
+
// A fact's hint (4.115): an info button after the value, its words in a
|
|
148
|
+
// tooltip on hover and on keyboard focus. On a touch screen, where a
|
|
149
|
+
// tooltip has no hover to open it, the words are a line under the value
|
|
150
|
+
// instead (and the button goes). A screen reader reads the words with the
|
|
151
|
+
// value either way: the line is there for it, only visually hidden on a
|
|
152
|
+
// mouse's screen, and it describes the button.
|
|
153
|
+
function FactHint({ label, hint }) {
|
|
154
|
+
const id = useId();
|
|
155
|
+
return (_jsxs(_Fragment, { children: [_jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { render: _jsx("button", { type: "button", "data-slot": "entity-view-fact-hint", "aria-label": `About ${label}`, "aria-describedby": id, className: "inline-flex size-6 shrink-0 items-center justify-center rounded-sm text-muted-foreground outline-none hover:text-foreground focus-visible:ring-3 focus-visible:ring-ring/50 pointer-coarse:hidden" }), children: _jsx(InfoIcon, { "aria-hidden": "true", className: "size-3.5" }) }), _jsx(TooltipContent, { children: hint })] }), _jsx("span", { id: id, "data-slot": "entity-view-fact-hint-text", className: "sr-only basis-full type-caption text-muted-foreground pointer-coarse:not-sr-only", children: hint })] }));
|
|
156
|
+
}
|
|
157
|
+
// A fact's action (4.115): a small button under its value, or the app's
|
|
158
|
+
// own action given that button (`render`), so its dialog opens from it.
|
|
159
|
+
function FactAction({ action }) {
|
|
160
|
+
const Icon = action.icon;
|
|
161
|
+
const button = (_jsxs(Button, { type: "button", variant: "outline", size: "xs", "data-slot": "entity-view-fact-action", onClick: action.render ? undefined : action.onClick, className: "pointer-coarse:min-h-11", children: [Icon && _jsx(Icon, { "aria-hidden": "true", "data-icon": "inline-start" }), action.label] }));
|
|
162
|
+
return _jsx("div", { className: "flex", children: action.render ? action.render(button) : button });
|
|
163
|
+
}
|
|
146
164
|
function FieldRow({ field, place }) {
|
|
147
165
|
const value = fieldValue(field);
|
|
148
166
|
// An editable row is the target as a whole (4.88, F15/F18): the list's
|
|
149
167
|
// row hover, its pencil at the end, a chevron on a phone.
|
|
150
168
|
const editable = Boolean(field.edit);
|
|
151
|
-
|
|
169
|
+
const shown = field.edit ? (_jsx(EditableValue, { label: field.label, edit: field.edit, look: "row", children: _jsx(OrEmpty, { value: value, emptyLabel: field.emptyLabel }) })) : (_jsx(OrEmpty, { value: value, emptyLabel: field.emptyLabel }));
|
|
170
|
+
return (_jsxs("div", { className: cn(FIELD_ROW_BASE, FIELD_ROW[place], editable && cn(editRowClass, '-mx-2 px-2 first:pt-2 last:pb-2')), onClick: editable ? onEditRowClick : undefined, children: [_jsx("dt", { className: FIELD_LABEL, children: field.label }), _jsxs("dd", { className: cn(FIELD_VALUE, field.action && 'flex flex-col items-start gap-1.5'), "data-record-status": field.recordStatus ? '' : undefined, children: [field.hint ? (_jsxs("span", { className: "inline-flex max-w-full flex-wrap items-center gap-x-1", children: [_jsx("span", { className: "min-w-0 max-w-full", children: shown }), _jsx(FactHint, { label: field.label, hint: field.hint })] })) : (shown), field.action && _jsx(FactAction, { action: field.action })] })] }));
|
|
152
171
|
}
|
|
153
172
|
// A fields card's rows. Folded (`emptyFields="fold"`), the filled fields
|
|
154
173
|
// show and the empty ones wait behind "N empty", which opens them in their
|
|
@@ -382,7 +401,9 @@ function tabsLayout(sections, detailsTab) {
|
|
|
382
401
|
tabs.push({ slug, name: detailsTab, sections: facts, side: [], details: true });
|
|
383
402
|
return { above: main.filter((section) => section.tab === undefined), tabs, factsInColumn: false };
|
|
384
403
|
}
|
|
385
|
-
export function EntityView({ title, documentTitle, titleEdit, leading, subtitle, badges, actions, notice, strip, cardStrip = false, sections, footer, layout = 'tabs', detailsTab = 'Details', tabCounts, tabsStickyTop, mobileOrder = 'rail-first', railLabel, factsRail = false, factsRailLabel, railFields = 'beside', emptyFields = 'show', emptyText = EMPTY_DASH, printLabel = 'Print Notes', printLook = 'icon', isLoading, error, onRetry, back, }) {
|
|
404
|
+
export function EntityView({ title, documentTitle, titleEdit, leading, subtitle, badges, actions, notice, strip, cardStrip = false, sections: givenSections, footer, layout = 'tabs', detailsTab = 'Details', tabCounts, tabsStickyTop, mobileOrder = 'rail-first', railLabel, factsRail = false, factsRailLabel, railFields = 'beside', emptyFields = 'show', emptyText = EMPTY_DASH, printLabel = 'Print Notes', printLook = 'icon', isLoading, error, onRetry, back, }) {
|
|
405
|
+
// The record's status first among the sections in its place (4.115).
|
|
406
|
+
const sections = statusSectionFirst(givenSections);
|
|
386
407
|
// Editing in place: one store per view, and the leave-page prompt only
|
|
387
408
|
// while a field is open (or one is always editable).
|
|
388
409
|
const [store] = useState(() => new EditInPlaceStore());
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const KeepPencilRoomContext: import("react").Context<boolean>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Set by a container whose inline <EditableValue>s must keep their
|
|
2
|
+
// pencil's room at rest (KeyStats, 4.115), as `keepPencilRoom` does for
|
|
3
|
+
// one: a value growing on hover moved the values after it along a
|
|
4
|
+
// wrapping row, and a nearly full row wrapped, so the hovered value slid
|
|
5
|
+
// out from under the mouse and a click opened the next one.
|
|
6
|
+
import { createContext } from 'react';
|
|
7
|
+
export const KeepPencilRoomContext = createContext(false);
|
|
@@ -2,10 +2,11 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
import { cn } from 'cn';
|
|
3
3
|
import { EmptyText } from './empty-value.js';
|
|
4
4
|
import { EMPTY_DASH } from '../../lib/empty-value.js';
|
|
5
|
+
import { KeepPencilRoomContext } from './keep-pencil-room.js';
|
|
5
6
|
const isEmpty = (value) => value === null || value === undefined || value === false || value === '';
|
|
6
7
|
export function KeyStats({ stats, emptyLabel = EMPTY_DASH, width = 'content', className }) {
|
|
7
|
-
return (_jsx("dl", { "data-slot": "key-stats", "data-width": width, className: cn('flex flex-wrap gap-x-8 gap-y-3 rounded-lg border border-border bg-card px-4 py-3 text-card-foreground', width === 'content' && 'w-fit max-w-full', className), children: stats.map((stat) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
return (_jsx(KeepPencilRoomContext.Provider, { value: true, children: _jsx("dl", { "data-slot": "key-stats", "data-width": width, className: cn('flex flex-wrap gap-x-8 gap-y-3 rounded-lg border border-border bg-card px-4 py-3 text-card-foreground', width === 'content' && 'w-fit max-w-full', className), children: stats.map((stat) => {
|
|
9
|
+
const Icon = stat.icon;
|
|
10
|
+
return (_jsxs("div", { className: "flex min-w-0 flex-col gap-0.5", children: [_jsxs("dt", { className: cn('type-caption text-muted-foreground', Icon && 'inline-flex items-center gap-1'), children: [Icon && _jsx(Icon, { "aria-hidden": "true", className: "size-3.25 shrink-0" }), stat.label] }), _jsx("dd", { className: "type-section-title tabular-nums break-words text-foreground", children: isEmpty(stat.value) ? _jsx(EmptyText, { text: emptyLabel, className: "type-body text-muted-foreground" }) : stat.value }), stat.hint && _jsx("dd", { className: "type-caption text-muted-foreground", children: stat.hint })] }, stat.label));
|
|
11
|
+
}) }) }));
|
|
11
12
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export { EmptyText, type EmptyTextProps } from './components/app/empty-value.js'
|
|
|
28
28
|
export { isEmptyValue } from './lib/empty-value.js';
|
|
29
29
|
export { IconAction, type IconActionProps } from './components/app/icon-action.js';
|
|
30
30
|
export { EntityView, type EntityViewEmptyFields, type EntityViewField, type EntityViewLayout, type EntityViewMobileOrder, type EntityViewPlacement, type EntityViewProps, type EntityViewRailFields, type EntityViewSection, } from './components/app/entity-view.js';
|
|
31
|
-
export { type EntityViewFact, type EntityViewFactListItem, type EntityViewFactValue } from './components/app/entity-view-facts.js';
|
|
31
|
+
export { type EntityViewFact, type EntityViewFactAction, type EntityViewFactBadge, type EntityViewFactListItem, type EntityViewFactValue, } from './components/app/entity-view-facts.js';
|
|
32
32
|
export { entityViewTabSlug } from './lib/entity-view-tab.js';
|
|
33
33
|
export { usePrinting } from './components/app/print-context.js';
|
|
34
34
|
export { RecordDialogRoute, RecordLink, type RecordDialogRouteProps, type RecordLinkProps, } from './components/app/record-dialog.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tristan2828/ui-foundation",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.115.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": {
|