@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
package/dist/index.d.ts CHANGED
@@ -38,14 +38,15 @@ export { RecordDialogRoute, RecordLink, type RecordDialogRouteProps, type Record
38
38
  export { recordDialogState, useNewRecordDialog, useOpenRecord, useRecordDialog, type NewRecordDialogContextValue, type RecordDialogBackground, type RecordDialogContextValue, type RecordDialogState, } from './components/app/record-dialog-context.js';
39
39
  export { FormDialog, type FormDialogProps } from './components/app/form-dialog.js';
40
40
  export { DeleteAction, type DeleteActionProps, type DeleteKind, type DeleteReason } from './components/app/delete-action.js';
41
- export { notify, doneMessage, pastTense, type NotifyDoneOptions } from './components/app/notify.js';
41
+ export { notify, doneMessage, pastTense, type NotifyDoneOptions, type NotifyOpen } from './components/app/notify.js';
42
42
  export { useAction, type ActionOutcome, type ActionState, type UseActionOptions } from './hooks/use-action.js';
43
43
  export { ActionError, type ActionErrorProps } from './components/app/action-error.js';
44
44
  export { JobStatus, type JobProgress, type JobStatusProps } from './components/app/job-status.js';
45
45
  export { OfflineNotice, type OfflineNoticeProps } from './components/app/offline-notice.js';
46
46
  export { useOffline } from './lib/connection.js';
47
47
  export { editInPlace, type EditControlProps, type EditInPlace, type EditInPlaceList, type EditInPlaceListOptions, type EditInPlaceOptions, type EditKind, type EditListAddProps, type EditListItemProps, } from './components/app/edit-in-place.js';
48
- export { inPlace, type InPlaceDateConfig, type InPlaceFieldsOptions, type InPlaceLinkConfig, type InPlaceLinkValue, type InPlaceMoneyConfig, type InPlaceMonthDayConfig, type InPlaceNumberConfig, type InPlaceOption, type InPlacePart, type InPlaceRecord, type InPlaceRecurrenceConfig, type InPlaceReferenceConfig, type InPlaceSaved, type InPlaceSelectConfig, type InPlaceTextConfig, } from './components/app/edit-in-place-presets.js';
48
+ export { rebaseMarkdown } from './lib/markdown-merge.js';
49
+ export { inPlace, type InPlaceDateConfig, type InPlaceFieldsOptions, type InPlaceLinkConfig, type InPlaceLinkValue, type InPlaceMoneyConfig, type InPlaceMonthDayConfig, type InPlaceNumberConfig, type InPlaceOption, type InPlacePart, type InPlaceRatingConfig, type InPlaceRecord, type InPlaceRecurrenceConfig, type InPlaceReferenceConfig, type InPlaceSaved, type InPlaceSelectConfig, type InPlaceTextConfig, } from './components/app/edit-in-place-presets.js';
49
50
  export { linkHost, linkHref, linkRule } from './lib/link-href.js';
50
51
  export { TITLE_CASE_SMALL_WORDS, titleCase } from './lib/title-case.js';
51
52
  export { DataEnvironmentBanner } from './components/app/data-environment-banner.js';
@@ -84,7 +85,8 @@ export { Notice, type NoticeProps, type NoticeTone } from './components/app/noti
84
85
  export { ValueList, type ValueListItem, type ValueListProps } from './components/app/value-list.js';
85
86
  export { ListHeader, type ListHeaderAction, type ListHeaderLink, type ListHeaderProps, type ListHeaderSecondaryAction, type ListHeaderSibling, } from './components/app/list-header.js';
86
87
  export { Timeline, type TimelineItem, type TimelineProps } from './components/app/timeline.js';
87
- export { EqualItems, type EqualItem, type EqualItemField, type EqualItemState, type EqualItemTone, type EqualItemsLook, type EqualItemsProps, } from './components/app/equal-items.js';
88
+ export { EqualItems, type EqualItem, type EqualItemField, type EqualItemState, type EqualItemStep, type EqualItemTone, type EqualItemsLook, type EqualItemsProps, } from './components/app/equal-items.js';
89
+ export { StepTrack, type StepTrackProps, type StepTrackState, type StepTrackStep, } from './components/app/step-track.js';
88
90
  export { NeedsYou, type NeedsYouItem, type NeedsYouProps, type NeedsYouTone } from './components/app/needs-you.js';
89
91
  export { Freshness, type FreshnessProps } from './components/app/freshness.js';
90
92
  export { isStale } from './lib/freshness.js';
@@ -96,6 +98,7 @@ export { MultiLineChart, type ChartSeries, type ChartTone, type MultiLineChartPr
96
98
  export { StepBar, type StepBarProps } from './components/app/step-bar.js';
97
99
  export { RatingStar, type RatingStarProps, type RatingStarValue } from './components/app/rating-star.js';
98
100
  export { RatingScore, type RatingScoreGlyph, type RatingScoreProps } from './components/app/rating-score.js';
101
+ export { RatingInput, type RatingInputProps, type RatingInputSource } from './components/app/rating-input.js';
99
102
  export { DateField, type DateFieldProps } from './components/app/date-field.js';
100
103
  export { EmojiField, type EmojiFieldProps } from './components/app/emoji-field.js';
101
104
  export { MonthDayField, type MonthDayFieldProps } from './components/app/month-day-field.js';
@@ -128,6 +131,7 @@ export type { TableView, UrlChanges } from './hooks/table-url-changes.js';
128
131
  export { useDebouncedValue } from './hooks/use-debounced-value.js';
129
132
  export { useDocumentTitle } from './hooks/use-document-title.js';
130
133
  export { useRecordUpdate, type RecordChange, type RecordUpdateOptions, } from './hooks/use-record-update.js';
134
+ export { useFormVersion, type FormConflict, type FormVersion, type FormVersionOptions, } from './hooks/use-form-version.js';
131
135
  export { useIsMobile } from './hooks/use-mobile.js';
132
136
  export { useWakeLock } from './hooks/use-wake-lock.js';
133
137
  export { useSessionClock, type SessionClock, type SessionClockOptions, type SessionClockState, type SessionStatus, } from './hooks/use-session-clock.js';
package/dist/index.js CHANGED
@@ -53,6 +53,10 @@ export { JobStatus } from './components/app/job-status.js';
53
53
  export { OfflineNotice } from './components/app/offline-notice.js';
54
54
  export { useOffline } from './lib/connection.js';
55
55
  export { editInPlace, } from './components/app/edit-in-place.js';
56
+ // "Keep Mine" for long text after it changed elsewhere: both sides' edits,
57
+ // block by block, or null when they touch the same part (an `editInPlace`'s
58
+ // `rebase`; long text has it by default).
59
+ export { rebaseMarkdown } from './lib/markdown-merge.js';
56
60
  export { inPlace, } from './components/app/edit-in-place-presets.js';
57
61
  export { linkHost, linkHref, linkRule } from './lib/link-href.js';
58
62
  export { TITLE_CASE_SMALL_WORDS, titleCase } from './lib/title-case.js';
@@ -93,6 +97,7 @@ export { ValueList } from './components/app/value-list.js';
93
97
  export { ListHeader, } from './components/app/list-header.js';
94
98
  export { Timeline } from './components/app/timeline.js';
95
99
  export { EqualItems, } from './components/app/equal-items.js';
100
+ export { StepTrack, } from './components/app/step-track.js';
96
101
  export { NeedsYou } from './components/app/needs-you.js';
97
102
  export { Freshness } from './components/app/freshness.js';
98
103
  export { isStale } from './lib/freshness.js';
@@ -104,6 +109,7 @@ export { MultiLineChart, } from './components/app/multi-line-chart.js';
104
109
  export { StepBar } from './components/app/step-bar.js';
105
110
  export { RatingStar } from './components/app/rating-star.js';
106
111
  export { RatingScore } from './components/app/rating-score.js';
112
+ export { RatingInput } from './components/app/rating-input.js';
107
113
  export { DateField } from './components/app/date-field.js';
108
114
  export { EmojiField } from './components/app/emoji-field.js';
109
115
  export { MonthDayField } from './components/app/month-day-field.js';
@@ -135,6 +141,7 @@ export { useWidgetLayout, createWidgetLayoutStore, mergeWidgetLayout, } from './
135
141
  export { useDebouncedValue } from './hooks/use-debounced-value.js';
136
142
  export { useDocumentTitle } from './hooks/use-document-title.js';
137
143
  export { useRecordUpdate, } from './hooks/use-record-update.js';
144
+ export { useFormVersion, } from './hooks/use-form-version.js';
138
145
  export { useIsMobile } from './hooks/use-mobile.js';
139
146
  // Timed screens (docs/foundation/timed-screens.md)
140
147
  export { useWakeLock } from './hooks/use-wake-lock.js';
@@ -34,6 +34,18 @@ export declare class MarkdownMergeError extends Error {
34
34
  * than `current`.
35
35
  */
36
36
  export declare function mergeMarkdown(original: string, baseline: string, current: string): string;
37
+ /**
38
+ * Both edits at once, block by block: `mine` and `theirs` each started from
39
+ * `base` (the same saved text, edited in two places: this tab and another
40
+ * tab, a phone or an AI chat). Every top-level block only one side changed
41
+ * takes that side's change; a block neither changed keeps `theirs`'s own
42
+ * bytes. Returns null when both changed the same stretch of blocks (or
43
+ * both added text at the same place), when it can't be done without
44
+ * losing one of them: the caller asks the person instead. A three-way
45
+ * merge (diff3) over blocks matched by meaning, as `mergeMarkdown`
46
+ * matches them; it never merges inside a block.
47
+ */
48
+ export declare function rebaseMarkdown(base: string, mine: string, theirs: string): string | null;
37
49
  /**
38
50
  * The document's own marks, for writing a block the person edited the way
39
51
  * the rest is written: its bullet (`-`, `*`, `+`) and its thematic break.
@@ -393,6 +393,96 @@ export function mergeMarkdown(original, baseline, current) {
393
393
  throw new MarkdownMergeError();
394
394
  return out;
395
395
  }
396
+ const keysOf = (list) => list.map((block) => block.key).join('\n');
397
+ /**
398
+ * Both edits at once, block by block: `mine` and `theirs` each started from
399
+ * `base` (the same saved text, edited in two places: this tab and another
400
+ * tab, a phone or an AI chat). Every top-level block only one side changed
401
+ * takes that side's change; a block neither changed keeps `theirs`'s own
402
+ * bytes. Returns null when both changed the same stretch of blocks (or
403
+ * both added text at the same place), when it can't be done without
404
+ * losing one of them: the caller asks the person instead. A three-way
405
+ * merge (diff3) over blocks matched by meaning, as `mergeMarkdown`
406
+ * matches them; it never merges inside a block.
407
+ */
408
+ export function rebaseMarkdown(base, mine, theirs) {
409
+ if (mine === base || mine === theirs)
410
+ return theirs;
411
+ if (theirs === base)
412
+ return mine;
413
+ // What's written goes in theirs's own line ending (the text it lands in).
414
+ const eol = theirs[theirs.indexOf('\n') - 1] === '\r' ? '\r\n' : '\n';
415
+ const ownEnding = (text) => text.replace(/\r?\n/g, eol);
416
+ const based = blocks(base);
417
+ const lists = { mine: blocks(mine), theirs: blocks(theirs) };
418
+ const texts = { mine, theirs };
419
+ const theirsAt = new Map([...match(based, lists.theirs)].map(([to, from]) => [from, to]));
420
+ const hunks = (side) => {
421
+ const pairs = [...match(based, lists[side])].map(([to, from]) => [from, to]).sort((a, b) => a[0] - b[0]);
422
+ const out = [];
423
+ let [b, s] = [-1, -1];
424
+ for (const [nextB, nextS] of [...pairs, [based.length, lists[side].length]]) {
425
+ if (nextB > b + 1 || nextS > s + 1)
426
+ out.push({ side, start: b + 1, end: nextB, from: s + 1, to: nextS });
427
+ [b, s] = [nextB, nextS];
428
+ }
429
+ return out;
430
+ };
431
+ const keysIn = (hunk) => keysOf(lists[hunk.side].slice(hunk.from, hunk.to));
432
+ const mineHunks = hunks('mine');
433
+ const theirsHunks = hunks('theirs');
434
+ // Both changed the same stretch (or added at the same place) in
435
+ // different ways: no merge. The same change on both sides is one.
436
+ const kept = [...theirsHunks];
437
+ for (const ours of mineHunks) {
438
+ const clash = theirsHunks.find((other) => (ours.start < other.end && other.start < ours.end) || ours.start === other.start);
439
+ if (!clash)
440
+ kept.push(ours);
441
+ else if (clash.start !== ours.start || clash.end !== ours.end || keysIn(clash) !== keysIn(ours))
442
+ return null;
443
+ }
444
+ // In base order; at one place, an insertion before a replacement.
445
+ kept.sort((a, b) => a.start - b.start || a.end - b.end);
446
+ const pieces = [];
447
+ const add = (from, index) => pieces.push({ from, index, block: lists[from][index] });
448
+ let next = 0;
449
+ const keepBase = (until) => {
450
+ // Blocks no one changed: as theirs has them.
451
+ for (; next < until; next++)
452
+ add('theirs', theirsAt.get(next));
453
+ };
454
+ for (const hunk of kept) {
455
+ keepBase(hunk.start);
456
+ for (let index = hunk.from; index < hunk.to; index++)
457
+ add(hunk.side, index);
458
+ next = Math.max(next, hunk.end);
459
+ }
460
+ keepBase(based.length);
461
+ let out = '';
462
+ pieces.forEach((piece, k) => {
463
+ const previous = pieces[k - 1];
464
+ const list = lists[piece.from];
465
+ if (!previous) {
466
+ if (piece.index === 0)
467
+ out += ownEnding(texts[piece.from].slice(0, list[0].start));
468
+ }
469
+ else if (previous.from === piece.from && previous.index === piece.index - 1) {
470
+ out += ownEnding(texts[piece.from].slice(list[previous.index].end, piece.block.start));
471
+ }
472
+ else {
473
+ out += eol + eol;
474
+ }
475
+ out += piece.from === 'theirs' ? piece.block.source : ownEnding(piece.block.source);
476
+ });
477
+ // The text ends the way theirs ends.
478
+ if (pieces.length > 0) {
479
+ const last = lists.theirs.at(-1);
480
+ out += last ? theirs.slice(last.end) : ownEnding(mine.slice(lists.mine.at(-1)?.end ?? mine.length));
481
+ }
482
+ // Guard, as in mergeMarkdown: the result must read as exactly the blocks
483
+ // picked (two blocks fusing across a seam would be something else).
484
+ return keysOf(blocks(out)) === keysOf(pieces.map((piece) => piece.block)) ? out : null;
485
+ }
396
486
  /**
397
487
  * The document's own marks, for writing a block the person edited the way
398
488
  * the rest is written: its bullet (`-`, `*`, `+`) and its thematic break.
@@ -0,0 +1,3 @@
1
+ /** Stars or hearts. */
2
+ export type RatingGlyph = 'star' | 'heart';
3
+ export declare const RATING_GLYPH_PATHS: Record<RatingGlyph, string>;
@@ -0,0 +1,7 @@
1
+ // The glyphs a score out of a few is drawn with (RatingScore, RatingInput).
2
+ // Lucide's star and heart (24×24), so they match the icons around them.
3
+ // RatingScore and RatingInput draw the same ones.
4
+ export const RATING_GLYPH_PATHS = {
5
+ star: 'M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.123 2.123 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.123 2.123 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.122 2.122 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.122 2.122 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.122 2.122 0 0 0 1.597-1.16z',
6
+ heart: 'M2 9.5a5.5 5.5 0 0 1 9.591-3.676.56.56 0 0 0 .818 0A5.49 5.49 0 0 1 22 9.5c0 2.29-1.5 4-3 5.5l-5.492 5.313a2 2 0 0 1-3 .019L5 15c-1.5-1.5-3-3.2-3-5.5',
7
+ };
@@ -0,0 +1,9 @@
1
+ import type { AppError } from '../api/contracts.js';
2
+ /**
3
+ * Why a save was refused, in the server's words: for a 422, the message
4
+ * on a field the save sent (the first field error otherwise), else the
5
+ * `AppError`'s message.
6
+ */
7
+ export declare function refusalReason(error: AppError, sent?: object): string;
8
+ /** Why a save failed, in words to show beside what was being saved. */
9
+ export declare function messageOf(error: unknown): string;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Why a save was refused, in the server's words: for a 422, the message
3
+ * on a field the save sent (the first field error otherwise), else the
4
+ * `AppError`'s message.
5
+ */
6
+ export function refusalReason(error, sent) {
7
+ const fieldErrors = Object.entries(error.fieldErrors ?? {});
8
+ const fields = Object.keys(sent ?? {});
9
+ const onSentField = fieldErrors.find(([key]) => fields.some((field) => key === field || key.startsWith(`${field}.`)));
10
+ return (onSentField ?? fieldErrors[0])?.[1][0] ?? error.message;
11
+ }
12
+ /** Why a save failed, in words to show beside what was being saved. */
13
+ export function messageOf(error) {
14
+ if (error && typeof error === 'object' && 'kind' in error)
15
+ return refusalReason(error);
16
+ if (error instanceof Error)
17
+ return error.message;
18
+ return 'The save failed. Try again.';
19
+ }
@@ -436,6 +436,18 @@ components:
436
436
  content:
437
437
  application/json:
438
438
  schema: { $ref: "#/components/schemas/HTTPErrorBody" }
439
+ ConflictError:
440
+ # Optional: an app that checks no versions leaves it out, and
441
+ # check-contract doesn't ask for it.
442
+ x-optional: true
443
+ description: >
444
+ The record changed since the version the request was built on
445
+ (another tab, device or AI chat saved in between). Nothing was
446
+ written. The client fetches the record again and lets the person
447
+ choose; the gateway's toAppError makes it AppError kind "conflict".
448
+ content:
449
+ application/json:
450
+ schema: { $ref: "#/components/schemas/HTTPErrorBody" }
439
451
  SignInExpiredError:
440
452
  description: The pending sign-in is missing, expired or out of tries. Start again with POST /auth/login.
441
453
  content:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tristan2828/ui-foundation",
3
- "version": "4.126.0",
3
+ "version": "4.128.0",
4
4
  "description": "Shared UI foundation for contract-first, database-backed React apps: shadcn primitives, DataTable/EntityForm composites, auth, the gateway error seam, design tokens, lint rules and the AI playbook.",
5
5
  "license": "MIT",
6
6
  "repository": {