@ruckc/truss-code 1.21.0 → 1.23.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.
- package/dist/MergeView.svelte +44 -20
- package/dist/MergeView.svelte.d.ts +14 -2
- package/package.json +1 -1
package/dist/MergeView.svelte
CHANGED
|
@@ -44,7 +44,8 @@
|
|
|
44
44
|
label = 'Merge',
|
|
45
45
|
height,
|
|
46
46
|
binary = false,
|
|
47
|
-
deletable
|
|
47
|
+
deletable,
|
|
48
|
+
deleted: deletedSide,
|
|
48
49
|
load,
|
|
49
50
|
loadAll,
|
|
50
51
|
onresolve,
|
|
@@ -73,7 +74,7 @@
|
|
|
73
74
|
label?: string;
|
|
74
75
|
/**
|
|
75
76
|
* How tall the view is. Unset keeps the default: the three panes scroll within 28rem and the result within 20rem.
|
|
76
|
-
* `'auto'` grows with the content and the page scrolls. `'fill'` takes the height of the parent (which needs one), splitting it between the
|
|
77
|
+
* `'auto'` grows with the content and the page scrolls (it sets `flex-shrink: 0`, so it is not squeezed inside a flex column whose children can shrink; the parent must scroll or grow). `'fill'` takes the height of the parent (which needs one), splitting it between the
|
|
77
78
|
* panes and the result, each scrolling inside. Any CSS length (`'32rem'`) or number of pixels does the same with a fixed height.
|
|
78
79
|
*/
|
|
79
80
|
height?: 'auto' | 'fill' | (string & {}) | number;
|
|
@@ -83,7 +84,19 @@
|
|
|
83
84
|
* `base`, `ours` and `theirs` are not shown, but a change to them starts the decision afresh; `load` is not called.
|
|
84
85
|
*/
|
|
85
86
|
binary?: boolean;
|
|
86
|
-
/**
|
|
87
|
+
/**
|
|
88
|
+
* A modify/delete conflict: which side deleted the file (`'ours'` or `'theirs'`); the other side modified it. No diff is drawn (a deleted side
|
|
89
|
+
* would only be an empty column in a diff3 block); the view is one unresolved conflict with the buttons "Keep modified" (`onresolve`
|
|
90
|
+
* reports `resolution` `{ kind: 'keep', side }` with the modifying side) and "Delete file" (`{ kind: 'delete' }`), as in `binary` mode, which it also
|
|
91
|
+
* works with. Like `binary`, `base`, `ours` and `theirs` are not shown, `load` is not called, and a change to them starts the decision afresh.
|
|
92
|
+
* Pass the flag instead of an empty string for the missing side: a deleted file is not an empty file.
|
|
93
|
+
*/
|
|
94
|
+
deleted?: 'ours' | 'theirs';
|
|
95
|
+
/**
|
|
96
|
+
* Offer "Delete file". Defaults to on in `binary` and `deleted` mode and off for a text merge; for a text merge it is for a modify/delete conflict you
|
|
97
|
+
* cannot express with `deleted`. While chosen, `onresolve` reports `resolution` `{ kind: 'delete' }` and `allResolved: true`.
|
|
98
|
+
* `false` hides it in every mode (when the file must be kept).
|
|
99
|
+
*/
|
|
87
100
|
deletable?: boolean;
|
|
88
101
|
/**
|
|
89
102
|
* Fetches the whole text of a side you did not pass as a prop, e.g. when the app only has conflict regions and assembles
|
|
@@ -133,7 +146,7 @@
|
|
|
133
146
|
void attempt;
|
|
134
147
|
const given = { base: baseProp, ours: oursProp, theirs: theirsProp };
|
|
135
148
|
const sides = COLS.filter((c) => given[c] === undefined);
|
|
136
|
-
const fetching = !
|
|
149
|
+
const fetching = !whole && (!!fetch || !!fetchAll) && sides.length > 0;
|
|
137
150
|
untrack(() => { loading = fetching; loadError = undefined; });
|
|
138
151
|
if (!fetching) return;
|
|
139
152
|
let stale = false;
|
|
@@ -166,9 +179,14 @@
|
|
|
166
179
|
// the decision about the file as a whole: delete it (a text merge with `deletable`, or a binary file), or keep one side of a binary file
|
|
167
180
|
let fileChoice = $state.raw<{ merge: Merge; pick: 'ours' | 'theirs' | 'delete' } | undefined>();
|
|
168
181
|
const pick = $derived(fileChoice?.merge === merge ? fileChoice.pick : undefined);
|
|
169
|
-
|
|
182
|
+
/** The file is decided as a whole (no diff): a binary file, or a modify/delete conflict. */
|
|
183
|
+
const whole = $derived(binary || !!deletedSide);
|
|
184
|
+
/** The side that modified the file in a modify/delete conflict. */
|
|
185
|
+
const modified = $derived<'ours' | 'theirs' | undefined>(deletedSide === 'ours' ? 'theirs' : deletedSide ? 'ours' : undefined);
|
|
186
|
+
const canDelete = $derived(whole ? deletable !== false : deletable === true);
|
|
187
|
+
const deleted = $derived(pick === 'delete' && canDelete);
|
|
170
188
|
const shown = $derived<MergeState>(
|
|
171
|
-
|
|
189
|
+
whole
|
|
172
190
|
? { result: '', resolved: pick ? 1 : 0, conflicts: 1, allResolved: !!pick, resolution: pick === 'delete' ? { kind: 'delete' } : pick ? { kind: 'keep', side: pick } : undefined }
|
|
173
191
|
: { result: out.text, resolved: out.resolved, conflicts: out.conflicts, allResolved: deleted || out.resolved === out.conflicts, resolution: deleted ? { kind: 'delete' } : { kind: 'text', text: out.text } }
|
|
174
192
|
);
|
|
@@ -189,7 +207,7 @@
|
|
|
189
207
|
untrack(() => { cur = -1; editing = null; announce = ''; });
|
|
190
208
|
});
|
|
191
209
|
|
|
192
|
-
const status = $derived(loading ? 'Loading...' :
|
|
210
|
+
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');
|
|
193
211
|
|
|
194
212
|
function decide(c: number, res: Resolution | undefined) {
|
|
195
213
|
const list = [...resolutions];
|
|
@@ -339,35 +357,39 @@
|
|
|
339
357
|
</script>
|
|
340
358
|
|
|
341
359
|
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
|
342
|
-
<div {...rest} bind:this={root} class={['mv', klass]} {style} role="group" aria-label={name ? `${label}: ${name}` : label} data-narrow={narrow} data-height={sizing} data-binary={binary || undefined} aria-busy={loading || undefined} onkeydown={onkey} aria-describedby="{uid}-help">
|
|
360
|
+
<div {...rest} bind:this={root} class={['mv', klass]} {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">
|
|
343
361
|
<div class="bar">
|
|
344
|
-
<span class="sum" role="status" data-testid="status" data-done={
|
|
362
|
+
<span class="sum" role="status" data-testid="status" data-done={whole ? !!pick : deleted || (total > 0 && out.resolved === total)}>{status}</span>
|
|
345
363
|
<span class="grow"></span>
|
|
346
|
-
{#if
|
|
364
|
+
{#if canDelete && !whole}
|
|
347
365
|
<Button variant="outlined" intent="danger" size="sm" pressed={deleted} data-testid="delete-file" onclick={() => choose('delete')}>Delete file</Button>
|
|
348
366
|
{/if}
|
|
349
|
-
<Button variant="minimal" intent="neutral" size="sm" icon="chevron-up" aria-label="Previous conflict" shortcut="p" disabled={!total ||
|
|
350
|
-
<Button variant="minimal" intent="neutral" size="sm" icon="chevron-down" aria-label="Next conflict" shortcut="n" disabled={!total ||
|
|
367
|
+
<Button variant="minimal" intent="neutral" size="sm" icon="chevron-up" aria-label="Previous conflict" shortcut="p" disabled={!total || whole} onclick={prev} />
|
|
368
|
+
<Button variant="minimal" intent="neutral" size="sm" icon="chevron-down" aria-label="Next conflict" shortcut="n" disabled={!total || whole} onclick={next} />
|
|
351
369
|
</div>
|
|
352
370
|
{#if loadError}
|
|
353
371
|
<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>
|
|
354
372
|
{/if}
|
|
355
373
|
<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>
|
|
356
374
|
<div class="vh" role="status" aria-live="polite" data-testid="announce">{announce}</div>
|
|
357
|
-
{#if
|
|
358
|
-
<div class="bin" role="group" aria-label=
|
|
359
|
-
<p class="bin-note">This file cannot be merged as text. Keep one version or delete it
|
|
375
|
+
{#if whole}
|
|
376
|
+
<div class="bin" role="group" aria-label={modified ? 'Modify/delete conflict' : 'Binary file'} data-testid={modified ? 'modify-delete' : 'binary'}>
|
|
377
|
+
<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>
|
|
360
378
|
<div class="acts">
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
379
|
+
{#if modified}
|
|
380
|
+
<Button size="sm" variant="outlined" intent="neutral" pressed={pick === modified} data-testid="keep-modified" onclick={() => choose(modified)}>Keep modified</Button>
|
|
381
|
+
{:else}
|
|
382
|
+
<Button size="sm" variant="outlined" intent="neutral" pressed={pick === 'ours'} data-testid="keep-ours" onclick={() => choose('ours')}>Keep {names.ours.toLowerCase()}</Button>
|
|
383
|
+
<Button size="sm" variant="outlined" intent="neutral" pressed={pick === 'theirs'} data-testid="keep-theirs" onclick={() => choose('theirs')}>Keep {names.theirs.toLowerCase()}</Button>
|
|
384
|
+
{/if}
|
|
385
|
+
{#if canDelete}<Button size="sm" variant="outlined" intent="danger" pressed={pick === 'delete'} data-testid="delete-file" onclick={() => choose('delete')}>Delete file</Button>{/if}
|
|
364
386
|
</div>
|
|
365
387
|
</div>
|
|
366
388
|
{:else if narrow}
|
|
367
389
|
<div class="tabs"><SegmentedControl size="sm" label="Merge pane" value={tab} onchange={(v) => (tab = v as Tab)} options={TABS} /></div>
|
|
368
390
|
{/if}
|
|
369
391
|
|
|
370
|
-
{#if showTable && !
|
|
392
|
+
{#if showTable && !whole}
|
|
371
393
|
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
|
372
394
|
<div class="scroll" role="region" aria-label="Base, ours and theirs" tabindex="0">
|
|
373
395
|
<table class="tbl" data-show={narrow ? tab : 'all'} aria-label={name ? `Versions of ${name}` : 'Versions'}>
|
|
@@ -422,7 +444,7 @@
|
|
|
422
444
|
</div>
|
|
423
445
|
{/if}
|
|
424
446
|
|
|
425
|
-
{#if showResult && !
|
|
447
|
+
{#if showResult && !whole}
|
|
426
448
|
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
|
427
449
|
<div class="result" role="region" aria-label="Result" tabindex="0">
|
|
428
450
|
<div class="rhead" aria-hidden="true">Result</div>
|
|
@@ -476,6 +498,8 @@
|
|
|
476
498
|
.bin { display: grid; gap: var(--tr-space-2); padding: var(--tr-space-3); font-family: var(--tr-font-sans); }
|
|
477
499
|
.bin-note { margin: 0; color: var(--tr-on-surface-variant); }
|
|
478
500
|
/* height: `auto` lets the page scroll; `fill` and a length make the view a column whose panes scroll inside it */
|
|
501
|
+
/* `auto` must not shrink: in a flex column whose children can shrink (a Panel with `overflow: hidden`) the view would be cut off */
|
|
502
|
+
.mv[data-height='auto'] { flex-shrink: 0; }
|
|
479
503
|
.mv[data-height='auto'] .scroll, .mv[data-height='auto'] .result { max-height: none; }
|
|
480
504
|
.mv[data-height='fill'], .mv[data-height='fixed'] { display: flex; flex-direction: column; min-height: 0; }
|
|
481
505
|
.mv[data-height='fill'] { height: 100%; }
|
|
@@ -38,7 +38,7 @@ type $$ComponentProps = {
|
|
|
38
38
|
label?: string;
|
|
39
39
|
/**
|
|
40
40
|
* How tall the view is. Unset keeps the default: the three panes scroll within 28rem and the result within 20rem.
|
|
41
|
-
* `'auto'` grows with the content and the page scrolls. `'fill'` takes the height of the parent (which needs one), splitting it between the
|
|
41
|
+
* `'auto'` grows with the content and the page scrolls (it sets `flex-shrink: 0`, so it is not squeezed inside a flex column whose children can shrink; the parent must scroll or grow). `'fill'` takes the height of the parent (which needs one), splitting it between the
|
|
42
42
|
* panes and the result, each scrolling inside. Any CSS length (`'32rem'`) or number of pixels does the same with a fixed height.
|
|
43
43
|
*/
|
|
44
44
|
height?: 'auto' | 'fill' | (string & {}) | number;
|
|
@@ -48,7 +48,19 @@ type $$ComponentProps = {
|
|
|
48
48
|
* `base`, `ours` and `theirs` are not shown, but a change to them starts the decision afresh; `load` is not called.
|
|
49
49
|
*/
|
|
50
50
|
binary?: boolean;
|
|
51
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* A modify/delete conflict: which side deleted the file (`'ours'` or `'theirs'`); the other side modified it. No diff is drawn (a deleted side
|
|
53
|
+
* would only be an empty column in a diff3 block); the view is one unresolved conflict with the buttons "Keep modified" (`onresolve`
|
|
54
|
+
* reports `resolution` `{ kind: 'keep', side }` with the modifying side) and "Delete file" (`{ kind: 'delete' }`), as in `binary` mode, which it also
|
|
55
|
+
* works with. Like `binary`, `base`, `ours` and `theirs` are not shown, `load` is not called, and a change to them starts the decision afresh.
|
|
56
|
+
* Pass the flag instead of an empty string for the missing side: a deleted file is not an empty file.
|
|
57
|
+
*/
|
|
58
|
+
deleted?: 'ours' | 'theirs';
|
|
59
|
+
/**
|
|
60
|
+
* Offer "Delete file". Defaults to on in `binary` and `deleted` mode and off for a text merge; for a text merge it is for a modify/delete conflict you
|
|
61
|
+
* cannot express with `deleted`. While chosen, `onresolve` reports `resolution` `{ kind: 'delete' }` and `allResolved: true`.
|
|
62
|
+
* `false` hides it in every mode (when the file must be kept).
|
|
63
|
+
*/
|
|
52
64
|
deletable?: boolean;
|
|
53
65
|
/**
|
|
54
66
|
* Fetches the whole text of a side you did not pass as a prop, e.g. when the app only has conflict regions and assembles
|
package/package.json
CHANGED