@ruckc/truss-code 1.20.1 → 1.21.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/CodeBlock.svelte +54 -3
- package/dist/CodeBlock.svelte.d.ts +14 -1
- package/dist/DiffView.svelte +3 -3
- package/dist/MergeView.svelte +93 -19
- package/dist/MergeView.svelte.d.ts +35 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/lite.d.ts +3 -1
- package/dist/lite.js +2 -0
- package/dist/merge.d.ts +13 -0
- package/package.json +1 -1
package/dist/CodeBlock.svelte
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { onMount } from 'svelte';
|
|
3
|
+
import type { ClassValue } from 'svelte/elements';
|
|
3
4
|
import { highlightText } from './syntax.js';
|
|
4
5
|
import { segmentLine, splitLines, paletteVars, type Seg } from './highlight.js';
|
|
5
6
|
import { resolveLanguage, modelLanguage, type SqlDialect } from './lang.js';
|
|
@@ -13,7 +14,13 @@
|
|
|
13
14
|
lineNumbers = false,
|
|
14
15
|
wrap = false,
|
|
15
16
|
label = 'Code',
|
|
16
|
-
maxHeight
|
|
17
|
+
maxHeight,
|
|
18
|
+
maxLines,
|
|
19
|
+
height,
|
|
20
|
+
follow = $bindable(false),
|
|
21
|
+
class: klass,
|
|
22
|
+
style: userStyle,
|
|
23
|
+
...rest
|
|
17
24
|
}: {
|
|
18
25
|
/** The text to show. */
|
|
19
26
|
code: string;
|
|
@@ -29,6 +36,18 @@
|
|
|
29
36
|
label?: string;
|
|
30
37
|
/** A CSS length; the block scrolls beyond it. */
|
|
31
38
|
maxHeight?: string | number;
|
|
39
|
+
/** Show at most this many lines, then scroll: a compact block whose height follows the line height of the theme (the lines wrap with `wrap`, so each may take several rows). */
|
|
40
|
+
maxLines?: number;
|
|
41
|
+
/** A fixed CSS length (or pixels): the block is exactly this tall and scrolls. Wins over `maxHeight` and `maxLines`. */
|
|
42
|
+
height?: string | number;
|
|
43
|
+
/**
|
|
44
|
+
* Stick to the end while the content grows (a streaming log): the block scrolls to the last line when `code` changes or the block resizes.
|
|
45
|
+
* It turns `false` when the reader scrolls up and `true` again at the bottom, so setting it to `true` jumps to the end. Bindable.
|
|
46
|
+
*/
|
|
47
|
+
follow?: boolean;
|
|
48
|
+
class?: ClassValue;
|
|
49
|
+
style?: string;
|
|
50
|
+
[attr: string]: unknown;
|
|
32
51
|
} = $props();
|
|
33
52
|
|
|
34
53
|
let el: HTMLPreElement;
|
|
@@ -37,7 +56,39 @@
|
|
|
37
56
|
const lang = $derived(modelLanguage(resolveLanguage(language, path), dialect));
|
|
38
57
|
// until the tokenizer has run (and on the server) the text is shown as it is
|
|
39
58
|
const lines = $derived(tokens && tokens.code === code && tokens.lang === lang ? tokens.segs : splitLines(code).map((l) => segmentLine(l, [])));
|
|
40
|
-
const
|
|
59
|
+
const len = (v: string | number) => (typeof v === 'number' ? v + 'px' : v);
|
|
60
|
+
// `maxLines` counts line boxes: the line height of the theme, else 1.5 (the stylesheet's), plus the block's padding and border
|
|
61
|
+
const lineH = $derived(theme ? `${theme.metrics.lineHeight}px` : '1.5em');
|
|
62
|
+
const style = $derived(
|
|
63
|
+
(theme ? paletteVars(theme.palette) + `;font-size:${theme.metrics.fontSize}px;line-height:${theme.metrics.lineHeight}px` : '') +
|
|
64
|
+
(height != null ? `;height:${len(height)}` : maxLines != null ? `;max-height:calc(${maxLines} * ${lineH} + 2 * var(--tr-space-3) + 2px)` : maxHeight != null ? `;max-height:${len(maxHeight)}` : '') +
|
|
65
|
+
(userStyle ? `;${userStyle}` : '')
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
// Only a scroll *up* means the reader left the end (as in ChatThread): the scroll event caused by pinning can arrive after more
|
|
69
|
+
// content has been added, and judged by position alone it would look like "not at the end" and stop following mid-stream.
|
|
70
|
+
let lastTop = 0;
|
|
71
|
+
const pin = (e: HTMLElement) => {
|
|
72
|
+
e.scrollTop = e.scrollHeight;
|
|
73
|
+
lastTop = e.scrollTop;
|
|
74
|
+
};
|
|
75
|
+
const onscroll = (e: Event & { currentTarget: HTMLElement }) => {
|
|
76
|
+
const top = e.currentTarget.scrollTop;
|
|
77
|
+
if (e.currentTarget.scrollHeight - top - e.currentTarget.clientHeight <= 8) follow = true;
|
|
78
|
+
else if (top < lastTop) follow = false;
|
|
79
|
+
lastTop = top;
|
|
80
|
+
};
|
|
81
|
+
$effect(() => {
|
|
82
|
+
void lines;
|
|
83
|
+
if (follow) pin(el);
|
|
84
|
+
});
|
|
85
|
+
$effect(() => {
|
|
86
|
+
const e = el;
|
|
87
|
+
const ro = new ResizeObserver(() => follow && pin(e));
|
|
88
|
+
ro.observe(e);
|
|
89
|
+
ro.observe(e.firstElementChild!);
|
|
90
|
+
return () => ro.disconnect();
|
|
91
|
+
});
|
|
41
92
|
|
|
42
93
|
onMount(() => {
|
|
43
94
|
theme = readTheme(el);
|
|
@@ -53,7 +104,7 @@
|
|
|
53
104
|
</script>
|
|
54
105
|
|
|
55
106
|
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
|
56
|
-
<pre bind:this={el} role="region" class=
|
|
107
|
+
<pre {...rest} bind:this={el} role="region" class={['cb', klass]} class:wrap class:nums={lineNumbers} {style} {onscroll} tabindex="0" aria-label={label}><code>{#each lines as segs, i (i)}<span class="ln">{#if lineNumbers}<span class="no" aria-hidden="true">{i + 1}</span>{/if}<span class="tx">{#each segs as s}<span class={s.role ? `s-${s.role}` : undefined}>{s.text}</span>{/each}{'\n'}</span></span>{/each}</code></pre>
|
|
57
108
|
|
|
58
109
|
<style>
|
|
59
110
|
.cb {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ClassValue } from 'svelte/elements';
|
|
1
2
|
import { type SqlDialect } from './lang.js';
|
|
2
3
|
type $$ComponentProps = {
|
|
3
4
|
/** The text to show. */
|
|
@@ -14,7 +15,19 @@ type $$ComponentProps = {
|
|
|
14
15
|
label?: string;
|
|
15
16
|
/** A CSS length; the block scrolls beyond it. */
|
|
16
17
|
maxHeight?: string | number;
|
|
18
|
+
/** Show at most this many lines, then scroll: a compact block whose height follows the line height of the theme (the lines wrap with `wrap`, so each may take several rows). */
|
|
19
|
+
maxLines?: number;
|
|
20
|
+
/** A fixed CSS length (or pixels): the block is exactly this tall and scrolls. Wins over `maxHeight` and `maxLines`. */
|
|
21
|
+
height?: string | number;
|
|
22
|
+
/**
|
|
23
|
+
* Stick to the end while the content grows (a streaming log): the block scrolls to the last line when `code` changes or the block resizes.
|
|
24
|
+
* It turns `false` when the reader scrolls up and `true` again at the bottom, so setting it to `true` jumps to the end. Bindable.
|
|
25
|
+
*/
|
|
26
|
+
follow?: boolean;
|
|
27
|
+
class?: ClassValue;
|
|
28
|
+
style?: string;
|
|
29
|
+
[attr: string]: unknown;
|
|
17
30
|
};
|
|
18
|
-
declare const CodeBlock: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
31
|
+
declare const CodeBlock: import("svelte").Component<$$ComponentProps, {}, "follow">;
|
|
19
32
|
type CodeBlock = ReturnType<typeof CodeBlock>;
|
|
20
33
|
export default CodeBlock;
|
package/dist/DiffView.svelte
CHANGED
|
@@ -679,10 +679,10 @@
|
|
|
679
679
|
<span class="note">{e.f.count ? `${e.f.count} unchanged ${e.f.count === 1 ? 'line' : 'lines'} not in this patch` : 'Lines not in this patch'}</span>
|
|
680
680
|
{:else}
|
|
681
681
|
{#if !e.f.fixed && e.f.count > EXPAND}
|
|
682
|
-
<Button size="sm" variant="minimal" intent="neutral" aria-label="Show {EXPAND} more lines from above" data-testid="diff-expand-above" data-fold={e.f.key} onclick={() => grow(e.f, 'top')}>↓ {EXPAND}</Button>
|
|
683
|
-
<Button size="sm" variant="minimal" intent="neutral" aria-label="Show {EXPAND} more lines from below" data-testid="diff-expand-below" data-fold={e.f.key} onclick={() => grow(e.f, 'bottom')}>↑ {EXPAND}</Button>
|
|
682
|
+
<Button size="sm" variant="minimal" intent="neutral" aria-label="Show {EXPAND} more lines from above" data-testid="diff-expand-above" data-fold={e.f.key} data-fold-id="diff-expand-above-{e.f.key}" onclick={() => grow(e.f, 'top')}>↓ {EXPAND}</Button>
|
|
683
|
+
<Button size="sm" variant="minimal" intent="neutral" aria-label="Show {EXPAND} more lines from below" data-testid="diff-expand-below" data-fold={e.f.key} data-fold-id="diff-expand-below-{e.f.key}" onclick={() => grow(e.f, 'bottom')}>↑ {EXPAND}</Button>
|
|
684
684
|
{/if}
|
|
685
|
-
<Button size="sm" variant="minimal" intent="neutral" data-testid="diff-expand" data-fold={e.f.key} data-lines={e.f.count} loading={busy === e.f.key} onclick={() => (e.f.fixed ? fill(e.f) : grow(e.f, 'all'))}>{failed?.key === e.f.key ? 'Retry' : `Expand ${e.f.count === 1 ? '1 line' : `${e.f.count} lines`}`}</Button>
|
|
685
|
+
<Button size="sm" variant="minimal" intent="neutral" data-testid="diff-expand" data-fold={e.f.key} data-fold-id="diff-expand-{e.f.key}" data-lines={e.f.count} loading={busy === e.f.key} onclick={() => (e.f.fixed ? fill(e.f) : grow(e.f, 'all'))}>{failed?.key === e.f.key ? 'Retry' : `Expand ${e.f.count === 1 ? '1 line' : `${e.f.count} lines`}`}</Button>
|
|
686
686
|
{#if failed?.key === e.f.key}<span class="note err" role="alert">Could not load the file: {failed.message}</span>{/if}
|
|
687
687
|
{/if}
|
|
688
688
|
</td></tr>
|
package/dist/MergeView.svelte
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { onMount, tick, untrack } from 'svelte';
|
|
3
|
+
import type { ClassValue } from 'svelte/elements';
|
|
3
4
|
import { Button, SegmentedControl, Textarea } from '@ruckc/truss-ui';
|
|
4
|
-
import { diff3, render, chosenLines, customResolution, linesText, type Choice, type Merge, type MergeLabels, type Resolution } from './merge.js';
|
|
5
|
+
import { diff3, render, chosenLines, customResolution, linesText, type Choice, type FileResolution, type Merge, type MergeLabels, type Resolution } from './merge.js';
|
|
5
6
|
import { splitDocument, type Line } from './diff.js';
|
|
6
7
|
import { paletteVars, segmentLine, type Seg } from './highlight.js';
|
|
7
8
|
import { highlightText } from './syntax.js';
|
|
@@ -21,6 +22,13 @@
|
|
|
21
22
|
resolved: number;
|
|
22
23
|
/** How many conflicts there are. */
|
|
23
24
|
conflicts: number;
|
|
25
|
+
/** Whether nothing is left to decide: every conflict has a resolution (or there are none), or the file is to be deleted, or a binary file has a choice. */
|
|
26
|
+
allResolved: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* What to do with the file: `{ kind: 'text', text }` write `text` (the merged text; it still holds conflict markers while `allResolved` is false),
|
|
29
|
+
* `{ kind: 'delete' }` remove it, or in `binary` mode `{ kind: 'keep', side }` keep that version. `undefined` while a binary file is undecided.
|
|
30
|
+
*/
|
|
31
|
+
resolution: FileResolution | undefined;
|
|
24
32
|
}
|
|
25
33
|
|
|
26
34
|
let {
|
|
@@ -34,8 +42,15 @@
|
|
|
34
42
|
labels,
|
|
35
43
|
highlight: syntax = true,
|
|
36
44
|
label = 'Merge',
|
|
45
|
+
height,
|
|
46
|
+
binary = false,
|
|
47
|
+
deletable = false,
|
|
37
48
|
load,
|
|
38
|
-
|
|
49
|
+
loadAll,
|
|
50
|
+
onresolve,
|
|
51
|
+
class: klass,
|
|
52
|
+
style: userStyle,
|
|
53
|
+
...rest
|
|
39
54
|
}: {
|
|
40
55
|
/** The common ancestor. Omit it (with `load`) to have it fetched; without either it is empty. */
|
|
41
56
|
base?: string;
|
|
@@ -56,6 +71,20 @@
|
|
|
56
71
|
/** 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. */
|
|
57
72
|
highlight?: boolean;
|
|
58
73
|
label?: string;
|
|
74
|
+
/**
|
|
75
|
+
* 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
|
+
* panes and the result, each scrolling inside. Any CSS length (`'32rem'`) or number of pixels does the same with a fixed height.
|
|
78
|
+
*/
|
|
79
|
+
height?: 'auto' | 'fill' | (string & {}) | number;
|
|
80
|
+
/**
|
|
81
|
+
* The file cannot be merged as text (an image, an archive): no diff is drawn. The view is one unresolved conflict with the buttons
|
|
82
|
+
* Keep ours, Keep theirs and Delete file (`onresolve` reports `resolution` `{ kind: 'keep', side }` or `{ kind: 'delete' }`).
|
|
83
|
+
* `base`, `ours` and `theirs` are not shown, but a change to them starts the decision afresh; `load` is not called.
|
|
84
|
+
*/
|
|
85
|
+
binary?: boolean;
|
|
86
|
+
/** Offer "Delete file" for a text merge (a modify/delete conflict). While chosen, `onresolve` reports `resolution` `{ kind: 'delete' }` and `allResolved: true`. */
|
|
87
|
+
deletable?: boolean;
|
|
59
88
|
/**
|
|
60
89
|
* 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
|
|
61
90
|
* the files on demand (like `DiffFiles`' `load`). All missing sides are fetched together when the view mounts, and again when
|
|
@@ -63,8 +92,16 @@
|
|
|
63
92
|
* a rejection shows the error with a Retry button. A side passed as a prop is never fetched.
|
|
64
93
|
*/
|
|
65
94
|
load?: (side: 'base' | 'ours' | 'theirs') => Promise<string>;
|
|
95
|
+
/**
|
|
96
|
+
* Like `load`, but one request for everything: it is called once (without arguments) and returns all three texts, of which only the
|
|
97
|
+
* sides you did not pass as props are used. Wins over `load` when both are given.
|
|
98
|
+
*/
|
|
99
|
+
loadAll?: () => Promise<{ base: string; ours: string; theirs: string }>;
|
|
66
100
|
/** Called whenever the merge changes: new inputs, or a conflict resolved, edited or reset. */
|
|
67
101
|
onresolve?: (state: MergeState) => void;
|
|
102
|
+
class?: ClassValue;
|
|
103
|
+
style?: string;
|
|
104
|
+
[attr: string]: unknown;
|
|
68
105
|
} = $props();
|
|
69
106
|
|
|
70
107
|
const uid = $props.id();
|
|
@@ -92,14 +129,16 @@
|
|
|
92
129
|
const ours = $derived(oursProp ?? loaded.ours ?? '');
|
|
93
130
|
const theirs = $derived(theirsProp ?? loaded.theirs ?? '');
|
|
94
131
|
$effect(() => {
|
|
95
|
-
const fetch = load;
|
|
132
|
+
const fetch = load, fetchAll = loadAll;
|
|
96
133
|
void attempt;
|
|
97
134
|
const given = { base: baseProp, ours: oursProp, theirs: theirsProp };
|
|
98
135
|
const sides = COLS.filter((c) => given[c] === undefined);
|
|
99
|
-
|
|
100
|
-
|
|
136
|
+
const fetching = !binary && (!!fetch || !!fetchAll) && sides.length > 0;
|
|
137
|
+
untrack(() => { loading = fetching; loadError = undefined; });
|
|
138
|
+
if (!fetching) return;
|
|
101
139
|
let stale = false;
|
|
102
|
-
Promise.all(sides.map(async (side) => fetch(side)))
|
|
140
|
+
const request = fetchAll ? fetchAll().then((all) => sides.map((side) => all[side])) : Promise.all(sides.map(async (side) => fetch!(side)));
|
|
141
|
+
request.then(
|
|
103
142
|
(texts) => {
|
|
104
143
|
if (stale) return;
|
|
105
144
|
loaded = { ...loaded, ...Object.fromEntries(sides.map((side, i) => [side, texts[i]])) };
|
|
@@ -124,22 +163,33 @@
|
|
|
124
163
|
const lang = $derived(resolveLanguage(language, path));
|
|
125
164
|
const name = $derived(path ?? '');
|
|
126
165
|
|
|
166
|
+
// 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
|
+
let fileChoice = $state.raw<{ merge: Merge; pick: 'ours' | 'theirs' | 'delete' } | undefined>();
|
|
168
|
+
const pick = $derived(fileChoice?.merge === merge ? fileChoice.pick : undefined);
|
|
169
|
+
const deleted = $derived(pick === 'delete' && (binary || deletable));
|
|
170
|
+
const shown = $derived<MergeState>(
|
|
171
|
+
binary
|
|
172
|
+
? { result: '', resolved: pick ? 1 : 0, conflicts: 1, allResolved: !!pick, resolution: pick === 'delete' ? { kind: 'delete' } : pick ? { kind: 'keep', side: pick } : undefined }
|
|
173
|
+
: { 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
|
+
);
|
|
175
|
+
const choose = (p: 'ours' | 'theirs' | 'delete') => (fileChoice = pick === p ? undefined : { merge, pick: p });
|
|
176
|
+
|
|
127
177
|
$effect.pre(() => {
|
|
128
178
|
if (loading) return;
|
|
129
|
-
result =
|
|
130
|
-
conflicts =
|
|
179
|
+
result = shown.result;
|
|
180
|
+
conflicts = shown.conflicts;
|
|
131
181
|
});
|
|
132
182
|
$effect(() => {
|
|
133
|
-
const
|
|
183
|
+
const s = shown;
|
|
134
184
|
if (untrack(() => loading)) return;
|
|
135
|
-
untrack(() => onresolve?.(
|
|
185
|
+
untrack(() => onresolve?.(s));
|
|
136
186
|
});
|
|
137
187
|
$effect.pre(() => {
|
|
138
188
|
merge;
|
|
139
189
|
untrack(() => { cur = -1; editing = null; announce = ''; });
|
|
140
190
|
});
|
|
141
191
|
|
|
142
|
-
const status = $derived(loading ? 'Loading...' : total ? `${out.resolved} of ${total} ${total === 1 ? 'conflict' : 'conflicts'} resolved` : 'No conflicts');
|
|
192
|
+
const status = $derived(loading ? 'Loading...' : binary ? (pick === 'delete' ? 'The file will be deleted' : pick ? `Keeping ${names[pick].toLowerCase()}` : 'Binary file: choose a version') : deleted ? 'The file will be deleted' : total ? `${out.resolved} of ${total} ${total === 1 ? 'conflict' : 'conflicts'} resolved` : 'No conflicts');
|
|
143
193
|
|
|
144
194
|
function decide(c: number, res: Resolution | undefined) {
|
|
145
195
|
const list = [...resolutions];
|
|
@@ -227,7 +277,12 @@
|
|
|
227
277
|
ro.observe(root);
|
|
228
278
|
return () => { stop(); ro.disconnect(); cancelAnimationFrame(frame); };
|
|
229
279
|
});
|
|
230
|
-
const style = $derived(
|
|
280
|
+
const style = $derived(
|
|
281
|
+
(theme ? paletteVars(theme.palette) + `;--mv-font:${theme.metrics.fontSize}px` : '') +
|
|
282
|
+
(height != null && height !== 'auto' && height !== 'fill' ? `;height:${typeof height === 'number' ? height + 'px' : height}` : '') +
|
|
283
|
+
(userStyle ? `;${userStyle}` : '')
|
|
284
|
+
);
|
|
285
|
+
const sizing = $derived(height == null ? 'capped' : height === 'auto' || height === 'fill' ? height : 'fixed');
|
|
231
286
|
|
|
232
287
|
// ───── navigation
|
|
233
288
|
async function go(c: number) {
|
|
@@ -284,23 +339,35 @@
|
|
|
284
339
|
</script>
|
|
285
340
|
|
|
286
341
|
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
|
287
|
-
<div bind:this={root} class=
|
|
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">
|
|
288
343
|
<div class="bar">
|
|
289
|
-
<span class="sum" role="status" data-testid="status" data-done={total > 0 && out.resolved === total}>{status}</span>
|
|
344
|
+
<span class="sum" role="status" data-testid="status" data-done={binary ? !!pick : deleted || (total > 0 && out.resolved === total)}>{status}</span>
|
|
290
345
|
<span class="grow"></span>
|
|
291
|
-
|
|
292
|
-
|
|
346
|
+
{#if deletable && !binary}
|
|
347
|
+
<Button variant="outlined" intent="danger" size="sm" pressed={deleted} data-testid="delete-file" onclick={() => choose('delete')}>Delete file</Button>
|
|
348
|
+
{/if}
|
|
349
|
+
<Button variant="minimal" intent="neutral" size="sm" icon="chevron-up" aria-label="Previous conflict" shortcut="p" disabled={!total || binary} onclick={prev} />
|
|
350
|
+
<Button variant="minimal" intent="neutral" size="sm" icon="chevron-down" aria-label="Next conflict" shortcut="n" disabled={!total || binary} onclick={next} />
|
|
293
351
|
</div>
|
|
294
352
|
{#if loadError}
|
|
295
353
|
<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>
|
|
296
354
|
{/if}
|
|
297
355
|
<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>
|
|
298
356
|
<div class="vh" role="status" aria-live="polite" data-testid="announce">{announce}</div>
|
|
299
|
-
{#if
|
|
357
|
+
{#if binary}
|
|
358
|
+
<div class="bin" role="group" aria-label="Binary file" data-testid="binary">
|
|
359
|
+
<p class="bin-note">This file cannot be merged as text. Keep one version or delete it.</p>
|
|
360
|
+
<div class="acts">
|
|
361
|
+
<Button size="sm" variant="outlined" intent="neutral" pressed={pick === 'ours'} data-testid="keep-ours" onclick={() => choose('ours')}>Keep {names.ours.toLowerCase()}</Button>
|
|
362
|
+
<Button size="sm" variant="outlined" intent="neutral" pressed={pick === 'theirs'} data-testid="keep-theirs" onclick={() => choose('theirs')}>Keep {names.theirs.toLowerCase()}</Button>
|
|
363
|
+
<Button size="sm" variant="outlined" intent="danger" pressed={pick === 'delete'} data-testid="delete-file" onclick={() => choose('delete')}>Delete file</Button>
|
|
364
|
+
</div>
|
|
365
|
+
</div>
|
|
366
|
+
{:else if narrow}
|
|
300
367
|
<div class="tabs"><SegmentedControl size="sm" label="Merge pane" value={tab} onchange={(v) => (tab = v as Tab)} options={TABS} /></div>
|
|
301
368
|
{/if}
|
|
302
369
|
|
|
303
|
-
{#if showTable}
|
|
370
|
+
{#if showTable && !binary}
|
|
304
371
|
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
|
305
372
|
<div class="scroll" role="region" aria-label="Base, ours and theirs" tabindex="0">
|
|
306
373
|
<table class="tbl" data-show={narrow ? tab : 'all'} aria-label={name ? `Versions of ${name}` : 'Versions'}>
|
|
@@ -355,7 +422,7 @@
|
|
|
355
422
|
</div>
|
|
356
423
|
{/if}
|
|
357
424
|
|
|
358
|
-
{#if showResult}
|
|
425
|
+
{#if showResult && !binary}
|
|
359
426
|
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
|
360
427
|
<div class="result" role="region" aria-label="Result" tabindex="0">
|
|
361
428
|
<div class="rhead" aria-hidden="true">Result</div>
|
|
@@ -406,6 +473,13 @@
|
|
|
406
473
|
.sum[data-done='true'] { color: var(--tr-success); }
|
|
407
474
|
.tabs { padding: var(--tr-space-1) var(--tr-space-2); border-bottom: 1px solid var(--tr-outline-variant); }
|
|
408
475
|
.scroll { overflow: auto; max-height: 28rem; }
|
|
476
|
+
.bin { display: grid; gap: var(--tr-space-2); padding: var(--tr-space-3); font-family: var(--tr-font-sans); }
|
|
477
|
+
.bin-note { margin: 0; color: var(--tr-on-surface-variant); }
|
|
478
|
+
/* height: `auto` lets the page scroll; `fill` and a length make the view a column whose panes scroll inside it */
|
|
479
|
+
.mv[data-height='auto'] .scroll, .mv[data-height='auto'] .result { max-height: none; }
|
|
480
|
+
.mv[data-height='fill'], .mv[data-height='fixed'] { display: flex; flex-direction: column; min-height: 0; }
|
|
481
|
+
.mv[data-height='fill'] { height: 100%; }
|
|
482
|
+
.mv[data-height='fill'] .scroll, .mv[data-height='fixed'] .scroll, .mv[data-height='fill'] .result, .mv[data-height='fixed'] .result { max-height: none; min-height: 0; flex: 1 1 auto; }
|
|
409
483
|
.scroll:focus-visible, .result:focus-visible { outline: none; box-shadow: inset var(--tr-focus-ring); }
|
|
410
484
|
.tbl { border-collapse: collapse; width: 100%; table-layout: fixed; font-family: var(--tr-font-mono); font-size: var(--mv-font, var(--tr-text-sm)); line-height: 1.5; tab-size: 4; }
|
|
411
485
|
.c-no { width: 5ch; } .c-sym { width: 3ch; }
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ClassValue } from 'svelte/elements';
|
|
2
|
+
import { type FileResolution, type MergeLabels } from './merge.js';
|
|
2
3
|
/** What `onresolve` receives. */
|
|
3
4
|
export interface MergeState {
|
|
4
5
|
/** The merged text; unresolved conflicts are written as `diff3` conflict blocks. */
|
|
@@ -7,6 +8,13 @@ export interface MergeState {
|
|
|
7
8
|
resolved: number;
|
|
8
9
|
/** How many conflicts there are. */
|
|
9
10
|
conflicts: number;
|
|
11
|
+
/** Whether nothing is left to decide: every conflict has a resolution (or there are none), or the file is to be deleted, or a binary file has a choice. */
|
|
12
|
+
allResolved: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* What to do with the file: `{ kind: 'text', text }` write `text` (the merged text; it still holds conflict markers while `allResolved` is false),
|
|
15
|
+
* `{ kind: 'delete' }` remove it, or in `binary` mode `{ kind: 'keep', side }` keep that version. `undefined` while a binary file is undecided.
|
|
16
|
+
*/
|
|
17
|
+
resolution: FileResolution | undefined;
|
|
10
18
|
}
|
|
11
19
|
type $$ComponentProps = {
|
|
12
20
|
/** The common ancestor. Omit it (with `load`) to have it fetched; without either it is empty. */
|
|
@@ -28,6 +36,20 @@ type $$ComponentProps = {
|
|
|
28
36
|
/** 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. */
|
|
29
37
|
highlight?: boolean;
|
|
30
38
|
label?: string;
|
|
39
|
+
/**
|
|
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
|
|
42
|
+
* panes and the result, each scrolling inside. Any CSS length (`'32rem'`) or number of pixels does the same with a fixed height.
|
|
43
|
+
*/
|
|
44
|
+
height?: 'auto' | 'fill' | (string & {}) | number;
|
|
45
|
+
/**
|
|
46
|
+
* The file cannot be merged as text (an image, an archive): no diff is drawn. The view is one unresolved conflict with the buttons
|
|
47
|
+
* Keep ours, Keep theirs and Delete file (`onresolve` reports `resolution` `{ kind: 'keep', side }` or `{ kind: 'delete' }`).
|
|
48
|
+
* `base`, `ours` and `theirs` are not shown, but a change to them starts the decision afresh; `load` is not called.
|
|
49
|
+
*/
|
|
50
|
+
binary?: boolean;
|
|
51
|
+
/** Offer "Delete file" for a text merge (a modify/delete conflict). While chosen, `onresolve` reports `resolution` `{ kind: 'delete' }` and `allResolved: true`. */
|
|
52
|
+
deletable?: boolean;
|
|
31
53
|
/**
|
|
32
54
|
* 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
|
|
33
55
|
* the files on demand (like `DiffFiles`' `load`). All missing sides are fetched together when the view mounts, and again when
|
|
@@ -35,8 +57,20 @@ type $$ComponentProps = {
|
|
|
35
57
|
* a rejection shows the error with a Retry button. A side passed as a prop is never fetched.
|
|
36
58
|
*/
|
|
37
59
|
load?: (side: 'base' | 'ours' | 'theirs') => Promise<string>;
|
|
60
|
+
/**
|
|
61
|
+
* Like `load`, but one request for everything: it is called once (without arguments) and returns all three texts, of which only the
|
|
62
|
+
* sides you did not pass as props are used. Wins over `load` when both are given.
|
|
63
|
+
*/
|
|
64
|
+
loadAll?: () => Promise<{
|
|
65
|
+
base: string;
|
|
66
|
+
ours: string;
|
|
67
|
+
theirs: string;
|
|
68
|
+
}>;
|
|
38
69
|
/** Called whenever the merge changes: new inputs, or a conflict resolved, edited or reset. */
|
|
39
70
|
onresolve?: (state: MergeState) => void;
|
|
71
|
+
class?: ClassValue;
|
|
72
|
+
style?: string;
|
|
73
|
+
[attr: string]: unknown;
|
|
40
74
|
};
|
|
41
75
|
declare const MergeView: import("svelte").Component<$$ComponentProps, {
|
|
42
76
|
next: () => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -4,4 +4,3 @@ export { default as DiffEditor } from './DiffEditor.svelte';
|
|
|
4
4
|
export { useMonaco } from './monaco-default.js';
|
|
5
5
|
export type { TypeScriptSetup } from './monaco.js';
|
|
6
6
|
export type { CompletionsOption } from './editor-util.js';
|
|
7
|
-
export { configureCodeEditor, type CodeEditorDefaults } from './editor-defaults.svelte.js';
|
package/dist/index.js
CHANGED
package/dist/lite.d.ts
CHANGED
|
@@ -7,12 +7,14 @@ export { detectLanguage, resolveLanguage, modelLanguage } from './lang.js';
|
|
|
7
7
|
export { setMonacoLoader, loadMonaco } from './monaco.js';
|
|
8
8
|
export { fallbackHighlight } from './fallback.js';
|
|
9
9
|
export { markLines } from './patch-text.js';
|
|
10
|
+
export { configureCodeEditor } from './editor-defaults.svelte.js';
|
|
10
11
|
export { buildPalette, monacoTheme, ensureContrast, contrast, parseColor } from './theme.js';
|
|
11
12
|
export { diffLines, diffSeq, intraline, annotateIntraline, pairLines, inlineWords, hunkSpans, toHunks, formatHunks, unifiedPatch, foldItems, expandFold, splitRows, splitDocument, changeStarts, diffStats } from './diff.js';
|
|
12
13
|
export { detectMoves } from './moves.js';
|
|
13
14
|
export { parsePatch, patchLines, layoutPatch, unquotePath, filePath } from './patch.js';
|
|
14
15
|
export { entriesFromPatch, buildTree } from './files.js';
|
|
15
16
|
export { diff3, render as renderMerge, mergeText, chosenLines, customResolution } from './merge.js';
|
|
17
|
+
export type { CodeEditorDefaults } from './editor-defaults.svelte.js';
|
|
16
18
|
export type { MonacoApi, MonacoLoader } from './monaco.js';
|
|
17
19
|
export type { SqlDialect } from './lang.js';
|
|
18
20
|
export type { CodeMarker, MarkerSeverity, CompletionItem, CompletionKind, CompletionContext, DiffAnnotation } from './types.js';
|
|
@@ -25,4 +27,4 @@ export type { PatchFile, FileStatus } from './patch.js';
|
|
|
25
27
|
export type { DiffFileInput, DiffStatus, FileEntry } from './files.js';
|
|
26
28
|
export type { LoadText } from './load.js';
|
|
27
29
|
export type { MergeState } from './MergeView.svelte';
|
|
28
|
-
export type { Merge, MergeRegion, RegionKind, Resolution, Choice, MergeLabels, Rendered as RenderedMerge } from './merge.js';
|
|
30
|
+
export type { Merge, MergeRegion, RegionKind, Resolution, FileResolution, Choice, MergeLabels, Rendered as RenderedMerge } from './merge.js';
|
package/dist/lite.js
CHANGED
|
@@ -10,6 +10,8 @@ export { detectLanguage, resolveLanguage, modelLanguage } from './lang.js';
|
|
|
10
10
|
export { setMonacoLoader, loadMonaco } from './monaco.js';
|
|
11
11
|
export { fallbackHighlight } from './fallback.js';
|
|
12
12
|
export { markLines } from './patch-text.js';
|
|
13
|
+
// app-wide editor defaults: config only (its Monaco import is type-only), so calling it at startup pulls no editor code into the entry chunk
|
|
14
|
+
export { configureCodeEditor } from './editor-defaults.svelte.js';
|
|
13
15
|
export { buildPalette, monacoTheme, ensureContrast, contrast, parseColor } from './theme.js';
|
|
14
16
|
// pure diff and patch logic, usable without any component
|
|
15
17
|
export { diffLines, diffSeq, intraline, annotateIntraline, pairLines, inlineWords, hunkSpans, toHunks, formatHunks, unifiedPatch, foldItems, expandFold, splitRows, splitDocument, changeStarts, diffStats } from './diff.js';
|
package/dist/merge.d.ts
CHANGED
|
@@ -44,6 +44,19 @@ export interface Resolution {
|
|
|
44
44
|
choice: Choice;
|
|
45
45
|
text?: string;
|
|
46
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* What to do with the file as a whole: write `text`, delete it (a modify/delete conflict), or, for a binary file that cannot be merged,
|
|
49
|
+
* keep one side's version.
|
|
50
|
+
*/
|
|
51
|
+
export type FileResolution = {
|
|
52
|
+
kind: 'text';
|
|
53
|
+
text: string;
|
|
54
|
+
} | {
|
|
55
|
+
kind: 'delete';
|
|
56
|
+
} | {
|
|
57
|
+
kind: 'keep';
|
|
58
|
+
side: 'ours' | 'theirs';
|
|
59
|
+
};
|
|
47
60
|
/** The lines a resolution puts into the result. */
|
|
48
61
|
export declare function chosenLines(r: MergeRegion, res: Resolution): Line[];
|
|
49
62
|
/** The text a conflict is shown as when it is edited (the lines of its current choice, without the last line ending). */
|
package/package.json
CHANGED