@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
package/dist/index.d.ts CHANGED
@@ -45,7 +45,8 @@ export { JobStatus, type JobProgress, type JobStatusProps } from './components/a
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';
@@ -69,6 +70,7 @@ export { MultiReference } from './components/app/multi-reference.js';
69
70
  export { ListEditor } from './components/app/list-editor.js';
70
71
  export { PasswordInput } from './components/app/password-input.js';
71
72
  export { RichTextEditor, type RichTextEditorProps } from './components/app/rich-text-editor.js';
73
+ export { flushPendingEdits, hasPendingEdits } from './lib/pending-edits.js';
72
74
  export { RouteErrorBoundary } from './components/app/route-error-boundary.js';
73
75
  export { PillFilter, type PillFilterOption, type PillFilterProps } from './components/app/pill-filter.js';
74
76
  export { SecondaryFilters, type ActiveFilter, type SecondaryFiltersProps } from './components/app/secondary-filters.js';
@@ -83,7 +85,7 @@ export { Notice, type NoticeProps, type NoticeTone } from './components/app/noti
83
85
  export { ValueList, type ValueListItem, type ValueListProps } from './components/app/value-list.js';
84
86
  export { ListHeader, type ListHeaderAction, type ListHeaderLink, type ListHeaderProps, type ListHeaderSecondaryAction, type ListHeaderSibling, } from './components/app/list-header.js';
85
87
  export { Timeline, type TimelineItem, type TimelineProps } from './components/app/timeline.js';
86
- 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';
87
89
  export { NeedsYou, type NeedsYouItem, type NeedsYouProps, type NeedsYouTone } from './components/app/needs-you.js';
88
90
  export { Freshness, type FreshnessProps } from './components/app/freshness.js';
89
91
  export { isStale } from './lib/freshness.js';
@@ -95,6 +97,7 @@ export { MultiLineChart, type ChartSeries, type ChartTone, type MultiLineChartPr
95
97
  export { StepBar, type StepBarProps } from './components/app/step-bar.js';
96
98
  export { RatingStar, type RatingStarProps, type RatingStarValue } from './components/app/rating-star.js';
97
99
  export { RatingScore, type RatingScoreGlyph, type RatingScoreProps } from './components/app/rating-score.js';
100
+ export { RatingInput, type RatingInputProps, type RatingInputSource } from './components/app/rating-input.js';
98
101
  export { DateField, type DateFieldProps } from './components/app/date-field.js';
99
102
  export { EmojiField, type EmojiFieldProps } from './components/app/emoji-field.js';
100
103
  export { MonthDayField, type MonthDayFieldProps } from './components/app/month-day-field.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';
@@ -75,6 +79,9 @@ export { MultiReference } from './components/app/multi-reference.js';
75
79
  export { ListEditor } from './components/app/list-editor.js';
76
80
  export { PasswordInput } from './components/app/password-input.js';
77
81
  export { RichTextEditor } from './components/app/rich-text-editor.js';
82
+ // Typing a RichTextEditor holds back until a pause, reported now: call it
83
+ // before reading a rich-text field's value to save it in your own form.
84
+ export { flushPendingEdits, hasPendingEdits } from './lib/pending-edits.js';
78
85
  export { RouteErrorBoundary } from './components/app/route-error-boundary.js';
79
86
  export { PillFilter } from './components/app/pill-filter.js';
80
87
  export { SecondaryFilters } from './components/app/secondary-filters.js';
@@ -101,6 +108,7 @@ export { MultiLineChart, } from './components/app/multi-line-chart.js';
101
108
  export { StepBar } from './components/app/step-bar.js';
102
109
  export { RatingStar } from './components/app/rating-star.js';
103
110
  export { RatingScore } from './components/app/rating-score.js';
111
+ export { RatingInput } from './components/app/rating-input.js';
104
112
  export { DateField } from './components/app/date-field.js';
105
113
  export { EmojiField } from './components/app/emoji-field.js';
106
114
  export { MonthDayField } from './components/app/month-day-field.js';
@@ -1,3 +1,28 @@
1
+ type MdNode = {
2
+ type: string;
3
+ position?: {
4
+ start: {
5
+ offset?: number;
6
+ };
7
+ end: {
8
+ offset?: number;
9
+ };
10
+ };
11
+ children?: MdNode[];
12
+ [key: string]: unknown;
13
+ };
14
+ declare function parse(markdown: string): MdNode;
15
+ declare function meaning(node: unknown, definitions: Map<string, MdNode>): unknown;
16
+ declare function content(node: MdNode, definitions: Map<string, MdNode>): string;
17
+ export declare const mergeParts: {
18
+ parse: typeof parse;
19
+ meaning: typeof meaning;
20
+ content: typeof content;
21
+ };
22
+ /** How many texts mergeMarkdown has parsed, for tests/markdown-merge-budget.test.ts. */
23
+ export declare const mergeStats: {
24
+ parses: number;
25
+ };
1
26
  export declare class MarkdownMergeError extends Error {
2
27
  constructor();
3
28
  }
@@ -9,6 +34,18 @@ export declare class MarkdownMergeError extends Error {
9
34
  * than `current`.
10
35
  */
11
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;
12
49
  /**
13
50
  * The document's own marks, for writing a block the person edited the way
14
51
  * the rest is written: its bullet (`-`, `*`, `+`) and its thematic break.
@@ -17,3 +54,4 @@ export declare function markdownStyle(markdown: string): {
17
54
  bullet: '-' | '*' | '+';
18
55
  rule: '-' | '*' | '_';
19
56
  };
57
+ export {};
@@ -28,6 +28,16 @@
28
28
  // - A table and the comment after it that keeps its column widths
29
29
  // (markdown-table-widths.ts) are one block: a width changed in the editor
30
30
  // is an edit to the table, and an unchanged one keeps the comment as written.
31
+ // - A code fence's info string after the language (`title="app.js"`,
32
+ // `{1,3}`) is something the editor can't hold: it loads only the
33
+ // language. `meaning` leaves it out, so an untouched fence still matches
34
+ // and is kept as written; `content` counts it, so a fence is never
35
+ // swapped for the editor's copy that lost it.
36
+ // - Line endings: a Windows (CRLF) note compares as if it were LF, and what
37
+ // the editor writes goes back in the document's own ending.
38
+ // - A link definition goes once nothing in the text uses it any more (no
39
+ // reference to it and no link to its address): select all and delete
40
+ // leaves an empty text, not an invisible definition.
31
41
  import remarkGfm from 'remark-gfm';
32
42
  import remarkParse from 'remark-parse';
33
43
  import { unified } from 'unified';
@@ -38,6 +48,10 @@ function parse(markdown) {
38
48
  }
39
49
  // Fields that are about how a node was written, not what it means.
40
50
  const STYLE_ONLY = new Set(['position', 'data', 'spread', 'label', 'referenceType']);
51
+ // Fields the editor can't hold, so it loads a node without them: left out
52
+ // of `meaning` (the block the editor shows still matches its original) but
53
+ // counted by `content` (nothing is lost by writing the editor's copy).
54
+ const EDITOR_DROPS = new Set(['meta']);
41
55
  // Nodes whose children are inline text: compared as runs of marked text.
42
56
  const INLINE_PARENTS = new Set(['paragraph', 'heading', 'tableCell']);
43
57
  // A reference link (or image) as the link it stands for, when its
@@ -99,9 +113,14 @@ function meaning(node, definitions) {
99
113
  const md = resolved(node, definitions);
100
114
  const out = {};
101
115
  for (const key of Object.keys(md).sort()) {
102
- if (STYLE_ONLY.has(key))
116
+ if (STYLE_ONLY.has(key) || EDITOR_DROPS.has(key))
103
117
  continue;
104
- out[key] = key === 'children' && INLINE_PARENTS.has(md.type) ? runs(md.children ?? [], definitions) : meaning(md[key], definitions);
118
+ const value = md[key];
119
+ // CRLF and LF text mean the same.
120
+ if (typeof value === 'string')
121
+ out[key] = value.replace(/\r\n?/g, '\n');
122
+ else
123
+ out[key] = key === 'children' && INLINE_PARENTS.has(md.type) ? runs(md.children ?? [], definitions) : meaning(value, definitions);
105
124
  }
106
125
  if ((md.type === 'link' || md.type === 'image') && out.title === undefined)
107
126
  out.title = null;
@@ -118,26 +137,68 @@ function meaning(node, definitions) {
118
137
  return out;
119
138
  }
120
139
  // Everything in a block a reader could lose: its text (spacing aside),
121
- // code, raw HTML, link and image addresses, image alt text, rules and
122
- // task boxes. Not how any of it is marked or laid out.
140
+ // code, raw HTML, rules, and every other field `meaning` compares
141
+ // (addresses, alt text, a code block's language, a heading's level, task
142
+ // boxes), plus what the editor can't hold (`EDITOR_DROPS`). Taken from the
143
+ // node's own fields, so a field `meaning` compares can't be missed here.
144
+ // Not how any of it is marked or nested (a node's type), nor laid out.
123
145
  function content(node, definitions) {
124
146
  const md = resolved(node, definitions);
125
147
  let out = '';
126
- if (typeof md.value === 'string')
127
- out += md.value.replace(/\s+/g, '');
128
- if (md.type === 'link' || md.type === 'image')
129
- out += `<${String(md.url)}>`;
130
- if (md.type === 'image' || md.type === 'imageReference')
131
- out += `![${String(md.alt ?? '')}]`;
132
148
  if (md.type === 'thematicBreak')
133
149
  out += '<hr>';
134
- if (md.type === 'listItem' && typeof md.checked === 'boolean')
135
- out += md.checked ? '[x]' : '[ ]';
150
+ for (const key of Object.keys(md).sort()) {
151
+ if (key === 'type' || key === 'children' || STYLE_ONLY.has(key))
152
+ continue;
153
+ const value = md[key];
154
+ if (value === null || value === undefined)
155
+ continue;
156
+ // Text runs on across marks: `a *b*` and `**a b**` hold the same text.
157
+ if (key === 'value' && typeof value === 'string')
158
+ out += value.replace(/\s+/g, '');
159
+ else
160
+ out += `<${key}=${JSON.stringify(value)}>`;
161
+ }
136
162
  for (const child of md.children ?? [])
137
163
  out += content(child, definitions);
138
164
  return out;
139
165
  }
166
+ // For tests/markdown-merge.test.ts: every field `meaning` compares must be
167
+ // one `content` counts. Not part of the package's exports.
168
+ export const mergeParts = { parse, meaning, content };
169
+ // References and addresses a block uses (see `Block`).
170
+ function uses(node, references = new Set(), urls = new Set()) {
171
+ if (node.type === 'linkReference' || node.type === 'imageReference' || node.type === 'definition') {
172
+ references.add(String(node.identifier));
173
+ }
174
+ if (typeof node.url === 'string')
175
+ urls.add(node.url);
176
+ for (const child of node.children ?? [])
177
+ uses(child, references, urls);
178
+ return { references, urls };
179
+ }
180
+ // The blocks of the texts merged lately, by text: an editor merges the
181
+ // same original and baseline against each edit, so each is parsed once
182
+ // per mount, not once per merge (F6). A few, most recent last.
183
+ const PARSED = 8;
184
+ const parsed = new Map();
140
185
  function blocks(markdown) {
186
+ const known = parsed.get(markdown);
187
+ if (known) {
188
+ parsed.delete(markdown);
189
+ parsed.set(markdown, known);
190
+ return known;
191
+ }
192
+ const out = parseBlocks(markdown);
193
+ parsed.set(markdown, out);
194
+ if (parsed.size > PARSED)
195
+ parsed.delete(parsed.keys().next().value);
196
+ return out;
197
+ }
198
+ /** How many texts mergeMarkdown has parsed, for tests/markdown-merge-budget.test.ts. */
199
+ export const mergeStats = { parses: 0 };
200
+ function parseBlocks(markdown) {
201
+ mergeStats.parses += 1;
141
202
  const tree = parse(markdown);
142
203
  const children = tree.children ?? [];
143
204
  const definitions = new Map();
@@ -161,6 +222,7 @@ function blocks(markdown) {
161
222
  // Tables with no width set read as they always have.
162
223
  key: JSON.stringify(widths?.some((width) => width !== null) ? [key, widths] : key),
163
224
  content: content(child, definitions),
225
+ ...uses(child),
164
226
  });
165
227
  }
166
228
  return out;
@@ -217,6 +279,19 @@ function shownOwnWay(originals, loaded, loadedToOriginal) {
217
279
  }
218
280
  return shown;
219
281
  }
282
+ const loadedPairs = new WeakMap();
283
+ function loadedAgainst(originals, loaded) {
284
+ let byLoaded = loadedPairs.get(originals);
285
+ if (!byLoaded)
286
+ loadedPairs.set(originals, (byLoaded = new WeakMap()));
287
+ let pair = byLoaded.get(loaded);
288
+ if (!pair) {
289
+ const loadedToOriginal = match(originals, loaded);
290
+ pair = { loadedToOriginal, shown: shownOwnWay(originals, loaded, loadedToOriginal) };
291
+ byLoaded.set(loaded, pair);
292
+ }
293
+ return pair;
294
+ }
220
295
  export class MarkdownMergeError extends Error {
221
296
  constructor() {
222
297
  super("This text can't be saved without changing parts you didn't edit. Undo the last change, or edit it in the form.");
@@ -233,10 +308,14 @@ export class MarkdownMergeError extends Error {
233
308
  export function mergeMarkdown(original, baseline, current) {
234
309
  if (current === baseline)
235
310
  return original;
311
+ // The document's own line ending (its first), for what the editor
312
+ // writes, which is always LF.
313
+ const eol = original[original.indexOf('\n') - 1] === '\r' ? '\r\n' : '\n';
314
+ const ownEnding = (text) => (eol === '\n' ? text : text.replace(/\r?\n/g, eol));
236
315
  const originals = blocks(original);
237
316
  const loaded = blocks(baseline);
238
317
  const edited = blocks(current);
239
- const loadedToOriginal = match(originals, loaded);
318
+ const { loadedToOriginal, shown } = loadedAgainst(originals, loaded);
240
319
  const editedToLoaded = match(loaded, edited);
241
320
  // Each edited block's original, if it is one unchanged.
242
321
  const sources = edited.map((_block, index) => {
@@ -254,7 +333,6 @@ export function mergeMarkdown(original, baseline, current) {
254
333
  });
255
334
  // Blocks the editor never showed (definitions, and any block it dropped
256
335
  // part of): after whatever came before them in the original.
257
- const shown = shownOwnWay(originals, loaded, loadedToOriginal);
258
336
  originals.forEach((_block, index) => {
259
337
  if (shown.has(index))
260
338
  return;
@@ -267,6 +345,23 @@ export function mergeMarkdown(original, baseline, current) {
267
345
  }
268
346
  items.splice(position, 0, { original: index, at: index });
269
347
  });
348
+ // A definition the original used and nothing uses now (no reference to
349
+ // it, no link to its address: the editor writes a reference link inline)
350
+ // goes with the text that used it.
351
+ const inText = (list) => list.filter((block) => block.type !== 'definition');
352
+ const usedBefore = new Set(inText(originals).flatMap((block) => [...block.references]));
353
+ const kept = items.map((item) => ('original' in item ? originals[item.original] : item.written));
354
+ const referencesNow = new Set(inText(kept).flatMap((block) => [...block.references]));
355
+ const urlsNow = new Set(inText(kept).flatMap((block) => [...block.urls]));
356
+ for (let k = items.length - 1; k >= 0; k--) {
357
+ const block = kept[k];
358
+ if (block.type !== 'definition')
359
+ continue;
360
+ const [identifier] = block.references;
361
+ const [url] = block.urls;
362
+ if (usedBefore.has(identifier) && !referencesNow.has(identifier) && !urlsNow.has(url))
363
+ items.splice(k, 1);
364
+ }
270
365
  let out = '';
271
366
  items.forEach((item, k) => {
272
367
  const previous = items[k - 1];
@@ -278,16 +373,16 @@ export function mergeMarkdown(original, baseline, current) {
278
373
  out += original.slice(originals[previous.original].end, originals[item.original].start);
279
374
  }
280
375
  else {
281
- out += '\n\n';
376
+ out += eol + eol;
282
377
  }
283
- out += 'original' in item ? originals[item.original].source : item.written.source;
378
+ out += 'original' in item ? originals[item.original].source : ownEnding(item.written.source);
284
379
  });
285
380
  // The document ends the way the original ended, whichever block is last
286
381
  // now: an edit to the last block adds no newline the person didn't type.
287
382
  // Text written from nothing ends the way the editor ends it.
288
383
  const ending = originals.length > 0
289
384
  ? original.slice(originals[originals.length - 1].end)
290
- : current.slice(edited.at(-1)?.end ?? current.length);
385
+ : ownEnding(current.slice(edited.at(-1)?.end ?? current.length));
291
386
  if (items.length > 0)
292
387
  out += ending;
293
388
  const saved = blocks(out)
@@ -298,6 +393,96 @@ export function mergeMarkdown(original, baseline, current) {
298
393
  throw new MarkdownMergeError();
299
394
  return out;
300
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
+ }
301
486
  /**
302
487
  * The document's own marks, for writing a block the person edited the way
303
488
  * the rest is written: its bullet (`-`, `*`, `+`) and its thematic break.
@@ -0,0 +1,8 @@
1
+ /** Under the browser's 64 KB keepalive budget, with room for a second save. */
2
+ export declare const KEEPALIVE_MAX_BYTES = 30000;
3
+ /** The page is closing or hidden: requests started in the next moment use `keepalive`. */
4
+ export declare function markPageLeaving(now?: number): void;
5
+ /** The page is back (visible again): requests are ordinary again. */
6
+ export declare function clearPageLeaving(): void;
7
+ /** Whether a request with this body, started now, should be sent with `keepalive`. */
8
+ export declare function keepaliveFor(body: unknown, now?: number): boolean;
@@ -0,0 +1,30 @@
1
+ // The page is going away (closing the tab, hidden on a phone): requests
2
+ // started now ask the browser to finish them after the page is gone
3
+ // (`keepalive`), so the last autosave still arrives (F13). LeaveGuard
4
+ // marks it; the transport reads it. Only a body that fits the browser's
5
+ // keepalive budget (64 KB across the page's keepalive requests) goes
6
+ // that way: a longer note's save goes as an ordinary request, which the
7
+ // leave prompt (`beforeunload`) gives time to finish.
8
+ /** Under the browser's 64 KB keepalive budget, with room for a second save. */
9
+ export const KEEPALIVE_MAX_BYTES = 30_000;
10
+ // How long after the mark a request still counts as made while leaving:
11
+ // the save goes through the mutation queue first.
12
+ const LEAVING_FOR_MS = 2_000;
13
+ let leavingUntil = 0;
14
+ /** The page is closing or hidden: requests started in the next moment use `keepalive`. */
15
+ export function markPageLeaving(now = Date.now()) {
16
+ leavingUntil = now + LEAVING_FOR_MS;
17
+ }
18
+ /** The page is back (visible again): requests are ordinary again. */
19
+ export function clearPageLeaving() {
20
+ leavingUntil = 0;
21
+ }
22
+ /** Whether a request with this body, started now, should be sent with `keepalive`. */
23
+ export function keepaliveFor(body, now = Date.now()) {
24
+ if (now >= leavingUntil)
25
+ return false;
26
+ // A save's JSON; nothing else (a GET, an upload's form) needs it.
27
+ if (typeof body !== 'string')
28
+ return false;
29
+ return new TextEncoder().encode(body).length <= KEEPALIVE_MAX_BYTES;
30
+ }
@@ -0,0 +1,14 @@
1
+ type Flush = () => void;
2
+ /**
3
+ * A control has typing it hasn't reported yet: `flush` reports it now.
4
+ * Returns the release, called once it has reported (by itself, after its
5
+ * pause, or through `flush`).
6
+ */
7
+ export declare function holdPendingEdit(flush: Flush): () => void;
8
+ /** Every control with typing held back reports it now (before a save reads the value). */
9
+ export declare function flushPendingEdits(): void;
10
+ /** Whether any control holds typing it hasn't reported yet. */
11
+ export declare function hasPendingEdits(): boolean;
12
+ /** Called when `hasPendingEdits()` changes (for `useSyncExternalStore`). */
13
+ export declare function subscribePendingEdits(listener: () => void): () => void;
14
+ export {};
@@ -0,0 +1,51 @@
1
+ // Edits a control holds back until they're needed (RichTextEditor, F6 of
2
+ // the 2026-11-17 review). Turning a long note back into Markdown that
3
+ // keeps every untouched block as written (mergeMarkdown) costs time in
4
+ // proportion to the note, so the editor does it a short pause after
5
+ // typing stops, not on every key. Anything about to read a control's
6
+ // value to save it calls `flushPendingEdits()` first: each editor with
7
+ // typing not yet reported reports it, synchronously, through its
8
+ // `onChange` (or `onProblem`).
9
+ //
10
+ // The edit-in-place store does (before each save, commit, refresh and
11
+ // when a field leaves), EntityForm does before its submit, and the leave
12
+ // guards do before they decide whether leaving loses something.
13
+ // `hasPendingEdits()` (with `subscribePendingEdits`) says whether any is
14
+ // waiting, for a leave guard that must ask the browser to hold a tab
15
+ // open before the pause is over.
16
+ const pending = new Set();
17
+ const listeners = new Set();
18
+ function changed() {
19
+ for (const listener of listeners)
20
+ listener();
21
+ }
22
+ /**
23
+ * A control has typing it hasn't reported yet: `flush` reports it now.
24
+ * Returns the release, called once it has reported (by itself, after its
25
+ * pause, or through `flush`).
26
+ */
27
+ export function holdPendingEdit(flush) {
28
+ pending.add(flush);
29
+ if (pending.size === 1)
30
+ changed();
31
+ return () => {
32
+ if (pending.delete(flush) && pending.size === 0)
33
+ changed();
34
+ };
35
+ }
36
+ /** Every control with typing held back reports it now (before a save reads the value). */
37
+ export function flushPendingEdits() {
38
+ for (const flush of [...pending])
39
+ flush();
40
+ }
41
+ /** Whether any control holds typing it hasn't reported yet. */
42
+ export function hasPendingEdits() {
43
+ return pending.size > 0;
44
+ }
45
+ /** Called when `hasPendingEdits()` changes (for `useSyncExternalStore`). */
46
+ export function subscribePendingEdits(listener) {
47
+ listeners.add(listener);
48
+ return () => {
49
+ listeners.delete(listener);
50
+ };
51
+ }
@@ -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
+ };
@@ -12,7 +12,17 @@ export function exposeMswForE2E(worker) {
12
12
  window.__msw = { worker, http, HttpResponse, delay };
13
13
  const override = window.__E2E_MSW_OVERRIDE__;
14
14
  if (override) {
15
+ // A held override answers once the test releases it: requests made
16
+ // before then wait, any made after go straight through.
17
+ const held = [];
18
+ window.__E2E_MSW_RELEASE__ = () => {
19
+ window.__E2E_MSW_RELEASED__ = true;
20
+ for (const go of held.splice(0))
21
+ go();
22
+ };
15
23
  worker.use(http[override.method](override.path, async () => {
24
+ if (override.hold && !window.__E2E_MSW_RELEASED__)
25
+ await new Promise((go) => held.push(go));
16
26
  if (override.delayMs)
17
27
  await delay(override.delayMs);
18
28
  if (override.bodyBase64 !== undefined) {
@@ -6,6 +6,12 @@ export type MswOverride = {
6
6
  status?: number;
7
7
  body?: unknown;
8
8
  delayMs?: number;
9
+ /**
10
+ * Holds every matching request until the test releases it
11
+ * (`forceMswOverride(page, override, { hold: true })` and its
12
+ * `release()`, or `releaseMswOverride(page)`). Set by `forceMswOverride`.
13
+ */
14
+ hold?: boolean;
9
15
  bodyBase64?: string;
10
16
  contentType?: string;
11
17
  /** Response headers, e.g. a 429's `Retry-After`. */
@@ -21,5 +27,7 @@ declare global {
21
27
  interface Window {
22
28
  __msw: MswHandle;
23
29
  __E2E_MSW_OVERRIDE__?: MswOverride;
30
+ __E2E_MSW_RELEASED__?: boolean;
31
+ __E2E_MSW_RELEASE__?: () => void;
24
32
  }
25
33
  }
@@ -5,7 +5,11 @@ import type { MswOverride } from '../mocks/override.js';
5
5
  export type { MswHandle, MswOverride } from '../mocks/override.js';
6
6
  export { expect };
7
7
  /**
8
- * Makes the page's `goto()` and `reload()` return once the app has
8
+ * Makes the page's `goto()` and `reload()` wait first until none of the
9
+ * page's own `/api/` requests has been in flight for 150 ms (at most 3 s,
10
+ * and reaching that never fails the test), so a save's follow-up refresh
11
+ * is answered by the page that sent it, on the mocks, not sent by the
12
+ * unloading page past them. They then return once the app has
9
13
  * booted (its first render into `#root`), not at the load event, and load
10
14
  * the page once more when one of the app's own files is refused before
11
15
  * then; a second refusal fails naming the file. The wait is bounded by
@@ -61,12 +65,46 @@ export declare function watchMswBypass(page: Page, { mockMode }?: MswBypassOptio
61
65
  export declare const test: import("playwright/test").TestType<import("playwright/test").PlaywrightTestArgs & import("playwright/test").PlaywrightTestOptions & {
62
66
  mswBypass: "fail" | "allow";
63
67
  }, import("playwright/test").PlaywrightWorkerArgs & import("playwright/test").PlaywrightWorkerOptions>;
68
+ export type MswOverrideOptions = {
69
+ /**
70
+ * Holds every matching request until the test calls `release()` (or
71
+ * `releaseMswOverride(page)`): the way to test a loading state. The
72
+ * skeleton is there for as long as the test needs, however slow the run,
73
+ * with no time to tune. `delayMs`, if set too, starts counting at the
74
+ * release.
75
+ */
76
+ hold?: boolean;
77
+ };
78
+ export type MswOverrideControl = {
79
+ /** Lets the held requests answer, and every later one answer at once (this page and any it loads next). */
80
+ release: () => Promise<void>;
81
+ };
64
82
  /**
65
83
  * Forces a response for the page's *first* load: set before navigation, so
66
84
  * it wins the race against the app's own first fetch. For states forced
67
85
  * after load, use `waitForMswReady` and then `window.__msw.worker.use(...)`.
86
+ * The override applies to every page the test loads after, reloads included.
87
+ *
88
+ * `{ hold: true }` holds the requests until the test releases them, for a
89
+ * loading state (`tasksList` here is the list's `MswOverride`):
90
+ *
91
+ * const list = await forceMswOverride(page, tasksList, { hold: true })
92
+ * await page.goto('/tasks')
93
+ * await expect(page.locator('[data-state="loading"]')).toBeVisible()
94
+ * await list.release()
95
+ * await expect(page.getByText('Water the ferns')).toBeVisible()
96
+ *
97
+ * Release before the test navigates again: `goto()` and `reload()` first
98
+ * wait for the page's `/api/` requests to settle, and a held one doesn't.
99
+ */
100
+ export declare function forceMswOverride(page: Page, override: MswOverride, { hold }?: MswOverrideOptions): Promise<MswOverrideControl>;
101
+ /**
102
+ * Releases a held override (`forceMswOverride(page, ..., { hold: true })`):
103
+ * the requests held so far answer, and later ones answer at once, on this
104
+ * page and every page the test loads after. Releasing twice, or an
105
+ * override that wasn't held, does nothing.
68
106
  */
69
- export declare function forceMswOverride(page: Page, override: MswOverride): Promise<void>;
107
+ export declare function releaseMswOverride(page: Page): Promise<void>;
70
108
  /** `window.__msw` is set only once the app's mocking has started — page.goto's load event doesn't wait for it. */
71
109
  export declare function waitForMswReady(page: Page): Promise<void>;
72
110
  /** Starts the page logged out: GET /auth/me answers 401 on first load. */