@ruckc/truss-code 1.20.1 → 1.22.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 +117 -19
- package/dist/MergeView.svelte.d.ts +47 -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,16 @@
|
|
|
34
42
|
labels,
|
|
35
43
|
highlight: syntax = true,
|
|
36
44
|
label = 'Merge',
|
|
45
|
+
height,
|
|
46
|
+
binary = false,
|
|
47
|
+
deletable,
|
|
48
|
+
deleted: deletedSide,
|
|
37
49
|
load,
|
|
38
|
-
|
|
50
|
+
loadAll,
|
|
51
|
+
onresolve,
|
|
52
|
+
class: klass,
|
|
53
|
+
style: userStyle,
|
|
54
|
+
...rest
|
|
39
55
|
}: {
|
|
40
56
|
/** The common ancestor. Omit it (with `load`) to have it fetched; without either it is empty. */
|
|
41
57
|
base?: string;
|
|
@@ -56,6 +72,32 @@
|
|
|
56
72
|
/** 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
73
|
highlight?: boolean;
|
|
58
74
|
label?: string;
|
|
75
|
+
/**
|
|
76
|
+
* How tall the view is. Unset keeps the default: the three panes scroll within 28rem and the result within 20rem.
|
|
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
|
|
78
|
+
* panes and the result, each scrolling inside. Any CSS length (`'32rem'`) or number of pixels does the same with a fixed height.
|
|
79
|
+
*/
|
|
80
|
+
height?: 'auto' | 'fill' | (string & {}) | number;
|
|
81
|
+
/**
|
|
82
|
+
* The file cannot be merged as text (an image, an archive): no diff is drawn. The view is one unresolved conflict with the buttons
|
|
83
|
+
* Keep ours, Keep theirs and Delete file (`onresolve` reports `resolution` `{ kind: 'keep', side }` or `{ kind: 'delete' }`).
|
|
84
|
+
* `base`, `ours` and `theirs` are not shown, but a change to them starts the decision afresh; `load` is not called.
|
|
85
|
+
*/
|
|
86
|
+
binary?: boolean;
|
|
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
|
+
*/
|
|
100
|
+
deletable?: boolean;
|
|
59
101
|
/**
|
|
60
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
|
|
61
103
|
* the files on demand (like `DiffFiles`' `load`). All missing sides are fetched together when the view mounts, and again when
|
|
@@ -63,8 +105,16 @@
|
|
|
63
105
|
* a rejection shows the error with a Retry button. A side passed as a prop is never fetched.
|
|
64
106
|
*/
|
|
65
107
|
load?: (side: 'base' | 'ours' | 'theirs') => Promise<string>;
|
|
108
|
+
/**
|
|
109
|
+
* Like `load`, but one request for everything: it is called once (without arguments) and returns all three texts, of which only the
|
|
110
|
+
* sides you did not pass as props are used. Wins over `load` when both are given.
|
|
111
|
+
*/
|
|
112
|
+
loadAll?: () => Promise<{ base: string; ours: string; theirs: string }>;
|
|
66
113
|
/** Called whenever the merge changes: new inputs, or a conflict resolved, edited or reset. */
|
|
67
114
|
onresolve?: (state: MergeState) => void;
|
|
115
|
+
class?: ClassValue;
|
|
116
|
+
style?: string;
|
|
117
|
+
[attr: string]: unknown;
|
|
68
118
|
} = $props();
|
|
69
119
|
|
|
70
120
|
const uid = $props.id();
|
|
@@ -92,14 +142,16 @@
|
|
|
92
142
|
const ours = $derived(oursProp ?? loaded.ours ?? '');
|
|
93
143
|
const theirs = $derived(theirsProp ?? loaded.theirs ?? '');
|
|
94
144
|
$effect(() => {
|
|
95
|
-
const fetch = load;
|
|
145
|
+
const fetch = load, fetchAll = loadAll;
|
|
96
146
|
void attempt;
|
|
97
147
|
const given = { base: baseProp, ours: oursProp, theirs: theirsProp };
|
|
98
148
|
const sides = COLS.filter((c) => given[c] === undefined);
|
|
99
|
-
|
|
100
|
-
|
|
149
|
+
const fetching = !whole && (!!fetch || !!fetchAll) && sides.length > 0;
|
|
150
|
+
untrack(() => { loading = fetching; loadError = undefined; });
|
|
151
|
+
if (!fetching) return;
|
|
101
152
|
let stale = false;
|
|
102
|
-
Promise.all(sides.map(async (side) => fetch(side)))
|
|
153
|
+
const request = fetchAll ? fetchAll().then((all) => sides.map((side) => all[side])) : Promise.all(sides.map(async (side) => fetch!(side)));
|
|
154
|
+
request.then(
|
|
103
155
|
(texts) => {
|
|
104
156
|
if (stale) return;
|
|
105
157
|
loaded = { ...loaded, ...Object.fromEntries(sides.map((side, i) => [side, texts[i]])) };
|
|
@@ -124,22 +176,38 @@
|
|
|
124
176
|
const lang = $derived(resolveLanguage(language, path));
|
|
125
177
|
const name = $derived(path ?? '');
|
|
126
178
|
|
|
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
|
|
180
|
+
let fileChoice = $state.raw<{ merge: Merge; pick: 'ours' | 'theirs' | 'delete' } | undefined>();
|
|
181
|
+
const pick = $derived(fileChoice?.merge === merge ? fileChoice.pick : undefined);
|
|
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);
|
|
188
|
+
const shown = $derived<MergeState>(
|
|
189
|
+
whole
|
|
190
|
+
? { result: '', resolved: pick ? 1 : 0, conflicts: 1, allResolved: !!pick, resolution: pick === 'delete' ? { kind: 'delete' } : pick ? { kind: 'keep', side: pick } : undefined }
|
|
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 } }
|
|
192
|
+
);
|
|
193
|
+
const choose = (p: 'ours' | 'theirs' | 'delete') => (fileChoice = pick === p ? undefined : { merge, pick: p });
|
|
194
|
+
|
|
127
195
|
$effect.pre(() => {
|
|
128
196
|
if (loading) return;
|
|
129
|
-
result =
|
|
130
|
-
conflicts =
|
|
197
|
+
result = shown.result;
|
|
198
|
+
conflicts = shown.conflicts;
|
|
131
199
|
});
|
|
132
200
|
$effect(() => {
|
|
133
|
-
const
|
|
201
|
+
const s = shown;
|
|
134
202
|
if (untrack(() => loading)) return;
|
|
135
|
-
untrack(() => onresolve?.(
|
|
203
|
+
untrack(() => onresolve?.(s));
|
|
136
204
|
});
|
|
137
205
|
$effect.pre(() => {
|
|
138
206
|
merge;
|
|
139
207
|
untrack(() => { cur = -1; editing = null; announce = ''; });
|
|
140
208
|
});
|
|
141
209
|
|
|
142
|
-
const status = $derived(loading ? 'Loading...' : total ? `${out.resolved} of ${total} ${total === 1 ? 'conflict' : 'conflicts'} resolved` : 'No conflicts');
|
|
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');
|
|
143
211
|
|
|
144
212
|
function decide(c: number, res: Resolution | undefined) {
|
|
145
213
|
const list = [...resolutions];
|
|
@@ -227,7 +295,12 @@
|
|
|
227
295
|
ro.observe(root);
|
|
228
296
|
return () => { stop(); ro.disconnect(); cancelAnimationFrame(frame); };
|
|
229
297
|
});
|
|
230
|
-
const style = $derived(
|
|
298
|
+
const style = $derived(
|
|
299
|
+
(theme ? paletteVars(theme.palette) + `;--mv-font:${theme.metrics.fontSize}px` : '') +
|
|
300
|
+
(height != null && height !== 'auto' && height !== 'fill' ? `;height:${typeof height === 'number' ? height + 'px' : height}` : '') +
|
|
301
|
+
(userStyle ? `;${userStyle}` : '')
|
|
302
|
+
);
|
|
303
|
+
const sizing = $derived(height == null ? 'capped' : height === 'auto' || height === 'fill' ? height : 'fixed');
|
|
231
304
|
|
|
232
305
|
// ───── navigation
|
|
233
306
|
async function go(c: number) {
|
|
@@ -284,23 +357,39 @@
|
|
|
284
357
|
</script>
|
|
285
358
|
|
|
286
359
|
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
|
287
|
-
<div bind:this={root} class=
|
|
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">
|
|
288
361
|
<div class="bar">
|
|
289
|
-
<span class="sum" role="status" data-testid="status" data-done={total > 0 && out.resolved === total}>{status}</span>
|
|
362
|
+
<span class="sum" role="status" data-testid="status" data-done={whole ? !!pick : deleted || (total > 0 && out.resolved === total)}>{status}</span>
|
|
290
363
|
<span class="grow"></span>
|
|
291
|
-
|
|
292
|
-
|
|
364
|
+
{#if canDelete && !whole}
|
|
365
|
+
<Button variant="outlined" intent="danger" size="sm" pressed={deleted} data-testid="delete-file" onclick={() => choose('delete')}>Delete file</Button>
|
|
366
|
+
{/if}
|
|
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} />
|
|
293
369
|
</div>
|
|
294
370
|
{#if loadError}
|
|
295
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>
|
|
296
372
|
{/if}
|
|
297
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>
|
|
298
374
|
<div class="vh" role="status" aria-live="polite" data-testid="announce">{announce}</div>
|
|
299
|
-
{#if
|
|
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>
|
|
378
|
+
<div class="acts">
|
|
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}
|
|
386
|
+
</div>
|
|
387
|
+
</div>
|
|
388
|
+
{:else if narrow}
|
|
300
389
|
<div class="tabs"><SegmentedControl size="sm" label="Merge pane" value={tab} onchange={(v) => (tab = v as Tab)} options={TABS} /></div>
|
|
301
390
|
{/if}
|
|
302
391
|
|
|
303
|
-
{#if showTable}
|
|
392
|
+
{#if showTable && !whole}
|
|
304
393
|
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
|
305
394
|
<div class="scroll" role="region" aria-label="Base, ours and theirs" tabindex="0">
|
|
306
395
|
<table class="tbl" data-show={narrow ? tab : 'all'} aria-label={name ? `Versions of ${name}` : 'Versions'}>
|
|
@@ -355,7 +444,7 @@
|
|
|
355
444
|
</div>
|
|
356
445
|
{/if}
|
|
357
446
|
|
|
358
|
-
{#if showResult}
|
|
447
|
+
{#if showResult && !whole}
|
|
359
448
|
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
|
360
449
|
<div class="result" role="region" aria-label="Result" tabindex="0">
|
|
361
450
|
<div class="rhead" aria-hidden="true">Result</div>
|
|
@@ -406,6 +495,15 @@
|
|
|
406
495
|
.sum[data-done='true'] { color: var(--tr-success); }
|
|
407
496
|
.tabs { padding: var(--tr-space-1) var(--tr-space-2); border-bottom: 1px solid var(--tr-outline-variant); }
|
|
408
497
|
.scroll { overflow: auto; max-height: 28rem; }
|
|
498
|
+
.bin { display: grid; gap: var(--tr-space-2); padding: var(--tr-space-3); font-family: var(--tr-font-sans); }
|
|
499
|
+
.bin-note { margin: 0; color: var(--tr-on-surface-variant); }
|
|
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; }
|
|
503
|
+
.mv[data-height='auto'] .scroll, .mv[data-height='auto'] .result { max-height: none; }
|
|
504
|
+
.mv[data-height='fill'], .mv[data-height='fixed'] { display: flex; flex-direction: column; min-height: 0; }
|
|
505
|
+
.mv[data-height='fill'] { height: 100%; }
|
|
506
|
+
.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
507
|
.scroll:focus-visible, .result:focus-visible { outline: none; box-shadow: inset var(--tr-focus-ring); }
|
|
410
508
|
.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
509
|
.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,32 @@ 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 (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
|
+
* 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
|
+
/**
|
|
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
|
+
*/
|
|
64
|
+
deletable?: boolean;
|
|
31
65
|
/**
|
|
32
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
|
|
33
67
|
* the files on demand (like `DiffFiles`' `load`). All missing sides are fetched together when the view mounts, and again when
|
|
@@ -35,8 +69,20 @@ type $$ComponentProps = {
|
|
|
35
69
|
* a rejection shows the error with a Retry button. A side passed as a prop is never fetched.
|
|
36
70
|
*/
|
|
37
71
|
load?: (side: 'base' | 'ours' | 'theirs') => Promise<string>;
|
|
72
|
+
/**
|
|
73
|
+
* Like `load`, but one request for everything: it is called once (without arguments) and returns all three texts, of which only the
|
|
74
|
+
* sides you did not pass as props are used. Wins over `load` when both are given.
|
|
75
|
+
*/
|
|
76
|
+
loadAll?: () => Promise<{
|
|
77
|
+
base: string;
|
|
78
|
+
ours: string;
|
|
79
|
+
theirs: string;
|
|
80
|
+
}>;
|
|
38
81
|
/** Called whenever the merge changes: new inputs, or a conflict resolved, edited or reset. */
|
|
39
82
|
onresolve?: (state: MergeState) => void;
|
|
83
|
+
class?: ClassValue;
|
|
84
|
+
style?: string;
|
|
85
|
+
[attr: string]: unknown;
|
|
40
86
|
};
|
|
41
87
|
declare const MergeView: import("svelte").Component<$$ComponentProps, {
|
|
42
88
|
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