@ruckc/truss-code 1.48.1 → 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/PatchText.svelte
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
|
+
<script module lang="ts">
|
|
2
|
+
export type PatchTextLabels = {
|
|
3
|
+
/** Accessible name of the scrollable region. */
|
|
4
|
+
patchText: string;
|
|
5
|
+
/** Screen-reader text before an added line (the line's `+` is hidden from readers). */
|
|
6
|
+
added: string;
|
|
7
|
+
/** Screen-reader text before a removed line. */
|
|
8
|
+
removed: string;
|
|
9
|
+
};
|
|
10
|
+
const DEFAULTS: PatchTextLabels = { patchText: 'Patch text', added: 'added', removed: 'removed' };
|
|
11
|
+
</script>
|
|
12
|
+
|
|
1
13
|
<script lang="ts">
|
|
14
|
+
import { useLabels } from './labels.js';
|
|
2
15
|
import { csstext } from './cssvars.js';
|
|
3
16
|
import SsrStyle from './SsrStyle.svelte';
|
|
4
17
|
const uid = $props.id();
|
|
@@ -7,31 +20,36 @@
|
|
|
7
20
|
|
|
8
21
|
let {
|
|
9
22
|
text,
|
|
10
|
-
label
|
|
23
|
+
label,
|
|
11
24
|
maxHeight,
|
|
12
25
|
wrap = false,
|
|
13
26
|
lineNumbers = false,
|
|
27
|
+
labels,
|
|
14
28
|
...rest
|
|
15
29
|
}: Omit<HTMLAttributes<HTMLPreElement>, 'children'> & {
|
|
16
30
|
/** Unified-diff-like text. It does not have to be a valid patch: lines starting with `+`, `-`, `@@` or `#` are coloured, any other line is plain. */
|
|
17
31
|
text: string;
|
|
18
|
-
/** Accessible name of the scrollable region. */
|
|
32
|
+
/** Accessible name of the scrollable region (default: "Patch text"). */
|
|
19
33
|
label?: string;
|
|
20
34
|
/** A CSS length; the view scrolls beyond it. */
|
|
21
35
|
maxHeight?: string | number;
|
|
22
36
|
/** Wrap long lines instead of scrolling sideways. */
|
|
23
37
|
wrap?: boolean;
|
|
24
38
|
lineNumbers?: boolean;
|
|
39
|
+
/** Replaces the built-in texts (translation). Missing keys keep the defaults. */
|
|
40
|
+
labels?: Partial<PatchTextLabels>;
|
|
25
41
|
} = $props();
|
|
26
42
|
|
|
27
|
-
const
|
|
43
|
+
const L = useLabels('PatchText', DEFAULTS, () => labels);
|
|
44
|
+
|
|
45
|
+
const MARK = $derived<Partial<Record<MarkKind, { sym: string; sr: string }>>>({ add: { sym: '+', sr: L.added }, del: { sym: '−', sr: L.removed } });
|
|
28
46
|
const lines = $derived(markLines(text).map((l) => ({ ...l, mark: MARK[l.kind], body: MARK[l.kind] ? l.text.slice(1) : l.text })));
|
|
29
47
|
const style = $derived(maxHeight != null ? `max-height:${typeof maxHeight === 'number' ? maxHeight + 'px' : maxHeight}` : undefined);
|
|
30
48
|
</script>
|
|
31
49
|
|
|
32
50
|
<SsrStyle {uid} rules={{ '': style ?? '' }} />
|
|
33
51
|
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
|
|
34
|
-
<pre {...rest} data-sv={uid} role="region" class="pt" class:wrap class:nums={lineNumbers} {@attach csstext(() => style)} tabindex="0" aria-label={label}><code>{#each lines as l, i (i)}<span class={"ln " + l.kind} data-kind={l.kind}>{#if lineNumbers}<span class="no" aria-hidden="true">{i + 1}</span>{/if}<span class="sym">{#if l.mark}<span aria-hidden="true">{l.mark.sym}</span><span class="vh">{l.mark.sr + ": "}</span>{/if}</span><span class="tx">{l.body + '\n'}</span></span>{/each}</code></pre>
|
|
52
|
+
<pre {...rest} data-sv={uid} role="region" class="pt" class:wrap class:nums={lineNumbers} {@attach csstext(() => style)} tabindex="0" aria-label={label ?? L.patchText}><code>{#each lines as l, i (i)}<span class={"ln " + l.kind} data-kind={l.kind}>{#if lineNumbers}<span class="no" aria-hidden="true">{i + 1}</span>{/if}<span class="sym">{#if l.mark}<span aria-hidden="true">{l.mark.sym}</span><span class="vh">{l.mark.sr + ": "}</span>{/if}</span><span class="tx">{l.body + '\n'}</span></span>{/each}</code></pre>
|
|
35
53
|
|
|
36
54
|
<style>
|
|
37
55
|
.pt {
|
|
@@ -1,14 +1,24 @@
|
|
|
1
|
+
export type PatchTextLabels = {
|
|
2
|
+
/** Accessible name of the scrollable region. */
|
|
3
|
+
patchText: string;
|
|
4
|
+
/** Screen-reader text before an added line (the line's `+` is hidden from readers). */
|
|
5
|
+
added: string;
|
|
6
|
+
/** Screen-reader text before a removed line. */
|
|
7
|
+
removed: string;
|
|
8
|
+
};
|
|
1
9
|
import type { HTMLAttributes } from 'svelte/elements';
|
|
2
10
|
type $$ComponentProps = Omit<HTMLAttributes<HTMLPreElement>, 'children'> & {
|
|
3
11
|
/** Unified-diff-like text. It does not have to be a valid patch: lines starting with `+`, `-`, `@@` or `#` are coloured, any other line is plain. */
|
|
4
12
|
text: string;
|
|
5
|
-
/** Accessible name of the scrollable region. */
|
|
13
|
+
/** Accessible name of the scrollable region (default: "Patch text"). */
|
|
6
14
|
label?: string;
|
|
7
15
|
/** A CSS length; the view scrolls beyond it. */
|
|
8
16
|
maxHeight?: string | number;
|
|
9
17
|
/** Wrap long lines instead of scrolling sideways. */
|
|
10
18
|
wrap?: boolean;
|
|
11
19
|
lineNumbers?: boolean;
|
|
20
|
+
/** Replaces the built-in texts (translation). Missing keys keep the defaults. */
|
|
21
|
+
labels?: Partial<PatchTextLabels>;
|
|
12
22
|
};
|
|
13
23
|
declare const PatchText: import("svelte").Component<$$ComponentProps, {}, "">;
|
|
14
24
|
type PatchText = ReturnType<typeof PatchText>;
|
package/dist/diff.d.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pure diff logic, no dependencies: line diff (Myers), intra-line word/character diff, hunks in `git diff`'s shape,
|
|
3
|
-
* collapsed regions and split-view pairing. Nothing here touches the DOM, so all of it is unit-tested directly.
|
|
4
|
-
*/
|
|
5
1
|
/** One line of a document: its text without the line ending, and what the ending was. */
|
|
6
2
|
export interface Line {
|
|
7
3
|
text: string;
|
|
@@ -150,8 +146,18 @@ export interface SplitRow {
|
|
|
150
146
|
}
|
|
151
147
|
/** Pairs a run of consecutive line indexes for side-by-side display: unchanged lines on both sides, the i-th removal beside the i-th addition. */
|
|
152
148
|
export declare function splitRows(lines: DiffLine[], indexes: number[]): SplitRow[];
|
|
153
|
-
/** The
|
|
154
|
-
export
|
|
149
|
+
/** The texts of `describeChange`; `DiffView` carries them as keys of its own labels (the component name below is that of `DiffView`). */
|
|
150
|
+
export type ChangeLabels = {
|
|
151
|
+
/** Screen-reader summary of a change: its number (from 1), how many there are, and what it holds (`removed` and `added` joined by a comma). */
|
|
152
|
+
change: (n: number, total: number, parts: string) => string;
|
|
153
|
+
/** The removed lines of a change, in that summary. */
|
|
154
|
+
linesRemoved: (count: number) => string;
|
|
155
|
+
/** The added lines of a change, in that summary. */
|
|
156
|
+
linesAdded: (count: number) => string;
|
|
157
|
+
};
|
|
158
|
+
export declare const CHANGE_DEFAULTS: ChangeLabels;
|
|
159
|
+
/** The screen-reader summary for a change: "Change 2 of 5: 3 lines removed, 4 lines added". `labels` are the component's resolved texts; without them the app-wide ones (`configureLabels`) and the English defaults apply. */
|
|
160
|
+
export declare function describeChange(lines: DiffLine[], starts: number[], n: number, labels?: Partial<ChangeLabels>): string;
|
|
155
161
|
export type Side = 'old' | 'new';
|
|
156
162
|
/** A range of line numbers on one side of the diff, both ends included. */
|
|
157
163
|
export interface LineSelection {
|
package/dist/diff.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Pure diff logic, no dependencies: line diff (Myers), intra-line word/character diff, hunks in `git diff`'s shape,
|
|
3
3
|
* collapsed regions and split-view pairing. Nothing here touches the DOM, so all of it is unit-tested directly.
|
|
4
4
|
*/
|
|
5
|
+
import { labelFor } from './labels.js';
|
|
5
6
|
/** Splits text on LF, CRLF or a lone CR. `''` is no lines; a final line ending does not start another line. */
|
|
6
7
|
export function splitDocument(text) {
|
|
7
8
|
if (text === '')
|
|
@@ -414,8 +415,14 @@ export function splitRows(lines, indexes) {
|
|
|
414
415
|
}
|
|
415
416
|
return rows;
|
|
416
417
|
}
|
|
417
|
-
|
|
418
|
-
|
|
418
|
+
export const CHANGE_DEFAULTS = {
|
|
419
|
+
change: (n, total, parts) => `Change ${n} of ${total}: ${parts}`,
|
|
420
|
+
linesRemoved: (count) => `${count} ${count === 1 ? 'line' : 'lines'} removed`,
|
|
421
|
+
linesAdded: (count) => `${count} ${count === 1 ? 'line' : 'lines'} added`
|
|
422
|
+
};
|
|
423
|
+
/** The screen-reader summary for a change: "Change 2 of 5: 3 lines removed, 4 lines added". `labels` are the component's resolved texts; without them the app-wide ones (`configureLabels`) and the English defaults apply. */
|
|
424
|
+
export function describeChange(lines, starts, n, labels) {
|
|
425
|
+
const L = (k) => labels?.[k] ?? labelFor('DiffView', k, CHANGE_DEFAULTS[k]);
|
|
419
426
|
const s = starts[n];
|
|
420
427
|
let e = s, del = 0, add = 0;
|
|
421
428
|
for (; e < lines.length && (lines[e].type === 'add' || lines[e].type === 'del'); e++) {
|
|
@@ -424,9 +431,8 @@ export function describeChange(lines, starts, n) {
|
|
|
424
431
|
else
|
|
425
432
|
add++;
|
|
426
433
|
}
|
|
427
|
-
const
|
|
428
|
-
|
|
429
|
-
return `Change ${n + 1} of ${starts.length}: ${parts.join(', ')}`;
|
|
434
|
+
const parts = [del ? L('linesRemoved')(del) : '', add ? L('linesAdded')(add) : ''].filter(Boolean);
|
|
435
|
+
return L('change')(n + 1, starts.length, parts.join(', '));
|
|
430
436
|
}
|
|
431
437
|
/** A line's number on a side (a removed line has no new number, an added line no old one). */
|
|
432
438
|
export const lineNo = (l, side) => (side === 'old' ? l.oldNo : l.newNo);
|
package/dist/index.d.ts
CHANGED
|
@@ -3,4 +3,6 @@ export { default as CodeEditor } from './CodeEditor.svelte';
|
|
|
3
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
|
+
export type { CodeEditorLabels } from './CodeEditor.svelte';
|
|
7
|
+
export type { DiffEditorLabels } from './DiffEditor.svelte';
|
|
6
8
|
export type { CompletionsOption } from './editor-util.js';
|
package/dist/labels.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** One label: a string, or a function for a string with values (`(n: number) => \`${n} selected\``). That covers plurals and word order without an ICU dependency. */
|
|
2
|
+
export type LabelValue = string | ((...args: never[]) => string);
|
|
3
|
+
/** @internal The labels of a component: `prop` over the context over `configureLabels` over `defaults`, read at the moment a key is used. Call during component initialisation (it reads context). */
|
|
4
|
+
export declare function useLabels<T extends object>(component: string, defaults: T, prop: () => Partial<T> | undefined): T;
|
|
5
|
+
/** @internal One app-wide label for code outside a component (no context there): `configureLabels` over `fallback`. */
|
|
6
|
+
export declare function labelFor<T extends LabelValue>(component: string, key: string, fallback: T): T;
|
package/dist/labels.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { getContext } from 'svelte';
|
|
2
|
+
const KEY = Symbol.for('@ruckc/truss-ui:labels');
|
|
3
|
+
const STATE = Symbol.for('@ruckc/truss-ui:labels-config');
|
|
4
|
+
// What `configureLabels` set for a component. Read-only here (no copy of this file has to create the state), and `Object(undefined)` is `{}`.
|
|
5
|
+
const config = (component) => Object(Object(globalThis[STATE])[component]);
|
|
6
|
+
// The strongest defined value wins (layers run from the weakest to the strongest). This reader is written without branches on purpose
|
|
7
|
+
// (`filter`, `Object(x)`, no `?.` / `??` / `if`): it is copied into every package, and V8 coverage counts each short-circuit as a branch,
|
|
8
|
+
// so a copy would need a test under every combination of context and config to reach the per-file coverage floor.
|
|
9
|
+
const none = () => undefined;
|
|
10
|
+
const pick = (...layers) => layers.filter((v) => v !== undefined).at(-1);
|
|
11
|
+
/** @internal The labels of a component: `prop` over the context over `configureLabels` over `defaults`, read at the moment a key is used. Call during component initialisation (it reads context). */
|
|
12
|
+
export function useLabels(component, defaults, prop) {
|
|
13
|
+
const lookup = [getContext(KEY), none].filter(Boolean)[0];
|
|
14
|
+
const out = {};
|
|
15
|
+
for (const k of Object.keys(defaults))
|
|
16
|
+
Object.defineProperty(out, k, { enumerable: true, get: () => pick(labelFor(component, k, defaults[k]), Object(lookup(component))[k], Object(prop())[k]) });
|
|
17
|
+
return out;
|
|
18
|
+
}
|
|
19
|
+
/** @internal One app-wide label for code outside a component (no context there): `configureLabels` over `fallback`. */
|
|
20
|
+
export function labelFor(component, key, fallback) {
|
|
21
|
+
return pick(fallback, config(component)[key]);
|
|
22
|
+
}
|
|
23
|
+
// </reader>
|
package/dist/lite.d.ts
CHANGED
|
@@ -26,5 +26,10 @@ export type { Move, MoveOptions } from './moves.js';
|
|
|
26
26
|
export type { PatchFile, FileStatus } from './patch.js';
|
|
27
27
|
export type { DiffFileInput, DiffStatus, FileEntry } from './files.js';
|
|
28
28
|
export type { LoadText } from './load.js';
|
|
29
|
-
export type { MergeState } from './MergeView.svelte';
|
|
29
|
+
export type { MergeState, MergeViewLabels } from './MergeView.svelte';
|
|
30
|
+
export type { CodeBlockLabels } from './CodeBlock.svelte';
|
|
31
|
+
export type { PatchTextLabels } from './PatchText.svelte';
|
|
32
|
+
export type { DiffViewLabels } from './DiffView.svelte';
|
|
33
|
+
export type { DiffFilesLabels } from './DiffFiles.svelte';
|
|
34
|
+
export type { ChangeLabels } from './diff.js';
|
|
30
35
|
export type { Merge, MergeRegion, RegionKind, Resolution, FileResolution, Choice, MergeLabels, Rendered as RenderedMerge } from './merge.js';
|
package/package.json
CHANGED