@noldova/code.editor.diff.angular 0.0.0-stage → 0.0.1
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/LICENSE +21 -0
- package/README.md +14 -2
- package/api/index.d.ts +17 -0
- package/api/index.js +16 -0
- package/app/components/diff-editor/diff-editor.component.d.ts +165 -0
- package/app/components/diff-editor/diff-editor.component.js +212 -0
- package/app/enums/diff-layout.d.ts +28 -0
- package/app/enums/diff-layout.js +13 -0
- package/app/interfaces/i-diff-navigator.d.ts +32 -0
- package/app/interfaces/i-diff-navigator.js +7 -0
- package/app/models/change-command.d.ts +15 -0
- package/app/models/change-command.js +23 -0
- package/app/models/diff-folds.d.ts +18 -0
- package/app/models/diff-folds.js +32 -0
- package/app/models/diff-layer.d.ts +26 -0
- package/app/models/diff-layer.js +62 -0
- package/app/models/inline-numbering.d.ts +16 -0
- package/app/models/inline-numbering.js +23 -0
- package/app/services/diff-editor-classes.d.ts +36 -0
- package/app/services/diff-editor-classes.js +14 -0
- package/app/services/diff-editor-commands.d.ts +37 -0
- package/app/services/diff-editor-commands.js +15 -0
- package/app/services/diff-editor-contribution.d.ts +44 -0
- package/app/services/diff-editor-contribution.js +28 -0
- package/app/services/diff-editor-features.d.ts +23 -0
- package/app/services/diff-editor-features.js +13 -0
- package/app/services/diff-editor-registries.d.ts +40 -0
- package/app/services/diff-editor-registries.js +25 -0
- package/app/services/diff-editor-settings.d.ts +49 -0
- package/app/services/diff-editor-settings.js +18 -0
- package/app/services/diff-worker.d.ts +42 -0
- package/app/services/diff-worker.js +13 -0
- package/app/workers/diff.worker.d.ts +8 -0
- package/app/workers/diff.worker.js +12 -0
- package/package.json +39 -4
- package/resources.d.ts +60 -0
- package/resources.js +72 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { CodeGutterMarker, type CodeInsertedRows, CodeLineDecoration, CodeRangeDecoration, type ICodeDecorations, type ICodeNumbering } from "@noldova/code.editor.angular";
|
|
9
|
+
import { DiffSide, type DocumentDiff } from "@noldova/code.editor.diff";
|
|
10
|
+
import { type IReadOnlyList } from "@noldova/context.collections";
|
|
11
|
+
export declare class DiffLayer implements ICodeDecorations {
|
|
12
|
+
readonly rows: IReadOnlyList<CodeInsertedRows>;
|
|
13
|
+
readonly numbering: ICodeNumbering | null;
|
|
14
|
+
private readonly diff;
|
|
15
|
+
private readonly side;
|
|
16
|
+
private readonly index;
|
|
17
|
+
private readonly background;
|
|
18
|
+
private readonly change;
|
|
19
|
+
private readonly sign;
|
|
20
|
+
private readonly color;
|
|
21
|
+
constructor(diff: DocumentDiff, side: DiffSide, rows?: IReadOnlyList<CodeInsertedRows>, numbering?: ICodeNumbering | null);
|
|
22
|
+
linesIn(start: number, end: number): IReadOnlyList<CodeLineDecoration>;
|
|
23
|
+
rangesIn(start: number, end: number): IReadOnlyList<CodeRangeDecoration>;
|
|
24
|
+
markersIn(start: number, end: number): IReadOnlyList<CodeGutterMarker>;
|
|
25
|
+
private static spacersOf;
|
|
26
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { CodeGutterMarker, CodeLineDecoration, CodeRangeDecoration, CodeSpacer, LineIndex } from "@noldova/code.editor.angular";
|
|
9
|
+
import { DiffSide } from "@noldova/code.editor.diff";
|
|
10
|
+
import { Enumerable } from "@noldova/context.collections";
|
|
11
|
+
import { Resources } from "../../resources.js";
|
|
12
|
+
export class DiffLayer {
|
|
13
|
+
rows;
|
|
14
|
+
numbering;
|
|
15
|
+
diff;
|
|
16
|
+
side;
|
|
17
|
+
index;
|
|
18
|
+
background;
|
|
19
|
+
change;
|
|
20
|
+
sign;
|
|
21
|
+
color;
|
|
22
|
+
constructor(diff, side, rows = DiffLayer.spacersOf(diff, side), numbering = null) {
|
|
23
|
+
const original = side === DiffSide.Original;
|
|
24
|
+
this.diff = diff;
|
|
25
|
+
this.side = side;
|
|
26
|
+
this.rows = rows;
|
|
27
|
+
this.numbering = numbering;
|
|
28
|
+
this.index = new LineIndex(diff.changes, t => t.startOf(side), t => t.endOf(side));
|
|
29
|
+
this.background = original ? Resources.removedBackground : Resources.addedBackground;
|
|
30
|
+
this.change = original ? Resources.removedChange : Resources.addedChange;
|
|
31
|
+
this.sign = original ? Resources.removedSign : Resources.addedSign;
|
|
32
|
+
this.color = original ? Resources.removedColor : Resources.addedColor;
|
|
33
|
+
}
|
|
34
|
+
linesIn(start, end) {
|
|
35
|
+
return this.index.overlapping(start, end)
|
|
36
|
+
.select(t => new CodeLineDecoration(t.startOf(this.side), t.endOf(this.side) - t.startOf(this.side), this.background))
|
|
37
|
+
.toList();
|
|
38
|
+
}
|
|
39
|
+
rangesIn(start, end) {
|
|
40
|
+
return this.index.overlapping(start, end)
|
|
41
|
+
.selectMany((t) => this.side === DiffSide.Original ? this.diff.rangesOf(t).original : this.diff.rangesOf(t).modified)
|
|
42
|
+
.where(t => t.start.line < end && t.end.line >= start)
|
|
43
|
+
.select(t => new CodeRangeDecoration(t, this.change))
|
|
44
|
+
.toList();
|
|
45
|
+
}
|
|
46
|
+
markersIn(start, end) {
|
|
47
|
+
return this.index.overlapping(start, end)
|
|
48
|
+
.selectMany(t => {
|
|
49
|
+
const first = Math.max(start, t.startOf(this.side));
|
|
50
|
+
return Enumerable.range(first, Math.min(end, t.endOf(this.side)) - first);
|
|
51
|
+
})
|
|
52
|
+
.select(t => new CodeGutterMarker(t, this.sign, this.color))
|
|
53
|
+
.toList();
|
|
54
|
+
}
|
|
55
|
+
static spacersOf(diff, side) {
|
|
56
|
+
const other = side === DiffSide.Original ? DiffSide.Modified : DiffSide.Original;
|
|
57
|
+
return diff.changes
|
|
58
|
+
.where(t => t.endOf(other) - t.startOf(other) > t.endOf(side) - t.startOf(side))
|
|
59
|
+
.select((t) => new CodeSpacer(t.endOf(side), t.endOf(other) - t.startOf(other) - (t.endOf(side) - t.startOf(side))))
|
|
60
|
+
.toList();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import "@noldova/context.core";
|
|
9
|
+
import type { ICodeNumbering } from "@noldova/code.editor.angular";
|
|
10
|
+
import { type DocumentDiff } from "@noldova/code.editor.diff";
|
|
11
|
+
export declare class InlineNumbering implements ICodeNumbering {
|
|
12
|
+
readonly largest: number;
|
|
13
|
+
private readonly diff;
|
|
14
|
+
constructor(diff: DocumentDiff);
|
|
15
|
+
numberOf(line: number): number | null;
|
|
16
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import "@noldova/context.core";
|
|
9
|
+
import { DiffSide } from "@noldova/code.editor.diff";
|
|
10
|
+
export class InlineNumbering {
|
|
11
|
+
largest;
|
|
12
|
+
diff;
|
|
13
|
+
constructor(diff) {
|
|
14
|
+
this.diff = diff;
|
|
15
|
+
this.largest = Math.max(diff.original.lineCount, diff.modified.lineCount);
|
|
16
|
+
}
|
|
17
|
+
numberOf(line) {
|
|
18
|
+
if (!Object.isNull(this.diff.changeAt(line, DiffSide.Modified)))
|
|
19
|
+
return null;
|
|
20
|
+
const change = this.diff.changes.lastOrDefault(t => t.modifiedEnd <= line);
|
|
21
|
+
return (Object.isUndefined(change) ? line : line - change.modifiedEnd + change.originalEnd) + 1;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* The diff view's CSS classes, each the bare class, which a host or a test
|
|
10
|
+
* builds its selectors from.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { DiffEditorClasses } from "@noldova/code.editor.diff.angular";
|
|
15
|
+
*
|
|
16
|
+
* document.querySelectorAll(`.${DiffEditorClasses.pane}`);
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
export declare class DiffEditorClasses {
|
|
20
|
+
/**
|
|
21
|
+
* `nol-diff-editor`: the diff view's host.
|
|
22
|
+
*/
|
|
23
|
+
static readonly host: string;
|
|
24
|
+
/**
|
|
25
|
+
* `nol-diff-editor-inline`: added to the host while it shows the change inline.
|
|
26
|
+
*/
|
|
27
|
+
static readonly inline: string;
|
|
28
|
+
/**
|
|
29
|
+
* `nol-diff-editor-pane`: a side's code view, or the one inline.
|
|
30
|
+
*/
|
|
31
|
+
static readonly pane: string;
|
|
32
|
+
/**
|
|
33
|
+
* `nol-diff-editor-status`: the status that names the change the caret moved to.
|
|
34
|
+
*/
|
|
35
|
+
static readonly status: string;
|
|
36
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { Resources } from "../../resources.js";
|
|
9
|
+
export class DiffEditorClasses {
|
|
10
|
+
static host = Resources.hostClass;
|
|
11
|
+
static inline = Resources.inlineClass;
|
|
12
|
+
static pane = Resources.paneClass;
|
|
13
|
+
static status = Resources.statusClass;
|
|
14
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import type { ICommand } from "@noldova/code.editor";
|
|
9
|
+
import { type IReadOnlyList } from "@noldova/context.collections";
|
|
10
|
+
/**
|
|
11
|
+
* The diff view's commands, which move its caret to the next or the previous
|
|
12
|
+
* change.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* A command returns false outside a diff view, so its key goes on.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { DiffEditorCommands } from "@noldova/code.editor.diff.angular";
|
|
20
|
+
*
|
|
21
|
+
* DiffEditorCommands.nextChange.id; // "diffEditor.nextChange"
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare class DiffEditorCommands {
|
|
25
|
+
/**
|
|
26
|
+
* `diffEditor.nextChange`: moves to the next change, after the last one to the first.
|
|
27
|
+
*/
|
|
28
|
+
static readonly nextChange: ICommand;
|
|
29
|
+
/**
|
|
30
|
+
* `diffEditor.previousChange`: moves to the previous change, before the first one to the last.
|
|
31
|
+
*/
|
|
32
|
+
static readonly previousChange: ICommand;
|
|
33
|
+
/**
|
|
34
|
+
* Both commands, the next change's first.
|
|
35
|
+
*/
|
|
36
|
+
static readonly all: IReadOnlyList<ICommand>;
|
|
37
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { List } from "@noldova/context.collections";
|
|
9
|
+
import { Resources } from "../../resources.js";
|
|
10
|
+
import { ChangeCommand } from "../models/change-command.js";
|
|
11
|
+
export class DiffEditorCommands {
|
|
12
|
+
static nextChange = new ChangeCommand(Resources.nextChangeCommand, true);
|
|
13
|
+
static previousChange = new ChangeCommand(Resources.previousChangeCommand, false);
|
|
14
|
+
static all = new List([DiffEditorCommands.nextChange, DiffEditorCommands.previousChange]);
|
|
15
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { type EditorRegistries, type IEditorContribution } from "@noldova/code.editor";
|
|
9
|
+
/**
|
|
10
|
+
* The diff view's contribution: the {@link DiffEditorCommands}, on Alt with
|
|
11
|
+
* Down and Up when `inDiffEditor`, the condition and the
|
|
12
|
+
* {@link DiffEditorSettings}.
|
|
13
|
+
*
|
|
14
|
+
* @remarks
|
|
15
|
+
* A command returns false outside a diff view, so its key goes on.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { EditorRegistries } from "@noldova/code.editor";
|
|
20
|
+
* import { DiffEditorContribution } from "@noldova/code.editor.diff.angular";
|
|
21
|
+
*
|
|
22
|
+
* new EditorRegistries().add(new DiffEditorContribution());
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare class DiffEditorContribution implements IEditorContribution {
|
|
26
|
+
private static readonly KEY_BINDINGS;
|
|
27
|
+
/**
|
|
28
|
+
* `"noldova.code.editor.diff.angular"`.
|
|
29
|
+
*/
|
|
30
|
+
readonly id: string;
|
|
31
|
+
/**
|
|
32
|
+
* Registers the diff view's entries.
|
|
33
|
+
*
|
|
34
|
+
* @param registries The set to register them in.
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* import { EditorRegistries } from "@noldova/code.editor";
|
|
38
|
+
* import { DiffEditorContribution } from "@noldova/code.editor.diff.angular";
|
|
39
|
+
*
|
|
40
|
+
* new DiffEditorContribution().contribute(new EditorRegistries());
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
contribute(registries: EditorRegistries): void;
|
|
44
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { Condition, KeyBindingRule } from "@noldova/code.editor";
|
|
9
|
+
import { List } from "@noldova/context.collections";
|
|
10
|
+
import { Resources } from "../../resources.js";
|
|
11
|
+
import { DiffEditorCommands } from "./diff-editor-commands.js";
|
|
12
|
+
import { DiffEditorFeatures } from "./diff-editor-features.js";
|
|
13
|
+
import { DiffEditorSettings } from "./diff-editor-settings.js";
|
|
14
|
+
export class DiffEditorContribution {
|
|
15
|
+
static KEY_BINDINGS = new List([
|
|
16
|
+
new KeyBindingRule(DiffEditorCommands.nextChange.id, Resources.nextChangeKey, Condition.has(DiffEditorFeatures.inDiffEditor)),
|
|
17
|
+
new KeyBindingRule(DiffEditorCommands.previousChange.id, Resources.previousChangeKey, Condition.has(DiffEditorFeatures.inDiffEditor))
|
|
18
|
+
]);
|
|
19
|
+
id = Resources.diffContribution;
|
|
20
|
+
contribute(registries) {
|
|
21
|
+
for (const command of DiffEditorCommands.all)
|
|
22
|
+
registries.commands.register(command);
|
|
23
|
+
registries.conditions.register(DiffEditorFeatures.inDiffEditor);
|
|
24
|
+
for (const setting of DiffEditorSettings.all)
|
|
25
|
+
registries.settings.declare(setting);
|
|
26
|
+
registries.keyBindings.addDefaults(this.id, DiffEditorContribution.KEY_BINDINGS);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { ConditionKey, EditorFeature } from "@noldova/code.editor";
|
|
9
|
+
import type { IDiffNavigator } from "../interfaces/i-diff-navigator.js";
|
|
10
|
+
/**
|
|
11
|
+
* The diff view's feature and condition, which its commands and key
|
|
12
|
+
* bindings use.
|
|
13
|
+
*/
|
|
14
|
+
export declare class DiffEditorFeatures {
|
|
15
|
+
/**
|
|
16
|
+
* The diff view a command moves between changes in.
|
|
17
|
+
*/
|
|
18
|
+
static readonly navigator: EditorFeature<IDiffNavigator>;
|
|
19
|
+
/**
|
|
20
|
+
* `inDiffEditor`: true while a key goes to a diff view.
|
|
21
|
+
*/
|
|
22
|
+
static readonly inDiffEditor: ConditionKey<boolean>;
|
|
23
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { ConditionKey, EditorFeature } from "@noldova/code.editor";
|
|
9
|
+
import { Resources } from "../../resources.js";
|
|
10
|
+
export class DiffEditorFeatures {
|
|
11
|
+
static navigator = new EditorFeature(Resources.navigatorFeature);
|
|
12
|
+
static inDiffEditor = new ConditionKey(Resources.inDiffEditorCondition, false, Resources.inDiffEditorDescription);
|
|
13
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { EditorRegistries } from "@noldova/code.editor";
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
/**
|
|
4
|
+
* The registries every {@link DiffEditorComponent} adds its own on top of:
|
|
5
|
+
* the app's `CodeEditorRegistries` with the diff model's `DiffContribution`
|
|
6
|
+
* and the {@link DiffEditorContribution}.
|
|
7
|
+
*
|
|
8
|
+
* @remarks
|
|
9
|
+
* A host sets the diff view's settings and keys in `CodeEditorRegistries`,
|
|
10
|
+
* which these follow.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { inject } from "@angular/core";
|
|
15
|
+
* import { DiffEditorRegistries } from "@noldova/code.editor.diff.angular";
|
|
16
|
+
*
|
|
17
|
+
* inject(DiffEditorRegistries).registries.commands.find("diffEditor.nextChange");
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export declare class DiffEditorRegistries {
|
|
21
|
+
/**
|
|
22
|
+
* The registries.
|
|
23
|
+
*/
|
|
24
|
+
readonly registries: EditorRegistries;
|
|
25
|
+
/**
|
|
26
|
+
* Creates the set over the app's `CodeEditorRegistries`; Angular creates it
|
|
27
|
+
* once per app.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```ts
|
|
31
|
+
* import { inject } from "@angular/core";
|
|
32
|
+
* import { DiffEditorRegistries } from "@noldova/code.editor.diff.angular";
|
|
33
|
+
*
|
|
34
|
+
* const registries = inject(DiffEditorRegistries);
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
constructor();
|
|
38
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<DiffEditorRegistries, never>;
|
|
39
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
40
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { inject, Injectable } from "@angular/core";
|
|
9
|
+
import { EditorRegistries } from "@noldova/code.editor";
|
|
10
|
+
import { CodeEditorRegistries } from "@noldova/code.editor.angular";
|
|
11
|
+
import { DiffContribution } from "@noldova/code.editor.diff";
|
|
12
|
+
import { DiffEditorContribution } from "./diff-editor-contribution.js";
|
|
13
|
+
import * as i0 from "@angular/core";
|
|
14
|
+
export class DiffEditorRegistries {
|
|
15
|
+
registries = new EditorRegistries(inject(CodeEditorRegistries).registries);
|
|
16
|
+
constructor() {
|
|
17
|
+
this.registries.add(new DiffContribution(), new DiffEditorContribution());
|
|
18
|
+
}
|
|
19
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: DiffEditorRegistries, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
20
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: DiffEditorRegistries, providedIn: "root" });
|
|
21
|
+
}
|
|
22
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: DiffEditorRegistries, decorators: [{
|
|
23
|
+
type: Injectable,
|
|
24
|
+
args: [{ providedIn: "root" }]
|
|
25
|
+
}], ctorParameters: () => [] });
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { Setting } from "@noldova/code.editor";
|
|
9
|
+
import { type IReadOnlyList } from "@noldova/context.collections";
|
|
10
|
+
/**
|
|
11
|
+
* The diff view's settings, declared in its registries: how much unchanged
|
|
12
|
+
* text stays in view, how far the characters of a change are compared, and
|
|
13
|
+
* where the automatic layout turns inline.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { inject } from "@angular/core";
|
|
18
|
+
* import { CodeEditorRegistries } from "@noldova/code.editor.angular";
|
|
19
|
+
* import { DiffEditorSettings } from "@noldova/code.editor.diff.angular";
|
|
20
|
+
*
|
|
21
|
+
* inject(CodeEditorRegistries).registries.settings.setUserValues({ [DiffEditorSettings.contextLines.id]: 5 });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare class DiffEditorSettings {
|
|
25
|
+
/**
|
|
26
|
+
* `diff.contextLines`, 3: the unchanged lines kept in view next to each
|
|
27
|
+
* change, 0 or more.
|
|
28
|
+
*/
|
|
29
|
+
static readonly contextLines: Setting<number>;
|
|
30
|
+
/**
|
|
31
|
+
* `diff.minimumHiddenLines`, 3: the fewest unchanged lines a fold hides,
|
|
32
|
+
* 1 or more.
|
|
33
|
+
*/
|
|
34
|
+
static readonly minimumHiddenLines: Setting<number>;
|
|
35
|
+
/**
|
|
36
|
+
* `diff.characterDiffLimit`, 20,000: the most characters of a change, both
|
|
37
|
+
* sides together, compared by character.
|
|
38
|
+
*/
|
|
39
|
+
static readonly characterDiffLimit: Setting<number>;
|
|
40
|
+
/**
|
|
41
|
+
* `diff.inlineBreakpoint`, 50: the width, in rem, below which the automatic
|
|
42
|
+
* layout is inline.
|
|
43
|
+
*/
|
|
44
|
+
static readonly inlineBreakpoint: Setting<number>;
|
|
45
|
+
/**
|
|
46
|
+
* Every diff view setting.
|
|
47
|
+
*/
|
|
48
|
+
static readonly all: IReadOnlyList<Setting<number>>;
|
|
49
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { Setting } from "@noldova/code.editor";
|
|
9
|
+
import { List } from "@noldova/context.collections";
|
|
10
|
+
import { Resources } from "../../resources.js";
|
|
11
|
+
export class DiffEditorSettings {
|
|
12
|
+
static contextLines = Setting.integer(Resources.contextLinesSetting, Resources.defaultContextLines, Resources.contextLinesDescription, Resources.contextLinesMinimum);
|
|
13
|
+
static minimumHiddenLines = Setting.integer(Resources.minimumHiddenLinesSetting, Resources.defaultMinimumHiddenLines, Resources.minimumHiddenLinesDescription, Resources.minimumHiddenLinesMinimum);
|
|
14
|
+
static characterDiffLimit = Setting.integer(Resources.characterDiffLimitSetting, Resources.defaultCharacterDiffLimit, Resources.characterDiffLimitDescription, Resources.characterDiffLimitMinimum);
|
|
15
|
+
static inlineBreakpoint = Setting.number(Resources.inlineBreakpointSetting, Resources.defaultInlineBreakpoint, Resources.inlineBreakpointDescription, Resources.inlineBreakpointMinimum);
|
|
16
|
+
static all = new List([DiffEditorSettings.contextLines, DiffEditorSettings.minimumHiddenLines,
|
|
17
|
+
DiffEditorSettings.characterDiffLimit, DiffEditorSettings.inlineBreakpoint]);
|
|
18
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { WorkerRunner } from "@noldova/code.editor.angular";
|
|
9
|
+
/**
|
|
10
|
+
* Makes the runner a diff runs its line diff on in the browser: a worker
|
|
11
|
+
* that serves the default algorithm's line diff job.
|
|
12
|
+
*
|
|
13
|
+
* @remarks
|
|
14
|
+
* Give it to `DocumentDiff`, so the page never waits for the diff. A host's
|
|
15
|
+
* own algorithm needs a worker script of its own that serves its job; this
|
|
16
|
+
* worker runs it on the calling thread instead. The app's build bundles the
|
|
17
|
+
* package's `diff.worker.ts` through `webWorkerTsConfig`.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { TextDocument } from "@noldova/code.editor";
|
|
22
|
+
* import { DocumentDiff } from "@noldova/code.editor.diff";
|
|
23
|
+
* import { DiffWorker } from "@noldova/code.editor.diff.angular";
|
|
24
|
+
*
|
|
25
|
+
* using runner = DiffWorker.create();
|
|
26
|
+
* using diff = new DocumentDiff(TextDocument.fromText("a"), TextDocument.fromText("b"), undefined, runner);
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare class DiffWorker {
|
|
30
|
+
/**
|
|
31
|
+
* Starts a worker running the package's `diff.worker.ts`.
|
|
32
|
+
*
|
|
33
|
+
* @returns The runner; dispose it to end its worker.
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { DiffWorker } from "@noldova/code.editor.diff.angular";
|
|
37
|
+
*
|
|
38
|
+
* using runner = DiffWorker.create();
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
static create(): WorkerRunner;
|
|
42
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { WorkerRunner } from "@noldova/code.editor.angular";
|
|
9
|
+
export class DiffWorker {
|
|
10
|
+
static create() {
|
|
11
|
+
return new WorkerRunner(new Worker(new URL("../workers/diff.worker.js", import.meta.url), { type: "module" }));
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
import { BackgroundJobRegistry, WorkerJobHost } from "@noldova/code.editor";
|
|
9
|
+
import { DefaultDiffAlgorithm, LineDiffJob } from "@noldova/code.editor.diff";
|
|
10
|
+
const jobs = new BackgroundJobRegistry();
|
|
11
|
+
jobs.register(new LineDiffJob(new DefaultDiffAlgorithm()));
|
|
12
|
+
new WorkerJobHost(jobs).listen(self);
|
package/package.json
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noldova/code.editor.diff.angular",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "The code editor's diff view in Angular: two documents side by side or inline, with changed lines and characters, folded unchanged regions and steps between changes, styled only with the kit's tokens.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "api/index.js",
|
|
7
|
+
"types": "api/index.d.ts",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/noldova-com/code-editor.git",
|
|
12
|
+
"directory": "src/noldova.code.editor.diff.angular"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/noldova-com/code-editor#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/noldova-com/code-editor/issues"
|
|
17
|
+
},
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public",
|
|
20
|
+
"registry": "https://registry.npmjs.org/"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"test": "ngc -p tsconfig.json && playwright install --only-shell chromium && ng test"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@noldova/code.editor": "0.0.1",
|
|
27
|
+
"@noldova/code.editor.angular": "0.0.1",
|
|
28
|
+
"@noldova/code.editor.diff": "0.0.1",
|
|
29
|
+
"tslib": "2.8.1"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"@angular/common": ">=22.3.0 <23.0.0",
|
|
33
|
+
"@angular/core": ">=22.3.0 <23.0.0",
|
|
34
|
+
"@noldova/context.collections": ">=0.0.16 <0.1.0",
|
|
35
|
+
"@noldova/context.core": ">=0.0.16 <0.1.0",
|
|
36
|
+
"@noldova/context.exceptions": ">=0.0.16 <0.1.0",
|
|
37
|
+
"@noldova/ui.components.angular": ">=0.0.35 <0.1.0",
|
|
38
|
+
"rxjs": ">=7.8.2 <8.0.0"
|
|
39
|
+
},
|
|
40
|
+
"gitHead": "f8f8640dfb1de8dc2db7e4f446dccd90facc25dd"
|
|
41
|
+
}
|