@ruckc/truss-code 1.48.0 → 1.49.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 +29 -9
- package/dist/CodeBlock.svelte.d.ts +13 -1
- package/dist/CodeEditor.svelte +29 -6
- package/dist/CodeEditor.svelte.d.ts +13 -1
- package/dist/DiffEditor.svelte +26 -5
- package/dist/DiffEditor.svelte.d.ts +11 -0
- package/dist/DiffFiles.svelte +81 -16
- package/dist/DiffFiles.svelte.d.ts +39 -0
- package/dist/DiffView.svelte +244 -46
- package/dist/DiffView.svelte.d.ts +126 -0
- package/dist/MergeView.svelte +267 -48
- package/dist/MergeView.svelte.d.ts +144 -3
- package/dist/PatchText.svelte +22 -4
- package/dist/PatchText.svelte.d.ts +11 -1
- package/dist/diff.d.ts +12 -6
- package/dist/diff.js +11 -5
- package/dist/index.d.ts +2 -0
- package/dist/labels.d.ts +6 -0
- package/dist/labels.js +23 -0
- package/dist/lite.d.ts +6 -1
- package/package.json +1 -1
package/dist/CodeBlock.svelte
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
export type CodeBlockLabels = {
|
|
3
|
+
/** Accessible name of the scrollable region. */
|
|
4
|
+
code: string;
|
|
5
|
+
/** Accessible name and tooltip of the copy button. */
|
|
6
|
+
copy: string;
|
|
7
|
+
/** Live-region text after a successful copy. */
|
|
8
|
+
copied: string;
|
|
9
|
+
/** Live-region text when copying failed. */
|
|
10
|
+
copyFailed: string;
|
|
11
|
+
};
|
|
12
|
+
const DEFAULTS: CodeBlockLabels = { code: 'Code', copy: 'Copy code', copied: 'Copied', copyFailed: 'Copy failed' };
|
|
13
|
+
</script>
|
|
14
|
+
|
|
1
15
|
<script lang="ts">
|
|
16
|
+
import { useLabels } from './labels.js';
|
|
2
17
|
import { csstext } from './cssvars.js';
|
|
3
18
|
import SsrStyle from './SsrStyle.svelte';
|
|
4
19
|
import { prepareMonacoCsp } from './monaco-csp.js';
|
|
@@ -22,7 +37,7 @@
|
|
|
22
37
|
path,
|
|
23
38
|
lineNumbers = false,
|
|
24
39
|
wrap = false,
|
|
25
|
-
label
|
|
40
|
+
label,
|
|
26
41
|
maxHeight,
|
|
27
42
|
maxLines,
|
|
28
43
|
height,
|
|
@@ -31,6 +46,7 @@
|
|
|
31
46
|
highlighter,
|
|
32
47
|
class: klass,
|
|
33
48
|
style: userStyle,
|
|
49
|
+
labels,
|
|
34
50
|
...rest
|
|
35
51
|
}: {
|
|
36
52
|
/** The text to show. */
|
|
@@ -43,7 +59,7 @@
|
|
|
43
59
|
lineNumbers?: boolean;
|
|
44
60
|
/** Wrap long lines instead of scrolling sideways. */
|
|
45
61
|
wrap?: boolean;
|
|
46
|
-
/** Accessible name of the scrollable region. */
|
|
62
|
+
/** Accessible name of the scrollable region (default: "Code"). */
|
|
47
63
|
label?: string;
|
|
48
64
|
/** A CSS length; the block scrolls beyond it. */
|
|
49
65
|
maxHeight?: string | number;
|
|
@@ -65,9 +81,13 @@
|
|
|
65
81
|
highlighter?: Highlighter;
|
|
66
82
|
class?: ClassValue;
|
|
67
83
|
style?: string;
|
|
84
|
+
/** Replaces the built-in texts (translation). Missing keys keep the defaults. */
|
|
85
|
+
labels?: Partial<CodeBlockLabels>;
|
|
68
86
|
[attr: string]: unknown;
|
|
69
87
|
} = $props();
|
|
70
88
|
|
|
89
|
+
const L = useLabels('CodeBlock', DEFAULTS, () => labels);
|
|
90
|
+
|
|
71
91
|
let el: HTMLPreElement;
|
|
72
92
|
let theme = $state.raw<Theme>();
|
|
73
93
|
let tokens = $state.raw<{ code: string; lang: string; segs: Seg[][] }>();
|
|
@@ -127,15 +147,15 @@
|
|
|
127
147
|
return () => { stale = true; };
|
|
128
148
|
});
|
|
129
149
|
|
|
130
|
-
let status = $state('');
|
|
150
|
+
let status = $state<'' | 'copied' | 'failed'>('');
|
|
131
151
|
let timer: ReturnType<typeof setTimeout>;
|
|
132
152
|
onDestroy(() => clearTimeout(timer));
|
|
133
153
|
async function copyCode() {
|
|
134
154
|
try {
|
|
135
155
|
await navigator.clipboard.writeText(code);
|
|
136
|
-
status = '
|
|
156
|
+
status = 'copied';
|
|
137
157
|
} catch {
|
|
138
|
-
status = '
|
|
158
|
+
status = 'failed';
|
|
139
159
|
}
|
|
140
160
|
clearTimeout(timer);
|
|
141
161
|
timer = setTimeout(() => (status = ''), 2000);
|
|
@@ -145,18 +165,18 @@
|
|
|
145
165
|
{#snippet block()}
|
|
146
166
|
<SsrStyle {uid} rules={{ '': style }} />
|
|
147
167
|
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
|
148
|
-
<pre {...rest} bind:this={el} data-sv={uid} role="region" class={['cb', klass]} class:wrap class:nums={lineNumbers} {@attach csstext(() => 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>
|
|
168
|
+
<pre {...rest} bind:this={el} data-sv={uid} role="region" class={['cb', klass]} class:wrap class:nums={lineNumbers} {@attach csstext(() => style)} {onscroll} tabindex="0" aria-label={label ?? L.code}><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>
|
|
149
169
|
{/snippet}
|
|
150
170
|
|
|
151
171
|
{#if copy}
|
|
152
172
|
<div class="box">
|
|
153
173
|
{@render block()}
|
|
154
174
|
<span class="copy">
|
|
155
|
-
<Tooltip text=
|
|
156
|
-
<Button variant="minimal" size="sm" icon={status === '
|
|
175
|
+
<Tooltip text={L.copy}>
|
|
176
|
+
<Button variant="minimal" size="sm" icon={status === 'copied' ? 'tick' : 'copy'} aria-label={L.copy} tooltip={false} onclick={copyCode} />
|
|
157
177
|
</Tooltip>
|
|
158
178
|
</span>
|
|
159
|
-
<span class="tr-visually-hidden" role="status" aria-live="polite">{status}</span>
|
|
179
|
+
<span class="tr-visually-hidden" role="status" aria-live="polite">{status === 'copied' ? L.copied : status === 'failed' ? L.copyFailed : ''}</span>
|
|
160
180
|
</div>
|
|
161
181
|
{:else}
|
|
162
182
|
{@render block()}
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
export type CodeBlockLabels = {
|
|
2
|
+
/** Accessible name of the scrollable region. */
|
|
3
|
+
code: string;
|
|
4
|
+
/** Accessible name and tooltip of the copy button. */
|
|
5
|
+
copy: string;
|
|
6
|
+
/** Live-region text after a successful copy. */
|
|
7
|
+
copied: string;
|
|
8
|
+
/** Live-region text when copying failed. */
|
|
9
|
+
copyFailed: string;
|
|
10
|
+
};
|
|
1
11
|
import type { ClassValue } from 'svelte/elements';
|
|
2
12
|
import type { Highlighter } from './editor-defaults.svelte.js';
|
|
3
13
|
import { type SqlDialect } from './lang.js';
|
|
@@ -12,7 +22,7 @@ type $$ComponentProps = {
|
|
|
12
22
|
lineNumbers?: boolean;
|
|
13
23
|
/** Wrap long lines instead of scrolling sideways. */
|
|
14
24
|
wrap?: boolean;
|
|
15
|
-
/** Accessible name of the scrollable region. */
|
|
25
|
+
/** Accessible name of the scrollable region (default: "Code"). */
|
|
16
26
|
label?: string;
|
|
17
27
|
/** A CSS length; the block scrolls beyond it. */
|
|
18
28
|
maxHeight?: string | number;
|
|
@@ -34,6 +44,8 @@ type $$ComponentProps = {
|
|
|
34
44
|
highlighter?: Highlighter;
|
|
35
45
|
class?: ClassValue;
|
|
36
46
|
style?: string;
|
|
47
|
+
/** Replaces the built-in texts (translation). Missing keys keep the defaults. */
|
|
48
|
+
labels?: Partial<CodeBlockLabels>;
|
|
37
49
|
[attr: string]: unknown;
|
|
38
50
|
};
|
|
39
51
|
declare const CodeBlock: import("svelte").Component<$$ComponentProps, {}, "follow">;
|
package/dist/CodeEditor.svelte
CHANGED
|
@@ -2,9 +2,27 @@
|
|
|
2
2
|
import { useMonacoByDefault } from './monaco-default.js';
|
|
3
3
|
// bundling an editor is what opts the app into Monaco: unless the app registered its own loader, use the built-in one
|
|
4
4
|
useMonacoByDefault();
|
|
5
|
+
|
|
6
|
+
export type CodeEditorLabels = {
|
|
7
|
+
/** Accessible name of the editor. */
|
|
8
|
+
codeEditor: string;
|
|
9
|
+
/** Name of the placeholder shown while the editor loads. */
|
|
10
|
+
loading: string;
|
|
11
|
+
/** Shown when the editor could not be loaded; `reason` is the loader's error message. */
|
|
12
|
+
loadFailed: (reason: string) => string;
|
|
13
|
+
/** Screen-reader description of the editor: how to leave it with Tab. */
|
|
14
|
+
tabHint: string;
|
|
15
|
+
};
|
|
16
|
+
const DEFAULTS: CodeEditorLabels = {
|
|
17
|
+
codeEditor: 'Code editor',
|
|
18
|
+
loading: 'Loading editor',
|
|
19
|
+
loadFailed: (reason) => `The editor could not be loaded: ${reason}`,
|
|
20
|
+
tabHint: 'Tab moves focus out of the editor when you press Control plus M; press Control plus M again to make Tab insert indentation.'
|
|
21
|
+
};
|
|
5
22
|
</script>
|
|
6
23
|
|
|
7
24
|
<script lang="ts">
|
|
25
|
+
import { useLabels } from './labels.js';
|
|
8
26
|
import { csstext } from './cssvars.js';
|
|
9
27
|
import SsrStyle from './SsrStyle.svelte';
|
|
10
28
|
import { prepareMonacoCsp } from './monaco-csp.js';
|
|
@@ -35,7 +53,7 @@
|
|
|
35
53
|
wordWrap,
|
|
36
54
|
height = 320,
|
|
37
55
|
screenReader,
|
|
38
|
-
label
|
|
56
|
+
label,
|
|
39
57
|
markers = [],
|
|
40
58
|
completions,
|
|
41
59
|
autoSurround,
|
|
@@ -46,6 +64,7 @@
|
|
|
46
64
|
onsave,
|
|
47
65
|
onrun,
|
|
48
66
|
onready,
|
|
67
|
+
labels,
|
|
49
68
|
class: klass = '',
|
|
50
69
|
style,
|
|
51
70
|
...rest
|
|
@@ -72,7 +91,7 @@
|
|
|
72
91
|
height?: number | string | 'fill';
|
|
73
92
|
/** `auto` follows the operating system's screen reader detection; `on` forces Monaco's screen-reader mode, `off` disables it. */
|
|
74
93
|
screenReader?: 'auto' | 'on' | 'off';
|
|
75
|
-
/** The accessible name of the editor. */
|
|
94
|
+
/** The accessible name of the editor (default: "Code editor"). */
|
|
76
95
|
label?: string;
|
|
77
96
|
/** Diagnostics for the current model. */
|
|
78
97
|
markers?: CodeMarker[];
|
|
@@ -94,8 +113,12 @@
|
|
|
94
113
|
onrun?: (value: string) => void;
|
|
95
114
|
/** The Monaco editor is created: gives you the instance and the Monaco namespace for anything not covered by props. */
|
|
96
115
|
onready?: (editor: Monaco.editor.IStandaloneCodeEditor, monaco: MonacoApi) => void;
|
|
116
|
+
/** Replaces the built-in texts (translation). Missing keys keep the defaults. */
|
|
117
|
+
labels?: Partial<CodeEditorLabels>;
|
|
97
118
|
} = $props();
|
|
98
119
|
|
|
120
|
+
const L = useLabels('CodeEditor', DEFAULTS, () => labels);
|
|
121
|
+
|
|
99
122
|
const id = $props.id();
|
|
100
123
|
let host: HTMLDivElement;
|
|
101
124
|
let monaco = $state.raw<MonacoApi>();
|
|
@@ -235,7 +258,7 @@
|
|
|
235
258
|
lineNumbers: (lineNumbers ?? dflt.lineNumbers ?? true) ? 'on' : 'off',
|
|
236
259
|
wordWrap: (wordWrap ?? dflt.wordWrap ?? false) ? 'on' : 'off',
|
|
237
260
|
accessibilitySupport: screenReader ?? dflt.screenReader ?? 'auto',
|
|
238
|
-
ariaLabel: label,
|
|
261
|
+
ariaLabel: label ?? L.codeEditor,
|
|
239
262
|
autoSurround: autoSurround ?? dflt.autoSurround ?? 'languageDefined',
|
|
240
263
|
autoClosingBrackets: autoClosingBrackets ?? dflt.autoClosingBrackets ?? 'languageDefined',
|
|
241
264
|
autoClosingQuotes: autoClosingQuotes ?? dflt.autoClosingQuotes ?? 'languageDefined',
|
|
@@ -287,14 +310,14 @@
|
|
|
287
310
|
</script>
|
|
288
311
|
|
|
289
312
|
<SsrStyle uid={id} rules={{ '': `${css ? `height:${css};` : ''}${style ?? ''}` }} />
|
|
290
|
-
<div {...rest} data-sv={id} class="ce {klass}" {@attach csstext(() => `${css ? `height:${css};` : ''}${style ?? ''}`)} data-ready={ready} role="group" aria-label={label} aria-describedby="ce-hint-{id}">
|
|
313
|
+
<div {...rest} data-sv={id} class="ce {klass}" {@attach csstext(() => `${css ? `height:${css};` : ''}${style ?? ''}`)} data-ready={ready} role="group" aria-label={label ?? L.codeEditor} aria-describedby="ce-hint-{id}">
|
|
291
314
|
<div class="mount" bind:this={host}></div>
|
|
292
315
|
{#if !ready}
|
|
293
316
|
<div class="ph">
|
|
294
|
-
{#if failed}<p role="alert">
|
|
317
|
+
{#if failed}<p role="alert">{L.loadFailed(failed)}</p>{:else}<Skeleton variant="rect" height="100%" label={L.loading} />{/if}
|
|
295
318
|
</div>
|
|
296
319
|
{/if}
|
|
297
|
-
<span class="vh" id="ce-hint-{id}">
|
|
320
|
+
<span class="vh" id="ce-hint-{id}">{L.tabHint}</span>
|
|
298
321
|
</div>
|
|
299
322
|
|
|
300
323
|
<style>
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
export type CodeEditorLabels = {
|
|
2
|
+
/** Accessible name of the editor. */
|
|
3
|
+
codeEditor: string;
|
|
4
|
+
/** Name of the placeholder shown while the editor loads. */
|
|
5
|
+
loading: string;
|
|
6
|
+
/** Shown when the editor could not be loaded; `reason` is the loader's error message. */
|
|
7
|
+
loadFailed: (reason: string) => string;
|
|
8
|
+
/** Screen-reader description of the editor: how to leave it with Tab. */
|
|
9
|
+
tabHint: string;
|
|
10
|
+
};
|
|
1
11
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
2
12
|
import type * as Monaco from 'monaco-editor';
|
|
3
13
|
import { type MonacoApi, type TypeScriptSetup } from './monaco.js';
|
|
@@ -27,7 +37,7 @@ type $$ComponentProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'oncha
|
|
|
27
37
|
height?: number | string | 'fill';
|
|
28
38
|
/** `auto` follows the operating system's screen reader detection; `on` forces Monaco's screen-reader mode, `off` disables it. */
|
|
29
39
|
screenReader?: 'auto' | 'on' | 'off';
|
|
30
|
-
/** The accessible name of the editor. */
|
|
40
|
+
/** The accessible name of the editor (default: "Code editor"). */
|
|
31
41
|
label?: string;
|
|
32
42
|
/** Diagnostics for the current model. */
|
|
33
43
|
markers?: CodeMarker[];
|
|
@@ -49,6 +59,8 @@ type $$ComponentProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'oncha
|
|
|
49
59
|
onrun?: (value: string) => void;
|
|
50
60
|
/** The Monaco editor is created: gives you the instance and the Monaco namespace for anything not covered by props. */
|
|
51
61
|
onready?: (editor: Monaco.editor.IStandaloneCodeEditor, monaco: MonacoApi) => void;
|
|
62
|
+
/** Replaces the built-in texts (translation). Missing keys keep the defaults. */
|
|
63
|
+
labels?: Partial<CodeEditorLabels>;
|
|
52
64
|
};
|
|
53
65
|
declare const CodeEditor: import("svelte").Component<$$ComponentProps, {
|
|
54
66
|
/** The focusable Monaco editor instance, once loaded. */ getEditor: () => Monaco.editor.IStandaloneCodeEditor | undefined;
|
package/dist/DiffEditor.svelte
CHANGED
|
@@ -2,9 +2,24 @@
|
|
|
2
2
|
import { useMonacoByDefault } from './monaco-default.js';
|
|
3
3
|
// bundling an editor is what opts the app into Monaco: unless the app registered its own loader, use the built-in one
|
|
4
4
|
useMonacoByDefault();
|
|
5
|
+
|
|
6
|
+
export type DiffEditorLabels = {
|
|
7
|
+
/** Accessible name of the editor. */
|
|
8
|
+
diffEditor: string;
|
|
9
|
+
/** Name of the placeholder shown while the editor loads. */
|
|
10
|
+
loading: string;
|
|
11
|
+
/** Shown when the editor could not be loaded; `reason` is the loader's error message. */
|
|
12
|
+
loadFailed: (reason: string) => string;
|
|
13
|
+
};
|
|
14
|
+
const DEFAULTS: DiffEditorLabels = {
|
|
15
|
+
diffEditor: 'Diff editor',
|
|
16
|
+
loading: 'Loading editor',
|
|
17
|
+
loadFailed: (reason) => `The editor could not be loaded: ${reason}`
|
|
18
|
+
};
|
|
5
19
|
</script>
|
|
6
20
|
|
|
7
21
|
<script lang="ts">
|
|
22
|
+
import { useLabels } from './labels.js';
|
|
8
23
|
import { cssvars } from './cssvars.js';
|
|
9
24
|
import SsrStyle from './SsrStyle.svelte';
|
|
10
25
|
import { prepareMonacoCsp } from './monaco-csp.js';
|
|
@@ -27,10 +42,11 @@
|
|
|
27
42
|
originalEditable = false,
|
|
28
43
|
ignoreTrimWhitespace = true,
|
|
29
44
|
height = 320,
|
|
30
|
-
label
|
|
45
|
+
label,
|
|
31
46
|
options,
|
|
32
47
|
onchange,
|
|
33
|
-
onready
|
|
48
|
+
onready,
|
|
49
|
+
labels
|
|
34
50
|
}: {
|
|
35
51
|
/** The left side. */
|
|
36
52
|
original?: string;
|
|
@@ -48,14 +64,19 @@
|
|
|
48
64
|
ignoreTrimWhitespace?: boolean;
|
|
49
65
|
/** A pixel height, any CSS length, or `'fill'` for the parent's height. */
|
|
50
66
|
height?: number | string | 'fill';
|
|
67
|
+
/** The accessible name of the editor (default: "Diff editor"). */
|
|
51
68
|
label?: string;
|
|
52
69
|
/** Any Monaco `IDiffEditorConstructionOptions`, applied after the props above. */
|
|
53
70
|
options?: Monaco.editor.IDiffEditorConstructionOptions;
|
|
54
71
|
/** Fires with the modified text after every edit made by the user. */
|
|
55
72
|
onchange?: (value: string) => void;
|
|
56
73
|
onready?: (editor: Monaco.editor.IStandaloneDiffEditor, monaco: MonacoApi) => void;
|
|
74
|
+
/** Replaces the built-in texts (translation). Missing keys keep the defaults. */
|
|
75
|
+
labels?: Partial<DiffEditorLabels>;
|
|
57
76
|
} = $props();
|
|
58
77
|
|
|
78
|
+
const L = useLabels('DiffEditor', DEFAULTS, () => labels);
|
|
79
|
+
|
|
59
80
|
const id = $props.id();
|
|
60
81
|
let host: HTMLDivElement;
|
|
61
82
|
let monaco = $state.raw<MonacoApi>();
|
|
@@ -125,7 +146,7 @@
|
|
|
125
146
|
readOnly: readonly,
|
|
126
147
|
originalEditable,
|
|
127
148
|
ignoreTrimWhitespace,
|
|
128
|
-
ariaLabel: label,
|
|
149
|
+
ariaLabel: label ?? L.diffEditor,
|
|
129
150
|
fontSize: metrics.fontSize,
|
|
130
151
|
lineHeight: metrics.lineHeight,
|
|
131
152
|
fontFamily: metrics.fontFamily,
|
|
@@ -135,11 +156,11 @@
|
|
|
135
156
|
</script>
|
|
136
157
|
|
|
137
158
|
<SsrStyle uid={id} rules={{ '': `height:${css}` }} />
|
|
138
|
-
<div class="de" data-sv={id} {@attach cssvars(() => ({ 'height': css }))} data-ready={ready} role="group" aria-label={label}>
|
|
159
|
+
<div class="de" data-sv={id} {@attach cssvars(() => ({ 'height': css }))} data-ready={ready} role="group" aria-label={label ?? L.diffEditor}>
|
|
139
160
|
<div class="mount" bind:this={host}></div>
|
|
140
161
|
{#if !ready}
|
|
141
162
|
<div class="ph">
|
|
142
|
-
{#if failed}<p role="alert">
|
|
163
|
+
{#if failed}<p role="alert">{L.loadFailed(failed)}</p>{:else}<Skeleton variant="rect" height="100%" label={L.loading} />{/if}
|
|
143
164
|
</div>
|
|
144
165
|
{/if}
|
|
145
166
|
</div>
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
export type DiffEditorLabels = {
|
|
2
|
+
/** Accessible name of the editor. */
|
|
3
|
+
diffEditor: string;
|
|
4
|
+
/** Name of the placeholder shown while the editor loads. */
|
|
5
|
+
loading: string;
|
|
6
|
+
/** Shown when the editor could not be loaded; `reason` is the loader's error message. */
|
|
7
|
+
loadFailed: (reason: string) => string;
|
|
8
|
+
};
|
|
1
9
|
import type * as Monaco from 'monaco-editor';
|
|
2
10
|
import { type MonacoApi } from './monaco.js';
|
|
3
11
|
type $$ComponentProps = {
|
|
@@ -17,12 +25,15 @@ type $$ComponentProps = {
|
|
|
17
25
|
ignoreTrimWhitespace?: boolean;
|
|
18
26
|
/** A pixel height, any CSS length, or `'fill'` for the parent's height. */
|
|
19
27
|
height?: number | string | 'fill';
|
|
28
|
+
/** The accessible name of the editor (default: "Diff editor"). */
|
|
20
29
|
label?: string;
|
|
21
30
|
/** Any Monaco `IDiffEditorConstructionOptions`, applied after the props above. */
|
|
22
31
|
options?: Monaco.editor.IDiffEditorConstructionOptions;
|
|
23
32
|
/** Fires with the modified text after every edit made by the user. */
|
|
24
33
|
onchange?: (value: string) => void;
|
|
25
34
|
onready?: (editor: Monaco.editor.IStandaloneDiffEditor, monaco: MonacoApi) => void;
|
|
35
|
+
/** Replaces the built-in texts (translation). Missing keys keep the defaults. */
|
|
36
|
+
labels?: Partial<DiffEditorLabels>;
|
|
26
37
|
};
|
|
27
38
|
declare const DiffEditor: import("svelte").Component<$$ComponentProps, {
|
|
28
39
|
/** The Monaco diff editor, once loaded. */ getEditor: () => Monaco.editor.IStandaloneDiffEditor | undefined;
|
package/dist/DiffFiles.svelte
CHANGED
|
@@ -1,11 +1,66 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
import type { DiffStatus } from './files.js';
|
|
3
|
+
|
|
4
|
+
export type DiffFilesLabels = {
|
|
5
|
+
/** Accessible name of the whole list and of the file tree. */
|
|
6
|
+
changedFiles: string;
|
|
7
|
+
/** Summary line: how many files changed (the additions and deletions follow it). */
|
|
8
|
+
filesChanged: (n: number) => string;
|
|
9
|
+
/** Summary line: how many of the files are marked viewed. */
|
|
10
|
+
viewedCount: (viewed: number, total: number) => string;
|
|
11
|
+
/** Accessible name of the layout switch. */
|
|
12
|
+
layout: string;
|
|
13
|
+
/** Layout option: one column. */
|
|
14
|
+
unified: string;
|
|
15
|
+
/** Layout option: two columns. */
|
|
16
|
+
split: string;
|
|
17
|
+
/** Layout option: one column with the changed words marked in line. */
|
|
18
|
+
inline: string;
|
|
19
|
+
/** Accessible name of each file's diff. */
|
|
20
|
+
changes: string;
|
|
21
|
+
/** Accessible name of a file's button that folds its diff. */
|
|
22
|
+
collapse: (path: string) => string;
|
|
23
|
+
/** Accessible name of a file's button that unfolds its diff. */
|
|
24
|
+
expand: (path: string) => string;
|
|
25
|
+
/** A file's status, in its badge and in the tree: `added`, `modified`, `deleted` or `renamed`. */
|
|
26
|
+
status: (status: DiffStatus) => string;
|
|
27
|
+
/** Label of each file's "viewed" checkbox. */
|
|
28
|
+
viewed: string;
|
|
29
|
+
/** Accessible name of that checkbox. */
|
|
30
|
+
viewedFile: (path: string) => string;
|
|
31
|
+
/** Tooltip of a file's status in the tree: the status word (from `status`) and the line counts. */
|
|
32
|
+
fileSummary: (status: string, added: number, removed: number) => string;
|
|
33
|
+
/** Shown when there is nothing to list. */
|
|
34
|
+
noFiles: string;
|
|
35
|
+
};
|
|
36
|
+
const DEFAULTS: DiffFilesLabels = {
|
|
37
|
+
changedFiles: 'Changed files',
|
|
38
|
+
filesChanged: (n) => `${n} ${n === 1 ? 'file' : 'files'} changed`,
|
|
39
|
+
viewedCount: (viewed, total) => `${viewed} of ${total} viewed`,
|
|
40
|
+
layout: 'Diff layout',
|
|
41
|
+
unified: 'Unified',
|
|
42
|
+
split: 'Split',
|
|
43
|
+
inline: 'Inline',
|
|
44
|
+
changes: 'Changes',
|
|
45
|
+
collapse: (path) => `Collapse ${path}`,
|
|
46
|
+
expand: (path) => `Expand ${path}`,
|
|
47
|
+
status: (status) => status,
|
|
48
|
+
viewed: 'Viewed',
|
|
49
|
+
viewedFile: (path) => `Viewed ${path}`,
|
|
50
|
+
fileSummary: (status, added, removed) => `${status}, ${added} added, ${removed} removed`,
|
|
51
|
+
noFiles: 'No files changed.'
|
|
52
|
+
};
|
|
53
|
+
</script>
|
|
54
|
+
|
|
1
55
|
<script lang="ts">
|
|
56
|
+
import { useLabels } from './labels.js';
|
|
2
57
|
import { tick, onMount, type Snippet } from 'svelte';
|
|
3
58
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
59
|
import { Badge, Button, Checkbox, Icon, SegmentedControl, Tooltip, Tree } from '@ruckc/truss-ui';
|
|
5
60
|
import type { TreeNode } from '@ruckc/truss-ui';
|
|
6
|
-
import DiffView from './DiffView.svelte';
|
|
61
|
+
import DiffView, { type DiffViewLabels } from './DiffView.svelte';
|
|
7
62
|
import { cachedLoader, type LoadText } from './load.js';
|
|
8
|
-
import { buildTree, entriesFromPatch, entryFromInput, folderIds, statusLetter, totals, type DiffFileInput, type
|
|
63
|
+
import { buildTree, entriesFromPatch, entryFromInput, folderIds, statusLetter, totals, type DiffFileInput, type FileEntry } from './files.js';
|
|
9
64
|
|
|
10
65
|
let {
|
|
11
66
|
files = [],
|
|
@@ -25,7 +80,9 @@
|
|
|
25
80
|
maxLines = 200000,
|
|
26
81
|
virtualize,
|
|
27
82
|
detectMoves = false,
|
|
28
|
-
label
|
|
83
|
+
label,
|
|
84
|
+
labels,
|
|
85
|
+
viewLabels,
|
|
29
86
|
onviewed,
|
|
30
87
|
fileExtra,
|
|
31
88
|
fileExtraPosition = 'above',
|
|
@@ -60,7 +117,12 @@
|
|
|
60
117
|
virtualize?: boolean | number;
|
|
61
118
|
/** Mark blocks moved within a file. */
|
|
62
119
|
detectMoves?: boolean;
|
|
120
|
+
/** Accessible name of the list (default: "Changed files"). */
|
|
63
121
|
label?: string;
|
|
122
|
+
/** Replaces the built-in texts (translation). Missing keys keep the defaults. */
|
|
123
|
+
labels?: Partial<DiffFilesLabels>;
|
|
124
|
+
/** The texts of each file's `DiffView` (translation), passed on to every one of them. */
|
|
125
|
+
viewLabels?: Partial<DiffViewLabels>;
|
|
64
126
|
onviewed?: (path: string, viewed: boolean) => void;
|
|
65
127
|
/** Rendered inside each open file's body, next to its diff (for example review threads or a summary). Receives the file (`path`, `status`, counts...) and its position in the list. */
|
|
66
128
|
fileExtra?: Snippet<[info: { file: FileEntry; index: number }]>;
|
|
@@ -73,6 +135,8 @@
|
|
|
73
135
|
class?: string;
|
|
74
136
|
} & Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'class' | 'role' | 'onkeydown'> = $props();
|
|
75
137
|
|
|
138
|
+
const L = useLabels('DiffFiles', DEFAULTS, () => labels);
|
|
139
|
+
|
|
76
140
|
let root: HTMLDivElement;
|
|
77
141
|
const views = $state<Record<string, { goto(where: 'first' | 'last'): boolean; focus(): void } | null | undefined>>({});
|
|
78
142
|
let expanded = $state<string[]>([]);
|
|
@@ -144,17 +208,17 @@
|
|
|
144
208
|
</script>
|
|
145
209
|
|
|
146
210
|
<!-- svelte-ignore a11y_no_noninteractive_element_interactions -->
|
|
147
|
-
<div bind:this={root} class={['df', cls]} {...rest} role="group" aria-label={label} onkeydown={onkey}>
|
|
211
|
+
<div bind:this={root} class={['df', cls]} {...rest} role="group" aria-label={label ?? L.changedFiles} onkeydown={onkey}>
|
|
148
212
|
<div class="top">
|
|
149
|
-
<span class="sum" data-testid="files-summary">{
|
|
150
|
-
<span class="prog" data-testid="viewed-count">{viewed.filter((p) => entries.some((e) => e.path === p)).length
|
|
213
|
+
<span class="sum" data-testid="files-summary">{L.filesChanged(sum.files)}<span class="plus">+{sum.additions}</span><span class="minus">−{sum.deletions}</span></span>
|
|
214
|
+
<span class="prog" data-testid="viewed-count">{L.viewedCount(viewed.filter((p) => entries.some((e) => e.path === p)).length, sum.files)}</span>
|
|
151
215
|
<span class="grow"></span>
|
|
152
|
-
<SegmentedControl size="sm" label=
|
|
216
|
+
<SegmentedControl size="sm" label={L.layout} value={layout} onchange={setLayout} options={[{ value: 'unified', label: L.unified }, { value: 'split', label: L.split }, { value: 'inline-word', label: L.inline }]} />
|
|
153
217
|
</div>
|
|
154
218
|
<div class="main">
|
|
155
219
|
{#if tree && entries.length}
|
|
156
|
-
<nav class="side" aria-label=
|
|
157
|
-
<Tree {nodes} bind:expanded {selected} {onselect} label=
|
|
220
|
+
<nav class="side" aria-label={L.changedFiles}>
|
|
221
|
+
<Tree {nodes} bind:expanded {selected} {onselect} label={L.changedFiles} nodeActions={status} />
|
|
158
222
|
</nav>
|
|
159
223
|
{/if}
|
|
160
224
|
<div class="list">
|
|
@@ -162,13 +226,13 @@
|
|
|
162
226
|
{@const open = !collapsedSet.has(f.path)}
|
|
163
227
|
<section data-testid="diff-file-{f.path}" {...fileAttrs?.(f)} id="{uid}-{slug(f.path)}" class="file" data-path={f.path} data-status={f.status} data-viewed={viewedSet.has(f.path)} aria-label={f.path}>
|
|
164
228
|
<header class="fh">
|
|
165
|
-
<Button variant="minimal" intent="neutral" size="sm" aria-expanded={open} aria-controls="{uid}-{slug(f.path)}-body" aria-label=
|
|
229
|
+
<Button variant="minimal" intent="neutral" size="sm" aria-expanded={open} aria-controls="{uid}-{slug(f.path)}-body" aria-label={open ? L.collapse(f.path) : L.expand(f.path)} onclick={() => toggle(f.path)}>
|
|
166
230
|
<Icon name={open ? 'chevron-down' : 'chevron-right'} />
|
|
167
231
|
</Button>
|
|
168
|
-
<Badge intent={BADGE[f.status]} dot={false}>{f.status}</Badge>
|
|
232
|
+
<Badge intent={BADGE[f.status]} dot={false}>{L.status(f.status)}</Badge>
|
|
169
233
|
<span class="path">{#if f.oldPath && f.oldPath !== f.path}<span class="old">{f.oldPath}</span> → {/if}<strong>{f.path}</strong></span>
|
|
170
234
|
<span class="stats"><span class="plus">+{f.additions}</span><span class="minus">−{f.deletions}</span></span>
|
|
171
|
-
<Checkbox label=
|
|
235
|
+
<Checkbox label={L.viewed} checked={viewedSet.has(f.path)} oncheckedchange={(on) => setViewed(f.path, on)} aria-label={L.viewedFile(f.path)} />
|
|
172
236
|
</header>
|
|
173
237
|
{#if open}
|
|
174
238
|
<div id="{uid}-{slug(f.path)}-body" class="body">
|
|
@@ -190,7 +254,8 @@
|
|
|
190
254
|
{virtualize}
|
|
191
255
|
{detectMoves}
|
|
192
256
|
toolbar={false}
|
|
193
|
-
label=
|
|
257
|
+
label={L.changes}
|
|
258
|
+
labels={viewLabels}
|
|
194
259
|
load={f.file ? loader : undefined}
|
|
195
260
|
onedge={(dir) => hop(i, dir)}
|
|
196
261
|
/>
|
|
@@ -199,7 +264,7 @@
|
|
|
199
264
|
{/if}
|
|
200
265
|
</section>
|
|
201
266
|
{:else}
|
|
202
|
-
<p class="empty" role="status">
|
|
267
|
+
<p class="empty" role="status">{L.noFiles}</p>
|
|
203
268
|
{/each}
|
|
204
269
|
</div>
|
|
205
270
|
</div>
|
|
@@ -209,8 +274,8 @@
|
|
|
209
274
|
{#snippet status(n: TreeNode)}
|
|
210
275
|
{@const e = byPath.get(n.id)}
|
|
211
276
|
{#if e}
|
|
212
|
-
<Tooltip text=
|
|
213
|
-
<span class="st" data-status={e.status}><span aria-hidden="true">{statusLetter(e.status)}</span><span class="vh">{e.status}</span></span>
|
|
277
|
+
<Tooltip text={L.fileSummary(L.status(e.status), e.additions, e.deletions)} placement="right">
|
|
278
|
+
<span class="st" data-status={e.status}><span aria-hidden="true">{statusLetter(e.status)}</span><span class="vh">{L.status(e.status)}</span></span>
|
|
214
279
|
</Tooltip>
|
|
215
280
|
{/if}
|
|
216
281
|
{/snippet}
|
|
@@ -1,5 +1,39 @@
|
|
|
1
|
+
import type { DiffStatus } from './files.js';
|
|
2
|
+
export type DiffFilesLabels = {
|
|
3
|
+
/** Accessible name of the whole list and of the file tree. */
|
|
4
|
+
changedFiles: string;
|
|
5
|
+
/** Summary line: how many files changed (the additions and deletions follow it). */
|
|
6
|
+
filesChanged: (n: number) => string;
|
|
7
|
+
/** Summary line: how many of the files are marked viewed. */
|
|
8
|
+
viewedCount: (viewed: number, total: number) => string;
|
|
9
|
+
/** Accessible name of the layout switch. */
|
|
10
|
+
layout: string;
|
|
11
|
+
/** Layout option: one column. */
|
|
12
|
+
unified: string;
|
|
13
|
+
/** Layout option: two columns. */
|
|
14
|
+
split: string;
|
|
15
|
+
/** Layout option: one column with the changed words marked in line. */
|
|
16
|
+
inline: string;
|
|
17
|
+
/** Accessible name of each file's diff. */
|
|
18
|
+
changes: string;
|
|
19
|
+
/** Accessible name of a file's button that folds its diff. */
|
|
20
|
+
collapse: (path: string) => string;
|
|
21
|
+
/** Accessible name of a file's button that unfolds its diff. */
|
|
22
|
+
expand: (path: string) => string;
|
|
23
|
+
/** A file's status, in its badge and in the tree: `added`, `modified`, `deleted` or `renamed`. */
|
|
24
|
+
status: (status: DiffStatus) => string;
|
|
25
|
+
/** Label of each file's "viewed" checkbox. */
|
|
26
|
+
viewed: string;
|
|
27
|
+
/** Accessible name of that checkbox. */
|
|
28
|
+
viewedFile: (path: string) => string;
|
|
29
|
+
/** Tooltip of a file's status in the tree: the status word (from `status`) and the line counts. */
|
|
30
|
+
fileSummary: (status: string, added: number, removed: number) => string;
|
|
31
|
+
/** Shown when there is nothing to list. */
|
|
32
|
+
noFiles: string;
|
|
33
|
+
};
|
|
1
34
|
import { type Snippet } from 'svelte';
|
|
2
35
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
36
|
+
import { type DiffViewLabels } from './DiffView.svelte';
|
|
3
37
|
import { type LoadText } from './load.js';
|
|
4
38
|
import { type DiffFileInput, type FileEntry } from './files.js';
|
|
5
39
|
type $$ComponentProps = {
|
|
@@ -29,7 +63,12 @@ type $$ComponentProps = {
|
|
|
29
63
|
virtualize?: boolean | number;
|
|
30
64
|
/** Mark blocks moved within a file. */
|
|
31
65
|
detectMoves?: boolean;
|
|
66
|
+
/** Accessible name of the list (default: "Changed files"). */
|
|
32
67
|
label?: string;
|
|
68
|
+
/** Replaces the built-in texts (translation). Missing keys keep the defaults. */
|
|
69
|
+
labels?: Partial<DiffFilesLabels>;
|
|
70
|
+
/** The texts of each file's `DiffView` (translation), passed on to every one of them. */
|
|
71
|
+
viewLabels?: Partial<DiffViewLabels>;
|
|
33
72
|
onviewed?: (path: string, viewed: boolean) => void;
|
|
34
73
|
/** Rendered inside each open file's body, next to its diff (for example review threads or a summary). Receives the file (`path`, `status`, counts...) and its position in the list. */
|
|
35
74
|
fileExtra?: Snippet<[info: {
|