@tristan2828/ui-foundation 4.100.0 → 4.102.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 +14 -12
- package/conventions/docs/cell-patterns.md +43 -18
- package/conventions/docs/design-language.md +17 -9
- package/dist/components/app/editable-value.d.ts +7 -1
- package/dist/components/app/editable-value.js +15 -3
- package/dist/components/app/entity-view.d.ts +13 -1
- package/dist/components/app/entity-view.js +49 -6
- package/dist/components/app/multi-pick.d.ts +11 -1
- package/dist/components/app/multi-pick.js +117 -21
- package/dist/components/app/record-dialog.js +6 -1
- package/dist/components/app/row-edit-cells.js +4 -4
- package/package.json +1 -1
|
@@ -15,17 +15,17 @@
|
|
|
15
15
|
- Step 8: Add Playwright specs for all three screens · lines 752–829
|
|
16
16
|
- Step 9: Register the nav entry and route names · lines 830–844
|
|
17
17
|
- Step 10: `npm run verify`. · lines 845–847
|
|
18
|
-
- [How a list opens a record](#how-a-list-opens-a-record) · lines 849–
|
|
19
|
-
- [The record view](#the-record-view) · lines 1002–
|
|
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
|
|
18
|
+
- [How a list opens a record](#how-a-list-opens-a-record) · lines 849–1208
|
|
19
|
+
- [The record view](#the-record-view) · lines 1002–1065
|
|
20
|
+
- [Forms](#forms) · lines 1067–1125
|
|
21
|
+
- [Dialogs](#dialogs) · lines 1127–1158
|
|
22
|
+
- [Toasts and feedback](#toasts-and-feedback) · lines 1160–1208
|
|
23
|
+
- [What not to copy](#what-not-to-copy) · lines 1210–1236
|
|
24
|
+
- [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 1238–1255
|
|
25
|
+
- [Deleting](#deleting) · lines 1257–1288
|
|
26
|
+
- [Fields only a script writes](#fields-only-a-script-writes) · lines 1290–1311
|
|
27
|
+
- [Searching one part of the app](#searching-one-part-of-the-app) · lines 1313–1322
|
|
28
|
+
- [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1325–1367
|
|
29
29
|
|
|
30
30
|
<!-- /index -->
|
|
31
31
|
|
|
@@ -1033,7 +1033,9 @@ A record uses the parts it has, in this order:
|
|
|
1033
1033
|
- **Tabs** (4.76), for a main column with **three or more groups of
|
|
1034
1034
|
long content** (the steps, where it's used, the reasoning): a `tab` on
|
|
1035
1035
|
each main section groups them under a tab list, the selected one in
|
|
1036
|
-
`?tab=`.
|
|
1036
|
+
`?tab=`. Give each tab that holds records its count (`tabCounts={{
|
|
1037
|
+
Updates: updates.length }}`); the bar sticks as the record scrolls,
|
|
1038
|
+
with the record's name above it (4.101). Fewer groups stay one scroll, folded by headings. A record's
|
|
1037
1039
|
Notes stay outside the tabs, above them, unless they are one tab's
|
|
1038
1040
|
content; the strip never goes in a tab, and the facts are a tab of
|
|
1039
1041
|
their own (Details, `detailsTab` to name it otherwise).
|
|
@@ -26,24 +26,24 @@
|
|
|
26
26
|
- [A variant: a pressed icon inside another value's cell](#a-variant-a-pressed-icon-inside-another-values-cell) · lines 631–714
|
|
27
27
|
- [16. Title linking to the record's view](#16-title-linking-to-the-records-view) · lines 716–751
|
|
28
28
|
- [17. Quick action on the view](#17-quick-action-on-the-view) · lines 753–826
|
|
29
|
-
- [18. Editable value](#18-editable-value) · lines 828–
|
|
30
|
-
- [Presets: one line per field](#presets-one-line-per-field) · lines
|
|
31
|
-
- [Several fields edited as one](#several-fields-edited-as-one) · lines
|
|
32
|
-
- [A link and its label](#a-link-and-its-label) · lines
|
|
33
|
-
- [A list of sub-items](#a-list-of-sub-items) · lines
|
|
34
|
-
- [In a table's rows](#in-a-tables-rows) · lines
|
|
35
|
-
- [A table of a few short columns: `width="content"`](#a-table-of-a-few-short-columns-widthcontent) · lines
|
|
36
|
-
- [19. Stage circle for an ordered status](#19-stage-circle-for-an-ordered-status) · lines
|
|
37
|
-
- [20. Count linking to the related records](#20-count-linking-to-the-related-records) · lines
|
|
38
|
-
- [21. Rows grouped under headings, and a pill filter](#21-rows-grouped-under-headings-and-a-pill-filter) · lines
|
|
39
|
-
- [22. A highlighted row, and rows that are done](#22-a-highlighted-row-and-rows-that-are-done) · lines
|
|
40
|
-
- [24. A list's rows: hover, lines, rows per page](#24-a-lists-rows-hover-lines-rows-per-page) · lines
|
|
41
|
-
- [23. A Group menu, and a record read beside the list](#23-a-group-menu-and-a-record-read-beside-the-list) · lines
|
|
42
|
-
- [24. A stored colour beside its name](#24-a-stored-colour-beside-its-name) · lines
|
|
43
|
-
- [25. A list's tools: views, filters, columns, row actions, a phone's rows](#25-a-lists-tools-views-filters-columns-row-actions-a-phones-rows) · lines
|
|
44
|
-
- [The framed look, and sibling lists beside the title](#the-framed-look-and-sibling-lists-beside-the-title) · lines
|
|
45
|
-
- [26. A record's related list, capped](#26-a-records-related-list-capped) · lines
|
|
46
|
-
- [27. A repeat and its next time](#27-a-repeat-and-its-next-time) · lines
|
|
29
|
+
- [18. Editable value](#18-editable-value) · lines 828–1531
|
|
30
|
+
- [Presets: one line per field](#presets-one-line-per-field) · lines 1163–1231
|
|
31
|
+
- [Several fields edited as one](#several-fields-edited-as-one) · lines 1233–1269
|
|
32
|
+
- [A link and its label](#a-link-and-its-label) · lines 1271–1295
|
|
33
|
+
- [A list of sub-items](#a-list-of-sub-items) · lines 1297–1430
|
|
34
|
+
- [In a table's rows](#in-a-tables-rows) · lines 1432–1517
|
|
35
|
+
- [A table of a few short columns: `width="content"`](#a-table-of-a-few-short-columns-widthcontent) · lines 1519–1531
|
|
36
|
+
- [19. Stage circle for an ordered status](#19-stage-circle-for-an-ordered-status) · lines 1533–1599
|
|
37
|
+
- [20. Count linking to the related records](#20-count-linking-to-the-related-records) · lines 1601–1665
|
|
38
|
+
- [21. Rows grouped under headings, and a pill filter](#21-rows-grouped-under-headings-and-a-pill-filter) · lines 1667–1765
|
|
39
|
+
- [22. A highlighted row, and rows that are done](#22-a-highlighted-row-and-rows-that-are-done) · lines 1767–1796
|
|
40
|
+
- [24. A list's rows: hover, lines, rows per page](#24-a-lists-rows-hover-lines-rows-per-page) · lines 1798–1836
|
|
41
|
+
- [23. A Group menu, and a record read beside the list](#23-a-group-menu-and-a-record-read-beside-the-list) · lines 1838–1914
|
|
42
|
+
- [24. A stored colour beside its name](#24-a-stored-colour-beside-its-name) · lines 1916–1939
|
|
43
|
+
- [25. A list's tools: views, filters, columns, row actions, a phone's rows](#25-a-lists-tools-views-filters-columns-row-actions-a-phones-rows) · lines 1941–2067
|
|
44
|
+
- [The framed look, and sibling lists beside the title](#the-framed-look-and-sibling-lists-beside-the-title) · lines 2029–2067
|
|
45
|
+
- [26. A record's related list, capped](#26-a-records-related-list-capped) · lines 2069–2105
|
|
46
|
+
- [27. A repeat and its next time](#27-a-repeat-and-its-next-time) · lines 2107–2152
|
|
47
47
|
|
|
48
48
|
<!-- /index -->
|
|
49
49
|
|
|
@@ -867,6 +867,16 @@ on each side without moving it, and never wraps it: a short title or
|
|
|
867
867
|
badge edited in place (`layout="inline"`) stays on one line, and a long
|
|
868
868
|
one wraps between words within its column (4.94; before, a title like
|
|
869
869
|
"Dr. Example" broke over two lines).
|
|
870
|
+
Inline, the pencil takes no room at rest (4.102): a value in a summary
|
|
871
|
+
line ("Harbor Office · Tuesdays") is followed by its separator a space
|
|
872
|
+
after it, not a pencil's width. The pencil keeps its 24px box out of the
|
|
873
|
+
flow, hidden just past the value over the separator, so it's still a
|
|
874
|
+
target to hover, click and Tab to. Hover or focus makes its room under
|
|
875
|
+
it, eased (at once with reduced motion): what follows moves over by the
|
|
876
|
+
pencil, smoothly, only while it shows, and the pencil stays put. A touch
|
|
877
|
+
screen keeps the room open. `DataTable`'s cells keep the room at rest
|
|
878
|
+
(a column never widens on hover), and so does `EntityView`'s title,
|
|
879
|
+
which ends its line and can fill it. An app needs no override for this.
|
|
870
880
|
|
|
871
881
|
**In a field list, the row is the target** (4.88, `look="row"`, which
|
|
872
882
|
EntityView's field rows use). The row wears the list's row hover, the
|
|
@@ -929,6 +939,21 @@ Larger sets, or ones that grow with the data, keep `MultiReference`
|
|
|
929
939
|
- **Keyboard:** opening puts the caret in the filter box; Down goes to
|
|
930
940
|
the chips, Left/Right (Home/End) move along them, Space or Enter
|
|
931
941
|
toggles one, Up goes back to the box.
|
|
942
|
+
- **Create "<typed>"** (4.102, `onCreate`): when what's typed names no
|
|
943
|
+
option (ignoring case), a Create "<typed>" button shows under the
|
|
944
|
+
chips; Enter in the box does the same when nothing matches, and Down
|
|
945
|
+
reaches it when there are no chips. It calls `onCreate(name)`, which
|
|
946
|
+
opens the app's small create form (a `FormDialog`, the name filled in)
|
|
947
|
+
or saves at once, and resolves with the new `{ id, label, icon? }`:
|
|
948
|
+
that option joins the chips and is picked (in place, saved like any
|
|
949
|
+
pick, with its spinner). `null` (the form cancelled) changes nothing.
|
|
950
|
+
While it's out the button reads Creating "<typed>"… (`aria-busy`), the
|
|
951
|
+
box is read-only and an edit in place stays open. A rejection shows
|
|
952
|
+
"Couldn't create "<typed>": <reason>" under the chips, the button
|
|
953
|
+
described by it, and keeps the typed name, so Create can be tried
|
|
954
|
+
again; typing clears it. The caret goes back to the box either way,
|
|
955
|
+
and a screen reader hears "<name> created and picked." Never a "New
|
|
956
|
+
<thing>" button beside the picker for this.
|
|
932
957
|
- Pass the record's value as `value`, not the control's `props.value`
|
|
933
958
|
(the draft, which never moves here), and keep the field's `save`: the
|
|
934
959
|
form's whole-set save, never called in place.
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
- [A few equal things](#a-few-equal-things) · lines 1401–1485
|
|
34
34
|
- [An overview page](#an-overview-page) · lines 1487–1550
|
|
35
35
|
- [A record's header and empty values](#a-records-header-and-empty-values) · lines 1551–1602
|
|
36
|
-
- [A record's tabs, mark and facts](#a-records-tabs-mark-and-facts) · lines 1604–
|
|
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 1604–1671
|
|
37
|
+
- [Picking at random](#picking-at-random) · lines 1673–1704
|
|
38
|
+
- [Filling in what's missing](#filling-in-whats-missing) · lines 1706–1773
|
|
39
|
+
- [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1775–1800
|
|
40
|
+
- [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 1802–1891
|
|
41
41
|
|
|
42
42
|
<!-- /index -->
|
|
43
43
|
|
|
@@ -1622,10 +1622,18 @@ its short facts the last tab, Details. A mark goes left of the title.
|
|
|
1622
1622
|
|
|
1623
1623
|
- **Tabs** (`tab` on a section): a line tab list under the strip and any
|
|
1624
1624
|
sections with no tab, one tab per name in the order the sections first
|
|
1625
|
-
give it. The
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1625
|
+
give it. The look is the record standard's 3B (4.101): 44px tabs in
|
|
1626
|
+
16px semibold (14px under 48rem), the selected one in foreground text
|
|
1627
|
+
with a 3px primary line under it, the others muted; the list's own
|
|
1628
|
+
bottom border runs the column's width. A tab's count (`tabCounts`, by
|
|
1629
|
+
name: the records it holds) sits beside its name in a small muted
|
|
1630
|
+
pill; a tab with none shows no count. A list wider than the column
|
|
1631
|
+
scrolls sideways on its own, never the page.
|
|
1632
|
+
- **The tab bar sticks** (4.101) to the top of whatever scrolls (the
|
|
1633
|
+
page, or a record dialog's body) while the record scrolls under it,
|
|
1634
|
+
and once stuck shows the record's name above the tabs, so you always
|
|
1635
|
+
see which record and which other tabs there are. A page with a bar of
|
|
1636
|
+
its own pinned to the top passes `tabsStickyTop` (any CSS length). Arrow keys move
|
|
1629
1637
|
between tabs and select (Home, End), and Tab goes on into the panel.
|
|
1630
1638
|
The address holds the selected tab (`?tab=used-in`,
|
|
1631
1639
|
`entityViewTabSlug`), replaced rather than pushed, so Back leaves the
|
|
@@ -28,9 +28,15 @@ export type EditableFieldProps = EditableValueProps & {
|
|
|
28
28
|
trigger?: (start: () => void) => ReactNode;
|
|
29
29
|
/** Opens again, empty, once a save from the keyboard succeeds: adding one item after another. */
|
|
30
30
|
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;
|
|
31
37
|
};
|
|
32
38
|
export declare function EditableValue(props: EditableValueProps): import("react").JSX.Element;
|
|
33
|
-
export declare function EditableField({ label, edit, children, layout, look, className, trigger, reopenAfterKeyboardSave, }: EditableFieldProps): import("react").JSX.Element;
|
|
39
|
+
export declare function EditableField({ label, edit, children, layout, look, className, trigger, reopenAfterKeyboardSave, keepPencilRoom, }: EditableFieldProps): import("react").JSX.Element;
|
|
34
40
|
/**
|
|
35
41
|
* While a field holds something unsaved, leaving asks first: an in-app
|
|
36
42
|
* link or Back (React Router's blocker, so the app needs a data router),
|
|
@@ -20,6 +20,8 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
20
20
|
// value it edits (`inline` among its props).
|
|
21
21
|
// - Saved (4.88, F16): once a save lands, "✓ Saved" shows beside the value
|
|
22
22
|
// for two seconds (`role="status"`).
|
|
23
|
+
// - `layout="inline"` (4.102): the pencil takes no room until hover or
|
|
24
|
+
// focus, so nothing gaps before what follows the value on its line.
|
|
23
25
|
// - `look="row"` (4.88, F15 and F18): in a record's field list the row is
|
|
24
26
|
// the target (edit-row.ts): it wears the list's row hover and the pencil
|
|
25
27
|
// sits at its end; under 48rem or on a touch screen there's a chevron
|
|
@@ -52,6 +54,13 @@ const LEAVING = 'a[href]:not([target="_blank"]), [data-leave-guard]';
|
|
|
52
54
|
// A control holding the field open while something of the app's is in
|
|
53
55
|
// front of it (ReferenceCombobox's create form): leaving doesn't save.
|
|
54
56
|
const HOLD = '[data-edit-hold]';
|
|
57
|
+
// An inline value's room for its pencil: none at rest; the pencil's 24px
|
|
58
|
+
// and a 4px gap (w-7) while the value is hovered or its pencil focused.
|
|
59
|
+
function InlinePencilRoom({ inline, children }) {
|
|
60
|
+
if (!inline)
|
|
61
|
+
return children;
|
|
62
|
+
return (_jsx("span", { "data-slot": "editable-value-pencil-room", className: "relative w-0 shrink-0 self-stretch transition-[width] duration-150 ease-out motion-reduce:transition-none group-hover/editable:w-7 group-has-[[data-edit]:focus-visible]/editable:w-7 pointer-coarse:w-7", children: children }));
|
|
63
|
+
}
|
|
55
64
|
// The field's own control, given what it needs.
|
|
56
65
|
function Control({ render, ...props }) {
|
|
57
66
|
return render(props);
|
|
@@ -65,7 +74,7 @@ function useStore() {
|
|
|
65
74
|
export function EditableValue(props) {
|
|
66
75
|
return _jsx(EditableField, { ...props });
|
|
67
76
|
}
|
|
68
|
-
export function EditableField({ label, edit, children, layout = 'block', look = 'value', className, trigger, reopenAfterKeyboardSave = false, }) {
|
|
77
|
+
export function EditableField({ label, edit, children, layout = 'block', look = 'value', className, trigger, reopenAfterKeyboardSave = false, keepPencilRoom = false, }) {
|
|
69
78
|
const store = useStore();
|
|
70
79
|
const key = useId();
|
|
71
80
|
const controlId = `${key}-control`;
|
|
@@ -235,7 +244,10 @@ export function EditableField({ label, edit, children, layout = 'block', look =
|
|
|
235
244
|
if (trigger)
|
|
236
245
|
return (_jsx("span", { ref: triggerBox, className: "contents", children: trigger(start) }));
|
|
237
246
|
const row = look === 'row';
|
|
238
|
-
|
|
247
|
+
const inlineValue = layout === 'inline' && !row && !keepPencilRoom;
|
|
248
|
+
return (_jsxs("span", { "data-slot": "editable-value", "data-look": look, onClick: onShownClick, className: cn(
|
|
249
|
+
// Inline, the gap is the pencil's own margin, there only while it shows.
|
|
250
|
+
'group/editable relative cursor-text items-start', !inlineValue && 'gap-1',
|
|
239
251
|
// A row: the row (editRowClass) wears the hover, not the value.
|
|
240
252
|
!row && '-mx-1.5 rounded-md px-1.5 transition-colors hover:bg-muted has-[[data-edit]:focus-visible]:bg-muted',
|
|
241
253
|
// Inline, the cap is its column plus the 0.75rem the negative
|
|
@@ -243,7 +255,7 @@ export function EditableField({ label, edit, children, layout = 'block', look =
|
|
|
243
255
|
// its line) is sized to the margin box, 0.75rem under the box,
|
|
244
256
|
// and `max-w-full` then wrapped a short value mid-word (4.94).
|
|
245
257
|
layout === 'block' ? 'flex w-full' : cn('inline-flex align-top', row ? 'max-w-full' : 'max-w-[calc(100%+0.75rem)]'), className), children: [_jsxs("span", { className: cn('min-w-0 flex-1', !row &&
|
|
246
|
-
'group-hover/editable:[&_.text-muted-foreground]:text-foreground group-has-[[data-edit]:focus-visible]/editable:[&_.text-muted-foreground]:text-foreground'), children: [children !== undefined ? children : edit.shown, _jsx("span", { role: "status", "data-slot": "editable-value-saved", className: "ml-2 inline-flex items-center gap-1 align-baseline type-caption text-success-text empty:hidden", children: justSaved && (_jsxs(_Fragment, { children: [_jsx(CheckIcon, { "aria-hidden": "true", className: "size-3.5" }), "Saved"] })) })] }), _jsx(Button, { ref: editButton, "data-edit": "", type: "button", variant: "ghost", size: "icon-xs", "aria-label": `Edit ${label}`, onClick: start, className: cn('shrink-0 text-muted-foreground opacity-0 focus-visible:opacity-100 pointer-coarse:opacity-100', row ? 'group-hover/edit-row:opacity-100 hover:bg-transparent max-md:opacity-100' : 'group-hover/editable:opacity-100'), children: row ? (_jsxs(_Fragment, { children: [_jsx(PencilIcon, { className: "max-md:hidden pointer-coarse:hidden" }), _jsx(ChevronRightIcon, { className: "hidden max-md:block pointer-coarse:block" })] })) : (_jsx(PencilIcon, {})) })] }));
|
|
258
|
+
'group-hover/editable:[&_.text-muted-foreground]:text-foreground group-has-[[data-edit]:focus-visible]/editable:[&_.text-muted-foreground]:text-foreground'), children: [children !== undefined ? children : edit.shown, _jsx("span", { role: "status", "data-slot": "editable-value-saved", className: "ml-2 inline-flex items-center gap-1 align-baseline type-caption text-success-text empty:hidden", children: justSaved && (_jsxs(_Fragment, { children: [_jsx(CheckIcon, { "aria-hidden": "true", className: "size-3.5" }), "Saved"] })) })] }), _jsx(InlinePencilRoom, { inline: inlineValue, children: _jsx(Button, { ref: editButton, "data-edit": "", type: "button", variant: "ghost", size: "icon-xs", "aria-label": `Edit ${label}`, onClick: start, className: cn('shrink-0 text-muted-foreground opacity-0 focus-visible:opacity-100 pointer-coarse:opacity-100', row ? 'group-hover/edit-row:opacity-100 hover:bg-transparent max-md:opacity-100' : 'group-hover/editable:opacity-100', inlineValue && 'absolute top-0 left-1 z-10'), children: row ? (_jsxs(_Fragment, { children: [_jsx(PencilIcon, { className: "max-md:hidden pointer-coarse:hidden" }), _jsx(ChevronRightIcon, { className: "hidden max-md:block pointer-coarse:block" })] })) : (_jsx(PencilIcon, {})) }) })] }));
|
|
247
259
|
}
|
|
248
260
|
// Always editable, before the store has it (the first render): the saved value.
|
|
249
261
|
const open = state.status === 'closed' ? { status: 'open', draft: edit.value, error: null, autosave: undefined, revision: 0 } : state;
|
|
@@ -174,6 +174,18 @@ export type EntityViewProps = {
|
|
|
174
174
|
* section of the record's own with this tab joins it.
|
|
175
175
|
*/
|
|
176
176
|
detailsTab?: string;
|
|
177
|
+
/**
|
|
178
|
+
* Each tab's count, by its name (`{ Updates: 2, Linked: 1 }`): the
|
|
179
|
+
* records it holds, shown beside the name. A tab left out, or at 0,
|
|
180
|
+
* shows none.
|
|
181
|
+
*/
|
|
182
|
+
tabCounts?: Readonly<Record<string, number>>;
|
|
183
|
+
/**
|
|
184
|
+
* How far from the top the tab bar sticks, for a page with a bar of its
|
|
185
|
+
* own pinned to the top: any CSS length (`'3.5rem'`,
|
|
186
|
+
* `'var(--page-bar-height)'`). Defaults to `0px`.
|
|
187
|
+
*/
|
|
188
|
+
tabsStickyTop?: string;
|
|
177
189
|
/**
|
|
178
190
|
* In the `rail` layout, where its columns stack (a phone): the rail
|
|
179
191
|
* before the main column (`rail-first`, the default), or the main column
|
|
@@ -233,4 +245,4 @@ export type EntityViewProps = {
|
|
|
233
245
|
trail?: readonly PageCrumb[];
|
|
234
246
|
};
|
|
235
247
|
};
|
|
236
|
-
export declare function EntityView({ title, documentTitle, titleEdit, leading, subtitle, badges, actions, notice, strip, sections, footer, layout, detailsTab, mobileOrder, railLabel, railFields, emptyFields, emptyText, printLabel, printLook, isLoading, error, onRetry, back, }: EntityViewProps): import("react").JSX.Element;
|
|
248
|
+
export declare function EntityView({ title, documentTitle, titleEdit, leading, subtitle, badges, actions, notice, strip, sections, footer, layout, detailsTab, tabCounts, tabsStickyTop, mobileOrder, railLabel, railFields, emptyFields, emptyText, printLabel, printLook, isLoading, error, onRetry, back, }: EntityViewProps): import("react").JSX.Element;
|
|
@@ -73,6 +73,15 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
|
|
|
73
73
|
// sections stay mounted, hidden, so a field open in place survives a
|
|
74
74
|
// switch. With no `tab` on any section, nothing changes.
|
|
75
75
|
//
|
|
76
|
+
// The tab bar (4.101, record standard 3B): bigger underline tabs (16px
|
|
77
|
+
// semibold, 14px on a phone), a 3px primary line under the open one, each
|
|
78
|
+
// tab's count beside its name (`tabCounts`; none for zero). The bar sticks
|
|
79
|
+
// to the top of whatever scrolls (the page, or a record dialog's body) as
|
|
80
|
+
// the record scrolls under it, `tabsStickyTop` below the top, and once
|
|
81
|
+
// stuck it shows the record's name above the tabs, so the other tabs and
|
|
82
|
+
// the record you're on stay in view. Stuck is measured (a marker just
|
|
83
|
+
// above the bar, compared on every scroll), never guessed from the width.
|
|
84
|
+
//
|
|
76
85
|
// `leading`, left of the title: the record's mark or avatar, with the
|
|
77
86
|
// title, subtitle and badges beside it at every width. A rail field's
|
|
78
87
|
// label sits to the left of its value (`railFields`, `beside` by default
|
|
@@ -100,7 +109,7 @@ import { EditInPlaceContext } from './edit-in-place.js';
|
|
|
100
109
|
import { EditInPlaceStore } from './edit-in-place-store.js';
|
|
101
110
|
import { EditableList } from './editable-list.js';
|
|
102
111
|
import { editRowClass, onEditRowClick } from './edit-row.js';
|
|
103
|
-
import { EditableValue, LeaveGuard } from './editable-value.js';
|
|
112
|
+
import { EditableField, EditableValue, LeaveGuard } from './editable-value.js';
|
|
104
113
|
import { EmptyText } from './empty-value.js';
|
|
105
114
|
import { EMPTY_DASH, isEmptyValue } from '../../lib/empty-value.js';
|
|
106
115
|
import { useRecordDialog } from './record-dialog-context.js';
|
|
@@ -258,7 +267,35 @@ function TabBody({ tab, railFields }) {
|
|
|
258
267
|
// (hidden but mounted unless selected). The selected tab is the address's,
|
|
259
268
|
// changed in place: the entry replaced, its state kept (a record over its
|
|
260
269
|
// list stays the dialog), the scroll where it was.
|
|
261
|
-
|
|
270
|
+
// Whether the tab bar is stuck: the marker just above it has scrolled
|
|
271
|
+
// above the bar's top. Read on every scroll anywhere (a capture listener:
|
|
272
|
+
// the page's or a dialog body's) and on resize.
|
|
273
|
+
function useStuck() {
|
|
274
|
+
const [marker, setMarker] = useState(null);
|
|
275
|
+
const [bar, setBar] = useState(null);
|
|
276
|
+
const [stuck, setStuck] = useState(false);
|
|
277
|
+
useEffect(() => {
|
|
278
|
+
if (!marker || !bar)
|
|
279
|
+
return;
|
|
280
|
+
const measure = () => setStuck(marker.getBoundingClientRect().top < bar.getBoundingClientRect().top - 1);
|
|
281
|
+
measure();
|
|
282
|
+
window.addEventListener('scroll', measure, { capture: true, passive: true });
|
|
283
|
+
window.addEventListener('resize', measure);
|
|
284
|
+
return () => {
|
|
285
|
+
window.removeEventListener('scroll', measure, { capture: true });
|
|
286
|
+
window.removeEventListener('resize', measure);
|
|
287
|
+
};
|
|
288
|
+
}, [marker, bar]);
|
|
289
|
+
return { setMarker, setBar, stuck };
|
|
290
|
+
}
|
|
291
|
+
function MainTabs({ tabs, label, railFields = 'beside', title, counts, stickyTop, }) {
|
|
292
|
+
const { setMarker, setBar, stuck } = useStuck();
|
|
293
|
+
const countOf = (tab) => {
|
|
294
|
+
if (!counts)
|
|
295
|
+
return 0;
|
|
296
|
+
const key = Object.keys(counts).find((name) => entityViewTabSlug(name) === tab.slug);
|
|
297
|
+
return key ? counts[key] ?? 0 : 0;
|
|
298
|
+
};
|
|
262
299
|
const location = useLocation();
|
|
263
300
|
const navigate = useNavigate();
|
|
264
301
|
const asked = new URLSearchParams(location.search).get(TAB_PARAM);
|
|
@@ -272,7 +309,13 @@ function MainTabs({ tabs, label, railFields = 'beside', }) {
|
|
|
272
309
|
const search = params.toString();
|
|
273
310
|
void navigate({ pathname: location.pathname, search: search ? `?${search}` : '', hash: location.hash }, { replace: true, state: location.state, preventScrollReset: true });
|
|
274
311
|
};
|
|
275
|
-
return (_jsxs(Tabs, { value: selected, onValueChange: (value) => select(String(value)), "data-slot": "entity-view-tabs", className: "min-w-0 gap-6", children: [_jsx(
|
|
312
|
+
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,
|
|
313
|
+
// A record dialog's body sets --entity-view-sticky-top to minus its
|
|
314
|
+
// padding, so the bar sits at the body's own top edge there.
|
|
315
|
+
style: { top: stickyTop ?? 'var(--entity-view-sticky-top, 0px)' }, className: "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)]", 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) => {
|
|
316
|
+
const count = countOf(tab);
|
|
317
|
+
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-foreground md:px-4 md:text-base dark:text-muted-foreground dark:data-active:text-foreground", 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));
|
|
318
|
+
}) })] }), tabs.map((tab) => (_jsx(TabsContent, { value: tab.slug, keepMounted: true, className: "@container/tab flex min-w-0 flex-col gap-6 [font-size:inherit]", children: _jsx(TabBody, { tab: tab, railFields: railFields }) }, tab.slug)))] }));
|
|
276
319
|
}
|
|
277
320
|
// The `tabs` layout's sections (1A): the main column's untabbed sections,
|
|
278
321
|
// then the tab list, with the facts (placed `rail`, no tab) as the last
|
|
@@ -298,7 +341,7 @@ function tabsLayout(sections, detailsTab) {
|
|
|
298
341
|
tabs.push({ slug, name: detailsTab, sections: facts, side: [], details: true });
|
|
299
342
|
return { above: main.filter((section) => section.tab === undefined), tabs, factsInColumn: false };
|
|
300
343
|
}
|
|
301
|
-
export function EntityView({ title, documentTitle, titleEdit, leading, subtitle, badges, actions, notice, strip, sections, footer, layout = 'tabs', detailsTab = 'Details', mobileOrder = 'rail-first', railLabel, railFields = 'beside', emptyFields = 'show', emptyText = EMPTY_DASH, printLabel = 'Print Notes', printLook = 'icon', isLoading, error, onRetry, back, }) {
|
|
344
|
+
export function EntityView({ title, documentTitle, titleEdit, leading, subtitle, badges, actions, notice, strip, sections, footer, layout = 'tabs', detailsTab = 'Details', tabCounts, tabsStickyTop, mobileOrder = 'rail-first', railLabel, railFields = 'beside', emptyFields = 'show', emptyText = EMPTY_DASH, printLabel = 'Print Notes', printLook = 'icon', isLoading, error, onRetry, back, }) {
|
|
302
345
|
// Editing in place: one store per view, and the leave-page prompt only
|
|
303
346
|
// while a field is open (or one is always editable).
|
|
304
347
|
const [store] = useState(() => new EditInPlaceStore());
|
|
@@ -346,7 +389,7 @@ export function EntityView({ title, documentTitle, titleEdit, leading, subtitle,
|
|
|
346
389
|
const shaped = layout === 'tabs' ? tabsLayout(sections, detailsTab) : null;
|
|
347
390
|
const tabs = shaped ? shaped.tabs : tabsOf(mainSections);
|
|
348
391
|
const tabbed = (section) => section.placement !== 'rail' && section.tab !== undefined;
|
|
349
|
-
const tabList = tabs.length > 0 && _jsx(MainTabs, { tabs: tabs, label: tabsLabel, railFields: railFields });
|
|
392
|
+
const tabList = tabs.length > 0 && (_jsx(MainTabs, { tabs: tabs, label: tabsLabel, railFields: railFields, title: title, counts: tabCounts, stickyTop: tabsStickyTop }));
|
|
350
393
|
const main = (_jsxs("div", { className: cn(RAIL_LAYOUT.main, railSections.length === 0 && RAIL_LAYOUT.mainAlone), children: [mainSections
|
|
351
394
|
.filter((section) => !tabbed(section))
|
|
352
395
|
.map((section) => (_jsx(ViewSection, { section: section }, section.title))), tabList] }));
|
|
@@ -365,5 +408,5 @@ export function EntityView({ title, documentTitle, titleEdit, leading, subtitle,
|
|
|
365
408
|
.filter((section) => !tabbed(section))
|
|
366
409
|
.map((section) => (_jsx(ViewSection, { section: section }, section.title))), tabList] }));
|
|
367
410
|
}
|
|
368
|
-
return (_jsx(EditInPlaceContext.Provider, { value: store, children: _jsx(EmptyContext.Provider, { value: { text: emptyText, fold: emptyFields === 'fold' }, children: _jsxs("div", { className: layout === 'rail' && !card ? RAIL_LAYOUT.page : cn('flex max-w-4xl flex-col', card ? 'gap-4' : 'gap-6'), "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(
|
|
411
|
+
return (_jsx(EditInPlaceContext.Provider, { value: store, children: _jsx(EmptyContext.Provider, { value: { text: emptyText, fold: emptyFields === 'fold' }, children: _jsxs("div", { className: layout === 'rail' && !card ? RAIL_LAYOUT.page : cn('flex max-w-4xl flex-col', card ? 'gap-4' : 'gap-6'), "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 && _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 }))] }) }) }));
|
|
369
412
|
}
|
|
@@ -45,6 +45,16 @@ export type MultiPickProps<Id extends string | number> = {
|
|
|
45
45
|
loading?: boolean;
|
|
46
46
|
/** Shown, not changeable. */
|
|
47
47
|
readOnly?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Offers Create "<typed>" when what's typed names no option (ignoring
|
|
50
|
+
* case and spaces at the ends). Opens the app's create form with the
|
|
51
|
+
* name, or saves it at once, and resolves with the new option, which is
|
|
52
|
+
* then picked (in place, through `onPick`), or `null` when the form was
|
|
53
|
+
* cancelled. Rejecting (with the AppError) shows the reason in the
|
|
54
|
+
* picker, the typed name kept. The new option shows as a chip until the
|
|
55
|
+
* app's `options` have it.
|
|
56
|
+
*/
|
|
57
|
+
onCreate?: (name: string) => Promise<MultiPickOption<Id> | null>;
|
|
48
58
|
className?: string;
|
|
49
59
|
};
|
|
50
|
-
export declare function MultiPick<Id extends string | number>({ options, value, onValueChange, onPick, 'aria-label': label, 'aria-describedby': describedBy, id, placeholder, emptyText, limit, loading, readOnly, className, }: MultiPickProps<Id>): import("react").JSX.Element;
|
|
60
|
+
export declare function MultiPick<Id extends string | number>({ options, value, onValueChange, onPick, 'aria-label': label, 'aria-describedby': describedBy, id, placeholder, emptyText, limit, loading, readOnly, onCreate, className, }: MultiPickProps<Id>): import("react").JSX.Element;
|
|
@@ -28,8 +28,19 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
28
28
|
// them all. The options can be the app's list of records (its query's
|
|
29
29
|
// rows as `{ id, label }`, `loading` while it loads), so a link to
|
|
30
30
|
// several other records uses it too.
|
|
31
|
+
// - `onCreate` (4.102): when what's typed names no option, Create "<typed>"
|
|
32
|
+
// shows under the chips (Enter in the box does the same when nothing
|
|
33
|
+
// matches; Down reaches it when there are no chips). It calls the app's
|
|
34
|
+
// `onCreate(name)`: its small create form with the name filled in, or a
|
|
35
|
+
// save straight away. While that's out the button reads Creating
|
|
36
|
+
// "<typed>"… (`aria-busy`), the box can't change, and an edit in place
|
|
37
|
+
// holding this stays open (`data-edit-hold`). The option it resolves
|
|
38
|
+
// with joins the chips and is picked (in place, saved as any pick is);
|
|
39
|
+
// `null` (the form cancelled) changes nothing. A rejection shows its
|
|
40
|
+
// reason under the chips and keeps what was typed, so Create can be
|
|
41
|
+
// tried again. Either way the caret goes back to the box.
|
|
31
42
|
import { CheckIcon } from 'lucide-react';
|
|
32
|
-
import { useEffect, useId, useRef, useState } from 'react';
|
|
43
|
+
import { useEffect, useId, useLayoutEffect, useRef, useState } from 'react';
|
|
33
44
|
import { toast } from 'sonner';
|
|
34
45
|
import { cn } from 'cn';
|
|
35
46
|
import { Button } from '../ui/button.js';
|
|
@@ -37,15 +48,25 @@ import { FieldError } from '../ui/field.js';
|
|
|
37
48
|
import { Input } from '../ui/input.js';
|
|
38
49
|
import { Spinner } from '../ui/spinner.js';
|
|
39
50
|
import { ToggleGroup, ToggleGroupItem } from '../ui/toggle-group.js';
|
|
51
|
+
import { namesRecord } from '../../lib/names-record.js';
|
|
40
52
|
import { messageOf } from './edit-in-place-store.js';
|
|
41
|
-
export function MultiPick({ options, value, onValueChange, onPick, 'aria-label': label, 'aria-describedby': describedBy, id, placeholder = 'Filter', emptyText = 'No options.', limit = 30, loading = false, readOnly = false, className, }) {
|
|
53
|
+
export function MultiPick({ options, value, onValueChange, onPick, 'aria-label': label, 'aria-describedby': describedBy, id, placeholder = 'Filter', emptyText = 'No options.', limit = 30, loading = false, readOnly = false, onCreate, className, }) {
|
|
42
54
|
const key = useId();
|
|
43
55
|
const [filter, setFilter] = useState('');
|
|
44
56
|
const [showAll, setShowAll] = useState(false);
|
|
45
57
|
const [pending, setPending] = useState(() => new Map());
|
|
46
58
|
const [refused, setRefused] = useState(() => new Map());
|
|
59
|
+
// Options made here that the app's `options` don't have yet.
|
|
60
|
+
const [created, setCreated] = useState([]);
|
|
61
|
+
// The name Create is making, while the app's answer is out.
|
|
62
|
+
const [creating, setCreating] = useState(null);
|
|
63
|
+
const [createFailed, setCreateFailed] = useState(null);
|
|
64
|
+
// Said to a screen reader once a created option is picked.
|
|
65
|
+
const [announced, setAnnounced] = useState('');
|
|
47
66
|
const filterBox = useRef(null);
|
|
48
67
|
const chips = useRef(null);
|
|
68
|
+
const createButton = useRef(null);
|
|
69
|
+
const root = useRef(null);
|
|
49
70
|
const mounted = useRef(true);
|
|
50
71
|
useEffect(() => {
|
|
51
72
|
mounted.current = true;
|
|
@@ -61,8 +82,15 @@ export function MultiPick({ options, value, onValueChange, onPick, 'aria-label':
|
|
|
61
82
|
if ([...pending.values()].some((entry) => entry.inFlight === 0))
|
|
62
83
|
setPending(new Map([...pending].filter(([, entry]) => entry.inFlight > 0)));
|
|
63
84
|
}
|
|
85
|
+
// The app's options, then any made here that they don't have yet.
|
|
86
|
+
const all = created.length === 0 ? options : [...options, ...created.filter((made) => !options.some((option) => option.id === made.id))];
|
|
87
|
+
// What a create answered later reads: the value and picks by then.
|
|
88
|
+
const latest = useRef({ value, pending });
|
|
89
|
+
useLayoutEffect(() => {
|
|
90
|
+
latest.current = { value, pending };
|
|
91
|
+
});
|
|
64
92
|
const isPicked = (option) => pending.get(option)?.picked ?? value.includes(option);
|
|
65
|
-
const shown =
|
|
93
|
+
const shown = all.filter((option) => isPicked(option.id)).map((option) => option.id);
|
|
66
94
|
const settle = (option, ok) => setPending((current) => {
|
|
67
95
|
const entry = current.get(option);
|
|
68
96
|
if (!entry)
|
|
@@ -76,19 +104,11 @@ export function MultiPick({ options, value, onValueChange, onPick, 'aria-label':
|
|
|
76
104
|
next.set(option, { ...entry, inFlight });
|
|
77
105
|
return next;
|
|
78
106
|
});
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
// In the options' order, keeping any picked id with no option.
|
|
82
|
-
const known = new Set(options.map((other) => other.id));
|
|
83
|
-
onValueChange?.([
|
|
84
|
-
...options.filter((other) => (other.id === option.id ? picked : isPicked(other.id))).map((other) => other.id),
|
|
85
|
-
...value.filter((other) => !known.has(other)),
|
|
86
|
-
]);
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
107
|
+
// Edited in place: one pick saved on its own.
|
|
108
|
+
const savePick = (option, picked, save) => {
|
|
89
109
|
setRefused((current) => without(current, option.id));
|
|
90
110
|
setPending((current) => new Map(current).set(option.id, { picked, inFlight: (current.get(option.id)?.inFlight ?? 0) + 1 }));
|
|
91
|
-
|
|
111
|
+
save(option.id, picked).then(() => settle(option.id, true), (error) => {
|
|
92
112
|
settle(option.id, false);
|
|
93
113
|
const reason = `Couldn't ${picked ? 'add' : 'remove'} ${option.label}: ${messageOf(error)}`;
|
|
94
114
|
// Closed before the answer: the reason has nowhere else to show.
|
|
@@ -98,18 +118,90 @@ export function MultiPick({ options, value, onValueChange, onPick, 'aria-label':
|
|
|
98
118
|
toast.error(reason);
|
|
99
119
|
});
|
|
100
120
|
};
|
|
121
|
+
const toggle = (option, picked) => {
|
|
122
|
+
if (!onPick) {
|
|
123
|
+
// In the options' order, keeping any picked id with no option.
|
|
124
|
+
const known = new Set(all.map((other) => other.id));
|
|
125
|
+
onValueChange?.([
|
|
126
|
+
...all.filter((other) => (other.id === option.id ? picked : isPicked(other.id))).map((other) => other.id),
|
|
127
|
+
...value.filter((other) => !known.has(other)),
|
|
128
|
+
]);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
savePick(option, picked, onPick);
|
|
132
|
+
};
|
|
101
133
|
const needle = filter.trim().toLowerCase();
|
|
102
|
-
const matching = needle ?
|
|
134
|
+
const matching = needle ? all.filter((option) => option.label.toLowerCase().includes(needle)) : all;
|
|
103
135
|
// A long set: the first `limit`, and any picked one past them, in the options' order.
|
|
104
|
-
const capped = !needle && !showAll &&
|
|
136
|
+
const capped = !needle && !showAll && all.length > limit;
|
|
105
137
|
const visible = capped ? matching.filter((option, index) => index < limit || isPicked(option.id)) : matching;
|
|
106
|
-
const hidden =
|
|
107
|
-
|
|
138
|
+
const hidden = all.length - visible.length;
|
|
139
|
+
const name = filter.trim();
|
|
140
|
+
const offerCreate = Boolean(onCreate) && !readOnly && !loading && (creating !== null || (name !== '' && !namesRecord(all, name)));
|
|
141
|
+
const create = () => {
|
|
142
|
+
if (!onCreate || creating !== null || name === '')
|
|
143
|
+
return;
|
|
144
|
+
setCreating(name);
|
|
145
|
+
setCreateFailed(null);
|
|
146
|
+
setAnnounced('');
|
|
147
|
+
// The caret back in the box once the app's form has closed, so the
|
|
148
|
+
// keyboard keeps its place: the Create button is gone after a create.
|
|
149
|
+
// A form's dialog hands focus back as it closes, a few frames on, so
|
|
150
|
+
// this waits (up to a second) while focus is still in something else.
|
|
151
|
+
// After a refusal the caret stays on Create, to try again.
|
|
152
|
+
const refocus = (created, frames = 60) => requestAnimationFrame(() => {
|
|
153
|
+
if (!mounted.current)
|
|
154
|
+
return;
|
|
155
|
+
const at = document.activeElement;
|
|
156
|
+
if (at === null || at === document.body || (created && at === createButton.current))
|
|
157
|
+
filterBox.current?.focus();
|
|
158
|
+
else if (!root.current?.contains(at) && frames > 0)
|
|
159
|
+
refocus(created, frames - 1);
|
|
160
|
+
});
|
|
161
|
+
onCreate(name).then((option) => {
|
|
162
|
+
if (!mounted.current) {
|
|
163
|
+
// Closed meanwhile: in place, the pick still saves.
|
|
164
|
+
if (option && onPick)
|
|
165
|
+
void onPick(option.id, true).catch((error) => toast.error(`Couldn't add ${option.label}: ${messageOf(error)}`));
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
setCreating(null);
|
|
169
|
+
if (option) {
|
|
170
|
+
setCreated((current) => [...current.filter((made) => made.id !== option.id), option]);
|
|
171
|
+
setFilter('');
|
|
172
|
+
setAnnounced(`${option.label} created and picked.`);
|
|
173
|
+
const { value: now, pending: out } = latest.current;
|
|
174
|
+
if (!(out.get(option.id)?.picked ?? now.includes(option.id))) {
|
|
175
|
+
if (onPick)
|
|
176
|
+
savePick(option, true, onPick);
|
|
177
|
+
else
|
|
178
|
+
onValueChange?.([...now, option.id]);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
refocus(option !== null);
|
|
182
|
+
}, (error) => {
|
|
183
|
+
const reason = `Couldn't create "${name}": ${messageOf(error)}`;
|
|
184
|
+
if (!mounted.current) {
|
|
185
|
+
toast.error(reason);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
setCreating(null);
|
|
189
|
+
setCreateFailed(reason);
|
|
190
|
+
refocus(false);
|
|
191
|
+
});
|
|
192
|
+
};
|
|
193
|
+
// Down from the box: into the chips, at the one the group would tab to
|
|
194
|
+
// (Create, with no chips). Enter, when nothing matches, creates.
|
|
108
195
|
const onFilterKeyDown = (event) => {
|
|
196
|
+
if (event.key === 'Enter' && offerCreate && visible.length === 0) {
|
|
197
|
+
event.preventDefault();
|
|
198
|
+
create();
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
109
201
|
if (event.key !== 'ArrowDown')
|
|
110
202
|
return;
|
|
111
203
|
const items = [...(chips.current?.querySelectorAll('[data-slot="toggle-group-item"]') ?? [])];
|
|
112
|
-
const target = items.find((item) => item.tabIndex === 0) ?? items[0];
|
|
204
|
+
const target = items.find((item) => item.tabIndex === 0) ?? items[0] ?? createButton.current;
|
|
113
205
|
if (!target)
|
|
114
206
|
return;
|
|
115
207
|
event.preventDefault();
|
|
@@ -122,13 +214,17 @@ export function MultiPick({ options, value, onValueChange, onPick, 'aria-label':
|
|
|
122
214
|
filterBox.current?.focus();
|
|
123
215
|
};
|
|
124
216
|
const errorId = (option) => `${key}-refused-${String(option)}`;
|
|
125
|
-
|
|
217
|
+
const createErrorId = `${key}-create-failed`;
|
|
218
|
+
return (_jsxs("div", { ref: root, "data-slot": "multi-pick", "data-edit-hold": creating !== null ? '' : undefined, className: cn('flex w-full min-w-0 flex-col gap-2', className), children: [_jsx(Input, { ref: filterBox, id: id, type: "search", value: filter, onChange: (event) => {
|
|
219
|
+
setFilter(event.target.value);
|
|
220
|
+
setCreateFailed(null);
|
|
221
|
+
}, onKeyDown: onFilterKeyDown, placeholder: placeholder, "aria-label": `Filter ${label}`, "aria-describedby": describedBy, autoComplete: "off", readOnly: readOnly || creating !== null, className: "max-w-xs" }), loading ? (_jsx("p", { role: "status", className: "type-caption text-muted-foreground", children: "Loading\u2026" })) : visible.length === 0 ? (_jsx("p", { className: "type-caption text-muted-foreground", children: all.length === 0 && !needle ? emptyText : 'No matches.' })) : (_jsx(ToggleGroup, { ref: chips, multiple: true, variant: "outline", size: "sm", spacing: 1.5, value: shown.map(String), disabled: readOnly, onKeyDown: onChipsKeyDown, "aria-label": label, "aria-describedby": describedBy,
|
|
126
222
|
// Wraps at every width; a chip longer than the row ends in "…".
|
|
127
223
|
className: "w-full max-w-full min-w-0 flex-wrap", children: visible.map((option) => {
|
|
128
224
|
const picked = isPicked(option.id);
|
|
129
225
|
const saving = (pending.get(option.id)?.inFlight ?? 0) > 0;
|
|
130
226
|
return (_jsxs(ToggleGroupItem, { value: String(option.id), onPressedChange: (next) => toggle(option, next), "aria-busy": saving || undefined, "aria-describedby": refused.has(option.id) ? errorId(option.id) : undefined, title: option.label, className: "max-w-full min-w-0", children: [option.icon && (_jsx("span", { "aria-hidden": "true", className: "inline-flex shrink-0", children: option.icon })), _jsx("span", { className: "min-w-0 truncate", children: option.label }), _jsx("span", { "aria-hidden": "true", className: "inline-flex size-3.5 shrink-0 items-center justify-center", children: saving ? (_jsx(Spinner, { className: "size-3.5 text-muted-foreground" })) : (picked && _jsx(CheckIcon, { className: "size-3.5" })) })] }, option.id));
|
|
131
|
-
}) })), !loading && capped && hidden > 0 && (_jsxs(Button, { type: "button", variant: "link", size: "sm", className: "h-auto w-fit p-0", "aria-label": `Show All ${
|
|
227
|
+
}) })), !loading && capped && hidden > 0 && (_jsxs(Button, { type: "button", variant: "link", size: "sm", className: "h-auto w-fit p-0", "aria-label": `Show All ${all.length} ${label}`, onClick: () => setShowAll(true), children: ["Show All ", all.length] })), offerCreate && (_jsxs(Button, { ref: createButton, type: "button", variant: "outline", size: "sm", "data-create": "", "aria-disabled": creating !== null || undefined, "aria-busy": creating !== null || undefined, "aria-describedby": createFailed ? createErrorId : undefined, onClick: create, className: "w-fit max-w-full min-w-0", children: [creating !== null && _jsx(Spinner, { "aria-hidden": "true", className: "size-3.5" }), _jsx("span", { className: "min-w-0 truncate", children: creating !== null ? `Creating "${creating}"…` : `Create "${name}"` })] })), _jsx("span", { role: "status", className: "sr-only", children: announced }), (refused.size > 0 || createFailed) && (_jsxs(FieldError, { className: "type-caption flex flex-col gap-0.5", children: [[...refused].map(([option, reason]) => (_jsx("span", { id: errorId(option), children: reason }, String(option)))), createFailed && _jsx("span", { id: createErrorId, children: createFailed })] }))] }));
|
|
132
228
|
}
|
|
133
229
|
function without(map, key) {
|
|
134
230
|
if (!map.has(key))
|
|
@@ -161,7 +161,12 @@ export function RecordDialogRoute({ list, label, className, look = 'record', ful
|
|
|
161
161
|
return;
|
|
162
162
|
}
|
|
163
163
|
close();
|
|
164
|
-
}, children: _jsxs(DialogContent, { showCloseButton: false, "aria-labelledby": titleId, "aria-label": label, "data-slot": "record-dialog", size: card ? 'confirm' : 'record', "data-look": look, className: cn('gap-0 overflow-hidden p-0 data-closed:hidden', card && 'flex max-h-[calc(100dvh-2rem)] flex-col', className), children: [!card && (_jsxs("div", { className: cn('flex items-center gap-2 border-b px-2 py-2', fullPage ? 'justify-between' : 'justify-end'), children: [fullPage && (_jsxs(Link, { to: { pathname: location.pathname, search: location.search, hash: location.hash }, replace: true, className: buttonVariants({ variant: 'ghost', size: 'sm' }), children: [_jsx(Maximize2Icon, { "aria-hidden": "true" }), "Open Full Page"] })), _jsxs(DialogClose, { render: _jsx(Button, { variant: "ghost", size: "icon-sm" }), children: [_jsx(XIcon, { "aria-hidden": "true" }), _jsx("span", { className: "sr-only", children: "Close" })] })] })), _jsx("div", { "data-slot": "record-dialog-body", className: cn('min-h-0 overflow-y-auto',
|
|
164
|
+
}, children: _jsxs(DialogContent, { showCloseButton: false, "aria-labelledby": titleId, "aria-label": label, "data-slot": "record-dialog", size: card ? 'confirm' : 'record', "data-look": look, className: cn('gap-0 overflow-hidden p-0 data-closed:hidden', card && 'flex max-h-[calc(100dvh-2rem)] flex-col', className), children: [!card && (_jsxs("div", { className: cn('flex items-center gap-2 border-b px-2 py-2', fullPage ? 'justify-between' : 'justify-end'), children: [fullPage && (_jsxs(Link, { to: { pathname: location.pathname, search: location.search, hash: location.hash }, replace: true, className: buttonVariants({ variant: 'ghost', size: 'sm' }), children: [_jsx(Maximize2Icon, { "aria-hidden": "true" }), "Open Full Page"] })), _jsxs(DialogClose, { render: _jsx(Button, { variant: "ghost", size: "icon-sm" }), children: [_jsx(XIcon, { "aria-hidden": "true" }), _jsx("span", { className: "sr-only", children: "Close" })] })] })), _jsx("div", { "data-slot": "record-dialog-body", className: cn('min-h-0 overflow-y-auto',
|
|
165
|
+
// A record's tab bar sticks to the body's top edge, not inside
|
|
166
|
+
// its padding (4.101): minus the padding, for EntityView.
|
|
167
|
+
card
|
|
168
|
+
? 'p-4 pb-[calc(1rem+env(safe-area-inset-bottom))] [--entity-view-sticky-top:-1rem] md:p-5 md:[--entity-view-sticky-top:-1.25rem]'
|
|
169
|
+
: 'p-4 [--entity-view-sticky-top:-1rem] sm:p-6 sm:[--entity-view-sticky-top:-1.5rem]'), children: _jsx(RecordDialogContext.Provider, { value: dialog, children: open && outlet }) })] }) })] }));
|
|
165
170
|
}
|
|
166
171
|
/**
|
|
167
172
|
* A link to a record that opens it over the current list (a board's card,
|
|
@@ -4,10 +4,10 @@ import { Input } from '../ui/input.js';
|
|
|
4
4
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '../ui/select.js';
|
|
5
5
|
import { linkHref, linkRule } from '../../lib/link-href.js';
|
|
6
6
|
import { editInPlace } from './edit-in-place.js';
|
|
7
|
-
import {
|
|
7
|
+
import { EditableField } from './editable-value.js';
|
|
8
8
|
/** A name in one line: Enter saves, the form's rule runs first, a taken name's 422 shows in the cell. */
|
|
9
9
|
export function NameCell({ label, value, save, schema, children, inputClassName = 'w-48' }) {
|
|
10
|
-
return (_jsx(
|
|
10
|
+
return (_jsx(EditableField, { keepPencilRoom: true, label: label, layout: "inline", edit: editInPlace({
|
|
11
11
|
kind: 'text',
|
|
12
12
|
value,
|
|
13
13
|
schema,
|
|
@@ -17,7 +17,7 @@ export function NameCell({ label, value, save, schema, children, inputClassName
|
|
|
17
17
|
}
|
|
18
18
|
/** A single choice: its list opens with the cell, a pick saves, closing it with no pick gives up. */
|
|
19
19
|
export function ChoiceCell({ label, value, options, render, save, triggerClassName = 'w-40', }) {
|
|
20
|
-
return (_jsx(
|
|
20
|
+
return (_jsx(EditableField, { keepPencilRoom: true, label: label, layout: "inline", edit: editInPlace({
|
|
21
21
|
kind: 'choice',
|
|
22
22
|
value,
|
|
23
23
|
save,
|
|
@@ -52,7 +52,7 @@ export function LinkCell({ label, value, save, linkText, emptyLabel = 'Not set',
|
|
|
52
52
|
// Only an address the editor would have saved is shown as a link: a
|
|
53
53
|
// stored `javascript:` reads as text, never as something to click.
|
|
54
54
|
const href = value ? linkHref(value) : null;
|
|
55
|
-
return (_jsx(
|
|
55
|
+
return (_jsx(EditableField, { keepPencilRoom: true, label: label, layout: "inline", edit: editInPlace({
|
|
56
56
|
kind: 'text',
|
|
57
57
|
value: value ?? '',
|
|
58
58
|
schema: LINK_RULE,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tristan2828/ui-foundation",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.102.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": {
|