@tristan2828/ui-foundation 4.125.0 → 4.127.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 (94) hide show
  1. package/README.md +1 -1
  2. package/conventions/docs/add-an-entity.md +140 -35
  3. package/conventions/docs/cell-patterns.md +144 -56
  4. package/conventions/docs/design-language.md +45 -13
  5. package/dist/api/contracts.d.ts +8 -1
  6. package/dist/api/gateway/errors.js +4 -0
  7. package/dist/api/schema.d.ts +9 -0
  8. package/dist/api/transport/index.js +10 -1
  9. package/dist/components/app/data-table-tools.d.ts +12 -0
  10. package/dist/components/app/data-table-tools.js +2 -2
  11. package/dist/components/app/data-table.d.ts +2 -1
  12. package/dist/components/app/data-table.js +1 -1
  13. package/dist/components/app/edit-caret.d.ts +25 -0
  14. package/dist/components/app/edit-caret.js +118 -0
  15. package/dist/components/app/edit-in-place-presets.d.ts +51 -1
  16. package/dist/components/app/edit-in-place-presets.js +30 -0
  17. package/dist/components/app/edit-in-place-store.d.ts +70 -4
  18. package/dist/components/app/edit-in-place-store.js +219 -21
  19. package/dist/components/app/edit-in-place.d.ts +11 -0
  20. package/dist/components/app/editable-value.js +202 -25
  21. package/dist/components/app/entity-form.js +4 -0
  22. package/dist/components/app/entity-view.js +5 -1
  23. package/dist/components/app/equal-items.d.ts +32 -6
  24. package/dist/components/app/equal-items.js +59 -8
  25. package/dist/components/app/error-state.js +1 -0
  26. package/dist/components/app/form-leave-guard.js +7 -1
  27. package/dist/components/app/milkdown-editor.d.ts +1 -0
  28. package/dist/components/app/milkdown-editor.js +226 -64
  29. package/dist/components/app/pill-filter.d.ts +16 -0
  30. package/dist/components/app/pill-filter.js +22 -1
  31. package/dist/components/app/prose-look.d.ts +1 -1
  32. package/dist/components/app/prose-look.js +3 -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-autolink.d.ts +6 -0
  38. package/dist/components/app/rich-text-autolink.js +79 -0
  39. package/dist/components/app/rich-text-edges.d.ts +8 -0
  40. package/dist/components/app/rich-text-edges.js +144 -0
  41. package/dist/components/app/rich-text-editor.d.ts +19 -4
  42. package/dist/components/app/rich-text-editor.js +19 -6
  43. package/dist/components/app/rich-text-empty-paragraph.d.ts +14 -6
  44. package/dist/components/app/rich-text-empty-paragraph.js +19 -8
  45. package/dist/components/app/rich-text-formats.js +88 -15
  46. package/dist/components/app/rich-text-full-screen.d.ts +2 -0
  47. package/dist/components/app/rich-text-full-screen.js +78 -0
  48. package/dist/components/app/rich-text-highlight-menu.d.ts +3 -1
  49. package/dist/components/app/rich-text-highlight-menu.js +3 -2
  50. package/dist/components/app/rich-text-input-rules.d.ts +7 -0
  51. package/dist/components/app/rich-text-input-rules.js +83 -0
  52. package/dist/components/app/rich-text-keyboard-bar.d.ts +24 -0
  53. package/dist/components/app/rich-text-keyboard-bar.js +215 -0
  54. package/dist/components/app/rich-text-node-views.js +2 -1
  55. package/dist/components/app/rich-text-paste.d.ts +43 -0
  56. package/dist/components/app/rich-text-paste.js +355 -0
  57. package/dist/components/app/rich-text-shortcuts.d.ts +5 -1
  58. package/dist/components/app/rich-text-shortcuts.js +132 -2
  59. package/dist/components/app/rich-text-slash-menu.js +47 -9
  60. package/dist/components/app/rich-text-slash.d.ts +7 -0
  61. package/dist/components/app/rich-text-slash.js +27 -14
  62. package/dist/components/app/rich-text-table-grips.d.ts +8 -6
  63. package/dist/components/app/rich-text-table-grips.js +11 -12
  64. package/dist/components/app/rich-text-tasks.d.ts +8 -0
  65. package/dist/components/app/rich-text-tasks.js +20 -0
  66. package/dist/components/app/rich-text-toolbar.d.ts +5 -1
  67. package/dist/components/app/rich-text-toolbar.js +14 -6
  68. package/dist/components/app/rich-text-tools-bar.d.ts +3 -1
  69. package/dist/components/app/rich-text-tools-bar.js +2 -2
  70. package/dist/components/app/rich-text-touch.d.ts +2 -0
  71. package/dist/components/app/rich-text-touch.js +18 -0
  72. package/dist/components/app/rich-text-widgets.js +1 -1
  73. package/dist/hooks/table-url-changes.d.ts +4 -0
  74. package/dist/hooks/table-url-changes.js +13 -0
  75. package/dist/hooks/use-record-update.d.ts +13 -1
  76. package/dist/hooks/use-record-update.js +17 -3
  77. package/dist/hooks/use-table-url-state.js +14 -8
  78. package/dist/index.d.ts +5 -2
  79. package/dist/index.js +8 -0
  80. package/dist/lib/markdown-merge.d.ts +38 -0
  81. package/dist/lib/markdown-merge.js +202 -17
  82. package/dist/lib/page-leaving.d.ts +8 -0
  83. package/dist/lib/page-leaving.js +30 -0
  84. package/dist/lib/pending-edits.d.ts +14 -0
  85. package/dist/lib/pending-edits.js +51 -0
  86. package/dist/lib/rating-glyphs.d.ts +3 -0
  87. package/dist/lib/rating-glyphs.js +7 -0
  88. package/dist/mocks/e2e-hooks.js +10 -0
  89. package/dist/mocks/override.d.ts +8 -0
  90. package/dist/testing/index.d.ts +40 -2
  91. package/dist/testing/index.js +101 -7
  92. package/openapi/foundation.yaml +12 -0
  93. package/package.json +1 -1
  94. package/styles/index.css +7 -0
@@ -13,11 +13,24 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
13
13
  // the server agrees. Failed: it stays, with the draft and the reason.
14
14
  // - `autosave`: it saves itself a pause after typing stops and stays
15
15
  // editable while it does ("Saving…", then "Saved" under it). Leaving,
16
- // Ctrl/Cmd+Enter and Esc save what's left now and close it.
16
+ // Ctrl/Cmd+Enter and Esc save what's left now and close it. On a note
17
+ // longer than the screen the line under it is pinned to the screen's
18
+ // bottom edge, so a refusal or a failed save is never off screen, and
19
+ // the first one also toasts (F5).
20
+ // - `long-text` without `autosave`: Esc on a changed draft asks
21
+ // ("Discard your changes?") rather than dropping it (F7).
22
+ // - Opening by a click puts the caret where the click was, not at the
23
+ // top, and the page doesn't move (F8).
24
+ // - The saved value changing elsewhere shows at once when nothing here is
25
+ // unsaved, the caret keeping its block; under unsaved typing the line
26
+ // says so, with "Keep Mine" and "Show Saved" (F4).
17
27
  // - `alwaysEditable`: the control is shown at rest, with no pencil and no
18
28
  // click to open, and never closes. Ctrl/Cmd+Enter and Esc save now.
19
29
  // - `inline`: always editable, and the control is told to look like the
20
30
  // value it edits (`inline` among its props).
31
+ // - Always editable and a `choice` (4.127, `inPlace.rating`'s stars): a
32
+ // value on one line, so "Saving…" and "Saved" sit beside it, not on a
33
+ // line under it, and "Saved" goes after two seconds, as at rest.
21
34
  // - Saved (4.88, F16): once a save lands, "✓ Saved" shows beside the value
22
35
  // for two seconds (`role="status"`).
23
36
  // - `layout="inline"` (4.102): the pencil takes no room until hover or
@@ -31,11 +44,16 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
31
44
  import { CheckIcon, ChevronRightIcon, PencilIcon } from 'lucide-react';
32
45
  import { useCallback, useContext, useEffect, useId, useLayoutEffect, useRef, useState, useSyncExternalStore } from 'react';
33
46
  import { useBlocker } from 'react-router';
47
+ import { toast } from 'sonner';
34
48
  import { cn } from 'cn';
35
49
  import { Button } from '../ui/button.js';
36
50
  import { DiscardChangesDialog } from '../ui/dialog.js';
37
51
  import { FieldError } from '../ui/field.js';
38
52
  import { Spinner } from '../ui/spinner.js';
53
+ import { clearPageLeaving, markPageLeaving } from '../../lib/page-leaving.js';
54
+ import { flushPendingEdits, hasPendingEdits, subscribePendingEdits } from '../../lib/pending-edits.js';
55
+ import { caretSpot, placeCaretWhenReady, spotAtPoint } from './edit-caret.js';
56
+ import { rebaseMarkdown } from '../../lib/markdown-merge.js';
39
57
  import { EditInPlaceContext } from './edit-in-place.js';
40
58
  import { SAVED_FOR_MS } from './edit-row.js';
41
59
  import { escapePassedThrough } from './escape-passthrough.js';
@@ -68,12 +86,59 @@ function InlinePencilRoom({ inline, children }) {
68
86
  function Control({ render, ...props }) {
69
87
  return render(props);
70
88
  }
89
+ // While a field runs past the bottom of the screen, its status line (the
90
+ // save's state, a refusal) is pinned to the screen's bottom edge, under the
91
+ // field's left edge, so it's never off screen (F5). Not CSS sticky: a
92
+ // section's card clips its content (`overflow-hidden`), which stops sticky
93
+ // at the card. Returns where to pin it, or null while it shows in place.
94
+ function usePinnedStatus(field, enabled) {
95
+ const [pin, setPin] = useState(null);
96
+ useLayoutEffect(() => {
97
+ if (!enabled)
98
+ return;
99
+ let frame = 0;
100
+ const measure = () => {
101
+ frame = 0;
102
+ const box = field.current?.getBoundingClientRect();
103
+ const runsPast = box !== undefined && box.top < window.innerHeight - 48 && box.bottom > window.innerHeight;
104
+ setPin((current) => {
105
+ if (!runsPast)
106
+ return null;
107
+ const next = { left: Math.round(box.left), width: Math.round(box.width) };
108
+ return current && current.left === next.left && current.width === next.width ? current : next;
109
+ });
110
+ };
111
+ const schedule = () => {
112
+ if (!frame)
113
+ frame = requestAnimationFrame(measure);
114
+ };
115
+ measure();
116
+ window.addEventListener('scroll', schedule, { capture: true, passive: true });
117
+ window.addEventListener('resize', schedule);
118
+ const observer = typeof ResizeObserver === 'undefined' ? null : new ResizeObserver(schedule);
119
+ if (field.current)
120
+ observer?.observe(field.current);
121
+ return () => {
122
+ cancelAnimationFrame(frame);
123
+ window.removeEventListener('scroll', schedule, { capture: true });
124
+ window.removeEventListener('resize', schedule);
125
+ observer?.disconnect();
126
+ };
127
+ }, [field, enabled]);
128
+ return enabled ? pin : null;
129
+ }
71
130
  function useStore() {
72
131
  const store = useContext(EditInPlaceContext);
73
132
  if (!store)
74
133
  throw new Error('<EditableValue> works inside an <EntityView>, which runs editing in place.');
75
134
  return store;
76
135
  }
136
+ // Long text's "Keep Mine": both sides kept block by block (rebaseMarkdown).
137
+ function rebaseText(base, mine, theirs) {
138
+ if (typeof base !== 'string' || typeof mine !== 'string' || typeof theirs !== 'string')
139
+ return null;
140
+ return rebaseMarkdown(base, mine, theirs);
141
+ }
77
142
  export function EditableValue(props) {
78
143
  return _jsx(EditableField, { ...props });
79
144
  }
@@ -87,10 +152,12 @@ export function EditableField({ label, edit, children, layout = 'block', look =
87
152
  const always = Boolean(edit.alwaysEditable || edit.inline);
88
153
  const autosave = always || Boolean(edit.autosave);
89
154
  // The latest config, read by the store whenever it needs it (`inline`
90
- // is always editable to it).
91
- const config = useRef(edit);
155
+ // is always editable to it; long text keeps both sides of a conflict
156
+ // block by block unless it says otherwise).
157
+ const config = useRef({ ...edit, rebase: undefined });
92
158
  useLayoutEffect(() => {
93
- config.current = always && !edit.alwaysEditable ? { ...edit, alwaysEditable: true } : edit;
159
+ const rebase = edit.rebase === false ? undefined : (edit.rebase ?? (edit.kind === 'long-text' ? rebaseText : undefined));
160
+ config.current = { ...edit, alwaysEditable: always || edit.alwaysEditable, rebase };
94
161
  });
95
162
  useEffect(() => store.register(key, () => config.current), [store, key]);
96
163
  const state = useSyncExternalStore(store.subscribe, () => store.state(key), () => store.state(key));
@@ -117,29 +184,61 @@ export function EditableField({ label, edit, children, layout = 'block', look =
117
184
  // Set by a keyboard save or Esc: the caret goes back to the edit button.
118
185
  const refocus = useRef(false);
119
186
  const blurTimer = useRef(undefined);
120
- // An always-editable control starts over (it's uncontrolled: a rich-text
121
- // editor reads its value once) when the value changed elsewhere while
122
- // nothing of its own was unsaved and the caret wasn't in it.
187
+ // Where the caret goes once the control shows or starts over: the spot
188
+ // clicked in the read view (F8), or the caret's own block (F4).
189
+ const caretTarget = useRef(null);
190
+ const stopPlacing = useRef(() => { });
191
+ useEffect(() => () => stopPlacing.current(), []);
192
+ const placeCaretSoon = useCallback((spot) => {
193
+ stopPlacing.current();
194
+ stopPlacing.current = placeCaretWhenReady(() => container.current, spot);
195
+ }, []);
196
+ // The value changed elsewhere (another tab, a phone, an AI chat): the
197
+ // control starts over (it's uncontrolled: a rich-text editor reads its
198
+ // value once) when nothing of its own is unsaved, the caret keeping its
199
+ // block if it was in it; under unsaved typing the store marks a conflict.
123
200
  const refresh = useCallback(() => {
124
- if (!container.current?.contains(document.activeElement))
125
- store.refresh(key);
126
- }, [store, key]);
201
+ const focused = Boolean(container.current?.contains(document.activeElement));
202
+ const spot = focused && container.current ? caretSpot(container.current) : null;
203
+ if (store.refresh(key) && spot)
204
+ placeCaretSoon(spot);
205
+ }, [store, key, placeCaretSoon]);
127
206
  useEffect(() => {
128
- if (always)
129
- refresh();
130
- }, [always, refresh, edit.value]);
207
+ refresh();
208
+ }, [refresh, edit.value]);
209
+ // Always editable and one pick (stars): its line is beside it (4.127).
210
+ const beside = always && edit.kind === 'choice';
211
+ const autosaved = state.status !== 'closed' && state.autosave === 'saved';
212
+ const [savedGone, setSavedGone] = useState(false);
213
+ const [seenSaved, setSeenSaved] = useState(autosaved);
214
+ if (seenSaved !== autosaved) {
215
+ setSeenSaved(autosaved);
216
+ setSavedGone(false);
217
+ }
218
+ useEffect(() => {
219
+ if (!beside || !autosaved)
220
+ return;
221
+ const timer = window.setTimeout(() => setSavedGone(true), SAVED_FOR_MS);
222
+ return () => window.clearTimeout(timer);
223
+ }, [beside, autosaved]);
131
224
  const isOpen = state.status !== 'closed';
225
+ const pinned = usePinnedStatus(container, autosave && (isOpen || always));
132
226
  const wasOpen = useRef(false);
133
227
  useEffect(() => {
134
228
  // Always open: the caret stays wherever the person put it.
135
229
  if (isOpen && !wasOpen.current && !always) {
230
+ const spot = caretTarget.current;
231
+ caretTarget.current = null;
136
232
  for (const selector of FOCUS_ORDER) {
137
233
  const target = container.current?.querySelector(selector);
138
234
  if (target) {
139
- target.focus();
235
+ // Opened by a click on the text: the page stays where it is.
236
+ target.focus(spot ? { preventScroll: true } : undefined);
140
237
  break;
141
238
  }
142
239
  }
240
+ if (spot)
241
+ placeCaretSoon(spot);
143
242
  }
144
243
  // Closed: the caret goes back to the value's edit button after a
145
244
  // keyboard save or Esc, or whenever closing left it nowhere (a pick
@@ -149,7 +248,35 @@ export function EditableField({ label, edit, children, layout = 'block', look =
149
248
  (editButton.current ?? triggerBox.current?.querySelector('button'))?.focus();
150
249
  }
151
250
  wasOpen.current = isOpen;
152
- }, [isOpen, always]);
251
+ }, [isOpen, always, placeCaretSoon]);
252
+ // Esc on a changed long text that doesn't autosave: asks first (F7).
253
+ const [askingDiscard, setAskingDiscard] = useState(false);
254
+ const asking = useRef(false);
255
+ useLayoutEffect(() => {
256
+ asking.current = askingDiscard;
257
+ });
258
+ // The first refusal or failed save of an autosaving field toasts too:
259
+ // its line may be far from where the person is looking (F5). Once per
260
+ // run of failures; a save that lands starts the count again.
261
+ // A conflict (saved elsewhere) isn't a failed save: its toast says so.
262
+ const failure = state.status !== 'closed' ? state.error : null;
263
+ const conflicted = state.status !== 'closed' && Boolean(state.conflict);
264
+ const toasted = useRef(false);
265
+ useEffect(() => {
266
+ if (!autosave)
267
+ return;
268
+ if (failure === null) {
269
+ toasted.current = false;
270
+ return;
271
+ }
272
+ if (toasted.current)
273
+ return;
274
+ toasted.current = true;
275
+ if (conflicted)
276
+ toast.warning(`${label} changed elsewhere`, { description: 'Keep Mine or Show Saved, under it.' });
277
+ else
278
+ toast.error(`Couldn't save ${label}`, { description: failure });
279
+ }, [autosave, failure, conflicted, label]);
153
280
  useEffect(() => () => window.clearTimeout(blurTimer.current), []);
154
281
  // Whether an Esc is closing a list inside the control. Read on the way
155
282
  // down (window, capture): a picker closes its list from a document
@@ -188,6 +315,9 @@ export function EditableField({ label, edit, children, layout = 'block', look =
188
315
  const onShownClick = (event) => {
189
316
  if (event.target.closest(INTERACTIVE))
190
317
  return;
318
+ // Long text opens with the caret where it was clicked (F8).
319
+ if (edit.kind === 'long-text')
320
+ caretTarget.current = spotAtPoint(event.currentTarget, event.clientX, event.clientY);
191
321
  start();
192
322
  };
193
323
  // Always editable: Ctrl/Cmd+Enter or Esc saves now, the caret staying put.
@@ -208,6 +338,13 @@ export function EditableField({ label, edit, children, layout = 'block', look =
208
338
  saveNow();
209
339
  else if (autosave)
210
340
  commitFromKeyboard();
341
+ else if (edit.kind === 'long-text' && !(edit.isEqual ?? sameAsJson)(state.draft, state.initial)) {
342
+ window.clearTimeout(blurTimer.current);
343
+ // This Esc opens the question; it mustn't also close it (or a
344
+ // record dialog around the field) on its way up to the document.
345
+ event.stopPropagation();
346
+ setAskingDiscard(true);
347
+ }
211
348
  else {
212
349
  refocus.current = true;
213
350
  cancel();
@@ -236,7 +373,7 @@ export function EditableField({ label, edit, children, layout = 'block', look =
236
373
  blurTimer.current = window.setTimeout(() => {
237
374
  if (store.state(key).status !== 'open')
238
375
  return;
239
- if (container.current?.querySelector(HOLD))
376
+ if (container.current?.querySelector(HOLD) || asking.current)
240
377
  return;
241
378
  void store.commit(key).then(() => {
242
379
  if (always)
@@ -270,9 +407,25 @@ export function EditableField({ label, edit, children, layout = 'block', look =
270
407
  // A refusal about one of the value's own fields shows on that field when
271
408
  // the control says it shows them; anything else shows under the control.
272
409
  const lineError = edit.errorsOnFields && fieldErrors ? null : open.error;
273
- return (_jsxs("span", { ref: container, "data-slot": "editable-value", "data-state": saving || autosaving ? 'saving' : open.error ? 'failed' : 'editing', onKeyDown: onKeyDown, onBlur: onBlur, onFocus: onFocus, className: cn('flex min-w-0 flex-col gap-1.5', layout === 'block' ? 'w-full' : 'w-fit max-w-full', className), children: [_jsx(Control, { render: edit.control, id: controlId, value: open.draft, onChange: (value) => store.change(key, value), commit: commit, cancel: cancel, disabled: saving, invalid: !saving && open.error !== null, label: label, describedBy: describedBy, onProblem: (problem) => store.report(key, problem), inline: Boolean(edit.inline), errors: saving ? undefined : fieldErrors }, open.revision ?? 0), _jsx("span", { id: describedBy, className: "type-body", children: autosave ? (_jsxs(_Fragment, { children: [lineError && _jsx(FieldError, { className: "type-caption", children: lineError }), _jsx("span", { role: "status", className: "inline-flex items-center gap-1.5 type-caption text-muted-foreground", children: autosaving ? (_jsxs(_Fragment, { children: [_jsx(Spinner, { "aria-hidden": "true", className: "size-3.5" }), "Saving\u2026"] })) : (open.autosave === 'saved' &&
274
- !open.error && (_jsxs(_Fragment, { children: [_jsx(CheckIcon, { "aria-hidden": "true", className: "size-3.5" }), "Saved"] }))) })] })) : saving ? (_jsxs("span", { role: "status", className: "inline-flex items-center gap-1.5 type-caption text-muted-foreground", children: [_jsx(Spinner, { "aria-hidden": "true", className: "size-3.5" }), "Saving\u2026"] })) : (lineError && _jsx(FieldError, { className: "type-caption", children: lineError })) })] }));
410
+ // Something to say: a save in flight, saved, or why it can't save.
411
+ const hasStatus = autosaving || open.autosave === 'saved' || lineError !== null;
412
+ const pin = hasStatus ? pinned : null;
413
+ // The saved value changed elsewhere under unsaved typing: the person picks (F4).
414
+ const conflictActions = 'conflict' in open && open.conflict && (_jsxs("span", { className: "mt-1 flex flex-wrap gap-2", children: [_jsx(Button, { type: "button", size: "xs", variant: "outline", onClick: () => void store.keepMine(key), children: "Keep Mine" }), _jsx(Button, { type: "button", size: "xs", variant: "ghost", onClick: () => store.takeSaved(key), children: "Show Saved" })] }));
415
+ return (_jsxs(_Fragment, { children: [_jsxs("span", { ref: container, "data-slot": "editable-value", "data-state": saving || autosaving ? 'saving' : open.error ? 'failed' : 'editing', onKeyDown: onKeyDown, onBlur: onBlur, onFocus: onFocus, className: cn('flex min-w-0', beside ? 'flex-row flex-wrap items-center gap-x-2 gap-y-1' : 'flex-col gap-1.5', layout === 'block' ? 'w-full' : 'w-fit max-w-full', className), children: [_jsx(Control, { render: edit.control, id: controlId, value: open.draft, onChange: (value) => store.change(key, value), commit: commit, cancel: cancel, disabled: saving, invalid: !saving && open.error !== null, label: label, describedBy: describedBy, onProblem: (problem) => store.report(key, problem), inline: Boolean(edit.inline), errors: saving ? undefined : fieldErrors }, open.revision ?? 0), _jsx("span", { id: describedBy, "data-slot": "editable-value-status", "data-pinned": pin ? '' : undefined,
416
+ // Pinned to the screen's bottom edge while the field runs past
417
+ // it, so the save's state and a refusal stay in view (F5).
418
+ style: pin ? { left: pin.left, maxWidth: pin.width } : undefined, className: cn('type-body',
419
+ // Beside the value, a refusal takes the line under it.
420
+ beside && (lineError ? 'basis-full' : 'flex items-center'), pin && 'fixed bottom-3 z-30 w-fit rounded-md border border-border bg-popover px-2 py-1 text-popover-foreground shadow-md'), children: autosave ? (_jsxs(_Fragment, { children: [lineError && _jsx(FieldError, { className: "type-caption", children: lineError }), conflictActions, _jsx("span", { role: "status", className: "inline-flex items-center gap-1.5 type-caption text-muted-foreground", children: autosaving ? (_jsxs(_Fragment, { children: [_jsx(Spinner, { "aria-hidden": "true", className: "size-3.5" }), _jsx("span", { className: cn(beside && 'sr-only'), children: "Saving\u2026" })] })) : (open.autosave === 'saved' &&
421
+ !open.error &&
422
+ !(beside && savedGone) && (_jsxs(_Fragment, { children: [_jsx(CheckIcon, { "aria-hidden": "true", className: cn('size-3.5', beside && 'text-success-text') }), _jsx("span", { className: cn(beside && 'sr-only'), children: "Saved" })] }))) })] })) : saving ? (_jsxs("span", { role: "status", className: "inline-flex items-center gap-1.5 type-caption text-muted-foreground", children: [_jsx(Spinner, { "aria-hidden": "true", className: "size-3.5" }), "Saving\u2026"] })) : (_jsxs(_Fragment, { children: [lineError && _jsx(FieldError, { className: "type-caption", children: lineError }), conflictActions] })) })] }), _jsx(DiscardChangesDialog, { open: askingDiscard, "data-leave-guard": "", onKeepEditing: () => setAskingDiscard(false), onDiscard: () => {
423
+ setAskingDiscard(false);
424
+ refocus.current = true;
425
+ cancel();
426
+ } })] }));
275
427
  }
428
+ const sameAsJson = (a, b) => JSON.stringify(a) === JSON.stringify(b);
276
429
  /**
277
430
  * While a field holds something unsaved, leaving asks first: an in-app
278
431
  * link or Back (React Router's blocker, so the app needs a data router),
@@ -287,7 +440,13 @@ export function EditableField({ label, edit, children, layout = 'block', look =
287
440
  export function LeaveGuard({ store }) {
288
441
  const dirty = useSyncExternalStore(store.subscribe, () => store.dirty, () => store.dirty);
289
442
  const savesOnLeave = useSyncExternalStore(store.subscribe, () => store.savesOnLeave, () => store.savesOnLeave);
290
- const blocker = useBlocker(({ currentLocation, nextLocation }) => store.dirty && currentLocation.pathname !== nextLocation.pathname);
443
+ // Typing a rich-text field holds back (F6) counts: the tab's prompt is
444
+ // set up from the first key, and a move reports it before it's judged.
445
+ const holding = useSyncExternalStore(subscribePendingEdits, hasPendingEdits, hasPendingEdits);
446
+ const blocker = useBlocker(({ currentLocation, nextLocation }) => {
447
+ flushPendingEdits();
448
+ return store.dirty && currentLocation.pathname !== nextLocation.pathname;
449
+ });
291
450
  const [saveFailed, setSaveFailed] = useState(false);
292
451
  const latestBlocker = useRef(blocker);
293
452
  useLayoutEffect(() => {
@@ -315,23 +474,41 @@ export function LeaveGuard({ store }) {
315
474
  };
316
475
  }, [blocker.state, store]);
317
476
  useEffect(() => {
318
- if (!dirty)
477
+ if (!dirty && !holding)
319
478
  return;
320
- const onBeforeUnload = (event) => {
479
+ // Saves started as the page goes ask the browser to finish them
480
+ // (`keepalive`, lib/page-leaving.ts), F13.
481
+ const saveAsLeaving = () => {
482
+ markPageLeaving();
321
483
  void store.saveAll();
322
- event.preventDefault();
323
484
  };
485
+ const onBeforeUnload = (event) => {
486
+ saveAsLeaving();
487
+ // Held-back typing that turned out unchanged leaves nothing to ask about.
488
+ if (store.dirty)
489
+ event.preventDefault();
490
+ };
491
+ // Hidden (another tab, a phone's home screen, often the last thing a
492
+ // phone tells a page): save now, and while hidden don't wait for the
493
+ // pause. iOS gives no leave prompt, only these.
324
494
  const onVisibilityChange = () => {
325
- if (document.visibilityState === 'hidden')
326
- void store.saveAll();
495
+ const hidden = document.visibilityState === 'hidden';
496
+ store.hurry(hidden);
497
+ if (hidden)
498
+ saveAsLeaving();
499
+ else
500
+ clearPageLeaving();
327
501
  };
328
502
  window.addEventListener('beforeunload', onBeforeUnload);
503
+ window.addEventListener('pagehide', saveAsLeaving);
329
504
  document.addEventListener('visibilitychange', onVisibilityChange);
330
505
  return () => {
331
506
  window.removeEventListener('beforeunload', onBeforeUnload);
507
+ window.removeEventListener('pagehide', saveAsLeaving);
332
508
  document.removeEventListener('visibilitychange', onVisibilityChange);
509
+ store.hurry(false);
333
510
  };
334
- }, [dirty, store]);
511
+ }, [dirty, holding, store]);
335
512
  return (_jsx(DiscardChangesDialog, { open: blocker.state === 'blocked' && (!savesOnLeave || saveFailed), description: "A field you're editing hasn't been saved. Leaving now loses what you typed.", "data-leave-guard": "", onKeepEditing: () => {
336
513
  setSaveFailed(false);
337
514
  if (blocker.state === 'blocked')
@@ -29,6 +29,7 @@ import { DiscardChangesDialog } from '../ui/dialog.js';
29
29
  import { FieldGroup } from '../ui/field.js';
30
30
  import { Spinner } from '../ui/spinner.js';
31
31
  import { countFormErrors } from '../../lib/form-errors.js';
32
+ import { flushPendingEdits } from '../../lib/pending-edits.js';
32
33
  import { FormLeaveGuard } from './form-leave-guard.js';
33
34
  import { Notice } from './notice.js';
34
35
  const FOCUSABLE = 'input:not([type=hidden]), select, textarea, button, [contenteditable=true], [tabindex]:not([tabindex="-1"])';
@@ -98,6 +99,9 @@ export function EntityForm({ title, onSubmit, isSubmitting, submitError, onRetry
98
99
  // the render that draws react-hook-form's marks, and looks for them.
99
100
  const [attempt, setAttempt] = useState(0);
100
101
  const submit = (event) => {
102
+ // A rich-text field reports its typing a pause after it stops: asked
103
+ // for now, so the submit reads the last of it (F6).
104
+ flushPendingEdits();
101
105
  const done = onSubmit(event);
102
106
  void Promise.resolve(done).then(() => setAttempt((count) => count + 1));
103
107
  };
@@ -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,12 @@
1
1
  import { type ReactNode } from 'react';
2
2
  /** Which look a set of equal items takes. */
3
- export type EqualItemsLook = 'cards' | 'table' | 'featured' | 'panels';
3
+ export type EqualItemsLook = 'cards' | 'table' | 'featured' | 'panels' | 'stepper';
4
+ /**
5
+ * Where an item is in a sequence, for `look="stepper"`: `done` (a filled
6
+ * step with a check), `current` (ringed, "Current" under its name, its
7
+ * panel's border the accent) or `upcoming` (outlined, the default).
8
+ */
9
+ export type EqualItemStep = 'done' | 'current' | 'upcoming';
4
10
  /**
5
11
  * A state's tone, from design-language.md "Semantic tones": `neutral` (the
6
12
  * default) for most values, a colour only where the state means good,
@@ -44,6 +50,15 @@ export type EqualItem = {
44
50
  actions?: ReactNode;
45
51
  /** The whole row in the `cards` and `panels` looks (an editor open in it). */
46
52
  wide?: boolean;
53
+ /** For `look="stepper"`: done, current or upcoming (the default). */
54
+ step?: EqualItemStep;
55
+ /**
56
+ * For `look="stepper"`: a step that needs a look while another is shown
57
+ * (an unsaved change that needs an answer in it): a small warning dot on
58
+ * its step, and these words at the end of the step's name ("needs an
59
+ * answer").
60
+ */
61
+ attention?: string;
47
62
  };
48
63
  export type EqualItemsProps = {
49
64
  items: readonly EqualItem[];
@@ -51,9 +66,19 @@ export type EqualItemsProps = {
51
66
  look?: EqualItemsLook;
52
67
  /**
53
68
  * 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.
69
+ * one; an id that matches none falls back to the first too. For
70
+ * `look="stepper"`: the step shown first, defaulting to the `current`
71
+ * one, else the first.
55
72
  */
56
73
  featuredId?: string;
74
+ /**
75
+ * For `look="stepper"`: the step shown, when the app keeps it (in the
76
+ * URL, say). An id that matches none falls back as `featuredId` does.
77
+ * Without it, the stepper keeps its own.
78
+ */
79
+ selectedId?: string;
80
+ /** For `look="stepper"`: called with the step picked. */
81
+ onSelectedChange?: (id: string) => void;
57
82
  /**
58
83
  * For `look="featured"`: the other items open when it first shows.
59
84
  * Each toggle opens and closes on its own after that.
@@ -77,7 +102,7 @@ export type EqualItemsProps = {
77
102
  };
78
103
  /**
79
104
  * A few equal, related things inside a record view (record page standard
80
- * R10): one data shape, four looks.
105
+ * R10): one data shape, five looks.
81
106
  *
82
107
  * ```tsx
83
108
  * <EqualItems
@@ -94,9 +119,10 @@ export type EqualItemsProps = {
94
119
  *
95
120
  * `cards` for a few things with little to say about each, `table` for
96
121
  * 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
122
+ * best, `panels` when each has several details and must read as separate,
123
+ * `stepper` for a sequence with a current step, its steps picking the one
124
+ * panel shown (design-language.md "A few equal things"). An item's own `content` (an
99
125
  * editor) goes under its fields at full width, its `actions` (Edit, Remove)
100
126
  * at its title line's end; `wide` gives it the whole row of cards or panels.
101
127
  */
102
- export declare function EqualItems({ items, look, featuredId, defaultOpenIds, label, headingLevel, titleColumn, stateColumn, actionsColumn, emptyText, noFieldsText, className, }: EqualItemsProps): import("react").JSX.Element;
128
+ 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,13 @@ 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.
18
25
  //
19
26
  // The parts are the record's own: a state is a `Badge` in the outline
20
27
  // style (design-language.md "The three badge styles"), a field is the
@@ -29,8 +36,9 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
29
36
  // `actions`, its own buttons (Edit, Remove), at the end of its title line,
30
37
  // or the table's last column. `wide` gives an item the whole row in
31
38
  // `cards` and `panels`, for content that needs it (an editor open).
32
- import { Fragment, useState } from 'react';
33
- import { ChevronDownIcon } from 'lucide-react';
39
+ import { Fragment, useLayoutEffect, useRef, useState } from 'react';
40
+ import { Tabs as TabsPrimitive } from '@base-ui/react/tabs';
41
+ import { CheckIcon, ChevronDownIcon } from 'lucide-react';
34
42
  import { cn } from 'cn';
35
43
  import { Badge } from '../ui/badge.js';
36
44
  import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '../ui/collapsible.js';
@@ -123,9 +131,51 @@ function FeaturedToggle({ item, level, noFieldsText, defaultOpen, }) {
123
131
  const Heading = `h${level}`;
124
132
  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
133
  }
134
+ // The items as numbered steps joined by a line, a tablist picking the one
135
+ // panel shown under it (Base UI's tabs: arrow keys, Home and End move and
136
+ // pick, Tab goes on into the panel). A step's name is what it shows plus
137
+ // hidden words ("Step 2: Phase 2: Build, done"), never an aria-label, so
138
+ // the visible text stays in the name. Wider than its column (a phone, many
139
+ // steps), the row scrolls sideways in its own box, never the page, and
140
+ // keeps the shown step in view.
141
+ function Stepper({ items, label, level, noFieldsText, featuredId, selectedId, onSelectedChange, }) {
142
+ const has = (id) => id !== undefined && items.some((item) => item.id === id);
143
+ const first = has(featuredId) ? featuredId : (items.find((item) => item.step === 'current') ?? items[0]).id;
144
+ const [own, setOwn] = useState(first);
145
+ const shownId = has(selectedId) ? selectedId : has(own) ? own : first;
146
+ 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]);
159
+ return (_jsxs(TabsPrimitive.Root, { "data-slot": "equal-items-stepper", value: shownId, onValueChange: (next) => {
160
+ const id = String(next);
161
+ setOwn(id);
162
+ 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) => {
164
+ 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));
174
+ }) }), 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
+ }
126
176
  /**
127
177
  * A few equal, related things inside a record view (record page standard
128
- * R10): one data shape, four looks.
178
+ * R10): one data shape, five looks.
129
179
  *
130
180
  * ```tsx
131
181
  * <EqualItems
@@ -142,15 +192,16 @@ function FeaturedToggle({ item, level, noFieldsText, defaultOpen, }) {
142
192
  *
143
193
  * `cards` for a few things with little to say about each, `table` for
144
194
  * 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
195
+ * best, `panels` when each has several details and must read as separate,
196
+ * `stepper` for a sequence with a current step, its steps picking the one
197
+ * panel shown (design-language.md "A few equal things"). An item's own `content` (an
147
198
  * editor) goes under its fields at full width, its `actions` (Edit, Remove)
148
199
  * at its title line's end; `wide` gives it the whole row of cards or panels.
149
200
  */
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, }) {
201
+ 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
202
  if (items.length === 0) {
152
203
  return (_jsx("p", { "data-slot": "equal-items", "data-look": look, "data-state": "empty", className: cn('type-body text-muted-foreground', className), children: emptyText }));
153
204
  }
154
205
  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 })) }));
206
+ 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
207
  }
@@ -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
  };
@@ -15,12 +15,18 @@ import { jsx as _jsx } from "react/jsx-runtime";
15
15
  import { useEffect, useLayoutEffect, useRef } from 'react';
16
16
  import { useBlocker } from 'react-router';
17
17
  import { DiscardChangesDialog } from '../ui/dialog.js';
18
+ import { flushPendingEdits } from '../../lib/pending-edits.js';
18
19
  export function FormLeaveGuard({ dirty, letThrough }) {
19
20
  const latest = useRef({ dirty, letThrough });
20
21
  useLayoutEffect(() => {
21
22
  latest.current = { dirty, letThrough };
22
23
  });
23
- const blocker = useBlocker(({ currentLocation, nextLocation }) => latest.current.dirty && !latest.current.letThrough() && currentLocation.pathname !== nextLocation.pathname);
24
+ // Typing a rich-text field holds back (F6) is reported first; the form
25
+ // marks itself dirty from it as it does from any change.
26
+ const blocker = useBlocker(({ currentLocation, nextLocation }) => {
27
+ flushPendingEdits();
28
+ return latest.current.dirty && !latest.current.letThrough() && currentLocation.pathname !== nextLocation.pathname;
29
+ });
24
30
  useEffect(() => {
25
31
  if (!dirty)
26
32
  return;
@@ -1,2 +1,3 @@
1
1
  import type { RichTextEditorProps } from './rich-text-editor.js';
2
+ export declare const MERGE_PAUSE_MS = 300;
2
3
  export default function MilkdownEditor({ id, defaultValue, onChange, onProblem, readOnly, autoFocus, placeholder, maxLength, toolbar, inline, upload, imageAccept, imageMaxSize, headingLevel, headingFrom, foldKey, tableLook, pageLink, onCreatePage, className, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, }: RichTextEditorProps): import("react").JSX.Element;