@ruckc/truss-code 1.48.1 → 1.50.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.
@@ -1,4 +1,220 @@
1
+ <script module lang="ts">
2
+ export type MergeViewLabels = {
3
+ /** Name of the base (common ancestor) side: heading, announcements and the `|||||||` conflict marker. */
4
+ base: string;
5
+ /** Name of the "ours" side: heading, announcements and the `<<<<<<<` conflict marker. */
6
+ ours: string;
7
+ /** Name of the "theirs" side: heading, announcements and the `>>>>>>>` conflict marker. */
8
+ theirs: string;
9
+ /** Heading of the merged result, and the name of its tab and region. */
10
+ result: string;
11
+ /** Accessible name of the whole view when no `label` is given. */
12
+ merge: string;
13
+ /** Name of the whole view when it has a file `name`: `label: name`. */
14
+ mergeOf: (label: string, name: string) => string;
15
+ /** Accessible name of the table of the three versions. */
16
+ versions: string;
17
+ /** Same, when the view has a file `name`. */
18
+ versionsOf: (name: string) => string;
19
+ /** Accessible name of the table of the merged result. */
20
+ merged: string;
21
+ /** Same, when the view has a file `name`. */
22
+ mergedOf: (name: string) => string;
23
+ /** Accessible name of the scrolling region of the three versions. */
24
+ versionsRegion: string;
25
+ /** Label of the pane switcher in a narrow view. */
26
+ mergePane: string;
27
+ /** Number of lines: "1 line", "3 lines". */
28
+ lines: (n: number) => string;
29
+ /** Hidden description of the base column. */
30
+ baseDescription: (name: string, lines: string) => string;
31
+ /** Hidden description of the ours / theirs column. */
32
+ sideDescription: (name: string, lines: string) => string;
33
+ /** Button that deletes the file (modify/delete or binary conflicts and the toolbar). */
34
+ deleteFile: string;
35
+ /** Accessible name of the previous-conflict button. */
36
+ previousConflict: string;
37
+ /** Accessible name of the next-conflict button. */
38
+ nextConflict: string;
39
+ /** Message when the files could not be loaded; `error` is the reason. */
40
+ loadFailed: (error: string) => string;
41
+ /** Retry button after a load failure. */
42
+ retry: string;
43
+ /** Hidden keyboard help of the view. */
44
+ help: string;
45
+ /** Name of the group shown for a modify/delete conflict. */
46
+ modifyDelete: string;
47
+ /** Name of the group shown for a binary file. */
48
+ binaryFile: string;
49
+ /** Note of a modify/delete conflict: which side deleted the file and which modified it (side names as given). */
50
+ modifyDeleteNote: (deleted: string, modified: string) => string;
51
+ /** Note of a binary file. */
52
+ binaryNote: string;
53
+ /** Button that keeps the modified file. */
54
+ keepModified: string;
55
+ /** Button that keeps one side of a binary file (the side's name as given). */
56
+ keep: (side: string) => string;
57
+ /** Status line while the files load. */
58
+ loading: string;
59
+ /** Status line: the file will be deleted. */
60
+ willDelete: string;
61
+ /** Status line: a side of a binary file was picked. */
62
+ keeping: (side: string) => string;
63
+ /** Status line: modified on one side, deleted on the other, nothing chosen yet. */
64
+ modifiedAndDeleted: string;
65
+ /** Status line: binary file, nothing chosen yet. */
66
+ binaryChoose: string;
67
+ /** Status line: how many conflicts are resolved. */
68
+ progress: (resolved: number, total: number) => string;
69
+ /** Status line without conflicts. */
70
+ noConflicts: string;
71
+ /** The state line of a conflict, e.g. "Conflict 1 of 3: unresolved". `resolution` is the `resolvedWith` text, absent when unresolved. */
72
+ conflictState: (n: number, total: number, resolution: string | undefined) => string;
73
+ /** "resolved with ours": `choice` is one of the `choice*` texts. */
74
+ resolvedWith: (choice: string) => string;
75
+ /** Announcement when jumping to a conflict: `state` is the `conflictState` text, `ours` and `theirs` the `sideHas` texts. */
76
+ conflictFocus: (state: string, ours: string, theirs: string) => string;
77
+ /** "Ours has 3 lines". */
78
+ sideHas: (side: string, lines: string) => string;
79
+ /** Announcement after resolving a conflict. */
80
+ announceResolved: (n: number, choice: string) => string;
81
+ /** Announcement after resetting a conflict. */
82
+ announceReset: (n: number) => string;
83
+ /** Announcement tail while conflicts remain. */
84
+ announceProgress: (resolved: number, total: number) => string;
85
+ /** Announcement tail when the last conflict is done. */
86
+ announceAllResolved: (total: number) => string;
87
+ /** Name of a conflict's action group. */
88
+ conflictActions: (n: number) => string;
89
+ /** A conflict button's accessible name: the button text plus which conflict. */
90
+ forConflict: (text: string, n: number) => string;
91
+ /** Button: take our side. */
92
+ acceptOurs: string;
93
+ /** Button: take their side. */
94
+ acceptTheirs: string;
95
+ /** Button: both sides, ours first. */
96
+ acceptOursTheirs: string;
97
+ /** Button: both sides, theirs first. */
98
+ acceptTheirsOurs: string;
99
+ /** Button: take the base. */
100
+ acceptBase: string;
101
+ /** Button: edit the resolution. */
102
+ edit: string;
103
+ /** Button: undo the resolution. */
104
+ reset: string;
105
+ /** Button: apply the edit. */
106
+ apply: string;
107
+ /** Button text: cancel the edit. */
108
+ cancel: string;
109
+ /** Accessible name prefix of the cancel-edit button. */
110
+ cancelEdit: string;
111
+ /** Label of the edit text area. */
112
+ customResolution: (n: number) => string;
113
+ /** "resolved with ___": our side. */
114
+ choiceOurs: string;
115
+ /** "resolved with ___": their side. */
116
+ choiceTheirs: string;
117
+ /** "resolved with ___": both, ours first. */
118
+ choiceOursTheirs: string;
119
+ /** "resolved with ___": both, theirs first. */
120
+ choiceTheirsOurs: string;
121
+ /** "resolved with ___": the base. */
122
+ choiceBase: string;
123
+ /** "resolved with ___": a custom edit. */
124
+ choiceCustom: string;
125
+ /** Hidden text beside a marker line of the result. */
126
+ conflictMarker: string;
127
+ /** Hidden text beside a line of the result that is an unresolved conflict. */
128
+ unresolvedConflict: string;
129
+ /** Hidden text beside a line of the result merged from a source (`both sides`, ours or theirs). */
130
+ mergedFrom: (source: string) => string;
131
+ /** "both sides", the source of a line changed on both. */
132
+ bothSides: string;
133
+ /** Hidden text beside a conflicting line of a side. */
134
+ srConflict: string;
135
+ /** Hidden text beside a changed line of a side. */
136
+ srChanged: string;
137
+ /** Row shown when the result is empty. */
138
+ resultEmpty: string;
139
+ /** Note after a last line that has no line ending. */
140
+ noNewline: string;
141
+ };
142
+ const plural = (n: number, one: string, many: string) => (n === 1 ? one : many);
143
+ const DEFAULTS: MergeViewLabels = {
144
+ base: 'Base',
145
+ ours: 'Ours',
146
+ theirs: 'Theirs',
147
+ result: 'Result',
148
+ merge: 'Merge',
149
+ mergeOf: (label, name) => `${label}: ${name}`,
150
+ versions: 'Versions',
151
+ versionsOf: (name) => `Versions of ${name}`,
152
+ merged: 'Merged result',
153
+ mergedOf: (name) => `Merged ${name}`,
154
+ versionsRegion: 'Base, ours and theirs',
155
+ mergePane: 'Merge pane',
156
+ lines: (n) => `${n} ${plural(n, 'line', 'lines')}`,
157
+ baseDescription: (name, lines) => `${name}: the common ancestor, ${lines}.`,
158
+ sideDescription: (name, lines) => `${name}: ${lines}. Lines marked changed were changed on this side only and are applied; lines marked conflict were changed on both sides.`,
159
+ deleteFile: 'Delete file',
160
+ previousConflict: 'Previous conflict',
161
+ nextConflict: 'Next conflict',
162
+ loadFailed: (error) => `Could not load the files: ${error}`,
163
+ retry: 'Retry',
164
+ help: 'Three-way merge. Press n or F7 for the next conflict, p or Shift and F7 for the previous one. Each conflict has buttons to accept one side, both sides, the base, or to edit the result.',
165
+ modifyDelete: 'Modify/delete conflict',
166
+ binaryFile: 'Binary file',
167
+ modifyDeleteNote: (deleted, modified) => `${deleted} deleted this file and ${modified.toLowerCase()} modified it. Keep the modified file or delete it.`,
168
+ binaryNote: 'This file cannot be merged as text. Keep one version or delete it.',
169
+ keepModified: 'Keep modified',
170
+ keep: (side) => `Keep ${side.toLowerCase()}`,
171
+ loading: 'Loading...',
172
+ willDelete: 'The file will be deleted',
173
+ keeping: (side) => `Keeping ${side.toLowerCase()}`,
174
+ modifiedAndDeleted: 'Modified and deleted: choose',
175
+ binaryChoose: 'Binary file: choose a version',
176
+ progress: (resolved, total) => `${resolved} of ${total} ${plural(total, 'conflict', 'conflicts')} resolved`,
177
+ noConflicts: 'No conflicts',
178
+ conflictState: (n, total, resolution) => `Conflict ${n} of ${total}: ${resolution ?? 'unresolved'}`,
179
+ resolvedWith: (choice) => `resolved with ${choice}`,
180
+ conflictFocus: (state, ours, theirs) => `${state}. ${ours}, ${theirs}.`,
181
+ sideHas: (side, lines) => `${side} has ${lines}`,
182
+ announceResolved: (n, choice) => `Conflict ${n} resolved with ${choice}.`,
183
+ announceReset: (n) => `Conflict ${n} reset.`,
184
+ announceProgress: (resolved, total) => `${resolved} of ${total} conflicts resolved.`,
185
+ announceAllResolved: (total) => `All ${total === 1 ? '1 conflict' : `${total} conflicts`} resolved.`,
186
+ conflictActions: (n) => `Actions for conflict ${n}`,
187
+ forConflict: (text, n) => `${text} (conflict ${n})`,
188
+ acceptOurs: 'Accept ours',
189
+ acceptTheirs: 'Accept theirs',
190
+ acceptOursTheirs: 'Accept both (ours then theirs)',
191
+ acceptTheirsOurs: 'Accept both (theirs then ours)',
192
+ acceptBase: 'Accept base',
193
+ edit: 'Edit',
194
+ reset: 'Reset',
195
+ apply: 'Apply',
196
+ cancel: 'Cancel',
197
+ cancelEdit: 'Cancel edit',
198
+ customResolution: (n) => `Custom resolution for conflict ${n}`,
199
+ choiceOurs: 'ours',
200
+ choiceTheirs: 'theirs',
201
+ choiceOursTheirs: 'both (ours then theirs)',
202
+ choiceTheirsOurs: 'both (theirs then ours)',
203
+ choiceBase: 'base',
204
+ choiceCustom: 'a custom edit',
205
+ conflictMarker: 'conflict marker',
206
+ unresolvedConflict: 'unresolved conflict',
207
+ mergedFrom: (source) => `merged from ${source}`,
208
+ bothSides: 'both sides',
209
+ srConflict: 'conflict',
210
+ srChanged: 'changed',
211
+ resultEmpty: 'The result is empty.',
212
+ noNewline: 'No newline at end of file'
213
+ };
214
+ </script>
215
+
1
216
  <script lang="ts">
217
+ import { useLabels } from './labels.js';
2
218
  import { csstext } from './cssvars.js';
3
219
  import SsrStyle from './SsrStyle.svelte';
4
220
  import { prepareMonacoCsp } from './monaco-csp.js';
@@ -46,7 +262,7 @@
46
262
  conflicts = $bindable(0),
47
263
  labels,
48
264
  highlight: syntax = true,
49
- label = 'Merge',
265
+ label,
50
266
  height,
51
267
  binary = false,
52
268
  deletable,
@@ -72,10 +288,11 @@
72
288
  result?: string;
73
289
  /** The number of conflicts between the two sides (output only). */
74
290
  conflicts?: number;
75
- /** Names for the three sides in the headings and the conflict markers. */
76
- labels?: MergeLabels;
291
+ /** Replaces the built-in texts (translation): the names of the three sides (also in the conflict markers), the buttons, the status and the screen-reader announcements. Missing keys keep the defaults. */
292
+ labels?: Partial<MergeViewLabels>;
77
293
  /** Colour the code (only when the language is known): with Monaco's tokenizers when a Monaco loader is registered, else with the small built-in highlighter. */
78
294
  highlight?: boolean;
295
+ /** Accessible name of the whole view. Wins over `labels.merge`. */
79
296
  label?: string;
80
297
  /**
81
298
  * How tall the view is. Unset keeps the default: the three panes scroll within 28rem and the result within 20rem.
@@ -124,8 +341,10 @@
124
341
 
125
342
  const uid = $props.id();
126
343
  const COLS: Col[] = ['base', 'ours', 'theirs'];
127
- const names = $derived({ base: labels?.base ?? 'Base', ours: labels?.ours ?? 'Ours', theirs: labels?.theirs ?? 'Theirs' });
128
- const CHOICE: Record<Choice, string> = { ours: 'ours', theirs: 'theirs', 'ours-theirs': 'both (ours then theirs)', 'theirs-ours': 'both (theirs then ours)', base: 'base', custom: 'a custom edit' };
344
+ const L = useLabels('MergeView', DEFAULTS, () => labels);
345
+ const names = $derived({ base: L.base, ours: L.ours, theirs: L.theirs });
346
+ const CHOICE = $derived<Record<Choice, string>>({ ours: L.choiceOurs, theirs: L.choiceTheirs, 'ours-theirs': L.choiceOursTheirs, 'theirs-ours': L.choiceTheirsOurs, base: L.choiceBase, custom: L.choiceCustom });
347
+ const stateText = (n: number, res: Resolution | undefined) => L.conflictState(n, total, res ? L.resolvedWith(CHOICE[res.choice]) : undefined);
129
348
 
130
349
  let root: HTMLDivElement;
131
350
  let theme = $state.raw<Theme>();
@@ -212,7 +431,7 @@
212
431
  untrack(() => { cur = -1; editing = null; announce = ''; });
213
432
  });
214
433
 
215
- const status = $derived(loading ? 'Loading...' : whole ? (deleted ? 'The file will be deleted' : pick ? `Keeping ${names[pick as 'ours' | 'theirs'].toLowerCase()}` : deletedSide ? 'Modified and deleted: choose' : 'Binary file: choose a version') : deleted ? 'The file will be deleted' : total ? `${out.resolved} of ${total} ${total === 1 ? 'conflict' : 'conflicts'} resolved` : 'No conflicts');
434
+ const status = $derived(loading ? L.loading : whole ? (deleted ? L.willDelete : pick ? L.keeping(names[pick as 'ours' | 'theirs']) : deletedSide ? L.modifiedAndDeleted : L.binaryChoose) : deleted ? L.willDelete : total ? L.progress(out.resolved, total) : L.noConflicts);
216
435
 
217
436
  function decide(c: number, res: Resolution | undefined) {
218
437
  const list = [...resolutions];
@@ -221,7 +440,7 @@
221
440
  cur = c;
222
441
  editing = null;
223
442
  const left = total - list.filter(Boolean).length;
224
- announce = `${res ? `Conflict ${c + 1} resolved with ${CHOICE[res.choice]}` : `Conflict ${c + 1} reset`}. ${left ? `${total - left} of ${total} conflicts resolved.` : `All ${total === 1 ? '1 conflict' : `${total} conflicts`} resolved.`}`;
443
+ announce = `${res ? L.announceResolved(c + 1, CHOICE[res.choice]) : L.announceReset(c + 1)} ${left ? L.announceProgress(total - left, total) : L.announceAllResolved(total)}`;
225
444
  }
226
445
 
227
446
  // ───── rows: the three documents side by side, aligned region by region
@@ -252,7 +471,7 @@
252
471
  const res = c >= 0 ? resolutions[c] : undefined;
253
472
  const open = r.kind === 'conflict' && !res;
254
473
  const sym = open ? '!' : res ? '✓' : r.kind === 'stable' ? '' : '~';
255
- const sr = p.marker ? 'conflict marker' : open ? 'unresolved conflict' : res ? `resolved with ${CHOICE[res.choice]}` : r.kind === 'stable' ? '' : `merged from ${r.kind === 'both' ? 'both sides' : r.kind}`;
474
+ const sr = p.marker ? L.conflictMarker : open ? L.unresolvedConflict : res ? L.resolvedWith(CHOICE[res.choice]) : r.kind === 'stable' ? '' : L.mergedFrom(r.kind === 'both' ? L.bothSides : r.kind === 'ours' ? L.choiceOurs : L.choiceTheirs);
256
475
  for (const line of splitDocument(p.text)) rows.push({ n: n++, line, region: p.region, c, sym, sr, marker: p.marker });
257
476
  }
258
477
  // the document ends without a line ending: the last line says so
@@ -260,11 +479,11 @@
260
479
  return rows;
261
480
  });
262
481
 
263
- const count = (ls: Line[]) => (ls.length === 1 ? '1 line' : `${ls.length} lines`);
482
+ const count = (ls: Line[]) => L.lines(ls.length);
264
483
  const desc = $derived({
265
- base: `${names.base}: the common ancestor, ${count(merge.docs.base)}.`,
266
- ours: `${names.ours}: ${count(merge.docs.ours)}. Lines marked changed were changed on this side only and are applied; lines marked conflict were changed on both sides.`,
267
- theirs: `${names.theirs}: ${count(merge.docs.theirs)}. Lines marked changed were changed on this side only and are applied; lines marked conflict were changed on both sides.`
484
+ base: L.baseDescription(names.base, count(merge.docs.base)),
485
+ ours: L.sideDescription(names.ours, count(merge.docs.ours)),
486
+ theirs: L.sideDescription(names.theirs, count(merge.docs.theirs))
268
487
  });
269
488
 
270
489
  // ───── syntax colours: each document is tokenized whole, then lines are looked up by their position
@@ -312,7 +531,7 @@
312
531
  cur = c;
313
532
  const r = merge.regions[confRegion[c]];
314
533
  const res = resolutions[c];
315
- announce = `Conflict ${c + 1} of ${total}: ${res ? `resolved with ${CHOICE[res.choice]}` : 'unresolved'}. ${names.ours} has ${count(r.ours)}, ${names.theirs} has ${count(r.theirs)}.`;
534
+ announce = L.conflictFocus(stateText(c + 1, res), L.sideHas(names.ours, count(r.ours)), L.sideHas(names.theirs, count(r.theirs)));
316
535
  if (narrow && tab === 'result') tab = 'ours';
317
536
  await tick();
318
537
  root.querySelector('[data-bar][data-active="true"]')?.scrollIntoView({ block: 'nearest' });
@@ -350,55 +569,55 @@
350
569
  }
351
570
 
352
571
  const ACTIONS: { choice: Choice; text: string }[] = [
353
- { choice: 'ours', text: 'Accept ours' },
354
- { choice: 'theirs', text: 'Accept theirs' },
355
- { choice: 'ours-theirs', text: 'Accept both (ours then theirs)' },
356
- { choice: 'theirs-ours', text: 'Accept both (theirs then ours)' },
357
- { choice: 'base', text: 'Accept base' }
572
+ { choice: 'ours', text: L.acceptOurs },
573
+ { choice: 'theirs', text: L.acceptTheirs },
574
+ { choice: 'ours-theirs', text: L.acceptOursTheirs },
575
+ { choice: 'theirs-ours', text: L.acceptTheirsOurs },
576
+ { choice: 'base', text: L.acceptBase }
358
577
  ];
359
- const TABS = [{ value: 'base', label: 'Base' }, { value: 'ours', label: 'Ours' }, { value: 'theirs', label: 'Theirs' }, { value: 'result', label: 'Result' }];
578
+ const TABS = $derived([{ value: 'base', label: L.base }, { value: 'ours', label: L.ours }, { value: 'theirs', label: L.theirs }, { value: 'result', label: L.result }]);
360
579
  const showTable = $derived(!narrow || tab !== 'result');
361
580
  const showResult = $derived(!narrow || tab === 'result');
362
581
  </script>
363
582
 
364
583
  <!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
365
584
  <SsrStyle {uid} rules={{ '': style }} />
366
- <div {...rest} bind:this={root} data-sv={uid} class={['mv', klass]} {@attach csstext(() => style)} role="group" aria-label={name ? `${label}: ${name}` : label} data-narrow={narrow} data-height={sizing} data-binary={binary || undefined} data-deleted={deletedSide} aria-busy={loading || undefined} onkeydown={onkey} aria-describedby="{uid}-help">
585
+ <div {...rest} bind:this={root} data-sv={uid} class={['mv', klass]} {@attach csstext(() => style)} role="group" aria-label={name ? L.mergeOf(label ?? L.merge, name) : (label ?? L.merge)} data-narrow={narrow} data-height={sizing} data-binary={binary || undefined} data-deleted={deletedSide} aria-busy={loading || undefined} onkeydown={onkey} aria-describedby="{uid}-help">
367
586
  <div class="bar">
368
587
  <span class="sum" role="status" data-testid="status" data-done={whole ? !!pick : deleted || (total > 0 && out.resolved === total)}>{status}</span>
369
588
  <span class="grow"></span>
370
589
  {#if canDelete && !whole}
371
- <Button variant="outlined" intent="danger" size="sm" pressed={deleted} data-testid="delete-file" onclick={() => choose('delete')}>Delete file</Button>
590
+ <Button variant="outlined" intent="danger" size="sm" pressed={deleted} data-testid="delete-file" onclick={() => choose('delete')}>{L.deleteFile}</Button>
372
591
  {/if}
373
- <Button variant="minimal" intent="neutral" size="sm" icon="chevron-up" aria-label="Previous conflict" shortcut="p" disabled={!total || whole} onclick={prev} />
374
- <Button variant="minimal" intent="neutral" size="sm" icon="chevron-down" aria-label="Next conflict" shortcut="n" disabled={!total || whole} onclick={next} />
592
+ <Button variant="minimal" intent="neutral" size="sm" icon="chevron-up" aria-label={L.previousConflict} shortcut="p" disabled={!total || whole} onclick={prev} />
593
+ <Button variant="minimal" intent="neutral" size="sm" icon="chevron-down" aria-label={L.nextConflict} shortcut="n" disabled={!total || whole} onclick={next} />
375
594
  </div>
376
595
  {#if loadError}
377
- <div class="load-err" role="alert" data-testid="load-error"><span>Could not load the files: {loadError}</span> <Button size="sm" variant="minimal" intent="neutral" data-testid="load-retry" onclick={() => attempt++}>Retry</Button></div>
596
+ <div class="load-err" role="alert" data-testid="load-error"><span>{L.loadFailed(loadError)}</span> <Button size="sm" variant="minimal" intent="neutral" data-testid="load-retry" onclick={() => attempt++}>{L.retry}</Button></div>
378
597
  {/if}
379
- <div class="vh" id="{uid}-help">Three-way merge. Press n or F7 for the next conflict, p or Shift and F7 for the previous one. Each conflict has buttons to accept one side, both sides, the base, or to edit the result.</div>
598
+ <div class="vh" id="{uid}-help">{L.help}</div>
380
599
  <div class="vh" role="status" aria-live="polite" data-testid="announce">{announce}</div>
381
600
  {#if whole}
382
- <div class="bin" role="group" aria-label={modified ? 'Modify/delete conflict' : 'Binary file'} data-testid={modified ? 'modify-delete' : 'binary'}>
383
- <p class="bin-note">{#if modified}{names[deletedSide!]} deleted this file and {names[modified].toLowerCase()} modified it. Keep the modified file or delete it.{:else}This file cannot be merged as text. Keep one version or delete it.{/if}</p>
601
+ <div class="bin" role="group" aria-label={modified ? L.modifyDelete : L.binaryFile} data-testid={modified ? 'modify-delete' : 'binary'}>
602
+ <p class="bin-note">{#if modified}{L.modifyDeleteNote(names[deletedSide!], names[modified])}{:else}{L.binaryNote}{/if}</p>
384
603
  <div class="acts">
385
604
  {#if modified}
386
- <Button size="sm" variant="outlined" intent="neutral" pressed={pick === modified} data-testid="keep-modified" onclick={() => choose(modified)}>Keep modified</Button>
605
+ <Button size="sm" variant="outlined" intent="neutral" pressed={pick === modified} data-testid="keep-modified" onclick={() => choose(modified)}>{L.keepModified}</Button>
387
606
  {:else}
388
- <Button size="sm" variant="outlined" intent="neutral" pressed={pick === 'ours'} data-testid="keep-ours" onclick={() => choose('ours')}>Keep {names.ours.toLowerCase()}</Button>
389
- <Button size="sm" variant="outlined" intent="neutral" pressed={pick === 'theirs'} data-testid="keep-theirs" onclick={() => choose('theirs')}>Keep {names.theirs.toLowerCase()}</Button>
607
+ <Button size="sm" variant="outlined" intent="neutral" pressed={pick === 'ours'} data-testid="keep-ours" onclick={() => choose('ours')}>{L.keep(names.ours)}</Button>
608
+ <Button size="sm" variant="outlined" intent="neutral" pressed={pick === 'theirs'} data-testid="keep-theirs" onclick={() => choose('theirs')}>{L.keep(names.theirs)}</Button>
390
609
  {/if}
391
- {#if canDelete}<Button size="sm" variant="outlined" intent="danger" pressed={pick === 'delete'} data-testid="delete-file" onclick={() => choose('delete')}>Delete file</Button>{/if}
610
+ {#if canDelete}<Button size="sm" variant="outlined" intent="danger" pressed={pick === 'delete'} data-testid="delete-file" onclick={() => choose('delete')}>{L.deleteFile}</Button>{/if}
392
611
  </div>
393
612
  </div>
394
613
  {:else if narrow}
395
- <div class="tabs"><SegmentedControl size="sm" label="Merge pane" value={tab} onchange={(v) => (tab = v as Tab)} options={TABS} /></div>
614
+ <div class="tabs"><SegmentedControl size="sm" label={L.mergePane} value={tab} onchange={(v) => (tab = v as Tab)} options={TABS} /></div>
396
615
  {/if}
397
616
 
398
617
  {#if showTable && !whole}
399
618
  <!-- svelte-ignore a11y_no_noninteractive_tabindex -->
400
- <div class="scroll" role="region" aria-label="Base, ours and theirs" tabindex="0">
401
- <table class="tbl" data-show={narrow ? tab : 'all'} aria-label={name ? `Versions of ${name}` : 'Versions'}>
619
+ <div class="scroll" role="region" aria-label={L.versionsRegion} tabindex="0">
620
+ <table class="tbl" data-show={narrow ? tab : 'all'} aria-label={name ? L.versionsOf(name) : L.versions}>
402
621
  <colgroup>
403
622
  {#each COLS as col}<col class="c-no" data-col={col} /><col class="c-sym" data-col={col} /><col class="c-code" data-col={col} />{/each}
404
623
  </colgroup>
@@ -416,22 +635,22 @@
416
635
  <tr class="hunk" data-bar data-conflict={e.c + 1} data-active={cur === e.c} data-resolved={!!res}>
417
636
  <td colspan="9">
418
637
  <div class="head">
419
- <span class="tag" data-testid="hunk-state"><span aria-hidden="true">{res ? '✓' : '⚠'}</span> Conflict {e.c + 1} of {total}: {res ? `resolved with ${CHOICE[res.choice]}` : 'unresolved'}</span>
420
- <span class="acts" role="group" aria-label="Actions for conflict {e.c + 1}">
638
+ <span class="tag" data-testid="hunk-state"><span aria-hidden="true">{res ? '✓' : '⚠'}</span> {stateText(e.c + 1, res)}</span>
639
+ <span class="acts" role="group" aria-label={L.conflictActions(e.c + 1)}>
421
640
  {#each ACTIONS as a}
422
- <Button size="sm" variant="outlined" intent="neutral" pressed={res?.choice === a.choice} aria-label="{a.text} (conflict {e.c + 1})" onclick={() => decide(e.c, { choice: a.choice })}>{a.text}</Button>
641
+ <Button size="sm" variant="outlined" intent="neutral" pressed={res?.choice === a.choice} aria-label={L.forConflict(a.text, e.c + 1)} onclick={() => decide(e.c, { choice: a.choice })}>{a.text}</Button>
423
642
  {/each}
424
- <Button size="sm" variant="outlined" intent="neutral" pressed={res?.choice === 'custom'} aria-label="Edit (conflict {e.c + 1})" data-edit-btn={e.c} onclick={() => edit(e.c)}>Edit</Button>
425
- {#if res}<Button size="sm" variant="minimal" intent="neutral" aria-label="Reset (conflict {e.c + 1})" onclick={() => decide(e.c, undefined)}>Reset</Button>{/if}
643
+ <Button size="sm" variant="outlined" intent="neutral" pressed={res?.choice === 'custom'} aria-label={L.forConflict(L.edit, e.c + 1)} data-edit-btn={e.c} onclick={() => edit(e.c)}>{L.edit}</Button>
644
+ {#if res}<Button size="sm" variant="minimal" intent="neutral" aria-label={L.forConflict(L.reset, e.c + 1)} onclick={() => decide(e.c, undefined)}>{L.reset}</Button>{/if}
426
645
  </span>
427
646
  </div>
428
647
  {#if editing === e.c}
429
648
  <!-- svelte-ignore a11y_no_static_element_interactions -->
430
649
  <div class="editor" onkeydown={editKey}>
431
- <Textarea id="{uid}-edit" label="Custom resolution for conflict {e.c + 1}" bind:value={draft} rows={Math.min(12, Math.max(3, draft.split('\n').length))} spellcheck="false" />
650
+ <Textarea id="{uid}-edit" label={L.customResolution(e.c + 1)} bind:value={draft} rows={Math.min(12, Math.max(3, draft.split('\n').length))} spellcheck="false" />
432
651
  <div class="acts">
433
- <Button size="sm" variant="filled" aria-label="Apply (conflict {e.c + 1})" onclick={() => apply(e.c)}>Apply</Button>
434
- <Button size="sm" variant="minimal" intent="neutral" aria-label="Cancel edit (conflict {e.c + 1})" onclick={() => { editing = null; }}>Cancel</Button>
652
+ <Button size="sm" variant="filled" aria-label={L.forConflict(L.apply, e.c + 1)} onclick={() => apply(e.c)}>{L.apply}</Button>
653
+ <Button size="sm" variant="minimal" intent="neutral" aria-label={L.forConflict(L.cancelEdit, e.c + 1)} onclick={() => { editing = null; }}>{L.cancel}</Button>
435
654
  </div>
436
655
  </div>
437
656
  {/if}
@@ -452,9 +671,9 @@
452
671
 
453
672
  {#if showResult && !whole}
454
673
  <!-- svelte-ignore a11y_no_noninteractive_tabindex -->
455
- <div class="result" role="region" aria-label="Result" tabindex="0">
456
- <div class="rhead" aria-hidden="true">Result</div>
457
- <table class="tbl res" aria-label={name ? `Merged ${name}` : 'Merged result'}>
674
+ <div class="result" role="region" aria-label={L.result} tabindex="0">
675
+ <div class="rhead" aria-hidden="true">{L.result}</div>
676
+ <table class="tbl res" aria-label={name ? L.mergedOf(name) : L.merged}>
458
677
  <colgroup><col class="c-no" /><col class="c-sym" /><col class="c-code" /></colgroup>
459
678
  <tbody>
460
679
  {#each resultRows as r (r.n)}
@@ -464,7 +683,7 @@
464
683
  <td class="code">{@render code(segsResult(r.n, r.line), r.line)}</td>
465
684
  </tr>
466
685
  {:else}
467
- <tr class="row"><td class="empty" colspan="3">The result is empty.</td></tr>
686
+ <tr class="row"><td class="empty" colspan="3">{L.resultEmpty}</td></tr>
468
687
  {/each}
469
688
  </tbody>
470
689
  </table>
@@ -475,7 +694,7 @@
475
694
  {#snippet pane(cell: Cell, col: Col)}
476
695
  {#if cell}
477
696
  <td class="no" data-col={col} data-s={cell.sym}>{cell.n + 1}</td>
478
- <td class="sym" data-col={col} data-s={cell.sym}>{#if cell.sym}<span aria-hidden="true">{cell.sym}</span><span class="vh">{cell.sym === '!' ? 'conflict' : 'changed'}: </span>{/if}</td>
697
+ <td class="sym" data-col={col} data-s={cell.sym}>{#if cell.sym}<span aria-hidden="true">{cell.sym}</span><span class="vh">{cell.sym === '!' ? L.srConflict : L.srChanged}: </span>{/if}</td>
479
698
  <td class="code" data-col={col} data-s={cell.sym}>{@render code(segs(col, cell.n, cell.line), cell.line)}</td>
480
699
  {:else}
481
700
  <td class="no filler" data-col={col}></td><td class="sym filler" data-col={col}></td><td class="code filler" data-col={col}></td>
@@ -483,7 +702,7 @@
483
702
  {/snippet}
484
703
 
485
704
  {#snippet code(parts: Seg[], line: Line)}
486
- {#each parts as p}{#if p.role}<span class="s-{p.role}">{p.text}</span>{:else}{p.text}{/if}{/each}{#if line.noEol}<span class="eof">&#8629; No newline at end of file</span>{/if}
705
+ {#each parts as p}{#if p.role}<span class="s-{p.role}">{p.text}</span>{:else}{p.text}{/if}{/each}{#if line.noEol}<span class="eof">&#8629; {L.noNewline}</span>{/if}
487
706
  {/snippet}
488
707
 
489
708
  <style>
@@ -1,5 +1,145 @@
1
+ export type MergeViewLabels = {
2
+ /** Name of the base (common ancestor) side: heading, announcements and the `|||||||` conflict marker. */
3
+ base: string;
4
+ /** Name of the "ours" side: heading, announcements and the `<<<<<<<` conflict marker. */
5
+ ours: string;
6
+ /** Name of the "theirs" side: heading, announcements and the `>>>>>>>` conflict marker. */
7
+ theirs: string;
8
+ /** Heading of the merged result, and the name of its tab and region. */
9
+ result: string;
10
+ /** Accessible name of the whole view when no `label` is given. */
11
+ merge: string;
12
+ /** Name of the whole view when it has a file `name`: `label: name`. */
13
+ mergeOf: (label: string, name: string) => string;
14
+ /** Accessible name of the table of the three versions. */
15
+ versions: string;
16
+ /** Same, when the view has a file `name`. */
17
+ versionsOf: (name: string) => string;
18
+ /** Accessible name of the table of the merged result. */
19
+ merged: string;
20
+ /** Same, when the view has a file `name`. */
21
+ mergedOf: (name: string) => string;
22
+ /** Accessible name of the scrolling region of the three versions. */
23
+ versionsRegion: string;
24
+ /** Label of the pane switcher in a narrow view. */
25
+ mergePane: string;
26
+ /** Number of lines: "1 line", "3 lines". */
27
+ lines: (n: number) => string;
28
+ /** Hidden description of the base column. */
29
+ baseDescription: (name: string, lines: string) => string;
30
+ /** Hidden description of the ours / theirs column. */
31
+ sideDescription: (name: string, lines: string) => string;
32
+ /** Button that deletes the file (modify/delete or binary conflicts and the toolbar). */
33
+ deleteFile: string;
34
+ /** Accessible name of the previous-conflict button. */
35
+ previousConflict: string;
36
+ /** Accessible name of the next-conflict button. */
37
+ nextConflict: string;
38
+ /** Message when the files could not be loaded; `error` is the reason. */
39
+ loadFailed: (error: string) => string;
40
+ /** Retry button after a load failure. */
41
+ retry: string;
42
+ /** Hidden keyboard help of the view. */
43
+ help: string;
44
+ /** Name of the group shown for a modify/delete conflict. */
45
+ modifyDelete: string;
46
+ /** Name of the group shown for a binary file. */
47
+ binaryFile: string;
48
+ /** Note of a modify/delete conflict: which side deleted the file and which modified it (side names as given). */
49
+ modifyDeleteNote: (deleted: string, modified: string) => string;
50
+ /** Note of a binary file. */
51
+ binaryNote: string;
52
+ /** Button that keeps the modified file. */
53
+ keepModified: string;
54
+ /** Button that keeps one side of a binary file (the side's name as given). */
55
+ keep: (side: string) => string;
56
+ /** Status line while the files load. */
57
+ loading: string;
58
+ /** Status line: the file will be deleted. */
59
+ willDelete: string;
60
+ /** Status line: a side of a binary file was picked. */
61
+ keeping: (side: string) => string;
62
+ /** Status line: modified on one side, deleted on the other, nothing chosen yet. */
63
+ modifiedAndDeleted: string;
64
+ /** Status line: binary file, nothing chosen yet. */
65
+ binaryChoose: string;
66
+ /** Status line: how many conflicts are resolved. */
67
+ progress: (resolved: number, total: number) => string;
68
+ /** Status line without conflicts. */
69
+ noConflicts: string;
70
+ /** The state line of a conflict, e.g. "Conflict 1 of 3: unresolved". `resolution` is the `resolvedWith` text, absent when unresolved. */
71
+ conflictState: (n: number, total: number, resolution: string | undefined) => string;
72
+ /** "resolved with ours": `choice` is one of the `choice*` texts. */
73
+ resolvedWith: (choice: string) => string;
74
+ /** Announcement when jumping to a conflict: `state` is the `conflictState` text, `ours` and `theirs` the `sideHas` texts. */
75
+ conflictFocus: (state: string, ours: string, theirs: string) => string;
76
+ /** "Ours has 3 lines". */
77
+ sideHas: (side: string, lines: string) => string;
78
+ /** Announcement after resolving a conflict. */
79
+ announceResolved: (n: number, choice: string) => string;
80
+ /** Announcement after resetting a conflict. */
81
+ announceReset: (n: number) => string;
82
+ /** Announcement tail while conflicts remain. */
83
+ announceProgress: (resolved: number, total: number) => string;
84
+ /** Announcement tail when the last conflict is done. */
85
+ announceAllResolved: (total: number) => string;
86
+ /** Name of a conflict's action group. */
87
+ conflictActions: (n: number) => string;
88
+ /** A conflict button's accessible name: the button text plus which conflict. */
89
+ forConflict: (text: string, n: number) => string;
90
+ /** Button: take our side. */
91
+ acceptOurs: string;
92
+ /** Button: take their side. */
93
+ acceptTheirs: string;
94
+ /** Button: both sides, ours first. */
95
+ acceptOursTheirs: string;
96
+ /** Button: both sides, theirs first. */
97
+ acceptTheirsOurs: string;
98
+ /** Button: take the base. */
99
+ acceptBase: string;
100
+ /** Button: edit the resolution. */
101
+ edit: string;
102
+ /** Button: undo the resolution. */
103
+ reset: string;
104
+ /** Button: apply the edit. */
105
+ apply: string;
106
+ /** Button text: cancel the edit. */
107
+ cancel: string;
108
+ /** Accessible name prefix of the cancel-edit button. */
109
+ cancelEdit: string;
110
+ /** Label of the edit text area. */
111
+ customResolution: (n: number) => string;
112
+ /** "resolved with ___": our side. */
113
+ choiceOurs: string;
114
+ /** "resolved with ___": their side. */
115
+ choiceTheirs: string;
116
+ /** "resolved with ___": both, ours first. */
117
+ choiceOursTheirs: string;
118
+ /** "resolved with ___": both, theirs first. */
119
+ choiceTheirsOurs: string;
120
+ /** "resolved with ___": the base. */
121
+ choiceBase: string;
122
+ /** "resolved with ___": a custom edit. */
123
+ choiceCustom: string;
124
+ /** Hidden text beside a marker line of the result. */
125
+ conflictMarker: string;
126
+ /** Hidden text beside a line of the result that is an unresolved conflict. */
127
+ unresolvedConflict: string;
128
+ /** Hidden text beside a line of the result merged from a source (`both sides`, ours or theirs). */
129
+ mergedFrom: (source: string) => string;
130
+ /** "both sides", the source of a line changed on both. */
131
+ bothSides: string;
132
+ /** Hidden text beside a conflicting line of a side. */
133
+ srConflict: string;
134
+ /** Hidden text beside a changed line of a side. */
135
+ srChanged: string;
136
+ /** Row shown when the result is empty. */
137
+ resultEmpty: string;
138
+ /** Note after a last line that has no line ending. */
139
+ noNewline: string;
140
+ };
1
141
  import type { ClassValue } from 'svelte/elements';
2
- import { type FileResolution, type MergeLabels } from './merge.js';
142
+ import { type FileResolution } from './merge.js';
3
143
  /** What `onresolve` receives. */
4
144
  export interface MergeState {
5
145
  /** The merged text; unresolved conflicts are written as `diff3` conflict blocks. */
@@ -31,10 +171,11 @@ type $$ComponentProps = {
31
171
  result?: string;
32
172
  /** The number of conflicts between the two sides (output only). */
33
173
  conflicts?: number;
34
- /** Names for the three sides in the headings and the conflict markers. */
35
- labels?: MergeLabels;
174
+ /** Replaces the built-in texts (translation): the names of the three sides (also in the conflict markers), the buttons, the status and the screen-reader announcements. Missing keys keep the defaults. */
175
+ labels?: Partial<MergeViewLabels>;
36
176
  /** Colour the code (only when the language is known): with Monaco's tokenizers when a Monaco loader is registered, else with the small built-in highlighter. */
37
177
  highlight?: boolean;
178
+ /** Accessible name of the whole view. Wins over `labels.merge`. */
38
179
  label?: string;
39
180
  /**
40
181
  * How tall the view is. Unset keeps the default: the three panes scroll within 28rem and the result within 20rem.