@tristan2828/ui-foundation 4.126.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 (74) hide show
  1. package/conventions/docs/add-an-entity.md +154 -34
  2. package/conventions/docs/cell-patterns.md +88 -41
  3. package/conventions/docs/design-language.md +62 -13
  4. package/dist/api/contracts.d.ts +8 -1
  5. package/dist/api/gateway/errors.js +4 -0
  6. package/dist/api/schema.d.ts +9 -0
  7. package/dist/components/app/data-table-tools.d.ts +12 -0
  8. package/dist/components/app/data-table-tools.js +2 -2
  9. package/dist/components/app/data-table.d.ts +2 -1
  10. package/dist/components/app/data-table.js +1 -1
  11. package/dist/components/app/edit-in-place-presets.d.ts +51 -1
  12. package/dist/components/app/edit-in-place-presets.js +30 -0
  13. package/dist/components/app/edit-in-place-store.d.ts +33 -7
  14. package/dist/components/app/edit-in-place-store.js +112 -20
  15. package/dist/components/app/edit-in-place.d.ts +11 -0
  16. package/dist/components/app/editable-value.js +43 -8
  17. package/dist/components/app/entity-form.d.ts +9 -1
  18. package/dist/components/app/entity-form.js +9 -2
  19. package/dist/components/app/entity-view.js +5 -1
  20. package/dist/components/app/equal-items.d.ts +33 -6
  21. package/dist/components/app/equal-items.js +42 -7
  22. package/dist/components/app/error-state.js +1 -0
  23. package/dist/components/app/form-conflict-notice.d.ts +8 -0
  24. package/dist/components/app/form-conflict-notice.js +15 -0
  25. package/dist/components/app/form-dialog.d.ts +8 -1
  26. package/dist/components/app/form-dialog.js +9 -2
  27. package/dist/components/app/milkdown-editor.js +24 -331
  28. package/dist/components/app/notify.d.ts +18 -1
  29. package/dist/components/app/notify.js +26 -3
  30. package/dist/components/app/page-restore.js +1 -1
  31. package/dist/components/app/pill-filter.d.ts +16 -0
  32. package/dist/components/app/pill-filter.js +22 -1
  33. package/dist/components/app/rating-input.d.ts +22 -0
  34. package/dist/components/app/rating-input.js +65 -0
  35. package/dist/components/app/rating-score.d.ts +2 -1
  36. package/dist/components/app/rating-score.js +2 -6
  37. package/dist/components/app/rich-text-box-anchor.d.ts +6 -0
  38. package/dist/components/app/rich-text-box-anchor.js +8 -0
  39. package/dist/components/app/rich-text-editor.d.ts +4 -2
  40. package/dist/components/app/rich-text-editor.js +3 -2
  41. package/dist/components/app/rich-text-heading-view.d.ts +4 -0
  42. package/dist/components/app/rich-text-heading-view.js +91 -0
  43. package/dist/components/app/rich-text-keyboard-bar.js +3 -2
  44. package/dist/components/app/rich-text-link-box.d.ts +9 -0
  45. package/dist/components/app/rich-text-link-box.js +40 -0
  46. package/dist/components/app/rich-text-links.d.ts +14 -0
  47. package/dist/components/app/rich-text-links.js +92 -0
  48. package/dist/components/app/rich-text-page-box.d.ts +10 -0
  49. package/dist/components/app/rich-text-page-box.js +45 -0
  50. package/dist/components/app/rich-text-task-item-view.d.ts +4 -0
  51. package/dist/components/app/rich-text-task-item-view.js +59 -0
  52. package/dist/components/app/rich-text-toggle-heading.js +1 -1
  53. package/dist/components/app/rich-text-toolbar.js +1 -1
  54. package/dist/components/app/rich-text-tools-bar.d.ts +3 -1
  55. package/dist/components/app/rich-text-tools-bar.js +2 -2
  56. package/dist/components/app/step-row.d.ts +15 -0
  57. package/dist/components/app/step-row.js +27 -0
  58. package/dist/components/app/step-track.d.ts +82 -0
  59. package/dist/components/app/step-track.js +98 -0
  60. package/dist/components/ui/sonner.js +1 -1
  61. package/dist/hooks/use-form-version.d.ts +101 -0
  62. package/dist/hooks/use-form-version.js +187 -0
  63. package/dist/hooks/use-record-update.d.ts +15 -8
  64. package/dist/hooks/use-record-update.js +19 -14
  65. package/dist/index.d.ts +7 -3
  66. package/dist/index.js +7 -0
  67. package/dist/lib/markdown-merge.d.ts +12 -0
  68. package/dist/lib/markdown-merge.js +90 -0
  69. package/dist/lib/rating-glyphs.d.ts +3 -0
  70. package/dist/lib/rating-glyphs.js +7 -0
  71. package/dist/lib/refusal.d.ts +9 -0
  72. package/dist/lib/refusal.js +19 -0
  73. package/openapi/foundation.yaml +12 -0
  74. package/package.json +1 -1
@@ -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();
@@ -151,7 +151,11 @@ function FieldRow({ field, place }) {
151
151
  // row hover, its pencil at the end, a chevron on a phone.
152
152
  const editable = Boolean(field.edit);
153
153
  const shown = field.edit ? (_jsx(EditableValue, { label: field.label, edit: field.edit, look: "row", children: _jsx(OrEmpty, { value: value, emptyLabel: field.emptyLabel }) })) : (_jsx(OrEmpty, { value: value, emptyLabel: field.emptyLabel }));
154
- return (_jsxs("div", { className: cn(FIELD_ROW_BASE, FIELD_ROW[place], editable && cn(editRowClass, '-mx-2 px-2 first:pt-2 last:pb-2')), onClick: editable ? onEditRowClick : undefined, children: [_jsx("dt", { className: FIELD_LABEL, children: field.label }), _jsxs("dd", { className: cn(FIELD_VALUE, field.action && 'flex flex-col items-start gap-1.5'), "data-record-status": field.recordStatus ? '' : undefined, children: [field.hint ? (_jsxs("span", { className: "inline-flex max-w-full flex-wrap items-center gap-x-1", children: [_jsx("span", { className: "min-w-0 max-w-full", children: shown }), _jsx(FactHint, { label: field.label, hint: field.hint })] })) : (shown), field.action && _jsx(FactAction, { action: field.action })] })] }));
154
+ return (_jsxs("div", { className: cn(FIELD_ROW_BASE, FIELD_ROW[place], editable && cn(editRowClass, '-mx-2 px-2 first:pt-2 last:pb-2'),
155
+ // Stars to tap (RatingInput, 4.127) are five 44px targets on a
156
+ // touch screen: wider than a narrow row's value column, so the
157
+ // label goes above them there.
158
+ 'pointer-coarse:has-[[data-slot=rating-input]]:flex!'), onClick: editable ? onEditRowClick : undefined, children: [_jsx("dt", { className: FIELD_LABEL, children: field.label }), _jsxs("dd", { className: cn(FIELD_VALUE, field.action && 'flex flex-col items-start gap-1.5'), "data-record-status": field.recordStatus ? '' : undefined, children: [field.hint ? (_jsxs("span", { className: "inline-flex max-w-full flex-wrap items-center gap-x-1", children: [_jsx("span", { className: "min-w-0 max-w-full", children: shown }), _jsx(FactHint, { label: field.label, hint: field.hint })] })) : (shown), field.action && _jsx(FactAction, { action: field.action })] })] }));
155
159
  }
156
160
  // A fields card's rows. Folded (`emptyFields="fold"`), the filled fields
157
161
  // show and the empty ones wait behind "N empty", which opens them in their
@@ -1,6 +1,13 @@
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
- export type EqualItemsLook = 'cards' | 'table' | 'featured' | 'panels';
4
+ export type EqualItemsLook = 'cards' | 'table' | 'featured' | 'panels' | 'stepper';
5
+ /**
6
+ * Where an item is in a sequence, for `look="stepper"`: `done` (a filled
7
+ * step with a check), `current` (ringed, "Current" under its name, its
8
+ * panel's border the accent) or `upcoming` (outlined, the default).
9
+ */
10
+ export type EqualItemStep = StepTrackState;
4
11
  /**
5
12
  * A state's tone, from design-language.md "Semantic tones": `neutral` (the
6
13
  * default) for most values, a colour only where the state means good,
@@ -44,6 +51,15 @@ export type EqualItem = {
44
51
  actions?: ReactNode;
45
52
  /** The whole row in the `cards` and `panels` looks (an editor open in it). */
46
53
  wide?: boolean;
54
+ /** For `look="stepper"`: done, current or upcoming (the default). */
55
+ step?: EqualItemStep;
56
+ /**
57
+ * For `look="stepper"`: a step that needs a look while another is shown
58
+ * (an unsaved change that needs an answer in it): a small warning dot on
59
+ * its step, and these words at the end of the step's name ("needs an
60
+ * answer").
61
+ */
62
+ attention?: string;
47
63
  };
48
64
  export type EqualItemsProps = {
49
65
  items: readonly EqualItem[];
@@ -51,9 +67,19 @@ export type EqualItemsProps = {
51
67
  look?: EqualItemsLook;
52
68
  /**
53
69
  * For `look="featured"`: the item shown in full. Defaults to the first
54
- * one; an id that matches none falls back to the first too.
70
+ * one; an id that matches none falls back to the first too. For
71
+ * `look="stepper"`: the step shown first, defaulting to the `current`
72
+ * one, else the first.
55
73
  */
56
74
  featuredId?: string;
75
+ /**
76
+ * For `look="stepper"`: the step shown, when the app keeps it (in the
77
+ * URL, say). An id that matches none falls back as `featuredId` does.
78
+ * Without it, the stepper keeps its own.
79
+ */
80
+ selectedId?: string;
81
+ /** For `look="stepper"`: called with the step picked. */
82
+ onSelectedChange?: (id: string) => void;
57
83
  /**
58
84
  * For `look="featured"`: the other items open when it first shows.
59
85
  * Each toggle opens and closes on its own after that.
@@ -77,7 +103,7 @@ export type EqualItemsProps = {
77
103
  };
78
104
  /**
79
105
  * A few equal, related things inside a record view (record page standard
80
- * R10): one data shape, four looks.
106
+ * R10): one data shape, five looks.
81
107
  *
82
108
  * ```tsx
83
109
  * <EqualItems
@@ -94,9 +120,10 @@ export type EqualItemsProps = {
94
120
  *
95
121
  * `cards` for a few things with little to say about each, `table` for
96
122
  * things compared on the same values, `featured` when one is current or
97
- * best, `panels` when each has several details and must read as separate
98
- * (design-language.md "A few equal things"). An item's own `content` (an
123
+ * best, `panels` when each has several details and must read as separate,
124
+ * `stepper` for a sequence with a current step, its steps picking the one
125
+ * panel shown (design-language.md "A few equal things"). An item's own `content` (an
99
126
  * editor) goes under its fields at full width, its `actions` (Edit, Remove)
100
127
  * at its title line's end; `wide` gives it the whole row of cards or panels.
101
128
  */
102
- export declare function EqualItems({ items, look, featuredId, defaultOpenIds, label, headingLevel, titleColumn, stateColumn, actionsColumn, emptyText, noFieldsText, className, }: EqualItemsProps): import("react").JSX.Element;
129
+ export declare function EqualItems({ items, look, featuredId, defaultOpenIds, selectedId, onSelectedChange, label, headingLevel, titleColumn, stateColumn, actionsColumn, emptyText, noFieldsText, className, }: EqualItemsProps): import("react").JSX.Element;
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  // A few equal things in a record (record page standard R10): the phases of
3
3
  // a plan, the stores a price is compared at, a handful of options. One data
4
- // shape, four looks, each the record picks for what it shows:
4
+ // shape, five looks, each the record picks for what it shows:
5
5
  //
6
6
  // - `cards`: a row of equal cards that wraps (one column on a phone), each
7
7
  // its title, its state as a badge and its fields as short label/value
@@ -15,6 +15,14 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
15
15
  // - `panels`: a panel per item side by side, every detail labelled above
16
16
  // its value, stacking on a phone. For things with several details each
17
17
  // that need to read as separate.
18
+ // - `stepper` (4.127): the items in order as a row of numbered steps, each
19
+ // done, current or upcoming (an item's `step`), picking the one item
20
+ // whose panel shows under it; it opens on the current step. For a
21
+ // sequence where one is running and the others are looked at in turn (a
22
+ // plan's phases). The steps are a tablist: arrow keys, Home and End move
23
+ // and pick; on a phone the row scrolls sideways in its own box, as the
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.
18
26
  //
19
27
  // The parts are the record's own: a state is a `Badge` in the outline
20
28
  // style (design-language.md "The three badge styles"), a field is the
@@ -29,7 +37,8 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
29
37
  // `actions`, its own buttons (Edit, Remove), at the end of its title line,
30
38
  // or the table's last column. `wide` gives an item the whole row in
31
39
  // `cards` and `panels`, for content that needs it (an editor open).
32
- import { Fragment, useState } from 'react';
40
+ import { Fragment, useRef, useState } from 'react';
41
+ import { Tabs as TabsPrimitive } from '@base-ui/react/tabs';
33
42
  import { ChevronDownIcon } from 'lucide-react';
34
43
  import { cn } from 'cn';
35
44
  import { Badge } from '../ui/badge.js';
@@ -38,6 +47,8 @@ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '.
38
47
  import { EMPTY_DASH, isEmptyValue } from '../../lib/empty-value.js';
39
48
  import { EmptyText } from './empty-value.js';
40
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';
41
52
  const TONE_BADGE = {
42
53
  neutral: 'outline',
43
54
  info: 'outline-info',
@@ -123,9 +134,32 @@ function FeaturedToggle({ item, level, noFieldsText, defaultOpen, }) {
123
134
  const Heading = `h${level}`;
124
135
  return (_jsx("li", { "data-slot": "equal-item", children: _jsxs(Collapsible, { open: open, onOpenChange: setOpen, children: [_jsxs("div", { className: "flex min-w-0 items-center", children: [_jsx(Heading, { className: "m-0 min-w-0 flex-1", children: _jsxs(CollapsibleTrigger, { "data-slot": "equal-item-toggle", className: "flex min-h-11 w-full items-center gap-2 px-4 py-2 text-left outline-none hover:bg-muted/50 focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:ring-inset", children: [_jsx(ChevronDownIcon, { "aria-hidden": "true", className: cn('size-4 shrink-0 text-muted-foreground transition-transform', !open && '-rotate-90') }), _jsxs("span", { className: "flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1", children: [_jsx("span", { className: "min-w-0 type-body font-semibold break-words text-foreground", children: item.title }), _jsx(StateBadge, { state: item.state })] })] }) }), _jsx(Actions, { actions: item.actions, className: "pr-4" })] }), _jsx(CollapsibleContent, { className: "flex flex-col gap-3 px-4 pt-1 pb-4 pl-10", children: _jsx(Body, { item: item, noFieldsText: noFieldsText, rows: "beside" }) })] }) }));
125
136
  }
137
+ // The items as numbered steps joined by a line, a tablist picking the one
138
+ // panel shown under it (Base UI's tabs: arrow keys, Home and End move and
139
+ // pick, Tab goes on into the panel). A step's name is what it shows plus
140
+ // hidden words ("Step 2: Phase 2: Build, done"), never an aria-label, so
141
+ // the visible text stays in the name. Wider than its column (a phone, many
142
+ // steps), the row scrolls sideways in its own box, never the page, and
143
+ // keeps the shown step in view.
144
+ function Stepper({ items, label, level, noFieldsText, featuredId, selectedId, onSelectedChange, }) {
145
+ const has = (id) => id !== undefined && items.some((item) => item.id === id);
146
+ const first = has(featuredId) ? featuredId : (items.find((item) => item.step === 'current') ?? items[0]).id;
147
+ const [own, setOwn] = useState(first);
148
+ const shownId = has(selectedId) ? selectedId : has(own) ? own : first;
149
+ const listRef = useRef(null);
150
+ useKeepStepInView(listRef, '[data-slot="equal-item-step"][data-active]', shownId);
151
+ return (_jsxs(TabsPrimitive.Root, { "data-slot": "equal-items-stepper", value: shownId, onValueChange: (next) => {
152
+ const id = String(next);
153
+ setOwn(id);
154
+ onSelectedChange?.(id);
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) => {
156
+ const step = item.step ?? 'upcoming';
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));
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)))] }));
159
+ }
126
160
  /**
127
161
  * A few equal, related things inside a record view (record page standard
128
- * R10): one data shape, four looks.
162
+ * R10): one data shape, five looks.
129
163
  *
130
164
  * ```tsx
131
165
  * <EqualItems
@@ -142,15 +176,16 @@ function FeaturedToggle({ item, level, noFieldsText, defaultOpen, }) {
142
176
  *
143
177
  * `cards` for a few things with little to say about each, `table` for
144
178
  * things compared on the same values, `featured` when one is current or
145
- * best, `panels` when each has several details and must read as separate
146
- * (design-language.md "A few equal things"). An item's own `content` (an
179
+ * best, `panels` when each has several details and must read as separate,
180
+ * `stepper` for a sequence with a current step, its steps picking the one
181
+ * panel shown (design-language.md "A few equal things"). An item's own `content` (an
147
182
  * editor) goes under its fields at full width, its `actions` (Edit, Remove)
148
183
  * at its title line's end; `wide` gives it the whole row of cards or panels.
149
184
  */
150
- export function EqualItems({ items, look = 'cards', featuredId, defaultOpenIds, label, headingLevel = 3, titleColumn = 'Name', stateColumn = 'Status', actionsColumn = 'Actions', emptyText = 'Nothing yet', noFieldsText = 'No details', className, }) {
185
+ export function EqualItems({ items, look = 'cards', featuredId, defaultOpenIds, selectedId, onSelectedChange, label, headingLevel = 3, titleColumn = 'Name', stateColumn = 'Status', actionsColumn = 'Actions', emptyText = 'Nothing yet', noFieldsText = 'No details', className, }) {
151
186
  if (items.length === 0) {
152
187
  return (_jsx("p", { "data-slot": "equal-items", "data-look": look, "data-state": "empty", className: cn('type-body text-muted-foreground', className), children: emptyText }));
153
188
  }
154
189
  const shared = { items, label, level: headingLevel, noFieldsText };
155
- return (_jsx("div", { "data-slot": "equal-items", "data-look": look, className: cn('min-w-0', className), children: look === 'table' ? (_jsx(ItemsTable, { items: items, label: label, titleColumn: titleColumn, stateColumn: stateColumn, actionsColumn: actionsColumn })) : look === 'featured' ? (_jsx(Featured, { ...shared, featuredId: featuredId, defaultOpenIds: defaultOpenIds })) : look === 'panels' ? (_jsx(Panels, { ...shared })) : (_jsx(Cards, { ...shared })) }));
190
+ return (_jsx("div", { "data-slot": "equal-items", "data-look": look, className: cn('min-w-0', className), children: look === 'table' ? (_jsx(ItemsTable, { items: items, label: label, titleColumn: titleColumn, stateColumn: stateColumn, actionsColumn: actionsColumn })) : look === 'featured' ? (_jsx(Featured, { ...shared, featuredId: featuredId, defaultOpenIds: defaultOpenIds })) : look === 'stepper' ? (_jsx(Stepper, { ...shared, featuredId: featuredId, selectedId: selectedId, onSelectedChange: onSelectedChange })) : look === 'panels' ? (_jsx(Panels, { ...shared })) : (_jsx(Cards, { ...shared })) }));
156
191
  }
@@ -24,6 +24,7 @@ const TITLE_BY_KIND = {
24
24
  notfound: 'Not found',
25
25
  auth: 'Not authorized',
26
26
  rate_limited: 'Too many attempts',
27
+ conflict: 'Changed elsewhere',
27
28
  validation: 'Check the form',
28
29
  proxy_auth: 'Sign-in expired',
29
30
  };
@@ -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
  }