@tristan2828/ui-foundation 4.126.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 (43) hide show
  1. package/conventions/docs/add-an-entity.md +118 -34
  2. package/conventions/docs/cell-patterns.md +88 -41
  3. package/conventions/docs/design-language.md +45 -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 +31 -4
  14. package/dist/components/app/edit-in-place-store.js +59 -11
  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-view.js +5 -1
  18. package/dist/components/app/equal-items.d.ts +32 -6
  19. package/dist/components/app/equal-items.js +59 -8
  20. package/dist/components/app/error-state.js +1 -0
  21. package/dist/components/app/milkdown-editor.js +3 -2
  22. package/dist/components/app/pill-filter.d.ts +16 -0
  23. package/dist/components/app/pill-filter.js +22 -1
  24. package/dist/components/app/rating-input.d.ts +22 -0
  25. package/dist/components/app/rating-input.js +65 -0
  26. package/dist/components/app/rating-score.d.ts +2 -1
  27. package/dist/components/app/rating-score.js +2 -6
  28. package/dist/components/app/rich-text-editor.d.ts +4 -2
  29. package/dist/components/app/rich-text-editor.js +3 -2
  30. package/dist/components/app/rich-text-keyboard-bar.js +3 -2
  31. package/dist/components/app/rich-text-toolbar.js +1 -1
  32. package/dist/components/app/rich-text-tools-bar.d.ts +3 -1
  33. package/dist/components/app/rich-text-tools-bar.js +2 -2
  34. package/dist/hooks/use-record-update.d.ts +13 -1
  35. package/dist/hooks/use-record-update.js +17 -3
  36. package/dist/index.d.ts +4 -2
  37. package/dist/index.js +5 -0
  38. package/dist/lib/markdown-merge.d.ts +12 -0
  39. package/dist/lib/markdown-merge.js +90 -0
  40. package/dist/lib/rating-glyphs.d.ts +3 -0
  41. package/dist/lib/rating-glyphs.js +7 -0
  42. package/openapi/foundation.yaml +12 -0
  43. package/package.json +1 -1
@@ -3,7 +3,8 @@ import { type MonthDay } from '../../lib/month-day.js';
3
3
  import { type PlainDate } from '../../lib/plain-date.js';
4
4
  import { type Recurrence, type WeekdayCode } from '../../lib/recurrence.js';
5
5
  import { type ChoiceButtonsOption } from './choice-buttons.js';
6
- import type { EditInPlace } from './edit-in-place.js';
6
+ import { type RatingScoreGlyph } from './rating-score.js';
7
+ import type { EditControlProps, EditInPlace } from './edit-in-place.js';
7
8
  /** What the value saves as: with `required: true` never `null` (a blank is refused). */
8
9
  export type InPlaceSaved<TValue, TRequired extends boolean> = TRequired extends true ? TValue : TValue | null;
9
10
  type Common<TValue, TSaved> = {
@@ -125,6 +126,21 @@ export type InPlaceSelectConfig<T extends string | number, TRequired extends boo
125
126
  emptyLabel?: string;
126
127
  placeholder?: string;
127
128
  };
129
+ /**
130
+ * A score out of a few, set by clicking a star (RatingInput, 4.127). The
131
+ * stars are the value: shown at rest, with no click to open, a click on a
132
+ * star saving it at once. Pressing the set star again saves `null` (none)
133
+ * unless `required`; the arrow keys move and set it, saved a pause after
134
+ * the last one (or on leaving it).
135
+ */
136
+ export type InPlaceRatingConfig<TRequired extends boolean = boolean> = {
137
+ /** Pressing the set star again doesn't clear it: never `null`. */
138
+ required?: TRequired;
139
+ /** How many stars. Defaults to 5. */
140
+ max?: number;
141
+ /** Stars (the default) or hearts. */
142
+ glyph?: RatingScoreGlyph;
143
+ };
128
144
  /** A record found by search, as `search` returns it. */
129
145
  export type InPlaceRecord<Id> = {
130
146
  id: Id;
@@ -248,6 +264,40 @@ export declare const inPlace: {
248
264
  * saves. `inPlace.select` with `look: 'buttons'`.
249
265
  */
250
266
  choice<T extends string | number, R extends boolean = false>(options: Common<T | null | undefined, InPlaceSaved<T, R>> & Omit<InPlaceSelectConfig<T, R>, "look">): EditInPlace;
267
+ /**
268
+ * A score out of a few as stars (or hearts) set by a click (RatingInput):
269
+ * the stars are the value, always there with no click to open, and a
270
+ * click on one saves it. Pressing the set one again saves `null` unless
271
+ * `required`. Reads at rest (printed) as RatingScore.
272
+ */
273
+ rating<R extends boolean = false>(options: Common<number | null | undefined, InPlaceSaved<number, R>> & InPlaceRatingConfig<R>): {
274
+ alwaysEditable: boolean;
275
+ kind: import("./edit-in-place.js").EditKind;
276
+ value: unknown;
277
+ control: (props: EditControlProps<unknown>) => ReactNode;
278
+ schema?: {
279
+ safeParse: (value: unknown) => {
280
+ success: false;
281
+ error: {
282
+ issues: readonly {
283
+ message: string;
284
+ path?: readonly PropertyKey[];
285
+ }[];
286
+ };
287
+ } | {
288
+ success: true;
289
+ data: unknown;
290
+ };
291
+ };
292
+ save: (value: unknown) => Promise<unknown>;
293
+ isEqual?: (a: unknown, b: unknown) => boolean;
294
+ autosave?: boolean;
295
+ inline?: boolean;
296
+ shown?: ReactNode;
297
+ fieldErrors?: (cause: unknown) => Record<string, string> | null;
298
+ errorsOnFields?: boolean;
299
+ rebase?: ((base: unknown, mine: unknown, theirs: unknown) => unknown) | false;
300
+ };
251
301
  /**
252
302
  * Another record, searched as you type through the app's `search`; a
253
303
  * pick saves its id. With `onCreate`, Create "<typed>" makes one.
@@ -10,6 +10,8 @@ import { ChoiceButtons } from './choice-buttons.js';
10
10
  import { DateField } from './date-field.js';
11
11
  import { MonthDayField } from './month-day-field.js';
12
12
  import { OptionSelect } from './option-select.js';
13
+ import { RatingInput } from './rating-input.js';
14
+ import { RatingScore } from './rating-score.js';
13
15
  import { RecurrenceField } from './recurrence-field.js';
14
16
  import { Parts, ReferencePicker } from './edit-in-place-controls.js';
15
17
  import { LinkOut } from './row-edit-cells.js';
@@ -216,6 +218,25 @@ function selectKind(config) {
216
218
  },
217
219
  };
218
220
  }
221
+ function ratingKind(config) {
222
+ const max = config.max ?? 5;
223
+ return {
224
+ editKind: 'choice',
225
+ toDraft: (value) => (value == null ? null : Math.min(Math.max(0, Math.round(value)), max) || null),
226
+ check: (draft) => (draft == null && config.required ? { ok: false, message: REQUIRED } : { ok: true, value: draft }),
227
+ show: (value) => (value == null ? null : _jsx(RatingScore, { value: value, max: max, glyph: config.glyph })),
228
+ control: (props) => (_jsx(RatingInput, { id: props.id, value: props.value, max: max, glyph: config.glyph, label: props.label,
229
+ // A pick saves now; an arrow's value waits for the last one.
230
+ onChange: (next, source) => {
231
+ if (next === null && config.required)
232
+ return;
233
+ if (source === 'pointer')
234
+ props.commit(next);
235
+ else
236
+ props.onChange(next);
237
+ }, disabled: props.disabled, invalid: props.invalid, "aria-describedby": props.describedBy })),
238
+ };
239
+ }
219
240
  function referenceKind(config) {
220
241
  return {
221
242
  editKind: 'choice',
@@ -461,6 +482,15 @@ export const inPlace = {
461
482
  choice(options) {
462
483
  return single(selectKind({ ...options, look: 'buttons' }), { ...options, value: options.value ?? null });
463
484
  },
485
+ /**
486
+ * A score out of a few as stars (or hearts) set by a click (RatingInput):
487
+ * the stars are the value, always there with no click to open, and a
488
+ * click on one saves it. Pressing the set one again saves `null` unless
489
+ * `required`. Reads at rest (printed) as RatingScore.
490
+ */
491
+ rating(options) {
492
+ return { ...single(ratingKind(options), { ...options, value: options.value ?? null }), alwaysEditable: true };
493
+ },
464
494
  /**
465
495
  * Another record, searched as you type through the app's `search`; a
466
496
  * pick saves its id. With `onCreate`, Create "<typed>" makes one.
@@ -32,6 +32,13 @@ export type EditFieldConfig = {
32
32
  * value (`text`, `effort`). `null` or `{}` when it names none.
33
33
  */
34
34
  fieldErrors?: (cause: unknown) => Record<string, string> | null;
35
+ /**
36
+ * "Keep mine" after a conflict: `mine` (what's typed, started from
37
+ * `base`) laid onto `theirs` (the value saved elsewhere since), or null
38
+ * when both changed the same part. Without it, "keep mine" saves what's
39
+ * typed over theirs. Long text's default is `rebaseMarkdown`.
40
+ */
41
+ rebase?: ((base: unknown, mine: unknown, theirs: unknown) => unknown) | false;
35
42
  };
36
43
  export type EditFieldState = {
37
44
  status: 'closed';
@@ -58,9 +65,15 @@ export type OpenFieldState = {
58
65
  /**
59
66
  * The saved value changed elsewhere while this held unsaved typing:
60
67
  * nothing saves until `keepMine` (save over it) or `takeSaved` (show it).
61
- * `markConflict` sets it too: the seam for a server's 409 (Roadmap 405).
68
+ * A save the server refused with a 409 (AppError kind `conflict`) sets
69
+ * it too.
62
70
  */
63
71
  conflict?: boolean;
72
+ /**
73
+ * "Keep mine" couldn't lay what's typed onto the value saved elsewhere:
74
+ * both changed the same part. Another "keep mine" replaces theirs.
75
+ */
76
+ overlap?: boolean;
64
77
  };
65
78
  /** How long typing has to stop before an autosaving field saves. */
66
79
  export declare const AUTOSAVE_DELAY_MS = 1000;
@@ -70,6 +83,12 @@ export type EditInPlaceStoreOptions = {
70
83
  };
71
84
  /** What a field shows when the saved value changed under unsaved typing. */
72
85
  export declare const CONFLICT_MESSAGE = "This changed elsewhere (another tab, device or chat) since you started typing. Saving now replaces that.";
86
+ /** The conflict's message for a field that can keep both (a `rebase`): Keep Mine adds what's typed to it. */
87
+ export declare const CONFLICT_REBASE_MESSAGE = "This changed elsewhere (another tab, device or chat) since you started typing. Keep Mine adds your changes to it.";
88
+ /** "Keep mine" found both sides changed the same part. */
89
+ 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
+ /** Whether a save's rejection is the server's "changed since" (a 409, AppError kind `conflict`). */
91
+ export declare function isConflict(error: unknown): boolean;
73
92
  /** Why a save failed, in words to show beside what was being saved. */
74
93
  export declare function messageOf(error: unknown): string;
75
94
  export declare class EditInPlaceStore {
@@ -178,11 +197,19 @@ export declare class EditInPlaceStore {
178
197
  refresh(key: string): boolean;
179
198
  /**
180
199
  * The saved value changed under this field's unsaved typing, as a
181
- * server's conflict answer says: the seam for a version check's 409
182
- * (Roadmap 405). Nothing saves until the person picks.
200
+ * server's conflict answer says. A save refused with a 409 (AppError
201
+ * kind `conflict`) does this itself. Nothing saves until the person picks.
183
202
  */
184
203
  markConflict(key: string): void;
185
- /** A conflict, answered "keep mine": what's typed saves over the value saved elsewhere. */
204
+ /**
205
+ * A conflict, answered "keep mine". With a `rebase`, what's typed is laid
206
+ * onto the value saved elsewhere and the control starts over showing
207
+ * both (`revision`) as it saves; if both changed the same part it stays
208
+ * a conflict (`overlap`), and keeping mine again saves what's typed over
209
+ * theirs. Without a `rebase`, what's typed saves over it. The save
210
+ * carries the record's latest version, so a writer that saved again
211
+ * meanwhile is another conflict, not an overwrite.
212
+ */
186
213
  keepMine(key: string): Promise<boolean>;
187
214
  /** A conflict, answered "show the saved one": what's typed goes, and the control starts over from the saved value. */
188
215
  takeSaved(key: string): void;
@@ -5,6 +5,17 @@ export const AUTOSAVE_DELAY_MS = 1000;
5
5
  const CLOSED = { status: 'closed' };
6
6
  /** What a field shows when the saved value changed under unsaved typing. */
7
7
  export const CONFLICT_MESSAGE = 'This changed elsewhere (another tab, device or chat) since you started typing. Saving now replaces that.';
8
+ /** The conflict's message for a field that can keep both (a `rebase`): Keep Mine adds what's typed to it. */
9
+ export const CONFLICT_REBASE_MESSAGE = 'This changed elsewhere (another tab, device or chat) since you started typing. Keep Mine adds your changes to it.';
10
+ /** "Keep mine" found both sides changed the same part. */
11
+ export 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.";
12
+ function conflictMessage(config) {
13
+ return config?.rebase ? CONFLICT_REBASE_MESSAGE : CONFLICT_MESSAGE;
14
+ }
15
+ /** Whether a save's rejection is the server's "changed since" (a 409, AppError kind `conflict`). */
16
+ export function isConflict(error) {
17
+ return Boolean(error && typeof error === 'object' && error.kind === 'conflict');
18
+ }
8
19
  // Line endings, trailing spaces on a line and blank lines at either end:
9
20
  // what a backend commonly normalises in text it's sent.
10
21
  function normalisedText(value) {
@@ -275,7 +286,7 @@ export class EditInPlaceStore {
275
286
  if (!config)
276
287
  return Promise.resolve(false);
277
288
  if (open.problem || open.conflict) {
278
- this.set(key, { ...open, error: open.problem ?? CONFLICT_MESSAGE });
289
+ this.set(key, { ...open, error: open.problem ?? open.error ?? conflictMessage(config) });
279
290
  return Promise.resolve(false);
280
291
  }
281
292
  const isEqual = config.isEqual ?? sameAsJson;
@@ -299,7 +310,12 @@ export class EditInPlaceStore {
299
310
  this.set(key, CLOSED);
300
311
  return true;
301
312
  }, (error) => {
302
- this.set(key, { ...open, status: 'open', error: messageOf(error), fieldErrors: fieldErrorsOf(config, error) });
313
+ // Another writer saved since (a 409): nothing was written, and
314
+ // nothing saves until the person picks.
315
+ if (isConflict(error))
316
+ this.set(key, { ...open, status: 'open', conflict: true, error: conflictMessage(config) });
317
+ else
318
+ this.set(key, { ...open, status: 'open', error: messageOf(error), fieldErrors: fieldErrorsOf(config, error) });
303
319
  return false;
304
320
  })
305
321
  .finally(() => this.saving.delete(key));
@@ -384,7 +400,7 @@ export class EditInPlaceStore {
384
400
  if (!config)
385
401
  return Promise.resolve(false);
386
402
  if (state.problem || state.conflict) {
387
- this.set(key, { ...state, error: state.problem ?? CONFLICT_MESSAGE });
403
+ this.set(key, { ...state, error: state.problem ?? state.error ?? conflictMessage(config) });
388
404
  return Promise.resolve(false);
389
405
  }
390
406
  const isEqual = config.isEqual ?? sameAsJson;
@@ -415,7 +431,15 @@ export class EditInPlaceStore {
415
431
  return true;
416
432
  }, (error) => {
417
433
  const now = this.state(key);
418
- if (now.status === 'open')
434
+ if (now.status !== 'open')
435
+ return false;
436
+ // Another writer saved since (a 409): nothing was written, and
437
+ // nothing saves until the person picks.
438
+ if (isConflict(error)) {
439
+ this.clearTimer(key);
440
+ this.set(key, { ...now, conflict: true, overlap: false, error: conflictMessage(config), fieldErrors: undefined, autosave: undefined });
441
+ }
442
+ else
419
443
  this.set(key, { ...now, error: messageOf(error), fieldErrors: fieldErrorsOf(config, error), autosave: undefined });
420
444
  return false;
421
445
  })
@@ -464,7 +488,9 @@ export class EditInPlaceStore {
464
488
  const busy = this.timers.has(key) || this.autosaving.has(key) || this.queued.has(key) || state.status === 'saving';
465
489
  const clean = !busy && state.error === null && state.problem === null && isEqual(state.draft, state.initial);
466
490
  if (!clean) {
467
- this.set(key, { ...state, conflict: true, error: CONFLICT_MESSAGE });
491
+ // Already a conflict ("keep mine" found an overlap): the new value is
492
+ // what it's now against, and the person picks again.
493
+ this.set(key, { ...state, conflict: true, overlap: false, error: conflictMessage(config) });
468
494
  return false;
469
495
  }
470
496
  const revision = (state.revision ?? 0) + 1;
@@ -473,23 +499,45 @@ export class EditInPlaceStore {
473
499
  }
474
500
  /**
475
501
  * The saved value changed under this field's unsaved typing, as a
476
- * server's conflict answer says: the seam for a version check's 409
477
- * (Roadmap 405). Nothing saves until the person picks.
502
+ * server's conflict answer says. A save refused with a 409 (AppError
503
+ * kind `conflict`) does this itself. Nothing saves until the person picks.
478
504
  */
479
505
  markConflict(key) {
480
506
  const state = this.state(key);
481
507
  if (state.status === 'closed')
482
508
  return;
483
509
  this.clearTimer(key);
484
- this.set(key, { ...state, status: 'open', conflict: true, error: CONFLICT_MESSAGE, autosave: undefined });
510
+ this.set(key, { ...state, status: 'open', conflict: true, error: conflictMessage(this.configs.get(key)?.()), autosave: undefined });
485
511
  }
486
- /** A conflict, answered "keep mine": what's typed saves over the value saved elsewhere. */
512
+ /**
513
+ * A conflict, answered "keep mine". With a `rebase`, what's typed is laid
514
+ * onto the value saved elsewhere and the control starts over showing
515
+ * both (`revision`) as it saves; if both changed the same part it stays
516
+ * a conflict (`overlap`), and keeping mine again saves what's typed over
517
+ * theirs. Without a `rebase`, what's typed saves over it. The save
518
+ * carries the record's latest version, so a writer that saved again
519
+ * meanwhile is another conflict, not an overwrite.
520
+ */
487
521
  keepMine(key) {
488
522
  const state = this.state(key);
489
523
  const config = this.configs.get(key)?.();
490
524
  if (state.status !== 'open' || !state.conflict || !config)
491
525
  return Promise.resolve(false);
492
- this.set(key, { ...state, conflict: false, error: null, initial: config.value });
526
+ let draft = state.draft;
527
+ let revision = state.revision;
528
+ if (config.rebase && !state.overlap) {
529
+ const merged = config.rebase(state.initial, state.draft, config.value);
530
+ if (merged === null || merged === undefined) {
531
+ this.set(key, { ...state, overlap: true, error: OVERLAP_MESSAGE });
532
+ return Promise.resolve(false);
533
+ }
534
+ if (!(config.isEqual ?? sameAsJson)(merged, state.draft)) {
535
+ draft = merged;
536
+ revision = (state.revision ?? 0) + 1;
537
+ }
538
+ }
539
+ this.seen.set(key, config.value);
540
+ this.set(key, { ...state, draft, revision, conflict: false, overlap: false, error: null, initial: config.value });
493
541
  return this.autosaves(key) ? this.flush(key) : this.commit(key);
494
542
  }
495
543
  /** A conflict, answered "show the saved one": what's typed goes, and the control starts over from the saved value. */
@@ -529,7 +577,7 @@ export class EditInPlaceStore {
529
577
  for (const key of this.always) {
530
578
  const state = this.state(key);
531
579
  if (state.status === 'open')
532
- this.set(key, { ...state, draft: state.initial, error: null, problem: null, conflict: false, autosave: undefined });
580
+ this.set(key, { ...state, draft: state.initial, error: null, problem: null, conflict: false, overlap: false, autosave: undefined });
533
581
  }
534
582
  }
535
583
  }
@@ -76,6 +76,7 @@ export type EditInPlace = {
76
76
  shown?: ReactNode;
77
77
  fieldErrors?: (cause: unknown) => Record<string, string> | null;
78
78
  errorsOnFields?: boolean;
79
+ rebase?: ((base: unknown, mine: unknown, theirs: unknown) => unknown) | false;
79
80
  };
80
81
  export type EditInPlaceOptions<TDraft, TValue> = {
81
82
  kind: EditKind;
@@ -138,6 +139,16 @@ export type EditInPlaceOptions<TDraft, TValue> = {
138
139
  * its path inside the value. The control gets them as `errors`.
139
140
  */
140
141
  fieldErrors?: (cause: unknown) => Record<string, string> | null;
142
+ /**
143
+ * "Keep Mine" after the value changed elsewhere (another tab, a phone,
144
+ * an AI chat): what's typed (`mine`, started from `base`) laid onto the
145
+ * value saved since (`theirs`), or null when both changed the same part
146
+ * (the person is told, and a second Keep Mine replaces theirs). Long
147
+ * text (`kind: 'long-text'`, a string) defaults to `rebaseMarkdown`,
148
+ * block by block; `false` turns that off, so Keep Mine saves what's
149
+ * typed over theirs, as every other kind does.
150
+ */
151
+ rebase?: ((base: TDraft, mine: TDraft, theirs: TDraft) => TDraft | null) | false;
141
152
  /**
142
153
  * The control shows `errors` on its own fields, so a refusal about one
143
154
  * of them isn't repeated under the control; one about none still shows there.
@@ -28,6 +28,9 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
28
28
  // click to open, and never closes. Ctrl/Cmd+Enter and Esc save now.
29
29
  // - `inline`: always editable, and the control is told to look like the
30
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.
31
34
  // - Saved (4.88, F16): once a save lands, "✓ Saved" shows beside the value
32
35
  // for two seconds (`role="status"`).
33
36
  // - `layout="inline"` (4.102): the pencil takes no room until hover or
@@ -50,6 +53,7 @@ import { Spinner } from '../ui/spinner.js';
50
53
  import { clearPageLeaving, markPageLeaving } from '../../lib/page-leaving.js';
51
54
  import { flushPendingEdits, hasPendingEdits, subscribePendingEdits } from '../../lib/pending-edits.js';
52
55
  import { caretSpot, placeCaretWhenReady, spotAtPoint } from './edit-caret.js';
56
+ import { rebaseMarkdown } from '../../lib/markdown-merge.js';
53
57
  import { EditInPlaceContext } from './edit-in-place.js';
54
58
  import { SAVED_FOR_MS } from './edit-row.js';
55
59
  import { escapePassedThrough } from './escape-passthrough.js';
@@ -129,6 +133,12 @@ function useStore() {
129
133
  throw new Error('<EditableValue> works inside an <EntityView>, which runs editing in place.');
130
134
  return store;
131
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
+ }
132
142
  export function EditableValue(props) {
133
143
  return _jsx(EditableField, { ...props });
134
144
  }
@@ -142,10 +152,12 @@ export function EditableField({ label, edit, children, layout = 'block', look =
142
152
  const always = Boolean(edit.alwaysEditable || edit.inline);
143
153
  const autosave = always || Boolean(edit.autosave);
144
154
  // The latest config, read by the store whenever it needs it (`inline`
145
- // is always editable to it).
146
- 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 });
147
158
  useLayoutEffect(() => {
148
- 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 };
149
161
  });
150
162
  useEffect(() => store.register(key, () => config.current), [store, key]);
151
163
  const state = useSyncExternalStore(store.subscribe, () => store.state(key), () => store.state(key));
@@ -194,6 +206,21 @@ export function EditableField({ label, edit, children, layout = 'block', look =
194
206
  useEffect(() => {
195
207
  refresh();
196
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]);
197
224
  const isOpen = state.status !== 'closed';
198
225
  const pinned = usePinnedStatus(container, autosave && (isOpen || always));
199
226
  const wasOpen = useRef(false);
@@ -231,7 +258,9 @@ export function EditableField({ label, edit, children, layout = 'block', look =
231
258
  // The first refusal or failed save of an autosaving field toasts too:
232
259
  // its line may be far from where the person is looking (F5). Once per
233
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.
234
262
  const failure = state.status !== 'closed' ? state.error : null;
263
+ const conflicted = state.status !== 'closed' && Boolean(state.conflict);
235
264
  const toasted = useRef(false);
236
265
  useEffect(() => {
237
266
  if (!autosave)
@@ -243,8 +272,11 @@ export function EditableField({ label, edit, children, layout = 'block', look =
243
272
  if (toasted.current)
244
273
  return;
245
274
  toasted.current = true;
246
- toast.error(`Couldn't save ${label}`, { description: failure });
247
- }, [autosave, failure, label]);
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]);
248
280
  useEffect(() => () => window.clearTimeout(blurTimer.current), []);
249
281
  // Whether an Esc is closing a list inside the control. Read on the way
250
282
  // down (window, capture): a picker closes its list from a document
@@ -380,11 +412,14 @@ export function EditableField({ label, edit, children, layout = 'block', look =
380
412
  const pin = hasStatus ? pinned : null;
381
413
  // The saved value changed elsewhere under unsaved typing: the person picks (F4).
382
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" })] }));
383
- 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 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,
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,
384
416
  // Pinned to the screen's bottom edge while the field runs past
385
417
  // it, so the save's state and a refusal stay in view (F5).
386
- style: pin ? { left: pin.left, maxWidth: pin.width } : undefined, className: cn('type-body', 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" }), "Saving\u2026"] })) : (open.autosave === 'saved' &&
387
- !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"] })) : (_jsxs(_Fragment, { children: [lineError && _jsx(FieldError, { className: "type-caption", children: lineError }), conflictActions] })) })] }), _jsx(DiscardChangesDialog, { open: askingDiscard, "data-leave-guard": "", onKeepEditing: () => setAskingDiscard(false), onDiscard: () => {
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: () => {
388
423
  setAskingDiscard(false);
389
424
  refocus.current = true;
390
425
  cancel();
@@ -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;