@tristan2828/ui-foundation 4.127.0 → 4.128.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.
Files changed (43) hide show
  1. package/conventions/docs/add-an-entity.md +52 -16
  2. package/conventions/docs/design-language.md +25 -8
  3. package/dist/components/app/edit-in-place-store.d.ts +2 -3
  4. package/dist/components/app/edit-in-place-store.js +53 -9
  5. package/dist/components/app/entity-form.d.ts +9 -1
  6. package/dist/components/app/entity-form.js +9 -2
  7. package/dist/components/app/equal-items.d.ts +2 -1
  8. package/dist/components/app/equal-items.js +9 -25
  9. package/dist/components/app/form-conflict-notice.d.ts +8 -0
  10. package/dist/components/app/form-conflict-notice.js +15 -0
  11. package/dist/components/app/form-dialog.d.ts +8 -1
  12. package/dist/components/app/form-dialog.js +9 -2
  13. package/dist/components/app/milkdown-editor.js +21 -329
  14. package/dist/components/app/notify.d.ts +18 -1
  15. package/dist/components/app/notify.js +26 -3
  16. package/dist/components/app/page-restore.js +1 -1
  17. package/dist/components/app/rich-text-box-anchor.d.ts +6 -0
  18. package/dist/components/app/rich-text-box-anchor.js +8 -0
  19. package/dist/components/app/rich-text-heading-view.d.ts +4 -0
  20. package/dist/components/app/rich-text-heading-view.js +91 -0
  21. package/dist/components/app/rich-text-link-box.d.ts +9 -0
  22. package/dist/components/app/rich-text-link-box.js +40 -0
  23. package/dist/components/app/rich-text-links.d.ts +14 -0
  24. package/dist/components/app/rich-text-links.js +92 -0
  25. package/dist/components/app/rich-text-page-box.d.ts +10 -0
  26. package/dist/components/app/rich-text-page-box.js +45 -0
  27. package/dist/components/app/rich-text-task-item-view.d.ts +4 -0
  28. package/dist/components/app/rich-text-task-item-view.js +59 -0
  29. package/dist/components/app/rich-text-toggle-heading.js +1 -1
  30. package/dist/components/app/step-row.d.ts +15 -0
  31. package/dist/components/app/step-row.js +27 -0
  32. package/dist/components/app/step-track.d.ts +82 -0
  33. package/dist/components/app/step-track.js +98 -0
  34. package/dist/components/ui/sonner.js +1 -1
  35. package/dist/hooks/use-form-version.d.ts +101 -0
  36. package/dist/hooks/use-form-version.js +187 -0
  37. package/dist/hooks/use-record-update.d.ts +2 -7
  38. package/dist/hooks/use-record-update.js +2 -11
  39. package/dist/index.d.ts +3 -1
  40. package/dist/index.js +2 -0
  41. package/dist/lib/refusal.d.ts +9 -0
  42. package/dist/lib/refusal.js +19 -0
  43. package/package.json +1 -1
@@ -15,19 +15,19 @@
15
15
  - Step 8: Add Playwright specs for all three screens · lines 776–863
16
16
  - Step 9: Register the nav entry and route names · lines 864–878
17
17
  - Step 10: `npm run verify`. · lines 879–881
18
- - [How a list opens a record](#how-a-list-opens-a-record) · lines 883–1385
19
- - [The record view](#the-record-view) · lines 1036–1215
20
- - [Forms](#forms) · lines 1217–1299
21
- - [Dialogs](#dialogs) · lines 1301–1332
22
- - [Toasts and feedback](#toasts-and-feedback) · lines 1334–1385
23
- - [What not to copy](#what-not-to-copy) · lines 1387–1422
24
- - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 1424–1441
25
- - [Saves that don't overwrite](#saves-that-dont-overwrite) · lines 1443–1489
26
- - [Deleting](#deleting) · lines 1491–1522
27
- - [Fields only a script writes](#fields-only-a-script-writes) · lines 1524–1545
28
- - [Searching one part of the app](#searching-one-part-of-the-app) · lines 1547–1556
29
- - [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1559–1601
30
- - [Behind a sign-in proxy](#behind-a-sign-in-proxy) · lines 1603–1639
18
+ - [How a list opens a record](#how-a-list-opens-a-record) · lines 883–1402
19
+ - [The record view](#the-record-view) · lines 1036–1217
20
+ - [Forms](#forms) · lines 1219–1301
21
+ - [Dialogs](#dialogs) · lines 1303–1336
22
+ - [Toasts and feedback](#toasts-and-feedback) · lines 1338–1402
23
+ - [What not to copy](#what-not-to-copy) · lines 1404–1439
24
+ - [After a commit, in the backend](#after-a-commit-in-the-backend) · lines 1441–1458
25
+ - [Saves that don't overwrite](#saves-that-dont-overwrite) · lines 1460–1525
26
+ - [Deleting](#deleting) · lines 1527–1558
27
+ - [Fields only a script writes](#fields-only-a-script-writes) · lines 1560–1581
28
+ - [Searching one part of the app](#searching-one-part-of-the-app) · lines 1583–1592
29
+ - [What a chat is told about an entity](#what-a-chat-is-told-about-an-entity) · lines 1595–1637
30
+ - [Behind a sign-in proxy](#behind-a-sign-in-proxy) · lines 1639–1675
31
31
 
32
32
  <!-- /index -->
33
33
 
@@ -1204,7 +1204,9 @@ A record uses the parts it has, in this order:
1204
1204
  `panels` when each has several details, `stepper` (4.127) for a
1205
1205
  sequence with a current step whose items are looked at one at a time
1206
1206
  (numbered steps picking the one panel shown; design-language.md "A few
1207
- equal things"). Never hand-made cards, a grid or a stepper of their own. An item
1207
+ equal things"). The same steps read only, on a list card with a
1208
+ caption under the current one ("Day 12"), are `StepTrack` (4.128).
1209
+ Never hand-made cards, a grid or a stepper of their own. An item
1208
1210
  edited or removed on its own carries its editor as `content` and its
1209
1211
  Edit and Remove as `actions` (4.94), `wide` while the editor is open;
1210
1212
  never an editor put in a field's value.
@@ -1326,6 +1328,8 @@ instead, as a small card: `RecordDialogRoute look="card"` (4.98).
1326
1328
  - **A form in a dialog is a `FormDialog`**: the title, the fields
1327
1329
  scrolling between it and the pinned Cancel and Add, a failed save as a
1328
1330
  destructive `Notice` above the buttons with Try Again, and `dirty`.
1331
+ An edit refused because the record changed elsewhere is its
1332
+ `conflict` instead ("Saves that don't overwrite").
1329
1333
  Opened from a page with `open`/`onOpenChange`; as a list's `new` route
1330
1334
  with neither (above).
1331
1335
  - **Always a dialog, never a side panel**, except a phone's filters
@@ -1341,6 +1345,7 @@ sight.** What happened where the person is looking says so there.
1341
1345
  | --- | --- |
1342
1346
  | A delete (soft: with Undo) | `DeleteAction`'s toast, "Deleted The Long Walk" |
1343
1347
  | A record made, landing on its own page | a toast, "Added The Long Walk" |
1348
+ | A record made where the person stays (a dialog over a page of tiles) | a toast with Open, "Added The Long Walk" · Open (`notify.done`'s `open`) |
1344
1349
  | An edit in place, a quick action, a toggle | the value itself and its "Saved" (cell pattern 18). **Never a toast** |
1345
1350
  | An action that failed, its button still there | `ActionError` beside the button: the reason and Try Again |
1346
1351
  | An action that failed after its page was left | a toast that stays until it's closed (`useAction` does this) |
@@ -1374,6 +1379,18 @@ sight.** What happened where the person is looking says so there.
1374
1379
  verb first, "Deleted The Long Walk", "Added Paper Atlas"; Undo, when
1375
1380
  given, then says "Restored The Long Walk". Never "X deleted", never
1376
1381
  "Book deleted". Toasts last 4 seconds, Undo's too.
1382
+ - **A record made without leaving the page gets Open:**
1383
+ ``notify.done('Added', book.title, { open: `/books/${book.id}` })``.
1384
+ When saving closes a dialog and stays put (a homepage of tiles, a
1385
+ `FormDialog` opened from a page), the toast says "Added The Long Walk"
1386
+ with an **Open** link to the new record; never a hand-built sonner
1387
+ toast. `open` is a path (anything `Link`'s `to` takes) or
1388
+ `{ to, label }` for another word ("View"). It is a real link, named
1389
+ "Open The Long Walk" for a screen reader, reached from the keyboard
1390
+ (Alt+T to the toasts, then Tab), and closes the toast as it goes; the
1391
+ toast keeps its 4 seconds. With `undo` too, both show, Open first. A
1392
+ create that lands on the record's own
1393
+ page doesn't need it: the person is already there.
1377
1394
  - **An error stays beside what failed**: `const save = useAction(mutation)`,
1378
1395
  `save.run(…)` on the button (`disabled={save.pending}`, a `Spinner` in
1379
1396
  it), `<ActionError action={save} />` next to it. Never
@@ -1477,6 +1494,24 @@ work. The fix is optimistic concurrency, the same for every entity:
1477
1494
  paragraph it says so, and only a second Keep Mine replaces theirs. Any
1478
1495
  other field's Keep Mine saves what's typed over theirs. An `editInPlace`
1479
1496
  takes its own `rebase`, or `rebase: false`.
1497
+ - **The edit form sends it too: `useFormVersion`**, with the same
1498
+ `withVersion`. `useFormVersion({ record: query.data, withVersion,
1499
+ refetch: query.refetch })` keeps the record the form opened with: the
1500
+ form's `values` come from `version.record`, so a refetch in the
1501
+ background never resets what's typed, and the save sends
1502
+ `version.send(update)`, that record's version. In the save's `onError`,
1503
+ `if (version.refused(error)) return` first: a 409 is the hook's (it
1504
+ fetches the newer version), anything else the form's as before. Pass
1505
+ `conflict={version.conflict}` to `EntityForm` (or `FormDialog`, for an
1506
+ edit in a dialog): the bar shows a warning Notice, "Changed elsewhere",
1507
+ saying nothing was saved and what's typed is still there, with **Keep
1508
+ Mine** (saves the form as it is over theirs, built on the newer
1509
+ version) and **Show Saved** (the form takes their record; the Notice
1510
+ says the typing goes). Never Try Again: the same save would be refused
1511
+ again. A form that stays open after a save (a dialog) calls
1512
+ `version.saved(record)` in `onSuccess`, so its next save builds on it.
1513
+ Keep Mine sends the whole form, so a field they changed and the form
1514
+ didn't goes back to the form's value.
1480
1515
  - **A chat** gets the same check through the entity's `McpEntity.update`:
1481
1516
  the `update` tool tells it to send the `updatedAt` it read as
1482
1517
  `baseUpdatedAt`, and a 409 comes back as a refusal that says to fetch
@@ -1485,8 +1520,9 @@ work. The fix is optimistic concurrency, the same for every entity:
1485
1520
  - **Copy:** `template/backend/app/routers/widgets.py` (`update_widget`),
1486
1521
  migration `0017_widget_updated_at.py`, `WidgetOut.updated_at` and
1487
1522
  `WidgetUpdate.base_updated_at` in `app/schemas.py`, the PATCH mock in
1488
- `src/mocks/handlers.ts`, `withVersion` in `use-widgets.ts`, and the
1489
- "two writers" specs in `e2e/widget-edit-in-place.spec.ts`.
1523
+ `src/mocks/handlers.ts`, `withVersion` in `use-widgets.ts`,
1524
+ `useFormVersion` in `widget-form.tsx`, and the "two writers" specs in
1525
+ `e2e/widget-edit-in-place.spec.ts` and `e2e/widget-form.spec.ts`.
1490
1526
 
1491
1527
  ## Deleting
1492
1528
 
@@ -30,14 +30,14 @@
30
30
  - [A list as cards](#a-list-as-cards) · lines 1308–1354
31
31
  - [Key numbers on a record](#key-numbers-on-a-record) · lines 1356–1392
32
32
  - [Parts of the page standards](#parts-of-the-page-standards) · lines 1394–1464
33
- - [A few equal things](#a-few-equal-things) · lines 1466–1569
34
- - [An overview page](#an-overview-page) · lines 1571–1642
35
- - [A record's header and empty values](#a-records-header-and-empty-values) · lines 1643–1709
36
- - [A record's tabs, mark and facts](#a-records-tabs-mark-and-facts) · lines 1711–1848
37
- - [Picking at random](#picking-at-random) · lines 1850–1881
38
- - [Filling in what's missing](#filling-in-whats-missing) · lines 1883–1950
39
- - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1952–1977
40
- - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 1979–2075
33
+ - [A few equal things](#a-few-equal-things) · lines 1466–1586
34
+ - [An overview page](#an-overview-page) · lines 1588–1659
35
+ - [A record's header and empty values](#a-records-header-and-empty-values) · lines 1660–1726
36
+ - [A record's tabs, mark and facts](#a-records-tabs-mark-and-facts) · lines 1728–1865
37
+ - [Picking at random](#picking-at-random) · lines 1867–1898
38
+ - [Filling in what's missing](#filling-in-whats-missing) · lines 1900–1967
39
+ - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1969–1994
40
+ - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 1996–2092
41
41
 
42
42
  <!-- /index -->
43
43
 
@@ -1520,6 +1520,23 @@ one look per set; a sixth is asked for first.
1520
1520
  in its own box (never the page) as the record's tab bar does, the
1521
1521
  shown step kept in view; it never folds into a select, which would
1522
1522
  hide the done and current marks the stepper is for.
1523
+ - **The same steps, read only** (4.128): `StepTrack` draws the stepper's
1524
+ row on its own, with no panels and nothing to pick, for a display of
1525
+ where a sequence is (a list card showing a program's phases). The
1526
+ marks, the line and the sizes are the stepper's own parts, so the two
1527
+ never differ; the current step is ringed and has "Current" under it,
1528
+ or `caption` in its place ("Day 12"), its name still saying ", current"
1529
+ to a screen reader. It's a named list (`<ol aria-label={label}>`), never
1530
+ a tablist: steps are list items, not tabs or buttons. On a phone it
1531
+ scrolls sideways in its own box with the current step in view, and
1532
+ only while it overflows is the box a tab stop, so the arrow keys
1533
+ scroll it. Pass the stepper's items as they are (an `EqualItem` is a
1534
+ `StepTrackStep`); no steps reads `emptyText`. Never a hand-drawn row of
1535
+ steps on a card.
1536
+
1537
+ ```tsx
1538
+ <StepTrack label={`${program.name}, phases`} caption={`Day ${program.day}`} steps={phases} />
1539
+ ```
1523
1540
  - **Empty**: no items reads `emptyText` ("Nothing yet"), an item with no
1524
1541
  fields `noFieldsText` ("No details"). `label` names the set for a screen
1525
1542
  reader (the list's name, the table's caption); titles are `h3` under a
@@ -1,3 +1,4 @@
1
+ import { messageOf } from '../../lib/refusal.js';
1
2
  type SafeParse = (value: unknown) => {
2
3
  success: true;
3
4
  data: unknown;
@@ -89,8 +90,7 @@ export declare const CONFLICT_REBASE_MESSAGE = "This changed elsewhere (another
89
90
  export declare const OVERLAP_MESSAGE = "Your changes and the ones saved elsewhere are in the same place, so both can't be kept. Keep Mine again replaces theirs; Show Saved drops yours.";
90
91
  /** Whether a save's rejection is the server's "changed since" (a 409, AppError kind `conflict`). */
91
92
  export declare function isConflict(error: unknown): boolean;
92
- /** Why a save failed, in words to show beside what was being saved. */
93
- export declare function messageOf(error: unknown): string;
93
+ export { messageOf };
94
94
  export declare class EditInPlaceStore {
95
95
  private configs;
96
96
  private states;
@@ -221,4 +221,3 @@ export declare class EditInPlaceStore {
221
221
  /** Leaving the page anyway: whatever is open is dropped, and nothing waiting to autosave is sent. */
222
222
  discard(): void;
223
223
  }
224
- export {};
@@ -1,4 +1,54 @@
1
- import { refusalReason } from '../../hooks/use-record-update.js';
1
+ // The rules of editing in place on a record's view, without React (so
2
+ // they're tested on their own, tests/edit-in-place-store.test.ts). One
3
+ // store per EntityView; each editable value is a field in it, and
4
+ // EditableValue is the React side.
5
+ //
6
+ // The rule behind every one: nothing typed is ever lost.
7
+ // - One field open at a time. Opening another saves the open one first;
8
+ // if that save fails, it stays open and the other doesn't open.
9
+ // - Saving: an unchanged draft closes with no request. A draft the form's
10
+ // schema rejects stays open with the schema's message, unsent. Otherwise
11
+ // it's sent; the field stays open (read-only, "Saving…") until the
12
+ // server agrees, then closes. Not optimistic.
13
+ // - A failed save keeps the field open with exactly the draft, and the
14
+ // reason under it. Nothing reverts on its own; saving again retries.
15
+ // - Cancel (Esc) closes and puts the saved value back. Not while saving.
16
+ //
17
+ // A field marked `autosave` (long text, Notion-style) saves on its own:
18
+ // - About a second after typing stops (debounced), and at once on leaving
19
+ // it. It stays open and editable while a save is in flight ("Saving…",
20
+ // then "Saved"); the next save waits behind that one and always sends
21
+ // the latest draft, so quick edits never cross or lose each other.
22
+ // - A failed save keeps the draft and the reason, as above; typing again
23
+ // retries after the pause.
24
+ // - What's been saved stays saved: closing it (leaving, Esc) saves what's
25
+ // left first. Nothing reverts.
26
+ // - A problem the control reports (rich text that can't round-trip) means
27
+ // nothing is saved; it counts as unsaved at once (leaving asks), and its
28
+ // message shows after the pause.
29
+ // - A field leaving the view mid-save (unmounted) still sends what was
30
+ // typed after that save started: the last draft and its config go with
31
+ // the save waiting behind it (`register`'s cleanup).
32
+ // - The saved value changing elsewhere (another tab, a phone, an AI chat)
33
+ // shows at once in a field with nothing of its own unsaved, even with the
34
+ // caret in it (`refresh`). Under unsaved typing it's a conflict: nothing
35
+ // saves until the person picks theirs or the saved one (`keepMine`,
36
+ // `takeSaved`). The server echoing a save back, even normalised
37
+ // (trimmed), is not a change.
38
+ // - The server refusing a save because the record changed since the
39
+ // version it was built on (a 409, AppError kind `conflict`: a writer this
40
+ // tab hadn't heard from yet) is the same conflict: nothing was written,
41
+ // and the record's query refetches (useRecordUpdate) so the latest value
42
+ // arrives. Never a plain failure that saving again would push through.
43
+ // - "Keep mine" keeps both where it can: with a `rebase` (long text's is
44
+ // block by block, rebaseMarkdown), what was typed is laid onto the latest
45
+ // saved value, and the control shows the result as it saves. When both
46
+ // changed the same part, it says so, and only a second "keep mine"
47
+ // replaces the other one.
48
+ // A field marked `alwaysEditable` is also open from the moment it joins:
49
+ // it's the value itself, never "the open field", so it never closes and
50
+ // opening another field leaves it alone.
51
+ import { messageOf } from '../../lib/refusal.js';
2
52
  import { flushPendingEdits } from '../../lib/pending-edits.js';
3
53
  /** How long typing has to stop before an autosaving field saves. */
4
54
  export const AUTOSAVE_DELAY_MS = 1000;
@@ -29,19 +79,13 @@ function normalisedText(value) {
29
79
  // How many of a field's last sent values still count as its own echo.
30
80
  const ECHOES = 4;
31
81
  const sameAsJson = (a, b) => JSON.stringify(a) === JSON.stringify(b);
32
- /** Why a save failed, in words to show beside what was being saved. */
33
- export function messageOf(error) {
34
- if (error && typeof error === 'object' && 'kind' in error)
35
- return refusalReason(error);
36
- if (error instanceof Error)
37
- return error.message;
38
- return 'The save failed. Try again.';
39
- }
40
82
  // The refusal's messages for the value's own fields, or null for none.
41
83
  function fieldErrorsOf(config, cause) {
42
84
  const found = config?.fieldErrors?.(cause);
43
85
  return found && Object.keys(found).length > 0 ? found : undefined;
44
86
  }
87
+ // Re-exported for the components that word a refusal beside the store's.
88
+ export { messageOf };
45
89
  export class EditInPlaceStore {
46
90
  configs = new Map();
47
91
  states = new Map();
@@ -1,5 +1,6 @@
1
1
  import { type FormEvent, type ReactNode } from 'react';
2
2
  import type { AppError } from '../../api/contracts.js';
3
+ import type { FormConflict } from '../../hooks/use-form-version.js';
3
4
  export type EntityFormProps = {
4
5
  /** "New book", "Edit book". */
5
6
  title: string;
@@ -10,6 +11,13 @@ export type EntityFormProps = {
10
11
  submitError?: AppError | null;
11
12
  /** Try again's action. Defaults to submitting the form again. */
12
13
  onRetry?: () => void;
14
+ /**
15
+ * The save was refused because the record changed elsewhere since the
16
+ * form opened (`useFormVersion`'s `conflict`): a warning Notice in the
17
+ * bar, in place of `submitError`'s, with Keep Mine (submits again, over
18
+ * the newer version) and Show Saved. Leave it out and nothing changes.
19
+ */
20
+ conflict?: FormConflict;
13
21
  /** "Add book": the word Add on every create form. */
14
22
  submitLabel: string;
15
23
  onCancel: () => void;
@@ -35,4 +43,4 @@ export type EntityFormProps = {
35
43
  firstInvalid?: (form: HTMLFormElement) => HTMLElement | null;
36
44
  children: ReactNode;
37
45
  };
38
- export declare function EntityForm({ title, onSubmit, isSubmitting, submitError, onRetry, submitLabel, onCancel, danger, dirty, errors, firstInvalid, children, }: EntityFormProps): import("react").JSX.Element;
46
+ export declare function EntityForm({ title, onSubmit, isSubmitting, submitError, onRetry, conflict, submitLabel, onCancel, danger, dirty, errors, firstInvalid, children, }: EntityFormProps): import("react").JSX.Element;
@@ -20,6 +20,9 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
20
20
  // than it; on a phone, two wide buttons. It sets
21
21
  // `--toast-bottom-offset` on <html> to the room it takes, for anything
22
22
  // pinned to the bottom of the window to sit above it.
23
+ // - `conflict` (useFormVersion): a save refused because the record
24
+ // changed elsewhere is a warning Notice in the bar instead, with Keep
25
+ // Mine and Show Saved; what was typed stays until one is picked.
23
26
  // - `dirty`: leaving (a link, Back, the sidebar, Cancel) asks "Discard
24
27
  // your changes?" first, and the browser asks before a reload. Nothing
25
28
  // typed, nothing asked.
@@ -30,6 +33,7 @@ import { FieldGroup } from '../ui/field.js';
30
33
  import { Spinner } from '../ui/spinner.js';
31
34
  import { countFormErrors } from '../../lib/form-errors.js';
32
35
  import { flushPendingEdits } from '../../lib/pending-edits.js';
36
+ import { FormConflictNotice } from './form-conflict-notice.js';
33
37
  import { FormLeaveGuard } from './form-leave-guard.js';
34
38
  import { Notice } from './notice.js';
35
39
  const FOCUSABLE = 'input:not([type=hidden]), select, textarea, button, [contenteditable=true], [tabindex]:not([tabindex="-1"])';
@@ -50,7 +54,7 @@ function moveTo(target, form) {
50
54
  if (!target.contains(document.activeElement))
51
55
  control.focus({ preventScroll: true });
52
56
  }
53
- export function EntityForm({ title, onSubmit, isSubmitting, submitError, onRetry, submitLabel, onCancel, danger, dirty, errors, firstInvalid, children, }) {
57
+ export function EntityForm({ title, onSubmit, isSubmitting, submitError, onRetry, conflict, submitLabel, onCancel, danger, dirty, errors, firstInvalid, children, }) {
54
58
  const form = useRef(null);
55
59
  const bar = useRef(null);
56
60
  // A submit was refused: the bar counts what's left until it's none.
@@ -125,7 +129,10 @@ export function EntityForm({ title, onSubmit, isSubmitting, submitError, onRetry
125
129
  }
126
130
  onCancel();
127
131
  };
128
- return (_jsxs("form", { ref: form, onSubmit: submit, noValidate: true, "data-slot": "entity-form", className: "flex max-w-xl flex-col gap-6", children: [_jsx("h1", { className: "type-page-title text-foreground", children: title }), _jsx(FieldGroup, { children: children }), _jsxs("div", { ref: bar, "data-slot": "entity-form-bar", className: "sticky z-10 -mt-3 flex flex-col gap-3 border-t border-border bg-background pt-3", children: [_jsx("div", { role: "status", className: "empty:hidden", children: submitError && (_jsx(Notice, { tone: "destructive", action: _jsx(Button, { type: "button", size: "sm", variant: "outline", disabled: isSubmitting, onClick: () => (onRetry ? onRetry() : form.current?.requestSubmit()), children: "Try Again" }), children: submitError.message })) }), _jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [danger, _jsx("p", { role: "status", "data-slot": "entity-form-to-fix", className: "mr-auto type-label text-destructive-text empty:hidden", children: toFix > 0 ? `${toFix} to fix` : '' }), _jsxs("div", { className: "ml-auto flex gap-2 max-md:w-full max-md:[&>*]:flex-1", children: [_jsx(Button, { type: "button", variant: "outline", onClick: cancel, disabled: isSubmitting, children: "Cancel" }), _jsxs(Button, { type: "submit", disabled: isSubmitting, children: [isSubmitting && _jsx(Spinner, { className: "size-4" }), submitLabel] })] })] })] }), dirty !== undefined && _jsx(FormLeaveGuard, { dirty: dirty, letThrough: () => leaving.current || submitting.current }), _jsx(DiscardChangesDialog, { open: askingCancel, onKeepEditing: () => setAskingCancel(false), onDiscard: () => {
132
+ return (_jsxs("form", { ref: form, onSubmit: submit, noValidate: true, "data-slot": "entity-form", className: "flex max-w-xl flex-col gap-6", children: [_jsx("h1", { className: "type-page-title text-foreground", children: title }), _jsx(FieldGroup, { children: children }), _jsxs("div", { ref: bar, "data-slot": "entity-form-bar", className: "sticky z-10 -mt-3 flex flex-col gap-3 border-t border-border bg-background pt-3", children: [_jsx("div", { role: "status", className: "empty:hidden", children: conflict ? (_jsx(FormConflictNotice, { conflict: conflict, isSubmitting: isSubmitting, onKeepMine: () => {
133
+ conflict.onKeepMine();
134
+ form.current?.requestSubmit();
135
+ } })) : submitError && (_jsx(Notice, { tone: "destructive", action: _jsx(Button, { type: "button", size: "sm", variant: "outline", disabled: isSubmitting, onClick: () => (onRetry ? onRetry() : form.current?.requestSubmit()), children: "Try Again" }), children: submitError.message })) }), _jsxs("div", { className: "flex flex-wrap items-center gap-2", children: [danger, _jsx("p", { role: "status", "data-slot": "entity-form-to-fix", className: "mr-auto type-label text-destructive-text empty:hidden", children: toFix > 0 ? `${toFix} to fix` : '' }), _jsxs("div", { className: "ml-auto flex gap-2 max-md:w-full max-md:[&>*]:flex-1", children: [_jsx(Button, { type: "button", variant: "outline", onClick: cancel, disabled: isSubmitting, children: "Cancel" }), _jsxs(Button, { type: "submit", disabled: isSubmitting, children: [isSubmitting && _jsx(Spinner, { className: "size-4" }), submitLabel] })] })] })] }), dirty !== undefined && _jsx(FormLeaveGuard, { dirty: dirty, letThrough: () => leaving.current || submitting.current }), _jsx(DiscardChangesDialog, { open: askingCancel, onKeepEditing: () => setAskingCancel(false), onDiscard: () => {
129
136
  setAskingCancel(false);
130
137
  leaving.current = true;
131
138
  onCancel();
@@ -1,4 +1,5 @@
1
1
  import { type ReactNode } from 'react';
2
+ import { type StepTrackState } from './step-track.js';
2
3
  /** Which look a set of equal items takes. */
3
4
  export type EqualItemsLook = 'cards' | 'table' | 'featured' | 'panels' | 'stepper';
4
5
  /**
@@ -6,7 +7,7 @@ export type EqualItemsLook = 'cards' | 'table' | 'featured' | 'panels' | 'steppe
6
7
  * step with a check), `current` (ringed, "Current" under its name, its
7
8
  * panel's border the accent) or `upcoming` (outlined, the default).
8
9
  */
9
- export type EqualItemStep = 'done' | 'current' | 'upcoming';
10
+ export type EqualItemStep = StepTrackState;
10
11
  /**
11
12
  * A state's tone, from design-language.md "Semantic tones": `neutral` (the
12
13
  * default) for most values, a colour only where the state means good,
@@ -21,7 +21,8 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
21
21
  // sequence where one is running and the others are looked at in turn (a
22
22
  // plan's phases). The steps are a tablist: arrow keys, Home and End move
23
23
  // and pick; on a phone the row scrolls sideways in its own box, as the
24
- // record's tab bar does.
24
+ // record's tab bar does. Its marks are StepTrack's (step-track.tsx,
25
+ // 4.128), the same row read only, for a display with no panels.
25
26
  //
26
27
  // The parts are the record's own: a state is a `Badge` in the outline
27
28
  // style (design-language.md "The three badge styles"), a field is the
@@ -36,9 +37,9 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
36
37
  // `actions`, its own buttons (Edit, Remove), at the end of its title line,
37
38
  // or the table's last column. `wide` gives an item the whole row in
38
39
  // `cards` and `panels`, for content that needs it (an editor open).
39
- import { Fragment, useLayoutEffect, useRef, useState } from 'react';
40
+ import { Fragment, useRef, useState } from 'react';
40
41
  import { Tabs as TabsPrimitive } from '@base-ui/react/tabs';
41
- import { CheckIcon, ChevronDownIcon } from 'lucide-react';
42
+ import { ChevronDownIcon } from 'lucide-react';
42
43
  import { cn } from 'cn';
43
44
  import { Badge } from '../ui/badge.js';
44
45
  import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '../ui/collapsible.js';
@@ -46,6 +47,8 @@ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '.
46
47
  import { EMPTY_DASH, isEmptyValue } from '../../lib/empty-value.js';
47
48
  import { EmptyText } from './empty-value.js';
48
49
  import { FIELD_LABEL, FIELD_ROW, FIELD_ROW_BASE, FIELD_VALUE } from './field-rows.js';
50
+ import { STEP_CELL, STEP_ROW, stepLine, useKeepStepInView } from './step-row.js';
51
+ import { StepMark, StepName } from './step-track.js';
49
52
  const TONE_BADGE = {
50
53
  neutral: 'outline',
51
54
  info: 'outline-info',
@@ -144,33 +147,14 @@ function Stepper({ items, label, level, noFieldsText, featuredId, selectedId, on
144
147
  const [own, setOwn] = useState(first);
145
148
  const shownId = has(selectedId) ? selectedId : has(own) ? own : first;
146
149
  const listRef = useRef(null);
147
- // Keep the shown step in the row's view when it scrolls sideways; the
148
- // row only, never the page.
149
- useLayoutEffect(() => {
150
- const list = listRef.current;
151
- const tab = list?.querySelector('[data-slot="equal-item-step"][data-active]');
152
- if (!list || !tab || list.scrollWidth <= list.clientWidth)
153
- return;
154
- const left = tab.offsetLeft - list.offsetLeft;
155
- if (left < list.scrollLeft || left + tab.offsetWidth > list.scrollLeft + list.clientWidth) {
156
- list.scrollLeft = left - (list.clientWidth - tab.offsetWidth) / 2;
157
- }
158
- }, [shownId]);
150
+ useKeepStepInView(listRef, '[data-slot="equal-item-step"][data-active]', shownId);
159
151
  return (_jsxs(TabsPrimitive.Root, { "data-slot": "equal-items-stepper", value: shownId, onValueChange: (next) => {
160
152
  const id = String(next);
161
153
  setOwn(id);
162
154
  onSelectedChange?.(id);
163
- }, className: "flex min-w-0 flex-col gap-3", children: [_jsx(TabsPrimitive.List, { ref: listRef, activateOnFocus: true, "aria-label": label, className: "relative flex max-w-full overflow-x-auto overflow-y-hidden [scrollbar-width:thin]", children: items.map((item, index) => {
155
+ }, className: "flex min-w-0 flex-col gap-3", children: [_jsx(TabsPrimitive.List, { ref: listRef, activateOnFocus: true, "aria-label": label, className: STEP_ROW, children: items.map((item, index) => {
164
156
  const step = item.step ?? 'upcoming';
165
- return (_jsxs(TabsPrimitive.Tab, { value: item.id, "data-slot": "equal-item-step", "data-step": step, "aria-current": step === 'current' ? 'step' : undefined, className: cn('group/step relative flex min-h-11 min-w-18 flex-1 basis-0 flex-col items-center gap-1 rounded-md px-1 pt-1 pb-1.5 text-center text-xs text-muted-foreground outline-none', 'hover:text-foreground focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:ring-inset', 'data-active:font-semibold data-active:text-foreground',
166
- // The line from the step before, under the marks.
167
- 'before:absolute before:top-4 before:right-1/2 before:h-0.5 before:w-full first:before:hidden', step === 'upcoming' ? 'before:bg-border' : 'before:bg-primary'), children: [_jsxs("span", { "aria-hidden": "true", "data-slot": "equal-item-step-mark", className: cn('relative z-10 grid size-6.5 shrink-0 place-items-center rounded-full border-2 text-xs font-bold tabular-nums', step === 'done'
168
- ? 'border-primary bg-primary text-primary-foreground'
169
- : step === 'current'
170
- ? 'border-primary bg-card text-foreground'
171
- : 'border-border bg-card text-muted-foreground',
172
- // The shown step: a ring round its mark.
173
- 'group-data-active/step:ring-2 group-data-active/step:ring-ring group-data-active/step:ring-offset-2 group-data-active/step:ring-offset-card'), children: [step === 'done' ? _jsx(CheckIcon, { className: "size-3.5" }) : index + 1, item.attention && (_jsx("span", { "data-slot": "equal-item-step-attention", className: "absolute -top-0.5 -right-0.5 size-2.5 rounded-full border border-card bg-warning-text" }))] }), _jsxs("span", { className: "line-clamp-3 max-w-full min-w-0 break-words", children: [_jsx("span", { className: "sr-only", children: `Step ${index + 1}: ` }), item.title, step === 'done' && _jsx("span", { className: "sr-only", children: ", done" }), item.attention && _jsx("span", { className: "sr-only", children: `, ${item.attention}` })] }), step === 'current' && _jsx("span", { className: "font-normal text-muted-foreground", children: "Current" })] }, item.id));
157
+ return (_jsxs(TabsPrimitive.Tab, { value: item.id, "data-slot": "equal-item-step", "data-step": step, "aria-current": step === 'current' ? 'step' : undefined, className: cn(STEP_CELL, stepLine(step), 'outline-none hover:text-foreground focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:ring-inset', 'data-active:font-semibold data-active:text-foreground'), children: [_jsx(StepMark, { step: step, number: index + 1, attention: item.attention, ring: "active", slot: "equal-item-step" }), _jsx(StepName, { step: step, number: index + 1, title: item.title, attention: item.attention }), step === 'current' && _jsx("span", { className: "font-normal text-muted-foreground", children: "Current" })] }, item.id));
174
158
  }) }), items.map((item) => (_jsxs(TabsPrimitive.Panel, { value: item.id, "data-slot": "equal-item", "data-step": item.step ?? 'upcoming', className: cn('flex min-w-0 flex-col gap-3 rounded-lg border bg-card p-4 text-card-foreground outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50', item.step === 'current' ? 'border-primary' : 'border-border'), children: [_jsx(Title, { item: item, level: level }), _jsx(Body, { item: item, noFieldsText: noFieldsText, rows: "beside" })] }, item.id)))] }));
175
159
  }
176
160
  /**
@@ -0,0 +1,8 @@
1
+ import type { FormConflict } from '../../hooks/use-form-version.js';
2
+ export declare const FORM_CONFLICT_MESSAGE: string;
3
+ export declare function FormConflictNotice({ conflict, isSubmitting, onKeepMine, }: {
4
+ conflict: FormConflict;
5
+ isSubmitting: boolean;
6
+ /** Keep Mine's click: the conflict's own, then the form submits again. */
7
+ onKeepMine: () => void;
8
+ }): import("react").JSX.Element;
@@ -0,0 +1,15 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ // A form's save refused because the record changed elsewhere (a 409,
3
+ // AppError kind `conflict`; useFormVersion): the Notice EntityForm and
4
+ // FormDialog put in their bar, above the buttons, in place of a failed
5
+ // save's. Warning, not destructive: nothing went wrong, two writers met.
6
+ // It says nothing was saved, that what's typed is still here, and what
7
+ // each button does, so Show Saved never drops the typing unannounced.
8
+ import { Button } from '../ui/button.js';
9
+ import { Notice } from './notice.js';
10
+ export const FORM_CONFLICT_MESSAGE = 'This was saved elsewhere (another tab, device or chat) after you opened it, so nothing was saved. ' +
11
+ 'What you typed is still here: Keep Mine saves this form as it is over that, Show Saved drops your changes and shows what was saved.';
12
+ export function FormConflictNotice({ conflict, isSubmitting, onKeepMine, }) {
13
+ const waiting = conflict.loading === true || isSubmitting;
14
+ return (_jsx(Notice, { tone: "warning", title: "Changed elsewhere", action: _jsxs(_Fragment, { children: [_jsx(Button, { type: "button", size: "sm", variant: "outline", disabled: waiting, onClick: conflict.onShowSaved, children: "Show Saved" }), _jsx(Button, { type: "button", size: "sm", variant: "outline", disabled: waiting, onClick: onKeepMine, children: "Keep Mine" })] }), children: _jsx("span", { "data-slot": "form-conflict", children: FORM_CONFLICT_MESSAGE }) }));
15
+ }
@@ -1,5 +1,6 @@
1
1
  import { type FormEvent, type ReactNode } from 'react';
2
2
  import type { AppError } from '../../api/contracts.js';
3
+ import type { FormConflict } from '../../hooks/use-form-version.js';
3
4
  export type FormDialogProps = {
4
5
  /** "New book": the dialog's name. */
5
6
  title: string;
@@ -20,10 +21,16 @@ export type FormDialogProps = {
20
21
  submitError?: AppError | null;
21
22
  /** Try again's action. Defaults to submitting the form again. */
22
23
  onRetry?: () => void;
24
+ /**
25
+ * An edit refused because the record changed elsewhere
26
+ * (`useFormVersion`'s `conflict`): a warning Notice in place of
27
+ * `submitError`'s, with Keep Mine and Show Saved.
28
+ */
29
+ conflict?: FormConflict;
23
30
  /** Something was typed: closing asks "Discard your changes?" first. */
24
31
  dirty?: boolean;
25
32
  /** The fields. */
26
33
  children: ReactNode;
27
34
  className?: string;
28
35
  };
29
- export declare function FormDialog({ title, description, open, onOpenChange, onSubmit, isSubmitting, submitLabel, submitError, onRetry, dirty, children, className, }: FormDialogProps): import("react").JSX.Element;
36
+ export declare function FormDialog({ title, description, open, onOpenChange, onSubmit, isSubmitting, submitLabel, submitError, onRetry, conflict, dirty, children, className, }: FormDialogProps): import("react").JSX.Element;
@@ -19,6 +19,9 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
19
19
  // the sidebar (FormLeaveGuard, 4.85), as EntityForm's does.
20
20
  // A failed save is a Notice above the buttons with Try again, which
21
21
  // submits again unless `onRetry` says otherwise; what was typed stays.
22
+ // An edit refused because the record changed elsewhere (`conflict`, from
23
+ // useFormVersion) is a warning Notice there instead, with Keep Mine and
24
+ // Show Saved, as EntityForm's.
22
25
  //
23
26
  // The form is the app's: its fields, its schema and its react-hook-form
24
27
  // wiring, as with EntityForm. This draws the chrome around them.
@@ -28,10 +31,11 @@ import { Button } from '../ui/button.js';
28
31
  import { Dialog, DialogClose, DialogContent, DialogDescription, DialogTitle } from '../ui/dialog.js';
29
32
  import { FieldGroup } from '../ui/field.js';
30
33
  import { Spinner } from '../ui/spinner.js';
34
+ import { FormConflictNotice } from './form-conflict-notice.js';
31
35
  import { FormLeaveGuard } from './form-leave-guard.js';
32
36
  import { Notice } from './notice.js';
33
37
  import { useNewRecordDialog } from './record-dialog-context.js';
34
- export function FormDialog({ title, description, open, onOpenChange, onSubmit, isSubmitting, submitLabel, submitError, onRetry, dirty = false, children, className, }) {
38
+ export function FormDialog({ title, description, open, onOpenChange, onSubmit, isSubmitting, submitLabel, submitError, onRetry, conflict, dirty = false, children, className, }) {
35
39
  const route = useNewRecordDialog();
36
40
  const form = useRef(null);
37
41
  const formId = useId();
@@ -50,5 +54,8 @@ export function FormDialog({ title, description, open, onOpenChange, onSubmit, i
50
54
  leaving.current = true;
51
55
  route?.close();
52
56
  }
53
- }, children: [_jsxs(DialogContent, { size: "form", dirty: dirty, "data-slot": "form-dialog", className: cn('gap-0 p-0', className), children: [_jsxs("div", { "data-slot": "form-dialog-header", className: "flex flex-col gap-1 px-4 pt-4 pb-2 pr-12 md:px-6 md:pt-5 md:pr-14", children: [_jsx(DialogTitle, { className: "type-section-title", children: title }), description && _jsx(DialogDescription, { children: description })] }), _jsxs("form", { ref: form, id: formId, onSubmit: onSubmit, noValidate: true, className: "flex min-h-0 flex-1 flex-col", children: [_jsx("div", { "data-slot": "form-dialog-body", className: "min-h-0 flex-1 overflow-y-auto px-4 py-4 md:px-6", children: _jsx(FieldGroup, { children: children }) }), _jsxs("div", { "data-slot": "form-dialog-bar", className: "flex flex-col gap-3 border-t px-4 py-3 pb-[calc(0.75rem+env(safe-area-inset-bottom))] md:px-6 md:pb-3", children: [_jsx("div", { role: "status", className: "empty:hidden", children: submitError && (_jsx(Notice, { tone: "destructive", action: _jsx(Button, { type: "button", size: "sm", variant: "outline", disabled: isSubmitting, onClick: () => (onRetry ? onRetry() : form.current?.requestSubmit()), children: "Try Again" }), children: submitError.message })) }), _jsxs("div", { className: "flex justify-end gap-2 max-md:[&>*]:h-10 max-md:[&>*]:flex-1", children: [_jsx(DialogClose, { render: _jsx(Button, { type: "button", variant: "outline", disabled: isSubmitting }), children: "Cancel" }), _jsxs(Button, { type: "submit", disabled: isSubmitting, children: [isSubmitting && _jsx(Spinner, { className: "size-4" }), submitLabel] })] })] })] })] }), route && open === undefined && (_jsx(FormLeaveGuard, { dirty: dirty, letThrough: () => leaving.current || submitting.current }))] }));
57
+ }, children: [_jsxs(DialogContent, { size: "form", dirty: dirty, "data-slot": "form-dialog", className: cn('gap-0 p-0', className), children: [_jsxs("div", { "data-slot": "form-dialog-header", className: "flex flex-col gap-1 px-4 pt-4 pb-2 pr-12 md:px-6 md:pt-5 md:pr-14", children: [_jsx(DialogTitle, { className: "type-section-title", children: title }), description && _jsx(DialogDescription, { children: description })] }), _jsxs("form", { ref: form, id: formId, onSubmit: onSubmit, noValidate: true, className: "flex min-h-0 flex-1 flex-col", children: [_jsx("div", { "data-slot": "form-dialog-body", className: "min-h-0 flex-1 overflow-y-auto px-4 py-4 md:px-6", children: _jsx(FieldGroup, { children: children }) }), _jsxs("div", { "data-slot": "form-dialog-bar", className: "flex flex-col gap-3 border-t px-4 py-3 pb-[calc(0.75rem+env(safe-area-inset-bottom))] md:px-6 md:pb-3", children: [_jsx("div", { role: "status", className: "empty:hidden", children: conflict ? (_jsx(FormConflictNotice, { conflict: conflict, isSubmitting: isSubmitting, onKeepMine: () => {
58
+ conflict.onKeepMine();
59
+ form.current?.requestSubmit();
60
+ } })) : submitError && (_jsx(Notice, { tone: "destructive", action: _jsx(Button, { type: "button", size: "sm", variant: "outline", disabled: isSubmitting, onClick: () => (onRetry ? onRetry() : form.current?.requestSubmit()), children: "Try Again" }), children: submitError.message })) }), _jsxs("div", { className: "flex justify-end gap-2 max-md:[&>*]:h-10 max-md:[&>*]:flex-1", children: [_jsx(DialogClose, { render: _jsx(Button, { type: "button", variant: "outline", disabled: isSubmitting }), children: "Cancel" }), _jsxs(Button, { type: "submit", disabled: isSubmitting, children: [isSubmitting && _jsx(Spinner, { className: "size-4" }), submitLabel] })] })] })] })] }), route && open === undefined && (_jsx(FormLeaveGuard, { dirty: dirty, letThrough: () => leaving.current || submitting.current }))] }));
54
61
  }